]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.5.1-201208132030.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.5.1-201208132030.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 d7ee1cb..bf3389b 100644
279 --- a/Makefile
280 +++ b/Makefile
281 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
282
283 HOSTCC = gcc
284 HOSTCXX = g++
285 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
286 -HOSTCXXFLAGS = -O2
287 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
288 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
289 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
290
291 # Decide whether to build built-in, modular, or both.
292 # Normally, just do built-in.
293 @@ -404,8 +405,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
294 # Rules shared between *config targets and build targets
295
296 # Basic helpers built in scripts/
297 -PHONY += scripts_basic
298 -scripts_basic:
299 +PHONY += scripts_basic gcc-plugins
300 +scripts_basic: gcc-plugins
301 $(Q)$(MAKE) $(build)=scripts/basic
302 $(Q)rm -f .tmp_quiet_recordmcount
303
304 @@ -561,6 +562,60 @@ else
305 KBUILD_CFLAGS += -O2
306 endif
307
308 +ifndef DISABLE_PAX_PLUGINS
309 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
310 +ifneq ($(PLUGINCC),)
311 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
312 +ifndef CONFIG_UML
313 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
314 +endif
315 +endif
316 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
317 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
318 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
319 +endif
320 +ifdef CONFIG_KALLOCSTAT_PLUGIN
321 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
322 +endif
323 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
324 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
325 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
326 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
327 +endif
328 +ifdef CONFIG_CHECKER_PLUGIN
329 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
330 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
331 +endif
332 +endif
333 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
334 +ifdef CONFIG_PAX_SIZE_OVERFLOW
335 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
336 +endif
337 +ifdef CONFIG_PAX_LATENT_ENTROPY
338 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
339 +endif
340 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
341 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
342 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
343 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
344 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
345 +ifeq ($(KBUILD_EXTMOD),)
346 +gcc-plugins:
347 + $(Q)$(MAKE) $(build)=tools/gcc
348 +else
349 +gcc-plugins: ;
350 +endif
351 +else
352 +gcc-plugins:
353 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
354 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
355 +else
356 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
357 +endif
358 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
359 +endif
360 +endif
361 +
362 include $(srctree)/arch/$(SRCARCH)/Makefile
363
364 ifdef CONFIG_READABLE_ASM
365 @@ -715,7 +770,7 @@ export mod_strip_cmd
366
367
368 ifeq ($(KBUILD_EXTMOD),)
369 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
370 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
371
372 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
373 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
374 @@ -762,6 +817,8 @@ endif
375
376 # The actual objects are generated when descending,
377 # make sure no implicit rule kicks in
378 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
379 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
380 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
381
382 # Handle descending into subdirectories listed in $(vmlinux-dirs)
383 @@ -771,7 +828,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
384 # Error messages still appears in the original language
385
386 PHONY += $(vmlinux-dirs)
387 -$(vmlinux-dirs): prepare scripts
388 +$(vmlinux-dirs): gcc-plugins prepare scripts
389 $(Q)$(MAKE) $(build)=$@
390
391 # Store (new) KERNELRELASE string in include/config/kernel.release
392 @@ -815,6 +872,7 @@ prepare0: archprepare FORCE
393 $(Q)$(MAKE) $(build)=.
394
395 # All the preparing..
396 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
397 prepare: prepare0
398
399 # Generate some files
400 @@ -922,6 +980,8 @@ all: modules
401 # using awk while concatenating to the final file.
402
403 PHONY += modules
404 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
405 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
406 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
407 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
408 @$(kecho) ' Building modules, stage 2.';
409 @@ -937,7 +997,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
410
411 # Target to prepare building external modules
412 PHONY += modules_prepare
413 -modules_prepare: prepare scripts
414 +modules_prepare: gcc-plugins prepare scripts
415
416 # Target to install modules
417 PHONY += modules_install
418 @@ -994,7 +1054,7 @@ CLEAN_DIRS += $(MODVERDIR)
419 MRPROPER_DIRS += include/config usr/include include/generated \
420 arch/*/include/generated
421 MRPROPER_FILES += .config .config.old .version .old_version \
422 - include/linux/version.h \
423 + include/linux/version.h tools/gcc/size_overflow_hash.h\
424 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
425
426 # clean - Delete most, but leave enough to build external modules
427 @@ -1032,6 +1092,7 @@ distclean: mrproper
428 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
429 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
430 -o -name '.*.rej' \
431 + -o -name '.*.rej' -o -name '*.so' \
432 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
433 -type f -print | xargs rm -f
434
435 @@ -1192,6 +1253,8 @@ PHONY += $(module-dirs) modules
436 $(module-dirs): crmodverdir $(objtree)/Module.symvers
437 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
438
439 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
440 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
441 modules: $(module-dirs)
442 @$(kecho) ' Building modules, stage 2.';
443 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
444 @@ -1326,17 +1389,21 @@ else
445 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
446 endif
447
448 -%.s: %.c prepare scripts FORCE
449 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
450 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
451 +%.s: %.c gcc-plugins prepare scripts FORCE
452 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
453 %.i: %.c prepare scripts FORCE
454 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
455 -%.o: %.c prepare scripts FORCE
456 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
457 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
458 +%.o: %.c gcc-plugins prepare scripts FORCE
459 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
460 %.lst: %.c prepare scripts FORCE
461 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
462 -%.s: %.S prepare scripts FORCE
463 +%.s: %.S gcc-plugins prepare scripts FORCE
464 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
465 -%.o: %.S prepare scripts FORCE
466 +%.o: %.S gcc-plugins prepare scripts FORCE
467 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
468 %.symtypes: %.c prepare scripts FORCE
469 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
470 @@ -1346,11 +1413,15 @@ endif
471 $(cmd_crmodverdir)
472 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
473 $(build)=$(build-dir)
474 -%/: prepare scripts FORCE
475 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
476 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
477 +%/: gcc-plugins prepare scripts FORCE
478 $(cmd_crmodverdir)
479 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
480 $(build)=$(build-dir)
481 -%.ko: prepare scripts FORCE
482 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
483 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
484 +%.ko: gcc-plugins prepare scripts FORCE
485 $(cmd_crmodverdir)
486 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
487 $(build)=$(build-dir) $(@:.ko=.o)
488 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
489 index 3bb7ffe..347a54c 100644
490 --- a/arch/alpha/include/asm/atomic.h
491 +++ b/arch/alpha/include/asm/atomic.h
492 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
493 #define atomic_dec(v) atomic_sub(1,(v))
494 #define atomic64_dec(v) atomic64_sub(1,(v))
495
496 +#define atomic64_read_unchecked(v) atomic64_read(v)
497 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
498 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
499 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
500 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
501 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
502 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
503 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
504 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
505 +
506 #define smp_mb__before_atomic_dec() smp_mb()
507 #define smp_mb__after_atomic_dec() smp_mb()
508 #define smp_mb__before_atomic_inc() smp_mb()
509 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
510 index ad368a9..fbe0f25 100644
511 --- a/arch/alpha/include/asm/cache.h
512 +++ b/arch/alpha/include/asm/cache.h
513 @@ -4,19 +4,19 @@
514 #ifndef __ARCH_ALPHA_CACHE_H
515 #define __ARCH_ALPHA_CACHE_H
516
517 +#include <linux/const.h>
518
519 /* Bytes per L1 (data) cache line. */
520 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
521 -# define L1_CACHE_BYTES 64
522 # define L1_CACHE_SHIFT 6
523 #else
524 /* Both EV4 and EV5 are write-through, read-allocate,
525 direct-mapped, physical.
526 */
527 -# define L1_CACHE_BYTES 32
528 # define L1_CACHE_SHIFT 5
529 #endif
530
531 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
532 #define SMP_CACHE_BYTES L1_CACHE_BYTES
533
534 #endif
535 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
536 index 968d999..d36b2df 100644
537 --- a/arch/alpha/include/asm/elf.h
538 +++ b/arch/alpha/include/asm/elf.h
539 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
540
541 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
542
543 +#ifdef CONFIG_PAX_ASLR
544 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
545 +
546 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
547 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
548 +#endif
549 +
550 /* $0 is set by ld.so to a pointer to a function which might be
551 registered using atexit. This provides a mean for the dynamic
552 linker to call DT_FINI functions for shared libraries that have
553 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
554 index bc2a0da..8ad11ee 100644
555 --- a/arch/alpha/include/asm/pgalloc.h
556 +++ b/arch/alpha/include/asm/pgalloc.h
557 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
558 pgd_set(pgd, pmd);
559 }
560
561 +static inline void
562 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
563 +{
564 + pgd_populate(mm, pgd, pmd);
565 +}
566 +
567 extern pgd_t *pgd_alloc(struct mm_struct *mm);
568
569 static inline void
570 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
571 index 81a4342..348b927 100644
572 --- a/arch/alpha/include/asm/pgtable.h
573 +++ b/arch/alpha/include/asm/pgtable.h
574 @@ -102,6 +102,17 @@ struct vm_area_struct;
575 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
576 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
577 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
578 +
579 +#ifdef CONFIG_PAX_PAGEEXEC
580 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
581 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
582 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
583 +#else
584 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
585 +# define PAGE_COPY_NOEXEC PAGE_COPY
586 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
587 +#endif
588 +
589 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
590
591 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
592 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
593 index 2fd00b7..cfd5069 100644
594 --- a/arch/alpha/kernel/module.c
595 +++ b/arch/alpha/kernel/module.c
596 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
597
598 /* The small sections were sorted to the end of the segment.
599 The following should definitely cover them. */
600 - gp = (u64)me->module_core + me->core_size - 0x8000;
601 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
602 got = sechdrs[me->arch.gotsecindex].sh_addr;
603
604 for (i = 0; i < n; i++) {
605 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
606 index 98a1036..fb54ccf 100644
607 --- a/arch/alpha/kernel/osf_sys.c
608 +++ b/arch/alpha/kernel/osf_sys.c
609 @@ -1312,7 +1312,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
610 /* At this point: (!vma || addr < vma->vm_end). */
611 if (limit - len < addr)
612 return -ENOMEM;
613 - if (!vma || addr + len <= vma->vm_start)
614 + if (check_heap_stack_gap(vma, addr, len))
615 return addr;
616 addr = vma->vm_end;
617 vma = vma->vm_next;
618 @@ -1348,6 +1348,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
619 merely specific addresses, but regions of memory -- perhaps
620 this feature should be incorporated into all ports? */
621
622 +#ifdef CONFIG_PAX_RANDMMAP
623 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
624 +#endif
625 +
626 if (addr) {
627 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
628 if (addr != (unsigned long) -ENOMEM)
629 @@ -1355,8 +1359,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
630 }
631
632 /* Next, try allocating at TASK_UNMAPPED_BASE. */
633 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
634 - len, limit);
635 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
636 +
637 if (addr != (unsigned long) -ENOMEM)
638 return addr;
639
640 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
641 index 5eecab1..609abc0 100644
642 --- a/arch/alpha/mm/fault.c
643 +++ b/arch/alpha/mm/fault.c
644 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
645 __reload_thread(pcb);
646 }
647
648 +#ifdef CONFIG_PAX_PAGEEXEC
649 +/*
650 + * PaX: decide what to do with offenders (regs->pc = fault address)
651 + *
652 + * returns 1 when task should be killed
653 + * 2 when patched PLT trampoline was detected
654 + * 3 when unpatched PLT trampoline was detected
655 + */
656 +static int pax_handle_fetch_fault(struct pt_regs *regs)
657 +{
658 +
659 +#ifdef CONFIG_PAX_EMUPLT
660 + int err;
661 +
662 + do { /* PaX: patched PLT emulation #1 */
663 + unsigned int ldah, ldq, jmp;
664 +
665 + err = get_user(ldah, (unsigned int *)regs->pc);
666 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
667 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
668 +
669 + if (err)
670 + break;
671 +
672 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
673 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
674 + jmp == 0x6BFB0000U)
675 + {
676 + unsigned long r27, addr;
677 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
678 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
679 +
680 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
681 + err = get_user(r27, (unsigned long *)addr);
682 + if (err)
683 + break;
684 +
685 + regs->r27 = r27;
686 + regs->pc = r27;
687 + return 2;
688 + }
689 + } while (0);
690 +
691 + do { /* PaX: patched PLT emulation #2 */
692 + unsigned int ldah, lda, br;
693 +
694 + err = get_user(ldah, (unsigned int *)regs->pc);
695 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
696 + err |= get_user(br, (unsigned int *)(regs->pc+8));
697 +
698 + if (err)
699 + break;
700 +
701 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
702 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
703 + (br & 0xFFE00000U) == 0xC3E00000U)
704 + {
705 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
706 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
707 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
708 +
709 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
710 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
711 + return 2;
712 + }
713 + } while (0);
714 +
715 + do { /* PaX: unpatched PLT emulation */
716 + unsigned int br;
717 +
718 + err = get_user(br, (unsigned int *)regs->pc);
719 +
720 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
721 + unsigned int br2, ldq, nop, jmp;
722 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
723 +
724 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
725 + err = get_user(br2, (unsigned int *)addr);
726 + err |= get_user(ldq, (unsigned int *)(addr+4));
727 + err |= get_user(nop, (unsigned int *)(addr+8));
728 + err |= get_user(jmp, (unsigned int *)(addr+12));
729 + err |= get_user(resolver, (unsigned long *)(addr+16));
730 +
731 + if (err)
732 + break;
733 +
734 + if (br2 == 0xC3600000U &&
735 + ldq == 0xA77B000CU &&
736 + nop == 0x47FF041FU &&
737 + jmp == 0x6B7B0000U)
738 + {
739 + regs->r28 = regs->pc+4;
740 + regs->r27 = addr+16;
741 + regs->pc = resolver;
742 + return 3;
743 + }
744 + }
745 + } while (0);
746 +#endif
747 +
748 + return 1;
749 +}
750 +
751 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
752 +{
753 + unsigned long i;
754 +
755 + printk(KERN_ERR "PAX: bytes at PC: ");
756 + for (i = 0; i < 5; i++) {
757 + unsigned int c;
758 + if (get_user(c, (unsigned int *)pc+i))
759 + printk(KERN_CONT "???????? ");
760 + else
761 + printk(KERN_CONT "%08x ", c);
762 + }
763 + printk("\n");
764 +}
765 +#endif
766
767 /*
768 * This routine handles page faults. It determines the address,
769 @@ -130,8 +248,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
770 good_area:
771 si_code = SEGV_ACCERR;
772 if (cause < 0) {
773 - if (!(vma->vm_flags & VM_EXEC))
774 + if (!(vma->vm_flags & VM_EXEC)) {
775 +
776 +#ifdef CONFIG_PAX_PAGEEXEC
777 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
778 + goto bad_area;
779 +
780 + up_read(&mm->mmap_sem);
781 + switch (pax_handle_fetch_fault(regs)) {
782 +
783 +#ifdef CONFIG_PAX_EMUPLT
784 + case 2:
785 + case 3:
786 + return;
787 +#endif
788 +
789 + }
790 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
791 + do_group_exit(SIGKILL);
792 +#else
793 goto bad_area;
794 +#endif
795 +
796 + }
797 } else if (!cause) {
798 /* Allow reads even for write-only mappings */
799 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
800 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
801 index c79f61f..9ac0642 100644
802 --- a/arch/arm/include/asm/atomic.h
803 +++ b/arch/arm/include/asm/atomic.h
804 @@ -17,17 +17,35 @@
805 #include <asm/barrier.h>
806 #include <asm/cmpxchg.h>
807
808 +#ifdef CONFIG_GENERIC_ATOMIC64
809 +#include <asm-generic/atomic64.h>
810 +#endif
811 +
812 #define ATOMIC_INIT(i) { (i) }
813
814 #ifdef __KERNEL__
815
816 +#define _ASM_EXTABLE(from, to) \
817 +" .pushsection __ex_table,\"a\"\n"\
818 +" .align 3\n" \
819 +" .long " #from ", " #to"\n" \
820 +" .popsection"
821 +
822 /*
823 * On ARM, ordinary assignment (str instruction) doesn't clear the local
824 * strex/ldrex monitor on some implementations. The reason we can use it for
825 * atomic_set() is the clrex or dummy strex done on every exception return.
826 */
827 #define atomic_read(v) (*(volatile int *)&(v)->counter)
828 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
829 +{
830 + return v->counter;
831 +}
832 #define atomic_set(v,i) (((v)->counter) = (i))
833 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
834 +{
835 + v->counter = i;
836 +}
837
838 #if __LINUX_ARM_ARCH__ >= 6
839
840 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
841 int result;
842
843 __asm__ __volatile__("@ atomic_add\n"
844 +"1: ldrex %1, [%3]\n"
845 +" adds %0, %1, %4\n"
846 +
847 +#ifdef CONFIG_PAX_REFCOUNT
848 +" bvc 3f\n"
849 +"2: bkpt 0xf103\n"
850 +"3:\n"
851 +#endif
852 +
853 +" strex %1, %0, [%3]\n"
854 +" teq %1, #0\n"
855 +" bne 1b"
856 +
857 +#ifdef CONFIG_PAX_REFCOUNT
858 +"\n4:\n"
859 + _ASM_EXTABLE(2b, 4b)
860 +#endif
861 +
862 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
863 + : "r" (&v->counter), "Ir" (i)
864 + : "cc");
865 +}
866 +
867 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
868 +{
869 + unsigned long tmp;
870 + int result;
871 +
872 + __asm__ __volatile__("@ atomic_add_unchecked\n"
873 "1: ldrex %0, [%3]\n"
874 " add %0, %0, %4\n"
875 " strex %1, %0, [%3]\n"
876 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
877 smp_mb();
878
879 __asm__ __volatile__("@ atomic_add_return\n"
880 +"1: ldrex %1, [%3]\n"
881 +" adds %0, %1, %4\n"
882 +
883 +#ifdef CONFIG_PAX_REFCOUNT
884 +" bvc 3f\n"
885 +" mov %0, %1\n"
886 +"2: bkpt 0xf103\n"
887 +"3:\n"
888 +#endif
889 +
890 +" strex %1, %0, [%3]\n"
891 +" teq %1, #0\n"
892 +" bne 1b"
893 +
894 +#ifdef CONFIG_PAX_REFCOUNT
895 +"\n4:\n"
896 + _ASM_EXTABLE(2b, 4b)
897 +#endif
898 +
899 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
900 + : "r" (&v->counter), "Ir" (i)
901 + : "cc");
902 +
903 + smp_mb();
904 +
905 + return result;
906 +}
907 +
908 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
909 +{
910 + unsigned long tmp;
911 + int result;
912 +
913 + smp_mb();
914 +
915 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
916 "1: ldrex %0, [%3]\n"
917 " add %0, %0, %4\n"
918 " strex %1, %0, [%3]\n"
919 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
920 int result;
921
922 __asm__ __volatile__("@ atomic_sub\n"
923 +"1: ldrex %1, [%3]\n"
924 +" subs %0, %1, %4\n"
925 +
926 +#ifdef CONFIG_PAX_REFCOUNT
927 +" bvc 3f\n"
928 +"2: bkpt 0xf103\n"
929 +"3:\n"
930 +#endif
931 +
932 +" strex %1, %0, [%3]\n"
933 +" teq %1, #0\n"
934 +" bne 1b"
935 +
936 +#ifdef CONFIG_PAX_REFCOUNT
937 +"\n4:\n"
938 + _ASM_EXTABLE(2b, 4b)
939 +#endif
940 +
941 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
942 + : "r" (&v->counter), "Ir" (i)
943 + : "cc");
944 +}
945 +
946 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
947 +{
948 + unsigned long tmp;
949 + int result;
950 +
951 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
952 "1: ldrex %0, [%3]\n"
953 " sub %0, %0, %4\n"
954 " strex %1, %0, [%3]\n"
955 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
956 smp_mb();
957
958 __asm__ __volatile__("@ atomic_sub_return\n"
959 -"1: ldrex %0, [%3]\n"
960 -" sub %0, %0, %4\n"
961 +"1: ldrex %1, [%3]\n"
962 +" subs %0, %1, %4\n"
963 +
964 +#ifdef CONFIG_PAX_REFCOUNT
965 +" bvc 3f\n"
966 +" mov %0, %1\n"
967 +"2: bkpt 0xf103\n"
968 +"3:\n"
969 +#endif
970 +
971 " strex %1, %0, [%3]\n"
972 " teq %1, #0\n"
973 " bne 1b"
974 +
975 +#ifdef CONFIG_PAX_REFCOUNT
976 +"\n4:\n"
977 + _ASM_EXTABLE(2b, 4b)
978 +#endif
979 +
980 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
981 : "r" (&v->counter), "Ir" (i)
982 : "cc");
983 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
984 return oldval;
985 }
986
987 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
988 +{
989 + unsigned long oldval, res;
990 +
991 + smp_mb();
992 +
993 + do {
994 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
995 + "ldrex %1, [%3]\n"
996 + "mov %0, #0\n"
997 + "teq %1, %4\n"
998 + "strexeq %0, %5, [%3]\n"
999 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1000 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1001 + : "cc");
1002 + } while (res);
1003 +
1004 + smp_mb();
1005 +
1006 + return oldval;
1007 +}
1008 +
1009 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1010 {
1011 unsigned long tmp, tmp2;
1012 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1013
1014 return val;
1015 }
1016 +
1017 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1018 +{
1019 + return atomic_add_return(i, v);
1020 +}
1021 +
1022 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1023 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1024 +{
1025 + (void) atomic_add_return(i, v);
1026 +}
1027
1028 static inline int atomic_sub_return(int i, atomic_t *v)
1029 {
1030 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1031 return val;
1032 }
1033 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1034 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1035 +{
1036 + (void) atomic_sub_return(i, v);
1037 +}
1038
1039 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1040 {
1041 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1042 return ret;
1043 }
1044
1045 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1046 +{
1047 + return atomic_cmpxchg(v, old, new);
1048 +}
1049 +
1050 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1051 {
1052 unsigned long flags;
1053 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1054 #endif /* __LINUX_ARM_ARCH__ */
1055
1056 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1057 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1058 +{
1059 + return xchg(&v->counter, new);
1060 +}
1061
1062 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1063 {
1064 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1065 }
1066
1067 #define atomic_inc(v) atomic_add(1, v)
1068 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1069 +{
1070 + atomic_add_unchecked(1, v);
1071 +}
1072 #define atomic_dec(v) atomic_sub(1, v)
1073 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1074 +{
1075 + atomic_sub_unchecked(1, v);
1076 +}
1077
1078 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1079 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1080 +{
1081 + return atomic_add_return_unchecked(1, v) == 0;
1082 +}
1083 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1084 #define atomic_inc_return(v) (atomic_add_return(1, v))
1085 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1086 +{
1087 + return atomic_add_return_unchecked(1, v);
1088 +}
1089 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1090 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1091
1092 @@ -241,6 +428,14 @@ typedef struct {
1093 u64 __aligned(8) counter;
1094 } atomic64_t;
1095
1096 +#ifdef CONFIG_PAX_REFCOUNT
1097 +typedef struct {
1098 + u64 __aligned(8) counter;
1099 +} atomic64_unchecked_t;
1100 +#else
1101 +typedef atomic64_t atomic64_unchecked_t;
1102 +#endif
1103 +
1104 #define ATOMIC64_INIT(i) { (i) }
1105
1106 static inline u64 atomic64_read(const atomic64_t *v)
1107 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1108 return result;
1109 }
1110
1111 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1112 +{
1113 + u64 result;
1114 +
1115 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1116 +" ldrexd %0, %H0, [%1]"
1117 + : "=&r" (result)
1118 + : "r" (&v->counter), "Qo" (v->counter)
1119 + );
1120 +
1121 + return result;
1122 +}
1123 +
1124 static inline void atomic64_set(atomic64_t *v, u64 i)
1125 {
1126 u64 tmp;
1127 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1128 : "cc");
1129 }
1130
1131 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1132 +{
1133 + u64 tmp;
1134 +
1135 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1136 +"1: ldrexd %0, %H0, [%2]\n"
1137 +" strexd %0, %3, %H3, [%2]\n"
1138 +" teq %0, #0\n"
1139 +" bne 1b"
1140 + : "=&r" (tmp), "=Qo" (v->counter)
1141 + : "r" (&v->counter), "r" (i)
1142 + : "cc");
1143 +}
1144 +
1145 static inline void atomic64_add(u64 i, atomic64_t *v)
1146 {
1147 u64 result;
1148 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1149 __asm__ __volatile__("@ atomic64_add\n"
1150 "1: ldrexd %0, %H0, [%3]\n"
1151 " adds %0, %0, %4\n"
1152 +" adcs %H0, %H0, %H4\n"
1153 +
1154 +#ifdef CONFIG_PAX_REFCOUNT
1155 +" bvc 3f\n"
1156 +"2: bkpt 0xf103\n"
1157 +"3:\n"
1158 +#endif
1159 +
1160 +" strexd %1, %0, %H0, [%3]\n"
1161 +" teq %1, #0\n"
1162 +" bne 1b"
1163 +
1164 +#ifdef CONFIG_PAX_REFCOUNT
1165 +"\n4:\n"
1166 + _ASM_EXTABLE(2b, 4b)
1167 +#endif
1168 +
1169 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1170 + : "r" (&v->counter), "r" (i)
1171 + : "cc");
1172 +}
1173 +
1174 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1175 +{
1176 + u64 result;
1177 + unsigned long tmp;
1178 +
1179 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1180 +"1: ldrexd %0, %H0, [%3]\n"
1181 +" adds %0, %0, %4\n"
1182 " adc %H0, %H0, %H4\n"
1183 " strexd %1, %0, %H0, [%3]\n"
1184 " teq %1, #0\n"
1185 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1186
1187 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1188 {
1189 - u64 result;
1190 - unsigned long tmp;
1191 + u64 result, tmp;
1192
1193 smp_mb();
1194
1195 __asm__ __volatile__("@ atomic64_add_return\n"
1196 +"1: ldrexd %1, %H1, [%3]\n"
1197 +" adds %0, %1, %4\n"
1198 +" adcs %H0, %H1, %H4\n"
1199 +
1200 +#ifdef CONFIG_PAX_REFCOUNT
1201 +" bvc 3f\n"
1202 +" mov %0, %1\n"
1203 +" mov %H0, %H1\n"
1204 +"2: bkpt 0xf103\n"
1205 +"3:\n"
1206 +#endif
1207 +
1208 +" strexd %1, %0, %H0, [%3]\n"
1209 +" teq %1, #0\n"
1210 +" bne 1b"
1211 +
1212 +#ifdef CONFIG_PAX_REFCOUNT
1213 +"\n4:\n"
1214 + _ASM_EXTABLE(2b, 4b)
1215 +#endif
1216 +
1217 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1218 + : "r" (&v->counter), "r" (i)
1219 + : "cc");
1220 +
1221 + smp_mb();
1222 +
1223 + return result;
1224 +}
1225 +
1226 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1227 +{
1228 + u64 result;
1229 + unsigned long tmp;
1230 +
1231 + smp_mb();
1232 +
1233 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1234 "1: ldrexd %0, %H0, [%3]\n"
1235 " adds %0, %0, %4\n"
1236 " adc %H0, %H0, %H4\n"
1237 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1238 __asm__ __volatile__("@ atomic64_sub\n"
1239 "1: ldrexd %0, %H0, [%3]\n"
1240 " subs %0, %0, %4\n"
1241 +" sbcs %H0, %H0, %H4\n"
1242 +
1243 +#ifdef CONFIG_PAX_REFCOUNT
1244 +" bvc 3f\n"
1245 +"2: bkpt 0xf103\n"
1246 +"3:\n"
1247 +#endif
1248 +
1249 +" strexd %1, %0, %H0, [%3]\n"
1250 +" teq %1, #0\n"
1251 +" bne 1b"
1252 +
1253 +#ifdef CONFIG_PAX_REFCOUNT
1254 +"\n4:\n"
1255 + _ASM_EXTABLE(2b, 4b)
1256 +#endif
1257 +
1258 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1259 + : "r" (&v->counter), "r" (i)
1260 + : "cc");
1261 +}
1262 +
1263 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1264 +{
1265 + u64 result;
1266 + unsigned long tmp;
1267 +
1268 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1269 +"1: ldrexd %0, %H0, [%3]\n"
1270 +" subs %0, %0, %4\n"
1271 " sbc %H0, %H0, %H4\n"
1272 " strexd %1, %0, %H0, [%3]\n"
1273 " teq %1, #0\n"
1274 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1275
1276 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1277 {
1278 - u64 result;
1279 - unsigned long tmp;
1280 + u64 result, tmp;
1281
1282 smp_mb();
1283
1284 __asm__ __volatile__("@ atomic64_sub_return\n"
1285 -"1: ldrexd %0, %H0, [%3]\n"
1286 -" subs %0, %0, %4\n"
1287 -" sbc %H0, %H0, %H4\n"
1288 +"1: ldrexd %1, %H1, [%3]\n"
1289 +" subs %0, %1, %4\n"
1290 +" sbcs %H0, %H1, %H4\n"
1291 +
1292 +#ifdef CONFIG_PAX_REFCOUNT
1293 +" bvc 3f\n"
1294 +" mov %0, %1\n"
1295 +" mov %H0, %H1\n"
1296 +"2: bkpt 0xf103\n"
1297 +"3:\n"
1298 +#endif
1299 +
1300 " strexd %1, %0, %H0, [%3]\n"
1301 " teq %1, #0\n"
1302 " bne 1b"
1303 +
1304 +#ifdef CONFIG_PAX_REFCOUNT
1305 +"\n4:\n"
1306 + _ASM_EXTABLE(2b, 4b)
1307 +#endif
1308 +
1309 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1310 : "r" (&v->counter), "r" (i)
1311 : "cc");
1312 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1313 return oldval;
1314 }
1315
1316 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1317 +{
1318 + u64 oldval;
1319 + unsigned long res;
1320 +
1321 + smp_mb();
1322 +
1323 + do {
1324 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1325 + "ldrexd %1, %H1, [%3]\n"
1326 + "mov %0, #0\n"
1327 + "teq %1, %4\n"
1328 + "teqeq %H1, %H4\n"
1329 + "strexdeq %0, %5, %H5, [%3]"
1330 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1331 + : "r" (&ptr->counter), "r" (old), "r" (new)
1332 + : "cc");
1333 + } while (res);
1334 +
1335 + smp_mb();
1336 +
1337 + return oldval;
1338 +}
1339 +
1340 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1341 {
1342 u64 result;
1343 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1344
1345 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1346 {
1347 - u64 result;
1348 - unsigned long tmp;
1349 + u64 result, tmp;
1350
1351 smp_mb();
1352
1353 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1354 -"1: ldrexd %0, %H0, [%3]\n"
1355 -" subs %0, %0, #1\n"
1356 -" sbc %H0, %H0, #0\n"
1357 +"1: ldrexd %1, %H1, [%3]\n"
1358 +" subs %0, %1, #1\n"
1359 +" sbcs %H0, %H1, #0\n"
1360 +
1361 +#ifdef CONFIG_PAX_REFCOUNT
1362 +" bvc 3f\n"
1363 +" mov %0, %1\n"
1364 +" mov %H0, %H1\n"
1365 +"2: bkpt 0xf103\n"
1366 +"3:\n"
1367 +#endif
1368 +
1369 " teq %H0, #0\n"
1370 -" bmi 2f\n"
1371 +" bmi 4f\n"
1372 " strexd %1, %0, %H0, [%3]\n"
1373 " teq %1, #0\n"
1374 " bne 1b\n"
1375 -"2:"
1376 +"4:\n"
1377 +
1378 +#ifdef CONFIG_PAX_REFCOUNT
1379 + _ASM_EXTABLE(2b, 4b)
1380 +#endif
1381 +
1382 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1383 : "r" (&v->counter)
1384 : "cc");
1385 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1386 " teq %0, %5\n"
1387 " teqeq %H0, %H5\n"
1388 " moveq %1, #0\n"
1389 -" beq 2f\n"
1390 +" beq 4f\n"
1391 " adds %0, %0, %6\n"
1392 -" adc %H0, %H0, %H6\n"
1393 +" adcs %H0, %H0, %H6\n"
1394 +
1395 +#ifdef CONFIG_PAX_REFCOUNT
1396 +" bvc 3f\n"
1397 +"2: bkpt 0xf103\n"
1398 +"3:\n"
1399 +#endif
1400 +
1401 " strexd %2, %0, %H0, [%4]\n"
1402 " teq %2, #0\n"
1403 " bne 1b\n"
1404 -"2:"
1405 +"4:\n"
1406 +
1407 +#ifdef CONFIG_PAX_REFCOUNT
1408 + _ASM_EXTABLE(2b, 4b)
1409 +#endif
1410 +
1411 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1412 : "r" (&v->counter), "r" (u), "r" (a)
1413 : "cc");
1414 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1415
1416 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1417 #define atomic64_inc(v) atomic64_add(1LL, (v))
1418 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1419 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1420 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1421 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1422 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1423 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1424 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1425 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1426 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1427 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1428 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1429 index 75fe66b..2255c86 100644
1430 --- a/arch/arm/include/asm/cache.h
1431 +++ b/arch/arm/include/asm/cache.h
1432 @@ -4,8 +4,10 @@
1433 #ifndef __ASMARM_CACHE_H
1434 #define __ASMARM_CACHE_H
1435
1436 +#include <linux/const.h>
1437 +
1438 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1439 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1440 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1441
1442 /*
1443 * Memory returned by kmalloc() may be used for DMA, so we must make
1444 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1445 index 004c1bc..d9d6d91 100644
1446 --- a/arch/arm/include/asm/cacheflush.h
1447 +++ b/arch/arm/include/asm/cacheflush.h
1448 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1449 void (*dma_unmap_area)(const void *, size_t, int);
1450
1451 void (*dma_flush_range)(const void *, const void *);
1452 -};
1453 +} __no_const;
1454
1455 /*
1456 * Select the calling method
1457 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1458 index 7eb18c1..e38b6d2 100644
1459 --- a/arch/arm/include/asm/cmpxchg.h
1460 +++ b/arch/arm/include/asm/cmpxchg.h
1461 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1462
1463 #define xchg(ptr,x) \
1464 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1465 +#define xchg_unchecked(ptr,x) \
1466 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1467
1468 #include <asm-generic/cmpxchg-local.h>
1469
1470 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1471 index 38050b1..9d90e8b 100644
1472 --- a/arch/arm/include/asm/elf.h
1473 +++ b/arch/arm/include/asm/elf.h
1474 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1475 the loader. We need to make sure that it is out of the way of the program
1476 that it will "exec", and that there is sufficient room for the brk. */
1477
1478 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1479 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1480 +
1481 +#ifdef CONFIG_PAX_ASLR
1482 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1483 +
1484 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1485 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1486 +#endif
1487
1488 /* When the program starts, a1 contains a pointer to a function to be
1489 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1490 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1491 extern void elf_set_personality(const struct elf32_hdr *);
1492 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1493
1494 -struct mm_struct;
1495 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1496 -#define arch_randomize_brk arch_randomize_brk
1497 -
1498 #endif
1499 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1500 index e51b1e8..32a3113 100644
1501 --- a/arch/arm/include/asm/kmap_types.h
1502 +++ b/arch/arm/include/asm/kmap_types.h
1503 @@ -21,6 +21,7 @@ enum km_type {
1504 KM_L1_CACHE,
1505 KM_L2_CACHE,
1506 KM_KDB,
1507 + KM_CLEARPAGE,
1508 KM_TYPE_NR
1509 };
1510
1511 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1512 index 53426c6..c7baff3 100644
1513 --- a/arch/arm/include/asm/outercache.h
1514 +++ b/arch/arm/include/asm/outercache.h
1515 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1516 #endif
1517 void (*set_debug)(unsigned long);
1518 void (*resume)(void);
1519 -};
1520 +} __no_const;
1521
1522 #ifdef CONFIG_OUTER_CACHE
1523
1524 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1525 index ecf9019..b71d9a1 100644
1526 --- a/arch/arm/include/asm/page.h
1527 +++ b/arch/arm/include/asm/page.h
1528 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1529 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1530 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1531 unsigned long vaddr, struct vm_area_struct *vma);
1532 -};
1533 +} __no_const;
1534
1535 #ifdef MULTI_USER
1536 extern struct cpu_user_fns cpu_user;
1537 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1538 index 943504f..bf8d667 100644
1539 --- a/arch/arm/include/asm/pgalloc.h
1540 +++ b/arch/arm/include/asm/pgalloc.h
1541 @@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1542 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1543 }
1544
1545 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1546 +{
1547 + pud_populate(mm, pud, pmd);
1548 +}
1549 +
1550 #else /* !CONFIG_ARM_LPAE */
1551
1552 /*
1553 @@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1554 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1555 #define pmd_free(mm, pmd) do { } while (0)
1556 #define pud_populate(mm,pmd,pte) BUG()
1557 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1558
1559 #endif /* CONFIG_ARM_LPAE */
1560
1561 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1562 index af7b0bd..6750a8c 100644
1563 --- a/arch/arm/include/asm/thread_info.h
1564 +++ b/arch/arm/include/asm/thread_info.h
1565 @@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1566 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1567 #define TIF_SYSCALL_TRACE 8
1568 #define TIF_SYSCALL_AUDIT 9
1569 +
1570 +/* within 8 bits of TIF_SYSCALL_TRACE
1571 + to meet flexible second operand requirements
1572 +*/
1573 +#define TIF_GRSEC_SETXID 10
1574 +
1575 #define TIF_POLLING_NRFLAG 16
1576 #define TIF_USING_IWMMXT 17
1577 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1578 @@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1579 #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
1580 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1581 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1582 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1583
1584 /* Checks for any syscall work in entry-common.S */
1585 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1586 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1587 + _TIF_GRSEC_SETXID)
1588
1589 /*
1590 * Change these and you break ASM code in entry-common.S
1591 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1592 index 71f6536..602f279 100644
1593 --- a/arch/arm/include/asm/uaccess.h
1594 +++ b/arch/arm/include/asm/uaccess.h
1595 @@ -22,6 +22,8 @@
1596 #define VERIFY_READ 0
1597 #define VERIFY_WRITE 1
1598
1599 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1600 +
1601 /*
1602 * The exception table consists of pairs of addresses: the first is the
1603 * address of an instruction that is allowed to fault, and the second is
1604 @@ -387,8 +389,23 @@ do { \
1605
1606
1607 #ifdef CONFIG_MMU
1608 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1609 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1610 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1611 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1612 +
1613 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1614 +{
1615 + if (!__builtin_constant_p(n))
1616 + check_object_size(to, n, false);
1617 + return ___copy_from_user(to, from, n);
1618 +}
1619 +
1620 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1621 +{
1622 + if (!__builtin_constant_p(n))
1623 + check_object_size(from, n, true);
1624 + return ___copy_to_user(to, from, n);
1625 +}
1626 +
1627 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1628 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1629 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1630 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1631
1632 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1633 {
1634 + if ((long)n < 0)
1635 + return n;
1636 +
1637 if (access_ok(VERIFY_READ, from, n))
1638 n = __copy_from_user(to, from, n);
1639 else /* security hole - plug it */
1640 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1641
1642 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1643 {
1644 + if ((long)n < 0)
1645 + return n;
1646 +
1647 if (access_ok(VERIFY_WRITE, to, n))
1648 n = __copy_to_user(to, from, n);
1649 return n;
1650 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1651 index b57c75e..ed2d6b2 100644
1652 --- a/arch/arm/kernel/armksyms.c
1653 +++ b/arch/arm/kernel/armksyms.c
1654 @@ -94,8 +94,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1655 #ifdef CONFIG_MMU
1656 EXPORT_SYMBOL(copy_page);
1657
1658 -EXPORT_SYMBOL(__copy_from_user);
1659 -EXPORT_SYMBOL(__copy_to_user);
1660 +EXPORT_SYMBOL(___copy_from_user);
1661 +EXPORT_SYMBOL(___copy_to_user);
1662 EXPORT_SYMBOL(__clear_user);
1663
1664 EXPORT_SYMBOL(__get_user_1);
1665 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1666 index 19c95ea..7160f7c 100644
1667 --- a/arch/arm/kernel/process.c
1668 +++ b/arch/arm/kernel/process.c
1669 @@ -28,7 +28,6 @@
1670 #include <linux/tick.h>
1671 #include <linux/utsname.h>
1672 #include <linux/uaccess.h>
1673 -#include <linux/random.h>
1674 #include <linux/hw_breakpoint.h>
1675 #include <linux/cpuidle.h>
1676
1677 @@ -255,9 +254,10 @@ void machine_power_off(void)
1678 machine_shutdown();
1679 if (pm_power_off)
1680 pm_power_off();
1681 + BUG();
1682 }
1683
1684 -void machine_restart(char *cmd)
1685 +__noreturn void machine_restart(char *cmd)
1686 {
1687 machine_shutdown();
1688
1689 @@ -499,12 +499,6 @@ unsigned long get_wchan(struct task_struct *p)
1690 return 0;
1691 }
1692
1693 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1694 -{
1695 - unsigned long range_end = mm->brk + 0x02000000;
1696 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1697 -}
1698 -
1699 #ifdef CONFIG_MMU
1700 /*
1701 * The vectors page is always readable from user space for the
1702 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1703 index 14e3826..d832d89 100644
1704 --- a/arch/arm/kernel/ptrace.c
1705 +++ b/arch/arm/kernel/ptrace.c
1706 @@ -907,10 +907,19 @@ long arch_ptrace(struct task_struct *child, long request,
1707 return ret;
1708 }
1709
1710 +#ifdef CONFIG_GRKERNSEC_SETXID
1711 +extern void gr_delayed_cred_worker(void);
1712 +#endif
1713 +
1714 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
1715 {
1716 unsigned long ip;
1717
1718 +#ifdef CONFIG_GRKERNSEC_SETXID
1719 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1720 + gr_delayed_cred_worker();
1721 +#endif
1722 +
1723 if (why)
1724 audit_syscall_exit(regs);
1725 else
1726 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1727 index e15d83b..8c466dd 100644
1728 --- a/arch/arm/kernel/setup.c
1729 +++ b/arch/arm/kernel/setup.c
1730 @@ -112,13 +112,13 @@ struct processor processor __read_mostly;
1731 struct cpu_tlb_fns cpu_tlb __read_mostly;
1732 #endif
1733 #ifdef MULTI_USER
1734 -struct cpu_user_fns cpu_user __read_mostly;
1735 +struct cpu_user_fns cpu_user __read_only;
1736 #endif
1737 #ifdef MULTI_CACHE
1738 -struct cpu_cache_fns cpu_cache __read_mostly;
1739 +struct cpu_cache_fns cpu_cache __read_only;
1740 #endif
1741 #ifdef CONFIG_OUTER_CACHE
1742 -struct outer_cache_fns outer_cache __read_mostly;
1743 +struct outer_cache_fns outer_cache __read_only;
1744 EXPORT_SYMBOL(outer_cache);
1745 #endif
1746
1747 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1748 index 3647170..065e1cd 100644
1749 --- a/arch/arm/kernel/traps.c
1750 +++ b/arch/arm/kernel/traps.c
1751 @@ -264,6 +264,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1752
1753 static DEFINE_RAW_SPINLOCK(die_lock);
1754
1755 +extern void gr_handle_kernel_exploit(void);
1756 +
1757 /*
1758 * This function is protected against re-entrancy.
1759 */
1760 @@ -296,6 +298,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1761 panic("Fatal exception in interrupt");
1762 if (panic_on_oops)
1763 panic("Fatal exception");
1764 +
1765 + gr_handle_kernel_exploit();
1766 +
1767 if (ret != NOTIFY_STOP)
1768 do_exit(SIGSEGV);
1769 }
1770 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1771 index 66a477a..bee61d3 100644
1772 --- a/arch/arm/lib/copy_from_user.S
1773 +++ b/arch/arm/lib/copy_from_user.S
1774 @@ -16,7 +16,7 @@
1775 /*
1776 * Prototype:
1777 *
1778 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1779 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1780 *
1781 * Purpose:
1782 *
1783 @@ -84,11 +84,11 @@
1784
1785 .text
1786
1787 -ENTRY(__copy_from_user)
1788 +ENTRY(___copy_from_user)
1789
1790 #include "copy_template.S"
1791
1792 -ENDPROC(__copy_from_user)
1793 +ENDPROC(___copy_from_user)
1794
1795 .pushsection .fixup,"ax"
1796 .align 0
1797 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1798 index 6ee2f67..d1cce76 100644
1799 --- a/arch/arm/lib/copy_page.S
1800 +++ b/arch/arm/lib/copy_page.S
1801 @@ -10,6 +10,7 @@
1802 * ASM optimised string functions
1803 */
1804 #include <linux/linkage.h>
1805 +#include <linux/const.h>
1806 #include <asm/assembler.h>
1807 #include <asm/asm-offsets.h>
1808 #include <asm/cache.h>
1809 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1810 index d066df6..df28194 100644
1811 --- a/arch/arm/lib/copy_to_user.S
1812 +++ b/arch/arm/lib/copy_to_user.S
1813 @@ -16,7 +16,7 @@
1814 /*
1815 * Prototype:
1816 *
1817 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1818 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1819 *
1820 * Purpose:
1821 *
1822 @@ -88,11 +88,11 @@
1823 .text
1824
1825 ENTRY(__copy_to_user_std)
1826 -WEAK(__copy_to_user)
1827 +WEAK(___copy_to_user)
1828
1829 #include "copy_template.S"
1830
1831 -ENDPROC(__copy_to_user)
1832 +ENDPROC(___copy_to_user)
1833 ENDPROC(__copy_to_user_std)
1834
1835 .pushsection .fixup,"ax"
1836 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1837 index 025f742..8432b08 100644
1838 --- a/arch/arm/lib/uaccess_with_memcpy.c
1839 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1840 @@ -104,7 +104,7 @@ out:
1841 }
1842
1843 unsigned long
1844 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1845 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1846 {
1847 /*
1848 * This test is stubbed out of the main function above to keep
1849 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
1850 index f261cd2..4ae63fb 100644
1851 --- a/arch/arm/mach-kirkwood/common.c
1852 +++ b/arch/arm/mach-kirkwood/common.c
1853 @@ -128,7 +128,7 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
1854 clk_gate_ops.disable(hw);
1855 }
1856
1857 -static struct clk_ops clk_gate_fn_ops;
1858 +static clk_ops_no_const clk_gate_fn_ops;
1859
1860 static struct clk __init *clk_register_gate_fn(struct device *dev,
1861 const char *name,
1862 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1863 index 2c5d0ed..7d9099c 100644
1864 --- a/arch/arm/mach-omap2/board-n8x0.c
1865 +++ b/arch/arm/mach-omap2/board-n8x0.c
1866 @@ -594,7 +594,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1867 }
1868 #endif
1869
1870 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1871 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1872 .late_init = n8x0_menelaus_late_init,
1873 };
1874
1875 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1876 index c3bd834..e81ef02 100644
1877 --- a/arch/arm/mm/fault.c
1878 +++ b/arch/arm/mm/fault.c
1879 @@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1880 }
1881 #endif
1882
1883 +#ifdef CONFIG_PAX_PAGEEXEC
1884 + if (fsr & FSR_LNX_PF) {
1885 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1886 + do_group_exit(SIGKILL);
1887 + }
1888 +#endif
1889 +
1890 tsk->thread.address = addr;
1891 tsk->thread.error_code = fsr;
1892 tsk->thread.trap_no = 14;
1893 @@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1894 }
1895 #endif /* CONFIG_MMU */
1896
1897 +#ifdef CONFIG_PAX_PAGEEXEC
1898 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1899 +{
1900 + long i;
1901 +
1902 + printk(KERN_ERR "PAX: bytes at PC: ");
1903 + for (i = 0; i < 20; i++) {
1904 + unsigned char c;
1905 + if (get_user(c, (__force unsigned char __user *)pc+i))
1906 + printk(KERN_CONT "?? ");
1907 + else
1908 + printk(KERN_CONT "%02x ", c);
1909 + }
1910 + printk("\n");
1911 +
1912 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1913 + for (i = -1; i < 20; i++) {
1914 + unsigned long c;
1915 + if (get_user(c, (__force unsigned long __user *)sp+i))
1916 + printk(KERN_CONT "???????? ");
1917 + else
1918 + printk(KERN_CONT "%08lx ", c);
1919 + }
1920 + printk("\n");
1921 +}
1922 +#endif
1923 +
1924 /*
1925 * First Level Translation Fault Handler
1926 *
1927 @@ -574,6 +608,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1928 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1929 struct siginfo info;
1930
1931 +#ifdef CONFIG_PAX_REFCOUNT
1932 + if (fsr_fs(ifsr) == 2) {
1933 + unsigned int bkpt;
1934 +
1935 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1936 + current->thread.error_code = ifsr;
1937 + current->thread.trap_no = 0;
1938 + pax_report_refcount_overflow(regs);
1939 + fixup_exception(regs);
1940 + return;
1941 + }
1942 + }
1943 +#endif
1944 +
1945 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1946 return;
1947
1948 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1949 index ce8cb19..3ec539d 100644
1950 --- a/arch/arm/mm/mmap.c
1951 +++ b/arch/arm/mm/mmap.c
1952 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1953 if (len > TASK_SIZE)
1954 return -ENOMEM;
1955
1956 +#ifdef CONFIG_PAX_RANDMMAP
1957 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1958 +#endif
1959 +
1960 if (addr) {
1961 if (do_align)
1962 addr = COLOUR_ALIGN(addr, pgoff);
1963 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1964 addr = PAGE_ALIGN(addr);
1965
1966 vma = find_vma(mm, addr);
1967 - if (TASK_SIZE - len >= addr &&
1968 - (!vma || addr + len <= vma->vm_start))
1969 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1970 return addr;
1971 }
1972 if (len > mm->cached_hole_size) {
1973 - start_addr = addr = mm->free_area_cache;
1974 + start_addr = addr = mm->free_area_cache;
1975 } else {
1976 - start_addr = addr = mm->mmap_base;
1977 - mm->cached_hole_size = 0;
1978 + start_addr = addr = mm->mmap_base;
1979 + mm->cached_hole_size = 0;
1980 }
1981
1982 full_search:
1983 @@ -124,14 +127,14 @@ full_search:
1984 * Start a new search - just in case we missed
1985 * some holes.
1986 */
1987 - if (start_addr != TASK_UNMAPPED_BASE) {
1988 - start_addr = addr = TASK_UNMAPPED_BASE;
1989 + if (start_addr != mm->mmap_base) {
1990 + start_addr = addr = mm->mmap_base;
1991 mm->cached_hole_size = 0;
1992 goto full_search;
1993 }
1994 return -ENOMEM;
1995 }
1996 - if (!vma || addr + len <= vma->vm_start) {
1997 + if (check_heap_stack_gap(vma, addr, len)) {
1998 /*
1999 * Remember the place where we stopped the search:
2000 */
2001 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2002
2003 if (mmap_is_legacy()) {
2004 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2005 +
2006 +#ifdef CONFIG_PAX_RANDMMAP
2007 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2008 + mm->mmap_base += mm->delta_mmap;
2009 +#endif
2010 +
2011 mm->get_unmapped_area = arch_get_unmapped_area;
2012 mm->unmap_area = arch_unmap_area;
2013 } else {
2014 mm->mmap_base = mmap_base(random_factor);
2015 +
2016 +#ifdef CONFIG_PAX_RANDMMAP
2017 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2018 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2019 +#endif
2020 +
2021 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2022 mm->unmap_area = arch_unmap_area_topdown;
2023 }
2024 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2025 index fd556f7..af2e7d2 100644
2026 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2027 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2028 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2029 value in bridge_virt_base */
2030 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2031 const int win);
2032 -};
2033 +} __no_const;
2034
2035 /*
2036 * Information needed to setup one address mapping.
2037 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2038 index 71a6827..e7fbc23 100644
2039 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2040 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2041 @@ -43,7 +43,7 @@ struct samsung_dma_ops {
2042 int (*started)(unsigned ch);
2043 int (*flush)(unsigned ch);
2044 int (*stop)(unsigned ch);
2045 -};
2046 +} __no_const;
2047
2048 extern void *samsung_dmadev_get_ops(void);
2049 extern void *s3c_dma_get_ops(void);
2050 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2051 index 5f28cae..3d23723 100644
2052 --- a/arch/arm/plat-samsung/include/plat/ehci.h
2053 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
2054 @@ -14,7 +14,7 @@
2055 struct s5p_ehci_platdata {
2056 int (*phy_init)(struct platform_device *pdev, int type);
2057 int (*phy_exit)(struct platform_device *pdev, int type);
2058 -};
2059 +} __no_const;
2060
2061 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2062
2063 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2064 index c3a58a1..78fbf54 100644
2065 --- a/arch/avr32/include/asm/cache.h
2066 +++ b/arch/avr32/include/asm/cache.h
2067 @@ -1,8 +1,10 @@
2068 #ifndef __ASM_AVR32_CACHE_H
2069 #define __ASM_AVR32_CACHE_H
2070
2071 +#include <linux/const.h>
2072 +
2073 #define L1_CACHE_SHIFT 5
2074 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2075 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2076
2077 /*
2078 * Memory returned by kmalloc() may be used for DMA, so we must make
2079 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2080 index 3b3159b..425ea94 100644
2081 --- a/arch/avr32/include/asm/elf.h
2082 +++ b/arch/avr32/include/asm/elf.h
2083 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2084 the loader. We need to make sure that it is out of the way of the program
2085 that it will "exec", and that there is sufficient room for the brk. */
2086
2087 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2088 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2089
2090 +#ifdef CONFIG_PAX_ASLR
2091 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2092 +
2093 +#define PAX_DELTA_MMAP_LEN 15
2094 +#define PAX_DELTA_STACK_LEN 15
2095 +#endif
2096
2097 /* This yields a mask that user programs can use to figure out what
2098 instruction set this CPU supports. This could be done in user space,
2099 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2100 index b7f5c68..556135c 100644
2101 --- a/arch/avr32/include/asm/kmap_types.h
2102 +++ b/arch/avr32/include/asm/kmap_types.h
2103 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2104 D(11) KM_IRQ1,
2105 D(12) KM_SOFTIRQ0,
2106 D(13) KM_SOFTIRQ1,
2107 -D(14) KM_TYPE_NR
2108 +D(14) KM_CLEARPAGE,
2109 +D(15) KM_TYPE_NR
2110 };
2111
2112 #undef D
2113 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2114 index f7040a1..db9f300 100644
2115 --- a/arch/avr32/mm/fault.c
2116 +++ b/arch/avr32/mm/fault.c
2117 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2118
2119 int exception_trace = 1;
2120
2121 +#ifdef CONFIG_PAX_PAGEEXEC
2122 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2123 +{
2124 + unsigned long i;
2125 +
2126 + printk(KERN_ERR "PAX: bytes at PC: ");
2127 + for (i = 0; i < 20; i++) {
2128 + unsigned char c;
2129 + if (get_user(c, (unsigned char *)pc+i))
2130 + printk(KERN_CONT "???????? ");
2131 + else
2132 + printk(KERN_CONT "%02x ", c);
2133 + }
2134 + printk("\n");
2135 +}
2136 +#endif
2137 +
2138 /*
2139 * This routine handles page faults. It determines the address and the
2140 * problem, and then passes it off to one of the appropriate routines.
2141 @@ -156,6 +173,16 @@ bad_area:
2142 up_read(&mm->mmap_sem);
2143
2144 if (user_mode(regs)) {
2145 +
2146 +#ifdef CONFIG_PAX_PAGEEXEC
2147 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2148 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2149 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2150 + do_group_exit(SIGKILL);
2151 + }
2152 + }
2153 +#endif
2154 +
2155 if (exception_trace && printk_ratelimit())
2156 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2157 "sp %08lx ecr %lu\n",
2158 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2159 index 568885a..f8008df 100644
2160 --- a/arch/blackfin/include/asm/cache.h
2161 +++ b/arch/blackfin/include/asm/cache.h
2162 @@ -7,6 +7,7 @@
2163 #ifndef __ARCH_BLACKFIN_CACHE_H
2164 #define __ARCH_BLACKFIN_CACHE_H
2165
2166 +#include <linux/const.h>
2167 #include <linux/linkage.h> /* for asmlinkage */
2168
2169 /*
2170 @@ -14,7 +15,7 @@
2171 * Blackfin loads 32 bytes for cache
2172 */
2173 #define L1_CACHE_SHIFT 5
2174 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2175 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2176 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2177
2178 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2179 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2180 index aea2718..3639a60 100644
2181 --- a/arch/cris/include/arch-v10/arch/cache.h
2182 +++ b/arch/cris/include/arch-v10/arch/cache.h
2183 @@ -1,8 +1,9 @@
2184 #ifndef _ASM_ARCH_CACHE_H
2185 #define _ASM_ARCH_CACHE_H
2186
2187 +#include <linux/const.h>
2188 /* Etrax 100LX have 32-byte cache-lines. */
2189 -#define L1_CACHE_BYTES 32
2190 #define L1_CACHE_SHIFT 5
2191 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2192
2193 #endif /* _ASM_ARCH_CACHE_H */
2194 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2195 index 7caf25d..ee65ac5 100644
2196 --- a/arch/cris/include/arch-v32/arch/cache.h
2197 +++ b/arch/cris/include/arch-v32/arch/cache.h
2198 @@ -1,11 +1,12 @@
2199 #ifndef _ASM_CRIS_ARCH_CACHE_H
2200 #define _ASM_CRIS_ARCH_CACHE_H
2201
2202 +#include <linux/const.h>
2203 #include <arch/hwregs/dma.h>
2204
2205 /* A cache-line is 32 bytes. */
2206 -#define L1_CACHE_BYTES 32
2207 #define L1_CACHE_SHIFT 5
2208 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2209
2210 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2211
2212 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2213 index b86329d..6709906 100644
2214 --- a/arch/frv/include/asm/atomic.h
2215 +++ b/arch/frv/include/asm/atomic.h
2216 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2217 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2218 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2219
2220 +#define atomic64_read_unchecked(v) atomic64_read(v)
2221 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2222 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2223 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2224 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2225 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2226 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2227 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2228 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2229 +
2230 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2231 {
2232 int c, old;
2233 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2234 index 2797163..c2a401d 100644
2235 --- a/arch/frv/include/asm/cache.h
2236 +++ b/arch/frv/include/asm/cache.h
2237 @@ -12,10 +12,11 @@
2238 #ifndef __ASM_CACHE_H
2239 #define __ASM_CACHE_H
2240
2241 +#include <linux/const.h>
2242
2243 /* bytes per L1 cache line */
2244 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2245 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2246 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2247
2248 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2249 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2250 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2251 index f8e16b2..c73ff79 100644
2252 --- a/arch/frv/include/asm/kmap_types.h
2253 +++ b/arch/frv/include/asm/kmap_types.h
2254 @@ -23,6 +23,7 @@ enum km_type {
2255 KM_IRQ1,
2256 KM_SOFTIRQ0,
2257 KM_SOFTIRQ1,
2258 + KM_CLEARPAGE,
2259 KM_TYPE_NR
2260 };
2261
2262 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2263 index 385fd30..6c3d97e 100644
2264 --- a/arch/frv/mm/elf-fdpic.c
2265 +++ b/arch/frv/mm/elf-fdpic.c
2266 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2267 if (addr) {
2268 addr = PAGE_ALIGN(addr);
2269 vma = find_vma(current->mm, addr);
2270 - if (TASK_SIZE - len >= addr &&
2271 - (!vma || addr + len <= vma->vm_start))
2272 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2273 goto success;
2274 }
2275
2276 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2277 for (; vma; vma = vma->vm_next) {
2278 if (addr > limit)
2279 break;
2280 - if (addr + len <= vma->vm_start)
2281 + if (check_heap_stack_gap(vma, addr, len))
2282 goto success;
2283 addr = vma->vm_end;
2284 }
2285 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2286 for (; vma; vma = vma->vm_next) {
2287 if (addr > limit)
2288 break;
2289 - if (addr + len <= vma->vm_start)
2290 + if (check_heap_stack_gap(vma, addr, len))
2291 goto success;
2292 addr = vma->vm_end;
2293 }
2294 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2295 index c635028..6d9445a 100644
2296 --- a/arch/h8300/include/asm/cache.h
2297 +++ b/arch/h8300/include/asm/cache.h
2298 @@ -1,8 +1,10 @@
2299 #ifndef __ARCH_H8300_CACHE_H
2300 #define __ARCH_H8300_CACHE_H
2301
2302 +#include <linux/const.h>
2303 +
2304 /* bytes per L1 cache line */
2305 -#define L1_CACHE_BYTES 4
2306 +#define L1_CACHE_BYTES _AC(4,UL)
2307
2308 /* m68k-elf-gcc 2.95.2 doesn't like these */
2309
2310 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2311 index 0f01de2..d37d309 100644
2312 --- a/arch/hexagon/include/asm/cache.h
2313 +++ b/arch/hexagon/include/asm/cache.h
2314 @@ -21,9 +21,11 @@
2315 #ifndef __ASM_CACHE_H
2316 #define __ASM_CACHE_H
2317
2318 +#include <linux/const.h>
2319 +
2320 /* Bytes per L1 cache line */
2321 -#define L1_CACHE_SHIFT (5)
2322 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2323 +#define L1_CACHE_SHIFT 5
2324 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2325
2326 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2327 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2328 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2329 index 7d91166..88ab87e 100644
2330 --- a/arch/ia64/include/asm/atomic.h
2331 +++ b/arch/ia64/include/asm/atomic.h
2332 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2333 #define atomic64_inc(v) atomic64_add(1, (v))
2334 #define atomic64_dec(v) atomic64_sub(1, (v))
2335
2336 +#define atomic64_read_unchecked(v) atomic64_read(v)
2337 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2338 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2339 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2340 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2341 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2342 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2343 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2344 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2345 +
2346 /* Atomic operations are already serializing */
2347 #define smp_mb__before_atomic_dec() barrier()
2348 #define smp_mb__after_atomic_dec() barrier()
2349 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2350 index 988254a..e1ee885 100644
2351 --- a/arch/ia64/include/asm/cache.h
2352 +++ b/arch/ia64/include/asm/cache.h
2353 @@ -1,6 +1,7 @@
2354 #ifndef _ASM_IA64_CACHE_H
2355 #define _ASM_IA64_CACHE_H
2356
2357 +#include <linux/const.h>
2358
2359 /*
2360 * Copyright (C) 1998-2000 Hewlett-Packard Co
2361 @@ -9,7 +10,7 @@
2362
2363 /* Bytes per L1 (data) cache line. */
2364 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2365 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2366 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2367
2368 #ifdef CONFIG_SMP
2369 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2370 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2371 index b5298eb..67c6e62 100644
2372 --- a/arch/ia64/include/asm/elf.h
2373 +++ b/arch/ia64/include/asm/elf.h
2374 @@ -42,6 +42,13 @@
2375 */
2376 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2377
2378 +#ifdef CONFIG_PAX_ASLR
2379 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2380 +
2381 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2382 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2383 +#endif
2384 +
2385 #define PT_IA_64_UNWIND 0x70000001
2386
2387 /* IA-64 relocations: */
2388 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2389 index 96a8d92..617a1cf 100644
2390 --- a/arch/ia64/include/asm/pgalloc.h
2391 +++ b/arch/ia64/include/asm/pgalloc.h
2392 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2393 pgd_val(*pgd_entry) = __pa(pud);
2394 }
2395
2396 +static inline void
2397 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2398 +{
2399 + pgd_populate(mm, pgd_entry, pud);
2400 +}
2401 +
2402 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2403 {
2404 return quicklist_alloc(0, GFP_KERNEL, NULL);
2405 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2406 pud_val(*pud_entry) = __pa(pmd);
2407 }
2408
2409 +static inline void
2410 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2411 +{
2412 + pud_populate(mm, pud_entry, pmd);
2413 +}
2414 +
2415 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2416 {
2417 return quicklist_alloc(0, GFP_KERNEL, NULL);
2418 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2419 index 815810c..d60bd4c 100644
2420 --- a/arch/ia64/include/asm/pgtable.h
2421 +++ b/arch/ia64/include/asm/pgtable.h
2422 @@ -12,7 +12,7 @@
2423 * David Mosberger-Tang <davidm@hpl.hp.com>
2424 */
2425
2426 -
2427 +#include <linux/const.h>
2428 #include <asm/mman.h>
2429 #include <asm/page.h>
2430 #include <asm/processor.h>
2431 @@ -142,6 +142,17 @@
2432 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2433 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2434 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2435 +
2436 +#ifdef CONFIG_PAX_PAGEEXEC
2437 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2438 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2439 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2440 +#else
2441 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2442 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2443 +# define PAGE_COPY_NOEXEC PAGE_COPY
2444 +#endif
2445 +
2446 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2447 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2448 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2449 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2450 index 54ff557..70c88b7 100644
2451 --- a/arch/ia64/include/asm/spinlock.h
2452 +++ b/arch/ia64/include/asm/spinlock.h
2453 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2454 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2455
2456 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2457 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2458 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2459 }
2460
2461 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2462 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2463 index 449c8c0..432a3d2 100644
2464 --- a/arch/ia64/include/asm/uaccess.h
2465 +++ b/arch/ia64/include/asm/uaccess.h
2466 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2467 const void *__cu_from = (from); \
2468 long __cu_len = (n); \
2469 \
2470 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2471 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2472 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2473 __cu_len; \
2474 })
2475 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2476 long __cu_len = (n); \
2477 \
2478 __chk_user_ptr(__cu_from); \
2479 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2480 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2481 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2482 __cu_len; \
2483 })
2484 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2485 index 24603be..948052d 100644
2486 --- a/arch/ia64/kernel/module.c
2487 +++ b/arch/ia64/kernel/module.c
2488 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2489 void
2490 module_free (struct module *mod, void *module_region)
2491 {
2492 - if (mod && mod->arch.init_unw_table &&
2493 - module_region == mod->module_init) {
2494 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2495 unw_remove_unwind_table(mod->arch.init_unw_table);
2496 mod->arch.init_unw_table = NULL;
2497 }
2498 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2499 }
2500
2501 static inline int
2502 +in_init_rx (const struct module *mod, uint64_t addr)
2503 +{
2504 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2505 +}
2506 +
2507 +static inline int
2508 +in_init_rw (const struct module *mod, uint64_t addr)
2509 +{
2510 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2511 +}
2512 +
2513 +static inline int
2514 in_init (const struct module *mod, uint64_t addr)
2515 {
2516 - return addr - (uint64_t) mod->module_init < mod->init_size;
2517 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2518 +}
2519 +
2520 +static inline int
2521 +in_core_rx (const struct module *mod, uint64_t addr)
2522 +{
2523 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2524 +}
2525 +
2526 +static inline int
2527 +in_core_rw (const struct module *mod, uint64_t addr)
2528 +{
2529 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2530 }
2531
2532 static inline int
2533 in_core (const struct module *mod, uint64_t addr)
2534 {
2535 - return addr - (uint64_t) mod->module_core < mod->core_size;
2536 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2537 }
2538
2539 static inline int
2540 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2541 break;
2542
2543 case RV_BDREL:
2544 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2545 + if (in_init_rx(mod, val))
2546 + val -= (uint64_t) mod->module_init_rx;
2547 + else if (in_init_rw(mod, val))
2548 + val -= (uint64_t) mod->module_init_rw;
2549 + else if (in_core_rx(mod, val))
2550 + val -= (uint64_t) mod->module_core_rx;
2551 + else if (in_core_rw(mod, val))
2552 + val -= (uint64_t) mod->module_core_rw;
2553 break;
2554
2555 case RV_LTV:
2556 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2557 * addresses have been selected...
2558 */
2559 uint64_t gp;
2560 - if (mod->core_size > MAX_LTOFF)
2561 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2562 /*
2563 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2564 * at the end of the module.
2565 */
2566 - gp = mod->core_size - MAX_LTOFF / 2;
2567 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2568 else
2569 - gp = mod->core_size / 2;
2570 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2571 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2572 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2573 mod->arch.gp = gp;
2574 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2575 }
2576 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2577 index d9439ef..b9a4303 100644
2578 --- a/arch/ia64/kernel/sys_ia64.c
2579 +++ b/arch/ia64/kernel/sys_ia64.c
2580 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2581 if (REGION_NUMBER(addr) == RGN_HPAGE)
2582 addr = 0;
2583 #endif
2584 +
2585 +#ifdef CONFIG_PAX_RANDMMAP
2586 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2587 + addr = mm->free_area_cache;
2588 + else
2589 +#endif
2590 +
2591 if (!addr)
2592 addr = mm->free_area_cache;
2593
2594 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2595 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2596 /* At this point: (!vma || addr < vma->vm_end). */
2597 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2598 - if (start_addr != TASK_UNMAPPED_BASE) {
2599 + if (start_addr != mm->mmap_base) {
2600 /* Start a new search --- just in case we missed some holes. */
2601 - addr = TASK_UNMAPPED_BASE;
2602 + addr = mm->mmap_base;
2603 goto full_search;
2604 }
2605 return -ENOMEM;
2606 }
2607 - if (!vma || addr + len <= vma->vm_start) {
2608 + if (check_heap_stack_gap(vma, addr, len)) {
2609 /* Remember the address where we stopped this search: */
2610 mm->free_area_cache = addr + len;
2611 return addr;
2612 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2613 index 0ccb28f..8992469 100644
2614 --- a/arch/ia64/kernel/vmlinux.lds.S
2615 +++ b/arch/ia64/kernel/vmlinux.lds.S
2616 @@ -198,7 +198,7 @@ SECTIONS {
2617 /* Per-cpu data: */
2618 . = ALIGN(PERCPU_PAGE_SIZE);
2619 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2620 - __phys_per_cpu_start = __per_cpu_load;
2621 + __phys_per_cpu_start = per_cpu_load;
2622 /*
2623 * ensure percpu data fits
2624 * into percpu page size
2625 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2626 index 02d29c2..ea893df 100644
2627 --- a/arch/ia64/mm/fault.c
2628 +++ b/arch/ia64/mm/fault.c
2629 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2630 return pte_present(pte);
2631 }
2632
2633 +#ifdef CONFIG_PAX_PAGEEXEC
2634 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2635 +{
2636 + unsigned long i;
2637 +
2638 + printk(KERN_ERR "PAX: bytes at PC: ");
2639 + for (i = 0; i < 8; i++) {
2640 + unsigned int c;
2641 + if (get_user(c, (unsigned int *)pc+i))
2642 + printk(KERN_CONT "???????? ");
2643 + else
2644 + printk(KERN_CONT "%08x ", c);
2645 + }
2646 + printk("\n");
2647 +}
2648 +#endif
2649 +
2650 void __kprobes
2651 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2652 {
2653 @@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2654 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2655 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2656
2657 - if ((vma->vm_flags & mask) != mask)
2658 + if ((vma->vm_flags & mask) != mask) {
2659 +
2660 +#ifdef CONFIG_PAX_PAGEEXEC
2661 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2662 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2663 + goto bad_area;
2664 +
2665 + up_read(&mm->mmap_sem);
2666 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2667 + do_group_exit(SIGKILL);
2668 + }
2669 +#endif
2670 +
2671 goto bad_area;
2672
2673 + }
2674 +
2675 /*
2676 * If for any reason at all we couldn't handle the fault, make
2677 * sure we exit gracefully rather than endlessly redo the
2678 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2679 index 5ca674b..e0e1b70 100644
2680 --- a/arch/ia64/mm/hugetlbpage.c
2681 +++ b/arch/ia64/mm/hugetlbpage.c
2682 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2683 /* At this point: (!vmm || addr < vmm->vm_end). */
2684 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2685 return -ENOMEM;
2686 - if (!vmm || (addr + len) <= vmm->vm_start)
2687 + if (check_heap_stack_gap(vmm, addr, len))
2688 return addr;
2689 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2690 }
2691 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2692 index 0eab454..bd794f2 100644
2693 --- a/arch/ia64/mm/init.c
2694 +++ b/arch/ia64/mm/init.c
2695 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2696 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2697 vma->vm_end = vma->vm_start + PAGE_SIZE;
2698 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2699 +
2700 +#ifdef CONFIG_PAX_PAGEEXEC
2701 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2702 + vma->vm_flags &= ~VM_EXEC;
2703 +
2704 +#ifdef CONFIG_PAX_MPROTECT
2705 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2706 + vma->vm_flags &= ~VM_MAYEXEC;
2707 +#endif
2708 +
2709 + }
2710 +#endif
2711 +
2712 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2713 down_write(&current->mm->mmap_sem);
2714 if (insert_vm_struct(current->mm, vma)) {
2715 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2716 index 40b3ee9..8c2c112 100644
2717 --- a/arch/m32r/include/asm/cache.h
2718 +++ b/arch/m32r/include/asm/cache.h
2719 @@ -1,8 +1,10 @@
2720 #ifndef _ASM_M32R_CACHE_H
2721 #define _ASM_M32R_CACHE_H
2722
2723 +#include <linux/const.h>
2724 +
2725 /* L1 cache line size */
2726 #define L1_CACHE_SHIFT 4
2727 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2728 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2729
2730 #endif /* _ASM_M32R_CACHE_H */
2731 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2732 index 82abd15..d95ae5d 100644
2733 --- a/arch/m32r/lib/usercopy.c
2734 +++ b/arch/m32r/lib/usercopy.c
2735 @@ -14,6 +14,9 @@
2736 unsigned long
2737 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2738 {
2739 + if ((long)n < 0)
2740 + return n;
2741 +
2742 prefetch(from);
2743 if (access_ok(VERIFY_WRITE, to, n))
2744 __copy_user(to,from,n);
2745 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2746 unsigned long
2747 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2748 {
2749 + if ((long)n < 0)
2750 + return n;
2751 +
2752 prefetchw(to);
2753 if (access_ok(VERIFY_READ, from, n))
2754 __copy_user_zeroing(to,from,n);
2755 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2756 index 0395c51..5f26031 100644
2757 --- a/arch/m68k/include/asm/cache.h
2758 +++ b/arch/m68k/include/asm/cache.h
2759 @@ -4,9 +4,11 @@
2760 #ifndef __ARCH_M68K_CACHE_H
2761 #define __ARCH_M68K_CACHE_H
2762
2763 +#include <linux/const.h>
2764 +
2765 /* bytes per L1 cache line */
2766 #define L1_CACHE_SHIFT 4
2767 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2768 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2769
2770 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2771
2772 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2773 index 4efe96a..60e8699 100644
2774 --- a/arch/microblaze/include/asm/cache.h
2775 +++ b/arch/microblaze/include/asm/cache.h
2776 @@ -13,11 +13,12 @@
2777 #ifndef _ASM_MICROBLAZE_CACHE_H
2778 #define _ASM_MICROBLAZE_CACHE_H
2779
2780 +#include <linux/const.h>
2781 #include <asm/registers.h>
2782
2783 #define L1_CACHE_SHIFT 5
2784 /* word-granular cache in microblaze */
2785 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2786 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2787
2788 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2789
2790 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2791 index 3f4c5cb..3439c6e 100644
2792 --- a/arch/mips/include/asm/atomic.h
2793 +++ b/arch/mips/include/asm/atomic.h
2794 @@ -21,6 +21,10 @@
2795 #include <asm/cmpxchg.h>
2796 #include <asm/war.h>
2797
2798 +#ifdef CONFIG_GENERIC_ATOMIC64
2799 +#include <asm-generic/atomic64.h>
2800 +#endif
2801 +
2802 #define ATOMIC_INIT(i) { (i) }
2803
2804 /*
2805 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2806 */
2807 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2808
2809 +#define atomic64_read_unchecked(v) atomic64_read(v)
2810 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2811 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2812 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2813 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2814 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2815 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2816 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2817 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2818 +
2819 #endif /* CONFIG_64BIT */
2820
2821 /*
2822 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2823 index b4db69f..8f3b093 100644
2824 --- a/arch/mips/include/asm/cache.h
2825 +++ b/arch/mips/include/asm/cache.h
2826 @@ -9,10 +9,11 @@
2827 #ifndef _ASM_CACHE_H
2828 #define _ASM_CACHE_H
2829
2830 +#include <linux/const.h>
2831 #include <kmalloc.h>
2832
2833 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2834 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2835 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2836
2837 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2838 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2839 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2840 index 455c0ac..ad65fbe 100644
2841 --- a/arch/mips/include/asm/elf.h
2842 +++ b/arch/mips/include/asm/elf.h
2843 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2844 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2845 #endif
2846
2847 +#ifdef CONFIG_PAX_ASLR
2848 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2849 +
2850 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2851 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2852 +#endif
2853 +
2854 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2855 struct linux_binprm;
2856 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2857 int uses_interp);
2858
2859 -struct mm_struct;
2860 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2861 -#define arch_randomize_brk arch_randomize_brk
2862 -
2863 #endif /* _ASM_ELF_H */
2864 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2865 index c1f6afa..38cc6e9 100644
2866 --- a/arch/mips/include/asm/exec.h
2867 +++ b/arch/mips/include/asm/exec.h
2868 @@ -12,6 +12,6 @@
2869 #ifndef _ASM_EXEC_H
2870 #define _ASM_EXEC_H
2871
2872 -extern unsigned long arch_align_stack(unsigned long sp);
2873 +#define arch_align_stack(x) ((x) & ~0xfUL)
2874
2875 #endif /* _ASM_EXEC_H */
2876 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2877 index da9bd7d..91aa7ab 100644
2878 --- a/arch/mips/include/asm/page.h
2879 +++ b/arch/mips/include/asm/page.h
2880 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2881 #ifdef CONFIG_CPU_MIPS32
2882 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2883 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2884 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2885 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2886 #else
2887 typedef struct { unsigned long long pte; } pte_t;
2888 #define pte_val(x) ((x).pte)
2889 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2890 index 881d18b..cea38bc 100644
2891 --- a/arch/mips/include/asm/pgalloc.h
2892 +++ b/arch/mips/include/asm/pgalloc.h
2893 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2894 {
2895 set_pud(pud, __pud((unsigned long)pmd));
2896 }
2897 +
2898 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2899 +{
2900 + pud_populate(mm, pud, pmd);
2901 +}
2902 #endif
2903
2904 /*
2905 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2906 index ca97e0e..cd08920 100644
2907 --- a/arch/mips/include/asm/thread_info.h
2908 +++ b/arch/mips/include/asm/thread_info.h
2909 @@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2910 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2911 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2912 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2913 +/* li takes a 32bit immediate */
2914 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2915 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2916
2917 #ifdef CONFIG_MIPS32_O32
2918 @@ -134,15 +136,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2919 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2920 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2921 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2922 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2923 +
2924 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2925
2926 /* work to do in syscall_trace_leave() */
2927 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2928 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2929
2930 /* work to do on interrupt/exception return */
2931 #define _TIF_WORK_MASK (0x0000ffef & \
2932 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2933 /* work to do on any return to u-space */
2934 -#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2935 +#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2936
2937 #endif /* __KERNEL__ */
2938
2939 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2940 index 9fdd8bc..4bd7f1a 100644
2941 --- a/arch/mips/kernel/binfmt_elfn32.c
2942 +++ b/arch/mips/kernel/binfmt_elfn32.c
2943 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2944 #undef ELF_ET_DYN_BASE
2945 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2946
2947 +#ifdef CONFIG_PAX_ASLR
2948 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2949 +
2950 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2951 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2952 +#endif
2953 +
2954 #include <asm/processor.h>
2955 #include <linux/module.h>
2956 #include <linux/elfcore.h>
2957 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2958 index ff44823..97f8906 100644
2959 --- a/arch/mips/kernel/binfmt_elfo32.c
2960 +++ b/arch/mips/kernel/binfmt_elfo32.c
2961 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2962 #undef ELF_ET_DYN_BASE
2963 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2964
2965 +#ifdef CONFIG_PAX_ASLR
2966 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2967 +
2968 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2969 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2970 +#endif
2971 +
2972 #include <asm/processor.h>
2973
2974 /*
2975 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2976 index e9a5fd7..378809a 100644
2977 --- a/arch/mips/kernel/process.c
2978 +++ b/arch/mips/kernel/process.c
2979 @@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2980 out:
2981 return pc;
2982 }
2983 -
2984 -/*
2985 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2986 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2987 - */
2988 -unsigned long arch_align_stack(unsigned long sp)
2989 -{
2990 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2991 - sp -= get_random_int() & ~PAGE_MASK;
2992 -
2993 - return sp & ALMASK;
2994 -}
2995 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2996 index 4812c6d..2069554 100644
2997 --- a/arch/mips/kernel/ptrace.c
2998 +++ b/arch/mips/kernel/ptrace.c
2999 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
3000 return arch;
3001 }
3002
3003 +#ifdef CONFIG_GRKERNSEC_SETXID
3004 +extern void gr_delayed_cred_worker(void);
3005 +#endif
3006 +
3007 /*
3008 * Notification of system call entry/exit
3009 * - triggered by current->work.syscall_trace
3010 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3011 /* do the secure computing check first */
3012 secure_computing_strict(regs->regs[2]);
3013
3014 +#ifdef CONFIG_GRKERNSEC_SETXID
3015 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3016 + gr_delayed_cred_worker();
3017 +#endif
3018 +
3019 if (!(current->ptrace & PT_PTRACED))
3020 goto out;
3021
3022 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3023 index a632bc1..0b77c7c 100644
3024 --- a/arch/mips/kernel/scall32-o32.S
3025 +++ b/arch/mips/kernel/scall32-o32.S
3026 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3027
3028 stack_done:
3029 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3030 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3031 + li t1, _TIF_SYSCALL_WORK
3032 and t0, t1
3033 bnez t0, syscall_trace_entry # -> yes
3034
3035 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3036 index 3b5a5e9..e1ee86d 100644
3037 --- a/arch/mips/kernel/scall64-64.S
3038 +++ b/arch/mips/kernel/scall64-64.S
3039 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3040
3041 sd a3, PT_R26(sp) # save a3 for syscall restarting
3042
3043 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3044 + li t1, _TIF_SYSCALL_WORK
3045 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3046 and t0, t1, t0
3047 bnez t0, syscall_trace_entry
3048 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3049 index 6be6f70..1859577 100644
3050 --- a/arch/mips/kernel/scall64-n32.S
3051 +++ b/arch/mips/kernel/scall64-n32.S
3052 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3053
3054 sd a3, PT_R26(sp) # save a3 for syscall restarting
3055
3056 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3057 + li t1, _TIF_SYSCALL_WORK
3058 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3059 and t0, t1, t0
3060 bnez t0, n32_syscall_trace_entry
3061 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3062 index 5422855..74e63a3 100644
3063 --- a/arch/mips/kernel/scall64-o32.S
3064 +++ b/arch/mips/kernel/scall64-o32.S
3065 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3066 PTR 4b, bad_stack
3067 .previous
3068
3069 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3070 + li t1, _TIF_SYSCALL_WORK
3071 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3072 and t0, t1, t0
3073 bnez t0, trace_a_syscall
3074 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3075 index c14f6df..537e729 100644
3076 --- a/arch/mips/mm/fault.c
3077 +++ b/arch/mips/mm/fault.c
3078 @@ -27,6 +27,23 @@
3079 #include <asm/highmem.h> /* For VMALLOC_END */
3080 #include <linux/kdebug.h>
3081
3082 +#ifdef CONFIG_PAX_PAGEEXEC
3083 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3084 +{
3085 + unsigned long i;
3086 +
3087 + printk(KERN_ERR "PAX: bytes at PC: ");
3088 + for (i = 0; i < 5; i++) {
3089 + unsigned int c;
3090 + if (get_user(c, (unsigned int *)pc+i))
3091 + printk(KERN_CONT "???????? ");
3092 + else
3093 + printk(KERN_CONT "%08x ", c);
3094 + }
3095 + printk("\n");
3096 +}
3097 +#endif
3098 +
3099 /*
3100 * This routine handles page faults. It determines the address,
3101 * and the problem, and then passes it off to one of the appropriate
3102 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3103 index 302d779..7d35bf8 100644
3104 --- a/arch/mips/mm/mmap.c
3105 +++ b/arch/mips/mm/mmap.c
3106 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3107 do_color_align = 1;
3108
3109 /* requesting a specific address */
3110 +
3111 +#ifdef CONFIG_PAX_RANDMMAP
3112 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3113 +#endif
3114 +
3115 if (addr) {
3116 if (do_color_align)
3117 addr = COLOUR_ALIGN(addr, pgoff);
3118 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3119 addr = PAGE_ALIGN(addr);
3120
3121 vma = find_vma(mm, addr);
3122 - if (TASK_SIZE - len >= addr &&
3123 - (!vma || addr + len <= vma->vm_start))
3124 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3125 return addr;
3126 }
3127
3128 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3129 /* At this point: (!vma || addr < vma->vm_end). */
3130 if (TASK_SIZE - len < addr)
3131 return -ENOMEM;
3132 - if (!vma || addr + len <= vma->vm_start)
3133 + if (check_heap_stack_gap(vmm, addr, len))
3134 return addr;
3135 addr = vma->vm_end;
3136 if (do_color_align)
3137 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3138 /* make sure it can fit in the remaining address space */
3139 if (likely(addr > len)) {
3140 vma = find_vma(mm, addr - len);
3141 - if (!vma || addr <= vma->vm_start) {
3142 + if (check_heap_stack_gap(vmm, addr - len, len))
3143 /* cache the address as a hint for next time */
3144 return mm->free_area_cache = addr - len;
3145 }
3146 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3147 * return with success:
3148 */
3149 vma = find_vma(mm, addr);
3150 - if (likely(!vma || addr + len <= vma->vm_start)) {
3151 + if (check_heap_stack_gap(vmm, addr, len)) {
3152 /* cache the address as a hint for next time */
3153 return mm->free_area_cache = addr;
3154 }
3155 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3156 mm->unmap_area = arch_unmap_area_topdown;
3157 }
3158 }
3159 -
3160 -static inline unsigned long brk_rnd(void)
3161 -{
3162 - unsigned long rnd = get_random_int();
3163 -
3164 - rnd = rnd << PAGE_SHIFT;
3165 - /* 8MB for 32bit, 256MB for 64bit */
3166 - if (TASK_IS_32BIT_ADDR)
3167 - rnd = rnd & 0x7ffffful;
3168 - else
3169 - rnd = rnd & 0xffffffful;
3170 -
3171 - return rnd;
3172 -}
3173 -
3174 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3175 -{
3176 - unsigned long base = mm->brk;
3177 - unsigned long ret;
3178 -
3179 - ret = PAGE_ALIGN(base + brk_rnd());
3180 -
3181 - if (ret < mm->brk)
3182 - return mm->brk;
3183 -
3184 - return ret;
3185 -}
3186 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3187 index 967d144..db12197 100644
3188 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3189 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3190 @@ -11,12 +11,14 @@
3191 #ifndef _ASM_PROC_CACHE_H
3192 #define _ASM_PROC_CACHE_H
3193
3194 +#include <linux/const.h>
3195 +
3196 /* L1 cache */
3197
3198 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3199 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3200 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3201 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3202 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3203 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3204
3205 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3206 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3207 index bcb5df2..84fabd2 100644
3208 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3209 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3210 @@ -16,13 +16,15 @@
3211 #ifndef _ASM_PROC_CACHE_H
3212 #define _ASM_PROC_CACHE_H
3213
3214 +#include <linux/const.h>
3215 +
3216 /*
3217 * L1 cache
3218 */
3219 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3220 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3221 -#define L1_CACHE_BYTES 32 /* bytes per entry */
3222 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3223 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3224 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3225
3226 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3227 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3228 index 4ce7a01..449202a 100644
3229 --- a/arch/openrisc/include/asm/cache.h
3230 +++ b/arch/openrisc/include/asm/cache.h
3231 @@ -19,11 +19,13 @@
3232 #ifndef __ASM_OPENRISC_CACHE_H
3233 #define __ASM_OPENRISC_CACHE_H
3234
3235 +#include <linux/const.h>
3236 +
3237 /* FIXME: How can we replace these with values from the CPU...
3238 * they shouldn't be hard-coded!
3239 */
3240
3241 -#define L1_CACHE_BYTES 16
3242 #define L1_CACHE_SHIFT 4
3243 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3244
3245 #endif /* __ASM_OPENRISC_CACHE_H */
3246 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3247 index 6c6defc..d30653d 100644
3248 --- a/arch/parisc/include/asm/atomic.h
3249 +++ b/arch/parisc/include/asm/atomic.h
3250 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3251
3252 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3253
3254 +#define atomic64_read_unchecked(v) atomic64_read(v)
3255 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3256 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3257 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3258 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3259 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3260 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3261 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3262 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3263 +
3264 #endif /* !CONFIG_64BIT */
3265
3266
3267 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3268 index 47f11c7..3420df2 100644
3269 --- a/arch/parisc/include/asm/cache.h
3270 +++ b/arch/parisc/include/asm/cache.h
3271 @@ -5,6 +5,7 @@
3272 #ifndef __ARCH_PARISC_CACHE_H
3273 #define __ARCH_PARISC_CACHE_H
3274
3275 +#include <linux/const.h>
3276
3277 /*
3278 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3279 @@ -15,13 +16,13 @@
3280 * just ruin performance.
3281 */
3282 #ifdef CONFIG_PA20
3283 -#define L1_CACHE_BYTES 64
3284 #define L1_CACHE_SHIFT 6
3285 #else
3286 -#define L1_CACHE_BYTES 32
3287 #define L1_CACHE_SHIFT 5
3288 #endif
3289
3290 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3291 +
3292 #ifndef __ASSEMBLY__
3293
3294 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3295 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3296 index 19f6cb1..6c78cf2 100644
3297 --- a/arch/parisc/include/asm/elf.h
3298 +++ b/arch/parisc/include/asm/elf.h
3299 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3300
3301 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3302
3303 +#ifdef CONFIG_PAX_ASLR
3304 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3305 +
3306 +#define PAX_DELTA_MMAP_LEN 16
3307 +#define PAX_DELTA_STACK_LEN 16
3308 +#endif
3309 +
3310 /* This yields a mask that user programs can use to figure out what
3311 instruction set this CPU supports. This could be done in user space,
3312 but it's not easy, and we've already done it here. */
3313 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3314 index fc987a1..6e068ef 100644
3315 --- a/arch/parisc/include/asm/pgalloc.h
3316 +++ b/arch/parisc/include/asm/pgalloc.h
3317 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3318 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3319 }
3320
3321 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3322 +{
3323 + pgd_populate(mm, pgd, pmd);
3324 +}
3325 +
3326 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3327 {
3328 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3329 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3330 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3331 #define pmd_free(mm, x) do { } while (0)
3332 #define pgd_populate(mm, pmd, pte) BUG()
3333 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3334
3335 #endif
3336
3337 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3338 index ee99f23..802b0a1 100644
3339 --- a/arch/parisc/include/asm/pgtable.h
3340 +++ b/arch/parisc/include/asm/pgtable.h
3341 @@ -212,6 +212,17 @@ struct vm_area_struct;
3342 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3343 #define PAGE_COPY PAGE_EXECREAD
3344 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3345 +
3346 +#ifdef CONFIG_PAX_PAGEEXEC
3347 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3348 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3349 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3350 +#else
3351 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3352 +# define PAGE_COPY_NOEXEC PAGE_COPY
3353 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3354 +#endif
3355 +
3356 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3357 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3358 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3359 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3360 index 4ba2c93..f5e3974 100644
3361 --- a/arch/parisc/include/asm/uaccess.h
3362 +++ b/arch/parisc/include/asm/uaccess.h
3363 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3364 const void __user *from,
3365 unsigned long n)
3366 {
3367 - int sz = __compiletime_object_size(to);
3368 + size_t sz = __compiletime_object_size(to);
3369 int ret = -EFAULT;
3370
3371 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3372 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3373 ret = __copy_from_user(to, from, n);
3374 else
3375 copy_from_user_overflow();
3376 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3377 index 5e34ccf..672bc9c 100644
3378 --- a/arch/parisc/kernel/module.c
3379 +++ b/arch/parisc/kernel/module.c
3380 @@ -98,16 +98,38 @@
3381
3382 /* three functions to determine where in the module core
3383 * or init pieces the location is */
3384 +static inline int in_init_rx(struct module *me, void *loc)
3385 +{
3386 + return (loc >= me->module_init_rx &&
3387 + loc < (me->module_init_rx + me->init_size_rx));
3388 +}
3389 +
3390 +static inline int in_init_rw(struct module *me, void *loc)
3391 +{
3392 + return (loc >= me->module_init_rw &&
3393 + loc < (me->module_init_rw + me->init_size_rw));
3394 +}
3395 +
3396 static inline int in_init(struct module *me, void *loc)
3397 {
3398 - return (loc >= me->module_init &&
3399 - loc <= (me->module_init + me->init_size));
3400 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3401 +}
3402 +
3403 +static inline int in_core_rx(struct module *me, void *loc)
3404 +{
3405 + return (loc >= me->module_core_rx &&
3406 + loc < (me->module_core_rx + me->core_size_rx));
3407 +}
3408 +
3409 +static inline int in_core_rw(struct module *me, void *loc)
3410 +{
3411 + return (loc >= me->module_core_rw &&
3412 + loc < (me->module_core_rw + me->core_size_rw));
3413 }
3414
3415 static inline int in_core(struct module *me, void *loc)
3416 {
3417 - return (loc >= me->module_core &&
3418 - loc <= (me->module_core + me->core_size));
3419 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3420 }
3421
3422 static inline int in_local(struct module *me, void *loc)
3423 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3424 }
3425
3426 /* align things a bit */
3427 - me->core_size = ALIGN(me->core_size, 16);
3428 - me->arch.got_offset = me->core_size;
3429 - me->core_size += gots * sizeof(struct got_entry);
3430 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3431 + me->arch.got_offset = me->core_size_rw;
3432 + me->core_size_rw += gots * sizeof(struct got_entry);
3433
3434 - me->core_size = ALIGN(me->core_size, 16);
3435 - me->arch.fdesc_offset = me->core_size;
3436 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3437 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3438 + me->arch.fdesc_offset = me->core_size_rw;
3439 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3440
3441 me->arch.got_max = gots;
3442 me->arch.fdesc_max = fdescs;
3443 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3444
3445 BUG_ON(value == 0);
3446
3447 - got = me->module_core + me->arch.got_offset;
3448 + got = me->module_core_rw + me->arch.got_offset;
3449 for (i = 0; got[i].addr; i++)
3450 if (got[i].addr == value)
3451 goto out;
3452 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3453 #ifdef CONFIG_64BIT
3454 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3455 {
3456 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3457 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3458
3459 if (!value) {
3460 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3461 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3462
3463 /* Create new one */
3464 fdesc->addr = value;
3465 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3466 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3467 return (Elf_Addr)fdesc;
3468 }
3469 #endif /* CONFIG_64BIT */
3470 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3471
3472 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3473 end = table + sechdrs[me->arch.unwind_section].sh_size;
3474 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3475 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3476
3477 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3478 me->arch.unwind_section, table, end, gp);
3479 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3480 index c9b9322..02d8940 100644
3481 --- a/arch/parisc/kernel/sys_parisc.c
3482 +++ b/arch/parisc/kernel/sys_parisc.c
3483 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3484 /* At this point: (!vma || addr < vma->vm_end). */
3485 if (TASK_SIZE - len < addr)
3486 return -ENOMEM;
3487 - if (!vma || addr + len <= vma->vm_start)
3488 + if (check_heap_stack_gap(vma, addr, len))
3489 return addr;
3490 addr = vma->vm_end;
3491 }
3492 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3493 /* At this point: (!vma || addr < vma->vm_end). */
3494 if (TASK_SIZE - len < addr)
3495 return -ENOMEM;
3496 - if (!vma || addr + len <= vma->vm_start)
3497 + if (check_heap_stack_gap(vma, addr, len))
3498 return addr;
3499 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3500 if (addr < vma->vm_end) /* handle wraparound */
3501 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3502 if (flags & MAP_FIXED)
3503 return addr;
3504 if (!addr)
3505 - addr = TASK_UNMAPPED_BASE;
3506 + addr = current->mm->mmap_base;
3507
3508 if (filp) {
3509 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3510 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3511 index 45ba99f..8e22c33 100644
3512 --- a/arch/parisc/kernel/traps.c
3513 +++ b/arch/parisc/kernel/traps.c
3514 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3515
3516 down_read(&current->mm->mmap_sem);
3517 vma = find_vma(current->mm,regs->iaoq[0]);
3518 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3519 - && (vma->vm_flags & VM_EXEC)) {
3520 -
3521 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3522 fault_address = regs->iaoq[0];
3523 fault_space = regs->iasq[0];
3524
3525 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3526 index 18162ce..94de376 100644
3527 --- a/arch/parisc/mm/fault.c
3528 +++ b/arch/parisc/mm/fault.c
3529 @@ -15,6 +15,7 @@
3530 #include <linux/sched.h>
3531 #include <linux/interrupt.h>
3532 #include <linux/module.h>
3533 +#include <linux/unistd.h>
3534
3535 #include <asm/uaccess.h>
3536 #include <asm/traps.h>
3537 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3538 static unsigned long
3539 parisc_acctyp(unsigned long code, unsigned int inst)
3540 {
3541 - if (code == 6 || code == 16)
3542 + if (code == 6 || code == 7 || code == 16)
3543 return VM_EXEC;
3544
3545 switch (inst & 0xf0000000) {
3546 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3547 }
3548 #endif
3549
3550 +#ifdef CONFIG_PAX_PAGEEXEC
3551 +/*
3552 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3553 + *
3554 + * returns 1 when task should be killed
3555 + * 2 when rt_sigreturn trampoline was detected
3556 + * 3 when unpatched PLT trampoline was detected
3557 + */
3558 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3559 +{
3560 +
3561 +#ifdef CONFIG_PAX_EMUPLT
3562 + int err;
3563 +
3564 + do { /* PaX: unpatched PLT emulation */
3565 + unsigned int bl, depwi;
3566 +
3567 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3568 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3569 +
3570 + if (err)
3571 + break;
3572 +
3573 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3574 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3575 +
3576 + err = get_user(ldw, (unsigned int *)addr);
3577 + err |= get_user(bv, (unsigned int *)(addr+4));
3578 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3579 +
3580 + if (err)
3581 + break;
3582 +
3583 + if (ldw == 0x0E801096U &&
3584 + bv == 0xEAC0C000U &&
3585 + ldw2 == 0x0E881095U)
3586 + {
3587 + unsigned int resolver, map;
3588 +
3589 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3590 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3591 + if (err)
3592 + break;
3593 +
3594 + regs->gr[20] = instruction_pointer(regs)+8;
3595 + regs->gr[21] = map;
3596 + regs->gr[22] = resolver;
3597 + regs->iaoq[0] = resolver | 3UL;
3598 + regs->iaoq[1] = regs->iaoq[0] + 4;
3599 + return 3;
3600 + }
3601 + }
3602 + } while (0);
3603 +#endif
3604 +
3605 +#ifdef CONFIG_PAX_EMUTRAMP
3606 +
3607 +#ifndef CONFIG_PAX_EMUSIGRT
3608 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3609 + return 1;
3610 +#endif
3611 +
3612 + do { /* PaX: rt_sigreturn emulation */
3613 + unsigned int ldi1, ldi2, bel, nop;
3614 +
3615 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3616 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3617 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3618 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3619 +
3620 + if (err)
3621 + break;
3622 +
3623 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3624 + ldi2 == 0x3414015AU &&
3625 + bel == 0xE4008200U &&
3626 + nop == 0x08000240U)
3627 + {
3628 + regs->gr[25] = (ldi1 & 2) >> 1;
3629 + regs->gr[20] = __NR_rt_sigreturn;
3630 + regs->gr[31] = regs->iaoq[1] + 16;
3631 + regs->sr[0] = regs->iasq[1];
3632 + regs->iaoq[0] = 0x100UL;
3633 + regs->iaoq[1] = regs->iaoq[0] + 4;
3634 + regs->iasq[0] = regs->sr[2];
3635 + regs->iasq[1] = regs->sr[2];
3636 + return 2;
3637 + }
3638 + } while (0);
3639 +#endif
3640 +
3641 + return 1;
3642 +}
3643 +
3644 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3645 +{
3646 + unsigned long i;
3647 +
3648 + printk(KERN_ERR "PAX: bytes at PC: ");
3649 + for (i = 0; i < 5; i++) {
3650 + unsigned int c;
3651 + if (get_user(c, (unsigned int *)pc+i))
3652 + printk(KERN_CONT "???????? ");
3653 + else
3654 + printk(KERN_CONT "%08x ", c);
3655 + }
3656 + printk("\n");
3657 +}
3658 +#endif
3659 +
3660 int fixup_exception(struct pt_regs *regs)
3661 {
3662 const struct exception_table_entry *fix;
3663 @@ -192,8 +303,33 @@ good_area:
3664
3665 acc_type = parisc_acctyp(code,regs->iir);
3666
3667 - if ((vma->vm_flags & acc_type) != acc_type)
3668 + if ((vma->vm_flags & acc_type) != acc_type) {
3669 +
3670 +#ifdef CONFIG_PAX_PAGEEXEC
3671 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3672 + (address & ~3UL) == instruction_pointer(regs))
3673 + {
3674 + up_read(&mm->mmap_sem);
3675 + switch (pax_handle_fetch_fault(regs)) {
3676 +
3677 +#ifdef CONFIG_PAX_EMUPLT
3678 + case 3:
3679 + return;
3680 +#endif
3681 +
3682 +#ifdef CONFIG_PAX_EMUTRAMP
3683 + case 2:
3684 + return;
3685 +#endif
3686 +
3687 + }
3688 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3689 + do_group_exit(SIGKILL);
3690 + }
3691 +#endif
3692 +
3693 goto bad_area;
3694 + }
3695
3696 /*
3697 * If for any reason at all we couldn't handle the fault, make
3698 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3699 index da29032..f76c24c 100644
3700 --- a/arch/powerpc/include/asm/atomic.h
3701 +++ b/arch/powerpc/include/asm/atomic.h
3702 @@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3703 return t1;
3704 }
3705
3706 +#define atomic64_read_unchecked(v) atomic64_read(v)
3707 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3708 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3709 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3710 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3711 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3712 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3713 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3714 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3715 +
3716 #endif /* __powerpc64__ */
3717
3718 #endif /* __KERNEL__ */
3719 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3720 index 9e495c9..b6878e5 100644
3721 --- a/arch/powerpc/include/asm/cache.h
3722 +++ b/arch/powerpc/include/asm/cache.h
3723 @@ -3,6 +3,7 @@
3724
3725 #ifdef __KERNEL__
3726
3727 +#include <linux/const.h>
3728
3729 /* bytes per L1 cache line */
3730 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3731 @@ -22,7 +23,7 @@
3732 #define L1_CACHE_SHIFT 7
3733 #endif
3734
3735 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3736 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3737
3738 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3739
3740 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3741 index 3bf9cca..e7457d0 100644
3742 --- a/arch/powerpc/include/asm/elf.h
3743 +++ b/arch/powerpc/include/asm/elf.h
3744 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3745 the loader. We need to make sure that it is out of the way of the program
3746 that it will "exec", and that there is sufficient room for the brk. */
3747
3748 -extern unsigned long randomize_et_dyn(unsigned long base);
3749 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3750 +#define ELF_ET_DYN_BASE (0x20000000)
3751 +
3752 +#ifdef CONFIG_PAX_ASLR
3753 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3754 +
3755 +#ifdef __powerpc64__
3756 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3757 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3758 +#else
3759 +#define PAX_DELTA_MMAP_LEN 15
3760 +#define PAX_DELTA_STACK_LEN 15
3761 +#endif
3762 +#endif
3763
3764 /*
3765 * Our registers are always unsigned longs, whether we're a 32 bit
3766 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3767 (0x7ff >> (PAGE_SHIFT - 12)) : \
3768 (0x3ffff >> (PAGE_SHIFT - 12)))
3769
3770 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3771 -#define arch_randomize_brk arch_randomize_brk
3772 -
3773 #endif /* __KERNEL__ */
3774
3775 /*
3776 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3777 index 8196e9c..d83a9f3 100644
3778 --- a/arch/powerpc/include/asm/exec.h
3779 +++ b/arch/powerpc/include/asm/exec.h
3780 @@ -4,6 +4,6 @@
3781 #ifndef _ASM_POWERPC_EXEC_H
3782 #define _ASM_POWERPC_EXEC_H
3783
3784 -extern unsigned long arch_align_stack(unsigned long sp);
3785 +#define arch_align_stack(x) ((x) & ~0xfUL)
3786
3787 #endif /* _ASM_POWERPC_EXEC_H */
3788 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3789 index bca8fdc..61e9580 100644
3790 --- a/arch/powerpc/include/asm/kmap_types.h
3791 +++ b/arch/powerpc/include/asm/kmap_types.h
3792 @@ -27,6 +27,7 @@ enum km_type {
3793 KM_PPC_SYNC_PAGE,
3794 KM_PPC_SYNC_ICACHE,
3795 KM_KDB,
3796 + KM_CLEARPAGE,
3797 KM_TYPE_NR
3798 };
3799
3800 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3801 index d4a7f64..451de1c 100644
3802 --- a/arch/powerpc/include/asm/mman.h
3803 +++ b/arch/powerpc/include/asm/mman.h
3804 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3805 }
3806 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3807
3808 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3809 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3810 {
3811 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3812 }
3813 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3814 index f072e97..b436dee 100644
3815 --- a/arch/powerpc/include/asm/page.h
3816 +++ b/arch/powerpc/include/asm/page.h
3817 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3818 * and needs to be executable. This means the whole heap ends
3819 * up being executable.
3820 */
3821 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3822 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3823 +#define VM_DATA_DEFAULT_FLAGS32 \
3824 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3825 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3826
3827 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3828 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3829 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3830 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3831 #endif
3832
3833 +#define ktla_ktva(addr) (addr)
3834 +#define ktva_ktla(addr) (addr)
3835 +
3836 /*
3837 * Use the top bit of the higher-level page table entries to indicate whether
3838 * the entries we point to contain hugepages. This works because we know that
3839 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3840 index fed85e6..da5c71b 100644
3841 --- a/arch/powerpc/include/asm/page_64.h
3842 +++ b/arch/powerpc/include/asm/page_64.h
3843 @@ -146,15 +146,18 @@ do { \
3844 * stack by default, so in the absence of a PT_GNU_STACK program header
3845 * we turn execute permission off.
3846 */
3847 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3848 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3849 +#define VM_STACK_DEFAULT_FLAGS32 \
3850 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3851 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3852
3853 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3854 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3855
3856 +#ifndef CONFIG_PAX_PAGEEXEC
3857 #define VM_STACK_DEFAULT_FLAGS \
3858 (is_32bit_task() ? \
3859 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3860 +#endif
3861
3862 #include <asm-generic/getorder.h>
3863
3864 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3865 index 292725c..f87ae14 100644
3866 --- a/arch/powerpc/include/asm/pgalloc-64.h
3867 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3868 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3869 #ifndef CONFIG_PPC_64K_PAGES
3870
3871 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3872 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3873
3874 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3875 {
3876 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3877 pud_set(pud, (unsigned long)pmd);
3878 }
3879
3880 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3881 +{
3882 + pud_populate(mm, pud, pmd);
3883 +}
3884 +
3885 #define pmd_populate(mm, pmd, pte_page) \
3886 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3887 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3888 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3889 #else /* CONFIG_PPC_64K_PAGES */
3890
3891 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3892 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3893
3894 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3895 pte_t *pte)
3896 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3897 index 2e0e411..7899c68 100644
3898 --- a/arch/powerpc/include/asm/pgtable.h
3899 +++ b/arch/powerpc/include/asm/pgtable.h
3900 @@ -2,6 +2,7 @@
3901 #define _ASM_POWERPC_PGTABLE_H
3902 #ifdef __KERNEL__
3903
3904 +#include <linux/const.h>
3905 #ifndef __ASSEMBLY__
3906 #include <asm/processor.h> /* For TASK_SIZE */
3907 #include <asm/mmu.h>
3908 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3909 index 4aad413..85d86bf 100644
3910 --- a/arch/powerpc/include/asm/pte-hash32.h
3911 +++ b/arch/powerpc/include/asm/pte-hash32.h
3912 @@ -21,6 +21,7 @@
3913 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3914 #define _PAGE_USER 0x004 /* usermode access allowed */
3915 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3916 +#define _PAGE_EXEC _PAGE_GUARDED
3917 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3918 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3919 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3920 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3921 index 360585d..c3930ef 100644
3922 --- a/arch/powerpc/include/asm/reg.h
3923 +++ b/arch/powerpc/include/asm/reg.h
3924 @@ -212,6 +212,7 @@
3925 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3926 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3927 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3928 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3929 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3930 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3931 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3932 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3933 index 68831e9..379c695 100644
3934 --- a/arch/powerpc/include/asm/thread_info.h
3935 +++ b/arch/powerpc/include/asm/thread_info.h
3936 @@ -91,12 +91,14 @@ static inline struct thread_info *current_thread_info(void)
3937 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3938 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3939 #define TIF_SINGLESTEP 8 /* singlestepping active */
3940 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3941 #define TIF_SECCOMP 10 /* secure computing */
3942 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3943 #define TIF_NOERROR 12 /* Force successful syscall return */
3944 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3945 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3946 +#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3947 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3948 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3949
3950 /* as above, but as bit values */
3951 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3952 @@ -113,8 +115,10 @@ static inline struct thread_info *current_thread_info(void)
3953 #define _TIF_NOERROR (1<<TIF_NOERROR)
3954 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3955 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3956 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3957 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3958 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3959 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3960 + _TIF_GRSEC_SETXID)
3961
3962 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3963 _TIF_NOTIFY_RESUME)
3964 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3965 index 17bb40c..353c98b 100644
3966 --- a/arch/powerpc/include/asm/uaccess.h
3967 +++ b/arch/powerpc/include/asm/uaccess.h
3968 @@ -13,6 +13,8 @@
3969 #define VERIFY_READ 0
3970 #define VERIFY_WRITE 1
3971
3972 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3973 +
3974 /*
3975 * The fs value determines whether argument validity checking should be
3976 * performed or not. If get_fs() == USER_DS, checking is performed, with
3977 @@ -329,52 +331,6 @@ do { \
3978 extern unsigned long __copy_tofrom_user(void __user *to,
3979 const void __user *from, unsigned long size);
3980
3981 -#ifndef __powerpc64__
3982 -
3983 -static inline unsigned long copy_from_user(void *to,
3984 - const void __user *from, unsigned long n)
3985 -{
3986 - unsigned long over;
3987 -
3988 - if (access_ok(VERIFY_READ, from, n))
3989 - return __copy_tofrom_user((__force void __user *)to, from, n);
3990 - if ((unsigned long)from < TASK_SIZE) {
3991 - over = (unsigned long)from + n - TASK_SIZE;
3992 - return __copy_tofrom_user((__force void __user *)to, from,
3993 - n - over) + over;
3994 - }
3995 - return n;
3996 -}
3997 -
3998 -static inline unsigned long copy_to_user(void __user *to,
3999 - const void *from, unsigned long n)
4000 -{
4001 - unsigned long over;
4002 -
4003 - if (access_ok(VERIFY_WRITE, to, n))
4004 - return __copy_tofrom_user(to, (__force void __user *)from, n);
4005 - if ((unsigned long)to < TASK_SIZE) {
4006 - over = (unsigned long)to + n - TASK_SIZE;
4007 - return __copy_tofrom_user(to, (__force void __user *)from,
4008 - n - over) + over;
4009 - }
4010 - return n;
4011 -}
4012 -
4013 -#else /* __powerpc64__ */
4014 -
4015 -#define __copy_in_user(to, from, size) \
4016 - __copy_tofrom_user((to), (from), (size))
4017 -
4018 -extern unsigned long copy_from_user(void *to, const void __user *from,
4019 - unsigned long n);
4020 -extern unsigned long copy_to_user(void __user *to, const void *from,
4021 - unsigned long n);
4022 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
4023 - unsigned long n);
4024 -
4025 -#endif /* __powerpc64__ */
4026 -
4027 static inline unsigned long __copy_from_user_inatomic(void *to,
4028 const void __user *from, unsigned long n)
4029 {
4030 @@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4031 if (ret == 0)
4032 return 0;
4033 }
4034 +
4035 + if (!__builtin_constant_p(n))
4036 + check_object_size(to, n, false);
4037 +
4038 return __copy_tofrom_user((__force void __user *)to, from, n);
4039 }
4040
4041 @@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4042 if (ret == 0)
4043 return 0;
4044 }
4045 +
4046 + if (!__builtin_constant_p(n))
4047 + check_object_size(from, n, true);
4048 +
4049 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4050 }
4051
4052 @@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4053 return __copy_to_user_inatomic(to, from, size);
4054 }
4055
4056 +#ifndef __powerpc64__
4057 +
4058 +static inline unsigned long __must_check copy_from_user(void *to,
4059 + const void __user *from, unsigned long n)
4060 +{
4061 + unsigned long over;
4062 +
4063 + if ((long)n < 0)
4064 + return n;
4065 +
4066 + if (access_ok(VERIFY_READ, from, n)) {
4067 + if (!__builtin_constant_p(n))
4068 + check_object_size(to, n, false);
4069 + return __copy_tofrom_user((__force void __user *)to, from, n);
4070 + }
4071 + if ((unsigned long)from < TASK_SIZE) {
4072 + over = (unsigned long)from + n - TASK_SIZE;
4073 + if (!__builtin_constant_p(n - over))
4074 + check_object_size(to, n - over, false);
4075 + return __copy_tofrom_user((__force void __user *)to, from,
4076 + n - over) + over;
4077 + }
4078 + return n;
4079 +}
4080 +
4081 +static inline unsigned long __must_check copy_to_user(void __user *to,
4082 + const void *from, unsigned long n)
4083 +{
4084 + unsigned long over;
4085 +
4086 + if ((long)n < 0)
4087 + return n;
4088 +
4089 + if (access_ok(VERIFY_WRITE, to, n)) {
4090 + if (!__builtin_constant_p(n))
4091 + check_object_size(from, n, true);
4092 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4093 + }
4094 + if ((unsigned long)to < TASK_SIZE) {
4095 + over = (unsigned long)to + n - TASK_SIZE;
4096 + if (!__builtin_constant_p(n))
4097 + check_object_size(from, n - over, true);
4098 + return __copy_tofrom_user(to, (__force void __user *)from,
4099 + n - over) + over;
4100 + }
4101 + return n;
4102 +}
4103 +
4104 +#else /* __powerpc64__ */
4105 +
4106 +#define __copy_in_user(to, from, size) \
4107 + __copy_tofrom_user((to), (from), (size))
4108 +
4109 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4110 +{
4111 + if ((long)n < 0 || n > INT_MAX)
4112 + return n;
4113 +
4114 + if (!__builtin_constant_p(n))
4115 + check_object_size(to, n, false);
4116 +
4117 + if (likely(access_ok(VERIFY_READ, from, n)))
4118 + n = __copy_from_user(to, from, n);
4119 + else
4120 + memset(to, 0, n);
4121 + return n;
4122 +}
4123 +
4124 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4125 +{
4126 + if ((long)n < 0 || n > INT_MAX)
4127 + return n;
4128 +
4129 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4130 + if (!__builtin_constant_p(n))
4131 + check_object_size(from, n, true);
4132 + n = __copy_to_user(to, from, n);
4133 + }
4134 + return n;
4135 +}
4136 +
4137 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4138 + unsigned long n);
4139 +
4140 +#endif /* __powerpc64__ */
4141 +
4142 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4143
4144 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4145 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4146 index 7215cc2..a9730c1 100644
4147 --- a/arch/powerpc/kernel/exceptions-64e.S
4148 +++ b/arch/powerpc/kernel/exceptions-64e.S
4149 @@ -661,6 +661,7 @@ storage_fault_common:
4150 std r14,_DAR(r1)
4151 std r15,_DSISR(r1)
4152 addi r3,r1,STACK_FRAME_OVERHEAD
4153 + bl .save_nvgprs
4154 mr r4,r14
4155 mr r5,r15
4156 ld r14,PACA_EXGEN+EX_R14(r13)
4157 @@ -669,8 +670,7 @@ storage_fault_common:
4158 cmpdi r3,0
4159 bne- 1f
4160 b .ret_from_except_lite
4161 -1: bl .save_nvgprs
4162 - mr r5,r3
4163 +1: mr r5,r3
4164 addi r3,r1,STACK_FRAME_OVERHEAD
4165 ld r4,_DAR(r1)
4166 bl .bad_page_fault
4167 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4168 index 1c06d29..c2a339b 100644
4169 --- a/arch/powerpc/kernel/exceptions-64s.S
4170 +++ b/arch/powerpc/kernel/exceptions-64s.S
4171 @@ -888,10 +888,10 @@ handle_page_fault:
4172 11: ld r4,_DAR(r1)
4173 ld r5,_DSISR(r1)
4174 addi r3,r1,STACK_FRAME_OVERHEAD
4175 + bl .save_nvgprs
4176 bl .do_page_fault
4177 cmpdi r3,0
4178 beq+ 12f
4179 - bl .save_nvgprs
4180 mr r5,r3
4181 addi r3,r1,STACK_FRAME_OVERHEAD
4182 lwz r4,_DAR(r1)
4183 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4184 index 2e3200c..72095ce 100644
4185 --- a/arch/powerpc/kernel/module_32.c
4186 +++ b/arch/powerpc/kernel/module_32.c
4187 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4188 me->arch.core_plt_section = i;
4189 }
4190 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4191 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4192 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4193 return -ENOEXEC;
4194 }
4195
4196 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4197
4198 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4199 /* Init, or core PLT? */
4200 - if (location >= mod->module_core
4201 - && location < mod->module_core + mod->core_size)
4202 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4203 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4204 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4205 - else
4206 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4207 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4208 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4209 + else {
4210 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4211 + return ~0UL;
4212 + }
4213
4214 /* Find this entry, or if that fails, the next avail. entry */
4215 while (entry->jump[0]) {
4216 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4217 index 710f400..d00ebe6 100644
4218 --- a/arch/powerpc/kernel/process.c
4219 +++ b/arch/powerpc/kernel/process.c
4220 @@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4221 * Lookup NIP late so we have the best change of getting the
4222 * above info out without failing
4223 */
4224 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4225 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4226 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4227 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4228 #endif
4229 show_stack(current, (unsigned long *) regs->gpr[1]);
4230 if (!user_mode(regs))
4231 @@ -1189,10 +1189,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4232 newsp = stack[0];
4233 ip = stack[STACK_FRAME_LR_SAVE];
4234 if (!firstframe || ip != lr) {
4235 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4236 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4237 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4238 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4239 - printk(" (%pS)",
4240 + printk(" (%pA)",
4241 (void *)current->ret_stack[curr_frame].ret);
4242 curr_frame--;
4243 }
4244 @@ -1212,7 +1212,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4245 struct pt_regs *regs = (struct pt_regs *)
4246 (sp + STACK_FRAME_OVERHEAD);
4247 lr = regs->link;
4248 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4249 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4250 regs->trap, (void *)regs->nip, (void *)lr);
4251 firstframe = 1;
4252 }
4253 @@ -1254,58 +1254,3 @@ void __ppc64_runlatch_off(void)
4254 mtspr(SPRN_CTRLT, ctrl);
4255 }
4256 #endif /* CONFIG_PPC64 */
4257 -
4258 -unsigned long arch_align_stack(unsigned long sp)
4259 -{
4260 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4261 - sp -= get_random_int() & ~PAGE_MASK;
4262 - return sp & ~0xf;
4263 -}
4264 -
4265 -static inline unsigned long brk_rnd(void)
4266 -{
4267 - unsigned long rnd = 0;
4268 -
4269 - /* 8MB for 32bit, 1GB for 64bit */
4270 - if (is_32bit_task())
4271 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4272 - else
4273 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4274 -
4275 - return rnd << PAGE_SHIFT;
4276 -}
4277 -
4278 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4279 -{
4280 - unsigned long base = mm->brk;
4281 - unsigned long ret;
4282 -
4283 -#ifdef CONFIG_PPC_STD_MMU_64
4284 - /*
4285 - * If we are using 1TB segments and we are allowed to randomise
4286 - * the heap, we can put it above 1TB so it is backed by a 1TB
4287 - * segment. Otherwise the heap will be in the bottom 1TB
4288 - * which always uses 256MB segments and this may result in a
4289 - * performance penalty.
4290 - */
4291 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4292 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4293 -#endif
4294 -
4295 - ret = PAGE_ALIGN(base + brk_rnd());
4296 -
4297 - if (ret < mm->brk)
4298 - return mm->brk;
4299 -
4300 - return ret;
4301 -}
4302 -
4303 -unsigned long randomize_et_dyn(unsigned long base)
4304 -{
4305 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4306 -
4307 - if (ret < base)
4308 - return base;
4309 -
4310 - return ret;
4311 -}
4312 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4313 index c10fc28..c4ef063 100644
4314 --- a/arch/powerpc/kernel/ptrace.c
4315 +++ b/arch/powerpc/kernel/ptrace.c
4316 @@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4317 return ret;
4318 }
4319
4320 +#ifdef CONFIG_GRKERNSEC_SETXID
4321 +extern void gr_delayed_cred_worker(void);
4322 +#endif
4323 +
4324 /*
4325 * We must return the syscall number to actually look up in the table.
4326 * This can be -1L to skip running any syscall at all.
4327 @@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4328
4329 secure_computing_strict(regs->gpr[0]);
4330
4331 +#ifdef CONFIG_GRKERNSEC_SETXID
4332 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4333 + gr_delayed_cred_worker();
4334 +#endif
4335 +
4336 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4337 tracehook_report_syscall_entry(regs))
4338 /*
4339 @@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4340 {
4341 int step;
4342
4343 +#ifdef CONFIG_GRKERNSEC_SETXID
4344 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4345 + gr_delayed_cred_worker();
4346 +#endif
4347 +
4348 audit_syscall_exit(regs);
4349
4350 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4351 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4352 index 8b4c049..dcd6ef3 100644
4353 --- a/arch/powerpc/kernel/signal_32.c
4354 +++ b/arch/powerpc/kernel/signal_32.c
4355 @@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4356 /* Save user registers on the stack */
4357 frame = &rt_sf->uc.uc_mcontext;
4358 addr = frame;
4359 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4360 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4361 if (save_user_regs(regs, frame, 0, 1))
4362 goto badframe;
4363 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4364 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4365 index d183f87..1867f1a 100644
4366 --- a/arch/powerpc/kernel/signal_64.c
4367 +++ b/arch/powerpc/kernel/signal_64.c
4368 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4369 current->thread.fpscr.val = 0;
4370
4371 /* Set up to return from userspace. */
4372 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4373 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4374 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4375 } else {
4376 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4377 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4378 index 1589723..cefe690 100644
4379 --- a/arch/powerpc/kernel/traps.c
4380 +++ b/arch/powerpc/kernel/traps.c
4381 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4382 return flags;
4383 }
4384
4385 +extern void gr_handle_kernel_exploit(void);
4386 +
4387 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4388 int signr)
4389 {
4390 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4391 panic("Fatal exception in interrupt");
4392 if (panic_on_oops)
4393 panic("Fatal exception");
4394 +
4395 + gr_handle_kernel_exploit();
4396 +
4397 do_exit(signr);
4398 }
4399
4400 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4401 index 9eb5b9b..e45498a 100644
4402 --- a/arch/powerpc/kernel/vdso.c
4403 +++ b/arch/powerpc/kernel/vdso.c
4404 @@ -34,6 +34,7 @@
4405 #include <asm/firmware.h>
4406 #include <asm/vdso.h>
4407 #include <asm/vdso_datapage.h>
4408 +#include <asm/mman.h>
4409
4410 #include "setup.h"
4411
4412 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4413 vdso_base = VDSO32_MBASE;
4414 #endif
4415
4416 - current->mm->context.vdso_base = 0;
4417 + current->mm->context.vdso_base = ~0UL;
4418
4419 /* vDSO has a problem and was disabled, just don't "enable" it for the
4420 * process
4421 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4422 vdso_base = get_unmapped_area(NULL, vdso_base,
4423 (vdso_pages << PAGE_SHIFT) +
4424 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4425 - 0, 0);
4426 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4427 if (IS_ERR_VALUE(vdso_base)) {
4428 rc = vdso_base;
4429 goto fail_mmapsem;
4430 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4431 index 5eea6f3..5d10396 100644
4432 --- a/arch/powerpc/lib/usercopy_64.c
4433 +++ b/arch/powerpc/lib/usercopy_64.c
4434 @@ -9,22 +9,6 @@
4435 #include <linux/module.h>
4436 #include <asm/uaccess.h>
4437
4438 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4439 -{
4440 - if (likely(access_ok(VERIFY_READ, from, n)))
4441 - n = __copy_from_user(to, from, n);
4442 - else
4443 - memset(to, 0, n);
4444 - return n;
4445 -}
4446 -
4447 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4448 -{
4449 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4450 - n = __copy_to_user(to, from, n);
4451 - return n;
4452 -}
4453 -
4454 unsigned long copy_in_user(void __user *to, const void __user *from,
4455 unsigned long n)
4456 {
4457 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4458 return n;
4459 }
4460
4461 -EXPORT_SYMBOL(copy_from_user);
4462 -EXPORT_SYMBOL(copy_to_user);
4463 EXPORT_SYMBOL(copy_in_user);
4464
4465 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4466 index 08ffcf5..a0ab912 100644
4467 --- a/arch/powerpc/mm/fault.c
4468 +++ b/arch/powerpc/mm/fault.c
4469 @@ -32,6 +32,10 @@
4470 #include <linux/perf_event.h>
4471 #include <linux/magic.h>
4472 #include <linux/ratelimit.h>
4473 +#include <linux/slab.h>
4474 +#include <linux/pagemap.h>
4475 +#include <linux/compiler.h>
4476 +#include <linux/unistd.h>
4477
4478 #include <asm/firmware.h>
4479 #include <asm/page.h>
4480 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4481 }
4482 #endif
4483
4484 +#ifdef CONFIG_PAX_PAGEEXEC
4485 +/*
4486 + * PaX: decide what to do with offenders (regs->nip = fault address)
4487 + *
4488 + * returns 1 when task should be killed
4489 + */
4490 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4491 +{
4492 + return 1;
4493 +}
4494 +
4495 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4496 +{
4497 + unsigned long i;
4498 +
4499 + printk(KERN_ERR "PAX: bytes at PC: ");
4500 + for (i = 0; i < 5; i++) {
4501 + unsigned int c;
4502 + if (get_user(c, (unsigned int __user *)pc+i))
4503 + printk(KERN_CONT "???????? ");
4504 + else
4505 + printk(KERN_CONT "%08x ", c);
4506 + }
4507 + printk("\n");
4508 +}
4509 +#endif
4510 +
4511 /*
4512 * Check whether the instruction at regs->nip is a store using
4513 * an update addressing form which will update r1.
4514 @@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4515 * indicate errors in DSISR but can validly be set in SRR1.
4516 */
4517 if (trap == 0x400)
4518 - error_code &= 0x48200000;
4519 + error_code &= 0x58200000;
4520 else
4521 is_write = error_code & DSISR_ISSTORE;
4522 #else
4523 @@ -366,7 +397,7 @@ good_area:
4524 * "undefined". Of those that can be set, this is the only
4525 * one which seems bad.
4526 */
4527 - if (error_code & 0x10000000)
4528 + if (error_code & DSISR_GUARDED)
4529 /* Guarded storage error. */
4530 goto bad_area;
4531 #endif /* CONFIG_8xx */
4532 @@ -381,7 +412,7 @@ good_area:
4533 * processors use the same I/D cache coherency mechanism
4534 * as embedded.
4535 */
4536 - if (error_code & DSISR_PROTFAULT)
4537 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4538 goto bad_area;
4539 #endif /* CONFIG_PPC_STD_MMU */
4540
4541 @@ -463,6 +494,23 @@ bad_area:
4542 bad_area_nosemaphore:
4543 /* User mode accesses cause a SIGSEGV */
4544 if (user_mode(regs)) {
4545 +
4546 +#ifdef CONFIG_PAX_PAGEEXEC
4547 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4548 +#ifdef CONFIG_PPC_STD_MMU
4549 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4550 +#else
4551 + if (is_exec && regs->nip == address) {
4552 +#endif
4553 + switch (pax_handle_fetch_fault(regs)) {
4554 + }
4555 +
4556 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4557 + do_group_exit(SIGKILL);
4558 + }
4559 + }
4560 +#endif
4561 +
4562 _exception(SIGSEGV, regs, code, address);
4563 return 0;
4564 }
4565 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4566 index 67a42ed..1c7210c 100644
4567 --- a/arch/powerpc/mm/mmap_64.c
4568 +++ b/arch/powerpc/mm/mmap_64.c
4569 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4570 */
4571 if (mmap_is_legacy()) {
4572 mm->mmap_base = TASK_UNMAPPED_BASE;
4573 +
4574 +#ifdef CONFIG_PAX_RANDMMAP
4575 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4576 + mm->mmap_base += mm->delta_mmap;
4577 +#endif
4578 +
4579 mm->get_unmapped_area = arch_get_unmapped_area;
4580 mm->unmap_area = arch_unmap_area;
4581 } else {
4582 mm->mmap_base = mmap_base();
4583 +
4584 +#ifdef CONFIG_PAX_RANDMMAP
4585 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4586 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4587 +#endif
4588 +
4589 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4590 mm->unmap_area = arch_unmap_area_topdown;
4591 }
4592 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4593 index 73709f7..6b90313 100644
4594 --- a/arch/powerpc/mm/slice.c
4595 +++ b/arch/powerpc/mm/slice.c
4596 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4597 if ((mm->task_size - len) < addr)
4598 return 0;
4599 vma = find_vma(mm, addr);
4600 - return (!vma || (addr + len) <= vma->vm_start);
4601 + return check_heap_stack_gap(vma, addr, len);
4602 }
4603
4604 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4605 @@ -256,7 +256,7 @@ full_search:
4606 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4607 continue;
4608 }
4609 - if (!vma || addr + len <= vma->vm_start) {
4610 + if (check_heap_stack_gap(vma, addr, len)) {
4611 /*
4612 * Remember the place where we stopped the search:
4613 */
4614 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4615 }
4616 }
4617
4618 - addr = mm->mmap_base;
4619 - while (addr > len) {
4620 + if (mm->mmap_base < len)
4621 + addr = -ENOMEM;
4622 + else
4623 + addr = mm->mmap_base - len;
4624 +
4625 + while (!IS_ERR_VALUE(addr)) {
4626 /* Go down by chunk size */
4627 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4628 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4629
4630 /* Check for hit with different page size */
4631 mask = slice_range_to_mask(addr, len);
4632 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4633 * return with success:
4634 */
4635 vma = find_vma(mm, addr);
4636 - if (!vma || (addr + len) <= vma->vm_start) {
4637 + if (check_heap_stack_gap(vma, addr, len)) {
4638 /* remember the address as a hint for next time */
4639 if (use_cache)
4640 mm->free_area_cache = addr;
4641 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4642 mm->cached_hole_size = vma->vm_start - addr;
4643
4644 /* try just below the current vma->vm_start */
4645 - addr = vma->vm_start;
4646 + addr = skip_heap_stack_gap(vma, len);
4647 }
4648
4649 /*
4650 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4651 if (fixed && addr > (mm->task_size - len))
4652 return -EINVAL;
4653
4654 +#ifdef CONFIG_PAX_RANDMMAP
4655 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4656 + addr = 0;
4657 +#endif
4658 +
4659 /* If hint, make sure it matches our alignment restrictions */
4660 if (!fixed && addr) {
4661 addr = _ALIGN_UP(addr, 1ul << pshift);
4662 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4663 index 748347b..81bc6c7 100644
4664 --- a/arch/s390/include/asm/atomic.h
4665 +++ b/arch/s390/include/asm/atomic.h
4666 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4667 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4668 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4669
4670 +#define atomic64_read_unchecked(v) atomic64_read(v)
4671 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4672 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4673 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4674 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4675 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4676 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4677 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4678 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4679 +
4680 #define smp_mb__before_atomic_dec() smp_mb()
4681 #define smp_mb__after_atomic_dec() smp_mb()
4682 #define smp_mb__before_atomic_inc() smp_mb()
4683 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4684 index 2a30d5a..5e5586f 100644
4685 --- a/arch/s390/include/asm/cache.h
4686 +++ b/arch/s390/include/asm/cache.h
4687 @@ -11,8 +11,10 @@
4688 #ifndef __ARCH_S390_CACHE_H
4689 #define __ARCH_S390_CACHE_H
4690
4691 -#define L1_CACHE_BYTES 256
4692 +#include <linux/const.h>
4693 +
4694 #define L1_CACHE_SHIFT 8
4695 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4696 #define NET_SKB_PAD 32
4697
4698 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4699 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4700 index 06151e6..c08cb52 100644
4701 --- a/arch/s390/include/asm/elf.h
4702 +++ b/arch/s390/include/asm/elf.h
4703 @@ -161,8 +161,14 @@ extern unsigned int vdso_enabled;
4704 the loader. We need to make sure that it is out of the way of the program
4705 that it will "exec", and that there is sufficient room for the brk. */
4706
4707 -extern unsigned long randomize_et_dyn(unsigned long base);
4708 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4709 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4710 +
4711 +#ifdef CONFIG_PAX_ASLR
4712 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4713 +
4714 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4715 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4716 +#endif
4717
4718 /* This yields a mask that user programs can use to figure out what
4719 instruction set this CPU supports. */
4720 @@ -210,7 +216,4 @@ struct linux_binprm;
4721 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4722 int arch_setup_additional_pages(struct linux_binprm *, int);
4723
4724 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4725 -#define arch_randomize_brk arch_randomize_brk
4726 -
4727 #endif
4728 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4729 index c4a93d6..4d2a9b4 100644
4730 --- a/arch/s390/include/asm/exec.h
4731 +++ b/arch/s390/include/asm/exec.h
4732 @@ -7,6 +7,6 @@
4733 #ifndef __ASM_EXEC_H
4734 #define __ASM_EXEC_H
4735
4736 -extern unsigned long arch_align_stack(unsigned long sp);
4737 +#define arch_align_stack(x) ((x) & ~0xfUL)
4738
4739 #endif /* __ASM_EXEC_H */
4740 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4741 index 1f3a79b..44d7f9c 100644
4742 --- a/arch/s390/include/asm/uaccess.h
4743 +++ b/arch/s390/include/asm/uaccess.h
4744 @@ -241,6 +241,10 @@ static inline unsigned long __must_check
4745 copy_to_user(void __user *to, const void *from, unsigned long n)
4746 {
4747 might_fault();
4748 +
4749 + if ((long)n < 0)
4750 + return n;
4751 +
4752 if (access_ok(VERIFY_WRITE, to, n))
4753 n = __copy_to_user(to, from, n);
4754 return n;
4755 @@ -266,6 +270,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4756 static inline unsigned long __must_check
4757 __copy_from_user(void *to, const void __user *from, unsigned long n)
4758 {
4759 + if ((long)n < 0)
4760 + return n;
4761 +
4762 if (__builtin_constant_p(n) && (n <= 256))
4763 return uaccess.copy_from_user_small(n, from, to);
4764 else
4765 @@ -297,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4766 static inline unsigned long __must_check
4767 copy_from_user(void *to, const void __user *from, unsigned long n)
4768 {
4769 - unsigned int sz = __compiletime_object_size(to);
4770 + size_t sz = __compiletime_object_size(to);
4771
4772 might_fault();
4773 - if (unlikely(sz != -1 && sz < n)) {
4774 +
4775 + if ((long)n < 0)
4776 + return n;
4777 +
4778 + if (unlikely(sz != (size_t)-1 && sz < n)) {
4779 copy_from_user_overflow();
4780 return n;
4781 }
4782 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4783 index dfcb343..eda788a 100644
4784 --- a/arch/s390/kernel/module.c
4785 +++ b/arch/s390/kernel/module.c
4786 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4787
4788 /* Increase core size by size of got & plt and set start
4789 offsets for got and plt. */
4790 - me->core_size = ALIGN(me->core_size, 4);
4791 - me->arch.got_offset = me->core_size;
4792 - me->core_size += me->arch.got_size;
4793 - me->arch.plt_offset = me->core_size;
4794 - me->core_size += me->arch.plt_size;
4795 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4796 + me->arch.got_offset = me->core_size_rw;
4797 + me->core_size_rw += me->arch.got_size;
4798 + me->arch.plt_offset = me->core_size_rx;
4799 + me->core_size_rx += me->arch.plt_size;
4800 return 0;
4801 }
4802
4803 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4804 if (info->got_initialized == 0) {
4805 Elf_Addr *gotent;
4806
4807 - gotent = me->module_core + me->arch.got_offset +
4808 + gotent = me->module_core_rw + me->arch.got_offset +
4809 info->got_offset;
4810 *gotent = val;
4811 info->got_initialized = 1;
4812 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4813 else if (r_type == R_390_GOTENT ||
4814 r_type == R_390_GOTPLTENT)
4815 *(unsigned int *) loc =
4816 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4817 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4818 else if (r_type == R_390_GOT64 ||
4819 r_type == R_390_GOTPLT64)
4820 *(unsigned long *) loc = val;
4821 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4822 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4823 if (info->plt_initialized == 0) {
4824 unsigned int *ip;
4825 - ip = me->module_core + me->arch.plt_offset +
4826 + ip = me->module_core_rx + me->arch.plt_offset +
4827 info->plt_offset;
4828 #ifndef CONFIG_64BIT
4829 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4830 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4831 val - loc + 0xffffUL < 0x1ffffeUL) ||
4832 (r_type == R_390_PLT32DBL &&
4833 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4834 - val = (Elf_Addr) me->module_core +
4835 + val = (Elf_Addr) me->module_core_rx +
4836 me->arch.plt_offset +
4837 info->plt_offset;
4838 val += rela->r_addend - loc;
4839 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4840 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4841 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4842 val = val + rela->r_addend -
4843 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4844 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4845 if (r_type == R_390_GOTOFF16)
4846 *(unsigned short *) loc = val;
4847 else if (r_type == R_390_GOTOFF32)
4848 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4849 break;
4850 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4851 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4852 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4853 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4854 rela->r_addend - loc;
4855 if (r_type == R_390_GOTPC)
4856 *(unsigned int *) loc = val;
4857 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4858 index 60055ce..ee4b252 100644
4859 --- a/arch/s390/kernel/process.c
4860 +++ b/arch/s390/kernel/process.c
4861 @@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4862 }
4863 return 0;
4864 }
4865 -
4866 -unsigned long arch_align_stack(unsigned long sp)
4867 -{
4868 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4869 - sp -= get_random_int() & ~PAGE_MASK;
4870 - return sp & ~0xf;
4871 -}
4872 -
4873 -static inline unsigned long brk_rnd(void)
4874 -{
4875 - /* 8MB for 32bit, 1GB for 64bit */
4876 - if (is_32bit_task())
4877 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4878 - else
4879 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4880 -}
4881 -
4882 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4883 -{
4884 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4885 -
4886 - if (ret < mm->brk)
4887 - return mm->brk;
4888 - return ret;
4889 -}
4890 -
4891 -unsigned long randomize_et_dyn(unsigned long base)
4892 -{
4893 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4894 -
4895 - if (!(current->flags & PF_RANDOMIZE))
4896 - return base;
4897 - if (ret < base)
4898 - return base;
4899 - return ret;
4900 -}
4901 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4902 index a64fe53..5c66963 100644
4903 --- a/arch/s390/mm/mmap.c
4904 +++ b/arch/s390/mm/mmap.c
4905 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4906 */
4907 if (mmap_is_legacy()) {
4908 mm->mmap_base = TASK_UNMAPPED_BASE;
4909 +
4910 +#ifdef CONFIG_PAX_RANDMMAP
4911 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4912 + mm->mmap_base += mm->delta_mmap;
4913 +#endif
4914 +
4915 mm->get_unmapped_area = arch_get_unmapped_area;
4916 mm->unmap_area = arch_unmap_area;
4917 } else {
4918 mm->mmap_base = mmap_base();
4919 +
4920 +#ifdef CONFIG_PAX_RANDMMAP
4921 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4922 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4923 +#endif
4924 +
4925 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4926 mm->unmap_area = arch_unmap_area_topdown;
4927 }
4928 @@ -174,10 +186,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4929 */
4930 if (mmap_is_legacy()) {
4931 mm->mmap_base = TASK_UNMAPPED_BASE;
4932 +
4933 +#ifdef CONFIG_PAX_RANDMMAP
4934 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4935 + mm->mmap_base += mm->delta_mmap;
4936 +#endif
4937 +
4938 mm->get_unmapped_area = s390_get_unmapped_area;
4939 mm->unmap_area = arch_unmap_area;
4940 } else {
4941 mm->mmap_base = mmap_base();
4942 +
4943 +#ifdef CONFIG_PAX_RANDMMAP
4944 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4945 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4946 +#endif
4947 +
4948 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4949 mm->unmap_area = arch_unmap_area_topdown;
4950 }
4951 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4952 index ae3d59f..f65f075 100644
4953 --- a/arch/score/include/asm/cache.h
4954 +++ b/arch/score/include/asm/cache.h
4955 @@ -1,7 +1,9 @@
4956 #ifndef _ASM_SCORE_CACHE_H
4957 #define _ASM_SCORE_CACHE_H
4958
4959 +#include <linux/const.h>
4960 +
4961 #define L1_CACHE_SHIFT 4
4962 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4963 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4964
4965 #endif /* _ASM_SCORE_CACHE_H */
4966 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4967 index f9f3cd5..58ff438 100644
4968 --- a/arch/score/include/asm/exec.h
4969 +++ b/arch/score/include/asm/exec.h
4970 @@ -1,6 +1,6 @@
4971 #ifndef _ASM_SCORE_EXEC_H
4972 #define _ASM_SCORE_EXEC_H
4973
4974 -extern unsigned long arch_align_stack(unsigned long sp);
4975 +#define arch_align_stack(x) (x)
4976
4977 #endif /* _ASM_SCORE_EXEC_H */
4978 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4979 index 2707023..1c2a3b7 100644
4980 --- a/arch/score/kernel/process.c
4981 +++ b/arch/score/kernel/process.c
4982 @@ -159,8 +159,3 @@ unsigned long get_wchan(struct task_struct *task)
4983
4984 return task_pt_regs(task)->cp0_epc;
4985 }
4986 -
4987 -unsigned long arch_align_stack(unsigned long sp)
4988 -{
4989 - return sp;
4990 -}
4991 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4992 index ef9e555..331bd29 100644
4993 --- a/arch/sh/include/asm/cache.h
4994 +++ b/arch/sh/include/asm/cache.h
4995 @@ -9,10 +9,11 @@
4996 #define __ASM_SH_CACHE_H
4997 #ifdef __KERNEL__
4998
4999 +#include <linux/const.h>
5000 #include <linux/init.h>
5001 #include <cpu/cache.h>
5002
5003 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5004 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5005
5006 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5007
5008 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5009 index afeb710..d1d1289 100644
5010 --- a/arch/sh/mm/mmap.c
5011 +++ b/arch/sh/mm/mmap.c
5012 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5013 addr = PAGE_ALIGN(addr);
5014
5015 vma = find_vma(mm, addr);
5016 - if (TASK_SIZE - len >= addr &&
5017 - (!vma || addr + len <= vma->vm_start))
5018 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5019 return addr;
5020 }
5021
5022 @@ -106,7 +105,7 @@ full_search:
5023 }
5024 return -ENOMEM;
5025 }
5026 - if (likely(!vma || addr + len <= vma->vm_start)) {
5027 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5028 /*
5029 * Remember the place where we stopped the search:
5030 */
5031 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5032 addr = PAGE_ALIGN(addr);
5033
5034 vma = find_vma(mm, addr);
5035 - if (TASK_SIZE - len >= addr &&
5036 - (!vma || addr + len <= vma->vm_start))
5037 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5038 return addr;
5039 }
5040
5041 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5042 /* make sure it can fit in the remaining address space */
5043 if (likely(addr > len)) {
5044 vma = find_vma(mm, addr-len);
5045 - if (!vma || addr <= vma->vm_start) {
5046 + if (check_heap_stack_gap(vma, addr - len, len)) {
5047 /* remember the address as a hint for next time */
5048 return (mm->free_area_cache = addr-len);
5049 }
5050 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5051 if (unlikely(mm->mmap_base < len))
5052 goto bottomup;
5053
5054 - addr = mm->mmap_base-len;
5055 - if (do_colour_align)
5056 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5057 + addr = mm->mmap_base - len;
5058
5059 do {
5060 + if (do_colour_align)
5061 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5062 /*
5063 * Lookup failure means no vma is above this address,
5064 * else if new region fits below vma->vm_start,
5065 * return with success:
5066 */
5067 vma = find_vma(mm, addr);
5068 - if (likely(!vma || addr+len <= vma->vm_start)) {
5069 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5070 /* remember the address as a hint for next time */
5071 return (mm->free_area_cache = addr);
5072 }
5073 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5074 mm->cached_hole_size = vma->vm_start - addr;
5075
5076 /* try just below the current vma->vm_start */
5077 - addr = vma->vm_start-len;
5078 - if (do_colour_align)
5079 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5080 - } while (likely(len < vma->vm_start));
5081 + addr = skip_heap_stack_gap(vma, len);
5082 + } while (!IS_ERR_VALUE(addr));
5083
5084 bottomup:
5085 /*
5086 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5087 index ce35a1c..2e7b8f9 100644
5088 --- a/arch/sparc/include/asm/atomic_64.h
5089 +++ b/arch/sparc/include/asm/atomic_64.h
5090 @@ -14,18 +14,40 @@
5091 #define ATOMIC64_INIT(i) { (i) }
5092
5093 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5094 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5095 +{
5096 + return v->counter;
5097 +}
5098 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5099 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5100 +{
5101 + return v->counter;
5102 +}
5103
5104 #define atomic_set(v, i) (((v)->counter) = i)
5105 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5106 +{
5107 + v->counter = i;
5108 +}
5109 #define atomic64_set(v, i) (((v)->counter) = i)
5110 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5111 +{
5112 + v->counter = i;
5113 +}
5114
5115 extern void atomic_add(int, atomic_t *);
5116 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5117 extern void atomic64_add(long, atomic64_t *);
5118 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5119 extern void atomic_sub(int, atomic_t *);
5120 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5121 extern void atomic64_sub(long, atomic64_t *);
5122 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5123
5124 extern int atomic_add_ret(int, atomic_t *);
5125 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5126 extern long atomic64_add_ret(long, atomic64_t *);
5127 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5128 extern int atomic_sub_ret(int, atomic_t *);
5129 extern long atomic64_sub_ret(long, atomic64_t *);
5130
5131 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5132 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5133
5134 #define atomic_inc_return(v) atomic_add_ret(1, v)
5135 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5136 +{
5137 + return atomic_add_ret_unchecked(1, v);
5138 +}
5139 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5140 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5141 +{
5142 + return atomic64_add_ret_unchecked(1, v);
5143 +}
5144
5145 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5146 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5147
5148 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5149 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5150 +{
5151 + return atomic_add_ret_unchecked(i, v);
5152 +}
5153 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5154 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5155 +{
5156 + return atomic64_add_ret_unchecked(i, v);
5157 +}
5158
5159 /*
5160 * atomic_inc_and_test - increment and test
5161 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5162 * other cases.
5163 */
5164 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5165 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5166 +{
5167 + return atomic_inc_return_unchecked(v) == 0;
5168 +}
5169 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5170
5171 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5172 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5173 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5174
5175 #define atomic_inc(v) atomic_add(1, v)
5176 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5177 +{
5178 + atomic_add_unchecked(1, v);
5179 +}
5180 #define atomic64_inc(v) atomic64_add(1, v)
5181 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5182 +{
5183 + atomic64_add_unchecked(1, v);
5184 +}
5185
5186 #define atomic_dec(v) atomic_sub(1, v)
5187 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5188 +{
5189 + atomic_sub_unchecked(1, v);
5190 +}
5191 #define atomic64_dec(v) atomic64_sub(1, v)
5192 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5193 +{
5194 + atomic64_sub_unchecked(1, v);
5195 +}
5196
5197 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5198 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5199
5200 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5201 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5202 +{
5203 + return cmpxchg(&v->counter, old, new);
5204 +}
5205 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5206 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5207 +{
5208 + return xchg(&v->counter, new);
5209 +}
5210
5211 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5212 {
5213 - int c, old;
5214 + int c, old, new;
5215 c = atomic_read(v);
5216 for (;;) {
5217 - if (unlikely(c == (u)))
5218 + if (unlikely(c == u))
5219 break;
5220 - old = atomic_cmpxchg((v), c, c + (a));
5221 +
5222 + asm volatile("addcc %2, %0, %0\n"
5223 +
5224 +#ifdef CONFIG_PAX_REFCOUNT
5225 + "tvs %%icc, 6\n"
5226 +#endif
5227 +
5228 + : "=r" (new)
5229 + : "0" (c), "ir" (a)
5230 + : "cc");
5231 +
5232 + old = atomic_cmpxchg(v, c, new);
5233 if (likely(old == c))
5234 break;
5235 c = old;
5236 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5237 #define atomic64_cmpxchg(v, o, n) \
5238 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5239 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5240 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5241 +{
5242 + return xchg(&v->counter, new);
5243 +}
5244
5245 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5246 {
5247 - long c, old;
5248 + long c, old, new;
5249 c = atomic64_read(v);
5250 for (;;) {
5251 - if (unlikely(c == (u)))
5252 + if (unlikely(c == u))
5253 break;
5254 - old = atomic64_cmpxchg((v), c, c + (a));
5255 +
5256 + asm volatile("addcc %2, %0, %0\n"
5257 +
5258 +#ifdef CONFIG_PAX_REFCOUNT
5259 + "tvs %%xcc, 6\n"
5260 +#endif
5261 +
5262 + : "=r" (new)
5263 + : "0" (c), "ir" (a)
5264 + : "cc");
5265 +
5266 + old = atomic64_cmpxchg(v, c, new);
5267 if (likely(old == c))
5268 break;
5269 c = old;
5270 }
5271 - return c != (u);
5272 + return c != u;
5273 }
5274
5275 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5276 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5277 index 5bb6991..5c2132e 100644
5278 --- a/arch/sparc/include/asm/cache.h
5279 +++ b/arch/sparc/include/asm/cache.h
5280 @@ -7,10 +7,12 @@
5281 #ifndef _SPARC_CACHE_H
5282 #define _SPARC_CACHE_H
5283
5284 +#include <linux/const.h>
5285 +
5286 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5287
5288 #define L1_CACHE_SHIFT 5
5289 -#define L1_CACHE_BYTES 32
5290 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5291
5292 #ifdef CONFIG_SPARC32
5293 #define SMP_CACHE_BYTES_SHIFT 5
5294 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5295 index 2d4d755..81b6662 100644
5296 --- a/arch/sparc/include/asm/elf_32.h
5297 +++ b/arch/sparc/include/asm/elf_32.h
5298 @@ -114,6 +114,13 @@ typedef struct {
5299
5300 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5301
5302 +#ifdef CONFIG_PAX_ASLR
5303 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5304 +
5305 +#define PAX_DELTA_MMAP_LEN 16
5306 +#define PAX_DELTA_STACK_LEN 16
5307 +#endif
5308 +
5309 /* This yields a mask that user programs can use to figure out what
5310 instruction set this cpu supports. This can NOT be done in userspace
5311 on Sparc. */
5312 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5313 index 7df8b7f..4946269 100644
5314 --- a/arch/sparc/include/asm/elf_64.h
5315 +++ b/arch/sparc/include/asm/elf_64.h
5316 @@ -180,6 +180,13 @@ typedef struct {
5317 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5318 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5319
5320 +#ifdef CONFIG_PAX_ASLR
5321 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5322 +
5323 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5324 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5325 +#endif
5326 +
5327 extern unsigned long sparc64_elf_hwcap;
5328 #define ELF_HWCAP sparc64_elf_hwcap
5329
5330 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5331 index e5b169b46..e90b4fa 100644
5332 --- a/arch/sparc/include/asm/pgalloc_32.h
5333 +++ b/arch/sparc/include/asm/pgalloc_32.h
5334 @@ -46,6 +46,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5335 }
5336
5337 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5338 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5339
5340 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5341 unsigned long address)
5342 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5343 index 40b2d7a..22a665b 100644
5344 --- a/arch/sparc/include/asm/pgalloc_64.h
5345 +++ b/arch/sparc/include/asm/pgalloc_64.h
5346 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5347 }
5348
5349 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5350 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5351
5352 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5353 {
5354 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5355 index cbbbed5..0983069 100644
5356 --- a/arch/sparc/include/asm/pgtable_32.h
5357 +++ b/arch/sparc/include/asm/pgtable_32.h
5358 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5359 #define PAGE_SHARED SRMMU_PAGE_SHARED
5360 #define PAGE_COPY SRMMU_PAGE_COPY
5361 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5362 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5363 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5364 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5365 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5366
5367 /* Top-level page directory */
5368 @@ -61,18 +64,18 @@ extern unsigned long ptr_in_current_pgd;
5369
5370 /* xwr */
5371 #define __P000 PAGE_NONE
5372 -#define __P001 PAGE_READONLY
5373 -#define __P010 PAGE_COPY
5374 -#define __P011 PAGE_COPY
5375 +#define __P001 PAGE_READONLY_NOEXEC
5376 +#define __P010 PAGE_COPY_NOEXEC
5377 +#define __P011 PAGE_COPY_NOEXEC
5378 #define __P100 PAGE_READONLY
5379 #define __P101 PAGE_READONLY
5380 #define __P110 PAGE_COPY
5381 #define __P111 PAGE_COPY
5382
5383 #define __S000 PAGE_NONE
5384 -#define __S001 PAGE_READONLY
5385 -#define __S010 PAGE_SHARED
5386 -#define __S011 PAGE_SHARED
5387 +#define __S001 PAGE_READONLY_NOEXEC
5388 +#define __S010 PAGE_SHARE_NOEXEC
5389 +#define __S011 PAGE_SHARE_NOEXEC
5390 #define __S100 PAGE_READONLY
5391 #define __S101 PAGE_READONLY
5392 #define __S110 PAGE_SHARED
5393 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5394 index 79da178..c2eede8 100644
5395 --- a/arch/sparc/include/asm/pgtsrmmu.h
5396 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5397 @@ -115,6 +115,11 @@
5398 SRMMU_EXEC | SRMMU_REF)
5399 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5400 SRMMU_EXEC | SRMMU_REF)
5401 +
5402 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5403 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5404 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5405 +
5406 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5407 SRMMU_DIRTY | SRMMU_REF)
5408
5409 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5410 index 9689176..63c18ea 100644
5411 --- a/arch/sparc/include/asm/spinlock_64.h
5412 +++ b/arch/sparc/include/asm/spinlock_64.h
5413 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5414
5415 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5416
5417 -static void inline arch_read_lock(arch_rwlock_t *lock)
5418 +static inline void arch_read_lock(arch_rwlock_t *lock)
5419 {
5420 unsigned long tmp1, tmp2;
5421
5422 __asm__ __volatile__ (
5423 "1: ldsw [%2], %0\n"
5424 " brlz,pn %0, 2f\n"
5425 -"4: add %0, 1, %1\n"
5426 +"4: addcc %0, 1, %1\n"
5427 +
5428 +#ifdef CONFIG_PAX_REFCOUNT
5429 +" tvs %%icc, 6\n"
5430 +#endif
5431 +
5432 " cas [%2], %0, %1\n"
5433 " cmp %0, %1\n"
5434 " bne,pn %%icc, 1b\n"
5435 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5436 " .previous"
5437 : "=&r" (tmp1), "=&r" (tmp2)
5438 : "r" (lock)
5439 - : "memory");
5440 + : "memory", "cc");
5441 }
5442
5443 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5444 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5445 {
5446 int tmp1, tmp2;
5447
5448 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5449 "1: ldsw [%2], %0\n"
5450 " brlz,a,pn %0, 2f\n"
5451 " mov 0, %0\n"
5452 -" add %0, 1, %1\n"
5453 +" addcc %0, 1, %1\n"
5454 +
5455 +#ifdef CONFIG_PAX_REFCOUNT
5456 +" tvs %%icc, 6\n"
5457 +#endif
5458 +
5459 " cas [%2], %0, %1\n"
5460 " cmp %0, %1\n"
5461 " bne,pn %%icc, 1b\n"
5462 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5463 return tmp1;
5464 }
5465
5466 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5467 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5468 {
5469 unsigned long tmp1, tmp2;
5470
5471 __asm__ __volatile__(
5472 "1: lduw [%2], %0\n"
5473 -" sub %0, 1, %1\n"
5474 +" subcc %0, 1, %1\n"
5475 +
5476 +#ifdef CONFIG_PAX_REFCOUNT
5477 +" tvs %%icc, 6\n"
5478 +#endif
5479 +
5480 " cas [%2], %0, %1\n"
5481 " cmp %0, %1\n"
5482 " bne,pn %%xcc, 1b\n"
5483 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5484 : "memory");
5485 }
5486
5487 -static void inline arch_write_lock(arch_rwlock_t *lock)
5488 +static inline void arch_write_lock(arch_rwlock_t *lock)
5489 {
5490 unsigned long mask, tmp1, tmp2;
5491
5492 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5493 : "memory");
5494 }
5495
5496 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5497 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5498 {
5499 __asm__ __volatile__(
5500 " stw %%g0, [%0]"
5501 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5502 : "memory");
5503 }
5504
5505 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5506 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5507 {
5508 unsigned long mask, tmp1, tmp2, result;
5509
5510 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5511 index e6cd224..3a71793 100644
5512 --- a/arch/sparc/include/asm/thread_info_32.h
5513 +++ b/arch/sparc/include/asm/thread_info_32.h
5514 @@ -49,6 +49,8 @@ struct thread_info {
5515 unsigned long w_saved;
5516
5517 struct restart_block restart_block;
5518 +
5519 + unsigned long lowest_stack;
5520 };
5521
5522 /*
5523 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5524 index cfa8c38..13f30d3 100644
5525 --- a/arch/sparc/include/asm/thread_info_64.h
5526 +++ b/arch/sparc/include/asm/thread_info_64.h
5527 @@ -63,6 +63,8 @@ struct thread_info {
5528 struct pt_regs *kern_una_regs;
5529 unsigned int kern_una_insn;
5530
5531 + unsigned long lowest_stack;
5532 +
5533 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5534 };
5535
5536 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5537 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5538 /* flag bit 6 is available */
5539 #define TIF_32BIT 7 /* 32-bit binary */
5540 -/* flag bit 8 is available */
5541 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5542 #define TIF_SECCOMP 9 /* secure computing */
5543 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5544 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5545 +
5546 /* NOTE: Thread flags >= 12 should be ones we have no interest
5547 * in using in assembly, else we can't use the mask as
5548 * an immediate value in instructions such as andcc.
5549 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5550 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5551 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5552 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5553 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5554
5555 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5556 _TIF_DO_NOTIFY_RESUME_MASK | \
5557 _TIF_NEED_RESCHED)
5558 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5559
5560 +#define _TIF_WORK_SYSCALL \
5561 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5562 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5563 +
5564 +
5565 /*
5566 * Thread-synchronous status.
5567 *
5568 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5569 index 0167d26..9acd8ed 100644
5570 --- a/arch/sparc/include/asm/uaccess.h
5571 +++ b/arch/sparc/include/asm/uaccess.h
5572 @@ -1,5 +1,13 @@
5573 #ifndef ___ASM_SPARC_UACCESS_H
5574 #define ___ASM_SPARC_UACCESS_H
5575 +
5576 +#ifdef __KERNEL__
5577 +#ifndef __ASSEMBLY__
5578 +#include <linux/types.h>
5579 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5580 +#endif
5581 +#endif
5582 +
5583 #if defined(__sparc__) && defined(__arch64__)
5584 #include <asm/uaccess_64.h>
5585 #else
5586 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5587 index 53a28dd..50c38c3 100644
5588 --- a/arch/sparc/include/asm/uaccess_32.h
5589 +++ b/arch/sparc/include/asm/uaccess_32.h
5590 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5591
5592 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5593 {
5594 - if (n && __access_ok((unsigned long) to, n))
5595 + if ((long)n < 0)
5596 + return n;
5597 +
5598 + if (n && __access_ok((unsigned long) to, n)) {
5599 + if (!__builtin_constant_p(n))
5600 + check_object_size(from, n, true);
5601 return __copy_user(to, (__force void __user *) from, n);
5602 - else
5603 + } else
5604 return n;
5605 }
5606
5607 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5608 {
5609 + if ((long)n < 0)
5610 + return n;
5611 +
5612 + if (!__builtin_constant_p(n))
5613 + check_object_size(from, n, true);
5614 +
5615 return __copy_user(to, (__force void __user *) from, n);
5616 }
5617
5618 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5619 {
5620 - if (n && __access_ok((unsigned long) from, n))
5621 + if ((long)n < 0)
5622 + return n;
5623 +
5624 + if (n && __access_ok((unsigned long) from, n)) {
5625 + if (!__builtin_constant_p(n))
5626 + check_object_size(to, n, false);
5627 return __copy_user((__force void __user *) to, from, n);
5628 - else
5629 + } else
5630 return n;
5631 }
5632
5633 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5634 {
5635 + if ((long)n < 0)
5636 + return n;
5637 +
5638 return __copy_user((__force void __user *) to, from, n);
5639 }
5640
5641 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5642 index 7c831d8..d440ca7 100644
5643 --- a/arch/sparc/include/asm/uaccess_64.h
5644 +++ b/arch/sparc/include/asm/uaccess_64.h
5645 @@ -10,6 +10,7 @@
5646 #include <linux/compiler.h>
5647 #include <linux/string.h>
5648 #include <linux/thread_info.h>
5649 +#include <linux/kernel.h>
5650 #include <asm/asi.h>
5651 #include <asm/spitfire.h>
5652 #include <asm-generic/uaccess-unaligned.h>
5653 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5654 static inline unsigned long __must_check
5655 copy_from_user(void *to, const void __user *from, unsigned long size)
5656 {
5657 - unsigned long ret = ___copy_from_user(to, from, size);
5658 + unsigned long ret;
5659
5660 + if ((long)size < 0 || size > INT_MAX)
5661 + return size;
5662 +
5663 + if (!__builtin_constant_p(size))
5664 + check_object_size(to, size, false);
5665 +
5666 + ret = ___copy_from_user(to, from, size);
5667 if (unlikely(ret))
5668 ret = copy_from_user_fixup(to, from, size);
5669
5670 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5671 static inline unsigned long __must_check
5672 copy_to_user(void __user *to, const void *from, unsigned long size)
5673 {
5674 - unsigned long ret = ___copy_to_user(to, from, size);
5675 + unsigned long ret;
5676
5677 + if ((long)size < 0 || size > INT_MAX)
5678 + return size;
5679 +
5680 + if (!__builtin_constant_p(size))
5681 + check_object_size(from, size, true);
5682 +
5683 + ret = ___copy_to_user(to, from, size);
5684 if (unlikely(ret))
5685 ret = copy_to_user_fixup(to, from, size);
5686 return ret;
5687 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5688 index 6cf591b..b49e65a 100644
5689 --- a/arch/sparc/kernel/Makefile
5690 +++ b/arch/sparc/kernel/Makefile
5691 @@ -3,7 +3,7 @@
5692 #
5693
5694 asflags-y := -ansi
5695 -ccflags-y := -Werror
5696 +#ccflags-y := -Werror
5697
5698 extra-y := head_$(BITS).o
5699
5700 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5701 index cb36e82..1c1462f 100644
5702 --- a/arch/sparc/kernel/process_32.c
5703 +++ b/arch/sparc/kernel/process_32.c
5704 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5705
5706 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5707 r->psr, r->pc, r->npc, r->y, print_tainted());
5708 - printk("PC: <%pS>\n", (void *) r->pc);
5709 + printk("PC: <%pA>\n", (void *) r->pc);
5710 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5711 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5712 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5713 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5714 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5715 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5716 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5717 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5718
5719 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5720 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5721 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5722 rw = (struct reg_window32 *) fp;
5723 pc = rw->ins[7];
5724 printk("[%08lx : ", pc);
5725 - printk("%pS ] ", (void *) pc);
5726 + printk("%pA ] ", (void *) pc);
5727 fp = rw->ins[6];
5728 } while (++count < 16);
5729 printk("\n");
5730 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5731 index aff0c72..9067b39 100644
5732 --- a/arch/sparc/kernel/process_64.c
5733 +++ b/arch/sparc/kernel/process_64.c
5734 @@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5735 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5736 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5737 if (regs->tstate & TSTATE_PRIV)
5738 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5739 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5740 }
5741
5742 void show_regs(struct pt_regs *regs)
5743 {
5744 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5745 regs->tpc, regs->tnpc, regs->y, print_tainted());
5746 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5747 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5748 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5749 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5750 regs->u_regs[3]);
5751 @@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5752 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5753 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5754 regs->u_regs[15]);
5755 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5756 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5757 show_regwindow(regs);
5758 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5759 }
5760 @@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5761 ((tp && tp->task) ? tp->task->pid : -1));
5762
5763 if (gp->tstate & TSTATE_PRIV) {
5764 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5765 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5766 (void *) gp->tpc,
5767 (void *) gp->o7,
5768 (void *) gp->i7,
5769 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5770 index 484daba..0674139 100644
5771 --- a/arch/sparc/kernel/ptrace_64.c
5772 +++ b/arch/sparc/kernel/ptrace_64.c
5773 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5774 return ret;
5775 }
5776
5777 +#ifdef CONFIG_GRKERNSEC_SETXID
5778 +extern void gr_delayed_cred_worker(void);
5779 +#endif
5780 +
5781 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5782 {
5783 int ret = 0;
5784 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5785 /* do the secure computing check first */
5786 secure_computing_strict(regs->u_regs[UREG_G1]);
5787
5788 +#ifdef CONFIG_GRKERNSEC_SETXID
5789 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5790 + gr_delayed_cred_worker();
5791 +#endif
5792 +
5793 if (test_thread_flag(TIF_SYSCALL_TRACE))
5794 ret = tracehook_report_syscall_entry(regs);
5795
5796 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5797
5798 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5799 {
5800 +#ifdef CONFIG_GRKERNSEC_SETXID
5801 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5802 + gr_delayed_cred_worker();
5803 +#endif
5804 +
5805 audit_syscall_exit(regs);
5806
5807 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5808 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5809 index 0c9b31b..7cb7aee 100644
5810 --- a/arch/sparc/kernel/sys_sparc_32.c
5811 +++ b/arch/sparc/kernel/sys_sparc_32.c
5812 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5813 if (len > TASK_SIZE - PAGE_SIZE)
5814 return -ENOMEM;
5815 if (!addr)
5816 - addr = TASK_UNMAPPED_BASE;
5817 + addr = current->mm->mmap_base;
5818
5819 if (flags & MAP_SHARED)
5820 addr = COLOUR_ALIGN(addr);
5821 @@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5822 /* At this point: (!vmm || addr < vmm->vm_end). */
5823 if (TASK_SIZE - PAGE_SIZE - len < addr)
5824 return -ENOMEM;
5825 - if (!vmm || addr + len <= vmm->vm_start)
5826 + if (check_heap_stack_gap(vmm, addr, len))
5827 return addr;
5828 addr = vmm->vm_end;
5829 if (flags & MAP_SHARED)
5830 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5831 index 275f74f..81bf5b8 100644
5832 --- a/arch/sparc/kernel/sys_sparc_64.c
5833 +++ b/arch/sparc/kernel/sys_sparc_64.c
5834 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5835 /* We do not accept a shared mapping if it would violate
5836 * cache aliasing constraints.
5837 */
5838 - if ((flags & MAP_SHARED) &&
5839 + if ((filp || (flags & MAP_SHARED)) &&
5840 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5841 return -EINVAL;
5842 return addr;
5843 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5844 if (filp || (flags & MAP_SHARED))
5845 do_color_align = 1;
5846
5847 +#ifdef CONFIG_PAX_RANDMMAP
5848 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5849 +#endif
5850 +
5851 if (addr) {
5852 if (do_color_align)
5853 addr = COLOUR_ALIGN(addr, pgoff);
5854 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5855 addr = PAGE_ALIGN(addr);
5856
5857 vma = find_vma(mm, addr);
5858 - if (task_size - len >= addr &&
5859 - (!vma || addr + len <= vma->vm_start))
5860 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5861 return addr;
5862 }
5863
5864 if (len > mm->cached_hole_size) {
5865 - start_addr = addr = mm->free_area_cache;
5866 + start_addr = addr = mm->free_area_cache;
5867 } else {
5868 - start_addr = addr = TASK_UNMAPPED_BASE;
5869 + start_addr = addr = mm->mmap_base;
5870 mm->cached_hole_size = 0;
5871 }
5872
5873 @@ -174,14 +177,14 @@ full_search:
5874 vma = find_vma(mm, VA_EXCLUDE_END);
5875 }
5876 if (unlikely(task_size < addr)) {
5877 - if (start_addr != TASK_UNMAPPED_BASE) {
5878 - start_addr = addr = TASK_UNMAPPED_BASE;
5879 + if (start_addr != mm->mmap_base) {
5880 + start_addr = addr = mm->mmap_base;
5881 mm->cached_hole_size = 0;
5882 goto full_search;
5883 }
5884 return -ENOMEM;
5885 }
5886 - if (likely(!vma || addr + len <= vma->vm_start)) {
5887 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5888 /*
5889 * Remember the place where we stopped the search:
5890 */
5891 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5892 /* We do not accept a shared mapping if it would violate
5893 * cache aliasing constraints.
5894 */
5895 - if ((flags & MAP_SHARED) &&
5896 + if ((filp || (flags & MAP_SHARED)) &&
5897 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5898 return -EINVAL;
5899 return addr;
5900 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5901 addr = PAGE_ALIGN(addr);
5902
5903 vma = find_vma(mm, addr);
5904 - if (task_size - len >= addr &&
5905 - (!vma || addr + len <= vma->vm_start))
5906 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5907 return addr;
5908 }
5909
5910 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5911 /* make sure it can fit in the remaining address space */
5912 if (likely(addr > len)) {
5913 vma = find_vma(mm, addr-len);
5914 - if (!vma || addr <= vma->vm_start) {
5915 + if (check_heap_stack_gap(vma, addr - len, len)) {
5916 /* remember the address as a hint for next time */
5917 return (mm->free_area_cache = addr-len);
5918 }
5919 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5920 if (unlikely(mm->mmap_base < len))
5921 goto bottomup;
5922
5923 - addr = mm->mmap_base-len;
5924 - if (do_color_align)
5925 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5926 + addr = mm->mmap_base - len;
5927
5928 do {
5929 + if (do_color_align)
5930 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5931 /*
5932 * Lookup failure means no vma is above this address,
5933 * else if new region fits below vma->vm_start,
5934 * return with success:
5935 */
5936 vma = find_vma(mm, addr);
5937 - if (likely(!vma || addr+len <= vma->vm_start)) {
5938 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5939 /* remember the address as a hint for next time */
5940 return (mm->free_area_cache = addr);
5941 }
5942 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5943 mm->cached_hole_size = vma->vm_start - addr;
5944
5945 /* try just below the current vma->vm_start */
5946 - addr = vma->vm_start-len;
5947 - if (do_color_align)
5948 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5949 - } while (likely(len < vma->vm_start));
5950 + addr = skip_heap_stack_gap(vma, len);
5951 + } while (!IS_ERR_VALUE(addr));
5952
5953 bottomup:
5954 /*
5955 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5956 gap == RLIM_INFINITY ||
5957 sysctl_legacy_va_layout) {
5958 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5959 +
5960 +#ifdef CONFIG_PAX_RANDMMAP
5961 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5962 + mm->mmap_base += mm->delta_mmap;
5963 +#endif
5964 +
5965 mm->get_unmapped_area = arch_get_unmapped_area;
5966 mm->unmap_area = arch_unmap_area;
5967 } else {
5968 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5969 gap = (task_size / 6 * 5);
5970
5971 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5972 +
5973 +#ifdef CONFIG_PAX_RANDMMAP
5974 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5975 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5976 +#endif
5977 +
5978 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5979 mm->unmap_area = arch_unmap_area_topdown;
5980 }
5981 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5982 index 1d7e274..b39c527 100644
5983 --- a/arch/sparc/kernel/syscalls.S
5984 +++ b/arch/sparc/kernel/syscalls.S
5985 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
5986 #endif
5987 .align 32
5988 1: ldx [%g6 + TI_FLAGS], %l5
5989 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5990 + andcc %l5, _TIF_WORK_SYSCALL, %g0
5991 be,pt %icc, rtrap
5992 nop
5993 call syscall_trace_leave
5994 @@ -179,7 +179,7 @@ linux_sparc_syscall32:
5995
5996 srl %i5, 0, %o5 ! IEU1
5997 srl %i2, 0, %o2 ! IEU0 Group
5998 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5999 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6000 bne,pn %icc, linux_syscall_trace32 ! CTI
6001 mov %i0, %l5 ! IEU1
6002 call %l7 ! CTI Group brk forced
6003 @@ -202,7 +202,7 @@ linux_sparc_syscall:
6004
6005 mov %i3, %o3 ! IEU1
6006 mov %i4, %o4 ! IEU0 Group
6007 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6008 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6009 bne,pn %icc, linux_syscall_trace ! CTI Group
6010 mov %i0, %l5 ! IEU0
6011 2: call %l7 ! CTI Group brk forced
6012 @@ -226,7 +226,7 @@ ret_sys_call:
6013
6014 cmp %o0, -ERESTART_RESTARTBLOCK
6015 bgeu,pn %xcc, 1f
6016 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6017 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6018 80:
6019 /* System call success, clear Carry condition code. */
6020 andn %g3, %g2, %g3
6021 @@ -241,7 +241,7 @@ ret_sys_call:
6022 /* System call failure, set Carry condition code.
6023 * Also, get abs(errno) to return to the process.
6024 */
6025 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6026 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6027 sub %g0, %o0, %o0
6028 or %g3, %g2, %g3
6029 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6030 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6031 index a5785ea..405c5f7 100644
6032 --- a/arch/sparc/kernel/traps_32.c
6033 +++ b/arch/sparc/kernel/traps_32.c
6034 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6035 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6036 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6037
6038 +extern void gr_handle_kernel_exploit(void);
6039 +
6040 void die_if_kernel(char *str, struct pt_regs *regs)
6041 {
6042 static int die_counter;
6043 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6044 count++ < 30 &&
6045 (((unsigned long) rw) >= PAGE_OFFSET) &&
6046 !(((unsigned long) rw) & 0x7)) {
6047 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6048 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6049 (void *) rw->ins[7]);
6050 rw = (struct reg_window32 *)rw->ins[6];
6051 }
6052 }
6053 printk("Instruction DUMP:");
6054 instruction_dump ((unsigned long *) regs->pc);
6055 - if(regs->psr & PSR_PS)
6056 + if(regs->psr & PSR_PS) {
6057 + gr_handle_kernel_exploit();
6058 do_exit(SIGKILL);
6059 + }
6060 do_exit(SIGSEGV);
6061 }
6062
6063 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6064 index 3b05e66..6ea2917 100644
6065 --- a/arch/sparc/kernel/traps_64.c
6066 +++ b/arch/sparc/kernel/traps_64.c
6067 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6068 i + 1,
6069 p->trapstack[i].tstate, p->trapstack[i].tpc,
6070 p->trapstack[i].tnpc, p->trapstack[i].tt);
6071 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6072 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6073 }
6074 }
6075
6076 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6077
6078 lvl -= 0x100;
6079 if (regs->tstate & TSTATE_PRIV) {
6080 +
6081 +#ifdef CONFIG_PAX_REFCOUNT
6082 + if (lvl == 6)
6083 + pax_report_refcount_overflow(regs);
6084 +#endif
6085 +
6086 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6087 die_if_kernel(buffer, regs);
6088 }
6089 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6090 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6091 {
6092 char buffer[32];
6093 -
6094 +
6095 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6096 0, lvl, SIGTRAP) == NOTIFY_STOP)
6097 return;
6098
6099 +#ifdef CONFIG_PAX_REFCOUNT
6100 + if (lvl == 6)
6101 + pax_report_refcount_overflow(regs);
6102 +#endif
6103 +
6104 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6105
6106 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6107 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6108 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6109 printk("%s" "ERROR(%d): ",
6110 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6111 - printk("TPC<%pS>\n", (void *) regs->tpc);
6112 + printk("TPC<%pA>\n", (void *) regs->tpc);
6113 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6114 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6115 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6116 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6117 smp_processor_id(),
6118 (type & 0x1) ? 'I' : 'D',
6119 regs->tpc);
6120 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6121 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6122 panic("Irrecoverable Cheetah+ parity error.");
6123 }
6124
6125 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6126 smp_processor_id(),
6127 (type & 0x1) ? 'I' : 'D',
6128 regs->tpc);
6129 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6130 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6131 }
6132
6133 struct sun4v_error_entry {
6134 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6135
6136 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6137 regs->tpc, tl);
6138 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6139 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6140 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6141 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6142 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6143 (void *) regs->u_regs[UREG_I7]);
6144 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6145 "pte[%lx] error[%lx]\n",
6146 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6147
6148 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6149 regs->tpc, tl);
6150 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6151 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6152 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6153 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6154 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6155 (void *) regs->u_regs[UREG_I7]);
6156 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6157 "pte[%lx] error[%lx]\n",
6158 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6159 fp = (unsigned long)sf->fp + STACK_BIAS;
6160 }
6161
6162 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6163 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6164 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6165 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6166 int index = tsk->curr_ret_stack;
6167 if (tsk->ret_stack && index >= graph) {
6168 pc = tsk->ret_stack[index - graph].ret;
6169 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6170 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6171 graph++;
6172 }
6173 }
6174 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6175 return (struct reg_window *) (fp + STACK_BIAS);
6176 }
6177
6178 +extern void gr_handle_kernel_exploit(void);
6179 +
6180 void die_if_kernel(char *str, struct pt_regs *regs)
6181 {
6182 static int die_counter;
6183 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6184 while (rw &&
6185 count++ < 30 &&
6186 kstack_valid(tp, (unsigned long) rw)) {
6187 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6188 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6189 (void *) rw->ins[7]);
6190
6191 rw = kernel_stack_up(rw);
6192 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6193 }
6194 user_instruction_dump ((unsigned int __user *) regs->tpc);
6195 }
6196 - if (regs->tstate & TSTATE_PRIV)
6197 + if (regs->tstate & TSTATE_PRIV) {
6198 + gr_handle_kernel_exploit();
6199 do_exit(SIGKILL);
6200 + }
6201 do_exit(SIGSEGV);
6202 }
6203 EXPORT_SYMBOL(die_if_kernel);
6204 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6205 index f81d038..e7a4680 100644
6206 --- a/arch/sparc/kernel/unaligned_64.c
6207 +++ b/arch/sparc/kernel/unaligned_64.c
6208 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6209 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6210
6211 if (__ratelimit(&ratelimit)) {
6212 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6213 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6214 regs->tpc, (void *) regs->tpc);
6215 }
6216 }
6217 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6218 index dff4096..bd9a388 100644
6219 --- a/arch/sparc/lib/Makefile
6220 +++ b/arch/sparc/lib/Makefile
6221 @@ -2,7 +2,7 @@
6222 #
6223
6224 asflags-y := -ansi -DST_DIV0=0x02
6225 -ccflags-y := -Werror
6226 +#ccflags-y := -Werror
6227
6228 lib-$(CONFIG_SPARC32) += ashrdi3.o
6229 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6230 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6231 index 4d502da..527c48d 100644
6232 --- a/arch/sparc/lib/atomic_64.S
6233 +++ b/arch/sparc/lib/atomic_64.S
6234 @@ -17,7 +17,12 @@
6235 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6236 BACKOFF_SETUP(%o2)
6237 1: lduw [%o1], %g1
6238 - add %g1, %o0, %g7
6239 + addcc %g1, %o0, %g7
6240 +
6241 +#ifdef CONFIG_PAX_REFCOUNT
6242 + tvs %icc, 6
6243 +#endif
6244 +
6245 cas [%o1], %g1, %g7
6246 cmp %g1, %g7
6247 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6248 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6249 2: BACKOFF_SPIN(%o2, %o3, 1b)
6250 ENDPROC(atomic_add)
6251
6252 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6253 + BACKOFF_SETUP(%o2)
6254 +1: lduw [%o1], %g1
6255 + add %g1, %o0, %g7
6256 + cas [%o1], %g1, %g7
6257 + cmp %g1, %g7
6258 + bne,pn %icc, 2f
6259 + nop
6260 + retl
6261 + nop
6262 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6263 +ENDPROC(atomic_add_unchecked)
6264 +
6265 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6266 BACKOFF_SETUP(%o2)
6267 1: lduw [%o1], %g1
6268 - sub %g1, %o0, %g7
6269 + subcc %g1, %o0, %g7
6270 +
6271 +#ifdef CONFIG_PAX_REFCOUNT
6272 + tvs %icc, 6
6273 +#endif
6274 +
6275 cas [%o1], %g1, %g7
6276 cmp %g1, %g7
6277 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6278 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6279 2: BACKOFF_SPIN(%o2, %o3, 1b)
6280 ENDPROC(atomic_sub)
6281
6282 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6283 + BACKOFF_SETUP(%o2)
6284 +1: lduw [%o1], %g1
6285 + sub %g1, %o0, %g7
6286 + cas [%o1], %g1, %g7
6287 + cmp %g1, %g7
6288 + bne,pn %icc, 2f
6289 + nop
6290 + retl
6291 + nop
6292 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6293 +ENDPROC(atomic_sub_unchecked)
6294 +
6295 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6296 BACKOFF_SETUP(%o2)
6297 1: lduw [%o1], %g1
6298 - add %g1, %o0, %g7
6299 + addcc %g1, %o0, %g7
6300 +
6301 +#ifdef CONFIG_PAX_REFCOUNT
6302 + tvs %icc, 6
6303 +#endif
6304 +
6305 cas [%o1], %g1, %g7
6306 cmp %g1, %g7
6307 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6308 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6309 2: BACKOFF_SPIN(%o2, %o3, 1b)
6310 ENDPROC(atomic_add_ret)
6311
6312 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6313 + BACKOFF_SETUP(%o2)
6314 +1: lduw [%o1], %g1
6315 + addcc %g1, %o0, %g7
6316 + cas [%o1], %g1, %g7
6317 + cmp %g1, %g7
6318 + bne,pn %icc, 2f
6319 + add %g7, %o0, %g7
6320 + sra %g7, 0, %o0
6321 + retl
6322 + nop
6323 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6324 +ENDPROC(atomic_add_ret_unchecked)
6325 +
6326 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6327 BACKOFF_SETUP(%o2)
6328 1: lduw [%o1], %g1
6329 - sub %g1, %o0, %g7
6330 + subcc %g1, %o0, %g7
6331 +
6332 +#ifdef CONFIG_PAX_REFCOUNT
6333 + tvs %icc, 6
6334 +#endif
6335 +
6336 cas [%o1], %g1, %g7
6337 cmp %g1, %g7
6338 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6339 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6340 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6341 BACKOFF_SETUP(%o2)
6342 1: ldx [%o1], %g1
6343 - add %g1, %o0, %g7
6344 + addcc %g1, %o0, %g7
6345 +
6346 +#ifdef CONFIG_PAX_REFCOUNT
6347 + tvs %xcc, 6
6348 +#endif
6349 +
6350 casx [%o1], %g1, %g7
6351 cmp %g1, %g7
6352 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6353 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6354 2: BACKOFF_SPIN(%o2, %o3, 1b)
6355 ENDPROC(atomic64_add)
6356
6357 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6358 + BACKOFF_SETUP(%o2)
6359 +1: ldx [%o1], %g1
6360 + addcc %g1, %o0, %g7
6361 + casx [%o1], %g1, %g7
6362 + cmp %g1, %g7
6363 + bne,pn %xcc, 2f
6364 + nop
6365 + retl
6366 + nop
6367 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6368 +ENDPROC(atomic64_add_unchecked)
6369 +
6370 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6371 BACKOFF_SETUP(%o2)
6372 1: ldx [%o1], %g1
6373 - sub %g1, %o0, %g7
6374 + subcc %g1, %o0, %g7
6375 +
6376 +#ifdef CONFIG_PAX_REFCOUNT
6377 + tvs %xcc, 6
6378 +#endif
6379 +
6380 casx [%o1], %g1, %g7
6381 cmp %g1, %g7
6382 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6383 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6384 2: BACKOFF_SPIN(%o2, %o3, 1b)
6385 ENDPROC(atomic64_sub)
6386
6387 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6388 + BACKOFF_SETUP(%o2)
6389 +1: ldx [%o1], %g1
6390 + subcc %g1, %o0, %g7
6391 + casx [%o1], %g1, %g7
6392 + cmp %g1, %g7
6393 + bne,pn %xcc, 2f
6394 + nop
6395 + retl
6396 + nop
6397 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6398 +ENDPROC(atomic64_sub_unchecked)
6399 +
6400 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6401 BACKOFF_SETUP(%o2)
6402 1: ldx [%o1], %g1
6403 - add %g1, %o0, %g7
6404 + addcc %g1, %o0, %g7
6405 +
6406 +#ifdef CONFIG_PAX_REFCOUNT
6407 + tvs %xcc, 6
6408 +#endif
6409 +
6410 casx [%o1], %g1, %g7
6411 cmp %g1, %g7
6412 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6413 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6414 2: BACKOFF_SPIN(%o2, %o3, 1b)
6415 ENDPROC(atomic64_add_ret)
6416
6417 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6418 + BACKOFF_SETUP(%o2)
6419 +1: ldx [%o1], %g1
6420 + addcc %g1, %o0, %g7
6421 + casx [%o1], %g1, %g7
6422 + cmp %g1, %g7
6423 + bne,pn %xcc, 2f
6424 + add %g7, %o0, %g7
6425 + mov %g7, %o0
6426 + retl
6427 + nop
6428 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6429 +ENDPROC(atomic64_add_ret_unchecked)
6430 +
6431 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6432 BACKOFF_SETUP(%o2)
6433 1: ldx [%o1], %g1
6434 - sub %g1, %o0, %g7
6435 + subcc %g1, %o0, %g7
6436 +
6437 +#ifdef CONFIG_PAX_REFCOUNT
6438 + tvs %xcc, 6
6439 +#endif
6440 +
6441 casx [%o1], %g1, %g7
6442 cmp %g1, %g7
6443 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6444 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6445 index 3b31218..345c609 100644
6446 --- a/arch/sparc/lib/ksyms.c
6447 +++ b/arch/sparc/lib/ksyms.c
6448 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6449
6450 /* Atomic counter implementation. */
6451 EXPORT_SYMBOL(atomic_add);
6452 +EXPORT_SYMBOL(atomic_add_unchecked);
6453 EXPORT_SYMBOL(atomic_add_ret);
6454 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6455 EXPORT_SYMBOL(atomic_sub);
6456 +EXPORT_SYMBOL(atomic_sub_unchecked);
6457 EXPORT_SYMBOL(atomic_sub_ret);
6458 EXPORT_SYMBOL(atomic64_add);
6459 +EXPORT_SYMBOL(atomic64_add_unchecked);
6460 EXPORT_SYMBOL(atomic64_add_ret);
6461 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6462 EXPORT_SYMBOL(atomic64_sub);
6463 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6464 EXPORT_SYMBOL(atomic64_sub_ret);
6465
6466 /* Atomic bit operations. */
6467 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6468 index 30c3ecc..736f015 100644
6469 --- a/arch/sparc/mm/Makefile
6470 +++ b/arch/sparc/mm/Makefile
6471 @@ -2,7 +2,7 @@
6472 #
6473
6474 asflags-y := -ansi
6475 -ccflags-y := -Werror
6476 +#ccflags-y := -Werror
6477
6478 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6479 obj-y += fault_$(BITS).o
6480 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6481 index f46cf6b..cc0666bae 100644
6482 --- a/arch/sparc/mm/fault_32.c
6483 +++ b/arch/sparc/mm/fault_32.c
6484 @@ -21,6 +21,9 @@
6485 #include <linux/perf_event.h>
6486 #include <linux/interrupt.h>
6487 #include <linux/kdebug.h>
6488 +#include <linux/slab.h>
6489 +#include <linux/pagemap.h>
6490 +#include <linux/compiler.h>
6491
6492 #include <asm/page.h>
6493 #include <asm/pgtable.h>
6494 @@ -177,6 +180,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6495 return safe_compute_effective_address(regs, insn);
6496 }
6497
6498 +#ifdef CONFIG_PAX_PAGEEXEC
6499 +#ifdef CONFIG_PAX_DLRESOLVE
6500 +static void pax_emuplt_close(struct vm_area_struct *vma)
6501 +{
6502 + vma->vm_mm->call_dl_resolve = 0UL;
6503 +}
6504 +
6505 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6506 +{
6507 + unsigned int *kaddr;
6508 +
6509 + vmf->page = alloc_page(GFP_HIGHUSER);
6510 + if (!vmf->page)
6511 + return VM_FAULT_OOM;
6512 +
6513 + kaddr = kmap(vmf->page);
6514 + memset(kaddr, 0, PAGE_SIZE);
6515 + kaddr[0] = 0x9DE3BFA8U; /* save */
6516 + flush_dcache_page(vmf->page);
6517 + kunmap(vmf->page);
6518 + return VM_FAULT_MAJOR;
6519 +}
6520 +
6521 +static const struct vm_operations_struct pax_vm_ops = {
6522 + .close = pax_emuplt_close,
6523 + .fault = pax_emuplt_fault
6524 +};
6525 +
6526 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6527 +{
6528 + int ret;
6529 +
6530 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6531 + vma->vm_mm = current->mm;
6532 + vma->vm_start = addr;
6533 + vma->vm_end = addr + PAGE_SIZE;
6534 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6535 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6536 + vma->vm_ops = &pax_vm_ops;
6537 +
6538 + ret = insert_vm_struct(current->mm, vma);
6539 + if (ret)
6540 + return ret;
6541 +
6542 + ++current->mm->total_vm;
6543 + return 0;
6544 +}
6545 +#endif
6546 +
6547 +/*
6548 + * PaX: decide what to do with offenders (regs->pc = fault address)
6549 + *
6550 + * returns 1 when task should be killed
6551 + * 2 when patched PLT trampoline was detected
6552 + * 3 when unpatched PLT trampoline was detected
6553 + */
6554 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6555 +{
6556 +
6557 +#ifdef CONFIG_PAX_EMUPLT
6558 + int err;
6559 +
6560 + do { /* PaX: patched PLT emulation #1 */
6561 + unsigned int sethi1, sethi2, jmpl;
6562 +
6563 + err = get_user(sethi1, (unsigned int *)regs->pc);
6564 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6565 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6566 +
6567 + if (err)
6568 + break;
6569 +
6570 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6571 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6572 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6573 + {
6574 + unsigned int addr;
6575 +
6576 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6577 + addr = regs->u_regs[UREG_G1];
6578 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6579 + regs->pc = addr;
6580 + regs->npc = addr+4;
6581 + return 2;
6582 + }
6583 + } while (0);
6584 +
6585 + do { /* PaX: patched PLT emulation #2 */
6586 + unsigned int ba;
6587 +
6588 + err = get_user(ba, (unsigned int *)regs->pc);
6589 +
6590 + if (err)
6591 + break;
6592 +
6593 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6594 + unsigned int addr;
6595 +
6596 + if ((ba & 0xFFC00000U) == 0x30800000U)
6597 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6598 + else
6599 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6600 + regs->pc = addr;
6601 + regs->npc = addr+4;
6602 + return 2;
6603 + }
6604 + } while (0);
6605 +
6606 + do { /* PaX: patched PLT emulation #3 */
6607 + unsigned int sethi, bajmpl, nop;
6608 +
6609 + err = get_user(sethi, (unsigned int *)regs->pc);
6610 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6611 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6612 +
6613 + if (err)
6614 + break;
6615 +
6616 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6617 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6618 + nop == 0x01000000U)
6619 + {
6620 + unsigned int addr;
6621 +
6622 + addr = (sethi & 0x003FFFFFU) << 10;
6623 + regs->u_regs[UREG_G1] = addr;
6624 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6625 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6626 + else
6627 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6628 + regs->pc = addr;
6629 + regs->npc = addr+4;
6630 + return 2;
6631 + }
6632 + } while (0);
6633 +
6634 + do { /* PaX: unpatched PLT emulation step 1 */
6635 + unsigned int sethi, ba, nop;
6636 +
6637 + err = get_user(sethi, (unsigned int *)regs->pc);
6638 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6639 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6640 +
6641 + if (err)
6642 + break;
6643 +
6644 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6645 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6646 + nop == 0x01000000U)
6647 + {
6648 + unsigned int addr, save, call;
6649 +
6650 + if ((ba & 0xFFC00000U) == 0x30800000U)
6651 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6652 + else
6653 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6654 +
6655 + err = get_user(save, (unsigned int *)addr);
6656 + err |= get_user(call, (unsigned int *)(addr+4));
6657 + err |= get_user(nop, (unsigned int *)(addr+8));
6658 + if (err)
6659 + break;
6660 +
6661 +#ifdef CONFIG_PAX_DLRESOLVE
6662 + if (save == 0x9DE3BFA8U &&
6663 + (call & 0xC0000000U) == 0x40000000U &&
6664 + nop == 0x01000000U)
6665 + {
6666 + struct vm_area_struct *vma;
6667 + unsigned long call_dl_resolve;
6668 +
6669 + down_read(&current->mm->mmap_sem);
6670 + call_dl_resolve = current->mm->call_dl_resolve;
6671 + up_read(&current->mm->mmap_sem);
6672 + if (likely(call_dl_resolve))
6673 + goto emulate;
6674 +
6675 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6676 +
6677 + down_write(&current->mm->mmap_sem);
6678 + if (current->mm->call_dl_resolve) {
6679 + call_dl_resolve = current->mm->call_dl_resolve;
6680 + up_write(&current->mm->mmap_sem);
6681 + if (vma)
6682 + kmem_cache_free(vm_area_cachep, vma);
6683 + goto emulate;
6684 + }
6685 +
6686 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6687 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6688 + up_write(&current->mm->mmap_sem);
6689 + if (vma)
6690 + kmem_cache_free(vm_area_cachep, vma);
6691 + return 1;
6692 + }
6693 +
6694 + if (pax_insert_vma(vma, call_dl_resolve)) {
6695 + up_write(&current->mm->mmap_sem);
6696 + kmem_cache_free(vm_area_cachep, vma);
6697 + return 1;
6698 + }
6699 +
6700 + current->mm->call_dl_resolve = call_dl_resolve;
6701 + up_write(&current->mm->mmap_sem);
6702 +
6703 +emulate:
6704 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6705 + regs->pc = call_dl_resolve;
6706 + regs->npc = addr+4;
6707 + return 3;
6708 + }
6709 +#endif
6710 +
6711 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6712 + if ((save & 0xFFC00000U) == 0x05000000U &&
6713 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6714 + nop == 0x01000000U)
6715 + {
6716 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6717 + regs->u_regs[UREG_G2] = addr + 4;
6718 + addr = (save & 0x003FFFFFU) << 10;
6719 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6720 + regs->pc = addr;
6721 + regs->npc = addr+4;
6722 + return 3;
6723 + }
6724 + }
6725 + } while (0);
6726 +
6727 + do { /* PaX: unpatched PLT emulation step 2 */
6728 + unsigned int save, call, nop;
6729 +
6730 + err = get_user(save, (unsigned int *)(regs->pc-4));
6731 + err |= get_user(call, (unsigned int *)regs->pc);
6732 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6733 + if (err)
6734 + break;
6735 +
6736 + if (save == 0x9DE3BFA8U &&
6737 + (call & 0xC0000000U) == 0x40000000U &&
6738 + nop == 0x01000000U)
6739 + {
6740 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6741 +
6742 + regs->u_regs[UREG_RETPC] = regs->pc;
6743 + regs->pc = dl_resolve;
6744 + regs->npc = dl_resolve+4;
6745 + return 3;
6746 + }
6747 + } while (0);
6748 +#endif
6749 +
6750 + return 1;
6751 +}
6752 +
6753 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6754 +{
6755 + unsigned long i;
6756 +
6757 + printk(KERN_ERR "PAX: bytes at PC: ");
6758 + for (i = 0; i < 8; i++) {
6759 + unsigned int c;
6760 + if (get_user(c, (unsigned int *)pc+i))
6761 + printk(KERN_CONT "???????? ");
6762 + else
6763 + printk(KERN_CONT "%08x ", c);
6764 + }
6765 + printk("\n");
6766 +}
6767 +#endif
6768 +
6769 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6770 int text_fault)
6771 {
6772 @@ -248,6 +522,24 @@ good_area:
6773 if (!(vma->vm_flags & VM_WRITE))
6774 goto bad_area;
6775 } else {
6776 +
6777 +#ifdef CONFIG_PAX_PAGEEXEC
6778 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6779 + up_read(&mm->mmap_sem);
6780 + switch (pax_handle_fetch_fault(regs)) {
6781 +
6782 +#ifdef CONFIG_PAX_EMUPLT
6783 + case 2:
6784 + case 3:
6785 + return;
6786 +#endif
6787 +
6788 + }
6789 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6790 + do_group_exit(SIGKILL);
6791 + }
6792 +#endif
6793 +
6794 /* Allow reads even for write-only mappings */
6795 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6796 goto bad_area;
6797 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6798 index 1fe0429..8dd5dd5 100644
6799 --- a/arch/sparc/mm/fault_64.c
6800 +++ b/arch/sparc/mm/fault_64.c
6801 @@ -21,6 +21,9 @@
6802 #include <linux/kprobes.h>
6803 #include <linux/kdebug.h>
6804 #include <linux/percpu.h>
6805 +#include <linux/slab.h>
6806 +#include <linux/pagemap.h>
6807 +#include <linux/compiler.h>
6808
6809 #include <asm/page.h>
6810 #include <asm/pgtable.h>
6811 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6812 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6813 regs->tpc);
6814 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6815 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6816 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6817 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6818 dump_stack();
6819 unhandled_fault(regs->tpc, current, regs);
6820 @@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6821 show_regs(regs);
6822 }
6823
6824 +#ifdef CONFIG_PAX_PAGEEXEC
6825 +#ifdef CONFIG_PAX_DLRESOLVE
6826 +static void pax_emuplt_close(struct vm_area_struct *vma)
6827 +{
6828 + vma->vm_mm->call_dl_resolve = 0UL;
6829 +}
6830 +
6831 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6832 +{
6833 + unsigned int *kaddr;
6834 +
6835 + vmf->page = alloc_page(GFP_HIGHUSER);
6836 + if (!vmf->page)
6837 + return VM_FAULT_OOM;
6838 +
6839 + kaddr = kmap(vmf->page);
6840 + memset(kaddr, 0, PAGE_SIZE);
6841 + kaddr[0] = 0x9DE3BFA8U; /* save */
6842 + flush_dcache_page(vmf->page);
6843 + kunmap(vmf->page);
6844 + return VM_FAULT_MAJOR;
6845 +}
6846 +
6847 +static const struct vm_operations_struct pax_vm_ops = {
6848 + .close = pax_emuplt_close,
6849 + .fault = pax_emuplt_fault
6850 +};
6851 +
6852 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6853 +{
6854 + int ret;
6855 +
6856 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6857 + vma->vm_mm = current->mm;
6858 + vma->vm_start = addr;
6859 + vma->vm_end = addr + PAGE_SIZE;
6860 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6861 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6862 + vma->vm_ops = &pax_vm_ops;
6863 +
6864 + ret = insert_vm_struct(current->mm, vma);
6865 + if (ret)
6866 + return ret;
6867 +
6868 + ++current->mm->total_vm;
6869 + return 0;
6870 +}
6871 +#endif
6872 +
6873 +/*
6874 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6875 + *
6876 + * returns 1 when task should be killed
6877 + * 2 when patched PLT trampoline was detected
6878 + * 3 when unpatched PLT trampoline was detected
6879 + */
6880 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6881 +{
6882 +
6883 +#ifdef CONFIG_PAX_EMUPLT
6884 + int err;
6885 +
6886 + do { /* PaX: patched PLT emulation #1 */
6887 + unsigned int sethi1, sethi2, jmpl;
6888 +
6889 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6890 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6891 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6892 +
6893 + if (err)
6894 + break;
6895 +
6896 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6897 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6898 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6899 + {
6900 + unsigned long addr;
6901 +
6902 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6903 + addr = regs->u_regs[UREG_G1];
6904 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6905 +
6906 + if (test_thread_flag(TIF_32BIT))
6907 + addr &= 0xFFFFFFFFUL;
6908 +
6909 + regs->tpc = addr;
6910 + regs->tnpc = addr+4;
6911 + return 2;
6912 + }
6913 + } while (0);
6914 +
6915 + do { /* PaX: patched PLT emulation #2 */
6916 + unsigned int ba;
6917 +
6918 + err = get_user(ba, (unsigned int *)regs->tpc);
6919 +
6920 + if (err)
6921 + break;
6922 +
6923 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6924 + unsigned long addr;
6925 +
6926 + if ((ba & 0xFFC00000U) == 0x30800000U)
6927 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6928 + else
6929 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6930 +
6931 + if (test_thread_flag(TIF_32BIT))
6932 + addr &= 0xFFFFFFFFUL;
6933 +
6934 + regs->tpc = addr;
6935 + regs->tnpc = addr+4;
6936 + return 2;
6937 + }
6938 + } while (0);
6939 +
6940 + do { /* PaX: patched PLT emulation #3 */
6941 + unsigned int sethi, bajmpl, nop;
6942 +
6943 + err = get_user(sethi, (unsigned int *)regs->tpc);
6944 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6945 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6946 +
6947 + if (err)
6948 + break;
6949 +
6950 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6951 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6952 + nop == 0x01000000U)
6953 + {
6954 + unsigned long addr;
6955 +
6956 + addr = (sethi & 0x003FFFFFU) << 10;
6957 + regs->u_regs[UREG_G1] = addr;
6958 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6959 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6960 + else
6961 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6962 +
6963 + if (test_thread_flag(TIF_32BIT))
6964 + addr &= 0xFFFFFFFFUL;
6965 +
6966 + regs->tpc = addr;
6967 + regs->tnpc = addr+4;
6968 + return 2;
6969 + }
6970 + } while (0);
6971 +
6972 + do { /* PaX: patched PLT emulation #4 */
6973 + unsigned int sethi, mov1, call, mov2;
6974 +
6975 + err = get_user(sethi, (unsigned int *)regs->tpc);
6976 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6977 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6978 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6979 +
6980 + if (err)
6981 + break;
6982 +
6983 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6984 + mov1 == 0x8210000FU &&
6985 + (call & 0xC0000000U) == 0x40000000U &&
6986 + mov2 == 0x9E100001U)
6987 + {
6988 + unsigned long addr;
6989 +
6990 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6991 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6992 +
6993 + if (test_thread_flag(TIF_32BIT))
6994 + addr &= 0xFFFFFFFFUL;
6995 +
6996 + regs->tpc = addr;
6997 + regs->tnpc = addr+4;
6998 + return 2;
6999 + }
7000 + } while (0);
7001 +
7002 + do { /* PaX: patched PLT emulation #5 */
7003 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7004 +
7005 + err = get_user(sethi, (unsigned int *)regs->tpc);
7006 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7007 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7008 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7009 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7010 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7011 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7012 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7013 +
7014 + if (err)
7015 + break;
7016 +
7017 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7018 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7019 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7020 + (or1 & 0xFFFFE000U) == 0x82106000U &&
7021 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7022 + sllx == 0x83287020U &&
7023 + jmpl == 0x81C04005U &&
7024 + nop == 0x01000000U)
7025 + {
7026 + unsigned long addr;
7027 +
7028 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7029 + regs->u_regs[UREG_G1] <<= 32;
7030 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7031 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7032 + regs->tpc = addr;
7033 + regs->tnpc = addr+4;
7034 + return 2;
7035 + }
7036 + } while (0);
7037 +
7038 + do { /* PaX: patched PLT emulation #6 */
7039 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7040 +
7041 + err = get_user(sethi, (unsigned int *)regs->tpc);
7042 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7043 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7044 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7045 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7046 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7047 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7048 +
7049 + if (err)
7050 + break;
7051 +
7052 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7053 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7054 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7055 + sllx == 0x83287020U &&
7056 + (or & 0xFFFFE000U) == 0x8A116000U &&
7057 + jmpl == 0x81C04005U &&
7058 + nop == 0x01000000U)
7059 + {
7060 + unsigned long addr;
7061 +
7062 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7063 + regs->u_regs[UREG_G1] <<= 32;
7064 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7065 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7066 + regs->tpc = addr;
7067 + regs->tnpc = addr+4;
7068 + return 2;
7069 + }
7070 + } while (0);
7071 +
7072 + do { /* PaX: unpatched PLT emulation step 1 */
7073 + unsigned int sethi, ba, nop;
7074 +
7075 + err = get_user(sethi, (unsigned int *)regs->tpc);
7076 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7077 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7078 +
7079 + if (err)
7080 + break;
7081 +
7082 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7083 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7084 + nop == 0x01000000U)
7085 + {
7086 + unsigned long addr;
7087 + unsigned int save, call;
7088 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7089 +
7090 + if ((ba & 0xFFC00000U) == 0x30800000U)
7091 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7092 + else
7093 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7094 +
7095 + if (test_thread_flag(TIF_32BIT))
7096 + addr &= 0xFFFFFFFFUL;
7097 +
7098 + err = get_user(save, (unsigned int *)addr);
7099 + err |= get_user(call, (unsigned int *)(addr+4));
7100 + err |= get_user(nop, (unsigned int *)(addr+8));
7101 + if (err)
7102 + break;
7103 +
7104 +#ifdef CONFIG_PAX_DLRESOLVE
7105 + if (save == 0x9DE3BFA8U &&
7106 + (call & 0xC0000000U) == 0x40000000U &&
7107 + nop == 0x01000000U)
7108 + {
7109 + struct vm_area_struct *vma;
7110 + unsigned long call_dl_resolve;
7111 +
7112 + down_read(&current->mm->mmap_sem);
7113 + call_dl_resolve = current->mm->call_dl_resolve;
7114 + up_read(&current->mm->mmap_sem);
7115 + if (likely(call_dl_resolve))
7116 + goto emulate;
7117 +
7118 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7119 +
7120 + down_write(&current->mm->mmap_sem);
7121 + if (current->mm->call_dl_resolve) {
7122 + call_dl_resolve = current->mm->call_dl_resolve;
7123 + up_write(&current->mm->mmap_sem);
7124 + if (vma)
7125 + kmem_cache_free(vm_area_cachep, vma);
7126 + goto emulate;
7127 + }
7128 +
7129 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7130 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7131 + up_write(&current->mm->mmap_sem);
7132 + if (vma)
7133 + kmem_cache_free(vm_area_cachep, vma);
7134 + return 1;
7135 + }
7136 +
7137 + if (pax_insert_vma(vma, call_dl_resolve)) {
7138 + up_write(&current->mm->mmap_sem);
7139 + kmem_cache_free(vm_area_cachep, vma);
7140 + return 1;
7141 + }
7142 +
7143 + current->mm->call_dl_resolve = call_dl_resolve;
7144 + up_write(&current->mm->mmap_sem);
7145 +
7146 +emulate:
7147 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7148 + regs->tpc = call_dl_resolve;
7149 + regs->tnpc = addr+4;
7150 + return 3;
7151 + }
7152 +#endif
7153 +
7154 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7155 + if ((save & 0xFFC00000U) == 0x05000000U &&
7156 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7157 + nop == 0x01000000U)
7158 + {
7159 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7160 + regs->u_regs[UREG_G2] = addr + 4;
7161 + addr = (save & 0x003FFFFFU) << 10;
7162 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7163 +
7164 + if (test_thread_flag(TIF_32BIT))
7165 + addr &= 0xFFFFFFFFUL;
7166 +
7167 + regs->tpc = addr;
7168 + regs->tnpc = addr+4;
7169 + return 3;
7170 + }
7171 +
7172 + /* PaX: 64-bit PLT stub */
7173 + err = get_user(sethi1, (unsigned int *)addr);
7174 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7175 + err |= get_user(or1, (unsigned int *)(addr+8));
7176 + err |= get_user(or2, (unsigned int *)(addr+12));
7177 + err |= get_user(sllx, (unsigned int *)(addr+16));
7178 + err |= get_user(add, (unsigned int *)(addr+20));
7179 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7180 + err |= get_user(nop, (unsigned int *)(addr+28));
7181 + if (err)
7182 + break;
7183 +
7184 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7185 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7186 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7187 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7188 + sllx == 0x89293020U &&
7189 + add == 0x8A010005U &&
7190 + jmpl == 0x89C14000U &&
7191 + nop == 0x01000000U)
7192 + {
7193 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7194 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7195 + regs->u_regs[UREG_G4] <<= 32;
7196 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7197 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7198 + regs->u_regs[UREG_G4] = addr + 24;
7199 + addr = regs->u_regs[UREG_G5];
7200 + regs->tpc = addr;
7201 + regs->tnpc = addr+4;
7202 + return 3;
7203 + }
7204 + }
7205 + } while (0);
7206 +
7207 +#ifdef CONFIG_PAX_DLRESOLVE
7208 + do { /* PaX: unpatched PLT emulation step 2 */
7209 + unsigned int save, call, nop;
7210 +
7211 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7212 + err |= get_user(call, (unsigned int *)regs->tpc);
7213 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7214 + if (err)
7215 + break;
7216 +
7217 + if (save == 0x9DE3BFA8U &&
7218 + (call & 0xC0000000U) == 0x40000000U &&
7219 + nop == 0x01000000U)
7220 + {
7221 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7222 +
7223 + if (test_thread_flag(TIF_32BIT))
7224 + dl_resolve &= 0xFFFFFFFFUL;
7225 +
7226 + regs->u_regs[UREG_RETPC] = regs->tpc;
7227 + regs->tpc = dl_resolve;
7228 + regs->tnpc = dl_resolve+4;
7229 + return 3;
7230 + }
7231 + } while (0);
7232 +#endif
7233 +
7234 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7235 + unsigned int sethi, ba, nop;
7236 +
7237 + err = get_user(sethi, (unsigned int *)regs->tpc);
7238 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7239 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7240 +
7241 + if (err)
7242 + break;
7243 +
7244 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7245 + (ba & 0xFFF00000U) == 0x30600000U &&
7246 + nop == 0x01000000U)
7247 + {
7248 + unsigned long addr;
7249 +
7250 + addr = (sethi & 0x003FFFFFU) << 10;
7251 + regs->u_regs[UREG_G1] = addr;
7252 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7253 +
7254 + if (test_thread_flag(TIF_32BIT))
7255 + addr &= 0xFFFFFFFFUL;
7256 +
7257 + regs->tpc = addr;
7258 + regs->tnpc = addr+4;
7259 + return 2;
7260 + }
7261 + } while (0);
7262 +
7263 +#endif
7264 +
7265 + return 1;
7266 +}
7267 +
7268 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7269 +{
7270 + unsigned long i;
7271 +
7272 + printk(KERN_ERR "PAX: bytes at PC: ");
7273 + for (i = 0; i < 8; i++) {
7274 + unsigned int c;
7275 + if (get_user(c, (unsigned int *)pc+i))
7276 + printk(KERN_CONT "???????? ");
7277 + else
7278 + printk(KERN_CONT "%08x ", c);
7279 + }
7280 + printk("\n");
7281 +}
7282 +#endif
7283 +
7284 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7285 {
7286 struct mm_struct *mm = current->mm;
7287 @@ -343,6 +806,29 @@ retry:
7288 if (!vma)
7289 goto bad_area;
7290
7291 +#ifdef CONFIG_PAX_PAGEEXEC
7292 + /* PaX: detect ITLB misses on non-exec pages */
7293 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7294 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7295 + {
7296 + if (address != regs->tpc)
7297 + goto good_area;
7298 +
7299 + up_read(&mm->mmap_sem);
7300 + switch (pax_handle_fetch_fault(regs)) {
7301 +
7302 +#ifdef CONFIG_PAX_EMUPLT
7303 + case 2:
7304 + case 3:
7305 + return;
7306 +#endif
7307 +
7308 + }
7309 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7310 + do_group_exit(SIGKILL);
7311 + }
7312 +#endif
7313 +
7314 /* Pure DTLB misses do not tell us whether the fault causing
7315 * load/store/atomic was a write or not, it only says that there
7316 * was no match. So in such a case we (carefully) read the
7317 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7318 index 07e1453..0a7d9e9 100644
7319 --- a/arch/sparc/mm/hugetlbpage.c
7320 +++ b/arch/sparc/mm/hugetlbpage.c
7321 @@ -67,7 +67,7 @@ full_search:
7322 }
7323 return -ENOMEM;
7324 }
7325 - if (likely(!vma || addr + len <= vma->vm_start)) {
7326 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7327 /*
7328 * Remember the place where we stopped the search:
7329 */
7330 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7331 /* make sure it can fit in the remaining address space */
7332 if (likely(addr > len)) {
7333 vma = find_vma(mm, addr-len);
7334 - if (!vma || addr <= vma->vm_start) {
7335 + if (check_heap_stack_gap(vma, addr - len, len)) {
7336 /* remember the address as a hint for next time */
7337 return (mm->free_area_cache = addr-len);
7338 }
7339 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7340 if (unlikely(mm->mmap_base < len))
7341 goto bottomup;
7342
7343 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7344 + addr = mm->mmap_base - len;
7345
7346 do {
7347 + addr &= HPAGE_MASK;
7348 /*
7349 * Lookup failure means no vma is above this address,
7350 * else if new region fits below vma->vm_start,
7351 * return with success:
7352 */
7353 vma = find_vma(mm, addr);
7354 - if (likely(!vma || addr+len <= vma->vm_start)) {
7355 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7356 /* remember the address as a hint for next time */
7357 return (mm->free_area_cache = addr);
7358 }
7359 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7360 mm->cached_hole_size = vma->vm_start - addr;
7361
7362 /* try just below the current vma->vm_start */
7363 - addr = (vma->vm_start-len) & HPAGE_MASK;
7364 - } while (likely(len < vma->vm_start));
7365 + addr = skip_heap_stack_gap(vma, len);
7366 + } while (!IS_ERR_VALUE(addr));
7367
7368 bottomup:
7369 /*
7370 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7371 if (addr) {
7372 addr = ALIGN(addr, HPAGE_SIZE);
7373 vma = find_vma(mm, addr);
7374 - if (task_size - len >= addr &&
7375 - (!vma || addr + len <= vma->vm_start))
7376 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7377 return addr;
7378 }
7379 if (mm->get_unmapped_area == arch_get_unmapped_area)
7380 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7381 index f4500c6..889656c 100644
7382 --- a/arch/tile/include/asm/atomic_64.h
7383 +++ b/arch/tile/include/asm/atomic_64.h
7384 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7385
7386 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7387
7388 +#define atomic64_read_unchecked(v) atomic64_read(v)
7389 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7390 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7391 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7392 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7393 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7394 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7395 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7396 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7397 +
7398 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7399 #define smp_mb__before_atomic_dec() smp_mb()
7400 #define smp_mb__after_atomic_dec() smp_mb()
7401 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7402 index 392e533..536b092 100644
7403 --- a/arch/tile/include/asm/cache.h
7404 +++ b/arch/tile/include/asm/cache.h
7405 @@ -15,11 +15,12 @@
7406 #ifndef _ASM_TILE_CACHE_H
7407 #define _ASM_TILE_CACHE_H
7408
7409 +#include <linux/const.h>
7410 #include <arch/chip.h>
7411
7412 /* bytes per L1 data cache line */
7413 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7414 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7415 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7416
7417 /* bytes per L2 cache line */
7418 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7419 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7420 index 9ab078a..d6635c2 100644
7421 --- a/arch/tile/include/asm/uaccess.h
7422 +++ b/arch/tile/include/asm/uaccess.h
7423 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7424 const void __user *from,
7425 unsigned long n)
7426 {
7427 - int sz = __compiletime_object_size(to);
7428 + size_t sz = __compiletime_object_size(to);
7429
7430 - if (likely(sz == -1 || sz >= n))
7431 + if (likely(sz == (size_t)-1 || sz >= n))
7432 n = _copy_from_user(to, from, n);
7433 else
7434 copy_from_user_overflow();
7435 diff --git a/arch/um/Makefile b/arch/um/Makefile
7436 index 0970910..13adb57a 100644
7437 --- a/arch/um/Makefile
7438 +++ b/arch/um/Makefile
7439 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7440 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7441 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7442
7443 +ifdef CONSTIFY_PLUGIN
7444 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7445 +endif
7446 +
7447 #This will adjust *FLAGS accordingly to the platform.
7448 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7449
7450 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7451 index 19e1bdd..3665b77 100644
7452 --- a/arch/um/include/asm/cache.h
7453 +++ b/arch/um/include/asm/cache.h
7454 @@ -1,6 +1,7 @@
7455 #ifndef __UM_CACHE_H
7456 #define __UM_CACHE_H
7457
7458 +#include <linux/const.h>
7459
7460 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7461 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7462 @@ -12,6 +13,6 @@
7463 # define L1_CACHE_SHIFT 5
7464 #endif
7465
7466 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7467 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7468
7469 #endif
7470 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7471 index 6c03acd..a5e0215 100644
7472 --- a/arch/um/include/asm/kmap_types.h
7473 +++ b/arch/um/include/asm/kmap_types.h
7474 @@ -23,6 +23,7 @@ enum km_type {
7475 KM_IRQ1,
7476 KM_SOFTIRQ0,
7477 KM_SOFTIRQ1,
7478 + KM_CLEARPAGE,
7479 KM_TYPE_NR
7480 };
7481
7482 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7483 index 7cfc3ce..cbd1a58 100644
7484 --- a/arch/um/include/asm/page.h
7485 +++ b/arch/um/include/asm/page.h
7486 @@ -14,6 +14,9 @@
7487 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7488 #define PAGE_MASK (~(PAGE_SIZE-1))
7489
7490 +#define ktla_ktva(addr) (addr)
7491 +#define ktva_ktla(addr) (addr)
7492 +
7493 #ifndef __ASSEMBLY__
7494
7495 struct page;
7496 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7497 index 0032f92..cd151e0 100644
7498 --- a/arch/um/include/asm/pgtable-3level.h
7499 +++ b/arch/um/include/asm/pgtable-3level.h
7500 @@ -58,6 +58,7 @@
7501 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7502 #define pud_populate(mm, pud, pmd) \
7503 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7504 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7505
7506 #ifdef CONFIG_64BIT
7507 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7508 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7509 index ccb9a9d..cc425bb 100644
7510 --- a/arch/um/kernel/process.c
7511 +++ b/arch/um/kernel/process.c
7512 @@ -407,22 +407,6 @@ int singlestepping(void * t)
7513 return 2;
7514 }
7515
7516 -/*
7517 - * Only x86 and x86_64 have an arch_align_stack().
7518 - * All other arches have "#define arch_align_stack(x) (x)"
7519 - * in their asm/system.h
7520 - * As this is included in UML from asm-um/system-generic.h,
7521 - * we can use it to behave as the subarch does.
7522 - */
7523 -#ifndef arch_align_stack
7524 -unsigned long arch_align_stack(unsigned long sp)
7525 -{
7526 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7527 - sp -= get_random_int() % 8192;
7528 - return sp & ~0xf;
7529 -}
7530 -#endif
7531 -
7532 unsigned long get_wchan(struct task_struct *p)
7533 {
7534 unsigned long stack_page, sp, ip;
7535 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7536 index ad8f795..2c7eec6 100644
7537 --- a/arch/unicore32/include/asm/cache.h
7538 +++ b/arch/unicore32/include/asm/cache.h
7539 @@ -12,8 +12,10 @@
7540 #ifndef __UNICORE_CACHE_H__
7541 #define __UNICORE_CACHE_H__
7542
7543 -#define L1_CACHE_SHIFT (5)
7544 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7545 +#include <linux/const.h>
7546 +
7547 +#define L1_CACHE_SHIFT 5
7548 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7549
7550 /*
7551 * Memory returned by kmalloc() may be used for DMA, so we must make
7552 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7553 index c70684f..698fa4b 100644
7554 --- a/arch/x86/Kconfig
7555 +++ b/arch/x86/Kconfig
7556 @@ -218,7 +218,7 @@ config X86_HT
7557
7558 config X86_32_LAZY_GS
7559 def_bool y
7560 - depends on X86_32 && !CC_STACKPROTECTOR
7561 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7562
7563 config ARCH_HWEIGHT_CFLAGS
7564 string
7565 @@ -1047,7 +1047,7 @@ choice
7566
7567 config NOHIGHMEM
7568 bool "off"
7569 - depends on !X86_NUMAQ
7570 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7571 ---help---
7572 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7573 However, the address space of 32-bit x86 processors is only 4
7574 @@ -1084,7 +1084,7 @@ config NOHIGHMEM
7575
7576 config HIGHMEM4G
7577 bool "4GB"
7578 - depends on !X86_NUMAQ
7579 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7580 ---help---
7581 Select this if you have a 32-bit processor and between 1 and 4
7582 gigabytes of physical RAM.
7583 @@ -1138,7 +1138,7 @@ config PAGE_OFFSET
7584 hex
7585 default 0xB0000000 if VMSPLIT_3G_OPT
7586 default 0x80000000 if VMSPLIT_2G
7587 - default 0x78000000 if VMSPLIT_2G_OPT
7588 + default 0x70000000 if VMSPLIT_2G_OPT
7589 default 0x40000000 if VMSPLIT_1G
7590 default 0xC0000000
7591 depends on X86_32
7592 @@ -1526,6 +1526,7 @@ config SECCOMP
7593
7594 config CC_STACKPROTECTOR
7595 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7596 + depends on X86_64 || !PAX_MEMORY_UDEREF
7597 ---help---
7598 This option turns on the -fstack-protector GCC feature. This
7599 feature puts, at the beginning of functions, a canary value on
7600 @@ -1583,6 +1584,7 @@ config KEXEC_JUMP
7601 config PHYSICAL_START
7602 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7603 default "0x1000000"
7604 + range 0x400000 0x40000000
7605 ---help---
7606 This gives the physical address where the kernel is loaded.
7607
7608 @@ -1646,6 +1648,7 @@ config X86_NEED_RELOCS
7609 config PHYSICAL_ALIGN
7610 hex "Alignment value to which kernel should be aligned" if X86_32
7611 default "0x1000000"
7612 + range 0x400000 0x1000000 if PAX_KERNEXEC
7613 range 0x2000 0x1000000
7614 ---help---
7615 This value puts the alignment restrictions on physical address
7616 @@ -1677,9 +1680,10 @@ config HOTPLUG_CPU
7617 Say N if you want to disable CPU hotplug.
7618
7619 config COMPAT_VDSO
7620 - def_bool y
7621 + def_bool n
7622 prompt "Compat VDSO support"
7623 depends on X86_32 || IA32_EMULATION
7624 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7625 ---help---
7626 Map the 32-bit VDSO to the predictable old-style address too.
7627
7628 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7629 index 706e12e..62e4feb 100644
7630 --- a/arch/x86/Kconfig.cpu
7631 +++ b/arch/x86/Kconfig.cpu
7632 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7633
7634 config X86_F00F_BUG
7635 def_bool y
7636 - depends on M586MMX || M586TSC || M586 || M486 || M386
7637 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7638
7639 config X86_INVD_BUG
7640 def_bool y
7641 @@ -358,7 +358,7 @@ config X86_POPAD_OK
7642
7643 config X86_ALIGNMENT_16
7644 def_bool y
7645 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7646 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7647
7648 config X86_INTEL_USERCOPY
7649 def_bool y
7650 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
7651 # generates cmov.
7652 config X86_CMOV
7653 def_bool y
7654 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7655 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7656
7657 config X86_MINIMUM_CPU_FAMILY
7658 int
7659 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7660 index e46c214..ab62fd1 100644
7661 --- a/arch/x86/Kconfig.debug
7662 +++ b/arch/x86/Kconfig.debug
7663 @@ -84,7 +84,7 @@ config X86_PTDUMP
7664 config DEBUG_RODATA
7665 bool "Write protect kernel read-only data structures"
7666 default y
7667 - depends on DEBUG_KERNEL
7668 + depends on DEBUG_KERNEL && BROKEN
7669 ---help---
7670 Mark the kernel read-only data as write-protected in the pagetables,
7671 in order to catch accidental (and incorrect) writes to such const
7672 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7673
7674 config DEBUG_SET_MODULE_RONX
7675 bool "Set loadable kernel module data as NX and text as RO"
7676 - depends on MODULES
7677 + depends on MODULES && BROKEN
7678 ---help---
7679 This option helps catch unintended modifications to loadable
7680 kernel module's text and read-only data. It also prevents execution
7681 @@ -275,7 +275,7 @@ config OPTIMIZE_INLINING
7682
7683 config DEBUG_STRICT_USER_COPY_CHECKS
7684 bool "Strict copy size checks"
7685 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7686 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7687 ---help---
7688 Enabling this option turns a certain set of sanity checks for user
7689 copy operations into compile time failures.
7690 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7691 index 1f25214..39422b3 100644
7692 --- a/arch/x86/Makefile
7693 +++ b/arch/x86/Makefile
7694 @@ -46,6 +46,7 @@ else
7695 UTS_MACHINE := x86_64
7696 CHECKFLAGS += -D__x86_64__ -m64
7697
7698 + biarch := $(call cc-option,-m64)
7699 KBUILD_AFLAGS += -m64
7700 KBUILD_CFLAGS += -m64
7701
7702 @@ -222,3 +223,12 @@ define archhelp
7703 echo ' FDARGS="..." arguments for the booted kernel'
7704 echo ' FDINITRD=file initrd for the booted kernel'
7705 endef
7706 +
7707 +define OLD_LD
7708 +
7709 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7710 +*** Please upgrade your binutils to 2.18 or newer
7711 +endef
7712 +
7713 +archprepare:
7714 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7715 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7716 index 5a747dd..ff7b12c 100644
7717 --- a/arch/x86/boot/Makefile
7718 +++ b/arch/x86/boot/Makefile
7719 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7720 $(call cc-option, -fno-stack-protector) \
7721 $(call cc-option, -mpreferred-stack-boundary=2)
7722 KBUILD_CFLAGS += $(call cc-option, -m32)
7723 +ifdef CONSTIFY_PLUGIN
7724 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7725 +endif
7726 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7727 GCOV_PROFILE := n
7728
7729 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7730 index 878e4b9..20537ab 100644
7731 --- a/arch/x86/boot/bitops.h
7732 +++ b/arch/x86/boot/bitops.h
7733 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7734 u8 v;
7735 const u32 *p = (const u32 *)addr;
7736
7737 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7738 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7739 return v;
7740 }
7741
7742 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7743
7744 static inline void set_bit(int nr, void *addr)
7745 {
7746 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7747 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7748 }
7749
7750 #endif /* BOOT_BITOPS_H */
7751 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7752 index 18997e5..83d9c67 100644
7753 --- a/arch/x86/boot/boot.h
7754 +++ b/arch/x86/boot/boot.h
7755 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7756 static inline u16 ds(void)
7757 {
7758 u16 seg;
7759 - asm("movw %%ds,%0" : "=rm" (seg));
7760 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7761 return seg;
7762 }
7763
7764 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7765 static inline int memcmp(const void *s1, const void *s2, size_t len)
7766 {
7767 u8 diff;
7768 - asm("repe; cmpsb; setnz %0"
7769 + asm volatile("repe; cmpsb; setnz %0"
7770 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7771 return diff;
7772 }
7773 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7774 index e398bb5..3a382ca 100644
7775 --- a/arch/x86/boot/compressed/Makefile
7776 +++ b/arch/x86/boot/compressed/Makefile
7777 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7778 KBUILD_CFLAGS += $(cflags-y)
7779 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7780 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7781 +ifdef CONSTIFY_PLUGIN
7782 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7783 +endif
7784
7785 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7786 GCOV_PROFILE := n
7787 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7788 index 4e85f5f..39fa641 100644
7789 --- a/arch/x86/boot/compressed/eboot.c
7790 +++ b/arch/x86/boot/compressed/eboot.c
7791 @@ -142,7 +142,6 @@ again:
7792 *addr = max_addr;
7793 }
7794
7795 -free_pool:
7796 efi_call_phys1(sys_table->boottime->free_pool, map);
7797
7798 fail:
7799 @@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7800 if (i == map_size / desc_size)
7801 status = EFI_NOT_FOUND;
7802
7803 -free_pool:
7804 efi_call_phys1(sys_table->boottime->free_pool, map);
7805 fail:
7806 return status;
7807 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7808 index c85e3ac..6f5aa80 100644
7809 --- a/arch/x86/boot/compressed/head_32.S
7810 +++ b/arch/x86/boot/compressed/head_32.S
7811 @@ -106,7 +106,7 @@ preferred_addr:
7812 notl %eax
7813 andl %eax, %ebx
7814 #else
7815 - movl $LOAD_PHYSICAL_ADDR, %ebx
7816 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7817 #endif
7818
7819 /* Target address to relocate to for decompression */
7820 @@ -192,7 +192,7 @@ relocated:
7821 * and where it was actually loaded.
7822 */
7823 movl %ebp, %ebx
7824 - subl $LOAD_PHYSICAL_ADDR, %ebx
7825 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7826 jz 2f /* Nothing to be done if loaded at compiled addr. */
7827 /*
7828 * Process relocations.
7829 @@ -200,8 +200,7 @@ relocated:
7830
7831 1: subl $4, %edi
7832 movl (%edi), %ecx
7833 - testl %ecx, %ecx
7834 - jz 2f
7835 + jecxz 2f
7836 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7837 jmp 1b
7838 2:
7839 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7840 index 87e03a1..0d94c76 100644
7841 --- a/arch/x86/boot/compressed/head_64.S
7842 +++ b/arch/x86/boot/compressed/head_64.S
7843 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7844 notl %eax
7845 andl %eax, %ebx
7846 #else
7847 - movl $LOAD_PHYSICAL_ADDR, %ebx
7848 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7849 #endif
7850
7851 /* Target address to relocate to for decompression */
7852 @@ -263,7 +263,7 @@ preferred_addr:
7853 notq %rax
7854 andq %rax, %rbp
7855 #else
7856 - movq $LOAD_PHYSICAL_ADDR, %rbp
7857 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7858 #endif
7859
7860 /* Target address to relocate to for decompression */
7861 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7862 index 7116dcb..d9ae1d7 100644
7863 --- a/arch/x86/boot/compressed/misc.c
7864 +++ b/arch/x86/boot/compressed/misc.c
7865 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7866 case PT_LOAD:
7867 #ifdef CONFIG_RELOCATABLE
7868 dest = output;
7869 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7870 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7871 #else
7872 dest = (void *)(phdr->p_paddr);
7873 #endif
7874 @@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7875 error("Destination address too large");
7876 #endif
7877 #ifndef CONFIG_RELOCATABLE
7878 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7879 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7880 error("Wrong destination address");
7881 #endif
7882
7883 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7884 index 4d3ff03..e4972ff 100644
7885 --- a/arch/x86/boot/cpucheck.c
7886 +++ b/arch/x86/boot/cpucheck.c
7887 @@ -74,7 +74,7 @@ static int has_fpu(void)
7888 u16 fcw = -1, fsw = -1;
7889 u32 cr0;
7890
7891 - asm("movl %%cr0,%0" : "=r" (cr0));
7892 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7893 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7894 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7895 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7896 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7897 {
7898 u32 f0, f1;
7899
7900 - asm("pushfl ; "
7901 + asm volatile("pushfl ; "
7902 "pushfl ; "
7903 "popl %0 ; "
7904 "movl %0,%1 ; "
7905 @@ -115,7 +115,7 @@ static void get_flags(void)
7906 set_bit(X86_FEATURE_FPU, cpu.flags);
7907
7908 if (has_eflag(X86_EFLAGS_ID)) {
7909 - asm("cpuid"
7910 + asm volatile("cpuid"
7911 : "=a" (max_intel_level),
7912 "=b" (cpu_vendor[0]),
7913 "=d" (cpu_vendor[1]),
7914 @@ -124,7 +124,7 @@ static void get_flags(void)
7915
7916 if (max_intel_level >= 0x00000001 &&
7917 max_intel_level <= 0x0000ffff) {
7918 - asm("cpuid"
7919 + asm volatile("cpuid"
7920 : "=a" (tfms),
7921 "=c" (cpu.flags[4]),
7922 "=d" (cpu.flags[0])
7923 @@ -136,7 +136,7 @@ static void get_flags(void)
7924 cpu.model += ((tfms >> 16) & 0xf) << 4;
7925 }
7926
7927 - asm("cpuid"
7928 + asm volatile("cpuid"
7929 : "=a" (max_amd_level)
7930 : "a" (0x80000000)
7931 : "ebx", "ecx", "edx");
7932 @@ -144,7 +144,7 @@ static void get_flags(void)
7933 if (max_amd_level >= 0x80000001 &&
7934 max_amd_level <= 0x8000ffff) {
7935 u32 eax = 0x80000001;
7936 - asm("cpuid"
7937 + asm volatile("cpuid"
7938 : "+a" (eax),
7939 "=c" (cpu.flags[6]),
7940 "=d" (cpu.flags[1])
7941 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7942 u32 ecx = MSR_K7_HWCR;
7943 u32 eax, edx;
7944
7945 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7946 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7947 eax &= ~(1 << 15);
7948 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7949 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7950
7951 get_flags(); /* Make sure it really did something */
7952 err = check_flags();
7953 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7954 u32 ecx = MSR_VIA_FCR;
7955 u32 eax, edx;
7956
7957 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7958 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7959 eax |= (1<<1)|(1<<7);
7960 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7961 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7962
7963 set_bit(X86_FEATURE_CX8, cpu.flags);
7964 err = check_flags();
7965 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7966 u32 eax, edx;
7967 u32 level = 1;
7968
7969 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7970 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7971 - asm("cpuid"
7972 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7973 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7974 + asm volatile("cpuid"
7975 : "+a" (level), "=d" (cpu.flags[0])
7976 : : "ecx", "ebx");
7977 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7978 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7979
7980 err = check_flags();
7981 }
7982 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7983 index efe5acf..22a3784 100644
7984 --- a/arch/x86/boot/header.S
7985 +++ b/arch/x86/boot/header.S
7986 @@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
7987 # single linked list of
7988 # struct setup_data
7989
7990 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7991 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7992
7993 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7994 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
7995 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
7996 +#else
7997 #define VO_INIT_SIZE (VO__end - VO__text)
7998 +#endif
7999 #if ZO_INIT_SIZE > VO_INIT_SIZE
8000 #define INIT_SIZE ZO_INIT_SIZE
8001 #else
8002 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8003 index db75d07..8e6d0af 100644
8004 --- a/arch/x86/boot/memory.c
8005 +++ b/arch/x86/boot/memory.c
8006 @@ -19,7 +19,7 @@
8007
8008 static int detect_memory_e820(void)
8009 {
8010 - int count = 0;
8011 + unsigned int count = 0;
8012 struct biosregs ireg, oreg;
8013 struct e820entry *desc = boot_params.e820_map;
8014 static struct e820entry buf; /* static so it is zeroed */
8015 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8016 index 11e8c6e..fdbb1ed 100644
8017 --- a/arch/x86/boot/video-vesa.c
8018 +++ b/arch/x86/boot/video-vesa.c
8019 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8020
8021 boot_params.screen_info.vesapm_seg = oreg.es;
8022 boot_params.screen_info.vesapm_off = oreg.di;
8023 + boot_params.screen_info.vesapm_size = oreg.cx;
8024 }
8025
8026 /*
8027 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8028 index 43eda28..5ab5fdb 100644
8029 --- a/arch/x86/boot/video.c
8030 +++ b/arch/x86/boot/video.c
8031 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8032 static unsigned int get_entry(void)
8033 {
8034 char entry_buf[4];
8035 - int i, len = 0;
8036 + unsigned int i, len = 0;
8037 int key;
8038 unsigned int v;
8039
8040 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8041 index 5b577d5..3c1fed4 100644
8042 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8043 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8044 @@ -8,6 +8,8 @@
8045 * including this sentence is retained in full.
8046 */
8047
8048 +#include <asm/alternative-asm.h>
8049 +
8050 .extern crypto_ft_tab
8051 .extern crypto_it_tab
8052 .extern crypto_fl_tab
8053 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8054 je B192; \
8055 leaq 32(r9),r9;
8056
8057 +#define ret pax_force_retaddr 0, 1; ret
8058 +
8059 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8060 movq r1,r2; \
8061 movq r3,r4; \
8062 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8063 index 3470624..201259d 100644
8064 --- a/arch/x86/crypto/aesni-intel_asm.S
8065 +++ b/arch/x86/crypto/aesni-intel_asm.S
8066 @@ -31,6 +31,7 @@
8067
8068 #include <linux/linkage.h>
8069 #include <asm/inst.h>
8070 +#include <asm/alternative-asm.h>
8071
8072 #ifdef __x86_64__
8073 .data
8074 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8075 pop %r14
8076 pop %r13
8077 pop %r12
8078 + pax_force_retaddr 0, 1
8079 ret
8080 +ENDPROC(aesni_gcm_dec)
8081
8082
8083 /*****************************************************************************
8084 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8085 pop %r14
8086 pop %r13
8087 pop %r12
8088 + pax_force_retaddr 0, 1
8089 ret
8090 +ENDPROC(aesni_gcm_enc)
8091
8092 #endif
8093
8094 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8095 pxor %xmm1, %xmm0
8096 movaps %xmm0, (TKEYP)
8097 add $0x10, TKEYP
8098 + pax_force_retaddr_bts
8099 ret
8100
8101 .align 4
8102 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8103 shufps $0b01001110, %xmm2, %xmm1
8104 movaps %xmm1, 0x10(TKEYP)
8105 add $0x20, TKEYP
8106 + pax_force_retaddr_bts
8107 ret
8108
8109 .align 4
8110 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8111
8112 movaps %xmm0, (TKEYP)
8113 add $0x10, TKEYP
8114 + pax_force_retaddr_bts
8115 ret
8116
8117 .align 4
8118 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8119 pxor %xmm1, %xmm2
8120 movaps %xmm2, (TKEYP)
8121 add $0x10, TKEYP
8122 + pax_force_retaddr_bts
8123 ret
8124
8125 /*
8126 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8127 #ifndef __x86_64__
8128 popl KEYP
8129 #endif
8130 + pax_force_retaddr 0, 1
8131 ret
8132 +ENDPROC(aesni_set_key)
8133
8134 /*
8135 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8136 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8137 popl KLEN
8138 popl KEYP
8139 #endif
8140 + pax_force_retaddr 0, 1
8141 ret
8142 +ENDPROC(aesni_enc)
8143
8144 /*
8145 * _aesni_enc1: internal ABI
8146 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8147 AESENC KEY STATE
8148 movaps 0x70(TKEYP), KEY
8149 AESENCLAST KEY STATE
8150 + pax_force_retaddr_bts
8151 ret
8152
8153 /*
8154 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8155 AESENCLAST KEY STATE2
8156 AESENCLAST KEY STATE3
8157 AESENCLAST KEY STATE4
8158 + pax_force_retaddr_bts
8159 ret
8160
8161 /*
8162 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8163 popl KLEN
8164 popl KEYP
8165 #endif
8166 + pax_force_retaddr 0, 1
8167 ret
8168 +ENDPROC(aesni_dec)
8169
8170 /*
8171 * _aesni_dec1: internal ABI
8172 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8173 AESDEC KEY STATE
8174 movaps 0x70(TKEYP), KEY
8175 AESDECLAST KEY STATE
8176 + pax_force_retaddr_bts
8177 ret
8178
8179 /*
8180 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8181 AESDECLAST KEY STATE2
8182 AESDECLAST KEY STATE3
8183 AESDECLAST KEY STATE4
8184 + pax_force_retaddr_bts
8185 ret
8186
8187 /*
8188 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8189 popl KEYP
8190 popl LEN
8191 #endif
8192 + pax_force_retaddr 0, 1
8193 ret
8194 +ENDPROC(aesni_ecb_enc)
8195
8196 /*
8197 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8198 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8199 popl KEYP
8200 popl LEN
8201 #endif
8202 + pax_force_retaddr 0, 1
8203 ret
8204 +ENDPROC(aesni_ecb_dec)
8205
8206 /*
8207 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8208 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8209 popl LEN
8210 popl IVP
8211 #endif
8212 + pax_force_retaddr 0, 1
8213 ret
8214 +ENDPROC(aesni_cbc_enc)
8215
8216 /*
8217 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8218 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8219 popl LEN
8220 popl IVP
8221 #endif
8222 + pax_force_retaddr 0, 1
8223 ret
8224 +ENDPROC(aesni_cbc_dec)
8225
8226 #ifdef __x86_64__
8227 .align 16
8228 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8229 mov $1, TCTR_LOW
8230 MOVQ_R64_XMM TCTR_LOW INC
8231 MOVQ_R64_XMM CTR TCTR_LOW
8232 + pax_force_retaddr_bts
8233 ret
8234
8235 /*
8236 @@ -2554,6 +2582,7 @@ _aesni_inc:
8237 .Linc_low:
8238 movaps CTR, IV
8239 PSHUFB_XMM BSWAP_MASK IV
8240 + pax_force_retaddr_bts
8241 ret
8242
8243 /*
8244 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8245 .Lctr_enc_ret:
8246 movups IV, (IVP)
8247 .Lctr_enc_just_ret:
8248 + pax_force_retaddr 0, 1
8249 ret
8250 +ENDPROC(aesni_ctr_enc)
8251 #endif
8252 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8253 index 391d245..67f35c2 100644
8254 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8255 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8256 @@ -20,6 +20,8 @@
8257 *
8258 */
8259
8260 +#include <asm/alternative-asm.h>
8261 +
8262 .file "blowfish-x86_64-asm.S"
8263 .text
8264
8265 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8266 jnz __enc_xor;
8267
8268 write_block();
8269 + pax_force_retaddr 0, 1
8270 ret;
8271 __enc_xor:
8272 xor_block();
8273 + pax_force_retaddr 0, 1
8274 ret;
8275
8276 .align 8
8277 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8278
8279 movq %r11, %rbp;
8280
8281 + pax_force_retaddr 0, 1
8282 ret;
8283
8284 /**********************************************************************
8285 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8286
8287 popq %rbx;
8288 popq %rbp;
8289 + pax_force_retaddr 0, 1
8290 ret;
8291
8292 __enc_xor4:
8293 @@ -349,6 +355,7 @@ __enc_xor4:
8294
8295 popq %rbx;
8296 popq %rbp;
8297 + pax_force_retaddr 0, 1
8298 ret;
8299
8300 .align 8
8301 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8302 popq %rbx;
8303 popq %rbp;
8304
8305 + pax_force_retaddr 0, 1
8306 ret;
8307
8308 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8309 index 0b33743..7a56206 100644
8310 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8311 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8312 @@ -20,6 +20,8 @@
8313 *
8314 */
8315
8316 +#include <asm/alternative-asm.h>
8317 +
8318 .file "camellia-x86_64-asm_64.S"
8319 .text
8320
8321 @@ -229,12 +231,14 @@ __enc_done:
8322 enc_outunpack(mov, RT1);
8323
8324 movq RRBP, %rbp;
8325 + pax_force_retaddr 0, 1
8326 ret;
8327
8328 __enc_xor:
8329 enc_outunpack(xor, RT1);
8330
8331 movq RRBP, %rbp;
8332 + pax_force_retaddr 0, 1
8333 ret;
8334
8335 .global camellia_dec_blk;
8336 @@ -275,6 +279,7 @@ __dec_rounds16:
8337 dec_outunpack();
8338
8339 movq RRBP, %rbp;
8340 + pax_force_retaddr 0, 1
8341 ret;
8342
8343 /**********************************************************************
8344 @@ -468,6 +473,7 @@ __enc2_done:
8345
8346 movq RRBP, %rbp;
8347 popq %rbx;
8348 + pax_force_retaddr 0, 1
8349 ret;
8350
8351 __enc2_xor:
8352 @@ -475,6 +481,7 @@ __enc2_xor:
8353
8354 movq RRBP, %rbp;
8355 popq %rbx;
8356 + pax_force_retaddr 0, 1
8357 ret;
8358
8359 .global camellia_dec_blk_2way;
8360 @@ -517,4 +524,5 @@ __dec2_rounds16:
8361
8362 movq RRBP, %rbp;
8363 movq RXOR, %rbx;
8364 + pax_force_retaddr 0, 1
8365 ret;
8366 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8367 index 6214a9b..1f4fc9a 100644
8368 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8369 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8370 @@ -1,3 +1,5 @@
8371 +#include <asm/alternative-asm.h>
8372 +
8373 # enter ECRYPT_encrypt_bytes
8374 .text
8375 .p2align 5
8376 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8377 add %r11,%rsp
8378 mov %rdi,%rax
8379 mov %rsi,%rdx
8380 + pax_force_retaddr 0, 1
8381 ret
8382 # bytesatleast65:
8383 ._bytesatleast65:
8384 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8385 add %r11,%rsp
8386 mov %rdi,%rax
8387 mov %rsi,%rdx
8388 + pax_force_retaddr
8389 ret
8390 # enter ECRYPT_ivsetup
8391 .text
8392 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8393 add %r11,%rsp
8394 mov %rdi,%rax
8395 mov %rsi,%rdx
8396 + pax_force_retaddr
8397 ret
8398 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8399 index 3ee1ff0..cbc568b 100644
8400 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8401 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8402 @@ -24,6 +24,8 @@
8403 *
8404 */
8405
8406 +#include <asm/alternative-asm.h>
8407 +
8408 .file "serpent-sse2-x86_64-asm_64.S"
8409 .text
8410
8411 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8412 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8413 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8414
8415 + pax_force_retaddr
8416 ret;
8417
8418 __enc_xor8:
8419 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8420 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8421
8422 + pax_force_retaddr
8423 ret;
8424
8425 .align 8
8426 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8427 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8428 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8429
8430 + pax_force_retaddr
8431 ret;
8432 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8433 index b2c2f57..8470cab 100644
8434 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8435 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8436 @@ -28,6 +28,8 @@
8437 * (at your option) any later version.
8438 */
8439
8440 +#include <asm/alternative-asm.h>
8441 +
8442 #define CTX %rdi // arg1
8443 #define BUF %rsi // arg2
8444 #define CNT %rdx // arg3
8445 @@ -104,6 +106,7 @@
8446 pop %r12
8447 pop %rbp
8448 pop %rbx
8449 + pax_force_retaddr 0, 1
8450 ret
8451
8452 .size \name, .-\name
8453 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8454 index 5b012a2..36d5364 100644
8455 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8456 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8457 @@ -20,6 +20,8 @@
8458 *
8459 */
8460
8461 +#include <asm/alternative-asm.h>
8462 +
8463 .file "twofish-x86_64-asm-3way.S"
8464 .text
8465
8466 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8467 popq %r13;
8468 popq %r14;
8469 popq %r15;
8470 + pax_force_retaddr 0, 1
8471 ret;
8472
8473 __enc_xor3:
8474 @@ -271,6 +274,7 @@ __enc_xor3:
8475 popq %r13;
8476 popq %r14;
8477 popq %r15;
8478 + pax_force_retaddr 0, 1
8479 ret;
8480
8481 .global twofish_dec_blk_3way
8482 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8483 popq %r13;
8484 popq %r14;
8485 popq %r15;
8486 + pax_force_retaddr 0, 1
8487 ret;
8488
8489 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8490 index 7bcf3fc..f53832f 100644
8491 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8492 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8493 @@ -21,6 +21,7 @@
8494 .text
8495
8496 #include <asm/asm-offsets.h>
8497 +#include <asm/alternative-asm.h>
8498
8499 #define a_offset 0
8500 #define b_offset 4
8501 @@ -268,6 +269,7 @@ twofish_enc_blk:
8502
8503 popq R1
8504 movq $1,%rax
8505 + pax_force_retaddr 0, 1
8506 ret
8507
8508 twofish_dec_blk:
8509 @@ -319,4 +321,5 @@ twofish_dec_blk:
8510
8511 popq R1
8512 movq $1,%rax
8513 + pax_force_retaddr 0, 1
8514 ret
8515 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8516 index 07b3a68..bd2a388 100644
8517 --- a/arch/x86/ia32/ia32_aout.c
8518 +++ b/arch/x86/ia32/ia32_aout.c
8519 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8520 unsigned long dump_start, dump_size;
8521 struct user32 dump;
8522
8523 + memset(&dump, 0, sizeof(dump));
8524 +
8525 fs = get_fs();
8526 set_fs(KERNEL_DS);
8527 has_dumped = 1;
8528 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8529 index 673ac9b..7a8c5df 100644
8530 --- a/arch/x86/ia32/ia32_signal.c
8531 +++ b/arch/x86/ia32/ia32_signal.c
8532 @@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8533 }
8534 seg = get_fs();
8535 set_fs(KERNEL_DS);
8536 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8537 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8538 set_fs(seg);
8539 if (ret >= 0 && uoss_ptr) {
8540 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8541 @@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8542 */
8543 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8544 size_t frame_size,
8545 - void **fpstate)
8546 + void __user **fpstate)
8547 {
8548 unsigned long sp;
8549
8550 @@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8551
8552 if (used_math()) {
8553 sp = sp - sig_xstate_ia32_size;
8554 - *fpstate = (struct _fpstate_ia32 *) sp;
8555 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8556 if (save_i387_xstate_ia32(*fpstate) < 0)
8557 return (void __user *) -1L;
8558 }
8559 @@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8560 sp -= frame_size;
8561 /* Align the stack pointer according to the i386 ABI,
8562 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8563 - sp = ((sp + 4) & -16ul) - 4;
8564 + sp = ((sp - 12) & -16ul) - 4;
8565 return (void __user *) sp;
8566 }
8567
8568 @@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8569 * These are actually not used anymore, but left because some
8570 * gdb versions depend on them as a marker.
8571 */
8572 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8573 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8574 } put_user_catch(err);
8575
8576 if (err)
8577 @@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8578 0xb8,
8579 __NR_ia32_rt_sigreturn,
8580 0x80cd,
8581 - 0,
8582 + 0
8583 };
8584
8585 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8586 @@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8587
8588 if (ka->sa.sa_flags & SA_RESTORER)
8589 restorer = ka->sa.sa_restorer;
8590 + else if (current->mm->context.vdso)
8591 + /* Return stub is in 32bit vsyscall page */
8592 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8593 else
8594 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8595 - rt_sigreturn);
8596 + restorer = &frame->retcode;
8597 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8598
8599 /*
8600 * Not actually used anymore, but left because some gdb
8601 * versions need it.
8602 */
8603 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8604 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8605 } put_user_catch(err);
8606
8607 if (err)
8608 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8609 index 20e5f7b..eab8751 100644
8610 --- a/arch/x86/ia32/ia32entry.S
8611 +++ b/arch/x86/ia32/ia32entry.S
8612 @@ -14,8 +14,10 @@
8613 #include <asm/segment.h>
8614 #include <asm/irqflags.h>
8615 #include <asm/asm.h>
8616 +#include <asm/pgtable.h>
8617 #include <linux/linkage.h>
8618 #include <linux/err.h>
8619 +#include <asm/alternative-asm.h>
8620
8621 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8622 #include <linux/elf-em.h>
8623 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8624 ENDPROC(native_irq_enable_sysexit)
8625 #endif
8626
8627 + .macro pax_enter_kernel_user
8628 + pax_set_fptr_mask
8629 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8630 + call pax_enter_kernel_user
8631 +#endif
8632 + .endm
8633 +
8634 + .macro pax_exit_kernel_user
8635 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8636 + call pax_exit_kernel_user
8637 +#endif
8638 +#ifdef CONFIG_PAX_RANDKSTACK
8639 + pushq %rax
8640 + pushq %r11
8641 + call pax_randomize_kstack
8642 + popq %r11
8643 + popq %rax
8644 +#endif
8645 + .endm
8646 +
8647 +.macro pax_erase_kstack
8648 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8649 + call pax_erase_kstack
8650 +#endif
8651 +.endm
8652 +
8653 /*
8654 * 32bit SYSENTER instruction entry.
8655 *
8656 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8657 CFI_REGISTER rsp,rbp
8658 SWAPGS_UNSAFE_STACK
8659 movq PER_CPU_VAR(kernel_stack), %rsp
8660 - addq $(KERNEL_STACK_OFFSET),%rsp
8661 - /*
8662 - * No need to follow this irqs on/off section: the syscall
8663 - * disabled irqs, here we enable it straight after entry:
8664 - */
8665 - ENABLE_INTERRUPTS(CLBR_NONE)
8666 movl %ebp,%ebp /* zero extension */
8667 pushq_cfi $__USER32_DS
8668 /*CFI_REL_OFFSET ss,0*/
8669 @@ -134,22 +156,37 @@ ENTRY(ia32_sysenter_target)
8670 CFI_REL_OFFSET rsp,0
8671 pushfq_cfi
8672 /*CFI_REL_OFFSET rflags,0*/
8673 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8674 - CFI_REGISTER rip,r10
8675 + orl $X86_EFLAGS_IF,(%rsp)
8676 + GET_THREAD_INFO(%r11)
8677 + movl TI_sysenter_return(%r11), %r11d
8678 + CFI_REGISTER rip,r11
8679 pushq_cfi $__USER32_CS
8680 /*CFI_REL_OFFSET cs,0*/
8681 movl %eax, %eax
8682 - pushq_cfi %r10
8683 + pushq_cfi %r11
8684 CFI_REL_OFFSET rip,0
8685 pushq_cfi %rax
8686 cld
8687 SAVE_ARGS 0,1,0
8688 + pax_enter_kernel_user
8689 + /*
8690 + * No need to follow this irqs on/off section: the syscall
8691 + * disabled irqs, here we enable it straight after entry:
8692 + */
8693 + ENABLE_INTERRUPTS(CLBR_NONE)
8694 /* no need to do an access_ok check here because rbp has been
8695 32bit zero extended */
8696 +
8697 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8698 + mov $PAX_USER_SHADOW_BASE,%r11
8699 + add %r11,%rbp
8700 +#endif
8701 +
8702 1: movl (%rbp),%ebp
8703 _ASM_EXTABLE(1b,ia32_badarg)
8704 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8705 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8706 + GET_THREAD_INFO(%r11)
8707 + orl $TS_COMPAT,TI_status(%r11)
8708 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8709 CFI_REMEMBER_STATE
8710 jnz sysenter_tracesys
8711 cmpq $(IA32_NR_syscalls-1),%rax
8712 @@ -159,12 +196,15 @@ sysenter_do_call:
8713 sysenter_dispatch:
8714 call *ia32_sys_call_table(,%rax,8)
8715 movq %rax,RAX-ARGOFFSET(%rsp)
8716 + GET_THREAD_INFO(%r11)
8717 DISABLE_INTERRUPTS(CLBR_NONE)
8718 TRACE_IRQS_OFF
8719 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8720 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8721 jnz sysexit_audit
8722 sysexit_from_sys_call:
8723 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8724 + pax_exit_kernel_user
8725 + pax_erase_kstack
8726 + andl $~TS_COMPAT,TI_status(%r11)
8727 /* clear IF, that popfq doesn't enable interrupts early */
8728 andl $~0x200,EFLAGS-R11(%rsp)
8729 movl RIP-R11(%rsp),%edx /* User %eip */
8730 @@ -190,6 +230,9 @@ sysexit_from_sys_call:
8731 movl %eax,%esi /* 2nd arg: syscall number */
8732 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8733 call __audit_syscall_entry
8734 +
8735 + pax_erase_kstack
8736 +
8737 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8738 cmpq $(IA32_NR_syscalls-1),%rax
8739 ja ia32_badsys
8740 @@ -201,7 +244,7 @@ sysexit_from_sys_call:
8741 .endm
8742
8743 .macro auditsys_exit exit
8744 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8745 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8746 jnz ia32_ret_from_sys_call
8747 TRACE_IRQS_ON
8748 sti
8749 @@ -212,11 +255,12 @@ sysexit_from_sys_call:
8750 1: setbe %al /* 1 if error, 0 if not */
8751 movzbl %al,%edi /* zero-extend that into %edi */
8752 call __audit_syscall_exit
8753 + GET_THREAD_INFO(%r11)
8754 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8755 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8756 cli
8757 TRACE_IRQS_OFF
8758 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8759 + testl %edi,TI_flags(%r11)
8760 jz \exit
8761 CLEAR_RREGS -ARGOFFSET
8762 jmp int_with_check
8763 @@ -234,7 +278,7 @@ sysexit_audit:
8764
8765 sysenter_tracesys:
8766 #ifdef CONFIG_AUDITSYSCALL
8767 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8768 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8769 jz sysenter_auditsys
8770 #endif
8771 SAVE_REST
8772 @@ -242,6 +286,9 @@ sysenter_tracesys:
8773 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8774 movq %rsp,%rdi /* &pt_regs -> arg1 */
8775 call syscall_trace_enter
8776 +
8777 + pax_erase_kstack
8778 +
8779 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8780 RESTORE_REST
8781 cmpq $(IA32_NR_syscalls-1),%rax
8782 @@ -273,19 +320,20 @@ ENDPROC(ia32_sysenter_target)
8783 ENTRY(ia32_cstar_target)
8784 CFI_STARTPROC32 simple
8785 CFI_SIGNAL_FRAME
8786 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8787 + CFI_DEF_CFA rsp,0
8788 CFI_REGISTER rip,rcx
8789 /*CFI_REGISTER rflags,r11*/
8790 SWAPGS_UNSAFE_STACK
8791 movl %esp,%r8d
8792 CFI_REGISTER rsp,r8
8793 movq PER_CPU_VAR(kernel_stack),%rsp
8794 + SAVE_ARGS 8*6,0,0
8795 + pax_enter_kernel_user
8796 /*
8797 * No need to follow this irqs on/off section: the syscall
8798 * disabled irqs and here we enable it straight after entry:
8799 */
8800 ENABLE_INTERRUPTS(CLBR_NONE)
8801 - SAVE_ARGS 8,0,0
8802 movl %eax,%eax /* zero extension */
8803 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8804 movq %rcx,RIP-ARGOFFSET(%rsp)
8805 @@ -301,10 +349,17 @@ ENTRY(ia32_cstar_target)
8806 /* no need to do an access_ok check here because r8 has been
8807 32bit zero extended */
8808 /* hardware stack frame is complete now */
8809 +
8810 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8811 + mov $PAX_USER_SHADOW_BASE,%r11
8812 + add %r11,%r8
8813 +#endif
8814 +
8815 1: movl (%r8),%r9d
8816 _ASM_EXTABLE(1b,ia32_badarg)
8817 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8818 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8819 + GET_THREAD_INFO(%r11)
8820 + orl $TS_COMPAT,TI_status(%r11)
8821 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8822 CFI_REMEMBER_STATE
8823 jnz cstar_tracesys
8824 cmpq $IA32_NR_syscalls-1,%rax
8825 @@ -314,12 +369,15 @@ cstar_do_call:
8826 cstar_dispatch:
8827 call *ia32_sys_call_table(,%rax,8)
8828 movq %rax,RAX-ARGOFFSET(%rsp)
8829 + GET_THREAD_INFO(%r11)
8830 DISABLE_INTERRUPTS(CLBR_NONE)
8831 TRACE_IRQS_OFF
8832 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8833 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8834 jnz sysretl_audit
8835 sysretl_from_sys_call:
8836 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8837 + pax_exit_kernel_user
8838 + pax_erase_kstack
8839 + andl $~TS_COMPAT,TI_status(%r11)
8840 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8841 movl RIP-ARGOFFSET(%rsp),%ecx
8842 CFI_REGISTER rip,rcx
8843 @@ -347,7 +405,7 @@ sysretl_audit:
8844
8845 cstar_tracesys:
8846 #ifdef CONFIG_AUDITSYSCALL
8847 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8848 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8849 jz cstar_auditsys
8850 #endif
8851 xchgl %r9d,%ebp
8852 @@ -356,6 +414,9 @@ cstar_tracesys:
8853 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8854 movq %rsp,%rdi /* &pt_regs -> arg1 */
8855 call syscall_trace_enter
8856 +
8857 + pax_erase_kstack
8858 +
8859 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8860 RESTORE_REST
8861 xchgl %ebp,%r9d
8862 @@ -401,19 +462,21 @@ ENTRY(ia32_syscall)
8863 CFI_REL_OFFSET rip,RIP-RIP
8864 PARAVIRT_ADJUST_EXCEPTION_FRAME
8865 SWAPGS
8866 - /*
8867 - * No need to follow this irqs on/off section: the syscall
8868 - * disabled irqs and here we enable it straight after entry:
8869 - */
8870 - ENABLE_INTERRUPTS(CLBR_NONE)
8871 movl %eax,%eax
8872 pushq_cfi %rax
8873 cld
8874 /* note the registers are not zero extended to the sf.
8875 this could be a problem. */
8876 SAVE_ARGS 0,1,0
8877 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8878 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8879 + pax_enter_kernel_user
8880 + /*
8881 + * No need to follow this irqs on/off section: the syscall
8882 + * disabled irqs and here we enable it straight after entry:
8883 + */
8884 + ENABLE_INTERRUPTS(CLBR_NONE)
8885 + GET_THREAD_INFO(%r11)
8886 + orl $TS_COMPAT,TI_status(%r11)
8887 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8888 jnz ia32_tracesys
8889 cmpq $(IA32_NR_syscalls-1),%rax
8890 ja ia32_badsys
8891 @@ -432,6 +495,9 @@ ia32_tracesys:
8892 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8893 movq %rsp,%rdi /* &pt_regs -> arg1 */
8894 call syscall_trace_enter
8895 +
8896 + pax_erase_kstack
8897 +
8898 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8899 RESTORE_REST
8900 cmpq $(IA32_NR_syscalls-1),%rax
8901 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8902 index 4540bec..714d913 100644
8903 --- a/arch/x86/ia32/sys_ia32.c
8904 +++ b/arch/x86/ia32/sys_ia32.c
8905 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8906 */
8907 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8908 {
8909 - typeof(ubuf->st_uid) uid = 0;
8910 - typeof(ubuf->st_gid) gid = 0;
8911 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8912 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8913 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
8914 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
8915 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8916 @@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
8917 return ret;
8918 }
8919
8920 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8921 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8922 int options)
8923 {
8924 return compat_sys_wait4(pid, stat_addr, options, NULL);
8925 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8926 mm_segment_t old_fs = get_fs();
8927
8928 set_fs(KERNEL_DS);
8929 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8930 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8931 set_fs(old_fs);
8932 if (put_compat_timespec(&t, interval))
8933 return -EFAULT;
8934 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8935 mm_segment_t old_fs = get_fs();
8936
8937 set_fs(KERNEL_DS);
8938 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8939 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8940 set_fs(old_fs);
8941 if (!ret) {
8942 switch (_NSIG_WORDS) {
8943 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8944 if (copy_siginfo_from_user32(&info, uinfo))
8945 return -EFAULT;
8946 set_fs(KERNEL_DS);
8947 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8948 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8949 set_fs(old_fs);
8950 return ret;
8951 }
8952 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8953 return -EFAULT;
8954
8955 set_fs(KERNEL_DS);
8956 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
8957 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
8958 count);
8959 set_fs(old_fs);
8960
8961 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8962 index 952bd01..7692c6f 100644
8963 --- a/arch/x86/include/asm/alternative-asm.h
8964 +++ b/arch/x86/include/asm/alternative-asm.h
8965 @@ -15,6 +15,45 @@
8966 .endm
8967 #endif
8968
8969 +#ifdef KERNEXEC_PLUGIN
8970 + .macro pax_force_retaddr_bts rip=0
8971 + btsq $63,\rip(%rsp)
8972 + .endm
8973 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
8974 + .macro pax_force_retaddr rip=0, reload=0
8975 + btsq $63,\rip(%rsp)
8976 + .endm
8977 + .macro pax_force_fptr ptr
8978 + btsq $63,\ptr
8979 + .endm
8980 + .macro pax_set_fptr_mask
8981 + .endm
8982 +#endif
8983 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
8984 + .macro pax_force_retaddr rip=0, reload=0
8985 + .if \reload
8986 + pax_set_fptr_mask
8987 + .endif
8988 + orq %r10,\rip(%rsp)
8989 + .endm
8990 + .macro pax_force_fptr ptr
8991 + orq %r10,\ptr
8992 + .endm
8993 + .macro pax_set_fptr_mask
8994 + movabs $0x8000000000000000,%r10
8995 + .endm
8996 +#endif
8997 +#else
8998 + .macro pax_force_retaddr rip=0, reload=0
8999 + .endm
9000 + .macro pax_force_fptr ptr
9001 + .endm
9002 + .macro pax_force_retaddr_bts rip=0
9003 + .endm
9004 + .macro pax_set_fptr_mask
9005 + .endm
9006 +#endif
9007 +
9008 .macro altinstruction_entry orig alt feature orig_len alt_len
9009 .long \orig - .
9010 .long \alt - .
9011 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9012 index 49331be..9706065 100644
9013 --- a/arch/x86/include/asm/alternative.h
9014 +++ b/arch/x86/include/asm/alternative.h
9015 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9016 ".section .discard,\"aw\",@progbits\n" \
9017 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
9018 ".previous\n" \
9019 - ".section .altinstr_replacement, \"ax\"\n" \
9020 + ".section .altinstr_replacement, \"a\"\n" \
9021 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
9022 ".previous"
9023
9024 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9025 index eaff479..3025a63 100644
9026 --- a/arch/x86/include/asm/apic.h
9027 +++ b/arch/x86/include/asm/apic.h
9028 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9029
9030 #ifdef CONFIG_X86_LOCAL_APIC
9031
9032 -extern unsigned int apic_verbosity;
9033 +extern int apic_verbosity;
9034 extern int local_apic_timer_c2_ok;
9035
9036 extern int disable_apic;
9037 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9038 index 20370c6..a2eb9b0 100644
9039 --- a/arch/x86/include/asm/apm.h
9040 +++ b/arch/x86/include/asm/apm.h
9041 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9042 __asm__ __volatile__(APM_DO_ZERO_SEGS
9043 "pushl %%edi\n\t"
9044 "pushl %%ebp\n\t"
9045 - "lcall *%%cs:apm_bios_entry\n\t"
9046 + "lcall *%%ss:apm_bios_entry\n\t"
9047 "setc %%al\n\t"
9048 "popl %%ebp\n\t"
9049 "popl %%edi\n\t"
9050 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9051 __asm__ __volatile__(APM_DO_ZERO_SEGS
9052 "pushl %%edi\n\t"
9053 "pushl %%ebp\n\t"
9054 - "lcall *%%cs:apm_bios_entry\n\t"
9055 + "lcall *%%ss:apm_bios_entry\n\t"
9056 "setc %%bl\n\t"
9057 "popl %%ebp\n\t"
9058 "popl %%edi\n\t"
9059 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9060 index 58cb6d4..a4b806c 100644
9061 --- a/arch/x86/include/asm/atomic.h
9062 +++ b/arch/x86/include/asm/atomic.h
9063 @@ -22,7 +22,18 @@
9064 */
9065 static inline int atomic_read(const atomic_t *v)
9066 {
9067 - return (*(volatile int *)&(v)->counter);
9068 + return (*(volatile const int *)&(v)->counter);
9069 +}
9070 +
9071 +/**
9072 + * atomic_read_unchecked - read atomic variable
9073 + * @v: pointer of type atomic_unchecked_t
9074 + *
9075 + * Atomically reads the value of @v.
9076 + */
9077 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9078 +{
9079 + return (*(volatile const int *)&(v)->counter);
9080 }
9081
9082 /**
9083 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9084 }
9085
9086 /**
9087 + * atomic_set_unchecked - set atomic variable
9088 + * @v: pointer of type atomic_unchecked_t
9089 + * @i: required value
9090 + *
9091 + * Atomically sets the value of @v to @i.
9092 + */
9093 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9094 +{
9095 + v->counter = i;
9096 +}
9097 +
9098 +/**
9099 * atomic_add - add integer to atomic variable
9100 * @i: integer value to add
9101 * @v: pointer of type atomic_t
9102 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9103 */
9104 static inline void atomic_add(int i, atomic_t *v)
9105 {
9106 - asm volatile(LOCK_PREFIX "addl %1,%0"
9107 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9108 +
9109 +#ifdef CONFIG_PAX_REFCOUNT
9110 + "jno 0f\n"
9111 + LOCK_PREFIX "subl %1,%0\n"
9112 + "int $4\n0:\n"
9113 + _ASM_EXTABLE(0b, 0b)
9114 +#endif
9115 +
9116 + : "+m" (v->counter)
9117 + : "ir" (i));
9118 +}
9119 +
9120 +/**
9121 + * atomic_add_unchecked - add integer to atomic variable
9122 + * @i: integer value to add
9123 + * @v: pointer of type atomic_unchecked_t
9124 + *
9125 + * Atomically adds @i to @v.
9126 + */
9127 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9128 +{
9129 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9130 : "+m" (v->counter)
9131 : "ir" (i));
9132 }
9133 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9134 */
9135 static inline void atomic_sub(int i, atomic_t *v)
9136 {
9137 - asm volatile(LOCK_PREFIX "subl %1,%0"
9138 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9139 +
9140 +#ifdef CONFIG_PAX_REFCOUNT
9141 + "jno 0f\n"
9142 + LOCK_PREFIX "addl %1,%0\n"
9143 + "int $4\n0:\n"
9144 + _ASM_EXTABLE(0b, 0b)
9145 +#endif
9146 +
9147 + : "+m" (v->counter)
9148 + : "ir" (i));
9149 +}
9150 +
9151 +/**
9152 + * atomic_sub_unchecked - subtract integer from atomic variable
9153 + * @i: integer value to subtract
9154 + * @v: pointer of type atomic_unchecked_t
9155 + *
9156 + * Atomically subtracts @i from @v.
9157 + */
9158 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9159 +{
9160 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9161 : "+m" (v->counter)
9162 : "ir" (i));
9163 }
9164 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9165 {
9166 unsigned char c;
9167
9168 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9169 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9170 +
9171 +#ifdef CONFIG_PAX_REFCOUNT
9172 + "jno 0f\n"
9173 + LOCK_PREFIX "addl %2,%0\n"
9174 + "int $4\n0:\n"
9175 + _ASM_EXTABLE(0b, 0b)
9176 +#endif
9177 +
9178 + "sete %1\n"
9179 : "+m" (v->counter), "=qm" (c)
9180 : "ir" (i) : "memory");
9181 return c;
9182 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9183 */
9184 static inline void atomic_inc(atomic_t *v)
9185 {
9186 - asm volatile(LOCK_PREFIX "incl %0"
9187 + asm volatile(LOCK_PREFIX "incl %0\n"
9188 +
9189 +#ifdef CONFIG_PAX_REFCOUNT
9190 + "jno 0f\n"
9191 + LOCK_PREFIX "decl %0\n"
9192 + "int $4\n0:\n"
9193 + _ASM_EXTABLE(0b, 0b)
9194 +#endif
9195 +
9196 + : "+m" (v->counter));
9197 +}
9198 +
9199 +/**
9200 + * atomic_inc_unchecked - increment atomic variable
9201 + * @v: pointer of type atomic_unchecked_t
9202 + *
9203 + * Atomically increments @v by 1.
9204 + */
9205 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9206 +{
9207 + asm volatile(LOCK_PREFIX "incl %0\n"
9208 : "+m" (v->counter));
9209 }
9210
9211 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9212 */
9213 static inline void atomic_dec(atomic_t *v)
9214 {
9215 - asm volatile(LOCK_PREFIX "decl %0"
9216 + asm volatile(LOCK_PREFIX "decl %0\n"
9217 +
9218 +#ifdef CONFIG_PAX_REFCOUNT
9219 + "jno 0f\n"
9220 + LOCK_PREFIX "incl %0\n"
9221 + "int $4\n0:\n"
9222 + _ASM_EXTABLE(0b, 0b)
9223 +#endif
9224 +
9225 + : "+m" (v->counter));
9226 +}
9227 +
9228 +/**
9229 + * atomic_dec_unchecked - decrement atomic variable
9230 + * @v: pointer of type atomic_unchecked_t
9231 + *
9232 + * Atomically decrements @v by 1.
9233 + */
9234 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9235 +{
9236 + asm volatile(LOCK_PREFIX "decl %0\n"
9237 : "+m" (v->counter));
9238 }
9239
9240 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9241 {
9242 unsigned char c;
9243
9244 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9245 + asm volatile(LOCK_PREFIX "decl %0\n"
9246 +
9247 +#ifdef CONFIG_PAX_REFCOUNT
9248 + "jno 0f\n"
9249 + LOCK_PREFIX "incl %0\n"
9250 + "int $4\n0:\n"
9251 + _ASM_EXTABLE(0b, 0b)
9252 +#endif
9253 +
9254 + "sete %1\n"
9255 : "+m" (v->counter), "=qm" (c)
9256 : : "memory");
9257 return c != 0;
9258 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9259 {
9260 unsigned char c;
9261
9262 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9263 + asm volatile(LOCK_PREFIX "incl %0\n"
9264 +
9265 +#ifdef CONFIG_PAX_REFCOUNT
9266 + "jno 0f\n"
9267 + LOCK_PREFIX "decl %0\n"
9268 + "int $4\n0:\n"
9269 + _ASM_EXTABLE(0b, 0b)
9270 +#endif
9271 +
9272 + "sete %1\n"
9273 + : "+m" (v->counter), "=qm" (c)
9274 + : : "memory");
9275 + return c != 0;
9276 +}
9277 +
9278 +/**
9279 + * atomic_inc_and_test_unchecked - increment and test
9280 + * @v: pointer of type atomic_unchecked_t
9281 + *
9282 + * Atomically increments @v by 1
9283 + * and returns true if the result is zero, or false for all
9284 + * other cases.
9285 + */
9286 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9287 +{
9288 + unsigned char c;
9289 +
9290 + asm volatile(LOCK_PREFIX "incl %0\n"
9291 + "sete %1\n"
9292 : "+m" (v->counter), "=qm" (c)
9293 : : "memory");
9294 return c != 0;
9295 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9296 {
9297 unsigned char c;
9298
9299 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9300 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9301 +
9302 +#ifdef CONFIG_PAX_REFCOUNT
9303 + "jno 0f\n"
9304 + LOCK_PREFIX "subl %2,%0\n"
9305 + "int $4\n0:\n"
9306 + _ASM_EXTABLE(0b, 0b)
9307 +#endif
9308 +
9309 + "sets %1\n"
9310 : "+m" (v->counter), "=qm" (c)
9311 : "ir" (i) : "memory");
9312 return c;
9313 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9314 goto no_xadd;
9315 #endif
9316 /* Modern 486+ processor */
9317 - return i + xadd(&v->counter, i);
9318 + return i + xadd_check_overflow(&v->counter, i);
9319
9320 #ifdef CONFIG_M386
9321 no_xadd: /* Legacy 386 processor */
9322 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9323 }
9324
9325 /**
9326 + * atomic_add_return_unchecked - add integer and return
9327 + * @i: integer value to add
9328 + * @v: pointer of type atomic_unchecked_t
9329 + *
9330 + * Atomically adds @i to @v and returns @i + @v
9331 + */
9332 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9333 +{
9334 +#ifdef CONFIG_M386
9335 + int __i;
9336 + unsigned long flags;
9337 + if (unlikely(boot_cpu_data.x86 <= 3))
9338 + goto no_xadd;
9339 +#endif
9340 + /* Modern 486+ processor */
9341 + return i + xadd(&v->counter, i);
9342 +
9343 +#ifdef CONFIG_M386
9344 +no_xadd: /* Legacy 386 processor */
9345 + raw_local_irq_save(flags);
9346 + __i = atomic_read_unchecked(v);
9347 + atomic_set_unchecked(v, i + __i);
9348 + raw_local_irq_restore(flags);
9349 + return i + __i;
9350 +#endif
9351 +}
9352 +
9353 +/**
9354 * atomic_sub_return - subtract integer and return
9355 * @v: pointer of type atomic_t
9356 * @i: integer value to subtract
9357 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9358 }
9359
9360 #define atomic_inc_return(v) (atomic_add_return(1, v))
9361 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9362 +{
9363 + return atomic_add_return_unchecked(1, v);
9364 +}
9365 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9366
9367 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9368 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9369 return cmpxchg(&v->counter, old, new);
9370 }
9371
9372 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9373 +{
9374 + return cmpxchg(&v->counter, old, new);
9375 +}
9376 +
9377 static inline int atomic_xchg(atomic_t *v, int new)
9378 {
9379 return xchg(&v->counter, new);
9380 }
9381
9382 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9383 +{
9384 + return xchg(&v->counter, new);
9385 +}
9386 +
9387 /**
9388 * __atomic_add_unless - add unless the number is already a given value
9389 * @v: pointer of type atomic_t
9390 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9391 */
9392 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9393 {
9394 - int c, old;
9395 + int c, old, new;
9396 c = atomic_read(v);
9397 for (;;) {
9398 - if (unlikely(c == (u)))
9399 + if (unlikely(c == u))
9400 break;
9401 - old = atomic_cmpxchg((v), c, c + (a));
9402 +
9403 + asm volatile("addl %2,%0\n"
9404 +
9405 +#ifdef CONFIG_PAX_REFCOUNT
9406 + "jno 0f\n"
9407 + "subl %2,%0\n"
9408 + "int $4\n0:\n"
9409 + _ASM_EXTABLE(0b, 0b)
9410 +#endif
9411 +
9412 + : "=r" (new)
9413 + : "0" (c), "ir" (a));
9414 +
9415 + old = atomic_cmpxchg(v, c, new);
9416 if (likely(old == c))
9417 break;
9418 c = old;
9419 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9420 return c;
9421 }
9422
9423 +/**
9424 + * atomic_inc_not_zero_hint - increment if not null
9425 + * @v: pointer of type atomic_t
9426 + * @hint: probable value of the atomic before the increment
9427 + *
9428 + * This version of atomic_inc_not_zero() gives a hint of probable
9429 + * value of the atomic. This helps processor to not read the memory
9430 + * before doing the atomic read/modify/write cycle, lowering
9431 + * number of bus transactions on some arches.
9432 + *
9433 + * Returns: 0 if increment was not done, 1 otherwise.
9434 + */
9435 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9436 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9437 +{
9438 + int val, c = hint, new;
9439 +
9440 + /* sanity test, should be removed by compiler if hint is a constant */
9441 + if (!hint)
9442 + return __atomic_add_unless(v, 1, 0);
9443 +
9444 + do {
9445 + asm volatile("incl %0\n"
9446 +
9447 +#ifdef CONFIG_PAX_REFCOUNT
9448 + "jno 0f\n"
9449 + "decl %0\n"
9450 + "int $4\n0:\n"
9451 + _ASM_EXTABLE(0b, 0b)
9452 +#endif
9453 +
9454 + : "=r" (new)
9455 + : "0" (c));
9456 +
9457 + val = atomic_cmpxchg(v, c, new);
9458 + if (val == c)
9459 + return 1;
9460 + c = val;
9461 + } while (c);
9462 +
9463 + return 0;
9464 +}
9465
9466 /*
9467 * atomic_dec_if_positive - decrement by 1 if old value positive
9468 @@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9469 #endif
9470
9471 /* These are x86-specific, used by some header files */
9472 -#define atomic_clear_mask(mask, addr) \
9473 - asm volatile(LOCK_PREFIX "andl %0,%1" \
9474 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
9475 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9476 +{
9477 + asm volatile(LOCK_PREFIX "andl %1,%0"
9478 + : "+m" (v->counter)
9479 + : "r" (~(mask))
9480 + : "memory");
9481 +}
9482
9483 -#define atomic_set_mask(mask, addr) \
9484 - asm volatile(LOCK_PREFIX "orl %0,%1" \
9485 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9486 - : "memory")
9487 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9488 +{
9489 + asm volatile(LOCK_PREFIX "andl %1,%0"
9490 + : "+m" (v->counter)
9491 + : "r" (~(mask))
9492 + : "memory");
9493 +}
9494 +
9495 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9496 +{
9497 + asm volatile(LOCK_PREFIX "orl %1,%0"
9498 + : "+m" (v->counter)
9499 + : "r" (mask)
9500 + : "memory");
9501 +}
9502 +
9503 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9504 +{
9505 + asm volatile(LOCK_PREFIX "orl %1,%0"
9506 + : "+m" (v->counter)
9507 + : "r" (mask)
9508 + : "memory");
9509 +}
9510
9511 /* Atomic operations are already serializing on x86 */
9512 #define smp_mb__before_atomic_dec() barrier()
9513 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9514 index b154de7..aadebd8 100644
9515 --- a/arch/x86/include/asm/atomic64_32.h
9516 +++ b/arch/x86/include/asm/atomic64_32.h
9517 @@ -12,6 +12,14 @@ typedef struct {
9518 u64 __aligned(8) counter;
9519 } atomic64_t;
9520
9521 +#ifdef CONFIG_PAX_REFCOUNT
9522 +typedef struct {
9523 + u64 __aligned(8) counter;
9524 +} atomic64_unchecked_t;
9525 +#else
9526 +typedef atomic64_t atomic64_unchecked_t;
9527 +#endif
9528 +
9529 #define ATOMIC64_INIT(val) { (val) }
9530
9531 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9532 @@ -37,21 +45,31 @@ typedef struct {
9533 ATOMIC64_DECL_ONE(sym##_386)
9534
9535 ATOMIC64_DECL_ONE(add_386);
9536 +ATOMIC64_DECL_ONE(add_unchecked_386);
9537 ATOMIC64_DECL_ONE(sub_386);
9538 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9539 ATOMIC64_DECL_ONE(inc_386);
9540 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9541 ATOMIC64_DECL_ONE(dec_386);
9542 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9543 #endif
9544
9545 #define alternative_atomic64(f, out, in...) \
9546 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9547
9548 ATOMIC64_DECL(read);
9549 +ATOMIC64_DECL(read_unchecked);
9550 ATOMIC64_DECL(set);
9551 +ATOMIC64_DECL(set_unchecked);
9552 ATOMIC64_DECL(xchg);
9553 ATOMIC64_DECL(add_return);
9554 +ATOMIC64_DECL(add_return_unchecked);
9555 ATOMIC64_DECL(sub_return);
9556 +ATOMIC64_DECL(sub_return_unchecked);
9557 ATOMIC64_DECL(inc_return);
9558 +ATOMIC64_DECL(inc_return_unchecked);
9559 ATOMIC64_DECL(dec_return);
9560 +ATOMIC64_DECL(dec_return_unchecked);
9561 ATOMIC64_DECL(dec_if_positive);
9562 ATOMIC64_DECL(inc_not_zero);
9563 ATOMIC64_DECL(add_unless);
9564 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9565 }
9566
9567 /**
9568 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9569 + * @p: pointer to type atomic64_unchecked_t
9570 + * @o: expected value
9571 + * @n: new value
9572 + *
9573 + * Atomically sets @v to @n if it was equal to @o and returns
9574 + * the old value.
9575 + */
9576 +
9577 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9578 +{
9579 + return cmpxchg64(&v->counter, o, n);
9580 +}
9581 +
9582 +/**
9583 * atomic64_xchg - xchg atomic64 variable
9584 * @v: pointer to type atomic64_t
9585 * @n: value to assign
9586 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9587 }
9588
9589 /**
9590 + * atomic64_set_unchecked - set atomic64 variable
9591 + * @v: pointer to type atomic64_unchecked_t
9592 + * @n: value to assign
9593 + *
9594 + * Atomically sets the value of @v to @n.
9595 + */
9596 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9597 +{
9598 + unsigned high = (unsigned)(i >> 32);
9599 + unsigned low = (unsigned)i;
9600 + alternative_atomic64(set, /* no output */,
9601 + "S" (v), "b" (low), "c" (high)
9602 + : "eax", "edx", "memory");
9603 +}
9604 +
9605 +/**
9606 * atomic64_read - read atomic64 variable
9607 * @v: pointer to type atomic64_t
9608 *
9609 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9610 }
9611
9612 /**
9613 + * atomic64_read_unchecked - read atomic64 variable
9614 + * @v: pointer to type atomic64_unchecked_t
9615 + *
9616 + * Atomically reads the value of @v and returns it.
9617 + */
9618 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9619 +{
9620 + long long r;
9621 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9622 + return r;
9623 + }
9624 +
9625 +/**
9626 * atomic64_add_return - add and return
9627 * @i: integer value to add
9628 * @v: pointer to type atomic64_t
9629 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9630 return i;
9631 }
9632
9633 +/**
9634 + * atomic64_add_return_unchecked - add and return
9635 + * @i: integer value to add
9636 + * @v: pointer to type atomic64_unchecked_t
9637 + *
9638 + * Atomically adds @i to @v and returns @i + *@v
9639 + */
9640 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9641 +{
9642 + alternative_atomic64(add_return_unchecked,
9643 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9644 + ASM_NO_INPUT_CLOBBER("memory"));
9645 + return i;
9646 +}
9647 +
9648 /*
9649 * Other variants with different arithmetic operators:
9650 */
9651 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9652 return a;
9653 }
9654
9655 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9656 +{
9657 + long long a;
9658 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9659 + "S" (v) : "memory", "ecx");
9660 + return a;
9661 +}
9662 +
9663 static inline long long atomic64_dec_return(atomic64_t *v)
9664 {
9665 long long a;
9666 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9667 }
9668
9669 /**
9670 + * atomic64_add_unchecked - add integer to atomic64 variable
9671 + * @i: integer value to add
9672 + * @v: pointer to type atomic64_unchecked_t
9673 + *
9674 + * Atomically adds @i to @v.
9675 + */
9676 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9677 +{
9678 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9679 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9680 + ASM_NO_INPUT_CLOBBER("memory"));
9681 + return i;
9682 +}
9683 +
9684 +/**
9685 * atomic64_sub - subtract the atomic64 variable
9686 * @i: integer value to subtract
9687 * @v: pointer to type atomic64_t
9688 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9689 index 0e1cbfc..5623683 100644
9690 --- a/arch/x86/include/asm/atomic64_64.h
9691 +++ b/arch/x86/include/asm/atomic64_64.h
9692 @@ -18,7 +18,19 @@
9693 */
9694 static inline long atomic64_read(const atomic64_t *v)
9695 {
9696 - return (*(volatile long *)&(v)->counter);
9697 + return (*(volatile const long *)&(v)->counter);
9698 +}
9699 +
9700 +/**
9701 + * atomic64_read_unchecked - read atomic64 variable
9702 + * @v: pointer of type atomic64_unchecked_t
9703 + *
9704 + * Atomically reads the value of @v.
9705 + * Doesn't imply a read memory barrier.
9706 + */
9707 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9708 +{
9709 + return (*(volatile const long *)&(v)->counter);
9710 }
9711
9712 /**
9713 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9714 }
9715
9716 /**
9717 + * atomic64_set_unchecked - set atomic64 variable
9718 + * @v: pointer to type atomic64_unchecked_t
9719 + * @i: required value
9720 + *
9721 + * Atomically sets the value of @v to @i.
9722 + */
9723 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9724 +{
9725 + v->counter = i;
9726 +}
9727 +
9728 +/**
9729 * atomic64_add - add integer to atomic64 variable
9730 * @i: integer value to add
9731 * @v: pointer to type atomic64_t
9732 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9733 */
9734 static inline void atomic64_add(long i, atomic64_t *v)
9735 {
9736 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9737 +
9738 +#ifdef CONFIG_PAX_REFCOUNT
9739 + "jno 0f\n"
9740 + LOCK_PREFIX "subq %1,%0\n"
9741 + "int $4\n0:\n"
9742 + _ASM_EXTABLE(0b, 0b)
9743 +#endif
9744 +
9745 + : "=m" (v->counter)
9746 + : "er" (i), "m" (v->counter));
9747 +}
9748 +
9749 +/**
9750 + * atomic64_add_unchecked - add integer to atomic64 variable
9751 + * @i: integer value to add
9752 + * @v: pointer to type atomic64_unchecked_t
9753 + *
9754 + * Atomically adds @i to @v.
9755 + */
9756 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9757 +{
9758 asm volatile(LOCK_PREFIX "addq %1,%0"
9759 : "=m" (v->counter)
9760 : "er" (i), "m" (v->counter));
9761 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9762 */
9763 static inline void atomic64_sub(long i, atomic64_t *v)
9764 {
9765 - asm volatile(LOCK_PREFIX "subq %1,%0"
9766 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9767 +
9768 +#ifdef CONFIG_PAX_REFCOUNT
9769 + "jno 0f\n"
9770 + LOCK_PREFIX "addq %1,%0\n"
9771 + "int $4\n0:\n"
9772 + _ASM_EXTABLE(0b, 0b)
9773 +#endif
9774 +
9775 + : "=m" (v->counter)
9776 + : "er" (i), "m" (v->counter));
9777 +}
9778 +
9779 +/**
9780 + * atomic64_sub_unchecked - subtract the atomic64 variable
9781 + * @i: integer value to subtract
9782 + * @v: pointer to type atomic64_unchecked_t
9783 + *
9784 + * Atomically subtracts @i from @v.
9785 + */
9786 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9787 +{
9788 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9789 : "=m" (v->counter)
9790 : "er" (i), "m" (v->counter));
9791 }
9792 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9793 {
9794 unsigned char c;
9795
9796 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9797 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9798 +
9799 +#ifdef CONFIG_PAX_REFCOUNT
9800 + "jno 0f\n"
9801 + LOCK_PREFIX "addq %2,%0\n"
9802 + "int $4\n0:\n"
9803 + _ASM_EXTABLE(0b, 0b)
9804 +#endif
9805 +
9806 + "sete %1\n"
9807 : "=m" (v->counter), "=qm" (c)
9808 : "er" (i), "m" (v->counter) : "memory");
9809 return c;
9810 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9811 */
9812 static inline void atomic64_inc(atomic64_t *v)
9813 {
9814 + asm volatile(LOCK_PREFIX "incq %0\n"
9815 +
9816 +#ifdef CONFIG_PAX_REFCOUNT
9817 + "jno 0f\n"
9818 + LOCK_PREFIX "decq %0\n"
9819 + "int $4\n0:\n"
9820 + _ASM_EXTABLE(0b, 0b)
9821 +#endif
9822 +
9823 + : "=m" (v->counter)
9824 + : "m" (v->counter));
9825 +}
9826 +
9827 +/**
9828 + * atomic64_inc_unchecked - increment atomic64 variable
9829 + * @v: pointer to type atomic64_unchecked_t
9830 + *
9831 + * Atomically increments @v by 1.
9832 + */
9833 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9834 +{
9835 asm volatile(LOCK_PREFIX "incq %0"
9836 : "=m" (v->counter)
9837 : "m" (v->counter));
9838 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9839 */
9840 static inline void atomic64_dec(atomic64_t *v)
9841 {
9842 - asm volatile(LOCK_PREFIX "decq %0"
9843 + asm volatile(LOCK_PREFIX "decq %0\n"
9844 +
9845 +#ifdef CONFIG_PAX_REFCOUNT
9846 + "jno 0f\n"
9847 + LOCK_PREFIX "incq %0\n"
9848 + "int $4\n0:\n"
9849 + _ASM_EXTABLE(0b, 0b)
9850 +#endif
9851 +
9852 + : "=m" (v->counter)
9853 + : "m" (v->counter));
9854 +}
9855 +
9856 +/**
9857 + * atomic64_dec_unchecked - decrement atomic64 variable
9858 + * @v: pointer to type atomic64_t
9859 + *
9860 + * Atomically decrements @v by 1.
9861 + */
9862 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9863 +{
9864 + asm volatile(LOCK_PREFIX "decq %0\n"
9865 : "=m" (v->counter)
9866 : "m" (v->counter));
9867 }
9868 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9869 {
9870 unsigned char c;
9871
9872 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9873 + asm volatile(LOCK_PREFIX "decq %0\n"
9874 +
9875 +#ifdef CONFIG_PAX_REFCOUNT
9876 + "jno 0f\n"
9877 + LOCK_PREFIX "incq %0\n"
9878 + "int $4\n0:\n"
9879 + _ASM_EXTABLE(0b, 0b)
9880 +#endif
9881 +
9882 + "sete %1\n"
9883 : "=m" (v->counter), "=qm" (c)
9884 : "m" (v->counter) : "memory");
9885 return c != 0;
9886 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9887 {
9888 unsigned char c;
9889
9890 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9891 + asm volatile(LOCK_PREFIX "incq %0\n"
9892 +
9893 +#ifdef CONFIG_PAX_REFCOUNT
9894 + "jno 0f\n"
9895 + LOCK_PREFIX "decq %0\n"
9896 + "int $4\n0:\n"
9897 + _ASM_EXTABLE(0b, 0b)
9898 +#endif
9899 +
9900 + "sete %1\n"
9901 : "=m" (v->counter), "=qm" (c)
9902 : "m" (v->counter) : "memory");
9903 return c != 0;
9904 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9905 {
9906 unsigned char c;
9907
9908 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9909 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9910 +
9911 +#ifdef CONFIG_PAX_REFCOUNT
9912 + "jno 0f\n"
9913 + LOCK_PREFIX "subq %2,%0\n"
9914 + "int $4\n0:\n"
9915 + _ASM_EXTABLE(0b, 0b)
9916 +#endif
9917 +
9918 + "sets %1\n"
9919 : "=m" (v->counter), "=qm" (c)
9920 : "er" (i), "m" (v->counter) : "memory");
9921 return c;
9922 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9923 */
9924 static inline long atomic64_add_return(long i, atomic64_t *v)
9925 {
9926 + return i + xadd_check_overflow(&v->counter, i);
9927 +}
9928 +
9929 +/**
9930 + * atomic64_add_return_unchecked - add and return
9931 + * @i: integer value to add
9932 + * @v: pointer to type atomic64_unchecked_t
9933 + *
9934 + * Atomically adds @i to @v and returns @i + @v
9935 + */
9936 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9937 +{
9938 return i + xadd(&v->counter, i);
9939 }
9940
9941 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9942 }
9943
9944 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9945 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9946 +{
9947 + return atomic64_add_return_unchecked(1, v);
9948 +}
9949 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9950
9951 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9952 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9953 return cmpxchg(&v->counter, old, new);
9954 }
9955
9956 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9957 +{
9958 + return cmpxchg(&v->counter, old, new);
9959 +}
9960 +
9961 static inline long atomic64_xchg(atomic64_t *v, long new)
9962 {
9963 return xchg(&v->counter, new);
9964 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
9965 */
9966 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9967 {
9968 - long c, old;
9969 + long c, old, new;
9970 c = atomic64_read(v);
9971 for (;;) {
9972 - if (unlikely(c == (u)))
9973 + if (unlikely(c == u))
9974 break;
9975 - old = atomic64_cmpxchg((v), c, c + (a));
9976 +
9977 + asm volatile("add %2,%0\n"
9978 +
9979 +#ifdef CONFIG_PAX_REFCOUNT
9980 + "jno 0f\n"
9981 + "sub %2,%0\n"
9982 + "int $4\n0:\n"
9983 + _ASM_EXTABLE(0b, 0b)
9984 +#endif
9985 +
9986 + : "=r" (new)
9987 + : "0" (c), "ir" (a));
9988 +
9989 + old = atomic64_cmpxchg(v, c, new);
9990 if (likely(old == c))
9991 break;
9992 c = old;
9993 }
9994 - return c != (u);
9995 + return c != u;
9996 }
9997
9998 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9999 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10000 index a6983b2..63f48a2 100644
10001 --- a/arch/x86/include/asm/bitops.h
10002 +++ b/arch/x86/include/asm/bitops.h
10003 @@ -40,7 +40,7 @@
10004 * a mask operation on a byte.
10005 */
10006 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10007 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10008 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10009 #define CONST_MASK(nr) (1 << ((nr) & 7))
10010
10011 /**
10012 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10013 index b13fe63..0dab13a 100644
10014 --- a/arch/x86/include/asm/boot.h
10015 +++ b/arch/x86/include/asm/boot.h
10016 @@ -11,10 +11,15 @@
10017 #include <asm/pgtable_types.h>
10018
10019 /* Physical address where kernel should be loaded. */
10020 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10021 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10022 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10023 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10024
10025 +#ifndef __ASSEMBLY__
10026 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10027 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10028 +#endif
10029 +
10030 /* Minimum kernel alignment, as a power of two */
10031 #ifdef CONFIG_X86_64
10032 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10033 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10034 index 48f99f1..d78ebf9 100644
10035 --- a/arch/x86/include/asm/cache.h
10036 +++ b/arch/x86/include/asm/cache.h
10037 @@ -5,12 +5,13 @@
10038
10039 /* L1 cache line size */
10040 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10041 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10042 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10043
10044 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10045 +#define __read_only __attribute__((__section__(".data..read_only")))
10046
10047 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10048 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10049 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10050
10051 #ifdef CONFIG_X86_VSMP
10052 #ifdef CONFIG_SMP
10053 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10054 index 9863ee3..4a1f8e1 100644
10055 --- a/arch/x86/include/asm/cacheflush.h
10056 +++ b/arch/x86/include/asm/cacheflush.h
10057 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10058 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10059
10060 if (pg_flags == _PGMT_DEFAULT)
10061 - return -1;
10062 + return ~0UL;
10063 else if (pg_flags == _PGMT_WC)
10064 return _PAGE_CACHE_WC;
10065 else if (pg_flags == _PGMT_UC_MINUS)
10066 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10067 index 46fc474..b02b0f9 100644
10068 --- a/arch/x86/include/asm/checksum_32.h
10069 +++ b/arch/x86/include/asm/checksum_32.h
10070 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10071 int len, __wsum sum,
10072 int *src_err_ptr, int *dst_err_ptr);
10073
10074 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10075 + int len, __wsum sum,
10076 + int *src_err_ptr, int *dst_err_ptr);
10077 +
10078 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10079 + int len, __wsum sum,
10080 + int *src_err_ptr, int *dst_err_ptr);
10081 +
10082 /*
10083 * Note: when you get a NULL pointer exception here this means someone
10084 * passed in an incorrect kernel address to one of these functions.
10085 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10086 int *err_ptr)
10087 {
10088 might_sleep();
10089 - return csum_partial_copy_generic((__force void *)src, dst,
10090 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10091 len, sum, err_ptr, NULL);
10092 }
10093
10094 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10095 {
10096 might_sleep();
10097 if (access_ok(VERIFY_WRITE, dst, len))
10098 - return csum_partial_copy_generic(src, (__force void *)dst,
10099 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10100 len, sum, NULL, err_ptr);
10101
10102 if (len)
10103 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10104 index 99480e5..d81165b 100644
10105 --- a/arch/x86/include/asm/cmpxchg.h
10106 +++ b/arch/x86/include/asm/cmpxchg.h
10107 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10108 __compiletime_error("Bad argument size for cmpxchg");
10109 extern void __xadd_wrong_size(void)
10110 __compiletime_error("Bad argument size for xadd");
10111 +extern void __xadd_check_overflow_wrong_size(void)
10112 + __compiletime_error("Bad argument size for xadd_check_overflow");
10113 extern void __add_wrong_size(void)
10114 __compiletime_error("Bad argument size for add");
10115 +extern void __add_check_overflow_wrong_size(void)
10116 + __compiletime_error("Bad argument size for add_check_overflow");
10117
10118 /*
10119 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10120 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10121 __ret; \
10122 })
10123
10124 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10125 + ({ \
10126 + __typeof__ (*(ptr)) __ret = (arg); \
10127 + switch (sizeof(*(ptr))) { \
10128 + case __X86_CASE_L: \
10129 + asm volatile (lock #op "l %0, %1\n" \
10130 + "jno 0f\n" \
10131 + "mov %0,%1\n" \
10132 + "int $4\n0:\n" \
10133 + _ASM_EXTABLE(0b, 0b) \
10134 + : "+r" (__ret), "+m" (*(ptr)) \
10135 + : : "memory", "cc"); \
10136 + break; \
10137 + case __X86_CASE_Q: \
10138 + asm volatile (lock #op "q %q0, %1\n" \
10139 + "jno 0f\n" \
10140 + "mov %0,%1\n" \
10141 + "int $4\n0:\n" \
10142 + _ASM_EXTABLE(0b, 0b) \
10143 + : "+r" (__ret), "+m" (*(ptr)) \
10144 + : : "memory", "cc"); \
10145 + break; \
10146 + default: \
10147 + __ ## op ## _check_overflow_wrong_size(); \
10148 + } \
10149 + __ret; \
10150 + })
10151 +
10152 /*
10153 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10154 * Since this is generally used to protect other memory information, we
10155 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10156 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10157 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10158
10159 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10160 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10161 +
10162 #define __add(ptr, inc, lock) \
10163 ({ \
10164 __typeof__ (*(ptr)) __ret = (inc); \
10165 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10166 index f91e80f..7f9bd27 100644
10167 --- a/arch/x86/include/asm/cpufeature.h
10168 +++ b/arch/x86/include/asm/cpufeature.h
10169 @@ -371,7 +371,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10170 ".section .discard,\"aw\",@progbits\n"
10171 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10172 ".previous\n"
10173 - ".section .altinstr_replacement,\"ax\"\n"
10174 + ".section .altinstr_replacement,\"a\"\n"
10175 "3: movb $1,%0\n"
10176 "4:\n"
10177 ".previous\n"
10178 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10179 index 8bf1c06..f723dfd 100644
10180 --- a/arch/x86/include/asm/desc.h
10181 +++ b/arch/x86/include/asm/desc.h
10182 @@ -4,6 +4,7 @@
10183 #include <asm/desc_defs.h>
10184 #include <asm/ldt.h>
10185 #include <asm/mmu.h>
10186 +#include <asm/pgtable.h>
10187
10188 #include <linux/smp.h>
10189 #include <linux/percpu.h>
10190 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10191
10192 desc->type = (info->read_exec_only ^ 1) << 1;
10193 desc->type |= info->contents << 2;
10194 + desc->type |= info->seg_not_present ^ 1;
10195
10196 desc->s = 1;
10197 desc->dpl = 0x3;
10198 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10199 }
10200
10201 extern struct desc_ptr idt_descr;
10202 -extern gate_desc idt_table[];
10203 extern struct desc_ptr nmi_idt_descr;
10204 -extern gate_desc nmi_idt_table[];
10205 -
10206 -struct gdt_page {
10207 - struct desc_struct gdt[GDT_ENTRIES];
10208 -} __attribute__((aligned(PAGE_SIZE)));
10209 -
10210 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10211 +extern gate_desc idt_table[256];
10212 +extern gate_desc nmi_idt_table[256];
10213
10214 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10215 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10216 {
10217 - return per_cpu(gdt_page, cpu).gdt;
10218 + return cpu_gdt_table[cpu];
10219 }
10220
10221 #ifdef CONFIG_X86_64
10222 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10223 unsigned long base, unsigned dpl, unsigned flags,
10224 unsigned short seg)
10225 {
10226 - gate->a = (seg << 16) | (base & 0xffff);
10227 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10228 + gate->gate.offset_low = base;
10229 + gate->gate.seg = seg;
10230 + gate->gate.reserved = 0;
10231 + gate->gate.type = type;
10232 + gate->gate.s = 0;
10233 + gate->gate.dpl = dpl;
10234 + gate->gate.p = 1;
10235 + gate->gate.offset_high = base >> 16;
10236 }
10237
10238 #endif
10239 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10240
10241 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10242 {
10243 + pax_open_kernel();
10244 memcpy(&idt[entry], gate, sizeof(*gate));
10245 + pax_close_kernel();
10246 }
10247
10248 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10249 {
10250 + pax_open_kernel();
10251 memcpy(&ldt[entry], desc, 8);
10252 + pax_close_kernel();
10253 }
10254
10255 static inline void
10256 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10257 default: size = sizeof(*gdt); break;
10258 }
10259
10260 + pax_open_kernel();
10261 memcpy(&gdt[entry], desc, size);
10262 + pax_close_kernel();
10263 }
10264
10265 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10266 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10267
10268 static inline void native_load_tr_desc(void)
10269 {
10270 + pax_open_kernel();
10271 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10272 + pax_close_kernel();
10273 }
10274
10275 static inline void native_load_gdt(const struct desc_ptr *dtr)
10276 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10277 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10278 unsigned int i;
10279
10280 + pax_open_kernel();
10281 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10282 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10283 + pax_close_kernel();
10284 }
10285
10286 #define _LDT_empty(info) \
10287 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10288 }
10289
10290 #ifdef CONFIG_X86_64
10291 -static inline void set_nmi_gate(int gate, void *addr)
10292 +static inline void set_nmi_gate(int gate, const void *addr)
10293 {
10294 gate_desc s;
10295
10296 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10297 }
10298 #endif
10299
10300 -static inline void _set_gate(int gate, unsigned type, void *addr,
10301 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10302 unsigned dpl, unsigned ist, unsigned seg)
10303 {
10304 gate_desc s;
10305 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10306 * Pentium F0 0F bugfix can have resulted in the mapped
10307 * IDT being write-protected.
10308 */
10309 -static inline void set_intr_gate(unsigned int n, void *addr)
10310 +static inline void set_intr_gate(unsigned int n, const void *addr)
10311 {
10312 BUG_ON((unsigned)n > 0xFF);
10313 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10314 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10315 /*
10316 * This routine sets up an interrupt gate at directory privilege level 3.
10317 */
10318 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10319 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10320 {
10321 BUG_ON((unsigned)n > 0xFF);
10322 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10323 }
10324
10325 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10326 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10327 {
10328 BUG_ON((unsigned)n > 0xFF);
10329 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10330 }
10331
10332 -static inline void set_trap_gate(unsigned int n, void *addr)
10333 +static inline void set_trap_gate(unsigned int n, const void *addr)
10334 {
10335 BUG_ON((unsigned)n > 0xFF);
10336 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10337 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10338 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10339 {
10340 BUG_ON((unsigned)n > 0xFF);
10341 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10342 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10343 }
10344
10345 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10346 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10347 {
10348 BUG_ON((unsigned)n > 0xFF);
10349 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10350 }
10351
10352 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10353 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10354 {
10355 BUG_ON((unsigned)n > 0xFF);
10356 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10357 }
10358
10359 +#ifdef CONFIG_X86_32
10360 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10361 +{
10362 + struct desc_struct d;
10363 +
10364 + if (likely(limit))
10365 + limit = (limit - 1UL) >> PAGE_SHIFT;
10366 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10367 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10368 +}
10369 +#endif
10370 +
10371 #endif /* _ASM_X86_DESC_H */
10372 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10373 index 278441f..b95a174 100644
10374 --- a/arch/x86/include/asm/desc_defs.h
10375 +++ b/arch/x86/include/asm/desc_defs.h
10376 @@ -31,6 +31,12 @@ struct desc_struct {
10377 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10378 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10379 };
10380 + struct {
10381 + u16 offset_low;
10382 + u16 seg;
10383 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10384 + unsigned offset_high: 16;
10385 + } gate;
10386 };
10387 } __attribute__((packed));
10388
10389 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10390 index 3778256..c5d4fce 100644
10391 --- a/arch/x86/include/asm/e820.h
10392 +++ b/arch/x86/include/asm/e820.h
10393 @@ -69,7 +69,7 @@ struct e820map {
10394 #define ISA_START_ADDRESS 0xa0000
10395 #define ISA_END_ADDRESS 0x100000
10396
10397 -#define BIOS_BEGIN 0x000a0000
10398 +#define BIOS_BEGIN 0x000c0000
10399 #define BIOS_END 0x00100000
10400
10401 #define BIOS_ROM_BASE 0xffe00000
10402 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10403 index 5939f44..f8845f6 100644
10404 --- a/arch/x86/include/asm/elf.h
10405 +++ b/arch/x86/include/asm/elf.h
10406 @@ -243,7 +243,25 @@ extern int force_personality32;
10407 the loader. We need to make sure that it is out of the way of the program
10408 that it will "exec", and that there is sufficient room for the brk. */
10409
10410 +#ifdef CONFIG_PAX_SEGMEXEC
10411 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10412 +#else
10413 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10414 +#endif
10415 +
10416 +#ifdef CONFIG_PAX_ASLR
10417 +#ifdef CONFIG_X86_32
10418 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10419 +
10420 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10421 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10422 +#else
10423 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10424 +
10425 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10426 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10427 +#endif
10428 +#endif
10429
10430 /* This yields a mask that user programs can use to figure out what
10431 instruction set this CPU supports. This could be done in user space,
10432 @@ -296,16 +314,12 @@ do { \
10433
10434 #define ARCH_DLINFO \
10435 do { \
10436 - if (vdso_enabled) \
10437 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10438 - (unsigned long)current->mm->context.vdso); \
10439 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10440 } while (0)
10441
10442 #define ARCH_DLINFO_X32 \
10443 do { \
10444 - if (vdso_enabled) \
10445 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10446 - (unsigned long)current->mm->context.vdso); \
10447 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10448 } while (0)
10449
10450 #define AT_SYSINFO 32
10451 @@ -320,7 +334,7 @@ else \
10452
10453 #endif /* !CONFIG_X86_32 */
10454
10455 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10456 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10457
10458 #define VDSO_ENTRY \
10459 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10460 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10461 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10462 #define compat_arch_setup_additional_pages syscall32_setup_pages
10463
10464 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10465 -#define arch_randomize_brk arch_randomize_brk
10466 -
10467 /*
10468 * True on X86_32 or when emulating IA32 on X86_64
10469 */
10470 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10471 index cc70c1c..d96d011 100644
10472 --- a/arch/x86/include/asm/emergency-restart.h
10473 +++ b/arch/x86/include/asm/emergency-restart.h
10474 @@ -15,6 +15,6 @@ enum reboot_type {
10475
10476 extern enum reboot_type reboot_type;
10477
10478 -extern void machine_emergency_restart(void);
10479 +extern void machine_emergency_restart(void) __noreturn;
10480
10481 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10482 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10483 index 75f4c6d..ee3eb8f 100644
10484 --- a/arch/x86/include/asm/fpu-internal.h
10485 +++ b/arch/x86/include/asm/fpu-internal.h
10486 @@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10487 {
10488 int err;
10489
10490 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10491 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10492 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10493 +#endif
10494 +
10495 /* See comment in fxsave() below. */
10496 #ifdef CONFIG_AS_FXSAVEQ
10497 asm volatile("1: fxrstorq %[fx]\n\t"
10498 @@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10499 {
10500 int err;
10501
10502 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10503 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10504 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10505 +#endif
10506 +
10507 /*
10508 * Clear the bytes not touched by the fxsave and reserved
10509 * for the SW usage.
10510 @@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10511 "emms\n\t" /* clear stack tags */
10512 "fildl %P[addr]", /* set F?P to defined value */
10513 X86_FEATURE_FXSAVE_LEAK,
10514 - [addr] "m" (tsk->thread.fpu.has_fpu));
10515 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10516
10517 return fpu_restore_checking(&tsk->thread.fpu);
10518 }
10519 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10520 index 71ecbcb..bac10b7 100644
10521 --- a/arch/x86/include/asm/futex.h
10522 +++ b/arch/x86/include/asm/futex.h
10523 @@ -11,16 +11,18 @@
10524 #include <asm/processor.h>
10525
10526 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10527 + typecheck(u32 __user *, uaddr); \
10528 asm volatile("1:\t" insn "\n" \
10529 "2:\t.section .fixup,\"ax\"\n" \
10530 "3:\tmov\t%3, %1\n" \
10531 "\tjmp\t2b\n" \
10532 "\t.previous\n" \
10533 _ASM_EXTABLE(1b, 3b) \
10534 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10535 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10536 : "i" (-EFAULT), "0" (oparg), "1" (0))
10537
10538 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10539 + typecheck(u32 __user *, uaddr); \
10540 asm volatile("1:\tmovl %2, %0\n" \
10541 "\tmovl\t%0, %3\n" \
10542 "\t" insn "\n" \
10543 @@ -33,7 +35,7 @@
10544 _ASM_EXTABLE(1b, 4b) \
10545 _ASM_EXTABLE(2b, 4b) \
10546 : "=&a" (oldval), "=&r" (ret), \
10547 - "+m" (*uaddr), "=&r" (tem) \
10548 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10549 : "r" (oparg), "i" (-EFAULT), "1" (0))
10550
10551 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10552 @@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10553
10554 switch (op) {
10555 case FUTEX_OP_SET:
10556 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10557 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10558 break;
10559 case FUTEX_OP_ADD:
10560 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10561 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10562 uaddr, oparg);
10563 break;
10564 case FUTEX_OP_OR:
10565 @@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10566 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10567 return -EFAULT;
10568
10569 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10570 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10571 "2:\t.section .fixup, \"ax\"\n"
10572 "3:\tmov %3, %0\n"
10573 "\tjmp 2b\n"
10574 "\t.previous\n"
10575 _ASM_EXTABLE(1b, 3b)
10576 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10577 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10578 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10579 : "memory"
10580 );
10581 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10582 index eb92a6e..b98b2f4 100644
10583 --- a/arch/x86/include/asm/hw_irq.h
10584 +++ b/arch/x86/include/asm/hw_irq.h
10585 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10586 extern void enable_IO_APIC(void);
10587
10588 /* Statistics */
10589 -extern atomic_t irq_err_count;
10590 -extern atomic_t irq_mis_count;
10591 +extern atomic_unchecked_t irq_err_count;
10592 +extern atomic_unchecked_t irq_mis_count;
10593
10594 /* EISA */
10595 extern void eisa_set_level_irq(unsigned int irq);
10596 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10597 index d8e8eef..99f81ae 100644
10598 --- a/arch/x86/include/asm/io.h
10599 +++ b/arch/x86/include/asm/io.h
10600 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10601
10602 #include <linux/vmalloc.h>
10603
10604 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10605 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10606 +{
10607 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10608 +}
10609 +
10610 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10611 +{
10612 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10613 +}
10614 +
10615 /*
10616 * Convert a virtual cached pointer to an uncached pointer
10617 */
10618 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10619 index bba3cf8..06bc8da 100644
10620 --- a/arch/x86/include/asm/irqflags.h
10621 +++ b/arch/x86/include/asm/irqflags.h
10622 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10623 sti; \
10624 sysexit
10625
10626 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10627 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10628 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10629 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10630 +
10631 #else
10632 #define INTERRUPT_RETURN iret
10633 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10634 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10635 index 5478825..839e88c 100644
10636 --- a/arch/x86/include/asm/kprobes.h
10637 +++ b/arch/x86/include/asm/kprobes.h
10638 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10639 #define RELATIVEJUMP_SIZE 5
10640 #define RELATIVECALL_OPCODE 0xe8
10641 #define RELATIVE_ADDR_SIZE 4
10642 -#define MAX_STACK_SIZE 64
10643 -#define MIN_STACK_SIZE(ADDR) \
10644 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10645 - THREAD_SIZE - (unsigned long)(ADDR))) \
10646 - ? (MAX_STACK_SIZE) \
10647 - : (((unsigned long)current_thread_info()) + \
10648 - THREAD_SIZE - (unsigned long)(ADDR)))
10649 +#define MAX_STACK_SIZE 64UL
10650 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10651
10652 #define flush_insn_slot(p) do { } while (0)
10653
10654 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10655 index db7c1f2..92f130a 100644
10656 --- a/arch/x86/include/asm/kvm_host.h
10657 +++ b/arch/x86/include/asm/kvm_host.h
10658 @@ -680,7 +680,7 @@ struct kvm_x86_ops {
10659 int (*check_intercept)(struct kvm_vcpu *vcpu,
10660 struct x86_instruction_info *info,
10661 enum x86_intercept_stage stage);
10662 -};
10663 +} __do_const;
10664
10665 struct kvm_arch_async_pf {
10666 u32 token;
10667 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10668 index c8bed0d..e5721fa 100644
10669 --- a/arch/x86/include/asm/local.h
10670 +++ b/arch/x86/include/asm/local.h
10671 @@ -17,26 +17,58 @@ typedef struct {
10672
10673 static inline void local_inc(local_t *l)
10674 {
10675 - asm volatile(_ASM_INC "%0"
10676 + asm volatile(_ASM_INC "%0\n"
10677 +
10678 +#ifdef CONFIG_PAX_REFCOUNT
10679 + "jno 0f\n"
10680 + _ASM_DEC "%0\n"
10681 + "int $4\n0:\n"
10682 + _ASM_EXTABLE(0b, 0b)
10683 +#endif
10684 +
10685 : "+m" (l->a.counter));
10686 }
10687
10688 static inline void local_dec(local_t *l)
10689 {
10690 - asm volatile(_ASM_DEC "%0"
10691 + asm volatile(_ASM_DEC "%0\n"
10692 +
10693 +#ifdef CONFIG_PAX_REFCOUNT
10694 + "jno 0f\n"
10695 + _ASM_INC "%0\n"
10696 + "int $4\n0:\n"
10697 + _ASM_EXTABLE(0b, 0b)
10698 +#endif
10699 +
10700 : "+m" (l->a.counter));
10701 }
10702
10703 static inline void local_add(long i, local_t *l)
10704 {
10705 - asm volatile(_ASM_ADD "%1,%0"
10706 + asm volatile(_ASM_ADD "%1,%0\n"
10707 +
10708 +#ifdef CONFIG_PAX_REFCOUNT
10709 + "jno 0f\n"
10710 + _ASM_SUB "%1,%0\n"
10711 + "int $4\n0:\n"
10712 + _ASM_EXTABLE(0b, 0b)
10713 +#endif
10714 +
10715 : "+m" (l->a.counter)
10716 : "ir" (i));
10717 }
10718
10719 static inline void local_sub(long i, local_t *l)
10720 {
10721 - asm volatile(_ASM_SUB "%1,%0"
10722 + asm volatile(_ASM_SUB "%1,%0\n"
10723 +
10724 +#ifdef CONFIG_PAX_REFCOUNT
10725 + "jno 0f\n"
10726 + _ASM_ADD "%1,%0\n"
10727 + "int $4\n0:\n"
10728 + _ASM_EXTABLE(0b, 0b)
10729 +#endif
10730 +
10731 : "+m" (l->a.counter)
10732 : "ir" (i));
10733 }
10734 @@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10735 {
10736 unsigned char c;
10737
10738 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10739 + asm volatile(_ASM_SUB "%2,%0\n"
10740 +
10741 +#ifdef CONFIG_PAX_REFCOUNT
10742 + "jno 0f\n"
10743 + _ASM_ADD "%2,%0\n"
10744 + "int $4\n0:\n"
10745 + _ASM_EXTABLE(0b, 0b)
10746 +#endif
10747 +
10748 + "sete %1\n"
10749 : "+m" (l->a.counter), "=qm" (c)
10750 : "ir" (i) : "memory");
10751 return c;
10752 @@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10753 {
10754 unsigned char c;
10755
10756 - asm volatile(_ASM_DEC "%0; sete %1"
10757 + asm volatile(_ASM_DEC "%0\n"
10758 +
10759 +#ifdef CONFIG_PAX_REFCOUNT
10760 + "jno 0f\n"
10761 + _ASM_INC "%0\n"
10762 + "int $4\n0:\n"
10763 + _ASM_EXTABLE(0b, 0b)
10764 +#endif
10765 +
10766 + "sete %1\n"
10767 : "+m" (l->a.counter), "=qm" (c)
10768 : : "memory");
10769 return c != 0;
10770 @@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10771 {
10772 unsigned char c;
10773
10774 - asm volatile(_ASM_INC "%0; sete %1"
10775 + asm volatile(_ASM_INC "%0\n"
10776 +
10777 +#ifdef CONFIG_PAX_REFCOUNT
10778 + "jno 0f\n"
10779 + _ASM_DEC "%0\n"
10780 + "int $4\n0:\n"
10781 + _ASM_EXTABLE(0b, 0b)
10782 +#endif
10783 +
10784 + "sete %1\n"
10785 : "+m" (l->a.counter), "=qm" (c)
10786 : : "memory");
10787 return c != 0;
10788 @@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10789 {
10790 unsigned char c;
10791
10792 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10793 + asm volatile(_ASM_ADD "%2,%0\n"
10794 +
10795 +#ifdef CONFIG_PAX_REFCOUNT
10796 + "jno 0f\n"
10797 + _ASM_SUB "%2,%0\n"
10798 + "int $4\n0:\n"
10799 + _ASM_EXTABLE(0b, 0b)
10800 +#endif
10801 +
10802 + "sets %1\n"
10803 : "+m" (l->a.counter), "=qm" (c)
10804 : "ir" (i) : "memory");
10805 return c;
10806 @@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10807 #endif
10808 /* Modern 486+ processor */
10809 __i = i;
10810 - asm volatile(_ASM_XADD "%0, %1;"
10811 + asm volatile(_ASM_XADD "%0, %1\n"
10812 +
10813 +#ifdef CONFIG_PAX_REFCOUNT
10814 + "jno 0f\n"
10815 + _ASM_MOV "%0,%1\n"
10816 + "int $4\n0:\n"
10817 + _ASM_EXTABLE(0b, 0b)
10818 +#endif
10819 +
10820 : "+r" (i), "+m" (l->a.counter)
10821 : : "memory");
10822 return i + __i;
10823 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10824 index 593e51d..fa69c9a 100644
10825 --- a/arch/x86/include/asm/mman.h
10826 +++ b/arch/x86/include/asm/mman.h
10827 @@ -5,4 +5,14 @@
10828
10829 #include <asm-generic/mman.h>
10830
10831 +#ifdef __KERNEL__
10832 +#ifndef __ASSEMBLY__
10833 +#ifdef CONFIG_X86_32
10834 +#define arch_mmap_check i386_mmap_check
10835 +int i386_mmap_check(unsigned long addr, unsigned long len,
10836 + unsigned long flags);
10837 +#endif
10838 +#endif
10839 +#endif
10840 +
10841 #endif /* _ASM_X86_MMAN_H */
10842 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10843 index 5f55e69..e20bfb1 100644
10844 --- a/arch/x86/include/asm/mmu.h
10845 +++ b/arch/x86/include/asm/mmu.h
10846 @@ -9,7 +9,7 @@
10847 * we put the segment information here.
10848 */
10849 typedef struct {
10850 - void *ldt;
10851 + struct desc_struct *ldt;
10852 int size;
10853
10854 #ifdef CONFIG_X86_64
10855 @@ -18,7 +18,19 @@ typedef struct {
10856 #endif
10857
10858 struct mutex lock;
10859 - void *vdso;
10860 + unsigned long vdso;
10861 +
10862 +#ifdef CONFIG_X86_32
10863 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10864 + unsigned long user_cs_base;
10865 + unsigned long user_cs_limit;
10866 +
10867 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10868 + cpumask_t cpu_user_cs_mask;
10869 +#endif
10870 +
10871 +#endif
10872 +#endif
10873 } mm_context_t;
10874
10875 #ifdef CONFIG_SMP
10876 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10877 index cdbf367..adb37ac 100644
10878 --- a/arch/x86/include/asm/mmu_context.h
10879 +++ b/arch/x86/include/asm/mmu_context.h
10880 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10881
10882 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10883 {
10884 +
10885 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10886 + unsigned int i;
10887 + pgd_t *pgd;
10888 +
10889 + pax_open_kernel();
10890 + pgd = get_cpu_pgd(smp_processor_id());
10891 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10892 + set_pgd_batched(pgd+i, native_make_pgd(0));
10893 + pax_close_kernel();
10894 +#endif
10895 +
10896 #ifdef CONFIG_SMP
10897 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10898 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10899 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10900 struct task_struct *tsk)
10901 {
10902 unsigned cpu = smp_processor_id();
10903 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10904 + int tlbstate = TLBSTATE_OK;
10905 +#endif
10906
10907 if (likely(prev != next)) {
10908 #ifdef CONFIG_SMP
10909 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10910 + tlbstate = this_cpu_read(cpu_tlbstate.state);
10911 +#endif
10912 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10913 this_cpu_write(cpu_tlbstate.active_mm, next);
10914 #endif
10915 cpumask_set_cpu(cpu, mm_cpumask(next));
10916
10917 /* Re-load page tables */
10918 +#ifdef CONFIG_PAX_PER_CPU_PGD
10919 + pax_open_kernel();
10920 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10921 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10922 + pax_close_kernel();
10923 + load_cr3(get_cpu_pgd(cpu));
10924 +#else
10925 load_cr3(next->pgd);
10926 +#endif
10927
10928 /* stop flush ipis for the previous mm */
10929 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10930 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10931 */
10932 if (unlikely(prev->context.ldt != next->context.ldt))
10933 load_LDT_nolock(&next->context);
10934 - }
10935 +
10936 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10937 + if (!(__supported_pte_mask & _PAGE_NX)) {
10938 + smp_mb__before_clear_bit();
10939 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10940 + smp_mb__after_clear_bit();
10941 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10942 + }
10943 +#endif
10944 +
10945 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10946 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10947 + prev->context.user_cs_limit != next->context.user_cs_limit))
10948 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10949 #ifdef CONFIG_SMP
10950 + else if (unlikely(tlbstate != TLBSTATE_OK))
10951 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10952 +#endif
10953 +#endif
10954 +
10955 + }
10956 else {
10957 +
10958 +#ifdef CONFIG_PAX_PER_CPU_PGD
10959 + pax_open_kernel();
10960 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10961 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10962 + pax_close_kernel();
10963 + load_cr3(get_cpu_pgd(cpu));
10964 +#endif
10965 +
10966 +#ifdef CONFIG_SMP
10967 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10968 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
10969
10970 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10971 * tlb flush IPI delivery. We must reload CR3
10972 * to make sure to use no freed page tables.
10973 */
10974 +
10975 +#ifndef CONFIG_PAX_PER_CPU_PGD
10976 load_cr3(next->pgd);
10977 +#endif
10978 +
10979 load_LDT_nolock(&next->context);
10980 +
10981 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10982 + if (!(__supported_pte_mask & _PAGE_NX))
10983 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10984 +#endif
10985 +
10986 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10987 +#ifdef CONFIG_PAX_PAGEEXEC
10988 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10989 +#endif
10990 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10991 +#endif
10992 +
10993 }
10994 +#endif
10995 }
10996 -#endif
10997 }
10998
10999 #define activate_mm(prev, next) \
11000 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11001 index 9eae775..c914fea 100644
11002 --- a/arch/x86/include/asm/module.h
11003 +++ b/arch/x86/include/asm/module.h
11004 @@ -5,6 +5,7 @@
11005
11006 #ifdef CONFIG_X86_64
11007 /* X86_64 does not define MODULE_PROC_FAMILY */
11008 +#define MODULE_PROC_FAMILY ""
11009 #elif defined CONFIG_M386
11010 #define MODULE_PROC_FAMILY "386 "
11011 #elif defined CONFIG_M486
11012 @@ -59,8 +60,20 @@
11013 #error unknown processor family
11014 #endif
11015
11016 -#ifdef CONFIG_X86_32
11017 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11018 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11019 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11020 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11021 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11022 +#else
11023 +#define MODULE_PAX_KERNEXEC ""
11024 #endif
11025
11026 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11027 +#define MODULE_PAX_UDEREF "UDEREF "
11028 +#else
11029 +#define MODULE_PAX_UDEREF ""
11030 +#endif
11031 +
11032 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11033 +
11034 #endif /* _ASM_X86_MODULE_H */
11035 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11036 index 320f7bb..e89f8f8 100644
11037 --- a/arch/x86/include/asm/page_64_types.h
11038 +++ b/arch/x86/include/asm/page_64_types.h
11039 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11040
11041 /* duplicated to the one in bootmem.h */
11042 extern unsigned long max_pfn;
11043 -extern unsigned long phys_base;
11044 +extern const unsigned long phys_base;
11045
11046 extern unsigned long __phys_addr(unsigned long);
11047 #define __phys_reloc_hide(x) (x)
11048 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11049 index 6cbbabf..11b3aed 100644
11050 --- a/arch/x86/include/asm/paravirt.h
11051 +++ b/arch/x86/include/asm/paravirt.h
11052 @@ -668,6 +668,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11053 val);
11054 }
11055
11056 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11057 +{
11058 + pgdval_t val = native_pgd_val(pgd);
11059 +
11060 + if (sizeof(pgdval_t) > sizeof(long))
11061 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11062 + val, (u64)val >> 32);
11063 + else
11064 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11065 + val);
11066 +}
11067 +
11068 static inline void pgd_clear(pgd_t *pgdp)
11069 {
11070 set_pgd(pgdp, __pgd(0));
11071 @@ -749,6 +761,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11072 pv_mmu_ops.set_fixmap(idx, phys, flags);
11073 }
11074
11075 +#ifdef CONFIG_PAX_KERNEXEC
11076 +static inline unsigned long pax_open_kernel(void)
11077 +{
11078 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11079 +}
11080 +
11081 +static inline unsigned long pax_close_kernel(void)
11082 +{
11083 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11084 +}
11085 +#else
11086 +static inline unsigned long pax_open_kernel(void) { return 0; }
11087 +static inline unsigned long pax_close_kernel(void) { return 0; }
11088 +#endif
11089 +
11090 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11091
11092 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11093 @@ -965,7 +992,7 @@ extern void default_banner(void);
11094
11095 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11096 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11097 -#define PARA_INDIRECT(addr) *%cs:addr
11098 +#define PARA_INDIRECT(addr) *%ss:addr
11099 #endif
11100
11101 #define INTERRUPT_RETURN \
11102 @@ -1040,6 +1067,21 @@ extern void default_banner(void);
11103 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11104 CLBR_NONE, \
11105 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11106 +
11107 +#define GET_CR0_INTO_RDI \
11108 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11109 + mov %rax,%rdi
11110 +
11111 +#define SET_RDI_INTO_CR0 \
11112 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11113 +
11114 +#define GET_CR3_INTO_RDI \
11115 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11116 + mov %rax,%rdi
11117 +
11118 +#define SET_RDI_INTO_CR3 \
11119 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11120 +
11121 #endif /* CONFIG_X86_32 */
11122
11123 #endif /* __ASSEMBLY__ */
11124 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11125 index 8e8b9a4..f07d725 100644
11126 --- a/arch/x86/include/asm/paravirt_types.h
11127 +++ b/arch/x86/include/asm/paravirt_types.h
11128 @@ -84,20 +84,20 @@ struct pv_init_ops {
11129 */
11130 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11131 unsigned long addr, unsigned len);
11132 -};
11133 +} __no_const;
11134
11135
11136 struct pv_lazy_ops {
11137 /* Set deferred update mode, used for batching operations. */
11138 void (*enter)(void);
11139 void (*leave)(void);
11140 -};
11141 +} __no_const;
11142
11143 struct pv_time_ops {
11144 unsigned long long (*sched_clock)(void);
11145 unsigned long long (*steal_clock)(int cpu);
11146 unsigned long (*get_tsc_khz)(void);
11147 -};
11148 +} __no_const;
11149
11150 struct pv_cpu_ops {
11151 /* hooks for various privileged instructions */
11152 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
11153
11154 void (*start_context_switch)(struct task_struct *prev);
11155 void (*end_context_switch)(struct task_struct *next);
11156 -};
11157 +} __no_const;
11158
11159 struct pv_irq_ops {
11160 /*
11161 @@ -224,7 +224,7 @@ struct pv_apic_ops {
11162 unsigned long start_eip,
11163 unsigned long start_esp);
11164 #endif
11165 -};
11166 +} __no_const;
11167
11168 struct pv_mmu_ops {
11169 unsigned long (*read_cr2)(void);
11170 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
11171 struct paravirt_callee_save make_pud;
11172
11173 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11174 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11175 #endif /* PAGETABLE_LEVELS == 4 */
11176 #endif /* PAGETABLE_LEVELS >= 3 */
11177
11178 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
11179 an mfn. We can tell which is which from the index. */
11180 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11181 phys_addr_t phys, pgprot_t flags);
11182 +
11183 +#ifdef CONFIG_PAX_KERNEXEC
11184 + unsigned long (*pax_open_kernel)(void);
11185 + unsigned long (*pax_close_kernel)(void);
11186 +#endif
11187 +
11188 };
11189
11190 struct arch_spinlock;
11191 @@ -334,7 +341,7 @@ struct pv_lock_ops {
11192 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11193 int (*spin_trylock)(struct arch_spinlock *lock);
11194 void (*spin_unlock)(struct arch_spinlock *lock);
11195 -};
11196 +} __no_const;
11197
11198 /* This contains all the paravirt structures: we get a convenient
11199 * number for each function using the offset which we use to indicate
11200 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11201 index b4389a4..7024269 100644
11202 --- a/arch/x86/include/asm/pgalloc.h
11203 +++ b/arch/x86/include/asm/pgalloc.h
11204 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11205 pmd_t *pmd, pte_t *pte)
11206 {
11207 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11208 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11209 +}
11210 +
11211 +static inline void pmd_populate_user(struct mm_struct *mm,
11212 + pmd_t *pmd, pte_t *pte)
11213 +{
11214 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11215 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11216 }
11217
11218 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11219
11220 #ifdef CONFIG_X86_PAE
11221 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11222 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11223 +{
11224 + pud_populate(mm, pudp, pmd);
11225 +}
11226 #else /* !CONFIG_X86_PAE */
11227 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11228 {
11229 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11230 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11231 }
11232 +
11233 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11234 +{
11235 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11236 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11237 +}
11238 #endif /* CONFIG_X86_PAE */
11239
11240 #if PAGETABLE_LEVELS > 3
11241 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11242 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11243 }
11244
11245 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11246 +{
11247 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11248 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11249 +}
11250 +
11251 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11252 {
11253 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11254 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11255 index 98391db..8f6984e 100644
11256 --- a/arch/x86/include/asm/pgtable-2level.h
11257 +++ b/arch/x86/include/asm/pgtable-2level.h
11258 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11259
11260 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11261 {
11262 + pax_open_kernel();
11263 *pmdp = pmd;
11264 + pax_close_kernel();
11265 }
11266
11267 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11268 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11269 index cb00ccc..17e9054 100644
11270 --- a/arch/x86/include/asm/pgtable-3level.h
11271 +++ b/arch/x86/include/asm/pgtable-3level.h
11272 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11273
11274 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11275 {
11276 + pax_open_kernel();
11277 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11278 + pax_close_kernel();
11279 }
11280
11281 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11282 {
11283 + pax_open_kernel();
11284 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11285 + pax_close_kernel();
11286 }
11287
11288 /*
11289 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11290 index 49afb3f..91a8c63 100644
11291 --- a/arch/x86/include/asm/pgtable.h
11292 +++ b/arch/x86/include/asm/pgtable.h
11293 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11294
11295 #ifndef __PAGETABLE_PUD_FOLDED
11296 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11297 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11298 #define pgd_clear(pgd) native_pgd_clear(pgd)
11299 #endif
11300
11301 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11302
11303 #define arch_end_context_switch(prev) do {} while(0)
11304
11305 +#define pax_open_kernel() native_pax_open_kernel()
11306 +#define pax_close_kernel() native_pax_close_kernel()
11307 #endif /* CONFIG_PARAVIRT */
11308
11309 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11310 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11311 +
11312 +#ifdef CONFIG_PAX_KERNEXEC
11313 +static inline unsigned long native_pax_open_kernel(void)
11314 +{
11315 + unsigned long cr0;
11316 +
11317 + preempt_disable();
11318 + barrier();
11319 + cr0 = read_cr0() ^ X86_CR0_WP;
11320 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11321 + write_cr0(cr0);
11322 + return cr0 ^ X86_CR0_WP;
11323 +}
11324 +
11325 +static inline unsigned long native_pax_close_kernel(void)
11326 +{
11327 + unsigned long cr0;
11328 +
11329 + cr0 = read_cr0() ^ X86_CR0_WP;
11330 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11331 + write_cr0(cr0);
11332 + barrier();
11333 + preempt_enable_no_resched();
11334 + return cr0 ^ X86_CR0_WP;
11335 +}
11336 +#else
11337 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11338 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11339 +#endif
11340 +
11341 /*
11342 * The following only work if pte_present() is true.
11343 * Undefined behaviour if not..
11344 */
11345 +static inline int pte_user(pte_t pte)
11346 +{
11347 + return pte_val(pte) & _PAGE_USER;
11348 +}
11349 +
11350 static inline int pte_dirty(pte_t pte)
11351 {
11352 return pte_flags(pte) & _PAGE_DIRTY;
11353 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11354 return pte_clear_flags(pte, _PAGE_RW);
11355 }
11356
11357 +static inline pte_t pte_mkread(pte_t pte)
11358 +{
11359 + return __pte(pte_val(pte) | _PAGE_USER);
11360 +}
11361 +
11362 static inline pte_t pte_mkexec(pte_t pte)
11363 {
11364 - return pte_clear_flags(pte, _PAGE_NX);
11365 +#ifdef CONFIG_X86_PAE
11366 + if (__supported_pte_mask & _PAGE_NX)
11367 + return pte_clear_flags(pte, _PAGE_NX);
11368 + else
11369 +#endif
11370 + return pte_set_flags(pte, _PAGE_USER);
11371 +}
11372 +
11373 +static inline pte_t pte_exprotect(pte_t pte)
11374 +{
11375 +#ifdef CONFIG_X86_PAE
11376 + if (__supported_pte_mask & _PAGE_NX)
11377 + return pte_set_flags(pte, _PAGE_NX);
11378 + else
11379 +#endif
11380 + return pte_clear_flags(pte, _PAGE_USER);
11381 }
11382
11383 static inline pte_t pte_mkdirty(pte_t pte)
11384 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11385 #endif
11386
11387 #ifndef __ASSEMBLY__
11388 +
11389 +#ifdef CONFIG_PAX_PER_CPU_PGD
11390 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11391 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11392 +{
11393 + return cpu_pgd[cpu];
11394 +}
11395 +#endif
11396 +
11397 #include <linux/mm_types.h>
11398
11399 static inline int pte_none(pte_t pte)
11400 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11401
11402 static inline int pgd_bad(pgd_t pgd)
11403 {
11404 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11405 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11406 }
11407
11408 static inline int pgd_none(pgd_t pgd)
11409 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11410 * pgd_offset() returns a (pgd_t *)
11411 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11412 */
11413 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11414 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11415 +
11416 +#ifdef CONFIG_PAX_PER_CPU_PGD
11417 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11418 +#endif
11419 +
11420 /*
11421 * a shortcut which implies the use of the kernel's pgd, instead
11422 * of a process's
11423 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11424 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11425 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11426
11427 +#ifdef CONFIG_X86_32
11428 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11429 +#else
11430 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11431 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11432 +
11433 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11434 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11435 +#else
11436 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11437 +#endif
11438 +
11439 +#endif
11440 +
11441 #ifndef __ASSEMBLY__
11442
11443 extern int direct_gbpages;
11444 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11445 * dst and src can be on the same page, but the range must not overlap,
11446 * and must not cross a page boundary.
11447 */
11448 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11449 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11450 {
11451 - memcpy(dst, src, count * sizeof(pgd_t));
11452 + pax_open_kernel();
11453 + while (count--)
11454 + *dst++ = *src++;
11455 + pax_close_kernel();
11456 }
11457
11458 +#ifdef CONFIG_PAX_PER_CPU_PGD
11459 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11460 +#endif
11461 +
11462 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11463 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11464 +#else
11465 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11466 +#endif
11467
11468 #include <asm-generic/pgtable.h>
11469 #endif /* __ASSEMBLY__ */
11470 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11471 index 0c92113..34a77c6 100644
11472 --- a/arch/x86/include/asm/pgtable_32.h
11473 +++ b/arch/x86/include/asm/pgtable_32.h
11474 @@ -25,9 +25,6 @@
11475 struct mm_struct;
11476 struct vm_area_struct;
11477
11478 -extern pgd_t swapper_pg_dir[1024];
11479 -extern pgd_t initial_page_table[1024];
11480 -
11481 static inline void pgtable_cache_init(void) { }
11482 static inline void check_pgt_cache(void) { }
11483 void paging_init(void);
11484 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11485 # include <asm/pgtable-2level.h>
11486 #endif
11487
11488 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11489 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11490 +#ifdef CONFIG_X86_PAE
11491 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11492 +#endif
11493 +
11494 #if defined(CONFIG_HIGHPTE)
11495 #define pte_offset_map(dir, address) \
11496 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11497 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11498 /* Clear a kernel PTE and flush it from the TLB */
11499 #define kpte_clear_flush(ptep, vaddr) \
11500 do { \
11501 + pax_open_kernel(); \
11502 pte_clear(&init_mm, (vaddr), (ptep)); \
11503 + pax_close_kernel(); \
11504 __flush_tlb_one((vaddr)); \
11505 } while (0)
11506
11507 @@ -74,6 +79,9 @@ do { \
11508
11509 #endif /* !__ASSEMBLY__ */
11510
11511 +#define HAVE_ARCH_UNMAPPED_AREA
11512 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11513 +
11514 /*
11515 * kern_addr_valid() is (1) for FLATMEM and (0) for
11516 * SPARSEMEM and DISCONTIGMEM
11517 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11518 index ed5903b..c7fe163 100644
11519 --- a/arch/x86/include/asm/pgtable_32_types.h
11520 +++ b/arch/x86/include/asm/pgtable_32_types.h
11521 @@ -8,7 +8,7 @@
11522 */
11523 #ifdef CONFIG_X86_PAE
11524 # include <asm/pgtable-3level_types.h>
11525 -# define PMD_SIZE (1UL << PMD_SHIFT)
11526 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11527 # define PMD_MASK (~(PMD_SIZE - 1))
11528 #else
11529 # include <asm/pgtable-2level_types.h>
11530 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11531 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11532 #endif
11533
11534 +#ifdef CONFIG_PAX_KERNEXEC
11535 +#ifndef __ASSEMBLY__
11536 +extern unsigned char MODULES_EXEC_VADDR[];
11537 +extern unsigned char MODULES_EXEC_END[];
11538 +#endif
11539 +#include <asm/boot.h>
11540 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11541 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11542 +#else
11543 +#define ktla_ktva(addr) (addr)
11544 +#define ktva_ktla(addr) (addr)
11545 +#endif
11546 +
11547 #define MODULES_VADDR VMALLOC_START
11548 #define MODULES_END VMALLOC_END
11549 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11550 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11551 index 975f709..9f779c9 100644
11552 --- a/arch/x86/include/asm/pgtable_64.h
11553 +++ b/arch/x86/include/asm/pgtable_64.h
11554 @@ -16,10 +16,14 @@
11555
11556 extern pud_t level3_kernel_pgt[512];
11557 extern pud_t level3_ident_pgt[512];
11558 +extern pud_t level3_vmalloc_start_pgt[512];
11559 +extern pud_t level3_vmalloc_end_pgt[512];
11560 +extern pud_t level3_vmemmap_pgt[512];
11561 +extern pud_t level2_vmemmap_pgt[512];
11562 extern pmd_t level2_kernel_pgt[512];
11563 extern pmd_t level2_fixmap_pgt[512];
11564 -extern pmd_t level2_ident_pgt[512];
11565 -extern pgd_t init_level4_pgt[];
11566 +extern pmd_t level2_ident_pgt[512*2];
11567 +extern pgd_t init_level4_pgt[512];
11568
11569 #define swapper_pg_dir init_level4_pgt
11570
11571 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11572
11573 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11574 {
11575 + pax_open_kernel();
11576 *pmdp = pmd;
11577 + pax_close_kernel();
11578 }
11579
11580 static inline void native_pmd_clear(pmd_t *pmd)
11581 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11582
11583 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11584 {
11585 + pax_open_kernel();
11586 *pudp = pud;
11587 + pax_close_kernel();
11588 }
11589
11590 static inline void native_pud_clear(pud_t *pud)
11591 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11592
11593 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11594 {
11595 + pax_open_kernel();
11596 + *pgdp = pgd;
11597 + pax_close_kernel();
11598 +}
11599 +
11600 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11601 +{
11602 *pgdp = pgd;
11603 }
11604
11605 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11606 index 766ea16..5b96cb3 100644
11607 --- a/arch/x86/include/asm/pgtable_64_types.h
11608 +++ b/arch/x86/include/asm/pgtable_64_types.h
11609 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11610 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11611 #define MODULES_END _AC(0xffffffffff000000, UL)
11612 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11613 +#define MODULES_EXEC_VADDR MODULES_VADDR
11614 +#define MODULES_EXEC_END MODULES_END
11615 +
11616 +#define ktla_ktva(addr) (addr)
11617 +#define ktva_ktla(addr) (addr)
11618
11619 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11620 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11621 index 013286a..8b42f4f 100644
11622 --- a/arch/x86/include/asm/pgtable_types.h
11623 +++ b/arch/x86/include/asm/pgtable_types.h
11624 @@ -16,13 +16,12 @@
11625 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11626 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11627 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11628 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11629 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11630 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11631 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11632 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11633 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11634 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11635 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11636 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11637 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11638 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11639
11640 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11641 @@ -40,7 +39,6 @@
11642 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11643 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11644 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11645 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11646 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11647 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11648 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11649 @@ -57,8 +55,10 @@
11650
11651 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11652 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11653 -#else
11654 +#elif defined(CONFIG_KMEMCHECK)
11655 #define _PAGE_NX (_AT(pteval_t, 0))
11656 +#else
11657 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11658 #endif
11659
11660 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11661 @@ -96,6 +96,9 @@
11662 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11663 _PAGE_ACCESSED)
11664
11665 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11666 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11667 +
11668 #define __PAGE_KERNEL_EXEC \
11669 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11670 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11671 @@ -106,7 +109,7 @@
11672 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11673 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11674 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11675 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11676 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11677 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11678 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11679 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11680 @@ -168,8 +171,8 @@
11681 * bits are combined, this will alow user to access the high address mapped
11682 * VDSO in the presence of CONFIG_COMPAT_VDSO
11683 */
11684 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11685 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11686 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11687 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11688 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11689 #endif
11690
11691 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11692 {
11693 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11694 }
11695 +#endif
11696
11697 +#if PAGETABLE_LEVELS == 3
11698 +#include <asm-generic/pgtable-nopud.h>
11699 +#endif
11700 +
11701 +#if PAGETABLE_LEVELS == 2
11702 +#include <asm-generic/pgtable-nopmd.h>
11703 +#endif
11704 +
11705 +#ifndef __ASSEMBLY__
11706 #if PAGETABLE_LEVELS > 3
11707 typedef struct { pudval_t pud; } pud_t;
11708
11709 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11710 return pud.pud;
11711 }
11712 #else
11713 -#include <asm-generic/pgtable-nopud.h>
11714 -
11715 static inline pudval_t native_pud_val(pud_t pud)
11716 {
11717 return native_pgd_val(pud.pgd);
11718 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11719 return pmd.pmd;
11720 }
11721 #else
11722 -#include <asm-generic/pgtable-nopmd.h>
11723 -
11724 static inline pmdval_t native_pmd_val(pmd_t pmd)
11725 {
11726 return native_pgd_val(pmd.pud.pgd);
11727 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11728
11729 extern pteval_t __supported_pte_mask;
11730 extern void set_nx(void);
11731 -extern int nx_enabled;
11732
11733 #define pgprot_writecombine pgprot_writecombine
11734 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11735 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11736 index 39bc577..538233f 100644
11737 --- a/arch/x86/include/asm/processor.h
11738 +++ b/arch/x86/include/asm/processor.h
11739 @@ -276,7 +276,7 @@ struct tss_struct {
11740
11741 } ____cacheline_aligned;
11742
11743 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11744 +extern struct tss_struct init_tss[NR_CPUS];
11745
11746 /*
11747 * Save the original ist values for checking stack pointers during debugging
11748 @@ -809,11 +809,18 @@ static inline void spin_lock_prefetch(const void *x)
11749 */
11750 #define TASK_SIZE PAGE_OFFSET
11751 #define TASK_SIZE_MAX TASK_SIZE
11752 +
11753 +#ifdef CONFIG_PAX_SEGMEXEC
11754 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11755 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11756 +#else
11757 #define STACK_TOP TASK_SIZE
11758 -#define STACK_TOP_MAX STACK_TOP
11759 +#endif
11760 +
11761 +#define STACK_TOP_MAX TASK_SIZE
11762
11763 #define INIT_THREAD { \
11764 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11765 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11766 .vm86_info = NULL, \
11767 .sysenter_cs = __KERNEL_CS, \
11768 .io_bitmap_ptr = NULL, \
11769 @@ -827,7 +834,7 @@ static inline void spin_lock_prefetch(const void *x)
11770 */
11771 #define INIT_TSS { \
11772 .x86_tss = { \
11773 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11774 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11775 .ss0 = __KERNEL_DS, \
11776 .ss1 = __KERNEL_CS, \
11777 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11778 @@ -838,11 +845,7 @@ static inline void spin_lock_prefetch(const void *x)
11779 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11780
11781 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11782 -#define KSTK_TOP(info) \
11783 -({ \
11784 - unsigned long *__ptr = (unsigned long *)(info); \
11785 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11786 -})
11787 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11788
11789 /*
11790 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11791 @@ -857,7 +860,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11792 #define task_pt_regs(task) \
11793 ({ \
11794 struct pt_regs *__regs__; \
11795 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11796 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11797 __regs__ - 1; \
11798 })
11799
11800 @@ -867,13 +870,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11801 /*
11802 * User space process size. 47bits minus one guard page.
11803 */
11804 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11805 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11806
11807 /* This decides where the kernel will search for a free chunk of vm
11808 * space during mmap's.
11809 */
11810 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11811 - 0xc0000000 : 0xFFFFe000)
11812 + 0xc0000000 : 0xFFFFf000)
11813
11814 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11815 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11816 @@ -884,11 +887,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11817 #define STACK_TOP_MAX TASK_SIZE_MAX
11818
11819 #define INIT_THREAD { \
11820 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11821 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11822 }
11823
11824 #define INIT_TSS { \
11825 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11826 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11827 }
11828
11829 /*
11830 @@ -916,6 +919,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11831 */
11832 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11833
11834 +#ifdef CONFIG_PAX_SEGMEXEC
11835 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11836 +#endif
11837 +
11838 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11839
11840 /* Get/set a process' ability to use the timestamp counter instruction */
11841 @@ -976,12 +983,12 @@ extern bool cpu_has_amd_erratum(const int *);
11842 #define cpu_has_amd_erratum(x) (false)
11843 #endif /* CONFIG_CPU_SUP_AMD */
11844
11845 -extern unsigned long arch_align_stack(unsigned long sp);
11846 +#define arch_align_stack(x) ((x) & ~0xfUL)
11847 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11848
11849 void default_idle(void);
11850 bool set_pm_idle_to_default(void);
11851
11852 -void stop_this_cpu(void *dummy);
11853 +void stop_this_cpu(void *dummy) __noreturn;
11854
11855 #endif /* _ASM_X86_PROCESSOR_H */
11856 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11857 index dcfde52..dbfea06 100644
11858 --- a/arch/x86/include/asm/ptrace.h
11859 +++ b/arch/x86/include/asm/ptrace.h
11860 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11861 }
11862
11863 /*
11864 - * user_mode_vm(regs) determines whether a register set came from user mode.
11865 + * user_mode(regs) determines whether a register set came from user mode.
11866 * This is true if V8086 mode was enabled OR if the register set was from
11867 * protected mode with RPL-3 CS value. This tricky test checks that with
11868 * one comparison. Many places in the kernel can bypass this full check
11869 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11870 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11871 + * be used.
11872 */
11873 -static inline int user_mode(struct pt_regs *regs)
11874 +static inline int user_mode_novm(struct pt_regs *regs)
11875 {
11876 #ifdef CONFIG_X86_32
11877 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11878 #else
11879 - return !!(regs->cs & 3);
11880 + return !!(regs->cs & SEGMENT_RPL_MASK);
11881 #endif
11882 }
11883
11884 -static inline int user_mode_vm(struct pt_regs *regs)
11885 +static inline int user_mode(struct pt_regs *regs)
11886 {
11887 #ifdef CONFIG_X86_32
11888 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11889 USER_RPL;
11890 #else
11891 - return user_mode(regs);
11892 + return user_mode_novm(regs);
11893 #endif
11894 }
11895
11896 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11897 #ifdef CONFIG_X86_64
11898 static inline bool user_64bit_mode(struct pt_regs *regs)
11899 {
11900 + unsigned long cs = regs->cs & 0xffff;
11901 #ifndef CONFIG_PARAVIRT
11902 /*
11903 * On non-paravirt systems, this is the only long mode CPL 3
11904 * selector. We do not allow long mode selectors in the LDT.
11905 */
11906 - return regs->cs == __USER_CS;
11907 + return cs == __USER_CS;
11908 #else
11909 /* Headers are too twisted for this to go in paravirt.h. */
11910 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11911 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11912 #endif
11913 }
11914 #endif
11915 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
11916 index fce3f4a..3f69f2a 100644
11917 --- a/arch/x86/include/asm/realmode.h
11918 +++ b/arch/x86/include/asm/realmode.h
11919 @@ -30,7 +30,7 @@ struct real_mode_header {
11920 struct trampoline_header {
11921 #ifdef CONFIG_X86_32
11922 u32 start;
11923 - u16 gdt_pad;
11924 + u16 boot_cs;
11925 u16 gdt_limit;
11926 u32 gdt_base;
11927 #else
11928 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11929 index 92f29706..a79cbbb 100644
11930 --- a/arch/x86/include/asm/reboot.h
11931 +++ b/arch/x86/include/asm/reboot.h
11932 @@ -6,19 +6,19 @@
11933 struct pt_regs;
11934
11935 struct machine_ops {
11936 - void (*restart)(char *cmd);
11937 - void (*halt)(void);
11938 - void (*power_off)(void);
11939 + void (* __noreturn restart)(char *cmd);
11940 + void (* __noreturn halt)(void);
11941 + void (* __noreturn power_off)(void);
11942 void (*shutdown)(void);
11943 void (*crash_shutdown)(struct pt_regs *);
11944 - void (*emergency_restart)(void);
11945 -};
11946 + void (* __noreturn emergency_restart)(void);
11947 +} __no_const;
11948
11949 extern struct machine_ops machine_ops;
11950
11951 void native_machine_crash_shutdown(struct pt_regs *regs);
11952 void native_machine_shutdown(void);
11953 -void machine_real_restart(unsigned int type);
11954 +void machine_real_restart(unsigned int type) __noreturn;
11955 /* These must match dispatch_table in reboot_32.S */
11956 #define MRR_BIOS 0
11957 #define MRR_APM 1
11958 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11959 index 2dbe4a7..ce1db00 100644
11960 --- a/arch/x86/include/asm/rwsem.h
11961 +++ b/arch/x86/include/asm/rwsem.h
11962 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11963 {
11964 asm volatile("# beginning down_read\n\t"
11965 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11966 +
11967 +#ifdef CONFIG_PAX_REFCOUNT
11968 + "jno 0f\n"
11969 + LOCK_PREFIX _ASM_DEC "(%1)\n"
11970 + "int $4\n0:\n"
11971 + _ASM_EXTABLE(0b, 0b)
11972 +#endif
11973 +
11974 /* adds 0x00000001 */
11975 " jns 1f\n"
11976 " call call_rwsem_down_read_failed\n"
11977 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11978 "1:\n\t"
11979 " mov %1,%2\n\t"
11980 " add %3,%2\n\t"
11981 +
11982 +#ifdef CONFIG_PAX_REFCOUNT
11983 + "jno 0f\n"
11984 + "sub %3,%2\n"
11985 + "int $4\n0:\n"
11986 + _ASM_EXTABLE(0b, 0b)
11987 +#endif
11988 +
11989 " jle 2f\n\t"
11990 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11991 " jnz 1b\n\t"
11992 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
11993 long tmp;
11994 asm volatile("# beginning down_write\n\t"
11995 LOCK_PREFIX " xadd %1,(%2)\n\t"
11996 +
11997 +#ifdef CONFIG_PAX_REFCOUNT
11998 + "jno 0f\n"
11999 + "mov %1,(%2)\n"
12000 + "int $4\n0:\n"
12001 + _ASM_EXTABLE(0b, 0b)
12002 +#endif
12003 +
12004 /* adds 0xffff0001, returns the old value */
12005 " test %1,%1\n\t"
12006 /* was the count 0 before? */
12007 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12008 long tmp;
12009 asm volatile("# beginning __up_read\n\t"
12010 LOCK_PREFIX " xadd %1,(%2)\n\t"
12011 +
12012 +#ifdef CONFIG_PAX_REFCOUNT
12013 + "jno 0f\n"
12014 + "mov %1,(%2)\n"
12015 + "int $4\n0:\n"
12016 + _ASM_EXTABLE(0b, 0b)
12017 +#endif
12018 +
12019 /* subtracts 1, returns the old value */
12020 " jns 1f\n\t"
12021 " call call_rwsem_wake\n" /* expects old value in %edx */
12022 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12023 long tmp;
12024 asm volatile("# beginning __up_write\n\t"
12025 LOCK_PREFIX " xadd %1,(%2)\n\t"
12026 +
12027 +#ifdef CONFIG_PAX_REFCOUNT
12028 + "jno 0f\n"
12029 + "mov %1,(%2)\n"
12030 + "int $4\n0:\n"
12031 + _ASM_EXTABLE(0b, 0b)
12032 +#endif
12033 +
12034 /* subtracts 0xffff0001, returns the old value */
12035 " jns 1f\n\t"
12036 " call call_rwsem_wake\n" /* expects old value in %edx */
12037 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12038 {
12039 asm volatile("# beginning __downgrade_write\n\t"
12040 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12041 +
12042 +#ifdef CONFIG_PAX_REFCOUNT
12043 + "jno 0f\n"
12044 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12045 + "int $4\n0:\n"
12046 + _ASM_EXTABLE(0b, 0b)
12047 +#endif
12048 +
12049 /*
12050 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12051 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12052 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12053 */
12054 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12055 {
12056 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12057 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12058 +
12059 +#ifdef CONFIG_PAX_REFCOUNT
12060 + "jno 0f\n"
12061 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12062 + "int $4\n0:\n"
12063 + _ASM_EXTABLE(0b, 0b)
12064 +#endif
12065 +
12066 : "+m" (sem->count)
12067 : "er" (delta));
12068 }
12069 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12070 */
12071 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12072 {
12073 - return delta + xadd(&sem->count, delta);
12074 + return delta + xadd_check_overflow(&sem->count, delta);
12075 }
12076
12077 #endif /* __KERNEL__ */
12078 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12079 index c48a950..c6d7468 100644
12080 --- a/arch/x86/include/asm/segment.h
12081 +++ b/arch/x86/include/asm/segment.h
12082 @@ -64,10 +64,15 @@
12083 * 26 - ESPFIX small SS
12084 * 27 - per-cpu [ offset to per-cpu data area ]
12085 * 28 - stack_canary-20 [ for stack protector ]
12086 - * 29 - unused
12087 - * 30 - unused
12088 + * 29 - PCI BIOS CS
12089 + * 30 - PCI BIOS DS
12090 * 31 - TSS for double fault handler
12091 */
12092 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12093 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12094 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12095 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12096 +
12097 #define GDT_ENTRY_TLS_MIN 6
12098 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12099
12100 @@ -79,6 +84,8 @@
12101
12102 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12103
12104 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12105 +
12106 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12107
12108 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12109 @@ -104,6 +111,12 @@
12110 #define __KERNEL_STACK_CANARY 0
12111 #endif
12112
12113 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12114 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12115 +
12116 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12117 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12118 +
12119 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12120
12121 /*
12122 @@ -141,7 +154,7 @@
12123 */
12124
12125 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12126 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12127 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12128
12129
12130 #else
12131 @@ -165,6 +178,8 @@
12132 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12133 #define __USER32_DS __USER_DS
12134
12135 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12136 +
12137 #define GDT_ENTRY_TSS 8 /* needs two entries */
12138 #define GDT_ENTRY_LDT 10 /* needs two entries */
12139 #define GDT_ENTRY_TLS_MIN 12
12140 @@ -185,6 +200,7 @@
12141 #endif
12142
12143 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12144 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12145 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12146 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12147 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12148 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12149 {
12150 unsigned long __limit;
12151 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12152 - return __limit + 1;
12153 + return __limit;
12154 }
12155
12156 #endif /* !__ASSEMBLY__ */
12157 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12158 index f483945..64a7851 100644
12159 --- a/arch/x86/include/asm/smp.h
12160 +++ b/arch/x86/include/asm/smp.h
12161 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12162 /* cpus sharing the last level cache: */
12163 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12164 DECLARE_PER_CPU(u16, cpu_llc_id);
12165 -DECLARE_PER_CPU(int, cpu_number);
12166 +DECLARE_PER_CPU(unsigned int, cpu_number);
12167
12168 static inline struct cpumask *cpu_sibling_mask(int cpu)
12169 {
12170 @@ -79,7 +79,7 @@ struct smp_ops {
12171
12172 void (*send_call_func_ipi)(const struct cpumask *mask);
12173 void (*send_call_func_single_ipi)(int cpu);
12174 -};
12175 +} __no_const;
12176
12177 /* Globals due to paravirt */
12178 extern void set_cpu_sibling_map(int cpu);
12179 @@ -195,14 +195,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12180 extern int safe_smp_processor_id(void);
12181
12182 #elif defined(CONFIG_X86_64_SMP)
12183 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12184 -
12185 -#define stack_smp_processor_id() \
12186 -({ \
12187 - struct thread_info *ti; \
12188 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12189 - ti->cpu; \
12190 -})
12191 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12192 +#define stack_smp_processor_id() raw_smp_processor_id()
12193 #define safe_smp_processor_id() smp_processor_id()
12194
12195 #endif
12196 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12197 index b315a33..8849ab0 100644
12198 --- a/arch/x86/include/asm/spinlock.h
12199 +++ b/arch/x86/include/asm/spinlock.h
12200 @@ -173,6 +173,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12201 static inline void arch_read_lock(arch_rwlock_t *rw)
12202 {
12203 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12204 +
12205 +#ifdef CONFIG_PAX_REFCOUNT
12206 + "jno 0f\n"
12207 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12208 + "int $4\n0:\n"
12209 + _ASM_EXTABLE(0b, 0b)
12210 +#endif
12211 +
12212 "jns 1f\n"
12213 "call __read_lock_failed\n\t"
12214 "1:\n"
12215 @@ -182,6 +190,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12216 static inline void arch_write_lock(arch_rwlock_t *rw)
12217 {
12218 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12219 +
12220 +#ifdef CONFIG_PAX_REFCOUNT
12221 + "jno 0f\n"
12222 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12223 + "int $4\n0:\n"
12224 + _ASM_EXTABLE(0b, 0b)
12225 +#endif
12226 +
12227 "jz 1f\n"
12228 "call __write_lock_failed\n\t"
12229 "1:\n"
12230 @@ -211,13 +227,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12231
12232 static inline void arch_read_unlock(arch_rwlock_t *rw)
12233 {
12234 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12235 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12236 +
12237 +#ifdef CONFIG_PAX_REFCOUNT
12238 + "jno 0f\n"
12239 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12240 + "int $4\n0:\n"
12241 + _ASM_EXTABLE(0b, 0b)
12242 +#endif
12243 +
12244 :"+m" (rw->lock) : : "memory");
12245 }
12246
12247 static inline void arch_write_unlock(arch_rwlock_t *rw)
12248 {
12249 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12250 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12251 +
12252 +#ifdef CONFIG_PAX_REFCOUNT
12253 + "jno 0f\n"
12254 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12255 + "int $4\n0:\n"
12256 + _ASM_EXTABLE(0b, 0b)
12257 +#endif
12258 +
12259 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12260 }
12261
12262 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12263 index 6a99859..03cb807 100644
12264 --- a/arch/x86/include/asm/stackprotector.h
12265 +++ b/arch/x86/include/asm/stackprotector.h
12266 @@ -47,7 +47,7 @@
12267 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12268 */
12269 #define GDT_STACK_CANARY_INIT \
12270 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12271 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12272
12273 /*
12274 * Initialize the stackprotector canary value.
12275 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12276
12277 static inline void load_stack_canary_segment(void)
12278 {
12279 -#ifdef CONFIG_X86_32
12280 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12281 asm volatile ("mov %0, %%gs" : : "r" (0));
12282 #endif
12283 }
12284 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12285 index 70bbe39..4ae2bd4 100644
12286 --- a/arch/x86/include/asm/stacktrace.h
12287 +++ b/arch/x86/include/asm/stacktrace.h
12288 @@ -11,28 +11,20 @@
12289
12290 extern int kstack_depth_to_print;
12291
12292 -struct thread_info;
12293 +struct task_struct;
12294 struct stacktrace_ops;
12295
12296 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12297 - unsigned long *stack,
12298 - unsigned long bp,
12299 - const struct stacktrace_ops *ops,
12300 - void *data,
12301 - unsigned long *end,
12302 - int *graph);
12303 +typedef unsigned long walk_stack_t(struct task_struct *task,
12304 + void *stack_start,
12305 + unsigned long *stack,
12306 + unsigned long bp,
12307 + const struct stacktrace_ops *ops,
12308 + void *data,
12309 + unsigned long *end,
12310 + int *graph);
12311
12312 -extern unsigned long
12313 -print_context_stack(struct thread_info *tinfo,
12314 - unsigned long *stack, unsigned long bp,
12315 - const struct stacktrace_ops *ops, void *data,
12316 - unsigned long *end, int *graph);
12317 -
12318 -extern unsigned long
12319 -print_context_stack_bp(struct thread_info *tinfo,
12320 - unsigned long *stack, unsigned long bp,
12321 - const struct stacktrace_ops *ops, void *data,
12322 - unsigned long *end, int *graph);
12323 +extern walk_stack_t print_context_stack;
12324 +extern walk_stack_t print_context_stack_bp;
12325
12326 /* Generic stack tracer with callbacks */
12327
12328 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12329 void (*address)(void *data, unsigned long address, int reliable);
12330 /* On negative return stop dumping */
12331 int (*stack)(void *data, char *name);
12332 - walk_stack_t walk_stack;
12333 + walk_stack_t *walk_stack;
12334 };
12335
12336 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12337 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12338 index 4ec45b3..a4f0a8a 100644
12339 --- a/arch/x86/include/asm/switch_to.h
12340 +++ b/arch/x86/include/asm/switch_to.h
12341 @@ -108,7 +108,7 @@ do { \
12342 "call __switch_to\n\t" \
12343 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12344 __switch_canary \
12345 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12346 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12347 "movq %%rax,%%rdi\n\t" \
12348 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12349 "jnz ret_from_fork\n\t" \
12350 @@ -119,7 +119,7 @@ do { \
12351 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12352 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12353 [_tif_fork] "i" (_TIF_FORK), \
12354 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12355 + [thread_info] "m" (current_tinfo), \
12356 [current_task] "m" (current_task) \
12357 __switch_canary_iparam \
12358 : "memory", "cc" __EXTRA_CLOBBER)
12359 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12360 index 3fda9db4..4ca1c61 100644
12361 --- a/arch/x86/include/asm/sys_ia32.h
12362 +++ b/arch/x86/include/asm/sys_ia32.h
12363 @@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12364 struct old_sigaction32 __user *);
12365 asmlinkage long sys32_alarm(unsigned int);
12366
12367 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12368 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12369 asmlinkage long sys32_sysfs(int, u32, u32);
12370
12371 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12372 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12373 index 89f794f..1422765 100644
12374 --- a/arch/x86/include/asm/thread_info.h
12375 +++ b/arch/x86/include/asm/thread_info.h
12376 @@ -10,6 +10,7 @@
12377 #include <linux/compiler.h>
12378 #include <asm/page.h>
12379 #include <asm/types.h>
12380 +#include <asm/percpu.h>
12381
12382 /*
12383 * low level task data that entry.S needs immediate access to
12384 @@ -24,7 +25,6 @@ struct exec_domain;
12385 #include <linux/atomic.h>
12386
12387 struct thread_info {
12388 - struct task_struct *task; /* main task structure */
12389 struct exec_domain *exec_domain; /* execution domain */
12390 __u32 flags; /* low level flags */
12391 __u32 status; /* thread synchronous flags */
12392 @@ -34,19 +34,13 @@ struct thread_info {
12393 mm_segment_t addr_limit;
12394 struct restart_block restart_block;
12395 void __user *sysenter_return;
12396 -#ifdef CONFIG_X86_32
12397 - unsigned long previous_esp; /* ESP of the previous stack in
12398 - case of nested (IRQ) stacks
12399 - */
12400 - __u8 supervisor_stack[0];
12401 -#endif
12402 + unsigned long lowest_stack;
12403 unsigned int sig_on_uaccess_error:1;
12404 unsigned int uaccess_err:1; /* uaccess failed */
12405 };
12406
12407 -#define INIT_THREAD_INFO(tsk) \
12408 +#define INIT_THREAD_INFO \
12409 { \
12410 - .task = &tsk, \
12411 .exec_domain = &default_exec_domain, \
12412 .flags = 0, \
12413 .cpu = 0, \
12414 @@ -57,7 +51,7 @@ struct thread_info {
12415 }, \
12416 }
12417
12418 -#define init_thread_info (init_thread_union.thread_info)
12419 +#define init_thread_info (init_thread_union.stack)
12420 #define init_stack (init_thread_union.stack)
12421
12422 #else /* !__ASSEMBLY__ */
12423 @@ -98,6 +92,7 @@ struct thread_info {
12424 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12425 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12426 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12427 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12428
12429 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12430 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12431 @@ -122,16 +117,18 @@ struct thread_info {
12432 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12433 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12434 #define _TIF_X32 (1 << TIF_X32)
12435 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12436
12437 /* work to do in syscall_trace_enter() */
12438 #define _TIF_WORK_SYSCALL_ENTRY \
12439 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12440 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12441 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12442 + _TIF_GRSEC_SETXID)
12443
12444 /* work to do in syscall_trace_leave() */
12445 #define _TIF_WORK_SYSCALL_EXIT \
12446 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12447 - _TIF_SYSCALL_TRACEPOINT)
12448 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12449
12450 /* work to do on interrupt/exception return */
12451 #define _TIF_WORK_MASK \
12452 @@ -141,7 +138,8 @@ struct thread_info {
12453
12454 /* work to do on any return to user space */
12455 #define _TIF_ALLWORK_MASK \
12456 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12457 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12458 + _TIF_GRSEC_SETXID)
12459
12460 /* Only used for 64 bit */
12461 #define _TIF_DO_NOTIFY_MASK \
12462 @@ -157,45 +155,40 @@ struct thread_info {
12463
12464 #define PREEMPT_ACTIVE 0x10000000
12465
12466 -#ifdef CONFIG_X86_32
12467 -
12468 -#define STACK_WARN (THREAD_SIZE/8)
12469 -/*
12470 - * macros/functions for gaining access to the thread information structure
12471 - *
12472 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12473 - */
12474 -#ifndef __ASSEMBLY__
12475 -
12476 -
12477 -/* how to get the current stack pointer from C */
12478 -register unsigned long current_stack_pointer asm("esp") __used;
12479 -
12480 -/* how to get the thread information struct from C */
12481 -static inline struct thread_info *current_thread_info(void)
12482 -{
12483 - return (struct thread_info *)
12484 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12485 -}
12486 -
12487 -#else /* !__ASSEMBLY__ */
12488 -
12489 +#ifdef __ASSEMBLY__
12490 /* how to get the thread information struct from ASM */
12491 #define GET_THREAD_INFO(reg) \
12492 - movl $-THREAD_SIZE, reg; \
12493 - andl %esp, reg
12494 + mov PER_CPU_VAR(current_tinfo), reg
12495
12496 /* use this one if reg already contains %esp */
12497 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12498 - andl $-THREAD_SIZE, reg
12499 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12500 +#else
12501 +/* how to get the thread information struct from C */
12502 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12503 +
12504 +static __always_inline struct thread_info *current_thread_info(void)
12505 +{
12506 + return this_cpu_read_stable(current_tinfo);
12507 +}
12508 +#endif
12509 +
12510 +#ifdef CONFIG_X86_32
12511 +
12512 +#define STACK_WARN (THREAD_SIZE/8)
12513 +/*
12514 + * macros/functions for gaining access to the thread information structure
12515 + *
12516 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12517 + */
12518 +#ifndef __ASSEMBLY__
12519 +
12520 +/* how to get the current stack pointer from C */
12521 +register unsigned long current_stack_pointer asm("esp") __used;
12522
12523 #endif
12524
12525 #else /* X86_32 */
12526
12527 -#include <asm/percpu.h>
12528 -#define KERNEL_STACK_OFFSET (5*8)
12529 -
12530 /*
12531 * macros/functions for gaining access to the thread information structure
12532 * preempt_count needs to be 1 initially, until the scheduler is functional.
12533 @@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12534 #ifndef __ASSEMBLY__
12535 DECLARE_PER_CPU(unsigned long, kernel_stack);
12536
12537 -static inline struct thread_info *current_thread_info(void)
12538 -{
12539 - struct thread_info *ti;
12540 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
12541 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12542 - return ti;
12543 -}
12544 -
12545 -#else /* !__ASSEMBLY__ */
12546 -
12547 -/* how to get the thread information struct from ASM */
12548 -#define GET_THREAD_INFO(reg) \
12549 - movq PER_CPU_VAR(kernel_stack),reg ; \
12550 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12551 -
12552 -/*
12553 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12554 - * a certain register (to be used in assembler memory operands).
12555 - */
12556 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12557 -
12558 +/* how to get the current stack pointer from C */
12559 +register unsigned long current_stack_pointer asm("rsp") __used;
12560 #endif
12561
12562 #endif /* !X86_32 */
12563 @@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12564 extern void arch_task_cache_init(void);
12565 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12566 extern void arch_release_task_struct(struct task_struct *tsk);
12567 +
12568 +#define __HAVE_THREAD_FUNCTIONS
12569 +#define task_thread_info(task) (&(task)->tinfo)
12570 +#define task_stack_page(task) ((task)->stack)
12571 +#define setup_thread_stack(p, org) do {} while (0)
12572 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12573 +
12574 #endif
12575 #endif /* _ASM_X86_THREAD_INFO_H */
12576 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12577 index e1f3a17..1ab364d 100644
12578 --- a/arch/x86/include/asm/uaccess.h
12579 +++ b/arch/x86/include/asm/uaccess.h
12580 @@ -7,12 +7,15 @@
12581 #include <linux/compiler.h>
12582 #include <linux/thread_info.h>
12583 #include <linux/string.h>
12584 +#include <linux/sched.h>
12585 #include <asm/asm.h>
12586 #include <asm/page.h>
12587
12588 #define VERIFY_READ 0
12589 #define VERIFY_WRITE 1
12590
12591 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12592 +
12593 /*
12594 * The fs value determines whether argument validity checking should be
12595 * performed or not. If get_fs() == USER_DS, checking is performed, with
12596 @@ -28,7 +31,12 @@
12597
12598 #define get_ds() (KERNEL_DS)
12599 #define get_fs() (current_thread_info()->addr_limit)
12600 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12601 +void __set_fs(mm_segment_t x);
12602 +void set_fs(mm_segment_t x);
12603 +#else
12604 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12605 +#endif
12606
12607 #define segment_eq(a, b) ((a).seg == (b).seg)
12608
12609 @@ -76,8 +84,33 @@
12610 * checks that the pointer is in the user space range - after calling
12611 * this function, memory access functions may still return -EFAULT.
12612 */
12613 -#define access_ok(type, addr, size) \
12614 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12615 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12616 +#define access_ok(type, addr, size) \
12617 +({ \
12618 + long __size = size; \
12619 + unsigned long __addr = (unsigned long)addr; \
12620 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12621 + unsigned long __end_ao = __addr + __size - 1; \
12622 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12623 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12624 + while(__addr_ao <= __end_ao) { \
12625 + char __c_ao; \
12626 + __addr_ao += PAGE_SIZE; \
12627 + if (__size > PAGE_SIZE) \
12628 + cond_resched(); \
12629 + if (__get_user(__c_ao, (char __user *)__addr)) \
12630 + break; \
12631 + if (type != VERIFY_WRITE) { \
12632 + __addr = __addr_ao; \
12633 + continue; \
12634 + } \
12635 + if (__put_user(__c_ao, (char __user *)__addr)) \
12636 + break; \
12637 + __addr = __addr_ao; \
12638 + } \
12639 + } \
12640 + __ret_ao; \
12641 +})
12642
12643 /*
12644 * The exception table consists of pairs of addresses relative to the
12645 @@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12646 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12647 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12648
12649 -
12650 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12651 +#define __copyuser_seg "gs;"
12652 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12653 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12654 +#else
12655 +#define __copyuser_seg
12656 +#define __COPYUSER_SET_ES
12657 +#define __COPYUSER_RESTORE_ES
12658 +#endif
12659
12660 #ifdef CONFIG_X86_32
12661 #define __put_user_asm_u64(x, addr, err, errret) \
12662 - asm volatile("1: movl %%eax,0(%2)\n" \
12663 - "2: movl %%edx,4(%2)\n" \
12664 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12665 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12666 "3:\n" \
12667 ".section .fixup,\"ax\"\n" \
12668 "4: movl %3,%0\n" \
12669 @@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12670 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12671
12672 #define __put_user_asm_ex_u64(x, addr) \
12673 - asm volatile("1: movl %%eax,0(%1)\n" \
12674 - "2: movl %%edx,4(%1)\n" \
12675 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12676 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12677 "3:\n" \
12678 _ASM_EXTABLE_EX(1b, 2b) \
12679 _ASM_EXTABLE_EX(2b, 3b) \
12680 @@ -258,7 +299,7 @@ extern void __put_user_8(void);
12681 __typeof__(*(ptr)) __pu_val; \
12682 __chk_user_ptr(ptr); \
12683 might_fault(); \
12684 - __pu_val = x; \
12685 + __pu_val = (x); \
12686 switch (sizeof(*(ptr))) { \
12687 case 1: \
12688 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12689 @@ -379,7 +420,7 @@ do { \
12690 } while (0)
12691
12692 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12693 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12694 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12695 "2:\n" \
12696 ".section .fixup,\"ax\"\n" \
12697 "3: mov %3,%0\n" \
12698 @@ -387,7 +428,7 @@ do { \
12699 " jmp 2b\n" \
12700 ".previous\n" \
12701 _ASM_EXTABLE(1b, 3b) \
12702 - : "=r" (err), ltype(x) \
12703 + : "=r" (err), ltype (x) \
12704 : "m" (__m(addr)), "i" (errret), "0" (err))
12705
12706 #define __get_user_size_ex(x, ptr, size) \
12707 @@ -412,7 +453,7 @@ do { \
12708 } while (0)
12709
12710 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12711 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12712 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12713 "2:\n" \
12714 _ASM_EXTABLE_EX(1b, 2b) \
12715 : ltype(x) : "m" (__m(addr)))
12716 @@ -429,13 +470,24 @@ do { \
12717 int __gu_err; \
12718 unsigned long __gu_val; \
12719 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12720 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12721 + (x) = (__typeof__(*(ptr)))__gu_val; \
12722 __gu_err; \
12723 })
12724
12725 /* FIXME: this hack is definitely wrong -AK */
12726 struct __large_struct { unsigned long buf[100]; };
12727 -#define __m(x) (*(struct __large_struct __user *)(x))
12728 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12729 +#define ____m(x) \
12730 +({ \
12731 + unsigned long ____x = (unsigned long)(x); \
12732 + if (____x < PAX_USER_SHADOW_BASE) \
12733 + ____x += PAX_USER_SHADOW_BASE; \
12734 + (void __user *)____x; \
12735 +})
12736 +#else
12737 +#define ____m(x) (x)
12738 +#endif
12739 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12740
12741 /*
12742 * Tell gcc we read from memory instead of writing: this is because
12743 @@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12744 * aliasing issues.
12745 */
12746 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12747 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12748 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12749 "2:\n" \
12750 ".section .fixup,\"ax\"\n" \
12751 "3: mov %3,%0\n" \
12752 @@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12753 ".previous\n" \
12754 _ASM_EXTABLE(1b, 3b) \
12755 : "=r"(err) \
12756 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12757 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12758
12759 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12760 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12761 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12762 "2:\n" \
12763 _ASM_EXTABLE_EX(1b, 2b) \
12764 : : ltype(x), "m" (__m(addr)))
12765 @@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12766 * On error, the variable @x is set to zero.
12767 */
12768
12769 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12770 +#define __get_user(x, ptr) get_user((x), (ptr))
12771 +#else
12772 #define __get_user(x, ptr) \
12773 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12774 +#endif
12775
12776 /**
12777 * __put_user: - Write a simple value into user space, with less checking.
12778 @@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12779 * Returns zero on success, or -EFAULT on error.
12780 */
12781
12782 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12783 +#define __put_user(x, ptr) put_user((x), (ptr))
12784 +#else
12785 #define __put_user(x, ptr) \
12786 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12787 +#endif
12788
12789 #define __get_user_unaligned __get_user
12790 #define __put_user_unaligned __put_user
12791 @@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12792 #define get_user_ex(x, ptr) do { \
12793 unsigned long __gue_val; \
12794 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12795 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12796 + (x) = (__typeof__(*(ptr)))__gue_val; \
12797 } while (0)
12798
12799 #ifdef CONFIG_X86_WP_WORKS_OK
12800 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12801 index 576e39b..ccd0a39 100644
12802 --- a/arch/x86/include/asm/uaccess_32.h
12803 +++ b/arch/x86/include/asm/uaccess_32.h
12804 @@ -11,15 +11,15 @@
12805 #include <asm/page.h>
12806
12807 unsigned long __must_check __copy_to_user_ll
12808 - (void __user *to, const void *from, unsigned long n);
12809 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12810 unsigned long __must_check __copy_from_user_ll
12811 - (void *to, const void __user *from, unsigned long n);
12812 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12813 unsigned long __must_check __copy_from_user_ll_nozero
12814 - (void *to, const void __user *from, unsigned long n);
12815 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12816 unsigned long __must_check __copy_from_user_ll_nocache
12817 - (void *to, const void __user *from, unsigned long n);
12818 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12819 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12820 - (void *to, const void __user *from, unsigned long n);
12821 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12822
12823 /**
12824 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12825 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12826 static __always_inline unsigned long __must_check
12827 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12828 {
12829 + if ((long)n < 0)
12830 + return n;
12831 +
12832 if (__builtin_constant_p(n)) {
12833 unsigned long ret;
12834
12835 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12836 return ret;
12837 }
12838 }
12839 + if (!__builtin_constant_p(n))
12840 + check_object_size(from, n, true);
12841 return __copy_to_user_ll(to, from, n);
12842 }
12843
12844 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12845 __copy_to_user(void __user *to, const void *from, unsigned long n)
12846 {
12847 might_fault();
12848 +
12849 return __copy_to_user_inatomic(to, from, n);
12850 }
12851
12852 static __always_inline unsigned long
12853 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12854 {
12855 + if ((long)n < 0)
12856 + return n;
12857 +
12858 /* Avoid zeroing the tail if the copy fails..
12859 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12860 * but as the zeroing behaviour is only significant when n is not
12861 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12862 __copy_from_user(void *to, const void __user *from, unsigned long n)
12863 {
12864 might_fault();
12865 +
12866 + if ((long)n < 0)
12867 + return n;
12868 +
12869 if (__builtin_constant_p(n)) {
12870 unsigned long ret;
12871
12872 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12873 return ret;
12874 }
12875 }
12876 + if (!__builtin_constant_p(n))
12877 + check_object_size(to, n, false);
12878 return __copy_from_user_ll(to, from, n);
12879 }
12880
12881 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12882 const void __user *from, unsigned long n)
12883 {
12884 might_fault();
12885 +
12886 + if ((long)n < 0)
12887 + return n;
12888 +
12889 if (__builtin_constant_p(n)) {
12890 unsigned long ret;
12891
12892 @@ -181,15 +200,19 @@ static __always_inline unsigned long
12893 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12894 unsigned long n)
12895 {
12896 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12897 + if ((long)n < 0)
12898 + return n;
12899 +
12900 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12901 }
12902
12903 -unsigned long __must_check copy_to_user(void __user *to,
12904 - const void *from, unsigned long n);
12905 -unsigned long __must_check _copy_from_user(void *to,
12906 - const void __user *from,
12907 - unsigned long n);
12908 -
12909 +extern void copy_to_user_overflow(void)
12910 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12911 + __compiletime_error("copy_to_user() buffer size is not provably correct")
12912 +#else
12913 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
12914 +#endif
12915 +;
12916
12917 extern void copy_from_user_overflow(void)
12918 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12919 @@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
12920 #endif
12921 ;
12922
12923 -static inline unsigned long __must_check copy_from_user(void *to,
12924 - const void __user *from,
12925 - unsigned long n)
12926 +/**
12927 + * copy_to_user: - Copy a block of data into user space.
12928 + * @to: Destination address, in user space.
12929 + * @from: Source address, in kernel space.
12930 + * @n: Number of bytes to copy.
12931 + *
12932 + * Context: User context only. This function may sleep.
12933 + *
12934 + * Copy data from kernel space to user space.
12935 + *
12936 + * Returns number of bytes that could not be copied.
12937 + * On success, this will be zero.
12938 + */
12939 +static inline unsigned long __must_check
12940 +copy_to_user(void __user *to, const void *from, unsigned long n)
12941 {
12942 - int sz = __compiletime_object_size(to);
12943 + size_t sz = __compiletime_object_size(from);
12944
12945 - if (likely(sz == -1 || sz >= n))
12946 - n = _copy_from_user(to, from, n);
12947 - else
12948 + if (unlikely(sz != (size_t)-1 && sz < n))
12949 + copy_to_user_overflow();
12950 + else if (access_ok(VERIFY_WRITE, to, n))
12951 + n = __copy_to_user(to, from, n);
12952 + return n;
12953 +}
12954 +
12955 +/**
12956 + * copy_from_user: - Copy a block of data from user space.
12957 + * @to: Destination address, in kernel space.
12958 + * @from: Source address, in user space.
12959 + * @n: Number of bytes to copy.
12960 + *
12961 + * Context: User context only. This function may sleep.
12962 + *
12963 + * Copy data from user space to kernel space.
12964 + *
12965 + * Returns number of bytes that could not be copied.
12966 + * On success, this will be zero.
12967 + *
12968 + * If some data could not be copied, this function will pad the copied
12969 + * data to the requested size using zero bytes.
12970 + */
12971 +static inline unsigned long __must_check
12972 +copy_from_user(void *to, const void __user *from, unsigned long n)
12973 +{
12974 + size_t sz = __compiletime_object_size(to);
12975 +
12976 + if (unlikely(sz != (size_t)-1 && sz < n))
12977 copy_from_user_overflow();
12978 -
12979 + else if (access_ok(VERIFY_READ, from, n))
12980 + n = __copy_from_user(to, from, n);
12981 + else if ((long)n > 0) {
12982 + if (!__builtin_constant_p(n))
12983 + check_object_size(to, n, false);
12984 + memset(to, 0, n);
12985 + }
12986 return n;
12987 }
12988
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);
12991 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12992 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12993
12994 #endif /* _ASM_X86_UACCESS_32_H */
12995 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12996 index 8e796fb..72fd934 100644
12997 --- a/arch/x86/include/asm/uaccess_64.h
12998 +++ b/arch/x86/include/asm/uaccess_64.h
12999 @@ -10,6 +10,9 @@
13000 #include <asm/alternative.h>
13001 #include <asm/cpufeature.h>
13002 #include <asm/page.h>
13003 +#include <asm/pgtable.h>
13004 +
13005 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13006
13007 /*
13008 * Copy To/From Userspace
13009 @@ -17,12 +20,14 @@
13010
13011 /* Handles exceptions in both to and from, but doesn't do access_ok */
13012 __must_check unsigned long
13013 -copy_user_generic_string(void *to, const void *from, unsigned len);
13014 +copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13015 __must_check unsigned long
13016 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13017 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13018
13019 static __always_inline __must_check unsigned long
13020 -copy_user_generic(void *to, const void *from, unsigned len)
13021 +copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
13022 +static __always_inline __must_check unsigned long
13023 +copy_user_generic(void *to, const void *from, unsigned long len)
13024 {
13025 unsigned ret;
13026
13027 @@ -32,142 +37,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13028 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13029 "=d" (len)),
13030 "1" (to), "2" (from), "3" (len)
13031 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13032 + : "memory", "rcx", "r8", "r9", "r11");
13033 return ret;
13034 }
13035
13036 +static __always_inline __must_check unsigned long
13037 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13038 +static __always_inline __must_check unsigned long
13039 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13040 __must_check unsigned long
13041 -_copy_to_user(void __user *to, const void *from, unsigned len);
13042 -__must_check unsigned long
13043 -_copy_from_user(void *to, const void __user *from, unsigned len);
13044 -__must_check unsigned long
13045 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13046 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13047 +
13048 +extern void copy_to_user_overflow(void)
13049 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13050 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13051 +#else
13052 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13053 +#endif
13054 +;
13055 +
13056 +extern void copy_from_user_overflow(void)
13057 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13058 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13059 +#else
13060 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13061 +#endif
13062 +;
13063
13064 static inline unsigned long __must_check copy_from_user(void *to,
13065 const void __user *from,
13066 unsigned long n)
13067 {
13068 - int sz = __compiletime_object_size(to);
13069 -
13070 might_fault();
13071 - if (likely(sz == -1 || sz >= n))
13072 - n = _copy_from_user(to, from, n);
13073 -#ifdef CONFIG_DEBUG_VM
13074 - else
13075 - WARN(1, "Buffer overflow detected!\n");
13076 -#endif
13077 +
13078 + if (access_ok(VERIFY_READ, from, n))
13079 + n = __copy_from_user(to, from, n);
13080 + else if (n < INT_MAX) {
13081 + if (!__builtin_constant_p(n))
13082 + check_object_size(to, n, false);
13083 + memset(to, 0, n);
13084 + }
13085 return n;
13086 }
13087
13088 static __always_inline __must_check
13089 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13090 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13091 {
13092 might_fault();
13093
13094 - return _copy_to_user(dst, src, size);
13095 + if (access_ok(VERIFY_WRITE, dst, size))
13096 + size = __copy_to_user(dst, src, size);
13097 + return size;
13098 }
13099
13100 static __always_inline __must_check
13101 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13102 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13103 {
13104 - int ret = 0;
13105 + size_t sz = __compiletime_object_size(dst);
13106 + unsigned ret = 0;
13107
13108 might_fault();
13109 - if (!__builtin_constant_p(size))
13110 - return copy_user_generic(dst, (__force void *)src, size);
13111 +
13112 + if (size > INT_MAX)
13113 + return size;
13114 +
13115 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13116 + if (!__access_ok(VERIFY_READ, src, size))
13117 + return size;
13118 +#endif
13119 +
13120 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13121 + copy_from_user_overflow();
13122 + return size;
13123 + }
13124 +
13125 + if (!__builtin_constant_p(size)) {
13126 + check_object_size(dst, size, false);
13127 +
13128 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13129 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13130 + src += PAX_USER_SHADOW_BASE;
13131 +#endif
13132 +
13133 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13134 + }
13135 switch (size) {
13136 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13137 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13138 ret, "b", "b", "=q", 1);
13139 return ret;
13140 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13141 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13142 ret, "w", "w", "=r", 2);
13143 return ret;
13144 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13145 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13146 ret, "l", "k", "=r", 4);
13147 return ret;
13148 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13149 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13150 ret, "q", "", "=r", 8);
13151 return ret;
13152 case 10:
13153 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13154 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13155 ret, "q", "", "=r", 10);
13156 if (unlikely(ret))
13157 return ret;
13158 __get_user_asm(*(u16 *)(8 + (char *)dst),
13159 - (u16 __user *)(8 + (char __user *)src),
13160 + (const u16 __user *)(8 + (const char __user *)src),
13161 ret, "w", "w", "=r", 2);
13162 return ret;
13163 case 16:
13164 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13165 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13166 ret, "q", "", "=r", 16);
13167 if (unlikely(ret))
13168 return ret;
13169 __get_user_asm(*(u64 *)(8 + (char *)dst),
13170 - (u64 __user *)(8 + (char __user *)src),
13171 + (const u64 __user *)(8 + (const char __user *)src),
13172 ret, "q", "", "=r", 8);
13173 return ret;
13174 default:
13175 - return copy_user_generic(dst, (__force void *)src, size);
13176 +
13177 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13178 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13179 + src += PAX_USER_SHADOW_BASE;
13180 +#endif
13181 +
13182 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13183 }
13184 }
13185
13186 static __always_inline __must_check
13187 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13188 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13189 {
13190 - int ret = 0;
13191 + size_t sz = __compiletime_object_size(src);
13192 + unsigned ret = 0;
13193
13194 might_fault();
13195 - if (!__builtin_constant_p(size))
13196 - return copy_user_generic((__force void *)dst, src, size);
13197 +
13198 + if (size > INT_MAX)
13199 + return size;
13200 +
13201 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13202 + if (!__access_ok(VERIFY_WRITE, dst, size))
13203 + return size;
13204 +#endif
13205 +
13206 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13207 + copy_to_user_overflow();
13208 + return size;
13209 + }
13210 +
13211 + if (!__builtin_constant_p(size)) {
13212 + check_object_size(src, size, true);
13213 +
13214 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13215 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13216 + dst += PAX_USER_SHADOW_BASE;
13217 +#endif
13218 +
13219 + return copy_user_generic((__force_kernel void *)dst, src, size);
13220 + }
13221 switch (size) {
13222 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13223 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13224 ret, "b", "b", "iq", 1);
13225 return ret;
13226 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13227 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13228 ret, "w", "w", "ir", 2);
13229 return ret;
13230 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13231 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13232 ret, "l", "k", "ir", 4);
13233 return ret;
13234 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13235 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13236 ret, "q", "", "er", 8);
13237 return ret;
13238 case 10:
13239 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13240 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13241 ret, "q", "", "er", 10);
13242 if (unlikely(ret))
13243 return ret;
13244 asm("":::"memory");
13245 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13246 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13247 ret, "w", "w", "ir", 2);
13248 return ret;
13249 case 16:
13250 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13251 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13252 ret, "q", "", "er", 16);
13253 if (unlikely(ret))
13254 return ret;
13255 asm("":::"memory");
13256 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13257 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13258 ret, "q", "", "er", 8);
13259 return ret;
13260 default:
13261 - return copy_user_generic((__force void *)dst, src, size);
13262 +
13263 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13264 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13265 + dst += PAX_USER_SHADOW_BASE;
13266 +#endif
13267 +
13268 + return copy_user_generic((__force_kernel void *)dst, src, size);
13269 }
13270 }
13271
13272 static __always_inline __must_check
13273 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13274 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13275 {
13276 - int ret = 0;
13277 + unsigned ret = 0;
13278
13279 might_fault();
13280 - if (!__builtin_constant_p(size))
13281 - return copy_user_generic((__force void *)dst,
13282 - (__force void *)src, size);
13283 +
13284 + if (size > INT_MAX)
13285 + return size;
13286 +
13287 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13288 + if (!__access_ok(VERIFY_READ, src, size))
13289 + return size;
13290 + if (!__access_ok(VERIFY_WRITE, dst, size))
13291 + return size;
13292 +#endif
13293 +
13294 + if (!__builtin_constant_p(size)) {
13295 +
13296 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13297 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13298 + src += PAX_USER_SHADOW_BASE;
13299 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13300 + dst += PAX_USER_SHADOW_BASE;
13301 +#endif
13302 +
13303 + return copy_user_generic((__force_kernel void *)dst,
13304 + (__force_kernel const void *)src, size);
13305 + }
13306 switch (size) {
13307 case 1: {
13308 u8 tmp;
13309 - __get_user_asm(tmp, (u8 __user *)src,
13310 + __get_user_asm(tmp, (const u8 __user *)src,
13311 ret, "b", "b", "=q", 1);
13312 if (likely(!ret))
13313 __put_user_asm(tmp, (u8 __user *)dst,
13314 @@ -176,7 +277,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13315 }
13316 case 2: {
13317 u16 tmp;
13318 - __get_user_asm(tmp, (u16 __user *)src,
13319 + __get_user_asm(tmp, (const u16 __user *)src,
13320 ret, "w", "w", "=r", 2);
13321 if (likely(!ret))
13322 __put_user_asm(tmp, (u16 __user *)dst,
13323 @@ -186,7 +287,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13324
13325 case 4: {
13326 u32 tmp;
13327 - __get_user_asm(tmp, (u32 __user *)src,
13328 + __get_user_asm(tmp, (const u32 __user *)src,
13329 ret, "l", "k", "=r", 4);
13330 if (likely(!ret))
13331 __put_user_asm(tmp, (u32 __user *)dst,
13332 @@ -195,7 +296,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13333 }
13334 case 8: {
13335 u64 tmp;
13336 - __get_user_asm(tmp, (u64 __user *)src,
13337 + __get_user_asm(tmp, (const u64 __user *)src,
13338 ret, "q", "", "=r", 8);
13339 if (likely(!ret))
13340 __put_user_asm(tmp, (u64 __user *)dst,
13341 @@ -203,44 +304,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13342 return ret;
13343 }
13344 default:
13345 - return copy_user_generic((__force void *)dst,
13346 - (__force void *)src, size);
13347 +
13348 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13349 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13350 + src += PAX_USER_SHADOW_BASE;
13351 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13352 + dst += PAX_USER_SHADOW_BASE;
13353 +#endif
13354 +
13355 + return copy_user_generic((__force_kernel void *)dst,
13356 + (__force_kernel const void *)src, size);
13357 }
13358 }
13359
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);
13362 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13363 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13364
13365 static __must_check __always_inline int
13366 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13367 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13368 {
13369 - return copy_user_generic(dst, (__force const void *)src, size);
13370 + if (size > INT_MAX)
13371 + return size;
13372 +
13373 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13374 + if (!__access_ok(VERIFY_READ, src, size))
13375 + return size;
13376 +
13377 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13378 + src += PAX_USER_SHADOW_BASE;
13379 +#endif
13380 +
13381 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13382 }
13383
13384 -static __must_check __always_inline int
13385 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13386 +static __must_check __always_inline unsigned long
13387 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13388 {
13389 - return copy_user_generic((__force void *)dst, src, size);
13390 + if (size > INT_MAX)
13391 + return size;
13392 +
13393 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13394 + if (!__access_ok(VERIFY_WRITE, dst, size))
13395 + return size;
13396 +
13397 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13398 + dst += PAX_USER_SHADOW_BASE;
13399 +#endif
13400 +
13401 + return copy_user_generic((__force_kernel void *)dst, src, size);
13402 }
13403
13404 -extern long __copy_user_nocache(void *dst, const void __user *src,
13405 - unsigned size, int zerorest);
13406 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13407 + unsigned long size, int zerorest) __size_overflow(3);
13408
13409 -static inline int
13410 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13411 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13412 {
13413 might_sleep();
13414 +
13415 + if (size > INT_MAX)
13416 + return size;
13417 +
13418 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13419 + if (!__access_ok(VERIFY_READ, src, size))
13420 + return size;
13421 +#endif
13422 +
13423 return __copy_user_nocache(dst, src, size, 1);
13424 }
13425
13426 -static inline int
13427 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13428 - unsigned size)
13429 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13430 + unsigned long size)
13431 {
13432 + if (size > INT_MAX)
13433 + return size;
13434 +
13435 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13436 + if (!__access_ok(VERIFY_READ, src, size))
13437 + return size;
13438 +#endif
13439 +
13440 return __copy_user_nocache(dst, src, size, 0);
13441 }
13442
13443 -unsigned long
13444 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13445 +extern unsigned long
13446 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13447
13448 #endif /* _ASM_X86_UACCESS_64_H */
13449 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13450 index bb05228..d763d5b 100644
13451 --- a/arch/x86/include/asm/vdso.h
13452 +++ b/arch/x86/include/asm/vdso.h
13453 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13454 #define VDSO32_SYMBOL(base, name) \
13455 ({ \
13456 extern const char VDSO32_##name[]; \
13457 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13458 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13459 })
13460 #endif
13461
13462 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13463 index 5b238981..77fdd78 100644
13464 --- a/arch/x86/include/asm/word-at-a-time.h
13465 +++ b/arch/x86/include/asm/word-at-a-time.h
13466 @@ -11,7 +11,7 @@
13467 * and shift, for example.
13468 */
13469 struct word_at_a_time {
13470 - const unsigned long one_bits, high_bits;
13471 + unsigned long one_bits, high_bits;
13472 };
13473
13474 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13475 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13476 index c090af1..7e7bf16 100644
13477 --- a/arch/x86/include/asm/x86_init.h
13478 +++ b/arch/x86/include/asm/x86_init.h
13479 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13480 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13481 void (*find_smp_config)(void);
13482 void (*get_smp_config)(unsigned int early);
13483 -};
13484 +} __no_const;
13485
13486 /**
13487 * struct x86_init_resources - platform specific resource related ops
13488 @@ -43,7 +43,7 @@ struct x86_init_resources {
13489 void (*probe_roms)(void);
13490 void (*reserve_resources)(void);
13491 char *(*memory_setup)(void);
13492 -};
13493 +} __no_const;
13494
13495 /**
13496 * struct x86_init_irqs - platform specific interrupt setup
13497 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13498 void (*pre_vector_init)(void);
13499 void (*intr_init)(void);
13500 void (*trap_init)(void);
13501 -};
13502 +} __no_const;
13503
13504 /**
13505 * struct x86_init_oem - oem platform specific customizing functions
13506 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13507 struct x86_init_oem {
13508 void (*arch_setup)(void);
13509 void (*banner)(void);
13510 -};
13511 +} __no_const;
13512
13513 /**
13514 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13515 @@ -77,7 +77,7 @@ struct x86_init_oem {
13516 */
13517 struct x86_init_mapping {
13518 void (*pagetable_reserve)(u64 start, u64 end);
13519 -};
13520 +} __no_const;
13521
13522 /**
13523 * struct x86_init_paging - platform specific paging functions
13524 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13525 struct x86_init_paging {
13526 void (*pagetable_setup_start)(pgd_t *base);
13527 void (*pagetable_setup_done)(pgd_t *base);
13528 -};
13529 +} __no_const;
13530
13531 /**
13532 * struct x86_init_timers - platform specific timer setup
13533 @@ -102,7 +102,7 @@ struct x86_init_timers {
13534 void (*tsc_pre_init)(void);
13535 void (*timer_init)(void);
13536 void (*wallclock_init)(void);
13537 -};
13538 +} __no_const;
13539
13540 /**
13541 * struct x86_init_iommu - platform specific iommu setup
13542 @@ -110,7 +110,7 @@ struct x86_init_timers {
13543 */
13544 struct x86_init_iommu {
13545 int (*iommu_init)(void);
13546 -};
13547 +} __no_const;
13548
13549 /**
13550 * struct x86_init_pci - platform specific pci init functions
13551 @@ -124,7 +124,7 @@ struct x86_init_pci {
13552 int (*init)(void);
13553 void (*init_irq)(void);
13554 void (*fixup_irqs)(void);
13555 -};
13556 +} __no_const;
13557
13558 /**
13559 * struct x86_init_ops - functions for platform specific setup
13560 @@ -140,7 +140,7 @@ struct x86_init_ops {
13561 struct x86_init_timers timers;
13562 struct x86_init_iommu iommu;
13563 struct x86_init_pci pci;
13564 -};
13565 +} __no_const;
13566
13567 /**
13568 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13569 @@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13570 void (*setup_percpu_clockev)(void);
13571 void (*early_percpu_clock_init)(void);
13572 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13573 -};
13574 +} __no_const;
13575
13576 /**
13577 * struct x86_platform_ops - platform specific runtime functions
13578 @@ -177,7 +177,7 @@ struct x86_platform_ops {
13579 int (*i8042_detect)(void);
13580 void (*save_sched_clock_state)(void);
13581 void (*restore_sched_clock_state)(void);
13582 -};
13583 +} __no_const;
13584
13585 struct pci_dev;
13586
13587 @@ -186,14 +186,14 @@ struct x86_msi_ops {
13588 void (*teardown_msi_irq)(unsigned int irq);
13589 void (*teardown_msi_irqs)(struct pci_dev *dev);
13590 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13591 -};
13592 +} __no_const;
13593
13594 struct x86_io_apic_ops {
13595 void (*init) (void);
13596 unsigned int (*read) (unsigned int apic, unsigned int reg);
13597 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13598 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13599 -};
13600 +} __no_const;
13601
13602 extern struct x86_init_ops x86_init;
13603 extern struct x86_cpuinit_ops x86_cpuinit;
13604 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13605 index 8a1b6f9..a29c4e4 100644
13606 --- a/arch/x86/include/asm/xsave.h
13607 +++ b/arch/x86/include/asm/xsave.h
13608 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13609 {
13610 int err;
13611
13612 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13613 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13614 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13615 +#endif
13616 +
13617 /*
13618 * Clear the xsave header first, so that reserved fields are
13619 * initialized to zero.
13620 @@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13621 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13622 {
13623 int err;
13624 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13625 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13626 u32 lmask = mask;
13627 u32 hmask = mask >> 32;
13628
13629 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13630 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13631 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13632 +#endif
13633 +
13634 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13635 "2:\n"
13636 ".section .fixup,\"ax\"\n"
13637 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13638 index 95bf99de..de9235c 100644
13639 --- a/arch/x86/kernel/acpi/sleep.c
13640 +++ b/arch/x86/kernel/acpi/sleep.c
13641 @@ -73,8 +73,12 @@ int acpi_suspend_lowlevel(void)
13642 #else /* CONFIG_64BIT */
13643 #ifdef CONFIG_SMP
13644 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13645 +
13646 + pax_open_kernel();
13647 early_gdt_descr.address =
13648 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13649 + pax_close_kernel();
13650 +
13651 initial_gs = per_cpu_offset(smp_processor_id());
13652 #endif
13653 initial_code = (unsigned long)wakeup_long64;
13654 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13655 index 7261083..5c12053 100644
13656 --- a/arch/x86/kernel/acpi/wakeup_32.S
13657 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13658 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13659 # and restore the stack ... but you need gdt for this to work
13660 movl saved_context_esp, %esp
13661
13662 - movl %cs:saved_magic, %eax
13663 - cmpl $0x12345678, %eax
13664 + cmpl $0x12345678, saved_magic
13665 jne bogus_magic
13666
13667 # jump to place where we left off
13668 - movl saved_eip, %eax
13669 - jmp *%eax
13670 + jmp *(saved_eip)
13671
13672 bogus_magic:
13673 jmp bogus_magic
13674 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13675 index 1f84794..e23f862 100644
13676 --- a/arch/x86/kernel/alternative.c
13677 +++ b/arch/x86/kernel/alternative.c
13678 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13679 */
13680 for (a = start; a < end; a++) {
13681 instr = (u8 *)&a->instr_offset + a->instr_offset;
13682 +
13683 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13684 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13685 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13686 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13687 +#endif
13688 +
13689 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13690 BUG_ON(a->replacementlen > a->instrlen);
13691 BUG_ON(a->instrlen > sizeof(insnbuf));
13692 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13693 for (poff = start; poff < end; poff++) {
13694 u8 *ptr = (u8 *)poff + *poff;
13695
13696 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13697 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13698 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13699 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13700 +#endif
13701 +
13702 if (!*poff || ptr < text || ptr >= text_end)
13703 continue;
13704 /* turn DS segment override prefix into lock prefix */
13705 - if (*ptr == 0x3e)
13706 + if (*ktla_ktva(ptr) == 0x3e)
13707 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13708 };
13709 mutex_unlock(&text_mutex);
13710 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13711 for (poff = start; poff < end; poff++) {
13712 u8 *ptr = (u8 *)poff + *poff;
13713
13714 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13715 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13716 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13717 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13718 +#endif
13719 +
13720 if (!*poff || ptr < text || ptr >= text_end)
13721 continue;
13722 /* turn lock prefix into DS segment override prefix */
13723 - if (*ptr == 0xf0)
13724 + if (*ktla_ktva(ptr) == 0xf0)
13725 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13726 };
13727 mutex_unlock(&text_mutex);
13728 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13729
13730 BUG_ON(p->len > MAX_PATCH_LEN);
13731 /* prep the buffer with the original instructions */
13732 - memcpy(insnbuf, p->instr, p->len);
13733 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13734 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13735 (unsigned long)p->instr, p->len);
13736
13737 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13738 if (smp_alt_once)
13739 free_init_pages("SMP alternatives",
13740 (unsigned long)__smp_locks,
13741 - (unsigned long)__smp_locks_end);
13742 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13743
13744 restart_nmi();
13745 }
13746 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13747 * instructions. And on the local CPU you need to be protected again NMI or MCE
13748 * handlers seeing an inconsistent instruction while you patch.
13749 */
13750 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13751 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13752 size_t len)
13753 {
13754 unsigned long flags;
13755 local_irq_save(flags);
13756 - memcpy(addr, opcode, len);
13757 +
13758 + pax_open_kernel();
13759 + memcpy(ktla_ktva(addr), opcode, len);
13760 sync_core();
13761 + pax_close_kernel();
13762 +
13763 local_irq_restore(flags);
13764 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13765 that causes hangs on some VIA CPUs. */
13766 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13767 */
13768 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13769 {
13770 - unsigned long flags;
13771 - char *vaddr;
13772 + unsigned char *vaddr = ktla_ktva(addr);
13773 struct page *pages[2];
13774 - int i;
13775 + size_t i;
13776
13777 if (!core_kernel_text((unsigned long)addr)) {
13778 - pages[0] = vmalloc_to_page(addr);
13779 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13780 + pages[0] = vmalloc_to_page(vaddr);
13781 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13782 } else {
13783 - pages[0] = virt_to_page(addr);
13784 + pages[0] = virt_to_page(vaddr);
13785 WARN_ON(!PageReserved(pages[0]));
13786 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13787 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13788 }
13789 BUG_ON(!pages[0]);
13790 - local_irq_save(flags);
13791 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13792 - if (pages[1])
13793 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13794 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13795 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13796 - clear_fixmap(FIX_TEXT_POKE0);
13797 - if (pages[1])
13798 - clear_fixmap(FIX_TEXT_POKE1);
13799 - local_flush_tlb();
13800 - sync_core();
13801 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13802 - that causes hangs on some VIA CPUs. */
13803 + text_poke_early(addr, opcode, len);
13804 for (i = 0; i < len; i++)
13805 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13806 - local_irq_restore(flags);
13807 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13808 return addr;
13809 }
13810
13811 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13812 index 39a222e..85a7767 100644
13813 --- a/arch/x86/kernel/apic/apic.c
13814 +++ b/arch/x86/kernel/apic/apic.c
13815 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13816 /*
13817 * Debug level, exported for io_apic.c
13818 */
13819 -unsigned int apic_verbosity;
13820 +int apic_verbosity;
13821
13822 int pic_mode;
13823
13824 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13825 apic_write(APIC_ESR, 0);
13826 v1 = apic_read(APIC_ESR);
13827 ack_APIC_irq();
13828 - atomic_inc(&irq_err_count);
13829 + atomic_inc_unchecked(&irq_err_count);
13830
13831 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13832 smp_processor_id(), v0 , v1);
13833 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13834 index 5f0ff59..f9e01bc 100644
13835 --- a/arch/x86/kernel/apic/io_apic.c
13836 +++ b/arch/x86/kernel/apic/io_apic.c
13837 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13838 }
13839 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13840
13841 -void lock_vector_lock(void)
13842 +void lock_vector_lock(void) __acquires(vector_lock)
13843 {
13844 /* Used to the online set of cpus does not change
13845 * during assign_irq_vector.
13846 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13847 raw_spin_lock(&vector_lock);
13848 }
13849
13850 -void unlock_vector_lock(void)
13851 +void unlock_vector_lock(void) __releases(vector_lock)
13852 {
13853 raw_spin_unlock(&vector_lock);
13854 }
13855 @@ -2369,7 +2369,7 @@ static void ack_apic_edge(struct irq_data *data)
13856 ack_APIC_irq();
13857 }
13858
13859 -atomic_t irq_mis_count;
13860 +atomic_unchecked_t irq_mis_count;
13861
13862 #ifdef CONFIG_GENERIC_PENDING_IRQ
13863 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
13864 @@ -2510,7 +2510,7 @@ static void ack_apic_level(struct irq_data *data)
13865 * at the cpu.
13866 */
13867 if (!(v & (1 << (i & 0x1f)))) {
13868 - atomic_inc(&irq_mis_count);
13869 + atomic_inc_unchecked(&irq_mis_count);
13870
13871 eoi_ioapic_irq(irq, cfg);
13872 }
13873 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13874 index 07b0c0d..1df6f42 100644
13875 --- a/arch/x86/kernel/apm_32.c
13876 +++ b/arch/x86/kernel/apm_32.c
13877 @@ -410,7 +410,7 @@ static DEFINE_MUTEX(apm_mutex);
13878 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13879 * even though they are called in protected mode.
13880 */
13881 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13882 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13883 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13884
13885 static const char driver_version[] = "1.16ac"; /* no spaces */
13886 @@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
13887 BUG_ON(cpu != 0);
13888 gdt = get_cpu_gdt_table(cpu);
13889 save_desc_40 = gdt[0x40 / 8];
13890 +
13891 + pax_open_kernel();
13892 gdt[0x40 / 8] = bad_bios_desc;
13893 + pax_close_kernel();
13894
13895 apm_irq_save(flags);
13896 APM_DO_SAVE_SEGS;
13897 @@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
13898 &call->esi);
13899 APM_DO_RESTORE_SEGS;
13900 apm_irq_restore(flags);
13901 +
13902 + pax_open_kernel();
13903 gdt[0x40 / 8] = save_desc_40;
13904 + pax_close_kernel();
13905 +
13906 put_cpu();
13907
13908 return call->eax & 0xff;
13909 @@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
13910 BUG_ON(cpu != 0);
13911 gdt = get_cpu_gdt_table(cpu);
13912 save_desc_40 = gdt[0x40 / 8];
13913 +
13914 + pax_open_kernel();
13915 gdt[0x40 / 8] = bad_bios_desc;
13916 + pax_close_kernel();
13917
13918 apm_irq_save(flags);
13919 APM_DO_SAVE_SEGS;
13920 @@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
13921 &call->eax);
13922 APM_DO_RESTORE_SEGS;
13923 apm_irq_restore(flags);
13924 +
13925 + pax_open_kernel();
13926 gdt[0x40 / 8] = save_desc_40;
13927 + pax_close_kernel();
13928 +
13929 put_cpu();
13930 return error;
13931 }
13932 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
13933 * code to that CPU.
13934 */
13935 gdt = get_cpu_gdt_table(0);
13936 +
13937 + pax_open_kernel();
13938 set_desc_base(&gdt[APM_CS >> 3],
13939 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13940 set_desc_base(&gdt[APM_CS_16 >> 3],
13941 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13942 set_desc_base(&gdt[APM_DS >> 3],
13943 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13944 + pax_close_kernel();
13945
13946 proc_create("apm", 0, NULL, &apm_file_ops);
13947
13948 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13949 index 68de2dc..1f3c720 100644
13950 --- a/arch/x86/kernel/asm-offsets.c
13951 +++ b/arch/x86/kernel/asm-offsets.c
13952 @@ -33,6 +33,8 @@ void common(void) {
13953 OFFSET(TI_status, thread_info, status);
13954 OFFSET(TI_addr_limit, thread_info, addr_limit);
13955 OFFSET(TI_preempt_count, thread_info, preempt_count);
13956 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13957 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13958
13959 BLANK();
13960 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
13961 @@ -53,8 +55,26 @@ void common(void) {
13962 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13963 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13964 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13965 +
13966 +#ifdef CONFIG_PAX_KERNEXEC
13967 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13968 #endif
13969
13970 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13971 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13972 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13973 +#ifdef CONFIG_X86_64
13974 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13975 +#endif
13976 +#endif
13977 +
13978 +#endif
13979 +
13980 + BLANK();
13981 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13982 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13983 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13984 +
13985 #ifdef CONFIG_XEN
13986 BLANK();
13987 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13988 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13989 index 1b4754f..fbb4227 100644
13990 --- a/arch/x86/kernel/asm-offsets_64.c
13991 +++ b/arch/x86/kernel/asm-offsets_64.c
13992 @@ -76,6 +76,7 @@ int main(void)
13993 BLANK();
13994 #undef ENTRY
13995
13996 + DEFINE(TSS_size, sizeof(struct tss_struct));
13997 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
13998 BLANK();
13999
14000 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14001 index 6ab6aa2..8f71507 100644
14002 --- a/arch/x86/kernel/cpu/Makefile
14003 +++ b/arch/x86/kernel/cpu/Makefile
14004 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14005 CFLAGS_REMOVE_perf_event.o = -pg
14006 endif
14007
14008 -# Make sure load_percpu_segment has no stackprotector
14009 -nostackp := $(call cc-option, -fno-stack-protector)
14010 -CFLAGS_common.o := $(nostackp)
14011 -
14012 obj-y := intel_cacheinfo.o scattered.o topology.o
14013 obj-y += proc.o capflags.o powerflags.o common.o
14014 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14015 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14016 index 146bb62..ac9c74a 100644
14017 --- a/arch/x86/kernel/cpu/amd.c
14018 +++ b/arch/x86/kernel/cpu/amd.c
14019 @@ -691,7 +691,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14020 unsigned int size)
14021 {
14022 /* AMD errata T13 (order #21922) */
14023 - if ((c->x86 == 6)) {
14024 + if (c->x86 == 6) {
14025 /* Duron Rev A0 */
14026 if (c->x86_model == 3 && c->x86_mask == 0)
14027 size = 64;
14028 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14029 index 6b9333b..4c3083a 100644
14030 --- a/arch/x86/kernel/cpu/common.c
14031 +++ b/arch/x86/kernel/cpu/common.c
14032 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14033
14034 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14035
14036 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14037 -#ifdef CONFIG_X86_64
14038 - /*
14039 - * We need valid kernel segments for data and code in long mode too
14040 - * IRET will check the segment types kkeil 2000/10/28
14041 - * Also sysret mandates a special GDT layout
14042 - *
14043 - * TLS descriptors are currently at a different place compared to i386.
14044 - * Hopefully nobody expects them at a fixed place (Wine?)
14045 - */
14046 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14047 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14048 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14049 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14050 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14051 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14052 -#else
14053 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14054 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14055 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14056 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14057 - /*
14058 - * Segments used for calling PnP BIOS have byte granularity.
14059 - * They code segments and data segments have fixed 64k limits,
14060 - * the transfer segment sizes are set at run time.
14061 - */
14062 - /* 32-bit code */
14063 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14064 - /* 16-bit code */
14065 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14066 - /* 16-bit data */
14067 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14068 - /* 16-bit data */
14069 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14070 - /* 16-bit data */
14071 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14072 - /*
14073 - * The APM segments have byte granularity and their bases
14074 - * are set at run time. All have 64k limits.
14075 - */
14076 - /* 32-bit code */
14077 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14078 - /* 16-bit code */
14079 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14080 - /* data */
14081 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14082 -
14083 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14084 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14085 - GDT_STACK_CANARY_INIT
14086 -#endif
14087 -} };
14088 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14089 -
14090 static int __init x86_xsave_setup(char *s)
14091 {
14092 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14093 @@ -374,7 +320,7 @@ void switch_to_new_gdt(int cpu)
14094 {
14095 struct desc_ptr gdt_descr;
14096
14097 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14098 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14099 gdt_descr.size = GDT_SIZE - 1;
14100 load_gdt(&gdt_descr);
14101 /* Reload the per-cpu base */
14102 @@ -841,6 +787,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14103 /* Filter out anything that depends on CPUID levels we don't have */
14104 filter_cpuid_features(c, true);
14105
14106 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14107 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14108 +#endif
14109 +
14110 /* If the model name is still unset, do table lookup. */
14111 if (!c->x86_model_id[0]) {
14112 const char *p;
14113 @@ -1021,10 +971,12 @@ static __init int setup_disablecpuid(char *arg)
14114 }
14115 __setup("clearcpuid=", setup_disablecpuid);
14116
14117 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14118 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14119 +
14120 #ifdef CONFIG_X86_64
14121 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14122 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14123 - (unsigned long) nmi_idt_table };
14124 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14125
14126 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14127 irq_stack_union) __aligned(PAGE_SIZE);
14128 @@ -1038,7 +990,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14129 EXPORT_PER_CPU_SYMBOL(current_task);
14130
14131 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14132 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14133 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14134 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14135
14136 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14137 @@ -1132,7 +1084,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14138 {
14139 memset(regs, 0, sizeof(struct pt_regs));
14140 regs->fs = __KERNEL_PERCPU;
14141 - regs->gs = __KERNEL_STACK_CANARY;
14142 + savesegment(gs, regs->gs);
14143
14144 return regs;
14145 }
14146 @@ -1187,7 +1139,7 @@ void __cpuinit cpu_init(void)
14147 int i;
14148
14149 cpu = stack_smp_processor_id();
14150 - t = &per_cpu(init_tss, cpu);
14151 + t = init_tss + cpu;
14152 oist = &per_cpu(orig_ist, cpu);
14153
14154 #ifdef CONFIG_NUMA
14155 @@ -1213,7 +1165,7 @@ void __cpuinit cpu_init(void)
14156 switch_to_new_gdt(cpu);
14157 loadsegment(fs, 0);
14158
14159 - load_idt((const struct desc_ptr *)&idt_descr);
14160 + load_idt(&idt_descr);
14161
14162 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14163 syscall_init();
14164 @@ -1222,7 +1174,6 @@ void __cpuinit cpu_init(void)
14165 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14166 barrier();
14167
14168 - x86_configure_nx();
14169 if (cpu != 0)
14170 enable_x2apic();
14171
14172 @@ -1278,7 +1229,7 @@ void __cpuinit cpu_init(void)
14173 {
14174 int cpu = smp_processor_id();
14175 struct task_struct *curr = current;
14176 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14177 + struct tss_struct *t = init_tss + cpu;
14178 struct thread_struct *thread = &curr->thread;
14179
14180 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14181 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14182 index 3e6ff6c..54b4992 100644
14183 --- a/arch/x86/kernel/cpu/intel.c
14184 +++ b/arch/x86/kernel/cpu/intel.c
14185 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14186 * Update the IDT descriptor and reload the IDT so that
14187 * it uses the read-only mapped virtual address.
14188 */
14189 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14190 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14191 load_idt(&idt_descr);
14192 }
14193 #endif
14194 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14195 index c46ed49..5dc0a53 100644
14196 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14197 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14198 @@ -42,6 +42,7 @@
14199 #include <asm/processor.h>
14200 #include <asm/mce.h>
14201 #include <asm/msr.h>
14202 +#include <asm/local.h>
14203
14204 #include "mce-internal.h"
14205
14206 @@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14207 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14208 m->cs, m->ip);
14209
14210 - if (m->cs == __KERNEL_CS)
14211 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14212 print_symbol("{%s}", m->ip);
14213 pr_cont("\n");
14214 }
14215 @@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14216
14217 #define PANIC_TIMEOUT 5 /* 5 seconds */
14218
14219 -static atomic_t mce_paniced;
14220 +static atomic_unchecked_t mce_paniced;
14221
14222 static int fake_panic;
14223 -static atomic_t mce_fake_paniced;
14224 +static atomic_unchecked_t mce_fake_paniced;
14225
14226 /* Panic in progress. Enable interrupts and wait for final IPI */
14227 static void wait_for_panic(void)
14228 @@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14229 /*
14230 * Make sure only one CPU runs in machine check panic
14231 */
14232 - if (atomic_inc_return(&mce_paniced) > 1)
14233 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14234 wait_for_panic();
14235 barrier();
14236
14237 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14238 console_verbose();
14239 } else {
14240 /* Don't log too much for fake panic */
14241 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14242 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14243 return;
14244 }
14245 /* First print corrected ones that are still unlogged */
14246 @@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
14247 * might have been modified by someone else.
14248 */
14249 rmb();
14250 - if (atomic_read(&mce_paniced))
14251 + if (atomic_read_unchecked(&mce_paniced))
14252 wait_for_panic();
14253 if (!monarch_timeout)
14254 goto out;
14255 @@ -1581,7 +1582,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14256 }
14257
14258 /* Call the installed machine check handler for this CPU setup. */
14259 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14260 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14261 unexpected_machine_check;
14262
14263 /*
14264 @@ -1604,7 +1605,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14265 return;
14266 }
14267
14268 + pax_open_kernel();
14269 machine_check_vector = do_machine_check;
14270 + pax_close_kernel();
14271
14272 __mcheck_cpu_init_generic();
14273 __mcheck_cpu_init_vendor(c);
14274 @@ -1618,7 +1621,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14275 */
14276
14277 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14278 -static int mce_chrdev_open_count; /* #times opened */
14279 +static local_t mce_chrdev_open_count; /* #times opened */
14280 static int mce_chrdev_open_exclu; /* already open exclusive? */
14281
14282 static int mce_chrdev_open(struct inode *inode, struct file *file)
14283 @@ -1626,7 +1629,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14284 spin_lock(&mce_chrdev_state_lock);
14285
14286 if (mce_chrdev_open_exclu ||
14287 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14288 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14289 spin_unlock(&mce_chrdev_state_lock);
14290
14291 return -EBUSY;
14292 @@ -1634,7 +1637,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14293
14294 if (file->f_flags & O_EXCL)
14295 mce_chrdev_open_exclu = 1;
14296 - mce_chrdev_open_count++;
14297 + local_inc(&mce_chrdev_open_count);
14298
14299 spin_unlock(&mce_chrdev_state_lock);
14300
14301 @@ -1645,7 +1648,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14302 {
14303 spin_lock(&mce_chrdev_state_lock);
14304
14305 - mce_chrdev_open_count--;
14306 + local_dec(&mce_chrdev_open_count);
14307 mce_chrdev_open_exclu = 0;
14308
14309 spin_unlock(&mce_chrdev_state_lock);
14310 @@ -2370,7 +2373,7 @@ struct dentry *mce_get_debugfs_dir(void)
14311 static void mce_reset(void)
14312 {
14313 cpu_missing = 0;
14314 - atomic_set(&mce_fake_paniced, 0);
14315 + atomic_set_unchecked(&mce_fake_paniced, 0);
14316 atomic_set(&mce_executing, 0);
14317 atomic_set(&mce_callin, 0);
14318 atomic_set(&global_nwo, 0);
14319 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14320 index 2d5454c..51987eb 100644
14321 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14322 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14323 @@ -11,6 +11,7 @@
14324 #include <asm/processor.h>
14325 #include <asm/mce.h>
14326 #include <asm/msr.h>
14327 +#include <asm/pgtable.h>
14328
14329 /* By default disabled */
14330 int mce_p5_enabled __read_mostly;
14331 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14332 if (!cpu_has(c, X86_FEATURE_MCE))
14333 return;
14334
14335 + pax_open_kernel();
14336 machine_check_vector = pentium_machine_check;
14337 + pax_close_kernel();
14338 /* Make sure the vector pointer is visible before we enable MCEs: */
14339 wmb();
14340
14341 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14342 index 2d7998f..17c9de1 100644
14343 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14344 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14345 @@ -10,6 +10,7 @@
14346 #include <asm/processor.h>
14347 #include <asm/mce.h>
14348 #include <asm/msr.h>
14349 +#include <asm/pgtable.h>
14350
14351 /* Machine check handler for WinChip C6: */
14352 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14353 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14354 {
14355 u32 lo, hi;
14356
14357 + pax_open_kernel();
14358 machine_check_vector = winchip_machine_check;
14359 + pax_close_kernel();
14360 /* Make sure the vector pointer is visible before we enable MCEs: */
14361 wmb();
14362
14363 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14364 index 6b96110..0da73eb 100644
14365 --- a/arch/x86/kernel/cpu/mtrr/main.c
14366 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14367 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14368 u64 size_or_mask, size_and_mask;
14369 static bool mtrr_aps_delayed_init;
14370
14371 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14372 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14373
14374 const struct mtrr_ops *mtrr_if;
14375
14376 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14377 index df5e41f..816c719 100644
14378 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14379 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14380 @@ -25,7 +25,7 @@ struct mtrr_ops {
14381 int (*validate_add_page)(unsigned long base, unsigned long size,
14382 unsigned int type);
14383 int (*have_wrcomb)(void);
14384 -};
14385 +} __do_const;
14386
14387 extern int generic_get_free_region(unsigned long base, unsigned long size,
14388 int replace_reg);
14389 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14390 index c4706cf..264b0f7 100644
14391 --- a/arch/x86/kernel/cpu/perf_event.c
14392 +++ b/arch/x86/kernel/cpu/perf_event.c
14393 @@ -1837,7 +1837,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14394 break;
14395
14396 perf_callchain_store(entry, frame.return_address);
14397 - fp = frame.next_frame;
14398 + fp = (const void __force_user *)frame.next_frame;
14399 }
14400 }
14401
14402 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14403 index 13ad899..f642b9a 100644
14404 --- a/arch/x86/kernel/crash.c
14405 +++ b/arch/x86/kernel/crash.c
14406 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14407 {
14408 #ifdef CONFIG_X86_32
14409 struct pt_regs fixed_regs;
14410 -#endif
14411
14412 -#ifdef CONFIG_X86_32
14413 - if (!user_mode_vm(regs)) {
14414 + if (!user_mode(regs)) {
14415 crash_fixup_ss_esp(&fixed_regs, regs);
14416 regs = &fixed_regs;
14417 }
14418 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14419 index 37250fe..bf2ec74 100644
14420 --- a/arch/x86/kernel/doublefault_32.c
14421 +++ b/arch/x86/kernel/doublefault_32.c
14422 @@ -11,7 +11,7 @@
14423
14424 #define DOUBLEFAULT_STACKSIZE (1024)
14425 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14426 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14427 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14428
14429 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14430
14431 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14432 unsigned long gdt, tss;
14433
14434 store_gdt(&gdt_desc);
14435 - gdt = gdt_desc.address;
14436 + gdt = (unsigned long)gdt_desc.address;
14437
14438 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14439
14440 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14441 /* 0x2 bit is always set */
14442 .flags = X86_EFLAGS_SF | 0x2,
14443 .sp = STACK_START,
14444 - .es = __USER_DS,
14445 + .es = __KERNEL_DS,
14446 .cs = __KERNEL_CS,
14447 .ss = __KERNEL_DS,
14448 - .ds = __USER_DS,
14449 + .ds = __KERNEL_DS,
14450 .fs = __KERNEL_PERCPU,
14451
14452 .__cr3 = __pa_nodebug(swapper_pg_dir),
14453 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14454 index 571246d..81f335c 100644
14455 --- a/arch/x86/kernel/dumpstack.c
14456 +++ b/arch/x86/kernel/dumpstack.c
14457 @@ -2,6 +2,9 @@
14458 * Copyright (C) 1991, 1992 Linus Torvalds
14459 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14460 */
14461 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14462 +#define __INCLUDED_BY_HIDESYM 1
14463 +#endif
14464 #include <linux/kallsyms.h>
14465 #include <linux/kprobes.h>
14466 #include <linux/uaccess.h>
14467 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14468 static void
14469 print_ftrace_graph_addr(unsigned long addr, void *data,
14470 const struct stacktrace_ops *ops,
14471 - struct thread_info *tinfo, int *graph)
14472 + struct task_struct *task, int *graph)
14473 {
14474 - struct task_struct *task;
14475 unsigned long ret_addr;
14476 int index;
14477
14478 if (addr != (unsigned long)return_to_handler)
14479 return;
14480
14481 - task = tinfo->task;
14482 index = task->curr_ret_stack;
14483
14484 if (!task->ret_stack || index < *graph)
14485 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14486 static inline void
14487 print_ftrace_graph_addr(unsigned long addr, void *data,
14488 const struct stacktrace_ops *ops,
14489 - struct thread_info *tinfo, int *graph)
14490 + struct task_struct *task, int *graph)
14491 { }
14492 #endif
14493
14494 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14495 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14496 */
14497
14498 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14499 - void *p, unsigned int size, void *end)
14500 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14501 {
14502 - void *t = tinfo;
14503 if (end) {
14504 if (p < end && p >= (end-THREAD_SIZE))
14505 return 1;
14506 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14507 }
14508
14509 unsigned long
14510 -print_context_stack(struct thread_info *tinfo,
14511 +print_context_stack(struct task_struct *task, void *stack_start,
14512 unsigned long *stack, unsigned long bp,
14513 const struct stacktrace_ops *ops, void *data,
14514 unsigned long *end, int *graph)
14515 {
14516 struct stack_frame *frame = (struct stack_frame *)bp;
14517
14518 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14519 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14520 unsigned long addr;
14521
14522 addr = *stack;
14523 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14524 } else {
14525 ops->address(data, addr, 0);
14526 }
14527 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14528 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14529 }
14530 stack++;
14531 }
14532 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14533 EXPORT_SYMBOL_GPL(print_context_stack);
14534
14535 unsigned long
14536 -print_context_stack_bp(struct thread_info *tinfo,
14537 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14538 unsigned long *stack, unsigned long bp,
14539 const struct stacktrace_ops *ops, void *data,
14540 unsigned long *end, int *graph)
14541 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14542 struct stack_frame *frame = (struct stack_frame *)bp;
14543 unsigned long *ret_addr = &frame->return_address;
14544
14545 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14546 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14547 unsigned long addr = *ret_addr;
14548
14549 if (!__kernel_text_address(addr))
14550 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14551 ops->address(data, addr, 1);
14552 frame = frame->next_frame;
14553 ret_addr = &frame->return_address;
14554 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14555 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14556 }
14557
14558 return (unsigned long)frame;
14559 @@ -189,7 +188,7 @@ void dump_stack(void)
14560
14561 bp = stack_frame(current, NULL);
14562 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14563 - current->pid, current->comm, print_tainted(),
14564 + task_pid_nr(current), current->comm, print_tainted(),
14565 init_utsname()->release,
14566 (int)strcspn(init_utsname()->version, " "),
14567 init_utsname()->version);
14568 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14569 }
14570 EXPORT_SYMBOL_GPL(oops_begin);
14571
14572 +extern void gr_handle_kernel_exploit(void);
14573 +
14574 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14575 {
14576 if (regs && kexec_should_crash(current))
14577 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14578 panic("Fatal exception in interrupt");
14579 if (panic_on_oops)
14580 panic("Fatal exception");
14581 - do_exit(signr);
14582 +
14583 + gr_handle_kernel_exploit();
14584 +
14585 + do_group_exit(signr);
14586 }
14587
14588 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14589 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14590
14591 show_regs(regs);
14592 #ifdef CONFIG_X86_32
14593 - if (user_mode_vm(regs)) {
14594 + if (user_mode(regs)) {
14595 sp = regs->sp;
14596 ss = regs->ss & 0xffff;
14597 } else {
14598 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14599 unsigned long flags = oops_begin();
14600 int sig = SIGSEGV;
14601
14602 - if (!user_mode_vm(regs))
14603 + if (!user_mode(regs))
14604 report_bug(regs->ip, regs);
14605
14606 if (__die(str, regs, err))
14607 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14608 index e0b1d78..a8ade5e 100644
14609 --- a/arch/x86/kernel/dumpstack_32.c
14610 +++ b/arch/x86/kernel/dumpstack_32.c
14611 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14612 bp = stack_frame(task, regs);
14613
14614 for (;;) {
14615 - struct thread_info *context;
14616 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14617
14618 - context = (struct thread_info *)
14619 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14620 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14621 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14622
14623 - stack = (unsigned long *)context->previous_esp;
14624 - if (!stack)
14625 + if (stack_start == task_stack_page(task))
14626 break;
14627 + stack = *(unsigned long **)stack_start;
14628 if (ops->stack(data, "IRQ") < 0)
14629 break;
14630 touch_nmi_watchdog();
14631 @@ -87,7 +85,7 @@ void show_regs(struct pt_regs *regs)
14632 int i;
14633
14634 print_modules();
14635 - __show_regs(regs, !user_mode_vm(regs));
14636 + __show_regs(regs, !user_mode(regs));
14637
14638 printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14639 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14640 @@ -96,21 +94,22 @@ void show_regs(struct pt_regs *regs)
14641 * When in-kernel, we also print out the stack and code at the
14642 * time of the fault..
14643 */
14644 - if (!user_mode_vm(regs)) {
14645 + if (!user_mode(regs)) {
14646 unsigned int code_prologue = code_bytes * 43 / 64;
14647 unsigned int code_len = code_bytes;
14648 unsigned char c;
14649 u8 *ip;
14650 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14651
14652 printk(KERN_EMERG "Stack:\n");
14653 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14654
14655 printk(KERN_EMERG "Code: ");
14656
14657 - ip = (u8 *)regs->ip - code_prologue;
14658 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14659 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14660 /* try starting at IP */
14661 - ip = (u8 *)regs->ip;
14662 + ip = (u8 *)regs->ip + cs_base;
14663 code_len = code_len - code_prologue + 1;
14664 }
14665 for (i = 0; i < code_len; i++, ip++) {
14666 @@ -119,7 +118,7 @@ void show_regs(struct pt_regs *regs)
14667 printk(KERN_CONT " Bad EIP value.");
14668 break;
14669 }
14670 - if (ip == (u8 *)regs->ip)
14671 + if (ip == (u8 *)regs->ip + cs_base)
14672 printk(KERN_CONT "<%02x> ", c);
14673 else
14674 printk(KERN_CONT "%02x ", c);
14675 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14676 {
14677 unsigned short ud2;
14678
14679 + ip = ktla_ktva(ip);
14680 if (ip < PAGE_OFFSET)
14681 return 0;
14682 if (probe_kernel_address((unsigned short *)ip, ud2))
14683 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14684
14685 return ud2 == 0x0b0f;
14686 }
14687 +
14688 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14689 +void pax_check_alloca(unsigned long size)
14690 +{
14691 + unsigned long sp = (unsigned long)&sp, stack_left;
14692 +
14693 + /* all kernel stacks are of the same size */
14694 + stack_left = sp & (THREAD_SIZE - 1);
14695 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14696 +}
14697 +EXPORT_SYMBOL(pax_check_alloca);
14698 +#endif
14699 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14700 index 791b761..2ab6e33 100644
14701 --- a/arch/x86/kernel/dumpstack_64.c
14702 +++ b/arch/x86/kernel/dumpstack_64.c
14703 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14704 unsigned long *irq_stack_end =
14705 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14706 unsigned used = 0;
14707 - struct thread_info *tinfo;
14708 int graph = 0;
14709 unsigned long dummy;
14710 + void *stack_start;
14711
14712 if (!task)
14713 task = current;
14714 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14715 * current stack address. If the stacks consist of nested
14716 * exceptions
14717 */
14718 - tinfo = task_thread_info(task);
14719 for (;;) {
14720 char *id;
14721 unsigned long *estack_end;
14722 +
14723 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14724 &used, &id);
14725
14726 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14727 if (ops->stack(data, id) < 0)
14728 break;
14729
14730 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14731 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14732 data, estack_end, &graph);
14733 ops->stack(data, "<EOE>");
14734 /*
14735 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14736 * second-to-last pointer (index -2 to end) in the
14737 * exception stack:
14738 */
14739 + if ((u16)estack_end[-1] != __KERNEL_DS)
14740 + goto out;
14741 stack = (unsigned long *) estack_end[-2];
14742 continue;
14743 }
14744 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14745 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14746 if (ops->stack(data, "IRQ") < 0)
14747 break;
14748 - bp = ops->walk_stack(tinfo, stack, bp,
14749 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14750 ops, data, irq_stack_end, &graph);
14751 /*
14752 * We link to the next stack (which would be
14753 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14754 /*
14755 * This handles the process stack:
14756 */
14757 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14758 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14759 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14760 +out:
14761 put_cpu();
14762 }
14763 EXPORT_SYMBOL(dump_trace);
14764 @@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14765
14766 return ud2 == 0x0b0f;
14767 }
14768 +
14769 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14770 +void pax_check_alloca(unsigned long size)
14771 +{
14772 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14773 + unsigned cpu, used;
14774 + char *id;
14775 +
14776 + /* check the process stack first */
14777 + stack_start = (unsigned long)task_stack_page(current);
14778 + stack_end = stack_start + THREAD_SIZE;
14779 + if (likely(stack_start <= sp && sp < stack_end)) {
14780 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14781 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14782 + return;
14783 + }
14784 +
14785 + cpu = get_cpu();
14786 +
14787 + /* check the irq stacks */
14788 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14789 + stack_start = stack_end - IRQ_STACK_SIZE;
14790 + if (stack_start <= sp && sp < stack_end) {
14791 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14792 + put_cpu();
14793 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14794 + return;
14795 + }
14796 +
14797 + /* check the exception stacks */
14798 + used = 0;
14799 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14800 + stack_start = stack_end - EXCEPTION_STKSZ;
14801 + if (stack_end && stack_start <= sp && sp < stack_end) {
14802 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14803 + put_cpu();
14804 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14805 + return;
14806 + }
14807 +
14808 + put_cpu();
14809 +
14810 + /* unknown stack */
14811 + BUG();
14812 +}
14813 +EXPORT_SYMBOL(pax_check_alloca);
14814 +#endif
14815 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14816 index 9b9f18b..9fcaa04 100644
14817 --- a/arch/x86/kernel/early_printk.c
14818 +++ b/arch/x86/kernel/early_printk.c
14819 @@ -7,6 +7,7 @@
14820 #include <linux/pci_regs.h>
14821 #include <linux/pci_ids.h>
14822 #include <linux/errno.h>
14823 +#include <linux/sched.h>
14824 #include <asm/io.h>
14825 #include <asm/processor.h>
14826 #include <asm/fcntl.h>
14827 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14828 index 623f288..0683156 100644
14829 --- a/arch/x86/kernel/entry_32.S
14830 +++ b/arch/x86/kernel/entry_32.S
14831 @@ -176,13 +176,146 @@
14832 /*CFI_REL_OFFSET gs, PT_GS*/
14833 .endm
14834 .macro SET_KERNEL_GS reg
14835 +
14836 +#ifdef CONFIG_CC_STACKPROTECTOR
14837 movl $(__KERNEL_STACK_CANARY), \reg
14838 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14839 + movl $(__USER_DS), \reg
14840 +#else
14841 + xorl \reg, \reg
14842 +#endif
14843 +
14844 movl \reg, %gs
14845 .endm
14846
14847 #endif /* CONFIG_X86_32_LAZY_GS */
14848
14849 -.macro SAVE_ALL
14850 +.macro pax_enter_kernel
14851 +#ifdef CONFIG_PAX_KERNEXEC
14852 + call pax_enter_kernel
14853 +#endif
14854 +.endm
14855 +
14856 +.macro pax_exit_kernel
14857 +#ifdef CONFIG_PAX_KERNEXEC
14858 + call pax_exit_kernel
14859 +#endif
14860 +.endm
14861 +
14862 +#ifdef CONFIG_PAX_KERNEXEC
14863 +ENTRY(pax_enter_kernel)
14864 +#ifdef CONFIG_PARAVIRT
14865 + pushl %eax
14866 + pushl %ecx
14867 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14868 + mov %eax, %esi
14869 +#else
14870 + mov %cr0, %esi
14871 +#endif
14872 + bts $16, %esi
14873 + jnc 1f
14874 + mov %cs, %esi
14875 + cmp $__KERNEL_CS, %esi
14876 + jz 3f
14877 + ljmp $__KERNEL_CS, $3f
14878 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14879 +2:
14880 +#ifdef CONFIG_PARAVIRT
14881 + mov %esi, %eax
14882 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14883 +#else
14884 + mov %esi, %cr0
14885 +#endif
14886 +3:
14887 +#ifdef CONFIG_PARAVIRT
14888 + popl %ecx
14889 + popl %eax
14890 +#endif
14891 + ret
14892 +ENDPROC(pax_enter_kernel)
14893 +
14894 +ENTRY(pax_exit_kernel)
14895 +#ifdef CONFIG_PARAVIRT
14896 + pushl %eax
14897 + pushl %ecx
14898 +#endif
14899 + mov %cs, %esi
14900 + cmp $__KERNEXEC_KERNEL_CS, %esi
14901 + jnz 2f
14902 +#ifdef CONFIG_PARAVIRT
14903 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14904 + mov %eax, %esi
14905 +#else
14906 + mov %cr0, %esi
14907 +#endif
14908 + btr $16, %esi
14909 + ljmp $__KERNEL_CS, $1f
14910 +1:
14911 +#ifdef CONFIG_PARAVIRT
14912 + mov %esi, %eax
14913 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14914 +#else
14915 + mov %esi, %cr0
14916 +#endif
14917 +2:
14918 +#ifdef CONFIG_PARAVIRT
14919 + popl %ecx
14920 + popl %eax
14921 +#endif
14922 + ret
14923 +ENDPROC(pax_exit_kernel)
14924 +#endif
14925 +
14926 +.macro pax_erase_kstack
14927 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14928 + call pax_erase_kstack
14929 +#endif
14930 +.endm
14931 +
14932 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14933 +/*
14934 + * ebp: thread_info
14935 + * ecx, edx: can be clobbered
14936 + */
14937 +ENTRY(pax_erase_kstack)
14938 + pushl %edi
14939 + pushl %eax
14940 +
14941 + mov TI_lowest_stack(%ebp), %edi
14942 + mov $-0xBEEF, %eax
14943 + std
14944 +
14945 +1: mov %edi, %ecx
14946 + and $THREAD_SIZE_asm - 1, %ecx
14947 + shr $2, %ecx
14948 + repne scasl
14949 + jecxz 2f
14950 +
14951 + cmp $2*16, %ecx
14952 + jc 2f
14953 +
14954 + mov $2*16, %ecx
14955 + repe scasl
14956 + jecxz 2f
14957 + jne 1b
14958 +
14959 +2: cld
14960 + mov %esp, %ecx
14961 + sub %edi, %ecx
14962 + shr $2, %ecx
14963 + rep stosl
14964 +
14965 + mov TI_task_thread_sp0(%ebp), %edi
14966 + sub $128, %edi
14967 + mov %edi, TI_lowest_stack(%ebp)
14968 +
14969 + popl %eax
14970 + popl %edi
14971 + ret
14972 +ENDPROC(pax_erase_kstack)
14973 +#endif
14974 +
14975 +.macro __SAVE_ALL _DS
14976 cld
14977 PUSH_GS
14978 pushl_cfi %fs
14979 @@ -205,7 +338,7 @@
14980 CFI_REL_OFFSET ecx, 0
14981 pushl_cfi %ebx
14982 CFI_REL_OFFSET ebx, 0
14983 - movl $(__USER_DS), %edx
14984 + movl $\_DS, %edx
14985 movl %edx, %ds
14986 movl %edx, %es
14987 movl $(__KERNEL_PERCPU), %edx
14988 @@ -213,6 +346,15 @@
14989 SET_KERNEL_GS %edx
14990 .endm
14991
14992 +.macro SAVE_ALL
14993 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
14994 + __SAVE_ALL __KERNEL_DS
14995 + pax_enter_kernel
14996 +#else
14997 + __SAVE_ALL __USER_DS
14998 +#endif
14999 +.endm
15000 +
15001 .macro RESTORE_INT_REGS
15002 popl_cfi %ebx
15003 CFI_RESTORE ebx
15004 @@ -296,7 +438,7 @@ ENTRY(ret_from_fork)
15005 popfl_cfi
15006 jmp syscall_exit
15007 CFI_ENDPROC
15008 -END(ret_from_fork)
15009 +ENDPROC(ret_from_fork)
15010
15011 /*
15012 * Interrupt exit functions should be protected against kprobes
15013 @@ -329,7 +471,15 @@ ret_from_intr:
15014 andl $SEGMENT_RPL_MASK, %eax
15015 #endif
15016 cmpl $USER_RPL, %eax
15017 +
15018 +#ifdef CONFIG_PAX_KERNEXEC
15019 + jae resume_userspace
15020 +
15021 + pax_exit_kernel
15022 + jmp resume_kernel
15023 +#else
15024 jb resume_kernel # not returning to v8086 or userspace
15025 +#endif
15026
15027 ENTRY(resume_userspace)
15028 LOCKDEP_SYS_EXIT
15029 @@ -341,8 +491,8 @@ ENTRY(resume_userspace)
15030 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15031 # int/exception return?
15032 jne work_pending
15033 - jmp restore_all
15034 -END(ret_from_exception)
15035 + jmp restore_all_pax
15036 +ENDPROC(ret_from_exception)
15037
15038 #ifdef CONFIG_PREEMPT
15039 ENTRY(resume_kernel)
15040 @@ -357,7 +507,7 @@ need_resched:
15041 jz restore_all
15042 call preempt_schedule_irq
15043 jmp need_resched
15044 -END(resume_kernel)
15045 +ENDPROC(resume_kernel)
15046 #endif
15047 CFI_ENDPROC
15048 /*
15049 @@ -391,23 +541,34 @@ sysenter_past_esp:
15050 /*CFI_REL_OFFSET cs, 0*/
15051 /*
15052 * Push current_thread_info()->sysenter_return to the stack.
15053 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15054 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15055 */
15056 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15057 + pushl_cfi $0
15058 CFI_REL_OFFSET eip, 0
15059
15060 pushl_cfi %eax
15061 SAVE_ALL
15062 + GET_THREAD_INFO(%ebp)
15063 + movl TI_sysenter_return(%ebp),%ebp
15064 + movl %ebp,PT_EIP(%esp)
15065 ENABLE_INTERRUPTS(CLBR_NONE)
15066
15067 /*
15068 * Load the potential sixth argument from user stack.
15069 * Careful about security.
15070 */
15071 + movl PT_OLDESP(%esp),%ebp
15072 +
15073 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15074 + mov PT_OLDSS(%esp),%ds
15075 +1: movl %ds:(%ebp),%ebp
15076 + push %ss
15077 + pop %ds
15078 +#else
15079 cmpl $__PAGE_OFFSET-3,%ebp
15080 jae syscall_fault
15081 1: movl (%ebp),%ebp
15082 +#endif
15083 +
15084 movl %ebp,PT_EBP(%esp)
15085 _ASM_EXTABLE(1b,syscall_fault)
15086
15087 @@ -427,12 +588,24 @@ sysenter_do_call:
15088 testl $_TIF_ALLWORK_MASK, %ecx
15089 jne sysexit_audit
15090 sysenter_exit:
15091 +
15092 +#ifdef CONFIG_PAX_RANDKSTACK
15093 + pushl_cfi %eax
15094 + movl %esp, %eax
15095 + call pax_randomize_kstack
15096 + popl_cfi %eax
15097 +#endif
15098 +
15099 + pax_erase_kstack
15100 +
15101 /* if something modifies registers it must also disable sysexit */
15102 movl PT_EIP(%esp), %edx
15103 movl PT_OLDESP(%esp), %ecx
15104 xorl %ebp,%ebp
15105 TRACE_IRQS_ON
15106 1: mov PT_FS(%esp), %fs
15107 +2: mov PT_DS(%esp), %ds
15108 +3: mov PT_ES(%esp), %es
15109 PTGS_TO_GS
15110 ENABLE_INTERRUPTS_SYSEXIT
15111
15112 @@ -449,6 +622,9 @@ sysenter_audit:
15113 movl %eax,%edx /* 2nd arg: syscall number */
15114 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15115 call __audit_syscall_entry
15116 +
15117 + pax_erase_kstack
15118 +
15119 pushl_cfi %ebx
15120 movl PT_EAX(%esp),%eax /* reload syscall number */
15121 jmp sysenter_do_call
15122 @@ -474,10 +650,16 @@ sysexit_audit:
15123
15124 CFI_ENDPROC
15125 .pushsection .fixup,"ax"
15126 -2: movl $0,PT_FS(%esp)
15127 +4: movl $0,PT_FS(%esp)
15128 + jmp 1b
15129 +5: movl $0,PT_DS(%esp)
15130 + jmp 1b
15131 +6: movl $0,PT_ES(%esp)
15132 jmp 1b
15133 .popsection
15134 - _ASM_EXTABLE(1b,2b)
15135 + _ASM_EXTABLE(1b,4b)
15136 + _ASM_EXTABLE(2b,5b)
15137 + _ASM_EXTABLE(3b,6b)
15138 PTGS_TO_GS_EX
15139 ENDPROC(ia32_sysenter_target)
15140
15141 @@ -509,6 +691,15 @@ syscall_exit:
15142 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15143 jne syscall_exit_work
15144
15145 +restore_all_pax:
15146 +
15147 +#ifdef CONFIG_PAX_RANDKSTACK
15148 + movl %esp, %eax
15149 + call pax_randomize_kstack
15150 +#endif
15151 +
15152 + pax_erase_kstack
15153 +
15154 restore_all:
15155 TRACE_IRQS_IRET
15156 restore_all_notrace:
15157 @@ -565,14 +756,34 @@ ldt_ss:
15158 * compensating for the offset by changing to the ESPFIX segment with
15159 * a base address that matches for the difference.
15160 */
15161 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15162 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15163 mov %esp, %edx /* load kernel esp */
15164 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15165 mov %dx, %ax /* eax: new kernel esp */
15166 sub %eax, %edx /* offset (low word is 0) */
15167 +#ifdef CONFIG_SMP
15168 + movl PER_CPU_VAR(cpu_number), %ebx
15169 + shll $PAGE_SHIFT_asm, %ebx
15170 + addl $cpu_gdt_table, %ebx
15171 +#else
15172 + movl $cpu_gdt_table, %ebx
15173 +#endif
15174 shr $16, %edx
15175 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15176 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15177 +
15178 +#ifdef CONFIG_PAX_KERNEXEC
15179 + mov %cr0, %esi
15180 + btr $16, %esi
15181 + mov %esi, %cr0
15182 +#endif
15183 +
15184 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15185 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15186 +
15187 +#ifdef CONFIG_PAX_KERNEXEC
15188 + bts $16, %esi
15189 + mov %esi, %cr0
15190 +#endif
15191 +
15192 pushl_cfi $__ESPFIX_SS
15193 pushl_cfi %eax /* new kernel esp */
15194 /* Disable interrupts, but do not irqtrace this section: we
15195 @@ -601,35 +812,23 @@ work_resched:
15196 movl TI_flags(%ebp), %ecx
15197 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15198 # than syscall tracing?
15199 - jz restore_all
15200 + jz restore_all_pax
15201 testb $_TIF_NEED_RESCHED, %cl
15202 jnz work_resched
15203
15204 work_notifysig: # deal with pending signals and
15205 # notify-resume requests
15206 + movl %esp, %eax
15207 #ifdef CONFIG_VM86
15208 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15209 - movl %esp, %eax
15210 - jne work_notifysig_v86 # returning to kernel-space or
15211 + jz 1f # returning to kernel-space or
15212 # vm86-space
15213 - TRACE_IRQS_ON
15214 - ENABLE_INTERRUPTS(CLBR_NONE)
15215 - movb PT_CS(%esp), %bl
15216 - andb $SEGMENT_RPL_MASK, %bl
15217 - cmpb $USER_RPL, %bl
15218 - jb resume_kernel
15219 - xorl %edx, %edx
15220 - call do_notify_resume
15221 - jmp resume_userspace
15222
15223 - ALIGN
15224 -work_notifysig_v86:
15225 pushl_cfi %ecx # save ti_flags for do_notify_resume
15226 call save_v86_state # %eax contains pt_regs pointer
15227 popl_cfi %ecx
15228 movl %eax, %esp
15229 -#else
15230 - movl %esp, %eax
15231 +1:
15232 #endif
15233 TRACE_IRQS_ON
15234 ENABLE_INTERRUPTS(CLBR_NONE)
15235 @@ -640,7 +839,7 @@ work_notifysig_v86:
15236 xorl %edx, %edx
15237 call do_notify_resume
15238 jmp resume_userspace
15239 -END(work_pending)
15240 +ENDPROC(work_pending)
15241
15242 # perform syscall exit tracing
15243 ALIGN
15244 @@ -648,11 +847,14 @@ syscall_trace_entry:
15245 movl $-ENOSYS,PT_EAX(%esp)
15246 movl %esp, %eax
15247 call syscall_trace_enter
15248 +
15249 + pax_erase_kstack
15250 +
15251 /* What it returned is what we'll actually use. */
15252 cmpl $(NR_syscalls), %eax
15253 jnae syscall_call
15254 jmp syscall_exit
15255 -END(syscall_trace_entry)
15256 +ENDPROC(syscall_trace_entry)
15257
15258 # perform syscall exit tracing
15259 ALIGN
15260 @@ -665,20 +867,24 @@ syscall_exit_work:
15261 movl %esp, %eax
15262 call syscall_trace_leave
15263 jmp resume_userspace
15264 -END(syscall_exit_work)
15265 +ENDPROC(syscall_exit_work)
15266 CFI_ENDPROC
15267
15268 RING0_INT_FRAME # can't unwind into user space anyway
15269 syscall_fault:
15270 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15271 + push %ss
15272 + pop %ds
15273 +#endif
15274 GET_THREAD_INFO(%ebp)
15275 movl $-EFAULT,PT_EAX(%esp)
15276 jmp resume_userspace
15277 -END(syscall_fault)
15278 +ENDPROC(syscall_fault)
15279
15280 syscall_badsys:
15281 movl $-ENOSYS,PT_EAX(%esp)
15282 jmp resume_userspace
15283 -END(syscall_badsys)
15284 +ENDPROC(syscall_badsys)
15285 CFI_ENDPROC
15286 /*
15287 * End of kprobes section
15288 @@ -750,6 +956,36 @@ ENTRY(ptregs_clone)
15289 CFI_ENDPROC
15290 ENDPROC(ptregs_clone)
15291
15292 + ALIGN;
15293 +ENTRY(kernel_execve)
15294 + CFI_STARTPROC
15295 + pushl_cfi %ebp
15296 + sub $PT_OLDSS+4,%esp
15297 + pushl_cfi %edi
15298 + pushl_cfi %ecx
15299 + pushl_cfi %eax
15300 + lea 3*4(%esp),%edi
15301 + mov $PT_OLDSS/4+1,%ecx
15302 + xorl %eax,%eax
15303 + rep stosl
15304 + popl_cfi %eax
15305 + popl_cfi %ecx
15306 + popl_cfi %edi
15307 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15308 + pushl_cfi %esp
15309 + call sys_execve
15310 + add $4,%esp
15311 + CFI_ADJUST_CFA_OFFSET -4
15312 + GET_THREAD_INFO(%ebp)
15313 + test %eax,%eax
15314 + jz syscall_exit
15315 + add $PT_OLDSS+4,%esp
15316 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15317 + popl_cfi %ebp
15318 + ret
15319 + CFI_ENDPROC
15320 +ENDPROC(kernel_execve)
15321 +
15322 .macro FIXUP_ESPFIX_STACK
15323 /*
15324 * Switch back for ESPFIX stack to the normal zerobased stack
15325 @@ -759,8 +995,15 @@ ENDPROC(ptregs_clone)
15326 * normal stack and adjusts ESP with the matching offset.
15327 */
15328 /* fixup the stack */
15329 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15330 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15331 +#ifdef CONFIG_SMP
15332 + movl PER_CPU_VAR(cpu_number), %ebx
15333 + shll $PAGE_SHIFT_asm, %ebx
15334 + addl $cpu_gdt_table, %ebx
15335 +#else
15336 + movl $cpu_gdt_table, %ebx
15337 +#endif
15338 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15339 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15340 shl $16, %eax
15341 addl %esp, %eax /* the adjusted stack pointer */
15342 pushl_cfi $__KERNEL_DS
15343 @@ -813,7 +1056,7 @@ vector=vector+1
15344 .endr
15345 2: jmp common_interrupt
15346 .endr
15347 -END(irq_entries_start)
15348 +ENDPROC(irq_entries_start)
15349
15350 .previous
15351 END(interrupt)
15352 @@ -861,7 +1104,7 @@ ENTRY(coprocessor_error)
15353 pushl_cfi $do_coprocessor_error
15354 jmp error_code
15355 CFI_ENDPROC
15356 -END(coprocessor_error)
15357 +ENDPROC(coprocessor_error)
15358
15359 ENTRY(simd_coprocessor_error)
15360 RING0_INT_FRAME
15361 @@ -882,7 +1125,7 @@ ENTRY(simd_coprocessor_error)
15362 #endif
15363 jmp error_code
15364 CFI_ENDPROC
15365 -END(simd_coprocessor_error)
15366 +ENDPROC(simd_coprocessor_error)
15367
15368 ENTRY(device_not_available)
15369 RING0_INT_FRAME
15370 @@ -890,18 +1133,18 @@ ENTRY(device_not_available)
15371 pushl_cfi $do_device_not_available
15372 jmp error_code
15373 CFI_ENDPROC
15374 -END(device_not_available)
15375 +ENDPROC(device_not_available)
15376
15377 #ifdef CONFIG_PARAVIRT
15378 ENTRY(native_iret)
15379 iret
15380 _ASM_EXTABLE(native_iret, iret_exc)
15381 -END(native_iret)
15382 +ENDPROC(native_iret)
15383
15384 ENTRY(native_irq_enable_sysexit)
15385 sti
15386 sysexit
15387 -END(native_irq_enable_sysexit)
15388 +ENDPROC(native_irq_enable_sysexit)
15389 #endif
15390
15391 ENTRY(overflow)
15392 @@ -910,7 +1153,7 @@ ENTRY(overflow)
15393 pushl_cfi $do_overflow
15394 jmp error_code
15395 CFI_ENDPROC
15396 -END(overflow)
15397 +ENDPROC(overflow)
15398
15399 ENTRY(bounds)
15400 RING0_INT_FRAME
15401 @@ -918,7 +1161,7 @@ ENTRY(bounds)
15402 pushl_cfi $do_bounds
15403 jmp error_code
15404 CFI_ENDPROC
15405 -END(bounds)
15406 +ENDPROC(bounds)
15407
15408 ENTRY(invalid_op)
15409 RING0_INT_FRAME
15410 @@ -926,7 +1169,7 @@ ENTRY(invalid_op)
15411 pushl_cfi $do_invalid_op
15412 jmp error_code
15413 CFI_ENDPROC
15414 -END(invalid_op)
15415 +ENDPROC(invalid_op)
15416
15417 ENTRY(coprocessor_segment_overrun)
15418 RING0_INT_FRAME
15419 @@ -934,35 +1177,35 @@ ENTRY(coprocessor_segment_overrun)
15420 pushl_cfi $do_coprocessor_segment_overrun
15421 jmp error_code
15422 CFI_ENDPROC
15423 -END(coprocessor_segment_overrun)
15424 +ENDPROC(coprocessor_segment_overrun)
15425
15426 ENTRY(invalid_TSS)
15427 RING0_EC_FRAME
15428 pushl_cfi $do_invalid_TSS
15429 jmp error_code
15430 CFI_ENDPROC
15431 -END(invalid_TSS)
15432 +ENDPROC(invalid_TSS)
15433
15434 ENTRY(segment_not_present)
15435 RING0_EC_FRAME
15436 pushl_cfi $do_segment_not_present
15437 jmp error_code
15438 CFI_ENDPROC
15439 -END(segment_not_present)
15440 +ENDPROC(segment_not_present)
15441
15442 ENTRY(stack_segment)
15443 RING0_EC_FRAME
15444 pushl_cfi $do_stack_segment
15445 jmp error_code
15446 CFI_ENDPROC
15447 -END(stack_segment)
15448 +ENDPROC(stack_segment)
15449
15450 ENTRY(alignment_check)
15451 RING0_EC_FRAME
15452 pushl_cfi $do_alignment_check
15453 jmp error_code
15454 CFI_ENDPROC
15455 -END(alignment_check)
15456 +ENDPROC(alignment_check)
15457
15458 ENTRY(divide_error)
15459 RING0_INT_FRAME
15460 @@ -970,7 +1213,7 @@ ENTRY(divide_error)
15461 pushl_cfi $do_divide_error
15462 jmp error_code
15463 CFI_ENDPROC
15464 -END(divide_error)
15465 +ENDPROC(divide_error)
15466
15467 #ifdef CONFIG_X86_MCE
15468 ENTRY(machine_check)
15469 @@ -979,7 +1222,7 @@ ENTRY(machine_check)
15470 pushl_cfi machine_check_vector
15471 jmp error_code
15472 CFI_ENDPROC
15473 -END(machine_check)
15474 +ENDPROC(machine_check)
15475 #endif
15476
15477 ENTRY(spurious_interrupt_bug)
15478 @@ -988,7 +1231,7 @@ ENTRY(spurious_interrupt_bug)
15479 pushl_cfi $do_spurious_interrupt_bug
15480 jmp error_code
15481 CFI_ENDPROC
15482 -END(spurious_interrupt_bug)
15483 +ENDPROC(spurious_interrupt_bug)
15484 /*
15485 * End of kprobes section
15486 */
15487 @@ -1100,7 +1343,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15488
15489 ENTRY(mcount)
15490 ret
15491 -END(mcount)
15492 +ENDPROC(mcount)
15493
15494 ENTRY(ftrace_caller)
15495 cmpl $0, function_trace_stop
15496 @@ -1129,7 +1372,7 @@ ftrace_graph_call:
15497 .globl ftrace_stub
15498 ftrace_stub:
15499 ret
15500 -END(ftrace_caller)
15501 +ENDPROC(ftrace_caller)
15502
15503 #else /* ! CONFIG_DYNAMIC_FTRACE */
15504
15505 @@ -1165,7 +1408,7 @@ trace:
15506 popl %ecx
15507 popl %eax
15508 jmp ftrace_stub
15509 -END(mcount)
15510 +ENDPROC(mcount)
15511 #endif /* CONFIG_DYNAMIC_FTRACE */
15512 #endif /* CONFIG_FUNCTION_TRACER */
15513
15514 @@ -1186,7 +1429,7 @@ ENTRY(ftrace_graph_caller)
15515 popl %ecx
15516 popl %eax
15517 ret
15518 -END(ftrace_graph_caller)
15519 +ENDPROC(ftrace_graph_caller)
15520
15521 .globl return_to_handler
15522 return_to_handler:
15523 @@ -1241,15 +1484,18 @@ error_code:
15524 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15525 REG_TO_PTGS %ecx
15526 SET_KERNEL_GS %ecx
15527 - movl $(__USER_DS), %ecx
15528 + movl $(__KERNEL_DS), %ecx
15529 movl %ecx, %ds
15530 movl %ecx, %es
15531 +
15532 + pax_enter_kernel
15533 +
15534 TRACE_IRQS_OFF
15535 movl %esp,%eax # pt_regs pointer
15536 call *%edi
15537 jmp ret_from_exception
15538 CFI_ENDPROC
15539 -END(page_fault)
15540 +ENDPROC(page_fault)
15541
15542 /*
15543 * Debug traps and NMI can happen at the one SYSENTER instruction
15544 @@ -1291,7 +1537,7 @@ debug_stack_correct:
15545 call do_debug
15546 jmp ret_from_exception
15547 CFI_ENDPROC
15548 -END(debug)
15549 +ENDPROC(debug)
15550
15551 /*
15552 * NMI is doubly nasty. It can happen _while_ we're handling
15553 @@ -1328,6 +1574,9 @@ nmi_stack_correct:
15554 xorl %edx,%edx # zero error code
15555 movl %esp,%eax # pt_regs pointer
15556 call do_nmi
15557 +
15558 + pax_exit_kernel
15559 +
15560 jmp restore_all_notrace
15561 CFI_ENDPROC
15562
15563 @@ -1364,12 +1613,15 @@ nmi_espfix_stack:
15564 FIXUP_ESPFIX_STACK # %eax == %esp
15565 xorl %edx,%edx # zero error code
15566 call do_nmi
15567 +
15568 + pax_exit_kernel
15569 +
15570 RESTORE_REGS
15571 lss 12+4(%esp), %esp # back to espfix stack
15572 CFI_ADJUST_CFA_OFFSET -24
15573 jmp irq_return
15574 CFI_ENDPROC
15575 -END(nmi)
15576 +ENDPROC(nmi)
15577
15578 ENTRY(int3)
15579 RING0_INT_FRAME
15580 @@ -1381,14 +1633,14 @@ ENTRY(int3)
15581 call do_int3
15582 jmp ret_from_exception
15583 CFI_ENDPROC
15584 -END(int3)
15585 +ENDPROC(int3)
15586
15587 ENTRY(general_protection)
15588 RING0_EC_FRAME
15589 pushl_cfi $do_general_protection
15590 jmp error_code
15591 CFI_ENDPROC
15592 -END(general_protection)
15593 +ENDPROC(general_protection)
15594
15595 #ifdef CONFIG_KVM_GUEST
15596 ENTRY(async_page_fault)
15597 @@ -1396,7 +1648,7 @@ ENTRY(async_page_fault)
15598 pushl_cfi $do_async_page_fault
15599 jmp error_code
15600 CFI_ENDPROC
15601 -END(async_page_fault)
15602 +ENDPROC(async_page_fault)
15603 #endif
15604
15605 /*
15606 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15607 index 7d65133..27bce5b 100644
15608 --- a/arch/x86/kernel/entry_64.S
15609 +++ b/arch/x86/kernel/entry_64.S
15610 @@ -57,6 +57,8 @@
15611 #include <asm/percpu.h>
15612 #include <asm/asm.h>
15613 #include <linux/err.h>
15614 +#include <asm/pgtable.h>
15615 +#include <asm/alternative-asm.h>
15616
15617 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15618 #include <linux/elf-em.h>
15619 @@ -70,8 +72,9 @@
15620 #ifdef CONFIG_FUNCTION_TRACER
15621 #ifdef CONFIG_DYNAMIC_FTRACE
15622 ENTRY(mcount)
15623 + pax_force_retaddr
15624 retq
15625 -END(mcount)
15626 +ENDPROC(mcount)
15627
15628 ENTRY(ftrace_caller)
15629 cmpl $0, function_trace_stop
15630 @@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15631 #endif
15632
15633 GLOBAL(ftrace_stub)
15634 + pax_force_retaddr
15635 retq
15636 -END(ftrace_caller)
15637 +ENDPROC(ftrace_caller)
15638
15639 #else /* ! CONFIG_DYNAMIC_FTRACE */
15640 ENTRY(mcount)
15641 @@ -114,6 +118,7 @@ ENTRY(mcount)
15642 #endif
15643
15644 GLOBAL(ftrace_stub)
15645 + pax_force_retaddr
15646 retq
15647
15648 trace:
15649 @@ -123,12 +128,13 @@ trace:
15650 movq 8(%rbp), %rsi
15651 subq $MCOUNT_INSN_SIZE, %rdi
15652
15653 + pax_force_fptr ftrace_trace_function
15654 call *ftrace_trace_function
15655
15656 MCOUNT_RESTORE_FRAME
15657
15658 jmp ftrace_stub
15659 -END(mcount)
15660 +ENDPROC(mcount)
15661 #endif /* CONFIG_DYNAMIC_FTRACE */
15662 #endif /* CONFIG_FUNCTION_TRACER */
15663
15664 @@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15665
15666 MCOUNT_RESTORE_FRAME
15667
15668 + pax_force_retaddr
15669 retq
15670 -END(ftrace_graph_caller)
15671 +ENDPROC(ftrace_graph_caller)
15672
15673 GLOBAL(return_to_handler)
15674 subq $24, %rsp
15675 @@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15676 movq 8(%rsp), %rdx
15677 movq (%rsp), %rax
15678 addq $24, %rsp
15679 + pax_force_fptr %rdi
15680 jmp *%rdi
15681 #endif
15682
15683 @@ -180,6 +188,282 @@ ENTRY(native_usergs_sysret64)
15684 ENDPROC(native_usergs_sysret64)
15685 #endif /* CONFIG_PARAVIRT */
15686
15687 + .macro ljmpq sel, off
15688 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15689 + .byte 0x48; ljmp *1234f(%rip)
15690 + .pushsection .rodata
15691 + .align 16
15692 + 1234: .quad \off; .word \sel
15693 + .popsection
15694 +#else
15695 + pushq $\sel
15696 + pushq $\off
15697 + lretq
15698 +#endif
15699 + .endm
15700 +
15701 + .macro pax_enter_kernel
15702 + pax_set_fptr_mask
15703 +#ifdef CONFIG_PAX_KERNEXEC
15704 + call pax_enter_kernel
15705 +#endif
15706 + .endm
15707 +
15708 + .macro pax_exit_kernel
15709 +#ifdef CONFIG_PAX_KERNEXEC
15710 + call pax_exit_kernel
15711 +#endif
15712 + .endm
15713 +
15714 +#ifdef CONFIG_PAX_KERNEXEC
15715 +ENTRY(pax_enter_kernel)
15716 + pushq %rdi
15717 +
15718 +#ifdef CONFIG_PARAVIRT
15719 + PV_SAVE_REGS(CLBR_RDI)
15720 +#endif
15721 +
15722 + GET_CR0_INTO_RDI
15723 + bts $16,%rdi
15724 + jnc 3f
15725 + mov %cs,%edi
15726 + cmp $__KERNEL_CS,%edi
15727 + jnz 2f
15728 +1:
15729 +
15730 +#ifdef CONFIG_PARAVIRT
15731 + PV_RESTORE_REGS(CLBR_RDI)
15732 +#endif
15733 +
15734 + popq %rdi
15735 + pax_force_retaddr
15736 + retq
15737 +
15738 +2: ljmpq __KERNEL_CS,1f
15739 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15740 +4: SET_RDI_INTO_CR0
15741 + jmp 1b
15742 +ENDPROC(pax_enter_kernel)
15743 +
15744 +ENTRY(pax_exit_kernel)
15745 + pushq %rdi
15746 +
15747 +#ifdef CONFIG_PARAVIRT
15748 + PV_SAVE_REGS(CLBR_RDI)
15749 +#endif
15750 +
15751 + mov %cs,%rdi
15752 + cmp $__KERNEXEC_KERNEL_CS,%edi
15753 + jz 2f
15754 +1:
15755 +
15756 +#ifdef CONFIG_PARAVIRT
15757 + PV_RESTORE_REGS(CLBR_RDI);
15758 +#endif
15759 +
15760 + popq %rdi
15761 + pax_force_retaddr
15762 + retq
15763 +
15764 +2: GET_CR0_INTO_RDI
15765 + btr $16,%rdi
15766 + ljmpq __KERNEL_CS,3f
15767 +3: SET_RDI_INTO_CR0
15768 + jmp 1b
15769 +#ifdef CONFIG_PARAVIRT
15770 + PV_RESTORE_REGS(CLBR_RDI);
15771 +#endif
15772 +
15773 + popq %rdi
15774 + pax_force_retaddr
15775 + retq
15776 +ENDPROC(pax_exit_kernel)
15777 +#endif
15778 +
15779 + .macro pax_enter_kernel_user
15780 + pax_set_fptr_mask
15781 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15782 + call pax_enter_kernel_user
15783 +#endif
15784 + .endm
15785 +
15786 + .macro pax_exit_kernel_user
15787 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15788 + call pax_exit_kernel_user
15789 +#endif
15790 +#ifdef CONFIG_PAX_RANDKSTACK
15791 + pushq %rax
15792 + call pax_randomize_kstack
15793 + popq %rax
15794 +#endif
15795 + .endm
15796 +
15797 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15798 +ENTRY(pax_enter_kernel_user)
15799 + pushq %rdi
15800 + pushq %rbx
15801 +
15802 +#ifdef CONFIG_PARAVIRT
15803 + PV_SAVE_REGS(CLBR_RDI)
15804 +#endif
15805 +
15806 + GET_CR3_INTO_RDI
15807 + mov %rdi,%rbx
15808 + add $__START_KERNEL_map,%rbx
15809 + sub phys_base(%rip),%rbx
15810 +
15811 +#ifdef CONFIG_PARAVIRT
15812 + pushq %rdi
15813 + cmpl $0, pv_info+PARAVIRT_enabled
15814 + jz 1f
15815 + i = 0
15816 + .rept USER_PGD_PTRS
15817 + mov i*8(%rbx),%rsi
15818 + mov $0,%sil
15819 + lea i*8(%rbx),%rdi
15820 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15821 + i = i + 1
15822 + .endr
15823 + jmp 2f
15824 +1:
15825 +#endif
15826 +
15827 + i = 0
15828 + .rept USER_PGD_PTRS
15829 + movb $0,i*8(%rbx)
15830 + i = i + 1
15831 + .endr
15832 +
15833 +#ifdef CONFIG_PARAVIRT
15834 +2: popq %rdi
15835 +#endif
15836 + SET_RDI_INTO_CR3
15837 +
15838 +#ifdef CONFIG_PAX_KERNEXEC
15839 + GET_CR0_INTO_RDI
15840 + bts $16,%rdi
15841 + SET_RDI_INTO_CR0
15842 +#endif
15843 +
15844 +#ifdef CONFIG_PARAVIRT
15845 + PV_RESTORE_REGS(CLBR_RDI)
15846 +#endif
15847 +
15848 + popq %rbx
15849 + popq %rdi
15850 + pax_force_retaddr
15851 + retq
15852 +ENDPROC(pax_enter_kernel_user)
15853 +
15854 +ENTRY(pax_exit_kernel_user)
15855 + push %rdi
15856 +
15857 +#ifdef CONFIG_PARAVIRT
15858 + pushq %rbx
15859 + PV_SAVE_REGS(CLBR_RDI)
15860 +#endif
15861 +
15862 +#ifdef CONFIG_PAX_KERNEXEC
15863 + GET_CR0_INTO_RDI
15864 + btr $16,%rdi
15865 + SET_RDI_INTO_CR0
15866 +#endif
15867 +
15868 + GET_CR3_INTO_RDI
15869 + add $__START_KERNEL_map,%rdi
15870 + sub phys_base(%rip),%rdi
15871 +
15872 +#ifdef CONFIG_PARAVIRT
15873 + cmpl $0, pv_info+PARAVIRT_enabled
15874 + jz 1f
15875 + mov %rdi,%rbx
15876 + i = 0
15877 + .rept USER_PGD_PTRS
15878 + mov i*8(%rbx),%rsi
15879 + mov $0x67,%sil
15880 + lea i*8(%rbx),%rdi
15881 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15882 + i = i + 1
15883 + .endr
15884 + jmp 2f
15885 +1:
15886 +#endif
15887 +
15888 + i = 0
15889 + .rept USER_PGD_PTRS
15890 + movb $0x67,i*8(%rdi)
15891 + i = i + 1
15892 + .endr
15893 +
15894 +#ifdef CONFIG_PARAVIRT
15895 +2: PV_RESTORE_REGS(CLBR_RDI)
15896 + popq %rbx
15897 +#endif
15898 +
15899 + popq %rdi
15900 + pax_force_retaddr
15901 + retq
15902 +ENDPROC(pax_exit_kernel_user)
15903 +#endif
15904 +
15905 +.macro pax_erase_kstack
15906 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15907 + call pax_erase_kstack
15908 +#endif
15909 +.endm
15910 +
15911 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15912 +/*
15913 + * r11: thread_info
15914 + * rcx, rdx: can be clobbered
15915 + */
15916 +ENTRY(pax_erase_kstack)
15917 + pushq %rdi
15918 + pushq %rax
15919 + pushq %r11
15920 +
15921 + GET_THREAD_INFO(%r11)
15922 + mov TI_lowest_stack(%r11), %rdi
15923 + mov $-0xBEEF, %rax
15924 + std
15925 +
15926 +1: mov %edi, %ecx
15927 + and $THREAD_SIZE_asm - 1, %ecx
15928 + shr $3, %ecx
15929 + repne scasq
15930 + jecxz 2f
15931 +
15932 + cmp $2*8, %ecx
15933 + jc 2f
15934 +
15935 + mov $2*8, %ecx
15936 + repe scasq
15937 + jecxz 2f
15938 + jne 1b
15939 +
15940 +2: cld
15941 + mov %esp, %ecx
15942 + sub %edi, %ecx
15943 +
15944 + cmp $THREAD_SIZE_asm, %rcx
15945 + jb 3f
15946 + ud2
15947 +3:
15948 +
15949 + shr $3, %ecx
15950 + rep stosq
15951 +
15952 + mov TI_task_thread_sp0(%r11), %rdi
15953 + sub $256, %rdi
15954 + mov %rdi, TI_lowest_stack(%r11)
15955 +
15956 + popq %r11
15957 + popq %rax
15958 + popq %rdi
15959 + pax_force_retaddr
15960 + ret
15961 +ENDPROC(pax_erase_kstack)
15962 +#endif
15963
15964 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
15965 #ifdef CONFIG_TRACE_IRQFLAGS
15966 @@ -271,8 +555,8 @@ ENDPROC(native_usergs_sysret64)
15967 .endm
15968
15969 .macro UNFAKE_STACK_FRAME
15970 - addq $8*6, %rsp
15971 - CFI_ADJUST_CFA_OFFSET -(6*8)
15972 + addq $8*6 + ARG_SKIP, %rsp
15973 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
15974 .endm
15975
15976 /*
15977 @@ -359,7 +643,7 @@ ENDPROC(native_usergs_sysret64)
15978 movq %rsp, %rsi
15979
15980 leaq -RBP(%rsp),%rdi /* arg1 for handler */
15981 - testl $3, CS-RBP(%rsi)
15982 + testb $3, CS-RBP(%rsi)
15983 je 1f
15984 SWAPGS
15985 /*
15986 @@ -394,9 +678,10 @@ ENTRY(save_rest)
15987 movq_cfi r15, R15+16
15988 movq %r11, 8(%rsp) /* return address */
15989 FIXUP_TOP_OF_STACK %r11, 16
15990 + pax_force_retaddr
15991 ret
15992 CFI_ENDPROC
15993 -END(save_rest)
15994 +ENDPROC(save_rest)
15995
15996 /* save complete stack frame */
15997 .pushsection .kprobes.text, "ax"
15998 @@ -425,9 +710,10 @@ ENTRY(save_paranoid)
15999 js 1f /* negative -> in kernel */
16000 SWAPGS
16001 xorl %ebx,%ebx
16002 -1: ret
16003 +1: pax_force_retaddr_bts
16004 + ret
16005 CFI_ENDPROC
16006 -END(save_paranoid)
16007 +ENDPROC(save_paranoid)
16008 .popsection
16009
16010 /*
16011 @@ -449,7 +735,7 @@ ENTRY(ret_from_fork)
16012
16013 RESTORE_REST
16014
16015 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16016 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16017 jz retint_restore_args
16018
16019 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16020 @@ -459,7 +745,7 @@ ENTRY(ret_from_fork)
16021 jmp ret_from_sys_call # go to the SYSRET fastpath
16022
16023 CFI_ENDPROC
16024 -END(ret_from_fork)
16025 +ENDPROC(ret_from_fork)
16026
16027 /*
16028 * System call entry. Up to 6 arguments in registers are supported.
16029 @@ -495,7 +781,7 @@ END(ret_from_fork)
16030 ENTRY(system_call)
16031 CFI_STARTPROC simple
16032 CFI_SIGNAL_FRAME
16033 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16034 + CFI_DEF_CFA rsp,0
16035 CFI_REGISTER rip,rcx
16036 /*CFI_REGISTER rflags,r11*/
16037 SWAPGS_UNSAFE_STACK
16038 @@ -508,16 +794,18 @@ GLOBAL(system_call_after_swapgs)
16039
16040 movq %rsp,PER_CPU_VAR(old_rsp)
16041 movq PER_CPU_VAR(kernel_stack),%rsp
16042 + SAVE_ARGS 8*6,0
16043 + pax_enter_kernel_user
16044 /*
16045 * No need to follow this irqs off/on section - it's straight
16046 * and short:
16047 */
16048 ENABLE_INTERRUPTS(CLBR_NONE)
16049 - SAVE_ARGS 8,0
16050 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16051 movq %rcx,RIP-ARGOFFSET(%rsp)
16052 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16053 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16054 + GET_THREAD_INFO(%rcx)
16055 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16056 jnz tracesys
16057 system_call_fastpath:
16058 #if __SYSCALL_MASK == ~0
16059 @@ -527,7 +815,7 @@ system_call_fastpath:
16060 cmpl $__NR_syscall_max,%eax
16061 #endif
16062 ja badsys
16063 - movq %r10,%rcx
16064 + movq R10-ARGOFFSET(%rsp),%rcx
16065 call *sys_call_table(,%rax,8) # XXX: rip relative
16066 movq %rax,RAX-ARGOFFSET(%rsp)
16067 /*
16068 @@ -541,10 +829,13 @@ sysret_check:
16069 LOCKDEP_SYS_EXIT
16070 DISABLE_INTERRUPTS(CLBR_NONE)
16071 TRACE_IRQS_OFF
16072 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16073 + GET_THREAD_INFO(%rcx)
16074 + movl TI_flags(%rcx),%edx
16075 andl %edi,%edx
16076 jnz sysret_careful
16077 CFI_REMEMBER_STATE
16078 + pax_exit_kernel_user
16079 + pax_erase_kstack
16080 /*
16081 * sysretq will re-enable interrupts:
16082 */
16083 @@ -596,14 +887,18 @@ badsys:
16084 * jump back to the normal fast path.
16085 */
16086 auditsys:
16087 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16088 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16089 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16090 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16091 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16092 movq %rax,%rsi /* 2nd arg: syscall number */
16093 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16094 call __audit_syscall_entry
16095 +
16096 + pax_erase_kstack
16097 +
16098 LOAD_ARGS 0 /* reload call-clobbered registers */
16099 + pax_set_fptr_mask
16100 jmp system_call_fastpath
16101
16102 /*
16103 @@ -624,7 +919,7 @@ sysret_audit:
16104 /* Do syscall tracing */
16105 tracesys:
16106 #ifdef CONFIG_AUDITSYSCALL
16107 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16108 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16109 jz auditsys
16110 #endif
16111 SAVE_REST
16112 @@ -632,12 +927,16 @@ tracesys:
16113 FIXUP_TOP_OF_STACK %rdi
16114 movq %rsp,%rdi
16115 call syscall_trace_enter
16116 +
16117 + pax_erase_kstack
16118 +
16119 /*
16120 * Reload arg registers from stack in case ptrace changed them.
16121 * We don't reload %rax because syscall_trace_enter() returned
16122 * the value it wants us to use in the table lookup.
16123 */
16124 LOAD_ARGS ARGOFFSET, 1
16125 + pax_set_fptr_mask
16126 RESTORE_REST
16127 #if __SYSCALL_MASK == ~0
16128 cmpq $__NR_syscall_max,%rax
16129 @@ -646,7 +945,7 @@ tracesys:
16130 cmpl $__NR_syscall_max,%eax
16131 #endif
16132 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16133 - movq %r10,%rcx /* fixup for C */
16134 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16135 call *sys_call_table(,%rax,8)
16136 movq %rax,RAX-ARGOFFSET(%rsp)
16137 /* Use IRET because user could have changed frame */
16138 @@ -667,6 +966,7 @@ GLOBAL(int_with_check)
16139 andl %edi,%edx
16140 jnz int_careful
16141 andl $~TS_COMPAT,TI_status(%rcx)
16142 + pax_erase_kstack
16143 jmp retint_swapgs
16144
16145 /* Either reschedule or signal or syscall exit tracking needed. */
16146 @@ -713,7 +1013,7 @@ int_restore_rest:
16147 TRACE_IRQS_OFF
16148 jmp int_with_check
16149 CFI_ENDPROC
16150 -END(system_call)
16151 +ENDPROC(system_call)
16152
16153 /*
16154 * Certain special system calls that need to save a complete full stack frame.
16155 @@ -729,7 +1029,7 @@ ENTRY(\label)
16156 call \func
16157 jmp ptregscall_common
16158 CFI_ENDPROC
16159 -END(\label)
16160 +ENDPROC(\label)
16161 .endm
16162
16163 PTREGSCALL stub_clone, sys_clone, %r8
16164 @@ -747,9 +1047,10 @@ ENTRY(ptregscall_common)
16165 movq_cfi_restore R12+8, r12
16166 movq_cfi_restore RBP+8, rbp
16167 movq_cfi_restore RBX+8, rbx
16168 + pax_force_retaddr
16169 ret $REST_SKIP /* pop extended registers */
16170 CFI_ENDPROC
16171 -END(ptregscall_common)
16172 +ENDPROC(ptregscall_common)
16173
16174 ENTRY(stub_execve)
16175 CFI_STARTPROC
16176 @@ -764,7 +1065,7 @@ ENTRY(stub_execve)
16177 RESTORE_REST
16178 jmp int_ret_from_sys_call
16179 CFI_ENDPROC
16180 -END(stub_execve)
16181 +ENDPROC(stub_execve)
16182
16183 /*
16184 * sigreturn is special because it needs to restore all registers on return.
16185 @@ -782,7 +1083,7 @@ ENTRY(stub_rt_sigreturn)
16186 RESTORE_REST
16187 jmp int_ret_from_sys_call
16188 CFI_ENDPROC
16189 -END(stub_rt_sigreturn)
16190 +ENDPROC(stub_rt_sigreturn)
16191
16192 #ifdef CONFIG_X86_X32_ABI
16193 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16194 @@ -851,7 +1152,7 @@ vector=vector+1
16195 2: jmp common_interrupt
16196 .endr
16197 CFI_ENDPROC
16198 -END(irq_entries_start)
16199 +ENDPROC(irq_entries_start)
16200
16201 .previous
16202 END(interrupt)
16203 @@ -871,6 +1172,16 @@ END(interrupt)
16204 subq $ORIG_RAX-RBP, %rsp
16205 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16206 SAVE_ARGS_IRQ
16207 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16208 + testb $3, CS(%rdi)
16209 + jnz 1f
16210 + pax_enter_kernel
16211 + jmp 2f
16212 +1: pax_enter_kernel_user
16213 +2:
16214 +#else
16215 + pax_enter_kernel
16216 +#endif
16217 call \func
16218 .endm
16219
16220 @@ -902,7 +1213,7 @@ ret_from_intr:
16221
16222 exit_intr:
16223 GET_THREAD_INFO(%rcx)
16224 - testl $3,CS-ARGOFFSET(%rsp)
16225 + testb $3,CS-ARGOFFSET(%rsp)
16226 je retint_kernel
16227
16228 /* Interrupt came from user space */
16229 @@ -924,12 +1235,15 @@ retint_swapgs: /* return to user-space */
16230 * The iretq could re-enable interrupts:
16231 */
16232 DISABLE_INTERRUPTS(CLBR_ANY)
16233 + pax_exit_kernel_user
16234 TRACE_IRQS_IRETQ
16235 SWAPGS
16236 jmp restore_args
16237
16238 retint_restore_args: /* return to kernel space */
16239 DISABLE_INTERRUPTS(CLBR_ANY)
16240 + pax_exit_kernel
16241 + pax_force_retaddr RIP-ARGOFFSET
16242 /*
16243 * The iretq could re-enable interrupts:
16244 */
16245 @@ -1012,7 +1326,7 @@ ENTRY(retint_kernel)
16246 #endif
16247
16248 CFI_ENDPROC
16249 -END(common_interrupt)
16250 +ENDPROC(common_interrupt)
16251 /*
16252 * End of kprobes section
16253 */
16254 @@ -1029,7 +1343,7 @@ ENTRY(\sym)
16255 interrupt \do_sym
16256 jmp ret_from_intr
16257 CFI_ENDPROC
16258 -END(\sym)
16259 +ENDPROC(\sym)
16260 .endm
16261
16262 #ifdef CONFIG_SMP
16263 @@ -1102,12 +1416,22 @@ ENTRY(\sym)
16264 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16265 call error_entry
16266 DEFAULT_FRAME 0
16267 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16268 + testb $3, CS(%rsp)
16269 + jnz 1f
16270 + pax_enter_kernel
16271 + jmp 2f
16272 +1: pax_enter_kernel_user
16273 +2:
16274 +#else
16275 + pax_enter_kernel
16276 +#endif
16277 movq %rsp,%rdi /* pt_regs pointer */
16278 xorl %esi,%esi /* no error code */
16279 call \do_sym
16280 jmp error_exit /* %ebx: no swapgs flag */
16281 CFI_ENDPROC
16282 -END(\sym)
16283 +ENDPROC(\sym)
16284 .endm
16285
16286 .macro paranoidzeroentry sym do_sym
16287 @@ -1119,15 +1443,25 @@ ENTRY(\sym)
16288 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16289 call save_paranoid
16290 TRACE_IRQS_OFF
16291 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16292 + testb $3, CS(%rsp)
16293 + jnz 1f
16294 + pax_enter_kernel
16295 + jmp 2f
16296 +1: pax_enter_kernel_user
16297 +2:
16298 +#else
16299 + pax_enter_kernel
16300 +#endif
16301 movq %rsp,%rdi /* pt_regs pointer */
16302 xorl %esi,%esi /* no error code */
16303 call \do_sym
16304 jmp paranoid_exit /* %ebx: no swapgs flag */
16305 CFI_ENDPROC
16306 -END(\sym)
16307 +ENDPROC(\sym)
16308 .endm
16309
16310 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16311 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16312 .macro paranoidzeroentry_ist sym do_sym ist
16313 ENTRY(\sym)
16314 INTR_FRAME
16315 @@ -1137,14 +1471,30 @@ ENTRY(\sym)
16316 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16317 call save_paranoid
16318 TRACE_IRQS_OFF_DEBUG
16319 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16320 + testb $3, CS(%rsp)
16321 + jnz 1f
16322 + pax_enter_kernel
16323 + jmp 2f
16324 +1: pax_enter_kernel_user
16325 +2:
16326 +#else
16327 + pax_enter_kernel
16328 +#endif
16329 movq %rsp,%rdi /* pt_regs pointer */
16330 xorl %esi,%esi /* no error code */
16331 +#ifdef CONFIG_SMP
16332 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16333 + lea init_tss(%r12), %r12
16334 +#else
16335 + lea init_tss(%rip), %r12
16336 +#endif
16337 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16338 call \do_sym
16339 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16340 jmp paranoid_exit /* %ebx: no swapgs flag */
16341 CFI_ENDPROC
16342 -END(\sym)
16343 +ENDPROC(\sym)
16344 .endm
16345
16346 .macro errorentry sym do_sym
16347 @@ -1155,13 +1505,23 @@ ENTRY(\sym)
16348 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16349 call error_entry
16350 DEFAULT_FRAME 0
16351 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16352 + testb $3, CS(%rsp)
16353 + jnz 1f
16354 + pax_enter_kernel
16355 + jmp 2f
16356 +1: pax_enter_kernel_user
16357 +2:
16358 +#else
16359 + pax_enter_kernel
16360 +#endif
16361 movq %rsp,%rdi /* pt_regs pointer */
16362 movq ORIG_RAX(%rsp),%rsi /* get error code */
16363 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16364 call \do_sym
16365 jmp error_exit /* %ebx: no swapgs flag */
16366 CFI_ENDPROC
16367 -END(\sym)
16368 +ENDPROC(\sym)
16369 .endm
16370
16371 /* error code is on the stack already */
16372 @@ -1174,13 +1534,23 @@ ENTRY(\sym)
16373 call save_paranoid
16374 DEFAULT_FRAME 0
16375 TRACE_IRQS_OFF
16376 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16377 + testb $3, CS(%rsp)
16378 + jnz 1f
16379 + pax_enter_kernel
16380 + jmp 2f
16381 +1: pax_enter_kernel_user
16382 +2:
16383 +#else
16384 + pax_enter_kernel
16385 +#endif
16386 movq %rsp,%rdi /* pt_regs pointer */
16387 movq ORIG_RAX(%rsp),%rsi /* get error code */
16388 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16389 call \do_sym
16390 jmp paranoid_exit /* %ebx: no swapgs flag */
16391 CFI_ENDPROC
16392 -END(\sym)
16393 +ENDPROC(\sym)
16394 .endm
16395
16396 zeroentry divide_error do_divide_error
16397 @@ -1210,9 +1580,10 @@ gs_change:
16398 2: mfence /* workaround */
16399 SWAPGS
16400 popfq_cfi
16401 + pax_force_retaddr
16402 ret
16403 CFI_ENDPROC
16404 -END(native_load_gs_index)
16405 +ENDPROC(native_load_gs_index)
16406
16407 _ASM_EXTABLE(gs_change,bad_gs)
16408 .section .fixup,"ax"
16409 @@ -1231,13 +1602,14 @@ ENTRY(kernel_thread_helper)
16410 * Here we are in the child and the registers are set as they were
16411 * at kernel_thread() invocation in the parent.
16412 */
16413 + pax_force_fptr %rsi
16414 call *%rsi
16415 # exit
16416 mov %eax, %edi
16417 call do_exit
16418 ud2 # padding for call trace
16419 CFI_ENDPROC
16420 -END(kernel_thread_helper)
16421 +ENDPROC(kernel_thread_helper)
16422
16423 /*
16424 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16425 @@ -1264,11 +1636,11 @@ ENTRY(kernel_execve)
16426 RESTORE_REST
16427 testq %rax,%rax
16428 je int_ret_from_sys_call
16429 - RESTORE_ARGS
16430 UNFAKE_STACK_FRAME
16431 + pax_force_retaddr
16432 ret
16433 CFI_ENDPROC
16434 -END(kernel_execve)
16435 +ENDPROC(kernel_execve)
16436
16437 /* Call softirq on interrupt stack. Interrupts are off. */
16438 ENTRY(call_softirq)
16439 @@ -1286,9 +1658,10 @@ ENTRY(call_softirq)
16440 CFI_DEF_CFA_REGISTER rsp
16441 CFI_ADJUST_CFA_OFFSET -8
16442 decl PER_CPU_VAR(irq_count)
16443 + pax_force_retaddr
16444 ret
16445 CFI_ENDPROC
16446 -END(call_softirq)
16447 +ENDPROC(call_softirq)
16448
16449 #ifdef CONFIG_XEN
16450 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16451 @@ -1326,7 +1699,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16452 decl PER_CPU_VAR(irq_count)
16453 jmp error_exit
16454 CFI_ENDPROC
16455 -END(xen_do_hypervisor_callback)
16456 +ENDPROC(xen_do_hypervisor_callback)
16457
16458 /*
16459 * Hypervisor uses this for application faults while it executes.
16460 @@ -1385,7 +1758,7 @@ ENTRY(xen_failsafe_callback)
16461 SAVE_ALL
16462 jmp error_exit
16463 CFI_ENDPROC
16464 -END(xen_failsafe_callback)
16465 +ENDPROC(xen_failsafe_callback)
16466
16467 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16468 xen_hvm_callback_vector xen_evtchn_do_upcall
16469 @@ -1434,16 +1807,31 @@ ENTRY(paranoid_exit)
16470 TRACE_IRQS_OFF_DEBUG
16471 testl %ebx,%ebx /* swapgs needed? */
16472 jnz paranoid_restore
16473 - testl $3,CS(%rsp)
16474 + testb $3,CS(%rsp)
16475 jnz paranoid_userspace
16476 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16477 + pax_exit_kernel
16478 + TRACE_IRQS_IRETQ 0
16479 + SWAPGS_UNSAFE_STACK
16480 + RESTORE_ALL 8
16481 + pax_force_retaddr_bts
16482 + jmp irq_return
16483 +#endif
16484 paranoid_swapgs:
16485 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16486 + pax_exit_kernel_user
16487 +#else
16488 + pax_exit_kernel
16489 +#endif
16490 TRACE_IRQS_IRETQ 0
16491 SWAPGS_UNSAFE_STACK
16492 RESTORE_ALL 8
16493 jmp irq_return
16494 paranoid_restore:
16495 + pax_exit_kernel
16496 TRACE_IRQS_IRETQ_DEBUG 0
16497 RESTORE_ALL 8
16498 + pax_force_retaddr_bts
16499 jmp irq_return
16500 paranoid_userspace:
16501 GET_THREAD_INFO(%rcx)
16502 @@ -1472,7 +1860,7 @@ paranoid_schedule:
16503 TRACE_IRQS_OFF
16504 jmp paranoid_userspace
16505 CFI_ENDPROC
16506 -END(paranoid_exit)
16507 +ENDPROC(paranoid_exit)
16508
16509 /*
16510 * Exception entry point. This expects an error code/orig_rax on the stack.
16511 @@ -1499,12 +1887,13 @@ ENTRY(error_entry)
16512 movq_cfi r14, R14+8
16513 movq_cfi r15, R15+8
16514 xorl %ebx,%ebx
16515 - testl $3,CS+8(%rsp)
16516 + testb $3,CS+8(%rsp)
16517 je error_kernelspace
16518 error_swapgs:
16519 SWAPGS
16520 error_sti:
16521 TRACE_IRQS_OFF
16522 + pax_force_retaddr_bts
16523 ret
16524
16525 /*
16526 @@ -1531,7 +1920,7 @@ bstep_iret:
16527 movq %rcx,RIP+8(%rsp)
16528 jmp error_swapgs
16529 CFI_ENDPROC
16530 -END(error_entry)
16531 +ENDPROC(error_entry)
16532
16533
16534 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16535 @@ -1551,7 +1940,7 @@ ENTRY(error_exit)
16536 jnz retint_careful
16537 jmp retint_swapgs
16538 CFI_ENDPROC
16539 -END(error_exit)
16540 +ENDPROC(error_exit)
16541
16542 /*
16543 * Test if a given stack is an NMI stack or not.
16544 @@ -1609,9 +1998,11 @@ ENTRY(nmi)
16545 * If %cs was not the kernel segment, then the NMI triggered in user
16546 * space, which means it is definitely not nested.
16547 */
16548 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16549 + je 1f
16550 cmpl $__KERNEL_CS, 16(%rsp)
16551 jne first_nmi
16552 -
16553 +1:
16554 /*
16555 * Check the special variable on the stack to see if NMIs are
16556 * executing.
16557 @@ -1758,6 +2149,16 @@ end_repeat_nmi:
16558 */
16559 call save_paranoid
16560 DEFAULT_FRAME 0
16561 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16562 + testb $3, CS(%rsp)
16563 + jnz 1f
16564 + pax_enter_kernel
16565 + jmp 2f
16566 +1: pax_enter_kernel_user
16567 +2:
16568 +#else
16569 + pax_enter_kernel
16570 +#endif
16571 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16572 movq %rsp,%rdi
16573 movq $-1,%rsi
16574 @@ -1765,21 +2166,32 @@ end_repeat_nmi:
16575 testl %ebx,%ebx /* swapgs needed? */
16576 jnz nmi_restore
16577 nmi_swapgs:
16578 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16579 + pax_exit_kernel_user
16580 +#else
16581 + pax_exit_kernel
16582 +#endif
16583 SWAPGS_UNSAFE_STACK
16584 + RESTORE_ALL 8
16585 + /* Clear the NMI executing stack variable */
16586 + movq $0, 10*8(%rsp)
16587 + jmp irq_return
16588 nmi_restore:
16589 + pax_exit_kernel
16590 RESTORE_ALL 8
16591 + pax_force_retaddr_bts
16592 /* Clear the NMI executing stack variable */
16593 movq $0, 10*8(%rsp)
16594 jmp irq_return
16595 CFI_ENDPROC
16596 -END(nmi)
16597 +ENDPROC(nmi)
16598
16599 ENTRY(ignore_sysret)
16600 CFI_STARTPROC
16601 mov $-ENOSYS,%eax
16602 sysret
16603 CFI_ENDPROC
16604 -END(ignore_sysret)
16605 +ENDPROC(ignore_sysret)
16606
16607 /*
16608 * End of kprobes section
16609 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16610 index c3a7cb4..3ad00dc 100644
16611 --- a/arch/x86/kernel/ftrace.c
16612 +++ b/arch/x86/kernel/ftrace.c
16613 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16614 {
16615 unsigned char replaced[MCOUNT_INSN_SIZE];
16616
16617 + ip = ktla_ktva(ip);
16618 +
16619 /*
16620 * Note: Due to modules and __init, code can
16621 * disappear and change, we need to protect against faulting
16622 @@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16623 unsigned char old[MCOUNT_INSN_SIZE], *new;
16624 int ret;
16625
16626 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16627 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16628 new = ftrace_call_replace(ip, (unsigned long)func);
16629
16630 /* See comment above by declaration of modifying_ftrace_code */
16631 @@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16632 {
16633 unsigned char code[MCOUNT_INSN_SIZE];
16634
16635 + ip = ktla_ktva(ip);
16636 +
16637 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16638 return -EFAULT;
16639
16640 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16641 index c18f59d..9c0c9f6 100644
16642 --- a/arch/x86/kernel/head32.c
16643 +++ b/arch/x86/kernel/head32.c
16644 @@ -18,6 +18,7 @@
16645 #include <asm/io_apic.h>
16646 #include <asm/bios_ebda.h>
16647 #include <asm/tlbflush.h>
16648 +#include <asm/boot.h>
16649
16650 static void __init i386_default_early_setup(void)
16651 {
16652 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16653
16654 void __init i386_start_kernel(void)
16655 {
16656 - memblock_reserve(__pa_symbol(&_text),
16657 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16658 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16659
16660 #ifdef CONFIG_BLK_DEV_INITRD
16661 /* Reserve INITRD */
16662 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16663 index d42ab17..cb1b997 100644
16664 --- a/arch/x86/kernel/head_32.S
16665 +++ b/arch/x86/kernel/head_32.S
16666 @@ -26,6 +26,12 @@
16667 /* Physical address */
16668 #define pa(X) ((X) - __PAGE_OFFSET)
16669
16670 +#ifdef CONFIG_PAX_KERNEXEC
16671 +#define ta(X) (X)
16672 +#else
16673 +#define ta(X) ((X) - __PAGE_OFFSET)
16674 +#endif
16675 +
16676 /*
16677 * References to members of the new_cpu_data structure.
16678 */
16679 @@ -55,11 +61,7 @@
16680 * and small than max_low_pfn, otherwise will waste some page table entries
16681 */
16682
16683 -#if PTRS_PER_PMD > 1
16684 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16685 -#else
16686 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16687 -#endif
16688 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16689
16690 /* Number of possible pages in the lowmem region */
16691 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16692 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16693 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16694
16695 /*
16696 + * Real beginning of normal "text" segment
16697 + */
16698 +ENTRY(stext)
16699 +ENTRY(_stext)
16700 +
16701 +/*
16702 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16703 * %esi points to the real-mode code as a 32-bit pointer.
16704 * CS and DS must be 4 GB flat segments, but we don't depend on
16705 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16706 * can.
16707 */
16708 __HEAD
16709 +
16710 +#ifdef CONFIG_PAX_KERNEXEC
16711 + jmp startup_32
16712 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16713 +.fill PAGE_SIZE-5,1,0xcc
16714 +#endif
16715 +
16716 ENTRY(startup_32)
16717 movl pa(stack_start),%ecx
16718
16719 @@ -106,6 +121,57 @@ ENTRY(startup_32)
16720 2:
16721 leal -__PAGE_OFFSET(%ecx),%esp
16722
16723 +#ifdef CONFIG_SMP
16724 + movl $pa(cpu_gdt_table),%edi
16725 + movl $__per_cpu_load,%eax
16726 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16727 + rorl $16,%eax
16728 + movb %al,__KERNEL_PERCPU + 4(%edi)
16729 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16730 + movl $__per_cpu_end - 1,%eax
16731 + subl $__per_cpu_start,%eax
16732 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16733 +#endif
16734 +
16735 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16736 + movl $NR_CPUS,%ecx
16737 + movl $pa(cpu_gdt_table),%edi
16738 +1:
16739 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16740 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16741 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16742 + addl $PAGE_SIZE_asm,%edi
16743 + loop 1b
16744 +#endif
16745 +
16746 +#ifdef CONFIG_PAX_KERNEXEC
16747 + movl $pa(boot_gdt),%edi
16748 + movl $__LOAD_PHYSICAL_ADDR,%eax
16749 + movw %ax,__BOOT_CS + 2(%edi)
16750 + rorl $16,%eax
16751 + movb %al,__BOOT_CS + 4(%edi)
16752 + movb %ah,__BOOT_CS + 7(%edi)
16753 + rorl $16,%eax
16754 +
16755 + ljmp $(__BOOT_CS),$1f
16756 +1:
16757 +
16758 + movl $NR_CPUS,%ecx
16759 + movl $pa(cpu_gdt_table),%edi
16760 + addl $__PAGE_OFFSET,%eax
16761 +1:
16762 + movw %ax,__KERNEL_CS + 2(%edi)
16763 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16764 + rorl $16,%eax
16765 + movb %al,__KERNEL_CS + 4(%edi)
16766 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16767 + movb %ah,__KERNEL_CS + 7(%edi)
16768 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16769 + rorl $16,%eax
16770 + addl $PAGE_SIZE_asm,%edi
16771 + loop 1b
16772 +#endif
16773 +
16774 /*
16775 * Clear BSS first so that there are no surprises...
16776 */
16777 @@ -196,8 +262,11 @@ ENTRY(startup_32)
16778 movl %eax, pa(max_pfn_mapped)
16779
16780 /* Do early initialization of the fixmap area */
16781 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16782 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16783 +#ifdef CONFIG_COMPAT_VDSO
16784 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16785 +#else
16786 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16787 +#endif
16788 #else /* Not PAE */
16789
16790 page_pde_offset = (__PAGE_OFFSET >> 20);
16791 @@ -227,8 +296,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16792 movl %eax, pa(max_pfn_mapped)
16793
16794 /* Do early initialization of the fixmap area */
16795 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16796 - movl %eax,pa(initial_page_table+0xffc)
16797 +#ifdef CONFIG_COMPAT_VDSO
16798 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16799 +#else
16800 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16801 +#endif
16802 #endif
16803
16804 #ifdef CONFIG_PARAVIRT
16805 @@ -242,9 +314,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16806 cmpl $num_subarch_entries, %eax
16807 jae bad_subarch
16808
16809 - movl pa(subarch_entries)(,%eax,4), %eax
16810 - subl $__PAGE_OFFSET, %eax
16811 - jmp *%eax
16812 + jmp *pa(subarch_entries)(,%eax,4)
16813
16814 bad_subarch:
16815 WEAK(lguest_entry)
16816 @@ -256,10 +326,10 @@ WEAK(xen_entry)
16817 __INITDATA
16818
16819 subarch_entries:
16820 - .long default_entry /* normal x86/PC */
16821 - .long lguest_entry /* lguest hypervisor */
16822 - .long xen_entry /* Xen hypervisor */
16823 - .long default_entry /* Moorestown MID */
16824 + .long ta(default_entry) /* normal x86/PC */
16825 + .long ta(lguest_entry) /* lguest hypervisor */
16826 + .long ta(xen_entry) /* Xen hypervisor */
16827 + .long ta(default_entry) /* Moorestown MID */
16828 num_subarch_entries = (. - subarch_entries) / 4
16829 .previous
16830 #else
16831 @@ -310,6 +380,7 @@ default_entry:
16832 orl %edx,%eax
16833 movl %eax,%cr4
16834
16835 +#ifdef CONFIG_X86_PAE
16836 testb $X86_CR4_PAE, %al # check if PAE is enabled
16837 jz 6f
16838
16839 @@ -338,6 +409,9 @@ default_entry:
16840 /* Make changes effective */
16841 wrmsr
16842
16843 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16844 +#endif
16845 +
16846 6:
16847
16848 /*
16849 @@ -436,14 +510,20 @@ is386: movl $2,%ecx # set MP
16850 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16851 movl %eax,%ss # after changing gdt.
16852
16853 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
16854 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16855 movl %eax,%ds
16856 movl %eax,%es
16857
16858 movl $(__KERNEL_PERCPU), %eax
16859 movl %eax,%fs # set this cpu's percpu
16860
16861 +#ifdef CONFIG_CC_STACKPROTECTOR
16862 movl $(__KERNEL_STACK_CANARY),%eax
16863 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16864 + movl $(__USER_DS),%eax
16865 +#else
16866 + xorl %eax,%eax
16867 +#endif
16868 movl %eax,%gs
16869
16870 xorl %eax,%eax # Clear LDT
16871 @@ -520,8 +600,11 @@ setup_once:
16872 * relocation. Manually set base address in stack canary
16873 * segment descriptor.
16874 */
16875 - movl $gdt_page,%eax
16876 + movl $cpu_gdt_table,%eax
16877 movl $stack_canary,%ecx
16878 +#ifdef CONFIG_SMP
16879 + addl $__per_cpu_load,%ecx
16880 +#endif
16881 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16882 shrl $16, %ecx
16883 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16884 @@ -552,7 +635,7 @@ ENDPROC(early_idt_handlers)
16885 /* This is global to keep gas from relaxing the jumps */
16886 ENTRY(early_idt_handler)
16887 cld
16888 - cmpl $2,%ss:early_recursion_flag
16889 + cmpl $1,%ss:early_recursion_flag
16890 je hlt_loop
16891 incl %ss:early_recursion_flag
16892
16893 @@ -590,8 +673,8 @@ ENTRY(early_idt_handler)
16894 pushl (20+6*4)(%esp) /* trapno */
16895 pushl $fault_msg
16896 call printk
16897 -#endif
16898 call dump_stack
16899 +#endif
16900 hlt_loop:
16901 hlt
16902 jmp hlt_loop
16903 @@ -610,8 +693,11 @@ ENDPROC(early_idt_handler)
16904 /* This is the default interrupt "handler" :-) */
16905 ALIGN
16906 ignore_int:
16907 - cld
16908 #ifdef CONFIG_PRINTK
16909 + cmpl $2,%ss:early_recursion_flag
16910 + je hlt_loop
16911 + incl %ss:early_recursion_flag
16912 + cld
16913 pushl %eax
16914 pushl %ecx
16915 pushl %edx
16916 @@ -620,9 +706,6 @@ ignore_int:
16917 movl $(__KERNEL_DS),%eax
16918 movl %eax,%ds
16919 movl %eax,%es
16920 - cmpl $2,early_recursion_flag
16921 - je hlt_loop
16922 - incl early_recursion_flag
16923 pushl 16(%esp)
16924 pushl 24(%esp)
16925 pushl 32(%esp)
16926 @@ -656,29 +739,43 @@ ENTRY(setup_once_ref)
16927 /*
16928 * BSS section
16929 */
16930 -__PAGE_ALIGNED_BSS
16931 - .align PAGE_SIZE
16932 #ifdef CONFIG_X86_PAE
16933 +.section .initial_pg_pmd,"a",@progbits
16934 initial_pg_pmd:
16935 .fill 1024*KPMDS,4,0
16936 #else
16937 +.section .initial_page_table,"a",@progbits
16938 ENTRY(initial_page_table)
16939 .fill 1024,4,0
16940 #endif
16941 +.section .initial_pg_fixmap,"a",@progbits
16942 initial_pg_fixmap:
16943 .fill 1024,4,0
16944 +.section .empty_zero_page,"a",@progbits
16945 ENTRY(empty_zero_page)
16946 .fill 4096,1,0
16947 +.section .swapper_pg_dir,"a",@progbits
16948 ENTRY(swapper_pg_dir)
16949 +#ifdef CONFIG_X86_PAE
16950 + .fill 4,8,0
16951 +#else
16952 .fill 1024,4,0
16953 +#endif
16954 +
16955 +/*
16956 + * The IDT has to be page-aligned to simplify the Pentium
16957 + * F0 0F bug workaround.. We have a special link segment
16958 + * for this.
16959 + */
16960 +.section .idt,"a",@progbits
16961 +ENTRY(idt_table)
16962 + .fill 256,8,0
16963
16964 /*
16965 * This starts the data section.
16966 */
16967 #ifdef CONFIG_X86_PAE
16968 -__PAGE_ALIGNED_DATA
16969 - /* Page-aligned for the benefit of paravirt? */
16970 - .align PAGE_SIZE
16971 +.section .initial_page_table,"a",@progbits
16972 ENTRY(initial_page_table)
16973 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
16974 # if KPMDS == 3
16975 @@ -697,12 +794,20 @@ ENTRY(initial_page_table)
16976 # error "Kernel PMDs should be 1, 2 or 3"
16977 # endif
16978 .align PAGE_SIZE /* needs to be page-sized too */
16979 +
16980 +#ifdef CONFIG_PAX_PER_CPU_PGD
16981 +ENTRY(cpu_pgd)
16982 + .rept NR_CPUS
16983 + .fill 4,8,0
16984 + .endr
16985 +#endif
16986 +
16987 #endif
16988
16989 .data
16990 .balign 4
16991 ENTRY(stack_start)
16992 - .long init_thread_union+THREAD_SIZE
16993 + .long init_thread_union+THREAD_SIZE-8
16994
16995 __INITRODATA
16996 int_msg:
16997 @@ -730,7 +835,7 @@ fault_msg:
16998 * segment size, and 32-bit linear address value:
16999 */
17000
17001 - .data
17002 +.section .rodata,"a",@progbits
17003 .globl boot_gdt_descr
17004 .globl idt_descr
17005
17006 @@ -739,7 +844,7 @@ fault_msg:
17007 .word 0 # 32 bit align gdt_desc.address
17008 boot_gdt_descr:
17009 .word __BOOT_DS+7
17010 - .long boot_gdt - __PAGE_OFFSET
17011 + .long pa(boot_gdt)
17012
17013 .word 0 # 32-bit align idt_desc.address
17014 idt_descr:
17015 @@ -750,7 +855,7 @@ idt_descr:
17016 .word 0 # 32 bit align gdt_desc.address
17017 ENTRY(early_gdt_descr)
17018 .word GDT_ENTRIES*8-1
17019 - .long gdt_page /* Overwritten for secondary CPUs */
17020 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17021
17022 /*
17023 * The boot_gdt must mirror the equivalent in setup.S and is
17024 @@ -759,5 +864,65 @@ ENTRY(early_gdt_descr)
17025 .align L1_CACHE_BYTES
17026 ENTRY(boot_gdt)
17027 .fill GDT_ENTRY_BOOT_CS,8,0
17028 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17029 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17030 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17031 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17032 +
17033 + .align PAGE_SIZE_asm
17034 +ENTRY(cpu_gdt_table)
17035 + .rept NR_CPUS
17036 + .quad 0x0000000000000000 /* NULL descriptor */
17037 + .quad 0x0000000000000000 /* 0x0b reserved */
17038 + .quad 0x0000000000000000 /* 0x13 reserved */
17039 + .quad 0x0000000000000000 /* 0x1b reserved */
17040 +
17041 +#ifdef CONFIG_PAX_KERNEXEC
17042 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17043 +#else
17044 + .quad 0x0000000000000000 /* 0x20 unused */
17045 +#endif
17046 +
17047 + .quad 0x0000000000000000 /* 0x28 unused */
17048 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17049 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17050 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17051 + .quad 0x0000000000000000 /* 0x4b reserved */
17052 + .quad 0x0000000000000000 /* 0x53 reserved */
17053 + .quad 0x0000000000000000 /* 0x5b reserved */
17054 +
17055 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17056 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17057 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17058 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17059 +
17060 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17061 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17062 +
17063 + /*
17064 + * Segments used for calling PnP BIOS have byte granularity.
17065 + * The code segments and data segments have fixed 64k limits,
17066 + * the transfer segment sizes are set at run time.
17067 + */
17068 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17069 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17070 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17071 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17072 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17073 +
17074 + /*
17075 + * The APM segments have byte granularity and their bases
17076 + * are set at run time. All have 64k limits.
17077 + */
17078 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17079 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17080 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17081 +
17082 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17083 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17084 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17085 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17086 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17087 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17088 +
17089 + /* Be sure this is zeroed to avoid false validations in Xen */
17090 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17091 + .endr
17092 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17093 index 94bf9cc..400455a 100644
17094 --- a/arch/x86/kernel/head_64.S
17095 +++ b/arch/x86/kernel/head_64.S
17096 @@ -20,6 +20,8 @@
17097 #include <asm/processor-flags.h>
17098 #include <asm/percpu.h>
17099 #include <asm/nops.h>
17100 +#include <asm/cpufeature.h>
17101 +#include <asm/alternative-asm.h>
17102
17103 #ifdef CONFIG_PARAVIRT
17104 #include <asm/asm-offsets.h>
17105 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17106 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17107 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17108 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17109 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17110 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17111 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17112 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17113 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17114 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17115
17116 .text
17117 __HEAD
17118 @@ -88,35 +96,23 @@ startup_64:
17119 */
17120 addq %rbp, init_level4_pgt + 0(%rip)
17121 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17122 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17123 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17124 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17125 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17126
17127 addq %rbp, level3_ident_pgt + 0(%rip)
17128 +#ifndef CONFIG_XEN
17129 + addq %rbp, level3_ident_pgt + 8(%rip)
17130 +#endif
17131
17132 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17133 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17134 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17135 +
17136 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17137 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17138
17139 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17140 -
17141 - /* Add an Identity mapping if I am above 1G */
17142 - leaq _text(%rip), %rdi
17143 - andq $PMD_PAGE_MASK, %rdi
17144 -
17145 - movq %rdi, %rax
17146 - shrq $PUD_SHIFT, %rax
17147 - andq $(PTRS_PER_PUD - 1), %rax
17148 - jz ident_complete
17149 -
17150 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17151 - leaq level3_ident_pgt(%rip), %rbx
17152 - movq %rdx, 0(%rbx, %rax, 8)
17153 -
17154 - movq %rdi, %rax
17155 - shrq $PMD_SHIFT, %rax
17156 - andq $(PTRS_PER_PMD - 1), %rax
17157 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17158 - leaq level2_spare_pgt(%rip), %rbx
17159 - movq %rdx, 0(%rbx, %rax, 8)
17160 -ident_complete:
17161 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17162
17163 /*
17164 * Fixup the kernel text+data virtual addresses. Note that
17165 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17166 * after the boot processor executes this code.
17167 */
17168
17169 - /* Enable PAE mode and PGE */
17170 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17171 + /* Enable PAE mode and PSE/PGE */
17172 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17173 movq %rax, %cr4
17174
17175 /* Setup early boot stage 4 level pagetables. */
17176 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17177 movl $MSR_EFER, %ecx
17178 rdmsr
17179 btsl $_EFER_SCE, %eax /* Enable System Call */
17180 - btl $20,%edi /* No Execute supported? */
17181 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17182 jnc 1f
17183 btsl $_EFER_NX, %eax
17184 + leaq init_level4_pgt(%rip), %rdi
17185 +#ifndef CONFIG_EFI
17186 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17187 +#endif
17188 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17189 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17190 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17191 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17192 1: wrmsr /* Make changes effective */
17193
17194 /* Setup cr0 */
17195 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17196 * jump. In addition we need to ensure %cs is set so we make this
17197 * a far return.
17198 */
17199 + pax_set_fptr_mask
17200 movq initial_code(%rip),%rax
17201 pushq $0 # fake return address to stop unwinder
17202 pushq $__KERNEL_CS # set correct cs
17203 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17204 bad_address:
17205 jmp bad_address
17206
17207 - .section ".init.text","ax"
17208 + __INIT
17209 .globl early_idt_handlers
17210 early_idt_handlers:
17211 # 104(%rsp) %rflags
17212 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17213 addq $16,%rsp # drop vector number and error code
17214 decl early_recursion_flag(%rip)
17215 INTERRUPT_RETURN
17216 + .previous
17217
17218 + __INITDATA
17219 .balign 4
17220 early_recursion_flag:
17221 .long 0
17222 + .previous
17223
17224 + .section .rodata,"a",@progbits
17225 #ifdef CONFIG_EARLY_PRINTK
17226 early_idt_msg:
17227 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17228 @@ -360,6 +369,7 @@ early_idt_ripmsg:
17229 #endif /* CONFIG_EARLY_PRINTK */
17230 .previous
17231
17232 + .section .rodata,"a",@progbits
17233 #define NEXT_PAGE(name) \
17234 .balign PAGE_SIZE; \
17235 ENTRY(name)
17236 @@ -372,7 +382,6 @@ ENTRY(name)
17237 i = i + 1 ; \
17238 .endr
17239
17240 - .data
17241 /*
17242 * This default setting generates an ident mapping at address 0x100000
17243 * and a mapping for the kernel that precisely maps virtual address
17244 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17245 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17246 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17247 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17248 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17249 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17250 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17251 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17252 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17253 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17254 .org init_level4_pgt + L4_START_KERNEL*8, 0
17255 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17256 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17257
17258 +#ifdef CONFIG_PAX_PER_CPU_PGD
17259 +NEXT_PAGE(cpu_pgd)
17260 + .rept NR_CPUS
17261 + .fill 512,8,0
17262 + .endr
17263 +#endif
17264 +
17265 NEXT_PAGE(level3_ident_pgt)
17266 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17267 +#ifdef CONFIG_XEN
17268 .fill 511,8,0
17269 +#else
17270 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17271 + .fill 510,8,0
17272 +#endif
17273 +
17274 +NEXT_PAGE(level3_vmalloc_start_pgt)
17275 + .fill 512,8,0
17276 +
17277 +NEXT_PAGE(level3_vmalloc_end_pgt)
17278 + .fill 512,8,0
17279 +
17280 +NEXT_PAGE(level3_vmemmap_pgt)
17281 + .fill L3_VMEMMAP_START,8,0
17282 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17283
17284 NEXT_PAGE(level3_kernel_pgt)
17285 .fill L3_START_KERNEL,8,0
17286 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17287 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17288 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17289
17290 +NEXT_PAGE(level2_vmemmap_pgt)
17291 + .fill 512,8,0
17292 +
17293 NEXT_PAGE(level2_fixmap_pgt)
17294 - .fill 506,8,0
17295 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17296 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17297 - .fill 5,8,0
17298 + .fill 507,8,0
17299 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17300 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17301 + .fill 4,8,0
17302
17303 -NEXT_PAGE(level1_fixmap_pgt)
17304 +NEXT_PAGE(level1_vsyscall_pgt)
17305 .fill 512,8,0
17306
17307 -NEXT_PAGE(level2_ident_pgt)
17308 - /* Since I easily can, map the first 1G.
17309 + /* Since I easily can, map the first 2G.
17310 * Don't set NX because code runs from these pages.
17311 */
17312 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17313 +NEXT_PAGE(level2_ident_pgt)
17314 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17315
17316 NEXT_PAGE(level2_kernel_pgt)
17317 /*
17318 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17319 * If you want to increase this then increase MODULES_VADDR
17320 * too.)
17321 */
17322 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17323 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17324 -
17325 -NEXT_PAGE(level2_spare_pgt)
17326 - .fill 512, 8, 0
17327 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17328
17329 #undef PMDS
17330 #undef NEXT_PAGE
17331
17332 - .data
17333 + .align PAGE_SIZE
17334 +ENTRY(cpu_gdt_table)
17335 + .rept NR_CPUS
17336 + .quad 0x0000000000000000 /* NULL descriptor */
17337 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17338 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17339 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17340 + .quad 0x00cffb000000ffff /* __USER32_CS */
17341 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17342 + .quad 0x00affb000000ffff /* __USER_CS */
17343 +
17344 +#ifdef CONFIG_PAX_KERNEXEC
17345 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17346 +#else
17347 + .quad 0x0 /* unused */
17348 +#endif
17349 +
17350 + .quad 0,0 /* TSS */
17351 + .quad 0,0 /* LDT */
17352 + .quad 0,0,0 /* three TLS descriptors */
17353 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17354 + /* asm/segment.h:GDT_ENTRIES must match this */
17355 +
17356 + /* zero the remaining page */
17357 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17358 + .endr
17359 +
17360 .align 16
17361 .globl early_gdt_descr
17362 early_gdt_descr:
17363 .word GDT_ENTRIES*8-1
17364 early_gdt_descr_base:
17365 - .quad INIT_PER_CPU_VAR(gdt_page)
17366 + .quad cpu_gdt_table
17367
17368 ENTRY(phys_base)
17369 /* This must match the first entry in level2_kernel_pgt */
17370 .quad 0x0000000000000000
17371
17372 #include "../../x86/xen/xen-head.S"
17373 -
17374 - .section .bss, "aw", @nobits
17375 +
17376 + .section .rodata,"a",@progbits
17377 .align L1_CACHE_BYTES
17378 ENTRY(idt_table)
17379 - .skip IDT_ENTRIES * 16
17380 + .fill 512,8,0
17381
17382 .align L1_CACHE_BYTES
17383 ENTRY(nmi_idt_table)
17384 - .skip IDT_ENTRIES * 16
17385 + .fill 512,8,0
17386
17387 __PAGE_ALIGNED_BSS
17388 .align PAGE_SIZE
17389 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17390 index 9c3bd4a..e1d9b35 100644
17391 --- a/arch/x86/kernel/i386_ksyms_32.c
17392 +++ b/arch/x86/kernel/i386_ksyms_32.c
17393 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17394 EXPORT_SYMBOL(cmpxchg8b_emu);
17395 #endif
17396
17397 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17398 +
17399 /* Networking helper routines. */
17400 EXPORT_SYMBOL(csum_partial_copy_generic);
17401 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17402 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17403
17404 EXPORT_SYMBOL(__get_user_1);
17405 EXPORT_SYMBOL(__get_user_2);
17406 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17407
17408 EXPORT_SYMBOL(csum_partial);
17409 EXPORT_SYMBOL(empty_zero_page);
17410 +
17411 +#ifdef CONFIG_PAX_KERNEXEC
17412 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17413 +#endif
17414 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17415 index f250431..54097e7 100644
17416 --- a/arch/x86/kernel/i387.c
17417 +++ b/arch/x86/kernel/i387.c
17418 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17419 static inline bool interrupted_user_mode(void)
17420 {
17421 struct pt_regs *regs = get_irq_regs();
17422 - return regs && user_mode_vm(regs);
17423 + return regs && user_mode(regs);
17424 }
17425
17426 /*
17427 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17428 index 36d1853..bf25736 100644
17429 --- a/arch/x86/kernel/i8259.c
17430 +++ b/arch/x86/kernel/i8259.c
17431 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17432 "spurious 8259A interrupt: IRQ%d.\n", irq);
17433 spurious_irq_mask |= irqmask;
17434 }
17435 - atomic_inc(&irq_err_count);
17436 + atomic_inc_unchecked(&irq_err_count);
17437 /*
17438 * Theoretically we do not have to handle this IRQ,
17439 * but in Linux this does not cause problems and is
17440 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17441 index 8c96897..be66bfa 100644
17442 --- a/arch/x86/kernel/ioport.c
17443 +++ b/arch/x86/kernel/ioport.c
17444 @@ -6,6 +6,7 @@
17445 #include <linux/sched.h>
17446 #include <linux/kernel.h>
17447 #include <linux/capability.h>
17448 +#include <linux/security.h>
17449 #include <linux/errno.h>
17450 #include <linux/types.h>
17451 #include <linux/ioport.h>
17452 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17453
17454 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17455 return -EINVAL;
17456 +#ifdef CONFIG_GRKERNSEC_IO
17457 + if (turn_on && grsec_disable_privio) {
17458 + gr_handle_ioperm();
17459 + return -EPERM;
17460 + }
17461 +#endif
17462 if (turn_on && !capable(CAP_SYS_RAWIO))
17463 return -EPERM;
17464
17465 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17466 * because the ->io_bitmap_max value must match the bitmap
17467 * contents:
17468 */
17469 - tss = &per_cpu(init_tss, get_cpu());
17470 + tss = init_tss + get_cpu();
17471
17472 if (turn_on)
17473 bitmap_clear(t->io_bitmap_ptr, from, num);
17474 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17475 return -EINVAL;
17476 /* Trying to gain more privileges? */
17477 if (level > old) {
17478 +#ifdef CONFIG_GRKERNSEC_IO
17479 + if (grsec_disable_privio) {
17480 + gr_handle_iopl();
17481 + return -EPERM;
17482 + }
17483 +#endif
17484 if (!capable(CAP_SYS_RAWIO))
17485 return -EPERM;
17486 }
17487 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17488 index 3dafc60..aa8e9c4 100644
17489 --- a/arch/x86/kernel/irq.c
17490 +++ b/arch/x86/kernel/irq.c
17491 @@ -18,7 +18,7 @@
17492 #include <asm/mce.h>
17493 #include <asm/hw_irq.h>
17494
17495 -atomic_t irq_err_count;
17496 +atomic_unchecked_t irq_err_count;
17497
17498 /* Function pointer for generic interrupt vector handling */
17499 void (*x86_platform_ipi_callback)(void) = NULL;
17500 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17501 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17502 seq_printf(p, " Machine check polls\n");
17503 #endif
17504 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17505 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17506 #if defined(CONFIG_X86_IO_APIC)
17507 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17508 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17509 #endif
17510 return 0;
17511 }
17512 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17513
17514 u64 arch_irq_stat(void)
17515 {
17516 - u64 sum = atomic_read(&irq_err_count);
17517 + u64 sum = atomic_read_unchecked(&irq_err_count);
17518
17519 #ifdef CONFIG_X86_IO_APIC
17520 - sum += atomic_read(&irq_mis_count);
17521 + sum += atomic_read_unchecked(&irq_mis_count);
17522 #endif
17523 return sum;
17524 }
17525 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17526 index 344faf8..355f60d 100644
17527 --- a/arch/x86/kernel/irq_32.c
17528 +++ b/arch/x86/kernel/irq_32.c
17529 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17530 __asm__ __volatile__("andl %%esp,%0" :
17531 "=r" (sp) : "0" (THREAD_SIZE - 1));
17532
17533 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17534 + return sp < STACK_WARN;
17535 }
17536
17537 static void print_stack_overflow(void)
17538 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17539 * per-CPU IRQ handling contexts (thread information and stack)
17540 */
17541 union irq_ctx {
17542 - struct thread_info tinfo;
17543 - u32 stack[THREAD_SIZE/sizeof(u32)];
17544 + unsigned long previous_esp;
17545 + u32 stack[THREAD_SIZE/sizeof(u32)];
17546 } __attribute__((aligned(THREAD_SIZE)));
17547
17548 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17549 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17550 static inline int
17551 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17552 {
17553 - union irq_ctx *curctx, *irqctx;
17554 + union irq_ctx *irqctx;
17555 u32 *isp, arg1, arg2;
17556
17557 - curctx = (union irq_ctx *) current_thread_info();
17558 irqctx = __this_cpu_read(hardirq_ctx);
17559
17560 /*
17561 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17562 * handler) we can't do that and just have to keep using the
17563 * current stack (which is the irq stack already after all)
17564 */
17565 - if (unlikely(curctx == irqctx))
17566 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17567 return 0;
17568
17569 /* build the stack frame on the IRQ stack */
17570 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17571 - irqctx->tinfo.task = curctx->tinfo.task;
17572 - irqctx->tinfo.previous_esp = current_stack_pointer;
17573 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17574 + irqctx->previous_esp = current_stack_pointer;
17575
17576 - /* Copy the preempt_count so that the [soft]irq checks work. */
17577 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17578 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17579 + __set_fs(MAKE_MM_SEG(0));
17580 +#endif
17581
17582 if (unlikely(overflow))
17583 call_on_stack(print_stack_overflow, isp);
17584 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17585 : "0" (irq), "1" (desc), "2" (isp),
17586 "D" (desc->handle_irq)
17587 : "memory", "cc", "ecx");
17588 +
17589 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17590 + __set_fs(current_thread_info()->addr_limit);
17591 +#endif
17592 +
17593 return 1;
17594 }
17595
17596 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17597 */
17598 void __cpuinit irq_ctx_init(int cpu)
17599 {
17600 - union irq_ctx *irqctx;
17601 -
17602 if (per_cpu(hardirq_ctx, cpu))
17603 return;
17604
17605 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17606 - THREADINFO_GFP,
17607 - THREAD_SIZE_ORDER));
17608 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17609 - irqctx->tinfo.cpu = cpu;
17610 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17611 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17612 -
17613 - per_cpu(hardirq_ctx, cpu) = irqctx;
17614 -
17615 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17616 - THREADINFO_GFP,
17617 - THREAD_SIZE_ORDER));
17618 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17619 - irqctx->tinfo.cpu = cpu;
17620 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17621 -
17622 - per_cpu(softirq_ctx, cpu) = irqctx;
17623 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17624 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17625 +
17626 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17627 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17628
17629 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17630 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17631 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17632 asmlinkage void do_softirq(void)
17633 {
17634 unsigned long flags;
17635 - struct thread_info *curctx;
17636 union irq_ctx *irqctx;
17637 u32 *isp;
17638
17639 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17640 local_irq_save(flags);
17641
17642 if (local_softirq_pending()) {
17643 - curctx = current_thread_info();
17644 irqctx = __this_cpu_read(softirq_ctx);
17645 - irqctx->tinfo.task = curctx->task;
17646 - irqctx->tinfo.previous_esp = current_stack_pointer;
17647 + irqctx->previous_esp = current_stack_pointer;
17648
17649 /* build the stack frame on the softirq stack */
17650 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17651 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17652 +
17653 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17654 + __set_fs(MAKE_MM_SEG(0));
17655 +#endif
17656
17657 call_on_stack(__do_softirq, isp);
17658 +
17659 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17660 + __set_fs(current_thread_info()->addr_limit);
17661 +#endif
17662 +
17663 /*
17664 * Shouldn't happen, we returned above if in_interrupt():
17665 */
17666 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17667 if (unlikely(!desc))
17668 return false;
17669
17670 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17671 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17672 if (unlikely(overflow))
17673 print_stack_overflow();
17674 desc->handle_irq(irq, desc);
17675 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17676 index d04d3ec..ea4b374 100644
17677 --- a/arch/x86/kernel/irq_64.c
17678 +++ b/arch/x86/kernel/irq_64.c
17679 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17680 u64 estack_top, estack_bottom;
17681 u64 curbase = (u64)task_stack_page(current);
17682
17683 - if (user_mode_vm(regs))
17684 + if (user_mode(regs))
17685 return;
17686
17687 if (regs->sp >= curbase + sizeof(struct thread_info) +
17688 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17689 index 1d5d31e..72731d4 100644
17690 --- a/arch/x86/kernel/kdebugfs.c
17691 +++ b/arch/x86/kernel/kdebugfs.c
17692 @@ -27,7 +27,7 @@ struct setup_data_node {
17693 u32 len;
17694 };
17695
17696 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17697 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17698 size_t count, loff_t *ppos)
17699 {
17700 struct setup_data_node *node = file->private_data;
17701 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17702 index 3f61904..873cea9 100644
17703 --- a/arch/x86/kernel/kgdb.c
17704 +++ b/arch/x86/kernel/kgdb.c
17705 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17706 #ifdef CONFIG_X86_32
17707 switch (regno) {
17708 case GDB_SS:
17709 - if (!user_mode_vm(regs))
17710 + if (!user_mode(regs))
17711 *(unsigned long *)mem = __KERNEL_DS;
17712 break;
17713 case GDB_SP:
17714 - if (!user_mode_vm(regs))
17715 + if (!user_mode(regs))
17716 *(unsigned long *)mem = kernel_stack_pointer(regs);
17717 break;
17718 case GDB_GS:
17719 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17720 case 'k':
17721 /* clear the trace bit */
17722 linux_regs->flags &= ~X86_EFLAGS_TF;
17723 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17724 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17725
17726 /* set the trace bit if we're stepping */
17727 if (remcomInBuffer[0] == 's') {
17728 linux_regs->flags |= X86_EFLAGS_TF;
17729 - atomic_set(&kgdb_cpu_doing_single_step,
17730 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17731 raw_smp_processor_id());
17732 }
17733
17734 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17735
17736 switch (cmd) {
17737 case DIE_DEBUG:
17738 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17739 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17740 if (user_mode(regs))
17741 return single_step_cont(regs, args);
17742 break;
17743 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17744 index c5e410e..da6aaf9 100644
17745 --- a/arch/x86/kernel/kprobes-opt.c
17746 +++ b/arch/x86/kernel/kprobes-opt.c
17747 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17748 * Verify if the address gap is in 2GB range, because this uses
17749 * a relative jump.
17750 */
17751 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17752 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17753 if (abs(rel) > 0x7fffffff)
17754 return -ERANGE;
17755
17756 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17757 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17758
17759 /* Set probe function call */
17760 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17761 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17762
17763 /* Set returning jmp instruction at the tail of out-of-line buffer */
17764 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17765 - (u8 *)op->kp.addr + op->optinsn.size);
17766 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17767
17768 flush_icache_range((unsigned long) buf,
17769 (unsigned long) buf + TMPL_END_IDX +
17770 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17771 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17772
17773 /* Backup instructions which will be replaced by jump address */
17774 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17775 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17776 RELATIVE_ADDR_SIZE);
17777
17778 insn_buf[0] = RELATIVEJUMP_OPCODE;
17779 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17780 index e2f751e..dffa2a0 100644
17781 --- a/arch/x86/kernel/kprobes.c
17782 +++ b/arch/x86/kernel/kprobes.c
17783 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17784 } __attribute__((packed)) *insn;
17785
17786 insn = (struct __arch_relative_insn *)from;
17787 +
17788 + pax_open_kernel();
17789 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17790 insn->op = op;
17791 + pax_close_kernel();
17792 }
17793
17794 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17795 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17796 kprobe_opcode_t opcode;
17797 kprobe_opcode_t *orig_opcodes = opcodes;
17798
17799 - if (search_exception_tables((unsigned long)opcodes))
17800 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17801 return 0; /* Page fault may occur on this address. */
17802
17803 retry:
17804 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17805 /* Another subsystem puts a breakpoint, failed to recover */
17806 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17807 return 0;
17808 + pax_open_kernel();
17809 memcpy(dest, insn.kaddr, insn.length);
17810 + pax_close_kernel();
17811
17812 #ifdef CONFIG_X86_64
17813 if (insn_rip_relative(&insn)) {
17814 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17815 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17816 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17817 disp = (u8 *) dest + insn_offset_displacement(&insn);
17818 + pax_open_kernel();
17819 *(s32 *) disp = (s32) newdisp;
17820 + pax_close_kernel();
17821 }
17822 #endif
17823 return insn.length;
17824 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17825 * nor set current_kprobe, because it doesn't use single
17826 * stepping.
17827 */
17828 - regs->ip = (unsigned long)p->ainsn.insn;
17829 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17830 preempt_enable_no_resched();
17831 return;
17832 }
17833 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17834 if (p->opcode == BREAKPOINT_INSTRUCTION)
17835 regs->ip = (unsigned long)p->addr;
17836 else
17837 - regs->ip = (unsigned long)p->ainsn.insn;
17838 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17839 }
17840
17841 /*
17842 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17843 setup_singlestep(p, regs, kcb, 0);
17844 return 1;
17845 }
17846 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
17847 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17848 /*
17849 * The breakpoint instruction was removed right
17850 * after we hit it. Another cpu has removed
17851 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17852 " movq %rax, 152(%rsp)\n"
17853 RESTORE_REGS_STRING
17854 " popfq\n"
17855 +#ifdef KERNEXEC_PLUGIN
17856 + " btsq $63,(%rsp)\n"
17857 +#endif
17858 #else
17859 " pushf\n"
17860 SAVE_REGS_STRING
17861 @@ -765,7 +775,7 @@ static void __kprobes
17862 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17863 {
17864 unsigned long *tos = stack_addr(regs);
17865 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17866 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17867 unsigned long orig_ip = (unsigned long)p->addr;
17868 kprobe_opcode_t *insn = p->ainsn.insn;
17869
17870 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
17871 struct die_args *args = data;
17872 int ret = NOTIFY_DONE;
17873
17874 - if (args->regs && user_mode_vm(args->regs))
17875 + if (args->regs && user_mode(args->regs))
17876 return ret;
17877
17878 switch (val) {
17879 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17880 index ebc9873..1b9724b 100644
17881 --- a/arch/x86/kernel/ldt.c
17882 +++ b/arch/x86/kernel/ldt.c
17883 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17884 if (reload) {
17885 #ifdef CONFIG_SMP
17886 preempt_disable();
17887 - load_LDT(pc);
17888 + load_LDT_nolock(pc);
17889 if (!cpumask_equal(mm_cpumask(current->mm),
17890 cpumask_of(smp_processor_id())))
17891 smp_call_function(flush_ldt, current->mm, 1);
17892 preempt_enable();
17893 #else
17894 - load_LDT(pc);
17895 + load_LDT_nolock(pc);
17896 #endif
17897 }
17898 if (oldsize) {
17899 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17900 return err;
17901
17902 for (i = 0; i < old->size; i++)
17903 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17904 + write_ldt_entry(new->ldt, i, old->ldt + i);
17905 return 0;
17906 }
17907
17908 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17909 retval = copy_ldt(&mm->context, &old_mm->context);
17910 mutex_unlock(&old_mm->context.lock);
17911 }
17912 +
17913 + if (tsk == current) {
17914 + mm->context.vdso = 0;
17915 +
17916 +#ifdef CONFIG_X86_32
17917 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17918 + mm->context.user_cs_base = 0UL;
17919 + mm->context.user_cs_limit = ~0UL;
17920 +
17921 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17922 + cpus_clear(mm->context.cpu_user_cs_mask);
17923 +#endif
17924 +
17925 +#endif
17926 +#endif
17927 +
17928 + }
17929 +
17930 return retval;
17931 }
17932
17933 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
17934 }
17935 }
17936
17937 +#ifdef CONFIG_PAX_SEGMEXEC
17938 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
17939 + error = -EINVAL;
17940 + goto out_unlock;
17941 + }
17942 +#endif
17943 +
17944 fill_ldt(&ldt, &ldt_info);
17945 if (oldmode)
17946 ldt.avl = 0;
17947 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
17948 index 5b19e4d..6476a76 100644
17949 --- a/arch/x86/kernel/machine_kexec_32.c
17950 +++ b/arch/x86/kernel/machine_kexec_32.c
17951 @@ -26,7 +26,7 @@
17952 #include <asm/cacheflush.h>
17953 #include <asm/debugreg.h>
17954
17955 -static void set_idt(void *newidt, __u16 limit)
17956 +static void set_idt(struct desc_struct *newidt, __u16 limit)
17957 {
17958 struct desc_ptr curidt;
17959
17960 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
17961 }
17962
17963
17964 -static void set_gdt(void *newgdt, __u16 limit)
17965 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
17966 {
17967 struct desc_ptr curgdt;
17968
17969 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
17970 }
17971
17972 control_page = page_address(image->control_code_page);
17973 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
17974 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
17975
17976 relocate_kernel_ptr = control_page;
17977 page_list[PA_CONTROL_PAGE] = __pa(control_page);
17978 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
17979 index 0327e2b..e43737b 100644
17980 --- a/arch/x86/kernel/microcode_intel.c
17981 +++ b/arch/x86/kernel/microcode_intel.c
17982 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
17983
17984 static int get_ucode_user(void *to, const void *from, size_t n)
17985 {
17986 - return copy_from_user(to, from, n);
17987 + return copy_from_user(to, (const void __force_user *)from, n);
17988 }
17989
17990 static enum ucode_state
17991 request_microcode_user(int cpu, const void __user *buf, size_t size)
17992 {
17993 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
17994 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
17995 }
17996
17997 static void microcode_fini_cpu(int cpu)
17998 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
17999 index f21fd94..61565cd 100644
18000 --- a/arch/x86/kernel/module.c
18001 +++ b/arch/x86/kernel/module.c
18002 @@ -35,15 +35,60 @@
18003 #define DEBUGP(fmt...)
18004 #endif
18005
18006 -void *module_alloc(unsigned long size)
18007 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18008 {
18009 - if (PAGE_ALIGN(size) > MODULES_LEN)
18010 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18011 return NULL;
18012 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18013 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18014 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18015 -1, __builtin_return_address(0));
18016 }
18017
18018 +void *module_alloc(unsigned long size)
18019 +{
18020 +
18021 +#ifdef CONFIG_PAX_KERNEXEC
18022 + return __module_alloc(size, PAGE_KERNEL);
18023 +#else
18024 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18025 +#endif
18026 +
18027 +}
18028 +
18029 +#ifdef CONFIG_PAX_KERNEXEC
18030 +#ifdef CONFIG_X86_32
18031 +void *module_alloc_exec(unsigned long size)
18032 +{
18033 + struct vm_struct *area;
18034 +
18035 + if (size == 0)
18036 + return NULL;
18037 +
18038 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18039 + return area ? area->addr : NULL;
18040 +}
18041 +EXPORT_SYMBOL(module_alloc_exec);
18042 +
18043 +void module_free_exec(struct module *mod, void *module_region)
18044 +{
18045 + vunmap(module_region);
18046 +}
18047 +EXPORT_SYMBOL(module_free_exec);
18048 +#else
18049 +void module_free_exec(struct module *mod, void *module_region)
18050 +{
18051 + module_free(mod, module_region);
18052 +}
18053 +EXPORT_SYMBOL(module_free_exec);
18054 +
18055 +void *module_alloc_exec(unsigned long size)
18056 +{
18057 + return __module_alloc(size, PAGE_KERNEL_RX);
18058 +}
18059 +EXPORT_SYMBOL(module_alloc_exec);
18060 +#endif
18061 +#endif
18062 +
18063 #ifdef CONFIG_X86_32
18064 int apply_relocate(Elf32_Shdr *sechdrs,
18065 const char *strtab,
18066 @@ -54,14 +99,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18067 unsigned int i;
18068 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18069 Elf32_Sym *sym;
18070 - uint32_t *location;
18071 + uint32_t *plocation, location;
18072
18073 DEBUGP("Applying relocate section %u to %u\n", relsec,
18074 sechdrs[relsec].sh_info);
18075 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18076 /* This is where to make the change */
18077 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18078 - + rel[i].r_offset;
18079 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18080 + location = (uint32_t)plocation;
18081 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18082 + plocation = ktla_ktva((void *)plocation);
18083 /* This is the symbol it is referring to. Note that all
18084 undefined symbols have been resolved. */
18085 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18086 @@ -70,11 +117,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18087 switch (ELF32_R_TYPE(rel[i].r_info)) {
18088 case R_386_32:
18089 /* We add the value into the location given */
18090 - *location += sym->st_value;
18091 + pax_open_kernel();
18092 + *plocation += sym->st_value;
18093 + pax_close_kernel();
18094 break;
18095 case R_386_PC32:
18096 /* Add the value, subtract its postition */
18097 - *location += sym->st_value - (uint32_t)location;
18098 + pax_open_kernel();
18099 + *plocation += sym->st_value - location;
18100 + pax_close_kernel();
18101 break;
18102 default:
18103 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18104 @@ -119,21 +170,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18105 case R_X86_64_NONE:
18106 break;
18107 case R_X86_64_64:
18108 + pax_open_kernel();
18109 *(u64 *)loc = val;
18110 + pax_close_kernel();
18111 break;
18112 case R_X86_64_32:
18113 + pax_open_kernel();
18114 *(u32 *)loc = val;
18115 + pax_close_kernel();
18116 if (val != *(u32 *)loc)
18117 goto overflow;
18118 break;
18119 case R_X86_64_32S:
18120 + pax_open_kernel();
18121 *(s32 *)loc = val;
18122 + pax_close_kernel();
18123 if ((s64)val != *(s32 *)loc)
18124 goto overflow;
18125 break;
18126 case R_X86_64_PC32:
18127 val -= (u64)loc;
18128 + pax_open_kernel();
18129 *(u32 *)loc = val;
18130 + pax_close_kernel();
18131 +
18132 #if 0
18133 if ((s64)val != *(s32 *)loc)
18134 goto overflow;
18135 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18136 index a0b2f84..875ab81 100644
18137 --- a/arch/x86/kernel/nmi.c
18138 +++ b/arch/x86/kernel/nmi.c
18139 @@ -460,6 +460,17 @@ static inline void nmi_nesting_postprocess(void)
18140 dotraplinkage notrace __kprobes void
18141 do_nmi(struct pt_regs *regs, long error_code)
18142 {
18143 +
18144 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18145 + if (!user_mode(regs)) {
18146 + unsigned long cs = regs->cs & 0xFFFF;
18147 + unsigned long ip = ktva_ktla(regs->ip);
18148 +
18149 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18150 + regs->ip = ip;
18151 + }
18152 +#endif
18153 +
18154 nmi_nesting_preprocess(regs);
18155
18156 nmi_enter();
18157 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18158 index 676b8c7..870ba04 100644
18159 --- a/arch/x86/kernel/paravirt-spinlocks.c
18160 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18161 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18162 arch_spin_lock(lock);
18163 }
18164
18165 -struct pv_lock_ops pv_lock_ops = {
18166 +struct pv_lock_ops pv_lock_ops __read_only = {
18167 #ifdef CONFIG_SMP
18168 .spin_is_locked = __ticket_spin_is_locked,
18169 .spin_is_contended = __ticket_spin_is_contended,
18170 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18171 index 9ce8859..b49bf51 100644
18172 --- a/arch/x86/kernel/paravirt.c
18173 +++ b/arch/x86/kernel/paravirt.c
18174 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18175 {
18176 return x;
18177 }
18178 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18179 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18180 +#endif
18181
18182 void __init default_banner(void)
18183 {
18184 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18185 if (opfunc == NULL)
18186 /* If there's no function, patch it with a ud2a (BUG) */
18187 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18188 - else if (opfunc == _paravirt_nop)
18189 + else if (opfunc == (void *)_paravirt_nop)
18190 /* If the operation is a nop, then nop the callsite */
18191 ret = paravirt_patch_nop();
18192
18193 /* identity functions just return their single argument */
18194 - else if (opfunc == _paravirt_ident_32)
18195 + else if (opfunc == (void *)_paravirt_ident_32)
18196 ret = paravirt_patch_ident_32(insnbuf, len);
18197 - else if (opfunc == _paravirt_ident_64)
18198 + else if (opfunc == (void *)_paravirt_ident_64)
18199 ret = paravirt_patch_ident_64(insnbuf, len);
18200 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18201 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18202 + ret = paravirt_patch_ident_64(insnbuf, len);
18203 +#endif
18204
18205 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18206 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18207 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18208 if (insn_len > len || start == NULL)
18209 insn_len = len;
18210 else
18211 - memcpy(insnbuf, start, insn_len);
18212 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18213
18214 return insn_len;
18215 }
18216 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18217 preempt_enable();
18218 }
18219
18220 -struct pv_info pv_info = {
18221 +struct pv_info pv_info __read_only = {
18222 .name = "bare hardware",
18223 .paravirt_enabled = 0,
18224 .kernel_rpl = 0,
18225 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18226 #endif
18227 };
18228
18229 -struct pv_init_ops pv_init_ops = {
18230 +struct pv_init_ops pv_init_ops __read_only = {
18231 .patch = native_patch,
18232 };
18233
18234 -struct pv_time_ops pv_time_ops = {
18235 +struct pv_time_ops pv_time_ops __read_only = {
18236 .sched_clock = native_sched_clock,
18237 .steal_clock = native_steal_clock,
18238 };
18239
18240 -struct pv_irq_ops pv_irq_ops = {
18241 +struct pv_irq_ops pv_irq_ops __read_only = {
18242 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18243 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18244 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18245 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18246 #endif
18247 };
18248
18249 -struct pv_cpu_ops pv_cpu_ops = {
18250 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18251 .cpuid = native_cpuid,
18252 .get_debugreg = native_get_debugreg,
18253 .set_debugreg = native_set_debugreg,
18254 @@ -397,21 +404,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18255 .end_context_switch = paravirt_nop,
18256 };
18257
18258 -struct pv_apic_ops pv_apic_ops = {
18259 +struct pv_apic_ops pv_apic_ops __read_only = {
18260 #ifdef CONFIG_X86_LOCAL_APIC
18261 .startup_ipi_hook = paravirt_nop,
18262 #endif
18263 };
18264
18265 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18266 +#ifdef CONFIG_X86_32
18267 +#ifdef CONFIG_X86_PAE
18268 +/* 64-bit pagetable entries */
18269 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18270 +#else
18271 /* 32-bit pagetable entries */
18272 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18273 +#endif
18274 #else
18275 /* 64-bit pagetable entries */
18276 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18277 #endif
18278
18279 -struct pv_mmu_ops pv_mmu_ops = {
18280 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18281
18282 .read_cr2 = native_read_cr2,
18283 .write_cr2 = native_write_cr2,
18284 @@ -461,6 +473,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18285 .make_pud = PTE_IDENT,
18286
18287 .set_pgd = native_set_pgd,
18288 + .set_pgd_batched = native_set_pgd_batched,
18289 #endif
18290 #endif /* PAGETABLE_LEVELS >= 3 */
18291
18292 @@ -480,6 +493,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18293 },
18294
18295 .set_fixmap = native_set_fixmap,
18296 +
18297 +#ifdef CONFIG_PAX_KERNEXEC
18298 + .pax_open_kernel = native_pax_open_kernel,
18299 + .pax_close_kernel = native_pax_close_kernel,
18300 +#endif
18301 +
18302 };
18303
18304 EXPORT_SYMBOL_GPL(pv_time_ops);
18305 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18306 index 35ccf75..7a15747 100644
18307 --- a/arch/x86/kernel/pci-iommu_table.c
18308 +++ b/arch/x86/kernel/pci-iommu_table.c
18309 @@ -2,7 +2,7 @@
18310 #include <asm/iommu_table.h>
18311 #include <linux/string.h>
18312 #include <linux/kallsyms.h>
18313 -
18314 +#include <linux/sched.h>
18315
18316 #define DEBUG 1
18317
18318 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18319 index 735279e..5008677 100644
18320 --- a/arch/x86/kernel/process.c
18321 +++ b/arch/x86/kernel/process.c
18322 @@ -34,7 +34,8 @@
18323 * section. Since TSS's are completely CPU-local, we want them
18324 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18325 */
18326 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18327 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18328 +EXPORT_SYMBOL(init_tss);
18329
18330 #ifdef CONFIG_X86_64
18331 static DEFINE_PER_CPU(unsigned char, is_idle);
18332 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
18333 task_xstate_cachep =
18334 kmem_cache_create("task_xstate", xstate_size,
18335 __alignof__(union thread_xstate),
18336 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18337 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18338 }
18339
18340 static inline void drop_fpu(struct task_struct *tsk)
18341 @@ -115,7 +116,7 @@ void exit_thread(void)
18342 unsigned long *bp = t->io_bitmap_ptr;
18343
18344 if (bp) {
18345 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18346 + struct tss_struct *tss = init_tss + get_cpu();
18347
18348 t->io_bitmap_ptr = NULL;
18349 clear_thread_flag(TIF_IO_BITMAP);
18350 @@ -147,7 +148,7 @@ void show_regs_common(void)
18351
18352 printk(KERN_CONT "\n");
18353 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18354 - current->pid, current->comm, print_tainted(),
18355 + task_pid_nr(current), current->comm, print_tainted(),
18356 init_utsname()->release,
18357 (int)strcspn(init_utsname()->version, " "),
18358 init_utsname()->version);
18359 @@ -161,6 +162,9 @@ void flush_thread(void)
18360 {
18361 struct task_struct *tsk = current;
18362
18363 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18364 + loadsegment(gs, 0);
18365 +#endif
18366 flush_ptrace_hw_breakpoint(tsk);
18367 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18368 drop_fpu(tsk);
18369 @@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18370 regs.di = (unsigned long) arg;
18371
18372 #ifdef CONFIG_X86_32
18373 - regs.ds = __USER_DS;
18374 - regs.es = __USER_DS;
18375 + regs.ds = __KERNEL_DS;
18376 + regs.es = __KERNEL_DS;
18377 regs.fs = __KERNEL_PERCPU;
18378 - regs.gs = __KERNEL_STACK_CANARY;
18379 + savesegment(gs, regs.gs);
18380 #else
18381 regs.ss = __KERNEL_DS;
18382 #endif
18383 @@ -407,7 +411,7 @@ static void __exit_idle(void)
18384 void exit_idle(void)
18385 {
18386 /* idle loop has pid 0 */
18387 - if (current->pid)
18388 + if (task_pid_nr(current))
18389 return;
18390 __exit_idle();
18391 }
18392 @@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18393
18394 return ret;
18395 }
18396 -void stop_this_cpu(void *dummy)
18397 +__noreturn void stop_this_cpu(void *dummy)
18398 {
18399 local_irq_disable();
18400 /*
18401 @@ -746,16 +750,37 @@ static int __init idle_setup(char *str)
18402 }
18403 early_param("idle", idle_setup);
18404
18405 -unsigned long arch_align_stack(unsigned long sp)
18406 +#ifdef CONFIG_PAX_RANDKSTACK
18407 +void pax_randomize_kstack(struct pt_regs *regs)
18408 {
18409 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18410 - sp -= get_random_int() % 8192;
18411 - return sp & ~0xf;
18412 -}
18413 + struct thread_struct *thread = &current->thread;
18414 + unsigned long time;
18415
18416 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18417 -{
18418 - unsigned long range_end = mm->brk + 0x02000000;
18419 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18420 -}
18421 + if (!randomize_va_space)
18422 + return;
18423 +
18424 + if (v8086_mode(regs))
18425 + return;
18426
18427 + rdtscl(time);
18428 +
18429 + /* P4 seems to return a 0 LSB, ignore it */
18430 +#ifdef CONFIG_MPENTIUM4
18431 + time &= 0x3EUL;
18432 + time <<= 2;
18433 +#elif defined(CONFIG_X86_64)
18434 + time &= 0xFUL;
18435 + time <<= 4;
18436 +#else
18437 + time &= 0x1FUL;
18438 + time <<= 3;
18439 +#endif
18440 +
18441 + thread->sp0 ^= time;
18442 + load_sp0(init_tss + smp_processor_id(), thread);
18443 +
18444 +#ifdef CONFIG_X86_64
18445 + this_cpu_write(kernel_stack, thread->sp0);
18446 +#endif
18447 +}
18448 +#endif
18449 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18450 index 516fa18..80bd9e6 100644
18451 --- a/arch/x86/kernel/process_32.c
18452 +++ b/arch/x86/kernel/process_32.c
18453 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18454 unsigned long thread_saved_pc(struct task_struct *tsk)
18455 {
18456 return ((unsigned long *)tsk->thread.sp)[3];
18457 +//XXX return tsk->thread.eip;
18458 }
18459
18460 void __show_regs(struct pt_regs *regs, int all)
18461 @@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18462 unsigned long sp;
18463 unsigned short ss, gs;
18464
18465 - if (user_mode_vm(regs)) {
18466 + if (user_mode(regs)) {
18467 sp = regs->sp;
18468 ss = regs->ss & 0xffff;
18469 - gs = get_user_gs(regs);
18470 } else {
18471 sp = kernel_stack_pointer(regs);
18472 savesegment(ss, ss);
18473 - savesegment(gs, gs);
18474 }
18475 + gs = get_user_gs(regs);
18476
18477 show_regs_common();
18478
18479 @@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18480 struct task_struct *tsk;
18481 int err;
18482
18483 - childregs = task_pt_regs(p);
18484 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18485 *childregs = *regs;
18486 childregs->ax = 0;
18487 childregs->sp = sp;
18488
18489 p->thread.sp = (unsigned long) childregs;
18490 p->thread.sp0 = (unsigned long) (childregs+1);
18491 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18492
18493 p->thread.ip = (unsigned long) ret_from_fork;
18494
18495 @@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18496 struct thread_struct *prev = &prev_p->thread,
18497 *next = &next_p->thread;
18498 int cpu = smp_processor_id();
18499 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18500 + struct tss_struct *tss = init_tss + cpu;
18501 fpu_switch_t fpu;
18502
18503 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18504 @@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18505 */
18506 lazy_save_gs(prev->gs);
18507
18508 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18509 + __set_fs(task_thread_info(next_p)->addr_limit);
18510 +#endif
18511 +
18512 /*
18513 * Load the per-thread Thread-Local Storage descriptor.
18514 */
18515 @@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18516 */
18517 arch_end_context_switch(next_p);
18518
18519 + this_cpu_write(current_task, next_p);
18520 + this_cpu_write(current_tinfo, &next_p->tinfo);
18521 +
18522 /*
18523 * Restore %gs if needed (which is common)
18524 */
18525 @@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18526
18527 switch_fpu_finish(next_p, fpu);
18528
18529 - this_cpu_write(current_task, next_p);
18530 -
18531 return prev_p;
18532 }
18533
18534 @@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18535 } while (count++ < 16);
18536 return 0;
18537 }
18538 -
18539 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18540 index 61cdf7f..797f06a 100644
18541 --- a/arch/x86/kernel/process_64.c
18542 +++ b/arch/x86/kernel/process_64.c
18543 @@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18544 struct pt_regs *childregs;
18545 struct task_struct *me = current;
18546
18547 - childregs = ((struct pt_regs *)
18548 - (THREAD_SIZE + task_stack_page(p))) - 1;
18549 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18550 *childregs = *regs;
18551
18552 childregs->ax = 0;
18553 @@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18554 p->thread.sp = (unsigned long) childregs;
18555 p->thread.sp0 = (unsigned long) (childregs+1);
18556 p->thread.usersp = me->thread.usersp;
18557 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18558
18559 set_tsk_thread_flag(p, TIF_FORK);
18560
18561 @@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18562 struct thread_struct *prev = &prev_p->thread;
18563 struct thread_struct *next = &next_p->thread;
18564 int cpu = smp_processor_id();
18565 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18566 + struct tss_struct *tss = init_tss + cpu;
18567 unsigned fsindex, gsindex;
18568 fpu_switch_t fpu;
18569
18570 @@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18571 prev->usersp = this_cpu_read(old_rsp);
18572 this_cpu_write(old_rsp, next->usersp);
18573 this_cpu_write(current_task, next_p);
18574 + this_cpu_write(current_tinfo, &next_p->tinfo);
18575
18576 - this_cpu_write(kernel_stack,
18577 - (unsigned long)task_stack_page(next_p) +
18578 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18579 + this_cpu_write(kernel_stack, next->sp0);
18580
18581 /*
18582 * Now maybe reload the debug registers and handle I/O bitmaps
18583 @@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18584 if (!p || p == current || p->state == TASK_RUNNING)
18585 return 0;
18586 stack = (unsigned long)task_stack_page(p);
18587 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18588 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18589 return 0;
18590 fp = *(u64 *)(p->thread.sp);
18591 do {
18592 - if (fp < (unsigned long)stack ||
18593 - fp >= (unsigned long)stack+THREAD_SIZE)
18594 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18595 return 0;
18596 ip = *(u64 *)(fp+8);
18597 if (!in_sched_functions(ip))
18598 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18599 index c4c6a5c..905f440 100644
18600 --- a/arch/x86/kernel/ptrace.c
18601 +++ b/arch/x86/kernel/ptrace.c
18602 @@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18603 unsigned long addr, unsigned long data)
18604 {
18605 int ret;
18606 - unsigned long __user *datap = (unsigned long __user *)data;
18607 + unsigned long __user *datap = (__force unsigned long __user *)data;
18608
18609 switch (request) {
18610 /* read the word at location addr in the USER area. */
18611 @@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18612 if ((int) addr < 0)
18613 return -EIO;
18614 ret = do_get_thread_area(child, addr,
18615 - (struct user_desc __user *)data);
18616 + (__force struct user_desc __user *) data);
18617 break;
18618
18619 case PTRACE_SET_THREAD_AREA:
18620 if ((int) addr < 0)
18621 return -EIO;
18622 ret = do_set_thread_area(child, addr,
18623 - (struct user_desc __user *)data, 0);
18624 + (__force struct user_desc __user *) data, 0);
18625 break;
18626 #endif
18627
18628 @@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18629 memset(info, 0, sizeof(*info));
18630 info->si_signo = SIGTRAP;
18631 info->si_code = si_code;
18632 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18633 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18634 }
18635
18636 void user_single_step_siginfo(struct task_struct *tsk,
18637 @@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18638 # define IS_IA32 0
18639 #endif
18640
18641 +#ifdef CONFIG_GRKERNSEC_SETXID
18642 +extern void gr_delayed_cred_worker(void);
18643 +#endif
18644 +
18645 /*
18646 * We must return the syscall number to actually look up in the table.
18647 * This can be -1L to skip running any syscall at all.
18648 @@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18649 {
18650 long ret = 0;
18651
18652 +#ifdef CONFIG_GRKERNSEC_SETXID
18653 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18654 + gr_delayed_cred_worker();
18655 +#endif
18656 +
18657 /*
18658 * If we stepped into a sysenter/syscall insn, it trapped in
18659 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18660 @@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18661 {
18662 bool step;
18663
18664 +#ifdef CONFIG_GRKERNSEC_SETXID
18665 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18666 + gr_delayed_cred_worker();
18667 +#endif
18668 +
18669 audit_syscall_exit(regs);
18670
18671 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18672 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18673 index 42eb330..139955c 100644
18674 --- a/arch/x86/kernel/pvclock.c
18675 +++ b/arch/x86/kernel/pvclock.c
18676 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18677 return pv_tsc_khz;
18678 }
18679
18680 -static atomic64_t last_value = ATOMIC64_INIT(0);
18681 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18682
18683 void pvclock_resume(void)
18684 {
18685 - atomic64_set(&last_value, 0);
18686 + atomic64_set_unchecked(&last_value, 0);
18687 }
18688
18689 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18690 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18691 * updating at the same time, and one of them could be slightly behind,
18692 * making the assumption that last_value always go forward fail to hold.
18693 */
18694 - last = atomic64_read(&last_value);
18695 + last = atomic64_read_unchecked(&last_value);
18696 do {
18697 if (ret < last)
18698 return last;
18699 - last = atomic64_cmpxchg(&last_value, last, ret);
18700 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18701 } while (unlikely(last != ret));
18702
18703 return ret;
18704 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18705 index 5de92f1..2732385 100644
18706 --- a/arch/x86/kernel/reboot.c
18707 +++ b/arch/x86/kernel/reboot.c
18708 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18709 EXPORT_SYMBOL(pm_power_off);
18710
18711 static const struct desc_ptr no_idt = {};
18712 -static int reboot_mode;
18713 +static unsigned short reboot_mode;
18714 enum reboot_type reboot_type = BOOT_ACPI;
18715 int reboot_force;
18716
18717 @@ -157,11 +157,15 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18718 return 0;
18719 }
18720
18721 -void machine_real_restart(unsigned int type)
18722 +__noreturn void machine_real_restart(unsigned int type)
18723 {
18724 - void (*restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18725 + void (* restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18726 real_mode_header->machine_real_restart_asm;
18727
18728 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18729 + struct desc_struct *gdt;
18730 +#endif
18731 +
18732 local_irq_disable();
18733
18734 /*
18735 @@ -189,10 +193,36 @@ void machine_real_restart(unsigned int type)
18736 * boot)". This seems like a fairly standard thing that gets set by
18737 * REBOOT.COM programs, and the previous reset routine did this
18738 * too. */
18739 - *((unsigned short *)0x472) = reboot_mode;
18740 + *(unsigned short *)(__va(0x472)) = reboot_mode;
18741
18742 /* Jump to the identity-mapped low memory code */
18743 +
18744 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18745 + gdt = get_cpu_gdt_table(smp_processor_id());
18746 + pax_open_kernel();
18747 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18748 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18749 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18750 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18751 +#endif
18752 +#ifdef CONFIG_PAX_KERNEXEC
18753 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18754 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18755 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18756 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18757 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18758 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18759 +#endif
18760 + pax_close_kernel();
18761 +#endif
18762 +
18763 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18764 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18765 + unreachable();
18766 +#else
18767 restart_lowmem(type);
18768 +#endif
18769 +
18770 }
18771 #ifdef CONFIG_APM_MODULE
18772 EXPORT_SYMBOL(machine_real_restart);
18773 @@ -543,7 +573,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18774 * try to force a triple fault and then cycle between hitting the keyboard
18775 * controller and doing that
18776 */
18777 -static void native_machine_emergency_restart(void)
18778 +__noreturn static void native_machine_emergency_restart(void)
18779 {
18780 int i;
18781 int attempt = 0;
18782 @@ -670,13 +700,13 @@ void native_machine_shutdown(void)
18783 #endif
18784 }
18785
18786 -static void __machine_emergency_restart(int emergency)
18787 +static __noreturn void __machine_emergency_restart(int emergency)
18788 {
18789 reboot_emergency = emergency;
18790 machine_ops.emergency_restart();
18791 }
18792
18793 -static void native_machine_restart(char *__unused)
18794 +static __noreturn void native_machine_restart(char *__unused)
18795 {
18796 printk("machine restart\n");
18797
18798 @@ -685,7 +715,7 @@ static void native_machine_restart(char *__unused)
18799 __machine_emergency_restart(0);
18800 }
18801
18802 -static void native_machine_halt(void)
18803 +static __noreturn void native_machine_halt(void)
18804 {
18805 /* Stop other cpus and apics */
18806 machine_shutdown();
18807 @@ -695,7 +725,7 @@ static void native_machine_halt(void)
18808 stop_this_cpu(NULL);
18809 }
18810
18811 -static void native_machine_power_off(void)
18812 +__noreturn static void native_machine_power_off(void)
18813 {
18814 if (pm_power_off) {
18815 if (!reboot_force)
18816 @@ -704,6 +734,7 @@ static void native_machine_power_off(void)
18817 }
18818 /* A fallback in case there is no PM info available */
18819 tboot_shutdown(TB_SHUTDOWN_HALT);
18820 + unreachable();
18821 }
18822
18823 struct machine_ops machine_ops = {
18824 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18825 index 7a6f3b3..bed145d7 100644
18826 --- a/arch/x86/kernel/relocate_kernel_64.S
18827 +++ b/arch/x86/kernel/relocate_kernel_64.S
18828 @@ -11,6 +11,7 @@
18829 #include <asm/kexec.h>
18830 #include <asm/processor-flags.h>
18831 #include <asm/pgtable_types.h>
18832 +#include <asm/alternative-asm.h>
18833
18834 /*
18835 * Must be relocatable PIC code callable as a C function
18836 @@ -160,13 +161,14 @@ identity_mapped:
18837 xorq %rbp, %rbp
18838 xorq %r8, %r8
18839 xorq %r9, %r9
18840 - xorq %r10, %r9
18841 + xorq %r10, %r10
18842 xorq %r11, %r11
18843 xorq %r12, %r12
18844 xorq %r13, %r13
18845 xorq %r14, %r14
18846 xorq %r15, %r15
18847
18848 + pax_force_retaddr 0, 1
18849 ret
18850
18851 1:
18852 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18853 index 16be6dc..4686132 100644
18854 --- a/arch/x86/kernel/setup.c
18855 +++ b/arch/x86/kernel/setup.c
18856 @@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
18857
18858 switch (data->type) {
18859 case SETUP_E820_EXT:
18860 - parse_e820_ext(data);
18861 + parse_e820_ext((struct setup_data __force_kernel *)data);
18862 break;
18863 case SETUP_DTB:
18864 add_dtb(pa_data);
18865 @@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
18866 * area (640->1Mb) as ram even though it is not.
18867 * take them out.
18868 */
18869 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18870 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18871 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18872 }
18873
18874 @@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
18875
18876 if (!boot_params.hdr.root_flags)
18877 root_mountflags &= ~MS_RDONLY;
18878 - init_mm.start_code = (unsigned long) _text;
18879 - init_mm.end_code = (unsigned long) _etext;
18880 + init_mm.start_code = ktla_ktva((unsigned long) _text);
18881 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
18882 init_mm.end_data = (unsigned long) _edata;
18883 init_mm.brk = _brk_end;
18884
18885 - code_resource.start = virt_to_phys(_text);
18886 - code_resource.end = virt_to_phys(_etext)-1;
18887 - data_resource.start = virt_to_phys(_etext);
18888 + code_resource.start = virt_to_phys(ktla_ktva(_text));
18889 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18890 + data_resource.start = virt_to_phys(_sdata);
18891 data_resource.end = virt_to_phys(_edata)-1;
18892 bss_resource.start = virt_to_phys(&__bss_start);
18893 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18894 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18895 index 5a98aa2..2f9288d 100644
18896 --- a/arch/x86/kernel/setup_percpu.c
18897 +++ b/arch/x86/kernel/setup_percpu.c
18898 @@ -21,19 +21,17 @@
18899 #include <asm/cpu.h>
18900 #include <asm/stackprotector.h>
18901
18902 -DEFINE_PER_CPU(int, cpu_number);
18903 +#ifdef CONFIG_SMP
18904 +DEFINE_PER_CPU(unsigned int, cpu_number);
18905 EXPORT_PER_CPU_SYMBOL(cpu_number);
18906 +#endif
18907
18908 -#ifdef CONFIG_X86_64
18909 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18910 -#else
18911 -#define BOOT_PERCPU_OFFSET 0
18912 -#endif
18913
18914 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18915 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18916
18917 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18918 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18919 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
18920 };
18921 EXPORT_SYMBOL(__per_cpu_offset);
18922 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
18923 {
18924 #ifdef CONFIG_X86_32
18925 struct desc_struct gdt;
18926 + unsigned long base = per_cpu_offset(cpu);
18927
18928 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
18929 - 0x2 | DESCTYPE_S, 0x8);
18930 - gdt.s = 1;
18931 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
18932 + 0x83 | DESCTYPE_S, 0xC);
18933 write_gdt_entry(get_cpu_gdt_table(cpu),
18934 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
18935 #endif
18936 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
18937 /* alrighty, percpu areas up and running */
18938 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
18939 for_each_possible_cpu(cpu) {
18940 +#ifdef CONFIG_CC_STACKPROTECTOR
18941 +#ifdef CONFIG_X86_32
18942 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
18943 +#endif
18944 +#endif
18945 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
18946 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
18947 per_cpu(cpu_number, cpu) = cpu;
18948 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
18949 */
18950 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
18951 #endif
18952 +#ifdef CONFIG_CC_STACKPROTECTOR
18953 +#ifdef CONFIG_X86_32
18954 + if (!cpu)
18955 + per_cpu(stack_canary.canary, cpu) = canary;
18956 +#endif
18957 +#endif
18958 /*
18959 * Up to this point, the boot CPU has been using .init.data
18960 * area. Reload any changed state for the boot CPU.
18961 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
18962 index 21af737..fb45e22 100644
18963 --- a/arch/x86/kernel/signal.c
18964 +++ b/arch/x86/kernel/signal.c
18965 @@ -191,7 +191,7 @@ static unsigned long align_sigframe(unsigned long sp)
18966 * Align the stack pointer according to the i386 ABI,
18967 * i.e. so that on function entry ((sp + 4) & 15) == 0.
18968 */
18969 - sp = ((sp + 4) & -16ul) - 4;
18970 + sp = ((sp - 12) & -16ul) - 4;
18971 #else /* !CONFIG_X86_32 */
18972 sp = round_down(sp, 16) - 8;
18973 #endif
18974 @@ -242,11 +242,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
18975 * Return an always-bogus address instead so we will die with SIGSEGV.
18976 */
18977 if (onsigstack && !likely(on_sig_stack(sp)))
18978 - return (void __user *)-1L;
18979 + return (__force void __user *)-1L;
18980
18981 /* save i387 state */
18982 if (used_math() && save_i387_xstate(*fpstate) < 0)
18983 - return (void __user *)-1L;
18984 + return (__force void __user *)-1L;
18985
18986 return (void __user *)sp;
18987 }
18988 @@ -301,9 +301,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18989 }
18990
18991 if (current->mm->context.vdso)
18992 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18993 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18994 else
18995 - restorer = &frame->retcode;
18996 + restorer = (void __user *)&frame->retcode;
18997 if (ka->sa.sa_flags & SA_RESTORER)
18998 restorer = ka->sa.sa_restorer;
18999
19000 @@ -317,7 +317,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19001 * reasons and because gdb uses it as a signature to notice
19002 * signal handler stack frames.
19003 */
19004 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19005 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19006
19007 if (err)
19008 return -EFAULT;
19009 @@ -371,7 +371,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19010 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19011
19012 /* Set up to return from userspace. */
19013 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19014 + if (current->mm->context.vdso)
19015 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19016 + else
19017 + restorer = (void __user *)&frame->retcode;
19018 if (ka->sa.sa_flags & SA_RESTORER)
19019 restorer = ka->sa.sa_restorer;
19020 put_user_ex(restorer, &frame->pretcode);
19021 @@ -383,7 +386,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19022 * reasons and because gdb uses it as a signature to notice
19023 * signal handler stack frames.
19024 */
19025 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19026 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19027 } put_user_catch(err);
19028
19029 if (err)
19030 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19031 index 7bd8a08..2659b5b 100644
19032 --- a/arch/x86/kernel/smpboot.c
19033 +++ b/arch/x86/kernel/smpboot.c
19034 @@ -679,6 +679,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19035 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19036 (THREAD_SIZE + task_stack_page(idle))) - 1);
19037 per_cpu(current_task, cpu) = idle;
19038 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
19039
19040 #ifdef CONFIG_X86_32
19041 /* Stack for startup_32 can be just as for start_secondary onwards */
19042 @@ -686,11 +687,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19043 #else
19044 clear_tsk_thread_flag(idle, TIF_FORK);
19045 initial_gs = per_cpu_offset(cpu);
19046 - per_cpu(kernel_stack, cpu) =
19047 - (unsigned long)task_stack_page(idle) -
19048 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19049 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19050 #endif
19051 +
19052 + pax_open_kernel();
19053 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19054 + pax_close_kernel();
19055 +
19056 initial_code = (unsigned long)start_secondary;
19057 stack_start = idle->thread.sp;
19058
19059 @@ -826,6 +829,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19060
19061 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19062
19063 +#ifdef CONFIG_PAX_PER_CPU_PGD
19064 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19065 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19066 + KERNEL_PGD_PTRS);
19067 +#endif
19068 +
19069 err = do_boot_cpu(apicid, cpu, tidle);
19070 if (err) {
19071 pr_debug("do_boot_cpu failed %d\n", err);
19072 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19073 index c346d11..d43b163 100644
19074 --- a/arch/x86/kernel/step.c
19075 +++ b/arch/x86/kernel/step.c
19076 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19077 struct desc_struct *desc;
19078 unsigned long base;
19079
19080 - seg &= ~7UL;
19081 + seg >>= 3;
19082
19083 mutex_lock(&child->mm->context.lock);
19084 - if (unlikely((seg >> 3) >= child->mm->context.size))
19085 + if (unlikely(seg >= child->mm->context.size))
19086 addr = -1L; /* bogus selector, access would fault */
19087 else {
19088 desc = child->mm->context.ldt + seg;
19089 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19090 addr += base;
19091 }
19092 mutex_unlock(&child->mm->context.lock);
19093 - }
19094 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19095 + addr = ktla_ktva(addr);
19096
19097 return addr;
19098 }
19099 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19100 unsigned char opcode[15];
19101 unsigned long addr = convert_ip_to_linear(child, regs);
19102
19103 + if (addr == -EINVAL)
19104 + return 0;
19105 +
19106 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19107 for (i = 0; i < copied; i++) {
19108 switch (opcode[i]) {
19109 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19110 index 0b0cb5f..db6b9ed 100644
19111 --- a/arch/x86/kernel/sys_i386_32.c
19112 +++ b/arch/x86/kernel/sys_i386_32.c
19113 @@ -24,17 +24,224 @@
19114
19115 #include <asm/syscalls.h>
19116
19117 -/*
19118 - * Do a system call from kernel instead of calling sys_execve so we
19119 - * end up with proper pt_regs.
19120 - */
19121 -int kernel_execve(const char *filename,
19122 - const char *const argv[],
19123 - const char *const envp[])
19124 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19125 {
19126 - long __res;
19127 - asm volatile ("int $0x80"
19128 - : "=a" (__res)
19129 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19130 - return __res;
19131 + unsigned long pax_task_size = TASK_SIZE;
19132 +
19133 +#ifdef CONFIG_PAX_SEGMEXEC
19134 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19135 + pax_task_size = SEGMEXEC_TASK_SIZE;
19136 +#endif
19137 +
19138 + if (len > pax_task_size || addr > pax_task_size - len)
19139 + return -EINVAL;
19140 +
19141 + return 0;
19142 +}
19143 +
19144 +unsigned long
19145 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19146 + unsigned long len, unsigned long pgoff, unsigned long flags)
19147 +{
19148 + struct mm_struct *mm = current->mm;
19149 + struct vm_area_struct *vma;
19150 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19151 +
19152 +#ifdef CONFIG_PAX_SEGMEXEC
19153 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19154 + pax_task_size = SEGMEXEC_TASK_SIZE;
19155 +#endif
19156 +
19157 + pax_task_size -= PAGE_SIZE;
19158 +
19159 + if (len > pax_task_size)
19160 + return -ENOMEM;
19161 +
19162 + if (flags & MAP_FIXED)
19163 + return addr;
19164 +
19165 +#ifdef CONFIG_PAX_RANDMMAP
19166 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19167 +#endif
19168 +
19169 + if (addr) {
19170 + addr = PAGE_ALIGN(addr);
19171 + if (pax_task_size - len >= addr) {
19172 + vma = find_vma(mm, addr);
19173 + if (check_heap_stack_gap(vma, addr, len))
19174 + return addr;
19175 + }
19176 + }
19177 + if (len > mm->cached_hole_size) {
19178 + start_addr = addr = mm->free_area_cache;
19179 + } else {
19180 + start_addr = addr = mm->mmap_base;
19181 + mm->cached_hole_size = 0;
19182 + }
19183 +
19184 +#ifdef CONFIG_PAX_PAGEEXEC
19185 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19186 + start_addr = 0x00110000UL;
19187 +
19188 +#ifdef CONFIG_PAX_RANDMMAP
19189 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19190 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19191 +#endif
19192 +
19193 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19194 + start_addr = addr = mm->mmap_base;
19195 + else
19196 + addr = start_addr;
19197 + }
19198 +#endif
19199 +
19200 +full_search:
19201 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19202 + /* At this point: (!vma || addr < vma->vm_end). */
19203 + if (pax_task_size - len < addr) {
19204 + /*
19205 + * Start a new search - just in case we missed
19206 + * some holes.
19207 + */
19208 + if (start_addr != mm->mmap_base) {
19209 + start_addr = addr = mm->mmap_base;
19210 + mm->cached_hole_size = 0;
19211 + goto full_search;
19212 + }
19213 + return -ENOMEM;
19214 + }
19215 + if (check_heap_stack_gap(vma, addr, len))
19216 + break;
19217 + if (addr + mm->cached_hole_size < vma->vm_start)
19218 + mm->cached_hole_size = vma->vm_start - addr;
19219 + addr = vma->vm_end;
19220 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19221 + start_addr = addr = mm->mmap_base;
19222 + mm->cached_hole_size = 0;
19223 + goto full_search;
19224 + }
19225 + }
19226 +
19227 + /*
19228 + * Remember the place where we stopped the search:
19229 + */
19230 + mm->free_area_cache = addr + len;
19231 + return addr;
19232 +}
19233 +
19234 +unsigned long
19235 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19236 + const unsigned long len, const unsigned long pgoff,
19237 + const unsigned long flags)
19238 +{
19239 + struct vm_area_struct *vma;
19240 + struct mm_struct *mm = current->mm;
19241 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19242 +
19243 +#ifdef CONFIG_PAX_SEGMEXEC
19244 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19245 + pax_task_size = SEGMEXEC_TASK_SIZE;
19246 +#endif
19247 +
19248 + pax_task_size -= PAGE_SIZE;
19249 +
19250 + /* requested length too big for entire address space */
19251 + if (len > pax_task_size)
19252 + return -ENOMEM;
19253 +
19254 + if (flags & MAP_FIXED)
19255 + return addr;
19256 +
19257 +#ifdef CONFIG_PAX_PAGEEXEC
19258 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19259 + goto bottomup;
19260 +#endif
19261 +
19262 +#ifdef CONFIG_PAX_RANDMMAP
19263 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19264 +#endif
19265 +
19266 + /* requesting a specific address */
19267 + if (addr) {
19268 + addr = PAGE_ALIGN(addr);
19269 + if (pax_task_size - len >= addr) {
19270 + vma = find_vma(mm, addr);
19271 + if (check_heap_stack_gap(vma, addr, len))
19272 + return addr;
19273 + }
19274 + }
19275 +
19276 + /* check if free_area_cache is useful for us */
19277 + if (len <= mm->cached_hole_size) {
19278 + mm->cached_hole_size = 0;
19279 + mm->free_area_cache = mm->mmap_base;
19280 + }
19281 +
19282 + /* either no address requested or can't fit in requested address hole */
19283 + addr = mm->free_area_cache;
19284 +
19285 + /* make sure it can fit in the remaining address space */
19286 + if (addr > len) {
19287 + vma = find_vma(mm, addr-len);
19288 + if (check_heap_stack_gap(vma, addr - len, len))
19289 + /* remember the address as a hint for next time */
19290 + return (mm->free_area_cache = addr-len);
19291 + }
19292 +
19293 + if (mm->mmap_base < len)
19294 + goto bottomup;
19295 +
19296 + addr = mm->mmap_base-len;
19297 +
19298 + do {
19299 + /*
19300 + * Lookup failure means no vma is above this address,
19301 + * else if new region fits below vma->vm_start,
19302 + * return with success:
19303 + */
19304 + vma = find_vma(mm, addr);
19305 + if (check_heap_stack_gap(vma, addr, len))
19306 + /* remember the address as a hint for next time */
19307 + return (mm->free_area_cache = addr);
19308 +
19309 + /* remember the largest hole we saw so far */
19310 + if (addr + mm->cached_hole_size < vma->vm_start)
19311 + mm->cached_hole_size = vma->vm_start - addr;
19312 +
19313 + /* try just below the current vma->vm_start */
19314 + addr = skip_heap_stack_gap(vma, len);
19315 + } while (!IS_ERR_VALUE(addr));
19316 +
19317 +bottomup:
19318 + /*
19319 + * A failed mmap() very likely causes application failure,
19320 + * so fall back to the bottom-up function here. This scenario
19321 + * can happen with large stack limits and large mmap()
19322 + * allocations.
19323 + */
19324 +
19325 +#ifdef CONFIG_PAX_SEGMEXEC
19326 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19327 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19328 + else
19329 +#endif
19330 +
19331 + mm->mmap_base = TASK_UNMAPPED_BASE;
19332 +
19333 +#ifdef CONFIG_PAX_RANDMMAP
19334 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19335 + mm->mmap_base += mm->delta_mmap;
19336 +#endif
19337 +
19338 + mm->free_area_cache = mm->mmap_base;
19339 + mm->cached_hole_size = ~0UL;
19340 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19341 + /*
19342 + * Restore the topdown base:
19343 + */
19344 + mm->mmap_base = base;
19345 + mm->free_area_cache = base;
19346 + mm->cached_hole_size = ~0UL;
19347 +
19348 + return addr;
19349 }
19350 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19351 index b4d3c39..82bb73b 100644
19352 --- a/arch/x86/kernel/sys_x86_64.c
19353 +++ b/arch/x86/kernel/sys_x86_64.c
19354 @@ -95,8 +95,8 @@ out:
19355 return error;
19356 }
19357
19358 -static void find_start_end(unsigned long flags, unsigned long *begin,
19359 - unsigned long *end)
19360 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19361 + unsigned long *begin, unsigned long *end)
19362 {
19363 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19364 unsigned long new_begin;
19365 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19366 *begin = new_begin;
19367 }
19368 } else {
19369 - *begin = TASK_UNMAPPED_BASE;
19370 + *begin = mm->mmap_base;
19371 *end = TASK_SIZE;
19372 }
19373 }
19374 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19375 if (flags & MAP_FIXED)
19376 return addr;
19377
19378 - find_start_end(flags, &begin, &end);
19379 + find_start_end(mm, flags, &begin, &end);
19380
19381 if (len > end)
19382 return -ENOMEM;
19383
19384 +#ifdef CONFIG_PAX_RANDMMAP
19385 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19386 +#endif
19387 +
19388 if (addr) {
19389 addr = PAGE_ALIGN(addr);
19390 vma = find_vma(mm, addr);
19391 - if (end - len >= addr &&
19392 - (!vma || addr + len <= vma->vm_start))
19393 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19394 return addr;
19395 }
19396 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19397 @@ -172,7 +175,7 @@ full_search:
19398 }
19399 return -ENOMEM;
19400 }
19401 - if (!vma || addr + len <= vma->vm_start) {
19402 + if (check_heap_stack_gap(vma, addr, len)) {
19403 /*
19404 * Remember the place where we stopped the search:
19405 */
19406 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19407 {
19408 struct vm_area_struct *vma;
19409 struct mm_struct *mm = current->mm;
19410 - unsigned long addr = addr0, start_addr;
19411 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19412
19413 /* requested length too big for entire address space */
19414 if (len > TASK_SIZE)
19415 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19416 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19417 goto bottomup;
19418
19419 +#ifdef CONFIG_PAX_RANDMMAP
19420 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19421 +#endif
19422 +
19423 /* requesting a specific address */
19424 if (addr) {
19425 addr = PAGE_ALIGN(addr);
19426 - vma = find_vma(mm, addr);
19427 - if (TASK_SIZE - len >= addr &&
19428 - (!vma || addr + len <= vma->vm_start))
19429 - return addr;
19430 + if (TASK_SIZE - len >= addr) {
19431 + vma = find_vma(mm, addr);
19432 + if (check_heap_stack_gap(vma, addr, len))
19433 + return addr;
19434 + }
19435 }
19436
19437 /* check if free_area_cache is useful for us */
19438 @@ -240,7 +248,7 @@ try_again:
19439 * return with success:
19440 */
19441 vma = find_vma(mm, addr);
19442 - if (!vma || addr+len <= vma->vm_start)
19443 + if (check_heap_stack_gap(vma, addr, len))
19444 /* remember the address as a hint for next time */
19445 return mm->free_area_cache = addr;
19446
19447 @@ -249,8 +257,8 @@ try_again:
19448 mm->cached_hole_size = vma->vm_start - addr;
19449
19450 /* try just below the current vma->vm_start */
19451 - addr = vma->vm_start-len;
19452 - } while (len < vma->vm_start);
19453 + addr = skip_heap_stack_gap(vma, len);
19454 + } while (!IS_ERR_VALUE(addr));
19455
19456 fail:
19457 /*
19458 @@ -270,13 +278,21 @@ bottomup:
19459 * can happen with large stack limits and large mmap()
19460 * allocations.
19461 */
19462 + mm->mmap_base = TASK_UNMAPPED_BASE;
19463 +
19464 +#ifdef CONFIG_PAX_RANDMMAP
19465 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19466 + mm->mmap_base += mm->delta_mmap;
19467 +#endif
19468 +
19469 + mm->free_area_cache = mm->mmap_base;
19470 mm->cached_hole_size = ~0UL;
19471 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19472 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19473 /*
19474 * Restore the topdown base:
19475 */
19476 - mm->free_area_cache = mm->mmap_base;
19477 + mm->mmap_base = base;
19478 + mm->free_area_cache = base;
19479 mm->cached_hole_size = ~0UL;
19480
19481 return addr;
19482 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19483 index f84fe00..93fe08f 100644
19484 --- a/arch/x86/kernel/tboot.c
19485 +++ b/arch/x86/kernel/tboot.c
19486 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19487
19488 void tboot_shutdown(u32 shutdown_type)
19489 {
19490 - void (*shutdown)(void);
19491 + void (* __noreturn shutdown)(void);
19492
19493 if (!tboot_enabled())
19494 return;
19495 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19496
19497 switch_to_tboot_pt();
19498
19499 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19500 + shutdown = (void *)tboot->shutdown_entry;
19501 shutdown();
19502
19503 /* should not reach here */
19504 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19505 return 0;
19506 }
19507
19508 -static atomic_t ap_wfs_count;
19509 +static atomic_unchecked_t ap_wfs_count;
19510
19511 static int tboot_wait_for_aps(int num_aps)
19512 {
19513 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19514 {
19515 switch (action) {
19516 case CPU_DYING:
19517 - atomic_inc(&ap_wfs_count);
19518 + atomic_inc_unchecked(&ap_wfs_count);
19519 if (num_online_cpus() == 1)
19520 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19521 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19522 return NOTIFY_BAD;
19523 break;
19524 }
19525 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19526
19527 tboot_create_trampoline();
19528
19529 - atomic_set(&ap_wfs_count, 0);
19530 + atomic_set_unchecked(&ap_wfs_count, 0);
19531 register_hotcpu_notifier(&tboot_cpu_notifier);
19532
19533 acpi_os_set_prepare_sleep(&tboot_sleep);
19534 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19535 index 24d3c91..d06b473 100644
19536 --- a/arch/x86/kernel/time.c
19537 +++ b/arch/x86/kernel/time.c
19538 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19539 {
19540 unsigned long pc = instruction_pointer(regs);
19541
19542 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19543 + if (!user_mode(regs) && in_lock_functions(pc)) {
19544 #ifdef CONFIG_FRAME_POINTER
19545 - return *(unsigned long *)(regs->bp + sizeof(long));
19546 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19547 #else
19548 unsigned long *sp =
19549 (unsigned long *)kernel_stack_pointer(regs);
19550 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19551 * or above a saved flags. Eflags has bits 22-31 zero,
19552 * kernel addresses don't.
19553 */
19554 +
19555 +#ifdef CONFIG_PAX_KERNEXEC
19556 + return ktla_ktva(sp[0]);
19557 +#else
19558 if (sp[0] >> 22)
19559 return sp[0];
19560 if (sp[1] >> 22)
19561 return sp[1];
19562 #endif
19563 +
19564 +#endif
19565 }
19566 return pc;
19567 }
19568 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19569 index 9d9d2f9..ed344e4 100644
19570 --- a/arch/x86/kernel/tls.c
19571 +++ b/arch/x86/kernel/tls.c
19572 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19573 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19574 return -EINVAL;
19575
19576 +#ifdef CONFIG_PAX_SEGMEXEC
19577 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19578 + return -EINVAL;
19579 +#endif
19580 +
19581 set_tls_desc(p, idx, &info, 1);
19582
19583 return 0;
19584 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19585 index 05b31d9..501d3ba 100644
19586 --- a/arch/x86/kernel/traps.c
19587 +++ b/arch/x86/kernel/traps.c
19588 @@ -67,12 +67,6 @@ asmlinkage int system_call(void);
19589
19590 /* Do we ignore FPU interrupts ? */
19591 char ignore_fpu_irq;
19592 -
19593 -/*
19594 - * The IDT has to be page-aligned to simplify the Pentium
19595 - * F0 0F bug workaround.
19596 - */
19597 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19598 #endif
19599
19600 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19601 @@ -105,13 +99,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19602 }
19603
19604 static void __kprobes
19605 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19606 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19607 long error_code, siginfo_t *info)
19608 {
19609 struct task_struct *tsk = current;
19610
19611 #ifdef CONFIG_X86_32
19612 - if (regs->flags & X86_VM_MASK) {
19613 + if (v8086_mode(regs)) {
19614 /*
19615 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19616 * On nmi (interrupt 2), do_trap should not be called.
19617 @@ -122,7 +116,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19618 }
19619 #endif
19620
19621 - if (!user_mode(regs))
19622 + if (!user_mode_novm(regs))
19623 goto kernel_trap;
19624
19625 #ifdef CONFIG_X86_32
19626 @@ -145,7 +139,7 @@ trap_signal:
19627 printk_ratelimit()) {
19628 printk(KERN_INFO
19629 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19630 - tsk->comm, tsk->pid, str,
19631 + tsk->comm, task_pid_nr(tsk), str,
19632 regs->ip, regs->sp, error_code);
19633 print_vma_addr(" in ", regs->ip);
19634 printk("\n");
19635 @@ -162,8 +156,20 @@ kernel_trap:
19636 if (!fixup_exception(regs)) {
19637 tsk->thread.error_code = error_code;
19638 tsk->thread.trap_nr = trapnr;
19639 +
19640 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19641 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19642 + str = "PAX: suspicious stack segment fault";
19643 +#endif
19644 +
19645 die(str, regs, error_code);
19646 }
19647 +
19648 +#ifdef CONFIG_PAX_REFCOUNT
19649 + if (trapnr == 4)
19650 + pax_report_refcount_overflow(regs);
19651 +#endif
19652 +
19653 return;
19654
19655 #ifdef CONFIG_X86_32
19656 @@ -256,14 +262,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19657 conditional_sti(regs);
19658
19659 #ifdef CONFIG_X86_32
19660 - if (regs->flags & X86_VM_MASK)
19661 + if (v8086_mode(regs))
19662 goto gp_in_vm86;
19663 #endif
19664
19665 tsk = current;
19666 - if (!user_mode(regs))
19667 + if (!user_mode_novm(regs))
19668 goto gp_in_kernel;
19669
19670 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19671 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19672 + struct mm_struct *mm = tsk->mm;
19673 + unsigned long limit;
19674 +
19675 + down_write(&mm->mmap_sem);
19676 + limit = mm->context.user_cs_limit;
19677 + if (limit < TASK_SIZE) {
19678 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19679 + up_write(&mm->mmap_sem);
19680 + return;
19681 + }
19682 + up_write(&mm->mmap_sem);
19683 + }
19684 +#endif
19685 +
19686 tsk->thread.error_code = error_code;
19687 tsk->thread.trap_nr = X86_TRAP_GP;
19688
19689 @@ -296,6 +318,13 @@ gp_in_kernel:
19690 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19691 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19692 return;
19693 +
19694 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19695 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19696 + die("PAX: suspicious general protection fault", regs, error_code);
19697 + else
19698 +#endif
19699 +
19700 die("general protection fault", regs, error_code);
19701 }
19702
19703 @@ -431,7 +460,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19704 /* It's safe to allow irq's after DR6 has been saved */
19705 preempt_conditional_sti(regs);
19706
19707 - if (regs->flags & X86_VM_MASK) {
19708 + if (v8086_mode(regs)) {
19709 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19710 X86_TRAP_DB);
19711 preempt_conditional_cli(regs);
19712 @@ -446,7 +475,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19713 * We already checked v86 mode above, so we can check for kernel mode
19714 * by just checking the CPL of CS.
19715 */
19716 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19717 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19718 tsk->thread.debugreg6 &= ~DR_STEP;
19719 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19720 regs->flags &= ~X86_EFLAGS_TF;
19721 @@ -477,7 +506,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19722 return;
19723 conditional_sti(regs);
19724
19725 - if (!user_mode_vm(regs))
19726 + if (!user_mode(regs))
19727 {
19728 if (!fixup_exception(regs)) {
19729 task->thread.error_code = error_code;
19730 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19731 index dc4e910..c9dedab 100644
19732 --- a/arch/x86/kernel/uprobes.c
19733 +++ b/arch/x86/kernel/uprobes.c
19734 @@ -606,7 +606,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19735 int ret = NOTIFY_DONE;
19736
19737 /* We are only interested in userspace traps */
19738 - if (regs && !user_mode_vm(regs))
19739 + if (regs && !user_mode(regs))
19740 return NOTIFY_DONE;
19741
19742 switch (val) {
19743 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19744 index b9242ba..50c5edd 100644
19745 --- a/arch/x86/kernel/verify_cpu.S
19746 +++ b/arch/x86/kernel/verify_cpu.S
19747 @@ -20,6 +20,7 @@
19748 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19749 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19750 * arch/x86/kernel/head_32.S: processor startup
19751 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19752 *
19753 * verify_cpu, returns the status of longmode and SSE in register %eax.
19754 * 0: Success 1: Failure
19755 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19756 index 255f58a..5e91150 100644
19757 --- a/arch/x86/kernel/vm86_32.c
19758 +++ b/arch/x86/kernel/vm86_32.c
19759 @@ -41,6 +41,7 @@
19760 #include <linux/ptrace.h>
19761 #include <linux/audit.h>
19762 #include <linux/stddef.h>
19763 +#include <linux/grsecurity.h>
19764
19765 #include <asm/uaccess.h>
19766 #include <asm/io.h>
19767 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19768 do_exit(SIGSEGV);
19769 }
19770
19771 - tss = &per_cpu(init_tss, get_cpu());
19772 + tss = init_tss + get_cpu();
19773 current->thread.sp0 = current->thread.saved_sp0;
19774 current->thread.sysenter_cs = __KERNEL_CS;
19775 load_sp0(tss, &current->thread);
19776 @@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19777 struct task_struct *tsk;
19778 int tmp, ret = -EPERM;
19779
19780 +#ifdef CONFIG_GRKERNSEC_VM86
19781 + if (!capable(CAP_SYS_RAWIO)) {
19782 + gr_handle_vm86();
19783 + goto out;
19784 + }
19785 +#endif
19786 +
19787 tsk = current;
19788 if (tsk->thread.saved_sp0)
19789 goto out;
19790 @@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19791 int tmp, ret;
19792 struct vm86plus_struct __user *v86;
19793
19794 +#ifdef CONFIG_GRKERNSEC_VM86
19795 + if (!capable(CAP_SYS_RAWIO)) {
19796 + gr_handle_vm86();
19797 + ret = -EPERM;
19798 + goto out;
19799 + }
19800 +#endif
19801 +
19802 tsk = current;
19803 switch (cmd) {
19804 case VM86_REQUEST_IRQ:
19805 @@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19806 tsk->thread.saved_fs = info->regs32->fs;
19807 tsk->thread.saved_gs = get_user_gs(info->regs32);
19808
19809 - tss = &per_cpu(init_tss, get_cpu());
19810 + tss = init_tss + get_cpu();
19811 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19812 if (cpu_has_sep)
19813 tsk->thread.sysenter_cs = 0;
19814 @@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19815 goto cannot_handle;
19816 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19817 goto cannot_handle;
19818 - intr_ptr = (unsigned long __user *) (i << 2);
19819 + intr_ptr = (__force unsigned long __user *) (i << 2);
19820 if (get_user(segoffs, intr_ptr))
19821 goto cannot_handle;
19822 if ((segoffs >> 16) == BIOSSEG)
19823 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19824 index 22a1530..8fbaaad 100644
19825 --- a/arch/x86/kernel/vmlinux.lds.S
19826 +++ b/arch/x86/kernel/vmlinux.lds.S
19827 @@ -26,6 +26,13 @@
19828 #include <asm/page_types.h>
19829 #include <asm/cache.h>
19830 #include <asm/boot.h>
19831 +#include <asm/segment.h>
19832 +
19833 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19834 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19835 +#else
19836 +#define __KERNEL_TEXT_OFFSET 0
19837 +#endif
19838
19839 #undef i386 /* in case the preprocessor is a 32bit one */
19840
19841 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19842
19843 PHDRS {
19844 text PT_LOAD FLAGS(5); /* R_E */
19845 +#ifdef CONFIG_X86_32
19846 + module PT_LOAD FLAGS(5); /* R_E */
19847 +#endif
19848 +#ifdef CONFIG_XEN
19849 + rodata PT_LOAD FLAGS(5); /* R_E */
19850 +#else
19851 + rodata PT_LOAD FLAGS(4); /* R__ */
19852 +#endif
19853 data PT_LOAD FLAGS(6); /* RW_ */
19854 -#ifdef CONFIG_X86_64
19855 + init.begin PT_LOAD FLAGS(6); /* RW_ */
19856 #ifdef CONFIG_SMP
19857 percpu PT_LOAD FLAGS(6); /* RW_ */
19858 #endif
19859 + text.init PT_LOAD FLAGS(5); /* R_E */
19860 + text.exit PT_LOAD FLAGS(5); /* R_E */
19861 init PT_LOAD FLAGS(7); /* RWE */
19862 -#endif
19863 note PT_NOTE FLAGS(0); /* ___ */
19864 }
19865
19866 SECTIONS
19867 {
19868 #ifdef CONFIG_X86_32
19869 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19870 - phys_startup_32 = startup_32 - LOAD_OFFSET;
19871 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19872 #else
19873 - . = __START_KERNEL;
19874 - phys_startup_64 = startup_64 - LOAD_OFFSET;
19875 + . = __START_KERNEL;
19876 #endif
19877
19878 /* Text and read-only data */
19879 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
19880 - _text = .;
19881 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19882 /* bootstrapping code */
19883 +#ifdef CONFIG_X86_32
19884 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19885 +#else
19886 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19887 +#endif
19888 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19889 + _text = .;
19890 HEAD_TEXT
19891 #ifdef CONFIG_X86_32
19892 . = ALIGN(PAGE_SIZE);
19893 @@ -108,13 +128,48 @@ SECTIONS
19894 IRQENTRY_TEXT
19895 *(.fixup)
19896 *(.gnu.warning)
19897 - /* End of text section */
19898 - _etext = .;
19899 } :text = 0x9090
19900
19901 - NOTES :text :note
19902 + . += __KERNEL_TEXT_OFFSET;
19903
19904 - EXCEPTION_TABLE(16) :text = 0x9090
19905 +#ifdef CONFIG_X86_32
19906 + . = ALIGN(PAGE_SIZE);
19907 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19908 +
19909 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19910 + MODULES_EXEC_VADDR = .;
19911 + BYTE(0)
19912 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19913 + . = ALIGN(HPAGE_SIZE) - 1;
19914 + MODULES_EXEC_END = .;
19915 +#endif
19916 +
19917 + } :module
19918 +#endif
19919 +
19920 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19921 + /* End of text section */
19922 + BYTE(0)
19923 + _etext = . - __KERNEL_TEXT_OFFSET;
19924 + }
19925 +
19926 +#ifdef CONFIG_X86_32
19927 + . = ALIGN(PAGE_SIZE);
19928 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
19929 + *(.idt)
19930 + . = ALIGN(PAGE_SIZE);
19931 + *(.empty_zero_page)
19932 + *(.initial_pg_fixmap)
19933 + *(.initial_pg_pmd)
19934 + *(.initial_page_table)
19935 + *(.swapper_pg_dir)
19936 + } :rodata
19937 +#endif
19938 +
19939 + . = ALIGN(PAGE_SIZE);
19940 + NOTES :rodata :note
19941 +
19942 + EXCEPTION_TABLE(16) :rodata
19943
19944 #if defined(CONFIG_DEBUG_RODATA)
19945 /* .text should occupy whole number of pages */
19946 @@ -126,16 +181,20 @@ SECTIONS
19947
19948 /* Data */
19949 .data : AT(ADDR(.data) - LOAD_OFFSET) {
19950 +
19951 +#ifdef CONFIG_PAX_KERNEXEC
19952 + . = ALIGN(HPAGE_SIZE);
19953 +#else
19954 + . = ALIGN(PAGE_SIZE);
19955 +#endif
19956 +
19957 /* Start of data section */
19958 _sdata = .;
19959
19960 /* init_task */
19961 INIT_TASK_DATA(THREAD_SIZE)
19962
19963 -#ifdef CONFIG_X86_32
19964 - /* 32 bit has nosave before _edata */
19965 NOSAVE_DATA
19966 -#endif
19967
19968 PAGE_ALIGNED_DATA(PAGE_SIZE)
19969
19970 @@ -176,12 +235,19 @@ SECTIONS
19971 #endif /* CONFIG_X86_64 */
19972
19973 /* Init code and data - will be freed after init */
19974 - . = ALIGN(PAGE_SIZE);
19975 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
19976 + BYTE(0)
19977 +
19978 +#ifdef CONFIG_PAX_KERNEXEC
19979 + . = ALIGN(HPAGE_SIZE);
19980 +#else
19981 + . = ALIGN(PAGE_SIZE);
19982 +#endif
19983 +
19984 __init_begin = .; /* paired with __init_end */
19985 - }
19986 + } :init.begin
19987
19988 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
19989 +#ifdef CONFIG_SMP
19990 /*
19991 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
19992 * output PHDR, so the next output section - .init.text - should
19993 @@ -190,12 +256,27 @@ SECTIONS
19994 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
19995 #endif
19996
19997 - INIT_TEXT_SECTION(PAGE_SIZE)
19998 -#ifdef CONFIG_X86_64
19999 - :init
20000 -#endif
20001 + . = ALIGN(PAGE_SIZE);
20002 + init_begin = .;
20003 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20004 + VMLINUX_SYMBOL(_sinittext) = .;
20005 + INIT_TEXT
20006 + VMLINUX_SYMBOL(_einittext) = .;
20007 + . = ALIGN(PAGE_SIZE);
20008 + } :text.init
20009
20010 - INIT_DATA_SECTION(16)
20011 + /*
20012 + * .exit.text is discard at runtime, not link time, to deal with
20013 + * references from .altinstructions and .eh_frame
20014 + */
20015 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20016 + EXIT_TEXT
20017 + . = ALIGN(16);
20018 + } :text.exit
20019 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20020 +
20021 + . = ALIGN(PAGE_SIZE);
20022 + INIT_DATA_SECTION(16) :init
20023
20024 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20025 __x86_cpu_dev_start = .;
20026 @@ -257,19 +338,12 @@ SECTIONS
20027 }
20028
20029 . = ALIGN(8);
20030 - /*
20031 - * .exit.text is discard at runtime, not link time, to deal with
20032 - * references from .altinstructions and .eh_frame
20033 - */
20034 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20035 - EXIT_TEXT
20036 - }
20037
20038 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20039 EXIT_DATA
20040 }
20041
20042 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20043 +#ifndef CONFIG_SMP
20044 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20045 #endif
20046
20047 @@ -288,16 +362,10 @@ SECTIONS
20048 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20049 __smp_locks = .;
20050 *(.smp_locks)
20051 - . = ALIGN(PAGE_SIZE);
20052 __smp_locks_end = .;
20053 + . = ALIGN(PAGE_SIZE);
20054 }
20055
20056 -#ifdef CONFIG_X86_64
20057 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20058 - NOSAVE_DATA
20059 - }
20060 -#endif
20061 -
20062 /* BSS */
20063 . = ALIGN(PAGE_SIZE);
20064 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20065 @@ -313,6 +381,7 @@ SECTIONS
20066 __brk_base = .;
20067 . += 64 * 1024; /* 64k alignment slop space */
20068 *(.brk_reservation) /* areas brk users have reserved */
20069 + . = ALIGN(HPAGE_SIZE);
20070 __brk_limit = .;
20071 }
20072
20073 @@ -339,13 +408,12 @@ SECTIONS
20074 * for the boot processor.
20075 */
20076 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20077 -INIT_PER_CPU(gdt_page);
20078 INIT_PER_CPU(irq_stack_union);
20079
20080 /*
20081 * Build-time check on the image size:
20082 */
20083 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20084 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20085 "kernel image bigger than KERNEL_IMAGE_SIZE");
20086
20087 #ifdef CONFIG_SMP
20088 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20089 index 5db36ca..2938af9 100644
20090 --- a/arch/x86/kernel/vsyscall_64.c
20091 +++ b/arch/x86/kernel/vsyscall_64.c
20092 @@ -54,15 +54,13 @@
20093 DEFINE_VVAR(int, vgetcpu_mode);
20094 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20095
20096 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20097 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20098
20099 static int __init vsyscall_setup(char *str)
20100 {
20101 if (str) {
20102 if (!strcmp("emulate", str))
20103 vsyscall_mode = EMULATE;
20104 - else if (!strcmp("native", str))
20105 - vsyscall_mode = NATIVE;
20106 else if (!strcmp("none", str))
20107 vsyscall_mode = NONE;
20108 else
20109 @@ -309,8 +307,7 @@ done:
20110 return true;
20111
20112 sigsegv:
20113 - force_sig(SIGSEGV, current);
20114 - return true;
20115 + do_group_exit(SIGKILL);
20116 }
20117
20118 /*
20119 @@ -363,10 +360,7 @@ void __init map_vsyscall(void)
20120 extern char __vvar_page;
20121 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20122
20123 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20124 - vsyscall_mode == NATIVE
20125 - ? PAGE_KERNEL_VSYSCALL
20126 - : PAGE_KERNEL_VVAR);
20127 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20128 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20129 (unsigned long)VSYSCALL_START);
20130
20131 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20132 index 9796c2f..f686fbf 100644
20133 --- a/arch/x86/kernel/x8664_ksyms_64.c
20134 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20135 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20136 EXPORT_SYMBOL(copy_user_generic_string);
20137 EXPORT_SYMBOL(copy_user_generic_unrolled);
20138 EXPORT_SYMBOL(__copy_user_nocache);
20139 -EXPORT_SYMBOL(_copy_from_user);
20140 -EXPORT_SYMBOL(_copy_to_user);
20141
20142 EXPORT_SYMBOL(copy_page);
20143 EXPORT_SYMBOL(clear_page);
20144 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20145 index bd18149..2ea0183 100644
20146 --- a/arch/x86/kernel/xsave.c
20147 +++ b/arch/x86/kernel/xsave.c
20148 @@ -129,7 +129,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20149 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20150 return -EINVAL;
20151
20152 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20153 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20154 fx_sw_user->extended_size -
20155 FP_XSTATE_MAGIC2_SIZE));
20156 if (err)
20157 @@ -265,7 +265,7 @@ fx_only:
20158 * the other extended state.
20159 */
20160 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20161 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20162 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20163 }
20164
20165 /*
20166 @@ -294,7 +294,7 @@ int restore_i387_xstate(void __user *buf)
20167 if (use_xsave())
20168 err = restore_user_xstate(buf);
20169 else
20170 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20171 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20172 buf);
20173 if (unlikely(err)) {
20174 /*
20175 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20176 index 7df1c6d..9ea7c79 100644
20177 --- a/arch/x86/kvm/cpuid.c
20178 +++ b/arch/x86/kvm/cpuid.c
20179 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20180 struct kvm_cpuid2 *cpuid,
20181 struct kvm_cpuid_entry2 __user *entries)
20182 {
20183 - int r;
20184 + int r, i;
20185
20186 r = -E2BIG;
20187 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20188 goto out;
20189 r = -EFAULT;
20190 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20191 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20192 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20193 goto out;
20194 + for (i = 0; i < cpuid->nent; ++i) {
20195 + struct kvm_cpuid_entry2 cpuid_entry;
20196 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20197 + goto out;
20198 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20199 + }
20200 vcpu->arch.cpuid_nent = cpuid->nent;
20201 kvm_apic_set_version(vcpu);
20202 kvm_x86_ops->cpuid_update(vcpu);
20203 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20204 struct kvm_cpuid2 *cpuid,
20205 struct kvm_cpuid_entry2 __user *entries)
20206 {
20207 - int r;
20208 + int r, i;
20209
20210 r = -E2BIG;
20211 if (cpuid->nent < vcpu->arch.cpuid_nent)
20212 goto out;
20213 r = -EFAULT;
20214 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20215 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20216 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20217 goto out;
20218 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20219 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20220 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20221 + goto out;
20222 + }
20223 return 0;
20224
20225 out:
20226 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20227 index f95d242..3b49a90 100644
20228 --- a/arch/x86/kvm/emulate.c
20229 +++ b/arch/x86/kvm/emulate.c
20230 @@ -256,6 +256,7 @@ struct gprefix {
20231
20232 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20233 do { \
20234 + unsigned long _tmp; \
20235 __asm__ __volatile__ ( \
20236 _PRE_EFLAGS("0", "4", "2") \
20237 _op _suffix " %"_x"3,%1; " \
20238 @@ -270,8 +271,6 @@ struct gprefix {
20239 /* Raw emulation: instruction has two explicit operands. */
20240 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20241 do { \
20242 - unsigned long _tmp; \
20243 - \
20244 switch ((ctxt)->dst.bytes) { \
20245 case 2: \
20246 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20247 @@ -287,7 +286,6 @@ struct gprefix {
20248
20249 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20250 do { \
20251 - unsigned long _tmp; \
20252 switch ((ctxt)->dst.bytes) { \
20253 case 1: \
20254 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20255 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20256 index 93c1574..d6097dc 100644
20257 --- a/arch/x86/kvm/lapic.c
20258 +++ b/arch/x86/kvm/lapic.c
20259 @@ -54,7 +54,7 @@
20260 #define APIC_BUS_CYCLE_NS 1
20261
20262 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20263 -#define apic_debug(fmt, arg...)
20264 +#define apic_debug(fmt, arg...) do {} while (0)
20265
20266 #define APIC_LVT_NUM 6
20267 /* 14 is the version for Xeon and Pentium 8.4.8*/
20268 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20269 index 34f9709..8eca2d5 100644
20270 --- a/arch/x86/kvm/paging_tmpl.h
20271 +++ b/arch/x86/kvm/paging_tmpl.h
20272 @@ -197,7 +197,7 @@ retry_walk:
20273 if (unlikely(kvm_is_error_hva(host_addr)))
20274 goto error;
20275
20276 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20277 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20278 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20279 goto error;
20280
20281 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20282 index f75af40..285b18f 100644
20283 --- a/arch/x86/kvm/svm.c
20284 +++ b/arch/x86/kvm/svm.c
20285 @@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20286 int cpu = raw_smp_processor_id();
20287
20288 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20289 +
20290 + pax_open_kernel();
20291 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20292 + pax_close_kernel();
20293 +
20294 load_TR_desc();
20295 }
20296
20297 @@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20298 #endif
20299 #endif
20300
20301 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20302 + __set_fs(current_thread_info()->addr_limit);
20303 +#endif
20304 +
20305 reload_tss(vcpu);
20306
20307 local_irq_disable();
20308 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20309 index 32eb588..19c4fe3 100644
20310 --- a/arch/x86/kvm/vmx.c
20311 +++ b/arch/x86/kvm/vmx.c
20312 @@ -1313,7 +1313,11 @@ static void reload_tss(void)
20313 struct desc_struct *descs;
20314
20315 descs = (void *)gdt->address;
20316 +
20317 + pax_open_kernel();
20318 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20319 + pax_close_kernel();
20320 +
20321 load_TR_desc();
20322 }
20323
20324 @@ -1475,8 +1479,8 @@ static void __vmx_load_host_state(struct vcpu_vmx *vmx)
20325 * The sysexit path does not restore ds/es, so we must set them to
20326 * a reasonable value ourselves.
20327 */
20328 - loadsegment(ds, __USER_DS);
20329 - loadsegment(es, __USER_DS);
20330 + loadsegment(ds, __KERNEL_DS);
20331 + loadsegment(es, __KERNEL_DS);
20332 #endif
20333 reload_tss();
20334 #ifdef CONFIG_X86_64
20335 @@ -2653,8 +2657,11 @@ static __init int hardware_setup(void)
20336 if (!cpu_has_vmx_flexpriority())
20337 flexpriority_enabled = 0;
20338
20339 - if (!cpu_has_vmx_tpr_shadow())
20340 - kvm_x86_ops->update_cr8_intercept = NULL;
20341 + if (!cpu_has_vmx_tpr_shadow()) {
20342 + pax_open_kernel();
20343 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20344 + pax_close_kernel();
20345 + }
20346
20347 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20348 kvm_disable_largepages();
20349 @@ -3680,7 +3687,7 @@ static void vmx_set_constant_host_state(void)
20350 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20351
20352 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20353 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20354 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20355
20356 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20357 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20358 @@ -6218,6 +6225,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20359 "jmp .Lkvm_vmx_return \n\t"
20360 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20361 ".Lkvm_vmx_return: "
20362 +
20363 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20364 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20365 + ".Lkvm_vmx_return2: "
20366 +#endif
20367 +
20368 /* Save guest registers, load host registers, keep flags */
20369 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20370 "pop %0 \n\t"
20371 @@ -6266,6 +6279,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20372 #endif
20373 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20374 [wordsize]"i"(sizeof(ulong))
20375 +
20376 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20377 + ,[cs]"i"(__KERNEL_CS)
20378 +#endif
20379 +
20380 : "cc", "memory"
20381 , R"ax", R"bx", R"di", R"si"
20382 #ifdef CONFIG_X86_64
20383 @@ -6294,6 +6312,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20384 }
20385 }
20386
20387 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20388 +
20389 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20390 + loadsegment(fs, __KERNEL_PERCPU);
20391 +#endif
20392 +
20393 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20394 + __set_fs(current_thread_info()->addr_limit);
20395 +#endif
20396 +
20397 vmx->loaded_vmcs->launched = 1;
20398
20399 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20400 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20401 index be6d549..b0ba2bf 100644
20402 --- a/arch/x86/kvm/x86.c
20403 +++ b/arch/x86/kvm/x86.c
20404 @@ -1357,8 +1357,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20405 {
20406 struct kvm *kvm = vcpu->kvm;
20407 int lm = is_long_mode(vcpu);
20408 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20409 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20410 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20411 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20412 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20413 : kvm->arch.xen_hvm_config.blob_size_32;
20414 u32 page_num = data & ~PAGE_MASK;
20415 @@ -2214,6 +2214,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20416 if (n < msr_list.nmsrs)
20417 goto out;
20418 r = -EFAULT;
20419 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20420 + goto out;
20421 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20422 num_msrs_to_save * sizeof(u32)))
20423 goto out;
20424 @@ -2339,7 +2341,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20425 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20426 struct kvm_interrupt *irq)
20427 {
20428 - if (irq->irq < 0 || irq->irq >= 256)
20429 + if (irq->irq >= 256)
20430 return -EINVAL;
20431 if (irqchip_in_kernel(vcpu->kvm))
20432 return -ENXIO;
20433 @@ -4876,7 +4878,7 @@ static void kvm_set_mmio_spte_mask(void)
20434 kvm_mmu_set_mmio_spte_mask(mask);
20435 }
20436
20437 -int kvm_arch_init(void *opaque)
20438 +int kvm_arch_init(const void *opaque)
20439 {
20440 int r;
20441 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20442 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20443 index 642d880..44e0f3f 100644
20444 --- a/arch/x86/lguest/boot.c
20445 +++ b/arch/x86/lguest/boot.c
20446 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20447 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20448 * Launcher to reboot us.
20449 */
20450 -static void lguest_restart(char *reason)
20451 +static __noreturn void lguest_restart(char *reason)
20452 {
20453 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20454 + BUG();
20455 }
20456
20457 /*G:050
20458 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20459 index 00933d5..3a64af9 100644
20460 --- a/arch/x86/lib/atomic64_386_32.S
20461 +++ b/arch/x86/lib/atomic64_386_32.S
20462 @@ -48,6 +48,10 @@ BEGIN(read)
20463 movl (v), %eax
20464 movl 4(v), %edx
20465 RET_ENDP
20466 +BEGIN(read_unchecked)
20467 + movl (v), %eax
20468 + movl 4(v), %edx
20469 +RET_ENDP
20470 #undef v
20471
20472 #define v %esi
20473 @@ -55,6 +59,10 @@ BEGIN(set)
20474 movl %ebx, (v)
20475 movl %ecx, 4(v)
20476 RET_ENDP
20477 +BEGIN(set_unchecked)
20478 + movl %ebx, (v)
20479 + movl %ecx, 4(v)
20480 +RET_ENDP
20481 #undef v
20482
20483 #define v %esi
20484 @@ -70,6 +78,20 @@ RET_ENDP
20485 BEGIN(add)
20486 addl %eax, (v)
20487 adcl %edx, 4(v)
20488 +
20489 +#ifdef CONFIG_PAX_REFCOUNT
20490 + jno 0f
20491 + subl %eax, (v)
20492 + sbbl %edx, 4(v)
20493 + int $4
20494 +0:
20495 + _ASM_EXTABLE(0b, 0b)
20496 +#endif
20497 +
20498 +RET_ENDP
20499 +BEGIN(add_unchecked)
20500 + addl %eax, (v)
20501 + adcl %edx, 4(v)
20502 RET_ENDP
20503 #undef v
20504
20505 @@ -77,6 +99,24 @@ RET_ENDP
20506 BEGIN(add_return)
20507 addl (v), %eax
20508 adcl 4(v), %edx
20509 +
20510 +#ifdef CONFIG_PAX_REFCOUNT
20511 + into
20512 +1234:
20513 + _ASM_EXTABLE(1234b, 2f)
20514 +#endif
20515 +
20516 + movl %eax, (v)
20517 + movl %edx, 4(v)
20518 +
20519 +#ifdef CONFIG_PAX_REFCOUNT
20520 +2:
20521 +#endif
20522 +
20523 +RET_ENDP
20524 +BEGIN(add_return_unchecked)
20525 + addl (v), %eax
20526 + adcl 4(v), %edx
20527 movl %eax, (v)
20528 movl %edx, 4(v)
20529 RET_ENDP
20530 @@ -86,6 +126,20 @@ RET_ENDP
20531 BEGIN(sub)
20532 subl %eax, (v)
20533 sbbl %edx, 4(v)
20534 +
20535 +#ifdef CONFIG_PAX_REFCOUNT
20536 + jno 0f
20537 + addl %eax, (v)
20538 + adcl %edx, 4(v)
20539 + int $4
20540 +0:
20541 + _ASM_EXTABLE(0b, 0b)
20542 +#endif
20543 +
20544 +RET_ENDP
20545 +BEGIN(sub_unchecked)
20546 + subl %eax, (v)
20547 + sbbl %edx, 4(v)
20548 RET_ENDP
20549 #undef v
20550
20551 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20552 sbbl $0, %edx
20553 addl (v), %eax
20554 adcl 4(v), %edx
20555 +
20556 +#ifdef CONFIG_PAX_REFCOUNT
20557 + into
20558 +1234:
20559 + _ASM_EXTABLE(1234b, 2f)
20560 +#endif
20561 +
20562 + movl %eax, (v)
20563 + movl %edx, 4(v)
20564 +
20565 +#ifdef CONFIG_PAX_REFCOUNT
20566 +2:
20567 +#endif
20568 +
20569 +RET_ENDP
20570 +BEGIN(sub_return_unchecked)
20571 + negl %edx
20572 + negl %eax
20573 + sbbl $0, %edx
20574 + addl (v), %eax
20575 + adcl 4(v), %edx
20576 movl %eax, (v)
20577 movl %edx, 4(v)
20578 RET_ENDP
20579 @@ -105,6 +180,20 @@ RET_ENDP
20580 BEGIN(inc)
20581 addl $1, (v)
20582 adcl $0, 4(v)
20583 +
20584 +#ifdef CONFIG_PAX_REFCOUNT
20585 + jno 0f
20586 + subl $1, (v)
20587 + sbbl $0, 4(v)
20588 + int $4
20589 +0:
20590 + _ASM_EXTABLE(0b, 0b)
20591 +#endif
20592 +
20593 +RET_ENDP
20594 +BEGIN(inc_unchecked)
20595 + addl $1, (v)
20596 + adcl $0, 4(v)
20597 RET_ENDP
20598 #undef v
20599
20600 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20601 movl 4(v), %edx
20602 addl $1, %eax
20603 adcl $0, %edx
20604 +
20605 +#ifdef CONFIG_PAX_REFCOUNT
20606 + into
20607 +1234:
20608 + _ASM_EXTABLE(1234b, 2f)
20609 +#endif
20610 +
20611 + movl %eax, (v)
20612 + movl %edx, 4(v)
20613 +
20614 +#ifdef CONFIG_PAX_REFCOUNT
20615 +2:
20616 +#endif
20617 +
20618 +RET_ENDP
20619 +BEGIN(inc_return_unchecked)
20620 + movl (v), %eax
20621 + movl 4(v), %edx
20622 + addl $1, %eax
20623 + adcl $0, %edx
20624 movl %eax, (v)
20625 movl %edx, 4(v)
20626 RET_ENDP
20627 @@ -123,6 +232,20 @@ RET_ENDP
20628 BEGIN(dec)
20629 subl $1, (v)
20630 sbbl $0, 4(v)
20631 +
20632 +#ifdef CONFIG_PAX_REFCOUNT
20633 + jno 0f
20634 + addl $1, (v)
20635 + adcl $0, 4(v)
20636 + int $4
20637 +0:
20638 + _ASM_EXTABLE(0b, 0b)
20639 +#endif
20640 +
20641 +RET_ENDP
20642 +BEGIN(dec_unchecked)
20643 + subl $1, (v)
20644 + sbbl $0, 4(v)
20645 RET_ENDP
20646 #undef v
20647
20648 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20649 movl 4(v), %edx
20650 subl $1, %eax
20651 sbbl $0, %edx
20652 +
20653 +#ifdef CONFIG_PAX_REFCOUNT
20654 + into
20655 +1234:
20656 + _ASM_EXTABLE(1234b, 2f)
20657 +#endif
20658 +
20659 + movl %eax, (v)
20660 + movl %edx, 4(v)
20661 +
20662 +#ifdef CONFIG_PAX_REFCOUNT
20663 +2:
20664 +#endif
20665 +
20666 +RET_ENDP
20667 +BEGIN(dec_return_unchecked)
20668 + movl (v), %eax
20669 + movl 4(v), %edx
20670 + subl $1, %eax
20671 + sbbl $0, %edx
20672 movl %eax, (v)
20673 movl %edx, 4(v)
20674 RET_ENDP
20675 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20676 adcl %edx, %edi
20677 addl (v), %eax
20678 adcl 4(v), %edx
20679 +
20680 +#ifdef CONFIG_PAX_REFCOUNT
20681 + into
20682 +1234:
20683 + _ASM_EXTABLE(1234b, 2f)
20684 +#endif
20685 +
20686 cmpl %eax, %ecx
20687 je 3f
20688 1:
20689 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20690 1:
20691 addl $1, %eax
20692 adcl $0, %edx
20693 +
20694 +#ifdef CONFIG_PAX_REFCOUNT
20695 + into
20696 +1234:
20697 + _ASM_EXTABLE(1234b, 2f)
20698 +#endif
20699 +
20700 movl %eax, (v)
20701 movl %edx, 4(v)
20702 movl $1, %eax
20703 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20704 movl 4(v), %edx
20705 subl $1, %eax
20706 sbbl $0, %edx
20707 +
20708 +#ifdef CONFIG_PAX_REFCOUNT
20709 + into
20710 +1234:
20711 + _ASM_EXTABLE(1234b, 1f)
20712 +#endif
20713 +
20714 js 1f
20715 movl %eax, (v)
20716 movl %edx, 4(v)
20717 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20718 index f5cc9eb..51fa319 100644
20719 --- a/arch/x86/lib/atomic64_cx8_32.S
20720 +++ b/arch/x86/lib/atomic64_cx8_32.S
20721 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20722 CFI_STARTPROC
20723
20724 read64 %ecx
20725 + pax_force_retaddr
20726 ret
20727 CFI_ENDPROC
20728 ENDPROC(atomic64_read_cx8)
20729
20730 +ENTRY(atomic64_read_unchecked_cx8)
20731 + CFI_STARTPROC
20732 +
20733 + read64 %ecx
20734 + pax_force_retaddr
20735 + ret
20736 + CFI_ENDPROC
20737 +ENDPROC(atomic64_read_unchecked_cx8)
20738 +
20739 ENTRY(atomic64_set_cx8)
20740 CFI_STARTPROC
20741
20742 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20743 cmpxchg8b (%esi)
20744 jne 1b
20745
20746 + pax_force_retaddr
20747 ret
20748 CFI_ENDPROC
20749 ENDPROC(atomic64_set_cx8)
20750
20751 +ENTRY(atomic64_set_unchecked_cx8)
20752 + CFI_STARTPROC
20753 +
20754 +1:
20755 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20756 + * are atomic on 586 and newer */
20757 + cmpxchg8b (%esi)
20758 + jne 1b
20759 +
20760 + pax_force_retaddr
20761 + ret
20762 + CFI_ENDPROC
20763 +ENDPROC(atomic64_set_unchecked_cx8)
20764 +
20765 ENTRY(atomic64_xchg_cx8)
20766 CFI_STARTPROC
20767
20768 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
20769 cmpxchg8b (%esi)
20770 jne 1b
20771
20772 + pax_force_retaddr
20773 ret
20774 CFI_ENDPROC
20775 ENDPROC(atomic64_xchg_cx8)
20776
20777 -.macro addsub_return func ins insc
20778 -ENTRY(atomic64_\func\()_return_cx8)
20779 +.macro addsub_return func ins insc unchecked=""
20780 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20781 CFI_STARTPROC
20782 SAVE ebp
20783 SAVE ebx
20784 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20785 movl %edx, %ecx
20786 \ins\()l %esi, %ebx
20787 \insc\()l %edi, %ecx
20788 +
20789 +.ifb \unchecked
20790 +#ifdef CONFIG_PAX_REFCOUNT
20791 + into
20792 +2:
20793 + _ASM_EXTABLE(2b, 3f)
20794 +#endif
20795 +.endif
20796 +
20797 LOCK_PREFIX
20798 cmpxchg8b (%ebp)
20799 jne 1b
20800 -
20801 -10:
20802 movl %ebx, %eax
20803 movl %ecx, %edx
20804 +
20805 +.ifb \unchecked
20806 +#ifdef CONFIG_PAX_REFCOUNT
20807 +3:
20808 +#endif
20809 +.endif
20810 +
20811 RESTORE edi
20812 RESTORE esi
20813 RESTORE ebx
20814 RESTORE ebp
20815 + pax_force_retaddr
20816 ret
20817 CFI_ENDPROC
20818 -ENDPROC(atomic64_\func\()_return_cx8)
20819 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20820 .endm
20821
20822 addsub_return add add adc
20823 addsub_return sub sub sbb
20824 +addsub_return add add adc _unchecked
20825 +addsub_return sub sub sbb _unchecked
20826
20827 -.macro incdec_return func ins insc
20828 -ENTRY(atomic64_\func\()_return_cx8)
20829 +.macro incdec_return func ins insc unchecked=""
20830 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20831 CFI_STARTPROC
20832 SAVE ebx
20833
20834 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
20835 movl %edx, %ecx
20836 \ins\()l $1, %ebx
20837 \insc\()l $0, %ecx
20838 +
20839 +.ifb \unchecked
20840 +#ifdef CONFIG_PAX_REFCOUNT
20841 + into
20842 +2:
20843 + _ASM_EXTABLE(2b, 3f)
20844 +#endif
20845 +.endif
20846 +
20847 LOCK_PREFIX
20848 cmpxchg8b (%esi)
20849 jne 1b
20850
20851 -10:
20852 movl %ebx, %eax
20853 movl %ecx, %edx
20854 +
20855 +.ifb \unchecked
20856 +#ifdef CONFIG_PAX_REFCOUNT
20857 +3:
20858 +#endif
20859 +.endif
20860 +
20861 RESTORE ebx
20862 + pax_force_retaddr
20863 ret
20864 CFI_ENDPROC
20865 -ENDPROC(atomic64_\func\()_return_cx8)
20866 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20867 .endm
20868
20869 incdec_return inc add adc
20870 incdec_return dec sub sbb
20871 +incdec_return inc add adc _unchecked
20872 +incdec_return dec sub sbb _unchecked
20873
20874 ENTRY(atomic64_dec_if_positive_cx8)
20875 CFI_STARTPROC
20876 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
20877 movl %edx, %ecx
20878 subl $1, %ebx
20879 sbb $0, %ecx
20880 +
20881 +#ifdef CONFIG_PAX_REFCOUNT
20882 + into
20883 +1234:
20884 + _ASM_EXTABLE(1234b, 2f)
20885 +#endif
20886 +
20887 js 2f
20888 LOCK_PREFIX
20889 cmpxchg8b (%esi)
20890 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
20891 movl %ebx, %eax
20892 movl %ecx, %edx
20893 RESTORE ebx
20894 + pax_force_retaddr
20895 ret
20896 CFI_ENDPROC
20897 ENDPROC(atomic64_dec_if_positive_cx8)
20898 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
20899 movl %edx, %ecx
20900 addl %ebp, %ebx
20901 adcl %edi, %ecx
20902 +
20903 +#ifdef CONFIG_PAX_REFCOUNT
20904 + into
20905 +1234:
20906 + _ASM_EXTABLE(1234b, 3f)
20907 +#endif
20908 +
20909 LOCK_PREFIX
20910 cmpxchg8b (%esi)
20911 jne 1b
20912 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
20913 CFI_ADJUST_CFA_OFFSET -8
20914 RESTORE ebx
20915 RESTORE ebp
20916 + pax_force_retaddr
20917 ret
20918 4:
20919 cmpl %edx, 4(%esp)
20920 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
20921 xorl %ecx, %ecx
20922 addl $1, %ebx
20923 adcl %edx, %ecx
20924 +
20925 +#ifdef CONFIG_PAX_REFCOUNT
20926 + into
20927 +1234:
20928 + _ASM_EXTABLE(1234b, 3f)
20929 +#endif
20930 +
20931 LOCK_PREFIX
20932 cmpxchg8b (%esi)
20933 jne 1b
20934 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
20935 movl $1, %eax
20936 3:
20937 RESTORE ebx
20938 + pax_force_retaddr
20939 ret
20940 CFI_ENDPROC
20941 ENDPROC(atomic64_inc_not_zero_cx8)
20942 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
20943 index 2af5df3..62b1a5a 100644
20944 --- a/arch/x86/lib/checksum_32.S
20945 +++ b/arch/x86/lib/checksum_32.S
20946 @@ -29,7 +29,8 @@
20947 #include <asm/dwarf2.h>
20948 #include <asm/errno.h>
20949 #include <asm/asm.h>
20950 -
20951 +#include <asm/segment.h>
20952 +
20953 /*
20954 * computes a partial checksum, e.g. for TCP/UDP fragments
20955 */
20956 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
20957
20958 #define ARGBASE 16
20959 #define FP 12
20960 -
20961 -ENTRY(csum_partial_copy_generic)
20962 +
20963 +ENTRY(csum_partial_copy_generic_to_user)
20964 CFI_STARTPROC
20965 +
20966 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20967 + pushl_cfi %gs
20968 + popl_cfi %es
20969 + jmp csum_partial_copy_generic
20970 +#endif
20971 +
20972 +ENTRY(csum_partial_copy_generic_from_user)
20973 +
20974 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20975 + pushl_cfi %gs
20976 + popl_cfi %ds
20977 +#endif
20978 +
20979 +ENTRY(csum_partial_copy_generic)
20980 subl $4,%esp
20981 CFI_ADJUST_CFA_OFFSET 4
20982 pushl_cfi %edi
20983 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
20984 jmp 4f
20985 SRC(1: movw (%esi), %bx )
20986 addl $2, %esi
20987 -DST( movw %bx, (%edi) )
20988 +DST( movw %bx, %es:(%edi) )
20989 addl $2, %edi
20990 addw %bx, %ax
20991 adcl $0, %eax
20992 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
20993 SRC(1: movl (%esi), %ebx )
20994 SRC( movl 4(%esi), %edx )
20995 adcl %ebx, %eax
20996 -DST( movl %ebx, (%edi) )
20997 +DST( movl %ebx, %es:(%edi) )
20998 adcl %edx, %eax
20999 -DST( movl %edx, 4(%edi) )
21000 +DST( movl %edx, %es:4(%edi) )
21001
21002 SRC( movl 8(%esi), %ebx )
21003 SRC( movl 12(%esi), %edx )
21004 adcl %ebx, %eax
21005 -DST( movl %ebx, 8(%edi) )
21006 +DST( movl %ebx, %es:8(%edi) )
21007 adcl %edx, %eax
21008 -DST( movl %edx, 12(%edi) )
21009 +DST( movl %edx, %es:12(%edi) )
21010
21011 SRC( movl 16(%esi), %ebx )
21012 SRC( movl 20(%esi), %edx )
21013 adcl %ebx, %eax
21014 -DST( movl %ebx, 16(%edi) )
21015 +DST( movl %ebx, %es:16(%edi) )
21016 adcl %edx, %eax
21017 -DST( movl %edx, 20(%edi) )
21018 +DST( movl %edx, %es:20(%edi) )
21019
21020 SRC( movl 24(%esi), %ebx )
21021 SRC( movl 28(%esi), %edx )
21022 adcl %ebx, %eax
21023 -DST( movl %ebx, 24(%edi) )
21024 +DST( movl %ebx, %es:24(%edi) )
21025 adcl %edx, %eax
21026 -DST( movl %edx, 28(%edi) )
21027 +DST( movl %edx, %es:28(%edi) )
21028
21029 lea 32(%esi), %esi
21030 lea 32(%edi), %edi
21031 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21032 shrl $2, %edx # This clears CF
21033 SRC(3: movl (%esi), %ebx )
21034 adcl %ebx, %eax
21035 -DST( movl %ebx, (%edi) )
21036 +DST( movl %ebx, %es:(%edi) )
21037 lea 4(%esi), %esi
21038 lea 4(%edi), %edi
21039 dec %edx
21040 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21041 jb 5f
21042 SRC( movw (%esi), %cx )
21043 leal 2(%esi), %esi
21044 -DST( movw %cx, (%edi) )
21045 +DST( movw %cx, %es:(%edi) )
21046 leal 2(%edi), %edi
21047 je 6f
21048 shll $16,%ecx
21049 SRC(5: movb (%esi), %cl )
21050 -DST( movb %cl, (%edi) )
21051 +DST( movb %cl, %es:(%edi) )
21052 6: addl %ecx, %eax
21053 adcl $0, %eax
21054 7:
21055 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21056
21057 6001:
21058 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21059 - movl $-EFAULT, (%ebx)
21060 + movl $-EFAULT, %ss:(%ebx)
21061
21062 # zero the complete destination - computing the rest
21063 # is too much work
21064 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21065
21066 6002:
21067 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21068 - movl $-EFAULT,(%ebx)
21069 + movl $-EFAULT,%ss:(%ebx)
21070 jmp 5000b
21071
21072 .previous
21073
21074 + pushl_cfi %ss
21075 + popl_cfi %ds
21076 + pushl_cfi %ss
21077 + popl_cfi %es
21078 popl_cfi %ebx
21079 CFI_RESTORE ebx
21080 popl_cfi %esi
21081 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21082 popl_cfi %ecx # equivalent to addl $4,%esp
21083 ret
21084 CFI_ENDPROC
21085 -ENDPROC(csum_partial_copy_generic)
21086 +ENDPROC(csum_partial_copy_generic_to_user)
21087
21088 #else
21089
21090 /* Version for PentiumII/PPro */
21091
21092 #define ROUND1(x) \
21093 + nop; nop; nop; \
21094 SRC(movl x(%esi), %ebx ) ; \
21095 addl %ebx, %eax ; \
21096 - DST(movl %ebx, x(%edi) ) ;
21097 + DST(movl %ebx, %es:x(%edi)) ;
21098
21099 #define ROUND(x) \
21100 + nop; nop; nop; \
21101 SRC(movl x(%esi), %ebx ) ; \
21102 adcl %ebx, %eax ; \
21103 - DST(movl %ebx, x(%edi) ) ;
21104 + DST(movl %ebx, %es:x(%edi)) ;
21105
21106 #define ARGBASE 12
21107 -
21108 -ENTRY(csum_partial_copy_generic)
21109 +
21110 +ENTRY(csum_partial_copy_generic_to_user)
21111 CFI_STARTPROC
21112 +
21113 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21114 + pushl_cfi %gs
21115 + popl_cfi %es
21116 + jmp csum_partial_copy_generic
21117 +#endif
21118 +
21119 +ENTRY(csum_partial_copy_generic_from_user)
21120 +
21121 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21122 + pushl_cfi %gs
21123 + popl_cfi %ds
21124 +#endif
21125 +
21126 +ENTRY(csum_partial_copy_generic)
21127 pushl_cfi %ebx
21128 CFI_REL_OFFSET ebx, 0
21129 pushl_cfi %edi
21130 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21131 subl %ebx, %edi
21132 lea -1(%esi),%edx
21133 andl $-32,%edx
21134 - lea 3f(%ebx,%ebx), %ebx
21135 + lea 3f(%ebx,%ebx,2), %ebx
21136 testl %esi, %esi
21137 jmp *%ebx
21138 1: addl $64,%esi
21139 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21140 jb 5f
21141 SRC( movw (%esi), %dx )
21142 leal 2(%esi), %esi
21143 -DST( movw %dx, (%edi) )
21144 +DST( movw %dx, %es:(%edi) )
21145 leal 2(%edi), %edi
21146 je 6f
21147 shll $16,%edx
21148 5:
21149 SRC( movb (%esi), %dl )
21150 -DST( movb %dl, (%edi) )
21151 +DST( movb %dl, %es:(%edi) )
21152 6: addl %edx, %eax
21153 adcl $0, %eax
21154 7:
21155 .section .fixup, "ax"
21156 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21157 - movl $-EFAULT, (%ebx)
21158 + movl $-EFAULT, %ss:(%ebx)
21159 # zero the complete destination (computing the rest is too much work)
21160 movl ARGBASE+8(%esp),%edi # dst
21161 movl ARGBASE+12(%esp),%ecx # len
21162 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21163 rep; stosb
21164 jmp 7b
21165 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21166 - movl $-EFAULT, (%ebx)
21167 + movl $-EFAULT, %ss:(%ebx)
21168 jmp 7b
21169 .previous
21170
21171 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21172 + pushl_cfi %ss
21173 + popl_cfi %ds
21174 + pushl_cfi %ss
21175 + popl_cfi %es
21176 +#endif
21177 +
21178 popl_cfi %esi
21179 CFI_RESTORE esi
21180 popl_cfi %edi
21181 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21182 CFI_RESTORE ebx
21183 ret
21184 CFI_ENDPROC
21185 -ENDPROC(csum_partial_copy_generic)
21186 +ENDPROC(csum_partial_copy_generic_to_user)
21187
21188 #undef ROUND
21189 #undef ROUND1
21190 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21191 index f2145cf..cea889d 100644
21192 --- a/arch/x86/lib/clear_page_64.S
21193 +++ b/arch/x86/lib/clear_page_64.S
21194 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21195 movl $4096/8,%ecx
21196 xorl %eax,%eax
21197 rep stosq
21198 + pax_force_retaddr
21199 ret
21200 CFI_ENDPROC
21201 ENDPROC(clear_page_c)
21202 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21203 movl $4096,%ecx
21204 xorl %eax,%eax
21205 rep stosb
21206 + pax_force_retaddr
21207 ret
21208 CFI_ENDPROC
21209 ENDPROC(clear_page_c_e)
21210 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21211 leaq 64(%rdi),%rdi
21212 jnz .Lloop
21213 nop
21214 + pax_force_retaddr
21215 ret
21216 CFI_ENDPROC
21217 .Lclear_page_end:
21218 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21219
21220 #include <asm/cpufeature.h>
21221
21222 - .section .altinstr_replacement,"ax"
21223 + .section .altinstr_replacement,"a"
21224 1: .byte 0xeb /* jmp <disp8> */
21225 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21226 2: .byte 0xeb /* jmp <disp8> */
21227 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21228 index 1e572c5..2a162cd 100644
21229 --- a/arch/x86/lib/cmpxchg16b_emu.S
21230 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21231 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21232
21233 popf
21234 mov $1, %al
21235 + pax_force_retaddr
21236 ret
21237
21238 not_same:
21239 popf
21240 xor %al,%al
21241 + pax_force_retaddr
21242 ret
21243
21244 CFI_ENDPROC
21245 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21246 index 6b34d04..dccb07f 100644
21247 --- a/arch/x86/lib/copy_page_64.S
21248 +++ b/arch/x86/lib/copy_page_64.S
21249 @@ -9,6 +9,7 @@ copy_page_c:
21250 CFI_STARTPROC
21251 movl $4096/8,%ecx
21252 rep movsq
21253 + pax_force_retaddr
21254 ret
21255 CFI_ENDPROC
21256 ENDPROC(copy_page_c)
21257 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21258
21259 ENTRY(copy_page)
21260 CFI_STARTPROC
21261 - subq $2*8,%rsp
21262 - CFI_ADJUST_CFA_OFFSET 2*8
21263 + subq $3*8,%rsp
21264 + CFI_ADJUST_CFA_OFFSET 3*8
21265 movq %rbx,(%rsp)
21266 CFI_REL_OFFSET rbx, 0
21267 movq %r12,1*8(%rsp)
21268 CFI_REL_OFFSET r12, 1*8
21269 + movq %r13,2*8(%rsp)
21270 + CFI_REL_OFFSET r13, 2*8
21271
21272 movl $(4096/64)-5,%ecx
21273 .p2align 4
21274 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21275 movq 16 (%rsi), %rdx
21276 movq 24 (%rsi), %r8
21277 movq 32 (%rsi), %r9
21278 - movq 40 (%rsi), %r10
21279 + movq 40 (%rsi), %r13
21280 movq 48 (%rsi), %r11
21281 movq 56 (%rsi), %r12
21282
21283 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21284 movq %rdx, 16 (%rdi)
21285 movq %r8, 24 (%rdi)
21286 movq %r9, 32 (%rdi)
21287 - movq %r10, 40 (%rdi)
21288 + movq %r13, 40 (%rdi)
21289 movq %r11, 48 (%rdi)
21290 movq %r12, 56 (%rdi)
21291
21292 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21293 movq 16 (%rsi), %rdx
21294 movq 24 (%rsi), %r8
21295 movq 32 (%rsi), %r9
21296 - movq 40 (%rsi), %r10
21297 + movq 40 (%rsi), %r13
21298 movq 48 (%rsi), %r11
21299 movq 56 (%rsi), %r12
21300
21301 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21302 movq %rdx, 16 (%rdi)
21303 movq %r8, 24 (%rdi)
21304 movq %r9, 32 (%rdi)
21305 - movq %r10, 40 (%rdi)
21306 + movq %r13, 40 (%rdi)
21307 movq %r11, 48 (%rdi)
21308 movq %r12, 56 (%rdi)
21309
21310 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21311 CFI_RESTORE rbx
21312 movq 1*8(%rsp),%r12
21313 CFI_RESTORE r12
21314 - addq $2*8,%rsp
21315 - CFI_ADJUST_CFA_OFFSET -2*8
21316 + movq 2*8(%rsp),%r13
21317 + CFI_RESTORE r13
21318 + addq $3*8,%rsp
21319 + CFI_ADJUST_CFA_OFFSET -3*8
21320 + pax_force_retaddr
21321 ret
21322 .Lcopy_page_end:
21323 CFI_ENDPROC
21324 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21325
21326 #include <asm/cpufeature.h>
21327
21328 - .section .altinstr_replacement,"ax"
21329 + .section .altinstr_replacement,"a"
21330 1: .byte 0xeb /* jmp <disp8> */
21331 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21332 2:
21333 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21334 index 5b2995f..78e7644 100644
21335 --- a/arch/x86/lib/copy_user_64.S
21336 +++ b/arch/x86/lib/copy_user_64.S
21337 @@ -17,6 +17,7 @@
21338 #include <asm/cpufeature.h>
21339 #include <asm/alternative-asm.h>
21340 #include <asm/asm.h>
21341 +#include <asm/pgtable.h>
21342
21343 /*
21344 * By placing feature2 after feature1 in altinstructions section, we logically
21345 @@ -30,7 +31,7 @@
21346 .byte 0xe9 /* 32bit jump */
21347 .long \orig-1f /* by default jump to orig */
21348 1:
21349 - .section .altinstr_replacement,"ax"
21350 + .section .altinstr_replacement,"a"
21351 2: .byte 0xe9 /* near jump with 32bit immediate */
21352 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21353 3: .byte 0xe9 /* near jump with 32bit immediate */
21354 @@ -69,47 +70,20 @@
21355 #endif
21356 .endm
21357
21358 -/* Standard copy_to_user with segment limit checking */
21359 -ENTRY(_copy_to_user)
21360 - CFI_STARTPROC
21361 - GET_THREAD_INFO(%rax)
21362 - movq %rdi,%rcx
21363 - addq %rdx,%rcx
21364 - jc bad_to_user
21365 - cmpq TI_addr_limit(%rax),%rcx
21366 - ja bad_to_user
21367 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21368 - copy_user_generic_unrolled,copy_user_generic_string, \
21369 - copy_user_enhanced_fast_string
21370 - CFI_ENDPROC
21371 -ENDPROC(_copy_to_user)
21372 -
21373 -/* Standard copy_from_user with segment limit checking */
21374 -ENTRY(_copy_from_user)
21375 - CFI_STARTPROC
21376 - GET_THREAD_INFO(%rax)
21377 - movq %rsi,%rcx
21378 - addq %rdx,%rcx
21379 - jc bad_from_user
21380 - cmpq TI_addr_limit(%rax),%rcx
21381 - ja bad_from_user
21382 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21383 - copy_user_generic_unrolled,copy_user_generic_string, \
21384 - copy_user_enhanced_fast_string
21385 - CFI_ENDPROC
21386 -ENDPROC(_copy_from_user)
21387 -
21388 .section .fixup,"ax"
21389 /* must zero dest */
21390 ENTRY(bad_from_user)
21391 bad_from_user:
21392 CFI_STARTPROC
21393 + testl %edx,%edx
21394 + js bad_to_user
21395 movl %edx,%ecx
21396 xorl %eax,%eax
21397 rep
21398 stosb
21399 bad_to_user:
21400 movl %edx,%eax
21401 + pax_force_retaddr
21402 ret
21403 CFI_ENDPROC
21404 ENDPROC(bad_from_user)
21405 @@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21406 jz 17f
21407 1: movq (%rsi),%r8
21408 2: movq 1*8(%rsi),%r9
21409 -3: movq 2*8(%rsi),%r10
21410 +3: movq 2*8(%rsi),%rax
21411 4: movq 3*8(%rsi),%r11
21412 5: movq %r8,(%rdi)
21413 6: movq %r9,1*8(%rdi)
21414 -7: movq %r10,2*8(%rdi)
21415 +7: movq %rax,2*8(%rdi)
21416 8: movq %r11,3*8(%rdi)
21417 9: movq 4*8(%rsi),%r8
21418 10: movq 5*8(%rsi),%r9
21419 -11: movq 6*8(%rsi),%r10
21420 +11: movq 6*8(%rsi),%rax
21421 12: movq 7*8(%rsi),%r11
21422 13: movq %r8,4*8(%rdi)
21423 14: movq %r9,5*8(%rdi)
21424 -15: movq %r10,6*8(%rdi)
21425 +15: movq %rax,6*8(%rdi)
21426 16: movq %r11,7*8(%rdi)
21427 leaq 64(%rsi),%rsi
21428 leaq 64(%rdi),%rdi
21429 @@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21430 decl %ecx
21431 jnz 21b
21432 23: xor %eax,%eax
21433 + pax_force_retaddr
21434 ret
21435
21436 .section .fixup,"ax"
21437 @@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21438 3: rep
21439 movsb
21440 4: xorl %eax,%eax
21441 + pax_force_retaddr
21442 ret
21443
21444 .section .fixup,"ax"
21445 @@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21446 1: rep
21447 movsb
21448 2: xorl %eax,%eax
21449 + pax_force_retaddr
21450 ret
21451
21452 .section .fixup,"ax"
21453 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21454 index cacddc7..09d49e4 100644
21455 --- a/arch/x86/lib/copy_user_nocache_64.S
21456 +++ b/arch/x86/lib/copy_user_nocache_64.S
21457 @@ -8,6 +8,7 @@
21458
21459 #include <linux/linkage.h>
21460 #include <asm/dwarf2.h>
21461 +#include <asm/alternative-asm.h>
21462
21463 #define FIX_ALIGNMENT 1
21464
21465 @@ -15,6 +16,7 @@
21466 #include <asm/asm-offsets.h>
21467 #include <asm/thread_info.h>
21468 #include <asm/asm.h>
21469 +#include <asm/pgtable.h>
21470
21471 .macro ALIGN_DESTINATION
21472 #ifdef FIX_ALIGNMENT
21473 @@ -48,6 +50,15 @@
21474 */
21475 ENTRY(__copy_user_nocache)
21476 CFI_STARTPROC
21477 +
21478 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21479 + mov $PAX_USER_SHADOW_BASE,%rcx
21480 + cmp %rcx,%rsi
21481 + jae 1f
21482 + add %rcx,%rsi
21483 +1:
21484 +#endif
21485 +
21486 cmpl $8,%edx
21487 jb 20f /* less then 8 bytes, go to byte copy loop */
21488 ALIGN_DESTINATION
21489 @@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21490 jz 17f
21491 1: movq (%rsi),%r8
21492 2: movq 1*8(%rsi),%r9
21493 -3: movq 2*8(%rsi),%r10
21494 +3: movq 2*8(%rsi),%rax
21495 4: movq 3*8(%rsi),%r11
21496 5: movnti %r8,(%rdi)
21497 6: movnti %r9,1*8(%rdi)
21498 -7: movnti %r10,2*8(%rdi)
21499 +7: movnti %rax,2*8(%rdi)
21500 8: movnti %r11,3*8(%rdi)
21501 9: movq 4*8(%rsi),%r8
21502 10: movq 5*8(%rsi),%r9
21503 -11: movq 6*8(%rsi),%r10
21504 +11: movq 6*8(%rsi),%rax
21505 12: movq 7*8(%rsi),%r11
21506 13: movnti %r8,4*8(%rdi)
21507 14: movnti %r9,5*8(%rdi)
21508 -15: movnti %r10,6*8(%rdi)
21509 +15: movnti %rax,6*8(%rdi)
21510 16: movnti %r11,7*8(%rdi)
21511 leaq 64(%rsi),%rsi
21512 leaq 64(%rdi),%rdi
21513 @@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21514 jnz 21b
21515 23: xorl %eax,%eax
21516 sfence
21517 + pax_force_retaddr
21518 ret
21519
21520 .section .fixup,"ax"
21521 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21522 index 2419d5f..953ee51 100644
21523 --- a/arch/x86/lib/csum-copy_64.S
21524 +++ b/arch/x86/lib/csum-copy_64.S
21525 @@ -9,6 +9,7 @@
21526 #include <asm/dwarf2.h>
21527 #include <asm/errno.h>
21528 #include <asm/asm.h>
21529 +#include <asm/alternative-asm.h>
21530
21531 /*
21532 * Checksum copy with exception handling.
21533 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21534 CFI_RESTORE rbp
21535 addq $7*8, %rsp
21536 CFI_ADJUST_CFA_OFFSET -7*8
21537 + pax_force_retaddr 0, 1
21538 ret
21539 CFI_RESTORE_STATE
21540
21541 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21542 index 25b7ae8..3b52ccd 100644
21543 --- a/arch/x86/lib/csum-wrappers_64.c
21544 +++ b/arch/x86/lib/csum-wrappers_64.c
21545 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21546 len -= 2;
21547 }
21548 }
21549 - isum = csum_partial_copy_generic((__force const void *)src,
21550 +
21551 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21552 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21553 + src += PAX_USER_SHADOW_BASE;
21554 +#endif
21555 +
21556 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21557 dst, len, isum, errp, NULL);
21558 if (unlikely(*errp))
21559 goto out_err;
21560 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21561 }
21562
21563 *errp = 0;
21564 - return csum_partial_copy_generic(src, (void __force *)dst,
21565 +
21566 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21567 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21568 + dst += PAX_USER_SHADOW_BASE;
21569 +#endif
21570 +
21571 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21572 len, isum, NULL, errp);
21573 }
21574 EXPORT_SYMBOL(csum_partial_copy_to_user);
21575 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21576 index b33b1fb..219f389 100644
21577 --- a/arch/x86/lib/getuser.S
21578 +++ b/arch/x86/lib/getuser.S
21579 @@ -33,15 +33,38 @@
21580 #include <asm/asm-offsets.h>
21581 #include <asm/thread_info.h>
21582 #include <asm/asm.h>
21583 +#include <asm/segment.h>
21584 +#include <asm/pgtable.h>
21585 +#include <asm/alternative-asm.h>
21586 +
21587 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21588 +#define __copyuser_seg gs;
21589 +#else
21590 +#define __copyuser_seg
21591 +#endif
21592
21593 .text
21594 ENTRY(__get_user_1)
21595 CFI_STARTPROC
21596 +
21597 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21598 GET_THREAD_INFO(%_ASM_DX)
21599 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21600 jae bad_get_user
21601 -1: movzb (%_ASM_AX),%edx
21602 +
21603 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21604 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21605 + cmp %_ASM_DX,%_ASM_AX
21606 + jae 1234f
21607 + add %_ASM_DX,%_ASM_AX
21608 +1234:
21609 +#endif
21610 +
21611 +#endif
21612 +
21613 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21614 xor %eax,%eax
21615 + pax_force_retaddr
21616 ret
21617 CFI_ENDPROC
21618 ENDPROC(__get_user_1)
21619 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21620 ENTRY(__get_user_2)
21621 CFI_STARTPROC
21622 add $1,%_ASM_AX
21623 +
21624 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21625 jc bad_get_user
21626 GET_THREAD_INFO(%_ASM_DX)
21627 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21628 jae bad_get_user
21629 -2: movzwl -1(%_ASM_AX),%edx
21630 +
21631 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21632 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21633 + cmp %_ASM_DX,%_ASM_AX
21634 + jae 1234f
21635 + add %_ASM_DX,%_ASM_AX
21636 +1234:
21637 +#endif
21638 +
21639 +#endif
21640 +
21641 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21642 xor %eax,%eax
21643 + pax_force_retaddr
21644 ret
21645 CFI_ENDPROC
21646 ENDPROC(__get_user_2)
21647 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21648 ENTRY(__get_user_4)
21649 CFI_STARTPROC
21650 add $3,%_ASM_AX
21651 +
21652 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21653 jc bad_get_user
21654 GET_THREAD_INFO(%_ASM_DX)
21655 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21656 jae bad_get_user
21657 -3: mov -3(%_ASM_AX),%edx
21658 +
21659 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21660 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21661 + cmp %_ASM_DX,%_ASM_AX
21662 + jae 1234f
21663 + add %_ASM_DX,%_ASM_AX
21664 +1234:
21665 +#endif
21666 +
21667 +#endif
21668 +
21669 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21670 xor %eax,%eax
21671 + pax_force_retaddr
21672 ret
21673 CFI_ENDPROC
21674 ENDPROC(__get_user_4)
21675 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21676 GET_THREAD_INFO(%_ASM_DX)
21677 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21678 jae bad_get_user
21679 +
21680 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21681 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21682 + cmp %_ASM_DX,%_ASM_AX
21683 + jae 1234f
21684 + add %_ASM_DX,%_ASM_AX
21685 +1234:
21686 +#endif
21687 +
21688 4: movq -7(%_ASM_AX),%_ASM_DX
21689 xor %eax,%eax
21690 + pax_force_retaddr
21691 ret
21692 CFI_ENDPROC
21693 ENDPROC(__get_user_8)
21694 @@ -91,6 +152,7 @@ bad_get_user:
21695 CFI_STARTPROC
21696 xor %edx,%edx
21697 mov $(-EFAULT),%_ASM_AX
21698 + pax_force_retaddr
21699 ret
21700 CFI_ENDPROC
21701 END(bad_get_user)
21702 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21703 index b1e6c4b..21ae8fc 100644
21704 --- a/arch/x86/lib/insn.c
21705 +++ b/arch/x86/lib/insn.c
21706 @@ -21,6 +21,11 @@
21707 #include <linux/string.h>
21708 #include <asm/inat.h>
21709 #include <asm/insn.h>
21710 +#ifdef __KERNEL__
21711 +#include <asm/pgtable_types.h>
21712 +#else
21713 +#define ktla_ktva(addr) addr
21714 +#endif
21715
21716 /* Verify next sizeof(t) bytes can be on the same instruction */
21717 #define validate_next(t, insn, n) \
21718 @@ -49,8 +54,8 @@
21719 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21720 {
21721 memset(insn, 0, sizeof(*insn));
21722 - insn->kaddr = kaddr;
21723 - insn->next_byte = kaddr;
21724 + insn->kaddr = ktla_ktva(kaddr);
21725 + insn->next_byte = ktla_ktva(kaddr);
21726 insn->x86_64 = x86_64 ? 1 : 0;
21727 insn->opnd_bytes = 4;
21728 if (x86_64)
21729 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21730 index 05a95e7..326f2fa 100644
21731 --- a/arch/x86/lib/iomap_copy_64.S
21732 +++ b/arch/x86/lib/iomap_copy_64.S
21733 @@ -17,6 +17,7 @@
21734
21735 #include <linux/linkage.h>
21736 #include <asm/dwarf2.h>
21737 +#include <asm/alternative-asm.h>
21738
21739 /*
21740 * override generic version in lib/iomap_copy.c
21741 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21742 CFI_STARTPROC
21743 movl %edx,%ecx
21744 rep movsd
21745 + pax_force_retaddr
21746 ret
21747 CFI_ENDPROC
21748 ENDPROC(__iowrite32_copy)
21749 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21750 index 1c273be..da9cc0e 100644
21751 --- a/arch/x86/lib/memcpy_64.S
21752 +++ b/arch/x86/lib/memcpy_64.S
21753 @@ -33,6 +33,7 @@
21754 rep movsq
21755 movl %edx, %ecx
21756 rep movsb
21757 + pax_force_retaddr
21758 ret
21759 .Lmemcpy_e:
21760 .previous
21761 @@ -49,6 +50,7 @@
21762 movq %rdi, %rax
21763 movq %rdx, %rcx
21764 rep movsb
21765 + pax_force_retaddr
21766 ret
21767 .Lmemcpy_e_e:
21768 .previous
21769 @@ -76,13 +78,13 @@ ENTRY(memcpy)
21770 */
21771 movq 0*8(%rsi), %r8
21772 movq 1*8(%rsi), %r9
21773 - movq 2*8(%rsi), %r10
21774 + movq 2*8(%rsi), %rcx
21775 movq 3*8(%rsi), %r11
21776 leaq 4*8(%rsi), %rsi
21777
21778 movq %r8, 0*8(%rdi)
21779 movq %r9, 1*8(%rdi)
21780 - movq %r10, 2*8(%rdi)
21781 + movq %rcx, 2*8(%rdi)
21782 movq %r11, 3*8(%rdi)
21783 leaq 4*8(%rdi), %rdi
21784 jae .Lcopy_forward_loop
21785 @@ -105,12 +107,12 @@ ENTRY(memcpy)
21786 subq $0x20, %rdx
21787 movq -1*8(%rsi), %r8
21788 movq -2*8(%rsi), %r9
21789 - movq -3*8(%rsi), %r10
21790 + movq -3*8(%rsi), %rcx
21791 movq -4*8(%rsi), %r11
21792 leaq -4*8(%rsi), %rsi
21793 movq %r8, -1*8(%rdi)
21794 movq %r9, -2*8(%rdi)
21795 - movq %r10, -3*8(%rdi)
21796 + movq %rcx, -3*8(%rdi)
21797 movq %r11, -4*8(%rdi)
21798 leaq -4*8(%rdi), %rdi
21799 jae .Lcopy_backward_loop
21800 @@ -130,12 +132,13 @@ ENTRY(memcpy)
21801 */
21802 movq 0*8(%rsi), %r8
21803 movq 1*8(%rsi), %r9
21804 - movq -2*8(%rsi, %rdx), %r10
21805 + movq -2*8(%rsi, %rdx), %rcx
21806 movq -1*8(%rsi, %rdx), %r11
21807 movq %r8, 0*8(%rdi)
21808 movq %r9, 1*8(%rdi)
21809 - movq %r10, -2*8(%rdi, %rdx)
21810 + movq %rcx, -2*8(%rdi, %rdx)
21811 movq %r11, -1*8(%rdi, %rdx)
21812 + pax_force_retaddr
21813 retq
21814 .p2align 4
21815 .Lless_16bytes:
21816 @@ -148,6 +151,7 @@ ENTRY(memcpy)
21817 movq -1*8(%rsi, %rdx), %r9
21818 movq %r8, 0*8(%rdi)
21819 movq %r9, -1*8(%rdi, %rdx)
21820 + pax_force_retaddr
21821 retq
21822 .p2align 4
21823 .Lless_8bytes:
21824 @@ -161,6 +165,7 @@ ENTRY(memcpy)
21825 movl -4(%rsi, %rdx), %r8d
21826 movl %ecx, (%rdi)
21827 movl %r8d, -4(%rdi, %rdx)
21828 + pax_force_retaddr
21829 retq
21830 .p2align 4
21831 .Lless_3bytes:
21832 @@ -179,6 +184,7 @@ ENTRY(memcpy)
21833 movb %cl, (%rdi)
21834
21835 .Lend:
21836 + pax_force_retaddr
21837 retq
21838 CFI_ENDPROC
21839 ENDPROC(memcpy)
21840 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
21841 index ee16461..c39c199 100644
21842 --- a/arch/x86/lib/memmove_64.S
21843 +++ b/arch/x86/lib/memmove_64.S
21844 @@ -61,13 +61,13 @@ ENTRY(memmove)
21845 5:
21846 sub $0x20, %rdx
21847 movq 0*8(%rsi), %r11
21848 - movq 1*8(%rsi), %r10
21849 + movq 1*8(%rsi), %rcx
21850 movq 2*8(%rsi), %r9
21851 movq 3*8(%rsi), %r8
21852 leaq 4*8(%rsi), %rsi
21853
21854 movq %r11, 0*8(%rdi)
21855 - movq %r10, 1*8(%rdi)
21856 + movq %rcx, 1*8(%rdi)
21857 movq %r9, 2*8(%rdi)
21858 movq %r8, 3*8(%rdi)
21859 leaq 4*8(%rdi), %rdi
21860 @@ -81,10 +81,10 @@ ENTRY(memmove)
21861 4:
21862 movq %rdx, %rcx
21863 movq -8(%rsi, %rdx), %r11
21864 - lea -8(%rdi, %rdx), %r10
21865 + lea -8(%rdi, %rdx), %r9
21866 shrq $3, %rcx
21867 rep movsq
21868 - movq %r11, (%r10)
21869 + movq %r11, (%r9)
21870 jmp 13f
21871 .Lmemmove_end_forward:
21872
21873 @@ -95,14 +95,14 @@ ENTRY(memmove)
21874 7:
21875 movq %rdx, %rcx
21876 movq (%rsi), %r11
21877 - movq %rdi, %r10
21878 + movq %rdi, %r9
21879 leaq -8(%rsi, %rdx), %rsi
21880 leaq -8(%rdi, %rdx), %rdi
21881 shrq $3, %rcx
21882 std
21883 rep movsq
21884 cld
21885 - movq %r11, (%r10)
21886 + movq %r11, (%r9)
21887 jmp 13f
21888
21889 /*
21890 @@ -127,13 +127,13 @@ ENTRY(memmove)
21891 8:
21892 subq $0x20, %rdx
21893 movq -1*8(%rsi), %r11
21894 - movq -2*8(%rsi), %r10
21895 + movq -2*8(%rsi), %rcx
21896 movq -3*8(%rsi), %r9
21897 movq -4*8(%rsi), %r8
21898 leaq -4*8(%rsi), %rsi
21899
21900 movq %r11, -1*8(%rdi)
21901 - movq %r10, -2*8(%rdi)
21902 + movq %rcx, -2*8(%rdi)
21903 movq %r9, -3*8(%rdi)
21904 movq %r8, -4*8(%rdi)
21905 leaq -4*8(%rdi), %rdi
21906 @@ -151,11 +151,11 @@ ENTRY(memmove)
21907 * Move data from 16 bytes to 31 bytes.
21908 */
21909 movq 0*8(%rsi), %r11
21910 - movq 1*8(%rsi), %r10
21911 + movq 1*8(%rsi), %rcx
21912 movq -2*8(%rsi, %rdx), %r9
21913 movq -1*8(%rsi, %rdx), %r8
21914 movq %r11, 0*8(%rdi)
21915 - movq %r10, 1*8(%rdi)
21916 + movq %rcx, 1*8(%rdi)
21917 movq %r9, -2*8(%rdi, %rdx)
21918 movq %r8, -1*8(%rdi, %rdx)
21919 jmp 13f
21920 @@ -167,9 +167,9 @@ ENTRY(memmove)
21921 * Move data from 8 bytes to 15 bytes.
21922 */
21923 movq 0*8(%rsi), %r11
21924 - movq -1*8(%rsi, %rdx), %r10
21925 + movq -1*8(%rsi, %rdx), %r9
21926 movq %r11, 0*8(%rdi)
21927 - movq %r10, -1*8(%rdi, %rdx)
21928 + movq %r9, -1*8(%rdi, %rdx)
21929 jmp 13f
21930 10:
21931 cmpq $4, %rdx
21932 @@ -178,9 +178,9 @@ ENTRY(memmove)
21933 * Move data from 4 bytes to 7 bytes.
21934 */
21935 movl (%rsi), %r11d
21936 - movl -4(%rsi, %rdx), %r10d
21937 + movl -4(%rsi, %rdx), %r9d
21938 movl %r11d, (%rdi)
21939 - movl %r10d, -4(%rdi, %rdx)
21940 + movl %r9d, -4(%rdi, %rdx)
21941 jmp 13f
21942 11:
21943 cmp $2, %rdx
21944 @@ -189,9 +189,9 @@ ENTRY(memmove)
21945 * Move data from 2 bytes to 3 bytes.
21946 */
21947 movw (%rsi), %r11w
21948 - movw -2(%rsi, %rdx), %r10w
21949 + movw -2(%rsi, %rdx), %r9w
21950 movw %r11w, (%rdi)
21951 - movw %r10w, -2(%rdi, %rdx)
21952 + movw %r9w, -2(%rdi, %rdx)
21953 jmp 13f
21954 12:
21955 cmp $1, %rdx
21956 @@ -202,6 +202,7 @@ ENTRY(memmove)
21957 movb (%rsi), %r11b
21958 movb %r11b, (%rdi)
21959 13:
21960 + pax_force_retaddr
21961 retq
21962 CFI_ENDPROC
21963
21964 @@ -210,6 +211,7 @@ ENTRY(memmove)
21965 /* Forward moving data. */
21966 movq %rdx, %rcx
21967 rep movsb
21968 + pax_force_retaddr
21969 retq
21970 .Lmemmove_end_forward_efs:
21971 .previous
21972 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
21973 index 2dcb380..963660a 100644
21974 --- a/arch/x86/lib/memset_64.S
21975 +++ b/arch/x86/lib/memset_64.S
21976 @@ -30,6 +30,7 @@
21977 movl %edx,%ecx
21978 rep stosb
21979 movq %r9,%rax
21980 + pax_force_retaddr
21981 ret
21982 .Lmemset_e:
21983 .previous
21984 @@ -52,6 +53,7 @@
21985 movq %rdx,%rcx
21986 rep stosb
21987 movq %r9,%rax
21988 + pax_force_retaddr
21989 ret
21990 .Lmemset_e_e:
21991 .previous
21992 @@ -59,7 +61,7 @@
21993 ENTRY(memset)
21994 ENTRY(__memset)
21995 CFI_STARTPROC
21996 - movq %rdi,%r10
21997 + movq %rdi,%r11
21998
21999 /* expand byte value */
22000 movzbl %sil,%ecx
22001 @@ -117,7 +119,8 @@ ENTRY(__memset)
22002 jnz .Lloop_1
22003
22004 .Lende:
22005 - movq %r10,%rax
22006 + movq %r11,%rax
22007 + pax_force_retaddr
22008 ret
22009
22010 CFI_RESTORE_STATE
22011 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22012 index c9f2d9b..e7fd2c0 100644
22013 --- a/arch/x86/lib/mmx_32.c
22014 +++ b/arch/x86/lib/mmx_32.c
22015 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22016 {
22017 void *p;
22018 int i;
22019 + unsigned long cr0;
22020
22021 if (unlikely(in_interrupt()))
22022 return __memcpy(to, from, len);
22023 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22024 kernel_fpu_begin();
22025
22026 __asm__ __volatile__ (
22027 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22028 - " prefetch 64(%0)\n"
22029 - " prefetch 128(%0)\n"
22030 - " prefetch 192(%0)\n"
22031 - " prefetch 256(%0)\n"
22032 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22033 + " prefetch 64(%1)\n"
22034 + " prefetch 128(%1)\n"
22035 + " prefetch 192(%1)\n"
22036 + " prefetch 256(%1)\n"
22037 "2: \n"
22038 ".section .fixup, \"ax\"\n"
22039 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22040 + "3: \n"
22041 +
22042 +#ifdef CONFIG_PAX_KERNEXEC
22043 + " movl %%cr0, %0\n"
22044 + " movl %0, %%eax\n"
22045 + " andl $0xFFFEFFFF, %%eax\n"
22046 + " movl %%eax, %%cr0\n"
22047 +#endif
22048 +
22049 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22050 +
22051 +#ifdef CONFIG_PAX_KERNEXEC
22052 + " movl %0, %%cr0\n"
22053 +#endif
22054 +
22055 " jmp 2b\n"
22056 ".previous\n"
22057 _ASM_EXTABLE(1b, 3b)
22058 - : : "r" (from));
22059 + : "=&r" (cr0) : "r" (from) : "ax");
22060
22061 for ( ; i > 5; i--) {
22062 __asm__ __volatile__ (
22063 - "1: prefetch 320(%0)\n"
22064 - "2: movq (%0), %%mm0\n"
22065 - " movq 8(%0), %%mm1\n"
22066 - " movq 16(%0), %%mm2\n"
22067 - " movq 24(%0), %%mm3\n"
22068 - " movq %%mm0, (%1)\n"
22069 - " movq %%mm1, 8(%1)\n"
22070 - " movq %%mm2, 16(%1)\n"
22071 - " movq %%mm3, 24(%1)\n"
22072 - " movq 32(%0), %%mm0\n"
22073 - " movq 40(%0), %%mm1\n"
22074 - " movq 48(%0), %%mm2\n"
22075 - " movq 56(%0), %%mm3\n"
22076 - " movq %%mm0, 32(%1)\n"
22077 - " movq %%mm1, 40(%1)\n"
22078 - " movq %%mm2, 48(%1)\n"
22079 - " movq %%mm3, 56(%1)\n"
22080 + "1: prefetch 320(%1)\n"
22081 + "2: movq (%1), %%mm0\n"
22082 + " movq 8(%1), %%mm1\n"
22083 + " movq 16(%1), %%mm2\n"
22084 + " movq 24(%1), %%mm3\n"
22085 + " movq %%mm0, (%2)\n"
22086 + " movq %%mm1, 8(%2)\n"
22087 + " movq %%mm2, 16(%2)\n"
22088 + " movq %%mm3, 24(%2)\n"
22089 + " movq 32(%1), %%mm0\n"
22090 + " movq 40(%1), %%mm1\n"
22091 + " movq 48(%1), %%mm2\n"
22092 + " movq 56(%1), %%mm3\n"
22093 + " movq %%mm0, 32(%2)\n"
22094 + " movq %%mm1, 40(%2)\n"
22095 + " movq %%mm2, 48(%2)\n"
22096 + " movq %%mm3, 56(%2)\n"
22097 ".section .fixup, \"ax\"\n"
22098 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22099 + "3:\n"
22100 +
22101 +#ifdef CONFIG_PAX_KERNEXEC
22102 + " movl %%cr0, %0\n"
22103 + " movl %0, %%eax\n"
22104 + " andl $0xFFFEFFFF, %%eax\n"
22105 + " movl %%eax, %%cr0\n"
22106 +#endif
22107 +
22108 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22109 +
22110 +#ifdef CONFIG_PAX_KERNEXEC
22111 + " movl %0, %%cr0\n"
22112 +#endif
22113 +
22114 " jmp 2b\n"
22115 ".previous\n"
22116 _ASM_EXTABLE(1b, 3b)
22117 - : : "r" (from), "r" (to) : "memory");
22118 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22119
22120 from += 64;
22121 to += 64;
22122 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22123 static void fast_copy_page(void *to, void *from)
22124 {
22125 int i;
22126 + unsigned long cr0;
22127
22128 kernel_fpu_begin();
22129
22130 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22131 * but that is for later. -AV
22132 */
22133 __asm__ __volatile__(
22134 - "1: prefetch (%0)\n"
22135 - " prefetch 64(%0)\n"
22136 - " prefetch 128(%0)\n"
22137 - " prefetch 192(%0)\n"
22138 - " prefetch 256(%0)\n"
22139 + "1: prefetch (%1)\n"
22140 + " prefetch 64(%1)\n"
22141 + " prefetch 128(%1)\n"
22142 + " prefetch 192(%1)\n"
22143 + " prefetch 256(%1)\n"
22144 "2: \n"
22145 ".section .fixup, \"ax\"\n"
22146 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22147 + "3: \n"
22148 +
22149 +#ifdef CONFIG_PAX_KERNEXEC
22150 + " movl %%cr0, %0\n"
22151 + " movl %0, %%eax\n"
22152 + " andl $0xFFFEFFFF, %%eax\n"
22153 + " movl %%eax, %%cr0\n"
22154 +#endif
22155 +
22156 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22157 +
22158 +#ifdef CONFIG_PAX_KERNEXEC
22159 + " movl %0, %%cr0\n"
22160 +#endif
22161 +
22162 " jmp 2b\n"
22163 ".previous\n"
22164 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22165 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22166
22167 for (i = 0; i < (4096-320)/64; i++) {
22168 __asm__ __volatile__ (
22169 - "1: prefetch 320(%0)\n"
22170 - "2: movq (%0), %%mm0\n"
22171 - " movntq %%mm0, (%1)\n"
22172 - " movq 8(%0), %%mm1\n"
22173 - " movntq %%mm1, 8(%1)\n"
22174 - " movq 16(%0), %%mm2\n"
22175 - " movntq %%mm2, 16(%1)\n"
22176 - " movq 24(%0), %%mm3\n"
22177 - " movntq %%mm3, 24(%1)\n"
22178 - " movq 32(%0), %%mm4\n"
22179 - " movntq %%mm4, 32(%1)\n"
22180 - " movq 40(%0), %%mm5\n"
22181 - " movntq %%mm5, 40(%1)\n"
22182 - " movq 48(%0), %%mm6\n"
22183 - " movntq %%mm6, 48(%1)\n"
22184 - " movq 56(%0), %%mm7\n"
22185 - " movntq %%mm7, 56(%1)\n"
22186 + "1: prefetch 320(%1)\n"
22187 + "2: movq (%1), %%mm0\n"
22188 + " movntq %%mm0, (%2)\n"
22189 + " movq 8(%1), %%mm1\n"
22190 + " movntq %%mm1, 8(%2)\n"
22191 + " movq 16(%1), %%mm2\n"
22192 + " movntq %%mm2, 16(%2)\n"
22193 + " movq 24(%1), %%mm3\n"
22194 + " movntq %%mm3, 24(%2)\n"
22195 + " movq 32(%1), %%mm4\n"
22196 + " movntq %%mm4, 32(%2)\n"
22197 + " movq 40(%1), %%mm5\n"
22198 + " movntq %%mm5, 40(%2)\n"
22199 + " movq 48(%1), %%mm6\n"
22200 + " movntq %%mm6, 48(%2)\n"
22201 + " movq 56(%1), %%mm7\n"
22202 + " movntq %%mm7, 56(%2)\n"
22203 ".section .fixup, \"ax\"\n"
22204 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22205 + "3:\n"
22206 +
22207 +#ifdef CONFIG_PAX_KERNEXEC
22208 + " movl %%cr0, %0\n"
22209 + " movl %0, %%eax\n"
22210 + " andl $0xFFFEFFFF, %%eax\n"
22211 + " movl %%eax, %%cr0\n"
22212 +#endif
22213 +
22214 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22215 +
22216 +#ifdef CONFIG_PAX_KERNEXEC
22217 + " movl %0, %%cr0\n"
22218 +#endif
22219 +
22220 " jmp 2b\n"
22221 ".previous\n"
22222 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22223 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22224
22225 from += 64;
22226 to += 64;
22227 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22228 static void fast_copy_page(void *to, void *from)
22229 {
22230 int i;
22231 + unsigned long cr0;
22232
22233 kernel_fpu_begin();
22234
22235 __asm__ __volatile__ (
22236 - "1: prefetch (%0)\n"
22237 - " prefetch 64(%0)\n"
22238 - " prefetch 128(%0)\n"
22239 - " prefetch 192(%0)\n"
22240 - " prefetch 256(%0)\n"
22241 + "1: prefetch (%1)\n"
22242 + " prefetch 64(%1)\n"
22243 + " prefetch 128(%1)\n"
22244 + " prefetch 192(%1)\n"
22245 + " prefetch 256(%1)\n"
22246 "2: \n"
22247 ".section .fixup, \"ax\"\n"
22248 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22249 + "3: \n"
22250 +
22251 +#ifdef CONFIG_PAX_KERNEXEC
22252 + " movl %%cr0, %0\n"
22253 + " movl %0, %%eax\n"
22254 + " andl $0xFFFEFFFF, %%eax\n"
22255 + " movl %%eax, %%cr0\n"
22256 +#endif
22257 +
22258 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22259 +
22260 +#ifdef CONFIG_PAX_KERNEXEC
22261 + " movl %0, %%cr0\n"
22262 +#endif
22263 +
22264 " jmp 2b\n"
22265 ".previous\n"
22266 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22267 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22268
22269 for (i = 0; i < 4096/64; i++) {
22270 __asm__ __volatile__ (
22271 - "1: prefetch 320(%0)\n"
22272 - "2: movq (%0), %%mm0\n"
22273 - " movq 8(%0), %%mm1\n"
22274 - " movq 16(%0), %%mm2\n"
22275 - " movq 24(%0), %%mm3\n"
22276 - " movq %%mm0, (%1)\n"
22277 - " movq %%mm1, 8(%1)\n"
22278 - " movq %%mm2, 16(%1)\n"
22279 - " movq %%mm3, 24(%1)\n"
22280 - " movq 32(%0), %%mm0\n"
22281 - " movq 40(%0), %%mm1\n"
22282 - " movq 48(%0), %%mm2\n"
22283 - " movq 56(%0), %%mm3\n"
22284 - " movq %%mm0, 32(%1)\n"
22285 - " movq %%mm1, 40(%1)\n"
22286 - " movq %%mm2, 48(%1)\n"
22287 - " movq %%mm3, 56(%1)\n"
22288 + "1: prefetch 320(%1)\n"
22289 + "2: movq (%1), %%mm0\n"
22290 + " movq 8(%1), %%mm1\n"
22291 + " movq 16(%1), %%mm2\n"
22292 + " movq 24(%1), %%mm3\n"
22293 + " movq %%mm0, (%2)\n"
22294 + " movq %%mm1, 8(%2)\n"
22295 + " movq %%mm2, 16(%2)\n"
22296 + " movq %%mm3, 24(%2)\n"
22297 + " movq 32(%1), %%mm0\n"
22298 + " movq 40(%1), %%mm1\n"
22299 + " movq 48(%1), %%mm2\n"
22300 + " movq 56(%1), %%mm3\n"
22301 + " movq %%mm0, 32(%2)\n"
22302 + " movq %%mm1, 40(%2)\n"
22303 + " movq %%mm2, 48(%2)\n"
22304 + " movq %%mm3, 56(%2)\n"
22305 ".section .fixup, \"ax\"\n"
22306 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22307 + "3:\n"
22308 +
22309 +#ifdef CONFIG_PAX_KERNEXEC
22310 + " movl %%cr0, %0\n"
22311 + " movl %0, %%eax\n"
22312 + " andl $0xFFFEFFFF, %%eax\n"
22313 + " movl %%eax, %%cr0\n"
22314 +#endif
22315 +
22316 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22317 +
22318 +#ifdef CONFIG_PAX_KERNEXEC
22319 + " movl %0, %%cr0\n"
22320 +#endif
22321 +
22322 " jmp 2b\n"
22323 ".previous\n"
22324 _ASM_EXTABLE(1b, 3b)
22325 - : : "r" (from), "r" (to) : "memory");
22326 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22327
22328 from += 64;
22329 to += 64;
22330 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22331 index 69fa106..adda88b 100644
22332 --- a/arch/x86/lib/msr-reg.S
22333 +++ b/arch/x86/lib/msr-reg.S
22334 @@ -3,6 +3,7 @@
22335 #include <asm/dwarf2.h>
22336 #include <asm/asm.h>
22337 #include <asm/msr.h>
22338 +#include <asm/alternative-asm.h>
22339
22340 #ifdef CONFIG_X86_64
22341 /*
22342 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22343 CFI_STARTPROC
22344 pushq_cfi %rbx
22345 pushq_cfi %rbp
22346 - movq %rdi, %r10 /* Save pointer */
22347 + movq %rdi, %r9 /* Save pointer */
22348 xorl %r11d, %r11d /* Return value */
22349 movl (%rdi), %eax
22350 movl 4(%rdi), %ecx
22351 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22352 movl 28(%rdi), %edi
22353 CFI_REMEMBER_STATE
22354 1: \op
22355 -2: movl %eax, (%r10)
22356 +2: movl %eax, (%r9)
22357 movl %r11d, %eax /* Return value */
22358 - movl %ecx, 4(%r10)
22359 - movl %edx, 8(%r10)
22360 - movl %ebx, 12(%r10)
22361 - movl %ebp, 20(%r10)
22362 - movl %esi, 24(%r10)
22363 - movl %edi, 28(%r10)
22364 + movl %ecx, 4(%r9)
22365 + movl %edx, 8(%r9)
22366 + movl %ebx, 12(%r9)
22367 + movl %ebp, 20(%r9)
22368 + movl %esi, 24(%r9)
22369 + movl %edi, 28(%r9)
22370 popq_cfi %rbp
22371 popq_cfi %rbx
22372 + pax_force_retaddr
22373 ret
22374 3:
22375 CFI_RESTORE_STATE
22376 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22377 index 7f951c8..ebd573a 100644
22378 --- a/arch/x86/lib/putuser.S
22379 +++ b/arch/x86/lib/putuser.S
22380 @@ -15,7 +15,9 @@
22381 #include <asm/thread_info.h>
22382 #include <asm/errno.h>
22383 #include <asm/asm.h>
22384 -
22385 +#include <asm/segment.h>
22386 +#include <asm/pgtable.h>
22387 +#include <asm/alternative-asm.h>
22388
22389 /*
22390 * __put_user_X
22391 @@ -29,52 +31,119 @@
22392 * as they get called from within inline assembly.
22393 */
22394
22395 -#define ENTER CFI_STARTPROC ; \
22396 - GET_THREAD_INFO(%_ASM_BX)
22397 -#define EXIT ret ; \
22398 +#define ENTER CFI_STARTPROC
22399 +#define EXIT pax_force_retaddr; ret ; \
22400 CFI_ENDPROC
22401
22402 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22403 +#define _DEST %_ASM_CX,%_ASM_BX
22404 +#else
22405 +#define _DEST %_ASM_CX
22406 +#endif
22407 +
22408 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22409 +#define __copyuser_seg gs;
22410 +#else
22411 +#define __copyuser_seg
22412 +#endif
22413 +
22414 .text
22415 ENTRY(__put_user_1)
22416 ENTER
22417 +
22418 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22419 + GET_THREAD_INFO(%_ASM_BX)
22420 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22421 jae bad_put_user
22422 -1: movb %al,(%_ASM_CX)
22423 +
22424 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22425 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22426 + cmp %_ASM_BX,%_ASM_CX
22427 + jb 1234f
22428 + xor %ebx,%ebx
22429 +1234:
22430 +#endif
22431 +
22432 +#endif
22433 +
22434 +1: __copyuser_seg movb %al,(_DEST)
22435 xor %eax,%eax
22436 EXIT
22437 ENDPROC(__put_user_1)
22438
22439 ENTRY(__put_user_2)
22440 ENTER
22441 +
22442 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22443 + GET_THREAD_INFO(%_ASM_BX)
22444 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22445 sub $1,%_ASM_BX
22446 cmp %_ASM_BX,%_ASM_CX
22447 jae bad_put_user
22448 -2: movw %ax,(%_ASM_CX)
22449 +
22450 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22451 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22452 + cmp %_ASM_BX,%_ASM_CX
22453 + jb 1234f
22454 + xor %ebx,%ebx
22455 +1234:
22456 +#endif
22457 +
22458 +#endif
22459 +
22460 +2: __copyuser_seg movw %ax,(_DEST)
22461 xor %eax,%eax
22462 EXIT
22463 ENDPROC(__put_user_2)
22464
22465 ENTRY(__put_user_4)
22466 ENTER
22467 +
22468 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22469 + GET_THREAD_INFO(%_ASM_BX)
22470 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22471 sub $3,%_ASM_BX
22472 cmp %_ASM_BX,%_ASM_CX
22473 jae bad_put_user
22474 -3: movl %eax,(%_ASM_CX)
22475 +
22476 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22477 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22478 + cmp %_ASM_BX,%_ASM_CX
22479 + jb 1234f
22480 + xor %ebx,%ebx
22481 +1234:
22482 +#endif
22483 +
22484 +#endif
22485 +
22486 +3: __copyuser_seg movl %eax,(_DEST)
22487 xor %eax,%eax
22488 EXIT
22489 ENDPROC(__put_user_4)
22490
22491 ENTRY(__put_user_8)
22492 ENTER
22493 +
22494 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22495 + GET_THREAD_INFO(%_ASM_BX)
22496 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22497 sub $7,%_ASM_BX
22498 cmp %_ASM_BX,%_ASM_CX
22499 jae bad_put_user
22500 -4: mov %_ASM_AX,(%_ASM_CX)
22501 +
22502 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22503 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22504 + cmp %_ASM_BX,%_ASM_CX
22505 + jb 1234f
22506 + xor %ebx,%ebx
22507 +1234:
22508 +#endif
22509 +
22510 +#endif
22511 +
22512 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22513 #ifdef CONFIG_X86_32
22514 -5: movl %edx,4(%_ASM_CX)
22515 +5: __copyuser_seg movl %edx,4(_DEST)
22516 #endif
22517 xor %eax,%eax
22518 EXIT
22519 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22520 index 1cad221..de671ee 100644
22521 --- a/arch/x86/lib/rwlock.S
22522 +++ b/arch/x86/lib/rwlock.S
22523 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22524 FRAME
22525 0: LOCK_PREFIX
22526 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22527 +
22528 +#ifdef CONFIG_PAX_REFCOUNT
22529 + jno 1234f
22530 + LOCK_PREFIX
22531 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22532 + int $4
22533 +1234:
22534 + _ASM_EXTABLE(1234b, 1234b)
22535 +#endif
22536 +
22537 1: rep; nop
22538 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22539 jne 1b
22540 LOCK_PREFIX
22541 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22542 +
22543 +#ifdef CONFIG_PAX_REFCOUNT
22544 + jno 1234f
22545 + LOCK_PREFIX
22546 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22547 + int $4
22548 +1234:
22549 + _ASM_EXTABLE(1234b, 1234b)
22550 +#endif
22551 +
22552 jnz 0b
22553 ENDFRAME
22554 + pax_force_retaddr
22555 ret
22556 CFI_ENDPROC
22557 END(__write_lock_failed)
22558 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22559 FRAME
22560 0: LOCK_PREFIX
22561 READ_LOCK_SIZE(inc) (%__lock_ptr)
22562 +
22563 +#ifdef CONFIG_PAX_REFCOUNT
22564 + jno 1234f
22565 + LOCK_PREFIX
22566 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22567 + int $4
22568 +1234:
22569 + _ASM_EXTABLE(1234b, 1234b)
22570 +#endif
22571 +
22572 1: rep; nop
22573 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22574 js 1b
22575 LOCK_PREFIX
22576 READ_LOCK_SIZE(dec) (%__lock_ptr)
22577 +
22578 +#ifdef CONFIG_PAX_REFCOUNT
22579 + jno 1234f
22580 + LOCK_PREFIX
22581 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22582 + int $4
22583 +1234:
22584 + _ASM_EXTABLE(1234b, 1234b)
22585 +#endif
22586 +
22587 js 0b
22588 ENDFRAME
22589 + pax_force_retaddr
22590 ret
22591 CFI_ENDPROC
22592 END(__read_lock_failed)
22593 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22594 index 5dff5f0..cadebf4 100644
22595 --- a/arch/x86/lib/rwsem.S
22596 +++ b/arch/x86/lib/rwsem.S
22597 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22598 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22599 CFI_RESTORE __ASM_REG(dx)
22600 restore_common_regs
22601 + pax_force_retaddr
22602 ret
22603 CFI_ENDPROC
22604 ENDPROC(call_rwsem_down_read_failed)
22605 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22606 movq %rax,%rdi
22607 call rwsem_down_write_failed
22608 restore_common_regs
22609 + pax_force_retaddr
22610 ret
22611 CFI_ENDPROC
22612 ENDPROC(call_rwsem_down_write_failed)
22613 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22614 movq %rax,%rdi
22615 call rwsem_wake
22616 restore_common_regs
22617 -1: ret
22618 +1: pax_force_retaddr
22619 + ret
22620 CFI_ENDPROC
22621 ENDPROC(call_rwsem_wake)
22622
22623 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22624 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22625 CFI_RESTORE __ASM_REG(dx)
22626 restore_common_regs
22627 + pax_force_retaddr
22628 ret
22629 CFI_ENDPROC
22630 ENDPROC(call_rwsem_downgrade_wake)
22631 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22632 index a63efd6..ccecad8 100644
22633 --- a/arch/x86/lib/thunk_64.S
22634 +++ b/arch/x86/lib/thunk_64.S
22635 @@ -8,6 +8,7 @@
22636 #include <linux/linkage.h>
22637 #include <asm/dwarf2.h>
22638 #include <asm/calling.h>
22639 +#include <asm/alternative-asm.h>
22640
22641 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22642 .macro THUNK name, func, put_ret_addr_in_rdi=0
22643 @@ -41,5 +42,6 @@
22644 SAVE_ARGS
22645 restore:
22646 RESTORE_ARGS
22647 + pax_force_retaddr
22648 ret
22649 CFI_ENDPROC
22650 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22651 index 1781b2f..90368dd 100644
22652 --- a/arch/x86/lib/usercopy_32.c
22653 +++ b/arch/x86/lib/usercopy_32.c
22654 @@ -42,10 +42,12 @@ do { \
22655 int __d0; \
22656 might_fault(); \
22657 __asm__ __volatile__( \
22658 + __COPYUSER_SET_ES \
22659 "0: rep; stosl\n" \
22660 " movl %2,%0\n" \
22661 "1: rep; stosb\n" \
22662 "2:\n" \
22663 + __COPYUSER_RESTORE_ES \
22664 ".section .fixup,\"ax\"\n" \
22665 "3: lea 0(%2,%0,4),%0\n" \
22666 " jmp 2b\n" \
22667 @@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22668
22669 #ifdef CONFIG_X86_INTEL_USERCOPY
22670 static unsigned long
22671 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22672 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22673 {
22674 int d0, d1;
22675 __asm__ __volatile__(
22676 @@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22677 " .align 2,0x90\n"
22678 "3: movl 0(%4), %%eax\n"
22679 "4: movl 4(%4), %%edx\n"
22680 - "5: movl %%eax, 0(%3)\n"
22681 - "6: movl %%edx, 4(%3)\n"
22682 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22683 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22684 "7: movl 8(%4), %%eax\n"
22685 "8: movl 12(%4),%%edx\n"
22686 - "9: movl %%eax, 8(%3)\n"
22687 - "10: movl %%edx, 12(%3)\n"
22688 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22689 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22690 "11: movl 16(%4), %%eax\n"
22691 "12: movl 20(%4), %%edx\n"
22692 - "13: movl %%eax, 16(%3)\n"
22693 - "14: movl %%edx, 20(%3)\n"
22694 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22695 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22696 "15: movl 24(%4), %%eax\n"
22697 "16: movl 28(%4), %%edx\n"
22698 - "17: movl %%eax, 24(%3)\n"
22699 - "18: movl %%edx, 28(%3)\n"
22700 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22701 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22702 "19: movl 32(%4), %%eax\n"
22703 "20: movl 36(%4), %%edx\n"
22704 - "21: movl %%eax, 32(%3)\n"
22705 - "22: movl %%edx, 36(%3)\n"
22706 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22707 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22708 "23: movl 40(%4), %%eax\n"
22709 "24: movl 44(%4), %%edx\n"
22710 - "25: movl %%eax, 40(%3)\n"
22711 - "26: movl %%edx, 44(%3)\n"
22712 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22713 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22714 "27: movl 48(%4), %%eax\n"
22715 "28: movl 52(%4), %%edx\n"
22716 - "29: movl %%eax, 48(%3)\n"
22717 - "30: movl %%edx, 52(%3)\n"
22718 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22719 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22720 "31: movl 56(%4), %%eax\n"
22721 "32: movl 60(%4), %%edx\n"
22722 - "33: movl %%eax, 56(%3)\n"
22723 - "34: movl %%edx, 60(%3)\n"
22724 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22725 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22726 " addl $-64, %0\n"
22727 " addl $64, %4\n"
22728 " addl $64, %3\n"
22729 @@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22730 " shrl $2, %0\n"
22731 " andl $3, %%eax\n"
22732 " cld\n"
22733 + __COPYUSER_SET_ES
22734 "99: rep; movsl\n"
22735 "36: movl %%eax, %0\n"
22736 "37: rep; movsb\n"
22737 "100:\n"
22738 + __COPYUSER_RESTORE_ES
22739 ".section .fixup,\"ax\"\n"
22740 "101: lea 0(%%eax,%0,4),%0\n"
22741 " jmp 100b\n"
22742 @@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22743 }
22744
22745 static unsigned long
22746 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22747 +{
22748 + int d0, d1;
22749 + __asm__ __volatile__(
22750 + " .align 2,0x90\n"
22751 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22752 + " cmpl $67, %0\n"
22753 + " jbe 3f\n"
22754 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22755 + " .align 2,0x90\n"
22756 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22757 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22758 + "5: movl %%eax, 0(%3)\n"
22759 + "6: movl %%edx, 4(%3)\n"
22760 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22761 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22762 + "9: movl %%eax, 8(%3)\n"
22763 + "10: movl %%edx, 12(%3)\n"
22764 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22765 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22766 + "13: movl %%eax, 16(%3)\n"
22767 + "14: movl %%edx, 20(%3)\n"
22768 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22769 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22770 + "17: movl %%eax, 24(%3)\n"
22771 + "18: movl %%edx, 28(%3)\n"
22772 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22773 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22774 + "21: movl %%eax, 32(%3)\n"
22775 + "22: movl %%edx, 36(%3)\n"
22776 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22777 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22778 + "25: movl %%eax, 40(%3)\n"
22779 + "26: movl %%edx, 44(%3)\n"
22780 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22781 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22782 + "29: movl %%eax, 48(%3)\n"
22783 + "30: movl %%edx, 52(%3)\n"
22784 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22785 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22786 + "33: movl %%eax, 56(%3)\n"
22787 + "34: movl %%edx, 60(%3)\n"
22788 + " addl $-64, %0\n"
22789 + " addl $64, %4\n"
22790 + " addl $64, %3\n"
22791 + " cmpl $63, %0\n"
22792 + " ja 1b\n"
22793 + "35: movl %0, %%eax\n"
22794 + " shrl $2, %0\n"
22795 + " andl $3, %%eax\n"
22796 + " cld\n"
22797 + "99: rep; "__copyuser_seg" movsl\n"
22798 + "36: movl %%eax, %0\n"
22799 + "37: rep; "__copyuser_seg" movsb\n"
22800 + "100:\n"
22801 + ".section .fixup,\"ax\"\n"
22802 + "101: lea 0(%%eax,%0,4),%0\n"
22803 + " jmp 100b\n"
22804 + ".previous\n"
22805 + _ASM_EXTABLE(1b,100b)
22806 + _ASM_EXTABLE(2b,100b)
22807 + _ASM_EXTABLE(3b,100b)
22808 + _ASM_EXTABLE(4b,100b)
22809 + _ASM_EXTABLE(5b,100b)
22810 + _ASM_EXTABLE(6b,100b)
22811 + _ASM_EXTABLE(7b,100b)
22812 + _ASM_EXTABLE(8b,100b)
22813 + _ASM_EXTABLE(9b,100b)
22814 + _ASM_EXTABLE(10b,100b)
22815 + _ASM_EXTABLE(11b,100b)
22816 + _ASM_EXTABLE(12b,100b)
22817 + _ASM_EXTABLE(13b,100b)
22818 + _ASM_EXTABLE(14b,100b)
22819 + _ASM_EXTABLE(15b,100b)
22820 + _ASM_EXTABLE(16b,100b)
22821 + _ASM_EXTABLE(17b,100b)
22822 + _ASM_EXTABLE(18b,100b)
22823 + _ASM_EXTABLE(19b,100b)
22824 + _ASM_EXTABLE(20b,100b)
22825 + _ASM_EXTABLE(21b,100b)
22826 + _ASM_EXTABLE(22b,100b)
22827 + _ASM_EXTABLE(23b,100b)
22828 + _ASM_EXTABLE(24b,100b)
22829 + _ASM_EXTABLE(25b,100b)
22830 + _ASM_EXTABLE(26b,100b)
22831 + _ASM_EXTABLE(27b,100b)
22832 + _ASM_EXTABLE(28b,100b)
22833 + _ASM_EXTABLE(29b,100b)
22834 + _ASM_EXTABLE(30b,100b)
22835 + _ASM_EXTABLE(31b,100b)
22836 + _ASM_EXTABLE(32b,100b)
22837 + _ASM_EXTABLE(33b,100b)
22838 + _ASM_EXTABLE(34b,100b)
22839 + _ASM_EXTABLE(35b,100b)
22840 + _ASM_EXTABLE(36b,100b)
22841 + _ASM_EXTABLE(37b,100b)
22842 + _ASM_EXTABLE(99b,101b)
22843 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
22844 + : "1"(to), "2"(from), "0"(size)
22845 + : "eax", "edx", "memory");
22846 + return size;
22847 +}
22848 +
22849 +static unsigned long __size_overflow(3)
22850 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22851 {
22852 int d0, d1;
22853 __asm__ __volatile__(
22854 " .align 2,0x90\n"
22855 - "0: movl 32(%4), %%eax\n"
22856 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22857 " cmpl $67, %0\n"
22858 " jbe 2f\n"
22859 - "1: movl 64(%4), %%eax\n"
22860 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22861 " .align 2,0x90\n"
22862 - "2: movl 0(%4), %%eax\n"
22863 - "21: movl 4(%4), %%edx\n"
22864 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22865 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22866 " movl %%eax, 0(%3)\n"
22867 " movl %%edx, 4(%3)\n"
22868 - "3: movl 8(%4), %%eax\n"
22869 - "31: movl 12(%4),%%edx\n"
22870 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22871 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22872 " movl %%eax, 8(%3)\n"
22873 " movl %%edx, 12(%3)\n"
22874 - "4: movl 16(%4), %%eax\n"
22875 - "41: movl 20(%4), %%edx\n"
22876 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22877 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22878 " movl %%eax, 16(%3)\n"
22879 " movl %%edx, 20(%3)\n"
22880 - "10: movl 24(%4), %%eax\n"
22881 - "51: movl 28(%4), %%edx\n"
22882 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22883 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22884 " movl %%eax, 24(%3)\n"
22885 " movl %%edx, 28(%3)\n"
22886 - "11: movl 32(%4), %%eax\n"
22887 - "61: movl 36(%4), %%edx\n"
22888 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22889 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22890 " movl %%eax, 32(%3)\n"
22891 " movl %%edx, 36(%3)\n"
22892 - "12: movl 40(%4), %%eax\n"
22893 - "71: movl 44(%4), %%edx\n"
22894 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22895 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22896 " movl %%eax, 40(%3)\n"
22897 " movl %%edx, 44(%3)\n"
22898 - "13: movl 48(%4), %%eax\n"
22899 - "81: movl 52(%4), %%edx\n"
22900 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22901 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22902 " movl %%eax, 48(%3)\n"
22903 " movl %%edx, 52(%3)\n"
22904 - "14: movl 56(%4), %%eax\n"
22905 - "91: movl 60(%4), %%edx\n"
22906 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22907 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22908 " movl %%eax, 56(%3)\n"
22909 " movl %%edx, 60(%3)\n"
22910 " addl $-64, %0\n"
22911 @@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22912 " shrl $2, %0\n"
22913 " andl $3, %%eax\n"
22914 " cld\n"
22915 - "6: rep; movsl\n"
22916 + "6: rep; "__copyuser_seg" movsl\n"
22917 " movl %%eax,%0\n"
22918 - "7: rep; movsb\n"
22919 + "7: rep; "__copyuser_seg" movsb\n"
22920 "8:\n"
22921 ".section .fixup,\"ax\"\n"
22922 "9: lea 0(%%eax,%0,4),%0\n"
22923 @@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22924 * hyoshiok@miraclelinux.com
22925 */
22926
22927 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22928 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
22929 const void __user *from, unsigned long size)
22930 {
22931 int d0, d1;
22932
22933 __asm__ __volatile__(
22934 " .align 2,0x90\n"
22935 - "0: movl 32(%4), %%eax\n"
22936 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22937 " cmpl $67, %0\n"
22938 " jbe 2f\n"
22939 - "1: movl 64(%4), %%eax\n"
22940 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22941 " .align 2,0x90\n"
22942 - "2: movl 0(%4), %%eax\n"
22943 - "21: movl 4(%4), %%edx\n"
22944 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22945 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22946 " movnti %%eax, 0(%3)\n"
22947 " movnti %%edx, 4(%3)\n"
22948 - "3: movl 8(%4), %%eax\n"
22949 - "31: movl 12(%4),%%edx\n"
22950 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22951 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22952 " movnti %%eax, 8(%3)\n"
22953 " movnti %%edx, 12(%3)\n"
22954 - "4: movl 16(%4), %%eax\n"
22955 - "41: movl 20(%4), %%edx\n"
22956 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22957 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22958 " movnti %%eax, 16(%3)\n"
22959 " movnti %%edx, 20(%3)\n"
22960 - "10: movl 24(%4), %%eax\n"
22961 - "51: movl 28(%4), %%edx\n"
22962 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22963 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22964 " movnti %%eax, 24(%3)\n"
22965 " movnti %%edx, 28(%3)\n"
22966 - "11: movl 32(%4), %%eax\n"
22967 - "61: movl 36(%4), %%edx\n"
22968 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22969 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22970 " movnti %%eax, 32(%3)\n"
22971 " movnti %%edx, 36(%3)\n"
22972 - "12: movl 40(%4), %%eax\n"
22973 - "71: movl 44(%4), %%edx\n"
22974 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22975 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22976 " movnti %%eax, 40(%3)\n"
22977 " movnti %%edx, 44(%3)\n"
22978 - "13: movl 48(%4), %%eax\n"
22979 - "81: movl 52(%4), %%edx\n"
22980 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22981 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22982 " movnti %%eax, 48(%3)\n"
22983 " movnti %%edx, 52(%3)\n"
22984 - "14: movl 56(%4), %%eax\n"
22985 - "91: movl 60(%4), %%edx\n"
22986 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22987 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22988 " movnti %%eax, 56(%3)\n"
22989 " movnti %%edx, 60(%3)\n"
22990 " addl $-64, %0\n"
22991 @@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22992 " shrl $2, %0\n"
22993 " andl $3, %%eax\n"
22994 " cld\n"
22995 - "6: rep; movsl\n"
22996 + "6: rep; "__copyuser_seg" movsl\n"
22997 " movl %%eax,%0\n"
22998 - "7: rep; movsb\n"
22999 + "7: rep; "__copyuser_seg" movsb\n"
23000 "8:\n"
23001 ".section .fixup,\"ax\"\n"
23002 "9: lea 0(%%eax,%0,4),%0\n"
23003 @@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23004 return size;
23005 }
23006
23007 -static unsigned long __copy_user_intel_nocache(void *to,
23008 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23009 const void __user *from, unsigned long size)
23010 {
23011 int d0, d1;
23012
23013 __asm__ __volatile__(
23014 " .align 2,0x90\n"
23015 - "0: movl 32(%4), %%eax\n"
23016 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23017 " cmpl $67, %0\n"
23018 " jbe 2f\n"
23019 - "1: movl 64(%4), %%eax\n"
23020 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23021 " .align 2,0x90\n"
23022 - "2: movl 0(%4), %%eax\n"
23023 - "21: movl 4(%4), %%edx\n"
23024 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23025 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23026 " movnti %%eax, 0(%3)\n"
23027 " movnti %%edx, 4(%3)\n"
23028 - "3: movl 8(%4), %%eax\n"
23029 - "31: movl 12(%4),%%edx\n"
23030 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23031 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23032 " movnti %%eax, 8(%3)\n"
23033 " movnti %%edx, 12(%3)\n"
23034 - "4: movl 16(%4), %%eax\n"
23035 - "41: movl 20(%4), %%edx\n"
23036 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23037 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23038 " movnti %%eax, 16(%3)\n"
23039 " movnti %%edx, 20(%3)\n"
23040 - "10: movl 24(%4), %%eax\n"
23041 - "51: movl 28(%4), %%edx\n"
23042 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23043 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23044 " movnti %%eax, 24(%3)\n"
23045 " movnti %%edx, 28(%3)\n"
23046 - "11: movl 32(%4), %%eax\n"
23047 - "61: movl 36(%4), %%edx\n"
23048 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23049 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23050 " movnti %%eax, 32(%3)\n"
23051 " movnti %%edx, 36(%3)\n"
23052 - "12: movl 40(%4), %%eax\n"
23053 - "71: movl 44(%4), %%edx\n"
23054 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23055 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23056 " movnti %%eax, 40(%3)\n"
23057 " movnti %%edx, 44(%3)\n"
23058 - "13: movl 48(%4), %%eax\n"
23059 - "81: movl 52(%4), %%edx\n"
23060 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23061 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23062 " movnti %%eax, 48(%3)\n"
23063 " movnti %%edx, 52(%3)\n"
23064 - "14: movl 56(%4), %%eax\n"
23065 - "91: movl 60(%4), %%edx\n"
23066 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23067 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23068 " movnti %%eax, 56(%3)\n"
23069 " movnti %%edx, 60(%3)\n"
23070 " addl $-64, %0\n"
23071 @@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23072 " shrl $2, %0\n"
23073 " andl $3, %%eax\n"
23074 " cld\n"
23075 - "6: rep; movsl\n"
23076 + "6: rep; "__copyuser_seg" movsl\n"
23077 " movl %%eax,%0\n"
23078 - "7: rep; movsb\n"
23079 + "7: rep; "__copyuser_seg" movsb\n"
23080 "8:\n"
23081 ".section .fixup,\"ax\"\n"
23082 "9: lea 0(%%eax,%0,4),%0\n"
23083 @@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23084 */
23085 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23086 unsigned long size);
23087 -unsigned long __copy_user_intel(void __user *to, const void *from,
23088 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23089 + unsigned long size);
23090 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23091 unsigned long size);
23092 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23093 const void __user *from, unsigned long size);
23094 #endif /* CONFIG_X86_INTEL_USERCOPY */
23095
23096 /* Generic arbitrary sized copy. */
23097 -#define __copy_user(to, from, size) \
23098 +#define __copy_user(to, from, size, prefix, set, restore) \
23099 do { \
23100 int __d0, __d1, __d2; \
23101 __asm__ __volatile__( \
23102 + set \
23103 " cmp $7,%0\n" \
23104 " jbe 1f\n" \
23105 " movl %1,%0\n" \
23106 " negl %0\n" \
23107 " andl $7,%0\n" \
23108 " subl %0,%3\n" \
23109 - "4: rep; movsb\n" \
23110 + "4: rep; "prefix"movsb\n" \
23111 " movl %3,%0\n" \
23112 " shrl $2,%0\n" \
23113 " andl $3,%3\n" \
23114 " .align 2,0x90\n" \
23115 - "0: rep; movsl\n" \
23116 + "0: rep; "prefix"movsl\n" \
23117 " movl %3,%0\n" \
23118 - "1: rep; movsb\n" \
23119 + "1: rep; "prefix"movsb\n" \
23120 "2:\n" \
23121 + restore \
23122 ".section .fixup,\"ax\"\n" \
23123 "5: addl %3,%0\n" \
23124 " jmp 2b\n" \
23125 @@ -537,14 +649,14 @@ do { \
23126 " negl %0\n" \
23127 " andl $7,%0\n" \
23128 " subl %0,%3\n" \
23129 - "4: rep; movsb\n" \
23130 + "4: rep; "__copyuser_seg"movsb\n" \
23131 " movl %3,%0\n" \
23132 " shrl $2,%0\n" \
23133 " andl $3,%3\n" \
23134 " .align 2,0x90\n" \
23135 - "0: rep; movsl\n" \
23136 + "0: rep; "__copyuser_seg"movsl\n" \
23137 " movl %3,%0\n" \
23138 - "1: rep; movsb\n" \
23139 + "1: rep; "__copyuser_seg"movsb\n" \
23140 "2:\n" \
23141 ".section .fixup,\"ax\"\n" \
23142 "5: addl %3,%0\n" \
23143 @@ -627,9 +739,9 @@ survive:
23144 }
23145 #endif
23146 if (movsl_is_ok(to, from, n))
23147 - __copy_user(to, from, n);
23148 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23149 else
23150 - n = __copy_user_intel(to, from, n);
23151 + n = __generic_copy_to_user_intel(to, from, n);
23152 return n;
23153 }
23154 EXPORT_SYMBOL(__copy_to_user_ll);
23155 @@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23156 unsigned long n)
23157 {
23158 if (movsl_is_ok(to, from, n))
23159 - __copy_user(to, from, n);
23160 + __copy_user(to, from, n, __copyuser_seg, "", "");
23161 else
23162 - n = __copy_user_intel((void __user *)to,
23163 - (const void *)from, n);
23164 + n = __generic_copy_from_user_intel(to, from, n);
23165 return n;
23166 }
23167 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23168 @@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23169 if (n > 64 && cpu_has_xmm2)
23170 n = __copy_user_intel_nocache(to, from, n);
23171 else
23172 - __copy_user(to, from, n);
23173 + __copy_user(to, from, n, __copyuser_seg, "", "");
23174 #else
23175 - __copy_user(to, from, n);
23176 + __copy_user(to, from, n, __copyuser_seg, "", "");
23177 #endif
23178 return n;
23179 }
23180 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23181
23182 -/**
23183 - * copy_to_user: - Copy a block of data into user space.
23184 - * @to: Destination address, in user space.
23185 - * @from: Source address, in kernel space.
23186 - * @n: Number of bytes to copy.
23187 - *
23188 - * Context: User context only. This function may sleep.
23189 - *
23190 - * Copy data from kernel space to user space.
23191 - *
23192 - * Returns number of bytes that could not be copied.
23193 - * On success, this will be zero.
23194 - */
23195 -unsigned long
23196 -copy_to_user(void __user *to, const void *from, unsigned long n)
23197 -{
23198 - if (access_ok(VERIFY_WRITE, to, n))
23199 - n = __copy_to_user(to, from, n);
23200 - return n;
23201 -}
23202 -EXPORT_SYMBOL(copy_to_user);
23203 -
23204 -/**
23205 - * copy_from_user: - Copy a block of data from user space.
23206 - * @to: Destination address, in kernel space.
23207 - * @from: Source address, in user space.
23208 - * @n: Number of bytes to copy.
23209 - *
23210 - * Context: User context only. This function may sleep.
23211 - *
23212 - * Copy data from user space to kernel space.
23213 - *
23214 - * Returns number of bytes that could not be copied.
23215 - * On success, this will be zero.
23216 - *
23217 - * If some data could not be copied, this function will pad the copied
23218 - * data to the requested size using zero bytes.
23219 - */
23220 -unsigned long
23221 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23222 -{
23223 - if (access_ok(VERIFY_READ, from, n))
23224 - n = __copy_from_user(to, from, n);
23225 - else
23226 - memset(to, 0, n);
23227 - return n;
23228 -}
23229 -EXPORT_SYMBOL(_copy_from_user);
23230 -
23231 void copy_from_user_overflow(void)
23232 {
23233 WARN(1, "Buffer overflow detected!\n");
23234 }
23235 EXPORT_SYMBOL(copy_from_user_overflow);
23236 +
23237 +void copy_to_user_overflow(void)
23238 +{
23239 + WARN(1, "Buffer overflow detected!\n");
23240 +}
23241 +EXPORT_SYMBOL(copy_to_user_overflow);
23242 +
23243 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23244 +void __set_fs(mm_segment_t x)
23245 +{
23246 + switch (x.seg) {
23247 + case 0:
23248 + loadsegment(gs, 0);
23249 + break;
23250 + case TASK_SIZE_MAX:
23251 + loadsegment(gs, __USER_DS);
23252 + break;
23253 + case -1UL:
23254 + loadsegment(gs, __KERNEL_DS);
23255 + break;
23256 + default:
23257 + BUG();
23258 + }
23259 + return;
23260 +}
23261 +EXPORT_SYMBOL(__set_fs);
23262 +
23263 +void set_fs(mm_segment_t x)
23264 +{
23265 + current_thread_info()->addr_limit = x;
23266 + __set_fs(x);
23267 +}
23268 +EXPORT_SYMBOL(set_fs);
23269 +#endif
23270 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23271 index e5b130b..6690d31 100644
23272 --- a/arch/x86/lib/usercopy_64.c
23273 +++ b/arch/x86/lib/usercopy_64.c
23274 @@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23275 {
23276 long __d0;
23277 might_fault();
23278 +
23279 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23280 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23281 + addr += PAX_USER_SHADOW_BASE;
23282 +#endif
23283 +
23284 /* no memory constraint because it doesn't change any memory gcc knows
23285 about */
23286 asm volatile(
23287 @@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23288 }
23289 EXPORT_SYMBOL(clear_user);
23290
23291 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23292 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23293 {
23294 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23295 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23296 - }
23297 - return len;
23298 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23299 +
23300 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23301 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23302 + to += PAX_USER_SHADOW_BASE;
23303 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23304 + from += PAX_USER_SHADOW_BASE;
23305 +#endif
23306 +
23307 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23308 + }
23309 + return len;
23310 }
23311 EXPORT_SYMBOL(copy_in_user);
23312
23313 @@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23314 * it is not necessary to optimize tail handling.
23315 */
23316 unsigned long
23317 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23318 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23319 {
23320 char c;
23321 unsigned zero_len;
23322 @@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23323 break;
23324 return len;
23325 }
23326 +
23327 +void copy_from_user_overflow(void)
23328 +{
23329 + WARN(1, "Buffer overflow detected!\n");
23330 +}
23331 +EXPORT_SYMBOL(copy_from_user_overflow);
23332 +
23333 +void copy_to_user_overflow(void)
23334 +{
23335 + WARN(1, "Buffer overflow detected!\n");
23336 +}
23337 +EXPORT_SYMBOL(copy_to_user_overflow);
23338 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23339 index 903ec1e..833f340 100644
23340 --- a/arch/x86/mm/extable.c
23341 +++ b/arch/x86/mm/extable.c
23342 @@ -6,12 +6,25 @@
23343 static inline unsigned long
23344 ex_insn_addr(const struct exception_table_entry *x)
23345 {
23346 - return (unsigned long)&x->insn + x->insn;
23347 +//printk(KERN_ERR "fixup %p insn:%x fixup:%x\n", x, x->insn, x->fixup);
23348 + unsigned long reloc = 0;
23349 +
23350 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
23351 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23352 +#endif
23353 +
23354 + return (unsigned long)&x->insn + x->insn + reloc;
23355 }
23356 static inline unsigned long
23357 ex_fixup_addr(const struct exception_table_entry *x)
23358 {
23359 - return (unsigned long)&x->fixup + x->fixup;
23360 + unsigned long reloc = 0;
23361 +
23362 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
23363 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23364 +#endif
23365 +
23366 + return (unsigned long)&x->fixup + x->fixup + reloc;
23367 }
23368
23369 int fixup_exception(struct pt_regs *regs)
23370 @@ -20,7 +33,7 @@ int fixup_exception(struct pt_regs *regs)
23371 unsigned long new_ip;
23372
23373 #ifdef CONFIG_PNPBIOS
23374 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23375 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23376 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23377 extern u32 pnp_bios_is_utter_crap;
23378 pnp_bios_is_utter_crap = 1;
23379 @@ -34,6 +47,7 @@ int fixup_exception(struct pt_regs *regs)
23380 #endif
23381
23382 fixup = search_exception_tables(regs->ip);
23383 +//printk(KERN_ERR "fixup %p %lx\n", fixup, regs->ip);
23384 if (fixup) {
23385 new_ip = ex_fixup_addr(fixup);
23386
23387 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23388 index 76dcd9d..e9dffde 100644
23389 --- a/arch/x86/mm/fault.c
23390 +++ b/arch/x86/mm/fault.c
23391 @@ -13,11 +13,18 @@
23392 #include <linux/perf_event.h> /* perf_sw_event */
23393 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23394 #include <linux/prefetch.h> /* prefetchw */
23395 +#include <linux/unistd.h>
23396 +#include <linux/compiler.h>
23397
23398 #include <asm/traps.h> /* dotraplinkage, ... */
23399 #include <asm/pgalloc.h> /* pgd_*(), ... */
23400 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23401 #include <asm/fixmap.h> /* VSYSCALL_START */
23402 +#include <asm/tlbflush.h>
23403 +
23404 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23405 +#include <asm/stacktrace.h>
23406 +#endif
23407
23408 /*
23409 * Page fault error code bits:
23410 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23411 int ret = 0;
23412
23413 /* kprobe_running() needs smp_processor_id() */
23414 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23415 + if (kprobes_built_in() && !user_mode(regs)) {
23416 preempt_disable();
23417 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23418 ret = 1;
23419 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23420 return !instr_lo || (instr_lo>>1) == 1;
23421 case 0x00:
23422 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23423 - if (probe_kernel_address(instr, opcode))
23424 + if (user_mode(regs)) {
23425 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23426 + return 0;
23427 + } else if (probe_kernel_address(instr, opcode))
23428 return 0;
23429
23430 *prefetch = (instr_lo == 0xF) &&
23431 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23432 while (instr < max_instr) {
23433 unsigned char opcode;
23434
23435 - if (probe_kernel_address(instr, opcode))
23436 + if (user_mode(regs)) {
23437 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23438 + break;
23439 + } else if (probe_kernel_address(instr, opcode))
23440 break;
23441
23442 instr++;
23443 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23444 force_sig_info(si_signo, &info, tsk);
23445 }
23446
23447 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23448 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23449 +#endif
23450 +
23451 +#ifdef CONFIG_PAX_EMUTRAMP
23452 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23453 +#endif
23454 +
23455 +#ifdef CONFIG_PAX_PAGEEXEC
23456 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23457 +{
23458 + pgd_t *pgd;
23459 + pud_t *pud;
23460 + pmd_t *pmd;
23461 +
23462 + pgd = pgd_offset(mm, address);
23463 + if (!pgd_present(*pgd))
23464 + return NULL;
23465 + pud = pud_offset(pgd, address);
23466 + if (!pud_present(*pud))
23467 + return NULL;
23468 + pmd = pmd_offset(pud, address);
23469 + if (!pmd_present(*pmd))
23470 + return NULL;
23471 + return pmd;
23472 +}
23473 +#endif
23474 +
23475 DEFINE_SPINLOCK(pgd_lock);
23476 LIST_HEAD(pgd_list);
23477
23478 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23479 for (address = VMALLOC_START & PMD_MASK;
23480 address >= TASK_SIZE && address < FIXADDR_TOP;
23481 address += PMD_SIZE) {
23482 +
23483 +#ifdef CONFIG_PAX_PER_CPU_PGD
23484 + unsigned long cpu;
23485 +#else
23486 struct page *page;
23487 +#endif
23488
23489 spin_lock(&pgd_lock);
23490 +
23491 +#ifdef CONFIG_PAX_PER_CPU_PGD
23492 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23493 + pgd_t *pgd = get_cpu_pgd(cpu);
23494 + pmd_t *ret;
23495 +#else
23496 list_for_each_entry(page, &pgd_list, lru) {
23497 + pgd_t *pgd = page_address(page);
23498 spinlock_t *pgt_lock;
23499 pmd_t *ret;
23500
23501 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23502 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23503
23504 spin_lock(pgt_lock);
23505 - ret = vmalloc_sync_one(page_address(page), address);
23506 +#endif
23507 +
23508 + ret = vmalloc_sync_one(pgd, address);
23509 +
23510 +#ifndef CONFIG_PAX_PER_CPU_PGD
23511 spin_unlock(pgt_lock);
23512 +#endif
23513
23514 if (!ret)
23515 break;
23516 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23517 * an interrupt in the middle of a task switch..
23518 */
23519 pgd_paddr = read_cr3();
23520 +
23521 +#ifdef CONFIG_PAX_PER_CPU_PGD
23522 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23523 +#endif
23524 +
23525 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23526 if (!pmd_k)
23527 return -1;
23528 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23529 * happen within a race in page table update. In the later
23530 * case just flush:
23531 */
23532 +
23533 +#ifdef CONFIG_PAX_PER_CPU_PGD
23534 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23535 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23536 +#else
23537 pgd = pgd_offset(current->active_mm, address);
23538 +#endif
23539 +
23540 pgd_ref = pgd_offset_k(address);
23541 if (pgd_none(*pgd_ref))
23542 return -1;
23543 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23544 static int is_errata100(struct pt_regs *regs, unsigned long address)
23545 {
23546 #ifdef CONFIG_X86_64
23547 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23548 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23549 return 1;
23550 #endif
23551 return 0;
23552 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23553 }
23554
23555 static const char nx_warning[] = KERN_CRIT
23556 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23557 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23558
23559 static void
23560 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23561 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23562 if (!oops_may_print())
23563 return;
23564
23565 - if (error_code & PF_INSTR) {
23566 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23567 unsigned int level;
23568
23569 pte_t *pte = lookup_address(address, &level);
23570
23571 if (pte && pte_present(*pte) && !pte_exec(*pte))
23572 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23573 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23574 }
23575
23576 +#ifdef CONFIG_PAX_KERNEXEC
23577 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23578 + if (current->signal->curr_ip)
23579 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23580 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23581 + else
23582 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23583 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23584 + }
23585 +#endif
23586 +
23587 printk(KERN_ALERT "BUG: unable to handle kernel ");
23588 if (address < PAGE_SIZE)
23589 printk(KERN_CONT "NULL pointer dereference");
23590 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23591 }
23592 #endif
23593
23594 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23595 + if (pax_is_fetch_fault(regs, error_code, address)) {
23596 +
23597 +#ifdef CONFIG_PAX_EMUTRAMP
23598 + switch (pax_handle_fetch_fault(regs)) {
23599 + case 2:
23600 + return;
23601 + }
23602 +#endif
23603 +
23604 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23605 + do_group_exit(SIGKILL);
23606 + }
23607 +#endif
23608 +
23609 if (unlikely(show_unhandled_signals))
23610 show_signal_msg(regs, error_code, address, tsk);
23611
23612 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23613 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23614 printk(KERN_ERR
23615 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23616 - tsk->comm, tsk->pid, address);
23617 + tsk->comm, task_pid_nr(tsk), address);
23618 code = BUS_MCEERR_AR;
23619 }
23620 #endif
23621 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23622 return 1;
23623 }
23624
23625 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23626 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23627 +{
23628 + pte_t *pte;
23629 + pmd_t *pmd;
23630 + spinlock_t *ptl;
23631 + unsigned char pte_mask;
23632 +
23633 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23634 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23635 + return 0;
23636 +
23637 + /* PaX: it's our fault, let's handle it if we can */
23638 +
23639 + /* PaX: take a look at read faults before acquiring any locks */
23640 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23641 + /* instruction fetch attempt from a protected page in user mode */
23642 + up_read(&mm->mmap_sem);
23643 +
23644 +#ifdef CONFIG_PAX_EMUTRAMP
23645 + switch (pax_handle_fetch_fault(regs)) {
23646 + case 2:
23647 + return 1;
23648 + }
23649 +#endif
23650 +
23651 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23652 + do_group_exit(SIGKILL);
23653 + }
23654 +
23655 + pmd = pax_get_pmd(mm, address);
23656 + if (unlikely(!pmd))
23657 + return 0;
23658 +
23659 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23660 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23661 + pte_unmap_unlock(pte, ptl);
23662 + return 0;
23663 + }
23664 +
23665 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23666 + /* write attempt to a protected page in user mode */
23667 + pte_unmap_unlock(pte, ptl);
23668 + return 0;
23669 + }
23670 +
23671 +#ifdef CONFIG_SMP
23672 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23673 +#else
23674 + if (likely(address > get_limit(regs->cs)))
23675 +#endif
23676 + {
23677 + set_pte(pte, pte_mkread(*pte));
23678 + __flush_tlb_one(address);
23679 + pte_unmap_unlock(pte, ptl);
23680 + up_read(&mm->mmap_sem);
23681 + return 1;
23682 + }
23683 +
23684 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23685 +
23686 + /*
23687 + * PaX: fill DTLB with user rights and retry
23688 + */
23689 + __asm__ __volatile__ (
23690 + "orb %2,(%1)\n"
23691 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23692 +/*
23693 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23694 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23695 + * page fault when examined during a TLB load attempt. this is true not only
23696 + * for PTEs holding a non-present entry but also present entries that will
23697 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23698 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23699 + * for our target pages since their PTEs are simply not in the TLBs at all.
23700 +
23701 + * the best thing in omitting it is that we gain around 15-20% speed in the
23702 + * fast path of the page fault handler and can get rid of tracing since we
23703 + * can no longer flush unintended entries.
23704 + */
23705 + "invlpg (%0)\n"
23706 +#endif
23707 + __copyuser_seg"testb $0,(%0)\n"
23708 + "xorb %3,(%1)\n"
23709 + :
23710 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23711 + : "memory", "cc");
23712 + pte_unmap_unlock(pte, ptl);
23713 + up_read(&mm->mmap_sem);
23714 + return 1;
23715 +}
23716 +#endif
23717 +
23718 /*
23719 * Handle a spurious fault caused by a stale TLB entry.
23720 *
23721 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23722 static inline int
23723 access_error(unsigned long error_code, struct vm_area_struct *vma)
23724 {
23725 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23726 + return 1;
23727 +
23728 if (error_code & PF_WRITE) {
23729 /* write, present and write, not present: */
23730 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23731 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23732 {
23733 struct vm_area_struct *vma;
23734 struct task_struct *tsk;
23735 - unsigned long address;
23736 struct mm_struct *mm;
23737 int fault;
23738 int write = error_code & PF_WRITE;
23739 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23740 (write ? FAULT_FLAG_WRITE : 0);
23741
23742 - tsk = current;
23743 - mm = tsk->mm;
23744 -
23745 /* Get the faulting address: */
23746 - address = read_cr2();
23747 + unsigned long address = read_cr2();
23748 +
23749 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23750 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23751 + if (!search_exception_tables(regs->ip)) {
23752 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23753 + bad_area_nosemaphore(regs, error_code, address);
23754 + return;
23755 + }
23756 + if (address < PAX_USER_SHADOW_BASE) {
23757 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23758 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23759 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23760 + } else
23761 + address -= PAX_USER_SHADOW_BASE;
23762 + }
23763 +#endif
23764 +
23765 + tsk = current;
23766 + mm = tsk->mm;
23767
23768 /*
23769 * Detect and handle instructions that would cause a page fault for
23770 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23771 * User-mode registers count as a user access even for any
23772 * potential system fault or CPU buglet:
23773 */
23774 - if (user_mode_vm(regs)) {
23775 + if (user_mode(regs)) {
23776 local_irq_enable();
23777 error_code |= PF_USER;
23778 } else {
23779 @@ -1132,6 +1339,11 @@ retry:
23780 might_sleep();
23781 }
23782
23783 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23784 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23785 + return;
23786 +#endif
23787 +
23788 vma = find_vma(mm, address);
23789 if (unlikely(!vma)) {
23790 bad_area(regs, error_code, address);
23791 @@ -1143,18 +1355,24 @@ retry:
23792 bad_area(regs, error_code, address);
23793 return;
23794 }
23795 - if (error_code & PF_USER) {
23796 - /*
23797 - * Accessing the stack below %sp is always a bug.
23798 - * The large cushion allows instructions like enter
23799 - * and pusha to work. ("enter $65535, $31" pushes
23800 - * 32 pointers and then decrements %sp by 65535.)
23801 - */
23802 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23803 - bad_area(regs, error_code, address);
23804 - return;
23805 - }
23806 + /*
23807 + * Accessing the stack below %sp is always a bug.
23808 + * The large cushion allows instructions like enter
23809 + * and pusha to work. ("enter $65535, $31" pushes
23810 + * 32 pointers and then decrements %sp by 65535.)
23811 + */
23812 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23813 + bad_area(regs, error_code, address);
23814 + return;
23815 }
23816 +
23817 +#ifdef CONFIG_PAX_SEGMEXEC
23818 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23819 + bad_area(regs, error_code, address);
23820 + return;
23821 + }
23822 +#endif
23823 +
23824 if (unlikely(expand_stack(vma, address))) {
23825 bad_area(regs, error_code, address);
23826 return;
23827 @@ -1209,3 +1427,292 @@ good_area:
23828
23829 up_read(&mm->mmap_sem);
23830 }
23831 +
23832 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23833 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23834 +{
23835 + struct mm_struct *mm = current->mm;
23836 + unsigned long ip = regs->ip;
23837 +
23838 + if (v8086_mode(regs))
23839 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
23840 +
23841 +#ifdef CONFIG_PAX_PAGEEXEC
23842 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
23843 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
23844 + return true;
23845 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
23846 + return true;
23847 + return false;
23848 + }
23849 +#endif
23850 +
23851 +#ifdef CONFIG_PAX_SEGMEXEC
23852 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
23853 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
23854 + return true;
23855 + return false;
23856 + }
23857 +#endif
23858 +
23859 + return false;
23860 +}
23861 +#endif
23862 +
23863 +#ifdef CONFIG_PAX_EMUTRAMP
23864 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
23865 +{
23866 + int err;
23867 +
23868 + do { /* PaX: libffi trampoline emulation */
23869 + unsigned char mov, jmp;
23870 + unsigned int addr1, addr2;
23871 +
23872 +#ifdef CONFIG_X86_64
23873 + if ((regs->ip + 9) >> 32)
23874 + break;
23875 +#endif
23876 +
23877 + err = get_user(mov, (unsigned char __user *)regs->ip);
23878 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23879 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23880 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23881 +
23882 + if (err)
23883 + break;
23884 +
23885 + if (mov == 0xB8 && jmp == 0xE9) {
23886 + regs->ax = addr1;
23887 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23888 + return 2;
23889 + }
23890 + } while (0);
23891 +
23892 + do { /* PaX: gcc trampoline emulation #1 */
23893 + unsigned char mov1, mov2;
23894 + unsigned short jmp;
23895 + unsigned int addr1, addr2;
23896 +
23897 +#ifdef CONFIG_X86_64
23898 + if ((regs->ip + 11) >> 32)
23899 + break;
23900 +#endif
23901 +
23902 + err = get_user(mov1, (unsigned char __user *)regs->ip);
23903 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23904 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
23905 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23906 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
23907 +
23908 + if (err)
23909 + break;
23910 +
23911 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
23912 + regs->cx = addr1;
23913 + regs->ax = addr2;
23914 + regs->ip = addr2;
23915 + return 2;
23916 + }
23917 + } while (0);
23918 +
23919 + do { /* PaX: gcc trampoline emulation #2 */
23920 + unsigned char mov, jmp;
23921 + unsigned int addr1, addr2;
23922 +
23923 +#ifdef CONFIG_X86_64
23924 + if ((regs->ip + 9) >> 32)
23925 + break;
23926 +#endif
23927 +
23928 + err = get_user(mov, (unsigned char __user *)regs->ip);
23929 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23930 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23931 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23932 +
23933 + if (err)
23934 + break;
23935 +
23936 + if (mov == 0xB9 && jmp == 0xE9) {
23937 + regs->cx = addr1;
23938 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23939 + return 2;
23940 + }
23941 + } while (0);
23942 +
23943 + return 1; /* PaX in action */
23944 +}
23945 +
23946 +#ifdef CONFIG_X86_64
23947 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
23948 +{
23949 + int err;
23950 +
23951 + do { /* PaX: libffi trampoline emulation */
23952 + unsigned short mov1, mov2, jmp1;
23953 + unsigned char stcclc, jmp2;
23954 + unsigned long addr1, addr2;
23955 +
23956 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23957 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23958 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23959 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23960 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
23961 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
23962 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
23963 +
23964 + if (err)
23965 + break;
23966 +
23967 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23968 + regs->r11 = addr1;
23969 + regs->r10 = addr2;
23970 + if (stcclc == 0xF8)
23971 + regs->flags &= ~X86_EFLAGS_CF;
23972 + else
23973 + regs->flags |= X86_EFLAGS_CF;
23974 + regs->ip = addr1;
23975 + return 2;
23976 + }
23977 + } while (0);
23978 +
23979 + do { /* PaX: gcc trampoline emulation #1 */
23980 + unsigned short mov1, mov2, jmp1;
23981 + unsigned char jmp2;
23982 + unsigned int addr1;
23983 + unsigned long addr2;
23984 +
23985 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23986 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
23987 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
23988 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
23989 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
23990 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
23991 +
23992 + if (err)
23993 + break;
23994 +
23995 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23996 + regs->r11 = addr1;
23997 + regs->r10 = addr2;
23998 + regs->ip = addr1;
23999 + return 2;
24000 + }
24001 + } while (0);
24002 +
24003 + do { /* PaX: gcc trampoline emulation #2 */
24004 + unsigned short mov1, mov2, jmp1;
24005 + unsigned char jmp2;
24006 + unsigned long addr1, addr2;
24007 +
24008 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24009 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24010 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24011 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24012 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24013 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24014 +
24015 + if (err)
24016 + break;
24017 +
24018 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24019 + regs->r11 = addr1;
24020 + regs->r10 = addr2;
24021 + regs->ip = addr1;
24022 + return 2;
24023 + }
24024 + } while (0);
24025 +
24026 + return 1; /* PaX in action */
24027 +}
24028 +#endif
24029 +
24030 +/*
24031 + * PaX: decide what to do with offenders (regs->ip = fault address)
24032 + *
24033 + * returns 1 when task should be killed
24034 + * 2 when gcc trampoline was detected
24035 + */
24036 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24037 +{
24038 + if (v8086_mode(regs))
24039 + return 1;
24040 +
24041 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24042 + return 1;
24043 +
24044 +#ifdef CONFIG_X86_32
24045 + return pax_handle_fetch_fault_32(regs);
24046 +#else
24047 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24048 + return pax_handle_fetch_fault_32(regs);
24049 + else
24050 + return pax_handle_fetch_fault_64(regs);
24051 +#endif
24052 +}
24053 +#endif
24054 +
24055 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24056 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24057 +{
24058 + long i;
24059 +
24060 + printk(KERN_ERR "PAX: bytes at PC: ");
24061 + for (i = 0; i < 20; i++) {
24062 + unsigned char c;
24063 + if (get_user(c, (unsigned char __force_user *)pc+i))
24064 + printk(KERN_CONT "?? ");
24065 + else
24066 + printk(KERN_CONT "%02x ", c);
24067 + }
24068 + printk("\n");
24069 +
24070 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24071 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24072 + unsigned long c;
24073 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24074 +#ifdef CONFIG_X86_32
24075 + printk(KERN_CONT "???????? ");
24076 +#else
24077 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24078 + printk(KERN_CONT "???????? ???????? ");
24079 + else
24080 + printk(KERN_CONT "???????????????? ");
24081 +#endif
24082 + } else {
24083 +#ifdef CONFIG_X86_64
24084 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24085 + printk(KERN_CONT "%08x ", (unsigned int)c);
24086 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24087 + } else
24088 +#endif
24089 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24090 + }
24091 + }
24092 + printk("\n");
24093 +}
24094 +#endif
24095 +
24096 +/**
24097 + * probe_kernel_write(): safely attempt to write to a location
24098 + * @dst: address to write to
24099 + * @src: pointer to the data that shall be written
24100 + * @size: size of the data chunk
24101 + *
24102 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24103 + * happens, handle that and return -EFAULT.
24104 + */
24105 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24106 +{
24107 + long ret;
24108 + mm_segment_t old_fs = get_fs();
24109 +
24110 + set_fs(KERNEL_DS);
24111 + pagefault_disable();
24112 + pax_open_kernel();
24113 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24114 + pax_close_kernel();
24115 + pagefault_enable();
24116 + set_fs(old_fs);
24117 +
24118 + return ret ? -EFAULT : 0;
24119 +}
24120 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24121 index dd74e46..7d26398 100644
24122 --- a/arch/x86/mm/gup.c
24123 +++ b/arch/x86/mm/gup.c
24124 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24125 addr = start;
24126 len = (unsigned long) nr_pages << PAGE_SHIFT;
24127 end = start + len;
24128 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24129 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24130 (void __user *)start, len)))
24131 return 0;
24132
24133 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24134 index 6f31ee5..8ee4164 100644
24135 --- a/arch/x86/mm/highmem_32.c
24136 +++ b/arch/x86/mm/highmem_32.c
24137 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24138 idx = type + KM_TYPE_NR*smp_processor_id();
24139 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24140 BUG_ON(!pte_none(*(kmap_pte-idx)));
24141 +
24142 + pax_open_kernel();
24143 set_pte(kmap_pte-idx, mk_pte(page, prot));
24144 + pax_close_kernel();
24145 +
24146 arch_flush_lazy_mmu_mode();
24147
24148 return (void *)vaddr;
24149 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24150 index f6679a7..8f795a3 100644
24151 --- a/arch/x86/mm/hugetlbpage.c
24152 +++ b/arch/x86/mm/hugetlbpage.c
24153 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24154 struct hstate *h = hstate_file(file);
24155 struct mm_struct *mm = current->mm;
24156 struct vm_area_struct *vma;
24157 - unsigned long start_addr;
24158 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24159 +
24160 +#ifdef CONFIG_PAX_SEGMEXEC
24161 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24162 + pax_task_size = SEGMEXEC_TASK_SIZE;
24163 +#endif
24164 +
24165 + pax_task_size -= PAGE_SIZE;
24166
24167 if (len > mm->cached_hole_size) {
24168 - start_addr = mm->free_area_cache;
24169 + start_addr = mm->free_area_cache;
24170 } else {
24171 - start_addr = TASK_UNMAPPED_BASE;
24172 - mm->cached_hole_size = 0;
24173 + start_addr = mm->mmap_base;
24174 + mm->cached_hole_size = 0;
24175 }
24176
24177 full_search:
24178 @@ -280,26 +287,27 @@ full_search:
24179
24180 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24181 /* At this point: (!vma || addr < vma->vm_end). */
24182 - if (TASK_SIZE - len < addr) {
24183 + if (pax_task_size - len < addr) {
24184 /*
24185 * Start a new search - just in case we missed
24186 * some holes.
24187 */
24188 - if (start_addr != TASK_UNMAPPED_BASE) {
24189 - start_addr = TASK_UNMAPPED_BASE;
24190 + if (start_addr != mm->mmap_base) {
24191 + start_addr = mm->mmap_base;
24192 mm->cached_hole_size = 0;
24193 goto full_search;
24194 }
24195 return -ENOMEM;
24196 }
24197 - if (!vma || addr + len <= vma->vm_start) {
24198 - mm->free_area_cache = addr + len;
24199 - return addr;
24200 - }
24201 + if (check_heap_stack_gap(vma, addr, len))
24202 + break;
24203 if (addr + mm->cached_hole_size < vma->vm_start)
24204 mm->cached_hole_size = vma->vm_start - addr;
24205 addr = ALIGN(vma->vm_end, huge_page_size(h));
24206 }
24207 +
24208 + mm->free_area_cache = addr + len;
24209 + return addr;
24210 }
24211
24212 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24213 @@ -310,9 +318,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24214 struct mm_struct *mm = current->mm;
24215 struct vm_area_struct *vma;
24216 unsigned long base = mm->mmap_base;
24217 - unsigned long addr = addr0;
24218 + unsigned long addr;
24219 unsigned long largest_hole = mm->cached_hole_size;
24220 - unsigned long start_addr;
24221
24222 /* don't allow allocations above current base */
24223 if (mm->free_area_cache > base)
24224 @@ -322,16 +329,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24225 largest_hole = 0;
24226 mm->free_area_cache = base;
24227 }
24228 -try_again:
24229 - start_addr = mm->free_area_cache;
24230
24231 /* make sure it can fit in the remaining address space */
24232 if (mm->free_area_cache < len)
24233 goto fail;
24234
24235 /* either no address requested or can't fit in requested address hole */
24236 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24237 + addr = mm->free_area_cache - len;
24238 do {
24239 + addr &= huge_page_mask(h);
24240 /*
24241 * Lookup failure means no vma is above this address,
24242 * i.e. return with success:
24243 @@ -340,10 +346,10 @@ try_again:
24244 if (!vma)
24245 return addr;
24246
24247 - if (addr + len <= vma->vm_start) {
24248 + if (check_heap_stack_gap(vma, addr, len)) {
24249 /* remember the address as a hint for next time */
24250 - mm->cached_hole_size = largest_hole;
24251 - return (mm->free_area_cache = addr);
24252 + mm->cached_hole_size = largest_hole;
24253 + return (mm->free_area_cache = addr);
24254 } else if (mm->free_area_cache == vma->vm_end) {
24255 /* pull free_area_cache down to the first hole */
24256 mm->free_area_cache = vma->vm_start;
24257 @@ -352,29 +358,34 @@ try_again:
24258
24259 /* remember the largest hole we saw so far */
24260 if (addr + largest_hole < vma->vm_start)
24261 - largest_hole = vma->vm_start - addr;
24262 + largest_hole = vma->vm_start - addr;
24263
24264 /* try just below the current vma->vm_start */
24265 - addr = (vma->vm_start - len) & huge_page_mask(h);
24266 - } while (len <= vma->vm_start);
24267 + addr = skip_heap_stack_gap(vma, len);
24268 + } while (!IS_ERR_VALUE(addr));
24269
24270 fail:
24271 /*
24272 - * if hint left us with no space for the requested
24273 - * mapping then try again:
24274 - */
24275 - if (start_addr != base) {
24276 - mm->free_area_cache = base;
24277 - largest_hole = 0;
24278 - goto try_again;
24279 - }
24280 - /*
24281 * A failed mmap() very likely causes application failure,
24282 * so fall back to the bottom-up function here. This scenario
24283 * can happen with large stack limits and large mmap()
24284 * allocations.
24285 */
24286 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24287 +
24288 +#ifdef CONFIG_PAX_SEGMEXEC
24289 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24290 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24291 + else
24292 +#endif
24293 +
24294 + mm->mmap_base = TASK_UNMAPPED_BASE;
24295 +
24296 +#ifdef CONFIG_PAX_RANDMMAP
24297 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24298 + mm->mmap_base += mm->delta_mmap;
24299 +#endif
24300 +
24301 + mm->free_area_cache = mm->mmap_base;
24302 mm->cached_hole_size = ~0UL;
24303 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24304 len, pgoff, flags);
24305 @@ -382,6 +393,7 @@ fail:
24306 /*
24307 * Restore the topdown base:
24308 */
24309 + mm->mmap_base = base;
24310 mm->free_area_cache = base;
24311 mm->cached_hole_size = ~0UL;
24312
24313 @@ -395,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24314 struct hstate *h = hstate_file(file);
24315 struct mm_struct *mm = current->mm;
24316 struct vm_area_struct *vma;
24317 + unsigned long pax_task_size = TASK_SIZE;
24318
24319 if (len & ~huge_page_mask(h))
24320 return -EINVAL;
24321 - if (len > TASK_SIZE)
24322 +
24323 +#ifdef CONFIG_PAX_SEGMEXEC
24324 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24325 + pax_task_size = SEGMEXEC_TASK_SIZE;
24326 +#endif
24327 +
24328 + pax_task_size -= PAGE_SIZE;
24329 +
24330 + if (len > pax_task_size)
24331 return -ENOMEM;
24332
24333 if (flags & MAP_FIXED) {
24334 @@ -410,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24335 if (addr) {
24336 addr = ALIGN(addr, huge_page_size(h));
24337 vma = find_vma(mm, addr);
24338 - if (TASK_SIZE - len >= addr &&
24339 - (!vma || addr + len <= vma->vm_start))
24340 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24341 return addr;
24342 }
24343 if (mm->get_unmapped_area == arch_get_unmapped_area)
24344 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24345 index bc4e9d8..ca4c14b 100644
24346 --- a/arch/x86/mm/init.c
24347 +++ b/arch/x86/mm/init.c
24348 @@ -16,6 +16,8 @@
24349 #include <asm/tlb.h>
24350 #include <asm/proto.h>
24351 #include <asm/dma.h> /* for MAX_DMA_PFN */
24352 +#include <asm/desc.h>
24353 +#include <asm/bios_ebda.h>
24354
24355 unsigned long __initdata pgt_buf_start;
24356 unsigned long __meminitdata pgt_buf_end;
24357 @@ -38,7 +40,7 @@ struct map_range {
24358 static void __init find_early_table_space(struct map_range *mr, unsigned long end,
24359 int use_pse, int use_gbpages)
24360 {
24361 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24362 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24363 phys_addr_t base;
24364
24365 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24366 @@ -317,10 +319,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24367 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24368 * mmio resources as well as potential bios/acpi data regions.
24369 */
24370 +
24371 +#ifdef CONFIG_GRKERNSEC_KMEM
24372 +static unsigned int ebda_start __read_only;
24373 +static unsigned int ebda_end __read_only;
24374 +#endif
24375 +
24376 int devmem_is_allowed(unsigned long pagenr)
24377 {
24378 +#ifdef CONFIG_GRKERNSEC_KMEM
24379 + /* allow BDA */
24380 + if (!pagenr)
24381 + return 1;
24382 + /* allow EBDA */
24383 + if (pagenr >= ebda_start && pagenr < ebda_end)
24384 + return 1;
24385 +#else
24386 + if (!pagenr)
24387 + return 1;
24388 +#ifdef CONFIG_VM86
24389 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24390 + return 1;
24391 +#endif
24392 +#endif
24393 +
24394 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24395 + return 1;
24396 +#ifdef CONFIG_GRKERNSEC_KMEM
24397 + /* throw out everything else below 1MB */
24398 if (pagenr <= 256)
24399 - return 1;
24400 + return 0;
24401 +#endif
24402 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24403 return 0;
24404 if (!page_is_ram(pagenr))
24405 @@ -377,8 +406,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24406 #endif
24407 }
24408
24409 +#ifdef CONFIG_GRKERNSEC_KMEM
24410 +static inline void gr_init_ebda(void)
24411 +{
24412 + unsigned int ebda_addr;
24413 + unsigned int ebda_size = 0;
24414 +
24415 + ebda_addr = get_bios_ebda();
24416 + if (ebda_addr) {
24417 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24418 + ebda_size <<= 10;
24419 + }
24420 + if (ebda_addr && ebda_size) {
24421 + ebda_start = ebda_addr >> PAGE_SHIFT;
24422 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24423 + } else {
24424 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24425 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24426 + }
24427 +}
24428 +#else
24429 +static inline void gr_init_ebda(void) { }
24430 +#endif
24431 +
24432 void free_initmem(void)
24433 {
24434 +#ifdef CONFIG_PAX_KERNEXEC
24435 +#ifdef CONFIG_X86_32
24436 + /* PaX: limit KERNEL_CS to actual size */
24437 + unsigned long addr, limit;
24438 + struct desc_struct d;
24439 + int cpu;
24440 +#else
24441 + pgd_t *pgd;
24442 + pud_t *pud;
24443 + pmd_t *pmd;
24444 + unsigned long addr, end;
24445 +#endif
24446 +#endif
24447 +
24448 + gr_init_ebda();
24449 +
24450 +#ifdef CONFIG_PAX_KERNEXEC
24451 +#ifdef CONFIG_X86_32
24452 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24453 + limit = (limit - 1UL) >> PAGE_SHIFT;
24454 +
24455 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24456 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24457 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24458 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24459 + }
24460 +
24461 + /* PaX: make KERNEL_CS read-only */
24462 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24463 + if (!paravirt_enabled())
24464 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24465 +/*
24466 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24467 + pgd = pgd_offset_k(addr);
24468 + pud = pud_offset(pgd, addr);
24469 + pmd = pmd_offset(pud, addr);
24470 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24471 + }
24472 +*/
24473 +#ifdef CONFIG_X86_PAE
24474 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24475 +/*
24476 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24477 + pgd = pgd_offset_k(addr);
24478 + pud = pud_offset(pgd, addr);
24479 + pmd = pmd_offset(pud, addr);
24480 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24481 + }
24482 +*/
24483 +#endif
24484 +
24485 +#ifdef CONFIG_MODULES
24486 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24487 +#endif
24488 +
24489 +#else
24490 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24491 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24492 + pgd = pgd_offset_k(addr);
24493 + pud = pud_offset(pgd, addr);
24494 + pmd = pmd_offset(pud, addr);
24495 + if (!pmd_present(*pmd))
24496 + continue;
24497 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24498 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24499 + else
24500 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24501 + }
24502 +
24503 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24504 + end = addr + KERNEL_IMAGE_SIZE;
24505 + for (; addr < end; addr += PMD_SIZE) {
24506 + pgd = pgd_offset_k(addr);
24507 + pud = pud_offset(pgd, addr);
24508 + pmd = pmd_offset(pud, addr);
24509 + if (!pmd_present(*pmd))
24510 + continue;
24511 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24512 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24513 + }
24514 +#endif
24515 +
24516 + flush_tlb_all();
24517 +#endif
24518 +
24519 free_init_pages("unused kernel memory",
24520 (unsigned long)(&__init_begin),
24521 (unsigned long)(&__init_end));
24522 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24523 index 575d86f..4987469 100644
24524 --- a/arch/x86/mm/init_32.c
24525 +++ b/arch/x86/mm/init_32.c
24526 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24527 }
24528
24529 /*
24530 - * Creates a middle page table and puts a pointer to it in the
24531 - * given global directory entry. This only returns the gd entry
24532 - * in non-PAE compilation mode, since the middle layer is folded.
24533 - */
24534 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24535 -{
24536 - pud_t *pud;
24537 - pmd_t *pmd_table;
24538 -
24539 -#ifdef CONFIG_X86_PAE
24540 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24541 - if (after_bootmem)
24542 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24543 - else
24544 - pmd_table = (pmd_t *)alloc_low_page();
24545 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24546 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24547 - pud = pud_offset(pgd, 0);
24548 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24549 -
24550 - return pmd_table;
24551 - }
24552 -#endif
24553 - pud = pud_offset(pgd, 0);
24554 - pmd_table = pmd_offset(pud, 0);
24555 -
24556 - return pmd_table;
24557 -}
24558 -
24559 -/*
24560 * Create a page table and place a pointer to it in a middle page
24561 * directory entry:
24562 */
24563 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24564 page_table = (pte_t *)alloc_low_page();
24565
24566 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24567 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24568 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24569 +#else
24570 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24571 +#endif
24572 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24573 }
24574
24575 return pte_offset_kernel(pmd, 0);
24576 }
24577
24578 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24579 +{
24580 + pud_t *pud;
24581 + pmd_t *pmd_table;
24582 +
24583 + pud = pud_offset(pgd, 0);
24584 + pmd_table = pmd_offset(pud, 0);
24585 +
24586 + return pmd_table;
24587 +}
24588 +
24589 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24590 {
24591 int pgd_idx = pgd_index(vaddr);
24592 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24593 int pgd_idx, pmd_idx;
24594 unsigned long vaddr;
24595 pgd_t *pgd;
24596 + pud_t *pud;
24597 pmd_t *pmd;
24598 pte_t *pte = NULL;
24599
24600 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24601 pgd = pgd_base + pgd_idx;
24602
24603 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24604 - pmd = one_md_table_init(pgd);
24605 - pmd = pmd + pmd_index(vaddr);
24606 + pud = pud_offset(pgd, vaddr);
24607 + pmd = pmd_offset(pud, vaddr);
24608 +
24609 +#ifdef CONFIG_X86_PAE
24610 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24611 +#endif
24612 +
24613 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24614 pmd++, pmd_idx++) {
24615 pte = page_table_kmap_check(one_page_table_init(pmd),
24616 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24617 }
24618 }
24619
24620 -static inline int is_kernel_text(unsigned long addr)
24621 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24622 {
24623 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24624 - return 1;
24625 - return 0;
24626 + if ((start > ktla_ktva((unsigned long)_etext) ||
24627 + end <= ktla_ktva((unsigned long)_stext)) &&
24628 + (start > ktla_ktva((unsigned long)_einittext) ||
24629 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24630 +
24631 +#ifdef CONFIG_ACPI_SLEEP
24632 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24633 +#endif
24634 +
24635 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24636 + return 0;
24637 + return 1;
24638 }
24639
24640 /*
24641 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24642 unsigned long last_map_addr = end;
24643 unsigned long start_pfn, end_pfn;
24644 pgd_t *pgd_base = swapper_pg_dir;
24645 - int pgd_idx, pmd_idx, pte_ofs;
24646 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24647 unsigned long pfn;
24648 pgd_t *pgd;
24649 + pud_t *pud;
24650 pmd_t *pmd;
24651 pte_t *pte;
24652 unsigned pages_2m, pages_4k;
24653 @@ -280,8 +281,13 @@ repeat:
24654 pfn = start_pfn;
24655 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24656 pgd = pgd_base + pgd_idx;
24657 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24658 - pmd = one_md_table_init(pgd);
24659 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24660 + pud = pud_offset(pgd, 0);
24661 + pmd = pmd_offset(pud, 0);
24662 +
24663 +#ifdef CONFIG_X86_PAE
24664 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24665 +#endif
24666
24667 if (pfn >= end_pfn)
24668 continue;
24669 @@ -293,14 +299,13 @@ repeat:
24670 #endif
24671 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24672 pmd++, pmd_idx++) {
24673 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24674 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24675
24676 /*
24677 * Map with big pages if possible, otherwise
24678 * create normal page tables:
24679 */
24680 if (use_pse) {
24681 - unsigned int addr2;
24682 pgprot_t prot = PAGE_KERNEL_LARGE;
24683 /*
24684 * first pass will use the same initial
24685 @@ -310,11 +315,7 @@ repeat:
24686 __pgprot(PTE_IDENT_ATTR |
24687 _PAGE_PSE);
24688
24689 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24690 - PAGE_OFFSET + PAGE_SIZE-1;
24691 -
24692 - if (is_kernel_text(addr) ||
24693 - is_kernel_text(addr2))
24694 + if (is_kernel_text(address, address + PMD_SIZE))
24695 prot = PAGE_KERNEL_LARGE_EXEC;
24696
24697 pages_2m++;
24698 @@ -331,7 +332,7 @@ repeat:
24699 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24700 pte += pte_ofs;
24701 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24702 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24703 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24704 pgprot_t prot = PAGE_KERNEL;
24705 /*
24706 * first pass will use the same initial
24707 @@ -339,7 +340,7 @@ repeat:
24708 */
24709 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24710
24711 - if (is_kernel_text(addr))
24712 + if (is_kernel_text(address, address + PAGE_SIZE))
24713 prot = PAGE_KERNEL_EXEC;
24714
24715 pages_4k++;
24716 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24717
24718 pud = pud_offset(pgd, va);
24719 pmd = pmd_offset(pud, va);
24720 - if (!pmd_present(*pmd))
24721 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24722 break;
24723
24724 pte = pte_offset_kernel(pmd, va);
24725 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24726
24727 static void __init pagetable_init(void)
24728 {
24729 - pgd_t *pgd_base = swapper_pg_dir;
24730 -
24731 - permanent_kmaps_init(pgd_base);
24732 + permanent_kmaps_init(swapper_pg_dir);
24733 }
24734
24735 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24736 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24737 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24738
24739 /* user-defined highmem size */
24740 @@ -734,6 +733,12 @@ void __init mem_init(void)
24741
24742 pci_iommu_alloc();
24743
24744 +#ifdef CONFIG_PAX_PER_CPU_PGD
24745 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24746 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24747 + KERNEL_PGD_PTRS);
24748 +#endif
24749 +
24750 #ifdef CONFIG_FLATMEM
24751 BUG_ON(!mem_map);
24752 #endif
24753 @@ -760,7 +765,7 @@ void __init mem_init(void)
24754 reservedpages++;
24755
24756 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24757 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24758 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24759 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24760
24761 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24762 @@ -801,10 +806,10 @@ void __init mem_init(void)
24763 ((unsigned long)&__init_end -
24764 (unsigned long)&__init_begin) >> 10,
24765
24766 - (unsigned long)&_etext, (unsigned long)&_edata,
24767 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24768 + (unsigned long)&_sdata, (unsigned long)&_edata,
24769 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24770
24771 - (unsigned long)&_text, (unsigned long)&_etext,
24772 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24773 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24774
24775 /*
24776 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
24777 if (!kernel_set_to_readonly)
24778 return;
24779
24780 + start = ktla_ktva(start);
24781 pr_debug("Set kernel text: %lx - %lx for read write\n",
24782 start, start+size);
24783
24784 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
24785 if (!kernel_set_to_readonly)
24786 return;
24787
24788 + start = ktla_ktva(start);
24789 pr_debug("Set kernel text: %lx - %lx for read only\n",
24790 start, start+size);
24791
24792 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
24793 unsigned long start = PFN_ALIGN(_text);
24794 unsigned long size = PFN_ALIGN(_etext) - start;
24795
24796 + start = ktla_ktva(start);
24797 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24798 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24799 size >> 10);
24800 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24801 index 2b6b4a3..c17210d 100644
24802 --- a/arch/x86/mm/init_64.c
24803 +++ b/arch/x86/mm/init_64.c
24804 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24805 * around without checking the pgd every time.
24806 */
24807
24808 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24809 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24810 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24811
24812 int force_personality32;
24813 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24814
24815 for (address = start; address <= end; address += PGDIR_SIZE) {
24816 const pgd_t *pgd_ref = pgd_offset_k(address);
24817 +
24818 +#ifdef CONFIG_PAX_PER_CPU_PGD
24819 + unsigned long cpu;
24820 +#else
24821 struct page *page;
24822 +#endif
24823
24824 if (pgd_none(*pgd_ref))
24825 continue;
24826
24827 spin_lock(&pgd_lock);
24828 +
24829 +#ifdef CONFIG_PAX_PER_CPU_PGD
24830 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24831 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
24832 +#else
24833 list_for_each_entry(page, &pgd_list, lru) {
24834 pgd_t *pgd;
24835 spinlock_t *pgt_lock;
24836 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24837 /* the pgt_lock only for Xen */
24838 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24839 spin_lock(pgt_lock);
24840 +#endif
24841
24842 if (pgd_none(*pgd))
24843 set_pgd(pgd, *pgd_ref);
24844 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24845 BUG_ON(pgd_page_vaddr(*pgd)
24846 != pgd_page_vaddr(*pgd_ref));
24847
24848 +#ifndef CONFIG_PAX_PER_CPU_PGD
24849 spin_unlock(pgt_lock);
24850 +#endif
24851 +
24852 }
24853 spin_unlock(&pgd_lock);
24854 }
24855 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
24856 {
24857 if (pgd_none(*pgd)) {
24858 pud_t *pud = (pud_t *)spp_getpage();
24859 - pgd_populate(&init_mm, pgd, pud);
24860 + pgd_populate_kernel(&init_mm, pgd, pud);
24861 if (pud != pud_offset(pgd, 0))
24862 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
24863 pud, pud_offset(pgd, 0));
24864 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
24865 {
24866 if (pud_none(*pud)) {
24867 pmd_t *pmd = (pmd_t *) spp_getpage();
24868 - pud_populate(&init_mm, pud, pmd);
24869 + pud_populate_kernel(&init_mm, pud, pmd);
24870 if (pmd != pmd_offset(pud, 0))
24871 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
24872 pmd, pmd_offset(pud, 0));
24873 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
24874 pmd = fill_pmd(pud, vaddr);
24875 pte = fill_pte(pmd, vaddr);
24876
24877 + pax_open_kernel();
24878 set_pte(pte, new_pte);
24879 + pax_close_kernel();
24880
24881 /*
24882 * It's enough to flush this one mapping.
24883 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
24884 pgd = pgd_offset_k((unsigned long)__va(phys));
24885 if (pgd_none(*pgd)) {
24886 pud = (pud_t *) spp_getpage();
24887 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
24888 - _PAGE_USER));
24889 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
24890 }
24891 pud = pud_offset(pgd, (unsigned long)__va(phys));
24892 if (pud_none(*pud)) {
24893 pmd = (pmd_t *) spp_getpage();
24894 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
24895 - _PAGE_USER));
24896 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
24897 }
24898 pmd = pmd_offset(pud, phys);
24899 BUG_ON(!pmd_none(*pmd));
24900 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
24901 if (pfn >= pgt_buf_top)
24902 panic("alloc_low_page: ran out of memory");
24903
24904 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24905 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24906 clear_page(adr);
24907 *phys = pfn * PAGE_SIZE;
24908 return adr;
24909 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
24910
24911 phys = __pa(virt);
24912 left = phys & (PAGE_SIZE - 1);
24913 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24914 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24915 adr = (void *)(((unsigned long)adr) | left);
24916
24917 return adr;
24918 @@ -548,7 +562,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
24919 unmap_low_page(pmd);
24920
24921 spin_lock(&init_mm.page_table_lock);
24922 - pud_populate(&init_mm, pud, __va(pmd_phys));
24923 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
24924 spin_unlock(&init_mm.page_table_lock);
24925 }
24926 __flush_tlb_all();
24927 @@ -594,7 +608,7 @@ kernel_physical_mapping_init(unsigned long start,
24928 unmap_low_page(pud);
24929
24930 spin_lock(&init_mm.page_table_lock);
24931 - pgd_populate(&init_mm, pgd, __va(pud_phys));
24932 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
24933 spin_unlock(&init_mm.page_table_lock);
24934 pgd_changed = true;
24935 }
24936 @@ -686,6 +700,12 @@ void __init mem_init(void)
24937
24938 pci_iommu_alloc();
24939
24940 +#ifdef CONFIG_PAX_PER_CPU_PGD
24941 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24942 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24943 + KERNEL_PGD_PTRS);
24944 +#endif
24945 +
24946 /* clear_bss() already clear the empty_zero_page */
24947
24948 reservedpages = 0;
24949 @@ -846,8 +866,8 @@ int kern_addr_valid(unsigned long addr)
24950 static struct vm_area_struct gate_vma = {
24951 .vm_start = VSYSCALL_START,
24952 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
24953 - .vm_page_prot = PAGE_READONLY_EXEC,
24954 - .vm_flags = VM_READ | VM_EXEC
24955 + .vm_page_prot = PAGE_READONLY,
24956 + .vm_flags = VM_READ
24957 };
24958
24959 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
24960 @@ -881,7 +901,7 @@ int in_gate_area_no_mm(unsigned long addr)
24961
24962 const char *arch_vma_name(struct vm_area_struct *vma)
24963 {
24964 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24965 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24966 return "[vdso]";
24967 if (vma == &gate_vma)
24968 return "[vsyscall]";
24969 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
24970 index 7b179b4..6bd1777 100644
24971 --- a/arch/x86/mm/iomap_32.c
24972 +++ b/arch/x86/mm/iomap_32.c
24973 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
24974 type = kmap_atomic_idx_push();
24975 idx = type + KM_TYPE_NR * smp_processor_id();
24976 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24977 +
24978 + pax_open_kernel();
24979 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
24980 + pax_close_kernel();
24981 +
24982 arch_flush_lazy_mmu_mode();
24983
24984 return (void *)vaddr;
24985 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
24986 index 78fe3f1..8293b6f 100644
24987 --- a/arch/x86/mm/ioremap.c
24988 +++ b/arch/x86/mm/ioremap.c
24989 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
24990 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
24991 int is_ram = page_is_ram(pfn);
24992
24993 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
24994 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
24995 return NULL;
24996 WARN_ON_ONCE(is_ram);
24997 }
24998 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
24999
25000 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25001 if (page_is_ram(start >> PAGE_SHIFT))
25002 +#ifdef CONFIG_HIGHMEM
25003 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25004 +#endif
25005 return __va(phys);
25006
25007 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25008 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25009 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25010
25011 static __initdata int after_paging_init;
25012 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25013 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25014
25015 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25016 {
25017 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25018 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25019
25020 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25021 - memset(bm_pte, 0, sizeof(bm_pte));
25022 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25023 + pmd_populate_user(&init_mm, pmd, bm_pte);
25024
25025 /*
25026 * The boot-ioremap range spans multiple pmds, for which
25027 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25028 index d87dd6d..bf3fa66 100644
25029 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25030 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25031 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25032 * memory (e.g. tracked pages)? For now, we need this to avoid
25033 * invoking kmemcheck for PnP BIOS calls.
25034 */
25035 - if (regs->flags & X86_VM_MASK)
25036 + if (v8086_mode(regs))
25037 return false;
25038 - if (regs->cs != __KERNEL_CS)
25039 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25040 return false;
25041
25042 pte = kmemcheck_pte_lookup(address);
25043 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25044 index 845df68..1d8d29f 100644
25045 --- a/arch/x86/mm/mmap.c
25046 +++ b/arch/x86/mm/mmap.c
25047 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25048 * Leave an at least ~128 MB hole with possible stack randomization.
25049 */
25050 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25051 -#define MAX_GAP (TASK_SIZE/6*5)
25052 +#define MAX_GAP (pax_task_size/6*5)
25053
25054 static int mmap_is_legacy(void)
25055 {
25056 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25057 return rnd << PAGE_SHIFT;
25058 }
25059
25060 -static unsigned long mmap_base(void)
25061 +static unsigned long mmap_base(struct mm_struct *mm)
25062 {
25063 unsigned long gap = rlimit(RLIMIT_STACK);
25064 + unsigned long pax_task_size = TASK_SIZE;
25065 +
25066 +#ifdef CONFIG_PAX_SEGMEXEC
25067 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25068 + pax_task_size = SEGMEXEC_TASK_SIZE;
25069 +#endif
25070
25071 if (gap < MIN_GAP)
25072 gap = MIN_GAP;
25073 else if (gap > MAX_GAP)
25074 gap = MAX_GAP;
25075
25076 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25077 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25078 }
25079
25080 /*
25081 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25082 * does, but not when emulating X86_32
25083 */
25084 -static unsigned long mmap_legacy_base(void)
25085 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25086 {
25087 - if (mmap_is_ia32())
25088 + if (mmap_is_ia32()) {
25089 +
25090 +#ifdef CONFIG_PAX_SEGMEXEC
25091 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25092 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25093 + else
25094 +#endif
25095 +
25096 return TASK_UNMAPPED_BASE;
25097 - else
25098 + } else
25099 return TASK_UNMAPPED_BASE + mmap_rnd();
25100 }
25101
25102 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25103 void arch_pick_mmap_layout(struct mm_struct *mm)
25104 {
25105 if (mmap_is_legacy()) {
25106 - mm->mmap_base = mmap_legacy_base();
25107 + mm->mmap_base = mmap_legacy_base(mm);
25108 +
25109 +#ifdef CONFIG_PAX_RANDMMAP
25110 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25111 + mm->mmap_base += mm->delta_mmap;
25112 +#endif
25113 +
25114 mm->get_unmapped_area = arch_get_unmapped_area;
25115 mm->unmap_area = arch_unmap_area;
25116 } else {
25117 - mm->mmap_base = mmap_base();
25118 + mm->mmap_base = mmap_base(mm);
25119 +
25120 +#ifdef CONFIG_PAX_RANDMMAP
25121 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25122 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25123 +#endif
25124 +
25125 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25126 mm->unmap_area = arch_unmap_area_topdown;
25127 }
25128 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25129 index dc0b727..dc9d71a 100644
25130 --- a/arch/x86/mm/mmio-mod.c
25131 +++ b/arch/x86/mm/mmio-mod.c
25132 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25133 break;
25134 default:
25135 {
25136 - unsigned char *ip = (unsigned char *)instptr;
25137 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25138 my_trace->opcode = MMIO_UNKNOWN_OP;
25139 my_trace->width = 0;
25140 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25141 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25142 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25143 void __iomem *addr)
25144 {
25145 - static atomic_t next_id;
25146 + static atomic_unchecked_t next_id;
25147 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25148 /* These are page-unaligned. */
25149 struct mmiotrace_map map = {
25150 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25151 .private = trace
25152 },
25153 .phys = offset,
25154 - .id = atomic_inc_return(&next_id)
25155 + .id = atomic_inc_return_unchecked(&next_id)
25156 };
25157 map.map_id = trace->id;
25158
25159 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25160 index b008656..773eac2 100644
25161 --- a/arch/x86/mm/pageattr-test.c
25162 +++ b/arch/x86/mm/pageattr-test.c
25163 @@ -36,7 +36,7 @@ enum {
25164
25165 static int pte_testbit(pte_t pte)
25166 {
25167 - return pte_flags(pte) & _PAGE_UNUSED1;
25168 + return pte_flags(pte) & _PAGE_CPA_TEST;
25169 }
25170
25171 struct split_state {
25172 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25173 index a718e0d..45efc32 100644
25174 --- a/arch/x86/mm/pageattr.c
25175 +++ b/arch/x86/mm/pageattr.c
25176 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25177 */
25178 #ifdef CONFIG_PCI_BIOS
25179 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25180 - pgprot_val(forbidden) |= _PAGE_NX;
25181 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25182 #endif
25183
25184 /*
25185 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25186 * Does not cover __inittext since that is gone later on. On
25187 * 64bit we do not enforce !NX on the low mapping
25188 */
25189 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25190 - pgprot_val(forbidden) |= _PAGE_NX;
25191 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25192 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25193
25194 +#ifdef CONFIG_DEBUG_RODATA
25195 /*
25196 * The .rodata section needs to be read-only. Using the pfn
25197 * catches all aliases.
25198 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25199 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25200 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25201 pgprot_val(forbidden) |= _PAGE_RW;
25202 +#endif
25203
25204 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25205 /*
25206 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25207 }
25208 #endif
25209
25210 +#ifdef CONFIG_PAX_KERNEXEC
25211 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25212 + pgprot_val(forbidden) |= _PAGE_RW;
25213 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25214 + }
25215 +#endif
25216 +
25217 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25218
25219 return prot;
25220 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25221 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25222 {
25223 /* change init_mm */
25224 + pax_open_kernel();
25225 set_pte_atomic(kpte, pte);
25226 +
25227 #ifdef CONFIG_X86_32
25228 if (!SHARED_KERNEL_PMD) {
25229 +
25230 +#ifdef CONFIG_PAX_PER_CPU_PGD
25231 + unsigned long cpu;
25232 +#else
25233 struct page *page;
25234 +#endif
25235
25236 +#ifdef CONFIG_PAX_PER_CPU_PGD
25237 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25238 + pgd_t *pgd = get_cpu_pgd(cpu);
25239 +#else
25240 list_for_each_entry(page, &pgd_list, lru) {
25241 - pgd_t *pgd;
25242 + pgd_t *pgd = (pgd_t *)page_address(page);
25243 +#endif
25244 +
25245 pud_t *pud;
25246 pmd_t *pmd;
25247
25248 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25249 + pgd += pgd_index(address);
25250 pud = pud_offset(pgd, address);
25251 pmd = pmd_offset(pud, address);
25252 set_pte_atomic((pte_t *)pmd, pte);
25253 }
25254 }
25255 #endif
25256 + pax_close_kernel();
25257 }
25258
25259 static int
25260 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25261 index 3d68ef6..7f69136 100644
25262 --- a/arch/x86/mm/pat.c
25263 +++ b/arch/x86/mm/pat.c
25264 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25265
25266 if (!entry) {
25267 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25268 - current->comm, current->pid, start, end - 1);
25269 + current->comm, task_pid_nr(current), start, end - 1);
25270 return -EINVAL;
25271 }
25272
25273 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25274
25275 while (cursor < to) {
25276 if (!devmem_is_allowed(pfn)) {
25277 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25278 - current->comm, from, to - 1);
25279 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25280 + current->comm, from, to - 1, cursor);
25281 return 0;
25282 }
25283 cursor += PAGE_SIZE;
25284 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25285 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25286 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25287 "for [mem %#010Lx-%#010Lx]\n",
25288 - current->comm, current->pid,
25289 + current->comm, task_pid_nr(current),
25290 cattr_name(flags),
25291 base, (unsigned long long)(base + size-1));
25292 return -EINVAL;
25293 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25294 flags = lookup_memtype(paddr);
25295 if (want_flags != flags) {
25296 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25297 - current->comm, current->pid,
25298 + current->comm, task_pid_nr(current),
25299 cattr_name(want_flags),
25300 (unsigned long long)paddr,
25301 (unsigned long long)(paddr + size - 1),
25302 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25303 free_memtype(paddr, paddr + size);
25304 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25305 " for [mem %#010Lx-%#010Lx], got %s\n",
25306 - current->comm, current->pid,
25307 + current->comm, task_pid_nr(current),
25308 cattr_name(want_flags),
25309 (unsigned long long)paddr,
25310 (unsigned long long)(paddr + size - 1),
25311 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25312 index 9f0614d..92ae64a 100644
25313 --- a/arch/x86/mm/pf_in.c
25314 +++ b/arch/x86/mm/pf_in.c
25315 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25316 int i;
25317 enum reason_type rv = OTHERS;
25318
25319 - p = (unsigned char *)ins_addr;
25320 + p = (unsigned char *)ktla_ktva(ins_addr);
25321 p += skip_prefix(p, &prf);
25322 p += get_opcode(p, &opcode);
25323
25324 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25325 struct prefix_bits prf;
25326 int i;
25327
25328 - p = (unsigned char *)ins_addr;
25329 + p = (unsigned char *)ktla_ktva(ins_addr);
25330 p += skip_prefix(p, &prf);
25331 p += get_opcode(p, &opcode);
25332
25333 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25334 struct prefix_bits prf;
25335 int i;
25336
25337 - p = (unsigned char *)ins_addr;
25338 + p = (unsigned char *)ktla_ktva(ins_addr);
25339 p += skip_prefix(p, &prf);
25340 p += get_opcode(p, &opcode);
25341
25342 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25343 struct prefix_bits prf;
25344 int i;
25345
25346 - p = (unsigned char *)ins_addr;
25347 + p = (unsigned char *)ktla_ktva(ins_addr);
25348 p += skip_prefix(p, &prf);
25349 p += get_opcode(p, &opcode);
25350 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25351 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25352 struct prefix_bits prf;
25353 int i;
25354
25355 - p = (unsigned char *)ins_addr;
25356 + p = (unsigned char *)ktla_ktva(ins_addr);
25357 p += skip_prefix(p, &prf);
25358 p += get_opcode(p, &opcode);
25359 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25360 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25361 index 8573b83..4f3ed7e 100644
25362 --- a/arch/x86/mm/pgtable.c
25363 +++ b/arch/x86/mm/pgtable.c
25364 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25365 list_del(&page->lru);
25366 }
25367
25368 -#define UNSHARED_PTRS_PER_PGD \
25369 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25370 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25371 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25372
25373 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25374 +{
25375 + unsigned int count = USER_PGD_PTRS;
25376
25377 + while (count--)
25378 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25379 +}
25380 +#endif
25381 +
25382 +#ifdef CONFIG_PAX_PER_CPU_PGD
25383 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25384 +{
25385 + unsigned int count = USER_PGD_PTRS;
25386 +
25387 + while (count--) {
25388 + pgd_t pgd;
25389 +
25390 +#ifdef CONFIG_X86_64
25391 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25392 +#else
25393 + pgd = *src++;
25394 +#endif
25395 +
25396 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25397 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25398 +#endif
25399 +
25400 + *dst++ = pgd;
25401 + }
25402 +
25403 +}
25404 +#endif
25405 +
25406 +#ifdef CONFIG_X86_64
25407 +#define pxd_t pud_t
25408 +#define pyd_t pgd_t
25409 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25410 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25411 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25412 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25413 +#define PYD_SIZE PGDIR_SIZE
25414 +#else
25415 +#define pxd_t pmd_t
25416 +#define pyd_t pud_t
25417 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25418 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25419 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25420 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25421 +#define PYD_SIZE PUD_SIZE
25422 +#endif
25423 +
25424 +#ifdef CONFIG_PAX_PER_CPU_PGD
25425 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25426 +static inline void pgd_dtor(pgd_t *pgd) {}
25427 +#else
25428 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25429 {
25430 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25431 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25432 pgd_list_del(pgd);
25433 spin_unlock(&pgd_lock);
25434 }
25435 +#endif
25436
25437 /*
25438 * List of all pgd's needed for non-PAE so it can invalidate entries
25439 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25440 * -- wli
25441 */
25442
25443 -#ifdef CONFIG_X86_PAE
25444 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25445 /*
25446 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25447 * updating the top-level pagetable entries to guarantee the
25448 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25449 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25450 * and initialize the kernel pmds here.
25451 */
25452 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25453 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25454
25455 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25456 {
25457 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25458 */
25459 flush_tlb_mm(mm);
25460 }
25461 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25462 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25463 #else /* !CONFIG_X86_PAE */
25464
25465 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25466 -#define PREALLOCATED_PMDS 0
25467 +#define PREALLOCATED_PXDS 0
25468
25469 #endif /* CONFIG_X86_PAE */
25470
25471 -static void free_pmds(pmd_t *pmds[])
25472 +static void free_pxds(pxd_t *pxds[])
25473 {
25474 int i;
25475
25476 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25477 - if (pmds[i])
25478 - free_page((unsigned long)pmds[i]);
25479 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25480 + if (pxds[i])
25481 + free_page((unsigned long)pxds[i]);
25482 }
25483
25484 -static int preallocate_pmds(pmd_t *pmds[])
25485 +static int preallocate_pxds(pxd_t *pxds[])
25486 {
25487 int i;
25488 bool failed = false;
25489
25490 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25491 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25492 - if (pmd == NULL)
25493 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25494 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25495 + if (pxd == NULL)
25496 failed = true;
25497 - pmds[i] = pmd;
25498 + pxds[i] = pxd;
25499 }
25500
25501 if (failed) {
25502 - free_pmds(pmds);
25503 + free_pxds(pxds);
25504 return -ENOMEM;
25505 }
25506
25507 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25508 * preallocate which never got a corresponding vma will need to be
25509 * freed manually.
25510 */
25511 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25512 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25513 {
25514 int i;
25515
25516 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25517 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25518 pgd_t pgd = pgdp[i];
25519
25520 if (pgd_val(pgd) != 0) {
25521 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25522 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25523
25524 - pgdp[i] = native_make_pgd(0);
25525 + set_pgd(pgdp + i, native_make_pgd(0));
25526
25527 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25528 - pmd_free(mm, pmd);
25529 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25530 + pxd_free(mm, pxd);
25531 }
25532 }
25533 }
25534
25535 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25536 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25537 {
25538 - pud_t *pud;
25539 + pyd_t *pyd;
25540 unsigned long addr;
25541 int i;
25542
25543 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25544 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25545 return;
25546
25547 - pud = pud_offset(pgd, 0);
25548 +#ifdef CONFIG_X86_64
25549 + pyd = pyd_offset(mm, 0L);
25550 +#else
25551 + pyd = pyd_offset(pgd, 0L);
25552 +#endif
25553
25554 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25555 - i++, pud++, addr += PUD_SIZE) {
25556 - pmd_t *pmd = pmds[i];
25557 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25558 + i++, pyd++, addr += PYD_SIZE) {
25559 + pxd_t *pxd = pxds[i];
25560
25561 if (i >= KERNEL_PGD_BOUNDARY)
25562 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25563 - sizeof(pmd_t) * PTRS_PER_PMD);
25564 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25565 + sizeof(pxd_t) * PTRS_PER_PMD);
25566
25567 - pud_populate(mm, pud, pmd);
25568 + pyd_populate(mm, pyd, pxd);
25569 }
25570 }
25571
25572 pgd_t *pgd_alloc(struct mm_struct *mm)
25573 {
25574 pgd_t *pgd;
25575 - pmd_t *pmds[PREALLOCATED_PMDS];
25576 + pxd_t *pxds[PREALLOCATED_PXDS];
25577
25578 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25579
25580 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25581
25582 mm->pgd = pgd;
25583
25584 - if (preallocate_pmds(pmds) != 0)
25585 + if (preallocate_pxds(pxds) != 0)
25586 goto out_free_pgd;
25587
25588 if (paravirt_pgd_alloc(mm) != 0)
25589 - goto out_free_pmds;
25590 + goto out_free_pxds;
25591
25592 /*
25593 * Make sure that pre-populating the pmds is atomic with
25594 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25595 spin_lock(&pgd_lock);
25596
25597 pgd_ctor(mm, pgd);
25598 - pgd_prepopulate_pmd(mm, pgd, pmds);
25599 + pgd_prepopulate_pxd(mm, pgd, pxds);
25600
25601 spin_unlock(&pgd_lock);
25602
25603 return pgd;
25604
25605 -out_free_pmds:
25606 - free_pmds(pmds);
25607 +out_free_pxds:
25608 + free_pxds(pxds);
25609 out_free_pgd:
25610 free_page((unsigned long)pgd);
25611 out:
25612 @@ -295,7 +356,7 @@ out:
25613
25614 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25615 {
25616 - pgd_mop_up_pmds(mm, pgd);
25617 + pgd_mop_up_pxds(mm, pgd);
25618 pgd_dtor(pgd);
25619 paravirt_pgd_free(mm, pgd);
25620 free_page((unsigned long)pgd);
25621 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25622 index a69bcb8..19068ab 100644
25623 --- a/arch/x86/mm/pgtable_32.c
25624 +++ b/arch/x86/mm/pgtable_32.c
25625 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25626 return;
25627 }
25628 pte = pte_offset_kernel(pmd, vaddr);
25629 +
25630 + pax_open_kernel();
25631 if (pte_val(pteval))
25632 set_pte_at(&init_mm, vaddr, pte, pteval);
25633 else
25634 pte_clear(&init_mm, vaddr, pte);
25635 + pax_close_kernel();
25636
25637 /*
25638 * It's enough to flush this one mapping.
25639 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25640 index 410531d..0f16030 100644
25641 --- a/arch/x86/mm/setup_nx.c
25642 +++ b/arch/x86/mm/setup_nx.c
25643 @@ -5,8 +5,10 @@
25644 #include <asm/pgtable.h>
25645 #include <asm/proto.h>
25646
25647 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25648 static int disable_nx __cpuinitdata;
25649
25650 +#ifndef CONFIG_PAX_PAGEEXEC
25651 /*
25652 * noexec = on|off
25653 *
25654 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25655 return 0;
25656 }
25657 early_param("noexec", noexec_setup);
25658 +#endif
25659 +
25660 +#endif
25661
25662 void __cpuinit x86_configure_nx(void)
25663 {
25664 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25665 if (cpu_has_nx && !disable_nx)
25666 __supported_pte_mask |= _PAGE_NX;
25667 else
25668 +#endif
25669 __supported_pte_mask &= ~_PAGE_NX;
25670 }
25671
25672 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25673 index 5e57e11..64874249 100644
25674 --- a/arch/x86/mm/tlb.c
25675 +++ b/arch/x86/mm/tlb.c
25676 @@ -66,7 +66,11 @@ void leave_mm(int cpu)
25677 BUG();
25678 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25679 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25680 +
25681 +#ifndef CONFIG_PAX_PER_CPU_PGD
25682 load_cr3(swapper_pg_dir);
25683 +#endif
25684 +
25685 }
25686 }
25687 EXPORT_SYMBOL_GPL(leave_mm);
25688 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25689 index 877b9a1..a8ecf42 100644
25690 --- a/arch/x86/net/bpf_jit.S
25691 +++ b/arch/x86/net/bpf_jit.S
25692 @@ -9,6 +9,7 @@
25693 */
25694 #include <linux/linkage.h>
25695 #include <asm/dwarf2.h>
25696 +#include <asm/alternative-asm.h>
25697
25698 /*
25699 * Calling convention :
25700 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25701 jle bpf_slow_path_word
25702 mov (SKBDATA,%rsi),%eax
25703 bswap %eax /* ntohl() */
25704 + pax_force_retaddr
25705 ret
25706
25707 sk_load_half:
25708 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25709 jle bpf_slow_path_half
25710 movzwl (SKBDATA,%rsi),%eax
25711 rol $8,%ax # ntohs()
25712 + pax_force_retaddr
25713 ret
25714
25715 sk_load_byte:
25716 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25717 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25718 jle bpf_slow_path_byte
25719 movzbl (SKBDATA,%rsi),%eax
25720 + pax_force_retaddr
25721 ret
25722
25723 /**
25724 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25725 movzbl (SKBDATA,%rsi),%ebx
25726 and $15,%bl
25727 shl $2,%bl
25728 + pax_force_retaddr
25729 ret
25730
25731 /* rsi contains offset and can be scratched */
25732 @@ -109,6 +114,7 @@ bpf_slow_path_word:
25733 js bpf_error
25734 mov -12(%rbp),%eax
25735 bswap %eax
25736 + pax_force_retaddr
25737 ret
25738
25739 bpf_slow_path_half:
25740 @@ -117,12 +123,14 @@ bpf_slow_path_half:
25741 mov -12(%rbp),%ax
25742 rol $8,%ax
25743 movzwl %ax,%eax
25744 + pax_force_retaddr
25745 ret
25746
25747 bpf_slow_path_byte:
25748 bpf_slow_path_common(1)
25749 js bpf_error
25750 movzbl -12(%rbp),%eax
25751 + pax_force_retaddr
25752 ret
25753
25754 bpf_slow_path_byte_msh:
25755 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25756 and $15,%al
25757 shl $2,%al
25758 xchg %eax,%ebx
25759 + pax_force_retaddr
25760 ret
25761
25762 #define sk_negative_common(SIZE) \
25763 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
25764 sk_negative_common(4)
25765 mov (%rax), %eax
25766 bswap %eax
25767 + pax_force_retaddr
25768 ret
25769
25770 bpf_slow_path_half_neg:
25771 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
25772 mov (%rax),%ax
25773 rol $8,%ax
25774 movzwl %ax,%eax
25775 + pax_force_retaddr
25776 ret
25777
25778 bpf_slow_path_byte_neg:
25779 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
25780 .globl sk_load_byte_negative_offset
25781 sk_negative_common(1)
25782 movzbl (%rax), %eax
25783 + pax_force_retaddr
25784 ret
25785
25786 bpf_slow_path_byte_msh_neg:
25787 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
25788 and $15,%al
25789 shl $2,%al
25790 xchg %eax,%ebx
25791 + pax_force_retaddr
25792 ret
25793
25794 bpf_error:
25795 @@ -197,4 +210,5 @@ bpf_error:
25796 xor %eax,%eax
25797 mov -8(%rbp),%rbx
25798 leaveq
25799 + pax_force_retaddr
25800 ret
25801 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25802 index 0597f95..a12c36e 100644
25803 --- a/arch/x86/net/bpf_jit_comp.c
25804 +++ b/arch/x86/net/bpf_jit_comp.c
25805 @@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
25806 set_fs(old_fs);
25807 }
25808
25809 +struct bpf_jit_work {
25810 + struct work_struct work;
25811 + void *image;
25812 +};
25813 +
25814 #define CHOOSE_LOAD_FUNC(K, func) \
25815 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
25816
25817 @@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25818 if (addrs == NULL)
25819 return;
25820
25821 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25822 + if (!fp->work)
25823 + goto out;
25824 +
25825 /* Before first pass, make a rough estimation of addrs[]
25826 * each bpf instruction is translated to less than 64 bytes
25827 */
25828 @@ -589,17 +598,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25829 break;
25830 default:
25831 /* hmm, too complex filter, give up with jit compiler */
25832 - goto out;
25833 + goto error;
25834 }
25835 ilen = prog - temp;
25836 if (image) {
25837 if (unlikely(proglen + ilen > oldproglen)) {
25838 pr_err("bpb_jit_compile fatal error\n");
25839 - kfree(addrs);
25840 - module_free(NULL, image);
25841 - return;
25842 + module_free_exec(NULL, image);
25843 + goto error;
25844 }
25845 + pax_open_kernel();
25846 memcpy(image + proglen, temp, ilen);
25847 + pax_close_kernel();
25848 }
25849 proglen += ilen;
25850 addrs[i] = proglen;
25851 @@ -620,11 +630,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25852 break;
25853 }
25854 if (proglen == oldproglen) {
25855 - image = module_alloc(max_t(unsigned int,
25856 - proglen,
25857 - sizeof(struct work_struct)));
25858 + image = module_alloc_exec(proglen);
25859 if (!image)
25860 - goto out;
25861 + goto error;
25862 }
25863 oldproglen = proglen;
25864 }
25865 @@ -640,7 +648,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25866 bpf_flush_icache(image, image + proglen);
25867
25868 fp->bpf_func = (void *)image;
25869 - }
25870 + } else
25871 +error:
25872 + kfree(fp->work);
25873 +
25874 out:
25875 kfree(addrs);
25876 return;
25877 @@ -648,18 +659,20 @@ out:
25878
25879 static void jit_free_defer(struct work_struct *arg)
25880 {
25881 - module_free(NULL, arg);
25882 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
25883 + kfree(arg);
25884 }
25885
25886 /* run from softirq, we must use a work_struct to call
25887 - * module_free() from process context
25888 + * module_free_exec() from process context
25889 */
25890 void bpf_jit_free(struct sk_filter *fp)
25891 {
25892 if (fp->bpf_func != sk_run_filter) {
25893 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
25894 + struct work_struct *work = &fp->work->work;
25895
25896 INIT_WORK(work, jit_free_defer);
25897 + fp->work->image = fp->bpf_func;
25898 schedule_work(work);
25899 }
25900 }
25901 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
25902 index d6aa6e8..266395a 100644
25903 --- a/arch/x86/oprofile/backtrace.c
25904 +++ b/arch/x86/oprofile/backtrace.c
25905 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
25906 struct stack_frame_ia32 *fp;
25907 unsigned long bytes;
25908
25909 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25910 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25911 if (bytes != sizeof(bufhead))
25912 return NULL;
25913
25914 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
25915 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
25916
25917 oprofile_add_trace(bufhead[0].return_address);
25918
25919 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
25920 struct stack_frame bufhead[2];
25921 unsigned long bytes;
25922
25923 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25924 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25925 if (bytes != sizeof(bufhead))
25926 return NULL;
25927
25928 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
25929 {
25930 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
25931
25932 - if (!user_mode_vm(regs)) {
25933 + if (!user_mode(regs)) {
25934 unsigned long stack = kernel_stack_pointer(regs);
25935 if (depth)
25936 dump_trace(NULL, regs, (unsigned long *)stack, 0,
25937 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
25938 index 140942f..8a5cc55 100644
25939 --- a/arch/x86/pci/mrst.c
25940 +++ b/arch/x86/pci/mrst.c
25941 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
25942 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
25943 pci_mmcfg_late_init();
25944 pcibios_enable_irq = mrst_pci_irq_enable;
25945 - pci_root_ops = pci_mrst_ops;
25946 + pax_open_kernel();
25947 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
25948 + pax_close_kernel();
25949 pci_soc_mode = 1;
25950 /* Continue with standard init */
25951 return 1;
25952 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
25953 index da8fe05..7ee6704 100644
25954 --- a/arch/x86/pci/pcbios.c
25955 +++ b/arch/x86/pci/pcbios.c
25956 @@ -79,50 +79,93 @@ union bios32 {
25957 static struct {
25958 unsigned long address;
25959 unsigned short segment;
25960 -} bios32_indirect = { 0, __KERNEL_CS };
25961 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
25962
25963 /*
25964 * Returns the entry point for the given service, NULL on error
25965 */
25966
25967 -static unsigned long bios32_service(unsigned long service)
25968 +static unsigned long __devinit bios32_service(unsigned long service)
25969 {
25970 unsigned char return_code; /* %al */
25971 unsigned long address; /* %ebx */
25972 unsigned long length; /* %ecx */
25973 unsigned long entry; /* %edx */
25974 unsigned long flags;
25975 + struct desc_struct d, *gdt;
25976
25977 local_irq_save(flags);
25978 - __asm__("lcall *(%%edi); cld"
25979 +
25980 + gdt = get_cpu_gdt_table(smp_processor_id());
25981 +
25982 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
25983 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25984 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
25985 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25986 +
25987 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
25988 : "=a" (return_code),
25989 "=b" (address),
25990 "=c" (length),
25991 "=d" (entry)
25992 : "0" (service),
25993 "1" (0),
25994 - "D" (&bios32_indirect));
25995 + "D" (&bios32_indirect),
25996 + "r"(__PCIBIOS_DS)
25997 + : "memory");
25998 +
25999 + pax_open_kernel();
26000 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26001 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26002 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26003 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26004 + pax_close_kernel();
26005 +
26006 local_irq_restore(flags);
26007
26008 switch (return_code) {
26009 - case 0:
26010 - return address + entry;
26011 - case 0x80: /* Not present */
26012 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26013 - return 0;
26014 - default: /* Shouldn't happen */
26015 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26016 - service, return_code);
26017 + case 0: {
26018 + int cpu;
26019 + unsigned char flags;
26020 +
26021 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26022 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26023 + printk(KERN_WARNING "bios32_service: not valid\n");
26024 return 0;
26025 + }
26026 + address = address + PAGE_OFFSET;
26027 + length += 16UL; /* some BIOSs underreport this... */
26028 + flags = 4;
26029 + if (length >= 64*1024*1024) {
26030 + length >>= PAGE_SHIFT;
26031 + flags |= 8;
26032 + }
26033 +
26034 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26035 + gdt = get_cpu_gdt_table(cpu);
26036 + pack_descriptor(&d, address, length, 0x9b, flags);
26037 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26038 + pack_descriptor(&d, address, length, 0x93, flags);
26039 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26040 + }
26041 + return entry;
26042 + }
26043 + case 0x80: /* Not present */
26044 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26045 + return 0;
26046 + default: /* Shouldn't happen */
26047 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26048 + service, return_code);
26049 + return 0;
26050 }
26051 }
26052
26053 static struct {
26054 unsigned long address;
26055 unsigned short segment;
26056 -} pci_indirect = { 0, __KERNEL_CS };
26057 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26058
26059 -static int pci_bios_present;
26060 +static int pci_bios_present __read_only;
26061
26062 static int __devinit check_pcibios(void)
26063 {
26064 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26065 unsigned long flags, pcibios_entry;
26066
26067 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26068 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26069 + pci_indirect.address = pcibios_entry;
26070
26071 local_irq_save(flags);
26072 - __asm__(
26073 - "lcall *(%%edi); cld\n\t"
26074 + __asm__("movw %w6, %%ds\n\t"
26075 + "lcall *%%ss:(%%edi); cld\n\t"
26076 + "push %%ss\n\t"
26077 + "pop %%ds\n\t"
26078 "jc 1f\n\t"
26079 "xor %%ah, %%ah\n"
26080 "1:"
26081 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26082 "=b" (ebx),
26083 "=c" (ecx)
26084 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26085 - "D" (&pci_indirect)
26086 + "D" (&pci_indirect),
26087 + "r" (__PCIBIOS_DS)
26088 : "memory");
26089 local_irq_restore(flags);
26090
26091 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26092
26093 switch (len) {
26094 case 1:
26095 - __asm__("lcall *(%%esi); cld\n\t"
26096 + __asm__("movw %w6, %%ds\n\t"
26097 + "lcall *%%ss:(%%esi); cld\n\t"
26098 + "push %%ss\n\t"
26099 + "pop %%ds\n\t"
26100 "jc 1f\n\t"
26101 "xor %%ah, %%ah\n"
26102 "1:"
26103 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26104 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26105 "b" (bx),
26106 "D" ((long)reg),
26107 - "S" (&pci_indirect));
26108 + "S" (&pci_indirect),
26109 + "r" (__PCIBIOS_DS));
26110 /*
26111 * Zero-extend the result beyond 8 bits, do not trust the
26112 * BIOS having done it:
26113 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26114 *value &= 0xff;
26115 break;
26116 case 2:
26117 - __asm__("lcall *(%%esi); cld\n\t"
26118 + __asm__("movw %w6, %%ds\n\t"
26119 + "lcall *%%ss:(%%esi); cld\n\t"
26120 + "push %%ss\n\t"
26121 + "pop %%ds\n\t"
26122 "jc 1f\n\t"
26123 "xor %%ah, %%ah\n"
26124 "1:"
26125 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26126 : "1" (PCIBIOS_READ_CONFIG_WORD),
26127 "b" (bx),
26128 "D" ((long)reg),
26129 - "S" (&pci_indirect));
26130 + "S" (&pci_indirect),
26131 + "r" (__PCIBIOS_DS));
26132 /*
26133 * Zero-extend the result beyond 16 bits, do not trust the
26134 * BIOS having done it:
26135 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26136 *value &= 0xffff;
26137 break;
26138 case 4:
26139 - __asm__("lcall *(%%esi); cld\n\t"
26140 + __asm__("movw %w6, %%ds\n\t"
26141 + "lcall *%%ss:(%%esi); cld\n\t"
26142 + "push %%ss\n\t"
26143 + "pop %%ds\n\t"
26144 "jc 1f\n\t"
26145 "xor %%ah, %%ah\n"
26146 "1:"
26147 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26148 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26149 "b" (bx),
26150 "D" ((long)reg),
26151 - "S" (&pci_indirect));
26152 + "S" (&pci_indirect),
26153 + "r" (__PCIBIOS_DS));
26154 break;
26155 }
26156
26157 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26158
26159 switch (len) {
26160 case 1:
26161 - __asm__("lcall *(%%esi); cld\n\t"
26162 + __asm__("movw %w6, %%ds\n\t"
26163 + "lcall *%%ss:(%%esi); cld\n\t"
26164 + "push %%ss\n\t"
26165 + "pop %%ds\n\t"
26166 "jc 1f\n\t"
26167 "xor %%ah, %%ah\n"
26168 "1:"
26169 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26170 "c" (value),
26171 "b" (bx),
26172 "D" ((long)reg),
26173 - "S" (&pci_indirect));
26174 + "S" (&pci_indirect),
26175 + "r" (__PCIBIOS_DS));
26176 break;
26177 case 2:
26178 - __asm__("lcall *(%%esi); cld\n\t"
26179 + __asm__("movw %w6, %%ds\n\t"
26180 + "lcall *%%ss:(%%esi); cld\n\t"
26181 + "push %%ss\n\t"
26182 + "pop %%ds\n\t"
26183 "jc 1f\n\t"
26184 "xor %%ah, %%ah\n"
26185 "1:"
26186 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26187 "c" (value),
26188 "b" (bx),
26189 "D" ((long)reg),
26190 - "S" (&pci_indirect));
26191 + "S" (&pci_indirect),
26192 + "r" (__PCIBIOS_DS));
26193 break;
26194 case 4:
26195 - __asm__("lcall *(%%esi); cld\n\t"
26196 + __asm__("movw %w6, %%ds\n\t"
26197 + "lcall *%%ss:(%%esi); cld\n\t"
26198 + "push %%ss\n\t"
26199 + "pop %%ds\n\t"
26200 "jc 1f\n\t"
26201 "xor %%ah, %%ah\n"
26202 "1:"
26203 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26204 "c" (value),
26205 "b" (bx),
26206 "D" ((long)reg),
26207 - "S" (&pci_indirect));
26208 + "S" (&pci_indirect),
26209 + "r" (__PCIBIOS_DS));
26210 break;
26211 }
26212
26213 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26214
26215 DBG("PCI: Fetching IRQ routing table... ");
26216 __asm__("push %%es\n\t"
26217 + "movw %w8, %%ds\n\t"
26218 "push %%ds\n\t"
26219 "pop %%es\n\t"
26220 - "lcall *(%%esi); cld\n\t"
26221 + "lcall *%%ss:(%%esi); cld\n\t"
26222 "pop %%es\n\t"
26223 + "push %%ss\n\t"
26224 + "pop %%ds\n"
26225 "jc 1f\n\t"
26226 "xor %%ah, %%ah\n"
26227 "1:"
26228 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26229 "1" (0),
26230 "D" ((long) &opt),
26231 "S" (&pci_indirect),
26232 - "m" (opt)
26233 + "m" (opt),
26234 + "r" (__PCIBIOS_DS)
26235 : "memory");
26236 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26237 if (ret & 0xff00)
26238 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26239 {
26240 int ret;
26241
26242 - __asm__("lcall *(%%esi); cld\n\t"
26243 + __asm__("movw %w5, %%ds\n\t"
26244 + "lcall *%%ss:(%%esi); cld\n\t"
26245 + "push %%ss\n\t"
26246 + "pop %%ds\n"
26247 "jc 1f\n\t"
26248 "xor %%ah, %%ah\n"
26249 "1:"
26250 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26251 : "0" (PCIBIOS_SET_PCI_HW_INT),
26252 "b" ((dev->bus->number << 8) | dev->devfn),
26253 "c" ((irq << 8) | (pin + 10)),
26254 - "S" (&pci_indirect));
26255 + "S" (&pci_indirect),
26256 + "r" (__PCIBIOS_DS));
26257 return !(ret & 0xff00);
26258 }
26259 EXPORT_SYMBOL(pcibios_set_irq_routing);
26260 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26261 index 40e4469..1ab536e 100644
26262 --- a/arch/x86/platform/efi/efi_32.c
26263 +++ b/arch/x86/platform/efi/efi_32.c
26264 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26265 {
26266 struct desc_ptr gdt_descr;
26267
26268 +#ifdef CONFIG_PAX_KERNEXEC
26269 + struct desc_struct d;
26270 +#endif
26271 +
26272 local_irq_save(efi_rt_eflags);
26273
26274 load_cr3(initial_page_table);
26275 __flush_tlb_all();
26276
26277 +#ifdef CONFIG_PAX_KERNEXEC
26278 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26279 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26280 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26281 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26282 +#endif
26283 +
26284 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26285 gdt_descr.size = GDT_SIZE - 1;
26286 load_gdt(&gdt_descr);
26287 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26288 {
26289 struct desc_ptr gdt_descr;
26290
26291 +#ifdef CONFIG_PAX_KERNEXEC
26292 + struct desc_struct d;
26293 +
26294 + memset(&d, 0, sizeof d);
26295 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26296 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26297 +#endif
26298 +
26299 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26300 gdt_descr.size = GDT_SIZE - 1;
26301 load_gdt(&gdt_descr);
26302 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26303 index fbe66e6..eae5e38 100644
26304 --- a/arch/x86/platform/efi/efi_stub_32.S
26305 +++ b/arch/x86/platform/efi/efi_stub_32.S
26306 @@ -6,7 +6,9 @@
26307 */
26308
26309 #include <linux/linkage.h>
26310 +#include <linux/init.h>
26311 #include <asm/page_types.h>
26312 +#include <asm/segment.h>
26313
26314 /*
26315 * efi_call_phys(void *, ...) is a function with variable parameters.
26316 @@ -20,7 +22,7 @@
26317 * service functions will comply with gcc calling convention, too.
26318 */
26319
26320 -.text
26321 +__INIT
26322 ENTRY(efi_call_phys)
26323 /*
26324 * 0. The function can only be called in Linux kernel. So CS has been
26325 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26326 * The mapping of lower virtual memory has been created in prelog and
26327 * epilog.
26328 */
26329 - movl $1f, %edx
26330 - subl $__PAGE_OFFSET, %edx
26331 - jmp *%edx
26332 +#ifdef CONFIG_PAX_KERNEXEC
26333 + movl $(__KERNEXEC_EFI_DS), %edx
26334 + mov %edx, %ds
26335 + mov %edx, %es
26336 + mov %edx, %ss
26337 + addl $2f,(1f)
26338 + ljmp *(1f)
26339 +
26340 +__INITDATA
26341 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26342 +.previous
26343 +
26344 +2:
26345 + subl $2b,(1b)
26346 +#else
26347 + jmp 1f-__PAGE_OFFSET
26348 1:
26349 +#endif
26350
26351 /*
26352 * 2. Now on the top of stack is the return
26353 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26354 * parameter 2, ..., param n. To make things easy, we save the return
26355 * address of efi_call_phys in a global variable.
26356 */
26357 - popl %edx
26358 - movl %edx, saved_return_addr
26359 - /* get the function pointer into ECX*/
26360 - popl %ecx
26361 - movl %ecx, efi_rt_function_ptr
26362 - movl $2f, %edx
26363 - subl $__PAGE_OFFSET, %edx
26364 - pushl %edx
26365 + popl (saved_return_addr)
26366 + popl (efi_rt_function_ptr)
26367
26368 /*
26369 * 3. Clear PG bit in %CR0.
26370 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26371 /*
26372 * 5. Call the physical function.
26373 */
26374 - jmp *%ecx
26375 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26376
26377 -2:
26378 /*
26379 * 6. After EFI runtime service returns, control will return to
26380 * following instruction. We'd better readjust stack pointer first.
26381 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26382 movl %cr0, %edx
26383 orl $0x80000000, %edx
26384 movl %edx, %cr0
26385 - jmp 1f
26386 -1:
26387 +
26388 /*
26389 * 8. Now restore the virtual mode from flat mode by
26390 * adding EIP with PAGE_OFFSET.
26391 */
26392 - movl $1f, %edx
26393 - jmp *%edx
26394 +#ifdef CONFIG_PAX_KERNEXEC
26395 + movl $(__KERNEL_DS), %edx
26396 + mov %edx, %ds
26397 + mov %edx, %es
26398 + mov %edx, %ss
26399 + ljmp $(__KERNEL_CS),$1f
26400 +#else
26401 + jmp 1f+__PAGE_OFFSET
26402 +#endif
26403 1:
26404
26405 /*
26406 * 9. Balance the stack. And because EAX contain the return value,
26407 * we'd better not clobber it.
26408 */
26409 - leal efi_rt_function_ptr, %edx
26410 - movl (%edx), %ecx
26411 - pushl %ecx
26412 + pushl (efi_rt_function_ptr)
26413
26414 /*
26415 - * 10. Push the saved return address onto the stack and return.
26416 + * 10. Return to the saved return address.
26417 */
26418 - leal saved_return_addr, %edx
26419 - movl (%edx), %ecx
26420 - pushl %ecx
26421 - ret
26422 + jmpl *(saved_return_addr)
26423 ENDPROC(efi_call_phys)
26424 .previous
26425
26426 -.data
26427 +__INITDATA
26428 saved_return_addr:
26429 .long 0
26430 efi_rt_function_ptr:
26431 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26432 index 4c07cca..2c8427d 100644
26433 --- a/arch/x86/platform/efi/efi_stub_64.S
26434 +++ b/arch/x86/platform/efi/efi_stub_64.S
26435 @@ -7,6 +7,7 @@
26436 */
26437
26438 #include <linux/linkage.h>
26439 +#include <asm/alternative-asm.h>
26440
26441 #define SAVE_XMM \
26442 mov %rsp, %rax; \
26443 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26444 call *%rdi
26445 addq $32, %rsp
26446 RESTORE_XMM
26447 + pax_force_retaddr 0, 1
26448 ret
26449 ENDPROC(efi_call0)
26450
26451 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26452 call *%rdi
26453 addq $32, %rsp
26454 RESTORE_XMM
26455 + pax_force_retaddr 0, 1
26456 ret
26457 ENDPROC(efi_call1)
26458
26459 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26460 call *%rdi
26461 addq $32, %rsp
26462 RESTORE_XMM
26463 + pax_force_retaddr 0, 1
26464 ret
26465 ENDPROC(efi_call2)
26466
26467 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26468 call *%rdi
26469 addq $32, %rsp
26470 RESTORE_XMM
26471 + pax_force_retaddr 0, 1
26472 ret
26473 ENDPROC(efi_call3)
26474
26475 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26476 call *%rdi
26477 addq $32, %rsp
26478 RESTORE_XMM
26479 + pax_force_retaddr 0, 1
26480 ret
26481 ENDPROC(efi_call4)
26482
26483 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26484 call *%rdi
26485 addq $48, %rsp
26486 RESTORE_XMM
26487 + pax_force_retaddr 0, 1
26488 ret
26489 ENDPROC(efi_call5)
26490
26491 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26492 call *%rdi
26493 addq $48, %rsp
26494 RESTORE_XMM
26495 + pax_force_retaddr 0, 1
26496 ret
26497 ENDPROC(efi_call6)
26498 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26499 index fd41a92..9c33628 100644
26500 --- a/arch/x86/platform/mrst/mrst.c
26501 +++ b/arch/x86/platform/mrst/mrst.c
26502 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26503 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26504 int sfi_mrtc_num;
26505
26506 -static void mrst_power_off(void)
26507 +static __noreturn void mrst_power_off(void)
26508 {
26509 + BUG();
26510 }
26511
26512 -static void mrst_reboot(void)
26513 +static __noreturn void mrst_reboot(void)
26514 {
26515 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26516 + BUG();
26517 }
26518
26519 /* parse all the mtimer info to a static mtimer array */
26520 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26521 index 218cdb1..fd55c08 100644
26522 --- a/arch/x86/power/cpu.c
26523 +++ b/arch/x86/power/cpu.c
26524 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
26525 static void fix_processor_context(void)
26526 {
26527 int cpu = smp_processor_id();
26528 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26529 + struct tss_struct *t = init_tss + cpu;
26530
26531 set_tss_desc(cpu, t); /*
26532 * This just modifies memory; should not be
26533 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
26534 */
26535
26536 #ifdef CONFIG_X86_64
26537 + pax_open_kernel();
26538 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26539 + pax_close_kernel();
26540
26541 syscall_init(); /* This sets MSR_*STAR and related */
26542 #endif
26543 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26544 index cbca565..35ce1d7 100644
26545 --- a/arch/x86/realmode/init.c
26546 +++ b/arch/x86/realmode/init.c
26547 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26548 __va(real_mode_header->trampoline_header);
26549
26550 #ifdef CONFIG_X86_32
26551 - trampoline_header->start = __pa(startup_32_smp);
26552 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26553 +
26554 +#ifdef CONFIG_PAX_KERNEXEC
26555 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26556 +#endif
26557 +
26558 + trampoline_header->boot_cs = __BOOT_CS;
26559 trampoline_header->gdt_limit = __BOOT_DS + 7;
26560 trampoline_header->gdt_base = __pa(boot_gdt);
26561 #else
26562 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26563 index 5b84a2d..a004393 100644
26564 --- a/arch/x86/realmode/rm/Makefile
26565 +++ b/arch/x86/realmode/rm/Makefile
26566 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26567 $(call cc-option, -fno-unit-at-a-time)) \
26568 $(call cc-option, -fno-stack-protector) \
26569 $(call cc-option, -mpreferred-stack-boundary=2)
26570 +ifdef CONSTIFY_PLUGIN
26571 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
26572 +endif
26573 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26574 GCOV_PROFILE := n
26575 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26576 index c1b2791..f9e31c7 100644
26577 --- a/arch/x86/realmode/rm/trampoline_32.S
26578 +++ b/arch/x86/realmode/rm/trampoline_32.S
26579 @@ -25,6 +25,12 @@
26580 #include <asm/page_types.h>
26581 #include "realmode.h"
26582
26583 +#ifdef CONFIG_PAX_KERNEXEC
26584 +#define ta(X) (X)
26585 +#else
26586 +#define ta(X) (pa_ ## X)
26587 +#endif
26588 +
26589 .text
26590 .code16
26591
26592 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26593
26594 cli # We should be safe anyway
26595
26596 - movl tr_start, %eax # where we need to go
26597 -
26598 movl $0xA5A5A5A5, trampoline_status
26599 # write marker for master knows we're running
26600
26601 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26602 movw $1, %dx # protected mode (PE) bit
26603 lmsw %dx # into protected mode
26604
26605 - ljmpl $__BOOT_CS, $pa_startup_32
26606 + ljmpl *(trampoline_header)
26607
26608 .section ".text32","ax"
26609 .code32
26610 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26611 .balign 8
26612 GLOBAL(trampoline_header)
26613 tr_start: .space 4
26614 - tr_gdt_pad: .space 2
26615 + tr_boot_cs: .space 2
26616 tr_gdt: .space 6
26617 END(trampoline_header)
26618
26619 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26620 index bb360dc..3e5945f 100644
26621 --- a/arch/x86/realmode/rm/trampoline_64.S
26622 +++ b/arch/x86/realmode/rm/trampoline_64.S
26623 @@ -107,7 +107,7 @@ ENTRY(startup_32)
26624 wrmsr
26625
26626 # Enable paging and in turn activate Long Mode
26627 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26628 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
26629 movl %eax, %cr0
26630
26631 /*
26632 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26633 index 5a1847d..deccb30 100644
26634 --- a/arch/x86/tools/relocs.c
26635 +++ b/arch/x86/tools/relocs.c
26636 @@ -12,10 +12,13 @@
26637 #include <regex.h>
26638 #include <tools/le_byteshift.h>
26639
26640 +#include "../../../include/generated/autoconf.h"
26641 +
26642 static void die(char *fmt, ...);
26643
26644 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26645 static Elf32_Ehdr ehdr;
26646 +static Elf32_Phdr *phdr;
26647 static unsigned long reloc_count, reloc_idx;
26648 static unsigned long *relocs;
26649 static unsigned long reloc16_count, reloc16_idx;
26650 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26651 }
26652 }
26653
26654 +static void read_phdrs(FILE *fp)
26655 +{
26656 + unsigned int i;
26657 +
26658 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26659 + if (!phdr) {
26660 + die("Unable to allocate %d program headers\n",
26661 + ehdr.e_phnum);
26662 + }
26663 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26664 + die("Seek to %d failed: %s\n",
26665 + ehdr.e_phoff, strerror(errno));
26666 + }
26667 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26668 + die("Cannot read ELF program headers: %s\n",
26669 + strerror(errno));
26670 + }
26671 + for(i = 0; i < ehdr.e_phnum; i++) {
26672 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26673 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26674 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26675 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26676 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26677 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26678 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26679 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26680 + }
26681 +
26682 +}
26683 +
26684 static void read_shdrs(FILE *fp)
26685 {
26686 - int i;
26687 + unsigned int i;
26688 Elf32_Shdr shdr;
26689
26690 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26691 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26692
26693 static void read_strtabs(FILE *fp)
26694 {
26695 - int i;
26696 + unsigned int i;
26697 for (i = 0; i < ehdr.e_shnum; i++) {
26698 struct section *sec = &secs[i];
26699 if (sec->shdr.sh_type != SHT_STRTAB) {
26700 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26701
26702 static void read_symtabs(FILE *fp)
26703 {
26704 - int i,j;
26705 + unsigned int i,j;
26706 for (i = 0; i < ehdr.e_shnum; i++) {
26707 struct section *sec = &secs[i];
26708 if (sec->shdr.sh_type != SHT_SYMTAB) {
26709 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26710 }
26711
26712
26713 -static void read_relocs(FILE *fp)
26714 +static void read_relocs(FILE *fp, int use_real_mode)
26715 {
26716 - int i,j;
26717 + unsigned int i,j;
26718 + uint32_t base;
26719 +
26720 for (i = 0; i < ehdr.e_shnum; i++) {
26721 struct section *sec = &secs[i];
26722 if (sec->shdr.sh_type != SHT_REL) {
26723 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26724 die("Cannot read symbol table: %s\n",
26725 strerror(errno));
26726 }
26727 + base = 0;
26728 +
26729 +#ifdef CONFIG_X86_32
26730 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26731 + if (phdr[j].p_type != PT_LOAD )
26732 + continue;
26733 + 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)
26734 + continue;
26735 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26736 + break;
26737 + }
26738 +#endif
26739 +
26740 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26741 Elf32_Rel *rel = &sec->reltab[j];
26742 - rel->r_offset = elf32_to_cpu(rel->r_offset);
26743 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26744 rel->r_info = elf32_to_cpu(rel->r_info);
26745 }
26746 }
26747 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
26748
26749 static void print_absolute_symbols(void)
26750 {
26751 - int i;
26752 + unsigned int i;
26753 printf("Absolute symbols\n");
26754 printf(" Num: Value Size Type Bind Visibility Name\n");
26755 for (i = 0; i < ehdr.e_shnum; i++) {
26756 struct section *sec = &secs[i];
26757 char *sym_strtab;
26758 - int j;
26759 + unsigned int j;
26760
26761 if (sec->shdr.sh_type != SHT_SYMTAB) {
26762 continue;
26763 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
26764
26765 static void print_absolute_relocs(void)
26766 {
26767 - int i, printed = 0;
26768 + unsigned int i, printed = 0;
26769
26770 for (i = 0; i < ehdr.e_shnum; i++) {
26771 struct section *sec = &secs[i];
26772 struct section *sec_applies, *sec_symtab;
26773 char *sym_strtab;
26774 Elf32_Sym *sh_symtab;
26775 - int j;
26776 + unsigned int j;
26777 if (sec->shdr.sh_type != SHT_REL) {
26778 continue;
26779 }
26780 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
26781 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26782 int use_real_mode)
26783 {
26784 - int i;
26785 + unsigned int i;
26786 /* Walk through the relocations */
26787 for (i = 0; i < ehdr.e_shnum; i++) {
26788 char *sym_strtab;
26789 Elf32_Sym *sh_symtab;
26790 struct section *sec_applies, *sec_symtab;
26791 - int j;
26792 + unsigned int j;
26793 struct section *sec = &secs[i];
26794
26795 if (sec->shdr.sh_type != SHT_REL) {
26796 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26797 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
26798 r_type = ELF32_R_TYPE(rel->r_info);
26799
26800 + if (!use_real_mode) {
26801 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
26802 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
26803 + continue;
26804 +
26805 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26806 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
26807 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
26808 + continue;
26809 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
26810 + continue;
26811 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
26812 + continue;
26813 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
26814 + continue;
26815 +#endif
26816 + }
26817 +
26818 shn_abs = sym->st_shndx == SHN_ABS;
26819
26820 switch (r_type) {
26821 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
26822
26823 static void emit_relocs(int as_text, int use_real_mode)
26824 {
26825 - int i;
26826 + unsigned int i;
26827 /* Count how many relocations I have and allocate space for them. */
26828 reloc_count = 0;
26829 walk_relocs(count_reloc, use_real_mode);
26830 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
26831 fname, strerror(errno));
26832 }
26833 read_ehdr(fp);
26834 + read_phdrs(fp);
26835 read_shdrs(fp);
26836 read_strtabs(fp);
26837 read_symtabs(fp);
26838 - read_relocs(fp);
26839 + read_relocs(fp, use_real_mode);
26840 if (show_absolute_syms) {
26841 print_absolute_symbols();
26842 return 0;
26843 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26844 index fd14be1..e3c79c0 100644
26845 --- a/arch/x86/vdso/Makefile
26846 +++ b/arch/x86/vdso/Makefile
26847 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
26848 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26849 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26850
26851 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26852 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26853 GCOV_PROFILE := n
26854
26855 #
26856 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26857 index 66e6d93..587f435 100644
26858 --- a/arch/x86/vdso/vdso32-setup.c
26859 +++ b/arch/x86/vdso/vdso32-setup.c
26860 @@ -25,6 +25,7 @@
26861 #include <asm/tlbflush.h>
26862 #include <asm/vdso.h>
26863 #include <asm/proto.h>
26864 +#include <asm/mman.h>
26865
26866 enum {
26867 VDSO_DISABLED = 0,
26868 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26869 void enable_sep_cpu(void)
26870 {
26871 int cpu = get_cpu();
26872 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26873 + struct tss_struct *tss = init_tss + cpu;
26874
26875 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26876 put_cpu();
26877 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26878 gate_vma.vm_start = FIXADDR_USER_START;
26879 gate_vma.vm_end = FIXADDR_USER_END;
26880 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26881 - gate_vma.vm_page_prot = __P101;
26882 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26883
26884 return 0;
26885 }
26886 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26887 if (compat)
26888 addr = VDSO_HIGH_BASE;
26889 else {
26890 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26891 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26892 if (IS_ERR_VALUE(addr)) {
26893 ret = addr;
26894 goto up_fail;
26895 }
26896 }
26897
26898 - current->mm->context.vdso = (void *)addr;
26899 + current->mm->context.vdso = addr;
26900
26901 if (compat_uses_vma || !compat) {
26902 /*
26903 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26904 }
26905
26906 current_thread_info()->sysenter_return =
26907 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26908 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26909
26910 up_fail:
26911 if (ret)
26912 - current->mm->context.vdso = NULL;
26913 + current->mm->context.vdso = 0;
26914
26915 up_write(&mm->mmap_sem);
26916
26917 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
26918
26919 const char *arch_vma_name(struct vm_area_struct *vma)
26920 {
26921 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26922 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26923 return "[vdso]";
26924 +
26925 +#ifdef CONFIG_PAX_SEGMEXEC
26926 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26927 + return "[vdso]";
26928 +#endif
26929 +
26930 return NULL;
26931 }
26932
26933 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26934 * Check to see if the corresponding task was created in compat vdso
26935 * mode.
26936 */
26937 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26938 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26939 return &gate_vma;
26940 return NULL;
26941 }
26942 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26943 index 00aaf04..4a26505 100644
26944 --- a/arch/x86/vdso/vma.c
26945 +++ b/arch/x86/vdso/vma.c
26946 @@ -16,8 +16,6 @@
26947 #include <asm/vdso.h>
26948 #include <asm/page.h>
26949
26950 -unsigned int __read_mostly vdso_enabled = 1;
26951 -
26952 extern char vdso_start[], vdso_end[];
26953 extern unsigned short vdso_sync_cpuid;
26954
26955 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26956 * unaligned here as a result of stack start randomization.
26957 */
26958 addr = PAGE_ALIGN(addr);
26959 - addr = align_addr(addr, NULL, ALIGN_VDSO);
26960
26961 return addr;
26962 }
26963 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
26964 unsigned size)
26965 {
26966 struct mm_struct *mm = current->mm;
26967 - unsigned long addr;
26968 + unsigned long addr = 0;
26969 int ret;
26970
26971 - if (!vdso_enabled)
26972 - return 0;
26973 -
26974 down_write(&mm->mmap_sem);
26975 +
26976 +#ifdef CONFIG_PAX_RANDMMAP
26977 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26978 +#endif
26979 +
26980 addr = vdso_addr(mm->start_stack, size);
26981 + addr = align_addr(addr, NULL, ALIGN_VDSO);
26982 addr = get_unmapped_area(NULL, addr, size, 0, 0);
26983 if (IS_ERR_VALUE(addr)) {
26984 ret = addr;
26985 goto up_fail;
26986 }
26987
26988 - current->mm->context.vdso = (void *)addr;
26989 + mm->context.vdso = addr;
26990
26991 ret = install_special_mapping(mm, addr, size,
26992 VM_READ|VM_EXEC|
26993 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
26994 pages);
26995 - if (ret) {
26996 - current->mm->context.vdso = NULL;
26997 - goto up_fail;
26998 - }
26999 + if (ret)
27000 + mm->context.vdso = 0;
27001
27002 up_fail:
27003 up_write(&mm->mmap_sem);
27004 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27005 vdsox32_size);
27006 }
27007 #endif
27008 -
27009 -static __init int vdso_setup(char *s)
27010 -{
27011 - vdso_enabled = simple_strtoul(s, NULL, 0);
27012 - return 0;
27013 -}
27014 -__setup("vdso=", vdso_setup);
27015 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27016 index ff962d4..2bb5e83 100644
27017 --- a/arch/x86/xen/enlighten.c
27018 +++ b/arch/x86/xen/enlighten.c
27019 @@ -97,8 +97,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27020
27021 struct shared_info xen_dummy_shared_info;
27022
27023 -void *xen_initial_gdt;
27024 -
27025 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27026 __read_mostly int xen_have_vector_callback;
27027 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27028 @@ -1175,30 +1173,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27029 #endif
27030 };
27031
27032 -static void xen_reboot(int reason)
27033 +static __noreturn void xen_reboot(int reason)
27034 {
27035 struct sched_shutdown r = { .reason = reason };
27036
27037 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27038 - BUG();
27039 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27040 + BUG();
27041 }
27042
27043 -static void xen_restart(char *msg)
27044 +static __noreturn void xen_restart(char *msg)
27045 {
27046 xen_reboot(SHUTDOWN_reboot);
27047 }
27048
27049 -static void xen_emergency_restart(void)
27050 +static __noreturn void xen_emergency_restart(void)
27051 {
27052 xen_reboot(SHUTDOWN_reboot);
27053 }
27054
27055 -static void xen_machine_halt(void)
27056 +static __noreturn void xen_machine_halt(void)
27057 {
27058 xen_reboot(SHUTDOWN_poweroff);
27059 }
27060
27061 -static void xen_machine_power_off(void)
27062 +static __noreturn void xen_machine_power_off(void)
27063 {
27064 if (pm_power_off)
27065 pm_power_off();
27066 @@ -1301,7 +1299,17 @@ asmlinkage void __init xen_start_kernel(void)
27067 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27068
27069 /* Work out if we support NX */
27070 - x86_configure_nx();
27071 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27072 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27073 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27074 + unsigned l, h;
27075 +
27076 + __supported_pte_mask |= _PAGE_NX;
27077 + rdmsr(MSR_EFER, l, h);
27078 + l |= EFER_NX;
27079 + wrmsr(MSR_EFER, l, h);
27080 + }
27081 +#endif
27082
27083 xen_setup_features();
27084
27085 @@ -1332,13 +1340,6 @@ asmlinkage void __init xen_start_kernel(void)
27086
27087 machine_ops = xen_machine_ops;
27088
27089 - /*
27090 - * The only reliable way to retain the initial address of the
27091 - * percpu gdt_page is to remember it here, so we can go and
27092 - * mark it RW later, when the initial percpu area is freed.
27093 - */
27094 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27095 -
27096 xen_smp_init();
27097
27098 #ifdef CONFIG_ACPI_NUMA
27099 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27100 index 3a73785..0d30df2 100644
27101 --- a/arch/x86/xen/mmu.c
27102 +++ b/arch/x86/xen/mmu.c
27103 @@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27104 convert_pfn_mfn(init_level4_pgt);
27105 convert_pfn_mfn(level3_ident_pgt);
27106 convert_pfn_mfn(level3_kernel_pgt);
27107 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27108 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27109 + convert_pfn_mfn(level3_vmemmap_pgt);
27110
27111 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27112 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27113 @@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27114 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27115 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27116 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27117 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27118 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27119 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27120 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27121 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27122 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27123 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27124
27125 @@ -1940,6 +1947,7 @@ static void __init xen_post_allocator_init(void)
27126 pv_mmu_ops.set_pud = xen_set_pud;
27127 #if PAGETABLE_LEVELS == 4
27128 pv_mmu_ops.set_pgd = xen_set_pgd;
27129 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27130 #endif
27131
27132 /* This will work as long as patching hasn't happened yet
27133 @@ -2021,6 +2029,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27134 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27135 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27136 .set_pgd = xen_set_pgd_hyper,
27137 + .set_pgd_batched = xen_set_pgd_hyper,
27138
27139 .alloc_pud = xen_alloc_pmd_init,
27140 .release_pud = xen_release_pmd_init,
27141 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27142 index afb250d..627075f 100644
27143 --- a/arch/x86/xen/smp.c
27144 +++ b/arch/x86/xen/smp.c
27145 @@ -231,11 +231,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27146 {
27147 BUG_ON(smp_processor_id() != 0);
27148 native_smp_prepare_boot_cpu();
27149 -
27150 - /* We've switched to the "real" per-cpu gdt, so make sure the
27151 - old memory can be recycled */
27152 - make_lowmem_page_readwrite(xen_initial_gdt);
27153 -
27154 xen_filter_cpu_maps();
27155 xen_setup_vcpu_info_placement();
27156 }
27157 @@ -302,12 +297,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27158 gdt = get_cpu_gdt_table(cpu);
27159
27160 ctxt->flags = VGCF_IN_KERNEL;
27161 - ctxt->user_regs.ds = __USER_DS;
27162 - ctxt->user_regs.es = __USER_DS;
27163 + ctxt->user_regs.ds = __KERNEL_DS;
27164 + ctxt->user_regs.es = __KERNEL_DS;
27165 ctxt->user_regs.ss = __KERNEL_DS;
27166 #ifdef CONFIG_X86_32
27167 ctxt->user_regs.fs = __KERNEL_PERCPU;
27168 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27169 + savesegment(gs, ctxt->user_regs.gs);
27170 #else
27171 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27172 #endif
27173 @@ -357,13 +352,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27174 int rc;
27175
27176 per_cpu(current_task, cpu) = idle;
27177 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27178 #ifdef CONFIG_X86_32
27179 irq_ctx_init(cpu);
27180 #else
27181 clear_tsk_thread_flag(idle, TIF_FORK);
27182 - per_cpu(kernel_stack, cpu) =
27183 - (unsigned long)task_stack_page(idle) -
27184 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27185 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27186 #endif
27187 xen_setup_runstate_info(cpu);
27188 xen_setup_timer(cpu);
27189 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27190 index f9643fc..602e8af 100644
27191 --- a/arch/x86/xen/xen-asm_32.S
27192 +++ b/arch/x86/xen/xen-asm_32.S
27193 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27194 ESP_OFFSET=4 # bytes pushed onto stack
27195
27196 /*
27197 - * Store vcpu_info pointer for easy access. Do it this way to
27198 - * avoid having to reload %fs
27199 + * Store vcpu_info pointer for easy access.
27200 */
27201 #ifdef CONFIG_SMP
27202 - GET_THREAD_INFO(%eax)
27203 - movl TI_cpu(%eax), %eax
27204 - movl __per_cpu_offset(,%eax,4), %eax
27205 - mov xen_vcpu(%eax), %eax
27206 + push %fs
27207 + mov $(__KERNEL_PERCPU), %eax
27208 + mov %eax, %fs
27209 + mov PER_CPU_VAR(xen_vcpu), %eax
27210 + pop %fs
27211 #else
27212 movl xen_vcpu, %eax
27213 #endif
27214 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27215 index aaa7291..3f77960 100644
27216 --- a/arch/x86/xen/xen-head.S
27217 +++ b/arch/x86/xen/xen-head.S
27218 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27219 #ifdef CONFIG_X86_32
27220 mov %esi,xen_start_info
27221 mov $init_thread_union+THREAD_SIZE,%esp
27222 +#ifdef CONFIG_SMP
27223 + movl $cpu_gdt_table,%edi
27224 + movl $__per_cpu_load,%eax
27225 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27226 + rorl $16,%eax
27227 + movb %al,__KERNEL_PERCPU + 4(%edi)
27228 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27229 + movl $__per_cpu_end - 1,%eax
27230 + subl $__per_cpu_start,%eax
27231 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27232 +#endif
27233 #else
27234 mov %rsi,xen_start_info
27235 mov $init_thread_union+THREAD_SIZE,%rsp
27236 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27237 index 202d4c1..99b072a 100644
27238 --- a/arch/x86/xen/xen-ops.h
27239 +++ b/arch/x86/xen/xen-ops.h
27240 @@ -10,8 +10,6 @@
27241 extern const char xen_hypervisor_callback[];
27242 extern const char xen_failsafe_callback[];
27243
27244 -extern void *xen_initial_gdt;
27245 -
27246 struct trap_info;
27247 void xen_copy_trap_info(struct trap_info *traps);
27248
27249 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27250 index 525bd3d..ef888b1 100644
27251 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27252 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27253 @@ -119,9 +119,9 @@
27254 ----------------------------------------------------------------------*/
27255
27256 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27257 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27258 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27259 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27260 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27261
27262 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27263 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27264 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27265 index 2f33760..835e50a 100644
27266 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27267 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27268 @@ -11,6 +11,7 @@
27269 #ifndef _XTENSA_CORE_H
27270 #define _XTENSA_CORE_H
27271
27272 +#include <linux/const.h>
27273
27274 /****************************************************************************
27275 Parameters Useful for Any Code, USER or PRIVILEGED
27276 @@ -112,9 +113,9 @@
27277 ----------------------------------------------------------------------*/
27278
27279 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27280 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27281 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27282 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27283 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27284
27285 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27286 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27287 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27288 index af00795..2bb8105 100644
27289 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27290 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27291 @@ -11,6 +11,7 @@
27292 #ifndef _XTENSA_CORE_CONFIGURATION_H
27293 #define _XTENSA_CORE_CONFIGURATION_H
27294
27295 +#include <linux/const.h>
27296
27297 /****************************************************************************
27298 Parameters Useful for Any Code, USER or PRIVILEGED
27299 @@ -118,9 +119,9 @@
27300 ----------------------------------------------------------------------*/
27301
27302 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27303 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27304 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27305 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27306 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27307
27308 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27309 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27310 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27311 index 58916af..9cb880b 100644
27312 --- a/block/blk-iopoll.c
27313 +++ b/block/blk-iopoll.c
27314 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27315 }
27316 EXPORT_SYMBOL(blk_iopoll_complete);
27317
27318 -static void blk_iopoll_softirq(struct softirq_action *h)
27319 +static void blk_iopoll_softirq(void)
27320 {
27321 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27322 int rearm = 0, budget = blk_iopoll_budget;
27323 diff --git a/block/blk-map.c b/block/blk-map.c
27324 index 623e1cd..ca1e109 100644
27325 --- a/block/blk-map.c
27326 +++ b/block/blk-map.c
27327 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27328 if (!len || !kbuf)
27329 return -EINVAL;
27330
27331 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27332 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27333 if (do_copy)
27334 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27335 else
27336 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27337 index 467c8de..4bddc6d 100644
27338 --- a/block/blk-softirq.c
27339 +++ b/block/blk-softirq.c
27340 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27341 * Softirq action handler - move entries to local list and loop over them
27342 * while passing them to the queue registered handler.
27343 */
27344 -static void blk_done_softirq(struct softirq_action *h)
27345 +static void blk_done_softirq(void)
27346 {
27347 struct list_head *cpu_list, local_list;
27348
27349 diff --git a/block/bsg.c b/block/bsg.c
27350 index ff64ae3..593560c 100644
27351 --- a/block/bsg.c
27352 +++ b/block/bsg.c
27353 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27354 struct sg_io_v4 *hdr, struct bsg_device *bd,
27355 fmode_t has_write_perm)
27356 {
27357 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27358 + unsigned char *cmdptr;
27359 +
27360 if (hdr->request_len > BLK_MAX_CDB) {
27361 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27362 if (!rq->cmd)
27363 return -ENOMEM;
27364 - }
27365 + cmdptr = rq->cmd;
27366 + } else
27367 + cmdptr = tmpcmd;
27368
27369 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27370 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27371 hdr->request_len))
27372 return -EFAULT;
27373
27374 + if (cmdptr != rq->cmd)
27375 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27376 +
27377 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27378 if (blk_verify_command(rq->cmd, has_write_perm))
27379 return -EPERM;
27380 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27381 index 7c668c8..db3521c 100644
27382 --- a/block/compat_ioctl.c
27383 +++ b/block/compat_ioctl.c
27384 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27385 err |= __get_user(f->spec1, &uf->spec1);
27386 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27387 err |= __get_user(name, &uf->name);
27388 - f->name = compat_ptr(name);
27389 + f->name = (void __force_kernel *)compat_ptr(name);
27390 if (err) {
27391 err = -EFAULT;
27392 goto out;
27393 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27394 index 6296b40..417c00f 100644
27395 --- a/block/partitions/efi.c
27396 +++ b/block/partitions/efi.c
27397 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27398 if (!gpt)
27399 return NULL;
27400
27401 + if (!le32_to_cpu(gpt->num_partition_entries))
27402 + return NULL;
27403 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27404 + if (!pte)
27405 + return NULL;
27406 +
27407 count = le32_to_cpu(gpt->num_partition_entries) *
27408 le32_to_cpu(gpt->sizeof_partition_entry);
27409 - if (!count)
27410 - return NULL;
27411 - pte = kzalloc(count, GFP_KERNEL);
27412 - if (!pte)
27413 - return NULL;
27414 -
27415 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27416 (u8 *) pte,
27417 count) < count) {
27418 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27419 index 9a87daa..fb17486 100644
27420 --- a/block/scsi_ioctl.c
27421 +++ b/block/scsi_ioctl.c
27422 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27423 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27424 struct sg_io_hdr *hdr, fmode_t mode)
27425 {
27426 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27427 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27428 + unsigned char *cmdptr;
27429 +
27430 + if (rq->cmd != rq->__cmd)
27431 + cmdptr = rq->cmd;
27432 + else
27433 + cmdptr = tmpcmd;
27434 +
27435 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27436 return -EFAULT;
27437 +
27438 + if (cmdptr != rq->cmd)
27439 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27440 +
27441 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27442 return -EPERM;
27443
27444 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27445 int err;
27446 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27447 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27448 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27449 + unsigned char *cmdptr;
27450
27451 if (!sic)
27452 return -EINVAL;
27453 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27454 */
27455 err = -EFAULT;
27456 rq->cmd_len = cmdlen;
27457 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27458 +
27459 + if (rq->cmd != rq->__cmd)
27460 + cmdptr = rq->cmd;
27461 + else
27462 + cmdptr = tmpcmd;
27463 +
27464 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27465 goto error;
27466
27467 + if (rq->cmd != cmdptr)
27468 + memcpy(rq->cmd, cmdptr, cmdlen);
27469 +
27470 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27471 goto error;
27472
27473 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27474 index 671d4d6..5f24030 100644
27475 --- a/crypto/cryptd.c
27476 +++ b/crypto/cryptd.c
27477 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27478
27479 struct cryptd_blkcipher_request_ctx {
27480 crypto_completion_t complete;
27481 -};
27482 +} __no_const;
27483
27484 struct cryptd_hash_ctx {
27485 struct crypto_shash *child;
27486 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27487
27488 struct cryptd_aead_request_ctx {
27489 crypto_completion_t complete;
27490 -};
27491 +} __no_const;
27492
27493 static void cryptd_queue_worker(struct work_struct *work);
27494
27495 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27496 index e6defd8..c26a225 100644
27497 --- a/drivers/acpi/apei/cper.c
27498 +++ b/drivers/acpi/apei/cper.c
27499 @@ -38,12 +38,12 @@
27500 */
27501 u64 cper_next_record_id(void)
27502 {
27503 - static atomic64_t seq;
27504 + static atomic64_unchecked_t seq;
27505
27506 - if (!atomic64_read(&seq))
27507 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27508 + if (!atomic64_read_unchecked(&seq))
27509 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27510
27511 - return atomic64_inc_return(&seq);
27512 + return atomic64_inc_return_unchecked(&seq);
27513 }
27514 EXPORT_SYMBOL_GPL(cper_next_record_id);
27515
27516 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27517 index 7586544..636a2f0 100644
27518 --- a/drivers/acpi/ec_sys.c
27519 +++ b/drivers/acpi/ec_sys.c
27520 @@ -12,6 +12,7 @@
27521 #include <linux/acpi.h>
27522 #include <linux/debugfs.h>
27523 #include <linux/module.h>
27524 +#include <linux/uaccess.h>
27525 #include "internal.h"
27526
27527 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27528 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27529 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27530 */
27531 unsigned int size = EC_SPACE_SIZE;
27532 - u8 *data = (u8 *) buf;
27533 + u8 data;
27534 loff_t init_off = *off;
27535 int err = 0;
27536
27537 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27538 size = count;
27539
27540 while (size) {
27541 - err = ec_read(*off, &data[*off - init_off]);
27542 + err = ec_read(*off, &data);
27543 if (err)
27544 return err;
27545 + if (put_user(data, &buf[*off - init_off]))
27546 + return -EFAULT;
27547 *off += 1;
27548 size--;
27549 }
27550 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27551
27552 unsigned int size = count;
27553 loff_t init_off = *off;
27554 - u8 *data = (u8 *) buf;
27555 int err = 0;
27556
27557 if (*off >= EC_SPACE_SIZE)
27558 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27559 }
27560
27561 while (size) {
27562 - u8 byte_write = data[*off - init_off];
27563 + u8 byte_write;
27564 + if (get_user(byte_write, &buf[*off - init_off]))
27565 + return -EFAULT;
27566 err = ec_write(*off, byte_write);
27567 if (err)
27568 return err;
27569 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27570 index 251c7b62..000462d 100644
27571 --- a/drivers/acpi/proc.c
27572 +++ b/drivers/acpi/proc.c
27573 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27574 size_t count, loff_t * ppos)
27575 {
27576 struct list_head *node, *next;
27577 - char strbuf[5];
27578 - char str[5] = "";
27579 - unsigned int len = count;
27580 + char strbuf[5] = {0};
27581
27582 - if (len > 4)
27583 - len = 4;
27584 - if (len < 0)
27585 + if (count > 4)
27586 + count = 4;
27587 + if (copy_from_user(strbuf, buffer, count))
27588 return -EFAULT;
27589 -
27590 - if (copy_from_user(strbuf, buffer, len))
27591 - return -EFAULT;
27592 - strbuf[len] = '\0';
27593 - sscanf(strbuf, "%s", str);
27594 + strbuf[count] = '\0';
27595
27596 mutex_lock(&acpi_device_lock);
27597 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27598 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27599 if (!dev->wakeup.flags.valid)
27600 continue;
27601
27602 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27603 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27604 if (device_can_wakeup(&dev->dev)) {
27605 bool enable = !device_may_wakeup(&dev->dev);
27606 device_set_wakeup_enable(&dev->dev, enable);
27607 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27608 index 0734086..3ad3e4c 100644
27609 --- a/drivers/acpi/processor_driver.c
27610 +++ b/drivers/acpi/processor_driver.c
27611 @@ -556,7 +556,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27612 return 0;
27613 #endif
27614
27615 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27616 + BUG_ON(pr->id >= nr_cpu_ids);
27617
27618 /*
27619 * Buggy BIOS check
27620 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27621 index cece3a4..0845256 100644
27622 --- a/drivers/ata/libata-core.c
27623 +++ b/drivers/ata/libata-core.c
27624 @@ -4743,7 +4743,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27625 struct ata_port *ap;
27626 unsigned int tag;
27627
27628 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27629 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27630 ap = qc->ap;
27631
27632 qc->flags = 0;
27633 @@ -4759,7 +4759,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27634 struct ata_port *ap;
27635 struct ata_link *link;
27636
27637 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27638 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27639 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27640 ap = qc->ap;
27641 link = qc->dev->link;
27642 @@ -5823,6 +5823,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27643 return;
27644
27645 spin_lock(&lock);
27646 + pax_open_kernel();
27647
27648 for (cur = ops->inherits; cur; cur = cur->inherits) {
27649 void **inherit = (void **)cur;
27650 @@ -5836,8 +5837,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27651 if (IS_ERR(*pp))
27652 *pp = NULL;
27653
27654 - ops->inherits = NULL;
27655 + *(struct ata_port_operations **)&ops->inherits = NULL;
27656
27657 + pax_close_kernel();
27658 spin_unlock(&lock);
27659 }
27660
27661 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27662 index ac6a5be..c7176b1 100644
27663 --- a/drivers/ata/pata_arasan_cf.c
27664 +++ b/drivers/ata/pata_arasan_cf.c
27665 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27666 /* Handle platform specific quirks */
27667 if (pdata->quirk) {
27668 if (pdata->quirk & CF_BROKEN_PIO) {
27669 - ap->ops->set_piomode = NULL;
27670 + pax_open_kernel();
27671 + *(void **)&ap->ops->set_piomode = NULL;
27672 + pax_close_kernel();
27673 ap->pio_mask = 0;
27674 }
27675 if (pdata->quirk & CF_BROKEN_MWDMA)
27676 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27677 index f9b983a..887b9d8 100644
27678 --- a/drivers/atm/adummy.c
27679 +++ b/drivers/atm/adummy.c
27680 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27681 vcc->pop(vcc, skb);
27682 else
27683 dev_kfree_skb_any(skb);
27684 - atomic_inc(&vcc->stats->tx);
27685 + atomic_inc_unchecked(&vcc->stats->tx);
27686
27687 return 0;
27688 }
27689 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27690 index 89b30f3..7964211 100644
27691 --- a/drivers/atm/ambassador.c
27692 +++ b/drivers/atm/ambassador.c
27693 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27694 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27695
27696 // VC layer stats
27697 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27698 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27699
27700 // free the descriptor
27701 kfree (tx_descr);
27702 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27703 dump_skb ("<<<", vc, skb);
27704
27705 // VC layer stats
27706 - atomic_inc(&atm_vcc->stats->rx);
27707 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27708 __net_timestamp(skb);
27709 // end of our responsibility
27710 atm_vcc->push (atm_vcc, skb);
27711 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27712 } else {
27713 PRINTK (KERN_INFO, "dropped over-size frame");
27714 // should we count this?
27715 - atomic_inc(&atm_vcc->stats->rx_drop);
27716 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27717 }
27718
27719 } else {
27720 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27721 }
27722
27723 if (check_area (skb->data, skb->len)) {
27724 - atomic_inc(&atm_vcc->stats->tx_err);
27725 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27726 return -ENOMEM; // ?
27727 }
27728
27729 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27730 index b22d71c..d6e1049 100644
27731 --- a/drivers/atm/atmtcp.c
27732 +++ b/drivers/atm/atmtcp.c
27733 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27734 if (vcc->pop) vcc->pop(vcc,skb);
27735 else dev_kfree_skb(skb);
27736 if (dev_data) return 0;
27737 - atomic_inc(&vcc->stats->tx_err);
27738 + atomic_inc_unchecked(&vcc->stats->tx_err);
27739 return -ENOLINK;
27740 }
27741 size = skb->len+sizeof(struct atmtcp_hdr);
27742 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27743 if (!new_skb) {
27744 if (vcc->pop) vcc->pop(vcc,skb);
27745 else dev_kfree_skb(skb);
27746 - atomic_inc(&vcc->stats->tx_err);
27747 + atomic_inc_unchecked(&vcc->stats->tx_err);
27748 return -ENOBUFS;
27749 }
27750 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27751 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27752 if (vcc->pop) vcc->pop(vcc,skb);
27753 else dev_kfree_skb(skb);
27754 out_vcc->push(out_vcc,new_skb);
27755 - atomic_inc(&vcc->stats->tx);
27756 - atomic_inc(&out_vcc->stats->rx);
27757 + atomic_inc_unchecked(&vcc->stats->tx);
27758 + atomic_inc_unchecked(&out_vcc->stats->rx);
27759 return 0;
27760 }
27761
27762 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27763 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27764 read_unlock(&vcc_sklist_lock);
27765 if (!out_vcc) {
27766 - atomic_inc(&vcc->stats->tx_err);
27767 + atomic_inc_unchecked(&vcc->stats->tx_err);
27768 goto done;
27769 }
27770 skb_pull(skb,sizeof(struct atmtcp_hdr));
27771 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27772 __net_timestamp(new_skb);
27773 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27774 out_vcc->push(out_vcc,new_skb);
27775 - atomic_inc(&vcc->stats->tx);
27776 - atomic_inc(&out_vcc->stats->rx);
27777 + atomic_inc_unchecked(&vcc->stats->tx);
27778 + atomic_inc_unchecked(&out_vcc->stats->rx);
27779 done:
27780 if (vcc->pop) vcc->pop(vcc,skb);
27781 else dev_kfree_skb(skb);
27782 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27783 index 2059ee4..faf51c7 100644
27784 --- a/drivers/atm/eni.c
27785 +++ b/drivers/atm/eni.c
27786 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27787 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27788 vcc->dev->number);
27789 length = 0;
27790 - atomic_inc(&vcc->stats->rx_err);
27791 + atomic_inc_unchecked(&vcc->stats->rx_err);
27792 }
27793 else {
27794 length = ATM_CELL_SIZE-1; /* no HEC */
27795 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27796 size);
27797 }
27798 eff = length = 0;
27799 - atomic_inc(&vcc->stats->rx_err);
27800 + atomic_inc_unchecked(&vcc->stats->rx_err);
27801 }
27802 else {
27803 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27804 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27805 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27806 vcc->dev->number,vcc->vci,length,size << 2,descr);
27807 length = eff = 0;
27808 - atomic_inc(&vcc->stats->rx_err);
27809 + atomic_inc_unchecked(&vcc->stats->rx_err);
27810 }
27811 }
27812 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27813 @@ -767,7 +767,7 @@ rx_dequeued++;
27814 vcc->push(vcc,skb);
27815 pushed++;
27816 }
27817 - atomic_inc(&vcc->stats->rx);
27818 + atomic_inc_unchecked(&vcc->stats->rx);
27819 }
27820 wake_up(&eni_dev->rx_wait);
27821 }
27822 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
27823 PCI_DMA_TODEVICE);
27824 if (vcc->pop) vcc->pop(vcc,skb);
27825 else dev_kfree_skb_irq(skb);
27826 - atomic_inc(&vcc->stats->tx);
27827 + atomic_inc_unchecked(&vcc->stats->tx);
27828 wake_up(&eni_dev->tx_wait);
27829 dma_complete++;
27830 }
27831 @@ -1567,7 +1567,7 @@ tx_complete++;
27832 /*--------------------------------- entries ---------------------------------*/
27833
27834
27835 -static const char *media_name[] __devinitdata = {
27836 +static const char *media_name[] __devinitconst = {
27837 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27838 "UTP", "05?", "06?", "07?", /* 4- 7 */
27839 "TAXI","09?", "10?", "11?", /* 8-11 */
27840 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27841 index 86fed1b..6dc4721 100644
27842 --- a/drivers/atm/firestream.c
27843 +++ b/drivers/atm/firestream.c
27844 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27845 }
27846 }
27847
27848 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27849 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27850
27851 fs_dprintk (FS_DEBUG_TXMEM, "i");
27852 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27853 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27854 #endif
27855 skb_put (skb, qe->p1 & 0xffff);
27856 ATM_SKB(skb)->vcc = atm_vcc;
27857 - atomic_inc(&atm_vcc->stats->rx);
27858 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27859 __net_timestamp(skb);
27860 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27861 atm_vcc->push (atm_vcc, skb);
27862 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27863 kfree (pe);
27864 }
27865 if (atm_vcc)
27866 - atomic_inc(&atm_vcc->stats->rx_drop);
27867 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27868 break;
27869 case 0x1f: /* Reassembly abort: no buffers. */
27870 /* Silently increment error counter. */
27871 if (atm_vcc)
27872 - atomic_inc(&atm_vcc->stats->rx_drop);
27873 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27874 break;
27875 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27876 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27877 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27878 index 361f5ae..7fc552d 100644
27879 --- a/drivers/atm/fore200e.c
27880 +++ b/drivers/atm/fore200e.c
27881 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27882 #endif
27883 /* check error condition */
27884 if (*entry->status & STATUS_ERROR)
27885 - atomic_inc(&vcc->stats->tx_err);
27886 + atomic_inc_unchecked(&vcc->stats->tx_err);
27887 else
27888 - atomic_inc(&vcc->stats->tx);
27889 + atomic_inc_unchecked(&vcc->stats->tx);
27890 }
27891 }
27892
27893 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27894 if (skb == NULL) {
27895 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27896
27897 - atomic_inc(&vcc->stats->rx_drop);
27898 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27899 return -ENOMEM;
27900 }
27901
27902 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27903
27904 dev_kfree_skb_any(skb);
27905
27906 - atomic_inc(&vcc->stats->rx_drop);
27907 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27908 return -ENOMEM;
27909 }
27910
27911 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27912
27913 vcc->push(vcc, skb);
27914 - atomic_inc(&vcc->stats->rx);
27915 + atomic_inc_unchecked(&vcc->stats->rx);
27916
27917 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27918
27919 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27920 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27921 fore200e->atm_dev->number,
27922 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27923 - atomic_inc(&vcc->stats->rx_err);
27924 + atomic_inc_unchecked(&vcc->stats->rx_err);
27925 }
27926 }
27927
27928 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27929 goto retry_here;
27930 }
27931
27932 - atomic_inc(&vcc->stats->tx_err);
27933 + atomic_inc_unchecked(&vcc->stats->tx_err);
27934
27935 fore200e->tx_sat++;
27936 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27937 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
27938 index b182c2f..1c6fa8a 100644
27939 --- a/drivers/atm/he.c
27940 +++ b/drivers/atm/he.c
27941 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27942
27943 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27944 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27945 - atomic_inc(&vcc->stats->rx_drop);
27946 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27947 goto return_host_buffers;
27948 }
27949
27950 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27951 RBRQ_LEN_ERR(he_dev->rbrq_head)
27952 ? "LEN_ERR" : "",
27953 vcc->vpi, vcc->vci);
27954 - atomic_inc(&vcc->stats->rx_err);
27955 + atomic_inc_unchecked(&vcc->stats->rx_err);
27956 goto return_host_buffers;
27957 }
27958
27959 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27960 vcc->push(vcc, skb);
27961 spin_lock(&he_dev->global_lock);
27962
27963 - atomic_inc(&vcc->stats->rx);
27964 + atomic_inc_unchecked(&vcc->stats->rx);
27965
27966 return_host_buffers:
27967 ++pdus_assembled;
27968 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
27969 tpd->vcc->pop(tpd->vcc, tpd->skb);
27970 else
27971 dev_kfree_skb_any(tpd->skb);
27972 - atomic_inc(&tpd->vcc->stats->tx_err);
27973 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
27974 }
27975 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
27976 return;
27977 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27978 vcc->pop(vcc, skb);
27979 else
27980 dev_kfree_skb_any(skb);
27981 - atomic_inc(&vcc->stats->tx_err);
27982 + atomic_inc_unchecked(&vcc->stats->tx_err);
27983 return -EINVAL;
27984 }
27985
27986 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27987 vcc->pop(vcc, skb);
27988 else
27989 dev_kfree_skb_any(skb);
27990 - atomic_inc(&vcc->stats->tx_err);
27991 + atomic_inc_unchecked(&vcc->stats->tx_err);
27992 return -EINVAL;
27993 }
27994 #endif
27995 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27996 vcc->pop(vcc, skb);
27997 else
27998 dev_kfree_skb_any(skb);
27999 - atomic_inc(&vcc->stats->tx_err);
28000 + atomic_inc_unchecked(&vcc->stats->tx_err);
28001 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28002 return -ENOMEM;
28003 }
28004 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28005 vcc->pop(vcc, skb);
28006 else
28007 dev_kfree_skb_any(skb);
28008 - atomic_inc(&vcc->stats->tx_err);
28009 + atomic_inc_unchecked(&vcc->stats->tx_err);
28010 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28011 return -ENOMEM;
28012 }
28013 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28014 __enqueue_tpd(he_dev, tpd, cid);
28015 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28016
28017 - atomic_inc(&vcc->stats->tx);
28018 + atomic_inc_unchecked(&vcc->stats->tx);
28019
28020 return 0;
28021 }
28022 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28023 index 7d01c2a..4e3ac01 100644
28024 --- a/drivers/atm/horizon.c
28025 +++ b/drivers/atm/horizon.c
28026 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28027 {
28028 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28029 // VC layer stats
28030 - atomic_inc(&vcc->stats->rx);
28031 + atomic_inc_unchecked(&vcc->stats->rx);
28032 __net_timestamp(skb);
28033 // end of our responsibility
28034 vcc->push (vcc, skb);
28035 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28036 dev->tx_iovec = NULL;
28037
28038 // VC layer stats
28039 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28040 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28041
28042 // free the skb
28043 hrz_kfree_skb (skb);
28044 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28045 index 8974bd2..b856f85 100644
28046 --- a/drivers/atm/idt77252.c
28047 +++ b/drivers/atm/idt77252.c
28048 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28049 else
28050 dev_kfree_skb(skb);
28051
28052 - atomic_inc(&vcc->stats->tx);
28053 + atomic_inc_unchecked(&vcc->stats->tx);
28054 }
28055
28056 atomic_dec(&scq->used);
28057 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28058 if ((sb = dev_alloc_skb(64)) == NULL) {
28059 printk("%s: Can't allocate buffers for aal0.\n",
28060 card->name);
28061 - atomic_add(i, &vcc->stats->rx_drop);
28062 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28063 break;
28064 }
28065 if (!atm_charge(vcc, sb->truesize)) {
28066 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28067 card->name);
28068 - atomic_add(i - 1, &vcc->stats->rx_drop);
28069 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28070 dev_kfree_skb(sb);
28071 break;
28072 }
28073 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28074 ATM_SKB(sb)->vcc = vcc;
28075 __net_timestamp(sb);
28076 vcc->push(vcc, sb);
28077 - atomic_inc(&vcc->stats->rx);
28078 + atomic_inc_unchecked(&vcc->stats->rx);
28079
28080 cell += ATM_CELL_PAYLOAD;
28081 }
28082 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28083 "(CDC: %08x)\n",
28084 card->name, len, rpp->len, readl(SAR_REG_CDC));
28085 recycle_rx_pool_skb(card, rpp);
28086 - atomic_inc(&vcc->stats->rx_err);
28087 + atomic_inc_unchecked(&vcc->stats->rx_err);
28088 return;
28089 }
28090 if (stat & SAR_RSQE_CRC) {
28091 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28092 recycle_rx_pool_skb(card, rpp);
28093 - atomic_inc(&vcc->stats->rx_err);
28094 + atomic_inc_unchecked(&vcc->stats->rx_err);
28095 return;
28096 }
28097 if (skb_queue_len(&rpp->queue) > 1) {
28098 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28099 RXPRINTK("%s: Can't alloc RX skb.\n",
28100 card->name);
28101 recycle_rx_pool_skb(card, rpp);
28102 - atomic_inc(&vcc->stats->rx_err);
28103 + atomic_inc_unchecked(&vcc->stats->rx_err);
28104 return;
28105 }
28106 if (!atm_charge(vcc, skb->truesize)) {
28107 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28108 __net_timestamp(skb);
28109
28110 vcc->push(vcc, skb);
28111 - atomic_inc(&vcc->stats->rx);
28112 + atomic_inc_unchecked(&vcc->stats->rx);
28113
28114 return;
28115 }
28116 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28117 __net_timestamp(skb);
28118
28119 vcc->push(vcc, skb);
28120 - atomic_inc(&vcc->stats->rx);
28121 + atomic_inc_unchecked(&vcc->stats->rx);
28122
28123 if (skb->truesize > SAR_FB_SIZE_3)
28124 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28125 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28126 if (vcc->qos.aal != ATM_AAL0) {
28127 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28128 card->name, vpi, vci);
28129 - atomic_inc(&vcc->stats->rx_drop);
28130 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28131 goto drop;
28132 }
28133
28134 if ((sb = dev_alloc_skb(64)) == NULL) {
28135 printk("%s: Can't allocate buffers for AAL0.\n",
28136 card->name);
28137 - atomic_inc(&vcc->stats->rx_err);
28138 + atomic_inc_unchecked(&vcc->stats->rx_err);
28139 goto drop;
28140 }
28141
28142 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28143 ATM_SKB(sb)->vcc = vcc;
28144 __net_timestamp(sb);
28145 vcc->push(vcc, sb);
28146 - atomic_inc(&vcc->stats->rx);
28147 + atomic_inc_unchecked(&vcc->stats->rx);
28148
28149 drop:
28150 skb_pull(queue, 64);
28151 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28152
28153 if (vc == NULL) {
28154 printk("%s: NULL connection in send().\n", card->name);
28155 - atomic_inc(&vcc->stats->tx_err);
28156 + atomic_inc_unchecked(&vcc->stats->tx_err);
28157 dev_kfree_skb(skb);
28158 return -EINVAL;
28159 }
28160 if (!test_bit(VCF_TX, &vc->flags)) {
28161 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28162 - atomic_inc(&vcc->stats->tx_err);
28163 + atomic_inc_unchecked(&vcc->stats->tx_err);
28164 dev_kfree_skb(skb);
28165 return -EINVAL;
28166 }
28167 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28168 break;
28169 default:
28170 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28171 - atomic_inc(&vcc->stats->tx_err);
28172 + atomic_inc_unchecked(&vcc->stats->tx_err);
28173 dev_kfree_skb(skb);
28174 return -EINVAL;
28175 }
28176
28177 if (skb_shinfo(skb)->nr_frags != 0) {
28178 printk("%s: No scatter-gather yet.\n", card->name);
28179 - atomic_inc(&vcc->stats->tx_err);
28180 + atomic_inc_unchecked(&vcc->stats->tx_err);
28181 dev_kfree_skb(skb);
28182 return -EINVAL;
28183 }
28184 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28185
28186 err = queue_skb(card, vc, skb, oam);
28187 if (err) {
28188 - atomic_inc(&vcc->stats->tx_err);
28189 + atomic_inc_unchecked(&vcc->stats->tx_err);
28190 dev_kfree_skb(skb);
28191 return err;
28192 }
28193 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28194 skb = dev_alloc_skb(64);
28195 if (!skb) {
28196 printk("%s: Out of memory in send_oam().\n", card->name);
28197 - atomic_inc(&vcc->stats->tx_err);
28198 + atomic_inc_unchecked(&vcc->stats->tx_err);
28199 return -ENOMEM;
28200 }
28201 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28202 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28203 index d438601..8b98495 100644
28204 --- a/drivers/atm/iphase.c
28205 +++ b/drivers/atm/iphase.c
28206 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28207 status = (u_short) (buf_desc_ptr->desc_mode);
28208 if (status & (RX_CER | RX_PTE | RX_OFL))
28209 {
28210 - atomic_inc(&vcc->stats->rx_err);
28211 + atomic_inc_unchecked(&vcc->stats->rx_err);
28212 IF_ERR(printk("IA: bad packet, dropping it");)
28213 if (status & RX_CER) {
28214 IF_ERR(printk(" cause: packet CRC error\n");)
28215 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28216 len = dma_addr - buf_addr;
28217 if (len > iadev->rx_buf_sz) {
28218 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28219 - atomic_inc(&vcc->stats->rx_err);
28220 + atomic_inc_unchecked(&vcc->stats->rx_err);
28221 goto out_free_desc;
28222 }
28223
28224 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28225 ia_vcc = INPH_IA_VCC(vcc);
28226 if (ia_vcc == NULL)
28227 {
28228 - atomic_inc(&vcc->stats->rx_err);
28229 + atomic_inc_unchecked(&vcc->stats->rx_err);
28230 atm_return(vcc, skb->truesize);
28231 dev_kfree_skb_any(skb);
28232 goto INCR_DLE;
28233 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28234 if ((length > iadev->rx_buf_sz) || (length >
28235 (skb->len - sizeof(struct cpcs_trailer))))
28236 {
28237 - atomic_inc(&vcc->stats->rx_err);
28238 + atomic_inc_unchecked(&vcc->stats->rx_err);
28239 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28240 length, skb->len);)
28241 atm_return(vcc, skb->truesize);
28242 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28243
28244 IF_RX(printk("rx_dle_intr: skb push");)
28245 vcc->push(vcc,skb);
28246 - atomic_inc(&vcc->stats->rx);
28247 + atomic_inc_unchecked(&vcc->stats->rx);
28248 iadev->rx_pkt_cnt++;
28249 }
28250 INCR_DLE:
28251 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28252 {
28253 struct k_sonet_stats *stats;
28254 stats = &PRIV(_ia_dev[board])->sonet_stats;
28255 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28256 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28257 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28258 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28259 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28260 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28261 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28262 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28263 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28264 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28265 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28266 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28267 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28268 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28269 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28270 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28271 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28272 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28273 }
28274 ia_cmds.status = 0;
28275 break;
28276 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28277 if ((desc == 0) || (desc > iadev->num_tx_desc))
28278 {
28279 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28280 - atomic_inc(&vcc->stats->tx);
28281 + atomic_inc_unchecked(&vcc->stats->tx);
28282 if (vcc->pop)
28283 vcc->pop(vcc, skb);
28284 else
28285 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28286 ATM_DESC(skb) = vcc->vci;
28287 skb_queue_tail(&iadev->tx_dma_q, skb);
28288
28289 - atomic_inc(&vcc->stats->tx);
28290 + atomic_inc_unchecked(&vcc->stats->tx);
28291 iadev->tx_pkt_cnt++;
28292 /* Increment transaction counter */
28293 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28294
28295 #if 0
28296 /* add flow control logic */
28297 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28298 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28299 if (iavcc->vc_desc_cnt > 10) {
28300 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28301 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28302 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28303 index 68c7588..7036683 100644
28304 --- a/drivers/atm/lanai.c
28305 +++ b/drivers/atm/lanai.c
28306 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28307 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28308 lanai_endtx(lanai, lvcc);
28309 lanai_free_skb(lvcc->tx.atmvcc, skb);
28310 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28311 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28312 }
28313
28314 /* Try to fill the buffer - don't call unless there is backlog */
28315 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28316 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28317 __net_timestamp(skb);
28318 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28319 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28320 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28321 out:
28322 lvcc->rx.buf.ptr = end;
28323 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28324 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28325 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28326 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28327 lanai->stats.service_rxnotaal5++;
28328 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28329 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28330 return 0;
28331 }
28332 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28333 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28334 int bytes;
28335 read_unlock(&vcc_sklist_lock);
28336 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28337 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28338 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28339 lvcc->stats.x.aal5.service_trash++;
28340 bytes = (SERVICE_GET_END(s) * 16) -
28341 (((unsigned long) lvcc->rx.buf.ptr) -
28342 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28343 }
28344 if (s & SERVICE_STREAM) {
28345 read_unlock(&vcc_sklist_lock);
28346 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28347 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28348 lvcc->stats.x.aal5.service_stream++;
28349 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28350 "PDU on VCI %d!\n", lanai->number, vci);
28351 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28352 return 0;
28353 }
28354 DPRINTK("got rx crc error on vci %d\n", vci);
28355 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28356 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28357 lvcc->stats.x.aal5.service_rxcrc++;
28358 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28359 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28360 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28361 index 1c70c45..300718d 100644
28362 --- a/drivers/atm/nicstar.c
28363 +++ b/drivers/atm/nicstar.c
28364 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28365 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28366 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28367 card->index);
28368 - atomic_inc(&vcc->stats->tx_err);
28369 + atomic_inc_unchecked(&vcc->stats->tx_err);
28370 dev_kfree_skb_any(skb);
28371 return -EINVAL;
28372 }
28373 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28374 if (!vc->tx) {
28375 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28376 card->index);
28377 - atomic_inc(&vcc->stats->tx_err);
28378 + atomic_inc_unchecked(&vcc->stats->tx_err);
28379 dev_kfree_skb_any(skb);
28380 return -EINVAL;
28381 }
28382 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28383 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28384 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28385 card->index);
28386 - atomic_inc(&vcc->stats->tx_err);
28387 + atomic_inc_unchecked(&vcc->stats->tx_err);
28388 dev_kfree_skb_any(skb);
28389 return -EINVAL;
28390 }
28391
28392 if (skb_shinfo(skb)->nr_frags != 0) {
28393 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28394 - atomic_inc(&vcc->stats->tx_err);
28395 + atomic_inc_unchecked(&vcc->stats->tx_err);
28396 dev_kfree_skb_any(skb);
28397 return -EINVAL;
28398 }
28399 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28400 }
28401
28402 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28403 - atomic_inc(&vcc->stats->tx_err);
28404 + atomic_inc_unchecked(&vcc->stats->tx_err);
28405 dev_kfree_skb_any(skb);
28406 return -EIO;
28407 }
28408 - atomic_inc(&vcc->stats->tx);
28409 + atomic_inc_unchecked(&vcc->stats->tx);
28410
28411 return 0;
28412 }
28413 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28414 printk
28415 ("nicstar%d: Can't allocate buffers for aal0.\n",
28416 card->index);
28417 - atomic_add(i, &vcc->stats->rx_drop);
28418 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28419 break;
28420 }
28421 if (!atm_charge(vcc, sb->truesize)) {
28422 RXPRINTK
28423 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28424 card->index);
28425 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28426 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28427 dev_kfree_skb_any(sb);
28428 break;
28429 }
28430 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28431 ATM_SKB(sb)->vcc = vcc;
28432 __net_timestamp(sb);
28433 vcc->push(vcc, sb);
28434 - atomic_inc(&vcc->stats->rx);
28435 + atomic_inc_unchecked(&vcc->stats->rx);
28436 cell += ATM_CELL_PAYLOAD;
28437 }
28438
28439 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28440 if (iovb == NULL) {
28441 printk("nicstar%d: Out of iovec buffers.\n",
28442 card->index);
28443 - atomic_inc(&vcc->stats->rx_drop);
28444 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28445 recycle_rx_buf(card, skb);
28446 return;
28447 }
28448 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28449 small or large buffer itself. */
28450 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28451 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28452 - atomic_inc(&vcc->stats->rx_err);
28453 + atomic_inc_unchecked(&vcc->stats->rx_err);
28454 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28455 NS_MAX_IOVECS);
28456 NS_PRV_IOVCNT(iovb) = 0;
28457 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28458 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28459 card->index);
28460 which_list(card, skb);
28461 - atomic_inc(&vcc->stats->rx_err);
28462 + atomic_inc_unchecked(&vcc->stats->rx_err);
28463 recycle_rx_buf(card, skb);
28464 vc->rx_iov = NULL;
28465 recycle_iov_buf(card, iovb);
28466 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28467 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28468 card->index);
28469 which_list(card, skb);
28470 - atomic_inc(&vcc->stats->rx_err);
28471 + atomic_inc_unchecked(&vcc->stats->rx_err);
28472 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28473 NS_PRV_IOVCNT(iovb));
28474 vc->rx_iov = NULL;
28475 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28476 printk(" - PDU size mismatch.\n");
28477 else
28478 printk(".\n");
28479 - atomic_inc(&vcc->stats->rx_err);
28480 + atomic_inc_unchecked(&vcc->stats->rx_err);
28481 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28482 NS_PRV_IOVCNT(iovb));
28483 vc->rx_iov = NULL;
28484 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28485 /* skb points to a small buffer */
28486 if (!atm_charge(vcc, skb->truesize)) {
28487 push_rxbufs(card, skb);
28488 - atomic_inc(&vcc->stats->rx_drop);
28489 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28490 } else {
28491 skb_put(skb, len);
28492 dequeue_sm_buf(card, skb);
28493 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28494 ATM_SKB(skb)->vcc = vcc;
28495 __net_timestamp(skb);
28496 vcc->push(vcc, skb);
28497 - atomic_inc(&vcc->stats->rx);
28498 + atomic_inc_unchecked(&vcc->stats->rx);
28499 }
28500 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28501 struct sk_buff *sb;
28502 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28503 if (len <= NS_SMBUFSIZE) {
28504 if (!atm_charge(vcc, sb->truesize)) {
28505 push_rxbufs(card, sb);
28506 - atomic_inc(&vcc->stats->rx_drop);
28507 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28508 } else {
28509 skb_put(sb, len);
28510 dequeue_sm_buf(card, sb);
28511 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28512 ATM_SKB(sb)->vcc = vcc;
28513 __net_timestamp(sb);
28514 vcc->push(vcc, sb);
28515 - atomic_inc(&vcc->stats->rx);
28516 + atomic_inc_unchecked(&vcc->stats->rx);
28517 }
28518
28519 push_rxbufs(card, skb);
28520 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28521
28522 if (!atm_charge(vcc, skb->truesize)) {
28523 push_rxbufs(card, skb);
28524 - atomic_inc(&vcc->stats->rx_drop);
28525 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28526 } else {
28527 dequeue_lg_buf(card, skb);
28528 #ifdef NS_USE_DESTRUCTORS
28529 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28530 ATM_SKB(skb)->vcc = vcc;
28531 __net_timestamp(skb);
28532 vcc->push(vcc, skb);
28533 - atomic_inc(&vcc->stats->rx);
28534 + atomic_inc_unchecked(&vcc->stats->rx);
28535 }
28536
28537 push_rxbufs(card, sb);
28538 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28539 printk
28540 ("nicstar%d: Out of huge buffers.\n",
28541 card->index);
28542 - atomic_inc(&vcc->stats->rx_drop);
28543 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28544 recycle_iovec_rx_bufs(card,
28545 (struct iovec *)
28546 iovb->data,
28547 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28548 card->hbpool.count++;
28549 } else
28550 dev_kfree_skb_any(hb);
28551 - atomic_inc(&vcc->stats->rx_drop);
28552 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28553 } else {
28554 /* Copy the small buffer to the huge buffer */
28555 sb = (struct sk_buff *)iov->iov_base;
28556 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28557 #endif /* NS_USE_DESTRUCTORS */
28558 __net_timestamp(hb);
28559 vcc->push(vcc, hb);
28560 - atomic_inc(&vcc->stats->rx);
28561 + atomic_inc_unchecked(&vcc->stats->rx);
28562 }
28563 }
28564
28565 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28566 index 9851093..adb2b1e 100644
28567 --- a/drivers/atm/solos-pci.c
28568 +++ b/drivers/atm/solos-pci.c
28569 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28570 }
28571 atm_charge(vcc, skb->truesize);
28572 vcc->push(vcc, skb);
28573 - atomic_inc(&vcc->stats->rx);
28574 + atomic_inc_unchecked(&vcc->stats->rx);
28575 break;
28576
28577 case PKT_STATUS:
28578 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28579 vcc = SKB_CB(oldskb)->vcc;
28580
28581 if (vcc) {
28582 - atomic_inc(&vcc->stats->tx);
28583 + atomic_inc_unchecked(&vcc->stats->tx);
28584 solos_pop(vcc, oldskb);
28585 } else
28586 dev_kfree_skb_irq(oldskb);
28587 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28588 index 0215934..ce9f5b1 100644
28589 --- a/drivers/atm/suni.c
28590 +++ b/drivers/atm/suni.c
28591 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28592
28593
28594 #define ADD_LIMITED(s,v) \
28595 - atomic_add((v),&stats->s); \
28596 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28597 + atomic_add_unchecked((v),&stats->s); \
28598 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28599
28600
28601 static void suni_hz(unsigned long from_timer)
28602 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28603 index 5120a96..e2572bd 100644
28604 --- a/drivers/atm/uPD98402.c
28605 +++ b/drivers/atm/uPD98402.c
28606 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28607 struct sonet_stats tmp;
28608 int error = 0;
28609
28610 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28611 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28612 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28613 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28614 if (zero && !error) {
28615 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28616
28617
28618 #define ADD_LIMITED(s,v) \
28619 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28620 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28621 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28622 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28623 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28624 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28625
28626
28627 static void stat_event(struct atm_dev *dev)
28628 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28629 if (reason & uPD98402_INT_PFM) stat_event(dev);
28630 if (reason & uPD98402_INT_PCO) {
28631 (void) GET(PCOCR); /* clear interrupt cause */
28632 - atomic_add(GET(HECCT),
28633 + atomic_add_unchecked(GET(HECCT),
28634 &PRIV(dev)->sonet_stats.uncorr_hcs);
28635 }
28636 if ((reason & uPD98402_INT_RFO) &&
28637 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28638 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28639 uPD98402_INT_LOS),PIMR); /* enable them */
28640 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28641 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28642 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28643 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28644 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28645 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28646 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28647 return 0;
28648 }
28649
28650 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28651 index abe4e20..83c4727 100644
28652 --- a/drivers/atm/zatm.c
28653 +++ b/drivers/atm/zatm.c
28654 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28655 }
28656 if (!size) {
28657 dev_kfree_skb_irq(skb);
28658 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28659 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28660 continue;
28661 }
28662 if (!atm_charge(vcc,skb->truesize)) {
28663 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28664 skb->len = size;
28665 ATM_SKB(skb)->vcc = vcc;
28666 vcc->push(vcc,skb);
28667 - atomic_inc(&vcc->stats->rx);
28668 + atomic_inc_unchecked(&vcc->stats->rx);
28669 }
28670 zout(pos & 0xffff,MTA(mbx));
28671 #if 0 /* probably a stupid idea */
28672 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28673 skb_queue_head(&zatm_vcc->backlog,skb);
28674 break;
28675 }
28676 - atomic_inc(&vcc->stats->tx);
28677 + atomic_inc_unchecked(&vcc->stats->tx);
28678 wake_up(&zatm_vcc->tx_wait);
28679 }
28680
28681 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28682 index 765c3a2..771ace6 100644
28683 --- a/drivers/base/devtmpfs.c
28684 +++ b/drivers/base/devtmpfs.c
28685 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28686 if (!thread)
28687 return 0;
28688
28689 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28690 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28691 if (err)
28692 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28693 else
28694 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28695 index cbb463b..babe2cf 100644
28696 --- a/drivers/base/power/wakeup.c
28697 +++ b/drivers/base/power/wakeup.c
28698 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
28699 * They need to be modified together atomically, so it's better to use one
28700 * atomic variable to hold them both.
28701 */
28702 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28703 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28704
28705 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28706 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28707
28708 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28709 {
28710 - unsigned int comb = atomic_read(&combined_event_count);
28711 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
28712
28713 *cnt = (comb >> IN_PROGRESS_BITS);
28714 *inpr = comb & MAX_IN_PROGRESS;
28715 @@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28716 ws->start_prevent_time = ws->last_time;
28717
28718 /* Increment the counter of events in progress. */
28719 - cec = atomic_inc_return(&combined_event_count);
28720 + cec = atomic_inc_return_unchecked(&combined_event_count);
28721
28722 trace_wakeup_source_activate(ws->name, cec);
28723 }
28724 @@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28725 * Increment the counter of registered wakeup events and decrement the
28726 * couter of wakeup events in progress simultaneously.
28727 */
28728 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
28729 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28730 trace_wakeup_source_deactivate(ws->name, cec);
28731
28732 split_counters(&cnt, &inpr);
28733 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28734 index b0f553b..77b928b 100644
28735 --- a/drivers/block/cciss.c
28736 +++ b/drivers/block/cciss.c
28737 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28738 int err;
28739 u32 cp;
28740
28741 + memset(&arg64, 0, sizeof(arg64));
28742 +
28743 err = 0;
28744 err |=
28745 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28746 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28747 while (!list_empty(&h->reqQ)) {
28748 c = list_entry(h->reqQ.next, CommandList_struct, list);
28749 /* can't do anything if fifo is full */
28750 - if ((h->access.fifo_full(h))) {
28751 + if ((h->access->fifo_full(h))) {
28752 dev_warn(&h->pdev->dev, "fifo full\n");
28753 break;
28754 }
28755 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28756 h->Qdepth--;
28757
28758 /* Tell the controller execute command */
28759 - h->access.submit_command(h, c);
28760 + h->access->submit_command(h, c);
28761
28762 /* Put job onto the completed Q */
28763 addQ(&h->cmpQ, c);
28764 @@ -3443,17 +3445,17 @@ startio:
28765
28766 static inline unsigned long get_next_completion(ctlr_info_t *h)
28767 {
28768 - return h->access.command_completed(h);
28769 + return h->access->command_completed(h);
28770 }
28771
28772 static inline int interrupt_pending(ctlr_info_t *h)
28773 {
28774 - return h->access.intr_pending(h);
28775 + return h->access->intr_pending(h);
28776 }
28777
28778 static inline long interrupt_not_for_us(ctlr_info_t *h)
28779 {
28780 - return ((h->access.intr_pending(h) == 0) ||
28781 + return ((h->access->intr_pending(h) == 0) ||
28782 (h->interrupts_enabled == 0));
28783 }
28784
28785 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28786 u32 a;
28787
28788 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28789 - return h->access.command_completed(h);
28790 + return h->access->command_completed(h);
28791
28792 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28793 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28794 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28795 trans_support & CFGTBL_Trans_use_short_tags);
28796
28797 /* Change the access methods to the performant access methods */
28798 - h->access = SA5_performant_access;
28799 + h->access = &SA5_performant_access;
28800 h->transMethod = CFGTBL_Trans_Performant;
28801
28802 return;
28803 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28804 if (prod_index < 0)
28805 return -ENODEV;
28806 h->product_name = products[prod_index].product_name;
28807 - h->access = *(products[prod_index].access);
28808 + h->access = products[prod_index].access;
28809
28810 if (cciss_board_disabled(h)) {
28811 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28812 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28813 }
28814
28815 /* make sure the board interrupts are off */
28816 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28817 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28818 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28819 if (rc)
28820 goto clean2;
28821 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28822 * fake ones to scoop up any residual completions.
28823 */
28824 spin_lock_irqsave(&h->lock, flags);
28825 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28826 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28827 spin_unlock_irqrestore(&h->lock, flags);
28828 free_irq(h->intr[h->intr_mode], h);
28829 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28830 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28831 dev_info(&h->pdev->dev, "Board READY.\n");
28832 dev_info(&h->pdev->dev,
28833 "Waiting for stale completions to drain.\n");
28834 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28835 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28836 msleep(10000);
28837 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28838 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28839
28840 rc = controller_reset_failed(h->cfgtable);
28841 if (rc)
28842 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28843 cciss_scsi_setup(h);
28844
28845 /* Turn the interrupts on so we can service requests */
28846 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28847 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28848
28849 /* Get the firmware version */
28850 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28851 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28852 kfree(flush_buf);
28853 if (return_code != IO_OK)
28854 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28855 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28856 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28857 free_irq(h->intr[h->intr_mode], h);
28858 }
28859
28860 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28861 index 7fda30e..eb5dfe0 100644
28862 --- a/drivers/block/cciss.h
28863 +++ b/drivers/block/cciss.h
28864 @@ -101,7 +101,7 @@ struct ctlr_info
28865 /* information about each logical volume */
28866 drive_info_struct *drv[CISS_MAX_LUN];
28867
28868 - struct access_method access;
28869 + struct access_method *access;
28870
28871 /* queue and queue Info */
28872 struct list_head reqQ;
28873 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28874 index 9125bbe..eede5c8 100644
28875 --- a/drivers/block/cpqarray.c
28876 +++ b/drivers/block/cpqarray.c
28877 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28878 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28879 goto Enomem4;
28880 }
28881 - hba[i]->access.set_intr_mask(hba[i], 0);
28882 + hba[i]->access->set_intr_mask(hba[i], 0);
28883 if (request_irq(hba[i]->intr, do_ida_intr,
28884 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28885 {
28886 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28887 add_timer(&hba[i]->timer);
28888
28889 /* Enable IRQ now that spinlock and rate limit timer are set up */
28890 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28891 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28892
28893 for(j=0; j<NWD; j++) {
28894 struct gendisk *disk = ida_gendisk[i][j];
28895 @@ -694,7 +694,7 @@ DBGINFO(
28896 for(i=0; i<NR_PRODUCTS; i++) {
28897 if (board_id == products[i].board_id) {
28898 c->product_name = products[i].product_name;
28899 - c->access = *(products[i].access);
28900 + c->access = products[i].access;
28901 break;
28902 }
28903 }
28904 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28905 hba[ctlr]->intr = intr;
28906 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28907 hba[ctlr]->product_name = products[j].product_name;
28908 - hba[ctlr]->access = *(products[j].access);
28909 + hba[ctlr]->access = products[j].access;
28910 hba[ctlr]->ctlr = ctlr;
28911 hba[ctlr]->board_id = board_id;
28912 hba[ctlr]->pci_dev = NULL; /* not PCI */
28913 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28914
28915 while((c = h->reqQ) != NULL) {
28916 /* Can't do anything if we're busy */
28917 - if (h->access.fifo_full(h) == 0)
28918 + if (h->access->fifo_full(h) == 0)
28919 return;
28920
28921 /* Get the first entry from the request Q */
28922 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28923 h->Qdepth--;
28924
28925 /* Tell the controller to do our bidding */
28926 - h->access.submit_command(h, c);
28927 + h->access->submit_command(h, c);
28928
28929 /* Get onto the completion Q */
28930 addQ(&h->cmpQ, c);
28931 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28932 unsigned long flags;
28933 __u32 a,a1;
28934
28935 - istat = h->access.intr_pending(h);
28936 + istat = h->access->intr_pending(h);
28937 /* Is this interrupt for us? */
28938 if (istat == 0)
28939 return IRQ_NONE;
28940 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28941 */
28942 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
28943 if (istat & FIFO_NOT_EMPTY) {
28944 - while((a = h->access.command_completed(h))) {
28945 + while((a = h->access->command_completed(h))) {
28946 a1 = a; a &= ~3;
28947 if ((c = h->cmpQ) == NULL)
28948 {
28949 @@ -1449,11 +1449,11 @@ static int sendcmd(
28950 /*
28951 * Disable interrupt
28952 */
28953 - info_p->access.set_intr_mask(info_p, 0);
28954 + info_p->access->set_intr_mask(info_p, 0);
28955 /* Make sure there is room in the command FIFO */
28956 /* Actually it should be completely empty at this time. */
28957 for (i = 200000; i > 0; i--) {
28958 - temp = info_p->access.fifo_full(info_p);
28959 + temp = info_p->access->fifo_full(info_p);
28960 if (temp != 0) {
28961 break;
28962 }
28963 @@ -1466,7 +1466,7 @@ DBG(
28964 /*
28965 * Send the cmd
28966 */
28967 - info_p->access.submit_command(info_p, c);
28968 + info_p->access->submit_command(info_p, c);
28969 complete = pollcomplete(ctlr);
28970
28971 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
28972 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
28973 * we check the new geometry. Then turn interrupts back on when
28974 * we're done.
28975 */
28976 - host->access.set_intr_mask(host, 0);
28977 + host->access->set_intr_mask(host, 0);
28978 getgeometry(ctlr);
28979 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
28980 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
28981
28982 for(i=0; i<NWD; i++) {
28983 struct gendisk *disk = ida_gendisk[ctlr][i];
28984 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
28985 /* Wait (up to 2 seconds) for a command to complete */
28986
28987 for (i = 200000; i > 0; i--) {
28988 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
28989 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
28990 if (done == 0) {
28991 udelay(10); /* a short fixed delay */
28992 } else
28993 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
28994 index be73e9d..7fbf140 100644
28995 --- a/drivers/block/cpqarray.h
28996 +++ b/drivers/block/cpqarray.h
28997 @@ -99,7 +99,7 @@ struct ctlr_info {
28998 drv_info_t drv[NWD];
28999 struct proc_dir_entry *proc;
29000
29001 - struct access_method access;
29002 + struct access_method *access;
29003
29004 cmdlist_t *reqQ;
29005 cmdlist_t *cmpQ;
29006 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29007 index 02f013a..afeba24 100644
29008 --- a/drivers/block/drbd/drbd_int.h
29009 +++ b/drivers/block/drbd/drbd_int.h
29010 @@ -735,7 +735,7 @@ struct drbd_request;
29011 struct drbd_epoch {
29012 struct list_head list;
29013 unsigned int barrier_nr;
29014 - atomic_t epoch_size; /* increased on every request added. */
29015 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29016 atomic_t active; /* increased on every req. added, and dec on every finished. */
29017 unsigned long flags;
29018 };
29019 @@ -1110,7 +1110,7 @@ struct drbd_conf {
29020 void *int_dig_in;
29021 void *int_dig_vv;
29022 wait_queue_head_t seq_wait;
29023 - atomic_t packet_seq;
29024 + atomic_unchecked_t packet_seq;
29025 unsigned int peer_seq;
29026 spinlock_t peer_seq_lock;
29027 unsigned int minor;
29028 @@ -1651,30 +1651,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29029
29030 static inline void drbd_tcp_cork(struct socket *sock)
29031 {
29032 - int __user val = 1;
29033 + int val = 1;
29034 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29035 - (char __user *)&val, sizeof(val));
29036 + (char __force_user *)&val, sizeof(val));
29037 }
29038
29039 static inline void drbd_tcp_uncork(struct socket *sock)
29040 {
29041 - int __user val = 0;
29042 + int val = 0;
29043 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29044 - (char __user *)&val, sizeof(val));
29045 + (char __force_user *)&val, sizeof(val));
29046 }
29047
29048 static inline void drbd_tcp_nodelay(struct socket *sock)
29049 {
29050 - int __user val = 1;
29051 + int val = 1;
29052 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29053 - (char __user *)&val, sizeof(val));
29054 + (char __force_user *)&val, sizeof(val));
29055 }
29056
29057 static inline void drbd_tcp_quickack(struct socket *sock)
29058 {
29059 - int __user val = 2;
29060 + int val = 2;
29061 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29062 - (char __user *)&val, sizeof(val));
29063 + (char __force_user *)&val, sizeof(val));
29064 }
29065
29066 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29067 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29068 index 920ede2..cb827ba 100644
29069 --- a/drivers/block/drbd/drbd_main.c
29070 +++ b/drivers/block/drbd/drbd_main.c
29071 @@ -2555,7 +2555,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29072 p.sector = sector;
29073 p.block_id = block_id;
29074 p.blksize = blksize;
29075 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29076 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29077
29078 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29079 return false;
29080 @@ -2853,7 +2853,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29081
29082 p.sector = cpu_to_be64(req->sector);
29083 p.block_id = (unsigned long)req;
29084 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29085 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29086
29087 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29088
29089 @@ -3138,7 +3138,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29090 atomic_set(&mdev->unacked_cnt, 0);
29091 atomic_set(&mdev->local_cnt, 0);
29092 atomic_set(&mdev->net_cnt, 0);
29093 - atomic_set(&mdev->packet_seq, 0);
29094 + atomic_set_unchecked(&mdev->packet_seq, 0);
29095 atomic_set(&mdev->pp_in_use, 0);
29096 atomic_set(&mdev->pp_in_use_by_net, 0);
29097 atomic_set(&mdev->rs_sect_in, 0);
29098 @@ -3220,8 +3220,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29099 mdev->receiver.t_state);
29100
29101 /* no need to lock it, I'm the only thread alive */
29102 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29103 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29104 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29105 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29106 mdev->al_writ_cnt =
29107 mdev->bm_writ_cnt =
29108 mdev->read_cnt =
29109 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29110 index 6d4de6a..7b7ad4b 100644
29111 --- a/drivers/block/drbd/drbd_nl.c
29112 +++ b/drivers/block/drbd/drbd_nl.c
29113 @@ -2387,7 +2387,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29114 module_put(THIS_MODULE);
29115 }
29116
29117 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29118 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29119
29120 static unsigned short *
29121 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29122 @@ -2458,7 +2458,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29123 cn_reply->id.idx = CN_IDX_DRBD;
29124 cn_reply->id.val = CN_VAL_DRBD;
29125
29126 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29127 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29128 cn_reply->ack = 0; /* not used here. */
29129 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29130 (int)((char *)tl - (char *)reply->tag_list);
29131 @@ -2490,7 +2490,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29132 cn_reply->id.idx = CN_IDX_DRBD;
29133 cn_reply->id.val = CN_VAL_DRBD;
29134
29135 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29136 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29137 cn_reply->ack = 0; /* not used here. */
29138 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29139 (int)((char *)tl - (char *)reply->tag_list);
29140 @@ -2568,7 +2568,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29141 cn_reply->id.idx = CN_IDX_DRBD;
29142 cn_reply->id.val = CN_VAL_DRBD;
29143
29144 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29145 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29146 cn_reply->ack = 0; // not used here.
29147 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29148 (int)((char*)tl - (char*)reply->tag_list);
29149 @@ -2607,7 +2607,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29150 cn_reply->id.idx = CN_IDX_DRBD;
29151 cn_reply->id.val = CN_VAL_DRBD;
29152
29153 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29154 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29155 cn_reply->ack = 0; /* not used here. */
29156 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29157 (int)((char *)tl - (char *)reply->tag_list);
29158 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29159 index ea4836e..272d72a 100644
29160 --- a/drivers/block/drbd/drbd_receiver.c
29161 +++ b/drivers/block/drbd/drbd_receiver.c
29162 @@ -893,7 +893,7 @@ retry:
29163 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29164 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29165
29166 - atomic_set(&mdev->packet_seq, 0);
29167 + atomic_set_unchecked(&mdev->packet_seq, 0);
29168 mdev->peer_seq = 0;
29169
29170 if (drbd_send_protocol(mdev) == -1)
29171 @@ -994,7 +994,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29172 do {
29173 next_epoch = NULL;
29174
29175 - epoch_size = atomic_read(&epoch->epoch_size);
29176 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29177
29178 switch (ev & ~EV_CLEANUP) {
29179 case EV_PUT:
29180 @@ -1030,7 +1030,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29181 rv = FE_DESTROYED;
29182 } else {
29183 epoch->flags = 0;
29184 - atomic_set(&epoch->epoch_size, 0);
29185 + atomic_set_unchecked(&epoch->epoch_size, 0);
29186 /* atomic_set(&epoch->active, 0); is already zero */
29187 if (rv == FE_STILL_LIVE)
29188 rv = FE_RECYCLED;
29189 @@ -1205,14 +1205,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29190 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29191 drbd_flush(mdev);
29192
29193 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29194 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29195 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29196 if (epoch)
29197 break;
29198 }
29199
29200 epoch = mdev->current_epoch;
29201 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29202 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29203
29204 D_ASSERT(atomic_read(&epoch->active) == 0);
29205 D_ASSERT(epoch->flags == 0);
29206 @@ -1224,11 +1224,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29207 }
29208
29209 epoch->flags = 0;
29210 - atomic_set(&epoch->epoch_size, 0);
29211 + atomic_set_unchecked(&epoch->epoch_size, 0);
29212 atomic_set(&epoch->active, 0);
29213
29214 spin_lock(&mdev->epoch_lock);
29215 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29216 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29217 list_add(&epoch->list, &mdev->current_epoch->list);
29218 mdev->current_epoch = epoch;
29219 mdev->epochs++;
29220 @@ -1695,7 +1695,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29221 spin_unlock(&mdev->peer_seq_lock);
29222
29223 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29224 - atomic_inc(&mdev->current_epoch->epoch_size);
29225 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29226 return drbd_drain_block(mdev, data_size);
29227 }
29228
29229 @@ -1721,7 +1721,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29230
29231 spin_lock(&mdev->epoch_lock);
29232 e->epoch = mdev->current_epoch;
29233 - atomic_inc(&e->epoch->epoch_size);
29234 + atomic_inc_unchecked(&e->epoch->epoch_size);
29235 atomic_inc(&e->epoch->active);
29236 spin_unlock(&mdev->epoch_lock);
29237
29238 @@ -3936,7 +3936,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29239 D_ASSERT(list_empty(&mdev->done_ee));
29240
29241 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29242 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29243 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29244 D_ASSERT(list_empty(&mdev->current_epoch->list));
29245 }
29246
29247 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29248 index 3bba655..6151b66 100644
29249 --- a/drivers/block/loop.c
29250 +++ b/drivers/block/loop.c
29251 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29252 mm_segment_t old_fs = get_fs();
29253
29254 set_fs(get_ds());
29255 - bw = file->f_op->write(file, buf, len, &pos);
29256 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29257 set_fs(old_fs);
29258 if (likely(bw == len))
29259 return 0;
29260 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29261 index ea6f632..eafb192 100644
29262 --- a/drivers/char/Kconfig
29263 +++ b/drivers/char/Kconfig
29264 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29265
29266 config DEVKMEM
29267 bool "/dev/kmem virtual device support"
29268 - default y
29269 + default n
29270 + depends on !GRKERNSEC_KMEM
29271 help
29272 Say Y here if you want to support the /dev/kmem device. The
29273 /dev/kmem device is rarely used, but can be used for certain
29274 @@ -581,6 +582,7 @@ config DEVPORT
29275 bool
29276 depends on !M68K
29277 depends on ISA || PCI
29278 + depends on !GRKERNSEC_KMEM
29279 default y
29280
29281 source "drivers/s390/char/Kconfig"
29282 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29283 index 2e04433..22afc64 100644
29284 --- a/drivers/char/agp/frontend.c
29285 +++ b/drivers/char/agp/frontend.c
29286 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29287 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29288 return -EFAULT;
29289
29290 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29291 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29292 return -EFAULT;
29293
29294 client = agp_find_client_by_pid(reserve.pid);
29295 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29296 index 21cb980..f15107c 100644
29297 --- a/drivers/char/genrtc.c
29298 +++ b/drivers/char/genrtc.c
29299 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29300 switch (cmd) {
29301
29302 case RTC_PLL_GET:
29303 + memset(&pll, 0, sizeof(pll));
29304 if (get_rtc_pll(&pll))
29305 return -EINVAL;
29306 else
29307 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29308 index dfd7876..c0b0885 100644
29309 --- a/drivers/char/hpet.c
29310 +++ b/drivers/char/hpet.c
29311 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29312 }
29313
29314 static int
29315 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29316 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29317 struct hpet_info *info)
29318 {
29319 struct hpet_timer __iomem *timer;
29320 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29321 index 2c29942..604c5ba 100644
29322 --- a/drivers/char/ipmi/ipmi_msghandler.c
29323 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29324 @@ -420,7 +420,7 @@ struct ipmi_smi {
29325 struct proc_dir_entry *proc_dir;
29326 char proc_dir_name[10];
29327
29328 - atomic_t stats[IPMI_NUM_STATS];
29329 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29330
29331 /*
29332 * run_to_completion duplicate of smb_info, smi_info
29333 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29334
29335
29336 #define ipmi_inc_stat(intf, stat) \
29337 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29338 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29339 #define ipmi_get_stat(intf, stat) \
29340 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29341 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29342
29343 static int is_lan_addr(struct ipmi_addr *addr)
29344 {
29345 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29346 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29347 init_waitqueue_head(&intf->waitq);
29348 for (i = 0; i < IPMI_NUM_STATS; i++)
29349 - atomic_set(&intf->stats[i], 0);
29350 + atomic_set_unchecked(&intf->stats[i], 0);
29351
29352 intf->proc_dir = NULL;
29353
29354 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29355 index 1e638ff..a869ef5 100644
29356 --- a/drivers/char/ipmi/ipmi_si_intf.c
29357 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29358 @@ -275,7 +275,7 @@ struct smi_info {
29359 unsigned char slave_addr;
29360
29361 /* Counters and things for the proc filesystem. */
29362 - atomic_t stats[SI_NUM_STATS];
29363 + atomic_unchecked_t stats[SI_NUM_STATS];
29364
29365 struct task_struct *thread;
29366
29367 @@ -284,9 +284,9 @@ struct smi_info {
29368 };
29369
29370 #define smi_inc_stat(smi, stat) \
29371 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29372 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29373 #define smi_get_stat(smi, stat) \
29374 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29375 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29376
29377 #define SI_MAX_PARMS 4
29378
29379 @@ -3209,7 +3209,7 @@ static int try_smi_init(struct smi_info *new_smi)
29380 atomic_set(&new_smi->req_events, 0);
29381 new_smi->run_to_completion = 0;
29382 for (i = 0; i < SI_NUM_STATS; i++)
29383 - atomic_set(&new_smi->stats[i], 0);
29384 + atomic_set_unchecked(&new_smi->stats[i], 0);
29385
29386 new_smi->interrupt_disabled = 1;
29387 atomic_set(&new_smi->stop_operation, 0);
29388 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29389 index 47ff7e4..0c7d340 100644
29390 --- a/drivers/char/mbcs.c
29391 +++ b/drivers/char/mbcs.c
29392 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29393 return 0;
29394 }
29395
29396 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29397 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29398 {
29399 .part_num = MBCS_PART_NUM,
29400 .mfg_num = MBCS_MFG_NUM,
29401 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29402 index 67c3371..ba8429d 100644
29403 --- a/drivers/char/mem.c
29404 +++ b/drivers/char/mem.c
29405 @@ -18,6 +18,7 @@
29406 #include <linux/raw.h>
29407 #include <linux/tty.h>
29408 #include <linux/capability.h>
29409 +#include <linux/security.h>
29410 #include <linux/ptrace.h>
29411 #include <linux/device.h>
29412 #include <linux/highmem.h>
29413 @@ -35,6 +36,10 @@
29414 # include <linux/efi.h>
29415 #endif
29416
29417 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29418 +extern const struct file_operations grsec_fops;
29419 +#endif
29420 +
29421 static inline unsigned long size_inside_page(unsigned long start,
29422 unsigned long size)
29423 {
29424 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29425
29426 while (cursor < to) {
29427 if (!devmem_is_allowed(pfn)) {
29428 +#ifdef CONFIG_GRKERNSEC_KMEM
29429 + gr_handle_mem_readwrite(from, to);
29430 +#else
29431 printk(KERN_INFO
29432 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29433 current->comm, from, to);
29434 +#endif
29435 return 0;
29436 }
29437 cursor += PAGE_SIZE;
29438 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29439 }
29440 return 1;
29441 }
29442 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29443 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29444 +{
29445 + return 0;
29446 +}
29447 #else
29448 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29449 {
29450 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29451
29452 while (count > 0) {
29453 unsigned long remaining;
29454 + char *temp;
29455
29456 sz = size_inside_page(p, count);
29457
29458 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29459 if (!ptr)
29460 return -EFAULT;
29461
29462 - remaining = copy_to_user(buf, ptr, sz);
29463 +#ifdef CONFIG_PAX_USERCOPY
29464 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29465 + if (!temp) {
29466 + unxlate_dev_mem_ptr(p, ptr);
29467 + return -ENOMEM;
29468 + }
29469 + memcpy(temp, ptr, sz);
29470 +#else
29471 + temp = ptr;
29472 +#endif
29473 +
29474 + remaining = copy_to_user(buf, temp, sz);
29475 +
29476 +#ifdef CONFIG_PAX_USERCOPY
29477 + kfree(temp);
29478 +#endif
29479 +
29480 unxlate_dev_mem_ptr(p, ptr);
29481 if (remaining)
29482 return -EFAULT;
29483 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29484 size_t count, loff_t *ppos)
29485 {
29486 unsigned long p = *ppos;
29487 - ssize_t low_count, read, sz;
29488 + ssize_t low_count, read, sz, err = 0;
29489 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29490 - int err = 0;
29491
29492 read = 0;
29493 if (p < (unsigned long) high_memory) {
29494 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29495 }
29496 #endif
29497 while (low_count > 0) {
29498 + char *temp;
29499 +
29500 sz = size_inside_page(p, low_count);
29501
29502 /*
29503 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29504 */
29505 kbuf = xlate_dev_kmem_ptr((char *)p);
29506
29507 - if (copy_to_user(buf, kbuf, sz))
29508 +#ifdef CONFIG_PAX_USERCOPY
29509 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29510 + if (!temp)
29511 + return -ENOMEM;
29512 + memcpy(temp, kbuf, sz);
29513 +#else
29514 + temp = kbuf;
29515 +#endif
29516 +
29517 + err = copy_to_user(buf, temp, sz);
29518 +
29519 +#ifdef CONFIG_PAX_USERCOPY
29520 + kfree(temp);
29521 +#endif
29522 +
29523 + if (err)
29524 return -EFAULT;
29525 buf += sz;
29526 p += sz;
29527 @@ -831,6 +878,9 @@ static const struct memdev {
29528 #ifdef CONFIG_CRASH_DUMP
29529 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29530 #endif
29531 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29532 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29533 +#endif
29534 };
29535
29536 static int memory_open(struct inode *inode, struct file *filp)
29537 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29538 index 9df78e2..01ba9ae 100644
29539 --- a/drivers/char/nvram.c
29540 +++ b/drivers/char/nvram.c
29541 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29542
29543 spin_unlock_irq(&rtc_lock);
29544
29545 - if (copy_to_user(buf, contents, tmp - contents))
29546 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29547 return -EFAULT;
29548
29549 *ppos = i;
29550 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29551 index 0a484b4..f48ccd1 100644
29552 --- a/drivers/char/pcmcia/synclink_cs.c
29553 +++ b/drivers/char/pcmcia/synclink_cs.c
29554 @@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29555
29556 if (debug_level >= DEBUG_LEVEL_INFO)
29557 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29558 - __FILE__,__LINE__, info->device_name, port->count);
29559 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29560
29561 - WARN_ON(!port->count);
29562 + WARN_ON(!atomic_read(&port->count));
29563
29564 if (tty_port_close_start(port, tty, filp) == 0)
29565 goto cleanup;
29566 @@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29567 cleanup:
29568 if (debug_level >= DEBUG_LEVEL_INFO)
29569 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29570 - tty->driver->name, port->count);
29571 + tty->driver->name, atomic_read(&port->count));
29572 }
29573
29574 /* Wait until the transmitter is empty.
29575 @@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29576
29577 if (debug_level >= DEBUG_LEVEL_INFO)
29578 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29579 - __FILE__,__LINE__,tty->driver->name, port->count);
29580 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29581
29582 /* If port is closing, signal caller to try again */
29583 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29584 @@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29585 goto cleanup;
29586 }
29587 spin_lock(&port->lock);
29588 - port->count++;
29589 + atomic_inc(&port->count);
29590 spin_unlock(&port->lock);
29591 spin_unlock_irqrestore(&info->netlock, flags);
29592
29593 - if (port->count == 1) {
29594 + if (atomic_read(&port->count) == 1) {
29595 /* 1st open on this device, init hardware */
29596 retval = startup(info, tty);
29597 if (retval < 0)
29598 @@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29599 unsigned short new_crctype;
29600
29601 /* return error if TTY interface open */
29602 - if (info->port.count)
29603 + if (atomic_read(&info->port.count))
29604 return -EBUSY;
29605
29606 switch (encoding)
29607 @@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29608
29609 /* arbitrate between network and tty opens */
29610 spin_lock_irqsave(&info->netlock, flags);
29611 - if (info->port.count != 0 || info->netcount != 0) {
29612 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29613 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29614 spin_unlock_irqrestore(&info->netlock, flags);
29615 return -EBUSY;
29616 @@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29617 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29618
29619 /* return error if TTY interface open */
29620 - if (info->port.count)
29621 + if (atomic_read(&info->port.count))
29622 return -EBUSY;
29623
29624 if (cmd != SIOCWANDEV)
29625 diff --git a/drivers/char/random.c b/drivers/char/random.c
29626 index 4ec04a7..9918387 100644
29627 --- a/drivers/char/random.c
29628 +++ b/drivers/char/random.c
29629 @@ -261,8 +261,13 @@
29630 /*
29631 * Configuration information
29632 */
29633 +#ifdef CONFIG_GRKERNSEC_RANDNET
29634 +#define INPUT_POOL_WORDS 512
29635 +#define OUTPUT_POOL_WORDS 128
29636 +#else
29637 #define INPUT_POOL_WORDS 128
29638 #define OUTPUT_POOL_WORDS 32
29639 +#endif
29640 #define SEC_XFER_SIZE 512
29641 #define EXTRACT_SIZE 10
29642
29643 @@ -300,10 +305,17 @@ static struct poolinfo {
29644 int poolwords;
29645 int tap1, tap2, tap3, tap4, tap5;
29646 } poolinfo_table[] = {
29647 +#ifdef CONFIG_GRKERNSEC_RANDNET
29648 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29649 + { 512, 411, 308, 208, 104, 1 },
29650 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29651 + { 128, 103, 76, 51, 25, 1 },
29652 +#else
29653 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29654 { 128, 103, 76, 51, 25, 1 },
29655 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29656 { 32, 26, 20, 14, 7, 1 },
29657 +#endif
29658 #if 0
29659 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29660 { 2048, 1638, 1231, 819, 411, 1 },
29661 @@ -726,6 +738,17 @@ void add_disk_randomness(struct gendisk *disk)
29662 }
29663 #endif
29664
29665 +#ifdef CONFIG_PAX_LATENT_ENTROPY
29666 +u64 latent_entropy;
29667 +
29668 +__init void transfer_latent_entropy(void)
29669 +{
29670 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy));
29671 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy));
29672 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29673 +}
29674 +#endif
29675 +
29676 /*********************************************************************
29677 *
29678 * Entropy extraction routines
29679 @@ -913,7 +936,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29680
29681 extract_buf(r, tmp);
29682 i = min_t(int, nbytes, EXTRACT_SIZE);
29683 - if (copy_to_user(buf, tmp, i)) {
29684 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29685 ret = -EFAULT;
29686 break;
29687 }
29688 @@ -1238,7 +1261,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29689 #include <linux/sysctl.h>
29690
29691 static int min_read_thresh = 8, min_write_thresh;
29692 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29693 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29694 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29695 static char sysctl_bootid[16];
29696
29697 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29698 index 45713f0..8286d21 100644
29699 --- a/drivers/char/sonypi.c
29700 +++ b/drivers/char/sonypi.c
29701 @@ -54,6 +54,7 @@
29702
29703 #include <asm/uaccess.h>
29704 #include <asm/io.h>
29705 +#include <asm/local.h>
29706
29707 #include <linux/sonypi.h>
29708
29709 @@ -490,7 +491,7 @@ static struct sonypi_device {
29710 spinlock_t fifo_lock;
29711 wait_queue_head_t fifo_proc_list;
29712 struct fasync_struct *fifo_async;
29713 - int open_count;
29714 + local_t open_count;
29715 int model;
29716 struct input_dev *input_jog_dev;
29717 struct input_dev *input_key_dev;
29718 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29719 static int sonypi_misc_release(struct inode *inode, struct file *file)
29720 {
29721 mutex_lock(&sonypi_device.lock);
29722 - sonypi_device.open_count--;
29723 + local_dec(&sonypi_device.open_count);
29724 mutex_unlock(&sonypi_device.lock);
29725 return 0;
29726 }
29727 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29728 {
29729 mutex_lock(&sonypi_device.lock);
29730 /* Flush input queue on first open */
29731 - if (!sonypi_device.open_count)
29732 + if (!local_read(&sonypi_device.open_count))
29733 kfifo_reset(&sonypi_device.fifo);
29734 - sonypi_device.open_count++;
29735 + local_inc(&sonypi_device.open_count);
29736 mutex_unlock(&sonypi_device.lock);
29737
29738 return 0;
29739 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29740 index 08427ab..1ab10b7 100644
29741 --- a/drivers/char/tpm/tpm.c
29742 +++ b/drivers/char/tpm/tpm.c
29743 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29744 chip->vendor.req_complete_val)
29745 goto out_recv;
29746
29747 - if ((status == chip->vendor.req_canceled)) {
29748 + if (status == chip->vendor.req_canceled) {
29749 dev_err(chip->dev, "Operation Canceled\n");
29750 rc = -ECANCELED;
29751 goto out;
29752 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29753 index 0636520..169c1d0 100644
29754 --- a/drivers/char/tpm/tpm_bios.c
29755 +++ b/drivers/char/tpm/tpm_bios.c
29756 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29757 event = addr;
29758
29759 if ((event->event_type == 0 && event->event_size == 0) ||
29760 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29761 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29762 return NULL;
29763
29764 return addr;
29765 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29766 return NULL;
29767
29768 if ((event->event_type == 0 && event->event_size == 0) ||
29769 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29770 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29771 return NULL;
29772
29773 (*pos)++;
29774 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29775 int i;
29776
29777 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29778 - seq_putc(m, data[i]);
29779 + if (!seq_putc(m, data[i]))
29780 + return -EFAULT;
29781
29782 return 0;
29783 }
29784 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29785 log->bios_event_log_end = log->bios_event_log + len;
29786
29787 virt = acpi_os_map_memory(start, len);
29788 + if (!virt) {
29789 + kfree(log->bios_event_log);
29790 + log->bios_event_log = NULL;
29791 + return -EFAULT;
29792 + }
29793
29794 - memcpy(log->bios_event_log, virt, len);
29795 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29796
29797 acpi_os_unmap_memory(virt, len);
29798 return 0;
29799 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29800 index cdf2f54..e55c197 100644
29801 --- a/drivers/char/virtio_console.c
29802 +++ b/drivers/char/virtio_console.c
29803 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29804 if (to_user) {
29805 ssize_t ret;
29806
29807 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29808 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29809 if (ret)
29810 return -EFAULT;
29811 } else {
29812 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29813 if (!port_has_data(port) && !port->host_connected)
29814 return 0;
29815
29816 - return fill_readbuf(port, ubuf, count, true);
29817 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29818 }
29819
29820 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29821 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29822 index 97f5064..202b6e6 100644
29823 --- a/drivers/edac/edac_pci_sysfs.c
29824 +++ b/drivers/edac/edac_pci_sysfs.c
29825 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29826 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29827 static int edac_pci_poll_msec = 1000; /* one second workq period */
29828
29829 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
29830 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29831 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29832 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29833
29834 static struct kobject *edac_pci_top_main_kobj;
29835 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29836 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29837 edac_printk(KERN_CRIT, EDAC_PCI,
29838 "Signaled System Error on %s\n",
29839 pci_name(dev));
29840 - atomic_inc(&pci_nonparity_count);
29841 + atomic_inc_unchecked(&pci_nonparity_count);
29842 }
29843
29844 if (status & (PCI_STATUS_PARITY)) {
29845 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29846 "Master Data Parity Error on %s\n",
29847 pci_name(dev));
29848
29849 - atomic_inc(&pci_parity_count);
29850 + atomic_inc_unchecked(&pci_parity_count);
29851 }
29852
29853 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29854 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29855 "Detected Parity Error on %s\n",
29856 pci_name(dev));
29857
29858 - atomic_inc(&pci_parity_count);
29859 + atomic_inc_unchecked(&pci_parity_count);
29860 }
29861 }
29862
29863 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29864 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29865 "Signaled System Error on %s\n",
29866 pci_name(dev));
29867 - atomic_inc(&pci_nonparity_count);
29868 + atomic_inc_unchecked(&pci_nonparity_count);
29869 }
29870
29871 if (status & (PCI_STATUS_PARITY)) {
29872 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29873 "Master Data Parity Error on "
29874 "%s\n", pci_name(dev));
29875
29876 - atomic_inc(&pci_parity_count);
29877 + atomic_inc_unchecked(&pci_parity_count);
29878 }
29879
29880 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29881 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29882 "Detected Parity Error on %s\n",
29883 pci_name(dev));
29884
29885 - atomic_inc(&pci_parity_count);
29886 + atomic_inc_unchecked(&pci_parity_count);
29887 }
29888 }
29889 }
29890 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29891 if (!check_pci_errors)
29892 return;
29893
29894 - before_count = atomic_read(&pci_parity_count);
29895 + before_count = atomic_read_unchecked(&pci_parity_count);
29896
29897 /* scan all PCI devices looking for a Parity Error on devices and
29898 * bridges.
29899 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29900 /* Only if operator has selected panic on PCI Error */
29901 if (edac_pci_get_panic_on_pe()) {
29902 /* If the count is different 'after' from 'before' */
29903 - if (before_count != atomic_read(&pci_parity_count))
29904 + if (before_count != atomic_read_unchecked(&pci_parity_count))
29905 panic("EDAC: PCI Parity Error");
29906 }
29907 }
29908 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29909 index 8c87a5e..a19cbd7 100644
29910 --- a/drivers/edac/mce_amd.h
29911 +++ b/drivers/edac/mce_amd.h
29912 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
29913 struct amd_decoder_ops {
29914 bool (*dc_mce)(u16, u8);
29915 bool (*ic_mce)(u16, u8);
29916 -};
29917 +} __no_const;
29918
29919 void amd_report_gart_errors(bool);
29920 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29921 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29922 index 57ea7f4..789e3c3 100644
29923 --- a/drivers/firewire/core-card.c
29924 +++ b/drivers/firewire/core-card.c
29925 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
29926
29927 void fw_core_remove_card(struct fw_card *card)
29928 {
29929 - struct fw_card_driver dummy_driver = dummy_driver_template;
29930 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
29931
29932 card->driver->update_phy_reg(card, 4,
29933 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29934 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29935 index 2783f69..9f4b0cc 100644
29936 --- a/drivers/firewire/core-cdev.c
29937 +++ b/drivers/firewire/core-cdev.c
29938 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
29939 int ret;
29940
29941 if ((request->channels == 0 && request->bandwidth == 0) ||
29942 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29943 - request->bandwidth < 0)
29944 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29945 return -EINVAL;
29946
29947 r = kmalloc(sizeof(*r), GFP_KERNEL);
29948 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
29949 index 780708d..ad60a66 100644
29950 --- a/drivers/firewire/core-transaction.c
29951 +++ b/drivers/firewire/core-transaction.c
29952 @@ -37,6 +37,7 @@
29953 #include <linux/timer.h>
29954 #include <linux/types.h>
29955 #include <linux/workqueue.h>
29956 +#include <linux/sched.h>
29957
29958 #include <asm/byteorder.h>
29959
29960 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
29961 index 515a42c..5ecf3ba 100644
29962 --- a/drivers/firewire/core.h
29963 +++ b/drivers/firewire/core.h
29964 @@ -111,6 +111,7 @@ struct fw_card_driver {
29965
29966 int (*stop_iso)(struct fw_iso_context *ctx);
29967 };
29968 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
29969
29970 void fw_card_initialize(struct fw_card *card,
29971 const struct fw_card_driver *driver, struct device *device);
29972 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
29973 index 153980b..4b4d046 100644
29974 --- a/drivers/firmware/dmi_scan.c
29975 +++ b/drivers/firmware/dmi_scan.c
29976 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
29977 }
29978 }
29979 else {
29980 - /*
29981 - * no iounmap() for that ioremap(); it would be a no-op, but
29982 - * it's so early in setup that sucker gets confused into doing
29983 - * what it shouldn't if we actually call it.
29984 - */
29985 p = dmi_ioremap(0xF0000, 0x10000);
29986 if (p == NULL)
29987 goto error;
29988 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
29989 if (buf == NULL)
29990 return -1;
29991
29992 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
29993 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
29994
29995 iounmap(buf);
29996 return 0;
29997 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
29998 index 82d5c20..44a7177 100644
29999 --- a/drivers/gpio/gpio-vr41xx.c
30000 +++ b/drivers/gpio/gpio-vr41xx.c
30001 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30002 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30003 maskl, pendl, maskh, pendh);
30004
30005 - atomic_inc(&irq_err_count);
30006 + atomic_inc_unchecked(&irq_err_count);
30007
30008 return -EINVAL;
30009 }
30010 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30011 index 3252e70..b5314ace 100644
30012 --- a/drivers/gpu/drm/drm_crtc_helper.c
30013 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30014 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30015 struct drm_crtc *tmp;
30016 int crtc_mask = 1;
30017
30018 - WARN(!crtc, "checking null crtc?\n");
30019 + BUG_ON(!crtc);
30020
30021 dev = crtc->dev;
30022
30023 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30024 index 8a9d079..606cdd5 100644
30025 --- a/drivers/gpu/drm/drm_drv.c
30026 +++ b/drivers/gpu/drm/drm_drv.c
30027 @@ -318,7 +318,7 @@ module_exit(drm_core_exit);
30028 /**
30029 * Copy and IOCTL return string to user space
30030 */
30031 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30032 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30033 {
30034 int len;
30035
30036 @@ -401,7 +401,7 @@ long drm_ioctl(struct file *filp,
30037 return -ENODEV;
30038
30039 atomic_inc(&dev->ioctl_count);
30040 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30041 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30042 ++file_priv->ioctl_count;
30043
30044 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30045 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30046 index 123de28..43a0897 100644
30047 --- a/drivers/gpu/drm/drm_fops.c
30048 +++ b/drivers/gpu/drm/drm_fops.c
30049 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30050 }
30051
30052 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30053 - atomic_set(&dev->counts[i], 0);
30054 + atomic_set_unchecked(&dev->counts[i], 0);
30055
30056 dev->sigdata.lock = NULL;
30057
30058 @@ -138,8 +138,8 @@ int drm_open(struct inode *inode, struct file *filp)
30059
30060 retcode = drm_open_helper(inode, filp, dev);
30061 if (!retcode) {
30062 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30063 - if (!dev->open_count++)
30064 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30065 + if (local_inc_return(&dev->open_count) == 1)
30066 retcode = drm_setup(dev);
30067 }
30068 if (!retcode) {
30069 @@ -482,7 +482,7 @@ int drm_release(struct inode *inode, struct file *filp)
30070
30071 mutex_lock(&drm_global_mutex);
30072
30073 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30074 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30075
30076 if (dev->driver->preclose)
30077 dev->driver->preclose(dev, file_priv);
30078 @@ -491,10 +491,10 @@ int drm_release(struct inode *inode, struct file *filp)
30079 * Begin inline drm_release
30080 */
30081
30082 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30083 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30084 task_pid_nr(current),
30085 (long)old_encode_dev(file_priv->minor->device),
30086 - dev->open_count);
30087 + local_read(&dev->open_count));
30088
30089 /* Release any auth tokens that might point to this file_priv,
30090 (do that under the drm_global_mutex) */
30091 @@ -584,8 +584,8 @@ int drm_release(struct inode *inode, struct file *filp)
30092 * End inline drm_release
30093 */
30094
30095 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30096 - if (!--dev->open_count) {
30097 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30098 + if (local_dec_and_test(&dev->open_count)) {
30099 if (atomic_read(&dev->ioctl_count)) {
30100 DRM_ERROR("Device busy: %d\n",
30101 atomic_read(&dev->ioctl_count));
30102 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30103 index c87dc96..326055d 100644
30104 --- a/drivers/gpu/drm/drm_global.c
30105 +++ b/drivers/gpu/drm/drm_global.c
30106 @@ -36,7 +36,7 @@
30107 struct drm_global_item {
30108 struct mutex mutex;
30109 void *object;
30110 - int refcount;
30111 + atomic_t refcount;
30112 };
30113
30114 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30115 @@ -49,7 +49,7 @@ void drm_global_init(void)
30116 struct drm_global_item *item = &glob[i];
30117 mutex_init(&item->mutex);
30118 item->object = NULL;
30119 - item->refcount = 0;
30120 + atomic_set(&item->refcount, 0);
30121 }
30122 }
30123
30124 @@ -59,7 +59,7 @@ void drm_global_release(void)
30125 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30126 struct drm_global_item *item = &glob[i];
30127 BUG_ON(item->object != NULL);
30128 - BUG_ON(item->refcount != 0);
30129 + BUG_ON(atomic_read(&item->refcount) != 0);
30130 }
30131 }
30132
30133 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30134 void *object;
30135
30136 mutex_lock(&item->mutex);
30137 - if (item->refcount == 0) {
30138 + if (atomic_read(&item->refcount) == 0) {
30139 item->object = kzalloc(ref->size, GFP_KERNEL);
30140 if (unlikely(item->object == NULL)) {
30141 ret = -ENOMEM;
30142 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30143 goto out_err;
30144
30145 }
30146 - ++item->refcount;
30147 + atomic_inc(&item->refcount);
30148 ref->object = item->object;
30149 object = item->object;
30150 mutex_unlock(&item->mutex);
30151 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30152 struct drm_global_item *item = &glob[ref->global_type];
30153
30154 mutex_lock(&item->mutex);
30155 - BUG_ON(item->refcount == 0);
30156 + BUG_ON(atomic_read(&item->refcount) == 0);
30157 BUG_ON(ref->object != item->object);
30158 - if (--item->refcount == 0) {
30159 + if (atomic_dec_and_test(&item->refcount)) {
30160 ref->release(ref);
30161 item->object = NULL;
30162 }
30163 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30164 index ab1162d..42587b2 100644
30165 --- a/drivers/gpu/drm/drm_info.c
30166 +++ b/drivers/gpu/drm/drm_info.c
30167 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30168 struct drm_local_map *map;
30169 struct drm_map_list *r_list;
30170
30171 - /* Hardcoded from _DRM_FRAME_BUFFER,
30172 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30173 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30174 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30175 + static const char * const types[] = {
30176 + [_DRM_FRAME_BUFFER] = "FB",
30177 + [_DRM_REGISTERS] = "REG",
30178 + [_DRM_SHM] = "SHM",
30179 + [_DRM_AGP] = "AGP",
30180 + [_DRM_SCATTER_GATHER] = "SG",
30181 + [_DRM_CONSISTENT] = "PCI",
30182 + [_DRM_GEM] = "GEM" };
30183 const char *type;
30184 int i;
30185
30186 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30187 map = r_list->map;
30188 if (!map)
30189 continue;
30190 - if (map->type < 0 || map->type > 5)
30191 + if (map->type >= ARRAY_SIZE(types))
30192 type = "??";
30193 else
30194 type = types[map->type];
30195 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30196 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30197 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30198 vma->vm_flags & VM_IO ? 'i' : '-',
30199 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30200 + 0);
30201 +#else
30202 vma->vm_pgoff);
30203 +#endif
30204
30205 #if defined(__i386__)
30206 pgprot = pgprot_val(vma->vm_page_prot);
30207 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30208 index 637fcc3..e890b33 100644
30209 --- a/drivers/gpu/drm/drm_ioc32.c
30210 +++ b/drivers/gpu/drm/drm_ioc32.c
30211 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30212 request = compat_alloc_user_space(nbytes);
30213 if (!access_ok(VERIFY_WRITE, request, nbytes))
30214 return -EFAULT;
30215 - list = (struct drm_buf_desc *) (request + 1);
30216 + list = (struct drm_buf_desc __user *) (request + 1);
30217
30218 if (__put_user(count, &request->count)
30219 || __put_user(list, &request->list))
30220 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30221 request = compat_alloc_user_space(nbytes);
30222 if (!access_ok(VERIFY_WRITE, request, nbytes))
30223 return -EFAULT;
30224 - list = (struct drm_buf_pub *) (request + 1);
30225 + list = (struct drm_buf_pub __user *) (request + 1);
30226
30227 if (__put_user(count, &request->count)
30228 || __put_user(list, &request->list))
30229 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30230 index 64a62c6..ceab35e 100644
30231 --- a/drivers/gpu/drm/drm_ioctl.c
30232 +++ b/drivers/gpu/drm/drm_ioctl.c
30233 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30234 stats->data[i].value =
30235 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30236 else
30237 - stats->data[i].value = atomic_read(&dev->counts[i]);
30238 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30239 stats->data[i].type = dev->types[i];
30240 }
30241
30242 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30243 index 5211520..c744d85 100644
30244 --- a/drivers/gpu/drm/drm_lock.c
30245 +++ b/drivers/gpu/drm/drm_lock.c
30246 @@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30247 if (drm_lock_take(&master->lock, lock->context)) {
30248 master->lock.file_priv = file_priv;
30249 master->lock.lock_time = jiffies;
30250 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30251 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30252 break; /* Got lock */
30253 }
30254
30255 @@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30256 return -EINVAL;
30257 }
30258
30259 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30260 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30261
30262 if (drm_lock_free(&master->lock, lock->context)) {
30263 /* FIXME: Should really bail out here. */
30264 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30265 index 21bcd4a..8e074e0 100644
30266 --- a/drivers/gpu/drm/drm_stub.c
30267 +++ b/drivers/gpu/drm/drm_stub.c
30268 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30269
30270 drm_device_set_unplugged(dev);
30271
30272 - if (dev->open_count == 0) {
30273 + if (local_read(&dev->open_count) == 0) {
30274 drm_put_dev(dev);
30275 }
30276 mutex_unlock(&drm_global_mutex);
30277 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30278 index fa94391..ed26ec8 100644
30279 --- a/drivers/gpu/drm/i810/i810_dma.c
30280 +++ b/drivers/gpu/drm/i810/i810_dma.c
30281 @@ -943,8 +943,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30282 dma->buflist[vertex->idx],
30283 vertex->discard, vertex->used);
30284
30285 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30286 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30287 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30288 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30289 sarea_priv->last_enqueue = dev_priv->counter - 1;
30290 sarea_priv->last_dispatch = (int)hw_status[5];
30291
30292 @@ -1104,8 +1104,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30293 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30294 mc->last_render);
30295
30296 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30297 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30298 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30299 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30300 sarea_priv->last_enqueue = dev_priv->counter - 1;
30301 sarea_priv->last_dispatch = (int)hw_status[5];
30302
30303 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30304 index c9339f4..f5e1b9d 100644
30305 --- a/drivers/gpu/drm/i810/i810_drv.h
30306 +++ b/drivers/gpu/drm/i810/i810_drv.h
30307 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30308 int page_flipping;
30309
30310 wait_queue_head_t irq_queue;
30311 - atomic_t irq_received;
30312 - atomic_t irq_emitted;
30313 + atomic_unchecked_t irq_received;
30314 + atomic_unchecked_t irq_emitted;
30315
30316 int front_offset;
30317 } drm_i810_private_t;
30318 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30319 index 5363e9c..59360d1 100644
30320 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30321 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30322 @@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30323 I915_READ(GTIMR));
30324 }
30325 seq_printf(m, "Interrupts received: %d\n",
30326 - atomic_read(&dev_priv->irq_received));
30327 + atomic_read_unchecked(&dev_priv->irq_received));
30328 for (i = 0; i < I915_NUM_RINGS; i++) {
30329 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30330 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30331 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30332 index 36822b9..b725e1b 100644
30333 --- a/drivers/gpu/drm/i915/i915_dma.c
30334 +++ b/drivers/gpu/drm/i915/i915_dma.c
30335 @@ -1266,7 +1266,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30336 bool can_switch;
30337
30338 spin_lock(&dev->count_lock);
30339 - can_switch = (dev->open_count == 0);
30340 + can_switch = (local_read(&dev->open_count) == 0);
30341 spin_unlock(&dev->count_lock);
30342 return can_switch;
30343 }
30344 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30345 index b0b676a..d107105 100644
30346 --- a/drivers/gpu/drm/i915/i915_drv.h
30347 +++ b/drivers/gpu/drm/i915/i915_drv.h
30348 @@ -268,7 +268,7 @@ struct drm_i915_display_funcs {
30349 /* render clock increase/decrease */
30350 /* display clock increase/decrease */
30351 /* pll clock increase/decrease */
30352 -};
30353 +} __no_const;
30354
30355 struct intel_device_info {
30356 u8 gen;
30357 @@ -386,7 +386,7 @@ typedef struct drm_i915_private {
30358 int current_page;
30359 int page_flipping;
30360
30361 - atomic_t irq_received;
30362 + atomic_unchecked_t irq_received;
30363
30364 /* protects the irq masks */
30365 spinlock_t irq_lock;
30366 @@ -985,7 +985,7 @@ struct drm_i915_gem_object {
30367 * will be page flipped away on the next vblank. When it
30368 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30369 */
30370 - atomic_t pending_flip;
30371 + atomic_unchecked_t pending_flip;
30372 };
30373
30374 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30375 @@ -1434,7 +1434,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30376 struct drm_i915_private *dev_priv, unsigned port);
30377 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30378 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30379 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30380 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30381 {
30382 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30383 }
30384 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30385 index 974a9f1..b3ebd45 100644
30386 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30387 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30388 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30389 i915_gem_clflush_object(obj);
30390
30391 if (obj->base.pending_write_domain)
30392 - cd->flips |= atomic_read(&obj->pending_flip);
30393 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30394
30395 /* The actual obj->write_domain will be updated with
30396 * pending_write_domain after we emit the accumulated flush for all
30397 @@ -916,9 +916,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30398
30399 static int
30400 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30401 - int count)
30402 + unsigned int count)
30403 {
30404 - int i;
30405 + unsigned int i;
30406
30407 for (i = 0; i < count; i++) {
30408 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30409 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30410 index ed3224c..6618589 100644
30411 --- a/drivers/gpu/drm/i915/i915_irq.c
30412 +++ b/drivers/gpu/drm/i915/i915_irq.c
30413 @@ -433,7 +433,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30414 int vblank = 0;
30415 bool blc_event;
30416
30417 - atomic_inc(&dev_priv->irq_received);
30418 + atomic_inc_unchecked(&dev_priv->irq_received);
30419
30420 vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS |
30421 PIPE_VBLANK_INTERRUPT_STATUS;
30422 @@ -586,7 +586,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30423 irqreturn_t ret = IRQ_NONE;
30424 int i;
30425
30426 - atomic_inc(&dev_priv->irq_received);
30427 + atomic_inc_unchecked(&dev_priv->irq_received);
30428
30429 /* disable master interrupt before clearing iir */
30430 de_ier = I915_READ(DEIER);
30431 @@ -661,7 +661,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30432 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30433 u32 hotplug_mask;
30434
30435 - atomic_inc(&dev_priv->irq_received);
30436 + atomic_inc_unchecked(&dev_priv->irq_received);
30437
30438 /* disable master interrupt before clearing iir */
30439 de_ier = I915_READ(DEIER);
30440 @@ -1646,7 +1646,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30441 {
30442 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30443
30444 - atomic_set(&dev_priv->irq_received, 0);
30445 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30446
30447
30448 I915_WRITE(HWSTAM, 0xeffe);
30449 @@ -1673,7 +1673,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30450 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30451 int pipe;
30452
30453 - atomic_set(&dev_priv->irq_received, 0);
30454 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30455
30456 /* VLV magic */
30457 I915_WRITE(VLV_IMR, 0);
30458 @@ -1969,7 +1969,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30459 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30460 int pipe;
30461
30462 - atomic_set(&dev_priv->irq_received, 0);
30463 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30464
30465 for_each_pipe(pipe)
30466 I915_WRITE(PIPESTAT(pipe), 0);
30467 @@ -2020,7 +2020,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30468 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30469 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30470
30471 - atomic_inc(&dev_priv->irq_received);
30472 + atomic_inc_unchecked(&dev_priv->irq_received);
30473
30474 iir = I915_READ16(IIR);
30475 if (iir == 0)
30476 @@ -2105,7 +2105,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30477 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30478 int pipe;
30479
30480 - atomic_set(&dev_priv->irq_received, 0);
30481 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30482
30483 if (I915_HAS_HOTPLUG(dev)) {
30484 I915_WRITE(PORT_HOTPLUG_EN, 0);
30485 @@ -2200,7 +2200,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30486 };
30487 int pipe, ret = IRQ_NONE;
30488
30489 - atomic_inc(&dev_priv->irq_received);
30490 + atomic_inc_unchecked(&dev_priv->irq_received);
30491
30492 iir = I915_READ(IIR);
30493 do {
30494 @@ -2326,7 +2326,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30495 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30496 int pipe;
30497
30498 - atomic_set(&dev_priv->irq_received, 0);
30499 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30500
30501 if (I915_HAS_HOTPLUG(dev)) {
30502 I915_WRITE(PORT_HOTPLUG_EN, 0);
30503 @@ -2436,7 +2436,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30504 int irq_received;
30505 int ret = IRQ_NONE, pipe;
30506
30507 - atomic_inc(&dev_priv->irq_received);
30508 + atomic_inc_unchecked(&dev_priv->irq_received);
30509
30510 iir = I915_READ(IIR);
30511
30512 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30513 index a8538ac..4868a05 100644
30514 --- a/drivers/gpu/drm/i915/intel_display.c
30515 +++ b/drivers/gpu/drm/i915/intel_display.c
30516 @@ -2000,7 +2000,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30517
30518 wait_event(dev_priv->pending_flip_queue,
30519 atomic_read(&dev_priv->mm.wedged) ||
30520 - atomic_read(&obj->pending_flip) == 0);
30521 + atomic_read_unchecked(&obj->pending_flip) == 0);
30522
30523 /* Big Hammer, we also need to ensure that any pending
30524 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30525 @@ -5925,9 +5925,8 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30526
30527 obj = work->old_fb_obj;
30528
30529 - atomic_clear_mask(1 << intel_crtc->plane,
30530 - &obj->pending_flip.counter);
30531 - if (atomic_read(&obj->pending_flip) == 0)
30532 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
30533 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
30534 wake_up(&dev_priv->pending_flip_queue);
30535
30536 schedule_work(&work->work);
30537 @@ -6264,7 +6263,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30538 /* Block clients from rendering to the new back buffer until
30539 * the flip occurs and the object is no longer visible.
30540 */
30541 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30542 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30543
30544 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30545 if (ret)
30546 @@ -6279,7 +6278,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30547 return 0;
30548
30549 cleanup_pending:
30550 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30551 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30552 drm_gem_object_unreference(&work->old_fb_obj->base);
30553 drm_gem_object_unreference(&obj->base);
30554 mutex_unlock(&dev->struct_mutex);
30555 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30556 index 54558a0..2d97005 100644
30557 --- a/drivers/gpu/drm/mga/mga_drv.h
30558 +++ b/drivers/gpu/drm/mga/mga_drv.h
30559 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30560 u32 clear_cmd;
30561 u32 maccess;
30562
30563 - atomic_t vbl_received; /**< Number of vblanks received. */
30564 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30565 wait_queue_head_t fence_queue;
30566 - atomic_t last_fence_retired;
30567 + atomic_unchecked_t last_fence_retired;
30568 u32 next_fence_to_post;
30569
30570 unsigned int fb_cpp;
30571 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30572 index 2581202..f230a8d9 100644
30573 --- a/drivers/gpu/drm/mga/mga_irq.c
30574 +++ b/drivers/gpu/drm/mga/mga_irq.c
30575 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30576 if (crtc != 0)
30577 return 0;
30578
30579 - return atomic_read(&dev_priv->vbl_received);
30580 + return atomic_read_unchecked(&dev_priv->vbl_received);
30581 }
30582
30583
30584 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30585 /* VBLANK interrupt */
30586 if (status & MGA_VLINEPEN) {
30587 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30588 - atomic_inc(&dev_priv->vbl_received);
30589 + atomic_inc_unchecked(&dev_priv->vbl_received);
30590 drm_handle_vblank(dev, 0);
30591 handled = 1;
30592 }
30593 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30594 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30595 MGA_WRITE(MGA_PRIMEND, prim_end);
30596
30597 - atomic_inc(&dev_priv->last_fence_retired);
30598 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30599 DRM_WAKEUP(&dev_priv->fence_queue);
30600 handled = 1;
30601 }
30602 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30603 * using fences.
30604 */
30605 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30606 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30607 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30608 - *sequence) <= (1 << 23)));
30609
30610 *sequence = cur_fence;
30611 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30612 index 2f11e16..191267e 100644
30613 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30614 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30615 @@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30616 struct bit_table {
30617 const char id;
30618 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30619 -};
30620 +} __no_const;
30621
30622 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30623
30624 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30625 index b863a3a..c55e0dc 100644
30626 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30627 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30628 @@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30629 u32 handle, u16 class);
30630 void (*set_tile_region)(struct drm_device *dev, int i);
30631 void (*tlb_flush)(struct drm_device *, int engine);
30632 -};
30633 +} __no_const;
30634
30635 struct nouveau_instmem_engine {
30636 void *priv;
30637 @@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30638 struct nouveau_mc_engine {
30639 int (*init)(struct drm_device *dev);
30640 void (*takedown)(struct drm_device *dev);
30641 -};
30642 +} __no_const;
30643
30644 struct nouveau_timer_engine {
30645 int (*init)(struct drm_device *dev);
30646 void (*takedown)(struct drm_device *dev);
30647 uint64_t (*read)(struct drm_device *dev);
30648 -};
30649 +} __no_const;
30650
30651 struct nouveau_fb_engine {
30652 int num_tiles;
30653 @@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30654 void (*put)(struct drm_device *, struct nouveau_mem **);
30655
30656 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30657 -};
30658 +} __no_const;
30659
30660 struct nouveau_engine {
30661 struct nouveau_instmem_engine instmem;
30662 @@ -693,7 +693,7 @@ struct drm_nouveau_private {
30663 struct drm_global_reference mem_global_ref;
30664 struct ttm_bo_global_ref bo_global_ref;
30665 struct ttm_bo_device bdev;
30666 - atomic_t validate_sequence;
30667 + atomic_unchecked_t validate_sequence;
30668 int (*move)(struct nouveau_channel *,
30669 struct ttm_buffer_object *,
30670 struct ttm_mem_reg *, struct ttm_mem_reg *);
30671 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30672 index 30f5423..abca136 100644
30673 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30674 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30675 @@ -319,7 +319,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30676 int trycnt = 0;
30677 int ret, i;
30678
30679 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30680 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30681 retry:
30682 if (++trycnt > 100000) {
30683 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30684 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30685 index 19706f0..f257368 100644
30686 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30687 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30688 @@ -490,7 +490,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30689 bool can_switch;
30690
30691 spin_lock(&dev->count_lock);
30692 - can_switch = (dev->open_count == 0);
30693 + can_switch = (local_read(&dev->open_count) == 0);
30694 spin_unlock(&dev->count_lock);
30695 return can_switch;
30696 }
30697 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30698 index a9514ea..369d511 100644
30699 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
30700 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
30701 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
30702 }
30703
30704 if (nv_encoder->dcb->type == OUTPUT_DP) {
30705 - struct dp_train_func func = {
30706 + static struct dp_train_func func = {
30707 .link_set = nv50_sor_dp_link_set,
30708 .train_set = nv50_sor_dp_train_set,
30709 .train_adj = nv50_sor_dp_train_adj
30710 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
30711 index c486d3c..3a7d6f4 100644
30712 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
30713 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
30714 @@ -1366,7 +1366,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
30715 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
30716
30717 if (nv_encoder->dcb->type == OUTPUT_DP) {
30718 - struct dp_train_func func = {
30719 + static struct dp_train_func func = {
30720 .link_set = nvd0_sor_dp_link_set,
30721 .train_set = nvd0_sor_dp_train_set,
30722 .train_adj = nvd0_sor_dp_train_adj
30723 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30724 index bcac90b..53bfc76 100644
30725 --- a/drivers/gpu/drm/r128/r128_cce.c
30726 +++ b/drivers/gpu/drm/r128/r128_cce.c
30727 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30728
30729 /* GH: Simple idle check.
30730 */
30731 - atomic_set(&dev_priv->idle_count, 0);
30732 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30733
30734 /* We don't support anything other than bus-mastering ring mode,
30735 * but the ring can be in either AGP or PCI space for the ring
30736 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30737 index 930c71b..499aded 100644
30738 --- a/drivers/gpu/drm/r128/r128_drv.h
30739 +++ b/drivers/gpu/drm/r128/r128_drv.h
30740 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30741 int is_pci;
30742 unsigned long cce_buffers_offset;
30743
30744 - atomic_t idle_count;
30745 + atomic_unchecked_t idle_count;
30746
30747 int page_flipping;
30748 int current_page;
30749 u32 crtc_offset;
30750 u32 crtc_offset_cntl;
30751
30752 - atomic_t vbl_received;
30753 + atomic_unchecked_t vbl_received;
30754
30755 u32 color_fmt;
30756 unsigned int front_offset;
30757 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30758 index 429d5a0..7e899ed 100644
30759 --- a/drivers/gpu/drm/r128/r128_irq.c
30760 +++ b/drivers/gpu/drm/r128/r128_irq.c
30761 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30762 if (crtc != 0)
30763 return 0;
30764
30765 - return atomic_read(&dev_priv->vbl_received);
30766 + return atomic_read_unchecked(&dev_priv->vbl_received);
30767 }
30768
30769 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30770 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30771 /* VBLANK interrupt */
30772 if (status & R128_CRTC_VBLANK_INT) {
30773 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30774 - atomic_inc(&dev_priv->vbl_received);
30775 + atomic_inc_unchecked(&dev_priv->vbl_received);
30776 drm_handle_vblank(dev, 0);
30777 return IRQ_HANDLED;
30778 }
30779 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30780 index a9e33ce..09edd4b 100644
30781 --- a/drivers/gpu/drm/r128/r128_state.c
30782 +++ b/drivers/gpu/drm/r128/r128_state.c
30783 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30784
30785 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30786 {
30787 - if (atomic_read(&dev_priv->idle_count) == 0)
30788 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30789 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30790 else
30791 - atomic_set(&dev_priv->idle_count, 0);
30792 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30793 }
30794
30795 #endif
30796 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30797 index 5a82b6b..9e69c73 100644
30798 --- a/drivers/gpu/drm/radeon/mkregtable.c
30799 +++ b/drivers/gpu/drm/radeon/mkregtable.c
30800 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30801 regex_t mask_rex;
30802 regmatch_t match[4];
30803 char buf[1024];
30804 - size_t end;
30805 + long end;
30806 int len;
30807 int done = 0;
30808 int r;
30809 unsigned o;
30810 struct offset *offset;
30811 char last_reg_s[10];
30812 - int last_reg;
30813 + unsigned long last_reg;
30814
30815 if (regcomp
30816 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30817 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30818 index fefcca5..20a5b90 100644
30819 --- a/drivers/gpu/drm/radeon/radeon.h
30820 +++ b/drivers/gpu/drm/radeon/radeon.h
30821 @@ -743,7 +743,7 @@ struct r600_blit_cp_primitives {
30822 int x2, int y2);
30823 void (*draw_auto)(struct radeon_device *rdev);
30824 void (*set_default_state)(struct radeon_device *rdev);
30825 -};
30826 +} __no_const;
30827
30828 struct r600_blit {
30829 struct radeon_bo *shader_obj;
30830 @@ -1244,7 +1244,7 @@ struct radeon_asic {
30831 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30832 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30833 } pflip;
30834 -};
30835 +} __no_const;
30836
30837 /*
30838 * Asic structures
30839 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30840 index 066c98b..96ab858 100644
30841 --- a/drivers/gpu/drm/radeon/radeon_device.c
30842 +++ b/drivers/gpu/drm/radeon/radeon_device.c
30843 @@ -692,7 +692,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30844 bool can_switch;
30845
30846 spin_lock(&dev->count_lock);
30847 - can_switch = (dev->open_count == 0);
30848 + can_switch = (local_read(&dev->open_count) == 0);
30849 spin_unlock(&dev->count_lock);
30850 return can_switch;
30851 }
30852 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30853 index a1b59ca..86f2d44 100644
30854 --- a/drivers/gpu/drm/radeon/radeon_drv.h
30855 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
30856 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30857
30858 /* SW interrupt */
30859 wait_queue_head_t swi_queue;
30860 - atomic_t swi_emitted;
30861 + atomic_unchecked_t swi_emitted;
30862 int vblank_crtc;
30863 uint32_t irq_enable_reg;
30864 uint32_t r500_disp_irq_reg;
30865 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30866 index 48b7cea..342236f 100644
30867 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30868 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30869 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30870 request = compat_alloc_user_space(sizeof(*request));
30871 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30872 || __put_user(req32.param, &request->param)
30873 - || __put_user((void __user *)(unsigned long)req32.value,
30874 + || __put_user((unsigned long)req32.value,
30875 &request->value))
30876 return -EFAULT;
30877
30878 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30879 index 00da384..32f972d 100644
30880 --- a/drivers/gpu/drm/radeon/radeon_irq.c
30881 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
30882 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30883 unsigned int ret;
30884 RING_LOCALS;
30885
30886 - atomic_inc(&dev_priv->swi_emitted);
30887 - ret = atomic_read(&dev_priv->swi_emitted);
30888 + atomic_inc_unchecked(&dev_priv->swi_emitted);
30889 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30890
30891 BEGIN_RING(4);
30892 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30893 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30894 drm_radeon_private_t *dev_priv =
30895 (drm_radeon_private_t *) dev->dev_private;
30896
30897 - atomic_set(&dev_priv->swi_emitted, 0);
30898 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30899 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30900
30901 dev->max_vblank_count = 0x001fffff;
30902 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30903 index e8422ae..d22d4a8 100644
30904 --- a/drivers/gpu/drm/radeon/radeon_state.c
30905 +++ b/drivers/gpu/drm/radeon/radeon_state.c
30906 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30907 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30908 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30909
30910 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30911 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30912 sarea_priv->nbox * sizeof(depth_boxes[0])))
30913 return -EFAULT;
30914
30915 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30916 {
30917 drm_radeon_private_t *dev_priv = dev->dev_private;
30918 drm_radeon_getparam_t *param = data;
30919 - int value;
30920 + int value = 0;
30921
30922 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30923
30924 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30925 index c94a225..5795d34 100644
30926 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
30927 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30928 @@ -852,8 +852,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30929 }
30930 if (unlikely(ttm_vm_ops == NULL)) {
30931 ttm_vm_ops = vma->vm_ops;
30932 - radeon_ttm_vm_ops = *ttm_vm_ops;
30933 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30934 + pax_open_kernel();
30935 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
30936 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30937 + pax_close_kernel();
30938 }
30939 vma->vm_ops = &radeon_ttm_vm_ops;
30940 return 0;
30941 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
30942 index 159b6a4..fa82487 100644
30943 --- a/drivers/gpu/drm/radeon/rs690.c
30944 +++ b/drivers/gpu/drm/radeon/rs690.c
30945 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
30946 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
30947 rdev->pm.sideport_bandwidth.full)
30948 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
30949 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
30950 + read_delay_latency.full = dfixed_const(800 * 1000);
30951 read_delay_latency.full = dfixed_div(read_delay_latency,
30952 rdev->pm.igp_sideport_mclk);
30953 + a.full = dfixed_const(370);
30954 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
30955 } else {
30956 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
30957 rdev->pm.k8_bandwidth.full)
30958 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30959 index ebc6fac..a8313ed 100644
30960 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
30961 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30962 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
30963 static int ttm_pool_mm_shrink(struct shrinker *shrink,
30964 struct shrink_control *sc)
30965 {
30966 - static atomic_t start_pool = ATOMIC_INIT(0);
30967 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
30968 unsigned i;
30969 - unsigned pool_offset = atomic_add_return(1, &start_pool);
30970 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
30971 struct ttm_page_pool *pool;
30972 int shrink_pages = sc->nr_to_scan;
30973
30974 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
30975 index 88edacc..1e5412b 100644
30976 --- a/drivers/gpu/drm/via/via_drv.h
30977 +++ b/drivers/gpu/drm/via/via_drv.h
30978 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
30979 typedef uint32_t maskarray_t[5];
30980
30981 typedef struct drm_via_irq {
30982 - atomic_t irq_received;
30983 + atomic_unchecked_t irq_received;
30984 uint32_t pending_mask;
30985 uint32_t enable_mask;
30986 wait_queue_head_t irq_queue;
30987 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
30988 struct timeval last_vblank;
30989 int last_vblank_valid;
30990 unsigned usec_per_vblank;
30991 - atomic_t vbl_received;
30992 + atomic_unchecked_t vbl_received;
30993 drm_via_state_t hc_state;
30994 char pci_buf[VIA_PCI_BUF_SIZE];
30995 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
30996 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
30997 index d391f48..10c8ca3 100644
30998 --- a/drivers/gpu/drm/via/via_irq.c
30999 +++ b/drivers/gpu/drm/via/via_irq.c
31000 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31001 if (crtc != 0)
31002 return 0;
31003
31004 - return atomic_read(&dev_priv->vbl_received);
31005 + return atomic_read_unchecked(&dev_priv->vbl_received);
31006 }
31007
31008 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31009 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31010
31011 status = VIA_READ(VIA_REG_INTERRUPT);
31012 if (status & VIA_IRQ_VBLANK_PENDING) {
31013 - atomic_inc(&dev_priv->vbl_received);
31014 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31015 + atomic_inc_unchecked(&dev_priv->vbl_received);
31016 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31017 do_gettimeofday(&cur_vblank);
31018 if (dev_priv->last_vblank_valid) {
31019 dev_priv->usec_per_vblank =
31020 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31021 dev_priv->last_vblank = cur_vblank;
31022 dev_priv->last_vblank_valid = 1;
31023 }
31024 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31025 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31026 DRM_DEBUG("US per vblank is: %u\n",
31027 dev_priv->usec_per_vblank);
31028 }
31029 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31030
31031 for (i = 0; i < dev_priv->num_irqs; ++i) {
31032 if (status & cur_irq->pending_mask) {
31033 - atomic_inc(&cur_irq->irq_received);
31034 + atomic_inc_unchecked(&cur_irq->irq_received);
31035 DRM_WAKEUP(&cur_irq->irq_queue);
31036 handled = 1;
31037 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31038 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31039 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31040 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31041 masks[irq][4]));
31042 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31043 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31044 } else {
31045 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31046 (((cur_irq_sequence =
31047 - atomic_read(&cur_irq->irq_received)) -
31048 + atomic_read_unchecked(&cur_irq->irq_received)) -
31049 *sequence) <= (1 << 23)));
31050 }
31051 *sequence = cur_irq_sequence;
31052 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31053 }
31054
31055 for (i = 0; i < dev_priv->num_irqs; ++i) {
31056 - atomic_set(&cur_irq->irq_received, 0);
31057 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31058 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31059 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31060 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31061 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31062 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31063 case VIA_IRQ_RELATIVE:
31064 irqwait->request.sequence +=
31065 - atomic_read(&cur_irq->irq_received);
31066 + atomic_read_unchecked(&cur_irq->irq_received);
31067 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31068 case VIA_IRQ_ABSOLUTE:
31069 break;
31070 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31071 index d0f2c07..9ebd9c3 100644
31072 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31073 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31074 @@ -263,7 +263,7 @@ struct vmw_private {
31075 * Fencing and IRQs.
31076 */
31077
31078 - atomic_t marker_seq;
31079 + atomic_unchecked_t marker_seq;
31080 wait_queue_head_t fence_queue;
31081 wait_queue_head_t fifo_queue;
31082 int fence_queue_waiters; /* Protected by hw_mutex */
31083 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31084 index a0c2f12..68ae6cb 100644
31085 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31086 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31087 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31088 (unsigned int) min,
31089 (unsigned int) fifo->capabilities);
31090
31091 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31092 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31093 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31094 vmw_marker_queue_init(&fifo->marker_queue);
31095 return vmw_fifo_send_fence(dev_priv, &dummy);
31096 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31097 if (reserveable)
31098 iowrite32(bytes, fifo_mem +
31099 SVGA_FIFO_RESERVED);
31100 - return fifo_mem + (next_cmd >> 2);
31101 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31102 } else {
31103 need_bounce = true;
31104 }
31105 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31106
31107 fm = vmw_fifo_reserve(dev_priv, bytes);
31108 if (unlikely(fm == NULL)) {
31109 - *seqno = atomic_read(&dev_priv->marker_seq);
31110 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31111 ret = -ENOMEM;
31112 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31113 false, 3*HZ);
31114 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31115 }
31116
31117 do {
31118 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31119 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31120 } while (*seqno == 0);
31121
31122 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31123 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31124 index cabc95f..14b3d77 100644
31125 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31126 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31127 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31128 * emitted. Then the fence is stale and signaled.
31129 */
31130
31131 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31132 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31133 > VMW_FENCE_WRAP);
31134
31135 return ret;
31136 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31137
31138 if (fifo_idle)
31139 down_read(&fifo_state->rwsem);
31140 - signal_seq = atomic_read(&dev_priv->marker_seq);
31141 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31142 ret = 0;
31143
31144 for (;;) {
31145 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31146 index 8a8725c..afed796 100644
31147 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31148 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31149 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31150 while (!vmw_lag_lt(queue, us)) {
31151 spin_lock(&queue->lock);
31152 if (list_empty(&queue->head))
31153 - seqno = atomic_read(&dev_priv->marker_seq);
31154 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31155 else {
31156 marker = list_first_entry(&queue->head,
31157 struct vmw_marker, head);
31158 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31159 index 4c87276..9ecc3c7 100644
31160 --- a/drivers/hid/hid-core.c
31161 +++ b/drivers/hid/hid-core.c
31162 @@ -2151,7 +2151,7 @@ static bool hid_ignore(struct hid_device *hdev)
31163
31164 int hid_add_device(struct hid_device *hdev)
31165 {
31166 - static atomic_t id = ATOMIC_INIT(0);
31167 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31168 int ret;
31169
31170 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31171 @@ -2186,7 +2186,7 @@ int hid_add_device(struct hid_device *hdev)
31172 /* XXX hack, any other cleaner solution after the driver core
31173 * is converted to allow more than 20 bytes as the device name? */
31174 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31175 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31176 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31177
31178 hid_debug_register(hdev, dev_name(&hdev->dev));
31179 ret = device_add(&hdev->dev);
31180 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31181 index eec3291..8ed706b 100644
31182 --- a/drivers/hid/hid-wiimote-debug.c
31183 +++ b/drivers/hid/hid-wiimote-debug.c
31184 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31185 else if (size == 0)
31186 return -EIO;
31187
31188 - if (copy_to_user(u, buf, size))
31189 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31190 return -EFAULT;
31191
31192 *off += size;
31193 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31194 index 14599e2..711c965 100644
31195 --- a/drivers/hid/usbhid/hiddev.c
31196 +++ b/drivers/hid/usbhid/hiddev.c
31197 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31198 break;
31199
31200 case HIDIOCAPPLICATION:
31201 - if (arg < 0 || arg >= hid->maxapplication)
31202 + if (arg >= hid->maxapplication)
31203 break;
31204
31205 for (i = 0; i < hid->maxcollection; i++)
31206 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31207 index 4065374..10ed7dc 100644
31208 --- a/drivers/hv/channel.c
31209 +++ b/drivers/hv/channel.c
31210 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31211 int ret = 0;
31212 int t;
31213
31214 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31215 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31216 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31217 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31218
31219 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31220 if (ret)
31221 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31222 index 86f8885..ab9cb2b 100644
31223 --- a/drivers/hv/hv.c
31224 +++ b/drivers/hv/hv.c
31225 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31226 u64 output_address = (output) ? virt_to_phys(output) : 0;
31227 u32 output_address_hi = output_address >> 32;
31228 u32 output_address_lo = output_address & 0xFFFFFFFF;
31229 - void *hypercall_page = hv_context.hypercall_page;
31230 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31231
31232 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31233 "=a"(hv_status_lo) : "d" (control_hi),
31234 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31235 index b9426a6..677ce34 100644
31236 --- a/drivers/hv/hyperv_vmbus.h
31237 +++ b/drivers/hv/hyperv_vmbus.h
31238 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31239 struct vmbus_connection {
31240 enum vmbus_connect_state conn_state;
31241
31242 - atomic_t next_gpadl_handle;
31243 + atomic_unchecked_t next_gpadl_handle;
31244
31245 /*
31246 * Represents channel interrupts. Each bit position represents a
31247 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31248 index a220e57..428f54d 100644
31249 --- a/drivers/hv/vmbus_drv.c
31250 +++ b/drivers/hv/vmbus_drv.c
31251 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31252 {
31253 int ret = 0;
31254
31255 - static atomic_t device_num = ATOMIC_INIT(0);
31256 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31257
31258 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31259 - atomic_inc_return(&device_num));
31260 + atomic_inc_return_unchecked(&device_num));
31261
31262 child_device_obj->device.bus = &hv_bus;
31263 child_device_obj->device.parent = &hv_acpi_dev->dev;
31264 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31265 index 34ad5a2..e2b0ae8 100644
31266 --- a/drivers/hwmon/acpi_power_meter.c
31267 +++ b/drivers/hwmon/acpi_power_meter.c
31268 @@ -308,8 +308,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31269 return res;
31270
31271 temp /= 1000;
31272 - if (temp < 0)
31273 - return -EINVAL;
31274
31275 mutex_lock(&resource->lock);
31276 resource->trip[attr->index - 7] = temp;
31277 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31278 index 8b011d0..3de24a1 100644
31279 --- a/drivers/hwmon/sht15.c
31280 +++ b/drivers/hwmon/sht15.c
31281 @@ -166,7 +166,7 @@ struct sht15_data {
31282 int supply_uV;
31283 bool supply_uV_valid;
31284 struct work_struct update_supply_work;
31285 - atomic_t interrupt_handled;
31286 + atomic_unchecked_t interrupt_handled;
31287 };
31288
31289 /**
31290 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31291 return ret;
31292
31293 gpio_direction_input(data->pdata->gpio_data);
31294 - atomic_set(&data->interrupt_handled, 0);
31295 + atomic_set_unchecked(&data->interrupt_handled, 0);
31296
31297 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31298 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31299 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31300 /* Only relevant if the interrupt hasn't occurred. */
31301 - if (!atomic_read(&data->interrupt_handled))
31302 + if (!atomic_read_unchecked(&data->interrupt_handled))
31303 schedule_work(&data->read_work);
31304 }
31305 ret = wait_event_timeout(data->wait_queue,
31306 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31307
31308 /* First disable the interrupt */
31309 disable_irq_nosync(irq);
31310 - atomic_inc(&data->interrupt_handled);
31311 + atomic_inc_unchecked(&data->interrupt_handled);
31312 /* Then schedule a reading work struct */
31313 if (data->state != SHT15_READING_NOTHING)
31314 schedule_work(&data->read_work);
31315 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31316 * If not, then start the interrupt again - care here as could
31317 * have gone low in meantime so verify it hasn't!
31318 */
31319 - atomic_set(&data->interrupt_handled, 0);
31320 + atomic_set_unchecked(&data->interrupt_handled, 0);
31321 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31322 /* If still not occurred or another handler was scheduled */
31323 if (gpio_get_value(data->pdata->gpio_data)
31324 - || atomic_read(&data->interrupt_handled))
31325 + || atomic_read_unchecked(&data->interrupt_handled))
31326 return;
31327 }
31328
31329 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31330 index 378fcb5..5e91fa8 100644
31331 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31332 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31333 @@ -43,7 +43,7 @@
31334 extern struct i2c_adapter amd756_smbus;
31335
31336 static struct i2c_adapter *s4882_adapter;
31337 -static struct i2c_algorithm *s4882_algo;
31338 +static i2c_algorithm_no_const *s4882_algo;
31339
31340 /* Wrapper access functions for multiplexed SMBus */
31341 static DEFINE_MUTEX(amd756_lock);
31342 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31343 index 29015eb..af2d8e9 100644
31344 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31345 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31346 @@ -41,7 +41,7 @@
31347 extern struct i2c_adapter *nforce2_smbus;
31348
31349 static struct i2c_adapter *s4985_adapter;
31350 -static struct i2c_algorithm *s4985_algo;
31351 +static i2c_algorithm_no_const *s4985_algo;
31352
31353 /* Wrapper access functions for multiplexed SMBus */
31354 static DEFINE_MUTEX(nforce2_lock);
31355 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31356 index 1038c38..eb92f51 100644
31357 --- a/drivers/i2c/i2c-mux.c
31358 +++ b/drivers/i2c/i2c-mux.c
31359 @@ -30,7 +30,7 @@
31360 /* multiplexer per channel data */
31361 struct i2c_mux_priv {
31362 struct i2c_adapter adap;
31363 - struct i2c_algorithm algo;
31364 + i2c_algorithm_no_const algo;
31365
31366 struct i2c_adapter *parent;
31367 void *mux_priv; /* the mux chip/device */
31368 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31369 index 57d00ca..0145194 100644
31370 --- a/drivers/ide/aec62xx.c
31371 +++ b/drivers/ide/aec62xx.c
31372 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31373 .cable_detect = atp86x_cable_detect,
31374 };
31375
31376 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31377 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31378 { /* 0: AEC6210 */
31379 .name = DRV_NAME,
31380 .init_chipset = init_chipset_aec62xx,
31381 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31382 index 2c8016a..911a27c 100644
31383 --- a/drivers/ide/alim15x3.c
31384 +++ b/drivers/ide/alim15x3.c
31385 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31386 .dma_sff_read_status = ide_dma_sff_read_status,
31387 };
31388
31389 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31390 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31391 .name = DRV_NAME,
31392 .init_chipset = init_chipset_ali15x3,
31393 .init_hwif = init_hwif_ali15x3,
31394 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31395 index 3747b25..56fc995 100644
31396 --- a/drivers/ide/amd74xx.c
31397 +++ b/drivers/ide/amd74xx.c
31398 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31399 .udma_mask = udma, \
31400 }
31401
31402 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31403 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31404 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31405 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31406 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31407 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31408 index 15f0ead..cb43480 100644
31409 --- a/drivers/ide/atiixp.c
31410 +++ b/drivers/ide/atiixp.c
31411 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31412 .cable_detect = atiixp_cable_detect,
31413 };
31414
31415 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31416 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31417 { /* 0: IXP200/300/400/700 */
31418 .name = DRV_NAME,
31419 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31420 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31421 index 5f80312..d1fc438 100644
31422 --- a/drivers/ide/cmd64x.c
31423 +++ b/drivers/ide/cmd64x.c
31424 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31425 .dma_sff_read_status = ide_dma_sff_read_status,
31426 };
31427
31428 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31429 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31430 { /* 0: CMD643 */
31431 .name = DRV_NAME,
31432 .init_chipset = init_chipset_cmd64x,
31433 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31434 index 2c1e5f7..1444762 100644
31435 --- a/drivers/ide/cs5520.c
31436 +++ b/drivers/ide/cs5520.c
31437 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31438 .set_dma_mode = cs5520_set_dma_mode,
31439 };
31440
31441 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31442 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31443 .name = DRV_NAME,
31444 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31445 .port_ops = &cs5520_port_ops,
31446 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31447 index 4dc4eb9..49b40ad 100644
31448 --- a/drivers/ide/cs5530.c
31449 +++ b/drivers/ide/cs5530.c
31450 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31451 .udma_filter = cs5530_udma_filter,
31452 };
31453
31454 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31455 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31456 .name = DRV_NAME,
31457 .init_chipset = init_chipset_cs5530,
31458 .init_hwif = init_hwif_cs5530,
31459 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31460 index 5059faf..18d4c85 100644
31461 --- a/drivers/ide/cs5535.c
31462 +++ b/drivers/ide/cs5535.c
31463 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31464 .cable_detect = cs5535_cable_detect,
31465 };
31466
31467 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31468 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31469 .name = DRV_NAME,
31470 .port_ops = &cs5535_port_ops,
31471 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31472 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31473 index 847553f..3ffb49d 100644
31474 --- a/drivers/ide/cy82c693.c
31475 +++ b/drivers/ide/cy82c693.c
31476 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31477 .set_dma_mode = cy82c693_set_dma_mode,
31478 };
31479
31480 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31481 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31482 .name = DRV_NAME,
31483 .init_iops = init_iops_cy82c693,
31484 .port_ops = &cy82c693_port_ops,
31485 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31486 index 58c51cd..4aec3b8 100644
31487 --- a/drivers/ide/hpt366.c
31488 +++ b/drivers/ide/hpt366.c
31489 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31490 }
31491 };
31492
31493 -static const struct hpt_info hpt36x __devinitdata = {
31494 +static const struct hpt_info hpt36x __devinitconst = {
31495 .chip_name = "HPT36x",
31496 .chip_type = HPT36x,
31497 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31498 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31499 .timings = &hpt36x_timings
31500 };
31501
31502 -static const struct hpt_info hpt370 __devinitdata = {
31503 +static const struct hpt_info hpt370 __devinitconst = {
31504 .chip_name = "HPT370",
31505 .chip_type = HPT370,
31506 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31507 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31508 .timings = &hpt37x_timings
31509 };
31510
31511 -static const struct hpt_info hpt370a __devinitdata = {
31512 +static const struct hpt_info hpt370a __devinitconst = {
31513 .chip_name = "HPT370A",
31514 .chip_type = HPT370A,
31515 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31516 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31517 .timings = &hpt37x_timings
31518 };
31519
31520 -static const struct hpt_info hpt374 __devinitdata = {
31521 +static const struct hpt_info hpt374 __devinitconst = {
31522 .chip_name = "HPT374",
31523 .chip_type = HPT374,
31524 .udma_mask = ATA_UDMA5,
31525 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31526 .timings = &hpt37x_timings
31527 };
31528
31529 -static const struct hpt_info hpt372 __devinitdata = {
31530 +static const struct hpt_info hpt372 __devinitconst = {
31531 .chip_name = "HPT372",
31532 .chip_type = HPT372,
31533 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31534 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31535 .timings = &hpt37x_timings
31536 };
31537
31538 -static const struct hpt_info hpt372a __devinitdata = {
31539 +static const struct hpt_info hpt372a __devinitconst = {
31540 .chip_name = "HPT372A",
31541 .chip_type = HPT372A,
31542 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31543 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31544 .timings = &hpt37x_timings
31545 };
31546
31547 -static const struct hpt_info hpt302 __devinitdata = {
31548 +static const struct hpt_info hpt302 __devinitconst = {
31549 .chip_name = "HPT302",
31550 .chip_type = HPT302,
31551 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31552 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31553 .timings = &hpt37x_timings
31554 };
31555
31556 -static const struct hpt_info hpt371 __devinitdata = {
31557 +static const struct hpt_info hpt371 __devinitconst = {
31558 .chip_name = "HPT371",
31559 .chip_type = HPT371,
31560 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31561 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31562 .timings = &hpt37x_timings
31563 };
31564
31565 -static const struct hpt_info hpt372n __devinitdata = {
31566 +static const struct hpt_info hpt372n __devinitconst = {
31567 .chip_name = "HPT372N",
31568 .chip_type = HPT372N,
31569 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31570 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31571 .timings = &hpt37x_timings
31572 };
31573
31574 -static const struct hpt_info hpt302n __devinitdata = {
31575 +static const struct hpt_info hpt302n __devinitconst = {
31576 .chip_name = "HPT302N",
31577 .chip_type = HPT302N,
31578 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31579 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31580 .timings = &hpt37x_timings
31581 };
31582
31583 -static const struct hpt_info hpt371n __devinitdata = {
31584 +static const struct hpt_info hpt371n __devinitconst = {
31585 .chip_name = "HPT371N",
31586 .chip_type = HPT371N,
31587 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31588 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31589 .dma_sff_read_status = ide_dma_sff_read_status,
31590 };
31591
31592 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31593 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31594 { /* 0: HPT36x */
31595 .name = DRV_NAME,
31596 .init_chipset = init_chipset_hpt366,
31597 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31598 index 8126824..55a2798 100644
31599 --- a/drivers/ide/ide-cd.c
31600 +++ b/drivers/ide/ide-cd.c
31601 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31602 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31603 if ((unsigned long)buf & alignment
31604 || blk_rq_bytes(rq) & q->dma_pad_mask
31605 - || object_is_on_stack(buf))
31606 + || object_starts_on_stack(buf))
31607 drive->dma = 0;
31608 }
31609 }
31610 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31611 index 7f56b73..dab5b67 100644
31612 --- a/drivers/ide/ide-pci-generic.c
31613 +++ b/drivers/ide/ide-pci-generic.c
31614 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31615 .udma_mask = ATA_UDMA6, \
31616 }
31617
31618 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31619 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31620 /* 0: Unknown */
31621 DECLARE_GENERIC_PCI_DEV(0),
31622
31623 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31624 index 560e66d..d5dd180 100644
31625 --- a/drivers/ide/it8172.c
31626 +++ b/drivers/ide/it8172.c
31627 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31628 .set_dma_mode = it8172_set_dma_mode,
31629 };
31630
31631 -static const struct ide_port_info it8172_port_info __devinitdata = {
31632 +static const struct ide_port_info it8172_port_info __devinitconst = {
31633 .name = DRV_NAME,
31634 .port_ops = &it8172_port_ops,
31635 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31636 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31637 index 46816ba..1847aeb 100644
31638 --- a/drivers/ide/it8213.c
31639 +++ b/drivers/ide/it8213.c
31640 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31641 .cable_detect = it8213_cable_detect,
31642 };
31643
31644 -static const struct ide_port_info it8213_chipset __devinitdata = {
31645 +static const struct ide_port_info it8213_chipset __devinitconst = {
31646 .name = DRV_NAME,
31647 .enablebits = { {0x41, 0x80, 0x80} },
31648 .port_ops = &it8213_port_ops,
31649 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31650 index 2e3169f..c5611db 100644
31651 --- a/drivers/ide/it821x.c
31652 +++ b/drivers/ide/it821x.c
31653 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31654 .cable_detect = it821x_cable_detect,
31655 };
31656
31657 -static const struct ide_port_info it821x_chipset __devinitdata = {
31658 +static const struct ide_port_info it821x_chipset __devinitconst = {
31659 .name = DRV_NAME,
31660 .init_chipset = init_chipset_it821x,
31661 .init_hwif = init_hwif_it821x,
31662 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31663 index 74c2c4a..efddd7d 100644
31664 --- a/drivers/ide/jmicron.c
31665 +++ b/drivers/ide/jmicron.c
31666 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31667 .cable_detect = jmicron_cable_detect,
31668 };
31669
31670 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31671 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31672 .name = DRV_NAME,
31673 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31674 .port_ops = &jmicron_port_ops,
31675 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31676 index 95327a2..73f78d8 100644
31677 --- a/drivers/ide/ns87415.c
31678 +++ b/drivers/ide/ns87415.c
31679 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31680 .dma_sff_read_status = superio_dma_sff_read_status,
31681 };
31682
31683 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31684 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31685 .name = DRV_NAME,
31686 .init_hwif = init_hwif_ns87415,
31687 .tp_ops = &ns87415_tp_ops,
31688 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31689 index 1a53a4c..39edc66 100644
31690 --- a/drivers/ide/opti621.c
31691 +++ b/drivers/ide/opti621.c
31692 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31693 .set_pio_mode = opti621_set_pio_mode,
31694 };
31695
31696 -static const struct ide_port_info opti621_chipset __devinitdata = {
31697 +static const struct ide_port_info opti621_chipset __devinitconst = {
31698 .name = DRV_NAME,
31699 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31700 .port_ops = &opti621_port_ops,
31701 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31702 index 9546fe2..2e5ceb6 100644
31703 --- a/drivers/ide/pdc202xx_new.c
31704 +++ b/drivers/ide/pdc202xx_new.c
31705 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31706 .udma_mask = udma, \
31707 }
31708
31709 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31710 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31711 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31712 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31713 };
31714 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31715 index 3a35ec6..5634510 100644
31716 --- a/drivers/ide/pdc202xx_old.c
31717 +++ b/drivers/ide/pdc202xx_old.c
31718 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31719 .max_sectors = sectors, \
31720 }
31721
31722 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31723 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31724 { /* 0: PDC20246 */
31725 .name = DRV_NAME,
31726 .init_chipset = init_chipset_pdc202xx,
31727 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31728 index 1892e81..fe0fd60 100644
31729 --- a/drivers/ide/piix.c
31730 +++ b/drivers/ide/piix.c
31731 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31732 .udma_mask = udma, \
31733 }
31734
31735 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
31736 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
31737 /* 0: MPIIX */
31738 { /*
31739 * MPIIX actually has only a single IDE channel mapped to
31740 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31741 index a6414a8..c04173e 100644
31742 --- a/drivers/ide/rz1000.c
31743 +++ b/drivers/ide/rz1000.c
31744 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31745 }
31746 }
31747
31748 -static const struct ide_port_info rz1000_chipset __devinitdata = {
31749 +static const struct ide_port_info rz1000_chipset __devinitconst = {
31750 .name = DRV_NAME,
31751 .host_flags = IDE_HFLAG_NO_DMA,
31752 };
31753 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31754 index 356b9b5..d4758eb 100644
31755 --- a/drivers/ide/sc1200.c
31756 +++ b/drivers/ide/sc1200.c
31757 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31758 .dma_sff_read_status = ide_dma_sff_read_status,
31759 };
31760
31761 -static const struct ide_port_info sc1200_chipset __devinitdata = {
31762 +static const struct ide_port_info sc1200_chipset __devinitconst = {
31763 .name = DRV_NAME,
31764 .port_ops = &sc1200_port_ops,
31765 .dma_ops = &sc1200_dma_ops,
31766 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31767 index b7f5b0c..9701038 100644
31768 --- a/drivers/ide/scc_pata.c
31769 +++ b/drivers/ide/scc_pata.c
31770 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31771 .dma_sff_read_status = scc_dma_sff_read_status,
31772 };
31773
31774 -static const struct ide_port_info scc_chipset __devinitdata = {
31775 +static const struct ide_port_info scc_chipset __devinitconst = {
31776 .name = "sccIDE",
31777 .init_iops = init_iops_scc,
31778 .init_dma = scc_init_dma,
31779 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31780 index 35fb8da..24d72ef 100644
31781 --- a/drivers/ide/serverworks.c
31782 +++ b/drivers/ide/serverworks.c
31783 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31784 .cable_detect = svwks_cable_detect,
31785 };
31786
31787 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31788 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31789 { /* 0: OSB4 */
31790 .name = DRV_NAME,
31791 .init_chipset = init_chipset_svwks,
31792 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31793 index ddeda44..46f7e30 100644
31794 --- a/drivers/ide/siimage.c
31795 +++ b/drivers/ide/siimage.c
31796 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31797 .udma_mask = ATA_UDMA6, \
31798 }
31799
31800 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31801 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31802 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31803 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31804 };
31805 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31806 index 4a00225..09e61b4 100644
31807 --- a/drivers/ide/sis5513.c
31808 +++ b/drivers/ide/sis5513.c
31809 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31810 .cable_detect = sis_cable_detect,
31811 };
31812
31813 -static const struct ide_port_info sis5513_chipset __devinitdata = {
31814 +static const struct ide_port_info sis5513_chipset __devinitconst = {
31815 .name = DRV_NAME,
31816 .init_chipset = init_chipset_sis5513,
31817 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31818 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31819 index f21dc2a..d051cd2 100644
31820 --- a/drivers/ide/sl82c105.c
31821 +++ b/drivers/ide/sl82c105.c
31822 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31823 .dma_sff_read_status = ide_dma_sff_read_status,
31824 };
31825
31826 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
31827 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
31828 .name = DRV_NAME,
31829 .init_chipset = init_chipset_sl82c105,
31830 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31831 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31832 index 864ffe0..863a5e9 100644
31833 --- a/drivers/ide/slc90e66.c
31834 +++ b/drivers/ide/slc90e66.c
31835 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31836 .cable_detect = slc90e66_cable_detect,
31837 };
31838
31839 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
31840 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
31841 .name = DRV_NAME,
31842 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31843 .port_ops = &slc90e66_port_ops,
31844 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31845 index 4799d5c..1794678 100644
31846 --- a/drivers/ide/tc86c001.c
31847 +++ b/drivers/ide/tc86c001.c
31848 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31849 .dma_sff_read_status = ide_dma_sff_read_status,
31850 };
31851
31852 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
31853 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
31854 .name = DRV_NAME,
31855 .init_hwif = init_hwif_tc86c001,
31856 .port_ops = &tc86c001_port_ops,
31857 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31858 index 281c914..55ce1b8 100644
31859 --- a/drivers/ide/triflex.c
31860 +++ b/drivers/ide/triflex.c
31861 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31862 .set_dma_mode = triflex_set_mode,
31863 };
31864
31865 -static const struct ide_port_info triflex_device __devinitdata = {
31866 +static const struct ide_port_info triflex_device __devinitconst = {
31867 .name = DRV_NAME,
31868 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31869 .port_ops = &triflex_port_ops,
31870 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31871 index 4b42ca0..e494a98 100644
31872 --- a/drivers/ide/trm290.c
31873 +++ b/drivers/ide/trm290.c
31874 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31875 .dma_check = trm290_dma_check,
31876 };
31877
31878 -static const struct ide_port_info trm290_chipset __devinitdata = {
31879 +static const struct ide_port_info trm290_chipset __devinitconst = {
31880 .name = DRV_NAME,
31881 .init_hwif = init_hwif_trm290,
31882 .tp_ops = &trm290_tp_ops,
31883 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31884 index f46f49c..eb77678 100644
31885 --- a/drivers/ide/via82cxxx.c
31886 +++ b/drivers/ide/via82cxxx.c
31887 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31888 .cable_detect = via82cxxx_cable_detect,
31889 };
31890
31891 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31892 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31893 .name = DRV_NAME,
31894 .init_chipset = init_chipset_via82cxxx,
31895 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31896 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31897 index 73d4531..c90cd2d 100644
31898 --- a/drivers/ieee802154/fakehard.c
31899 +++ b/drivers/ieee802154/fakehard.c
31900 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31901 phy->transmit_power = 0xbf;
31902
31903 dev->netdev_ops = &fake_ops;
31904 - dev->ml_priv = &fake_mlme;
31905 + dev->ml_priv = (void *)&fake_mlme;
31906
31907 priv = netdev_priv(dev);
31908 priv->phy = phy;
31909 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31910 index c889aae..6cf5aa7 100644
31911 --- a/drivers/infiniband/core/cm.c
31912 +++ b/drivers/infiniband/core/cm.c
31913 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31914
31915 struct cm_counter_group {
31916 struct kobject obj;
31917 - atomic_long_t counter[CM_ATTR_COUNT];
31918 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31919 };
31920
31921 struct cm_counter_attribute {
31922 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31923 struct ib_mad_send_buf *msg = NULL;
31924 int ret;
31925
31926 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31927 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31928 counter[CM_REQ_COUNTER]);
31929
31930 /* Quick state check to discard duplicate REQs. */
31931 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
31932 if (!cm_id_priv)
31933 return;
31934
31935 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31936 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31937 counter[CM_REP_COUNTER]);
31938 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
31939 if (ret)
31940 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
31941 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
31942 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
31943 spin_unlock_irq(&cm_id_priv->lock);
31944 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31945 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31946 counter[CM_RTU_COUNTER]);
31947 goto out;
31948 }
31949 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
31950 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
31951 dreq_msg->local_comm_id);
31952 if (!cm_id_priv) {
31953 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31954 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31955 counter[CM_DREQ_COUNTER]);
31956 cm_issue_drep(work->port, work->mad_recv_wc);
31957 return -EINVAL;
31958 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
31959 case IB_CM_MRA_REP_RCVD:
31960 break;
31961 case IB_CM_TIMEWAIT:
31962 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31963 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31964 counter[CM_DREQ_COUNTER]);
31965 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31966 goto unlock;
31967 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
31968 cm_free_msg(msg);
31969 goto deref;
31970 case IB_CM_DREQ_RCVD:
31971 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31972 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31973 counter[CM_DREQ_COUNTER]);
31974 goto unlock;
31975 default:
31976 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
31977 ib_modify_mad(cm_id_priv->av.port->mad_agent,
31978 cm_id_priv->msg, timeout)) {
31979 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
31980 - atomic_long_inc(&work->port->
31981 + atomic_long_inc_unchecked(&work->port->
31982 counter_group[CM_RECV_DUPLICATES].
31983 counter[CM_MRA_COUNTER]);
31984 goto out;
31985 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
31986 break;
31987 case IB_CM_MRA_REQ_RCVD:
31988 case IB_CM_MRA_REP_RCVD:
31989 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31990 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31991 counter[CM_MRA_COUNTER]);
31992 /* fall through */
31993 default:
31994 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
31995 case IB_CM_LAP_IDLE:
31996 break;
31997 case IB_CM_MRA_LAP_SENT:
31998 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31999 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32000 counter[CM_LAP_COUNTER]);
32001 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32002 goto unlock;
32003 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32004 cm_free_msg(msg);
32005 goto deref;
32006 case IB_CM_LAP_RCVD:
32007 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32008 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32009 counter[CM_LAP_COUNTER]);
32010 goto unlock;
32011 default:
32012 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32013 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32014 if (cur_cm_id_priv) {
32015 spin_unlock_irq(&cm.lock);
32016 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32017 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32018 counter[CM_SIDR_REQ_COUNTER]);
32019 goto out; /* Duplicate message. */
32020 }
32021 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32022 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32023 msg->retries = 1;
32024
32025 - atomic_long_add(1 + msg->retries,
32026 + atomic_long_add_unchecked(1 + msg->retries,
32027 &port->counter_group[CM_XMIT].counter[attr_index]);
32028 if (msg->retries)
32029 - atomic_long_add(msg->retries,
32030 + atomic_long_add_unchecked(msg->retries,
32031 &port->counter_group[CM_XMIT_RETRIES].
32032 counter[attr_index]);
32033
32034 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32035 }
32036
32037 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32038 - atomic_long_inc(&port->counter_group[CM_RECV].
32039 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32040 counter[attr_id - CM_ATTR_ID_OFFSET]);
32041
32042 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32043 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32044 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32045
32046 return sprintf(buf, "%ld\n",
32047 - atomic_long_read(&group->counter[cm_attr->index]));
32048 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32049 }
32050
32051 static const struct sysfs_ops cm_counter_ops = {
32052 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32053 index 176c8f9..2627b62 100644
32054 --- a/drivers/infiniband/core/fmr_pool.c
32055 +++ b/drivers/infiniband/core/fmr_pool.c
32056 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32057
32058 struct task_struct *thread;
32059
32060 - atomic_t req_ser;
32061 - atomic_t flush_ser;
32062 + atomic_unchecked_t req_ser;
32063 + atomic_unchecked_t flush_ser;
32064
32065 wait_queue_head_t force_wait;
32066 };
32067 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32068 struct ib_fmr_pool *pool = pool_ptr;
32069
32070 do {
32071 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32072 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32073 ib_fmr_batch_release(pool);
32074
32075 - atomic_inc(&pool->flush_ser);
32076 + atomic_inc_unchecked(&pool->flush_ser);
32077 wake_up_interruptible(&pool->force_wait);
32078
32079 if (pool->flush_function)
32080 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32081 }
32082
32083 set_current_state(TASK_INTERRUPTIBLE);
32084 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32085 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32086 !kthread_should_stop())
32087 schedule();
32088 __set_current_state(TASK_RUNNING);
32089 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32090 pool->dirty_watermark = params->dirty_watermark;
32091 pool->dirty_len = 0;
32092 spin_lock_init(&pool->pool_lock);
32093 - atomic_set(&pool->req_ser, 0);
32094 - atomic_set(&pool->flush_ser, 0);
32095 + atomic_set_unchecked(&pool->req_ser, 0);
32096 + atomic_set_unchecked(&pool->flush_ser, 0);
32097 init_waitqueue_head(&pool->force_wait);
32098
32099 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32100 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32101 }
32102 spin_unlock_irq(&pool->pool_lock);
32103
32104 - serial = atomic_inc_return(&pool->req_ser);
32105 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32106 wake_up_process(pool->thread);
32107
32108 if (wait_event_interruptible(pool->force_wait,
32109 - atomic_read(&pool->flush_ser) - serial >= 0))
32110 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32111 return -EINTR;
32112
32113 return 0;
32114 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32115 } else {
32116 list_add_tail(&fmr->list, &pool->dirty_list);
32117 if (++pool->dirty_len >= pool->dirty_watermark) {
32118 - atomic_inc(&pool->req_ser);
32119 + atomic_inc_unchecked(&pool->req_ser);
32120 wake_up_process(pool->thread);
32121 }
32122 }
32123 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32124 index 57e07c6..56d09d4 100644
32125 --- a/drivers/infiniband/hw/cxgb4/mem.c
32126 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32127 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32128 int err;
32129 struct fw_ri_tpte tpt;
32130 u32 stag_idx;
32131 - static atomic_t key;
32132 + static atomic_unchecked_t key;
32133
32134 if (c4iw_fatal_error(rdev))
32135 return -EIO;
32136 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32137 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32138 rdev->stats.stag.max = rdev->stats.stag.cur;
32139 mutex_unlock(&rdev->stats.lock);
32140 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32141 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32142 }
32143 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32144 __func__, stag_state, type, pdid, stag_idx);
32145 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32146 index 79b3dbc..96e5fcc 100644
32147 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32148 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32149 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32150 struct ib_atomic_eth *ateth;
32151 struct ipath_ack_entry *e;
32152 u64 vaddr;
32153 - atomic64_t *maddr;
32154 + atomic64_unchecked_t *maddr;
32155 u64 sdata;
32156 u32 rkey;
32157 u8 next;
32158 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32159 IB_ACCESS_REMOTE_ATOMIC)))
32160 goto nack_acc_unlck;
32161 /* Perform atomic OP and save result. */
32162 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32163 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32164 sdata = be64_to_cpu(ateth->swap_data);
32165 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32166 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32167 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32168 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32169 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32170 be64_to_cpu(ateth->compare_data),
32171 sdata);
32172 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32173 index 1f95bba..9530f87 100644
32174 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32175 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32176 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32177 unsigned long flags;
32178 struct ib_wc wc;
32179 u64 sdata;
32180 - atomic64_t *maddr;
32181 + atomic64_unchecked_t *maddr;
32182 enum ib_wc_status send_status;
32183
32184 /*
32185 @@ -382,11 +382,11 @@ again:
32186 IB_ACCESS_REMOTE_ATOMIC)))
32187 goto acc_err;
32188 /* Perform atomic OP and save result. */
32189 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32190 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32191 sdata = wqe->wr.wr.atomic.compare_add;
32192 *(u64 *) sqp->s_sge.sge.vaddr =
32193 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32194 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32195 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32196 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32197 sdata, wqe->wr.wr.atomic.swap);
32198 goto send_comp;
32199 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32200 index 7140199..da60063 100644
32201 --- a/drivers/infiniband/hw/nes/nes.c
32202 +++ b/drivers/infiniband/hw/nes/nes.c
32203 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32204 LIST_HEAD(nes_adapter_list);
32205 static LIST_HEAD(nes_dev_list);
32206
32207 -atomic_t qps_destroyed;
32208 +atomic_unchecked_t qps_destroyed;
32209
32210 static unsigned int ee_flsh_adapter;
32211 static unsigned int sysfs_nonidx_addr;
32212 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32213 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32214 struct nes_adapter *nesadapter = nesdev->nesadapter;
32215
32216 - atomic_inc(&qps_destroyed);
32217 + atomic_inc_unchecked(&qps_destroyed);
32218
32219 /* Free the control structures */
32220
32221 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32222 index c438e46..ca30356 100644
32223 --- a/drivers/infiniband/hw/nes/nes.h
32224 +++ b/drivers/infiniband/hw/nes/nes.h
32225 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32226 extern unsigned int wqm_quanta;
32227 extern struct list_head nes_adapter_list;
32228
32229 -extern atomic_t cm_connects;
32230 -extern atomic_t cm_accepts;
32231 -extern atomic_t cm_disconnects;
32232 -extern atomic_t cm_closes;
32233 -extern atomic_t cm_connecteds;
32234 -extern atomic_t cm_connect_reqs;
32235 -extern atomic_t cm_rejects;
32236 -extern atomic_t mod_qp_timouts;
32237 -extern atomic_t qps_created;
32238 -extern atomic_t qps_destroyed;
32239 -extern atomic_t sw_qps_destroyed;
32240 +extern atomic_unchecked_t cm_connects;
32241 +extern atomic_unchecked_t cm_accepts;
32242 +extern atomic_unchecked_t cm_disconnects;
32243 +extern atomic_unchecked_t cm_closes;
32244 +extern atomic_unchecked_t cm_connecteds;
32245 +extern atomic_unchecked_t cm_connect_reqs;
32246 +extern atomic_unchecked_t cm_rejects;
32247 +extern atomic_unchecked_t mod_qp_timouts;
32248 +extern atomic_unchecked_t qps_created;
32249 +extern atomic_unchecked_t qps_destroyed;
32250 +extern atomic_unchecked_t sw_qps_destroyed;
32251 extern u32 mh_detected;
32252 extern u32 mh_pauses_sent;
32253 extern u32 cm_packets_sent;
32254 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32255 extern u32 cm_packets_received;
32256 extern u32 cm_packets_dropped;
32257 extern u32 cm_packets_retrans;
32258 -extern atomic_t cm_listens_created;
32259 -extern atomic_t cm_listens_destroyed;
32260 +extern atomic_unchecked_t cm_listens_created;
32261 +extern atomic_unchecked_t cm_listens_destroyed;
32262 extern u32 cm_backlog_drops;
32263 -extern atomic_t cm_loopbacks;
32264 -extern atomic_t cm_nodes_created;
32265 -extern atomic_t cm_nodes_destroyed;
32266 -extern atomic_t cm_accel_dropped_pkts;
32267 -extern atomic_t cm_resets_recvd;
32268 -extern atomic_t pau_qps_created;
32269 -extern atomic_t pau_qps_destroyed;
32270 +extern atomic_unchecked_t cm_loopbacks;
32271 +extern atomic_unchecked_t cm_nodes_created;
32272 +extern atomic_unchecked_t cm_nodes_destroyed;
32273 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32274 +extern atomic_unchecked_t cm_resets_recvd;
32275 +extern atomic_unchecked_t pau_qps_created;
32276 +extern atomic_unchecked_t pau_qps_destroyed;
32277
32278 extern u32 int_mod_timer_init;
32279 extern u32 int_mod_cq_depth_256;
32280 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32281 index 020e95c..fbb3450 100644
32282 --- a/drivers/infiniband/hw/nes/nes_cm.c
32283 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32284 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32285 u32 cm_packets_retrans;
32286 u32 cm_packets_created;
32287 u32 cm_packets_received;
32288 -atomic_t cm_listens_created;
32289 -atomic_t cm_listens_destroyed;
32290 +atomic_unchecked_t cm_listens_created;
32291 +atomic_unchecked_t cm_listens_destroyed;
32292 u32 cm_backlog_drops;
32293 -atomic_t cm_loopbacks;
32294 -atomic_t cm_nodes_created;
32295 -atomic_t cm_nodes_destroyed;
32296 -atomic_t cm_accel_dropped_pkts;
32297 -atomic_t cm_resets_recvd;
32298 +atomic_unchecked_t cm_loopbacks;
32299 +atomic_unchecked_t cm_nodes_created;
32300 +atomic_unchecked_t cm_nodes_destroyed;
32301 +atomic_unchecked_t cm_accel_dropped_pkts;
32302 +atomic_unchecked_t cm_resets_recvd;
32303
32304 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32305 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32306 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32307
32308 static struct nes_cm_core *g_cm_core;
32309
32310 -atomic_t cm_connects;
32311 -atomic_t cm_accepts;
32312 -atomic_t cm_disconnects;
32313 -atomic_t cm_closes;
32314 -atomic_t cm_connecteds;
32315 -atomic_t cm_connect_reqs;
32316 -atomic_t cm_rejects;
32317 +atomic_unchecked_t cm_connects;
32318 +atomic_unchecked_t cm_accepts;
32319 +atomic_unchecked_t cm_disconnects;
32320 +atomic_unchecked_t cm_closes;
32321 +atomic_unchecked_t cm_connecteds;
32322 +atomic_unchecked_t cm_connect_reqs;
32323 +atomic_unchecked_t cm_rejects;
32324
32325 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32326 {
32327 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32328 kfree(listener);
32329 listener = NULL;
32330 ret = 0;
32331 - atomic_inc(&cm_listens_destroyed);
32332 + atomic_inc_unchecked(&cm_listens_destroyed);
32333 } else {
32334 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32335 }
32336 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32337 cm_node->rem_mac);
32338
32339 add_hte_node(cm_core, cm_node);
32340 - atomic_inc(&cm_nodes_created);
32341 + atomic_inc_unchecked(&cm_nodes_created);
32342
32343 return cm_node;
32344 }
32345 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32346 }
32347
32348 atomic_dec(&cm_core->node_cnt);
32349 - atomic_inc(&cm_nodes_destroyed);
32350 + atomic_inc_unchecked(&cm_nodes_destroyed);
32351 nesqp = cm_node->nesqp;
32352 if (nesqp) {
32353 nesqp->cm_node = NULL;
32354 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32355
32356 static void drop_packet(struct sk_buff *skb)
32357 {
32358 - atomic_inc(&cm_accel_dropped_pkts);
32359 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32360 dev_kfree_skb_any(skb);
32361 }
32362
32363 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32364 {
32365
32366 int reset = 0; /* whether to send reset in case of err.. */
32367 - atomic_inc(&cm_resets_recvd);
32368 + atomic_inc_unchecked(&cm_resets_recvd);
32369 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32370 " refcnt=%d\n", cm_node, cm_node->state,
32371 atomic_read(&cm_node->ref_count));
32372 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32373 rem_ref_cm_node(cm_node->cm_core, cm_node);
32374 return NULL;
32375 }
32376 - atomic_inc(&cm_loopbacks);
32377 + atomic_inc_unchecked(&cm_loopbacks);
32378 loopbackremotenode->loopbackpartner = cm_node;
32379 loopbackremotenode->tcp_cntxt.rcv_wscale =
32380 NES_CM_DEFAULT_RCV_WND_SCALE;
32381 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32382 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32383 else {
32384 rem_ref_cm_node(cm_core, cm_node);
32385 - atomic_inc(&cm_accel_dropped_pkts);
32386 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32387 dev_kfree_skb_any(skb);
32388 }
32389 break;
32390 @@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32391
32392 if ((cm_id) && (cm_id->event_handler)) {
32393 if (issue_disconn) {
32394 - atomic_inc(&cm_disconnects);
32395 + atomic_inc_unchecked(&cm_disconnects);
32396 cm_event.event = IW_CM_EVENT_DISCONNECT;
32397 cm_event.status = disconn_status;
32398 cm_event.local_addr = cm_id->local_addr;
32399 @@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32400 }
32401
32402 if (issue_close) {
32403 - atomic_inc(&cm_closes);
32404 + atomic_inc_unchecked(&cm_closes);
32405 nes_disconnect(nesqp, 1);
32406
32407 cm_id->provider_data = nesqp;
32408 @@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32409
32410 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32411 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32412 - atomic_inc(&cm_accepts);
32413 + atomic_inc_unchecked(&cm_accepts);
32414
32415 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32416 netdev_refcnt_read(nesvnic->netdev));
32417 @@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32418 struct nes_cm_core *cm_core;
32419 u8 *start_buff;
32420
32421 - atomic_inc(&cm_rejects);
32422 + atomic_inc_unchecked(&cm_rejects);
32423 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32424 loopback = cm_node->loopbackpartner;
32425 cm_core = cm_node->cm_core;
32426 @@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32427 ntohl(cm_id->local_addr.sin_addr.s_addr),
32428 ntohs(cm_id->local_addr.sin_port));
32429
32430 - atomic_inc(&cm_connects);
32431 + atomic_inc_unchecked(&cm_connects);
32432 nesqp->active_conn = 1;
32433
32434 /* cache the cm_id in the qp */
32435 @@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32436 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32437 return err;
32438 }
32439 - atomic_inc(&cm_listens_created);
32440 + atomic_inc_unchecked(&cm_listens_created);
32441 }
32442
32443 cm_id->add_ref(cm_id);
32444 @@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32445
32446 if (nesqp->destroyed)
32447 return;
32448 - atomic_inc(&cm_connecteds);
32449 + atomic_inc_unchecked(&cm_connecteds);
32450 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32451 " local port 0x%04X. jiffies = %lu.\n",
32452 nesqp->hwqp.qp_id,
32453 @@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32454
32455 cm_id->add_ref(cm_id);
32456 ret = cm_id->event_handler(cm_id, &cm_event);
32457 - atomic_inc(&cm_closes);
32458 + atomic_inc_unchecked(&cm_closes);
32459 cm_event.event = IW_CM_EVENT_CLOSE;
32460 cm_event.status = 0;
32461 cm_event.provider_data = cm_id->provider_data;
32462 @@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32463 return;
32464 cm_id = cm_node->cm_id;
32465
32466 - atomic_inc(&cm_connect_reqs);
32467 + atomic_inc_unchecked(&cm_connect_reqs);
32468 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32469 cm_node, cm_id, jiffies);
32470
32471 @@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32472 return;
32473 cm_id = cm_node->cm_id;
32474
32475 - atomic_inc(&cm_connect_reqs);
32476 + atomic_inc_unchecked(&cm_connect_reqs);
32477 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32478 cm_node, cm_id, jiffies);
32479
32480 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32481 index 3ba7be3..c81f6ff 100644
32482 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32483 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32484 @@ -40,8 +40,8 @@
32485 #include "nes.h"
32486 #include "nes_mgt.h"
32487
32488 -atomic_t pau_qps_created;
32489 -atomic_t pau_qps_destroyed;
32490 +atomic_unchecked_t pau_qps_created;
32491 +atomic_unchecked_t pau_qps_destroyed;
32492
32493 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32494 {
32495 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32496 {
32497 struct sk_buff *skb;
32498 unsigned long flags;
32499 - atomic_inc(&pau_qps_destroyed);
32500 + atomic_inc_unchecked(&pau_qps_destroyed);
32501
32502 /* Free packets that have not yet been forwarded */
32503 /* Lock is acquired by skb_dequeue when removing the skb */
32504 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32505 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32506 skb_queue_head_init(&nesqp->pau_list);
32507 spin_lock_init(&nesqp->pau_lock);
32508 - atomic_inc(&pau_qps_created);
32509 + atomic_inc_unchecked(&pau_qps_created);
32510 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32511 }
32512
32513 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32514 index f3a3ecf..57d311d 100644
32515 --- a/drivers/infiniband/hw/nes/nes_nic.c
32516 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32517 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32518 target_stat_values[++index] = mh_detected;
32519 target_stat_values[++index] = mh_pauses_sent;
32520 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32521 - target_stat_values[++index] = atomic_read(&cm_connects);
32522 - target_stat_values[++index] = atomic_read(&cm_accepts);
32523 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32524 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32525 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32526 - target_stat_values[++index] = atomic_read(&cm_rejects);
32527 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32528 - target_stat_values[++index] = atomic_read(&qps_created);
32529 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32530 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32531 - target_stat_values[++index] = atomic_read(&cm_closes);
32532 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32533 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32534 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32535 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32536 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32537 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32538 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32539 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32540 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32541 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32542 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32543 target_stat_values[++index] = cm_packets_sent;
32544 target_stat_values[++index] = cm_packets_bounced;
32545 target_stat_values[++index] = cm_packets_created;
32546 target_stat_values[++index] = cm_packets_received;
32547 target_stat_values[++index] = cm_packets_dropped;
32548 target_stat_values[++index] = cm_packets_retrans;
32549 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32550 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32551 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32552 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32553 target_stat_values[++index] = cm_backlog_drops;
32554 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32555 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32556 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32557 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32558 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32559 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32560 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32561 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32562 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32563 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32564 target_stat_values[++index] = nesadapter->free_4kpbl;
32565 target_stat_values[++index] = nesadapter->free_256pbl;
32566 target_stat_values[++index] = int_mod_timer_init;
32567 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32568 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32569 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32570 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32571 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32572 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32573 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32574 }
32575
32576 /**
32577 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32578 index 8b8812d..a5e1133 100644
32579 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32580 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32581 @@ -46,9 +46,9 @@
32582
32583 #include <rdma/ib_umem.h>
32584
32585 -atomic_t mod_qp_timouts;
32586 -atomic_t qps_created;
32587 -atomic_t sw_qps_destroyed;
32588 +atomic_unchecked_t mod_qp_timouts;
32589 +atomic_unchecked_t qps_created;
32590 +atomic_unchecked_t sw_qps_destroyed;
32591
32592 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32593
32594 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32595 if (init_attr->create_flags)
32596 return ERR_PTR(-EINVAL);
32597
32598 - atomic_inc(&qps_created);
32599 + atomic_inc_unchecked(&qps_created);
32600 switch (init_attr->qp_type) {
32601 case IB_QPT_RC:
32602 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32603 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32604 struct iw_cm_event cm_event;
32605 int ret = 0;
32606
32607 - atomic_inc(&sw_qps_destroyed);
32608 + atomic_inc_unchecked(&sw_qps_destroyed);
32609 nesqp->destroyed = 1;
32610
32611 /* Blow away the connection if it exists. */
32612 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32613 index 7e62f41..4c2b8e2 100644
32614 --- a/drivers/infiniband/hw/qib/qib.h
32615 +++ b/drivers/infiniband/hw/qib/qib.h
32616 @@ -51,6 +51,7 @@
32617 #include <linux/completion.h>
32618 #include <linux/kref.h>
32619 #include <linux/sched.h>
32620 +#include <linux/slab.h>
32621
32622 #include "qib_common.h"
32623 #include "qib_verbs.h"
32624 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32625 index da739d9..da1c7f4 100644
32626 --- a/drivers/input/gameport/gameport.c
32627 +++ b/drivers/input/gameport/gameport.c
32628 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32629 */
32630 static void gameport_init_port(struct gameport *gameport)
32631 {
32632 - static atomic_t gameport_no = ATOMIC_INIT(0);
32633 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32634
32635 __module_get(THIS_MODULE);
32636
32637 mutex_init(&gameport->drv_mutex);
32638 device_initialize(&gameport->dev);
32639 dev_set_name(&gameport->dev, "gameport%lu",
32640 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32641 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32642 gameport->dev.bus = &gameport_bus;
32643 gameport->dev.release = gameport_release_port;
32644 if (gameport->parent)
32645 diff --git a/drivers/input/input.c b/drivers/input/input.c
32646 index 8921c61..f5cd63d 100644
32647 --- a/drivers/input/input.c
32648 +++ b/drivers/input/input.c
32649 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32650 */
32651 int input_register_device(struct input_dev *dev)
32652 {
32653 - static atomic_t input_no = ATOMIC_INIT(0);
32654 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32655 struct input_handler *handler;
32656 const char *path;
32657 int error;
32658 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32659 dev->setkeycode = input_default_setkeycode;
32660
32661 dev_set_name(&dev->dev, "input%ld",
32662 - (unsigned long) atomic_inc_return(&input_no) - 1);
32663 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32664
32665 error = device_add(&dev->dev);
32666 if (error)
32667 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32668 index 04c69af..5f92d00 100644
32669 --- a/drivers/input/joystick/sidewinder.c
32670 +++ b/drivers/input/joystick/sidewinder.c
32671 @@ -30,6 +30,7 @@
32672 #include <linux/kernel.h>
32673 #include <linux/module.h>
32674 #include <linux/slab.h>
32675 +#include <linux/sched.h>
32676 #include <linux/init.h>
32677 #include <linux/input.h>
32678 #include <linux/gameport.h>
32679 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32680 index 83811e4..0822b90 100644
32681 --- a/drivers/input/joystick/xpad.c
32682 +++ b/drivers/input/joystick/xpad.c
32683 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32684
32685 static int xpad_led_probe(struct usb_xpad *xpad)
32686 {
32687 - static atomic_t led_seq = ATOMIC_INIT(0);
32688 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32689 long led_no;
32690 struct xpad_led *led;
32691 struct led_classdev *led_cdev;
32692 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32693 if (!led)
32694 return -ENOMEM;
32695
32696 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32697 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32698
32699 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32700 led->xpad = xpad;
32701 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32702 index 0110b5a..d3ad144 100644
32703 --- a/drivers/input/mousedev.c
32704 +++ b/drivers/input/mousedev.c
32705 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32706
32707 spin_unlock_irq(&client->packet_lock);
32708
32709 - if (copy_to_user(buffer, data, count))
32710 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32711 return -EFAULT;
32712
32713 return count;
32714 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32715 index d0f7533..fb8215b 100644
32716 --- a/drivers/input/serio/serio.c
32717 +++ b/drivers/input/serio/serio.c
32718 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32719 */
32720 static void serio_init_port(struct serio *serio)
32721 {
32722 - static atomic_t serio_no = ATOMIC_INIT(0);
32723 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32724
32725 __module_get(THIS_MODULE);
32726
32727 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32728 mutex_init(&serio->drv_mutex);
32729 device_initialize(&serio->dev);
32730 dev_set_name(&serio->dev, "serio%ld",
32731 - (long)atomic_inc_return(&serio_no) - 1);
32732 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32733 serio->dev.bus = &serio_bus;
32734 serio->dev.release = serio_release_port;
32735 serio->dev.groups = serio_device_attr_groups;
32736 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32737 index 38c4bd8..58965d9 100644
32738 --- a/drivers/isdn/capi/capi.c
32739 +++ b/drivers/isdn/capi/capi.c
32740 @@ -83,8 +83,8 @@ struct capiminor {
32741
32742 struct capi20_appl *ap;
32743 u32 ncci;
32744 - atomic_t datahandle;
32745 - atomic_t msgid;
32746 + atomic_unchecked_t datahandle;
32747 + atomic_unchecked_t msgid;
32748
32749 struct tty_port port;
32750 int ttyinstop;
32751 @@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32752 capimsg_setu16(s, 2, mp->ap->applid);
32753 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32754 capimsg_setu8 (s, 5, CAPI_RESP);
32755 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32756 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32757 capimsg_setu32(s, 8, mp->ncci);
32758 capimsg_setu16(s, 12, datahandle);
32759 }
32760 @@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
32761 mp->outbytes -= len;
32762 spin_unlock_bh(&mp->outlock);
32763
32764 - datahandle = atomic_inc_return(&mp->datahandle);
32765 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32766 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32767 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32768 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32769 capimsg_setu16(skb->data, 2, mp->ap->applid);
32770 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32771 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32772 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32773 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32774 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32775 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32776 capimsg_setu16(skb->data, 16, len); /* Data length */
32777 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32778 index a6d9fd2..afdb8a3 100644
32779 --- a/drivers/isdn/gigaset/interface.c
32780 +++ b/drivers/isdn/gigaset/interface.c
32781 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32782 }
32783 tty->driver_data = cs;
32784
32785 - ++cs->port.count;
32786 + atomic_inc(&cs->port.count);
32787
32788 - if (cs->port.count == 1) {
32789 + if (atomic_read(&cs->port.count) == 1) {
32790 tty_port_tty_set(&cs->port, tty);
32791 tty->low_latency = 1;
32792 }
32793 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32794
32795 if (!cs->connected)
32796 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32797 - else if (!cs->port.count)
32798 + else if (!atomic_read(&cs->port.count))
32799 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32800 - else if (!--cs->port.count)
32801 + else if (!atomic_dec_return(&cs->port.count))
32802 tty_port_tty_set(&cs->port, NULL);
32803
32804 mutex_unlock(&cs->mutex);
32805 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32806 index 821f7ac..28d4030 100644
32807 --- a/drivers/isdn/hardware/avm/b1.c
32808 +++ b/drivers/isdn/hardware/avm/b1.c
32809 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
32810 }
32811 if (left) {
32812 if (t4file->user) {
32813 - if (copy_from_user(buf, dp, left))
32814 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32815 return -EFAULT;
32816 } else {
32817 memcpy(buf, dp, left);
32818 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
32819 }
32820 if (left) {
32821 if (config->user) {
32822 - if (copy_from_user(buf, dp, left))
32823 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32824 return -EFAULT;
32825 } else {
32826 memcpy(buf, dp, left);
32827 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32828 index dd6b53a..19d9ee6 100644
32829 --- a/drivers/isdn/hardware/eicon/divasync.h
32830 +++ b/drivers/isdn/hardware/eicon/divasync.h
32831 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32832 } diva_didd_add_adapter_t;
32833 typedef struct _diva_didd_remove_adapter {
32834 IDI_CALL p_request;
32835 -} diva_didd_remove_adapter_t;
32836 +} __no_const diva_didd_remove_adapter_t;
32837 typedef struct _diva_didd_read_adapter_array {
32838 void *buffer;
32839 dword length;
32840 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32841 index d303e65..28bcb7b 100644
32842 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32843 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32844 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32845 typedef struct _diva_os_idi_adapter_interface {
32846 diva_init_card_proc_t cleanup_adapter_proc;
32847 diva_cmd_card_proc_t cmd_proc;
32848 -} diva_os_idi_adapter_interface_t;
32849 +} __no_const diva_os_idi_adapter_interface_t;
32850
32851 typedef struct _diva_os_xdi_adapter {
32852 struct list_head link;
32853 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
32854 index 7bc5067..fd36232 100644
32855 --- a/drivers/isdn/i4l/isdn_tty.c
32856 +++ b/drivers/isdn/i4l/isdn_tty.c
32857 @@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
32858 port = &info->port;
32859 #ifdef ISDN_DEBUG_MODEM_OPEN
32860 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
32861 - port->count);
32862 + atomic_read(&port->count))
32863 #endif
32864 - port->count++;
32865 + atomic_inc(&port->count);
32866 tty->driver_data = info;
32867 port->tty = tty;
32868 tty->port = port;
32869 @@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32870 #endif
32871 return;
32872 }
32873 - if ((tty->count == 1) && (port->count != 1)) {
32874 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
32875 /*
32876 * Uh, oh. tty->count is 1, which means that the tty
32877 * structure will be freed. Info->count should always
32878 @@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32879 * serial port won't be shutdown.
32880 */
32881 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
32882 - "info->count is %d\n", port->count);
32883 - port->count = 1;
32884 + "info->count is %d\n", atomic_read(&port->count));
32885 + atomic_set(&port->count, 1);
32886 }
32887 - if (--port->count < 0) {
32888 + if (atomic_dec_return(&port->count) < 0) {
32889 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
32890 - info->line, port->count);
32891 - port->count = 0;
32892 + info->line, atomic_read(&port->count));
32893 + atomic_set(&port->count, 0);
32894 }
32895 - if (port->count) {
32896 + if (atomic_read(&port->count)) {
32897 #ifdef ISDN_DEBUG_MODEM_OPEN
32898 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
32899 #endif
32900 @@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
32901 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
32902 return;
32903 isdn_tty_shutdown(info);
32904 - port->count = 0;
32905 + atomic_set(&port->count, 0);
32906 port->flags &= ~ASYNC_NORMAL_ACTIVE;
32907 port->tty = NULL;
32908 wake_up_interruptible(&port->open_wait);
32909 @@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
32910 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
32911 modem_info *info = &dev->mdm.info[i];
32912
32913 - if (info->port.count == 0)
32914 + if (atomic_read(&info->port.count) == 0)
32915 continue;
32916 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
32917 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
32918 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32919 index e74df7c..03a03ba 100644
32920 --- a/drivers/isdn/icn/icn.c
32921 +++ b/drivers/isdn/icn/icn.c
32922 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
32923 if (count > len)
32924 count = len;
32925 if (user) {
32926 - if (copy_from_user(msg, buf, count))
32927 + if (count > sizeof msg || copy_from_user(msg, buf, count))
32928 return -EFAULT;
32929 } else
32930 memcpy(msg, buf, count);
32931 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32932 index b5fdcb7..5b6c59f 100644
32933 --- a/drivers/lguest/core.c
32934 +++ b/drivers/lguest/core.c
32935 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
32936 * it's worked so far. The end address needs +1 because __get_vm_area
32937 * allocates an extra guard page, so we need space for that.
32938 */
32939 +
32940 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32941 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32942 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32943 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32944 +#else
32945 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32946 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32947 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32948 +#endif
32949 +
32950 if (!switcher_vma) {
32951 err = -ENOMEM;
32952 printk("lguest: could not map switcher pages high\n");
32953 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
32954 * Now the Switcher is mapped at the right address, we can't fail!
32955 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
32956 */
32957 - memcpy(switcher_vma->addr, start_switcher_text,
32958 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32959 end_switcher_text - start_switcher_text);
32960
32961 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32962 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
32963 index 39809035..ce25c5e 100644
32964 --- a/drivers/lguest/x86/core.c
32965 +++ b/drivers/lguest/x86/core.c
32966 @@ -59,7 +59,7 @@ static struct {
32967 /* Offset from where switcher.S was compiled to where we've copied it */
32968 static unsigned long switcher_offset(void)
32969 {
32970 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
32971 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
32972 }
32973
32974 /* This cpu's struct lguest_pages. */
32975 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
32976 * These copies are pretty cheap, so we do them unconditionally: */
32977 /* Save the current Host top-level page directory.
32978 */
32979 +
32980 +#ifdef CONFIG_PAX_PER_CPU_PGD
32981 + pages->state.host_cr3 = read_cr3();
32982 +#else
32983 pages->state.host_cr3 = __pa(current->mm->pgd);
32984 +#endif
32985 +
32986 /*
32987 * Set up the Guest's page tables to see this CPU's pages (and no
32988 * other CPU's pages).
32989 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
32990 * compiled-in switcher code and the high-mapped copy we just made.
32991 */
32992 for (i = 0; i < IDT_ENTRIES; i++)
32993 - default_idt_entries[i] += switcher_offset();
32994 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
32995
32996 /*
32997 * Set up the Switcher's per-cpu areas.
32998 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
32999 * it will be undisturbed when we switch. To change %cs and jump we
33000 * need this structure to feed to Intel's "lcall" instruction.
33001 */
33002 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33003 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33004 lguest_entry.segment = LGUEST_CS;
33005
33006 /*
33007 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33008 index 40634b0..4f5855e 100644
33009 --- a/drivers/lguest/x86/switcher_32.S
33010 +++ b/drivers/lguest/x86/switcher_32.S
33011 @@ -87,6 +87,7 @@
33012 #include <asm/page.h>
33013 #include <asm/segment.h>
33014 #include <asm/lguest.h>
33015 +#include <asm/processor-flags.h>
33016
33017 // We mark the start of the code to copy
33018 // It's placed in .text tho it's never run here
33019 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33020 // Changes type when we load it: damn Intel!
33021 // For after we switch over our page tables
33022 // That entry will be read-only: we'd crash.
33023 +
33024 +#ifdef CONFIG_PAX_KERNEXEC
33025 + mov %cr0, %edx
33026 + xor $X86_CR0_WP, %edx
33027 + mov %edx, %cr0
33028 +#endif
33029 +
33030 movl $(GDT_ENTRY_TSS*8), %edx
33031 ltr %dx
33032
33033 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33034 // Let's clear it again for our return.
33035 // The GDT descriptor of the Host
33036 // Points to the table after two "size" bytes
33037 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33038 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33039 // Clear "used" from type field (byte 5, bit 2)
33040 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33041 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33042 +
33043 +#ifdef CONFIG_PAX_KERNEXEC
33044 + mov %cr0, %eax
33045 + xor $X86_CR0_WP, %eax
33046 + mov %eax, %cr0
33047 +#endif
33048
33049 // Once our page table's switched, the Guest is live!
33050 // The Host fades as we run this final step.
33051 @@ -295,13 +309,12 @@ deliver_to_host:
33052 // I consulted gcc, and it gave
33053 // These instructions, which I gladly credit:
33054 leal (%edx,%ebx,8), %eax
33055 - movzwl (%eax),%edx
33056 - movl 4(%eax), %eax
33057 - xorw %ax, %ax
33058 - orl %eax, %edx
33059 + movl 4(%eax), %edx
33060 + movw (%eax), %dx
33061 // Now the address of the handler's in %edx
33062 // We call it now: its "iret" drops us home.
33063 - jmp *%edx
33064 + ljmp $__KERNEL_CS, $1f
33065 +1: jmp *%edx
33066
33067 // Every interrupt can come to us here
33068 // But we must truly tell each apart.
33069 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33070 index 20e5c2c..9e849a9 100644
33071 --- a/drivers/macintosh/macio_asic.c
33072 +++ b/drivers/macintosh/macio_asic.c
33073 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33074 * MacIO is matched against any Apple ID, it's probe() function
33075 * will then decide wether it applies or not
33076 */
33077 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33078 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33079 .vendor = PCI_VENDOR_ID_APPLE,
33080 .device = PCI_ANY_ID,
33081 .subvendor = PCI_ANY_ID,
33082 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33083 index 15dbe03..743fc65 100644
33084 --- a/drivers/md/bitmap.c
33085 +++ b/drivers/md/bitmap.c
33086 @@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33087 chunk_kb ? "KB" : "B");
33088 if (bitmap->storage.file) {
33089 seq_printf(seq, ", file: ");
33090 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33091 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33092 }
33093
33094 seq_printf(seq, "\n");
33095 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33096 index a1a3e6d..1918bfc 100644
33097 --- a/drivers/md/dm-ioctl.c
33098 +++ b/drivers/md/dm-ioctl.c
33099 @@ -1590,7 +1590,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33100 cmd == DM_LIST_VERSIONS_CMD)
33101 return 0;
33102
33103 - if ((cmd == DM_DEV_CREATE_CMD)) {
33104 + if (cmd == DM_DEV_CREATE_CMD) {
33105 if (!*param->name) {
33106 DMWARN("name not supplied when creating device");
33107 return -EINVAL;
33108 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33109 index b58b7a3..8018b19 100644
33110 --- a/drivers/md/dm-raid1.c
33111 +++ b/drivers/md/dm-raid1.c
33112 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33113
33114 struct mirror {
33115 struct mirror_set *ms;
33116 - atomic_t error_count;
33117 + atomic_unchecked_t error_count;
33118 unsigned long error_type;
33119 struct dm_dev *dev;
33120 sector_t offset;
33121 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33122 struct mirror *m;
33123
33124 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33125 - if (!atomic_read(&m->error_count))
33126 + if (!atomic_read_unchecked(&m->error_count))
33127 return m;
33128
33129 return NULL;
33130 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33131 * simple way to tell if a device has encountered
33132 * errors.
33133 */
33134 - atomic_inc(&m->error_count);
33135 + atomic_inc_unchecked(&m->error_count);
33136
33137 if (test_and_set_bit(error_type, &m->error_type))
33138 return;
33139 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33140 struct mirror *m = get_default_mirror(ms);
33141
33142 do {
33143 - if (likely(!atomic_read(&m->error_count)))
33144 + if (likely(!atomic_read_unchecked(&m->error_count)))
33145 return m;
33146
33147 if (m-- == ms->mirror)
33148 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33149 {
33150 struct mirror *default_mirror = get_default_mirror(m->ms);
33151
33152 - return !atomic_read(&default_mirror->error_count);
33153 + return !atomic_read_unchecked(&default_mirror->error_count);
33154 }
33155
33156 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33157 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33158 */
33159 if (likely(region_in_sync(ms, region, 1)))
33160 m = choose_mirror(ms, bio->bi_sector);
33161 - else if (m && atomic_read(&m->error_count))
33162 + else if (m && atomic_read_unchecked(&m->error_count))
33163 m = NULL;
33164
33165 if (likely(m))
33166 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33167 }
33168
33169 ms->mirror[mirror].ms = ms;
33170 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33171 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33172 ms->mirror[mirror].error_type = 0;
33173 ms->mirror[mirror].offset = offset;
33174
33175 @@ -1352,7 +1352,7 @@ static void mirror_resume(struct dm_target *ti)
33176 */
33177 static char device_status_char(struct mirror *m)
33178 {
33179 - if (!atomic_read(&(m->error_count)))
33180 + if (!atomic_read_unchecked(&(m->error_count)))
33181 return 'A';
33182
33183 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33184 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33185 index 35c94ff..20d4c17 100644
33186 --- a/drivers/md/dm-stripe.c
33187 +++ b/drivers/md/dm-stripe.c
33188 @@ -20,7 +20,7 @@ struct stripe {
33189 struct dm_dev *dev;
33190 sector_t physical_start;
33191
33192 - atomic_t error_count;
33193 + atomic_unchecked_t error_count;
33194 };
33195
33196 struct stripe_c {
33197 @@ -193,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33198 kfree(sc);
33199 return r;
33200 }
33201 - atomic_set(&(sc->stripe[i].error_count), 0);
33202 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33203 }
33204
33205 ti->private = sc;
33206 @@ -315,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33207 DMEMIT("%d ", sc->stripes);
33208 for (i = 0; i < sc->stripes; i++) {
33209 DMEMIT("%s ", sc->stripe[i].dev->name);
33210 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33211 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33212 'D' : 'A';
33213 }
33214 buffer[i] = '\0';
33215 @@ -362,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33216 */
33217 for (i = 0; i < sc->stripes; i++)
33218 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33219 - atomic_inc(&(sc->stripe[i].error_count));
33220 - if (atomic_read(&(sc->stripe[i].error_count)) <
33221 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33222 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33223 DM_IO_ERROR_THRESHOLD)
33224 schedule_work(&sc->trigger_event);
33225 }
33226 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33227 index 2e227fb..44ead1f 100644
33228 --- a/drivers/md/dm-table.c
33229 +++ b/drivers/md/dm-table.c
33230 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33231 if (!dev_size)
33232 return 0;
33233
33234 - if ((start >= dev_size) || (start + len > dev_size)) {
33235 + if ((start >= dev_size) || (len > dev_size - start)) {
33236 DMWARN("%s: %s too small for target: "
33237 "start=%llu, len=%llu, dev_size=%llu",
33238 dm_device_name(ti->table->md), bdevname(bdev, b),
33239 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33240 index 3e2907f..c28851a 100644
33241 --- a/drivers/md/dm-thin-metadata.c
33242 +++ b/drivers/md/dm-thin-metadata.c
33243 @@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33244
33245 pmd->info.tm = tm;
33246 pmd->info.levels = 2;
33247 - pmd->info.value_type.context = pmd->data_sm;
33248 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33249 pmd->info.value_type.size = sizeof(__le64);
33250 pmd->info.value_type.inc = data_block_inc;
33251 pmd->info.value_type.dec = data_block_dec;
33252 @@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33253
33254 pmd->bl_info.tm = tm;
33255 pmd->bl_info.levels = 1;
33256 - pmd->bl_info.value_type.context = pmd->data_sm;
33257 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33258 pmd->bl_info.value_type.size = sizeof(__le64);
33259 pmd->bl_info.value_type.inc = data_block_inc;
33260 pmd->bl_info.value_type.dec = data_block_dec;
33261 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33262 index e24143c..ce2f21a1 100644
33263 --- a/drivers/md/dm.c
33264 +++ b/drivers/md/dm.c
33265 @@ -176,9 +176,9 @@ struct mapped_device {
33266 /*
33267 * Event handling.
33268 */
33269 - atomic_t event_nr;
33270 + atomic_unchecked_t event_nr;
33271 wait_queue_head_t eventq;
33272 - atomic_t uevent_seq;
33273 + atomic_unchecked_t uevent_seq;
33274 struct list_head uevent_list;
33275 spinlock_t uevent_lock; /* Protect access to uevent_list */
33276
33277 @@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
33278 rwlock_init(&md->map_lock);
33279 atomic_set(&md->holders, 1);
33280 atomic_set(&md->open_count, 0);
33281 - atomic_set(&md->event_nr, 0);
33282 - atomic_set(&md->uevent_seq, 0);
33283 + atomic_set_unchecked(&md->event_nr, 0);
33284 + atomic_set_unchecked(&md->uevent_seq, 0);
33285 INIT_LIST_HEAD(&md->uevent_list);
33286 spin_lock_init(&md->uevent_lock);
33287
33288 @@ -1980,7 +1980,7 @@ static void event_callback(void *context)
33289
33290 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33291
33292 - atomic_inc(&md->event_nr);
33293 + atomic_inc_unchecked(&md->event_nr);
33294 wake_up(&md->eventq);
33295 }
33296
33297 @@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33298
33299 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33300 {
33301 - return atomic_add_return(1, &md->uevent_seq);
33302 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33303 }
33304
33305 uint32_t dm_get_event_nr(struct mapped_device *md)
33306 {
33307 - return atomic_read(&md->event_nr);
33308 + return atomic_read_unchecked(&md->event_nr);
33309 }
33310
33311 int dm_wait_event(struct mapped_device *md, int event_nr)
33312 {
33313 return wait_event_interruptible(md->eventq,
33314 - (event_nr != atomic_read(&md->event_nr)));
33315 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33316 }
33317
33318 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33319 diff --git a/drivers/md/md.c b/drivers/md/md.c
33320 index d5ab449..7e9ed7b 100644
33321 --- a/drivers/md/md.c
33322 +++ b/drivers/md/md.c
33323 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33324 * start build, activate spare
33325 */
33326 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33327 -static atomic_t md_event_count;
33328 +static atomic_unchecked_t md_event_count;
33329 void md_new_event(struct mddev *mddev)
33330 {
33331 - atomic_inc(&md_event_count);
33332 + atomic_inc_unchecked(&md_event_count);
33333 wake_up(&md_event_waiters);
33334 }
33335 EXPORT_SYMBOL_GPL(md_new_event);
33336 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33337 */
33338 static void md_new_event_inintr(struct mddev *mddev)
33339 {
33340 - atomic_inc(&md_event_count);
33341 + atomic_inc_unchecked(&md_event_count);
33342 wake_up(&md_event_waiters);
33343 }
33344
33345 @@ -1565,7 +1565,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33346 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33347 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33348 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33349 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33350 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33351
33352 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33353 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33354 @@ -1809,7 +1809,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33355 else
33356 sb->resync_offset = cpu_to_le64(0);
33357
33358 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33359 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33360
33361 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33362 sb->size = cpu_to_le64(mddev->dev_sectors);
33363 @@ -2803,7 +2803,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33364 static ssize_t
33365 errors_show(struct md_rdev *rdev, char *page)
33366 {
33367 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33368 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33369 }
33370
33371 static ssize_t
33372 @@ -2812,7 +2812,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33373 char *e;
33374 unsigned long n = simple_strtoul(buf, &e, 10);
33375 if (*buf && (*e == 0 || *e == '\n')) {
33376 - atomic_set(&rdev->corrected_errors, n);
33377 + atomic_set_unchecked(&rdev->corrected_errors, n);
33378 return len;
33379 }
33380 return -EINVAL;
33381 @@ -3259,8 +3259,8 @@ int md_rdev_init(struct md_rdev *rdev)
33382 rdev->sb_loaded = 0;
33383 rdev->bb_page = NULL;
33384 atomic_set(&rdev->nr_pending, 0);
33385 - atomic_set(&rdev->read_errors, 0);
33386 - atomic_set(&rdev->corrected_errors, 0);
33387 + atomic_set_unchecked(&rdev->read_errors, 0);
33388 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33389
33390 INIT_LIST_HEAD(&rdev->same_set);
33391 init_waitqueue_head(&rdev->blocked_wait);
33392 @@ -6997,7 +6997,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33393
33394 spin_unlock(&pers_lock);
33395 seq_printf(seq, "\n");
33396 - seq->poll_event = atomic_read(&md_event_count);
33397 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33398 return 0;
33399 }
33400 if (v == (void*)2) {
33401 @@ -7100,7 +7100,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33402 return error;
33403
33404 seq = file->private_data;
33405 - seq->poll_event = atomic_read(&md_event_count);
33406 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33407 return error;
33408 }
33409
33410 @@ -7114,7 +7114,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33411 /* always allow read */
33412 mask = POLLIN | POLLRDNORM;
33413
33414 - if (seq->poll_event != atomic_read(&md_event_count))
33415 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33416 mask |= POLLERR | POLLPRI;
33417 return mask;
33418 }
33419 @@ -7158,7 +7158,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33420 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33421 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33422 (int)part_stat_read(&disk->part0, sectors[1]) -
33423 - atomic_read(&disk->sync_io);
33424 + atomic_read_unchecked(&disk->sync_io);
33425 /* sync IO will cause sync_io to increase before the disk_stats
33426 * as sync_io is counted when a request starts, and
33427 * disk_stats is counted when it completes.
33428 diff --git a/drivers/md/md.h b/drivers/md/md.h
33429 index 7b4a3c3..994ad4f 100644
33430 --- a/drivers/md/md.h
33431 +++ b/drivers/md/md.h
33432 @@ -94,13 +94,13 @@ struct md_rdev {
33433 * only maintained for arrays that
33434 * support hot removal
33435 */
33436 - atomic_t read_errors; /* number of consecutive read errors that
33437 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33438 * we have tried to ignore.
33439 */
33440 struct timespec last_read_error; /* monotonic time since our
33441 * last read error
33442 */
33443 - atomic_t corrected_errors; /* number of corrected read errors,
33444 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33445 * for reporting to userspace and storing
33446 * in superblock.
33447 */
33448 @@ -435,7 +435,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33449
33450 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33451 {
33452 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33453 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33454 }
33455
33456 struct md_personality
33457 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33458 index fc90c11..c8cd9a9 100644
33459 --- a/drivers/md/persistent-data/dm-space-map-checker.c
33460 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
33461 @@ -167,7 +167,7 @@ static int ca_commit(struct count_array *old, struct count_array *new)
33462 /*----------------------------------------------------------------*/
33463
33464 struct sm_checker {
33465 - struct dm_space_map sm;
33466 + dm_space_map_no_const sm;
33467
33468 struct count_array old_counts;
33469 struct count_array counts;
33470 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33471 index 3d0ed53..35dc592 100644
33472 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33473 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33474 @@ -23,7 +23,7 @@
33475 * Space map interface.
33476 */
33477 struct sm_disk {
33478 - struct dm_space_map sm;
33479 + dm_space_map_no_const sm;
33480
33481 struct ll_disk ll;
33482 struct ll_disk old_ll;
33483 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33484 index e89ae5e..062e4c2 100644
33485 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33486 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33487 @@ -43,7 +43,7 @@ struct block_op {
33488 };
33489
33490 struct sm_metadata {
33491 - struct dm_space_map sm;
33492 + dm_space_map_no_const sm;
33493
33494 struct ll_disk ll;
33495 struct ll_disk old_ll;
33496 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33497 index 1cbfc6b..56e1dbb 100644
33498 --- a/drivers/md/persistent-data/dm-space-map.h
33499 +++ b/drivers/md/persistent-data/dm-space-map.h
33500 @@ -60,6 +60,7 @@ struct dm_space_map {
33501 int (*root_size)(struct dm_space_map *sm, size_t *result);
33502 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33503 };
33504 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33505
33506 /*----------------------------------------------------------------*/
33507
33508 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33509 index cacd008..2823610 100644
33510 --- a/drivers/md/raid1.c
33511 +++ b/drivers/md/raid1.c
33512 @@ -1685,7 +1685,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33513 if (r1_sync_page_io(rdev, sect, s,
33514 bio->bi_io_vec[idx].bv_page,
33515 READ) != 0)
33516 - atomic_add(s, &rdev->corrected_errors);
33517 + atomic_add_unchecked(s, &rdev->corrected_errors);
33518 }
33519 sectors -= s;
33520 sect += s;
33521 @@ -1907,7 +1907,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33522 test_bit(In_sync, &rdev->flags)) {
33523 if (r1_sync_page_io(rdev, sect, s,
33524 conf->tmppage, READ)) {
33525 - atomic_add(s, &rdev->corrected_errors);
33526 + atomic_add_unchecked(s, &rdev->corrected_errors);
33527 printk(KERN_INFO
33528 "md/raid1:%s: read error corrected "
33529 "(%d sectors at %llu on %s)\n",
33530 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33531 index 8da6282..8ec7103 100644
33532 --- a/drivers/md/raid10.c
33533 +++ b/drivers/md/raid10.c
33534 @@ -1784,7 +1784,7 @@ static void end_sync_read(struct bio *bio, int error)
33535 /* The write handler will notice the lack of
33536 * R10BIO_Uptodate and record any errors etc
33537 */
33538 - atomic_add(r10_bio->sectors,
33539 + atomic_add_unchecked(r10_bio->sectors,
33540 &conf->mirrors[d].rdev->corrected_errors);
33541
33542 /* for reconstruct, we always reschedule after a read.
33543 @@ -2133,7 +2133,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33544 {
33545 struct timespec cur_time_mon;
33546 unsigned long hours_since_last;
33547 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33548 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33549
33550 ktime_get_ts(&cur_time_mon);
33551
33552 @@ -2155,9 +2155,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33553 * overflowing the shift of read_errors by hours_since_last.
33554 */
33555 if (hours_since_last >= 8 * sizeof(read_errors))
33556 - atomic_set(&rdev->read_errors, 0);
33557 + atomic_set_unchecked(&rdev->read_errors, 0);
33558 else
33559 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33560 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33561 }
33562
33563 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33564 @@ -2211,8 +2211,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33565 return;
33566
33567 check_decay_read_errors(mddev, rdev);
33568 - atomic_inc(&rdev->read_errors);
33569 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33570 + atomic_inc_unchecked(&rdev->read_errors);
33571 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33572 char b[BDEVNAME_SIZE];
33573 bdevname(rdev->bdev, b);
33574
33575 @@ -2220,7 +2220,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33576 "md/raid10:%s: %s: Raid device exceeded "
33577 "read_error threshold [cur %d:max %d]\n",
33578 mdname(mddev), b,
33579 - atomic_read(&rdev->read_errors), max_read_errors);
33580 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33581 printk(KERN_NOTICE
33582 "md/raid10:%s: %s: Failing raid device\n",
33583 mdname(mddev), b);
33584 @@ -2375,7 +2375,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33585 sect +
33586 choose_data_offset(r10_bio, rdev)),
33587 bdevname(rdev->bdev, b));
33588 - atomic_add(s, &rdev->corrected_errors);
33589 + atomic_add_unchecked(s, &rdev->corrected_errors);
33590 }
33591
33592 rdev_dec_pending(rdev, mddev);
33593 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33594 index 04348d7..62a4b9b 100644
33595 --- a/drivers/md/raid5.c
33596 +++ b/drivers/md/raid5.c
33597 @@ -1736,19 +1736,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
33598 mdname(conf->mddev), STRIPE_SECTORS,
33599 (unsigned long long)s,
33600 bdevname(rdev->bdev, b));
33601 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33602 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33603 clear_bit(R5_ReadError, &sh->dev[i].flags);
33604 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33605 }
33606 - if (atomic_read(&rdev->read_errors))
33607 - atomic_set(&rdev->read_errors, 0);
33608 + if (atomic_read_unchecked(&rdev->read_errors))
33609 + atomic_set_unchecked(&rdev->read_errors, 0);
33610 } else {
33611 const char *bdn = bdevname(rdev->bdev, b);
33612 int retry = 0;
33613 int set_bad = 0;
33614
33615 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33616 - atomic_inc(&rdev->read_errors);
33617 + atomic_inc_unchecked(&rdev->read_errors);
33618 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33619 printk_ratelimited(
33620 KERN_WARNING
33621 @@ -1776,7 +1776,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33622 mdname(conf->mddev),
33623 (unsigned long long)s,
33624 bdn);
33625 - } else if (atomic_read(&rdev->read_errors)
33626 + } else if (atomic_read_unchecked(&rdev->read_errors)
33627 > conf->max_nr_stripes)
33628 printk(KERN_WARNING
33629 "md/raid:%s: Too many read errors, failing device %s.\n",
33630 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33631 index 131b938..8572ed1 100644
33632 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33633 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33634 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33635 .subvendor = _subvend, .subdevice = _subdev, \
33636 .driver_data = (unsigned long)&_driverdata }
33637
33638 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33639 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33640 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33641 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33642 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33643 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33644 index fa7188a..04a045e 100644
33645 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33646 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33647 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33648 union {
33649 dmx_ts_cb ts;
33650 dmx_section_cb sec;
33651 - } cb;
33652 + } __no_const cb;
33653
33654 struct dvb_demux *demux;
33655 void *priv;
33656 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33657 index 39eab73..60033e7 100644
33658 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33659 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33660 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33661 const struct dvb_device *template, void *priv, int type)
33662 {
33663 struct dvb_device *dvbdev;
33664 - struct file_operations *dvbdevfops;
33665 + file_operations_no_const *dvbdevfops;
33666 struct device *clsdev;
33667 int minor;
33668 int id;
33669 diff --git a/drivers/media/dvb/dvb-usb/az6007.c b/drivers/media/dvb/dvb-usb/az6007.c
33670 index 4008b9c..ce714f5 100644
33671 --- a/drivers/media/dvb/dvb-usb/az6007.c
33672 +++ b/drivers/media/dvb/dvb-usb/az6007.c
33673 @@ -590,7 +590,7 @@ static int az6007_read_mac_addr(struct dvb_usb_device *d, u8 mac[6])
33674 int ret;
33675
33676 ret = az6007_read(d, AZ6007_READ_DATA, 6, 0, st->data, 6);
33677 - memcpy(mac, st->data, sizeof(mac));
33678 + memcpy(mac, st->data, 6);
33679
33680 if (ret > 0)
33681 deb_info("%s: mac is %02x:%02x:%02x:%02x:%02x:%02x\n",
33682 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33683 index 3940bb0..fb3952a 100644
33684 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33685 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33686 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33687
33688 struct dib0700_adapter_state {
33689 int (*set_param_save) (struct dvb_frontend *);
33690 -};
33691 +} __no_const;
33692
33693 static int dib7070_set_param_override(struct dvb_frontend *fe)
33694 {
33695 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33696 index 9382895..ac8093c 100644
33697 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33698 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33699 @@ -95,7 +95,7 @@ struct su3000_state {
33700
33701 struct s6x0_state {
33702 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33703 -};
33704 +} __no_const;
33705
33706 /* debug */
33707 static int dvb_usb_dw2102_debug;
33708 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33709 index 404f63a..4796533 100644
33710 --- a/drivers/media/dvb/frontends/dib3000.h
33711 +++ b/drivers/media/dvb/frontends/dib3000.h
33712 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33713 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33714 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33715 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33716 -};
33717 +} __no_const;
33718
33719 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33720 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33721 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33722 index 7539a5d..06531a6 100644
33723 --- a/drivers/media/dvb/ngene/ngene-cards.c
33724 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33725 @@ -478,7 +478,7 @@ static struct ngene_info ngene_info_m780 = {
33726
33727 /****************************************************************************/
33728
33729 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33730 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33731 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33732 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33733 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33734 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33735 index 16a089f..1661b11 100644
33736 --- a/drivers/media/radio/radio-cadet.c
33737 +++ b/drivers/media/radio/radio-cadet.c
33738 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33739 unsigned char readbuf[RDS_BUFFER];
33740 int i = 0;
33741
33742 + if (count > RDS_BUFFER)
33743 + return -EFAULT;
33744 mutex_lock(&dev->lock);
33745 if (dev->rdsstat == 0) {
33746 dev->rdsstat = 1;
33747 @@ -347,7 +349,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33748 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33749 mutex_unlock(&dev->lock);
33750
33751 - if (copy_to_user(data, readbuf, i))
33752 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
33753 return -EFAULT;
33754 return i;
33755 }
33756 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33757 index 9cde353..8c6a1c3 100644
33758 --- a/drivers/media/video/au0828/au0828.h
33759 +++ b/drivers/media/video/au0828/au0828.h
33760 @@ -191,7 +191,7 @@ struct au0828_dev {
33761
33762 /* I2C */
33763 struct i2c_adapter i2c_adap;
33764 - struct i2c_algorithm i2c_algo;
33765 + i2c_algorithm_no_const i2c_algo;
33766 struct i2c_client i2c_client;
33767 u32 i2c_rc;
33768
33769 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33770 index 04bf662..e0ac026 100644
33771 --- a/drivers/media/video/cx88/cx88-alsa.c
33772 +++ b/drivers/media/video/cx88/cx88-alsa.c
33773 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33774 * Only boards with eeprom and byte 1 at eeprom=1 have it
33775 */
33776
33777 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33778 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33779 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33780 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33781 {0, }
33782 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33783 index 88cf9d9..bbc4b2c 100644
33784 --- a/drivers/media/video/omap/omap_vout.c
33785 +++ b/drivers/media/video/omap/omap_vout.c
33786 @@ -64,7 +64,6 @@ enum omap_vout_channels {
33787 OMAP_VIDEO2,
33788 };
33789
33790 -static struct videobuf_queue_ops video_vbq_ops;
33791 /* Variables configurable through module params*/
33792 static u32 video1_numbuffers = 3;
33793 static u32 video2_numbuffers = 3;
33794 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33795 {
33796 struct videobuf_queue *q;
33797 struct omap_vout_device *vout = NULL;
33798 + static struct videobuf_queue_ops video_vbq_ops = {
33799 + .buf_setup = omap_vout_buffer_setup,
33800 + .buf_prepare = omap_vout_buffer_prepare,
33801 + .buf_release = omap_vout_buffer_release,
33802 + .buf_queue = omap_vout_buffer_queue,
33803 + };
33804
33805 vout = video_drvdata(file);
33806 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33807 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33808 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33809
33810 q = &vout->vbq;
33811 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33812 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33813 - video_vbq_ops.buf_release = omap_vout_buffer_release;
33814 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33815 spin_lock_init(&vout->vbq_lock);
33816
33817 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33818 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33819 index 036952f..80d356d 100644
33820 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33821 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33822 @@ -196,7 +196,7 @@ struct pvr2_hdw {
33823
33824 /* I2C stuff */
33825 struct i2c_adapter i2c_adap;
33826 - struct i2c_algorithm i2c_algo;
33827 + i2c_algorithm_no_const i2c_algo;
33828 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33829 int i2c_cx25840_hack_state;
33830 int i2c_linked;
33831 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33832 index 02194c0..091733b 100644
33833 --- a/drivers/media/video/timblogiw.c
33834 +++ b/drivers/media/video/timblogiw.c
33835 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33836
33837 /* Platform device functions */
33838
33839 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33840 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33841 .vidioc_querycap = timblogiw_querycap,
33842 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33843 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33844 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33845 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33846 };
33847
33848 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33849 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33850 .owner = THIS_MODULE,
33851 .open = timblogiw_open,
33852 .release = timblogiw_close,
33853 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33854 index d99db56..a16b959 100644
33855 --- a/drivers/message/fusion/mptbase.c
33856 +++ b/drivers/message/fusion/mptbase.c
33857 @@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33858 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33859 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33860
33861 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33862 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33863 +#else
33864 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33865 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33866 +#endif
33867 +
33868 /*
33869 * Rounding UP to nearest 4-kB boundary here...
33870 */
33871 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33872 index 551262e..7551198 100644
33873 --- a/drivers/message/fusion/mptsas.c
33874 +++ b/drivers/message/fusion/mptsas.c
33875 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33876 return 0;
33877 }
33878
33879 +static inline void
33880 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33881 +{
33882 + if (phy_info->port_details) {
33883 + phy_info->port_details->rphy = rphy;
33884 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33885 + ioc->name, rphy));
33886 + }
33887 +
33888 + if (rphy) {
33889 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33890 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33891 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33892 + ioc->name, rphy, rphy->dev.release));
33893 + }
33894 +}
33895 +
33896 /* no mutex */
33897 static void
33898 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33899 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33900 return NULL;
33901 }
33902
33903 -static inline void
33904 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33905 -{
33906 - if (phy_info->port_details) {
33907 - phy_info->port_details->rphy = rphy;
33908 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33909 - ioc->name, rphy));
33910 - }
33911 -
33912 - if (rphy) {
33913 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33914 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33915 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33916 - ioc->name, rphy, rphy->dev.release));
33917 - }
33918 -}
33919 -
33920 static inline struct sas_port *
33921 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33922 {
33923 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
33924 index 0c3ced7..1fe34ec 100644
33925 --- a/drivers/message/fusion/mptscsih.c
33926 +++ b/drivers/message/fusion/mptscsih.c
33927 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33928
33929 h = shost_priv(SChost);
33930
33931 - if (h) {
33932 - if (h->info_kbuf == NULL)
33933 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33934 - return h->info_kbuf;
33935 - h->info_kbuf[0] = '\0';
33936 + if (!h)
33937 + return NULL;
33938
33939 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33940 - h->info_kbuf[size-1] = '\0';
33941 - }
33942 + if (h->info_kbuf == NULL)
33943 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33944 + return h->info_kbuf;
33945 + h->info_kbuf[0] = '\0';
33946 +
33947 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33948 + h->info_kbuf[size-1] = '\0';
33949
33950 return h->info_kbuf;
33951 }
33952 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
33953 index 506c36f..b137580 100644
33954 --- a/drivers/message/i2o/i2o_proc.c
33955 +++ b/drivers/message/i2o/i2o_proc.c
33956 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
33957 "Array Controller Device"
33958 };
33959
33960 -static char *chtostr(u8 * chars, int n)
33961 -{
33962 - char tmp[256];
33963 - tmp[0] = 0;
33964 - return strncat(tmp, (char *)chars, n);
33965 -}
33966 -
33967 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33968 char *group)
33969 {
33970 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
33971
33972 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33973 seq_printf(seq, "%-#8x", ddm_table.module_id);
33974 - seq_printf(seq, "%-29s",
33975 - chtostr(ddm_table.module_name_version, 28));
33976 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33977 seq_printf(seq, "%9d ", ddm_table.data_size);
33978 seq_printf(seq, "%8d", ddm_table.code_size);
33979
33980 @@ -927,8 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
33981
33982 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33983 seq_printf(seq, "%-#8x", dst->module_id);
33984 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33985 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33986 + seq_printf(seq, "%-.28s", dst->module_name_version);
33987 + seq_printf(seq, "%-.8s", dst->date);
33988 seq_printf(seq, "%8d ", dst->module_size);
33989 seq_printf(seq, "%8d ", dst->mpb_size);
33990 seq_printf(seq, "0x%04x", dst->module_flags);
33991 @@ -1259,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
33992 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
33993 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
33994 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
33995 - seq_printf(seq, "Vendor info : %s\n",
33996 - chtostr((u8 *) (work32 + 2), 16));
33997 - seq_printf(seq, "Product info : %s\n",
33998 - chtostr((u8 *) (work32 + 6), 16));
33999 - seq_printf(seq, "Description : %s\n",
34000 - chtostr((u8 *) (work32 + 10), 16));
34001 - seq_printf(seq, "Product rev. : %s\n",
34002 - chtostr((u8 *) (work32 + 14), 8));
34003 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34004 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34005 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34006 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34007
34008 seq_printf(seq, "Serial number : ");
34009 print_serial_number(seq, (u8 *) (work32 + 16),
34010 @@ -1311,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34011 }
34012
34013 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34014 - seq_printf(seq, "Module name : %s\n",
34015 - chtostr(result.module_name, 24));
34016 - seq_printf(seq, "Module revision : %s\n",
34017 - chtostr(result.module_rev, 8));
34018 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34019 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34020
34021 seq_printf(seq, "Serial number : ");
34022 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34023 @@ -1345,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34024 return 0;
34025 }
34026
34027 - seq_printf(seq, "Device name : %s\n",
34028 - chtostr(result.device_name, 64));
34029 - seq_printf(seq, "Service name : %s\n",
34030 - chtostr(result.service_name, 64));
34031 - seq_printf(seq, "Physical name : %s\n",
34032 - chtostr(result.physical_location, 64));
34033 - seq_printf(seq, "Instance number : %s\n",
34034 - chtostr(result.instance_number, 4));
34035 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34036 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34037 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34038 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34039
34040 return 0;
34041 }
34042 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34043 index a8c08f3..155fe3d 100644
34044 --- a/drivers/message/i2o/iop.c
34045 +++ b/drivers/message/i2o/iop.c
34046 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34047
34048 spin_lock_irqsave(&c->context_list_lock, flags);
34049
34050 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34051 - atomic_inc(&c->context_list_counter);
34052 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34053 + atomic_inc_unchecked(&c->context_list_counter);
34054
34055 - entry->context = atomic_read(&c->context_list_counter);
34056 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34057
34058 list_add(&entry->list, &c->context_list);
34059
34060 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34061
34062 #if BITS_PER_LONG == 64
34063 spin_lock_init(&c->context_list_lock);
34064 - atomic_set(&c->context_list_counter, 0);
34065 + atomic_set_unchecked(&c->context_list_counter, 0);
34066 INIT_LIST_HEAD(&c->context_list);
34067 #endif
34068
34069 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34070 index 7ce65f4..e66e9bc 100644
34071 --- a/drivers/mfd/abx500-core.c
34072 +++ b/drivers/mfd/abx500-core.c
34073 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34074
34075 struct abx500_device_entry {
34076 struct list_head list;
34077 - struct abx500_ops ops;
34078 + abx500_ops_no_const ops;
34079 struct device *dev;
34080 };
34081
34082 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34083 index 2ea9998..51dabee 100644
34084 --- a/drivers/mfd/janz-cmodio.c
34085 +++ b/drivers/mfd/janz-cmodio.c
34086 @@ -13,6 +13,7 @@
34087
34088 #include <linux/kernel.h>
34089 #include <linux/module.h>
34090 +#include <linux/slab.h>
34091 #include <linux/init.h>
34092 #include <linux/pci.h>
34093 #include <linux/interrupt.h>
34094 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34095 index a981e2a..5ca0c8b 100644
34096 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34097 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34098 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34099 * the lid is closed. This leads to interrupts as soon as a little move
34100 * is done.
34101 */
34102 - atomic_inc(&lis3->count);
34103 + atomic_inc_unchecked(&lis3->count);
34104
34105 wake_up_interruptible(&lis3->misc_wait);
34106 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34107 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34108 if (lis3->pm_dev)
34109 pm_runtime_get_sync(lis3->pm_dev);
34110
34111 - atomic_set(&lis3->count, 0);
34112 + atomic_set_unchecked(&lis3->count, 0);
34113 return 0;
34114 }
34115
34116 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34117 add_wait_queue(&lis3->misc_wait, &wait);
34118 while (true) {
34119 set_current_state(TASK_INTERRUPTIBLE);
34120 - data = atomic_xchg(&lis3->count, 0);
34121 + data = atomic_xchg_unchecked(&lis3->count, 0);
34122 if (data)
34123 break;
34124
34125 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34126 struct lis3lv02d, miscdev);
34127
34128 poll_wait(file, &lis3->misc_wait, wait);
34129 - if (atomic_read(&lis3->count))
34130 + if (atomic_read_unchecked(&lis3->count))
34131 return POLLIN | POLLRDNORM;
34132 return 0;
34133 }
34134 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34135 index 2b1482a..5d33616 100644
34136 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34137 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34138 @@ -266,7 +266,7 @@ struct lis3lv02d {
34139 struct input_polled_dev *idev; /* input device */
34140 struct platform_device *pdev; /* platform device */
34141 struct regulator_bulk_data regulators[2];
34142 - atomic_t count; /* interrupt count after last read */
34143 + atomic_unchecked_t count; /* interrupt count after last read */
34144 union axis_conversion ac; /* hw -> logical axis */
34145 int mapped_btns[3];
34146
34147 diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
34148 index 28adefe..08aad69 100644
34149 --- a/drivers/misc/lkdtm.c
34150 +++ b/drivers/misc/lkdtm.c
34151 @@ -477,6 +477,8 @@ static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf,
34152 int i, n, out;
34153
34154 buf = (char *)__get_free_page(GFP_KERNEL);
34155 + if (buf == NULL)
34156 + return -ENOMEM;
34157
34158 n = snprintf(buf, PAGE_SIZE, "Available crash types:\n");
34159 for (i = 0; i < ARRAY_SIZE(cp_type); i++)
34160 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34161 index 2f30bad..c4c13d0 100644
34162 --- a/drivers/misc/sgi-gru/gruhandles.c
34163 +++ b/drivers/misc/sgi-gru/gruhandles.c
34164 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34165 unsigned long nsec;
34166
34167 nsec = CLKS2NSEC(clks);
34168 - atomic_long_inc(&mcs_op_statistics[op].count);
34169 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34170 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34171 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34172 if (mcs_op_statistics[op].max < nsec)
34173 mcs_op_statistics[op].max = nsec;
34174 }
34175 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34176 index 950dbe9..eeef0f8 100644
34177 --- a/drivers/misc/sgi-gru/gruprocfs.c
34178 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34179 @@ -32,9 +32,9 @@
34180
34181 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34182
34183 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34184 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34185 {
34186 - unsigned long val = atomic_long_read(v);
34187 + unsigned long val = atomic_long_read_unchecked(v);
34188
34189 seq_printf(s, "%16lu %s\n", val, id);
34190 }
34191 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34192
34193 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34194 for (op = 0; op < mcsop_last; op++) {
34195 - count = atomic_long_read(&mcs_op_statistics[op].count);
34196 - total = atomic_long_read(&mcs_op_statistics[op].total);
34197 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34198 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34199 max = mcs_op_statistics[op].max;
34200 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34201 count ? total / count : 0, max);
34202 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34203 index 5c3ce24..4915ccb 100644
34204 --- a/drivers/misc/sgi-gru/grutables.h
34205 +++ b/drivers/misc/sgi-gru/grutables.h
34206 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34207 * GRU statistics.
34208 */
34209 struct gru_stats_s {
34210 - atomic_long_t vdata_alloc;
34211 - atomic_long_t vdata_free;
34212 - atomic_long_t gts_alloc;
34213 - atomic_long_t gts_free;
34214 - atomic_long_t gms_alloc;
34215 - atomic_long_t gms_free;
34216 - atomic_long_t gts_double_allocate;
34217 - atomic_long_t assign_context;
34218 - atomic_long_t assign_context_failed;
34219 - atomic_long_t free_context;
34220 - atomic_long_t load_user_context;
34221 - atomic_long_t load_kernel_context;
34222 - atomic_long_t lock_kernel_context;
34223 - atomic_long_t unlock_kernel_context;
34224 - atomic_long_t steal_user_context;
34225 - atomic_long_t steal_kernel_context;
34226 - atomic_long_t steal_context_failed;
34227 - atomic_long_t nopfn;
34228 - atomic_long_t asid_new;
34229 - atomic_long_t asid_next;
34230 - atomic_long_t asid_wrap;
34231 - atomic_long_t asid_reuse;
34232 - atomic_long_t intr;
34233 - atomic_long_t intr_cbr;
34234 - atomic_long_t intr_tfh;
34235 - atomic_long_t intr_spurious;
34236 - atomic_long_t intr_mm_lock_failed;
34237 - atomic_long_t call_os;
34238 - atomic_long_t call_os_wait_queue;
34239 - atomic_long_t user_flush_tlb;
34240 - atomic_long_t user_unload_context;
34241 - atomic_long_t user_exception;
34242 - atomic_long_t set_context_option;
34243 - atomic_long_t check_context_retarget_intr;
34244 - atomic_long_t check_context_unload;
34245 - atomic_long_t tlb_dropin;
34246 - atomic_long_t tlb_preload_page;
34247 - atomic_long_t tlb_dropin_fail_no_asid;
34248 - atomic_long_t tlb_dropin_fail_upm;
34249 - atomic_long_t tlb_dropin_fail_invalid;
34250 - atomic_long_t tlb_dropin_fail_range_active;
34251 - atomic_long_t tlb_dropin_fail_idle;
34252 - atomic_long_t tlb_dropin_fail_fmm;
34253 - atomic_long_t tlb_dropin_fail_no_exception;
34254 - atomic_long_t tfh_stale_on_fault;
34255 - atomic_long_t mmu_invalidate_range;
34256 - atomic_long_t mmu_invalidate_page;
34257 - atomic_long_t flush_tlb;
34258 - atomic_long_t flush_tlb_gru;
34259 - atomic_long_t flush_tlb_gru_tgh;
34260 - atomic_long_t flush_tlb_gru_zero_asid;
34261 + atomic_long_unchecked_t vdata_alloc;
34262 + atomic_long_unchecked_t vdata_free;
34263 + atomic_long_unchecked_t gts_alloc;
34264 + atomic_long_unchecked_t gts_free;
34265 + atomic_long_unchecked_t gms_alloc;
34266 + atomic_long_unchecked_t gms_free;
34267 + atomic_long_unchecked_t gts_double_allocate;
34268 + atomic_long_unchecked_t assign_context;
34269 + atomic_long_unchecked_t assign_context_failed;
34270 + atomic_long_unchecked_t free_context;
34271 + atomic_long_unchecked_t load_user_context;
34272 + atomic_long_unchecked_t load_kernel_context;
34273 + atomic_long_unchecked_t lock_kernel_context;
34274 + atomic_long_unchecked_t unlock_kernel_context;
34275 + atomic_long_unchecked_t steal_user_context;
34276 + atomic_long_unchecked_t steal_kernel_context;
34277 + atomic_long_unchecked_t steal_context_failed;
34278 + atomic_long_unchecked_t nopfn;
34279 + atomic_long_unchecked_t asid_new;
34280 + atomic_long_unchecked_t asid_next;
34281 + atomic_long_unchecked_t asid_wrap;
34282 + atomic_long_unchecked_t asid_reuse;
34283 + atomic_long_unchecked_t intr;
34284 + atomic_long_unchecked_t intr_cbr;
34285 + atomic_long_unchecked_t intr_tfh;
34286 + atomic_long_unchecked_t intr_spurious;
34287 + atomic_long_unchecked_t intr_mm_lock_failed;
34288 + atomic_long_unchecked_t call_os;
34289 + atomic_long_unchecked_t call_os_wait_queue;
34290 + atomic_long_unchecked_t user_flush_tlb;
34291 + atomic_long_unchecked_t user_unload_context;
34292 + atomic_long_unchecked_t user_exception;
34293 + atomic_long_unchecked_t set_context_option;
34294 + atomic_long_unchecked_t check_context_retarget_intr;
34295 + atomic_long_unchecked_t check_context_unload;
34296 + atomic_long_unchecked_t tlb_dropin;
34297 + atomic_long_unchecked_t tlb_preload_page;
34298 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34299 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34300 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34301 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34302 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34303 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34304 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34305 + atomic_long_unchecked_t tfh_stale_on_fault;
34306 + atomic_long_unchecked_t mmu_invalidate_range;
34307 + atomic_long_unchecked_t mmu_invalidate_page;
34308 + atomic_long_unchecked_t flush_tlb;
34309 + atomic_long_unchecked_t flush_tlb_gru;
34310 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34311 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34312
34313 - atomic_long_t copy_gpa;
34314 - atomic_long_t read_gpa;
34315 + atomic_long_unchecked_t copy_gpa;
34316 + atomic_long_unchecked_t read_gpa;
34317
34318 - atomic_long_t mesq_receive;
34319 - atomic_long_t mesq_receive_none;
34320 - atomic_long_t mesq_send;
34321 - atomic_long_t mesq_send_failed;
34322 - atomic_long_t mesq_noop;
34323 - atomic_long_t mesq_send_unexpected_error;
34324 - atomic_long_t mesq_send_lb_overflow;
34325 - atomic_long_t mesq_send_qlimit_reached;
34326 - atomic_long_t mesq_send_amo_nacked;
34327 - atomic_long_t mesq_send_put_nacked;
34328 - atomic_long_t mesq_page_overflow;
34329 - atomic_long_t mesq_qf_locked;
34330 - atomic_long_t mesq_qf_noop_not_full;
34331 - atomic_long_t mesq_qf_switch_head_failed;
34332 - atomic_long_t mesq_qf_unexpected_error;
34333 - atomic_long_t mesq_noop_unexpected_error;
34334 - atomic_long_t mesq_noop_lb_overflow;
34335 - atomic_long_t mesq_noop_qlimit_reached;
34336 - atomic_long_t mesq_noop_amo_nacked;
34337 - atomic_long_t mesq_noop_put_nacked;
34338 - atomic_long_t mesq_noop_page_overflow;
34339 + atomic_long_unchecked_t mesq_receive;
34340 + atomic_long_unchecked_t mesq_receive_none;
34341 + atomic_long_unchecked_t mesq_send;
34342 + atomic_long_unchecked_t mesq_send_failed;
34343 + atomic_long_unchecked_t mesq_noop;
34344 + atomic_long_unchecked_t mesq_send_unexpected_error;
34345 + atomic_long_unchecked_t mesq_send_lb_overflow;
34346 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34347 + atomic_long_unchecked_t mesq_send_amo_nacked;
34348 + atomic_long_unchecked_t mesq_send_put_nacked;
34349 + atomic_long_unchecked_t mesq_page_overflow;
34350 + atomic_long_unchecked_t mesq_qf_locked;
34351 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34352 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34353 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34354 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34355 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34356 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34357 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34358 + atomic_long_unchecked_t mesq_noop_put_nacked;
34359 + atomic_long_unchecked_t mesq_noop_page_overflow;
34360
34361 };
34362
34363 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34364 tghop_invalidate, mcsop_last};
34365
34366 struct mcs_op_statistic {
34367 - atomic_long_t count;
34368 - atomic_long_t total;
34369 + atomic_long_unchecked_t count;
34370 + atomic_long_unchecked_t total;
34371 unsigned long max;
34372 };
34373
34374 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34375
34376 #define STAT(id) do { \
34377 if (gru_options & OPT_STATS) \
34378 - atomic_long_inc(&gru_stats.id); \
34379 + atomic_long_inc_unchecked(&gru_stats.id); \
34380 } while (0)
34381
34382 #ifdef CONFIG_SGI_GRU_DEBUG
34383 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34384 index c862cd4..0d176fe 100644
34385 --- a/drivers/misc/sgi-xp/xp.h
34386 +++ b/drivers/misc/sgi-xp/xp.h
34387 @@ -288,7 +288,7 @@ struct xpc_interface {
34388 xpc_notify_func, void *);
34389 void (*received) (short, int, void *);
34390 enum xp_retval (*partid_to_nasids) (short, void *);
34391 -};
34392 +} __no_const;
34393
34394 extern struct xpc_interface xpc_interface;
34395
34396 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34397 index b94d5f7..7f494c5 100644
34398 --- a/drivers/misc/sgi-xp/xpc.h
34399 +++ b/drivers/misc/sgi-xp/xpc.h
34400 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34401 void (*received_payload) (struct xpc_channel *, void *);
34402 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34403 };
34404 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34405
34406 /* struct xpc_partition act_state values (for XPC HB) */
34407
34408 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34409 /* found in xpc_main.c */
34410 extern struct device *xpc_part;
34411 extern struct device *xpc_chan;
34412 -extern struct xpc_arch_operations xpc_arch_ops;
34413 +extern xpc_arch_operations_no_const xpc_arch_ops;
34414 extern int xpc_disengage_timelimit;
34415 extern int xpc_disengage_timedout;
34416 extern int xpc_activate_IRQ_rcvd;
34417 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34418 index 8d082b4..aa749ae 100644
34419 --- a/drivers/misc/sgi-xp/xpc_main.c
34420 +++ b/drivers/misc/sgi-xp/xpc_main.c
34421 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34422 .notifier_call = xpc_system_die,
34423 };
34424
34425 -struct xpc_arch_operations xpc_arch_ops;
34426 +xpc_arch_operations_no_const xpc_arch_ops;
34427
34428 /*
34429 * Timer function to enforce the timelimit on the partition disengage.
34430 diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
34431 index 2b62232..acfaeeb 100644
34432 --- a/drivers/misc/ti-st/st_core.c
34433 +++ b/drivers/misc/ti-st/st_core.c
34434 @@ -349,6 +349,11 @@ void st_int_recv(void *disc_data,
34435 st_gdata->rx_skb = alloc_skb(
34436 st_gdata->list[type]->max_frame_size,
34437 GFP_ATOMIC);
34438 + if (st_gdata->rx_skb == NULL) {
34439 + pr_err("out of memory: dropping\n");
34440 + goto done;
34441 + }
34442 +
34443 skb_reserve(st_gdata->rx_skb,
34444 st_gdata->list[type]->reserve);
34445 /* next 2 required for BT only */
34446 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34447 index 504da71..9722d43 100644
34448 --- a/drivers/mmc/host/sdhci-pci.c
34449 +++ b/drivers/mmc/host/sdhci-pci.c
34450 @@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34451 .probe = via_probe,
34452 };
34453
34454 -static const struct pci_device_id pci_ids[] __devinitdata = {
34455 +static const struct pci_device_id pci_ids[] __devinitconst = {
34456 {
34457 .vendor = PCI_VENDOR_ID_RICOH,
34458 .device = PCI_DEVICE_ID_RICOH_R5C822,
34459 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34460 index a4eb8b5..8c0628f 100644
34461 --- a/drivers/mtd/devices/doc2000.c
34462 +++ b/drivers/mtd/devices/doc2000.c
34463 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34464
34465 /* The ECC will not be calculated correctly if less than 512 is written */
34466 /* DBB-
34467 - if (len != 0x200 && eccbuf)
34468 + if (len != 0x200)
34469 printk(KERN_WARNING
34470 "ECC needs a full sector write (adr: %lx size %lx)\n",
34471 (long) to, (long) len);
34472 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34473 index 0650aaf..7718762 100644
34474 --- a/drivers/mtd/nand/denali.c
34475 +++ b/drivers/mtd/nand/denali.c
34476 @@ -26,6 +26,7 @@
34477 #include <linux/pci.h>
34478 #include <linux/mtd/mtd.h>
34479 #include <linux/module.h>
34480 +#include <linux/slab.h>
34481
34482 #include "denali.h"
34483
34484 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34485 index 51b9d6a..52af9a7 100644
34486 --- a/drivers/mtd/nftlmount.c
34487 +++ b/drivers/mtd/nftlmount.c
34488 @@ -24,6 +24,7 @@
34489 #include <asm/errno.h>
34490 #include <linux/delay.h>
34491 #include <linux/slab.h>
34492 +#include <linux/sched.h>
34493 #include <linux/mtd/mtd.h>
34494 #include <linux/mtd/nand.h>
34495 #include <linux/mtd/nftl.h>
34496 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34497 index 6762dc4..9956862 100644
34498 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34499 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34500 @@ -2859,7 +2859,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34501 */
34502
34503 #define ATL2_PARAM(X, desc) \
34504 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34505 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34506 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34507 MODULE_PARM_DESC(X, desc);
34508 #else
34509 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34510 index efd80bd..21fcff0 100644
34511 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34512 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34513 @@ -487,7 +487,7 @@ struct bnx2x_rx_mode_obj {
34514
34515 int (*wait_comp)(struct bnx2x *bp,
34516 struct bnx2x_rx_mode_ramrod_params *p);
34517 -};
34518 +} __no_const;
34519
34520 /********************** Set multicast group ***********************************/
34521
34522 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34523 index 93865f8..5448741 100644
34524 --- a/drivers/net/ethernet/broadcom/tg3.h
34525 +++ b/drivers/net/ethernet/broadcom/tg3.h
34526 @@ -140,6 +140,7 @@
34527 #define CHIPREV_ID_5750_A0 0x4000
34528 #define CHIPREV_ID_5750_A1 0x4001
34529 #define CHIPREV_ID_5750_A3 0x4003
34530 +#define CHIPREV_ID_5750_C1 0x4201
34531 #define CHIPREV_ID_5750_C2 0x4202
34532 #define CHIPREV_ID_5752_A0_HW 0x5000
34533 #define CHIPREV_ID_5752_A0 0x6000
34534 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34535 index c4e8643..0979484 100644
34536 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34537 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34538 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34539 */
34540 struct l2t_skb_cb {
34541 arp_failure_handler_func arp_failure_handler;
34542 -};
34543 +} __no_const;
34544
34545 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34546
34547 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34548 index d3cd489..0fd52dd 100644
34549 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34550 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34551 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34552 for (i=0; i<ETH_ALEN; i++) {
34553 tmp.addr[i] = dev->dev_addr[i];
34554 }
34555 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34556 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34557 break;
34558
34559 case DE4X5_SET_HWADDR: /* Set the hardware address */
34560 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34561 spin_lock_irqsave(&lp->lock, flags);
34562 memcpy(&statbuf, &lp->pktStats, ioc->len);
34563 spin_unlock_irqrestore(&lp->lock, flags);
34564 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34565 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34566 return -EFAULT;
34567 break;
34568 }
34569 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34570 index ed7d1dc..d426748 100644
34571 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34572 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34573 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34574 {NULL}};
34575
34576
34577 -static const char *block_name[] __devinitdata = {
34578 +static const char *block_name[] __devinitconst = {
34579 "21140 non-MII",
34580 "21140 MII PHY",
34581 "21142 Serial PHY",
34582 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34583 index 75d45f8..3d9c55b 100644
34584 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
34585 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34586 @@ -129,7 +129,7 @@ struct uli526x_board_info {
34587 struct uli_phy_ops {
34588 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34589 u16 (*read)(struct uli526x_board_info *, u8, u8);
34590 - } phy;
34591 + } __no_const phy;
34592 struct net_device *next_dev; /* next device */
34593 struct pci_dev *pdev; /* PCI device */
34594 spinlock_t lock;
34595 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34596 index 4d1ffca..7c1ec4d 100644
34597 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34598 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34599 @@ -236,7 +236,7 @@ struct pci_id_info {
34600 int drv_flags; /* Driver use, intended as capability flags. */
34601 };
34602
34603 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34604 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34605 { /* Sometime a Level-One switch card. */
34606 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34607 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34608 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34609 index d7bb52a..3b83588 100644
34610 --- a/drivers/net/ethernet/dlink/sundance.c
34611 +++ b/drivers/net/ethernet/dlink/sundance.c
34612 @@ -218,7 +218,7 @@ enum {
34613 struct pci_id_info {
34614 const char *name;
34615 };
34616 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34617 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34618 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34619 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34620 {"D-Link DFE-580TX 4 port Server Adapter"},
34621 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34622 index bd5cf7e..c165651 100644
34623 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34624 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34625 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34626
34627 if (wrapped)
34628 newacc += 65536;
34629 - ACCESS_ONCE(*acc) = newacc;
34630 + ACCESS_ONCE_RW(*acc) = newacc;
34631 }
34632
34633 void be_parse_stats(struct be_adapter *adapter)
34634 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34635 index 16b0704..d2c07d7 100644
34636 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34637 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34638 @@ -31,6 +31,8 @@
34639 #include <linux/netdevice.h>
34640 #include <linux/phy.h>
34641 #include <linux/platform_device.h>
34642 +#include <linux/interrupt.h>
34643 +#include <linux/irqreturn.h>
34644 #include <net/ip.h>
34645
34646 #include "ftgmac100.h"
34647 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34648 index 829b109..4ae5f6a 100644
34649 --- a/drivers/net/ethernet/faraday/ftmac100.c
34650 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34651 @@ -31,6 +31,8 @@
34652 #include <linux/module.h>
34653 #include <linux/netdevice.h>
34654 #include <linux/platform_device.h>
34655 +#include <linux/interrupt.h>
34656 +#include <linux/irqreturn.h>
34657
34658 #include "ftmac100.h"
34659
34660 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34661 index 9d71c9c..0e4a0ac 100644
34662 --- a/drivers/net/ethernet/fealnx.c
34663 +++ b/drivers/net/ethernet/fealnx.c
34664 @@ -150,7 +150,7 @@ struct chip_info {
34665 int flags;
34666 };
34667
34668 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34669 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34670 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34671 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34672 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34673 diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
34674 index 6e6fffb..588f361 100644
34675 --- a/drivers/net/ethernet/intel/e1000e/e1000.h
34676 +++ b/drivers/net/ethernet/intel/e1000e/e1000.h
34677 @@ -181,7 +181,7 @@ struct e1000_info;
34678 #define E1000_TXDCTL_DMA_BURST_ENABLE \
34679 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
34680 E1000_TXDCTL_COUNT_DESC | \
34681 - (5 << 16) | /* wthresh must be +1 more than desired */\
34682 + (1 << 16) | /* wthresh must be +1 more than desired */\
34683 (1 << 8) | /* hthresh */ \
34684 0x1f) /* pthresh */
34685
34686 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34687 index ed5b409..ec37828 100644
34688 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34689 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34690 @@ -797,6 +797,7 @@ struct e1000_mac_operations {
34691 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34692 s32 (*read_mac_addr)(struct e1000_hw *);
34693 };
34694 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34695
34696 /*
34697 * When to use various PHY register access functions:
34698 @@ -837,6 +838,7 @@ struct e1000_phy_operations {
34699 void (*power_up)(struct e1000_hw *);
34700 void (*power_down)(struct e1000_hw *);
34701 };
34702 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34703
34704 /* Function pointers for the NVM. */
34705 struct e1000_nvm_operations {
34706 @@ -849,9 +851,10 @@ struct e1000_nvm_operations {
34707 s32 (*validate)(struct e1000_hw *);
34708 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34709 };
34710 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34711
34712 struct e1000_mac_info {
34713 - struct e1000_mac_operations ops;
34714 + e1000_mac_operations_no_const ops;
34715 u8 addr[ETH_ALEN];
34716 u8 perm_addr[ETH_ALEN];
34717
34718 @@ -892,7 +895,7 @@ struct e1000_mac_info {
34719 };
34720
34721 struct e1000_phy_info {
34722 - struct e1000_phy_operations ops;
34723 + e1000_phy_operations_no_const ops;
34724
34725 enum e1000_phy_type type;
34726
34727 @@ -926,7 +929,7 @@ struct e1000_phy_info {
34728 };
34729
34730 struct e1000_nvm_info {
34731 - struct e1000_nvm_operations ops;
34732 + e1000_nvm_operations_no_const ops;
34733
34734 enum e1000_nvm_type type;
34735 enum e1000_nvm_override override;
34736 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34737 index c2a51dc..c2bd262 100644
34738 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34739 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34740 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
34741 void (*release_swfw_sync)(struct e1000_hw *, u16);
34742
34743 };
34744 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34745
34746 struct e1000_phy_operations {
34747 s32 (*acquire)(struct e1000_hw *);
34748 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
34749 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34750 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34751 };
34752 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34753
34754 struct e1000_nvm_operations {
34755 s32 (*acquire)(struct e1000_hw *);
34756 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
34757 s32 (*validate)(struct e1000_hw *);
34758 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
34759 };
34760 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34761
34762 struct e1000_info {
34763 s32 (*get_invariants)(struct e1000_hw *);
34764 @@ -364,7 +367,7 @@ struct e1000_info {
34765 extern const struct e1000_info e1000_82575_info;
34766
34767 struct e1000_mac_info {
34768 - struct e1000_mac_operations ops;
34769 + e1000_mac_operations_no_const ops;
34770
34771 u8 addr[6];
34772 u8 perm_addr[6];
34773 @@ -402,7 +405,7 @@ struct e1000_mac_info {
34774 };
34775
34776 struct e1000_phy_info {
34777 - struct e1000_phy_operations ops;
34778 + e1000_phy_operations_no_const ops;
34779
34780 enum e1000_phy_type type;
34781
34782 @@ -437,7 +440,7 @@ struct e1000_phy_info {
34783 };
34784
34785 struct e1000_nvm_info {
34786 - struct e1000_nvm_operations ops;
34787 + e1000_nvm_operations_no_const ops;
34788 enum e1000_nvm_type type;
34789 enum e1000_nvm_override override;
34790
34791 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
34792 s32 (*check_for_ack)(struct e1000_hw *, u16);
34793 s32 (*check_for_rst)(struct e1000_hw *, u16);
34794 };
34795 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34796
34797 struct e1000_mbx_stats {
34798 u32 msgs_tx;
34799 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
34800 };
34801
34802 struct e1000_mbx_info {
34803 - struct e1000_mbx_operations ops;
34804 + e1000_mbx_operations_no_const ops;
34805 struct e1000_mbx_stats stats;
34806 u32 timeout;
34807 u32 usec_delay;
34808 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34809 index 57db3c6..aa825fc 100644
34810 --- a/drivers/net/ethernet/intel/igbvf/vf.h
34811 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
34812 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
34813 s32 (*read_mac_addr)(struct e1000_hw *);
34814 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34815 };
34816 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34817
34818 struct e1000_mac_info {
34819 - struct e1000_mac_operations ops;
34820 + e1000_mac_operations_no_const ops;
34821 u8 addr[6];
34822 u8 perm_addr[6];
34823
34824 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34825 s32 (*check_for_ack)(struct e1000_hw *);
34826 s32 (*check_for_rst)(struct e1000_hw *);
34827 };
34828 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34829
34830 struct e1000_mbx_stats {
34831 u32 msgs_tx;
34832 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34833 };
34834
34835 struct e1000_mbx_info {
34836 - struct e1000_mbx_operations ops;
34837 + e1000_mbx_operations_no_const ops;
34838 struct e1000_mbx_stats stats;
34839 u32 timeout;
34840 u32 usec_delay;
34841 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34842 index dcebd12..c1fe8be 100644
34843 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34844 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34845 @@ -805,7 +805,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
34846 /* store the new cycle speed */
34847 adapter->cycle_speed = cycle_speed;
34848
34849 - ACCESS_ONCE(adapter->base_incval) = incval;
34850 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
34851 smp_mb();
34852
34853 /* grab the ptp lock */
34854 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34855 index 204848d..d8aeaec 100644
34856 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34857 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34858 @@ -2791,6 +2791,7 @@ struct ixgbe_eeprom_operations {
34859 s32 (*update_checksum)(struct ixgbe_hw *);
34860 u16 (*calc_checksum)(struct ixgbe_hw *);
34861 };
34862 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34863
34864 struct ixgbe_mac_operations {
34865 s32 (*init_hw)(struct ixgbe_hw *);
34866 @@ -2856,6 +2857,7 @@ struct ixgbe_mac_operations {
34867 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
34868 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
34869 };
34870 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34871
34872 struct ixgbe_phy_operations {
34873 s32 (*identify)(struct ixgbe_hw *);
34874 @@ -2875,9 +2877,10 @@ struct ixgbe_phy_operations {
34875 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34876 s32 (*check_overtemp)(struct ixgbe_hw *);
34877 };
34878 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34879
34880 struct ixgbe_eeprom_info {
34881 - struct ixgbe_eeprom_operations ops;
34882 + ixgbe_eeprom_operations_no_const ops;
34883 enum ixgbe_eeprom_type type;
34884 u32 semaphore_delay;
34885 u16 word_size;
34886 @@ -2887,7 +2890,7 @@ struct ixgbe_eeprom_info {
34887
34888 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34889 struct ixgbe_mac_info {
34890 - struct ixgbe_mac_operations ops;
34891 + ixgbe_mac_operations_no_const ops;
34892 enum ixgbe_mac_type type;
34893 u8 addr[ETH_ALEN];
34894 u8 perm_addr[ETH_ALEN];
34895 @@ -2916,7 +2919,7 @@ struct ixgbe_mac_info {
34896 };
34897
34898 struct ixgbe_phy_info {
34899 - struct ixgbe_phy_operations ops;
34900 + ixgbe_phy_operations_no_const ops;
34901 struct mdio_if_info mdio;
34902 enum ixgbe_phy_type type;
34903 u32 id;
34904 @@ -2944,6 +2947,7 @@ struct ixgbe_mbx_operations {
34905 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34906 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34907 };
34908 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34909
34910 struct ixgbe_mbx_stats {
34911 u32 msgs_tx;
34912 @@ -2955,7 +2959,7 @@ struct ixgbe_mbx_stats {
34913 };
34914
34915 struct ixgbe_mbx_info {
34916 - struct ixgbe_mbx_operations ops;
34917 + ixgbe_mbx_operations_no_const ops;
34918 struct ixgbe_mbx_stats stats;
34919 u32 timeout;
34920 u32 usec_delay;
34921 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
34922 index 25c951d..cc7cf33 100644
34923 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
34924 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
34925 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
34926 s32 (*clear_vfta)(struct ixgbe_hw *);
34927 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
34928 };
34929 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34930
34931 enum ixgbe_mac_type {
34932 ixgbe_mac_unknown = 0,
34933 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
34934 };
34935
34936 struct ixgbe_mac_info {
34937 - struct ixgbe_mac_operations ops;
34938 + ixgbe_mac_operations_no_const ops;
34939 u8 addr[6];
34940 u8 perm_addr[6];
34941
34942 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
34943 s32 (*check_for_ack)(struct ixgbe_hw *);
34944 s32 (*check_for_rst)(struct ixgbe_hw *);
34945 };
34946 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34947
34948 struct ixgbe_mbx_stats {
34949 u32 msgs_tx;
34950 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
34951 };
34952
34953 struct ixgbe_mbx_info {
34954 - struct ixgbe_mbx_operations ops;
34955 + ixgbe_mbx_operations_no_const ops;
34956 struct ixgbe_mbx_stats stats;
34957 u32 timeout;
34958 u32 udelay;
34959 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
34960 index a0313de..e83a572 100644
34961 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
34962 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
34963 @@ -41,6 +41,7 @@
34964 #include <linux/slab.h>
34965 #include <linux/io-mapping.h>
34966 #include <linux/delay.h>
34967 +#include <linux/sched.h>
34968
34969 #include <linux/mlx4/device.h>
34970 #include <linux/mlx4/doorbell.h>
34971 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34972 index 5046a64..71ca936 100644
34973 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
34974 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34975 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
34976 void (*link_down)(struct __vxge_hw_device *devh);
34977 void (*crit_err)(struct __vxge_hw_device *devh,
34978 enum vxge_hw_event type, u64 ext_data);
34979 -};
34980 +} __no_const;
34981
34982 /*
34983 * struct __vxge_hw_blockpool_entry - Block private data structure
34984 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34985 index 4a518a3..936b334 100644
34986 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34987 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34988 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
34989 struct vxge_hw_mempool_dma *dma_object,
34990 u32 index,
34991 u32 is_last);
34992 -};
34993 +} __no_const;
34994
34995 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
34996 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
34997 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
34998 index eb81da4..1592b62 100644
34999 --- a/drivers/net/ethernet/realtek/r8169.c
35000 +++ b/drivers/net/ethernet/realtek/r8169.c
35001 @@ -723,22 +723,22 @@ struct rtl8169_private {
35002 struct mdio_ops {
35003 void (*write)(void __iomem *, int, int);
35004 int (*read)(void __iomem *, int);
35005 - } mdio_ops;
35006 + } __no_const mdio_ops;
35007
35008 struct pll_power_ops {
35009 void (*down)(struct rtl8169_private *);
35010 void (*up)(struct rtl8169_private *);
35011 - } pll_power_ops;
35012 + } __no_const pll_power_ops;
35013
35014 struct jumbo_ops {
35015 void (*enable)(struct rtl8169_private *);
35016 void (*disable)(struct rtl8169_private *);
35017 - } jumbo_ops;
35018 + } __no_const jumbo_ops;
35019
35020 struct csi_ops {
35021 void (*write)(void __iomem *, int, int);
35022 u32 (*read)(void __iomem *, int);
35023 - } csi_ops;
35024 + } __no_const csi_ops;
35025
35026 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35027 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35028 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35029 index 4613591..d816601 100644
35030 --- a/drivers/net/ethernet/sis/sis190.c
35031 +++ b/drivers/net/ethernet/sis/sis190.c
35032 @@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35033 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35034 struct net_device *dev)
35035 {
35036 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35037 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35038 struct sis190_private *tp = netdev_priv(dev);
35039 struct pci_dev *isa_bridge;
35040 u8 reg, tmp8;
35041 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35042 index c07cfe9..81cbf7e 100644
35043 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35044 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35045 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35046
35047 writel(value, ioaddr + MMC_CNTRL);
35048
35049 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35050 - MMC_CNTRL, value);
35051 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35052 +// MMC_CNTRL, value);
35053 }
35054
35055 /* To mask all all interrupts.*/
35056 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35057 index 2857ab0..9a1f9b0 100644
35058 --- a/drivers/net/hyperv/hyperv_net.h
35059 +++ b/drivers/net/hyperv/hyperv_net.h
35060 @@ -99,7 +99,7 @@ struct rndis_device {
35061
35062 enum rndis_device_state state;
35063 bool link_state;
35064 - atomic_t new_req_id;
35065 + atomic_unchecked_t new_req_id;
35066
35067 spinlock_t request_lock;
35068 struct list_head req_list;
35069 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35070 index 981ebb1..b34959b 100644
35071 --- a/drivers/net/hyperv/rndis_filter.c
35072 +++ b/drivers/net/hyperv/rndis_filter.c
35073 @@ -97,7 +97,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35074 * template
35075 */
35076 set = &rndis_msg->msg.set_req;
35077 - set->req_id = atomic_inc_return(&dev->new_req_id);
35078 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35079
35080 /* Add to the request list */
35081 spin_lock_irqsave(&dev->request_lock, flags);
35082 @@ -648,7 +648,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35083
35084 /* Setup the rndis set */
35085 halt = &request->request_msg.msg.halt_req;
35086 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35087 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35088
35089 /* Ignore return since this msg is optional. */
35090 rndis_filter_send_request(dev, request);
35091 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35092 index 5c05572..389610b 100644
35093 --- a/drivers/net/ppp/ppp_generic.c
35094 +++ b/drivers/net/ppp/ppp_generic.c
35095 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35096 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35097 struct ppp_stats stats;
35098 struct ppp_comp_stats cstats;
35099 - char *vers;
35100
35101 switch (cmd) {
35102 case SIOCGPPPSTATS:
35103 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35104 break;
35105
35106 case SIOCGPPPVER:
35107 - vers = PPP_VERSION;
35108 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35109 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35110 break;
35111 err = 0;
35112 break;
35113 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35114 index 62f30b4..ff99dfd 100644
35115 --- a/drivers/net/usb/hso.c
35116 +++ b/drivers/net/usb/hso.c
35117 @@ -71,7 +71,7 @@
35118 #include <asm/byteorder.h>
35119 #include <linux/serial_core.h>
35120 #include <linux/serial.h>
35121 -
35122 +#include <asm/local.h>
35123
35124 #define MOD_AUTHOR "Option Wireless"
35125 #define MOD_DESCRIPTION "USB High Speed Option driver"
35126 @@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35127 struct urb *urb;
35128
35129 urb = serial->rx_urb[0];
35130 - if (serial->port.count > 0) {
35131 + if (atomic_read(&serial->port.count) > 0) {
35132 count = put_rxbuf_data(urb, serial);
35133 if (count == -1)
35134 return;
35135 @@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35136 DUMP1(urb->transfer_buffer, urb->actual_length);
35137
35138 /* Anyone listening? */
35139 - if (serial->port.count == 0)
35140 + if (atomic_read(&serial->port.count) == 0)
35141 return;
35142
35143 if (status == 0) {
35144 @@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35145 tty_port_tty_set(&serial->port, tty);
35146
35147 /* check for port already opened, if not set the termios */
35148 - serial->port.count++;
35149 - if (serial->port.count == 1) {
35150 + if (atomic_inc_return(&serial->port.count) == 1) {
35151 serial->rx_state = RX_IDLE;
35152 /* Force default termio settings */
35153 _hso_serial_set_termios(tty, NULL);
35154 @@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35155 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35156 if (result) {
35157 hso_stop_serial_device(serial->parent);
35158 - serial->port.count--;
35159 + atomic_dec(&serial->port.count);
35160 kref_put(&serial->parent->ref, hso_serial_ref_free);
35161 }
35162 } else {
35163 @@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35164
35165 /* reset the rts and dtr */
35166 /* do the actual close */
35167 - serial->port.count--;
35168 + atomic_dec(&serial->port.count);
35169
35170 - if (serial->port.count <= 0) {
35171 - serial->port.count = 0;
35172 + if (atomic_read(&serial->port.count) <= 0) {
35173 + atomic_set(&serial->port.count, 0);
35174 tty_port_tty_set(&serial->port, NULL);
35175 if (!usb_gone)
35176 hso_stop_serial_device(serial->parent);
35177 @@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35178
35179 /* the actual setup */
35180 spin_lock_irqsave(&serial->serial_lock, flags);
35181 - if (serial->port.count)
35182 + if (atomic_read(&serial->port.count))
35183 _hso_serial_set_termios(tty, old);
35184 else
35185 tty->termios = old;
35186 @@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35187 D1("Pending read interrupt on port %d\n", i);
35188 spin_lock(&serial->serial_lock);
35189 if (serial->rx_state == RX_IDLE &&
35190 - serial->port.count > 0) {
35191 + atomic_read(&serial->port.count) > 0) {
35192 /* Setup and send a ctrl req read on
35193 * port i */
35194 if (!serial->rx_urb_filled[0]) {
35195 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35196 /* Start all serial ports */
35197 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35198 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35199 - if (dev2ser(serial_table[i])->port.count) {
35200 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35201 result =
35202 hso_start_serial_device(serial_table[i], GFP_NOIO);
35203 hso_kick_transmit(dev2ser(serial_table[i]));
35204 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35205 index 420d69b..74f90a2 100644
35206 --- a/drivers/net/wireless/ath/ath.h
35207 +++ b/drivers/net/wireless/ath/ath.h
35208 @@ -119,6 +119,7 @@ struct ath_ops {
35209 void (*write_flush) (void *);
35210 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35211 };
35212 +typedef struct ath_ops __no_const ath_ops_no_const;
35213
35214 struct ath_common;
35215 struct ath_bus_ops;
35216 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35217 index 8d78253..bebbb68 100644
35218 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35219 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35220 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35221 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35222 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35223
35224 - ACCESS_ONCE(ads->ds_link) = i->link;
35225 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35226 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35227 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35228
35229 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35230 ctl6 = SM(i->keytype, AR_EncrType);
35231 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35232
35233 if ((i->is_first || i->is_last) &&
35234 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35235 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35236 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35237 | set11nTries(i->rates, 1)
35238 | set11nTries(i->rates, 2)
35239 | set11nTries(i->rates, 3)
35240 | (i->dur_update ? AR_DurUpdateEna : 0)
35241 | SM(0, AR_BurstDur);
35242
35243 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35244 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35245 | set11nRate(i->rates, 1)
35246 | set11nRate(i->rates, 2)
35247 | set11nRate(i->rates, 3);
35248 } else {
35249 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35250 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35251 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35252 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35253 }
35254
35255 if (!i->is_first) {
35256 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35257 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35258 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35259 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35260 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35261 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35262 return;
35263 }
35264
35265 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35266 break;
35267 }
35268
35269 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35270 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35271 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35272 | SM(i->txpower, AR_XmitPower)
35273 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35274 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35275 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35276 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35277
35278 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35279 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35280 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35281 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35282
35283 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35284 return;
35285
35286 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35287 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35288 | set11nPktDurRTSCTS(i->rates, 1);
35289
35290 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35291 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35292 | set11nPktDurRTSCTS(i->rates, 3);
35293
35294 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35295 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35296 | set11nRateFlags(i->rates, 1)
35297 | set11nRateFlags(i->rates, 2)
35298 | set11nRateFlags(i->rates, 3)
35299 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35300 index d9e0824..1a874e7 100644
35301 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35302 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35303 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35304 (i->qcu << AR_TxQcuNum_S) | desc_len;
35305
35306 checksum += val;
35307 - ACCESS_ONCE(ads->info) = val;
35308 + ACCESS_ONCE_RW(ads->info) = val;
35309
35310 checksum += i->link;
35311 - ACCESS_ONCE(ads->link) = i->link;
35312 + ACCESS_ONCE_RW(ads->link) = i->link;
35313
35314 checksum += i->buf_addr[0];
35315 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35316 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35317 checksum += i->buf_addr[1];
35318 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35319 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35320 checksum += i->buf_addr[2];
35321 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35322 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35323 checksum += i->buf_addr[3];
35324 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35325 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35326
35327 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35328 - ACCESS_ONCE(ads->ctl3) = val;
35329 + ACCESS_ONCE_RW(ads->ctl3) = val;
35330 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35331 - ACCESS_ONCE(ads->ctl5) = val;
35332 + ACCESS_ONCE_RW(ads->ctl5) = val;
35333 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35334 - ACCESS_ONCE(ads->ctl7) = val;
35335 + ACCESS_ONCE_RW(ads->ctl7) = val;
35336 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35337 - ACCESS_ONCE(ads->ctl9) = val;
35338 + ACCESS_ONCE_RW(ads->ctl9) = val;
35339
35340 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35341 - ACCESS_ONCE(ads->ctl10) = checksum;
35342 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35343
35344 if (i->is_first || i->is_last) {
35345 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35346 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35347 | set11nTries(i->rates, 1)
35348 | set11nTries(i->rates, 2)
35349 | set11nTries(i->rates, 3)
35350 | (i->dur_update ? AR_DurUpdateEna : 0)
35351 | SM(0, AR_BurstDur);
35352
35353 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35354 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35355 | set11nRate(i->rates, 1)
35356 | set11nRate(i->rates, 2)
35357 | set11nRate(i->rates, 3);
35358 } else {
35359 - ACCESS_ONCE(ads->ctl13) = 0;
35360 - ACCESS_ONCE(ads->ctl14) = 0;
35361 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35362 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35363 }
35364
35365 ads->ctl20 = 0;
35366 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35367
35368 ctl17 = SM(i->keytype, AR_EncrType);
35369 if (!i->is_first) {
35370 - ACCESS_ONCE(ads->ctl11) = 0;
35371 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35372 - ACCESS_ONCE(ads->ctl15) = 0;
35373 - ACCESS_ONCE(ads->ctl16) = 0;
35374 - ACCESS_ONCE(ads->ctl17) = ctl17;
35375 - ACCESS_ONCE(ads->ctl18) = 0;
35376 - ACCESS_ONCE(ads->ctl19) = 0;
35377 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35378 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35379 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35380 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35381 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35382 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35383 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35384 return;
35385 }
35386
35387 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35388 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35389 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35390 | SM(i->txpower, AR_XmitPower)
35391 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35392 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35393 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35394 ctl12 |= SM(val, AR_PAPRDChainMask);
35395
35396 - ACCESS_ONCE(ads->ctl12) = ctl12;
35397 - ACCESS_ONCE(ads->ctl17) = ctl17;
35398 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35399 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35400
35401 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35402 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35403 | set11nPktDurRTSCTS(i->rates, 1);
35404
35405 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35406 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35407 | set11nPktDurRTSCTS(i->rates, 3);
35408
35409 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35410 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35411 | set11nRateFlags(i->rates, 1)
35412 | set11nRateFlags(i->rates, 2)
35413 | set11nRateFlags(i->rates, 3)
35414 | SM(i->rtscts_rate, AR_RTSCTSRate);
35415
35416 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35417 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35418 }
35419
35420 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35421 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35422 index b620c55..a76cd49 100644
35423 --- a/drivers/net/wireless/ath/ath9k/hw.h
35424 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35425 @@ -609,7 +609,7 @@ struct ath_hw_private_ops {
35426
35427 /* ANI */
35428 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35429 -};
35430 +} __no_const;
35431
35432 /**
35433 * struct ath_hw_ops - callbacks used by hardware code and driver code
35434 @@ -639,7 +639,7 @@ struct ath_hw_ops {
35435 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35436 struct ath_hw_antcomb_conf *antconf);
35437
35438 -};
35439 +} __no_const;
35440
35441 struct ath_nf_limits {
35442 s16 max;
35443 @@ -659,7 +659,7 @@ enum ath_cal_list {
35444 #define AH_FASTCC 0x4
35445
35446 struct ath_hw {
35447 - struct ath_ops reg_ops;
35448 + ath_ops_no_const reg_ops;
35449
35450 struct ieee80211_hw *hw;
35451 struct ath_common common;
35452 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35453 index af00e2c..ab04d34 100644
35454 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35455 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35456 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35457 void (*carrsuppr)(struct brcms_phy *);
35458 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35459 void (*detach)(struct brcms_phy *);
35460 -};
35461 +} __no_const;
35462
35463 struct brcms_phy {
35464 struct brcms_phy_pub pubpi_ro;
35465 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35466 index faec404..a5277f1 100644
35467 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35468 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35469 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35470 */
35471 if (il3945_mod_params.disable_hw_scan) {
35472 D_INFO("Disabling hw_scan\n");
35473 - il3945_mac_ops.hw_scan = NULL;
35474 + pax_open_kernel();
35475 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35476 + pax_close_kernel();
35477 }
35478
35479 D_INFO("*** LOAD DRIVER ***\n");
35480 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35481 index a0b7cfd..20b49f7 100644
35482 --- a/drivers/net/wireless/mac80211_hwsim.c
35483 +++ b/drivers/net/wireless/mac80211_hwsim.c
35484 @@ -1752,9 +1752,11 @@ static int __init init_mac80211_hwsim(void)
35485 return -EINVAL;
35486
35487 if (fake_hw_scan) {
35488 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35489 - mac80211_hwsim_ops.sw_scan_start = NULL;
35490 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35491 + pax_open_kernel();
35492 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35493 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35494 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35495 + pax_close_kernel();
35496 }
35497
35498 spin_lock_init(&hwsim_radio_lock);
35499 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35500 index bd3b0bf..f9db92a 100644
35501 --- a/drivers/net/wireless/mwifiex/main.h
35502 +++ b/drivers/net/wireless/mwifiex/main.h
35503 @@ -567,7 +567,7 @@ struct mwifiex_if_ops {
35504 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35505 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35506 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35507 -};
35508 +} __no_const;
35509
35510 struct mwifiex_adapter {
35511 u8 iface_type;
35512 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35513 index dfcd02a..a42a59d 100644
35514 --- a/drivers/net/wireless/rndis_wlan.c
35515 +++ b/drivers/net/wireless/rndis_wlan.c
35516 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35517
35518 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35519
35520 - if (rts_threshold < 0 || rts_threshold > 2347)
35521 + if (rts_threshold > 2347)
35522 rts_threshold = 2347;
35523
35524 tmp = cpu_to_le32(rts_threshold);
35525 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35526 index 8f75402..eed109d 100644
35527 --- a/drivers/net/wireless/rt2x00/rt2x00.h
35528 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
35529 @@ -396,7 +396,7 @@ struct rt2x00_intf {
35530 * for hardware which doesn't support hardware
35531 * sequence counting.
35532 */
35533 - atomic_t seqno;
35534 + atomic_unchecked_t seqno;
35535 };
35536
35537 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35538 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35539 index 2fd8301..9767e8c 100644
35540 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35541 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35542 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35543 * sequence counter given by mac80211.
35544 */
35545 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35546 - seqno = atomic_add_return(0x10, &intf->seqno);
35547 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35548 else
35549 - seqno = atomic_read(&intf->seqno);
35550 + seqno = atomic_read_unchecked(&intf->seqno);
35551
35552 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35553 hdr->seq_ctrl |= cpu_to_le16(seqno);
35554 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
35555 index 9d8f581..0f6589e 100644
35556 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
35557 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
35558 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35559 void (*reset)(struct wl1251 *wl);
35560 void (*enable_irq)(struct wl1251 *wl);
35561 void (*disable_irq)(struct wl1251 *wl);
35562 -};
35563 +} __no_const;
35564
35565 struct wl1251 {
35566 struct ieee80211_hw *hw;
35567 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
35568 index 0b3f0b5..62f68bd 100644
35569 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
35570 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
35571 @@ -61,7 +61,7 @@ struct wlcore_ops {
35572 struct wl12xx_vif *wlvif);
35573 s8 (*get_pg_ver)(struct wl1271 *wl);
35574 void (*get_mac)(struct wl1271 *wl);
35575 -};
35576 +} __no_const;
35577
35578 enum wlcore_partitions {
35579 PART_DOWN,
35580 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35581 index f34b5b2..b5abb9f 100644
35582 --- a/drivers/oprofile/buffer_sync.c
35583 +++ b/drivers/oprofile/buffer_sync.c
35584 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35585 if (cookie == NO_COOKIE)
35586 offset = pc;
35587 if (cookie == INVALID_COOKIE) {
35588 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35589 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35590 offset = pc;
35591 }
35592 if (cookie != last_cookie) {
35593 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35594 /* add userspace sample */
35595
35596 if (!mm) {
35597 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35598 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35599 return 0;
35600 }
35601
35602 cookie = lookup_dcookie(mm, s->eip, &offset);
35603
35604 if (cookie == INVALID_COOKIE) {
35605 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35606 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35607 return 0;
35608 }
35609
35610 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35611 /* ignore backtraces if failed to add a sample */
35612 if (state == sb_bt_start) {
35613 state = sb_bt_ignore;
35614 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35615 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35616 }
35617 }
35618 release_mm(mm);
35619 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35620 index c0cc4e7..44d4e54 100644
35621 --- a/drivers/oprofile/event_buffer.c
35622 +++ b/drivers/oprofile/event_buffer.c
35623 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35624 }
35625
35626 if (buffer_pos == buffer_size) {
35627 - atomic_inc(&oprofile_stats.event_lost_overflow);
35628 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35629 return;
35630 }
35631
35632 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35633 index ed2c3ec..deda85a 100644
35634 --- a/drivers/oprofile/oprof.c
35635 +++ b/drivers/oprofile/oprof.c
35636 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35637 if (oprofile_ops.switch_events())
35638 return;
35639
35640 - atomic_inc(&oprofile_stats.multiplex_counter);
35641 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35642 start_switch_worker();
35643 }
35644
35645 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35646 index 917d28e..d62d981 100644
35647 --- a/drivers/oprofile/oprofile_stats.c
35648 +++ b/drivers/oprofile/oprofile_stats.c
35649 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35650 cpu_buf->sample_invalid_eip = 0;
35651 }
35652
35653 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35654 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35655 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
35656 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35657 - atomic_set(&oprofile_stats.multiplex_counter, 0);
35658 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35659 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35660 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35661 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35662 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35663 }
35664
35665
35666 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35667 index 38b6fc0..b5cbfce 100644
35668 --- a/drivers/oprofile/oprofile_stats.h
35669 +++ b/drivers/oprofile/oprofile_stats.h
35670 @@ -13,11 +13,11 @@
35671 #include <linux/atomic.h>
35672
35673 struct oprofile_stat_struct {
35674 - atomic_t sample_lost_no_mm;
35675 - atomic_t sample_lost_no_mapping;
35676 - atomic_t bt_lost_no_mapping;
35677 - atomic_t event_lost_overflow;
35678 - atomic_t multiplex_counter;
35679 + atomic_unchecked_t sample_lost_no_mm;
35680 + atomic_unchecked_t sample_lost_no_mapping;
35681 + atomic_unchecked_t bt_lost_no_mapping;
35682 + atomic_unchecked_t event_lost_overflow;
35683 + atomic_unchecked_t multiplex_counter;
35684 };
35685
35686 extern struct oprofile_stat_struct oprofile_stats;
35687 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35688 index 849357c..b83c1e0 100644
35689 --- a/drivers/oprofile/oprofilefs.c
35690 +++ b/drivers/oprofile/oprofilefs.c
35691 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
35692
35693
35694 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35695 - char const *name, atomic_t *val)
35696 + char const *name, atomic_unchecked_t *val)
35697 {
35698 return __oprofilefs_create_file(sb, root, name,
35699 &atomic_ro_fops, 0444, val);
35700 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35701 index 3f56bc0..707d642 100644
35702 --- a/drivers/parport/procfs.c
35703 +++ b/drivers/parport/procfs.c
35704 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35705
35706 *ppos += len;
35707
35708 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35709 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35710 }
35711
35712 #ifdef CONFIG_PARPORT_1284
35713 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35714
35715 *ppos += len;
35716
35717 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35718 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35719 }
35720 #endif /* IEEE1284.3 support. */
35721
35722 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35723 index 9fff878..ad0ad53 100644
35724 --- a/drivers/pci/hotplug/cpci_hotplug.h
35725 +++ b/drivers/pci/hotplug/cpci_hotplug.h
35726 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35727 int (*hardware_test) (struct slot* slot, u32 value);
35728 u8 (*get_power) (struct slot* slot);
35729 int (*set_power) (struct slot* slot, int value);
35730 -};
35731 +} __no_const;
35732
35733 struct cpci_hp_controller {
35734 unsigned int irq;
35735 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35736 index 76ba8a1..20ca857 100644
35737 --- a/drivers/pci/hotplug/cpqphp_nvram.c
35738 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
35739 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35740
35741 void compaq_nvram_init (void __iomem *rom_start)
35742 {
35743 +
35744 +#ifndef CONFIG_PAX_KERNEXEC
35745 if (rom_start) {
35746 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35747 }
35748 +#endif
35749 +
35750 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35751
35752 /* initialize our int15 lock */
35753 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35754 index b500840..d7159d3 100644
35755 --- a/drivers/pci/pcie/aspm.c
35756 +++ b/drivers/pci/pcie/aspm.c
35757 @@ -27,9 +27,9 @@
35758 #define MODULE_PARAM_PREFIX "pcie_aspm."
35759
35760 /* Note: those are not register definitions */
35761 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35762 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35763 -#define ASPM_STATE_L1 (4) /* L1 state */
35764 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35765 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35766 +#define ASPM_STATE_L1 (4U) /* L1 state */
35767 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35768 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35769
35770 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35771 index 658ac97..05e1b90 100644
35772 --- a/drivers/pci/probe.c
35773 +++ b/drivers/pci/probe.c
35774 @@ -137,7 +137,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35775 u16 orig_cmd;
35776 struct pci_bus_region region;
35777
35778 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35779 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35780
35781 if (!dev->mmio_always_on) {
35782 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35783 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35784 index 27911b5..5b6db88 100644
35785 --- a/drivers/pci/proc.c
35786 +++ b/drivers/pci/proc.c
35787 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35788 static int __init pci_proc_init(void)
35789 {
35790 struct pci_dev *dev = NULL;
35791 +
35792 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
35793 +#ifdef CONFIG_GRKERNSEC_PROC_USER
35794 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35795 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35796 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35797 +#endif
35798 +#else
35799 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35800 +#endif
35801 proc_create("devices", 0, proc_bus_pci_dir,
35802 &proc_bus_pci_dev_operations);
35803 proc_initialized = 1;
35804 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35805 index 8b5610d..a4c22bb 100644
35806 --- a/drivers/platform/x86/thinkpad_acpi.c
35807 +++ b/drivers/platform/x86/thinkpad_acpi.c
35808 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35809 return 0;
35810 }
35811
35812 -void static hotkey_mask_warn_incomplete_mask(void)
35813 +static void hotkey_mask_warn_incomplete_mask(void)
35814 {
35815 /* log only what the user can fix... */
35816 const u32 wantedmask = hotkey_driver_mask &
35817 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35818 }
35819 }
35820
35821 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35822 - struct tp_nvram_state *newn,
35823 - const u32 event_mask)
35824 -{
35825 -
35826 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35827 do { \
35828 if ((event_mask & (1 << __scancode)) && \
35829 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35830 tpacpi_hotkey_send_key(__scancode); \
35831 } while (0)
35832
35833 - void issue_volchange(const unsigned int oldvol,
35834 - const unsigned int newvol)
35835 - {
35836 - unsigned int i = oldvol;
35837 +static void issue_volchange(const unsigned int oldvol,
35838 + const unsigned int newvol,
35839 + const u32 event_mask)
35840 +{
35841 + unsigned int i = oldvol;
35842
35843 - while (i > newvol) {
35844 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35845 - i--;
35846 - }
35847 - while (i < newvol) {
35848 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35849 - i++;
35850 - }
35851 + while (i > newvol) {
35852 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35853 + i--;
35854 }
35855 + while (i < newvol) {
35856 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35857 + i++;
35858 + }
35859 +}
35860
35861 - void issue_brightnesschange(const unsigned int oldbrt,
35862 - const unsigned int newbrt)
35863 - {
35864 - unsigned int i = oldbrt;
35865 +static void issue_brightnesschange(const unsigned int oldbrt,
35866 + const unsigned int newbrt,
35867 + const u32 event_mask)
35868 +{
35869 + unsigned int i = oldbrt;
35870
35871 - while (i > newbrt) {
35872 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35873 - i--;
35874 - }
35875 - while (i < newbrt) {
35876 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35877 - i++;
35878 - }
35879 + while (i > newbrt) {
35880 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35881 + i--;
35882 + }
35883 + while (i < newbrt) {
35884 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35885 + i++;
35886 }
35887 +}
35888
35889 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35890 + struct tp_nvram_state *newn,
35891 + const u32 event_mask)
35892 +{
35893 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35894 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35895 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35896 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35897 oldn->volume_level != newn->volume_level) {
35898 /* recently muted, or repeated mute keypress, or
35899 * multiple presses ending in mute */
35900 - issue_volchange(oldn->volume_level, newn->volume_level);
35901 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35902 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
35903 }
35904 } else {
35905 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35906 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35907 }
35908 if (oldn->volume_level != newn->volume_level) {
35909 - issue_volchange(oldn->volume_level, newn->volume_level);
35910 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35911 } else if (oldn->volume_toggle != newn->volume_toggle) {
35912 /* repeated vol up/down keypress at end of scale ? */
35913 if (newn->volume_level == 0)
35914 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35915 /* handle brightness */
35916 if (oldn->brightness_level != newn->brightness_level) {
35917 issue_brightnesschange(oldn->brightness_level,
35918 - newn->brightness_level);
35919 + newn->brightness_level,
35920 + event_mask);
35921 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
35922 /* repeated key presses that didn't change state */
35923 if (newn->brightness_level == 0)
35924 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35925 && !tp_features.bright_unkfw)
35926 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35927 }
35928 +}
35929
35930 #undef TPACPI_COMPARE_KEY
35931 #undef TPACPI_MAY_SEND_KEY
35932 -}
35933
35934 /*
35935 * Polling driver
35936 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
35937 index 769d265..a3a05ca 100644
35938 --- a/drivers/pnp/pnpbios/bioscalls.c
35939 +++ b/drivers/pnp/pnpbios/bioscalls.c
35940 @@ -58,7 +58,7 @@ do { \
35941 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
35942 } while(0)
35943
35944 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
35945 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
35946 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
35947
35948 /*
35949 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35950
35951 cpu = get_cpu();
35952 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
35953 +
35954 + pax_open_kernel();
35955 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
35956 + pax_close_kernel();
35957
35958 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
35959 spin_lock_irqsave(&pnp_bios_lock, flags);
35960 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35961 :"memory");
35962 spin_unlock_irqrestore(&pnp_bios_lock, flags);
35963
35964 + pax_open_kernel();
35965 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
35966 + pax_close_kernel();
35967 +
35968 put_cpu();
35969
35970 /* If we get here and this is set then the PnP BIOS faulted on us. */
35971 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
35972 return status;
35973 }
35974
35975 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
35976 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
35977 {
35978 int i;
35979
35980 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35981 pnp_bios_callpoint.offset = header->fields.pm16offset;
35982 pnp_bios_callpoint.segment = PNP_CS16;
35983
35984 + pax_open_kernel();
35985 +
35986 for_each_possible_cpu(i) {
35987 struct desc_struct *gdt = get_cpu_gdt_table(i);
35988 if (!gdt)
35989 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35990 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
35991 (unsigned long)__va(header->fields.pm16dseg));
35992 }
35993 +
35994 + pax_close_kernel();
35995 }
35996 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
35997 index b0ecacb..7c9da2e 100644
35998 --- a/drivers/pnp/resource.c
35999 +++ b/drivers/pnp/resource.c
36000 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36001 return 1;
36002
36003 /* check if the resource is valid */
36004 - if (*irq < 0 || *irq > 15)
36005 + if (*irq > 15)
36006 return 0;
36007
36008 /* check if the resource is reserved */
36009 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36010 return 1;
36011
36012 /* check if the resource is valid */
36013 - if (*dma < 0 || *dma == 4 || *dma > 7)
36014 + if (*dma == 4 || *dma > 7)
36015 return 0;
36016
36017 /* check if the resource is reserved */
36018 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36019 index f5d6d37..739f6a9 100644
36020 --- a/drivers/power/bq27x00_battery.c
36021 +++ b/drivers/power/bq27x00_battery.c
36022 @@ -72,7 +72,7 @@
36023 struct bq27x00_device_info;
36024 struct bq27x00_access_methods {
36025 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36026 -};
36027 +} __no_const;
36028
36029 enum bq27x00_chip { BQ27000, BQ27500 };
36030
36031 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36032 index 8d53174..04c65de 100644
36033 --- a/drivers/regulator/max8660.c
36034 +++ b/drivers/regulator/max8660.c
36035 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36036 max8660->shadow_regs[MAX8660_OVER1] = 5;
36037 } else {
36038 /* Otherwise devices can be toggled via software */
36039 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36040 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36041 + pax_open_kernel();
36042 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36043 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36044 + pax_close_kernel();
36045 }
36046
36047 /*
36048 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36049 index 970a233..ee1f241 100644
36050 --- a/drivers/regulator/mc13892-regulator.c
36051 +++ b/drivers/regulator/mc13892-regulator.c
36052 @@ -566,10 +566,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36053 }
36054 mc13xxx_unlock(mc13892);
36055
36056 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36057 + pax_open_kernel();
36058 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36059 = mc13892_vcam_set_mode;
36060 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36061 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36062 = mc13892_vcam_get_mode;
36063 + pax_close_kernel();
36064
36065 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36066 ARRAY_SIZE(mc13892_regulators));
36067 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36068 index cace6d3..f623fda 100644
36069 --- a/drivers/rtc/rtc-dev.c
36070 +++ b/drivers/rtc/rtc-dev.c
36071 @@ -14,6 +14,7 @@
36072 #include <linux/module.h>
36073 #include <linux/rtc.h>
36074 #include <linux/sched.h>
36075 +#include <linux/grsecurity.h>
36076 #include "rtc-core.h"
36077
36078 static dev_t rtc_devt;
36079 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36080 if (copy_from_user(&tm, uarg, sizeof(tm)))
36081 return -EFAULT;
36082
36083 + gr_log_timechange();
36084 +
36085 return rtc_set_time(rtc, &tm);
36086
36087 case RTC_PIE_ON:
36088 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36089 index 3fcf627..f334910 100644
36090 --- a/drivers/scsi/aacraid/aacraid.h
36091 +++ b/drivers/scsi/aacraid/aacraid.h
36092 @@ -492,7 +492,7 @@ struct adapter_ops
36093 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36094 /* Administrative operations */
36095 int (*adapter_comm)(struct aac_dev * dev, int comm);
36096 -};
36097 +} __no_const;
36098
36099 /*
36100 * Define which interrupt handler needs to be installed
36101 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36102 index 0d279c44..3d25a97 100644
36103 --- a/drivers/scsi/aacraid/linit.c
36104 +++ b/drivers/scsi/aacraid/linit.c
36105 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36106 #elif defined(__devinitconst)
36107 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36108 #else
36109 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36110 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36111 #endif
36112 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36113 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36114 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36115 index ff80552..1c4120c 100644
36116 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36117 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36118 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36119 .lldd_ata_set_dmamode = asd_set_dmamode,
36120 };
36121
36122 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36123 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36124 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36125 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36126 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36127 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36128 index 4ad7e36..d004679 100644
36129 --- a/drivers/scsi/bfa/bfa.h
36130 +++ b/drivers/scsi/bfa/bfa.h
36131 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36132 u32 *end);
36133 int cpe_vec_q0;
36134 int rme_vec_q0;
36135 -};
36136 +} __no_const;
36137 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36138
36139 struct bfa_faa_cbfn_s {
36140 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36141 index f0f80e2..8ec946b 100644
36142 --- a/drivers/scsi/bfa/bfa_fcpim.c
36143 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36144 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36145
36146 bfa_iotag_attach(fcp);
36147
36148 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36149 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36150 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36151 (fcp->num_itns * sizeof(struct bfa_itn_s));
36152 memset(fcp->itn_arr, 0,
36153 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36154 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36155 {
36156 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36157 - struct bfa_itn_s *itn;
36158 + bfa_itn_s_no_const *itn;
36159
36160 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36161 itn->isr = isr;
36162 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36163 index 36f26da..38a34a8 100644
36164 --- a/drivers/scsi/bfa/bfa_fcpim.h
36165 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36166 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36167 struct bfa_itn_s {
36168 bfa_isr_func_t isr;
36169 };
36170 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36171
36172 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36173 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36174 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36175 struct list_head iotag_tio_free_q; /* free IO resources */
36176 struct list_head iotag_unused_q; /* unused IO resources*/
36177 struct bfa_iotag_s *iotag_arr;
36178 - struct bfa_itn_s *itn_arr;
36179 + bfa_itn_s_no_const *itn_arr;
36180 int num_ioim_reqs;
36181 int num_fwtio_reqs;
36182 int num_itns;
36183 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36184 index 1a99d4b..e85d64b 100644
36185 --- a/drivers/scsi/bfa/bfa_ioc.h
36186 +++ b/drivers/scsi/bfa/bfa_ioc.h
36187 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36188 bfa_ioc_disable_cbfn_t disable_cbfn;
36189 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36190 bfa_ioc_reset_cbfn_t reset_cbfn;
36191 -};
36192 +} __no_const;
36193
36194 /*
36195 * IOC event notification mechanism.
36196 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36197 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36198 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36199 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36200 -};
36201 +} __no_const;
36202
36203 /*
36204 * Queue element to wait for room in request queue. FIFO order is
36205 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36206 index b48c24f..dac0fbc 100644
36207 --- a/drivers/scsi/hosts.c
36208 +++ b/drivers/scsi/hosts.c
36209 @@ -42,7 +42,7 @@
36210 #include "scsi_logging.h"
36211
36212
36213 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
36214 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36215
36216
36217 static void scsi_host_cls_release(struct device *dev)
36218 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36219 * subtract one because we increment first then return, but we need to
36220 * know what the next host number was before increment
36221 */
36222 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36223 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36224 shost->dma_channel = 0xff;
36225
36226 /* These three are default values which can be overridden */
36227 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36228 index 796482b..d08435c 100644
36229 --- a/drivers/scsi/hpsa.c
36230 +++ b/drivers/scsi/hpsa.c
36231 @@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36232 unsigned long flags;
36233
36234 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36235 - return h->access.command_completed(h, q);
36236 + return h->access->command_completed(h, q);
36237
36238 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36239 a = rq->head[rq->current_entry];
36240 @@ -3354,7 +3354,7 @@ static void start_io(struct ctlr_info *h)
36241 while (!list_empty(&h->reqQ)) {
36242 c = list_entry(h->reqQ.next, struct CommandList, list);
36243 /* can't do anything if fifo is full */
36244 - if ((h->access.fifo_full(h))) {
36245 + if ((h->access->fifo_full(h))) {
36246 dev_warn(&h->pdev->dev, "fifo full\n");
36247 break;
36248 }
36249 @@ -3376,7 +3376,7 @@ static void start_io(struct ctlr_info *h)
36250
36251 /* Tell the controller execute command */
36252 spin_unlock_irqrestore(&h->lock, flags);
36253 - h->access.submit_command(h, c);
36254 + h->access->submit_command(h, c);
36255 spin_lock_irqsave(&h->lock, flags);
36256 }
36257 spin_unlock_irqrestore(&h->lock, flags);
36258 @@ -3384,17 +3384,17 @@ static void start_io(struct ctlr_info *h)
36259
36260 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36261 {
36262 - return h->access.command_completed(h, q);
36263 + return h->access->command_completed(h, q);
36264 }
36265
36266 static inline bool interrupt_pending(struct ctlr_info *h)
36267 {
36268 - return h->access.intr_pending(h);
36269 + return h->access->intr_pending(h);
36270 }
36271
36272 static inline long interrupt_not_for_us(struct ctlr_info *h)
36273 {
36274 - return (h->access.intr_pending(h) == 0) ||
36275 + return (h->access->intr_pending(h) == 0) ||
36276 (h->interrupts_enabled == 0);
36277 }
36278
36279 @@ -4298,7 +4298,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36280 if (prod_index < 0)
36281 return -ENODEV;
36282 h->product_name = products[prod_index].product_name;
36283 - h->access = *(products[prod_index].access);
36284 + h->access = products[prod_index].access;
36285
36286 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36287 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36288 @@ -4580,7 +4580,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36289
36290 assert_spin_locked(&lockup_detector_lock);
36291 remove_ctlr_from_lockup_detector_list(h);
36292 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36293 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36294 spin_lock_irqsave(&h->lock, flags);
36295 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36296 spin_unlock_irqrestore(&h->lock, flags);
36297 @@ -4758,7 +4758,7 @@ reinit_after_soft_reset:
36298 }
36299
36300 /* make sure the board interrupts are off */
36301 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36302 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36303
36304 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36305 goto clean2;
36306 @@ -4792,7 +4792,7 @@ reinit_after_soft_reset:
36307 * fake ones to scoop up any residual completions.
36308 */
36309 spin_lock_irqsave(&h->lock, flags);
36310 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36311 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36312 spin_unlock_irqrestore(&h->lock, flags);
36313 free_irqs(h);
36314 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36315 @@ -4811,9 +4811,9 @@ reinit_after_soft_reset:
36316 dev_info(&h->pdev->dev, "Board READY.\n");
36317 dev_info(&h->pdev->dev,
36318 "Waiting for stale completions to drain.\n");
36319 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36320 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36321 msleep(10000);
36322 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36323 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36324
36325 rc = controller_reset_failed(h->cfgtable);
36326 if (rc)
36327 @@ -4834,7 +4834,7 @@ reinit_after_soft_reset:
36328 }
36329
36330 /* Turn the interrupts on so we can service requests */
36331 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36332 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36333
36334 hpsa_hba_inquiry(h);
36335 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36336 @@ -4886,7 +4886,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36337 * To write all data in the battery backed cache to disks
36338 */
36339 hpsa_flush_cache(h);
36340 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36341 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36342 hpsa_free_irqs_and_disable_msix(h);
36343 }
36344
36345 @@ -5055,7 +5055,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36346 return;
36347 }
36348 /* Change the access methods to the performant access methods */
36349 - h->access = SA5_performant_access;
36350 + h->access = &SA5_performant_access;
36351 h->transMethod = CFGTBL_Trans_Performant;
36352 }
36353
36354 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36355 index 9816479..c5d4e97 100644
36356 --- a/drivers/scsi/hpsa.h
36357 +++ b/drivers/scsi/hpsa.h
36358 @@ -79,7 +79,7 @@ struct ctlr_info {
36359 unsigned int msix_vector;
36360 unsigned int msi_vector;
36361 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36362 - struct access_method access;
36363 + struct access_method *access;
36364
36365 /* queue and queue Info */
36366 struct list_head reqQ;
36367 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36368 index f2df059..a3a9930 100644
36369 --- a/drivers/scsi/ips.h
36370 +++ b/drivers/scsi/ips.h
36371 @@ -1027,7 +1027,7 @@ typedef struct {
36372 int (*intr)(struct ips_ha *);
36373 void (*enableint)(struct ips_ha *);
36374 uint32_t (*statupd)(struct ips_ha *);
36375 -} ips_hw_func_t;
36376 +} __no_const ips_hw_func_t;
36377
36378 typedef struct ips_ha {
36379 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36380 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36381 index aceffad..c35c08d 100644
36382 --- a/drivers/scsi/libfc/fc_exch.c
36383 +++ b/drivers/scsi/libfc/fc_exch.c
36384 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
36385 * all together if not used XXX
36386 */
36387 struct {
36388 - atomic_t no_free_exch;
36389 - atomic_t no_free_exch_xid;
36390 - atomic_t xid_not_found;
36391 - atomic_t xid_busy;
36392 - atomic_t seq_not_found;
36393 - atomic_t non_bls_resp;
36394 + atomic_unchecked_t no_free_exch;
36395 + atomic_unchecked_t no_free_exch_xid;
36396 + atomic_unchecked_t xid_not_found;
36397 + atomic_unchecked_t xid_busy;
36398 + atomic_unchecked_t seq_not_found;
36399 + atomic_unchecked_t non_bls_resp;
36400 } stats;
36401 };
36402
36403 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36404 /* allocate memory for exchange */
36405 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36406 if (!ep) {
36407 - atomic_inc(&mp->stats.no_free_exch);
36408 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36409 goto out;
36410 }
36411 memset(ep, 0, sizeof(*ep));
36412 @@ -780,7 +780,7 @@ out:
36413 return ep;
36414 err:
36415 spin_unlock_bh(&pool->lock);
36416 - atomic_inc(&mp->stats.no_free_exch_xid);
36417 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36418 mempool_free(ep, mp->ep_pool);
36419 return NULL;
36420 }
36421 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36422 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36423 ep = fc_exch_find(mp, xid);
36424 if (!ep) {
36425 - atomic_inc(&mp->stats.xid_not_found);
36426 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36427 reject = FC_RJT_OX_ID;
36428 goto out;
36429 }
36430 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36431 ep = fc_exch_find(mp, xid);
36432 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36433 if (ep) {
36434 - atomic_inc(&mp->stats.xid_busy);
36435 + atomic_inc_unchecked(&mp->stats.xid_busy);
36436 reject = FC_RJT_RX_ID;
36437 goto rel;
36438 }
36439 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36440 }
36441 xid = ep->xid; /* get our XID */
36442 } else if (!ep) {
36443 - atomic_inc(&mp->stats.xid_not_found);
36444 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36445 reject = FC_RJT_RX_ID; /* XID not found */
36446 goto out;
36447 }
36448 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36449 } else {
36450 sp = &ep->seq;
36451 if (sp->id != fh->fh_seq_id) {
36452 - atomic_inc(&mp->stats.seq_not_found);
36453 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36454 if (f_ctl & FC_FC_END_SEQ) {
36455 /*
36456 * Update sequence_id based on incoming last
36457 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36458
36459 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36460 if (!ep) {
36461 - atomic_inc(&mp->stats.xid_not_found);
36462 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36463 goto out;
36464 }
36465 if (ep->esb_stat & ESB_ST_COMPLETE) {
36466 - atomic_inc(&mp->stats.xid_not_found);
36467 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36468 goto rel;
36469 }
36470 if (ep->rxid == FC_XID_UNKNOWN)
36471 ep->rxid = ntohs(fh->fh_rx_id);
36472 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36473 - atomic_inc(&mp->stats.xid_not_found);
36474 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36475 goto rel;
36476 }
36477 if (ep->did != ntoh24(fh->fh_s_id) &&
36478 ep->did != FC_FID_FLOGI) {
36479 - atomic_inc(&mp->stats.xid_not_found);
36480 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36481 goto rel;
36482 }
36483 sof = fr_sof(fp);
36484 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36485 sp->ssb_stat |= SSB_ST_RESP;
36486 sp->id = fh->fh_seq_id;
36487 } else if (sp->id != fh->fh_seq_id) {
36488 - atomic_inc(&mp->stats.seq_not_found);
36489 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36490 goto rel;
36491 }
36492
36493 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36494 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36495
36496 if (!sp)
36497 - atomic_inc(&mp->stats.xid_not_found);
36498 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36499 else
36500 - atomic_inc(&mp->stats.non_bls_resp);
36501 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36502
36503 fc_frame_free(fp);
36504 }
36505 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36506 index d109cc3..09f4e7d 100644
36507 --- a/drivers/scsi/libsas/sas_ata.c
36508 +++ b/drivers/scsi/libsas/sas_ata.c
36509 @@ -529,7 +529,7 @@ static struct ata_port_operations sas_sata_ops = {
36510 .postreset = ata_std_postreset,
36511 .error_handler = ata_std_error_handler,
36512 .post_internal_cmd = sas_ata_post_internal,
36513 - .qc_defer = ata_std_qc_defer,
36514 + .qc_defer = ata_std_qc_defer,
36515 .qc_prep = ata_noop_qc_prep,
36516 .qc_issue = sas_ata_qc_issue,
36517 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36518 diff --git a/drivers/scsi/lpfc/Makefile b/drivers/scsi/lpfc/Makefile
36519 index fe5d396..e93d526 100644
36520 --- a/drivers/scsi/lpfc/Makefile
36521 +++ b/drivers/scsi/lpfc/Makefile
36522 @@ -22,7 +22,7 @@
36523 ccflags-$(GCOV) := -fprofile-arcs -ftest-coverage
36524 ccflags-$(GCOV) += -O0
36525
36526 -ccflags-y += -Werror
36527 +#ccflags-y += -Werror
36528
36529 obj-$(CONFIG_SCSI_LPFC) := lpfc.o
36530
36531 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36532 index e5da6da..c888d48 100644
36533 --- a/drivers/scsi/lpfc/lpfc.h
36534 +++ b/drivers/scsi/lpfc/lpfc.h
36535 @@ -416,7 +416,7 @@ struct lpfc_vport {
36536 struct dentry *debug_nodelist;
36537 struct dentry *vport_debugfs_root;
36538 struct lpfc_debugfs_trc *disc_trc;
36539 - atomic_t disc_trc_cnt;
36540 + atomic_unchecked_t disc_trc_cnt;
36541 #endif
36542 uint8_t stat_data_enabled;
36543 uint8_t stat_data_blocked;
36544 @@ -830,8 +830,8 @@ struct lpfc_hba {
36545 struct timer_list fabric_block_timer;
36546 unsigned long bit_flags;
36547 #define FABRIC_COMANDS_BLOCKED 0
36548 - atomic_t num_rsrc_err;
36549 - atomic_t num_cmd_success;
36550 + atomic_unchecked_t num_rsrc_err;
36551 + atomic_unchecked_t num_cmd_success;
36552 unsigned long last_rsrc_error_time;
36553 unsigned long last_ramp_down_time;
36554 unsigned long last_ramp_up_time;
36555 @@ -867,7 +867,7 @@ struct lpfc_hba {
36556
36557 struct dentry *debug_slow_ring_trc;
36558 struct lpfc_debugfs_trc *slow_ring_trc;
36559 - atomic_t slow_ring_trc_cnt;
36560 + atomic_unchecked_t slow_ring_trc_cnt;
36561 /* iDiag debugfs sub-directory */
36562 struct dentry *idiag_root;
36563 struct dentry *idiag_pci_cfg;
36564 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36565 index 3217d63..c417981 100644
36566 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36567 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36568 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36569
36570 #include <linux/debugfs.h>
36571
36572 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36573 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36574 static unsigned long lpfc_debugfs_start_time = 0L;
36575
36576 /* iDiag */
36577 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36578 lpfc_debugfs_enable = 0;
36579
36580 len = 0;
36581 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36582 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36583 (lpfc_debugfs_max_disc_trc - 1);
36584 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36585 dtp = vport->disc_trc + i;
36586 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36587 lpfc_debugfs_enable = 0;
36588
36589 len = 0;
36590 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36591 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36592 (lpfc_debugfs_max_slow_ring_trc - 1);
36593 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36594 dtp = phba->slow_ring_trc + i;
36595 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36596 !vport || !vport->disc_trc)
36597 return;
36598
36599 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36600 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36601 (lpfc_debugfs_max_disc_trc - 1);
36602 dtp = vport->disc_trc + index;
36603 dtp->fmt = fmt;
36604 dtp->data1 = data1;
36605 dtp->data2 = data2;
36606 dtp->data3 = data3;
36607 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36608 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36609 dtp->jif = jiffies;
36610 #endif
36611 return;
36612 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36613 !phba || !phba->slow_ring_trc)
36614 return;
36615
36616 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36617 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36618 (lpfc_debugfs_max_slow_ring_trc - 1);
36619 dtp = phba->slow_ring_trc + index;
36620 dtp->fmt = fmt;
36621 dtp->data1 = data1;
36622 dtp->data2 = data2;
36623 dtp->data3 = data3;
36624 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36625 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36626 dtp->jif = jiffies;
36627 #endif
36628 return;
36629 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36630 "slow_ring buffer\n");
36631 goto debug_failed;
36632 }
36633 - atomic_set(&phba->slow_ring_trc_cnt, 0);
36634 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36635 memset(phba->slow_ring_trc, 0,
36636 (sizeof(struct lpfc_debugfs_trc) *
36637 lpfc_debugfs_max_slow_ring_trc));
36638 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36639 "buffer\n");
36640 goto debug_failed;
36641 }
36642 - atomic_set(&vport->disc_trc_cnt, 0);
36643 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36644
36645 snprintf(name, sizeof(name), "discovery_trace");
36646 vport->debug_disc_trc =
36647 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36648 index 411ed48..967f553 100644
36649 --- a/drivers/scsi/lpfc/lpfc_init.c
36650 +++ b/drivers/scsi/lpfc/lpfc_init.c
36651 @@ -10341,8 +10341,10 @@ lpfc_init(void)
36652 "misc_register returned with status %d", error);
36653
36654 if (lpfc_enable_npiv) {
36655 - lpfc_transport_functions.vport_create = lpfc_vport_create;
36656 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36657 + pax_open_kernel();
36658 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36659 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36660 + pax_close_kernel();
36661 }
36662 lpfc_transport_template =
36663 fc_attach_transport(&lpfc_transport_functions);
36664 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36665 index 66e0906..1620281 100644
36666 --- a/drivers/scsi/lpfc/lpfc_scsi.c
36667 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
36668 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36669 uint32_t evt_posted;
36670
36671 spin_lock_irqsave(&phba->hbalock, flags);
36672 - atomic_inc(&phba->num_rsrc_err);
36673 + atomic_inc_unchecked(&phba->num_rsrc_err);
36674 phba->last_rsrc_error_time = jiffies;
36675
36676 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36677 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36678 unsigned long flags;
36679 struct lpfc_hba *phba = vport->phba;
36680 uint32_t evt_posted;
36681 - atomic_inc(&phba->num_cmd_success);
36682 + atomic_inc_unchecked(&phba->num_cmd_success);
36683
36684 if (vport->cfg_lun_queue_depth <= queue_depth)
36685 return;
36686 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36687 unsigned long num_rsrc_err, num_cmd_success;
36688 int i;
36689
36690 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36691 - num_cmd_success = atomic_read(&phba->num_cmd_success);
36692 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36693 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36694
36695 /*
36696 * The error and success command counters are global per
36697 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36698 }
36699 }
36700 lpfc_destroy_vport_work_array(phba, vports);
36701 - atomic_set(&phba->num_rsrc_err, 0);
36702 - atomic_set(&phba->num_cmd_success, 0);
36703 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36704 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36705 }
36706
36707 /**
36708 @@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36709 }
36710 }
36711 lpfc_destroy_vport_work_array(phba, vports);
36712 - atomic_set(&phba->num_rsrc_err, 0);
36713 - atomic_set(&phba->num_cmd_success, 0);
36714 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36715 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36716 }
36717
36718 /**
36719 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36720 index ea8a0b4..812a124 100644
36721 --- a/drivers/scsi/pmcraid.c
36722 +++ b/drivers/scsi/pmcraid.c
36723 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36724 res->scsi_dev = scsi_dev;
36725 scsi_dev->hostdata = res;
36726 res->change_detected = 0;
36727 - atomic_set(&res->read_failures, 0);
36728 - atomic_set(&res->write_failures, 0);
36729 + atomic_set_unchecked(&res->read_failures, 0);
36730 + atomic_set_unchecked(&res->write_failures, 0);
36731 rc = 0;
36732 }
36733 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36734 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36735
36736 /* If this was a SCSI read/write command keep count of errors */
36737 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36738 - atomic_inc(&res->read_failures);
36739 + atomic_inc_unchecked(&res->read_failures);
36740 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36741 - atomic_inc(&res->write_failures);
36742 + atomic_inc_unchecked(&res->write_failures);
36743
36744 if (!RES_IS_GSCSI(res->cfg_entry) &&
36745 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36746 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36747 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36748 * hrrq_id assigned here in queuecommand
36749 */
36750 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36751 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36752 pinstance->num_hrrq;
36753 cmd->cmd_done = pmcraid_io_done;
36754
36755 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36756 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36757 * hrrq_id assigned here in queuecommand
36758 */
36759 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36760 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36761 pinstance->num_hrrq;
36762
36763 if (request_size) {
36764 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36765
36766 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36767 /* add resources only after host is added into system */
36768 - if (!atomic_read(&pinstance->expose_resources))
36769 + if (!atomic_read_unchecked(&pinstance->expose_resources))
36770 return;
36771
36772 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36773 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36774 init_waitqueue_head(&pinstance->reset_wait_q);
36775
36776 atomic_set(&pinstance->outstanding_cmds, 0);
36777 - atomic_set(&pinstance->last_message_id, 0);
36778 - atomic_set(&pinstance->expose_resources, 0);
36779 + atomic_set_unchecked(&pinstance->last_message_id, 0);
36780 + atomic_set_unchecked(&pinstance->expose_resources, 0);
36781
36782 INIT_LIST_HEAD(&pinstance->free_res_q);
36783 INIT_LIST_HEAD(&pinstance->used_res_q);
36784 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
36785 /* Schedule worker thread to handle CCN and take care of adding and
36786 * removing devices to OS
36787 */
36788 - atomic_set(&pinstance->expose_resources, 1);
36789 + atomic_set_unchecked(&pinstance->expose_resources, 1);
36790 schedule_work(&pinstance->worker_q);
36791 return rc;
36792
36793 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36794 index e1d150f..6c6df44 100644
36795 --- a/drivers/scsi/pmcraid.h
36796 +++ b/drivers/scsi/pmcraid.h
36797 @@ -748,7 +748,7 @@ struct pmcraid_instance {
36798 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36799
36800 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36801 - atomic_t last_message_id;
36802 + atomic_unchecked_t last_message_id;
36803
36804 /* configuration table */
36805 struct pmcraid_config_table *cfg_table;
36806 @@ -777,7 +777,7 @@ struct pmcraid_instance {
36807 atomic_t outstanding_cmds;
36808
36809 /* should add/delete resources to mid-layer now ?*/
36810 - atomic_t expose_resources;
36811 + atomic_unchecked_t expose_resources;
36812
36813
36814
36815 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
36816 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36817 };
36818 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36819 - atomic_t read_failures; /* count of failed READ commands */
36820 - atomic_t write_failures; /* count of failed WRITE commands */
36821 + atomic_unchecked_t read_failures; /* count of failed READ commands */
36822 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36823
36824 /* To indicate add/delete/modify during CCN */
36825 u8 change_detected;
36826 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
36827 index 5ab9530..2dd80f7 100644
36828 --- a/drivers/scsi/qla2xxx/qla_attr.c
36829 +++ b/drivers/scsi/qla2xxx/qla_attr.c
36830 @@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
36831 return 0;
36832 }
36833
36834 -struct fc_function_template qla2xxx_transport_functions = {
36835 +fc_function_template_no_const qla2xxx_transport_functions = {
36836
36837 .show_host_node_name = 1,
36838 .show_host_port_name = 1,
36839 @@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
36840 .bsg_timeout = qla24xx_bsg_timeout,
36841 };
36842
36843 -struct fc_function_template qla2xxx_transport_vport_functions = {
36844 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
36845
36846 .show_host_node_name = 1,
36847 .show_host_port_name = 1,
36848 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36849 index 39007f5..7fafc64 100644
36850 --- a/drivers/scsi/qla2xxx/qla_def.h
36851 +++ b/drivers/scsi/qla2xxx/qla_def.h
36852 @@ -2284,7 +2284,7 @@ struct isp_operations {
36853 int (*start_scsi) (srb_t *);
36854 int (*abort_isp) (struct scsi_qla_host *);
36855 int (*iospace_config)(struct qla_hw_data*);
36856 -};
36857 +} __no_const;
36858
36859 /* MSI-X Support *************************************************************/
36860
36861 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
36862 index 9eacd2d..d79629c 100644
36863 --- a/drivers/scsi/qla2xxx/qla_gbl.h
36864 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
36865 @@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
36866 struct device_attribute;
36867 extern struct device_attribute *qla2x00_host_attrs[];
36868 struct fc_function_template;
36869 -extern struct fc_function_template qla2xxx_transport_functions;
36870 -extern struct fc_function_template qla2xxx_transport_vport_functions;
36871 +extern fc_function_template_no_const qla2xxx_transport_functions;
36872 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
36873 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
36874 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
36875 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
36876 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36877 index 96a5616..eeb185a 100644
36878 --- a/drivers/scsi/qla4xxx/ql4_def.h
36879 +++ b/drivers/scsi/qla4xxx/ql4_def.h
36880 @@ -268,7 +268,7 @@ struct ddb_entry {
36881 * (4000 only) */
36882 atomic_t relogin_timer; /* Max Time to wait for
36883 * relogin to complete */
36884 - atomic_t relogin_retry_count; /* Num of times relogin has been
36885 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36886 * retried */
36887 uint32_t default_time2wait; /* Default Min time between
36888 * relogins (+aens) */
36889 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36890 index cd15678..f7e6846 100644
36891 --- a/drivers/scsi/qla4xxx/ql4_os.c
36892 +++ b/drivers/scsi/qla4xxx/ql4_os.c
36893 @@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
36894 */
36895 if (!iscsi_is_session_online(cls_sess)) {
36896 /* Reset retry relogin timer */
36897 - atomic_inc(&ddb_entry->relogin_retry_count);
36898 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36899 DEBUG2(ql4_printk(KERN_INFO, ha,
36900 "%s: index[%d] relogin timed out-retrying"
36901 " relogin (%d), retry (%d)\n", __func__,
36902 ddb_entry->fw_ddb_index,
36903 - atomic_read(&ddb_entry->relogin_retry_count),
36904 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
36905 ddb_entry->default_time2wait + 4));
36906 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
36907 atomic_set(&ddb_entry->retry_relogin_timer,
36908 @@ -4517,7 +4517,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
36909
36910 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36911 atomic_set(&ddb_entry->relogin_timer, 0);
36912 - atomic_set(&ddb_entry->relogin_retry_count, 0);
36913 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36914 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
36915 ddb_entry->default_relogin_timeout =
36916 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
36917 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
36918 index bbbc9c9..ce22f77 100644
36919 --- a/drivers/scsi/scsi.c
36920 +++ b/drivers/scsi/scsi.c
36921 @@ -659,7 +659,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
36922 unsigned long timeout;
36923 int rtn = 0;
36924
36925 - atomic_inc(&cmd->device->iorequest_cnt);
36926 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36927
36928 /* check if the device is still usable */
36929 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
36930 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
36931 index 495db80..fb37d59 100644
36932 --- a/drivers/scsi/scsi_lib.c
36933 +++ b/drivers/scsi/scsi_lib.c
36934 @@ -1422,7 +1422,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
36935 shost = sdev->host;
36936 scsi_init_cmd_errh(cmd);
36937 cmd->result = DID_NO_CONNECT << 16;
36938 - atomic_inc(&cmd->device->iorequest_cnt);
36939 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36940
36941 /*
36942 * SCSI request completion path will do scsi_device_unbusy(),
36943 @@ -1448,9 +1448,9 @@ static void scsi_softirq_done(struct request *rq)
36944
36945 INIT_LIST_HEAD(&cmd->eh_entry);
36946
36947 - atomic_inc(&cmd->device->iodone_cnt);
36948 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
36949 if (cmd->result)
36950 - atomic_inc(&cmd->device->ioerr_cnt);
36951 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
36952
36953 disposition = scsi_decide_disposition(cmd);
36954 if (disposition != SUCCESS &&
36955 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
36956 index bb7c482..7551a95 100644
36957 --- a/drivers/scsi/scsi_sysfs.c
36958 +++ b/drivers/scsi/scsi_sysfs.c
36959 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
36960 char *buf) \
36961 { \
36962 struct scsi_device *sdev = to_scsi_device(dev); \
36963 - unsigned long long count = atomic_read(&sdev->field); \
36964 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
36965 return snprintf(buf, 20, "0x%llx\n", count); \
36966 } \
36967 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
36968 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
36969 index 84a1fdf..693b0d6 100644
36970 --- a/drivers/scsi/scsi_tgt_lib.c
36971 +++ b/drivers/scsi/scsi_tgt_lib.c
36972 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
36973 int err;
36974
36975 dprintk("%lx %u\n", uaddr, len);
36976 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
36977 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
36978 if (err) {
36979 /*
36980 * TODO: need to fixup sg_tablesize, max_segment_size,
36981 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
36982 index 5797604..289a5b5 100644
36983 --- a/drivers/scsi/scsi_transport_fc.c
36984 +++ b/drivers/scsi/scsi_transport_fc.c
36985 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
36986 * Netlink Infrastructure
36987 */
36988
36989 -static atomic_t fc_event_seq;
36990 +static atomic_unchecked_t fc_event_seq;
36991
36992 /**
36993 * fc_get_event_number - Obtain the next sequential FC event number
36994 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
36995 u32
36996 fc_get_event_number(void)
36997 {
36998 - return atomic_add_return(1, &fc_event_seq);
36999 + return atomic_add_return_unchecked(1, &fc_event_seq);
37000 }
37001 EXPORT_SYMBOL(fc_get_event_number);
37002
37003 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37004 {
37005 int error;
37006
37007 - atomic_set(&fc_event_seq, 0);
37008 + atomic_set_unchecked(&fc_event_seq, 0);
37009
37010 error = transport_class_register(&fc_host_class);
37011 if (error)
37012 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37013 char *cp;
37014
37015 *val = simple_strtoul(buf, &cp, 0);
37016 - if ((*cp && (*cp != '\n')) || (*val < 0))
37017 + if (*cp && (*cp != '\n'))
37018 return -EINVAL;
37019 /*
37020 * Check for overflow; dev_loss_tmo is u32
37021 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37022 index 1cf640e..78e9014 100644
37023 --- a/drivers/scsi/scsi_transport_iscsi.c
37024 +++ b/drivers/scsi/scsi_transport_iscsi.c
37025 @@ -79,7 +79,7 @@ struct iscsi_internal {
37026 struct transport_container session_cont;
37027 };
37028
37029 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37030 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37031 static struct workqueue_struct *iscsi_eh_timer_workq;
37032
37033 static DEFINE_IDA(iscsi_sess_ida);
37034 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37035 int err;
37036
37037 ihost = shost->shost_data;
37038 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37039 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37040
37041 if (target_id == ISCSI_MAX_TARGET) {
37042 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37043 @@ -2940,7 +2940,7 @@ static __init int iscsi_transport_init(void)
37044 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37045 ISCSI_TRANSPORT_VERSION);
37046
37047 - atomic_set(&iscsi_session_nr, 0);
37048 + atomic_set_unchecked(&iscsi_session_nr, 0);
37049
37050 err = class_register(&iscsi_transport_class);
37051 if (err)
37052 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37053 index 21a045e..ec89e03 100644
37054 --- a/drivers/scsi/scsi_transport_srp.c
37055 +++ b/drivers/scsi/scsi_transport_srp.c
37056 @@ -33,7 +33,7 @@
37057 #include "scsi_transport_srp_internal.h"
37058
37059 struct srp_host_attrs {
37060 - atomic_t next_port_id;
37061 + atomic_unchecked_t next_port_id;
37062 };
37063 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37064
37065 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37066 struct Scsi_Host *shost = dev_to_shost(dev);
37067 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37068
37069 - atomic_set(&srp_host->next_port_id, 0);
37070 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37071 return 0;
37072 }
37073
37074 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37075 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37076 rport->roles = ids->roles;
37077
37078 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37079 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37080 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37081
37082 transport_setup_device(&rport->dev);
37083 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37084 index 9c5c5f2..8414557 100644
37085 --- a/drivers/scsi/sg.c
37086 +++ b/drivers/scsi/sg.c
37087 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37088 sdp->disk->disk_name,
37089 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37090 NULL,
37091 - (char *)arg);
37092 + (char __user *)arg);
37093 case BLKTRACESTART:
37094 return blk_trace_startstop(sdp->device->request_queue, 1);
37095 case BLKTRACESTOP:
37096 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37097 index 1041cb8..4a946fa 100644
37098 --- a/drivers/spi/spi.c
37099 +++ b/drivers/spi/spi.c
37100 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37101 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37102
37103 /* portable code must never pass more than 32 bytes */
37104 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37105 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37106
37107 static u8 *buf;
37108
37109 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37110 index 34afc16..ffe44dd 100644
37111 --- a/drivers/staging/octeon/ethernet-rx.c
37112 +++ b/drivers/staging/octeon/ethernet-rx.c
37113 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37114 /* Increment RX stats for virtual ports */
37115 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37116 #ifdef CONFIG_64BIT
37117 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37118 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37119 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37120 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37121 #else
37122 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37123 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37124 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37125 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37126 #endif
37127 }
37128 netif_receive_skb(skb);
37129 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37130 dev->name);
37131 */
37132 #ifdef CONFIG_64BIT
37133 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37134 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37135 #else
37136 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37137 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37138 #endif
37139 dev_kfree_skb_irq(skb);
37140 }
37141 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37142 index 18f7a79..cc3bc24 100644
37143 --- a/drivers/staging/octeon/ethernet.c
37144 +++ b/drivers/staging/octeon/ethernet.c
37145 @@ -259,11 +259,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37146 * since the RX tasklet also increments it.
37147 */
37148 #ifdef CONFIG_64BIT
37149 - atomic64_add(rx_status.dropped_packets,
37150 - (atomic64_t *)&priv->stats.rx_dropped);
37151 + atomic64_add_unchecked(rx_status.dropped_packets,
37152 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37153 #else
37154 - atomic_add(rx_status.dropped_packets,
37155 - (atomic_t *)&priv->stats.rx_dropped);
37156 + atomic_add_unchecked(rx_status.dropped_packets,
37157 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37158 #endif
37159 }
37160
37161 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37162 index dc23395..cf7e9b1 100644
37163 --- a/drivers/staging/rtl8712/rtl871x_io.h
37164 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37165 @@ -108,7 +108,7 @@ struct _io_ops {
37166 u8 *pmem);
37167 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37168 u8 *pmem);
37169 -};
37170 +} __no_const;
37171
37172 struct io_req {
37173 struct list_head list;
37174 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37175 index c7b5e8b..783d6cb 100644
37176 --- a/drivers/staging/sbe-2t3e3/netdev.c
37177 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37178 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37179 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37180
37181 if (rlen)
37182 - if (copy_to_user(data, &resp, rlen))
37183 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37184 return -EFAULT;
37185
37186 return 0;
37187 diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37188 index 42cdafe..2769103 100644
37189 --- a/drivers/staging/speakup/speakup_soft.c
37190 +++ b/drivers/staging/speakup/speakup_soft.c
37191 @@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37192 break;
37193 } else if (!initialized) {
37194 if (*init) {
37195 - ch = *init;
37196 init++;
37197 } else {
37198 initialized = 1;
37199 }
37200 + ch = *init;
37201 } else {
37202 ch = synth_buffer_getc();
37203 }
37204 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37205 index 5d89c0f..9261317 100644
37206 --- a/drivers/staging/usbip/usbip_common.h
37207 +++ b/drivers/staging/usbip/usbip_common.h
37208 @@ -289,7 +289,7 @@ struct usbip_device {
37209 void (*shutdown)(struct usbip_device *);
37210 void (*reset)(struct usbip_device *);
37211 void (*unusable)(struct usbip_device *);
37212 - } eh_ops;
37213 + } __no_const eh_ops;
37214 };
37215
37216 #define kthread_get_run(threadfn, data, namefmt, ...) \
37217 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37218 index 88b3298..3783eee 100644
37219 --- a/drivers/staging/usbip/vhci.h
37220 +++ b/drivers/staging/usbip/vhci.h
37221 @@ -88,7 +88,7 @@ struct vhci_hcd {
37222 unsigned resuming:1;
37223 unsigned long re_timeout;
37224
37225 - atomic_t seqnum;
37226 + atomic_unchecked_t seqnum;
37227
37228 /*
37229 * NOTE:
37230 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37231 index f708cba..2de6d72 100644
37232 --- a/drivers/staging/usbip/vhci_hcd.c
37233 +++ b/drivers/staging/usbip/vhci_hcd.c
37234 @@ -488,7 +488,7 @@ static void vhci_tx_urb(struct urb *urb)
37235 return;
37236 }
37237
37238 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37239 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37240 if (priv->seqnum == 0xffff)
37241 dev_info(&urb->dev->dev, "seqnum max\n");
37242
37243 @@ -740,7 +740,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37244 return -ENOMEM;
37245 }
37246
37247 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37248 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37249 if (unlink->seqnum == 0xffff)
37250 pr_info("seqnum max\n");
37251
37252 @@ -928,7 +928,7 @@ static int vhci_start(struct usb_hcd *hcd)
37253 vdev->rhport = rhport;
37254 }
37255
37256 - atomic_set(&vhci->seqnum, 0);
37257 + atomic_set_unchecked(&vhci->seqnum, 0);
37258 spin_lock_init(&vhci->lock);
37259
37260 hcd->power_budget = 0; /* no limit */
37261 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37262 index f0eaf04..5a82e06 100644
37263 --- a/drivers/staging/usbip/vhci_rx.c
37264 +++ b/drivers/staging/usbip/vhci_rx.c
37265 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37266 if (!urb) {
37267 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37268 pr_info("max seqnum %d\n",
37269 - atomic_read(&the_controller->seqnum));
37270 + atomic_read_unchecked(&the_controller->seqnum));
37271 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37272 return;
37273 }
37274 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37275 index 7735027..30eed13 100644
37276 --- a/drivers/staging/vt6655/hostap.c
37277 +++ b/drivers/staging/vt6655/hostap.c
37278 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37279 *
37280 */
37281
37282 +static net_device_ops_no_const apdev_netdev_ops;
37283 +
37284 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37285 {
37286 PSDevice apdev_priv;
37287 struct net_device *dev = pDevice->dev;
37288 int ret;
37289 - const struct net_device_ops apdev_netdev_ops = {
37290 - .ndo_start_xmit = pDevice->tx_80211,
37291 - };
37292
37293 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37294
37295 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37296 *apdev_priv = *pDevice;
37297 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37298
37299 + /* only half broken now */
37300 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37301 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37302
37303 pDevice->apdev->type = ARPHRD_IEEE80211;
37304 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37305 index 51b5adf..098e320 100644
37306 --- a/drivers/staging/vt6656/hostap.c
37307 +++ b/drivers/staging/vt6656/hostap.c
37308 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37309 *
37310 */
37311
37312 +static net_device_ops_no_const apdev_netdev_ops;
37313 +
37314 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37315 {
37316 PSDevice apdev_priv;
37317 struct net_device *dev = pDevice->dev;
37318 int ret;
37319 - const struct net_device_ops apdev_netdev_ops = {
37320 - .ndo_start_xmit = pDevice->tx_80211,
37321 - };
37322
37323 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37324
37325 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37326 *apdev_priv = *pDevice;
37327 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37328
37329 + /* only half broken now */
37330 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37331 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37332
37333 pDevice->apdev->type = ARPHRD_IEEE80211;
37334 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37335 index 7843dfd..3db105f 100644
37336 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37337 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37338 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37339
37340 struct usbctlx_completor {
37341 int (*complete) (struct usbctlx_completor *);
37342 -};
37343 +} __no_const;
37344
37345 static int
37346 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37347 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37348 index 1ca66ea..76f1343 100644
37349 --- a/drivers/staging/zcache/tmem.c
37350 +++ b/drivers/staging/zcache/tmem.c
37351 @@ -39,7 +39,7 @@
37352 * A tmem host implementation must use this function to register callbacks
37353 * for memory allocation.
37354 */
37355 -static struct tmem_hostops tmem_hostops;
37356 +static tmem_hostops_no_const tmem_hostops;
37357
37358 static void tmem_objnode_tree_init(void);
37359
37360 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37361 * A tmem host implementation must use this function to register
37362 * callbacks for a page-accessible memory (PAM) implementation
37363 */
37364 -static struct tmem_pamops tmem_pamops;
37365 +static tmem_pamops_no_const tmem_pamops;
37366
37367 void tmem_register_pamops(struct tmem_pamops *m)
37368 {
37369 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37370 index 0d4aa82..f7832d4 100644
37371 --- a/drivers/staging/zcache/tmem.h
37372 +++ b/drivers/staging/zcache/tmem.h
37373 @@ -180,6 +180,7 @@ struct tmem_pamops {
37374 void (*new_obj)(struct tmem_obj *);
37375 int (*replace_in_obj)(void *, struct tmem_obj *);
37376 };
37377 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37378 extern void tmem_register_pamops(struct tmem_pamops *m);
37379
37380 /* memory allocation methods provided by the host implementation */
37381 @@ -189,6 +190,7 @@ struct tmem_hostops {
37382 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37383 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37384 };
37385 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37386 extern void tmem_register_hostops(struct tmem_hostops *m);
37387
37388 /* core tmem accessor functions */
37389 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37390 index c6c385f..b23c65d 100644
37391 --- a/drivers/target/target_core_transport.c
37392 +++ b/drivers/target/target_core_transport.c
37393 @@ -1233,7 +1233,7 @@ struct se_device *transport_add_device_to_core_hba(
37394 spin_lock_init(&dev->se_port_lock);
37395 spin_lock_init(&dev->se_tmr_lock);
37396 spin_lock_init(&dev->qf_cmd_lock);
37397 - atomic_set(&dev->dev_ordered_id, 0);
37398 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37399
37400 se_dev_set_default_attribs(dev, dev_limits);
37401
37402 @@ -1402,7 +1402,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37403 * Used to determine when ORDERED commands should go from
37404 * Dormant to Active status.
37405 */
37406 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37407 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37408 smp_mb__after_atomic_inc();
37409 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37410 cmd->se_ordered_id, cmd->sam_task_attr,
37411 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37412 index e61cabd..7617d26 100644
37413 --- a/drivers/tty/cyclades.c
37414 +++ b/drivers/tty/cyclades.c
37415 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37416 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37417 info->port.count);
37418 #endif
37419 - info->port.count++;
37420 + atomic_inc(&info->port.count);
37421 #ifdef CY_DEBUG_COUNT
37422 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37423 - current->pid, info->port.count);
37424 + current->pid, atomic_read(&info->port.count));
37425 #endif
37426
37427 /*
37428 @@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37429 for (j = 0; j < cy_card[i].nports; j++) {
37430 info = &cy_card[i].ports[j];
37431
37432 - if (info->port.count) {
37433 + if (atomic_read(&info->port.count)) {
37434 /* XXX is the ldisc num worth this? */
37435 struct tty_struct *tty;
37436 struct tty_ldisc *ld;
37437 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37438 index 2d691eb..be02ebd 100644
37439 --- a/drivers/tty/hvc/hvc_console.c
37440 +++ b/drivers/tty/hvc/hvc_console.c
37441 @@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37442
37443 spin_lock_irqsave(&hp->port.lock, flags);
37444 /* Check and then increment for fast path open. */
37445 - if (hp->port.count++ > 0) {
37446 + if (atomic_inc_return(&hp->port.count) > 1) {
37447 spin_unlock_irqrestore(&hp->port.lock, flags);
37448 hvc_kick();
37449 return 0;
37450 @@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37451
37452 spin_lock_irqsave(&hp->port.lock, flags);
37453
37454 - if (--hp->port.count == 0) {
37455 + if (atomic_dec_return(&hp->port.count) == 0) {
37456 spin_unlock_irqrestore(&hp->port.lock, flags);
37457 /* We are done with the tty pointer now. */
37458 tty_port_tty_set(&hp->port, NULL);
37459 @@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37460 */
37461 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37462 } else {
37463 - if (hp->port.count < 0)
37464 + if (atomic_read(&hp->port.count) < 0)
37465 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
37466 - hp->vtermno, hp->port.count);
37467 + hp->vtermno, atomic_read(&hp->port.count));
37468 spin_unlock_irqrestore(&hp->port.lock, flags);
37469 }
37470
37471 @@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
37472 * open->hangup case this can be called after the final close so prevent
37473 * that from happening for now.
37474 */
37475 - if (hp->port.count <= 0) {
37476 + if (atomic_read(&hp->port.count) <= 0) {
37477 spin_unlock_irqrestore(&hp->port.lock, flags);
37478 return;
37479 }
37480
37481 - temp_open_count = hp->port.count;
37482 - hp->port.count = 0;
37483 + temp_open_count = atomic_read(&hp->port.count);
37484 + atomic_set(&hp->port.count, 0);
37485 spin_unlock_irqrestore(&hp->port.lock, flags);
37486 tty_port_tty_set(&hp->port, NULL);
37487
37488 @@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
37489 return -EPIPE;
37490
37491 /* FIXME what's this (unprotected) check for? */
37492 - if (hp->port.count <= 0)
37493 + if (atomic_read(&hp->port.count) <= 0)
37494 return -EIO;
37495
37496 spin_lock_irqsave(&hp->lock, flags);
37497 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37498 index d56788c..12d8f85 100644
37499 --- a/drivers/tty/hvc/hvcs.c
37500 +++ b/drivers/tty/hvc/hvcs.c
37501 @@ -83,6 +83,7 @@
37502 #include <asm/hvcserver.h>
37503 #include <asm/uaccess.h>
37504 #include <asm/vio.h>
37505 +#include <asm/local.h>
37506
37507 /*
37508 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37509 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37510
37511 spin_lock_irqsave(&hvcsd->lock, flags);
37512
37513 - if (hvcsd->port.count > 0) {
37514 + if (atomic_read(&hvcsd->port.count) > 0) {
37515 spin_unlock_irqrestore(&hvcsd->lock, flags);
37516 printk(KERN_INFO "HVCS: vterm state unchanged. "
37517 "The hvcs device node is still in use.\n");
37518 @@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37519 if ((retval = hvcs_partner_connect(hvcsd)))
37520 goto error_release;
37521
37522 - hvcsd->port.count = 1;
37523 + atomic_set(&hvcsd->port.count, 1);
37524 hvcsd->port.tty = tty;
37525 tty->driver_data = hvcsd;
37526
37527 @@ -1168,7 +1169,7 @@ fast_open:
37528
37529 spin_lock_irqsave(&hvcsd->lock, flags);
37530 tty_port_get(&hvcsd->port);
37531 - hvcsd->port.count++;
37532 + atomic_inc(&hvcsd->port.count);
37533 hvcsd->todo_mask |= HVCS_SCHED_READ;
37534 spin_unlock_irqrestore(&hvcsd->lock, flags);
37535
37536 @@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37537 hvcsd = tty->driver_data;
37538
37539 spin_lock_irqsave(&hvcsd->lock, flags);
37540 - if (--hvcsd->port.count == 0) {
37541 + if (atomic_dec_and_test(&hvcsd->port.count)) {
37542
37543 vio_disable_interrupts(hvcsd->vdev);
37544
37545 @@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37546 free_irq(irq, hvcsd);
37547 tty_port_put(&hvcsd->port);
37548 return;
37549 - } else if (hvcsd->port.count < 0) {
37550 + } else if (atomic_read(&hvcsd->port.count) < 0) {
37551 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37552 " is missmanaged.\n",
37553 - hvcsd->vdev->unit_address, hvcsd->port.count);
37554 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
37555 }
37556
37557 spin_unlock_irqrestore(&hvcsd->lock, flags);
37558 @@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37559
37560 spin_lock_irqsave(&hvcsd->lock, flags);
37561 /* Preserve this so that we know how many kref refs to put */
37562 - temp_open_count = hvcsd->port.count;
37563 + temp_open_count = atomic_read(&hvcsd->port.count);
37564
37565 /*
37566 * Don't kref put inside the spinlock because the destruction
37567 @@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37568 tty->driver_data = NULL;
37569 hvcsd->port.tty = NULL;
37570
37571 - hvcsd->port.count = 0;
37572 + atomic_set(&hvcsd->port.count, 0);
37573
37574 /* This will drop any buffered data on the floor which is OK in a hangup
37575 * scenario. */
37576 @@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
37577 * the middle of a write operation? This is a crummy place to do this
37578 * but we want to keep it all in the spinlock.
37579 */
37580 - if (hvcsd->port.count <= 0) {
37581 + if (atomic_read(&hvcsd->port.count) <= 0) {
37582 spin_unlock_irqrestore(&hvcsd->lock, flags);
37583 return -ENODEV;
37584 }
37585 @@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37586 {
37587 struct hvcs_struct *hvcsd = tty->driver_data;
37588
37589 - if (!hvcsd || hvcsd->port.count <= 0)
37590 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
37591 return 0;
37592
37593 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37594 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37595 index f8b5fa0..4ba9f89 100644
37596 --- a/drivers/tty/ipwireless/tty.c
37597 +++ b/drivers/tty/ipwireless/tty.c
37598 @@ -29,6 +29,7 @@
37599 #include <linux/tty_driver.h>
37600 #include <linux/tty_flip.h>
37601 #include <linux/uaccess.h>
37602 +#include <asm/local.h>
37603
37604 #include "tty.h"
37605 #include "network.h"
37606 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37607 mutex_unlock(&tty->ipw_tty_mutex);
37608 return -ENODEV;
37609 }
37610 - if (tty->port.count == 0)
37611 + if (atomic_read(&tty->port.count) == 0)
37612 tty->tx_bytes_queued = 0;
37613
37614 - tty->port.count++;
37615 + atomic_inc(&tty->port.count);
37616
37617 tty->port.tty = linux_tty;
37618 linux_tty->driver_data = tty;
37619 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37620
37621 static void do_ipw_close(struct ipw_tty *tty)
37622 {
37623 - tty->port.count--;
37624 -
37625 - if (tty->port.count == 0) {
37626 + if (atomic_dec_return(&tty->port.count) == 0) {
37627 struct tty_struct *linux_tty = tty->port.tty;
37628
37629 if (linux_tty != NULL) {
37630 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37631 return;
37632
37633 mutex_lock(&tty->ipw_tty_mutex);
37634 - if (tty->port.count == 0) {
37635 + if (atomic_read(&tty->port.count) == 0) {
37636 mutex_unlock(&tty->ipw_tty_mutex);
37637 return;
37638 }
37639 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37640 return;
37641 }
37642
37643 - if (!tty->port.count) {
37644 + if (!atomic_read(&tty->port.count)) {
37645 mutex_unlock(&tty->ipw_tty_mutex);
37646 return;
37647 }
37648 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37649 return -ENODEV;
37650
37651 mutex_lock(&tty->ipw_tty_mutex);
37652 - if (!tty->port.count) {
37653 + if (!atomic_read(&tty->port.count)) {
37654 mutex_unlock(&tty->ipw_tty_mutex);
37655 return -EINVAL;
37656 }
37657 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37658 if (!tty)
37659 return -ENODEV;
37660
37661 - if (!tty->port.count)
37662 + if (!atomic_read(&tty->port.count))
37663 return -EINVAL;
37664
37665 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37666 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37667 if (!tty)
37668 return 0;
37669
37670 - if (!tty->port.count)
37671 + if (!atomic_read(&tty->port.count))
37672 return 0;
37673
37674 return tty->tx_bytes_queued;
37675 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
37676 if (!tty)
37677 return -ENODEV;
37678
37679 - if (!tty->port.count)
37680 + if (!atomic_read(&tty->port.count))
37681 return -EINVAL;
37682
37683 return get_control_lines(tty);
37684 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
37685 if (!tty)
37686 return -ENODEV;
37687
37688 - if (!tty->port.count)
37689 + if (!atomic_read(&tty->port.count))
37690 return -EINVAL;
37691
37692 return set_control_lines(tty, set, clear);
37693 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37694 if (!tty)
37695 return -ENODEV;
37696
37697 - if (!tty->port.count)
37698 + if (!atomic_read(&tty->port.count))
37699 return -EINVAL;
37700
37701 /* FIXME: Exactly how is the tty object locked here .. */
37702 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37703 * are gone */
37704 mutex_lock(&ttyj->ipw_tty_mutex);
37705 }
37706 - while (ttyj->port.count)
37707 + while (atomic_read(&ttyj->port.count))
37708 do_ipw_close(ttyj);
37709 ipwireless_disassociate_network_ttys(network,
37710 ttyj->channel_idx);
37711 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
37712 index 324467d..504cc25 100644
37713 --- a/drivers/tty/moxa.c
37714 +++ b/drivers/tty/moxa.c
37715 @@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
37716 }
37717
37718 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
37719 - ch->port.count++;
37720 + atomic_inc(&ch->port.count);
37721 tty->driver_data = ch;
37722 tty_port_tty_set(&ch->port, tty);
37723 mutex_lock(&ch->port.mutex);
37724 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37725 index c43b683..4dab83e 100644
37726 --- a/drivers/tty/n_gsm.c
37727 +++ b/drivers/tty/n_gsm.c
37728 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37729 kref_init(&dlci->ref);
37730 mutex_init(&dlci->mutex);
37731 dlci->fifo = &dlci->_fifo;
37732 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37733 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37734 kfree(dlci);
37735 return NULL;
37736 }
37737 @@ -2895,7 +2895,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
37738 if (dlci == NULL)
37739 return -ENOMEM;
37740 port = &dlci->port;
37741 - port->count++;
37742 + atomic_inc(&port->count);
37743 tty->driver_data = dlci;
37744 dlci_get(dlci);
37745 dlci_get(dlci->gsm->dlci[0]);
37746 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37747 index ee1c268..0e97caf 100644
37748 --- a/drivers/tty/n_tty.c
37749 +++ b/drivers/tty/n_tty.c
37750 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37751 {
37752 *ops = tty_ldisc_N_TTY;
37753 ops->owner = NULL;
37754 - ops->refcount = ops->flags = 0;
37755 + atomic_set(&ops->refcount, 0);
37756 + ops->flags = 0;
37757 }
37758 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37759 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37760 index 5505ffc..7affff9 100644
37761 --- a/drivers/tty/pty.c
37762 +++ b/drivers/tty/pty.c
37763 @@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
37764 panic("Couldn't register Unix98 pts driver");
37765
37766 /* Now create the /dev/ptmx special device */
37767 + pax_open_kernel();
37768 tty_default_fops(&ptmx_fops);
37769 - ptmx_fops.open = ptmx_open;
37770 + *(void **)&ptmx_fops.open = ptmx_open;
37771 + pax_close_kernel();
37772
37773 cdev_init(&ptmx_cdev, &ptmx_fops);
37774 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37775 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
37776 index 777d5f9..56d67ca 100644
37777 --- a/drivers/tty/rocket.c
37778 +++ b/drivers/tty/rocket.c
37779 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37780 tty->driver_data = info;
37781 tty_port_tty_set(port, tty);
37782
37783 - if (port->count++ == 0) {
37784 + if (atomic_inc_return(&port->count) == 1) {
37785 atomic_inc(&rp_num_ports_open);
37786
37787 #ifdef ROCKET_DEBUG_OPEN
37788 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37789 #endif
37790 }
37791 #ifdef ROCKET_DEBUG_OPEN
37792 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
37793 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
37794 #endif
37795
37796 /*
37797 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
37798 spin_unlock_irqrestore(&info->port.lock, flags);
37799 return;
37800 }
37801 - if (info->port.count)
37802 + if (atomic_read(&info->port.count))
37803 atomic_dec(&rp_num_ports_open);
37804 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
37805 spin_unlock_irqrestore(&info->port.lock, flags);
37806 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37807 index 2b42a01..32a2ed3 100644
37808 --- a/drivers/tty/serial/kgdboc.c
37809 +++ b/drivers/tty/serial/kgdboc.c
37810 @@ -24,8 +24,9 @@
37811 #define MAX_CONFIG_LEN 40
37812
37813 static struct kgdb_io kgdboc_io_ops;
37814 +static struct kgdb_io kgdboc_io_ops_console;
37815
37816 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37817 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37818 static int configured = -1;
37819
37820 static char config[MAX_CONFIG_LEN];
37821 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37822 kgdboc_unregister_kbd();
37823 if (configured == 1)
37824 kgdb_unregister_io_module(&kgdboc_io_ops);
37825 + else if (configured == 2)
37826 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
37827 }
37828
37829 static int configure_kgdboc(void)
37830 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37831 int err;
37832 char *cptr = config;
37833 struct console *cons;
37834 + int is_console = 0;
37835
37836 err = kgdboc_option_setup(config);
37837 if (err || !strlen(config) || isspace(config[0]))
37838 goto noconfig;
37839
37840 err = -ENODEV;
37841 - kgdboc_io_ops.is_console = 0;
37842 kgdb_tty_driver = NULL;
37843
37844 kgdboc_use_kms = 0;
37845 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37846 int idx;
37847 if (cons->device && cons->device(cons, &idx) == p &&
37848 idx == tty_line) {
37849 - kgdboc_io_ops.is_console = 1;
37850 + is_console = 1;
37851 break;
37852 }
37853 cons = cons->next;
37854 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37855 kgdb_tty_line = tty_line;
37856
37857 do_register:
37858 - err = kgdb_register_io_module(&kgdboc_io_ops);
37859 + if (is_console) {
37860 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
37861 + configured = 2;
37862 + } else {
37863 + err = kgdb_register_io_module(&kgdboc_io_ops);
37864 + configured = 1;
37865 + }
37866 if (err)
37867 goto noconfig;
37868
37869 - configured = 1;
37870 -
37871 return 0;
37872
37873 noconfig:
37874 @@ -213,7 +220,7 @@ noconfig:
37875 static int __init init_kgdboc(void)
37876 {
37877 /* Already configured? */
37878 - if (configured == 1)
37879 + if (configured >= 1)
37880 return 0;
37881
37882 return configure_kgdboc();
37883 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37884 if (config[len - 1] == '\n')
37885 config[len - 1] = '\0';
37886
37887 - if (configured == 1)
37888 + if (configured >= 1)
37889 cleanup_kgdboc();
37890
37891 /* Go and configure with the new params. */
37892 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37893 .post_exception = kgdboc_post_exp_handler,
37894 };
37895
37896 +static struct kgdb_io kgdboc_io_ops_console = {
37897 + .name = "kgdboc",
37898 + .read_char = kgdboc_get_char,
37899 + .write_char = kgdboc_put_char,
37900 + .pre_exception = kgdboc_pre_exp_handler,
37901 + .post_exception = kgdboc_post_exp_handler,
37902 + .is_console = 1
37903 +};
37904 +
37905 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
37906 /* This is only available if kgdboc is a built in for early debugging */
37907 static int __init kgdboc_early_init(char *opt)
37908 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
37909 index 246b823..9e0db76 100644
37910 --- a/drivers/tty/serial/serial_core.c
37911 +++ b/drivers/tty/serial/serial_core.c
37912 @@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
37913 uart_flush_buffer(tty);
37914 uart_shutdown(tty, state);
37915 spin_lock_irqsave(&port->lock, flags);
37916 - port->count = 0;
37917 + atomic_set(&port->count, 0);
37918 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
37919 spin_unlock_irqrestore(&port->lock, flags);
37920 tty_port_tty_set(port, NULL);
37921 @@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37922 goto end;
37923 }
37924
37925 - port->count++;
37926 + atomic_inc(&port->count);
37927 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
37928 retval = -ENXIO;
37929 goto err_dec_count;
37930 @@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37931 /*
37932 * Make sure the device is in D0 state.
37933 */
37934 - if (port->count == 1)
37935 + if (atomic_read(&port->count) == 1)
37936 uart_change_pm(state, 0);
37937
37938 /*
37939 @@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37940 end:
37941 return retval;
37942 err_dec_count:
37943 - port->count--;
37944 + atomic_inc(&port->count);
37945 mutex_unlock(&port->mutex);
37946 goto end;
37947 }
37948 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
37949 index 593d40a..bdc61f3 100644
37950 --- a/drivers/tty/synclink.c
37951 +++ b/drivers/tty/synclink.c
37952 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
37953
37954 if (debug_level >= DEBUG_LEVEL_INFO)
37955 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
37956 - __FILE__,__LINE__, info->device_name, info->port.count);
37957 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
37958
37959 if (tty_port_close_start(&info->port, tty, filp) == 0)
37960 goto cleanup;
37961 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
37962 cleanup:
37963 if (debug_level >= DEBUG_LEVEL_INFO)
37964 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
37965 - tty->driver->name, info->port.count);
37966 + tty->driver->name, atomic_read(&info->port.count));
37967
37968 } /* end of mgsl_close() */
37969
37970 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
37971
37972 mgsl_flush_buffer(tty);
37973 shutdown(info);
37974 -
37975 - info->port.count = 0;
37976 +
37977 + atomic_set(&info->port.count, 0);
37978 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
37979 info->port.tty = NULL;
37980
37981 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
37982
37983 if (debug_level >= DEBUG_LEVEL_INFO)
37984 printk("%s(%d):block_til_ready before block on %s count=%d\n",
37985 - __FILE__,__LINE__, tty->driver->name, port->count );
37986 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
37987
37988 spin_lock_irqsave(&info->irq_spinlock, flags);
37989 if (!tty_hung_up_p(filp)) {
37990 extra_count = true;
37991 - port->count--;
37992 + atomic_dec(&port->count);
37993 }
37994 spin_unlock_irqrestore(&info->irq_spinlock, flags);
37995 port->blocked_open++;
37996 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
37997
37998 if (debug_level >= DEBUG_LEVEL_INFO)
37999 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38000 - __FILE__,__LINE__, tty->driver->name, port->count );
38001 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38002
38003 tty_unlock();
38004 schedule();
38005 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38006
38007 /* FIXME: Racy on hangup during close wait */
38008 if (extra_count)
38009 - port->count++;
38010 + atomic_inc(&port->count);
38011 port->blocked_open--;
38012
38013 if (debug_level >= DEBUG_LEVEL_INFO)
38014 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38015 - __FILE__,__LINE__, tty->driver->name, port->count );
38016 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38017
38018 if (!retval)
38019 port->flags |= ASYNC_NORMAL_ACTIVE;
38020 @@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38021
38022 if (debug_level >= DEBUG_LEVEL_INFO)
38023 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38024 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38025 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38026
38027 /* If port is closing, signal caller to try again */
38028 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38029 @@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38030 spin_unlock_irqrestore(&info->netlock, flags);
38031 goto cleanup;
38032 }
38033 - info->port.count++;
38034 + atomic_inc(&info->port.count);
38035 spin_unlock_irqrestore(&info->netlock, flags);
38036
38037 - if (info->port.count == 1) {
38038 + if (atomic_read(&info->port.count) == 1) {
38039 /* 1st open on this device, init hardware */
38040 retval = startup(info);
38041 if (retval < 0)
38042 @@ -3444,8 +3444,8 @@ cleanup:
38043 if (retval) {
38044 if (tty->count == 1)
38045 info->port.tty = NULL; /* tty layer will release tty struct */
38046 - if(info->port.count)
38047 - info->port.count--;
38048 + if (atomic_read(&info->port.count))
38049 + atomic_dec(&info->port.count);
38050 }
38051
38052 return retval;
38053 @@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38054 unsigned short new_crctype;
38055
38056 /* return error if TTY interface open */
38057 - if (info->port.count)
38058 + if (atomic_read(&info->port.count))
38059 return -EBUSY;
38060
38061 switch (encoding)
38062 @@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38063
38064 /* arbitrate between network and tty opens */
38065 spin_lock_irqsave(&info->netlock, flags);
38066 - if (info->port.count != 0 || info->netcount != 0) {
38067 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38068 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38069 spin_unlock_irqrestore(&info->netlock, flags);
38070 return -EBUSY;
38071 @@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38072 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38073
38074 /* return error if TTY interface open */
38075 - if (info->port.count)
38076 + if (atomic_read(&info->port.count))
38077 return -EBUSY;
38078
38079 if (cmd != SIOCWANDEV)
38080 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38081 index aa1debf..9297a16 100644
38082 --- a/drivers/tty/synclink_gt.c
38083 +++ b/drivers/tty/synclink_gt.c
38084 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38085 tty->driver_data = info;
38086 info->port.tty = tty;
38087
38088 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38089 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38090
38091 /* If port is closing, signal caller to try again */
38092 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38093 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38094 mutex_unlock(&info->port.mutex);
38095 goto cleanup;
38096 }
38097 - info->port.count++;
38098 + atomic_inc(&info->port.count);
38099 spin_unlock_irqrestore(&info->netlock, flags);
38100
38101 - if (info->port.count == 1) {
38102 + if (atomic_read(&info->port.count) == 1) {
38103 /* 1st open on this device, init hardware */
38104 retval = startup(info);
38105 if (retval < 0) {
38106 @@ -716,8 +716,8 @@ cleanup:
38107 if (retval) {
38108 if (tty->count == 1)
38109 info->port.tty = NULL; /* tty layer will release tty struct */
38110 - if(info->port.count)
38111 - info->port.count--;
38112 + if(atomic_read(&info->port.count))
38113 + atomic_dec(&info->port.count);
38114 }
38115
38116 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38117 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38118
38119 if (sanity_check(info, tty->name, "close"))
38120 return;
38121 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38122 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38123
38124 if (tty_port_close_start(&info->port, tty, filp) == 0)
38125 goto cleanup;
38126 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38127 tty_port_close_end(&info->port, tty);
38128 info->port.tty = NULL;
38129 cleanup:
38130 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38131 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38132 }
38133
38134 static void hangup(struct tty_struct *tty)
38135 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38136 shutdown(info);
38137
38138 spin_lock_irqsave(&info->port.lock, flags);
38139 - info->port.count = 0;
38140 + atomic_set(&info->port.count, 0);
38141 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38142 info->port.tty = NULL;
38143 spin_unlock_irqrestore(&info->port.lock, flags);
38144 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38145 unsigned short new_crctype;
38146
38147 /* return error if TTY interface open */
38148 - if (info->port.count)
38149 + if (atomic_read(&info->port.count))
38150 return -EBUSY;
38151
38152 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38153 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38154
38155 /* arbitrate between network and tty opens */
38156 spin_lock_irqsave(&info->netlock, flags);
38157 - if (info->port.count != 0 || info->netcount != 0) {
38158 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38159 DBGINFO(("%s hdlc_open busy\n", dev->name));
38160 spin_unlock_irqrestore(&info->netlock, flags);
38161 return -EBUSY;
38162 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38163 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38164
38165 /* return error if TTY interface open */
38166 - if (info->port.count)
38167 + if (atomic_read(&info->port.count))
38168 return -EBUSY;
38169
38170 if (cmd != SIOCWANDEV)
38171 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38172 if (port == NULL)
38173 continue;
38174 spin_lock(&port->lock);
38175 - if ((port->port.count || port->netcount) &&
38176 + if ((atomic_read(&port->port.count) || port->netcount) &&
38177 port->pending_bh && !port->bh_running &&
38178 !port->bh_requested) {
38179 DBGISR(("%s bh queued\n", port->device_name));
38180 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38181 spin_lock_irqsave(&info->lock, flags);
38182 if (!tty_hung_up_p(filp)) {
38183 extra_count = true;
38184 - port->count--;
38185 + atomic_dec(&port->count);
38186 }
38187 spin_unlock_irqrestore(&info->lock, flags);
38188 port->blocked_open++;
38189 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38190 remove_wait_queue(&port->open_wait, &wait);
38191
38192 if (extra_count)
38193 - port->count++;
38194 + atomic_inc(&port->count);
38195 port->blocked_open--;
38196
38197 if (!retval)
38198 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38199 index a3dddc1..8905ab2 100644
38200 --- a/drivers/tty/synclinkmp.c
38201 +++ b/drivers/tty/synclinkmp.c
38202 @@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38203
38204 if (debug_level >= DEBUG_LEVEL_INFO)
38205 printk("%s(%d):%s open(), old ref count = %d\n",
38206 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38207 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38208
38209 /* If port is closing, signal caller to try again */
38210 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38211 @@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38212 spin_unlock_irqrestore(&info->netlock, flags);
38213 goto cleanup;
38214 }
38215 - info->port.count++;
38216 + atomic_inc(&info->port.count);
38217 spin_unlock_irqrestore(&info->netlock, flags);
38218
38219 - if (info->port.count == 1) {
38220 + if (atomic_read(&info->port.count) == 1) {
38221 /* 1st open on this device, init hardware */
38222 retval = startup(info);
38223 if (retval < 0)
38224 @@ -788,8 +788,8 @@ cleanup:
38225 if (retval) {
38226 if (tty->count == 1)
38227 info->port.tty = NULL; /* tty layer will release tty struct */
38228 - if(info->port.count)
38229 - info->port.count--;
38230 + if(atomic_read(&info->port.count))
38231 + atomic_dec(&info->port.count);
38232 }
38233
38234 return retval;
38235 @@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38236
38237 if (debug_level >= DEBUG_LEVEL_INFO)
38238 printk("%s(%d):%s close() entry, count=%d\n",
38239 - __FILE__,__LINE__, info->device_name, info->port.count);
38240 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38241
38242 if (tty_port_close_start(&info->port, tty, filp) == 0)
38243 goto cleanup;
38244 @@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38245 cleanup:
38246 if (debug_level >= DEBUG_LEVEL_INFO)
38247 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38248 - tty->driver->name, info->port.count);
38249 + tty->driver->name, atomic_read(&info->port.count));
38250 }
38251
38252 /* Called by tty_hangup() when a hangup is signaled.
38253 @@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38254 shutdown(info);
38255
38256 spin_lock_irqsave(&info->port.lock, flags);
38257 - info->port.count = 0;
38258 + atomic_set(&info->port.count, 0);
38259 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38260 info->port.tty = NULL;
38261 spin_unlock_irqrestore(&info->port.lock, flags);
38262 @@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38263 unsigned short new_crctype;
38264
38265 /* return error if TTY interface open */
38266 - if (info->port.count)
38267 + if (atomic_read(&info->port.count))
38268 return -EBUSY;
38269
38270 switch (encoding)
38271 @@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38272
38273 /* arbitrate between network and tty opens */
38274 spin_lock_irqsave(&info->netlock, flags);
38275 - if (info->port.count != 0 || info->netcount != 0) {
38276 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38277 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38278 spin_unlock_irqrestore(&info->netlock, flags);
38279 return -EBUSY;
38280 @@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38281 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38282
38283 /* return error if TTY interface open */
38284 - if (info->port.count)
38285 + if (atomic_read(&info->port.count))
38286 return -EBUSY;
38287
38288 if (cmd != SIOCWANDEV)
38289 @@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38290 * do not request bottom half processing if the
38291 * device is not open in a normal mode.
38292 */
38293 - if ( port && (port->port.count || port->netcount) &&
38294 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38295 port->pending_bh && !port->bh_running &&
38296 !port->bh_requested ) {
38297 if ( debug_level >= DEBUG_LEVEL_ISR )
38298 @@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38299
38300 if (debug_level >= DEBUG_LEVEL_INFO)
38301 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38302 - __FILE__,__LINE__, tty->driver->name, port->count );
38303 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38304
38305 spin_lock_irqsave(&info->lock, flags);
38306 if (!tty_hung_up_p(filp)) {
38307 extra_count = true;
38308 - port->count--;
38309 + atomic_dec(&port->count);
38310 }
38311 spin_unlock_irqrestore(&info->lock, flags);
38312 port->blocked_open++;
38313 @@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38314
38315 if (debug_level >= DEBUG_LEVEL_INFO)
38316 printk("%s(%d):%s block_til_ready() count=%d\n",
38317 - __FILE__,__LINE__, tty->driver->name, port->count );
38318 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38319
38320 tty_unlock();
38321 schedule();
38322 @@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38323 remove_wait_queue(&port->open_wait, &wait);
38324
38325 if (extra_count)
38326 - port->count++;
38327 + atomic_inc(&port->count);
38328 port->blocked_open--;
38329
38330 if (debug_level >= DEBUG_LEVEL_INFO)
38331 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38332 - __FILE__,__LINE__, tty->driver->name, port->count );
38333 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38334
38335 if (!retval)
38336 port->flags |= ASYNC_NORMAL_ACTIVE;
38337 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38338 index 05728894..b9d44c6 100644
38339 --- a/drivers/tty/sysrq.c
38340 +++ b/drivers/tty/sysrq.c
38341 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38342 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38343 size_t count, loff_t *ppos)
38344 {
38345 - if (count) {
38346 + if (count && capable(CAP_SYS_ADMIN)) {
38347 char c;
38348
38349 if (get_user(c, buf))
38350 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38351 index b425c79..08a3f06 100644
38352 --- a/drivers/tty/tty_io.c
38353 +++ b/drivers/tty/tty_io.c
38354 @@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38355
38356 void tty_default_fops(struct file_operations *fops)
38357 {
38358 - *fops = tty_fops;
38359 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38360 }
38361
38362 /*
38363 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38364 index 9911eb6..5abe0e1 100644
38365 --- a/drivers/tty/tty_ldisc.c
38366 +++ b/drivers/tty/tty_ldisc.c
38367 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38368 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38369 struct tty_ldisc_ops *ldo = ld->ops;
38370
38371 - ldo->refcount--;
38372 + atomic_dec(&ldo->refcount);
38373 module_put(ldo->owner);
38374 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38375
38376 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38377 spin_lock_irqsave(&tty_ldisc_lock, flags);
38378 tty_ldiscs[disc] = new_ldisc;
38379 new_ldisc->num = disc;
38380 - new_ldisc->refcount = 0;
38381 + atomic_set(&new_ldisc->refcount, 0);
38382 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38383
38384 return ret;
38385 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38386 return -EINVAL;
38387
38388 spin_lock_irqsave(&tty_ldisc_lock, flags);
38389 - if (tty_ldiscs[disc]->refcount)
38390 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38391 ret = -EBUSY;
38392 else
38393 tty_ldiscs[disc] = NULL;
38394 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38395 if (ldops) {
38396 ret = ERR_PTR(-EAGAIN);
38397 if (try_module_get(ldops->owner)) {
38398 - ldops->refcount++;
38399 + atomic_inc(&ldops->refcount);
38400 ret = ldops;
38401 }
38402 }
38403 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38404 unsigned long flags;
38405
38406 spin_lock_irqsave(&tty_ldisc_lock, flags);
38407 - ldops->refcount--;
38408 + atomic_dec(&ldops->refcount);
38409 module_put(ldops->owner);
38410 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38411 }
38412 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38413 index bf6e238..d401c04 100644
38414 --- a/drivers/tty/tty_port.c
38415 +++ b/drivers/tty/tty_port.c
38416 @@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38417 unsigned long flags;
38418
38419 spin_lock_irqsave(&port->lock, flags);
38420 - port->count = 0;
38421 + atomic_set(&port->count, 0);
38422 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38423 if (port->tty) {
38424 set_bit(TTY_IO_ERROR, &port->tty->flags);
38425 @@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38426 /* The port lock protects the port counts */
38427 spin_lock_irqsave(&port->lock, flags);
38428 if (!tty_hung_up_p(filp))
38429 - port->count--;
38430 + atomic_dec(&port->count);
38431 port->blocked_open++;
38432 spin_unlock_irqrestore(&port->lock, flags);
38433
38434 @@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38435 we must not mess that up further */
38436 spin_lock_irqsave(&port->lock, flags);
38437 if (!tty_hung_up_p(filp))
38438 - port->count++;
38439 + atomic_inc(&port->count);
38440 port->blocked_open--;
38441 if (retval == 0)
38442 port->flags |= ASYNC_NORMAL_ACTIVE;
38443 @@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38444 return 0;
38445 }
38446
38447 - if (tty->count == 1 && port->count != 1) {
38448 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
38449 printk(KERN_WARNING
38450 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38451 - port->count);
38452 - port->count = 1;
38453 + atomic_read(&port->count));
38454 + atomic_set(&port->count, 1);
38455 }
38456 - if (--port->count < 0) {
38457 + if (atomic_dec_return(&port->count) < 0) {
38458 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38459 - port->count);
38460 - port->count = 0;
38461 + atomic_read(&port->count));
38462 + atomic_set(&port->count, 0);
38463 }
38464
38465 - if (port->count) {
38466 + if (atomic_read(&port->count)) {
38467 spin_unlock_irqrestore(&port->lock, flags);
38468 if (port->ops->drop)
38469 port->ops->drop(port);
38470 @@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
38471 {
38472 spin_lock_irq(&port->lock);
38473 if (!tty_hung_up_p(filp))
38474 - ++port->count;
38475 + atomic_inc(&port->count);
38476 spin_unlock_irq(&port->lock);
38477 tty_port_tty_set(port, tty);
38478
38479 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38480 index 48cc6f2..85584dd 100644
38481 --- a/drivers/tty/vt/keyboard.c
38482 +++ b/drivers/tty/vt/keyboard.c
38483 @@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38484 kbd->kbdmode == VC_OFF) &&
38485 value != KVAL(K_SAK))
38486 return; /* SAK is allowed even in raw mode */
38487 +
38488 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38489 + {
38490 + void *func = fn_handler[value];
38491 + if (func == fn_show_state || func == fn_show_ptregs ||
38492 + func == fn_show_mem)
38493 + return;
38494 + }
38495 +#endif
38496 +
38497 fn_handler[value](vc);
38498 }
38499
38500 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38501 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38502 return -EFAULT;
38503
38504 - if (!capable(CAP_SYS_TTY_CONFIG))
38505 - perm = 0;
38506 -
38507 switch (cmd) {
38508 case KDGKBENT:
38509 /* Ensure another thread doesn't free it under us */
38510 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38511 spin_unlock_irqrestore(&kbd_event_lock, flags);
38512 return put_user(val, &user_kbe->kb_value);
38513 case KDSKBENT:
38514 + if (!capable(CAP_SYS_TTY_CONFIG))
38515 + perm = 0;
38516 +
38517 if (!perm)
38518 return -EPERM;
38519 if (!i && v == K_NOSUCHMAP) {
38520 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38521 int i, j, k;
38522 int ret;
38523
38524 - if (!capable(CAP_SYS_TTY_CONFIG))
38525 - perm = 0;
38526 -
38527 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38528 if (!kbs) {
38529 ret = -ENOMEM;
38530 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38531 kfree(kbs);
38532 return ((p && *p) ? -EOVERFLOW : 0);
38533 case KDSKBSENT:
38534 + if (!capable(CAP_SYS_TTY_CONFIG))
38535 + perm = 0;
38536 +
38537 if (!perm) {
38538 ret = -EPERM;
38539 goto reterr;
38540 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38541 index a783d53..cb30d94 100644
38542 --- a/drivers/uio/uio.c
38543 +++ b/drivers/uio/uio.c
38544 @@ -25,6 +25,7 @@
38545 #include <linux/kobject.h>
38546 #include <linux/cdev.h>
38547 #include <linux/uio_driver.h>
38548 +#include <asm/local.h>
38549
38550 #define UIO_MAX_DEVICES (1U << MINORBITS)
38551
38552 @@ -32,10 +33,10 @@ struct uio_device {
38553 struct module *owner;
38554 struct device *dev;
38555 int minor;
38556 - atomic_t event;
38557 + atomic_unchecked_t event;
38558 struct fasync_struct *async_queue;
38559 wait_queue_head_t wait;
38560 - int vma_count;
38561 + local_t vma_count;
38562 struct uio_info *info;
38563 struct kobject *map_dir;
38564 struct kobject *portio_dir;
38565 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38566 struct device_attribute *attr, char *buf)
38567 {
38568 struct uio_device *idev = dev_get_drvdata(dev);
38569 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38570 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38571 }
38572
38573 static struct device_attribute uio_class_attributes[] = {
38574 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38575 {
38576 struct uio_device *idev = info->uio_dev;
38577
38578 - atomic_inc(&idev->event);
38579 + atomic_inc_unchecked(&idev->event);
38580 wake_up_interruptible(&idev->wait);
38581 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38582 }
38583 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38584 }
38585
38586 listener->dev = idev;
38587 - listener->event_count = atomic_read(&idev->event);
38588 + listener->event_count = atomic_read_unchecked(&idev->event);
38589 filep->private_data = listener;
38590
38591 if (idev->info->open) {
38592 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38593 return -EIO;
38594
38595 poll_wait(filep, &idev->wait, wait);
38596 - if (listener->event_count != atomic_read(&idev->event))
38597 + if (listener->event_count != atomic_read_unchecked(&idev->event))
38598 return POLLIN | POLLRDNORM;
38599 return 0;
38600 }
38601 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38602 do {
38603 set_current_state(TASK_INTERRUPTIBLE);
38604
38605 - event_count = atomic_read(&idev->event);
38606 + event_count = atomic_read_unchecked(&idev->event);
38607 if (event_count != listener->event_count) {
38608 if (copy_to_user(buf, &event_count, count))
38609 retval = -EFAULT;
38610 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38611 static void uio_vma_open(struct vm_area_struct *vma)
38612 {
38613 struct uio_device *idev = vma->vm_private_data;
38614 - idev->vma_count++;
38615 + local_inc(&idev->vma_count);
38616 }
38617
38618 static void uio_vma_close(struct vm_area_struct *vma)
38619 {
38620 struct uio_device *idev = vma->vm_private_data;
38621 - idev->vma_count--;
38622 + local_dec(&idev->vma_count);
38623 }
38624
38625 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38626 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38627 idev->owner = owner;
38628 idev->info = info;
38629 init_waitqueue_head(&idev->wait);
38630 - atomic_set(&idev->event, 0);
38631 + atomic_set_unchecked(&idev->event, 0);
38632
38633 ret = uio_get_minor(idev);
38634 if (ret)
38635 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38636 index b7eb86a..36d28af 100644
38637 --- a/drivers/usb/atm/cxacru.c
38638 +++ b/drivers/usb/atm/cxacru.c
38639 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38640 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38641 if (ret < 2)
38642 return -EINVAL;
38643 - if (index < 0 || index > 0x7f)
38644 + if (index > 0x7f)
38645 return -EINVAL;
38646 pos += tmp;
38647
38648 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38649 index ee62b35..b663594 100644
38650 --- a/drivers/usb/atm/usbatm.c
38651 +++ b/drivers/usb/atm/usbatm.c
38652 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38653 if (printk_ratelimit())
38654 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38655 __func__, vpi, vci);
38656 - atomic_inc(&vcc->stats->rx_err);
38657 + atomic_inc_unchecked(&vcc->stats->rx_err);
38658 return;
38659 }
38660
38661 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38662 if (length > ATM_MAX_AAL5_PDU) {
38663 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38664 __func__, length, vcc);
38665 - atomic_inc(&vcc->stats->rx_err);
38666 + atomic_inc_unchecked(&vcc->stats->rx_err);
38667 goto out;
38668 }
38669
38670 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38671 if (sarb->len < pdu_length) {
38672 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38673 __func__, pdu_length, sarb->len, vcc);
38674 - atomic_inc(&vcc->stats->rx_err);
38675 + atomic_inc_unchecked(&vcc->stats->rx_err);
38676 goto out;
38677 }
38678
38679 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38680 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38681 __func__, vcc);
38682 - atomic_inc(&vcc->stats->rx_err);
38683 + atomic_inc_unchecked(&vcc->stats->rx_err);
38684 goto out;
38685 }
38686
38687 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38688 if (printk_ratelimit())
38689 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38690 __func__, length);
38691 - atomic_inc(&vcc->stats->rx_drop);
38692 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38693 goto out;
38694 }
38695
38696 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38697
38698 vcc->push(vcc, skb);
38699
38700 - atomic_inc(&vcc->stats->rx);
38701 + atomic_inc_unchecked(&vcc->stats->rx);
38702 out:
38703 skb_trim(sarb, 0);
38704 }
38705 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38706 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38707
38708 usbatm_pop(vcc, skb);
38709 - atomic_inc(&vcc->stats->tx);
38710 + atomic_inc_unchecked(&vcc->stats->tx);
38711
38712 skb = skb_dequeue(&instance->sndqueue);
38713 }
38714 @@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38715 if (!left--)
38716 return sprintf(page,
38717 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38718 - atomic_read(&atm_dev->stats.aal5.tx),
38719 - atomic_read(&atm_dev->stats.aal5.tx_err),
38720 - atomic_read(&atm_dev->stats.aal5.rx),
38721 - atomic_read(&atm_dev->stats.aal5.rx_err),
38722 - atomic_read(&atm_dev->stats.aal5.rx_drop));
38723 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38724 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38725 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38726 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38727 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38728
38729 if (!left--) {
38730 if (instance->disconnected)
38731 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38732 index d956965..4179a77 100644
38733 --- a/drivers/usb/core/devices.c
38734 +++ b/drivers/usb/core/devices.c
38735 @@ -126,7 +126,7 @@ static const char format_endpt[] =
38736 * time it gets called.
38737 */
38738 static struct device_connect_event {
38739 - atomic_t count;
38740 + atomic_unchecked_t count;
38741 wait_queue_head_t wait;
38742 } device_event = {
38743 .count = ATOMIC_INIT(1),
38744 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38745
38746 void usbfs_conn_disc_event(void)
38747 {
38748 - atomic_add(2, &device_event.count);
38749 + atomic_add_unchecked(2, &device_event.count);
38750 wake_up(&device_event.wait);
38751 }
38752
38753 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38754
38755 poll_wait(file, &device_event.wait, wait);
38756
38757 - event_count = atomic_read(&device_event.count);
38758 + event_count = atomic_read_unchecked(&device_event.count);
38759 if (file->f_version != event_count) {
38760 file->f_version = event_count;
38761 return POLLIN | POLLRDNORM;
38762 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38763 index 347bb05..63e1b73 100644
38764 --- a/drivers/usb/early/ehci-dbgp.c
38765 +++ b/drivers/usb/early/ehci-dbgp.c
38766 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38767
38768 #ifdef CONFIG_KGDB
38769 static struct kgdb_io kgdbdbgp_io_ops;
38770 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38771 +static struct kgdb_io kgdbdbgp_io_ops_console;
38772 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38773 #else
38774 #define dbgp_kgdb_mode (0)
38775 #endif
38776 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38777 .write_char = kgdbdbgp_write_char,
38778 };
38779
38780 +static struct kgdb_io kgdbdbgp_io_ops_console = {
38781 + .name = "kgdbdbgp",
38782 + .read_char = kgdbdbgp_read_char,
38783 + .write_char = kgdbdbgp_write_char,
38784 + .is_console = 1
38785 +};
38786 +
38787 static int kgdbdbgp_wait_time;
38788
38789 static int __init kgdbdbgp_parse_config(char *str)
38790 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38791 ptr++;
38792 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38793 }
38794 - kgdb_register_io_module(&kgdbdbgp_io_ops);
38795 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38796 + if (early_dbgp_console.index != -1)
38797 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38798 + else
38799 + kgdb_register_io_module(&kgdbdbgp_io_ops);
38800
38801 return 0;
38802 }
38803 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
38804 index 5b3f5ff..6e00893 100644
38805 --- a/drivers/usb/gadget/u_serial.c
38806 +++ b/drivers/usb/gadget/u_serial.c
38807 @@ -731,9 +731,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38808 spin_lock_irq(&port->port_lock);
38809
38810 /* already open? Great. */
38811 - if (port->port.count) {
38812 + if (atomic_read(&port->port.count)) {
38813 status = 0;
38814 - port->port.count++;
38815 + atomic_inc(&port->port.count);
38816
38817 /* currently opening/closing? wait ... */
38818 } else if (port->openclose) {
38819 @@ -792,7 +792,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38820 tty->driver_data = port;
38821 port->port.tty = tty;
38822
38823 - port->port.count = 1;
38824 + atomic_set(&port->port.count, 1);
38825 port->openclose = false;
38826
38827 /* if connected, start the I/O stream */
38828 @@ -834,11 +834,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38829
38830 spin_lock_irq(&port->port_lock);
38831
38832 - if (port->port.count != 1) {
38833 - if (port->port.count == 0)
38834 + if (atomic_read(&port->port.count) != 1) {
38835 + if (atomic_read(&port->port.count) == 0)
38836 WARN_ON(1);
38837 else
38838 - --port->port.count;
38839 + atomic_dec(&port->port.count);
38840 goto exit;
38841 }
38842
38843 @@ -848,7 +848,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38844 * and sleep if necessary
38845 */
38846 port->openclose = true;
38847 - port->port.count = 0;
38848 + atomic_set(&port->port.count, 0);
38849
38850 gser = port->port_usb;
38851 if (gser && gser->disconnect)
38852 @@ -1152,7 +1152,7 @@ static int gs_closed(struct gs_port *port)
38853 int cond;
38854
38855 spin_lock_irq(&port->port_lock);
38856 - cond = (port->port.count == 0) && !port->openclose;
38857 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
38858 spin_unlock_irq(&port->port_lock);
38859 return cond;
38860 }
38861 @@ -1265,7 +1265,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
38862 /* if it's already open, start I/O ... and notify the serial
38863 * protocol about open/close status (connect/disconnect).
38864 */
38865 - if (port->port.count) {
38866 + if (atomic_read(&port->port.count)) {
38867 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
38868 gs_start_io(port);
38869 if (gser->connect)
38870 @@ -1312,7 +1312,7 @@ void gserial_disconnect(struct gserial *gser)
38871
38872 port->port_usb = NULL;
38873 gser->ioport = NULL;
38874 - if (port->port.count > 0 || port->openclose) {
38875 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
38876 wake_up_interruptible(&port->drain_wait);
38877 if (port->port.tty)
38878 tty_hangup(port->port.tty);
38879 @@ -1328,7 +1328,7 @@ void gserial_disconnect(struct gserial *gser)
38880
38881 /* finally, free any unused/unusable I/O buffers */
38882 spin_lock_irqsave(&port->port_lock, flags);
38883 - if (port->port.count == 0 && !port->openclose)
38884 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
38885 gs_buf_free(&port->port_write_buf);
38886 gs_free_requests(gser->out, &port->read_pool, NULL);
38887 gs_free_requests(gser->out, &port->read_queue, NULL);
38888 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
38889 index b9cca6d..75c75df 100644
38890 --- a/drivers/usb/serial/console.c
38891 +++ b/drivers/usb/serial/console.c
38892 @@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
38893
38894 info->port = port;
38895
38896 - ++port->port.count;
38897 + atomic_inc(&port->port.count);
38898 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
38899 if (serial->type->set_termios) {
38900 /*
38901 @@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
38902 }
38903 /* Now that any required fake tty operations are completed restore
38904 * the tty port count */
38905 - --port->port.count;
38906 + atomic_dec(&port->port.count);
38907 /* The console is special in terms of closing the device so
38908 * indicate this port is now acting as a system console. */
38909 port->port.console = 1;
38910 @@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
38911 free_tty:
38912 kfree(tty);
38913 reset_open_count:
38914 - port->port.count = 0;
38915 + atomic_set(&port->port.count, 0);
38916 usb_autopm_put_interface(serial->interface);
38917 error_get_interface:
38918 usb_serial_put(serial);
38919 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38920 index d6bea3e..60b250e 100644
38921 --- a/drivers/usb/wusbcore/wa-hc.h
38922 +++ b/drivers/usb/wusbcore/wa-hc.h
38923 @@ -192,7 +192,7 @@ struct wahc {
38924 struct list_head xfer_delayed_list;
38925 spinlock_t xfer_list_lock;
38926 struct work_struct xfer_work;
38927 - atomic_t xfer_id_count;
38928 + atomic_unchecked_t xfer_id_count;
38929 };
38930
38931
38932 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38933 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38934 spin_lock_init(&wa->xfer_list_lock);
38935 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38936 - atomic_set(&wa->xfer_id_count, 1);
38937 + atomic_set_unchecked(&wa->xfer_id_count, 1);
38938 }
38939
38940 /**
38941 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38942 index 57c01ab..8a05959 100644
38943 --- a/drivers/usb/wusbcore/wa-xfer.c
38944 +++ b/drivers/usb/wusbcore/wa-xfer.c
38945 @@ -296,7 +296,7 @@ out:
38946 */
38947 static void wa_xfer_id_init(struct wa_xfer *xfer)
38948 {
38949 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38950 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38951 }
38952
38953 /*
38954 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38955 index 112156f..eb81154 100644
38956 --- a/drivers/vhost/vhost.c
38957 +++ b/drivers/vhost/vhost.c
38958 @@ -635,7 +635,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38959 return 0;
38960 }
38961
38962 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38963 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38964 {
38965 struct file *eventfp, *filep = NULL,
38966 *pollstart = NULL, *pollstop = NULL;
38967 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38968 index b0b2ac3..89a4399 100644
38969 --- a/drivers/video/aty/aty128fb.c
38970 +++ b/drivers/video/aty/aty128fb.c
38971 @@ -148,7 +148,7 @@ enum {
38972 };
38973
38974 /* Must match above enum */
38975 -static const char *r128_family[] __devinitdata = {
38976 +static const char *r128_family[] __devinitconst = {
38977 "AGP",
38978 "PCI",
38979 "PRO AGP",
38980 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38981 index 5c3960d..15cf8fc 100644
38982 --- a/drivers/video/fbcmap.c
38983 +++ b/drivers/video/fbcmap.c
38984 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38985 rc = -ENODEV;
38986 goto out;
38987 }
38988 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38989 - !info->fbops->fb_setcmap)) {
38990 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38991 rc = -EINVAL;
38992 goto out1;
38993 }
38994 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38995 index 0dff12a..2ef47b3 100644
38996 --- a/drivers/video/fbmem.c
38997 +++ b/drivers/video/fbmem.c
38998 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38999 image->dx += image->width + 8;
39000 }
39001 } else if (rotate == FB_ROTATE_UD) {
39002 - for (x = 0; x < num && image->dx >= 0; x++) {
39003 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39004 info->fbops->fb_imageblit(info, image);
39005 image->dx -= image->width + 8;
39006 }
39007 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39008 image->dy += image->height + 8;
39009 }
39010 } else if (rotate == FB_ROTATE_CCW) {
39011 - for (x = 0; x < num && image->dy >= 0; x++) {
39012 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39013 info->fbops->fb_imageblit(info, image);
39014 image->dy -= image->height + 8;
39015 }
39016 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39017 return -EFAULT;
39018 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39019 return -EINVAL;
39020 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39021 + if (con2fb.framebuffer >= FB_MAX)
39022 return -EINVAL;
39023 if (!registered_fb[con2fb.framebuffer])
39024 request_module("fb%d", con2fb.framebuffer);
39025 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39026 index 5a5d092..265c5ed 100644
39027 --- a/drivers/video/geode/gx1fb_core.c
39028 +++ b/drivers/video/geode/gx1fb_core.c
39029 @@ -29,7 +29,7 @@ static int crt_option = 1;
39030 static char panel_option[32] = "";
39031
39032 /* Modes relevant to the GX1 (taken from modedb.c) */
39033 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39034 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39035 /* 640x480-60 VESA */
39036 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39037 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39038 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39039 index 0fad23f..0e9afa4 100644
39040 --- a/drivers/video/gxt4500.c
39041 +++ b/drivers/video/gxt4500.c
39042 @@ -156,7 +156,7 @@ struct gxt4500_par {
39043 static char *mode_option;
39044
39045 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39046 -static const struct fb_videomode defaultmode __devinitdata = {
39047 +static const struct fb_videomode defaultmode __devinitconst = {
39048 .refresh = 60,
39049 .xres = 1280,
39050 .yres = 1024,
39051 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39052 return 0;
39053 }
39054
39055 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39056 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39057 .id = "IBM GXT4500P",
39058 .type = FB_TYPE_PACKED_PIXELS,
39059 .visual = FB_VISUAL_PSEUDOCOLOR,
39060 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39061 index 7672d2e..b56437f 100644
39062 --- a/drivers/video/i810/i810_accel.c
39063 +++ b/drivers/video/i810/i810_accel.c
39064 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39065 }
39066 }
39067 printk("ringbuffer lockup!!!\n");
39068 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39069 i810_report_error(mmio);
39070 par->dev_flags |= LOCKUP;
39071 info->pixmap.scan_align = 1;
39072 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39073 index b83f361..2b05a91 100644
39074 --- a/drivers/video/i810/i810_main.c
39075 +++ b/drivers/video/i810/i810_main.c
39076 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39077 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39078
39079 /* PCI */
39080 -static const char *i810_pci_list[] __devinitdata = {
39081 +static const char *i810_pci_list[] __devinitconst = {
39082 "Intel(R) 810 Framebuffer Device" ,
39083 "Intel(R) 810-DC100 Framebuffer Device" ,
39084 "Intel(R) 810E Framebuffer Device" ,
39085 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39086 index de36693..3c63fc2 100644
39087 --- a/drivers/video/jz4740_fb.c
39088 +++ b/drivers/video/jz4740_fb.c
39089 @@ -136,7 +136,7 @@ struct jzfb {
39090 uint32_t pseudo_palette[16];
39091 };
39092
39093 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39094 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39095 .id = "JZ4740 FB",
39096 .type = FB_TYPE_PACKED_PIXELS,
39097 .visual = FB_VISUAL_TRUECOLOR,
39098 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39099 index 3c14e43..eafa544 100644
39100 --- a/drivers/video/logo/logo_linux_clut224.ppm
39101 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39102 @@ -1,1604 +1,1123 @@
39103 P3
39104 -# Standard 224-color Linux logo
39105 80 80
39106 255
39107 - 0 0 0 0 0 0 0 0 0 0 0 0
39108 - 0 0 0 0 0 0 0 0 0 0 0 0
39109 - 0 0 0 0 0 0 0 0 0 0 0 0
39110 - 0 0 0 0 0 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 - 6 6 6 6 6 6 10 10 10 10 10 10
39117 - 10 10 10 6 6 6 6 6 6 6 6 6
39118 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 10 10 10 14 14 14
39136 - 22 22 22 26 26 26 30 30 30 34 34 34
39137 - 30 30 30 30 30 30 26 26 26 18 18 18
39138 - 14 14 14 10 10 10 6 6 6 0 0 0
39139 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 0
39149 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 14 14 14 26 26 26 42 42 42
39156 - 54 54 54 66 66 66 78 78 78 78 78 78
39157 - 78 78 78 74 74 74 66 66 66 54 54 54
39158 - 42 42 42 26 26 26 18 18 18 10 10 10
39159 - 6 6 6 0 0 0 0 0 0 0 0 0
39160 - 0 0 0 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 1 0 0 0 0 0 0 0 0 0
39169 - 0 0 0 0 0 0 0 0 0 0 0 0
39170 - 0 0 0 0 0 0 0 0 0 0 0 0
39171 - 0 0 0 0 0 0 0 0 0 0 0 0
39172 - 0 0 0 0 0 0 0 0 0 0 0 0
39173 - 0 0 0 0 0 0 0 0 0 0 0 0
39174 - 0 0 0 0 0 0 0 0 0 10 10 10
39175 - 22 22 22 42 42 42 66 66 66 86 86 86
39176 - 66 66 66 38 38 38 38 38 38 22 22 22
39177 - 26 26 26 34 34 34 54 54 54 66 66 66
39178 - 86 86 86 70 70 70 46 46 46 26 26 26
39179 - 14 14 14 6 6 6 0 0 0 0 0 0
39180 - 0 0 0 0 0 0 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 1 0 0 1 0 0 1 0 0 0
39189 - 0 0 0 0 0 0 0 0 0 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 10 10 10 26 26 26
39195 - 50 50 50 82 82 82 58 58 58 6 6 6
39196 - 2 2 6 2 2 6 2 2 6 2 2 6
39197 - 2 2 6 2 2 6 2 2 6 2 2 6
39198 - 6 6 6 54 54 54 86 86 86 66 66 66
39199 - 38 38 38 18 18 18 6 6 6 0 0 0
39200 - 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
39215 - 78 78 78 34 34 34 2 2 6 2 2 6
39216 - 2 2 6 2 2 6 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 6 6 6 70 70 70
39219 - 78 78 78 46 46 46 22 22 22 6 6 6
39220 - 0 0 0 0 0 0 0 0 0 0 0 0
39221 - 0 0 0 0 0 0 0 0 0 0 0 0
39222 - 0 0 0 0 0 0 0 0 0 0 0 0
39223 - 0 0 0 0 0 0 0 0 0 0 0 0
39224 - 0 0 0 0 0 0 0 0 0 0 0 0
39225 - 0 0 0 0 0 0 0 0 0 0 0 0
39226 - 0 0 0 0 0 0 0 0 0 0 0 0
39227 - 0 0 0 0 0 0 0 0 0 0 0 0
39228 - 0 0 1 0 0 1 0 0 1 0 0 0
39229 - 0 0 0 0 0 0 0 0 0 0 0 0
39230 - 0 0 0 0 0 0 0 0 0 0 0 0
39231 - 0 0 0 0 0 0 0 0 0 0 0 0
39232 - 0 0 0 0 0 0 0 0 0 0 0 0
39233 - 0 0 0 0 0 0 0 0 0 0 0 0
39234 - 6 6 6 18 18 18 42 42 42 82 82 82
39235 - 26 26 26 2 2 6 2 2 6 2 2 6
39236 - 2 2 6 2 2 6 2 2 6 2 2 6
39237 - 2 2 6 2 2 6 2 2 6 14 14 14
39238 - 46 46 46 34 34 34 6 6 6 2 2 6
39239 - 42 42 42 78 78 78 42 42 42 18 18 18
39240 - 6 6 6 0 0 0 0 0 0 0 0 0
39241 - 0 0 0 0 0 0 0 0 0 0 0 0
39242 - 0 0 0 0 0 0 0 0 0 0 0 0
39243 - 0 0 0 0 0 0 0 0 0 0 0 0
39244 - 0 0 0 0 0 0 0 0 0 0 0 0
39245 - 0 0 0 0 0 0 0 0 0 0 0 0
39246 - 0 0 0 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 1 0 0 0 0 0 1 0 0 0
39249 - 0 0 0 0 0 0 0 0 0 0 0 0
39250 - 0 0 0 0 0 0 0 0 0 0 0 0
39251 - 0 0 0 0 0 0 0 0 0 0 0 0
39252 - 0 0 0 0 0 0 0 0 0 0 0 0
39253 - 0 0 0 0 0 0 0 0 0 0 0 0
39254 - 10 10 10 30 30 30 66 66 66 58 58 58
39255 - 2 2 6 2 2 6 2 2 6 2 2 6
39256 - 2 2 6 2 2 6 2 2 6 2 2 6
39257 - 2 2 6 2 2 6 2 2 6 26 26 26
39258 - 86 86 86 101 101 101 46 46 46 10 10 10
39259 - 2 2 6 58 58 58 70 70 70 34 34 34
39260 - 10 10 10 0 0 0 0 0 0 0 0 0
39261 - 0 0 0 0 0 0 0 0 0 0 0 0
39262 - 0 0 0 0 0 0 0 0 0 0 0 0
39263 - 0 0 0 0 0 0 0 0 0 0 0 0
39264 - 0 0 0 0 0 0 0 0 0 0 0 0
39265 - 0 0 0 0 0 0 0 0 0 0 0 0
39266 - 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 1 0 0 1 0 0 1 0 0 0
39269 - 0 0 0 0 0 0 0 0 0 0 0 0
39270 - 0 0 0 0 0 0 0 0 0 0 0 0
39271 - 0 0 0 0 0 0 0 0 0 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 - 14 14 14 42 42 42 86 86 86 10 10 10
39275 - 2 2 6 2 2 6 2 2 6 2 2 6
39276 - 2 2 6 2 2 6 2 2 6 2 2 6
39277 - 2 2 6 2 2 6 2 2 6 30 30 30
39278 - 94 94 94 94 94 94 58 58 58 26 26 26
39279 - 2 2 6 6 6 6 78 78 78 54 54 54
39280 - 22 22 22 6 6 6 0 0 0 0 0 0
39281 - 0 0 0 0 0 0 0 0 0 0 0 0
39282 - 0 0 0 0 0 0 0 0 0 0 0 0
39283 - 0 0 0 0 0 0 0 0 0 0 0 0
39284 - 0 0 0 0 0 0 0 0 0 0 0 0
39285 - 0 0 0 0 0 0 0 0 0 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 6 6 6
39294 - 22 22 22 62 62 62 62 62 62 2 2 6
39295 - 2 2 6 2 2 6 2 2 6 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 26 26 26
39298 - 54 54 54 38 38 38 18 18 18 10 10 10
39299 - 2 2 6 2 2 6 34 34 34 82 82 82
39300 - 38 38 38 14 14 14 0 0 0 0 0 0
39301 - 0 0 0 0 0 0 0 0 0 0 0 0
39302 - 0 0 0 0 0 0 0 0 0 0 0 0
39303 - 0 0 0 0 0 0 0 0 0 0 0 0
39304 - 0 0 0 0 0 0 0 0 0 0 0 0
39305 - 0 0 0 0 0 0 0 0 0 0 0 0
39306 - 0 0 0 0 0 0 0 0 0 0 0 0
39307 - 0 0 0 0 0 0 0 0 0 0 0 0
39308 - 0 0 0 0 0 1 0 0 1 0 0 0
39309 - 0 0 0 0 0 0 0 0 0 0 0 0
39310 - 0 0 0 0 0 0 0 0 0 0 0 0
39311 - 0 0 0 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 6 6 6
39314 - 30 30 30 78 78 78 30 30 30 2 2 6
39315 - 2 2 6 2 2 6 2 2 6 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 10 10 10
39318 - 10 10 10 2 2 6 2 2 6 2 2 6
39319 - 2 2 6 2 2 6 2 2 6 78 78 78
39320 - 50 50 50 18 18 18 6 6 6 0 0 0
39321 - 0 0 0 0 0 0 0 0 0 0 0 0
39322 - 0 0 0 0 0 0 0 0 0 0 0 0
39323 - 0 0 0 0 0 0 0 0 0 0 0 0
39324 - 0 0 0 0 0 0 0 0 0 0 0 0
39325 - 0 0 0 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 1 0 0 0 0 0 0 0 0 0
39329 - 0 0 0 0 0 0 0 0 0 0 0 0
39330 - 0 0 0 0 0 0 0 0 0 0 0 0
39331 - 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 10 10 10
39334 - 38 38 38 86 86 86 14 14 14 2 2 6
39335 - 2 2 6 2 2 6 2 2 6 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 54 54 54
39340 - 66 66 66 26 26 26 6 6 6 0 0 0
39341 - 0 0 0 0 0 0 0 0 0 0 0 0
39342 - 0 0 0 0 0 0 0 0 0 0 0 0
39343 - 0 0 0 0 0 0 0 0 0 0 0 0
39344 - 0 0 0 0 0 0 0 0 0 0 0 0
39345 - 0 0 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 1 0 0 1 0 0 0
39349 - 0 0 0 0 0 0 0 0 0 0 0 0
39350 - 0 0 0 0 0 0 0 0 0 0 0 0
39351 - 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 14 14 14
39354 - 42 42 42 82 82 82 2 2 6 2 2 6
39355 - 2 2 6 6 6 6 10 10 10 2 2 6
39356 - 2 2 6 2 2 6 2 2 6 2 2 6
39357 - 2 2 6 2 2 6 2 2 6 6 6 6
39358 - 14 14 14 10 10 10 2 2 6 2 2 6
39359 - 2 2 6 2 2 6 2 2 6 18 18 18
39360 - 82 82 82 34 34 34 10 10 10 0 0 0
39361 - 0 0 0 0 0 0 0 0 0 0 0 0
39362 - 0 0 0 0 0 0 0 0 0 0 0 0
39363 - 0 0 0 0 0 0 0 0 0 0 0 0
39364 - 0 0 0 0 0 0 0 0 0 0 0 0
39365 - 0 0 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 1 0 0 0 0 0 0 0 0 0
39369 - 0 0 0 0 0 0 0 0 0 0 0 0
39370 - 0 0 0 0 0 0 0 0 0 0 0 0
39371 - 0 0 0 0 0 0 0 0 0 0 0 0
39372 - 0 0 0 0 0 0 0 0 0 0 0 0
39373 - 0 0 0 0 0 0 0 0 0 14 14 14
39374 - 46 46 46 86 86 86 2 2 6 2 2 6
39375 - 6 6 6 6 6 6 22 22 22 34 34 34
39376 - 6 6 6 2 2 6 2 2 6 2 2 6
39377 - 2 2 6 2 2 6 18 18 18 34 34 34
39378 - 10 10 10 50 50 50 22 22 22 2 2 6
39379 - 2 2 6 2 2 6 2 2 6 10 10 10
39380 - 86 86 86 42 42 42 14 14 14 0 0 0
39381 - 0 0 0 0 0 0 0 0 0 0 0 0
39382 - 0 0 0 0 0 0 0 0 0 0 0 0
39383 - 0 0 0 0 0 0 0 0 0 0 0 0
39384 - 0 0 0 0 0 0 0 0 0 0 0 0
39385 - 0 0 0 0 0 0 0 0 0 0 0 0
39386 - 0 0 0 0 0 0 0 0 0 0 0 0
39387 - 0 0 0 0 0 0 0 0 0 0 0 0
39388 - 0 0 1 0 0 1 0 0 1 0 0 0
39389 - 0 0 0 0 0 0 0 0 0 0 0 0
39390 - 0 0 0 0 0 0 0 0 0 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 14 14 14
39394 - 46 46 46 86 86 86 2 2 6 2 2 6
39395 - 38 38 38 116 116 116 94 94 94 22 22 22
39396 - 22 22 22 2 2 6 2 2 6 2 2 6
39397 - 14 14 14 86 86 86 138 138 138 162 162 162
39398 -154 154 154 38 38 38 26 26 26 6 6 6
39399 - 2 2 6 2 2 6 2 2 6 2 2 6
39400 - 86 86 86 46 46 46 14 14 14 0 0 0
39401 - 0 0 0 0 0 0 0 0 0 0 0 0
39402 - 0 0 0 0 0 0 0 0 0 0 0 0
39403 - 0 0 0 0 0 0 0 0 0 0 0 0
39404 - 0 0 0 0 0 0 0 0 0 0 0 0
39405 - 0 0 0 0 0 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 14 14 14
39414 - 46 46 46 86 86 86 2 2 6 14 14 14
39415 -134 134 134 198 198 198 195 195 195 116 116 116
39416 - 10 10 10 2 2 6 2 2 6 6 6 6
39417 -101 98 89 187 187 187 210 210 210 218 218 218
39418 -214 214 214 134 134 134 14 14 14 6 6 6
39419 - 2 2 6 2 2 6 2 2 6 2 2 6
39420 - 86 86 86 50 50 50 18 18 18 6 6 6
39421 - 0 0 0 0 0 0 0 0 0 0 0 0
39422 - 0 0 0 0 0 0 0 0 0 0 0 0
39423 - 0 0 0 0 0 0 0 0 0 0 0 0
39424 - 0 0 0 0 0 0 0 0 0 0 0 0
39425 - 0 0 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 1 0 0 0
39428 - 0 0 1 0 0 1 0 0 1 0 0 0
39429 - 0 0 0 0 0 0 0 0 0 0 0 0
39430 - 0 0 0 0 0 0 0 0 0 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 14 14 14
39434 - 46 46 46 86 86 86 2 2 6 54 54 54
39435 -218 218 218 195 195 195 226 226 226 246 246 246
39436 - 58 58 58 2 2 6 2 2 6 30 30 30
39437 -210 210 210 253 253 253 174 174 174 123 123 123
39438 -221 221 221 234 234 234 74 74 74 2 2 6
39439 - 2 2 6 2 2 6 2 2 6 2 2 6
39440 - 70 70 70 58 58 58 22 22 22 6 6 6
39441 - 0 0 0 0 0 0 0 0 0 0 0 0
39442 - 0 0 0 0 0 0 0 0 0 0 0 0
39443 - 0 0 0 0 0 0 0 0 0 0 0 0
39444 - 0 0 0 0 0 0 0 0 0 0 0 0
39445 - 0 0 0 0 0 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 14 14 14
39454 - 46 46 46 82 82 82 2 2 6 106 106 106
39455 -170 170 170 26 26 26 86 86 86 226 226 226
39456 -123 123 123 10 10 10 14 14 14 46 46 46
39457 -231 231 231 190 190 190 6 6 6 70 70 70
39458 - 90 90 90 238 238 238 158 158 158 2 2 6
39459 - 2 2 6 2 2 6 2 2 6 2 2 6
39460 - 70 70 70 58 58 58 22 22 22 6 6 6
39461 - 0 0 0 0 0 0 0 0 0 0 0 0
39462 - 0 0 0 0 0 0 0 0 0 0 0 0
39463 - 0 0 0 0 0 0 0 0 0 0 0 0
39464 - 0 0 0 0 0 0 0 0 0 0 0 0
39465 - 0 0 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 1 0 0 0
39468 - 0 0 1 0 0 1 0 0 1 0 0 0
39469 - 0 0 0 0 0 0 0 0 0 0 0 0
39470 - 0 0 0 0 0 0 0 0 0 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 14 14 14
39474 - 42 42 42 86 86 86 6 6 6 116 116 116
39475 -106 106 106 6 6 6 70 70 70 149 149 149
39476 -128 128 128 18 18 18 38 38 38 54 54 54
39477 -221 221 221 106 106 106 2 2 6 14 14 14
39478 - 46 46 46 190 190 190 198 198 198 2 2 6
39479 - 2 2 6 2 2 6 2 2 6 2 2 6
39480 - 74 74 74 62 62 62 22 22 22 6 6 6
39481 - 0 0 0 0 0 0 0 0 0 0 0 0
39482 - 0 0 0 0 0 0 0 0 0 0 0 0
39483 - 0 0 0 0 0 0 0 0 0 0 0 0
39484 - 0 0 0 0 0 0 0 0 0 0 0 0
39485 - 0 0 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 1 0 0 0
39488 - 0 0 1 0 0 0 0 0 1 0 0 0
39489 - 0 0 0 0 0 0 0 0 0 0 0 0
39490 - 0 0 0 0 0 0 0 0 0 0 0 0
39491 - 0 0 0 0 0 0 0 0 0 0 0 0
39492 - 0 0 0 0 0 0 0 0 0 0 0 0
39493 - 0 0 0 0 0 0 0 0 0 14 14 14
39494 - 42 42 42 94 94 94 14 14 14 101 101 101
39495 -128 128 128 2 2 6 18 18 18 116 116 116
39496 -118 98 46 121 92 8 121 92 8 98 78 10
39497 -162 162 162 106 106 106 2 2 6 2 2 6
39498 - 2 2 6 195 195 195 195 195 195 6 6 6
39499 - 2 2 6 2 2 6 2 2 6 2 2 6
39500 - 74 74 74 62 62 62 22 22 22 6 6 6
39501 - 0 0 0 0 0 0 0 0 0 0 0 0
39502 - 0 0 0 0 0 0 0 0 0 0 0 0
39503 - 0 0 0 0 0 0 0 0 0 0 0 0
39504 - 0 0 0 0 0 0 0 0 0 0 0 0
39505 - 0 0 0 0 0 0 0 0 0 0 0 0
39506 - 0 0 0 0 0 0 0 0 0 0 0 0
39507 - 0 0 0 0 0 0 0 0 1 0 0 1
39508 - 0 0 1 0 0 0 0 0 1 0 0 0
39509 - 0 0 0 0 0 0 0 0 0 0 0 0
39510 - 0 0 0 0 0 0 0 0 0 0 0 0
39511 - 0 0 0 0 0 0 0 0 0 0 0 0
39512 - 0 0 0 0 0 0 0 0 0 0 0 0
39513 - 0 0 0 0 0 0 0 0 0 10 10 10
39514 - 38 38 38 90 90 90 14 14 14 58 58 58
39515 -210 210 210 26 26 26 54 38 6 154 114 10
39516 -226 170 11 236 186 11 225 175 15 184 144 12
39517 -215 174 15 175 146 61 37 26 9 2 2 6
39518 - 70 70 70 246 246 246 138 138 138 2 2 6
39519 - 2 2 6 2 2 6 2 2 6 2 2 6
39520 - 70 70 70 66 66 66 26 26 26 6 6 6
39521 - 0 0 0 0 0 0 0 0 0 0 0 0
39522 - 0 0 0 0 0 0 0 0 0 0 0 0
39523 - 0 0 0 0 0 0 0 0 0 0 0 0
39524 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39534 - 38 38 38 86 86 86 14 14 14 10 10 10
39535 -195 195 195 188 164 115 192 133 9 225 175 15
39536 -239 182 13 234 190 10 232 195 16 232 200 30
39537 -245 207 45 241 208 19 232 195 16 184 144 12
39538 -218 194 134 211 206 186 42 42 42 2 2 6
39539 - 2 2 6 2 2 6 2 2 6 2 2 6
39540 - 50 50 50 74 74 74 30 30 30 6 6 6
39541 - 0 0 0 0 0 0 0 0 0 0 0 0
39542 - 0 0 0 0 0 0 0 0 0 0 0 0
39543 - 0 0 0 0 0 0 0 0 0 0 0 0
39544 - 0 0 0 0 0 0 0 0 0 0 0 0
39545 - 0 0 0 0 0 0 0 0 0 0 0 0
39546 - 0 0 0 0 0 0 0 0 0 0 0 0
39547 - 0 0 0 0 0 0 0 0 0 0 0 0
39548 - 0 0 0 0 0 0 0 0 0 0 0 0
39549 - 0 0 0 0 0 0 0 0 0 0 0 0
39550 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39554 - 34 34 34 86 86 86 14 14 14 2 2 6
39555 -121 87 25 192 133 9 219 162 10 239 182 13
39556 -236 186 11 232 195 16 241 208 19 244 214 54
39557 -246 218 60 246 218 38 246 215 20 241 208 19
39558 -241 208 19 226 184 13 121 87 25 2 2 6
39559 - 2 2 6 2 2 6 2 2 6 2 2 6
39560 - 50 50 50 82 82 82 34 34 34 10 10 10
39561 - 0 0 0 0 0 0 0 0 0 0 0 0
39562 - 0 0 0 0 0 0 0 0 0 0 0 0
39563 - 0 0 0 0 0 0 0 0 0 0 0 0
39564 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39574 - 34 34 34 82 82 82 30 30 30 61 42 6
39575 -180 123 7 206 145 10 230 174 11 239 182 13
39576 -234 190 10 238 202 15 241 208 19 246 218 74
39577 -246 218 38 246 215 20 246 215 20 246 215 20
39578 -226 184 13 215 174 15 184 144 12 6 6 6
39579 - 2 2 6 2 2 6 2 2 6 2 2 6
39580 - 26 26 26 94 94 94 42 42 42 14 14 14
39581 - 0 0 0 0 0 0 0 0 0 0 0 0
39582 - 0 0 0 0 0 0 0 0 0 0 0 0
39583 - 0 0 0 0 0 0 0 0 0 0 0 0
39584 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39594 - 30 30 30 78 78 78 50 50 50 104 69 6
39595 -192 133 9 216 158 10 236 178 12 236 186 11
39596 -232 195 16 241 208 19 244 214 54 245 215 43
39597 -246 215 20 246 215 20 241 208 19 198 155 10
39598 -200 144 11 216 158 10 156 118 10 2 2 6
39599 - 2 2 6 2 2 6 2 2 6 2 2 6
39600 - 6 6 6 90 90 90 54 54 54 18 18 18
39601 - 6 6 6 0 0 0 0 0 0 0 0 0
39602 - 0 0 0 0 0 0 0 0 0 0 0 0
39603 - 0 0 0 0 0 0 0 0 0 0 0 0
39604 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39614 - 30 30 30 78 78 78 46 46 46 22 22 22
39615 -137 92 6 210 162 10 239 182 13 238 190 10
39616 -238 202 15 241 208 19 246 215 20 246 215 20
39617 -241 208 19 203 166 17 185 133 11 210 150 10
39618 -216 158 10 210 150 10 102 78 10 2 2 6
39619 - 6 6 6 54 54 54 14 14 14 2 2 6
39620 - 2 2 6 62 62 62 74 74 74 30 30 30
39621 - 10 10 10 0 0 0 0 0 0 0 0 0
39622 - 0 0 0 0 0 0 0 0 0 0 0 0
39623 - 0 0 0 0 0 0 0 0 0 0 0 0
39624 - 0 0 0 0 0 0 0 0 0 0 0 0
39625 - 0 0 0 0 0 0 0 0 0 0 0 0
39626 - 0 0 0 0 0 0 0 0 0 0 0 0
39627 - 0 0 0 0 0 0 0 0 0 0 0 0
39628 - 0 0 0 0 0 0 0 0 0 0 0 0
39629 - 0 0 0 0 0 0 0 0 0 0 0 0
39630 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39634 - 34 34 34 78 78 78 50 50 50 6 6 6
39635 - 94 70 30 139 102 15 190 146 13 226 184 13
39636 -232 200 30 232 195 16 215 174 15 190 146 13
39637 -168 122 10 192 133 9 210 150 10 213 154 11
39638 -202 150 34 182 157 106 101 98 89 2 2 6
39639 - 2 2 6 78 78 78 116 116 116 58 58 58
39640 - 2 2 6 22 22 22 90 90 90 46 46 46
39641 - 18 18 18 6 6 6 0 0 0 0 0 0
39642 - 0 0 0 0 0 0 0 0 0 0 0 0
39643 - 0 0 0 0 0 0 0 0 0 0 0 0
39644 - 0 0 0 0 0 0 0 0 0 0 0 0
39645 - 0 0 0 0 0 0 0 0 0 0 0 0
39646 - 0 0 0 0 0 0 0 0 0 0 0 0
39647 - 0 0 0 0 0 0 0 0 0 0 0 0
39648 - 0 0 0 0 0 0 0 0 0 0 0 0
39649 - 0 0 0 0 0 0 0 0 0 0 0 0
39650 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39654 - 38 38 38 86 86 86 50 50 50 6 6 6
39655 -128 128 128 174 154 114 156 107 11 168 122 10
39656 -198 155 10 184 144 12 197 138 11 200 144 11
39657 -206 145 10 206 145 10 197 138 11 188 164 115
39658 -195 195 195 198 198 198 174 174 174 14 14 14
39659 - 2 2 6 22 22 22 116 116 116 116 116 116
39660 - 22 22 22 2 2 6 74 74 74 70 70 70
39661 - 30 30 30 10 10 10 0 0 0 0 0 0
39662 - 0 0 0 0 0 0 0 0 0 0 0 0
39663 - 0 0 0 0 0 0 0 0 0 0 0 0
39664 - 0 0 0 0 0 0 0 0 0 0 0 0
39665 - 0 0 0 0 0 0 0 0 0 0 0 0
39666 - 0 0 0 0 0 0 0 0 0 0 0 0
39667 - 0 0 0 0 0 0 0 0 0 0 0 0
39668 - 0 0 0 0 0 0 0 0 0 0 0 0
39669 - 0 0 0 0 0 0 0 0 0 0 0 0
39670 - 0 0 0 0 0 0 0 0 0 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 6 6 6 18 18 18
39674 - 50 50 50 101 101 101 26 26 26 10 10 10
39675 -138 138 138 190 190 190 174 154 114 156 107 11
39676 -197 138 11 200 144 11 197 138 11 192 133 9
39677 -180 123 7 190 142 34 190 178 144 187 187 187
39678 -202 202 202 221 221 221 214 214 214 66 66 66
39679 - 2 2 6 2 2 6 50 50 50 62 62 62
39680 - 6 6 6 2 2 6 10 10 10 90 90 90
39681 - 50 50 50 18 18 18 6 6 6 0 0 0
39682 - 0 0 0 0 0 0 0 0 0 0 0 0
39683 - 0 0 0 0 0 0 0 0 0 0 0 0
39684 - 0 0 0 0 0 0 0 0 0 0 0 0
39685 - 0 0 0 0 0 0 0 0 0 0 0 0
39686 - 0 0 0 0 0 0 0 0 0 0 0 0
39687 - 0 0 0 0 0 0 0 0 0 0 0 0
39688 - 0 0 0 0 0 0 0 0 0 0 0 0
39689 - 0 0 0 0 0 0 0 0 0 0 0 0
39690 - 0 0 0 0 0 0 0 0 0 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 10 10 10 34 34 34
39694 - 74 74 74 74 74 74 2 2 6 6 6 6
39695 -144 144 144 198 198 198 190 190 190 178 166 146
39696 -154 121 60 156 107 11 156 107 11 168 124 44
39697 -174 154 114 187 187 187 190 190 190 210 210 210
39698 -246 246 246 253 253 253 253 253 253 182 182 182
39699 - 6 6 6 2 2 6 2 2 6 2 2 6
39700 - 2 2 6 2 2 6 2 2 6 62 62 62
39701 - 74 74 74 34 34 34 14 14 14 0 0 0
39702 - 0 0 0 0 0 0 0 0 0 0 0 0
39703 - 0 0 0 0 0 0 0 0 0 0 0 0
39704 - 0 0 0 0 0 0 0 0 0 0 0 0
39705 - 0 0 0 0 0 0 0 0 0 0 0 0
39706 - 0 0 0 0 0 0 0 0 0 0 0 0
39707 - 0 0 0 0 0 0 0 0 0 0 0 0
39708 - 0 0 0 0 0 0 0 0 0 0 0 0
39709 - 0 0 0 0 0 0 0 0 0 0 0 0
39710 - 0 0 0 0 0 0 0 0 0 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 10 10 10 22 22 22 54 54 54
39714 - 94 94 94 18 18 18 2 2 6 46 46 46
39715 -234 234 234 221 221 221 190 190 190 190 190 190
39716 -190 190 190 187 187 187 187 187 187 190 190 190
39717 -190 190 190 195 195 195 214 214 214 242 242 242
39718 -253 253 253 253 253 253 253 253 253 253 253 253
39719 - 82 82 82 2 2 6 2 2 6 2 2 6
39720 - 2 2 6 2 2 6 2 2 6 14 14 14
39721 - 86 86 86 54 54 54 22 22 22 6 6 6
39722 - 0 0 0 0 0 0 0 0 0 0 0 0
39723 - 0 0 0 0 0 0 0 0 0 0 0 0
39724 - 0 0 0 0 0 0 0 0 0 0 0 0
39725 - 0 0 0 0 0 0 0 0 0 0 0 0
39726 - 0 0 0 0 0 0 0 0 0 0 0 0
39727 - 0 0 0 0 0 0 0 0 0 0 0 0
39728 - 0 0 0 0 0 0 0 0 0 0 0 0
39729 - 0 0 0 0 0 0 0 0 0 0 0 0
39730 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 18 18 18 46 46 46 90 90 90
39734 - 46 46 46 18 18 18 6 6 6 182 182 182
39735 -253 253 253 246 246 246 206 206 206 190 190 190
39736 -190 190 190 190 190 190 190 190 190 190 190 190
39737 -206 206 206 231 231 231 250 250 250 253 253 253
39738 -253 253 253 253 253 253 253 253 253 253 253 253
39739 -202 202 202 14 14 14 2 2 6 2 2 6
39740 - 2 2 6 2 2 6 2 2 6 2 2 6
39741 - 42 42 42 86 86 86 42 42 42 18 18 18
39742 - 6 6 6 0 0 0 0 0 0 0 0 0
39743 - 0 0 0 0 0 0 0 0 0 0 0 0
39744 - 0 0 0 0 0 0 0 0 0 0 0 0
39745 - 0 0 0 0 0 0 0 0 0 0 0 0
39746 - 0 0 0 0 0 0 0 0 0 0 0 0
39747 - 0 0 0 0 0 0 0 0 0 0 0 0
39748 - 0 0 0 0 0 0 0 0 0 0 0 0
39749 - 0 0 0 0 0 0 0 0 0 0 0 0
39750 - 0 0 0 0 0 0 0 0 0 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 6 6 6
39753 - 14 14 14 38 38 38 74 74 74 66 66 66
39754 - 2 2 6 6 6 6 90 90 90 250 250 250
39755 -253 253 253 253 253 253 238 238 238 198 198 198
39756 -190 190 190 190 190 190 195 195 195 221 221 221
39757 -246 246 246 253 253 253 253 253 253 253 253 253
39758 -253 253 253 253 253 253 253 253 253 253 253 253
39759 -253 253 253 82 82 82 2 2 6 2 2 6
39760 - 2 2 6 2 2 6 2 2 6 2 2 6
39761 - 2 2 6 78 78 78 70 70 70 34 34 34
39762 - 14 14 14 6 6 6 0 0 0 0 0 0
39763 - 0 0 0 0 0 0 0 0 0 0 0 0
39764 - 0 0 0 0 0 0 0 0 0 0 0 0
39765 - 0 0 0 0 0 0 0 0 0 0 0 0
39766 - 0 0 0 0 0 0 0 0 0 0 0 0
39767 - 0 0 0 0 0 0 0 0 0 0 0 0
39768 - 0 0 0 0 0 0 0 0 0 0 0 0
39769 - 0 0 0 0 0 0 0 0 0 0 0 0
39770 - 0 0 0 0 0 0 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 14 14 14
39773 - 34 34 34 66 66 66 78 78 78 6 6 6
39774 - 2 2 6 18 18 18 218 218 218 253 253 253
39775 -253 253 253 253 253 253 253 253 253 246 246 246
39776 -226 226 226 231 231 231 246 246 246 253 253 253
39777 -253 253 253 253 253 253 253 253 253 253 253 253
39778 -253 253 253 253 253 253 253 253 253 253 253 253
39779 -253 253 253 178 178 178 2 2 6 2 2 6
39780 - 2 2 6 2 2 6 2 2 6 2 2 6
39781 - 2 2 6 18 18 18 90 90 90 62 62 62
39782 - 30 30 30 10 10 10 0 0 0 0 0 0
39783 - 0 0 0 0 0 0 0 0 0 0 0 0
39784 - 0 0 0 0 0 0 0 0 0 0 0 0
39785 - 0 0 0 0 0 0 0 0 0 0 0 0
39786 - 0 0 0 0 0 0 0 0 0 0 0 0
39787 - 0 0 0 0 0 0 0 0 0 0 0 0
39788 - 0 0 0 0 0 0 0 0 0 0 0 0
39789 - 0 0 0 0 0 0 0 0 0 0 0 0
39790 - 0 0 0 0 0 0 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 10 10 10 26 26 26
39793 - 58 58 58 90 90 90 18 18 18 2 2 6
39794 - 2 2 6 110 110 110 253 253 253 253 253 253
39795 -253 253 253 253 253 253 253 253 253 253 253 253
39796 -250 250 250 253 253 253 253 253 253 253 253 253
39797 -253 253 253 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 231 231 231 18 18 18 2 2 6
39800 - 2 2 6 2 2 6 2 2 6 2 2 6
39801 - 2 2 6 2 2 6 18 18 18 94 94 94
39802 - 54 54 54 26 26 26 10 10 10 0 0 0
39803 - 0 0 0 0 0 0 0 0 0 0 0 0
39804 - 0 0 0 0 0 0 0 0 0 0 0 0
39805 - 0 0 0 0 0 0 0 0 0 0 0 0
39806 - 0 0 0 0 0 0 0 0 0 0 0 0
39807 - 0 0 0 0 0 0 0 0 0 0 0 0
39808 - 0 0 0 0 0 0 0 0 0 0 0 0
39809 - 0 0 0 0 0 0 0 0 0 0 0 0
39810 - 0 0 0 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 6 6 6 22 22 22 50 50 50
39813 - 90 90 90 26 26 26 2 2 6 2 2 6
39814 - 14 14 14 195 195 195 250 250 250 253 253 253
39815 -253 253 253 253 253 253 253 253 253 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 -250 250 250 242 242 242 54 54 54 2 2 6
39820 - 2 2 6 2 2 6 2 2 6 2 2 6
39821 - 2 2 6 2 2 6 2 2 6 38 38 38
39822 - 86 86 86 50 50 50 22 22 22 6 6 6
39823 - 0 0 0 0 0 0 0 0 0 0 0 0
39824 - 0 0 0 0 0 0 0 0 0 0 0 0
39825 - 0 0 0 0 0 0 0 0 0 0 0 0
39826 - 0 0 0 0 0 0 0 0 0 0 0 0
39827 - 0 0 0 0 0 0 0 0 0 0 0 0
39828 - 0 0 0 0 0 0 0 0 0 0 0 0
39829 - 0 0 0 0 0 0 0 0 0 0 0 0
39830 - 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 - 6 6 6 14 14 14 38 38 38 82 82 82
39833 - 34 34 34 2 2 6 2 2 6 2 2 6
39834 - 42 42 42 195 195 195 246 246 246 253 253 253
39835 -253 253 253 253 253 253 253 253 253 250 250 250
39836 -242 242 242 242 242 242 250 250 250 253 253 253
39837 -253 253 253 253 253 253 253 253 253 253 253 253
39838 -253 253 253 250 250 250 246 246 246 238 238 238
39839 -226 226 226 231 231 231 101 101 101 6 6 6
39840 - 2 2 6 2 2 6 2 2 6 2 2 6
39841 - 2 2 6 2 2 6 2 2 6 2 2 6
39842 - 38 38 38 82 82 82 42 42 42 14 14 14
39843 - 6 6 6 0 0 0 0 0 0 0 0 0
39844 - 0 0 0 0 0 0 0 0 0 0 0 0
39845 - 0 0 0 0 0 0 0 0 0 0 0 0
39846 - 0 0 0 0 0 0 0 0 0 0 0 0
39847 - 0 0 0 0 0 0 0 0 0 0 0 0
39848 - 0 0 0 0 0 0 0 0 0 0 0 0
39849 - 0 0 0 0 0 0 0 0 0 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 - 10 10 10 26 26 26 62 62 62 66 66 66
39853 - 2 2 6 2 2 6 2 2 6 6 6 6
39854 - 70 70 70 170 170 170 206 206 206 234 234 234
39855 -246 246 246 250 250 250 250 250 250 238 238 238
39856 -226 226 226 231 231 231 238 238 238 250 250 250
39857 -250 250 250 250 250 250 246 246 246 231 231 231
39858 -214 214 214 206 206 206 202 202 202 202 202 202
39859 -198 198 198 202 202 202 182 182 182 18 18 18
39860 - 2 2 6 2 2 6 2 2 6 2 2 6
39861 - 2 2 6 2 2 6 2 2 6 2 2 6
39862 - 2 2 6 62 62 62 66 66 66 30 30 30
39863 - 10 10 10 0 0 0 0 0 0 0 0 0
39864 - 0 0 0 0 0 0 0 0 0 0 0 0
39865 - 0 0 0 0 0 0 0 0 0 0 0 0
39866 - 0 0 0 0 0 0 0 0 0 0 0 0
39867 - 0 0 0 0 0 0 0 0 0 0 0 0
39868 - 0 0 0 0 0 0 0 0 0 0 0 0
39869 - 0 0 0 0 0 0 0 0 0 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 - 14 14 14 42 42 42 82 82 82 18 18 18
39873 - 2 2 6 2 2 6 2 2 6 10 10 10
39874 - 94 94 94 182 182 182 218 218 218 242 242 242
39875 -250 250 250 253 253 253 253 253 253 250 250 250
39876 -234 234 234 253 253 253 253 253 253 253 253 253
39877 -253 253 253 253 253 253 253 253 253 246 246 246
39878 -238 238 238 226 226 226 210 210 210 202 202 202
39879 -195 195 195 195 195 195 210 210 210 158 158 158
39880 - 6 6 6 14 14 14 50 50 50 14 14 14
39881 - 2 2 6 2 2 6 2 2 6 2 2 6
39882 - 2 2 6 6 6 6 86 86 86 46 46 46
39883 - 18 18 18 6 6 6 0 0 0 0 0 0
39884 - 0 0 0 0 0 0 0 0 0 0 0 0
39885 - 0 0 0 0 0 0 0 0 0 0 0 0
39886 - 0 0 0 0 0 0 0 0 0 0 0 0
39887 - 0 0 0 0 0 0 0 0 0 0 0 0
39888 - 0 0 0 0 0 0 0 0 0 0 0 0
39889 - 0 0 0 0 0 0 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 6 6 6
39892 - 22 22 22 54 54 54 70 70 70 2 2 6
39893 - 2 2 6 10 10 10 2 2 6 22 22 22
39894 -166 166 166 231 231 231 250 250 250 253 253 253
39895 -253 253 253 253 253 253 253 253 253 250 250 250
39896 -242 242 242 253 253 253 253 253 253 253 253 253
39897 -253 253 253 253 253 253 253 253 253 253 253 253
39898 -253 253 253 253 253 253 253 253 253 246 246 246
39899 -231 231 231 206 206 206 198 198 198 226 226 226
39900 - 94 94 94 2 2 6 6 6 6 38 38 38
39901 - 30 30 30 2 2 6 2 2 6 2 2 6
39902 - 2 2 6 2 2 6 62 62 62 66 66 66
39903 - 26 26 26 10 10 10 0 0 0 0 0 0
39904 - 0 0 0 0 0 0 0 0 0 0 0 0
39905 - 0 0 0 0 0 0 0 0 0 0 0 0
39906 - 0 0 0 0 0 0 0 0 0 0 0 0
39907 - 0 0 0 0 0 0 0 0 0 0 0 0
39908 - 0 0 0 0 0 0 0 0 0 0 0 0
39909 - 0 0 0 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 10 10 10
39912 - 30 30 30 74 74 74 50 50 50 2 2 6
39913 - 26 26 26 26 26 26 2 2 6 106 106 106
39914 -238 238 238 253 253 253 253 253 253 253 253 253
39915 -253 253 253 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 246 246 246 218 218 218 202 202 202
39920 -210 210 210 14 14 14 2 2 6 2 2 6
39921 - 30 30 30 22 22 22 2 2 6 2 2 6
39922 - 2 2 6 2 2 6 18 18 18 86 86 86
39923 - 42 42 42 14 14 14 0 0 0 0 0 0
39924 - 0 0 0 0 0 0 0 0 0 0 0 0
39925 - 0 0 0 0 0 0 0 0 0 0 0 0
39926 - 0 0 0 0 0 0 0 0 0 0 0 0
39927 - 0 0 0 0 0 0 0 0 0 0 0 0
39928 - 0 0 0 0 0 0 0 0 0 0 0 0
39929 - 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 14 14 14
39932 - 42 42 42 90 90 90 22 22 22 2 2 6
39933 - 42 42 42 2 2 6 18 18 18 218 218 218
39934 -253 253 253 253 253 253 253 253 253 253 253 253
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 250 250 250 221 221 221
39940 -218 218 218 101 101 101 2 2 6 14 14 14
39941 - 18 18 18 38 38 38 10 10 10 2 2 6
39942 - 2 2 6 2 2 6 2 2 6 78 78 78
39943 - 58 58 58 22 22 22 6 6 6 0 0 0
39944 - 0 0 0 0 0 0 0 0 0 0 0 0
39945 - 0 0 0 0 0 0 0 0 0 0 0 0
39946 - 0 0 0 0 0 0 0 0 0 0 0 0
39947 - 0 0 0 0 0 0 0 0 0 0 0 0
39948 - 0 0 0 0 0 0 0 0 0 0 0 0
39949 - 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 6 6 6 18 18 18
39952 - 54 54 54 82 82 82 2 2 6 26 26 26
39953 - 22 22 22 2 2 6 123 123 123 253 253 253
39954 -253 253 253 253 253 253 253 253 253 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 250 250 250
39960 -238 238 238 198 198 198 6 6 6 38 38 38
39961 - 58 58 58 26 26 26 38 38 38 2 2 6
39962 - 2 2 6 2 2 6 2 2 6 46 46 46
39963 - 78 78 78 30 30 30 10 10 10 0 0 0
39964 - 0 0 0 0 0 0 0 0 0 0 0 0
39965 - 0 0 0 0 0 0 0 0 0 0 0 0
39966 - 0 0 0 0 0 0 0 0 0 0 0 0
39967 - 0 0 0 0 0 0 0 0 0 0 0 0
39968 - 0 0 0 0 0 0 0 0 0 0 0 0
39969 - 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 10 10 10 30 30 30
39972 - 74 74 74 58 58 58 2 2 6 42 42 42
39973 - 2 2 6 22 22 22 231 231 231 253 253 253
39974 -253 253 253 253 253 253 253 253 253 253 253 253
39975 -253 253 253 253 253 253 253 253 253 250 250 250
39976 -253 253 253 253 253 253 253 253 253 253 253 253
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 246 246 246 46 46 46 38 38 38
39981 - 42 42 42 14 14 14 38 38 38 14 14 14
39982 - 2 2 6 2 2 6 2 2 6 6 6 6
39983 - 86 86 86 46 46 46 14 14 14 0 0 0
39984 - 0 0 0 0 0 0 0 0 0 0 0 0
39985 - 0 0 0 0 0 0 0 0 0 0 0 0
39986 - 0 0 0 0 0 0 0 0 0 0 0 0
39987 - 0 0 0 0 0 0 0 0 0 0 0 0
39988 - 0 0 0 0 0 0 0 0 0 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 6 6 6 14 14 14 42 42 42
39992 - 90 90 90 18 18 18 18 18 18 26 26 26
39993 - 2 2 6 116 116 116 253 253 253 253 253 253
39994 -253 253 253 253 253 253 253 253 253 253 253 253
39995 -253 253 253 253 253 253 250 250 250 238 238 238
39996 -253 253 253 253 253 253 253 253 253 253 253 253
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 94 94 94 6 6 6
40001 - 2 2 6 2 2 6 10 10 10 34 34 34
40002 - 2 2 6 2 2 6 2 2 6 2 2 6
40003 - 74 74 74 58 58 58 22 22 22 6 6 6
40004 - 0 0 0 0 0 0 0 0 0 0 0 0
40005 - 0 0 0 0 0 0 0 0 0 0 0 0
40006 - 0 0 0 0 0 0 0 0 0 0 0 0
40007 - 0 0 0 0 0 0 0 0 0 0 0 0
40008 - 0 0 0 0 0 0 0 0 0 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 10 10 10 26 26 26 66 66 66
40012 - 82 82 82 2 2 6 38 38 38 6 6 6
40013 - 14 14 14 210 210 210 253 253 253 253 253 253
40014 -253 253 253 253 253 253 253 253 253 253 253 253
40015 -253 253 253 253 253 253 246 246 246 242 242 242
40016 -253 253 253 253 253 253 253 253 253 253 253 253
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 144 144 144 2 2 6
40021 - 2 2 6 2 2 6 2 2 6 46 46 46
40022 - 2 2 6 2 2 6 2 2 6 2 2 6
40023 - 42 42 42 74 74 74 30 30 30 10 10 10
40024 - 0 0 0 0 0 0 0 0 0 0 0 0
40025 - 0 0 0 0 0 0 0 0 0 0 0 0
40026 - 0 0 0 0 0 0 0 0 0 0 0 0
40027 - 0 0 0 0 0 0 0 0 0 0 0 0
40028 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 14 14 14 42 42 42 90 90 90
40032 - 26 26 26 6 6 6 42 42 42 2 2 6
40033 - 74 74 74 250 250 250 253 253 253 253 253 253
40034 -253 253 253 253 253 253 253 253 253 253 253 253
40035 -253 253 253 253 253 253 242 242 242 242 242 242
40036 -253 253 253 253 253 253 253 253 253 253 253 253
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 182 182 182 2 2 6
40041 - 2 2 6 2 2 6 2 2 6 46 46 46
40042 - 2 2 6 2 2 6 2 2 6 2 2 6
40043 - 10 10 10 86 86 86 38 38 38 10 10 10
40044 - 0 0 0 0 0 0 0 0 0 0 0 0
40045 - 0 0 0 0 0 0 0 0 0 0 0 0
40046 - 0 0 0 0 0 0 0 0 0 0 0 0
40047 - 0 0 0 0 0 0 0 0 0 0 0 0
40048 - 0 0 0 0 0 0 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 - 10 10 10 26 26 26 66 66 66 82 82 82
40052 - 2 2 6 22 22 22 18 18 18 2 2 6
40053 -149 149 149 253 253 253 253 253 253 253 253 253
40054 -253 253 253 253 253 253 253 253 253 253 253 253
40055 -253 253 253 253 253 253 234 234 234 242 242 242
40056 -253 253 253 253 253 253 253 253 253 253 253 253
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 206 206 206 2 2 6
40061 - 2 2 6 2 2 6 2 2 6 38 38 38
40062 - 2 2 6 2 2 6 2 2 6 2 2 6
40063 - 6 6 6 86 86 86 46 46 46 14 14 14
40064 - 0 0 0 0 0 0 0 0 0 0 0 0
40065 - 0 0 0 0 0 0 0 0 0 0 0 0
40066 - 0 0 0 0 0 0 0 0 0 0 0 0
40067 - 0 0 0 0 0 0 0 0 0 0 0 0
40068 - 0 0 0 0 0 0 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 6 6 6
40071 - 18 18 18 46 46 46 86 86 86 18 18 18
40072 - 2 2 6 34 34 34 10 10 10 6 6 6
40073 -210 210 210 253 253 253 253 253 253 253 253 253
40074 -253 253 253 253 253 253 253 253 253 253 253 253
40075 -253 253 253 253 253 253 234 234 234 242 242 242
40076 -253 253 253 253 253 253 253 253 253 253 253 253
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 221 221 221 6 6 6
40081 - 2 2 6 2 2 6 6 6 6 30 30 30
40082 - 2 2 6 2 2 6 2 2 6 2 2 6
40083 - 2 2 6 82 82 82 54 54 54 18 18 18
40084 - 6 6 6 0 0 0 0 0 0 0 0 0
40085 - 0 0 0 0 0 0 0 0 0 0 0 0
40086 - 0 0 0 0 0 0 0 0 0 0 0 0
40087 - 0 0 0 0 0 0 0 0 0 0 0 0
40088 - 0 0 0 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 10 10 10
40091 - 26 26 26 66 66 66 62 62 62 2 2 6
40092 - 2 2 6 38 38 38 10 10 10 26 26 26
40093 -238 238 238 253 253 253 253 253 253 253 253 253
40094 -253 253 253 253 253 253 253 253 253 253 253 253
40095 -253 253 253 253 253 253 231 231 231 238 238 238
40096 -253 253 253 253 253 253 253 253 253 253 253 253
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 231 231 231 6 6 6
40101 - 2 2 6 2 2 6 10 10 10 30 30 30
40102 - 2 2 6 2 2 6 2 2 6 2 2 6
40103 - 2 2 6 66 66 66 58 58 58 22 22 22
40104 - 6 6 6 0 0 0 0 0 0 0 0 0
40105 - 0 0 0 0 0 0 0 0 0 0 0 0
40106 - 0 0 0 0 0 0 0 0 0 0 0 0
40107 - 0 0 0 0 0 0 0 0 0 0 0 0
40108 - 0 0 0 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 10 10 10
40111 - 38 38 38 78 78 78 6 6 6 2 2 6
40112 - 2 2 6 46 46 46 14 14 14 42 42 42
40113 -246 246 246 253 253 253 253 253 253 253 253 253
40114 -253 253 253 253 253 253 253 253 253 253 253 253
40115 -253 253 253 253 253 253 231 231 231 242 242 242
40116 -253 253 253 253 253 253 253 253 253 253 253 253
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 234 234 234 10 10 10
40121 - 2 2 6 2 2 6 22 22 22 14 14 14
40122 - 2 2 6 2 2 6 2 2 6 2 2 6
40123 - 2 2 6 66 66 66 62 62 62 22 22 22
40124 - 6 6 6 0 0 0 0 0 0 0 0 0
40125 - 0 0 0 0 0 0 0 0 0 0 0 0
40126 - 0 0 0 0 0 0 0 0 0 0 0 0
40127 - 0 0 0 0 0 0 0 0 0 0 0 0
40128 - 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 6 6 6 18 18 18
40131 - 50 50 50 74 74 74 2 2 6 2 2 6
40132 - 14 14 14 70 70 70 34 34 34 62 62 62
40133 -250 250 250 253 253 253 253 253 253 253 253 253
40134 -253 253 253 253 253 253 253 253 253 253 253 253
40135 -253 253 253 253 253 253 231 231 231 246 246 246
40136 -253 253 253 253 253 253 253 253 253 253 253 253
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 234 234 234 14 14 14
40141 - 2 2 6 2 2 6 30 30 30 2 2 6
40142 - 2 2 6 2 2 6 2 2 6 2 2 6
40143 - 2 2 6 66 66 66 62 62 62 22 22 22
40144 - 6 6 6 0 0 0 0 0 0 0 0 0
40145 - 0 0 0 0 0 0 0 0 0 0 0 0
40146 - 0 0 0 0 0 0 0 0 0 0 0 0
40147 - 0 0 0 0 0 0 0 0 0 0 0 0
40148 - 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 6 6 6 18 18 18
40151 - 54 54 54 62 62 62 2 2 6 2 2 6
40152 - 2 2 6 30 30 30 46 46 46 70 70 70
40153 -250 250 250 253 253 253 253 253 253 253 253 253
40154 -253 253 253 253 253 253 253 253 253 253 253 253
40155 -253 253 253 253 253 253 231 231 231 246 246 246
40156 -253 253 253 253 253 253 253 253 253 253 253 253
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 226 226 226 10 10 10
40161 - 2 2 6 6 6 6 30 30 30 2 2 6
40162 - 2 2 6 2 2 6 2 2 6 2 2 6
40163 - 2 2 6 66 66 66 58 58 58 22 22 22
40164 - 6 6 6 0 0 0 0 0 0 0 0 0
40165 - 0 0 0 0 0 0 0 0 0 0 0 0
40166 - 0 0 0 0 0 0 0 0 0 0 0 0
40167 - 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22
40171 - 58 58 58 62 62 62 2 2 6 2 2 6
40172 - 2 2 6 2 2 6 30 30 30 78 78 78
40173 -250 250 250 253 253 253 253 253 253 253 253 253
40174 -253 253 253 253 253 253 253 253 253 253 253 253
40175 -253 253 253 253 253 253 231 231 231 246 246 246
40176 -253 253 253 253 253 253 253 253 253 253 253 253
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 206 206 206 2 2 6
40181 - 22 22 22 34 34 34 18 14 6 22 22 22
40182 - 26 26 26 18 18 18 6 6 6 2 2 6
40183 - 2 2 6 82 82 82 54 54 54 18 18 18
40184 - 6 6 6 0 0 0 0 0 0 0 0 0
40185 - 0 0 0 0 0 0 0 0 0 0 0 0
40186 - 0 0 0 0 0 0 0 0 0 0 0 0
40187 - 0 0 0 0 0 0 0 0 0 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 6 6 6 26 26 26
40191 - 62 62 62 106 106 106 74 54 14 185 133 11
40192 -210 162 10 121 92 8 6 6 6 62 62 62
40193 -238 238 238 253 253 253 253 253 253 253 253 253
40194 -253 253 253 253 253 253 253 253 253 253 253 253
40195 -253 253 253 253 253 253 231 231 231 246 246 246
40196 -253 253 253 253 253 253 253 253 253 253 253 253
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 158 158 158 18 18 18
40201 - 14 14 14 2 2 6 2 2 6 2 2 6
40202 - 6 6 6 18 18 18 66 66 66 38 38 38
40203 - 6 6 6 94 94 94 50 50 50 18 18 18
40204 - 6 6 6 0 0 0 0 0 0 0 0 0
40205 - 0 0 0 0 0 0 0 0 0 0 0 0
40206 - 0 0 0 0 0 0 0 0 0 0 0 0
40207 - 0 0 0 0 0 0 0 0 0 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 6 6 6
40210 - 10 10 10 10 10 10 18 18 18 38 38 38
40211 - 78 78 78 142 134 106 216 158 10 242 186 14
40212 -246 190 14 246 190 14 156 118 10 10 10 10
40213 - 90 90 90 238 238 238 253 253 253 253 253 253
40214 -253 253 253 253 253 253 253 253 253 253 253 253
40215 -253 253 253 253 253 253 231 231 231 250 250 250
40216 -253 253 253 253 253 253 253 253 253 253 253 253
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 246 230 190
40220 -238 204 91 238 204 91 181 142 44 37 26 9
40221 - 2 2 6 2 2 6 2 2 6 2 2 6
40222 - 2 2 6 2 2 6 38 38 38 46 46 46
40223 - 26 26 26 106 106 106 54 54 54 18 18 18
40224 - 6 6 6 0 0 0 0 0 0 0 0 0
40225 - 0 0 0 0 0 0 0 0 0 0 0 0
40226 - 0 0 0 0 0 0 0 0 0 0 0 0
40227 - 0 0 0 0 0 0 0 0 0 0 0 0
40228 - 0 0 0 0 0 0 0 0 0 0 0 0
40229 - 0 0 0 6 6 6 14 14 14 22 22 22
40230 - 30 30 30 38 38 38 50 50 50 70 70 70
40231 -106 106 106 190 142 34 226 170 11 242 186 14
40232 -246 190 14 246 190 14 246 190 14 154 114 10
40233 - 6 6 6 74 74 74 226 226 226 253 253 253
40234 -253 253 253 253 253 253 253 253 253 253 253 253
40235 -253 253 253 253 253 253 231 231 231 250 250 250
40236 -253 253 253 253 253 253 253 253 253 253 253 253
40237 -253 253 253 253 253 253 253 253 253 253 253 253
40238 -253 253 253 253 253 253 253 253 253 253 253 253
40239 -253 253 253 253 253 253 253 253 253 228 184 62
40240 -241 196 14 241 208 19 232 195 16 38 30 10
40241 - 2 2 6 2 2 6 2 2 6 2 2 6
40242 - 2 2 6 6 6 6 30 30 30 26 26 26
40243 -203 166 17 154 142 90 66 66 66 26 26 26
40244 - 6 6 6 0 0 0 0 0 0 0 0 0
40245 - 0 0 0 0 0 0 0 0 0 0 0 0
40246 - 0 0 0 0 0 0 0 0 0 0 0 0
40247 - 0 0 0 0 0 0 0 0 0 0 0 0
40248 - 0 0 0 0 0 0 0 0 0 0 0 0
40249 - 6 6 6 18 18 18 38 38 38 58 58 58
40250 - 78 78 78 86 86 86 101 101 101 123 123 123
40251 -175 146 61 210 150 10 234 174 13 246 186 14
40252 -246 190 14 246 190 14 246 190 14 238 190 10
40253 -102 78 10 2 2 6 46 46 46 198 198 198
40254 -253 253 253 253 253 253 253 253 253 253 253 253
40255 -253 253 253 253 253 253 234 234 234 242 242 242
40256 -253 253 253 253 253 253 253 253 253 253 253 253
40257 -253 253 253 253 253 253 253 253 253 253 253 253
40258 -253 253 253 253 253 253 253 253 253 253 253 253
40259 -253 253 253 253 253 253 253 253 253 224 178 62
40260 -242 186 14 241 196 14 210 166 10 22 18 6
40261 - 2 2 6 2 2 6 2 2 6 2 2 6
40262 - 2 2 6 2 2 6 6 6 6 121 92 8
40263 -238 202 15 232 195 16 82 82 82 34 34 34
40264 - 10 10 10 0 0 0 0 0 0 0 0 0
40265 - 0 0 0 0 0 0 0 0 0 0 0 0
40266 - 0 0 0 0 0 0 0 0 0 0 0 0
40267 - 0 0 0 0 0 0 0 0 0 0 0 0
40268 - 0 0 0 0 0 0 0 0 0 0 0 0
40269 - 14 14 14 38 38 38 70 70 70 154 122 46
40270 -190 142 34 200 144 11 197 138 11 197 138 11
40271 -213 154 11 226 170 11 242 186 14 246 190 14
40272 -246 190 14 246 190 14 246 190 14 246 190 14
40273 -225 175 15 46 32 6 2 2 6 22 22 22
40274 -158 158 158 250 250 250 253 253 253 253 253 253
40275 -253 253 253 253 253 253 253 253 253 253 253 253
40276 -253 253 253 253 253 253 253 253 253 253 253 253
40277 -253 253 253 253 253 253 253 253 253 253 253 253
40278 -253 253 253 253 253 253 253 253 253 253 253 253
40279 -253 253 253 250 250 250 242 242 242 224 178 62
40280 -239 182 13 236 186 11 213 154 11 46 32 6
40281 - 2 2 6 2 2 6 2 2 6 2 2 6
40282 - 2 2 6 2 2 6 61 42 6 225 175 15
40283 -238 190 10 236 186 11 112 100 78 42 42 42
40284 - 14 14 14 0 0 0 0 0 0 0 0 0
40285 - 0 0 0 0 0 0 0 0 0 0 0 0
40286 - 0 0 0 0 0 0 0 0 0 0 0 0
40287 - 0 0 0 0 0 0 0 0 0 0 0 0
40288 - 0 0 0 0 0 0 0 0 0 6 6 6
40289 - 22 22 22 54 54 54 154 122 46 213 154 11
40290 -226 170 11 230 174 11 226 170 11 226 170 11
40291 -236 178 12 242 186 14 246 190 14 246 190 14
40292 -246 190 14 246 190 14 246 190 14 246 190 14
40293 -241 196 14 184 144 12 10 10 10 2 2 6
40294 - 6 6 6 116 116 116 242 242 242 253 253 253
40295 -253 253 253 253 253 253 253 253 253 253 253 253
40296 -253 253 253 253 253 253 253 253 253 253 253 253
40297 -253 253 253 253 253 253 253 253 253 253 253 253
40298 -253 253 253 253 253 253 253 253 253 253 253 253
40299 -253 253 253 231 231 231 198 198 198 214 170 54
40300 -236 178 12 236 178 12 210 150 10 137 92 6
40301 - 18 14 6 2 2 6 2 2 6 2 2 6
40302 - 6 6 6 70 47 6 200 144 11 236 178 12
40303 -239 182 13 239 182 13 124 112 88 58 58 58
40304 - 22 22 22 6 6 6 0 0 0 0 0 0
40305 - 0 0 0 0 0 0 0 0 0 0 0 0
40306 - 0 0 0 0 0 0 0 0 0 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 10 10 10
40309 - 30 30 30 70 70 70 180 133 36 226 170 11
40310 -239 182 13 242 186 14 242 186 14 246 186 14
40311 -246 190 14 246 190 14 246 190 14 246 190 14
40312 -246 190 14 246 190 14 246 190 14 246 190 14
40313 -246 190 14 232 195 16 98 70 6 2 2 6
40314 - 2 2 6 2 2 6 66 66 66 221 221 221
40315 -253 253 253 253 253 253 253 253 253 253 253 253
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 206 206 206 198 198 198 214 166 58
40320 -230 174 11 230 174 11 216 158 10 192 133 9
40321 -163 110 8 116 81 8 102 78 10 116 81 8
40322 -167 114 7 197 138 11 226 170 11 239 182 13
40323 -242 186 14 242 186 14 162 146 94 78 78 78
40324 - 34 34 34 14 14 14 6 6 6 0 0 0
40325 - 0 0 0 0 0 0 0 0 0 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 6 6 6
40329 - 30 30 30 78 78 78 190 142 34 226 170 11
40330 -239 182 13 246 190 14 246 190 14 246 190 14
40331 -246 190 14 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 241 196 14 203 166 17 22 18 6
40334 - 2 2 6 2 2 6 2 2 6 38 38 38
40335 -218 218 218 253 253 253 253 253 253 253 253 253
40336 -253 253 253 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 -250 250 250 206 206 206 198 198 198 202 162 69
40340 -226 170 11 236 178 12 224 166 10 210 150 10
40341 -200 144 11 197 138 11 192 133 9 197 138 11
40342 -210 150 10 226 170 11 242 186 14 246 190 14
40343 -246 190 14 246 186 14 225 175 15 124 112 88
40344 - 62 62 62 30 30 30 14 14 14 6 6 6
40345 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
40349 - 30 30 30 78 78 78 174 135 50 224 166 10
40350 -239 182 13 246 190 14 246 190 14 246 190 14
40351 -246 190 14 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 241 196 14 139 102 15
40354 - 2 2 6 2 2 6 2 2 6 2 2 6
40355 - 78 78 78 250 250 250 253 253 253 253 253 253
40356 -253 253 253 253 253 253 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 -250 250 250 214 214 214 198 198 198 190 150 46
40360 -219 162 10 236 178 12 234 174 13 224 166 10
40361 -216 158 10 213 154 11 213 154 11 216 158 10
40362 -226 170 11 239 182 13 246 190 14 246 190 14
40363 -246 190 14 246 190 14 242 186 14 206 162 42
40364 -101 101 101 58 58 58 30 30 30 14 14 14
40365 - 6 6 6 0 0 0 0 0 0 0 0 0
40366 - 0 0 0 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 10 10 10
40369 - 30 30 30 74 74 74 174 135 50 216 158 10
40370 -236 178 12 246 190 14 246 190 14 246 190 14
40371 -246 190 14 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 241 196 14 226 184 13
40374 - 61 42 6 2 2 6 2 2 6 2 2 6
40375 - 22 22 22 238 238 238 253 253 253 253 253 253
40376 -253 253 253 253 253 253 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 226 226 226 187 187 187 180 133 36
40380 -216 158 10 236 178 12 239 182 13 236 178 12
40381 -230 174 11 226 170 11 226 170 11 230 174 11
40382 -236 178 12 242 186 14 246 190 14 246 190 14
40383 -246 190 14 246 190 14 246 186 14 239 182 13
40384 -206 162 42 106 106 106 66 66 66 34 34 34
40385 - 14 14 14 6 6 6 0 0 0 0 0 0
40386 - 0 0 0 0 0 0 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 6 6 6
40389 - 26 26 26 70 70 70 163 133 67 213 154 11
40390 -236 178 12 246 190 14 246 190 14 246 190 14
40391 -246 190 14 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 241 196 14
40394 -190 146 13 18 14 6 2 2 6 2 2 6
40395 - 46 46 46 246 246 246 253 253 253 253 253 253
40396 -253 253 253 253 253 253 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 221 221 221 86 86 86 156 107 11
40400 -216 158 10 236 178 12 242 186 14 246 186 14
40401 -242 186 14 239 182 13 239 182 13 242 186 14
40402 -242 186 14 246 186 14 246 190 14 246 190 14
40403 -246 190 14 246 190 14 246 190 14 246 190 14
40404 -242 186 14 225 175 15 142 122 72 66 66 66
40405 - 30 30 30 10 10 10 0 0 0 0 0 0
40406 - 0 0 0 0 0 0 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 6 6 6
40409 - 26 26 26 70 70 70 163 133 67 210 150 10
40410 -236 178 12 246 190 14 246 190 14 246 190 14
40411 -246 190 14 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 -232 195 16 121 92 8 34 34 34 106 106 106
40415 -221 221 221 253 253 253 253 253 253 253 253 253
40416 -253 253 253 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 -242 242 242 82 82 82 18 14 6 163 110 8
40420 -216 158 10 236 178 12 242 186 14 246 190 14
40421 -246 190 14 246 190 14 246 190 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 242 186 14 163 133 67
40425 - 46 46 46 18 18 18 6 6 6 0 0 0
40426 - 0 0 0 0 0 0 0 0 0 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 10 10 10
40429 - 30 30 30 78 78 78 163 133 67 210 150 10
40430 -236 178 12 246 186 14 246 190 14 246 190 14
40431 -246 190 14 246 190 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 -241 196 14 215 174 15 190 178 144 253 253 253
40435 -253 253 253 253 253 253 253 253 253 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 218 218 218
40439 - 58 58 58 2 2 6 22 18 6 167 114 7
40440 -216 158 10 236 178 12 246 186 14 246 190 14
40441 -246 190 14 246 190 14 246 190 14 246 190 14
40442 -246 190 14 246 190 14 246 190 14 246 190 14
40443 -246 190 14 246 190 14 246 190 14 246 190 14
40444 -246 190 14 246 186 14 242 186 14 190 150 46
40445 - 54 54 54 22 22 22 6 6 6 0 0 0
40446 - 0 0 0 0 0 0 0 0 0 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 14 14 14
40449 - 38 38 38 86 86 86 180 133 36 213 154 11
40450 -236 178 12 246 186 14 246 190 14 246 190 14
40451 -246 190 14 246 190 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 232 195 16 190 146 13 214 214 214
40455 -253 253 253 253 253 253 253 253 253 253 253 253
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 250 250 250 170 170 170 26 26 26
40459 - 2 2 6 2 2 6 37 26 9 163 110 8
40460 -219 162 10 239 182 13 246 186 14 246 190 14
40461 -246 190 14 246 190 14 246 190 14 246 190 14
40462 -246 190 14 246 190 14 246 190 14 246 190 14
40463 -246 190 14 246 190 14 246 190 14 246 190 14
40464 -246 186 14 236 178 12 224 166 10 142 122 72
40465 - 46 46 46 18 18 18 6 6 6 0 0 0
40466 - 0 0 0 0 0 0 0 0 0 0 0 0
40467 - 0 0 0 0 0 0 0 0 0 0 0 0
40468 - 0 0 0 0 0 0 6 6 6 18 18 18
40469 - 50 50 50 109 106 95 192 133 9 224 166 10
40470 -242 186 14 246 190 14 246 190 14 246 190 14
40471 -246 190 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 -242 186 14 226 184 13 210 162 10 142 110 46
40475 -226 226 226 253 253 253 253 253 253 253 253 253
40476 -253 253 253 253 253 253 253 253 253 253 253 253
40477 -253 253 253 253 253 253 253 253 253 253 253 253
40478 -198 198 198 66 66 66 2 2 6 2 2 6
40479 - 2 2 6 2 2 6 50 34 6 156 107 11
40480 -219 162 10 239 182 13 246 186 14 246 190 14
40481 -246 190 14 246 190 14 246 190 14 246 190 14
40482 -246 190 14 246 190 14 246 190 14 246 190 14
40483 -246 190 14 246 190 14 246 190 14 242 186 14
40484 -234 174 13 213 154 11 154 122 46 66 66 66
40485 - 30 30 30 10 10 10 0 0 0 0 0 0
40486 - 0 0 0 0 0 0 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 6 6 6 22 22 22
40489 - 58 58 58 154 121 60 206 145 10 234 174 13
40490 -242 186 14 246 186 14 246 190 14 246 190 14
40491 -246 190 14 246 190 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 186 14 236 178 12 210 162 10 163 110 8
40495 - 61 42 6 138 138 138 218 218 218 250 250 250
40496 -253 253 253 253 253 253 253 253 253 250 250 250
40497 -242 242 242 210 210 210 144 144 144 66 66 66
40498 - 6 6 6 2 2 6 2 2 6 2 2 6
40499 - 2 2 6 2 2 6 61 42 6 163 110 8
40500 -216 158 10 236 178 12 246 190 14 246 190 14
40501 -246 190 14 246 190 14 246 190 14 246 190 14
40502 -246 190 14 246 190 14 246 190 14 246 190 14
40503 -246 190 14 239 182 13 230 174 11 216 158 10
40504 -190 142 34 124 112 88 70 70 70 38 38 38
40505 - 18 18 18 6 6 6 0 0 0 0 0 0
40506 - 0 0 0 0 0 0 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 6 6 6 22 22 22
40509 - 62 62 62 168 124 44 206 145 10 224 166 10
40510 -236 178 12 239 182 13 242 186 14 242 186 14
40511 -246 186 14 246 190 14 246 190 14 246 190 14
40512 -246 190 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 236 178 12 216 158 10 175 118 6
40515 - 80 54 7 2 2 6 6 6 6 30 30 30
40516 - 54 54 54 62 62 62 50 50 50 38 38 38
40517 - 14 14 14 2 2 6 2 2 6 2 2 6
40518 - 2 2 6 2 2 6 2 2 6 2 2 6
40519 - 2 2 6 6 6 6 80 54 7 167 114 7
40520 -213 154 11 236 178 12 246 190 14 246 190 14
40521 -246 190 14 246 190 14 246 190 14 246 190 14
40522 -246 190 14 242 186 14 239 182 13 239 182 13
40523 -230 174 11 210 150 10 174 135 50 124 112 88
40524 - 82 82 82 54 54 54 34 34 34 18 18 18
40525 - 6 6 6 0 0 0 0 0 0 0 0 0
40526 - 0 0 0 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 6 6 6 18 18 18
40529 - 50 50 50 158 118 36 192 133 9 200 144 11
40530 -216 158 10 219 162 10 224 166 10 226 170 11
40531 -230 174 11 236 178 12 239 182 13 239 182 13
40532 -242 186 14 246 186 14 246 190 14 246 190 14
40533 -246 190 14 246 190 14 246 190 14 246 190 14
40534 -246 186 14 230 174 11 210 150 10 163 110 8
40535 -104 69 6 10 10 10 2 2 6 2 2 6
40536 - 2 2 6 2 2 6 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 6 6 6 91 60 6 167 114 7
40540 -206 145 10 230 174 11 242 186 14 246 190 14
40541 -246 190 14 246 190 14 246 186 14 242 186 14
40542 -239 182 13 230 174 11 224 166 10 213 154 11
40543 -180 133 36 124 112 88 86 86 86 58 58 58
40544 - 38 38 38 22 22 22 10 10 10 6 6 6
40545 - 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
40549 - 34 34 34 70 70 70 138 110 50 158 118 36
40550 -167 114 7 180 123 7 192 133 9 197 138 11
40551 -200 144 11 206 145 10 213 154 11 219 162 10
40552 -224 166 10 230 174 11 239 182 13 242 186 14
40553 -246 186 14 246 186 14 246 186 14 246 186 14
40554 -239 182 13 216 158 10 185 133 11 152 99 6
40555 -104 69 6 18 14 6 2 2 6 2 2 6
40556 - 2 2 6 2 2 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 6 6 6 80 54 7 152 99 6
40560 -192 133 9 219 162 10 236 178 12 239 182 13
40561 -246 186 14 242 186 14 239 182 13 236 178 12
40562 -224 166 10 206 145 10 192 133 9 154 121 60
40563 - 94 94 94 62 62 62 42 42 42 22 22 22
40564 - 14 14 14 6 6 6 0 0 0 0 0 0
40565 - 0 0 0 0 0 0 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 6 6 6
40569 - 18 18 18 34 34 34 58 58 58 78 78 78
40570 -101 98 89 124 112 88 142 110 46 156 107 11
40571 -163 110 8 167 114 7 175 118 6 180 123 7
40572 -185 133 11 197 138 11 210 150 10 219 162 10
40573 -226 170 11 236 178 12 236 178 12 234 174 13
40574 -219 162 10 197 138 11 163 110 8 130 83 6
40575 - 91 60 6 10 10 10 2 2 6 2 2 6
40576 - 18 18 18 38 38 38 38 38 38 38 38 38
40577 - 38 38 38 38 38 38 38 38 38 38 38 38
40578 - 38 38 38 38 38 38 26 26 26 2 2 6
40579 - 2 2 6 6 6 6 70 47 6 137 92 6
40580 -175 118 6 200 144 11 219 162 10 230 174 11
40581 -234 174 13 230 174 11 219 162 10 210 150 10
40582 -192 133 9 163 110 8 124 112 88 82 82 82
40583 - 50 50 50 30 30 30 14 14 14 6 6 6
40584 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 6 6 6 14 14 14 22 22 22 34 34 34
40590 - 42 42 42 58 58 58 74 74 74 86 86 86
40591 -101 98 89 122 102 70 130 98 46 121 87 25
40592 -137 92 6 152 99 6 163 110 8 180 123 7
40593 -185 133 11 197 138 11 206 145 10 200 144 11
40594 -180 123 7 156 107 11 130 83 6 104 69 6
40595 - 50 34 6 54 54 54 110 110 110 101 98 89
40596 - 86 86 86 82 82 82 78 78 78 78 78 78
40597 - 78 78 78 78 78 78 78 78 78 78 78 78
40598 - 78 78 78 82 82 82 86 86 86 94 94 94
40599 -106 106 106 101 101 101 86 66 34 124 80 6
40600 -156 107 11 180 123 7 192 133 9 200 144 11
40601 -206 145 10 200 144 11 192 133 9 175 118 6
40602 -139 102 15 109 106 95 70 70 70 42 42 42
40603 - 22 22 22 10 10 10 0 0 0 0 0 0
40604 - 0 0 0 0 0 0 0 0 0 0 0 0
40605 - 0 0 0 0 0 0 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 6 6 6 10 10 10
40610 - 14 14 14 22 22 22 30 30 30 38 38 38
40611 - 50 50 50 62 62 62 74 74 74 90 90 90
40612 -101 98 89 112 100 78 121 87 25 124 80 6
40613 -137 92 6 152 99 6 152 99 6 152 99 6
40614 -138 86 6 124 80 6 98 70 6 86 66 30
40615 -101 98 89 82 82 82 58 58 58 46 46 46
40616 - 38 38 38 34 34 34 34 34 34 34 34 34
40617 - 34 34 34 34 34 34 34 34 34 34 34 34
40618 - 34 34 34 34 34 34 38 38 38 42 42 42
40619 - 54 54 54 82 82 82 94 86 76 91 60 6
40620 -134 86 6 156 107 11 167 114 7 175 118 6
40621 -175 118 6 167 114 7 152 99 6 121 87 25
40622 -101 98 89 62 62 62 34 34 34 18 18 18
40623 - 6 6 6 0 0 0 0 0 0 0 0 0
40624 - 0 0 0 0 0 0 0 0 0 0 0 0
40625 - 0 0 0 0 0 0 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 6 6 6 6 6 6 10 10 10
40631 - 18 18 18 22 22 22 30 30 30 42 42 42
40632 - 50 50 50 66 66 66 86 86 86 101 98 89
40633 -106 86 58 98 70 6 104 69 6 104 69 6
40634 -104 69 6 91 60 6 82 62 34 90 90 90
40635 - 62 62 62 38 38 38 22 22 22 14 14 14
40636 - 10 10 10 10 10 10 10 10 10 10 10 10
40637 - 10 10 10 10 10 10 6 6 6 10 10 10
40638 - 10 10 10 10 10 10 10 10 10 14 14 14
40639 - 22 22 22 42 42 42 70 70 70 89 81 66
40640 - 80 54 7 104 69 6 124 80 6 137 92 6
40641 -134 86 6 116 81 8 100 82 52 86 86 86
40642 - 58 58 58 30 30 30 14 14 14 6 6 6
40643 - 0 0 0 0 0 0 0 0 0 0 0 0
40644 - 0 0 0 0 0 0 0 0 0 0 0 0
40645 - 0 0 0 0 0 0 0 0 0 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 6 6 6 10 10 10 14 14 14
40652 - 18 18 18 26 26 26 38 38 38 54 54 54
40653 - 70 70 70 86 86 86 94 86 76 89 81 66
40654 - 89 81 66 86 86 86 74 74 74 50 50 50
40655 - 30 30 30 14 14 14 6 6 6 0 0 0
40656 - 0 0 0 0 0 0 0 0 0 0 0 0
40657 - 0 0 0 0 0 0 0 0 0 0 0 0
40658 - 0 0 0 0 0 0 0 0 0 0 0 0
40659 - 6 6 6 18 18 18 34 34 34 58 58 58
40660 - 82 82 82 89 81 66 89 81 66 89 81 66
40661 - 94 86 66 94 86 76 74 74 74 50 50 50
40662 - 26 26 26 14 14 14 6 6 6 0 0 0
40663 - 0 0 0 0 0 0 0 0 0 0 0 0
40664 - 0 0 0 0 0 0 0 0 0 0 0 0
40665 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 6 6 6 14 14 14 18 18 18
40673 - 30 30 30 38 38 38 46 46 46 54 54 54
40674 - 50 50 50 42 42 42 30 30 30 18 18 18
40675 - 10 10 10 0 0 0 0 0 0 0 0 0
40676 - 0 0 0 0 0 0 0 0 0 0 0 0
40677 - 0 0 0 0 0 0 0 0 0 0 0 0
40678 - 0 0 0 0 0 0 0 0 0 0 0 0
40679 - 0 0 0 6 6 6 14 14 14 26 26 26
40680 - 38 38 38 50 50 50 58 58 58 58 58 58
40681 - 54 54 54 42 42 42 30 30 30 18 18 18
40682 - 10 10 10 0 0 0 0 0 0 0 0 0
40683 - 0 0 0 0 0 0 0 0 0 0 0 0
40684 - 0 0 0 0 0 0 0 0 0 0 0 0
40685 - 0 0 0 0 0 0 0 0 0 0 0 0
40686 - 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 6 6 6
40693 - 6 6 6 10 10 10 14 14 14 18 18 18
40694 - 18 18 18 14 14 14 10 10 10 6 6 6
40695 - 0 0 0 0 0 0 0 0 0 0 0 0
40696 - 0 0 0 0 0 0 0 0 0 0 0 0
40697 - 0 0 0 0 0 0 0 0 0 0 0 0
40698 - 0 0 0 0 0 0 0 0 0 0 0 0
40699 - 0 0 0 0 0 0 0 0 0 6 6 6
40700 - 14 14 14 18 18 18 22 22 22 22 22 22
40701 - 18 18 18 14 14 14 10 10 10 6 6 6
40702 - 0 0 0 0 0 0 0 0 0 0 0 0
40703 - 0 0 0 0 0 0 0 0 0 0 0 0
40704 - 0 0 0 0 0 0 0 0 0 0 0 0
40705 - 0 0 0 0 0 0 0 0 0 0 0 0
40706 - 0 0 0 0 0 0 0 0 0 0 0 0
40707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40708 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40710 +4 4 4 4 4 4 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
40721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40724 +4 4 4 4 4 4 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
40735 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40736 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40738 +4 4 4 4 4 4 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
40749 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40750 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40752 +4 4 4 4 4 4 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
40763 +4 4 4 4 4 4 4 4 4 4 4 4 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
40777 +4 4 4 4 4 4 4 4 4 4 4 4 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
40791 +4 4 4 4 4 4 4 4 4 4 4 4 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 3 3 3 0 0 0 0 0 0
40796 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40797 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40798 +4 4 4 4 4 4 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 1 1 1 0 0 0
40801 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40802 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40803 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40804 +4 4 4 4 4 4
40805 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40806 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40807 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40809 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40810 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40811 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40812 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40813 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40814 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40815 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40816 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40817 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40818 +4 4 4 4 4 4
40819 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40820 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40821 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40823 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40824 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40825 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40826 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40827 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40828 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40829 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40830 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40831 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40832 +4 4 4 4 4 4
40833 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40834 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40836 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40837 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40838 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40839 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40840 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40841 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40842 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40843 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40844 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40845 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40846 +4 4 4 4 4 4
40847 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40848 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40850 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40851 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40852 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40853 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40854 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40855 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40856 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40857 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40858 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40859 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40860 +4 4 4 4 4 4
40861 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40862 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40864 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40865 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40866 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40867 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40868 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40869 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40870 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40871 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40872 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40873 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40874 +4 4 4 4 4 4
40875 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40876 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40877 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40878 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40879 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40880 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40881 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40882 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40883 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40884 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40885 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40886 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40887 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40888 +4 4 4 4 4 4
40889 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40890 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40891 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40892 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40893 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40894 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40895 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40896 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40897 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40898 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40899 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40900 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40901 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40902 +4 4 4 4 4 4
40903 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40904 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40905 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40906 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40907 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40908 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40909 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40910 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40911 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40912 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40913 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40914 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40915 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40916 +4 4 4 4 4 4
40917 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40918 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40919 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40920 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40921 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40922 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40923 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40924 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40925 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40926 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40927 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40928 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40929 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40930 +4 4 4 4 4 4
40931 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40932 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40933 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40934 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40935 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40936 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40937 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40938 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40939 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40940 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40941 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40942 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40943 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40944 +4 4 4 4 4 4
40945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40946 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40947 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40948 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40949 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40950 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40951 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40952 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40953 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40954 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40955 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40956 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40957 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40958 +0 0 0 4 4 4
40959 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40960 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40961 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40962 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40963 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40964 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40965 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40966 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40967 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40968 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40969 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40970 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40971 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40972 +2 0 0 0 0 0
40973 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40974 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40975 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40976 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40977 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40978 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40979 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40980 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40981 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40982 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40983 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40984 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40985 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40986 +37 38 37 0 0 0
40987 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40988 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40989 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40990 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40991 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40992 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40993 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40994 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40995 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40996 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40997 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40998 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40999 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41000 +85 115 134 4 0 0
41001 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41002 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41003 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41004 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41005 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41006 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41007 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41008 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41009 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41010 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41011 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41012 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41013 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41014 +60 73 81 4 0 0
41015 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41016 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41017 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41018 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41019 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41020 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41021 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41022 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41023 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41024 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41025 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41026 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41027 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41028 +16 19 21 4 0 0
41029 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41030 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41031 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41032 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41033 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41034 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41035 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41036 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41037 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41038 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41039 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41040 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41041 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41042 +4 0 0 4 3 3
41043 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41044 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41045 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41047 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41048 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41049 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41050 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41051 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41052 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41053 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41054 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41055 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41056 +3 2 2 4 4 4
41057 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41058 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41059 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41060 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41061 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41062 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41063 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41064 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41065 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41066 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41067 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41068 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41069 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41070 +4 4 4 4 4 4
41071 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41072 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41073 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41074 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41075 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41076 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41077 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41078 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41079 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41080 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41081 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41082 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41083 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41084 +4 4 4 4 4 4
41085 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41086 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41087 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41088 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41089 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41090 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41091 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41092 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41093 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41094 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41095 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41096 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41097 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41098 +5 5 5 5 5 5
41099 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41100 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41101 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41102 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41103 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41104 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41105 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41106 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41107 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41108 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41109 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41110 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41111 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41112 +5 5 5 4 4 4
41113 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41114 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41115 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41116 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41117 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41118 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41119 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41120 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41121 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41122 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41123 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41124 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41126 +4 4 4 4 4 4
41127 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41128 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41129 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41130 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41131 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41132 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41133 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41134 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41135 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41136 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41137 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41138 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41140 +4 4 4 4 4 4
41141 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41142 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41143 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41144 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41145 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41146 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41147 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41148 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41149 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41150 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41151 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
41155 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41156 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41157 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41158 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41159 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41160 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41161 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41162 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41163 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41164 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41165 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41166 +4 4 4 4 4 4 4 4 4 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
41169 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41170 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41171 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41172 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41173 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41174 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41175 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41176 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41177 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41178 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41179 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41180 +4 4 4 4 4 4 4 4 4 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
41183 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41184 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41185 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41186 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41187 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41188 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41189 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41190 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41191 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41192 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41193 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41194 +4 4 4 4 4 4 4 4 4 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
41197 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41198 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41199 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41200 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41201 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41202 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41203 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41204 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41205 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41206 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41207 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41208 +4 4 4 4 4 4 4 4 4 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
41211 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41212 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41213 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41214 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41215 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41216 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41217 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41218 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41219 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41220 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41221 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41224 +4 4 4 4 4 4
41225 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41226 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41227 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41228 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41229 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41230 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41231 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41232 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41233 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41234 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41235 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41238 +4 4 4 4 4 4
41239 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41240 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41241 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41242 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41243 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41244 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41245 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41246 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41247 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41248 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41249 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41252 +4 4 4 4 4 4
41253 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41254 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41255 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41256 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41257 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41258 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41259 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41260 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41261 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41262 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41263 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41266 +4 4 4 4 4 4
41267 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41268 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41269 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41270 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41271 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41272 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41273 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41274 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41275 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41276 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41277 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41280 +4 4 4 4 4 4
41281 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41282 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41283 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41284 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41285 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41286 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41287 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41288 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41289 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41290 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41291 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41294 +4 4 4 4 4 4
41295 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41296 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41297 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41298 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41299 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41300 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41301 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41302 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41303 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41304 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41305 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41308 +4 4 4 4 4 4
41309 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41310 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41311 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41312 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41313 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41314 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41315 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41316 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41317 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41318 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41319 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41322 +4 4 4 4 4 4
41323 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41324 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41325 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41326 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41327 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41328 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41329 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41330 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41331 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41332 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41333 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41336 +4 4 4 4 4 4
41337 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41338 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41339 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41340 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41341 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41342 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41343 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41344 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41345 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41346 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41347 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41350 +4 4 4 4 4 4
41351 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41352 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41353 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41354 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41355 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41356 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41357 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41358 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41359 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41360 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41361 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41364 +4 4 4 4 4 4
41365 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41366 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41367 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41368 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41369 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41370 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41371 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41372 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41373 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41374 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41375 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41378 +4 4 4 4 4 4
41379 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41380 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41381 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41382 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41383 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41384 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41385 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41386 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41387 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41388 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41389 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41392 +4 4 4 4 4 4
41393 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41394 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41395 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41396 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41397 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41398 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41399 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41400 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41401 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41402 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41403 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41406 +4 4 4 4 4 4
41407 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41408 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41409 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41410 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41411 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41412 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41413 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41414 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41415 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41416 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41417 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41418 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41420 +4 4 4 4 4 4
41421 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41422 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41423 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41424 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41425 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41426 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41427 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41428 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41429 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41430 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41431 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41432 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41433 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41434 +4 4 4 4 4 4
41435 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41436 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41437 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41438 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41439 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41440 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41441 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41442 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41443 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41444 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41445 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41447 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41448 +4 4 4 4 4 4
41449 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41450 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41451 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41452 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41453 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41454 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41455 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41456 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41457 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41458 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41459 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41461 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41462 +4 4 4 4 4 4
41463 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41464 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41465 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41466 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41467 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41468 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41469 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41470 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41471 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41472 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41473 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41475 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41476 +4 4 4 4 4 4
41477 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41478 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41479 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41480 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41481 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41482 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41483 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41484 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41485 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41486 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41487 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41489 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41490 +4 4 4 4 4 4
41491 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41492 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41493 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41494 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41495 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41496 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41497 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41498 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41499 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41500 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41501 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41504 +4 4 4 4 4 4
41505 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41506 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41507 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41508 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41509 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41510 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41511 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41512 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41513 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41514 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41515 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41517 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41518 +4 4 4 4 4 4
41519 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41520 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41521 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41522 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41523 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41524 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41525 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41526 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41527 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41528 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41530 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41531 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41532 +4 4 4 4 4 4
41533 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41534 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41535 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41536 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41537 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41538 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41539 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41540 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41541 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41542 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41543 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41544 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41545 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41546 +4 4 4 4 4 4
41547 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41548 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41549 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41550 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41551 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41552 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41553 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41554 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41555 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41556 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41557 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41559 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41560 +4 4 4 4 4 4
41561 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41562 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41563 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41564 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41565 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41566 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41567 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41568 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41569 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41570 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41573 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41574 +4 4 4 4 4 4
41575 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41576 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41577 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41578 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41579 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41580 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41581 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41582 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41583 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41587 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41588 +4 4 4 4 4 4
41589 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41590 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41591 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41592 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41593 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41594 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41595 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41596 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41597 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41601 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41602 +4 4 4 4 4 4
41603 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41604 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41605 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41606 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41607 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41608 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41609 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41610 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41611 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41612 +4 4 4 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
41617 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41618 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41619 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41620 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41621 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41622 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41623 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41624 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
41631 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41632 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41633 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41634 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41635 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41636 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41637 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41638 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41639 +4 4 4 4 4 4 4 4 4 4 4 4 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
41645 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41646 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41647 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41648 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41649 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41650 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41651 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41652 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
41653 +4 4 4 4 4 4 4 4 4 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
41659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41660 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41661 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41662 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41663 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41664 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41665 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41666 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41672 +4 4 4 4 4 4
41673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41674 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41675 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41676 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41677 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41678 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41679 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41680 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41686 +4 4 4 4 4 4
41687 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41689 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41690 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41691 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41692 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41693 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41694 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41699 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41700 +4 4 4 4 4 4
41701 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41704 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41705 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41706 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41707 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
41708 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41714 +4 4 4 4 4 4
41715 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41718 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41719 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41720 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41721 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41728 +4 4 4 4 4 4
41729 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41732 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41733 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41734 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41735 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
41736 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41741 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41742 +4 4 4 4 4 4
41743 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41746 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41747 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41748 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41749 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
41750 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41755 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41756 +4 4 4 4 4 4
41757 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41761 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41762 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41763 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41764 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41769 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41770 +4 4 4 4 4 4
41771 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41775 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41776 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41777 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41778 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41781 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41783 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41784 +4 4 4 4 4 4
41785 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41789 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41790 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41791 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41792 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41795 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41796 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41797 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41798 +4 4 4 4 4 4
41799 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3 6 6 6
41804 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41805 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41806 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41807 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41809 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41810 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41811 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41812 +4 4 4 4 4 4
41813 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41815 +4 4 4 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 5 5 5 4 3 3
41818 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41819 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41820 +4 4 4 4 4 4 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
41827 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41828 index 8af6414..658c030 100644
41829 --- a/drivers/video/udlfb.c
41830 +++ b/drivers/video/udlfb.c
41831 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41832 dlfb_urb_completion(urb);
41833
41834 error:
41835 - atomic_add(bytes_sent, &dev->bytes_sent);
41836 - atomic_add(bytes_identical, &dev->bytes_identical);
41837 - atomic_add(width*height*2, &dev->bytes_rendered);
41838 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41839 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41840 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41841 end_cycles = get_cycles();
41842 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41843 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41844 >> 10)), /* Kcycles */
41845 &dev->cpu_kcycles_used);
41846
41847 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41848 dlfb_urb_completion(urb);
41849
41850 error:
41851 - atomic_add(bytes_sent, &dev->bytes_sent);
41852 - atomic_add(bytes_identical, &dev->bytes_identical);
41853 - atomic_add(bytes_rendered, &dev->bytes_rendered);
41854 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41855 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41856 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41857 end_cycles = get_cycles();
41858 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41859 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41860 >> 10)), /* Kcycles */
41861 &dev->cpu_kcycles_used);
41862 }
41863 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41864 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41865 struct dlfb_data *dev = fb_info->par;
41866 return snprintf(buf, PAGE_SIZE, "%u\n",
41867 - atomic_read(&dev->bytes_rendered));
41868 + atomic_read_unchecked(&dev->bytes_rendered));
41869 }
41870
41871 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41872 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41873 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41874 struct dlfb_data *dev = fb_info->par;
41875 return snprintf(buf, PAGE_SIZE, "%u\n",
41876 - atomic_read(&dev->bytes_identical));
41877 + atomic_read_unchecked(&dev->bytes_identical));
41878 }
41879
41880 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41881 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41882 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41883 struct dlfb_data *dev = fb_info->par;
41884 return snprintf(buf, PAGE_SIZE, "%u\n",
41885 - atomic_read(&dev->bytes_sent));
41886 + atomic_read_unchecked(&dev->bytes_sent));
41887 }
41888
41889 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41890 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41891 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41892 struct dlfb_data *dev = fb_info->par;
41893 return snprintf(buf, PAGE_SIZE, "%u\n",
41894 - atomic_read(&dev->cpu_kcycles_used));
41895 + atomic_read_unchecked(&dev->cpu_kcycles_used));
41896 }
41897
41898 static ssize_t edid_show(
41899 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41900 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41901 struct dlfb_data *dev = fb_info->par;
41902
41903 - atomic_set(&dev->bytes_rendered, 0);
41904 - atomic_set(&dev->bytes_identical, 0);
41905 - atomic_set(&dev->bytes_sent, 0);
41906 - atomic_set(&dev->cpu_kcycles_used, 0);
41907 + atomic_set_unchecked(&dev->bytes_rendered, 0);
41908 + atomic_set_unchecked(&dev->bytes_identical, 0);
41909 + atomic_set_unchecked(&dev->bytes_sent, 0);
41910 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41911
41912 return count;
41913 }
41914 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41915 index b0e2a42..e2df3ad 100644
41916 --- a/drivers/video/uvesafb.c
41917 +++ b/drivers/video/uvesafb.c
41918 @@ -19,6 +19,7 @@
41919 #include <linux/io.h>
41920 #include <linux/mutex.h>
41921 #include <linux/slab.h>
41922 +#include <linux/moduleloader.h>
41923 #include <video/edid.h>
41924 #include <video/uvesafb.h>
41925 #ifdef CONFIG_X86
41926 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41927 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41928 par->pmi_setpal = par->ypan = 0;
41929 } else {
41930 +
41931 +#ifdef CONFIG_PAX_KERNEXEC
41932 +#ifdef CONFIG_MODULES
41933 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41934 +#endif
41935 + if (!par->pmi_code) {
41936 + par->pmi_setpal = par->ypan = 0;
41937 + return 0;
41938 + }
41939 +#endif
41940 +
41941 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41942 + task->t.regs.edi);
41943 +
41944 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41945 + pax_open_kernel();
41946 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41947 + pax_close_kernel();
41948 +
41949 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41950 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41951 +#else
41952 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41953 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41954 +#endif
41955 +
41956 printk(KERN_INFO "uvesafb: protected mode interface info at "
41957 "%04x:%04x\n",
41958 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41959 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
41960 par->ypan = ypan;
41961
41962 if (par->pmi_setpal || par->ypan) {
41963 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
41964 if (__supported_pte_mask & _PAGE_NX) {
41965 par->pmi_setpal = par->ypan = 0;
41966 printk(KERN_WARNING "uvesafb: NX protection is actively."
41967 "We have better not to use the PMI.\n");
41968 - } else {
41969 + } else
41970 +#endif
41971 uvesafb_vbe_getpmi(task, par);
41972 - }
41973 }
41974 #else
41975 /* The protected mode interface is not available on non-x86. */
41976 @@ -1836,6 +1860,11 @@ out:
41977 if (par->vbe_modes)
41978 kfree(par->vbe_modes);
41979
41980 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41981 + if (par->pmi_code)
41982 + module_free_exec(NULL, par->pmi_code);
41983 +#endif
41984 +
41985 framebuffer_release(info);
41986 return err;
41987 }
41988 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
41989 kfree(par->vbe_state_orig);
41990 if (par->vbe_state_saved)
41991 kfree(par->vbe_state_saved);
41992 +
41993 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41994 + if (par->pmi_code)
41995 + module_free_exec(NULL, par->pmi_code);
41996 +#endif
41997 +
41998 }
41999
42000 framebuffer_release(info);
42001 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42002 index 501b340..86bd4cf 100644
42003 --- a/drivers/video/vesafb.c
42004 +++ b/drivers/video/vesafb.c
42005 @@ -9,6 +9,7 @@
42006 */
42007
42008 #include <linux/module.h>
42009 +#include <linux/moduleloader.h>
42010 #include <linux/kernel.h>
42011 #include <linux/errno.h>
42012 #include <linux/string.h>
42013 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42014 static int vram_total __initdata; /* Set total amount of memory */
42015 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42016 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42017 -static void (*pmi_start)(void) __read_mostly;
42018 -static void (*pmi_pal) (void) __read_mostly;
42019 +static void (*pmi_start)(void) __read_only;
42020 +static void (*pmi_pal) (void) __read_only;
42021 static int depth __read_mostly;
42022 static int vga_compat __read_mostly;
42023 /* --------------------------------------------------------------------- */
42024 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42025 unsigned int size_vmode;
42026 unsigned int size_remap;
42027 unsigned int size_total;
42028 + void *pmi_code = NULL;
42029
42030 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42031 return -ENODEV;
42032 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42033 size_remap = size_total;
42034 vesafb_fix.smem_len = size_remap;
42035
42036 -#ifndef __i386__
42037 - screen_info.vesapm_seg = 0;
42038 -#endif
42039 -
42040 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42041 printk(KERN_WARNING
42042 "vesafb: cannot reserve video memory at 0x%lx\n",
42043 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42044 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42045 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42046
42047 +#ifdef __i386__
42048 +
42049 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42050 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42051 + if (!pmi_code)
42052 +#elif !defined(CONFIG_PAX_KERNEXEC)
42053 + if (0)
42054 +#endif
42055 +
42056 +#endif
42057 + screen_info.vesapm_seg = 0;
42058 +
42059 if (screen_info.vesapm_seg) {
42060 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42061 - screen_info.vesapm_seg,screen_info.vesapm_off);
42062 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42063 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42064 }
42065
42066 if (screen_info.vesapm_seg < 0xc000)
42067 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42068
42069 if (ypan || pmi_setpal) {
42070 unsigned short *pmi_base;
42071 +
42072 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42073 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42074 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42075 +
42076 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42077 + pax_open_kernel();
42078 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42079 +#else
42080 + pmi_code = pmi_base;
42081 +#endif
42082 +
42083 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42084 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42085 +
42086 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42087 + pmi_start = ktva_ktla(pmi_start);
42088 + pmi_pal = ktva_ktla(pmi_pal);
42089 + pax_close_kernel();
42090 +#endif
42091 +
42092 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42093 if (pmi_base[3]) {
42094 printk(KERN_INFO "vesafb: pmi: ports = ");
42095 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42096 info->node, info->fix.id);
42097 return 0;
42098 err:
42099 +
42100 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42101 + module_free_exec(NULL, pmi_code);
42102 +#endif
42103 +
42104 if (info->screen_base)
42105 iounmap(info->screen_base);
42106 framebuffer_release(info);
42107 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42108 index 88714ae..16c2e11 100644
42109 --- a/drivers/video/via/via_clock.h
42110 +++ b/drivers/video/via/via_clock.h
42111 @@ -56,7 +56,7 @@ struct via_clock {
42112
42113 void (*set_engine_pll_state)(u8 state);
42114 void (*set_engine_pll)(struct via_pll_config config);
42115 -};
42116 +} __no_const;
42117
42118
42119 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42120 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42121 index e56c934..fc22f4b 100644
42122 --- a/drivers/xen/xen-pciback/conf_space.h
42123 +++ b/drivers/xen/xen-pciback/conf_space.h
42124 @@ -44,15 +44,15 @@ struct config_field {
42125 struct {
42126 conf_dword_write write;
42127 conf_dword_read read;
42128 - } dw;
42129 + } __no_const dw;
42130 struct {
42131 conf_word_write write;
42132 conf_word_read read;
42133 - } w;
42134 + } __no_const w;
42135 struct {
42136 conf_byte_write write;
42137 conf_byte_read read;
42138 - } b;
42139 + } __no_const b;
42140 } u;
42141 struct list_head list;
42142 };
42143 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42144 index 57ccb75..f6d05f8 100644
42145 --- a/fs/9p/vfs_inode.c
42146 +++ b/fs/9p/vfs_inode.c
42147 @@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42148 void
42149 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42150 {
42151 - char *s = nd_get_link(nd);
42152 + const char *s = nd_get_link(nd);
42153
42154 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42155 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42156 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42157 index 0225742..1cd4732 100644
42158 --- a/fs/Kconfig.binfmt
42159 +++ b/fs/Kconfig.binfmt
42160 @@ -89,7 +89,7 @@ config HAVE_AOUT
42161
42162 config BINFMT_AOUT
42163 tristate "Kernel support for a.out and ECOFF binaries"
42164 - depends on HAVE_AOUT
42165 + depends on HAVE_AOUT && BROKEN
42166 ---help---
42167 A.out (Assembler.OUTput) is a set of formats for libraries and
42168 executables used in the earliest versions of UNIX. Linux used
42169 diff --git a/fs/aio.c b/fs/aio.c
42170 index 55c4c76..11aee6f 100644
42171 --- a/fs/aio.c
42172 +++ b/fs/aio.c
42173 @@ -118,7 +118,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42174 size += sizeof(struct io_event) * nr_events;
42175 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42176
42177 - if (nr_pages < 0)
42178 + if (nr_pages <= 0)
42179 return -EINVAL;
42180
42181 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42182 @@ -1440,18 +1440,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42183 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42184 {
42185 ssize_t ret;
42186 + struct iovec iovstack;
42187
42188 #ifdef CONFIG_COMPAT
42189 if (compat)
42190 ret = compat_rw_copy_check_uvector(type,
42191 (struct compat_iovec __user *)kiocb->ki_buf,
42192 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42193 + kiocb->ki_nbytes, 1, &iovstack,
42194 &kiocb->ki_iovec);
42195 else
42196 #endif
42197 ret = rw_copy_check_uvector(type,
42198 (struct iovec __user *)kiocb->ki_buf,
42199 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42200 + kiocb->ki_nbytes, 1, &iovstack,
42201 &kiocb->ki_iovec);
42202 if (ret < 0)
42203 goto out;
42204 @@ -1460,6 +1461,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42205 if (ret < 0)
42206 goto out;
42207
42208 + if (kiocb->ki_iovec == &iovstack) {
42209 + kiocb->ki_inline_vec = iovstack;
42210 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42211 + }
42212 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42213 kiocb->ki_cur_seg = 0;
42214 /* ki_nbytes/left now reflect bytes instead of segs */
42215 diff --git a/fs/attr.c b/fs/attr.c
42216 index 0da9095..1386693 100644
42217 --- a/fs/attr.c
42218 +++ b/fs/attr.c
42219 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42220 unsigned long limit;
42221
42222 limit = rlimit(RLIMIT_FSIZE);
42223 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42224 if (limit != RLIM_INFINITY && offset > limit)
42225 goto out_sig;
42226 if (offset > inode->i_sb->s_maxbytes)
42227 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42228 index da8876d..9f3e6d8 100644
42229 --- a/fs/autofs4/waitq.c
42230 +++ b/fs/autofs4/waitq.c
42231 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42232 {
42233 unsigned long sigpipe, flags;
42234 mm_segment_t fs;
42235 - const char *data = (const char *)addr;
42236 + const char __user *data = (const char __force_user *)addr;
42237 ssize_t wr = 0;
42238
42239 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42240 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42241 index e18da23..affc30e 100644
42242 --- a/fs/befs/linuxvfs.c
42243 +++ b/fs/befs/linuxvfs.c
42244 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42245 {
42246 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42247 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42248 - char *link = nd_get_link(nd);
42249 + const char *link = nd_get_link(nd);
42250 if (!IS_ERR(link))
42251 kfree(link);
42252 }
42253 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42254 index d146e18..12d1bd1 100644
42255 --- a/fs/binfmt_aout.c
42256 +++ b/fs/binfmt_aout.c
42257 @@ -16,6 +16,7 @@
42258 #include <linux/string.h>
42259 #include <linux/fs.h>
42260 #include <linux/file.h>
42261 +#include <linux/security.h>
42262 #include <linux/stat.h>
42263 #include <linux/fcntl.h>
42264 #include <linux/ptrace.h>
42265 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42266 #endif
42267 # define START_STACK(u) ((void __user *)u.start_stack)
42268
42269 + memset(&dump, 0, sizeof(dump));
42270 +
42271 fs = get_fs();
42272 set_fs(KERNEL_DS);
42273 has_dumped = 1;
42274 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42275
42276 /* If the size of the dump file exceeds the rlimit, then see what would happen
42277 if we wrote the stack, but not the data area. */
42278 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42279 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42280 dump.u_dsize = 0;
42281
42282 /* Make sure we have enough room to write the stack and data areas. */
42283 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42284 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42285 dump.u_ssize = 0;
42286
42287 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42288 rlim = rlimit(RLIMIT_DATA);
42289 if (rlim >= RLIM_INFINITY)
42290 rlim = ~0;
42291 +
42292 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42293 if (ex.a_data + ex.a_bss > rlim)
42294 return -ENOMEM;
42295
42296 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42297
42298 install_exec_creds(bprm);
42299
42300 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42301 + current->mm->pax_flags = 0UL;
42302 +#endif
42303 +
42304 +#ifdef CONFIG_PAX_PAGEEXEC
42305 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42306 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42307 +
42308 +#ifdef CONFIG_PAX_EMUTRAMP
42309 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42310 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42311 +#endif
42312 +
42313 +#ifdef CONFIG_PAX_MPROTECT
42314 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42315 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42316 +#endif
42317 +
42318 + }
42319 +#endif
42320 +
42321 if (N_MAGIC(ex) == OMAGIC) {
42322 unsigned long text_addr, map_size;
42323 loff_t pos;
42324 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42325 }
42326
42327 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42328 - PROT_READ | PROT_WRITE | PROT_EXEC,
42329 + PROT_READ | PROT_WRITE,
42330 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42331 fd_offset + ex.a_text);
42332 if (error != N_DATADDR(ex)) {
42333 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42334 index 1b52956..271266e 100644
42335 --- a/fs/binfmt_elf.c
42336 +++ b/fs/binfmt_elf.c
42337 @@ -32,6 +32,7 @@
42338 #include <linux/elf.h>
42339 #include <linux/utsname.h>
42340 #include <linux/coredump.h>
42341 +#include <linux/xattr.h>
42342 #include <asm/uaccess.h>
42343 #include <asm/param.h>
42344 #include <asm/page.h>
42345 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42346 #define elf_core_dump NULL
42347 #endif
42348
42349 +#ifdef CONFIG_PAX_MPROTECT
42350 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42351 +#endif
42352 +
42353 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42354 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42355 #else
42356 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42357 .load_binary = load_elf_binary,
42358 .load_shlib = load_elf_library,
42359 .core_dump = elf_core_dump,
42360 +
42361 +#ifdef CONFIG_PAX_MPROTECT
42362 + .handle_mprotect= elf_handle_mprotect,
42363 +#endif
42364 +
42365 .min_coredump = ELF_EXEC_PAGESIZE,
42366 };
42367
42368 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42369
42370 static int set_brk(unsigned long start, unsigned long end)
42371 {
42372 + unsigned long e = end;
42373 +
42374 start = ELF_PAGEALIGN(start);
42375 end = ELF_PAGEALIGN(end);
42376 if (end > start) {
42377 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42378 if (BAD_ADDR(addr))
42379 return addr;
42380 }
42381 - current->mm->start_brk = current->mm->brk = end;
42382 + current->mm->start_brk = current->mm->brk = e;
42383 return 0;
42384 }
42385
42386 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42387 elf_addr_t __user *u_rand_bytes;
42388 const char *k_platform = ELF_PLATFORM;
42389 const char *k_base_platform = ELF_BASE_PLATFORM;
42390 - unsigned char k_rand_bytes[16];
42391 + u32 k_rand_bytes[4];
42392 int items;
42393 elf_addr_t *elf_info;
42394 int ei_index = 0;
42395 const struct cred *cred = current_cred();
42396 struct vm_area_struct *vma;
42397 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42398
42399 /*
42400 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42401 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42402 * Generate 16 random bytes for userspace PRNG seeding.
42403 */
42404 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42405 - u_rand_bytes = (elf_addr_t __user *)
42406 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42407 + srandom32(k_rand_bytes[0] ^ random32());
42408 + srandom32(k_rand_bytes[1] ^ random32());
42409 + srandom32(k_rand_bytes[2] ^ random32());
42410 + srandom32(k_rand_bytes[3] ^ random32());
42411 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42412 + u_rand_bytes = (elf_addr_t __user *) p;
42413 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42414 return -EFAULT;
42415
42416 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42417 return -EFAULT;
42418 current->mm->env_end = p;
42419
42420 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42421 +
42422 /* Put the elf_info on the stack in the right place. */
42423 sp = (elf_addr_t __user *)envp + 1;
42424 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42425 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42426 return -EFAULT;
42427 return 0;
42428 }
42429 @@ -378,10 +397,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42430 {
42431 struct elf_phdr *elf_phdata;
42432 struct elf_phdr *eppnt;
42433 - unsigned long load_addr = 0;
42434 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42435 int load_addr_set = 0;
42436 unsigned long last_bss = 0, elf_bss = 0;
42437 - unsigned long error = ~0UL;
42438 + unsigned long error = -EINVAL;
42439 unsigned long total_size;
42440 int retval, i, size;
42441
42442 @@ -427,6 +446,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42443 goto out_close;
42444 }
42445
42446 +#ifdef CONFIG_PAX_SEGMEXEC
42447 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42448 + pax_task_size = SEGMEXEC_TASK_SIZE;
42449 +#endif
42450 +
42451 eppnt = elf_phdata;
42452 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42453 if (eppnt->p_type == PT_LOAD) {
42454 @@ -470,8 +494,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42455 k = load_addr + eppnt->p_vaddr;
42456 if (BAD_ADDR(k) ||
42457 eppnt->p_filesz > eppnt->p_memsz ||
42458 - eppnt->p_memsz > TASK_SIZE ||
42459 - TASK_SIZE - eppnt->p_memsz < k) {
42460 + eppnt->p_memsz > pax_task_size ||
42461 + pax_task_size - eppnt->p_memsz < k) {
42462 error = -ENOMEM;
42463 goto out_close;
42464 }
42465 @@ -523,6 +547,311 @@ out:
42466 return error;
42467 }
42468
42469 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42470 +#ifdef CONFIG_PAX_SOFTMODE
42471 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42472 +{
42473 + unsigned long pax_flags = 0UL;
42474 +
42475 +#ifdef CONFIG_PAX_PAGEEXEC
42476 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42477 + pax_flags |= MF_PAX_PAGEEXEC;
42478 +#endif
42479 +
42480 +#ifdef CONFIG_PAX_SEGMEXEC
42481 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42482 + pax_flags |= MF_PAX_SEGMEXEC;
42483 +#endif
42484 +
42485 +#ifdef CONFIG_PAX_EMUTRAMP
42486 + if (elf_phdata->p_flags & PF_EMUTRAMP)
42487 + pax_flags |= MF_PAX_EMUTRAMP;
42488 +#endif
42489 +
42490 +#ifdef CONFIG_PAX_MPROTECT
42491 + if (elf_phdata->p_flags & PF_MPROTECT)
42492 + pax_flags |= MF_PAX_MPROTECT;
42493 +#endif
42494 +
42495 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42496 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42497 + pax_flags |= MF_PAX_RANDMMAP;
42498 +#endif
42499 +
42500 + return pax_flags;
42501 +}
42502 +#endif
42503 +
42504 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42505 +{
42506 + unsigned long pax_flags = 0UL;
42507 +
42508 +#ifdef CONFIG_PAX_PAGEEXEC
42509 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42510 + pax_flags |= MF_PAX_PAGEEXEC;
42511 +#endif
42512 +
42513 +#ifdef CONFIG_PAX_SEGMEXEC
42514 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42515 + pax_flags |= MF_PAX_SEGMEXEC;
42516 +#endif
42517 +
42518 +#ifdef CONFIG_PAX_EMUTRAMP
42519 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42520 + pax_flags |= MF_PAX_EMUTRAMP;
42521 +#endif
42522 +
42523 +#ifdef CONFIG_PAX_MPROTECT
42524 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42525 + pax_flags |= MF_PAX_MPROTECT;
42526 +#endif
42527 +
42528 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42529 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42530 + pax_flags |= MF_PAX_RANDMMAP;
42531 +#endif
42532 +
42533 + return pax_flags;
42534 +}
42535 +#endif
42536 +
42537 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42538 +#ifdef CONFIG_PAX_SOFTMODE
42539 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42540 +{
42541 + unsigned long pax_flags = 0UL;
42542 +
42543 +#ifdef CONFIG_PAX_PAGEEXEC
42544 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42545 + pax_flags |= MF_PAX_PAGEEXEC;
42546 +#endif
42547 +
42548 +#ifdef CONFIG_PAX_SEGMEXEC
42549 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42550 + pax_flags |= MF_PAX_SEGMEXEC;
42551 +#endif
42552 +
42553 +#ifdef CONFIG_PAX_EMUTRAMP
42554 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42555 + pax_flags |= MF_PAX_EMUTRAMP;
42556 +#endif
42557 +
42558 +#ifdef CONFIG_PAX_MPROTECT
42559 + if (pax_flags_softmode & MF_PAX_MPROTECT)
42560 + pax_flags |= MF_PAX_MPROTECT;
42561 +#endif
42562 +
42563 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42564 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42565 + pax_flags |= MF_PAX_RANDMMAP;
42566 +#endif
42567 +
42568 + return pax_flags;
42569 +}
42570 +#endif
42571 +
42572 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42573 +{
42574 + unsigned long pax_flags = 0UL;
42575 +
42576 +#ifdef CONFIG_PAX_PAGEEXEC
42577 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42578 + pax_flags |= MF_PAX_PAGEEXEC;
42579 +#endif
42580 +
42581 +#ifdef CONFIG_PAX_SEGMEXEC
42582 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42583 + pax_flags |= MF_PAX_SEGMEXEC;
42584 +#endif
42585 +
42586 +#ifdef CONFIG_PAX_EMUTRAMP
42587 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42588 + pax_flags |= MF_PAX_EMUTRAMP;
42589 +#endif
42590 +
42591 +#ifdef CONFIG_PAX_MPROTECT
42592 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42593 + pax_flags |= MF_PAX_MPROTECT;
42594 +#endif
42595 +
42596 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42597 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42598 + pax_flags |= MF_PAX_RANDMMAP;
42599 +#endif
42600 +
42601 + return pax_flags;
42602 +}
42603 +#endif
42604 +
42605 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42606 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42607 +{
42608 + unsigned long pax_flags = 0UL;
42609 +
42610 +#ifdef CONFIG_PAX_EI_PAX
42611 +
42612 +#ifdef CONFIG_PAX_PAGEEXEC
42613 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42614 + pax_flags |= MF_PAX_PAGEEXEC;
42615 +#endif
42616 +
42617 +#ifdef CONFIG_PAX_SEGMEXEC
42618 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42619 + pax_flags |= MF_PAX_SEGMEXEC;
42620 +#endif
42621 +
42622 +#ifdef CONFIG_PAX_EMUTRAMP
42623 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42624 + pax_flags |= MF_PAX_EMUTRAMP;
42625 +#endif
42626 +
42627 +#ifdef CONFIG_PAX_MPROTECT
42628 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42629 + pax_flags |= MF_PAX_MPROTECT;
42630 +#endif
42631 +
42632 +#ifdef CONFIG_PAX_ASLR
42633 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42634 + pax_flags |= MF_PAX_RANDMMAP;
42635 +#endif
42636 +
42637 +#else
42638 +
42639 +#ifdef CONFIG_PAX_PAGEEXEC
42640 + pax_flags |= MF_PAX_PAGEEXEC;
42641 +#endif
42642 +
42643 +#ifdef CONFIG_PAX_SEGMEXEC
42644 + pax_flags |= MF_PAX_SEGMEXEC;
42645 +#endif
42646 +
42647 +#ifdef CONFIG_PAX_MPROTECT
42648 + pax_flags |= MF_PAX_MPROTECT;
42649 +#endif
42650 +
42651 +#ifdef CONFIG_PAX_RANDMMAP
42652 + if (randomize_va_space)
42653 + pax_flags |= MF_PAX_RANDMMAP;
42654 +#endif
42655 +
42656 +#endif
42657 +
42658 + return pax_flags;
42659 +}
42660 +
42661 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42662 +{
42663 +
42664 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42665 + unsigned long i;
42666 +
42667 + for (i = 0UL; i < elf_ex->e_phnum; i++)
42668 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42669 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42670 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42671 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42672 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42673 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42674 + return ~0UL;
42675 +
42676 +#ifdef CONFIG_PAX_SOFTMODE
42677 + if (pax_softmode)
42678 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42679 + else
42680 +#endif
42681 +
42682 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42683 + break;
42684 + }
42685 +#endif
42686 +
42687 + return ~0UL;
42688 +}
42689 +
42690 +static unsigned long pax_parse_xattr_pax(struct file * const file)
42691 +{
42692 +
42693 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42694 + ssize_t xattr_size, i;
42695 + unsigned char xattr_value[5];
42696 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42697 +
42698 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42699 + if (xattr_size <= 0)
42700 + return ~0UL;
42701 +
42702 + for (i = 0; i < xattr_size; i++)
42703 + switch (xattr_value[i]) {
42704 + default:
42705 + return ~0UL;
42706 +
42707 +#define parse_flag(option1, option2, flag) \
42708 + case option1: \
42709 + pax_flags_hardmode |= MF_PAX_##flag; \
42710 + break; \
42711 + case option2: \
42712 + pax_flags_softmode |= MF_PAX_##flag; \
42713 + break;
42714 +
42715 + parse_flag('p', 'P', PAGEEXEC);
42716 + parse_flag('e', 'E', EMUTRAMP);
42717 + parse_flag('m', 'M', MPROTECT);
42718 + parse_flag('r', 'R', RANDMMAP);
42719 + parse_flag('s', 'S', SEGMEXEC);
42720 +
42721 +#undef parse_flag
42722 + }
42723 +
42724 + if (pax_flags_hardmode & pax_flags_softmode)
42725 + return ~0UL;
42726 +
42727 +#ifdef CONFIG_PAX_SOFTMODE
42728 + if (pax_softmode)
42729 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42730 + else
42731 +#endif
42732 +
42733 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42734 +#else
42735 + return ~0UL;
42736 +#endif
42737 +
42738 +}
42739 +
42740 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42741 +{
42742 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42743 +
42744 + pax_flags = pax_parse_ei_pax(elf_ex);
42745 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42746 + xattr_pax_flags = pax_parse_xattr_pax(file);
42747 +
42748 + if (pt_pax_flags == ~0UL)
42749 + pt_pax_flags = xattr_pax_flags;
42750 + else if (xattr_pax_flags == ~0UL)
42751 + xattr_pax_flags = pt_pax_flags;
42752 + if (pt_pax_flags != xattr_pax_flags)
42753 + return -EINVAL;
42754 + if (pt_pax_flags != ~0UL)
42755 + pax_flags = pt_pax_flags;
42756 +
42757 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42758 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42759 + if ((__supported_pte_mask & _PAGE_NX))
42760 + pax_flags &= ~MF_PAX_SEGMEXEC;
42761 + else
42762 + pax_flags &= ~MF_PAX_PAGEEXEC;
42763 + }
42764 +#endif
42765 +
42766 + if (0 > pax_check_flags(&pax_flags))
42767 + return -EINVAL;
42768 +
42769 + current->mm->pax_flags = pax_flags;
42770 + return 0;
42771 +}
42772 +#endif
42773 +
42774 /*
42775 * These are the functions used to load ELF style executables and shared
42776 * libraries. There is no binary dependent code anywhere else.
42777 @@ -539,6 +868,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42778 {
42779 unsigned int random_variable = 0;
42780
42781 +#ifdef CONFIG_PAX_RANDUSTACK
42782 + if (randomize_va_space)
42783 + return stack_top - current->mm->delta_stack;
42784 +#endif
42785 +
42786 if ((current->flags & PF_RANDOMIZE) &&
42787 !(current->personality & ADDR_NO_RANDOMIZE)) {
42788 random_variable = get_random_int() & STACK_RND_MASK;
42789 @@ -557,7 +891,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42790 unsigned long load_addr = 0, load_bias = 0;
42791 int load_addr_set = 0;
42792 char * elf_interpreter = NULL;
42793 - unsigned long error;
42794 + unsigned long error = 0;
42795 struct elf_phdr *elf_ppnt, *elf_phdata;
42796 unsigned long elf_bss, elf_brk;
42797 int retval, i;
42798 @@ -567,11 +901,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42799 unsigned long start_code, end_code, start_data, end_data;
42800 unsigned long reloc_func_desc __maybe_unused = 0;
42801 int executable_stack = EXSTACK_DEFAULT;
42802 - unsigned long def_flags = 0;
42803 struct {
42804 struct elfhdr elf_ex;
42805 struct elfhdr interp_elf_ex;
42806 } *loc;
42807 + unsigned long pax_task_size = TASK_SIZE;
42808
42809 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42810 if (!loc) {
42811 @@ -707,11 +1041,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42812 goto out_free_dentry;
42813
42814 /* OK, This is the point of no return */
42815 - current->mm->def_flags = def_flags;
42816 +
42817 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42818 + current->mm->pax_flags = 0UL;
42819 +#endif
42820 +
42821 +#ifdef CONFIG_PAX_DLRESOLVE
42822 + current->mm->call_dl_resolve = 0UL;
42823 +#endif
42824 +
42825 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42826 + current->mm->call_syscall = 0UL;
42827 +#endif
42828 +
42829 +#ifdef CONFIG_PAX_ASLR
42830 + current->mm->delta_mmap = 0UL;
42831 + current->mm->delta_stack = 0UL;
42832 +#endif
42833 +
42834 + current->mm->def_flags = 0;
42835 +
42836 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42837 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42838 + send_sig(SIGKILL, current, 0);
42839 + goto out_free_dentry;
42840 + }
42841 +#endif
42842 +
42843 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42844 + pax_set_initial_flags(bprm);
42845 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42846 + if (pax_set_initial_flags_func)
42847 + (pax_set_initial_flags_func)(bprm);
42848 +#endif
42849 +
42850 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42851 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42852 + current->mm->context.user_cs_limit = PAGE_SIZE;
42853 + current->mm->def_flags |= VM_PAGEEXEC;
42854 + }
42855 +#endif
42856 +
42857 +#ifdef CONFIG_PAX_SEGMEXEC
42858 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42859 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42860 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42861 + pax_task_size = SEGMEXEC_TASK_SIZE;
42862 + current->mm->def_flags |= VM_NOHUGEPAGE;
42863 + }
42864 +#endif
42865 +
42866 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42867 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42868 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42869 + put_cpu();
42870 + }
42871 +#endif
42872
42873 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42874 may depend on the personality. */
42875 SET_PERSONALITY(loc->elf_ex);
42876 +
42877 +#ifdef CONFIG_PAX_ASLR
42878 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42879 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42880 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42881 + }
42882 +#endif
42883 +
42884 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42885 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42886 + executable_stack = EXSTACK_DISABLE_X;
42887 + current->personality &= ~READ_IMPLIES_EXEC;
42888 + } else
42889 +#endif
42890 +
42891 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42892 current->personality |= READ_IMPLIES_EXEC;
42893
42894 @@ -802,6 +1206,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42895 #else
42896 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42897 #endif
42898 +
42899 +#ifdef CONFIG_PAX_RANDMMAP
42900 + /* PaX: randomize base address at the default exe base if requested */
42901 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42902 +#ifdef CONFIG_SPARC64
42903 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42904 +#else
42905 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42906 +#endif
42907 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42908 + elf_flags |= MAP_FIXED;
42909 + }
42910 +#endif
42911 +
42912 }
42913
42914 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42915 @@ -834,9 +1252,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42916 * allowed task size. Note that p_filesz must always be
42917 * <= p_memsz so it is only necessary to check p_memsz.
42918 */
42919 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42920 - elf_ppnt->p_memsz > TASK_SIZE ||
42921 - TASK_SIZE - elf_ppnt->p_memsz < k) {
42922 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42923 + elf_ppnt->p_memsz > pax_task_size ||
42924 + pax_task_size - elf_ppnt->p_memsz < k) {
42925 /* set_brk can never work. Avoid overflows. */
42926 send_sig(SIGKILL, current, 0);
42927 retval = -EINVAL;
42928 @@ -875,11 +1293,41 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42929 goto out_free_dentry;
42930 }
42931 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42932 - send_sig(SIGSEGV, current, 0);
42933 - retval = -EFAULT; /* Nobody gets to see this, but.. */
42934 - goto out_free_dentry;
42935 + /*
42936 + * This bss-zeroing can fail if the ELF
42937 + * file specifies odd protections. So
42938 + * we don't check the return value
42939 + */
42940 }
42941
42942 +#ifdef CONFIG_PAX_RANDMMAP
42943 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42944 + unsigned long start, size;
42945 +
42946 + start = ELF_PAGEALIGN(elf_brk);
42947 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42948 + down_read(&current->mm->mmap_sem);
42949 + retval = -ENOMEM;
42950 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
42951 + unsigned long prot = PROT_NONE;
42952 +
42953 + up_read(&current->mm->mmap_sem);
42954 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
42955 +// if (current->personality & ADDR_NO_RANDOMIZE)
42956 +// prot = PROT_READ;
42957 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
42958 + retval = IS_ERR_VALUE(start) ? start : 0;
42959 + } else
42960 + up_read(&current->mm->mmap_sem);
42961 + if (retval == 0)
42962 + retval = set_brk(start + size, start + size + PAGE_SIZE);
42963 + if (retval < 0) {
42964 + send_sig(SIGKILL, current, 0);
42965 + goto out_free_dentry;
42966 + }
42967 + }
42968 +#endif
42969 +
42970 if (elf_interpreter) {
42971 unsigned long uninitialized_var(interp_map_addr);
42972
42973 @@ -1107,7 +1555,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
42974 * Decide what to dump of a segment, part, all or none.
42975 */
42976 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42977 - unsigned long mm_flags)
42978 + unsigned long mm_flags, long signr)
42979 {
42980 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42981
42982 @@ -1144,7 +1592,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42983 if (vma->vm_file == NULL)
42984 return 0;
42985
42986 - if (FILTER(MAPPED_PRIVATE))
42987 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42988 goto whole;
42989
42990 /*
42991 @@ -1366,9 +1814,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42992 {
42993 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42994 int i = 0;
42995 - do
42996 + do {
42997 i += 2;
42998 - while (auxv[i - 2] != AT_NULL);
42999 + } while (auxv[i - 2] != AT_NULL);
43000 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43001 }
43002
43003 @@ -1890,14 +2338,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43004 }
43005
43006 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43007 - unsigned long mm_flags)
43008 + struct coredump_params *cprm)
43009 {
43010 struct vm_area_struct *vma;
43011 size_t size = 0;
43012
43013 for (vma = first_vma(current, gate_vma); vma != NULL;
43014 vma = next_vma(vma, gate_vma))
43015 - size += vma_dump_size(vma, mm_flags);
43016 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43017 return size;
43018 }
43019
43020 @@ -1991,7 +2439,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43021
43022 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43023
43024 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43025 + offset += elf_core_vma_data_size(gate_vma, cprm);
43026 offset += elf_core_extra_data_size();
43027 e_shoff = offset;
43028
43029 @@ -2005,10 +2453,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43030 offset = dataoff;
43031
43032 size += sizeof(*elf);
43033 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43034 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43035 goto end_coredump;
43036
43037 size += sizeof(*phdr4note);
43038 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43039 if (size > cprm->limit
43040 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43041 goto end_coredump;
43042 @@ -2022,7 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43043 phdr.p_offset = offset;
43044 phdr.p_vaddr = vma->vm_start;
43045 phdr.p_paddr = 0;
43046 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43047 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43048 phdr.p_memsz = vma->vm_end - vma->vm_start;
43049 offset += phdr.p_filesz;
43050 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43051 @@ -2033,6 +2483,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43052 phdr.p_align = ELF_EXEC_PAGESIZE;
43053
43054 size += sizeof(phdr);
43055 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43056 if (size > cprm->limit
43057 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43058 goto end_coredump;
43059 @@ -2057,7 +2508,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43060 unsigned long addr;
43061 unsigned long end;
43062
43063 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43064 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43065
43066 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43067 struct page *page;
43068 @@ -2066,6 +2517,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43069 page = get_dump_page(addr);
43070 if (page) {
43071 void *kaddr = kmap(page);
43072 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43073 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43074 !dump_write(cprm->file, kaddr,
43075 PAGE_SIZE);
43076 @@ -2083,6 +2535,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43077
43078 if (e_phnum == PN_XNUM) {
43079 size += sizeof(*shdr4extnum);
43080 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43081 if (size > cprm->limit
43082 || !dump_write(cprm->file, shdr4extnum,
43083 sizeof(*shdr4extnum)))
43084 @@ -2103,6 +2556,97 @@ out:
43085
43086 #endif /* CONFIG_ELF_CORE */
43087
43088 +#ifdef CONFIG_PAX_MPROTECT
43089 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43090 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43091 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43092 + *
43093 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43094 + * basis because we want to allow the common case and not the special ones.
43095 + */
43096 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43097 +{
43098 + struct elfhdr elf_h;
43099 + struct elf_phdr elf_p;
43100 + unsigned long i;
43101 + unsigned long oldflags;
43102 + bool is_textrel_rw, is_textrel_rx, is_relro;
43103 +
43104 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43105 + return;
43106 +
43107 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43108 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43109 +
43110 +#ifdef CONFIG_PAX_ELFRELOCS
43111 + /* possible TEXTREL */
43112 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43113 + 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);
43114 +#else
43115 + is_textrel_rw = false;
43116 + is_textrel_rx = false;
43117 +#endif
43118 +
43119 + /* possible RELRO */
43120 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43121 +
43122 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43123 + return;
43124 +
43125 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43126 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43127 +
43128 +#ifdef CONFIG_PAX_ETEXECRELOCS
43129 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43130 +#else
43131 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43132 +#endif
43133 +
43134 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43135 + !elf_check_arch(&elf_h) ||
43136 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43137 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43138 + return;
43139 +
43140 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43141 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43142 + return;
43143 + switch (elf_p.p_type) {
43144 + case PT_DYNAMIC:
43145 + if (!is_textrel_rw && !is_textrel_rx)
43146 + continue;
43147 + i = 0UL;
43148 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43149 + elf_dyn dyn;
43150 +
43151 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43152 + return;
43153 + if (dyn.d_tag == DT_NULL)
43154 + return;
43155 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43156 + gr_log_textrel(vma);
43157 + if (is_textrel_rw)
43158 + vma->vm_flags |= VM_MAYWRITE;
43159 + else
43160 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43161 + vma->vm_flags &= ~VM_MAYWRITE;
43162 + return;
43163 + }
43164 + i++;
43165 + }
43166 + return;
43167 +
43168 + case PT_GNU_RELRO:
43169 + if (!is_relro)
43170 + continue;
43171 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43172 + vma->vm_flags &= ~VM_MAYWRITE;
43173 + return;
43174 + }
43175 + }
43176 +}
43177 +#endif
43178 +
43179 static int __init init_elf_binfmt(void)
43180 {
43181 register_binfmt(&elf_format);
43182 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43183 index 178cb70..8972997 100644
43184 --- a/fs/binfmt_flat.c
43185 +++ b/fs/binfmt_flat.c
43186 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43187 realdatastart = (unsigned long) -ENOMEM;
43188 printk("Unable to allocate RAM for process data, errno %d\n",
43189 (int)-realdatastart);
43190 + down_write(&current->mm->mmap_sem);
43191 vm_munmap(textpos, text_len);
43192 + up_write(&current->mm->mmap_sem);
43193 ret = realdatastart;
43194 goto err;
43195 }
43196 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43197 }
43198 if (IS_ERR_VALUE(result)) {
43199 printk("Unable to read data+bss, errno %d\n", (int)-result);
43200 + down_write(&current->mm->mmap_sem);
43201 vm_munmap(textpos, text_len);
43202 vm_munmap(realdatastart, len);
43203 + up_write(&current->mm->mmap_sem);
43204 ret = result;
43205 goto err;
43206 }
43207 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43208 }
43209 if (IS_ERR_VALUE(result)) {
43210 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43211 + down_write(&current->mm->mmap_sem);
43212 vm_munmap(textpos, text_len + data_len + extra +
43213 MAX_SHARED_LIBS * sizeof(unsigned long));
43214 + up_write(&current->mm->mmap_sem);
43215 ret = result;
43216 goto err;
43217 }
43218 diff --git a/fs/bio.c b/fs/bio.c
43219 index 73922ab..16642dd 100644
43220 --- a/fs/bio.c
43221 +++ b/fs/bio.c
43222 @@ -841,7 +841,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43223 /*
43224 * Overflow, abort
43225 */
43226 - if (end < start)
43227 + if (end < start || end - start > INT_MAX - nr_pages)
43228 return ERR_PTR(-EINVAL);
43229
43230 nr_pages += end - start;
43231 @@ -975,7 +975,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43232 /*
43233 * Overflow, abort
43234 */
43235 - if (end < start)
43236 + if (end < start || end - start > INT_MAX - nr_pages)
43237 return ERR_PTR(-EINVAL);
43238
43239 nr_pages += end - start;
43240 @@ -1237,7 +1237,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43241 const int read = bio_data_dir(bio) == READ;
43242 struct bio_map_data *bmd = bio->bi_private;
43243 int i;
43244 - char *p = bmd->sgvecs[0].iov_base;
43245 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43246
43247 __bio_for_each_segment(bvec, bio, i, 0) {
43248 char *addr = page_address(bvec->bv_page);
43249 diff --git a/fs/block_dev.c b/fs/block_dev.c
43250 index c2bbe1f..9dfbc23 100644
43251 --- a/fs/block_dev.c
43252 +++ b/fs/block_dev.c
43253 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43254 else if (bdev->bd_contains == bdev)
43255 return true; /* is a whole device which isn't held */
43256
43257 - else if (whole->bd_holder == bd_may_claim)
43258 + else if (whole->bd_holder == (void *)bd_may_claim)
43259 return true; /* is a partition of a device that is being partitioned */
43260 else if (whole->bd_holder != NULL)
43261 return false; /* is a partition of a held device */
43262 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43263 index da6e936..1598dd0 100644
43264 --- a/fs/btrfs/check-integrity.c
43265 +++ b/fs/btrfs/check-integrity.c
43266 @@ -155,7 +155,7 @@ struct btrfsic_block {
43267 union {
43268 bio_end_io_t *bio;
43269 bh_end_io_t *bh;
43270 - } orig_bio_bh_end_io;
43271 + } __no_const orig_bio_bh_end_io;
43272 int submit_bio_bh_rw;
43273 u64 flush_gen; /* only valid if !never_written */
43274 };
43275 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43276 index 8206b39..06d5654 100644
43277 --- a/fs/btrfs/ctree.c
43278 +++ b/fs/btrfs/ctree.c
43279 @@ -973,9 +973,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43280 free_extent_buffer(buf);
43281 add_root_to_dirty_list(root);
43282 } else {
43283 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43284 - parent_start = parent->start;
43285 - else
43286 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43287 + if (parent)
43288 + parent_start = parent->start;
43289 + else
43290 + parent_start = 0;
43291 + } else
43292 parent_start = 0;
43293
43294 WARN_ON(trans->transid != btrfs_header_generation(parent));
43295 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43296 index a7d1921..a32dba2 100644
43297 --- a/fs/btrfs/inode.c
43298 +++ b/fs/btrfs/inode.c
43299 @@ -7111,7 +7111,7 @@ fail:
43300 return -ENOMEM;
43301 }
43302
43303 -static int btrfs_getattr(struct vfsmount *mnt,
43304 +int btrfs_getattr(struct vfsmount *mnt,
43305 struct dentry *dentry, struct kstat *stat)
43306 {
43307 struct inode *inode = dentry->d_inode;
43308 @@ -7125,6 +7125,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43309 return 0;
43310 }
43311
43312 +EXPORT_SYMBOL(btrfs_getattr);
43313 +
43314 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43315 +{
43316 + return BTRFS_I(inode)->root->anon_dev;
43317 +}
43318 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43319 +
43320 /*
43321 * If a file is moved, it will inherit the cow and compression flags of the new
43322 * directory.
43323 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43324 index 0e92e57..8b560de 100644
43325 --- a/fs/btrfs/ioctl.c
43326 +++ b/fs/btrfs/ioctl.c
43327 @@ -2902,9 +2902,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43328 for (i = 0; i < num_types; i++) {
43329 struct btrfs_space_info *tmp;
43330
43331 + /* Don't copy in more than we allocated */
43332 if (!slot_count)
43333 break;
43334
43335 + slot_count--;
43336 +
43337 info = NULL;
43338 rcu_read_lock();
43339 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43340 @@ -2926,10 +2929,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43341 memcpy(dest, &space, sizeof(space));
43342 dest++;
43343 space_args.total_spaces++;
43344 - slot_count--;
43345 }
43346 - if (!slot_count)
43347 - break;
43348 }
43349 up_read(&info->groups_sem);
43350 }
43351 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43352 index 646ee21..f020f87 100644
43353 --- a/fs/btrfs/relocation.c
43354 +++ b/fs/btrfs/relocation.c
43355 @@ -1268,7 +1268,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43356 }
43357 spin_unlock(&rc->reloc_root_tree.lock);
43358
43359 - BUG_ON((struct btrfs_root *)node->data != root);
43360 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43361
43362 if (!del) {
43363 spin_lock(&rc->reloc_root_tree.lock);
43364 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43365 index 622f469..e8d2d55 100644
43366 --- a/fs/cachefiles/bind.c
43367 +++ b/fs/cachefiles/bind.c
43368 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43369 args);
43370
43371 /* start by checking things over */
43372 - ASSERT(cache->fstop_percent >= 0 &&
43373 - cache->fstop_percent < cache->fcull_percent &&
43374 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43375 cache->fcull_percent < cache->frun_percent &&
43376 cache->frun_percent < 100);
43377
43378 - ASSERT(cache->bstop_percent >= 0 &&
43379 - cache->bstop_percent < cache->bcull_percent &&
43380 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43381 cache->bcull_percent < cache->brun_percent &&
43382 cache->brun_percent < 100);
43383
43384 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43385 index 0a1467b..6a53245 100644
43386 --- a/fs/cachefiles/daemon.c
43387 +++ b/fs/cachefiles/daemon.c
43388 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43389 if (n > buflen)
43390 return -EMSGSIZE;
43391
43392 - if (copy_to_user(_buffer, buffer, n) != 0)
43393 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43394 return -EFAULT;
43395
43396 return n;
43397 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43398 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43399 return -EIO;
43400
43401 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43402 + if (datalen > PAGE_SIZE - 1)
43403 return -EOPNOTSUPP;
43404
43405 /* drag the command string into the kernel so we can parse it */
43406 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43407 if (args[0] != '%' || args[1] != '\0')
43408 return -EINVAL;
43409
43410 - if (fstop < 0 || fstop >= cache->fcull_percent)
43411 + if (fstop >= cache->fcull_percent)
43412 return cachefiles_daemon_range_error(cache, args);
43413
43414 cache->fstop_percent = fstop;
43415 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43416 if (args[0] != '%' || args[1] != '\0')
43417 return -EINVAL;
43418
43419 - if (bstop < 0 || bstop >= cache->bcull_percent)
43420 + if (bstop >= cache->bcull_percent)
43421 return cachefiles_daemon_range_error(cache, args);
43422
43423 cache->bstop_percent = bstop;
43424 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43425 index bd6bc1b..b627b53 100644
43426 --- a/fs/cachefiles/internal.h
43427 +++ b/fs/cachefiles/internal.h
43428 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43429 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43430 struct rb_root active_nodes; /* active nodes (can't be culled) */
43431 rwlock_t active_lock; /* lock for active_nodes */
43432 - atomic_t gravecounter; /* graveyard uniquifier */
43433 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43434 unsigned frun_percent; /* when to stop culling (% files) */
43435 unsigned fcull_percent; /* when to start culling (% files) */
43436 unsigned fstop_percent; /* when to stop allocating (% files) */
43437 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43438 * proc.c
43439 */
43440 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43441 -extern atomic_t cachefiles_lookup_histogram[HZ];
43442 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43443 -extern atomic_t cachefiles_create_histogram[HZ];
43444 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43445 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43446 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43447
43448 extern int __init cachefiles_proc_init(void);
43449 extern void cachefiles_proc_cleanup(void);
43450 static inline
43451 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43452 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43453 {
43454 unsigned long jif = jiffies - start_jif;
43455 if (jif >= HZ)
43456 jif = HZ - 1;
43457 - atomic_inc(&histogram[jif]);
43458 + atomic_inc_unchecked(&histogram[jif]);
43459 }
43460
43461 #else
43462 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43463 index 7f0771d..87d4f36 100644
43464 --- a/fs/cachefiles/namei.c
43465 +++ b/fs/cachefiles/namei.c
43466 @@ -318,7 +318,7 @@ try_again:
43467 /* first step is to make up a grave dentry in the graveyard */
43468 sprintf(nbuffer, "%08x%08x",
43469 (uint32_t) get_seconds(),
43470 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43471 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43472
43473 /* do the multiway lock magic */
43474 trap = lock_rename(cache->graveyard, dir);
43475 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43476 index eccd339..4c1d995 100644
43477 --- a/fs/cachefiles/proc.c
43478 +++ b/fs/cachefiles/proc.c
43479 @@ -14,9 +14,9 @@
43480 #include <linux/seq_file.h>
43481 #include "internal.h"
43482
43483 -atomic_t cachefiles_lookup_histogram[HZ];
43484 -atomic_t cachefiles_mkdir_histogram[HZ];
43485 -atomic_t cachefiles_create_histogram[HZ];
43486 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43487 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43488 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43489
43490 /*
43491 * display the latency histogram
43492 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43493 return 0;
43494 default:
43495 index = (unsigned long) v - 3;
43496 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43497 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43498 - z = atomic_read(&cachefiles_create_histogram[index]);
43499 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43500 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43501 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43502 if (x == 0 && y == 0 && z == 0)
43503 return 0;
43504
43505 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43506 index 0e3c092..818480e 100644
43507 --- a/fs/cachefiles/rdwr.c
43508 +++ b/fs/cachefiles/rdwr.c
43509 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43510 old_fs = get_fs();
43511 set_fs(KERNEL_DS);
43512 ret = file->f_op->write(
43513 - file, (const void __user *) data, len, &pos);
43514 + file, (const void __force_user *) data, len, &pos);
43515 set_fs(old_fs);
43516 kunmap(page);
43517 if (ret != len)
43518 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43519 index 3e8094b..cb3ff3d 100644
43520 --- a/fs/ceph/dir.c
43521 +++ b/fs/ceph/dir.c
43522 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43523 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43524 struct ceph_mds_client *mdsc = fsc->mdsc;
43525 unsigned frag = fpos_frag(filp->f_pos);
43526 - int off = fpos_off(filp->f_pos);
43527 + unsigned int off = fpos_off(filp->f_pos);
43528 int err;
43529 u32 ftype;
43530 struct ceph_mds_reply_info_parsed *rinfo;
43531 @@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
43532 if (nd &&
43533 (nd->flags & LOOKUP_OPEN) &&
43534 !(nd->intent.open.flags & O_CREAT)) {
43535 - int mode = nd->intent.open.create_mode & ~current->fs->umask;
43536 + int mode = nd->intent.open.create_mode & ~current_umask();
43537 return ceph_lookup_open(dir, dentry, nd, mode, 1);
43538 }
43539
43540 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43541 index e814052..28dcdf7 100644
43542 --- a/fs/cifs/cifs_debug.c
43543 +++ b/fs/cifs/cifs_debug.c
43544 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43545
43546 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43547 #ifdef CONFIG_CIFS_STATS2
43548 - atomic_set(&totBufAllocCount, 0);
43549 - atomic_set(&totSmBufAllocCount, 0);
43550 + atomic_set_unchecked(&totBufAllocCount, 0);
43551 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43552 #endif /* CONFIG_CIFS_STATS2 */
43553 spin_lock(&cifs_tcp_ses_lock);
43554 list_for_each(tmp1, &cifs_tcp_ses_list) {
43555 @@ -281,25 +281,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43556 tcon = list_entry(tmp3,
43557 struct cifs_tcon,
43558 tcon_list);
43559 - atomic_set(&tcon->num_smbs_sent, 0);
43560 - atomic_set(&tcon->num_writes, 0);
43561 - atomic_set(&tcon->num_reads, 0);
43562 - atomic_set(&tcon->num_oplock_brks, 0);
43563 - atomic_set(&tcon->num_opens, 0);
43564 - atomic_set(&tcon->num_posixopens, 0);
43565 - atomic_set(&tcon->num_posixmkdirs, 0);
43566 - atomic_set(&tcon->num_closes, 0);
43567 - atomic_set(&tcon->num_deletes, 0);
43568 - atomic_set(&tcon->num_mkdirs, 0);
43569 - atomic_set(&tcon->num_rmdirs, 0);
43570 - atomic_set(&tcon->num_renames, 0);
43571 - atomic_set(&tcon->num_t2renames, 0);
43572 - atomic_set(&tcon->num_ffirst, 0);
43573 - atomic_set(&tcon->num_fnext, 0);
43574 - atomic_set(&tcon->num_fclose, 0);
43575 - atomic_set(&tcon->num_hardlinks, 0);
43576 - atomic_set(&tcon->num_symlinks, 0);
43577 - atomic_set(&tcon->num_locks, 0);
43578 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43579 + atomic_set_unchecked(&tcon->num_writes, 0);
43580 + atomic_set_unchecked(&tcon->num_reads, 0);
43581 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43582 + atomic_set_unchecked(&tcon->num_opens, 0);
43583 + atomic_set_unchecked(&tcon->num_posixopens, 0);
43584 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43585 + atomic_set_unchecked(&tcon->num_closes, 0);
43586 + atomic_set_unchecked(&tcon->num_deletes, 0);
43587 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
43588 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
43589 + atomic_set_unchecked(&tcon->num_renames, 0);
43590 + atomic_set_unchecked(&tcon->num_t2renames, 0);
43591 + atomic_set_unchecked(&tcon->num_ffirst, 0);
43592 + atomic_set_unchecked(&tcon->num_fnext, 0);
43593 + atomic_set_unchecked(&tcon->num_fclose, 0);
43594 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
43595 + atomic_set_unchecked(&tcon->num_symlinks, 0);
43596 + atomic_set_unchecked(&tcon->num_locks, 0);
43597 }
43598 }
43599 }
43600 @@ -329,8 +329,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43601 smBufAllocCount.counter, cifs_min_small);
43602 #ifdef CONFIG_CIFS_STATS2
43603 seq_printf(m, "Total Large %d Small %d Allocations\n",
43604 - atomic_read(&totBufAllocCount),
43605 - atomic_read(&totSmBufAllocCount));
43606 + atomic_read_unchecked(&totBufAllocCount),
43607 + atomic_read_unchecked(&totSmBufAllocCount));
43608 #endif /* CONFIG_CIFS_STATS2 */
43609
43610 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43611 @@ -359,41 +359,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43612 if (tcon->need_reconnect)
43613 seq_puts(m, "\tDISCONNECTED ");
43614 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43615 - atomic_read(&tcon->num_smbs_sent),
43616 - atomic_read(&tcon->num_oplock_brks));
43617 + atomic_read_unchecked(&tcon->num_smbs_sent),
43618 + atomic_read_unchecked(&tcon->num_oplock_brks));
43619 seq_printf(m, "\nReads: %d Bytes: %lld",
43620 - atomic_read(&tcon->num_reads),
43621 + atomic_read_unchecked(&tcon->num_reads),
43622 (long long)(tcon->bytes_read));
43623 seq_printf(m, "\nWrites: %d Bytes: %lld",
43624 - atomic_read(&tcon->num_writes),
43625 + atomic_read_unchecked(&tcon->num_writes),
43626 (long long)(tcon->bytes_written));
43627 seq_printf(m, "\nFlushes: %d",
43628 - atomic_read(&tcon->num_flushes));
43629 + atomic_read_unchecked(&tcon->num_flushes));
43630 seq_printf(m, "\nLocks: %d HardLinks: %d "
43631 "Symlinks: %d",
43632 - atomic_read(&tcon->num_locks),
43633 - atomic_read(&tcon->num_hardlinks),
43634 - atomic_read(&tcon->num_symlinks));
43635 + atomic_read_unchecked(&tcon->num_locks),
43636 + atomic_read_unchecked(&tcon->num_hardlinks),
43637 + atomic_read_unchecked(&tcon->num_symlinks));
43638 seq_printf(m, "\nOpens: %d Closes: %d "
43639 "Deletes: %d",
43640 - atomic_read(&tcon->num_opens),
43641 - atomic_read(&tcon->num_closes),
43642 - atomic_read(&tcon->num_deletes));
43643 + atomic_read_unchecked(&tcon->num_opens),
43644 + atomic_read_unchecked(&tcon->num_closes),
43645 + atomic_read_unchecked(&tcon->num_deletes));
43646 seq_printf(m, "\nPosix Opens: %d "
43647 "Posix Mkdirs: %d",
43648 - atomic_read(&tcon->num_posixopens),
43649 - atomic_read(&tcon->num_posixmkdirs));
43650 + atomic_read_unchecked(&tcon->num_posixopens),
43651 + atomic_read_unchecked(&tcon->num_posixmkdirs));
43652 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43653 - atomic_read(&tcon->num_mkdirs),
43654 - atomic_read(&tcon->num_rmdirs));
43655 + atomic_read_unchecked(&tcon->num_mkdirs),
43656 + atomic_read_unchecked(&tcon->num_rmdirs));
43657 seq_printf(m, "\nRenames: %d T2 Renames %d",
43658 - atomic_read(&tcon->num_renames),
43659 - atomic_read(&tcon->num_t2renames));
43660 + atomic_read_unchecked(&tcon->num_renames),
43661 + atomic_read_unchecked(&tcon->num_t2renames));
43662 seq_printf(m, "\nFindFirst: %d FNext %d "
43663 "FClose %d",
43664 - atomic_read(&tcon->num_ffirst),
43665 - atomic_read(&tcon->num_fnext),
43666 - atomic_read(&tcon->num_fclose));
43667 + atomic_read_unchecked(&tcon->num_ffirst),
43668 + atomic_read_unchecked(&tcon->num_fnext),
43669 + atomic_read_unchecked(&tcon->num_fclose));
43670 }
43671 }
43672 }
43673 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43674 index 8b6e344..303a662 100644
43675 --- a/fs/cifs/cifsfs.c
43676 +++ b/fs/cifs/cifsfs.c
43677 @@ -994,7 +994,7 @@ cifs_init_request_bufs(void)
43678 cifs_req_cachep = kmem_cache_create("cifs_request",
43679 CIFSMaxBufSize +
43680 MAX_CIFS_HDR_SIZE, 0,
43681 - SLAB_HWCACHE_ALIGN, NULL);
43682 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43683 if (cifs_req_cachep == NULL)
43684 return -ENOMEM;
43685
43686 @@ -1021,7 +1021,7 @@ cifs_init_request_bufs(void)
43687 efficient to alloc 1 per page off the slab compared to 17K (5page)
43688 alloc of large cifs buffers even when page debugging is on */
43689 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43690 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43691 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43692 NULL);
43693 if (cifs_sm_req_cachep == NULL) {
43694 mempool_destroy(cifs_req_poolp);
43695 @@ -1106,8 +1106,8 @@ init_cifs(void)
43696 atomic_set(&bufAllocCount, 0);
43697 atomic_set(&smBufAllocCount, 0);
43698 #ifdef CONFIG_CIFS_STATS2
43699 - atomic_set(&totBufAllocCount, 0);
43700 - atomic_set(&totSmBufAllocCount, 0);
43701 + atomic_set_unchecked(&totBufAllocCount, 0);
43702 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43703 #endif /* CONFIG_CIFS_STATS2 */
43704
43705 atomic_set(&midCount, 0);
43706 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43707 index d86ba9f..e80049d 100644
43708 --- a/fs/cifs/cifsglob.h
43709 +++ b/fs/cifs/cifsglob.h
43710 @@ -491,28 +491,28 @@ struct cifs_tcon {
43711 __u16 Flags; /* optional support bits */
43712 enum statusEnum tidStatus;
43713 #ifdef CONFIG_CIFS_STATS
43714 - atomic_t num_smbs_sent;
43715 - atomic_t num_writes;
43716 - atomic_t num_reads;
43717 - atomic_t num_flushes;
43718 - atomic_t num_oplock_brks;
43719 - atomic_t num_opens;
43720 - atomic_t num_closes;
43721 - atomic_t num_deletes;
43722 - atomic_t num_mkdirs;
43723 - atomic_t num_posixopens;
43724 - atomic_t num_posixmkdirs;
43725 - atomic_t num_rmdirs;
43726 - atomic_t num_renames;
43727 - atomic_t num_t2renames;
43728 - atomic_t num_ffirst;
43729 - atomic_t num_fnext;
43730 - atomic_t num_fclose;
43731 - atomic_t num_hardlinks;
43732 - atomic_t num_symlinks;
43733 - atomic_t num_locks;
43734 - atomic_t num_acl_get;
43735 - atomic_t num_acl_set;
43736 + atomic_unchecked_t num_smbs_sent;
43737 + atomic_unchecked_t num_writes;
43738 + atomic_unchecked_t num_reads;
43739 + atomic_unchecked_t num_flushes;
43740 + atomic_unchecked_t num_oplock_brks;
43741 + atomic_unchecked_t num_opens;
43742 + atomic_unchecked_t num_closes;
43743 + atomic_unchecked_t num_deletes;
43744 + atomic_unchecked_t num_mkdirs;
43745 + atomic_unchecked_t num_posixopens;
43746 + atomic_unchecked_t num_posixmkdirs;
43747 + atomic_unchecked_t num_rmdirs;
43748 + atomic_unchecked_t num_renames;
43749 + atomic_unchecked_t num_t2renames;
43750 + atomic_unchecked_t num_ffirst;
43751 + atomic_unchecked_t num_fnext;
43752 + atomic_unchecked_t num_fclose;
43753 + atomic_unchecked_t num_hardlinks;
43754 + atomic_unchecked_t num_symlinks;
43755 + atomic_unchecked_t num_locks;
43756 + atomic_unchecked_t num_acl_get;
43757 + atomic_unchecked_t num_acl_set;
43758 #ifdef CONFIG_CIFS_STATS2
43759 unsigned long long time_writes;
43760 unsigned long long time_reads;
43761 @@ -735,7 +735,7 @@ convert_delimiter(char *path, char delim)
43762 }
43763
43764 #ifdef CONFIG_CIFS_STATS
43765 -#define cifs_stats_inc atomic_inc
43766 +#define cifs_stats_inc atomic_inc_unchecked
43767
43768 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43769 unsigned int bytes)
43770 @@ -1093,8 +1093,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43771 /* Various Debug counters */
43772 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43773 #ifdef CONFIG_CIFS_STATS2
43774 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43775 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43776 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43777 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43778 #endif
43779 GLOBAL_EXTERN atomic_t smBufAllocCount;
43780 GLOBAL_EXTERN atomic_t midCount;
43781 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43782 index 6b0e064..94e6c3c 100644
43783 --- a/fs/cifs/link.c
43784 +++ b/fs/cifs/link.c
43785 @@ -600,7 +600,7 @@ symlink_exit:
43786
43787 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43788 {
43789 - char *p = nd_get_link(nd);
43790 + const char *p = nd_get_link(nd);
43791 if (!IS_ERR(p))
43792 kfree(p);
43793 }
43794 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43795 index 557506a..2fd3816 100644
43796 --- a/fs/cifs/misc.c
43797 +++ b/fs/cifs/misc.c
43798 @@ -156,7 +156,7 @@ cifs_buf_get(void)
43799 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43800 atomic_inc(&bufAllocCount);
43801 #ifdef CONFIG_CIFS_STATS2
43802 - atomic_inc(&totBufAllocCount);
43803 + atomic_inc_unchecked(&totBufAllocCount);
43804 #endif /* CONFIG_CIFS_STATS2 */
43805 }
43806
43807 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43808 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43809 atomic_inc(&smBufAllocCount);
43810 #ifdef CONFIG_CIFS_STATS2
43811 - atomic_inc(&totSmBufAllocCount);
43812 + atomic_inc_unchecked(&totSmBufAllocCount);
43813 #endif /* CONFIG_CIFS_STATS2 */
43814
43815 }
43816 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43817 index 6901578..d402eb5 100644
43818 --- a/fs/coda/cache.c
43819 +++ b/fs/coda/cache.c
43820 @@ -24,7 +24,7 @@
43821 #include "coda_linux.h"
43822 #include "coda_cache.h"
43823
43824 -static atomic_t permission_epoch = ATOMIC_INIT(0);
43825 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43826
43827 /* replace or extend an acl cache hit */
43828 void coda_cache_enter(struct inode *inode, int mask)
43829 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43830 struct coda_inode_info *cii = ITOC(inode);
43831
43832 spin_lock(&cii->c_lock);
43833 - cii->c_cached_epoch = atomic_read(&permission_epoch);
43834 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43835 if (cii->c_uid != current_fsuid()) {
43836 cii->c_uid = current_fsuid();
43837 cii->c_cached_perm = mask;
43838 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43839 {
43840 struct coda_inode_info *cii = ITOC(inode);
43841 spin_lock(&cii->c_lock);
43842 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43843 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43844 spin_unlock(&cii->c_lock);
43845 }
43846
43847 /* remove all acl caches */
43848 void coda_cache_clear_all(struct super_block *sb)
43849 {
43850 - atomic_inc(&permission_epoch);
43851 + atomic_inc_unchecked(&permission_epoch);
43852 }
43853
43854
43855 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43856 spin_lock(&cii->c_lock);
43857 hit = (mask & cii->c_cached_perm) == mask &&
43858 cii->c_uid == current_fsuid() &&
43859 - cii->c_cached_epoch == atomic_read(&permission_epoch);
43860 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43861 spin_unlock(&cii->c_lock);
43862
43863 return hit;
43864 diff --git a/fs/compat.c b/fs/compat.c
43865 index 6161255..512b1a1 100644
43866 --- a/fs/compat.c
43867 +++ b/fs/compat.c
43868 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43869
43870 set_fs(KERNEL_DS);
43871 /* The __user pointer cast is valid because of the set_fs() */
43872 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43873 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43874 set_fs(oldfs);
43875 /* truncating is ok because it's a user address */
43876 if (!ret)
43877 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43878 goto out;
43879
43880 ret = -EINVAL;
43881 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43882 + if (nr_segs > UIO_MAXIOV)
43883 goto out;
43884 if (nr_segs > fast_segs) {
43885 ret = -ENOMEM;
43886 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
43887
43888 struct compat_readdir_callback {
43889 struct compat_old_linux_dirent __user *dirent;
43890 + struct file * file;
43891 int result;
43892 };
43893
43894 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43895 buf->result = -EOVERFLOW;
43896 return -EOVERFLOW;
43897 }
43898 +
43899 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43900 + return 0;
43901 +
43902 buf->result++;
43903 dirent = buf->dirent;
43904 if (!access_ok(VERIFY_WRITE, dirent,
43905 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43906
43907 buf.result = 0;
43908 buf.dirent = dirent;
43909 + buf.file = file;
43910
43911 error = vfs_readdir(file, compat_fillonedir, &buf);
43912 if (buf.result)
43913 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
43914 struct compat_getdents_callback {
43915 struct compat_linux_dirent __user *current_dir;
43916 struct compat_linux_dirent __user *previous;
43917 + struct file * file;
43918 int count;
43919 int error;
43920 };
43921 @@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43922 buf->error = -EOVERFLOW;
43923 return -EOVERFLOW;
43924 }
43925 +
43926 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43927 + return 0;
43928 +
43929 dirent = buf->previous;
43930 if (dirent) {
43931 if (__put_user(offset, &dirent->d_off))
43932 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43933 buf.previous = NULL;
43934 buf.count = count;
43935 buf.error = 0;
43936 + buf.file = file;
43937
43938 error = vfs_readdir(file, compat_filldir, &buf);
43939 if (error >= 0)
43940 @@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43941 struct compat_getdents_callback64 {
43942 struct linux_dirent64 __user *current_dir;
43943 struct linux_dirent64 __user *previous;
43944 + struct file * file;
43945 int count;
43946 int error;
43947 };
43948 @@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43949 buf->error = -EINVAL; /* only used if we fail.. */
43950 if (reclen > buf->count)
43951 return -EINVAL;
43952 +
43953 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43954 + return 0;
43955 +
43956 dirent = buf->previous;
43957
43958 if (dirent) {
43959 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43960 buf.previous = NULL;
43961 buf.count = count;
43962 buf.error = 0;
43963 + buf.file = file;
43964
43965 error = vfs_readdir(file, compat_filldir64, &buf);
43966 if (error >= 0)
43967 error = buf.error;
43968 lastdirent = buf.previous;
43969 if (lastdirent) {
43970 - typeof(lastdirent->d_off) d_off = file->f_pos;
43971 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43972 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43973 error = -EFAULT;
43974 else
43975 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43976 index 112e45a..b59845b 100644
43977 --- a/fs/compat_binfmt_elf.c
43978 +++ b/fs/compat_binfmt_elf.c
43979 @@ -30,11 +30,13 @@
43980 #undef elf_phdr
43981 #undef elf_shdr
43982 #undef elf_note
43983 +#undef elf_dyn
43984 #undef elf_addr_t
43985 #define elfhdr elf32_hdr
43986 #define elf_phdr elf32_phdr
43987 #define elf_shdr elf32_shdr
43988 #define elf_note elf32_note
43989 +#define elf_dyn Elf32_Dyn
43990 #define elf_addr_t Elf32_Addr
43991
43992 /*
43993 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43994 index debdfe0..75d31d4 100644
43995 --- a/fs/compat_ioctl.c
43996 +++ b/fs/compat_ioctl.c
43997 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43998
43999 err = get_user(palp, &up->palette);
44000 err |= get_user(length, &up->length);
44001 + if (err)
44002 + return -EFAULT;
44003
44004 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
44005 err = put_user(compat_ptr(palp), &up_native->palette);
44006 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44007 return -EFAULT;
44008 if (__get_user(udata, &ss32->iomem_base))
44009 return -EFAULT;
44010 - ss.iomem_base = compat_ptr(udata);
44011 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44012 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44013 __get_user(ss.port_high, &ss32->port_high))
44014 return -EFAULT;
44015 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44016 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44017 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44018 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44019 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44020 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44021 return -EFAULT;
44022
44023 return ioctl_preallocate(file, p);
44024 @@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44025 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44026 {
44027 unsigned int a, b;
44028 - a = *(unsigned int *)p;
44029 - b = *(unsigned int *)q;
44030 + a = *(const unsigned int *)p;
44031 + b = *(const unsigned int *)q;
44032 if (a > b)
44033 return 1;
44034 if (a < b)
44035 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44036 index 7e6c52d..94bc756 100644
44037 --- a/fs/configfs/dir.c
44038 +++ b/fs/configfs/dir.c
44039 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44040 }
44041 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44042 struct configfs_dirent *next;
44043 - const char * name;
44044 + const unsigned char * name;
44045 + char d_name[sizeof(next->s_dentry->d_iname)];
44046 int len;
44047 struct inode *inode = NULL;
44048
44049 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44050 continue;
44051
44052 name = configfs_get_name(next);
44053 - len = strlen(name);
44054 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44055 + len = next->s_dentry->d_name.len;
44056 + memcpy(d_name, name, len);
44057 + name = d_name;
44058 + } else
44059 + len = strlen(name);
44060
44061 /*
44062 * We'll have a dentry and an inode for
44063 diff --git a/fs/dcache.c b/fs/dcache.c
44064 index 4046904..5e31505 100644
44065 --- a/fs/dcache.c
44066 +++ b/fs/dcache.c
44067 @@ -3154,7 +3154,7 @@ void __init vfs_caches_init(unsigned long mempages)
44068 mempages -= reserve;
44069
44070 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44071 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44072 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44073
44074 dcache_init();
44075 inode_init();
44076 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44077 index b80bc84..0d46d1a 100644
44078 --- a/fs/debugfs/inode.c
44079 +++ b/fs/debugfs/inode.c
44080 @@ -408,7 +408,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44081 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44082 {
44083 return debugfs_create_file(name,
44084 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44085 + S_IFDIR | S_IRWXU,
44086 +#else
44087 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44088 +#endif
44089 parent, NULL, NULL);
44090 }
44091 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44092 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44093 index a07441a..046fc0d 100644
44094 --- a/fs/ecryptfs/inode.c
44095 +++ b/fs/ecryptfs/inode.c
44096 @@ -671,7 +671,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44097 old_fs = get_fs();
44098 set_fs(get_ds());
44099 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44100 - (char __user *)lower_buf,
44101 + (char __force_user *)lower_buf,
44102 PATH_MAX);
44103 set_fs(old_fs);
44104 if (rc < 0)
44105 @@ -703,7 +703,7 @@ out:
44106 static void
44107 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44108 {
44109 - char *buf = nd_get_link(nd);
44110 + const char *buf = nd_get_link(nd);
44111 if (!IS_ERR(buf)) {
44112 /* Free the char* */
44113 kfree(buf);
44114 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44115 index c0038f6..47ab347 100644
44116 --- a/fs/ecryptfs/miscdev.c
44117 +++ b/fs/ecryptfs/miscdev.c
44118 @@ -355,7 +355,7 @@ check_list:
44119 goto out_unlock_msg_ctx;
44120 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44121 if (msg_ctx->msg) {
44122 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44123 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44124 goto out_unlock_msg_ctx;
44125 i += packet_length_size;
44126 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44127 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44128 index b2a34a1..162fa69 100644
44129 --- a/fs/ecryptfs/read_write.c
44130 +++ b/fs/ecryptfs/read_write.c
44131 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44132 return -EIO;
44133 fs_save = get_fs();
44134 set_fs(get_ds());
44135 - rc = vfs_write(lower_file, data, size, &offset);
44136 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44137 set_fs(fs_save);
44138 mark_inode_dirty_sync(ecryptfs_inode);
44139 return rc;
44140 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44141 return -EIO;
44142 fs_save = get_fs();
44143 set_fs(get_ds());
44144 - rc = vfs_read(lower_file, data, size, &offset);
44145 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44146 set_fs(fs_save);
44147 return rc;
44148 }
44149 diff --git a/fs/exec.c b/fs/exec.c
44150 index e95aeed..9c7b4c2 100644
44151 --- a/fs/exec.c
44152 +++ b/fs/exec.c
44153 @@ -55,6 +55,15 @@
44154 #include <linux/pipe_fs_i.h>
44155 #include <linux/oom.h>
44156 #include <linux/compat.h>
44157 +#include <linux/random.h>
44158 +#include <linux/seq_file.h>
44159 +
44160 +#ifdef CONFIG_PAX_REFCOUNT
44161 +#include <linux/kallsyms.h>
44162 +#include <linux/kdebug.h>
44163 +#endif
44164 +
44165 +#include <trace/events/fs.h>
44166
44167 #include <asm/uaccess.h>
44168 #include <asm/mmu_context.h>
44169 @@ -66,6 +75,18 @@
44170
44171 #include <trace/events/sched.h>
44172
44173 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44174 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44175 +{
44176 + 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");
44177 +}
44178 +#endif
44179 +
44180 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44181 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44182 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44183 +#endif
44184 +
44185 int core_uses_pid;
44186 char core_pattern[CORENAME_MAX_SIZE] = "core";
44187 unsigned int core_pipe_limit;
44188 @@ -75,7 +96,7 @@ struct core_name {
44189 char *corename;
44190 int used, size;
44191 };
44192 -static atomic_t call_count = ATOMIC_INIT(1);
44193 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44194
44195 /* The maximal length of core_pattern is also specified in sysctl.c */
44196
44197 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44198 int write)
44199 {
44200 struct page *page;
44201 - int ret;
44202
44203 -#ifdef CONFIG_STACK_GROWSUP
44204 - if (write) {
44205 - ret = expand_downwards(bprm->vma, pos);
44206 - if (ret < 0)
44207 - return NULL;
44208 - }
44209 -#endif
44210 - ret = get_user_pages(current, bprm->mm, pos,
44211 - 1, write, 1, &page, NULL);
44212 - if (ret <= 0)
44213 + if (0 > expand_downwards(bprm->vma, pos))
44214 + return NULL;
44215 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44216 return NULL;
44217
44218 if (write) {
44219 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44220 if (size <= ARG_MAX)
44221 return page;
44222
44223 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44224 + // only allow 512KB for argv+env on suid/sgid binaries
44225 + // to prevent easy ASLR exhaustion
44226 + if (((bprm->cred->euid != current_euid()) ||
44227 + (bprm->cred->egid != current_egid())) &&
44228 + (size > (512 * 1024))) {
44229 + put_page(page);
44230 + return NULL;
44231 + }
44232 +#endif
44233 +
44234 /*
44235 * Limit to 1/4-th the stack size for the argv+env strings.
44236 * This ensures that:
44237 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44238 vma->vm_end = STACK_TOP_MAX;
44239 vma->vm_start = vma->vm_end - PAGE_SIZE;
44240 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44241 +
44242 +#ifdef CONFIG_PAX_SEGMEXEC
44243 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44244 +#endif
44245 +
44246 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44247 INIT_LIST_HEAD(&vma->anon_vma_chain);
44248
44249 @@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44250 mm->stack_vm = mm->total_vm = 1;
44251 up_write(&mm->mmap_sem);
44252 bprm->p = vma->vm_end - sizeof(void *);
44253 +
44254 +#ifdef CONFIG_PAX_RANDUSTACK
44255 + if (randomize_va_space)
44256 + bprm->p ^= random32() & ~PAGE_MASK;
44257 +#endif
44258 +
44259 return 0;
44260 err:
44261 up_write(&mm->mmap_sem);
44262 @@ -395,19 +430,7 @@ err:
44263 return err;
44264 }
44265
44266 -struct user_arg_ptr {
44267 -#ifdef CONFIG_COMPAT
44268 - bool is_compat;
44269 -#endif
44270 - union {
44271 - const char __user *const __user *native;
44272 -#ifdef CONFIG_COMPAT
44273 - compat_uptr_t __user *compat;
44274 -#endif
44275 - } ptr;
44276 -};
44277 -
44278 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44279 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44280 {
44281 const char __user *native;
44282
44283 @@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44284 compat_uptr_t compat;
44285
44286 if (get_user(compat, argv.ptr.compat + nr))
44287 - return ERR_PTR(-EFAULT);
44288 + return (const char __force_user *)ERR_PTR(-EFAULT);
44289
44290 return compat_ptr(compat);
44291 }
44292 #endif
44293
44294 if (get_user(native, argv.ptr.native + nr))
44295 - return ERR_PTR(-EFAULT);
44296 + return (const char __force_user *)ERR_PTR(-EFAULT);
44297
44298 return native;
44299 }
44300 @@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
44301 if (!p)
44302 break;
44303
44304 - if (IS_ERR(p))
44305 + if (IS_ERR((const char __force_kernel *)p))
44306 return -EFAULT;
44307
44308 if (i++ >= max)
44309 @@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44310
44311 ret = -EFAULT;
44312 str = get_user_arg_ptr(argv, argc);
44313 - if (IS_ERR(str))
44314 + if (IS_ERR((const char __force_kernel *)str))
44315 goto out;
44316
44317 len = strnlen_user(str, MAX_ARG_STRLEN);
44318 @@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44319 int r;
44320 mm_segment_t oldfs = get_fs();
44321 struct user_arg_ptr argv = {
44322 - .ptr.native = (const char __user *const __user *)__argv,
44323 + .ptr.native = (const char __force_user *const __force_user *)__argv,
44324 };
44325
44326 set_fs(KERNEL_DS);
44327 @@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44328 unsigned long new_end = old_end - shift;
44329 struct mmu_gather tlb;
44330
44331 - BUG_ON(new_start > new_end);
44332 + if (new_start >= new_end || new_start < mmap_min_addr)
44333 + return -ENOMEM;
44334
44335 /*
44336 * ensure there are no vmas between where we want to go
44337 @@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44338 if (vma != find_vma(mm, new_start))
44339 return -EFAULT;
44340
44341 +#ifdef CONFIG_PAX_SEGMEXEC
44342 + BUG_ON(pax_find_mirror_vma(vma));
44343 +#endif
44344 +
44345 /*
44346 * cover the whole range: [new_start, old_end)
44347 */
44348 @@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44349 stack_top = arch_align_stack(stack_top);
44350 stack_top = PAGE_ALIGN(stack_top);
44351
44352 - if (unlikely(stack_top < mmap_min_addr) ||
44353 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44354 - return -ENOMEM;
44355 -
44356 stack_shift = vma->vm_end - stack_top;
44357
44358 bprm->p -= stack_shift;
44359 @@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44360 bprm->exec -= stack_shift;
44361
44362 down_write(&mm->mmap_sem);
44363 +
44364 + /* Move stack pages down in memory. */
44365 + if (stack_shift) {
44366 + ret = shift_arg_pages(vma, stack_shift);
44367 + if (ret)
44368 + goto out_unlock;
44369 + }
44370 +
44371 vm_flags = VM_STACK_FLAGS;
44372
44373 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44374 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44375 + vm_flags &= ~VM_EXEC;
44376 +
44377 +#ifdef CONFIG_PAX_MPROTECT
44378 + if (mm->pax_flags & MF_PAX_MPROTECT)
44379 + vm_flags &= ~VM_MAYEXEC;
44380 +#endif
44381 +
44382 + }
44383 +#endif
44384 +
44385 /*
44386 * Adjust stack execute permissions; explicitly enable for
44387 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44388 @@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44389 goto out_unlock;
44390 BUG_ON(prev != vma);
44391
44392 - /* Move stack pages down in memory. */
44393 - if (stack_shift) {
44394 - ret = shift_arg_pages(vma, stack_shift);
44395 - if (ret)
44396 - goto out_unlock;
44397 - }
44398 -
44399 /* mprotect_fixup is overkill to remove the temporary stack flags */
44400 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44401
44402 @@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
44403
44404 fsnotify_open(file);
44405
44406 + trace_open_exec(name);
44407 +
44408 err = deny_write_access(file);
44409 if (err)
44410 goto exit;
44411 @@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
44412 old_fs = get_fs();
44413 set_fs(get_ds());
44414 /* The cast to a user pointer is valid due to the set_fs() */
44415 - result = vfs_read(file, (void __user *)addr, count, &pos);
44416 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
44417 set_fs(old_fs);
44418 return result;
44419 }
44420 @@ -1257,7 +1296,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
44421 }
44422 rcu_read_unlock();
44423
44424 - if (p->fs->users > n_fs) {
44425 + if (atomic_read(&p->fs->users) > n_fs) {
44426 bprm->unsafe |= LSM_UNSAFE_SHARE;
44427 } else {
44428 res = -EAGAIN;
44429 @@ -1460,6 +1499,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
44430
44431 EXPORT_SYMBOL(search_binary_handler);
44432
44433 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44434 +static DEFINE_PER_CPU(u64, exec_counter);
44435 +static int __init init_exec_counters(void)
44436 +{
44437 + unsigned int cpu;
44438 +
44439 + for_each_possible_cpu(cpu) {
44440 + per_cpu(exec_counter, cpu) = (u64)cpu;
44441 + }
44442 +
44443 + return 0;
44444 +}
44445 +early_initcall(init_exec_counters);
44446 +static inline void increment_exec_counter(void)
44447 +{
44448 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
44449 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
44450 +}
44451 +#else
44452 +static inline void increment_exec_counter(void) {}
44453 +#endif
44454 +
44455 /*
44456 * sys_execve() executes a new program.
44457 */
44458 @@ -1468,6 +1529,11 @@ static int do_execve_common(const char *filename,
44459 struct user_arg_ptr envp,
44460 struct pt_regs *regs)
44461 {
44462 +#ifdef CONFIG_GRKERNSEC
44463 + struct file *old_exec_file;
44464 + struct acl_subject_label *old_acl;
44465 + struct rlimit old_rlim[RLIM_NLIMITS];
44466 +#endif
44467 struct linux_binprm *bprm;
44468 struct file *file;
44469 struct files_struct *displaced;
44470 @@ -1475,6 +1541,8 @@ static int do_execve_common(const char *filename,
44471 int retval;
44472 const struct cred *cred = current_cred();
44473
44474 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44475 +
44476 /*
44477 * We move the actual failure in case of RLIMIT_NPROC excess from
44478 * set*uid() to execve() because too many poorly written programs
44479 @@ -1515,12 +1583,27 @@ static int do_execve_common(const char *filename,
44480 if (IS_ERR(file))
44481 goto out_unmark;
44482
44483 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
44484 + retval = -EPERM;
44485 + goto out_file;
44486 + }
44487 +
44488 sched_exec();
44489
44490 bprm->file = file;
44491 bprm->filename = filename;
44492 bprm->interp = filename;
44493
44494 + if (gr_process_user_ban()) {
44495 + retval = -EPERM;
44496 + goto out_file;
44497 + }
44498 +
44499 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44500 + retval = -EACCES;
44501 + goto out_file;
44502 + }
44503 +
44504 retval = bprm_mm_init(bprm);
44505 if (retval)
44506 goto out_file;
44507 @@ -1537,24 +1620,65 @@ static int do_execve_common(const char *filename,
44508 if (retval < 0)
44509 goto out;
44510
44511 +#ifdef CONFIG_GRKERNSEC
44512 + old_acl = current->acl;
44513 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44514 + old_exec_file = current->exec_file;
44515 + get_file(file);
44516 + current->exec_file = file;
44517 +#endif
44518 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44519 + /* limit suid stack to 8MB
44520 + we saved the old limits above and will restore them if this exec fails
44521 + */
44522 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44523 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44524 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44525 +#endif
44526 +
44527 + if (!gr_tpe_allow(file)) {
44528 + retval = -EACCES;
44529 + goto out_fail;
44530 + }
44531 +
44532 + if (gr_check_crash_exec(file)) {
44533 + retval = -EACCES;
44534 + goto out_fail;
44535 + }
44536 +
44537 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44538 + bprm->unsafe);
44539 + if (retval < 0)
44540 + goto out_fail;
44541 +
44542 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44543 if (retval < 0)
44544 - goto out;
44545 + goto out_fail;
44546
44547 bprm->exec = bprm->p;
44548 retval = copy_strings(bprm->envc, envp, bprm);
44549 if (retval < 0)
44550 - goto out;
44551 + goto out_fail;
44552
44553 retval = copy_strings(bprm->argc, argv, bprm);
44554 if (retval < 0)
44555 - goto out;
44556 + goto out_fail;
44557 +
44558 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44559 +
44560 + gr_handle_exec_args(bprm, argv);
44561
44562 retval = search_binary_handler(bprm,regs);
44563 if (retval < 0)
44564 - goto out;
44565 + goto out_fail;
44566 +#ifdef CONFIG_GRKERNSEC
44567 + if (old_exec_file)
44568 + fput(old_exec_file);
44569 +#endif
44570
44571 /* execve succeeded */
44572 +
44573 + increment_exec_counter();
44574 current->fs->in_exec = 0;
44575 current->in_execve = 0;
44576 acct_update_integrals(current);
44577 @@ -1563,6 +1687,14 @@ static int do_execve_common(const char *filename,
44578 put_files_struct(displaced);
44579 return retval;
44580
44581 +out_fail:
44582 +#ifdef CONFIG_GRKERNSEC
44583 + current->acl = old_acl;
44584 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44585 + fput(current->exec_file);
44586 + current->exec_file = old_exec_file;
44587 +#endif
44588 +
44589 out:
44590 if (bprm->mm) {
44591 acct_arg_size(bprm, 0);
44592 @@ -1636,7 +1768,7 @@ static int expand_corename(struct core_name *cn)
44593 {
44594 char *old_corename = cn->corename;
44595
44596 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44597 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44598 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44599
44600 if (!cn->corename) {
44601 @@ -1733,7 +1865,7 @@ static int format_corename(struct core_name *cn, long signr)
44602 int pid_in_pattern = 0;
44603 int err = 0;
44604
44605 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44606 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44607 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44608 cn->used = 0;
44609
44610 @@ -1830,6 +1962,250 @@ out:
44611 return ispipe;
44612 }
44613
44614 +int pax_check_flags(unsigned long *flags)
44615 +{
44616 + int retval = 0;
44617 +
44618 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44619 + if (*flags & MF_PAX_SEGMEXEC)
44620 + {
44621 + *flags &= ~MF_PAX_SEGMEXEC;
44622 + retval = -EINVAL;
44623 + }
44624 +#endif
44625 +
44626 + if ((*flags & MF_PAX_PAGEEXEC)
44627 +
44628 +#ifdef CONFIG_PAX_PAGEEXEC
44629 + && (*flags & MF_PAX_SEGMEXEC)
44630 +#endif
44631 +
44632 + )
44633 + {
44634 + *flags &= ~MF_PAX_PAGEEXEC;
44635 + retval = -EINVAL;
44636 + }
44637 +
44638 + if ((*flags & MF_PAX_MPROTECT)
44639 +
44640 +#ifdef CONFIG_PAX_MPROTECT
44641 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44642 +#endif
44643 +
44644 + )
44645 + {
44646 + *flags &= ~MF_PAX_MPROTECT;
44647 + retval = -EINVAL;
44648 + }
44649 +
44650 + if ((*flags & MF_PAX_EMUTRAMP)
44651 +
44652 +#ifdef CONFIG_PAX_EMUTRAMP
44653 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44654 +#endif
44655 +
44656 + )
44657 + {
44658 + *flags &= ~MF_PAX_EMUTRAMP;
44659 + retval = -EINVAL;
44660 + }
44661 +
44662 + return retval;
44663 +}
44664 +
44665 +EXPORT_SYMBOL(pax_check_flags);
44666 +
44667 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44668 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44669 +{
44670 + struct task_struct *tsk = current;
44671 + struct mm_struct *mm = current->mm;
44672 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44673 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44674 + char *path_exec = NULL;
44675 + char *path_fault = NULL;
44676 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
44677 +
44678 + if (buffer_exec && buffer_fault) {
44679 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44680 +
44681 + down_read(&mm->mmap_sem);
44682 + vma = mm->mmap;
44683 + while (vma && (!vma_exec || !vma_fault)) {
44684 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44685 + vma_exec = vma;
44686 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44687 + vma_fault = vma;
44688 + vma = vma->vm_next;
44689 + }
44690 + if (vma_exec) {
44691 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44692 + if (IS_ERR(path_exec))
44693 + path_exec = "<path too long>";
44694 + else {
44695 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44696 + if (path_exec) {
44697 + *path_exec = 0;
44698 + path_exec = buffer_exec;
44699 + } else
44700 + path_exec = "<path too long>";
44701 + }
44702 + }
44703 + if (vma_fault) {
44704 + start = vma_fault->vm_start;
44705 + end = vma_fault->vm_end;
44706 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44707 + if (vma_fault->vm_file) {
44708 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44709 + if (IS_ERR(path_fault))
44710 + path_fault = "<path too long>";
44711 + else {
44712 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44713 + if (path_fault) {
44714 + *path_fault = 0;
44715 + path_fault = buffer_fault;
44716 + } else
44717 + path_fault = "<path too long>";
44718 + }
44719 + } else
44720 + path_fault = "<anonymous mapping>";
44721 + }
44722 + up_read(&mm->mmap_sem);
44723 + }
44724 + if (tsk->signal->curr_ip)
44725 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44726 + else
44727 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44728 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44729 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44730 + task_uid(tsk), task_euid(tsk), pc, sp);
44731 + free_page((unsigned long)buffer_exec);
44732 + free_page((unsigned long)buffer_fault);
44733 + pax_report_insns(regs, pc, sp);
44734 + do_coredump(SIGKILL, SIGKILL, regs);
44735 +}
44736 +#endif
44737 +
44738 +#ifdef CONFIG_PAX_REFCOUNT
44739 +void pax_report_refcount_overflow(struct pt_regs *regs)
44740 +{
44741 + if (current->signal->curr_ip)
44742 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44743 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44744 + else
44745 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44746 + current->comm, task_pid_nr(current), current_uid(), current_euid());
44747 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44748 + show_regs(regs);
44749 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44750 +}
44751 +#endif
44752 +
44753 +#ifdef CONFIG_PAX_USERCOPY
44754 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44755 +static noinline int check_stack_object(const void *obj, unsigned long len)
44756 +{
44757 + const void * const stack = task_stack_page(current);
44758 + const void * const stackend = stack + THREAD_SIZE;
44759 +
44760 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44761 + const void *frame = NULL;
44762 + const void *oldframe;
44763 +#endif
44764 +
44765 + if (obj + len < obj)
44766 + return -1;
44767 +
44768 + if (obj + len <= stack || stackend <= obj)
44769 + return 0;
44770 +
44771 + if (obj < stack || stackend < obj + len)
44772 + return -1;
44773 +
44774 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44775 + oldframe = __builtin_frame_address(1);
44776 + if (oldframe)
44777 + frame = __builtin_frame_address(2);
44778 + /*
44779 + low ----------------------------------------------> high
44780 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
44781 + ^----------------^
44782 + allow copies only within here
44783 + */
44784 + while (stack <= frame && frame < stackend) {
44785 + /* if obj + len extends past the last frame, this
44786 + check won't pass and the next frame will be 0,
44787 + causing us to bail out and correctly report
44788 + the copy as invalid
44789 + */
44790 + if (obj + len <= frame)
44791 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44792 + oldframe = frame;
44793 + frame = *(const void * const *)frame;
44794 + }
44795 + return -1;
44796 +#else
44797 + return 1;
44798 +#endif
44799 +}
44800 +
44801 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44802 +{
44803 + if (current->signal->curr_ip)
44804 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44805 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44806 + else
44807 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44808 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44809 + dump_stack();
44810 + gr_handle_kernel_exploit();
44811 + do_group_exit(SIGKILL);
44812 +}
44813 +#endif
44814 +
44815 +void check_object_size(const void *ptr, unsigned long n, bool to)
44816 +{
44817 +
44818 +#ifdef CONFIG_PAX_USERCOPY
44819 + const char *type;
44820 +
44821 + if (!n)
44822 + return;
44823 +
44824 + type = check_heap_object(ptr, n, to);
44825 + if (!type) {
44826 + if (check_stack_object(ptr, n) != -1)
44827 + return;
44828 + type = "<process stack>";
44829 + }
44830 +
44831 + pax_report_usercopy(ptr, n, to, type);
44832 +#endif
44833 +
44834 +}
44835 +EXPORT_SYMBOL(check_object_size);
44836 +
44837 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44838 +void pax_track_stack(void)
44839 +{
44840 + unsigned long sp = (unsigned long)&sp;
44841 + if (sp < current_thread_info()->lowest_stack &&
44842 + sp > (unsigned long)task_stack_page(current))
44843 + current_thread_info()->lowest_stack = sp;
44844 +}
44845 +EXPORT_SYMBOL(pax_track_stack);
44846 +#endif
44847 +
44848 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
44849 +void report_size_overflow(const char *file, unsigned int line, const char *func)
44850 +{
44851 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44852 + dump_stack();
44853 + do_group_exit(SIGKILL);
44854 +}
44855 +EXPORT_SYMBOL(report_size_overflow);
44856 +#endif
44857 +
44858 static int zap_process(struct task_struct *start, int exit_code)
44859 {
44860 struct task_struct *t;
44861 @@ -2002,17 +2378,17 @@ static void coredump_finish(struct mm_struct *mm)
44862 void set_dumpable(struct mm_struct *mm, int value)
44863 {
44864 switch (value) {
44865 - case 0:
44866 + case SUID_DUMPABLE_DISABLED:
44867 clear_bit(MMF_DUMPABLE, &mm->flags);
44868 smp_wmb();
44869 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
44870 break;
44871 - case 1:
44872 + case SUID_DUMPABLE_ENABLED:
44873 set_bit(MMF_DUMPABLE, &mm->flags);
44874 smp_wmb();
44875 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
44876 break;
44877 - case 2:
44878 + case SUID_DUMPABLE_SAFE:
44879 set_bit(MMF_DUMP_SECURELY, &mm->flags);
44880 smp_wmb();
44881 set_bit(MMF_DUMPABLE, &mm->flags);
44882 @@ -2025,7 +2401,7 @@ static int __get_dumpable(unsigned long mm_flags)
44883 int ret;
44884
44885 ret = mm_flags & MMF_DUMPABLE_MASK;
44886 - return (ret >= 2) ? 2 : ret;
44887 + return (ret > SUID_DUMPABLE_ENABLED) ? SUID_DUMPABLE_SAFE : ret;
44888 }
44889
44890 int get_dumpable(struct mm_struct *mm)
44891 @@ -2040,17 +2416,17 @@ static void wait_for_dump_helpers(struct file *file)
44892 pipe = file->f_path.dentry->d_inode->i_pipe;
44893
44894 pipe_lock(pipe);
44895 - pipe->readers++;
44896 - pipe->writers--;
44897 + atomic_inc(&pipe->readers);
44898 + atomic_dec(&pipe->writers);
44899
44900 - while ((pipe->readers > 1) && (!signal_pending(current))) {
44901 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44902 wake_up_interruptible_sync(&pipe->wait);
44903 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44904 pipe_wait(pipe);
44905 }
44906
44907 - pipe->readers--;
44908 - pipe->writers++;
44909 + atomic_dec(&pipe->readers);
44910 + atomic_inc(&pipe->writers);
44911 pipe_unlock(pipe);
44912
44913 }
44914 @@ -2111,7 +2487,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44915 int retval = 0;
44916 int flag = 0;
44917 int ispipe;
44918 - static atomic_t core_dump_count = ATOMIC_INIT(0);
44919 + bool need_nonrelative = false;
44920 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44921 struct coredump_params cprm = {
44922 .signr = signr,
44923 .regs = regs,
44924 @@ -2126,6 +2503,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44925
44926 audit_core_dumps(signr);
44927
44928 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44929 + gr_handle_brute_attach(current, cprm.mm_flags);
44930 +
44931 binfmt = mm->binfmt;
44932 if (!binfmt || !binfmt->core_dump)
44933 goto fail;
44934 @@ -2136,14 +2516,16 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44935 if (!cred)
44936 goto fail;
44937 /*
44938 - * We cannot trust fsuid as being the "true" uid of the
44939 - * process nor do we know its entire history. We only know it
44940 - * was tainted so we dump it as root in mode 2.
44941 + * We cannot trust fsuid as being the "true" uid of the process
44942 + * nor do we know its entire history. We only know it was tainted
44943 + * so we dump it as root in mode 2, and only into a controlled
44944 + * environment (pipe handler or fully qualified path).
44945 */
44946 - if (__get_dumpable(cprm.mm_flags) == 2) {
44947 + if (__get_dumpable(cprm.mm_flags) == SUID_DUMPABLE_SAFE) {
44948 /* Setuid core dump mode */
44949 flag = O_EXCL; /* Stop rewrite attacks */
44950 cred->fsuid = GLOBAL_ROOT_UID; /* Dump root private */
44951 + need_nonrelative = true;
44952 }
44953
44954 retval = coredump_wait(exit_code, &core_state);
44955 @@ -2193,7 +2575,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44956 }
44957 cprm.limit = RLIM_INFINITY;
44958
44959 - dump_count = atomic_inc_return(&core_dump_count);
44960 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
44961 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44962 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44963 task_tgid_vnr(current), current->comm);
44964 @@ -2220,9 +2602,19 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44965 } else {
44966 struct inode *inode;
44967
44968 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44969 +
44970 if (cprm.limit < binfmt->min_coredump)
44971 goto fail_unlock;
44972
44973 + if (need_nonrelative && cn.corename[0] != '/') {
44974 + printk(KERN_WARNING "Pid %d(%s) can only dump core "\
44975 + "to fully qualified path!\n",
44976 + task_tgid_vnr(current), current->comm);
44977 + printk(KERN_WARNING "Skipping core dump\n");
44978 + goto fail_unlock;
44979 + }
44980 +
44981 cprm.file = filp_open(cn.corename,
44982 O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag,
44983 0600);
44984 @@ -2263,7 +2655,7 @@ close_fail:
44985 filp_close(cprm.file, NULL);
44986 fail_dropcount:
44987 if (ispipe)
44988 - atomic_dec(&core_dump_count);
44989 + atomic_dec_unchecked(&core_dump_count);
44990 fail_unlock:
44991 kfree(cn.corename);
44992 fail_corename:
44993 @@ -2282,7 +2674,7 @@ fail:
44994 */
44995 int dump_write(struct file *file, const void *addr, int nr)
44996 {
44997 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44998 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44999 }
45000 EXPORT_SYMBOL(dump_write);
45001
45002 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45003 index 1c36139..cf6b350 100644
45004 --- a/fs/ext2/balloc.c
45005 +++ b/fs/ext2/balloc.c
45006 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45007
45008 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45009 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45010 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45011 + if (free_blocks < root_blocks + 1 &&
45012 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45013 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45014 - !in_group_p (sbi->s_resgid))) {
45015 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45016 return 0;
45017 }
45018 return 1;
45019 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45020 index 25cd608..9ed5294 100644
45021 --- a/fs/ext3/balloc.c
45022 +++ b/fs/ext3/balloc.c
45023 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45024
45025 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45026 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45027 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45028 + if (free_blocks < root_blocks + 1 &&
45029 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45030 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45031 - !in_group_p (sbi->s_resgid))) {
45032 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45033 return 0;
45034 }
45035 return 1;
45036 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45037 index d23b31c..0585239 100644
45038 --- a/fs/ext4/balloc.c
45039 +++ b/fs/ext4/balloc.c
45040 @@ -488,8 +488,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45041 /* Hm, nope. Are (enough) root reserved clusters available? */
45042 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45043 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45044 - capable(CAP_SYS_RESOURCE) ||
45045 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45046 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45047 + capable_nolog(CAP_SYS_RESOURCE)) {
45048
45049 if (free_clusters >= (nclusters + dirty_clusters))
45050 return 1;
45051 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45052 index 01434f2..bd995b4 100644
45053 --- a/fs/ext4/ext4.h
45054 +++ b/fs/ext4/ext4.h
45055 @@ -1246,19 +1246,19 @@ struct ext4_sb_info {
45056 unsigned long s_mb_last_start;
45057
45058 /* stats for buddy allocator */
45059 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45060 - atomic_t s_bal_success; /* we found long enough chunks */
45061 - atomic_t s_bal_allocated; /* in blocks */
45062 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45063 - atomic_t s_bal_goals; /* goal hits */
45064 - atomic_t s_bal_breaks; /* too long searches */
45065 - atomic_t s_bal_2orders; /* 2^order hits */
45066 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45067 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45068 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45069 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45070 + atomic_unchecked_t s_bal_goals; /* goal hits */
45071 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45072 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45073 spinlock_t s_bal_lock;
45074 unsigned long s_mb_buddies_generated;
45075 unsigned long long s_mb_generation_time;
45076 - atomic_t s_mb_lost_chunks;
45077 - atomic_t s_mb_preallocated;
45078 - atomic_t s_mb_discarded;
45079 + atomic_unchecked_t s_mb_lost_chunks;
45080 + atomic_unchecked_t s_mb_preallocated;
45081 + atomic_unchecked_t s_mb_discarded;
45082 atomic_t s_lock_busy;
45083
45084 /* locality groups */
45085 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45086 index 1cd6994..5799d45 100644
45087 --- a/fs/ext4/mballoc.c
45088 +++ b/fs/ext4/mballoc.c
45089 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45090 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45091
45092 if (EXT4_SB(sb)->s_mb_stats)
45093 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45094 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45095
45096 break;
45097 }
45098 @@ -2041,7 +2041,7 @@ repeat:
45099 ac->ac_status = AC_STATUS_CONTINUE;
45100 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45101 cr = 3;
45102 - atomic_inc(&sbi->s_mb_lost_chunks);
45103 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45104 goto repeat;
45105 }
45106 }
45107 @@ -2545,25 +2545,25 @@ int ext4_mb_release(struct super_block *sb)
45108 if (sbi->s_mb_stats) {
45109 ext4_msg(sb, KERN_INFO,
45110 "mballoc: %u blocks %u reqs (%u success)",
45111 - atomic_read(&sbi->s_bal_allocated),
45112 - atomic_read(&sbi->s_bal_reqs),
45113 - atomic_read(&sbi->s_bal_success));
45114 + atomic_read_unchecked(&sbi->s_bal_allocated),
45115 + atomic_read_unchecked(&sbi->s_bal_reqs),
45116 + atomic_read_unchecked(&sbi->s_bal_success));
45117 ext4_msg(sb, KERN_INFO,
45118 "mballoc: %u extents scanned, %u goal hits, "
45119 "%u 2^N hits, %u breaks, %u lost",
45120 - atomic_read(&sbi->s_bal_ex_scanned),
45121 - atomic_read(&sbi->s_bal_goals),
45122 - atomic_read(&sbi->s_bal_2orders),
45123 - atomic_read(&sbi->s_bal_breaks),
45124 - atomic_read(&sbi->s_mb_lost_chunks));
45125 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45126 + atomic_read_unchecked(&sbi->s_bal_goals),
45127 + atomic_read_unchecked(&sbi->s_bal_2orders),
45128 + atomic_read_unchecked(&sbi->s_bal_breaks),
45129 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45130 ext4_msg(sb, KERN_INFO,
45131 "mballoc: %lu generated and it took %Lu",
45132 sbi->s_mb_buddies_generated,
45133 sbi->s_mb_generation_time);
45134 ext4_msg(sb, KERN_INFO,
45135 "mballoc: %u preallocated, %u discarded",
45136 - atomic_read(&sbi->s_mb_preallocated),
45137 - atomic_read(&sbi->s_mb_discarded));
45138 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45139 + atomic_read_unchecked(&sbi->s_mb_discarded));
45140 }
45141
45142 free_percpu(sbi->s_locality_groups);
45143 @@ -3047,16 +3047,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45144 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45145
45146 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45147 - atomic_inc(&sbi->s_bal_reqs);
45148 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45149 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45150 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45151 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45152 - atomic_inc(&sbi->s_bal_success);
45153 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45154 + atomic_inc_unchecked(&sbi->s_bal_success);
45155 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45156 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45157 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45158 - atomic_inc(&sbi->s_bal_goals);
45159 + atomic_inc_unchecked(&sbi->s_bal_goals);
45160 if (ac->ac_found > sbi->s_mb_max_to_scan)
45161 - atomic_inc(&sbi->s_bal_breaks);
45162 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45163 }
45164
45165 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45166 @@ -3456,7 +3456,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45167 trace_ext4_mb_new_inode_pa(ac, pa);
45168
45169 ext4_mb_use_inode_pa(ac, pa);
45170 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45171 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45172
45173 ei = EXT4_I(ac->ac_inode);
45174 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45175 @@ -3516,7 +3516,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45176 trace_ext4_mb_new_group_pa(ac, pa);
45177
45178 ext4_mb_use_group_pa(ac, pa);
45179 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45180 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45181
45182 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45183 lg = ac->ac_lg;
45184 @@ -3605,7 +3605,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45185 * from the bitmap and continue.
45186 */
45187 }
45188 - atomic_add(free, &sbi->s_mb_discarded);
45189 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45190
45191 return err;
45192 }
45193 @@ -3623,7 +3623,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45194 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45195 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45196 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45197 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45198 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45199 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45200
45201 return 0;
45202 diff --git a/fs/fcntl.c b/fs/fcntl.c
45203 index 81b70e6..d9ae6cf 100644
45204 --- a/fs/fcntl.c
45205 +++ b/fs/fcntl.c
45206 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45207 if (err)
45208 return err;
45209
45210 + if (gr_handle_chroot_fowner(pid, type))
45211 + return -ENOENT;
45212 + if (gr_check_protected_task_fowner(pid, type))
45213 + return -EACCES;
45214 +
45215 f_modown(filp, pid, type, force);
45216 return 0;
45217 }
45218 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
45219
45220 static int f_setown_ex(struct file *filp, unsigned long arg)
45221 {
45222 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45223 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45224 struct f_owner_ex owner;
45225 struct pid *pid;
45226 int type;
45227 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45228
45229 static int f_getown_ex(struct file *filp, unsigned long arg)
45230 {
45231 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45232 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45233 struct f_owner_ex owner;
45234 int ret = 0;
45235
45236 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45237 switch (cmd) {
45238 case F_DUPFD:
45239 case F_DUPFD_CLOEXEC:
45240 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45241 if (arg >= rlimit(RLIMIT_NOFILE))
45242 break;
45243 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45244 diff --git a/fs/fifo.c b/fs/fifo.c
45245 index cf6f434..3d7942c 100644
45246 --- a/fs/fifo.c
45247 +++ b/fs/fifo.c
45248 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45249 */
45250 filp->f_op = &read_pipefifo_fops;
45251 pipe->r_counter++;
45252 - if (pipe->readers++ == 0)
45253 + if (atomic_inc_return(&pipe->readers) == 1)
45254 wake_up_partner(inode);
45255
45256 - if (!pipe->writers) {
45257 + if (!atomic_read(&pipe->writers)) {
45258 if ((filp->f_flags & O_NONBLOCK)) {
45259 /* suppress POLLHUP until we have
45260 * seen a writer */
45261 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45262 * errno=ENXIO when there is no process reading the FIFO.
45263 */
45264 ret = -ENXIO;
45265 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45266 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45267 goto err;
45268
45269 filp->f_op = &write_pipefifo_fops;
45270 pipe->w_counter++;
45271 - if (!pipe->writers++)
45272 + if (atomic_inc_return(&pipe->writers) == 1)
45273 wake_up_partner(inode);
45274
45275 - if (!pipe->readers) {
45276 + if (!atomic_read(&pipe->readers)) {
45277 if (wait_for_partner(inode, &pipe->r_counter))
45278 goto err_wr;
45279 }
45280 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45281 */
45282 filp->f_op = &rdwr_pipefifo_fops;
45283
45284 - pipe->readers++;
45285 - pipe->writers++;
45286 + atomic_inc(&pipe->readers);
45287 + atomic_inc(&pipe->writers);
45288 pipe->r_counter++;
45289 pipe->w_counter++;
45290 - if (pipe->readers == 1 || pipe->writers == 1)
45291 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45292 wake_up_partner(inode);
45293 break;
45294
45295 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45296 return 0;
45297
45298 err_rd:
45299 - if (!--pipe->readers)
45300 + if (atomic_dec_and_test(&pipe->readers))
45301 wake_up_interruptible(&pipe->wait);
45302 ret = -ERESTARTSYS;
45303 goto err;
45304
45305 err_wr:
45306 - if (!--pipe->writers)
45307 + if (atomic_dec_and_test(&pipe->writers))
45308 wake_up_interruptible(&pipe->wait);
45309 ret = -ERESTARTSYS;
45310 goto err;
45311
45312 err:
45313 - if (!pipe->readers && !pipe->writers)
45314 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45315 free_pipe_info(inode);
45316
45317 err_nocleanup:
45318 diff --git a/fs/file.c b/fs/file.c
45319 index ba3f605..fade102 100644
45320 --- a/fs/file.c
45321 +++ b/fs/file.c
45322 @@ -15,6 +15,7 @@
45323 #include <linux/slab.h>
45324 #include <linux/vmalloc.h>
45325 #include <linux/file.h>
45326 +#include <linux/security.h>
45327 #include <linux/fdtable.h>
45328 #include <linux/bitops.h>
45329 #include <linux/interrupt.h>
45330 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
45331 * N.B. For clone tasks sharing a files structure, this test
45332 * will limit the total number of files that can be opened.
45333 */
45334 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45335 if (nr >= rlimit(RLIMIT_NOFILE))
45336 return -EMFILE;
45337
45338 diff --git a/fs/filesystems.c b/fs/filesystems.c
45339 index 96f2428..f5eeb8e 100644
45340 --- a/fs/filesystems.c
45341 +++ b/fs/filesystems.c
45342 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45343 int len = dot ? dot - name : strlen(name);
45344
45345 fs = __get_fs_type(name, len);
45346 +
45347 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45348 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45349 +#else
45350 if (!fs && (request_module("%.*s", len, name) == 0))
45351 +#endif
45352 fs = __get_fs_type(name, len);
45353
45354 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45355 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45356 index e159e68..e7d2a6f 100644
45357 --- a/fs/fs_struct.c
45358 +++ b/fs/fs_struct.c
45359 @@ -4,6 +4,7 @@
45360 #include <linux/path.h>
45361 #include <linux/slab.h>
45362 #include <linux/fs_struct.h>
45363 +#include <linux/grsecurity.h>
45364 #include "internal.h"
45365
45366 static inline void path_get_longterm(struct path *path)
45367 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45368 write_seqcount_begin(&fs->seq);
45369 old_root = fs->root;
45370 fs->root = *path;
45371 + gr_set_chroot_entries(current, path);
45372 write_seqcount_end(&fs->seq);
45373 spin_unlock(&fs->lock);
45374 if (old_root.dentry)
45375 @@ -65,6 +67,17 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45376 return 1;
45377 }
45378
45379 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45380 +{
45381 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45382 + return 0;
45383 + *p = *new;
45384 +
45385 + gr_set_chroot_entries(task, new);
45386 +
45387 + return 1;
45388 +}
45389 +
45390 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45391 {
45392 struct task_struct *g, *p;
45393 @@ -79,7 +92,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45394 int hits = 0;
45395 spin_lock(&fs->lock);
45396 write_seqcount_begin(&fs->seq);
45397 - hits += replace_path(&fs->root, old_root, new_root);
45398 + hits += replace_root_path(p, &fs->root, old_root, new_root);
45399 hits += replace_path(&fs->pwd, old_root, new_root);
45400 write_seqcount_end(&fs->seq);
45401 while (hits--) {
45402 @@ -111,7 +124,8 @@ void exit_fs(struct task_struct *tsk)
45403 task_lock(tsk);
45404 spin_lock(&fs->lock);
45405 tsk->fs = NULL;
45406 - kill = !--fs->users;
45407 + gr_clear_chroot_entries(tsk);
45408 + kill = !atomic_dec_return(&fs->users);
45409 spin_unlock(&fs->lock);
45410 task_unlock(tsk);
45411 if (kill)
45412 @@ -124,7 +138,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45413 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45414 /* We don't need to lock fs - think why ;-) */
45415 if (fs) {
45416 - fs->users = 1;
45417 + atomic_set(&fs->users, 1);
45418 fs->in_exec = 0;
45419 spin_lock_init(&fs->lock);
45420 seqcount_init(&fs->seq);
45421 @@ -133,6 +147,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45422 spin_lock(&old->lock);
45423 fs->root = old->root;
45424 path_get_longterm(&fs->root);
45425 + /* instead of calling gr_set_chroot_entries here,
45426 + we call it from every caller of this function
45427 + */
45428 fs->pwd = old->pwd;
45429 path_get_longterm(&fs->pwd);
45430 spin_unlock(&old->lock);
45431 @@ -151,8 +168,9 @@ int unshare_fs_struct(void)
45432
45433 task_lock(current);
45434 spin_lock(&fs->lock);
45435 - kill = !--fs->users;
45436 + kill = !atomic_dec_return(&fs->users);
45437 current->fs = new_fs;
45438 + gr_set_chroot_entries(current, &new_fs->root);
45439 spin_unlock(&fs->lock);
45440 task_unlock(current);
45441
45442 @@ -165,13 +183,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45443
45444 int current_umask(void)
45445 {
45446 - return current->fs->umask;
45447 + return current->fs->umask | gr_acl_umask();
45448 }
45449 EXPORT_SYMBOL(current_umask);
45450
45451 /* to be mentioned only in INIT_TASK */
45452 struct fs_struct init_fs = {
45453 - .users = 1,
45454 + .users = ATOMIC_INIT(1),
45455 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45456 .seq = SEQCNT_ZERO,
45457 .umask = 0022,
45458 @@ -187,12 +205,13 @@ void daemonize_fs_struct(void)
45459 task_lock(current);
45460
45461 spin_lock(&init_fs.lock);
45462 - init_fs.users++;
45463 + atomic_inc(&init_fs.users);
45464 spin_unlock(&init_fs.lock);
45465
45466 spin_lock(&fs->lock);
45467 current->fs = &init_fs;
45468 - kill = !--fs->users;
45469 + gr_set_chroot_entries(current, &current->fs->root);
45470 + kill = !atomic_dec_return(&fs->users);
45471 spin_unlock(&fs->lock);
45472
45473 task_unlock(current);
45474 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45475 index 9905350..02eaec4 100644
45476 --- a/fs/fscache/cookie.c
45477 +++ b/fs/fscache/cookie.c
45478 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45479 parent ? (char *) parent->def->name : "<no-parent>",
45480 def->name, netfs_data);
45481
45482 - fscache_stat(&fscache_n_acquires);
45483 + fscache_stat_unchecked(&fscache_n_acquires);
45484
45485 /* if there's no parent cookie, then we don't create one here either */
45486 if (!parent) {
45487 - fscache_stat(&fscache_n_acquires_null);
45488 + fscache_stat_unchecked(&fscache_n_acquires_null);
45489 _leave(" [no parent]");
45490 return NULL;
45491 }
45492 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45493 /* allocate and initialise a cookie */
45494 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45495 if (!cookie) {
45496 - fscache_stat(&fscache_n_acquires_oom);
45497 + fscache_stat_unchecked(&fscache_n_acquires_oom);
45498 _leave(" [ENOMEM]");
45499 return NULL;
45500 }
45501 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45502
45503 switch (cookie->def->type) {
45504 case FSCACHE_COOKIE_TYPE_INDEX:
45505 - fscache_stat(&fscache_n_cookie_index);
45506 + fscache_stat_unchecked(&fscache_n_cookie_index);
45507 break;
45508 case FSCACHE_COOKIE_TYPE_DATAFILE:
45509 - fscache_stat(&fscache_n_cookie_data);
45510 + fscache_stat_unchecked(&fscache_n_cookie_data);
45511 break;
45512 default:
45513 - fscache_stat(&fscache_n_cookie_special);
45514 + fscache_stat_unchecked(&fscache_n_cookie_special);
45515 break;
45516 }
45517
45518 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45519 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45520 atomic_dec(&parent->n_children);
45521 __fscache_cookie_put(cookie);
45522 - fscache_stat(&fscache_n_acquires_nobufs);
45523 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45524 _leave(" = NULL");
45525 return NULL;
45526 }
45527 }
45528
45529 - fscache_stat(&fscache_n_acquires_ok);
45530 + fscache_stat_unchecked(&fscache_n_acquires_ok);
45531 _leave(" = %p", cookie);
45532 return cookie;
45533 }
45534 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45535 cache = fscache_select_cache_for_object(cookie->parent);
45536 if (!cache) {
45537 up_read(&fscache_addremove_sem);
45538 - fscache_stat(&fscache_n_acquires_no_cache);
45539 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45540 _leave(" = -ENOMEDIUM [no cache]");
45541 return -ENOMEDIUM;
45542 }
45543 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45544 object = cache->ops->alloc_object(cache, cookie);
45545 fscache_stat_d(&fscache_n_cop_alloc_object);
45546 if (IS_ERR(object)) {
45547 - fscache_stat(&fscache_n_object_no_alloc);
45548 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
45549 ret = PTR_ERR(object);
45550 goto error;
45551 }
45552
45553 - fscache_stat(&fscache_n_object_alloc);
45554 + fscache_stat_unchecked(&fscache_n_object_alloc);
45555
45556 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45557
45558 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45559 struct fscache_object *object;
45560 struct hlist_node *_p;
45561
45562 - fscache_stat(&fscache_n_updates);
45563 + fscache_stat_unchecked(&fscache_n_updates);
45564
45565 if (!cookie) {
45566 - fscache_stat(&fscache_n_updates_null);
45567 + fscache_stat_unchecked(&fscache_n_updates_null);
45568 _leave(" [no cookie]");
45569 return;
45570 }
45571 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45572 struct fscache_object *object;
45573 unsigned long event;
45574
45575 - fscache_stat(&fscache_n_relinquishes);
45576 + fscache_stat_unchecked(&fscache_n_relinquishes);
45577 if (retire)
45578 - fscache_stat(&fscache_n_relinquishes_retire);
45579 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45580
45581 if (!cookie) {
45582 - fscache_stat(&fscache_n_relinquishes_null);
45583 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
45584 _leave(" [no cookie]");
45585 return;
45586 }
45587 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45588
45589 /* wait for the cookie to finish being instantiated (or to fail) */
45590 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45591 - fscache_stat(&fscache_n_relinquishes_waitcrt);
45592 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45593 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45594 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45595 }
45596 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45597 index f6aad48..88dcf26 100644
45598 --- a/fs/fscache/internal.h
45599 +++ b/fs/fscache/internal.h
45600 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45601 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45602 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45603
45604 -extern atomic_t fscache_n_op_pend;
45605 -extern atomic_t fscache_n_op_run;
45606 -extern atomic_t fscache_n_op_enqueue;
45607 -extern atomic_t fscache_n_op_deferred_release;
45608 -extern atomic_t fscache_n_op_release;
45609 -extern atomic_t fscache_n_op_gc;
45610 -extern atomic_t fscache_n_op_cancelled;
45611 -extern atomic_t fscache_n_op_rejected;
45612 +extern atomic_unchecked_t fscache_n_op_pend;
45613 +extern atomic_unchecked_t fscache_n_op_run;
45614 +extern atomic_unchecked_t fscache_n_op_enqueue;
45615 +extern atomic_unchecked_t fscache_n_op_deferred_release;
45616 +extern atomic_unchecked_t fscache_n_op_release;
45617 +extern atomic_unchecked_t fscache_n_op_gc;
45618 +extern atomic_unchecked_t fscache_n_op_cancelled;
45619 +extern atomic_unchecked_t fscache_n_op_rejected;
45620
45621 -extern atomic_t fscache_n_attr_changed;
45622 -extern atomic_t fscache_n_attr_changed_ok;
45623 -extern atomic_t fscache_n_attr_changed_nobufs;
45624 -extern atomic_t fscache_n_attr_changed_nomem;
45625 -extern atomic_t fscache_n_attr_changed_calls;
45626 +extern atomic_unchecked_t fscache_n_attr_changed;
45627 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
45628 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45629 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45630 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
45631
45632 -extern atomic_t fscache_n_allocs;
45633 -extern atomic_t fscache_n_allocs_ok;
45634 -extern atomic_t fscache_n_allocs_wait;
45635 -extern atomic_t fscache_n_allocs_nobufs;
45636 -extern atomic_t fscache_n_allocs_intr;
45637 -extern atomic_t fscache_n_allocs_object_dead;
45638 -extern atomic_t fscache_n_alloc_ops;
45639 -extern atomic_t fscache_n_alloc_op_waits;
45640 +extern atomic_unchecked_t fscache_n_allocs;
45641 +extern atomic_unchecked_t fscache_n_allocs_ok;
45642 +extern atomic_unchecked_t fscache_n_allocs_wait;
45643 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
45644 +extern atomic_unchecked_t fscache_n_allocs_intr;
45645 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
45646 +extern atomic_unchecked_t fscache_n_alloc_ops;
45647 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
45648
45649 -extern atomic_t fscache_n_retrievals;
45650 -extern atomic_t fscache_n_retrievals_ok;
45651 -extern atomic_t fscache_n_retrievals_wait;
45652 -extern atomic_t fscache_n_retrievals_nodata;
45653 -extern atomic_t fscache_n_retrievals_nobufs;
45654 -extern atomic_t fscache_n_retrievals_intr;
45655 -extern atomic_t fscache_n_retrievals_nomem;
45656 -extern atomic_t fscache_n_retrievals_object_dead;
45657 -extern atomic_t fscache_n_retrieval_ops;
45658 -extern atomic_t fscache_n_retrieval_op_waits;
45659 +extern atomic_unchecked_t fscache_n_retrievals;
45660 +extern atomic_unchecked_t fscache_n_retrievals_ok;
45661 +extern atomic_unchecked_t fscache_n_retrievals_wait;
45662 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
45663 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45664 +extern atomic_unchecked_t fscache_n_retrievals_intr;
45665 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
45666 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45667 +extern atomic_unchecked_t fscache_n_retrieval_ops;
45668 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45669
45670 -extern atomic_t fscache_n_stores;
45671 -extern atomic_t fscache_n_stores_ok;
45672 -extern atomic_t fscache_n_stores_again;
45673 -extern atomic_t fscache_n_stores_nobufs;
45674 -extern atomic_t fscache_n_stores_oom;
45675 -extern atomic_t fscache_n_store_ops;
45676 -extern atomic_t fscache_n_store_calls;
45677 -extern atomic_t fscache_n_store_pages;
45678 -extern atomic_t fscache_n_store_radix_deletes;
45679 -extern atomic_t fscache_n_store_pages_over_limit;
45680 +extern atomic_unchecked_t fscache_n_stores;
45681 +extern atomic_unchecked_t fscache_n_stores_ok;
45682 +extern atomic_unchecked_t fscache_n_stores_again;
45683 +extern atomic_unchecked_t fscache_n_stores_nobufs;
45684 +extern atomic_unchecked_t fscache_n_stores_oom;
45685 +extern atomic_unchecked_t fscache_n_store_ops;
45686 +extern atomic_unchecked_t fscache_n_store_calls;
45687 +extern atomic_unchecked_t fscache_n_store_pages;
45688 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
45689 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45690
45691 -extern atomic_t fscache_n_store_vmscan_not_storing;
45692 -extern atomic_t fscache_n_store_vmscan_gone;
45693 -extern atomic_t fscache_n_store_vmscan_busy;
45694 -extern atomic_t fscache_n_store_vmscan_cancelled;
45695 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45696 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45697 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45698 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45699
45700 -extern atomic_t fscache_n_marks;
45701 -extern atomic_t fscache_n_uncaches;
45702 +extern atomic_unchecked_t fscache_n_marks;
45703 +extern atomic_unchecked_t fscache_n_uncaches;
45704
45705 -extern atomic_t fscache_n_acquires;
45706 -extern atomic_t fscache_n_acquires_null;
45707 -extern atomic_t fscache_n_acquires_no_cache;
45708 -extern atomic_t fscache_n_acquires_ok;
45709 -extern atomic_t fscache_n_acquires_nobufs;
45710 -extern atomic_t fscache_n_acquires_oom;
45711 +extern atomic_unchecked_t fscache_n_acquires;
45712 +extern atomic_unchecked_t fscache_n_acquires_null;
45713 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
45714 +extern atomic_unchecked_t fscache_n_acquires_ok;
45715 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
45716 +extern atomic_unchecked_t fscache_n_acquires_oom;
45717
45718 -extern atomic_t fscache_n_updates;
45719 -extern atomic_t fscache_n_updates_null;
45720 -extern atomic_t fscache_n_updates_run;
45721 +extern atomic_unchecked_t fscache_n_updates;
45722 +extern atomic_unchecked_t fscache_n_updates_null;
45723 +extern atomic_unchecked_t fscache_n_updates_run;
45724
45725 -extern atomic_t fscache_n_relinquishes;
45726 -extern atomic_t fscache_n_relinquishes_null;
45727 -extern atomic_t fscache_n_relinquishes_waitcrt;
45728 -extern atomic_t fscache_n_relinquishes_retire;
45729 +extern atomic_unchecked_t fscache_n_relinquishes;
45730 +extern atomic_unchecked_t fscache_n_relinquishes_null;
45731 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45732 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
45733
45734 -extern atomic_t fscache_n_cookie_index;
45735 -extern atomic_t fscache_n_cookie_data;
45736 -extern atomic_t fscache_n_cookie_special;
45737 +extern atomic_unchecked_t fscache_n_cookie_index;
45738 +extern atomic_unchecked_t fscache_n_cookie_data;
45739 +extern atomic_unchecked_t fscache_n_cookie_special;
45740
45741 -extern atomic_t fscache_n_object_alloc;
45742 -extern atomic_t fscache_n_object_no_alloc;
45743 -extern atomic_t fscache_n_object_lookups;
45744 -extern atomic_t fscache_n_object_lookups_negative;
45745 -extern atomic_t fscache_n_object_lookups_positive;
45746 -extern atomic_t fscache_n_object_lookups_timed_out;
45747 -extern atomic_t fscache_n_object_created;
45748 -extern atomic_t fscache_n_object_avail;
45749 -extern atomic_t fscache_n_object_dead;
45750 +extern atomic_unchecked_t fscache_n_object_alloc;
45751 +extern atomic_unchecked_t fscache_n_object_no_alloc;
45752 +extern atomic_unchecked_t fscache_n_object_lookups;
45753 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
45754 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
45755 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45756 +extern atomic_unchecked_t fscache_n_object_created;
45757 +extern atomic_unchecked_t fscache_n_object_avail;
45758 +extern atomic_unchecked_t fscache_n_object_dead;
45759
45760 -extern atomic_t fscache_n_checkaux_none;
45761 -extern atomic_t fscache_n_checkaux_okay;
45762 -extern atomic_t fscache_n_checkaux_update;
45763 -extern atomic_t fscache_n_checkaux_obsolete;
45764 +extern atomic_unchecked_t fscache_n_checkaux_none;
45765 +extern atomic_unchecked_t fscache_n_checkaux_okay;
45766 +extern atomic_unchecked_t fscache_n_checkaux_update;
45767 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45768
45769 extern atomic_t fscache_n_cop_alloc_object;
45770 extern atomic_t fscache_n_cop_lookup_object;
45771 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45772 atomic_inc(stat);
45773 }
45774
45775 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45776 +{
45777 + atomic_inc_unchecked(stat);
45778 +}
45779 +
45780 static inline void fscache_stat_d(atomic_t *stat)
45781 {
45782 atomic_dec(stat);
45783 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45784
45785 #define __fscache_stat(stat) (NULL)
45786 #define fscache_stat(stat) do {} while (0)
45787 +#define fscache_stat_unchecked(stat) do {} while (0)
45788 #define fscache_stat_d(stat) do {} while (0)
45789 #endif
45790
45791 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45792 index b6b897c..0ffff9c 100644
45793 --- a/fs/fscache/object.c
45794 +++ b/fs/fscache/object.c
45795 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45796 /* update the object metadata on disk */
45797 case FSCACHE_OBJECT_UPDATING:
45798 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45799 - fscache_stat(&fscache_n_updates_run);
45800 + fscache_stat_unchecked(&fscache_n_updates_run);
45801 fscache_stat(&fscache_n_cop_update_object);
45802 object->cache->ops->update_object(object);
45803 fscache_stat_d(&fscache_n_cop_update_object);
45804 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45805 spin_lock(&object->lock);
45806 object->state = FSCACHE_OBJECT_DEAD;
45807 spin_unlock(&object->lock);
45808 - fscache_stat(&fscache_n_object_dead);
45809 + fscache_stat_unchecked(&fscache_n_object_dead);
45810 goto terminal_transit;
45811
45812 /* handle the parent cache of this object being withdrawn from
45813 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45814 spin_lock(&object->lock);
45815 object->state = FSCACHE_OBJECT_DEAD;
45816 spin_unlock(&object->lock);
45817 - fscache_stat(&fscache_n_object_dead);
45818 + fscache_stat_unchecked(&fscache_n_object_dead);
45819 goto terminal_transit;
45820
45821 /* complain about the object being woken up once it is
45822 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45823 parent->cookie->def->name, cookie->def->name,
45824 object->cache->tag->name);
45825
45826 - fscache_stat(&fscache_n_object_lookups);
45827 + fscache_stat_unchecked(&fscache_n_object_lookups);
45828 fscache_stat(&fscache_n_cop_lookup_object);
45829 ret = object->cache->ops->lookup_object(object);
45830 fscache_stat_d(&fscache_n_cop_lookup_object);
45831 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45832 if (ret == -ETIMEDOUT) {
45833 /* probably stuck behind another object, so move this one to
45834 * the back of the queue */
45835 - fscache_stat(&fscache_n_object_lookups_timed_out);
45836 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45837 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45838 }
45839
45840 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45841
45842 spin_lock(&object->lock);
45843 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45844 - fscache_stat(&fscache_n_object_lookups_negative);
45845 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45846
45847 /* transit here to allow write requests to begin stacking up
45848 * and read requests to begin returning ENODATA */
45849 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45850 * result, in which case there may be data available */
45851 spin_lock(&object->lock);
45852 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45853 - fscache_stat(&fscache_n_object_lookups_positive);
45854 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45855
45856 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45857
45858 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45859 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45860 } else {
45861 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45862 - fscache_stat(&fscache_n_object_created);
45863 + fscache_stat_unchecked(&fscache_n_object_created);
45864
45865 object->state = FSCACHE_OBJECT_AVAILABLE;
45866 spin_unlock(&object->lock);
45867 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45868 fscache_enqueue_dependents(object);
45869
45870 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45871 - fscache_stat(&fscache_n_object_avail);
45872 + fscache_stat_unchecked(&fscache_n_object_avail);
45873
45874 _leave("");
45875 }
45876 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45877 enum fscache_checkaux result;
45878
45879 if (!object->cookie->def->check_aux) {
45880 - fscache_stat(&fscache_n_checkaux_none);
45881 + fscache_stat_unchecked(&fscache_n_checkaux_none);
45882 return FSCACHE_CHECKAUX_OKAY;
45883 }
45884
45885 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45886 switch (result) {
45887 /* entry okay as is */
45888 case FSCACHE_CHECKAUX_OKAY:
45889 - fscache_stat(&fscache_n_checkaux_okay);
45890 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
45891 break;
45892
45893 /* entry requires update */
45894 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45895 - fscache_stat(&fscache_n_checkaux_update);
45896 + fscache_stat_unchecked(&fscache_n_checkaux_update);
45897 break;
45898
45899 /* entry requires deletion */
45900 case FSCACHE_CHECKAUX_OBSOLETE:
45901 - fscache_stat(&fscache_n_checkaux_obsolete);
45902 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45903 break;
45904
45905 default:
45906 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45907 index 30afdfa..2256596 100644
45908 --- a/fs/fscache/operation.c
45909 +++ b/fs/fscache/operation.c
45910 @@ -17,7 +17,7 @@
45911 #include <linux/slab.h>
45912 #include "internal.h"
45913
45914 -atomic_t fscache_op_debug_id;
45915 +atomic_unchecked_t fscache_op_debug_id;
45916 EXPORT_SYMBOL(fscache_op_debug_id);
45917
45918 /**
45919 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45920 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45921 ASSERTCMP(atomic_read(&op->usage), >, 0);
45922
45923 - fscache_stat(&fscache_n_op_enqueue);
45924 + fscache_stat_unchecked(&fscache_n_op_enqueue);
45925 switch (op->flags & FSCACHE_OP_TYPE) {
45926 case FSCACHE_OP_ASYNC:
45927 _debug("queue async");
45928 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45929 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45930 if (op->processor)
45931 fscache_enqueue_operation(op);
45932 - fscache_stat(&fscache_n_op_run);
45933 + fscache_stat_unchecked(&fscache_n_op_run);
45934 }
45935
45936 /*
45937 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45938 if (object->n_ops > 1) {
45939 atomic_inc(&op->usage);
45940 list_add_tail(&op->pend_link, &object->pending_ops);
45941 - fscache_stat(&fscache_n_op_pend);
45942 + fscache_stat_unchecked(&fscache_n_op_pend);
45943 } else if (!list_empty(&object->pending_ops)) {
45944 atomic_inc(&op->usage);
45945 list_add_tail(&op->pend_link, &object->pending_ops);
45946 - fscache_stat(&fscache_n_op_pend);
45947 + fscache_stat_unchecked(&fscache_n_op_pend);
45948 fscache_start_operations(object);
45949 } else {
45950 ASSERTCMP(object->n_in_progress, ==, 0);
45951 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45952 object->n_exclusive++; /* reads and writes must wait */
45953 atomic_inc(&op->usage);
45954 list_add_tail(&op->pend_link, &object->pending_ops);
45955 - fscache_stat(&fscache_n_op_pend);
45956 + fscache_stat_unchecked(&fscache_n_op_pend);
45957 ret = 0;
45958 } else {
45959 /* not allowed to submit ops in any other state */
45960 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45961 if (object->n_exclusive > 0) {
45962 atomic_inc(&op->usage);
45963 list_add_tail(&op->pend_link, &object->pending_ops);
45964 - fscache_stat(&fscache_n_op_pend);
45965 + fscache_stat_unchecked(&fscache_n_op_pend);
45966 } else if (!list_empty(&object->pending_ops)) {
45967 atomic_inc(&op->usage);
45968 list_add_tail(&op->pend_link, &object->pending_ops);
45969 - fscache_stat(&fscache_n_op_pend);
45970 + fscache_stat_unchecked(&fscache_n_op_pend);
45971 fscache_start_operations(object);
45972 } else {
45973 ASSERTCMP(object->n_exclusive, ==, 0);
45974 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45975 object->n_ops++;
45976 atomic_inc(&op->usage);
45977 list_add_tail(&op->pend_link, &object->pending_ops);
45978 - fscache_stat(&fscache_n_op_pend);
45979 + fscache_stat_unchecked(&fscache_n_op_pend);
45980 ret = 0;
45981 } else if (object->state == FSCACHE_OBJECT_DYING ||
45982 object->state == FSCACHE_OBJECT_LC_DYING ||
45983 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45984 - fscache_stat(&fscache_n_op_rejected);
45985 + fscache_stat_unchecked(&fscache_n_op_rejected);
45986 ret = -ENOBUFS;
45987 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45988 fscache_report_unexpected_submission(object, op, ostate);
45989 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45990
45991 ret = -EBUSY;
45992 if (!list_empty(&op->pend_link)) {
45993 - fscache_stat(&fscache_n_op_cancelled);
45994 + fscache_stat_unchecked(&fscache_n_op_cancelled);
45995 list_del_init(&op->pend_link);
45996 object->n_ops--;
45997 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45998 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45999 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46000 BUG();
46001
46002 - fscache_stat(&fscache_n_op_release);
46003 + fscache_stat_unchecked(&fscache_n_op_release);
46004
46005 if (op->release) {
46006 op->release(op);
46007 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46008 * lock, and defer it otherwise */
46009 if (!spin_trylock(&object->lock)) {
46010 _debug("defer put");
46011 - fscache_stat(&fscache_n_op_deferred_release);
46012 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46013
46014 cache = object->cache;
46015 spin_lock(&cache->op_gc_list_lock);
46016 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46017
46018 _debug("GC DEFERRED REL OBJ%x OP%x",
46019 object->debug_id, op->debug_id);
46020 - fscache_stat(&fscache_n_op_gc);
46021 + fscache_stat_unchecked(&fscache_n_op_gc);
46022
46023 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46024
46025 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46026 index 3f7a59b..cf196cc 100644
46027 --- a/fs/fscache/page.c
46028 +++ b/fs/fscache/page.c
46029 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46030 val = radix_tree_lookup(&cookie->stores, page->index);
46031 if (!val) {
46032 rcu_read_unlock();
46033 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46034 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46035 __fscache_uncache_page(cookie, page);
46036 return true;
46037 }
46038 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46039 spin_unlock(&cookie->stores_lock);
46040
46041 if (xpage) {
46042 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46043 - fscache_stat(&fscache_n_store_radix_deletes);
46044 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46045 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46046 ASSERTCMP(xpage, ==, page);
46047 } else {
46048 - fscache_stat(&fscache_n_store_vmscan_gone);
46049 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46050 }
46051
46052 wake_up_bit(&cookie->flags, 0);
46053 @@ -107,7 +107,7 @@ page_busy:
46054 /* we might want to wait here, but that could deadlock the allocator as
46055 * the work threads writing to the cache may all end up sleeping
46056 * on memory allocation */
46057 - fscache_stat(&fscache_n_store_vmscan_busy);
46058 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46059 return false;
46060 }
46061 EXPORT_SYMBOL(__fscache_maybe_release_page);
46062 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46063 FSCACHE_COOKIE_STORING_TAG);
46064 if (!radix_tree_tag_get(&cookie->stores, page->index,
46065 FSCACHE_COOKIE_PENDING_TAG)) {
46066 - fscache_stat(&fscache_n_store_radix_deletes);
46067 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46068 xpage = radix_tree_delete(&cookie->stores, page->index);
46069 }
46070 spin_unlock(&cookie->stores_lock);
46071 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46072
46073 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46074
46075 - fscache_stat(&fscache_n_attr_changed_calls);
46076 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46077
46078 if (fscache_object_is_active(object)) {
46079 fscache_stat(&fscache_n_cop_attr_changed);
46080 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46081
46082 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46083
46084 - fscache_stat(&fscache_n_attr_changed);
46085 + fscache_stat_unchecked(&fscache_n_attr_changed);
46086
46087 op = kzalloc(sizeof(*op), GFP_KERNEL);
46088 if (!op) {
46089 - fscache_stat(&fscache_n_attr_changed_nomem);
46090 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46091 _leave(" = -ENOMEM");
46092 return -ENOMEM;
46093 }
46094 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46095 if (fscache_submit_exclusive_op(object, op) < 0)
46096 goto nobufs;
46097 spin_unlock(&cookie->lock);
46098 - fscache_stat(&fscache_n_attr_changed_ok);
46099 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46100 fscache_put_operation(op);
46101 _leave(" = 0");
46102 return 0;
46103 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46104 nobufs:
46105 spin_unlock(&cookie->lock);
46106 kfree(op);
46107 - fscache_stat(&fscache_n_attr_changed_nobufs);
46108 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46109 _leave(" = %d", -ENOBUFS);
46110 return -ENOBUFS;
46111 }
46112 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46113 /* allocate a retrieval operation and attempt to submit it */
46114 op = kzalloc(sizeof(*op), GFP_NOIO);
46115 if (!op) {
46116 - fscache_stat(&fscache_n_retrievals_nomem);
46117 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46118 return NULL;
46119 }
46120
46121 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46122 return 0;
46123 }
46124
46125 - fscache_stat(&fscache_n_retrievals_wait);
46126 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46127
46128 jif = jiffies;
46129 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46130 fscache_wait_bit_interruptible,
46131 TASK_INTERRUPTIBLE) != 0) {
46132 - fscache_stat(&fscache_n_retrievals_intr);
46133 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46134 _leave(" = -ERESTARTSYS");
46135 return -ERESTARTSYS;
46136 }
46137 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46138 */
46139 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46140 struct fscache_retrieval *op,
46141 - atomic_t *stat_op_waits,
46142 - atomic_t *stat_object_dead)
46143 + atomic_unchecked_t *stat_op_waits,
46144 + atomic_unchecked_t *stat_object_dead)
46145 {
46146 int ret;
46147
46148 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46149 goto check_if_dead;
46150
46151 _debug(">>> WT");
46152 - fscache_stat(stat_op_waits);
46153 + fscache_stat_unchecked(stat_op_waits);
46154 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46155 fscache_wait_bit_interruptible,
46156 TASK_INTERRUPTIBLE) < 0) {
46157 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46158
46159 check_if_dead:
46160 if (unlikely(fscache_object_is_dead(object))) {
46161 - fscache_stat(stat_object_dead);
46162 + fscache_stat_unchecked(stat_object_dead);
46163 return -ENOBUFS;
46164 }
46165 return 0;
46166 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46167
46168 _enter("%p,%p,,,", cookie, page);
46169
46170 - fscache_stat(&fscache_n_retrievals);
46171 + fscache_stat_unchecked(&fscache_n_retrievals);
46172
46173 if (hlist_empty(&cookie->backing_objects))
46174 goto nobufs;
46175 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46176 goto nobufs_unlock;
46177 spin_unlock(&cookie->lock);
46178
46179 - fscache_stat(&fscache_n_retrieval_ops);
46180 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46181
46182 /* pin the netfs read context in case we need to do the actual netfs
46183 * read because we've encountered a cache read failure */
46184 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46185
46186 error:
46187 if (ret == -ENOMEM)
46188 - fscache_stat(&fscache_n_retrievals_nomem);
46189 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46190 else if (ret == -ERESTARTSYS)
46191 - fscache_stat(&fscache_n_retrievals_intr);
46192 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46193 else if (ret == -ENODATA)
46194 - fscache_stat(&fscache_n_retrievals_nodata);
46195 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46196 else if (ret < 0)
46197 - fscache_stat(&fscache_n_retrievals_nobufs);
46198 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46199 else
46200 - fscache_stat(&fscache_n_retrievals_ok);
46201 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46202
46203 fscache_put_retrieval(op);
46204 _leave(" = %d", ret);
46205 @@ -429,7 +429,7 @@ nobufs_unlock:
46206 spin_unlock(&cookie->lock);
46207 kfree(op);
46208 nobufs:
46209 - fscache_stat(&fscache_n_retrievals_nobufs);
46210 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46211 _leave(" = -ENOBUFS");
46212 return -ENOBUFS;
46213 }
46214 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46215
46216 _enter("%p,,%d,,,", cookie, *nr_pages);
46217
46218 - fscache_stat(&fscache_n_retrievals);
46219 + fscache_stat_unchecked(&fscache_n_retrievals);
46220
46221 if (hlist_empty(&cookie->backing_objects))
46222 goto nobufs;
46223 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46224 goto nobufs_unlock;
46225 spin_unlock(&cookie->lock);
46226
46227 - fscache_stat(&fscache_n_retrieval_ops);
46228 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46229
46230 /* pin the netfs read context in case we need to do the actual netfs
46231 * read because we've encountered a cache read failure */
46232 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46233
46234 error:
46235 if (ret == -ENOMEM)
46236 - fscache_stat(&fscache_n_retrievals_nomem);
46237 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46238 else if (ret == -ERESTARTSYS)
46239 - fscache_stat(&fscache_n_retrievals_intr);
46240 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46241 else if (ret == -ENODATA)
46242 - fscache_stat(&fscache_n_retrievals_nodata);
46243 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46244 else if (ret < 0)
46245 - fscache_stat(&fscache_n_retrievals_nobufs);
46246 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46247 else
46248 - fscache_stat(&fscache_n_retrievals_ok);
46249 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46250
46251 fscache_put_retrieval(op);
46252 _leave(" = %d", ret);
46253 @@ -545,7 +545,7 @@ nobufs_unlock:
46254 spin_unlock(&cookie->lock);
46255 kfree(op);
46256 nobufs:
46257 - fscache_stat(&fscache_n_retrievals_nobufs);
46258 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46259 _leave(" = -ENOBUFS");
46260 return -ENOBUFS;
46261 }
46262 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46263
46264 _enter("%p,%p,,,", cookie, page);
46265
46266 - fscache_stat(&fscache_n_allocs);
46267 + fscache_stat_unchecked(&fscache_n_allocs);
46268
46269 if (hlist_empty(&cookie->backing_objects))
46270 goto nobufs;
46271 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46272 goto nobufs_unlock;
46273 spin_unlock(&cookie->lock);
46274
46275 - fscache_stat(&fscache_n_alloc_ops);
46276 + fscache_stat_unchecked(&fscache_n_alloc_ops);
46277
46278 ret = fscache_wait_for_retrieval_activation(
46279 object, op,
46280 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46281
46282 error:
46283 if (ret == -ERESTARTSYS)
46284 - fscache_stat(&fscache_n_allocs_intr);
46285 + fscache_stat_unchecked(&fscache_n_allocs_intr);
46286 else if (ret < 0)
46287 - fscache_stat(&fscache_n_allocs_nobufs);
46288 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46289 else
46290 - fscache_stat(&fscache_n_allocs_ok);
46291 + fscache_stat_unchecked(&fscache_n_allocs_ok);
46292
46293 fscache_put_retrieval(op);
46294 _leave(" = %d", ret);
46295 @@ -625,7 +625,7 @@ nobufs_unlock:
46296 spin_unlock(&cookie->lock);
46297 kfree(op);
46298 nobufs:
46299 - fscache_stat(&fscache_n_allocs_nobufs);
46300 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46301 _leave(" = -ENOBUFS");
46302 return -ENOBUFS;
46303 }
46304 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46305
46306 spin_lock(&cookie->stores_lock);
46307
46308 - fscache_stat(&fscache_n_store_calls);
46309 + fscache_stat_unchecked(&fscache_n_store_calls);
46310
46311 /* find a page to store */
46312 page = NULL;
46313 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46314 page = results[0];
46315 _debug("gang %d [%lx]", n, page->index);
46316 if (page->index > op->store_limit) {
46317 - fscache_stat(&fscache_n_store_pages_over_limit);
46318 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46319 goto superseded;
46320 }
46321
46322 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46323 spin_unlock(&cookie->stores_lock);
46324 spin_unlock(&object->lock);
46325
46326 - fscache_stat(&fscache_n_store_pages);
46327 + fscache_stat_unchecked(&fscache_n_store_pages);
46328 fscache_stat(&fscache_n_cop_write_page);
46329 ret = object->cache->ops->write_page(op, page);
46330 fscache_stat_d(&fscache_n_cop_write_page);
46331 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46332 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46333 ASSERT(PageFsCache(page));
46334
46335 - fscache_stat(&fscache_n_stores);
46336 + fscache_stat_unchecked(&fscache_n_stores);
46337
46338 op = kzalloc(sizeof(*op), GFP_NOIO);
46339 if (!op)
46340 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46341 spin_unlock(&cookie->stores_lock);
46342 spin_unlock(&object->lock);
46343
46344 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46345 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46346 op->store_limit = object->store_limit;
46347
46348 if (fscache_submit_op(object, &op->op) < 0)
46349 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46350
46351 spin_unlock(&cookie->lock);
46352 radix_tree_preload_end();
46353 - fscache_stat(&fscache_n_store_ops);
46354 - fscache_stat(&fscache_n_stores_ok);
46355 + fscache_stat_unchecked(&fscache_n_store_ops);
46356 + fscache_stat_unchecked(&fscache_n_stores_ok);
46357
46358 /* the work queue now carries its own ref on the object */
46359 fscache_put_operation(&op->op);
46360 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46361 return 0;
46362
46363 already_queued:
46364 - fscache_stat(&fscache_n_stores_again);
46365 + fscache_stat_unchecked(&fscache_n_stores_again);
46366 already_pending:
46367 spin_unlock(&cookie->stores_lock);
46368 spin_unlock(&object->lock);
46369 spin_unlock(&cookie->lock);
46370 radix_tree_preload_end();
46371 kfree(op);
46372 - fscache_stat(&fscache_n_stores_ok);
46373 + fscache_stat_unchecked(&fscache_n_stores_ok);
46374 _leave(" = 0");
46375 return 0;
46376
46377 @@ -851,14 +851,14 @@ nobufs:
46378 spin_unlock(&cookie->lock);
46379 radix_tree_preload_end();
46380 kfree(op);
46381 - fscache_stat(&fscache_n_stores_nobufs);
46382 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46383 _leave(" = -ENOBUFS");
46384 return -ENOBUFS;
46385
46386 nomem_free:
46387 kfree(op);
46388 nomem:
46389 - fscache_stat(&fscache_n_stores_oom);
46390 + fscache_stat_unchecked(&fscache_n_stores_oom);
46391 _leave(" = -ENOMEM");
46392 return -ENOMEM;
46393 }
46394 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46395 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46396 ASSERTCMP(page, !=, NULL);
46397
46398 - fscache_stat(&fscache_n_uncaches);
46399 + fscache_stat_unchecked(&fscache_n_uncaches);
46400
46401 /* cache withdrawal may beat us to it */
46402 if (!PageFsCache(page))
46403 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46404 unsigned long loop;
46405
46406 #ifdef CONFIG_FSCACHE_STATS
46407 - atomic_add(pagevec->nr, &fscache_n_marks);
46408 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46409 #endif
46410
46411 for (loop = 0; loop < pagevec->nr; loop++) {
46412 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46413 index 4765190..2a067f2 100644
46414 --- a/fs/fscache/stats.c
46415 +++ b/fs/fscache/stats.c
46416 @@ -18,95 +18,95 @@
46417 /*
46418 * operation counters
46419 */
46420 -atomic_t fscache_n_op_pend;
46421 -atomic_t fscache_n_op_run;
46422 -atomic_t fscache_n_op_enqueue;
46423 -atomic_t fscache_n_op_requeue;
46424 -atomic_t fscache_n_op_deferred_release;
46425 -atomic_t fscache_n_op_release;
46426 -atomic_t fscache_n_op_gc;
46427 -atomic_t fscache_n_op_cancelled;
46428 -atomic_t fscache_n_op_rejected;
46429 +atomic_unchecked_t fscache_n_op_pend;
46430 +atomic_unchecked_t fscache_n_op_run;
46431 +atomic_unchecked_t fscache_n_op_enqueue;
46432 +atomic_unchecked_t fscache_n_op_requeue;
46433 +atomic_unchecked_t fscache_n_op_deferred_release;
46434 +atomic_unchecked_t fscache_n_op_release;
46435 +atomic_unchecked_t fscache_n_op_gc;
46436 +atomic_unchecked_t fscache_n_op_cancelled;
46437 +atomic_unchecked_t fscache_n_op_rejected;
46438
46439 -atomic_t fscache_n_attr_changed;
46440 -atomic_t fscache_n_attr_changed_ok;
46441 -atomic_t fscache_n_attr_changed_nobufs;
46442 -atomic_t fscache_n_attr_changed_nomem;
46443 -atomic_t fscache_n_attr_changed_calls;
46444 +atomic_unchecked_t fscache_n_attr_changed;
46445 +atomic_unchecked_t fscache_n_attr_changed_ok;
46446 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
46447 +atomic_unchecked_t fscache_n_attr_changed_nomem;
46448 +atomic_unchecked_t fscache_n_attr_changed_calls;
46449
46450 -atomic_t fscache_n_allocs;
46451 -atomic_t fscache_n_allocs_ok;
46452 -atomic_t fscache_n_allocs_wait;
46453 -atomic_t fscache_n_allocs_nobufs;
46454 -atomic_t fscache_n_allocs_intr;
46455 -atomic_t fscache_n_allocs_object_dead;
46456 -atomic_t fscache_n_alloc_ops;
46457 -atomic_t fscache_n_alloc_op_waits;
46458 +atomic_unchecked_t fscache_n_allocs;
46459 +atomic_unchecked_t fscache_n_allocs_ok;
46460 +atomic_unchecked_t fscache_n_allocs_wait;
46461 +atomic_unchecked_t fscache_n_allocs_nobufs;
46462 +atomic_unchecked_t fscache_n_allocs_intr;
46463 +atomic_unchecked_t fscache_n_allocs_object_dead;
46464 +atomic_unchecked_t fscache_n_alloc_ops;
46465 +atomic_unchecked_t fscache_n_alloc_op_waits;
46466
46467 -atomic_t fscache_n_retrievals;
46468 -atomic_t fscache_n_retrievals_ok;
46469 -atomic_t fscache_n_retrievals_wait;
46470 -atomic_t fscache_n_retrievals_nodata;
46471 -atomic_t fscache_n_retrievals_nobufs;
46472 -atomic_t fscache_n_retrievals_intr;
46473 -atomic_t fscache_n_retrievals_nomem;
46474 -atomic_t fscache_n_retrievals_object_dead;
46475 -atomic_t fscache_n_retrieval_ops;
46476 -atomic_t fscache_n_retrieval_op_waits;
46477 +atomic_unchecked_t fscache_n_retrievals;
46478 +atomic_unchecked_t fscache_n_retrievals_ok;
46479 +atomic_unchecked_t fscache_n_retrievals_wait;
46480 +atomic_unchecked_t fscache_n_retrievals_nodata;
46481 +atomic_unchecked_t fscache_n_retrievals_nobufs;
46482 +atomic_unchecked_t fscache_n_retrievals_intr;
46483 +atomic_unchecked_t fscache_n_retrievals_nomem;
46484 +atomic_unchecked_t fscache_n_retrievals_object_dead;
46485 +atomic_unchecked_t fscache_n_retrieval_ops;
46486 +atomic_unchecked_t fscache_n_retrieval_op_waits;
46487
46488 -atomic_t fscache_n_stores;
46489 -atomic_t fscache_n_stores_ok;
46490 -atomic_t fscache_n_stores_again;
46491 -atomic_t fscache_n_stores_nobufs;
46492 -atomic_t fscache_n_stores_oom;
46493 -atomic_t fscache_n_store_ops;
46494 -atomic_t fscache_n_store_calls;
46495 -atomic_t fscache_n_store_pages;
46496 -atomic_t fscache_n_store_radix_deletes;
46497 -atomic_t fscache_n_store_pages_over_limit;
46498 +atomic_unchecked_t fscache_n_stores;
46499 +atomic_unchecked_t fscache_n_stores_ok;
46500 +atomic_unchecked_t fscache_n_stores_again;
46501 +atomic_unchecked_t fscache_n_stores_nobufs;
46502 +atomic_unchecked_t fscache_n_stores_oom;
46503 +atomic_unchecked_t fscache_n_store_ops;
46504 +atomic_unchecked_t fscache_n_store_calls;
46505 +atomic_unchecked_t fscache_n_store_pages;
46506 +atomic_unchecked_t fscache_n_store_radix_deletes;
46507 +atomic_unchecked_t fscache_n_store_pages_over_limit;
46508
46509 -atomic_t fscache_n_store_vmscan_not_storing;
46510 -atomic_t fscache_n_store_vmscan_gone;
46511 -atomic_t fscache_n_store_vmscan_busy;
46512 -atomic_t fscache_n_store_vmscan_cancelled;
46513 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46514 +atomic_unchecked_t fscache_n_store_vmscan_gone;
46515 +atomic_unchecked_t fscache_n_store_vmscan_busy;
46516 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46517
46518 -atomic_t fscache_n_marks;
46519 -atomic_t fscache_n_uncaches;
46520 +atomic_unchecked_t fscache_n_marks;
46521 +atomic_unchecked_t fscache_n_uncaches;
46522
46523 -atomic_t fscache_n_acquires;
46524 -atomic_t fscache_n_acquires_null;
46525 -atomic_t fscache_n_acquires_no_cache;
46526 -atomic_t fscache_n_acquires_ok;
46527 -atomic_t fscache_n_acquires_nobufs;
46528 -atomic_t fscache_n_acquires_oom;
46529 +atomic_unchecked_t fscache_n_acquires;
46530 +atomic_unchecked_t fscache_n_acquires_null;
46531 +atomic_unchecked_t fscache_n_acquires_no_cache;
46532 +atomic_unchecked_t fscache_n_acquires_ok;
46533 +atomic_unchecked_t fscache_n_acquires_nobufs;
46534 +atomic_unchecked_t fscache_n_acquires_oom;
46535
46536 -atomic_t fscache_n_updates;
46537 -atomic_t fscache_n_updates_null;
46538 -atomic_t fscache_n_updates_run;
46539 +atomic_unchecked_t fscache_n_updates;
46540 +atomic_unchecked_t fscache_n_updates_null;
46541 +atomic_unchecked_t fscache_n_updates_run;
46542
46543 -atomic_t fscache_n_relinquishes;
46544 -atomic_t fscache_n_relinquishes_null;
46545 -atomic_t fscache_n_relinquishes_waitcrt;
46546 -atomic_t fscache_n_relinquishes_retire;
46547 +atomic_unchecked_t fscache_n_relinquishes;
46548 +atomic_unchecked_t fscache_n_relinquishes_null;
46549 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46550 +atomic_unchecked_t fscache_n_relinquishes_retire;
46551
46552 -atomic_t fscache_n_cookie_index;
46553 -atomic_t fscache_n_cookie_data;
46554 -atomic_t fscache_n_cookie_special;
46555 +atomic_unchecked_t fscache_n_cookie_index;
46556 +atomic_unchecked_t fscache_n_cookie_data;
46557 +atomic_unchecked_t fscache_n_cookie_special;
46558
46559 -atomic_t fscache_n_object_alloc;
46560 -atomic_t fscache_n_object_no_alloc;
46561 -atomic_t fscache_n_object_lookups;
46562 -atomic_t fscache_n_object_lookups_negative;
46563 -atomic_t fscache_n_object_lookups_positive;
46564 -atomic_t fscache_n_object_lookups_timed_out;
46565 -atomic_t fscache_n_object_created;
46566 -atomic_t fscache_n_object_avail;
46567 -atomic_t fscache_n_object_dead;
46568 +atomic_unchecked_t fscache_n_object_alloc;
46569 +atomic_unchecked_t fscache_n_object_no_alloc;
46570 +atomic_unchecked_t fscache_n_object_lookups;
46571 +atomic_unchecked_t fscache_n_object_lookups_negative;
46572 +atomic_unchecked_t fscache_n_object_lookups_positive;
46573 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
46574 +atomic_unchecked_t fscache_n_object_created;
46575 +atomic_unchecked_t fscache_n_object_avail;
46576 +atomic_unchecked_t fscache_n_object_dead;
46577
46578 -atomic_t fscache_n_checkaux_none;
46579 -atomic_t fscache_n_checkaux_okay;
46580 -atomic_t fscache_n_checkaux_update;
46581 -atomic_t fscache_n_checkaux_obsolete;
46582 +atomic_unchecked_t fscache_n_checkaux_none;
46583 +atomic_unchecked_t fscache_n_checkaux_okay;
46584 +atomic_unchecked_t fscache_n_checkaux_update;
46585 +atomic_unchecked_t fscache_n_checkaux_obsolete;
46586
46587 atomic_t fscache_n_cop_alloc_object;
46588 atomic_t fscache_n_cop_lookup_object;
46589 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46590 seq_puts(m, "FS-Cache statistics\n");
46591
46592 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46593 - atomic_read(&fscache_n_cookie_index),
46594 - atomic_read(&fscache_n_cookie_data),
46595 - atomic_read(&fscache_n_cookie_special));
46596 + atomic_read_unchecked(&fscache_n_cookie_index),
46597 + atomic_read_unchecked(&fscache_n_cookie_data),
46598 + atomic_read_unchecked(&fscache_n_cookie_special));
46599
46600 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46601 - atomic_read(&fscache_n_object_alloc),
46602 - atomic_read(&fscache_n_object_no_alloc),
46603 - atomic_read(&fscache_n_object_avail),
46604 - atomic_read(&fscache_n_object_dead));
46605 + atomic_read_unchecked(&fscache_n_object_alloc),
46606 + atomic_read_unchecked(&fscache_n_object_no_alloc),
46607 + atomic_read_unchecked(&fscache_n_object_avail),
46608 + atomic_read_unchecked(&fscache_n_object_dead));
46609 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46610 - atomic_read(&fscache_n_checkaux_none),
46611 - atomic_read(&fscache_n_checkaux_okay),
46612 - atomic_read(&fscache_n_checkaux_update),
46613 - atomic_read(&fscache_n_checkaux_obsolete));
46614 + atomic_read_unchecked(&fscache_n_checkaux_none),
46615 + atomic_read_unchecked(&fscache_n_checkaux_okay),
46616 + atomic_read_unchecked(&fscache_n_checkaux_update),
46617 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46618
46619 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46620 - atomic_read(&fscache_n_marks),
46621 - atomic_read(&fscache_n_uncaches));
46622 + atomic_read_unchecked(&fscache_n_marks),
46623 + atomic_read_unchecked(&fscache_n_uncaches));
46624
46625 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46626 " oom=%u\n",
46627 - atomic_read(&fscache_n_acquires),
46628 - atomic_read(&fscache_n_acquires_null),
46629 - atomic_read(&fscache_n_acquires_no_cache),
46630 - atomic_read(&fscache_n_acquires_ok),
46631 - atomic_read(&fscache_n_acquires_nobufs),
46632 - atomic_read(&fscache_n_acquires_oom));
46633 + atomic_read_unchecked(&fscache_n_acquires),
46634 + atomic_read_unchecked(&fscache_n_acquires_null),
46635 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
46636 + atomic_read_unchecked(&fscache_n_acquires_ok),
46637 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
46638 + atomic_read_unchecked(&fscache_n_acquires_oom));
46639
46640 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46641 - atomic_read(&fscache_n_object_lookups),
46642 - atomic_read(&fscache_n_object_lookups_negative),
46643 - atomic_read(&fscache_n_object_lookups_positive),
46644 - atomic_read(&fscache_n_object_created),
46645 - atomic_read(&fscache_n_object_lookups_timed_out));
46646 + atomic_read_unchecked(&fscache_n_object_lookups),
46647 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
46648 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
46649 + atomic_read_unchecked(&fscache_n_object_created),
46650 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46651
46652 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46653 - atomic_read(&fscache_n_updates),
46654 - atomic_read(&fscache_n_updates_null),
46655 - atomic_read(&fscache_n_updates_run));
46656 + atomic_read_unchecked(&fscache_n_updates),
46657 + atomic_read_unchecked(&fscache_n_updates_null),
46658 + atomic_read_unchecked(&fscache_n_updates_run));
46659
46660 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46661 - atomic_read(&fscache_n_relinquishes),
46662 - atomic_read(&fscache_n_relinquishes_null),
46663 - atomic_read(&fscache_n_relinquishes_waitcrt),
46664 - atomic_read(&fscache_n_relinquishes_retire));
46665 + atomic_read_unchecked(&fscache_n_relinquishes),
46666 + atomic_read_unchecked(&fscache_n_relinquishes_null),
46667 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46668 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
46669
46670 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46671 - atomic_read(&fscache_n_attr_changed),
46672 - atomic_read(&fscache_n_attr_changed_ok),
46673 - atomic_read(&fscache_n_attr_changed_nobufs),
46674 - atomic_read(&fscache_n_attr_changed_nomem),
46675 - atomic_read(&fscache_n_attr_changed_calls));
46676 + atomic_read_unchecked(&fscache_n_attr_changed),
46677 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
46678 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46679 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46680 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
46681
46682 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46683 - atomic_read(&fscache_n_allocs),
46684 - atomic_read(&fscache_n_allocs_ok),
46685 - atomic_read(&fscache_n_allocs_wait),
46686 - atomic_read(&fscache_n_allocs_nobufs),
46687 - atomic_read(&fscache_n_allocs_intr));
46688 + atomic_read_unchecked(&fscache_n_allocs),
46689 + atomic_read_unchecked(&fscache_n_allocs_ok),
46690 + atomic_read_unchecked(&fscache_n_allocs_wait),
46691 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
46692 + atomic_read_unchecked(&fscache_n_allocs_intr));
46693 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46694 - atomic_read(&fscache_n_alloc_ops),
46695 - atomic_read(&fscache_n_alloc_op_waits),
46696 - atomic_read(&fscache_n_allocs_object_dead));
46697 + atomic_read_unchecked(&fscache_n_alloc_ops),
46698 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
46699 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
46700
46701 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46702 " int=%u oom=%u\n",
46703 - atomic_read(&fscache_n_retrievals),
46704 - atomic_read(&fscache_n_retrievals_ok),
46705 - atomic_read(&fscache_n_retrievals_wait),
46706 - atomic_read(&fscache_n_retrievals_nodata),
46707 - atomic_read(&fscache_n_retrievals_nobufs),
46708 - atomic_read(&fscache_n_retrievals_intr),
46709 - atomic_read(&fscache_n_retrievals_nomem));
46710 + atomic_read_unchecked(&fscache_n_retrievals),
46711 + atomic_read_unchecked(&fscache_n_retrievals_ok),
46712 + atomic_read_unchecked(&fscache_n_retrievals_wait),
46713 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
46714 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46715 + atomic_read_unchecked(&fscache_n_retrievals_intr),
46716 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
46717 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46718 - atomic_read(&fscache_n_retrieval_ops),
46719 - atomic_read(&fscache_n_retrieval_op_waits),
46720 - atomic_read(&fscache_n_retrievals_object_dead));
46721 + atomic_read_unchecked(&fscache_n_retrieval_ops),
46722 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46723 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46724
46725 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46726 - atomic_read(&fscache_n_stores),
46727 - atomic_read(&fscache_n_stores_ok),
46728 - atomic_read(&fscache_n_stores_again),
46729 - atomic_read(&fscache_n_stores_nobufs),
46730 - atomic_read(&fscache_n_stores_oom));
46731 + atomic_read_unchecked(&fscache_n_stores),
46732 + atomic_read_unchecked(&fscache_n_stores_ok),
46733 + atomic_read_unchecked(&fscache_n_stores_again),
46734 + atomic_read_unchecked(&fscache_n_stores_nobufs),
46735 + atomic_read_unchecked(&fscache_n_stores_oom));
46736 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46737 - atomic_read(&fscache_n_store_ops),
46738 - atomic_read(&fscache_n_store_calls),
46739 - atomic_read(&fscache_n_store_pages),
46740 - atomic_read(&fscache_n_store_radix_deletes),
46741 - atomic_read(&fscache_n_store_pages_over_limit));
46742 + atomic_read_unchecked(&fscache_n_store_ops),
46743 + atomic_read_unchecked(&fscache_n_store_calls),
46744 + atomic_read_unchecked(&fscache_n_store_pages),
46745 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
46746 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46747
46748 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46749 - atomic_read(&fscache_n_store_vmscan_not_storing),
46750 - atomic_read(&fscache_n_store_vmscan_gone),
46751 - atomic_read(&fscache_n_store_vmscan_busy),
46752 - atomic_read(&fscache_n_store_vmscan_cancelled));
46753 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46754 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46755 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46756 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46757
46758 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46759 - atomic_read(&fscache_n_op_pend),
46760 - atomic_read(&fscache_n_op_run),
46761 - atomic_read(&fscache_n_op_enqueue),
46762 - atomic_read(&fscache_n_op_cancelled),
46763 - atomic_read(&fscache_n_op_rejected));
46764 + atomic_read_unchecked(&fscache_n_op_pend),
46765 + atomic_read_unchecked(&fscache_n_op_run),
46766 + atomic_read_unchecked(&fscache_n_op_enqueue),
46767 + atomic_read_unchecked(&fscache_n_op_cancelled),
46768 + atomic_read_unchecked(&fscache_n_op_rejected));
46769 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46770 - atomic_read(&fscache_n_op_deferred_release),
46771 - atomic_read(&fscache_n_op_release),
46772 - atomic_read(&fscache_n_op_gc));
46773 + atomic_read_unchecked(&fscache_n_op_deferred_release),
46774 + atomic_read_unchecked(&fscache_n_op_release),
46775 + atomic_read_unchecked(&fscache_n_op_gc));
46776
46777 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46778 atomic_read(&fscache_n_cop_alloc_object),
46779 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46780 index 3426521..3b75162 100644
46781 --- a/fs/fuse/cuse.c
46782 +++ b/fs/fuse/cuse.c
46783 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
46784 INIT_LIST_HEAD(&cuse_conntbl[i]);
46785
46786 /* inherit and extend fuse_dev_operations */
46787 - cuse_channel_fops = fuse_dev_operations;
46788 - cuse_channel_fops.owner = THIS_MODULE;
46789 - cuse_channel_fops.open = cuse_channel_open;
46790 - cuse_channel_fops.release = cuse_channel_release;
46791 + pax_open_kernel();
46792 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46793 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46794 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
46795 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
46796 + pax_close_kernel();
46797
46798 cuse_class = class_create(THIS_MODULE, "cuse");
46799 if (IS_ERR(cuse_class))
46800 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46801 index 7df2b5e..5804aa7 100644
46802 --- a/fs/fuse/dev.c
46803 +++ b/fs/fuse/dev.c
46804 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46805 ret = 0;
46806 pipe_lock(pipe);
46807
46808 - if (!pipe->readers) {
46809 + if (!atomic_read(&pipe->readers)) {
46810 send_sig(SIGPIPE, current, 0);
46811 if (!ret)
46812 ret = -EPIPE;
46813 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46814 index 334e0b1..fc571e8 100644
46815 --- a/fs/fuse/dir.c
46816 +++ b/fs/fuse/dir.c
46817 @@ -1189,7 +1189,7 @@ static char *read_link(struct dentry *dentry)
46818 return link;
46819 }
46820
46821 -static void free_link(char *link)
46822 +static void free_link(const char *link)
46823 {
46824 if (!IS_ERR(link))
46825 free_page((unsigned long) link);
46826 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46827 index a9ba244..d9df391 100644
46828 --- a/fs/gfs2/inode.c
46829 +++ b/fs/gfs2/inode.c
46830 @@ -1496,7 +1496,7 @@ out:
46831
46832 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46833 {
46834 - char *s = nd_get_link(nd);
46835 + const char *s = nd_get_link(nd);
46836 if (!IS_ERR(s))
46837 kfree(s);
46838 }
46839 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46840 index cc9281b..58996fb 100644
46841 --- a/fs/hugetlbfs/inode.c
46842 +++ b/fs/hugetlbfs/inode.c
46843 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46844 .kill_sb = kill_litter_super,
46845 };
46846
46847 -static struct vfsmount *hugetlbfs_vfsmount;
46848 +struct vfsmount *hugetlbfs_vfsmount;
46849
46850 static int can_do_hugetlb_shm(void)
46851 {
46852 diff --git a/fs/inode.c b/fs/inode.c
46853 index c99163b..a11ad40 100644
46854 --- a/fs/inode.c
46855 +++ b/fs/inode.c
46856 @@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
46857
46858 #ifdef CONFIG_SMP
46859 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46860 - static atomic_t shared_last_ino;
46861 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46862 + static atomic_unchecked_t shared_last_ino;
46863 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46864
46865 res = next - LAST_INO_BATCH;
46866 }
46867 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46868 index 4a6cf28..d3a29d3 100644
46869 --- a/fs/jffs2/erase.c
46870 +++ b/fs/jffs2/erase.c
46871 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46872 struct jffs2_unknown_node marker = {
46873 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46874 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46875 - .totlen = cpu_to_je32(c->cleanmarker_size)
46876 + .totlen = cpu_to_je32(c->cleanmarker_size),
46877 + .hdr_crc = cpu_to_je32(0)
46878 };
46879
46880 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46881 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46882 index 6f4529d..bf12806 100644
46883 --- a/fs/jffs2/wbuf.c
46884 +++ b/fs/jffs2/wbuf.c
46885 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46886 {
46887 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46888 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46889 - .totlen = constant_cpu_to_je32(8)
46890 + .totlen = constant_cpu_to_je32(8),
46891 + .hdr_crc = constant_cpu_to_je32(0)
46892 };
46893
46894 /*
46895 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46896 index 4a82950..bcaa0cb 100644
46897 --- a/fs/jfs/super.c
46898 +++ b/fs/jfs/super.c
46899 @@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46900
46901 jfs_inode_cachep =
46902 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46903 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46904 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46905 init_once);
46906 if (jfs_inode_cachep == NULL)
46907 return -ENOMEM;
46908 diff --git a/fs/libfs.c b/fs/libfs.c
46909 index f86ec27..4734776 100644
46910 --- a/fs/libfs.c
46911 +++ b/fs/libfs.c
46912 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46913
46914 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46915 struct dentry *next;
46916 + char d_name[sizeof(next->d_iname)];
46917 + const unsigned char *name;
46918 +
46919 next = list_entry(p, struct dentry, d_u.d_child);
46920 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46921 if (!simple_positive(next)) {
46922 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46923
46924 spin_unlock(&next->d_lock);
46925 spin_unlock(&dentry->d_lock);
46926 - if (filldir(dirent, next->d_name.name,
46927 + name = next->d_name.name;
46928 + if (name == next->d_iname) {
46929 + memcpy(d_name, name, next->d_name.len);
46930 + name = d_name;
46931 + }
46932 + if (filldir(dirent, name,
46933 next->d_name.len, filp->f_pos,
46934 next->d_inode->i_ino,
46935 dt_type(next->d_inode)) < 0)
46936 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46937 index 8392cb8..80d6193 100644
46938 --- a/fs/lockd/clntproc.c
46939 +++ b/fs/lockd/clntproc.c
46940 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46941 /*
46942 * Cookie counter for NLM requests
46943 */
46944 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46945 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46946
46947 void nlmclnt_next_cookie(struct nlm_cookie *c)
46948 {
46949 - u32 cookie = atomic_inc_return(&nlm_cookie);
46950 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46951
46952 memcpy(c->data, &cookie, 4);
46953 c->len=4;
46954 diff --git a/fs/locks.c b/fs/locks.c
46955 index 82c3533..34e929c 100644
46956 --- a/fs/locks.c
46957 +++ b/fs/locks.c
46958 @@ -2076,16 +2076,16 @@ void locks_remove_flock(struct file *filp)
46959 return;
46960
46961 if (filp->f_op && filp->f_op->flock) {
46962 - struct file_lock fl = {
46963 + struct file_lock flock = {
46964 .fl_pid = current->tgid,
46965 .fl_file = filp,
46966 .fl_flags = FL_FLOCK,
46967 .fl_type = F_UNLCK,
46968 .fl_end = OFFSET_MAX,
46969 };
46970 - filp->f_op->flock(filp, F_SETLKW, &fl);
46971 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
46972 - fl.fl_ops->fl_release_private(&fl);
46973 + filp->f_op->flock(filp, F_SETLKW, &flock);
46974 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
46975 + flock.fl_ops->fl_release_private(&flock);
46976 }
46977
46978 lock_flocks();
46979 diff --git a/fs/namei.c b/fs/namei.c
46980 index 7d69419..10c6af6 100644
46981 --- a/fs/namei.c
46982 +++ b/fs/namei.c
46983 @@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
46984 if (ret != -EACCES)
46985 return ret;
46986
46987 +#ifdef CONFIG_GRKERNSEC
46988 + /* we'll block if we have to log due to a denied capability use */
46989 + if (mask & MAY_NOT_BLOCK)
46990 + return -ECHILD;
46991 +#endif
46992 +
46993 if (S_ISDIR(inode->i_mode)) {
46994 /* DACs are overridable for directories */
46995 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
46996 - return 0;
46997 if (!(mask & MAY_WRITE))
46998 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
46999 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47000 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47001 return 0;
47002 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
47003 + return 0;
47004 return -EACCES;
47005 }
47006 /*
47007 + * Searching includes executable on directories, else just read.
47008 + */
47009 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47010 + if (mask == MAY_READ)
47011 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47012 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47013 + return 0;
47014 +
47015 + /*
47016 * Read/write DACs are always overridable.
47017 * Executable DACs are overridable when there is
47018 * at least one exec bit set.
47019 @@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47020 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47021 return 0;
47022
47023 - /*
47024 - * Searching includes executable on directories, else just read.
47025 - */
47026 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47027 - if (mask == MAY_READ)
47028 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47029 - return 0;
47030 -
47031 return -EACCES;
47032 }
47033
47034 @@ -639,11 +647,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47035 return error;
47036 }
47037
47038 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47039 + dentry->d_inode, dentry, nd->path.mnt)) {
47040 + error = -EACCES;
47041 + *p = ERR_PTR(error); /* no ->put_link(), please */
47042 + path_put(&nd->path);
47043 + return error;
47044 + }
47045 +
47046 nd->last_type = LAST_BIND;
47047 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47048 error = PTR_ERR(*p);
47049 if (!IS_ERR(*p)) {
47050 - char *s = nd_get_link(nd);
47051 + const char *s = nd_get_link(nd);
47052 error = 0;
47053 if (s)
47054 error = __vfs_follow_link(nd, s);
47055 @@ -1386,6 +1402,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47056 if (!res)
47057 res = walk_component(nd, path, &nd->last,
47058 nd->last_type, LOOKUP_FOLLOW);
47059 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47060 + res = -EACCES;
47061 put_link(nd, &link, cookie);
47062 } while (res > 0);
47063
47064 @@ -1779,6 +1797,8 @@ static int path_lookupat(int dfd, const char *name,
47065 err = follow_link(&link, nd, &cookie);
47066 if (!err)
47067 err = lookup_last(nd, &path);
47068 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
47069 + err = -EACCES;
47070 put_link(nd, &link, cookie);
47071 }
47072 }
47073 @@ -1786,6 +1806,21 @@ static int path_lookupat(int dfd, const char *name,
47074 if (!err)
47075 err = complete_walk(nd);
47076
47077 + if (!(nd->flags & LOOKUP_PARENT)) {
47078 +#ifdef CONFIG_GRKERNSEC
47079 + if (flags & LOOKUP_RCU) {
47080 + if (!err)
47081 + path_put(&nd->path);
47082 + err = -ECHILD;
47083 + } else
47084 +#endif
47085 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47086 + if (!err)
47087 + path_put(&nd->path);
47088 + err = -ENOENT;
47089 + }
47090 + }
47091 +
47092 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47093 if (!nd->inode->i_op->lookup) {
47094 path_put(&nd->path);
47095 @@ -1813,6 +1848,15 @@ static int do_path_lookup(int dfd, const char *name,
47096 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47097
47098 if (likely(!retval)) {
47099 + if (*name != '/' && nd->path.dentry && nd->inode) {
47100 +#ifdef CONFIG_GRKERNSEC
47101 + if (flags & LOOKUP_RCU)
47102 + return -ECHILD;
47103 +#endif
47104 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47105 + return -ENOENT;
47106 + }
47107 +
47108 if (unlikely(!audit_dummy_context())) {
47109 if (nd->path.dentry && nd->inode)
47110 audit_inode(name, nd->path.dentry);
47111 @@ -2155,6 +2199,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47112 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47113 return -EPERM;
47114
47115 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47116 + return -EPERM;
47117 + if (gr_handle_rawio(inode))
47118 + return -EPERM;
47119 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47120 + return -EACCES;
47121 +
47122 return 0;
47123 }
47124
47125 @@ -2190,7 +2241,7 @@ static inline int open_to_namei_flags(int flag)
47126 /*
47127 * Handle the last step of open()
47128 */
47129 -static struct file *do_last(struct nameidata *nd, struct path *path,
47130 +static struct file *do_last(struct nameidata *nd, struct path *path, struct path *link,
47131 const struct open_flags *op, const char *pathname)
47132 {
47133 struct dentry *dir = nd->path.dentry;
47134 @@ -2220,16 +2271,44 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47135 error = complete_walk(nd);
47136 if (error)
47137 return ERR_PTR(error);
47138 +#ifdef CONFIG_GRKERNSEC
47139 + if (nd->flags & LOOKUP_RCU) {
47140 + error = -ECHILD;
47141 + goto exit;
47142 + }
47143 +#endif
47144 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47145 + error = -ENOENT;
47146 + goto exit;
47147 + }
47148 audit_inode(pathname, nd->path.dentry);
47149 if (open_flag & O_CREAT) {
47150 error = -EISDIR;
47151 goto exit;
47152 }
47153 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47154 + error = -EACCES;
47155 + goto exit;
47156 + }
47157 goto ok;
47158 case LAST_BIND:
47159 error = complete_walk(nd);
47160 if (error)
47161 return ERR_PTR(error);
47162 +#ifdef CONFIG_GRKERNSEC
47163 + if (nd->flags & LOOKUP_RCU) {
47164 + error = -ECHILD;
47165 + goto exit;
47166 + }
47167 +#endif
47168 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47169 + error = -ENOENT;
47170 + goto exit;
47171 + }
47172 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47173 + error = -EACCES;
47174 + goto exit;
47175 + }
47176 audit_inode(pathname, dir);
47177 goto ok;
47178 }
47179 @@ -2285,6 +2364,12 @@ retry_lookup:
47180 /* Negative dentry, just create the file */
47181 if (!dentry->d_inode) {
47182 umode_t mode = op->mode;
47183 +
47184 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
47185 + error = -EACCES;
47186 + goto exit_mutex_unlock;
47187 + }
47188 +
47189 if (!IS_POSIXACL(dir->d_inode))
47190 mode &= ~current_umask();
47191 /*
47192 @@ -2308,6 +2393,8 @@ retry_lookup:
47193 error = vfs_create(dir->d_inode, dentry, mode, nd);
47194 if (error)
47195 goto exit_mutex_unlock;
47196 + else
47197 + gr_handle_create(path->dentry, path->mnt);
47198 mutex_unlock(&dir->d_inode->i_mutex);
47199 dput(nd->path.dentry);
47200 nd->path.dentry = dentry;
47201 @@ -2317,6 +2404,23 @@ retry_lookup:
47202 /*
47203 * It already exists.
47204 */
47205 +
47206 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
47207 + error = -ENOENT;
47208 + goto exit_mutex_unlock;
47209 + }
47210 + if (link && gr_handle_symlink_owner(link, dentry->d_inode)) {
47211 + error = -EACCES;
47212 + goto exit_mutex_unlock;
47213 + }
47214 +
47215 + /* only check if O_CREAT is specified, all other checks need to go
47216 + into may_open */
47217 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47218 + error = -EACCES;
47219 + goto exit_mutex_unlock;
47220 + }
47221 +
47222 mutex_unlock(&dir->d_inode->i_mutex);
47223 audit_inode(pathname, path->dentry);
47224
47225 @@ -2349,6 +2453,11 @@ finish_lookup:
47226 }
47227 }
47228 BUG_ON(inode != path->dentry->d_inode);
47229 + /* if we're resolving a symlink to another symlink */
47230 + if (link && gr_handle_symlink_owner(link, inode)) {
47231 + error = -EACCES;
47232 + goto exit;
47233 + }
47234 return NULL;
47235 }
47236
47237 @@ -2358,7 +2467,6 @@ finish_lookup:
47238 save_parent.dentry = nd->path.dentry;
47239 save_parent.mnt = mntget(path->mnt);
47240 nd->path.dentry = path->dentry;
47241 -
47242 }
47243 nd->inode = inode;
47244 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
47245 @@ -2367,6 +2475,21 @@ finish_lookup:
47246 path_put(&save_parent);
47247 return ERR_PTR(error);
47248 }
47249 +#ifdef CONFIG_GRKERNSEC
47250 + if (nd->flags & LOOKUP_RCU) {
47251 + error = -ECHILD;
47252 + goto exit;
47253 + }
47254 +#endif
47255 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47256 + error = -ENOENT;
47257 + goto exit;
47258 + }
47259 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47260 + error = -EACCES;
47261 + goto exit;
47262 + }
47263 +
47264 error = -EISDIR;
47265 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47266 goto exit;
47267 @@ -2461,7 +2584,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47268 if (unlikely(error))
47269 goto out_filp;
47270
47271 - filp = do_last(nd, &path, op, pathname);
47272 + filp = do_last(nd, &path, NULL, op, pathname);
47273 while (unlikely(!filp)) { /* trailing symlink */
47274 struct path link = path;
47275 void *cookie;
47276 @@ -2476,8 +2599,9 @@ static struct file *path_openat(int dfd, const char *pathname,
47277 error = follow_link(&link, nd, &cookie);
47278 if (unlikely(error))
47279 filp = ERR_PTR(error);
47280 - else
47281 - filp = do_last(nd, &path, op, pathname);
47282 + else {
47283 + filp = do_last(nd, &path, &link, op, pathname);
47284 + }
47285 put_link(nd, &link, cookie);
47286 }
47287 out:
47288 @@ -2577,6 +2701,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47289 *path = nd.path;
47290 return dentry;
47291 eexist:
47292 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47293 + dput(dentry);
47294 + dentry = ERR_PTR(-ENOENT);
47295 + goto fail;
47296 + }
47297 dput(dentry);
47298 dentry = ERR_PTR(-EEXIST);
47299 fail:
47300 @@ -2599,6 +2728,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47301 }
47302 EXPORT_SYMBOL(user_path_create);
47303
47304 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47305 +{
47306 + char *tmp = getname(pathname);
47307 + struct dentry *res;
47308 + if (IS_ERR(tmp))
47309 + return ERR_CAST(tmp);
47310 + res = kern_path_create(dfd, tmp, path, is_dir);
47311 + if (IS_ERR(res))
47312 + putname(tmp);
47313 + else
47314 + *to = tmp;
47315 + return res;
47316 +}
47317 +
47318 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47319 {
47320 int error = may_create(dir, dentry);
47321 @@ -2665,6 +2808,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47322 error = mnt_want_write(path.mnt);
47323 if (error)
47324 goto out_dput;
47325 +
47326 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47327 + error = -EPERM;
47328 + goto out_drop_write;
47329 + }
47330 +
47331 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47332 + error = -EACCES;
47333 + goto out_drop_write;
47334 + }
47335 +
47336 error = security_path_mknod(&path, dentry, mode, dev);
47337 if (error)
47338 goto out_drop_write;
47339 @@ -2682,6 +2836,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47340 }
47341 out_drop_write:
47342 mnt_drop_write(path.mnt);
47343 +
47344 + if (!error)
47345 + gr_handle_create(dentry, path.mnt);
47346 out_dput:
47347 dput(dentry);
47348 mutex_unlock(&path.dentry->d_inode->i_mutex);
47349 @@ -2735,12 +2892,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47350 error = mnt_want_write(path.mnt);
47351 if (error)
47352 goto out_dput;
47353 +
47354 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47355 + error = -EACCES;
47356 + goto out_drop_write;
47357 + }
47358 +
47359 error = security_path_mkdir(&path, dentry, mode);
47360 if (error)
47361 goto out_drop_write;
47362 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47363 out_drop_write:
47364 mnt_drop_write(path.mnt);
47365 +
47366 + if (!error)
47367 + gr_handle_create(dentry, path.mnt);
47368 out_dput:
47369 dput(dentry);
47370 mutex_unlock(&path.dentry->d_inode->i_mutex);
47371 @@ -2820,6 +2986,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47372 char * name;
47373 struct dentry *dentry;
47374 struct nameidata nd;
47375 + ino_t saved_ino = 0;
47376 + dev_t saved_dev = 0;
47377
47378 error = user_path_parent(dfd, pathname, &nd, &name);
47379 if (error)
47380 @@ -2848,6 +3016,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
47381 error = -ENOENT;
47382 goto exit3;
47383 }
47384 +
47385 + saved_ino = dentry->d_inode->i_ino;
47386 + saved_dev = gr_get_dev_from_dentry(dentry);
47387 +
47388 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47389 + error = -EACCES;
47390 + goto exit3;
47391 + }
47392 +
47393 error = mnt_want_write(nd.path.mnt);
47394 if (error)
47395 goto exit3;
47396 @@ -2855,6 +3032,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47397 if (error)
47398 goto exit4;
47399 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47400 + if (!error && (saved_dev || saved_ino))
47401 + gr_handle_delete(saved_ino, saved_dev);
47402 exit4:
47403 mnt_drop_write(nd.path.mnt);
47404 exit3:
47405 @@ -2917,6 +3096,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47406 struct dentry *dentry;
47407 struct nameidata nd;
47408 struct inode *inode = NULL;
47409 + ino_t saved_ino = 0;
47410 + dev_t saved_dev = 0;
47411
47412 error = user_path_parent(dfd, pathname, &nd, &name);
47413 if (error)
47414 @@ -2939,6 +3120,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47415 if (!inode)
47416 goto slashes;
47417 ihold(inode);
47418 +
47419 + if (inode->i_nlink <= 1) {
47420 + saved_ino = inode->i_ino;
47421 + saved_dev = gr_get_dev_from_dentry(dentry);
47422 + }
47423 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47424 + error = -EACCES;
47425 + goto exit2;
47426 + }
47427 +
47428 error = mnt_want_write(nd.path.mnt);
47429 if (error)
47430 goto exit2;
47431 @@ -2946,6 +3137,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47432 if (error)
47433 goto exit3;
47434 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
47435 + if (!error && (saved_ino || saved_dev))
47436 + gr_handle_delete(saved_ino, saved_dev);
47437 exit3:
47438 mnt_drop_write(nd.path.mnt);
47439 exit2:
47440 @@ -3021,10 +3214,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
47441 error = mnt_want_write(path.mnt);
47442 if (error)
47443 goto out_dput;
47444 +
47445 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47446 + error = -EACCES;
47447 + goto out_drop_write;
47448 + }
47449 +
47450 error = security_path_symlink(&path, dentry, from);
47451 if (error)
47452 goto out_drop_write;
47453 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47454 + if (!error)
47455 + gr_handle_create(dentry, path.mnt);
47456 out_drop_write:
47457 mnt_drop_write(path.mnt);
47458 out_dput:
47459 @@ -3099,6 +3300,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47460 {
47461 struct dentry *new_dentry;
47462 struct path old_path, new_path;
47463 + char *to = NULL;
47464 int how = 0;
47465 int error;
47466
47467 @@ -3122,7 +3324,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47468 if (error)
47469 return error;
47470
47471 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47472 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47473 error = PTR_ERR(new_dentry);
47474 if (IS_ERR(new_dentry))
47475 goto out;
47476 @@ -3133,13 +3335,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47477 error = mnt_want_write(new_path.mnt);
47478 if (error)
47479 goto out_dput;
47480 +
47481 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47482 + old_path.dentry->d_inode,
47483 + old_path.dentry->d_inode->i_mode, to)) {
47484 + error = -EACCES;
47485 + goto out_drop_write;
47486 + }
47487 +
47488 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47489 + old_path.dentry, old_path.mnt, to)) {
47490 + error = -EACCES;
47491 + goto out_drop_write;
47492 + }
47493 +
47494 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47495 if (error)
47496 goto out_drop_write;
47497 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47498 + if (!error)
47499 + gr_handle_create(new_dentry, new_path.mnt);
47500 out_drop_write:
47501 mnt_drop_write(new_path.mnt);
47502 out_dput:
47503 + putname(to);
47504 dput(new_dentry);
47505 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47506 path_put(&new_path);
47507 @@ -3373,6 +3592,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47508 if (new_dentry == trap)
47509 goto exit5;
47510
47511 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47512 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
47513 + to);
47514 + if (error)
47515 + goto exit5;
47516 +
47517 error = mnt_want_write(oldnd.path.mnt);
47518 if (error)
47519 goto exit5;
47520 @@ -3382,6 +3607,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47521 goto exit6;
47522 error = vfs_rename(old_dir->d_inode, old_dentry,
47523 new_dir->d_inode, new_dentry);
47524 + if (!error)
47525 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47526 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47527 exit6:
47528 mnt_drop_write(oldnd.path.mnt);
47529 exit5:
47530 @@ -3407,6 +3635,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47531
47532 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47533 {
47534 + char tmpbuf[64];
47535 + const char *newlink;
47536 int len;
47537
47538 len = PTR_ERR(link);
47539 @@ -3416,7 +3646,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47540 len = strlen(link);
47541 if (len > (unsigned) buflen)
47542 len = buflen;
47543 - if (copy_to_user(buffer, link, len))
47544 +
47545 + if (len < sizeof(tmpbuf)) {
47546 + memcpy(tmpbuf, link, len);
47547 + newlink = tmpbuf;
47548 + } else
47549 + newlink = link;
47550 +
47551 + if (copy_to_user(buffer, newlink, len))
47552 len = -EFAULT;
47553 out:
47554 return len;
47555 diff --git a/fs/namespace.c b/fs/namespace.c
47556 index 1e4a5fe..a5ce747 100644
47557 --- a/fs/namespace.c
47558 +++ b/fs/namespace.c
47559 @@ -1157,6 +1157,9 @@ static int do_umount(struct mount *mnt, int flags)
47560 if (!(sb->s_flags & MS_RDONLY))
47561 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47562 up_write(&sb->s_umount);
47563 +
47564 + gr_log_remount(mnt->mnt_devname, retval);
47565 +
47566 return retval;
47567 }
47568
47569 @@ -1176,6 +1179,9 @@ static int do_umount(struct mount *mnt, int flags)
47570 br_write_unlock(&vfsmount_lock);
47571 up_write(&namespace_sem);
47572 release_mounts(&umount_list);
47573 +
47574 + gr_log_unmount(mnt->mnt_devname, retval);
47575 +
47576 return retval;
47577 }
47578
47579 @@ -2177,6 +2183,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47580 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47581 MS_STRICTATIME);
47582
47583 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47584 + retval = -EPERM;
47585 + goto dput_out;
47586 + }
47587 +
47588 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47589 + retval = -EPERM;
47590 + goto dput_out;
47591 + }
47592 +
47593 if (flags & MS_REMOUNT)
47594 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47595 data_page);
47596 @@ -2191,6 +2207,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47597 dev_name, data_page);
47598 dput_out:
47599 path_put(&path);
47600 +
47601 + gr_log_mount(dev_name, dir_name, retval);
47602 +
47603 return retval;
47604 }
47605
47606 @@ -2472,6 +2491,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47607 if (error)
47608 goto out2;
47609
47610 + if (gr_handle_chroot_pivot()) {
47611 + error = -EPERM;
47612 + goto out2;
47613 + }
47614 +
47615 get_fs_root(current->fs, &root);
47616 error = lock_mount(&old);
47617 if (error)
47618 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47619 index f729698..2bac081 100644
47620 --- a/fs/nfs/inode.c
47621 +++ b/fs/nfs/inode.c
47622 @@ -152,7 +152,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47623 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47624 nfsi->attrtimeo_timestamp = jiffies;
47625
47626 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47627 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47628 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47629 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47630 else
47631 @@ -1008,16 +1008,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47632 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47633 }
47634
47635 -static atomic_long_t nfs_attr_generation_counter;
47636 +static atomic_long_unchecked_t nfs_attr_generation_counter;
47637
47638 static unsigned long nfs_read_attr_generation_counter(void)
47639 {
47640 - return atomic_long_read(&nfs_attr_generation_counter);
47641 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47642 }
47643
47644 unsigned long nfs_inc_attr_generation_counter(void)
47645 {
47646 - return atomic_long_inc_return(&nfs_attr_generation_counter);
47647 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47648 }
47649
47650 void nfs_fattr_init(struct nfs_fattr *fattr)
47651 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47652 index c8bd9c3..4f83416 100644
47653 --- a/fs/nfsd/vfs.c
47654 +++ b/fs/nfsd/vfs.c
47655 @@ -933,7 +933,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47656 } else {
47657 oldfs = get_fs();
47658 set_fs(KERNEL_DS);
47659 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47660 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47661 set_fs(oldfs);
47662 }
47663
47664 @@ -1037,7 +1037,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47665
47666 /* Write the data. */
47667 oldfs = get_fs(); set_fs(KERNEL_DS);
47668 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47669 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47670 set_fs(oldfs);
47671 if (host_err < 0)
47672 goto out_nfserr;
47673 @@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47674 */
47675
47676 oldfs = get_fs(); set_fs(KERNEL_DS);
47677 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
47678 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
47679 set_fs(oldfs);
47680
47681 if (host_err < 0)
47682 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47683 index 3568c8a..e0240d8 100644
47684 --- a/fs/notify/fanotify/fanotify_user.c
47685 +++ b/fs/notify/fanotify/fanotify_user.c
47686 @@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47687 goto out_close_fd;
47688
47689 ret = -EFAULT;
47690 - if (copy_to_user(buf, &fanotify_event_metadata,
47691 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47692 + copy_to_user(buf, &fanotify_event_metadata,
47693 fanotify_event_metadata.event_len))
47694 goto out_kill_access_response;
47695
47696 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47697 index c887b13..0fdf472 100644
47698 --- a/fs/notify/notification.c
47699 +++ b/fs/notify/notification.c
47700 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47701 * get set to 0 so it will never get 'freed'
47702 */
47703 static struct fsnotify_event *q_overflow_event;
47704 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47705 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47706
47707 /**
47708 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47709 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47710 */
47711 u32 fsnotify_get_cookie(void)
47712 {
47713 - return atomic_inc_return(&fsnotify_sync_cookie);
47714 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47715 }
47716 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47717
47718 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47719 index 99e3610..02c1068 100644
47720 --- a/fs/ntfs/dir.c
47721 +++ b/fs/ntfs/dir.c
47722 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
47723 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47724 ~(s64)(ndir->itype.index.block_size - 1)));
47725 /* Bounds checks. */
47726 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47727 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47728 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47729 "inode 0x%lx or driver bug.", vdir->i_ino);
47730 goto err_out;
47731 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47732 index 7389d2d..dfd5dbe 100644
47733 --- a/fs/ntfs/file.c
47734 +++ b/fs/ntfs/file.c
47735 @@ -2231,6 +2231,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47736 #endif /* NTFS_RW */
47737 };
47738
47739 -const struct file_operations ntfs_empty_file_ops = {};
47740 +const struct file_operations ntfs_empty_file_ops __read_only;
47741
47742 -const struct inode_operations ntfs_empty_inode_ops = {};
47743 +const struct inode_operations ntfs_empty_inode_ops __read_only;
47744 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47745 index 210c352..a174f83 100644
47746 --- a/fs/ocfs2/localalloc.c
47747 +++ b/fs/ocfs2/localalloc.c
47748 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47749 goto bail;
47750 }
47751
47752 - atomic_inc(&osb->alloc_stats.moves);
47753 + atomic_inc_unchecked(&osb->alloc_stats.moves);
47754
47755 bail:
47756 if (handle)
47757 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47758 index d355e6e..578d905 100644
47759 --- a/fs/ocfs2/ocfs2.h
47760 +++ b/fs/ocfs2/ocfs2.h
47761 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
47762
47763 struct ocfs2_alloc_stats
47764 {
47765 - atomic_t moves;
47766 - atomic_t local_data;
47767 - atomic_t bitmap_data;
47768 - atomic_t bg_allocs;
47769 - atomic_t bg_extends;
47770 + atomic_unchecked_t moves;
47771 + atomic_unchecked_t local_data;
47772 + atomic_unchecked_t bitmap_data;
47773 + atomic_unchecked_t bg_allocs;
47774 + atomic_unchecked_t bg_extends;
47775 };
47776
47777 enum ocfs2_local_alloc_state
47778 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47779 index f169da4..9112253 100644
47780 --- a/fs/ocfs2/suballoc.c
47781 +++ b/fs/ocfs2/suballoc.c
47782 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47783 mlog_errno(status);
47784 goto bail;
47785 }
47786 - atomic_inc(&osb->alloc_stats.bg_extends);
47787 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47788
47789 /* You should never ask for this much metadata */
47790 BUG_ON(bits_wanted >
47791 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47792 mlog_errno(status);
47793 goto bail;
47794 }
47795 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47796 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47797
47798 *suballoc_loc = res.sr_bg_blkno;
47799 *suballoc_bit_start = res.sr_bit_offset;
47800 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47801 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47802 res->sr_bits);
47803
47804 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47805 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47806
47807 BUG_ON(res->sr_bits != 1);
47808
47809 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47810 mlog_errno(status);
47811 goto bail;
47812 }
47813 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47814 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47815
47816 BUG_ON(res.sr_bits != 1);
47817
47818 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47819 cluster_start,
47820 num_clusters);
47821 if (!status)
47822 - atomic_inc(&osb->alloc_stats.local_data);
47823 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
47824 } else {
47825 if (min_clusters > (osb->bitmap_cpg - 1)) {
47826 /* The only paths asking for contiguousness
47827 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47828 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47829 res.sr_bg_blkno,
47830 res.sr_bit_offset);
47831 - atomic_inc(&osb->alloc_stats.bitmap_data);
47832 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47833 *num_clusters = res.sr_bits;
47834 }
47835 }
47836 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47837 index 68f4541..89cfe6a 100644
47838 --- a/fs/ocfs2/super.c
47839 +++ b/fs/ocfs2/super.c
47840 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47841 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47842 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47843 "Stats",
47844 - atomic_read(&osb->alloc_stats.bitmap_data),
47845 - atomic_read(&osb->alloc_stats.local_data),
47846 - atomic_read(&osb->alloc_stats.bg_allocs),
47847 - atomic_read(&osb->alloc_stats.moves),
47848 - atomic_read(&osb->alloc_stats.bg_extends));
47849 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47850 + atomic_read_unchecked(&osb->alloc_stats.local_data),
47851 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47852 + atomic_read_unchecked(&osb->alloc_stats.moves),
47853 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47854
47855 out += snprintf(buf + out, len - out,
47856 "%10s => State: %u Descriptor: %llu Size: %u bits "
47857 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47858 spin_lock_init(&osb->osb_xattr_lock);
47859 ocfs2_init_steal_slots(osb);
47860
47861 - atomic_set(&osb->alloc_stats.moves, 0);
47862 - atomic_set(&osb->alloc_stats.local_data, 0);
47863 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
47864 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
47865 - atomic_set(&osb->alloc_stats.bg_extends, 0);
47866 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47867 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47868 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47869 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47870 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47871
47872 /* Copy the blockcheck stats from the superblock probe */
47873 osb->osb_ecc_stats = *stats;
47874 diff --git a/fs/open.c b/fs/open.c
47875 index 1540632..79d7242 100644
47876 --- a/fs/open.c
47877 +++ b/fs/open.c
47878 @@ -31,6 +31,8 @@
47879 #include <linux/ima.h>
47880 #include <linux/dnotify.h>
47881
47882 +#define CREATE_TRACE_POINTS
47883 +#include <trace/events/fs.h>
47884 #include "internal.h"
47885
47886 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
47887 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47888 error = locks_verify_truncate(inode, NULL, length);
47889 if (!error)
47890 error = security_path_truncate(&path);
47891 +
47892 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47893 + error = -EACCES;
47894 +
47895 if (!error)
47896 error = do_truncate(path.dentry, length, 0, NULL);
47897
47898 @@ -359,6 +365,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47899 if (__mnt_is_readonly(path.mnt))
47900 res = -EROFS;
47901
47902 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47903 + res = -EACCES;
47904 +
47905 out_path_release:
47906 path_put(&path);
47907 out:
47908 @@ -385,6 +394,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47909 if (error)
47910 goto dput_and_out;
47911
47912 + gr_log_chdir(path.dentry, path.mnt);
47913 +
47914 set_fs_pwd(current->fs, &path);
47915
47916 dput_and_out:
47917 @@ -411,6 +422,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47918 goto out_putf;
47919
47920 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47921 +
47922 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47923 + error = -EPERM;
47924 +
47925 + if (!error)
47926 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47927 +
47928 if (!error)
47929 set_fs_pwd(current->fs, &file->f_path);
47930 out_putf:
47931 @@ -439,7 +457,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47932 if (error)
47933 goto dput_and_out;
47934
47935 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47936 + goto dput_and_out;
47937 +
47938 set_fs_root(current->fs, &path);
47939 +
47940 + gr_handle_chroot_chdir(&path);
47941 +
47942 error = 0;
47943 dput_and_out:
47944 path_put(&path);
47945 @@ -457,6 +481,16 @@ static int chmod_common(struct path *path, umode_t mode)
47946 if (error)
47947 return error;
47948 mutex_lock(&inode->i_mutex);
47949 +
47950 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47951 + error = -EACCES;
47952 + goto out_unlock;
47953 + }
47954 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47955 + error = -EACCES;
47956 + goto out_unlock;
47957 + }
47958 +
47959 error = security_path_chmod(path, mode);
47960 if (error)
47961 goto out_unlock;
47962 @@ -512,6 +546,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47963 uid = make_kuid(current_user_ns(), user);
47964 gid = make_kgid(current_user_ns(), group);
47965
47966 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
47967 + return -EACCES;
47968 +
47969 newattrs.ia_valid = ATTR_CTIME;
47970 if (user != (uid_t) -1) {
47971 if (!uid_valid(uid))
47972 @@ -1035,6 +1072,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
47973 } else {
47974 fsnotify_open(f);
47975 fd_install(fd, f);
47976 + trace_do_sys_open(tmp, flags, mode);
47977 }
47978 }
47979 putname(tmp);
47980 diff --git a/fs/pipe.c b/fs/pipe.c
47981 index 49c1065..13b9e12 100644
47982 --- a/fs/pipe.c
47983 +++ b/fs/pipe.c
47984 @@ -438,9 +438,9 @@ redo:
47985 }
47986 if (bufs) /* More to do? */
47987 continue;
47988 - if (!pipe->writers)
47989 + if (!atomic_read(&pipe->writers))
47990 break;
47991 - if (!pipe->waiting_writers) {
47992 + if (!atomic_read(&pipe->waiting_writers)) {
47993 /* syscall merging: Usually we must not sleep
47994 * if O_NONBLOCK is set, or if we got some data.
47995 * But if a writer sleeps in kernel space, then
47996 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47997 mutex_lock(&inode->i_mutex);
47998 pipe = inode->i_pipe;
47999
48000 - if (!pipe->readers) {
48001 + if (!atomic_read(&pipe->readers)) {
48002 send_sig(SIGPIPE, current, 0);
48003 ret = -EPIPE;
48004 goto out;
48005 @@ -553,7 +553,7 @@ redo1:
48006 for (;;) {
48007 int bufs;
48008
48009 - if (!pipe->readers) {
48010 + if (!atomic_read(&pipe->readers)) {
48011 send_sig(SIGPIPE, current, 0);
48012 if (!ret)
48013 ret = -EPIPE;
48014 @@ -644,9 +644,9 @@ redo2:
48015 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48016 do_wakeup = 0;
48017 }
48018 - pipe->waiting_writers++;
48019 + atomic_inc(&pipe->waiting_writers);
48020 pipe_wait(pipe);
48021 - pipe->waiting_writers--;
48022 + atomic_dec(&pipe->waiting_writers);
48023 }
48024 out:
48025 mutex_unlock(&inode->i_mutex);
48026 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48027 mask = 0;
48028 if (filp->f_mode & FMODE_READ) {
48029 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48030 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48031 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48032 mask |= POLLHUP;
48033 }
48034
48035 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48036 * Most Unices do not set POLLERR for FIFOs but on Linux they
48037 * behave exactly like pipes for poll().
48038 */
48039 - if (!pipe->readers)
48040 + if (!atomic_read(&pipe->readers))
48041 mask |= POLLERR;
48042 }
48043
48044 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48045
48046 mutex_lock(&inode->i_mutex);
48047 pipe = inode->i_pipe;
48048 - pipe->readers -= decr;
48049 - pipe->writers -= decw;
48050 + atomic_sub(decr, &pipe->readers);
48051 + atomic_sub(decw, &pipe->writers);
48052
48053 - if (!pipe->readers && !pipe->writers) {
48054 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48055 free_pipe_info(inode);
48056 } else {
48057 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48058 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48059
48060 if (inode->i_pipe) {
48061 ret = 0;
48062 - inode->i_pipe->readers++;
48063 + atomic_inc(&inode->i_pipe->readers);
48064 }
48065
48066 mutex_unlock(&inode->i_mutex);
48067 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48068
48069 if (inode->i_pipe) {
48070 ret = 0;
48071 - inode->i_pipe->writers++;
48072 + atomic_inc(&inode->i_pipe->writers);
48073 }
48074
48075 mutex_unlock(&inode->i_mutex);
48076 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48077 if (inode->i_pipe) {
48078 ret = 0;
48079 if (filp->f_mode & FMODE_READ)
48080 - inode->i_pipe->readers++;
48081 + atomic_inc(&inode->i_pipe->readers);
48082 if (filp->f_mode & FMODE_WRITE)
48083 - inode->i_pipe->writers++;
48084 + atomic_inc(&inode->i_pipe->writers);
48085 }
48086
48087 mutex_unlock(&inode->i_mutex);
48088 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48089 inode->i_pipe = NULL;
48090 }
48091
48092 -static struct vfsmount *pipe_mnt __read_mostly;
48093 +struct vfsmount *pipe_mnt __read_mostly;
48094
48095 /*
48096 * pipefs_dname() is called from d_path().
48097 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48098 goto fail_iput;
48099 inode->i_pipe = pipe;
48100
48101 - pipe->readers = pipe->writers = 1;
48102 + atomic_set(&pipe->readers, 1);
48103 + atomic_set(&pipe->writers, 1);
48104 inode->i_fop = &rdwr_pipefifo_fops;
48105
48106 /*
48107 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48108 index 15af622..0e9f4467 100644
48109 --- a/fs/proc/Kconfig
48110 +++ b/fs/proc/Kconfig
48111 @@ -30,12 +30,12 @@ config PROC_FS
48112
48113 config PROC_KCORE
48114 bool "/proc/kcore support" if !ARM
48115 - depends on PROC_FS && MMU
48116 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48117
48118 config PROC_VMCORE
48119 bool "/proc/vmcore support"
48120 - depends on PROC_FS && CRASH_DUMP
48121 - default y
48122 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48123 + default n
48124 help
48125 Exports the dump image of crashed kernel in ELF format.
48126
48127 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48128 limited in memory.
48129
48130 config PROC_PAGE_MONITOR
48131 - default y
48132 - depends on PROC_FS && MMU
48133 + default n
48134 + depends on PROC_FS && MMU && !GRKERNSEC
48135 bool "Enable /proc page monitoring" if EXPERT
48136 help
48137 Various /proc files exist to monitor process memory utilization:
48138 diff --git a/fs/proc/array.c b/fs/proc/array.c
48139 index c1c207c..5179411 100644
48140 --- a/fs/proc/array.c
48141 +++ b/fs/proc/array.c
48142 @@ -60,6 +60,7 @@
48143 #include <linux/tty.h>
48144 #include <linux/string.h>
48145 #include <linux/mman.h>
48146 +#include <linux/grsecurity.h>
48147 #include <linux/proc_fs.h>
48148 #include <linux/ioport.h>
48149 #include <linux/uaccess.h>
48150 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48151 seq_putc(m, '\n');
48152 }
48153
48154 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48155 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48156 +{
48157 + if (p->mm)
48158 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48159 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48160 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48161 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48162 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48163 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48164 + else
48165 + seq_printf(m, "PaX:\t-----\n");
48166 +}
48167 +#endif
48168 +
48169 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48170 struct pid *pid, struct task_struct *task)
48171 {
48172 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48173 task_cpus_allowed(m, task);
48174 cpuset_task_status_allowed(m, task);
48175 task_context_switch_counts(m, task);
48176 +
48177 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48178 + task_pax(m, task);
48179 +#endif
48180 +
48181 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48182 + task_grsec_rbac(m, task);
48183 +#endif
48184 +
48185 return 0;
48186 }
48187
48188 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48189 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48190 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48191 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48192 +#endif
48193 +
48194 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48195 struct pid *pid, struct task_struct *task, int whole)
48196 {
48197 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48198 char tcomm[sizeof(task->comm)];
48199 unsigned long flags;
48200
48201 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48202 + if (current->exec_id != m->exec_id) {
48203 + gr_log_badprocpid("stat");
48204 + return 0;
48205 + }
48206 +#endif
48207 +
48208 state = *get_task_state(task);
48209 vsize = eip = esp = 0;
48210 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48211 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48212 gtime = task->gtime;
48213 }
48214
48215 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48216 + if (PAX_RAND_FLAGS(mm)) {
48217 + eip = 0;
48218 + esp = 0;
48219 + wchan = 0;
48220 + }
48221 +#endif
48222 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48223 + wchan = 0;
48224 + eip =0;
48225 + esp =0;
48226 +#endif
48227 +
48228 /* scale priority and nice values from timeslices to -20..20 */
48229 /* to make it look like a "normal" Unix priority/nice value */
48230 priority = task_prio(task);
48231 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48232 seq_put_decimal_ull(m, ' ', vsize);
48233 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48234 seq_put_decimal_ull(m, ' ', rsslim);
48235 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48236 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48237 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48238 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48239 +#else
48240 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48241 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48242 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48243 +#endif
48244 seq_put_decimal_ull(m, ' ', esp);
48245 seq_put_decimal_ull(m, ' ', eip);
48246 /* The signal information here is obsolete.
48247 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48248 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48249 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48250
48251 - if (mm && permitted) {
48252 + if (mm && permitted
48253 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48254 + && !PAX_RAND_FLAGS(mm)
48255 +#endif
48256 + ) {
48257 seq_put_decimal_ull(m, ' ', mm->start_data);
48258 seq_put_decimal_ull(m, ' ', mm->end_data);
48259 seq_put_decimal_ull(m, ' ', mm->start_brk);
48260 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48261 struct pid *pid, struct task_struct *task)
48262 {
48263 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48264 - struct mm_struct *mm = get_task_mm(task);
48265 + struct mm_struct *mm;
48266
48267 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48268 + if (current->exec_id != m->exec_id) {
48269 + gr_log_badprocpid("statm");
48270 + return 0;
48271 + }
48272 +#endif
48273 + mm = get_task_mm(task);
48274 if (mm) {
48275 size = task_statm(mm, &shared, &text, &data, &resident);
48276 mmput(mm);
48277 @@ -580,6 +648,21 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48278 return 0;
48279 }
48280
48281 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48282 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48283 +{
48284 + u32 curr_ip = 0;
48285 + unsigned long flags;
48286 +
48287 + if (lock_task_sighand(task, &flags)) {
48288 + curr_ip = task->signal->curr_ip;
48289 + unlock_task_sighand(task, &flags);
48290 + }
48291 +
48292 + return sprintf(buffer, "%pI4\n", &curr_ip);
48293 +}
48294 +#endif
48295 +
48296 #ifdef CONFIG_CHECKPOINT_RESTORE
48297 static struct pid *
48298 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48299 diff --git a/fs/proc/base.c b/fs/proc/base.c
48300 index 437195f..cd2210d 100644
48301 --- a/fs/proc/base.c
48302 +++ b/fs/proc/base.c
48303 @@ -110,6 +110,14 @@ struct pid_entry {
48304 union proc_op op;
48305 };
48306
48307 +struct getdents_callback {
48308 + struct linux_dirent __user * current_dir;
48309 + struct linux_dirent __user * previous;
48310 + struct file * file;
48311 + int count;
48312 + int error;
48313 +};
48314 +
48315 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48316 .name = (NAME), \
48317 .len = sizeof(NAME) - 1, \
48318 @@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48319 if (!mm->arg_end)
48320 goto out_mm; /* Shh! No looking before we're done */
48321
48322 + if (gr_acl_handle_procpidmem(task))
48323 + goto out_mm;
48324 +
48325 len = mm->arg_end - mm->arg_start;
48326
48327 if (len > PAGE_SIZE)
48328 @@ -236,12 +247,28 @@ out:
48329 return res;
48330 }
48331
48332 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48333 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48334 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48335 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48336 +#endif
48337 +
48338 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48339 {
48340 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48341 int res = PTR_ERR(mm);
48342 if (mm && !IS_ERR(mm)) {
48343 unsigned int nwords = 0;
48344 +
48345 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48346 + /* allow if we're currently ptracing this task */
48347 + if (PAX_RAND_FLAGS(mm) &&
48348 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48349 + mmput(mm);
48350 + return 0;
48351 + }
48352 +#endif
48353 +
48354 do {
48355 nwords += 2;
48356 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48357 @@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48358 }
48359
48360
48361 -#ifdef CONFIG_KALLSYMS
48362 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48363 /*
48364 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48365 * Returns the resolved symbol. If that fails, simply return the address.
48366 @@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
48367 mutex_unlock(&task->signal->cred_guard_mutex);
48368 }
48369
48370 -#ifdef CONFIG_STACKTRACE
48371 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48372
48373 #define MAX_STACK_TRACE_DEPTH 64
48374
48375 @@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48376 return count;
48377 }
48378
48379 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48380 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48381 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48382 {
48383 long nr;
48384 @@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48385 /************************************************************************/
48386
48387 /* permission checks */
48388 -static int proc_fd_access_allowed(struct inode *inode)
48389 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48390 {
48391 struct task_struct *task;
48392 int allowed = 0;
48393 @@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48394 */
48395 task = get_proc_task(inode);
48396 if (task) {
48397 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48398 + if (log)
48399 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48400 + else
48401 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48402 put_task_struct(task);
48403 }
48404 return allowed;
48405 @@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48406 struct task_struct *task,
48407 int hide_pid_min)
48408 {
48409 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48410 + return false;
48411 +
48412 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48413 + rcu_read_lock();
48414 + {
48415 + const struct cred *tmpcred = current_cred();
48416 + const struct cred *cred = __task_cred(task);
48417 +
48418 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48419 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48420 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48421 +#endif
48422 + ) {
48423 + rcu_read_unlock();
48424 + return true;
48425 + }
48426 + }
48427 + rcu_read_unlock();
48428 +
48429 + if (!pid->hide_pid)
48430 + return false;
48431 +#endif
48432 +
48433 if (pid->hide_pid < hide_pid_min)
48434 return true;
48435 if (in_group_p(pid->pid_gid))
48436 return true;
48437 +
48438 return ptrace_may_access(task, PTRACE_MODE_READ);
48439 }
48440
48441 @@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
48442 put_task_struct(task);
48443
48444 if (!has_perms) {
48445 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48446 + {
48447 +#else
48448 if (pid->hide_pid == 2) {
48449 +#endif
48450 /*
48451 * Let's make getdents(), stat(), and open()
48452 * consistent with each other. If a process
48453 @@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48454 if (!task)
48455 return -ESRCH;
48456
48457 + if (gr_acl_handle_procpidmem(task)) {
48458 + put_task_struct(task);
48459 + return -EPERM;
48460 + }
48461 +
48462 mm = mm_access(task, mode);
48463 put_task_struct(task);
48464
48465 @@ -695,16 +759,24 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48466 mmput(mm);
48467 }
48468
48469 - /* OK to pass negative loff_t, we can catch out-of-range */
48470 - file->f_mode |= FMODE_UNSIGNED_OFFSET;
48471 file->private_data = mm;
48472
48473 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48474 + file->f_version = current->exec_id;
48475 +#endif
48476 +
48477 return 0;
48478 }
48479
48480 static int mem_open(struct inode *inode, struct file *file)
48481 {
48482 - return __mem_open(inode, file, PTRACE_MODE_ATTACH);
48483 + int ret;
48484 + ret = __mem_open(inode, file, PTRACE_MODE_ATTACH);
48485 +
48486 + /* OK to pass negative loff_t, we can catch out-of-range */
48487 + file->f_mode |= FMODE_UNSIGNED_OFFSET;
48488 +
48489 + return ret;
48490 }
48491
48492 static ssize_t mem_rw(struct file *file, char __user *buf,
48493 @@ -715,6 +787,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
48494 ssize_t copied;
48495 char *page;
48496
48497 +#ifdef CONFIG_GRKERNSEC
48498 + if (write)
48499 + return -EPERM;
48500 +#endif
48501 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48502 + if (file->f_version != current->exec_id) {
48503 + gr_log_badprocpid("mem");
48504 + return 0;
48505 + }
48506 +#endif
48507 +
48508 if (!mm)
48509 return 0;
48510
48511 @@ -819,6 +902,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48512 if (!mm)
48513 return 0;
48514
48515 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48516 + if (file->f_version != current->exec_id) {
48517 + gr_log_badprocpid("environ");
48518 + return 0;
48519 + }
48520 +#endif
48521 +
48522 page = (char *)__get_free_page(GFP_TEMPORARY);
48523 if (!page)
48524 return -ENOMEM;
48525 @@ -827,15 +917,17 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48526 if (!atomic_inc_not_zero(&mm->mm_users))
48527 goto free;
48528 while (count > 0) {
48529 - int this_len, retval, max_len;
48530 + size_t this_len, max_len;
48531 + int retval;
48532 +
48533 + if (src >= (mm->env_end - mm->env_start))
48534 + break;
48535
48536 this_len = mm->env_end - (mm->env_start + src);
48537
48538 - if (this_len <= 0)
48539 - break;
48540
48541 - max_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
48542 - this_len = (this_len > max_len) ? max_len : this_len;
48543 + max_len = min_t(size_t, PAGE_SIZE, count);
48544 + this_len = min(max_len, this_len);
48545
48546 retval = access_remote_vm(mm, (mm->env_start + src),
48547 page, this_len, 0);
48548 @@ -1433,7 +1525,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48549 path_put(&nd->path);
48550
48551 /* Are we allowed to snoop on the tasks file descriptors? */
48552 - if (!proc_fd_access_allowed(inode))
48553 + if (!proc_fd_access_allowed(inode, 0))
48554 goto out;
48555
48556 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
48557 @@ -1472,8 +1564,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48558 struct path path;
48559
48560 /* Are we allowed to snoop on the tasks file descriptors? */
48561 - if (!proc_fd_access_allowed(inode))
48562 - goto out;
48563 + /* logging this is needed for learning on chromium to work properly,
48564 + but we don't want to flood the logs from 'ps' which does a readlink
48565 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48566 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
48567 + */
48568 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48569 + if (!proc_fd_access_allowed(inode,0))
48570 + goto out;
48571 + } else {
48572 + if (!proc_fd_access_allowed(inode,1))
48573 + goto out;
48574 + }
48575
48576 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
48577 if (error)
48578 @@ -1538,7 +1640,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48579 rcu_read_lock();
48580 cred = __task_cred(task);
48581 inode->i_uid = cred->euid;
48582 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48583 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48584 +#else
48585 inode->i_gid = cred->egid;
48586 +#endif
48587 rcu_read_unlock();
48588 }
48589 security_task_to_inode(task, inode);
48590 @@ -1574,10 +1680,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48591 return -ENOENT;
48592 }
48593 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48594 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48595 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48596 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48597 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48598 +#endif
48599 task_dumpable(task)) {
48600 cred = __task_cred(task);
48601 stat->uid = cred->euid;
48602 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48603 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48604 +#else
48605 stat->gid = cred->egid;
48606 +#endif
48607 }
48608 }
48609 rcu_read_unlock();
48610 @@ -1615,11 +1730,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48611
48612 if (task) {
48613 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48614 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48615 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48616 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48617 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48618 +#endif
48619 task_dumpable(task)) {
48620 rcu_read_lock();
48621 cred = __task_cred(task);
48622 inode->i_uid = cred->euid;
48623 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48624 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48625 +#else
48626 inode->i_gid = cred->egid;
48627 +#endif
48628 rcu_read_unlock();
48629 } else {
48630 inode->i_uid = GLOBAL_ROOT_UID;
48631 @@ -1737,7 +1861,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48632 int fd = proc_fd(inode);
48633
48634 if (task) {
48635 - files = get_files_struct(task);
48636 + if (!gr_acl_handle_procpidmem(task))
48637 + files = get_files_struct(task);
48638 put_task_struct(task);
48639 }
48640 if (files) {
48641 @@ -2336,11 +2461,21 @@ static const struct file_operations proc_map_files_operations = {
48642 */
48643 static int proc_fd_permission(struct inode *inode, int mask)
48644 {
48645 + struct task_struct *task;
48646 int rv = generic_permission(inode, mask);
48647 - if (rv == 0)
48648 - return 0;
48649 +
48650 if (task_pid(current) == proc_pid(inode))
48651 rv = 0;
48652 +
48653 + task = get_proc_task(inode);
48654 + if (task == NULL)
48655 + return rv;
48656 +
48657 + if (gr_acl_handle_procpidmem(task))
48658 + rv = -EACCES;
48659 +
48660 + put_task_struct(task);
48661 +
48662 return rv;
48663 }
48664
48665 @@ -2450,6 +2585,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48666 if (!task)
48667 goto out_no_task;
48668
48669 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48670 + goto out;
48671 +
48672 /*
48673 * Yes, it does not scale. And it should not. Don't add
48674 * new entries into /proc/<tgid>/ without very good reasons.
48675 @@ -2494,6 +2632,9 @@ static int proc_pident_readdir(struct file *filp,
48676 if (!task)
48677 goto out_no_task;
48678
48679 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48680 + goto out;
48681 +
48682 ret = 0;
48683 i = filp->f_pos;
48684 switch (i) {
48685 @@ -2764,7 +2905,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48686 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48687 void *cookie)
48688 {
48689 - char *s = nd_get_link(nd);
48690 + const char *s = nd_get_link(nd);
48691 if (!IS_ERR(s))
48692 __putname(s);
48693 }
48694 @@ -3033,7 +3174,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48695 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48696 #endif
48697 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48698 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48699 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48700 INF("syscall", S_IRUGO, proc_pid_syscall),
48701 #endif
48702 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48703 @@ -3058,10 +3199,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48704 #ifdef CONFIG_SECURITY
48705 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48706 #endif
48707 -#ifdef CONFIG_KALLSYMS
48708 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48709 INF("wchan", S_IRUGO, proc_pid_wchan),
48710 #endif
48711 -#ifdef CONFIG_STACKTRACE
48712 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48713 ONE("stack", S_IRUGO, proc_pid_stack),
48714 #endif
48715 #ifdef CONFIG_SCHEDSTATS
48716 @@ -3095,6 +3236,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48717 #ifdef CONFIG_HARDWALL
48718 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48719 #endif
48720 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48721 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48722 +#endif
48723 #ifdef CONFIG_USER_NS
48724 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
48725 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
48726 @@ -3225,7 +3369,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48727 if (!inode)
48728 goto out;
48729
48730 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48731 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48732 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48733 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48734 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48735 +#else
48736 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48737 +#endif
48738 inode->i_op = &proc_tgid_base_inode_operations;
48739 inode->i_fop = &proc_tgid_base_operations;
48740 inode->i_flags|=S_IMMUTABLE;
48741 @@ -3267,7 +3418,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48742 if (!task)
48743 goto out;
48744
48745 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48746 + goto out_put_task;
48747 +
48748 result = proc_pid_instantiate(dir, dentry, task, NULL);
48749 +out_put_task:
48750 put_task_struct(task);
48751 out:
48752 return result;
48753 @@ -3330,6 +3485,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48754 static int fake_filldir(void *buf, const char *name, int namelen,
48755 loff_t offset, u64 ino, unsigned d_type)
48756 {
48757 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
48758 + __buf->error = -EINVAL;
48759 return 0;
48760 }
48761
48762 @@ -3396,7 +3553,7 @@ static const struct pid_entry tid_base_stuff[] = {
48763 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48764 #endif
48765 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48766 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48767 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48768 INF("syscall", S_IRUGO, proc_pid_syscall),
48769 #endif
48770 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48771 @@ -3423,10 +3580,10 @@ static const struct pid_entry tid_base_stuff[] = {
48772 #ifdef CONFIG_SECURITY
48773 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48774 #endif
48775 -#ifdef CONFIG_KALLSYMS
48776 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48777 INF("wchan", S_IRUGO, proc_pid_wchan),
48778 #endif
48779 -#ifdef CONFIG_STACKTRACE
48780 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48781 ONE("stack", S_IRUGO, proc_pid_stack),
48782 #endif
48783 #ifdef CONFIG_SCHEDSTATS
48784 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48785 index 82676e3..5f8518a 100644
48786 --- a/fs/proc/cmdline.c
48787 +++ b/fs/proc/cmdline.c
48788 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48789
48790 static int __init proc_cmdline_init(void)
48791 {
48792 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48793 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48794 +#else
48795 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48796 +#endif
48797 return 0;
48798 }
48799 module_init(proc_cmdline_init);
48800 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48801 index b143471..bb105e5 100644
48802 --- a/fs/proc/devices.c
48803 +++ b/fs/proc/devices.c
48804 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48805
48806 static int __init proc_devices_init(void)
48807 {
48808 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48809 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48810 +#else
48811 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48812 +#endif
48813 return 0;
48814 }
48815 module_init(proc_devices_init);
48816 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48817 index 7ac817b..abab1a5 100644
48818 --- a/fs/proc/inode.c
48819 +++ b/fs/proc/inode.c
48820 @@ -21,11 +21,17 @@
48821 #include <linux/seq_file.h>
48822 #include <linux/slab.h>
48823 #include <linux/mount.h>
48824 +#include <linux/grsecurity.h>
48825
48826 #include <asm/uaccess.h>
48827
48828 #include "internal.h"
48829
48830 +#ifdef CONFIG_PROC_SYSCTL
48831 +extern const struct inode_operations proc_sys_inode_operations;
48832 +extern const struct inode_operations proc_sys_dir_operations;
48833 +#endif
48834 +
48835 static void proc_evict_inode(struct inode *inode)
48836 {
48837 struct proc_dir_entry *de;
48838 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
48839 ns_ops = PROC_I(inode)->ns_ops;
48840 if (ns_ops && ns_ops->put)
48841 ns_ops->put(PROC_I(inode)->ns);
48842 +
48843 +#ifdef CONFIG_PROC_SYSCTL
48844 + if (inode->i_op == &proc_sys_inode_operations ||
48845 + inode->i_op == &proc_sys_dir_operations)
48846 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48847 +#endif
48848 +
48849 }
48850
48851 static struct kmem_cache * proc_inode_cachep;
48852 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48853 if (de->mode) {
48854 inode->i_mode = de->mode;
48855 inode->i_uid = de->uid;
48856 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48857 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48858 +#else
48859 inode->i_gid = de->gid;
48860 +#endif
48861 }
48862 if (de->size)
48863 inode->i_size = de->size;
48864 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48865 index eca4aca..19166b2 100644
48866 --- a/fs/proc/internal.h
48867 +++ b/fs/proc/internal.h
48868 @@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48869 struct pid *pid, struct task_struct *task);
48870 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48871 struct pid *pid, struct task_struct *task);
48872 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48873 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48874 +#endif
48875 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48876
48877 extern const struct file_operations proc_tid_children_operations;
48878 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48879 index 86c67ee..cdca321 100644
48880 --- a/fs/proc/kcore.c
48881 +++ b/fs/proc/kcore.c
48882 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48883 * the addresses in the elf_phdr on our list.
48884 */
48885 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48886 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48887 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48888 + if (tsz > buflen)
48889 tsz = buflen;
48890 -
48891 +
48892 while (buflen) {
48893 struct kcore_list *m;
48894
48895 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48896 kfree(elf_buf);
48897 } else {
48898 if (kern_addr_valid(start)) {
48899 - unsigned long n;
48900 + char *elf_buf;
48901 + mm_segment_t oldfs;
48902
48903 - n = copy_to_user(buffer, (char *)start, tsz);
48904 - /*
48905 - * We cannot distinguish between fault on source
48906 - * and fault on destination. When this happens
48907 - * we clear too and hope it will trigger the
48908 - * EFAULT again.
48909 - */
48910 - if (n) {
48911 - if (clear_user(buffer + tsz - n,
48912 - n))
48913 + elf_buf = kmalloc(tsz, GFP_KERNEL);
48914 + if (!elf_buf)
48915 + return -ENOMEM;
48916 + oldfs = get_fs();
48917 + set_fs(KERNEL_DS);
48918 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48919 + set_fs(oldfs);
48920 + if (copy_to_user(buffer, elf_buf, tsz)) {
48921 + kfree(elf_buf);
48922 return -EFAULT;
48923 + }
48924 }
48925 + set_fs(oldfs);
48926 + kfree(elf_buf);
48927 } else {
48928 if (clear_user(buffer, tsz))
48929 return -EFAULT;
48930 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48931
48932 static int open_kcore(struct inode *inode, struct file *filp)
48933 {
48934 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48935 + return -EPERM;
48936 +#endif
48937 if (!capable(CAP_SYS_RAWIO))
48938 return -EPERM;
48939 if (kcore_need_update)
48940 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48941 index 80e4645..53e5fcf 100644
48942 --- a/fs/proc/meminfo.c
48943 +++ b/fs/proc/meminfo.c
48944 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48945 vmi.used >> 10,
48946 vmi.largest_chunk >> 10
48947 #ifdef CONFIG_MEMORY_FAILURE
48948 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48949 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48950 #endif
48951 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48952 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48953 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48954 index b1822dd..df622cb 100644
48955 --- a/fs/proc/nommu.c
48956 +++ b/fs/proc/nommu.c
48957 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48958 if (len < 1)
48959 len = 1;
48960 seq_printf(m, "%*c", len, ' ');
48961 - seq_path(m, &file->f_path, "");
48962 + seq_path(m, &file->f_path, "\n\\");
48963 }
48964
48965 seq_putc(m, '\n');
48966 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48967 index 06e1cc1..177cd98 100644
48968 --- a/fs/proc/proc_net.c
48969 +++ b/fs/proc/proc_net.c
48970 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48971 struct task_struct *task;
48972 struct nsproxy *ns;
48973 struct net *net = NULL;
48974 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48975 + const struct cred *cred = current_cred();
48976 +#endif
48977 +
48978 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48979 + if (cred->fsuid)
48980 + return net;
48981 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48982 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48983 + return net;
48984 +#endif
48985
48986 rcu_read_lock();
48987 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48988 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48989 index 3476bca..cb6d86a 100644
48990 --- a/fs/proc/proc_sysctl.c
48991 +++ b/fs/proc/proc_sysctl.c
48992 @@ -12,11 +12,15 @@
48993 #include <linux/module.h>
48994 #include "internal.h"
48995
48996 +extern int gr_handle_chroot_sysctl(const int op);
48997 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
48998 + const int op);
48999 +
49000 static const struct dentry_operations proc_sys_dentry_operations;
49001 static const struct file_operations proc_sys_file_operations;
49002 -static const struct inode_operations proc_sys_inode_operations;
49003 +const struct inode_operations proc_sys_inode_operations;
49004 static const struct file_operations proc_sys_dir_file_operations;
49005 -static const struct inode_operations proc_sys_dir_operations;
49006 +const struct inode_operations proc_sys_dir_operations;
49007
49008 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49009 {
49010 @@ -470,8 +474,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49011
49012 err = NULL;
49013 d_set_d_op(dentry, &proc_sys_dentry_operations);
49014 +
49015 + gr_handle_proc_create(dentry, inode);
49016 +
49017 d_add(dentry, inode);
49018
49019 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt))
49020 + err = ERR_PTR(-ENOENT);
49021 +
49022 out:
49023 sysctl_head_finish(head);
49024 return err;
49025 @@ -483,18 +493,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49026 struct inode *inode = filp->f_path.dentry->d_inode;
49027 struct ctl_table_header *head = grab_header(inode);
49028 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49029 + int op = write ? MAY_WRITE : MAY_READ;
49030 ssize_t error;
49031 size_t res;
49032
49033 if (IS_ERR(head))
49034 return PTR_ERR(head);
49035
49036 +
49037 /*
49038 * At this point we know that the sysctl was not unregistered
49039 * and won't be until we finish.
49040 */
49041 error = -EPERM;
49042 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49043 + if (sysctl_perm(head->root, table, op))
49044 goto out;
49045
49046 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49047 @@ -502,6 +514,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49048 if (!table->proc_handler)
49049 goto out;
49050
49051 +#ifdef CONFIG_GRKERNSEC
49052 + error = -EPERM;
49053 + if (gr_handle_chroot_sysctl(op))
49054 + goto out;
49055 + dget(filp->f_path.dentry);
49056 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49057 + dput(filp->f_path.dentry);
49058 + goto out;
49059 + }
49060 + dput(filp->f_path.dentry);
49061 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49062 + goto out;
49063 + if (write && !capable(CAP_SYS_ADMIN))
49064 + goto out;
49065 +#endif
49066 +
49067 /* careful: calling conventions are nasty here */
49068 res = count;
49069 error = table->proc_handler(table, write, buf, &res, ppos);
49070 @@ -599,6 +627,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49071 return -ENOMEM;
49072 } else {
49073 d_set_d_op(child, &proc_sys_dentry_operations);
49074 +
49075 + gr_handle_proc_create(child, inode);
49076 +
49077 d_add(child, inode);
49078 }
49079 } else {
49080 @@ -642,6 +673,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49081 if ((*pos)++ < file->f_pos)
49082 return 0;
49083
49084 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49085 + return 0;
49086 +
49087 if (unlikely(S_ISLNK(table->mode)))
49088 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49089 else
49090 @@ -759,6 +793,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49091 if (IS_ERR(head))
49092 return PTR_ERR(head);
49093
49094 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49095 + return -ENOENT;
49096 +
49097 generic_fillattr(inode, stat);
49098 if (table)
49099 stat->mode = (stat->mode & S_IFMT) | table->mode;
49100 @@ -781,13 +818,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49101 .llseek = generic_file_llseek,
49102 };
49103
49104 -static const struct inode_operations proc_sys_inode_operations = {
49105 +const struct inode_operations proc_sys_inode_operations = {
49106 .permission = proc_sys_permission,
49107 .setattr = proc_sys_setattr,
49108 .getattr = proc_sys_getattr,
49109 };
49110
49111 -static const struct inode_operations proc_sys_dir_operations = {
49112 +const struct inode_operations proc_sys_dir_operations = {
49113 .lookup = proc_sys_lookup,
49114 .permission = proc_sys_permission,
49115 .setattr = proc_sys_setattr,
49116 diff --git a/fs/proc/root.c b/fs/proc/root.c
49117 index 7c30fce..b3d3aa2 100644
49118 --- a/fs/proc/root.c
49119 +++ b/fs/proc/root.c
49120 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
49121 #ifdef CONFIG_PROC_DEVICETREE
49122 proc_device_tree_init();
49123 #endif
49124 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49125 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49126 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49127 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49128 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49129 +#endif
49130 +#else
49131 proc_mkdir("bus", NULL);
49132 +#endif
49133 proc_sys_init();
49134 }
49135
49136 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49137 index 4540b8f..1b9772f 100644
49138 --- a/fs/proc/task_mmu.c
49139 +++ b/fs/proc/task_mmu.c
49140 @@ -11,12 +11,19 @@
49141 #include <linux/rmap.h>
49142 #include <linux/swap.h>
49143 #include <linux/swapops.h>
49144 +#include <linux/grsecurity.h>
49145
49146 #include <asm/elf.h>
49147 #include <asm/uaccess.h>
49148 #include <asm/tlbflush.h>
49149 #include "internal.h"
49150
49151 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49152 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49153 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49154 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49155 +#endif
49156 +
49157 void task_mem(struct seq_file *m, struct mm_struct *mm)
49158 {
49159 unsigned long data, text, lib, swap;
49160 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49161 "VmExe:\t%8lu kB\n"
49162 "VmLib:\t%8lu kB\n"
49163 "VmPTE:\t%8lu kB\n"
49164 - "VmSwap:\t%8lu kB\n",
49165 - hiwater_vm << (PAGE_SHIFT-10),
49166 + "VmSwap:\t%8lu kB\n"
49167 +
49168 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49169 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49170 +#endif
49171 +
49172 + ,hiwater_vm << (PAGE_SHIFT-10),
49173 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49174 mm->locked_vm << (PAGE_SHIFT-10),
49175 mm->pinned_vm << (PAGE_SHIFT-10),
49176 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49177 data << (PAGE_SHIFT-10),
49178 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49179 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49180 - swap << (PAGE_SHIFT-10));
49181 + swap << (PAGE_SHIFT-10)
49182 +
49183 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49184 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49185 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49186 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49187 +#else
49188 + , mm->context.user_cs_base
49189 + , mm->context.user_cs_limit
49190 +#endif
49191 +#endif
49192 +
49193 + );
49194 }
49195
49196 unsigned long task_vsize(struct mm_struct *mm)
49197 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49198 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49199 }
49200
49201 - /* We don't show the stack guard page in /proc/maps */
49202 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49203 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49204 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49205 +#else
49206 start = vma->vm_start;
49207 - if (stack_guard_page_start(vma, start))
49208 - start += PAGE_SIZE;
49209 end = vma->vm_end;
49210 - if (stack_guard_page_end(vma, end))
49211 - end -= PAGE_SIZE;
49212 +#endif
49213
49214 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49215 start,
49216 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49217 flags & VM_WRITE ? 'w' : '-',
49218 flags & VM_EXEC ? 'x' : '-',
49219 flags & VM_MAYSHARE ? 's' : 'p',
49220 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49221 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49222 +#else
49223 pgoff,
49224 +#endif
49225 MAJOR(dev), MINOR(dev), ino, &len);
49226
49227 /*
49228 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49229 */
49230 if (file) {
49231 pad_len_spaces(m, len);
49232 - seq_path(m, &file->f_path, "\n");
49233 + seq_path(m, &file->f_path, "\n\\");
49234 goto done;
49235 }
49236
49237 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49238 * Thread stack in /proc/PID/task/TID/maps or
49239 * the main process stack.
49240 */
49241 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
49242 - vma->vm_end >= mm->start_stack)) {
49243 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49244 + (vma->vm_start <= mm->start_stack &&
49245 + vma->vm_end >= mm->start_stack)) {
49246 name = "[stack]";
49247 } else {
49248 /* Thread stack in /proc/PID/maps */
49249 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49250 struct proc_maps_private *priv = m->private;
49251 struct task_struct *task = priv->task;
49252
49253 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49254 + if (current->exec_id != m->exec_id) {
49255 + gr_log_badprocpid("maps");
49256 + return 0;
49257 + }
49258 +#endif
49259 +
49260 show_map_vma(m, vma, is_pid);
49261
49262 if (m->count < m->size) /* vma is copied successfully */
49263 @@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49264 .private = &mss,
49265 };
49266
49267 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49268 + if (current->exec_id != m->exec_id) {
49269 + gr_log_badprocpid("smaps");
49270 + return 0;
49271 + }
49272 +#endif
49273 memset(&mss, 0, sizeof mss);
49274 - mss.vma = vma;
49275 - /* mmap_sem is held in m_start */
49276 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49277 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49278 -
49279 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49280 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49281 +#endif
49282 + mss.vma = vma;
49283 + /* mmap_sem is held in m_start */
49284 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49285 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49286 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49287 + }
49288 +#endif
49289 show_map_vma(m, vma, is_pid);
49290
49291 seq_printf(m,
49292 @@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49293 "KernelPageSize: %8lu kB\n"
49294 "MMUPageSize: %8lu kB\n"
49295 "Locked: %8lu kB\n",
49296 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49297 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49298 +#else
49299 (vma->vm_end - vma->vm_start) >> 10,
49300 +#endif
49301 mss.resident >> 10,
49302 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49303 mss.shared_clean >> 10,
49304 @@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49305 int n;
49306 char buffer[50];
49307
49308 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49309 + if (current->exec_id != m->exec_id) {
49310 + gr_log_badprocpid("numa_maps");
49311 + return 0;
49312 + }
49313 +#endif
49314 +
49315 if (!mm)
49316 return 0;
49317
49318 @@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49319 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49320 mpol_cond_put(pol);
49321
49322 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49323 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49324 +#else
49325 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49326 +#endif
49327
49328 if (file) {
49329 seq_printf(m, " file=");
49330 - seq_path(m, &file->f_path, "\n\t= ");
49331 + seq_path(m, &file->f_path, "\n\t\\= ");
49332 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49333 seq_printf(m, " heap");
49334 } else {
49335 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49336 index 1ccfa53..0848f95 100644
49337 --- a/fs/proc/task_nommu.c
49338 +++ b/fs/proc/task_nommu.c
49339 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49340 else
49341 bytes += kobjsize(mm);
49342
49343 - if (current->fs && current->fs->users > 1)
49344 + if (current->fs && atomic_read(&current->fs->users) > 1)
49345 sbytes += kobjsize(current->fs);
49346 else
49347 bytes += kobjsize(current->fs);
49348 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49349
49350 if (file) {
49351 pad_len_spaces(m, len);
49352 - seq_path(m, &file->f_path, "");
49353 + seq_path(m, &file->f_path, "\n\\");
49354 } else if (mm) {
49355 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49356
49357 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49358 index d67908b..d13f6a6 100644
49359 --- a/fs/quota/netlink.c
49360 +++ b/fs/quota/netlink.c
49361 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49362 void quota_send_warning(short type, unsigned int id, dev_t dev,
49363 const char warntype)
49364 {
49365 - static atomic_t seq;
49366 + static atomic_unchecked_t seq;
49367 struct sk_buff *skb;
49368 void *msg_head;
49369 int ret;
49370 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49371 "VFS: Not enough memory to send quota warning.\n");
49372 return;
49373 }
49374 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49375 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49376 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49377 if (!msg_head) {
49378 printk(KERN_ERR
49379 diff --git a/fs/readdir.c b/fs/readdir.c
49380 index 39e3370..20d446d 100644
49381 --- a/fs/readdir.c
49382 +++ b/fs/readdir.c
49383 @@ -17,6 +17,7 @@
49384 #include <linux/security.h>
49385 #include <linux/syscalls.h>
49386 #include <linux/unistd.h>
49387 +#include <linux/namei.h>
49388
49389 #include <asm/uaccess.h>
49390
49391 @@ -67,6 +68,7 @@ struct old_linux_dirent {
49392
49393 struct readdir_callback {
49394 struct old_linux_dirent __user * dirent;
49395 + struct file * file;
49396 int result;
49397 };
49398
49399 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49400 buf->result = -EOVERFLOW;
49401 return -EOVERFLOW;
49402 }
49403 +
49404 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49405 + return 0;
49406 +
49407 buf->result++;
49408 dirent = buf->dirent;
49409 if (!access_ok(VERIFY_WRITE, dirent,
49410 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49411
49412 buf.result = 0;
49413 buf.dirent = dirent;
49414 + buf.file = file;
49415
49416 error = vfs_readdir(file, fillonedir, &buf);
49417 if (buf.result)
49418 @@ -141,6 +148,7 @@ struct linux_dirent {
49419 struct getdents_callback {
49420 struct linux_dirent __user * current_dir;
49421 struct linux_dirent __user * previous;
49422 + struct file * file;
49423 int count;
49424 int error;
49425 };
49426 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49427 buf->error = -EOVERFLOW;
49428 return -EOVERFLOW;
49429 }
49430 +
49431 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49432 + return 0;
49433 +
49434 dirent = buf->previous;
49435 if (dirent) {
49436 if (__put_user(offset, &dirent->d_off))
49437 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49438 buf.previous = NULL;
49439 buf.count = count;
49440 buf.error = 0;
49441 + buf.file = file;
49442
49443 error = vfs_readdir(file, filldir, &buf);
49444 if (error >= 0)
49445 @@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49446 struct getdents_callback64 {
49447 struct linux_dirent64 __user * current_dir;
49448 struct linux_dirent64 __user * previous;
49449 + struct file *file;
49450 int count;
49451 int error;
49452 };
49453 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49454 buf->error = -EINVAL; /* only used if we fail.. */
49455 if (reclen > buf->count)
49456 return -EINVAL;
49457 +
49458 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49459 + return 0;
49460 +
49461 dirent = buf->previous;
49462 if (dirent) {
49463 if (__put_user(offset, &dirent->d_off))
49464 @@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49465
49466 buf.current_dir = dirent;
49467 buf.previous = NULL;
49468 + buf.file = file;
49469 buf.count = count;
49470 buf.error = 0;
49471
49472 @@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49473 error = buf.error;
49474 lastdirent = buf.previous;
49475 if (lastdirent) {
49476 - typeof(lastdirent->d_off) d_off = file->f_pos;
49477 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49478 if (__put_user(d_off, &lastdirent->d_off))
49479 error = -EFAULT;
49480 else
49481 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
49482 index 2b7882b..1c5ef48 100644
49483 --- a/fs/reiserfs/do_balan.c
49484 +++ b/fs/reiserfs/do_balan.c
49485 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
49486 return;
49487 }
49488
49489 - atomic_inc(&(fs_generation(tb->tb_sb)));
49490 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
49491 do_balance_starts(tb);
49492
49493 /* balance leaf returns 0 except if combining L R and S into
49494 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
49495 index 2c1ade6..8c59d8d 100644
49496 --- a/fs/reiserfs/procfs.c
49497 +++ b/fs/reiserfs/procfs.c
49498 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
49499 "SMALL_TAILS " : "NO_TAILS ",
49500 replay_only(sb) ? "REPLAY_ONLY " : "",
49501 convert_reiserfs(sb) ? "CONV " : "",
49502 - atomic_read(&r->s_generation_counter),
49503 + atomic_read_unchecked(&r->s_generation_counter),
49504 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
49505 SF(s_do_balance), SF(s_unneeded_left_neighbor),
49506 SF(s_good_search_by_key_reada), SF(s_bmaps),
49507 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
49508 index 33215f5..c5d427a 100644
49509 --- a/fs/reiserfs/reiserfs.h
49510 +++ b/fs/reiserfs/reiserfs.h
49511 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
49512 /* Comment? -Hans */
49513 wait_queue_head_t s_wait;
49514 /* To be obsoleted soon by per buffer seals.. -Hans */
49515 - atomic_t s_generation_counter; // increased by one every time the
49516 + atomic_unchecked_t s_generation_counter; // increased by one every time the
49517 // tree gets re-balanced
49518 unsigned long s_properties; /* File system properties. Currently holds
49519 on-disk FS format */
49520 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
49521 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
49522
49523 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
49524 -#define get_generation(s) atomic_read (&fs_generation(s))
49525 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
49526 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
49527 #define __fs_changed(gen,s) (gen != get_generation (s))
49528 #define fs_changed(gen,s) \
49529 diff --git a/fs/select.c b/fs/select.c
49530 index db14c78..3aae1bd 100644
49531 --- a/fs/select.c
49532 +++ b/fs/select.c
49533 @@ -20,6 +20,7 @@
49534 #include <linux/export.h>
49535 #include <linux/slab.h>
49536 #include <linux/poll.h>
49537 +#include <linux/security.h>
49538 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
49539 #include <linux/file.h>
49540 #include <linux/fdtable.h>
49541 @@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
49542 struct poll_list *walk = head;
49543 unsigned long todo = nfds;
49544
49545 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
49546 if (nfds > rlimit(RLIMIT_NOFILE))
49547 return -EINVAL;
49548
49549 diff --git a/fs/seq_file.c b/fs/seq_file.c
49550 index 0cbd049..64e705c 100644
49551 --- a/fs/seq_file.c
49552 +++ b/fs/seq_file.c
49553 @@ -9,6 +9,7 @@
49554 #include <linux/export.h>
49555 #include <linux/seq_file.h>
49556 #include <linux/slab.h>
49557 +#include <linux/sched.h>
49558
49559 #include <asm/uaccess.h>
49560 #include <asm/page.h>
49561 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
49562 memset(p, 0, sizeof(*p));
49563 mutex_init(&p->lock);
49564 p->op = op;
49565 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49566 + p->exec_id = current->exec_id;
49567 +#endif
49568
49569 /*
49570 * Wrappers around seq_open(e.g. swaps_open) need to be
49571 @@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49572 return 0;
49573 }
49574 if (!m->buf) {
49575 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49576 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49577 if (!m->buf)
49578 return -ENOMEM;
49579 }
49580 @@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49581 Eoverflow:
49582 m->op->stop(m, p);
49583 kfree(m->buf);
49584 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49585 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49586 return !m->buf ? -ENOMEM : -EAGAIN;
49587 }
49588
49589 @@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49590
49591 /* grab buffer if we didn't have one */
49592 if (!m->buf) {
49593 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49594 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49595 if (!m->buf)
49596 goto Enomem;
49597 }
49598 @@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49599 goto Fill;
49600 m->op->stop(m, p);
49601 kfree(m->buf);
49602 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49603 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49604 if (!m->buf)
49605 goto Enomem;
49606 m->count = 0;
49607 @@ -567,7 +571,7 @@ static void single_stop(struct seq_file *p, void *v)
49608 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49609 void *data)
49610 {
49611 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49612 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49613 int res = -ENOMEM;
49614
49615 if (op) {
49616 diff --git a/fs/splice.c b/fs/splice.c
49617 index 7bf08fa..eb35c2f 100644
49618 --- a/fs/splice.c
49619 +++ b/fs/splice.c
49620 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49621 pipe_lock(pipe);
49622
49623 for (;;) {
49624 - if (!pipe->readers) {
49625 + if (!atomic_read(&pipe->readers)) {
49626 send_sig(SIGPIPE, current, 0);
49627 if (!ret)
49628 ret = -EPIPE;
49629 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49630 do_wakeup = 0;
49631 }
49632
49633 - pipe->waiting_writers++;
49634 + atomic_inc(&pipe->waiting_writers);
49635 pipe_wait(pipe);
49636 - pipe->waiting_writers--;
49637 + atomic_dec(&pipe->waiting_writers);
49638 }
49639
49640 pipe_unlock(pipe);
49641 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49642 old_fs = get_fs();
49643 set_fs(get_ds());
49644 /* The cast to a user pointer is valid due to the set_fs() */
49645 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49646 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49647 set_fs(old_fs);
49648
49649 return res;
49650 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49651 old_fs = get_fs();
49652 set_fs(get_ds());
49653 /* The cast to a user pointer is valid due to the set_fs() */
49654 - res = vfs_write(file, (const char __user *)buf, count, &pos);
49655 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49656 set_fs(old_fs);
49657
49658 return res;
49659 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49660 goto err;
49661
49662 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49663 - vec[i].iov_base = (void __user *) page_address(page);
49664 + vec[i].iov_base = (void __force_user *) page_address(page);
49665 vec[i].iov_len = this_len;
49666 spd.pages[i] = page;
49667 spd.nr_pages++;
49668 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49669 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49670 {
49671 while (!pipe->nrbufs) {
49672 - if (!pipe->writers)
49673 + if (!atomic_read(&pipe->writers))
49674 return 0;
49675
49676 - if (!pipe->waiting_writers && sd->num_spliced)
49677 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49678 return 0;
49679
49680 if (sd->flags & SPLICE_F_NONBLOCK)
49681 @@ -1187,7 +1187,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49682 * out of the pipe right after the splice_to_pipe(). So set
49683 * PIPE_READERS appropriately.
49684 */
49685 - pipe->readers = 1;
49686 + atomic_set(&pipe->readers, 1);
49687
49688 current->splice_pipe = pipe;
49689 }
49690 @@ -1740,9 +1740,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49691 ret = -ERESTARTSYS;
49692 break;
49693 }
49694 - if (!pipe->writers)
49695 + if (!atomic_read(&pipe->writers))
49696 break;
49697 - if (!pipe->waiting_writers) {
49698 + if (!atomic_read(&pipe->waiting_writers)) {
49699 if (flags & SPLICE_F_NONBLOCK) {
49700 ret = -EAGAIN;
49701 break;
49702 @@ -1774,7 +1774,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49703 pipe_lock(pipe);
49704
49705 while (pipe->nrbufs >= pipe->buffers) {
49706 - if (!pipe->readers) {
49707 + if (!atomic_read(&pipe->readers)) {
49708 send_sig(SIGPIPE, current, 0);
49709 ret = -EPIPE;
49710 break;
49711 @@ -1787,9 +1787,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49712 ret = -ERESTARTSYS;
49713 break;
49714 }
49715 - pipe->waiting_writers++;
49716 + atomic_inc(&pipe->waiting_writers);
49717 pipe_wait(pipe);
49718 - pipe->waiting_writers--;
49719 + atomic_dec(&pipe->waiting_writers);
49720 }
49721
49722 pipe_unlock(pipe);
49723 @@ -1825,14 +1825,14 @@ retry:
49724 pipe_double_lock(ipipe, opipe);
49725
49726 do {
49727 - if (!opipe->readers) {
49728 + if (!atomic_read(&opipe->readers)) {
49729 send_sig(SIGPIPE, current, 0);
49730 if (!ret)
49731 ret = -EPIPE;
49732 break;
49733 }
49734
49735 - if (!ipipe->nrbufs && !ipipe->writers)
49736 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49737 break;
49738
49739 /*
49740 @@ -1929,7 +1929,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49741 pipe_double_lock(ipipe, opipe);
49742
49743 do {
49744 - if (!opipe->readers) {
49745 + if (!atomic_read(&opipe->readers)) {
49746 send_sig(SIGPIPE, current, 0);
49747 if (!ret)
49748 ret = -EPIPE;
49749 @@ -1974,7 +1974,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49750 * return EAGAIN if we have the potential of some data in the
49751 * future, otherwise just return 0
49752 */
49753 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49754 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49755 ret = -EAGAIN;
49756
49757 pipe_unlock(ipipe);
49758 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49759 index e6bb9b2..d8e3951 100644
49760 --- a/fs/sysfs/dir.c
49761 +++ b/fs/sysfs/dir.c
49762 @@ -678,6 +678,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49763 struct sysfs_dirent *sd;
49764 int rc;
49765
49766 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49767 + const char *parent_name = parent_sd->s_name;
49768 +
49769 + mode = S_IFDIR | S_IRWXU;
49770 +
49771 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49772 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49773 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49774 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49775 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49776 +#endif
49777 +
49778 /* allocate */
49779 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49780 if (!sd)
49781 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49782 index 00012e3..8392349 100644
49783 --- a/fs/sysfs/file.c
49784 +++ b/fs/sysfs/file.c
49785 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49786
49787 struct sysfs_open_dirent {
49788 atomic_t refcnt;
49789 - atomic_t event;
49790 + atomic_unchecked_t event;
49791 wait_queue_head_t poll;
49792 struct list_head buffers; /* goes through sysfs_buffer.list */
49793 };
49794 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49795 if (!sysfs_get_active(attr_sd))
49796 return -ENODEV;
49797
49798 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49799 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49800 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49801
49802 sysfs_put_active(attr_sd);
49803 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49804 return -ENOMEM;
49805
49806 atomic_set(&new_od->refcnt, 0);
49807 - atomic_set(&new_od->event, 1);
49808 + atomic_set_unchecked(&new_od->event, 1);
49809 init_waitqueue_head(&new_od->poll);
49810 INIT_LIST_HEAD(&new_od->buffers);
49811 goto retry;
49812 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49813
49814 sysfs_put_active(attr_sd);
49815
49816 - if (buffer->event != atomic_read(&od->event))
49817 + if (buffer->event != atomic_read_unchecked(&od->event))
49818 goto trigger;
49819
49820 return DEFAULT_POLLMASK;
49821 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49822
49823 od = sd->s_attr.open;
49824 if (od) {
49825 - atomic_inc(&od->event);
49826 + atomic_inc_unchecked(&od->event);
49827 wake_up_interruptible(&od->poll);
49828 }
49829
49830 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49831 index a7ac78f..02158e1 100644
49832 --- a/fs/sysfs/symlink.c
49833 +++ b/fs/sysfs/symlink.c
49834 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49835
49836 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49837 {
49838 - char *page = nd_get_link(nd);
49839 + const char *page = nd_get_link(nd);
49840 if (!IS_ERR(page))
49841 free_page((unsigned long)page);
49842 }
49843 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49844 index c175b4d..8f36a16 100644
49845 --- a/fs/udf/misc.c
49846 +++ b/fs/udf/misc.c
49847 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49848
49849 u8 udf_tag_checksum(const struct tag *t)
49850 {
49851 - u8 *data = (u8 *)t;
49852 + const u8 *data = (const u8 *)t;
49853 u8 checksum = 0;
49854 int i;
49855 for (i = 0; i < sizeof(struct tag); ++i)
49856 diff --git a/fs/utimes.c b/fs/utimes.c
49857 index fa4dbe4..e12d1b9 100644
49858 --- a/fs/utimes.c
49859 +++ b/fs/utimes.c
49860 @@ -1,6 +1,7 @@
49861 #include <linux/compiler.h>
49862 #include <linux/file.h>
49863 #include <linux/fs.h>
49864 +#include <linux/security.h>
49865 #include <linux/linkage.h>
49866 #include <linux/mount.h>
49867 #include <linux/namei.h>
49868 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49869 goto mnt_drop_write_and_out;
49870 }
49871 }
49872 +
49873 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
49874 + error = -EACCES;
49875 + goto mnt_drop_write_and_out;
49876 + }
49877 +
49878 mutex_lock(&inode->i_mutex);
49879 error = notify_change(path->dentry, &newattrs);
49880 mutex_unlock(&inode->i_mutex);
49881 diff --git a/fs/xattr.c b/fs/xattr.c
49882 index 1d7ac37..23cb9ec 100644
49883 --- a/fs/xattr.c
49884 +++ b/fs/xattr.c
49885 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49886 * Extended attribute SET operations
49887 */
49888 static long
49889 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
49890 +setxattr(struct path *path, const char __user *name, const void __user *value,
49891 size_t size, int flags)
49892 {
49893 int error;
49894 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49895 }
49896 }
49897
49898 - error = vfs_setxattr(d, kname, kvalue, size, flags);
49899 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49900 + error = -EACCES;
49901 + goto out;
49902 + }
49903 +
49904 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49905 out:
49906 if (vvalue)
49907 vfree(vvalue);
49908 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49909 return error;
49910 error = mnt_want_write(path.mnt);
49911 if (!error) {
49912 - error = setxattr(path.dentry, name, value, size, flags);
49913 + error = setxattr(&path, name, value, size, flags);
49914 mnt_drop_write(path.mnt);
49915 }
49916 path_put(&path);
49917 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49918 return error;
49919 error = mnt_want_write(path.mnt);
49920 if (!error) {
49921 - error = setxattr(path.dentry, name, value, size, flags);
49922 + error = setxattr(&path, name, value, size, flags);
49923 mnt_drop_write(path.mnt);
49924 }
49925 path_put(&path);
49926 @@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49927 {
49928 int fput_needed;
49929 struct file *f;
49930 - struct dentry *dentry;
49931 int error = -EBADF;
49932
49933 f = fget_light(fd, &fput_needed);
49934 if (!f)
49935 return error;
49936 - dentry = f->f_path.dentry;
49937 - audit_inode(NULL, dentry);
49938 + audit_inode(NULL, f->f_path.dentry);
49939 error = mnt_want_write_file(f);
49940 if (!error) {
49941 - error = setxattr(dentry, name, value, size, flags);
49942 + error = setxattr(&f->f_path, name, value, size, flags);
49943 mnt_drop_write_file(f);
49944 }
49945 fput_light(f, fput_needed);
49946 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49947 index 69d06b0..c0996e5 100644
49948 --- a/fs/xattr_acl.c
49949 +++ b/fs/xattr_acl.c
49950 @@ -17,8 +17,8 @@
49951 struct posix_acl *
49952 posix_acl_from_xattr(const void *value, size_t size)
49953 {
49954 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49955 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49956 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49957 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49958 int count;
49959 struct posix_acl *acl;
49960 struct posix_acl_entry *acl_e;
49961 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49962 index 58b815e..595ddee 100644
49963 --- a/fs/xfs/xfs_bmap.c
49964 +++ b/fs/xfs/xfs_bmap.c
49965 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
49966 int nmap,
49967 int ret_nmap);
49968 #else
49969 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49970 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49971 #endif /* DEBUG */
49972
49973 STATIC int
49974 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49975 index 19bf0c5..9f26b02 100644
49976 --- a/fs/xfs/xfs_dir2_sf.c
49977 +++ b/fs/xfs/xfs_dir2_sf.c
49978 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
49979 }
49980
49981 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49982 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49983 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49984 + char name[sfep->namelen];
49985 + memcpy(name, sfep->name, sfep->namelen);
49986 + if (filldir(dirent, name, sfep->namelen,
49987 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
49988 + *offset = off & 0x7fffffff;
49989 + return 0;
49990 + }
49991 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49992 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49993 *offset = off & 0x7fffffff;
49994 return 0;
49995 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49996 index 3a05a41..320bec6 100644
49997 --- a/fs/xfs/xfs_ioctl.c
49998 +++ b/fs/xfs/xfs_ioctl.c
49999 @@ -126,7 +126,7 @@ xfs_find_handle(
50000 }
50001
50002 error = -EFAULT;
50003 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50004 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50005 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50006 goto out_put;
50007
50008 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50009 index 1a25fd8..e935581 100644
50010 --- a/fs/xfs/xfs_iops.c
50011 +++ b/fs/xfs/xfs_iops.c
50012 @@ -394,7 +394,7 @@ xfs_vn_put_link(
50013 struct nameidata *nd,
50014 void *p)
50015 {
50016 - char *s = nd_get_link(nd);
50017 + const char *s = nd_get_link(nd);
50018
50019 if (!IS_ERR(s))
50020 kfree(s);
50021 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50022 new file mode 100644
50023 index 0000000..4d533f1
50024 --- /dev/null
50025 +++ b/grsecurity/Kconfig
50026 @@ -0,0 +1,941 @@
50027 +#
50028 +# grecurity configuration
50029 +#
50030 +menu "Memory Protections"
50031 +depends on GRKERNSEC
50032 +
50033 +config GRKERNSEC_KMEM
50034 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50035 + default y if GRKERNSEC_CONFIG_AUTO
50036 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50037 + help
50038 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50039 + be written to or read from to modify or leak the contents of the running
50040 + kernel. /dev/port will also not be allowed to be opened. If you have module
50041 + support disabled, enabling this will close up four ways that are
50042 + currently used to insert malicious code into the running kernel.
50043 + Even with all these features enabled, we still highly recommend that
50044 + you use the RBAC system, as it is still possible for an attacker to
50045 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50046 + If you are not using XFree86, you may be able to stop this additional
50047 + case by enabling the 'Disable privileged I/O' option. Though nothing
50048 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50049 + but only to video memory, which is the only writing we allow in this
50050 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50051 + not be allowed to mprotect it with PROT_WRITE later.
50052 + It is highly recommended that you say Y here if you meet all the
50053 + conditions above.
50054 +
50055 +config GRKERNSEC_VM86
50056 + bool "Restrict VM86 mode"
50057 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50058 + depends on X86_32
50059 +
50060 + help
50061 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50062 + make use of a special execution mode on 32bit x86 processors called
50063 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50064 + video cards and will still work with this option enabled. The purpose
50065 + of the option is to prevent exploitation of emulation errors in
50066 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50067 + Nearly all users should be able to enable this option.
50068 +
50069 +config GRKERNSEC_IO
50070 + bool "Disable privileged I/O"
50071 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50072 + depends on X86
50073 + select RTC_CLASS
50074 + select RTC_INTF_DEV
50075 + select RTC_DRV_CMOS
50076 +
50077 + help
50078 + If you say Y here, all ioperm and iopl calls will return an error.
50079 + Ioperm and iopl can be used to modify the running kernel.
50080 + Unfortunately, some programs need this access to operate properly,
50081 + the most notable of which are XFree86 and hwclock. hwclock can be
50082 + remedied by having RTC support in the kernel, so real-time
50083 + clock support is enabled if this option is enabled, to ensure
50084 + that hwclock operates correctly. XFree86 still will not
50085 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50086 + IF YOU USE XFree86. If you use XFree86 and you still want to
50087 + protect your kernel against modification, use the RBAC system.
50088 +
50089 +config GRKERNSEC_PROC_MEMMAP
50090 + bool "Harden ASLR against information leaks and entropy reduction"
50091 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50092 + depends on PAX_NOEXEC || PAX_ASLR
50093 + help
50094 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50095 + give no information about the addresses of its mappings if
50096 + PaX features that rely on random addresses are enabled on the task.
50097 + In addition to sanitizing this information and disabling other
50098 + dangerous sources of information, this option causes reads of sensitive
50099 + /proc/<pid> entries where the file descriptor was opened in a different
50100 + task than the one performing the read. Such attempts are logged.
50101 + This option also limits argv/env strings for suid/sgid binaries
50102 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50103 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50104 + binaries to prevent alternative mmap layouts from being abused.
50105 +
50106 + If you use PaX it is essential that you say Y here as it closes up
50107 + several holes that make full ASLR useless locally.
50108 +
50109 +config GRKERNSEC_BRUTE
50110 + bool "Deter exploit bruteforcing"
50111 + default y if GRKERNSEC_CONFIG_AUTO
50112 + help
50113 + If you say Y here, attempts to bruteforce exploits against forking
50114 + daemons such as apache or sshd, as well as against suid/sgid binaries
50115 + will be deterred. When a child of a forking daemon is killed by PaX
50116 + or crashes due to an illegal instruction or other suspicious signal,
50117 + the parent process will be delayed 30 seconds upon every subsequent
50118 + fork until the administrator is able to assess the situation and
50119 + restart the daemon.
50120 + In the suid/sgid case, the attempt is logged, the user has all their
50121 + processes terminated, and they are prevented from executing any further
50122 + processes for 15 minutes.
50123 + It is recommended that you also enable signal logging in the auditing
50124 + section so that logs are generated when a process triggers a suspicious
50125 + signal.
50126 + If the sysctl option is enabled, a sysctl option with name
50127 + "deter_bruteforce" is created.
50128 +
50129 +
50130 +config GRKERNSEC_MODHARDEN
50131 + bool "Harden module auto-loading"
50132 + default y if GRKERNSEC_CONFIG_AUTO
50133 + depends on MODULES
50134 + help
50135 + If you say Y here, module auto-loading in response to use of some
50136 + feature implemented by an unloaded module will be restricted to
50137 + root users. Enabling this option helps defend against attacks
50138 + by unprivileged users who abuse the auto-loading behavior to
50139 + cause a vulnerable module to load that is then exploited.
50140 +
50141 + If this option prevents a legitimate use of auto-loading for a
50142 + non-root user, the administrator can execute modprobe manually
50143 + with the exact name of the module mentioned in the alert log.
50144 + Alternatively, the administrator can add the module to the list
50145 + of modules loaded at boot by modifying init scripts.
50146 +
50147 + Modification of init scripts will most likely be needed on
50148 + Ubuntu servers with encrypted home directory support enabled,
50149 + as the first non-root user logging in will cause the ecb(aes),
50150 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50151 +
50152 +config GRKERNSEC_HIDESYM
50153 + bool "Hide kernel symbols"
50154 + default y if GRKERNSEC_CONFIG_AUTO
50155 + select PAX_USERCOPY_SLABS
50156 + help
50157 + If you say Y here, getting information on loaded modules, and
50158 + displaying all kernel symbols through a syscall will be restricted
50159 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50160 + /proc/kallsyms will be restricted to the root user. The RBAC
50161 + system can hide that entry even from root.
50162 +
50163 + This option also prevents leaking of kernel addresses through
50164 + several /proc entries.
50165 +
50166 + Note that this option is only effective provided the following
50167 + conditions are met:
50168 + 1) The kernel using grsecurity is not precompiled by some distribution
50169 + 2) You have also enabled GRKERNSEC_DMESG
50170 + 3) You are using the RBAC system and hiding other files such as your
50171 + kernel image and System.map. Alternatively, enabling this option
50172 + causes the permissions on /boot, /lib/modules, and the kernel
50173 + source directory to change at compile time to prevent
50174 + reading by non-root users.
50175 + If the above conditions are met, this option will aid in providing a
50176 + useful protection against local kernel exploitation of overflows
50177 + and arbitrary read/write vulnerabilities.
50178 +
50179 +config GRKERNSEC_KERN_LOCKOUT
50180 + bool "Active kernel exploit response"
50181 + default y if GRKERNSEC_CONFIG_AUTO
50182 + depends on X86 || ARM || PPC || SPARC
50183 + help
50184 + If you say Y here, when a PaX alert is triggered due to suspicious
50185 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50186 + or an OOPS occurs due to bad memory accesses, instead of just
50187 + terminating the offending process (and potentially allowing
50188 + a subsequent exploit from the same user), we will take one of two
50189 + actions:
50190 + If the user was root, we will panic the system
50191 + If the user was non-root, we will log the attempt, terminate
50192 + all processes owned by the user, then prevent them from creating
50193 + any new processes until the system is restarted
50194 + This deters repeated kernel exploitation/bruteforcing attempts
50195 + and is useful for later forensics.
50196 +
50197 +endmenu
50198 +menu "Role Based Access Control Options"
50199 +depends on GRKERNSEC
50200 +
50201 +config GRKERNSEC_RBAC_DEBUG
50202 + bool
50203 +
50204 +config GRKERNSEC_NO_RBAC
50205 + bool "Disable RBAC system"
50206 + help
50207 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50208 + preventing the RBAC system from being enabled. You should only say Y
50209 + here if you have no intention of using the RBAC system, so as to prevent
50210 + an attacker with root access from misusing the RBAC system to hide files
50211 + and processes when loadable module support and /dev/[k]mem have been
50212 + locked down.
50213 +
50214 +config GRKERNSEC_ACL_HIDEKERN
50215 + bool "Hide kernel processes"
50216 + help
50217 + If you say Y here, all kernel threads will be hidden to all
50218 + processes but those whose subject has the "view hidden processes"
50219 + flag.
50220 +
50221 +config GRKERNSEC_ACL_MAXTRIES
50222 + int "Maximum tries before password lockout"
50223 + default 3
50224 + help
50225 + This option enforces the maximum number of times a user can attempt
50226 + to authorize themselves with the grsecurity RBAC system before being
50227 + denied the ability to attempt authorization again for a specified time.
50228 + The lower the number, the harder it will be to brute-force a password.
50229 +
50230 +config GRKERNSEC_ACL_TIMEOUT
50231 + int "Time to wait after max password tries, in seconds"
50232 + default 30
50233 + help
50234 + This option specifies the time the user must wait after attempting to
50235 + authorize to the RBAC system with the maximum number of invalid
50236 + passwords. The higher the number, the harder it will be to brute-force
50237 + a password.
50238 +
50239 +endmenu
50240 +menu "Filesystem Protections"
50241 +depends on GRKERNSEC
50242 +
50243 +config GRKERNSEC_PROC
50244 + bool "Proc restrictions"
50245 + default y if GRKERNSEC_CONFIG_AUTO
50246 + help
50247 + If you say Y here, the permissions of the /proc filesystem
50248 + will be altered to enhance system security and privacy. You MUST
50249 + choose either a user only restriction or a user and group restriction.
50250 + Depending upon the option you choose, you can either restrict users to
50251 + see only the processes they themselves run, or choose a group that can
50252 + view all processes and files normally restricted to root if you choose
50253 + the "restrict to user only" option. NOTE: If you're running identd or
50254 + ntpd as a non-root user, you will have to run it as the group you
50255 + specify here.
50256 +
50257 +config GRKERNSEC_PROC_USER
50258 + bool "Restrict /proc to user only"
50259 + depends on GRKERNSEC_PROC
50260 + help
50261 + If you say Y here, non-root users will only be able to view their own
50262 + processes, and restricts them from viewing network-related information,
50263 + and viewing kernel symbol and module information.
50264 +
50265 +config GRKERNSEC_PROC_USERGROUP
50266 + bool "Allow special group"
50267 + default y if GRKERNSEC_CONFIG_AUTO
50268 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50269 + help
50270 + If you say Y here, you will be able to select a group that will be
50271 + able to view all processes and network-related information. If you've
50272 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50273 + remain hidden. This option is useful if you want to run identd as
50274 + a non-root user.
50275 +
50276 +config GRKERNSEC_PROC_GID
50277 + int "GID for special group"
50278 + depends on GRKERNSEC_PROC_USERGROUP
50279 + default 1001
50280 +
50281 +config GRKERNSEC_PROC_ADD
50282 + bool "Additional restrictions"
50283 + default y if GRKERNSEC_CONFIG_AUTO
50284 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50285 + help
50286 + If you say Y here, additional restrictions will be placed on
50287 + /proc that keep normal users from viewing device information and
50288 + slabinfo information that could be useful for exploits.
50289 +
50290 +config GRKERNSEC_LINK
50291 + bool "Linking restrictions"
50292 + default y if GRKERNSEC_CONFIG_AUTO
50293 + help
50294 + If you say Y here, /tmp race exploits will be prevented, since users
50295 + will no longer be able to follow symlinks owned by other users in
50296 + world-writable +t directories (e.g. /tmp), unless the owner of the
50297 + symlink is the owner of the directory. users will also not be
50298 + able to hardlink to files they do not own. If the sysctl option is
50299 + enabled, a sysctl option with name "linking_restrictions" is created.
50300 +
50301 +config GRKERNSEC_SYMLINKOWN
50302 + bool "Kernel-enforced SymlinksIfOwnerMatch"
50303 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50304 + help
50305 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
50306 + that prevents it from being used as a security feature. As Apache
50307 + verifies the symlink by performing a stat() against the target of
50308 + the symlink before it is followed, an attacker can setup a symlink
50309 + to point to a same-owned file, then replace the symlink with one
50310 + that targets another user's file just after Apache "validates" the
50311 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
50312 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50313 + will be in place for the group you specify. If the sysctl option
50314 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
50315 + created.
50316 +
50317 +config GRKERNSEC_SYMLINKOWN_GID
50318 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50319 + depends on GRKERNSEC_SYMLINKOWN
50320 + default 1006
50321 + help
50322 + Setting this GID determines what group kernel-enforced
50323 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50324 + is enabled, a sysctl option with name "symlinkown_gid" is created.
50325 +
50326 +config GRKERNSEC_FIFO
50327 + bool "FIFO restrictions"
50328 + default y if GRKERNSEC_CONFIG_AUTO
50329 + help
50330 + If you say Y here, users will not be able to write to FIFOs they don't
50331 + own in world-writable +t directories (e.g. /tmp), unless the owner of
50332 + the FIFO is the same owner of the directory it's held in. If the sysctl
50333 + option is enabled, a sysctl option with name "fifo_restrictions" is
50334 + created.
50335 +
50336 +config GRKERNSEC_SYSFS_RESTRICT
50337 + bool "Sysfs/debugfs restriction"
50338 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50339 + depends on SYSFS
50340 + help
50341 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50342 + any filesystem normally mounted under it (e.g. debugfs) will be
50343 + mostly accessible only by root. These filesystems generally provide access
50344 + to hardware and debug information that isn't appropriate for unprivileged
50345 + users of the system. Sysfs and debugfs have also become a large source
50346 + of new vulnerabilities, ranging from infoleaks to local compromise.
50347 + There has been very little oversight with an eye toward security involved
50348 + in adding new exporters of information to these filesystems, so their
50349 + use is discouraged.
50350 + For reasons of compatibility, a few directories have been whitelisted
50351 + for access by non-root users:
50352 + /sys/fs/selinux
50353 + /sys/fs/fuse
50354 + /sys/devices/system/cpu
50355 +
50356 +config GRKERNSEC_ROFS
50357 + bool "Runtime read-only mount protection"
50358 + help
50359 + If you say Y here, a sysctl option with name "romount_protect" will
50360 + be created. By setting this option to 1 at runtime, filesystems
50361 + will be protected in the following ways:
50362 + * No new writable mounts will be allowed
50363 + * Existing read-only mounts won't be able to be remounted read/write
50364 + * Write operations will be denied on all block devices
50365 + This option acts independently of grsec_lock: once it is set to 1,
50366 + it cannot be turned off. Therefore, please be mindful of the resulting
50367 + behavior if this option is enabled in an init script on a read-only
50368 + filesystem. This feature is mainly intended for secure embedded systems.
50369 +
50370 +config GRKERNSEC_CHROOT
50371 + bool "Chroot jail restrictions"
50372 + default y if GRKERNSEC_CONFIG_AUTO
50373 + help
50374 + If you say Y here, you will be able to choose several options that will
50375 + make breaking out of a chrooted jail much more difficult. If you
50376 + encounter no software incompatibilities with the following options, it
50377 + is recommended that you enable each one.
50378 +
50379 +config GRKERNSEC_CHROOT_MOUNT
50380 + bool "Deny mounts"
50381 + default y if GRKERNSEC_CONFIG_AUTO
50382 + depends on GRKERNSEC_CHROOT
50383 + help
50384 + If you say Y here, processes inside a chroot will not be able to
50385 + mount or remount filesystems. If the sysctl option is enabled, a
50386 + sysctl option with name "chroot_deny_mount" is created.
50387 +
50388 +config GRKERNSEC_CHROOT_DOUBLE
50389 + bool "Deny double-chroots"
50390 + default y if GRKERNSEC_CONFIG_AUTO
50391 + depends on GRKERNSEC_CHROOT
50392 + help
50393 + If you say Y here, processes inside a chroot will not be able to chroot
50394 + again outside the chroot. This is a widely used method of breaking
50395 + out of a chroot jail and should not be allowed. If the sysctl
50396 + option is enabled, a sysctl option with name
50397 + "chroot_deny_chroot" is created.
50398 +
50399 +config GRKERNSEC_CHROOT_PIVOT
50400 + bool "Deny pivot_root in chroot"
50401 + default y if GRKERNSEC_CONFIG_AUTO
50402 + depends on GRKERNSEC_CHROOT
50403 + help
50404 + If you say Y here, processes inside a chroot will not be able to use
50405 + a function called pivot_root() that was introduced in Linux 2.3.41. It
50406 + works similar to chroot in that it changes the root filesystem. This
50407 + function could be misused in a chrooted process to attempt to break out
50408 + of the chroot, and therefore should not be allowed. If the sysctl
50409 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
50410 + created.
50411 +
50412 +config GRKERNSEC_CHROOT_CHDIR
50413 + bool "Enforce chdir(\"/\") on all chroots"
50414 + default y if GRKERNSEC_CONFIG_AUTO
50415 + depends on GRKERNSEC_CHROOT
50416 + help
50417 + If you say Y here, the current working directory of all newly-chrooted
50418 + applications will be set to the the root directory of the chroot.
50419 + The man page on chroot(2) states:
50420 + Note that this call does not change the current working
50421 + directory, so that `.' can be outside the tree rooted at
50422 + `/'. In particular, the super-user can escape from a
50423 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50424 +
50425 + It is recommended that you say Y here, since it's not known to break
50426 + any software. If the sysctl option is enabled, a sysctl option with
50427 + name "chroot_enforce_chdir" is created.
50428 +
50429 +config GRKERNSEC_CHROOT_CHMOD
50430 + bool "Deny (f)chmod +s"
50431 + default y if GRKERNSEC_CONFIG_AUTO
50432 + depends on GRKERNSEC_CHROOT
50433 + help
50434 + If you say Y here, processes inside a chroot will not be able to chmod
50435 + or fchmod files to make them have suid or sgid bits. This protects
50436 + against another published method of breaking a chroot. If the sysctl
50437 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
50438 + created.
50439 +
50440 +config GRKERNSEC_CHROOT_FCHDIR
50441 + bool "Deny fchdir out of chroot"
50442 + default y if GRKERNSEC_CONFIG_AUTO
50443 + depends on GRKERNSEC_CHROOT
50444 + help
50445 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
50446 + to a file descriptor of the chrooting process that points to a directory
50447 + outside the filesystem will be stopped. If the sysctl option
50448 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50449 +
50450 +config GRKERNSEC_CHROOT_MKNOD
50451 + bool "Deny mknod"
50452 + default y if GRKERNSEC_CONFIG_AUTO
50453 + depends on GRKERNSEC_CHROOT
50454 + help
50455 + If you say Y here, processes inside a chroot will not be allowed to
50456 + mknod. The problem with using mknod inside a chroot is that it
50457 + would allow an attacker to create a device entry that is the same
50458 + as one on the physical root of your system, which could range from
50459 + anything from the console device to a device for your harddrive (which
50460 + they could then use to wipe the drive or steal data). It is recommended
50461 + that you say Y here, unless you run into software incompatibilities.
50462 + If the sysctl option is enabled, a sysctl option with name
50463 + "chroot_deny_mknod" is created.
50464 +
50465 +config GRKERNSEC_CHROOT_SHMAT
50466 + bool "Deny shmat() out of chroot"
50467 + default y if GRKERNSEC_CONFIG_AUTO
50468 + depends on GRKERNSEC_CHROOT
50469 + help
50470 + If you say Y here, processes inside a chroot will not be able to attach
50471 + to shared memory segments that were created outside of the chroot jail.
50472 + It is recommended that you say Y here. If the sysctl option is enabled,
50473 + a sysctl option with name "chroot_deny_shmat" is created.
50474 +
50475 +config GRKERNSEC_CHROOT_UNIX
50476 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
50477 + default y if GRKERNSEC_CONFIG_AUTO
50478 + depends on GRKERNSEC_CHROOT
50479 + help
50480 + If you say Y here, processes inside a chroot will not be able to
50481 + connect to abstract (meaning not belonging to a filesystem) Unix
50482 + domain sockets that were bound outside of a chroot. It is recommended
50483 + that you say Y here. If the sysctl option is enabled, a sysctl option
50484 + with name "chroot_deny_unix" is created.
50485 +
50486 +config GRKERNSEC_CHROOT_FINDTASK
50487 + bool "Protect outside processes"
50488 + default y if GRKERNSEC_CONFIG_AUTO
50489 + depends on GRKERNSEC_CHROOT
50490 + help
50491 + If you say Y here, processes inside a chroot will not be able to
50492 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50493 + getsid, or view any process outside of the chroot. If the sysctl
50494 + option is enabled, a sysctl option with name "chroot_findtask" is
50495 + created.
50496 +
50497 +config GRKERNSEC_CHROOT_NICE
50498 + bool "Restrict priority changes"
50499 + default y if GRKERNSEC_CONFIG_AUTO
50500 + depends on GRKERNSEC_CHROOT
50501 + help
50502 + If you say Y here, processes inside a chroot will not be able to raise
50503 + the priority of processes in the chroot, or alter the priority of
50504 + processes outside the chroot. This provides more security than simply
50505 + removing CAP_SYS_NICE from the process' capability set. If the
50506 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50507 + is created.
50508 +
50509 +config GRKERNSEC_CHROOT_SYSCTL
50510 + bool "Deny sysctl writes"
50511 + default y if GRKERNSEC_CONFIG_AUTO
50512 + depends on GRKERNSEC_CHROOT
50513 + help
50514 + If you say Y here, an attacker in a chroot will not be able to
50515 + write to sysctl entries, either by sysctl(2) or through a /proc
50516 + interface. It is strongly recommended that you say Y here. If the
50517 + sysctl option is enabled, a sysctl option with name
50518 + "chroot_deny_sysctl" is created.
50519 +
50520 +config GRKERNSEC_CHROOT_CAPS
50521 + bool "Capability restrictions"
50522 + default y if GRKERNSEC_CONFIG_AUTO
50523 + depends on GRKERNSEC_CHROOT
50524 + help
50525 + If you say Y here, the capabilities on all processes within a
50526 + chroot jail will be lowered to stop module insertion, raw i/o,
50527 + system and net admin tasks, rebooting the system, modifying immutable
50528 + files, modifying IPC owned by another, and changing the system time.
50529 + This is left an option because it can break some apps. Disable this
50530 + if your chrooted apps are having problems performing those kinds of
50531 + tasks. If the sysctl option is enabled, a sysctl option with
50532 + name "chroot_caps" is created.
50533 +
50534 +endmenu
50535 +menu "Kernel Auditing"
50536 +depends on GRKERNSEC
50537 +
50538 +config GRKERNSEC_AUDIT_GROUP
50539 + bool "Single group for auditing"
50540 + help
50541 + If you say Y here, the exec, chdir, and (un)mount logging features
50542 + will only operate on a group you specify. This option is recommended
50543 + if you only want to watch certain users instead of having a large
50544 + amount of logs from the entire system. If the sysctl option is enabled,
50545 + a sysctl option with name "audit_group" is created.
50546 +
50547 +config GRKERNSEC_AUDIT_GID
50548 + int "GID for auditing"
50549 + depends on GRKERNSEC_AUDIT_GROUP
50550 + default 1007
50551 +
50552 +config GRKERNSEC_EXECLOG
50553 + bool "Exec logging"
50554 + help
50555 + If you say Y here, all execve() calls will be logged (since the
50556 + other exec*() calls are frontends to execve(), all execution
50557 + will be logged). Useful for shell-servers that like to keep track
50558 + of their users. If the sysctl option is enabled, a sysctl option with
50559 + name "exec_logging" is created.
50560 + WARNING: This option when enabled will produce a LOT of logs, especially
50561 + on an active system.
50562 +
50563 +config GRKERNSEC_RESLOG
50564 + bool "Resource logging"
50565 + default y if GRKERNSEC_CONFIG_AUTO
50566 + help
50567 + If you say Y here, all attempts to overstep resource limits will
50568 + be logged with the resource name, the requested size, and the current
50569 + limit. It is highly recommended that you say Y here. If the sysctl
50570 + option is enabled, a sysctl option with name "resource_logging" is
50571 + created. If the RBAC system is enabled, the sysctl value is ignored.
50572 +
50573 +config GRKERNSEC_CHROOT_EXECLOG
50574 + bool "Log execs within chroot"
50575 + help
50576 + If you say Y here, all executions inside a chroot jail will be logged
50577 + to syslog. This can cause a large amount of logs if certain
50578 + applications (eg. djb's daemontools) are installed on the system, and
50579 + is therefore left as an option. If the sysctl option is enabled, a
50580 + sysctl option with name "chroot_execlog" is created.
50581 +
50582 +config GRKERNSEC_AUDIT_PTRACE
50583 + bool "Ptrace logging"
50584 + help
50585 + If you say Y here, all attempts to attach to a process via ptrace
50586 + will be logged. If the sysctl option is enabled, a sysctl option
50587 + with name "audit_ptrace" is created.
50588 +
50589 +config GRKERNSEC_AUDIT_CHDIR
50590 + bool "Chdir logging"
50591 + help
50592 + If you say Y here, all chdir() calls will be logged. If the sysctl
50593 + option is enabled, a sysctl option with name "audit_chdir" is created.
50594 +
50595 +config GRKERNSEC_AUDIT_MOUNT
50596 + bool "(Un)Mount logging"
50597 + help
50598 + If you say Y here, all mounts and unmounts will be logged. If the
50599 + sysctl option is enabled, a sysctl option with name "audit_mount" is
50600 + created.
50601 +
50602 +config GRKERNSEC_SIGNAL
50603 + bool "Signal logging"
50604 + default y if GRKERNSEC_CONFIG_AUTO
50605 + help
50606 + If you say Y here, certain important signals will be logged, such as
50607 + SIGSEGV, which will as a result inform you of when a error in a program
50608 + occurred, which in some cases could mean a possible exploit attempt.
50609 + If the sysctl option is enabled, a sysctl option with name
50610 + "signal_logging" is created.
50611 +
50612 +config GRKERNSEC_FORKFAIL
50613 + bool "Fork failure logging"
50614 + help
50615 + If you say Y here, all failed fork() attempts will be logged.
50616 + This could suggest a fork bomb, or someone attempting to overstep
50617 + their process limit. If the sysctl option is enabled, a sysctl option
50618 + with name "forkfail_logging" is created.
50619 +
50620 +config GRKERNSEC_TIME
50621 + bool "Time change logging"
50622 + default y if GRKERNSEC_CONFIG_AUTO
50623 + help
50624 + If you say Y here, any changes of the system clock will be logged.
50625 + If the sysctl option is enabled, a sysctl option with name
50626 + "timechange_logging" is created.
50627 +
50628 +config GRKERNSEC_PROC_IPADDR
50629 + bool "/proc/<pid>/ipaddr support"
50630 + default y if GRKERNSEC_CONFIG_AUTO
50631 + help
50632 + If you say Y here, a new entry will be added to each /proc/<pid>
50633 + directory that contains the IP address of the person using the task.
50634 + The IP is carried across local TCP and AF_UNIX stream sockets.
50635 + This information can be useful for IDS/IPSes to perform remote response
50636 + to a local attack. The entry is readable by only the owner of the
50637 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50638 + the RBAC system), and thus does not create privacy concerns.
50639 +
50640 +config GRKERNSEC_RWXMAP_LOG
50641 + bool 'Denied RWX mmap/mprotect logging'
50642 + default y if GRKERNSEC_CONFIG_AUTO
50643 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50644 + help
50645 + If you say Y here, calls to mmap() and mprotect() with explicit
50646 + usage of PROT_WRITE and PROT_EXEC together will be logged when
50647 + denied by the PAX_MPROTECT feature. If the sysctl option is
50648 + enabled, a sysctl option with name "rwxmap_logging" is created.
50649 +
50650 +config GRKERNSEC_AUDIT_TEXTREL
50651 + bool 'ELF text relocations logging (READ HELP)'
50652 + depends on PAX_MPROTECT
50653 + help
50654 + If you say Y here, text relocations will be logged with the filename
50655 + of the offending library or binary. The purpose of the feature is
50656 + to help Linux distribution developers get rid of libraries and
50657 + binaries that need text relocations which hinder the future progress
50658 + of PaX. Only Linux distribution developers should say Y here, and
50659 + never on a production machine, as this option creates an information
50660 + leak that could aid an attacker in defeating the randomization of
50661 + a single memory region. If the sysctl option is enabled, a sysctl
50662 + option with name "audit_textrel" is created.
50663 +
50664 +endmenu
50665 +
50666 +menu "Executable Protections"
50667 +depends on GRKERNSEC
50668 +
50669 +config GRKERNSEC_DMESG
50670 + bool "Dmesg(8) restriction"
50671 + default y if GRKERNSEC_CONFIG_AUTO
50672 + help
50673 + If you say Y here, non-root users will not be able to use dmesg(8)
50674 + to view up to the last 4kb of messages in the kernel's log buffer.
50675 + The kernel's log buffer often contains kernel addresses and other
50676 + identifying information useful to an attacker in fingerprinting a
50677 + system for a targeted exploit.
50678 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
50679 + created.
50680 +
50681 +config GRKERNSEC_HARDEN_PTRACE
50682 + bool "Deter ptrace-based process snooping"
50683 + default y if GRKERNSEC_CONFIG_AUTO
50684 + help
50685 + If you say Y here, TTY sniffers and other malicious monitoring
50686 + programs implemented through ptrace will be defeated. If you
50687 + have been using the RBAC system, this option has already been
50688 + enabled for several years for all users, with the ability to make
50689 + fine-grained exceptions.
50690 +
50691 + This option only affects the ability of non-root users to ptrace
50692 + processes that are not a descendent of the ptracing process.
50693 + This means that strace ./binary and gdb ./binary will still work,
50694 + but attaching to arbitrary processes will not. If the sysctl
50695 + option is enabled, a sysctl option with name "harden_ptrace" is
50696 + created.
50697 +
50698 +config GRKERNSEC_PTRACE_READEXEC
50699 + bool "Require read access to ptrace sensitive binaries"
50700 + default y if GRKERNSEC_CONFIG_AUTO
50701 + help
50702 + If you say Y here, unprivileged users will not be able to ptrace unreadable
50703 + binaries. This option is useful in environments that
50704 + remove the read bits (e.g. file mode 4711) from suid binaries to
50705 + prevent infoleaking of their contents. This option adds
50706 + consistency to the use of that file mode, as the binary could normally
50707 + be read out when run without privileges while ptracing.
50708 +
50709 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50710 + is created.
50711 +
50712 +config GRKERNSEC_SETXID
50713 + bool "Enforce consistent multithreaded privileges"
50714 + default y if GRKERNSEC_CONFIG_AUTO
50715 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
50716 + help
50717 + If you say Y here, a change from a root uid to a non-root uid
50718 + in a multithreaded application will cause the resulting uids,
50719 + gids, supplementary groups, and capabilities in that thread
50720 + to be propagated to the other threads of the process. In most
50721 + cases this is unnecessary, as glibc will emulate this behavior
50722 + on behalf of the application. Other libcs do not act in the
50723 + same way, allowing the other threads of the process to continue
50724 + running with root privileges. If the sysctl option is enabled,
50725 + a sysctl option with name "consistent_setxid" is created.
50726 +
50727 +config GRKERNSEC_TPE
50728 + bool "Trusted Path Execution (TPE)"
50729 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50730 + help
50731 + If you say Y here, you will be able to choose a gid to add to the
50732 + supplementary groups of users you want to mark as "untrusted."
50733 + These users will not be able to execute any files that are not in
50734 + root-owned directories writable only by root. If the sysctl option
50735 + is enabled, a sysctl option with name "tpe" is created.
50736 +
50737 +config GRKERNSEC_TPE_ALL
50738 + bool "Partially restrict all non-root users"
50739 + depends on GRKERNSEC_TPE
50740 + help
50741 + If you say Y here, all non-root users will be covered under
50742 + a weaker TPE restriction. This is separate from, and in addition to,
50743 + the main TPE options that you have selected elsewhere. Thus, if a
50744 + "trusted" GID is chosen, this restriction applies to even that GID.
50745 + Under this restriction, all non-root users will only be allowed to
50746 + execute files in directories they own that are not group or
50747 + world-writable, or in directories owned by root and writable only by
50748 + root. If the sysctl option is enabled, a sysctl option with name
50749 + "tpe_restrict_all" is created.
50750 +
50751 +config GRKERNSEC_TPE_INVERT
50752 + bool "Invert GID option"
50753 + depends on GRKERNSEC_TPE
50754 + help
50755 + If you say Y here, the group you specify in the TPE configuration will
50756 + decide what group TPE restrictions will be *disabled* for. This
50757 + option is useful if you want TPE restrictions to be applied to most
50758 + users on the system. If the sysctl option is enabled, a sysctl option
50759 + with name "tpe_invert" is created. Unlike other sysctl options, this
50760 + entry will default to on for backward-compatibility.
50761 +
50762 +config GRKERNSEC_TPE_GID
50763 + int "GID for untrusted users"
50764 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50765 + default 1005
50766 + help
50767 + Setting this GID determines what group TPE restrictions will be
50768 + *enabled* for. If the sysctl option is enabled, a sysctl option
50769 + with name "tpe_gid" is created.
50770 +
50771 +config GRKERNSEC_TPE_GID
50772 + int "GID for trusted users"
50773 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50774 + default 1005
50775 + help
50776 + Setting this GID determines what group TPE restrictions will be
50777 + *disabled* for. If the sysctl option is enabled, a sysctl option
50778 + with name "tpe_gid" is created.
50779 +
50780 +endmenu
50781 +menu "Network Protections"
50782 +depends on GRKERNSEC
50783 +
50784 +config GRKERNSEC_RANDNET
50785 + bool "Larger entropy pools"
50786 + default y if GRKERNSEC_CONFIG_AUTO
50787 + help
50788 + If you say Y here, the entropy pools used for many features of Linux
50789 + and grsecurity will be doubled in size. Since several grsecurity
50790 + features use additional randomness, it is recommended that you say Y
50791 + here. Saying Y here has a similar effect as modifying
50792 + /proc/sys/kernel/random/poolsize.
50793 +
50794 +config GRKERNSEC_BLACKHOLE
50795 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50796 + default y if GRKERNSEC_CONFIG_AUTO
50797 + depends on NET
50798 + help
50799 + If you say Y here, neither TCP resets nor ICMP
50800 + destination-unreachable packets will be sent in response to packets
50801 + sent to ports for which no associated listening process exists.
50802 + This feature supports both IPV4 and IPV6 and exempts the
50803 + loopback interface from blackholing. Enabling this feature
50804 + makes a host more resilient to DoS attacks and reduces network
50805 + visibility against scanners.
50806 +
50807 + The blackhole feature as-implemented is equivalent to the FreeBSD
50808 + blackhole feature, as it prevents RST responses to all packets, not
50809 + just SYNs. Under most application behavior this causes no
50810 + problems, but applications (like haproxy) may not close certain
50811 + connections in a way that cleanly terminates them on the remote
50812 + end, leaving the remote host in LAST_ACK state. Because of this
50813 + side-effect and to prevent intentional LAST_ACK DoSes, this
50814 + feature also adds automatic mitigation against such attacks.
50815 + The mitigation drastically reduces the amount of time a socket
50816 + can spend in LAST_ACK state. If you're using haproxy and not
50817 + all servers it connects to have this option enabled, consider
50818 + disabling this feature on the haproxy host.
50819 +
50820 + If the sysctl option is enabled, two sysctl options with names
50821 + "ip_blackhole" and "lastack_retries" will be created.
50822 + While "ip_blackhole" takes the standard zero/non-zero on/off
50823 + toggle, "lastack_retries" uses the same kinds of values as
50824 + "tcp_retries1" and "tcp_retries2". The default value of 4
50825 + prevents a socket from lasting more than 45 seconds in LAST_ACK
50826 + state.
50827 +
50828 +config GRKERNSEC_SOCKET
50829 + bool "Socket restrictions"
50830 + depends on NET
50831 + help
50832 + If you say Y here, you will be able to choose from several options.
50833 + If you assign a GID on your system and add it to the supplementary
50834 + groups of users you want to restrict socket access to, this patch
50835 + will perform up to three things, based on the option(s) you choose.
50836 +
50837 +config GRKERNSEC_SOCKET_ALL
50838 + bool "Deny any sockets to group"
50839 + depends on GRKERNSEC_SOCKET
50840 + help
50841 + If you say Y here, you will be able to choose a GID of whose users will
50842 + be unable to connect to other hosts from your machine or run server
50843 + applications from your machine. If the sysctl option is enabled, a
50844 + sysctl option with name "socket_all" is created.
50845 +
50846 +config GRKERNSEC_SOCKET_ALL_GID
50847 + int "GID to deny all sockets for"
50848 + depends on GRKERNSEC_SOCKET_ALL
50849 + default 1004
50850 + help
50851 + Here you can choose the GID to disable socket access for. Remember to
50852 + add the users you want socket access disabled for to the GID
50853 + specified here. If the sysctl option is enabled, a sysctl option
50854 + with name "socket_all_gid" is created.
50855 +
50856 +config GRKERNSEC_SOCKET_CLIENT
50857 + bool "Deny client sockets to group"
50858 + depends on GRKERNSEC_SOCKET
50859 + help
50860 + If you say Y here, you will be able to choose a GID of whose users will
50861 + be unable to connect to other hosts from your machine, but will be
50862 + able to run servers. If this option is enabled, all users in the group
50863 + you specify will have to use passive mode when initiating ftp transfers
50864 + from the shell on your machine. If the sysctl option is enabled, a
50865 + sysctl option with name "socket_client" is created.
50866 +
50867 +config GRKERNSEC_SOCKET_CLIENT_GID
50868 + int "GID to deny client sockets for"
50869 + depends on GRKERNSEC_SOCKET_CLIENT
50870 + default 1003
50871 + help
50872 + Here you can choose the GID to disable client socket access for.
50873 + Remember to add the users you want client socket access disabled for to
50874 + the GID specified here. If the sysctl option is enabled, a sysctl
50875 + option with name "socket_client_gid" is created.
50876 +
50877 +config GRKERNSEC_SOCKET_SERVER
50878 + bool "Deny server sockets to group"
50879 + depends on GRKERNSEC_SOCKET
50880 + help
50881 + If you say Y here, you will be able to choose a GID of whose users will
50882 + be unable to run server applications from your machine. If the sysctl
50883 + option is enabled, a sysctl option with name "socket_server" is created.
50884 +
50885 +config GRKERNSEC_SOCKET_SERVER_GID
50886 + int "GID to deny server sockets for"
50887 + depends on GRKERNSEC_SOCKET_SERVER
50888 + default 1002
50889 + help
50890 + Here you can choose the GID to disable server socket access for.
50891 + Remember to add the users you want server socket access disabled for to
50892 + the GID specified here. If the sysctl option is enabled, a sysctl
50893 + option with name "socket_server_gid" is created.
50894 +
50895 +endmenu
50896 +menu "Sysctl Support"
50897 +depends on GRKERNSEC && SYSCTL
50898 +
50899 +config GRKERNSEC_SYSCTL
50900 + bool "Sysctl support"
50901 + default y if GRKERNSEC_CONFIG_AUTO
50902 + help
50903 + If you say Y here, you will be able to change the options that
50904 + grsecurity runs with at bootup, without having to recompile your
50905 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50906 + to enable (1) or disable (0) various features. All the sysctl entries
50907 + are mutable until the "grsec_lock" entry is set to a non-zero value.
50908 + All features enabled in the kernel configuration are disabled at boot
50909 + if you do not say Y to the "Turn on features by default" option.
50910 + All options should be set at startup, and the grsec_lock entry should
50911 + be set to a non-zero value after all the options are set.
50912 + *THIS IS EXTREMELY IMPORTANT*
50913 +
50914 +config GRKERNSEC_SYSCTL_DISTRO
50915 + bool "Extra sysctl support for distro makers (READ HELP)"
50916 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50917 + help
50918 + If you say Y here, additional sysctl options will be created
50919 + for features that affect processes running as root. Therefore,
50920 + it is critical when using this option that the grsec_lock entry be
50921 + enabled after boot. Only distros with prebuilt kernel packages
50922 + with this option enabled that can ensure grsec_lock is enabled
50923 + after boot should use this option.
50924 + *Failure to set grsec_lock after boot makes all grsec features
50925 + this option covers useless*
50926 +
50927 + Currently this option creates the following sysctl entries:
50928 + "Disable Privileged I/O": "disable_priv_io"
50929 +
50930 +config GRKERNSEC_SYSCTL_ON
50931 + bool "Turn on features by default"
50932 + default y if GRKERNSEC_CONFIG_AUTO
50933 + depends on GRKERNSEC_SYSCTL
50934 + help
50935 + If you say Y here, instead of having all features enabled in the
50936 + kernel configuration disabled at boot time, the features will be
50937 + enabled at boot time. It is recommended you say Y here unless
50938 + there is some reason you would want all sysctl-tunable features to
50939 + be disabled by default. As mentioned elsewhere, it is important
50940 + to enable the grsec_lock entry once you have finished modifying
50941 + the sysctl entries.
50942 +
50943 +endmenu
50944 +menu "Logging Options"
50945 +depends on GRKERNSEC
50946 +
50947 +config GRKERNSEC_FLOODTIME
50948 + int "Seconds in between log messages (minimum)"
50949 + default 10
50950 + help
50951 + This option allows you to enforce the number of seconds between
50952 + grsecurity log messages. The default should be suitable for most
50953 + people, however, if you choose to change it, choose a value small enough
50954 + to allow informative logs to be produced, but large enough to
50955 + prevent flooding.
50956 +
50957 +config GRKERNSEC_FLOODBURST
50958 + int "Number of messages in a burst (maximum)"
50959 + default 6
50960 + help
50961 + This option allows you to choose the maximum number of messages allowed
50962 + within the flood time interval you chose in a separate option. The
50963 + default should be suitable for most people, however if you find that
50964 + many of your logs are being interpreted as flooding, you may want to
50965 + raise this value.
50966 +
50967 +endmenu
50968 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50969 new file mode 100644
50970 index 0000000..1b9afa9
50971 --- /dev/null
50972 +++ b/grsecurity/Makefile
50973 @@ -0,0 +1,38 @@
50974 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50975 +# during 2001-2009 it has been completely redesigned by Brad Spengler
50976 +# into an RBAC system
50977 +#
50978 +# All code in this directory and various hooks inserted throughout the kernel
50979 +# are copyright Brad Spengler - Open Source Security, Inc., and released
50980 +# under the GPL v2 or higher
50981 +
50982 +KBUILD_CFLAGS += -Werror
50983 +
50984 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50985 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
50986 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50987 +
50988 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50989 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50990 + gracl_learn.o grsec_log.o
50991 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50992 +
50993 +ifdef CONFIG_NET
50994 +obj-y += grsec_sock.o
50995 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50996 +endif
50997 +
50998 +ifndef CONFIG_GRKERNSEC
50999 +obj-y += grsec_disabled.o
51000 +endif
51001 +
51002 +ifdef CONFIG_GRKERNSEC_HIDESYM
51003 +extra-y := grsec_hidesym.o
51004 +$(obj)/grsec_hidesym.o:
51005 + @-chmod -f 500 /boot
51006 + @-chmod -f 500 /lib/modules
51007 + @-chmod -f 500 /lib64/modules
51008 + @-chmod -f 500 /lib32/modules
51009 + @-chmod -f 700 .
51010 + @echo ' grsec: protected kernel image paths'
51011 +endif
51012 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51013 new file mode 100644
51014 index 0000000..1561617
51015 --- /dev/null
51016 +++ b/grsecurity/gracl.c
51017 @@ -0,0 +1,4017 @@
51018 +#include <linux/kernel.h>
51019 +#include <linux/module.h>
51020 +#include <linux/sched.h>
51021 +#include <linux/mm.h>
51022 +#include <linux/file.h>
51023 +#include <linux/fs.h>
51024 +#include <linux/namei.h>
51025 +#include <linux/mount.h>
51026 +#include <linux/tty.h>
51027 +#include <linux/proc_fs.h>
51028 +#include <linux/lglock.h>
51029 +#include <linux/slab.h>
51030 +#include <linux/vmalloc.h>
51031 +#include <linux/types.h>
51032 +#include <linux/sysctl.h>
51033 +#include <linux/netdevice.h>
51034 +#include <linux/ptrace.h>
51035 +#include <linux/gracl.h>
51036 +#include <linux/gralloc.h>
51037 +#include <linux/security.h>
51038 +#include <linux/grinternal.h>
51039 +#include <linux/pid_namespace.h>
51040 +#include <linux/stop_machine.h>
51041 +#include <linux/fdtable.h>
51042 +#include <linux/percpu.h>
51043 +#include <linux/lglock.h>
51044 +#include "../fs/mount.h"
51045 +
51046 +#include <asm/uaccess.h>
51047 +#include <asm/errno.h>
51048 +#include <asm/mman.h>
51049 +
51050 +extern struct lglock vfsmount_lock;
51051 +
51052 +static struct acl_role_db acl_role_set;
51053 +static struct name_db name_set;
51054 +static struct inodev_db inodev_set;
51055 +
51056 +/* for keeping track of userspace pointers used for subjects, so we
51057 + can share references in the kernel as well
51058 +*/
51059 +
51060 +static struct path real_root;
51061 +
51062 +static struct acl_subj_map_db subj_map_set;
51063 +
51064 +static struct acl_role_label *default_role;
51065 +
51066 +static struct acl_role_label *role_list;
51067 +
51068 +static u16 acl_sp_role_value;
51069 +
51070 +extern char *gr_shared_page[4];
51071 +static DEFINE_MUTEX(gr_dev_mutex);
51072 +DEFINE_RWLOCK(gr_inode_lock);
51073 +
51074 +struct gr_arg *gr_usermode;
51075 +
51076 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51077 +
51078 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51079 +extern void gr_clear_learn_entries(void);
51080 +
51081 +#ifdef CONFIG_GRKERNSEC_RESLOG
51082 +extern void gr_log_resource(const struct task_struct *task,
51083 + const int res, const unsigned long wanted, const int gt);
51084 +#endif
51085 +
51086 +unsigned char *gr_system_salt;
51087 +unsigned char *gr_system_sum;
51088 +
51089 +static struct sprole_pw **acl_special_roles = NULL;
51090 +static __u16 num_sprole_pws = 0;
51091 +
51092 +static struct acl_role_label *kernel_role = NULL;
51093 +
51094 +static unsigned int gr_auth_attempts = 0;
51095 +static unsigned long gr_auth_expires = 0UL;
51096 +
51097 +#ifdef CONFIG_NET
51098 +extern struct vfsmount *sock_mnt;
51099 +#endif
51100 +
51101 +extern struct vfsmount *pipe_mnt;
51102 +extern struct vfsmount *shm_mnt;
51103 +#ifdef CONFIG_HUGETLBFS
51104 +extern struct vfsmount *hugetlbfs_vfsmount;
51105 +#endif
51106 +
51107 +static struct acl_object_label *fakefs_obj_rw;
51108 +static struct acl_object_label *fakefs_obj_rwx;
51109 +
51110 +extern int gr_init_uidset(void);
51111 +extern void gr_free_uidset(void);
51112 +extern void gr_remove_uid(uid_t uid);
51113 +extern int gr_find_uid(uid_t uid);
51114 +
51115 +__inline__ int
51116 +gr_acl_is_enabled(void)
51117 +{
51118 + return (gr_status & GR_READY);
51119 +}
51120 +
51121 +#ifdef CONFIG_BTRFS_FS
51122 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51123 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51124 +#endif
51125 +
51126 +static inline dev_t __get_dev(const struct dentry *dentry)
51127 +{
51128 +#ifdef CONFIG_BTRFS_FS
51129 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51130 + return get_btrfs_dev_from_inode(dentry->d_inode);
51131 + else
51132 +#endif
51133 + return dentry->d_inode->i_sb->s_dev;
51134 +}
51135 +
51136 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51137 +{
51138 + return __get_dev(dentry);
51139 +}
51140 +
51141 +static char gr_task_roletype_to_char(struct task_struct *task)
51142 +{
51143 + switch (task->role->roletype &
51144 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51145 + GR_ROLE_SPECIAL)) {
51146 + case GR_ROLE_DEFAULT:
51147 + return 'D';
51148 + case GR_ROLE_USER:
51149 + return 'U';
51150 + case GR_ROLE_GROUP:
51151 + return 'G';
51152 + case GR_ROLE_SPECIAL:
51153 + return 'S';
51154 + }
51155 +
51156 + return 'X';
51157 +}
51158 +
51159 +char gr_roletype_to_char(void)
51160 +{
51161 + return gr_task_roletype_to_char(current);
51162 +}
51163 +
51164 +__inline__ int
51165 +gr_acl_tpe_check(void)
51166 +{
51167 + if (unlikely(!(gr_status & GR_READY)))
51168 + return 0;
51169 + if (current->role->roletype & GR_ROLE_TPE)
51170 + return 1;
51171 + else
51172 + return 0;
51173 +}
51174 +
51175 +int
51176 +gr_handle_rawio(const struct inode *inode)
51177 +{
51178 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51179 + if (inode && S_ISBLK(inode->i_mode) &&
51180 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51181 + !capable(CAP_SYS_RAWIO))
51182 + return 1;
51183 +#endif
51184 + return 0;
51185 +}
51186 +
51187 +static int
51188 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51189 +{
51190 + if (likely(lena != lenb))
51191 + return 0;
51192 +
51193 + return !memcmp(a, b, lena);
51194 +}
51195 +
51196 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51197 +{
51198 + *buflen -= namelen;
51199 + if (*buflen < 0)
51200 + return -ENAMETOOLONG;
51201 + *buffer -= namelen;
51202 + memcpy(*buffer, str, namelen);
51203 + return 0;
51204 +}
51205 +
51206 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51207 +{
51208 + return prepend(buffer, buflen, name->name, name->len);
51209 +}
51210 +
51211 +static int prepend_path(const struct path *path, struct path *root,
51212 + char **buffer, int *buflen)
51213 +{
51214 + struct dentry *dentry = path->dentry;
51215 + struct vfsmount *vfsmnt = path->mnt;
51216 + struct mount *mnt = real_mount(vfsmnt);
51217 + bool slash = false;
51218 + int error = 0;
51219 +
51220 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51221 + struct dentry * parent;
51222 +
51223 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51224 + /* Global root? */
51225 + if (!mnt_has_parent(mnt)) {
51226 + goto out;
51227 + }
51228 + dentry = mnt->mnt_mountpoint;
51229 + mnt = mnt->mnt_parent;
51230 + vfsmnt = &mnt->mnt;
51231 + continue;
51232 + }
51233 + parent = dentry->d_parent;
51234 + prefetch(parent);
51235 + spin_lock(&dentry->d_lock);
51236 + error = prepend_name(buffer, buflen, &dentry->d_name);
51237 + spin_unlock(&dentry->d_lock);
51238 + if (!error)
51239 + error = prepend(buffer, buflen, "/", 1);
51240 + if (error)
51241 + break;
51242 +
51243 + slash = true;
51244 + dentry = parent;
51245 + }
51246 +
51247 +out:
51248 + if (!error && !slash)
51249 + error = prepend(buffer, buflen, "/", 1);
51250 +
51251 + return error;
51252 +}
51253 +
51254 +/* this must be called with vfsmount_lock and rename_lock held */
51255 +
51256 +static char *__our_d_path(const struct path *path, struct path *root,
51257 + char *buf, int buflen)
51258 +{
51259 + char *res = buf + buflen;
51260 + int error;
51261 +
51262 + prepend(&res, &buflen, "\0", 1);
51263 + error = prepend_path(path, root, &res, &buflen);
51264 + if (error)
51265 + return ERR_PTR(error);
51266 +
51267 + return res;
51268 +}
51269 +
51270 +static char *
51271 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51272 +{
51273 + char *retval;
51274 +
51275 + retval = __our_d_path(path, root, buf, buflen);
51276 + if (unlikely(IS_ERR(retval)))
51277 + retval = strcpy(buf, "<path too long>");
51278 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51279 + retval[1] = '\0';
51280 +
51281 + return retval;
51282 +}
51283 +
51284 +static char *
51285 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51286 + char *buf, int buflen)
51287 +{
51288 + struct path path;
51289 + char *res;
51290 +
51291 + path.dentry = (struct dentry *)dentry;
51292 + path.mnt = (struct vfsmount *)vfsmnt;
51293 +
51294 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51295 + by the RBAC system */
51296 + res = gen_full_path(&path, &real_root, buf, buflen);
51297 +
51298 + return res;
51299 +}
51300 +
51301 +static char *
51302 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51303 + char *buf, int buflen)
51304 +{
51305 + char *res;
51306 + struct path path;
51307 + struct path root;
51308 + struct task_struct *reaper = init_pid_ns.child_reaper;
51309 +
51310 + path.dentry = (struct dentry *)dentry;
51311 + path.mnt = (struct vfsmount *)vfsmnt;
51312 +
51313 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51314 + get_fs_root(reaper->fs, &root);
51315 +
51316 + write_seqlock(&rename_lock);
51317 + br_read_lock(&vfsmount_lock);
51318 + res = gen_full_path(&path, &root, buf, buflen);
51319 + br_read_unlock(&vfsmount_lock);
51320 + write_sequnlock(&rename_lock);
51321 +
51322 + path_put(&root);
51323 + return res;
51324 +}
51325 +
51326 +static char *
51327 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51328 +{
51329 + char *ret;
51330 + write_seqlock(&rename_lock);
51331 + br_read_lock(&vfsmount_lock);
51332 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51333 + PAGE_SIZE);
51334 + br_read_unlock(&vfsmount_lock);
51335 + write_sequnlock(&rename_lock);
51336 + return ret;
51337 +}
51338 +
51339 +static char *
51340 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51341 +{
51342 + char *ret;
51343 + char *buf;
51344 + int buflen;
51345 +
51346 + write_seqlock(&rename_lock);
51347 + br_read_lock(&vfsmount_lock);
51348 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51349 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51350 + buflen = (int)(ret - buf);
51351 + if (buflen >= 5)
51352 + prepend(&ret, &buflen, "/proc", 5);
51353 + else
51354 + ret = strcpy(buf, "<path too long>");
51355 + br_read_unlock(&vfsmount_lock);
51356 + write_sequnlock(&rename_lock);
51357 + return ret;
51358 +}
51359 +
51360 +char *
51361 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51362 +{
51363 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51364 + PAGE_SIZE);
51365 +}
51366 +
51367 +char *
51368 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51369 +{
51370 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51371 + PAGE_SIZE);
51372 +}
51373 +
51374 +char *
51375 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51376 +{
51377 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51378 + PAGE_SIZE);
51379 +}
51380 +
51381 +char *
51382 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51383 +{
51384 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51385 + PAGE_SIZE);
51386 +}
51387 +
51388 +char *
51389 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51390 +{
51391 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51392 + PAGE_SIZE);
51393 +}
51394 +
51395 +__inline__ __u32
51396 +to_gr_audit(const __u32 reqmode)
51397 +{
51398 + /* masks off auditable permission flags, then shifts them to create
51399 + auditing flags, and adds the special case of append auditing if
51400 + we're requesting write */
51401 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51402 +}
51403 +
51404 +struct acl_subject_label *
51405 +lookup_subject_map(const struct acl_subject_label *userp)
51406 +{
51407 + unsigned int index = shash(userp, subj_map_set.s_size);
51408 + struct subject_map *match;
51409 +
51410 + match = subj_map_set.s_hash[index];
51411 +
51412 + while (match && match->user != userp)
51413 + match = match->next;
51414 +
51415 + if (match != NULL)
51416 + return match->kernel;
51417 + else
51418 + return NULL;
51419 +}
51420 +
51421 +static void
51422 +insert_subj_map_entry(struct subject_map *subjmap)
51423 +{
51424 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51425 + struct subject_map **curr;
51426 +
51427 + subjmap->prev = NULL;
51428 +
51429 + curr = &subj_map_set.s_hash[index];
51430 + if (*curr != NULL)
51431 + (*curr)->prev = subjmap;
51432 +
51433 + subjmap->next = *curr;
51434 + *curr = subjmap;
51435 +
51436 + return;
51437 +}
51438 +
51439 +static struct acl_role_label *
51440 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51441 + const gid_t gid)
51442 +{
51443 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51444 + struct acl_role_label *match;
51445 + struct role_allowed_ip *ipp;
51446 + unsigned int x;
51447 + u32 curr_ip = task->signal->curr_ip;
51448 +
51449 + task->signal->saved_ip = curr_ip;
51450 +
51451 + match = acl_role_set.r_hash[index];
51452 +
51453 + while (match) {
51454 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51455 + for (x = 0; x < match->domain_child_num; x++) {
51456 + if (match->domain_children[x] == uid)
51457 + goto found;
51458 + }
51459 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51460 + break;
51461 + match = match->next;
51462 + }
51463 +found:
51464 + if (match == NULL) {
51465 + try_group:
51466 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51467 + match = acl_role_set.r_hash[index];
51468 +
51469 + while (match) {
51470 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51471 + for (x = 0; x < match->domain_child_num; x++) {
51472 + if (match->domain_children[x] == gid)
51473 + goto found2;
51474 + }
51475 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51476 + break;
51477 + match = match->next;
51478 + }
51479 +found2:
51480 + if (match == NULL)
51481 + match = default_role;
51482 + if (match->allowed_ips == NULL)
51483 + return match;
51484 + else {
51485 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51486 + if (likely
51487 + ((ntohl(curr_ip) & ipp->netmask) ==
51488 + (ntohl(ipp->addr) & ipp->netmask)))
51489 + return match;
51490 + }
51491 + match = default_role;
51492 + }
51493 + } else if (match->allowed_ips == NULL) {
51494 + return match;
51495 + } else {
51496 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51497 + if (likely
51498 + ((ntohl(curr_ip) & ipp->netmask) ==
51499 + (ntohl(ipp->addr) & ipp->netmask)))
51500 + return match;
51501 + }
51502 + goto try_group;
51503 + }
51504 +
51505 + return match;
51506 +}
51507 +
51508 +struct acl_subject_label *
51509 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51510 + const struct acl_role_label *role)
51511 +{
51512 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51513 + struct acl_subject_label *match;
51514 +
51515 + match = role->subj_hash[index];
51516 +
51517 + while (match && (match->inode != ino || match->device != dev ||
51518 + (match->mode & GR_DELETED))) {
51519 + match = match->next;
51520 + }
51521 +
51522 + if (match && !(match->mode & GR_DELETED))
51523 + return match;
51524 + else
51525 + return NULL;
51526 +}
51527 +
51528 +struct acl_subject_label *
51529 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51530 + const struct acl_role_label *role)
51531 +{
51532 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51533 + struct acl_subject_label *match;
51534 +
51535 + match = role->subj_hash[index];
51536 +
51537 + while (match && (match->inode != ino || match->device != dev ||
51538 + !(match->mode & GR_DELETED))) {
51539 + match = match->next;
51540 + }
51541 +
51542 + if (match && (match->mode & GR_DELETED))
51543 + return match;
51544 + else
51545 + return NULL;
51546 +}
51547 +
51548 +static struct acl_object_label *
51549 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51550 + const struct acl_subject_label *subj)
51551 +{
51552 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51553 + struct acl_object_label *match;
51554 +
51555 + match = subj->obj_hash[index];
51556 +
51557 + while (match && (match->inode != ino || match->device != dev ||
51558 + (match->mode & GR_DELETED))) {
51559 + match = match->next;
51560 + }
51561 +
51562 + if (match && !(match->mode & GR_DELETED))
51563 + return match;
51564 + else
51565 + return NULL;
51566 +}
51567 +
51568 +static struct acl_object_label *
51569 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51570 + const struct acl_subject_label *subj)
51571 +{
51572 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51573 + struct acl_object_label *match;
51574 +
51575 + match = subj->obj_hash[index];
51576 +
51577 + while (match && (match->inode != ino || match->device != dev ||
51578 + !(match->mode & GR_DELETED))) {
51579 + match = match->next;
51580 + }
51581 +
51582 + if (match && (match->mode & GR_DELETED))
51583 + return match;
51584 +
51585 + match = subj->obj_hash[index];
51586 +
51587 + while (match && (match->inode != ino || match->device != dev ||
51588 + (match->mode & GR_DELETED))) {
51589 + match = match->next;
51590 + }
51591 +
51592 + if (match && !(match->mode & GR_DELETED))
51593 + return match;
51594 + else
51595 + return NULL;
51596 +}
51597 +
51598 +static struct name_entry *
51599 +lookup_name_entry(const char *name)
51600 +{
51601 + unsigned int len = strlen(name);
51602 + unsigned int key = full_name_hash(name, len);
51603 + unsigned int index = key % name_set.n_size;
51604 + struct name_entry *match;
51605 +
51606 + match = name_set.n_hash[index];
51607 +
51608 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51609 + match = match->next;
51610 +
51611 + return match;
51612 +}
51613 +
51614 +static struct name_entry *
51615 +lookup_name_entry_create(const char *name)
51616 +{
51617 + unsigned int len = strlen(name);
51618 + unsigned int key = full_name_hash(name, len);
51619 + unsigned int index = key % name_set.n_size;
51620 + struct name_entry *match;
51621 +
51622 + match = name_set.n_hash[index];
51623 +
51624 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51625 + !match->deleted))
51626 + match = match->next;
51627 +
51628 + if (match && match->deleted)
51629 + return match;
51630 +
51631 + match = name_set.n_hash[index];
51632 +
51633 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51634 + match->deleted))
51635 + match = match->next;
51636 +
51637 + if (match && !match->deleted)
51638 + return match;
51639 + else
51640 + return NULL;
51641 +}
51642 +
51643 +static struct inodev_entry *
51644 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
51645 +{
51646 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
51647 + struct inodev_entry *match;
51648 +
51649 + match = inodev_set.i_hash[index];
51650 +
51651 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51652 + match = match->next;
51653 +
51654 + return match;
51655 +}
51656 +
51657 +static void
51658 +insert_inodev_entry(struct inodev_entry *entry)
51659 +{
51660 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51661 + inodev_set.i_size);
51662 + struct inodev_entry **curr;
51663 +
51664 + entry->prev = NULL;
51665 +
51666 + curr = &inodev_set.i_hash[index];
51667 + if (*curr != NULL)
51668 + (*curr)->prev = entry;
51669 +
51670 + entry->next = *curr;
51671 + *curr = entry;
51672 +
51673 + return;
51674 +}
51675 +
51676 +static void
51677 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51678 +{
51679 + unsigned int index =
51680 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51681 + struct acl_role_label **curr;
51682 + struct acl_role_label *tmp, *tmp2;
51683 +
51684 + curr = &acl_role_set.r_hash[index];
51685 +
51686 + /* simple case, slot is empty, just set it to our role */
51687 + if (*curr == NULL) {
51688 + *curr = role;
51689 + } else {
51690 + /* example:
51691 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
51692 + 2 -> 3
51693 + */
51694 + /* first check to see if we can already be reached via this slot */
51695 + tmp = *curr;
51696 + while (tmp && tmp != role)
51697 + tmp = tmp->next;
51698 + if (tmp == role) {
51699 + /* we don't need to add ourselves to this slot's chain */
51700 + return;
51701 + }
51702 + /* we need to add ourselves to this chain, two cases */
51703 + if (role->next == NULL) {
51704 + /* simple case, append the current chain to our role */
51705 + role->next = *curr;
51706 + *curr = role;
51707 + } else {
51708 + /* 1 -> 2 -> 3 -> 4
51709 + 2 -> 3 -> 4
51710 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51711 + */
51712 + /* trickier case: walk our role's chain until we find
51713 + the role for the start of the current slot's chain */
51714 + tmp = role;
51715 + tmp2 = *curr;
51716 + while (tmp->next && tmp->next != tmp2)
51717 + tmp = tmp->next;
51718 + if (tmp->next == tmp2) {
51719 + /* from example above, we found 3, so just
51720 + replace this slot's chain with ours */
51721 + *curr = role;
51722 + } else {
51723 + /* we didn't find a subset of our role's chain
51724 + in the current slot's chain, so append their
51725 + chain to ours, and set us as the first role in
51726 + the slot's chain
51727 +
51728 + we could fold this case with the case above,
51729 + but making it explicit for clarity
51730 + */
51731 + tmp->next = tmp2;
51732 + *curr = role;
51733 + }
51734 + }
51735 + }
51736 +
51737 + return;
51738 +}
51739 +
51740 +static void
51741 +insert_acl_role_label(struct acl_role_label *role)
51742 +{
51743 + int i;
51744 +
51745 + if (role_list == NULL) {
51746 + role_list = role;
51747 + role->prev = NULL;
51748 + } else {
51749 + role->prev = role_list;
51750 + role_list = role;
51751 + }
51752 +
51753 + /* used for hash chains */
51754 + role->next = NULL;
51755 +
51756 + if (role->roletype & GR_ROLE_DOMAIN) {
51757 + for (i = 0; i < role->domain_child_num; i++)
51758 + __insert_acl_role_label(role, role->domain_children[i]);
51759 + } else
51760 + __insert_acl_role_label(role, role->uidgid);
51761 +}
51762 +
51763 +static int
51764 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51765 +{
51766 + struct name_entry **curr, *nentry;
51767 + struct inodev_entry *ientry;
51768 + unsigned int len = strlen(name);
51769 + unsigned int key = full_name_hash(name, len);
51770 + unsigned int index = key % name_set.n_size;
51771 +
51772 + curr = &name_set.n_hash[index];
51773 +
51774 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51775 + curr = &((*curr)->next);
51776 +
51777 + if (*curr != NULL)
51778 + return 1;
51779 +
51780 + nentry = acl_alloc(sizeof (struct name_entry));
51781 + if (nentry == NULL)
51782 + return 0;
51783 + ientry = acl_alloc(sizeof (struct inodev_entry));
51784 + if (ientry == NULL)
51785 + return 0;
51786 + ientry->nentry = nentry;
51787 +
51788 + nentry->key = key;
51789 + nentry->name = name;
51790 + nentry->inode = inode;
51791 + nentry->device = device;
51792 + nentry->len = len;
51793 + nentry->deleted = deleted;
51794 +
51795 + nentry->prev = NULL;
51796 + curr = &name_set.n_hash[index];
51797 + if (*curr != NULL)
51798 + (*curr)->prev = nentry;
51799 + nentry->next = *curr;
51800 + *curr = nentry;
51801 +
51802 + /* insert us into the table searchable by inode/dev */
51803 + insert_inodev_entry(ientry);
51804 +
51805 + return 1;
51806 +}
51807 +
51808 +static void
51809 +insert_acl_obj_label(struct acl_object_label *obj,
51810 + struct acl_subject_label *subj)
51811 +{
51812 + unsigned int index =
51813 + fhash(obj->inode, obj->device, subj->obj_hash_size);
51814 + struct acl_object_label **curr;
51815 +
51816 +
51817 + obj->prev = NULL;
51818 +
51819 + curr = &subj->obj_hash[index];
51820 + if (*curr != NULL)
51821 + (*curr)->prev = obj;
51822 +
51823 + obj->next = *curr;
51824 + *curr = obj;
51825 +
51826 + return;
51827 +}
51828 +
51829 +static void
51830 +insert_acl_subj_label(struct acl_subject_label *obj,
51831 + struct acl_role_label *role)
51832 +{
51833 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51834 + struct acl_subject_label **curr;
51835 +
51836 + obj->prev = NULL;
51837 +
51838 + curr = &role->subj_hash[index];
51839 + if (*curr != NULL)
51840 + (*curr)->prev = obj;
51841 +
51842 + obj->next = *curr;
51843 + *curr = obj;
51844 +
51845 + return;
51846 +}
51847 +
51848 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51849 +
51850 +static void *
51851 +create_table(__u32 * len, int elementsize)
51852 +{
51853 + unsigned int table_sizes[] = {
51854 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51855 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51856 + 4194301, 8388593, 16777213, 33554393, 67108859
51857 + };
51858 + void *newtable = NULL;
51859 + unsigned int pwr = 0;
51860 +
51861 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51862 + table_sizes[pwr] <= *len)
51863 + pwr++;
51864 +
51865 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51866 + return newtable;
51867 +
51868 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51869 + newtable =
51870 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51871 + else
51872 + newtable = vmalloc(table_sizes[pwr] * elementsize);
51873 +
51874 + *len = table_sizes[pwr];
51875 +
51876 + return newtable;
51877 +}
51878 +
51879 +static int
51880 +init_variables(const struct gr_arg *arg)
51881 +{
51882 + struct task_struct *reaper = init_pid_ns.child_reaper;
51883 + unsigned int stacksize;
51884 +
51885 + subj_map_set.s_size = arg->role_db.num_subjects;
51886 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51887 + name_set.n_size = arg->role_db.num_objects;
51888 + inodev_set.i_size = arg->role_db.num_objects;
51889 +
51890 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
51891 + !name_set.n_size || !inodev_set.i_size)
51892 + return 1;
51893 +
51894 + if (!gr_init_uidset())
51895 + return 1;
51896 +
51897 + /* set up the stack that holds allocation info */
51898 +
51899 + stacksize = arg->role_db.num_pointers + 5;
51900 +
51901 + if (!acl_alloc_stack_init(stacksize))
51902 + return 1;
51903 +
51904 + /* grab reference for the real root dentry and vfsmount */
51905 + get_fs_root(reaper->fs, &real_root);
51906 +
51907 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51908 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51909 +#endif
51910 +
51911 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51912 + if (fakefs_obj_rw == NULL)
51913 + return 1;
51914 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51915 +
51916 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51917 + if (fakefs_obj_rwx == NULL)
51918 + return 1;
51919 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51920 +
51921 + subj_map_set.s_hash =
51922 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51923 + acl_role_set.r_hash =
51924 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51925 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51926 + inodev_set.i_hash =
51927 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51928 +
51929 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51930 + !name_set.n_hash || !inodev_set.i_hash)
51931 + return 1;
51932 +
51933 + memset(subj_map_set.s_hash, 0,
51934 + sizeof(struct subject_map *) * subj_map_set.s_size);
51935 + memset(acl_role_set.r_hash, 0,
51936 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
51937 + memset(name_set.n_hash, 0,
51938 + sizeof (struct name_entry *) * name_set.n_size);
51939 + memset(inodev_set.i_hash, 0,
51940 + sizeof (struct inodev_entry *) * inodev_set.i_size);
51941 +
51942 + return 0;
51943 +}
51944 +
51945 +/* free information not needed after startup
51946 + currently contains user->kernel pointer mappings for subjects
51947 +*/
51948 +
51949 +static void
51950 +free_init_variables(void)
51951 +{
51952 + __u32 i;
51953 +
51954 + if (subj_map_set.s_hash) {
51955 + for (i = 0; i < subj_map_set.s_size; i++) {
51956 + if (subj_map_set.s_hash[i]) {
51957 + kfree(subj_map_set.s_hash[i]);
51958 + subj_map_set.s_hash[i] = NULL;
51959 + }
51960 + }
51961 +
51962 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51963 + PAGE_SIZE)
51964 + kfree(subj_map_set.s_hash);
51965 + else
51966 + vfree(subj_map_set.s_hash);
51967 + }
51968 +
51969 + return;
51970 +}
51971 +
51972 +static void
51973 +free_variables(void)
51974 +{
51975 + struct acl_subject_label *s;
51976 + struct acl_role_label *r;
51977 + struct task_struct *task, *task2;
51978 + unsigned int x;
51979 +
51980 + gr_clear_learn_entries();
51981 +
51982 + read_lock(&tasklist_lock);
51983 + do_each_thread(task2, task) {
51984 + task->acl_sp_role = 0;
51985 + task->acl_role_id = 0;
51986 + task->acl = NULL;
51987 + task->role = NULL;
51988 + } while_each_thread(task2, task);
51989 + read_unlock(&tasklist_lock);
51990 +
51991 + /* release the reference to the real root dentry and vfsmount */
51992 + path_put(&real_root);
51993 + memset(&real_root, 0, sizeof(real_root));
51994 +
51995 + /* free all object hash tables */
51996 +
51997 + FOR_EACH_ROLE_START(r)
51998 + if (r->subj_hash == NULL)
51999 + goto next_role;
52000 + FOR_EACH_SUBJECT_START(r, s, x)
52001 + if (s->obj_hash == NULL)
52002 + break;
52003 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52004 + kfree(s->obj_hash);
52005 + else
52006 + vfree(s->obj_hash);
52007 + FOR_EACH_SUBJECT_END(s, x)
52008 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52009 + if (s->obj_hash == NULL)
52010 + break;
52011 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52012 + kfree(s->obj_hash);
52013 + else
52014 + vfree(s->obj_hash);
52015 + FOR_EACH_NESTED_SUBJECT_END(s)
52016 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52017 + kfree(r->subj_hash);
52018 + else
52019 + vfree(r->subj_hash);
52020 + r->subj_hash = NULL;
52021 +next_role:
52022 + FOR_EACH_ROLE_END(r)
52023 +
52024 + acl_free_all();
52025 +
52026 + if (acl_role_set.r_hash) {
52027 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52028 + PAGE_SIZE)
52029 + kfree(acl_role_set.r_hash);
52030 + else
52031 + vfree(acl_role_set.r_hash);
52032 + }
52033 + if (name_set.n_hash) {
52034 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52035 + PAGE_SIZE)
52036 + kfree(name_set.n_hash);
52037 + else
52038 + vfree(name_set.n_hash);
52039 + }
52040 +
52041 + if (inodev_set.i_hash) {
52042 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52043 + PAGE_SIZE)
52044 + kfree(inodev_set.i_hash);
52045 + else
52046 + vfree(inodev_set.i_hash);
52047 + }
52048 +
52049 + gr_free_uidset();
52050 +
52051 + memset(&name_set, 0, sizeof (struct name_db));
52052 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52053 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52054 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52055 +
52056 + default_role = NULL;
52057 + kernel_role = NULL;
52058 + role_list = NULL;
52059 +
52060 + return;
52061 +}
52062 +
52063 +static __u32
52064 +count_user_objs(struct acl_object_label *userp)
52065 +{
52066 + struct acl_object_label o_tmp;
52067 + __u32 num = 0;
52068 +
52069 + while (userp) {
52070 + if (copy_from_user(&o_tmp, userp,
52071 + sizeof (struct acl_object_label)))
52072 + break;
52073 +
52074 + userp = o_tmp.prev;
52075 + num++;
52076 + }
52077 +
52078 + return num;
52079 +}
52080 +
52081 +static struct acl_subject_label *
52082 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52083 +
52084 +static int
52085 +copy_user_glob(struct acl_object_label *obj)
52086 +{
52087 + struct acl_object_label *g_tmp, **guser;
52088 + unsigned int len;
52089 + char *tmp;
52090 +
52091 + if (obj->globbed == NULL)
52092 + return 0;
52093 +
52094 + guser = &obj->globbed;
52095 + while (*guser) {
52096 + g_tmp = (struct acl_object_label *)
52097 + acl_alloc(sizeof (struct acl_object_label));
52098 + if (g_tmp == NULL)
52099 + return -ENOMEM;
52100 +
52101 + if (copy_from_user(g_tmp, *guser,
52102 + sizeof (struct acl_object_label)))
52103 + return -EFAULT;
52104 +
52105 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52106 +
52107 + if (!len || len >= PATH_MAX)
52108 + return -EINVAL;
52109 +
52110 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52111 + return -ENOMEM;
52112 +
52113 + if (copy_from_user(tmp, g_tmp->filename, len))
52114 + return -EFAULT;
52115 + tmp[len-1] = '\0';
52116 + g_tmp->filename = tmp;
52117 +
52118 + *guser = g_tmp;
52119 + guser = &(g_tmp->next);
52120 + }
52121 +
52122 + return 0;
52123 +}
52124 +
52125 +static int
52126 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52127 + struct acl_role_label *role)
52128 +{
52129 + struct acl_object_label *o_tmp;
52130 + unsigned int len;
52131 + int ret;
52132 + char *tmp;
52133 +
52134 + while (userp) {
52135 + if ((o_tmp = (struct acl_object_label *)
52136 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52137 + return -ENOMEM;
52138 +
52139 + if (copy_from_user(o_tmp, userp,
52140 + sizeof (struct acl_object_label)))
52141 + return -EFAULT;
52142 +
52143 + userp = o_tmp->prev;
52144 +
52145 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52146 +
52147 + if (!len || len >= PATH_MAX)
52148 + return -EINVAL;
52149 +
52150 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52151 + return -ENOMEM;
52152 +
52153 + if (copy_from_user(tmp, o_tmp->filename, len))
52154 + return -EFAULT;
52155 + tmp[len-1] = '\0';
52156 + o_tmp->filename = tmp;
52157 +
52158 + insert_acl_obj_label(o_tmp, subj);
52159 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52160 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52161 + return -ENOMEM;
52162 +
52163 + ret = copy_user_glob(o_tmp);
52164 + if (ret)
52165 + return ret;
52166 +
52167 + if (o_tmp->nested) {
52168 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52169 + if (IS_ERR(o_tmp->nested))
52170 + return PTR_ERR(o_tmp->nested);
52171 +
52172 + /* insert into nested subject list */
52173 + o_tmp->nested->next = role->hash->first;
52174 + role->hash->first = o_tmp->nested;
52175 + }
52176 + }
52177 +
52178 + return 0;
52179 +}
52180 +
52181 +static __u32
52182 +count_user_subjs(struct acl_subject_label *userp)
52183 +{
52184 + struct acl_subject_label s_tmp;
52185 + __u32 num = 0;
52186 +
52187 + while (userp) {
52188 + if (copy_from_user(&s_tmp, userp,
52189 + sizeof (struct acl_subject_label)))
52190 + break;
52191 +
52192 + userp = s_tmp.prev;
52193 + /* do not count nested subjects against this count, since
52194 + they are not included in the hash table, but are
52195 + attached to objects. We have already counted
52196 + the subjects in userspace for the allocation
52197 + stack
52198 + */
52199 + if (!(s_tmp.mode & GR_NESTED))
52200 + num++;
52201 + }
52202 +
52203 + return num;
52204 +}
52205 +
52206 +static int
52207 +copy_user_allowedips(struct acl_role_label *rolep)
52208 +{
52209 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52210 +
52211 + ruserip = rolep->allowed_ips;
52212 +
52213 + while (ruserip) {
52214 + rlast = rtmp;
52215 +
52216 + if ((rtmp = (struct role_allowed_ip *)
52217 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52218 + return -ENOMEM;
52219 +
52220 + if (copy_from_user(rtmp, ruserip,
52221 + sizeof (struct role_allowed_ip)))
52222 + return -EFAULT;
52223 +
52224 + ruserip = rtmp->prev;
52225 +
52226 + if (!rlast) {
52227 + rtmp->prev = NULL;
52228 + rolep->allowed_ips = rtmp;
52229 + } else {
52230 + rlast->next = rtmp;
52231 + rtmp->prev = rlast;
52232 + }
52233 +
52234 + if (!ruserip)
52235 + rtmp->next = NULL;
52236 + }
52237 +
52238 + return 0;
52239 +}
52240 +
52241 +static int
52242 +copy_user_transitions(struct acl_role_label *rolep)
52243 +{
52244 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52245 +
52246 + unsigned int len;
52247 + char *tmp;
52248 +
52249 + rusertp = rolep->transitions;
52250 +
52251 + while (rusertp) {
52252 + rlast = rtmp;
52253 +
52254 + if ((rtmp = (struct role_transition *)
52255 + acl_alloc(sizeof (struct role_transition))) == NULL)
52256 + return -ENOMEM;
52257 +
52258 + if (copy_from_user(rtmp, rusertp,
52259 + sizeof (struct role_transition)))
52260 + return -EFAULT;
52261 +
52262 + rusertp = rtmp->prev;
52263 +
52264 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52265 +
52266 + if (!len || len >= GR_SPROLE_LEN)
52267 + return -EINVAL;
52268 +
52269 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52270 + return -ENOMEM;
52271 +
52272 + if (copy_from_user(tmp, rtmp->rolename, len))
52273 + return -EFAULT;
52274 + tmp[len-1] = '\0';
52275 + rtmp->rolename = tmp;
52276 +
52277 + if (!rlast) {
52278 + rtmp->prev = NULL;
52279 + rolep->transitions = rtmp;
52280 + } else {
52281 + rlast->next = rtmp;
52282 + rtmp->prev = rlast;
52283 + }
52284 +
52285 + if (!rusertp)
52286 + rtmp->next = NULL;
52287 + }
52288 +
52289 + return 0;
52290 +}
52291 +
52292 +static struct acl_subject_label *
52293 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52294 +{
52295 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52296 + unsigned int len;
52297 + char *tmp;
52298 + __u32 num_objs;
52299 + struct acl_ip_label **i_tmp, *i_utmp2;
52300 + struct gr_hash_struct ghash;
52301 + struct subject_map *subjmap;
52302 + unsigned int i_num;
52303 + int err;
52304 +
52305 + s_tmp = lookup_subject_map(userp);
52306 +
52307 + /* we've already copied this subject into the kernel, just return
52308 + the reference to it, and don't copy it over again
52309 + */
52310 + if (s_tmp)
52311 + return(s_tmp);
52312 +
52313 + if ((s_tmp = (struct acl_subject_label *)
52314 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52315 + return ERR_PTR(-ENOMEM);
52316 +
52317 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52318 + if (subjmap == NULL)
52319 + return ERR_PTR(-ENOMEM);
52320 +
52321 + subjmap->user = userp;
52322 + subjmap->kernel = s_tmp;
52323 + insert_subj_map_entry(subjmap);
52324 +
52325 + if (copy_from_user(s_tmp, userp,
52326 + sizeof (struct acl_subject_label)))
52327 + return ERR_PTR(-EFAULT);
52328 +
52329 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52330 +
52331 + if (!len || len >= PATH_MAX)
52332 + return ERR_PTR(-EINVAL);
52333 +
52334 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52335 + return ERR_PTR(-ENOMEM);
52336 +
52337 + if (copy_from_user(tmp, s_tmp->filename, len))
52338 + return ERR_PTR(-EFAULT);
52339 + tmp[len-1] = '\0';
52340 + s_tmp->filename = tmp;
52341 +
52342 + if (!strcmp(s_tmp->filename, "/"))
52343 + role->root_label = s_tmp;
52344 +
52345 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52346 + return ERR_PTR(-EFAULT);
52347 +
52348 + /* copy user and group transition tables */
52349 +
52350 + if (s_tmp->user_trans_num) {
52351 + uid_t *uidlist;
52352 +
52353 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52354 + if (uidlist == NULL)
52355 + return ERR_PTR(-ENOMEM);
52356 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52357 + return ERR_PTR(-EFAULT);
52358 +
52359 + s_tmp->user_transitions = uidlist;
52360 + }
52361 +
52362 + if (s_tmp->group_trans_num) {
52363 + gid_t *gidlist;
52364 +
52365 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52366 + if (gidlist == NULL)
52367 + return ERR_PTR(-ENOMEM);
52368 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52369 + return ERR_PTR(-EFAULT);
52370 +
52371 + s_tmp->group_transitions = gidlist;
52372 + }
52373 +
52374 + /* set up object hash table */
52375 + num_objs = count_user_objs(ghash.first);
52376 +
52377 + s_tmp->obj_hash_size = num_objs;
52378 + s_tmp->obj_hash =
52379 + (struct acl_object_label **)
52380 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52381 +
52382 + if (!s_tmp->obj_hash)
52383 + return ERR_PTR(-ENOMEM);
52384 +
52385 + memset(s_tmp->obj_hash, 0,
52386 + s_tmp->obj_hash_size *
52387 + sizeof (struct acl_object_label *));
52388 +
52389 + /* add in objects */
52390 + err = copy_user_objs(ghash.first, s_tmp, role);
52391 +
52392 + if (err)
52393 + return ERR_PTR(err);
52394 +
52395 + /* set pointer for parent subject */
52396 + if (s_tmp->parent_subject) {
52397 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52398 +
52399 + if (IS_ERR(s_tmp2))
52400 + return s_tmp2;
52401 +
52402 + s_tmp->parent_subject = s_tmp2;
52403 + }
52404 +
52405 + /* add in ip acls */
52406 +
52407 + if (!s_tmp->ip_num) {
52408 + s_tmp->ips = NULL;
52409 + goto insert;
52410 + }
52411 +
52412 + i_tmp =
52413 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52414 + sizeof (struct acl_ip_label *));
52415 +
52416 + if (!i_tmp)
52417 + return ERR_PTR(-ENOMEM);
52418 +
52419 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52420 + *(i_tmp + i_num) =
52421 + (struct acl_ip_label *)
52422 + acl_alloc(sizeof (struct acl_ip_label));
52423 + if (!*(i_tmp + i_num))
52424 + return ERR_PTR(-ENOMEM);
52425 +
52426 + if (copy_from_user
52427 + (&i_utmp2, s_tmp->ips + i_num,
52428 + sizeof (struct acl_ip_label *)))
52429 + return ERR_PTR(-EFAULT);
52430 +
52431 + if (copy_from_user
52432 + (*(i_tmp + i_num), i_utmp2,
52433 + sizeof (struct acl_ip_label)))
52434 + return ERR_PTR(-EFAULT);
52435 +
52436 + if ((*(i_tmp + i_num))->iface == NULL)
52437 + continue;
52438 +
52439 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52440 + if (!len || len >= IFNAMSIZ)
52441 + return ERR_PTR(-EINVAL);
52442 + tmp = acl_alloc(len);
52443 + if (tmp == NULL)
52444 + return ERR_PTR(-ENOMEM);
52445 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52446 + return ERR_PTR(-EFAULT);
52447 + (*(i_tmp + i_num))->iface = tmp;
52448 + }
52449 +
52450 + s_tmp->ips = i_tmp;
52451 +
52452 +insert:
52453 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52454 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52455 + return ERR_PTR(-ENOMEM);
52456 +
52457 + return s_tmp;
52458 +}
52459 +
52460 +static int
52461 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52462 +{
52463 + struct acl_subject_label s_pre;
52464 + struct acl_subject_label * ret;
52465 + int err;
52466 +
52467 + while (userp) {
52468 + if (copy_from_user(&s_pre, userp,
52469 + sizeof (struct acl_subject_label)))
52470 + return -EFAULT;
52471 +
52472 + /* do not add nested subjects here, add
52473 + while parsing objects
52474 + */
52475 +
52476 + if (s_pre.mode & GR_NESTED) {
52477 + userp = s_pre.prev;
52478 + continue;
52479 + }
52480 +
52481 + ret = do_copy_user_subj(userp, role);
52482 +
52483 + err = PTR_ERR(ret);
52484 + if (IS_ERR(ret))
52485 + return err;
52486 +
52487 + insert_acl_subj_label(ret, role);
52488 +
52489 + userp = s_pre.prev;
52490 + }
52491 +
52492 + return 0;
52493 +}
52494 +
52495 +static int
52496 +copy_user_acl(struct gr_arg *arg)
52497 +{
52498 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52499 + struct sprole_pw *sptmp;
52500 + struct gr_hash_struct *ghash;
52501 + uid_t *domainlist;
52502 + unsigned int r_num;
52503 + unsigned int len;
52504 + char *tmp;
52505 + int err = 0;
52506 + __u16 i;
52507 + __u32 num_subjs;
52508 +
52509 + /* we need a default and kernel role */
52510 + if (arg->role_db.num_roles < 2)
52511 + return -EINVAL;
52512 +
52513 + /* copy special role authentication info from userspace */
52514 +
52515 + num_sprole_pws = arg->num_sprole_pws;
52516 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52517 +
52518 + if (!acl_special_roles && num_sprole_pws)
52519 + return -ENOMEM;
52520 +
52521 + for (i = 0; i < num_sprole_pws; i++) {
52522 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52523 + if (!sptmp)
52524 + return -ENOMEM;
52525 + if (copy_from_user(sptmp, arg->sprole_pws + i,
52526 + sizeof (struct sprole_pw)))
52527 + return -EFAULT;
52528 +
52529 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52530 +
52531 + if (!len || len >= GR_SPROLE_LEN)
52532 + return -EINVAL;
52533 +
52534 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52535 + return -ENOMEM;
52536 +
52537 + if (copy_from_user(tmp, sptmp->rolename, len))
52538 + return -EFAULT;
52539 +
52540 + tmp[len-1] = '\0';
52541 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52542 + printk(KERN_ALERT "Copying special role %s\n", tmp);
52543 +#endif
52544 + sptmp->rolename = tmp;
52545 + acl_special_roles[i] = sptmp;
52546 + }
52547 +
52548 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52549 +
52550 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52551 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
52552 +
52553 + if (!r_tmp)
52554 + return -ENOMEM;
52555 +
52556 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
52557 + sizeof (struct acl_role_label *)))
52558 + return -EFAULT;
52559 +
52560 + if (copy_from_user(r_tmp, r_utmp2,
52561 + sizeof (struct acl_role_label)))
52562 + return -EFAULT;
52563 +
52564 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52565 +
52566 + if (!len || len >= PATH_MAX)
52567 + return -EINVAL;
52568 +
52569 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52570 + return -ENOMEM;
52571 +
52572 + if (copy_from_user(tmp, r_tmp->rolename, len))
52573 + return -EFAULT;
52574 +
52575 + tmp[len-1] = '\0';
52576 + r_tmp->rolename = tmp;
52577 +
52578 + if (!strcmp(r_tmp->rolename, "default")
52579 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52580 + default_role = r_tmp;
52581 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52582 + kernel_role = r_tmp;
52583 + }
52584 +
52585 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52586 + return -ENOMEM;
52587 +
52588 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52589 + return -EFAULT;
52590 +
52591 + r_tmp->hash = ghash;
52592 +
52593 + num_subjs = count_user_subjs(r_tmp->hash->first);
52594 +
52595 + r_tmp->subj_hash_size = num_subjs;
52596 + r_tmp->subj_hash =
52597 + (struct acl_subject_label **)
52598 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52599 +
52600 + if (!r_tmp->subj_hash)
52601 + return -ENOMEM;
52602 +
52603 + err = copy_user_allowedips(r_tmp);
52604 + if (err)
52605 + return err;
52606 +
52607 + /* copy domain info */
52608 + if (r_tmp->domain_children != NULL) {
52609 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52610 + if (domainlist == NULL)
52611 + return -ENOMEM;
52612 +
52613 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52614 + return -EFAULT;
52615 +
52616 + r_tmp->domain_children = domainlist;
52617 + }
52618 +
52619 + err = copy_user_transitions(r_tmp);
52620 + if (err)
52621 + return err;
52622 +
52623 + memset(r_tmp->subj_hash, 0,
52624 + r_tmp->subj_hash_size *
52625 + sizeof (struct acl_subject_label *));
52626 +
52627 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52628 +
52629 + if (err)
52630 + return err;
52631 +
52632 + /* set nested subject list to null */
52633 + r_tmp->hash->first = NULL;
52634 +
52635 + insert_acl_role_label(r_tmp);
52636 + }
52637 +
52638 + if (default_role == NULL || kernel_role == NULL)
52639 + return -EINVAL;
52640 +
52641 + return err;
52642 +}
52643 +
52644 +static int
52645 +gracl_init(struct gr_arg *args)
52646 +{
52647 + int error = 0;
52648 +
52649 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52650 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52651 +
52652 + if (init_variables(args)) {
52653 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52654 + error = -ENOMEM;
52655 + free_variables();
52656 + goto out;
52657 + }
52658 +
52659 + error = copy_user_acl(args);
52660 + free_init_variables();
52661 + if (error) {
52662 + free_variables();
52663 + goto out;
52664 + }
52665 +
52666 + if ((error = gr_set_acls(0))) {
52667 + free_variables();
52668 + goto out;
52669 + }
52670 +
52671 + pax_open_kernel();
52672 + gr_status |= GR_READY;
52673 + pax_close_kernel();
52674 +
52675 + out:
52676 + return error;
52677 +}
52678 +
52679 +/* derived from glibc fnmatch() 0: match, 1: no match*/
52680 +
52681 +static int
52682 +glob_match(const char *p, const char *n)
52683 +{
52684 + char c;
52685 +
52686 + while ((c = *p++) != '\0') {
52687 + switch (c) {
52688 + case '?':
52689 + if (*n == '\0')
52690 + return 1;
52691 + else if (*n == '/')
52692 + return 1;
52693 + break;
52694 + case '\\':
52695 + if (*n != c)
52696 + return 1;
52697 + break;
52698 + case '*':
52699 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
52700 + if (*n == '/')
52701 + return 1;
52702 + else if (c == '?') {
52703 + if (*n == '\0')
52704 + return 1;
52705 + else
52706 + ++n;
52707 + }
52708 + }
52709 + if (c == '\0') {
52710 + return 0;
52711 + } else {
52712 + const char *endp;
52713 +
52714 + if ((endp = strchr(n, '/')) == NULL)
52715 + endp = n + strlen(n);
52716 +
52717 + if (c == '[') {
52718 + for (--p; n < endp; ++n)
52719 + if (!glob_match(p, n))
52720 + return 0;
52721 + } else if (c == '/') {
52722 + while (*n != '\0' && *n != '/')
52723 + ++n;
52724 + if (*n == '/' && !glob_match(p, n + 1))
52725 + return 0;
52726 + } else {
52727 + for (--p; n < endp; ++n)
52728 + if (*n == c && !glob_match(p, n))
52729 + return 0;
52730 + }
52731 +
52732 + return 1;
52733 + }
52734 + case '[':
52735 + {
52736 + int not;
52737 + char cold;
52738 +
52739 + if (*n == '\0' || *n == '/')
52740 + return 1;
52741 +
52742 + not = (*p == '!' || *p == '^');
52743 + if (not)
52744 + ++p;
52745 +
52746 + c = *p++;
52747 + for (;;) {
52748 + unsigned char fn = (unsigned char)*n;
52749 +
52750 + if (c == '\0')
52751 + return 1;
52752 + else {
52753 + if (c == fn)
52754 + goto matched;
52755 + cold = c;
52756 + c = *p++;
52757 +
52758 + if (c == '-' && *p != ']') {
52759 + unsigned char cend = *p++;
52760 +
52761 + if (cend == '\0')
52762 + return 1;
52763 +
52764 + if (cold <= fn && fn <= cend)
52765 + goto matched;
52766 +
52767 + c = *p++;
52768 + }
52769 + }
52770 +
52771 + if (c == ']')
52772 + break;
52773 + }
52774 + if (!not)
52775 + return 1;
52776 + break;
52777 + matched:
52778 + while (c != ']') {
52779 + if (c == '\0')
52780 + return 1;
52781 +
52782 + c = *p++;
52783 + }
52784 + if (not)
52785 + return 1;
52786 + }
52787 + break;
52788 + default:
52789 + if (c != *n)
52790 + return 1;
52791 + }
52792 +
52793 + ++n;
52794 + }
52795 +
52796 + if (*n == '\0')
52797 + return 0;
52798 +
52799 + if (*n == '/')
52800 + return 0;
52801 +
52802 + return 1;
52803 +}
52804 +
52805 +static struct acl_object_label *
52806 +chk_glob_label(struct acl_object_label *globbed,
52807 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52808 +{
52809 + struct acl_object_label *tmp;
52810 +
52811 + if (*path == NULL)
52812 + *path = gr_to_filename_nolock(dentry, mnt);
52813 +
52814 + tmp = globbed;
52815 +
52816 + while (tmp) {
52817 + if (!glob_match(tmp->filename, *path))
52818 + return tmp;
52819 + tmp = tmp->next;
52820 + }
52821 +
52822 + return NULL;
52823 +}
52824 +
52825 +static struct acl_object_label *
52826 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52827 + const ino_t curr_ino, const dev_t curr_dev,
52828 + const struct acl_subject_label *subj, char **path, const int checkglob)
52829 +{
52830 + struct acl_subject_label *tmpsubj;
52831 + struct acl_object_label *retval;
52832 + struct acl_object_label *retval2;
52833 +
52834 + tmpsubj = (struct acl_subject_label *) subj;
52835 + read_lock(&gr_inode_lock);
52836 + do {
52837 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52838 + if (retval) {
52839 + if (checkglob && retval->globbed) {
52840 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52841 + if (retval2)
52842 + retval = retval2;
52843 + }
52844 + break;
52845 + }
52846 + } while ((tmpsubj = tmpsubj->parent_subject));
52847 + read_unlock(&gr_inode_lock);
52848 +
52849 + return retval;
52850 +}
52851 +
52852 +static __inline__ struct acl_object_label *
52853 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52854 + struct dentry *curr_dentry,
52855 + const struct acl_subject_label *subj, char **path, const int checkglob)
52856 +{
52857 + int newglob = checkglob;
52858 + ino_t inode;
52859 + dev_t device;
52860 +
52861 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52862 + as we don't want a / * rule to match instead of the / object
52863 + don't do this for create lookups that call this function though, since they're looking up
52864 + on the parent and thus need globbing checks on all paths
52865 + */
52866 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52867 + newglob = GR_NO_GLOB;
52868 +
52869 + spin_lock(&curr_dentry->d_lock);
52870 + inode = curr_dentry->d_inode->i_ino;
52871 + device = __get_dev(curr_dentry);
52872 + spin_unlock(&curr_dentry->d_lock);
52873 +
52874 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52875 +}
52876 +
52877 +static struct acl_object_label *
52878 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52879 + const struct acl_subject_label *subj, char *path, const int checkglob)
52880 +{
52881 + struct dentry *dentry = (struct dentry *) l_dentry;
52882 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52883 + struct mount *real_mnt = real_mount(mnt);
52884 + struct acl_object_label *retval;
52885 + struct dentry *parent;
52886 +
52887 + write_seqlock(&rename_lock);
52888 + br_read_lock(&vfsmount_lock);
52889 +
52890 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52891 +#ifdef CONFIG_NET
52892 + mnt == sock_mnt ||
52893 +#endif
52894 +#ifdef CONFIG_HUGETLBFS
52895 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52896 +#endif
52897 + /* ignore Eric Biederman */
52898 + IS_PRIVATE(l_dentry->d_inode))) {
52899 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52900 + goto out;
52901 + }
52902 +
52903 + for (;;) {
52904 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52905 + break;
52906 +
52907 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52908 + if (!mnt_has_parent(real_mnt))
52909 + break;
52910 +
52911 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52912 + if (retval != NULL)
52913 + goto out;
52914 +
52915 + dentry = real_mnt->mnt_mountpoint;
52916 + real_mnt = real_mnt->mnt_parent;
52917 + mnt = &real_mnt->mnt;
52918 + continue;
52919 + }
52920 +
52921 + parent = dentry->d_parent;
52922 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52923 + if (retval != NULL)
52924 + goto out;
52925 +
52926 + dentry = parent;
52927 + }
52928 +
52929 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52930 +
52931 + /* real_root is pinned so we don't have to hold a reference */
52932 + if (retval == NULL)
52933 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52934 +out:
52935 + br_read_unlock(&vfsmount_lock);
52936 + write_sequnlock(&rename_lock);
52937 +
52938 + BUG_ON(retval == NULL);
52939 +
52940 + return retval;
52941 +}
52942 +
52943 +static __inline__ struct acl_object_label *
52944 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52945 + const struct acl_subject_label *subj)
52946 +{
52947 + char *path = NULL;
52948 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52949 +}
52950 +
52951 +static __inline__ struct acl_object_label *
52952 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52953 + const struct acl_subject_label *subj)
52954 +{
52955 + char *path = NULL;
52956 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52957 +}
52958 +
52959 +static __inline__ struct acl_object_label *
52960 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52961 + const struct acl_subject_label *subj, char *path)
52962 +{
52963 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52964 +}
52965 +
52966 +static struct acl_subject_label *
52967 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52968 + const struct acl_role_label *role)
52969 +{
52970 + struct dentry *dentry = (struct dentry *) l_dentry;
52971 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52972 + struct mount *real_mnt = real_mount(mnt);
52973 + struct acl_subject_label *retval;
52974 + struct dentry *parent;
52975 +
52976 + write_seqlock(&rename_lock);
52977 + br_read_lock(&vfsmount_lock);
52978 +
52979 + for (;;) {
52980 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52981 + break;
52982 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52983 + if (!mnt_has_parent(real_mnt))
52984 + break;
52985 +
52986 + spin_lock(&dentry->d_lock);
52987 + read_lock(&gr_inode_lock);
52988 + retval =
52989 + lookup_acl_subj_label(dentry->d_inode->i_ino,
52990 + __get_dev(dentry), role);
52991 + read_unlock(&gr_inode_lock);
52992 + spin_unlock(&dentry->d_lock);
52993 + if (retval != NULL)
52994 + goto out;
52995 +
52996 + dentry = real_mnt->mnt_mountpoint;
52997 + real_mnt = real_mnt->mnt_parent;
52998 + mnt = &real_mnt->mnt;
52999 + continue;
53000 + }
53001 +
53002 + spin_lock(&dentry->d_lock);
53003 + read_lock(&gr_inode_lock);
53004 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53005 + __get_dev(dentry), role);
53006 + read_unlock(&gr_inode_lock);
53007 + parent = dentry->d_parent;
53008 + spin_unlock(&dentry->d_lock);
53009 +
53010 + if (retval != NULL)
53011 + goto out;
53012 +
53013 + dentry = parent;
53014 + }
53015 +
53016 + spin_lock(&dentry->d_lock);
53017 + read_lock(&gr_inode_lock);
53018 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53019 + __get_dev(dentry), role);
53020 + read_unlock(&gr_inode_lock);
53021 + spin_unlock(&dentry->d_lock);
53022 +
53023 + if (unlikely(retval == NULL)) {
53024 + /* real_root is pinned, we don't need to hold a reference */
53025 + read_lock(&gr_inode_lock);
53026 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53027 + __get_dev(real_root.dentry), role);
53028 + read_unlock(&gr_inode_lock);
53029 + }
53030 +out:
53031 + br_read_unlock(&vfsmount_lock);
53032 + write_sequnlock(&rename_lock);
53033 +
53034 + BUG_ON(retval == NULL);
53035 +
53036 + return retval;
53037 +}
53038 +
53039 +static void
53040 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53041 +{
53042 + struct task_struct *task = current;
53043 + const struct cred *cred = current_cred();
53044 +
53045 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53046 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53047 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53048 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53049 +
53050 + return;
53051 +}
53052 +
53053 +static void
53054 +gr_log_learn_id_change(const char type, const unsigned int real,
53055 + const unsigned int effective, const unsigned int fs)
53056 +{
53057 + struct task_struct *task = current;
53058 + const struct cred *cred = current_cred();
53059 +
53060 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53061 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53062 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53063 + type, real, effective, fs, &task->signal->saved_ip);
53064 +
53065 + return;
53066 +}
53067 +
53068 +__u32
53069 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53070 + const struct vfsmount * mnt)
53071 +{
53072 + __u32 retval = mode;
53073 + struct acl_subject_label *curracl;
53074 + struct acl_object_label *currobj;
53075 +
53076 + if (unlikely(!(gr_status & GR_READY)))
53077 + return (mode & ~GR_AUDITS);
53078 +
53079 + curracl = current->acl;
53080 +
53081 + currobj = chk_obj_label(dentry, mnt, curracl);
53082 + retval = currobj->mode & mode;
53083 +
53084 + /* if we're opening a specified transfer file for writing
53085 + (e.g. /dev/initctl), then transfer our role to init
53086 + */
53087 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53088 + current->role->roletype & GR_ROLE_PERSIST)) {
53089 + struct task_struct *task = init_pid_ns.child_reaper;
53090 +
53091 + if (task->role != current->role) {
53092 + task->acl_sp_role = 0;
53093 + task->acl_role_id = current->acl_role_id;
53094 + task->role = current->role;
53095 + rcu_read_lock();
53096 + read_lock(&grsec_exec_file_lock);
53097 + gr_apply_subject_to_task(task);
53098 + read_unlock(&grsec_exec_file_lock);
53099 + rcu_read_unlock();
53100 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53101 + }
53102 + }
53103 +
53104 + if (unlikely
53105 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53106 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53107 + __u32 new_mode = mode;
53108 +
53109 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53110 +
53111 + retval = new_mode;
53112 +
53113 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53114 + new_mode |= GR_INHERIT;
53115 +
53116 + if (!(mode & GR_NOLEARN))
53117 + gr_log_learn(dentry, mnt, new_mode);
53118 + }
53119 +
53120 + return retval;
53121 +}
53122 +
53123 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53124 + const struct dentry *parent,
53125 + const struct vfsmount *mnt)
53126 +{
53127 + struct name_entry *match;
53128 + struct acl_object_label *matchpo;
53129 + struct acl_subject_label *curracl;
53130 + char *path;
53131 +
53132 + if (unlikely(!(gr_status & GR_READY)))
53133 + return NULL;
53134 +
53135 + preempt_disable();
53136 + path = gr_to_filename_rbac(new_dentry, mnt);
53137 + match = lookup_name_entry_create(path);
53138 +
53139 + curracl = current->acl;
53140 +
53141 + if (match) {
53142 + read_lock(&gr_inode_lock);
53143 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53144 + read_unlock(&gr_inode_lock);
53145 +
53146 + if (matchpo) {
53147 + preempt_enable();
53148 + return matchpo;
53149 + }
53150 + }
53151 +
53152 + // lookup parent
53153 +
53154 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53155 +
53156 + preempt_enable();
53157 + return matchpo;
53158 +}
53159 +
53160 +__u32
53161 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53162 + const struct vfsmount * mnt, const __u32 mode)
53163 +{
53164 + struct acl_object_label *matchpo;
53165 + __u32 retval;
53166 +
53167 + if (unlikely(!(gr_status & GR_READY)))
53168 + return (mode & ~GR_AUDITS);
53169 +
53170 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53171 +
53172 + retval = matchpo->mode & mode;
53173 +
53174 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53175 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53176 + __u32 new_mode = mode;
53177 +
53178 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53179 +
53180 + gr_log_learn(new_dentry, mnt, new_mode);
53181 + return new_mode;
53182 + }
53183 +
53184 + return retval;
53185 +}
53186 +
53187 +__u32
53188 +gr_check_link(const struct dentry * new_dentry,
53189 + const struct dentry * parent_dentry,
53190 + const struct vfsmount * parent_mnt,
53191 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53192 +{
53193 + struct acl_object_label *obj;
53194 + __u32 oldmode, newmode;
53195 + __u32 needmode;
53196 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53197 + GR_DELETE | GR_INHERIT;
53198 +
53199 + if (unlikely(!(gr_status & GR_READY)))
53200 + return (GR_CREATE | GR_LINK);
53201 +
53202 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53203 + oldmode = obj->mode;
53204 +
53205 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53206 + newmode = obj->mode;
53207 +
53208 + needmode = newmode & checkmodes;
53209 +
53210 + // old name for hardlink must have at least the permissions of the new name
53211 + if ((oldmode & needmode) != needmode)
53212 + goto bad;
53213 +
53214 + // if old name had restrictions/auditing, make sure the new name does as well
53215 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53216 +
53217 + // don't allow hardlinking of suid/sgid/fcapped files without permission
53218 + if (is_privileged_binary(old_dentry))
53219 + needmode |= GR_SETID;
53220 +
53221 + if ((newmode & needmode) != needmode)
53222 + goto bad;
53223 +
53224 + // enforce minimum permissions
53225 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53226 + return newmode;
53227 +bad:
53228 + needmode = oldmode;
53229 + if (is_privileged_binary(old_dentry))
53230 + needmode |= GR_SETID;
53231 +
53232 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53233 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53234 + return (GR_CREATE | GR_LINK);
53235 + } else if (newmode & GR_SUPPRESS)
53236 + return GR_SUPPRESS;
53237 + else
53238 + return 0;
53239 +}
53240 +
53241 +int
53242 +gr_check_hidden_task(const struct task_struct *task)
53243 +{
53244 + if (unlikely(!(gr_status & GR_READY)))
53245 + return 0;
53246 +
53247 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53248 + return 1;
53249 +
53250 + return 0;
53251 +}
53252 +
53253 +int
53254 +gr_check_protected_task(const struct task_struct *task)
53255 +{
53256 + if (unlikely(!(gr_status & GR_READY) || !task))
53257 + return 0;
53258 +
53259 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53260 + task->acl != current->acl)
53261 + return 1;
53262 +
53263 + return 0;
53264 +}
53265 +
53266 +int
53267 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53268 +{
53269 + struct task_struct *p;
53270 + int ret = 0;
53271 +
53272 + if (unlikely(!(gr_status & GR_READY) || !pid))
53273 + return ret;
53274 +
53275 + read_lock(&tasklist_lock);
53276 + do_each_pid_task(pid, type, p) {
53277 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53278 + p->acl != current->acl) {
53279 + ret = 1;
53280 + goto out;
53281 + }
53282 + } while_each_pid_task(pid, type, p);
53283 +out:
53284 + read_unlock(&tasklist_lock);
53285 +
53286 + return ret;
53287 +}
53288 +
53289 +void
53290 +gr_copy_label(struct task_struct *tsk)
53291 +{
53292 + tsk->signal->used_accept = 0;
53293 + tsk->acl_sp_role = 0;
53294 + tsk->acl_role_id = current->acl_role_id;
53295 + tsk->acl = current->acl;
53296 + tsk->role = current->role;
53297 + tsk->signal->curr_ip = current->signal->curr_ip;
53298 + tsk->signal->saved_ip = current->signal->saved_ip;
53299 + if (current->exec_file)
53300 + get_file(current->exec_file);
53301 + tsk->exec_file = current->exec_file;
53302 + tsk->is_writable = current->is_writable;
53303 + if (unlikely(current->signal->used_accept)) {
53304 + current->signal->curr_ip = 0;
53305 + current->signal->saved_ip = 0;
53306 + }
53307 +
53308 + return;
53309 +}
53310 +
53311 +static void
53312 +gr_set_proc_res(struct task_struct *task)
53313 +{
53314 + struct acl_subject_label *proc;
53315 + unsigned short i;
53316 +
53317 + proc = task->acl;
53318 +
53319 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53320 + return;
53321 +
53322 + for (i = 0; i < RLIM_NLIMITS; i++) {
53323 + if (!(proc->resmask & (1 << i)))
53324 + continue;
53325 +
53326 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53327 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53328 + }
53329 +
53330 + return;
53331 +}
53332 +
53333 +extern int __gr_process_user_ban(struct user_struct *user);
53334 +
53335 +int
53336 +gr_check_user_change(int real, int effective, int fs)
53337 +{
53338 + unsigned int i;
53339 + __u16 num;
53340 + uid_t *uidlist;
53341 + int curuid;
53342 + int realok = 0;
53343 + int effectiveok = 0;
53344 + int fsok = 0;
53345 +
53346 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53347 + struct user_struct *user;
53348 +
53349 + if (real == -1)
53350 + goto skipit;
53351 +
53352 + user = find_user(real);
53353 + if (user == NULL)
53354 + goto skipit;
53355 +
53356 + if (__gr_process_user_ban(user)) {
53357 + /* for find_user */
53358 + free_uid(user);
53359 + return 1;
53360 + }
53361 +
53362 + /* for find_user */
53363 + free_uid(user);
53364 +
53365 +skipit:
53366 +#endif
53367 +
53368 + if (unlikely(!(gr_status & GR_READY)))
53369 + return 0;
53370 +
53371 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53372 + gr_log_learn_id_change('u', real, effective, fs);
53373 +
53374 + num = current->acl->user_trans_num;
53375 + uidlist = current->acl->user_transitions;
53376 +
53377 + if (uidlist == NULL)
53378 + return 0;
53379 +
53380 + if (real == -1)
53381 + realok = 1;
53382 + if (effective == -1)
53383 + effectiveok = 1;
53384 + if (fs == -1)
53385 + fsok = 1;
53386 +
53387 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
53388 + for (i = 0; i < num; i++) {
53389 + curuid = (int)uidlist[i];
53390 + if (real == curuid)
53391 + realok = 1;
53392 + if (effective == curuid)
53393 + effectiveok = 1;
53394 + if (fs == curuid)
53395 + fsok = 1;
53396 + }
53397 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
53398 + for (i = 0; i < num; i++) {
53399 + curuid = (int)uidlist[i];
53400 + if (real == curuid)
53401 + break;
53402 + if (effective == curuid)
53403 + break;
53404 + if (fs == curuid)
53405 + break;
53406 + }
53407 + /* not in deny list */
53408 + if (i == num) {
53409 + realok = 1;
53410 + effectiveok = 1;
53411 + fsok = 1;
53412 + }
53413 + }
53414 +
53415 + if (realok && effectiveok && fsok)
53416 + return 0;
53417 + else {
53418 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53419 + return 1;
53420 + }
53421 +}
53422 +
53423 +int
53424 +gr_check_group_change(int real, int effective, int fs)
53425 +{
53426 + unsigned int i;
53427 + __u16 num;
53428 + gid_t *gidlist;
53429 + int curgid;
53430 + int realok = 0;
53431 + int effectiveok = 0;
53432 + int fsok = 0;
53433 +
53434 + if (unlikely(!(gr_status & GR_READY)))
53435 + return 0;
53436 +
53437 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53438 + gr_log_learn_id_change('g', real, effective, fs);
53439 +
53440 + num = current->acl->group_trans_num;
53441 + gidlist = current->acl->group_transitions;
53442 +
53443 + if (gidlist == NULL)
53444 + return 0;
53445 +
53446 + if (real == -1)
53447 + realok = 1;
53448 + if (effective == -1)
53449 + effectiveok = 1;
53450 + if (fs == -1)
53451 + fsok = 1;
53452 +
53453 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53454 + for (i = 0; i < num; i++) {
53455 + curgid = (int)gidlist[i];
53456 + if (real == curgid)
53457 + realok = 1;
53458 + if (effective == curgid)
53459 + effectiveok = 1;
53460 + if (fs == curgid)
53461 + fsok = 1;
53462 + }
53463 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
53464 + for (i = 0; i < num; i++) {
53465 + curgid = (int)gidlist[i];
53466 + if (real == curgid)
53467 + break;
53468 + if (effective == curgid)
53469 + break;
53470 + if (fs == curgid)
53471 + break;
53472 + }
53473 + /* not in deny list */
53474 + if (i == num) {
53475 + realok = 1;
53476 + effectiveok = 1;
53477 + fsok = 1;
53478 + }
53479 + }
53480 +
53481 + if (realok && effectiveok && fsok)
53482 + return 0;
53483 + else {
53484 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53485 + return 1;
53486 + }
53487 +}
53488 +
53489 +extern int gr_acl_is_capable(const int cap);
53490 +
53491 +void
53492 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53493 +{
53494 + struct acl_role_label *role = task->role;
53495 + struct acl_subject_label *subj = NULL;
53496 + struct acl_object_label *obj;
53497 + struct file *filp;
53498 +
53499 + if (unlikely(!(gr_status & GR_READY)))
53500 + return;
53501 +
53502 + filp = task->exec_file;
53503 +
53504 + /* kernel process, we'll give them the kernel role */
53505 + if (unlikely(!filp)) {
53506 + task->role = kernel_role;
53507 + task->acl = kernel_role->root_label;
53508 + return;
53509 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53510 + role = lookup_acl_role_label(task, uid, gid);
53511 +
53512 + /* don't change the role if we're not a privileged process */
53513 + if (role && task->role != role &&
53514 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53515 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53516 + return;
53517 +
53518 + /* perform subject lookup in possibly new role
53519 + we can use this result below in the case where role == task->role
53520 + */
53521 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53522 +
53523 + /* if we changed uid/gid, but result in the same role
53524 + and are using inheritance, don't lose the inherited subject
53525 + if current subject is other than what normal lookup
53526 + would result in, we arrived via inheritance, don't
53527 + lose subject
53528 + */
53529 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53530 + (subj == task->acl)))
53531 + task->acl = subj;
53532 +
53533 + task->role = role;
53534 +
53535 + task->is_writable = 0;
53536 +
53537 + /* ignore additional mmap checks for processes that are writable
53538 + by the default ACL */
53539 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53540 + if (unlikely(obj->mode & GR_WRITE))
53541 + task->is_writable = 1;
53542 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53543 + if (unlikely(obj->mode & GR_WRITE))
53544 + task->is_writable = 1;
53545 +
53546 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53547 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53548 +#endif
53549 +
53550 + gr_set_proc_res(task);
53551 +
53552 + return;
53553 +}
53554 +
53555 +int
53556 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53557 + const int unsafe_flags)
53558 +{
53559 + struct task_struct *task = current;
53560 + struct acl_subject_label *newacl;
53561 + struct acl_object_label *obj;
53562 + __u32 retmode;
53563 +
53564 + if (unlikely(!(gr_status & GR_READY)))
53565 + return 0;
53566 +
53567 + newacl = chk_subj_label(dentry, mnt, task->role);
53568 +
53569 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
53570 + did an exec
53571 + */
53572 + rcu_read_lock();
53573 + read_lock(&tasklist_lock);
53574 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
53575 + (task->parent->acl->mode & GR_POVERRIDE))) {
53576 + read_unlock(&tasklist_lock);
53577 + rcu_read_unlock();
53578 + goto skip_check;
53579 + }
53580 + read_unlock(&tasklist_lock);
53581 + rcu_read_unlock();
53582 +
53583 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53584 + !(task->role->roletype & GR_ROLE_GOD) &&
53585 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53586 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53587 + if (unsafe_flags & LSM_UNSAFE_SHARE)
53588 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53589 + else
53590 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53591 + return -EACCES;
53592 + }
53593 +
53594 +skip_check:
53595 +
53596 + obj = chk_obj_label(dentry, mnt, task->acl);
53597 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53598 +
53599 + if (!(task->acl->mode & GR_INHERITLEARN) &&
53600 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53601 + if (obj->nested)
53602 + task->acl = obj->nested;
53603 + else
53604 + task->acl = newacl;
53605 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53606 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53607 +
53608 + task->is_writable = 0;
53609 +
53610 + /* ignore additional mmap checks for processes that are writable
53611 + by the default ACL */
53612 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
53613 + if (unlikely(obj->mode & GR_WRITE))
53614 + task->is_writable = 1;
53615 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
53616 + if (unlikely(obj->mode & GR_WRITE))
53617 + task->is_writable = 1;
53618 +
53619 + gr_set_proc_res(task);
53620 +
53621 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53622 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53623 +#endif
53624 + return 0;
53625 +}
53626 +
53627 +/* always called with valid inodev ptr */
53628 +static void
53629 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53630 +{
53631 + struct acl_object_label *matchpo;
53632 + struct acl_subject_label *matchps;
53633 + struct acl_subject_label *subj;
53634 + struct acl_role_label *role;
53635 + unsigned int x;
53636 +
53637 + FOR_EACH_ROLE_START(role)
53638 + FOR_EACH_SUBJECT_START(role, subj, x)
53639 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53640 + matchpo->mode |= GR_DELETED;
53641 + FOR_EACH_SUBJECT_END(subj,x)
53642 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53643 + if (subj->inode == ino && subj->device == dev)
53644 + subj->mode |= GR_DELETED;
53645 + FOR_EACH_NESTED_SUBJECT_END(subj)
53646 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53647 + matchps->mode |= GR_DELETED;
53648 + FOR_EACH_ROLE_END(role)
53649 +
53650 + inodev->nentry->deleted = 1;
53651 +
53652 + return;
53653 +}
53654 +
53655 +void
53656 +gr_handle_delete(const ino_t ino, const dev_t dev)
53657 +{
53658 + struct inodev_entry *inodev;
53659 +
53660 + if (unlikely(!(gr_status & GR_READY)))
53661 + return;
53662 +
53663 + write_lock(&gr_inode_lock);
53664 + inodev = lookup_inodev_entry(ino, dev);
53665 + if (inodev != NULL)
53666 + do_handle_delete(inodev, ino, dev);
53667 + write_unlock(&gr_inode_lock);
53668 +
53669 + return;
53670 +}
53671 +
53672 +static void
53673 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53674 + const ino_t newinode, const dev_t newdevice,
53675 + struct acl_subject_label *subj)
53676 +{
53677 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53678 + struct acl_object_label *match;
53679 +
53680 + match = subj->obj_hash[index];
53681 +
53682 + while (match && (match->inode != oldinode ||
53683 + match->device != olddevice ||
53684 + !(match->mode & GR_DELETED)))
53685 + match = match->next;
53686 +
53687 + if (match && (match->inode == oldinode)
53688 + && (match->device == olddevice)
53689 + && (match->mode & GR_DELETED)) {
53690 + if (match->prev == NULL) {
53691 + subj->obj_hash[index] = match->next;
53692 + if (match->next != NULL)
53693 + match->next->prev = NULL;
53694 + } else {
53695 + match->prev->next = match->next;
53696 + if (match->next != NULL)
53697 + match->next->prev = match->prev;
53698 + }
53699 + match->prev = NULL;
53700 + match->next = NULL;
53701 + match->inode = newinode;
53702 + match->device = newdevice;
53703 + match->mode &= ~GR_DELETED;
53704 +
53705 + insert_acl_obj_label(match, subj);
53706 + }
53707 +
53708 + return;
53709 +}
53710 +
53711 +static void
53712 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53713 + const ino_t newinode, const dev_t newdevice,
53714 + struct acl_role_label *role)
53715 +{
53716 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53717 + struct acl_subject_label *match;
53718 +
53719 + match = role->subj_hash[index];
53720 +
53721 + while (match && (match->inode != oldinode ||
53722 + match->device != olddevice ||
53723 + !(match->mode & GR_DELETED)))
53724 + match = match->next;
53725 +
53726 + if (match && (match->inode == oldinode)
53727 + && (match->device == olddevice)
53728 + && (match->mode & GR_DELETED)) {
53729 + if (match->prev == NULL) {
53730 + role->subj_hash[index] = match->next;
53731 + if (match->next != NULL)
53732 + match->next->prev = NULL;
53733 + } else {
53734 + match->prev->next = match->next;
53735 + if (match->next != NULL)
53736 + match->next->prev = match->prev;
53737 + }
53738 + match->prev = NULL;
53739 + match->next = NULL;
53740 + match->inode = newinode;
53741 + match->device = newdevice;
53742 + match->mode &= ~GR_DELETED;
53743 +
53744 + insert_acl_subj_label(match, role);
53745 + }
53746 +
53747 + return;
53748 +}
53749 +
53750 +static void
53751 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53752 + const ino_t newinode, const dev_t newdevice)
53753 +{
53754 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53755 + struct inodev_entry *match;
53756 +
53757 + match = inodev_set.i_hash[index];
53758 +
53759 + while (match && (match->nentry->inode != oldinode ||
53760 + match->nentry->device != olddevice || !match->nentry->deleted))
53761 + match = match->next;
53762 +
53763 + if (match && (match->nentry->inode == oldinode)
53764 + && (match->nentry->device == olddevice) &&
53765 + match->nentry->deleted) {
53766 + if (match->prev == NULL) {
53767 + inodev_set.i_hash[index] = match->next;
53768 + if (match->next != NULL)
53769 + match->next->prev = NULL;
53770 + } else {
53771 + match->prev->next = match->next;
53772 + if (match->next != NULL)
53773 + match->next->prev = match->prev;
53774 + }
53775 + match->prev = NULL;
53776 + match->next = NULL;
53777 + match->nentry->inode = newinode;
53778 + match->nentry->device = newdevice;
53779 + match->nentry->deleted = 0;
53780 +
53781 + insert_inodev_entry(match);
53782 + }
53783 +
53784 + return;
53785 +}
53786 +
53787 +static void
53788 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53789 +{
53790 + struct acl_subject_label *subj;
53791 + struct acl_role_label *role;
53792 + unsigned int x;
53793 +
53794 + FOR_EACH_ROLE_START(role)
53795 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53796 +
53797 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53798 + if ((subj->inode == ino) && (subj->device == dev)) {
53799 + subj->inode = ino;
53800 + subj->device = dev;
53801 + }
53802 + FOR_EACH_NESTED_SUBJECT_END(subj)
53803 + FOR_EACH_SUBJECT_START(role, subj, x)
53804 + update_acl_obj_label(matchn->inode, matchn->device,
53805 + ino, dev, subj);
53806 + FOR_EACH_SUBJECT_END(subj,x)
53807 + FOR_EACH_ROLE_END(role)
53808 +
53809 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53810 +
53811 + return;
53812 +}
53813 +
53814 +static void
53815 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53816 + const struct vfsmount *mnt)
53817 +{
53818 + ino_t ino = dentry->d_inode->i_ino;
53819 + dev_t dev = __get_dev(dentry);
53820 +
53821 + __do_handle_create(matchn, ino, dev);
53822 +
53823 + return;
53824 +}
53825 +
53826 +void
53827 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53828 +{
53829 + struct name_entry *matchn;
53830 +
53831 + if (unlikely(!(gr_status & GR_READY)))
53832 + return;
53833 +
53834 + preempt_disable();
53835 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53836 +
53837 + if (unlikely((unsigned long)matchn)) {
53838 + write_lock(&gr_inode_lock);
53839 + do_handle_create(matchn, dentry, mnt);
53840 + write_unlock(&gr_inode_lock);
53841 + }
53842 + preempt_enable();
53843 +
53844 + return;
53845 +}
53846 +
53847 +void
53848 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53849 +{
53850 + struct name_entry *matchn;
53851 +
53852 + if (unlikely(!(gr_status & GR_READY)))
53853 + return;
53854 +
53855 + preempt_disable();
53856 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53857 +
53858 + if (unlikely((unsigned long)matchn)) {
53859 + write_lock(&gr_inode_lock);
53860 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53861 + write_unlock(&gr_inode_lock);
53862 + }
53863 + preempt_enable();
53864 +
53865 + return;
53866 +}
53867 +
53868 +void
53869 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53870 + struct dentry *old_dentry,
53871 + struct dentry *new_dentry,
53872 + struct vfsmount *mnt, const __u8 replace)
53873 +{
53874 + struct name_entry *matchn;
53875 + struct inodev_entry *inodev;
53876 + struct inode *inode = new_dentry->d_inode;
53877 + ino_t old_ino = old_dentry->d_inode->i_ino;
53878 + dev_t old_dev = __get_dev(old_dentry);
53879 +
53880 + /* vfs_rename swaps the name and parent link for old_dentry and
53881 + new_dentry
53882 + at this point, old_dentry has the new name, parent link, and inode
53883 + for the renamed file
53884 + if a file is being replaced by a rename, new_dentry has the inode
53885 + and name for the replaced file
53886 + */
53887 +
53888 + if (unlikely(!(gr_status & GR_READY)))
53889 + return;
53890 +
53891 + preempt_disable();
53892 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53893 +
53894 + /* we wouldn't have to check d_inode if it weren't for
53895 + NFS silly-renaming
53896 + */
53897 +
53898 + write_lock(&gr_inode_lock);
53899 + if (unlikely(replace && inode)) {
53900 + ino_t new_ino = inode->i_ino;
53901 + dev_t new_dev = __get_dev(new_dentry);
53902 +
53903 + inodev = lookup_inodev_entry(new_ino, new_dev);
53904 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53905 + do_handle_delete(inodev, new_ino, new_dev);
53906 + }
53907 +
53908 + inodev = lookup_inodev_entry(old_ino, old_dev);
53909 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53910 + do_handle_delete(inodev, old_ino, old_dev);
53911 +
53912 + if (unlikely((unsigned long)matchn))
53913 + do_handle_create(matchn, old_dentry, mnt);
53914 +
53915 + write_unlock(&gr_inode_lock);
53916 + preempt_enable();
53917 +
53918 + return;
53919 +}
53920 +
53921 +static int
53922 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53923 + unsigned char **sum)
53924 +{
53925 + struct acl_role_label *r;
53926 + struct role_allowed_ip *ipp;
53927 + struct role_transition *trans;
53928 + unsigned int i;
53929 + int found = 0;
53930 + u32 curr_ip = current->signal->curr_ip;
53931 +
53932 + current->signal->saved_ip = curr_ip;
53933 +
53934 + /* check transition table */
53935 +
53936 + for (trans = current->role->transitions; trans; trans = trans->next) {
53937 + if (!strcmp(rolename, trans->rolename)) {
53938 + found = 1;
53939 + break;
53940 + }
53941 + }
53942 +
53943 + if (!found)
53944 + return 0;
53945 +
53946 + /* handle special roles that do not require authentication
53947 + and check ip */
53948 +
53949 + FOR_EACH_ROLE_START(r)
53950 + if (!strcmp(rolename, r->rolename) &&
53951 + (r->roletype & GR_ROLE_SPECIAL)) {
53952 + found = 0;
53953 + if (r->allowed_ips != NULL) {
53954 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53955 + if ((ntohl(curr_ip) & ipp->netmask) ==
53956 + (ntohl(ipp->addr) & ipp->netmask))
53957 + found = 1;
53958 + }
53959 + } else
53960 + found = 2;
53961 + if (!found)
53962 + return 0;
53963 +
53964 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53965 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53966 + *salt = NULL;
53967 + *sum = NULL;
53968 + return 1;
53969 + }
53970 + }
53971 + FOR_EACH_ROLE_END(r)
53972 +
53973 + for (i = 0; i < num_sprole_pws; i++) {
53974 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53975 + *salt = acl_special_roles[i]->salt;
53976 + *sum = acl_special_roles[i]->sum;
53977 + return 1;
53978 + }
53979 + }
53980 +
53981 + return 0;
53982 +}
53983 +
53984 +static void
53985 +assign_special_role(char *rolename)
53986 +{
53987 + struct acl_object_label *obj;
53988 + struct acl_role_label *r;
53989 + struct acl_role_label *assigned = NULL;
53990 + struct task_struct *tsk;
53991 + struct file *filp;
53992 +
53993 + FOR_EACH_ROLE_START(r)
53994 + if (!strcmp(rolename, r->rolename) &&
53995 + (r->roletype & GR_ROLE_SPECIAL)) {
53996 + assigned = r;
53997 + break;
53998 + }
53999 + FOR_EACH_ROLE_END(r)
54000 +
54001 + if (!assigned)
54002 + return;
54003 +
54004 + read_lock(&tasklist_lock);
54005 + read_lock(&grsec_exec_file_lock);
54006 +
54007 + tsk = current->real_parent;
54008 + if (tsk == NULL)
54009 + goto out_unlock;
54010 +
54011 + filp = tsk->exec_file;
54012 + if (filp == NULL)
54013 + goto out_unlock;
54014 +
54015 + tsk->is_writable = 0;
54016 +
54017 + tsk->acl_sp_role = 1;
54018 + tsk->acl_role_id = ++acl_sp_role_value;
54019 + tsk->role = assigned;
54020 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54021 +
54022 + /* ignore additional mmap checks for processes that are writable
54023 + by the default ACL */
54024 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54025 + if (unlikely(obj->mode & GR_WRITE))
54026 + tsk->is_writable = 1;
54027 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54028 + if (unlikely(obj->mode & GR_WRITE))
54029 + tsk->is_writable = 1;
54030 +
54031 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54032 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54033 +#endif
54034 +
54035 +out_unlock:
54036 + read_unlock(&grsec_exec_file_lock);
54037 + read_unlock(&tasklist_lock);
54038 + return;
54039 +}
54040 +
54041 +int gr_check_secure_terminal(struct task_struct *task)
54042 +{
54043 + struct task_struct *p, *p2, *p3;
54044 + struct files_struct *files;
54045 + struct fdtable *fdt;
54046 + struct file *our_file = NULL, *file;
54047 + int i;
54048 +
54049 + if (task->signal->tty == NULL)
54050 + return 1;
54051 +
54052 + files = get_files_struct(task);
54053 + if (files != NULL) {
54054 + rcu_read_lock();
54055 + fdt = files_fdtable(files);
54056 + for (i=0; i < fdt->max_fds; i++) {
54057 + file = fcheck_files(files, i);
54058 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54059 + get_file(file);
54060 + our_file = file;
54061 + }
54062 + }
54063 + rcu_read_unlock();
54064 + put_files_struct(files);
54065 + }
54066 +
54067 + if (our_file == NULL)
54068 + return 1;
54069 +
54070 + read_lock(&tasklist_lock);
54071 + do_each_thread(p2, p) {
54072 + files = get_files_struct(p);
54073 + if (files == NULL ||
54074 + (p->signal && p->signal->tty == task->signal->tty)) {
54075 + if (files != NULL)
54076 + put_files_struct(files);
54077 + continue;
54078 + }
54079 + rcu_read_lock();
54080 + fdt = files_fdtable(files);
54081 + for (i=0; i < fdt->max_fds; i++) {
54082 + file = fcheck_files(files, i);
54083 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54084 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54085 + p3 = task;
54086 + while (p3->pid > 0) {
54087 + if (p3 == p)
54088 + break;
54089 + p3 = p3->real_parent;
54090 + }
54091 + if (p3 == p)
54092 + break;
54093 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54094 + gr_handle_alertkill(p);
54095 + rcu_read_unlock();
54096 + put_files_struct(files);
54097 + read_unlock(&tasklist_lock);
54098 + fput(our_file);
54099 + return 0;
54100 + }
54101 + }
54102 + rcu_read_unlock();
54103 + put_files_struct(files);
54104 + } while_each_thread(p2, p);
54105 + read_unlock(&tasklist_lock);
54106 +
54107 + fput(our_file);
54108 + return 1;
54109 +}
54110 +
54111 +static int gr_rbac_disable(void *unused)
54112 +{
54113 + pax_open_kernel();
54114 + gr_status &= ~GR_READY;
54115 + pax_close_kernel();
54116 +
54117 + return 0;
54118 +}
54119 +
54120 +ssize_t
54121 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54122 +{
54123 + struct gr_arg_wrapper uwrap;
54124 + unsigned char *sprole_salt = NULL;
54125 + unsigned char *sprole_sum = NULL;
54126 + int error = sizeof (struct gr_arg_wrapper);
54127 + int error2 = 0;
54128 +
54129 + mutex_lock(&gr_dev_mutex);
54130 +
54131 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54132 + error = -EPERM;
54133 + goto out;
54134 + }
54135 +
54136 + if (count != sizeof (struct gr_arg_wrapper)) {
54137 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54138 + error = -EINVAL;
54139 + goto out;
54140 + }
54141 +
54142 +
54143 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54144 + gr_auth_expires = 0;
54145 + gr_auth_attempts = 0;
54146 + }
54147 +
54148 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54149 + error = -EFAULT;
54150 + goto out;
54151 + }
54152 +
54153 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54154 + error = -EINVAL;
54155 + goto out;
54156 + }
54157 +
54158 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54159 + error = -EFAULT;
54160 + goto out;
54161 + }
54162 +
54163 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54164 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54165 + time_after(gr_auth_expires, get_seconds())) {
54166 + error = -EBUSY;
54167 + goto out;
54168 + }
54169 +
54170 + /* if non-root trying to do anything other than use a special role,
54171 + do not attempt authentication, do not count towards authentication
54172 + locking
54173 + */
54174 +
54175 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54176 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54177 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54178 + error = -EPERM;
54179 + goto out;
54180 + }
54181 +
54182 + /* ensure pw and special role name are null terminated */
54183 +
54184 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54185 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54186 +
54187 + /* Okay.
54188 + * We have our enough of the argument structure..(we have yet
54189 + * to copy_from_user the tables themselves) . Copy the tables
54190 + * only if we need them, i.e. for loading operations. */
54191 +
54192 + switch (gr_usermode->mode) {
54193 + case GR_STATUS:
54194 + if (gr_status & GR_READY) {
54195 + error = 1;
54196 + if (!gr_check_secure_terminal(current))
54197 + error = 3;
54198 + } else
54199 + error = 2;
54200 + goto out;
54201 + case GR_SHUTDOWN:
54202 + if ((gr_status & GR_READY)
54203 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54204 + stop_machine(gr_rbac_disable, NULL, NULL);
54205 + free_variables();
54206 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54207 + memset(gr_system_salt, 0, GR_SALT_LEN);
54208 + memset(gr_system_sum, 0, GR_SHA_LEN);
54209 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54210 + } else if (gr_status & GR_READY) {
54211 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54212 + error = -EPERM;
54213 + } else {
54214 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54215 + error = -EAGAIN;
54216 + }
54217 + break;
54218 + case GR_ENABLE:
54219 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54220 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54221 + else {
54222 + if (gr_status & GR_READY)
54223 + error = -EAGAIN;
54224 + else
54225 + error = error2;
54226 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54227 + }
54228 + break;
54229 + case GR_RELOAD:
54230 + if (!(gr_status & GR_READY)) {
54231 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54232 + error = -EAGAIN;
54233 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54234 + stop_machine(gr_rbac_disable, NULL, NULL);
54235 + free_variables();
54236 + error2 = gracl_init(gr_usermode);
54237 + if (!error2)
54238 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54239 + else {
54240 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54241 + error = error2;
54242 + }
54243 + } else {
54244 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54245 + error = -EPERM;
54246 + }
54247 + break;
54248 + case GR_SEGVMOD:
54249 + if (unlikely(!(gr_status & GR_READY))) {
54250 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54251 + error = -EAGAIN;
54252 + break;
54253 + }
54254 +
54255 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54256 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54257 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54258 + struct acl_subject_label *segvacl;
54259 + segvacl =
54260 + lookup_acl_subj_label(gr_usermode->segv_inode,
54261 + gr_usermode->segv_device,
54262 + current->role);
54263 + if (segvacl) {
54264 + segvacl->crashes = 0;
54265 + segvacl->expires = 0;
54266 + }
54267 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54268 + gr_remove_uid(gr_usermode->segv_uid);
54269 + }
54270 + } else {
54271 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54272 + error = -EPERM;
54273 + }
54274 + break;
54275 + case GR_SPROLE:
54276 + case GR_SPROLEPAM:
54277 + if (unlikely(!(gr_status & GR_READY))) {
54278 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54279 + error = -EAGAIN;
54280 + break;
54281 + }
54282 +
54283 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54284 + current->role->expires = 0;
54285 + current->role->auth_attempts = 0;
54286 + }
54287 +
54288 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54289 + time_after(current->role->expires, get_seconds())) {
54290 + error = -EBUSY;
54291 + goto out;
54292 + }
54293 +
54294 + if (lookup_special_role_auth
54295 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54296 + && ((!sprole_salt && !sprole_sum)
54297 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54298 + char *p = "";
54299 + assign_special_role(gr_usermode->sp_role);
54300 + read_lock(&tasklist_lock);
54301 + if (current->real_parent)
54302 + p = current->real_parent->role->rolename;
54303 + read_unlock(&tasklist_lock);
54304 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54305 + p, acl_sp_role_value);
54306 + } else {
54307 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54308 + error = -EPERM;
54309 + if(!(current->role->auth_attempts++))
54310 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54311 +
54312 + goto out;
54313 + }
54314 + break;
54315 + case GR_UNSPROLE:
54316 + if (unlikely(!(gr_status & GR_READY))) {
54317 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54318 + error = -EAGAIN;
54319 + break;
54320 + }
54321 +
54322 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54323 + char *p = "";
54324 + int i = 0;
54325 +
54326 + read_lock(&tasklist_lock);
54327 + if (current->real_parent) {
54328 + p = current->real_parent->role->rolename;
54329 + i = current->real_parent->acl_role_id;
54330 + }
54331 + read_unlock(&tasklist_lock);
54332 +
54333 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54334 + gr_set_acls(1);
54335 + } else {
54336 + error = -EPERM;
54337 + goto out;
54338 + }
54339 + break;
54340 + default:
54341 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54342 + error = -EINVAL;
54343 + break;
54344 + }
54345 +
54346 + if (error != -EPERM)
54347 + goto out;
54348 +
54349 + if(!(gr_auth_attempts++))
54350 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54351 +
54352 + out:
54353 + mutex_unlock(&gr_dev_mutex);
54354 + return error;
54355 +}
54356 +
54357 +/* must be called with
54358 + rcu_read_lock();
54359 + read_lock(&tasklist_lock);
54360 + read_lock(&grsec_exec_file_lock);
54361 +*/
54362 +int gr_apply_subject_to_task(struct task_struct *task)
54363 +{
54364 + struct acl_object_label *obj;
54365 + char *tmpname;
54366 + struct acl_subject_label *tmpsubj;
54367 + struct file *filp;
54368 + struct name_entry *nmatch;
54369 +
54370 + filp = task->exec_file;
54371 + if (filp == NULL)
54372 + return 0;
54373 +
54374 + /* the following is to apply the correct subject
54375 + on binaries running when the RBAC system
54376 + is enabled, when the binaries have been
54377 + replaced or deleted since their execution
54378 + -----
54379 + when the RBAC system starts, the inode/dev
54380 + from exec_file will be one the RBAC system
54381 + is unaware of. It only knows the inode/dev
54382 + of the present file on disk, or the absence
54383 + of it.
54384 + */
54385 + preempt_disable();
54386 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54387 +
54388 + nmatch = lookup_name_entry(tmpname);
54389 + preempt_enable();
54390 + tmpsubj = NULL;
54391 + if (nmatch) {
54392 + if (nmatch->deleted)
54393 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54394 + else
54395 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54396 + if (tmpsubj != NULL)
54397 + task->acl = tmpsubj;
54398 + }
54399 + if (tmpsubj == NULL)
54400 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54401 + task->role);
54402 + if (task->acl) {
54403 + task->is_writable = 0;
54404 + /* ignore additional mmap checks for processes that are writable
54405 + by the default ACL */
54406 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54407 + if (unlikely(obj->mode & GR_WRITE))
54408 + task->is_writable = 1;
54409 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54410 + if (unlikely(obj->mode & GR_WRITE))
54411 + task->is_writable = 1;
54412 +
54413 + gr_set_proc_res(task);
54414 +
54415 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54416 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54417 +#endif
54418 + } else {
54419 + return 1;
54420 + }
54421 +
54422 + return 0;
54423 +}
54424 +
54425 +int
54426 +gr_set_acls(const int type)
54427 +{
54428 + struct task_struct *task, *task2;
54429 + struct acl_role_label *role = current->role;
54430 + __u16 acl_role_id = current->acl_role_id;
54431 + const struct cred *cred;
54432 + int ret;
54433 +
54434 + rcu_read_lock();
54435 + read_lock(&tasklist_lock);
54436 + read_lock(&grsec_exec_file_lock);
54437 + do_each_thread(task2, task) {
54438 + /* check to see if we're called from the exit handler,
54439 + if so, only replace ACLs that have inherited the admin
54440 + ACL */
54441 +
54442 + if (type && (task->role != role ||
54443 + task->acl_role_id != acl_role_id))
54444 + continue;
54445 +
54446 + task->acl_role_id = 0;
54447 + task->acl_sp_role = 0;
54448 +
54449 + if (task->exec_file) {
54450 + cred = __task_cred(task);
54451 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54452 + ret = gr_apply_subject_to_task(task);
54453 + if (ret) {
54454 + read_unlock(&grsec_exec_file_lock);
54455 + read_unlock(&tasklist_lock);
54456 + rcu_read_unlock();
54457 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54458 + return ret;
54459 + }
54460 + } else {
54461 + // it's a kernel process
54462 + task->role = kernel_role;
54463 + task->acl = kernel_role->root_label;
54464 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54465 + task->acl->mode &= ~GR_PROCFIND;
54466 +#endif
54467 + }
54468 + } while_each_thread(task2, task);
54469 + read_unlock(&grsec_exec_file_lock);
54470 + read_unlock(&tasklist_lock);
54471 + rcu_read_unlock();
54472 +
54473 + return 0;
54474 +}
54475 +
54476 +void
54477 +gr_learn_resource(const struct task_struct *task,
54478 + const int res, const unsigned long wanted, const int gt)
54479 +{
54480 + struct acl_subject_label *acl;
54481 + const struct cred *cred;
54482 +
54483 + if (unlikely((gr_status & GR_READY) &&
54484 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54485 + goto skip_reslog;
54486 +
54487 +#ifdef CONFIG_GRKERNSEC_RESLOG
54488 + gr_log_resource(task, res, wanted, gt);
54489 +#endif
54490 + skip_reslog:
54491 +
54492 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54493 + return;
54494 +
54495 + acl = task->acl;
54496 +
54497 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54498 + !(acl->resmask & (1 << (unsigned short) res))))
54499 + return;
54500 +
54501 + if (wanted >= acl->res[res].rlim_cur) {
54502 + unsigned long res_add;
54503 +
54504 + res_add = wanted;
54505 + switch (res) {
54506 + case RLIMIT_CPU:
54507 + res_add += GR_RLIM_CPU_BUMP;
54508 + break;
54509 + case RLIMIT_FSIZE:
54510 + res_add += GR_RLIM_FSIZE_BUMP;
54511 + break;
54512 + case RLIMIT_DATA:
54513 + res_add += GR_RLIM_DATA_BUMP;
54514 + break;
54515 + case RLIMIT_STACK:
54516 + res_add += GR_RLIM_STACK_BUMP;
54517 + break;
54518 + case RLIMIT_CORE:
54519 + res_add += GR_RLIM_CORE_BUMP;
54520 + break;
54521 + case RLIMIT_RSS:
54522 + res_add += GR_RLIM_RSS_BUMP;
54523 + break;
54524 + case RLIMIT_NPROC:
54525 + res_add += GR_RLIM_NPROC_BUMP;
54526 + break;
54527 + case RLIMIT_NOFILE:
54528 + res_add += GR_RLIM_NOFILE_BUMP;
54529 + break;
54530 + case RLIMIT_MEMLOCK:
54531 + res_add += GR_RLIM_MEMLOCK_BUMP;
54532 + break;
54533 + case RLIMIT_AS:
54534 + res_add += GR_RLIM_AS_BUMP;
54535 + break;
54536 + case RLIMIT_LOCKS:
54537 + res_add += GR_RLIM_LOCKS_BUMP;
54538 + break;
54539 + case RLIMIT_SIGPENDING:
54540 + res_add += GR_RLIM_SIGPENDING_BUMP;
54541 + break;
54542 + case RLIMIT_MSGQUEUE:
54543 + res_add += GR_RLIM_MSGQUEUE_BUMP;
54544 + break;
54545 + case RLIMIT_NICE:
54546 + res_add += GR_RLIM_NICE_BUMP;
54547 + break;
54548 + case RLIMIT_RTPRIO:
54549 + res_add += GR_RLIM_RTPRIO_BUMP;
54550 + break;
54551 + case RLIMIT_RTTIME:
54552 + res_add += GR_RLIM_RTTIME_BUMP;
54553 + break;
54554 + }
54555 +
54556 + acl->res[res].rlim_cur = res_add;
54557 +
54558 + if (wanted > acl->res[res].rlim_max)
54559 + acl->res[res].rlim_max = res_add;
54560 +
54561 + /* only log the subject filename, since resource logging is supported for
54562 + single-subject learning only */
54563 + rcu_read_lock();
54564 + cred = __task_cred(task);
54565 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54566 + task->role->roletype, cred->uid, cred->gid, acl->filename,
54567 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54568 + "", (unsigned long) res, &task->signal->saved_ip);
54569 + rcu_read_unlock();
54570 + }
54571 +
54572 + return;
54573 +}
54574 +
54575 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54576 +void
54577 +pax_set_initial_flags(struct linux_binprm *bprm)
54578 +{
54579 + struct task_struct *task = current;
54580 + struct acl_subject_label *proc;
54581 + unsigned long flags;
54582 +
54583 + if (unlikely(!(gr_status & GR_READY)))
54584 + return;
54585 +
54586 + flags = pax_get_flags(task);
54587 +
54588 + proc = task->acl;
54589 +
54590 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54591 + flags &= ~MF_PAX_PAGEEXEC;
54592 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54593 + flags &= ~MF_PAX_SEGMEXEC;
54594 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54595 + flags &= ~MF_PAX_RANDMMAP;
54596 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54597 + flags &= ~MF_PAX_EMUTRAMP;
54598 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54599 + flags &= ~MF_PAX_MPROTECT;
54600 +
54601 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54602 + flags |= MF_PAX_PAGEEXEC;
54603 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54604 + flags |= MF_PAX_SEGMEXEC;
54605 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54606 + flags |= MF_PAX_RANDMMAP;
54607 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54608 + flags |= MF_PAX_EMUTRAMP;
54609 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54610 + flags |= MF_PAX_MPROTECT;
54611 +
54612 + pax_set_flags(task, flags);
54613 +
54614 + return;
54615 +}
54616 +#endif
54617 +
54618 +int
54619 +gr_handle_proc_ptrace(struct task_struct *task)
54620 +{
54621 + struct file *filp;
54622 + struct task_struct *tmp = task;
54623 + struct task_struct *curtemp = current;
54624 + __u32 retmode;
54625 +
54626 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54627 + if (unlikely(!(gr_status & GR_READY)))
54628 + return 0;
54629 +#endif
54630 +
54631 + read_lock(&tasklist_lock);
54632 + read_lock(&grsec_exec_file_lock);
54633 + filp = task->exec_file;
54634 +
54635 + while (tmp->pid > 0) {
54636 + if (tmp == curtemp)
54637 + break;
54638 + tmp = tmp->real_parent;
54639 + }
54640 +
54641 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54642 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54643 + read_unlock(&grsec_exec_file_lock);
54644 + read_unlock(&tasklist_lock);
54645 + return 1;
54646 + }
54647 +
54648 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54649 + if (!(gr_status & GR_READY)) {
54650 + read_unlock(&grsec_exec_file_lock);
54651 + read_unlock(&tasklist_lock);
54652 + return 0;
54653 + }
54654 +#endif
54655 +
54656 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54657 + read_unlock(&grsec_exec_file_lock);
54658 + read_unlock(&tasklist_lock);
54659 +
54660 + if (retmode & GR_NOPTRACE)
54661 + return 1;
54662 +
54663 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54664 + && (current->acl != task->acl || (current->acl != current->role->root_label
54665 + && current->pid != task->pid)))
54666 + return 1;
54667 +
54668 + return 0;
54669 +}
54670 +
54671 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54672 +{
54673 + if (unlikely(!(gr_status & GR_READY)))
54674 + return;
54675 +
54676 + if (!(current->role->roletype & GR_ROLE_GOD))
54677 + return;
54678 +
54679 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54680 + p->role->rolename, gr_task_roletype_to_char(p),
54681 + p->acl->filename);
54682 +}
54683 +
54684 +int
54685 +gr_handle_ptrace(struct task_struct *task, const long request)
54686 +{
54687 + struct task_struct *tmp = task;
54688 + struct task_struct *curtemp = current;
54689 + __u32 retmode;
54690 +
54691 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54692 + if (unlikely(!(gr_status & GR_READY)))
54693 + return 0;
54694 +#endif
54695 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
54696 + read_lock(&tasklist_lock);
54697 + while (tmp->pid > 0) {
54698 + if (tmp == curtemp)
54699 + break;
54700 + tmp = tmp->real_parent;
54701 + }
54702 +
54703 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54704 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54705 + read_unlock(&tasklist_lock);
54706 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54707 + return 1;
54708 + }
54709 + read_unlock(&tasklist_lock);
54710 + }
54711 +
54712 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54713 + if (!(gr_status & GR_READY))
54714 + return 0;
54715 +#endif
54716 +
54717 + read_lock(&grsec_exec_file_lock);
54718 + if (unlikely(!task->exec_file)) {
54719 + read_unlock(&grsec_exec_file_lock);
54720 + return 0;
54721 + }
54722 +
54723 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54724 + read_unlock(&grsec_exec_file_lock);
54725 +
54726 + if (retmode & GR_NOPTRACE) {
54727 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54728 + return 1;
54729 + }
54730 +
54731 + if (retmode & GR_PTRACERD) {
54732 + switch (request) {
54733 + case PTRACE_SEIZE:
54734 + case PTRACE_POKETEXT:
54735 + case PTRACE_POKEDATA:
54736 + case PTRACE_POKEUSR:
54737 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54738 + case PTRACE_SETREGS:
54739 + case PTRACE_SETFPREGS:
54740 +#endif
54741 +#ifdef CONFIG_X86
54742 + case PTRACE_SETFPXREGS:
54743 +#endif
54744 +#ifdef CONFIG_ALTIVEC
54745 + case PTRACE_SETVRREGS:
54746 +#endif
54747 + return 1;
54748 + default:
54749 + return 0;
54750 + }
54751 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
54752 + !(current->role->roletype & GR_ROLE_GOD) &&
54753 + (current->acl != task->acl)) {
54754 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54755 + return 1;
54756 + }
54757 +
54758 + return 0;
54759 +}
54760 +
54761 +static int is_writable_mmap(const struct file *filp)
54762 +{
54763 + struct task_struct *task = current;
54764 + struct acl_object_label *obj, *obj2;
54765 +
54766 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54767 + !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))) {
54768 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54769 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54770 + task->role->root_label);
54771 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54772 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54773 + return 1;
54774 + }
54775 + }
54776 + return 0;
54777 +}
54778 +
54779 +int
54780 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54781 +{
54782 + __u32 mode;
54783 +
54784 + if (unlikely(!file || !(prot & PROT_EXEC)))
54785 + return 1;
54786 +
54787 + if (is_writable_mmap(file))
54788 + return 0;
54789 +
54790 + mode =
54791 + gr_search_file(file->f_path.dentry,
54792 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54793 + file->f_path.mnt);
54794 +
54795 + if (!gr_tpe_allow(file))
54796 + return 0;
54797 +
54798 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54799 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54800 + return 0;
54801 + } else if (unlikely(!(mode & GR_EXEC))) {
54802 + return 0;
54803 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54804 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54805 + return 1;
54806 + }
54807 +
54808 + return 1;
54809 +}
54810 +
54811 +int
54812 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54813 +{
54814 + __u32 mode;
54815 +
54816 + if (unlikely(!file || !(prot & PROT_EXEC)))
54817 + return 1;
54818 +
54819 + if (is_writable_mmap(file))
54820 + return 0;
54821 +
54822 + mode =
54823 + gr_search_file(file->f_path.dentry,
54824 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54825 + file->f_path.mnt);
54826 +
54827 + if (!gr_tpe_allow(file))
54828 + return 0;
54829 +
54830 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54831 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54832 + return 0;
54833 + } else if (unlikely(!(mode & GR_EXEC))) {
54834 + return 0;
54835 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54836 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54837 + return 1;
54838 + }
54839 +
54840 + return 1;
54841 +}
54842 +
54843 +void
54844 +gr_acl_handle_psacct(struct task_struct *task, const long code)
54845 +{
54846 + unsigned long runtime;
54847 + unsigned long cputime;
54848 + unsigned int wday, cday;
54849 + __u8 whr, chr;
54850 + __u8 wmin, cmin;
54851 + __u8 wsec, csec;
54852 + struct timespec timeval;
54853 +
54854 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54855 + !(task->acl->mode & GR_PROCACCT)))
54856 + return;
54857 +
54858 + do_posix_clock_monotonic_gettime(&timeval);
54859 + runtime = timeval.tv_sec - task->start_time.tv_sec;
54860 + wday = runtime / (3600 * 24);
54861 + runtime -= wday * (3600 * 24);
54862 + whr = runtime / 3600;
54863 + runtime -= whr * 3600;
54864 + wmin = runtime / 60;
54865 + runtime -= wmin * 60;
54866 + wsec = runtime;
54867 +
54868 + cputime = (task->utime + task->stime) / HZ;
54869 + cday = cputime / (3600 * 24);
54870 + cputime -= cday * (3600 * 24);
54871 + chr = cputime / 3600;
54872 + cputime -= chr * 3600;
54873 + cmin = cputime / 60;
54874 + cputime -= cmin * 60;
54875 + csec = cputime;
54876 +
54877 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
54878 +
54879 + return;
54880 +}
54881 +
54882 +void gr_set_kernel_label(struct task_struct *task)
54883 +{
54884 + if (gr_status & GR_READY) {
54885 + task->role = kernel_role;
54886 + task->acl = kernel_role->root_label;
54887 + }
54888 + return;
54889 +}
54890 +
54891 +#ifdef CONFIG_TASKSTATS
54892 +int gr_is_taskstats_denied(int pid)
54893 +{
54894 + struct task_struct *task;
54895 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54896 + const struct cred *cred;
54897 +#endif
54898 + int ret = 0;
54899 +
54900 + /* restrict taskstats viewing to un-chrooted root users
54901 + who have the 'view' subject flag if the RBAC system is enabled
54902 + */
54903 +
54904 + rcu_read_lock();
54905 + read_lock(&tasklist_lock);
54906 + task = find_task_by_vpid(pid);
54907 + if (task) {
54908 +#ifdef CONFIG_GRKERNSEC_CHROOT
54909 + if (proc_is_chrooted(task))
54910 + ret = -EACCES;
54911 +#endif
54912 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54913 + cred = __task_cred(task);
54914 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54915 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
54916 + ret = -EACCES;
54917 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54918 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54919 + ret = -EACCES;
54920 +#endif
54921 +#endif
54922 + if (gr_status & GR_READY) {
54923 + if (!(task->acl->mode & GR_VIEW))
54924 + ret = -EACCES;
54925 + }
54926 + } else
54927 + ret = -ENOENT;
54928 +
54929 + read_unlock(&tasklist_lock);
54930 + rcu_read_unlock();
54931 +
54932 + return ret;
54933 +}
54934 +#endif
54935 +
54936 +/* AUXV entries are filled via a descendant of search_binary_handler
54937 + after we've already applied the subject for the target
54938 +*/
54939 +int gr_acl_enable_at_secure(void)
54940 +{
54941 + if (unlikely(!(gr_status & GR_READY)))
54942 + return 0;
54943 +
54944 + if (current->acl->mode & GR_ATSECURE)
54945 + return 1;
54946 +
54947 + return 0;
54948 +}
54949 +
54950 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
54951 +{
54952 + struct task_struct *task = current;
54953 + struct dentry *dentry = file->f_path.dentry;
54954 + struct vfsmount *mnt = file->f_path.mnt;
54955 + struct acl_object_label *obj, *tmp;
54956 + struct acl_subject_label *subj;
54957 + unsigned int bufsize;
54958 + int is_not_root;
54959 + char *path;
54960 + dev_t dev = __get_dev(dentry);
54961 +
54962 + if (unlikely(!(gr_status & GR_READY)))
54963 + return 1;
54964 +
54965 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54966 + return 1;
54967 +
54968 + /* ignore Eric Biederman */
54969 + if (IS_PRIVATE(dentry->d_inode))
54970 + return 1;
54971 +
54972 + subj = task->acl;
54973 + read_lock(&gr_inode_lock);
54974 + do {
54975 + obj = lookup_acl_obj_label(ino, dev, subj);
54976 + if (obj != NULL) {
54977 + read_unlock(&gr_inode_lock);
54978 + return (obj->mode & GR_FIND) ? 1 : 0;
54979 + }
54980 + } while ((subj = subj->parent_subject));
54981 + read_unlock(&gr_inode_lock);
54982 +
54983 + /* this is purely an optimization since we're looking for an object
54984 + for the directory we're doing a readdir on
54985 + if it's possible for any globbed object to match the entry we're
54986 + filling into the directory, then the object we find here will be
54987 + an anchor point with attached globbed objects
54988 + */
54989 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
54990 + if (obj->globbed == NULL)
54991 + return (obj->mode & GR_FIND) ? 1 : 0;
54992 +
54993 + is_not_root = ((obj->filename[0] == '/') &&
54994 + (obj->filename[1] == '\0')) ? 0 : 1;
54995 + bufsize = PAGE_SIZE - namelen - is_not_root;
54996 +
54997 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
54998 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
54999 + return 1;
55000 +
55001 + preempt_disable();
55002 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55003 + bufsize);
55004 +
55005 + bufsize = strlen(path);
55006 +
55007 + /* if base is "/", don't append an additional slash */
55008 + if (is_not_root)
55009 + *(path + bufsize) = '/';
55010 + memcpy(path + bufsize + is_not_root, name, namelen);
55011 + *(path + bufsize + namelen + is_not_root) = '\0';
55012 +
55013 + tmp = obj->globbed;
55014 + while (tmp) {
55015 + if (!glob_match(tmp->filename, path)) {
55016 + preempt_enable();
55017 + return (tmp->mode & GR_FIND) ? 1 : 0;
55018 + }
55019 + tmp = tmp->next;
55020 + }
55021 + preempt_enable();
55022 + return (obj->mode & GR_FIND) ? 1 : 0;
55023 +}
55024 +
55025 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55026 +EXPORT_SYMBOL(gr_acl_is_enabled);
55027 +#endif
55028 +EXPORT_SYMBOL(gr_learn_resource);
55029 +EXPORT_SYMBOL(gr_set_kernel_label);
55030 +#ifdef CONFIG_SECURITY
55031 +EXPORT_SYMBOL(gr_check_user_change);
55032 +EXPORT_SYMBOL(gr_check_group_change);
55033 +#endif
55034 +
55035 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55036 new file mode 100644
55037 index 0000000..34fefda
55038 --- /dev/null
55039 +++ b/grsecurity/gracl_alloc.c
55040 @@ -0,0 +1,105 @@
55041 +#include <linux/kernel.h>
55042 +#include <linux/mm.h>
55043 +#include <linux/slab.h>
55044 +#include <linux/vmalloc.h>
55045 +#include <linux/gracl.h>
55046 +#include <linux/grsecurity.h>
55047 +
55048 +static unsigned long alloc_stack_next = 1;
55049 +static unsigned long alloc_stack_size = 1;
55050 +static void **alloc_stack;
55051 +
55052 +static __inline__ int
55053 +alloc_pop(void)
55054 +{
55055 + if (alloc_stack_next == 1)
55056 + return 0;
55057 +
55058 + kfree(alloc_stack[alloc_stack_next - 2]);
55059 +
55060 + alloc_stack_next--;
55061 +
55062 + return 1;
55063 +}
55064 +
55065 +static __inline__ int
55066 +alloc_push(void *buf)
55067 +{
55068 + if (alloc_stack_next >= alloc_stack_size)
55069 + return 1;
55070 +
55071 + alloc_stack[alloc_stack_next - 1] = buf;
55072 +
55073 + alloc_stack_next++;
55074 +
55075 + return 0;
55076 +}
55077 +
55078 +void *
55079 +acl_alloc(unsigned long len)
55080 +{
55081 + void *ret = NULL;
55082 +
55083 + if (!len || len > PAGE_SIZE)
55084 + goto out;
55085 +
55086 + ret = kmalloc(len, GFP_KERNEL);
55087 +
55088 + if (ret) {
55089 + if (alloc_push(ret)) {
55090 + kfree(ret);
55091 + ret = NULL;
55092 + }
55093 + }
55094 +
55095 +out:
55096 + return ret;
55097 +}
55098 +
55099 +void *
55100 +acl_alloc_num(unsigned long num, unsigned long len)
55101 +{
55102 + if (!len || (num > (PAGE_SIZE / len)))
55103 + return NULL;
55104 +
55105 + return acl_alloc(num * len);
55106 +}
55107 +
55108 +void
55109 +acl_free_all(void)
55110 +{
55111 + if (gr_acl_is_enabled() || !alloc_stack)
55112 + return;
55113 +
55114 + while (alloc_pop()) ;
55115 +
55116 + if (alloc_stack) {
55117 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55118 + kfree(alloc_stack);
55119 + else
55120 + vfree(alloc_stack);
55121 + }
55122 +
55123 + alloc_stack = NULL;
55124 + alloc_stack_size = 1;
55125 + alloc_stack_next = 1;
55126 +
55127 + return;
55128 +}
55129 +
55130 +int
55131 +acl_alloc_stack_init(unsigned long size)
55132 +{
55133 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55134 + alloc_stack =
55135 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55136 + else
55137 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55138 +
55139 + alloc_stack_size = size;
55140 +
55141 + if (!alloc_stack)
55142 + return 0;
55143 + else
55144 + return 1;
55145 +}
55146 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55147 new file mode 100644
55148 index 0000000..6d21049
55149 --- /dev/null
55150 +++ b/grsecurity/gracl_cap.c
55151 @@ -0,0 +1,110 @@
55152 +#include <linux/kernel.h>
55153 +#include <linux/module.h>
55154 +#include <linux/sched.h>
55155 +#include <linux/gracl.h>
55156 +#include <linux/grsecurity.h>
55157 +#include <linux/grinternal.h>
55158 +
55159 +extern const char *captab_log[];
55160 +extern int captab_log_entries;
55161 +
55162 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55163 +{
55164 + struct acl_subject_label *curracl;
55165 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55166 + kernel_cap_t cap_audit = __cap_empty_set;
55167 +
55168 + if (!gr_acl_is_enabled())
55169 + return 1;
55170 +
55171 + curracl = task->acl;
55172 +
55173 + cap_drop = curracl->cap_lower;
55174 + cap_mask = curracl->cap_mask;
55175 + cap_audit = curracl->cap_invert_audit;
55176 +
55177 + while ((curracl = curracl->parent_subject)) {
55178 + /* if the cap isn't specified in the current computed mask but is specified in the
55179 + current level subject, and is lowered in the current level subject, then add
55180 + it to the set of dropped capabilities
55181 + otherwise, add the current level subject's mask to the current computed mask
55182 + */
55183 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55184 + cap_raise(cap_mask, cap);
55185 + if (cap_raised(curracl->cap_lower, cap))
55186 + cap_raise(cap_drop, cap);
55187 + if (cap_raised(curracl->cap_invert_audit, cap))
55188 + cap_raise(cap_audit, cap);
55189 + }
55190 + }
55191 +
55192 + if (!cap_raised(cap_drop, cap)) {
55193 + if (cap_raised(cap_audit, cap))
55194 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55195 + return 1;
55196 + }
55197 +
55198 + curracl = task->acl;
55199 +
55200 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55201 + && cap_raised(cred->cap_effective, cap)) {
55202 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55203 + task->role->roletype, cred->uid,
55204 + cred->gid, task->exec_file ?
55205 + gr_to_filename(task->exec_file->f_path.dentry,
55206 + task->exec_file->f_path.mnt) : curracl->filename,
55207 + curracl->filename, 0UL,
55208 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55209 + return 1;
55210 + }
55211 +
55212 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55213 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55214 +
55215 + return 0;
55216 +}
55217 +
55218 +int
55219 +gr_acl_is_capable(const int cap)
55220 +{
55221 + return gr_task_acl_is_capable(current, current_cred(), cap);
55222 +}
55223 +
55224 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55225 +{
55226 + struct acl_subject_label *curracl;
55227 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55228 +
55229 + if (!gr_acl_is_enabled())
55230 + return 1;
55231 +
55232 + curracl = task->acl;
55233 +
55234 + cap_drop = curracl->cap_lower;
55235 + cap_mask = curracl->cap_mask;
55236 +
55237 + while ((curracl = curracl->parent_subject)) {
55238 + /* if the cap isn't specified in the current computed mask but is specified in the
55239 + current level subject, and is lowered in the current level subject, then add
55240 + it to the set of dropped capabilities
55241 + otherwise, add the current level subject's mask to the current computed mask
55242 + */
55243 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55244 + cap_raise(cap_mask, cap);
55245 + if (cap_raised(curracl->cap_lower, cap))
55246 + cap_raise(cap_drop, cap);
55247 + }
55248 + }
55249 +
55250 + if (!cap_raised(cap_drop, cap))
55251 + return 1;
55252 +
55253 + return 0;
55254 +}
55255 +
55256 +int
55257 +gr_acl_is_capable_nolog(const int cap)
55258 +{
55259 + return gr_task_acl_is_capable_nolog(current, cap);
55260 +}
55261 +
55262 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55263 new file mode 100644
55264 index 0000000..d28e241
55265 --- /dev/null
55266 +++ b/grsecurity/gracl_fs.c
55267 @@ -0,0 +1,437 @@
55268 +#include <linux/kernel.h>
55269 +#include <linux/sched.h>
55270 +#include <linux/types.h>
55271 +#include <linux/fs.h>
55272 +#include <linux/file.h>
55273 +#include <linux/stat.h>
55274 +#include <linux/grsecurity.h>
55275 +#include <linux/grinternal.h>
55276 +#include <linux/gracl.h>
55277 +
55278 +umode_t
55279 +gr_acl_umask(void)
55280 +{
55281 + if (unlikely(!gr_acl_is_enabled()))
55282 + return 0;
55283 +
55284 + return current->role->umask;
55285 +}
55286 +
55287 +__u32
55288 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55289 + const struct vfsmount * mnt)
55290 +{
55291 + __u32 mode;
55292 +
55293 + if (unlikely(!dentry->d_inode))
55294 + return GR_FIND;
55295 +
55296 + mode =
55297 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55298 +
55299 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55300 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55301 + return mode;
55302 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55303 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55304 + return 0;
55305 + } else if (unlikely(!(mode & GR_FIND)))
55306 + return 0;
55307 +
55308 + return GR_FIND;
55309 +}
55310 +
55311 +__u32
55312 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55313 + int acc_mode)
55314 +{
55315 + __u32 reqmode = GR_FIND;
55316 + __u32 mode;
55317 +
55318 + if (unlikely(!dentry->d_inode))
55319 + return reqmode;
55320 +
55321 + if (acc_mode & MAY_APPEND)
55322 + reqmode |= GR_APPEND;
55323 + else if (acc_mode & MAY_WRITE)
55324 + reqmode |= GR_WRITE;
55325 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55326 + reqmode |= GR_READ;
55327 +
55328 + mode =
55329 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55330 + mnt);
55331 +
55332 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55333 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55334 + reqmode & GR_READ ? " reading" : "",
55335 + reqmode & GR_WRITE ? " writing" : reqmode &
55336 + GR_APPEND ? " appending" : "");
55337 + return reqmode;
55338 + } else
55339 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55340 + {
55341 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55342 + reqmode & GR_READ ? " reading" : "",
55343 + reqmode & GR_WRITE ? " writing" : reqmode &
55344 + GR_APPEND ? " appending" : "");
55345 + return 0;
55346 + } else if (unlikely((mode & reqmode) != reqmode))
55347 + return 0;
55348 +
55349 + return reqmode;
55350 +}
55351 +
55352 +__u32
55353 +gr_acl_handle_creat(const struct dentry * dentry,
55354 + const struct dentry * p_dentry,
55355 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55356 + const int imode)
55357 +{
55358 + __u32 reqmode = GR_WRITE | GR_CREATE;
55359 + __u32 mode;
55360 +
55361 + if (acc_mode & MAY_APPEND)
55362 + reqmode |= GR_APPEND;
55363 + // if a directory was required or the directory already exists, then
55364 + // don't count this open as a read
55365 + if ((acc_mode & MAY_READ) &&
55366 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55367 + reqmode |= GR_READ;
55368 + if ((open_flags & O_CREAT) &&
55369 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
55370 + reqmode |= GR_SETID;
55371 +
55372 + mode =
55373 + gr_check_create(dentry, p_dentry, p_mnt,
55374 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55375 +
55376 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55377 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55378 + reqmode & GR_READ ? " reading" : "",
55379 + reqmode & GR_WRITE ? " writing" : reqmode &
55380 + GR_APPEND ? " appending" : "");
55381 + return reqmode;
55382 + } else
55383 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55384 + {
55385 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55386 + reqmode & GR_READ ? " reading" : "",
55387 + reqmode & GR_WRITE ? " writing" : reqmode &
55388 + GR_APPEND ? " appending" : "");
55389 + return 0;
55390 + } else if (unlikely((mode & reqmode) != reqmode))
55391 + return 0;
55392 +
55393 + return reqmode;
55394 +}
55395 +
55396 +__u32
55397 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55398 + const int fmode)
55399 +{
55400 + __u32 mode, reqmode = GR_FIND;
55401 +
55402 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55403 + reqmode |= GR_EXEC;
55404 + if (fmode & S_IWOTH)
55405 + reqmode |= GR_WRITE;
55406 + if (fmode & S_IROTH)
55407 + reqmode |= GR_READ;
55408 +
55409 + mode =
55410 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55411 + mnt);
55412 +
55413 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55414 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55415 + reqmode & GR_READ ? " reading" : "",
55416 + reqmode & GR_WRITE ? " writing" : "",
55417 + reqmode & GR_EXEC ? " executing" : "");
55418 + return reqmode;
55419 + } else
55420 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55421 + {
55422 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55423 + reqmode & GR_READ ? " reading" : "",
55424 + reqmode & GR_WRITE ? " writing" : "",
55425 + reqmode & GR_EXEC ? " executing" : "");
55426 + return 0;
55427 + } else if (unlikely((mode & reqmode) != reqmode))
55428 + return 0;
55429 +
55430 + return reqmode;
55431 +}
55432 +
55433 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55434 +{
55435 + __u32 mode;
55436 +
55437 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55438 +
55439 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55440 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55441 + return mode;
55442 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55443 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55444 + return 0;
55445 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55446 + return 0;
55447 +
55448 + return (reqmode);
55449 +}
55450 +
55451 +__u32
55452 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55453 +{
55454 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55455 +}
55456 +
55457 +__u32
55458 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55459 +{
55460 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55461 +}
55462 +
55463 +__u32
55464 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55465 +{
55466 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55467 +}
55468 +
55469 +__u32
55470 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55471 +{
55472 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55473 +}
55474 +
55475 +__u32
55476 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55477 + umode_t *modeptr)
55478 +{
55479 + umode_t mode;
55480 +
55481 + *modeptr &= ~gr_acl_umask();
55482 + mode = *modeptr;
55483 +
55484 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55485 + return 1;
55486 +
55487 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
55488 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
55489 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55490 + GR_CHMOD_ACL_MSG);
55491 + } else {
55492 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55493 + }
55494 +}
55495 +
55496 +__u32
55497 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55498 +{
55499 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55500 +}
55501 +
55502 +__u32
55503 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55504 +{
55505 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55506 +}
55507 +
55508 +__u32
55509 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55510 +{
55511 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55512 +}
55513 +
55514 +__u32
55515 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55516 +{
55517 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55518 + GR_UNIXCONNECT_ACL_MSG);
55519 +}
55520 +
55521 +/* hardlinks require at minimum create and link permission,
55522 + any additional privilege required is based on the
55523 + privilege of the file being linked to
55524 +*/
55525 +__u32
55526 +gr_acl_handle_link(const struct dentry * new_dentry,
55527 + const struct dentry * parent_dentry,
55528 + const struct vfsmount * parent_mnt,
55529 + const struct dentry * old_dentry,
55530 + const struct vfsmount * old_mnt, const char *to)
55531 +{
55532 + __u32 mode;
55533 + __u32 needmode = GR_CREATE | GR_LINK;
55534 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55535 +
55536 + mode =
55537 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55538 + old_mnt);
55539 +
55540 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55541 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55542 + return mode;
55543 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55544 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55545 + return 0;
55546 + } else if (unlikely((mode & needmode) != needmode))
55547 + return 0;
55548 +
55549 + return 1;
55550 +}
55551 +
55552 +__u32
55553 +gr_acl_handle_symlink(const struct dentry * new_dentry,
55554 + const struct dentry * parent_dentry,
55555 + const struct vfsmount * parent_mnt, const char *from)
55556 +{
55557 + __u32 needmode = GR_WRITE | GR_CREATE;
55558 + __u32 mode;
55559 +
55560 + mode =
55561 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
55562 + GR_CREATE | GR_AUDIT_CREATE |
55563 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55564 +
55565 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55566 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55567 + return mode;
55568 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55569 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55570 + return 0;
55571 + } else if (unlikely((mode & needmode) != needmode))
55572 + return 0;
55573 +
55574 + return (GR_WRITE | GR_CREATE);
55575 +}
55576 +
55577 +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)
55578 +{
55579 + __u32 mode;
55580 +
55581 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55582 +
55583 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55584 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55585 + return mode;
55586 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55587 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55588 + return 0;
55589 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55590 + return 0;
55591 +
55592 + return (reqmode);
55593 +}
55594 +
55595 +__u32
55596 +gr_acl_handle_mknod(const struct dentry * new_dentry,
55597 + const struct dentry * parent_dentry,
55598 + const struct vfsmount * parent_mnt,
55599 + const int mode)
55600 +{
55601 + __u32 reqmode = GR_WRITE | GR_CREATE;
55602 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
55603 + reqmode |= GR_SETID;
55604 +
55605 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55606 + reqmode, GR_MKNOD_ACL_MSG);
55607 +}
55608 +
55609 +__u32
55610 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
55611 + const struct dentry *parent_dentry,
55612 + const struct vfsmount *parent_mnt)
55613 +{
55614 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55615 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55616 +}
55617 +
55618 +#define RENAME_CHECK_SUCCESS(old, new) \
55619 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55620 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55621 +
55622 +int
55623 +gr_acl_handle_rename(struct dentry *new_dentry,
55624 + struct dentry *parent_dentry,
55625 + const struct vfsmount *parent_mnt,
55626 + struct dentry *old_dentry,
55627 + struct inode *old_parent_inode,
55628 + struct vfsmount *old_mnt, const char *newname)
55629 +{
55630 + __u32 comp1, comp2;
55631 + int error = 0;
55632 +
55633 + if (unlikely(!gr_acl_is_enabled()))
55634 + return 0;
55635 +
55636 + if (!new_dentry->d_inode) {
55637 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55638 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55639 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55640 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55641 + GR_DELETE | GR_AUDIT_DELETE |
55642 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55643 + GR_SUPPRESS, old_mnt);
55644 + } else {
55645 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55646 + GR_CREATE | GR_DELETE |
55647 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55648 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55649 + GR_SUPPRESS, parent_mnt);
55650 + comp2 =
55651 + gr_search_file(old_dentry,
55652 + GR_READ | GR_WRITE | GR_AUDIT_READ |
55653 + GR_DELETE | GR_AUDIT_DELETE |
55654 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55655 + }
55656 +
55657 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55658 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55659 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55660 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55661 + && !(comp2 & GR_SUPPRESS)) {
55662 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55663 + error = -EACCES;
55664 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55665 + error = -EACCES;
55666 +
55667 + return error;
55668 +}
55669 +
55670 +void
55671 +gr_acl_handle_exit(void)
55672 +{
55673 + u16 id;
55674 + char *rolename;
55675 + struct file *exec_file;
55676 +
55677 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55678 + !(current->role->roletype & GR_ROLE_PERSIST))) {
55679 + id = current->acl_role_id;
55680 + rolename = current->role->rolename;
55681 + gr_set_acls(1);
55682 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55683 + }
55684 +
55685 + write_lock(&grsec_exec_file_lock);
55686 + exec_file = current->exec_file;
55687 + current->exec_file = NULL;
55688 + write_unlock(&grsec_exec_file_lock);
55689 +
55690 + if (exec_file)
55691 + fput(exec_file);
55692 +}
55693 +
55694 +int
55695 +gr_acl_handle_procpidmem(const struct task_struct *task)
55696 +{
55697 + if (unlikely(!gr_acl_is_enabled()))
55698 + return 0;
55699 +
55700 + if (task != current && task->acl->mode & GR_PROTPROCFD)
55701 + return -EACCES;
55702 +
55703 + return 0;
55704 +}
55705 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55706 new file mode 100644
55707 index 0000000..58800a7
55708 --- /dev/null
55709 +++ b/grsecurity/gracl_ip.c
55710 @@ -0,0 +1,384 @@
55711 +#include <linux/kernel.h>
55712 +#include <asm/uaccess.h>
55713 +#include <asm/errno.h>
55714 +#include <net/sock.h>
55715 +#include <linux/file.h>
55716 +#include <linux/fs.h>
55717 +#include <linux/net.h>
55718 +#include <linux/in.h>
55719 +#include <linux/skbuff.h>
55720 +#include <linux/ip.h>
55721 +#include <linux/udp.h>
55722 +#include <linux/types.h>
55723 +#include <linux/sched.h>
55724 +#include <linux/netdevice.h>
55725 +#include <linux/inetdevice.h>
55726 +#include <linux/gracl.h>
55727 +#include <linux/grsecurity.h>
55728 +#include <linux/grinternal.h>
55729 +
55730 +#define GR_BIND 0x01
55731 +#define GR_CONNECT 0x02
55732 +#define GR_INVERT 0x04
55733 +#define GR_BINDOVERRIDE 0x08
55734 +#define GR_CONNECTOVERRIDE 0x10
55735 +#define GR_SOCK_FAMILY 0x20
55736 +
55737 +static const char * gr_protocols[IPPROTO_MAX] = {
55738 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55739 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55740 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55741 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55742 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55743 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55744 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55745 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55746 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55747 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55748 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55749 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55750 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55751 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55752 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55753 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55754 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55755 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55756 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55757 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55758 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55759 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55760 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55761 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55762 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55763 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55764 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55765 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55766 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55767 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55768 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55769 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55770 + };
55771 +
55772 +static const char * gr_socktypes[SOCK_MAX] = {
55773 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55774 + "unknown:7", "unknown:8", "unknown:9", "packet"
55775 + };
55776 +
55777 +static const char * gr_sockfamilies[AF_MAX+1] = {
55778 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55779 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55780 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55781 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55782 + };
55783 +
55784 +const char *
55785 +gr_proto_to_name(unsigned char proto)
55786 +{
55787 + return gr_protocols[proto];
55788 +}
55789 +
55790 +const char *
55791 +gr_socktype_to_name(unsigned char type)
55792 +{
55793 + return gr_socktypes[type];
55794 +}
55795 +
55796 +const char *
55797 +gr_sockfamily_to_name(unsigned char family)
55798 +{
55799 + return gr_sockfamilies[family];
55800 +}
55801 +
55802 +int
55803 +gr_search_socket(const int domain, const int type, const int protocol)
55804 +{
55805 + struct acl_subject_label *curr;
55806 + const struct cred *cred = current_cred();
55807 +
55808 + if (unlikely(!gr_acl_is_enabled()))
55809 + goto exit;
55810 +
55811 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
55812 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55813 + goto exit; // let the kernel handle it
55814 +
55815 + curr = current->acl;
55816 +
55817 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55818 + /* the family is allowed, if this is PF_INET allow it only if
55819 + the extra sock type/protocol checks pass */
55820 + if (domain == PF_INET)
55821 + goto inet_check;
55822 + goto exit;
55823 + } else {
55824 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55825 + __u32 fakeip = 0;
55826 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55827 + current->role->roletype, cred->uid,
55828 + cred->gid, current->exec_file ?
55829 + gr_to_filename(current->exec_file->f_path.dentry,
55830 + current->exec_file->f_path.mnt) :
55831 + curr->filename, curr->filename,
55832 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55833 + &current->signal->saved_ip);
55834 + goto exit;
55835 + }
55836 + goto exit_fail;
55837 + }
55838 +
55839 +inet_check:
55840 + /* the rest of this checking is for IPv4 only */
55841 + if (!curr->ips)
55842 + goto exit;
55843 +
55844 + if ((curr->ip_type & (1 << type)) &&
55845 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55846 + goto exit;
55847 +
55848 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55849 + /* we don't place acls on raw sockets , and sometimes
55850 + dgram/ip sockets are opened for ioctl and not
55851 + bind/connect, so we'll fake a bind learn log */
55852 + if (type == SOCK_RAW || type == SOCK_PACKET) {
55853 + __u32 fakeip = 0;
55854 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55855 + current->role->roletype, cred->uid,
55856 + cred->gid, current->exec_file ?
55857 + gr_to_filename(current->exec_file->f_path.dentry,
55858 + current->exec_file->f_path.mnt) :
55859 + curr->filename, curr->filename,
55860 + &fakeip, 0, type,
55861 + protocol, GR_CONNECT, &current->signal->saved_ip);
55862 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55863 + __u32 fakeip = 0;
55864 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55865 + current->role->roletype, cred->uid,
55866 + cred->gid, current->exec_file ?
55867 + gr_to_filename(current->exec_file->f_path.dentry,
55868 + current->exec_file->f_path.mnt) :
55869 + curr->filename, curr->filename,
55870 + &fakeip, 0, type,
55871 + protocol, GR_BIND, &current->signal->saved_ip);
55872 + }
55873 + /* we'll log when they use connect or bind */
55874 + goto exit;
55875 + }
55876 +
55877 +exit_fail:
55878 + if (domain == PF_INET)
55879 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
55880 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
55881 + else
55882 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55883 + gr_socktype_to_name(type), protocol);
55884 +
55885 + return 0;
55886 +exit:
55887 + return 1;
55888 +}
55889 +
55890 +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)
55891 +{
55892 + if ((ip->mode & mode) &&
55893 + (ip_port >= ip->low) &&
55894 + (ip_port <= ip->high) &&
55895 + ((ntohl(ip_addr) & our_netmask) ==
55896 + (ntohl(our_addr) & our_netmask))
55897 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55898 + && (ip->type & (1 << type))) {
55899 + if (ip->mode & GR_INVERT)
55900 + return 2; // specifically denied
55901 + else
55902 + return 1; // allowed
55903 + }
55904 +
55905 + return 0; // not specifically allowed, may continue parsing
55906 +}
55907 +
55908 +static int
55909 +gr_search_connectbind(const int full_mode, struct sock *sk,
55910 + struct sockaddr_in *addr, const int type)
55911 +{
55912 + char iface[IFNAMSIZ] = {0};
55913 + struct acl_subject_label *curr;
55914 + struct acl_ip_label *ip;
55915 + struct inet_sock *isk;
55916 + struct net_device *dev;
55917 + struct in_device *idev;
55918 + unsigned long i;
55919 + int ret;
55920 + int mode = full_mode & (GR_BIND | GR_CONNECT);
55921 + __u32 ip_addr = 0;
55922 + __u32 our_addr;
55923 + __u32 our_netmask;
55924 + char *p;
55925 + __u16 ip_port = 0;
55926 + const struct cred *cred = current_cred();
55927 +
55928 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55929 + return 0;
55930 +
55931 + curr = current->acl;
55932 + isk = inet_sk(sk);
55933 +
55934 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55935 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55936 + addr->sin_addr.s_addr = curr->inaddr_any_override;
55937 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55938 + struct sockaddr_in saddr;
55939 + int err;
55940 +
55941 + saddr.sin_family = AF_INET;
55942 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
55943 + saddr.sin_port = isk->inet_sport;
55944 +
55945 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55946 + if (err)
55947 + return err;
55948 +
55949 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55950 + if (err)
55951 + return err;
55952 + }
55953 +
55954 + if (!curr->ips)
55955 + return 0;
55956 +
55957 + ip_addr = addr->sin_addr.s_addr;
55958 + ip_port = ntohs(addr->sin_port);
55959 +
55960 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55961 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55962 + current->role->roletype, cred->uid,
55963 + cred->gid, current->exec_file ?
55964 + gr_to_filename(current->exec_file->f_path.dentry,
55965 + current->exec_file->f_path.mnt) :
55966 + curr->filename, curr->filename,
55967 + &ip_addr, ip_port, type,
55968 + sk->sk_protocol, mode, &current->signal->saved_ip);
55969 + return 0;
55970 + }
55971 +
55972 + for (i = 0; i < curr->ip_num; i++) {
55973 + ip = *(curr->ips + i);
55974 + if (ip->iface != NULL) {
55975 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
55976 + p = strchr(iface, ':');
55977 + if (p != NULL)
55978 + *p = '\0';
55979 + dev = dev_get_by_name(sock_net(sk), iface);
55980 + if (dev == NULL)
55981 + continue;
55982 + idev = in_dev_get(dev);
55983 + if (idev == NULL) {
55984 + dev_put(dev);
55985 + continue;
55986 + }
55987 + rcu_read_lock();
55988 + for_ifa(idev) {
55989 + if (!strcmp(ip->iface, ifa->ifa_label)) {
55990 + our_addr = ifa->ifa_address;
55991 + our_netmask = 0xffffffff;
55992 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55993 + if (ret == 1) {
55994 + rcu_read_unlock();
55995 + in_dev_put(idev);
55996 + dev_put(dev);
55997 + return 0;
55998 + } else if (ret == 2) {
55999 + rcu_read_unlock();
56000 + in_dev_put(idev);
56001 + dev_put(dev);
56002 + goto denied;
56003 + }
56004 + }
56005 + } endfor_ifa(idev);
56006 + rcu_read_unlock();
56007 + in_dev_put(idev);
56008 + dev_put(dev);
56009 + } else {
56010 + our_addr = ip->addr;
56011 + our_netmask = ip->netmask;
56012 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56013 + if (ret == 1)
56014 + return 0;
56015 + else if (ret == 2)
56016 + goto denied;
56017 + }
56018 + }
56019 +
56020 +denied:
56021 + if (mode == GR_BIND)
56022 + 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));
56023 + else if (mode == GR_CONNECT)
56024 + 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));
56025 +
56026 + return -EACCES;
56027 +}
56028 +
56029 +int
56030 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56031 +{
56032 + /* always allow disconnection of dgram sockets with connect */
56033 + if (addr->sin_family == AF_UNSPEC)
56034 + return 0;
56035 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56036 +}
56037 +
56038 +int
56039 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56040 +{
56041 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56042 +}
56043 +
56044 +int gr_search_listen(struct socket *sock)
56045 +{
56046 + struct sock *sk = sock->sk;
56047 + struct sockaddr_in addr;
56048 +
56049 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56050 + addr.sin_port = inet_sk(sk)->inet_sport;
56051 +
56052 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56053 +}
56054 +
56055 +int gr_search_accept(struct socket *sock)
56056 +{
56057 + struct sock *sk = sock->sk;
56058 + struct sockaddr_in addr;
56059 +
56060 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56061 + addr.sin_port = inet_sk(sk)->inet_sport;
56062 +
56063 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56064 +}
56065 +
56066 +int
56067 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56068 +{
56069 + if (addr)
56070 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56071 + else {
56072 + struct sockaddr_in sin;
56073 + const struct inet_sock *inet = inet_sk(sk);
56074 +
56075 + sin.sin_addr.s_addr = inet->inet_daddr;
56076 + sin.sin_port = inet->inet_dport;
56077 +
56078 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56079 + }
56080 +}
56081 +
56082 +int
56083 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56084 +{
56085 + struct sockaddr_in sin;
56086 +
56087 + if (unlikely(skb->len < sizeof (struct udphdr)))
56088 + return 0; // skip this packet
56089 +
56090 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56091 + sin.sin_port = udp_hdr(skb)->source;
56092 +
56093 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56094 +}
56095 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56096 new file mode 100644
56097 index 0000000..25f54ef
56098 --- /dev/null
56099 +++ b/grsecurity/gracl_learn.c
56100 @@ -0,0 +1,207 @@
56101 +#include <linux/kernel.h>
56102 +#include <linux/mm.h>
56103 +#include <linux/sched.h>
56104 +#include <linux/poll.h>
56105 +#include <linux/string.h>
56106 +#include <linux/file.h>
56107 +#include <linux/types.h>
56108 +#include <linux/vmalloc.h>
56109 +#include <linux/grinternal.h>
56110 +
56111 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56112 + size_t count, loff_t *ppos);
56113 +extern int gr_acl_is_enabled(void);
56114 +
56115 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56116 +static int gr_learn_attached;
56117 +
56118 +/* use a 512k buffer */
56119 +#define LEARN_BUFFER_SIZE (512 * 1024)
56120 +
56121 +static DEFINE_SPINLOCK(gr_learn_lock);
56122 +static DEFINE_MUTEX(gr_learn_user_mutex);
56123 +
56124 +/* we need to maintain two buffers, so that the kernel context of grlearn
56125 + uses a semaphore around the userspace copying, and the other kernel contexts
56126 + use a spinlock when copying into the buffer, since they cannot sleep
56127 +*/
56128 +static char *learn_buffer;
56129 +static char *learn_buffer_user;
56130 +static int learn_buffer_len;
56131 +static int learn_buffer_user_len;
56132 +
56133 +static ssize_t
56134 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56135 +{
56136 + DECLARE_WAITQUEUE(wait, current);
56137 + ssize_t retval = 0;
56138 +
56139 + add_wait_queue(&learn_wait, &wait);
56140 + set_current_state(TASK_INTERRUPTIBLE);
56141 + do {
56142 + mutex_lock(&gr_learn_user_mutex);
56143 + spin_lock(&gr_learn_lock);
56144 + if (learn_buffer_len)
56145 + break;
56146 + spin_unlock(&gr_learn_lock);
56147 + mutex_unlock(&gr_learn_user_mutex);
56148 + if (file->f_flags & O_NONBLOCK) {
56149 + retval = -EAGAIN;
56150 + goto out;
56151 + }
56152 + if (signal_pending(current)) {
56153 + retval = -ERESTARTSYS;
56154 + goto out;
56155 + }
56156 +
56157 + schedule();
56158 + } while (1);
56159 +
56160 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56161 + learn_buffer_user_len = learn_buffer_len;
56162 + retval = learn_buffer_len;
56163 + learn_buffer_len = 0;
56164 +
56165 + spin_unlock(&gr_learn_lock);
56166 +
56167 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56168 + retval = -EFAULT;
56169 +
56170 + mutex_unlock(&gr_learn_user_mutex);
56171 +out:
56172 + set_current_state(TASK_RUNNING);
56173 + remove_wait_queue(&learn_wait, &wait);
56174 + return retval;
56175 +}
56176 +
56177 +static unsigned int
56178 +poll_learn(struct file * file, poll_table * wait)
56179 +{
56180 + poll_wait(file, &learn_wait, wait);
56181 +
56182 + if (learn_buffer_len)
56183 + return (POLLIN | POLLRDNORM);
56184 +
56185 + return 0;
56186 +}
56187 +
56188 +void
56189 +gr_clear_learn_entries(void)
56190 +{
56191 + char *tmp;
56192 +
56193 + mutex_lock(&gr_learn_user_mutex);
56194 + spin_lock(&gr_learn_lock);
56195 + tmp = learn_buffer;
56196 + learn_buffer = NULL;
56197 + spin_unlock(&gr_learn_lock);
56198 + if (tmp)
56199 + vfree(tmp);
56200 + if (learn_buffer_user != NULL) {
56201 + vfree(learn_buffer_user);
56202 + learn_buffer_user = NULL;
56203 + }
56204 + learn_buffer_len = 0;
56205 + mutex_unlock(&gr_learn_user_mutex);
56206 +
56207 + return;
56208 +}
56209 +
56210 +void
56211 +gr_add_learn_entry(const char *fmt, ...)
56212 +{
56213 + va_list args;
56214 + unsigned int len;
56215 +
56216 + if (!gr_learn_attached)
56217 + return;
56218 +
56219 + spin_lock(&gr_learn_lock);
56220 +
56221 + /* leave a gap at the end so we know when it's "full" but don't have to
56222 + compute the exact length of the string we're trying to append
56223 + */
56224 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56225 + spin_unlock(&gr_learn_lock);
56226 + wake_up_interruptible(&learn_wait);
56227 + return;
56228 + }
56229 + if (learn_buffer == NULL) {
56230 + spin_unlock(&gr_learn_lock);
56231 + return;
56232 + }
56233 +
56234 + va_start(args, fmt);
56235 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56236 + va_end(args);
56237 +
56238 + learn_buffer_len += len + 1;
56239 +
56240 + spin_unlock(&gr_learn_lock);
56241 + wake_up_interruptible(&learn_wait);
56242 +
56243 + return;
56244 +}
56245 +
56246 +static int
56247 +open_learn(struct inode *inode, struct file *file)
56248 +{
56249 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56250 + return -EBUSY;
56251 + if (file->f_mode & FMODE_READ) {
56252 + int retval = 0;
56253 + mutex_lock(&gr_learn_user_mutex);
56254 + if (learn_buffer == NULL)
56255 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56256 + if (learn_buffer_user == NULL)
56257 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56258 + if (learn_buffer == NULL) {
56259 + retval = -ENOMEM;
56260 + goto out_error;
56261 + }
56262 + if (learn_buffer_user == NULL) {
56263 + retval = -ENOMEM;
56264 + goto out_error;
56265 + }
56266 + learn_buffer_len = 0;
56267 + learn_buffer_user_len = 0;
56268 + gr_learn_attached = 1;
56269 +out_error:
56270 + mutex_unlock(&gr_learn_user_mutex);
56271 + return retval;
56272 + }
56273 + return 0;
56274 +}
56275 +
56276 +static int
56277 +close_learn(struct inode *inode, struct file *file)
56278 +{
56279 + if (file->f_mode & FMODE_READ) {
56280 + char *tmp = NULL;
56281 + mutex_lock(&gr_learn_user_mutex);
56282 + spin_lock(&gr_learn_lock);
56283 + tmp = learn_buffer;
56284 + learn_buffer = NULL;
56285 + spin_unlock(&gr_learn_lock);
56286 + if (tmp)
56287 + vfree(tmp);
56288 + if (learn_buffer_user != NULL) {
56289 + vfree(learn_buffer_user);
56290 + learn_buffer_user = NULL;
56291 + }
56292 + learn_buffer_len = 0;
56293 + learn_buffer_user_len = 0;
56294 + gr_learn_attached = 0;
56295 + mutex_unlock(&gr_learn_user_mutex);
56296 + }
56297 +
56298 + return 0;
56299 +}
56300 +
56301 +const struct file_operations grsec_fops = {
56302 + .read = read_learn,
56303 + .write = write_grsec_handler,
56304 + .open = open_learn,
56305 + .release = close_learn,
56306 + .poll = poll_learn,
56307 +};
56308 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56309 new file mode 100644
56310 index 0000000..39645c9
56311 --- /dev/null
56312 +++ b/grsecurity/gracl_res.c
56313 @@ -0,0 +1,68 @@
56314 +#include <linux/kernel.h>
56315 +#include <linux/sched.h>
56316 +#include <linux/gracl.h>
56317 +#include <linux/grinternal.h>
56318 +
56319 +static const char *restab_log[] = {
56320 + [RLIMIT_CPU] = "RLIMIT_CPU",
56321 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56322 + [RLIMIT_DATA] = "RLIMIT_DATA",
56323 + [RLIMIT_STACK] = "RLIMIT_STACK",
56324 + [RLIMIT_CORE] = "RLIMIT_CORE",
56325 + [RLIMIT_RSS] = "RLIMIT_RSS",
56326 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56327 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56328 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56329 + [RLIMIT_AS] = "RLIMIT_AS",
56330 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56331 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56332 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56333 + [RLIMIT_NICE] = "RLIMIT_NICE",
56334 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56335 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56336 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56337 +};
56338 +
56339 +void
56340 +gr_log_resource(const struct task_struct *task,
56341 + const int res, const unsigned long wanted, const int gt)
56342 +{
56343 + const struct cred *cred;
56344 + unsigned long rlim;
56345 +
56346 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56347 + return;
56348 +
56349 + // not yet supported resource
56350 + if (unlikely(!restab_log[res]))
56351 + return;
56352 +
56353 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56354 + rlim = task_rlimit_max(task, res);
56355 + else
56356 + rlim = task_rlimit(task, res);
56357 +
56358 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56359 + return;
56360 +
56361 + rcu_read_lock();
56362 + cred = __task_cred(task);
56363 +
56364 + if (res == RLIMIT_NPROC &&
56365 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56366 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56367 + goto out_rcu_unlock;
56368 + else if (res == RLIMIT_MEMLOCK &&
56369 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56370 + goto out_rcu_unlock;
56371 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56372 + goto out_rcu_unlock;
56373 + rcu_read_unlock();
56374 +
56375 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56376 +
56377 + return;
56378 +out_rcu_unlock:
56379 + rcu_read_unlock();
56380 + return;
56381 +}
56382 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56383 new file mode 100644
56384 index 0000000..25197e9
56385 --- /dev/null
56386 +++ b/grsecurity/gracl_segv.c
56387 @@ -0,0 +1,299 @@
56388 +#include <linux/kernel.h>
56389 +#include <linux/mm.h>
56390 +#include <asm/uaccess.h>
56391 +#include <asm/errno.h>
56392 +#include <asm/mman.h>
56393 +#include <net/sock.h>
56394 +#include <linux/file.h>
56395 +#include <linux/fs.h>
56396 +#include <linux/net.h>
56397 +#include <linux/in.h>
56398 +#include <linux/slab.h>
56399 +#include <linux/types.h>
56400 +#include <linux/sched.h>
56401 +#include <linux/timer.h>
56402 +#include <linux/gracl.h>
56403 +#include <linux/grsecurity.h>
56404 +#include <linux/grinternal.h>
56405 +
56406 +static struct crash_uid *uid_set;
56407 +static unsigned short uid_used;
56408 +static DEFINE_SPINLOCK(gr_uid_lock);
56409 +extern rwlock_t gr_inode_lock;
56410 +extern struct acl_subject_label *
56411 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56412 + struct acl_role_label *role);
56413 +
56414 +#ifdef CONFIG_BTRFS_FS
56415 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56416 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56417 +#endif
56418 +
56419 +static inline dev_t __get_dev(const struct dentry *dentry)
56420 +{
56421 +#ifdef CONFIG_BTRFS_FS
56422 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56423 + return get_btrfs_dev_from_inode(dentry->d_inode);
56424 + else
56425 +#endif
56426 + return dentry->d_inode->i_sb->s_dev;
56427 +}
56428 +
56429 +int
56430 +gr_init_uidset(void)
56431 +{
56432 + uid_set =
56433 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56434 + uid_used = 0;
56435 +
56436 + return uid_set ? 1 : 0;
56437 +}
56438 +
56439 +void
56440 +gr_free_uidset(void)
56441 +{
56442 + if (uid_set)
56443 + kfree(uid_set);
56444 +
56445 + return;
56446 +}
56447 +
56448 +int
56449 +gr_find_uid(const uid_t uid)
56450 +{
56451 + struct crash_uid *tmp = uid_set;
56452 + uid_t buid;
56453 + int low = 0, high = uid_used - 1, mid;
56454 +
56455 + while (high >= low) {
56456 + mid = (low + high) >> 1;
56457 + buid = tmp[mid].uid;
56458 + if (buid == uid)
56459 + return mid;
56460 + if (buid > uid)
56461 + high = mid - 1;
56462 + if (buid < uid)
56463 + low = mid + 1;
56464 + }
56465 +
56466 + return -1;
56467 +}
56468 +
56469 +static __inline__ void
56470 +gr_insertsort(void)
56471 +{
56472 + unsigned short i, j;
56473 + struct crash_uid index;
56474 +
56475 + for (i = 1; i < uid_used; i++) {
56476 + index = uid_set[i];
56477 + j = i;
56478 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56479 + uid_set[j] = uid_set[j - 1];
56480 + j--;
56481 + }
56482 + uid_set[j] = index;
56483 + }
56484 +
56485 + return;
56486 +}
56487 +
56488 +static __inline__ void
56489 +gr_insert_uid(const uid_t uid, const unsigned long expires)
56490 +{
56491 + int loc;
56492 +
56493 + if (uid_used == GR_UIDTABLE_MAX)
56494 + return;
56495 +
56496 + loc = gr_find_uid(uid);
56497 +
56498 + if (loc >= 0) {
56499 + uid_set[loc].expires = expires;
56500 + return;
56501 + }
56502 +
56503 + uid_set[uid_used].uid = uid;
56504 + uid_set[uid_used].expires = expires;
56505 + uid_used++;
56506 +
56507 + gr_insertsort();
56508 +
56509 + return;
56510 +}
56511 +
56512 +void
56513 +gr_remove_uid(const unsigned short loc)
56514 +{
56515 + unsigned short i;
56516 +
56517 + for (i = loc + 1; i < uid_used; i++)
56518 + uid_set[i - 1] = uid_set[i];
56519 +
56520 + uid_used--;
56521 +
56522 + return;
56523 +}
56524 +
56525 +int
56526 +gr_check_crash_uid(const uid_t uid)
56527 +{
56528 + int loc;
56529 + int ret = 0;
56530 +
56531 + if (unlikely(!gr_acl_is_enabled()))
56532 + return 0;
56533 +
56534 + spin_lock(&gr_uid_lock);
56535 + loc = gr_find_uid(uid);
56536 +
56537 + if (loc < 0)
56538 + goto out_unlock;
56539 +
56540 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
56541 + gr_remove_uid(loc);
56542 + else
56543 + ret = 1;
56544 +
56545 +out_unlock:
56546 + spin_unlock(&gr_uid_lock);
56547 + return ret;
56548 +}
56549 +
56550 +static __inline__ int
56551 +proc_is_setxid(const struct cred *cred)
56552 +{
56553 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
56554 + !uid_eq(cred->uid, cred->fsuid))
56555 + return 1;
56556 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
56557 + !uid_eq(cred->gid, cred->fsgid))
56558 + return 1;
56559 +
56560 + return 0;
56561 +}
56562 +
56563 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
56564 +
56565 +void
56566 +gr_handle_crash(struct task_struct *task, const int sig)
56567 +{
56568 + struct acl_subject_label *curr;
56569 + struct task_struct *tsk, *tsk2;
56570 + const struct cred *cred;
56571 + const struct cred *cred2;
56572 +
56573 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56574 + return;
56575 +
56576 + if (unlikely(!gr_acl_is_enabled()))
56577 + return;
56578 +
56579 + curr = task->acl;
56580 +
56581 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
56582 + return;
56583 +
56584 + if (time_before_eq(curr->expires, get_seconds())) {
56585 + curr->expires = 0;
56586 + curr->crashes = 0;
56587 + }
56588 +
56589 + curr->crashes++;
56590 +
56591 + if (!curr->expires)
56592 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56593 +
56594 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56595 + time_after(curr->expires, get_seconds())) {
56596 + rcu_read_lock();
56597 + cred = __task_cred(task);
56598 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
56599 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56600 + spin_lock(&gr_uid_lock);
56601 + gr_insert_uid(cred->uid, curr->expires);
56602 + spin_unlock(&gr_uid_lock);
56603 + curr->expires = 0;
56604 + curr->crashes = 0;
56605 + read_lock(&tasklist_lock);
56606 + do_each_thread(tsk2, tsk) {
56607 + cred2 = __task_cred(tsk);
56608 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
56609 + gr_fake_force_sig(SIGKILL, tsk);
56610 + } while_each_thread(tsk2, tsk);
56611 + read_unlock(&tasklist_lock);
56612 + } else {
56613 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56614 + read_lock(&tasklist_lock);
56615 + read_lock(&grsec_exec_file_lock);
56616 + do_each_thread(tsk2, tsk) {
56617 + if (likely(tsk != task)) {
56618 + // if this thread has the same subject as the one that triggered
56619 + // RES_CRASH and it's the same binary, kill it
56620 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56621 + gr_fake_force_sig(SIGKILL, tsk);
56622 + }
56623 + } while_each_thread(tsk2, tsk);
56624 + read_unlock(&grsec_exec_file_lock);
56625 + read_unlock(&tasklist_lock);
56626 + }
56627 + rcu_read_unlock();
56628 + }
56629 +
56630 + return;
56631 +}
56632 +
56633 +int
56634 +gr_check_crash_exec(const struct file *filp)
56635 +{
56636 + struct acl_subject_label *curr;
56637 +
56638 + if (unlikely(!gr_acl_is_enabled()))
56639 + return 0;
56640 +
56641 + read_lock(&gr_inode_lock);
56642 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56643 + __get_dev(filp->f_path.dentry),
56644 + current->role);
56645 + read_unlock(&gr_inode_lock);
56646 +
56647 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56648 + (!curr->crashes && !curr->expires))
56649 + return 0;
56650 +
56651 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56652 + time_after(curr->expires, get_seconds()))
56653 + return 1;
56654 + else if (time_before_eq(curr->expires, get_seconds())) {
56655 + curr->crashes = 0;
56656 + curr->expires = 0;
56657 + }
56658 +
56659 + return 0;
56660 +}
56661 +
56662 +void
56663 +gr_handle_alertkill(struct task_struct *task)
56664 +{
56665 + struct acl_subject_label *curracl;
56666 + __u32 curr_ip;
56667 + struct task_struct *p, *p2;
56668 +
56669 + if (unlikely(!gr_acl_is_enabled()))
56670 + return;
56671 +
56672 + curracl = task->acl;
56673 + curr_ip = task->signal->curr_ip;
56674 +
56675 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56676 + read_lock(&tasklist_lock);
56677 + do_each_thread(p2, p) {
56678 + if (p->signal->curr_ip == curr_ip)
56679 + gr_fake_force_sig(SIGKILL, p);
56680 + } while_each_thread(p2, p);
56681 + read_unlock(&tasklist_lock);
56682 + } else if (curracl->mode & GR_KILLPROC)
56683 + gr_fake_force_sig(SIGKILL, task);
56684 +
56685 + return;
56686 +}
56687 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56688 new file mode 100644
56689 index 0000000..9d83a69
56690 --- /dev/null
56691 +++ b/grsecurity/gracl_shm.c
56692 @@ -0,0 +1,40 @@
56693 +#include <linux/kernel.h>
56694 +#include <linux/mm.h>
56695 +#include <linux/sched.h>
56696 +#include <linux/file.h>
56697 +#include <linux/ipc.h>
56698 +#include <linux/gracl.h>
56699 +#include <linux/grsecurity.h>
56700 +#include <linux/grinternal.h>
56701 +
56702 +int
56703 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56704 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56705 +{
56706 + struct task_struct *task;
56707 +
56708 + if (!gr_acl_is_enabled())
56709 + return 1;
56710 +
56711 + rcu_read_lock();
56712 + read_lock(&tasklist_lock);
56713 +
56714 + task = find_task_by_vpid(shm_cprid);
56715 +
56716 + if (unlikely(!task))
56717 + task = find_task_by_vpid(shm_lapid);
56718 +
56719 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56720 + (task->pid == shm_lapid)) &&
56721 + (task->acl->mode & GR_PROTSHM) &&
56722 + (task->acl != current->acl))) {
56723 + read_unlock(&tasklist_lock);
56724 + rcu_read_unlock();
56725 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56726 + return 0;
56727 + }
56728 + read_unlock(&tasklist_lock);
56729 + rcu_read_unlock();
56730 +
56731 + return 1;
56732 +}
56733 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56734 new file mode 100644
56735 index 0000000..bc0be01
56736 --- /dev/null
56737 +++ b/grsecurity/grsec_chdir.c
56738 @@ -0,0 +1,19 @@
56739 +#include <linux/kernel.h>
56740 +#include <linux/sched.h>
56741 +#include <linux/fs.h>
56742 +#include <linux/file.h>
56743 +#include <linux/grsecurity.h>
56744 +#include <linux/grinternal.h>
56745 +
56746 +void
56747 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56748 +{
56749 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56750 + if ((grsec_enable_chdir && grsec_enable_group &&
56751 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56752 + !grsec_enable_group)) {
56753 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56754 + }
56755 +#endif
56756 + return;
56757 +}
56758 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56759 new file mode 100644
56760 index 0000000..9807ee2
56761 --- /dev/null
56762 +++ b/grsecurity/grsec_chroot.c
56763 @@ -0,0 +1,368 @@
56764 +#include <linux/kernel.h>
56765 +#include <linux/module.h>
56766 +#include <linux/sched.h>
56767 +#include <linux/file.h>
56768 +#include <linux/fs.h>
56769 +#include <linux/mount.h>
56770 +#include <linux/types.h>
56771 +#include "../fs/mount.h"
56772 +#include <linux/grsecurity.h>
56773 +#include <linux/grinternal.h>
56774 +
56775 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56776 +{
56777 +#ifdef CONFIG_GRKERNSEC
56778 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56779 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
56780 + task->gr_is_chrooted = 1;
56781 + else
56782 + task->gr_is_chrooted = 0;
56783 +
56784 + task->gr_chroot_dentry = path->dentry;
56785 +#endif
56786 + return;
56787 +}
56788 +
56789 +void gr_clear_chroot_entries(struct task_struct *task)
56790 +{
56791 +#ifdef CONFIG_GRKERNSEC
56792 + task->gr_is_chrooted = 0;
56793 + task->gr_chroot_dentry = NULL;
56794 +#endif
56795 + return;
56796 +}
56797 +
56798 +int
56799 +gr_handle_chroot_unix(const pid_t pid)
56800 +{
56801 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56802 + struct task_struct *p;
56803 +
56804 + if (unlikely(!grsec_enable_chroot_unix))
56805 + return 1;
56806 +
56807 + if (likely(!proc_is_chrooted(current)))
56808 + return 1;
56809 +
56810 + rcu_read_lock();
56811 + read_lock(&tasklist_lock);
56812 + p = find_task_by_vpid_unrestricted(pid);
56813 + if (unlikely(p && !have_same_root(current, p))) {
56814 + read_unlock(&tasklist_lock);
56815 + rcu_read_unlock();
56816 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56817 + return 0;
56818 + }
56819 + read_unlock(&tasklist_lock);
56820 + rcu_read_unlock();
56821 +#endif
56822 + return 1;
56823 +}
56824 +
56825 +int
56826 +gr_handle_chroot_nice(void)
56827 +{
56828 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56829 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56830 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56831 + return -EPERM;
56832 + }
56833 +#endif
56834 + return 0;
56835 +}
56836 +
56837 +int
56838 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56839 +{
56840 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56841 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56842 + && proc_is_chrooted(current)) {
56843 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56844 + return -EACCES;
56845 + }
56846 +#endif
56847 + return 0;
56848 +}
56849 +
56850 +int
56851 +gr_handle_chroot_rawio(const struct inode *inode)
56852 +{
56853 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56854 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56855 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56856 + return 1;
56857 +#endif
56858 + return 0;
56859 +}
56860 +
56861 +int
56862 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56863 +{
56864 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56865 + struct task_struct *p;
56866 + int ret = 0;
56867 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56868 + return ret;
56869 +
56870 + read_lock(&tasklist_lock);
56871 + do_each_pid_task(pid, type, p) {
56872 + if (!have_same_root(current, p)) {
56873 + ret = 1;
56874 + goto out;
56875 + }
56876 + } while_each_pid_task(pid, type, p);
56877 +out:
56878 + read_unlock(&tasklist_lock);
56879 + return ret;
56880 +#endif
56881 + return 0;
56882 +}
56883 +
56884 +int
56885 +gr_pid_is_chrooted(struct task_struct *p)
56886 +{
56887 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56888 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56889 + return 0;
56890 +
56891 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56892 + !have_same_root(current, p)) {
56893 + return 1;
56894 + }
56895 +#endif
56896 + return 0;
56897 +}
56898 +
56899 +EXPORT_SYMBOL(gr_pid_is_chrooted);
56900 +
56901 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56902 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56903 +{
56904 + struct path path, currentroot;
56905 + int ret = 0;
56906 +
56907 + path.dentry = (struct dentry *)u_dentry;
56908 + path.mnt = (struct vfsmount *)u_mnt;
56909 + get_fs_root(current->fs, &currentroot);
56910 + if (path_is_under(&path, &currentroot))
56911 + ret = 1;
56912 + path_put(&currentroot);
56913 +
56914 + return ret;
56915 +}
56916 +#endif
56917 +
56918 +int
56919 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56920 +{
56921 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56922 + if (!grsec_enable_chroot_fchdir)
56923 + return 1;
56924 +
56925 + if (!proc_is_chrooted(current))
56926 + return 1;
56927 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56928 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56929 + return 0;
56930 + }
56931 +#endif
56932 + return 1;
56933 +}
56934 +
56935 +int
56936 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56937 + const time_t shm_createtime)
56938 +{
56939 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56940 + struct task_struct *p;
56941 + time_t starttime;
56942 +
56943 + if (unlikely(!grsec_enable_chroot_shmat))
56944 + return 1;
56945 +
56946 + if (likely(!proc_is_chrooted(current)))
56947 + return 1;
56948 +
56949 + rcu_read_lock();
56950 + read_lock(&tasklist_lock);
56951 +
56952 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
56953 + starttime = p->start_time.tv_sec;
56954 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
56955 + if (have_same_root(current, p)) {
56956 + goto allow;
56957 + } else {
56958 + read_unlock(&tasklist_lock);
56959 + rcu_read_unlock();
56960 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56961 + return 0;
56962 + }
56963 + }
56964 + /* creator exited, pid reuse, fall through to next check */
56965 + }
56966 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
56967 + if (unlikely(!have_same_root(current, p))) {
56968 + read_unlock(&tasklist_lock);
56969 + rcu_read_unlock();
56970 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56971 + return 0;
56972 + }
56973 + }
56974 +
56975 +allow:
56976 + read_unlock(&tasklist_lock);
56977 + rcu_read_unlock();
56978 +#endif
56979 + return 1;
56980 +}
56981 +
56982 +void
56983 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
56984 +{
56985 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56986 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
56987 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
56988 +#endif
56989 + return;
56990 +}
56991 +
56992 +int
56993 +gr_handle_chroot_mknod(const struct dentry *dentry,
56994 + const struct vfsmount *mnt, const int mode)
56995 +{
56996 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56997 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
56998 + proc_is_chrooted(current)) {
56999 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57000 + return -EPERM;
57001 + }
57002 +#endif
57003 + return 0;
57004 +}
57005 +
57006 +int
57007 +gr_handle_chroot_mount(const struct dentry *dentry,
57008 + const struct vfsmount *mnt, const char *dev_name)
57009 +{
57010 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57011 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57012 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57013 + return -EPERM;
57014 + }
57015 +#endif
57016 + return 0;
57017 +}
57018 +
57019 +int
57020 +gr_handle_chroot_pivot(void)
57021 +{
57022 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57023 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57024 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57025 + return -EPERM;
57026 + }
57027 +#endif
57028 + return 0;
57029 +}
57030 +
57031 +int
57032 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57033 +{
57034 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57035 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57036 + !gr_is_outside_chroot(dentry, mnt)) {
57037 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57038 + return -EPERM;
57039 + }
57040 +#endif
57041 + return 0;
57042 +}
57043 +
57044 +extern const char *captab_log[];
57045 +extern int captab_log_entries;
57046 +
57047 +int
57048 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, 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 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57055 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57056 + }
57057 + return 0;
57058 + }
57059 + }
57060 +#endif
57061 + return 1;
57062 +}
57063 +
57064 +int
57065 +gr_chroot_is_capable(const int cap)
57066 +{
57067 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57068 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57069 +#endif
57070 + return 1;
57071 +}
57072 +
57073 +int
57074 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57075 +{
57076 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57077 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57078 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57079 + if (cap_raised(chroot_caps, cap)) {
57080 + return 0;
57081 + }
57082 + }
57083 +#endif
57084 + return 1;
57085 +}
57086 +
57087 +int
57088 +gr_chroot_is_capable_nolog(const int cap)
57089 +{
57090 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57091 + return gr_task_chroot_is_capable_nolog(current, cap);
57092 +#endif
57093 + return 1;
57094 +}
57095 +
57096 +int
57097 +gr_handle_chroot_sysctl(const int op)
57098 +{
57099 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57100 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57101 + proc_is_chrooted(current))
57102 + return -EACCES;
57103 +#endif
57104 + return 0;
57105 +}
57106 +
57107 +void
57108 +gr_handle_chroot_chdir(struct path *path)
57109 +{
57110 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57111 + if (grsec_enable_chroot_chdir)
57112 + set_fs_pwd(current->fs, path);
57113 +#endif
57114 + return;
57115 +}
57116 +
57117 +int
57118 +gr_handle_chroot_chmod(const struct dentry *dentry,
57119 + const struct vfsmount *mnt, const int mode)
57120 +{
57121 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57122 + /* allow chmod +s on directories, but not files */
57123 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57124 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57125 + proc_is_chrooted(current)) {
57126 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57127 + return -EPERM;
57128 + }
57129 +#endif
57130 + return 0;
57131 +}
57132 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57133 new file mode 100644
57134 index 0000000..213ad8b
57135 --- /dev/null
57136 +++ b/grsecurity/grsec_disabled.c
57137 @@ -0,0 +1,437 @@
57138 +#include <linux/kernel.h>
57139 +#include <linux/module.h>
57140 +#include <linux/sched.h>
57141 +#include <linux/file.h>
57142 +#include <linux/fs.h>
57143 +#include <linux/kdev_t.h>
57144 +#include <linux/net.h>
57145 +#include <linux/in.h>
57146 +#include <linux/ip.h>
57147 +#include <linux/skbuff.h>
57148 +#include <linux/sysctl.h>
57149 +
57150 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57151 +void
57152 +pax_set_initial_flags(struct linux_binprm *bprm)
57153 +{
57154 + return;
57155 +}
57156 +#endif
57157 +
57158 +#ifdef CONFIG_SYSCTL
57159 +__u32
57160 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57161 +{
57162 + return 0;
57163 +}
57164 +#endif
57165 +
57166 +#ifdef CONFIG_TASKSTATS
57167 +int gr_is_taskstats_denied(int pid)
57168 +{
57169 + return 0;
57170 +}
57171 +#endif
57172 +
57173 +int
57174 +gr_acl_is_enabled(void)
57175 +{
57176 + return 0;
57177 +}
57178 +
57179 +void
57180 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57181 +{
57182 + return;
57183 +}
57184 +
57185 +int
57186 +gr_handle_rawio(const struct inode *inode)
57187 +{
57188 + return 0;
57189 +}
57190 +
57191 +void
57192 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57193 +{
57194 + return;
57195 +}
57196 +
57197 +int
57198 +gr_handle_ptrace(struct task_struct *task, const long request)
57199 +{
57200 + return 0;
57201 +}
57202 +
57203 +int
57204 +gr_handle_proc_ptrace(struct task_struct *task)
57205 +{
57206 + return 0;
57207 +}
57208 +
57209 +void
57210 +gr_learn_resource(const struct task_struct *task,
57211 + const int res, const unsigned long wanted, const int gt)
57212 +{
57213 + return;
57214 +}
57215 +
57216 +int
57217 +gr_set_acls(const int type)
57218 +{
57219 + return 0;
57220 +}
57221 +
57222 +int
57223 +gr_check_hidden_task(const struct task_struct *tsk)
57224 +{
57225 + return 0;
57226 +}
57227 +
57228 +int
57229 +gr_check_protected_task(const struct task_struct *task)
57230 +{
57231 + return 0;
57232 +}
57233 +
57234 +int
57235 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57236 +{
57237 + return 0;
57238 +}
57239 +
57240 +void
57241 +gr_copy_label(struct task_struct *tsk)
57242 +{
57243 + return;
57244 +}
57245 +
57246 +void
57247 +gr_set_pax_flags(struct task_struct *task)
57248 +{
57249 + return;
57250 +}
57251 +
57252 +int
57253 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57254 + const int unsafe_share)
57255 +{
57256 + return 0;
57257 +}
57258 +
57259 +void
57260 +gr_handle_delete(const ino_t ino, const dev_t dev)
57261 +{
57262 + return;
57263 +}
57264 +
57265 +void
57266 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57267 +{
57268 + return;
57269 +}
57270 +
57271 +void
57272 +gr_handle_crash(struct task_struct *task, const int sig)
57273 +{
57274 + return;
57275 +}
57276 +
57277 +int
57278 +gr_check_crash_exec(const struct file *filp)
57279 +{
57280 + return 0;
57281 +}
57282 +
57283 +int
57284 +gr_check_crash_uid(const uid_t uid)
57285 +{
57286 + return 0;
57287 +}
57288 +
57289 +void
57290 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57291 + struct dentry *old_dentry,
57292 + struct dentry *new_dentry,
57293 + struct vfsmount *mnt, const __u8 replace)
57294 +{
57295 + return;
57296 +}
57297 +
57298 +int
57299 +gr_search_socket(const int family, const int type, const int protocol)
57300 +{
57301 + return 1;
57302 +}
57303 +
57304 +int
57305 +gr_search_connectbind(const int mode, const struct socket *sock,
57306 + const struct sockaddr_in *addr)
57307 +{
57308 + return 0;
57309 +}
57310 +
57311 +void
57312 +gr_handle_alertkill(struct task_struct *task)
57313 +{
57314 + return;
57315 +}
57316 +
57317 +__u32
57318 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57319 +{
57320 + return 1;
57321 +}
57322 +
57323 +__u32
57324 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57325 + const struct vfsmount * mnt)
57326 +{
57327 + return 1;
57328 +}
57329 +
57330 +__u32
57331 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57332 + int acc_mode)
57333 +{
57334 + return 1;
57335 +}
57336 +
57337 +__u32
57338 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57339 +{
57340 + return 1;
57341 +}
57342 +
57343 +__u32
57344 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57345 +{
57346 + return 1;
57347 +}
57348 +
57349 +int
57350 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57351 + unsigned int *vm_flags)
57352 +{
57353 + return 1;
57354 +}
57355 +
57356 +__u32
57357 +gr_acl_handle_truncate(const struct dentry * dentry,
57358 + const struct vfsmount * mnt)
57359 +{
57360 + return 1;
57361 +}
57362 +
57363 +__u32
57364 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57365 +{
57366 + return 1;
57367 +}
57368 +
57369 +__u32
57370 +gr_acl_handle_access(const struct dentry * dentry,
57371 + const struct vfsmount * mnt, const int fmode)
57372 +{
57373 + return 1;
57374 +}
57375 +
57376 +__u32
57377 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57378 + umode_t *mode)
57379 +{
57380 + return 1;
57381 +}
57382 +
57383 +__u32
57384 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57385 +{
57386 + return 1;
57387 +}
57388 +
57389 +__u32
57390 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57391 +{
57392 + return 1;
57393 +}
57394 +
57395 +void
57396 +grsecurity_init(void)
57397 +{
57398 + return;
57399 +}
57400 +
57401 +umode_t gr_acl_umask(void)
57402 +{
57403 + return 0;
57404 +}
57405 +
57406 +__u32
57407 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57408 + const struct dentry * parent_dentry,
57409 + const struct vfsmount * parent_mnt,
57410 + const int mode)
57411 +{
57412 + return 1;
57413 +}
57414 +
57415 +__u32
57416 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57417 + const struct dentry * parent_dentry,
57418 + const struct vfsmount * parent_mnt)
57419 +{
57420 + return 1;
57421 +}
57422 +
57423 +__u32
57424 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57425 + const struct dentry * parent_dentry,
57426 + const struct vfsmount * parent_mnt, const char *from)
57427 +{
57428 + return 1;
57429 +}
57430 +
57431 +__u32
57432 +gr_acl_handle_link(const struct dentry * new_dentry,
57433 + const struct dentry * parent_dentry,
57434 + const struct vfsmount * parent_mnt,
57435 + const struct dentry * old_dentry,
57436 + const struct vfsmount * old_mnt, const char *to)
57437 +{
57438 + return 1;
57439 +}
57440 +
57441 +int
57442 +gr_acl_handle_rename(const struct dentry *new_dentry,
57443 + const struct dentry *parent_dentry,
57444 + const struct vfsmount *parent_mnt,
57445 + const struct dentry *old_dentry,
57446 + const struct inode *old_parent_inode,
57447 + const struct vfsmount *old_mnt, const char *newname)
57448 +{
57449 + return 0;
57450 +}
57451 +
57452 +int
57453 +gr_acl_handle_filldir(const struct file *file, const char *name,
57454 + const int namelen, const ino_t ino)
57455 +{
57456 + return 1;
57457 +}
57458 +
57459 +int
57460 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57461 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57462 +{
57463 + return 1;
57464 +}
57465 +
57466 +int
57467 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57468 +{
57469 + return 0;
57470 +}
57471 +
57472 +int
57473 +gr_search_accept(const struct socket *sock)
57474 +{
57475 + return 0;
57476 +}
57477 +
57478 +int
57479 +gr_search_listen(const struct socket *sock)
57480 +{
57481 + return 0;
57482 +}
57483 +
57484 +int
57485 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57486 +{
57487 + return 0;
57488 +}
57489 +
57490 +__u32
57491 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57492 +{
57493 + return 1;
57494 +}
57495 +
57496 +__u32
57497 +gr_acl_handle_creat(const struct dentry * dentry,
57498 + const struct dentry * p_dentry,
57499 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57500 + const int imode)
57501 +{
57502 + return 1;
57503 +}
57504 +
57505 +void
57506 +gr_acl_handle_exit(void)
57507 +{
57508 + return;
57509 +}
57510 +
57511 +int
57512 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57513 +{
57514 + return 1;
57515 +}
57516 +
57517 +void
57518 +gr_set_role_label(const uid_t uid, const gid_t gid)
57519 +{
57520 + return;
57521 +}
57522 +
57523 +int
57524 +gr_acl_handle_procpidmem(const struct task_struct *task)
57525 +{
57526 + return 0;
57527 +}
57528 +
57529 +int
57530 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57531 +{
57532 + return 0;
57533 +}
57534 +
57535 +int
57536 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57537 +{
57538 + return 0;
57539 +}
57540 +
57541 +void
57542 +gr_set_kernel_label(struct task_struct *task)
57543 +{
57544 + return;
57545 +}
57546 +
57547 +int
57548 +gr_check_user_change(int real, int effective, int fs)
57549 +{
57550 + return 0;
57551 +}
57552 +
57553 +int
57554 +gr_check_group_change(int real, int effective, int fs)
57555 +{
57556 + return 0;
57557 +}
57558 +
57559 +int gr_acl_enable_at_secure(void)
57560 +{
57561 + return 0;
57562 +}
57563 +
57564 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57565 +{
57566 + return dentry->d_inode->i_sb->s_dev;
57567 +}
57568 +
57569 +EXPORT_SYMBOL(gr_learn_resource);
57570 +EXPORT_SYMBOL(gr_set_kernel_label);
57571 +#ifdef CONFIG_SECURITY
57572 +EXPORT_SYMBOL(gr_check_user_change);
57573 +EXPORT_SYMBOL(gr_check_group_change);
57574 +#endif
57575 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57576 new file mode 100644
57577 index 0000000..abfa971
57578 --- /dev/null
57579 +++ b/grsecurity/grsec_exec.c
57580 @@ -0,0 +1,174 @@
57581 +#include <linux/kernel.h>
57582 +#include <linux/sched.h>
57583 +#include <linux/file.h>
57584 +#include <linux/binfmts.h>
57585 +#include <linux/fs.h>
57586 +#include <linux/types.h>
57587 +#include <linux/grdefs.h>
57588 +#include <linux/grsecurity.h>
57589 +#include <linux/grinternal.h>
57590 +#include <linux/capability.h>
57591 +#include <linux/module.h>
57592 +
57593 +#include <asm/uaccess.h>
57594 +
57595 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57596 +static char gr_exec_arg_buf[132];
57597 +static DEFINE_MUTEX(gr_exec_arg_mutex);
57598 +#endif
57599 +
57600 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57601 +
57602 +void
57603 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57604 +{
57605 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57606 + char *grarg = gr_exec_arg_buf;
57607 + unsigned int i, x, execlen = 0;
57608 + char c;
57609 +
57610 + if (!((grsec_enable_execlog && grsec_enable_group &&
57611 + in_group_p(grsec_audit_gid))
57612 + || (grsec_enable_execlog && !grsec_enable_group)))
57613 + return;
57614 +
57615 + mutex_lock(&gr_exec_arg_mutex);
57616 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
57617 +
57618 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
57619 + const char __user *p;
57620 + unsigned int len;
57621 +
57622 + p = get_user_arg_ptr(argv, i);
57623 + if (IS_ERR(p))
57624 + goto log;
57625 +
57626 + len = strnlen_user(p, 128 - execlen);
57627 + if (len > 128 - execlen)
57628 + len = 128 - execlen;
57629 + else if (len > 0)
57630 + len--;
57631 + if (copy_from_user(grarg + execlen, p, len))
57632 + goto log;
57633 +
57634 + /* rewrite unprintable characters */
57635 + for (x = 0; x < len; x++) {
57636 + c = *(grarg + execlen + x);
57637 + if (c < 32 || c > 126)
57638 + *(grarg + execlen + x) = ' ';
57639 + }
57640 +
57641 + execlen += len;
57642 + *(grarg + execlen) = ' ';
57643 + *(grarg + execlen + 1) = '\0';
57644 + execlen++;
57645 + }
57646 +
57647 + log:
57648 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57649 + bprm->file->f_path.mnt, grarg);
57650 + mutex_unlock(&gr_exec_arg_mutex);
57651 +#endif
57652 + return;
57653 +}
57654 +
57655 +#ifdef CONFIG_GRKERNSEC
57656 +extern int gr_acl_is_capable(const int cap);
57657 +extern int gr_acl_is_capable_nolog(const int cap);
57658 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57659 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
57660 +extern int gr_chroot_is_capable(const int cap);
57661 +extern int gr_chroot_is_capable_nolog(const int cap);
57662 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57663 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
57664 +#endif
57665 +
57666 +const char *captab_log[] = {
57667 + "CAP_CHOWN",
57668 + "CAP_DAC_OVERRIDE",
57669 + "CAP_DAC_READ_SEARCH",
57670 + "CAP_FOWNER",
57671 + "CAP_FSETID",
57672 + "CAP_KILL",
57673 + "CAP_SETGID",
57674 + "CAP_SETUID",
57675 + "CAP_SETPCAP",
57676 + "CAP_LINUX_IMMUTABLE",
57677 + "CAP_NET_BIND_SERVICE",
57678 + "CAP_NET_BROADCAST",
57679 + "CAP_NET_ADMIN",
57680 + "CAP_NET_RAW",
57681 + "CAP_IPC_LOCK",
57682 + "CAP_IPC_OWNER",
57683 + "CAP_SYS_MODULE",
57684 + "CAP_SYS_RAWIO",
57685 + "CAP_SYS_CHROOT",
57686 + "CAP_SYS_PTRACE",
57687 + "CAP_SYS_PACCT",
57688 + "CAP_SYS_ADMIN",
57689 + "CAP_SYS_BOOT",
57690 + "CAP_SYS_NICE",
57691 + "CAP_SYS_RESOURCE",
57692 + "CAP_SYS_TIME",
57693 + "CAP_SYS_TTY_CONFIG",
57694 + "CAP_MKNOD",
57695 + "CAP_LEASE",
57696 + "CAP_AUDIT_WRITE",
57697 + "CAP_AUDIT_CONTROL",
57698 + "CAP_SETFCAP",
57699 + "CAP_MAC_OVERRIDE",
57700 + "CAP_MAC_ADMIN",
57701 + "CAP_SYSLOG",
57702 + "CAP_WAKE_ALARM"
57703 +};
57704 +
57705 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57706 +
57707 +int gr_is_capable(const int cap)
57708 +{
57709 +#ifdef CONFIG_GRKERNSEC
57710 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57711 + return 1;
57712 + return 0;
57713 +#else
57714 + return 1;
57715 +#endif
57716 +}
57717 +
57718 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57719 +{
57720 +#ifdef CONFIG_GRKERNSEC
57721 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57722 + return 1;
57723 + return 0;
57724 +#else
57725 + return 1;
57726 +#endif
57727 +}
57728 +
57729 +int gr_is_capable_nolog(const int cap)
57730 +{
57731 +#ifdef CONFIG_GRKERNSEC
57732 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57733 + return 1;
57734 + return 0;
57735 +#else
57736 + return 1;
57737 +#endif
57738 +}
57739 +
57740 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57741 +{
57742 +#ifdef CONFIG_GRKERNSEC
57743 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57744 + return 1;
57745 + return 0;
57746 +#else
57747 + return 1;
57748 +#endif
57749 +}
57750 +
57751 +EXPORT_SYMBOL(gr_is_capable);
57752 +EXPORT_SYMBOL(gr_is_capable_nolog);
57753 +EXPORT_SYMBOL(gr_task_is_capable);
57754 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
57755 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57756 new file mode 100644
57757 index 0000000..d3ee748
57758 --- /dev/null
57759 +++ b/grsecurity/grsec_fifo.c
57760 @@ -0,0 +1,24 @@
57761 +#include <linux/kernel.h>
57762 +#include <linux/sched.h>
57763 +#include <linux/fs.h>
57764 +#include <linux/file.h>
57765 +#include <linux/grinternal.h>
57766 +
57767 +int
57768 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57769 + const struct dentry *dir, const int flag, const int acc_mode)
57770 +{
57771 +#ifdef CONFIG_GRKERNSEC_FIFO
57772 + const struct cred *cred = current_cred();
57773 +
57774 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57775 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57776 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57777 + (cred->fsuid != dentry->d_inode->i_uid)) {
57778 + if (!inode_permission(dentry->d_inode, acc_mode))
57779 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57780 + return -EACCES;
57781 + }
57782 +#endif
57783 + return 0;
57784 +}
57785 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57786 new file mode 100644
57787 index 0000000..8ca18bf
57788 --- /dev/null
57789 +++ b/grsecurity/grsec_fork.c
57790 @@ -0,0 +1,23 @@
57791 +#include <linux/kernel.h>
57792 +#include <linux/sched.h>
57793 +#include <linux/grsecurity.h>
57794 +#include <linux/grinternal.h>
57795 +#include <linux/errno.h>
57796 +
57797 +void
57798 +gr_log_forkfail(const int retval)
57799 +{
57800 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57801 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57802 + switch (retval) {
57803 + case -EAGAIN:
57804 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57805 + break;
57806 + case -ENOMEM:
57807 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57808 + break;
57809 + }
57810 + }
57811 +#endif
57812 + return;
57813 +}
57814 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57815 new file mode 100644
57816 index 0000000..05a6015
57817 --- /dev/null
57818 +++ b/grsecurity/grsec_init.c
57819 @@ -0,0 +1,283 @@
57820 +#include <linux/kernel.h>
57821 +#include <linux/sched.h>
57822 +#include <linux/mm.h>
57823 +#include <linux/gracl.h>
57824 +#include <linux/slab.h>
57825 +#include <linux/vmalloc.h>
57826 +#include <linux/percpu.h>
57827 +#include <linux/module.h>
57828 +
57829 +int grsec_enable_ptrace_readexec;
57830 +int grsec_enable_setxid;
57831 +int grsec_enable_symlinkown;
57832 +int grsec_symlinkown_gid;
57833 +int grsec_enable_brute;
57834 +int grsec_enable_link;
57835 +int grsec_enable_dmesg;
57836 +int grsec_enable_harden_ptrace;
57837 +int grsec_enable_fifo;
57838 +int grsec_enable_execlog;
57839 +int grsec_enable_signal;
57840 +int grsec_enable_forkfail;
57841 +int grsec_enable_audit_ptrace;
57842 +int grsec_enable_time;
57843 +int grsec_enable_audit_textrel;
57844 +int grsec_enable_group;
57845 +int grsec_audit_gid;
57846 +int grsec_enable_chdir;
57847 +int grsec_enable_mount;
57848 +int grsec_enable_rofs;
57849 +int grsec_enable_chroot_findtask;
57850 +int grsec_enable_chroot_mount;
57851 +int grsec_enable_chroot_shmat;
57852 +int grsec_enable_chroot_fchdir;
57853 +int grsec_enable_chroot_double;
57854 +int grsec_enable_chroot_pivot;
57855 +int grsec_enable_chroot_chdir;
57856 +int grsec_enable_chroot_chmod;
57857 +int grsec_enable_chroot_mknod;
57858 +int grsec_enable_chroot_nice;
57859 +int grsec_enable_chroot_execlog;
57860 +int grsec_enable_chroot_caps;
57861 +int grsec_enable_chroot_sysctl;
57862 +int grsec_enable_chroot_unix;
57863 +int grsec_enable_tpe;
57864 +int grsec_tpe_gid;
57865 +int grsec_enable_blackhole;
57866 +#ifdef CONFIG_IPV6_MODULE
57867 +EXPORT_SYMBOL(grsec_enable_blackhole);
57868 +#endif
57869 +int grsec_lastack_retries;
57870 +int grsec_enable_tpe_all;
57871 +int grsec_enable_tpe_invert;
57872 +int grsec_enable_socket_all;
57873 +int grsec_socket_all_gid;
57874 +int grsec_enable_socket_client;
57875 +int grsec_socket_client_gid;
57876 +int grsec_enable_socket_server;
57877 +int grsec_socket_server_gid;
57878 +int grsec_resource_logging;
57879 +int grsec_disable_privio;
57880 +int grsec_enable_log_rwxmaps;
57881 +int grsec_lock;
57882 +
57883 +DEFINE_SPINLOCK(grsec_alert_lock);
57884 +unsigned long grsec_alert_wtime = 0;
57885 +unsigned long grsec_alert_fyet = 0;
57886 +
57887 +DEFINE_SPINLOCK(grsec_audit_lock);
57888 +
57889 +DEFINE_RWLOCK(grsec_exec_file_lock);
57890 +
57891 +char *gr_shared_page[4];
57892 +
57893 +char *gr_alert_log_fmt;
57894 +char *gr_audit_log_fmt;
57895 +char *gr_alert_log_buf;
57896 +char *gr_audit_log_buf;
57897 +
57898 +extern struct gr_arg *gr_usermode;
57899 +extern unsigned char *gr_system_salt;
57900 +extern unsigned char *gr_system_sum;
57901 +
57902 +void __init
57903 +grsecurity_init(void)
57904 +{
57905 + int j;
57906 + /* create the per-cpu shared pages */
57907 +
57908 +#ifdef CONFIG_X86
57909 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57910 +#endif
57911 +
57912 + for (j = 0; j < 4; j++) {
57913 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57914 + if (gr_shared_page[j] == NULL) {
57915 + panic("Unable to allocate grsecurity shared page");
57916 + return;
57917 + }
57918 + }
57919 +
57920 + /* allocate log buffers */
57921 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57922 + if (!gr_alert_log_fmt) {
57923 + panic("Unable to allocate grsecurity alert log format buffer");
57924 + return;
57925 + }
57926 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57927 + if (!gr_audit_log_fmt) {
57928 + panic("Unable to allocate grsecurity audit log format buffer");
57929 + return;
57930 + }
57931 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57932 + if (!gr_alert_log_buf) {
57933 + panic("Unable to allocate grsecurity alert log buffer");
57934 + return;
57935 + }
57936 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57937 + if (!gr_audit_log_buf) {
57938 + panic("Unable to allocate grsecurity audit log buffer");
57939 + return;
57940 + }
57941 +
57942 + /* allocate memory for authentication structure */
57943 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57944 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
57945 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
57946 +
57947 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
57948 + panic("Unable to allocate grsecurity authentication structure");
57949 + return;
57950 + }
57951 +
57952 +
57953 +#ifdef CONFIG_GRKERNSEC_IO
57954 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
57955 + grsec_disable_privio = 1;
57956 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57957 + grsec_disable_privio = 1;
57958 +#else
57959 + grsec_disable_privio = 0;
57960 +#endif
57961 +#endif
57962 +
57963 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57964 + /* for backward compatibility, tpe_invert always defaults to on if
57965 + enabled in the kernel
57966 + */
57967 + grsec_enable_tpe_invert = 1;
57968 +#endif
57969 +
57970 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57971 +#ifndef CONFIG_GRKERNSEC_SYSCTL
57972 + grsec_lock = 1;
57973 +#endif
57974 +
57975 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57976 + grsec_enable_audit_textrel = 1;
57977 +#endif
57978 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57979 + grsec_enable_log_rwxmaps = 1;
57980 +#endif
57981 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
57982 + grsec_enable_group = 1;
57983 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
57984 +#endif
57985 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57986 + grsec_enable_ptrace_readexec = 1;
57987 +#endif
57988 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57989 + grsec_enable_chdir = 1;
57990 +#endif
57991 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57992 + grsec_enable_harden_ptrace = 1;
57993 +#endif
57994 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57995 + grsec_enable_mount = 1;
57996 +#endif
57997 +#ifdef CONFIG_GRKERNSEC_LINK
57998 + grsec_enable_link = 1;
57999 +#endif
58000 +#ifdef CONFIG_GRKERNSEC_BRUTE
58001 + grsec_enable_brute = 1;
58002 +#endif
58003 +#ifdef CONFIG_GRKERNSEC_DMESG
58004 + grsec_enable_dmesg = 1;
58005 +#endif
58006 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58007 + grsec_enable_blackhole = 1;
58008 + grsec_lastack_retries = 4;
58009 +#endif
58010 +#ifdef CONFIG_GRKERNSEC_FIFO
58011 + grsec_enable_fifo = 1;
58012 +#endif
58013 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58014 + grsec_enable_execlog = 1;
58015 +#endif
58016 +#ifdef CONFIG_GRKERNSEC_SETXID
58017 + grsec_enable_setxid = 1;
58018 +#endif
58019 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58020 + grsec_enable_signal = 1;
58021 +#endif
58022 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58023 + grsec_enable_forkfail = 1;
58024 +#endif
58025 +#ifdef CONFIG_GRKERNSEC_TIME
58026 + grsec_enable_time = 1;
58027 +#endif
58028 +#ifdef CONFIG_GRKERNSEC_RESLOG
58029 + grsec_resource_logging = 1;
58030 +#endif
58031 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58032 + grsec_enable_chroot_findtask = 1;
58033 +#endif
58034 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58035 + grsec_enable_chroot_unix = 1;
58036 +#endif
58037 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58038 + grsec_enable_chroot_mount = 1;
58039 +#endif
58040 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58041 + grsec_enable_chroot_fchdir = 1;
58042 +#endif
58043 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58044 + grsec_enable_chroot_shmat = 1;
58045 +#endif
58046 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58047 + grsec_enable_audit_ptrace = 1;
58048 +#endif
58049 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58050 + grsec_enable_chroot_double = 1;
58051 +#endif
58052 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58053 + grsec_enable_chroot_pivot = 1;
58054 +#endif
58055 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58056 + grsec_enable_chroot_chdir = 1;
58057 +#endif
58058 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58059 + grsec_enable_chroot_chmod = 1;
58060 +#endif
58061 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58062 + grsec_enable_chroot_mknod = 1;
58063 +#endif
58064 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58065 + grsec_enable_chroot_nice = 1;
58066 +#endif
58067 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58068 + grsec_enable_chroot_execlog = 1;
58069 +#endif
58070 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58071 + grsec_enable_chroot_caps = 1;
58072 +#endif
58073 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58074 + grsec_enable_chroot_sysctl = 1;
58075 +#endif
58076 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58077 + grsec_enable_symlinkown = 1;
58078 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58079 +#endif
58080 +#ifdef CONFIG_GRKERNSEC_TPE
58081 + grsec_enable_tpe = 1;
58082 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58083 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58084 + grsec_enable_tpe_all = 1;
58085 +#endif
58086 +#endif
58087 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58088 + grsec_enable_socket_all = 1;
58089 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58090 +#endif
58091 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58092 + grsec_enable_socket_client = 1;
58093 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58094 +#endif
58095 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58096 + grsec_enable_socket_server = 1;
58097 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58098 +#endif
58099 +#endif
58100 +
58101 + return;
58102 +}
58103 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58104 new file mode 100644
58105 index 0000000..589481f
58106 --- /dev/null
58107 +++ b/grsecurity/grsec_link.c
58108 @@ -0,0 +1,58 @@
58109 +#include <linux/kernel.h>
58110 +#include <linux/sched.h>
58111 +#include <linux/fs.h>
58112 +#include <linux/file.h>
58113 +#include <linux/grinternal.h>
58114 +
58115 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58116 +{
58117 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58118 + const struct inode *link_inode = link->dentry->d_inode;
58119 +
58120 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58121 + /* ignore root-owned links, e.g. /proc/self */
58122 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58123 + !uid_eq(link_inode->i_uid, target->i_uid)) {
58124 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58125 + return 1;
58126 + }
58127 +#endif
58128 + return 0;
58129 +}
58130 +
58131 +int
58132 +gr_handle_follow_link(const struct inode *parent,
58133 + const struct inode *inode,
58134 + const struct dentry *dentry, const struct vfsmount *mnt)
58135 +{
58136 +#ifdef CONFIG_GRKERNSEC_LINK
58137 + const struct cred *cred = current_cred();
58138 +
58139 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58140 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58141 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58142 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58143 + return -EACCES;
58144 + }
58145 +#endif
58146 + return 0;
58147 +}
58148 +
58149 +int
58150 +gr_handle_hardlink(const struct dentry *dentry,
58151 + const struct vfsmount *mnt,
58152 + struct inode *inode, const int mode, const char *to)
58153 +{
58154 +#ifdef CONFIG_GRKERNSEC_LINK
58155 + const struct cred *cred = current_cred();
58156 +
58157 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58158 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58159 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58160 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58161 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58162 + return -EPERM;
58163 + }
58164 +#endif
58165 + return 0;
58166 +}
58167 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58168 new file mode 100644
58169 index 0000000..a45d2e9
58170 --- /dev/null
58171 +++ b/grsecurity/grsec_log.c
58172 @@ -0,0 +1,322 @@
58173 +#include <linux/kernel.h>
58174 +#include <linux/sched.h>
58175 +#include <linux/file.h>
58176 +#include <linux/tty.h>
58177 +#include <linux/fs.h>
58178 +#include <linux/grinternal.h>
58179 +
58180 +#ifdef CONFIG_TREE_PREEMPT_RCU
58181 +#define DISABLE_PREEMPT() preempt_disable()
58182 +#define ENABLE_PREEMPT() preempt_enable()
58183 +#else
58184 +#define DISABLE_PREEMPT()
58185 +#define ENABLE_PREEMPT()
58186 +#endif
58187 +
58188 +#define BEGIN_LOCKS(x) \
58189 + DISABLE_PREEMPT(); \
58190 + rcu_read_lock(); \
58191 + read_lock(&tasklist_lock); \
58192 + read_lock(&grsec_exec_file_lock); \
58193 + if (x != GR_DO_AUDIT) \
58194 + spin_lock(&grsec_alert_lock); \
58195 + else \
58196 + spin_lock(&grsec_audit_lock)
58197 +
58198 +#define END_LOCKS(x) \
58199 + if (x != GR_DO_AUDIT) \
58200 + spin_unlock(&grsec_alert_lock); \
58201 + else \
58202 + spin_unlock(&grsec_audit_lock); \
58203 + read_unlock(&grsec_exec_file_lock); \
58204 + read_unlock(&tasklist_lock); \
58205 + rcu_read_unlock(); \
58206 + ENABLE_PREEMPT(); \
58207 + if (x == GR_DONT_AUDIT) \
58208 + gr_handle_alertkill(current)
58209 +
58210 +enum {
58211 + FLOODING,
58212 + NO_FLOODING
58213 +};
58214 +
58215 +extern char *gr_alert_log_fmt;
58216 +extern char *gr_audit_log_fmt;
58217 +extern char *gr_alert_log_buf;
58218 +extern char *gr_audit_log_buf;
58219 +
58220 +static int gr_log_start(int audit)
58221 +{
58222 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58223 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58224 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58225 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58226 + unsigned long curr_secs = get_seconds();
58227 +
58228 + if (audit == GR_DO_AUDIT)
58229 + goto set_fmt;
58230 +
58231 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58232 + grsec_alert_wtime = curr_secs;
58233 + grsec_alert_fyet = 0;
58234 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58235 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58236 + grsec_alert_fyet++;
58237 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58238 + grsec_alert_wtime = curr_secs;
58239 + grsec_alert_fyet++;
58240 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58241 + return FLOODING;
58242 + }
58243 + else return FLOODING;
58244 +
58245 +set_fmt:
58246 +#endif
58247 + memset(buf, 0, PAGE_SIZE);
58248 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58249 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58250 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58251 + } else if (current->signal->curr_ip) {
58252 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58253 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58254 + } else if (gr_acl_is_enabled()) {
58255 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58256 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58257 + } else {
58258 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58259 + strcpy(buf, fmt);
58260 + }
58261 +
58262 + return NO_FLOODING;
58263 +}
58264 +
58265 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58266 + __attribute__ ((format (printf, 2, 0)));
58267 +
58268 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58269 +{
58270 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58271 + unsigned int len = strlen(buf);
58272 +
58273 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58274 +
58275 + return;
58276 +}
58277 +
58278 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58279 + __attribute__ ((format (printf, 2, 3)));
58280 +
58281 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58282 +{
58283 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58284 + unsigned int len = strlen(buf);
58285 + va_list ap;
58286 +
58287 + va_start(ap, msg);
58288 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58289 + va_end(ap);
58290 +
58291 + return;
58292 +}
58293 +
58294 +static void gr_log_end(int audit, int append_default)
58295 +{
58296 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58297 +
58298 + if (append_default) {
58299 + unsigned int len = strlen(buf);
58300 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58301 + }
58302 +
58303 + printk("%s\n", buf);
58304 +
58305 + return;
58306 +}
58307 +
58308 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58309 +{
58310 + int logtype;
58311 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58312 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58313 + void *voidptr = NULL;
58314 + int num1 = 0, num2 = 0;
58315 + unsigned long ulong1 = 0, ulong2 = 0;
58316 + struct dentry *dentry = NULL;
58317 + struct vfsmount *mnt = NULL;
58318 + struct file *file = NULL;
58319 + struct task_struct *task = NULL;
58320 + const struct cred *cred, *pcred;
58321 + va_list ap;
58322 +
58323 + BEGIN_LOCKS(audit);
58324 + logtype = gr_log_start(audit);
58325 + if (logtype == FLOODING) {
58326 + END_LOCKS(audit);
58327 + return;
58328 + }
58329 + va_start(ap, argtypes);
58330 + switch (argtypes) {
58331 + case GR_TTYSNIFF:
58332 + task = va_arg(ap, struct task_struct *);
58333 + 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);
58334 + break;
58335 + case GR_SYSCTL_HIDDEN:
58336 + str1 = va_arg(ap, char *);
58337 + gr_log_middle_varargs(audit, msg, result, str1);
58338 + break;
58339 + case GR_RBAC:
58340 + dentry = va_arg(ap, struct dentry *);
58341 + mnt = va_arg(ap, struct vfsmount *);
58342 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58343 + break;
58344 + case GR_RBAC_STR:
58345 + dentry = va_arg(ap, struct dentry *);
58346 + mnt = va_arg(ap, struct vfsmount *);
58347 + str1 = va_arg(ap, char *);
58348 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58349 + break;
58350 + case GR_STR_RBAC:
58351 + str1 = va_arg(ap, char *);
58352 + dentry = va_arg(ap, struct dentry *);
58353 + mnt = va_arg(ap, struct vfsmount *);
58354 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58355 + break;
58356 + case GR_RBAC_MODE2:
58357 + dentry = va_arg(ap, struct dentry *);
58358 + mnt = va_arg(ap, struct vfsmount *);
58359 + str1 = va_arg(ap, char *);
58360 + str2 = va_arg(ap, char *);
58361 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58362 + break;
58363 + case GR_RBAC_MODE3:
58364 + dentry = va_arg(ap, struct dentry *);
58365 + mnt = va_arg(ap, struct vfsmount *);
58366 + str1 = va_arg(ap, char *);
58367 + str2 = va_arg(ap, char *);
58368 + str3 = va_arg(ap, char *);
58369 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58370 + break;
58371 + case GR_FILENAME:
58372 + dentry = va_arg(ap, struct dentry *);
58373 + mnt = va_arg(ap, struct vfsmount *);
58374 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58375 + break;
58376 + case GR_STR_FILENAME:
58377 + str1 = va_arg(ap, char *);
58378 + dentry = va_arg(ap, struct dentry *);
58379 + mnt = va_arg(ap, struct vfsmount *);
58380 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58381 + break;
58382 + case GR_FILENAME_STR:
58383 + dentry = va_arg(ap, struct dentry *);
58384 + mnt = va_arg(ap, struct vfsmount *);
58385 + str1 = va_arg(ap, char *);
58386 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58387 + break;
58388 + case GR_FILENAME_TWO_INT:
58389 + dentry = va_arg(ap, struct dentry *);
58390 + mnt = va_arg(ap, struct vfsmount *);
58391 + num1 = va_arg(ap, int);
58392 + num2 = va_arg(ap, int);
58393 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58394 + break;
58395 + case GR_FILENAME_TWO_INT_STR:
58396 + dentry = va_arg(ap, struct dentry *);
58397 + mnt = va_arg(ap, struct vfsmount *);
58398 + num1 = va_arg(ap, int);
58399 + num2 = va_arg(ap, int);
58400 + str1 = va_arg(ap, char *);
58401 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58402 + break;
58403 + case GR_TEXTREL:
58404 + file = va_arg(ap, struct file *);
58405 + ulong1 = va_arg(ap, unsigned long);
58406 + ulong2 = va_arg(ap, unsigned long);
58407 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58408 + break;
58409 + case GR_PTRACE:
58410 + task = va_arg(ap, struct task_struct *);
58411 + 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);
58412 + break;
58413 + case GR_RESOURCE:
58414 + task = va_arg(ap, struct task_struct *);
58415 + cred = __task_cred(task);
58416 + pcred = __task_cred(task->real_parent);
58417 + ulong1 = va_arg(ap, unsigned long);
58418 + str1 = va_arg(ap, char *);
58419 + ulong2 = va_arg(ap, unsigned long);
58420 + 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);
58421 + break;
58422 + case GR_CAP:
58423 + task = va_arg(ap, struct task_struct *);
58424 + cred = __task_cred(task);
58425 + pcred = __task_cred(task->real_parent);
58426 + str1 = va_arg(ap, char *);
58427 + 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);
58428 + break;
58429 + case GR_SIG:
58430 + str1 = va_arg(ap, char *);
58431 + voidptr = va_arg(ap, void *);
58432 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58433 + break;
58434 + case GR_SIG2:
58435 + task = va_arg(ap, struct task_struct *);
58436 + cred = __task_cred(task);
58437 + pcred = __task_cred(task->real_parent);
58438 + num1 = va_arg(ap, int);
58439 + 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);
58440 + break;
58441 + case GR_CRASH1:
58442 + task = va_arg(ap, struct task_struct *);
58443 + cred = __task_cred(task);
58444 + pcred = __task_cred(task->real_parent);
58445 + ulong1 = va_arg(ap, unsigned long);
58446 + 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);
58447 + break;
58448 + case GR_CRASH2:
58449 + task = va_arg(ap, struct task_struct *);
58450 + cred = __task_cred(task);
58451 + pcred = __task_cred(task->real_parent);
58452 + ulong1 = va_arg(ap, unsigned long);
58453 + 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);
58454 + break;
58455 + case GR_RWXMAP:
58456 + file = va_arg(ap, struct file *);
58457 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58458 + break;
58459 + case GR_PSACCT:
58460 + {
58461 + unsigned int wday, cday;
58462 + __u8 whr, chr;
58463 + __u8 wmin, cmin;
58464 + __u8 wsec, csec;
58465 + char cur_tty[64] = { 0 };
58466 + char parent_tty[64] = { 0 };
58467 +
58468 + task = va_arg(ap, struct task_struct *);
58469 + wday = va_arg(ap, unsigned int);
58470 + cday = va_arg(ap, unsigned int);
58471 + whr = va_arg(ap, int);
58472 + chr = va_arg(ap, int);
58473 + wmin = va_arg(ap, int);
58474 + cmin = va_arg(ap, int);
58475 + wsec = va_arg(ap, int);
58476 + csec = va_arg(ap, int);
58477 + ulong1 = va_arg(ap, unsigned long);
58478 + cred = __task_cred(task);
58479 + pcred = __task_cred(task->real_parent);
58480 +
58481 + 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);
58482 + }
58483 + break;
58484 + default:
58485 + gr_log_middle(audit, msg, ap);
58486 + }
58487 + va_end(ap);
58488 + // these don't need DEFAULTSECARGS printed on the end
58489 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58490 + gr_log_end(audit, 0);
58491 + else
58492 + gr_log_end(audit, 1);
58493 + END_LOCKS(audit);
58494 +}
58495 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58496 new file mode 100644
58497 index 0000000..f536303
58498 --- /dev/null
58499 +++ b/grsecurity/grsec_mem.c
58500 @@ -0,0 +1,40 @@
58501 +#include <linux/kernel.h>
58502 +#include <linux/sched.h>
58503 +#include <linux/mm.h>
58504 +#include <linux/mman.h>
58505 +#include <linux/grinternal.h>
58506 +
58507 +void
58508 +gr_handle_ioperm(void)
58509 +{
58510 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58511 + return;
58512 +}
58513 +
58514 +void
58515 +gr_handle_iopl(void)
58516 +{
58517 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58518 + return;
58519 +}
58520 +
58521 +void
58522 +gr_handle_mem_readwrite(u64 from, u64 to)
58523 +{
58524 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58525 + return;
58526 +}
58527 +
58528 +void
58529 +gr_handle_vm86(void)
58530 +{
58531 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58532 + return;
58533 +}
58534 +
58535 +void
58536 +gr_log_badprocpid(const char *entry)
58537 +{
58538 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58539 + return;
58540 +}
58541 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58542 new file mode 100644
58543 index 0000000..2131422
58544 --- /dev/null
58545 +++ b/grsecurity/grsec_mount.c
58546 @@ -0,0 +1,62 @@
58547 +#include <linux/kernel.h>
58548 +#include <linux/sched.h>
58549 +#include <linux/mount.h>
58550 +#include <linux/grsecurity.h>
58551 +#include <linux/grinternal.h>
58552 +
58553 +void
58554 +gr_log_remount(const char *devname, const int retval)
58555 +{
58556 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58557 + if (grsec_enable_mount && (retval >= 0))
58558 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58559 +#endif
58560 + return;
58561 +}
58562 +
58563 +void
58564 +gr_log_unmount(const char *devname, const int retval)
58565 +{
58566 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58567 + if (grsec_enable_mount && (retval >= 0))
58568 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58569 +#endif
58570 + return;
58571 +}
58572 +
58573 +void
58574 +gr_log_mount(const char *from, const char *to, const int retval)
58575 +{
58576 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58577 + if (grsec_enable_mount && (retval >= 0))
58578 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58579 +#endif
58580 + return;
58581 +}
58582 +
58583 +int
58584 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58585 +{
58586 +#ifdef CONFIG_GRKERNSEC_ROFS
58587 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58588 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58589 + return -EPERM;
58590 + } else
58591 + return 0;
58592 +#endif
58593 + return 0;
58594 +}
58595 +
58596 +int
58597 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58598 +{
58599 +#ifdef CONFIG_GRKERNSEC_ROFS
58600 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58601 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58602 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58603 + return -EPERM;
58604 + } else
58605 + return 0;
58606 +#endif
58607 + return 0;
58608 +}
58609 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58610 new file mode 100644
58611 index 0000000..a3b12a0
58612 --- /dev/null
58613 +++ b/grsecurity/grsec_pax.c
58614 @@ -0,0 +1,36 @@
58615 +#include <linux/kernel.h>
58616 +#include <linux/sched.h>
58617 +#include <linux/mm.h>
58618 +#include <linux/file.h>
58619 +#include <linux/grinternal.h>
58620 +#include <linux/grsecurity.h>
58621 +
58622 +void
58623 +gr_log_textrel(struct vm_area_struct * vma)
58624 +{
58625 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58626 + if (grsec_enable_audit_textrel)
58627 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58628 +#endif
58629 + return;
58630 +}
58631 +
58632 +void
58633 +gr_log_rwxmmap(struct file *file)
58634 +{
58635 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58636 + if (grsec_enable_log_rwxmaps)
58637 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58638 +#endif
58639 + return;
58640 +}
58641 +
58642 +void
58643 +gr_log_rwxmprotect(struct file *file)
58644 +{
58645 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58646 + if (grsec_enable_log_rwxmaps)
58647 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58648 +#endif
58649 + return;
58650 +}
58651 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58652 new file mode 100644
58653 index 0000000..f7f29aa
58654 --- /dev/null
58655 +++ b/grsecurity/grsec_ptrace.c
58656 @@ -0,0 +1,30 @@
58657 +#include <linux/kernel.h>
58658 +#include <linux/sched.h>
58659 +#include <linux/grinternal.h>
58660 +#include <linux/security.h>
58661 +
58662 +void
58663 +gr_audit_ptrace(struct task_struct *task)
58664 +{
58665 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58666 + if (grsec_enable_audit_ptrace)
58667 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58668 +#endif
58669 + return;
58670 +}
58671 +
58672 +int
58673 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
58674 +{
58675 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58676 + const struct dentry *dentry = file->f_path.dentry;
58677 + const struct vfsmount *mnt = file->f_path.mnt;
58678 +
58679 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58680 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58681 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58682 + return -EACCES;
58683 + }
58684 +#endif
58685 + return 0;
58686 +}
58687 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58688 new file mode 100644
58689 index 0000000..b4ac94c
58690 --- /dev/null
58691 +++ b/grsecurity/grsec_sig.c
58692 @@ -0,0 +1,209 @@
58693 +#include <linux/kernel.h>
58694 +#include <linux/sched.h>
58695 +#include <linux/delay.h>
58696 +#include <linux/grsecurity.h>
58697 +#include <linux/grinternal.h>
58698 +#include <linux/hardirq.h>
58699 +
58700 +char *signames[] = {
58701 + [SIGSEGV] = "Segmentation fault",
58702 + [SIGILL] = "Illegal instruction",
58703 + [SIGABRT] = "Abort",
58704 + [SIGBUS] = "Invalid alignment/Bus error"
58705 +};
58706 +
58707 +void
58708 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58709 +{
58710 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58711 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58712 + (sig == SIGABRT) || (sig == SIGBUS))) {
58713 + if (t->pid == current->pid) {
58714 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58715 + } else {
58716 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58717 + }
58718 + }
58719 +#endif
58720 + return;
58721 +}
58722 +
58723 +int
58724 +gr_handle_signal(const struct task_struct *p, const int sig)
58725 +{
58726 +#ifdef CONFIG_GRKERNSEC
58727 + /* ignore the 0 signal for protected task checks */
58728 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58729 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58730 + return -EPERM;
58731 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58732 + return -EPERM;
58733 + }
58734 +#endif
58735 + return 0;
58736 +}
58737 +
58738 +#ifdef CONFIG_GRKERNSEC
58739 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58740 +
58741 +int gr_fake_force_sig(int sig, struct task_struct *t)
58742 +{
58743 + unsigned long int flags;
58744 + int ret, blocked, ignored;
58745 + struct k_sigaction *action;
58746 +
58747 + spin_lock_irqsave(&t->sighand->siglock, flags);
58748 + action = &t->sighand->action[sig-1];
58749 + ignored = action->sa.sa_handler == SIG_IGN;
58750 + blocked = sigismember(&t->blocked, sig);
58751 + if (blocked || ignored) {
58752 + action->sa.sa_handler = SIG_DFL;
58753 + if (blocked) {
58754 + sigdelset(&t->blocked, sig);
58755 + recalc_sigpending_and_wake(t);
58756 + }
58757 + }
58758 + if (action->sa.sa_handler == SIG_DFL)
58759 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
58760 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58761 +
58762 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
58763 +
58764 + return ret;
58765 +}
58766 +#endif
58767 +
58768 +#ifdef CONFIG_GRKERNSEC_BRUTE
58769 +#define GR_USER_BAN_TIME (15 * 60)
58770 +
58771 +static int __get_dumpable(unsigned long mm_flags)
58772 +{
58773 + int ret;
58774 +
58775 + ret = mm_flags & MMF_DUMPABLE_MASK;
58776 + return (ret >= 2) ? 2 : ret;
58777 +}
58778 +#endif
58779 +
58780 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58781 +{
58782 +#ifdef CONFIG_GRKERNSEC_BRUTE
58783 + kuid_t uid = GLOBAL_ROOT_UID;
58784 +
58785 + if (!grsec_enable_brute)
58786 + return;
58787 +
58788 + rcu_read_lock();
58789 + read_lock(&tasklist_lock);
58790 + read_lock(&grsec_exec_file_lock);
58791 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58792 + p->real_parent->brute = 1;
58793 + else {
58794 + const struct cred *cred = __task_cred(p), *cred2;
58795 + struct task_struct *tsk, *tsk2;
58796 +
58797 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58798 + struct user_struct *user;
58799 +
58800 + uid = cred->uid;
58801 +
58802 + /* this is put upon execution past expiration */
58803 + user = find_user(uid);
58804 + if (user == NULL)
58805 + goto unlock;
58806 + user->banned = 1;
58807 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58808 + if (user->ban_expires == ~0UL)
58809 + user->ban_expires--;
58810 +
58811 + do_each_thread(tsk2, tsk) {
58812 + cred2 = __task_cred(tsk);
58813 + if (tsk != p && uid_eq(cred2->uid, uid))
58814 + gr_fake_force_sig(SIGKILL, tsk);
58815 + } while_each_thread(tsk2, tsk);
58816 + }
58817 + }
58818 +unlock:
58819 + read_unlock(&grsec_exec_file_lock);
58820 + read_unlock(&tasklist_lock);
58821 + rcu_read_unlock();
58822 +
58823 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
58824 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
58825 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
58826 +
58827 +#endif
58828 + return;
58829 +}
58830 +
58831 +void gr_handle_brute_check(void)
58832 +{
58833 +#ifdef CONFIG_GRKERNSEC_BRUTE
58834 + if (current->brute)
58835 + msleep(30 * 1000);
58836 +#endif
58837 + return;
58838 +}
58839 +
58840 +void gr_handle_kernel_exploit(void)
58841 +{
58842 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58843 + const struct cred *cred;
58844 + struct task_struct *tsk, *tsk2;
58845 + struct user_struct *user;
58846 + kuid_t uid;
58847 +
58848 + if (in_irq() || in_serving_softirq() || in_nmi())
58849 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58850 +
58851 + uid = current_uid();
58852 +
58853 + if (uid_eq(uid, GLOBAL_ROOT_UID))
58854 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
58855 + else {
58856 + /* kill all the processes of this user, hold a reference
58857 + to their creds struct, and prevent them from creating
58858 + another process until system reset
58859 + */
58860 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
58861 + from_kuid_munged(&init_user_ns, uid));
58862 + /* we intentionally leak this ref */
58863 + user = get_uid(current->cred->user);
58864 + if (user) {
58865 + user->banned = 1;
58866 + user->ban_expires = ~0UL;
58867 + }
58868 +
58869 + read_lock(&tasklist_lock);
58870 + do_each_thread(tsk2, tsk) {
58871 + cred = __task_cred(tsk);
58872 + if (uid_eq(cred->uid, uid))
58873 + gr_fake_force_sig(SIGKILL, tsk);
58874 + } while_each_thread(tsk2, tsk);
58875 + read_unlock(&tasklist_lock);
58876 + }
58877 +#endif
58878 +}
58879 +
58880 +int __gr_process_user_ban(struct user_struct *user)
58881 +{
58882 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58883 + if (unlikely(user->banned)) {
58884 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58885 + user->banned = 0;
58886 + user->ban_expires = 0;
58887 + free_uid(user);
58888 + } else
58889 + return -EPERM;
58890 + }
58891 +#endif
58892 + return 0;
58893 +}
58894 +
58895 +int gr_process_user_ban(void)
58896 +{
58897 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58898 + return __gr_process_user_ban(current->cred->user);
58899 +#endif
58900 + return 0;
58901 +}
58902 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58903 new file mode 100644
58904 index 0000000..4030d57
58905 --- /dev/null
58906 +++ b/grsecurity/grsec_sock.c
58907 @@ -0,0 +1,244 @@
58908 +#include <linux/kernel.h>
58909 +#include <linux/module.h>
58910 +#include <linux/sched.h>
58911 +#include <linux/file.h>
58912 +#include <linux/net.h>
58913 +#include <linux/in.h>
58914 +#include <linux/ip.h>
58915 +#include <net/sock.h>
58916 +#include <net/inet_sock.h>
58917 +#include <linux/grsecurity.h>
58918 +#include <linux/grinternal.h>
58919 +#include <linux/gracl.h>
58920 +
58921 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58922 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58923 +
58924 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
58925 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
58926 +
58927 +#ifdef CONFIG_UNIX_MODULE
58928 +EXPORT_SYMBOL(gr_acl_handle_unix);
58929 +EXPORT_SYMBOL(gr_acl_handle_mknod);
58930 +EXPORT_SYMBOL(gr_handle_chroot_unix);
58931 +EXPORT_SYMBOL(gr_handle_create);
58932 +#endif
58933 +
58934 +#ifdef CONFIG_GRKERNSEC
58935 +#define gr_conn_table_size 32749
58936 +struct conn_table_entry {
58937 + struct conn_table_entry *next;
58938 + struct signal_struct *sig;
58939 +};
58940 +
58941 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58942 +DEFINE_SPINLOCK(gr_conn_table_lock);
58943 +
58944 +extern const char * gr_socktype_to_name(unsigned char type);
58945 +extern const char * gr_proto_to_name(unsigned char proto);
58946 +extern const char * gr_sockfamily_to_name(unsigned char family);
58947 +
58948 +static __inline__ int
58949 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58950 +{
58951 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58952 +}
58953 +
58954 +static __inline__ int
58955 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58956 + __u16 sport, __u16 dport)
58957 +{
58958 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58959 + sig->gr_sport == sport && sig->gr_dport == dport))
58960 + return 1;
58961 + else
58962 + return 0;
58963 +}
58964 +
58965 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58966 +{
58967 + struct conn_table_entry **match;
58968 + unsigned int index;
58969 +
58970 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58971 + sig->gr_sport, sig->gr_dport,
58972 + gr_conn_table_size);
58973 +
58974 + newent->sig = sig;
58975 +
58976 + match = &gr_conn_table[index];
58977 + newent->next = *match;
58978 + *match = newent;
58979 +
58980 + return;
58981 +}
58982 +
58983 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58984 +{
58985 + struct conn_table_entry *match, *last = NULL;
58986 + unsigned int index;
58987 +
58988 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58989 + sig->gr_sport, sig->gr_dport,
58990 + gr_conn_table_size);
58991 +
58992 + match = gr_conn_table[index];
58993 + while (match && !conn_match(match->sig,
58994 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58995 + sig->gr_dport)) {
58996 + last = match;
58997 + match = match->next;
58998 + }
58999 +
59000 + if (match) {
59001 + if (last)
59002 + last->next = match->next;
59003 + else
59004 + gr_conn_table[index] = NULL;
59005 + kfree(match);
59006 + }
59007 +
59008 + return;
59009 +}
59010 +
59011 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59012 + __u16 sport, __u16 dport)
59013 +{
59014 + struct conn_table_entry *match;
59015 + unsigned int index;
59016 +
59017 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59018 +
59019 + match = gr_conn_table[index];
59020 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59021 + match = match->next;
59022 +
59023 + if (match)
59024 + return match->sig;
59025 + else
59026 + return NULL;
59027 +}
59028 +
59029 +#endif
59030 +
59031 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59032 +{
59033 +#ifdef CONFIG_GRKERNSEC
59034 + struct signal_struct *sig = task->signal;
59035 + struct conn_table_entry *newent;
59036 +
59037 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59038 + if (newent == NULL)
59039 + return;
59040 + /* no bh lock needed since we are called with bh disabled */
59041 + spin_lock(&gr_conn_table_lock);
59042 + gr_del_task_from_ip_table_nolock(sig);
59043 + sig->gr_saddr = inet->inet_rcv_saddr;
59044 + sig->gr_daddr = inet->inet_daddr;
59045 + sig->gr_sport = inet->inet_sport;
59046 + sig->gr_dport = inet->inet_dport;
59047 + gr_add_to_task_ip_table_nolock(sig, newent);
59048 + spin_unlock(&gr_conn_table_lock);
59049 +#endif
59050 + return;
59051 +}
59052 +
59053 +void gr_del_task_from_ip_table(struct task_struct *task)
59054 +{
59055 +#ifdef CONFIG_GRKERNSEC
59056 + spin_lock_bh(&gr_conn_table_lock);
59057 + gr_del_task_from_ip_table_nolock(task->signal);
59058 + spin_unlock_bh(&gr_conn_table_lock);
59059 +#endif
59060 + return;
59061 +}
59062 +
59063 +void
59064 +gr_attach_curr_ip(const struct sock *sk)
59065 +{
59066 +#ifdef CONFIG_GRKERNSEC
59067 + struct signal_struct *p, *set;
59068 + const struct inet_sock *inet = inet_sk(sk);
59069 +
59070 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59071 + return;
59072 +
59073 + set = current->signal;
59074 +
59075 + spin_lock_bh(&gr_conn_table_lock);
59076 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59077 + inet->inet_dport, inet->inet_sport);
59078 + if (unlikely(p != NULL)) {
59079 + set->curr_ip = p->curr_ip;
59080 + set->used_accept = 1;
59081 + gr_del_task_from_ip_table_nolock(p);
59082 + spin_unlock_bh(&gr_conn_table_lock);
59083 + return;
59084 + }
59085 + spin_unlock_bh(&gr_conn_table_lock);
59086 +
59087 + set->curr_ip = inet->inet_daddr;
59088 + set->used_accept = 1;
59089 +#endif
59090 + return;
59091 +}
59092 +
59093 +int
59094 +gr_handle_sock_all(const int family, const int type, const int protocol)
59095 +{
59096 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59097 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59098 + (family != AF_UNIX)) {
59099 + if (family == AF_INET)
59100 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59101 + else
59102 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59103 + return -EACCES;
59104 + }
59105 +#endif
59106 + return 0;
59107 +}
59108 +
59109 +int
59110 +gr_handle_sock_server(const struct sockaddr *sck)
59111 +{
59112 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59113 + if (grsec_enable_socket_server &&
59114 + in_group_p(grsec_socket_server_gid) &&
59115 + sck && (sck->sa_family != AF_UNIX) &&
59116 + (sck->sa_family != AF_LOCAL)) {
59117 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59118 + return -EACCES;
59119 + }
59120 +#endif
59121 + return 0;
59122 +}
59123 +
59124 +int
59125 +gr_handle_sock_server_other(const struct sock *sck)
59126 +{
59127 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59128 + if (grsec_enable_socket_server &&
59129 + in_group_p(grsec_socket_server_gid) &&
59130 + sck && (sck->sk_family != AF_UNIX) &&
59131 + (sck->sk_family != AF_LOCAL)) {
59132 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59133 + return -EACCES;
59134 + }
59135 +#endif
59136 + return 0;
59137 +}
59138 +
59139 +int
59140 +gr_handle_sock_client(const struct sockaddr *sck)
59141 +{
59142 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59143 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59144 + sck && (sck->sa_family != AF_UNIX) &&
59145 + (sck->sa_family != AF_LOCAL)) {
59146 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59147 + return -EACCES;
59148 + }
59149 +#endif
59150 + return 0;
59151 +}
59152 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59153 new file mode 100644
59154 index 0000000..f55ef0f
59155 --- /dev/null
59156 +++ b/grsecurity/grsec_sysctl.c
59157 @@ -0,0 +1,469 @@
59158 +#include <linux/kernel.h>
59159 +#include <linux/sched.h>
59160 +#include <linux/sysctl.h>
59161 +#include <linux/grsecurity.h>
59162 +#include <linux/grinternal.h>
59163 +
59164 +int
59165 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59166 +{
59167 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59168 + if (dirname == NULL || name == NULL)
59169 + return 0;
59170 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59171 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59172 + return -EACCES;
59173 + }
59174 +#endif
59175 + return 0;
59176 +}
59177 +
59178 +#ifdef CONFIG_GRKERNSEC_ROFS
59179 +static int __maybe_unused one = 1;
59180 +#endif
59181 +
59182 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59183 +struct ctl_table grsecurity_table[] = {
59184 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59185 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59186 +#ifdef CONFIG_GRKERNSEC_IO
59187 + {
59188 + .procname = "disable_priv_io",
59189 + .data = &grsec_disable_privio,
59190 + .maxlen = sizeof(int),
59191 + .mode = 0600,
59192 + .proc_handler = &proc_dointvec,
59193 + },
59194 +#endif
59195 +#endif
59196 +#ifdef CONFIG_GRKERNSEC_LINK
59197 + {
59198 + .procname = "linking_restrictions",
59199 + .data = &grsec_enable_link,
59200 + .maxlen = sizeof(int),
59201 + .mode = 0600,
59202 + .proc_handler = &proc_dointvec,
59203 + },
59204 +#endif
59205 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59206 + {
59207 + .procname = "enforce_symlinksifowner",
59208 + .data = &grsec_enable_symlinkown,
59209 + .maxlen = sizeof(int),
59210 + .mode = 0600,
59211 + .proc_handler = &proc_dointvec,
59212 + },
59213 + {
59214 + .procname = "symlinkown_gid",
59215 + .data = &grsec_symlinkown_gid,
59216 + .maxlen = sizeof(int),
59217 + .mode = 0600,
59218 + .proc_handler = &proc_dointvec,
59219 + },
59220 +#endif
59221 +#ifdef CONFIG_GRKERNSEC_BRUTE
59222 + {
59223 + .procname = "deter_bruteforce",
59224 + .data = &grsec_enable_brute,
59225 + .maxlen = sizeof(int),
59226 + .mode = 0600,
59227 + .proc_handler = &proc_dointvec,
59228 + },
59229 +#endif
59230 +#ifdef CONFIG_GRKERNSEC_FIFO
59231 + {
59232 + .procname = "fifo_restrictions",
59233 + .data = &grsec_enable_fifo,
59234 + .maxlen = sizeof(int),
59235 + .mode = 0600,
59236 + .proc_handler = &proc_dointvec,
59237 + },
59238 +#endif
59239 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59240 + {
59241 + .procname = "ptrace_readexec",
59242 + .data = &grsec_enable_ptrace_readexec,
59243 + .maxlen = sizeof(int),
59244 + .mode = 0600,
59245 + .proc_handler = &proc_dointvec,
59246 + },
59247 +#endif
59248 +#ifdef CONFIG_GRKERNSEC_SETXID
59249 + {
59250 + .procname = "consistent_setxid",
59251 + .data = &grsec_enable_setxid,
59252 + .maxlen = sizeof(int),
59253 + .mode = 0600,
59254 + .proc_handler = &proc_dointvec,
59255 + },
59256 +#endif
59257 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59258 + {
59259 + .procname = "ip_blackhole",
59260 + .data = &grsec_enable_blackhole,
59261 + .maxlen = sizeof(int),
59262 + .mode = 0600,
59263 + .proc_handler = &proc_dointvec,
59264 + },
59265 + {
59266 + .procname = "lastack_retries",
59267 + .data = &grsec_lastack_retries,
59268 + .maxlen = sizeof(int),
59269 + .mode = 0600,
59270 + .proc_handler = &proc_dointvec,
59271 + },
59272 +#endif
59273 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59274 + {
59275 + .procname = "exec_logging",
59276 + .data = &grsec_enable_execlog,
59277 + .maxlen = sizeof(int),
59278 + .mode = 0600,
59279 + .proc_handler = &proc_dointvec,
59280 + },
59281 +#endif
59282 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59283 + {
59284 + .procname = "rwxmap_logging",
59285 + .data = &grsec_enable_log_rwxmaps,
59286 + .maxlen = sizeof(int),
59287 + .mode = 0600,
59288 + .proc_handler = &proc_dointvec,
59289 + },
59290 +#endif
59291 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59292 + {
59293 + .procname = "signal_logging",
59294 + .data = &grsec_enable_signal,
59295 + .maxlen = sizeof(int),
59296 + .mode = 0600,
59297 + .proc_handler = &proc_dointvec,
59298 + },
59299 +#endif
59300 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59301 + {
59302 + .procname = "forkfail_logging",
59303 + .data = &grsec_enable_forkfail,
59304 + .maxlen = sizeof(int),
59305 + .mode = 0600,
59306 + .proc_handler = &proc_dointvec,
59307 + },
59308 +#endif
59309 +#ifdef CONFIG_GRKERNSEC_TIME
59310 + {
59311 + .procname = "timechange_logging",
59312 + .data = &grsec_enable_time,
59313 + .maxlen = sizeof(int),
59314 + .mode = 0600,
59315 + .proc_handler = &proc_dointvec,
59316 + },
59317 +#endif
59318 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59319 + {
59320 + .procname = "chroot_deny_shmat",
59321 + .data = &grsec_enable_chroot_shmat,
59322 + .maxlen = sizeof(int),
59323 + .mode = 0600,
59324 + .proc_handler = &proc_dointvec,
59325 + },
59326 +#endif
59327 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59328 + {
59329 + .procname = "chroot_deny_unix",
59330 + .data = &grsec_enable_chroot_unix,
59331 + .maxlen = sizeof(int),
59332 + .mode = 0600,
59333 + .proc_handler = &proc_dointvec,
59334 + },
59335 +#endif
59336 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59337 + {
59338 + .procname = "chroot_deny_mount",
59339 + .data = &grsec_enable_chroot_mount,
59340 + .maxlen = sizeof(int),
59341 + .mode = 0600,
59342 + .proc_handler = &proc_dointvec,
59343 + },
59344 +#endif
59345 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59346 + {
59347 + .procname = "chroot_deny_fchdir",
59348 + .data = &grsec_enable_chroot_fchdir,
59349 + .maxlen = sizeof(int),
59350 + .mode = 0600,
59351 + .proc_handler = &proc_dointvec,
59352 + },
59353 +#endif
59354 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59355 + {
59356 + .procname = "chroot_deny_chroot",
59357 + .data = &grsec_enable_chroot_double,
59358 + .maxlen = sizeof(int),
59359 + .mode = 0600,
59360 + .proc_handler = &proc_dointvec,
59361 + },
59362 +#endif
59363 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59364 + {
59365 + .procname = "chroot_deny_pivot",
59366 + .data = &grsec_enable_chroot_pivot,
59367 + .maxlen = sizeof(int),
59368 + .mode = 0600,
59369 + .proc_handler = &proc_dointvec,
59370 + },
59371 +#endif
59372 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59373 + {
59374 + .procname = "chroot_enforce_chdir",
59375 + .data = &grsec_enable_chroot_chdir,
59376 + .maxlen = sizeof(int),
59377 + .mode = 0600,
59378 + .proc_handler = &proc_dointvec,
59379 + },
59380 +#endif
59381 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59382 + {
59383 + .procname = "chroot_deny_chmod",
59384 + .data = &grsec_enable_chroot_chmod,
59385 + .maxlen = sizeof(int),
59386 + .mode = 0600,
59387 + .proc_handler = &proc_dointvec,
59388 + },
59389 +#endif
59390 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59391 + {
59392 + .procname = "chroot_deny_mknod",
59393 + .data = &grsec_enable_chroot_mknod,
59394 + .maxlen = sizeof(int),
59395 + .mode = 0600,
59396 + .proc_handler = &proc_dointvec,
59397 + },
59398 +#endif
59399 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59400 + {
59401 + .procname = "chroot_restrict_nice",
59402 + .data = &grsec_enable_chroot_nice,
59403 + .maxlen = sizeof(int),
59404 + .mode = 0600,
59405 + .proc_handler = &proc_dointvec,
59406 + },
59407 +#endif
59408 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59409 + {
59410 + .procname = "chroot_execlog",
59411 + .data = &grsec_enable_chroot_execlog,
59412 + .maxlen = sizeof(int),
59413 + .mode = 0600,
59414 + .proc_handler = &proc_dointvec,
59415 + },
59416 +#endif
59417 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59418 + {
59419 + .procname = "chroot_caps",
59420 + .data = &grsec_enable_chroot_caps,
59421 + .maxlen = sizeof(int),
59422 + .mode = 0600,
59423 + .proc_handler = &proc_dointvec,
59424 + },
59425 +#endif
59426 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59427 + {
59428 + .procname = "chroot_deny_sysctl",
59429 + .data = &grsec_enable_chroot_sysctl,
59430 + .maxlen = sizeof(int),
59431 + .mode = 0600,
59432 + .proc_handler = &proc_dointvec,
59433 + },
59434 +#endif
59435 +#ifdef CONFIG_GRKERNSEC_TPE
59436 + {
59437 + .procname = "tpe",
59438 + .data = &grsec_enable_tpe,
59439 + .maxlen = sizeof(int),
59440 + .mode = 0600,
59441 + .proc_handler = &proc_dointvec,
59442 + },
59443 + {
59444 + .procname = "tpe_gid",
59445 + .data = &grsec_tpe_gid,
59446 + .maxlen = sizeof(int),
59447 + .mode = 0600,
59448 + .proc_handler = &proc_dointvec,
59449 + },
59450 +#endif
59451 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59452 + {
59453 + .procname = "tpe_invert",
59454 + .data = &grsec_enable_tpe_invert,
59455 + .maxlen = sizeof(int),
59456 + .mode = 0600,
59457 + .proc_handler = &proc_dointvec,
59458 + },
59459 +#endif
59460 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59461 + {
59462 + .procname = "tpe_restrict_all",
59463 + .data = &grsec_enable_tpe_all,
59464 + .maxlen = sizeof(int),
59465 + .mode = 0600,
59466 + .proc_handler = &proc_dointvec,
59467 + },
59468 +#endif
59469 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59470 + {
59471 + .procname = "socket_all",
59472 + .data = &grsec_enable_socket_all,
59473 + .maxlen = sizeof(int),
59474 + .mode = 0600,
59475 + .proc_handler = &proc_dointvec,
59476 + },
59477 + {
59478 + .procname = "socket_all_gid",
59479 + .data = &grsec_socket_all_gid,
59480 + .maxlen = sizeof(int),
59481 + .mode = 0600,
59482 + .proc_handler = &proc_dointvec,
59483 + },
59484 +#endif
59485 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59486 + {
59487 + .procname = "socket_client",
59488 + .data = &grsec_enable_socket_client,
59489 + .maxlen = sizeof(int),
59490 + .mode = 0600,
59491 + .proc_handler = &proc_dointvec,
59492 + },
59493 + {
59494 + .procname = "socket_client_gid",
59495 + .data = &grsec_socket_client_gid,
59496 + .maxlen = sizeof(int),
59497 + .mode = 0600,
59498 + .proc_handler = &proc_dointvec,
59499 + },
59500 +#endif
59501 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59502 + {
59503 + .procname = "socket_server",
59504 + .data = &grsec_enable_socket_server,
59505 + .maxlen = sizeof(int),
59506 + .mode = 0600,
59507 + .proc_handler = &proc_dointvec,
59508 + },
59509 + {
59510 + .procname = "socket_server_gid",
59511 + .data = &grsec_socket_server_gid,
59512 + .maxlen = sizeof(int),
59513 + .mode = 0600,
59514 + .proc_handler = &proc_dointvec,
59515 + },
59516 +#endif
59517 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59518 + {
59519 + .procname = "audit_group",
59520 + .data = &grsec_enable_group,
59521 + .maxlen = sizeof(int),
59522 + .mode = 0600,
59523 + .proc_handler = &proc_dointvec,
59524 + },
59525 + {
59526 + .procname = "audit_gid",
59527 + .data = &grsec_audit_gid,
59528 + .maxlen = sizeof(int),
59529 + .mode = 0600,
59530 + .proc_handler = &proc_dointvec,
59531 + },
59532 +#endif
59533 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59534 + {
59535 + .procname = "audit_chdir",
59536 + .data = &grsec_enable_chdir,
59537 + .maxlen = sizeof(int),
59538 + .mode = 0600,
59539 + .proc_handler = &proc_dointvec,
59540 + },
59541 +#endif
59542 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59543 + {
59544 + .procname = "audit_mount",
59545 + .data = &grsec_enable_mount,
59546 + .maxlen = sizeof(int),
59547 + .mode = 0600,
59548 + .proc_handler = &proc_dointvec,
59549 + },
59550 +#endif
59551 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59552 + {
59553 + .procname = "audit_textrel",
59554 + .data = &grsec_enable_audit_textrel,
59555 + .maxlen = sizeof(int),
59556 + .mode = 0600,
59557 + .proc_handler = &proc_dointvec,
59558 + },
59559 +#endif
59560 +#ifdef CONFIG_GRKERNSEC_DMESG
59561 + {
59562 + .procname = "dmesg",
59563 + .data = &grsec_enable_dmesg,
59564 + .maxlen = sizeof(int),
59565 + .mode = 0600,
59566 + .proc_handler = &proc_dointvec,
59567 + },
59568 +#endif
59569 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59570 + {
59571 + .procname = "chroot_findtask",
59572 + .data = &grsec_enable_chroot_findtask,
59573 + .maxlen = sizeof(int),
59574 + .mode = 0600,
59575 + .proc_handler = &proc_dointvec,
59576 + },
59577 +#endif
59578 +#ifdef CONFIG_GRKERNSEC_RESLOG
59579 + {
59580 + .procname = "resource_logging",
59581 + .data = &grsec_resource_logging,
59582 + .maxlen = sizeof(int),
59583 + .mode = 0600,
59584 + .proc_handler = &proc_dointvec,
59585 + },
59586 +#endif
59587 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59588 + {
59589 + .procname = "audit_ptrace",
59590 + .data = &grsec_enable_audit_ptrace,
59591 + .maxlen = sizeof(int),
59592 + .mode = 0600,
59593 + .proc_handler = &proc_dointvec,
59594 + },
59595 +#endif
59596 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59597 + {
59598 + .procname = "harden_ptrace",
59599 + .data = &grsec_enable_harden_ptrace,
59600 + .maxlen = sizeof(int),
59601 + .mode = 0600,
59602 + .proc_handler = &proc_dointvec,
59603 + },
59604 +#endif
59605 + {
59606 + .procname = "grsec_lock",
59607 + .data = &grsec_lock,
59608 + .maxlen = sizeof(int),
59609 + .mode = 0600,
59610 + .proc_handler = &proc_dointvec,
59611 + },
59612 +#endif
59613 +#ifdef CONFIG_GRKERNSEC_ROFS
59614 + {
59615 + .procname = "romount_protect",
59616 + .data = &grsec_enable_rofs,
59617 + .maxlen = sizeof(int),
59618 + .mode = 0600,
59619 + .proc_handler = &proc_dointvec_minmax,
59620 + .extra1 = &one,
59621 + .extra2 = &one,
59622 + },
59623 +#endif
59624 + { }
59625 +};
59626 +#endif
59627 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59628 new file mode 100644
59629 index 0000000..0dc13c3
59630 --- /dev/null
59631 +++ b/grsecurity/grsec_time.c
59632 @@ -0,0 +1,16 @@
59633 +#include <linux/kernel.h>
59634 +#include <linux/sched.h>
59635 +#include <linux/grinternal.h>
59636 +#include <linux/module.h>
59637 +
59638 +void
59639 +gr_log_timechange(void)
59640 +{
59641 +#ifdef CONFIG_GRKERNSEC_TIME
59642 + if (grsec_enable_time)
59643 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59644 +#endif
59645 + return;
59646 +}
59647 +
59648 +EXPORT_SYMBOL(gr_log_timechange);
59649 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59650 new file mode 100644
59651 index 0000000..07e0dc0
59652 --- /dev/null
59653 +++ b/grsecurity/grsec_tpe.c
59654 @@ -0,0 +1,73 @@
59655 +#include <linux/kernel.h>
59656 +#include <linux/sched.h>
59657 +#include <linux/file.h>
59658 +#include <linux/fs.h>
59659 +#include <linux/grinternal.h>
59660 +
59661 +extern int gr_acl_tpe_check(void);
59662 +
59663 +int
59664 +gr_tpe_allow(const struct file *file)
59665 +{
59666 +#ifdef CONFIG_GRKERNSEC
59667 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59668 + const struct cred *cred = current_cred();
59669 + char *msg = NULL;
59670 + char *msg2 = NULL;
59671 +
59672 + // never restrict root
59673 + if (!cred->uid)
59674 + return 1;
59675 +
59676 + if (grsec_enable_tpe) {
59677 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59678 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59679 + msg = "not being in trusted group";
59680 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59681 + msg = "being in untrusted group";
59682 +#else
59683 + if (in_group_p(grsec_tpe_gid))
59684 + msg = "being in untrusted group";
59685 +#endif
59686 + }
59687 + if (!msg && gr_acl_tpe_check())
59688 + msg = "being in untrusted role";
59689 +
59690 + // not in any affected group/role
59691 + if (!msg)
59692 + goto next_check;
59693 +
59694 + if (inode->i_uid)
59695 + msg2 = "file in non-root-owned directory";
59696 + else if (inode->i_mode & S_IWOTH)
59697 + msg2 = "file in world-writable directory";
59698 + else if (inode->i_mode & S_IWGRP)
59699 + msg2 = "file in group-writable directory";
59700 +
59701 + if (msg && msg2) {
59702 + char fullmsg[70] = {0};
59703 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59704 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59705 + return 0;
59706 + }
59707 + msg = NULL;
59708 +next_check:
59709 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59710 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59711 + return 1;
59712 +
59713 + if (inode->i_uid && (inode->i_uid != cred->uid))
59714 + msg = "directory not owned by user";
59715 + else if (inode->i_mode & S_IWOTH)
59716 + msg = "file in world-writable directory";
59717 + else if (inode->i_mode & S_IWGRP)
59718 + msg = "file in group-writable directory";
59719 +
59720 + if (msg) {
59721 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59722 + return 0;
59723 + }
59724 +#endif
59725 +#endif
59726 + return 1;
59727 +}
59728 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59729 new file mode 100644
59730 index 0000000..9f7b1ac
59731 --- /dev/null
59732 +++ b/grsecurity/grsum.c
59733 @@ -0,0 +1,61 @@
59734 +#include <linux/err.h>
59735 +#include <linux/kernel.h>
59736 +#include <linux/sched.h>
59737 +#include <linux/mm.h>
59738 +#include <linux/scatterlist.h>
59739 +#include <linux/crypto.h>
59740 +#include <linux/gracl.h>
59741 +
59742 +
59743 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59744 +#error "crypto and sha256 must be built into the kernel"
59745 +#endif
59746 +
59747 +int
59748 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59749 +{
59750 + char *p;
59751 + struct crypto_hash *tfm;
59752 + struct hash_desc desc;
59753 + struct scatterlist sg;
59754 + unsigned char temp_sum[GR_SHA_LEN];
59755 + volatile int retval = 0;
59756 + volatile int dummy = 0;
59757 + unsigned int i;
59758 +
59759 + sg_init_table(&sg, 1);
59760 +
59761 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59762 + if (IS_ERR(tfm)) {
59763 + /* should never happen, since sha256 should be built in */
59764 + return 1;
59765 + }
59766 +
59767 + desc.tfm = tfm;
59768 + desc.flags = 0;
59769 +
59770 + crypto_hash_init(&desc);
59771 +
59772 + p = salt;
59773 + sg_set_buf(&sg, p, GR_SALT_LEN);
59774 + crypto_hash_update(&desc, &sg, sg.length);
59775 +
59776 + p = entry->pw;
59777 + sg_set_buf(&sg, p, strlen(p));
59778 +
59779 + crypto_hash_update(&desc, &sg, sg.length);
59780 +
59781 + crypto_hash_final(&desc, temp_sum);
59782 +
59783 + memset(entry->pw, 0, GR_PW_LEN);
59784 +
59785 + for (i = 0; i < GR_SHA_LEN; i++)
59786 + if (sum[i] != temp_sum[i])
59787 + retval = 1;
59788 + else
59789 + dummy = 1; // waste a cycle
59790 +
59791 + crypto_free_hash(tfm);
59792 +
59793 + return retval;
59794 +}
59795 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59796 index 9e6e1c6..d47b906 100644
59797 --- a/include/acpi/acpi_bus.h
59798 +++ b/include/acpi/acpi_bus.h
59799 @@ -138,7 +138,7 @@ struct acpi_device_ops {
59800 acpi_op_bind bind;
59801 acpi_op_unbind unbind;
59802 acpi_op_notify notify;
59803 -};
59804 +} __no_const;
59805
59806 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59807
59808 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59809 index b7babf0..3ba8aee 100644
59810 --- a/include/asm-generic/atomic-long.h
59811 +++ b/include/asm-generic/atomic-long.h
59812 @@ -22,6 +22,12 @@
59813
59814 typedef atomic64_t atomic_long_t;
59815
59816 +#ifdef CONFIG_PAX_REFCOUNT
59817 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
59818 +#else
59819 +typedef atomic64_t atomic_long_unchecked_t;
59820 +#endif
59821 +
59822 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59823
59824 static inline long atomic_long_read(atomic_long_t *l)
59825 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59826 return (long)atomic64_read(v);
59827 }
59828
59829 +#ifdef CONFIG_PAX_REFCOUNT
59830 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59831 +{
59832 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59833 +
59834 + return (long)atomic64_read_unchecked(v);
59835 +}
59836 +#endif
59837 +
59838 static inline void atomic_long_set(atomic_long_t *l, long i)
59839 {
59840 atomic64_t *v = (atomic64_t *)l;
59841 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59842 atomic64_set(v, i);
59843 }
59844
59845 +#ifdef CONFIG_PAX_REFCOUNT
59846 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59847 +{
59848 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59849 +
59850 + atomic64_set_unchecked(v, i);
59851 +}
59852 +#endif
59853 +
59854 static inline void atomic_long_inc(atomic_long_t *l)
59855 {
59856 atomic64_t *v = (atomic64_t *)l;
59857 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59858 atomic64_inc(v);
59859 }
59860
59861 +#ifdef CONFIG_PAX_REFCOUNT
59862 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59863 +{
59864 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59865 +
59866 + atomic64_inc_unchecked(v);
59867 +}
59868 +#endif
59869 +
59870 static inline void atomic_long_dec(atomic_long_t *l)
59871 {
59872 atomic64_t *v = (atomic64_t *)l;
59873 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59874 atomic64_dec(v);
59875 }
59876
59877 +#ifdef CONFIG_PAX_REFCOUNT
59878 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59879 +{
59880 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59881 +
59882 + atomic64_dec_unchecked(v);
59883 +}
59884 +#endif
59885 +
59886 static inline void atomic_long_add(long i, atomic_long_t *l)
59887 {
59888 atomic64_t *v = (atomic64_t *)l;
59889 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59890 atomic64_add(i, v);
59891 }
59892
59893 +#ifdef CONFIG_PAX_REFCOUNT
59894 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59895 +{
59896 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59897 +
59898 + atomic64_add_unchecked(i, v);
59899 +}
59900 +#endif
59901 +
59902 static inline void atomic_long_sub(long i, atomic_long_t *l)
59903 {
59904 atomic64_t *v = (atomic64_t *)l;
59905 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59906 atomic64_sub(i, v);
59907 }
59908
59909 +#ifdef CONFIG_PAX_REFCOUNT
59910 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59911 +{
59912 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59913 +
59914 + atomic64_sub_unchecked(i, v);
59915 +}
59916 +#endif
59917 +
59918 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59919 {
59920 atomic64_t *v = (atomic64_t *)l;
59921 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59922 return (long)atomic64_inc_return(v);
59923 }
59924
59925 +#ifdef CONFIG_PAX_REFCOUNT
59926 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59927 +{
59928 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59929 +
59930 + return (long)atomic64_inc_return_unchecked(v);
59931 +}
59932 +#endif
59933 +
59934 static inline long atomic_long_dec_return(atomic_long_t *l)
59935 {
59936 atomic64_t *v = (atomic64_t *)l;
59937 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59938
59939 typedef atomic_t atomic_long_t;
59940
59941 +#ifdef CONFIG_PAX_REFCOUNT
59942 +typedef atomic_unchecked_t atomic_long_unchecked_t;
59943 +#else
59944 +typedef atomic_t atomic_long_unchecked_t;
59945 +#endif
59946 +
59947 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59948 static inline long atomic_long_read(atomic_long_t *l)
59949 {
59950 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59951 return (long)atomic_read(v);
59952 }
59953
59954 +#ifdef CONFIG_PAX_REFCOUNT
59955 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59956 +{
59957 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59958 +
59959 + return (long)atomic_read_unchecked(v);
59960 +}
59961 +#endif
59962 +
59963 static inline void atomic_long_set(atomic_long_t *l, long i)
59964 {
59965 atomic_t *v = (atomic_t *)l;
59966 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59967 atomic_set(v, i);
59968 }
59969
59970 +#ifdef CONFIG_PAX_REFCOUNT
59971 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59972 +{
59973 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59974 +
59975 + atomic_set_unchecked(v, i);
59976 +}
59977 +#endif
59978 +
59979 static inline void atomic_long_inc(atomic_long_t *l)
59980 {
59981 atomic_t *v = (atomic_t *)l;
59982 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59983 atomic_inc(v);
59984 }
59985
59986 +#ifdef CONFIG_PAX_REFCOUNT
59987 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59988 +{
59989 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59990 +
59991 + atomic_inc_unchecked(v);
59992 +}
59993 +#endif
59994 +
59995 static inline void atomic_long_dec(atomic_long_t *l)
59996 {
59997 atomic_t *v = (atomic_t *)l;
59998 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59999 atomic_dec(v);
60000 }
60001
60002 +#ifdef CONFIG_PAX_REFCOUNT
60003 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60004 +{
60005 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60006 +
60007 + atomic_dec_unchecked(v);
60008 +}
60009 +#endif
60010 +
60011 static inline void atomic_long_add(long i, atomic_long_t *l)
60012 {
60013 atomic_t *v = (atomic_t *)l;
60014 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60015 atomic_add(i, v);
60016 }
60017
60018 +#ifdef CONFIG_PAX_REFCOUNT
60019 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60020 +{
60021 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60022 +
60023 + atomic_add_unchecked(i, v);
60024 +}
60025 +#endif
60026 +
60027 static inline void atomic_long_sub(long i, atomic_long_t *l)
60028 {
60029 atomic_t *v = (atomic_t *)l;
60030 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60031 atomic_sub(i, v);
60032 }
60033
60034 +#ifdef CONFIG_PAX_REFCOUNT
60035 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60036 +{
60037 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60038 +
60039 + atomic_sub_unchecked(i, v);
60040 +}
60041 +#endif
60042 +
60043 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60044 {
60045 atomic_t *v = (atomic_t *)l;
60046 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60047 return (long)atomic_inc_return(v);
60048 }
60049
60050 +#ifdef CONFIG_PAX_REFCOUNT
60051 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60052 +{
60053 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60054 +
60055 + return (long)atomic_inc_return_unchecked(v);
60056 +}
60057 +#endif
60058 +
60059 static inline long atomic_long_dec_return(atomic_long_t *l)
60060 {
60061 atomic_t *v = (atomic_t *)l;
60062 @@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60063
60064 #endif /* BITS_PER_LONG == 64 */
60065
60066 +#ifdef CONFIG_PAX_REFCOUNT
60067 +static inline void pax_refcount_needs_these_functions(void)
60068 +{
60069 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60070 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60071 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60072 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60073 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60074 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60075 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60076 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60077 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60078 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60079 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60080 +#ifdef CONFIG_X86
60081 + atomic_clear_mask_unchecked(0, NULL);
60082 + atomic_set_mask_unchecked(0, NULL);
60083 +#endif
60084 +
60085 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60086 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60087 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60088 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60089 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60090 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60091 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60092 +}
60093 +#else
60094 +#define atomic_read_unchecked(v) atomic_read(v)
60095 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60096 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60097 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60098 +#define atomic_inc_unchecked(v) atomic_inc(v)
60099 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60100 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60101 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60102 +#define atomic_dec_unchecked(v) atomic_dec(v)
60103 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60104 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60105 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60106 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60107 +
60108 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60109 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60110 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60111 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60112 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60113 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60114 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60115 +#endif
60116 +
60117 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60118 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60119 index 1ced641..c896ee8 100644
60120 --- a/include/asm-generic/atomic.h
60121 +++ b/include/asm-generic/atomic.h
60122 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60123 * Atomically clears the bits set in @mask from @v
60124 */
60125 #ifndef atomic_clear_mask
60126 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60127 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60128 {
60129 unsigned long flags;
60130
60131 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60132 index b18ce4f..2ee2843 100644
60133 --- a/include/asm-generic/atomic64.h
60134 +++ b/include/asm-generic/atomic64.h
60135 @@ -16,6 +16,8 @@ typedef struct {
60136 long long counter;
60137 } atomic64_t;
60138
60139 +typedef atomic64_t atomic64_unchecked_t;
60140 +
60141 #define ATOMIC64_INIT(i) { (i) }
60142
60143 extern long long atomic64_read(const atomic64_t *v);
60144 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60145 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60146 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60147
60148 +#define atomic64_read_unchecked(v) atomic64_read(v)
60149 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60150 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60151 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60152 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60153 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60154 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60155 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60156 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60157 +
60158 #endif /* _ASM_GENERIC_ATOMIC64_H */
60159 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60160 index 1bfcfe5..e04c5c9 100644
60161 --- a/include/asm-generic/cache.h
60162 +++ b/include/asm-generic/cache.h
60163 @@ -6,7 +6,7 @@
60164 * cache lines need to provide their own cache.h.
60165 */
60166
60167 -#define L1_CACHE_SHIFT 5
60168 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60169 +#define L1_CACHE_SHIFT 5UL
60170 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60171
60172 #endif /* __ASM_GENERIC_CACHE_H */
60173 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60174 index 0d68a1e..b74a761 100644
60175 --- a/include/asm-generic/emergency-restart.h
60176 +++ b/include/asm-generic/emergency-restart.h
60177 @@ -1,7 +1,7 @@
60178 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60179 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60180
60181 -static inline void machine_emergency_restart(void)
60182 +static inline __noreturn void machine_emergency_restart(void)
60183 {
60184 machine_restart(NULL);
60185 }
60186 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60187 index 0232ccb..13d9165 100644
60188 --- a/include/asm-generic/kmap_types.h
60189 +++ b/include/asm-generic/kmap_types.h
60190 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
60191 KMAP_D(17) KM_NMI,
60192 KMAP_D(18) KM_NMI_PTE,
60193 KMAP_D(19) KM_KDB,
60194 +KMAP_D(20) KM_CLEARPAGE,
60195 /*
60196 * Remember to update debug_kmap_atomic() when adding new kmap types!
60197 */
60198 -KMAP_D(20) KM_TYPE_NR
60199 +KMAP_D(21) KM_TYPE_NR
60200 };
60201
60202 #undef KMAP_D
60203 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60204 index 9ceb03b..2efbcbd 100644
60205 --- a/include/asm-generic/local.h
60206 +++ b/include/asm-generic/local.h
60207 @@ -39,6 +39,7 @@ typedef struct
60208 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60209 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60210 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60211 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60212
60213 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60214 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60215 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60216 index 725612b..9cc513a 100644
60217 --- a/include/asm-generic/pgtable-nopmd.h
60218 +++ b/include/asm-generic/pgtable-nopmd.h
60219 @@ -1,14 +1,19 @@
60220 #ifndef _PGTABLE_NOPMD_H
60221 #define _PGTABLE_NOPMD_H
60222
60223 -#ifndef __ASSEMBLY__
60224 -
60225 #include <asm-generic/pgtable-nopud.h>
60226
60227 -struct mm_struct;
60228 -
60229 #define __PAGETABLE_PMD_FOLDED
60230
60231 +#define PMD_SHIFT PUD_SHIFT
60232 +#define PTRS_PER_PMD 1
60233 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60234 +#define PMD_MASK (~(PMD_SIZE-1))
60235 +
60236 +#ifndef __ASSEMBLY__
60237 +
60238 +struct mm_struct;
60239 +
60240 /*
60241 * Having the pmd type consist of a pud gets the size right, and allows
60242 * us to conceptually access the pud entry that this pmd is folded into
60243 @@ -16,11 +21,6 @@ struct mm_struct;
60244 */
60245 typedef struct { pud_t pud; } pmd_t;
60246
60247 -#define PMD_SHIFT PUD_SHIFT
60248 -#define PTRS_PER_PMD 1
60249 -#define PMD_SIZE (1UL << PMD_SHIFT)
60250 -#define PMD_MASK (~(PMD_SIZE-1))
60251 -
60252 /*
60253 * The "pud_xxx()" functions here are trivial for a folded two-level
60254 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60255 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60256 index 810431d..0ec4804f 100644
60257 --- a/include/asm-generic/pgtable-nopud.h
60258 +++ b/include/asm-generic/pgtable-nopud.h
60259 @@ -1,10 +1,15 @@
60260 #ifndef _PGTABLE_NOPUD_H
60261 #define _PGTABLE_NOPUD_H
60262
60263 -#ifndef __ASSEMBLY__
60264 -
60265 #define __PAGETABLE_PUD_FOLDED
60266
60267 +#define PUD_SHIFT PGDIR_SHIFT
60268 +#define PTRS_PER_PUD 1
60269 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60270 +#define PUD_MASK (~(PUD_SIZE-1))
60271 +
60272 +#ifndef __ASSEMBLY__
60273 +
60274 /*
60275 * Having the pud type consist of a pgd gets the size right, and allows
60276 * us to conceptually access the pgd entry that this pud is folded into
60277 @@ -12,11 +17,6 @@
60278 */
60279 typedef struct { pgd_t pgd; } pud_t;
60280
60281 -#define PUD_SHIFT PGDIR_SHIFT
60282 -#define PTRS_PER_PUD 1
60283 -#define PUD_SIZE (1UL << PUD_SHIFT)
60284 -#define PUD_MASK (~(PUD_SIZE-1))
60285 -
60286 /*
60287 * The "pgd_xxx()" functions here are trivial for a folded two-level
60288 * setup: the pud is never bad, and a pud always exists (as it's folded
60289 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60290 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60291
60292 #define pgd_populate(mm, pgd, pud) do { } while (0)
60293 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60294 /*
60295 * (puds are folded into pgds so this doesn't get actually called,
60296 * but the define is needed for a generic inline function.)
60297 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60298 index ff4947b..f48183f 100644
60299 --- a/include/asm-generic/pgtable.h
60300 +++ b/include/asm-generic/pgtable.h
60301 @@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60302 #endif
60303 }
60304
60305 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60306 +static inline unsigned long pax_open_kernel(void) { return 0; }
60307 +#endif
60308 +
60309 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60310 +static inline unsigned long pax_close_kernel(void) { return 0; }
60311 +#endif
60312 +
60313 #endif /* CONFIG_MMU */
60314
60315 #endif /* !__ASSEMBLY__ */
60316 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60317 index 4e2e1cc..12c266b 100644
60318 --- a/include/asm-generic/vmlinux.lds.h
60319 +++ b/include/asm-generic/vmlinux.lds.h
60320 @@ -218,6 +218,7 @@
60321 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60322 VMLINUX_SYMBOL(__start_rodata) = .; \
60323 *(.rodata) *(.rodata.*) \
60324 + *(.data..read_only) \
60325 *(__vermagic) /* Kernel version magic */ \
60326 . = ALIGN(8); \
60327 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60328 @@ -716,17 +717,18 @@
60329 * section in the linker script will go there too. @phdr should have
60330 * a leading colon.
60331 *
60332 - * Note that this macros defines __per_cpu_load as an absolute symbol.
60333 + * Note that this macros defines per_cpu_load as an absolute symbol.
60334 * If there is no need to put the percpu section at a predetermined
60335 * address, use PERCPU_SECTION.
60336 */
60337 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60338 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
60339 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60340 + per_cpu_load = .; \
60341 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60342 - LOAD_OFFSET) { \
60343 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60344 PERCPU_INPUT(cacheline) \
60345 } phdr \
60346 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60347 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60348
60349 /**
60350 * PERCPU_SECTION - define output section for percpu area, simple version
60351 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60352 index 31ad880..4e79884 100644
60353 --- a/include/drm/drmP.h
60354 +++ b/include/drm/drmP.h
60355 @@ -72,6 +72,7 @@
60356 #include <linux/workqueue.h>
60357 #include <linux/poll.h>
60358 #include <asm/pgalloc.h>
60359 +#include <asm/local.h>
60360 #include "drm.h"
60361
60362 #include <linux/idr.h>
60363 @@ -1074,7 +1075,7 @@ struct drm_device {
60364
60365 /** \name Usage Counters */
60366 /*@{ */
60367 - int open_count; /**< Outstanding files open */
60368 + local_t open_count; /**< Outstanding files open */
60369 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60370 atomic_t vma_count; /**< Outstanding vma areas open */
60371 int buf_use; /**< Buffers in use -- cannot alloc */
60372 @@ -1085,7 +1086,7 @@ struct drm_device {
60373 /*@{ */
60374 unsigned long counters;
60375 enum drm_stat_type types[15];
60376 - atomic_t counts[15];
60377 + atomic_unchecked_t counts[15];
60378 /*@} */
60379
60380 struct list_head filelist;
60381 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60382 index 7988e55..ec974c9 100644
60383 --- a/include/drm/drm_crtc_helper.h
60384 +++ b/include/drm/drm_crtc_helper.h
60385 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
60386
60387 /* disable crtc when not in use - more explicit than dpms off */
60388 void (*disable)(struct drm_crtc *crtc);
60389 -};
60390 +} __no_const;
60391
60392 /**
60393 * drm_encoder_helper_funcs - helper operations for encoders
60394 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
60395 struct drm_connector *connector);
60396 /* disable encoder when not in use - more explicit than dpms off */
60397 void (*disable)(struct drm_encoder *encoder);
60398 -};
60399 +} __no_const;
60400
60401 /**
60402 * drm_connector_helper_funcs - helper operations for connectors
60403 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60404 index d6d1da4..fdd1ac5 100644
60405 --- a/include/drm/ttm/ttm_memory.h
60406 +++ b/include/drm/ttm/ttm_memory.h
60407 @@ -48,7 +48,7 @@
60408
60409 struct ttm_mem_shrink {
60410 int (*do_shrink) (struct ttm_mem_shrink *);
60411 -};
60412 +} __no_const;
60413
60414 /**
60415 * struct ttm_mem_global - Global memory accounting structure.
60416 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60417 index e86dfca..40cc55f 100644
60418 --- a/include/linux/a.out.h
60419 +++ b/include/linux/a.out.h
60420 @@ -39,6 +39,14 @@ enum machine_type {
60421 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60422 };
60423
60424 +/* Constants for the N_FLAGS field */
60425 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60426 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60427 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60428 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60429 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60430 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60431 +
60432 #if !defined (N_MAGIC)
60433 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60434 #endif
60435 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60436 index 06fd4bb..1caec0d 100644
60437 --- a/include/linux/atmdev.h
60438 +++ b/include/linux/atmdev.h
60439 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60440 #endif
60441
60442 struct k_atm_aal_stats {
60443 -#define __HANDLE_ITEM(i) atomic_t i
60444 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
60445 __AAL_STAT_ITEMS
60446 #undef __HANDLE_ITEM
60447 };
60448 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60449 index 366422b..1fa7f84 100644
60450 --- a/include/linux/binfmts.h
60451 +++ b/include/linux/binfmts.h
60452 @@ -89,6 +89,7 @@ struct linux_binfmt {
60453 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60454 int (*load_shlib)(struct file *);
60455 int (*core_dump)(struct coredump_params *cprm);
60456 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60457 unsigned long min_coredump; /* minimal dump size */
60458 };
60459
60460 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60461 index 07954b0..cb2ae71 100644
60462 --- a/include/linux/blkdev.h
60463 +++ b/include/linux/blkdev.h
60464 @@ -1393,7 +1393,7 @@ struct block_device_operations {
60465 /* this callback is with swap_lock and sometimes page table lock held */
60466 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60467 struct module *owner;
60468 -};
60469 +} __do_const;
60470
60471 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60472 unsigned long);
60473 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60474 index 4d1a074..88f929a 100644
60475 --- a/include/linux/blktrace_api.h
60476 +++ b/include/linux/blktrace_api.h
60477 @@ -162,7 +162,7 @@ struct blk_trace {
60478 struct dentry *dir;
60479 struct dentry *dropped_file;
60480 struct dentry *msg_file;
60481 - atomic_t dropped;
60482 + atomic_unchecked_t dropped;
60483 };
60484
60485 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60486 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60487 index 83195fb..0b0f77d 100644
60488 --- a/include/linux/byteorder/little_endian.h
60489 +++ b/include/linux/byteorder/little_endian.h
60490 @@ -42,51 +42,51 @@
60491
60492 static inline __le64 __cpu_to_le64p(const __u64 *p)
60493 {
60494 - return (__force __le64)*p;
60495 + return (__force const __le64)*p;
60496 }
60497 static inline __u64 __le64_to_cpup(const __le64 *p)
60498 {
60499 - return (__force __u64)*p;
60500 + return (__force const __u64)*p;
60501 }
60502 static inline __le32 __cpu_to_le32p(const __u32 *p)
60503 {
60504 - return (__force __le32)*p;
60505 + return (__force const __le32)*p;
60506 }
60507 static inline __u32 __le32_to_cpup(const __le32 *p)
60508 {
60509 - return (__force __u32)*p;
60510 + return (__force const __u32)*p;
60511 }
60512 static inline __le16 __cpu_to_le16p(const __u16 *p)
60513 {
60514 - return (__force __le16)*p;
60515 + return (__force const __le16)*p;
60516 }
60517 static inline __u16 __le16_to_cpup(const __le16 *p)
60518 {
60519 - return (__force __u16)*p;
60520 + return (__force const __u16)*p;
60521 }
60522 static inline __be64 __cpu_to_be64p(const __u64 *p)
60523 {
60524 - return (__force __be64)__swab64p(p);
60525 + return (__force const __be64)__swab64p(p);
60526 }
60527 static inline __u64 __be64_to_cpup(const __be64 *p)
60528 {
60529 - return __swab64p((__u64 *)p);
60530 + return __swab64p((const __u64 *)p);
60531 }
60532 static inline __be32 __cpu_to_be32p(const __u32 *p)
60533 {
60534 - return (__force __be32)__swab32p(p);
60535 + return (__force const __be32)__swab32p(p);
60536 }
60537 static inline __u32 __be32_to_cpup(const __be32 *p)
60538 {
60539 - return __swab32p((__u32 *)p);
60540 + return __swab32p((const __u32 *)p);
60541 }
60542 static inline __be16 __cpu_to_be16p(const __u16 *p)
60543 {
60544 - return (__force __be16)__swab16p(p);
60545 + return (__force const __be16)__swab16p(p);
60546 }
60547 static inline __u16 __be16_to_cpup(const __be16 *p)
60548 {
60549 - return __swab16p((__u16 *)p);
60550 + return __swab16p((const __u16 *)p);
60551 }
60552 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60553 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60554 diff --git a/include/linux/cache.h b/include/linux/cache.h
60555 index 4c57065..4307975 100644
60556 --- a/include/linux/cache.h
60557 +++ b/include/linux/cache.h
60558 @@ -16,6 +16,10 @@
60559 #define __read_mostly
60560 #endif
60561
60562 +#ifndef __read_only
60563 +#define __read_only __read_mostly
60564 +#endif
60565 +
60566 #ifndef ____cacheline_aligned
60567 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60568 #endif
60569 diff --git a/include/linux/capability.h b/include/linux/capability.h
60570 index d10b7ed..0288b79 100644
60571 --- a/include/linux/capability.h
60572 +++ b/include/linux/capability.h
60573 @@ -553,10 +553,15 @@ extern bool capable(int cap);
60574 extern bool ns_capable(struct user_namespace *ns, int cap);
60575 extern bool nsown_capable(int cap);
60576 extern bool inode_capable(const struct inode *inode, int cap);
60577 +extern bool capable_nolog(int cap);
60578 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60579 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
60580
60581 /* audit system wants to get cap info from files as well */
60582 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60583
60584 +extern int is_privileged_binary(const struct dentry *dentry);
60585 +
60586 #endif /* __KERNEL__ */
60587
60588 #endif /* !_LINUX_CAPABILITY_H */
60589 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60590 index 42e55de..1cd0e66 100644
60591 --- a/include/linux/cleancache.h
60592 +++ b/include/linux/cleancache.h
60593 @@ -31,7 +31,7 @@ struct cleancache_ops {
60594 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
60595 void (*invalidate_inode)(int, struct cleancache_filekey);
60596 void (*invalidate_fs)(int);
60597 -};
60598 +} __no_const;
60599
60600 extern struct cleancache_ops
60601 cleancache_register_ops(struct cleancache_ops *ops);
60602 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
60603 index 4a0b483..f1f70ba 100644
60604 --- a/include/linux/clk-provider.h
60605 +++ b/include/linux/clk-provider.h
60606 @@ -110,6 +110,7 @@ struct clk_ops {
60607 unsigned long);
60608 void (*init)(struct clk_hw *hw);
60609 };
60610 +typedef struct clk_ops __no_const clk_ops_no_const;
60611
60612 /**
60613 * struct clk_init_data - holds init data that's common to all clocks and is
60614 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60615 index 2f40791..9c9e13c 100644
60616 --- a/include/linux/compiler-gcc4.h
60617 +++ b/include/linux/compiler-gcc4.h
60618 @@ -32,6 +32,20 @@
60619 #define __linktime_error(message) __attribute__((__error__(message)))
60620
60621 #if __GNUC_MINOR__ >= 5
60622 +
60623 +#ifdef CONSTIFY_PLUGIN
60624 +#define __no_const __attribute__((no_const))
60625 +#define __do_const __attribute__((do_const))
60626 +#endif
60627 +
60628 +#ifdef SIZE_OVERFLOW_PLUGIN
60629 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60630 +#endif
60631 +
60632 +#ifdef LATENT_ENTROPY_PLUGIN
60633 +#define __latent_entropy __attribute__((latent_entropy))
60634 +#endif
60635 +
60636 /*
60637 * Mark a position in code as unreachable. This can be used to
60638 * suppress control flow warnings after asm blocks that transfer
60639 @@ -47,6 +61,11 @@
60640 #define __noclone __attribute__((__noclone__))
60641
60642 #endif
60643 +
60644 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60645 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60646 +#define __bos0(ptr) __bos((ptr), 0)
60647 +#define __bos1(ptr) __bos((ptr), 1)
60648 #endif
60649
60650 #if __GNUC_MINOR__ > 0
60651 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60652 index 923d093..1fef491 100644
60653 --- a/include/linux/compiler.h
60654 +++ b/include/linux/compiler.h
60655 @@ -5,31 +5,62 @@
60656
60657 #ifdef __CHECKER__
60658 # define __user __attribute__((noderef, address_space(1)))
60659 +# define __force_user __force __user
60660 # define __kernel __attribute__((address_space(0)))
60661 +# define __force_kernel __force __kernel
60662 # define __safe __attribute__((safe))
60663 # define __force __attribute__((force))
60664 # define __nocast __attribute__((nocast))
60665 # define __iomem __attribute__((noderef, address_space(2)))
60666 +# define __force_iomem __force __iomem
60667 # define __acquires(x) __attribute__((context(x,0,1)))
60668 # define __releases(x) __attribute__((context(x,1,0)))
60669 # define __acquire(x) __context__(x,1)
60670 # define __release(x) __context__(x,-1)
60671 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60672 # define __percpu __attribute__((noderef, address_space(3)))
60673 +# define __force_percpu __force __percpu
60674 #ifdef CONFIG_SPARSE_RCU_POINTER
60675 # define __rcu __attribute__((noderef, address_space(4)))
60676 +# define __force_rcu __force __rcu
60677 #else
60678 # define __rcu
60679 +# define __force_rcu
60680 #endif
60681 extern void __chk_user_ptr(const volatile void __user *);
60682 extern void __chk_io_ptr(const volatile void __iomem *);
60683 +#elif defined(CHECKER_PLUGIN)
60684 +//# define __user
60685 +//# define __force_user
60686 +//# define __kernel
60687 +//# define __force_kernel
60688 +# define __safe
60689 +# define __force
60690 +# define __nocast
60691 +# define __iomem
60692 +# define __force_iomem
60693 +# define __chk_user_ptr(x) (void)0
60694 +# define __chk_io_ptr(x) (void)0
60695 +# define __builtin_warning(x, y...) (1)
60696 +# define __acquires(x)
60697 +# define __releases(x)
60698 +# define __acquire(x) (void)0
60699 +# define __release(x) (void)0
60700 +# define __cond_lock(x,c) (c)
60701 +# define __percpu
60702 +# define __force_percpu
60703 +# define __rcu
60704 +# define __force_rcu
60705 #else
60706 # define __user
60707 +# define __force_user
60708 # define __kernel
60709 +# define __force_kernel
60710 # define __safe
60711 # define __force
60712 # define __nocast
60713 # define __iomem
60714 +# define __force_iomem
60715 # define __chk_user_ptr(x) (void)0
60716 # define __chk_io_ptr(x) (void)0
60717 # define __builtin_warning(x, y...) (1)
60718 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60719 # define __release(x) (void)0
60720 # define __cond_lock(x,c) (c)
60721 # define __percpu
60722 +# define __force_percpu
60723 # define __rcu
60724 +# define __force_rcu
60725 #endif
60726
60727 #ifdef __KERNEL__
60728 @@ -264,6 +297,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60729 # define __attribute_const__ /* unimplemented */
60730 #endif
60731
60732 +#ifndef __no_const
60733 +# define __no_const
60734 +#endif
60735 +
60736 +#ifndef __do_const
60737 +# define __do_const
60738 +#endif
60739 +
60740 +#ifndef __size_overflow
60741 +# define __size_overflow(...)
60742 +#endif
60743 +
60744 +#ifndef __latent_entropy
60745 +# define __latent_entropy
60746 +#endif
60747 +
60748 /*
60749 * Tell gcc if a function is cold. The compiler will assume any path
60750 * directly leading to the call is unlikely.
60751 @@ -273,6 +322,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60752 #define __cold
60753 #endif
60754
60755 +#ifndef __alloc_size
60756 +#define __alloc_size(...)
60757 +#endif
60758 +
60759 +#ifndef __bos
60760 +#define __bos(ptr, arg)
60761 +#endif
60762 +
60763 +#ifndef __bos0
60764 +#define __bos0(ptr)
60765 +#endif
60766 +
60767 +#ifndef __bos1
60768 +#define __bos1(ptr)
60769 +#endif
60770 +
60771 /* Simple shorthand for a section definition */
60772 #ifndef __section
60773 # define __section(S) __attribute__ ((__section__(#S)))
60774 @@ -308,6 +373,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60775 * use is to mediate communication between process-level code and irq/NMI
60776 * handlers, all running on the same CPU.
60777 */
60778 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60779 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60780 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60781
60782 #endif /* __LINUX_COMPILER_H */
60783 diff --git a/include/linux/cred.h b/include/linux/cred.h
60784 index ebbed2c..908cc2c 100644
60785 --- a/include/linux/cred.h
60786 +++ b/include/linux/cred.h
60787 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60788 static inline void validate_process_creds(void)
60789 {
60790 }
60791 +static inline void validate_task_creds(struct task_struct *task)
60792 +{
60793 +}
60794 #endif
60795
60796 /**
60797 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60798 index b92eadf..b4ecdc1 100644
60799 --- a/include/linux/crypto.h
60800 +++ b/include/linux/crypto.h
60801 @@ -373,7 +373,7 @@ struct cipher_tfm {
60802 const u8 *key, unsigned int keylen);
60803 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60804 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60805 -};
60806 +} __no_const;
60807
60808 struct hash_tfm {
60809 int (*init)(struct hash_desc *desc);
60810 @@ -394,13 +394,13 @@ struct compress_tfm {
60811 int (*cot_decompress)(struct crypto_tfm *tfm,
60812 const u8 *src, unsigned int slen,
60813 u8 *dst, unsigned int *dlen);
60814 -};
60815 +} __no_const;
60816
60817 struct rng_tfm {
60818 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60819 unsigned int dlen);
60820 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60821 -};
60822 +} __no_const;
60823
60824 #define crt_ablkcipher crt_u.ablkcipher
60825 #define crt_aead crt_u.aead
60826 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60827 index 7925bf0..d5143d2 100644
60828 --- a/include/linux/decompress/mm.h
60829 +++ b/include/linux/decompress/mm.h
60830 @@ -77,7 +77,7 @@ static void free(void *where)
60831 * warnings when not needed (indeed large_malloc / large_free are not
60832 * needed by inflate */
60833
60834 -#define malloc(a) kmalloc(a, GFP_KERNEL)
60835 +#define malloc(a) kmalloc((a), GFP_KERNEL)
60836 #define free(a) kfree(a)
60837
60838 #define large_malloc(a) vmalloc(a)
60839 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60840 index dfc099e..e583e66 100644
60841 --- a/include/linux/dma-mapping.h
60842 +++ b/include/linux/dma-mapping.h
60843 @@ -51,7 +51,7 @@ struct dma_map_ops {
60844 u64 (*get_required_mask)(struct device *dev);
60845 #endif
60846 int is_phys;
60847 -};
60848 +} __do_const;
60849
60850 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60851
60852 diff --git a/include/linux/efi.h b/include/linux/efi.h
60853 index ec45ccd..9923c32 100644
60854 --- a/include/linux/efi.h
60855 +++ b/include/linux/efi.h
60856 @@ -635,7 +635,7 @@ struct efivar_operations {
60857 efi_get_variable_t *get_variable;
60858 efi_get_next_variable_t *get_next_variable;
60859 efi_set_variable_t *set_variable;
60860 -};
60861 +} __no_const;
60862
60863 struct efivars {
60864 /*
60865 diff --git a/include/linux/elf.h b/include/linux/elf.h
60866 index 999b4f5..57753b4 100644
60867 --- a/include/linux/elf.h
60868 +++ b/include/linux/elf.h
60869 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
60870 #define PT_GNU_EH_FRAME 0x6474e550
60871
60872 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60873 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60874 +
60875 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60876 +
60877 +/* Constants for the e_flags field */
60878 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60879 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60880 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60881 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
60882 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60883 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60884
60885 /*
60886 * Extended Numbering
60887 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
60888 #define DT_DEBUG 21
60889 #define DT_TEXTREL 22
60890 #define DT_JMPREL 23
60891 +#define DT_FLAGS 30
60892 + #define DF_TEXTREL 0x00000004
60893 #define DT_ENCODING 32
60894 #define OLD_DT_LOOS 0x60000000
60895 #define DT_LOOS 0x6000000d
60896 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
60897 #define PF_W 0x2
60898 #define PF_X 0x1
60899
60900 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60901 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60902 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60903 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60904 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60905 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60906 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60907 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60908 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60909 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60910 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60911 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60912 +
60913 typedef struct elf32_phdr{
60914 Elf32_Word p_type;
60915 Elf32_Off p_offset;
60916 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
60917 #define EI_OSABI 7
60918 #define EI_PAD 8
60919
60920 +#define EI_PAX 14
60921 +
60922 #define ELFMAG0 0x7f /* EI_MAG */
60923 #define ELFMAG1 'E'
60924 #define ELFMAG2 'L'
60925 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
60926 #define elf_note elf32_note
60927 #define elf_addr_t Elf32_Off
60928 #define Elf_Half Elf32_Half
60929 +#define elf_dyn Elf32_Dyn
60930
60931 #else
60932
60933 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
60934 #define elf_note elf64_note
60935 #define elf_addr_t Elf64_Off
60936 #define Elf_Half Elf64_Half
60937 +#define elf_dyn Elf64_Dyn
60938
60939 #endif
60940
60941 diff --git a/include/linux/filter.h b/include/linux/filter.h
60942 index 82b0135..917914d 100644
60943 --- a/include/linux/filter.h
60944 +++ b/include/linux/filter.h
60945 @@ -146,6 +146,7 @@ struct compat_sock_fprog {
60946
60947 struct sk_buff;
60948 struct sock;
60949 +struct bpf_jit_work;
60950
60951 struct sk_filter
60952 {
60953 @@ -153,6 +154,9 @@ struct sk_filter
60954 unsigned int len; /* Number of filter blocks */
60955 unsigned int (*bpf_func)(const struct sk_buff *skb,
60956 const struct sock_filter *filter);
60957 +#ifdef CONFIG_BPF_JIT
60958 + struct bpf_jit_work *work;
60959 +#endif
60960 struct rcu_head rcu;
60961 struct sock_filter insns[0];
60962 };
60963 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60964 index 7edcf10..714d5e8 100644
60965 --- a/include/linux/firewire.h
60966 +++ b/include/linux/firewire.h
60967 @@ -430,7 +430,7 @@ struct fw_iso_context {
60968 union {
60969 fw_iso_callback_t sc;
60970 fw_iso_mc_callback_t mc;
60971 - } callback;
60972 + } __no_const callback;
60973 void *callback_data;
60974 };
60975
60976 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
60977 index 0e4e2ee..4ff4312 100644
60978 --- a/include/linux/frontswap.h
60979 +++ b/include/linux/frontswap.h
60980 @@ -11,7 +11,7 @@ struct frontswap_ops {
60981 int (*load)(unsigned, pgoff_t, struct page *);
60982 void (*invalidate_page)(unsigned, pgoff_t);
60983 void (*invalidate_area)(unsigned);
60984 -};
60985 +} __no_const;
60986
60987 extern bool frontswap_enabled;
60988 extern struct frontswap_ops
60989 diff --git a/include/linux/fs.h b/include/linux/fs.h
60990 index 17fd887..8eebca0 100644
60991 --- a/include/linux/fs.h
60992 +++ b/include/linux/fs.h
60993 @@ -1663,7 +1663,8 @@ struct file_operations {
60994 int (*setlease)(struct file *, long, struct file_lock **);
60995 long (*fallocate)(struct file *file, int mode, loff_t offset,
60996 loff_t len);
60997 -};
60998 +} __do_const;
60999 +typedef struct file_operations __no_const file_operations_no_const;
61000
61001 struct inode_operations {
61002 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
61003 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61004 index 003dc0f..3c4ea97 100644
61005 --- a/include/linux/fs_struct.h
61006 +++ b/include/linux/fs_struct.h
61007 @@ -6,7 +6,7 @@
61008 #include <linux/seqlock.h>
61009
61010 struct fs_struct {
61011 - int users;
61012 + atomic_t users;
61013 spinlock_t lock;
61014 seqcount_t seq;
61015 int umask;
61016 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61017 index ce31408..b1ad003 100644
61018 --- a/include/linux/fscache-cache.h
61019 +++ b/include/linux/fscache-cache.h
61020 @@ -102,7 +102,7 @@ struct fscache_operation {
61021 fscache_operation_release_t release;
61022 };
61023
61024 -extern atomic_t fscache_op_debug_id;
61025 +extern atomic_unchecked_t fscache_op_debug_id;
61026 extern void fscache_op_work_func(struct work_struct *work);
61027
61028 extern void fscache_enqueue_operation(struct fscache_operation *);
61029 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61030 {
61031 INIT_WORK(&op->work, fscache_op_work_func);
61032 atomic_set(&op->usage, 1);
61033 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61034 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61035 op->processor = processor;
61036 op->release = release;
61037 INIT_LIST_HEAD(&op->pend_link);
61038 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61039 index a6dfe69..569586df 100644
61040 --- a/include/linux/fsnotify.h
61041 +++ b/include/linux/fsnotify.h
61042 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61043 */
61044 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61045 {
61046 - return kstrdup(name, GFP_KERNEL);
61047 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61048 }
61049
61050 /*
61051 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61052 index 63d966d..cdcb717 100644
61053 --- a/include/linux/fsnotify_backend.h
61054 +++ b/include/linux/fsnotify_backend.h
61055 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61056 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61057 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61058 };
61059 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61060
61061 /*
61062 * A group is a "thing" that wants to receive notification about filesystem
61063 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61064 index 176a939..1462211 100644
61065 --- a/include/linux/ftrace_event.h
61066 +++ b/include/linux/ftrace_event.h
61067 @@ -97,7 +97,7 @@ struct trace_event_functions {
61068 trace_print_func raw;
61069 trace_print_func hex;
61070 trace_print_func binary;
61071 -};
61072 +} __no_const;
61073
61074 struct trace_event {
61075 struct hlist_node node;
61076 @@ -263,7 +263,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61077 extern int trace_add_event_call(struct ftrace_event_call *call);
61078 extern void trace_remove_event_call(struct ftrace_event_call *call);
61079
61080 -#define is_signed_type(type) (((type)(-1)) < 0)
61081 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61082
61083 int trace_set_clr_event(const char *system, const char *event, int set);
61084
61085 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61086 index 017a7fb..33a8507 100644
61087 --- a/include/linux/genhd.h
61088 +++ b/include/linux/genhd.h
61089 @@ -185,7 +185,7 @@ struct gendisk {
61090 struct kobject *slave_dir;
61091
61092 struct timer_rand_state *random;
61093 - atomic_t sync_io; /* RAID */
61094 + atomic_unchecked_t sync_io; /* RAID */
61095 struct disk_events *ev;
61096 #ifdef CONFIG_BLK_DEV_INTEGRITY
61097 struct blk_integrity *integrity;
61098 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61099 index 1e49be4..b8a9305 100644
61100 --- a/include/linux/gfp.h
61101 +++ b/include/linux/gfp.h
61102 @@ -38,6 +38,12 @@ struct vm_area_struct;
61103 #define ___GFP_OTHER_NODE 0x800000u
61104 #define ___GFP_WRITE 0x1000000u
61105
61106 +#ifdef CONFIG_PAX_USERCOPY_SLABS
61107 +#define ___GFP_USERCOPY 0x2000000u
61108 +#else
61109 +#define ___GFP_USERCOPY 0
61110 +#endif
61111 +
61112 /*
61113 * GFP bitmasks..
61114 *
61115 @@ -87,6 +93,7 @@ struct vm_area_struct;
61116 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61117 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61118 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61119 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61120
61121 /*
61122 * This may seem redundant, but it's a way of annotating false positives vs.
61123 @@ -94,7 +101,7 @@ struct vm_area_struct;
61124 */
61125 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61126
61127 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61128 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61129 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61130
61131 /* This equals 0, but use constants in case they ever change */
61132 @@ -148,6 +155,8 @@ struct vm_area_struct;
61133 /* 4GB DMA on some platforms */
61134 #define GFP_DMA32 __GFP_DMA32
61135
61136 +#define GFP_USERCOPY __GFP_USERCOPY
61137 +
61138 /* Convert GFP flags to their corresponding migrate type */
61139 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61140 {
61141 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61142 new file mode 100644
61143 index 0000000..c938b1f
61144 --- /dev/null
61145 +++ b/include/linux/gracl.h
61146 @@ -0,0 +1,319 @@
61147 +#ifndef GR_ACL_H
61148 +#define GR_ACL_H
61149 +
61150 +#include <linux/grdefs.h>
61151 +#include <linux/resource.h>
61152 +#include <linux/capability.h>
61153 +#include <linux/dcache.h>
61154 +#include <asm/resource.h>
61155 +
61156 +/* Major status information */
61157 +
61158 +#define GR_VERSION "grsecurity 2.9.1"
61159 +#define GRSECURITY_VERSION 0x2901
61160 +
61161 +enum {
61162 + GR_SHUTDOWN = 0,
61163 + GR_ENABLE = 1,
61164 + GR_SPROLE = 2,
61165 + GR_RELOAD = 3,
61166 + GR_SEGVMOD = 4,
61167 + GR_STATUS = 5,
61168 + GR_UNSPROLE = 6,
61169 + GR_PASSSET = 7,
61170 + GR_SPROLEPAM = 8,
61171 +};
61172 +
61173 +/* Password setup definitions
61174 + * kernel/grhash.c */
61175 +enum {
61176 + GR_PW_LEN = 128,
61177 + GR_SALT_LEN = 16,
61178 + GR_SHA_LEN = 32,
61179 +};
61180 +
61181 +enum {
61182 + GR_SPROLE_LEN = 64,
61183 +};
61184 +
61185 +enum {
61186 + GR_NO_GLOB = 0,
61187 + GR_REG_GLOB,
61188 + GR_CREATE_GLOB
61189 +};
61190 +
61191 +#define GR_NLIMITS 32
61192 +
61193 +/* Begin Data Structures */
61194 +
61195 +struct sprole_pw {
61196 + unsigned char *rolename;
61197 + unsigned char salt[GR_SALT_LEN];
61198 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61199 +};
61200 +
61201 +struct name_entry {
61202 + __u32 key;
61203 + ino_t inode;
61204 + dev_t device;
61205 + char *name;
61206 + __u16 len;
61207 + __u8 deleted;
61208 + struct name_entry *prev;
61209 + struct name_entry *next;
61210 +};
61211 +
61212 +struct inodev_entry {
61213 + struct name_entry *nentry;
61214 + struct inodev_entry *prev;
61215 + struct inodev_entry *next;
61216 +};
61217 +
61218 +struct acl_role_db {
61219 + struct acl_role_label **r_hash;
61220 + __u32 r_size;
61221 +};
61222 +
61223 +struct inodev_db {
61224 + struct inodev_entry **i_hash;
61225 + __u32 i_size;
61226 +};
61227 +
61228 +struct name_db {
61229 + struct name_entry **n_hash;
61230 + __u32 n_size;
61231 +};
61232 +
61233 +struct crash_uid {
61234 + uid_t uid;
61235 + unsigned long expires;
61236 +};
61237 +
61238 +struct gr_hash_struct {
61239 + void **table;
61240 + void **nametable;
61241 + void *first;
61242 + __u32 table_size;
61243 + __u32 used_size;
61244 + int type;
61245 +};
61246 +
61247 +/* Userspace Grsecurity ACL data structures */
61248 +
61249 +struct acl_subject_label {
61250 + char *filename;
61251 + ino_t inode;
61252 + dev_t device;
61253 + __u32 mode;
61254 + kernel_cap_t cap_mask;
61255 + kernel_cap_t cap_lower;
61256 + kernel_cap_t cap_invert_audit;
61257 +
61258 + struct rlimit res[GR_NLIMITS];
61259 + __u32 resmask;
61260 +
61261 + __u8 user_trans_type;
61262 + __u8 group_trans_type;
61263 + uid_t *user_transitions;
61264 + gid_t *group_transitions;
61265 + __u16 user_trans_num;
61266 + __u16 group_trans_num;
61267 +
61268 + __u32 sock_families[2];
61269 + __u32 ip_proto[8];
61270 + __u32 ip_type;
61271 + struct acl_ip_label **ips;
61272 + __u32 ip_num;
61273 + __u32 inaddr_any_override;
61274 +
61275 + __u32 crashes;
61276 + unsigned long expires;
61277 +
61278 + struct acl_subject_label *parent_subject;
61279 + struct gr_hash_struct *hash;
61280 + struct acl_subject_label *prev;
61281 + struct acl_subject_label *next;
61282 +
61283 + struct acl_object_label **obj_hash;
61284 + __u32 obj_hash_size;
61285 + __u16 pax_flags;
61286 +};
61287 +
61288 +struct role_allowed_ip {
61289 + __u32 addr;
61290 + __u32 netmask;
61291 +
61292 + struct role_allowed_ip *prev;
61293 + struct role_allowed_ip *next;
61294 +};
61295 +
61296 +struct role_transition {
61297 + char *rolename;
61298 +
61299 + struct role_transition *prev;
61300 + struct role_transition *next;
61301 +};
61302 +
61303 +struct acl_role_label {
61304 + char *rolename;
61305 + uid_t uidgid;
61306 + __u16 roletype;
61307 +
61308 + __u16 auth_attempts;
61309 + unsigned long expires;
61310 +
61311 + struct acl_subject_label *root_label;
61312 + struct gr_hash_struct *hash;
61313 +
61314 + struct acl_role_label *prev;
61315 + struct acl_role_label *next;
61316 +
61317 + struct role_transition *transitions;
61318 + struct role_allowed_ip *allowed_ips;
61319 + uid_t *domain_children;
61320 + __u16 domain_child_num;
61321 +
61322 + umode_t umask;
61323 +
61324 + struct acl_subject_label **subj_hash;
61325 + __u32 subj_hash_size;
61326 +};
61327 +
61328 +struct user_acl_role_db {
61329 + struct acl_role_label **r_table;
61330 + __u32 num_pointers; /* Number of allocations to track */
61331 + __u32 num_roles; /* Number of roles */
61332 + __u32 num_domain_children; /* Number of domain children */
61333 + __u32 num_subjects; /* Number of subjects */
61334 + __u32 num_objects; /* Number of objects */
61335 +};
61336 +
61337 +struct acl_object_label {
61338 + char *filename;
61339 + ino_t inode;
61340 + dev_t device;
61341 + __u32 mode;
61342 +
61343 + struct acl_subject_label *nested;
61344 + struct acl_object_label *globbed;
61345 +
61346 + /* next two structures not used */
61347 +
61348 + struct acl_object_label *prev;
61349 + struct acl_object_label *next;
61350 +};
61351 +
61352 +struct acl_ip_label {
61353 + char *iface;
61354 + __u32 addr;
61355 + __u32 netmask;
61356 + __u16 low, high;
61357 + __u8 mode;
61358 + __u32 type;
61359 + __u32 proto[8];
61360 +
61361 + /* next two structures not used */
61362 +
61363 + struct acl_ip_label *prev;
61364 + struct acl_ip_label *next;
61365 +};
61366 +
61367 +struct gr_arg {
61368 + struct user_acl_role_db role_db;
61369 + unsigned char pw[GR_PW_LEN];
61370 + unsigned char salt[GR_SALT_LEN];
61371 + unsigned char sum[GR_SHA_LEN];
61372 + unsigned char sp_role[GR_SPROLE_LEN];
61373 + struct sprole_pw *sprole_pws;
61374 + dev_t segv_device;
61375 + ino_t segv_inode;
61376 + uid_t segv_uid;
61377 + __u16 num_sprole_pws;
61378 + __u16 mode;
61379 +};
61380 +
61381 +struct gr_arg_wrapper {
61382 + struct gr_arg *arg;
61383 + __u32 version;
61384 + __u32 size;
61385 +};
61386 +
61387 +struct subject_map {
61388 + struct acl_subject_label *user;
61389 + struct acl_subject_label *kernel;
61390 + struct subject_map *prev;
61391 + struct subject_map *next;
61392 +};
61393 +
61394 +struct acl_subj_map_db {
61395 + struct subject_map **s_hash;
61396 + __u32 s_size;
61397 +};
61398 +
61399 +/* End Data Structures Section */
61400 +
61401 +/* Hash functions generated by empirical testing by Brad Spengler
61402 + Makes good use of the low bits of the inode. Generally 0-1 times
61403 + in loop for successful match. 0-3 for unsuccessful match.
61404 + Shift/add algorithm with modulus of table size and an XOR*/
61405 +
61406 +static __inline__ unsigned int
61407 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61408 +{
61409 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
61410 +}
61411 +
61412 + static __inline__ unsigned int
61413 +shash(const struct acl_subject_label *userp, const unsigned int sz)
61414 +{
61415 + return ((const unsigned long)userp % sz);
61416 +}
61417 +
61418 +static __inline__ unsigned int
61419 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61420 +{
61421 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61422 +}
61423 +
61424 +static __inline__ unsigned int
61425 +nhash(const char *name, const __u16 len, const unsigned int sz)
61426 +{
61427 + return full_name_hash((const unsigned char *)name, len) % sz;
61428 +}
61429 +
61430 +#define FOR_EACH_ROLE_START(role) \
61431 + role = role_list; \
61432 + while (role) {
61433 +
61434 +#define FOR_EACH_ROLE_END(role) \
61435 + role = role->prev; \
61436 + }
61437 +
61438 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61439 + subj = NULL; \
61440 + iter = 0; \
61441 + while (iter < role->subj_hash_size) { \
61442 + if (subj == NULL) \
61443 + subj = role->subj_hash[iter]; \
61444 + if (subj == NULL) { \
61445 + iter++; \
61446 + continue; \
61447 + }
61448 +
61449 +#define FOR_EACH_SUBJECT_END(subj,iter) \
61450 + subj = subj->next; \
61451 + if (subj == NULL) \
61452 + iter++; \
61453 + }
61454 +
61455 +
61456 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61457 + subj = role->hash->first; \
61458 + while (subj != NULL) {
61459 +
61460 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61461 + subj = subj->next; \
61462 + }
61463 +
61464 +#endif
61465 +
61466 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61467 new file mode 100644
61468 index 0000000..323ecf2
61469 --- /dev/null
61470 +++ b/include/linux/gralloc.h
61471 @@ -0,0 +1,9 @@
61472 +#ifndef __GRALLOC_H
61473 +#define __GRALLOC_H
61474 +
61475 +void acl_free_all(void);
61476 +int acl_alloc_stack_init(unsigned long size);
61477 +void *acl_alloc(unsigned long len);
61478 +void *acl_alloc_num(unsigned long num, unsigned long len);
61479 +
61480 +#endif
61481 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61482 new file mode 100644
61483 index 0000000..b30e9bc
61484 --- /dev/null
61485 +++ b/include/linux/grdefs.h
61486 @@ -0,0 +1,140 @@
61487 +#ifndef GRDEFS_H
61488 +#define GRDEFS_H
61489 +
61490 +/* Begin grsecurity status declarations */
61491 +
61492 +enum {
61493 + GR_READY = 0x01,
61494 + GR_STATUS_INIT = 0x00 // disabled state
61495 +};
61496 +
61497 +/* Begin ACL declarations */
61498 +
61499 +/* Role flags */
61500 +
61501 +enum {
61502 + GR_ROLE_USER = 0x0001,
61503 + GR_ROLE_GROUP = 0x0002,
61504 + GR_ROLE_DEFAULT = 0x0004,
61505 + GR_ROLE_SPECIAL = 0x0008,
61506 + GR_ROLE_AUTH = 0x0010,
61507 + GR_ROLE_NOPW = 0x0020,
61508 + GR_ROLE_GOD = 0x0040,
61509 + GR_ROLE_LEARN = 0x0080,
61510 + GR_ROLE_TPE = 0x0100,
61511 + GR_ROLE_DOMAIN = 0x0200,
61512 + GR_ROLE_PAM = 0x0400,
61513 + GR_ROLE_PERSIST = 0x0800
61514 +};
61515 +
61516 +/* ACL Subject and Object mode flags */
61517 +enum {
61518 + GR_DELETED = 0x80000000
61519 +};
61520 +
61521 +/* ACL Object-only mode flags */
61522 +enum {
61523 + GR_READ = 0x00000001,
61524 + GR_APPEND = 0x00000002,
61525 + GR_WRITE = 0x00000004,
61526 + GR_EXEC = 0x00000008,
61527 + GR_FIND = 0x00000010,
61528 + GR_INHERIT = 0x00000020,
61529 + GR_SETID = 0x00000040,
61530 + GR_CREATE = 0x00000080,
61531 + GR_DELETE = 0x00000100,
61532 + GR_LINK = 0x00000200,
61533 + GR_AUDIT_READ = 0x00000400,
61534 + GR_AUDIT_APPEND = 0x00000800,
61535 + GR_AUDIT_WRITE = 0x00001000,
61536 + GR_AUDIT_EXEC = 0x00002000,
61537 + GR_AUDIT_FIND = 0x00004000,
61538 + GR_AUDIT_INHERIT= 0x00008000,
61539 + GR_AUDIT_SETID = 0x00010000,
61540 + GR_AUDIT_CREATE = 0x00020000,
61541 + GR_AUDIT_DELETE = 0x00040000,
61542 + GR_AUDIT_LINK = 0x00080000,
61543 + GR_PTRACERD = 0x00100000,
61544 + GR_NOPTRACE = 0x00200000,
61545 + GR_SUPPRESS = 0x00400000,
61546 + GR_NOLEARN = 0x00800000,
61547 + GR_INIT_TRANSFER= 0x01000000
61548 +};
61549 +
61550 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61551 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61552 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61553 +
61554 +/* ACL subject-only mode flags */
61555 +enum {
61556 + GR_KILL = 0x00000001,
61557 + GR_VIEW = 0x00000002,
61558 + GR_PROTECTED = 0x00000004,
61559 + GR_LEARN = 0x00000008,
61560 + GR_OVERRIDE = 0x00000010,
61561 + /* just a placeholder, this mode is only used in userspace */
61562 + GR_DUMMY = 0x00000020,
61563 + GR_PROTSHM = 0x00000040,
61564 + GR_KILLPROC = 0x00000080,
61565 + GR_KILLIPPROC = 0x00000100,
61566 + /* just a placeholder, this mode is only used in userspace */
61567 + GR_NOTROJAN = 0x00000200,
61568 + GR_PROTPROCFD = 0x00000400,
61569 + GR_PROCACCT = 0x00000800,
61570 + GR_RELAXPTRACE = 0x00001000,
61571 + GR_NESTED = 0x00002000,
61572 + GR_INHERITLEARN = 0x00004000,
61573 + GR_PROCFIND = 0x00008000,
61574 + GR_POVERRIDE = 0x00010000,
61575 + GR_KERNELAUTH = 0x00020000,
61576 + GR_ATSECURE = 0x00040000,
61577 + GR_SHMEXEC = 0x00080000
61578 +};
61579 +
61580 +enum {
61581 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61582 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61583 + GR_PAX_ENABLE_MPROTECT = 0x0004,
61584 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
61585 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61586 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61587 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61588 + GR_PAX_DISABLE_MPROTECT = 0x0400,
61589 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
61590 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61591 +};
61592 +
61593 +enum {
61594 + GR_ID_USER = 0x01,
61595 + GR_ID_GROUP = 0x02,
61596 +};
61597 +
61598 +enum {
61599 + GR_ID_ALLOW = 0x01,
61600 + GR_ID_DENY = 0x02,
61601 +};
61602 +
61603 +#define GR_CRASH_RES 31
61604 +#define GR_UIDTABLE_MAX 500
61605 +
61606 +/* begin resource learning section */
61607 +enum {
61608 + GR_RLIM_CPU_BUMP = 60,
61609 + GR_RLIM_FSIZE_BUMP = 50000,
61610 + GR_RLIM_DATA_BUMP = 10000,
61611 + GR_RLIM_STACK_BUMP = 1000,
61612 + GR_RLIM_CORE_BUMP = 10000,
61613 + GR_RLIM_RSS_BUMP = 500000,
61614 + GR_RLIM_NPROC_BUMP = 1,
61615 + GR_RLIM_NOFILE_BUMP = 5,
61616 + GR_RLIM_MEMLOCK_BUMP = 50000,
61617 + GR_RLIM_AS_BUMP = 500000,
61618 + GR_RLIM_LOCKS_BUMP = 2,
61619 + GR_RLIM_SIGPENDING_BUMP = 5,
61620 + GR_RLIM_MSGQUEUE_BUMP = 10000,
61621 + GR_RLIM_NICE_BUMP = 1,
61622 + GR_RLIM_RTPRIO_BUMP = 1,
61623 + GR_RLIM_RTTIME_BUMP = 1000000
61624 +};
61625 +
61626 +#endif
61627 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61628 new file mode 100644
61629 index 0000000..c9292f7
61630 --- /dev/null
61631 +++ b/include/linux/grinternal.h
61632 @@ -0,0 +1,223 @@
61633 +#ifndef __GRINTERNAL_H
61634 +#define __GRINTERNAL_H
61635 +
61636 +#ifdef CONFIG_GRKERNSEC
61637 +
61638 +#include <linux/fs.h>
61639 +#include <linux/mnt_namespace.h>
61640 +#include <linux/nsproxy.h>
61641 +#include <linux/gracl.h>
61642 +#include <linux/grdefs.h>
61643 +#include <linux/grmsg.h>
61644 +
61645 +void gr_add_learn_entry(const char *fmt, ...)
61646 + __attribute__ ((format (printf, 1, 2)));
61647 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61648 + const struct vfsmount *mnt);
61649 +__u32 gr_check_create(const struct dentry *new_dentry,
61650 + const struct dentry *parent,
61651 + const struct vfsmount *mnt, const __u32 mode);
61652 +int gr_check_protected_task(const struct task_struct *task);
61653 +__u32 to_gr_audit(const __u32 reqmode);
61654 +int gr_set_acls(const int type);
61655 +int gr_apply_subject_to_task(struct task_struct *task);
61656 +int gr_acl_is_enabled(void);
61657 +char gr_roletype_to_char(void);
61658 +
61659 +void gr_handle_alertkill(struct task_struct *task);
61660 +char *gr_to_filename(const struct dentry *dentry,
61661 + const struct vfsmount *mnt);
61662 +char *gr_to_filename1(const struct dentry *dentry,
61663 + const struct vfsmount *mnt);
61664 +char *gr_to_filename2(const struct dentry *dentry,
61665 + const struct vfsmount *mnt);
61666 +char *gr_to_filename3(const struct dentry *dentry,
61667 + const struct vfsmount *mnt);
61668 +
61669 +extern int grsec_enable_ptrace_readexec;
61670 +extern int grsec_enable_harden_ptrace;
61671 +extern int grsec_enable_link;
61672 +extern int grsec_enable_fifo;
61673 +extern int grsec_enable_execve;
61674 +extern int grsec_enable_shm;
61675 +extern int grsec_enable_execlog;
61676 +extern int grsec_enable_signal;
61677 +extern int grsec_enable_audit_ptrace;
61678 +extern int grsec_enable_forkfail;
61679 +extern int grsec_enable_time;
61680 +extern int grsec_enable_rofs;
61681 +extern int grsec_enable_chroot_shmat;
61682 +extern int grsec_enable_chroot_mount;
61683 +extern int grsec_enable_chroot_double;
61684 +extern int grsec_enable_chroot_pivot;
61685 +extern int grsec_enable_chroot_chdir;
61686 +extern int grsec_enable_chroot_chmod;
61687 +extern int grsec_enable_chroot_mknod;
61688 +extern int grsec_enable_chroot_fchdir;
61689 +extern int grsec_enable_chroot_nice;
61690 +extern int grsec_enable_chroot_execlog;
61691 +extern int grsec_enable_chroot_caps;
61692 +extern int grsec_enable_chroot_sysctl;
61693 +extern int grsec_enable_chroot_unix;
61694 +extern int grsec_enable_symlinkown;
61695 +extern int grsec_symlinkown_gid;
61696 +extern int grsec_enable_tpe;
61697 +extern int grsec_tpe_gid;
61698 +extern int grsec_enable_tpe_all;
61699 +extern int grsec_enable_tpe_invert;
61700 +extern int grsec_enable_socket_all;
61701 +extern int grsec_socket_all_gid;
61702 +extern int grsec_enable_socket_client;
61703 +extern int grsec_socket_client_gid;
61704 +extern int grsec_enable_socket_server;
61705 +extern int grsec_socket_server_gid;
61706 +extern int grsec_audit_gid;
61707 +extern int grsec_enable_group;
61708 +extern int grsec_enable_audit_textrel;
61709 +extern int grsec_enable_log_rwxmaps;
61710 +extern int grsec_enable_mount;
61711 +extern int grsec_enable_chdir;
61712 +extern int grsec_resource_logging;
61713 +extern int grsec_enable_blackhole;
61714 +extern int grsec_lastack_retries;
61715 +extern int grsec_enable_brute;
61716 +extern int grsec_lock;
61717 +
61718 +extern spinlock_t grsec_alert_lock;
61719 +extern unsigned long grsec_alert_wtime;
61720 +extern unsigned long grsec_alert_fyet;
61721 +
61722 +extern spinlock_t grsec_audit_lock;
61723 +
61724 +extern rwlock_t grsec_exec_file_lock;
61725 +
61726 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61727 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61728 + (tsk)->exec_file->f_vfsmnt) : "/")
61729 +
61730 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61731 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61732 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61733 +
61734 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61735 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
61736 + (tsk)->exec_file->f_vfsmnt) : "/")
61737 +
61738 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61739 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61740 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61741 +
61742 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61743 +
61744 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61745 +
61746 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61747 + (task)->pid, (cred)->uid, \
61748 + (cred)->euid, (cred)->gid, (cred)->egid, \
61749 + gr_parent_task_fullpath(task), \
61750 + (task)->real_parent->comm, (task)->real_parent->pid, \
61751 + (pcred)->uid, (pcred)->euid, \
61752 + (pcred)->gid, (pcred)->egid
61753 +
61754 +#define GR_CHROOT_CAPS {{ \
61755 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61756 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61757 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61758 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61759 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61760 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61761 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61762 +
61763 +#define security_learn(normal_msg,args...) \
61764 +({ \
61765 + read_lock(&grsec_exec_file_lock); \
61766 + gr_add_learn_entry(normal_msg "\n", ## args); \
61767 + read_unlock(&grsec_exec_file_lock); \
61768 +})
61769 +
61770 +enum {
61771 + GR_DO_AUDIT,
61772 + GR_DONT_AUDIT,
61773 + /* used for non-audit messages that we shouldn't kill the task on */
61774 + GR_DONT_AUDIT_GOOD
61775 +};
61776 +
61777 +enum {
61778 + GR_TTYSNIFF,
61779 + GR_RBAC,
61780 + GR_RBAC_STR,
61781 + GR_STR_RBAC,
61782 + GR_RBAC_MODE2,
61783 + GR_RBAC_MODE3,
61784 + GR_FILENAME,
61785 + GR_SYSCTL_HIDDEN,
61786 + GR_NOARGS,
61787 + GR_ONE_INT,
61788 + GR_ONE_INT_TWO_STR,
61789 + GR_ONE_STR,
61790 + GR_STR_INT,
61791 + GR_TWO_STR_INT,
61792 + GR_TWO_INT,
61793 + GR_TWO_U64,
61794 + GR_THREE_INT,
61795 + GR_FIVE_INT_TWO_STR,
61796 + GR_TWO_STR,
61797 + GR_THREE_STR,
61798 + GR_FOUR_STR,
61799 + GR_STR_FILENAME,
61800 + GR_FILENAME_STR,
61801 + GR_FILENAME_TWO_INT,
61802 + GR_FILENAME_TWO_INT_STR,
61803 + GR_TEXTREL,
61804 + GR_PTRACE,
61805 + GR_RESOURCE,
61806 + GR_CAP,
61807 + GR_SIG,
61808 + GR_SIG2,
61809 + GR_CRASH1,
61810 + GR_CRASH2,
61811 + GR_PSACCT,
61812 + GR_RWXMAP
61813 +};
61814 +
61815 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61816 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61817 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61818 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61819 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61820 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61821 +#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)
61822 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61823 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61824 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61825 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61826 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61827 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61828 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61829 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61830 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61831 +#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)
61832 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61833 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61834 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61835 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61836 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61837 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61838 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61839 +#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)
61840 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61841 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61842 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61843 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61844 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61845 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61846 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61847 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61848 +#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)
61849 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61850 +
61851 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61852 +
61853 +#endif
61854 +
61855 +#endif
61856 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61857 new file mode 100644
61858 index 0000000..54f4e85
61859 --- /dev/null
61860 +++ b/include/linux/grmsg.h
61861 @@ -0,0 +1,110 @@
61862 +#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"
61863 +#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"
61864 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61865 +#define GR_STOPMOD_MSG "denied modification of module state by "
61866 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61867 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61868 +#define GR_IOPERM_MSG "denied use of ioperm() by "
61869 +#define GR_IOPL_MSG "denied use of iopl() by "
61870 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
61871 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
61872 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
61873 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
61874 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
61875 +#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"
61876 +#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"
61877 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
61878 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
61879 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
61880 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
61881 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
61882 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
61883 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
61884 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
61885 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
61886 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
61887 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
61888 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
61889 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
61890 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
61891 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
61892 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61893 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61894 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61895 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61896 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
61897 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61898 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61899 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61900 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61901 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61902 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61903 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61904 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61905 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61906 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61907 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61908 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61909 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61910 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61911 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61912 +#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"
61913 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
61914 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61915 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61916 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61917 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61918 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61919 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61920 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61921 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61922 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61923 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61924 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61925 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61926 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61927 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61928 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61929 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61930 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61931 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61932 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61933 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
61934 +#define GR_NICE_CHROOT_MSG "denied priority change by "
61935 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61936 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61937 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61938 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61939 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
61940 +#define GR_TIME_MSG "time set by "
61941 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
61942 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
61943 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
61944 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
61945 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
61946 +#define GR_BIND_MSG "denied bind() by "
61947 +#define GR_CONNECT_MSG "denied connect() by "
61948 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
61949 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
61950 +#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"
61951 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
61952 +#define GR_CAP_ACL_MSG "use of %s denied for "
61953 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
61954 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
61955 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
61956 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
61957 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
61958 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
61959 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
61960 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
61961 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
61962 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
61963 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
61964 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
61965 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
61966 +#define GR_VM86_MSG "denied use of vm86 by "
61967 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
61968 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
61969 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
61970 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
61971 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
61972 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
61973 new file mode 100644
61974 index 0000000..38bfb04
61975 --- /dev/null
61976 +++ b/include/linux/grsecurity.h
61977 @@ -0,0 +1,233 @@
61978 +#ifndef GR_SECURITY_H
61979 +#define GR_SECURITY_H
61980 +#include <linux/fs.h>
61981 +#include <linux/fs_struct.h>
61982 +#include <linux/binfmts.h>
61983 +#include <linux/gracl.h>
61984 +
61985 +/* notify of brain-dead configs */
61986 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61987 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
61988 +#endif
61989 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
61990 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
61991 +#endif
61992 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
61993 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
61994 +#endif
61995 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
61996 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
61997 +#endif
61998 +
61999 +#include <linux/compat.h>
62000 +
62001 +struct user_arg_ptr {
62002 +#ifdef CONFIG_COMPAT
62003 + bool is_compat;
62004 +#endif
62005 + union {
62006 + const char __user *const __user *native;
62007 +#ifdef CONFIG_COMPAT
62008 + compat_uptr_t __user *compat;
62009 +#endif
62010 + } ptr;
62011 +};
62012 +
62013 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62014 +void gr_handle_brute_check(void);
62015 +void gr_handle_kernel_exploit(void);
62016 +int gr_process_user_ban(void);
62017 +
62018 +char gr_roletype_to_char(void);
62019 +
62020 +int gr_acl_enable_at_secure(void);
62021 +
62022 +int gr_check_user_change(int real, int effective, int fs);
62023 +int gr_check_group_change(int real, int effective, int fs);
62024 +
62025 +void gr_del_task_from_ip_table(struct task_struct *p);
62026 +
62027 +int gr_pid_is_chrooted(struct task_struct *p);
62028 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62029 +int gr_handle_chroot_nice(void);
62030 +int gr_handle_chroot_sysctl(const int op);
62031 +int gr_handle_chroot_setpriority(struct task_struct *p,
62032 + const int niceval);
62033 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62034 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62035 + const struct vfsmount *mnt);
62036 +void gr_handle_chroot_chdir(struct path *path);
62037 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62038 + const struct vfsmount *mnt, const int mode);
62039 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62040 + const struct vfsmount *mnt, const int mode);
62041 +int gr_handle_chroot_mount(const struct dentry *dentry,
62042 + const struct vfsmount *mnt,
62043 + const char *dev_name);
62044 +int gr_handle_chroot_pivot(void);
62045 +int gr_handle_chroot_unix(const pid_t pid);
62046 +
62047 +int gr_handle_rawio(const struct inode *inode);
62048 +
62049 +void gr_handle_ioperm(void);
62050 +void gr_handle_iopl(void);
62051 +
62052 +umode_t gr_acl_umask(void);
62053 +
62054 +int gr_tpe_allow(const struct file *file);
62055 +
62056 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62057 +void gr_clear_chroot_entries(struct task_struct *task);
62058 +
62059 +void gr_log_forkfail(const int retval);
62060 +void gr_log_timechange(void);
62061 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62062 +void gr_log_chdir(const struct dentry *dentry,
62063 + const struct vfsmount *mnt);
62064 +void gr_log_chroot_exec(const struct dentry *dentry,
62065 + const struct vfsmount *mnt);
62066 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62067 +void gr_log_remount(const char *devname, const int retval);
62068 +void gr_log_unmount(const char *devname, const int retval);
62069 +void gr_log_mount(const char *from, const char *to, const int retval);
62070 +void gr_log_textrel(struct vm_area_struct *vma);
62071 +void gr_log_rwxmmap(struct file *file);
62072 +void gr_log_rwxmprotect(struct file *file);
62073 +
62074 +int gr_handle_follow_link(const struct inode *parent,
62075 + const struct inode *inode,
62076 + const struct dentry *dentry,
62077 + const struct vfsmount *mnt);
62078 +int gr_handle_fifo(const struct dentry *dentry,
62079 + const struct vfsmount *mnt,
62080 + const struct dentry *dir, const int flag,
62081 + const int acc_mode);
62082 +int gr_handle_hardlink(const struct dentry *dentry,
62083 + const struct vfsmount *mnt,
62084 + struct inode *inode,
62085 + const int mode, const char *to);
62086 +
62087 +int gr_is_capable(const int cap);
62088 +int gr_is_capable_nolog(const int cap);
62089 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62090 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62091 +
62092 +void gr_learn_resource(const struct task_struct *task, const int limit,
62093 + const unsigned long wanted, const int gt);
62094 +void gr_copy_label(struct task_struct *tsk);
62095 +void gr_handle_crash(struct task_struct *task, const int sig);
62096 +int gr_handle_signal(const struct task_struct *p, const int sig);
62097 +int gr_check_crash_uid(const uid_t uid);
62098 +int gr_check_protected_task(const struct task_struct *task);
62099 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62100 +int gr_acl_handle_mmap(const struct file *file,
62101 + const unsigned long prot);
62102 +int gr_acl_handle_mprotect(const struct file *file,
62103 + const unsigned long prot);
62104 +int gr_check_hidden_task(const struct task_struct *tsk);
62105 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62106 + const struct vfsmount *mnt);
62107 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62108 + const struct vfsmount *mnt);
62109 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62110 + const struct vfsmount *mnt, const int fmode);
62111 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62112 + const struct vfsmount *mnt, umode_t *mode);
62113 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62114 + const struct vfsmount *mnt);
62115 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62116 + const struct vfsmount *mnt);
62117 +int gr_handle_ptrace(struct task_struct *task, const long request);
62118 +int gr_handle_proc_ptrace(struct task_struct *task);
62119 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62120 + const struct vfsmount *mnt);
62121 +int gr_check_crash_exec(const struct file *filp);
62122 +int gr_acl_is_enabled(void);
62123 +void gr_set_kernel_label(struct task_struct *task);
62124 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62125 + const gid_t gid);
62126 +int gr_set_proc_label(const struct dentry *dentry,
62127 + const struct vfsmount *mnt,
62128 + const int unsafe_flags);
62129 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62130 + const struct vfsmount *mnt);
62131 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62132 + const struct vfsmount *mnt, int acc_mode);
62133 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62134 + const struct dentry *p_dentry,
62135 + const struct vfsmount *p_mnt,
62136 + int open_flags, int acc_mode, const int imode);
62137 +void gr_handle_create(const struct dentry *dentry,
62138 + const struct vfsmount *mnt);
62139 +void gr_handle_proc_create(const struct dentry *dentry,
62140 + const struct inode *inode);
62141 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62142 + const struct dentry *parent_dentry,
62143 + const struct vfsmount *parent_mnt,
62144 + const int mode);
62145 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62146 + const struct dentry *parent_dentry,
62147 + const struct vfsmount *parent_mnt);
62148 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62149 + const struct vfsmount *mnt);
62150 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62151 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62152 + const struct vfsmount *mnt);
62153 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62154 + const struct dentry *parent_dentry,
62155 + const struct vfsmount *parent_mnt,
62156 + const char *from);
62157 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62158 + const struct dentry *parent_dentry,
62159 + const struct vfsmount *parent_mnt,
62160 + const struct dentry *old_dentry,
62161 + const struct vfsmount *old_mnt, const char *to);
62162 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62163 +int gr_acl_handle_rename(struct dentry *new_dentry,
62164 + struct dentry *parent_dentry,
62165 + const struct vfsmount *parent_mnt,
62166 + struct dentry *old_dentry,
62167 + struct inode *old_parent_inode,
62168 + struct vfsmount *old_mnt, const char *newname);
62169 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62170 + struct dentry *old_dentry,
62171 + struct dentry *new_dentry,
62172 + struct vfsmount *mnt, const __u8 replace);
62173 +__u32 gr_check_link(const struct dentry *new_dentry,
62174 + const struct dentry *parent_dentry,
62175 + const struct vfsmount *parent_mnt,
62176 + const struct dentry *old_dentry,
62177 + const struct vfsmount *old_mnt);
62178 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62179 + const unsigned int namelen, const ino_t ino);
62180 +
62181 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62182 + const struct vfsmount *mnt);
62183 +void gr_acl_handle_exit(void);
62184 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62185 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62186 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62187 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62188 +void gr_audit_ptrace(struct task_struct *task);
62189 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62190 +
62191 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62192 +
62193 +#ifdef CONFIG_GRKERNSEC
62194 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62195 +void gr_handle_vm86(void);
62196 +void gr_handle_mem_readwrite(u64 from, u64 to);
62197 +
62198 +void gr_log_badprocpid(const char *entry);
62199 +
62200 +extern int grsec_enable_dmesg;
62201 +extern int grsec_disable_privio;
62202 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62203 +extern int grsec_enable_chroot_findtask;
62204 +#endif
62205 +#ifdef CONFIG_GRKERNSEC_SETXID
62206 +extern int grsec_enable_setxid;
62207 +#endif
62208 +#endif
62209 +
62210 +#endif
62211 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62212 new file mode 100644
62213 index 0000000..e7ffaaf
62214 --- /dev/null
62215 +++ b/include/linux/grsock.h
62216 @@ -0,0 +1,19 @@
62217 +#ifndef __GRSOCK_H
62218 +#define __GRSOCK_H
62219 +
62220 +extern void gr_attach_curr_ip(const struct sock *sk);
62221 +extern int gr_handle_sock_all(const int family, const int type,
62222 + const int protocol);
62223 +extern int gr_handle_sock_server(const struct sockaddr *sck);
62224 +extern int gr_handle_sock_server_other(const struct sock *sck);
62225 +extern int gr_handle_sock_client(const struct sockaddr *sck);
62226 +extern int gr_search_connect(struct socket * sock,
62227 + struct sockaddr_in * addr);
62228 +extern int gr_search_bind(struct socket * sock,
62229 + struct sockaddr_in * addr);
62230 +extern int gr_search_listen(struct socket * sock);
62231 +extern int gr_search_accept(struct socket * sock);
62232 +extern int gr_search_socket(const int domain, const int type,
62233 + const int protocol);
62234 +
62235 +#endif
62236 diff --git a/include/linux/hid.h b/include/linux/hid.h
62237 index 449fa38..b37c8cc 100644
62238 --- a/include/linux/hid.h
62239 +++ b/include/linux/hid.h
62240 @@ -704,7 +704,7 @@ struct hid_ll_driver {
62241 unsigned int code, int value);
62242
62243 int (*parse)(struct hid_device *hdev);
62244 -};
62245 +} __no_const;
62246
62247 #define PM_HINT_FULLON 1<<5
62248 #define PM_HINT_NORMAL 1<<1
62249 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62250 index d3999b4..1304cb4 100644
62251 --- a/include/linux/highmem.h
62252 +++ b/include/linux/highmem.h
62253 @@ -221,6 +221,18 @@ static inline void clear_highpage(struct page *page)
62254 kunmap_atomic(kaddr);
62255 }
62256
62257 +static inline void sanitize_highpage(struct page *page)
62258 +{
62259 + void *kaddr;
62260 + unsigned long flags;
62261 +
62262 + local_irq_save(flags);
62263 + kaddr = kmap_atomic(page);
62264 + clear_page(kaddr);
62265 + kunmap_atomic(kaddr);
62266 + local_irq_restore(flags);
62267 +}
62268 +
62269 static inline void zero_user_segments(struct page *page,
62270 unsigned start1, unsigned end1,
62271 unsigned start2, unsigned end2)
62272 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62273 index ddfa041..a44cfff 100644
62274 --- a/include/linux/i2c.h
62275 +++ b/include/linux/i2c.h
62276 @@ -366,6 +366,7 @@ struct i2c_algorithm {
62277 /* To determine what the adapter supports */
62278 u32 (*functionality) (struct i2c_adapter *);
62279 };
62280 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62281
62282 /*
62283 * i2c_adapter is the structure used to identify a physical i2c bus along
62284 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62285 index d23c3c2..eb63c81 100644
62286 --- a/include/linux/i2o.h
62287 +++ b/include/linux/i2o.h
62288 @@ -565,7 +565,7 @@ struct i2o_controller {
62289 struct i2o_device *exec; /* Executive */
62290 #if BITS_PER_LONG == 64
62291 spinlock_t context_list_lock; /* lock for context_list */
62292 - atomic_t context_list_counter; /* needed for unique contexts */
62293 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62294 struct list_head context_list; /* list of context id's
62295 and pointers */
62296 #endif
62297 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62298 index 8185f57..7b2d222 100644
62299 --- a/include/linux/if_team.h
62300 +++ b/include/linux/if_team.h
62301 @@ -74,6 +74,7 @@ struct team_mode_ops {
62302 void (*port_leave)(struct team *team, struct team_port *port);
62303 void (*port_change_mac)(struct team *team, struct team_port *port);
62304 };
62305 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62306
62307 enum team_option_type {
62308 TEAM_OPTION_TYPE_U32,
62309 @@ -136,7 +137,7 @@ struct team {
62310 struct list_head option_inst_list; /* list of option instances */
62311
62312 const struct team_mode *mode;
62313 - struct team_mode_ops ops;
62314 + team_mode_ops_no_const ops;
62315 long mode_priv[TEAM_MODE_PRIV_LONGS];
62316 };
62317
62318 diff --git a/include/linux/init.h b/include/linux/init.h
62319 index 6b95109..bcbdd68 100644
62320 --- a/include/linux/init.h
62321 +++ b/include/linux/init.h
62322 @@ -39,9 +39,15 @@
62323 * Also note, that this data cannot be "const".
62324 */
62325
62326 +#ifdef MODULE
62327 +#define add_latent_entropy
62328 +#else
62329 +#define add_latent_entropy __latent_entropy
62330 +#endif
62331 +
62332 /* These are for everybody (although not all archs will actually
62333 discard it in modules) */
62334 -#define __init __section(.init.text) __cold notrace
62335 +#define __init __section(.init.text) __cold notrace add_latent_entropy
62336 #define __initdata __section(.init.data)
62337 #define __initconst __section(.init.rodata)
62338 #define __exitdata __section(.exit.data)
62339 @@ -83,7 +89,7 @@
62340 #define __exit __section(.exit.text) __exitused __cold notrace
62341
62342 /* Used for HOTPLUG */
62343 -#define __devinit __section(.devinit.text) __cold notrace
62344 +#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
62345 #define __devinitdata __section(.devinit.data)
62346 #define __devinitconst __section(.devinit.rodata)
62347 #define __devexit __section(.devexit.text) __exitused __cold notrace
62348 @@ -91,7 +97,7 @@
62349 #define __devexitconst __section(.devexit.rodata)
62350
62351 /* Used for HOTPLUG_CPU */
62352 -#define __cpuinit __section(.cpuinit.text) __cold notrace
62353 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
62354 #define __cpuinitdata __section(.cpuinit.data)
62355 #define __cpuinitconst __section(.cpuinit.rodata)
62356 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
62357 @@ -99,7 +105,7 @@
62358 #define __cpuexitconst __section(.cpuexit.rodata)
62359
62360 /* Used for MEMORY_HOTPLUG */
62361 -#define __meminit __section(.meminit.text) __cold notrace
62362 +#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
62363 #define __meminitdata __section(.meminit.data)
62364 #define __meminitconst __section(.meminit.rodata)
62365 #define __memexit __section(.memexit.text) __exitused __cold notrace
62366 @@ -294,13 +300,13 @@ void __init parse_early_options(char *cmdline);
62367
62368 /* Each module must use one module_init(). */
62369 #define module_init(initfn) \
62370 - static inline initcall_t __inittest(void) \
62371 + static inline __used initcall_t __inittest(void) \
62372 { return initfn; } \
62373 int init_module(void) __attribute__((alias(#initfn)));
62374
62375 /* This is only required if you want to be unloadable. */
62376 #define module_exit(exitfn) \
62377 - static inline exitcall_t __exittest(void) \
62378 + static inline __used exitcall_t __exittest(void) \
62379 { return exitfn; } \
62380 void cleanup_module(void) __attribute__((alias(#exitfn)));
62381
62382 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62383 index 9e65eff..b131e8b 100644
62384 --- a/include/linux/init_task.h
62385 +++ b/include/linux/init_task.h
62386 @@ -134,6 +134,12 @@ extern struct cred init_cred;
62387
62388 #define INIT_TASK_COMM "swapper"
62389
62390 +#ifdef CONFIG_X86
62391 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62392 +#else
62393 +#define INIT_TASK_THREAD_INFO
62394 +#endif
62395 +
62396 /*
62397 * INIT_TASK is used to set up the first task table, touch at
62398 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62399 @@ -172,6 +178,7 @@ extern struct cred init_cred;
62400 RCU_INIT_POINTER(.cred, &init_cred), \
62401 .comm = INIT_TASK_COMM, \
62402 .thread = INIT_THREAD, \
62403 + INIT_TASK_THREAD_INFO \
62404 .fs = &init_fs, \
62405 .files = &init_files, \
62406 .signal = &init_signals, \
62407 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62408 index e6ca56d..8583707 100644
62409 --- a/include/linux/intel-iommu.h
62410 +++ b/include/linux/intel-iommu.h
62411 @@ -296,7 +296,7 @@ struct iommu_flush {
62412 u8 fm, u64 type);
62413 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62414 unsigned int size_order, u64 type);
62415 -};
62416 +} __no_const;
62417
62418 enum {
62419 SR_DMAR_FECTL_REG,
62420 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62421 index e68a8e5..811b9af 100644
62422 --- a/include/linux/interrupt.h
62423 +++ b/include/linux/interrupt.h
62424 @@ -435,7 +435,7 @@ enum
62425 /* map softirq index to softirq name. update 'softirq_to_name' in
62426 * kernel/softirq.c when adding a new softirq.
62427 */
62428 -extern char *softirq_to_name[NR_SOFTIRQS];
62429 +extern const char * const softirq_to_name[NR_SOFTIRQS];
62430
62431 /* softirq mask and active fields moved to irq_cpustat_t in
62432 * asm/hardirq.h to get better cache usage. KAO
62433 @@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62434
62435 struct softirq_action
62436 {
62437 - void (*action)(struct softirq_action *);
62438 + void (*action)(void);
62439 };
62440
62441 asmlinkage void do_softirq(void);
62442 asmlinkage void __do_softirq(void);
62443 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62444 +extern void open_softirq(int nr, void (*action)(void));
62445 extern void softirq_init(void);
62446 extern void __raise_softirq_irqoff(unsigned int nr);
62447
62448 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62449 index 6883e19..06992b1 100644
62450 --- a/include/linux/kallsyms.h
62451 +++ b/include/linux/kallsyms.h
62452 @@ -15,7 +15,8 @@
62453
62454 struct module;
62455
62456 -#ifdef CONFIG_KALLSYMS
62457 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62458 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62459 /* Lookup the address for a symbol. Returns 0 if not found. */
62460 unsigned long kallsyms_lookup_name(const char *name);
62461
62462 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62463 /* Stupid that this does nothing, but I didn't create this mess. */
62464 #define __print_symbol(fmt, addr)
62465 #endif /*CONFIG_KALLSYMS*/
62466 +#else /* when included by kallsyms.c, vsnprintf.c, or
62467 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62468 +extern void __print_symbol(const char *fmt, unsigned long address);
62469 +extern int sprint_backtrace(char *buffer, unsigned long address);
62470 +extern int sprint_symbol(char *buffer, unsigned long address);
62471 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
62472 +const char *kallsyms_lookup(unsigned long addr,
62473 + unsigned long *symbolsize,
62474 + unsigned long *offset,
62475 + char **modname, char *namebuf);
62476 +#endif
62477
62478 /* This macro allows us to keep printk typechecking */
62479 static __printf(1, 2)
62480 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62481 index c4d2fc1..5df9c19 100644
62482 --- a/include/linux/kgdb.h
62483 +++ b/include/linux/kgdb.h
62484 @@ -53,7 +53,7 @@ extern int kgdb_connected;
62485 extern int kgdb_io_module_registered;
62486
62487 extern atomic_t kgdb_setting_breakpoint;
62488 -extern atomic_t kgdb_cpu_doing_single_step;
62489 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62490
62491 extern struct task_struct *kgdb_usethread;
62492 extern struct task_struct *kgdb_contthread;
62493 @@ -252,7 +252,7 @@ struct kgdb_arch {
62494 void (*disable_hw_break)(struct pt_regs *regs);
62495 void (*remove_all_hw_break)(void);
62496 void (*correct_hw_break)(void);
62497 -};
62498 +} __do_const;
62499
62500 /**
62501 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62502 @@ -277,7 +277,7 @@ struct kgdb_io {
62503 void (*pre_exception) (void);
62504 void (*post_exception) (void);
62505 int is_console;
62506 -};
62507 +} __do_const;
62508
62509 extern struct kgdb_arch arch_kgdb_ops;
62510
62511 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62512 index 5398d58..5883a34 100644
62513 --- a/include/linux/kmod.h
62514 +++ b/include/linux/kmod.h
62515 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62516 * usually useless though. */
62517 extern __printf(2, 3)
62518 int __request_module(bool wait, const char *name, ...);
62519 +extern __printf(3, 4)
62520 +int ___request_module(bool wait, char *param_name, const char *name, ...);
62521 #define request_module(mod...) __request_module(true, mod)
62522 #define request_module_nowait(mod...) __request_module(false, mod)
62523 #define try_then_request_module(x, mod...) \
62524 diff --git a/include/linux/kref.h b/include/linux/kref.h
62525 index 9c07dce..a92fa71 100644
62526 --- a/include/linux/kref.h
62527 +++ b/include/linux/kref.h
62528 @@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
62529 static inline int kref_sub(struct kref *kref, unsigned int count,
62530 void (*release)(struct kref *kref))
62531 {
62532 - WARN_ON(release == NULL);
62533 + BUG_ON(release == NULL);
62534
62535 if (atomic_sub_and_test((int) count, &kref->refcount)) {
62536 release(kref);
62537 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62538 index 96c158a..1864db5 100644
62539 --- a/include/linux/kvm_host.h
62540 +++ b/include/linux/kvm_host.h
62541 @@ -345,7 +345,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62542 void vcpu_load(struct kvm_vcpu *vcpu);
62543 void vcpu_put(struct kvm_vcpu *vcpu);
62544
62545 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62546 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62547 struct module *module);
62548 void kvm_exit(void);
62549
62550 @@ -511,7 +511,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62551 struct kvm_guest_debug *dbg);
62552 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62553
62554 -int kvm_arch_init(void *opaque);
62555 +int kvm_arch_init(const void *opaque);
62556 void kvm_arch_exit(void);
62557
62558 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62559 diff --git a/include/linux/libata.h b/include/linux/libata.h
62560 index 6e887c7..4539601 100644
62561 --- a/include/linux/libata.h
62562 +++ b/include/linux/libata.h
62563 @@ -910,7 +910,7 @@ struct ata_port_operations {
62564 * fields must be pointers.
62565 */
62566 const struct ata_port_operations *inherits;
62567 -};
62568 +} __do_const;
62569
62570 struct ata_port_info {
62571 unsigned long flags;
62572 diff --git a/include/linux/memory.h b/include/linux/memory.h
62573 index 1ac7f6e..a5794d0 100644
62574 --- a/include/linux/memory.h
62575 +++ b/include/linux/memory.h
62576 @@ -143,7 +143,7 @@ struct memory_accessor {
62577 size_t count);
62578 ssize_t (*write)(struct memory_accessor *, const char *buf,
62579 off_t offset, size_t count);
62580 -};
62581 +} __no_const;
62582
62583 /*
62584 * Kernel text modification mutex, used for code patching. Users of this lock
62585 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62586 index 1318ca6..7521340 100644
62587 --- a/include/linux/mfd/abx500.h
62588 +++ b/include/linux/mfd/abx500.h
62589 @@ -452,6 +452,7 @@ struct abx500_ops {
62590 int (*event_registers_startup_state_get) (struct device *, u8 *);
62591 int (*startup_irq_enabled) (struct device *, unsigned int);
62592 };
62593 +typedef struct abx500_ops __no_const abx500_ops_no_const;
62594
62595 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62596 void abx500_remove_ops(struct device *dev);
62597 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
62598 index 9b07725..3d55001 100644
62599 --- a/include/linux/mfd/abx500/ux500_chargalg.h
62600 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
62601 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
62602 int (*enable) (struct ux500_charger *, int, int, int);
62603 int (*kick_wd) (struct ux500_charger *);
62604 int (*update_curr) (struct ux500_charger *, int);
62605 -};
62606 +} __no_const;
62607
62608 /**
62609 * struct ux500_charger - power supply ux500 charger sub class
62610 diff --git a/include/linux/mm.h b/include/linux/mm.h
62611 index f9f279c..198da78 100644
62612 --- a/include/linux/mm.h
62613 +++ b/include/linux/mm.h
62614 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
62615
62616 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62617 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62618 +
62619 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62620 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62621 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62622 +#else
62623 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62624 +#endif
62625 +
62626 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62627 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62628
62629 @@ -1009,34 +1016,6 @@ int set_page_dirty(struct page *page);
62630 int set_page_dirty_lock(struct page *page);
62631 int clear_page_dirty_for_io(struct page *page);
62632
62633 -/* Is the vma a continuation of the stack vma above it? */
62634 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62635 -{
62636 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62637 -}
62638 -
62639 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
62640 - unsigned long addr)
62641 -{
62642 - return (vma->vm_flags & VM_GROWSDOWN) &&
62643 - (vma->vm_start == addr) &&
62644 - !vma_growsdown(vma->vm_prev, addr);
62645 -}
62646 -
62647 -/* Is the vma a continuation of the stack vma below it? */
62648 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62649 -{
62650 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62651 -}
62652 -
62653 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
62654 - unsigned long addr)
62655 -{
62656 - return (vma->vm_flags & VM_GROWSUP) &&
62657 - (vma->vm_end == addr) &&
62658 - !vma_growsup(vma->vm_next, addr);
62659 -}
62660 -
62661 extern pid_t
62662 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
62663
62664 @@ -1135,6 +1114,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
62665 }
62666 #endif
62667
62668 +#ifdef CONFIG_MMU
62669 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62670 +#else
62671 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62672 +{
62673 + return __pgprot(0);
62674 +}
62675 +#endif
62676 +
62677 int vma_wants_writenotify(struct vm_area_struct *vma);
62678
62679 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62680 @@ -1153,8 +1141,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
62681 {
62682 return 0;
62683 }
62684 +
62685 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
62686 + unsigned long address)
62687 +{
62688 + return 0;
62689 +}
62690 #else
62691 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62692 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62693 #endif
62694
62695 #ifdef __PAGETABLE_PMD_FOLDED
62696 @@ -1163,8 +1158,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
62697 {
62698 return 0;
62699 }
62700 +
62701 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
62702 + unsigned long address)
62703 +{
62704 + return 0;
62705 +}
62706 #else
62707 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
62708 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
62709 #endif
62710
62711 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
62712 @@ -1182,11 +1184,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
62713 NULL: pud_offset(pgd, address);
62714 }
62715
62716 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
62717 +{
62718 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
62719 + NULL: pud_offset(pgd, address);
62720 +}
62721 +
62722 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
62723 {
62724 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
62725 NULL: pmd_offset(pud, address);
62726 }
62727 +
62728 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
62729 +{
62730 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
62731 + NULL: pmd_offset(pud, address);
62732 +}
62733 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
62734
62735 #if USE_SPLIT_PTLOCKS
62736 @@ -1396,6 +1410,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
62737 unsigned long, unsigned long,
62738 unsigned long, unsigned long);
62739 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62740 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62741
62742 /* These take the mm semaphore themselves */
62743 extern unsigned long vm_brk(unsigned long, unsigned long);
62744 @@ -1458,6 +1473,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62745 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62746 struct vm_area_struct **pprev);
62747
62748 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62749 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62750 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62751 +
62752 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62753 NULL if none. Assume start_addr < end_addr. */
62754 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62755 @@ -1486,15 +1505,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
62756 return vma;
62757 }
62758
62759 -#ifdef CONFIG_MMU
62760 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
62761 -#else
62762 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62763 -{
62764 - return __pgprot(0);
62765 -}
62766 -#endif
62767 -
62768 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62769 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62770 unsigned long pfn, unsigned long size, pgprot_t);
62771 @@ -1599,7 +1609,7 @@ extern int unpoison_memory(unsigned long pfn);
62772 extern int sysctl_memory_failure_early_kill;
62773 extern int sysctl_memory_failure_recovery;
62774 extern void shake_page(struct page *p, int access);
62775 -extern atomic_long_t mce_bad_pages;
62776 +extern atomic_long_unchecked_t mce_bad_pages;
62777 extern int soft_offline_page(struct page *page, int flags);
62778
62779 extern void dump_page(struct page *page);
62780 @@ -1630,5 +1640,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
62781 static inline bool page_is_guard(struct page *page) { return false; }
62782 #endif /* CONFIG_DEBUG_PAGEALLOC */
62783
62784 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62785 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62786 +#else
62787 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62788 +#endif
62789 +
62790 #endif /* __KERNEL__ */
62791 #endif /* _LINUX_MM_H */
62792 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62793 index 704a626..bb0705a 100644
62794 --- a/include/linux/mm_types.h
62795 +++ b/include/linux/mm_types.h
62796 @@ -263,6 +263,8 @@ struct vm_area_struct {
62797 #ifdef CONFIG_NUMA
62798 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62799 #endif
62800 +
62801 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62802 };
62803
62804 struct core_thread {
62805 @@ -337,7 +339,7 @@ struct mm_struct {
62806 unsigned long def_flags;
62807 unsigned long nr_ptes; /* Page table pages */
62808 unsigned long start_code, end_code, start_data, end_data;
62809 - unsigned long start_brk, brk, start_stack;
62810 + unsigned long brk_gap, start_brk, brk, start_stack;
62811 unsigned long arg_start, arg_end, env_start, env_end;
62812
62813 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
62814 @@ -389,6 +391,24 @@ struct mm_struct {
62815 struct cpumask cpumask_allocation;
62816 #endif
62817 struct uprobes_state uprobes_state;
62818 +
62819 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62820 + unsigned long pax_flags;
62821 +#endif
62822 +
62823 +#ifdef CONFIG_PAX_DLRESOLVE
62824 + unsigned long call_dl_resolve;
62825 +#endif
62826 +
62827 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
62828 + unsigned long call_syscall;
62829 +#endif
62830 +
62831 +#ifdef CONFIG_PAX_ASLR
62832 + unsigned long delta_mmap; /* randomized offset */
62833 + unsigned long delta_stack; /* randomized offset */
62834 +#endif
62835 +
62836 };
62837
62838 static inline void mm_init_cpumask(struct mm_struct *mm)
62839 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
62840 index 1d1b1e1..2a13c78 100644
62841 --- a/include/linux/mmu_notifier.h
62842 +++ b/include/linux/mmu_notifier.h
62843 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62844 */
62845 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62846 ({ \
62847 - pte_t __pte; \
62848 + pte_t ___pte; \
62849 struct vm_area_struct *___vma = __vma; \
62850 unsigned long ___address = __address; \
62851 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62852 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62853 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62854 - __pte; \
62855 + ___pte; \
62856 })
62857
62858 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62859 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62860 index 68c569f..5f43753 100644
62861 --- a/include/linux/mmzone.h
62862 +++ b/include/linux/mmzone.h
62863 @@ -411,7 +411,7 @@ struct zone {
62864 unsigned long flags; /* zone flags, see below */
62865
62866 /* Zone statistics */
62867 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62868 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62869
62870 /*
62871 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62872 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62873 index 5db9382..50e801d 100644
62874 --- a/include/linux/mod_devicetable.h
62875 +++ b/include/linux/mod_devicetable.h
62876 @@ -12,7 +12,7 @@
62877 typedef unsigned long kernel_ulong_t;
62878 #endif
62879
62880 -#define PCI_ANY_ID (~0)
62881 +#define PCI_ANY_ID ((__u16)~0)
62882
62883 struct pci_device_id {
62884 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62885 @@ -131,7 +131,7 @@ struct usb_device_id {
62886 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
62887 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
62888
62889 -#define HID_ANY_ID (~0)
62890 +#define HID_ANY_ID (~0U)
62891 #define HID_BUS_ANY 0xffff
62892 #define HID_GROUP_ANY 0x0000
62893
62894 diff --git a/include/linux/module.h b/include/linux/module.h
62895 index fbcafe2..e5d9587 100644
62896 --- a/include/linux/module.h
62897 +++ b/include/linux/module.h
62898 @@ -17,6 +17,7 @@
62899 #include <linux/moduleparam.h>
62900 #include <linux/tracepoint.h>
62901 #include <linux/export.h>
62902 +#include <linux/fs.h>
62903
62904 #include <linux/percpu.h>
62905 #include <asm/module.h>
62906 @@ -273,19 +274,16 @@ struct module
62907 int (*init)(void);
62908
62909 /* If this is non-NULL, vfree after init() returns */
62910 - void *module_init;
62911 + void *module_init_rx, *module_init_rw;
62912
62913 /* Here is the actual code + data, vfree'd on unload. */
62914 - void *module_core;
62915 + void *module_core_rx, *module_core_rw;
62916
62917 /* Here are the sizes of the init and core sections */
62918 - unsigned int init_size, core_size;
62919 + unsigned int init_size_rw, core_size_rw;
62920
62921 /* The size of the executable code in each section. */
62922 - unsigned int init_text_size, core_text_size;
62923 -
62924 - /* Size of RO sections of the module (text+rodata) */
62925 - unsigned int init_ro_size, core_ro_size;
62926 + unsigned int init_size_rx, core_size_rx;
62927
62928 /* Arch-specific module values */
62929 struct mod_arch_specific arch;
62930 @@ -341,6 +339,10 @@ struct module
62931 #ifdef CONFIG_EVENT_TRACING
62932 struct ftrace_event_call **trace_events;
62933 unsigned int num_trace_events;
62934 + struct file_operations trace_id;
62935 + struct file_operations trace_enable;
62936 + struct file_operations trace_format;
62937 + struct file_operations trace_filter;
62938 #endif
62939 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62940 unsigned int num_ftrace_callsites;
62941 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
62942 bool is_module_percpu_address(unsigned long addr);
62943 bool is_module_text_address(unsigned long addr);
62944
62945 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62946 +{
62947 +
62948 +#ifdef CONFIG_PAX_KERNEXEC
62949 + if (ktla_ktva(addr) >= (unsigned long)start &&
62950 + ktla_ktva(addr) < (unsigned long)start + size)
62951 + return 1;
62952 +#endif
62953 +
62954 + return ((void *)addr >= start && (void *)addr < start + size);
62955 +}
62956 +
62957 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
62958 +{
62959 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
62960 +}
62961 +
62962 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
62963 +{
62964 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
62965 +}
62966 +
62967 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
62968 +{
62969 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
62970 +}
62971 +
62972 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
62973 +{
62974 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
62975 +}
62976 +
62977 static inline int within_module_core(unsigned long addr, struct module *mod)
62978 {
62979 - return (unsigned long)mod->module_core <= addr &&
62980 - addr < (unsigned long)mod->module_core + mod->core_size;
62981 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62982 }
62983
62984 static inline int within_module_init(unsigned long addr, struct module *mod)
62985 {
62986 - return (unsigned long)mod->module_init <= addr &&
62987 - addr < (unsigned long)mod->module_init + mod->init_size;
62988 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62989 }
62990
62991 /* Search for module by name: must hold module_mutex. */
62992 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62993 index b2be02e..72d2f78 100644
62994 --- a/include/linux/moduleloader.h
62995 +++ b/include/linux/moduleloader.h
62996 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62997
62998 /* Allocator used for allocating struct module, core sections and init
62999 sections. Returns NULL on failure. */
63000 -void *module_alloc(unsigned long size);
63001 +void *module_alloc(unsigned long size) __size_overflow(1);
63002 +
63003 +#ifdef CONFIG_PAX_KERNEXEC
63004 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
63005 +#else
63006 +#define module_alloc_exec(x) module_alloc(x)
63007 +#endif
63008
63009 /* Free memory returned from module_alloc. */
63010 void module_free(struct module *mod, void *module_region);
63011
63012 +#ifdef CONFIG_PAX_KERNEXEC
63013 +void module_free_exec(struct module *mod, void *module_region);
63014 +#else
63015 +#define module_free_exec(x, y) module_free((x), (y))
63016 +#endif
63017 +
63018 /* Apply the given relocation to the (simplified) ELF. Return -error
63019 or 0. */
63020 int apply_relocate(Elf_Shdr *sechdrs,
63021 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63022 index d6a5806..7c13347 100644
63023 --- a/include/linux/moduleparam.h
63024 +++ b/include/linux/moduleparam.h
63025 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63026 * @len is usually just sizeof(string).
63027 */
63028 #define module_param_string(name, string, len, perm) \
63029 - static const struct kparam_string __param_string_##name \
63030 + static const struct kparam_string __param_string_##name __used \
63031 = { len, string }; \
63032 __module_param_call(MODULE_PARAM_PREFIX, name, \
63033 &param_ops_string, \
63034 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63035 */
63036 #define module_param_array_named(name, array, type, nump, perm) \
63037 param_check_##type(name, &(array)[0]); \
63038 - static const struct kparam_array __param_arr_##name \
63039 + static const struct kparam_array __param_arr_##name __used \
63040 = { .max = ARRAY_SIZE(array), .num = nump, \
63041 .ops = &param_ops_##type, \
63042 .elemsize = sizeof(array[0]), .elem = array }; \
63043 diff --git a/include/linux/namei.h b/include/linux/namei.h
63044 index ffc0213..2c1f2cb 100644
63045 --- a/include/linux/namei.h
63046 +++ b/include/linux/namei.h
63047 @@ -24,7 +24,7 @@ struct nameidata {
63048 unsigned seq;
63049 int last_type;
63050 unsigned depth;
63051 - char *saved_names[MAX_NESTED_LINKS + 1];
63052 + const char *saved_names[MAX_NESTED_LINKS + 1];
63053
63054 /* Intent data */
63055 union {
63056 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
63057 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
63058 extern void unlock_rename(struct dentry *, struct dentry *);
63059
63060 -static inline void nd_set_link(struct nameidata *nd, char *path)
63061 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63062 {
63063 nd->saved_names[nd->depth] = path;
63064 }
63065
63066 -static inline char *nd_get_link(struct nameidata *nd)
63067 +static inline const char *nd_get_link(const struct nameidata *nd)
63068 {
63069 return nd->saved_names[nd->depth];
63070 }
63071 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63072 index d94cb14..e64c951 100644
63073 --- a/include/linux/netdevice.h
63074 +++ b/include/linux/netdevice.h
63075 @@ -1026,6 +1026,7 @@ struct net_device_ops {
63076 struct net_device *dev,
63077 int idx);
63078 };
63079 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63080
63081 /*
63082 * The DEVICE structure.
63083 @@ -1087,7 +1088,7 @@ struct net_device {
63084 int iflink;
63085
63086 struct net_device_stats stats;
63087 - atomic_long_t rx_dropped; /* dropped packets by core network
63088 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63089 * Do not use this in drivers.
63090 */
63091
63092 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63093 new file mode 100644
63094 index 0000000..33f4af8
63095 --- /dev/null
63096 +++ b/include/linux/netfilter/xt_gradm.h
63097 @@ -0,0 +1,9 @@
63098 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63099 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63100 +
63101 +struct xt_gradm_mtinfo {
63102 + __u16 flags;
63103 + __u16 invflags;
63104 +};
63105 +
63106 +#endif
63107 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63108 index c65a18a..0c05f3a 100644
63109 --- a/include/linux/of_pdt.h
63110 +++ b/include/linux/of_pdt.h
63111 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63112
63113 /* return 0 on success; fill in 'len' with number of bytes in path */
63114 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63115 -};
63116 +} __no_const;
63117
63118 extern void *prom_early_alloc(unsigned long size);
63119
63120 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63121 index a4c5624..79d6d88 100644
63122 --- a/include/linux/oprofile.h
63123 +++ b/include/linux/oprofile.h
63124 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63125 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63126 char const * name, ulong * val);
63127
63128 -/** Create a file for read-only access to an atomic_t. */
63129 +/** Create a file for read-only access to an atomic_unchecked_t. */
63130 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63131 - char const * name, atomic_t * val);
63132 + char const * name, atomic_unchecked_t * val);
63133
63134 /** create a directory */
63135 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63136 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63137 index 45db49f..386788e 100644
63138 --- a/include/linux/perf_event.h
63139 +++ b/include/linux/perf_event.h
63140 @@ -879,8 +879,8 @@ struct perf_event {
63141
63142 enum perf_event_active_state state;
63143 unsigned int attach_state;
63144 - local64_t count;
63145 - atomic64_t child_count;
63146 + local64_t count; /* PaX: fix it one day */
63147 + atomic64_unchecked_t child_count;
63148
63149 /*
63150 * These are the total time in nanoseconds that the event
63151 @@ -931,8 +931,8 @@ struct perf_event {
63152 * These accumulate total time (in nanoseconds) that children
63153 * events have been enabled and running, respectively.
63154 */
63155 - atomic64_t child_total_time_enabled;
63156 - atomic64_t child_total_time_running;
63157 + atomic64_unchecked_t child_total_time_enabled;
63158 + atomic64_unchecked_t child_total_time_running;
63159
63160 /*
63161 * Protect attach/detach and child_list:
63162 diff --git a/include/linux/personality.h b/include/linux/personality.h
63163 index 8fc7dd1a..c19d89e 100644
63164 --- a/include/linux/personality.h
63165 +++ b/include/linux/personality.h
63166 @@ -44,6 +44,7 @@ enum {
63167 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63168 ADDR_NO_RANDOMIZE | \
63169 ADDR_COMPAT_LAYOUT | \
63170 + ADDR_LIMIT_3GB | \
63171 MMAP_PAGE_ZERO)
63172
63173 /*
63174 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63175 index e1ac1ce..0675fed 100644
63176 --- a/include/linux/pipe_fs_i.h
63177 +++ b/include/linux/pipe_fs_i.h
63178 @@ -45,9 +45,9 @@ struct pipe_buffer {
63179 struct pipe_inode_info {
63180 wait_queue_head_t wait;
63181 unsigned int nrbufs, curbuf, buffers;
63182 - unsigned int readers;
63183 - unsigned int writers;
63184 - unsigned int waiting_writers;
63185 + atomic_t readers;
63186 + atomic_t writers;
63187 + atomic_t waiting_writers;
63188 unsigned int r_counter;
63189 unsigned int w_counter;
63190 struct page *tmp_page;
63191 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63192 index f271860..6b3bec5 100644
63193 --- a/include/linux/pm_runtime.h
63194 +++ b/include/linux/pm_runtime.h
63195 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63196
63197 static inline void pm_runtime_mark_last_busy(struct device *dev)
63198 {
63199 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63200 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63201 }
63202
63203 #else /* !CONFIG_PM_RUNTIME */
63204 diff --git a/include/linux/poison.h b/include/linux/poison.h
63205 index 2110a81..13a11bb 100644
63206 --- a/include/linux/poison.h
63207 +++ b/include/linux/poison.h
63208 @@ -19,8 +19,8 @@
63209 * under normal circumstances, used to verify that nobody uses
63210 * non-initialized list entries.
63211 */
63212 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63213 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63214 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63215 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63216
63217 /********** include/linux/timer.h **********/
63218 /*
63219 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63220 index 5a710b9..0b0dab9 100644
63221 --- a/include/linux/preempt.h
63222 +++ b/include/linux/preempt.h
63223 @@ -126,7 +126,7 @@ struct preempt_ops {
63224 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63225 void (*sched_out)(struct preempt_notifier *notifier,
63226 struct task_struct *next);
63227 -};
63228 +} __no_const;
63229
63230 /**
63231 * preempt_notifier - key for installing preemption notifiers
63232 diff --git a/include/linux/printk.h b/include/linux/printk.h
63233 index 1bec2f7..b66e833 100644
63234 --- a/include/linux/printk.h
63235 +++ b/include/linux/printk.h
63236 @@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
63237 extern int printk_needs_cpu(int cpu);
63238 extern void printk_tick(void);
63239
63240 +extern int kptr_restrict;
63241 +
63242 #ifdef CONFIG_PRINTK
63243 asmlinkage __printf(5, 0)
63244 int vprintk_emit(int facility, int level,
63245 @@ -128,7 +130,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63246
63247 extern int printk_delay_msec;
63248 extern int dmesg_restrict;
63249 -extern int kptr_restrict;
63250
63251 void log_buf_kexec_setup(void);
63252 void __init setup_log_buf(int early);
63253 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63254 index 3fd2e87..d93a721 100644
63255 --- a/include/linux/proc_fs.h
63256 +++ b/include/linux/proc_fs.h
63257 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63258 return proc_create_data(name, mode, parent, proc_fops, NULL);
63259 }
63260
63261 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63262 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63263 +{
63264 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63265 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63266 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63267 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63268 +#else
63269 + return proc_create_data(name, mode, parent, proc_fops, NULL);
63270 +#endif
63271 +}
63272 +
63273 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63274 umode_t mode, struct proc_dir_entry *base,
63275 read_proc_t *read_proc, void * data)
63276 @@ -258,7 +270,7 @@ union proc_op {
63277 int (*proc_show)(struct seq_file *m,
63278 struct pid_namespace *ns, struct pid *pid,
63279 struct task_struct *task);
63280 -};
63281 +} __no_const;
63282
63283 struct ctl_table_header;
63284 struct ctl_table;
63285 diff --git a/include/linux/random.h b/include/linux/random.h
63286 index 8f74538..de61694 100644
63287 --- a/include/linux/random.h
63288 +++ b/include/linux/random.h
63289 @@ -54,6 +54,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63290 unsigned int value);
63291 extern void add_interrupt_randomness(int irq);
63292
63293 +#ifdef CONFIG_PAX_LATENT_ENTROPY
63294 +extern void transfer_latent_entropy(void);
63295 +#endif
63296 +
63297 extern void get_random_bytes(void *buf, int nbytes);
63298 void generate_random_uuid(unsigned char uuid_out[16]);
63299
63300 @@ -69,12 +73,17 @@ void srandom32(u32 seed);
63301
63302 u32 prandom32(struct rnd_state *);
63303
63304 +static inline unsigned long pax_get_random_long(void)
63305 +{
63306 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63307 +}
63308 +
63309 /*
63310 * Handle minimum values for seeds
63311 */
63312 static inline u32 __seed(u32 x, u32 m)
63313 {
63314 - return (x < m) ? x + m : x;
63315 + return (x <= m) ? x + m + 1 : x;
63316 }
63317
63318 /**
63319 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63320 index e0879a7..a12f962 100644
63321 --- a/include/linux/reboot.h
63322 +++ b/include/linux/reboot.h
63323 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63324 * Architecture-specific implementations of sys_reboot commands.
63325 */
63326
63327 -extern void machine_restart(char *cmd);
63328 -extern void machine_halt(void);
63329 -extern void machine_power_off(void);
63330 +extern void machine_restart(char *cmd) __noreturn;
63331 +extern void machine_halt(void) __noreturn;
63332 +extern void machine_power_off(void) __noreturn;
63333
63334 extern void machine_shutdown(void);
63335 struct pt_regs;
63336 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63337 */
63338
63339 extern void kernel_restart_prepare(char *cmd);
63340 -extern void kernel_restart(char *cmd);
63341 -extern void kernel_halt(void);
63342 -extern void kernel_power_off(void);
63343 +extern void kernel_restart(char *cmd) __noreturn;
63344 +extern void kernel_halt(void) __noreturn;
63345 +extern void kernel_power_off(void) __noreturn;
63346
63347 extern int C_A_D; /* for sysctl */
63348 void ctrl_alt_del(void);
63349 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63350 * Emergency restart, callable from an interrupt handler.
63351 */
63352
63353 -extern void emergency_restart(void);
63354 +extern void emergency_restart(void) __noreturn;
63355 #include <asm/emergency-restart.h>
63356
63357 #endif
63358 diff --git a/include/linux/relay.h b/include/linux/relay.h
63359 index 91cacc3..b55ff74 100644
63360 --- a/include/linux/relay.h
63361 +++ b/include/linux/relay.h
63362 @@ -160,7 +160,7 @@ struct rchan_callbacks
63363 * The callback should return 0 if successful, negative if not.
63364 */
63365 int (*remove_buf_file)(struct dentry *dentry);
63366 -};
63367 +} __no_const;
63368
63369 /*
63370 * CONFIG_RELAY kernel API, kernel/relay.c
63371 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63372 index 6fdf027..ff72610 100644
63373 --- a/include/linux/rfkill.h
63374 +++ b/include/linux/rfkill.h
63375 @@ -147,6 +147,7 @@ struct rfkill_ops {
63376 void (*query)(struct rfkill *rfkill, void *data);
63377 int (*set_block)(void *data, bool blocked);
63378 };
63379 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63380
63381 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63382 /**
63383 diff --git a/include/linux/rio.h b/include/linux/rio.h
63384 index a90ebad..fd87b5d 100644
63385 --- a/include/linux/rio.h
63386 +++ b/include/linux/rio.h
63387 @@ -321,7 +321,7 @@ struct rio_ops {
63388 int mbox, void *buffer, size_t len);
63389 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63390 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63391 -};
63392 +} __no_const;
63393
63394 #define RIO_RESOURCE_MEM 0x00000100
63395 #define RIO_RESOURCE_DOORBELL 0x00000200
63396 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63397 index 3fce545..b4fed6e 100644
63398 --- a/include/linux/rmap.h
63399 +++ b/include/linux/rmap.h
63400 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63401 void anon_vma_init(void); /* create anon_vma_cachep */
63402 int anon_vma_prepare(struct vm_area_struct *);
63403 void unlink_anon_vmas(struct vm_area_struct *);
63404 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63405 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63406 void anon_vma_moveto_tail(struct vm_area_struct *);
63407 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63408 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63409
63410 static inline void anon_vma_merge(struct vm_area_struct *vma,
63411 struct vm_area_struct *next)
63412 diff --git a/include/linux/sched.h b/include/linux/sched.h
63413 index 4a1f493..5812aeb 100644
63414 --- a/include/linux/sched.h
63415 +++ b/include/linux/sched.h
63416 @@ -101,6 +101,7 @@ struct bio_list;
63417 struct fs_struct;
63418 struct perf_event_context;
63419 struct blk_plug;
63420 +struct linux_binprm;
63421
63422 /*
63423 * List of flags we want to share for kernel threads,
63424 @@ -384,10 +385,13 @@ struct user_namespace;
63425 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63426
63427 extern int sysctl_max_map_count;
63428 +extern unsigned long sysctl_heap_stack_gap;
63429
63430 #include <linux/aio.h>
63431
63432 #ifdef CONFIG_MMU
63433 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63434 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63435 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63436 extern unsigned long
63437 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63438 @@ -406,6 +410,11 @@ static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
63439 extern void set_dumpable(struct mm_struct *mm, int value);
63440 extern int get_dumpable(struct mm_struct *mm);
63441
63442 +/* get/set_dumpable() values */
63443 +#define SUID_DUMPABLE_DISABLED 0
63444 +#define SUID_DUMPABLE_ENABLED 1
63445 +#define SUID_DUMPABLE_SAFE 2
63446 +
63447 /* mm flags */
63448 /* dumpable bits */
63449 #define MMF_DUMPABLE 0 /* core dump is permitted */
63450 @@ -646,6 +655,17 @@ struct signal_struct {
63451 #ifdef CONFIG_TASKSTATS
63452 struct taskstats *stats;
63453 #endif
63454 +
63455 +#ifdef CONFIG_GRKERNSEC
63456 + u32 curr_ip;
63457 + u32 saved_ip;
63458 + u32 gr_saddr;
63459 + u32 gr_daddr;
63460 + u16 gr_sport;
63461 + u16 gr_dport;
63462 + u8 used_accept:1;
63463 +#endif
63464 +
63465 #ifdef CONFIG_AUDIT
63466 unsigned audit_tty;
63467 struct tty_audit_buf *tty_audit_buf;
63468 @@ -729,6 +749,11 @@ struct user_struct {
63469 struct key *session_keyring; /* UID's default session keyring */
63470 #endif
63471
63472 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63473 + unsigned int banned;
63474 + unsigned long ban_expires;
63475 +#endif
63476 +
63477 /* Hash table maintenance information */
63478 struct hlist_node uidhash_node;
63479 kuid_t uid;
63480 @@ -1348,8 +1373,8 @@ struct task_struct {
63481 struct list_head thread_group;
63482
63483 struct completion *vfork_done; /* for vfork() */
63484 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63485 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63486 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63487 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63488
63489 cputime_t utime, stime, utimescaled, stimescaled;
63490 cputime_t gtime;
63491 @@ -1365,11 +1390,6 @@ struct task_struct {
63492 struct task_cputime cputime_expires;
63493 struct list_head cpu_timers[3];
63494
63495 -/* process credentials */
63496 - const struct cred __rcu *real_cred; /* objective and real subjective task
63497 - * credentials (COW) */
63498 - const struct cred __rcu *cred; /* effective (overridable) subjective task
63499 - * credentials (COW) */
63500 char comm[TASK_COMM_LEN]; /* executable name excluding path
63501 - access with [gs]et_task_comm (which lock
63502 it with task_lock())
63503 @@ -1386,8 +1406,16 @@ struct task_struct {
63504 #endif
63505 /* CPU-specific state of this task */
63506 struct thread_struct thread;
63507 +/* thread_info moved to task_struct */
63508 +#ifdef CONFIG_X86
63509 + struct thread_info tinfo;
63510 +#endif
63511 /* filesystem information */
63512 struct fs_struct *fs;
63513 +
63514 + const struct cred __rcu *cred; /* effective (overridable) subjective task
63515 + * credentials (COW) */
63516 +
63517 /* open file information */
63518 struct files_struct *files;
63519 /* namespaces */
63520 @@ -1431,6 +1459,11 @@ struct task_struct {
63521 struct rt_mutex_waiter *pi_blocked_on;
63522 #endif
63523
63524 +/* process credentials */
63525 + const struct cred __rcu *real_cred; /* objective and real subjective task
63526 + * credentials (COW) */
63527 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63528 +
63529 #ifdef CONFIG_DEBUG_MUTEXES
63530 /* mutex deadlock detection */
63531 struct mutex_waiter *blocked_on;
63532 @@ -1547,6 +1580,27 @@ struct task_struct {
63533 unsigned long default_timer_slack_ns;
63534
63535 struct list_head *scm_work_list;
63536 +
63537 +#ifdef CONFIG_GRKERNSEC
63538 + /* grsecurity */
63539 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63540 + u64 exec_id;
63541 +#endif
63542 +#ifdef CONFIG_GRKERNSEC_SETXID
63543 + const struct cred *delayed_cred;
63544 +#endif
63545 + struct dentry *gr_chroot_dentry;
63546 + struct acl_subject_label *acl;
63547 + struct acl_role_label *role;
63548 + struct file *exec_file;
63549 + u16 acl_role_id;
63550 + /* is this the task that authenticated to the special role */
63551 + u8 acl_sp_role;
63552 + u8 is_writable;
63553 + u8 brute;
63554 + u8 gr_is_chrooted;
63555 +#endif
63556 +
63557 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63558 /* Index of current stored address in ret_stack */
63559 int curr_ret_stack;
63560 @@ -1585,6 +1639,51 @@ struct task_struct {
63561 #endif
63562 };
63563
63564 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63565 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63566 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63567 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63568 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63569 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63570 +
63571 +#ifdef CONFIG_PAX_SOFTMODE
63572 +extern int pax_softmode;
63573 +#endif
63574 +
63575 +extern int pax_check_flags(unsigned long *);
63576 +
63577 +/* if tsk != current then task_lock must be held on it */
63578 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63579 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
63580 +{
63581 + if (likely(tsk->mm))
63582 + return tsk->mm->pax_flags;
63583 + else
63584 + return 0UL;
63585 +}
63586 +
63587 +/* if tsk != current then task_lock must be held on it */
63588 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63589 +{
63590 + if (likely(tsk->mm)) {
63591 + tsk->mm->pax_flags = flags;
63592 + return 0;
63593 + }
63594 + return -EINVAL;
63595 +}
63596 +#endif
63597 +
63598 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63599 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
63600 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63601 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63602 +#endif
63603 +
63604 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63605 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63606 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
63607 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
63608 +
63609 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63610 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63611
63612 @@ -2112,7 +2211,9 @@ void yield(void);
63613 extern struct exec_domain default_exec_domain;
63614
63615 union thread_union {
63616 +#ifndef CONFIG_X86
63617 struct thread_info thread_info;
63618 +#endif
63619 unsigned long stack[THREAD_SIZE/sizeof(long)];
63620 };
63621
63622 @@ -2145,6 +2246,7 @@ extern struct pid_namespace init_pid_ns;
63623 */
63624
63625 extern struct task_struct *find_task_by_vpid(pid_t nr);
63626 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63627 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63628 struct pid_namespace *ns);
63629
63630 @@ -2301,7 +2403,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63631 extern void exit_itimers(struct signal_struct *);
63632 extern void flush_itimer_signals(void);
63633
63634 -extern void do_group_exit(int);
63635 +extern __noreturn void do_group_exit(int);
63636
63637 extern void daemonize(const char *, ...);
63638 extern int allow_signal(int);
63639 @@ -2502,9 +2604,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63640
63641 #endif
63642
63643 -static inline int object_is_on_stack(void *obj)
63644 +static inline int object_starts_on_stack(void *obj)
63645 {
63646 - void *stack = task_stack_page(current);
63647 + const void *stack = task_stack_page(current);
63648
63649 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63650 }
63651 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63652 index 899fbb4..1cb4138 100644
63653 --- a/include/linux/screen_info.h
63654 +++ b/include/linux/screen_info.h
63655 @@ -43,7 +43,8 @@ struct screen_info {
63656 __u16 pages; /* 0x32 */
63657 __u16 vesa_attributes; /* 0x34 */
63658 __u32 capabilities; /* 0x36 */
63659 - __u8 _reserved[6]; /* 0x3a */
63660 + __u16 vesapm_size; /* 0x3a */
63661 + __u8 _reserved[4]; /* 0x3c */
63662 } __attribute__((packed));
63663
63664 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63665 diff --git a/include/linux/security.h b/include/linux/security.h
63666 index 4e5a73c..a5784a1 100644
63667 --- a/include/linux/security.h
63668 +++ b/include/linux/security.h
63669 @@ -26,6 +26,7 @@
63670 #include <linux/capability.h>
63671 #include <linux/slab.h>
63672 #include <linux/err.h>
63673 +#include <linux/grsecurity.h>
63674
63675 struct linux_binprm;
63676 struct cred;
63677 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63678 index fc61854..d7c490b 100644
63679 --- a/include/linux/seq_file.h
63680 +++ b/include/linux/seq_file.h
63681 @@ -25,6 +25,9 @@ struct seq_file {
63682 struct mutex lock;
63683 const struct seq_operations *op;
63684 int poll_event;
63685 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63686 + u64 exec_id;
63687 +#endif
63688 void *private;
63689 };
63690
63691 @@ -34,6 +37,7 @@ struct seq_operations {
63692 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63693 int (*show) (struct seq_file *m, void *v);
63694 };
63695 +typedef struct seq_operations __no_const seq_operations_no_const;
63696
63697 #define SEQ_SKIP 1
63698
63699 diff --git a/include/linux/shm.h b/include/linux/shm.h
63700 index 92808b8..c28cac4 100644
63701 --- a/include/linux/shm.h
63702 +++ b/include/linux/shm.h
63703 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63704
63705 /* The task created the shm object. NULL if the task is dead. */
63706 struct task_struct *shm_creator;
63707 +#ifdef CONFIG_GRKERNSEC
63708 + time_t shm_createtime;
63709 + pid_t shm_lapid;
63710 +#endif
63711 };
63712
63713 /* shm_mode upper byte flags */
63714 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63715 index 642cb73..7ff7f9f 100644
63716 --- a/include/linux/skbuff.h
63717 +++ b/include/linux/skbuff.h
63718 @@ -680,7 +680,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63719 */
63720 static inline int skb_queue_empty(const struct sk_buff_head *list)
63721 {
63722 - return list->next == (struct sk_buff *)list;
63723 + return list->next == (const struct sk_buff *)list;
63724 }
63725
63726 /**
63727 @@ -693,7 +693,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63728 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63729 const struct sk_buff *skb)
63730 {
63731 - return skb->next == (struct sk_buff *)list;
63732 + return skb->next == (const struct sk_buff *)list;
63733 }
63734
63735 /**
63736 @@ -706,7 +706,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63737 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63738 const struct sk_buff *skb)
63739 {
63740 - return skb->prev == (struct sk_buff *)list;
63741 + return skb->prev == (const struct sk_buff *)list;
63742 }
63743
63744 /**
63745 @@ -1605,7 +1605,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63746 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63747 */
63748 #ifndef NET_SKB_PAD
63749 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63750 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63751 #endif
63752
63753 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63754 diff --git a/include/linux/slab.h b/include/linux/slab.h
63755 index 67d5d94..bbd740b 100644
63756 --- a/include/linux/slab.h
63757 +++ b/include/linux/slab.h
63758 @@ -11,12 +11,20 @@
63759
63760 #include <linux/gfp.h>
63761 #include <linux/types.h>
63762 +#include <linux/err.h>
63763
63764 /*
63765 * Flags to pass to kmem_cache_create().
63766 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63767 */
63768 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63769 +
63770 +#ifdef CONFIG_PAX_USERCOPY_SLABS
63771 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63772 +#else
63773 +#define SLAB_USERCOPY 0x00000000UL
63774 +#endif
63775 +
63776 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63777 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63778 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63779 @@ -87,10 +95,13 @@
63780 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63781 * Both make kfree a no-op.
63782 */
63783 -#define ZERO_SIZE_PTR ((void *)16)
63784 +#define ZERO_SIZE_PTR \
63785 +({ \
63786 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63787 + (void *)(-MAX_ERRNO-1L); \
63788 +})
63789
63790 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63791 - (unsigned long)ZERO_SIZE_PTR)
63792 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63793
63794 /*
63795 * struct kmem_cache related prototypes
63796 @@ -161,6 +172,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
63797 void kfree(const void *);
63798 void kzfree(const void *);
63799 size_t ksize(const void *);
63800 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
63801 +bool is_usercopy_object(const void *ptr);
63802
63803 /*
63804 * Allocator specific definitions. These are mainly used to establish optimized
63805 @@ -298,7 +311,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
63806 */
63807 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63808 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63809 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63810 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
63811 #define kmalloc_track_caller(size, flags) \
63812 __kmalloc_track_caller(size, flags, _RET_IP_)
63813 #else
63814 @@ -317,7 +330,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63815 */
63816 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63817 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63818 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
63819 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
63820 #define kmalloc_node_track_caller(size, flags, node) \
63821 __kmalloc_node_track_caller(size, flags, node, \
63822 _RET_IP_)
63823 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
63824 index fbd1117..0a3d314 100644
63825 --- a/include/linux/slab_def.h
63826 +++ b/include/linux/slab_def.h
63827 @@ -66,10 +66,10 @@ struct kmem_cache {
63828 unsigned long node_allocs;
63829 unsigned long node_frees;
63830 unsigned long node_overflow;
63831 - atomic_t allochit;
63832 - atomic_t allocmiss;
63833 - atomic_t freehit;
63834 - atomic_t freemiss;
63835 + atomic_unchecked_t allochit;
63836 + atomic_unchecked_t allocmiss;
63837 + atomic_unchecked_t freehit;
63838 + atomic_unchecked_t freemiss;
63839
63840 /*
63841 * If debugging is enabled, then the allocator can add additional
63842 @@ -103,11 +103,16 @@ struct cache_sizes {
63843 #ifdef CONFIG_ZONE_DMA
63844 struct kmem_cache *cs_dmacachep;
63845 #endif
63846 +
63847 +#ifdef CONFIG_PAX_USERCOPY_SLABS
63848 + struct kmem_cache *cs_usercopycachep;
63849 +#endif
63850 +
63851 };
63852 extern struct cache_sizes malloc_sizes[];
63853
63854 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63855 -void *__kmalloc(size_t size, gfp_t flags);
63856 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63857
63858 #ifdef CONFIG_TRACING
63859 extern void *kmem_cache_alloc_trace(size_t size,
63860 @@ -150,6 +155,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 ret = kmem_cache_alloc_trace(size, cachep, flags);
63874 @@ -160,7 +172,7 @@ found:
63875 }
63876
63877 #ifdef CONFIG_NUMA
63878 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
63879 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63880 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63881
63882 #ifdef CONFIG_TRACING
63883 @@ -203,6 +215,13 @@ found:
63884 cachep = malloc_sizes[i].cs_dmacachep;
63885 else
63886 #endif
63887 +
63888 +#ifdef CONFIG_PAX_USERCOPY_SLABS
63889 + if (flags & GFP_USERCOPY)
63890 + cachep = malloc_sizes[i].cs_usercopycachep;
63891 + else
63892 +#endif
63893 +
63894 cachep = malloc_sizes[i].cs_cachep;
63895
63896 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
63897 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
63898 index 0ec00b3..22b4715 100644
63899 --- a/include/linux/slob_def.h
63900 +++ b/include/linux/slob_def.h
63901 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
63902 return kmem_cache_alloc_node(cachep, flags, -1);
63903 }
63904
63905 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63906 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63907
63908 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63909 {
63910 @@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63911 return __kmalloc_node(size, flags, -1);
63912 }
63913
63914 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
63915 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
63916 {
63917 return kmalloc(size, flags);
63918 }
63919 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
63920 index c2f8c8b..d992a41 100644
63921 --- a/include/linux/slub_def.h
63922 +++ b/include/linux/slub_def.h
63923 @@ -92,7 +92,7 @@ struct kmem_cache {
63924 struct kmem_cache_order_objects max;
63925 struct kmem_cache_order_objects min;
63926 gfp_t allocflags; /* gfp flags to use on each alloc */
63927 - int refcount; /* Refcount for slab cache destroy */
63928 + atomic_t refcount; /* Refcount for slab cache destroy */
63929 void (*ctor)(void *);
63930 int inuse; /* Offset to metadata */
63931 int align; /* Alignment */
63932 @@ -153,7 +153,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
63933 * Sorry that the following has to be that ugly but some versions of GCC
63934 * have trouble with constant propagation and loops.
63935 */
63936 -static __always_inline int kmalloc_index(size_t size)
63937 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
63938 {
63939 if (!size)
63940 return 0;
63941 @@ -218,7 +218,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63942 }
63943
63944 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63945 -void *__kmalloc(size_t size, gfp_t flags);
63946 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
63947
63948 static __always_inline void *
63949 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
63950 @@ -259,7 +259,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
63951 }
63952 #endif
63953
63954 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
63955 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
63956 {
63957 unsigned int order = get_order(size);
63958 return kmalloc_order_trace(size, flags, order);
63959 @@ -284,7 +284,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63960 }
63961
63962 #ifdef CONFIG_NUMA
63963 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63964 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63965 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63966
63967 #ifdef CONFIG_TRACING
63968 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
63969 index de8832d..0147b46 100644
63970 --- a/include/linux/sonet.h
63971 +++ b/include/linux/sonet.h
63972 @@ -61,7 +61,7 @@ struct sonet_stats {
63973 #include <linux/atomic.h>
63974
63975 struct k_sonet_stats {
63976 -#define __HANDLE_ITEM(i) atomic_t i
63977 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
63978 __SONET_ITEMS
63979 #undef __HANDLE_ITEM
63980 };
63981 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
63982 index 523547e..2cb7140 100644
63983 --- a/include/linux/sunrpc/clnt.h
63984 +++ b/include/linux/sunrpc/clnt.h
63985 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
63986 {
63987 switch (sap->sa_family) {
63988 case AF_INET:
63989 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
63990 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
63991 case AF_INET6:
63992 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
63993 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
63994 }
63995 return 0;
63996 }
63997 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
63998 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
63999 const struct sockaddr *src)
64000 {
64001 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64002 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64003 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64004
64005 dsin->sin_family = ssin->sin_family;
64006 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64007 if (sa->sa_family != AF_INET6)
64008 return 0;
64009
64010 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64011 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64012 }
64013
64014 #endif /* __KERNEL__ */
64015 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64016 index dc0c3cc..8503fb6 100644
64017 --- a/include/linux/sunrpc/sched.h
64018 +++ b/include/linux/sunrpc/sched.h
64019 @@ -106,6 +106,7 @@ struct rpc_call_ops {
64020 void (*rpc_count_stats)(struct rpc_task *, void *);
64021 void (*rpc_release)(void *);
64022 };
64023 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64024
64025 struct rpc_task_setup {
64026 struct rpc_task *task;
64027 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64028 index 0b8e3e6..33e0a01 100644
64029 --- a/include/linux/sunrpc/svc_rdma.h
64030 +++ b/include/linux/sunrpc/svc_rdma.h
64031 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64032 extern unsigned int svcrdma_max_requests;
64033 extern unsigned int svcrdma_max_req_size;
64034
64035 -extern atomic_t rdma_stat_recv;
64036 -extern atomic_t rdma_stat_read;
64037 -extern atomic_t rdma_stat_write;
64038 -extern atomic_t rdma_stat_sq_starve;
64039 -extern atomic_t rdma_stat_rq_starve;
64040 -extern atomic_t rdma_stat_rq_poll;
64041 -extern atomic_t rdma_stat_rq_prod;
64042 -extern atomic_t rdma_stat_sq_poll;
64043 -extern atomic_t rdma_stat_sq_prod;
64044 +extern atomic_unchecked_t rdma_stat_recv;
64045 +extern atomic_unchecked_t rdma_stat_read;
64046 +extern atomic_unchecked_t rdma_stat_write;
64047 +extern atomic_unchecked_t rdma_stat_sq_starve;
64048 +extern atomic_unchecked_t rdma_stat_rq_starve;
64049 +extern atomic_unchecked_t rdma_stat_rq_poll;
64050 +extern atomic_unchecked_t rdma_stat_rq_prod;
64051 +extern atomic_unchecked_t rdma_stat_sq_poll;
64052 +extern atomic_unchecked_t rdma_stat_sq_prod;
64053
64054 #define RPCRDMA_VERSION 1
64055
64056 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64057 index c34b4c8..a65b67d 100644
64058 --- a/include/linux/sysctl.h
64059 +++ b/include/linux/sysctl.h
64060 @@ -155,7 +155,11 @@ enum
64061 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64062 };
64063
64064 -
64065 +#ifdef CONFIG_PAX_SOFTMODE
64066 +enum {
64067 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64068 +};
64069 +#endif
64070
64071 /* CTL_VM names: */
64072 enum
64073 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64074
64075 extern int proc_dostring(struct ctl_table *, int,
64076 void __user *, size_t *, loff_t *);
64077 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64078 + void __user *, size_t *, loff_t *);
64079 extern int proc_dointvec(struct ctl_table *, int,
64080 void __user *, size_t *, loff_t *);
64081 extern int proc_dointvec_minmax(struct ctl_table *, int,
64082 diff --git a/include/linux/tty.h b/include/linux/tty.h
64083 index 9f47ab5..73da944 100644
64084 --- a/include/linux/tty.h
64085 +++ b/include/linux/tty.h
64086 @@ -225,7 +225,7 @@ struct tty_port {
64087 const struct tty_port_operations *ops; /* Port operations */
64088 spinlock_t lock; /* Lock protecting tty field */
64089 int blocked_open; /* Waiting to open */
64090 - int count; /* Usage count */
64091 + atomic_t count; /* Usage count */
64092 wait_queue_head_t open_wait; /* Open waiters */
64093 wait_queue_head_t close_wait; /* Close waiters */
64094 wait_queue_head_t delta_msr_wait; /* Modem status change */
64095 @@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64096 struct tty_struct *tty, struct file *filp);
64097 static inline int tty_port_users(struct tty_port *port)
64098 {
64099 - return port->count + port->blocked_open;
64100 + return atomic_read(&port->count) + port->blocked_open;
64101 }
64102
64103 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64104 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64105 index fb79dd8d..07d4773 100644
64106 --- a/include/linux/tty_ldisc.h
64107 +++ b/include/linux/tty_ldisc.h
64108 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64109
64110 struct module *owner;
64111
64112 - int refcount;
64113 + atomic_t refcount;
64114 };
64115
64116 struct tty_ldisc {
64117 diff --git a/include/linux/types.h b/include/linux/types.h
64118 index 9c1bd53..c2370f6 100644
64119 --- a/include/linux/types.h
64120 +++ b/include/linux/types.h
64121 @@ -220,10 +220,26 @@ typedef struct {
64122 int counter;
64123 } atomic_t;
64124
64125 +#ifdef CONFIG_PAX_REFCOUNT
64126 +typedef struct {
64127 + int counter;
64128 +} atomic_unchecked_t;
64129 +#else
64130 +typedef atomic_t atomic_unchecked_t;
64131 +#endif
64132 +
64133 #ifdef CONFIG_64BIT
64134 typedef struct {
64135 long counter;
64136 } atomic64_t;
64137 +
64138 +#ifdef CONFIG_PAX_REFCOUNT
64139 +typedef struct {
64140 + long counter;
64141 +} atomic64_unchecked_t;
64142 +#else
64143 +typedef atomic64_t atomic64_unchecked_t;
64144 +#endif
64145 #endif
64146
64147 struct list_head {
64148 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64149 index 5ca0951..ab496a5 100644
64150 --- a/include/linux/uaccess.h
64151 +++ b/include/linux/uaccess.h
64152 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64153 long ret; \
64154 mm_segment_t old_fs = get_fs(); \
64155 \
64156 - set_fs(KERNEL_DS); \
64157 pagefault_disable(); \
64158 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64159 - pagefault_enable(); \
64160 + set_fs(KERNEL_DS); \
64161 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64162 set_fs(old_fs); \
64163 + pagefault_enable(); \
64164 ret; \
64165 })
64166
64167 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64168 index 99c1b4d..bb94261 100644
64169 --- a/include/linux/unaligned/access_ok.h
64170 +++ b/include/linux/unaligned/access_ok.h
64171 @@ -6,32 +6,32 @@
64172
64173 static inline u16 get_unaligned_le16(const void *p)
64174 {
64175 - return le16_to_cpup((__le16 *)p);
64176 + return le16_to_cpup((const __le16 *)p);
64177 }
64178
64179 static inline u32 get_unaligned_le32(const void *p)
64180 {
64181 - return le32_to_cpup((__le32 *)p);
64182 + return le32_to_cpup((const __le32 *)p);
64183 }
64184
64185 static inline u64 get_unaligned_le64(const void *p)
64186 {
64187 - return le64_to_cpup((__le64 *)p);
64188 + return le64_to_cpup((const __le64 *)p);
64189 }
64190
64191 static inline u16 get_unaligned_be16(const void *p)
64192 {
64193 - return be16_to_cpup((__be16 *)p);
64194 + return be16_to_cpup((const __be16 *)p);
64195 }
64196
64197 static inline u32 get_unaligned_be32(const void *p)
64198 {
64199 - return be32_to_cpup((__be32 *)p);
64200 + return be32_to_cpup((const __be32 *)p);
64201 }
64202
64203 static inline u64 get_unaligned_be64(const void *p)
64204 {
64205 - return be64_to_cpup((__be64 *)p);
64206 + return be64_to_cpup((const __be64 *)p);
64207 }
64208
64209 static inline void put_unaligned_le16(u16 val, void *p)
64210 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64211 index 547e59c..db6ad19 100644
64212 --- a/include/linux/usb/renesas_usbhs.h
64213 +++ b/include/linux/usb/renesas_usbhs.h
64214 @@ -39,7 +39,7 @@ enum {
64215 */
64216 struct renesas_usbhs_driver_callback {
64217 int (*notify_hotplug)(struct platform_device *pdev);
64218 -};
64219 +} __no_const;
64220
64221 /*
64222 * callback functions for platform
64223 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64224 * VBUS control is needed for Host
64225 */
64226 int (*set_vbus)(struct platform_device *pdev, int enable);
64227 -};
64228 +} __no_const;
64229
64230 /*
64231 * parameters for renesas usbhs
64232 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64233 index 6f8fbcf..8259001 100644
64234 --- a/include/linux/vermagic.h
64235 +++ b/include/linux/vermagic.h
64236 @@ -25,9 +25,35 @@
64237 #define MODULE_ARCH_VERMAGIC ""
64238 #endif
64239
64240 +#ifdef CONFIG_PAX_REFCOUNT
64241 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
64242 +#else
64243 +#define MODULE_PAX_REFCOUNT ""
64244 +#endif
64245 +
64246 +#ifdef CONSTIFY_PLUGIN
64247 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64248 +#else
64249 +#define MODULE_CONSTIFY_PLUGIN ""
64250 +#endif
64251 +
64252 +#ifdef STACKLEAK_PLUGIN
64253 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64254 +#else
64255 +#define MODULE_STACKLEAK_PLUGIN ""
64256 +#endif
64257 +
64258 +#ifdef CONFIG_GRKERNSEC
64259 +#define MODULE_GRSEC "GRSEC "
64260 +#else
64261 +#define MODULE_GRSEC ""
64262 +#endif
64263 +
64264 #define VERMAGIC_STRING \
64265 UTS_RELEASE " " \
64266 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64267 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64268 - MODULE_ARCH_VERMAGIC
64269 + MODULE_ARCH_VERMAGIC \
64270 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64271 + MODULE_GRSEC
64272
64273 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64274 index dcdfc2b..ec79ab5 100644
64275 --- a/include/linux/vmalloc.h
64276 +++ b/include/linux/vmalloc.h
64277 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64278 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64279 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64280 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64281 +
64282 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64283 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64284 +#endif
64285 +
64286 /* bits [20..32] reserved for arch specific ioremap internals */
64287
64288 /*
64289 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64290 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64291 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64292 unsigned long start, unsigned long end, gfp_t gfp_mask,
64293 - pgprot_t prot, int node, void *caller);
64294 + pgprot_t prot, int node, void *caller) __size_overflow(1);
64295 extern void vfree(const void *addr);
64296
64297 extern void *vmap(struct page **pages, unsigned int count,
64298 @@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64299 extern void free_vm_area(struct vm_struct *area);
64300
64301 /* for /dev/kmem */
64302 -extern long vread(char *buf, char *addr, unsigned long count);
64303 -extern long vwrite(char *buf, char *addr, unsigned long count);
64304 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64305 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64306
64307 /*
64308 * Internals. Dont't use..
64309 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64310 index 65efb92..137adbb 100644
64311 --- a/include/linux/vmstat.h
64312 +++ b/include/linux/vmstat.h
64313 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64314 /*
64315 * Zone based page accounting with per cpu differentials.
64316 */
64317 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64318 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64319
64320 static inline void zone_page_state_add(long x, struct zone *zone,
64321 enum zone_stat_item item)
64322 {
64323 - atomic_long_add(x, &zone->vm_stat[item]);
64324 - atomic_long_add(x, &vm_stat[item]);
64325 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64326 + atomic_long_add_unchecked(x, &vm_stat[item]);
64327 }
64328
64329 static inline unsigned long global_page_state(enum zone_stat_item item)
64330 {
64331 - long x = atomic_long_read(&vm_stat[item]);
64332 + long x = atomic_long_read_unchecked(&vm_stat[item]);
64333 #ifdef CONFIG_SMP
64334 if (x < 0)
64335 x = 0;
64336 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64337 static inline unsigned long zone_page_state(struct zone *zone,
64338 enum zone_stat_item item)
64339 {
64340 - long x = atomic_long_read(&zone->vm_stat[item]);
64341 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64342 #ifdef CONFIG_SMP
64343 if (x < 0)
64344 x = 0;
64345 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64346 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64347 enum zone_stat_item item)
64348 {
64349 - long x = atomic_long_read(&zone->vm_stat[item]);
64350 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64351
64352 #ifdef CONFIG_SMP
64353 int cpu;
64354 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64355
64356 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64357 {
64358 - atomic_long_inc(&zone->vm_stat[item]);
64359 - atomic_long_inc(&vm_stat[item]);
64360 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64361 + atomic_long_inc_unchecked(&vm_stat[item]);
64362 }
64363
64364 static inline void __inc_zone_page_state(struct page *page,
64365 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
64366
64367 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64368 {
64369 - atomic_long_dec(&zone->vm_stat[item]);
64370 - atomic_long_dec(&vm_stat[item]);
64371 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64372 + atomic_long_dec_unchecked(&vm_stat[item]);
64373 }
64374
64375 static inline void __dec_zone_page_state(struct page *page,
64376 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64377 index e5d1220..ef6e406 100644
64378 --- a/include/linux/xattr.h
64379 +++ b/include/linux/xattr.h
64380 @@ -57,6 +57,11 @@
64381 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64382 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64383
64384 +/* User namespace */
64385 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64386 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
64387 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64388 +
64389 #ifdef __KERNEL__
64390
64391 #include <linux/types.h>
64392 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64393 index 944ecdf..a3994fc 100644
64394 --- a/include/media/saa7146_vv.h
64395 +++ b/include/media/saa7146_vv.h
64396 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
64397 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64398
64399 /* the extension can override this */
64400 - struct v4l2_ioctl_ops vid_ops;
64401 - struct v4l2_ioctl_ops vbi_ops;
64402 + v4l2_ioctl_ops_no_const vid_ops;
64403 + v4l2_ioctl_ops_no_const vbi_ops;
64404 /* pointer to the saa7146 core ops */
64405 const struct v4l2_ioctl_ops *core_ops;
64406
64407 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64408 index a056e6e..31023a5 100644
64409 --- a/include/media/v4l2-dev.h
64410 +++ b/include/media/v4l2-dev.h
64411 @@ -73,7 +73,8 @@ struct v4l2_file_operations {
64412 int (*mmap) (struct file *, struct vm_area_struct *);
64413 int (*open) (struct file *);
64414 int (*release) (struct file *);
64415 -};
64416 +} __do_const;
64417 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64418
64419 /*
64420 * Newer version of video_device, handled by videodev2.c
64421 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64422 index d8b76f7..7d5aa18 100644
64423 --- a/include/media/v4l2-ioctl.h
64424 +++ b/include/media/v4l2-ioctl.h
64425 @@ -287,7 +287,7 @@ struct v4l2_ioctl_ops {
64426 long (*vidioc_default) (struct file *file, void *fh,
64427 bool valid_prio, int cmd, void *arg);
64428 };
64429 -
64430 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64431
64432 /* v4l debugging and diagnostics */
64433
64434 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64435 index 439dadc..1c67e3f 100644
64436 --- a/include/net/caif/caif_hsi.h
64437 +++ b/include/net/caif/caif_hsi.h
64438 @@ -98,7 +98,7 @@ struct cfhsi_drv {
64439 void (*rx_done_cb) (struct cfhsi_drv *drv);
64440 void (*wake_up_cb) (struct cfhsi_drv *drv);
64441 void (*wake_down_cb) (struct cfhsi_drv *drv);
64442 -};
64443 +} __no_const;
64444
64445 /* Structure implemented by HSI device. */
64446 struct cfhsi_dev {
64447 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64448 index 9e5425b..8136ffc 100644
64449 --- a/include/net/caif/cfctrl.h
64450 +++ b/include/net/caif/cfctrl.h
64451 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
64452 void (*radioset_rsp)(void);
64453 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64454 struct cflayer *client_layer);
64455 -};
64456 +} __no_const;
64457
64458 /* Link Setup Parameters for CAIF-Links. */
64459 struct cfctrl_link_param {
64460 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
64461 struct cfctrl {
64462 struct cfsrvl serv;
64463 struct cfctrl_rsp res;
64464 - atomic_t req_seq_no;
64465 - atomic_t rsp_seq_no;
64466 + atomic_unchecked_t req_seq_no;
64467 + atomic_unchecked_t rsp_seq_no;
64468 struct list_head list;
64469 /* Protects from simultaneous access to first_req list */
64470 spinlock_t info_list_lock;
64471 diff --git a/include/net/flow.h b/include/net/flow.h
64472 index 6c469db..7743b8e 100644
64473 --- a/include/net/flow.h
64474 +++ b/include/net/flow.h
64475 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64476
64477 extern void flow_cache_flush(void);
64478 extern void flow_cache_flush_deferred(void);
64479 -extern atomic_t flow_cache_genid;
64480 +extern atomic_unchecked_t flow_cache_genid;
64481
64482 #endif
64483 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64484 index 2040bff..f4c0733 100644
64485 --- a/include/net/inetpeer.h
64486 +++ b/include/net/inetpeer.h
64487 @@ -51,8 +51,8 @@ struct inet_peer {
64488 */
64489 union {
64490 struct {
64491 - atomic_t rid; /* Frag reception counter */
64492 - atomic_t ip_id_count; /* IP ID for the next packet */
64493 + atomic_unchecked_t rid; /* Frag reception counter */
64494 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64495 __u32 tcp_ts;
64496 __u32 tcp_ts_stamp;
64497 };
64498 @@ -118,11 +118,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64499 more++;
64500 inet_peer_refcheck(p);
64501 do {
64502 - old = atomic_read(&p->ip_id_count);
64503 + old = atomic_read_unchecked(&p->ip_id_count);
64504 new = old + more;
64505 if (!new)
64506 new = 1;
64507 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64508 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64509 return new;
64510 }
64511
64512 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64513 index 78df0866..00e5c9b 100644
64514 --- a/include/net/ip_fib.h
64515 +++ b/include/net/ip_fib.h
64516 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64517
64518 #define FIB_RES_SADDR(net, res) \
64519 ((FIB_RES_NH(res).nh_saddr_genid == \
64520 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64521 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64522 FIB_RES_NH(res).nh_saddr : \
64523 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64524 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64525 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64526 index 95374d1..2300e36 100644
64527 --- a/include/net/ip_vs.h
64528 +++ b/include/net/ip_vs.h
64529 @@ -510,7 +510,7 @@ struct ip_vs_conn {
64530 struct ip_vs_conn *control; /* Master control connection */
64531 atomic_t n_control; /* Number of controlled ones */
64532 struct ip_vs_dest *dest; /* real server */
64533 - atomic_t in_pkts; /* incoming packet counter */
64534 + atomic_unchecked_t in_pkts; /* incoming packet counter */
64535
64536 /* packet transmitter for different forwarding methods. If it
64537 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64538 @@ -648,7 +648,7 @@ struct ip_vs_dest {
64539 __be16 port; /* port number of the server */
64540 union nf_inet_addr addr; /* IP address of the server */
64541 volatile unsigned int flags; /* dest status flags */
64542 - atomic_t conn_flags; /* flags to copy to conn */
64543 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
64544 atomic_t weight; /* server weight */
64545
64546 atomic_t refcnt; /* reference counter */
64547 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64548 index 69b610a..fe3962c 100644
64549 --- a/include/net/irda/ircomm_core.h
64550 +++ b/include/net/irda/ircomm_core.h
64551 @@ -51,7 +51,7 @@ typedef struct {
64552 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64553 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64554 struct ircomm_info *);
64555 -} call_t;
64556 +} __no_const call_t;
64557
64558 struct ircomm_cb {
64559 irda_queue_t queue;
64560 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64561 index 59ba38bc..d515662 100644
64562 --- a/include/net/irda/ircomm_tty.h
64563 +++ b/include/net/irda/ircomm_tty.h
64564 @@ -35,6 +35,7 @@
64565 #include <linux/termios.h>
64566 #include <linux/timer.h>
64567 #include <linux/tty.h> /* struct tty_struct */
64568 +#include <asm/local.h>
64569
64570 #include <net/irda/irias_object.h>
64571 #include <net/irda/ircomm_core.h>
64572 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64573 unsigned short close_delay;
64574 unsigned short closing_wait; /* time to wait before closing */
64575
64576 - int open_count;
64577 - int blocked_open; /* # of blocked opens */
64578 + local_t open_count;
64579 + local_t blocked_open; /* # of blocked opens */
64580
64581 /* Protect concurent access to :
64582 * o self->open_count
64583 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64584 index cc7c197..9f2da2a 100644
64585 --- a/include/net/iucv/af_iucv.h
64586 +++ b/include/net/iucv/af_iucv.h
64587 @@ -141,7 +141,7 @@ struct iucv_sock {
64588 struct iucv_sock_list {
64589 struct hlist_head head;
64590 rwlock_t lock;
64591 - atomic_t autobind_name;
64592 + atomic_unchecked_t autobind_name;
64593 };
64594
64595 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64596 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64597 index 6cdfeed..55a0256 100644
64598 --- a/include/net/neighbour.h
64599 +++ b/include/net/neighbour.h
64600 @@ -123,7 +123,7 @@ struct neigh_ops {
64601 void (*error_report)(struct neighbour *, struct sk_buff *);
64602 int (*output)(struct neighbour *, struct sk_buff *);
64603 int (*connected_output)(struct neighbour *, struct sk_buff *);
64604 -};
64605 +} __do_const;
64606
64607 struct pneigh_entry {
64608 struct pneigh_entry *next;
64609 diff --git a/include/net/netlink.h b/include/net/netlink.h
64610 index 785f37a..c81dc0c 100644
64611 --- a/include/net/netlink.h
64612 +++ b/include/net/netlink.h
64613 @@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64614 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64615 {
64616 if (mark)
64617 - skb_trim(skb, (unsigned char *) mark - skb->data);
64618 + skb_trim(skb, (const unsigned char *) mark - skb->data);
64619 }
64620
64621 /**
64622 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64623 index bbd023a..97c6d0d 100644
64624 --- a/include/net/netns/ipv4.h
64625 +++ b/include/net/netns/ipv4.h
64626 @@ -57,8 +57,8 @@ struct netns_ipv4 {
64627 unsigned int sysctl_ping_group_range[2];
64628 long sysctl_tcp_mem[3];
64629
64630 - atomic_t rt_genid;
64631 - atomic_t dev_addr_genid;
64632 + atomic_unchecked_t rt_genid;
64633 + atomic_unchecked_t dev_addr_genid;
64634
64635 #ifdef CONFIG_IP_MROUTE
64636 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64637 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64638 index a2ef814..31a8e3f 100644
64639 --- a/include/net/sctp/sctp.h
64640 +++ b/include/net/sctp/sctp.h
64641 @@ -318,9 +318,9 @@ do { \
64642
64643 #else /* SCTP_DEBUG */
64644
64645 -#define SCTP_DEBUG_PRINTK(whatever...)
64646 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64647 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64648 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64649 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64650 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64651 #define SCTP_ENABLE_DEBUG
64652 #define SCTP_DISABLE_DEBUG
64653 #define SCTP_ASSERT(expr, str, func)
64654 diff --git a/include/net/sock.h b/include/net/sock.h
64655 index 4a45216..7af2578 100644
64656 --- a/include/net/sock.h
64657 +++ b/include/net/sock.h
64658 @@ -303,7 +303,7 @@ struct sock {
64659 #ifdef CONFIG_RPS
64660 __u32 sk_rxhash;
64661 #endif
64662 - atomic_t sk_drops;
64663 + atomic_unchecked_t sk_drops;
64664 int sk_rcvbuf;
64665
64666 struct sk_filter __rcu *sk_filter;
64667 @@ -1726,7 +1726,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
64668 }
64669
64670 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64671 - char __user *from, char *to,
64672 + char __user *from, unsigned char *to,
64673 int copy, int offset)
64674 {
64675 if (skb->ip_summed == CHECKSUM_NONE) {
64676 diff --git a/include/net/tcp.h b/include/net/tcp.h
64677 index e79aa48..9929421 100644
64678 --- a/include/net/tcp.h
64679 +++ b/include/net/tcp.h
64680 @@ -1459,7 +1459,7 @@ struct tcp_seq_afinfo {
64681 char *name;
64682 sa_family_t family;
64683 const struct file_operations *seq_fops;
64684 - struct seq_operations seq_ops;
64685 + seq_operations_no_const seq_ops;
64686 };
64687
64688 struct tcp_iter_state {
64689 diff --git a/include/net/udp.h b/include/net/udp.h
64690 index 065f379..b661b40 100644
64691 --- a/include/net/udp.h
64692 +++ b/include/net/udp.h
64693 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
64694 sa_family_t family;
64695 struct udp_table *udp_table;
64696 const struct file_operations *seq_fops;
64697 - struct seq_operations seq_ops;
64698 + seq_operations_no_const seq_ops;
64699 };
64700
64701 struct udp_iter_state {
64702 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64703 index e0a55df..5890bca07 100644
64704 --- a/include/net/xfrm.h
64705 +++ b/include/net/xfrm.h
64706 @@ -505,7 +505,7 @@ struct xfrm_policy {
64707 struct timer_list timer;
64708
64709 struct flow_cache_object flo;
64710 - atomic_t genid;
64711 + atomic_unchecked_t genid;
64712 u32 priority;
64713 u32 index;
64714 struct xfrm_mark mark;
64715 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64716 index 1a046b1..ee0bef0 100644
64717 --- a/include/rdma/iw_cm.h
64718 +++ b/include/rdma/iw_cm.h
64719 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
64720 int backlog);
64721
64722 int (*destroy_listen)(struct iw_cm_id *cm_id);
64723 -};
64724 +} __no_const;
64725
64726 /**
64727 * iw_create_cm_id - Create an IW CM identifier.
64728 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64729 index 8f9dfba..610ab6c 100644
64730 --- a/include/scsi/libfc.h
64731 +++ b/include/scsi/libfc.h
64732 @@ -756,6 +756,7 @@ struct libfc_function_template {
64733 */
64734 void (*disc_stop_final) (struct fc_lport *);
64735 };
64736 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64737
64738 /**
64739 * struct fc_disc - Discovery context
64740 @@ -861,7 +862,7 @@ struct fc_lport {
64741 struct fc_vport *vport;
64742
64743 /* Operational Information */
64744 - struct libfc_function_template tt;
64745 + libfc_function_template_no_const tt;
64746 u8 link_up;
64747 u8 qfull;
64748 enum fc_lport_state state;
64749 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64750 index ba96988..ecf2eb9 100644
64751 --- a/include/scsi/scsi_device.h
64752 +++ b/include/scsi/scsi_device.h
64753 @@ -163,9 +163,9 @@ struct scsi_device {
64754 unsigned int max_device_blocked; /* what device_blocked counts down from */
64755 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64756
64757 - atomic_t iorequest_cnt;
64758 - atomic_t iodone_cnt;
64759 - atomic_t ioerr_cnt;
64760 + atomic_unchecked_t iorequest_cnt;
64761 + atomic_unchecked_t iodone_cnt;
64762 + atomic_unchecked_t ioerr_cnt;
64763
64764 struct device sdev_gendev,
64765 sdev_dev;
64766 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64767 index 719faf1..07b6728 100644
64768 --- a/include/scsi/scsi_transport_fc.h
64769 +++ b/include/scsi/scsi_transport_fc.h
64770 @@ -739,7 +739,8 @@ struct fc_function_template {
64771 unsigned long show_host_system_hostname:1;
64772
64773 unsigned long disable_target_scan:1;
64774 -};
64775 +} __do_const;
64776 +typedef struct fc_function_template __no_const fc_function_template_no_const;
64777
64778
64779 /**
64780 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64781 index 030b87c..98a6954 100644
64782 --- a/include/sound/ak4xxx-adda.h
64783 +++ b/include/sound/ak4xxx-adda.h
64784 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64785 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64786 unsigned char val);
64787 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64788 -};
64789 +} __no_const;
64790
64791 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64792
64793 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64794 index 8c05e47..2b5df97 100644
64795 --- a/include/sound/hwdep.h
64796 +++ b/include/sound/hwdep.h
64797 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
64798 struct snd_hwdep_dsp_status *status);
64799 int (*dsp_load)(struct snd_hwdep *hw,
64800 struct snd_hwdep_dsp_image *image);
64801 -};
64802 +} __no_const;
64803
64804 struct snd_hwdep {
64805 struct snd_card *card;
64806 diff --git a/include/sound/info.h b/include/sound/info.h
64807 index 9ca1a49..aba1728 100644
64808 --- a/include/sound/info.h
64809 +++ b/include/sound/info.h
64810 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
64811 struct snd_info_buffer *buffer);
64812 void (*write)(struct snd_info_entry *entry,
64813 struct snd_info_buffer *buffer);
64814 -};
64815 +} __no_const;
64816
64817 struct snd_info_entry_ops {
64818 int (*open)(struct snd_info_entry *entry,
64819 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
64820 index 0d11128..814178e 100644
64821 --- a/include/sound/pcm.h
64822 +++ b/include/sound/pcm.h
64823 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
64824 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
64825 int (*ack)(struct snd_pcm_substream *substream);
64826 };
64827 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
64828
64829 /*
64830 *
64831 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
64832 index af1b49e..a5d55a5 100644
64833 --- a/include/sound/sb16_csp.h
64834 +++ b/include/sound/sb16_csp.h
64835 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
64836 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
64837 int (*csp_stop) (struct snd_sb_csp * p);
64838 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
64839 -};
64840 +} __no_const;
64841
64842 /*
64843 * CSP private data
64844 diff --git a/include/sound/soc.h b/include/sound/soc.h
64845 index c703871..f7fbbbd 100644
64846 --- a/include/sound/soc.h
64847 +++ b/include/sound/soc.h
64848 @@ -757,7 +757,7 @@ struct snd_soc_platform_driver {
64849 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
64850 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
64851 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
64852 -};
64853 +} __do_const;
64854
64855 struct snd_soc_platform {
64856 const char *name;
64857 @@ -949,7 +949,7 @@ struct snd_soc_pcm_runtime {
64858 struct snd_soc_dai_link *dai_link;
64859 struct mutex pcm_mutex;
64860 enum snd_soc_pcm_subclass pcm_subclass;
64861 - struct snd_pcm_ops ops;
64862 + snd_pcm_ops_no_const ops;
64863
64864 unsigned int dev_registered:1;
64865
64866 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
64867 index 0c3c2fb..d9d9990 100644
64868 --- a/include/sound/tea575x-tuner.h
64869 +++ b/include/sound/tea575x-tuner.h
64870 @@ -44,7 +44,7 @@ struct snd_tea575x_ops {
64871
64872 struct snd_tea575x {
64873 struct v4l2_device *v4l2_dev;
64874 - struct v4l2_file_operations fops;
64875 + v4l2_file_operations_no_const fops;
64876 struct video_device vd; /* video device */
64877 int radio_nr; /* radio_nr */
64878 bool tea5759; /* 5759 chip is present */
64879 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
64880 index 4119966..1a4671c 100644
64881 --- a/include/sound/ymfpci.h
64882 +++ b/include/sound/ymfpci.h
64883 @@ -358,7 +358,7 @@ struct snd_ymfpci {
64884 spinlock_t reg_lock;
64885 spinlock_t voice_lock;
64886 wait_queue_head_t interrupt_sleep;
64887 - atomic_t interrupt_sleep_count;
64888 + atomic_unchecked_t interrupt_sleep_count;
64889 struct snd_info_entry *proc_entry;
64890 const struct firmware *dsp_microcode;
64891 const struct firmware *controller_microcode;
64892 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
64893 index 362e0d9..36b9a83 100644
64894 --- a/include/target/target_core_base.h
64895 +++ b/include/target/target_core_base.h
64896 @@ -441,7 +441,7 @@ struct t10_reservation_ops {
64897 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
64898 int (*t10_pr_register)(struct se_cmd *);
64899 int (*t10_pr_clear)(struct se_cmd *);
64900 -};
64901 +} __no_const;
64902
64903 struct t10_reservation {
64904 /* Reservation effects all target ports */
64905 @@ -780,7 +780,7 @@ struct se_device {
64906 spinlock_t stats_lock;
64907 /* Active commands on this virtual SE device */
64908 atomic_t simple_cmds;
64909 - atomic_t dev_ordered_id;
64910 + atomic_unchecked_t dev_ordered_id;
64911 atomic_t execute_tasks;
64912 atomic_t dev_ordered_sync;
64913 atomic_t dev_qf_count;
64914 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
64915 new file mode 100644
64916 index 0000000..2efe49d
64917 --- /dev/null
64918 +++ b/include/trace/events/fs.h
64919 @@ -0,0 +1,53 @@
64920 +#undef TRACE_SYSTEM
64921 +#define TRACE_SYSTEM fs
64922 +
64923 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
64924 +#define _TRACE_FS_H
64925 +
64926 +#include <linux/fs.h>
64927 +#include <linux/tracepoint.h>
64928 +
64929 +TRACE_EVENT(do_sys_open,
64930 +
64931 + TP_PROTO(char *filename, int flags, int mode),
64932 +
64933 + TP_ARGS(filename, flags, mode),
64934 +
64935 + TP_STRUCT__entry(
64936 + __string( filename, filename )
64937 + __field( int, flags )
64938 + __field( int, mode )
64939 + ),
64940 +
64941 + TP_fast_assign(
64942 + __assign_str(filename, filename);
64943 + __entry->flags = flags;
64944 + __entry->mode = mode;
64945 + ),
64946 +
64947 + TP_printk("\"%s\" %x %o",
64948 + __get_str(filename), __entry->flags, __entry->mode)
64949 +);
64950 +
64951 +TRACE_EVENT(open_exec,
64952 +
64953 + TP_PROTO(const char *filename),
64954 +
64955 + TP_ARGS(filename),
64956 +
64957 + TP_STRUCT__entry(
64958 + __string( filename, filename )
64959 + ),
64960 +
64961 + TP_fast_assign(
64962 + __assign_str(filename, filename);
64963 + ),
64964 +
64965 + TP_printk("\"%s\"",
64966 + __get_str(filename))
64967 +);
64968 +
64969 +#endif /* _TRACE_FS_H */
64970 +
64971 +/* This part must be outside protection */
64972 +#include <trace/define_trace.h>
64973 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
64974 index 1c09820..7f5ec79 100644
64975 --- a/include/trace/events/irq.h
64976 +++ b/include/trace/events/irq.h
64977 @@ -36,7 +36,7 @@ struct softirq_action;
64978 */
64979 TRACE_EVENT(irq_handler_entry,
64980
64981 - TP_PROTO(int irq, struct irqaction *action),
64982 + TP_PROTO(int irq, const struct irqaction *action),
64983
64984 TP_ARGS(irq, action),
64985
64986 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
64987 */
64988 TRACE_EVENT(irq_handler_exit,
64989
64990 - TP_PROTO(int irq, struct irqaction *action, int ret),
64991 + TP_PROTO(int irq, const struct irqaction *action, int ret),
64992
64993 TP_ARGS(irq, action, ret),
64994
64995 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
64996 index f9466fa..f4e2b81 100644
64997 --- a/include/video/udlfb.h
64998 +++ b/include/video/udlfb.h
64999 @@ -53,10 +53,10 @@ struct dlfb_data {
65000 u32 pseudo_palette[256];
65001 int blank_mode; /*one of FB_BLANK_ */
65002 /* blit-only rendering path metrics, exposed through sysfs */
65003 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65004 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65005 - atomic_t bytes_sent; /* to usb, after compression including overhead */
65006 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65007 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65008 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65009 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65010 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65011 };
65012
65013 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65014 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65015 index 0993a22..32ba2fe 100644
65016 --- a/include/video/uvesafb.h
65017 +++ b/include/video/uvesafb.h
65018 @@ -177,6 +177,7 @@ struct uvesafb_par {
65019 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65020 u8 pmi_setpal; /* PMI for palette changes */
65021 u16 *pmi_base; /* protected mode interface location */
65022 + u8 *pmi_code; /* protected mode code location */
65023 void *pmi_start;
65024 void *pmi_pal;
65025 u8 *vbe_state_orig; /*
65026 diff --git a/init/Kconfig b/init/Kconfig
65027 index d07dcf9..fa47d0e 100644
65028 --- a/init/Kconfig
65029 +++ b/init/Kconfig
65030 @@ -835,6 +835,7 @@ endif # CGROUPS
65031
65032 config CHECKPOINT_RESTORE
65033 bool "Checkpoint/restore support" if EXPERT
65034 + depends on !GRKERNSEC
65035 default n
65036 help
65037 Enables additional kernel features in a sake of checkpoint/restore.
65038 @@ -1014,6 +1015,7 @@ config UIDGID_CONVERTED
65039 # Security modules
65040 depends on SECURITY_TOMOYO = n
65041 depends on SECURITY_APPARMOR = n
65042 + depends on GRKERNSEC = n
65043
65044 config UIDGID_STRICT_TYPE_CHECKS
65045 bool "Require conversions between uid/gids and their internal representation"
65046 @@ -1401,7 +1403,7 @@ config SLUB_DEBUG
65047
65048 config COMPAT_BRK
65049 bool "Disable heap randomization"
65050 - default y
65051 + default n
65052 help
65053 Randomizing heap placement makes heap exploits harder, but it
65054 also breaks ancient binaries (including anything libc5 based).
65055 @@ -1584,7 +1586,7 @@ config INIT_ALL_POSSIBLE
65056 config STOP_MACHINE
65057 bool
65058 default y
65059 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65060 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65061 help
65062 Need stop_machine() primitive.
65063
65064 diff --git a/init/Makefile b/init/Makefile
65065 index 7bc47ee..6da2dc7 100644
65066 --- a/init/Makefile
65067 +++ b/init/Makefile
65068 @@ -2,6 +2,9 @@
65069 # Makefile for the linux kernel.
65070 #
65071
65072 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
65073 +asflags-y := $(GCC_PLUGINS_AFLAGS)
65074 +
65075 obj-y := main.o version.o mounts.o
65076 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65077 obj-y += noinitramfs.o
65078 diff --git a/init/do_mounts.c b/init/do_mounts.c
65079 index d3f0aee..c9322f5 100644
65080 --- a/init/do_mounts.c
65081 +++ b/init/do_mounts.c
65082 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65083 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65084 {
65085 struct super_block *s;
65086 - int err = sys_mount(name, "/root", fs, flags, data);
65087 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65088 if (err)
65089 return err;
65090
65091 - sys_chdir("/root");
65092 + sys_chdir((const char __force_user *)"/root");
65093 s = current->fs->pwd.dentry->d_sb;
65094 ROOT_DEV = s->s_dev;
65095 printk(KERN_INFO
65096 @@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65097 va_start(args, fmt);
65098 vsprintf(buf, fmt, args);
65099 va_end(args);
65100 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65101 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65102 if (fd >= 0) {
65103 sys_ioctl(fd, FDEJECT, 0);
65104 sys_close(fd);
65105 }
65106 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65107 - fd = sys_open("/dev/console", O_RDWR, 0);
65108 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65109 if (fd >= 0) {
65110 sys_ioctl(fd, TCGETS, (long)&termios);
65111 termios.c_lflag &= ~ICANON;
65112 sys_ioctl(fd, TCSETSF, (long)&termios);
65113 - sys_read(fd, &c, 1);
65114 + sys_read(fd, (char __user *)&c, 1);
65115 termios.c_lflag |= ICANON;
65116 sys_ioctl(fd, TCSETSF, (long)&termios);
65117 sys_close(fd);
65118 @@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65119 mount_root();
65120 out:
65121 devtmpfs_mount("dev");
65122 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65123 - sys_chroot(".");
65124 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65125 + sys_chroot((const char __force_user *)".");
65126 }
65127 diff --git a/init/do_mounts.h b/init/do_mounts.h
65128 index f5b978a..69dbfe8 100644
65129 --- a/init/do_mounts.h
65130 +++ b/init/do_mounts.h
65131 @@ -15,15 +15,15 @@ extern int root_mountflags;
65132
65133 static inline int create_dev(char *name, dev_t dev)
65134 {
65135 - sys_unlink(name);
65136 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65137 + sys_unlink((char __force_user *)name);
65138 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65139 }
65140
65141 #if BITS_PER_LONG == 32
65142 static inline u32 bstat(char *name)
65143 {
65144 struct stat64 stat;
65145 - if (sys_stat64(name, &stat) != 0)
65146 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65147 return 0;
65148 if (!S_ISBLK(stat.st_mode))
65149 return 0;
65150 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65151 static inline u32 bstat(char *name)
65152 {
65153 struct stat stat;
65154 - if (sys_newstat(name, &stat) != 0)
65155 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65156 return 0;
65157 if (!S_ISBLK(stat.st_mode))
65158 return 0;
65159 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65160 index 135959a2..28a3f43 100644
65161 --- a/init/do_mounts_initrd.c
65162 +++ b/init/do_mounts_initrd.c
65163 @@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65164 create_dev("/dev/root.old", Root_RAM0);
65165 /* mount initrd on rootfs' /root */
65166 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65167 - sys_mkdir("/old", 0700);
65168 - root_fd = sys_open("/", 0, 0);
65169 - old_fd = sys_open("/old", 0, 0);
65170 + sys_mkdir((const char __force_user *)"/old", 0700);
65171 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
65172 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65173 /* move initrd over / and chdir/chroot in initrd root */
65174 - sys_chdir("/root");
65175 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65176 - sys_chroot(".");
65177 + sys_chdir((const char __force_user *)"/root");
65178 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65179 + sys_chroot((const char __force_user *)".");
65180
65181 /*
65182 * In case that a resume from disk is carried out by linuxrc or one of
65183 @@ -76,15 +76,15 @@ static void __init handle_initrd(void)
65184
65185 /* move initrd to rootfs' /old */
65186 sys_fchdir(old_fd);
65187 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
65188 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65189 /* switch root and cwd back to / of rootfs */
65190 sys_fchdir(root_fd);
65191 - sys_chroot(".");
65192 + sys_chroot((const char __force_user *)".");
65193 sys_close(old_fd);
65194 sys_close(root_fd);
65195
65196 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65197 - sys_chdir("/old");
65198 + sys_chdir((const char __force_user *)"/old");
65199 return;
65200 }
65201
65202 @@ -92,17 +92,17 @@ static void __init handle_initrd(void)
65203 mount_root();
65204
65205 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65206 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65207 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65208 if (!error)
65209 printk("okay\n");
65210 else {
65211 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
65212 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65213 if (error == -ENOENT)
65214 printk("/initrd does not exist. Ignored.\n");
65215 else
65216 printk("failed\n");
65217 printk(KERN_NOTICE "Unmounting old root\n");
65218 - sys_umount("/old", MNT_DETACH);
65219 + sys_umount((char __force_user *)"/old", MNT_DETACH);
65220 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65221 if (fd < 0) {
65222 error = fd;
65223 @@ -125,11 +125,11 @@ int __init initrd_load(void)
65224 * mounted in the normal path.
65225 */
65226 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65227 - sys_unlink("/initrd.image");
65228 + sys_unlink((const char __force_user *)"/initrd.image");
65229 handle_initrd();
65230 return 1;
65231 }
65232 }
65233 - sys_unlink("/initrd.image");
65234 + sys_unlink((const char __force_user *)"/initrd.image");
65235 return 0;
65236 }
65237 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65238 index 8cb6db5..d729f50 100644
65239 --- a/init/do_mounts_md.c
65240 +++ b/init/do_mounts_md.c
65241 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
65242 partitioned ? "_d" : "", minor,
65243 md_setup_args[ent].device_names);
65244
65245 - fd = sys_open(name, 0, 0);
65246 + fd = sys_open((char __force_user *)name, 0, 0);
65247 if (fd < 0) {
65248 printk(KERN_ERR "md: open failed - cannot start "
65249 "array %s\n", name);
65250 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
65251 * array without it
65252 */
65253 sys_close(fd);
65254 - fd = sys_open(name, 0, 0);
65255 + fd = sys_open((char __force_user *)name, 0, 0);
65256 sys_ioctl(fd, BLKRRPART, 0);
65257 }
65258 sys_close(fd);
65259 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
65260
65261 wait_for_device_probe();
65262
65263 - fd = sys_open("/dev/md0", 0, 0);
65264 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65265 if (fd >= 0) {
65266 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65267 sys_close(fd);
65268 diff --git a/init/init_task.c b/init/init_task.c
65269 index 8b2f399..f0797c9 100644
65270 --- a/init/init_task.c
65271 +++ b/init/init_task.c
65272 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
65273 * Initial thread structure. Alignment of this is handled by a special
65274 * linker map entry.
65275 */
65276 +#ifdef CONFIG_X86
65277 +union thread_union init_thread_union __init_task_data;
65278 +#else
65279 union thread_union init_thread_union __init_task_data =
65280 { INIT_THREAD_INFO(init_task) };
65281 +#endif
65282 diff --git a/init/initramfs.c b/init/initramfs.c
65283 index 84c6bf1..8899338 100644
65284 --- a/init/initramfs.c
65285 +++ b/init/initramfs.c
65286 @@ -84,7 +84,7 @@ static void __init free_hash(void)
65287 }
65288 }
65289
65290 -static long __init do_utime(char *filename, time_t mtime)
65291 +static long __init do_utime(char __force_user *filename, time_t mtime)
65292 {
65293 struct timespec t[2];
65294
65295 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
65296 struct dir_entry *de, *tmp;
65297 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65298 list_del(&de->list);
65299 - do_utime(de->name, de->mtime);
65300 + do_utime((char __force_user *)de->name, de->mtime);
65301 kfree(de->name);
65302 kfree(de);
65303 }
65304 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
65305 if (nlink >= 2) {
65306 char *old = find_link(major, minor, ino, mode, collected);
65307 if (old)
65308 - return (sys_link(old, collected) < 0) ? -1 : 1;
65309 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65310 }
65311 return 0;
65312 }
65313 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
65314 {
65315 struct stat st;
65316
65317 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65318 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65319 if (S_ISDIR(st.st_mode))
65320 - sys_rmdir(path);
65321 + sys_rmdir((char __force_user *)path);
65322 else
65323 - sys_unlink(path);
65324 + sys_unlink((char __force_user *)path);
65325 }
65326 }
65327
65328 @@ -315,7 +315,7 @@ static int __init do_name(void)
65329 int openflags = O_WRONLY|O_CREAT;
65330 if (ml != 1)
65331 openflags |= O_TRUNC;
65332 - wfd = sys_open(collected, openflags, mode);
65333 + wfd = sys_open((char __force_user *)collected, openflags, mode);
65334
65335 if (wfd >= 0) {
65336 sys_fchown(wfd, uid, gid);
65337 @@ -327,17 +327,17 @@ static int __init do_name(void)
65338 }
65339 }
65340 } else if (S_ISDIR(mode)) {
65341 - sys_mkdir(collected, mode);
65342 - sys_chown(collected, uid, gid);
65343 - sys_chmod(collected, mode);
65344 + sys_mkdir((char __force_user *)collected, mode);
65345 + sys_chown((char __force_user *)collected, uid, gid);
65346 + sys_chmod((char __force_user *)collected, mode);
65347 dir_add(collected, mtime);
65348 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65349 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65350 if (maybe_link() == 0) {
65351 - sys_mknod(collected, mode, rdev);
65352 - sys_chown(collected, uid, gid);
65353 - sys_chmod(collected, mode);
65354 - do_utime(collected, mtime);
65355 + sys_mknod((char __force_user *)collected, mode, rdev);
65356 + sys_chown((char __force_user *)collected, uid, gid);
65357 + sys_chmod((char __force_user *)collected, mode);
65358 + do_utime((char __force_user *)collected, mtime);
65359 }
65360 }
65361 return 0;
65362 @@ -346,15 +346,15 @@ static int __init do_name(void)
65363 static int __init do_copy(void)
65364 {
65365 if (count >= body_len) {
65366 - sys_write(wfd, victim, body_len);
65367 + sys_write(wfd, (char __force_user *)victim, body_len);
65368 sys_close(wfd);
65369 - do_utime(vcollected, mtime);
65370 + do_utime((char __force_user *)vcollected, mtime);
65371 kfree(vcollected);
65372 eat(body_len);
65373 state = SkipIt;
65374 return 0;
65375 } else {
65376 - sys_write(wfd, victim, count);
65377 + sys_write(wfd, (char __force_user *)victim, count);
65378 body_len -= count;
65379 eat(count);
65380 return 1;
65381 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
65382 {
65383 collected[N_ALIGN(name_len) + body_len] = '\0';
65384 clean_path(collected, 0);
65385 - sys_symlink(collected + N_ALIGN(name_len), collected);
65386 - sys_lchown(collected, uid, gid);
65387 - do_utime(collected, mtime);
65388 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
65389 + sys_lchown((char __force_user *)collected, uid, gid);
65390 + do_utime((char __force_user *)collected, mtime);
65391 state = SkipIt;
65392 next_state = Reset;
65393 return 0;
65394 diff --git a/init/main.c b/init/main.c
65395 index b5cc0a7..5605c91 100644
65396 --- a/init/main.c
65397 +++ b/init/main.c
65398 @@ -95,6 +95,8 @@ static inline void mark_rodata_ro(void) { }
65399 extern void tc_init(void);
65400 #endif
65401
65402 +extern void grsecurity_init(void);
65403 +
65404 /*
65405 * Debug helper: via this flag we know that we are in 'early bootup code'
65406 * where only the boot processor is running with IRQ disabled. This means
65407 @@ -148,6 +150,49 @@ static int __init set_reset_devices(char *str)
65408
65409 __setup("reset_devices", set_reset_devices);
65410
65411 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
65412 +extern char pax_enter_kernel_user[];
65413 +extern char pax_exit_kernel_user[];
65414 +extern pgdval_t clone_pgd_mask;
65415 +#endif
65416 +
65417 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
65418 +static int __init setup_pax_nouderef(char *str)
65419 +{
65420 +#ifdef CONFIG_X86_32
65421 + unsigned int cpu;
65422 + struct desc_struct *gdt;
65423 +
65424 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
65425 + gdt = get_cpu_gdt_table(cpu);
65426 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
65427 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
65428 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
65429 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
65430 + }
65431 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
65432 +#else
65433 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
65434 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
65435 + clone_pgd_mask = ~(pgdval_t)0UL;
65436 +#endif
65437 +
65438 + return 0;
65439 +}
65440 +early_param("pax_nouderef", setup_pax_nouderef);
65441 +#endif
65442 +
65443 +#ifdef CONFIG_PAX_SOFTMODE
65444 +int pax_softmode;
65445 +
65446 +static int __init setup_pax_softmode(char *str)
65447 +{
65448 + get_option(&str, &pax_softmode);
65449 + return 1;
65450 +}
65451 +__setup("pax_softmode=", setup_pax_softmode);
65452 +#endif
65453 +
65454 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
65455 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
65456 static const char *panic_later, *panic_param;
65457 @@ -674,6 +719,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
65458 {
65459 int count = preempt_count();
65460 int ret;
65461 + const char *msg1 = "", *msg2 = "";
65462
65463 if (initcall_debug)
65464 ret = do_one_initcall_debug(fn);
65465 @@ -686,15 +732,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
65466 sprintf(msgbuf, "error code %d ", ret);
65467
65468 if (preempt_count() != count) {
65469 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
65470 + msg1 = " preemption imbalance";
65471 preempt_count() = count;
65472 }
65473 if (irqs_disabled()) {
65474 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
65475 + msg2 = " disabled interrupts";
65476 local_irq_enable();
65477 }
65478 - if (msgbuf[0]) {
65479 - printk("initcall %pF returned with %s\n", fn, msgbuf);
65480 + if (msgbuf[0] || *msg1 || *msg2) {
65481 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
65482 }
65483
65484 return ret;
65485 @@ -747,8 +793,14 @@ static void __init do_initcall_level(int level)
65486 level, level,
65487 &repair_env_string);
65488
65489 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
65490 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
65491 do_one_initcall(*fn);
65492 +
65493 +#ifdef CONFIG_PAX_LATENT_ENTROPY
65494 + transfer_latent_entropy();
65495 +#endif
65496 +
65497 + }
65498 }
65499
65500 static void __init do_initcalls(void)
65501 @@ -782,8 +834,14 @@ static void __init do_pre_smp_initcalls(void)
65502 {
65503 initcall_t *fn;
65504
65505 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
65506 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
65507 do_one_initcall(*fn);
65508 +
65509 +#ifdef CONFIG_PAX_LATENT_ENTROPY
65510 + transfer_latent_entropy();
65511 +#endif
65512 +
65513 + }
65514 }
65515
65516 static void run_init_process(const char *init_filename)
65517 @@ -865,7 +923,7 @@ static int __init kernel_init(void * unused)
65518 do_basic_setup();
65519
65520 /* Open the /dev/console on the rootfs, this should never fail */
65521 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65522 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65523 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65524
65525 (void) sys_dup(0);
65526 @@ -878,11 +936,13 @@ static int __init kernel_init(void * unused)
65527 if (!ramdisk_execute_command)
65528 ramdisk_execute_command = "/init";
65529
65530 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65531 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65532 ramdisk_execute_command = NULL;
65533 prepare_namespace();
65534 }
65535
65536 + grsecurity_init();
65537 +
65538 /*
65539 * Ok, we have completed the initial bootup, and
65540 * we're essentially up and running. Get rid of the
65541 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65542 index 8ce5769..4666884 100644
65543 --- a/ipc/mqueue.c
65544 +++ b/ipc/mqueue.c
65545 @@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65546 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
65547 info->attr.mq_msgsize);
65548
65549 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65550 spin_lock(&mq_lock);
65551 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65552 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
65553 diff --git a/ipc/msg.c b/ipc/msg.c
65554 index 7385de2..a8180e08 100644
65555 --- a/ipc/msg.c
65556 +++ b/ipc/msg.c
65557 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65558 return security_msg_queue_associate(msq, msgflg);
65559 }
65560
65561 +static struct ipc_ops msg_ops = {
65562 + .getnew = newque,
65563 + .associate = msg_security,
65564 + .more_checks = NULL
65565 +};
65566 +
65567 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65568 {
65569 struct ipc_namespace *ns;
65570 - struct ipc_ops msg_ops;
65571 struct ipc_params msg_params;
65572
65573 ns = current->nsproxy->ipc_ns;
65574
65575 - msg_ops.getnew = newque;
65576 - msg_ops.associate = msg_security;
65577 - msg_ops.more_checks = NULL;
65578 -
65579 msg_params.key = key;
65580 msg_params.flg = msgflg;
65581
65582 diff --git a/ipc/sem.c b/ipc/sem.c
65583 index 5215a81..cfc0cac 100644
65584 --- a/ipc/sem.c
65585 +++ b/ipc/sem.c
65586 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65587 return 0;
65588 }
65589
65590 +static struct ipc_ops sem_ops = {
65591 + .getnew = newary,
65592 + .associate = sem_security,
65593 + .more_checks = sem_more_checks
65594 +};
65595 +
65596 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65597 {
65598 struct ipc_namespace *ns;
65599 - struct ipc_ops sem_ops;
65600 struct ipc_params sem_params;
65601
65602 ns = current->nsproxy->ipc_ns;
65603 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65604 if (nsems < 0 || nsems > ns->sc_semmsl)
65605 return -EINVAL;
65606
65607 - sem_ops.getnew = newary;
65608 - sem_ops.associate = sem_security;
65609 - sem_ops.more_checks = sem_more_checks;
65610 -
65611 sem_params.key = key;
65612 sem_params.flg = semflg;
65613 sem_params.u.nsems = nsems;
65614 diff --git a/ipc/shm.c b/ipc/shm.c
65615 index 41c1285..cf6404c 100644
65616 --- a/ipc/shm.c
65617 +++ b/ipc/shm.c
65618 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65619 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65620 #endif
65621
65622 +#ifdef CONFIG_GRKERNSEC
65623 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65624 + const time_t shm_createtime, const uid_t cuid,
65625 + const int shmid);
65626 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65627 + const time_t shm_createtime);
65628 +#endif
65629 +
65630 void shm_init_ns(struct ipc_namespace *ns)
65631 {
65632 ns->shm_ctlmax = SHMMAX;
65633 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65634 shp->shm_lprid = 0;
65635 shp->shm_atim = shp->shm_dtim = 0;
65636 shp->shm_ctim = get_seconds();
65637 +#ifdef CONFIG_GRKERNSEC
65638 + {
65639 + struct timespec timeval;
65640 + do_posix_clock_monotonic_gettime(&timeval);
65641 +
65642 + shp->shm_createtime = timeval.tv_sec;
65643 + }
65644 +#endif
65645 shp->shm_segsz = size;
65646 shp->shm_nattch = 0;
65647 shp->shm_file = file;
65648 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65649 return 0;
65650 }
65651
65652 +static struct ipc_ops shm_ops = {
65653 + .getnew = newseg,
65654 + .associate = shm_security,
65655 + .more_checks = shm_more_checks
65656 +};
65657 +
65658 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65659 {
65660 struct ipc_namespace *ns;
65661 - struct ipc_ops shm_ops;
65662 struct ipc_params shm_params;
65663
65664 ns = current->nsproxy->ipc_ns;
65665
65666 - shm_ops.getnew = newseg;
65667 - shm_ops.associate = shm_security;
65668 - shm_ops.more_checks = shm_more_checks;
65669 -
65670 shm_params.key = key;
65671 shm_params.flg = shmflg;
65672 shm_params.u.size = size;
65673 @@ -1000,6 +1017,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65674 f_mode = FMODE_READ | FMODE_WRITE;
65675 }
65676 if (shmflg & SHM_EXEC) {
65677 +
65678 +#ifdef CONFIG_PAX_MPROTECT
65679 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
65680 + goto out;
65681 +#endif
65682 +
65683 prot |= PROT_EXEC;
65684 acc_mode |= S_IXUGO;
65685 }
65686 @@ -1023,9 +1046,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65687 if (err)
65688 goto out_unlock;
65689
65690 +#ifdef CONFIG_GRKERNSEC
65691 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65692 + shp->shm_perm.cuid, shmid) ||
65693 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65694 + err = -EACCES;
65695 + goto out_unlock;
65696 + }
65697 +#endif
65698 +
65699 path = shp->shm_file->f_path;
65700 path_get(&path);
65701 shp->shm_nattch++;
65702 +#ifdef CONFIG_GRKERNSEC
65703 + shp->shm_lapid = current->pid;
65704 +#endif
65705 size = i_size_read(path.dentry->d_inode);
65706 shm_unlock(shp);
65707
65708 diff --git a/kernel/acct.c b/kernel/acct.c
65709 index 02e6167..54824f7 100644
65710 --- a/kernel/acct.c
65711 +++ b/kernel/acct.c
65712 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65713 */
65714 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65715 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65716 - file->f_op->write(file, (char *)&ac,
65717 + file->f_op->write(file, (char __force_user *)&ac,
65718 sizeof(acct_t), &file->f_pos);
65719 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65720 set_fs(fs);
65721 diff --git a/kernel/audit.c b/kernel/audit.c
65722 index 1c7f2c6..9ba5359 100644
65723 --- a/kernel/audit.c
65724 +++ b/kernel/audit.c
65725 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65726 3) suppressed due to audit_rate_limit
65727 4) suppressed due to audit_backlog_limit
65728 */
65729 -static atomic_t audit_lost = ATOMIC_INIT(0);
65730 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65731
65732 /* The netlink socket. */
65733 static struct sock *audit_sock;
65734 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65735 unsigned long now;
65736 int print;
65737
65738 - atomic_inc(&audit_lost);
65739 + atomic_inc_unchecked(&audit_lost);
65740
65741 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65742
65743 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65744 printk(KERN_WARNING
65745 "audit: audit_lost=%d audit_rate_limit=%d "
65746 "audit_backlog_limit=%d\n",
65747 - atomic_read(&audit_lost),
65748 + atomic_read_unchecked(&audit_lost),
65749 audit_rate_limit,
65750 audit_backlog_limit);
65751 audit_panic(message);
65752 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65753 status_set.pid = audit_pid;
65754 status_set.rate_limit = audit_rate_limit;
65755 status_set.backlog_limit = audit_backlog_limit;
65756 - status_set.lost = atomic_read(&audit_lost);
65757 + status_set.lost = atomic_read_unchecked(&audit_lost);
65758 status_set.backlog = skb_queue_len(&audit_skb_queue);
65759 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65760 &status_set, sizeof(status_set));
65761 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65762 index 4b96415..d8c16ee 100644
65763 --- a/kernel/auditsc.c
65764 +++ b/kernel/auditsc.c
65765 @@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65766 }
65767
65768 /* global counter which is incremented every time something logs in */
65769 -static atomic_t session_id = ATOMIC_INIT(0);
65770 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65771
65772 /**
65773 * audit_set_loginuid - set current task's audit_context loginuid
65774 @@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
65775 return -EPERM;
65776 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
65777
65778 - sessionid = atomic_inc_return(&session_id);
65779 + sessionid = atomic_inc_return_unchecked(&session_id);
65780 if (context && context->in_syscall) {
65781 struct audit_buffer *ab;
65782
65783 diff --git a/kernel/capability.c b/kernel/capability.c
65784 index 493d972..ea17248 100644
65785 --- a/kernel/capability.c
65786 +++ b/kernel/capability.c
65787 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65788 * before modification is attempted and the application
65789 * fails.
65790 */
65791 + if (tocopy > ARRAY_SIZE(kdata))
65792 + return -EFAULT;
65793 +
65794 if (copy_to_user(dataptr, kdata, tocopy
65795 * sizeof(struct __user_cap_data_struct))) {
65796 return -EFAULT;
65797 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
65798 int ret;
65799
65800 rcu_read_lock();
65801 - ret = security_capable(__task_cred(t), ns, cap);
65802 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
65803 + gr_task_is_capable(t, __task_cred(t), cap);
65804 rcu_read_unlock();
65805
65806 - return (ret == 0);
65807 + return ret;
65808 }
65809
65810 /**
65811 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
65812 int ret;
65813
65814 rcu_read_lock();
65815 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
65816 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
65817 rcu_read_unlock();
65818
65819 - return (ret == 0);
65820 + return ret;
65821 }
65822
65823 /**
65824 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
65825 BUG();
65826 }
65827
65828 - if (security_capable(current_cred(), ns, cap) == 0) {
65829 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
65830 current->flags |= PF_SUPERPRIV;
65831 return true;
65832 }
65833 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
65834 }
65835 EXPORT_SYMBOL(ns_capable);
65836
65837 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
65838 +{
65839 + if (unlikely(!cap_valid(cap))) {
65840 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
65841 + BUG();
65842 + }
65843 +
65844 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
65845 + current->flags |= PF_SUPERPRIV;
65846 + return true;
65847 + }
65848 + return false;
65849 +}
65850 +EXPORT_SYMBOL(ns_capable_nolog);
65851 +
65852 /**
65853 * capable - Determine if the current task has a superior capability in effect
65854 * @cap: The capability to be tested for
65855 @@ -408,6 +427,12 @@ bool capable(int cap)
65856 }
65857 EXPORT_SYMBOL(capable);
65858
65859 +bool capable_nolog(int cap)
65860 +{
65861 + return ns_capable_nolog(&init_user_ns, cap);
65862 +}
65863 +EXPORT_SYMBOL(capable_nolog);
65864 +
65865 /**
65866 * nsown_capable - Check superior capability to one's own user_ns
65867 * @cap: The capability in question
65868 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
65869
65870 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
65871 }
65872 +
65873 +bool inode_capable_nolog(const struct inode *inode, int cap)
65874 +{
65875 + struct user_namespace *ns = current_user_ns();
65876 +
65877 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
65878 +}
65879 diff --git a/kernel/compat.c b/kernel/compat.c
65880 index c28a306..b4d0cf3 100644
65881 --- a/kernel/compat.c
65882 +++ b/kernel/compat.c
65883 @@ -13,6 +13,7 @@
65884
65885 #include <linux/linkage.h>
65886 #include <linux/compat.h>
65887 +#include <linux/module.h>
65888 #include <linux/errno.h>
65889 #include <linux/time.h>
65890 #include <linux/signal.h>
65891 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
65892 mm_segment_t oldfs;
65893 long ret;
65894
65895 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
65896 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
65897 oldfs = get_fs();
65898 set_fs(KERNEL_DS);
65899 ret = hrtimer_nanosleep_restart(restart);
65900 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
65901 oldfs = get_fs();
65902 set_fs(KERNEL_DS);
65903 ret = hrtimer_nanosleep(&tu,
65904 - rmtp ? (struct timespec __user *)&rmt : NULL,
65905 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
65906 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
65907 set_fs(oldfs);
65908
65909 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
65910 mm_segment_t old_fs = get_fs();
65911
65912 set_fs(KERNEL_DS);
65913 - ret = sys_sigpending((old_sigset_t __user *) &s);
65914 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
65915 set_fs(old_fs);
65916 if (ret == 0)
65917 ret = put_user(s, set);
65918 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
65919 mm_segment_t old_fs = get_fs();
65920
65921 set_fs(KERNEL_DS);
65922 - ret = sys_old_getrlimit(resource, &r);
65923 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
65924 set_fs(old_fs);
65925
65926 if (!ret) {
65927 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
65928 mm_segment_t old_fs = get_fs();
65929
65930 set_fs(KERNEL_DS);
65931 - ret = sys_getrusage(who, (struct rusage __user *) &r);
65932 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
65933 set_fs(old_fs);
65934
65935 if (ret)
65936 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
65937 set_fs (KERNEL_DS);
65938 ret = sys_wait4(pid,
65939 (stat_addr ?
65940 - (unsigned int __user *) &status : NULL),
65941 - options, (struct rusage __user *) &r);
65942 + (unsigned int __force_user *) &status : NULL),
65943 + options, (struct rusage __force_user *) &r);
65944 set_fs (old_fs);
65945
65946 if (ret > 0) {
65947 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
65948 memset(&info, 0, sizeof(info));
65949
65950 set_fs(KERNEL_DS);
65951 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
65952 - uru ? (struct rusage __user *)&ru : NULL);
65953 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
65954 + uru ? (struct rusage __force_user *)&ru : NULL);
65955 set_fs(old_fs);
65956
65957 if ((ret < 0) || (info.si_signo == 0))
65958 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
65959 oldfs = get_fs();
65960 set_fs(KERNEL_DS);
65961 err = sys_timer_settime(timer_id, flags,
65962 - (struct itimerspec __user *) &newts,
65963 - (struct itimerspec __user *) &oldts);
65964 + (struct itimerspec __force_user *) &newts,
65965 + (struct itimerspec __force_user *) &oldts);
65966 set_fs(oldfs);
65967 if (!err && old && put_compat_itimerspec(old, &oldts))
65968 return -EFAULT;
65969 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
65970 oldfs = get_fs();
65971 set_fs(KERNEL_DS);
65972 err = sys_timer_gettime(timer_id,
65973 - (struct itimerspec __user *) &ts);
65974 + (struct itimerspec __force_user *) &ts);
65975 set_fs(oldfs);
65976 if (!err && put_compat_itimerspec(setting, &ts))
65977 return -EFAULT;
65978 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
65979 oldfs = get_fs();
65980 set_fs(KERNEL_DS);
65981 err = sys_clock_settime(which_clock,
65982 - (struct timespec __user *) &ts);
65983 + (struct timespec __force_user *) &ts);
65984 set_fs(oldfs);
65985 return err;
65986 }
65987 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
65988 oldfs = get_fs();
65989 set_fs(KERNEL_DS);
65990 err = sys_clock_gettime(which_clock,
65991 - (struct timespec __user *) &ts);
65992 + (struct timespec __force_user *) &ts);
65993 set_fs(oldfs);
65994 if (!err && put_compat_timespec(&ts, tp))
65995 return -EFAULT;
65996 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
65997
65998 oldfs = get_fs();
65999 set_fs(KERNEL_DS);
66000 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66001 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66002 set_fs(oldfs);
66003
66004 err = compat_put_timex(utp, &txc);
66005 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66006 oldfs = get_fs();
66007 set_fs(KERNEL_DS);
66008 err = sys_clock_getres(which_clock,
66009 - (struct timespec __user *) &ts);
66010 + (struct timespec __force_user *) &ts);
66011 set_fs(oldfs);
66012 if (!err && tp && put_compat_timespec(&ts, tp))
66013 return -EFAULT;
66014 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66015 long err;
66016 mm_segment_t oldfs;
66017 struct timespec tu;
66018 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66019 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66020
66021 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66022 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66023 oldfs = get_fs();
66024 set_fs(KERNEL_DS);
66025 err = clock_nanosleep_restart(restart);
66026 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66027 oldfs = get_fs();
66028 set_fs(KERNEL_DS);
66029 err = sys_clock_nanosleep(which_clock, flags,
66030 - (struct timespec __user *) &in,
66031 - (struct timespec __user *) &out);
66032 + (struct timespec __force_user *) &in,
66033 + (struct timespec __force_user *) &out);
66034 set_fs(oldfs);
66035
66036 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66037 diff --git a/kernel/configs.c b/kernel/configs.c
66038 index 42e8fa0..9e7406b 100644
66039 --- a/kernel/configs.c
66040 +++ b/kernel/configs.c
66041 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66042 struct proc_dir_entry *entry;
66043
66044 /* create the current config file */
66045 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66046 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66047 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66048 + &ikconfig_file_ops);
66049 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66050 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66051 + &ikconfig_file_ops);
66052 +#endif
66053 +#else
66054 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66055 &ikconfig_file_ops);
66056 +#endif
66057 +
66058 if (!entry)
66059 return -ENOMEM;
66060
66061 diff --git a/kernel/cred.c b/kernel/cred.c
66062 index de728ac..e3c267c 100644
66063 --- a/kernel/cred.c
66064 +++ b/kernel/cred.c
66065 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66066 validate_creds(cred);
66067 alter_cred_subscribers(cred, -1);
66068 put_cred(cred);
66069 +
66070 +#ifdef CONFIG_GRKERNSEC_SETXID
66071 + cred = (struct cred *) tsk->delayed_cred;
66072 + if (cred != NULL) {
66073 + tsk->delayed_cred = NULL;
66074 + validate_creds(cred);
66075 + alter_cred_subscribers(cred, -1);
66076 + put_cred(cred);
66077 + }
66078 +#endif
66079 }
66080
66081 /**
66082 @@ -469,7 +479,7 @@ error_put:
66083 * Always returns 0 thus allowing this function to be tail-called at the end
66084 * of, say, sys_setgid().
66085 */
66086 -int commit_creds(struct cred *new)
66087 +static int __commit_creds(struct cred *new)
66088 {
66089 struct task_struct *task = current;
66090 const struct cred *old = task->real_cred;
66091 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66092
66093 get_cred(new); /* we will require a ref for the subj creds too */
66094
66095 + gr_set_role_label(task, new->uid, new->gid);
66096 +
66097 /* dumpability changes */
66098 if (!uid_eq(old->euid, new->euid) ||
66099 !gid_eq(old->egid, new->egid) ||
66100 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66101 put_cred(old);
66102 return 0;
66103 }
66104 +#ifdef CONFIG_GRKERNSEC_SETXID
66105 +extern int set_user(struct cred *new);
66106 +
66107 +void gr_delayed_cred_worker(void)
66108 +{
66109 + const struct cred *new = current->delayed_cred;
66110 + struct cred *ncred;
66111 +
66112 + current->delayed_cred = NULL;
66113 +
66114 + if (current_uid() && new != NULL) {
66115 + // from doing get_cred on it when queueing this
66116 + put_cred(new);
66117 + return;
66118 + } else if (new == NULL)
66119 + return;
66120 +
66121 + ncred = prepare_creds();
66122 + if (!ncred)
66123 + goto die;
66124 + // uids
66125 + ncred->uid = new->uid;
66126 + ncred->euid = new->euid;
66127 + ncred->suid = new->suid;
66128 + ncred->fsuid = new->fsuid;
66129 + // gids
66130 + ncred->gid = new->gid;
66131 + ncred->egid = new->egid;
66132 + ncred->sgid = new->sgid;
66133 + ncred->fsgid = new->fsgid;
66134 + // groups
66135 + if (set_groups(ncred, new->group_info) < 0) {
66136 + abort_creds(ncred);
66137 + goto die;
66138 + }
66139 + // caps
66140 + ncred->securebits = new->securebits;
66141 + ncred->cap_inheritable = new->cap_inheritable;
66142 + ncred->cap_permitted = new->cap_permitted;
66143 + ncred->cap_effective = new->cap_effective;
66144 + ncred->cap_bset = new->cap_bset;
66145 +
66146 + if (set_user(ncred)) {
66147 + abort_creds(ncred);
66148 + goto die;
66149 + }
66150 +
66151 + // from doing get_cred on it when queueing this
66152 + put_cred(new);
66153 +
66154 + __commit_creds(ncred);
66155 + return;
66156 +die:
66157 + // from doing get_cred on it when queueing this
66158 + put_cred(new);
66159 + do_group_exit(SIGKILL);
66160 +}
66161 +#endif
66162 +
66163 +int commit_creds(struct cred *new)
66164 +{
66165 +#ifdef CONFIG_GRKERNSEC_SETXID
66166 + int ret;
66167 + int schedule_it = 0;
66168 + struct task_struct *t;
66169 +
66170 + /* we won't get called with tasklist_lock held for writing
66171 + and interrupts disabled as the cred struct in that case is
66172 + init_cred
66173 + */
66174 + if (grsec_enable_setxid && !current_is_single_threaded() &&
66175 + !current_uid() && new->uid) {
66176 + schedule_it = 1;
66177 + }
66178 + ret = __commit_creds(new);
66179 + if (schedule_it) {
66180 + rcu_read_lock();
66181 + read_lock(&tasklist_lock);
66182 + for (t = next_thread(current); t != current;
66183 + t = next_thread(t)) {
66184 + if (t->delayed_cred == NULL) {
66185 + t->delayed_cred = get_cred(new);
66186 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
66187 + set_tsk_need_resched(t);
66188 + }
66189 + }
66190 + read_unlock(&tasklist_lock);
66191 + rcu_read_unlock();
66192 + }
66193 + return ret;
66194 +#else
66195 + return __commit_creds(new);
66196 +#endif
66197 +}
66198 +
66199 EXPORT_SYMBOL(commit_creds);
66200
66201 /**
66202 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66203 index 0557f24..1a00d9a 100644
66204 --- a/kernel/debug/debug_core.c
66205 +++ b/kernel/debug/debug_core.c
66206 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66207 */
66208 static atomic_t masters_in_kgdb;
66209 static atomic_t slaves_in_kgdb;
66210 -static atomic_t kgdb_break_tasklet_var;
66211 +static atomic_unchecked_t kgdb_break_tasklet_var;
66212 atomic_t kgdb_setting_breakpoint;
66213
66214 struct task_struct *kgdb_usethread;
66215 @@ -132,7 +132,7 @@ int kgdb_single_step;
66216 static pid_t kgdb_sstep_pid;
66217
66218 /* to keep track of the CPU which is doing the single stepping*/
66219 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66220 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66221
66222 /*
66223 * If you are debugging a problem where roundup (the collection of
66224 @@ -540,7 +540,7 @@ return_normal:
66225 * kernel will only try for the value of sstep_tries before
66226 * giving up and continuing on.
66227 */
66228 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66229 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66230 (kgdb_info[cpu].task &&
66231 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66232 atomic_set(&kgdb_active, -1);
66233 @@ -634,8 +634,8 @@ cpu_master_loop:
66234 }
66235
66236 kgdb_restore:
66237 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66238 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66239 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66240 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66241 if (kgdb_info[sstep_cpu].task)
66242 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66243 else
66244 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
66245 static void kgdb_tasklet_bpt(unsigned long ing)
66246 {
66247 kgdb_breakpoint();
66248 - atomic_set(&kgdb_break_tasklet_var, 0);
66249 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66250 }
66251
66252 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66253
66254 void kgdb_schedule_breakpoint(void)
66255 {
66256 - if (atomic_read(&kgdb_break_tasklet_var) ||
66257 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66258 atomic_read(&kgdb_active) != -1 ||
66259 atomic_read(&kgdb_setting_breakpoint))
66260 return;
66261 - atomic_inc(&kgdb_break_tasklet_var);
66262 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
66263 tasklet_schedule(&kgdb_tasklet_breakpoint);
66264 }
66265 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66266 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66267 index 1f91413..362a0a1 100644
66268 --- a/kernel/debug/kdb/kdb_main.c
66269 +++ b/kernel/debug/kdb/kdb_main.c
66270 @@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
66271 list_for_each_entry(mod, kdb_modules, list) {
66272
66273 kdb_printf("%-20s%8u 0x%p ", mod->name,
66274 - mod->core_size, (void *)mod);
66275 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
66276 #ifdef CONFIG_MODULE_UNLOAD
66277 kdb_printf("%4ld ", module_refcount(mod));
66278 #endif
66279 @@ -1994,7 +1994,7 @@ static int kdb_lsmod(int argc, const char **argv)
66280 kdb_printf(" (Loading)");
66281 else
66282 kdb_printf(" (Live)");
66283 - kdb_printf(" 0x%p", mod->module_core);
66284 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
66285
66286 #ifdef CONFIG_MODULE_UNLOAD
66287 {
66288 diff --git a/kernel/events/core.c b/kernel/events/core.c
66289 index d7d71d6..f54b76f 100644
66290 --- a/kernel/events/core.c
66291 +++ b/kernel/events/core.c
66292 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
66293 return 0;
66294 }
66295
66296 -static atomic64_t perf_event_id;
66297 +static atomic64_unchecked_t perf_event_id;
66298
66299 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
66300 enum event_type_t event_type);
66301 @@ -2663,7 +2663,7 @@ static void __perf_event_read(void *info)
66302
66303 static inline u64 perf_event_count(struct perf_event *event)
66304 {
66305 - return local64_read(&event->count) + atomic64_read(&event->child_count);
66306 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
66307 }
66308
66309 static u64 perf_event_read(struct perf_event *event)
66310 @@ -2987,9 +2987,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
66311 mutex_lock(&event->child_mutex);
66312 total += perf_event_read(event);
66313 *enabled += event->total_time_enabled +
66314 - atomic64_read(&event->child_total_time_enabled);
66315 + atomic64_read_unchecked(&event->child_total_time_enabled);
66316 *running += event->total_time_running +
66317 - atomic64_read(&event->child_total_time_running);
66318 + atomic64_read_unchecked(&event->child_total_time_running);
66319
66320 list_for_each_entry(child, &event->child_list, child_list) {
66321 total += perf_event_read(child);
66322 @@ -3396,10 +3396,10 @@ void perf_event_update_userpage(struct perf_event *event)
66323 userpg->offset -= local64_read(&event->hw.prev_count);
66324
66325 userpg->time_enabled = enabled +
66326 - atomic64_read(&event->child_total_time_enabled);
66327 + atomic64_read_unchecked(&event->child_total_time_enabled);
66328
66329 userpg->time_running = running +
66330 - atomic64_read(&event->child_total_time_running);
66331 + atomic64_read_unchecked(&event->child_total_time_running);
66332
66333 arch_perf_update_userpage(userpg, now);
66334
66335 @@ -3832,11 +3832,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
66336 values[n++] = perf_event_count(event);
66337 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
66338 values[n++] = enabled +
66339 - atomic64_read(&event->child_total_time_enabled);
66340 + atomic64_read_unchecked(&event->child_total_time_enabled);
66341 }
66342 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
66343 values[n++] = running +
66344 - atomic64_read(&event->child_total_time_running);
66345 + atomic64_read_unchecked(&event->child_total_time_running);
66346 }
66347 if (read_format & PERF_FORMAT_ID)
66348 values[n++] = primary_event_id(event);
66349 @@ -4514,12 +4514,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
66350 * need to add enough zero bytes after the string to handle
66351 * the 64bit alignment we do later.
66352 */
66353 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
66354 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
66355 if (!buf) {
66356 name = strncpy(tmp, "//enomem", sizeof(tmp));
66357 goto got_name;
66358 }
66359 - name = d_path(&file->f_path, buf, PATH_MAX);
66360 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
66361 if (IS_ERR(name)) {
66362 name = strncpy(tmp, "//toolong", sizeof(tmp));
66363 goto got_name;
66364 @@ -5931,7 +5931,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
66365 event->parent = parent_event;
66366
66367 event->ns = get_pid_ns(current->nsproxy->pid_ns);
66368 - event->id = atomic64_inc_return(&perf_event_id);
66369 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
66370
66371 event->state = PERF_EVENT_STATE_INACTIVE;
66372
66373 @@ -6493,10 +6493,10 @@ static void sync_child_event(struct perf_event *child_event,
66374 /*
66375 * Add back the child's count to the parent's count:
66376 */
66377 - atomic64_add(child_val, &parent_event->child_count);
66378 - atomic64_add(child_event->total_time_enabled,
66379 + atomic64_add_unchecked(child_val, &parent_event->child_count);
66380 + atomic64_add_unchecked(child_event->total_time_enabled,
66381 &parent_event->child_total_time_enabled);
66382 - atomic64_add(child_event->total_time_running,
66383 + atomic64_add_unchecked(child_event->total_time_running,
66384 &parent_event->child_total_time_running);
66385
66386 /*
66387 diff --git a/kernel/exit.c b/kernel/exit.c
66388 index 46ce8da..c648f3a 100644
66389 --- a/kernel/exit.c
66390 +++ b/kernel/exit.c
66391 @@ -59,6 +59,10 @@
66392 #include <asm/pgtable.h>
66393 #include <asm/mmu_context.h>
66394
66395 +#ifdef CONFIG_GRKERNSEC
66396 +extern rwlock_t grsec_exec_file_lock;
66397 +#endif
66398 +
66399 static void exit_mm(struct task_struct * tsk);
66400
66401 static void __unhash_process(struct task_struct *p, bool group_dead)
66402 @@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
66403 struct task_struct *leader;
66404 int zap_leader;
66405 repeat:
66406 +#ifdef CONFIG_NET
66407 + gr_del_task_from_ip_table(p);
66408 +#endif
66409 +
66410 /* don't need to get the RCU readlock here - the process is dead and
66411 * can't be modifying its own credentials. But shut RCU-lockdep up */
66412 rcu_read_lock();
66413 @@ -394,7 +402,7 @@ int allow_signal(int sig)
66414 * know it'll be handled, so that they don't get converted to
66415 * SIGKILL or just silently dropped.
66416 */
66417 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
66418 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
66419 recalc_sigpending();
66420 spin_unlock_irq(&current->sighand->siglock);
66421 return 0;
66422 @@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
66423 vsnprintf(current->comm, sizeof(current->comm), name, args);
66424 va_end(args);
66425
66426 +#ifdef CONFIG_GRKERNSEC
66427 + write_lock(&grsec_exec_file_lock);
66428 + if (current->exec_file) {
66429 + fput(current->exec_file);
66430 + current->exec_file = NULL;
66431 + }
66432 + write_unlock(&grsec_exec_file_lock);
66433 +#endif
66434 +
66435 + gr_set_kernel_label(current);
66436 +
66437 /*
66438 * If we were started as result of loading a module, close all of the
66439 * user space pages. We don't need them, and if we didn't close them
66440 @@ -907,6 +926,8 @@ void do_exit(long code)
66441 struct task_struct *tsk = current;
66442 int group_dead;
66443
66444 + set_fs(USER_DS);
66445 +
66446 profile_task_exit(tsk);
66447
66448 WARN_ON(blk_needs_flush_plug(tsk));
66449 @@ -923,7 +944,6 @@ void do_exit(long code)
66450 * mm_release()->clear_child_tid() from writing to a user-controlled
66451 * kernel address.
66452 */
66453 - set_fs(USER_DS);
66454
66455 ptrace_event(PTRACE_EVENT_EXIT, code);
66456
66457 @@ -985,6 +1005,9 @@ void do_exit(long code)
66458 tsk->exit_code = code;
66459 taskstats_exit(tsk, group_dead);
66460
66461 + gr_acl_handle_psacct(tsk, code);
66462 + gr_acl_handle_exit();
66463 +
66464 exit_mm(tsk);
66465
66466 if (group_dead)
66467 @@ -1101,7 +1124,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
66468 * Take down every thread in the group. This is called by fatal signals
66469 * as well as by sys_exit_group (below).
66470 */
66471 -void
66472 +__noreturn void
66473 do_group_exit(int exit_code)
66474 {
66475 struct signal_struct *sig = current->signal;
66476 diff --git a/kernel/fork.c b/kernel/fork.c
66477 index f00e319..c212fbc 100644
66478 --- a/kernel/fork.c
66479 +++ b/kernel/fork.c
66480 @@ -321,7 +321,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
66481 *stackend = STACK_END_MAGIC; /* for overflow detection */
66482
66483 #ifdef CONFIG_CC_STACKPROTECTOR
66484 - tsk->stack_canary = get_random_int();
66485 + tsk->stack_canary = pax_get_random_long();
66486 #endif
66487
66488 /*
66489 @@ -345,13 +345,78 @@ out:
66490 }
66491
66492 #ifdef CONFIG_MMU
66493 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
66494 +{
66495 + struct vm_area_struct *tmp;
66496 + unsigned long charge;
66497 + struct mempolicy *pol;
66498 + struct file *file;
66499 +
66500 + charge = 0;
66501 + if (mpnt->vm_flags & VM_ACCOUNT) {
66502 + unsigned long len;
66503 + len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66504 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66505 + goto fail_nomem;
66506 + charge = len;
66507 + }
66508 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66509 + if (!tmp)
66510 + goto fail_nomem;
66511 + *tmp = *mpnt;
66512 + tmp->vm_mm = mm;
66513 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
66514 + pol = mpol_dup(vma_policy(mpnt));
66515 + if (IS_ERR(pol))
66516 + goto fail_nomem_policy;
66517 + vma_set_policy(tmp, pol);
66518 + if (anon_vma_fork(tmp, mpnt))
66519 + goto fail_nomem_anon_vma_fork;
66520 + tmp->vm_flags &= ~VM_LOCKED;
66521 + tmp->vm_next = tmp->vm_prev = NULL;
66522 + tmp->vm_mirror = NULL;
66523 + file = tmp->vm_file;
66524 + if (file) {
66525 + struct inode *inode = file->f_path.dentry->d_inode;
66526 + struct address_space *mapping = file->f_mapping;
66527 +
66528 + get_file(file);
66529 + if (tmp->vm_flags & VM_DENYWRITE)
66530 + atomic_dec(&inode->i_writecount);
66531 + mutex_lock(&mapping->i_mmap_mutex);
66532 + if (tmp->vm_flags & VM_SHARED)
66533 + mapping->i_mmap_writable++;
66534 + flush_dcache_mmap_lock(mapping);
66535 + /* insert tmp into the share list, just after mpnt */
66536 + vma_prio_tree_add(tmp, mpnt);
66537 + flush_dcache_mmap_unlock(mapping);
66538 + mutex_unlock(&mapping->i_mmap_mutex);
66539 + }
66540 +
66541 + /*
66542 + * Clear hugetlb-related page reserves for children. This only
66543 + * affects MAP_PRIVATE mappings. Faults generated by the child
66544 + * are not guaranteed to succeed, even if read-only
66545 + */
66546 + if (is_vm_hugetlb_page(tmp))
66547 + reset_vma_resv_huge_pages(tmp);
66548 +
66549 + return tmp;
66550 +
66551 +fail_nomem_anon_vma_fork:
66552 + mpol_put(pol);
66553 +fail_nomem_policy:
66554 + kmem_cache_free(vm_area_cachep, tmp);
66555 +fail_nomem:
66556 + vm_unacct_memory(charge);
66557 + return NULL;
66558 +}
66559 +
66560 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66561 {
66562 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66563 struct rb_node **rb_link, *rb_parent;
66564 int retval;
66565 - unsigned long charge;
66566 - struct mempolicy *pol;
66567
66568 down_write(&oldmm->mmap_sem);
66569 flush_cache_dup_mm(oldmm);
66570 @@ -363,8 +428,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66571 mm->locked_vm = 0;
66572 mm->mmap = NULL;
66573 mm->mmap_cache = NULL;
66574 - mm->free_area_cache = oldmm->mmap_base;
66575 - mm->cached_hole_size = ~0UL;
66576 + mm->free_area_cache = oldmm->free_area_cache;
66577 + mm->cached_hole_size = oldmm->cached_hole_size;
66578 mm->map_count = 0;
66579 cpumask_clear(mm_cpumask(mm));
66580 mm->mm_rb = RB_ROOT;
66581 @@ -380,8 +445,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66582
66583 prev = NULL;
66584 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66585 - struct file *file;
66586 -
66587 if (mpnt->vm_flags & VM_DONTCOPY) {
66588 long pages = vma_pages(mpnt);
66589 mm->total_vm -= pages;
66590 @@ -389,54 +452,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66591 -pages);
66592 continue;
66593 }
66594 - charge = 0;
66595 - if (mpnt->vm_flags & VM_ACCOUNT) {
66596 - unsigned long len;
66597 - len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66598 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66599 - goto fail_nomem;
66600 - charge = len;
66601 + tmp = dup_vma(mm, oldmm, mpnt);
66602 + if (!tmp) {
66603 + retval = -ENOMEM;
66604 + goto out;
66605 }
66606 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66607 - if (!tmp)
66608 - goto fail_nomem;
66609 - *tmp = *mpnt;
66610 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
66611 - pol = mpol_dup(vma_policy(mpnt));
66612 - retval = PTR_ERR(pol);
66613 - if (IS_ERR(pol))
66614 - goto fail_nomem_policy;
66615 - vma_set_policy(tmp, pol);
66616 - tmp->vm_mm = mm;
66617 - if (anon_vma_fork(tmp, mpnt))
66618 - goto fail_nomem_anon_vma_fork;
66619 - tmp->vm_flags &= ~VM_LOCKED;
66620 - tmp->vm_next = tmp->vm_prev = NULL;
66621 - file = tmp->vm_file;
66622 - if (file) {
66623 - struct inode *inode = file->f_path.dentry->d_inode;
66624 - struct address_space *mapping = file->f_mapping;
66625 -
66626 - get_file(file);
66627 - if (tmp->vm_flags & VM_DENYWRITE)
66628 - atomic_dec(&inode->i_writecount);
66629 - mutex_lock(&mapping->i_mmap_mutex);
66630 - if (tmp->vm_flags & VM_SHARED)
66631 - mapping->i_mmap_writable++;
66632 - flush_dcache_mmap_lock(mapping);
66633 - /* insert tmp into the share list, just after mpnt */
66634 - vma_prio_tree_add(tmp, mpnt);
66635 - flush_dcache_mmap_unlock(mapping);
66636 - mutex_unlock(&mapping->i_mmap_mutex);
66637 - }
66638 -
66639 - /*
66640 - * Clear hugetlb-related page reserves for children. This only
66641 - * affects MAP_PRIVATE mappings. Faults generated by the child
66642 - * are not guaranteed to succeed, even if read-only
66643 - */
66644 - if (is_vm_hugetlb_page(tmp))
66645 - reset_vma_resv_huge_pages(tmp);
66646
66647 /*
66648 * Link in the new vma and copy the page table entries.
66649 @@ -459,9 +479,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66650 if (retval)
66651 goto out;
66652
66653 - if (file && uprobe_mmap(tmp))
66654 + if (tmp->vm_file && uprobe_mmap(tmp))
66655 goto out;
66656 }
66657 +
66658 +#ifdef CONFIG_PAX_SEGMEXEC
66659 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66660 + struct vm_area_struct *mpnt_m;
66661 +
66662 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66663 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66664 +
66665 + if (!mpnt->vm_mirror)
66666 + continue;
66667 +
66668 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66669 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66670 + mpnt->vm_mirror = mpnt_m;
66671 + } else {
66672 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66673 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66674 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66675 + mpnt->vm_mirror->vm_mirror = mpnt;
66676 + }
66677 + }
66678 + BUG_ON(mpnt_m);
66679 + }
66680 +#endif
66681 +
66682 /* a new mm has just been created */
66683 arch_dup_mmap(oldmm, mm);
66684 retval = 0;
66685 @@ -470,14 +515,6 @@ out:
66686 flush_tlb_mm(oldmm);
66687 up_write(&oldmm->mmap_sem);
66688 return retval;
66689 -fail_nomem_anon_vma_fork:
66690 - mpol_put(pol);
66691 -fail_nomem_policy:
66692 - kmem_cache_free(vm_area_cachep, tmp);
66693 -fail_nomem:
66694 - retval = -ENOMEM;
66695 - vm_unacct_memory(charge);
66696 - goto out;
66697 }
66698
66699 static inline int mm_alloc_pgd(struct mm_struct *mm)
66700 @@ -714,8 +751,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66701 return ERR_PTR(err);
66702
66703 mm = get_task_mm(task);
66704 - if (mm && mm != current->mm &&
66705 - !ptrace_may_access(task, mode)) {
66706 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66707 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66708 mmput(mm);
66709 mm = ERR_PTR(-EACCES);
66710 }
66711 @@ -936,13 +973,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66712 spin_unlock(&fs->lock);
66713 return -EAGAIN;
66714 }
66715 - fs->users++;
66716 + atomic_inc(&fs->users);
66717 spin_unlock(&fs->lock);
66718 return 0;
66719 }
66720 tsk->fs = copy_fs_struct(fs);
66721 if (!tsk->fs)
66722 return -ENOMEM;
66723 + gr_set_chroot_entries(tsk, &tsk->fs->root);
66724 return 0;
66725 }
66726
66727 @@ -1209,6 +1247,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66728 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66729 #endif
66730 retval = -EAGAIN;
66731 +
66732 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66733 +
66734 if (atomic_read(&p->real_cred->user->processes) >=
66735 task_rlimit(p, RLIMIT_NPROC)) {
66736 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66737 @@ -1431,6 +1472,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66738 /* Need tasklist lock for parent etc handling! */
66739 write_lock_irq(&tasklist_lock);
66740
66741 + /* synchronizes with gr_set_acls() */
66742 + gr_copy_label(p);
66743 +
66744 /* CLONE_PARENT re-uses the old parent */
66745 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
66746 p->real_parent = current->real_parent;
66747 @@ -1541,6 +1585,8 @@ bad_fork_cleanup_count:
66748 bad_fork_free:
66749 free_task(p);
66750 fork_out:
66751 + gr_log_forkfail(retval);
66752 +
66753 return ERR_PTR(retval);
66754 }
66755
66756 @@ -1641,6 +1687,8 @@ long do_fork(unsigned long clone_flags,
66757 if (clone_flags & CLONE_PARENT_SETTID)
66758 put_user(nr, parent_tidptr);
66759
66760 + gr_handle_brute_check();
66761 +
66762 if (clone_flags & CLONE_VFORK) {
66763 p->vfork_done = &vfork;
66764 init_completion(&vfork);
66765 @@ -1739,7 +1787,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66766 return 0;
66767
66768 /* don't need lock here; in the worst case we'll do useless copy */
66769 - if (fs->users == 1)
66770 + if (atomic_read(&fs->users) == 1)
66771 return 0;
66772
66773 *new_fsp = copy_fs_struct(fs);
66774 @@ -1828,7 +1876,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66775 fs = current->fs;
66776 spin_lock(&fs->lock);
66777 current->fs = new_fs;
66778 - if (--fs->users)
66779 + gr_set_chroot_entries(current, &current->fs->root);
66780 + if (atomic_dec_return(&fs->users))
66781 new_fs = NULL;
66782 else
66783 new_fs = fs;
66784 diff --git a/kernel/futex.c b/kernel/futex.c
66785 index 3717e7b..473c750 100644
66786 --- a/kernel/futex.c
66787 +++ b/kernel/futex.c
66788 @@ -54,6 +54,7 @@
66789 #include <linux/mount.h>
66790 #include <linux/pagemap.h>
66791 #include <linux/syscalls.h>
66792 +#include <linux/ptrace.h>
66793 #include <linux/signal.h>
66794 #include <linux/export.h>
66795 #include <linux/magic.h>
66796 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
66797 struct page *page, *page_head;
66798 int err, ro = 0;
66799
66800 +#ifdef CONFIG_PAX_SEGMEXEC
66801 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
66802 + return -EFAULT;
66803 +#endif
66804 +
66805 /*
66806 * The futex address must be "naturally" aligned.
66807 */
66808 @@ -2714,6 +2720,7 @@ static int __init futex_init(void)
66809 {
66810 u32 curval;
66811 int i;
66812 + mm_segment_t oldfs;
66813
66814 /*
66815 * This will fail and we want it. Some arch implementations do
66816 @@ -2725,8 +2732,11 @@ static int __init futex_init(void)
66817 * implementation, the non-functional ones will return
66818 * -ENOSYS.
66819 */
66820 + oldfs = get_fs();
66821 + set_fs(USER_DS);
66822 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
66823 futex_cmpxchg_enabled = 1;
66824 + set_fs(oldfs);
66825
66826 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
66827 plist_head_init(&futex_queues[i].chain);
66828 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
66829 index 9b22d03..6295b62 100644
66830 --- a/kernel/gcov/base.c
66831 +++ b/kernel/gcov/base.c
66832 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
66833 }
66834
66835 #ifdef CONFIG_MODULES
66836 -static inline int within(void *addr, void *start, unsigned long size)
66837 -{
66838 - return ((addr >= start) && (addr < start + size));
66839 -}
66840 -
66841 /* Update list and generate events when modules are unloaded. */
66842 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66843 void *data)
66844 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66845 prev = NULL;
66846 /* Remove entries located in module from linked list. */
66847 for (info = gcov_info_head; info; info = info->next) {
66848 - if (within(info, mod->module_core, mod->core_size)) {
66849 + if (within_module_core_rw((unsigned long)info, mod)) {
66850 if (prev)
66851 prev->next = info->next;
66852 else
66853 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
66854 index 6db7a5e..25b6648 100644
66855 --- a/kernel/hrtimer.c
66856 +++ b/kernel/hrtimer.c
66857 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
66858 local_irq_restore(flags);
66859 }
66860
66861 -static void run_hrtimer_softirq(struct softirq_action *h)
66862 +static void run_hrtimer_softirq(void)
66863 {
66864 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
66865
66866 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
66867 index 4304919..408c4c0 100644
66868 --- a/kernel/jump_label.c
66869 +++ b/kernel/jump_label.c
66870 @@ -13,6 +13,7 @@
66871 #include <linux/sort.h>
66872 #include <linux/err.h>
66873 #include <linux/static_key.h>
66874 +#include <linux/mm.h>
66875
66876 #ifdef HAVE_JUMP_LABEL
66877
66878 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
66879
66880 size = (((unsigned long)stop - (unsigned long)start)
66881 / sizeof(struct jump_entry));
66882 + pax_open_kernel();
66883 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
66884 + pax_close_kernel();
66885 }
66886
66887 static void jump_label_update(struct static_key *key, int enable);
66888 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
66889 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
66890 struct jump_entry *iter;
66891
66892 + pax_open_kernel();
66893 for (iter = iter_start; iter < iter_stop; iter++) {
66894 if (within_module_init(iter->code, mod))
66895 iter->code = 0;
66896 }
66897 + pax_close_kernel();
66898 }
66899
66900 static int
66901 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
66902 index 2169fee..45c017a 100644
66903 --- a/kernel/kallsyms.c
66904 +++ b/kernel/kallsyms.c
66905 @@ -11,6 +11,9 @@
66906 * Changed the compression method from stem compression to "table lookup"
66907 * compression (see scripts/kallsyms.c for a more complete description)
66908 */
66909 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66910 +#define __INCLUDED_BY_HIDESYM 1
66911 +#endif
66912 #include <linux/kallsyms.h>
66913 #include <linux/module.h>
66914 #include <linux/init.h>
66915 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
66916
66917 static inline int is_kernel_inittext(unsigned long addr)
66918 {
66919 + if (system_state != SYSTEM_BOOTING)
66920 + return 0;
66921 +
66922 if (addr >= (unsigned long)_sinittext
66923 && addr <= (unsigned long)_einittext)
66924 return 1;
66925 return 0;
66926 }
66927
66928 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66929 +#ifdef CONFIG_MODULES
66930 +static inline int is_module_text(unsigned long addr)
66931 +{
66932 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
66933 + return 1;
66934 +
66935 + addr = ktla_ktva(addr);
66936 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
66937 +}
66938 +#else
66939 +static inline int is_module_text(unsigned long addr)
66940 +{
66941 + return 0;
66942 +}
66943 +#endif
66944 +#endif
66945 +
66946 static inline int is_kernel_text(unsigned long addr)
66947 {
66948 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
66949 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
66950
66951 static inline int is_kernel(unsigned long addr)
66952 {
66953 +
66954 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66955 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
66956 + return 1;
66957 +
66958 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
66959 +#else
66960 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
66961 +#endif
66962 +
66963 return 1;
66964 return in_gate_area_no_mm(addr);
66965 }
66966
66967 static int is_ksym_addr(unsigned long addr)
66968 {
66969 +
66970 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66971 + if (is_module_text(addr))
66972 + return 0;
66973 +#endif
66974 +
66975 if (all_var)
66976 return is_kernel(addr);
66977
66978 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
66979
66980 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
66981 {
66982 - iter->name[0] = '\0';
66983 iter->nameoff = get_symbol_offset(new_pos);
66984 iter->pos = new_pos;
66985 }
66986 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
66987 {
66988 struct kallsym_iter *iter = m->private;
66989
66990 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66991 + if (current_uid())
66992 + return 0;
66993 +#endif
66994 +
66995 /* Some debugging symbols have no name. Ignore them. */
66996 if (!iter->name[0])
66997 return 0;
66998 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
66999 */
67000 type = iter->exported ? toupper(iter->type) :
67001 tolower(iter->type);
67002 +
67003 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67004 type, iter->name, iter->module_name);
67005 } else
67006 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67007 struct kallsym_iter *iter;
67008 int ret;
67009
67010 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67011 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67012 if (!iter)
67013 return -ENOMEM;
67014 reset_iter(iter, 0);
67015 diff --git a/kernel/kexec.c b/kernel/kexec.c
67016 index 4e2e472..cd0c7ae 100644
67017 --- a/kernel/kexec.c
67018 +++ b/kernel/kexec.c
67019 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67020 unsigned long flags)
67021 {
67022 struct compat_kexec_segment in;
67023 - struct kexec_segment out, __user *ksegments;
67024 + struct kexec_segment out;
67025 + struct kexec_segment __user *ksegments;
67026 unsigned long i, result;
67027
67028 /* Don't allow clients that don't understand the native
67029 diff --git a/kernel/kmod.c b/kernel/kmod.c
67030 index ff2c7cb..085d7af 100644
67031 --- a/kernel/kmod.c
67032 +++ b/kernel/kmod.c
67033 @@ -66,7 +66,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67034 kfree(info->argv);
67035 }
67036
67037 -static int call_modprobe(char *module_name, int wait)
67038 +static int call_modprobe(char *module_name, char *module_param, int wait)
67039 {
67040 static char *envp[] = {
67041 "HOME=/",
67042 @@ -75,7 +75,7 @@ static int call_modprobe(char *module_name, int wait)
67043 NULL
67044 };
67045
67046 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67047 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67048 if (!argv)
67049 goto out;
67050
67051 @@ -87,7 +87,8 @@ static int call_modprobe(char *module_name, int wait)
67052 argv[1] = "-q";
67053 argv[2] = "--";
67054 argv[3] = module_name; /* check free_modprobe_argv() */
67055 - argv[4] = NULL;
67056 + argv[4] = module_param;
67057 + argv[5] = NULL;
67058
67059 return call_usermodehelper_fns(modprobe_path, argv, envp,
67060 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67061 @@ -112,9 +113,8 @@ out:
67062 * If module auto-loading support is disabled then this function
67063 * becomes a no-operation.
67064 */
67065 -int __request_module(bool wait, const char *fmt, ...)
67066 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67067 {
67068 - va_list args;
67069 char module_name[MODULE_NAME_LEN];
67070 unsigned int max_modprobes;
67071 int ret;
67072 @@ -122,9 +122,7 @@ int __request_module(bool wait, const char *fmt, ...)
67073 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67074 static int kmod_loop_msg;
67075
67076 - va_start(args, fmt);
67077 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67078 - va_end(args);
67079 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67080 if (ret >= MODULE_NAME_LEN)
67081 return -ENAMETOOLONG;
67082
67083 @@ -132,6 +130,20 @@ int __request_module(bool wait, const char *fmt, ...)
67084 if (ret)
67085 return ret;
67086
67087 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67088 + if (!current_uid()) {
67089 + /* hack to workaround consolekit/udisks stupidity */
67090 + read_lock(&tasklist_lock);
67091 + if (!strcmp(current->comm, "mount") &&
67092 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67093 + read_unlock(&tasklist_lock);
67094 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67095 + return -EPERM;
67096 + }
67097 + read_unlock(&tasklist_lock);
67098 + }
67099 +#endif
67100 +
67101 /* If modprobe needs a service that is in a module, we get a recursive
67102 * loop. Limit the number of running kmod threads to max_threads/2 or
67103 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67104 @@ -160,11 +172,52 @@ int __request_module(bool wait, const char *fmt, ...)
67105
67106 trace_module_request(module_name, wait, _RET_IP_);
67107
67108 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67109 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67110
67111 atomic_dec(&kmod_concurrent);
67112 return ret;
67113 }
67114 +
67115 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67116 +{
67117 + va_list args;
67118 + int ret;
67119 +
67120 + va_start(args, fmt);
67121 + ret = ____request_module(wait, module_param, fmt, args);
67122 + va_end(args);
67123 +
67124 + return ret;
67125 +}
67126 +
67127 +int __request_module(bool wait, const char *fmt, ...)
67128 +{
67129 + va_list args;
67130 + int ret;
67131 +
67132 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67133 + if (current_uid()) {
67134 + char module_param[MODULE_NAME_LEN];
67135 +
67136 + memset(module_param, 0, sizeof(module_param));
67137 +
67138 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67139 +
67140 + va_start(args, fmt);
67141 + ret = ____request_module(wait, module_param, fmt, args);
67142 + va_end(args);
67143 +
67144 + return ret;
67145 + }
67146 +#endif
67147 +
67148 + va_start(args, fmt);
67149 + ret = ____request_module(wait, NULL, fmt, args);
67150 + va_end(args);
67151 +
67152 + return ret;
67153 +}
67154 +
67155 EXPORT_SYMBOL(__request_module);
67156 #endif /* CONFIG_MODULES */
67157
67158 @@ -266,7 +319,7 @@ static int wait_for_helper(void *data)
67159 *
67160 * Thus the __user pointer cast is valid here.
67161 */
67162 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
67163 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67164
67165 /*
67166 * If ret is 0, either ____call_usermodehelper failed and the
67167 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67168 index c62b854..cb67968 100644
67169 --- a/kernel/kprobes.c
67170 +++ b/kernel/kprobes.c
67171 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67172 * kernel image and loaded module images reside. This is required
67173 * so x86_64 can correctly handle the %rip-relative fixups.
67174 */
67175 - kip->insns = module_alloc(PAGE_SIZE);
67176 + kip->insns = module_alloc_exec(PAGE_SIZE);
67177 if (!kip->insns) {
67178 kfree(kip);
67179 return NULL;
67180 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67181 */
67182 if (!list_is_singular(&kip->list)) {
67183 list_del(&kip->list);
67184 - module_free(NULL, kip->insns);
67185 + module_free_exec(NULL, kip->insns);
67186 kfree(kip);
67187 }
67188 return 1;
67189 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67190 {
67191 int i, err = 0;
67192 unsigned long offset = 0, size = 0;
67193 - char *modname, namebuf[128];
67194 + char *modname, namebuf[KSYM_NAME_LEN];
67195 const char *symbol_name;
67196 void *addr;
67197 struct kprobe_blackpoint *kb;
67198 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67199 const char *sym = NULL;
67200 unsigned int i = *(loff_t *) v;
67201 unsigned long offset = 0;
67202 - char *modname, namebuf[128];
67203 + char *modname, namebuf[KSYM_NAME_LEN];
67204
67205 head = &kprobe_table[i];
67206 preempt_disable();
67207 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67208 index 4e316e1..5501eef 100644
67209 --- a/kernel/ksysfs.c
67210 +++ b/kernel/ksysfs.c
67211 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67212 {
67213 if (count+1 > UEVENT_HELPER_PATH_LEN)
67214 return -ENOENT;
67215 + if (!capable(CAP_SYS_ADMIN))
67216 + return -EPERM;
67217 memcpy(uevent_helper, buf, count);
67218 uevent_helper[count] = '\0';
67219 if (count && uevent_helper[count-1] == '\n')
67220 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67221 index ea9ee45..67ebc8f 100644
67222 --- a/kernel/lockdep.c
67223 +++ b/kernel/lockdep.c
67224 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
67225 end = (unsigned long) &_end,
67226 addr = (unsigned long) obj;
67227
67228 +#ifdef CONFIG_PAX_KERNEXEC
67229 + start = ktla_ktva(start);
67230 +#endif
67231 +
67232 /*
67233 * static variable?
67234 */
67235 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67236 if (!static_obj(lock->key)) {
67237 debug_locks_off();
67238 printk("INFO: trying to register non-static key.\n");
67239 + printk("lock:%pS key:%pS.\n", lock, lock->key);
67240 printk("the code is fine but needs lockdep annotation.\n");
67241 printk("turning off the locking correctness validator.\n");
67242 dump_stack();
67243 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67244 if (!class)
67245 return 0;
67246 }
67247 - atomic_inc((atomic_t *)&class->ops);
67248 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67249 if (very_verbose(class)) {
67250 printk("\nacquire class [%p] %s", class->key, class->name);
67251 if (class->name_version > 1)
67252 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67253 index 91c32a0..b2c71c5 100644
67254 --- a/kernel/lockdep_proc.c
67255 +++ b/kernel/lockdep_proc.c
67256 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67257
67258 static void print_name(struct seq_file *m, struct lock_class *class)
67259 {
67260 - char str[128];
67261 + char str[KSYM_NAME_LEN];
67262 const char *name = class->name;
67263
67264 if (!name) {
67265 diff --git a/kernel/module.c b/kernel/module.c
67266 index 4edbd9c..165e780 100644
67267 --- a/kernel/module.c
67268 +++ b/kernel/module.c
67269 @@ -58,6 +58,7 @@
67270 #include <linux/jump_label.h>
67271 #include <linux/pfn.h>
67272 #include <linux/bsearch.h>
67273 +#include <linux/grsecurity.h>
67274
67275 #define CREATE_TRACE_POINTS
67276 #include <trace/events/module.h>
67277 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
67278
67279 /* Bounds of module allocation, for speeding __module_address.
67280 * Protected by module_mutex. */
67281 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
67282 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
67283 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
67284
67285 int register_module_notifier(struct notifier_block * nb)
67286 {
67287 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67288 return true;
67289
67290 list_for_each_entry_rcu(mod, &modules, list) {
67291 - struct symsearch arr[] = {
67292 + struct symsearch modarr[] = {
67293 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
67294 NOT_GPL_ONLY, false },
67295 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
67296 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67297 #endif
67298 };
67299
67300 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
67301 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
67302 return true;
67303 }
67304 return false;
67305 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
67306 static int percpu_modalloc(struct module *mod,
67307 unsigned long size, unsigned long align)
67308 {
67309 - if (align > PAGE_SIZE) {
67310 + if (align-1 >= PAGE_SIZE) {
67311 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
67312 mod->name, align, PAGE_SIZE);
67313 align = PAGE_SIZE;
67314 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
67315 static ssize_t show_coresize(struct module_attribute *mattr,
67316 struct module_kobject *mk, char *buffer)
67317 {
67318 - return sprintf(buffer, "%u\n", mk->mod->core_size);
67319 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
67320 }
67321
67322 static struct module_attribute modinfo_coresize =
67323 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
67324 static ssize_t show_initsize(struct module_attribute *mattr,
67325 struct module_kobject *mk, char *buffer)
67326 {
67327 - return sprintf(buffer, "%u\n", mk->mod->init_size);
67328 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
67329 }
67330
67331 static struct module_attribute modinfo_initsize =
67332 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
67333 */
67334 #ifdef CONFIG_SYSFS
67335
67336 -#ifdef CONFIG_KALLSYMS
67337 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67338 static inline bool sect_empty(const Elf_Shdr *sect)
67339 {
67340 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
67341 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
67342
67343 static void unset_module_core_ro_nx(struct module *mod)
67344 {
67345 - set_page_attributes(mod->module_core + mod->core_text_size,
67346 - mod->module_core + mod->core_size,
67347 + set_page_attributes(mod->module_core_rw,
67348 + mod->module_core_rw + mod->core_size_rw,
67349 set_memory_x);
67350 - set_page_attributes(mod->module_core,
67351 - mod->module_core + mod->core_ro_size,
67352 + set_page_attributes(mod->module_core_rx,
67353 + mod->module_core_rx + mod->core_size_rx,
67354 set_memory_rw);
67355 }
67356
67357 static void unset_module_init_ro_nx(struct module *mod)
67358 {
67359 - set_page_attributes(mod->module_init + mod->init_text_size,
67360 - mod->module_init + mod->init_size,
67361 + set_page_attributes(mod->module_init_rw,
67362 + mod->module_init_rw + mod->init_size_rw,
67363 set_memory_x);
67364 - set_page_attributes(mod->module_init,
67365 - mod->module_init + mod->init_ro_size,
67366 + set_page_attributes(mod->module_init_rx,
67367 + mod->module_init_rx + mod->init_size_rx,
67368 set_memory_rw);
67369 }
67370
67371 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
67372
67373 mutex_lock(&module_mutex);
67374 list_for_each_entry_rcu(mod, &modules, list) {
67375 - if ((mod->module_core) && (mod->core_text_size)) {
67376 - set_page_attributes(mod->module_core,
67377 - mod->module_core + mod->core_text_size,
67378 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
67379 + set_page_attributes(mod->module_core_rx,
67380 + mod->module_core_rx + mod->core_size_rx,
67381 set_memory_rw);
67382 }
67383 - if ((mod->module_init) && (mod->init_text_size)) {
67384 - set_page_attributes(mod->module_init,
67385 - mod->module_init + mod->init_text_size,
67386 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
67387 + set_page_attributes(mod->module_init_rx,
67388 + mod->module_init_rx + mod->init_size_rx,
67389 set_memory_rw);
67390 }
67391 }
67392 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
67393
67394 mutex_lock(&module_mutex);
67395 list_for_each_entry_rcu(mod, &modules, list) {
67396 - if ((mod->module_core) && (mod->core_text_size)) {
67397 - set_page_attributes(mod->module_core,
67398 - mod->module_core + mod->core_text_size,
67399 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
67400 + set_page_attributes(mod->module_core_rx,
67401 + mod->module_core_rx + mod->core_size_rx,
67402 set_memory_ro);
67403 }
67404 - if ((mod->module_init) && (mod->init_text_size)) {
67405 - set_page_attributes(mod->module_init,
67406 - mod->module_init + mod->init_text_size,
67407 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
67408 + set_page_attributes(mod->module_init_rx,
67409 + mod->module_init_rx + mod->init_size_rx,
67410 set_memory_ro);
67411 }
67412 }
67413 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
67414
67415 /* This may be NULL, but that's OK */
67416 unset_module_init_ro_nx(mod);
67417 - module_free(mod, mod->module_init);
67418 + module_free(mod, mod->module_init_rw);
67419 + module_free_exec(mod, mod->module_init_rx);
67420 kfree(mod->args);
67421 percpu_modfree(mod);
67422
67423 /* Free lock-classes: */
67424 - lockdep_free_key_range(mod->module_core, mod->core_size);
67425 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
67426 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
67427
67428 /* Finally, free the core (containing the module structure) */
67429 unset_module_core_ro_nx(mod);
67430 - module_free(mod, mod->module_core);
67431 + module_free_exec(mod, mod->module_core_rx);
67432 + module_free(mod, mod->module_core_rw);
67433
67434 #ifdef CONFIG_MPU
67435 update_protections(current->mm);
67436 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67437 int ret = 0;
67438 const struct kernel_symbol *ksym;
67439
67440 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67441 + int is_fs_load = 0;
67442 + int register_filesystem_found = 0;
67443 + char *p;
67444 +
67445 + p = strstr(mod->args, "grsec_modharden_fs");
67446 + if (p) {
67447 + char *endptr = p + strlen("grsec_modharden_fs");
67448 + /* copy \0 as well */
67449 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
67450 + is_fs_load = 1;
67451 + }
67452 +#endif
67453 +
67454 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
67455 const char *name = info->strtab + sym[i].st_name;
67456
67457 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67458 + /* it's a real shame this will never get ripped and copied
67459 + upstream! ;(
67460 + */
67461 + if (is_fs_load && !strcmp(name, "register_filesystem"))
67462 + register_filesystem_found = 1;
67463 +#endif
67464 +
67465 switch (sym[i].st_shndx) {
67466 case SHN_COMMON:
67467 /* We compiled with -fno-common. These are not
67468 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67469 ksym = resolve_symbol_wait(mod, info, name);
67470 /* Ok if resolved. */
67471 if (ksym && !IS_ERR(ksym)) {
67472 + pax_open_kernel();
67473 sym[i].st_value = ksym->value;
67474 + pax_close_kernel();
67475 break;
67476 }
67477
67478 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67479 secbase = (unsigned long)mod_percpu(mod);
67480 else
67481 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
67482 + pax_open_kernel();
67483 sym[i].st_value += secbase;
67484 + pax_close_kernel();
67485 break;
67486 }
67487 }
67488
67489 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67490 + if (is_fs_load && !register_filesystem_found) {
67491 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
67492 + ret = -EPERM;
67493 + }
67494 +#endif
67495 +
67496 return ret;
67497 }
67498
67499 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
67500 || s->sh_entsize != ~0UL
67501 || strstarts(sname, ".init"))
67502 continue;
67503 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
67504 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67505 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
67506 + else
67507 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
67508 pr_debug("\t%s\n", sname);
67509 }
67510 - switch (m) {
67511 - case 0: /* executable */
67512 - mod->core_size = debug_align(mod->core_size);
67513 - mod->core_text_size = mod->core_size;
67514 - break;
67515 - case 1: /* RO: text and ro-data */
67516 - mod->core_size = debug_align(mod->core_size);
67517 - mod->core_ro_size = mod->core_size;
67518 - break;
67519 - case 3: /* whole core */
67520 - mod->core_size = debug_align(mod->core_size);
67521 - break;
67522 - }
67523 }
67524
67525 pr_debug("Init section allocation order:\n");
67526 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67527 || s->sh_entsize != ~0UL
67528 || !strstarts(sname, ".init"))
67529 continue;
67530 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67531 - | INIT_OFFSET_MASK);
67532 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67533 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67534 + else
67535 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67536 + s->sh_entsize |= INIT_OFFSET_MASK;
67537 pr_debug("\t%s\n", sname);
67538 }
67539 - switch (m) {
67540 - case 0: /* executable */
67541 - mod->init_size = debug_align(mod->init_size);
67542 - mod->init_text_size = mod->init_size;
67543 - break;
67544 - case 1: /* RO: text and ro-data */
67545 - mod->init_size = debug_align(mod->init_size);
67546 - mod->init_ro_size = mod->init_size;
67547 - break;
67548 - case 3: /* whole init */
67549 - mod->init_size = debug_align(mod->init_size);
67550 - break;
67551 - }
67552 }
67553 }
67554
67555 @@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67556
67557 /* Put symbol section at end of init part of module. */
67558 symsect->sh_flags |= SHF_ALLOC;
67559 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67560 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67561 info->index.sym) | INIT_OFFSET_MASK;
67562 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
67563
67564 @@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67565 }
67566
67567 /* Append room for core symbols at end of core part. */
67568 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67569 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67570 - mod->core_size += strtab_size;
67571 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67572 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67573 + mod->core_size_rx += strtab_size;
67574
67575 /* Put string table section at end of init part of module. */
67576 strsect->sh_flags |= SHF_ALLOC;
67577 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67578 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67579 info->index.str) | INIT_OFFSET_MASK;
67580 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
67581 }
67582 @@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67583 /* Make sure we get permanent strtab: don't use info->strtab. */
67584 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67585
67586 + pax_open_kernel();
67587 +
67588 /* Set types up while we still have access to sections. */
67589 for (i = 0; i < mod->num_symtab; i++)
67590 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67591
67592 - mod->core_symtab = dst = mod->module_core + info->symoffs;
67593 - mod->core_strtab = s = mod->module_core + info->stroffs;
67594 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67595 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67596 src = mod->symtab;
67597 *dst = *src;
67598 *s++ = 0;
67599 @@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67600 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
67601 }
67602 mod->core_num_syms = ndst;
67603 +
67604 + pax_close_kernel();
67605 }
67606 #else
67607 static inline void layout_symtab(struct module *mod, struct load_info *info)
67608 @@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
67609 return size == 0 ? NULL : vmalloc_exec(size);
67610 }
67611
67612 -static void *module_alloc_update_bounds(unsigned long size)
67613 +static void *module_alloc_update_bounds_rw(unsigned long size)
67614 {
67615 void *ret = module_alloc(size);
67616
67617 if (ret) {
67618 mutex_lock(&module_mutex);
67619 /* Update module bounds. */
67620 - if ((unsigned long)ret < module_addr_min)
67621 - module_addr_min = (unsigned long)ret;
67622 - if ((unsigned long)ret + size > module_addr_max)
67623 - module_addr_max = (unsigned long)ret + size;
67624 + if ((unsigned long)ret < module_addr_min_rw)
67625 + module_addr_min_rw = (unsigned long)ret;
67626 + if ((unsigned long)ret + size > module_addr_max_rw)
67627 + module_addr_max_rw = (unsigned long)ret + size;
67628 + mutex_unlock(&module_mutex);
67629 + }
67630 + return ret;
67631 +}
67632 +
67633 +static void *module_alloc_update_bounds_rx(unsigned long size)
67634 +{
67635 + void *ret = module_alloc_exec(size);
67636 +
67637 + if (ret) {
67638 + mutex_lock(&module_mutex);
67639 + /* Update module bounds. */
67640 + if ((unsigned long)ret < module_addr_min_rx)
67641 + module_addr_min_rx = (unsigned long)ret;
67642 + if ((unsigned long)ret + size > module_addr_max_rx)
67643 + module_addr_max_rx = (unsigned long)ret + size;
67644 mutex_unlock(&module_mutex);
67645 }
67646 return ret;
67647 @@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
67648 static int check_modinfo(struct module *mod, struct load_info *info)
67649 {
67650 const char *modmagic = get_modinfo(info, "vermagic");
67651 + const char *license = get_modinfo(info, "license");
67652 int err;
67653
67654 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67655 + if (!license || !license_is_gpl_compatible(license))
67656 + return -ENOEXEC;
67657 +#endif
67658 +
67659 /* This is allowed: modprobe --force will invalidate it. */
67660 if (!modmagic) {
67661 err = try_to_force_load(mod, "bad vermagic");
67662 @@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67663 }
67664
67665 /* Set up license info based on the info section */
67666 - set_license(mod, get_modinfo(info, "license"));
67667 + set_license(mod, license);
67668
67669 return 0;
67670 }
67671 @@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
67672 void *ptr;
67673
67674 /* Do the allocs. */
67675 - ptr = module_alloc_update_bounds(mod->core_size);
67676 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67677 /*
67678 * The pointer to this block is stored in the module structure
67679 * which is inside the block. Just mark it as not being a
67680 @@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
67681 if (!ptr)
67682 return -ENOMEM;
67683
67684 - memset(ptr, 0, mod->core_size);
67685 - mod->module_core = ptr;
67686 + memset(ptr, 0, mod->core_size_rw);
67687 + mod->module_core_rw = ptr;
67688
67689 - ptr = module_alloc_update_bounds(mod->init_size);
67690 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67691 /*
67692 * The pointer to this block is stored in the module structure
67693 * which is inside the block. This block doesn't need to be
67694 * scanned as it contains data and code that will be freed
67695 * after the module is initialized.
67696 */
67697 - kmemleak_ignore(ptr);
67698 - if (!ptr && mod->init_size) {
67699 - module_free(mod, mod->module_core);
67700 + kmemleak_not_leak(ptr);
67701 + if (!ptr && mod->init_size_rw) {
67702 + module_free(mod, mod->module_core_rw);
67703 return -ENOMEM;
67704 }
67705 - memset(ptr, 0, mod->init_size);
67706 - mod->module_init = ptr;
67707 + memset(ptr, 0, mod->init_size_rw);
67708 + mod->module_init_rw = ptr;
67709 +
67710 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67711 + kmemleak_not_leak(ptr);
67712 + if (!ptr) {
67713 + module_free(mod, mod->module_init_rw);
67714 + module_free(mod, mod->module_core_rw);
67715 + return -ENOMEM;
67716 + }
67717 +
67718 + pax_open_kernel();
67719 + memset(ptr, 0, mod->core_size_rx);
67720 + pax_close_kernel();
67721 + mod->module_core_rx = ptr;
67722 +
67723 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67724 + kmemleak_not_leak(ptr);
67725 + if (!ptr && mod->init_size_rx) {
67726 + module_free_exec(mod, mod->module_core_rx);
67727 + module_free(mod, mod->module_init_rw);
67728 + module_free(mod, mod->module_core_rw);
67729 + return -ENOMEM;
67730 + }
67731 +
67732 + pax_open_kernel();
67733 + memset(ptr, 0, mod->init_size_rx);
67734 + pax_close_kernel();
67735 + mod->module_init_rx = ptr;
67736
67737 /* Transfer each section which specifies SHF_ALLOC */
67738 pr_debug("final section addresses:\n");
67739 @@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
67740 if (!(shdr->sh_flags & SHF_ALLOC))
67741 continue;
67742
67743 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
67744 - dest = mod->module_init
67745 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67746 - else
67747 - dest = mod->module_core + shdr->sh_entsize;
67748 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67749 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67750 + dest = mod->module_init_rw
67751 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67752 + else
67753 + dest = mod->module_init_rx
67754 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67755 + } else {
67756 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67757 + dest = mod->module_core_rw + shdr->sh_entsize;
67758 + else
67759 + dest = mod->module_core_rx + shdr->sh_entsize;
67760 + }
67761 +
67762 + if (shdr->sh_type != SHT_NOBITS) {
67763 +
67764 +#ifdef CONFIG_PAX_KERNEXEC
67765 +#ifdef CONFIG_X86_64
67766 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67767 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67768 +#endif
67769 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67770 + pax_open_kernel();
67771 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67772 + pax_close_kernel();
67773 + } else
67774 +#endif
67775
67776 - if (shdr->sh_type != SHT_NOBITS)
67777 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67778 + }
67779 /* Update sh_addr to point to copy in image. */
67780 - shdr->sh_addr = (unsigned long)dest;
67781 +
67782 +#ifdef CONFIG_PAX_KERNEXEC
67783 + if (shdr->sh_flags & SHF_EXECINSTR)
67784 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
67785 + else
67786 +#endif
67787 +
67788 + shdr->sh_addr = (unsigned long)dest;
67789 pr_debug("\t0x%lx %s\n",
67790 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
67791 }
67792 @@ -2759,12 +2859,12 @@ static void flush_module_icache(const struct module *mod)
67793 * Do it before processing of module parameters, so the module
67794 * can provide parameter accessor functions of its own.
67795 */
67796 - if (mod->module_init)
67797 - flush_icache_range((unsigned long)mod->module_init,
67798 - (unsigned long)mod->module_init
67799 - + mod->init_size);
67800 - flush_icache_range((unsigned long)mod->module_core,
67801 - (unsigned long)mod->module_core + mod->core_size);
67802 + if (mod->module_init_rx)
67803 + flush_icache_range((unsigned long)mod->module_init_rx,
67804 + (unsigned long)mod->module_init_rx
67805 + + mod->init_size_rx);
67806 + flush_icache_range((unsigned long)mod->module_core_rx,
67807 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
67808
67809 set_fs(old_fs);
67810 }
67811 @@ -2834,8 +2934,10 @@ out:
67812 static void module_deallocate(struct module *mod, struct load_info *info)
67813 {
67814 percpu_modfree(mod);
67815 - module_free(mod, mod->module_init);
67816 - module_free(mod, mod->module_core);
67817 + module_free_exec(mod, mod->module_init_rx);
67818 + module_free_exec(mod, mod->module_core_rx);
67819 + module_free(mod, mod->module_init_rw);
67820 + module_free(mod, mod->module_core_rw);
67821 }
67822
67823 int __weak module_finalize(const Elf_Ehdr *hdr,
67824 @@ -2848,7 +2950,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
67825 static int post_relocation(struct module *mod, const struct load_info *info)
67826 {
67827 /* Sort exception table now relocations are done. */
67828 + pax_open_kernel();
67829 sort_extable(mod->extable, mod->extable + mod->num_exentries);
67830 + pax_close_kernel();
67831
67832 /* Copy relocated percpu area over. */
67833 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
67834 @@ -2899,9 +3003,38 @@ static struct module *load_module(void __user *umod,
67835 if (err)
67836 goto free_unload;
67837
67838 + /* Now copy in args */
67839 + mod->args = strndup_user(uargs, ~0UL >> 1);
67840 + if (IS_ERR(mod->args)) {
67841 + err = PTR_ERR(mod->args);
67842 + goto free_unload;
67843 + }
67844 +
67845 /* Set up MODINFO_ATTR fields */
67846 setup_modinfo(mod, &info);
67847
67848 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67849 + {
67850 + char *p, *p2;
67851 +
67852 + if (strstr(mod->args, "grsec_modharden_netdev")) {
67853 + 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);
67854 + err = -EPERM;
67855 + goto free_modinfo;
67856 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
67857 + p += strlen("grsec_modharden_normal");
67858 + p2 = strstr(p, "_");
67859 + if (p2) {
67860 + *p2 = '\0';
67861 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
67862 + *p2 = '_';
67863 + }
67864 + err = -EPERM;
67865 + goto free_modinfo;
67866 + }
67867 + }
67868 +#endif
67869 +
67870 /* Fix up syms, so that st_value is a pointer to location. */
67871 err = simplify_symbols(mod, &info);
67872 if (err < 0)
67873 @@ -2917,13 +3050,6 @@ static struct module *load_module(void __user *umod,
67874
67875 flush_module_icache(mod);
67876
67877 - /* Now copy in args */
67878 - mod->args = strndup_user(uargs, ~0UL >> 1);
67879 - if (IS_ERR(mod->args)) {
67880 - err = PTR_ERR(mod->args);
67881 - goto free_arch_cleanup;
67882 - }
67883 -
67884 /* Mark state as coming so strong_try_module_get() ignores us. */
67885 mod->state = MODULE_STATE_COMING;
67886
67887 @@ -2981,11 +3107,10 @@ static struct module *load_module(void __user *umod,
67888 unlock:
67889 mutex_unlock(&module_mutex);
67890 synchronize_sched();
67891 - kfree(mod->args);
67892 - free_arch_cleanup:
67893 module_arch_cleanup(mod);
67894 free_modinfo:
67895 free_modinfo(mod);
67896 + kfree(mod->args);
67897 free_unload:
67898 module_unload_free(mod);
67899 free_module:
67900 @@ -3026,16 +3151,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67901 MODULE_STATE_COMING, mod);
67902
67903 /* Set RO and NX regions for core */
67904 - set_section_ro_nx(mod->module_core,
67905 - mod->core_text_size,
67906 - mod->core_ro_size,
67907 - mod->core_size);
67908 + set_section_ro_nx(mod->module_core_rx,
67909 + mod->core_size_rx,
67910 + mod->core_size_rx,
67911 + mod->core_size_rx);
67912
67913 /* Set RO and NX regions for init */
67914 - set_section_ro_nx(mod->module_init,
67915 - mod->init_text_size,
67916 - mod->init_ro_size,
67917 - mod->init_size);
67918 + set_section_ro_nx(mod->module_init_rx,
67919 + mod->init_size_rx,
67920 + mod->init_size_rx,
67921 + mod->init_size_rx);
67922
67923 do_mod_ctors(mod);
67924 /* Start the module */
67925 @@ -3081,11 +3206,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67926 mod->strtab = mod->core_strtab;
67927 #endif
67928 unset_module_init_ro_nx(mod);
67929 - module_free(mod, mod->module_init);
67930 - mod->module_init = NULL;
67931 - mod->init_size = 0;
67932 - mod->init_ro_size = 0;
67933 - mod->init_text_size = 0;
67934 + module_free(mod, mod->module_init_rw);
67935 + module_free_exec(mod, mod->module_init_rx);
67936 + mod->module_init_rw = NULL;
67937 + mod->module_init_rx = NULL;
67938 + mod->init_size_rw = 0;
67939 + mod->init_size_rx = 0;
67940 mutex_unlock(&module_mutex);
67941
67942 return 0;
67943 @@ -3116,10 +3242,16 @@ static const char *get_ksymbol(struct module *mod,
67944 unsigned long nextval;
67945
67946 /* At worse, next value is at end of module */
67947 - if (within_module_init(addr, mod))
67948 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
67949 + if (within_module_init_rx(addr, mod))
67950 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
67951 + else if (within_module_init_rw(addr, mod))
67952 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
67953 + else if (within_module_core_rx(addr, mod))
67954 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
67955 + else if (within_module_core_rw(addr, mod))
67956 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
67957 else
67958 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
67959 + return NULL;
67960
67961 /* Scan for closest preceding symbol, and next symbol. (ELF
67962 starts real symbols at 1). */
67963 @@ -3354,7 +3486,7 @@ static int m_show(struct seq_file *m, void *p)
67964 char buf[8];
67965
67966 seq_printf(m, "%s %u",
67967 - mod->name, mod->init_size + mod->core_size);
67968 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
67969 print_unload_info(m, mod);
67970
67971 /* Informative for users. */
67972 @@ -3363,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
67973 mod->state == MODULE_STATE_COMING ? "Loading":
67974 "Live");
67975 /* Used by oprofile and other similar tools. */
67976 - seq_printf(m, " 0x%pK", mod->module_core);
67977 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
67978
67979 /* Taints info */
67980 if (mod->taints)
67981 @@ -3399,7 +3531,17 @@ static const struct file_operations proc_modules_operations = {
67982
67983 static int __init proc_modules_init(void)
67984 {
67985 +#ifndef CONFIG_GRKERNSEC_HIDESYM
67986 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67987 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67988 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67989 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
67990 +#else
67991 proc_create("modules", 0, NULL, &proc_modules_operations);
67992 +#endif
67993 +#else
67994 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67995 +#endif
67996 return 0;
67997 }
67998 module_init(proc_modules_init);
67999 @@ -3458,12 +3600,12 @@ struct module *__module_address(unsigned long addr)
68000 {
68001 struct module *mod;
68002
68003 - if (addr < module_addr_min || addr > module_addr_max)
68004 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68005 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68006 return NULL;
68007
68008 list_for_each_entry_rcu(mod, &modules, list)
68009 - if (within_module_core(addr, mod)
68010 - || within_module_init(addr, mod))
68011 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68012 return mod;
68013 return NULL;
68014 }
68015 @@ -3497,11 +3639,20 @@ bool is_module_text_address(unsigned long addr)
68016 */
68017 struct module *__module_text_address(unsigned long addr)
68018 {
68019 - struct module *mod = __module_address(addr);
68020 + struct module *mod;
68021 +
68022 +#ifdef CONFIG_X86_32
68023 + addr = ktla_ktva(addr);
68024 +#endif
68025 +
68026 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68027 + return NULL;
68028 +
68029 + mod = __module_address(addr);
68030 +
68031 if (mod) {
68032 /* Make sure it's within the text section. */
68033 - if (!within(addr, mod->module_init, mod->init_text_size)
68034 - && !within(addr, mod->module_core, mod->core_text_size))
68035 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68036 mod = NULL;
68037 }
68038 return mod;
68039 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68040 index 7e3443f..b2a1e6b 100644
68041 --- a/kernel/mutex-debug.c
68042 +++ b/kernel/mutex-debug.c
68043 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68044 }
68045
68046 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68047 - struct thread_info *ti)
68048 + struct task_struct *task)
68049 {
68050 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68051
68052 /* Mark the current thread as blocked on the lock: */
68053 - ti->task->blocked_on = waiter;
68054 + task->blocked_on = waiter;
68055 }
68056
68057 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68058 - struct thread_info *ti)
68059 + struct task_struct *task)
68060 {
68061 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68062 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68063 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68064 - ti->task->blocked_on = NULL;
68065 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
68066 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68067 + task->blocked_on = NULL;
68068
68069 list_del_init(&waiter->list);
68070 waiter->task = NULL;
68071 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68072 index 0799fd3..d06ae3b 100644
68073 --- a/kernel/mutex-debug.h
68074 +++ b/kernel/mutex-debug.h
68075 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68076 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68077 extern void debug_mutex_add_waiter(struct mutex *lock,
68078 struct mutex_waiter *waiter,
68079 - struct thread_info *ti);
68080 + struct task_struct *task);
68081 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68082 - struct thread_info *ti);
68083 + struct task_struct *task);
68084 extern void debug_mutex_unlock(struct mutex *lock);
68085 extern void debug_mutex_init(struct mutex *lock, const char *name,
68086 struct lock_class_key *key);
68087 diff --git a/kernel/mutex.c b/kernel/mutex.c
68088 index a307cc9..27fd2e9 100644
68089 --- a/kernel/mutex.c
68090 +++ b/kernel/mutex.c
68091 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68092 spin_lock_mutex(&lock->wait_lock, flags);
68093
68094 debug_mutex_lock_common(lock, &waiter);
68095 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68096 + debug_mutex_add_waiter(lock, &waiter, task);
68097
68098 /* add waiting tasks to the end of the waitqueue (FIFO): */
68099 list_add_tail(&waiter.list, &lock->wait_list);
68100 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68101 * TASK_UNINTERRUPTIBLE case.)
68102 */
68103 if (unlikely(signal_pending_state(state, task))) {
68104 - mutex_remove_waiter(lock, &waiter,
68105 - task_thread_info(task));
68106 + mutex_remove_waiter(lock, &waiter, task);
68107 mutex_release(&lock->dep_map, 1, ip);
68108 spin_unlock_mutex(&lock->wait_lock, flags);
68109
68110 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68111 done:
68112 lock_acquired(&lock->dep_map, ip);
68113 /* got the lock - rejoice! */
68114 - mutex_remove_waiter(lock, &waiter, current_thread_info());
68115 + mutex_remove_waiter(lock, &waiter, task);
68116 mutex_set_owner(lock);
68117
68118 /* set it to 0 if there are no waiters left: */
68119 diff --git a/kernel/panic.c b/kernel/panic.c
68120 index d2a5f4e..5edc1d9 100644
68121 --- a/kernel/panic.c
68122 +++ b/kernel/panic.c
68123 @@ -75,6 +75,14 @@ void panic(const char *fmt, ...)
68124 int state = 0;
68125
68126 /*
68127 + * Disable local interrupts. This will prevent panic_smp_self_stop
68128 + * from deadlocking the first cpu that invokes the panic, since
68129 + * there is nothing to prevent an interrupt handler (that runs
68130 + * after the panic_lock is acquired) from invoking panic again.
68131 + */
68132 + local_irq_disable();
68133 +
68134 + /*
68135 * It's possible to come here directly from a panic-assertion and
68136 * not have preempt disabled. Some functions called from here want
68137 * preempt to be disabled. No point enabling it later though...
68138 @@ -402,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68139 const char *board;
68140
68141 printk(KERN_WARNING "------------[ cut here ]------------\n");
68142 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68143 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68144 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68145 if (board)
68146 printk(KERN_WARNING "Hardware name: %s\n", board);
68147 @@ -457,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68148 */
68149 void __stack_chk_fail(void)
68150 {
68151 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
68152 + dump_stack();
68153 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68154 __builtin_return_address(0));
68155 }
68156 EXPORT_SYMBOL(__stack_chk_fail);
68157 diff --git a/kernel/pid.c b/kernel/pid.c
68158 index e86b291a..e8b0fb5 100644
68159 --- a/kernel/pid.c
68160 +++ b/kernel/pid.c
68161 @@ -33,6 +33,7 @@
68162 #include <linux/rculist.h>
68163 #include <linux/bootmem.h>
68164 #include <linux/hash.h>
68165 +#include <linux/security.h>
68166 #include <linux/pid_namespace.h>
68167 #include <linux/init_task.h>
68168 #include <linux/syscalls.h>
68169 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68170
68171 int pid_max = PID_MAX_DEFAULT;
68172
68173 -#define RESERVED_PIDS 300
68174 +#define RESERVED_PIDS 500
68175
68176 int pid_max_min = RESERVED_PIDS + 1;
68177 int pid_max_max = PID_MAX_LIMIT;
68178 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68179 */
68180 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68181 {
68182 + struct task_struct *task;
68183 +
68184 rcu_lockdep_assert(rcu_read_lock_held(),
68185 "find_task_by_pid_ns() needs rcu_read_lock()"
68186 " protection");
68187 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68188 +
68189 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68190 +
68191 + if (gr_pid_is_chrooted(task))
68192 + return NULL;
68193 +
68194 + return task;
68195 }
68196
68197 struct task_struct *find_task_by_vpid(pid_t vnr)
68198 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68199 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68200 }
68201
68202 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68203 +{
68204 + rcu_lockdep_assert(rcu_read_lock_held(),
68205 + "find_task_by_pid_ns() needs rcu_read_lock()"
68206 + " protection");
68207 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68208 +}
68209 +
68210 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68211 {
68212 struct pid *pid;
68213 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68214 index 125cb67..a4d1c30 100644
68215 --- a/kernel/posix-cpu-timers.c
68216 +++ b/kernel/posix-cpu-timers.c
68217 @@ -6,6 +6,7 @@
68218 #include <linux/posix-timers.h>
68219 #include <linux/errno.h>
68220 #include <linux/math64.h>
68221 +#include <linux/security.h>
68222 #include <asm/uaccess.h>
68223 #include <linux/kernel_stat.h>
68224 #include <trace/events/timer.h>
68225 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
68226
68227 static __init int init_posix_cpu_timers(void)
68228 {
68229 - struct k_clock process = {
68230 + static struct k_clock process = {
68231 .clock_getres = process_cpu_clock_getres,
68232 .clock_get = process_cpu_clock_get,
68233 .timer_create = process_cpu_timer_create,
68234 .nsleep = process_cpu_nsleep,
68235 .nsleep_restart = process_cpu_nsleep_restart,
68236 };
68237 - struct k_clock thread = {
68238 + static struct k_clock thread = {
68239 .clock_getres = thread_cpu_clock_getres,
68240 .clock_get = thread_cpu_clock_get,
68241 .timer_create = thread_cpu_timer_create,
68242 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68243 index 69185ae..cc2847a 100644
68244 --- a/kernel/posix-timers.c
68245 +++ b/kernel/posix-timers.c
68246 @@ -43,6 +43,7 @@
68247 #include <linux/idr.h>
68248 #include <linux/posix-clock.h>
68249 #include <linux/posix-timers.h>
68250 +#include <linux/grsecurity.h>
68251 #include <linux/syscalls.h>
68252 #include <linux/wait.h>
68253 #include <linux/workqueue.h>
68254 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68255 * which we beg off on and pass to do_sys_settimeofday().
68256 */
68257
68258 -static struct k_clock posix_clocks[MAX_CLOCKS];
68259 +static struct k_clock *posix_clocks[MAX_CLOCKS];
68260
68261 /*
68262 * These ones are defined below.
68263 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68264 */
68265 static __init int init_posix_timers(void)
68266 {
68267 - struct k_clock clock_realtime = {
68268 + static struct k_clock clock_realtime = {
68269 .clock_getres = hrtimer_get_res,
68270 .clock_get = posix_clock_realtime_get,
68271 .clock_set = posix_clock_realtime_set,
68272 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68273 .timer_get = common_timer_get,
68274 .timer_del = common_timer_del,
68275 };
68276 - struct k_clock clock_monotonic = {
68277 + static struct k_clock clock_monotonic = {
68278 .clock_getres = hrtimer_get_res,
68279 .clock_get = posix_ktime_get_ts,
68280 .nsleep = common_nsleep,
68281 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
68282 .timer_get = common_timer_get,
68283 .timer_del = common_timer_del,
68284 };
68285 - struct k_clock clock_monotonic_raw = {
68286 + static struct k_clock clock_monotonic_raw = {
68287 .clock_getres = hrtimer_get_res,
68288 .clock_get = posix_get_monotonic_raw,
68289 };
68290 - struct k_clock clock_realtime_coarse = {
68291 + static struct k_clock clock_realtime_coarse = {
68292 .clock_getres = posix_get_coarse_res,
68293 .clock_get = posix_get_realtime_coarse,
68294 };
68295 - struct k_clock clock_monotonic_coarse = {
68296 + static struct k_clock clock_monotonic_coarse = {
68297 .clock_getres = posix_get_coarse_res,
68298 .clock_get = posix_get_monotonic_coarse,
68299 };
68300 - struct k_clock clock_boottime = {
68301 + static struct k_clock clock_boottime = {
68302 .clock_getres = hrtimer_get_res,
68303 .clock_get = posix_get_boottime,
68304 .nsleep = common_nsleep,
68305 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
68306 return;
68307 }
68308
68309 - posix_clocks[clock_id] = *new_clock;
68310 + posix_clocks[clock_id] = new_clock;
68311 }
68312 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
68313
68314 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
68315 return (id & CLOCKFD_MASK) == CLOCKFD ?
68316 &clock_posix_dynamic : &clock_posix_cpu;
68317
68318 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
68319 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
68320 return NULL;
68321 - return &posix_clocks[id];
68322 + return posix_clocks[id];
68323 }
68324
68325 static int common_timer_create(struct k_itimer *new_timer)
68326 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
68327 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
68328 return -EFAULT;
68329
68330 + /* only the CLOCK_REALTIME clock can be set, all other clocks
68331 + have their clock_set fptr set to a nosettime dummy function
68332 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
68333 + call common_clock_set, which calls do_sys_settimeofday, which
68334 + we hook
68335 + */
68336 +
68337 return kc->clock_set(which_clock, &new_tp);
68338 }
68339
68340 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
68341 index d523593..68197a4 100644
68342 --- a/kernel/power/poweroff.c
68343 +++ b/kernel/power/poweroff.c
68344 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
68345 .enable_mask = SYSRQ_ENABLE_BOOT,
68346 };
68347
68348 -static int pm_sysrq_init(void)
68349 +static int __init pm_sysrq_init(void)
68350 {
68351 register_sysrq_key('o', &sysrq_poweroff_op);
68352 return 0;
68353 diff --git a/kernel/power/process.c b/kernel/power/process.c
68354 index 19db29f..33b52b6 100644
68355 --- a/kernel/power/process.c
68356 +++ b/kernel/power/process.c
68357 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
68358 u64 elapsed_csecs64;
68359 unsigned int elapsed_csecs;
68360 bool wakeup = false;
68361 + bool timedout = false;
68362
68363 do_gettimeofday(&start);
68364
68365 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
68366
68367 while (true) {
68368 todo = 0;
68369 + if (time_after(jiffies, end_time))
68370 + timedout = true;
68371 read_lock(&tasklist_lock);
68372 do_each_thread(g, p) {
68373 if (p == current || !freeze_task(p))
68374 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
68375 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
68376 * transition can't race with task state testing here.
68377 */
68378 - if (!task_is_stopped_or_traced(p) &&
68379 - !freezer_should_skip(p))
68380 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
68381 todo++;
68382 + if (timedout) {
68383 + printk(KERN_ERR "Task refusing to freeze:\n");
68384 + sched_show_task(p);
68385 + }
68386 + }
68387 } while_each_thread(g, p);
68388 read_unlock(&tasklist_lock);
68389
68390 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
68391 todo += wq_busy;
68392 }
68393
68394 - if (!todo || time_after(jiffies, end_time))
68395 + if (!todo || timedout)
68396 break;
68397
68398 if (pm_wakeup_pending()) {
68399 diff --git a/kernel/printk.c b/kernel/printk.c
68400 index 21bea76..f55ef3e 100644
68401 --- a/kernel/printk.c
68402 +++ b/kernel/printk.c
68403 @@ -782,6 +782,11 @@ static int check_syslog_permissions(int type, bool from_file)
68404 if (from_file && type != SYSLOG_ACTION_OPEN)
68405 return 0;
68406
68407 +#ifdef CONFIG_GRKERNSEC_DMESG
68408 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
68409 + return -EPERM;
68410 +#endif
68411 +
68412 if (syslog_action_restricted(type)) {
68413 if (capable(CAP_SYSLOG))
68414 return 0;
68415 diff --git a/kernel/profile.c b/kernel/profile.c
68416 index 76b8e77..a2930e8 100644
68417 --- a/kernel/profile.c
68418 +++ b/kernel/profile.c
68419 @@ -39,7 +39,7 @@ struct profile_hit {
68420 /* Oprofile timer tick hook */
68421 static int (*timer_hook)(struct pt_regs *) __read_mostly;
68422
68423 -static atomic_t *prof_buffer;
68424 +static atomic_unchecked_t *prof_buffer;
68425 static unsigned long prof_len, prof_shift;
68426
68427 int prof_on __read_mostly;
68428 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
68429 hits[i].pc = 0;
68430 continue;
68431 }
68432 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68433 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68434 hits[i].hits = hits[i].pc = 0;
68435 }
68436 }
68437 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68438 * Add the current hit(s) and flush the write-queue out
68439 * to the global buffer:
68440 */
68441 - atomic_add(nr_hits, &prof_buffer[pc]);
68442 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
68443 for (i = 0; i < NR_PROFILE_HIT; ++i) {
68444 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68445 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68446 hits[i].pc = hits[i].hits = 0;
68447 }
68448 out:
68449 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68450 {
68451 unsigned long pc;
68452 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
68453 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68454 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68455 }
68456 #endif /* !CONFIG_SMP */
68457
68458 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
68459 return -EFAULT;
68460 buf++; p++; count--; read++;
68461 }
68462 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
68463 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
68464 if (copy_to_user(buf, (void *)pnt, count))
68465 return -EFAULT;
68466 read += count;
68467 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
68468 }
68469 #endif
68470 profile_discard_flip_buffers();
68471 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
68472 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
68473 return count;
68474 }
68475
68476 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
68477 index a232bb5..2a65ef9 100644
68478 --- a/kernel/ptrace.c
68479 +++ b/kernel/ptrace.c
68480 @@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68481
68482 if (seize)
68483 flags |= PT_SEIZED;
68484 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
68485 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
68486 flags |= PT_PTRACE_CAP;
68487 task->ptrace = flags;
68488
68489 @@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68490 break;
68491 return -EIO;
68492 }
68493 - if (copy_to_user(dst, buf, retval))
68494 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
68495 return -EFAULT;
68496 copied += retval;
68497 src += retval;
68498 @@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
68499 bool seized = child->ptrace & PT_SEIZED;
68500 int ret = -EIO;
68501 siginfo_t siginfo, *si;
68502 - void __user *datavp = (void __user *) data;
68503 + void __user *datavp = (__force void __user *) data;
68504 unsigned long __user *datalp = datavp;
68505 unsigned long flags;
68506
68507 @@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
68508 goto out;
68509 }
68510
68511 + if (gr_handle_ptrace(child, request)) {
68512 + ret = -EPERM;
68513 + goto out_put_task_struct;
68514 + }
68515 +
68516 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68517 ret = ptrace_attach(child, request, addr, data);
68518 /*
68519 * Some architectures need to do book-keeping after
68520 * a ptrace attach.
68521 */
68522 - if (!ret)
68523 + if (!ret) {
68524 arch_ptrace_attach(child);
68525 + gr_audit_ptrace(child);
68526 + }
68527 goto out_put_task_struct;
68528 }
68529
68530 @@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68531 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68532 if (copied != sizeof(tmp))
68533 return -EIO;
68534 - return put_user(tmp, (unsigned long __user *)data);
68535 + return put_user(tmp, (__force unsigned long __user *)data);
68536 }
68537
68538 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68539 @@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68540 goto out;
68541 }
68542
68543 + if (gr_handle_ptrace(child, request)) {
68544 + ret = -EPERM;
68545 + goto out_put_task_struct;
68546 + }
68547 +
68548 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68549 ret = ptrace_attach(child, request, addr, data);
68550 /*
68551 * Some architectures need to do book-keeping after
68552 * a ptrace attach.
68553 */
68554 - if (!ret)
68555 + if (!ret) {
68556 arch_ptrace_attach(child);
68557 + gr_audit_ptrace(child);
68558 + }
68559 goto out_put_task_struct;
68560 }
68561
68562 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
68563 index 37a5444..eec170a 100644
68564 --- a/kernel/rcutiny.c
68565 +++ b/kernel/rcutiny.c
68566 @@ -46,7 +46,7 @@
68567 struct rcu_ctrlblk;
68568 static void invoke_rcu_callbacks(void);
68569 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
68570 -static void rcu_process_callbacks(struct softirq_action *unused);
68571 +static void rcu_process_callbacks(void);
68572 static void __call_rcu(struct rcu_head *head,
68573 void (*func)(struct rcu_head *rcu),
68574 struct rcu_ctrlblk *rcp);
68575 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
68576 rcu_is_callbacks_kthread()));
68577 }
68578
68579 -static void rcu_process_callbacks(struct softirq_action *unused)
68580 +static void rcu_process_callbacks(void)
68581 {
68582 __rcu_process_callbacks(&rcu_sched_ctrlblk);
68583 __rcu_process_callbacks(&rcu_bh_ctrlblk);
68584 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
68585 index fc31a2d..be2ec04 100644
68586 --- a/kernel/rcutiny_plugin.h
68587 +++ b/kernel/rcutiny_plugin.h
68588 @@ -939,7 +939,7 @@ static int rcu_kthread(void *arg)
68589 have_rcu_kthread_work = morework;
68590 local_irq_restore(flags);
68591 if (work)
68592 - rcu_process_callbacks(NULL);
68593 + rcu_process_callbacks();
68594 schedule_timeout_interruptible(1); /* Leave CPU for others. */
68595 }
68596
68597 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68598 index e66b34a..4b8b626 100644
68599 --- a/kernel/rcutorture.c
68600 +++ b/kernel/rcutorture.c
68601 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68602 { 0 };
68603 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68604 { 0 };
68605 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68606 -static atomic_t n_rcu_torture_alloc;
68607 -static atomic_t n_rcu_torture_alloc_fail;
68608 -static atomic_t n_rcu_torture_free;
68609 -static atomic_t n_rcu_torture_mberror;
68610 -static atomic_t n_rcu_torture_error;
68611 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68612 +static atomic_unchecked_t n_rcu_torture_alloc;
68613 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
68614 +static atomic_unchecked_t n_rcu_torture_free;
68615 +static atomic_unchecked_t n_rcu_torture_mberror;
68616 +static atomic_unchecked_t n_rcu_torture_error;
68617 static long n_rcu_torture_barrier_error;
68618 static long n_rcu_torture_boost_ktrerror;
68619 static long n_rcu_torture_boost_rterror;
68620 @@ -265,11 +265,11 @@ rcu_torture_alloc(void)
68621
68622 spin_lock_bh(&rcu_torture_lock);
68623 if (list_empty(&rcu_torture_freelist)) {
68624 - atomic_inc(&n_rcu_torture_alloc_fail);
68625 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68626 spin_unlock_bh(&rcu_torture_lock);
68627 return NULL;
68628 }
68629 - atomic_inc(&n_rcu_torture_alloc);
68630 + atomic_inc_unchecked(&n_rcu_torture_alloc);
68631 p = rcu_torture_freelist.next;
68632 list_del_init(p);
68633 spin_unlock_bh(&rcu_torture_lock);
68634 @@ -282,7 +282,7 @@ rcu_torture_alloc(void)
68635 static void
68636 rcu_torture_free(struct rcu_torture *p)
68637 {
68638 - atomic_inc(&n_rcu_torture_free);
68639 + atomic_inc_unchecked(&n_rcu_torture_free);
68640 spin_lock_bh(&rcu_torture_lock);
68641 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68642 spin_unlock_bh(&rcu_torture_lock);
68643 @@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
68644 i = rp->rtort_pipe_count;
68645 if (i > RCU_TORTURE_PIPE_LEN)
68646 i = RCU_TORTURE_PIPE_LEN;
68647 - atomic_inc(&rcu_torture_wcount[i]);
68648 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68649 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68650 rp->rtort_mbtest = 0;
68651 rcu_torture_free(rp);
68652 @@ -451,7 +451,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68653 i = rp->rtort_pipe_count;
68654 if (i > RCU_TORTURE_PIPE_LEN)
68655 i = RCU_TORTURE_PIPE_LEN;
68656 - atomic_inc(&rcu_torture_wcount[i]);
68657 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68658 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68659 rp->rtort_mbtest = 0;
68660 list_del(&rp->rtort_free);
68661 @@ -983,7 +983,7 @@ rcu_torture_writer(void *arg)
68662 i = old_rp->rtort_pipe_count;
68663 if (i > RCU_TORTURE_PIPE_LEN)
68664 i = RCU_TORTURE_PIPE_LEN;
68665 - atomic_inc(&rcu_torture_wcount[i]);
68666 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68667 old_rp->rtort_pipe_count++;
68668 cur_ops->deferred_free(old_rp);
68669 }
68670 @@ -1064,7 +1064,7 @@ static void rcu_torture_timer(unsigned long unused)
68671 }
68672 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68673 if (p->rtort_mbtest == 0)
68674 - atomic_inc(&n_rcu_torture_mberror);
68675 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68676 spin_lock(&rand_lock);
68677 cur_ops->read_delay(&rand);
68678 n_rcu_torture_timers++;
68679 @@ -1128,7 +1128,7 @@ rcu_torture_reader(void *arg)
68680 }
68681 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68682 if (p->rtort_mbtest == 0)
68683 - atomic_inc(&n_rcu_torture_mberror);
68684 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68685 cur_ops->read_delay(&rand);
68686 preempt_disable();
68687 pipe_count = p->rtort_pipe_count;
68688 @@ -1191,10 +1191,10 @@ rcu_torture_printk(char *page)
68689 rcu_torture_current,
68690 rcu_torture_current_version,
68691 list_empty(&rcu_torture_freelist),
68692 - atomic_read(&n_rcu_torture_alloc),
68693 - atomic_read(&n_rcu_torture_alloc_fail),
68694 - atomic_read(&n_rcu_torture_free),
68695 - atomic_read(&n_rcu_torture_mberror),
68696 + atomic_read_unchecked(&n_rcu_torture_alloc),
68697 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68698 + atomic_read_unchecked(&n_rcu_torture_free),
68699 + atomic_read_unchecked(&n_rcu_torture_mberror),
68700 n_rcu_torture_boost_ktrerror,
68701 n_rcu_torture_boost_rterror,
68702 n_rcu_torture_boost_failure,
68703 @@ -1208,14 +1208,14 @@ rcu_torture_printk(char *page)
68704 n_barrier_attempts,
68705 n_rcu_torture_barrier_error);
68706 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68707 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68708 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68709 n_rcu_torture_barrier_error != 0 ||
68710 n_rcu_torture_boost_ktrerror != 0 ||
68711 n_rcu_torture_boost_rterror != 0 ||
68712 n_rcu_torture_boost_failure != 0 ||
68713 i > 1) {
68714 cnt += sprintf(&page[cnt], "!!! ");
68715 - atomic_inc(&n_rcu_torture_error);
68716 + atomic_inc_unchecked(&n_rcu_torture_error);
68717 WARN_ON_ONCE(1);
68718 }
68719 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68720 @@ -1229,7 +1229,7 @@ rcu_torture_printk(char *page)
68721 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68722 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68723 cnt += sprintf(&page[cnt], " %d",
68724 - atomic_read(&rcu_torture_wcount[i]));
68725 + atomic_read_unchecked(&rcu_torture_wcount[i]));
68726 }
68727 cnt += sprintf(&page[cnt], "\n");
68728 if (cur_ops->stats)
68729 @@ -1888,7 +1888,7 @@ rcu_torture_cleanup(void)
68730
68731 if (cur_ops->cleanup)
68732 cur_ops->cleanup();
68733 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68734 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68735 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68736 else if (n_online_successes != n_online_attempts ||
68737 n_offline_successes != n_offline_attempts)
68738 @@ -1958,18 +1958,18 @@ rcu_torture_init(void)
68739
68740 rcu_torture_current = NULL;
68741 rcu_torture_current_version = 0;
68742 - atomic_set(&n_rcu_torture_alloc, 0);
68743 - atomic_set(&n_rcu_torture_alloc_fail, 0);
68744 - atomic_set(&n_rcu_torture_free, 0);
68745 - atomic_set(&n_rcu_torture_mberror, 0);
68746 - atomic_set(&n_rcu_torture_error, 0);
68747 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68748 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68749 + atomic_set_unchecked(&n_rcu_torture_free, 0);
68750 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68751 + atomic_set_unchecked(&n_rcu_torture_error, 0);
68752 n_rcu_torture_barrier_error = 0;
68753 n_rcu_torture_boost_ktrerror = 0;
68754 n_rcu_torture_boost_rterror = 0;
68755 n_rcu_torture_boost_failure = 0;
68756 n_rcu_torture_boosts = 0;
68757 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68758 - atomic_set(&rcu_torture_wcount[i], 0);
68759 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68760 for_each_possible_cpu(cpu) {
68761 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68762 per_cpu(rcu_torture_count, cpu)[i] = 0;
68763 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68764 index 4b97bba..b92c9d2 100644
68765 --- a/kernel/rcutree.c
68766 +++ b/kernel/rcutree.c
68767 @@ -366,9 +366,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
68768 rcu_prepare_for_idle(smp_processor_id());
68769 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68770 smp_mb__before_atomic_inc(); /* See above. */
68771 - atomic_inc(&rdtp->dynticks);
68772 + atomic_inc_unchecked(&rdtp->dynticks);
68773 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68774 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68775 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68776
68777 /*
68778 * The idle task is not permitted to enter the idle loop while
68779 @@ -457,10 +457,10 @@ void rcu_irq_exit(void)
68780 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
68781 {
68782 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68783 - atomic_inc(&rdtp->dynticks);
68784 + atomic_inc_unchecked(&rdtp->dynticks);
68785 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68786 smp_mb__after_atomic_inc(); /* See above. */
68787 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68788 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68789 rcu_cleanup_after_idle(smp_processor_id());
68790 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
68791 if (!is_idle_task(current)) {
68792 @@ -554,14 +554,14 @@ void rcu_nmi_enter(void)
68793 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68794
68795 if (rdtp->dynticks_nmi_nesting == 0 &&
68796 - (atomic_read(&rdtp->dynticks) & 0x1))
68797 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
68798 return;
68799 rdtp->dynticks_nmi_nesting++;
68800 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
68801 - atomic_inc(&rdtp->dynticks);
68802 + atomic_inc_unchecked(&rdtp->dynticks);
68803 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68804 smp_mb__after_atomic_inc(); /* See above. */
68805 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68806 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68807 }
68808
68809 /**
68810 @@ -580,9 +580,9 @@ void rcu_nmi_exit(void)
68811 return;
68812 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68813 smp_mb__before_atomic_inc(); /* See above. */
68814 - atomic_inc(&rdtp->dynticks);
68815 + atomic_inc_unchecked(&rdtp->dynticks);
68816 smp_mb__after_atomic_inc(); /* Force delay to next write. */
68817 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68818 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68819 }
68820
68821 #ifdef CONFIG_PROVE_RCU
68822 @@ -598,7 +598,7 @@ int rcu_is_cpu_idle(void)
68823 int ret;
68824
68825 preempt_disable();
68826 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68827 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68828 preempt_enable();
68829 return ret;
68830 }
68831 @@ -668,7 +668,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
68832 */
68833 static int dyntick_save_progress_counter(struct rcu_data *rdp)
68834 {
68835 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
68836 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68837 return (rdp->dynticks_snap & 0x1) == 0;
68838 }
68839
68840 @@ -683,7 +683,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
68841 unsigned int curr;
68842 unsigned int snap;
68843
68844 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
68845 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68846 snap = (unsigned int)rdp->dynticks_snap;
68847
68848 /*
68849 @@ -713,10 +713,10 @@ static int jiffies_till_stall_check(void)
68850 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
68851 */
68852 if (till_stall_check < 3) {
68853 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
68854 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
68855 till_stall_check = 3;
68856 } else if (till_stall_check > 300) {
68857 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
68858 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
68859 till_stall_check = 300;
68860 }
68861 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
68862 @@ -1824,7 +1824,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
68863 /*
68864 * Do RCU core processing for the current CPU.
68865 */
68866 -static void rcu_process_callbacks(struct softirq_action *unused)
68867 +static void rcu_process_callbacks(void)
68868 {
68869 trace_rcu_utilization("Start RCU core");
68870 __rcu_process_callbacks(&rcu_sched_state,
68871 @@ -2042,8 +2042,8 @@ void synchronize_rcu_bh(void)
68872 }
68873 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
68874
68875 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
68876 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
68877 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
68878 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
68879
68880 static int synchronize_sched_expedited_cpu_stop(void *data)
68881 {
68882 @@ -2104,7 +2104,7 @@ void synchronize_sched_expedited(void)
68883 int firstsnap, s, snap, trycount = 0;
68884
68885 /* Note that atomic_inc_return() implies full memory barrier. */
68886 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
68887 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
68888 get_online_cpus();
68889 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
68890
68891 @@ -2126,7 +2126,7 @@ void synchronize_sched_expedited(void)
68892 }
68893
68894 /* Check to see if someone else did our work for us. */
68895 - s = atomic_read(&sync_sched_expedited_done);
68896 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68897 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
68898 smp_mb(); /* ensure test happens before caller kfree */
68899 return;
68900 @@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
68901 * grace period works for us.
68902 */
68903 get_online_cpus();
68904 - snap = atomic_read(&sync_sched_expedited_started);
68905 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
68906 smp_mb(); /* ensure read is before try_stop_cpus(). */
68907 }
68908
68909 @@ -2152,12 +2152,12 @@ void synchronize_sched_expedited(void)
68910 * than we did beat us to the punch.
68911 */
68912 do {
68913 - s = atomic_read(&sync_sched_expedited_done);
68914 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68915 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
68916 smp_mb(); /* ensure test happens before caller kfree */
68917 break;
68918 }
68919 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
68920 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
68921
68922 put_online_cpus();
68923 }
68924 @@ -2421,7 +2421,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
68925 rdp->qlen = 0;
68926 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
68927 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
68928 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
68929 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
68930 rdp->cpu = cpu;
68931 rdp->rsp = rsp;
68932 raw_spin_unlock_irqrestore(&rnp->lock, flags);
68933 @@ -2449,8 +2449,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
68934 rdp->n_force_qs_snap = rsp->n_force_qs;
68935 rdp->blimit = blimit;
68936 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
68937 - atomic_set(&rdp->dynticks->dynticks,
68938 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
68939 + atomic_set_unchecked(&rdp->dynticks->dynticks,
68940 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
68941 rcu_prepare_for_idle_init(cpu);
68942 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
68943
68944 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
68945 index 19b61ac..5c60a94 100644
68946 --- a/kernel/rcutree.h
68947 +++ b/kernel/rcutree.h
68948 @@ -83,7 +83,7 @@ struct rcu_dynticks {
68949 long long dynticks_nesting; /* Track irq/process nesting level. */
68950 /* Process level is worth LLONG_MAX/2. */
68951 int dynticks_nmi_nesting; /* Track NMI nesting level. */
68952 - atomic_t dynticks; /* Even value for idle, else odd. */
68953 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
68954 #ifdef CONFIG_RCU_FAST_NO_HZ
68955 int dyntick_drain; /* Prepare-for-idle state variable. */
68956 unsigned long dyntick_holdoff;
68957 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
68958 index 3e48994..d94f03a 100644
68959 --- a/kernel/rcutree_plugin.h
68960 +++ b/kernel/rcutree_plugin.h
68961 @@ -909,7 +909,7 @@ void synchronize_rcu_expedited(void)
68962
68963 /* Clean up and exit. */
68964 smp_mb(); /* ensure expedited GP seen before counter increment. */
68965 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
68966 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
68967 unlock_mb_ret:
68968 mutex_unlock(&sync_rcu_preempt_exp_mutex);
68969 mb_ret:
68970 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
68971 index d4bc16d..c234a5c 100644
68972 --- a/kernel/rcutree_trace.c
68973 +++ b/kernel/rcutree_trace.c
68974 @@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
68975 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68976 rdp->qs_pending);
68977 seq_printf(m, " dt=%d/%llx/%d df=%lu",
68978 - atomic_read(&rdp->dynticks->dynticks),
68979 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68980 rdp->dynticks->dynticks_nesting,
68981 rdp->dynticks->dynticks_nmi_nesting,
68982 rdp->dynticks_fqs);
68983 @@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
68984 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68985 rdp->qs_pending);
68986 seq_printf(m, ",%d,%llx,%d,%lu",
68987 - atomic_read(&rdp->dynticks->dynticks),
68988 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68989 rdp->dynticks->dynticks_nesting,
68990 rdp->dynticks->dynticks_nmi_nesting,
68991 rdp->dynticks_fqs);
68992 diff --git a/kernel/resource.c b/kernel/resource.c
68993 index e1d2b8e..24820bb 100644
68994 --- a/kernel/resource.c
68995 +++ b/kernel/resource.c
68996 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
68997
68998 static int __init ioresources_init(void)
68999 {
69000 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69001 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69002 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69003 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69004 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69005 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69006 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69007 +#endif
69008 +#else
69009 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69010 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69011 +#endif
69012 return 0;
69013 }
69014 __initcall(ioresources_init);
69015 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69016 index 98ec494..4241d6d 100644
69017 --- a/kernel/rtmutex-tester.c
69018 +++ b/kernel/rtmutex-tester.c
69019 @@ -20,7 +20,7 @@
69020 #define MAX_RT_TEST_MUTEXES 8
69021
69022 static spinlock_t rttest_lock;
69023 -static atomic_t rttest_event;
69024 +static atomic_unchecked_t rttest_event;
69025
69026 struct test_thread_data {
69027 int opcode;
69028 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69029
69030 case RTTEST_LOCKCONT:
69031 td->mutexes[td->opdata] = 1;
69032 - td->event = atomic_add_return(1, &rttest_event);
69033 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69034 return 0;
69035
69036 case RTTEST_RESET:
69037 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69038 return 0;
69039
69040 case RTTEST_RESETEVENT:
69041 - atomic_set(&rttest_event, 0);
69042 + atomic_set_unchecked(&rttest_event, 0);
69043 return 0;
69044
69045 default:
69046 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69047 return ret;
69048
69049 td->mutexes[id] = 1;
69050 - td->event = atomic_add_return(1, &rttest_event);
69051 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69052 rt_mutex_lock(&mutexes[id]);
69053 - td->event = atomic_add_return(1, &rttest_event);
69054 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69055 td->mutexes[id] = 4;
69056 return 0;
69057
69058 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69059 return ret;
69060
69061 td->mutexes[id] = 1;
69062 - td->event = atomic_add_return(1, &rttest_event);
69063 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69064 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69065 - td->event = atomic_add_return(1, &rttest_event);
69066 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69067 td->mutexes[id] = ret ? 0 : 4;
69068 return ret ? -EINTR : 0;
69069
69070 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69071 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69072 return ret;
69073
69074 - td->event = atomic_add_return(1, &rttest_event);
69075 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69076 rt_mutex_unlock(&mutexes[id]);
69077 - td->event = atomic_add_return(1, &rttest_event);
69078 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69079 td->mutexes[id] = 0;
69080 return 0;
69081
69082 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69083 break;
69084
69085 td->mutexes[dat] = 2;
69086 - td->event = atomic_add_return(1, &rttest_event);
69087 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69088 break;
69089
69090 default:
69091 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69092 return;
69093
69094 td->mutexes[dat] = 3;
69095 - td->event = atomic_add_return(1, &rttest_event);
69096 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69097 break;
69098
69099 case RTTEST_LOCKNOWAIT:
69100 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69101 return;
69102
69103 td->mutexes[dat] = 1;
69104 - td->event = atomic_add_return(1, &rttest_event);
69105 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69106 return;
69107
69108 default:
69109 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69110 index 0984a21..939f183 100644
69111 --- a/kernel/sched/auto_group.c
69112 +++ b/kernel/sched/auto_group.c
69113 @@ -11,7 +11,7 @@
69114
69115 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69116 static struct autogroup autogroup_default;
69117 -static atomic_t autogroup_seq_nr;
69118 +static atomic_unchecked_t autogroup_seq_nr;
69119
69120 void __init autogroup_init(struct task_struct *init_task)
69121 {
69122 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69123
69124 kref_init(&ag->kref);
69125 init_rwsem(&ag->lock);
69126 - ag->id = atomic_inc_return(&autogroup_seq_nr);
69127 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69128 ag->tg = tg;
69129 #ifdef CONFIG_RT_GROUP_SCHED
69130 /*
69131 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69132 index 468bdd4..b941572 100644
69133 --- a/kernel/sched/core.c
69134 +++ b/kernel/sched/core.c
69135 @@ -4097,6 +4097,8 @@ int can_nice(const struct task_struct *p, const int nice)
69136 /* convert nice value [19,-20] to rlimit style value [1,40] */
69137 int nice_rlim = 20 - nice;
69138
69139 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69140 +
69141 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69142 capable(CAP_SYS_NICE));
69143 }
69144 @@ -4130,7 +4132,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69145 if (nice > 19)
69146 nice = 19;
69147
69148 - if (increment < 0 && !can_nice(current, nice))
69149 + if (increment < 0 && (!can_nice(current, nice) ||
69150 + gr_handle_chroot_nice()))
69151 return -EPERM;
69152
69153 retval = security_task_setnice(current, nice);
69154 @@ -4284,6 +4287,7 @@ recheck:
69155 unsigned long rlim_rtprio =
69156 task_rlimit(p, RLIMIT_RTPRIO);
69157
69158 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69159 /* can't set/change the rt policy */
69160 if (policy != p->policy && !rlim_rtprio)
69161 return -EPERM;
69162 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69163 index c099cc6..06aec4f 100644
69164 --- a/kernel/sched/fair.c
69165 +++ b/kernel/sched/fair.c
69166 @@ -4846,7 +4846,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69167 * run_rebalance_domains is triggered when needed from the scheduler tick.
69168 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69169 */
69170 -static void run_rebalance_domains(struct softirq_action *h)
69171 +static void run_rebalance_domains(void)
69172 {
69173 int this_cpu = smp_processor_id();
69174 struct rq *this_rq = cpu_rq(this_cpu);
69175 diff --git a/kernel/signal.c b/kernel/signal.c
69176 index 6771027..763e51e 100644
69177 --- a/kernel/signal.c
69178 +++ b/kernel/signal.c
69179 @@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
69180
69181 int print_fatal_signals __read_mostly;
69182
69183 -static void __user *sig_handler(struct task_struct *t, int sig)
69184 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
69185 {
69186 return t->sighand->action[sig - 1].sa.sa_handler;
69187 }
69188
69189 -static int sig_handler_ignored(void __user *handler, int sig)
69190 +static int sig_handler_ignored(__sighandler_t handler, int sig)
69191 {
69192 /* Is it explicitly or implicitly ignored? */
69193 return handler == SIG_IGN ||
69194 @@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69195
69196 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
69197 {
69198 - void __user *handler;
69199 + __sighandler_t handler;
69200
69201 handler = sig_handler(t, sig);
69202
69203 @@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69204 atomic_inc(&user->sigpending);
69205 rcu_read_unlock();
69206
69207 + if (!override_rlimit)
69208 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69209 +
69210 if (override_rlimit ||
69211 atomic_read(&user->sigpending) <=
69212 task_rlimit(t, RLIMIT_SIGPENDING)) {
69213 @@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69214
69215 int unhandled_signal(struct task_struct *tsk, int sig)
69216 {
69217 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69218 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69219 if (is_global_init(tsk))
69220 return 1;
69221 if (handler != SIG_IGN && handler != SIG_DFL)
69222 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69223 }
69224 }
69225
69226 + /* allow glibc communication via tgkill to other threads in our
69227 + thread group */
69228 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69229 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69230 + && gr_handle_signal(t, sig))
69231 + return -EPERM;
69232 +
69233 return security_task_kill(t, info, sig, 0);
69234 }
69235
69236 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69237 return send_signal(sig, info, p, 1);
69238 }
69239
69240 -static int
69241 +int
69242 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69243 {
69244 return send_signal(sig, info, t, 0);
69245 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69246 unsigned long int flags;
69247 int ret, blocked, ignored;
69248 struct k_sigaction *action;
69249 + int is_unhandled = 0;
69250
69251 spin_lock_irqsave(&t->sighand->siglock, flags);
69252 action = &t->sighand->action[sig-1];
69253 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69254 }
69255 if (action->sa.sa_handler == SIG_DFL)
69256 t->signal->flags &= ~SIGNAL_UNKILLABLE;
69257 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
69258 + is_unhandled = 1;
69259 ret = specific_send_sig_info(sig, info, t);
69260 spin_unlock_irqrestore(&t->sighand->siglock, flags);
69261
69262 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
69263 + normal operation */
69264 + if (is_unhandled) {
69265 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
69266 + gr_handle_crash(t, sig);
69267 + }
69268 +
69269 return ret;
69270 }
69271
69272 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69273 ret = check_kill_permission(sig, info, p);
69274 rcu_read_unlock();
69275
69276 - if (!ret && sig)
69277 + if (!ret && sig) {
69278 ret = do_send_sig_info(sig, info, p, true);
69279 + if (!ret)
69280 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
69281 + }
69282
69283 return ret;
69284 }
69285 @@ -2858,7 +2881,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
69286 int error = -ESRCH;
69287
69288 rcu_read_lock();
69289 - p = find_task_by_vpid(pid);
69290 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69291 + /* allow glibc communication via tgkill to other threads in our
69292 + thread group */
69293 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
69294 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
69295 + p = find_task_by_vpid_unrestricted(pid);
69296 + else
69297 +#endif
69298 + p = find_task_by_vpid(pid);
69299 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
69300 error = check_kill_permission(sig, info, p);
69301 /*
69302 diff --git a/kernel/smp.c b/kernel/smp.c
69303 index d0ae5b2..b87c5a8 100644
69304 --- a/kernel/smp.c
69305 +++ b/kernel/smp.c
69306 @@ -582,22 +582,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
69307 }
69308 EXPORT_SYMBOL(smp_call_function);
69309
69310 -void ipi_call_lock(void)
69311 +void ipi_call_lock(void) __acquires(call_function.lock)
69312 {
69313 raw_spin_lock(&call_function.lock);
69314 }
69315
69316 -void ipi_call_unlock(void)
69317 +void ipi_call_unlock(void) __releases(call_function.lock)
69318 {
69319 raw_spin_unlock(&call_function.lock);
69320 }
69321
69322 -void ipi_call_lock_irq(void)
69323 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
69324 {
69325 raw_spin_lock_irq(&call_function.lock);
69326 }
69327
69328 -void ipi_call_unlock_irq(void)
69329 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
69330 {
69331 raw_spin_unlock_irq(&call_function.lock);
69332 }
69333 diff --git a/kernel/softirq.c b/kernel/softirq.c
69334 index 671f959..91c51cb 100644
69335 --- a/kernel/softirq.c
69336 +++ b/kernel/softirq.c
69337 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
69338
69339 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
69340
69341 -char *softirq_to_name[NR_SOFTIRQS] = {
69342 +const char * const softirq_to_name[NR_SOFTIRQS] = {
69343 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
69344 "TASKLET", "SCHED", "HRTIMER", "RCU"
69345 };
69346 @@ -235,7 +235,7 @@ restart:
69347 kstat_incr_softirqs_this_cpu(vec_nr);
69348
69349 trace_softirq_entry(vec_nr);
69350 - h->action(h);
69351 + h->action();
69352 trace_softirq_exit(vec_nr);
69353 if (unlikely(prev_count != preempt_count())) {
69354 printk(KERN_ERR "huh, entered softirq %u %s %p"
69355 @@ -381,9 +381,11 @@ void __raise_softirq_irqoff(unsigned int nr)
69356 or_softirq_pending(1UL << nr);
69357 }
69358
69359 -void open_softirq(int nr, void (*action)(struct softirq_action *))
69360 +void open_softirq(int nr, void (*action)(void))
69361 {
69362 - softirq_vec[nr].action = action;
69363 + pax_open_kernel();
69364 + *(void **)&softirq_vec[nr].action = action;
69365 + pax_close_kernel();
69366 }
69367
69368 /*
69369 @@ -437,7 +439,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
69370
69371 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
69372
69373 -static void tasklet_action(struct softirq_action *a)
69374 +static void tasklet_action(void)
69375 {
69376 struct tasklet_struct *list;
69377
69378 @@ -472,7 +474,7 @@ static void tasklet_action(struct softirq_action *a)
69379 }
69380 }
69381
69382 -static void tasklet_hi_action(struct softirq_action *a)
69383 +static void tasklet_hi_action(void)
69384 {
69385 struct tasklet_struct *list;
69386
69387 diff --git a/kernel/srcu.c b/kernel/srcu.c
69388 index 2095be3..9a5b89d 100644
69389 --- a/kernel/srcu.c
69390 +++ b/kernel/srcu.c
69391 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
69392 preempt_disable();
69393 idx = rcu_dereference_index_check(sp->completed,
69394 rcu_read_lock_sched_held()) & 0x1;
69395 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69396 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69397 smp_mb(); /* B */ /* Avoid leaking the critical section. */
69398 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69399 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69400 preempt_enable();
69401 return idx;
69402 }
69403 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
69404 {
69405 preempt_disable();
69406 smp_mb(); /* C */ /* Avoid leaking the critical section. */
69407 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69408 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69409 preempt_enable();
69410 }
69411 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
69412 diff --git a/kernel/sys.c b/kernel/sys.c
69413 index 2d39a84..f778b49 100644
69414 --- a/kernel/sys.c
69415 +++ b/kernel/sys.c
69416 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
69417 error = -EACCES;
69418 goto out;
69419 }
69420 +
69421 + if (gr_handle_chroot_setpriority(p, niceval)) {
69422 + error = -EACCES;
69423 + goto out;
69424 + }
69425 +
69426 no_nice = security_task_setnice(p, niceval);
69427 if (no_nice) {
69428 error = no_nice;
69429 @@ -594,6 +600,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
69430 goto error;
69431 }
69432
69433 + if (gr_check_group_change(new->gid, new->egid, -1))
69434 + goto error;
69435 +
69436 if (rgid != (gid_t) -1 ||
69437 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
69438 new->sgid = new->egid;
69439 @@ -629,6 +638,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
69440 old = current_cred();
69441
69442 retval = -EPERM;
69443 +
69444 + if (gr_check_group_change(kgid, kgid, kgid))
69445 + goto error;
69446 +
69447 if (nsown_capable(CAP_SETGID))
69448 new->gid = new->egid = new->sgid = new->fsgid = kgid;
69449 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
69450 @@ -646,7 +659,7 @@ error:
69451 /*
69452 * change the user struct in a credentials set to match the new UID
69453 */
69454 -static int set_user(struct cred *new)
69455 +int set_user(struct cred *new)
69456 {
69457 struct user_struct *new_user;
69458
69459 @@ -726,6 +739,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
69460 goto error;
69461 }
69462
69463 + if (gr_check_user_change(new->uid, new->euid, -1))
69464 + goto error;
69465 +
69466 if (!uid_eq(new->uid, old->uid)) {
69467 retval = set_user(new);
69468 if (retval < 0)
69469 @@ -776,6 +792,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
69470 old = current_cred();
69471
69472 retval = -EPERM;
69473 +
69474 + if (gr_check_crash_uid(kuid))
69475 + goto error;
69476 + if (gr_check_user_change(kuid, kuid, kuid))
69477 + goto error;
69478 +
69479 if (nsown_capable(CAP_SETUID)) {
69480 new->suid = new->uid = kuid;
69481 if (!uid_eq(kuid, old->uid)) {
69482 @@ -845,6 +867,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
69483 goto error;
69484 }
69485
69486 + if (gr_check_user_change(kruid, keuid, -1))
69487 + goto error;
69488 +
69489 if (ruid != (uid_t) -1) {
69490 new->uid = kruid;
69491 if (!uid_eq(kruid, old->uid)) {
69492 @@ -927,6 +952,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
69493 goto error;
69494 }
69495
69496 + if (gr_check_group_change(krgid, kegid, -1))
69497 + goto error;
69498 +
69499 if (rgid != (gid_t) -1)
69500 new->gid = krgid;
69501 if (egid != (gid_t) -1)
69502 @@ -980,6 +1008,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69503 if (!uid_valid(kuid))
69504 return old_fsuid;
69505
69506 + if (gr_check_user_change(-1, -1, kuid))
69507 + goto error;
69508 +
69509 new = prepare_creds();
69510 if (!new)
69511 return old_fsuid;
69512 @@ -994,6 +1025,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69513 }
69514 }
69515
69516 +error:
69517 abort_creds(new);
69518 return old_fsuid;
69519
69520 @@ -1026,12 +1058,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
69521 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
69522 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
69523 nsown_capable(CAP_SETGID)) {
69524 + if (gr_check_group_change(-1, -1, kgid))
69525 + goto error;
69526 +
69527 if (!gid_eq(kgid, old->fsgid)) {
69528 new->fsgid = kgid;
69529 goto change_okay;
69530 }
69531 }
69532
69533 +error:
69534 abort_creds(new);
69535 return old_fsgid;
69536
69537 @@ -1283,7 +1319,10 @@ static int override_release(char __user *release, int len)
69538 }
69539 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
69540 snprintf(buf, len, "2.6.%u%s", v, rest);
69541 - ret = copy_to_user(release, buf, len);
69542 + if (len > sizeof(buf))
69543 + ret = -EFAULT;
69544 + else
69545 + ret = copy_to_user(release, buf, len);
69546 }
69547 return ret;
69548 }
69549 @@ -1337,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
69550 return -EFAULT;
69551
69552 down_read(&uts_sem);
69553 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
69554 + error = __copy_to_user(name->sysname, &utsname()->sysname,
69555 __OLD_UTS_LEN);
69556 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69557 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69558 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
69559 __OLD_UTS_LEN);
69560 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69561 - error |= __copy_to_user(&name->release, &utsname()->release,
69562 + error |= __copy_to_user(name->release, &utsname()->release,
69563 __OLD_UTS_LEN);
69564 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69565 - error |= __copy_to_user(&name->version, &utsname()->version,
69566 + error |= __copy_to_user(name->version, &utsname()->version,
69567 __OLD_UTS_LEN);
69568 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69569 - error |= __copy_to_user(&name->machine, &utsname()->machine,
69570 + error |= __copy_to_user(name->machine, &utsname()->machine,
69571 __OLD_UTS_LEN);
69572 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69573 up_read(&uts_sem);
69574 @@ -2024,7 +2063,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69575 error = get_dumpable(me->mm);
69576 break;
69577 case PR_SET_DUMPABLE:
69578 - if (arg2 < 0 || arg2 > 1) {
69579 + if (arg2 > 1) {
69580 error = -EINVAL;
69581 break;
69582 }
69583 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69584 index 4ab1187..33f4f2b 100644
69585 --- a/kernel/sysctl.c
69586 +++ b/kernel/sysctl.c
69587 @@ -91,7 +91,6 @@
69588
69589
69590 #if defined(CONFIG_SYSCTL)
69591 -
69592 /* External variables not in a header file. */
69593 extern int sysctl_overcommit_memory;
69594 extern int sysctl_overcommit_ratio;
69595 @@ -169,10 +168,13 @@ static int proc_taint(struct ctl_table *table, int write,
69596 void __user *buffer, size_t *lenp, loff_t *ppos);
69597 #endif
69598
69599 -#ifdef CONFIG_PRINTK
69600 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69601 void __user *buffer, size_t *lenp, loff_t *ppos);
69602 -#endif
69603 +
69604 +static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69605 + void __user *buffer, size_t *lenp, loff_t *ppos);
69606 +static int proc_dostring_coredump(struct ctl_table *table, int write,
69607 + void __user *buffer, size_t *lenp, loff_t *ppos);
69608
69609 #ifdef CONFIG_MAGIC_SYSRQ
69610 /* Note: sysrq code uses it's own private copy */
69611 @@ -196,6 +198,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69612
69613 #endif
69614
69615 +extern struct ctl_table grsecurity_table[];
69616 +
69617 static struct ctl_table kern_table[];
69618 static struct ctl_table vm_table[];
69619 static struct ctl_table fs_table[];
69620 @@ -210,6 +214,20 @@ extern struct ctl_table epoll_table[];
69621 int sysctl_legacy_va_layout;
69622 #endif
69623
69624 +#ifdef CONFIG_PAX_SOFTMODE
69625 +static ctl_table pax_table[] = {
69626 + {
69627 + .procname = "softmode",
69628 + .data = &pax_softmode,
69629 + .maxlen = sizeof(unsigned int),
69630 + .mode = 0600,
69631 + .proc_handler = &proc_dointvec,
69632 + },
69633 +
69634 + { }
69635 +};
69636 +#endif
69637 +
69638 /* The default sysctl tables: */
69639
69640 static struct ctl_table sysctl_base_table[] = {
69641 @@ -256,6 +274,22 @@ static int max_extfrag_threshold = 1000;
69642 #endif
69643
69644 static struct ctl_table kern_table[] = {
69645 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69646 + {
69647 + .procname = "grsecurity",
69648 + .mode = 0500,
69649 + .child = grsecurity_table,
69650 + },
69651 +#endif
69652 +
69653 +#ifdef CONFIG_PAX_SOFTMODE
69654 + {
69655 + .procname = "pax",
69656 + .mode = 0500,
69657 + .child = pax_table,
69658 + },
69659 +#endif
69660 +
69661 {
69662 .procname = "sched_child_runs_first",
69663 .data = &sysctl_sched_child_runs_first,
69664 @@ -410,7 +444,7 @@ static struct ctl_table kern_table[] = {
69665 .data = core_pattern,
69666 .maxlen = CORENAME_MAX_SIZE,
69667 .mode = 0644,
69668 - .proc_handler = proc_dostring,
69669 + .proc_handler = proc_dostring_coredump,
69670 },
69671 {
69672 .procname = "core_pipe_limit",
69673 @@ -540,7 +574,7 @@ static struct ctl_table kern_table[] = {
69674 .data = &modprobe_path,
69675 .maxlen = KMOD_PATH_LEN,
69676 .mode = 0644,
69677 - .proc_handler = proc_dostring,
69678 + .proc_handler = proc_dostring_modpriv,
69679 },
69680 {
69681 .procname = "modules_disabled",
69682 @@ -707,16 +741,20 @@ static struct ctl_table kern_table[] = {
69683 .extra1 = &zero,
69684 .extra2 = &one,
69685 },
69686 +#endif
69687 {
69688 .procname = "kptr_restrict",
69689 .data = &kptr_restrict,
69690 .maxlen = sizeof(int),
69691 .mode = 0644,
69692 .proc_handler = proc_dointvec_minmax_sysadmin,
69693 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69694 + .extra1 = &two,
69695 +#else
69696 .extra1 = &zero,
69697 +#endif
69698 .extra2 = &two,
69699 },
69700 -#endif
69701 {
69702 .procname = "ngroups_max",
69703 .data = &ngroups_max,
69704 @@ -1215,6 +1253,13 @@ static struct ctl_table vm_table[] = {
69705 .proc_handler = proc_dointvec_minmax,
69706 .extra1 = &zero,
69707 },
69708 + {
69709 + .procname = "heap_stack_gap",
69710 + .data = &sysctl_heap_stack_gap,
69711 + .maxlen = sizeof(sysctl_heap_stack_gap),
69712 + .mode = 0644,
69713 + .proc_handler = proc_doulongvec_minmax,
69714 + },
69715 #else
69716 {
69717 .procname = "nr_trim_pages",
69718 @@ -1498,7 +1543,7 @@ static struct ctl_table fs_table[] = {
69719 .data = &suid_dumpable,
69720 .maxlen = sizeof(int),
69721 .mode = 0644,
69722 - .proc_handler = proc_dointvec_minmax,
69723 + .proc_handler = proc_dointvec_minmax_coredump,
69724 .extra1 = &zero,
69725 .extra2 = &two,
69726 },
69727 @@ -1645,6 +1690,16 @@ int proc_dostring(struct ctl_table *table, int write,
69728 buffer, lenp, ppos);
69729 }
69730
69731 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69732 + void __user *buffer, size_t *lenp, loff_t *ppos)
69733 +{
69734 + if (write && !capable(CAP_SYS_MODULE))
69735 + return -EPERM;
69736 +
69737 + return _proc_do_string(table->data, table->maxlen, write,
69738 + buffer, lenp, ppos);
69739 +}
69740 +
69741 static size_t proc_skip_spaces(char **buf)
69742 {
69743 size_t ret;
69744 @@ -1750,6 +1805,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69745 len = strlen(tmp);
69746 if (len > *size)
69747 len = *size;
69748 + if (len > sizeof(tmp))
69749 + len = sizeof(tmp);
69750 if (copy_to_user(*buf, tmp, len))
69751 return -EFAULT;
69752 *size -= len;
69753 @@ -1942,7 +1999,6 @@ static int proc_taint(struct ctl_table *table, int write,
69754 return err;
69755 }
69756
69757 -#ifdef CONFIG_PRINTK
69758 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69759 void __user *buffer, size_t *lenp, loff_t *ppos)
69760 {
69761 @@ -1951,7 +2007,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69762
69763 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69764 }
69765 -#endif
69766
69767 struct do_proc_dointvec_minmax_conv_param {
69768 int *min;
69769 @@ -2009,6 +2064,34 @@ int proc_dointvec_minmax(struct ctl_table *table, int write,
69770 do_proc_dointvec_minmax_conv, &param);
69771 }
69772
69773 +static void validate_coredump_safety(void)
69774 +{
69775 + if (suid_dumpable == SUID_DUMPABLE_SAFE &&
69776 + core_pattern[0] != '/' && core_pattern[0] != '|') {
69777 + printk(KERN_WARNING "Unsafe core_pattern used with "\
69778 + "suid_dumpable=2. Pipe handler or fully qualified "\
69779 + "core dump path required.\n");
69780 + }
69781 +}
69782 +
69783 +static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69784 + void __user *buffer, size_t *lenp, loff_t *ppos)
69785 +{
69786 + int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69787 + if (!error)
69788 + validate_coredump_safety();
69789 + return error;
69790 +}
69791 +
69792 +static int proc_dostring_coredump(struct ctl_table *table, int write,
69793 + void __user *buffer, size_t *lenp, loff_t *ppos)
69794 +{
69795 + int error = proc_dostring(table, write, buffer, lenp, ppos);
69796 + if (!error)
69797 + validate_coredump_safety();
69798 + return error;
69799 +}
69800 +
69801 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
69802 void __user *buffer,
69803 size_t *lenp, loff_t *ppos,
69804 @@ -2066,8 +2149,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
69805 *i = val;
69806 } else {
69807 val = convdiv * (*i) / convmul;
69808 - if (!first)
69809 + if (!first) {
69810 err = proc_put_char(&buffer, &left, '\t');
69811 + if (err)
69812 + break;
69813 + }
69814 err = proc_put_long(&buffer, &left, val, false);
69815 if (err)
69816 break;
69817 @@ -2459,6 +2545,12 @@ int proc_dostring(struct ctl_table *table, int write,
69818 return -ENOSYS;
69819 }
69820
69821 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69822 + void __user *buffer, size_t *lenp, loff_t *ppos)
69823 +{
69824 + return -ENOSYS;
69825 +}
69826 +
69827 int proc_dointvec(struct ctl_table *table, int write,
69828 void __user *buffer, size_t *lenp, loff_t *ppos)
69829 {
69830 @@ -2515,5 +2607,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
69831 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
69832 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
69833 EXPORT_SYMBOL(proc_dostring);
69834 +EXPORT_SYMBOL(proc_dostring_modpriv);
69835 EXPORT_SYMBOL(proc_doulongvec_minmax);
69836 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
69837 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
69838 index a650694..aaeeb20 100644
69839 --- a/kernel/sysctl_binary.c
69840 +++ b/kernel/sysctl_binary.c
69841 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
69842 int i;
69843
69844 set_fs(KERNEL_DS);
69845 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69846 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69847 set_fs(old_fs);
69848 if (result < 0)
69849 goto out_kfree;
69850 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
69851 }
69852
69853 set_fs(KERNEL_DS);
69854 - result = vfs_write(file, buffer, str - buffer, &pos);
69855 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69856 set_fs(old_fs);
69857 if (result < 0)
69858 goto out_kfree;
69859 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
69860 int i;
69861
69862 set_fs(KERNEL_DS);
69863 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69864 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69865 set_fs(old_fs);
69866 if (result < 0)
69867 goto out_kfree;
69868 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
69869 }
69870
69871 set_fs(KERNEL_DS);
69872 - result = vfs_write(file, buffer, str - buffer, &pos);
69873 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69874 set_fs(old_fs);
69875 if (result < 0)
69876 goto out_kfree;
69877 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
69878 int i;
69879
69880 set_fs(KERNEL_DS);
69881 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69882 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69883 set_fs(old_fs);
69884 if (result < 0)
69885 goto out;
69886 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69887 __le16 dnaddr;
69888
69889 set_fs(KERNEL_DS);
69890 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69891 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69892 set_fs(old_fs);
69893 if (result < 0)
69894 goto out;
69895 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69896 le16_to_cpu(dnaddr) & 0x3ff);
69897
69898 set_fs(KERNEL_DS);
69899 - result = vfs_write(file, buf, len, &pos);
69900 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
69901 set_fs(old_fs);
69902 if (result < 0)
69903 goto out;
69904 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
69905 index e660464..c8b9e67 100644
69906 --- a/kernel/taskstats.c
69907 +++ b/kernel/taskstats.c
69908 @@ -27,9 +27,12 @@
69909 #include <linux/cgroup.h>
69910 #include <linux/fs.h>
69911 #include <linux/file.h>
69912 +#include <linux/grsecurity.h>
69913 #include <net/genetlink.h>
69914 #include <linux/atomic.h>
69915
69916 +extern int gr_is_taskstats_denied(int pid);
69917 +
69918 /*
69919 * Maximum length of a cpumask that can be specified in
69920 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
69921 @@ -556,6 +559,9 @@ err:
69922
69923 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
69924 {
69925 + if (gr_is_taskstats_denied(current->pid))
69926 + return -EACCES;
69927 +
69928 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
69929 return cmd_attr_register_cpumask(info);
69930 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
69931 diff --git a/kernel/time.c b/kernel/time.c
69932 index ba744cf..267b7c5 100644
69933 --- a/kernel/time.c
69934 +++ b/kernel/time.c
69935 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
69936 return error;
69937
69938 if (tz) {
69939 + /* we log in do_settimeofday called below, so don't log twice
69940 + */
69941 + if (!tv)
69942 + gr_log_timechange();
69943 +
69944 sys_tz = *tz;
69945 update_vsyscall_tz();
69946 if (firsttime) {
69947 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
69948 index aa27d39..34d221c 100644
69949 --- a/kernel/time/alarmtimer.c
69950 +++ b/kernel/time/alarmtimer.c
69951 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
69952 struct platform_device *pdev;
69953 int error = 0;
69954 int i;
69955 - struct k_clock alarm_clock = {
69956 + static struct k_clock alarm_clock = {
69957 .clock_getres = alarm_clock_getres,
69958 .clock_get = alarm_clock_get,
69959 .timer_create = alarm_timer_create,
69960 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
69961 index f113755..ec24223 100644
69962 --- a/kernel/time/tick-broadcast.c
69963 +++ b/kernel/time/tick-broadcast.c
69964 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
69965 * then clear the broadcast bit.
69966 */
69967 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
69968 - int cpu = smp_processor_id();
69969 + cpu = smp_processor_id();
69970
69971 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
69972 tick_broadcast_clear_oneshot(cpu);
69973 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
69974 index 3447cfa..291806b 100644
69975 --- a/kernel/time/timekeeping.c
69976 +++ b/kernel/time/timekeeping.c
69977 @@ -14,6 +14,7 @@
69978 #include <linux/init.h>
69979 #include <linux/mm.h>
69980 #include <linux/sched.h>
69981 +#include <linux/grsecurity.h>
69982 #include <linux/syscore_ops.h>
69983 #include <linux/clocksource.h>
69984 #include <linux/jiffies.h>
69985 @@ -387,6 +388,8 @@ int do_settimeofday(const struct timespec *tv)
69986 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
69987 return -EINVAL;
69988
69989 + gr_log_timechange();
69990 +
69991 write_seqlock_irqsave(&timekeeper.lock, flags);
69992
69993 timekeeping_forward_now();
69994 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
69995 index 3258455..f35227d 100644
69996 --- a/kernel/time/timer_list.c
69997 +++ b/kernel/time/timer_list.c
69998 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
69999
70000 static void print_name_offset(struct seq_file *m, void *sym)
70001 {
70002 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70003 + SEQ_printf(m, "<%p>", NULL);
70004 +#else
70005 char symname[KSYM_NAME_LEN];
70006
70007 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70008 SEQ_printf(m, "<%pK>", sym);
70009 else
70010 SEQ_printf(m, "%s", symname);
70011 +#endif
70012 }
70013
70014 static void
70015 @@ -112,7 +116,11 @@ next_one:
70016 static void
70017 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70018 {
70019 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70020 + SEQ_printf(m, " .base: %p\n", NULL);
70021 +#else
70022 SEQ_printf(m, " .base: %pK\n", base);
70023 +#endif
70024 SEQ_printf(m, " .index: %d\n",
70025 base->index);
70026 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70027 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70028 {
70029 struct proc_dir_entry *pe;
70030
70031 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70032 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70033 +#else
70034 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70035 +#endif
70036 if (!pe)
70037 return -ENOMEM;
70038 return 0;
70039 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70040 index 0b537f2..9e71eca 100644
70041 --- a/kernel/time/timer_stats.c
70042 +++ b/kernel/time/timer_stats.c
70043 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70044 static unsigned long nr_entries;
70045 static struct entry entries[MAX_ENTRIES];
70046
70047 -static atomic_t overflow_count;
70048 +static atomic_unchecked_t overflow_count;
70049
70050 /*
70051 * The entries are in a hash-table, for fast lookup:
70052 @@ -140,7 +140,7 @@ static void reset_entries(void)
70053 nr_entries = 0;
70054 memset(entries, 0, sizeof(entries));
70055 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70056 - atomic_set(&overflow_count, 0);
70057 + atomic_set_unchecked(&overflow_count, 0);
70058 }
70059
70060 static struct entry *alloc_entry(void)
70061 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70062 if (likely(entry))
70063 entry->count++;
70064 else
70065 - atomic_inc(&overflow_count);
70066 + atomic_inc_unchecked(&overflow_count);
70067
70068 out_unlock:
70069 raw_spin_unlock_irqrestore(lock, flags);
70070 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70071
70072 static void print_name_offset(struct seq_file *m, unsigned long addr)
70073 {
70074 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70075 + seq_printf(m, "<%p>", NULL);
70076 +#else
70077 char symname[KSYM_NAME_LEN];
70078
70079 if (lookup_symbol_name(addr, symname) < 0)
70080 seq_printf(m, "<%p>", (void *)addr);
70081 else
70082 seq_printf(m, "%s", symname);
70083 +#endif
70084 }
70085
70086 static int tstats_show(struct seq_file *m, void *v)
70087 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70088
70089 seq_puts(m, "Timer Stats Version: v0.2\n");
70090 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70091 - if (atomic_read(&overflow_count))
70092 + if (atomic_read_unchecked(&overflow_count))
70093 seq_printf(m, "Overflow: %d entries\n",
70094 - atomic_read(&overflow_count));
70095 + atomic_read_unchecked(&overflow_count));
70096
70097 for (i = 0; i < nr_entries; i++) {
70098 entry = entries + i;
70099 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70100 {
70101 struct proc_dir_entry *pe;
70102
70103 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70104 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70105 +#else
70106 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70107 +#endif
70108 if (!pe)
70109 return -ENOMEM;
70110 return 0;
70111 diff --git a/kernel/timer.c b/kernel/timer.c
70112 index 6ec7e7e..cbc448b 100644
70113 --- a/kernel/timer.c
70114 +++ b/kernel/timer.c
70115 @@ -1362,7 +1362,7 @@ void update_process_times(int user_tick)
70116 /*
70117 * This function runs timers and the timer-tq in bottom half context.
70118 */
70119 -static void run_timer_softirq(struct softirq_action *h)
70120 +static void run_timer_softirq(void)
70121 {
70122 struct tvec_base *base = __this_cpu_read(tvec_bases);
70123
70124 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70125 index c0bd030..62a1927 100644
70126 --- a/kernel/trace/blktrace.c
70127 +++ b/kernel/trace/blktrace.c
70128 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70129 struct blk_trace *bt = filp->private_data;
70130 char buf[16];
70131
70132 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70133 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70134
70135 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70136 }
70137 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70138 return 1;
70139
70140 bt = buf->chan->private_data;
70141 - atomic_inc(&bt->dropped);
70142 + atomic_inc_unchecked(&bt->dropped);
70143 return 0;
70144 }
70145
70146 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70147
70148 bt->dir = dir;
70149 bt->dev = dev;
70150 - atomic_set(&bt->dropped, 0);
70151 + atomic_set_unchecked(&bt->dropped, 0);
70152
70153 ret = -EIO;
70154 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70155 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70156 index a008663..30d7429 100644
70157 --- a/kernel/trace/ftrace.c
70158 +++ b/kernel/trace/ftrace.c
70159 @@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70160 if (unlikely(ftrace_disabled))
70161 return 0;
70162
70163 + ret = ftrace_arch_code_modify_prepare();
70164 + FTRACE_WARN_ON(ret);
70165 + if (ret)
70166 + return 0;
70167 +
70168 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70169 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70170 if (ret) {
70171 ftrace_bug(ret, ip);
70172 - return 0;
70173 }
70174 - return 1;
70175 + return ret ? 0 : 1;
70176 }
70177
70178 /*
70179 @@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70180
70181 int
70182 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70183 - void *data)
70184 + void *data)
70185 {
70186 struct ftrace_func_probe *entry;
70187 struct ftrace_page *pg;
70188 @@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
70189 if (!count)
70190 return 0;
70191
70192 + pax_open_kernel();
70193 sort(start, count, sizeof(*start),
70194 ftrace_cmp_ips, ftrace_swap_ips);
70195 + pax_close_kernel();
70196
70197 start_pg = ftrace_allocate_pages(count);
70198 if (!start_pg)
70199 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70200 index a7fa070..403bc8d 100644
70201 --- a/kernel/trace/trace.c
70202 +++ b/kernel/trace/trace.c
70203 @@ -4421,10 +4421,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70204 };
70205 #endif
70206
70207 -static struct dentry *d_tracer;
70208 -
70209 struct dentry *tracing_init_dentry(void)
70210 {
70211 + static struct dentry *d_tracer;
70212 static int once;
70213
70214 if (d_tracer)
70215 @@ -4444,10 +4443,9 @@ struct dentry *tracing_init_dentry(void)
70216 return d_tracer;
70217 }
70218
70219 -static struct dentry *d_percpu;
70220 -
70221 struct dentry *tracing_dentry_percpu(void)
70222 {
70223 + static struct dentry *d_percpu;
70224 static int once;
70225 struct dentry *d_tracer;
70226
70227 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70228 index 29111da..d190fe2 100644
70229 --- a/kernel/trace/trace_events.c
70230 +++ b/kernel/trace/trace_events.c
70231 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
70232 struct ftrace_module_file_ops {
70233 struct list_head list;
70234 struct module *mod;
70235 - struct file_operations id;
70236 - struct file_operations enable;
70237 - struct file_operations format;
70238 - struct file_operations filter;
70239 };
70240
70241 static struct ftrace_module_file_ops *
70242 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
70243
70244 file_ops->mod = mod;
70245
70246 - file_ops->id = ftrace_event_id_fops;
70247 - file_ops->id.owner = mod;
70248 -
70249 - file_ops->enable = ftrace_enable_fops;
70250 - file_ops->enable.owner = mod;
70251 -
70252 - file_ops->filter = ftrace_event_filter_fops;
70253 - file_ops->filter.owner = mod;
70254 -
70255 - file_ops->format = ftrace_event_format_fops;
70256 - file_ops->format.owner = mod;
70257 + pax_open_kernel();
70258 + *(void **)&mod->trace_id.owner = mod;
70259 + *(void **)&mod->trace_enable.owner = mod;
70260 + *(void **)&mod->trace_filter.owner = mod;
70261 + *(void **)&mod->trace_format.owner = mod;
70262 + pax_close_kernel();
70263
70264 list_add(&file_ops->list, &ftrace_module_file_list);
70265
70266 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
70267
70268 for_each_event(call, start, end) {
70269 __trace_add_event_call(*call, mod,
70270 - &file_ops->id, &file_ops->enable,
70271 - &file_ops->filter, &file_ops->format);
70272 + &mod->trace_id, &mod->trace_enable,
70273 + &mod->trace_filter, &mod->trace_format);
70274 }
70275 }
70276
70277 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70278 index fd3c8aa..5f324a6 100644
70279 --- a/kernel/trace/trace_mmiotrace.c
70280 +++ b/kernel/trace/trace_mmiotrace.c
70281 @@ -24,7 +24,7 @@ struct header_iter {
70282 static struct trace_array *mmio_trace_array;
70283 static bool overrun_detected;
70284 static unsigned long prev_overruns;
70285 -static atomic_t dropped_count;
70286 +static atomic_unchecked_t dropped_count;
70287
70288 static void mmio_reset_data(struct trace_array *tr)
70289 {
70290 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70291
70292 static unsigned long count_overruns(struct trace_iterator *iter)
70293 {
70294 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
70295 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70296 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70297
70298 if (over > prev_overruns)
70299 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70300 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70301 sizeof(*entry), 0, pc);
70302 if (!event) {
70303 - atomic_inc(&dropped_count);
70304 + atomic_inc_unchecked(&dropped_count);
70305 return;
70306 }
70307 entry = ring_buffer_event_data(event);
70308 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70309 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70310 sizeof(*entry), 0, pc);
70311 if (!event) {
70312 - atomic_inc(&dropped_count);
70313 + atomic_inc_unchecked(&dropped_count);
70314 return;
70315 }
70316 entry = ring_buffer_event_data(event);
70317 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
70318 index df611a0..10d8b32 100644
70319 --- a/kernel/trace/trace_output.c
70320 +++ b/kernel/trace/trace_output.c
70321 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
70322
70323 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
70324 if (!IS_ERR(p)) {
70325 - p = mangle_path(s->buffer + s->len, p, "\n");
70326 + p = mangle_path(s->buffer + s->len, p, "\n\\");
70327 if (p) {
70328 s->len = p - s->buffer;
70329 return 1;
70330 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
70331 index d4545f4..a9010a1 100644
70332 --- a/kernel/trace/trace_stack.c
70333 +++ b/kernel/trace/trace_stack.c
70334 @@ -53,7 +53,7 @@ static inline void check_stack(void)
70335 return;
70336
70337 /* we do not handle interrupt stacks yet */
70338 - if (!object_is_on_stack(&this_size))
70339 + if (!object_starts_on_stack(&this_size))
70340 return;
70341
70342 local_irq_save(flags);
70343 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
70344 index ff5bdee..3eaeba6 100644
70345 --- a/lib/Kconfig.debug
70346 +++ b/lib/Kconfig.debug
70347 @@ -1165,6 +1165,7 @@ config LATENCYTOP
70348 depends on DEBUG_KERNEL
70349 depends on STACKTRACE_SUPPORT
70350 depends on PROC_FS
70351 + depends on !GRKERNSEC_HIDESYM
70352 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
70353 select KALLSYMS
70354 select KALLSYMS_ALL
70355 diff --git a/lib/bitmap.c b/lib/bitmap.c
70356 index 06fdfa1..97c5c7d 100644
70357 --- a/lib/bitmap.c
70358 +++ b/lib/bitmap.c
70359 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
70360 {
70361 int c, old_c, totaldigits, ndigits, nchunks, nbits;
70362 u32 chunk;
70363 - const char __user __force *ubuf = (const char __user __force *)buf;
70364 + const char __user *ubuf = (const char __force_user *)buf;
70365
70366 bitmap_zero(maskp, nmaskbits);
70367
70368 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
70369 {
70370 if (!access_ok(VERIFY_READ, ubuf, ulen))
70371 return -EFAULT;
70372 - return __bitmap_parse((const char __force *)ubuf,
70373 + return __bitmap_parse((const char __force_kernel *)ubuf,
70374 ulen, 1, maskp, nmaskbits);
70375
70376 }
70377 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
70378 {
70379 unsigned a, b;
70380 int c, old_c, totaldigits;
70381 - const char __user __force *ubuf = (const char __user __force *)buf;
70382 + const char __user *ubuf = (const char __force_user *)buf;
70383 int exp_digit, in_range;
70384
70385 totaldigits = c = 0;
70386 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
70387 {
70388 if (!access_ok(VERIFY_READ, ubuf, ulen))
70389 return -EFAULT;
70390 - return __bitmap_parselist((const char __force *)ubuf,
70391 + return __bitmap_parselist((const char __force_kernel *)ubuf,
70392 ulen, 1, maskp, nmaskbits);
70393 }
70394 EXPORT_SYMBOL(bitmap_parselist_user);
70395 diff --git a/lib/bug.c b/lib/bug.c
70396 index a28c141..2bd3d95 100644
70397 --- a/lib/bug.c
70398 +++ b/lib/bug.c
70399 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
70400 return BUG_TRAP_TYPE_NONE;
70401
70402 bug = find_bug(bugaddr);
70403 + if (!bug)
70404 + return BUG_TRAP_TYPE_NONE;
70405
70406 file = NULL;
70407 line = 0;
70408 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
70409 index d11808c..dc2d6f8 100644
70410 --- a/lib/debugobjects.c
70411 +++ b/lib/debugobjects.c
70412 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
70413 if (limit > 4)
70414 return;
70415
70416 - is_on_stack = object_is_on_stack(addr);
70417 + is_on_stack = object_starts_on_stack(addr);
70418 if (is_on_stack == onstack)
70419 return;
70420
70421 diff --git a/lib/devres.c b/lib/devres.c
70422 index 80b9c76..9e32279 100644
70423 --- a/lib/devres.c
70424 +++ b/lib/devres.c
70425 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
70426 void devm_iounmap(struct device *dev, void __iomem *addr)
70427 {
70428 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
70429 - (void *)addr));
70430 + (void __force *)addr));
70431 iounmap(addr);
70432 }
70433 EXPORT_SYMBOL(devm_iounmap);
70434 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
70435 {
70436 ioport_unmap(addr);
70437 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
70438 - devm_ioport_map_match, (void *)addr));
70439 + devm_ioport_map_match, (void __force *)addr));
70440 }
70441 EXPORT_SYMBOL(devm_ioport_unmap);
70442
70443 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
70444 index 66ce414..6f0a0dd 100644
70445 --- a/lib/dma-debug.c
70446 +++ b/lib/dma-debug.c
70447 @@ -924,7 +924,7 @@ out:
70448
70449 static void check_for_stack(struct device *dev, void *addr)
70450 {
70451 - if (object_is_on_stack(addr))
70452 + if (object_starts_on_stack(addr))
70453 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
70454 "stack [addr=%p]\n", addr);
70455 }
70456 diff --git a/lib/extable.c b/lib/extable.c
70457 index 4cac81e..4d66cfc 100644
70458 --- a/lib/extable.c
70459 +++ b/lib/extable.c
70460 @@ -13,6 +13,7 @@
70461 #include <linux/init.h>
70462 #include <linux/sort.h>
70463 #include <asm/uaccess.h>
70464 +#include <asm/pgtable.h>
70465
70466 #ifndef ARCH_HAS_SORT_EXTABLE
70467 /*
70468 diff --git a/lib/inflate.c b/lib/inflate.c
70469 index 013a761..c28f3fc 100644
70470 --- a/lib/inflate.c
70471 +++ b/lib/inflate.c
70472 @@ -269,7 +269,7 @@ static void free(void *where)
70473 malloc_ptr = free_mem_ptr;
70474 }
70475 #else
70476 -#define malloc(a) kmalloc(a, GFP_KERNEL)
70477 +#define malloc(a) kmalloc((a), GFP_KERNEL)
70478 #define free(a) kfree(a)
70479 #endif
70480
70481 diff --git a/lib/ioremap.c b/lib/ioremap.c
70482 index 0c9216c..863bd89 100644
70483 --- a/lib/ioremap.c
70484 +++ b/lib/ioremap.c
70485 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
70486 unsigned long next;
70487
70488 phys_addr -= addr;
70489 - pmd = pmd_alloc(&init_mm, pud, addr);
70490 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
70491 if (!pmd)
70492 return -ENOMEM;
70493 do {
70494 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
70495 unsigned long next;
70496
70497 phys_addr -= addr;
70498 - pud = pud_alloc(&init_mm, pgd, addr);
70499 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
70500 if (!pud)
70501 return -ENOMEM;
70502 do {
70503 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70504 index bd2bea9..6b3c95e 100644
70505 --- a/lib/is_single_threaded.c
70506 +++ b/lib/is_single_threaded.c
70507 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70508 struct task_struct *p, *t;
70509 bool ret;
70510
70511 + if (!mm)
70512 + return true;
70513 +
70514 if (atomic_read(&task->signal->live) != 1)
70515 return false;
70516
70517 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70518 index e796429..6e38f9f 100644
70519 --- a/lib/radix-tree.c
70520 +++ b/lib/radix-tree.c
70521 @@ -92,7 +92,7 @@ struct radix_tree_preload {
70522 int nr;
70523 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
70524 };
70525 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70526 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70527
70528 static inline void *ptr_to_indirect(void *ptr)
70529 {
70530 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70531 index c3f36d41..5c5aeb5 100644
70532 --- a/lib/vsprintf.c
70533 +++ b/lib/vsprintf.c
70534 @@ -16,6 +16,9 @@
70535 * - scnprintf and vscnprintf
70536 */
70537
70538 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70539 +#define __INCLUDED_BY_HIDESYM 1
70540 +#endif
70541 #include <stdarg.h>
70542 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
70543 #include <linux/types.h>
70544 @@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70545 char sym[KSYM_SYMBOL_LEN];
70546 if (ext == 'B')
70547 sprint_backtrace(sym, value);
70548 - else if (ext != 'f' && ext != 's')
70549 + else if (ext != 'f' && ext != 's' && ext != 'a')
70550 sprint_symbol(sym, value);
70551 else
70552 sprint_symbol_no_offset(sym, value);
70553 @@ -912,7 +915,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
70554 return number(buf, end, *(const netdev_features_t *)addr, spec);
70555 }
70556
70557 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70558 +int kptr_restrict __read_mostly = 2;
70559 +#else
70560 int kptr_restrict __read_mostly;
70561 +#endif
70562
70563 /*
70564 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70565 @@ -926,6 +933,8 @@ int kptr_restrict __read_mostly;
70566 * - 'S' For symbolic direct pointers with offset
70567 * - 's' For symbolic direct pointers without offset
70568 * - 'B' For backtraced symbolic direct pointers with offset
70569 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70570 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70571 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70572 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70573 * - 'M' For a 6-byte MAC address, it prints the address in the
70574 @@ -973,12 +982,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70575
70576 if (!ptr && *fmt != 'K') {
70577 /*
70578 - * Print (null) with the same width as a pointer so it makes
70579 + * Print (nil) with the same width as a pointer so it makes
70580 * tabular output look nice.
70581 */
70582 if (spec.field_width == -1)
70583 spec.field_width = default_width;
70584 - return string(buf, end, "(null)", spec);
70585 + return string(buf, end, "(nil)", spec);
70586 }
70587
70588 switch (*fmt) {
70589 @@ -988,6 +997,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70590 /* Fallthrough */
70591 case 'S':
70592 case 's':
70593 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70594 + break;
70595 +#else
70596 + return symbol_string(buf, end, ptr, spec, *fmt);
70597 +#endif
70598 + case 'A':
70599 + case 'a':
70600 case 'B':
70601 return symbol_string(buf, end, ptr, spec, *fmt);
70602 case 'R':
70603 @@ -1025,12 +1041,15 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70604 va_end(va);
70605 return buf;
70606 }
70607 + case 'P':
70608 + break;
70609 case 'K':
70610 /*
70611 * %pK cannot be used in IRQ context because its test
70612 * for CAP_SYSLOG would be meaningless.
70613 */
70614 - if (in_irq() || in_serving_softirq() || in_nmi()) {
70615 + if (kptr_restrict && (in_irq() || in_serving_softirq() ||
70616 + in_nmi())) {
70617 if (spec.field_width == -1)
70618 spec.field_width = default_width;
70619 return string(buf, end, "pK-error", spec);
70620 @@ -1047,6 +1066,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70621 }
70622 break;
70623 }
70624 +
70625 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70626 + /* 'P' = approved pointers to copy to userland,
70627 + as in the /proc/kallsyms case, as we make it display nothing
70628 + for non-root users, and the real contents for root users
70629 + Also ignore 'K' pointers, since we force their NULLing for non-root users
70630 + above
70631 + */
70632 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
70633 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
70634 + dump_stack();
70635 + ptr = NULL;
70636 + }
70637 +#endif
70638 +
70639 spec.flags |= SMALL;
70640 if (spec.field_width == -1) {
70641 spec.field_width = default_width;
70642 @@ -1758,11 +1792,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70643 typeof(type) value; \
70644 if (sizeof(type) == 8) { \
70645 args = PTR_ALIGN(args, sizeof(u32)); \
70646 - *(u32 *)&value = *(u32 *)args; \
70647 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70648 + *(u32 *)&value = *(const u32 *)args; \
70649 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70650 } else { \
70651 args = PTR_ALIGN(args, sizeof(type)); \
70652 - value = *(typeof(type) *)args; \
70653 + value = *(const typeof(type) *)args; \
70654 } \
70655 args += sizeof(type); \
70656 value; \
70657 @@ -1825,7 +1859,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70658 case FORMAT_TYPE_STR: {
70659 const char *str_arg = args;
70660 args += strlen(str_arg) + 1;
70661 - str = string(str, end, (char *)str_arg, spec);
70662 + str = string(str, end, str_arg, spec);
70663 break;
70664 }
70665
70666 diff --git a/localversion-grsec b/localversion-grsec
70667 new file mode 100644
70668 index 0000000..7cd6065
70669 --- /dev/null
70670 +++ b/localversion-grsec
70671 @@ -0,0 +1 @@
70672 +-grsec
70673 diff --git a/mm/Kconfig b/mm/Kconfig
70674 index 82fed4e..979e814 100644
70675 --- a/mm/Kconfig
70676 +++ b/mm/Kconfig
70677 @@ -247,10 +247,10 @@ config KSM
70678 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70679
70680 config DEFAULT_MMAP_MIN_ADDR
70681 - int "Low address space to protect from user allocation"
70682 + int "Low address space to protect from user allocation"
70683 depends on MMU
70684 - default 4096
70685 - help
70686 + default 65536
70687 + help
70688 This is the portion of low virtual memory which should be protected
70689 from userspace allocation. Keeping a user from writing to low pages
70690 can help reduce the impact of kernel NULL pointer bugs.
70691 @@ -280,7 +280,7 @@ config MEMORY_FAILURE
70692
70693 config HWPOISON_INJECT
70694 tristate "HWPoison pages injector"
70695 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
70696 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
70697 select PROC_PAGE_MONITOR
70698
70699 config NOMMU_INITIAL_TRIM_EXCESS
70700 diff --git a/mm/filemap.c b/mm/filemap.c
70701 index a4a5260..6151dc5 100644
70702 --- a/mm/filemap.c
70703 +++ b/mm/filemap.c
70704 @@ -1723,7 +1723,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70705 struct address_space *mapping = file->f_mapping;
70706
70707 if (!mapping->a_ops->readpage)
70708 - return -ENOEXEC;
70709 + return -ENODEV;
70710 file_accessed(file);
70711 vma->vm_ops = &generic_file_vm_ops;
70712 vma->vm_flags |= VM_CAN_NONLINEAR;
70713 @@ -2064,6 +2064,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70714 *pos = i_size_read(inode);
70715
70716 if (limit != RLIM_INFINITY) {
70717 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70718 if (*pos >= limit) {
70719 send_sig(SIGXFSZ, current, 0);
70720 return -EFBIG;
70721 diff --git a/mm/fremap.c b/mm/fremap.c
70722 index 9ed4fd4..c42648d 100644
70723 --- a/mm/fremap.c
70724 +++ b/mm/fremap.c
70725 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70726 retry:
70727 vma = find_vma(mm, start);
70728
70729 +#ifdef CONFIG_PAX_SEGMEXEC
70730 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70731 + goto out;
70732 +#endif
70733 +
70734 /*
70735 * Make sure the vma is shared, that it supports prefaulting,
70736 * and that the remapped range is valid and fully within
70737 diff --git a/mm/highmem.c b/mm/highmem.c
70738 index 57d82c6..e9e0552 100644
70739 --- a/mm/highmem.c
70740 +++ b/mm/highmem.c
70741 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70742 * So no dangers, even with speculative execution.
70743 */
70744 page = pte_page(pkmap_page_table[i]);
70745 + pax_open_kernel();
70746 pte_clear(&init_mm, (unsigned long)page_address(page),
70747 &pkmap_page_table[i]);
70748 -
70749 + pax_close_kernel();
70750 set_page_address(page, NULL);
70751 need_flush = 1;
70752 }
70753 @@ -186,9 +187,11 @@ start:
70754 }
70755 }
70756 vaddr = PKMAP_ADDR(last_pkmap_nr);
70757 +
70758 + pax_open_kernel();
70759 set_pte_at(&init_mm, vaddr,
70760 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70761 -
70762 + pax_close_kernel();
70763 pkmap_count[last_pkmap_nr] = 1;
70764 set_page_address(page, (void *)vaddr);
70765
70766 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70767 index 57c4b93..24b8f59 100644
70768 --- a/mm/huge_memory.c
70769 +++ b/mm/huge_memory.c
70770 @@ -735,7 +735,7 @@ out:
70771 * run pte_offset_map on the pmd, if an huge pmd could
70772 * materialize from under us from a different thread.
70773 */
70774 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70775 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70776 return VM_FAULT_OOM;
70777 /* if an huge pmd materialized from under us just retry later */
70778 if (unlikely(pmd_trans_huge(*pmd)))
70779 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70780 index e198831..38d524f 100644
70781 --- a/mm/hugetlb.c
70782 +++ b/mm/hugetlb.c
70783 @@ -2447,6 +2447,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70784 return 1;
70785 }
70786
70787 +#ifdef CONFIG_PAX_SEGMEXEC
70788 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70789 +{
70790 + struct mm_struct *mm = vma->vm_mm;
70791 + struct vm_area_struct *vma_m;
70792 + unsigned long address_m;
70793 + pte_t *ptep_m;
70794 +
70795 + vma_m = pax_find_mirror_vma(vma);
70796 + if (!vma_m)
70797 + return;
70798 +
70799 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70800 + address_m = address + SEGMEXEC_TASK_SIZE;
70801 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70802 + get_page(page_m);
70803 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
70804 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70805 +}
70806 +#endif
70807 +
70808 /*
70809 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70810 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
70811 @@ -2559,6 +2580,11 @@ retry_avoidcopy:
70812 make_huge_pte(vma, new_page, 1));
70813 page_remove_rmap(old_page);
70814 hugepage_add_new_anon_rmap(new_page, vma, address);
70815 +
70816 +#ifdef CONFIG_PAX_SEGMEXEC
70817 + pax_mirror_huge_pte(vma, address, new_page);
70818 +#endif
70819 +
70820 /* Make the old page be freed below */
70821 new_page = old_page;
70822 mmu_notifier_invalidate_range_end(mm,
70823 @@ -2713,6 +2739,10 @@ retry:
70824 && (vma->vm_flags & VM_SHARED)));
70825 set_huge_pte_at(mm, address, ptep, new_pte);
70826
70827 +#ifdef CONFIG_PAX_SEGMEXEC
70828 + pax_mirror_huge_pte(vma, address, page);
70829 +#endif
70830 +
70831 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
70832 /* Optimization, do the COW without a second fault */
70833 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
70834 @@ -2742,6 +2772,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70835 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
70836 struct hstate *h = hstate_vma(vma);
70837
70838 +#ifdef CONFIG_PAX_SEGMEXEC
70839 + struct vm_area_struct *vma_m;
70840 +#endif
70841 +
70842 address &= huge_page_mask(h);
70843
70844 ptep = huge_pte_offset(mm, address);
70845 @@ -2755,6 +2789,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70846 VM_FAULT_SET_HINDEX(h - hstates);
70847 }
70848
70849 +#ifdef CONFIG_PAX_SEGMEXEC
70850 + vma_m = pax_find_mirror_vma(vma);
70851 + if (vma_m) {
70852 + unsigned long address_m;
70853 +
70854 + if (vma->vm_start > vma_m->vm_start) {
70855 + address_m = address;
70856 + address -= SEGMEXEC_TASK_SIZE;
70857 + vma = vma_m;
70858 + h = hstate_vma(vma);
70859 + } else
70860 + address_m = address + SEGMEXEC_TASK_SIZE;
70861 +
70862 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
70863 + return VM_FAULT_OOM;
70864 + address_m &= HPAGE_MASK;
70865 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
70866 + }
70867 +#endif
70868 +
70869 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
70870 if (!ptep)
70871 return VM_FAULT_OOM;
70872 diff --git a/mm/internal.h b/mm/internal.h
70873 index 2ba87fb..7f451e2 100644
70874 --- a/mm/internal.h
70875 +++ b/mm/internal.h
70876 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
70877 * in mm/page_alloc.c
70878 */
70879 extern void __free_pages_bootmem(struct page *page, unsigned int order);
70880 +extern void free_compound_page(struct page *page);
70881 extern void prep_compound_page(struct page *page, unsigned long order);
70882 #ifdef CONFIG_MEMORY_FAILURE
70883 extern bool is_free_buddy_page(struct page *page);
70884 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
70885 index 45eb621..6ccd8ea 100644
70886 --- a/mm/kmemleak.c
70887 +++ b/mm/kmemleak.c
70888 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
70889
70890 for (i = 0; i < object->trace_len; i++) {
70891 void *ptr = (void *)object->trace[i];
70892 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
70893 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
70894 }
70895 }
70896
70897 diff --git a/mm/maccess.c b/mm/maccess.c
70898 index d53adf9..03a24bf 100644
70899 --- a/mm/maccess.c
70900 +++ b/mm/maccess.c
70901 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
70902 set_fs(KERNEL_DS);
70903 pagefault_disable();
70904 ret = __copy_from_user_inatomic(dst,
70905 - (__force const void __user *)src, size);
70906 + (const void __force_user *)src, size);
70907 pagefault_enable();
70908 set_fs(old_fs);
70909
70910 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
70911
70912 set_fs(KERNEL_DS);
70913 pagefault_disable();
70914 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
70915 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
70916 pagefault_enable();
70917 set_fs(old_fs);
70918
70919 diff --git a/mm/madvise.c b/mm/madvise.c
70920 index 14d260f..b2a80fd 100644
70921 --- a/mm/madvise.c
70922 +++ b/mm/madvise.c
70923 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
70924 pgoff_t pgoff;
70925 unsigned long new_flags = vma->vm_flags;
70926
70927 +#ifdef CONFIG_PAX_SEGMEXEC
70928 + struct vm_area_struct *vma_m;
70929 +#endif
70930 +
70931 switch (behavior) {
70932 case MADV_NORMAL:
70933 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
70934 @@ -119,6 +123,13 @@ success:
70935 /*
70936 * vm_flags is protected by the mmap_sem held in write mode.
70937 */
70938 +
70939 +#ifdef CONFIG_PAX_SEGMEXEC
70940 + vma_m = pax_find_mirror_vma(vma);
70941 + if (vma_m)
70942 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
70943 +#endif
70944 +
70945 vma->vm_flags = new_flags;
70946
70947 out:
70948 @@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70949 struct vm_area_struct ** prev,
70950 unsigned long start, unsigned long end)
70951 {
70952 +
70953 +#ifdef CONFIG_PAX_SEGMEXEC
70954 + struct vm_area_struct *vma_m;
70955 +#endif
70956 +
70957 *prev = vma;
70958 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
70959 return -EINVAL;
70960 @@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70961 zap_page_range(vma, start, end - start, &details);
70962 } else
70963 zap_page_range(vma, start, end - start, NULL);
70964 +
70965 +#ifdef CONFIG_PAX_SEGMEXEC
70966 + vma_m = pax_find_mirror_vma(vma);
70967 + if (vma_m) {
70968 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
70969 + struct zap_details details = {
70970 + .nonlinear_vma = vma_m,
70971 + .last_index = ULONG_MAX,
70972 + };
70973 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
70974 + } else
70975 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
70976 + }
70977 +#endif
70978 +
70979 return 0;
70980 }
70981
70982 @@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
70983 if (end < start)
70984 goto out;
70985
70986 +#ifdef CONFIG_PAX_SEGMEXEC
70987 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70988 + if (end > SEGMEXEC_TASK_SIZE)
70989 + goto out;
70990 + } else
70991 +#endif
70992 +
70993 + if (end > TASK_SIZE)
70994 + goto out;
70995 +
70996 error = 0;
70997 if (end == start)
70998 goto out;
70999 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71000 index de4ce70..3629c7d 100644
71001 --- a/mm/memory-failure.c
71002 +++ b/mm/memory-failure.c
71003 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71004
71005 int sysctl_memory_failure_recovery __read_mostly = 1;
71006
71007 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71008 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71009
71010 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71011
71012 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
71013 pfn, t->comm, t->pid);
71014 si.si_signo = SIGBUS;
71015 si.si_errno = 0;
71016 - si.si_addr = (void *)addr;
71017 + si.si_addr = (void __user *)addr;
71018 #ifdef __ARCH_SI_TRAPNO
71019 si.si_trapno = trapno;
71020 #endif
71021 @@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71022 }
71023
71024 nr_pages = 1 << compound_trans_order(hpage);
71025 - atomic_long_add(nr_pages, &mce_bad_pages);
71026 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71027
71028 /*
71029 * We need/can do nothing about count=0 pages.
71030 @@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71031 if (!PageHWPoison(hpage)
71032 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71033 || (p != hpage && TestSetPageHWPoison(hpage))) {
71034 - atomic_long_sub(nr_pages, &mce_bad_pages);
71035 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71036 return 0;
71037 }
71038 set_page_hwpoison_huge_page(hpage);
71039 @@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71040 }
71041 if (hwpoison_filter(p)) {
71042 if (TestClearPageHWPoison(p))
71043 - atomic_long_sub(nr_pages, &mce_bad_pages);
71044 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71045 unlock_page(hpage);
71046 put_page(hpage);
71047 return 0;
71048 @@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
71049 return 0;
71050 }
71051 if (TestClearPageHWPoison(p))
71052 - atomic_long_sub(nr_pages, &mce_bad_pages);
71053 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71054 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71055 return 0;
71056 }
71057 @@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
71058 */
71059 if (TestClearPageHWPoison(page)) {
71060 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71061 - atomic_long_sub(nr_pages, &mce_bad_pages);
71062 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71063 freeit = 1;
71064 if (PageHuge(page))
71065 clear_page_hwpoison_huge_page(page);
71066 @@ -1448,7 +1448,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71067 }
71068 done:
71069 if (!PageHWPoison(hpage))
71070 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
71071 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
71072 set_page_hwpoison_huge_page(hpage);
71073 dequeue_hwpoisoned_huge_page(hpage);
71074 /* keep elevated page count for bad page */
71075 @@ -1579,7 +1579,7 @@ int soft_offline_page(struct page *page, int flags)
71076 return ret;
71077
71078 done:
71079 - atomic_long_add(1, &mce_bad_pages);
71080 + atomic_long_add_unchecked(1, &mce_bad_pages);
71081 SetPageHWPoison(page);
71082 /* keep elevated page count for bad page */
71083 return ret;
71084 diff --git a/mm/memory.c b/mm/memory.c
71085 index 2466d12..08be4f6 100644
71086 --- a/mm/memory.c
71087 +++ b/mm/memory.c
71088 @@ -434,8 +434,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71089 return;
71090
71091 pmd = pmd_offset(pud, start);
71092 +
71093 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71094 pud_clear(pud);
71095 pmd_free_tlb(tlb, pmd, start);
71096 +#endif
71097 +
71098 }
71099
71100 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71101 @@ -466,9 +470,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71102 if (end - 1 > ceiling - 1)
71103 return;
71104
71105 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71106 pud = pud_offset(pgd, start);
71107 pgd_clear(pgd);
71108 pud_free_tlb(tlb, pud, start);
71109 +#endif
71110 +
71111 }
71112
71113 /*
71114 @@ -1602,12 +1609,6 @@ no_page_table:
71115 return page;
71116 }
71117
71118 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71119 -{
71120 - return stack_guard_page_start(vma, addr) ||
71121 - stack_guard_page_end(vma, addr+PAGE_SIZE);
71122 -}
71123 -
71124 /**
71125 * __get_user_pages() - pin user pages in memory
71126 * @tsk: task_struct of target task
71127 @@ -1680,10 +1681,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71128 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71129 i = 0;
71130
71131 - do {
71132 + while (nr_pages) {
71133 struct vm_area_struct *vma;
71134
71135 - vma = find_extend_vma(mm, start);
71136 + vma = find_vma(mm, start);
71137 if (!vma && in_gate_area(mm, start)) {
71138 unsigned long pg = start & PAGE_MASK;
71139 pgd_t *pgd;
71140 @@ -1731,7 +1732,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71141 goto next_page;
71142 }
71143
71144 - if (!vma ||
71145 + if (!vma || start < vma->vm_start ||
71146 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71147 !(vm_flags & vma->vm_flags))
71148 return i ? : -EFAULT;
71149 @@ -1758,11 +1759,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71150 int ret;
71151 unsigned int fault_flags = 0;
71152
71153 - /* For mlock, just skip the stack guard page. */
71154 - if (foll_flags & FOLL_MLOCK) {
71155 - if (stack_guard_page(vma, start))
71156 - goto next_page;
71157 - }
71158 if (foll_flags & FOLL_WRITE)
71159 fault_flags |= FAULT_FLAG_WRITE;
71160 if (nonblocking)
71161 @@ -1836,7 +1832,7 @@ next_page:
71162 start += PAGE_SIZE;
71163 nr_pages--;
71164 } while (nr_pages && start < vma->vm_end);
71165 - } while (nr_pages);
71166 + }
71167 return i;
71168 }
71169 EXPORT_SYMBOL(__get_user_pages);
71170 @@ -2043,6 +2039,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71171 page_add_file_rmap(page);
71172 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71173
71174 +#ifdef CONFIG_PAX_SEGMEXEC
71175 + pax_mirror_file_pte(vma, addr, page, ptl);
71176 +#endif
71177 +
71178 retval = 0;
71179 pte_unmap_unlock(pte, ptl);
71180 return retval;
71181 @@ -2077,10 +2077,22 @@ out:
71182 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71183 struct page *page)
71184 {
71185 +
71186 +#ifdef CONFIG_PAX_SEGMEXEC
71187 + struct vm_area_struct *vma_m;
71188 +#endif
71189 +
71190 if (addr < vma->vm_start || addr >= vma->vm_end)
71191 return -EFAULT;
71192 if (!page_count(page))
71193 return -EINVAL;
71194 +
71195 +#ifdef CONFIG_PAX_SEGMEXEC
71196 + vma_m = pax_find_mirror_vma(vma);
71197 + if (vma_m)
71198 + vma_m->vm_flags |= VM_INSERTPAGE;
71199 +#endif
71200 +
71201 vma->vm_flags |= VM_INSERTPAGE;
71202 return insert_page(vma, addr, page, vma->vm_page_prot);
71203 }
71204 @@ -2166,6 +2178,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71205 unsigned long pfn)
71206 {
71207 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71208 + BUG_ON(vma->vm_mirror);
71209
71210 if (addr < vma->vm_start || addr >= vma->vm_end)
71211 return -EFAULT;
71212 @@ -2373,7 +2386,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
71213
71214 BUG_ON(pud_huge(*pud));
71215
71216 - pmd = pmd_alloc(mm, pud, addr);
71217 + pmd = (mm == &init_mm) ?
71218 + pmd_alloc_kernel(mm, pud, addr) :
71219 + pmd_alloc(mm, pud, addr);
71220 if (!pmd)
71221 return -ENOMEM;
71222 do {
71223 @@ -2393,7 +2408,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
71224 unsigned long next;
71225 int err;
71226
71227 - pud = pud_alloc(mm, pgd, addr);
71228 + pud = (mm == &init_mm) ?
71229 + pud_alloc_kernel(mm, pgd, addr) :
71230 + pud_alloc(mm, pgd, addr);
71231 if (!pud)
71232 return -ENOMEM;
71233 do {
71234 @@ -2481,6 +2498,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71235 copy_user_highpage(dst, src, va, vma);
71236 }
71237
71238 +#ifdef CONFIG_PAX_SEGMEXEC
71239 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71240 +{
71241 + struct mm_struct *mm = vma->vm_mm;
71242 + spinlock_t *ptl;
71243 + pte_t *pte, entry;
71244 +
71245 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71246 + entry = *pte;
71247 + if (!pte_present(entry)) {
71248 + if (!pte_none(entry)) {
71249 + BUG_ON(pte_file(entry));
71250 + free_swap_and_cache(pte_to_swp_entry(entry));
71251 + pte_clear_not_present_full(mm, address, pte, 0);
71252 + }
71253 + } else {
71254 + struct page *page;
71255 +
71256 + flush_cache_page(vma, address, pte_pfn(entry));
71257 + entry = ptep_clear_flush(vma, address, pte);
71258 + BUG_ON(pte_dirty(entry));
71259 + page = vm_normal_page(vma, address, entry);
71260 + if (page) {
71261 + update_hiwater_rss(mm);
71262 + if (PageAnon(page))
71263 + dec_mm_counter_fast(mm, MM_ANONPAGES);
71264 + else
71265 + dec_mm_counter_fast(mm, MM_FILEPAGES);
71266 + page_remove_rmap(page);
71267 + page_cache_release(page);
71268 + }
71269 + }
71270 + pte_unmap_unlock(pte, ptl);
71271 +}
71272 +
71273 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
71274 + *
71275 + * the ptl of the lower mapped page is held on entry and is not released on exit
71276 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71277 + */
71278 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71279 +{
71280 + struct mm_struct *mm = vma->vm_mm;
71281 + unsigned long address_m;
71282 + spinlock_t *ptl_m;
71283 + struct vm_area_struct *vma_m;
71284 + pmd_t *pmd_m;
71285 + pte_t *pte_m, entry_m;
71286 +
71287 + BUG_ON(!page_m || !PageAnon(page_m));
71288 +
71289 + vma_m = pax_find_mirror_vma(vma);
71290 + if (!vma_m)
71291 + return;
71292 +
71293 + BUG_ON(!PageLocked(page_m));
71294 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71295 + address_m = address + SEGMEXEC_TASK_SIZE;
71296 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71297 + pte_m = pte_offset_map(pmd_m, address_m);
71298 + ptl_m = pte_lockptr(mm, pmd_m);
71299 + if (ptl != ptl_m) {
71300 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71301 + if (!pte_none(*pte_m))
71302 + goto out;
71303 + }
71304 +
71305 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71306 + page_cache_get(page_m);
71307 + page_add_anon_rmap(page_m, vma_m, address_m);
71308 + inc_mm_counter_fast(mm, MM_ANONPAGES);
71309 + set_pte_at(mm, address_m, pte_m, entry_m);
71310 + update_mmu_cache(vma_m, address_m, entry_m);
71311 +out:
71312 + if (ptl != ptl_m)
71313 + spin_unlock(ptl_m);
71314 + pte_unmap(pte_m);
71315 + unlock_page(page_m);
71316 +}
71317 +
71318 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71319 +{
71320 + struct mm_struct *mm = vma->vm_mm;
71321 + unsigned long address_m;
71322 + spinlock_t *ptl_m;
71323 + struct vm_area_struct *vma_m;
71324 + pmd_t *pmd_m;
71325 + pte_t *pte_m, entry_m;
71326 +
71327 + BUG_ON(!page_m || PageAnon(page_m));
71328 +
71329 + vma_m = pax_find_mirror_vma(vma);
71330 + if (!vma_m)
71331 + return;
71332 +
71333 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71334 + address_m = address + SEGMEXEC_TASK_SIZE;
71335 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71336 + pte_m = pte_offset_map(pmd_m, address_m);
71337 + ptl_m = pte_lockptr(mm, pmd_m);
71338 + if (ptl != ptl_m) {
71339 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71340 + if (!pte_none(*pte_m))
71341 + goto out;
71342 + }
71343 +
71344 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71345 + page_cache_get(page_m);
71346 + page_add_file_rmap(page_m);
71347 + inc_mm_counter_fast(mm, MM_FILEPAGES);
71348 + set_pte_at(mm, address_m, pte_m, entry_m);
71349 + update_mmu_cache(vma_m, address_m, entry_m);
71350 +out:
71351 + if (ptl != ptl_m)
71352 + spin_unlock(ptl_m);
71353 + pte_unmap(pte_m);
71354 +}
71355 +
71356 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
71357 +{
71358 + struct mm_struct *mm = vma->vm_mm;
71359 + unsigned long address_m;
71360 + spinlock_t *ptl_m;
71361 + struct vm_area_struct *vma_m;
71362 + pmd_t *pmd_m;
71363 + pte_t *pte_m, entry_m;
71364 +
71365 + vma_m = pax_find_mirror_vma(vma);
71366 + if (!vma_m)
71367 + return;
71368 +
71369 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71370 + address_m = address + SEGMEXEC_TASK_SIZE;
71371 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71372 + pte_m = pte_offset_map(pmd_m, address_m);
71373 + ptl_m = pte_lockptr(mm, pmd_m);
71374 + if (ptl != ptl_m) {
71375 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71376 + if (!pte_none(*pte_m))
71377 + goto out;
71378 + }
71379 +
71380 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
71381 + set_pte_at(mm, address_m, pte_m, entry_m);
71382 +out:
71383 + if (ptl != ptl_m)
71384 + spin_unlock(ptl_m);
71385 + pte_unmap(pte_m);
71386 +}
71387 +
71388 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
71389 +{
71390 + struct page *page_m;
71391 + pte_t entry;
71392 +
71393 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
71394 + goto out;
71395 +
71396 + entry = *pte;
71397 + page_m = vm_normal_page(vma, address, entry);
71398 + if (!page_m)
71399 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
71400 + else if (PageAnon(page_m)) {
71401 + if (pax_find_mirror_vma(vma)) {
71402 + pte_unmap_unlock(pte, ptl);
71403 + lock_page(page_m);
71404 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
71405 + if (pte_same(entry, *pte))
71406 + pax_mirror_anon_pte(vma, address, page_m, ptl);
71407 + else
71408 + unlock_page(page_m);
71409 + }
71410 + } else
71411 + pax_mirror_file_pte(vma, address, page_m, ptl);
71412 +
71413 +out:
71414 + pte_unmap_unlock(pte, ptl);
71415 +}
71416 +#endif
71417 +
71418 /*
71419 * This routine handles present pages, when users try to write
71420 * to a shared page. It is done by copying the page to a new address
71421 @@ -2692,6 +2889,12 @@ gotten:
71422 */
71423 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71424 if (likely(pte_same(*page_table, orig_pte))) {
71425 +
71426 +#ifdef CONFIG_PAX_SEGMEXEC
71427 + if (pax_find_mirror_vma(vma))
71428 + BUG_ON(!trylock_page(new_page));
71429 +#endif
71430 +
71431 if (old_page) {
71432 if (!PageAnon(old_page)) {
71433 dec_mm_counter_fast(mm, MM_FILEPAGES);
71434 @@ -2743,6 +2946,10 @@ gotten:
71435 page_remove_rmap(old_page);
71436 }
71437
71438 +#ifdef CONFIG_PAX_SEGMEXEC
71439 + pax_mirror_anon_pte(vma, address, new_page, ptl);
71440 +#endif
71441 +
71442 /* Free the old page.. */
71443 new_page = old_page;
71444 ret |= VM_FAULT_WRITE;
71445 @@ -3022,6 +3229,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71446 swap_free(entry);
71447 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
71448 try_to_free_swap(page);
71449 +
71450 +#ifdef CONFIG_PAX_SEGMEXEC
71451 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
71452 +#endif
71453 +
71454 unlock_page(page);
71455 if (swapcache) {
71456 /*
71457 @@ -3045,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71458
71459 /* No need to invalidate - it was non-present before */
71460 update_mmu_cache(vma, address, page_table);
71461 +
71462 +#ifdef CONFIG_PAX_SEGMEXEC
71463 + pax_mirror_anon_pte(vma, address, page, ptl);
71464 +#endif
71465 +
71466 unlock:
71467 pte_unmap_unlock(page_table, ptl);
71468 out:
71469 @@ -3064,40 +3281,6 @@ out_release:
71470 }
71471
71472 /*
71473 - * This is like a special single-page "expand_{down|up}wards()",
71474 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
71475 - * doesn't hit another vma.
71476 - */
71477 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
71478 -{
71479 - address &= PAGE_MASK;
71480 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
71481 - struct vm_area_struct *prev = vma->vm_prev;
71482 -
71483 - /*
71484 - * Is there a mapping abutting this one below?
71485 - *
71486 - * That's only ok if it's the same stack mapping
71487 - * that has gotten split..
71488 - */
71489 - if (prev && prev->vm_end == address)
71490 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
71491 -
71492 - expand_downwards(vma, address - PAGE_SIZE);
71493 - }
71494 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
71495 - struct vm_area_struct *next = vma->vm_next;
71496 -
71497 - /* As VM_GROWSDOWN but s/below/above/ */
71498 - if (next && next->vm_start == address + PAGE_SIZE)
71499 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
71500 -
71501 - expand_upwards(vma, address + PAGE_SIZE);
71502 - }
71503 - return 0;
71504 -}
71505 -
71506 -/*
71507 * We enter with non-exclusive mmap_sem (to exclude vma changes,
71508 * but allow concurrent faults), and pte mapped but not yet locked.
71509 * We return with mmap_sem still held, but pte unmapped and unlocked.
71510 @@ -3106,27 +3289,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71511 unsigned long address, pte_t *page_table, pmd_t *pmd,
71512 unsigned int flags)
71513 {
71514 - struct page *page;
71515 + struct page *page = NULL;
71516 spinlock_t *ptl;
71517 pte_t entry;
71518
71519 - pte_unmap(page_table);
71520 -
71521 - /* Check if we need to add a guard page to the stack */
71522 - if (check_stack_guard_page(vma, address) < 0)
71523 - return VM_FAULT_SIGBUS;
71524 -
71525 - /* Use the zero-page for reads */
71526 if (!(flags & FAULT_FLAG_WRITE)) {
71527 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71528 vma->vm_page_prot));
71529 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71530 + ptl = pte_lockptr(mm, pmd);
71531 + spin_lock(ptl);
71532 if (!pte_none(*page_table))
71533 goto unlock;
71534 goto setpte;
71535 }
71536
71537 /* Allocate our own private page. */
71538 + pte_unmap(page_table);
71539 +
71540 if (unlikely(anon_vma_prepare(vma)))
71541 goto oom;
71542 page = alloc_zeroed_user_highpage_movable(vma, address);
71543 @@ -3145,6 +3324,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71544 if (!pte_none(*page_table))
71545 goto release;
71546
71547 +#ifdef CONFIG_PAX_SEGMEXEC
71548 + if (pax_find_mirror_vma(vma))
71549 + BUG_ON(!trylock_page(page));
71550 +#endif
71551 +
71552 inc_mm_counter_fast(mm, MM_ANONPAGES);
71553 page_add_new_anon_rmap(page, vma, address);
71554 setpte:
71555 @@ -3152,6 +3336,12 @@ setpte:
71556
71557 /* No need to invalidate - it was non-present before */
71558 update_mmu_cache(vma, address, page_table);
71559 +
71560 +#ifdef CONFIG_PAX_SEGMEXEC
71561 + if (page)
71562 + pax_mirror_anon_pte(vma, address, page, ptl);
71563 +#endif
71564 +
71565 unlock:
71566 pte_unmap_unlock(page_table, ptl);
71567 return 0;
71568 @@ -3295,6 +3485,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71569 */
71570 /* Only go through if we didn't race with anybody else... */
71571 if (likely(pte_same(*page_table, orig_pte))) {
71572 +
71573 +#ifdef CONFIG_PAX_SEGMEXEC
71574 + if (anon && pax_find_mirror_vma(vma))
71575 + BUG_ON(!trylock_page(page));
71576 +#endif
71577 +
71578 flush_icache_page(vma, page);
71579 entry = mk_pte(page, vma->vm_page_prot);
71580 if (flags & FAULT_FLAG_WRITE)
71581 @@ -3314,6 +3510,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71582
71583 /* no need to invalidate: a not-present page won't be cached */
71584 update_mmu_cache(vma, address, page_table);
71585 +
71586 +#ifdef CONFIG_PAX_SEGMEXEC
71587 + if (anon)
71588 + pax_mirror_anon_pte(vma, address, page, ptl);
71589 + else
71590 + pax_mirror_file_pte(vma, address, page, ptl);
71591 +#endif
71592 +
71593 } else {
71594 if (cow_page)
71595 mem_cgroup_uncharge_page(cow_page);
71596 @@ -3467,6 +3671,12 @@ int handle_pte_fault(struct mm_struct *mm,
71597 if (flags & FAULT_FLAG_WRITE)
71598 flush_tlb_fix_spurious_fault(vma, address);
71599 }
71600 +
71601 +#ifdef CONFIG_PAX_SEGMEXEC
71602 + pax_mirror_pte(vma, address, pte, pmd, ptl);
71603 + return 0;
71604 +#endif
71605 +
71606 unlock:
71607 pte_unmap_unlock(pte, ptl);
71608 return 0;
71609 @@ -3483,6 +3693,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71610 pmd_t *pmd;
71611 pte_t *pte;
71612
71613 +#ifdef CONFIG_PAX_SEGMEXEC
71614 + struct vm_area_struct *vma_m;
71615 +#endif
71616 +
71617 __set_current_state(TASK_RUNNING);
71618
71619 count_vm_event(PGFAULT);
71620 @@ -3494,6 +3708,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71621 if (unlikely(is_vm_hugetlb_page(vma)))
71622 return hugetlb_fault(mm, vma, address, flags);
71623
71624 +#ifdef CONFIG_PAX_SEGMEXEC
71625 + vma_m = pax_find_mirror_vma(vma);
71626 + if (vma_m) {
71627 + unsigned long address_m;
71628 + pgd_t *pgd_m;
71629 + pud_t *pud_m;
71630 + pmd_t *pmd_m;
71631 +
71632 + if (vma->vm_start > vma_m->vm_start) {
71633 + address_m = address;
71634 + address -= SEGMEXEC_TASK_SIZE;
71635 + vma = vma_m;
71636 + } else
71637 + address_m = address + SEGMEXEC_TASK_SIZE;
71638 +
71639 + pgd_m = pgd_offset(mm, address_m);
71640 + pud_m = pud_alloc(mm, pgd_m, address_m);
71641 + if (!pud_m)
71642 + return VM_FAULT_OOM;
71643 + pmd_m = pmd_alloc(mm, pud_m, address_m);
71644 + if (!pmd_m)
71645 + return VM_FAULT_OOM;
71646 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71647 + return VM_FAULT_OOM;
71648 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71649 + }
71650 +#endif
71651 +
71652 retry:
71653 pgd = pgd_offset(mm, address);
71654 pud = pud_alloc(mm, pgd, address);
71655 @@ -3535,7 +3777,7 @@ retry:
71656 * run pte_offset_map on the pmd, if an huge pmd could
71657 * materialize from under us from a different thread.
71658 */
71659 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71660 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71661 return VM_FAULT_OOM;
71662 /* if an huge pmd materialized from under us just retry later */
71663 if (unlikely(pmd_trans_huge(*pmd)))
71664 @@ -3572,6 +3814,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71665 spin_unlock(&mm->page_table_lock);
71666 return 0;
71667 }
71668 +
71669 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71670 +{
71671 + pud_t *new = pud_alloc_one(mm, address);
71672 + if (!new)
71673 + return -ENOMEM;
71674 +
71675 + smp_wmb(); /* See comment in __pte_alloc */
71676 +
71677 + spin_lock(&mm->page_table_lock);
71678 + if (pgd_present(*pgd)) /* Another has populated it */
71679 + pud_free(mm, new);
71680 + else
71681 + pgd_populate_kernel(mm, pgd, new);
71682 + spin_unlock(&mm->page_table_lock);
71683 + return 0;
71684 +}
71685 #endif /* __PAGETABLE_PUD_FOLDED */
71686
71687 #ifndef __PAGETABLE_PMD_FOLDED
71688 @@ -3602,6 +3861,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
71689 spin_unlock(&mm->page_table_lock);
71690 return 0;
71691 }
71692 +
71693 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
71694 +{
71695 + pmd_t *new = pmd_alloc_one(mm, address);
71696 + if (!new)
71697 + return -ENOMEM;
71698 +
71699 + smp_wmb(); /* See comment in __pte_alloc */
71700 +
71701 + spin_lock(&mm->page_table_lock);
71702 +#ifndef __ARCH_HAS_4LEVEL_HACK
71703 + if (pud_present(*pud)) /* Another has populated it */
71704 + pmd_free(mm, new);
71705 + else
71706 + pud_populate_kernel(mm, pud, new);
71707 +#else
71708 + if (pgd_present(*pud)) /* Another has populated it */
71709 + pmd_free(mm, new);
71710 + else
71711 + pgd_populate_kernel(mm, pud, new);
71712 +#endif /* __ARCH_HAS_4LEVEL_HACK */
71713 + spin_unlock(&mm->page_table_lock);
71714 + return 0;
71715 +}
71716 #endif /* __PAGETABLE_PMD_FOLDED */
71717
71718 int make_pages_present(unsigned long addr, unsigned long end)
71719 @@ -3639,7 +3922,7 @@ static int __init gate_vma_init(void)
71720 gate_vma.vm_start = FIXADDR_USER_START;
71721 gate_vma.vm_end = FIXADDR_USER_END;
71722 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71723 - gate_vma.vm_page_prot = __P101;
71724 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71725
71726 return 0;
71727 }
71728 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71729 index 1d771e4..f9a6808 100644
71730 --- a/mm/mempolicy.c
71731 +++ b/mm/mempolicy.c
71732 @@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71733 unsigned long vmstart;
71734 unsigned long vmend;
71735
71736 +#ifdef CONFIG_PAX_SEGMEXEC
71737 + struct vm_area_struct *vma_m;
71738 +#endif
71739 +
71740 vma = find_vma(mm, start);
71741 if (!vma || vma->vm_start > start)
71742 return -EFAULT;
71743 @@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71744 if (err)
71745 goto out;
71746 }
71747 +
71748 +#ifdef CONFIG_PAX_SEGMEXEC
71749 + vma_m = pax_find_mirror_vma(vma);
71750 + if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
71751 + err = vma_m->vm_ops->set_policy(vma_m, new_pol);
71752 + if (err)
71753 + goto out;
71754 + }
71755 +#endif
71756 +
71757 }
71758
71759 out:
71760 @@ -1125,6 +1139,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71761
71762 if (end < start)
71763 return -EINVAL;
71764 +
71765 +#ifdef CONFIG_PAX_SEGMEXEC
71766 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71767 + if (end > SEGMEXEC_TASK_SIZE)
71768 + return -EINVAL;
71769 + } else
71770 +#endif
71771 +
71772 + if (end > TASK_SIZE)
71773 + return -EINVAL;
71774 +
71775 if (end == start)
71776 return 0;
71777
71778 @@ -1348,8 +1373,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71779 */
71780 tcred = __task_cred(task);
71781 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
71782 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
71783 - !capable(CAP_SYS_NICE)) {
71784 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
71785 rcu_read_unlock();
71786 err = -EPERM;
71787 goto out_put;
71788 @@ -1380,6 +1404,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71789 goto out;
71790 }
71791
71792 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71793 + if (mm != current->mm &&
71794 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71795 + mmput(mm);
71796 + err = -EPERM;
71797 + goto out;
71798 + }
71799 +#endif
71800 +
71801 err = do_migrate_pages(mm, old, new,
71802 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
71803
71804 diff --git a/mm/mlock.c b/mm/mlock.c
71805 index ef726e8..cd7f1ec 100644
71806 --- a/mm/mlock.c
71807 +++ b/mm/mlock.c
71808 @@ -13,6 +13,7 @@
71809 #include <linux/pagemap.h>
71810 #include <linux/mempolicy.h>
71811 #include <linux/syscalls.h>
71812 +#include <linux/security.h>
71813 #include <linux/sched.h>
71814 #include <linux/export.h>
71815 #include <linux/rmap.h>
71816 @@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
71817 {
71818 unsigned long nstart, end, tmp;
71819 struct vm_area_struct * vma, * prev;
71820 - int error;
71821 + int error = 0;
71822
71823 VM_BUG_ON(start & ~PAGE_MASK);
71824 VM_BUG_ON(len != PAGE_ALIGN(len));
71825 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
71826 return -EINVAL;
71827 if (end == start)
71828 return 0;
71829 + if (end > TASK_SIZE)
71830 + return -EINVAL;
71831 +
71832 vma = find_vma(current->mm, start);
71833 if (!vma || vma->vm_start > start)
71834 return -ENOMEM;
71835 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
71836 for (nstart = start ; ; ) {
71837 vm_flags_t newflags;
71838
71839 +#ifdef CONFIG_PAX_SEGMEXEC
71840 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71841 + break;
71842 +#endif
71843 +
71844 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
71845
71846 newflags = vma->vm_flags | VM_LOCKED;
71847 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
71848 lock_limit >>= PAGE_SHIFT;
71849
71850 /* check against resource limits */
71851 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
71852 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
71853 error = do_mlock(start, len, 1);
71854 up_write(&current->mm->mmap_sem);
71855 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
71856 static int do_mlockall(int flags)
71857 {
71858 struct vm_area_struct * vma, * prev = NULL;
71859 - unsigned int def_flags = 0;
71860
71861 if (flags & MCL_FUTURE)
71862 - def_flags = VM_LOCKED;
71863 - current->mm->def_flags = def_flags;
71864 + current->mm->def_flags |= VM_LOCKED;
71865 + else
71866 + current->mm->def_flags &= ~VM_LOCKED;
71867 if (flags == MCL_FUTURE)
71868 goto out;
71869
71870 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
71871 vm_flags_t newflags;
71872
71873 +#ifdef CONFIG_PAX_SEGMEXEC
71874 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71875 + break;
71876 +#endif
71877 +
71878 + BUG_ON(vma->vm_end > TASK_SIZE);
71879 newflags = vma->vm_flags | VM_LOCKED;
71880 if (!(flags & MCL_CURRENT))
71881 newflags &= ~VM_LOCKED;
71882 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
71883 lock_limit >>= PAGE_SHIFT;
71884
71885 ret = -ENOMEM;
71886 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
71887 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
71888 capable(CAP_IPC_LOCK))
71889 ret = do_mlockall(flags);
71890 diff --git a/mm/mmap.c b/mm/mmap.c
71891 index 3edfcdf..4a27ae9 100644
71892 --- a/mm/mmap.c
71893 +++ b/mm/mmap.c
71894 @@ -47,6 +47,16 @@
71895 #define arch_rebalance_pgtables(addr, len) (addr)
71896 #endif
71897
71898 +static inline void verify_mm_writelocked(struct mm_struct *mm)
71899 +{
71900 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
71901 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71902 + up_read(&mm->mmap_sem);
71903 + BUG();
71904 + }
71905 +#endif
71906 +}
71907 +
71908 static void unmap_region(struct mm_struct *mm,
71909 struct vm_area_struct *vma, struct vm_area_struct *prev,
71910 unsigned long start, unsigned long end);
71911 @@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
71912 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
71913 *
71914 */
71915 -pgprot_t protection_map[16] = {
71916 +pgprot_t protection_map[16] __read_only = {
71917 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
71918 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
71919 };
71920
71921 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
71922 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
71923 {
71924 - return __pgprot(pgprot_val(protection_map[vm_flags &
71925 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
71926 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
71927 pgprot_val(arch_vm_get_page_prot(vm_flags)));
71928 +
71929 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71930 + if (!(__supported_pte_mask & _PAGE_NX) &&
71931 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
71932 + (vm_flags & (VM_READ | VM_WRITE)))
71933 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
71934 +#endif
71935 +
71936 + return prot;
71937 }
71938 EXPORT_SYMBOL(vm_get_page_prot);
71939
71940 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
71941 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
71942 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
71943 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
71944 /*
71945 * Make sure vm_committed_as in one cacheline and not cacheline shared with
71946 * other variables. It can be updated by several CPUs frequently.
71947 @@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
71948 struct vm_area_struct *next = vma->vm_next;
71949
71950 might_sleep();
71951 + BUG_ON(vma->vm_mirror);
71952 if (vma->vm_ops && vma->vm_ops->close)
71953 vma->vm_ops->close(vma);
71954 if (vma->vm_file) {
71955 @@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
71956 * not page aligned -Ram Gupta
71957 */
71958 rlim = rlimit(RLIMIT_DATA);
71959 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
71960 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
71961 (mm->end_data - mm->start_data) > rlim)
71962 goto out;
71963 @@ -708,6 +730,12 @@ static int
71964 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
71965 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71966 {
71967 +
71968 +#ifdef CONFIG_PAX_SEGMEXEC
71969 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
71970 + return 0;
71971 +#endif
71972 +
71973 if (is_mergeable_vma(vma, file, vm_flags) &&
71974 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71975 if (vma->vm_pgoff == vm_pgoff)
71976 @@ -727,6 +755,12 @@ static int
71977 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71978 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71979 {
71980 +
71981 +#ifdef CONFIG_PAX_SEGMEXEC
71982 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
71983 + return 0;
71984 +#endif
71985 +
71986 if (is_mergeable_vma(vma, file, vm_flags) &&
71987 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71988 pgoff_t vm_pglen;
71989 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71990 struct vm_area_struct *vma_merge(struct mm_struct *mm,
71991 struct vm_area_struct *prev, unsigned long addr,
71992 unsigned long end, unsigned long vm_flags,
71993 - struct anon_vma *anon_vma, struct file *file,
71994 + struct anon_vma *anon_vma, struct file *file,
71995 pgoff_t pgoff, struct mempolicy *policy)
71996 {
71997 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
71998 struct vm_area_struct *area, *next;
71999 int err;
72000
72001 +#ifdef CONFIG_PAX_SEGMEXEC
72002 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72003 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72004 +
72005 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72006 +#endif
72007 +
72008 /*
72009 * We later require that vma->vm_flags == vm_flags,
72010 * so this tests vma->vm_flags & VM_SPECIAL, too.
72011 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72012 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72013 next = next->vm_next;
72014
72015 +#ifdef CONFIG_PAX_SEGMEXEC
72016 + if (prev)
72017 + prev_m = pax_find_mirror_vma(prev);
72018 + if (area)
72019 + area_m = pax_find_mirror_vma(area);
72020 + if (next)
72021 + next_m = pax_find_mirror_vma(next);
72022 +#endif
72023 +
72024 /*
72025 * Can it merge with the predecessor?
72026 */
72027 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72028 /* cases 1, 6 */
72029 err = vma_adjust(prev, prev->vm_start,
72030 next->vm_end, prev->vm_pgoff, NULL);
72031 - } else /* cases 2, 5, 7 */
72032 +
72033 +#ifdef CONFIG_PAX_SEGMEXEC
72034 + if (!err && prev_m)
72035 + err = vma_adjust(prev_m, prev_m->vm_start,
72036 + next_m->vm_end, prev_m->vm_pgoff, NULL);
72037 +#endif
72038 +
72039 + } else { /* cases 2, 5, 7 */
72040 err = vma_adjust(prev, prev->vm_start,
72041 end, prev->vm_pgoff, NULL);
72042 +
72043 +#ifdef CONFIG_PAX_SEGMEXEC
72044 + if (!err && prev_m)
72045 + err = vma_adjust(prev_m, prev_m->vm_start,
72046 + end_m, prev_m->vm_pgoff, NULL);
72047 +#endif
72048 +
72049 + }
72050 if (err)
72051 return NULL;
72052 khugepaged_enter_vma_merge(prev);
72053 @@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72054 mpol_equal(policy, vma_policy(next)) &&
72055 can_vma_merge_before(next, vm_flags,
72056 anon_vma, file, pgoff+pglen)) {
72057 - if (prev && addr < prev->vm_end) /* case 4 */
72058 + if (prev && addr < prev->vm_end) { /* case 4 */
72059 err = vma_adjust(prev, prev->vm_start,
72060 addr, prev->vm_pgoff, NULL);
72061 - else /* cases 3, 8 */
72062 +
72063 +#ifdef CONFIG_PAX_SEGMEXEC
72064 + if (!err && prev_m)
72065 + err = vma_adjust(prev_m, prev_m->vm_start,
72066 + addr_m, prev_m->vm_pgoff, NULL);
72067 +#endif
72068 +
72069 + } else { /* cases 3, 8 */
72070 err = vma_adjust(area, addr, next->vm_end,
72071 next->vm_pgoff - pglen, NULL);
72072 +
72073 +#ifdef CONFIG_PAX_SEGMEXEC
72074 + if (!err && area_m)
72075 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
72076 + next_m->vm_pgoff - pglen, NULL);
72077 +#endif
72078 +
72079 + }
72080 if (err)
72081 return NULL;
72082 khugepaged_enter_vma_merge(area);
72083 @@ -940,14 +1020,11 @@ none:
72084 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72085 struct file *file, long pages)
72086 {
72087 - const unsigned long stack_flags
72088 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72089 -
72090 if (file) {
72091 mm->shared_vm += pages;
72092 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72093 mm->exec_vm += pages;
72094 - } else if (flags & stack_flags)
72095 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72096 mm->stack_vm += pages;
72097 if (flags & (VM_RESERVED|VM_IO))
72098 mm->reserved_vm += pages;
72099 @@ -985,7 +1062,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72100 * (the exception is when the underlying filesystem is noexec
72101 * mounted, in which case we dont add PROT_EXEC.)
72102 */
72103 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72104 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72105 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72106 prot |= PROT_EXEC;
72107
72108 @@ -1011,7 +1088,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72109 /* Obtain the address to map to. we verify (or select) it and ensure
72110 * that it represents a valid section of the address space.
72111 */
72112 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
72113 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72114 if (addr & ~PAGE_MASK)
72115 return addr;
72116
72117 @@ -1022,6 +1099,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72118 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72119 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72120
72121 +#ifdef CONFIG_PAX_MPROTECT
72122 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72123 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72124 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72125 + gr_log_rwxmmap(file);
72126 +
72127 +#ifdef CONFIG_PAX_EMUPLT
72128 + vm_flags &= ~VM_EXEC;
72129 +#else
72130 + return -EPERM;
72131 +#endif
72132 +
72133 + }
72134 +
72135 + if (!(vm_flags & VM_EXEC))
72136 + vm_flags &= ~VM_MAYEXEC;
72137 +#else
72138 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72139 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72140 +#endif
72141 + else
72142 + vm_flags &= ~VM_MAYWRITE;
72143 + }
72144 +#endif
72145 +
72146 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72147 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72148 + vm_flags &= ~VM_PAGEEXEC;
72149 +#endif
72150 +
72151 if (flags & MAP_LOCKED)
72152 if (!can_do_mlock())
72153 return -EPERM;
72154 @@ -1033,6 +1140,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72155 locked += mm->locked_vm;
72156 lock_limit = rlimit(RLIMIT_MEMLOCK);
72157 lock_limit >>= PAGE_SHIFT;
72158 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72159 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72160 return -EAGAIN;
72161 }
72162 @@ -1099,6 +1207,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72163 }
72164 }
72165
72166 + if (!gr_acl_handle_mmap(file, prot))
72167 + return -EACCES;
72168 +
72169 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72170 }
72171
72172 @@ -1175,7 +1286,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72173 vm_flags_t vm_flags = vma->vm_flags;
72174
72175 /* If it was private or non-writable, the write bit is already clear */
72176 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72177 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72178 return 0;
72179
72180 /* The backer wishes to know when pages are first written to? */
72181 @@ -1224,14 +1335,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72182 unsigned long charged = 0;
72183 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72184
72185 +#ifdef CONFIG_PAX_SEGMEXEC
72186 + struct vm_area_struct *vma_m = NULL;
72187 +#endif
72188 +
72189 + /*
72190 + * mm->mmap_sem is required to protect against another thread
72191 + * changing the mappings in case we sleep.
72192 + */
72193 + verify_mm_writelocked(mm);
72194 +
72195 /* Clear old maps */
72196 error = -ENOMEM;
72197 -munmap_back:
72198 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72199 if (vma && vma->vm_start < addr + len) {
72200 if (do_munmap(mm, addr, len))
72201 return -ENOMEM;
72202 - goto munmap_back;
72203 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72204 + BUG_ON(vma && vma->vm_start < addr + len);
72205 }
72206
72207 /* Check against address space limit. */
72208 @@ -1280,6 +1401,16 @@ munmap_back:
72209 goto unacct_error;
72210 }
72211
72212 +#ifdef CONFIG_PAX_SEGMEXEC
72213 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72214 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72215 + if (!vma_m) {
72216 + error = -ENOMEM;
72217 + goto free_vma;
72218 + }
72219 + }
72220 +#endif
72221 +
72222 vma->vm_mm = mm;
72223 vma->vm_start = addr;
72224 vma->vm_end = addr + len;
72225 @@ -1304,6 +1435,19 @@ munmap_back:
72226 error = file->f_op->mmap(file, vma);
72227 if (error)
72228 goto unmap_and_free_vma;
72229 +
72230 +#ifdef CONFIG_PAX_SEGMEXEC
72231 + if (vma_m && (vm_flags & VM_EXECUTABLE))
72232 + added_exe_file_vma(mm);
72233 +#endif
72234 +
72235 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72236 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72237 + vma->vm_flags |= VM_PAGEEXEC;
72238 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72239 + }
72240 +#endif
72241 +
72242 if (vm_flags & VM_EXECUTABLE)
72243 added_exe_file_vma(mm);
72244
72245 @@ -1341,6 +1485,11 @@ munmap_back:
72246 vma_link(mm, vma, prev, rb_link, rb_parent);
72247 file = vma->vm_file;
72248
72249 +#ifdef CONFIG_PAX_SEGMEXEC
72250 + if (vma_m)
72251 + BUG_ON(pax_mirror_vma(vma_m, vma));
72252 +#endif
72253 +
72254 /* Once vma denies write, undo our temporary denial count */
72255 if (correct_wcount)
72256 atomic_inc(&inode->i_writecount);
72257 @@ -1349,6 +1498,7 @@ out:
72258
72259 mm->total_vm += len >> PAGE_SHIFT;
72260 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72261 + track_exec_limit(mm, addr, addr + len, vm_flags);
72262 if (vm_flags & VM_LOCKED) {
72263 if (!mlock_vma_pages_range(vma, addr, addr + len))
72264 mm->locked_vm += (len >> PAGE_SHIFT);
72265 @@ -1371,6 +1521,12 @@ unmap_and_free_vma:
72266 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72267 charged = 0;
72268 free_vma:
72269 +
72270 +#ifdef CONFIG_PAX_SEGMEXEC
72271 + if (vma_m)
72272 + kmem_cache_free(vm_area_cachep, vma_m);
72273 +#endif
72274 +
72275 kmem_cache_free(vm_area_cachep, vma);
72276 unacct_error:
72277 if (charged)
72278 @@ -1378,6 +1534,44 @@ unacct_error:
72279 return error;
72280 }
72281
72282 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72283 +{
72284 + if (!vma) {
72285 +#ifdef CONFIG_STACK_GROWSUP
72286 + if (addr > sysctl_heap_stack_gap)
72287 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72288 + else
72289 + vma = find_vma(current->mm, 0);
72290 + if (vma && (vma->vm_flags & VM_GROWSUP))
72291 + return false;
72292 +#endif
72293 + return true;
72294 + }
72295 +
72296 + if (addr + len > vma->vm_start)
72297 + return false;
72298 +
72299 + if (vma->vm_flags & VM_GROWSDOWN)
72300 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72301 +#ifdef CONFIG_STACK_GROWSUP
72302 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
72303 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
72304 +#endif
72305 +
72306 + return true;
72307 +}
72308 +
72309 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
72310 +{
72311 + if (vma->vm_start < len)
72312 + return -ENOMEM;
72313 + if (!(vma->vm_flags & VM_GROWSDOWN))
72314 + return vma->vm_start - len;
72315 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
72316 + return vma->vm_start - len - sysctl_heap_stack_gap;
72317 + return -ENOMEM;
72318 +}
72319 +
72320 /* Get an address range which is currently unmapped.
72321 * For shmat() with addr=0.
72322 *
72323 @@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
72324 if (flags & MAP_FIXED)
72325 return addr;
72326
72327 +#ifdef CONFIG_PAX_RANDMMAP
72328 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72329 +#endif
72330 +
72331 if (addr) {
72332 addr = PAGE_ALIGN(addr);
72333 - vma = find_vma(mm, addr);
72334 - if (TASK_SIZE - len >= addr &&
72335 - (!vma || addr + len <= vma->vm_start))
72336 - return addr;
72337 + if (TASK_SIZE - len >= addr) {
72338 + vma = find_vma(mm, addr);
72339 + if (check_heap_stack_gap(vma, addr, len))
72340 + return addr;
72341 + }
72342 }
72343 if (len > mm->cached_hole_size) {
72344 - start_addr = addr = mm->free_area_cache;
72345 + start_addr = addr = mm->free_area_cache;
72346 } else {
72347 - start_addr = addr = TASK_UNMAPPED_BASE;
72348 - mm->cached_hole_size = 0;
72349 + start_addr = addr = mm->mmap_base;
72350 + mm->cached_hole_size = 0;
72351 }
72352
72353 full_search:
72354 @@ -1426,34 +1625,40 @@ full_search:
72355 * Start a new search - just in case we missed
72356 * some holes.
72357 */
72358 - if (start_addr != TASK_UNMAPPED_BASE) {
72359 - addr = TASK_UNMAPPED_BASE;
72360 - start_addr = addr;
72361 + if (start_addr != mm->mmap_base) {
72362 + start_addr = addr = mm->mmap_base;
72363 mm->cached_hole_size = 0;
72364 goto full_search;
72365 }
72366 return -ENOMEM;
72367 }
72368 - if (!vma || addr + len <= vma->vm_start) {
72369 - /*
72370 - * Remember the place where we stopped the search:
72371 - */
72372 - mm->free_area_cache = addr + len;
72373 - return addr;
72374 - }
72375 + if (check_heap_stack_gap(vma, addr, len))
72376 + break;
72377 if (addr + mm->cached_hole_size < vma->vm_start)
72378 mm->cached_hole_size = vma->vm_start - addr;
72379 addr = vma->vm_end;
72380 }
72381 +
72382 + /*
72383 + * Remember the place where we stopped the search:
72384 + */
72385 + mm->free_area_cache = addr + len;
72386 + return addr;
72387 }
72388 #endif
72389
72390 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
72391 {
72392 +
72393 +#ifdef CONFIG_PAX_SEGMEXEC
72394 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72395 + return;
72396 +#endif
72397 +
72398 /*
72399 * Is this a new hole at the lowest possible address?
72400 */
72401 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
72402 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
72403 mm->free_area_cache = addr;
72404 }
72405
72406 @@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72407 {
72408 struct vm_area_struct *vma;
72409 struct mm_struct *mm = current->mm;
72410 - unsigned long addr = addr0, start_addr;
72411 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
72412
72413 /* requested length too big for entire address space */
72414 if (len > TASK_SIZE)
72415 @@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72416 if (flags & MAP_FIXED)
72417 return addr;
72418
72419 +#ifdef CONFIG_PAX_RANDMMAP
72420 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72421 +#endif
72422 +
72423 /* requesting a specific address */
72424 if (addr) {
72425 addr = PAGE_ALIGN(addr);
72426 - vma = find_vma(mm, addr);
72427 - if (TASK_SIZE - len >= addr &&
72428 - (!vma || addr + len <= vma->vm_start))
72429 - return addr;
72430 + if (TASK_SIZE - len >= addr) {
72431 + vma = find_vma(mm, addr);
72432 + if (check_heap_stack_gap(vma, addr, len))
72433 + return addr;
72434 + }
72435 }
72436
72437 /* check if free_area_cache is useful for us */
72438 @@ -1508,7 +1718,7 @@ try_again:
72439 * return with success:
72440 */
72441 vma = find_vma(mm, addr);
72442 - if (!vma || addr+len <= vma->vm_start)
72443 + if (check_heap_stack_gap(vma, addr, len))
72444 /* remember the address as a hint for next time */
72445 return (mm->free_area_cache = addr);
72446
72447 @@ -1517,8 +1727,8 @@ try_again:
72448 mm->cached_hole_size = vma->vm_start - addr;
72449
72450 /* try just below the current vma->vm_start */
72451 - addr = vma->vm_start-len;
72452 - } while (len < vma->vm_start);
72453 + addr = skip_heap_stack_gap(vma, len);
72454 + } while (!IS_ERR_VALUE(addr));
72455
72456 fail:
72457 /*
72458 @@ -1541,13 +1751,21 @@ fail:
72459 * can happen with large stack limits and large mmap()
72460 * allocations.
72461 */
72462 + mm->mmap_base = TASK_UNMAPPED_BASE;
72463 +
72464 +#ifdef CONFIG_PAX_RANDMMAP
72465 + if (mm->pax_flags & MF_PAX_RANDMMAP)
72466 + mm->mmap_base += mm->delta_mmap;
72467 +#endif
72468 +
72469 + mm->free_area_cache = mm->mmap_base;
72470 mm->cached_hole_size = ~0UL;
72471 - mm->free_area_cache = TASK_UNMAPPED_BASE;
72472 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
72473 /*
72474 * Restore the topdown base:
72475 */
72476 - mm->free_area_cache = mm->mmap_base;
72477 + mm->mmap_base = base;
72478 + mm->free_area_cache = base;
72479 mm->cached_hole_size = ~0UL;
72480
72481 return addr;
72482 @@ -1556,6 +1774,12 @@ fail:
72483
72484 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72485 {
72486 +
72487 +#ifdef CONFIG_PAX_SEGMEXEC
72488 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72489 + return;
72490 +#endif
72491 +
72492 /*
72493 * Is this a new hole at the highest possible address?
72494 */
72495 @@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72496 mm->free_area_cache = addr;
72497
72498 /* dont allow allocations above current base */
72499 - if (mm->free_area_cache > mm->mmap_base)
72500 + if (mm->free_area_cache > mm->mmap_base) {
72501 mm->free_area_cache = mm->mmap_base;
72502 + mm->cached_hole_size = ~0UL;
72503 + }
72504 }
72505
72506 unsigned long
72507 @@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
72508 return vma;
72509 }
72510
72511 +#ifdef CONFIG_PAX_SEGMEXEC
72512 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
72513 +{
72514 + struct vm_area_struct *vma_m;
72515 +
72516 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
72517 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
72518 + BUG_ON(vma->vm_mirror);
72519 + return NULL;
72520 + }
72521 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
72522 + vma_m = vma->vm_mirror;
72523 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
72524 + BUG_ON(vma->vm_file != vma_m->vm_file);
72525 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
72526 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
72527 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
72528 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
72529 + return vma_m;
72530 +}
72531 +#endif
72532 +
72533 /*
72534 * Verify that the stack growth is acceptable and
72535 * update accounting. This is shared with both the
72536 @@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72537 return -ENOMEM;
72538
72539 /* Stack limit test */
72540 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
72541 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72542 return -ENOMEM;
72543
72544 @@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72545 locked = mm->locked_vm + grow;
72546 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72547 limit >>= PAGE_SHIFT;
72548 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72549 if (locked > limit && !capable(CAP_IPC_LOCK))
72550 return -ENOMEM;
72551 }
72552 @@ -1719,37 +1969,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72553 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72554 * vma is the last one with address > vma->vm_end. Have to extend vma.
72555 */
72556 +#ifndef CONFIG_IA64
72557 +static
72558 +#endif
72559 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72560 {
72561 int error;
72562 + bool locknext;
72563
72564 if (!(vma->vm_flags & VM_GROWSUP))
72565 return -EFAULT;
72566
72567 + /* Also guard against wrapping around to address 0. */
72568 + if (address < PAGE_ALIGN(address+1))
72569 + address = PAGE_ALIGN(address+1);
72570 + else
72571 + return -ENOMEM;
72572 +
72573 /*
72574 * We must make sure the anon_vma is allocated
72575 * so that the anon_vma locking is not a noop.
72576 */
72577 if (unlikely(anon_vma_prepare(vma)))
72578 return -ENOMEM;
72579 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72580 + if (locknext && anon_vma_prepare(vma->vm_next))
72581 + return -ENOMEM;
72582 vma_lock_anon_vma(vma);
72583 + if (locknext)
72584 + vma_lock_anon_vma(vma->vm_next);
72585
72586 /*
72587 * vma->vm_start/vm_end cannot change under us because the caller
72588 * is required to hold the mmap_sem in read mode. We need the
72589 - * anon_vma lock to serialize against concurrent expand_stacks.
72590 - * Also guard against wrapping around to address 0.
72591 + * anon_vma locks to serialize against concurrent expand_stacks
72592 + * and expand_upwards.
72593 */
72594 - if (address < PAGE_ALIGN(address+4))
72595 - address = PAGE_ALIGN(address+4);
72596 - else {
72597 - vma_unlock_anon_vma(vma);
72598 - return -ENOMEM;
72599 - }
72600 error = 0;
72601
72602 /* Somebody else might have raced and expanded it already */
72603 - if (address > vma->vm_end) {
72604 + 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)
72605 + error = -ENOMEM;
72606 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72607 unsigned long size, grow;
72608
72609 size = address - vma->vm_start;
72610 @@ -1764,6 +2025,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72611 }
72612 }
72613 }
72614 + if (locknext)
72615 + vma_unlock_anon_vma(vma->vm_next);
72616 vma_unlock_anon_vma(vma);
72617 khugepaged_enter_vma_merge(vma);
72618 return error;
72619 @@ -1777,6 +2040,8 @@ int expand_downwards(struct vm_area_struct *vma,
72620 unsigned long address)
72621 {
72622 int error;
72623 + bool lockprev = false;
72624 + struct vm_area_struct *prev;
72625
72626 /*
72627 * We must make sure the anon_vma is allocated
72628 @@ -1790,6 +2055,15 @@ int expand_downwards(struct vm_area_struct *vma,
72629 if (error)
72630 return error;
72631
72632 + prev = vma->vm_prev;
72633 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72634 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72635 +#endif
72636 + if (lockprev && anon_vma_prepare(prev))
72637 + return -ENOMEM;
72638 + if (lockprev)
72639 + vma_lock_anon_vma(prev);
72640 +
72641 vma_lock_anon_vma(vma);
72642
72643 /*
72644 @@ -1799,9 +2073,17 @@ int expand_downwards(struct vm_area_struct *vma,
72645 */
72646
72647 /* Somebody else might have raced and expanded it already */
72648 - if (address < vma->vm_start) {
72649 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72650 + error = -ENOMEM;
72651 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72652 unsigned long size, grow;
72653
72654 +#ifdef CONFIG_PAX_SEGMEXEC
72655 + struct vm_area_struct *vma_m;
72656 +
72657 + vma_m = pax_find_mirror_vma(vma);
72658 +#endif
72659 +
72660 size = vma->vm_end - address;
72661 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72662
72663 @@ -1811,11 +2093,22 @@ int expand_downwards(struct vm_area_struct *vma,
72664 if (!error) {
72665 vma->vm_start = address;
72666 vma->vm_pgoff -= grow;
72667 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72668 +
72669 +#ifdef CONFIG_PAX_SEGMEXEC
72670 + if (vma_m) {
72671 + vma_m->vm_start -= grow << PAGE_SHIFT;
72672 + vma_m->vm_pgoff -= grow;
72673 + }
72674 +#endif
72675 +
72676 perf_event_mmap(vma);
72677 }
72678 }
72679 }
72680 vma_unlock_anon_vma(vma);
72681 + if (lockprev)
72682 + vma_unlock_anon_vma(prev);
72683 khugepaged_enter_vma_merge(vma);
72684 return error;
72685 }
72686 @@ -1887,6 +2180,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72687 do {
72688 long nrpages = vma_pages(vma);
72689
72690 +#ifdef CONFIG_PAX_SEGMEXEC
72691 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72692 + vma = remove_vma(vma);
72693 + continue;
72694 + }
72695 +#endif
72696 +
72697 if (vma->vm_flags & VM_ACCOUNT)
72698 nr_accounted += nrpages;
72699 mm->total_vm -= nrpages;
72700 @@ -1933,6 +2233,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72701 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72702 vma->vm_prev = NULL;
72703 do {
72704 +
72705 +#ifdef CONFIG_PAX_SEGMEXEC
72706 + if (vma->vm_mirror) {
72707 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72708 + vma->vm_mirror->vm_mirror = NULL;
72709 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
72710 + vma->vm_mirror = NULL;
72711 + }
72712 +#endif
72713 +
72714 rb_erase(&vma->vm_rb, &mm->mm_rb);
72715 mm->map_count--;
72716 tail_vma = vma;
72717 @@ -1961,14 +2271,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72718 struct vm_area_struct *new;
72719 int err = -ENOMEM;
72720
72721 +#ifdef CONFIG_PAX_SEGMEXEC
72722 + struct vm_area_struct *vma_m, *new_m = NULL;
72723 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72724 +#endif
72725 +
72726 if (is_vm_hugetlb_page(vma) && (addr &
72727 ~(huge_page_mask(hstate_vma(vma)))))
72728 return -EINVAL;
72729
72730 +#ifdef CONFIG_PAX_SEGMEXEC
72731 + vma_m = pax_find_mirror_vma(vma);
72732 +#endif
72733 +
72734 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72735 if (!new)
72736 goto out_err;
72737
72738 +#ifdef CONFIG_PAX_SEGMEXEC
72739 + if (vma_m) {
72740 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72741 + if (!new_m) {
72742 + kmem_cache_free(vm_area_cachep, new);
72743 + goto out_err;
72744 + }
72745 + }
72746 +#endif
72747 +
72748 /* most fields are the same, copy all, and then fixup */
72749 *new = *vma;
72750
72751 @@ -1981,6 +2310,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72752 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72753 }
72754
72755 +#ifdef CONFIG_PAX_SEGMEXEC
72756 + if (vma_m) {
72757 + *new_m = *vma_m;
72758 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
72759 + new_m->vm_mirror = new;
72760 + new->vm_mirror = new_m;
72761 +
72762 + if (new_below)
72763 + new_m->vm_end = addr_m;
72764 + else {
72765 + new_m->vm_start = addr_m;
72766 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72767 + }
72768 + }
72769 +#endif
72770 +
72771 pol = mpol_dup(vma_policy(vma));
72772 if (IS_ERR(pol)) {
72773 err = PTR_ERR(pol);
72774 @@ -2006,6 +2351,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72775 else
72776 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72777
72778 +#ifdef CONFIG_PAX_SEGMEXEC
72779 + if (!err && vma_m) {
72780 + if (anon_vma_clone(new_m, vma_m))
72781 + goto out_free_mpol;
72782 +
72783 + mpol_get(pol);
72784 + vma_set_policy(new_m, pol);
72785 +
72786 + if (new_m->vm_file) {
72787 + get_file(new_m->vm_file);
72788 + if (vma_m->vm_flags & VM_EXECUTABLE)
72789 + added_exe_file_vma(mm);
72790 + }
72791 +
72792 + if (new_m->vm_ops && new_m->vm_ops->open)
72793 + new_m->vm_ops->open(new_m);
72794 +
72795 + if (new_below)
72796 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72797 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72798 + else
72799 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72800 +
72801 + if (err) {
72802 + if (new_m->vm_ops && new_m->vm_ops->close)
72803 + new_m->vm_ops->close(new_m);
72804 + if (new_m->vm_file) {
72805 + if (vma_m->vm_flags & VM_EXECUTABLE)
72806 + removed_exe_file_vma(mm);
72807 + fput(new_m->vm_file);
72808 + }
72809 + mpol_put(pol);
72810 + }
72811 + }
72812 +#endif
72813 +
72814 /* Success. */
72815 if (!err)
72816 return 0;
72817 @@ -2018,10 +2399,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72818 removed_exe_file_vma(mm);
72819 fput(new->vm_file);
72820 }
72821 - unlink_anon_vmas(new);
72822 out_free_mpol:
72823 mpol_put(pol);
72824 out_free_vma:
72825 +
72826 +#ifdef CONFIG_PAX_SEGMEXEC
72827 + if (new_m) {
72828 + unlink_anon_vmas(new_m);
72829 + kmem_cache_free(vm_area_cachep, new_m);
72830 + }
72831 +#endif
72832 +
72833 + unlink_anon_vmas(new);
72834 kmem_cache_free(vm_area_cachep, new);
72835 out_err:
72836 return err;
72837 @@ -2034,6 +2423,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72838 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72839 unsigned long addr, int new_below)
72840 {
72841 +
72842 +#ifdef CONFIG_PAX_SEGMEXEC
72843 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72844 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
72845 + if (mm->map_count >= sysctl_max_map_count-1)
72846 + return -ENOMEM;
72847 + } else
72848 +#endif
72849 +
72850 if (mm->map_count >= sysctl_max_map_count)
72851 return -ENOMEM;
72852
72853 @@ -2045,11 +2443,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72854 * work. This now handles partial unmappings.
72855 * Jeremy Fitzhardinge <jeremy@goop.org>
72856 */
72857 +#ifdef CONFIG_PAX_SEGMEXEC
72858 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72859 {
72860 + int ret = __do_munmap(mm, start, len);
72861 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
72862 + return ret;
72863 +
72864 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
72865 +}
72866 +
72867 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72868 +#else
72869 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72870 +#endif
72871 +{
72872 unsigned long end;
72873 struct vm_area_struct *vma, *prev, *last;
72874
72875 + /*
72876 + * mm->mmap_sem is required to protect against another thread
72877 + * changing the mappings in case we sleep.
72878 + */
72879 + verify_mm_writelocked(mm);
72880 +
72881 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
72882 return -EINVAL;
72883
72884 @@ -2124,6 +2541,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72885 /* Fix up all other VM information */
72886 remove_vma_list(mm, vma);
72887
72888 + track_exec_limit(mm, start, end, 0UL);
72889 +
72890 return 0;
72891 }
72892
72893 @@ -2132,6 +2551,13 @@ int vm_munmap(unsigned long start, size_t len)
72894 int ret;
72895 struct mm_struct *mm = current->mm;
72896
72897 +
72898 +#ifdef CONFIG_PAX_SEGMEXEC
72899 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
72900 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
72901 + return -EINVAL;
72902 +#endif
72903 +
72904 down_write(&mm->mmap_sem);
72905 ret = do_munmap(mm, start, len);
72906 up_write(&mm->mmap_sem);
72907 @@ -2145,16 +2571,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
72908 return vm_munmap(addr, len);
72909 }
72910
72911 -static inline void verify_mm_writelocked(struct mm_struct *mm)
72912 -{
72913 -#ifdef CONFIG_DEBUG_VM
72914 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72915 - WARN_ON(1);
72916 - up_read(&mm->mmap_sem);
72917 - }
72918 -#endif
72919 -}
72920 -
72921 /*
72922 * this is really a simplified "do_mmap". it only handles
72923 * anonymous maps. eventually we may be able to do some
72924 @@ -2168,6 +2584,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72925 struct rb_node ** rb_link, * rb_parent;
72926 pgoff_t pgoff = addr >> PAGE_SHIFT;
72927 int error;
72928 + unsigned long charged;
72929
72930 len = PAGE_ALIGN(len);
72931 if (!len)
72932 @@ -2175,16 +2592,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72933
72934 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
72935
72936 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
72937 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
72938 + flags &= ~VM_EXEC;
72939 +
72940 +#ifdef CONFIG_PAX_MPROTECT
72941 + if (mm->pax_flags & MF_PAX_MPROTECT)
72942 + flags &= ~VM_MAYEXEC;
72943 +#endif
72944 +
72945 + }
72946 +#endif
72947 +
72948 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
72949 if (error & ~PAGE_MASK)
72950 return error;
72951
72952 + charged = len >> PAGE_SHIFT;
72953 +
72954 /*
72955 * mlock MCL_FUTURE?
72956 */
72957 if (mm->def_flags & VM_LOCKED) {
72958 unsigned long locked, lock_limit;
72959 - locked = len >> PAGE_SHIFT;
72960 + locked = charged;
72961 locked += mm->locked_vm;
72962 lock_limit = rlimit(RLIMIT_MEMLOCK);
72963 lock_limit >>= PAGE_SHIFT;
72964 @@ -2201,22 +2632,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72965 /*
72966 * Clear old maps. this also does some error checking for us
72967 */
72968 - munmap_back:
72969 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72970 if (vma && vma->vm_start < addr + len) {
72971 if (do_munmap(mm, addr, len))
72972 return -ENOMEM;
72973 - goto munmap_back;
72974 - }
72975 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72976 + BUG_ON(vma && vma->vm_start < addr + len);
72977 + }
72978
72979 /* Check against address space limits *after* clearing old maps... */
72980 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
72981 + if (!may_expand_vm(mm, charged))
72982 return -ENOMEM;
72983
72984 if (mm->map_count > sysctl_max_map_count)
72985 return -ENOMEM;
72986
72987 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
72988 + if (security_vm_enough_memory_mm(mm, charged))
72989 return -ENOMEM;
72990
72991 /* Can we just expand an old private anonymous mapping? */
72992 @@ -2230,7 +2661,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72993 */
72994 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72995 if (!vma) {
72996 - vm_unacct_memory(len >> PAGE_SHIFT);
72997 + vm_unacct_memory(charged);
72998 return -ENOMEM;
72999 }
73000
73001 @@ -2244,11 +2675,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73002 vma_link(mm, vma, prev, rb_link, rb_parent);
73003 out:
73004 perf_event_mmap(vma);
73005 - mm->total_vm += len >> PAGE_SHIFT;
73006 + mm->total_vm += charged;
73007 if (flags & VM_LOCKED) {
73008 if (!mlock_vma_pages_range(vma, addr, addr + len))
73009 - mm->locked_vm += (len >> PAGE_SHIFT);
73010 + mm->locked_vm += charged;
73011 }
73012 + track_exec_limit(mm, addr, addr + len, flags);
73013 return addr;
73014 }
73015
73016 @@ -2306,6 +2738,7 @@ void exit_mmap(struct mm_struct *mm)
73017 while (vma) {
73018 if (vma->vm_flags & VM_ACCOUNT)
73019 nr_accounted += vma_pages(vma);
73020 + vma->vm_mirror = NULL;
73021 vma = remove_vma(vma);
73022 }
73023 vm_unacct_memory(nr_accounted);
73024 @@ -2322,6 +2755,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73025 struct vm_area_struct * __vma, * prev;
73026 struct rb_node ** rb_link, * rb_parent;
73027
73028 +#ifdef CONFIG_PAX_SEGMEXEC
73029 + struct vm_area_struct *vma_m = NULL;
73030 +#endif
73031 +
73032 + if (security_mmap_addr(vma->vm_start))
73033 + return -EPERM;
73034 +
73035 /*
73036 * The vm_pgoff of a purely anonymous vma should be irrelevant
73037 * until its first write fault, when page's anon_vma and index
73038 @@ -2348,7 +2788,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73039 if (vma->vm_file && uprobe_mmap(vma))
73040 return -EINVAL;
73041
73042 +#ifdef CONFIG_PAX_SEGMEXEC
73043 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73044 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73045 + if (!vma_m)
73046 + return -ENOMEM;
73047 + }
73048 +#endif
73049 +
73050 vma_link(mm, vma, prev, rb_link, rb_parent);
73051 +
73052 +#ifdef CONFIG_PAX_SEGMEXEC
73053 + if (vma_m)
73054 + BUG_ON(pax_mirror_vma(vma_m, vma));
73055 +#endif
73056 +
73057 return 0;
73058 }
73059
73060 @@ -2367,6 +2821,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73061 struct mempolicy *pol;
73062 bool faulted_in_anon_vma = true;
73063
73064 + BUG_ON(vma->vm_mirror);
73065 +
73066 /*
73067 * If anonymous vma has not yet been faulted, update new pgoff
73068 * to match new location, to increase its chance of merging.
73069 @@ -2438,6 +2894,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73070 return NULL;
73071 }
73072
73073 +#ifdef CONFIG_PAX_SEGMEXEC
73074 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73075 +{
73076 + struct vm_area_struct *prev_m;
73077 + struct rb_node **rb_link_m, *rb_parent_m;
73078 + struct mempolicy *pol_m;
73079 +
73080 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73081 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73082 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73083 + *vma_m = *vma;
73084 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73085 + if (anon_vma_clone(vma_m, vma))
73086 + return -ENOMEM;
73087 + pol_m = vma_policy(vma_m);
73088 + mpol_get(pol_m);
73089 + vma_set_policy(vma_m, pol_m);
73090 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73091 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73092 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73093 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73094 + if (vma_m->vm_file)
73095 + get_file(vma_m->vm_file);
73096 + if (vma_m->vm_ops && vma_m->vm_ops->open)
73097 + vma_m->vm_ops->open(vma_m);
73098 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73099 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73100 + vma_m->vm_mirror = vma;
73101 + vma->vm_mirror = vma_m;
73102 + return 0;
73103 +}
73104 +#endif
73105 +
73106 /*
73107 * Return true if the calling process may expand its vm space by the passed
73108 * number of pages
73109 @@ -2449,6 +2938,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73110
73111 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73112
73113 +#ifdef CONFIG_PAX_RANDMMAP
73114 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73115 + cur -= mm->brk_gap;
73116 +#endif
73117 +
73118 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73119 if (cur + npages > lim)
73120 return 0;
73121 return 1;
73122 @@ -2519,6 +3014,22 @@ int install_special_mapping(struct mm_struct *mm,
73123 vma->vm_start = addr;
73124 vma->vm_end = addr + len;
73125
73126 +#ifdef CONFIG_PAX_MPROTECT
73127 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73128 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73129 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73130 + return -EPERM;
73131 + if (!(vm_flags & VM_EXEC))
73132 + vm_flags &= ~VM_MAYEXEC;
73133 +#else
73134 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73135 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73136 +#endif
73137 + else
73138 + vm_flags &= ~VM_MAYWRITE;
73139 + }
73140 +#endif
73141 +
73142 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73143 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73144
73145 diff --git a/mm/mprotect.c b/mm/mprotect.c
73146 index a409926..8b32e6d 100644
73147 --- a/mm/mprotect.c
73148 +++ b/mm/mprotect.c
73149 @@ -23,10 +23,17 @@
73150 #include <linux/mmu_notifier.h>
73151 #include <linux/migrate.h>
73152 #include <linux/perf_event.h>
73153 +
73154 +#ifdef CONFIG_PAX_MPROTECT
73155 +#include <linux/elf.h>
73156 +#include <linux/binfmts.h>
73157 +#endif
73158 +
73159 #include <asm/uaccess.h>
73160 #include <asm/pgtable.h>
73161 #include <asm/cacheflush.h>
73162 #include <asm/tlbflush.h>
73163 +#include <asm/mmu_context.h>
73164
73165 #ifndef pgprot_modify
73166 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73167 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
73168 flush_tlb_range(vma, start, end);
73169 }
73170
73171 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73172 +/* called while holding the mmap semaphor for writing except stack expansion */
73173 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73174 +{
73175 + unsigned long oldlimit, newlimit = 0UL;
73176 +
73177 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73178 + return;
73179 +
73180 + spin_lock(&mm->page_table_lock);
73181 + oldlimit = mm->context.user_cs_limit;
73182 + if ((prot & VM_EXEC) && oldlimit < end)
73183 + /* USER_CS limit moved up */
73184 + newlimit = end;
73185 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73186 + /* USER_CS limit moved down */
73187 + newlimit = start;
73188 +
73189 + if (newlimit) {
73190 + mm->context.user_cs_limit = newlimit;
73191 +
73192 +#ifdef CONFIG_SMP
73193 + wmb();
73194 + cpus_clear(mm->context.cpu_user_cs_mask);
73195 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73196 +#endif
73197 +
73198 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73199 + }
73200 + spin_unlock(&mm->page_table_lock);
73201 + if (newlimit == end) {
73202 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
73203 +
73204 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
73205 + if (is_vm_hugetlb_page(vma))
73206 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73207 + else
73208 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73209 + }
73210 +}
73211 +#endif
73212 +
73213 int
73214 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73215 unsigned long start, unsigned long end, unsigned long newflags)
73216 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73217 int error;
73218 int dirty_accountable = 0;
73219
73220 +#ifdef CONFIG_PAX_SEGMEXEC
73221 + struct vm_area_struct *vma_m = NULL;
73222 + unsigned long start_m, end_m;
73223 +
73224 + start_m = start + SEGMEXEC_TASK_SIZE;
73225 + end_m = end + SEGMEXEC_TASK_SIZE;
73226 +#endif
73227 +
73228 if (newflags == oldflags) {
73229 *pprev = vma;
73230 return 0;
73231 }
73232
73233 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73234 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73235 +
73236 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73237 + return -ENOMEM;
73238 +
73239 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73240 + return -ENOMEM;
73241 + }
73242 +
73243 /*
73244 * If we make a private mapping writable we increase our commit;
73245 * but (without finer accounting) cannot reduce our commit if we
73246 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73247 }
73248 }
73249
73250 +#ifdef CONFIG_PAX_SEGMEXEC
73251 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73252 + if (start != vma->vm_start) {
73253 + error = split_vma(mm, vma, start, 1);
73254 + if (error)
73255 + goto fail;
73256 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73257 + *pprev = (*pprev)->vm_next;
73258 + }
73259 +
73260 + if (end != vma->vm_end) {
73261 + error = split_vma(mm, vma, end, 0);
73262 + if (error)
73263 + goto fail;
73264 + }
73265 +
73266 + if (pax_find_mirror_vma(vma)) {
73267 + error = __do_munmap(mm, start_m, end_m - start_m);
73268 + if (error)
73269 + goto fail;
73270 + } else {
73271 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73272 + if (!vma_m) {
73273 + error = -ENOMEM;
73274 + goto fail;
73275 + }
73276 + vma->vm_flags = newflags;
73277 + error = pax_mirror_vma(vma_m, vma);
73278 + if (error) {
73279 + vma->vm_flags = oldflags;
73280 + goto fail;
73281 + }
73282 + }
73283 + }
73284 +#endif
73285 +
73286 /*
73287 * First try to merge with previous and/or next vma.
73288 */
73289 @@ -204,9 +307,21 @@ success:
73290 * vm_flags and vm_page_prot are protected by the mmap_sem
73291 * held in write mode.
73292 */
73293 +
73294 +#ifdef CONFIG_PAX_SEGMEXEC
73295 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73296 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73297 +#endif
73298 +
73299 vma->vm_flags = newflags;
73300 +
73301 +#ifdef CONFIG_PAX_MPROTECT
73302 + if (mm->binfmt && mm->binfmt->handle_mprotect)
73303 + mm->binfmt->handle_mprotect(vma, newflags);
73304 +#endif
73305 +
73306 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
73307 - vm_get_page_prot(newflags));
73308 + vm_get_page_prot(vma->vm_flags));
73309
73310 if (vma_wants_writenotify(vma)) {
73311 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
73312 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73313 end = start + len;
73314 if (end <= start)
73315 return -ENOMEM;
73316 +
73317 +#ifdef CONFIG_PAX_SEGMEXEC
73318 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73319 + if (end > SEGMEXEC_TASK_SIZE)
73320 + return -EINVAL;
73321 + } else
73322 +#endif
73323 +
73324 + if (end > TASK_SIZE)
73325 + return -EINVAL;
73326 +
73327 if (!arch_validate_prot(prot))
73328 return -EINVAL;
73329
73330 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73331 /*
73332 * Does the application expect PROT_READ to imply PROT_EXEC:
73333 */
73334 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73335 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73336 prot |= PROT_EXEC;
73337
73338 vm_flags = calc_vm_prot_bits(prot);
73339 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73340 if (start > vma->vm_start)
73341 prev = vma;
73342
73343 +#ifdef CONFIG_PAX_MPROTECT
73344 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
73345 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
73346 +#endif
73347 +
73348 for (nstart = start ; ; ) {
73349 unsigned long newflags;
73350
73351 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73352
73353 /* newflags >> 4 shift VM_MAY% in place of VM_% */
73354 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
73355 + if (prot & (PROT_WRITE | PROT_EXEC))
73356 + gr_log_rwxmprotect(vma->vm_file);
73357 +
73358 + error = -EACCES;
73359 + goto out;
73360 + }
73361 +
73362 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
73363 error = -EACCES;
73364 goto out;
73365 }
73366 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73367 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
73368 if (error)
73369 goto out;
73370 +
73371 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
73372 +
73373 nstart = tmp;
73374
73375 if (nstart < prev->vm_end)
73376 diff --git a/mm/mremap.c b/mm/mremap.c
73377 index 21fed20..6822658 100644
73378 --- a/mm/mremap.c
73379 +++ b/mm/mremap.c
73380 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
73381 continue;
73382 pte = ptep_get_and_clear(mm, old_addr, old_pte);
73383 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
73384 +
73385 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73386 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
73387 + pte = pte_exprotect(pte);
73388 +#endif
73389 +
73390 set_pte_at(mm, new_addr, new_pte, pte);
73391 }
73392
73393 @@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
73394 if (is_vm_hugetlb_page(vma))
73395 goto Einval;
73396
73397 +#ifdef CONFIG_PAX_SEGMEXEC
73398 + if (pax_find_mirror_vma(vma))
73399 + goto Einval;
73400 +#endif
73401 +
73402 /* We can't remap across vm area boundaries */
73403 if (old_len > vma->vm_end - addr)
73404 goto Efault;
73405 @@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
73406 unsigned long ret = -EINVAL;
73407 unsigned long charged = 0;
73408 unsigned long map_flags;
73409 + unsigned long pax_task_size = TASK_SIZE;
73410
73411 if (new_addr & ~PAGE_MASK)
73412 goto out;
73413
73414 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
73415 +#ifdef CONFIG_PAX_SEGMEXEC
73416 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73417 + pax_task_size = SEGMEXEC_TASK_SIZE;
73418 +#endif
73419 +
73420 + pax_task_size -= PAGE_SIZE;
73421 +
73422 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
73423 goto out;
73424
73425 /* Check if the location we're moving into overlaps the
73426 * old location at all, and fail if it does.
73427 */
73428 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
73429 - goto out;
73430 -
73431 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
73432 + if (addr + old_len > new_addr && new_addr + new_len > addr)
73433 goto out;
73434
73435 ret = do_munmap(mm, new_addr, new_len);
73436 @@ -436,6 +452,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73437 struct vm_area_struct *vma;
73438 unsigned long ret = -EINVAL;
73439 unsigned long charged = 0;
73440 + unsigned long pax_task_size = TASK_SIZE;
73441
73442 down_write(&current->mm->mmap_sem);
73443
73444 @@ -456,6 +473,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73445 if (!new_len)
73446 goto out;
73447
73448 +#ifdef CONFIG_PAX_SEGMEXEC
73449 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73450 + pax_task_size = SEGMEXEC_TASK_SIZE;
73451 +#endif
73452 +
73453 + pax_task_size -= PAGE_SIZE;
73454 +
73455 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
73456 + old_len > pax_task_size || addr > pax_task_size-old_len)
73457 + goto out;
73458 +
73459 if (flags & MREMAP_FIXED) {
73460 if (flags & MREMAP_MAYMOVE)
73461 ret = mremap_to(addr, old_len, new_addr, new_len);
73462 @@ -505,6 +533,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73463 addr + new_len);
73464 }
73465 ret = addr;
73466 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
73467 goto out;
73468 }
73469 }
73470 @@ -528,7 +557,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73471 goto out;
73472 }
73473
73474 + map_flags = vma->vm_flags;
73475 ret = move_vma(vma, addr, old_len, new_len, new_addr);
73476 + if (!(ret & ~PAGE_MASK)) {
73477 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
73478 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
73479 + }
73480 }
73481 out:
73482 if (ret & ~PAGE_MASK)
73483 diff --git a/mm/nommu.c b/mm/nommu.c
73484 index d4b0c10..ed421b5 100644
73485 --- a/mm/nommu.c
73486 +++ b/mm/nommu.c
73487 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
73488 int sysctl_overcommit_ratio = 50; /* default is 50% */
73489 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
73490 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
73491 -int heap_stack_gap = 0;
73492
73493 atomic_long_t mmap_pages_allocated;
73494
73495 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
73496 EXPORT_SYMBOL(find_vma);
73497
73498 /*
73499 - * find a VMA
73500 - * - we don't extend stack VMAs under NOMMU conditions
73501 - */
73502 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
73503 -{
73504 - return find_vma(mm, addr);
73505 -}
73506 -
73507 -/*
73508 * expand a stack to a given address
73509 * - not supported under NOMMU conditions
73510 */
73511 @@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73512
73513 /* most fields are the same, copy all, and then fixup */
73514 *new = *vma;
73515 + INIT_LIST_HEAD(&new->anon_vma_chain);
73516 *region = *vma->vm_region;
73517 new->vm_region = region;
73518
73519 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
73520 index 4a4f921..eaa5e3a 100644
73521 --- a/mm/page_alloc.c
73522 +++ b/mm/page_alloc.c
73523 @@ -336,7 +336,7 @@ out:
73524 * This usage means that zero-order pages may not be compound.
73525 */
73526
73527 -static void free_compound_page(struct page *page)
73528 +void free_compound_page(struct page *page)
73529 {
73530 __free_pages_ok(page, compound_order(page));
73531 }
73532 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73533 int i;
73534 int bad = 0;
73535
73536 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73537 + unsigned long index = 1UL << order;
73538 +#endif
73539 +
73540 trace_mm_page_free(page, order);
73541 kmemcheck_free_shadow(page, order);
73542
73543 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73544 debug_check_no_obj_freed(page_address(page),
73545 PAGE_SIZE << order);
73546 }
73547 +
73548 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73549 + for (; index; --index)
73550 + sanitize_highpage(page + index - 1);
73551 +#endif
73552 +
73553 arch_free_page(page, order);
73554 kernel_map_pages(page, 1 << order, 0);
73555
73556 @@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73557 arch_alloc_page(page, order);
73558 kernel_map_pages(page, 1 << order, 1);
73559
73560 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
73561 if (gfp_flags & __GFP_ZERO)
73562 prep_zero_page(page, order, gfp_flags);
73563 +#endif
73564
73565 if (order && (gfp_flags & __GFP_COMP))
73566 prep_compound_page(page, order);
73567 @@ -3579,7 +3591,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73568 unsigned long pfn;
73569
73570 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73571 +#ifdef CONFIG_X86_32
73572 + /* boot failures in VMware 8 on 32bit vanilla since
73573 + this change */
73574 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73575 +#else
73576 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73577 +#endif
73578 return 1;
73579 }
73580 return 0;
73581 diff --git a/mm/percpu.c b/mm/percpu.c
73582 index bb4be74..a43ea85 100644
73583 --- a/mm/percpu.c
73584 +++ b/mm/percpu.c
73585 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73586 static unsigned int pcpu_high_unit_cpu __read_mostly;
73587
73588 /* the address of the first chunk which starts with the kernel static area */
73589 -void *pcpu_base_addr __read_mostly;
73590 +void *pcpu_base_addr __read_only;
73591 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73592
73593 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73594 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73595 index 926b466..b23df53 100644
73596 --- a/mm/process_vm_access.c
73597 +++ b/mm/process_vm_access.c
73598 @@ -13,6 +13,7 @@
73599 #include <linux/uio.h>
73600 #include <linux/sched.h>
73601 #include <linux/highmem.h>
73602 +#include <linux/security.h>
73603 #include <linux/ptrace.h>
73604 #include <linux/slab.h>
73605 #include <linux/syscalls.h>
73606 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73607 size_t iov_l_curr_offset = 0;
73608 ssize_t iov_len;
73609
73610 + return -ENOSYS; // PaX: until properly audited
73611 +
73612 /*
73613 * Work out how many pages of struct pages we're going to need
73614 * when eventually calling get_user_pages
73615 */
73616 for (i = 0; i < riovcnt; i++) {
73617 iov_len = rvec[i].iov_len;
73618 - if (iov_len > 0) {
73619 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
73620 - + iov_len)
73621 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73622 - / PAGE_SIZE + 1;
73623 - nr_pages = max(nr_pages, nr_pages_iov);
73624 - }
73625 + if (iov_len <= 0)
73626 + continue;
73627 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73628 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73629 + nr_pages = max(nr_pages, nr_pages_iov);
73630 }
73631
73632 if (nr_pages == 0)
73633 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73634 goto free_proc_pages;
73635 }
73636
73637 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73638 + rc = -EPERM;
73639 + goto put_task_struct;
73640 + }
73641 +
73642 mm = mm_access(task, PTRACE_MODE_ATTACH);
73643 if (!mm || IS_ERR(mm)) {
73644 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73645 diff --git a/mm/rmap.c b/mm/rmap.c
73646 index 0f3b7cd..c5652b6 100644
73647 --- a/mm/rmap.c
73648 +++ b/mm/rmap.c
73649 @@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73650 struct anon_vma *anon_vma = vma->anon_vma;
73651 struct anon_vma_chain *avc;
73652
73653 +#ifdef CONFIG_PAX_SEGMEXEC
73654 + struct anon_vma_chain *avc_m = NULL;
73655 +#endif
73656 +
73657 might_sleep();
73658 if (unlikely(!anon_vma)) {
73659 struct mm_struct *mm = vma->vm_mm;
73660 @@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73661 if (!avc)
73662 goto out_enomem;
73663
73664 +#ifdef CONFIG_PAX_SEGMEXEC
73665 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73666 + if (!avc_m)
73667 + goto out_enomem_free_avc;
73668 +#endif
73669 +
73670 anon_vma = find_mergeable_anon_vma(vma);
73671 allocated = NULL;
73672 if (!anon_vma) {
73673 @@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73674 /* page_table_lock to protect against threads */
73675 spin_lock(&mm->page_table_lock);
73676 if (likely(!vma->anon_vma)) {
73677 +
73678 +#ifdef CONFIG_PAX_SEGMEXEC
73679 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73680 +
73681 + if (vma_m) {
73682 + BUG_ON(vma_m->anon_vma);
73683 + vma_m->anon_vma = anon_vma;
73684 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
73685 + avc_m = NULL;
73686 + }
73687 +#endif
73688 +
73689 vma->anon_vma = anon_vma;
73690 anon_vma_chain_link(vma, avc, anon_vma);
73691 allocated = NULL;
73692 @@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73693
73694 if (unlikely(allocated))
73695 put_anon_vma(allocated);
73696 +
73697 +#ifdef CONFIG_PAX_SEGMEXEC
73698 + if (unlikely(avc_m))
73699 + anon_vma_chain_free(avc_m);
73700 +#endif
73701 +
73702 if (unlikely(avc))
73703 anon_vma_chain_free(avc);
73704 }
73705 return 0;
73706
73707 out_enomem_free_avc:
73708 +
73709 +#ifdef CONFIG_PAX_SEGMEXEC
73710 + if (avc_m)
73711 + anon_vma_chain_free(avc_m);
73712 +#endif
73713 +
73714 anon_vma_chain_free(avc);
73715 out_enomem:
73716 return -ENOMEM;
73717 @@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
73718 * Attach the anon_vmas from src to dst.
73719 * Returns 0 on success, -ENOMEM on failure.
73720 */
73721 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73722 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73723 {
73724 struct anon_vma_chain *avc, *pavc;
73725 struct anon_vma *root = NULL;
73726 @@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
73727 * the corresponding VMA in the parent process is attached to.
73728 * Returns 0 on success, non-zero on failure.
73729 */
73730 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73731 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73732 {
73733 struct anon_vma_chain *avc;
73734 struct anon_vma *anon_vma;
73735 diff --git a/mm/shmem.c b/mm/shmem.c
73736 index bd10636..5c16d49 100644
73737 --- a/mm/shmem.c
73738 +++ b/mm/shmem.c
73739 @@ -31,7 +31,7 @@
73740 #include <linux/export.h>
73741 #include <linux/swap.h>
73742
73743 -static struct vfsmount *shm_mnt;
73744 +struct vfsmount *shm_mnt;
73745
73746 #ifdef CONFIG_SHMEM
73747 /*
73748 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
73749 #define BOGO_DIRENT_SIZE 20
73750
73751 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73752 -#define SHORT_SYMLINK_LEN 128
73753 +#define SHORT_SYMLINK_LEN 64
73754
73755 struct shmem_xattr {
73756 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73757 @@ -2590,8 +2590,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73758 int err = -ENOMEM;
73759
73760 /* Round up to L1_CACHE_BYTES to resist false sharing */
73761 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73762 - L1_CACHE_BYTES), GFP_KERNEL);
73763 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73764 if (!sbinfo)
73765 return -ENOMEM;
73766
73767 diff --git a/mm/slab.c b/mm/slab.c
73768 index e901a36..ca479fc 100644
73769 --- a/mm/slab.c
73770 +++ b/mm/slab.c
73771 @@ -153,7 +153,7 @@
73772
73773 /* Legal flag mask for kmem_cache_create(). */
73774 #if DEBUG
73775 -# define CREATE_MASK (SLAB_RED_ZONE | \
73776 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73777 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73778 SLAB_CACHE_DMA | \
73779 SLAB_STORE_USER | \
73780 @@ -161,7 +161,7 @@
73781 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73782 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73783 #else
73784 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73785 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73786 SLAB_CACHE_DMA | \
73787 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73788 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73789 @@ -290,7 +290,7 @@ struct kmem_list3 {
73790 * Need this for bootstrapping a per node allocator.
73791 */
73792 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73793 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73794 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73795 #define CACHE_CACHE 0
73796 #define SIZE_AC MAX_NUMNODES
73797 #define SIZE_L3 (2 * MAX_NUMNODES)
73798 @@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73799 if ((x)->max_freeable < i) \
73800 (x)->max_freeable = i; \
73801 } while (0)
73802 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73803 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73804 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73805 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73806 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73807 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73808 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73809 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73810 #else
73811 #define STATS_INC_ACTIVE(x) do { } while (0)
73812 #define STATS_DEC_ACTIVE(x) do { } while (0)
73813 @@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73814 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73815 */
73816 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
73817 - const struct slab *slab, void *obj)
73818 + const struct slab *slab, const void *obj)
73819 {
73820 u32 offset = (obj - slab->s_mem);
73821 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
73822 @@ -563,12 +563,13 @@ EXPORT_SYMBOL(malloc_sizes);
73823 struct cache_names {
73824 char *name;
73825 char *name_dma;
73826 + char *name_usercopy;
73827 };
73828
73829 static struct cache_names __initdata cache_names[] = {
73830 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
73831 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
73832 #include <linux/kmalloc_sizes.h>
73833 - {NULL,}
73834 + {NULL}
73835 #undef CACHE
73836 };
73837
73838 @@ -756,6 +757,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
73839 if (unlikely(gfpflags & GFP_DMA))
73840 return csizep->cs_dmacachep;
73841 #endif
73842 +
73843 +#ifdef CONFIG_PAX_USERCOPY_SLABS
73844 + if (unlikely(gfpflags & GFP_USERCOPY))
73845 + return csizep->cs_usercopycachep;
73846 +#endif
73847 +
73848 return csizep->cs_cachep;
73849 }
73850
73851 @@ -1588,7 +1595,7 @@ void __init kmem_cache_init(void)
73852 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
73853 sizes[INDEX_AC].cs_size,
73854 ARCH_KMALLOC_MINALIGN,
73855 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73856 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73857 NULL);
73858
73859 if (INDEX_AC != INDEX_L3) {
73860 @@ -1596,7 +1603,7 @@ void __init kmem_cache_init(void)
73861 kmem_cache_create(names[INDEX_L3].name,
73862 sizes[INDEX_L3].cs_size,
73863 ARCH_KMALLOC_MINALIGN,
73864 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73865 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73866 NULL);
73867 }
73868
73869 @@ -1614,7 +1621,7 @@ void __init kmem_cache_init(void)
73870 sizes->cs_cachep = kmem_cache_create(names->name,
73871 sizes->cs_size,
73872 ARCH_KMALLOC_MINALIGN,
73873 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73874 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73875 NULL);
73876 }
73877 #ifdef CONFIG_ZONE_DMA
73878 @@ -1626,6 +1633,16 @@ void __init kmem_cache_init(void)
73879 SLAB_PANIC,
73880 NULL);
73881 #endif
73882 +
73883 +#ifdef CONFIG_PAX_USERCOPY_SLABS
73884 + sizes->cs_usercopycachep = kmem_cache_create(
73885 + names->name_usercopy,
73886 + sizes->cs_size,
73887 + ARCH_KMALLOC_MINALIGN,
73888 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73889 + NULL);
73890 +#endif
73891 +
73892 sizes++;
73893 names++;
73894 }
73895 @@ -4390,10 +4407,10 @@ static int s_show(struct seq_file *m, void *p)
73896 }
73897 /* cpu stats */
73898 {
73899 - unsigned long allochit = atomic_read(&cachep->allochit);
73900 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
73901 - unsigned long freehit = atomic_read(&cachep->freehit);
73902 - unsigned long freemiss = atomic_read(&cachep->freemiss);
73903 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
73904 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
73905 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
73906 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
73907
73908 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
73909 allochit, allocmiss, freehit, freemiss);
73910 @@ -4652,13 +4669,68 @@ static int __init slab_proc_init(void)
73911 {
73912 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
73913 #ifdef CONFIG_DEBUG_SLAB_LEAK
73914 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
73915 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
73916 #endif
73917 return 0;
73918 }
73919 module_init(slab_proc_init);
73920 #endif
73921
73922 +bool is_usercopy_object(const void *ptr)
73923 +{
73924 + struct page *page;
73925 + struct kmem_cache *cachep;
73926 +
73927 + if (ZERO_OR_NULL_PTR(ptr))
73928 + return false;
73929 +
73930 + if (!virt_addr_valid(ptr))
73931 + return false;
73932 +
73933 + page = virt_to_head_page(ptr);
73934 +
73935 + if (!PageSlab(page))
73936 + return false;
73937 +
73938 + cachep = page_get_cache(page);
73939 + return cachep->flags & SLAB_USERCOPY;
73940 +}
73941 +
73942 +#ifdef CONFIG_PAX_USERCOPY
73943 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
73944 +{
73945 + struct page *page;
73946 + struct kmem_cache *cachep;
73947 + struct slab *slabp;
73948 + unsigned int objnr;
73949 + unsigned long offset;
73950 +
73951 + if (ZERO_OR_NULL_PTR(ptr))
73952 + return "<null>";
73953 +
73954 + if (!virt_addr_valid(ptr))
73955 + return NULL;
73956 +
73957 + page = virt_to_head_page(ptr);
73958 +
73959 + if (!PageSlab(page))
73960 + return NULL;
73961 +
73962 + cachep = page_get_cache(page);
73963 + if (!(cachep->flags & SLAB_USERCOPY))
73964 + return cachep->name;
73965 +
73966 + slabp = page_get_slab(page);
73967 + objnr = obj_to_index(cachep, slabp, ptr);
73968 + BUG_ON(objnr >= cachep->num);
73969 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
73970 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
73971 + return NULL;
73972 +
73973 + return cachep->name;
73974 +}
73975 +#endif
73976 +
73977 /**
73978 * ksize - get the actual amount of memory allocated for a given object
73979 * @objp: Pointer to the object
73980 diff --git a/mm/slob.c b/mm/slob.c
73981 index 8105be4..3c15e57 100644
73982 --- a/mm/slob.c
73983 +++ b/mm/slob.c
73984 @@ -29,7 +29,7 @@
73985 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
73986 * alloc_pages() directly, allocating compound pages so the page order
73987 * does not have to be separately tracked, and also stores the exact
73988 - * allocation size in page->private so that it can be used to accurately
73989 + * allocation size in slob_page->size so that it can be used to accurately
73990 * provide ksize(). These objects are detected in kfree() because slob_page()
73991 * is false for them.
73992 *
73993 @@ -58,6 +58,7 @@
73994 */
73995
73996 #include <linux/kernel.h>
73997 +#include <linux/sched.h>
73998 #include <linux/slab.h>
73999 #include <linux/mm.h>
74000 #include <linux/swap.h> /* struct reclaim_state */
74001 @@ -102,7 +103,8 @@ struct slob_page {
74002 unsigned long flags; /* mandatory */
74003 atomic_t _count; /* mandatory */
74004 slobidx_t units; /* free units left in page */
74005 - unsigned long pad[2];
74006 + unsigned long pad[1];
74007 + unsigned long size; /* size when >=PAGE_SIZE */
74008 slob_t *free; /* first free slob_t in page */
74009 struct list_head list; /* linked list of free pages */
74010 };
74011 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
74012 */
74013 static inline int is_slob_page(struct slob_page *sp)
74014 {
74015 - return PageSlab((struct page *)sp);
74016 + return PageSlab((struct page *)sp) && !sp->size;
74017 }
74018
74019 static inline void set_slob_page(struct slob_page *sp)
74020 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
74021
74022 static inline struct slob_page *slob_page(const void *addr)
74023 {
74024 - return (struct slob_page *)virt_to_page(addr);
74025 + return (struct slob_page *)virt_to_head_page(addr);
74026 }
74027
74028 /*
74029 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74030 /*
74031 * Return the size of a slob block.
74032 */
74033 -static slobidx_t slob_units(slob_t *s)
74034 +static slobidx_t slob_units(const slob_t *s)
74035 {
74036 if (s->units > 0)
74037 return s->units;
74038 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
74039 /*
74040 * Return the next free slob block pointer after this one.
74041 */
74042 -static slob_t *slob_next(slob_t *s)
74043 +static slob_t *slob_next(const slob_t *s)
74044 {
74045 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74046 slobidx_t next;
74047 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
74048 /*
74049 * Returns true if s is the last free block in its page.
74050 */
74051 -static int slob_last(slob_t *s)
74052 +static int slob_last(const slob_t *s)
74053 {
74054 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74055 }
74056 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74057 if (!page)
74058 return NULL;
74059
74060 + set_slob_page(page);
74061 return page_address(page);
74062 }
74063
74064 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74065 if (!b)
74066 return NULL;
74067 sp = slob_page(b);
74068 - set_slob_page(sp);
74069
74070 spin_lock_irqsave(&slob_lock, flags);
74071 sp->units = SLOB_UNITS(PAGE_SIZE);
74072 sp->free = b;
74073 + sp->size = 0;
74074 INIT_LIST_HEAD(&sp->list);
74075 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74076 set_slob_page_free(sp, slob_list);
74077 @@ -476,10 +479,9 @@ out:
74078 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74079 */
74080
74081 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74082 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74083 {
74084 - unsigned int *m;
74085 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74086 + slob_t *m;
74087 void *ret;
74088
74089 gfp &= gfp_allowed_mask;
74090 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74091
74092 if (!m)
74093 return NULL;
74094 - *m = size;
74095 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74096 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74097 + m[0].units = size;
74098 + m[1].units = align;
74099 ret = (void *)m + align;
74100
74101 trace_kmalloc_node(_RET_IP_, ret,
74102 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74103 gfp |= __GFP_COMP;
74104 ret = slob_new_pages(gfp, order, node);
74105 if (ret) {
74106 - struct page *page;
74107 - page = virt_to_page(ret);
74108 - page->private = size;
74109 + struct slob_page *sp;
74110 + sp = slob_page(ret);
74111 + sp->size = size;
74112 }
74113
74114 trace_kmalloc_node(_RET_IP_, ret,
74115 size, PAGE_SIZE << order, gfp, node);
74116 }
74117
74118 - kmemleak_alloc(ret, size, 1, gfp);
74119 + return ret;
74120 +}
74121 +
74122 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74123 +{
74124 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74125 + void *ret = __kmalloc_node_align(size, gfp, node, align);
74126 +
74127 + if (!ZERO_OR_NULL_PTR(ret))
74128 + kmemleak_alloc(ret, size, 1, gfp);
74129 return ret;
74130 }
74131 EXPORT_SYMBOL(__kmalloc_node);
74132 @@ -533,13 +547,83 @@ void kfree(const void *block)
74133 sp = slob_page(block);
74134 if (is_slob_page(sp)) {
74135 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74136 - unsigned int *m = (unsigned int *)(block - align);
74137 - slob_free(m, *m + align);
74138 - } else
74139 + slob_t *m = (slob_t *)(block - align);
74140 + slob_free(m, m[0].units + align);
74141 + } else {
74142 + clear_slob_page(sp);
74143 + free_slob_page(sp);
74144 + sp->size = 0;
74145 put_page(&sp->page);
74146 + }
74147 }
74148 EXPORT_SYMBOL(kfree);
74149
74150 +bool is_usercopy_object(const void *ptr)
74151 +{
74152 + return false;
74153 +}
74154 +
74155 +#ifdef CONFIG_PAX_USERCOPY
74156 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74157 +{
74158 + struct slob_page *sp;
74159 + const slob_t *free;
74160 + const void *base;
74161 + unsigned long flags;
74162 +
74163 + if (ZERO_OR_NULL_PTR(ptr))
74164 + return "<null>";
74165 +
74166 + if (!virt_addr_valid(ptr))
74167 + return NULL;
74168 +
74169 + sp = slob_page(ptr);
74170 + if (!PageSlab((struct page *)sp))
74171 + return NULL;
74172 +
74173 + if (sp->size) {
74174 + base = page_address(&sp->page);
74175 + if (base <= ptr && n <= sp->size - (ptr - base))
74176 + return NULL;
74177 + return "<slob>";
74178 + }
74179 +
74180 + /* some tricky double walking to find the chunk */
74181 + spin_lock_irqsave(&slob_lock, flags);
74182 + base = (void *)((unsigned long)ptr & PAGE_MASK);
74183 + free = sp->free;
74184 +
74185 + while (!slob_last(free) && (void *)free <= ptr) {
74186 + base = free + slob_units(free);
74187 + free = slob_next(free);
74188 + }
74189 +
74190 + while (base < (void *)free) {
74191 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74192 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
74193 + int offset;
74194 +
74195 + if (ptr < base + align)
74196 + break;
74197 +
74198 + offset = ptr - base - align;
74199 + if (offset >= m) {
74200 + base += size;
74201 + continue;
74202 + }
74203 +
74204 + if (n > m - offset)
74205 + break;
74206 +
74207 + spin_unlock_irqrestore(&slob_lock, flags);
74208 + return NULL;
74209 + }
74210 +
74211 + spin_unlock_irqrestore(&slob_lock, flags);
74212 + return "<slob>";
74213 +}
74214 +#endif
74215 +
74216 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74217 size_t ksize(const void *block)
74218 {
74219 @@ -552,10 +636,10 @@ size_t ksize(const void *block)
74220 sp = slob_page(block);
74221 if (is_slob_page(sp)) {
74222 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74223 - unsigned int *m = (unsigned int *)(block - align);
74224 - return SLOB_UNITS(*m) * SLOB_UNIT;
74225 + slob_t *m = (slob_t *)(block - align);
74226 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74227 } else
74228 - return sp->page.private;
74229 + return sp->size;
74230 }
74231 EXPORT_SYMBOL(ksize);
74232
74233 @@ -571,8 +655,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74234 {
74235 struct kmem_cache *c;
74236
74237 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74238 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
74239 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74240 +#else
74241 c = slob_alloc(sizeof(struct kmem_cache),
74242 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74243 +#endif
74244
74245 if (c) {
74246 c->name = name;
74247 @@ -614,17 +703,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
74248
74249 lockdep_trace_alloc(flags);
74250
74251 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74252 + b = __kmalloc_node_align(c->size, flags, node, c->align);
74253 +#else
74254 if (c->size < PAGE_SIZE) {
74255 b = slob_alloc(c->size, flags, c->align, node);
74256 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74257 SLOB_UNITS(c->size) * SLOB_UNIT,
74258 flags, node);
74259 } else {
74260 + struct slob_page *sp;
74261 +
74262 b = slob_new_pages(flags, get_order(c->size), node);
74263 + sp = slob_page(b);
74264 + sp->size = c->size;
74265 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74266 PAGE_SIZE << get_order(c->size),
74267 flags, node);
74268 }
74269 +#endif
74270
74271 if (c->ctor)
74272 c->ctor(b);
74273 @@ -636,10 +733,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74274
74275 static void __kmem_cache_free(void *b, int size)
74276 {
74277 - if (size < PAGE_SIZE)
74278 + struct slob_page *sp = slob_page(b);
74279 +
74280 + if (is_slob_page(sp))
74281 slob_free(b, size);
74282 - else
74283 + else {
74284 + clear_slob_page(sp);
74285 + free_slob_page(sp);
74286 + sp->size = 0;
74287 slob_free_pages(b, get_order(size));
74288 + }
74289 }
74290
74291 static void kmem_rcu_free(struct rcu_head *head)
74292 @@ -652,17 +755,31 @@ static void kmem_rcu_free(struct rcu_head *head)
74293
74294 void kmem_cache_free(struct kmem_cache *c, void *b)
74295 {
74296 + int size = c->size;
74297 +
74298 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74299 + if (size + c->align < PAGE_SIZE) {
74300 + size += c->align;
74301 + b -= c->align;
74302 + }
74303 +#endif
74304 +
74305 kmemleak_free_recursive(b, c->flags);
74306 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74307 struct slob_rcu *slob_rcu;
74308 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74309 - slob_rcu->size = c->size;
74310 + slob_rcu = b + (size - sizeof(struct slob_rcu));
74311 + slob_rcu->size = size;
74312 call_rcu(&slob_rcu->head, kmem_rcu_free);
74313 } else {
74314 - __kmem_cache_free(b, c->size);
74315 + __kmem_cache_free(b, size);
74316 }
74317
74318 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74319 + trace_kfree(_RET_IP_, b);
74320 +#else
74321 trace_kmem_cache_free(_RET_IP_, b);
74322 +#endif
74323 +
74324 }
74325 EXPORT_SYMBOL(kmem_cache_free);
74326
74327 diff --git a/mm/slub.c b/mm/slub.c
74328 index 8c691fa..ff23a85 100644
74329 --- a/mm/slub.c
74330 +++ b/mm/slub.c
74331 @@ -209,7 +209,7 @@ struct track {
74332
74333 enum track_item { TRACK_ALLOC, TRACK_FREE };
74334
74335 -#ifdef CONFIG_SYSFS
74336 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74337 static int sysfs_slab_add(struct kmem_cache *);
74338 static int sysfs_slab_alias(struct kmem_cache *, const char *);
74339 static void sysfs_slab_remove(struct kmem_cache *);
74340 @@ -538,7 +538,7 @@ static void print_track(const char *s, struct track *t)
74341 if (!t->addr)
74342 return;
74343
74344 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74345 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74346 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
74347 #ifdef CONFIG_STACKTRACE
74348 {
74349 @@ -2603,6 +2603,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
74350
74351 page = virt_to_head_page(x);
74352
74353 + BUG_ON(!PageSlab(page));
74354 +
74355 slab_free(s, page, x, _RET_IP_);
74356
74357 trace_kmem_cache_free(_RET_IP_, x);
74358 @@ -2636,7 +2638,7 @@ static int slub_min_objects;
74359 * Merge control. If this is set then no merging of slab caches will occur.
74360 * (Could be removed. This was introduced to pacify the merge skeptics.)
74361 */
74362 -static int slub_nomerge;
74363 +static int slub_nomerge = 1;
74364
74365 /*
74366 * Calculate the order of allocation given an slab object size.
74367 @@ -3089,7 +3091,7 @@ static int kmem_cache_open(struct kmem_cache *s,
74368 else
74369 s->cpu_partial = 30;
74370
74371 - s->refcount = 1;
74372 + atomic_set(&s->refcount, 1);
74373 #ifdef CONFIG_NUMA
74374 s->remote_node_defrag_ratio = 1000;
74375 #endif
74376 @@ -3193,8 +3195,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
74377 void kmem_cache_destroy(struct kmem_cache *s)
74378 {
74379 down_write(&slub_lock);
74380 - s->refcount--;
74381 - if (!s->refcount) {
74382 + if (atomic_dec_and_test(&s->refcount)) {
74383 list_del(&s->list);
74384 up_write(&slub_lock);
74385 if (kmem_cache_close(s)) {
74386 @@ -3223,6 +3224,10 @@ static struct kmem_cache *kmem_cache;
74387 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
74388 #endif
74389
74390 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74391 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
74392 +#endif
74393 +
74394 static int __init setup_slub_min_order(char *str)
74395 {
74396 get_option(&str, &slub_min_order);
74397 @@ -3337,6 +3342,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
74398 return kmalloc_dma_caches[index];
74399
74400 #endif
74401 +
74402 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74403 + if (flags & SLAB_USERCOPY)
74404 + return kmalloc_usercopy_caches[index];
74405 +
74406 +#endif
74407 +
74408 return kmalloc_caches[index];
74409 }
74410
74411 @@ -3405,6 +3417,56 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
74412 EXPORT_SYMBOL(__kmalloc_node);
74413 #endif
74414
74415 +bool is_usercopy_object(const void *ptr)
74416 +{
74417 + struct page *page;
74418 + struct kmem_cache *s;
74419 +
74420 + if (ZERO_OR_NULL_PTR(ptr))
74421 + return false;
74422 +
74423 + if (!virt_addr_valid(ptr))
74424 + return false;
74425 +
74426 + page = virt_to_head_page(ptr);
74427 +
74428 + if (!PageSlab(page))
74429 + return false;
74430 +
74431 + s = page->slab;
74432 + return s->flags & SLAB_USERCOPY;
74433 +}
74434 +
74435 +#ifdef CONFIG_PAX_USERCOPY
74436 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74437 +{
74438 + struct page *page;
74439 + struct kmem_cache *s;
74440 + unsigned long offset;
74441 +
74442 + if (ZERO_OR_NULL_PTR(ptr))
74443 + return "<null>";
74444 +
74445 + if (!virt_addr_valid(ptr))
74446 + return NULL;
74447 +
74448 + page = virt_to_head_page(ptr);
74449 +
74450 + if (!PageSlab(page))
74451 + return NULL;
74452 +
74453 + s = page->slab;
74454 + if (!(s->flags & SLAB_USERCOPY))
74455 + return s->name;
74456 +
74457 + offset = (ptr - page_address(page)) % s->size;
74458 + if (offset <= s->objsize && n <= s->objsize - offset)
74459 + return NULL;
74460 +
74461 + return s->name;
74462 +}
74463 +#endif
74464 +
74465 size_t ksize(const void *object)
74466 {
74467 struct page *page;
74468 @@ -3679,7 +3741,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
74469 int node;
74470
74471 list_add(&s->list, &slab_caches);
74472 - s->refcount = -1;
74473 + atomic_set(&s->refcount, -1);
74474
74475 for_each_node_state(node, N_NORMAL_MEMORY) {
74476 struct kmem_cache_node *n = get_node(s, node);
74477 @@ -3799,17 +3861,17 @@ void __init kmem_cache_init(void)
74478
74479 /* Caches that are not of the two-to-the-power-of size */
74480 if (KMALLOC_MIN_SIZE <= 32) {
74481 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
74482 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
74483 caches++;
74484 }
74485
74486 if (KMALLOC_MIN_SIZE <= 64) {
74487 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
74488 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
74489 caches++;
74490 }
74491
74492 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
74493 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
74494 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
74495 caches++;
74496 }
74497
74498 @@ -3851,6 +3913,22 @@ void __init kmem_cache_init(void)
74499 }
74500 }
74501 #endif
74502 +
74503 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74504 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
74505 + struct kmem_cache *s = kmalloc_caches[i];
74506 +
74507 + if (s && s->size) {
74508 + char *name = kasprintf(GFP_NOWAIT,
74509 + "usercopy-kmalloc-%d", s->objsize);
74510 +
74511 + BUG_ON(!name);
74512 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
74513 + s->objsize, SLAB_USERCOPY);
74514 + }
74515 + }
74516 +#endif
74517 +
74518 printk(KERN_INFO
74519 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
74520 " CPUs=%d, Nodes=%d\n",
74521 @@ -3877,7 +3955,7 @@ static int slab_unmergeable(struct kmem_cache *s)
74522 /*
74523 * We may have set a slab to be unmergeable during bootstrap.
74524 */
74525 - if (s->refcount < 0)
74526 + if (atomic_read(&s->refcount) < 0)
74527 return 1;
74528
74529 return 0;
74530 @@ -3936,7 +4014,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74531 down_write(&slub_lock);
74532 s = find_mergeable(size, align, flags, name, ctor);
74533 if (s) {
74534 - s->refcount++;
74535 + atomic_inc(&s->refcount);
74536 /*
74537 * Adjust the object sizes so that we clear
74538 * the complete object on kzalloc.
74539 @@ -3945,7 +4023,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74540 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
74541
74542 if (sysfs_slab_alias(s, name)) {
74543 - s->refcount--;
74544 + atomic_dec(&s->refcount);
74545 goto err;
74546 }
74547 up_write(&slub_lock);
74548 @@ -4074,7 +4152,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
74549 }
74550 #endif
74551
74552 -#ifdef CONFIG_SYSFS
74553 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74554 static int count_inuse(struct page *page)
74555 {
74556 return page->inuse;
74557 @@ -4461,12 +4539,12 @@ static void resiliency_test(void)
74558 validate_slab_cache(kmalloc_caches[9]);
74559 }
74560 #else
74561 -#ifdef CONFIG_SYSFS
74562 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74563 static void resiliency_test(void) {};
74564 #endif
74565 #endif
74566
74567 -#ifdef CONFIG_SYSFS
74568 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74569 enum slab_stat_type {
74570 SL_ALL, /* All slabs */
74571 SL_PARTIAL, /* Only partially allocated slabs */
74572 @@ -4709,7 +4787,7 @@ SLAB_ATTR_RO(ctor);
74573
74574 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74575 {
74576 - return sprintf(buf, "%d\n", s->refcount - 1);
74577 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74578 }
74579 SLAB_ATTR_RO(aliases);
74580
74581 @@ -5280,6 +5358,7 @@ static char *create_unique_id(struct kmem_cache *s)
74582 return name;
74583 }
74584
74585 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74586 static int sysfs_slab_add(struct kmem_cache *s)
74587 {
74588 int err;
74589 @@ -5342,6 +5421,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
74590 kobject_del(&s->kobj);
74591 kobject_put(&s->kobj);
74592 }
74593 +#endif
74594
74595 /*
74596 * Need to buffer aliases during bootup until sysfs becomes
74597 @@ -5355,6 +5435,7 @@ struct saved_alias {
74598
74599 static struct saved_alias *alias_list;
74600
74601 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74602 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74603 {
74604 struct saved_alias *al;
74605 @@ -5377,6 +5458,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74606 alias_list = al;
74607 return 0;
74608 }
74609 +#endif
74610
74611 static int __init slab_sysfs_init(void)
74612 {
74613 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
74614 index 1b7e22a..3fcd4f3 100644
74615 --- a/mm/sparse-vmemmap.c
74616 +++ b/mm/sparse-vmemmap.c
74617 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
74618 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74619 if (!p)
74620 return NULL;
74621 - pud_populate(&init_mm, pud, p);
74622 + pud_populate_kernel(&init_mm, pud, p);
74623 }
74624 return pud;
74625 }
74626 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
74627 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74628 if (!p)
74629 return NULL;
74630 - pgd_populate(&init_mm, pgd, p);
74631 + pgd_populate_kernel(&init_mm, pgd, p);
74632 }
74633 return pgd;
74634 }
74635 diff --git a/mm/swap.c b/mm/swap.c
74636 index 4e7e2ec..0c57830 100644
74637 --- a/mm/swap.c
74638 +++ b/mm/swap.c
74639 @@ -30,6 +30,7 @@
74640 #include <linux/backing-dev.h>
74641 #include <linux/memcontrol.h>
74642 #include <linux/gfp.h>
74643 +#include <linux/hugetlb.h>
74644
74645 #include "internal.h"
74646
74647 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
74648
74649 __page_cache_release(page);
74650 dtor = get_compound_page_dtor(page);
74651 + if (!PageHuge(page))
74652 + BUG_ON(dtor != free_compound_page);
74653 (*dtor)(page);
74654 }
74655
74656 diff --git a/mm/swapfile.c b/mm/swapfile.c
74657 index 71373d0..11fa7d9 100644
74658 --- a/mm/swapfile.c
74659 +++ b/mm/swapfile.c
74660 @@ -63,7 +63,7 @@ static DEFINE_MUTEX(swapon_mutex);
74661
74662 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74663 /* Activity counter to indicate that a swapon or swapoff has occurred */
74664 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
74665 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74666
74667 static inline unsigned char swap_count(unsigned char ent)
74668 {
74669 @@ -1663,7 +1663,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74670 }
74671 filp_close(swap_file, NULL);
74672 err = 0;
74673 - atomic_inc(&proc_poll_event);
74674 + atomic_inc_unchecked(&proc_poll_event);
74675 wake_up_interruptible(&proc_poll_wait);
74676
74677 out_dput:
74678 @@ -1679,8 +1679,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74679
74680 poll_wait(file, &proc_poll_wait, wait);
74681
74682 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
74683 - seq->poll_event = atomic_read(&proc_poll_event);
74684 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74685 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74686 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74687 }
74688
74689 @@ -1778,7 +1778,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74690 return ret;
74691
74692 seq = file->private_data;
74693 - seq->poll_event = atomic_read(&proc_poll_event);
74694 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74695 return 0;
74696 }
74697
74698 @@ -2120,7 +2120,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74699 (frontswap_map) ? "FS" : "");
74700
74701 mutex_unlock(&swapon_mutex);
74702 - atomic_inc(&proc_poll_event);
74703 + atomic_inc_unchecked(&proc_poll_event);
74704 wake_up_interruptible(&proc_poll_wait);
74705
74706 if (S_ISREG(inode->i_mode))
74707 diff --git a/mm/util.c b/mm/util.c
74708 index 8c7265a..c96d884 100644
74709 --- a/mm/util.c
74710 +++ b/mm/util.c
74711 @@ -285,6 +285,12 @@ done:
74712 void arch_pick_mmap_layout(struct mm_struct *mm)
74713 {
74714 mm->mmap_base = TASK_UNMAPPED_BASE;
74715 +
74716 +#ifdef CONFIG_PAX_RANDMMAP
74717 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74718 + mm->mmap_base += mm->delta_mmap;
74719 +#endif
74720 +
74721 mm->get_unmapped_area = arch_get_unmapped_area;
74722 mm->unmap_area = arch_unmap_area;
74723 }
74724 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74725 index 2aad499..a8a740e 100644
74726 --- a/mm/vmalloc.c
74727 +++ b/mm/vmalloc.c
74728 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74729
74730 pte = pte_offset_kernel(pmd, addr);
74731 do {
74732 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74733 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74734 +
74735 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74736 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74737 + BUG_ON(!pte_exec(*pte));
74738 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74739 + continue;
74740 + }
74741 +#endif
74742 +
74743 + {
74744 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74745 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74746 + }
74747 } while (pte++, addr += PAGE_SIZE, addr != end);
74748 }
74749
74750 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74751 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74752 {
74753 pte_t *pte;
74754 + int ret = -ENOMEM;
74755
74756 /*
74757 * nr is a running index into the array which helps higher level
74758 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74759 pte = pte_alloc_kernel(pmd, addr);
74760 if (!pte)
74761 return -ENOMEM;
74762 +
74763 + pax_open_kernel();
74764 do {
74765 struct page *page = pages[*nr];
74766
74767 - if (WARN_ON(!pte_none(*pte)))
74768 - return -EBUSY;
74769 - if (WARN_ON(!page))
74770 - return -ENOMEM;
74771 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74772 + if (pgprot_val(prot) & _PAGE_NX)
74773 +#endif
74774 +
74775 + if (WARN_ON(!pte_none(*pte))) {
74776 + ret = -EBUSY;
74777 + goto out;
74778 + }
74779 + if (WARN_ON(!page)) {
74780 + ret = -ENOMEM;
74781 + goto out;
74782 + }
74783 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74784 (*nr)++;
74785 } while (pte++, addr += PAGE_SIZE, addr != end);
74786 - return 0;
74787 + ret = 0;
74788 +out:
74789 + pax_close_kernel();
74790 + return ret;
74791 }
74792
74793 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74794 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74795 pmd_t *pmd;
74796 unsigned long next;
74797
74798 - pmd = pmd_alloc(&init_mm, pud, addr);
74799 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
74800 if (!pmd)
74801 return -ENOMEM;
74802 do {
74803 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
74804 pud_t *pud;
74805 unsigned long next;
74806
74807 - pud = pud_alloc(&init_mm, pgd, addr);
74808 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
74809 if (!pud)
74810 return -ENOMEM;
74811 do {
74812 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74813 * and fall back on vmalloc() if that fails. Others
74814 * just put it in the vmalloc space.
74815 */
74816 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
74817 +#ifdef CONFIG_MODULES
74818 +#ifdef MODULES_VADDR
74819 unsigned long addr = (unsigned long)x;
74820 if (addr >= MODULES_VADDR && addr < MODULES_END)
74821 return 1;
74822 #endif
74823 +
74824 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74825 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
74826 + return 1;
74827 +#endif
74828 +
74829 +#endif
74830 +
74831 return is_vmalloc_addr(x);
74832 }
74833
74834 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
74835
74836 if (!pgd_none(*pgd)) {
74837 pud_t *pud = pud_offset(pgd, addr);
74838 +#ifdef CONFIG_X86
74839 + if (!pud_large(*pud))
74840 +#endif
74841 if (!pud_none(*pud)) {
74842 pmd_t *pmd = pmd_offset(pud, addr);
74843 +#ifdef CONFIG_X86
74844 + if (!pmd_large(*pmd))
74845 +#endif
74846 if (!pmd_none(*pmd)) {
74847 pte_t *ptep, pte;
74848
74849 @@ -329,7 +369,7 @@ static void purge_vmap_area_lazy(void);
74850 * Allocate a region of KVA of the specified size and alignment, within the
74851 * vstart and vend.
74852 */
74853 -static struct vmap_area *alloc_vmap_area(unsigned long size,
74854 +static struct __size_overflow(1) vmap_area *alloc_vmap_area(unsigned long size,
74855 unsigned long align,
74856 unsigned long vstart, unsigned long vend,
74857 int node, gfp_t gfp_mask)
74858 @@ -1320,6 +1360,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
74859 struct vm_struct *area;
74860
74861 BUG_ON(in_interrupt());
74862 +
74863 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74864 + if (flags & VM_KERNEXEC) {
74865 + if (start != VMALLOC_START || end != VMALLOC_END)
74866 + return NULL;
74867 + start = (unsigned long)MODULES_EXEC_VADDR;
74868 + end = (unsigned long)MODULES_EXEC_END;
74869 + }
74870 +#endif
74871 +
74872 if (flags & VM_IOREMAP) {
74873 int bit = fls(size);
74874
74875 @@ -1552,6 +1602,11 @@ void *vmap(struct page **pages, unsigned int count,
74876 if (count > totalram_pages)
74877 return NULL;
74878
74879 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74880 + if (!(pgprot_val(prot) & _PAGE_NX))
74881 + flags |= VM_KERNEXEC;
74882 +#endif
74883 +
74884 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
74885 __builtin_return_address(0));
74886 if (!area)
74887 @@ -1653,6 +1708,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
74888 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
74889 goto fail;
74890
74891 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74892 + if (!(pgprot_val(prot) & _PAGE_NX))
74893 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
74894 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
74895 + else
74896 +#endif
74897 +
74898 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
74899 start, end, node, gfp_mask, caller);
74900 if (!area)
74901 @@ -1826,10 +1888,9 @@ EXPORT_SYMBOL(vzalloc_node);
74902 * For tight control over page level allocator and protection flags
74903 * use __vmalloc() instead.
74904 */
74905 -
74906 void *vmalloc_exec(unsigned long size)
74907 {
74908 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
74909 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
74910 -1, __builtin_return_address(0));
74911 }
74912
74913 @@ -2124,6 +2185,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
74914 unsigned long uaddr = vma->vm_start;
74915 unsigned long usize = vma->vm_end - vma->vm_start;
74916
74917 + BUG_ON(vma->vm_mirror);
74918 +
74919 if ((PAGE_SIZE-1) & (unsigned long)addr)
74920 return -EINVAL;
74921
74922 diff --git a/mm/vmstat.c b/mm/vmstat.c
74923 index 1bbbbd9..ff35669 100644
74924 --- a/mm/vmstat.c
74925 +++ b/mm/vmstat.c
74926 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
74927 *
74928 * vm_stat contains the global counters
74929 */
74930 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74931 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74932 EXPORT_SYMBOL(vm_stat);
74933
74934 #ifdef CONFIG_SMP
74935 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
74936 v = p->vm_stat_diff[i];
74937 p->vm_stat_diff[i] = 0;
74938 local_irq_restore(flags);
74939 - atomic_long_add(v, &zone->vm_stat[i]);
74940 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
74941 global_diff[i] += v;
74942 #ifdef CONFIG_NUMA
74943 /* 3 seconds idle till flush */
74944 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
74945
74946 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
74947 if (global_diff[i])
74948 - atomic_long_add(global_diff[i], &vm_stat[i]);
74949 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
74950 }
74951
74952 #endif
74953 @@ -1211,10 +1211,20 @@ static int __init setup_vmstat(void)
74954 start_cpu_timer(cpu);
74955 #endif
74956 #ifdef CONFIG_PROC_FS
74957 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
74958 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
74959 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
74960 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
74961 + {
74962 + mode_t gr_mode = S_IRUGO;
74963 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74964 + gr_mode = S_IRUSR;
74965 +#endif
74966 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
74967 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
74968 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74969 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
74970 +#else
74971 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
74972 +#endif
74973 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
74974 + }
74975 #endif
74976 return 0;
74977 }
74978 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
74979 index 9096bcb..43ed7bb 100644
74980 --- a/net/8021q/vlan.c
74981 +++ b/net/8021q/vlan.c
74982 @@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
74983 err = -EPERM;
74984 if (!capable(CAP_NET_ADMIN))
74985 break;
74986 - if ((args.u.name_type >= 0) &&
74987 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
74988 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
74989 struct vlan_net *vn;
74990
74991 vn = net_generic(net, vlan_net_id);
74992 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
74993 index 6449bae..8c1f454 100644
74994 --- a/net/9p/trans_fd.c
74995 +++ b/net/9p/trans_fd.c
74996 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
74997 oldfs = get_fs();
74998 set_fs(get_ds());
74999 /* The cast to a user pointer is valid due to the set_fs() */
75000 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75001 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75002 set_fs(oldfs);
75003
75004 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75005 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
75006 index 876fbe8..8bbea9f 100644
75007 --- a/net/atm/atm_misc.c
75008 +++ b/net/atm/atm_misc.c
75009 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
75010 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75011 return 1;
75012 atm_return(vcc, truesize);
75013 - atomic_inc(&vcc->stats->rx_drop);
75014 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75015 return 0;
75016 }
75017 EXPORT_SYMBOL(atm_charge);
75018 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
75019 }
75020 }
75021 atm_return(vcc, guess);
75022 - atomic_inc(&vcc->stats->rx_drop);
75023 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75024 return NULL;
75025 }
75026 EXPORT_SYMBOL(atm_alloc_charge);
75027 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75028
75029 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75030 {
75031 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75032 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75033 __SONET_ITEMS
75034 #undef __HANDLE_ITEM
75035 }
75036 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75037
75038 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75039 {
75040 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75041 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75042 __SONET_ITEMS
75043 #undef __HANDLE_ITEM
75044 }
75045 diff --git a/net/atm/lec.h b/net/atm/lec.h
75046 index a86aff9..3a0d6f6 100644
75047 --- a/net/atm/lec.h
75048 +++ b/net/atm/lec.h
75049 @@ -48,7 +48,7 @@ struct lane2_ops {
75050 const u8 *tlvs, u32 sizeoftlvs);
75051 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75052 const u8 *tlvs, u32 sizeoftlvs);
75053 -};
75054 +} __no_const;
75055
75056 /*
75057 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75058 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
75059 index 0919a88..a23d54e 100644
75060 --- a/net/atm/mpc.h
75061 +++ b/net/atm/mpc.h
75062 @@ -33,7 +33,7 @@ struct mpoa_client {
75063 struct mpc_parameters parameters; /* parameters for this client */
75064
75065 const struct net_device_ops *old_ops;
75066 - struct net_device_ops new_ops;
75067 + net_device_ops_no_const new_ops;
75068 };
75069
75070
75071 diff --git a/net/atm/proc.c b/net/atm/proc.c
75072 index 0d020de..011c7bb 100644
75073 --- a/net/atm/proc.c
75074 +++ b/net/atm/proc.c
75075 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75076 const struct k_atm_aal_stats *stats)
75077 {
75078 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75079 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75080 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75081 - atomic_read(&stats->rx_drop));
75082 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75083 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75084 + atomic_read_unchecked(&stats->rx_drop));
75085 }
75086
75087 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75088 diff --git a/net/atm/resources.c b/net/atm/resources.c
75089 index 23f45ce..c748f1a 100644
75090 --- a/net/atm/resources.c
75091 +++ b/net/atm/resources.c
75092 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75093 static void copy_aal_stats(struct k_atm_aal_stats *from,
75094 struct atm_aal_stats *to)
75095 {
75096 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75097 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75098 __AAL_STAT_ITEMS
75099 #undef __HANDLE_ITEM
75100 }
75101 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75102 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75103 struct atm_aal_stats *to)
75104 {
75105 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75106 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75107 __AAL_STAT_ITEMS
75108 #undef __HANDLE_ITEM
75109 }
75110 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75111 index dc53798..dc66333 100644
75112 --- a/net/batman-adv/bat_iv_ogm.c
75113 +++ b/net/batman-adv/bat_iv_ogm.c
75114 @@ -63,7 +63,7 @@ static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
75115
75116 /* randomize initial seqno to avoid collision */
75117 get_random_bytes(&random_seqno, sizeof(random_seqno));
75118 - atomic_set(&hard_iface->seqno, random_seqno);
75119 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
75120
75121 hard_iface->packet_len = BATMAN_OGM_HLEN;
75122 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
75123 @@ -572,7 +572,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75124
75125 /* change sequence number to network order */
75126 batman_ogm_packet->seqno =
75127 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
75128 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75129
75130 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
75131 batman_ogm_packet->tt_crc = htons((uint16_t)
75132 @@ -592,7 +592,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75133 else
75134 batman_ogm_packet->gw_flags = NO_FLAGS;
75135
75136 - atomic_inc(&hard_iface->seqno);
75137 + atomic_inc_unchecked(&hard_iface->seqno);
75138
75139 slide_own_bcast_window(hard_iface);
75140 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
75141 @@ -956,7 +956,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
75142 return;
75143
75144 /* could be changed by schedule_own_packet() */
75145 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
75146 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75147
75148 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
75149
75150 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
75151 index dc334fa..766a01a 100644
75152 --- a/net/batman-adv/hard-interface.c
75153 +++ b/net/batman-adv/hard-interface.c
75154 @@ -321,7 +321,7 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
75155 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75156 dev_add_pack(&hard_iface->batman_adv_ptype);
75157
75158 - atomic_set(&hard_iface->frag_seqno, 1);
75159 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75160 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
75161 hard_iface->net_dev->name);
75162
75163 @@ -444,7 +444,7 @@ static struct hard_iface *hardif_add_interface(struct net_device *net_dev)
75164 * This can't be called via a bat_priv callback because
75165 * we have no bat_priv yet.
75166 */
75167 - atomic_set(&hard_iface->seqno, 1);
75168 + atomic_set_unchecked(&hard_iface->seqno, 1);
75169 hard_iface->packet_buff = NULL;
75170
75171 return hard_iface;
75172 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75173 index a0ec0e4..7beb587 100644
75174 --- a/net/batman-adv/soft-interface.c
75175 +++ b/net/batman-adv/soft-interface.c
75176 @@ -214,7 +214,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
75177
75178 /* set broadcast sequence number */
75179 bcast_packet->seqno =
75180 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75181 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75182
75183 add_bcast_packet_to_list(bat_priv, skb, 1);
75184
75185 @@ -390,7 +390,7 @@ struct net_device *softif_create(const char *name)
75186 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
75187
75188 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
75189 - atomic_set(&bat_priv->bcast_seqno, 1);
75190 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75191 atomic_set(&bat_priv->ttvn, 0);
75192 atomic_set(&bat_priv->tt_local_changes, 0);
75193 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75194 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75195 index 61308e8..2e142b2 100644
75196 --- a/net/batman-adv/types.h
75197 +++ b/net/batman-adv/types.h
75198 @@ -38,8 +38,8 @@ struct hard_iface {
75199 int16_t if_num;
75200 char if_status;
75201 struct net_device *net_dev;
75202 - atomic_t seqno;
75203 - atomic_t frag_seqno;
75204 + atomic_unchecked_t seqno;
75205 + atomic_unchecked_t frag_seqno;
75206 unsigned char *packet_buff;
75207 int packet_len;
75208 struct kobject *hardif_obj;
75209 @@ -163,7 +163,7 @@ struct bat_priv {
75210 atomic_t orig_interval; /* uint */
75211 atomic_t hop_penalty; /* uint */
75212 atomic_t log_level; /* uint */
75213 - atomic_t bcast_seqno;
75214 + atomic_unchecked_t bcast_seqno;
75215 atomic_t bcast_queue_left;
75216 atomic_t batman_queue_left;
75217 atomic_t ttvn; /* translation table version number */
75218 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75219 index 74175c2..32f8901 100644
75220 --- a/net/batman-adv/unicast.c
75221 +++ b/net/batman-adv/unicast.c
75222 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
75223 frag1->flags = UNI_FRAG_HEAD | large_tail;
75224 frag2->flags = large_tail;
75225
75226 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75227 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75228 frag1->seqno = htons(seqno - 1);
75229 frag2->seqno = htons(seqno);
75230
75231 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
75232 index 4554e80..b778671 100644
75233 --- a/net/bluetooth/l2cap_core.c
75234 +++ b/net/bluetooth/l2cap_core.c
75235 @@ -2798,8 +2798,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
75236 break;
75237
75238 case L2CAP_CONF_RFC:
75239 - if (olen == sizeof(rfc))
75240 - memcpy(&rfc, (void *)val, olen);
75241 + if (olen != sizeof(rfc))
75242 + break;
75243 +
75244 + memcpy(&rfc, (void *)val, olen);
75245
75246 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
75247 rfc.mode != chan->mode)
75248 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
75249 index d1820ff..d414b0e 100644
75250 --- a/net/bluetooth/rfcomm/tty.c
75251 +++ b/net/bluetooth/rfcomm/tty.c
75252 @@ -314,7 +314,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
75253 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
75254
75255 spin_lock_irqsave(&dev->port.lock, flags);
75256 - if (dev->port.count > 0) {
75257 + if (atomic_read(&dev->port.count) > 0) {
75258 spin_unlock_irqrestore(&dev->port.lock, flags);
75259 return;
75260 }
75261 @@ -669,10 +669,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
75262 return -ENODEV;
75263
75264 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
75265 - dev->channel, dev->port.count);
75266 + dev->channel, atomic_read(&dev->port.count));
75267
75268 spin_lock_irqsave(&dev->port.lock, flags);
75269 - if (++dev->port.count > 1) {
75270 + if (atomic_inc_return(&dev->port.count) > 1) {
75271 spin_unlock_irqrestore(&dev->port.lock, flags);
75272 return 0;
75273 }
75274 @@ -737,10 +737,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
75275 return;
75276
75277 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
75278 - dev->port.count);
75279 + atomic_read(&dev->port.count));
75280
75281 spin_lock_irqsave(&dev->port.lock, flags);
75282 - if (!--dev->port.count) {
75283 + if (!atomic_dec_return(&dev->port.count)) {
75284 spin_unlock_irqrestore(&dev->port.lock, flags);
75285 if (dev->tty_dev->parent)
75286 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
75287 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
75288 index 5fe2ff3..10968b5 100644
75289 --- a/net/bridge/netfilter/ebtables.c
75290 +++ b/net/bridge/netfilter/ebtables.c
75291 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
75292 tmp.valid_hooks = t->table->valid_hooks;
75293 }
75294 mutex_unlock(&ebt_mutex);
75295 - if (copy_to_user(user, &tmp, *len) != 0){
75296 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
75297 BUGPRINT("c2u Didn't work\n");
75298 ret = -EFAULT;
75299 break;
75300 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
75301 index 047cd0e..461fd28 100644
75302 --- a/net/caif/cfctrl.c
75303 +++ b/net/caif/cfctrl.c
75304 @@ -10,6 +10,7 @@
75305 #include <linux/spinlock.h>
75306 #include <linux/slab.h>
75307 #include <linux/pkt_sched.h>
75308 +#include <linux/sched.h>
75309 #include <net/caif/caif_layer.h>
75310 #include <net/caif/cfpkt.h>
75311 #include <net/caif/cfctrl.h>
75312 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
75313 memset(&dev_info, 0, sizeof(dev_info));
75314 dev_info.id = 0xff;
75315 cfsrvl_init(&this->serv, 0, &dev_info, false);
75316 - atomic_set(&this->req_seq_no, 1);
75317 - atomic_set(&this->rsp_seq_no, 1);
75318 + atomic_set_unchecked(&this->req_seq_no, 1);
75319 + atomic_set_unchecked(&this->rsp_seq_no, 1);
75320 this->serv.layer.receive = cfctrl_recv;
75321 sprintf(this->serv.layer.name, "ctrl");
75322 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75323 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
75324 struct cfctrl_request_info *req)
75325 {
75326 spin_lock_bh(&ctrl->info_list_lock);
75327 - atomic_inc(&ctrl->req_seq_no);
75328 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
75329 + atomic_inc_unchecked(&ctrl->req_seq_no);
75330 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75331 list_add_tail(&req->list, &ctrl->list);
75332 spin_unlock_bh(&ctrl->info_list_lock);
75333 }
75334 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
75335 if (p != first)
75336 pr_warn("Requests are not received in order\n");
75337
75338 - atomic_set(&ctrl->rsp_seq_no,
75339 + atomic_set_unchecked(&ctrl->rsp_seq_no,
75340 p->sequence_no);
75341 list_del(&p->list);
75342 goto out;
75343 diff --git a/net/can/gw.c b/net/can/gw.c
75344 index b41acf2..3affb3a 100644
75345 --- a/net/can/gw.c
75346 +++ b/net/can/gw.c
75347 @@ -96,7 +96,7 @@ struct cf_mod {
75348 struct {
75349 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
75350 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
75351 - } csumfunc;
75352 + } __no_const csumfunc;
75353 };
75354
75355
75356 diff --git a/net/compat.c b/net/compat.c
75357 index 74ed1d7..62f7ea6 100644
75358 --- a/net/compat.c
75359 +++ b/net/compat.c
75360 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
75361 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
75362 __get_user(kmsg->msg_flags, &umsg->msg_flags))
75363 return -EFAULT;
75364 - kmsg->msg_name = compat_ptr(tmp1);
75365 - kmsg->msg_iov = compat_ptr(tmp2);
75366 - kmsg->msg_control = compat_ptr(tmp3);
75367 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
75368 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
75369 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
75370 return 0;
75371 }
75372
75373 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75374
75375 if (kern_msg->msg_namelen) {
75376 if (mode == VERIFY_READ) {
75377 - int err = move_addr_to_kernel(kern_msg->msg_name,
75378 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
75379 kern_msg->msg_namelen,
75380 kern_address);
75381 if (err < 0)
75382 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75383 kern_msg->msg_name = NULL;
75384
75385 tot_len = iov_from_user_compat_to_kern(kern_iov,
75386 - (struct compat_iovec __user *)kern_msg->msg_iov,
75387 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
75388 kern_msg->msg_iovlen);
75389 if (tot_len >= 0)
75390 kern_msg->msg_iov = kern_iov;
75391 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75392
75393 #define CMSG_COMPAT_FIRSTHDR(msg) \
75394 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
75395 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
75396 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
75397 (struct compat_cmsghdr __user *)NULL)
75398
75399 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
75400 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
75401 (ucmlen) <= (unsigned long) \
75402 ((mhdr)->msg_controllen - \
75403 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
75404 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
75405
75406 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
75407 struct compat_cmsghdr __user *cmsg, int cmsg_len)
75408 {
75409 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
75410 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
75411 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
75412 msg->msg_controllen)
75413 return NULL;
75414 return (struct compat_cmsghdr __user *)ptr;
75415 @@ -219,7 +219,7 @@ Efault:
75416
75417 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
75418 {
75419 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75420 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75421 struct compat_cmsghdr cmhdr;
75422 struct compat_timeval ctv;
75423 struct compat_timespec cts[3];
75424 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75425
75426 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
75427 {
75428 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75429 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75430 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
75431 int fdnum = scm->fp->count;
75432 struct file **fp = scm->fp->fp;
75433 @@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
75434 return -EFAULT;
75435 old_fs = get_fs();
75436 set_fs(KERNEL_DS);
75437 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
75438 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
75439 set_fs(old_fs);
75440
75441 return err;
75442 @@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
75443 len = sizeof(ktime);
75444 old_fs = get_fs();
75445 set_fs(KERNEL_DS);
75446 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
75447 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
75448 set_fs(old_fs);
75449
75450 if (!err) {
75451 @@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75452 case MCAST_JOIN_GROUP:
75453 case MCAST_LEAVE_GROUP:
75454 {
75455 - struct compat_group_req __user *gr32 = (void *)optval;
75456 + struct compat_group_req __user *gr32 = (void __user *)optval;
75457 struct group_req __user *kgr =
75458 compat_alloc_user_space(sizeof(struct group_req));
75459 u32 interface;
75460 @@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75461 case MCAST_BLOCK_SOURCE:
75462 case MCAST_UNBLOCK_SOURCE:
75463 {
75464 - struct compat_group_source_req __user *gsr32 = (void *)optval;
75465 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
75466 struct group_source_req __user *kgsr = compat_alloc_user_space(
75467 sizeof(struct group_source_req));
75468 u32 interface;
75469 @@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75470 }
75471 case MCAST_MSFILTER:
75472 {
75473 - struct compat_group_filter __user *gf32 = (void *)optval;
75474 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75475 struct group_filter __user *kgf;
75476 u32 interface, fmode, numsrc;
75477
75478 @@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
75479 char __user *optval, int __user *optlen,
75480 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
75481 {
75482 - struct compat_group_filter __user *gf32 = (void *)optval;
75483 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75484 struct group_filter __user *kgf;
75485 int __user *koptlen;
75486 u32 interface, fmode, numsrc;
75487 diff --git a/net/core/datagram.c b/net/core/datagram.c
75488 index ae6acf6..d5c8f66 100644
75489 --- a/net/core/datagram.c
75490 +++ b/net/core/datagram.c
75491 @@ -290,7 +290,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
75492 }
75493
75494 kfree_skb(skb);
75495 - atomic_inc(&sk->sk_drops);
75496 + atomic_inc_unchecked(&sk->sk_drops);
75497 sk_mem_reclaim_partial(sk);
75498
75499 return err;
75500 diff --git a/net/core/dev.c b/net/core/dev.c
75501 index 1cb0d8a..0427dd9 100644
75502 --- a/net/core/dev.c
75503 +++ b/net/core/dev.c
75504 @@ -1135,9 +1135,13 @@ void dev_load(struct net *net, const char *name)
75505 if (no_module && capable(CAP_NET_ADMIN))
75506 no_module = request_module("netdev-%s", name);
75507 if (no_module && capable(CAP_SYS_MODULE)) {
75508 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
75509 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
75510 +#else
75511 if (!request_module("%s", name))
75512 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
75513 name);
75514 +#endif
75515 }
75516 }
75517 EXPORT_SYMBOL(dev_load);
75518 @@ -1601,7 +1605,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75519 {
75520 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
75521 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
75522 - atomic_long_inc(&dev->rx_dropped);
75523 + atomic_long_inc_unchecked(&dev->rx_dropped);
75524 kfree_skb(skb);
75525 return NET_RX_DROP;
75526 }
75527 @@ -1611,7 +1615,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75528 nf_reset(skb);
75529
75530 if (unlikely(!is_skb_forwardable(dev, skb))) {
75531 - atomic_long_inc(&dev->rx_dropped);
75532 + atomic_long_inc_unchecked(&dev->rx_dropped);
75533 kfree_skb(skb);
75534 return NET_RX_DROP;
75535 }
75536 @@ -2040,7 +2044,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
75537
75538 struct dev_gso_cb {
75539 void (*destructor)(struct sk_buff *skb);
75540 -};
75541 +} __no_const;
75542
75543 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75544
75545 @@ -2875,7 +2879,7 @@ enqueue:
75546
75547 local_irq_restore(flags);
75548
75549 - atomic_long_inc(&skb->dev->rx_dropped);
75550 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75551 kfree_skb(skb);
75552 return NET_RX_DROP;
75553 }
75554 @@ -2947,7 +2951,7 @@ int netif_rx_ni(struct sk_buff *skb)
75555 }
75556 EXPORT_SYMBOL(netif_rx_ni);
75557
75558 -static void net_tx_action(struct softirq_action *h)
75559 +static void net_tx_action(void)
75560 {
75561 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75562
75563 @@ -3234,7 +3238,7 @@ ncls:
75564 if (pt_prev) {
75565 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
75566 } else {
75567 - atomic_long_inc(&skb->dev->rx_dropped);
75568 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75569 kfree_skb(skb);
75570 /* Jamal, now you will not able to escape explaining
75571 * me how you were going to use this. :-)
75572 @@ -3799,7 +3803,7 @@ void netif_napi_del(struct napi_struct *napi)
75573 }
75574 EXPORT_SYMBOL(netif_napi_del);
75575
75576 -static void net_rx_action(struct softirq_action *h)
75577 +static void net_rx_action(void)
75578 {
75579 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75580 unsigned long time_limit = jiffies + 2;
75581 @@ -4269,8 +4273,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
75582 else
75583 seq_printf(seq, "%04x", ntohs(pt->type));
75584
75585 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75586 + seq_printf(seq, " %-8s %p\n",
75587 + pt->dev ? pt->dev->name : "", NULL);
75588 +#else
75589 seq_printf(seq, " %-8s %pF\n",
75590 pt->dev ? pt->dev->name : "", pt->func);
75591 +#endif
75592 }
75593
75594 return 0;
75595 @@ -5820,7 +5829,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75596 } else {
75597 netdev_stats_to_stats64(storage, &dev->stats);
75598 }
75599 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75600 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75601 return storage;
75602 }
75603 EXPORT_SYMBOL(dev_get_stats);
75604 diff --git a/net/core/flow.c b/net/core/flow.c
75605 index e318c7e..168b1d0 100644
75606 --- a/net/core/flow.c
75607 +++ b/net/core/flow.c
75608 @@ -61,7 +61,7 @@ struct flow_cache {
75609 struct timer_list rnd_timer;
75610 };
75611
75612 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
75613 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75614 EXPORT_SYMBOL(flow_cache_genid);
75615 static struct flow_cache flow_cache_global;
75616 static struct kmem_cache *flow_cachep __read_mostly;
75617 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75618
75619 static int flow_entry_valid(struct flow_cache_entry *fle)
75620 {
75621 - if (atomic_read(&flow_cache_genid) != fle->genid)
75622 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75623 return 0;
75624 if (fle->object && !fle->object->ops->check(fle->object))
75625 return 0;
75626 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75627 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75628 fcp->hash_count++;
75629 }
75630 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75631 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75632 flo = fle->object;
75633 if (!flo)
75634 goto ret_object;
75635 @@ -280,7 +280,7 @@ nocache:
75636 }
75637 flo = resolver(net, key, family, dir, flo, ctx);
75638 if (fle) {
75639 - fle->genid = atomic_read(&flow_cache_genid);
75640 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
75641 if (!IS_ERR(flo))
75642 fle->object = flo;
75643 else
75644 diff --git a/net/core/iovec.c b/net/core/iovec.c
75645 index 7e7aeb0..2a998cb 100644
75646 --- a/net/core/iovec.c
75647 +++ b/net/core/iovec.c
75648 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75649 if (m->msg_namelen) {
75650 if (mode == VERIFY_READ) {
75651 void __user *namep;
75652 - namep = (void __user __force *) m->msg_name;
75653 + namep = (void __force_user *) m->msg_name;
75654 err = move_addr_to_kernel(namep, m->msg_namelen,
75655 address);
75656 if (err < 0)
75657 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75658 }
75659
75660 size = m->msg_iovlen * sizeof(struct iovec);
75661 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75662 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75663 return -EFAULT;
75664
75665 m->msg_iov = iov;
75666 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75667 index 23e3f66..f78041f 100644
75668 --- a/net/core/rtnetlink.c
75669 +++ b/net/core/rtnetlink.c
75670 @@ -58,7 +58,7 @@ struct rtnl_link {
75671 rtnl_doit_func doit;
75672 rtnl_dumpit_func dumpit;
75673 rtnl_calcit_func calcit;
75674 -};
75675 +} __no_const;
75676
75677 static DEFINE_MUTEX(rtnl_mutex);
75678
75679 diff --git a/net/core/scm.c b/net/core/scm.c
75680 index 611c5ef..88f6d6d 100644
75681 --- a/net/core/scm.c
75682 +++ b/net/core/scm.c
75683 @@ -219,7 +219,7 @@ EXPORT_SYMBOL(__scm_send);
75684 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75685 {
75686 struct cmsghdr __user *cm
75687 - = (__force struct cmsghdr __user *)msg->msg_control;
75688 + = (struct cmsghdr __force_user *)msg->msg_control;
75689 struct cmsghdr cmhdr;
75690 int cmlen = CMSG_LEN(len);
75691 int err;
75692 @@ -242,7 +242,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75693 err = -EFAULT;
75694 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75695 goto out;
75696 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75697 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75698 goto out;
75699 cmlen = CMSG_SPACE(len);
75700 if (msg->msg_controllen < cmlen)
75701 @@ -258,7 +258,7 @@ EXPORT_SYMBOL(put_cmsg);
75702 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75703 {
75704 struct cmsghdr __user *cm
75705 - = (__force struct cmsghdr __user*)msg->msg_control;
75706 + = (struct cmsghdr __force_user *)msg->msg_control;
75707
75708 int fdmax = 0;
75709 int fdnum = scm->fp->count;
75710 @@ -278,7 +278,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75711 if (fdnum < fdmax)
75712 fdmax = fdnum;
75713
75714 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75715 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75716 i++, cmfptr++)
75717 {
75718 int new_fd;
75719 diff --git a/net/core/sock.c b/net/core/sock.c
75720 index 9e5b71f..66dec30 100644
75721 --- a/net/core/sock.c
75722 +++ b/net/core/sock.c
75723 @@ -344,7 +344,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75724 struct sk_buff_head *list = &sk->sk_receive_queue;
75725
75726 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
75727 - atomic_inc(&sk->sk_drops);
75728 + atomic_inc_unchecked(&sk->sk_drops);
75729 trace_sock_rcvqueue_full(sk, skb);
75730 return -ENOMEM;
75731 }
75732 @@ -354,7 +354,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75733 return err;
75734
75735 if (!sk_rmem_schedule(sk, skb->truesize)) {
75736 - atomic_inc(&sk->sk_drops);
75737 + atomic_inc_unchecked(&sk->sk_drops);
75738 return -ENOBUFS;
75739 }
75740
75741 @@ -374,7 +374,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75742 skb_dst_force(skb);
75743
75744 spin_lock_irqsave(&list->lock, flags);
75745 - skb->dropcount = atomic_read(&sk->sk_drops);
75746 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75747 __skb_queue_tail(list, skb);
75748 spin_unlock_irqrestore(&list->lock, flags);
75749
75750 @@ -394,7 +394,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75751 skb->dev = NULL;
75752
75753 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
75754 - atomic_inc(&sk->sk_drops);
75755 + atomic_inc_unchecked(&sk->sk_drops);
75756 goto discard_and_relse;
75757 }
75758 if (nested)
75759 @@ -412,7 +412,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75760 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75761 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
75762 bh_unlock_sock(sk);
75763 - atomic_inc(&sk->sk_drops);
75764 + atomic_inc_unchecked(&sk->sk_drops);
75765 goto discard_and_relse;
75766 }
75767
75768 @@ -976,7 +976,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75769 if (len > sizeof(peercred))
75770 len = sizeof(peercred);
75771 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
75772 - if (copy_to_user(optval, &peercred, len))
75773 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
75774 return -EFAULT;
75775 goto lenout;
75776 }
75777 @@ -989,7 +989,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75778 return -ENOTCONN;
75779 if (lv < len)
75780 return -EINVAL;
75781 - if (copy_to_user(optval, address, len))
75782 + if (len > sizeof(address) || copy_to_user(optval, address, len))
75783 return -EFAULT;
75784 goto lenout;
75785 }
75786 @@ -1035,7 +1035,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75787
75788 if (len > lv)
75789 len = lv;
75790 - if (copy_to_user(optval, &v, len))
75791 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
75792 return -EFAULT;
75793 lenout:
75794 if (put_user(len, optlen))
75795 @@ -2124,7 +2124,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
75796 */
75797 smp_wmb();
75798 atomic_set(&sk->sk_refcnt, 1);
75799 - atomic_set(&sk->sk_drops, 0);
75800 + atomic_set_unchecked(&sk->sk_drops, 0);
75801 }
75802 EXPORT_SYMBOL(sock_init_data);
75803
75804 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
75805 index 5fd1467..8b70900 100644
75806 --- a/net/core/sock_diag.c
75807 +++ b/net/core/sock_diag.c
75808 @@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
75809
75810 int sock_diag_check_cookie(void *sk, __u32 *cookie)
75811 {
75812 +#ifndef CONFIG_GRKERNSEC_HIDESYM
75813 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
75814 cookie[1] != INET_DIAG_NOCOOKIE) &&
75815 ((u32)(unsigned long)sk != cookie[0] ||
75816 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
75817 return -ESTALE;
75818 else
75819 +#endif
75820 return 0;
75821 }
75822 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
75823
75824 void sock_diag_save_cookie(void *sk, __u32 *cookie)
75825 {
75826 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75827 + cookie[0] = 0;
75828 + cookie[1] = 0;
75829 +#else
75830 cookie[0] = (u32)(unsigned long)sk;
75831 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
75832 +#endif
75833 }
75834 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
75835
75836 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
75837 index a55eecc..dd8428c 100644
75838 --- a/net/decnet/sysctl_net_decnet.c
75839 +++ b/net/decnet/sysctl_net_decnet.c
75840 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
75841
75842 if (len > *lenp) len = *lenp;
75843
75844 - if (copy_to_user(buffer, addr, len))
75845 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
75846 return -EFAULT;
75847
75848 *lenp = len;
75849 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
75850
75851 if (len > *lenp) len = *lenp;
75852
75853 - if (copy_to_user(buffer, devname, len))
75854 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
75855 return -EFAULT;
75856
75857 *lenp = len;
75858 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
75859 index 3854411..2201a94 100644
75860 --- a/net/ipv4/fib_frontend.c
75861 +++ b/net/ipv4/fib_frontend.c
75862 @@ -969,12 +969,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
75863 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75864 fib_sync_up(dev);
75865 #endif
75866 - atomic_inc(&net->ipv4.dev_addr_genid);
75867 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75868 rt_cache_flush(dev_net(dev), -1);
75869 break;
75870 case NETDEV_DOWN:
75871 fib_del_ifaddr(ifa, NULL);
75872 - atomic_inc(&net->ipv4.dev_addr_genid);
75873 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75874 if (ifa->ifa_dev->ifa_list == NULL) {
75875 /* Last address was deleted from this interface.
75876 * Disable IP.
75877 @@ -1010,7 +1010,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
75878 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75879 fib_sync_up(dev);
75880 #endif
75881 - atomic_inc(&net->ipv4.dev_addr_genid);
75882 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75883 rt_cache_flush(dev_net(dev), -1);
75884 break;
75885 case NETDEV_DOWN:
75886 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
75887 index e5b7182..570a90e 100644
75888 --- a/net/ipv4/fib_semantics.c
75889 +++ b/net/ipv4/fib_semantics.c
75890 @@ -698,7 +698,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
75891 nh->nh_saddr = inet_select_addr(nh->nh_dev,
75892 nh->nh_gw,
75893 nh->nh_parent->fib_scope);
75894 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
75895 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
75896
75897 return nh->nh_saddr;
75898 }
75899 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
75900 index 7880af9..70f92a3 100644
75901 --- a/net/ipv4/inet_hashtables.c
75902 +++ b/net/ipv4/inet_hashtables.c
75903 @@ -18,12 +18,15 @@
75904 #include <linux/sched.h>
75905 #include <linux/slab.h>
75906 #include <linux/wait.h>
75907 +#include <linux/security.h>
75908
75909 #include <net/inet_connection_sock.h>
75910 #include <net/inet_hashtables.h>
75911 #include <net/secure_seq.h>
75912 #include <net/ip.h>
75913
75914 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
75915 +
75916 /*
75917 * Allocate and initialize a new local port bind bucket.
75918 * The bindhash mutex for snum's hash chain must be held here.
75919 @@ -530,6 +533,8 @@ ok:
75920 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
75921 spin_unlock(&head->lock);
75922
75923 + gr_update_task_in_ip_table(current, inet_sk(sk));
75924 +
75925 if (tw) {
75926 inet_twsk_deschedule(tw, death_row);
75927 while (twrefcnt) {
75928 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
75929 index dfba343..c827d50 100644
75930 --- a/net/ipv4/inetpeer.c
75931 +++ b/net/ipv4/inetpeer.c
75932 @@ -487,8 +487,8 @@ relookup:
75933 if (p) {
75934 p->daddr = *daddr;
75935 atomic_set(&p->refcnt, 1);
75936 - atomic_set(&p->rid, 0);
75937 - atomic_set(&p->ip_id_count,
75938 + atomic_set_unchecked(&p->rid, 0);
75939 + atomic_set_unchecked(&p->ip_id_count,
75940 (daddr->family == AF_INET) ?
75941 secure_ip_id(daddr->addr.a4) :
75942 secure_ipv6_id(daddr->addr.a6));
75943 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
75944 index 9dbd3dd..0c59fb2 100644
75945 --- a/net/ipv4/ip_fragment.c
75946 +++ b/net/ipv4/ip_fragment.c
75947 @@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
75948 return 0;
75949
75950 start = qp->rid;
75951 - end = atomic_inc_return(&peer->rid);
75952 + end = atomic_inc_return_unchecked(&peer->rid);
75953 qp->rid = end;
75954
75955 rc = qp->q.fragments && (end - start) > max;
75956 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
75957 index 0d11f23..2bb3f64 100644
75958 --- a/net/ipv4/ip_sockglue.c
75959 +++ b/net/ipv4/ip_sockglue.c
75960 @@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75961 len = min_t(unsigned int, len, opt->optlen);
75962 if (put_user(len, optlen))
75963 return -EFAULT;
75964 - if (copy_to_user(optval, opt->__data, len))
75965 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
75966 + copy_to_user(optval, opt->__data, len))
75967 return -EFAULT;
75968 return 0;
75969 }
75970 @@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75971 if (sk->sk_type != SOCK_STREAM)
75972 return -ENOPROTOOPT;
75973
75974 - msg.msg_control = optval;
75975 + msg.msg_control = (void __force_kernel *)optval;
75976 msg.msg_controllen = len;
75977 msg.msg_flags = flags;
75978
75979 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
75980 index 67e8a6b..386764d 100644
75981 --- a/net/ipv4/ipconfig.c
75982 +++ b/net/ipv4/ipconfig.c
75983 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
75984
75985 mm_segment_t oldfs = get_fs();
75986 set_fs(get_ds());
75987 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75988 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75989 set_fs(oldfs);
75990 return res;
75991 }
75992 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
75993
75994 mm_segment_t oldfs = get_fs();
75995 set_fs(get_ds());
75996 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75997 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75998 set_fs(oldfs);
75999 return res;
76000 }
76001 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
76002
76003 mm_segment_t oldfs = get_fs();
76004 set_fs(get_ds());
76005 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
76006 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
76007 set_fs(oldfs);
76008 return res;
76009 }
76010 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
76011 index 2c00e8b..45b3bdd 100644
76012 --- a/net/ipv4/ping.c
76013 +++ b/net/ipv4/ping.c
76014 @@ -845,7 +845,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
76015 sk_rmem_alloc_get(sp),
76016 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76017 atomic_read(&sp->sk_refcnt), sp,
76018 - atomic_read(&sp->sk_drops), len);
76019 + atomic_read_unchecked(&sp->sk_drops), len);
76020 }
76021
76022 static int ping_seq_show(struct seq_file *seq, void *v)
76023 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
76024 index 4032b81..625143c 100644
76025 --- a/net/ipv4/raw.c
76026 +++ b/net/ipv4/raw.c
76027 @@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
76028 int raw_rcv(struct sock *sk, struct sk_buff *skb)
76029 {
76030 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
76031 - atomic_inc(&sk->sk_drops);
76032 + atomic_inc_unchecked(&sk->sk_drops);
76033 kfree_skb(skb);
76034 return NET_RX_DROP;
76035 }
76036 @@ -740,16 +740,20 @@ static int raw_init(struct sock *sk)
76037
76038 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76039 {
76040 + struct icmp_filter filter;
76041 +
76042 if (optlen > sizeof(struct icmp_filter))
76043 optlen = sizeof(struct icmp_filter);
76044 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
76045 + if (copy_from_user(&filter, optval, optlen))
76046 return -EFAULT;
76047 + raw_sk(sk)->filter = filter;
76048 return 0;
76049 }
76050
76051 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76052 {
76053 int len, ret = -EFAULT;
76054 + struct icmp_filter filter;
76055
76056 if (get_user(len, optlen))
76057 goto out;
76058 @@ -759,8 +763,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
76059 if (len > sizeof(struct icmp_filter))
76060 len = sizeof(struct icmp_filter);
76061 ret = -EFAULT;
76062 - if (put_user(len, optlen) ||
76063 - copy_to_user(optval, &raw_sk(sk)->filter, len))
76064 + filter = raw_sk(sk)->filter;
76065 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
76066 goto out;
76067 ret = 0;
76068 out: return ret;
76069 @@ -988,7 +992,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76070 sk_wmem_alloc_get(sp),
76071 sk_rmem_alloc_get(sp),
76072 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76073 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76074 + atomic_read(&sp->sk_refcnt),
76075 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76076 + NULL,
76077 +#else
76078 + sp,
76079 +#endif
76080 + atomic_read_unchecked(&sp->sk_drops));
76081 }
76082
76083 static int raw_seq_show(struct seq_file *seq, void *v)
76084 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
76085 index 98b30d0..cfa3cf7 100644
76086 --- a/net/ipv4/route.c
76087 +++ b/net/ipv4/route.c
76088 @@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
76089
76090 static inline int rt_genid(struct net *net)
76091 {
76092 - return atomic_read(&net->ipv4.rt_genid);
76093 + return atomic_read_unchecked(&net->ipv4.rt_genid);
76094 }
76095
76096 #ifdef CONFIG_PROC_FS
76097 @@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
76098 unsigned char shuffle;
76099
76100 get_random_bytes(&shuffle, sizeof(shuffle));
76101 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76102 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76103 inetpeer_invalidate_tree(AF_INET);
76104 }
76105
76106 @@ -3011,7 +3011,7 @@ static int rt_fill_info(struct net *net,
76107 error = rt->dst.error;
76108 if (peer) {
76109 inet_peer_refcheck(rt->peer);
76110 - id = atomic_read(&peer->ip_id_count) & 0xffff;
76111 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
76112 if (peer->tcp_ts_stamp) {
76113 ts = peer->tcp_ts;
76114 tsage = get_seconds() - peer->tcp_ts_stamp;
76115 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
76116 index c8d28c4..e40f75a 100644
76117 --- a/net/ipv4/tcp_ipv4.c
76118 +++ b/net/ipv4/tcp_ipv4.c
76119 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
76120 EXPORT_SYMBOL(sysctl_tcp_low_latency);
76121
76122
76123 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76124 +extern int grsec_enable_blackhole;
76125 +#endif
76126 +
76127 #ifdef CONFIG_TCP_MD5SIG
76128 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
76129 __be32 daddr, __be32 saddr, const struct tcphdr *th);
76130 @@ -1656,6 +1660,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
76131 return 0;
76132
76133 reset:
76134 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76135 + if (!grsec_enable_blackhole)
76136 +#endif
76137 tcp_v4_send_reset(rsk, skb);
76138 discard:
76139 kfree_skb(skb);
76140 @@ -1718,12 +1725,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
76141 TCP_SKB_CB(skb)->sacked = 0;
76142
76143 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76144 - if (!sk)
76145 + if (!sk) {
76146 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76147 + ret = 1;
76148 +#endif
76149 goto no_tcp_socket;
76150 -
76151 + }
76152 process:
76153 - if (sk->sk_state == TCP_TIME_WAIT)
76154 + if (sk->sk_state == TCP_TIME_WAIT) {
76155 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76156 + ret = 2;
76157 +#endif
76158 goto do_time_wait;
76159 + }
76160
76161 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
76162 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76163 @@ -1774,6 +1788,10 @@ no_tcp_socket:
76164 bad_packet:
76165 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76166 } else {
76167 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76168 + if (!grsec_enable_blackhole || (ret == 1 &&
76169 + (skb->dev->flags & IFF_LOOPBACK)))
76170 +#endif
76171 tcp_v4_send_reset(NULL, skb);
76172 }
76173
76174 @@ -2386,7 +2404,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
76175 0, /* non standard timer */
76176 0, /* open_requests have no inode */
76177 atomic_read(&sk->sk_refcnt),
76178 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76179 + NULL,
76180 +#else
76181 req,
76182 +#endif
76183 len);
76184 }
76185
76186 @@ -2436,7 +2458,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
76187 sock_i_uid(sk),
76188 icsk->icsk_probes_out,
76189 sock_i_ino(sk),
76190 - atomic_read(&sk->sk_refcnt), sk,
76191 + atomic_read(&sk->sk_refcnt),
76192 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76193 + NULL,
76194 +#else
76195 + sk,
76196 +#endif
76197 jiffies_to_clock_t(icsk->icsk_rto),
76198 jiffies_to_clock_t(icsk->icsk_ack.ato),
76199 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76200 @@ -2464,7 +2491,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
76201 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
76202 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76203 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76204 - atomic_read(&tw->tw_refcnt), tw, len);
76205 + atomic_read(&tw->tw_refcnt),
76206 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76207 + NULL,
76208 +#else
76209 + tw,
76210 +#endif
76211 + len);
76212 }
76213
76214 #define TMPSZ 150
76215 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
76216 index b85d9fe..4b0eed9 100644
76217 --- a/net/ipv4/tcp_minisocks.c
76218 +++ b/net/ipv4/tcp_minisocks.c
76219 @@ -27,6 +27,10 @@
76220 #include <net/inet_common.h>
76221 #include <net/xfrm.h>
76222
76223 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76224 +extern int grsec_enable_blackhole;
76225 +#endif
76226 +
76227 int sysctl_tcp_syncookies __read_mostly = 1;
76228 EXPORT_SYMBOL(sysctl_tcp_syncookies);
76229
76230 @@ -754,6 +758,10 @@ listen_overflow:
76231
76232 embryonic_reset:
76233 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76234 +
76235 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76236 + if (!grsec_enable_blackhole)
76237 +#endif
76238 if (!(flg & TCP_FLAG_RST))
76239 req->rsk_ops->send_reset(sk, skb);
76240
76241 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
76242 index 4526fe6..1a34e43 100644
76243 --- a/net/ipv4/tcp_probe.c
76244 +++ b/net/ipv4/tcp_probe.c
76245 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
76246 if (cnt + width >= len)
76247 break;
76248
76249 - if (copy_to_user(buf + cnt, tbuf, width))
76250 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76251 return -EFAULT;
76252 cnt += width;
76253 }
76254 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
76255 index e911e6c..d0a9356 100644
76256 --- a/net/ipv4/tcp_timer.c
76257 +++ b/net/ipv4/tcp_timer.c
76258 @@ -22,6 +22,10 @@
76259 #include <linux/gfp.h>
76260 #include <net/tcp.h>
76261
76262 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76263 +extern int grsec_lastack_retries;
76264 +#endif
76265 +
76266 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76267 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76268 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76269 @@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
76270 }
76271 }
76272
76273 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76274 + if ((sk->sk_state == TCP_LAST_ACK) &&
76275 + (grsec_lastack_retries > 0) &&
76276 + (grsec_lastack_retries < retry_until))
76277 + retry_until = grsec_lastack_retries;
76278 +#endif
76279 +
76280 if (retransmits_timed_out(sk, retry_until,
76281 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
76282 /* Has it gone just too far? */
76283 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
76284 index eaca736..60488ae 100644
76285 --- a/net/ipv4/udp.c
76286 +++ b/net/ipv4/udp.c
76287 @@ -87,6 +87,7 @@
76288 #include <linux/types.h>
76289 #include <linux/fcntl.h>
76290 #include <linux/module.h>
76291 +#include <linux/security.h>
76292 #include <linux/socket.h>
76293 #include <linux/sockios.h>
76294 #include <linux/igmp.h>
76295 @@ -110,6 +111,10 @@
76296 #include <linux/static_key.h>
76297 #include "udp_impl.h"
76298
76299 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76300 +extern int grsec_enable_blackhole;
76301 +#endif
76302 +
76303 struct udp_table udp_table __read_mostly;
76304 EXPORT_SYMBOL(udp_table);
76305
76306 @@ -568,6 +573,9 @@ found:
76307 return s;
76308 }
76309
76310 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76311 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76312 +
76313 /*
76314 * This routine is called by the ICMP module when it gets some
76315 * sort of error condition. If err < 0 then the socket should
76316 @@ -859,9 +867,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
76317 dport = usin->sin_port;
76318 if (dport == 0)
76319 return -EINVAL;
76320 +
76321 + err = gr_search_udp_sendmsg(sk, usin);
76322 + if (err)
76323 + return err;
76324 } else {
76325 if (sk->sk_state != TCP_ESTABLISHED)
76326 return -EDESTADDRREQ;
76327 +
76328 + err = gr_search_udp_sendmsg(sk, NULL);
76329 + if (err)
76330 + return err;
76331 +
76332 daddr = inet->inet_daddr;
76333 dport = inet->inet_dport;
76334 /* Open fast path for connected socket.
76335 @@ -1103,7 +1120,7 @@ static unsigned int first_packet_length(struct sock *sk)
76336 udp_lib_checksum_complete(skb)) {
76337 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76338 IS_UDPLITE(sk));
76339 - atomic_inc(&sk->sk_drops);
76340 + atomic_inc_unchecked(&sk->sk_drops);
76341 __skb_unlink(skb, rcvq);
76342 __skb_queue_tail(&list_kill, skb);
76343 }
76344 @@ -1189,6 +1206,10 @@ try_again:
76345 if (!skb)
76346 goto out;
76347
76348 + err = gr_search_udp_recvmsg(sk, skb);
76349 + if (err)
76350 + goto out_free;
76351 +
76352 ulen = skb->len - sizeof(struct udphdr);
76353 copied = len;
76354 if (copied > ulen)
76355 @@ -1498,7 +1519,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76356
76357 drop:
76358 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76359 - atomic_inc(&sk->sk_drops);
76360 + atomic_inc_unchecked(&sk->sk_drops);
76361 kfree_skb(skb);
76362 return -1;
76363 }
76364 @@ -1517,7 +1538,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76365 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76366
76367 if (!skb1) {
76368 - atomic_inc(&sk->sk_drops);
76369 + atomic_inc_unchecked(&sk->sk_drops);
76370 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76371 IS_UDPLITE(sk));
76372 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76373 @@ -1686,6 +1707,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76374 goto csum_error;
76375
76376 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76377 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76378 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76379 +#endif
76380 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76381
76382 /*
76383 @@ -2104,8 +2128,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
76384 sk_wmem_alloc_get(sp),
76385 sk_rmem_alloc_get(sp),
76386 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76387 - atomic_read(&sp->sk_refcnt), sp,
76388 - atomic_read(&sp->sk_drops), len);
76389 + atomic_read(&sp->sk_refcnt),
76390 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76391 + NULL,
76392 +#else
76393 + sp,
76394 +#endif
76395 + atomic_read_unchecked(&sp->sk_drops), len);
76396 }
76397
76398 int udp4_seq_show(struct seq_file *seq, void *v)
76399 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
76400 index 8f6411c..5767579 100644
76401 --- a/net/ipv6/addrconf.c
76402 +++ b/net/ipv6/addrconf.c
76403 @@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
76404 p.iph.ihl = 5;
76405 p.iph.protocol = IPPROTO_IPV6;
76406 p.iph.ttl = 64;
76407 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
76408 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
76409
76410 if (ops->ndo_do_ioctl) {
76411 mm_segment_t oldfs = get_fs();
76412 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
76413 index e6cee52..cf47476 100644
76414 --- a/net/ipv6/inet6_connection_sock.c
76415 +++ b/net/ipv6/inet6_connection_sock.c
76416 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
76417 #ifdef CONFIG_XFRM
76418 {
76419 struct rt6_info *rt = (struct rt6_info *)dst;
76420 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76421 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76422 }
76423 #endif
76424 }
76425 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
76426 #ifdef CONFIG_XFRM
76427 if (dst) {
76428 struct rt6_info *rt = (struct rt6_info *)dst;
76429 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76430 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76431 __sk_dst_reset(sk);
76432 dst = NULL;
76433 }
76434 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
76435 index ba6d13d..6899122 100644
76436 --- a/net/ipv6/ipv6_sockglue.c
76437 +++ b/net/ipv6/ipv6_sockglue.c
76438 @@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76439 if (sk->sk_type != SOCK_STREAM)
76440 return -ENOPROTOOPT;
76441
76442 - msg.msg_control = optval;
76443 + msg.msg_control = (void __force_kernel *)optval;
76444 msg.msg_controllen = len;
76445 msg.msg_flags = flags;
76446
76447 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76448 index 93d6983..8e54c4d 100644
76449 --- a/net/ipv6/raw.c
76450 +++ b/net/ipv6/raw.c
76451 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
76452 {
76453 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
76454 skb_checksum_complete(skb)) {
76455 - atomic_inc(&sk->sk_drops);
76456 + atomic_inc_unchecked(&sk->sk_drops);
76457 kfree_skb(skb);
76458 return NET_RX_DROP;
76459 }
76460 @@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76461 struct raw6_sock *rp = raw6_sk(sk);
76462
76463 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76464 - atomic_inc(&sk->sk_drops);
76465 + atomic_inc_unchecked(&sk->sk_drops);
76466 kfree_skb(skb);
76467 return NET_RX_DROP;
76468 }
76469 @@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76470
76471 if (inet->hdrincl) {
76472 if (skb_checksum_complete(skb)) {
76473 - atomic_inc(&sk->sk_drops);
76474 + atomic_inc_unchecked(&sk->sk_drops);
76475 kfree_skb(skb);
76476 return NET_RX_DROP;
76477 }
76478 @@ -602,7 +602,7 @@ out:
76479 return err;
76480 }
76481
76482 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76483 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76484 struct flowi6 *fl6, struct dst_entry **dstp,
76485 unsigned int flags)
76486 {
76487 @@ -914,12 +914,15 @@ do_confirm:
76488 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76489 char __user *optval, int optlen)
76490 {
76491 + struct icmp6_filter filter;
76492 +
76493 switch (optname) {
76494 case ICMPV6_FILTER:
76495 if (optlen > sizeof(struct icmp6_filter))
76496 optlen = sizeof(struct icmp6_filter);
76497 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76498 + if (copy_from_user(&filter, optval, optlen))
76499 return -EFAULT;
76500 + raw6_sk(sk)->filter = filter;
76501 return 0;
76502 default:
76503 return -ENOPROTOOPT;
76504 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76505 char __user *optval, int __user *optlen)
76506 {
76507 int len;
76508 + struct icmp6_filter filter;
76509
76510 switch (optname) {
76511 case ICMPV6_FILTER:
76512 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76513 len = sizeof(struct icmp6_filter);
76514 if (put_user(len, optlen))
76515 return -EFAULT;
76516 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76517 + filter = raw6_sk(sk)->filter;
76518 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
76519 return -EFAULT;
76520 return 0;
76521 default:
76522 @@ -1250,7 +1255,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76523 0, 0L, 0,
76524 sock_i_uid(sp), 0,
76525 sock_i_ino(sp),
76526 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76527 + atomic_read(&sp->sk_refcnt),
76528 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76529 + NULL,
76530 +#else
76531 + sp,
76532 +#endif
76533 + atomic_read_unchecked(&sp->sk_drops));
76534 }
76535
76536 static int raw6_seq_show(struct seq_file *seq, void *v)
76537 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76538 index 9df64a5..39875da 100644
76539 --- a/net/ipv6/tcp_ipv6.c
76540 +++ b/net/ipv6/tcp_ipv6.c
76541 @@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76542 }
76543 #endif
76544
76545 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76546 +extern int grsec_enable_blackhole;
76547 +#endif
76548 +
76549 static void tcp_v6_hash(struct sock *sk)
76550 {
76551 if (sk->sk_state != TCP_CLOSE) {
76552 @@ -1544,6 +1548,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76553 return 0;
76554
76555 reset:
76556 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76557 + if (!grsec_enable_blackhole)
76558 +#endif
76559 tcp_v6_send_reset(sk, skb);
76560 discard:
76561 if (opt_skb)
76562 @@ -1625,12 +1632,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76563 TCP_SKB_CB(skb)->sacked = 0;
76564
76565 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76566 - if (!sk)
76567 + if (!sk) {
76568 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76569 + ret = 1;
76570 +#endif
76571 goto no_tcp_socket;
76572 + }
76573
76574 process:
76575 - if (sk->sk_state == TCP_TIME_WAIT)
76576 + if (sk->sk_state == TCP_TIME_WAIT) {
76577 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76578 + ret = 2;
76579 +#endif
76580 goto do_time_wait;
76581 + }
76582
76583 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76584 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76585 @@ -1679,6 +1694,10 @@ no_tcp_socket:
76586 bad_packet:
76587 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76588 } else {
76589 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76590 + if (!grsec_enable_blackhole || (ret == 1 &&
76591 + (skb->dev->flags & IFF_LOOPBACK)))
76592 +#endif
76593 tcp_v6_send_reset(NULL, skb);
76594 }
76595
76596 @@ -1885,7 +1904,13 @@ static void get_openreq6(struct seq_file *seq,
76597 uid,
76598 0, /* non standard timer */
76599 0, /* open_requests have no inode */
76600 - 0, req);
76601 + 0,
76602 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76603 + NULL
76604 +#else
76605 + req
76606 +#endif
76607 + );
76608 }
76609
76610 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76611 @@ -1935,7 +1960,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76612 sock_i_uid(sp),
76613 icsk->icsk_probes_out,
76614 sock_i_ino(sp),
76615 - atomic_read(&sp->sk_refcnt), sp,
76616 + atomic_read(&sp->sk_refcnt),
76617 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76618 + NULL,
76619 +#else
76620 + sp,
76621 +#endif
76622 jiffies_to_clock_t(icsk->icsk_rto),
76623 jiffies_to_clock_t(icsk->icsk_ack.ato),
76624 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76625 @@ -1970,7 +2000,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76626 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76627 tw->tw_substate, 0, 0,
76628 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76629 - atomic_read(&tw->tw_refcnt), tw);
76630 + atomic_read(&tw->tw_refcnt),
76631 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76632 + NULL
76633 +#else
76634 + tw
76635 +#endif
76636 + );
76637 }
76638
76639 static int tcp6_seq_show(struct seq_file *seq, void *v)
76640 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76641 index f05099f..ea613f0 100644
76642 --- a/net/ipv6/udp.c
76643 +++ b/net/ipv6/udp.c
76644 @@ -50,6 +50,10 @@
76645 #include <linux/seq_file.h>
76646 #include "udp_impl.h"
76647
76648 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76649 +extern int grsec_enable_blackhole;
76650 +#endif
76651 +
76652 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76653 {
76654 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76655 @@ -615,7 +619,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76656 return rc;
76657 drop:
76658 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76659 - atomic_inc(&sk->sk_drops);
76660 + atomic_inc_unchecked(&sk->sk_drops);
76661 kfree_skb(skb);
76662 return -1;
76663 }
76664 @@ -673,7 +677,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76665 if (likely(skb1 == NULL))
76666 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76667 if (!skb1) {
76668 - atomic_inc(&sk->sk_drops);
76669 + atomic_inc_unchecked(&sk->sk_drops);
76670 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76671 IS_UDPLITE(sk));
76672 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76673 @@ -844,6 +848,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76674 goto discard;
76675
76676 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76677 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76678 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76679 +#endif
76680 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76681
76682 kfree_skb(skb);
76683 @@ -1453,8 +1460,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
76684 0, 0L, 0,
76685 sock_i_uid(sp), 0,
76686 sock_i_ino(sp),
76687 - atomic_read(&sp->sk_refcnt), sp,
76688 - atomic_read(&sp->sk_drops));
76689 + atomic_read(&sp->sk_refcnt),
76690 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76691 + NULL,
76692 +#else
76693 + sp,
76694 +#endif
76695 + atomic_read_unchecked(&sp->sk_drops));
76696 }
76697
76698 int udp6_seq_show(struct seq_file *seq, void *v)
76699 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
76700 index 6b9d5a0..4dffaf1 100644
76701 --- a/net/irda/ircomm/ircomm_tty.c
76702 +++ b/net/irda/ircomm/ircomm_tty.c
76703 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76704 add_wait_queue(&self->open_wait, &wait);
76705
76706 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76707 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76708 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76709
76710 /* As far as I can see, we protect open_count - Jean II */
76711 spin_lock_irqsave(&self->spinlock, flags);
76712 if (!tty_hung_up_p(filp)) {
76713 extra_count = 1;
76714 - self->open_count--;
76715 + local_dec(&self->open_count);
76716 }
76717 spin_unlock_irqrestore(&self->spinlock, flags);
76718 - self->blocked_open++;
76719 + local_inc(&self->blocked_open);
76720
76721 while (1) {
76722 if (tty->termios->c_cflag & CBAUD) {
76723 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76724 }
76725
76726 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76727 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76728 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76729
76730 schedule();
76731 }
76732 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76733 if (extra_count) {
76734 /* ++ is not atomic, so this should be protected - Jean II */
76735 spin_lock_irqsave(&self->spinlock, flags);
76736 - self->open_count++;
76737 + local_inc(&self->open_count);
76738 spin_unlock_irqrestore(&self->spinlock, flags);
76739 }
76740 - self->blocked_open--;
76741 + local_dec(&self->blocked_open);
76742
76743 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76744 - __FILE__,__LINE__, tty->driver->name, self->open_count);
76745 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76746
76747 if (!retval)
76748 self->flags |= ASYNC_NORMAL_ACTIVE;
76749 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
76750 }
76751 /* ++ is not atomic, so this should be protected - Jean II */
76752 spin_lock_irqsave(&self->spinlock, flags);
76753 - self->open_count++;
76754 + local_inc(&self->open_count);
76755
76756 tty->driver_data = self;
76757 self->tty = tty;
76758 spin_unlock_irqrestore(&self->spinlock, flags);
76759
76760 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
76761 - self->line, self->open_count);
76762 + self->line, local_read(&self->open_count));
76763
76764 /* Not really used by us, but lets do it anyway */
76765 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
76766 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76767 return;
76768 }
76769
76770 - if ((tty->count == 1) && (self->open_count != 1)) {
76771 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
76772 /*
76773 * Uh, oh. tty->count is 1, which means that the tty
76774 * structure will be freed. state->count should always
76775 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76776 */
76777 IRDA_DEBUG(0, "%s(), bad serial port count; "
76778 "tty->count is 1, state->count is %d\n", __func__ ,
76779 - self->open_count);
76780 - self->open_count = 1;
76781 + local_read(&self->open_count));
76782 + local_set(&self->open_count, 1);
76783 }
76784
76785 - if (--self->open_count < 0) {
76786 + if (local_dec_return(&self->open_count) < 0) {
76787 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
76788 - __func__, self->line, self->open_count);
76789 - self->open_count = 0;
76790 + __func__, self->line, local_read(&self->open_count));
76791 + local_set(&self->open_count, 0);
76792 }
76793 - if (self->open_count) {
76794 + if (local_read(&self->open_count)) {
76795 spin_unlock_irqrestore(&self->spinlock, flags);
76796
76797 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
76798 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76799 tty->closing = 0;
76800 self->tty = NULL;
76801
76802 - if (self->blocked_open) {
76803 + if (local_read(&self->blocked_open)) {
76804 if (self->close_delay)
76805 schedule_timeout_interruptible(self->close_delay);
76806 wake_up_interruptible(&self->open_wait);
76807 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
76808 spin_lock_irqsave(&self->spinlock, flags);
76809 self->flags &= ~ASYNC_NORMAL_ACTIVE;
76810 self->tty = NULL;
76811 - self->open_count = 0;
76812 + local_set(&self->open_count, 0);
76813 spin_unlock_irqrestore(&self->spinlock, flags);
76814
76815 wake_up_interruptible(&self->open_wait);
76816 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
76817 seq_putc(m, '\n');
76818
76819 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
76820 - seq_printf(m, "Open count: %d\n", self->open_count);
76821 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
76822 seq_printf(m, "Max data size: %d\n", self->max_data_size);
76823 seq_printf(m, "Max header size: %d\n", self->max_header_size);
76824
76825 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
76826 index cd6f7a9..e63fe89 100644
76827 --- a/net/iucv/af_iucv.c
76828 +++ b/net/iucv/af_iucv.c
76829 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
76830
76831 write_lock_bh(&iucv_sk_list.lock);
76832
76833 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
76834 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76835 while (__iucv_get_sock_by_name(name)) {
76836 sprintf(name, "%08x",
76837 - atomic_inc_return(&iucv_sk_list.autobind_name));
76838 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76839 }
76840
76841 write_unlock_bh(&iucv_sk_list.lock);
76842 diff --git a/net/key/af_key.c b/net/key/af_key.c
76843 index 34e4185..8823368 100644
76844 --- a/net/key/af_key.c
76845 +++ b/net/key/af_key.c
76846 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
76847 static u32 get_acqseq(void)
76848 {
76849 u32 res;
76850 - static atomic_t acqseq;
76851 + static atomic_unchecked_t acqseq;
76852
76853 do {
76854 - res = atomic_inc_return(&acqseq);
76855 + res = atomic_inc_return_unchecked(&acqseq);
76856 } while (!res);
76857 return res;
76858 }
76859 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
76860 index 3f3cd50..d2cf249 100644
76861 --- a/net/mac80211/ieee80211_i.h
76862 +++ b/net/mac80211/ieee80211_i.h
76863 @@ -28,6 +28,7 @@
76864 #include <net/ieee80211_radiotap.h>
76865 #include <net/cfg80211.h>
76866 #include <net/mac80211.h>
76867 +#include <asm/local.h>
76868 #include "key.h"
76869 #include "sta_info.h"
76870
76871 @@ -863,7 +864,7 @@ struct ieee80211_local {
76872 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
76873 spinlock_t queue_stop_reason_lock;
76874
76875 - int open_count;
76876 + local_t open_count;
76877 int monitors, cooked_mntrs;
76878 /* number of interfaces with corresponding FIF_ flags */
76879 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
76880 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
76881 index 8664111..1d6a065 100644
76882 --- a/net/mac80211/iface.c
76883 +++ b/net/mac80211/iface.c
76884 @@ -328,7 +328,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76885 break;
76886 }
76887
76888 - if (local->open_count == 0) {
76889 + if (local_read(&local->open_count) == 0) {
76890 res = drv_start(local);
76891 if (res)
76892 goto err_del_bss;
76893 @@ -371,7 +371,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76894 break;
76895 }
76896
76897 - if (local->monitors == 0 && local->open_count == 0) {
76898 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
76899 res = ieee80211_add_virtual_monitor(local);
76900 if (res)
76901 goto err_stop;
76902 @@ -468,7 +468,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76903 mutex_unlock(&local->mtx);
76904
76905 if (coming_up)
76906 - local->open_count++;
76907 + local_inc(&local->open_count);
76908
76909 if (hw_reconf_flags)
76910 ieee80211_hw_config(local, hw_reconf_flags);
76911 @@ -481,7 +481,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76912 err_del_interface:
76913 drv_remove_interface(local, sdata);
76914 err_stop:
76915 - if (!local->open_count)
76916 + if (!local_read(&local->open_count))
76917 drv_stop(local);
76918 err_del_bss:
76919 sdata->bss = NULL;
76920 @@ -613,7 +613,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76921 }
76922
76923 if (going_down)
76924 - local->open_count--;
76925 + local_dec(&local->open_count);
76926
76927 switch (sdata->vif.type) {
76928 case NL80211_IFTYPE_AP_VLAN:
76929 @@ -685,7 +685,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76930
76931 ieee80211_recalc_ps(local, -1);
76932
76933 - if (local->open_count == 0) {
76934 + if (local_read(&local->open_count) == 0) {
76935 if (local->ops->napi_poll)
76936 napi_disable(&local->napi);
76937 ieee80211_clear_tx_pending(local);
76938 @@ -717,7 +717,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76939 }
76940 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
76941
76942 - if (local->monitors == local->open_count && local->monitors > 0)
76943 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
76944 ieee80211_add_virtual_monitor(local);
76945 }
76946
76947 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
76948 index f5548e9..474a15f 100644
76949 --- a/net/mac80211/main.c
76950 +++ b/net/mac80211/main.c
76951 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
76952 local->hw.conf.power_level = power;
76953 }
76954
76955 - if (changed && local->open_count) {
76956 + if (changed && local_read(&local->open_count)) {
76957 ret = drv_config(local, changed);
76958 /*
76959 * Goal:
76960 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
76961 index af1c4e2..24dbbe3 100644
76962 --- a/net/mac80211/pm.c
76963 +++ b/net/mac80211/pm.c
76964 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76965 struct ieee80211_sub_if_data *sdata;
76966 struct sta_info *sta;
76967
76968 - if (!local->open_count)
76969 + if (!local_read(&local->open_count))
76970 goto suspend;
76971
76972 ieee80211_scan_cancel(local);
76973 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76974 cancel_work_sync(&local->dynamic_ps_enable_work);
76975 del_timer_sync(&local->dynamic_ps_timer);
76976
76977 - local->wowlan = wowlan && local->open_count;
76978 + local->wowlan = wowlan && local_read(&local->open_count);
76979 if (local->wowlan) {
76980 int err = drv_suspend(local, wowlan);
76981 if (err < 0) {
76982 @@ -132,7 +132,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76983 drv_remove_interface(local, sdata);
76984
76985 /* stop hardware - this must stop RX */
76986 - if (local->open_count)
76987 + if (local_read(&local->open_count))
76988 ieee80211_stop_device(local);
76989
76990 suspend:
76991 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
76992 index 3313c11..bec9f17 100644
76993 --- a/net/mac80211/rate.c
76994 +++ b/net/mac80211/rate.c
76995 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
76996
76997 ASSERT_RTNL();
76998
76999 - if (local->open_count)
77000 + if (local_read(&local->open_count))
77001 return -EBUSY;
77002
77003 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
77004 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
77005 index c97a065..ff61928 100644
77006 --- a/net/mac80211/rc80211_pid_debugfs.c
77007 +++ b/net/mac80211/rc80211_pid_debugfs.c
77008 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
77009
77010 spin_unlock_irqrestore(&events->lock, status);
77011
77012 - if (copy_to_user(buf, pb, p))
77013 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
77014 return -EFAULT;
77015
77016 return p;
77017 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
77018 index f564b5e..22fee47 100644
77019 --- a/net/mac80211/util.c
77020 +++ b/net/mac80211/util.c
77021 @@ -1224,7 +1224,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
77022 }
77023 #endif
77024 /* everything else happens only if HW was up & running */
77025 - if (!local->open_count)
77026 + if (!local_read(&local->open_count))
77027 goto wake_up;
77028
77029 /*
77030 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
77031 index 209c1ed..39484dc 100644
77032 --- a/net/netfilter/Kconfig
77033 +++ b/net/netfilter/Kconfig
77034 @@ -851,6 +851,16 @@ config NETFILTER_XT_MATCH_ESP
77035
77036 To compile it as a module, choose M here. If unsure, say N.
77037
77038 +config NETFILTER_XT_MATCH_GRADM
77039 + tristate '"gradm" match support'
77040 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
77041 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
77042 + ---help---
77043 + The gradm match allows to match on grsecurity RBAC being enabled.
77044 + It is useful when iptables rules are applied early on bootup to
77045 + prevent connections to the machine (except from a trusted host)
77046 + while the RBAC system is disabled.
77047 +
77048 config NETFILTER_XT_MATCH_HASHLIMIT
77049 tristate '"hashlimit" match support'
77050 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
77051 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
77052 index 4e7960c..89e48d4 100644
77053 --- a/net/netfilter/Makefile
77054 +++ b/net/netfilter/Makefile
77055 @@ -87,6 +87,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
77056 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77057 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
77058 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77059 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77060 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77061 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77062 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77063 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
77064 index 1548df9..98ad9b4 100644
77065 --- a/net/netfilter/ipvs/ip_vs_conn.c
77066 +++ b/net/netfilter/ipvs/ip_vs_conn.c
77067 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
77068 /* Increase the refcnt counter of the dest */
77069 atomic_inc(&dest->refcnt);
77070
77071 - conn_flags = atomic_read(&dest->conn_flags);
77072 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
77073 if (cp->protocol != IPPROTO_UDP)
77074 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77075 flags = cp->flags;
77076 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
77077 atomic_set(&cp->refcnt, 1);
77078
77079 atomic_set(&cp->n_control, 0);
77080 - atomic_set(&cp->in_pkts, 0);
77081 + atomic_set_unchecked(&cp->in_pkts, 0);
77082
77083 atomic_inc(&ipvs->conn_count);
77084 if (flags & IP_VS_CONN_F_NO_CPORT)
77085 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
77086
77087 /* Don't drop the entry if its number of incoming packets is not
77088 located in [0, 8] */
77089 - i = atomic_read(&cp->in_pkts);
77090 + i = atomic_read_unchecked(&cp->in_pkts);
77091 if (i > 8 || i < 0) return 0;
77092
77093 if (!todrop_rate[i]) return 0;
77094 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
77095 index a54b018c..07e0120 100644
77096 --- a/net/netfilter/ipvs/ip_vs_core.c
77097 +++ b/net/netfilter/ipvs/ip_vs_core.c
77098 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
77099 ret = cp->packet_xmit(skb, cp, pd->pp);
77100 /* do not touch skb anymore */
77101
77102 - atomic_inc(&cp->in_pkts);
77103 + atomic_inc_unchecked(&cp->in_pkts);
77104 ip_vs_conn_put(cp);
77105 return ret;
77106 }
77107 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
77108 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77109 pkts = sysctl_sync_threshold(ipvs);
77110 else
77111 - pkts = atomic_add_return(1, &cp->in_pkts);
77112 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77113
77114 if (ipvs->sync_state & IP_VS_STATE_MASTER)
77115 ip_vs_sync_conn(net, cp, pkts);
77116 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
77117 index 84444dd..86adaa0 100644
77118 --- a/net/netfilter/ipvs/ip_vs_ctl.c
77119 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
77120 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
77121 ip_vs_rs_hash(ipvs, dest);
77122 write_unlock_bh(&ipvs->rs_lock);
77123 }
77124 - atomic_set(&dest->conn_flags, conn_flags);
77125 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
77126
77127 /* bind the service */
77128 if (!dest->svc) {
77129 @@ -2074,7 +2074,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77130 " %-7s %-6d %-10d %-10d\n",
77131 &dest->addr.in6,
77132 ntohs(dest->port),
77133 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77134 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77135 atomic_read(&dest->weight),
77136 atomic_read(&dest->activeconns),
77137 atomic_read(&dest->inactconns));
77138 @@ -2085,7 +2085,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77139 "%-7s %-6d %-10d %-10d\n",
77140 ntohl(dest->addr.ip),
77141 ntohs(dest->port),
77142 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77143 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77144 atomic_read(&dest->weight),
77145 atomic_read(&dest->activeconns),
77146 atomic_read(&dest->inactconns));
77147 @@ -2555,7 +2555,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
77148
77149 entry.addr = dest->addr.ip;
77150 entry.port = dest->port;
77151 - entry.conn_flags = atomic_read(&dest->conn_flags);
77152 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77153 entry.weight = atomic_read(&dest->weight);
77154 entry.u_threshold = dest->u_threshold;
77155 entry.l_threshold = dest->l_threshold;
77156 @@ -3089,7 +3089,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
77157 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
77158 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
77159 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77160 - (atomic_read(&dest->conn_flags) &
77161 + (atomic_read_unchecked(&dest->conn_flags) &
77162 IP_VS_CONN_F_FWD_MASK)) ||
77163 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
77164 atomic_read(&dest->weight)) ||
77165 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
77166 index effa10c..9058928 100644
77167 --- a/net/netfilter/ipvs/ip_vs_sync.c
77168 +++ b/net/netfilter/ipvs/ip_vs_sync.c
77169 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
77170 cp = cp->control;
77171 if (cp) {
77172 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
77173 - pkts = atomic_add_return(1, &cp->in_pkts);
77174 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77175 else
77176 pkts = sysctl_sync_threshold(ipvs);
77177 ip_vs_sync_conn(net, cp->control, pkts);
77178 @@ -758,7 +758,7 @@ control:
77179 if (!cp)
77180 return;
77181 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
77182 - pkts = atomic_add_return(1, &cp->in_pkts);
77183 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77184 else
77185 pkts = sysctl_sync_threshold(ipvs);
77186 goto sloop;
77187 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
77188
77189 if (opt)
77190 memcpy(&cp->in_seq, opt, sizeof(*opt));
77191 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77192 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77193 cp->state = state;
77194 cp->old_state = cp->state;
77195 /*
77196 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
77197 index 7fd66de..e6fb361 100644
77198 --- a/net/netfilter/ipvs/ip_vs_xmit.c
77199 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
77200 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
77201 else
77202 rc = NF_ACCEPT;
77203 /* do not touch skb anymore */
77204 - atomic_inc(&cp->in_pkts);
77205 + atomic_inc_unchecked(&cp->in_pkts);
77206 goto out;
77207 }
77208
77209 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
77210 else
77211 rc = NF_ACCEPT;
77212 /* do not touch skb anymore */
77213 - atomic_inc(&cp->in_pkts);
77214 + atomic_inc_unchecked(&cp->in_pkts);
77215 goto out;
77216 }
77217
77218 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
77219 index ac3af97..c134c21 100644
77220 --- a/net/netfilter/nf_conntrack_core.c
77221 +++ b/net/netfilter/nf_conntrack_core.c
77222 @@ -1530,6 +1530,10 @@ err_proto:
77223 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
77224 #define DYING_NULLS_VAL ((1<<30)+1)
77225
77226 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77227 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
77228 +#endif
77229 +
77230 static int nf_conntrack_init_net(struct net *net)
77231 {
77232 int ret;
77233 @@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
77234 goto err_stat;
77235 }
77236
77237 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77238 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
77239 +#else
77240 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
77241 +#endif
77242 if (!net->ct.slabname) {
77243 ret = -ENOMEM;
77244 goto err_slabname;
77245 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
77246 index 3c3cfc0..7a6ea1a 100644
77247 --- a/net/netfilter/nfnetlink_log.c
77248 +++ b/net/netfilter/nfnetlink_log.c
77249 @@ -70,7 +70,7 @@ struct nfulnl_instance {
77250 };
77251
77252 static DEFINE_SPINLOCK(instances_lock);
77253 -static atomic_t global_seq;
77254 +static atomic_unchecked_t global_seq;
77255
77256 #define INSTANCE_BUCKETS 16
77257 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77258 @@ -517,7 +517,7 @@ __build_packet_message(struct nfulnl_instance *inst,
77259 /* global sequence number */
77260 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
77261 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
77262 - htonl(atomic_inc_return(&global_seq))))
77263 + htonl(atomic_inc_return_unchecked(&global_seq))))
77264 goto nla_put_failure;
77265
77266 if (data_len) {
77267 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
77268 new file mode 100644
77269 index 0000000..6905327
77270 --- /dev/null
77271 +++ b/net/netfilter/xt_gradm.c
77272 @@ -0,0 +1,51 @@
77273 +/*
77274 + * gradm match for netfilter
77275 + * Copyright © Zbigniew Krzystolik, 2010
77276 + *
77277 + * This program is free software; you can redistribute it and/or modify
77278 + * it under the terms of the GNU General Public License; either version
77279 + * 2 or 3 as published by the Free Software Foundation.
77280 + */
77281 +#include <linux/module.h>
77282 +#include <linux/moduleparam.h>
77283 +#include <linux/skbuff.h>
77284 +#include <linux/netfilter/x_tables.h>
77285 +#include <linux/grsecurity.h>
77286 +#include <linux/netfilter/xt_gradm.h>
77287 +
77288 +static bool
77289 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
77290 +{
77291 + const struct xt_gradm_mtinfo *info = par->matchinfo;
77292 + bool retval = false;
77293 + if (gr_acl_is_enabled())
77294 + retval = true;
77295 + return retval ^ info->invflags;
77296 +}
77297 +
77298 +static struct xt_match gradm_mt_reg __read_mostly = {
77299 + .name = "gradm",
77300 + .revision = 0,
77301 + .family = NFPROTO_UNSPEC,
77302 + .match = gradm_mt,
77303 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
77304 + .me = THIS_MODULE,
77305 +};
77306 +
77307 +static int __init gradm_mt_init(void)
77308 +{
77309 + return xt_register_match(&gradm_mt_reg);
77310 +}
77311 +
77312 +static void __exit gradm_mt_exit(void)
77313 +{
77314 + xt_unregister_match(&gradm_mt_reg);
77315 +}
77316 +
77317 +module_init(gradm_mt_init);
77318 +module_exit(gradm_mt_exit);
77319 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
77320 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
77321 +MODULE_LICENSE("GPL");
77322 +MODULE_ALIAS("ipt_gradm");
77323 +MODULE_ALIAS("ip6t_gradm");
77324 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
77325 index 4fe4fb4..87a89e5 100644
77326 --- a/net/netfilter/xt_statistic.c
77327 +++ b/net/netfilter/xt_statistic.c
77328 @@ -19,7 +19,7 @@
77329 #include <linux/module.h>
77330
77331 struct xt_statistic_priv {
77332 - atomic_t count;
77333 + atomic_unchecked_t count;
77334 } ____cacheline_aligned_in_smp;
77335
77336 MODULE_LICENSE("GPL");
77337 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
77338 break;
77339 case XT_STATISTIC_MODE_NTH:
77340 do {
77341 - oval = atomic_read(&info->master->count);
77342 + oval = atomic_read_unchecked(&info->master->count);
77343 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
77344 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
77345 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
77346 if (nval == 0)
77347 ret = !ret;
77348 break;
77349 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
77350 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
77351 if (info->master == NULL)
77352 return -ENOMEM;
77353 - atomic_set(&info->master->count, info->u.nth.count);
77354 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
77355
77356 return 0;
77357 }
77358 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
77359 index b3025a6..d63a537 100644
77360 --- a/net/netlink/af_netlink.c
77361 +++ b/net/netlink/af_netlink.c
77362 @@ -753,7 +753,7 @@ static void netlink_overrun(struct sock *sk)
77363 sk->sk_error_report(sk);
77364 }
77365 }
77366 - atomic_inc(&sk->sk_drops);
77367 + atomic_inc_unchecked(&sk->sk_drops);
77368 }
77369
77370 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
77371 @@ -2022,7 +2022,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
77372 sk_wmem_alloc_get(s),
77373 nlk->cb,
77374 atomic_read(&s->sk_refcnt),
77375 - atomic_read(&s->sk_drops),
77376 + atomic_read_unchecked(&s->sk_drops),
77377 sock_i_ino(s)
77378 );
77379
77380 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
77381 index 06592d8..64860f6 100644
77382 --- a/net/netrom/af_netrom.c
77383 +++ b/net/netrom/af_netrom.c
77384 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77385 struct sock *sk = sock->sk;
77386 struct nr_sock *nr = nr_sk(sk);
77387
77388 + memset(sax, 0, sizeof(*sax));
77389 lock_sock(sk);
77390 if (peer != 0) {
77391 if (sk->sk_state != TCP_ESTABLISHED) {
77392 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77393 *uaddr_len = sizeof(struct full_sockaddr_ax25);
77394 } else {
77395 sax->fsa_ax25.sax25_family = AF_NETROM;
77396 - sax->fsa_ax25.sax25_ndigis = 0;
77397 sax->fsa_ax25.sax25_call = nr->source_addr;
77398 *uaddr_len = sizeof(struct sockaddr_ax25);
77399 }
77400 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
77401 index 0f66174..e7cb04c 100644
77402 --- a/net/packet/af_packet.c
77403 +++ b/net/packet/af_packet.c
77404 @@ -1687,7 +1687,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77405
77406 spin_lock(&sk->sk_receive_queue.lock);
77407 po->stats.tp_packets++;
77408 - skb->dropcount = atomic_read(&sk->sk_drops);
77409 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77410 __skb_queue_tail(&sk->sk_receive_queue, skb);
77411 spin_unlock(&sk->sk_receive_queue.lock);
77412 sk->sk_data_ready(sk, skb->len);
77413 @@ -1696,7 +1696,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77414 drop_n_acct:
77415 spin_lock(&sk->sk_receive_queue.lock);
77416 po->stats.tp_drops++;
77417 - atomic_inc(&sk->sk_drops);
77418 + atomic_inc_unchecked(&sk->sk_drops);
77419 spin_unlock(&sk->sk_receive_queue.lock);
77420
77421 drop_n_restore:
77422 @@ -2641,6 +2641,7 @@ out:
77423
77424 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
77425 {
77426 + struct sock_extended_err ee;
77427 struct sock_exterr_skb *serr;
77428 struct sk_buff *skb, *skb2;
77429 int copied, err;
77430 @@ -2662,8 +2663,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
77431 sock_recv_timestamp(msg, sk, skb);
77432
77433 serr = SKB_EXT_ERR(skb);
77434 + ee = serr->ee;
77435 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
77436 - sizeof(serr->ee), &serr->ee);
77437 + sizeof ee, &ee);
77438
77439 msg->msg_flags |= MSG_ERRQUEUE;
77440 err = copied;
77441 @@ -3275,7 +3277,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77442 case PACKET_HDRLEN:
77443 if (len > sizeof(int))
77444 len = sizeof(int);
77445 - if (copy_from_user(&val, optval, len))
77446 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
77447 return -EFAULT;
77448 switch (val) {
77449 case TPACKET_V1:
77450 @@ -3314,7 +3316,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77451 len = lv;
77452 if (put_user(len, optlen))
77453 return -EFAULT;
77454 - if (copy_to_user(optval, data, len))
77455 + if (len > sizeof(st) || copy_to_user(optval, data, len))
77456 return -EFAULT;
77457 return 0;
77458 }
77459 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
77460 index 5a940db..f0b9c12 100644
77461 --- a/net/phonet/af_phonet.c
77462 +++ b/net/phonet/af_phonet.c
77463 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
77464 {
77465 struct phonet_protocol *pp;
77466
77467 - if (protocol >= PHONET_NPROTO)
77468 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77469 return NULL;
77470
77471 rcu_read_lock();
77472 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
77473 {
77474 int err = 0;
77475
77476 - if (protocol >= PHONET_NPROTO)
77477 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77478 return -EINVAL;
77479
77480 err = proto_register(pp->prot, 1);
77481 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
77482 index 576f22c..bc7a71b 100644
77483 --- a/net/phonet/pep.c
77484 +++ b/net/phonet/pep.c
77485 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77486
77487 case PNS_PEP_CTRL_REQ:
77488 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
77489 - atomic_inc(&sk->sk_drops);
77490 + atomic_inc_unchecked(&sk->sk_drops);
77491 break;
77492 }
77493 __skb_pull(skb, 4);
77494 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77495 }
77496
77497 if (pn->rx_credits == 0) {
77498 - atomic_inc(&sk->sk_drops);
77499 + atomic_inc_unchecked(&sk->sk_drops);
77500 err = -ENOBUFS;
77501 break;
77502 }
77503 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
77504 }
77505
77506 if (pn->rx_credits == 0) {
77507 - atomic_inc(&sk->sk_drops);
77508 + atomic_inc_unchecked(&sk->sk_drops);
77509 err = NET_RX_DROP;
77510 break;
77511 }
77512 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
77513 index 0acc943..c727611 100644
77514 --- a/net/phonet/socket.c
77515 +++ b/net/phonet/socket.c
77516 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
77517 pn->resource, sk->sk_state,
77518 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
77519 sock_i_uid(sk), sock_i_ino(sk),
77520 - atomic_read(&sk->sk_refcnt), sk,
77521 - atomic_read(&sk->sk_drops), &len);
77522 + atomic_read(&sk->sk_refcnt),
77523 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77524 + NULL,
77525 +#else
77526 + sk,
77527 +#endif
77528 + atomic_read_unchecked(&sk->sk_drops), &len);
77529 }
77530 seq_printf(seq, "%*s\n", 127 - len, "");
77531 return 0;
77532 diff --git a/net/rds/cong.c b/net/rds/cong.c
77533 index e5b65ac..f3b6fb7 100644
77534 --- a/net/rds/cong.c
77535 +++ b/net/rds/cong.c
77536 @@ -78,7 +78,7 @@
77537 * finds that the saved generation number is smaller than the global generation
77538 * number, it wakes up the process.
77539 */
77540 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
77541 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
77542
77543 /*
77544 * Congestion monitoring
77545 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
77546 rdsdebug("waking map %p for %pI4\n",
77547 map, &map->m_addr);
77548 rds_stats_inc(s_cong_update_received);
77549 - atomic_inc(&rds_cong_generation);
77550 + atomic_inc_unchecked(&rds_cong_generation);
77551 if (waitqueue_active(&map->m_waitq))
77552 wake_up(&map->m_waitq);
77553 if (waitqueue_active(&rds_poll_waitq))
77554 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
77555
77556 int rds_cong_updated_since(unsigned long *recent)
77557 {
77558 - unsigned long gen = atomic_read(&rds_cong_generation);
77559 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
77560
77561 if (likely(*recent == gen))
77562 return 0;
77563 diff --git a/net/rds/ib.h b/net/rds/ib.h
77564 index 8d2b3d5..227ec5b 100644
77565 --- a/net/rds/ib.h
77566 +++ b/net/rds/ib.h
77567 @@ -128,7 +128,7 @@ struct rds_ib_connection {
77568 /* sending acks */
77569 unsigned long i_ack_flags;
77570 #ifdef KERNEL_HAS_ATOMIC64
77571 - atomic64_t i_ack_next; /* next ACK to send */
77572 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77573 #else
77574 spinlock_t i_ack_lock; /* protect i_ack_next */
77575 u64 i_ack_next; /* next ACK to send */
77576 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
77577 index a1e1162..265e129 100644
77578 --- a/net/rds/ib_cm.c
77579 +++ b/net/rds/ib_cm.c
77580 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
77581 /* Clear the ACK state */
77582 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77583 #ifdef KERNEL_HAS_ATOMIC64
77584 - atomic64_set(&ic->i_ack_next, 0);
77585 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77586 #else
77587 ic->i_ack_next = 0;
77588 #endif
77589 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
77590 index 8d19491..05a3e65 100644
77591 --- a/net/rds/ib_recv.c
77592 +++ b/net/rds/ib_recv.c
77593 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77594 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
77595 int ack_required)
77596 {
77597 - atomic64_set(&ic->i_ack_next, seq);
77598 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77599 if (ack_required) {
77600 smp_mb__before_clear_bit();
77601 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77602 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77603 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77604 smp_mb__after_clear_bit();
77605
77606 - return atomic64_read(&ic->i_ack_next);
77607 + return atomic64_read_unchecked(&ic->i_ack_next);
77608 }
77609 #endif
77610
77611 diff --git a/net/rds/iw.h b/net/rds/iw.h
77612 index 04ce3b1..48119a6 100644
77613 --- a/net/rds/iw.h
77614 +++ b/net/rds/iw.h
77615 @@ -134,7 +134,7 @@ struct rds_iw_connection {
77616 /* sending acks */
77617 unsigned long i_ack_flags;
77618 #ifdef KERNEL_HAS_ATOMIC64
77619 - atomic64_t i_ack_next; /* next ACK to send */
77620 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77621 #else
77622 spinlock_t i_ack_lock; /* protect i_ack_next */
77623 u64 i_ack_next; /* next ACK to send */
77624 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
77625 index a91e1db..cf3053f 100644
77626 --- a/net/rds/iw_cm.c
77627 +++ b/net/rds/iw_cm.c
77628 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
77629 /* Clear the ACK state */
77630 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77631 #ifdef KERNEL_HAS_ATOMIC64
77632 - atomic64_set(&ic->i_ack_next, 0);
77633 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77634 #else
77635 ic->i_ack_next = 0;
77636 #endif
77637 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
77638 index 4503335..db566b4 100644
77639 --- a/net/rds/iw_recv.c
77640 +++ b/net/rds/iw_recv.c
77641 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77642 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
77643 int ack_required)
77644 {
77645 - atomic64_set(&ic->i_ack_next, seq);
77646 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77647 if (ack_required) {
77648 smp_mb__before_clear_bit();
77649 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77650 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77651 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77652 smp_mb__after_clear_bit();
77653
77654 - return atomic64_read(&ic->i_ack_next);
77655 + return atomic64_read_unchecked(&ic->i_ack_next);
77656 }
77657 #endif
77658
77659 diff --git a/net/rds/recv.c b/net/rds/recv.c
77660 index 5c6e9f1..9f0f17c 100644
77661 --- a/net/rds/recv.c
77662 +++ b/net/rds/recv.c
77663 @@ -410,6 +410,8 @@ int rds_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
77664
77665 rdsdebug("size %zu flags 0x%x timeo %ld\n", size, msg_flags, timeo);
77666
77667 + msg->msg_namelen = 0;
77668 +
77669 if (msg_flags & MSG_OOB)
77670 goto out;
77671
77672 @@ -485,6 +487,7 @@ int rds_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
77673 sin->sin_port = inc->i_hdr.h_sport;
77674 sin->sin_addr.s_addr = inc->i_saddr;
77675 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
77676 + msg->msg_namelen = sizeof(*sin);
77677 }
77678 break;
77679 }
77680 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
77681 index edac9ef..16bcb98 100644
77682 --- a/net/rds/tcp.c
77683 +++ b/net/rds/tcp.c
77684 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
77685 int val = 1;
77686
77687 set_fs(KERNEL_DS);
77688 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
77689 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
77690 sizeof(val));
77691 set_fs(oldfs);
77692 }
77693 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
77694 index 1b4fd68..2234175 100644
77695 --- a/net/rds/tcp_send.c
77696 +++ b/net/rds/tcp_send.c
77697 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
77698
77699 oldfs = get_fs();
77700 set_fs(KERNEL_DS);
77701 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
77702 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
77703 sizeof(val));
77704 set_fs(oldfs);
77705 }
77706 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
77707 index 05996d0..5a1dfe0 100644
77708 --- a/net/rxrpc/af_rxrpc.c
77709 +++ b/net/rxrpc/af_rxrpc.c
77710 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
77711 __be32 rxrpc_epoch;
77712
77713 /* current debugging ID */
77714 -atomic_t rxrpc_debug_id;
77715 +atomic_unchecked_t rxrpc_debug_id;
77716
77717 /* count of skbs currently in use */
77718 atomic_t rxrpc_n_skbs;
77719 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
77720 index e4d9cbc..b229649 100644
77721 --- a/net/rxrpc/ar-ack.c
77722 +++ b/net/rxrpc/ar-ack.c
77723 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77724
77725 _enter("{%d,%d,%d,%d},",
77726 call->acks_hard, call->acks_unacked,
77727 - atomic_read(&call->sequence),
77728 + atomic_read_unchecked(&call->sequence),
77729 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
77730
77731 stop = 0;
77732 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77733
77734 /* each Tx packet has a new serial number */
77735 sp->hdr.serial =
77736 - htonl(atomic_inc_return(&call->conn->serial));
77737 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
77738
77739 hdr = (struct rxrpc_header *) txb->head;
77740 hdr->serial = sp->hdr.serial;
77741 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
77742 */
77743 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
77744 {
77745 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
77746 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
77747 }
77748
77749 /*
77750 @@ -629,7 +629,7 @@ process_further:
77751
77752 latest = ntohl(sp->hdr.serial);
77753 hard = ntohl(ack.firstPacket);
77754 - tx = atomic_read(&call->sequence);
77755 + tx = atomic_read_unchecked(&call->sequence);
77756
77757 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77758 latest,
77759 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
77760 goto maybe_reschedule;
77761
77762 send_ACK_with_skew:
77763 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
77764 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
77765 ntohl(ack.serial));
77766 send_ACK:
77767 mtu = call->conn->trans->peer->if_mtu;
77768 @@ -1173,7 +1173,7 @@ send_ACK:
77769 ackinfo.rxMTU = htonl(5692);
77770 ackinfo.jumbo_max = htonl(4);
77771
77772 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77773 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77774 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77775 ntohl(hdr.serial),
77776 ntohs(ack.maxSkew),
77777 @@ -1191,7 +1191,7 @@ send_ACK:
77778 send_message:
77779 _debug("send message");
77780
77781 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77782 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77783 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
77784 send_message_2:
77785
77786 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
77787 index a3bbb36..3341fb9 100644
77788 --- a/net/rxrpc/ar-call.c
77789 +++ b/net/rxrpc/ar-call.c
77790 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
77791 spin_lock_init(&call->lock);
77792 rwlock_init(&call->state_lock);
77793 atomic_set(&call->usage, 1);
77794 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
77795 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77796 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
77797
77798 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
77799 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
77800 index 4106ca9..a338d7a 100644
77801 --- a/net/rxrpc/ar-connection.c
77802 +++ b/net/rxrpc/ar-connection.c
77803 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
77804 rwlock_init(&conn->lock);
77805 spin_lock_init(&conn->state_lock);
77806 atomic_set(&conn->usage, 1);
77807 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
77808 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77809 conn->avail_calls = RXRPC_MAXCALLS;
77810 conn->size_align = 4;
77811 conn->header_size = sizeof(struct rxrpc_header);
77812 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
77813 index e7ed43a..6afa140 100644
77814 --- a/net/rxrpc/ar-connevent.c
77815 +++ b/net/rxrpc/ar-connevent.c
77816 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
77817
77818 len = iov[0].iov_len + iov[1].iov_len;
77819
77820 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77821 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77822 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
77823
77824 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77825 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
77826 index 529572f..c758ca7 100644
77827 --- a/net/rxrpc/ar-input.c
77828 +++ b/net/rxrpc/ar-input.c
77829 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
77830 /* track the latest serial number on this connection for ACK packet
77831 * information */
77832 serial = ntohl(sp->hdr.serial);
77833 - hi_serial = atomic_read(&call->conn->hi_serial);
77834 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
77835 while (serial > hi_serial)
77836 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
77837 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
77838 serial);
77839
77840 /* request ACK generation for any ACK or DATA packet that requests
77841 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
77842 index a693aca..81e7293 100644
77843 --- a/net/rxrpc/ar-internal.h
77844 +++ b/net/rxrpc/ar-internal.h
77845 @@ -272,8 +272,8 @@ struct rxrpc_connection {
77846 int error; /* error code for local abort */
77847 int debug_id; /* debug ID for printks */
77848 unsigned int call_counter; /* call ID counter */
77849 - atomic_t serial; /* packet serial number counter */
77850 - atomic_t hi_serial; /* highest serial number received */
77851 + atomic_unchecked_t serial; /* packet serial number counter */
77852 + atomic_unchecked_t hi_serial; /* highest serial number received */
77853 u8 avail_calls; /* number of calls available */
77854 u8 size_align; /* data size alignment (for security) */
77855 u8 header_size; /* rxrpc + security header size */
77856 @@ -346,7 +346,7 @@ struct rxrpc_call {
77857 spinlock_t lock;
77858 rwlock_t state_lock; /* lock for state transition */
77859 atomic_t usage;
77860 - atomic_t sequence; /* Tx data packet sequence counter */
77861 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
77862 u32 abort_code; /* local/remote abort code */
77863 enum { /* current state of call */
77864 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
77865 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
77866 */
77867 extern atomic_t rxrpc_n_skbs;
77868 extern __be32 rxrpc_epoch;
77869 -extern atomic_t rxrpc_debug_id;
77870 +extern atomic_unchecked_t rxrpc_debug_id;
77871 extern struct workqueue_struct *rxrpc_workqueue;
77872
77873 /*
77874 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
77875 index 87f7135..74d3703 100644
77876 --- a/net/rxrpc/ar-local.c
77877 +++ b/net/rxrpc/ar-local.c
77878 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
77879 spin_lock_init(&local->lock);
77880 rwlock_init(&local->services_lock);
77881 atomic_set(&local->usage, 1);
77882 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
77883 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77884 memcpy(&local->srx, srx, sizeof(*srx));
77885 }
77886
77887 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
77888 index 16ae887..d24f12b 100644
77889 --- a/net/rxrpc/ar-output.c
77890 +++ b/net/rxrpc/ar-output.c
77891 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
77892 sp->hdr.cid = call->cid;
77893 sp->hdr.callNumber = call->call_id;
77894 sp->hdr.seq =
77895 - htonl(atomic_inc_return(&call->sequence));
77896 + htonl(atomic_inc_return_unchecked(&call->sequence));
77897 sp->hdr.serial =
77898 - htonl(atomic_inc_return(&conn->serial));
77899 + htonl(atomic_inc_return_unchecked(&conn->serial));
77900 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
77901 sp->hdr.userStatus = 0;
77902 sp->hdr.securityIndex = conn->security_ix;
77903 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
77904 index bebaa43..2644591 100644
77905 --- a/net/rxrpc/ar-peer.c
77906 +++ b/net/rxrpc/ar-peer.c
77907 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
77908 INIT_LIST_HEAD(&peer->error_targets);
77909 spin_lock_init(&peer->lock);
77910 atomic_set(&peer->usage, 1);
77911 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
77912 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77913 memcpy(&peer->srx, srx, sizeof(*srx));
77914
77915 rxrpc_assess_MTU_size(peer);
77916 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
77917 index 38047f7..9f48511 100644
77918 --- a/net/rxrpc/ar-proc.c
77919 +++ b/net/rxrpc/ar-proc.c
77920 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
77921 atomic_read(&conn->usage),
77922 rxrpc_conn_states[conn->state],
77923 key_serial(conn->key),
77924 - atomic_read(&conn->serial),
77925 - atomic_read(&conn->hi_serial));
77926 + atomic_read_unchecked(&conn->serial),
77927 + atomic_read_unchecked(&conn->hi_serial));
77928
77929 return 0;
77930 }
77931 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
77932 index 92df566..87ec1bf 100644
77933 --- a/net/rxrpc/ar-transport.c
77934 +++ b/net/rxrpc/ar-transport.c
77935 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
77936 spin_lock_init(&trans->client_lock);
77937 rwlock_init(&trans->conn_lock);
77938 atomic_set(&trans->usage, 1);
77939 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
77940 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77941
77942 if (peer->srx.transport.family == AF_INET) {
77943 switch (peer->srx.transport_type) {
77944 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
77945 index f226709..0e735a8 100644
77946 --- a/net/rxrpc/rxkad.c
77947 +++ b/net/rxrpc/rxkad.c
77948 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
77949
77950 len = iov[0].iov_len + iov[1].iov_len;
77951
77952 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77953 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77954 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
77955
77956 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77957 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
77958
77959 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
77960
77961 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
77962 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77963 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
77964
77965 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
77966 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
77967 index 1e2eee8..ce3967e 100644
77968 --- a/net/sctp/proc.c
77969 +++ b/net/sctp/proc.c
77970 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
77971 seq_printf(seq,
77972 "%8pK %8pK %-3d %-3d %-2d %-4d "
77973 "%4d %8d %8d %7d %5lu %-5d %5d ",
77974 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
77975 + assoc, sk,
77976 + sctp_sk(sk)->type, sk->sk_state,
77977 assoc->state, hash,
77978 assoc->assoc_id,
77979 assoc->sndbuf_used,
77980 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
77981 index 31c7bfc..bc380ae 100644
77982 --- a/net/sctp/socket.c
77983 +++ b/net/sctp/socket.c
77984 @@ -4577,7 +4577,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
77985 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
77986 if (space_left < addrlen)
77987 return -ENOMEM;
77988 - if (copy_to_user(to, &temp, addrlen))
77989 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
77990 return -EFAULT;
77991 to += addrlen;
77992 cnt++;
77993 diff --git a/net/socket.c b/net/socket.c
77994 index 0452dca..7e9758c 100644
77995 --- a/net/socket.c
77996 +++ b/net/socket.c
77997 @@ -88,6 +88,7 @@
77998 #include <linux/nsproxy.h>
77999 #include <linux/magic.h>
78000 #include <linux/slab.h>
78001 +#include <linux/in.h>
78002
78003 #include <asm/uaccess.h>
78004 #include <asm/unistd.h>
78005 @@ -105,6 +106,8 @@
78006 #include <linux/sockios.h>
78007 #include <linux/atalk.h>
78008
78009 +#include <linux/grsock.h>
78010 +
78011 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
78012 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
78013 unsigned long nr_segs, loff_t pos);
78014 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
78015 &sockfs_dentry_operations, SOCKFS_MAGIC);
78016 }
78017
78018 -static struct vfsmount *sock_mnt __read_mostly;
78019 +struct vfsmount *sock_mnt __read_mostly;
78020
78021 static struct file_system_type sock_fs_type = {
78022 .name = "sockfs",
78023 @@ -1210,6 +1213,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
78024 return -EAFNOSUPPORT;
78025 if (type < 0 || type >= SOCK_MAX)
78026 return -EINVAL;
78027 + if (protocol < 0)
78028 + return -EINVAL;
78029
78030 /* Compatibility.
78031
78032 @@ -1341,6 +1346,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
78033 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
78034 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
78035
78036 + if(!gr_search_socket(family, type, protocol)) {
78037 + retval = -EACCES;
78038 + goto out;
78039 + }
78040 +
78041 + if (gr_handle_sock_all(family, type, protocol)) {
78042 + retval = -EACCES;
78043 + goto out;
78044 + }
78045 +
78046 retval = sock_create(family, type, protocol, &sock);
78047 if (retval < 0)
78048 goto out;
78049 @@ -1453,6 +1468,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
78050 if (sock) {
78051 err = move_addr_to_kernel(umyaddr, addrlen, &address);
78052 if (err >= 0) {
78053 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
78054 + err = -EACCES;
78055 + goto error;
78056 + }
78057 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
78058 + if (err)
78059 + goto error;
78060 +
78061 err = security_socket_bind(sock,
78062 (struct sockaddr *)&address,
78063 addrlen);
78064 @@ -1461,6 +1484,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
78065 (struct sockaddr *)
78066 &address, addrlen);
78067 }
78068 +error:
78069 fput_light(sock->file, fput_needed);
78070 }
78071 return err;
78072 @@ -1484,10 +1508,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
78073 if ((unsigned int)backlog > somaxconn)
78074 backlog = somaxconn;
78075
78076 + if (gr_handle_sock_server_other(sock->sk)) {
78077 + err = -EPERM;
78078 + goto error;
78079 + }
78080 +
78081 + err = gr_search_listen(sock);
78082 + if (err)
78083 + goto error;
78084 +
78085 err = security_socket_listen(sock, backlog);
78086 if (!err)
78087 err = sock->ops->listen(sock, backlog);
78088
78089 +error:
78090 fput_light(sock->file, fput_needed);
78091 }
78092 return err;
78093 @@ -1531,6 +1565,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78094 newsock->type = sock->type;
78095 newsock->ops = sock->ops;
78096
78097 + if (gr_handle_sock_server_other(sock->sk)) {
78098 + err = -EPERM;
78099 + sock_release(newsock);
78100 + goto out_put;
78101 + }
78102 +
78103 + err = gr_search_accept(sock);
78104 + if (err) {
78105 + sock_release(newsock);
78106 + goto out_put;
78107 + }
78108 +
78109 /*
78110 * We don't need try_module_get here, as the listening socket (sock)
78111 * has the protocol module (sock->ops->owner) held.
78112 @@ -1569,6 +1615,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78113 fd_install(newfd, newfile);
78114 err = newfd;
78115
78116 + gr_attach_curr_ip(newsock->sk);
78117 +
78118 out_put:
78119 fput_light(sock->file, fput_needed);
78120 out:
78121 @@ -1601,6 +1649,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78122 int, addrlen)
78123 {
78124 struct socket *sock;
78125 + struct sockaddr *sck;
78126 struct sockaddr_storage address;
78127 int err, fput_needed;
78128
78129 @@ -1611,6 +1660,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78130 if (err < 0)
78131 goto out_put;
78132
78133 + sck = (struct sockaddr *)&address;
78134 +
78135 + if (gr_handle_sock_client(sck)) {
78136 + err = -EACCES;
78137 + goto out_put;
78138 + }
78139 +
78140 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
78141 + if (err)
78142 + goto out_put;
78143 +
78144 err =
78145 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
78146 if (err)
78147 @@ -1965,7 +2025,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
78148 * checking falls down on this.
78149 */
78150 if (copy_from_user(ctl_buf,
78151 - (void __user __force *)msg_sys->msg_control,
78152 + (void __force_user *)msg_sys->msg_control,
78153 ctl_len))
78154 goto out_freectl;
78155 msg_sys->msg_control = ctl_buf;
78156 @@ -2133,7 +2193,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
78157 * kernel msghdr to use the kernel address space)
78158 */
78159
78160 - uaddr = (__force void __user *)msg_sys->msg_name;
78161 + uaddr = (void __force_user *)msg_sys->msg_name;
78162 uaddr_len = COMPAT_NAMELEN(msg);
78163 if (MSG_CMSG_COMPAT & flags) {
78164 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
78165 @@ -2761,7 +2821,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78166 }
78167
78168 ifr = compat_alloc_user_space(buf_size);
78169 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
78170 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
78171
78172 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
78173 return -EFAULT;
78174 @@ -2785,12 +2845,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78175 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
78176
78177 if (copy_in_user(rxnfc, compat_rxnfc,
78178 - (void *)(&rxnfc->fs.m_ext + 1) -
78179 - (void *)rxnfc) ||
78180 + (void __user *)(&rxnfc->fs.m_ext + 1) -
78181 + (void __user *)rxnfc) ||
78182 copy_in_user(&rxnfc->fs.ring_cookie,
78183 &compat_rxnfc->fs.ring_cookie,
78184 - (void *)(&rxnfc->fs.location + 1) -
78185 - (void *)&rxnfc->fs.ring_cookie) ||
78186 + (void __user *)(&rxnfc->fs.location + 1) -
78187 + (void __user *)&rxnfc->fs.ring_cookie) ||
78188 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
78189 sizeof(rxnfc->rule_cnt)))
78190 return -EFAULT;
78191 @@ -2802,12 +2862,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78192
78193 if (convert_out) {
78194 if (copy_in_user(compat_rxnfc, rxnfc,
78195 - (const void *)(&rxnfc->fs.m_ext + 1) -
78196 - (const void *)rxnfc) ||
78197 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
78198 + (const void __user *)rxnfc) ||
78199 copy_in_user(&compat_rxnfc->fs.ring_cookie,
78200 &rxnfc->fs.ring_cookie,
78201 - (const void *)(&rxnfc->fs.location + 1) -
78202 - (const void *)&rxnfc->fs.ring_cookie) ||
78203 + (const void __user *)(&rxnfc->fs.location + 1) -
78204 + (const void __user *)&rxnfc->fs.ring_cookie) ||
78205 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
78206 sizeof(rxnfc->rule_cnt)))
78207 return -EFAULT;
78208 @@ -2877,7 +2937,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
78209 old_fs = get_fs();
78210 set_fs(KERNEL_DS);
78211 err = dev_ioctl(net, cmd,
78212 - (struct ifreq __user __force *) &kifr);
78213 + (struct ifreq __force_user *) &kifr);
78214 set_fs(old_fs);
78215
78216 return err;
78217 @@ -2986,7 +3046,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
78218
78219 old_fs = get_fs();
78220 set_fs(KERNEL_DS);
78221 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
78222 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
78223 set_fs(old_fs);
78224
78225 if (cmd == SIOCGIFMAP && !err) {
78226 @@ -3091,7 +3151,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
78227 ret |= __get_user(rtdev, &(ur4->rt_dev));
78228 if (rtdev) {
78229 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
78230 - r4.rt_dev = (char __user __force *)devname;
78231 + r4.rt_dev = (char __force_user *)devname;
78232 devname[15] = 0;
78233 } else
78234 r4.rt_dev = NULL;
78235 @@ -3317,8 +3377,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
78236 int __user *uoptlen;
78237 int err;
78238
78239 - uoptval = (char __user __force *) optval;
78240 - uoptlen = (int __user __force *) optlen;
78241 + uoptval = (char __force_user *) optval;
78242 + uoptlen = (int __force_user *) optlen;
78243
78244 set_fs(KERNEL_DS);
78245 if (level == SOL_SOCKET)
78246 @@ -3338,7 +3398,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
78247 char __user *uoptval;
78248 int err;
78249
78250 - uoptval = (char __user __force *) optval;
78251 + uoptval = (char __force_user *) optval;
78252
78253 set_fs(KERNEL_DS);
78254 if (level == SOL_SOCKET)
78255 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
78256 index eda32ae..1c9fa7c 100644
78257 --- a/net/sunrpc/sched.c
78258 +++ b/net/sunrpc/sched.c
78259 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
78260 #ifdef RPC_DEBUG
78261 static void rpc_task_set_debuginfo(struct rpc_task *task)
78262 {
78263 - static atomic_t rpc_pid;
78264 + static atomic_unchecked_t rpc_pid;
78265
78266 - task->tk_pid = atomic_inc_return(&rpc_pid);
78267 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
78268 }
78269 #else
78270 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
78271 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
78272 index 8343737..677025e 100644
78273 --- a/net/sunrpc/xprtrdma/svc_rdma.c
78274 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
78275 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
78276 static unsigned int min_max_inline = 4096;
78277 static unsigned int max_max_inline = 65536;
78278
78279 -atomic_t rdma_stat_recv;
78280 -atomic_t rdma_stat_read;
78281 -atomic_t rdma_stat_write;
78282 -atomic_t rdma_stat_sq_starve;
78283 -atomic_t rdma_stat_rq_starve;
78284 -atomic_t rdma_stat_rq_poll;
78285 -atomic_t rdma_stat_rq_prod;
78286 -atomic_t rdma_stat_sq_poll;
78287 -atomic_t rdma_stat_sq_prod;
78288 +atomic_unchecked_t rdma_stat_recv;
78289 +atomic_unchecked_t rdma_stat_read;
78290 +atomic_unchecked_t rdma_stat_write;
78291 +atomic_unchecked_t rdma_stat_sq_starve;
78292 +atomic_unchecked_t rdma_stat_rq_starve;
78293 +atomic_unchecked_t rdma_stat_rq_poll;
78294 +atomic_unchecked_t rdma_stat_rq_prod;
78295 +atomic_unchecked_t rdma_stat_sq_poll;
78296 +atomic_unchecked_t rdma_stat_sq_prod;
78297
78298 /* Temporary NFS request map and context caches */
78299 struct kmem_cache *svc_rdma_map_cachep;
78300 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
78301 len -= *ppos;
78302 if (len > *lenp)
78303 len = *lenp;
78304 - if (len && copy_to_user(buffer, str_buf, len))
78305 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
78306 return -EFAULT;
78307 *lenp = len;
78308 *ppos += len;
78309 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
78310 {
78311 .procname = "rdma_stat_read",
78312 .data = &rdma_stat_read,
78313 - .maxlen = sizeof(atomic_t),
78314 + .maxlen = sizeof(atomic_unchecked_t),
78315 .mode = 0644,
78316 .proc_handler = read_reset_stat,
78317 },
78318 {
78319 .procname = "rdma_stat_recv",
78320 .data = &rdma_stat_recv,
78321 - .maxlen = sizeof(atomic_t),
78322 + .maxlen = sizeof(atomic_unchecked_t),
78323 .mode = 0644,
78324 .proc_handler = read_reset_stat,
78325 },
78326 {
78327 .procname = "rdma_stat_write",
78328 .data = &rdma_stat_write,
78329 - .maxlen = sizeof(atomic_t),
78330 + .maxlen = sizeof(atomic_unchecked_t),
78331 .mode = 0644,
78332 .proc_handler = read_reset_stat,
78333 },
78334 {
78335 .procname = "rdma_stat_sq_starve",
78336 .data = &rdma_stat_sq_starve,
78337 - .maxlen = sizeof(atomic_t),
78338 + .maxlen = sizeof(atomic_unchecked_t),
78339 .mode = 0644,
78340 .proc_handler = read_reset_stat,
78341 },
78342 {
78343 .procname = "rdma_stat_rq_starve",
78344 .data = &rdma_stat_rq_starve,
78345 - .maxlen = sizeof(atomic_t),
78346 + .maxlen = sizeof(atomic_unchecked_t),
78347 .mode = 0644,
78348 .proc_handler = read_reset_stat,
78349 },
78350 {
78351 .procname = "rdma_stat_rq_poll",
78352 .data = &rdma_stat_rq_poll,
78353 - .maxlen = sizeof(atomic_t),
78354 + .maxlen = sizeof(atomic_unchecked_t),
78355 .mode = 0644,
78356 .proc_handler = read_reset_stat,
78357 },
78358 {
78359 .procname = "rdma_stat_rq_prod",
78360 .data = &rdma_stat_rq_prod,
78361 - .maxlen = sizeof(atomic_t),
78362 + .maxlen = sizeof(atomic_unchecked_t),
78363 .mode = 0644,
78364 .proc_handler = read_reset_stat,
78365 },
78366 {
78367 .procname = "rdma_stat_sq_poll",
78368 .data = &rdma_stat_sq_poll,
78369 - .maxlen = sizeof(atomic_t),
78370 + .maxlen = sizeof(atomic_unchecked_t),
78371 .mode = 0644,
78372 .proc_handler = read_reset_stat,
78373 },
78374 {
78375 .procname = "rdma_stat_sq_prod",
78376 .data = &rdma_stat_sq_prod,
78377 - .maxlen = sizeof(atomic_t),
78378 + .maxlen = sizeof(atomic_unchecked_t),
78379 .mode = 0644,
78380 .proc_handler = read_reset_stat,
78381 },
78382 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78383 index 41cb63b..c4a1489 100644
78384 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78385 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78386 @@ -501,7 +501,7 @@ next_sge:
78387 svc_rdma_put_context(ctxt, 0);
78388 goto out;
78389 }
78390 - atomic_inc(&rdma_stat_read);
78391 + atomic_inc_unchecked(&rdma_stat_read);
78392
78393 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
78394 chl_map->ch[ch_no].count -= read_wr.num_sge;
78395 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78396 dto_q);
78397 list_del_init(&ctxt->dto_q);
78398 } else {
78399 - atomic_inc(&rdma_stat_rq_starve);
78400 + atomic_inc_unchecked(&rdma_stat_rq_starve);
78401 clear_bit(XPT_DATA, &xprt->xpt_flags);
78402 ctxt = NULL;
78403 }
78404 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78405 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
78406 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
78407 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
78408 - atomic_inc(&rdma_stat_recv);
78409 + atomic_inc_unchecked(&rdma_stat_recv);
78410
78411 /* Build up the XDR from the receive buffers. */
78412 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
78413 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78414 index 42eb7ba..c887c45 100644
78415 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78416 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78417 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
78418 write_wr.wr.rdma.remote_addr = to;
78419
78420 /* Post It */
78421 - atomic_inc(&rdma_stat_write);
78422 + atomic_inc_unchecked(&rdma_stat_write);
78423 if (svc_rdma_send(xprt, &write_wr))
78424 goto err;
78425 return 0;
78426 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78427 index 73b428b..5f3f8f3 100644
78428 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
78429 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78430 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78431 return;
78432
78433 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
78434 - atomic_inc(&rdma_stat_rq_poll);
78435 + atomic_inc_unchecked(&rdma_stat_rq_poll);
78436
78437 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
78438 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
78439 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78440 }
78441
78442 if (ctxt)
78443 - atomic_inc(&rdma_stat_rq_prod);
78444 + atomic_inc_unchecked(&rdma_stat_rq_prod);
78445
78446 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
78447 /*
78448 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78449 return;
78450
78451 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
78452 - atomic_inc(&rdma_stat_sq_poll);
78453 + atomic_inc_unchecked(&rdma_stat_sq_poll);
78454 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
78455 if (wc.status != IB_WC_SUCCESS)
78456 /* Close the transport */
78457 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78458 }
78459
78460 if (ctxt)
78461 - atomic_inc(&rdma_stat_sq_prod);
78462 + atomic_inc_unchecked(&rdma_stat_sq_prod);
78463 }
78464
78465 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
78466 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
78467 spin_lock_bh(&xprt->sc_lock);
78468 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
78469 spin_unlock_bh(&xprt->sc_lock);
78470 - atomic_inc(&rdma_stat_sq_starve);
78471 + atomic_inc_unchecked(&rdma_stat_sq_starve);
78472
78473 /* See if we can opportunistically reap SQ WR to make room */
78474 sq_cq_reap(xprt);
78475 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
78476 index e3a6e37..be2ea77 100644
78477 --- a/net/sysctl_net.c
78478 +++ b/net/sysctl_net.c
78479 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
78480 struct ctl_table *table)
78481 {
78482 /* Allow network administrator to have same access as root. */
78483 - if (capable(CAP_NET_ADMIN)) {
78484 + if (capable_nolog(CAP_NET_ADMIN)) {
78485 int mode = (table->mode >> 6) & 7;
78486 return (mode << 6) | (mode << 3) | mode;
78487 }
78488 diff --git a/net/tipc/link.c b/net/tipc/link.c
78489 index 7a614f4..b14dbd2 100644
78490 --- a/net/tipc/link.c
78491 +++ b/net/tipc/link.c
78492 @@ -1164,7 +1164,7 @@ static int link_send_sections_long(struct tipc_port *sender,
78493 struct tipc_msg fragm_hdr;
78494 struct sk_buff *buf, *buf_chain, *prev;
78495 u32 fragm_crs, fragm_rest, hsz, sect_rest;
78496 - const unchar *sect_crs;
78497 + const unchar __user *sect_crs;
78498 int curr_sect;
78499 u32 fragm_no;
78500
78501 @@ -1205,7 +1205,7 @@ again:
78502
78503 if (!sect_rest) {
78504 sect_rest = msg_sect[++curr_sect].iov_len;
78505 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
78506 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
78507 }
78508
78509 if (sect_rest < fragm_rest)
78510 @@ -1224,7 +1224,7 @@ error:
78511 }
78512 } else
78513 skb_copy_to_linear_data_offset(buf, fragm_crs,
78514 - sect_crs, sz);
78515 + (const void __force_kernel *)sect_crs, sz);
78516 sect_crs += sz;
78517 sect_rest -= sz;
78518 fragm_crs += sz;
78519 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
78520 index deea0d2..fa13bd7 100644
78521 --- a/net/tipc/msg.c
78522 +++ b/net/tipc/msg.c
78523 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
78524 msg_sect[cnt].iov_len);
78525 else
78526 skb_copy_to_linear_data_offset(*buf, pos,
78527 - msg_sect[cnt].iov_base,
78528 + (const void __force_kernel *)msg_sect[cnt].iov_base,
78529 msg_sect[cnt].iov_len);
78530 pos += msg_sect[cnt].iov_len;
78531 }
78532 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
78533 index f976e9cd..560d055 100644
78534 --- a/net/tipc/subscr.c
78535 +++ b/net/tipc/subscr.c
78536 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
78537 {
78538 struct iovec msg_sect;
78539
78540 - msg_sect.iov_base = (void *)&sub->evt;
78541 + msg_sect.iov_base = (void __force_user *)&sub->evt;
78542 msg_sect.iov_len = sizeof(struct tipc_event);
78543
78544 sub->evt.event = htohl(event, sub->swap);
78545 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
78546 index 641f2e4..a63f5e1 100644
78547 --- a/net/unix/af_unix.c
78548 +++ b/net/unix/af_unix.c
78549 @@ -780,6 +780,12 @@ static struct sock *unix_find_other(struct net *net,
78550 err = -ECONNREFUSED;
78551 if (!S_ISSOCK(inode->i_mode))
78552 goto put_fail;
78553 +
78554 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
78555 + err = -EACCES;
78556 + goto put_fail;
78557 + }
78558 +
78559 u = unix_find_socket_byinode(inode);
78560 if (!u)
78561 goto put_fail;
78562 @@ -800,6 +806,13 @@ static struct sock *unix_find_other(struct net *net,
78563 if (u) {
78564 struct dentry *dentry;
78565 dentry = unix_sk(u)->path.dentry;
78566 +
78567 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
78568 + err = -EPERM;
78569 + sock_put(u);
78570 + goto fail;
78571 + }
78572 +
78573 if (dentry)
78574 touch_atime(&unix_sk(u)->path);
78575 } else
78576 @@ -882,11 +895,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
78577 err = security_path_mknod(&path, dentry, mode, 0);
78578 if (err)
78579 goto out_mknod_drop_write;
78580 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
78581 + err = -EACCES;
78582 + goto out_mknod_drop_write;
78583 + }
78584 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
78585 out_mknod_drop_write:
78586 mnt_drop_write(path.mnt);
78587 if (err)
78588 goto out_mknod_dput;
78589 +
78590 + gr_handle_create(dentry, path.mnt);
78591 +
78592 mutex_unlock(&path.dentry->d_inode->i_mutex);
78593 dput(path.dentry);
78594 path.dentry = dentry;
78595 diff --git a/net/wireless/core.h b/net/wireless/core.h
78596 index 8523f38..79f6091 100644
78597 --- a/net/wireless/core.h
78598 +++ b/net/wireless/core.h
78599 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
78600 struct mutex mtx;
78601
78602 /* rfkill support */
78603 - struct rfkill_ops rfkill_ops;
78604 + rfkill_ops_no_const rfkill_ops;
78605 struct rfkill *rfkill;
78606 struct work_struct rfkill_sync;
78607
78608 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
78609 index b0eb7aa..7d73e82 100644
78610 --- a/net/wireless/wext-core.c
78611 +++ b/net/wireless/wext-core.c
78612 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78613 */
78614
78615 /* Support for very large requests */
78616 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
78617 - (user_length > descr->max_tokens)) {
78618 + if (user_length > descr->max_tokens) {
78619 /* Allow userspace to GET more than max so
78620 * we can support any size GET requests.
78621 * There is still a limit : -ENOMEM.
78622 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78623 }
78624 }
78625
78626 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
78627 - /*
78628 - * If this is a GET, but not NOMAX, it means that the extra
78629 - * data is not bounded by userspace, but by max_tokens. Thus
78630 - * set the length to max_tokens. This matches the extra data
78631 - * allocation.
78632 - * The driver should fill it with the number of tokens it
78633 - * provided, and it may check iwp->length rather than having
78634 - * knowledge of max_tokens. If the driver doesn't change the
78635 - * iwp->length, this ioctl just copies back max_token tokens
78636 - * filled with zeroes. Hopefully the driver isn't claiming
78637 - * them to be valid data.
78638 - */
78639 - iwp->length = descr->max_tokens;
78640 - }
78641 -
78642 err = handler(dev, info, (union iwreq_data *) iwp, extra);
78643
78644 iwp->length += essid_compat;
78645 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
78646 index ccfbd32..9b61cf9f 100644
78647 --- a/net/xfrm/xfrm_policy.c
78648 +++ b/net/xfrm/xfrm_policy.c
78649 @@ -300,7 +300,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
78650 {
78651 policy->walk.dead = 1;
78652
78653 - atomic_inc(&policy->genid);
78654 + atomic_inc_unchecked(&policy->genid);
78655
78656 if (del_timer(&policy->timer))
78657 xfrm_pol_put(policy);
78658 @@ -584,7 +584,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
78659 hlist_add_head(&policy->bydst, chain);
78660 xfrm_pol_hold(policy);
78661 net->xfrm.policy_count[dir]++;
78662 - atomic_inc(&flow_cache_genid);
78663 + atomic_inc_unchecked(&flow_cache_genid);
78664 if (delpol)
78665 __xfrm_policy_unlink(delpol, dir);
78666 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
78667 @@ -1532,7 +1532,7 @@ free_dst:
78668 goto out;
78669 }
78670
78671 -static int inline
78672 +static inline int
78673 xfrm_dst_alloc_copy(void **target, const void *src, int size)
78674 {
78675 if (!*target) {
78676 @@ -1544,7 +1544,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
78677 return 0;
78678 }
78679
78680 -static int inline
78681 +static inline int
78682 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78683 {
78684 #ifdef CONFIG_XFRM_SUB_POLICY
78685 @@ -1556,7 +1556,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78686 #endif
78687 }
78688
78689 -static int inline
78690 +static inline int
78691 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
78692 {
78693 #ifdef CONFIG_XFRM_SUB_POLICY
78694 @@ -1650,7 +1650,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
78695
78696 xdst->num_pols = num_pols;
78697 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
78698 - xdst->policy_genid = atomic_read(&pols[0]->genid);
78699 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
78700
78701 return xdst;
78702 }
78703 @@ -2350,7 +2350,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
78704 if (xdst->xfrm_genid != dst->xfrm->genid)
78705 return 0;
78706 if (xdst->num_pols > 0 &&
78707 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
78708 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
78709 return 0;
78710
78711 mtu = dst_mtu(dst->child);
78712 @@ -2887,7 +2887,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
78713 sizeof(pol->xfrm_vec[i].saddr));
78714 pol->xfrm_vec[i].encap_family = mp->new_family;
78715 /* flush bundles */
78716 - atomic_inc(&pol->genid);
78717 + atomic_inc_unchecked(&pol->genid);
78718 }
78719 }
78720
78721 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
78722 index ff1720d..ed8475e 100644
78723 --- a/scripts/Makefile.build
78724 +++ b/scripts/Makefile.build
78725 @@ -111,7 +111,7 @@ endif
78726 endif
78727
78728 # Do not include host rules unless needed
78729 -ifneq ($(hostprogs-y)$(hostprogs-m),)
78730 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
78731 include scripts/Makefile.host
78732 endif
78733
78734 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
78735 index 686cb0d..9d653bf 100644
78736 --- a/scripts/Makefile.clean
78737 +++ b/scripts/Makefile.clean
78738 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
78739 __clean-files := $(extra-y) $(always) \
78740 $(targets) $(clean-files) \
78741 $(host-progs) \
78742 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
78743 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
78744 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
78745
78746 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
78747
78748 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
78749 index 1ac414f..38575f7 100644
78750 --- a/scripts/Makefile.host
78751 +++ b/scripts/Makefile.host
78752 @@ -31,6 +31,8 @@
78753 # Note: Shared libraries consisting of C++ files are not supported
78754
78755 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
78756 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
78757 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
78758
78759 # C code
78760 # Executables compiled from a single .c file
78761 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
78762 # Shared libaries (only .c supported)
78763 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
78764 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
78765 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
78766 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
78767 # Remove .so files from "xxx-objs"
78768 host-cobjs := $(filter-out %.so,$(host-cobjs))
78769 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
78770
78771 -#Object (.o) files used by the shared libaries
78772 +# Object (.o) files used by the shared libaries
78773 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
78774 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
78775
78776 # output directory for programs/.o files
78777 # hostprogs-y := tools/build may have been specified. Retrieve directory
78778 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
78779 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
78780 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
78781 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
78782 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
78783 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
78784 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
78785 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
78786
78787 obj-dirs += $(host-objdirs)
78788 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
78789 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
78790 $(call if_changed_dep,host-cshobjs)
78791
78792 +# Compile .c file, create position independent .o file
78793 +# host-cxxshobjs -> .o
78794 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
78795 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
78796 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
78797 + $(call if_changed_dep,host-cxxshobjs)
78798 +
78799 # Link a shared library, based on position independent .o files
78800 # *.o -> .so shared library (host-cshlib)
78801 quiet_cmd_host-cshlib = HOSTLLD -shared $@
78802 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
78803 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
78804 $(call if_changed,host-cshlib)
78805
78806 +# Link a shared library, based on position independent .o files
78807 +# *.o -> .so shared library (host-cxxshlib)
78808 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
78809 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
78810 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
78811 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
78812 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
78813 + $(call if_changed,host-cxxshlib)
78814 +
78815 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
78816 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
78817 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
78818
78819 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
78820 index cb1f50c..cef2a7c 100644
78821 --- a/scripts/basic/fixdep.c
78822 +++ b/scripts/basic/fixdep.c
78823 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
78824 /*
78825 * Lookup a value in the configuration string.
78826 */
78827 -static int is_defined_config(const char *name, int len, unsigned int hash)
78828 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
78829 {
78830 struct item *aux;
78831
78832 @@ -211,10 +211,10 @@ static void clear_config(void)
78833 /*
78834 * Record the use of a CONFIG_* word.
78835 */
78836 -static void use_config(const char *m, int slen)
78837 +static void use_config(const char *m, unsigned int slen)
78838 {
78839 unsigned int hash = strhash(m, slen);
78840 - int c, i;
78841 + unsigned int c, i;
78842
78843 if (is_defined_config(m, slen, hash))
78844 return;
78845 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
78846
78847 static void parse_config_file(const char *map, size_t len)
78848 {
78849 - const int *end = (const int *) (map + len);
78850 + const unsigned int *end = (const unsigned int *) (map + len);
78851 /* start at +1, so that p can never be < map */
78852 - const int *m = (const int *) map + 1;
78853 + const unsigned int *m = (const unsigned int *) map + 1;
78854 const char *p, *q;
78855
78856 for (; m < end; m++) {
78857 @@ -406,7 +406,7 @@ static void print_deps(void)
78858 static void traps(void)
78859 {
78860 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
78861 - int *p = (int *)test;
78862 + unsigned int *p = (unsigned int *)test;
78863
78864 if (*p != INT_CONF) {
78865 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
78866 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
78867 new file mode 100644
78868 index 0000000..008ac1a
78869 --- /dev/null
78870 +++ b/scripts/gcc-plugin.sh
78871 @@ -0,0 +1,17 @@
78872 +#!/bin/bash
78873 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
78874 +#include "gcc-plugin.h"
78875 +#include "tree.h"
78876 +#include "tm.h"
78877 +#include "rtl.h"
78878 +#ifdef ENABLE_BUILD_WITH_CXX
78879 +#warning $2
78880 +#else
78881 +#warning $1
78882 +#endif
78883 +EOF`
78884 +if [ $? -eq 0 ]
78885 +then
78886 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
78887 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
78888 +fi
78889 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
78890 index cd9c6c6..0c8f0fa 100644
78891 --- a/scripts/link-vmlinux.sh
78892 +++ b/scripts/link-vmlinux.sh
78893 @@ -147,7 +147,7 @@ else
78894 fi;
78895
78896 # final build of init/
78897 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
78898 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
78899
78900 kallsymso=""
78901 kallsyms_vmlinux=""
78902 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
78903 index 5759751..b170367 100644
78904 --- a/scripts/mod/file2alias.c
78905 +++ b/scripts/mod/file2alias.c
78906 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
78907 unsigned long size, unsigned long id_size,
78908 void *symval)
78909 {
78910 - int i;
78911 + unsigned int i;
78912
78913 if (size % id_size || size < id_size) {
78914 if (cross_build != 0)
78915 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
78916 /* USB is special because the bcdDevice can be matched against a numeric range */
78917 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
78918 static void do_usb_entry(struct usb_device_id *id,
78919 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
78920 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
78921 unsigned char range_lo, unsigned char range_hi,
78922 unsigned char max, struct module *mod)
78923 {
78924 @@ -259,7 +259,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
78925 {
78926 unsigned int devlo, devhi;
78927 unsigned char chi, clo, max;
78928 - int ndigits;
78929 + unsigned int ndigits;
78930
78931 id->match_flags = TO_NATIVE(id->match_flags);
78932 id->idVendor = TO_NATIVE(id->idVendor);
78933 @@ -504,7 +504,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
78934 for (i = 0; i < count; i++) {
78935 const char *id = (char *)devs[i].id;
78936 char acpi_id[sizeof(devs[0].id)];
78937 - int j;
78938 + unsigned int j;
78939
78940 buf_printf(&mod->dev_table_buf,
78941 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78942 @@ -534,7 +534,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78943
78944 for (j = 0; j < PNP_MAX_DEVICES; j++) {
78945 const char *id = (char *)card->devs[j].id;
78946 - int i2, j2;
78947 + unsigned int i2, j2;
78948 int dup = 0;
78949
78950 if (!id[0])
78951 @@ -560,7 +560,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78952 /* add an individual alias for every device entry */
78953 if (!dup) {
78954 char acpi_id[sizeof(card->devs[0].id)];
78955 - int k;
78956 + unsigned int k;
78957
78958 buf_printf(&mod->dev_table_buf,
78959 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78960 @@ -885,7 +885,7 @@ static void dmi_ascii_filter(char *d, const char *s)
78961 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
78962 char *alias)
78963 {
78964 - int i, j;
78965 + unsigned int i, j;
78966
78967 sprintf(alias, "dmi*");
78968
78969 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
78970 index 0f84bb3..2d42035 100644
78971 --- a/scripts/mod/modpost.c
78972 +++ b/scripts/mod/modpost.c
78973 @@ -925,6 +925,7 @@ enum mismatch {
78974 ANY_INIT_TO_ANY_EXIT,
78975 ANY_EXIT_TO_ANY_INIT,
78976 EXPORT_TO_INIT_EXIT,
78977 + DATA_TO_TEXT
78978 };
78979
78980 struct sectioncheck {
78981 @@ -1033,6 +1034,12 @@ const struct sectioncheck sectioncheck[] = {
78982 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
78983 .mismatch = EXPORT_TO_INIT_EXIT,
78984 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
78985 +},
78986 +/* Do not reference code from writable data */
78987 +{
78988 + .fromsec = { DATA_SECTIONS, NULL },
78989 + .tosec = { TEXT_SECTIONS, NULL },
78990 + .mismatch = DATA_TO_TEXT
78991 }
78992 };
78993
78994 @@ -1155,10 +1162,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
78995 continue;
78996 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
78997 continue;
78998 - if (sym->st_value == addr)
78999 - return sym;
79000 /* Find a symbol nearby - addr are maybe negative */
79001 d = sym->st_value - addr;
79002 + if (d == 0)
79003 + return sym;
79004 if (d < 0)
79005 d = addr - sym->st_value;
79006 if (d < distance) {
79007 @@ -1437,6 +1444,14 @@ static void report_sec_mismatch(const char *modname,
79008 tosym, prl_to, prl_to, tosym);
79009 free(prl_to);
79010 break;
79011 + case DATA_TO_TEXT:
79012 +#if 0
79013 + fprintf(stderr,
79014 + "The %s %s:%s references\n"
79015 + "the %s %s:%s%s\n",
79016 + from, fromsec, fromsym, to, tosec, tosym, to_p);
79017 +#endif
79018 + break;
79019 }
79020 fprintf(stderr, "\n");
79021 }
79022 @@ -1671,7 +1686,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
79023 static void check_sec_ref(struct module *mod, const char *modname,
79024 struct elf_info *elf)
79025 {
79026 - int i;
79027 + unsigned int i;
79028 Elf_Shdr *sechdrs = elf->sechdrs;
79029
79030 /* Walk through all sections */
79031 @@ -1769,7 +1784,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
79032 va_end(ap);
79033 }
79034
79035 -void buf_write(struct buffer *buf, const char *s, int len)
79036 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
79037 {
79038 if (buf->size - buf->pos < len) {
79039 buf->size += len + SZ;
79040 @@ -1987,7 +2002,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
79041 if (fstat(fileno(file), &st) < 0)
79042 goto close_write;
79043
79044 - if (st.st_size != b->pos)
79045 + if (st.st_size != (off_t)b->pos)
79046 goto close_write;
79047
79048 tmp = NOFAIL(malloc(b->pos));
79049 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
79050 index 51207e4..f7d603d 100644
79051 --- a/scripts/mod/modpost.h
79052 +++ b/scripts/mod/modpost.h
79053 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
79054
79055 struct buffer {
79056 char *p;
79057 - int pos;
79058 - int size;
79059 + unsigned int pos;
79060 + unsigned int size;
79061 };
79062
79063 void __attribute__((format(printf, 2, 3)))
79064 buf_printf(struct buffer *buf, const char *fmt, ...);
79065
79066 void
79067 -buf_write(struct buffer *buf, const char *s, int len);
79068 +buf_write(struct buffer *buf, const char *s, unsigned int len);
79069
79070 struct module {
79071 struct module *next;
79072 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
79073 index 9dfcd6d..099068e 100644
79074 --- a/scripts/mod/sumversion.c
79075 +++ b/scripts/mod/sumversion.c
79076 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
79077 goto out;
79078 }
79079
79080 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
79081 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
79082 warn("writing sum in %s failed: %s\n",
79083 filename, strerror(errno));
79084 goto out;
79085 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
79086 index 5c11312..72742b5 100644
79087 --- a/scripts/pnmtologo.c
79088 +++ b/scripts/pnmtologo.c
79089 @@ -237,14 +237,14 @@ static void write_header(void)
79090 fprintf(out, " * Linux logo %s\n", logoname);
79091 fputs(" */\n\n", out);
79092 fputs("#include <linux/linux_logo.h>\n\n", out);
79093 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
79094 + fprintf(out, "static unsigned char %s_data[] = {\n",
79095 logoname);
79096 }
79097
79098 static void write_footer(void)
79099 {
79100 fputs("\n};\n\n", out);
79101 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
79102 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
79103 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
79104 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
79105 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
79106 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
79107 fputs("\n};\n\n", out);
79108
79109 /* write logo clut */
79110 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
79111 + fprintf(out, "static unsigned char %s_clut[] = {\n",
79112 logoname);
79113 write_hex_cnt = 0;
79114 for (i = 0; i < logo_clutsize; i++) {
79115 diff --git a/security/Kconfig b/security/Kconfig
79116 index e9c6ac7..4349785 100644
79117 --- a/security/Kconfig
79118 +++ b/security/Kconfig
79119 @@ -4,6 +4,876 @@
79120
79121 menu "Security options"
79122
79123 +menu "Grsecurity"
79124 +
79125 + config ARCH_TRACK_EXEC_LIMIT
79126 + bool
79127 +
79128 + config PAX_KERNEXEC_PLUGIN
79129 + bool
79130 +
79131 + config PAX_PER_CPU_PGD
79132 + bool
79133 +
79134 + config TASK_SIZE_MAX_SHIFT
79135 + int
79136 + depends on X86_64
79137 + default 47 if !PAX_PER_CPU_PGD
79138 + default 42 if PAX_PER_CPU_PGD
79139 +
79140 + config PAX_ENABLE_PAE
79141 + bool
79142 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
79143 +
79144 + config PAX_USERCOPY_SLABS
79145 + bool
79146 +
79147 +config GRKERNSEC
79148 + bool "Grsecurity"
79149 + select CRYPTO
79150 + select CRYPTO_SHA256
79151 + select PROC_FS
79152 + select STOP_MACHINE
79153 + help
79154 + If you say Y here, you will be able to configure many features
79155 + that will enhance the security of your system. It is highly
79156 + recommended that you say Y here and read through the help
79157 + for each option so that you fully understand the features and
79158 + can evaluate their usefulness for your machine.
79159 +
79160 +choice
79161 + prompt "Configuration Method"
79162 + depends on GRKERNSEC
79163 + default GRKERNSEC_CONFIG_CUSTOM
79164 + help
79165 +
79166 +config GRKERNSEC_CONFIG_AUTO
79167 + bool "Automatic"
79168 + help
79169 + If you choose this configuration method, you'll be able to answer a small
79170 + number of simple questions about how you plan to use this kernel.
79171 + The settings of grsecurity and PaX will be automatically configured for
79172 + the highest commonly-used settings within the provided constraints.
79173 +
79174 + If you require additional configuration, custom changes can still be made
79175 + from the "custom configuration" menu.
79176 +
79177 +config GRKERNSEC_CONFIG_CUSTOM
79178 + bool "Custom"
79179 + help
79180 + If you choose this configuration method, you'll be able to configure all
79181 + grsecurity and PaX settings manually. Via this method, no options are
79182 + automatically enabled.
79183 +
79184 +endchoice
79185 +
79186 +choice
79187 + prompt "Usage Type"
79188 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
79189 + default GRKERNSEC_CONFIG_SERVER
79190 + help
79191 +
79192 +config GRKERNSEC_CONFIG_SERVER
79193 + bool "Server"
79194 + help
79195 + Choose this option if you plan to use this kernel on a server.
79196 +
79197 +config GRKERNSEC_CONFIG_DESKTOP
79198 + bool "Desktop"
79199 + help
79200 + Choose this option if you plan to use this kernel on a desktop.
79201 +
79202 +endchoice
79203 +
79204 +choice
79205 + prompt "Virtualization Type"
79206 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
79207 + default GRKERNSEC_CONFIG_VIRT_NONE
79208 + help
79209 +
79210 +config GRKERNSEC_CONFIG_VIRT_NONE
79211 + bool "None"
79212 + help
79213 + Choose this option if this kernel will be run on bare metal.
79214 +
79215 +config GRKERNSEC_CONFIG_VIRT_GUEST
79216 + bool "Guest"
79217 + help
79218 + Choose this option if this kernel will be run as a VM guest.
79219 +
79220 +config GRKERNSEC_CONFIG_VIRT_HOST
79221 + bool "Host"
79222 + help
79223 + Choose this option if this kernel will be run as a VM host.
79224 +
79225 +endchoice
79226 +
79227 +choice
79228 + prompt "Virtualization Hardware"
79229 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
79230 + help
79231 +
79232 +config GRKERNSEC_CONFIG_VIRT_EPT
79233 + bool "EPT/RVI Processor Support"
79234 + depends on X86
79235 + help
79236 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
79237 + hardware virtualization. This allows for additional kernel hardening protections
79238 + to operate without additional performance impact.
79239 +
79240 + To see if your Intel processor supports EPT, see:
79241 + http://ark.intel.com/Products/VirtualizationTechnology
79242 + (Most Core i3/5/7 support EPT)
79243 +
79244 + To see if your AMD processor supports RVI, see:
79245 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
79246 +
79247 +config GRKERNSEC_CONFIG_VIRT_SOFT
79248 + bool "First-gen/No Hardware Virtualization"
79249 + help
79250 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
79251 + support hardware virtualization or doesn't support the EPT/RVI extensions.
79252 +
79253 +endchoice
79254 +
79255 +choice
79256 + prompt "Virtualization Software"
79257 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
79258 + help
79259 +
79260 +config GRKERNSEC_CONFIG_VIRT_XEN
79261 + bool "Xen"
79262 + help
79263 + Choose this option if this kernel is running as a Xen guest or host.
79264 +
79265 +config GRKERNSEC_CONFIG_VIRT_VMWARE
79266 + bool "VMWare"
79267 + help
79268 + Choose this option if this kernel is running as a VMWare guest or host.
79269 +
79270 +config GRKERNSEC_CONFIG_VIRT_KVM
79271 + bool "KVM"
79272 + help
79273 + Choose this option if this kernel is running as a KVM guest or host.
79274 +
79275 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
79276 + bool "VirtualBox"
79277 + help
79278 + Choose this option if this kernel is running as a VirtualBox guest or host.
79279 +
79280 +endchoice
79281 +
79282 +choice
79283 + prompt "Required Priorities"
79284 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
79285 + default GRKERNSEC_CONFIG_PRIORITY_PERF
79286 + help
79287 +
79288 +config GRKERNSEC_CONFIG_PRIORITY_PERF
79289 + bool "Performance"
79290 + help
79291 + Choose this option if performance is of highest priority for this deployment
79292 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
79293 + and freed memory sanitizing will be disabled.
79294 +
79295 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
79296 + bool "Security"
79297 + help
79298 + Choose this option if security is of highest priority for this deployment of
79299 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
79300 + be enabled for this kernel. In a worst-case scenario, these features can
79301 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
79302 +
79303 +endchoice
79304 +
79305 +menu "Default Special Groups"
79306 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
79307 +
79308 +config GRKERNSEC_PROC_GID
79309 + int "GID exempted from /proc restrictions"
79310 + default 1001
79311 + help
79312 + Setting this GID determines which group will be exempted from
79313 + grsecurity's /proc restrictions, allowing users of the specified
79314 + group to view network statistics and the existence of other users'
79315 + processes on the system.
79316 +
79317 +config GRKERNSEC_TPE_GID
79318 + int "GID for untrusted users"
79319 + depends on GRKERNSEC_CONFIG_SERVER
79320 + default 1005
79321 + help
79322 + Setting this GID determines which group untrusted users should
79323 + be added to. These users will be placed under grsecurity's Trusted Path
79324 + Execution mechanism, preventing them from executing their own binaries.
79325 + The users will only be able to execute binaries in directories owned and
79326 + writable only by the root user.
79327 +
79328 +config GRKERNSEC_SYMLINKOWN_GID
79329 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
79330 + depends on GRKERNSEC_CONFIG_SERVER
79331 + default 1006
79332 + help
79333 + Setting this GID determines what group kernel-enforced
79334 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
79335 + is enabled, a sysctl option with name "symlinkown_gid" is created.
79336 +
79337 +
79338 +endmenu
79339 +
79340 +menu "Customize Configuration"
79341 +depends on GRKERNSEC
79342 +
79343 +menu "PaX"
79344 +
79345 +config PAX
79346 + bool "Enable various PaX features"
79347 + default y if GRKERNSEC_CONFIG_AUTO
79348 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
79349 + help
79350 + This allows you to enable various PaX features. PaX adds
79351 + intrusion prevention mechanisms to the kernel that reduce
79352 + the risks posed by exploitable memory corruption bugs.
79353 +
79354 +menu "PaX Control"
79355 + depends on PAX
79356 +
79357 +config PAX_SOFTMODE
79358 + bool 'Support soft mode'
79359 + help
79360 + Enabling this option will allow you to run PaX in soft mode, that
79361 + is, PaX features will not be enforced by default, only on executables
79362 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
79363 + support as they are the only way to mark executables for soft mode use.
79364 +
79365 + Soft mode can be activated by using the "pax_softmode=1" kernel command
79366 + line option on boot. Furthermore you can control various PaX features
79367 + at runtime via the entries in /proc/sys/kernel/pax.
79368 +
79369 +config PAX_EI_PAX
79370 + bool 'Use legacy ELF header marking'
79371 + default y if GRKERNSEC_CONFIG_AUTO
79372 + help
79373 + Enabling this option will allow you to control PaX features on
79374 + a per executable basis via the 'chpax' utility available at
79375 + http://pax.grsecurity.net/. The control flags will be read from
79376 + an otherwise reserved part of the ELF header. This marking has
79377 + numerous drawbacks (no support for soft-mode, toolchain does not
79378 + know about the non-standard use of the ELF header) therefore it
79379 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
79380 + support.
79381 +
79382 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
79383 + support as well, they will override the legacy EI_PAX marks.
79384 +
79385 + If you enable none of the marking options then all applications
79386 + will run with PaX enabled on them by default.
79387 +
79388 +config PAX_PT_PAX_FLAGS
79389 + bool 'Use ELF program header marking'
79390 + default y if GRKERNSEC_CONFIG_AUTO
79391 + help
79392 + Enabling this option will allow you to control PaX features on
79393 + a per executable basis via the 'paxctl' utility available at
79394 + http://pax.grsecurity.net/. The control flags will be read from
79395 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
79396 + has the benefits of supporting both soft mode and being fully
79397 + integrated into the toolchain (the binutils patch is available
79398 + from http://pax.grsecurity.net).
79399 +
79400 + Note that if you enable the legacy EI_PAX marking support as well,
79401 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
79402 +
79403 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79404 + must make sure that the marks are the same if a binary has both marks.
79405 +
79406 + If you enable none of the marking options then all applications
79407 + will run with PaX enabled on them by default.
79408 +
79409 +config PAX_XATTR_PAX_FLAGS
79410 + bool 'Use filesystem extended attributes marking'
79411 + default y if GRKERNSEC_CONFIG_AUTO
79412 + select CIFS_XATTR if CIFS
79413 + select EXT2_FS_XATTR if EXT2_FS
79414 + select EXT3_FS_XATTR if EXT3_FS
79415 + select EXT4_FS_XATTR if EXT4_FS
79416 + select JFFS2_FS_XATTR if JFFS2_FS
79417 + select REISERFS_FS_XATTR if REISERFS_FS
79418 + select SQUASHFS_XATTR if SQUASHFS
79419 + select TMPFS_XATTR if TMPFS
79420 + select UBIFS_FS_XATTR if UBIFS_FS
79421 + help
79422 + Enabling this option will allow you to control PaX features on
79423 + a per executable basis via the 'setfattr' utility. The control
79424 + flags will be read from the user.pax.flags extended attribute of
79425 + the file. This marking has the benefit of supporting binary-only
79426 + applications that self-check themselves (e.g., skype) and would
79427 + not tolerate chpax/paxctl changes. The main drawback is that
79428 + extended attributes are not supported by some filesystems (e.g.,
79429 + isofs, udf, vfat) so copying files through such filesystems will
79430 + lose the extended attributes and these PaX markings.
79431 +
79432 + Note that if you enable the legacy EI_PAX marking support as well,
79433 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
79434 +
79435 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79436 + must make sure that the marks are the same if a binary has both marks.
79437 +
79438 + If you enable none of the marking options then all applications
79439 + will run with PaX enabled on them by default.
79440 +
79441 +choice
79442 + prompt 'MAC system integration'
79443 + default PAX_HAVE_ACL_FLAGS
79444 + help
79445 + Mandatory Access Control systems have the option of controlling
79446 + PaX flags on a per executable basis, choose the method supported
79447 + by your particular system.
79448 +
79449 + - "none": if your MAC system does not interact with PaX,
79450 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
79451 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
79452 +
79453 + NOTE: this option is for developers/integrators only.
79454 +
79455 + config PAX_NO_ACL_FLAGS
79456 + bool 'none'
79457 +
79458 + config PAX_HAVE_ACL_FLAGS
79459 + bool 'direct'
79460 +
79461 + config PAX_HOOK_ACL_FLAGS
79462 + bool 'hook'
79463 +endchoice
79464 +
79465 +endmenu
79466 +
79467 +menu "Non-executable pages"
79468 + depends on PAX
79469 +
79470 +config PAX_NOEXEC
79471 + bool "Enforce non-executable pages"
79472 + default y if GRKERNSEC_CONFIG_AUTO
79473 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
79474 + help
79475 + By design some architectures do not allow for protecting memory
79476 + pages against execution or even if they do, Linux does not make
79477 + use of this feature. In practice this means that if a page is
79478 + readable (such as the stack or heap) it is also executable.
79479 +
79480 + There is a well known exploit technique that makes use of this
79481 + fact and a common programming mistake where an attacker can
79482 + introduce code of his choice somewhere in the attacked program's
79483 + memory (typically the stack or the heap) and then execute it.
79484 +
79485 + If the attacked program was running with different (typically
79486 + higher) privileges than that of the attacker, then he can elevate
79487 + his own privilege level (e.g. get a root shell, write to files for
79488 + which he does not have write access to, etc).
79489 +
79490 + Enabling this option will let you choose from various features
79491 + that prevent the injection and execution of 'foreign' code in
79492 + a program.
79493 +
79494 + This will also break programs that rely on the old behaviour and
79495 + expect that dynamically allocated memory via the malloc() family
79496 + of functions is executable (which it is not). Notable examples
79497 + are the XFree86 4.x server, the java runtime and wine.
79498 +
79499 +config PAX_PAGEEXEC
79500 + bool "Paging based non-executable pages"
79501 + default y if GRKERNSEC_CONFIG_AUTO
79502 + 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)
79503 + select S390_SWITCH_AMODE if S390
79504 + select S390_EXEC_PROTECT if S390
79505 + select ARCH_TRACK_EXEC_LIMIT if X86_32
79506 + help
79507 + This implementation is based on the paging feature of the CPU.
79508 + On i386 without hardware non-executable bit support there is a
79509 + variable but usually low performance impact, however on Intel's
79510 + P4 core based CPUs it is very high so you should not enable this
79511 + for kernels meant to be used on such CPUs.
79512 +
79513 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
79514 + with hardware non-executable bit support there is no performance
79515 + impact, on ppc the impact is negligible.
79516 +
79517 + Note that several architectures require various emulations due to
79518 + badly designed userland ABIs, this will cause a performance impact
79519 + but will disappear as soon as userland is fixed. For example, ppc
79520 + userland MUST have been built with secure-plt by a recent toolchain.
79521 +
79522 +config PAX_SEGMEXEC
79523 + bool "Segmentation based non-executable pages"
79524 + default y if GRKERNSEC_CONFIG_AUTO
79525 + depends on PAX_NOEXEC && X86_32
79526 + help
79527 + This implementation is based on the segmentation feature of the
79528 + CPU and has a very small performance impact, however applications
79529 + will be limited to a 1.5 GB address space instead of the normal
79530 + 3 GB.
79531 +
79532 +config PAX_EMUTRAMP
79533 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
79534 + default y if PARISC
79535 + help
79536 + There are some programs and libraries that for one reason or
79537 + another attempt to execute special small code snippets from
79538 + non-executable memory pages. Most notable examples are the
79539 + signal handler return code generated by the kernel itself and
79540 + the GCC trampolines.
79541 +
79542 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
79543 + such programs will no longer work under your kernel.
79544 +
79545 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
79546 + utilities to enable trampoline emulation for the affected programs
79547 + yet still have the protection provided by the non-executable pages.
79548 +
79549 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
79550 + your system will not even boot.
79551 +
79552 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
79553 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
79554 + for the affected files.
79555 +
79556 + NOTE: enabling this feature *may* open up a loophole in the
79557 + protection provided by non-executable pages that an attacker
79558 + could abuse. Therefore the best solution is to not have any
79559 + files on your system that would require this option. This can
79560 + be achieved by not using libc5 (which relies on the kernel
79561 + signal handler return code) and not using or rewriting programs
79562 + that make use of the nested function implementation of GCC.
79563 + Skilled users can just fix GCC itself so that it implements
79564 + nested function calls in a way that does not interfere with PaX.
79565 +
79566 +config PAX_EMUSIGRT
79567 + bool "Automatically emulate sigreturn trampolines"
79568 + depends on PAX_EMUTRAMP && PARISC
79569 + default y
79570 + help
79571 + Enabling this option will have the kernel automatically detect
79572 + and emulate signal return trampolines executing on the stack
79573 + that would otherwise lead to task termination.
79574 +
79575 + This solution is intended as a temporary one for users with
79576 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
79577 + Modula-3 runtime, etc) or executables linked to such, basically
79578 + everything that does not specify its own SA_RESTORER function in
79579 + normal executable memory like glibc 2.1+ does.
79580 +
79581 + On parisc you MUST enable this option, otherwise your system will
79582 + not even boot.
79583 +
79584 + NOTE: this feature cannot be disabled on a per executable basis
79585 + and since it *does* open up a loophole in the protection provided
79586 + by non-executable pages, the best solution is to not have any
79587 + files on your system that would require this option.
79588 +
79589 +config PAX_MPROTECT
79590 + bool "Restrict mprotect()"
79591 + default y if GRKERNSEC_CONFIG_AUTO
79592 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
79593 + help
79594 + Enabling this option will prevent programs from
79595 + - changing the executable status of memory pages that were
79596 + not originally created as executable,
79597 + - making read-only executable pages writable again,
79598 + - creating executable pages from anonymous memory,
79599 + - making read-only-after-relocations (RELRO) data pages writable again.
79600 +
79601 + You should say Y here to complete the protection provided by
79602 + the enforcement of non-executable pages.
79603 +
79604 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79605 + this feature on a per file basis.
79606 +
79607 +config PAX_MPROTECT_COMPAT
79608 + bool "Use legacy/compat protection demoting (read help)"
79609 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
79610 + depends on PAX_MPROTECT
79611 + help
79612 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
79613 + by sending the proper error code to the application. For some broken
79614 + userland, this can cause problems with Python or other applications. The
79615 + current implementation however allows for applications like clamav to
79616 + detect if JIT compilation/execution is allowed and to fall back gracefully
79617 + to an interpreter-based mode if it does not. While we encourage everyone
79618 + to use the current implementation as-is and push upstream to fix broken
79619 + userland (note that the RWX logging option can assist with this), in some
79620 + environments this may not be possible. Having to disable MPROTECT
79621 + completely on certain binaries reduces the security benefit of PaX,
79622 + so this option is provided for those environments to revert to the old
79623 + behavior.
79624 +
79625 +config PAX_ELFRELOCS
79626 + bool "Allow ELF text relocations (read help)"
79627 + depends on PAX_MPROTECT
79628 + default n
79629 + help
79630 + Non-executable pages and mprotect() restrictions are effective
79631 + in preventing the introduction of new executable code into an
79632 + attacked task's address space. There remain only two venues
79633 + for this kind of attack: if the attacker can execute already
79634 + existing code in the attacked task then he can either have it
79635 + create and mmap() a file containing his code or have it mmap()
79636 + an already existing ELF library that does not have position
79637 + independent code in it and use mprotect() on it to make it
79638 + writable and copy his code there. While protecting against
79639 + the former approach is beyond PaX, the latter can be prevented
79640 + by having only PIC ELF libraries on one's system (which do not
79641 + need to relocate their code). If you are sure this is your case,
79642 + as is the case with all modern Linux distributions, then leave
79643 + this option disabled. You should say 'n' here.
79644 +
79645 +config PAX_ETEXECRELOCS
79646 + bool "Allow ELF ET_EXEC text relocations"
79647 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
79648 + select PAX_ELFRELOCS
79649 + default y
79650 + help
79651 + On some architectures there are incorrectly created applications
79652 + that require text relocations and would not work without enabling
79653 + this option. If you are an alpha, ia64 or parisc user, you should
79654 + enable this option and disable it once you have made sure that
79655 + none of your applications need it.
79656 +
79657 +config PAX_EMUPLT
79658 + bool "Automatically emulate ELF PLT"
79659 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
79660 + default y
79661 + help
79662 + Enabling this option will have the kernel automatically detect
79663 + and emulate the Procedure Linkage Table entries in ELF files.
79664 + On some architectures such entries are in writable memory, and
79665 + become non-executable leading to task termination. Therefore
79666 + it is mandatory that you enable this option on alpha, parisc,
79667 + sparc and sparc64, otherwise your system would not even boot.
79668 +
79669 + NOTE: this feature *does* open up a loophole in the protection
79670 + provided by the non-executable pages, therefore the proper
79671 + solution is to modify the toolchain to produce a PLT that does
79672 + not need to be writable.
79673 +
79674 +config PAX_DLRESOLVE
79675 + bool 'Emulate old glibc resolver stub'
79676 + depends on PAX_EMUPLT && SPARC
79677 + default n
79678 + help
79679 + This option is needed if userland has an old glibc (before 2.4)
79680 + that puts a 'save' instruction into the runtime generated resolver
79681 + stub that needs special emulation.
79682 +
79683 +config PAX_KERNEXEC
79684 + bool "Enforce non-executable kernel pages"
79685 + 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))
79686 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
79687 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
79688 + select PAX_KERNEXEC_PLUGIN if X86_64
79689 + help
79690 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
79691 + that is, enabling this option will make it harder to inject
79692 + and execute 'foreign' code in kernel memory itself.
79693 +
79694 + Note that on x86_64 kernels there is a known regression when
79695 + this feature and KVM/VMX are both enabled in the host kernel.
79696 +
79697 +choice
79698 + prompt "Return Address Instrumentation Method"
79699 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
79700 + depends on PAX_KERNEXEC_PLUGIN
79701 + help
79702 + Select the method used to instrument function pointer dereferences.
79703 + Note that binary modules cannot be instrumented by this approach.
79704 +
79705 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
79706 + bool "bts"
79707 + help
79708 + This method is compatible with binary only modules but has
79709 + a higher runtime overhead.
79710 +
79711 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
79712 + bool "or"
79713 + depends on !PARAVIRT
79714 + help
79715 + This method is incompatible with binary only modules but has
79716 + a lower runtime overhead.
79717 +endchoice
79718 +
79719 +config PAX_KERNEXEC_PLUGIN_METHOD
79720 + string
79721 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
79722 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
79723 + default ""
79724 +
79725 +config PAX_KERNEXEC_MODULE_TEXT
79726 + int "Minimum amount of memory reserved for module code"
79727 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
79728 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
79729 + depends on PAX_KERNEXEC && X86_32 && MODULES
79730 + help
79731 + Due to implementation details the kernel must reserve a fixed
79732 + amount of memory for module code at compile time that cannot be
79733 + changed at runtime. Here you can specify the minimum amount
79734 + in MB that will be reserved. Due to the same implementation
79735 + details this size will always be rounded up to the next 2/4 MB
79736 + boundary (depends on PAE) so the actually available memory for
79737 + module code will usually be more than this minimum.
79738 +
79739 + The default 4 MB should be enough for most users but if you have
79740 + an excessive number of modules (e.g., most distribution configs
79741 + compile many drivers as modules) or use huge modules such as
79742 + nvidia's kernel driver, you will need to adjust this amount.
79743 + A good rule of thumb is to look at your currently loaded kernel
79744 + modules and add up their sizes.
79745 +
79746 +endmenu
79747 +
79748 +menu "Address Space Layout Randomization"
79749 + depends on PAX
79750 +
79751 +config PAX_ASLR
79752 + bool "Address Space Layout Randomization"
79753 + default y if GRKERNSEC_CONFIG_AUTO
79754 + help
79755 + Many if not most exploit techniques rely on the knowledge of
79756 + certain addresses in the attacked program. The following options
79757 + will allow the kernel to apply a certain amount of randomization
79758 + to specific parts of the program thereby forcing an attacker to
79759 + guess them in most cases. Any failed guess will most likely crash
79760 + the attacked program which allows the kernel to detect such attempts
79761 + and react on them. PaX itself provides no reaction mechanisms,
79762 + instead it is strongly encouraged that you make use of Nergal's
79763 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
79764 + (http://www.grsecurity.net/) built-in crash detection features or
79765 + develop one yourself.
79766 +
79767 + By saying Y here you can choose to randomize the following areas:
79768 + - top of the task's kernel stack
79769 + - top of the task's userland stack
79770 + - base address for mmap() requests that do not specify one
79771 + (this includes all libraries)
79772 + - base address of the main executable
79773 +
79774 + It is strongly recommended to say Y here as address space layout
79775 + randomization has negligible impact on performance yet it provides
79776 + a very effective protection.
79777 +
79778 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79779 + this feature on a per file basis.
79780 +
79781 +config PAX_RANDKSTACK
79782 + bool "Randomize kernel stack base"
79783 + default y if GRKERNSEC_CONFIG_AUTO
79784 + depends on X86_TSC && X86
79785 + help
79786 + By saying Y here the kernel will randomize every task's kernel
79787 + stack on every system call. This will not only force an attacker
79788 + to guess it but also prevent him from making use of possible
79789 + leaked information about it.
79790 +
79791 + Since the kernel stack is a rather scarce resource, randomization
79792 + may cause unexpected stack overflows, therefore you should very
79793 + carefully test your system. Note that once enabled in the kernel
79794 + configuration, this feature cannot be disabled on a per file basis.
79795 +
79796 +config PAX_RANDUSTACK
79797 + bool "Randomize user stack base"
79798 + default y if GRKERNSEC_CONFIG_AUTO
79799 + depends on PAX_ASLR
79800 + help
79801 + By saying Y here the kernel will randomize every task's userland
79802 + stack. The randomization is done in two steps where the second
79803 + one may apply a big amount of shift to the top of the stack and
79804 + cause problems for programs that want to use lots of memory (more
79805 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
79806 + For this reason the second step can be controlled by 'chpax' or
79807 + 'paxctl' on a per file basis.
79808 +
79809 +config PAX_RANDMMAP
79810 + bool "Randomize mmap() base"
79811 + default y if GRKERNSEC_CONFIG_AUTO
79812 + depends on PAX_ASLR
79813 + help
79814 + By saying Y here the kernel will use a randomized base address for
79815 + mmap() requests that do not specify one themselves. As a result
79816 + all dynamically loaded libraries will appear at random addresses
79817 + and therefore be harder to exploit by a technique where an attacker
79818 + attempts to execute library code for his purposes (e.g. spawn a
79819 + shell from an exploited program that is running at an elevated
79820 + privilege level).
79821 +
79822 + Furthermore, if a program is relinked as a dynamic ELF file, its
79823 + base address will be randomized as well, completing the full
79824 + randomization of the address space layout. Attacking such programs
79825 + becomes a guess game. You can find an example of doing this at
79826 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
79827 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
79828 +
79829 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
79830 + feature on a per file basis.
79831 +
79832 +endmenu
79833 +
79834 +menu "Miscellaneous hardening features"
79835 +
79836 +config PAX_MEMORY_SANITIZE
79837 + bool "Sanitize all freed memory"
79838 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
79839 + depends on !HIBERNATION
79840 + help
79841 + By saying Y here the kernel will erase memory pages as soon as they
79842 + are freed. This in turn reduces the lifetime of data stored in the
79843 + pages, making it less likely that sensitive information such as
79844 + passwords, cryptographic secrets, etc stay in memory for too long.
79845 +
79846 + This is especially useful for programs whose runtime is short, long
79847 + lived processes and the kernel itself benefit from this as long as
79848 + they operate on whole memory pages and ensure timely freeing of pages
79849 + that may hold sensitive information.
79850 +
79851 + The tradeoff is performance impact, on a single CPU system kernel
79852 + compilation sees a 3% slowdown, other systems and workloads may vary
79853 + and you are advised to test this feature on your expected workload
79854 + before deploying it.
79855 +
79856 + Note that this feature does not protect data stored in live pages,
79857 + e.g., process memory swapped to disk may stay there for a long time.
79858 +
79859 +config PAX_MEMORY_STACKLEAK
79860 + bool "Sanitize kernel stack"
79861 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
79862 + depends on X86
79863 + help
79864 + By saying Y here the kernel will erase the kernel stack before it
79865 + returns from a system call. This in turn reduces the information
79866 + that a kernel stack leak bug can reveal.
79867 +
79868 + Note that such a bug can still leak information that was put on
79869 + the stack by the current system call (the one eventually triggering
79870 + the bug) but traces of earlier system calls on the kernel stack
79871 + cannot leak anymore.
79872 +
79873 + The tradeoff is performance impact: on a single CPU system kernel
79874 + compilation sees a 1% slowdown, other systems and workloads may vary
79875 + and you are advised to test this feature on your expected workload
79876 + before deploying it.
79877 +
79878 + Note: full support for this feature requires gcc with plugin support
79879 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
79880 + versions means that functions with large enough stack frames may
79881 + leave uninitialized memory behind that may be exposed to a later
79882 + syscall leaking the stack.
79883 +
79884 +config PAX_MEMORY_UDEREF
79885 + bool "Prevent invalid userland pointer dereference"
79886 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
79887 + depends on X86 && !UML_X86 && !XEN
79888 + select PAX_PER_CPU_PGD if X86_64
79889 + help
79890 + By saying Y here the kernel will be prevented from dereferencing
79891 + userland pointers in contexts where the kernel expects only kernel
79892 + pointers. This is both a useful runtime debugging feature and a
79893 + security measure that prevents exploiting a class of kernel bugs.
79894 +
79895 + The tradeoff is that some virtualization solutions may experience
79896 + a huge slowdown and therefore you should not enable this feature
79897 + for kernels meant to run in such environments. Whether a given VM
79898 + solution is affected or not is best determined by simply trying it
79899 + out, the performance impact will be obvious right on boot as this
79900 + mechanism engages from very early on. A good rule of thumb is that
79901 + VMs running on CPUs without hardware virtualization support (i.e.,
79902 + the majority of IA-32 CPUs) will likely experience the slowdown.
79903 +
79904 +config PAX_REFCOUNT
79905 + bool "Prevent various kernel object reference counter overflows"
79906 + default y if GRKERNSEC_CONFIG_AUTO
79907 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
79908 + help
79909 + By saying Y here the kernel will detect and prevent overflowing
79910 + various (but not all) kinds of object reference counters. Such
79911 + overflows can normally occur due to bugs only and are often, if
79912 + not always, exploitable.
79913 +
79914 + The tradeoff is that data structures protected by an overflowed
79915 + refcount will never be freed and therefore will leak memory. Note
79916 + that this leak also happens even without this protection but in
79917 + that case the overflow can eventually trigger the freeing of the
79918 + data structure while it is still being used elsewhere, resulting
79919 + in the exploitable situation that this feature prevents.
79920 +
79921 + Since this has a negligible performance impact, you should enable
79922 + this feature.
79923 +
79924 +config PAX_USERCOPY
79925 + bool "Harden heap object copies between kernel and userland"
79926 + default y if GRKERNSEC_CONFIG_AUTO
79927 + depends on X86 || PPC || SPARC || ARM
79928 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
79929 + select PAX_USERCOPY_SLABS
79930 + help
79931 + By saying Y here the kernel will enforce the size of heap objects
79932 + when they are copied in either direction between the kernel and
79933 + userland, even if only a part of the heap object is copied.
79934 +
79935 + Specifically, this checking prevents information leaking from the
79936 + kernel heap during kernel to userland copies (if the kernel heap
79937 + object is otherwise fully initialized) and prevents kernel heap
79938 + overflows during userland to kernel copies.
79939 +
79940 + Note that the current implementation provides the strictest bounds
79941 + checks for the SLUB allocator.
79942 +
79943 + Enabling this option also enables per-slab cache protection against
79944 + data in a given cache being copied into/out of via userland
79945 + accessors. Though the whitelist of regions will be reduced over
79946 + time, it notably protects important data structures like task structs.
79947 +
79948 + If frame pointers are enabled on x86, this option will also restrict
79949 + copies into and out of the kernel stack to local variables within a
79950 + single frame.
79951 +
79952 + Since this has a negligible performance impact, you should enable
79953 + this feature.
79954 +
79955 +config PAX_SIZE_OVERFLOW
79956 + bool "Prevent various integer overflows in function size parameters"
79957 + default y if GRKERNSEC_CONFIG_AUTO
79958 + depends on X86
79959 + help
79960 + By saying Y here the kernel recomputes expressions of function
79961 + arguments marked by a size_overflow attribute with double integer
79962 + precision (DImode/TImode for 32/64 bit integer types).
79963 +
79964 + The recomputed argument is checked against INT_MAX and an event
79965 + is logged on overflow and the triggering process is killed.
79966 +
79967 + Homepage:
79968 + http://www.grsecurity.net/~ephox/overflow_plugin/
79969 +
79970 +config PAX_LATENT_ENTROPY
79971 + bool "Generate some entropy during boot"
79972 + default y if GRKERNSEC_CONFIG_AUTO
79973 + help
79974 + By saying Y here the kernel will instrument early boot code to
79975 + extract some entropy from both original and artificially created
79976 + program state. This will help especially embedded systems where
79977 + there is little 'natural' source of entropy normally. The cost
79978 + is some slowdown of the boot process.
79979 +
79980 + Note that entropy extracted this way is not cryptographically
79981 + secure!
79982 +
79983 +endmenu
79984 +
79985 +endmenu
79986 +
79987 +source grsecurity/Kconfig
79988 +
79989 +endmenu
79990 +
79991 +endmenu
79992 +
79993 source security/keys/Kconfig
79994
79995 config SECURITY_DMESG_RESTRICT
79996 @@ -103,7 +973,7 @@ config INTEL_TXT
79997 config LSM_MMAP_MIN_ADDR
79998 int "Low address space for LSM to protect from user allocation"
79999 depends on SECURITY && SECURITY_SELINUX
80000 - default 32768 if ARM
80001 + default 32768 if ALPHA || ARM || PARISC || SPARC32
80002 default 65536
80003 help
80004 This is the portion of low virtual memory which should be protected
80005 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
80006 index 8ea39aa..8569ac5 100644
80007 --- a/security/apparmor/lsm.c
80008 +++ b/security/apparmor/lsm.c
80009 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
80010 return error;
80011 }
80012
80013 -static struct security_operations apparmor_ops = {
80014 +static struct security_operations apparmor_ops __read_only = {
80015 .name = "apparmor",
80016
80017 .ptrace_access_check = apparmor_ptrace_access_check,
80018 diff --git a/security/commoncap.c b/security/commoncap.c
80019 index 6dbae46..d5611fd 100644
80020 --- a/security/commoncap.c
80021 +++ b/security/commoncap.c
80022 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
80023 return 0;
80024 }
80025
80026 +/* returns:
80027 + 1 for suid privilege
80028 + 2 for sgid privilege
80029 + 3 for fscap privilege
80030 +*/
80031 +int is_privileged_binary(const struct dentry *dentry)
80032 +{
80033 + struct cpu_vfs_cap_data capdata;
80034 + struct inode *inode = dentry->d_inode;
80035 +
80036 + if (!inode || S_ISDIR(inode->i_mode))
80037 + return 0;
80038 +
80039 + if (inode->i_mode & S_ISUID)
80040 + return 1;
80041 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
80042 + return 2;
80043 +
80044 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
80045 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
80046 + return 3;
80047 + }
80048 +
80049 + return 0;
80050 +}
80051 +
80052 /*
80053 * Attempt to get the on-exec apply capability sets for an executable file from
80054 * its xattrs and, if present, apply them to the proposed credentials being
80055 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
80056 const struct cred *cred = current_cred();
80057 kuid_t root_uid = make_kuid(cred->user_ns, 0);
80058
80059 + if (gr_acl_enable_at_secure())
80060 + return 1;
80061 +
80062 if (!uid_eq(cred->uid, root_uid)) {
80063 if (bprm->cap_effective)
80064 return 1;
80065 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
80066 index 3ccf7ac..d73ad64 100644
80067 --- a/security/integrity/ima/ima.h
80068 +++ b/security/integrity/ima/ima.h
80069 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
80070 extern spinlock_t ima_queue_lock;
80071
80072 struct ima_h_table {
80073 - atomic_long_t len; /* number of stored measurements in the list */
80074 - atomic_long_t violations;
80075 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
80076 + atomic_long_unchecked_t violations;
80077 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
80078 };
80079 extern struct ima_h_table ima_htable;
80080 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
80081 index 88a2788..581ab92 100644
80082 --- a/security/integrity/ima/ima_api.c
80083 +++ b/security/integrity/ima/ima_api.c
80084 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
80085 int result;
80086
80087 /* can overflow, only indicator */
80088 - atomic_long_inc(&ima_htable.violations);
80089 + atomic_long_inc_unchecked(&ima_htable.violations);
80090
80091 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
80092 if (!entry) {
80093 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
80094 index e1aa2b4..52027bf 100644
80095 --- a/security/integrity/ima/ima_fs.c
80096 +++ b/security/integrity/ima/ima_fs.c
80097 @@ -28,12 +28,12 @@
80098 static int valid_policy = 1;
80099 #define TMPBUFLEN 12
80100 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
80101 - loff_t *ppos, atomic_long_t *val)
80102 + loff_t *ppos, atomic_long_unchecked_t *val)
80103 {
80104 char tmpbuf[TMPBUFLEN];
80105 ssize_t len;
80106
80107 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
80108 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
80109 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
80110 }
80111
80112 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
80113 index 55a6271..ad829c3 100644
80114 --- a/security/integrity/ima/ima_queue.c
80115 +++ b/security/integrity/ima/ima_queue.c
80116 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
80117 INIT_LIST_HEAD(&qe->later);
80118 list_add_tail_rcu(&qe->later, &ima_measurements);
80119
80120 - atomic_long_inc(&ima_htable.len);
80121 + atomic_long_inc_unchecked(&ima_htable.len);
80122 key = ima_hash_key(entry->digest);
80123 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
80124 return 0;
80125 diff --git a/security/keys/compat.c b/security/keys/compat.c
80126 index c92d42b..341e7ea 100644
80127 --- a/security/keys/compat.c
80128 +++ b/security/keys/compat.c
80129 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
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/keyctl.c b/security/keys/keyctl.c
80139 index 0f5b3f0..b8d47c1 100644
80140 --- a/security/keys/keyctl.c
80141 +++ b/security/keys/keyctl.c
80142 @@ -966,7 +966,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
80143 /*
80144 * Copy the iovec data from userspace
80145 */
80146 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
80147 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
80148 unsigned ioc)
80149 {
80150 for (; ioc > 0; ioc--) {
80151 @@ -988,7 +988,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
80152 * If successful, 0 will be returned.
80153 */
80154 long keyctl_instantiate_key_common(key_serial_t id,
80155 - const struct iovec *payload_iov,
80156 + const struct iovec __user *payload_iov,
80157 unsigned ioc,
80158 size_t plen,
80159 key_serial_t ringid)
80160 @@ -1083,7 +1083,7 @@ long keyctl_instantiate_key(key_serial_t id,
80161 [0].iov_len = plen
80162 };
80163
80164 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
80165 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
80166 }
80167
80168 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
80169 @@ -1116,7 +1116,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
80170 if (ret == 0)
80171 goto no_payload_free;
80172
80173 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
80174 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
80175
80176 if (iov != iovstack)
80177 kfree(iov);
80178 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
80179 index 7445875..262834f 100644
80180 --- a/security/keys/keyring.c
80181 +++ b/security/keys/keyring.c
80182 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
80183 ret = -EFAULT;
80184
80185 for (loop = 0; loop < klist->nkeys; loop++) {
80186 + key_serial_t serial;
80187 key = rcu_deref_link_locked(klist, loop,
80188 keyring);
80189 + serial = key->serial;
80190
80191 tmp = sizeof(key_serial_t);
80192 if (tmp > buflen)
80193 tmp = buflen;
80194
80195 - if (copy_to_user(buffer,
80196 - &key->serial,
80197 - tmp) != 0)
80198 + if (copy_to_user(buffer, &serial, tmp))
80199 goto error;
80200
80201 buflen -= tmp;
80202 diff --git a/security/min_addr.c b/security/min_addr.c
80203 index f728728..6457a0c 100644
80204 --- a/security/min_addr.c
80205 +++ b/security/min_addr.c
80206 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
80207 */
80208 static void update_mmap_min_addr(void)
80209 {
80210 +#ifndef SPARC
80211 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
80212 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
80213 mmap_min_addr = dac_mmap_min_addr;
80214 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
80215 #else
80216 mmap_min_addr = dac_mmap_min_addr;
80217 #endif
80218 +#endif
80219 }
80220
80221 /*
80222 diff --git a/security/security.c b/security/security.c
80223 index 860aeb3..45765c0 100644
80224 --- a/security/security.c
80225 +++ b/security/security.c
80226 @@ -20,6 +20,7 @@
80227 #include <linux/ima.h>
80228 #include <linux/evm.h>
80229 #include <linux/fsnotify.h>
80230 +#include <linux/mm.h>
80231 #include <linux/mman.h>
80232 #include <linux/mount.h>
80233 #include <linux/personality.h>
80234 @@ -32,8 +33,8 @@
80235 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
80236 CONFIG_DEFAULT_SECURITY;
80237
80238 -static struct security_operations *security_ops;
80239 -static struct security_operations default_security_ops = {
80240 +static struct security_operations *security_ops __read_only;
80241 +static struct security_operations default_security_ops __read_only = {
80242 .name = "default",
80243 };
80244
80245 @@ -74,7 +75,9 @@ int __init security_init(void)
80246
80247 void reset_security_ops(void)
80248 {
80249 + pax_open_kernel();
80250 security_ops = &default_security_ops;
80251 + pax_close_kernel();
80252 }
80253
80254 /* Save user chosen LSM */
80255 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
80256 index daaa4ed..99a640f 100644
80257 --- a/security/selinux/hooks.c
80258 +++ b/security/selinux/hooks.c
80259 @@ -95,8 +95,6 @@
80260
80261 #define NUM_SEL_MNT_OPTS 5
80262
80263 -extern struct security_operations *security_ops;
80264 -
80265 /* SECMARK reference count */
80266 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
80267
80268 @@ -2792,11 +2790,16 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
80269
80270 /* We strip a nul only if it is at the end, otherwise the
80271 * context contains a nul and we should audit that */
80272 - str = value;
80273 - if (str[size - 1] == '\0')
80274 - audit_size = size - 1;
80275 - else
80276 - audit_size = size;
80277 + if (value) {
80278 + str = value;
80279 + if (str[size - 1] == '\0')
80280 + audit_size = size - 1;
80281 + else
80282 + audit_size = size;
80283 + } else {
80284 + str = "";
80285 + audit_size = 0;
80286 + }
80287 ab = audit_log_start(current->audit_context, GFP_ATOMIC, AUDIT_SELINUX_ERR);
80288 audit_log_format(ab, "op=setxattr invalid_context=");
80289 audit_log_n_untrustedstring(ab, value, audit_size);
80290 @@ -5506,7 +5509,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
80291
80292 #endif
80293
80294 -static struct security_operations selinux_ops = {
80295 +static struct security_operations selinux_ops __read_only = {
80296 .name = "selinux",
80297
80298 .ptrace_access_check = selinux_ptrace_access_check,
80299 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
80300 index c220f31..89fab3f 100644
80301 --- a/security/selinux/include/xfrm.h
80302 +++ b/security/selinux/include/xfrm.h
80303 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
80304
80305 static inline void selinux_xfrm_notify_policyload(void)
80306 {
80307 - atomic_inc(&flow_cache_genid);
80308 + atomic_inc_unchecked(&flow_cache_genid);
80309 }
80310 #else
80311 static inline int selinux_xfrm_enabled(void)
80312 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
80313 index ee0bb57..57fcd43 100644
80314 --- a/security/smack/smack_lsm.c
80315 +++ b/security/smack/smack_lsm.c
80316 @@ -3432,7 +3432,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
80317 return 0;
80318 }
80319
80320 -struct security_operations smack_ops = {
80321 +struct security_operations smack_ops __read_only = {
80322 .name = "smack",
80323
80324 .ptrace_access_check = smack_ptrace_access_check,
80325 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
80326 index c2d04a5..e6a1aeb 100644
80327 --- a/security/tomoyo/tomoyo.c
80328 +++ b/security/tomoyo/tomoyo.c
80329 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
80330 * tomoyo_security_ops is a "struct security_operations" which is used for
80331 * registering TOMOYO.
80332 */
80333 -static struct security_operations tomoyo_security_ops = {
80334 +static struct security_operations tomoyo_security_ops __read_only = {
80335 .name = "tomoyo",
80336 .cred_alloc_blank = tomoyo_cred_alloc_blank,
80337 .cred_prepare = tomoyo_cred_prepare,
80338 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
80339 index 51d6709..1f3dbe2 100644
80340 --- a/security/yama/Kconfig
80341 +++ b/security/yama/Kconfig
80342 @@ -1,6 +1,6 @@
80343 config SECURITY_YAMA
80344 bool "Yama support"
80345 - depends on SECURITY
80346 + depends on SECURITY && !GRKERNSEC
80347 select SECURITYFS
80348 select SECURITY_PATH
80349 default n
80350 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
80351 index 270790d..c67dfcb 100644
80352 --- a/sound/aoa/codecs/onyx.c
80353 +++ b/sound/aoa/codecs/onyx.c
80354 @@ -54,7 +54,7 @@ struct onyx {
80355 spdif_locked:1,
80356 analog_locked:1,
80357 original_mute:2;
80358 - int open_count;
80359 + local_t open_count;
80360 struct codec_info *codec_info;
80361
80362 /* mutex serializes concurrent access to the device
80363 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
80364 struct onyx *onyx = cii->codec_data;
80365
80366 mutex_lock(&onyx->mutex);
80367 - onyx->open_count++;
80368 + local_inc(&onyx->open_count);
80369 mutex_unlock(&onyx->mutex);
80370
80371 return 0;
80372 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
80373 struct onyx *onyx = cii->codec_data;
80374
80375 mutex_lock(&onyx->mutex);
80376 - onyx->open_count--;
80377 - if (!onyx->open_count)
80378 + if (local_dec_and_test(&onyx->open_count))
80379 onyx->spdif_locked = onyx->analog_locked = 0;
80380 mutex_unlock(&onyx->mutex);
80381
80382 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
80383 index ffd2025..df062c9 100644
80384 --- a/sound/aoa/codecs/onyx.h
80385 +++ b/sound/aoa/codecs/onyx.h
80386 @@ -11,6 +11,7 @@
80387 #include <linux/i2c.h>
80388 #include <asm/pmac_low_i2c.h>
80389 #include <asm/prom.h>
80390 +#include <asm/local.h>
80391
80392 /* PCM3052 register definitions */
80393
80394 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
80395 index 08fde00..0bf641a 100644
80396 --- a/sound/core/oss/pcm_oss.c
80397 +++ b/sound/core/oss/pcm_oss.c
80398 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
80399 if (in_kernel) {
80400 mm_segment_t fs;
80401 fs = snd_enter_user();
80402 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80403 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80404 snd_leave_user(fs);
80405 } else {
80406 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80407 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80408 }
80409 if (ret != -EPIPE && ret != -ESTRPIPE)
80410 break;
80411 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
80412 if (in_kernel) {
80413 mm_segment_t fs;
80414 fs = snd_enter_user();
80415 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80416 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80417 snd_leave_user(fs);
80418 } else {
80419 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80420 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80421 }
80422 if (ret == -EPIPE) {
80423 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
80424 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
80425 struct snd_pcm_plugin_channel *channels;
80426 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
80427 if (!in_kernel) {
80428 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
80429 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
80430 return -EFAULT;
80431 buf = runtime->oss.buffer;
80432 }
80433 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
80434 }
80435 } else {
80436 tmp = snd_pcm_oss_write2(substream,
80437 - (const char __force *)buf,
80438 + (const char __force_kernel *)buf,
80439 runtime->oss.period_bytes, 0);
80440 if (tmp <= 0)
80441 goto err;
80442 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
80443 struct snd_pcm_runtime *runtime = substream->runtime;
80444 snd_pcm_sframes_t frames, frames1;
80445 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
80446 - char __user *final_dst = (char __force __user *)buf;
80447 + char __user *final_dst = (char __force_user *)buf;
80448 if (runtime->oss.plugin_first) {
80449 struct snd_pcm_plugin_channel *channels;
80450 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
80451 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
80452 xfer += tmp;
80453 runtime->oss.buffer_used -= tmp;
80454 } else {
80455 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
80456 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
80457 runtime->oss.period_bytes, 0);
80458 if (tmp <= 0)
80459 goto err;
80460 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
80461 size1);
80462 size1 /= runtime->channels; /* frames */
80463 fs = snd_enter_user();
80464 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
80465 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
80466 snd_leave_user(fs);
80467 }
80468 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
80469 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
80470 index 91cdf94..4085161 100644
80471 --- a/sound/core/pcm_compat.c
80472 +++ b/sound/core/pcm_compat.c
80473 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
80474 int err;
80475
80476 fs = snd_enter_user();
80477 - err = snd_pcm_delay(substream, &delay);
80478 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
80479 snd_leave_user(fs);
80480 if (err < 0)
80481 return err;
80482 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
80483 index 53b5ada..2db94c8 100644
80484 --- a/sound/core/pcm_native.c
80485 +++ b/sound/core/pcm_native.c
80486 @@ -2780,11 +2780,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
80487 switch (substream->stream) {
80488 case SNDRV_PCM_STREAM_PLAYBACK:
80489 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
80490 - (void __user *)arg);
80491 + (void __force_user *)arg);
80492 break;
80493 case SNDRV_PCM_STREAM_CAPTURE:
80494 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
80495 - (void __user *)arg);
80496 + (void __force_user *)arg);
80497 break;
80498 default:
80499 result = -EINVAL;
80500 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
80501 index 5cf8d65..912a79c 100644
80502 --- a/sound/core/seq/seq_device.c
80503 +++ b/sound/core/seq/seq_device.c
80504 @@ -64,7 +64,7 @@ struct ops_list {
80505 int argsize; /* argument size */
80506
80507 /* operators */
80508 - struct snd_seq_dev_ops ops;
80509 + struct snd_seq_dev_ops *ops;
80510
80511 /* registred devices */
80512 struct list_head dev_list; /* list of devices */
80513 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
80514
80515 mutex_lock(&ops->reg_mutex);
80516 /* copy driver operators */
80517 - ops->ops = *entry;
80518 + ops->ops = entry;
80519 ops->driver |= DRIVER_LOADED;
80520 ops->argsize = argsize;
80521
80522 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
80523 dev->name, ops->id, ops->argsize, dev->argsize);
80524 return -EINVAL;
80525 }
80526 - if (ops->ops.init_device(dev) >= 0) {
80527 + if (ops->ops->init_device(dev) >= 0) {
80528 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
80529 ops->num_init_devices++;
80530 } else {
80531 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
80532 dev->name, ops->id, ops->argsize, dev->argsize);
80533 return -EINVAL;
80534 }
80535 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
80536 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
80537 dev->status = SNDRV_SEQ_DEVICE_FREE;
80538 dev->driver_data = NULL;
80539 ops->num_init_devices--;
80540 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
80541 index 621e60e..f4543f5 100644
80542 --- a/sound/drivers/mts64.c
80543 +++ b/sound/drivers/mts64.c
80544 @@ -29,6 +29,7 @@
80545 #include <sound/initval.h>
80546 #include <sound/rawmidi.h>
80547 #include <sound/control.h>
80548 +#include <asm/local.h>
80549
80550 #define CARD_NAME "Miditerminal 4140"
80551 #define DRIVER_NAME "MTS64"
80552 @@ -67,7 +68,7 @@ struct mts64 {
80553 struct pardevice *pardev;
80554 int pardev_claimed;
80555
80556 - int open_count;
80557 + local_t open_count;
80558 int current_midi_output_port;
80559 int current_midi_input_port;
80560 u8 mode[MTS64_NUM_INPUT_PORTS];
80561 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
80562 {
80563 struct mts64 *mts = substream->rmidi->private_data;
80564
80565 - if (mts->open_count == 0) {
80566 + if (local_read(&mts->open_count) == 0) {
80567 /* We don't need a spinlock here, because this is just called
80568 if the device has not been opened before.
80569 So there aren't any IRQs from the device */
80570 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
80571
80572 msleep(50);
80573 }
80574 - ++(mts->open_count);
80575 + local_inc(&mts->open_count);
80576
80577 return 0;
80578 }
80579 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
80580 struct mts64 *mts = substream->rmidi->private_data;
80581 unsigned long flags;
80582
80583 - --(mts->open_count);
80584 - if (mts->open_count == 0) {
80585 + if (local_dec_return(&mts->open_count) == 0) {
80586 /* We need the spinlock_irqsave here because we can still
80587 have IRQs at this point */
80588 spin_lock_irqsave(&mts->lock, flags);
80589 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
80590
80591 msleep(500);
80592
80593 - } else if (mts->open_count < 0)
80594 - mts->open_count = 0;
80595 + } else if (local_read(&mts->open_count) < 0)
80596 + local_set(&mts->open_count, 0);
80597
80598 return 0;
80599 }
80600 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
80601 index b953fb4..1999c01 100644
80602 --- a/sound/drivers/opl4/opl4_lib.c
80603 +++ b/sound/drivers/opl4/opl4_lib.c
80604 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
80605 MODULE_DESCRIPTION("OPL4 driver");
80606 MODULE_LICENSE("GPL");
80607
80608 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
80609 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
80610 {
80611 int timeout = 10;
80612 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
80613 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
80614 index 3e32bd3..46fc152 100644
80615 --- a/sound/drivers/portman2x4.c
80616 +++ b/sound/drivers/portman2x4.c
80617 @@ -48,6 +48,7 @@
80618 #include <sound/initval.h>
80619 #include <sound/rawmidi.h>
80620 #include <sound/control.h>
80621 +#include <asm/local.h>
80622
80623 #define CARD_NAME "Portman 2x4"
80624 #define DRIVER_NAME "portman"
80625 @@ -85,7 +86,7 @@ struct portman {
80626 struct pardevice *pardev;
80627 int pardev_claimed;
80628
80629 - int open_count;
80630 + local_t open_count;
80631 int mode[PORTMAN_NUM_INPUT_PORTS];
80632 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
80633 };
80634 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
80635 index ea995af..f1bfa37 100644
80636 --- a/sound/firewire/amdtp.c
80637 +++ b/sound/firewire/amdtp.c
80638 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
80639 ptr = s->pcm_buffer_pointer + data_blocks;
80640 if (ptr >= pcm->runtime->buffer_size)
80641 ptr -= pcm->runtime->buffer_size;
80642 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
80643 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
80644
80645 s->pcm_period_pointer += data_blocks;
80646 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
80647 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
80648 */
80649 void amdtp_out_stream_update(struct amdtp_out_stream *s)
80650 {
80651 - ACCESS_ONCE(s->source_node_id_field) =
80652 + ACCESS_ONCE_RW(s->source_node_id_field) =
80653 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
80654 }
80655 EXPORT_SYMBOL(amdtp_out_stream_update);
80656 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
80657 index b680c5e..061b7a0 100644
80658 --- a/sound/firewire/amdtp.h
80659 +++ b/sound/firewire/amdtp.h
80660 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
80661 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
80662 struct snd_pcm_substream *pcm)
80663 {
80664 - ACCESS_ONCE(s->pcm) = pcm;
80665 + ACCESS_ONCE_RW(s->pcm) = pcm;
80666 }
80667
80668 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
80669 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
80670 index d428ffe..751ef78 100644
80671 --- a/sound/firewire/isight.c
80672 +++ b/sound/firewire/isight.c
80673 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
80674 ptr += count;
80675 if (ptr >= runtime->buffer_size)
80676 ptr -= runtime->buffer_size;
80677 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
80678 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
80679
80680 isight->period_counter += count;
80681 if (isight->period_counter >= runtime->period_size) {
80682 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
80683 if (err < 0)
80684 return err;
80685
80686 - ACCESS_ONCE(isight->pcm_active) = true;
80687 + ACCESS_ONCE_RW(isight->pcm_active) = true;
80688
80689 return 0;
80690 }
80691 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
80692 {
80693 struct isight *isight = substream->private_data;
80694
80695 - ACCESS_ONCE(isight->pcm_active) = false;
80696 + ACCESS_ONCE_RW(isight->pcm_active) = false;
80697
80698 mutex_lock(&isight->mutex);
80699 isight_stop_streaming(isight);
80700 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
80701
80702 switch (cmd) {
80703 case SNDRV_PCM_TRIGGER_START:
80704 - ACCESS_ONCE(isight->pcm_running) = true;
80705 + ACCESS_ONCE_RW(isight->pcm_running) = true;
80706 break;
80707 case SNDRV_PCM_TRIGGER_STOP:
80708 - ACCESS_ONCE(isight->pcm_running) = false;
80709 + ACCESS_ONCE_RW(isight->pcm_running) = false;
80710 break;
80711 default:
80712 return -EINVAL;
80713 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
80714 index 7bd5e33..1fcab12 100644
80715 --- a/sound/isa/cmi8330.c
80716 +++ b/sound/isa/cmi8330.c
80717 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
80718
80719 struct snd_pcm *pcm;
80720 struct snd_cmi8330_stream {
80721 - struct snd_pcm_ops ops;
80722 + snd_pcm_ops_no_const ops;
80723 snd_pcm_open_callback_t open;
80724 void *private_data; /* sb or wss */
80725 } streams[2];
80726 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
80727 index 733b014..56ce96f 100644
80728 --- a/sound/oss/sb_audio.c
80729 +++ b/sound/oss/sb_audio.c
80730 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
80731 buf16 = (signed short *)(localbuf + localoffs);
80732 while (c)
80733 {
80734 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
80735 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
80736 if (copy_from_user(lbuf8,
80737 userbuf+useroffs + p,
80738 locallen))
80739 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
80740 index 09d4648..cf234c7 100644
80741 --- a/sound/oss/swarm_cs4297a.c
80742 +++ b/sound/oss/swarm_cs4297a.c
80743 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
80744 {
80745 struct cs4297a_state *s;
80746 u32 pwr, id;
80747 - mm_segment_t fs;
80748 int rval;
80749 #ifndef CONFIG_BCM_CS4297A_CSWARM
80750 u64 cfg;
80751 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
80752 if (!rval) {
80753 char *sb1250_duart_present;
80754
80755 +#if 0
80756 + mm_segment_t fs;
80757 fs = get_fs();
80758 set_fs(KERNEL_DS);
80759 -#if 0
80760 val = SOUND_MASK_LINE;
80761 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
80762 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
80763 val = initvol[i].vol;
80764 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
80765 }
80766 + set_fs(fs);
80767 // cs4297a_write_ac97(s, 0x18, 0x0808);
80768 #else
80769 // cs4297a_write_ac97(s, 0x5e, 0x180);
80770 cs4297a_write_ac97(s, 0x02, 0x0808);
80771 cs4297a_write_ac97(s, 0x18, 0x0808);
80772 #endif
80773 - set_fs(fs);
80774
80775 list_add(&s->list, &cs4297a_devs);
80776
80777 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
80778 index 2fdaadb..7df8fc6 100644
80779 --- a/sound/pci/hda/hda_codec.h
80780 +++ b/sound/pci/hda/hda_codec.h
80781 @@ -611,7 +611,7 @@ struct hda_bus_ops {
80782 /* notify power-up/down from codec to controller */
80783 void (*pm_notify)(struct hda_bus *bus);
80784 #endif
80785 -};
80786 +} __no_const;
80787
80788 /* template to pass to the bus constructor */
80789 struct hda_bus_template {
80790 @@ -711,6 +711,7 @@ struct hda_codec_ops {
80791 #endif
80792 void (*reboot_notify)(struct hda_codec *codec);
80793 };
80794 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
80795
80796 /* record for amp information cache */
80797 struct hda_cache_head {
80798 @@ -741,7 +742,7 @@ struct hda_pcm_ops {
80799 struct snd_pcm_substream *substream);
80800 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
80801 struct snd_pcm_substream *substream);
80802 -};
80803 +} __no_const;
80804
80805 /* PCM information for each substream */
80806 struct hda_pcm_stream {
80807 @@ -799,7 +800,7 @@ struct hda_codec {
80808 const char *modelname; /* model name for preset */
80809
80810 /* set by patch */
80811 - struct hda_codec_ops patch_ops;
80812 + hda_codec_ops_no_const patch_ops;
80813
80814 /* PCM to create, set by patch_ops.build_pcms callback */
80815 unsigned int num_pcms;
80816 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
80817 index 0da778a..bc38b84 100644
80818 --- a/sound/pci/ice1712/ice1712.h
80819 +++ b/sound/pci/ice1712/ice1712.h
80820 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
80821 unsigned int mask_flags; /* total mask bits */
80822 struct snd_akm4xxx_ops {
80823 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
80824 - } ops;
80825 + } __no_const ops;
80826 };
80827
80828 struct snd_ice1712_spdif {
80829 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
80830 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80831 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80832 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80833 - } ops;
80834 + } __no_const ops;
80835 };
80836
80837
80838 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
80839 index a8159b81..5f006a5 100644
80840 --- a/sound/pci/ymfpci/ymfpci_main.c
80841 +++ b/sound/pci/ymfpci/ymfpci_main.c
80842 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
80843 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
80844 break;
80845 }
80846 - if (atomic_read(&chip->interrupt_sleep_count)) {
80847 - atomic_set(&chip->interrupt_sleep_count, 0);
80848 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80849 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80850 wake_up(&chip->interrupt_sleep);
80851 }
80852 __end:
80853 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
80854 continue;
80855 init_waitqueue_entry(&wait, current);
80856 add_wait_queue(&chip->interrupt_sleep, &wait);
80857 - atomic_inc(&chip->interrupt_sleep_count);
80858 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
80859 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
80860 remove_wait_queue(&chip->interrupt_sleep, &wait);
80861 }
80862 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
80863 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
80864 spin_unlock(&chip->reg_lock);
80865
80866 - if (atomic_read(&chip->interrupt_sleep_count)) {
80867 - atomic_set(&chip->interrupt_sleep_count, 0);
80868 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80869 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80870 wake_up(&chip->interrupt_sleep);
80871 }
80872 }
80873 @@ -2398,7 +2398,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
80874 spin_lock_init(&chip->reg_lock);
80875 spin_lock_init(&chip->voice_lock);
80876 init_waitqueue_head(&chip->interrupt_sleep);
80877 - atomic_set(&chip->interrupt_sleep_count, 0);
80878 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80879 chip->card = card;
80880 chip->pci = pci;
80881 chip->irq = -1;
80882 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
80883 new file mode 100644
80884 index 0000000..50f2f2f
80885 --- /dev/null
80886 +++ b/tools/gcc/.gitignore
80887 @@ -0,0 +1 @@
80888 +size_overflow_hash.h
80889 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
80890 new file mode 100644
80891 index 0000000..1d09b7e
80892 --- /dev/null
80893 +++ b/tools/gcc/Makefile
80894 @@ -0,0 +1,43 @@
80895 +#CC := gcc
80896 +#PLUGIN_SOURCE_FILES := pax_plugin.c
80897 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
80898 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
80899 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
80900 +
80901 +ifeq ($(PLUGINCC),$(HOSTCC))
80902 +HOSTLIBS := hostlibs
80903 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
80904 +else
80905 +HOSTLIBS := hostcxxlibs
80906 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
80907 +endif
80908 +
80909 +$(HOSTLIBS)-y := constify_plugin.so
80910 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
80911 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
80912 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
80913 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
80914 +$(HOSTLIBS)-y += colorize_plugin.so
80915 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
80916 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
80917 +
80918 +always := $($(HOSTLIBS)-y)
80919 +
80920 +constify_plugin-objs := constify_plugin.o
80921 +stackleak_plugin-objs := stackleak_plugin.o
80922 +kallocstat_plugin-objs := kallocstat_plugin.o
80923 +kernexec_plugin-objs := kernexec_plugin.o
80924 +checker_plugin-objs := checker_plugin.o
80925 +colorize_plugin-objs := colorize_plugin.o
80926 +size_overflow_plugin-objs := size_overflow_plugin.o
80927 +latent_entropy_plugin-objs := latent_entropy_plugin.o
80928 +
80929 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
80930 +
80931 +quiet_cmd_build_size_overflow_hash = GENHASH $@
80932 + cmd_build_size_overflow_hash = \
80933 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
80934 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
80935 + $(call if_changed,build_size_overflow_hash)
80936 +
80937 +targets += size_overflow_hash.h
80938 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
80939 new file mode 100644
80940 index 0000000..d41b5af
80941 --- /dev/null
80942 +++ b/tools/gcc/checker_plugin.c
80943 @@ -0,0 +1,171 @@
80944 +/*
80945 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80946 + * Licensed under the GPL v2
80947 + *
80948 + * Note: the choice of the license means that the compilation process is
80949 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80950 + * but for the kernel it doesn't matter since it doesn't link against
80951 + * any of the gcc libraries
80952 + *
80953 + * gcc plugin to implement various sparse (source code checker) features
80954 + *
80955 + * TODO:
80956 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
80957 + *
80958 + * BUGS:
80959 + * - none known
80960 + */
80961 +#include "gcc-plugin.h"
80962 +#include "config.h"
80963 +#include "system.h"
80964 +#include "coretypes.h"
80965 +#include "tree.h"
80966 +#include "tree-pass.h"
80967 +#include "flags.h"
80968 +#include "intl.h"
80969 +#include "toplev.h"
80970 +#include "plugin.h"
80971 +//#include "expr.h" where are you...
80972 +#include "diagnostic.h"
80973 +#include "plugin-version.h"
80974 +#include "tm.h"
80975 +#include "function.h"
80976 +#include "basic-block.h"
80977 +#include "gimple.h"
80978 +#include "rtl.h"
80979 +#include "emit-rtl.h"
80980 +#include "tree-flow.h"
80981 +#include "target.h"
80982 +
80983 +extern void c_register_addr_space (const char *str, addr_space_t as);
80984 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
80985 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
80986 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
80987 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
80988 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
80989 +
80990 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80991 +extern rtx emit_move_insn(rtx x, rtx y);
80992 +
80993 +int plugin_is_GPL_compatible;
80994 +
80995 +static struct plugin_info checker_plugin_info = {
80996 + .version = "201111150100",
80997 +};
80998 +
80999 +#define ADDR_SPACE_KERNEL 0
81000 +#define ADDR_SPACE_FORCE_KERNEL 1
81001 +#define ADDR_SPACE_USER 2
81002 +#define ADDR_SPACE_FORCE_USER 3
81003 +#define ADDR_SPACE_IOMEM 0
81004 +#define ADDR_SPACE_FORCE_IOMEM 0
81005 +#define ADDR_SPACE_PERCPU 0
81006 +#define ADDR_SPACE_FORCE_PERCPU 0
81007 +#define ADDR_SPACE_RCU 0
81008 +#define ADDR_SPACE_FORCE_RCU 0
81009 +
81010 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
81011 +{
81012 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
81013 +}
81014 +
81015 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
81016 +{
81017 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
81018 +}
81019 +
81020 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
81021 +{
81022 + return default_addr_space_valid_pointer_mode(mode, as);
81023 +}
81024 +
81025 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
81026 +{
81027 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
81028 +}
81029 +
81030 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
81031 +{
81032 + return default_addr_space_legitimize_address(x, oldx, mode, as);
81033 +}
81034 +
81035 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
81036 +{
81037 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
81038 + return true;
81039 +
81040 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
81041 + return true;
81042 +
81043 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
81044 + return true;
81045 +
81046 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
81047 + return true;
81048 +
81049 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
81050 + return true;
81051 +
81052 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
81053 + return true;
81054 +
81055 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
81056 + return true;
81057 +
81058 + return subset == superset;
81059 +}
81060 +
81061 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
81062 +{
81063 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
81064 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
81065 +
81066 + return op;
81067 +}
81068 +
81069 +static void register_checker_address_spaces(void *event_data, void *data)
81070 +{
81071 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
81072 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
81073 + c_register_addr_space("__user", ADDR_SPACE_USER);
81074 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
81075 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
81076 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
81077 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
81078 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
81079 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
81080 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
81081 +
81082 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
81083 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
81084 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
81085 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
81086 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
81087 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
81088 + targetm.addr_space.convert = checker_addr_space_convert;
81089 +}
81090 +
81091 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81092 +{
81093 + const char * const plugin_name = plugin_info->base_name;
81094 + const int argc = plugin_info->argc;
81095 + const struct plugin_argument * const argv = plugin_info->argv;
81096 + int i;
81097 +
81098 + if (!plugin_default_version_check(version, &gcc_version)) {
81099 + error(G_("incompatible gcc/plugin versions"));
81100 + return 1;
81101 + }
81102 +
81103 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
81104 +
81105 + for (i = 0; i < argc; ++i)
81106 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81107 +
81108 + if (TARGET_64BIT == 0)
81109 + return 0;
81110 +
81111 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
81112 +
81113 + return 0;
81114 +}
81115 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
81116 new file mode 100644
81117 index 0000000..846aeb0
81118 --- /dev/null
81119 +++ b/tools/gcc/colorize_plugin.c
81120 @@ -0,0 +1,148 @@
81121 +/*
81122 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
81123 + * Licensed under the GPL v2
81124 + *
81125 + * Note: the choice of the license means that the compilation process is
81126 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81127 + * but for the kernel it doesn't matter since it doesn't link against
81128 + * any of the gcc libraries
81129 + *
81130 + * gcc plugin to colorize diagnostic output
81131 + *
81132 + */
81133 +
81134 +#include "gcc-plugin.h"
81135 +#include "config.h"
81136 +#include "system.h"
81137 +#include "coretypes.h"
81138 +#include "tree.h"
81139 +#include "tree-pass.h"
81140 +#include "flags.h"
81141 +#include "intl.h"
81142 +#include "toplev.h"
81143 +#include "plugin.h"
81144 +#include "diagnostic.h"
81145 +#include "plugin-version.h"
81146 +#include "tm.h"
81147 +
81148 +int plugin_is_GPL_compatible;
81149 +
81150 +static struct plugin_info colorize_plugin_info = {
81151 + .version = "201203092200",
81152 + .help = NULL,
81153 +};
81154 +
81155 +#define GREEN "\033[32m\033[2m"
81156 +#define LIGHTGREEN "\033[32m\033[1m"
81157 +#define YELLOW "\033[33m\033[2m"
81158 +#define LIGHTYELLOW "\033[33m\033[1m"
81159 +#define RED "\033[31m\033[2m"
81160 +#define LIGHTRED "\033[31m\033[1m"
81161 +#define BLUE "\033[34m\033[2m"
81162 +#define LIGHTBLUE "\033[34m\033[1m"
81163 +#define BRIGHT "\033[m\033[1m"
81164 +#define NORMAL "\033[m"
81165 +
81166 +static diagnostic_starter_fn old_starter;
81167 +static diagnostic_finalizer_fn old_finalizer;
81168 +
81169 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
81170 +{
81171 + const char *color;
81172 + char *newprefix;
81173 +
81174 + switch (diagnostic->kind) {
81175 + case DK_NOTE:
81176 + color = LIGHTBLUE;
81177 + break;
81178 +
81179 + case DK_PEDWARN:
81180 + case DK_WARNING:
81181 + color = LIGHTYELLOW;
81182 + break;
81183 +
81184 + case DK_ERROR:
81185 + case DK_FATAL:
81186 + case DK_ICE:
81187 + case DK_PERMERROR:
81188 + case DK_SORRY:
81189 + color = LIGHTRED;
81190 + break;
81191 +
81192 + default:
81193 + color = NORMAL;
81194 + }
81195 +
81196 + old_starter(context, diagnostic);
81197 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
81198 + return;
81199 + pp_destroy_prefix(context->printer);
81200 + pp_set_prefix(context->printer, newprefix);
81201 +}
81202 +
81203 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
81204 +{
81205 + old_finalizer(context, diagnostic);
81206 +}
81207 +
81208 +static void colorize_arm(void)
81209 +{
81210 + old_starter = diagnostic_starter(global_dc);
81211 + old_finalizer = diagnostic_finalizer(global_dc);
81212 +
81213 + diagnostic_starter(global_dc) = start_colorize;
81214 + diagnostic_finalizer(global_dc) = finalize_colorize;
81215 +}
81216 +
81217 +static unsigned int execute_colorize_rearm(void)
81218 +{
81219 + if (diagnostic_starter(global_dc) == start_colorize)
81220 + return 0;
81221 +
81222 + colorize_arm();
81223 + return 0;
81224 +}
81225 +
81226 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
81227 + .pass = {
81228 + .type = SIMPLE_IPA_PASS,
81229 + .name = "colorize_rearm",
81230 + .gate = NULL,
81231 + .execute = execute_colorize_rearm,
81232 + .sub = NULL,
81233 + .next = NULL,
81234 + .static_pass_number = 0,
81235 + .tv_id = TV_NONE,
81236 + .properties_required = 0,
81237 + .properties_provided = 0,
81238 + .properties_destroyed = 0,
81239 + .todo_flags_start = 0,
81240 + .todo_flags_finish = 0
81241 + }
81242 +};
81243 +
81244 +static void colorize_start_unit(void *gcc_data, void *user_data)
81245 +{
81246 + colorize_arm();
81247 +}
81248 +
81249 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81250 +{
81251 + const char * const plugin_name = plugin_info->base_name;
81252 + struct register_pass_info colorize_rearm_pass_info = {
81253 + .pass = &pass_ipa_colorize_rearm.pass,
81254 + .reference_pass_name = "*free_lang_data",
81255 + .ref_pass_instance_number = 1,
81256 + .pos_op = PASS_POS_INSERT_AFTER
81257 + };
81258 +
81259 + if (!plugin_default_version_check(version, &gcc_version)) {
81260 + error(G_("incompatible gcc/plugin versions"));
81261 + return 1;
81262 + }
81263 +
81264 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
81265 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
81266 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
81267 + return 0;
81268 +}
81269 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
81270 new file mode 100644
81271 index 0000000..048d4ff
81272 --- /dev/null
81273 +++ b/tools/gcc/constify_plugin.c
81274 @@ -0,0 +1,328 @@
81275 +/*
81276 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
81277 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
81278 + * Licensed under the GPL v2, or (at your option) v3
81279 + *
81280 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
81281 + *
81282 + * Homepage:
81283 + * http://www.grsecurity.net/~ephox/const_plugin/
81284 + *
81285 + * Usage:
81286 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
81287 + * $ gcc -fplugin=constify_plugin.so test.c -O2
81288 + */
81289 +
81290 +#include "gcc-plugin.h"
81291 +#include "config.h"
81292 +#include "system.h"
81293 +#include "coretypes.h"
81294 +#include "tree.h"
81295 +#include "tree-pass.h"
81296 +#include "flags.h"
81297 +#include "intl.h"
81298 +#include "toplev.h"
81299 +#include "plugin.h"
81300 +#include "diagnostic.h"
81301 +#include "plugin-version.h"
81302 +#include "tm.h"
81303 +#include "function.h"
81304 +#include "basic-block.h"
81305 +#include "gimple.h"
81306 +#include "rtl.h"
81307 +#include "emit-rtl.h"
81308 +#include "tree-flow.h"
81309 +
81310 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
81311 +
81312 +int plugin_is_GPL_compatible;
81313 +
81314 +static struct plugin_info const_plugin_info = {
81315 + .version = "201205300030",
81316 + .help = "no-constify\tturn off constification\n",
81317 +};
81318 +
81319 +static void deconstify_tree(tree node);
81320 +
81321 +static void deconstify_type(tree type)
81322 +{
81323 + tree field;
81324 +
81325 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
81326 + tree type = TREE_TYPE(field);
81327 +
81328 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
81329 + continue;
81330 + if (!TYPE_READONLY(type))
81331 + continue;
81332 +
81333 + deconstify_tree(field);
81334 + }
81335 + TYPE_READONLY(type) = 0;
81336 + C_TYPE_FIELDS_READONLY(type) = 0;
81337 +}
81338 +
81339 +static void deconstify_tree(tree node)
81340 +{
81341 + tree old_type, new_type, field;
81342 +
81343 + old_type = TREE_TYPE(node);
81344 +
81345 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
81346 +
81347 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
81348 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
81349 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
81350 + DECL_FIELD_CONTEXT(field) = new_type;
81351 +
81352 + deconstify_type(new_type);
81353 +
81354 + TREE_READONLY(node) = 0;
81355 + TREE_TYPE(node) = new_type;
81356 +}
81357 +
81358 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81359 +{
81360 + tree type;
81361 +
81362 + *no_add_attrs = true;
81363 + if (TREE_CODE(*node) == FUNCTION_DECL) {
81364 + error("%qE attribute does not apply to functions", name);
81365 + return NULL_TREE;
81366 + }
81367 +
81368 + if (TREE_CODE(*node) == VAR_DECL) {
81369 + error("%qE attribute does not apply to variables", name);
81370 + return NULL_TREE;
81371 + }
81372 +
81373 + if (TYPE_P(*node)) {
81374 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
81375 + *no_add_attrs = false;
81376 + else
81377 + error("%qE attribute applies to struct and union types only", name);
81378 + return NULL_TREE;
81379 + }
81380 +
81381 + type = TREE_TYPE(*node);
81382 +
81383 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
81384 + error("%qE attribute applies to struct and union types only", name);
81385 + return NULL_TREE;
81386 + }
81387 +
81388 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
81389 + error("%qE attribute is already applied to the type", name);
81390 + return NULL_TREE;
81391 + }
81392 +
81393 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
81394 + error("%qE attribute used on type that is not constified", name);
81395 + return NULL_TREE;
81396 + }
81397 +
81398 + if (TREE_CODE(*node) == TYPE_DECL) {
81399 + deconstify_tree(*node);
81400 + return NULL_TREE;
81401 + }
81402 +
81403 + return NULL_TREE;
81404 +}
81405 +
81406 +static void constify_type(tree type)
81407 +{
81408 + TYPE_READONLY(type) = 1;
81409 + C_TYPE_FIELDS_READONLY(type) = 1;
81410 +}
81411 +
81412 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81413 +{
81414 + *no_add_attrs = true;
81415 + if (!TYPE_P(*node)) {
81416 + error("%qE attribute applies to types only", name);
81417 + return NULL_TREE;
81418 + }
81419 +
81420 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
81421 + error("%qE attribute applies to struct and union types only", name);
81422 + return NULL_TREE;
81423 + }
81424 +
81425 + *no_add_attrs = false;
81426 + constify_type(*node);
81427 + return NULL_TREE;
81428 +}
81429 +
81430 +static struct attribute_spec no_const_attr = {
81431 + .name = "no_const",
81432 + .min_length = 0,
81433 + .max_length = 0,
81434 + .decl_required = false,
81435 + .type_required = false,
81436 + .function_type_required = false,
81437 + .handler = handle_no_const_attribute,
81438 +#if BUILDING_GCC_VERSION >= 4007
81439 + .affects_type_identity = true
81440 +#endif
81441 +};
81442 +
81443 +static struct attribute_spec do_const_attr = {
81444 + .name = "do_const",
81445 + .min_length = 0,
81446 + .max_length = 0,
81447 + .decl_required = false,
81448 + .type_required = false,
81449 + .function_type_required = false,
81450 + .handler = handle_do_const_attribute,
81451 +#if BUILDING_GCC_VERSION >= 4007
81452 + .affects_type_identity = true
81453 +#endif
81454 +};
81455 +
81456 +static void register_attributes(void *event_data, void *data)
81457 +{
81458 + register_attribute(&no_const_attr);
81459 + register_attribute(&do_const_attr);
81460 +}
81461 +
81462 +static bool is_fptr(tree field)
81463 +{
81464 + tree ptr = TREE_TYPE(field);
81465 +
81466 + if (TREE_CODE(ptr) != POINTER_TYPE)
81467 + return false;
81468 +
81469 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
81470 +}
81471 +
81472 +static bool walk_struct(tree node)
81473 +{
81474 + tree field;
81475 +
81476 + if (TYPE_FIELDS(node) == NULL_TREE)
81477 + return false;
81478 +
81479 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
81480 + gcc_assert(!TYPE_READONLY(node));
81481 + deconstify_type(node);
81482 + return false;
81483 + }
81484 +
81485 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
81486 + tree type = TREE_TYPE(field);
81487 + enum tree_code code = TREE_CODE(type);
81488 + if (code == RECORD_TYPE || code == UNION_TYPE) {
81489 + if (!(walk_struct(type)))
81490 + return false;
81491 + } else if (!is_fptr(field) && !TREE_READONLY(field))
81492 + return false;
81493 + }
81494 + return true;
81495 +}
81496 +
81497 +static void finish_type(void *event_data, void *data)
81498 +{
81499 + tree type = (tree)event_data;
81500 +
81501 + if (type == NULL_TREE)
81502 + return;
81503 +
81504 + if (TYPE_READONLY(type))
81505 + return;
81506 +
81507 + if (walk_struct(type))
81508 + constify_type(type);
81509 +}
81510 +
81511 +static unsigned int check_local_variables(void);
81512 +
81513 +struct gimple_opt_pass pass_local_variable = {
81514 + {
81515 + .type = GIMPLE_PASS,
81516 + .name = "check_local_variables",
81517 + .gate = NULL,
81518 + .execute = check_local_variables,
81519 + .sub = NULL,
81520 + .next = NULL,
81521 + .static_pass_number = 0,
81522 + .tv_id = TV_NONE,
81523 + .properties_required = 0,
81524 + .properties_provided = 0,
81525 + .properties_destroyed = 0,
81526 + .todo_flags_start = 0,
81527 + .todo_flags_finish = 0
81528 + }
81529 +};
81530 +
81531 +static unsigned int check_local_variables(void)
81532 +{
81533 + tree var;
81534 + referenced_var_iterator rvi;
81535 +
81536 +#if BUILDING_GCC_VERSION == 4005
81537 + FOR_EACH_REFERENCED_VAR(var, rvi) {
81538 +#else
81539 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
81540 +#endif
81541 + tree type = TREE_TYPE(var);
81542 +
81543 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
81544 + continue;
81545 +
81546 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
81547 + continue;
81548 +
81549 + if (!TYPE_READONLY(type))
81550 + continue;
81551 +
81552 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
81553 +// continue;
81554 +
81555 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
81556 +// continue;
81557 +
81558 + if (walk_struct(type)) {
81559 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
81560 + return 1;
81561 + }
81562 + }
81563 + return 0;
81564 +}
81565 +
81566 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81567 +{
81568 + const char * const plugin_name = plugin_info->base_name;
81569 + const int argc = plugin_info->argc;
81570 + const struct plugin_argument * const argv = plugin_info->argv;
81571 + int i;
81572 + bool constify = true;
81573 +
81574 + struct register_pass_info local_variable_pass_info = {
81575 + .pass = &pass_local_variable.pass,
81576 + .reference_pass_name = "*referenced_vars",
81577 + .ref_pass_instance_number = 1,
81578 + .pos_op = PASS_POS_INSERT_AFTER
81579 + };
81580 +
81581 + if (!plugin_default_version_check(version, &gcc_version)) {
81582 + error(G_("incompatible gcc/plugin versions"));
81583 + return 1;
81584 + }
81585 +
81586 + for (i = 0; i < argc; ++i) {
81587 + if (!(strcmp(argv[i].key, "no-constify"))) {
81588 + constify = false;
81589 + continue;
81590 + }
81591 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81592 + }
81593 +
81594 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
81595 + if (constify) {
81596 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
81597 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
81598 + }
81599 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
81600 +
81601 + return 0;
81602 +}
81603 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
81604 new file mode 100644
81605 index 0000000..a0fe8b2
81606 --- /dev/null
81607 +++ b/tools/gcc/generate_size_overflow_hash.sh
81608 @@ -0,0 +1,94 @@
81609 +#!/bin/bash
81610 +
81611 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
81612 +
81613 +header1="size_overflow_hash.h"
81614 +database="size_overflow_hash.data"
81615 +n=65536
81616 +
81617 +usage() {
81618 +cat <<EOF
81619 +usage: $0 options
81620 +OPTIONS:
81621 + -h|--help help
81622 + -o header file
81623 + -d database file
81624 + -n hash array size
81625 +EOF
81626 + return 0
81627 +}
81628 +
81629 +while true
81630 +do
81631 + case "$1" in
81632 + -h|--help) usage && exit 0;;
81633 + -n) n=$2; shift 2;;
81634 + -o) header1="$2"; shift 2;;
81635 + -d) database="$2"; shift 2;;
81636 + --) shift 1; break ;;
81637 + *) break ;;
81638 + esac
81639 +done
81640 +
81641 +create_defines() {
81642 + for i in `seq 1 10`
81643 + do
81644 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
81645 + done
81646 + echo >> "$header1"
81647 +}
81648 +
81649 +create_structs () {
81650 + rm -f "$header1"
81651 +
81652 + create_defines
81653 +
81654 + cat "$database" | while read data
81655 + do
81656 + data_array=($data)
81657 + struct_hash_name="${data_array[0]}"
81658 + funcn="${data_array[1]}"
81659 + params="${data_array[2]}"
81660 + next="${data_array[5]}"
81661 +
81662 + echo "struct size_overflow_hash $struct_hash_name = {" >> "$header1"
81663 +
81664 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
81665 + echo -en "\t.param\t= " >> "$header1"
81666 + line=
81667 + for param_num in ${params//-/ };
81668 + do
81669 + line="${line}PARAM"$param_num"|"
81670 + done
81671 +
81672 + echo -e "${line%?},\n};\n" >> "$header1"
81673 + done
81674 +}
81675 +
81676 +create_headers () {
81677 + echo "struct size_overflow_hash *size_overflow_hash[$n] = {" >> "$header1"
81678 +}
81679 +
81680 +create_array_elements () {
81681 + index=0
81682 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
81683 + do
81684 + data_array=($data)
81685 + i="${data_array[3]}"
81686 + hash="${data_array[4]}"
81687 + while [[ $index -lt $i ]]
81688 + do
81689 + echo -e "\t["$index"]\t= NULL," >> "$header1"
81690 + index=$(($index + 1))
81691 + done
81692 + index=$(($index + 1))
81693 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
81694 + done
81695 + echo '};' >> $header1
81696 +}
81697 +
81698 +create_structs
81699 +create_headers
81700 +create_array_elements
81701 +
81702 +exit 0
81703 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
81704 new file mode 100644
81705 index 0000000..a86e422
81706 --- /dev/null
81707 +++ b/tools/gcc/kallocstat_plugin.c
81708 @@ -0,0 +1,167 @@
81709 +/*
81710 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81711 + * Licensed under the GPL v2
81712 + *
81713 + * Note: the choice of the license means that the compilation process is
81714 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81715 + * but for the kernel it doesn't matter since it doesn't link against
81716 + * any of the gcc libraries
81717 + *
81718 + * gcc plugin to find the distribution of k*alloc sizes
81719 + *
81720 + * TODO:
81721 + *
81722 + * BUGS:
81723 + * - none known
81724 + */
81725 +#include "gcc-plugin.h"
81726 +#include "config.h"
81727 +#include "system.h"
81728 +#include "coretypes.h"
81729 +#include "tree.h"
81730 +#include "tree-pass.h"
81731 +#include "flags.h"
81732 +#include "intl.h"
81733 +#include "toplev.h"
81734 +#include "plugin.h"
81735 +//#include "expr.h" where are you...
81736 +#include "diagnostic.h"
81737 +#include "plugin-version.h"
81738 +#include "tm.h"
81739 +#include "function.h"
81740 +#include "basic-block.h"
81741 +#include "gimple.h"
81742 +#include "rtl.h"
81743 +#include "emit-rtl.h"
81744 +
81745 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81746 +
81747 +int plugin_is_GPL_compatible;
81748 +
81749 +static const char * const kalloc_functions[] = {
81750 + "__kmalloc",
81751 + "kmalloc",
81752 + "kmalloc_large",
81753 + "kmalloc_node",
81754 + "kmalloc_order",
81755 + "kmalloc_order_trace",
81756 + "kmalloc_slab",
81757 + "kzalloc",
81758 + "kzalloc_node",
81759 +};
81760 +
81761 +static struct plugin_info kallocstat_plugin_info = {
81762 + .version = "201111150100",
81763 +};
81764 +
81765 +static unsigned int execute_kallocstat(void);
81766 +
81767 +static struct gimple_opt_pass kallocstat_pass = {
81768 + .pass = {
81769 + .type = GIMPLE_PASS,
81770 + .name = "kallocstat",
81771 + .gate = NULL,
81772 + .execute = execute_kallocstat,
81773 + .sub = NULL,
81774 + .next = NULL,
81775 + .static_pass_number = 0,
81776 + .tv_id = TV_NONE,
81777 + .properties_required = 0,
81778 + .properties_provided = 0,
81779 + .properties_destroyed = 0,
81780 + .todo_flags_start = 0,
81781 + .todo_flags_finish = 0
81782 + }
81783 +};
81784 +
81785 +static bool is_kalloc(const char *fnname)
81786 +{
81787 + size_t i;
81788 +
81789 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
81790 + if (!strcmp(fnname, kalloc_functions[i]))
81791 + return true;
81792 + return false;
81793 +}
81794 +
81795 +static unsigned int execute_kallocstat(void)
81796 +{
81797 + basic_block bb;
81798 +
81799 + // 1. loop through BBs and GIMPLE statements
81800 + FOR_EACH_BB(bb) {
81801 + gimple_stmt_iterator gsi;
81802 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81803 + // gimple match:
81804 + tree fndecl, size;
81805 + gimple call_stmt;
81806 + const char *fnname;
81807 +
81808 + // is it a call
81809 + call_stmt = gsi_stmt(gsi);
81810 + if (!is_gimple_call(call_stmt))
81811 + continue;
81812 + fndecl = gimple_call_fndecl(call_stmt);
81813 + if (fndecl == NULL_TREE)
81814 + continue;
81815 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
81816 + continue;
81817 +
81818 + // is it a call to k*alloc
81819 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
81820 + if (!is_kalloc(fnname))
81821 + continue;
81822 +
81823 + // is the size arg the result of a simple const assignment
81824 + size = gimple_call_arg(call_stmt, 0);
81825 + while (true) {
81826 + gimple def_stmt;
81827 + expanded_location xloc;
81828 + size_t size_val;
81829 +
81830 + if (TREE_CODE(size) != SSA_NAME)
81831 + break;
81832 + def_stmt = SSA_NAME_DEF_STMT(size);
81833 + if (!def_stmt || !is_gimple_assign(def_stmt))
81834 + break;
81835 + if (gimple_num_ops(def_stmt) != 2)
81836 + break;
81837 + size = gimple_assign_rhs1(def_stmt);
81838 + if (!TREE_CONSTANT(size))
81839 + continue;
81840 + xloc = expand_location(gimple_location(def_stmt));
81841 + if (!xloc.file)
81842 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
81843 + size_val = TREE_INT_CST_LOW(size);
81844 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
81845 + break;
81846 + }
81847 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81848 +//debug_tree(gimple_call_fn(call_stmt));
81849 +//print_node(stderr, "pax", fndecl, 4);
81850 + }
81851 + }
81852 +
81853 + return 0;
81854 +}
81855 +
81856 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81857 +{
81858 + const char * const plugin_name = plugin_info->base_name;
81859 + struct register_pass_info kallocstat_pass_info = {
81860 + .pass = &kallocstat_pass.pass,
81861 + .reference_pass_name = "ssa",
81862 + .ref_pass_instance_number = 1,
81863 + .pos_op = PASS_POS_INSERT_AFTER
81864 + };
81865 +
81866 + if (!plugin_default_version_check(version, &gcc_version)) {
81867 + error(G_("incompatible gcc/plugin versions"));
81868 + return 1;
81869 + }
81870 +
81871 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
81872 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
81873 +
81874 + return 0;
81875 +}
81876 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
81877 new file mode 100644
81878 index 0000000..98011fa
81879 --- /dev/null
81880 +++ b/tools/gcc/kernexec_plugin.c
81881 @@ -0,0 +1,427 @@
81882 +/*
81883 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81884 + * Licensed under the GPL v2
81885 + *
81886 + * Note: the choice of the license means that the compilation process is
81887 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81888 + * but for the kernel it doesn't matter since it doesn't link against
81889 + * any of the gcc libraries
81890 + *
81891 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
81892 + *
81893 + * TODO:
81894 + *
81895 + * BUGS:
81896 + * - none known
81897 + */
81898 +#include "gcc-plugin.h"
81899 +#include "config.h"
81900 +#include "system.h"
81901 +#include "coretypes.h"
81902 +#include "tree.h"
81903 +#include "tree-pass.h"
81904 +#include "flags.h"
81905 +#include "intl.h"
81906 +#include "toplev.h"
81907 +#include "plugin.h"
81908 +//#include "expr.h" where are you...
81909 +#include "diagnostic.h"
81910 +#include "plugin-version.h"
81911 +#include "tm.h"
81912 +#include "function.h"
81913 +#include "basic-block.h"
81914 +#include "gimple.h"
81915 +#include "rtl.h"
81916 +#include "emit-rtl.h"
81917 +#include "tree-flow.h"
81918 +
81919 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81920 +extern rtx emit_move_insn(rtx x, rtx y);
81921 +
81922 +int plugin_is_GPL_compatible;
81923 +
81924 +static struct plugin_info kernexec_plugin_info = {
81925 + .version = "201111291120",
81926 + .help = "method=[bts|or]\tinstrumentation method\n"
81927 +};
81928 +
81929 +static unsigned int execute_kernexec_reload(void);
81930 +static unsigned int execute_kernexec_fptr(void);
81931 +static unsigned int execute_kernexec_retaddr(void);
81932 +static bool kernexec_cmodel_check(void);
81933 +
81934 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
81935 +static void (*kernexec_instrument_retaddr)(rtx);
81936 +
81937 +static struct gimple_opt_pass kernexec_reload_pass = {
81938 + .pass = {
81939 + .type = GIMPLE_PASS,
81940 + .name = "kernexec_reload",
81941 + .gate = kernexec_cmodel_check,
81942 + .execute = execute_kernexec_reload,
81943 + .sub = NULL,
81944 + .next = NULL,
81945 + .static_pass_number = 0,
81946 + .tv_id = TV_NONE,
81947 + .properties_required = 0,
81948 + .properties_provided = 0,
81949 + .properties_destroyed = 0,
81950 + .todo_flags_start = 0,
81951 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81952 + }
81953 +};
81954 +
81955 +static struct gimple_opt_pass kernexec_fptr_pass = {
81956 + .pass = {
81957 + .type = GIMPLE_PASS,
81958 + .name = "kernexec_fptr",
81959 + .gate = kernexec_cmodel_check,
81960 + .execute = execute_kernexec_fptr,
81961 + .sub = NULL,
81962 + .next = NULL,
81963 + .static_pass_number = 0,
81964 + .tv_id = TV_NONE,
81965 + .properties_required = 0,
81966 + .properties_provided = 0,
81967 + .properties_destroyed = 0,
81968 + .todo_flags_start = 0,
81969 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81970 + }
81971 +};
81972 +
81973 +static struct rtl_opt_pass kernexec_retaddr_pass = {
81974 + .pass = {
81975 + .type = RTL_PASS,
81976 + .name = "kernexec_retaddr",
81977 + .gate = kernexec_cmodel_check,
81978 + .execute = execute_kernexec_retaddr,
81979 + .sub = NULL,
81980 + .next = NULL,
81981 + .static_pass_number = 0,
81982 + .tv_id = TV_NONE,
81983 + .properties_required = 0,
81984 + .properties_provided = 0,
81985 + .properties_destroyed = 0,
81986 + .todo_flags_start = 0,
81987 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
81988 + }
81989 +};
81990 +
81991 +static bool kernexec_cmodel_check(void)
81992 +{
81993 + tree section;
81994 +
81995 + if (ix86_cmodel != CM_KERNEL)
81996 + return false;
81997 +
81998 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
81999 + if (!section || !TREE_VALUE(section))
82000 + return true;
82001 +
82002 + section = TREE_VALUE(TREE_VALUE(section));
82003 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
82004 + return true;
82005 +
82006 + return false;
82007 +}
82008 +
82009 +/*
82010 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
82011 + */
82012 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
82013 +{
82014 + gimple asm_movabs_stmt;
82015 +
82016 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
82017 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
82018 + gimple_asm_set_volatile(asm_movabs_stmt, true);
82019 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
82020 + update_stmt(asm_movabs_stmt);
82021 +}
82022 +
82023 +/*
82024 + * find all asm() stmts that clobber r10 and add a reload of r10
82025 + */
82026 +static unsigned int execute_kernexec_reload(void)
82027 +{
82028 + basic_block bb;
82029 +
82030 + // 1. loop through BBs and GIMPLE statements
82031 + FOR_EACH_BB(bb) {
82032 + gimple_stmt_iterator gsi;
82033 +
82034 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82035 + // gimple match: __asm__ ("" : : : "r10");
82036 + gimple asm_stmt;
82037 + size_t nclobbers;
82038 +
82039 + // is it an asm ...
82040 + asm_stmt = gsi_stmt(gsi);
82041 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
82042 + continue;
82043 +
82044 + // ... clobbering r10
82045 + nclobbers = gimple_asm_nclobbers(asm_stmt);
82046 + while (nclobbers--) {
82047 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
82048 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
82049 + continue;
82050 + kernexec_reload_fptr_mask(&gsi);
82051 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
82052 + break;
82053 + }
82054 + }
82055 + }
82056 +
82057 + return 0;
82058 +}
82059 +
82060 +/*
82061 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
82062 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
82063 + */
82064 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
82065 +{
82066 + gimple assign_intptr, assign_new_fptr, call_stmt;
82067 + tree intptr, old_fptr, new_fptr, kernexec_mask;
82068 +
82069 + call_stmt = gsi_stmt(*gsi);
82070 + old_fptr = gimple_call_fn(call_stmt);
82071 +
82072 + // create temporary unsigned long variable used for bitops and cast fptr to it
82073 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
82074 + add_referenced_var(intptr);
82075 + mark_sym_for_renaming(intptr);
82076 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
82077 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
82078 + update_stmt(assign_intptr);
82079 +
82080 + // apply logical or to temporary unsigned long and bitmask
82081 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
82082 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
82083 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
82084 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
82085 + update_stmt(assign_intptr);
82086 +
82087 + // cast temporary unsigned long back to a temporary fptr variable
82088 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
82089 + add_referenced_var(new_fptr);
82090 + mark_sym_for_renaming(new_fptr);
82091 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
82092 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
82093 + update_stmt(assign_new_fptr);
82094 +
82095 + // replace call stmt fn with the new fptr
82096 + gimple_call_set_fn(call_stmt, new_fptr);
82097 + update_stmt(call_stmt);
82098 +}
82099 +
82100 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
82101 +{
82102 + gimple asm_or_stmt, call_stmt;
82103 + tree old_fptr, new_fptr, input, output;
82104 + VEC(tree, gc) *inputs = NULL;
82105 + VEC(tree, gc) *outputs = NULL;
82106 +
82107 + call_stmt = gsi_stmt(*gsi);
82108 + old_fptr = gimple_call_fn(call_stmt);
82109 +
82110 + // create temporary fptr variable
82111 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
82112 + add_referenced_var(new_fptr);
82113 + mark_sym_for_renaming(new_fptr);
82114 +
82115 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
82116 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
82117 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
82118 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
82119 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
82120 + VEC_safe_push(tree, gc, inputs, input);
82121 + VEC_safe_push(tree, gc, outputs, output);
82122 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
82123 + gimple_asm_set_volatile(asm_or_stmt, true);
82124 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
82125 + update_stmt(asm_or_stmt);
82126 +
82127 + // replace call stmt fn with the new fptr
82128 + gimple_call_set_fn(call_stmt, new_fptr);
82129 + update_stmt(call_stmt);
82130 +}
82131 +
82132 +/*
82133 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
82134 + */
82135 +static unsigned int execute_kernexec_fptr(void)
82136 +{
82137 + basic_block bb;
82138 +
82139 + // 1. loop through BBs and GIMPLE statements
82140 + FOR_EACH_BB(bb) {
82141 + gimple_stmt_iterator gsi;
82142 +
82143 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82144 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
82145 + tree fn;
82146 + gimple call_stmt;
82147 +
82148 + // is it a call ...
82149 + call_stmt = gsi_stmt(gsi);
82150 + if (!is_gimple_call(call_stmt))
82151 + continue;
82152 + fn = gimple_call_fn(call_stmt);
82153 + if (TREE_CODE(fn) == ADDR_EXPR)
82154 + continue;
82155 + if (TREE_CODE(fn) != SSA_NAME)
82156 + gcc_unreachable();
82157 +
82158 + // ... through a function pointer
82159 + fn = SSA_NAME_VAR(fn);
82160 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
82161 + continue;
82162 + fn = TREE_TYPE(fn);
82163 + if (TREE_CODE(fn) != POINTER_TYPE)
82164 + continue;
82165 + fn = TREE_TYPE(fn);
82166 + if (TREE_CODE(fn) != FUNCTION_TYPE)
82167 + continue;
82168 +
82169 + kernexec_instrument_fptr(&gsi);
82170 +
82171 +//debug_tree(gimple_call_fn(call_stmt));
82172 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
82173 + }
82174 + }
82175 +
82176 + return 0;
82177 +}
82178 +
82179 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
82180 +static void kernexec_instrument_retaddr_bts(rtx insn)
82181 +{
82182 + rtx btsq;
82183 + rtvec argvec, constraintvec, labelvec;
82184 + int line;
82185 +
82186 + // create asm volatile("btsq $63,(%%rsp)":::)
82187 + argvec = rtvec_alloc(0);
82188 + constraintvec = rtvec_alloc(0);
82189 + labelvec = rtvec_alloc(0);
82190 + line = expand_location(RTL_LOCATION(insn)).line;
82191 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
82192 + MEM_VOLATILE_P(btsq) = 1;
82193 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
82194 + emit_insn_before(btsq, insn);
82195 +}
82196 +
82197 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
82198 +static void kernexec_instrument_retaddr_or(rtx insn)
82199 +{
82200 + rtx orq;
82201 + rtvec argvec, constraintvec, labelvec;
82202 + int line;
82203 +
82204 + // create asm volatile("orq %%r10,(%%rsp)":::)
82205 + argvec = rtvec_alloc(0);
82206 + constraintvec = rtvec_alloc(0);
82207 + labelvec = rtvec_alloc(0);
82208 + line = expand_location(RTL_LOCATION(insn)).line;
82209 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
82210 + MEM_VOLATILE_P(orq) = 1;
82211 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
82212 + emit_insn_before(orq, insn);
82213 +}
82214 +
82215 +/*
82216 + * find all asm level function returns and forcibly set the highest bit of the return address
82217 + */
82218 +static unsigned int execute_kernexec_retaddr(void)
82219 +{
82220 + rtx insn;
82221 +
82222 + // 1. find function returns
82223 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
82224 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
82225 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
82226 + rtx body;
82227 +
82228 + // is it a retn
82229 + if (!JUMP_P(insn))
82230 + continue;
82231 + body = PATTERN(insn);
82232 + if (GET_CODE(body) == PARALLEL)
82233 + body = XVECEXP(body, 0, 0);
82234 + if (GET_CODE(body) != RETURN)
82235 + continue;
82236 + kernexec_instrument_retaddr(insn);
82237 + }
82238 +
82239 +// print_simple_rtl(stderr, get_insns());
82240 +// print_rtl(stderr, get_insns());
82241 +
82242 + return 0;
82243 +}
82244 +
82245 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82246 +{
82247 + const char * const plugin_name = plugin_info->base_name;
82248 + const int argc = plugin_info->argc;
82249 + const struct plugin_argument * const argv = plugin_info->argv;
82250 + int i;
82251 + struct register_pass_info kernexec_reload_pass_info = {
82252 + .pass = &kernexec_reload_pass.pass,
82253 + .reference_pass_name = "ssa",
82254 + .ref_pass_instance_number = 1,
82255 + .pos_op = PASS_POS_INSERT_AFTER
82256 + };
82257 + struct register_pass_info kernexec_fptr_pass_info = {
82258 + .pass = &kernexec_fptr_pass.pass,
82259 + .reference_pass_name = "ssa",
82260 + .ref_pass_instance_number = 1,
82261 + .pos_op = PASS_POS_INSERT_AFTER
82262 + };
82263 + struct register_pass_info kernexec_retaddr_pass_info = {
82264 + .pass = &kernexec_retaddr_pass.pass,
82265 + .reference_pass_name = "pro_and_epilogue",
82266 + .ref_pass_instance_number = 1,
82267 + .pos_op = PASS_POS_INSERT_AFTER
82268 + };
82269 +
82270 + if (!plugin_default_version_check(version, &gcc_version)) {
82271 + error(G_("incompatible gcc/plugin versions"));
82272 + return 1;
82273 + }
82274 +
82275 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
82276 +
82277 + if (TARGET_64BIT == 0)
82278 + return 0;
82279 +
82280 + for (i = 0; i < argc; ++i) {
82281 + if (!strcmp(argv[i].key, "method")) {
82282 + if (!argv[i].value) {
82283 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82284 + continue;
82285 + }
82286 + if (!strcmp(argv[i].value, "bts")) {
82287 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
82288 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
82289 + } else if (!strcmp(argv[i].value, "or")) {
82290 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
82291 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
82292 + fix_register("r10", 1, 1);
82293 + } else
82294 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
82295 + continue;
82296 + }
82297 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82298 + }
82299 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
82300 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
82301 +
82302 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
82303 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
82304 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
82305 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
82306 +
82307 + return 0;
82308 +}
82309 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
82310 new file mode 100644
82311 index 0000000..b8008f7
82312 --- /dev/null
82313 +++ b/tools/gcc/latent_entropy_plugin.c
82314 @@ -0,0 +1,295 @@
82315 +/*
82316 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
82317 + * Licensed under the GPL v2
82318 + *
82319 + * Note: the choice of the license means that the compilation process is
82320 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82321 + * but for the kernel it doesn't matter since it doesn't link against
82322 + * any of the gcc libraries
82323 + *
82324 + * gcc plugin to help generate a little bit of entropy from program state,
82325 + * used during boot in the kernel
82326 + *
82327 + * TODO:
82328 + * - add ipa pass to identify not explicitly marked candidate functions
82329 + * - mix in more program state (function arguments/return values, loop variables, etc)
82330 + * - more instrumentation control via attribute parameters
82331 + *
82332 + * BUGS:
82333 + * - LTO needs -flto-partition=none for now
82334 + */
82335 +#include "gcc-plugin.h"
82336 +#include "config.h"
82337 +#include "system.h"
82338 +#include "coretypes.h"
82339 +#include "tree.h"
82340 +#include "tree-pass.h"
82341 +#include "flags.h"
82342 +#include "intl.h"
82343 +#include "toplev.h"
82344 +#include "plugin.h"
82345 +//#include "expr.h" where are you...
82346 +#include "diagnostic.h"
82347 +#include "plugin-version.h"
82348 +#include "tm.h"
82349 +#include "function.h"
82350 +#include "basic-block.h"
82351 +#include "gimple.h"
82352 +#include "rtl.h"
82353 +#include "emit-rtl.h"
82354 +#include "tree-flow.h"
82355 +
82356 +int plugin_is_GPL_compatible;
82357 +
82358 +static tree latent_entropy_decl;
82359 +
82360 +static struct plugin_info latent_entropy_plugin_info = {
82361 + .version = "201207271820",
82362 + .help = NULL
82363 +};
82364 +
82365 +static unsigned int execute_latent_entropy(void);
82366 +static bool gate_latent_entropy(void);
82367 +
82368 +static struct gimple_opt_pass latent_entropy_pass = {
82369 + .pass = {
82370 + .type = GIMPLE_PASS,
82371 + .name = "latent_entropy",
82372 + .gate = gate_latent_entropy,
82373 + .execute = execute_latent_entropy,
82374 + .sub = NULL,
82375 + .next = NULL,
82376 + .static_pass_number = 0,
82377 + .tv_id = TV_NONE,
82378 + .properties_required = PROP_gimple_leh | PROP_cfg,
82379 + .properties_provided = 0,
82380 + .properties_destroyed = 0,
82381 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
82382 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
82383 + }
82384 +};
82385 +
82386 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82387 +{
82388 + if (TREE_CODE(*node) != FUNCTION_DECL) {
82389 + *no_add_attrs = true;
82390 + error("%qE attribute only applies to functions", name);
82391 + }
82392 + return NULL_TREE;
82393 +}
82394 +
82395 +static struct attribute_spec latent_entropy_attr = {
82396 + .name = "latent_entropy",
82397 + .min_length = 0,
82398 + .max_length = 0,
82399 + .decl_required = true,
82400 + .type_required = false,
82401 + .function_type_required = false,
82402 + .handler = handle_latent_entropy_attribute,
82403 +#if BUILDING_GCC_VERSION >= 4007
82404 + .affects_type_identity = false
82405 +#endif
82406 +};
82407 +
82408 +static void register_attributes(void *event_data, void *data)
82409 +{
82410 + register_attribute(&latent_entropy_attr);
82411 +}
82412 +
82413 +static bool gate_latent_entropy(void)
82414 +{
82415 + tree latent_entropy_attr;
82416 +
82417 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
82418 + return latent_entropy_attr != NULL_TREE;
82419 +}
82420 +
82421 +static unsigned HOST_WIDE_INT seed;
82422 +static unsigned HOST_WIDE_INT get_random_const(void)
82423 +{
82424 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
82425 + return seed;
82426 +}
82427 +
82428 +static enum tree_code get_op(tree *rhs)
82429 +{
82430 + static enum tree_code op;
82431 + unsigned HOST_WIDE_INT random_const;
82432 +
82433 + random_const = get_random_const();
82434 +
82435 + switch (op) {
82436 + case BIT_XOR_EXPR:
82437 + op = PLUS_EXPR;
82438 + break;
82439 +
82440 + case PLUS_EXPR:
82441 + if (rhs) {
82442 + op = LROTATE_EXPR;
82443 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
82444 + break;
82445 + }
82446 +
82447 + case LROTATE_EXPR:
82448 + default:
82449 + op = BIT_XOR_EXPR;
82450 + break;
82451 + }
82452 + if (rhs)
82453 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
82454 + return op;
82455 +}
82456 +
82457 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
82458 +{
82459 + gimple_stmt_iterator gsi;
82460 + gimple assign;
82461 + tree addxorrol, rhs;
82462 + enum tree_code op;
82463 +
82464 + op = get_op(&rhs);
82465 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
82466 + assign = gimple_build_assign(local_entropy, addxorrol);
82467 + find_referenced_vars_in(assign);
82468 +//debug_bb(bb);
82469 + gsi = gsi_after_labels(bb);
82470 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
82471 + update_stmt(assign);
82472 +}
82473 +
82474 +static void perturb_latent_entropy(basic_block bb, tree rhs)
82475 +{
82476 + gimple_stmt_iterator gsi;
82477 + gimple assign;
82478 + tree addxorrol, temp;
82479 +
82480 + // 1. create temporary copy of latent_entropy
82481 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
82482 + add_referenced_var(temp);
82483 + mark_sym_for_renaming(temp);
82484 +
82485 + // 2. read...
82486 + assign = gimple_build_assign(temp, latent_entropy_decl);
82487 + find_referenced_vars_in(assign);
82488 + gsi = gsi_after_labels(bb);
82489 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
82490 + update_stmt(assign);
82491 +
82492 + // 3. ...modify...
82493 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
82494 + assign = gimple_build_assign(temp, addxorrol);
82495 + find_referenced_vars_in(assign);
82496 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
82497 + update_stmt(assign);
82498 +
82499 + // 4. ...write latent_entropy
82500 + assign = gimple_build_assign(latent_entropy_decl, temp);
82501 + find_referenced_vars_in(assign);
82502 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
82503 + update_stmt(assign);
82504 +}
82505 +
82506 +static unsigned int execute_latent_entropy(void)
82507 +{
82508 + basic_block bb;
82509 + gimple assign;
82510 + gimple_stmt_iterator gsi;
82511 + tree local_entropy;
82512 +
82513 + if (!latent_entropy_decl) {
82514 + struct varpool_node *node;
82515 +
82516 + for (node = varpool_nodes; node; node = node->next) {
82517 + tree var = node->decl;
82518 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
82519 + continue;
82520 + latent_entropy_decl = var;
82521 +// debug_tree(var);
82522 + break;
82523 + }
82524 + if (!latent_entropy_decl) {
82525 +// debug_tree(current_function_decl);
82526 + return 0;
82527 + }
82528 + }
82529 +
82530 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
82531 +
82532 + // 1. create local entropy variable
82533 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
82534 + add_referenced_var(local_entropy);
82535 + mark_sym_for_renaming(local_entropy);
82536 +
82537 + // 2. initialize local entropy variable
82538 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
82539 + if (dom_info_available_p(CDI_DOMINATORS))
82540 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
82541 + gsi = gsi_start_bb(bb);
82542 +
82543 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
82544 +// gimple_set_location(assign, loc);
82545 + find_referenced_vars_in(assign);
82546 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
82547 + update_stmt(assign);
82548 + bb = bb->next_bb;
82549 +
82550 + // 3. instrument each BB with an operation on the local entropy variable
82551 + while (bb != EXIT_BLOCK_PTR) {
82552 + perturb_local_entropy(bb, local_entropy);
82553 + bb = bb->next_bb;
82554 + };
82555 +
82556 + // 4. mix local entropy into the global entropy variable
82557 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
82558 + return 0;
82559 +}
82560 +
82561 +static void start_unit_callback(void *gcc_data, void *user_data)
82562 +{
82563 +#if BUILDING_GCC_VERSION >= 4007
82564 + seed = get_random_seed(false);
82565 +#else
82566 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
82567 + seed *= seed;
82568 +#endif
82569 +
82570 + if (in_lto_p)
82571 + return;
82572 +
82573 + // extern u64 latent_entropy
82574 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
82575 +
82576 + TREE_STATIC(latent_entropy_decl) = 1;
82577 + TREE_PUBLIC(latent_entropy_decl) = 1;
82578 + TREE_USED(latent_entropy_decl) = 1;
82579 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
82580 + DECL_EXTERNAL(latent_entropy_decl) = 1;
82581 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
82582 + DECL_INITIAL(latent_entropy_decl) = NULL;
82583 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
82584 +// varpool_finalize_decl(latent_entropy_decl);
82585 +// varpool_mark_needed_node(latent_entropy_decl);
82586 +}
82587 +
82588 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82589 +{
82590 + const char * const plugin_name = plugin_info->base_name;
82591 + struct register_pass_info latent_entropy_pass_info = {
82592 + .pass = &latent_entropy_pass.pass,
82593 + .reference_pass_name = "optimized",
82594 + .ref_pass_instance_number = 1,
82595 + .pos_op = PASS_POS_INSERT_BEFORE
82596 + };
82597 +
82598 + if (!plugin_default_version_check(version, &gcc_version)) {
82599 + error(G_("incompatible gcc/plugin versions"));
82600 + return 1;
82601 + }
82602 +
82603 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
82604 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
82605 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
82606 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
82607 +
82608 + return 0;
82609 +}
82610 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
82611 new file mode 100644
82612 index 0000000..036c9c6
82613 --- /dev/null
82614 +++ b/tools/gcc/size_overflow_hash.data
82615 @@ -0,0 +1,3057 @@
82616 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
82617 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
82618 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
82619 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
82620 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
82621 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
82622 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
82623 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
82624 +_000009_hash kmalloc 1 60432 _002597_hash NULL nohasharray
82625 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
82626 +_000012_hash kmalloc_slab 1 11917 _000012_hash NULL
82627 +_000013_hash kmemdup 2 64015 _000013_hash NULL
82628 +_000014_hash __krealloc 2 14857 _000331_hash NULL nohasharray
82629 +_000015_hash memdup_user 2 59590 _000015_hash NULL
82630 +_000016_hash module_alloc 1 63630 _000016_hash NULL
82631 +_000017_hash read_default_ldt 2 14302 _000017_hash NULL
82632 +_000018_hash read_kcore 3 63488 _000018_hash NULL
82633 +_000019_hash read_ldt 2 47570 _000019_hash NULL
82634 +_000020_hash read_zero 3 19366 _000020_hash NULL
82635 +_000021_hash __vmalloc_node 1 39308 _000021_hash NULL
82636 +_000022_hash vm_map_ram 2 23078 _001054_hash NULL nohasharray
82637 +_000023_hash aa_simple_write_to_buffer 4-3 49683 _000023_hash NULL
82638 +_000024_hash ablkcipher_copy_iv 3 64140 _000024_hash NULL
82639 +_000025_hash ablkcipher_next_slow 4 47274 _000025_hash NULL
82640 +_000026_hash acpi_battery_write_alarm 3 1240 _000026_hash NULL
82641 +_000027_hash acpi_os_allocate 1 14892 _000027_hash NULL
82642 +_000028_hash acpi_system_write_wakeup_device 3 34853 _000028_hash NULL
82643 +_000029_hash adu_write 3 30487 _000029_hash NULL
82644 +_000030_hash aer_inject_write 3 52399 _000030_hash NULL
82645 +_000031_hash afs_alloc_flat_call 2-3 36399 _000031_hash NULL
82646 +_000033_hash afs_proc_cells_write 3 61139 _000033_hash NULL
82647 +_000034_hash afs_proc_rootcell_write 3 15822 _000034_hash NULL
82648 +_000035_hash agp_3_5_isochronous_node_enable 3 49465 _000035_hash NULL
82649 +_000036_hash agp_alloc_page_array 1 22554 _000036_hash NULL
82650 +_000037_hash ah_alloc_tmp 2 54378 _000037_hash NULL
82651 +_000038_hash ahash_setkey_unaligned 3 33521 _000038_hash NULL
82652 +_000039_hash alg_setkey 3 31485 _000039_hash NULL
82653 +_000040_hash aligned_kmalloc 1 3628 _000040_hash NULL
82654 +_000041_hash alloc_context 1 3194 _000041_hash NULL
82655 +_000042_hash alloc_ep_req 2 54860 _000042_hash NULL
82656 +_000043_hash alloc_fdmem 1 27083 _000043_hash NULL
82657 +_000044_hash alloc_flex_gd 1 57259 _000044_hash NULL
82658 +_000045_hash alloc_sglist 1-3-2 22960 _000045_hash NULL
82659 +_000046_hash aoedev_flush 2 44398 _000046_hash NULL
82660 +_000047_hash append_to_buffer 3 63550 _000047_hash NULL
82661 +_000048_hash asix_read_cmd 5 13245 _000048_hash NULL
82662 +_000049_hash asix_write_cmd 5 58192 _000049_hash NULL
82663 +_000050_hash asn1_octets_decode 2 9991 _000050_hash NULL
82664 +_000051_hash asn1_oid_decode 2 4999 _000051_hash NULL
82665 +_000052_hash at76_set_card_command 4 4471 _000052_hash NULL
82666 +_000053_hash ath6kl_add_bss_if_needed 6 24317 _000053_hash NULL
82667 +_000054_hash ath6kl_debug_roam_tbl_event 3 5224 _000054_hash NULL
82668 +_000055_hash ath6kl_mgmt_powersave_ap 6 13791 _000055_hash NULL
82669 +_000056_hash ath6kl_send_go_probe_resp 3 21113 _000056_hash NULL
82670 +_000057_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000057_hash NULL
82671 +_000058_hash ath6kl_set_assoc_req_ies 3 43185 _000058_hash NULL
82672 +_000059_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000059_hash NULL
82673 +_000060_hash ath6kl_wmi_send_action_cmd 7 58860 _000060_hash NULL
82674 +_000061_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000061_hash NULL
82675 +_000062_hash attach_hdlc_protocol 3 19986 _000062_hash NULL
82676 +_000063_hash audio_write 4 54261 _001597_hash NULL nohasharray
82677 +_000064_hash audit_unpack_string 3 13748 _000064_hash NULL
82678 +_000065_hash av7110_vbi_write 3 34384 _000065_hash NULL
82679 +_000066_hash ax25_setsockopt 5 42740 _000066_hash NULL
82680 +_000067_hash b43_debugfs_write 3 34838 _000067_hash NULL
82681 +_000068_hash b43legacy_debugfs_write 3 28556 _000068_hash NULL
82682 +_000069_hash bch_alloc 1 4593 _000069_hash NULL
82683 +_000070_hash befs_nls2utf 3 17163 _000070_hash NULL
82684 +_000071_hash befs_utf2nls 3 25628 _000071_hash NULL
82685 +_000072_hash bfad_debugfs_write_regrd 3 15218 _000072_hash NULL
82686 +_000073_hash bfad_debugfs_write_regwr 3 61841 _000073_hash NULL
82687 +_000074_hash bio_alloc_map_data 1-2 50782 _000074_hash NULL
82688 +_000076_hash bio_kmalloc 2 54672 _000076_hash NULL
82689 +_000077_hash blkcipher_copy_iv 3 24075 _000077_hash NULL
82690 +_000078_hash blkcipher_next_slow 4 52733 _000078_hash NULL
82691 +_000079_hash bl_pipe_downcall 3 34264 _000079_hash NULL
82692 +_000080_hash bnad_debugfs_write_regrd 3 6706 _000080_hash NULL
82693 +_000081_hash bnad_debugfs_write_regwr 3 57500 _000081_hash NULL
82694 +_000082_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000082_hash NULL
82695 +_000084_hash bnx2_nvram_write 4 7790 _000084_hash NULL
82696 +_000085_hash brcmf_sdbrcm_downloadvars 3 42064 _000085_hash NULL
82697 +_000086_hash btmrvl_gpiogap_write 3 35053 _000086_hash NULL
82698 +_000087_hash btmrvl_hscfgcmd_write 3 27143 _000087_hash NULL
82699 +_000088_hash btmrvl_hscmd_write 3 27089 _000088_hash NULL
82700 +_000089_hash btmrvl_hsmode_write 3 42252 _000089_hash NULL
82701 +_000090_hash btmrvl_pscmd_write 3 29504 _000090_hash NULL
82702 +_000091_hash btmrvl_psmode_write 3 3703 _000091_hash NULL
82703 +_000092_hash btrfs_alloc_delayed_item 1 11678 _000092_hash NULL
82704 +_000093_hash cache_do_downcall 3 6926 _000093_hash NULL
82705 +_000094_hash cachefiles_cook_key 2 33274 _000094_hash NULL
82706 +_000095_hash cachefiles_daemon_write 3 43535 _000095_hash NULL
82707 +_000096_hash capi_write 3 35104 _000096_hash NULL
82708 +_000097_hash carl9170_debugfs_write 3 50857 _000097_hash NULL
82709 +_000098_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000098_hash NULL
82710 +_000100_hash cciss_proc_write 3 10259 _000100_hash NULL
82711 +_000101_hash cdrom_read_cdda_old 4 27664 _000101_hash NULL
82712 +_000102_hash ceph_alloc_page_vector 1 18710 _000102_hash NULL
82713 +_000103_hash ceph_buffer_new 1 35974 _000103_hash NULL
82714 +_000104_hash ceph_copy_user_to_page_vector 4 656 _000104_hash NULL
82715 +_000105_hash ceph_get_direct_page_vector 2 41917 _000105_hash NULL
82716 +_000106_hash ceph_msg_new 2 5846 _000106_hash NULL
82717 +_000107_hash ceph_setxattr 4 18913 _000107_hash NULL
82718 +_000108_hash cfi_read_pri 3 24366 _000108_hash NULL
82719 +_000109_hash cgroup_write_string 5 10900 _000109_hash NULL
82720 +_000110_hash cgroup_write_X64 5 54514 _000110_hash NULL
82721 +_000111_hash change_xattr 5 61390 _000111_hash NULL
82722 +_000112_hash check_load_and_stores 2 2143 _000112_hash NULL
82723 +_000113_hash cifs_idmap_key_instantiate 3 54503 _000113_hash NULL
82724 +_000114_hash cifs_security_flags_proc_write 3 5484 _000114_hash NULL
82725 +_000115_hash cifs_setxattr 4 23957 _000115_hash NULL
82726 +_000116_hash cifs_spnego_key_instantiate 3 23588 _000116_hash NULL
82727 +_000117_hash ci_ll_write 4 3740 _000117_hash NULL
82728 +_000118_hash cld_pipe_downcall 3 15058 _000118_hash NULL
82729 +_000119_hash clear_refs_write 3 61904 _000119_hash NULL
82730 +_000120_hash clusterip_proc_write 3 44729 _000120_hash NULL
82731 +_000121_hash cm4040_write 3 58079 _000121_hash NULL
82732 +_000122_hash cm_copy_private_data 2 3649 _000122_hash NULL
82733 +_000123_hash cmm_write 3 2896 _000123_hash NULL
82734 +_000124_hash cm_write 3 36858 _000124_hash NULL
82735 +_000125_hash coda_psdev_write 3 1711 _000125_hash NULL
82736 +_000126_hash codec_reg_read_file 3 36280 _000126_hash NULL
82737 +_000127_hash command_file_write 3 31318 _000127_hash NULL
82738 +_000128_hash command_write 3 58841 _000128_hash NULL
82739 +_000129_hash comm_write 3 44537 _001532_hash NULL nohasharray
82740 +_000130_hash concat_writev 3 21451 _000130_hash NULL
82741 +_000131_hash copy_and_check 3 19089 _000131_hash NULL
82742 +_000132_hash copy_from_user_toio 3 31966 _000132_hash NULL
82743 +_000133_hash copy_items 6 50140 _000133_hash NULL
82744 +_000134_hash copy_macs 4 45534 _000134_hash NULL
82745 +_000135_hash __copy_to_user 3 17551 _000135_hash NULL
82746 +_000136_hash copy_vm86_regs_from_user 3 45340 _000136_hash NULL
82747 +_000137_hash cosa_write 3 1774 _000137_hash NULL
82748 +_000138_hash create_entry 2 33479 _000138_hash NULL
82749 +_000139_hash create_queues 2-3 9088 _000139_hash NULL
82750 +_000141_hash create_xattr 5 54106 _000141_hash NULL
82751 +_000142_hash create_xattr_datum 5 33356 _000142_hash NULL
82752 +_000143_hash csum_partial_copy_fromiovecend 3-4 9957 _000143_hash NULL
82753 +_000145_hash ctrl_out 3-5 8712 _000145_hash NULL
82754 +_000147_hash cx24116_writeregN 4 41975 _000147_hash NULL
82755 +_000148_hash cxacru_cm_get_array 4 4412 _000148_hash NULL
82756 +_000149_hash cxgbi_alloc_big_mem 1 4707 _000149_hash NULL
82757 +_000150_hash dac960_user_command_proc_write 3 3071 _000150_hash NULL
82758 +_000151_hash datablob_format 2 39571 _002156_hash NULL nohasharray
82759 +_000152_hash dccp_feat_clone_sp_val 3 11942 _000152_hash NULL
82760 +_000153_hash dccp_setsockopt_ccid 4 30701 _000153_hash NULL
82761 +_000154_hash dccp_setsockopt_cscov 2 37766 _000154_hash NULL
82762 +_000155_hash dccp_setsockopt_service 4 65336 _000155_hash NULL
82763 +_000156_hash ddb_output_write 3 31902 _000156_hash NULL
82764 +_000157_hash ddebug_proc_write 3 18055 _000157_hash NULL
82765 +_000158_hash dev_config 3 8506 _000158_hash NULL
82766 +_000159_hash device_write 3 45156 _000159_hash NULL
82767 +_000160_hash devm_kzalloc 2 4966 _000160_hash NULL
82768 +_000161_hash devres_alloc 2 551 _000161_hash NULL
82769 +_000162_hash dfs_file_write 3 41196 _000162_hash NULL
82770 +_000163_hash direct_entry 3 38836 _000163_hash NULL
82771 +_000164_hash dispatch_proc_write 3 44320 _000164_hash NULL
82772 +_000165_hash diva_os_copy_from_user 4 7792 _000165_hash NULL
82773 +_000166_hash dlm_alloc_pagevec 1 54296 _000166_hash NULL
82774 +_000167_hash dlmfs_file_read 3 28385 _000167_hash NULL
82775 +_000168_hash dlmfs_file_write 3 6892 _000168_hash NULL
82776 +_000169_hash dm_read 3 15674 _000169_hash NULL
82777 +_000170_hash dm_write 3 2513 _000170_hash NULL
82778 +_000171_hash __dn_setsockopt 5 13060 _000171_hash NULL
82779 +_000172_hash dns_query 3 9676 _000172_hash NULL
82780 +_000173_hash dns_resolver_instantiate 3 63314 _000173_hash NULL
82781 +_000174_hash do_add_counters 3 3992 _000174_hash NULL
82782 +_000175_hash __do_config_autodelink 3 58763 _000175_hash NULL
82783 +_000176_hash do_ip_setsockopt 5 41852 _000176_hash NULL
82784 +_000177_hash do_ipv6_setsockopt 5 18215 _000177_hash NULL
82785 +_000178_hash do_ip_vs_set_ctl 4 48641 _000178_hash NULL
82786 +_000179_hash do_kimage_alloc 3 64827 _000179_hash NULL
82787 +_000180_hash do_register_entry 4 29478 _000180_hash NULL
82788 +_000181_hash do_tty_write 5 44896 _000181_hash NULL
82789 +_000182_hash do_update_counters 4 2259 _000182_hash NULL
82790 +_000183_hash dsp_write 2 46218 _000183_hash NULL
82791 +_000184_hash dup_to_netobj 3 26363 _000184_hash NULL
82792 +_000185_hash dvb_aplay 3 56296 _000185_hash NULL
82793 +_000186_hash dvb_ca_en50221_io_write 3 43533 _000186_hash NULL
82794 +_000187_hash dvbdmx_write 3 19423 _000187_hash NULL
82795 +_000188_hash dvb_play 3 50814 _000188_hash NULL
82796 +_000189_hash dw210x_op_rw 6 39915 _000189_hash NULL
82797 +_000190_hash dwc3_link_state_write 3 12641 _000190_hash NULL
82798 +_000191_hash dwc3_mode_write 3 51997 _000191_hash NULL
82799 +_000192_hash dwc3_testmode_write 3 30516 _000192_hash NULL
82800 +_000193_hash ecryptfs_copy_filename 4 11868 _000193_hash NULL
82801 +_000194_hash ecryptfs_miscdev_write 3 26847 _000194_hash NULL
82802 +_000195_hash ecryptfs_send_miscdev 2 64816 _000195_hash NULL
82803 +_000196_hash efx_tsoh_heap_alloc 2 58545 _000196_hash NULL
82804 +_000197_hash emi26_writememory 4 57908 _000197_hash NULL
82805 +_000198_hash emi62_writememory 4 29731 _000198_hash NULL
82806 +_000199_hash encrypted_instantiate 3 3168 _000199_hash NULL
82807 +_000200_hash encrypted_update 3 13414 _000200_hash NULL
82808 +_000201_hash ep0_write 3 14536 _001328_hash NULL nohasharray
82809 +_000202_hash ep_read 3 58813 _000202_hash NULL
82810 +_000203_hash ep_write 3 59008 _000203_hash NULL
82811 +_000204_hash erst_dbg_write 3 46715 _000204_hash NULL
82812 +_000205_hash esp_alloc_tmp 2 40558 _000205_hash NULL
82813 +_000206_hash exofs_read_lookup_dev_table 3 17733 _000206_hash NULL
82814 +_000207_hash ext4_kvmalloc 1 14796 _000207_hash NULL
82815 +_000208_hash ezusb_writememory 4 45976 _000208_hash NULL
82816 +_000209_hash fanotify_write 3 64623 _000209_hash NULL
82817 +_000210_hash fd_copyin 3 56247 _000210_hash NULL
82818 +_000211_hash ffs_epfile_io 3 64886 _000211_hash NULL
82819 +_000212_hash ffs_prepare_buffer 2 59892 _000212_hash NULL
82820 +_000213_hash f_hidg_write 3 7932 _000213_hash NULL
82821 +_000214_hash file_read_actor 4 1401 _000214_hash NULL
82822 +_000215_hash fill_write_buffer 3 3142 _000215_hash NULL
82823 +_000216_hash fl_create 5 56435 _000216_hash NULL
82824 +_000217_hash ftdi_elan_write 3 57309 _000217_hash NULL
82825 +_000218_hash fuse_conn_limit_write 3 30777 _000218_hash NULL
82826 +_000219_hash fw_iso_buffer_init 3 54582 _000219_hash NULL
82827 +_000220_hash garmin_write_bulk 3 58191 _000220_hash NULL
82828 +_000221_hash garp_attr_create 3 3883 _000221_hash NULL
82829 +_000222_hash get_arg 3 5694 _000222_hash NULL
82830 +_000223_hash getdqbuf 1 62908 _000223_hash NULL
82831 +_000224_hash get_fdb_entries 3 41916 _000224_hash NULL
82832 +_000225_hash get_indirect_ea 4 51869 _000225_hash NULL
82833 +_000226_hash get_registers 3 26187 _000226_hash NULL
82834 +_000227_hash get_scq 2 10897 _000227_hash NULL
82835 +_000228_hash get_server_iovec 2 16804 _000228_hash NULL
82836 +_000229_hash get_ucode_user 3 38202 _000229_hash NULL
82837 +_000230_hash get_user_cpu_mask 2 14861 _000230_hash NULL
82838 +_000231_hash gfs2_alloc_sort_buffer 1 18275 _000231_hash NULL
82839 +_000232_hash gfs2_glock_nq_m 1 20347 _000232_hash NULL
82840 +_000233_hash gigaset_initcs 2 43753 _000233_hash NULL
82841 +_000234_hash gigaset_initdriver 2 1060 _000234_hash NULL
82842 +_000235_hash gs_alloc_req 2 58883 _000235_hash NULL
82843 +_000236_hash gs_buf_alloc 2 25067 _000236_hash NULL
82844 +_000237_hash gsm_data_alloc 3 42437 _000237_hash NULL
82845 +_000238_hash gss_pipe_downcall 3 23182 _000238_hash NULL
82846 +_000239_hash handle_request 9 10024 _000239_hash NULL
82847 +_000240_hash hash_new 1 62224 _000240_hash NULL
82848 +_000241_hash hashtab_create 3 33769 _000241_hash NULL
82849 +_000242_hash hcd_buffer_alloc 2 27495 _000242_hash NULL
82850 +_000243_hash hci_sock_setsockopt 5 28993 _000243_hash NULL
82851 +_000244_hash heap_init 2 49617 _000244_hash NULL
82852 +_000245_hash hest_ghes_dev_register 1 46766 _000245_hash NULL
82853 +_000246_hash hidraw_get_report 3 45609 _000246_hash NULL
82854 +_000247_hash hidraw_report_event 3 49578 _000509_hash NULL nohasharray
82855 +_000248_hash hidraw_send_report 3 23449 _000248_hash NULL
82856 +_000249_hash hpfs_translate_name 3 41497 _000249_hash NULL
82857 +_000250_hash hysdn_conf_write 3 52145 _000250_hash NULL
82858 +_000251_hash hysdn_log_write 3 48694 _000251_hash NULL
82859 +_000252_hash __i2400mu_send_barker 3 23652 _000252_hash NULL
82860 +_000253_hash i2cdev_read 3 1206 _000253_hash NULL
82861 +_000254_hash i2cdev_write 3 23310 _000254_hash NULL
82862 +_000255_hash i2o_parm_field_get 5 34477 _000255_hash NULL
82863 +_000256_hash i2o_parm_table_get 6 61635 _000256_hash NULL
82864 +_000257_hash ib_copy_from_udata 3 59502 _000257_hash NULL
82865 +_000258_hash ib_ucm_alloc_data 3 36885 _000258_hash NULL
82866 +_000259_hash ib_umad_write 3 47993 _000259_hash NULL
82867 +_000260_hash ib_uverbs_unmarshall_recv 5 12251 _000260_hash NULL
82868 +_000261_hash icn_writecmd 2 38629 _000261_hash NULL
82869 +_000262_hash ide_driver_proc_write 3 32493 _000262_hash NULL
82870 +_000263_hash ide_settings_proc_write 3 35110 _000263_hash NULL
82871 +_000264_hash idetape_chrdev_write 3 53976 _000264_hash NULL
82872 +_000265_hash idmap_pipe_downcall 3 14591 _000265_hash NULL
82873 +_000266_hash ieee80211_build_probe_req 7-5 27660 _000266_hash NULL
82874 +_000267_hash ieee80211_if_write 3 34894 _000267_hash NULL
82875 +_000268_hash if_write 3 51756 _000268_hash NULL
82876 +_000269_hash ilo_write 3 64378 _000269_hash NULL
82877 +_000270_hash ima_write_policy 3 40548 _000270_hash NULL
82878 +_000271_hash init_data_container 1 60709 _000271_hash NULL
82879 +_000272_hash init_send_hfcd 1 34586 _000272_hash NULL
82880 +_000273_hash insert_dent 7 65034 _000273_hash NULL
82881 +_000274_hash interpret_user_input 2 19393 _000274_hash NULL
82882 +_000275_hash int_proc_write 3 39542 _000275_hash NULL
82883 +_000276_hash ioctl_private_iw_point 7 1273 _000276_hash NULL
82884 +_000277_hash iov_iter_copy_from_user 4 31942 _000277_hash NULL
82885 +_000278_hash iov_iter_copy_from_user_atomic 4 56368 _000278_hash NULL
82886 +_000279_hash iowarrior_write 3 18604 _000279_hash NULL
82887 +_000280_hash ipc_alloc 1 1192 _000280_hash NULL
82888 +_000281_hash ipc_rcu_alloc 1 21208 _000281_hash NULL
82889 +_000282_hash ip_options_get_from_user 4 64958 _000282_hash NULL
82890 +_000283_hash ipv6_renew_option 3 38813 _000283_hash NULL
82891 +_000284_hash ip_vs_conn_fill_param_sync 6 29771 _002404_hash NULL nohasharray
82892 +_000285_hash ip_vs_create_timeout_table 2 64478 _000285_hash NULL
82893 +_000286_hash ipw_queue_tx_init 3 49161 _000286_hash NULL
82894 +_000287_hash irda_setsockopt 5 19824 _000287_hash NULL
82895 +_000288_hash irias_new_octseq_value 2 13596 _000288_hash NULL
82896 +_000289_hash ir_lirc_transmit_ir 3 64403 _000289_hash NULL
82897 +_000290_hash irnet_ctrl_write 3 24139 _000290_hash NULL
82898 +_000291_hash isdn_add_channels 3 40905 _000291_hash NULL
82899 +_000292_hash isdn_ppp_fill_rq 2 41428 _000292_hash NULL
82900 +_000293_hash isdn_ppp_write 4 29109 _000293_hash NULL
82901 +_000294_hash isdn_read 3 50021 _000294_hash NULL
82902 +_000295_hash isdn_v110_open 3 2418 _000295_hash NULL
82903 +_000296_hash isdn_writebuf_stub 4 52383 _000296_hash NULL
82904 +_000297_hash islpci_mgt_transmit 5 34133 _000297_hash NULL
82905 +_000298_hash iso_callback 3 43208 _000298_hash NULL
82906 +_000299_hash iso_packets_buffer_init 3 29061 _000299_hash NULL
82907 +_000300_hash it821x_firmware_command 3 8628 _000300_hash NULL
82908 +_000301_hash ivtv_buf_copy_from_user 4 25502 _000301_hash NULL
82909 +_000302_hash iwch_alloc_fastreg_pbl 2 40153 _000302_hash NULL
82910 +_000303_hash iwl_calib_set 3 34400 _002188_hash NULL nohasharray
82911 +_000304_hash jbd2_journal_init_revoke_table 1 36336 _000304_hash NULL
82912 +_000305_hash jffs2_alloc_full_dirent 1 60179 _001111_hash NULL nohasharray
82913 +_000306_hash journal_init_revoke_table 1 56331 _000306_hash NULL
82914 +_000307_hash kcalloc 1-2 27770 _000307_hash NULL
82915 +_000309_hash keyctl_instantiate_key_common 4 47889 _000309_hash NULL
82916 +_000310_hash keyctl_update_key 3 26061 _000310_hash NULL
82917 +_000311_hash __kfifo_alloc 2-3 22173 _000311_hash NULL
82918 +_000313_hash kfifo_copy_from_user 3 5091 _000313_hash NULL
82919 +_000314_hash kmalloc_node 1 50163 _000314_hash NULL
82920 +_000315_hash kmalloc_parameter 1 65279 _000315_hash NULL
82921 +_000316_hash kmem_alloc 1 31920 _000316_hash NULL
82922 +_000317_hash kobj_map 2-3 9566 _000317_hash NULL
82923 +_000319_hash kone_receive 4 4690 _000319_hash NULL
82924 +_000320_hash kone_send 4 63435 _000320_hash NULL
82925 +_000321_hash krealloc 2 14908 _000321_hash NULL
82926 +_000322_hash kvmalloc 1 32646 _000322_hash NULL
82927 +_000323_hash kvm_read_guest_atomic 4 10765 _000323_hash NULL
82928 +_000324_hash kvm_read_guest_cached 4 39666 _000324_hash NULL
82929 +_000325_hash kvm_read_guest_page 5 18074 _000325_hash NULL
82930 +_000326_hash kzalloc 1 54740 _000326_hash NULL
82931 +_000327_hash l2cap_sock_setsockopt 5 50207 _000327_hash NULL
82932 +_000328_hash l2cap_sock_setsockopt_old 4 29346 _000328_hash NULL
82933 +_000329_hash lane2_associate_req 4 45398 _000329_hash NULL
82934 +_000330_hash lbs_debugfs_write 3 48413 _000330_hash NULL
82935 +_000331_hash lcd_write 3 14857 _000331_hash &_000014_hash
82936 +_000332_hash ldm_frag_add 2 5611 _000332_hash NULL
82937 +_000333_hash __lgread 4 31668 _000333_hash NULL
82938 +_000334_hash libipw_alloc_txb 1-3-2 27579 _000334_hash NULL
82939 +_000335_hash link_send_sections_long 4 46556 _000335_hash NULL
82940 +_000336_hash listxattr 3 12769 _000336_hash NULL
82941 +_000337_hash LoadBitmap 2 19658 _000337_hash NULL
82942 +_000338_hash load_msg 2 95 _000338_hash NULL
82943 +_000339_hash lpfc_debugfs_dif_err_write 3 17424 _000339_hash NULL
82944 +_000340_hash lp_write 3 9511 _000340_hash NULL
82945 +_000341_hash mb_cache_create 2 17307 _000341_hash NULL
82946 +_000342_hash mce_write 3 26201 _000342_hash NULL
82947 +_000343_hash mcs7830_get_reg 3 33308 _000343_hash NULL
82948 +_000344_hash mcs7830_set_reg 3 31413 _000344_hash NULL
82949 +_000345_hash memcpy_fromiovec 3 55247 _000345_hash NULL
82950 +_000346_hash memcpy_fromiovecend 3-4 2707 _000346_hash NULL
82951 +_000348_hash mempool_kmalloc 2 53831 _000348_hash NULL
82952 +_000349_hash mempool_resize 2 47983 _001821_hash NULL nohasharray
82953 +_000350_hash mem_rw 3 22085 _000350_hash NULL
82954 +_000351_hash mgmt_control 3 7349 _000351_hash NULL
82955 +_000352_hash mgmt_pending_add 5 46976 _000352_hash NULL
82956 +_000353_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000353_hash NULL
82957 +_000354_hash mmc_alloc_sg 1 21504 _000354_hash NULL
82958 +_000355_hash mmc_send_bus_test 4 18285 _000355_hash NULL
82959 +_000356_hash mmc_send_cxd_data 5 38655 _000356_hash NULL
82960 +_000357_hash module_alloc_update_bounds 1 47205 _000357_hash NULL
82961 +_000358_hash move_addr_to_kernel 2 32673 _000358_hash NULL
82962 +_000359_hash mpi_alloc_limb_space 1 23190 _000359_hash NULL
82963 +_000360_hash mpi_resize 2 44674 _000360_hash NULL
82964 +_000361_hash mptctl_getiocinfo 2 28545 _000361_hash NULL
82965 +_000362_hash mtdchar_readoob 4 31200 _000362_hash NULL
82966 +_000363_hash mtdchar_write 3 56831 _002688_hash NULL nohasharray
82967 +_000364_hash mtdchar_writeoob 4 3393 _000364_hash NULL
82968 +_000365_hash mtd_device_parse_register 5 5024 _000365_hash NULL
82969 +_000366_hash mtf_test_write 3 18844 _000366_hash NULL
82970 +_000367_hash mtrr_write 3 59622 _000367_hash NULL
82971 +_000368_hash musb_test_mode_write 3 33518 _000368_hash NULL
82972 +_000369_hash mwifiex_get_common_rates 3 17131 _000369_hash NULL
82973 +_000370_hash mwifiex_update_curr_bss_params 5 16908 _000370_hash NULL
82974 +_000371_hash nand_bch_init 2-3 16280 _001341_hash NULL nohasharray
82975 +_000373_hash ncp_file_write 3 3813 _000373_hash NULL
82976 +_000374_hash ncp__vol2io 5 4804 _000374_hash NULL
82977 +_000375_hash nes_alloc_fast_reg_page_list 2 33523 _000375_hash NULL
82978 +_000376_hash nfc_targets_found 3 29886 _000376_hash NULL
82979 +_000377_hash nfs4_acl_new 1 49806 _000377_hash NULL
82980 +_000378_hash nfs4_write_cached_acl 4 15070 _000378_hash NULL
82981 +_000379_hash nfsd_cache_update 3 59574 _000379_hash NULL
82982 +_000380_hash nfsd_symlink 6 63442 _000380_hash NULL
82983 +_000381_hash nfs_idmap_get_desc 2-4 42990 _000381_hash NULL
82984 +_000383_hash nfs_readdir_make_qstr 3 12509 _000383_hash NULL
82985 +_000384_hash note_last_dentry 3 12285 _000384_hash NULL
82986 +_000385_hash ntfs_copy_from_user 3-5 15072 _000385_hash NULL
82987 +_000387_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000387_hash NULL
82988 +_000389_hash ntfs_ucstonls 3 23097 _000389_hash NULL
82989 +_000390_hash nvme_alloc_iod 1 56027 _000390_hash NULL
82990 +_000391_hash nvram_write 3 3894 _000391_hash NULL
82991 +_000392_hash o2hb_debug_create 4 18744 _000392_hash NULL
82992 +_000393_hash o2net_send_message_vec 4 879 _001792_hash NULL nohasharray
82993 +_000394_hash ocfs2_control_cfu 2 37750 _000394_hash NULL
82994 +_000395_hash oom_adjust_write 3 41116 _000395_hash NULL
82995 +_000396_hash oom_score_adj_write 3 42594 _000396_hash NULL
82996 +_000397_hash opera1_xilinx_rw 5 31453 _000397_hash NULL
82997 +_000398_hash oprofilefs_ulong_from_user 3 57251 _000398_hash NULL
82998 +_000399_hash opticon_write 4 60775 _000399_hash NULL
82999 +_000400_hash orig_node_add_if 2 32833 _000400_hash NULL
83000 +_000401_hash orig_node_del_if 2 28371 _000401_hash NULL
83001 +_000402_hash p9_check_zc_errors 4 15534 _000402_hash NULL
83002 +_000403_hash packet_buffer_init 2 1607 _000403_hash NULL
83003 +_000404_hash packet_setsockopt 5 17662 _000404_hash NULL
83004 +_000405_hash parse_command 2 37079 _000405_hash NULL
83005 +_000406_hash pcbit_writecmd 2 12332 _000406_hash NULL
83006 +_000407_hash pcmcia_replace_cis 3 57066 _000407_hash NULL
83007 +_000408_hash pgctrl_write 3 50453 _000408_hash NULL
83008 +_000409_hash pg_write 3 40766 _000409_hash NULL
83009 +_000410_hash pidlist_allocate 1 64404 _000410_hash NULL
83010 +_000411_hash pipe_iov_copy_from_user 3 23102 _000411_hash NULL
83011 +_000412_hash pipe_iov_copy_to_user 3 3447 _000412_hash NULL
83012 +_000413_hash pkt_add 3 39897 _000413_hash NULL
83013 +_000414_hash pktgen_if_write 3 55628 _000414_hash NULL
83014 +_000415_hash platform_device_add_data 3 310 _000415_hash NULL
83015 +_000416_hash platform_device_add_resources 3 13289 _000416_hash NULL
83016 +_000417_hash pm_qos_power_write 3 52513 _000417_hash NULL
83017 +_000418_hash pnpbios_proc_write 3 19758 _000418_hash NULL
83018 +_000419_hash pool_allocate 3 42012 _000419_hash NULL
83019 +_000420_hash posix_acl_alloc 1 48063 _000420_hash NULL
83020 +_000421_hash ppp_cp_parse_cr 4 5214 _000421_hash NULL
83021 +_000422_hash ppp_write 3 34034 _000422_hash NULL
83022 +_000423_hash pp_read 3 33210 _000423_hash NULL
83023 +_000424_hash pp_write 3 39554 _000424_hash NULL
83024 +_000425_hash printer_req_alloc 2 62687 _001807_hash NULL nohasharray
83025 +_000426_hash printer_write 3 60276 _000426_hash NULL
83026 +_000427_hash prism2_set_genericelement 3 29277 _000427_hash NULL
83027 +_000428_hash __probe_kernel_read 3 61119 _000428_hash NULL
83028 +_000429_hash __probe_kernel_write 3 29842 _000429_hash NULL
83029 +_000430_hash proc_coredump_filter_write 3 25625 _000430_hash NULL
83030 +_000431_hash _proc_do_string 2 6376 _000431_hash NULL
83031 +_000432_hash process_vm_rw_pages 5-6 15954 _000432_hash NULL
83032 +_000434_hash proc_loginuid_write 3 63648 _000434_hash NULL
83033 +_000435_hash proc_pid_attr_write 3 63845 _000435_hash NULL
83034 +_000436_hash proc_scsi_devinfo_write 3 32064 _000436_hash NULL
83035 +_000437_hash proc_scsi_write 3 29142 _000437_hash NULL
83036 +_000438_hash proc_scsi_write_proc 3 267 _000438_hash NULL
83037 +_000439_hash pstore_mkfile 5 50830 _000439_hash NULL
83038 +_000440_hash pti_char_write 3 60960 _000440_hash NULL
83039 +_000441_hash ptrace_writedata 4 45021 _000441_hash NULL
83040 +_000442_hash pt_write 3 40159 _000442_hash NULL
83041 +_000443_hash pvr2_ioread_set_sync_key 3 59882 _000443_hash NULL
83042 +_000444_hash pvr2_stream_buffer_count 2 33719 _000444_hash NULL
83043 +_000445_hash qdisc_class_hash_alloc 1 18262 _000445_hash NULL
83044 +_000446_hash r3964_write 4 57662 _000446_hash NULL
83045 +_000447_hash raw_seticmpfilter 3 6888 _000447_hash NULL
83046 +_000448_hash raw_setsockopt 5 45800 _000448_hash NULL
83047 +_000449_hash rawv6_seticmpfilter 5 12137 _000449_hash NULL
83048 +_000450_hash ray_cs_essid_proc_write 3 17875 _000450_hash NULL
83049 +_000451_hash rbd_add 3 16366 _000451_hash NULL
83050 +_000452_hash rbd_snap_add 4 19678 _000452_hash NULL
83051 +_000453_hash rdma_set_ib_paths 3 45592 _000453_hash NULL
83052 +_000454_hash rds_page_copy_user 4 35691 _000454_hash NULL
83053 +_000455_hash read 3 9397 _000455_hash NULL
83054 +_000456_hash read_buf 2 20469 _000456_hash NULL
83055 +_000457_hash read_cis_cache 4 29735 _000457_hash NULL
83056 +_000458_hash realloc_buffer 2 25816 _000458_hash NULL
83057 +_000459_hash realloc_packet_buffer 2 25569 _000459_hash NULL
83058 +_000460_hash receive_DataRequest 3 9904 _000460_hash NULL
83059 +_000461_hash recent_mt_proc_write 3 8206 _000461_hash NULL
83060 +_000462_hash regmap_access_read_file 3 37223 _000462_hash NULL
83061 +_000463_hash regmap_bulk_write 4 59049 _000463_hash NULL
83062 +_000464_hash regmap_map_read_file 3 37685 _000464_hash NULL
83063 +_000465_hash regset_tls_set 4 18459 _000465_hash NULL
83064 +_000466_hash reg_w_buf 3 27724 _000466_hash NULL
83065 +_000467_hash reg_w_ixbuf 4 34736 _000467_hash NULL
83066 +_000468_hash remote_settings_file_write 3 22987 _000468_hash NULL
83067 +_000469_hash request_key_auth_new 3 38092 _000469_hash NULL
83068 +_000470_hash restore_i387_fxsave 2 17528 _000470_hash NULL
83069 +_000471_hash revalidate 2 19043 _000471_hash NULL
83070 +_000472_hash rfcomm_sock_setsockopt 5 18254 _000472_hash NULL
83071 +_000473_hash rndis_add_response 2 58544 _000473_hash NULL
83072 +_000474_hash rndis_set_oid 4 6547 _000474_hash NULL
83073 +_000475_hash rngapi_reset 3 34366 _002911_hash NULL nohasharray
83074 +_000476_hash roccat_common_receive 4 53407 _000476_hash NULL
83075 +_000477_hash roccat_common_send 4 12284 _000477_hash NULL
83076 +_000478_hash rpc_malloc 2 43573 _000478_hash NULL
83077 +_000479_hash rt2x00debug_write_bbp 3 8212 _000479_hash NULL
83078 +_000480_hash rt2x00debug_write_csr 3 64753 _000480_hash NULL
83079 +_000481_hash rt2x00debug_write_eeprom 3 23091 _000481_hash NULL
83080 +_000482_hash rt2x00debug_write_rf 3 38195 _000482_hash NULL
83081 +_000483_hash rts51x_read_mem 4 26577 _000483_hash NULL
83082 +_000484_hash rts51x_read_status 4 11830 _000484_hash NULL
83083 +_000485_hash rts51x_write_mem 4 17598 _000485_hash NULL
83084 +_000486_hash rw_copy_check_uvector 3 34271 _000486_hash NULL
83085 +_000487_hash rxrpc_request_key 3 27235 _000487_hash NULL
83086 +_000488_hash rxrpc_server_keyring 3 16431 _000488_hash NULL
83087 +_000489_hash savemem 3 58129 _000489_hash NULL
83088 +_000490_hash sb16_copy_from_user 10-7-6 55836 _000490_hash NULL
83089 +_000493_hash sched_autogroup_write 3 10984 _000493_hash NULL
83090 +_000494_hash scsi_mode_select 6 37330 _000494_hash NULL
83091 +_000495_hash scsi_tgt_copy_sense 3 26933 _000495_hash NULL
83092 +_000496_hash sctp_auth_create_key 1 51641 _000496_hash NULL
83093 +_000497_hash sctp_getsockopt_delayed_ack 2 9232 _000497_hash NULL
83094 +_000498_hash sctp_getsockopt_local_addrs 2 25178 _000498_hash NULL
83095 +_000499_hash sctp_make_abort_user 3 29654 _000499_hash NULL
83096 +_000500_hash sctp_setsockopt_active_key 3 43755 _000500_hash NULL
83097 +_000501_hash sctp_setsockopt_adaptation_layer 3 26935 _001925_hash NULL nohasharray
83098 +_000502_hash sctp_setsockopt_associnfo 3 51684 _000502_hash NULL
83099 +_000503_hash sctp_setsockopt_auth_chunk 3 30843 _000503_hash NULL
83100 +_000504_hash sctp_setsockopt_auth_key 3 3793 _000504_hash NULL
83101 +_000505_hash sctp_setsockopt_autoclose 3 5775 _000505_hash NULL
83102 +_000506_hash sctp_setsockopt_bindx 3 49870 _000506_hash NULL
83103 +_000507_hash __sctp_setsockopt_connectx 3 46949 _000507_hash NULL
83104 +_000508_hash sctp_setsockopt_context 3 31091 _000508_hash NULL
83105 +_000509_hash sctp_setsockopt_default_send_param 3 49578 _000509_hash &_000247_hash
83106 +_000510_hash sctp_setsockopt_delayed_ack 3 40129 _000510_hash NULL
83107 +_000511_hash sctp_setsockopt_del_key 3 42304 _002281_hash NULL nohasharray
83108 +_000512_hash sctp_setsockopt_events 3 18862 _000512_hash NULL
83109 +_000513_hash sctp_setsockopt_hmac_ident 3 11687 _000513_hash NULL
83110 +_000514_hash sctp_setsockopt_initmsg 3 1383 _000514_hash NULL
83111 +_000515_hash sctp_setsockopt_maxburst 3 28041 _000515_hash NULL
83112 +_000516_hash sctp_setsockopt_maxseg 3 11829 _000516_hash NULL
83113 +_000517_hash sctp_setsockopt_peer_addr_params 3 734 _000517_hash NULL
83114 +_000518_hash sctp_setsockopt_peer_primary_addr 3 13440 _000518_hash NULL
83115 +_000519_hash sctp_setsockopt_rtoinfo 3 30941 _000519_hash NULL
83116 +_000520_hash security_context_to_sid_core 2 29248 _000520_hash NULL
83117 +_000521_hash sel_commit_bools_write 3 46077 _000521_hash NULL
83118 +_000522_hash sel_write_avc_cache_threshold 3 2256 _000522_hash NULL
83119 +_000523_hash sel_write_bool 3 46996 _000523_hash NULL
83120 +_000524_hash sel_write_checkreqprot 3 60774 _000524_hash NULL
83121 +_000525_hash sel_write_disable 3 10511 _000525_hash NULL
83122 +_000526_hash sel_write_enforce 3 48998 _000526_hash NULL
83123 +_000527_hash sel_write_load 3 63830 _000527_hash NULL
83124 +_000528_hash send_bulk_static_data 3 61932 _000528_hash NULL
83125 +_000529_hash send_control_msg 6 48498 _000529_hash NULL
83126 +_000530_hash set_aoe_iflist 2 42737 _000530_hash NULL
83127 +_000531_hash setkey_unaligned 3 39474 _000531_hash NULL
83128 +_000532_hash set_registers 3 53582 _000532_hash NULL
83129 +_000533_hash setsockopt 5 54539 _000533_hash NULL
83130 +_000534_hash setup_req 3 5848 _000534_hash NULL
83131 +_000535_hash setup_window 7 59178 _000535_hash NULL
83132 +_000536_hash setxattr 4 37006 _000536_hash NULL
83133 +_000537_hash sfq_alloc 1 2861 _000537_hash NULL
83134 +_000538_hash sg_kmalloc 1 50240 _000538_hash NULL
83135 +_000539_hash sgl_map_user_pages 2 30610 _000539_hash NULL
83136 +_000540_hash shash_setkey_unaligned 3 8620 _000540_hash NULL
83137 +_000541_hash shmem_xattr_alloc 2 61190 _000541_hash NULL
83138 +_000542_hash sierra_setup_urb 5 46029 _000542_hash NULL
83139 +_000543_hash simple_transaction_get 3 50633 _000543_hash NULL
83140 +_000544_hash simple_write_to_buffer 2-5 3122 _000544_hash NULL
83141 +_000546_hash sisusb_send_bulk_msg 3 17864 _000546_hash NULL
83142 +_000547_hash skb_add_data 3 48363 _000547_hash NULL
83143 +_000548_hash skb_do_copy_data_nocache 5 12465 _000548_hash NULL
83144 +_000549_hash sl_alloc_bufs 2 50380 _000549_hash NULL
83145 +_000550_hash sl_realloc_bufs 2 64086 _000550_hash NULL
83146 +_000551_hash smk_write_ambient 3 45691 _000551_hash NULL
83147 +_000552_hash smk_write_cipso 3 17989 _000552_hash NULL
83148 +_000553_hash smk_write_direct 3 46363 _000553_hash NULL
83149 +_000554_hash smk_write_doi 3 49621 _000554_hash NULL
83150 +_000555_hash smk_write_load_list 3 52280 _000555_hash NULL
83151 +_000556_hash smk_write_logging 3 2618 _000556_hash NULL
83152 +_000557_hash smk_write_netlbladdr 3 42525 _000557_hash NULL
83153 +_000558_hash smk_write_onlycap 3 14400 _000558_hash NULL
83154 +_000559_hash snd_ctl_elem_user_tlv 3 11695 _000559_hash NULL
83155 +_000560_hash snd_emu10k1_fx8010_read 5 9605 _000560_hash NULL
83156 +_000561_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000561_hash NULL
83157 +_000563_hash snd_gus_dram_poke 4 18525 _000563_hash NULL
83158 +_000564_hash snd_hdsp_playback_copy 5 20676 _000564_hash NULL
83159 +_000565_hash snd_info_entry_write 3 63474 _000565_hash NULL
83160 +_000566_hash snd_korg1212_copy_from 6 36169 _000566_hash NULL
83161 +_000567_hash snd_mem_proc_write 3 9786 _000567_hash NULL
83162 +_000568_hash snd_midi_channel_init_set 1 30092 _000568_hash NULL
83163 +_000569_hash snd_midi_event_new 1 9893 _000750_hash NULL nohasharray
83164 +_000570_hash snd_opl4_mem_proc_write 5 9670 _000570_hash NULL
83165 +_000571_hash snd_pcm_aio_read 3 13900 _000571_hash NULL
83166 +_000572_hash snd_pcm_aio_write 3 28738 _000572_hash NULL
83167 +_000573_hash snd_pcm_oss_write1 3 10872 _000573_hash NULL
83168 +_000574_hash snd_pcm_oss_write2 3 27332 _000574_hash NULL
83169 +_000575_hash snd_rawmidi_kernel_write1 4 56847 _000575_hash NULL
83170 +_000576_hash snd_rme9652_playback_copy 5 20970 _000576_hash NULL
83171 +_000577_hash snd_sb_csp_load_user 3 45190 _000577_hash NULL
83172 +_000578_hash snd_usb_ctl_msg 8 8436 _000578_hash NULL
83173 +_000579_hash sock_bindtodevice 3 50942 _000579_hash NULL
83174 +_000580_hash sock_kmalloc 2 62205 _000580_hash NULL
83175 +_000581_hash spidev_write 3 44510 _000581_hash NULL
83176 +_000582_hash squashfs_read_table 3 16945 _000582_hash NULL
83177 +_000583_hash srpt_alloc_ioctx 2-3 51042 _000583_hash NULL
83178 +_000585_hash srpt_alloc_ioctx_ring 2 49330 _000585_hash NULL
83179 +_000586_hash st5481_setup_isocpipes 6-4 61340 _000586_hash NULL
83180 +_000587_hash sta_agg_status_write 3 45164 _000587_hash NULL
83181 +_000588_hash svc_setsockopt 5 36876 _000588_hash NULL
83182 +_000589_hash sys_add_key 4 61288 _000589_hash NULL
83183 +_000590_hash sys_modify_ldt 3 18824 _000590_hash NULL
83184 +_000591_hash sys_semtimedop 3 4486 _000591_hash NULL
83185 +_000592_hash sys_setdomainname 2 4373 _000592_hash NULL
83186 +_000593_hash sys_sethostname 2 42962 _000593_hash NULL
83187 +_000594_hash tda10048_writeregbulk 4 11050 _000594_hash NULL
83188 +_000595_hash tipc_log_resize 1 34803 _000595_hash NULL
83189 +_000596_hash tomoyo_write_self 3 45161 _000596_hash NULL
83190 +_000597_hash tower_write 3 8580 _000597_hash NULL
83191 +_000598_hash tpm_write 3 50798 _000598_hash NULL
83192 +_000599_hash trusted_instantiate 3 4710 _000599_hash NULL
83193 +_000600_hash trusted_update 3 12664 _000600_hash NULL
83194 +_000601_hash tt_changes_fill_buffer 3 62649 _000601_hash NULL
83195 +_000602_hash tty_buffer_alloc 2 45437 _000602_hash NULL
83196 +_000603_hash __tun_chr_ioctl 4 22300 _000603_hash NULL
83197 +_000604_hash ubi_more_leb_change_data 4 63534 _000604_hash NULL
83198 +_000605_hash ubi_more_update_data 4 39189 _000605_hash NULL
83199 +_000606_hash ubi_resize_volume 2 50172 _000606_hash NULL
83200 +_000607_hash udf_alloc_i_data 2 35786 _000607_hash NULL
83201 +_000608_hash uea_idma_write 3 64139 _000608_hash NULL
83202 +_000609_hash uea_request 4 47613 _000609_hash NULL
83203 +_000610_hash uea_send_modem_cmd 3 3888 _000610_hash NULL
83204 +_000611_hash uio_write 3 43202 _000611_hash NULL
83205 +_000612_hash um_idi_write 3 18293 _000612_hash NULL
83206 +_000613_hash us122l_ctl_msg 8 13330 _000613_hash NULL
83207 +_000614_hash usb_alloc_urb 1 43436 _000614_hash NULL
83208 +_000615_hash usblp_new_writeurb 2 22894 _000615_hash NULL
83209 +_000616_hash usblp_write 3 23178 _000616_hash NULL
83210 +_000617_hash usbtest_alloc_urb 3-5 34446 _000617_hash NULL
83211 +_000619_hash usbtmc_write 3 64340 _000619_hash NULL
83212 +_000620_hash user_instantiate 3 26131 _000620_hash NULL
83213 +_000621_hash user_update 3 41332 _000621_hash NULL
83214 +_000622_hash uvc_simplify_fraction 3 31303 _000622_hash NULL
83215 +_000623_hash uwb_rc_cmd_done 4 35892 _000623_hash NULL
83216 +_000624_hash uwb_rc_neh_grok_event 3 55799 _000624_hash NULL
83217 +_000625_hash v9fs_alloc_rdir_buf 2 42150 _000625_hash NULL
83218 +_000626_hash __vb2_perform_fileio 3 63033 _000626_hash NULL
83219 +_000627_hash vc_do_resize 3-4 48842 _000627_hash NULL
83220 +_000629_hash vcs_write 3 3910 _000629_hash NULL
83221 +_000630_hash vfd_write 3 14717 _000630_hash NULL
83222 +_000631_hash vga_arb_write 3 36112 _000631_hash NULL
83223 +_000632_hash vga_switcheroo_debugfs_write 3 33984 _000632_hash NULL
83224 +_000633_hash vhci_get_user 3 45039 _000633_hash NULL
83225 +_000634_hash video_proc_write 3 6724 _000634_hash NULL
83226 +_000635_hash vlsi_alloc_ring 3-4 57003 _000635_hash NULL
83227 +_000637_hash __vmalloc 1 61168 _000637_hash NULL
83228 +_000638_hash vmalloc_32 1 1135 _000638_hash NULL
83229 +_000639_hash vmalloc_32_user 1 37519 _000639_hash NULL
83230 +_000640_hash vmalloc_exec 1 36132 _000640_hash NULL
83231 +_000641_hash vmalloc_node 1 58700 _000641_hash NULL
83232 +_000642_hash __vmalloc_node_flags 1 30352 _000642_hash NULL
83233 +_000643_hash vmalloc_user 1 32308 _000643_hash NULL
83234 +_000644_hash vol_cdev_direct_write 3 20751 _000644_hash NULL
83235 +_000645_hash vp_request_msix_vectors 2 28849 _000645_hash NULL
83236 +_000646_hash vring_add_indirect 3-4 20737 _000646_hash NULL
83237 +_000648_hash vring_new_virtqueue 1 9671 _000648_hash NULL
83238 +_000649_hash vxge_os_dma_malloc 2 46184 _000649_hash NULL
83239 +_000650_hash vxge_os_dma_malloc_async 3 56348 _000650_hash NULL
83240 +_000651_hash wdm_write 3 53735 _000651_hash NULL
83241 +_000652_hash wiimote_hid_send 3 48528 _000652_hash NULL
83242 +_000653_hash wl1273_fm_fops_write 3 60621 _000653_hash NULL
83243 +_000654_hash wlc_phy_loadsampletable_nphy 3 64367 _000654_hash NULL
83244 +_000655_hash write 3 62671 _000655_hash NULL
83245 +_000656_hash write_flush 3 50803 _000656_hash NULL
83246 +_000657_hash write_rio 3 54837 _000657_hash NULL
83247 +_000658_hash x25_asy_change_mtu 2 26928 _000658_hash NULL
83248 +_000659_hash xdi_copy_from_user 4 8395 _000659_hash NULL
83249 +_000660_hash xfrm_dst_alloc_copy 3 3034 _000660_hash NULL
83250 +_000661_hash xfrm_user_policy 4 62573 _000661_hash NULL
83251 +_000662_hash xfs_attrmulti_attr_set 4 59346 _000662_hash NULL
83252 +_000663_hash xfs_handle_to_dentry 3 12135 _000663_hash NULL
83253 +_000664_hash __xip_file_write 3 2733 _000664_hash NULL
83254 +_000665_hash xprt_rdma_allocate 2 31372 _000665_hash NULL
83255 +_000666_hash zd_usb_iowrite16v_async 3 23984 _000666_hash NULL
83256 +_000667_hash zd_usb_read_fw 4 22049 _000667_hash NULL
83257 +_000668_hash zerocopy_sg_from_iovec 3 11828 _000668_hash NULL
83258 +_000669_hash zoran_write 3 22404 _000669_hash NULL
83259 +_000671_hash acpi_ex_allocate_name_string 2 7685 _002855_hash NULL nohasharray
83260 +_000672_hash acpi_os_allocate_zeroed 1 37422 _000672_hash NULL
83261 +_000673_hash acpi_ut_initialize_buffer 2 47143 _002314_hash NULL nohasharray
83262 +_000674_hash ad7879_spi_xfer 3 36311 _000674_hash NULL
83263 +_000675_hash add_new_gdb 3 27643 _000675_hash NULL
83264 +_000676_hash add_numbered_child 5 14273 _000676_hash NULL
83265 +_000677_hash add_res_range 4 21310 _000677_hash NULL
83266 +_000678_hash addtgt 3 54703 _000678_hash NULL
83267 +_000679_hash add_uuid 4 49831 _000679_hash NULL
83268 +_000680_hash afs_cell_alloc 2 24052 _000680_hash NULL
83269 +_000681_hash aggr_recv_addba_req_evt 4 38037 _000681_hash NULL
83270 +_000682_hash agp_create_memory 1 1075 _000682_hash NULL
83271 +_000683_hash agp_create_user_memory 1 62955 _000683_hash NULL
83272 +_000684_hash alg_setsockopt 5 20985 _000684_hash NULL
83273 +_000685_hash alloc_async 1 14208 _000685_hash NULL
83274 +_000686_hash ___alloc_bootmem_nopanic 1 53626 _000686_hash NULL
83275 +_000687_hash alloc_buf 1 34532 _000687_hash NULL
83276 +_000688_hash alloc_chunk 1 49575 _000688_hash NULL
83277 +_000689_hash alloc_context 1 41283 _000689_hash NULL
83278 +_000690_hash alloc_ctrl_packet 1 44667 _000690_hash NULL
83279 +_000691_hash alloc_data_packet 1 46698 _000691_hash NULL
83280 +_000692_hash alloc_dca_provider 2 59670 _000692_hash NULL
83281 +_000693_hash __alloc_dev_table 2 54343 _000693_hash NULL
83282 +_000694_hash alloc_ep 1 17269 _000694_hash NULL
83283 +_000695_hash __alloc_extent_buffer 3 15093 _000695_hash NULL
83284 +_000696_hash alloc_group_attrs 2 9194 _000719_hash NULL nohasharray
83285 +_000697_hash alloc_large_system_hash 2 64490 _000697_hash NULL
83286 +_000698_hash alloc_netdev_mqs 1 30030 _000698_hash NULL
83287 +_000699_hash __alloc_objio_seg 1 7203 _000699_hash NULL
83288 +_000700_hash alloc_ring 2-4 15345 _000700_hash NULL
83289 +_000701_hash alloc_ring 2-4 39151 _000701_hash NULL
83290 +_000704_hash alloc_session 1-2 64171 _000704_hash NULL
83291 +_000708_hash alloc_smp_req 1 51337 _000708_hash NULL
83292 +_000709_hash alloc_smp_resp 1 3566 _000709_hash NULL
83293 +_000710_hash alloc_ts_config 1 45775 _000710_hash NULL
83294 +_000711_hash alloc_upcall 2 62186 _000711_hash NULL
83295 +_000712_hash altera_drscan 2 48698 _000712_hash NULL
83296 +_000713_hash altera_irscan 2 62396 _000713_hash NULL
83297 +_000714_hash altera_set_dr_post 2 54291 _000714_hash NULL
83298 +_000715_hash altera_set_dr_pre 2 64862 _000715_hash NULL
83299 +_000716_hash altera_set_ir_post 2 20948 _000716_hash NULL
83300 +_000717_hash altera_set_ir_pre 2 54103 _000717_hash NULL
83301 +_000718_hash altera_swap_dr 2 50090 _000718_hash NULL
83302 +_000719_hash altera_swap_ir 2 9194 _000719_hash &_000696_hash
83303 +_000720_hash amd_create_gatt_pages 1 20537 _000720_hash NULL
83304 +_000721_hash aoechr_write 3 62883 _001352_hash NULL nohasharray
83305 +_000722_hash applesmc_create_nodes 2 49392 _000722_hash NULL
83306 +_000723_hash array_zalloc 1-2 7519 _000723_hash NULL
83307 +_000725_hash arvo_sysfs_read 6 31617 _000725_hash NULL
83308 +_000726_hash arvo_sysfs_write 6 3311 _000726_hash NULL
83309 +_000727_hash asd_store_update_bios 4 10165 _000727_hash NULL
83310 +_000728_hash ata_host_alloc 2 46094 _000728_hash NULL
83311 +_000729_hash atalk_sendmsg 4 21677 _000729_hash NULL
83312 +_000730_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000730_hash NULL
83313 +_000731_hash ath6kl_mgmt_tx 9 21153 _000731_hash NULL
83314 +_000732_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000732_hash NULL
83315 +_000733_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000733_hash NULL
83316 +_000734_hash ath_descdma_setup 5 12257 _000734_hash NULL
83317 +_000735_hash ath_rx_edma_init 2 65483 _000735_hash NULL
83318 +_000736_hash ati_create_gatt_pages 1 4722 _003185_hash NULL nohasharray
83319 +_000737_hash au0828_init_isoc 2-3 61917 _000737_hash NULL
83320 +_000739_hash audit_init_entry 1 38644 _000739_hash NULL
83321 +_000740_hash ax25_sendmsg 4 62770 _000740_hash NULL
83322 +_000741_hash b1_alloc_card 1 36155 _000741_hash NULL
83323 +_000742_hash b43_nphy_load_samples 3 36481 _000742_hash NULL
83324 +_000743_hash bio_copy_user_iov 4 37660 _000743_hash NULL
83325 +_000744_hash __bio_map_kern 2-3 47379 _000744_hash NULL
83326 +_000746_hash blk_register_region 1-2 51424 _000746_hash NULL
83327 +_000748_hash bm_entry_write 3 28338 _000748_hash NULL
83328 +_000749_hash bm_realloc_pages 2 9431 _000749_hash NULL
83329 +_000750_hash bm_register_write 3 9893 _000750_hash &_000569_hash
83330 +_000751_hash bm_status_write 3 12964 _000751_hash NULL
83331 +_000752_hash br_mdb_rehash 2 42643 _000752_hash NULL
83332 +_000753_hash btrfs_copy_from_user 3 43806 _000753_hash NULL
83333 +_000754_hash btrfs_insert_delayed_dir_index 4 63720 _000754_hash NULL
83334 +_000755_hash __btrfs_map_block 3 49839 _000755_hash NULL
83335 +_000756_hash __c4iw_init_resource_fifo 3 8334 _000756_hash NULL
83336 +_000757_hash cache_downcall 3 13666 _000757_hash NULL
83337 +_000758_hash cache_slow_downcall 2 8570 _000758_hash NULL
83338 +_000759_hash ca_extend 2 64541 _000759_hash NULL
83339 +_000760_hash caif_seqpkt_sendmsg 4 22961 _000760_hash NULL
83340 +_000761_hash caif_stream_sendmsg 4 9110 _000761_hash NULL
83341 +_000762_hash carl9170_cmd_buf 3 950 _000762_hash NULL
83342 +_000763_hash cdev_add 2-3 38176 _000763_hash NULL
83343 +_000765_hash cdrom_read_cdda 4 50478 _000765_hash NULL
83344 +_000766_hash ceph_dns_resolve_name 1 62488 _000766_hash NULL
83345 +_000767_hash ceph_msgpool_get 2 54258 _000767_hash NULL
83346 +_000768_hash cfg80211_connect_result 4-6 56515 _000768_hash NULL
83347 +_000770_hash cfg80211_disconnected 4 57 _000770_hash NULL
83348 +_000771_hash cfg80211_inform_bss 8 19332 _000771_hash NULL
83349 +_000772_hash cfg80211_inform_bss_frame 4 41078 _000772_hash NULL
83350 +_000773_hash cfg80211_mlme_register_mgmt 5 19852 _000773_hash NULL
83351 +_000774_hash cfg80211_roamed_bss 4-6 50198 _000774_hash NULL
83352 +_000776_hash cifs_readdata_alloc 1 50318 _000776_hash NULL
83353 +_000777_hash cifs_readv_from_socket 3 19109 _000777_hash NULL
83354 +_000778_hash cifs_writedata_alloc 1 32880 _003119_hash NULL nohasharray
83355 +_000779_hash cnic_alloc_dma 3 34641 _000779_hash NULL
83356 +_000780_hash configfs_write_file 3 61621 _000780_hash NULL
83357 +_000781_hash construct_key 3 11329 _000781_hash NULL
83358 +_000782_hash context_alloc 3 24645 _000782_hash NULL
83359 +_000783_hash copy_to_user 3 57835 _000783_hash NULL
83360 +_000784_hash create_attr_set 1 22861 _000784_hash NULL
83361 +_000785_hash create_bounce_buffer 3 39155 _000785_hash NULL
83362 +_000786_hash create_gpadl_header 2 19064 _000786_hash NULL
83363 +_000787_hash _create_sg_bios 4 31244 _000787_hash NULL
83364 +_000788_hash cryptd_alloc_instance 2-3 18048 _000788_hash NULL
83365 +_000790_hash crypto_ahash_setkey 3 55134 _000790_hash NULL
83366 +_000791_hash crypto_alloc_instance2 3 25277 _000791_hash NULL
83367 +_000792_hash crypto_shash_setkey 3 60483 _000792_hash NULL
83368 +_000793_hash cx231xx_init_bulk 3-2 47024 _000793_hash NULL
83369 +_000794_hash cx231xx_init_isoc 2-3 56453 _000794_hash NULL
83370 +_000796_hash cx231xx_init_vbi_isoc 2-3 28053 _000796_hash NULL
83371 +_000798_hash cxgb_alloc_mem 1 24007 _000798_hash NULL
83372 +_000799_hash cxgbi_device_portmap_create 3 25747 _000799_hash NULL
83373 +_000800_hash cxgbi_device_register 1-2 36746 _000800_hash NULL
83374 +_000802_hash __cxio_init_resource_fifo 3 23447 _000802_hash NULL
83375 +_000803_hash dccp_sendmsg 4 56058 _000803_hash NULL
83376 +_000804_hash ddp_make_gl 1 12179 _000804_hash NULL
83377 +_000805_hash depth_write 3 3021 _000805_hash NULL
83378 +_000806_hash dev_irnet_write 3 11398 _000806_hash NULL
83379 +_000807_hash dev_set_alias 3 50084 _000807_hash NULL
83380 +_000808_hash dev_write 3 7708 _000808_hash NULL
83381 +_000809_hash dfs_global_file_write 3 6112 _000809_hash NULL
83382 +_000810_hash dgram_sendmsg 4 45679 _000810_hash NULL
83383 +_000811_hash disconnect 4 32521 _000811_hash NULL
83384 +_000812_hash dma_attach 6-7 50831 _000812_hash NULL
83385 +_000814_hash dn_sendmsg 4 38390 _000814_hash NULL
83386 +_000815_hash do_dccp_setsockopt 5 54377 _003160_hash NULL nohasharray
83387 +_000816_hash do_jffs2_setxattr 5 25910 _000816_hash NULL
83388 +_000817_hash do_msgsnd 4 1387 _000817_hash NULL
83389 +_000818_hash do_raw_setsockopt 5 55215 _000818_hash NULL
83390 +_000819_hash do_readv_writev 4 51849 _000819_hash NULL
83391 +_000820_hash do_sync 1 9604 _000820_hash NULL
83392 +_000821_hash dup_array 3 33551 _000821_hash NULL
83393 +_000822_hash dvb_audio_write 3 51275 _000822_hash NULL
83394 +_000823_hash dvb_ca_en50221_init 4 45718 _000823_hash NULL
83395 +_000824_hash dvb_video_write 3 754 _000824_hash NULL
83396 +_000825_hash econet_sendmsg 4 51430 _000825_hash NULL
83397 +_000826_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000826_hash NULL
83398 +_000827_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000827_hash NULL
83399 +_000828_hash ecryptfs_send_message_locked 2 31801 _000828_hash NULL
83400 +_000829_hash edac_device_alloc_ctl_info 1 5941 _000829_hash NULL
83401 +_000830_hash edac_mc_alloc 1 54846 _000830_hash NULL
83402 +_000831_hash edac_pci_alloc_ctl_info 1 63388 _000831_hash NULL
83403 +_000832_hash efivar_create_sysfs_entry 2 19485 _000832_hash NULL
83404 +_000833_hash em28xx_alloc_isoc 4 46892 _000833_hash NULL
83405 +_000834_hash enable_write 3 30456 _000834_hash NULL
83406 +_000835_hash enclosure_register 3 57412 _000835_hash NULL
83407 +_000836_hash ext4_kvzalloc 1 47605 _000836_hash NULL
83408 +_000837_hash extend_netdev_table 2 31680 _000837_hash NULL
83409 +_000838_hash __feat_register_sp 6 64712 _000838_hash NULL
83410 +_000839_hash __ffs_ep0_read_events 3 48868 _000839_hash NULL
83411 +_000840_hash ffs_ep0_write 3 9438 _000840_hash NULL
83412 +_000841_hash ffs_epfile_read 3 18775 _000841_hash NULL
83413 +_000842_hash ffs_epfile_write 3 48014 _000842_hash NULL
83414 +_000843_hash fib_info_hash_alloc 1 9075 _000843_hash NULL
83415 +_000844_hash fillonedir 3 41746 _000844_hash NULL
83416 +_000845_hash flexcop_device_kmalloc 1 54793 _000845_hash NULL
83417 +_000846_hash frame_alloc 4 15981 _000846_hash NULL
83418 +_000847_hash fw_node_create 2 9559 _000847_hash NULL
83419 +_000848_hash garmin_read_process 3 27509 _000848_hash NULL
83420 +_000849_hash garp_request_join 4 7471 _000849_hash NULL
83421 +_000850_hash get_derived_key 4 61100 _000850_hash NULL
83422 +_000851_hash get_entry 4 16003 _000851_hash NULL
83423 +_000852_hash get_free_de 2 33714 _000852_hash NULL
83424 +_000853_hash get_new_cssid 2 51665 _000853_hash NULL
83425 +_000854_hash getxattr 4 24398 _000854_hash NULL
83426 +_000855_hash gspca_dev_probe2 4 59833 _000855_hash NULL
83427 +_000856_hash hcd_alloc_coherent 5 55862 _000856_hash NULL
83428 +_000857_hash hci_sock_sendmsg 4 37420 _000857_hash NULL
83429 +_000858_hash hid_register_field 2-3 4874 _000858_hash NULL
83430 +_000860_hash hid_report_raw_event 4 7024 _000860_hash NULL
83431 +_000861_hash hpi_alloc_control_cache 1 35351 _000861_hash NULL
83432 +_000862_hash hugetlbfs_read_actor 2-5-4 34547 _000862_hash NULL
83433 +_000865_hash hvc_alloc 4 12579 _000865_hash NULL
83434 +_000866_hash __hwahc_dev_set_key 5 46328 _000866_hash NULL
83435 +_000867_hash i2400m_zrealloc_2x 3 54166 _001430_hash NULL nohasharray
83436 +_000868_hash ib_alloc_device 1 26483 _000868_hash NULL
83437 +_000869_hash ib_create_send_mad 5 1196 _000869_hash NULL
83438 +_000870_hash ibmasm_new_command 2 25714 _000870_hash NULL
83439 +_000871_hash ib_send_cm_drep 3 50186 _000871_hash NULL
83440 +_000872_hash ib_send_cm_mra 4 60202 _000872_hash NULL
83441 +_000873_hash ib_send_cm_rtu 3 63138 _000873_hash NULL
83442 +_000874_hash ieee80211_key_alloc 3 19065 _000874_hash NULL
83443 +_000875_hash ieee80211_mgmt_tx 9 46860 _000875_hash NULL
83444 +_000876_hash ieee80211_send_probe_req 6-4 6924 _000876_hash NULL
83445 +_000877_hash if_writecmd 2 815 _000877_hash NULL
83446 +_000878_hash init_bch 1-2 64130 _000878_hash NULL
83447 +_000880_hash init_ipath 1 48187 _000880_hash NULL
83448 +_000881_hash init_list_set 2-3 39188 _000881_hash NULL
83449 +_000883_hash init_q 4 132 _000883_hash NULL
83450 +_000884_hash init_state 2 60165 _000884_hash NULL
83451 +_000885_hash init_tag_map 3 57515 _000885_hash NULL
83452 +_000886_hash input_ff_create 2 21240 _000886_hash NULL
83453 +_000887_hash input_mt_init_slots 2 31183 _000887_hash NULL
83454 +_000888_hash interfaces 2 38859 _000888_hash NULL
83455 +_000889_hash ioat2_alloc_ring 2 11172 _000889_hash NULL
83456 +_000890_hash ip_generic_getfrag 3-4 12187 _000890_hash NULL
83457 +_000892_hash ipr_alloc_ucode_buffer 1 40199 _000892_hash NULL
83458 +_000893_hash ip_set_alloc 1 57953 _000893_hash NULL
83459 +_000894_hash ipv6_flowlabel_opt 3 58135 _001125_hash NULL nohasharray
83460 +_000895_hash ipv6_renew_options 5 28867 _000895_hash NULL
83461 +_000896_hash ipxrtr_route_packet 4 54036 _000896_hash NULL
83462 +_000897_hash irda_sendmsg 4 4388 _000897_hash NULL
83463 +_000898_hash irda_sendmsg_dgram 4 38563 _000898_hash NULL
83464 +_000899_hash irda_sendmsg_ultra 4 42047 _000899_hash NULL
83465 +_000900_hash irias_add_octseq_attrib 4 29983 _000900_hash NULL
83466 +_000901_hash irq_alloc_generic_chip 2 26650 _000901_hash NULL
83467 +_000902_hash irq_domain_add_linear 2 29236 _000902_hash NULL
83468 +_000903_hash iscsi_alloc_session 3 49390 _000903_hash NULL
83469 +_000904_hash iscsi_create_conn 2 50425 _000904_hash NULL
83470 +_000905_hash iscsi_create_endpoint 1 15193 _000905_hash NULL
83471 +_000906_hash iscsi_create_iface 5 38510 _000906_hash NULL
83472 +_000907_hash iscsi_decode_text_input 4 58292 _000907_hash NULL
83473 +_000908_hash iscsi_pool_init 2-4 54913 _000908_hash NULL
83474 +_000910_hash iscsit_dump_data_payload 2 38683 _000910_hash NULL
83475 +_000911_hash isdn_write 3 45863 _000911_hash NULL
83476 +_000912_hash isku_receive 4 54130 _000912_hash NULL
83477 +_000913_hash isku_send 4 41542 _000913_hash NULL
83478 +_000914_hash islpci_mgt_transaction 5 23610 _000914_hash NULL
83479 +_000915_hash iso_sched_alloc 1 13377 _002079_hash NULL nohasharray
83480 +_000916_hash ivtv_v4l2_write 3 39226 _000916_hash NULL
83481 +_000917_hash iwl_trans_txq_alloc 3 36147 _000917_hash NULL
83482 +_000918_hash iwmct_fw_parser_init 4 37876 _000918_hash NULL
83483 +_000919_hash iwm_notif_send 6 12295 _000919_hash NULL
83484 +_000920_hash iwm_ntf_calib_res 3 11686 _000920_hash NULL
83485 +_000921_hash iwm_umac_set_config_var 4 17320 _000921_hash NULL
83486 +_000922_hash ixgbe_alloc_q_vector 3-5 45428 _000922_hash NULL
83487 +_000924_hash jbd2_journal_init_revoke 2 51088 _000924_hash NULL
83488 +_000925_hash jffs2_write_dirent 5 37311 _000925_hash NULL
83489 +_000926_hash journal_init_revoke 2 56933 _000926_hash NULL
83490 +_000927_hash keyctl_instantiate_key 3 41855 _000927_hash NULL
83491 +_000928_hash keyctl_instantiate_key_iov 3 16969 _000928_hash NULL
83492 +_000929_hash __kfifo_from_user 3 20399 _000929_hash NULL
83493 +_000930_hash kimage_crash_alloc 3 3233 _000930_hash NULL
83494 +_000931_hash kimage_normal_alloc 3 31140 _000931_hash NULL
83495 +_000932_hash kmem_realloc 2 37489 _000932_hash NULL
83496 +_000933_hash kmem_zalloc 1 11510 _000933_hash NULL
83497 +_000934_hash koneplus_send 4 18226 _000934_hash NULL
83498 +_000935_hash koneplus_sysfs_read 6 42792 _000935_hash NULL
83499 +_000936_hash kovaplus_send 4 10009 _000936_hash NULL
83500 +_000937_hash kvm_read_guest_page_mmu 6 37611 _000937_hash NULL
83501 +_000938_hash kvm_set_irq_routing 3 48704 _000938_hash NULL
83502 +_000939_hash kvm_write_guest_cached 4 11106 _000939_hash NULL
83503 +_000940_hash kvm_write_guest_page 5 63555 _002809_hash NULL nohasharray
83504 +_000941_hash l2cap_skbuff_fromiovec 3-4 35003 _000941_hash NULL
83505 +_000943_hash l2tp_ip_sendmsg 4 50411 _000943_hash NULL
83506 +_000944_hash l2tp_session_create 1 25286 _000944_hash NULL
83507 +_000945_hash lc_create 3 48662 _000945_hash NULL
83508 +_000946_hash leaf_dealloc 3 29566 _000946_hash NULL
83509 +_000947_hash linear_conf 2 23485 _000947_hash NULL
83510 +_000948_hash lirc_buffer_init 2-3 53282 _000948_hash NULL
83511 +_000950_hash llc_ui_sendmsg 4 24987 _000950_hash NULL
83512 +_000951_hash lpfc_sli4_queue_alloc 3 62646 _000951_hash NULL
83513 +_000952_hash mce_request_packet 3 1073 _000952_hash NULL
83514 +_000953_hash mdiobus_alloc_size 1 52259 _000953_hash NULL
83515 +_000954_hash media_entity_init 2-4 15870 _001556_hash NULL nohasharray
83516 +_000956_hash memstick_alloc_host 1 142 _000956_hash NULL
83517 +_000957_hash mesh_table_alloc 1 22305 _000957_hash NULL
83518 +_000958_hash mfd_add_devices 4 56753 _000958_hash NULL
83519 +_000959_hash mISDN_sock_sendmsg 4 41035 _000959_hash NULL
83520 +_000960_hash mmc_alloc_host 1 48097 _000960_hash NULL
83521 +_000961_hash mmc_test_alloc_mem 3 28102 _000961_hash NULL
83522 +_000962_hash mpi_alloc 1 18094 _000962_hash NULL
83523 +_000963_hash mpihelp_mul_karatsuba_case 5-3 23918 _000963_hash NULL
83524 +_000964_hash mpihelp_mul_n 4 16405 _000964_hash NULL
83525 +_000965_hash mpi_set_bit 2 15104 _000965_hash NULL
83526 +_000966_hash mpi_set_highbit 2 37327 _001420_hash NULL nohasharray
83527 +_000967_hash mtd_concat_create 2 14416 _000967_hash NULL
83528 +_000968_hash mvumi_alloc_mem_resource 3 47750 _000968_hash NULL
83529 +_000969_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _000969_hash NULL
83530 +_000970_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _000970_hash NULL
83531 +_000972_hash mwl8k_cmd_set_beacon 4 23110 _000972_hash NULL
83532 +_000973_hash neigh_hash_alloc 1 17595 _000973_hash NULL
83533 +_000974_hash netlink_sendmsg 4 33708 _001172_hash NULL nohasharray
83534 +_000975_hash netxen_alloc_sds_rings 2 13417 _000975_hash NULL
83535 +_000976_hash new_bind_ctl 2 35324 _000976_hash NULL
83536 +_000977_hash new_dir 3 31919 _000977_hash NULL
83537 +_000978_hash new_tape_buffer 2 32866 _000978_hash NULL
83538 +_000979_hash nfc_llcp_build_tlv 3 19536 _000979_hash NULL
83539 +_000980_hash nfc_llcp_send_i_frame 3 59130 _000980_hash NULL
83540 +_000981_hash nfs4_alloc_slots 1 2454 _000981_hash NULL
83541 +_000982_hash nfsctl_transaction_write 3 64800 _000982_hash NULL
83542 +_000983_hash nfs_idmap_request_key 3 30208 _000983_hash NULL
83543 +_000984_hash nfs_readdata_alloc 1 9990 _000984_hash NULL
83544 +_000985_hash nfs_writedata_alloc 1 62868 _000985_hash NULL
83545 +_000986_hash nl_pid_hash_zalloc 1 23314 _000986_hash NULL
83546 +_000987_hash nr_sendmsg 4 53656 _000987_hash NULL
83547 +_000988_hash nsm_create_handle 4 38060 _000988_hash NULL
83548 +_000989_hash ntfs_copy_from_user_iovec 3-6 49829 _000989_hash NULL
83549 +_000991_hash ntfs_file_buffered_write 4-6 41442 _000991_hash NULL
83550 +_000993_hash __ntfs_malloc 1 34022 _000993_hash NULL
83551 +_000994_hash nvme_alloc_queue 3 46865 _000994_hash NULL
83552 +_000995_hash ocfs2_acl_from_xattr 2 21604 _000995_hash NULL
83553 +_000996_hash ocfs2_control_message 3 19564 _000996_hash NULL
83554 +_000997_hash opera1_usb_i2c_msgxfer 4 64521 _000997_hash NULL
83555 +_000998_hash _ore_get_io_state 3 2166 _000998_hash NULL
83556 +_000999_hash orig_hash_add_if 2 53676 _000999_hash NULL
83557 +_001000_hash orig_hash_del_if 2 45080 _001000_hash NULL
83558 +_001001_hash orinoco_set_key 5-7 17878 _001001_hash NULL
83559 +_001003_hash osdmap_set_max_osd 2 57630 _001003_hash NULL
83560 +_001004_hash _osd_realloc_seg 3 54352 _001004_hash NULL
83561 +_001005_hash OSDSetBlock 2-4 38986 _001005_hash NULL
83562 +_001007_hash osst_execute 7-6 17607 _001007_hash NULL
83563 +_001008_hash osst_write 3 31581 _001008_hash NULL
83564 +_001009_hash otp_read 2-5-4 10594 _001009_hash NULL
83565 +_001012_hash ovs_vport_alloc 1 33475 _001012_hash NULL
83566 +_001013_hash packet_sendmsg_spkt 4 28885 _001013_hash NULL
83567 +_001014_hash pair_device 4 61175 _001708_hash NULL nohasharray
83568 +_001015_hash pccard_store_cis 6 18176 _001015_hash NULL
83569 +_001016_hash pci_add_cap_save_buffer 3 3426 _001016_hash NULL
83570 +_001017_hash pcnet32_realloc_rx_ring 3 36598 _001017_hash NULL
83571 +_001018_hash pcnet32_realloc_tx_ring 3 38428 _001018_hash NULL
83572 +_001019_hash pcpu_mem_zalloc 1 22948 _001019_hash NULL
83573 +_001020_hash pep_sendmsg 4 62524 _001020_hash NULL
83574 +_001021_hash pfkey_sendmsg 4 47394 _001021_hash NULL
83575 +_001022_hash pidlist_resize 2 496 _001022_hash NULL
83576 +_001023_hash pin_code_reply 4 46510 _001023_hash NULL
83577 +_001024_hash ping_getfrag 3-4 8360 _001024_hash NULL
83578 +_001026_hash pipe_set_size 2 5204 _001026_hash NULL
83579 +_001027_hash pkt_bio_alloc 1 48284 _001027_hash NULL
83580 +_001028_hash platform_create_bundle 4-6 12785 _001028_hash NULL
83581 +_001030_hash play_iframe 3 8219 _001030_hash NULL
83582 +_001031_hash pm8001_store_update_fw 4 55716 _001031_hash NULL
83583 +_001032_hash pmcraid_alloc_sglist 1 9864 _001032_hash NULL
83584 +_001033_hash pn533_dep_link_up 5 7659 _001033_hash NULL
83585 +_001034_hash pnp_alloc 1 24869 _001419_hash NULL nohasharray
83586 +_001035_hash pn_sendmsg 4 12640 _001035_hash NULL
83587 +_001036_hash pppoe_sendmsg 4 48039 _001036_hash NULL
83588 +_001037_hash pppol2tp_sendmsg 4 56420 _001037_hash NULL
83589 +_001038_hash process_vm_rw 3-5 47533 _001038_hash NULL
83590 +_001040_hash process_vm_rw_single_vec 1-2 26213 _001040_hash NULL
83591 +_001042_hash proc_write 3 51003 _001042_hash NULL
83592 +_001043_hash profile_load 3 58267 _001043_hash NULL
83593 +_001044_hash profile_remove 3 8556 _001044_hash NULL
83594 +_001045_hash profile_replace 3 14652 _001045_hash NULL
83595 +_001046_hash pscsi_get_bio 1 56103 _001046_hash NULL
83596 +_001047_hash pyra_send 4 12061 _001047_hash NULL
83597 +_001048_hash qc_capture 3 19298 _001048_hash NULL
83598 +_001049_hash qla4xxx_alloc_work 2 44813 _001049_hash NULL
83599 +_001050_hash qlcnic_alloc_msix_entries 2 46160 _001050_hash NULL
83600 +_001051_hash qlcnic_alloc_sds_rings 2 26795 _001051_hash NULL
83601 +_001052_hash queue_received_packet 5 9657 _001052_hash NULL
83602 +_001053_hash raw_send_hdrinc 4 58803 _001053_hash NULL
83603 +_001054_hash raw_sendmsg 4 23078 _001054_hash &_000022_hash
83604 +_001055_hash rawsock_sendmsg 4 60010 _001055_hash NULL
83605 +_001056_hash rawv6_send_hdrinc 3 35425 _001056_hash NULL
83606 +_001057_hash rb_alloc 1 3102 _001057_hash NULL
83607 +_001058_hash rbd_alloc_coll 1 33678 _001058_hash NULL
83608 +_001059_hash rbd_create_rw_ops 2 4605 _001059_hash NULL
83609 +_001060_hash rds_ib_inc_copy_to_user 3 55007 _001060_hash NULL
83610 +_001061_hash rds_iw_inc_copy_to_user 3 29214 _001061_hash NULL
83611 +_001062_hash rds_message_alloc 1 10517 _001062_hash NULL
83612 +_001063_hash rds_message_copy_from_user 3 45510 _001063_hash NULL
83613 +_001064_hash rds_message_inc_copy_to_user 3 26540 _001064_hash NULL
83614 +_001065_hash redrat3_transmit_ir 3 64244 _001065_hash NULL
83615 +_001066_hash regcache_rbtree_insert_to_block 5 58009 _001066_hash NULL
83616 +_001067_hash _regmap_raw_write 4 42652 _001067_hash NULL
83617 +_001068_hash regmap_register_patch 3 21681 _001068_hash NULL
83618 +_001069_hash relay_alloc_page_array 1 52735 _001069_hash NULL
83619 +_001070_hash remove_uuid 4 64505 _001070_hash NULL
83620 +_001071_hash reshape_ring 2 29147 _001071_hash NULL
83621 +_001072_hash RESIZE_IF_NEEDED 2 56286 _001072_hash NULL
83622 +_001073_hash resize_stripes 2 61650 _001073_hash NULL
83623 +_001074_hash rfcomm_sock_sendmsg 4 37661 _001074_hash NULL
83624 +_001075_hash rose_sendmsg 4 20249 _001075_hash NULL
83625 +_001076_hash rxrpc_send_data 5 21553 _001076_hash NULL
83626 +_001077_hash rxrpc_setsockopt 5 50286 _001077_hash NULL
83627 +_001078_hash saa7146_vmalloc_build_pgtable 2 19780 _001078_hash NULL
83628 +_001079_hash saa7164_buffer_alloc_user 2 9627 _001079_hash NULL
83629 +_001081_hash sco_send_frame 3 41815 _001081_hash NULL
83630 +_001082_hash scsi_host_alloc 2 63041 _001082_hash NULL
83631 +_001083_hash scsi_tgt_kspace_exec 8 9522 _001083_hash NULL
83632 +_001084_hash sctp_sendmsg 4 61919 _001084_hash NULL
83633 +_001085_hash sctp_setsockopt 5 44788 _001085_hash NULL
83634 +_001086_hash sctp_setsockopt_connectx 3 6073 _001086_hash NULL
83635 +_001087_hash sctp_setsockopt_connectx_old 3 22631 _001087_hash NULL
83636 +_001088_hash sctp_tsnmap_init 2 36446 _001088_hash NULL
83637 +_001089_hash sctp_user_addto_chunk 2-3 62047 _001089_hash NULL
83638 +_001091_hash security_context_to_sid 2 19839 _001091_hash NULL
83639 +_001092_hash security_context_to_sid_default 2 3492 _001092_hash NULL
83640 +_001093_hash security_context_to_sid_force 2 20724 _001093_hash NULL
83641 +_001094_hash selinux_transaction_write 3 59038 _001094_hash NULL
83642 +_001095_hash sel_write_access 3 51704 _001095_hash NULL
83643 +_001096_hash sel_write_create 3 11353 _001096_hash NULL
83644 +_001097_hash sel_write_member 3 28800 _001097_hash NULL
83645 +_001098_hash sel_write_relabel 3 55195 _001098_hash NULL
83646 +_001099_hash sel_write_user 3 45060 _001099_hash NULL
83647 +_001100_hash __seq_open_private 3 40715 _001100_hash NULL
83648 +_001101_hash serverworks_create_gatt_pages 1 46582 _001101_hash NULL
83649 +_001102_hash set_connectable 4 56458 _001102_hash NULL
83650 +_001103_hash set_dev_class 4 39645 _001697_hash NULL nohasharray
83651 +_001104_hash set_discoverable 4 48141 _001104_hash NULL
83652 +_001105_hash setkey 3 14987 _001105_hash NULL
83653 +_001106_hash set_le 4 30581 _001106_hash NULL
83654 +_001107_hash set_link_security 4 4502 _001107_hash NULL
83655 +_001108_hash set_local_name 4 55757 _001108_hash NULL
83656 +_001109_hash set_powered 4 12129 _001109_hash NULL
83657 +_001110_hash set_ssp 4 62411 _001110_hash NULL
83658 +_001111_hash sg_build_sgat 3 60179 _001111_hash &_000305_hash
83659 +_001112_hash sg_read_oxfer 3 51724 _001112_hash NULL
83660 +_001113_hash shmem_xattr_set 4 11843 _001113_hash NULL
83661 +_001114_hash simple_alloc_urb 3 60420 _001114_hash NULL
83662 +_001115_hash sisusb_send_bridge_packet 2 11649 _001115_hash NULL
83663 +_001116_hash sisusb_send_packet 2 20891 _001116_hash NULL
83664 +_001117_hash skb_add_data_nocache 4 4682 _001117_hash NULL
83665 +_001118_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001118_hash NULL
83666 +_001121_hash skb_copy_to_page_nocache 6 58624 _001121_hash NULL
83667 +_001122_hash sk_chk_filter 2 42095 _001122_hash NULL
83668 +_001123_hash skcipher_sendmsg 4 30290 _001123_hash NULL
83669 +_001124_hash sl_change_mtu 2 7396 _001124_hash NULL
83670 +_001125_hash slhc_init 1-2 58135 _001125_hash &_000894_hash
83671 +_001127_hash sm501_create_subdev 3-4 48668 _001127_hash NULL
83672 +_001129_hash smk_write_access 3 49561 _001129_hash NULL
83673 +_001130_hash snapshot_write 3 28351 _001130_hash NULL
83674 +_001131_hash snd_ac97_pcm_assign 2 30218 _001131_hash NULL
83675 +_001132_hash snd_card_create 4 64418 _001411_hash NULL nohasharray
83676 +_001133_hash snd_emux_create_port 3 42533 _001133_hash NULL
83677 +_001134_hash snd_gus_dram_write 4 38784 _001134_hash NULL
83678 +_001135_hash snd_midi_channel_alloc_set 1 28153 _001135_hash NULL
83679 +_001136_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001136_hash NULL
83680 +_001137_hash snd_pcm_oss_sync1 2 45298 _001137_hash NULL
83681 +_001138_hash snd_pcm_oss_write 3 38108 _001138_hash NULL
83682 +_001139_hash snd_pcm_plugin_build 5 25505 _001139_hash NULL
83683 +_001140_hash snd_rawmidi_kernel_write 3 25106 _001140_hash NULL
83684 +_001141_hash snd_rawmidi_write 3 28008 _001141_hash NULL
83685 +_001142_hash snd_rme32_playback_copy 5 43732 _001142_hash NULL
83686 +_001143_hash snd_rme96_playback_copy 5 13111 _001143_hash NULL
83687 +_001144_hash snd_seq_device_new 4 31753 _001144_hash NULL
83688 +_001145_hash snd_seq_oss_readq_new 2 14283 _001145_hash NULL
83689 +_001146_hash snd_vx_create 4 40948 _001146_hash NULL
83690 +_001147_hash sock_setsockopt 5 50088 _001147_hash NULL
83691 +_001148_hash sound_write 3 5102 _001148_hash NULL
83692 +_001149_hash _sp2d_alloc 1 16944 _001149_hash NULL
83693 +_001150_hash spi_alloc_master 2 45223 _001150_hash NULL
83694 +_001151_hash spidev_message 3 5518 _001151_hash NULL
83695 +_001152_hash spi_register_board_info 2 35651 _001152_hash NULL
83696 +_001153_hash squashfs_cache_init 2 41656 _001153_hash NULL
83697 +_001154_hash squashfs_read_data 6 59440 _001154_hash NULL
83698 +_001155_hash srp_alloc_iu 2 44227 _001155_hash NULL
83699 +_001156_hash srp_iu_pool_alloc 2 17920 _001156_hash NULL
83700 +_001157_hash srp_ring_alloc 2 26760 _001157_hash NULL
83701 +_001159_hash start_isoc_chain 2 565 _001159_hash NULL
83702 +_001160_hash stk_prepare_sio_buffers 2 57168 _001160_hash NULL
83703 +_001161_hash store_iwmct_log_level 4 60209 _001161_hash NULL
83704 +_001162_hash store_iwmct_log_level_fw 4 1974 _001162_hash NULL
83705 +_001163_hash st_write 3 16874 _001163_hash NULL
83706 +_001164_hash svc_pool_map_alloc_arrays 2 47181 _001164_hash NULL
83707 +_001165_hash symtab_init 2 61050 _001165_hash NULL
83708 +_001166_hash sys_bind 3 10799 _001166_hash NULL
83709 +_001167_hash sys_connect 3 15291 _001167_hash NULL
83710 +_001168_hash sys_flistxattr 3 41407 _001168_hash NULL
83711 +_001169_hash sys_fsetxattr 4 49736 _001169_hash NULL
83712 +_001170_hash sysfs_write_file 3 57116 _001170_hash NULL
83713 +_001171_hash sys_ipc 3 4889 _001171_hash NULL
83714 +_001172_hash sys_keyctl 4 33708 _001172_hash &_000974_hash
83715 +_001173_hash sys_listxattr 3 27833 _001173_hash NULL
83716 +_001174_hash sys_llistxattr 3 4532 _001174_hash NULL
83717 +_001175_hash sys_lsetxattr 4 61177 _001175_hash NULL
83718 +_001176_hash sys_mq_timedsend 3 57661 _001176_hash NULL
83719 +_001177_hash sys_sched_setaffinity 2 32046 _001177_hash NULL
83720 +_001178_hash sys_semop 3 39457 _001178_hash NULL
83721 +_001179_hash sys_sendto 6 20809 _001179_hash NULL
83722 +_001180_hash sys_setxattr 4 37880 _001180_hash NULL
83723 +_001181_hash t4_alloc_mem 1 32342 _001181_hash NULL
83724 +_001182_hash tcf_hash_create 4 54360 _001182_hash NULL
83725 +_001183_hash __team_options_register 3 63941 _001183_hash NULL
83726 +_001184_hash test_unaligned_bulk 3 52333 _001184_hash NULL
83727 +_001185_hash tifm_alloc_adapter 1 10903 _001185_hash NULL
83728 +_001186_hash timeout_write 3 50991 _001186_hash NULL
83729 +_001187_hash tipc_link_send_sections_fast 4 37920 _001187_hash NULL
83730 +_001188_hash tipc_subseq_alloc 1 5957 _001188_hash NULL
83731 +_001189_hash tm6000_read_write_usb 7 50774 _002917_hash NULL nohasharray
83732 +_001190_hash tnode_alloc 1 49407 _001190_hash NULL
83733 +_001191_hash tomoyo_commit_ok 2 20167 _001191_hash NULL
83734 +_001192_hash tomoyo_scan_bprm 2-4 15642 _001192_hash NULL
83735 +_001194_hash tps65910_i2c_write 3 39531 _001194_hash NULL
83736 +_001195_hash ts_write 3 64336 _001195_hash NULL
83737 +_001196_hash ttusb2_msg 4 3100 _001196_hash NULL
83738 +_001197_hash tty_write 3 5494 _001197_hash NULL
83739 +_001198_hash ubi_dbg_check_all_ff 4 59810 _001198_hash NULL
83740 +_001199_hash ubi_dbg_check_write 5 48525 _001199_hash NULL
83741 +_001200_hash ubifs_setxattr 4 59650 _001370_hash NULL nohasharray
83742 +_001201_hash udf_sb_alloc_partition_maps 2 62313 _001201_hash NULL
83743 +_001202_hash udplite_getfrag 3-4 14479 _001202_hash NULL
83744 +_001204_hash ulong_write_file 3 26485 _001204_hash NULL
83745 +_001205_hash unix_dgram_sendmsg 4 45699 _001205_hash NULL
83746 +_001206_hash unix_stream_sendmsg 4 61455 _001206_hash NULL
83747 +_001207_hash unlink_queued 3-4 645 _001207_hash NULL
83748 +_001208_hash update_pmkid 4 2481 _001208_hash NULL
83749 +_001209_hash usb_alloc_coherent 2 65444 _001209_hash NULL
83750 +_001210_hash uvc_alloc_buffers 2 9656 _001210_hash NULL
83751 +_001211_hash uvc_alloc_entity 3-4 20836 _001211_hash NULL
83752 +_001212_hash v4l2_ctrl_new 7 38725 _001212_hash NULL
83753 +_001213_hash v4l2_event_subscribe 3 19510 _001213_hash NULL
83754 +_001214_hash vb2_read 3 42703 _001214_hash NULL
83755 +_001215_hash vb2_write 3 31948 _001215_hash NULL
83756 +_001216_hash vc_resize 2-3 3585 _001216_hash NULL
83757 +_001218_hash __vhost_add_used_n 3 26554 _001218_hash NULL
83758 +_001219_hash __videobuf_alloc_vb 1 27062 _001219_hash NULL
83759 +_001220_hash videobuf_dma_init_kernel 3 6963 _001220_hash NULL
83760 +_001221_hash virtqueue_add_buf 3-4 59470 _001221_hash NULL
83761 +_001223_hash vmalloc 1 15464 _001223_hash NULL
83762 +_001224_hash vmalloc_to_sg 2 58354 _001224_hash NULL
83763 +_001225_hash vol_cdev_write 3 40915 _001225_hash NULL
83764 +_001226_hash vxge_device_register 4 7752 _001226_hash NULL
83765 +_001227_hash __vxge_hw_channel_allocate 3 55462 _001227_hash NULL
83766 +_001228_hash vzalloc 1 47421 _001228_hash NULL
83767 +_001229_hash vzalloc_node 1 23424 _001229_hash NULL
83768 +_001230_hash wa_nep_queue 2 8858 _001230_hash NULL
83769 +_001231_hash __wa_xfer_setup_segs 2 56725 _001231_hash NULL
83770 +_001232_hash wiphy_new 2 2482 _001232_hash NULL
83771 +_001233_hash wpan_phy_alloc 1 48056 _001233_hash NULL
83772 +_001234_hash wusb_ccm_mac 7 32199 _001234_hash NULL
83773 +_001235_hash x25_sendmsg 4 12487 _001235_hash NULL
83774 +_001236_hash xfrm_hash_alloc 1 10997 _001236_hash NULL
83775 +_001237_hash _xfs_buf_get_pages 2 46811 _001237_hash NULL
83776 +_001238_hash xfs_da_buf_make 1 55845 _001238_hash NULL
83777 +_001239_hash xfs_da_grow_inode_int 3 21785 _001239_hash NULL
83778 +_001240_hash xfs_dir_cilookup_result 3 64288 _003139_hash NULL nohasharray
83779 +_001241_hash xfs_iext_add_indirect_multi 3 32400 _001241_hash NULL
83780 +_001242_hash xfs_iext_inline_to_direct 2 12384 _001242_hash NULL
83781 +_001243_hash xfs_iroot_realloc 2 46826 _001243_hash NULL
83782 +_001244_hash xhci_alloc_stream_info 3 63902 _001244_hash NULL
83783 +_001245_hash xlog_recover_add_to_trans 4 62839 _001245_hash NULL
83784 +_001246_hash xprt_alloc 2 1475 _001246_hash NULL
83785 +_001247_hash xt_alloc_table_info 1 57903 _001247_hash NULL
83786 +_001248_hash _zd_iowrite32v_async_locked 3 39034 _001248_hash NULL
83787 +_001249_hash zd_usb_iowrite16v 3 49744 _001249_hash NULL
83788 +_001250_hash acpi_ds_build_internal_package_obj 3 58271 _001250_hash NULL
83789 +_001251_hash acpi_system_read_event 3 55362 _001251_hash NULL
83790 +_001252_hash acpi_ut_create_buffer_object 1 42030 _001252_hash NULL
83791 +_001253_hash acpi_ut_create_package_object 1 17594 _001253_hash NULL
83792 +_001254_hash acpi_ut_create_string_object 1 15360 _001254_hash NULL
83793 +_001255_hash ad7879_spi_multi_read 3 8218 _001255_hash NULL
83794 +_001256_hash add_child 4 45201 _001256_hash NULL
83795 +_001257_hash add_port 2 54941 _001257_hash NULL
83796 +_001258_hash adu_read 3 24177 _001258_hash NULL
83797 +_001259_hash afs_cell_create 2 27346 _001259_hash NULL
83798 +_001260_hash agp_generic_alloc_user 1 9470 _001260_hash NULL
83799 +_001261_hash alloc_agpphysmem_i8xx 1 39427 _001261_hash NULL
83800 +_001262_hash allocate_cnodes 1 5329 _001262_hash NULL
83801 +_001263_hash ___alloc_bootmem 1 11410 _001263_hash NULL
83802 +_001264_hash __alloc_bootmem_nopanic 1 65397 _001264_hash NULL
83803 +_001265_hash alloc_bulk_urbs_generic 5 12127 _001265_hash NULL
83804 +_001266_hash alloc_candev 1-2 7776 _001266_hash NULL
83805 +_001268_hash ____alloc_ei_netdev 1 51475 _001268_hash NULL
83806 +_001269_hash alloc_etherdev_mqs 1 36450 _001269_hash NULL
83807 +_001270_hash alloc_extent_buffer 3 52824 _001270_hash NULL
83808 +_001271_hash alloc_fcdev 1 18780 _001271_hash NULL
83809 +_001272_hash alloc_fddidev 1 15382 _001272_hash NULL
83810 +_001273_hash alloc_hippi_dev 1 51320 _001273_hash NULL
83811 +_001274_hash alloc_irdadev 1 19140 _001274_hash NULL
83812 +_001275_hash alloc_ltalkdev 1 38071 _001275_hash NULL
83813 +_001276_hash alloc_one_pg_vec_page 1 10747 _001276_hash NULL
83814 +_001277_hash alloc_orinocodev 1 21371 _001277_hash NULL
83815 +_001279_hash alloc_trdev 1 16399 _001279_hash NULL
83816 +_001280_hash async_setkey 3 35521 _001280_hash NULL
83817 +_001281_hash ata_host_alloc_pinfo 3 17325 _001281_hash NULL
83818 +_001284_hash ath6kl_connect_event 7-9-8 14267 _001284_hash NULL
83819 +_001285_hash ath6kl_fwlog_block_read 3 49836 _001285_hash NULL
83820 +_001286_hash ath6kl_fwlog_read 3 32101 _001286_hash NULL
83821 +_001287_hash ath_rx_init 2 43564 _001287_hash NULL
83822 +_001288_hash ath_tx_init 2 60515 _001288_hash NULL
83823 +_001289_hash atm_get_addr 3 31221 _001289_hash NULL
83824 +_001290_hash av7110_ipack_init 2 46655 _001290_hash NULL
83825 +_001291_hash bdx_rxdb_create 1 46525 _001291_hash NULL
83826 +_001292_hash bdx_tx_db_init 2 41719 _001292_hash NULL
83827 +_001293_hash bio_map_kern 3 64751 _001293_hash NULL
83828 +_001294_hash bits_to_user 3 47733 _001294_hash NULL
83829 +_001295_hash __blk_queue_init_tags 2 9778 _001295_hash NULL
83830 +_001296_hash blk_queue_resize_tags 2 28670 _001296_hash NULL
83831 +_001297_hash blk_rq_map_user_iov 5 16772 _001297_hash NULL
83832 +_001298_hash bm_init 2 13529 _001298_hash NULL
83833 +_001299_hash brcmf_alloc_wdev 1 60347 _001299_hash NULL
83834 +_001300_hash btrfs_insert_dir_item 4 59304 _001300_hash NULL
83835 +_001301_hash btrfs_map_block 3 64379 _001301_hash NULL
83836 +_001302_hash c4_add_card 3 54968 _001302_hash NULL
83837 +_001303_hash cache_read 3 24790 _001303_hash NULL
83838 +_001304_hash cache_write 3 13589 _001304_hash NULL
83839 +_001305_hash calc_hmac 3 32010 _001305_hash NULL
83840 +_001306_hash ccid_getsockopt_builtin_ccids 2 53634 _001306_hash NULL
83841 +_001307_hash ceph_copy_page_vector_to_user 4 31270 _001307_hash NULL
83842 +_001308_hash ceph_read_dir 3 17005 _001308_hash NULL
83843 +_001309_hash cfg80211_roamed 5-7 32632 _001309_hash NULL
83844 +_001311_hash ci_ll_init 3 12930 _001311_hash NULL
83845 +_001312_hash coda_psdev_read 3 35029 _001312_hash NULL
83846 +_001313_hash construct_key_and_link 4 8321 _001313_hash NULL
83847 +_001314_hash copy_counters_to_user 5 17027 _001824_hash NULL nohasharray
83848 +_001315_hash copy_entries_to_user 1 52367 _001315_hash NULL
83849 +_001316_hash copy_from_buf 4 27308 _001316_hash NULL
83850 +_001317_hash copy_oldmem_page 3 26164 _001317_hash NULL
83851 +_001318_hash copy_to_user_fromio 3 57432 _001318_hash NULL
83852 +_001319_hash cryptd_hash_setkey 3 42781 _001319_hash NULL
83853 +_001320_hash crypto_authenc_esn_setkey 3 6985 _001320_hash NULL
83854 +_001321_hash crypto_authenc_setkey 3 80 _001321_hash NULL
83855 +_001322_hash cx18_copy_buf_to_user 4 22735 _001322_hash NULL
83856 +_001324_hash cxgbi_ddp_reserve 4 30091 _001324_hash NULL
83857 +_001325_hash datablob_hmac_append 3 40038 _001325_hash NULL
83858 +_001326_hash datablob_hmac_verify 4 24786 _001326_hash NULL
83859 +_001327_hash dataflash_read_fact_otp 3-2 33204 _001327_hash NULL
83860 +_001328_hash dataflash_read_user_otp 3-2 14536 _001328_hash &_000201_hash
83861 +_001329_hash dccp_feat_register_sp 5 17914 _001329_hash NULL
83862 +_001330_hash ddb_input_read 3 9743 _001330_hash NULL
83863 +_001331_hash dev_read 3 56369 _001331_hash NULL
83864 +_001332_hash diva_os_copy_to_user 4 48508 _001332_hash NULL
83865 +_001333_hash diva_os_malloc 2 16406 _001333_hash NULL
83866 +_001334_hash dlm_dir_lookup 4 56662 _001334_hash NULL
83867 +_001335_hash dm_vcalloc 1-2 16814 _001335_hash NULL
83868 +_001337_hash do_proc_readlink 3 14096 _001337_hash NULL
83869 +_001338_hash do_readlink 2 43518 _001338_hash NULL
83870 +_001339_hash __do_replace 5 37227 _001339_hash NULL
83871 +_001340_hash do_sigpending 2 9766 _001340_hash NULL
83872 +_001341_hash drbd_setsockopt 5 16280 _001341_hash &_000371_hash
83873 +_001342_hash dsp_buffer_alloc 2 11684 _001342_hash NULL
83874 +_001343_hash dump_midi 3 51040 _001343_hash NULL
83875 +_001344_hash dvb_dmxdev_set_buffer_size 2 55643 _001344_hash NULL
83876 +_001345_hash dvb_dvr_set_buffer_size 2 9840 _001345_hash NULL
83877 +_001346_hash dvb_ringbuffer_pkt_read_user 3-5-2 4303 _001346_hash NULL
83878 +_001348_hash dvb_ringbuffer_read_user 3 56702 _001348_hash NULL
83879 +_001349_hash ecryptfs_filldir 3 6622 _001349_hash NULL
83880 +_001350_hash ecryptfs_readlink 3 40775 _001350_hash NULL
83881 +_001351_hash ecryptfs_send_message 2 18322 _001351_hash NULL
83882 +_001352_hash em28xx_init_isoc 4 62883 _001352_hash &_000721_hash
83883 +_001353_hash et61x251_read 3 25420 _001353_hash NULL
83884 +_001354_hash ext4_add_new_descs 3 19509 _001354_hash NULL
83885 +_001355_hash fat_ioctl_filldir 3 36621 _001355_hash NULL
83886 +_001356_hash fd_copyout 3 59323 _001356_hash NULL
83887 +_001357_hash f_hidg_read 3 6238 _001357_hash NULL
83888 +_001358_hash filldir 3 55137 _001358_hash NULL
83889 +_001359_hash filldir64 3 46469 _001359_hash NULL
83890 +_001360_hash fops_read 3 40672 _001360_hash NULL
83891 +_001361_hash from_buffer 3 18625 _001361_hash NULL
83892 +_001362_hash fsm_init 2 16134 _001362_hash NULL
83893 +_001363_hash get_subdir 3 62581 _001363_hash NULL
83894 +_001364_hash gspca_dev_probe 4 2570 _001364_hash NULL
83895 +_001365_hash handle_received_packet 3 22457 _001365_hash NULL
83896 +_001366_hash hash_setkey 3 48310 _001366_hash NULL
83897 +_001367_hash hdlcdrv_register 2 6792 _001367_hash NULL
83898 +_001368_hash hdpvr_read 3 9273 _001368_hash NULL
83899 +_001369_hash hid_input_report 4 32458 _001369_hash NULL
83900 +_001370_hash hidraw_read 3 59650 _001370_hash &_001200_hash
83901 +_001371_hash HiSax_readstatus 2 15752 _001371_hash NULL
83902 +_001373_hash __hwahc_op_set_gtk 4 42038 _001373_hash NULL
83903 +_001374_hash __hwahc_op_set_ptk 5 36510 _001374_hash NULL
83904 +_001375_hash ib_copy_to_udata 3 27525 _001375_hash NULL
83905 +_001376_hash idetape_chrdev_read 3 2097 _001376_hash NULL
83906 +_001377_hash ieee80211_alloc_hw 1 43829 _001377_hash NULL
83907 +_001378_hash ieee80211_bss_info_update 4 13991 _001378_hash NULL
83908 +_001379_hash ilo_read 3 32531 _001379_hash NULL
83909 +_001380_hash init_map_ipmac 3-4 63896 _001380_hash NULL
83910 +_001382_hash init_tid_tabs 2-4-3 13252 _001382_hash NULL
83911 +_001385_hash iowarrior_read 3 53483 _001385_hash NULL
83912 +_001386_hash ipv6_getsockopt_sticky 5 56711 _001386_hash NULL
83913 +_001387_hash ipwireless_send_packet 4 8328 _001387_hash NULL
83914 +_001388_hash ipx_sendmsg 4 1362 _001388_hash NULL
83915 +_001389_hash iscsi_conn_setup 2 35159 _001389_hash NULL
83916 +_001390_hash iscsi_create_session 3 51647 _001390_hash NULL
83917 +_001391_hash iscsi_host_alloc 2 36671 _001391_hash NULL
83918 +_001392_hash iscsi_session_setup 4-5 196 _001392_hash NULL
83919 +_001394_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _001701_hash NULL nohasharray
83920 +_001395_hash isdn_ppp_read 4 50356 _001395_hash NULL
83921 +_001396_hash isku_sysfs_read 6 58806 _001396_hash NULL
83922 +_001397_hash isku_sysfs_write 6 49767 _001397_hash NULL
83923 +_001398_hash iso_alloc_urb 4-5 45206 _001398_hash NULL
83924 +_001400_hash ivtv_copy_buf_to_user 4 6159 _001400_hash NULL
83925 +_001401_hash iwm_rx_handle 3 24899 _001401_hash NULL
83926 +_001402_hash iwm_wdev_alloc 1 38415 _001402_hash NULL
83927 +_001403_hash jbd2_alloc 1 41359 _001403_hash NULL
83928 +_001404_hash jffs2_do_link 6 42048 _001404_hash NULL
83929 +_001405_hash jffs2_do_unlink 4 62020 _001405_hash NULL
83930 +_001406_hash jffs2_security_setxattr 4 62107 _001406_hash NULL
83931 +_001407_hash jffs2_trusted_setxattr 4 17048 _001407_hash NULL
83932 +_001408_hash jffs2_user_setxattr 4 10182 _001408_hash NULL
83933 +_001409_hash kernel_setsockopt 5 35913 _001409_hash NULL
83934 +_001410_hash keyctl_describe_key 3 36853 _001410_hash NULL
83935 +_001411_hash keyctl_get_security 3 64418 _001411_hash &_001132_hash
83936 +_001412_hash keyring_read 3 13438 _001412_hash NULL
83937 +_001413_hash kfifo_copy_to_user 3 20646 _001413_hash NULL
83938 +_001414_hash kmem_zalloc_large 1 56128 _001414_hash NULL
83939 +_001415_hash kmp_init 2 41373 _001415_hash NULL
83940 +_001416_hash koneplus_sysfs_write 6 35993 _001416_hash NULL
83941 +_001417_hash kvm_clear_guest_page 4 2308 _001417_hash NULL
83942 +_001418_hash kvm_read_nested_guest_page 5 13337 _001418_hash NULL
83943 +_001419_hash l2cap_create_basic_pdu 3 24869 _001419_hash &_001034_hash
83944 +_001420_hash l2cap_create_connless_pdu 3 37327 _001420_hash &_000966_hash
83945 +_001421_hash l2cap_create_iframe_pdu 3 51801 _001421_hash NULL
83946 +_001422_hash __lgwrite 4 57669 _001422_hash NULL
83947 +_001423_hash libfc_host_alloc 2 7917 _001423_hash NULL
83948 +_001424_hash llcp_sock_sendmsg 4 1092 _001424_hash NULL
83949 +_001425_hash macvtap_get_user 4 28185 _001425_hash NULL
83950 +_001426_hash mcam_v4l_read 3 36513 _001426_hash NULL
83951 +_001427_hash mce_async_out 3 58056 _001427_hash NULL
83952 +_001428_hash mce_flush_rx_buffer 2 14976 _001428_hash NULL
83953 +_001429_hash mdc800_device_read 3 22896 _001429_hash NULL
83954 +_001430_hash memcpy_toiovec 3 54166 _001430_hash &_000867_hash
83955 +_001431_hash memcpy_toiovecend 3-4 19736 _001431_hash NULL
83956 +_001433_hash mgt_set_varlen 4 60916 _001433_hash NULL
83957 +_001434_hash mlx4_en_create_rx_ring 3 62498 _001434_hash NULL
83958 +_001435_hash mlx4_en_create_tx_ring 4 48501 _001435_hash NULL
83959 +_001436_hash mon_bin_get_event 4 52863 _001436_hash NULL
83960 +_001437_hash mousedev_read 3 47123 _001437_hash NULL
83961 +_001438_hash move_addr_to_user 2 2868 _001438_hash NULL
83962 +_001439_hash mpihelp_mul 5-3 27805 _001439_hash NULL
83963 +_001441_hash mpi_lshift_limbs 2 9337 _001441_hash NULL
83964 +_001442_hash msnd_fifo_alloc 2 23179 _001442_hash NULL
83965 +_001443_hash mtdswap_init 2 55719 _001443_hash NULL
83966 +_001444_hash neigh_hash_grow 2 17283 _001444_hash NULL
83967 +_001445_hash nfs4_realloc_slot_table 2 22859 _001445_hash NULL
83968 +_001446_hash nfs_idmap_get_key 2 39616 _001446_hash NULL
83969 +_001447_hash nsm_get_handle 4 52089 _001447_hash NULL
83970 +_001448_hash ntfs_malloc_nofs 1 49572 _001448_hash NULL
83971 +_001449_hash ntfs_malloc_nofs_nofail 1 63631 _001449_hash NULL
83972 +_001450_hash nvme_create_queue 3 170 _001450_hash NULL
83973 +_001451_hash ocfs2_control_write 3 54737 _001451_hash NULL
83974 +_001452_hash orinoco_add_extscan_result 3 18207 _001452_hash NULL
83975 +_001454_hash override_release 2 52032 _001454_hash NULL
83976 +_001455_hash packet_snd 3 13634 _001455_hash NULL
83977 +_001456_hash pcbit_stat 2 27364 _001456_hash NULL
83978 +_001457_hash pcpu_extend_area_map 2 12589 _001457_hash NULL
83979 +_001458_hash pg_read 3 17276 _001458_hash NULL
83980 +_001459_hash picolcd_debug_eeprom_read 3 14549 _001459_hash NULL
83981 +_001460_hash pkt_alloc_packet_data 1 37928 _001460_hash NULL
83982 +_001461_hash pmcraid_build_passthrough_ioadls 2 62034 _001461_hash NULL
83983 +_001462_hash pms_capture 4 27142 _001462_hash NULL
83984 +_001463_hash posix_clock_register 2 5662 _001463_hash NULL
83985 +_001464_hash printer_read 3 54851 _001464_hash NULL
83986 +_001465_hash __proc_file_read 3 54978 _001465_hash NULL
83987 +_001466_hash pt_read 3 49136 _001466_hash NULL
83988 +_001467_hash put_cmsg 4 36589 _001467_hash NULL
83989 +_001468_hash pvr2_ioread_read 3 10720 _001505_hash NULL nohasharray
83990 +_001469_hash pwc_video_read 3 51735 _001469_hash NULL
83991 +_001470_hash px_raw_event 4 49371 _001470_hash NULL
83992 +_001471_hash qcam_read 3 13977 _001471_hash NULL
83993 +_001472_hash rawv6_sendmsg 4 20080 _001472_hash NULL
83994 +_001473_hash rds_sendmsg 4 40976 _001473_hash NULL
83995 +_001474_hash read_flush 3 43851 _001474_hash NULL
83996 +_001475_hash read_profile 3 27859 _001475_hash NULL
83997 +_001476_hash read_vmcore 3 26501 _001476_hash NULL
83998 +_001477_hash redirected_tty_write 3 65297 _001477_hash NULL
83999 +_001478_hash __register_chrdev 2-3 54223 _001478_hash NULL
84000 +_001480_hash regmap_raw_write 4 53803 _001480_hash NULL
84001 +_001481_hash reiserfs_allocate_list_bitmaps 3 21732 _001481_hash NULL
84002 +_001482_hash reiserfs_resize 2 34377 _001482_hash NULL
84003 +_001483_hash request_key_auth_read 3 24109 _001483_hash NULL
84004 +_001484_hash rfkill_fop_read 3 54711 _001484_hash NULL
84005 +_001485_hash rng_dev_read 3 41581 _001485_hash NULL
84006 +_001486_hash roccat_read 3 41093 _001486_hash NULL
84007 +_001487_hash sco_sock_sendmsg 4 62542 _001487_hash NULL
84008 +_001488_hash scsi_register 2 49094 _001488_hash NULL
84009 +_001489_hash sctp_getsockopt_events 2 3607 _001489_hash NULL
84010 +_001490_hash sctp_getsockopt_maxburst 2 42941 _001490_hash NULL
84011 +_001491_hash sctp_getsockopt_maxseg 2 10737 _001491_hash NULL
84012 +_001492_hash sctpprobe_read 3 17741 _001492_hash NULL
84013 +_001493_hash sdhci_alloc_host 2 7509 _001493_hash NULL
84014 +_001494_hash selinux_inode_post_setxattr 4 26037 _001494_hash NULL
84015 +_001495_hash selinux_inode_setsecurity 4 18148 _001495_hash NULL
84016 +_001496_hash selinux_inode_setxattr 4 10708 _001496_hash NULL
84017 +_001497_hash selinux_secctx_to_secid 2 63744 _001497_hash NULL
84018 +_001498_hash selinux_setprocattr 4 55611 _001498_hash NULL
84019 +_001499_hash sel_write_context 3 25726 _002397_hash NULL nohasharray
84020 +_001500_hash seq_copy_in_user 3 18543 _001500_hash NULL
84021 +_001501_hash seq_open_net 4 8968 _001594_hash NULL nohasharray
84022 +_001502_hash seq_open_private 3 61589 _001502_hash NULL
84023 +_001503_hash set_arg 3 42824 _001503_hash NULL
84024 +_001504_hash sg_read 3 25799 _001504_hash NULL
84025 +_001505_hash shash_async_setkey 3 10720 _001505_hash &_001468_hash
84026 +_001506_hash shash_compat_setkey 3 12267 _001506_hash NULL
84027 +_001507_hash shmem_setxattr 4 55867 _001507_hash NULL
84028 +_001508_hash simple_read_from_buffer 2-5 55957 _001508_hash NULL
84029 +_001511_hash sm_checker_extend 2 23615 _001511_hash NULL
84030 +_001512_hash sn9c102_read 3 29305 _001512_hash NULL
84031 +_001513_hash snd_es1938_capture_copy 5 25930 _001513_hash NULL
84032 +_001514_hash snd_gus_dram_peek 4 9062 _001514_hash NULL
84033 +_001515_hash snd_hdsp_capture_copy 5 4011 _001515_hash NULL
84034 +_001516_hash snd_korg1212_copy_to 6 92 _001516_hash NULL
84035 +_001517_hash snd_opl4_mem_proc_read 5 63774 _001517_hash NULL
84036 +_001518_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _001518_hash NULL
84037 +_001519_hash snd_pcm_oss_read1 3 63771 _001519_hash NULL
84038 +_001520_hash snd_rawmidi_kernel_read1 4 36740 _001520_hash NULL
84039 +_001521_hash snd_rme9652_capture_copy 5 10287 _001521_hash NULL
84040 +_001522_hash srp_target_alloc 3 37288 _001522_hash NULL
84041 +_001523_hash stk_allocate_buffers 2 16291 _001523_hash NULL
84042 +_001524_hash store_ifalias 4 35088 _001524_hash NULL
84043 +_001525_hash store_msg 3 56417 _001525_hash NULL
84044 +_001526_hash str_to_user 2 11411 _001526_hash NULL
84045 +_001527_hash subbuf_read_actor 3 2071 _001527_hash NULL
84046 +_001528_hash sys_fgetxattr 4 25166 _001528_hash NULL
84047 +_001529_hash sys_gethostname 2 49698 _001529_hash NULL
84048 +_001530_hash sys_getxattr 4 37418 _001530_hash NULL
84049 +_001531_hash sys_kexec_load 2 14222 _001531_hash NULL
84050 +_001532_hash sys_msgsnd 3 44537 _001532_hash &_000129_hash
84051 +_001533_hash sys_process_vm_readv 3-5 19090 _003125_hash NULL nohasharray
84052 +_001535_hash sys_process_vm_writev 3-5 4928 _001535_hash NULL
84053 +_001537_hash sys_sched_getaffinity 2 60033 _001537_hash NULL
84054 +_001538_hash sys_setsockopt 5 35320 _001538_hash NULL
84055 +_001539_hash t3_init_l2t 1 8261 _001539_hash NULL
84056 +_001540_hash team_options_register 3 20091 _001540_hash NULL
84057 +_001541_hash tipc_send2name 6 16809 _001541_hash NULL
84058 +_001542_hash tipc_send2port 5 63935 _001542_hash NULL
84059 +_001543_hash tipc_send 4 51238 _001543_hash NULL
84060 +_001544_hash tm6000_i2c_recv_regs16 5 2949 _001544_hash NULL
84061 +_001545_hash tm6000_i2c_recv_regs 5 46215 _001545_hash NULL
84062 +_001546_hash tm6000_i2c_send_regs 5 20250 _001546_hash NULL
84063 +_001547_hash tnode_new 3 44757 _001547_hash NULL
84064 +_001548_hash tomoyo_read_self 3 33539 _001548_hash NULL
84065 +_001549_hash tomoyo_update_domain 2 5498 _001549_hash NULL
84066 +_001550_hash tomoyo_update_policy 2 40458 _001550_hash NULL
84067 +_001551_hash tpm_read 3 50344 _001551_hash NULL
84068 +_001552_hash TSS_rawhmac 3 17486 _001552_hash NULL
84069 +_001553_hash tt3650_ci_msg 4 57219 _001553_hash NULL
84070 +_001554_hash tun_get_user 3 33178 _001554_hash NULL
84071 +_001555_hash ubi_dbg_dump_flash 4 3870 _001555_hash NULL
84072 +_001556_hash ubi_io_write 4-5 15870 _001556_hash &_000954_hash
84073 +_001558_hash uio_read 3 49300 _001558_hash NULL
84074 +_001559_hash unix_seqpacket_sendmsg 4 27893 _001559_hash NULL
84075 +_001560_hash unlink1 3 63059 _001560_hash NULL
84076 +_001562_hash usb_allocate_stream_buffers 3 8964 _001562_hash NULL
84077 +_001563_hash usbdev_read 3 45114 _001563_hash NULL
84078 +_001564_hash usblp_read 3 57342 _001564_hash NULL
84079 +_001565_hash usbtmc_read 3 32377 _001565_hash NULL
84080 +_001566_hash usbvision_v4l2_read 3 34386 _001566_hash NULL
84081 +_001567_hash _usb_writeN_sync 4 31682 _001567_hash NULL
84082 +_001568_hash user_read 3 51881 _001568_hash NULL
84083 +_001569_hash v4l_stk_read 3 39672 _001569_hash NULL
84084 +_001570_hash vcs_read 3 8017 _001570_hash NULL
84085 +_001571_hash vdma_mem_alloc 1 6171 _001571_hash NULL
84086 +_001572_hash venus_create 4 20555 _001572_hash NULL
84087 +_001573_hash venus_link 5 32165 _001573_hash NULL
84088 +_001574_hash venus_lookup 4 8121 _001574_hash NULL
84089 +_001575_hash venus_mkdir 4 8967 _001575_hash NULL
84090 +_001576_hash venus_remove 4 59781 _001576_hash NULL
84091 +_001577_hash venus_rename 4-5 17707 _001577_hash NULL
84092 +_001579_hash venus_rmdir 4 45564 _001579_hash NULL
84093 +_001580_hash venus_symlink 4-6 23570 _001580_hash NULL
84094 +_001582_hash vfs_readlink 3 54368 _001582_hash NULL
84095 +_001583_hash vfs_readv 3 38011 _001583_hash NULL
84096 +_001584_hash vfs_writev 3 25278 _001584_hash NULL
84097 +_001585_hash vga_arb_read 3 4886 _001585_hash NULL
84098 +_001586_hash vhci_put_user 4 12604 _001586_hash NULL
84099 +_001587_hash vhost_add_used_n 3 10760 _001587_hash NULL
84100 +_001588_hash __videobuf_copy_to_user 4 15423 _001588_hash NULL
84101 +_001589_hash videobuf_pages_to_sg 2 3708 _001589_hash NULL
84102 +_001590_hash videobuf_vmalloc_to_sg 2 4548 _001590_hash NULL
84103 +_001591_hash virtnet_send_command 5-6 61993 _001591_hash NULL
84104 +_001593_hash vmbus_establish_gpadl 3 4495 _001593_hash NULL
84105 +_001594_hash vol_cdev_read 3 8968 _001594_hash &_001501_hash
84106 +_001595_hash w9966_v4l_read 3 31148 _001595_hash NULL
84107 +_001596_hash wdm_read 3 6549 _001596_hash NULL
84108 +_001597_hash wusb_prf 7 54261 _001597_hash &_000063_hash
84109 +_001598_hash xdi_copy_to_user 4 48900 _001598_hash NULL
84110 +_001599_hash xfs_buf_get_uncached 2 51477 _001599_hash NULL
84111 +_001600_hash xfs_efd_init 3 5463 _001600_hash NULL
84112 +_001601_hash xfs_efi_init 2 5476 _001601_hash NULL
84113 +_001602_hash xfs_iext_realloc_direct 2 20521 _001602_hash NULL
84114 +_001603_hash xfs_iext_realloc_indirect 2 59211 _001603_hash NULL
84115 +_001604_hash xfs_inumbers_fmt 3 12817 _001604_hash NULL
84116 +_001605_hash xlog_recover_add_to_cont_trans 4 44102 _001605_hash NULL
84117 +_001606_hash xz_dec_lzma2_create 2 36353 _002745_hash NULL nohasharray
84118 +_001607_hash _zd_iowrite32v_locked 3 44725 _001607_hash NULL
84119 +_001608_hash aat2870_reg_read_file 3 12221 _001608_hash NULL
84120 +_001609_hash add_sctp_bind_addr 3 12269 _001609_hash NULL
84121 +_001610_hash aes_decrypt_fail_read 3 54815 _001610_hash NULL
84122 +_001611_hash aes_decrypt_interrupt_read 3 19910 _001611_hash NULL
84123 +_001612_hash aes_decrypt_packets_read 3 10155 _001612_hash NULL
84124 +_001613_hash aes_encrypt_fail_read 3 32562 _001613_hash NULL
84125 +_001614_hash aes_encrypt_interrupt_read 3 39919 _001614_hash NULL
84126 +_001615_hash aes_encrypt_packets_read 3 48666 _001615_hash NULL
84127 +_001616_hash afs_cell_lookup 2 8482 _001616_hash NULL
84128 +_001617_hash agp_allocate_memory 2 58761 _001617_hash NULL
84129 +_001618_hash __alloc_bootmem 1 31498 _001618_hash NULL
84130 +_001619_hash __alloc_bootmem_low 1 43423 _003150_hash NULL nohasharray
84131 +_001620_hash __alloc_bootmem_node_nopanic 2 6432 _001620_hash NULL
84132 +_001621_hash alloc_cc770dev 1 48186 _001621_hash NULL
84133 +_001622_hash __alloc_ei_netdev 1 29338 _001622_hash NULL
84134 +_001623_hash __alloc_eip_netdev 1 51549 _001623_hash NULL
84135 +_001624_hash alloc_libipw 1 22708 _001624_hash NULL
84136 +_001625_hash alloc_pg_vec 2 8533 _001625_hash NULL
84137 +_001626_hash alloc_sja1000dev 1 17868 _001626_hash NULL
84138 +_001627_hash alloc_targets 2 8074 _001627_hash NULL
84139 +_001630_hash ath6kl_disconnect_timeout_read 3 3650 _001630_hash NULL
84140 +_001631_hash ath6kl_endpoint_stats_read 3 41554 _001631_hash NULL
84141 +_001632_hash ath6kl_fwlog_mask_read 3 2050 _001632_hash NULL
84142 +_001633_hash ath6kl_keepalive_read 3 44303 _001633_hash NULL
84143 +_001634_hash ath6kl_listen_int_read 3 10355 _001634_hash NULL
84144 +_001635_hash ath6kl_lrssi_roam_read 3 61022 _001635_hash NULL
84145 +_001636_hash ath6kl_regdump_read 3 14393 _001636_hash NULL
84146 +_001637_hash ath6kl_regread_read 3 25884 _001637_hash NULL
84147 +_001638_hash ath6kl_regwrite_read 3 48747 _001638_hash NULL
84148 +_001639_hash ath6kl_roam_table_read 3 26166 _001639_hash NULL
84149 +_001640_hash ath9k_debugfs_read_buf 3 25316 _001640_hash NULL
84150 +_001641_hash atk_debugfs_ggrp_read 3 29522 _001641_hash NULL
84151 +_001642_hash b43_debugfs_read 3 24425 _001642_hash NULL
84152 +_001643_hash b43legacy_debugfs_read 3 2473 _001643_hash NULL
84153 +_001644_hash bcm_recvmsg 4 43992 _001644_hash NULL
84154 +_001645_hash bfad_debugfs_read 3 13119 _001645_hash NULL
84155 +_001646_hash bfad_debugfs_read_regrd 3 57830 _001646_hash NULL
84156 +_001647_hash blk_init_tags 1 30592 _001647_hash NULL
84157 +_001648_hash blk_queue_init_tags 2 44355 _002686_hash NULL nohasharray
84158 +_001649_hash blk_rq_map_kern 4 47004 _001649_hash NULL
84159 +_001650_hash bm_entry_read 3 10976 _001650_hash NULL
84160 +_001651_hash bm_status_read 3 19583 _001651_hash NULL
84161 +_001652_hash bnad_debugfs_read 3 50665 _001652_hash NULL
84162 +_001653_hash bnad_debugfs_read_regrd 3 51308 _001653_hash NULL
84163 +_001654_hash btmrvl_curpsmode_read 3 46939 _001654_hash NULL
84164 +_001655_hash btmrvl_gpiogap_read 3 4718 _001655_hash NULL
84165 +_001656_hash btmrvl_hscfgcmd_read 3 56303 _001656_hash NULL
84166 +_001657_hash btmrvl_hscmd_read 3 1614 _001657_hash NULL
84167 +_001658_hash btmrvl_hsmode_read 3 1647 _001658_hash NULL
84168 +_001659_hash btmrvl_hsstate_read 3 920 _001659_hash NULL
84169 +_001660_hash btmrvl_pscmd_read 3 24308 _001660_hash NULL
84170 +_001661_hash btmrvl_psmode_read 3 22395 _001661_hash NULL
84171 +_001662_hash btmrvl_psstate_read 3 50683 _001662_hash NULL
84172 +_001663_hash btmrvl_txdnldready_read 3 413 _001663_hash NULL
84173 +_001664_hash btrfs_add_link 5 9973 _001664_hash NULL
84174 +_001665_hash btrfs_discard_extent 2 38547 _001665_hash NULL
84175 +_001666_hash btrfs_find_create_tree_block 3 55812 _001666_hash NULL
84176 +_001667_hash btrfsic_map_block 2 56751 _001667_hash NULL
84177 +_001668_hash caif_stream_recvmsg 4 13173 _001668_hash NULL
84178 +_001669_hash carl9170_alloc 1 27 _001669_hash NULL
84179 +_001670_hash carl9170_debugfs_read 3 47738 _001670_hash NULL
84180 +_001671_hash cgroup_read_s64 5 19570 _001671_hash NULL
84181 +_001672_hash cgroup_read_u64 5 45532 _001672_hash NULL
84182 +_001673_hash channel_type_read 3 47308 _001673_hash NULL
84183 +_001674_hash codec_list_read_file 3 24910 _001674_hash NULL
84184 +_001675_hash configfs_read_file 3 1683 _001675_hash NULL
84185 +_001676_hash cpuset_common_file_read 5 8800 _001676_hash NULL
84186 +_001677_hash create_subvol 4 2347 _001677_hash NULL
84187 +_001678_hash cx18_copy_mdl_to_user 4 45549 _001678_hash NULL
84188 +_001679_hash dai_list_read_file 3 25421 _001679_hash NULL
84189 +_001680_hash dapm_bias_read_file 3 64715 _001680_hash NULL
84190 +_001681_hash dapm_widget_power_read_file 3 59950 _001754_hash NULL nohasharray
84191 +_001684_hash dbgfs_frame 3 45917 _001684_hash NULL
84192 +_001685_hash dbgfs_state 3 38894 _001685_hash NULL
84193 +_001686_hash debugfs_read 3 62535 _001686_hash NULL
84194 +_001687_hash debug_output 3 18575 _001687_hash NULL
84195 +_001688_hash debug_read 3 19322 _001688_hash NULL
84196 +_001689_hash dfs_file_read 3 18116 _001689_hash NULL
84197 +_001690_hash dma_memcpy_pg_to_iovec 6 1725 _001690_hash NULL
84198 +_001691_hash dma_memcpy_to_iovec 5 12173 _001691_hash NULL
84199 +_001692_hash dma_rx_errors_read 3 52045 _001692_hash NULL
84200 +_001693_hash dma_rx_requested_read 3 65354 _001693_hash NULL
84201 +_001694_hash dma_show_regs 3 35266 _001694_hash NULL
84202 +_001695_hash dma_tx_errors_read 3 46060 _001695_hash NULL
84203 +_001696_hash dma_tx_requested_read 3 16110 _001775_hash NULL nohasharray
84204 +_001697_hash dm_exception_table_init 2 39645 _001697_hash &_001103_hash
84205 +_001698_hash dn_recvmsg 4 17213 _001698_hash NULL
84206 +_001699_hash dns_resolver_read 3 54658 _001699_hash NULL
84207 +_001700_hash do_msgrcv 4 5590 _001700_hash NULL
84208 +_001701_hash driver_state_read 3 17194 _001701_hash &_001394_hash
84209 +_001702_hash dvb_demux_do_ioctl 3 34871 _001702_hash NULL
84210 +_001703_hash dvb_dmxdev_buffer_read 4 20682 _001703_hash NULL
84211 +_001704_hash dvb_dvr_do_ioctl 3 43355 _001704_hash NULL
84212 +_001705_hash econet_recvmsg 4 40978 _001705_hash NULL
84213 +_001706_hash event_calibration_read 3 21083 _001706_hash NULL
84214 +_001707_hash event_heart_beat_read 3 48961 _001707_hash NULL
84215 +_001708_hash event_oom_late_read 3 61175 _001708_hash &_001014_hash
84216 +_001709_hash event_phy_transmit_error_read 3 10471 _001709_hash NULL
84217 +_001710_hash event_rx_mem_empty_read 3 40363 _001710_hash NULL
84218 +_001711_hash event_rx_mismatch_read 3 38518 _001711_hash NULL
84219 +_001712_hash event_rx_pool_read 3 25792 _001712_hash NULL
84220 +_001713_hash event_tx_stuck_read 3 19305 _001713_hash NULL
84221 +_001714_hash excessive_retries_read 3 60425 _001714_hash NULL
84222 +_001715_hash fallback_on_nodma_alloc 2 35332 _001715_hash NULL
84223 +_001716_hash filter_read 3 61692 _001716_hash NULL
84224 +_001717_hash format_devstat_counter 3 32550 _001717_hash NULL
84225 +_001718_hash fragmentation_threshold_read 3 61718 _001718_hash NULL
84226 +_001719_hash fuse_conn_limit_read 3 20084 _001719_hash NULL
84227 +_001720_hash fuse_conn_waiting_read 3 49762 _001720_hash NULL
84228 +_001721_hash generic_readlink 3 32654 _001721_hash NULL
84229 +_001722_hash gpio_power_read 3 36059 _001722_hash NULL
84230 +_001723_hash hash_recvmsg 4 50924 _001723_hash NULL
84231 +_001724_hash ht40allow_map_read 3 55209 _002830_hash NULL nohasharray
84232 +_001725_hash hwflags_read 3 52318 _001725_hash NULL
84233 +_001726_hash hysdn_conf_read 3 42324 _003205_hash NULL nohasharray
84234 +_001727_hash i2400m_rx_stats_read 3 57706 _001727_hash NULL
84235 +_001728_hash i2400m_tx_stats_read 3 28527 _001728_hash NULL
84236 +_001729_hash idmouse_read 3 63374 _001729_hash NULL
84237 +_001730_hash ieee80211_if_read 3 6785 _001730_hash NULL
84238 +_001731_hash ieee80211_rx_bss_info 3 61630 _001731_hash NULL
84239 +_001732_hash ikconfig_read_current 3 1658 _001732_hash NULL
84240 +_001733_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001733_hash NULL
84241 +_001734_hash il3945_ucode_general_stats_read 3 46111 _001734_hash NULL
84242 +_001735_hash il3945_ucode_rx_stats_read 3 3048 _001735_hash NULL
84243 +_001736_hash il3945_ucode_tx_stats_read 3 36016 _001736_hash NULL
84244 +_001737_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001737_hash NULL
84245 +_001738_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001738_hash NULL
84246 +_001739_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001739_hash NULL
84247 +_001740_hash il4965_ucode_general_stats_read 3 56277 _001740_hash NULL
84248 +_001741_hash il4965_ucode_rx_stats_read 3 61948 _001741_hash NULL
84249 +_001742_hash il4965_ucode_tx_stats_read 3 12064 _001742_hash NULL
84250 +_001743_hash il_dbgfs_chain_noise_read 3 38044 _001743_hash NULL
84251 +_001744_hash il_dbgfs_channels_read 3 25005 _001744_hash NULL
84252 +_001745_hash il_dbgfs_disable_ht40_read 3 42386 _001745_hash NULL
84253 +_001746_hash il_dbgfs_fh_reg_read 3 40993 _001746_hash NULL
84254 +_001747_hash il_dbgfs_force_reset_read 3 57517 _001747_hash NULL
84255 +_001748_hash il_dbgfs_interrupt_read 3 3351 _001748_hash NULL
84256 +_001749_hash il_dbgfs_missed_beacon_read 3 59956 _001749_hash NULL
84257 +_001750_hash il_dbgfs_nvm_read 3 12288 _001750_hash NULL
84258 +_001751_hash il_dbgfs_power_save_status_read 3 43165 _001751_hash NULL
84259 +_001752_hash il_dbgfs_qos_read 3 33615 _001752_hash NULL
84260 +_001753_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001753_hash NULL
84261 +_001754_hash il_dbgfs_rxon_flags_read 3 59950 _001754_hash &_001681_hash
84262 +_001755_hash il_dbgfs_rx_queue_read 3 11221 _001755_hash NULL
84263 +_001756_hash il_dbgfs_rx_stats_read 3 15243 _001756_hash NULL
84264 +_001757_hash il_dbgfs_sensitivity_read 3 2370 _001757_hash NULL
84265 +_001758_hash il_dbgfs_sram_read 3 62296 _001758_hash NULL
84266 +_001759_hash il_dbgfs_stations_read 3 21532 _001759_hash NULL
84267 +_001760_hash il_dbgfs_status_read 3 58388 _001760_hash NULL
84268 +_001761_hash il_dbgfs_tx_queue_read 3 55668 _001761_hash NULL
84269 +_001762_hash il_dbgfs_tx_stats_read 3 32913 _001762_hash NULL
84270 +_001763_hash ima_show_htable_value 2 57136 _001763_hash NULL
84271 +_001765_hash ipw_write 3 59807 _001765_hash NULL
84272 +_001766_hash irda_recvmsg_stream 4 35280 _001766_hash NULL
84273 +_001767_hash iscsi_tcp_conn_setup 2 16376 _001767_hash NULL
84274 +_001768_hash isr_cmd_cmplt_read 3 53439 _001768_hash NULL
84275 +_001769_hash isr_commands_read 3 41398 _001769_hash NULL
84276 +_001770_hash isr_decrypt_done_read 3 49490 _001770_hash NULL
84277 +_001771_hash isr_dma0_done_read 3 8574 _001771_hash NULL
84278 +_001772_hash isr_dma1_done_read 3 48159 _001772_hash NULL
84279 +_001773_hash isr_fiqs_read 3 34687 _001773_hash NULL
84280 +_001774_hash isr_host_acknowledges_read 3 54136 _001774_hash NULL
84281 +_001775_hash isr_hw_pm_mode_changes_read 3 16110 _001775_hash &_001696_hash
84282 +_001776_hash isr_irqs_read 3 9181 _001776_hash NULL
84283 +_001777_hash isr_low_rssi_read 3 64789 _001777_hash NULL
84284 +_001778_hash isr_pci_pm_read 3 30271 _001778_hash NULL
84285 +_001779_hash isr_rx_headers_read 3 38325 _001779_hash NULL
84286 +_001780_hash isr_rx_mem_overflow_read 3 43025 _001780_hash NULL
84287 +_001781_hash isr_rx_procs_read 3 31804 _001781_hash NULL
84288 +_001782_hash isr_rx_rdys_read 3 35283 _001782_hash NULL
84289 +_001783_hash isr_tx_exch_complete_read 3 16103 _001783_hash NULL
84290 +_001784_hash isr_tx_procs_read 3 23084 _001784_hash NULL
84291 +_001785_hash isr_wakeups_read 3 49607 _001785_hash NULL
84292 +_001786_hash ivtv_read 3 57796 _001786_hash NULL
84293 +_001787_hash iwl_dbgfs_bt_traffic_read 3 35534 _001787_hash NULL
84294 +_001788_hash iwl_dbgfs_chain_noise_read 3 46355 _001788_hash NULL
84295 +_001789_hash iwl_dbgfs_channels_read 3 6784 _001789_hash NULL
84296 +_001790_hash iwl_dbgfs_current_sleep_command_read 3 2081 _001790_hash NULL
84297 +_001791_hash iwl_dbgfs_disable_ht40_read 3 35761 _001791_hash NULL
84298 +_001792_hash iwl_dbgfs_fh_reg_read 3 879 _001792_hash &_000393_hash
84299 +_001793_hash iwl_dbgfs_force_reset_read 3 62628 _001793_hash NULL
84300 +_001794_hash iwl_dbgfs_interrupt_read 3 23574 _001794_hash NULL
84301 +_001795_hash iwl_dbgfs_log_event_read 3 2107 _001795_hash NULL
84302 +_001796_hash iwl_dbgfs_missed_beacon_read 3 50584 _001796_hash NULL
84303 +_001797_hash iwl_dbgfs_nvm_read 3 23845 _001797_hash NULL
84304 +_001798_hash iwl_dbgfs_plcp_delta_read 3 55407 _001798_hash NULL
84305 +_001799_hash iwl_dbgfs_power_save_status_read 3 54392 _001799_hash NULL
84306 +_001800_hash iwl_dbgfs_protection_mode_read 3 13943 _001800_hash NULL
84307 +_001801_hash iwl_dbgfs_qos_read 3 11753 _001801_hash NULL
84308 +_001802_hash iwl_dbgfs_reply_tx_error_read 3 19205 _001802_hash NULL
84309 +_001803_hash iwl_dbgfs_rx_handlers_read 3 18708 _001803_hash NULL
84310 +_001804_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _001804_hash NULL
84311 +_001805_hash iwl_dbgfs_rxon_flags_read 3 20795 _001805_hash NULL
84312 +_001806_hash iwl_dbgfs_rx_queue_read 3 19943 _001806_hash NULL
84313 +_001807_hash iwl_dbgfs_rx_statistics_read 3 62687 _001807_hash &_000425_hash
84314 +_001808_hash iwl_dbgfs_sensitivity_read 3 63116 _003026_hash NULL nohasharray
84315 +_001809_hash iwl_dbgfs_sleep_level_override_read 3 3038 _001809_hash NULL
84316 +_001810_hash iwl_dbgfs_sram_read 3 44505 _001810_hash NULL
84317 +_001811_hash iwl_dbgfs_stations_read 3 9309 _001811_hash NULL
84318 +_001812_hash iwl_dbgfs_status_read 3 5171 _001812_hash NULL
84319 +_001813_hash iwl_dbgfs_temperature_read 3 29224 _001813_hash NULL
84320 +_001814_hash iwl_dbgfs_thermal_throttling_read 3 38779 _001814_hash NULL
84321 +_001815_hash iwl_dbgfs_traffic_log_read 3 58870 _001815_hash NULL
84322 +_001816_hash iwl_dbgfs_tx_queue_read 3 4635 _001816_hash NULL
84323 +_001817_hash iwl_dbgfs_tx_statistics_read 3 314 _001817_hash NULL
84324 +_001818_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _001818_hash NULL
84325 +_001819_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _001819_hash NULL
84326 +_001820_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _001820_hash NULL
84327 +_001821_hash iwl_dbgfs_ucode_tracing_read 3 47983 _001821_hash &_000349_hash
84328 +_001822_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _001822_hash NULL
84329 +_001823_hash iwl_dbgfs_wowlan_sram_read 3 540 _001823_hash NULL
84330 +_001824_hash iwm_if_alloc 1 17027 _001824_hash &_001314_hash
84331 +_001825_hash kernel_readv 3 35617 _001825_hash NULL
84332 +_001826_hash key_algorithm_read 3 57946 _001826_hash NULL
84333 +_001827_hash key_icverrors_read 3 20895 _001827_hash NULL
84334 +_001828_hash key_key_read 3 3241 _001828_hash NULL
84335 +_001829_hash key_replays_read 3 62746 _001829_hash NULL
84336 +_001830_hash key_rx_spec_read 3 12736 _001830_hash NULL
84337 +_001831_hash key_tx_spec_read 3 4862 _001831_hash NULL
84338 +_001832_hash __kfifo_to_user 3 36555 _002199_hash NULL nohasharray
84339 +_001833_hash __kfifo_to_user_r 3 39123 _001833_hash NULL
84340 +_001834_hash kmem_zalloc_greedy 2-3 65268 _001834_hash NULL
84341 +_001836_hash l2cap_chan_send 3 49995 _001836_hash NULL
84342 +_001837_hash l2cap_sar_segment_sdu 3 27701 _001837_hash NULL
84343 +_001838_hash lbs_debugfs_read 3 30721 _001838_hash NULL
84344 +_001839_hash lbs_dev_info 3 51023 _001839_hash NULL
84345 +_001840_hash lbs_host_sleep_read 3 31013 _001840_hash NULL
84346 +_001841_hash lbs_rdbbp_read 3 45805 _001841_hash NULL
84347 +_001842_hash lbs_rdmac_read 3 418 _001842_hash NULL
84348 +_001843_hash lbs_rdrf_read 3 41431 _001843_hash NULL
84349 +_001844_hash lbs_sleepparams_read 3 10840 _001844_hash NULL
84350 +_001845_hash lbs_threshold_read 5 21046 _001845_hash NULL
84351 +_001846_hash libfc_vport_create 2 4415 _001846_hash NULL
84352 +_001847_hash lkdtm_debugfs_read 3 45752 _001847_hash NULL
84353 +_001848_hash llcp_sock_recvmsg 4 13556 _001848_hash NULL
84354 +_001849_hash long_retry_limit_read 3 59766 _001849_hash NULL
84355 +_001850_hash lpfc_debugfs_dif_err_read 3 36303 _001850_hash NULL
84356 +_001851_hash lpfc_debugfs_read 3 16566 _001851_hash NULL
84357 +_001852_hash lpfc_idiag_baracc_read 3 58466 _002447_hash NULL nohasharray
84358 +_001853_hash lpfc_idiag_ctlacc_read 3 33943 _001853_hash NULL
84359 +_001854_hash lpfc_idiag_drbacc_read 3 15948 _001854_hash NULL
84360 +_001855_hash lpfc_idiag_extacc_read 3 48301 _001855_hash NULL
84361 +_001856_hash lpfc_idiag_mbxacc_read 3 28061 _001856_hash NULL
84362 +_001857_hash lpfc_idiag_pcicfg_read 3 50334 _001857_hash NULL
84363 +_001858_hash lpfc_idiag_queacc_read 3 13950 _001858_hash NULL
84364 +_001859_hash lpfc_idiag_queinfo_read 3 55662 _001859_hash NULL
84365 +_001860_hash mac80211_format_buffer 2 41010 _001860_hash NULL
84366 +_001861_hash macvtap_put_user 4 55609 _001861_hash NULL
84367 +_001862_hash macvtap_sendmsg 4 30629 _001862_hash NULL
84368 +_001863_hash mic_calc_failure_read 3 59700 _001863_hash NULL
84369 +_001864_hash mic_rx_pkts_read 3 27972 _001864_hash NULL
84370 +_001865_hash minstrel_stats_read 3 17290 _001865_hash NULL
84371 +_001866_hash mmc_ext_csd_read 3 13205 _001866_hash NULL
84372 +_001867_hash mon_bin_read 3 6841 _001867_hash NULL
84373 +_001868_hash mon_stat_read 3 25238 _001868_hash NULL
84374 +_001870_hash mqueue_read_file 3 6228 _001870_hash NULL
84375 +_001871_hash mwifiex_debug_read 3 53074 _001871_hash NULL
84376 +_001872_hash mwifiex_getlog_read 3 54269 _001872_hash NULL
84377 +_001873_hash mwifiex_info_read 3 53447 _001873_hash NULL
84378 +_001874_hash mwifiex_rdeeprom_read 3 51429 _001874_hash NULL
84379 +_001875_hash mwifiex_regrdwr_read 3 34472 _001875_hash NULL
84380 +_001876_hash nfsd_vfs_read 6 62605 _003003_hash NULL nohasharray
84381 +_001877_hash nfsd_vfs_write 6 54577 _001877_hash NULL
84382 +_001878_hash nfs_idmap_lookup_id 2 10660 _001878_hash NULL
84383 +_001879_hash o2hb_debug_read 3 37851 _001879_hash NULL
84384 +_001880_hash o2net_debug_read 3 52105 _001880_hash NULL
84385 +_001881_hash ocfs2_control_read 3 56405 _001881_hash NULL
84386 +_001882_hash ocfs2_debug_read 3 14507 _001882_hash NULL
84387 +_001883_hash ocfs2_readlink 3 50656 _001883_hash NULL
84388 +_001884_hash oom_adjust_read 3 25127 _001884_hash NULL
84389 +_001885_hash oom_score_adj_read 3 39921 _002116_hash NULL nohasharray
84390 +_001886_hash oprofilefs_str_to_user 3 42182 _001886_hash NULL
84391 +_001887_hash oprofilefs_ulong_to_user 3 11582 _001887_hash NULL
84392 +_001888_hash _osd_req_list_objects 6 4204 _001888_hash NULL
84393 +_001889_hash osd_req_read_kern 5 59990 _001889_hash NULL
84394 +_001890_hash osd_req_write_kern 5 53486 _001890_hash NULL
84395 +_001891_hash p54_init_common 1 23850 _001891_hash NULL
84396 +_001892_hash packet_sendmsg 4 24954 _001892_hash NULL
84397 +_001893_hash page_readlink 3 23346 _001893_hash NULL
84398 +_001894_hash pcf50633_write_block 3 2124 _001894_hash NULL
84399 +_001895_hash platform_list_read_file 3 34734 _001895_hash NULL
84400 +_001896_hash pm860x_bulk_write 3 43875 _001896_hash NULL
84401 +_001897_hash pm_qos_power_read 3 55891 _001897_hash NULL
84402 +_001898_hash pms_read 3 53873 _001898_hash NULL
84403 +_001899_hash port_show_regs 3 5904 _001899_hash NULL
84404 +_001900_hash proc_coredump_filter_read 3 39153 _001900_hash NULL
84405 +_001901_hash proc_fdinfo_read 3 62043 _001901_hash NULL
84406 +_001902_hash proc_info_read 3 63344 _001902_hash NULL
84407 +_001903_hash proc_loginuid_read 3 15631 _001903_hash NULL
84408 +_001904_hash proc_pid_attr_read 3 10173 _001904_hash NULL
84409 +_001905_hash proc_pid_readlink 3 52186 _001905_hash NULL
84410 +_001906_hash proc_read 3 43614 _001906_hash NULL
84411 +_001907_hash proc_self_readlink 3 38094 _001907_hash NULL
84412 +_001908_hash proc_sessionid_read 3 6911 _002038_hash NULL nohasharray
84413 +_001909_hash provide_user_output 3 41105 _001909_hash NULL
84414 +_001910_hash ps_pspoll_max_apturn_read 3 6699 _001910_hash NULL
84415 +_001911_hash ps_pspoll_timeouts_read 3 11776 _001911_hash NULL
84416 +_001912_hash ps_pspoll_utilization_read 3 5361 _001912_hash NULL
84417 +_001913_hash pstore_file_read 3 57288 _001913_hash NULL
84418 +_001914_hash ps_upsd_max_apturn_read 3 19918 _001914_hash NULL
84419 +_001915_hash ps_upsd_max_sptime_read 3 63362 _001915_hash NULL
84420 +_001916_hash ps_upsd_timeouts_read 3 28924 _001916_hash NULL
84421 +_001917_hash ps_upsd_utilization_read 3 51669 _001917_hash NULL
84422 +_001918_hash pvr2_v4l2_read 3 18006 _001918_hash NULL
84423 +_001919_hash pwr_disable_ps_read 3 13176 _001919_hash NULL
84424 +_001920_hash pwr_elp_enter_read 3 5324 _001920_hash NULL
84425 +_001921_hash pwr_enable_ps_read 3 17686 _001921_hash NULL
84426 +_001922_hash pwr_fix_tsf_ps_read 3 26627 _001922_hash NULL
84427 +_001923_hash pwr_missing_bcns_read 3 25824 _001923_hash NULL
84428 +_001924_hash pwr_power_save_off_read 3 18355 _001924_hash NULL
84429 +_001925_hash pwr_ps_enter_read 3 26935 _001925_hash &_000501_hash
84430 +_001926_hash pwr_rcvd_awake_beacons_read 3 50505 _001926_hash NULL
84431 +_001927_hash pwr_rcvd_beacons_read 3 52836 _001927_hash NULL
84432 +_001928_hash pwr_tx_without_ps_read 3 48423 _001928_hash NULL
84433 +_001929_hash pwr_tx_with_ps_read 3 60851 _001929_hash NULL
84434 +_001930_hash pwr_wake_on_host_read 3 26321 _001930_hash NULL
84435 +_001931_hash pwr_wake_on_timer_exp_read 3 22640 _001931_hash NULL
84436 +_001932_hash queues_read 3 24877 _001932_hash NULL
84437 +_001933_hash raw_recvmsg 4 17277 _001933_hash NULL
84438 +_001934_hash rcname_read 3 25919 _001934_hash NULL
84439 +_001935_hash read_4k_modal_eeprom 3 30212 _001935_hash NULL
84440 +_001936_hash read_9287_modal_eeprom 3 59327 _001936_hash NULL
84441 +_001937_hash reada_find_extent 2 63486 _001937_hash NULL
84442 +_001938_hash read_def_modal_eeprom 3 14041 _001938_hash NULL
84443 +_001939_hash read_enabled_file_bool 3 37744 _001939_hash NULL
84444 +_001940_hash read_file_ani 3 23161 _001940_hash NULL
84445 +_001941_hash read_file_antenna 3 13574 _001941_hash NULL
84446 +_001942_hash read_file_base_eeprom 3 42168 _001942_hash NULL
84447 +_001943_hash read_file_beacon 3 32595 _001943_hash NULL
84448 +_001944_hash read_file_blob 3 57406 _001944_hash NULL
84449 +_001945_hash read_file_bool 3 4180 _001945_hash NULL
84450 +_001946_hash read_file_credit_dist_stats 3 54367 _001946_hash NULL
84451 +_001947_hash read_file_debug 3 58256 _001947_hash NULL
84452 +_001948_hash read_file_disable_ani 3 6536 _001948_hash NULL
84453 +_001949_hash read_file_dma 3 9530 _001949_hash NULL
84454 +_001950_hash read_file_dump_nfcal 3 18766 _001950_hash NULL
84455 +_001951_hash read_file_frameerrors 3 64001 _001951_hash NULL
84456 +_001952_hash read_file_interrupt 3 61742 _001959_hash NULL nohasharray
84457 +_001953_hash read_file_misc 3 9948 _001953_hash NULL
84458 +_001954_hash read_file_modal_eeprom 3 39909 _001954_hash NULL
84459 +_001955_hash read_file_queue 3 40895 _001955_hash NULL
84460 +_001956_hash read_file_rcstat 3 22854 _001956_hash NULL
84461 +_001957_hash read_file_recv 3 48232 _001957_hash NULL
84462 +_001958_hash read_file_regidx 3 33370 _001958_hash NULL
84463 +_001959_hash read_file_regval 3 61742 _001959_hash &_001952_hash
84464 +_001960_hash read_file_reset 3 52310 _001960_hash NULL
84465 +_001961_hash read_file_rx_chainmask 3 41605 _001961_hash NULL
84466 +_001962_hash read_file_slot 3 50111 _001962_hash NULL
84467 +_001963_hash read_file_stations 3 35795 _001963_hash NULL
84468 +_001964_hash read_file_tgt_int_stats 3 20697 _001964_hash NULL
84469 +_001965_hash read_file_tgt_rx_stats 3 33944 _001965_hash NULL
84470 +_001966_hash read_file_tgt_stats 3 8959 _001966_hash NULL
84471 +_001967_hash read_file_tgt_tx_stats 3 51847 _001967_hash NULL
84472 +_001968_hash read_file_tx_chainmask 3 3829 _001968_hash NULL
84473 +_001969_hash read_file_war_stats 3 292 _001969_hash NULL
84474 +_001970_hash read_file_xmit 3 21487 _001970_hash NULL
84475 +_001971_hash read_from_oldmem 2 3337 _001971_hash NULL
84476 +_001972_hash read_oldmem 3 55658 _001972_hash NULL
84477 +_001973_hash regmap_name_read_file 3 39379 _001973_hash NULL
84478 +_001974_hash repair_io_failure 4 4815 _001974_hash NULL
84479 +_001975_hash request_key_and_link 4 42693 _001975_hash NULL
84480 +_001976_hash res_counter_read 4 33499 _001976_hash NULL
84481 +_001977_hash retry_count_read 3 52129 _001977_hash NULL
84482 +_001978_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _001978_hash NULL
84483 +_001979_hash rs_sta_dbgfs_scale_table_read 3 40262 _001979_hash NULL
84484 +_001980_hash rs_sta_dbgfs_stats_table_read 3 56573 _001980_hash NULL
84485 +_001981_hash rts_threshold_read 3 44384 _001981_hash NULL
84486 +_001982_hash rx_dropped_read 3 44799 _001982_hash NULL
84487 +_001983_hash rx_fcs_err_read 3 62844 _001983_hash NULL
84488 +_001984_hash rx_hdr_overflow_read 3 64407 _001984_hash NULL
84489 +_001985_hash rx_hw_stuck_read 3 57179 _001985_hash NULL
84490 +_001986_hash rx_out_of_mem_read 3 10157 _001986_hash NULL
84491 +_001987_hash rx_path_reset_read 3 23801 _001987_hash NULL
84492 +_001988_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _001988_hash NULL
84493 +_001989_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _003089_hash NULL nohasharray
84494 +_001990_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _001990_hash NULL
84495 +_001991_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _001991_hash NULL
84496 +_001992_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _001992_hash NULL
84497 +_001993_hash rx_reset_counter_read 3 58001 _001993_hash NULL
84498 +_001994_hash rx_xfr_hint_trig_read 3 40283 _001994_hash NULL
84499 +_001995_hash s5m_bulk_write 3 4833 _001995_hash NULL
84500 +_001996_hash scrub_setup_recheck_block 3-4 56245 _001996_hash NULL
84501 +_001998_hash scsi_adjust_queue_depth 3 12802 _001998_hash NULL
84502 +_001999_hash selinux_inode_notifysecctx 3 36896 _001999_hash NULL
84503 +_002000_hash sel_read_avc_cache_threshold 3 33942 _002000_hash NULL
84504 +_002001_hash sel_read_avc_hash_stats 3 1984 _002001_hash NULL
84505 +_002002_hash sel_read_bool 3 24236 _002002_hash NULL
84506 +_002003_hash sel_read_checkreqprot 3 33068 _002003_hash NULL
84507 +_002004_hash sel_read_class 3 12669 _002541_hash NULL nohasharray
84508 +_002005_hash sel_read_enforce 3 2828 _002005_hash NULL
84509 +_002006_hash sel_read_handle_status 3 56139 _002006_hash NULL
84510 +_002007_hash sel_read_handle_unknown 3 57933 _002007_hash NULL
84511 +_002008_hash sel_read_initcon 3 32362 _002008_hash NULL
84512 +_002009_hash sel_read_mls 3 25369 _002009_hash NULL
84513 +_002010_hash sel_read_perm 3 42302 _002010_hash NULL
84514 +_002011_hash sel_read_policy 3 55947 _002011_hash NULL
84515 +_002012_hash sel_read_policycap 3 28544 _002012_hash NULL
84516 +_002013_hash sel_read_policyvers 3 55 _002013_hash NULL
84517 +_002014_hash send_msg 4 37323 _002014_hash NULL
84518 +_002015_hash send_packet 4 52960 _002015_hash NULL
84519 +_002016_hash short_retry_limit_read 3 4687 _002016_hash NULL
84520 +_002017_hash simple_attr_read 3 24738 _002017_hash NULL
84521 +_002018_hash simple_transaction_read 3 17076 _002018_hash NULL
84522 +_002019_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002019_hash NULL
84523 +_002022_hash skb_copy_datagram_iovec 2-4 5806 _002022_hash NULL
84524 +_002024_hash smk_read_ambient 3 61220 _002024_hash NULL
84525 +_002025_hash smk_read_direct 3 15803 _002025_hash NULL
84526 +_002026_hash smk_read_doi 3 30813 _002026_hash NULL
84527 +_002027_hash smk_read_logging 3 37804 _002027_hash NULL
84528 +_002028_hash smk_read_onlycap 3 3855 _002028_hash NULL
84529 +_002029_hash snapshot_read 3 22601 _002029_hash NULL
84530 +_002030_hash snd_cs4281_BA0_read 5 6847 _002030_hash NULL
84531 +_002031_hash snd_cs4281_BA1_read 5 20323 _002031_hash NULL
84532 +_002032_hash snd_cs46xx_io_read 5 45734 _002032_hash NULL
84533 +_002033_hash snd_gus_dram_read 4 56686 _002033_hash NULL
84534 +_002034_hash snd_pcm_oss_read 3 28317 _002034_hash NULL
84535 +_002035_hash snd_rme32_capture_copy 5 39653 _002035_hash NULL
84536 +_002036_hash snd_rme96_capture_copy 5 58484 _002036_hash NULL
84537 +_002037_hash snd_soc_hw_bulk_write_raw 4 14245 _002037_hash NULL
84538 +_002038_hash spi_show_regs 3 6911 _002038_hash &_001908_hash
84539 +_002039_hash sta_agg_status_read 3 14058 _002039_hash NULL
84540 +_002040_hash sta_connected_time_read 3 17435 _002040_hash NULL
84541 +_002041_hash sta_flags_read 3 56710 _002041_hash NULL
84542 +_002042_hash sta_ht_capa_read 3 10366 _002042_hash NULL
84543 +_002043_hash sta_last_seq_ctrl_read 3 19106 _002043_hash NULL
84544 +_002044_hash sta_num_ps_buf_frames_read 3 1488 _002044_hash NULL
84545 +_002045_hash st_read 3 51251 _002045_hash NULL
84546 +_002046_hash supply_map_read_file 3 10608 _002046_hash NULL
84547 +_002047_hash sysfs_read_file 3 42113 _002047_hash NULL
84548 +_002048_hash sys_lgetxattr 4 45531 _002048_hash NULL
84549 +_002049_hash sys_preadv 3 17100 _002049_hash NULL
84550 +_002050_hash sys_pwritev 3 41722 _002050_hash NULL
84551 +_002051_hash sys_readv 3 50664 _002051_hash NULL
84552 +_002052_hash sys_rt_sigpending 2 24961 _002052_hash NULL
84553 +_002053_hash sys_writev 3 28384 _002053_hash NULL
84554 +_002054_hash test_iso_queue 5 62534 _002054_hash NULL
84555 +_002055_hash ts_read 3 44687 _002055_hash NULL
84556 +_002056_hash TSS_authhmac 3 12839 _002056_hash NULL
84557 +_002057_hash TSS_checkhmac1 5 31429 _002057_hash NULL
84558 +_002058_hash TSS_checkhmac2 5-7 40520 _002058_hash NULL
84559 +_002060_hash tt3650_ci_msg_locked 4 8013 _002060_hash NULL
84560 +_002061_hash tun_sendmsg 4 10337 _002061_hash NULL
84561 +_002062_hash tx_internal_desc_overflow_read 3 47300 _002062_hash NULL
84562 +_002063_hash tx_queue_len_read 3 1463 _002063_hash NULL
84563 +_002064_hash tx_queue_status_read 3 44978 _002064_hash NULL
84564 +_002065_hash ubi_io_write_data 4-5 40305 _002065_hash NULL
84565 +_002067_hash uhci_debug_read 3 5911 _002067_hash NULL
84566 +_002068_hash unix_stream_recvmsg 4 35210 _002068_hash NULL
84567 +_002069_hash uvc_debugfs_stats_read 3 56651 _002069_hash NULL
84568 +_002070_hash vhost_add_used_and_signal_n 4 8038 _002070_hash NULL
84569 +_002071_hash vifs_state_read 3 33762 _002071_hash NULL
84570 +_002072_hash vmbus_open 2-3 12154 _002072_hash NULL
84571 +_002074_hash waiters_read 3 40902 _002074_hash NULL
84572 +_002075_hash wep_addr_key_count_read 3 20174 _002075_hash NULL
84573 +_002076_hash wep_decrypt_fail_read 3 58567 _002076_hash NULL
84574 +_002077_hash wep_default_key_count_read 3 43035 _002077_hash NULL
84575 +_002078_hash wep_interrupt_read 3 41492 _002078_hash NULL
84576 +_002079_hash wep_key_not_found_read 3 13377 _002079_hash &_000915_hash
84577 +_002080_hash wep_packets_read 3 18751 _002080_hash NULL
84578 +_002081_hash wl1271_format_buffer 2 20834 _002081_hash NULL
84579 +_002082_hash wm8994_bulk_write 3 13615 _002082_hash NULL
84580 +_002083_hash wusb_prf_256 7 29203 _002083_hash NULL
84581 +_002084_hash wusb_prf_64 7 51065 _002084_hash NULL
84582 +_002085_hash xfs_buf_read_uncached 4 27519 _002085_hash NULL
84583 +_002086_hash xfs_iext_add 3 41422 _002086_hash NULL
84584 +_002087_hash xfs_iext_remove_direct 3 40744 _002087_hash NULL
84585 +_002088_hash xfs_trans_get_efd 3 51148 _002088_hash NULL
84586 +_002089_hash xfs_trans_get_efi 2 7898 _002089_hash NULL
84587 +_002090_hash xlog_get_bp 2 23229 _002090_hash NULL
84588 +_002091_hash xz_dec_init 2 29029 _002091_hash NULL
84589 +_002092_hash aac_change_queue_depth 2 825 _002092_hash NULL
84590 +_002093_hash agp_allocate_memory_wrap 1 16576 _002093_hash NULL
84591 +_002094_hash arcmsr_adjust_disk_queue_depth 2 16756 _002094_hash NULL
84592 +_002095_hash atalk_recvmsg 4 22053 _002095_hash NULL
84593 +_002097_hash atomic_read_file 3 16227 _002097_hash NULL
84594 +_002098_hash ax25_recvmsg 4 64441 _002098_hash NULL
84595 +_002099_hash beacon_interval_read 3 7091 _002099_hash NULL
84596 +_002100_hash btrfs_init_new_buffer 4 55761 _002100_hash NULL
84597 +_002101_hash btrfs_mksubvol 3 39479 _002101_hash NULL
84598 +_002102_hash bt_sock_recvmsg 4 12316 _002102_hash NULL
84599 +_002103_hash bt_sock_stream_recvmsg 4 52518 _002103_hash NULL
84600 +_002104_hash caif_seqpkt_recvmsg 4 32241 _002104_hash NULL
84601 +_002105_hash cpu_type_read 3 36540 _002105_hash NULL
84602 +_002106_hash cx18_read 3 23699 _002106_hash NULL
84603 +_002107_hash dccp_recvmsg 4 16056 _002107_hash NULL
84604 +_002108_hash depth_read 3 31112 _002108_hash NULL
84605 +_002109_hash dfs_global_file_read 3 7787 _002109_hash NULL
84606 +_002110_hash dgram_recvmsg 4 23104 _002110_hash NULL
84607 +_002111_hash dma_skb_copy_datagram_iovec 3-5 21516 _002111_hash NULL
84608 +_002113_hash dtim_interval_read 3 654 _002113_hash NULL
84609 +_002114_hash dynamic_ps_timeout_read 3 10110 _002114_hash NULL
84610 +_002115_hash enable_read 3 2117 _002115_hash NULL
84611 +_002116_hash exofs_read_kern 6 39921 _002116_hash &_001885_hash
84612 +_002117_hash fc_change_queue_depth 2 36841 _002117_hash NULL
84613 +_002118_hash forced_ps_read 3 31685 _002118_hash NULL
84614 +_002119_hash frequency_read 3 64031 _003106_hash NULL nohasharray
84615 +_002120_hash get_alua_req 3 4166 _002120_hash NULL
84616 +_002121_hash get_rdac_req 3 45882 _002121_hash NULL
84617 +_002122_hash hci_sock_recvmsg 4 7072 _002122_hash NULL
84618 +_002123_hash hpsa_change_queue_depth 2 15449 _002123_hash NULL
84619 +_002124_hash hptiop_adjust_disk_queue_depth 2 20122 _002124_hash NULL
84620 +_002125_hash ide_queue_pc_tail 5 11673 _002125_hash NULL
84621 +_002126_hash ide_raw_taskfile 4 42355 _002126_hash NULL
84622 +_002127_hash idetape_queue_rw_tail 3 29562 _002127_hash NULL
84623 +_002128_hash ieee80211_if_read_aid 3 9705 _002128_hash NULL
84624 +_002129_hash ieee80211_if_read_auto_open_plinks 3 38268 _002129_hash NULL
84625 +_002130_hash ieee80211_if_read_ave_beacon 3 64924 _002130_hash NULL
84626 +_002131_hash ieee80211_if_read_bssid 3 35161 _002131_hash NULL
84627 +_002132_hash ieee80211_if_read_channel_type 3 23884 _002132_hash NULL
84628 +_002133_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002133_hash NULL
84629 +_002134_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002134_hash NULL
84630 +_002135_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002135_hash NULL
84631 +_002136_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002136_hash NULL
84632 +_002137_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002137_hash NULL
84633 +_002138_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002138_hash NULL
84634 +_002139_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002139_hash NULL
84635 +_002140_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002140_hash NULL
84636 +_002141_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002141_hash NULL
84637 +_002142_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002142_hash NULL
84638 +_002143_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002143_hash NULL
84639 +_002144_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002144_hash NULL
84640 +_002145_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002145_hash NULL
84641 +_002146_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002146_hash NULL
84642 +_002147_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002147_hash NULL
84643 +_002148_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002148_hash NULL
84644 +_002149_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002149_hash NULL
84645 +_002150_hash ieee80211_if_read_drop_unencrypted 3 37053 _002150_hash NULL
84646 +_002151_hash ieee80211_if_read_dtim_count 3 38419 _002151_hash NULL
84647 +_002152_hash ieee80211_if_read_element_ttl 3 18869 _002152_hash NULL
84648 +_002153_hash ieee80211_if_read_estab_plinks 3 32533 _002153_hash NULL
84649 +_002154_hash ieee80211_if_read_flags 3 57470 _002389_hash NULL nohasharray
84650 +_002155_hash ieee80211_if_read_fwded_frames 3 36520 _002155_hash NULL
84651 +_002156_hash ieee80211_if_read_fwded_mcast 3 39571 _002156_hash &_000151_hash
84652 +_002157_hash ieee80211_if_read_fwded_unicast 3 59740 _002859_hash NULL nohasharray
84653 +_002158_hash ieee80211_if_read_last_beacon 3 31257 _002158_hash NULL
84654 +_002159_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002159_hash NULL
84655 +_002160_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002160_hash NULL
84656 +_002161_hash ieee80211_if_read_num_sta_authorized 3 56177 _002161_hash NULL
84657 +_002162_hash ieee80211_if_read_num_sta_ps 3 34722 _002162_hash NULL
84658 +_002163_hash ieee80211_if_read_path_refresh_time 3 25545 _002163_hash NULL
84659 +_002164_hash ieee80211_if_read_peer 3 45233 _002164_hash NULL
84660 +_002165_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002165_hash NULL
84661 +_002166_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002166_hash NULL
84662 +_002167_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002167_hash NULL
84663 +_002168_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002168_hash NULL
84664 +_002169_hash ieee80211_if_read_rssi_threshold 3 49260 _002169_hash NULL
84665 +_002170_hash ieee80211_if_read_smps 3 27416 _002170_hash NULL
84666 +_002171_hash ieee80211_if_read_state 3 9813 _002280_hash NULL nohasharray
84667 +_002172_hash ieee80211_if_read_tkip_mic_test 3 19565 _002172_hash NULL
84668 +_002173_hash ieee80211_if_read_tsf 3 16420 _002173_hash NULL
84669 +_002174_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002174_hash NULL
84670 +_002175_hash ieee80211_if_read_uapsd_queues 3 55150 _002175_hash NULL
84671 +_002176_hash ieee80211_rx_mgmt_beacon 3 24430 _002176_hash NULL
84672 +_002177_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002177_hash NULL
84673 +_002178_hash ima_show_htable_violations 3 10619 _002178_hash NULL
84674 +_002179_hash ima_show_measurements_count 3 23536 _002179_hash NULL
84675 +_002180_hash insert_one_name 7 61668 _002180_hash NULL
84676 +_002181_hash ipr_change_queue_depth 2 6431 _002181_hash NULL
84677 +_002182_hash ip_recv_error 3 23109 _002182_hash NULL
84678 +_002183_hash ipv6_recv_error 3 56347 _002183_hash NULL
84679 +_002184_hash ipv6_recv_rxpmtu 3 7142 _002184_hash NULL
84680 +_002185_hash ipx_recvmsg 4 44366 _002185_hash NULL
84681 +_002186_hash irda_recvmsg_dgram 4 32631 _002186_hash NULL
84682 +_002187_hash iscsi_change_queue_depth 2 23416 _002187_hash NULL
84683 +_002188_hash ivtv_read_pos 3 34400 _002188_hash &_000303_hash
84684 +_002189_hash key_conf_hw_key_idx_read 3 25003 _002189_hash NULL
84685 +_002190_hash key_conf_keyidx_read 3 42443 _002190_hash NULL
84686 +_002191_hash key_conf_keylen_read 3 49758 _002191_hash NULL
84687 +_002192_hash key_flags_read 3 25931 _002192_hash NULL
84688 +_002193_hash key_ifindex_read 3 31411 _002193_hash NULL
84689 +_002194_hash key_tx_rx_count_read 3 44742 _002194_hash NULL
84690 +_002195_hash l2cap_sock_sendmsg 4 63427 _002195_hash NULL
84691 +_002196_hash l2tp_ip_recvmsg 4 22681 _002196_hash NULL
84692 +_002197_hash llc_ui_recvmsg 4 3826 _002197_hash NULL
84693 +_002198_hash lpfc_change_queue_depth 2 25905 _002198_hash NULL
84694 +_002199_hash macvtap_do_read 4 36555 _002199_hash &_001832_hash
84695 +_002200_hash megaraid_change_queue_depth 2 64815 _002200_hash NULL
84696 +_002201_hash megasas_change_queue_depth 2 32747 _002201_hash NULL
84697 +_002202_hash mptscsih_change_queue_depth 2 26036 _002202_hash NULL
84698 +_002203_hash NCR_700_change_queue_depth 2 31742 _002203_hash NULL
84699 +_002204_hash netlink_recvmsg 4 61600 _002204_hash NULL
84700 +_002205_hash nfsctl_transaction_read 3 48250 _002205_hash NULL
84701 +_002206_hash nfs_map_group_to_gid 3 15892 _002206_hash NULL
84702 +_002207_hash nfs_map_name_to_uid 3 51132 _002207_hash NULL
84703 +_002208_hash nr_recvmsg 4 12649 _002208_hash NULL
84704 +_002209_hash osd_req_list_collection_objects 5 36664 _002209_hash NULL
84705 +_002210_hash osd_req_list_partition_objects 5 56464 _002210_hash NULL
84706 +_002212_hash packet_recv_error 3 16669 _002212_hash NULL
84707 +_002213_hash packet_recvmsg 4 47700 _002213_hash NULL
84708 +_002214_hash pep_recvmsg 4 19402 _002214_hash NULL
84709 +_002215_hash pfkey_recvmsg 4 53604 _002215_hash NULL
84710 +_002216_hash ping_recvmsg 4 25597 _002216_hash NULL
84711 +_002217_hash pmcraid_change_queue_depth 2 9116 _002217_hash NULL
84712 +_002218_hash pn_recvmsg 4 30887 _002218_hash NULL
84713 +_002219_hash pointer_size_read 3 51863 _002219_hash NULL
84714 +_002220_hash power_read 3 15939 _002220_hash NULL
84715 +_002221_hash pppoe_recvmsg 4 15073 _002221_hash NULL
84716 +_002222_hash pppol2tp_recvmsg 4 57742 _002222_hash NULL
84717 +_002223_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002223_hash NULL
84718 +_002224_hash qla2x00_change_queue_depth 2 24742 _002224_hash NULL
84719 +_002225_hash raw_recvmsg 4 52529 _002225_hash NULL
84720 +_002226_hash rawsock_recvmsg 4 12144 _002226_hash NULL
84721 +_002227_hash rawv6_recvmsg 4 30265 _002227_hash NULL
84722 +_002228_hash reada_add_block 2 54247 _002228_hash NULL
84723 +_002229_hash readahead_tree_block 3 36285 _002229_hash NULL
84724 +_002230_hash reada_tree_block_flagged 3 18402 _002230_hash NULL
84725 +_002231_hash read_tree_block 3 841 _002231_hash NULL
84726 +_002232_hash recover_peb 6-7 29238 _002232_hash NULL
84727 +_002234_hash recv_msg 4 48709 _002234_hash NULL
84728 +_002235_hash recv_stream 4 30138 _002235_hash NULL
84729 +_002236_hash _req_append_segment 2 41031 _002236_hash NULL
84730 +_002237_hash request_key_async 4 6990 _002237_hash NULL
84731 +_002238_hash request_key_async_with_auxdata 4 46624 _002238_hash NULL
84732 +_002239_hash request_key_with_auxdata 4 24515 _002239_hash NULL
84733 +_002240_hash rose_recvmsg 4 2368 _002240_hash NULL
84734 +_002241_hash rxrpc_recvmsg 4 26233 _002241_hash NULL
84735 +_002242_hash rx_streaming_always_read 3 49401 _002242_hash NULL
84736 +_002243_hash rx_streaming_interval_read 3 55291 _002243_hash NULL
84737 +_002244_hash sas_change_queue_depth 2 18555 _002244_hash NULL
84738 +_002245_hash scsi_activate_tcq 2 42640 _002245_hash NULL
84739 +_002246_hash scsi_deactivate_tcq 2 47086 _002246_hash NULL
84740 +_002247_hash scsi_execute 5 33596 _002247_hash NULL
84741 +_002248_hash _scsih_adjust_queue_depth 2 1083 _002248_hash NULL
84742 +_002249_hash scsi_init_shared_tag_map 2 59812 _002249_hash NULL
84743 +_002250_hash scsi_track_queue_full 2 44239 _002250_hash NULL
84744 +_002251_hash sctp_recvmsg 4 23265 _002251_hash NULL
84745 +_002252_hash send_stream 4 3397 _002252_hash NULL
84746 +_002253_hash skb_copy_and_csum_datagram_iovec 2 24466 _002253_hash NULL
84747 +_002255_hash snd_gf1_mem_proc_dump 5 16926 _002255_hash NULL
84748 +_002256_hash split_scan_timeout_read 3 20029 _002256_hash NULL
84749 +_002257_hash sta_dev_read 3 14782 _002257_hash NULL
84750 +_002258_hash sta_inactive_ms_read 3 25690 _002258_hash NULL
84751 +_002259_hash sta_last_signal_read 3 31818 _002259_hash NULL
84752 +_002260_hash stats_dot11ACKFailureCount_read 3 45558 _002260_hash NULL
84753 +_002261_hash stats_dot11FCSErrorCount_read 3 28154 _002261_hash NULL
84754 +_002262_hash stats_dot11RTSFailureCount_read 3 43948 _002262_hash NULL
84755 +_002263_hash stats_dot11RTSSuccessCount_read 3 33065 _002263_hash NULL
84756 +_002264_hash storvsc_connect_to_vsp 2 22 _002264_hash NULL
84757 +_002265_hash suspend_dtim_interval_read 3 64971 _002265_hash NULL
84758 +_002266_hash sys_msgrcv 3 959 _002266_hash NULL
84759 +_002267_hash tcm_loop_change_queue_depth 2 42454 _002267_hash NULL
84760 +_002268_hash tcp_copy_to_iovec 3 28344 _002268_hash NULL
84761 +_002269_hash tcp_recvmsg 4 31238 _002269_hash NULL
84762 +_002270_hash timeout_read 3 47915 _002270_hash NULL
84763 +_002271_hash total_ps_buffered_read 3 16365 _002271_hash NULL
84764 +_002272_hash tun_put_user 4 59849 _002272_hash NULL
84765 +_002273_hash twa_change_queue_depth 2 48808 _002273_hash NULL
84766 +_002274_hash tw_change_queue_depth 2 11116 _002274_hash NULL
84767 +_002275_hash twl_change_queue_depth 2 41342 _002275_hash NULL
84768 +_002276_hash ubi_eba_write_leb 5-6 19826 _002276_hash NULL
84769 +_002278_hash ubi_eba_write_leb_st 5 27896 _002278_hash NULL
84770 +_002279_hash udp_recvmsg 4 42558 _002279_hash NULL
84771 +_002280_hash udpv6_recvmsg 4 9813 _002280_hash &_002171_hash
84772 +_002281_hash ulong_read_file 3 42304 _002281_hash &_000511_hash
84773 +_002282_hash unix_dgram_recvmsg 4 14952 _002282_hash NULL
84774 +_002283_hash user_power_read 3 39414 _002283_hash NULL
84775 +_002284_hash vcc_recvmsg 4 37198 _002284_hash NULL
84776 +_002285_hash wep_iv_read 3 54744 _002285_hash NULL
84777 +_002286_hash x25_recvmsg 4 42777 _002286_hash NULL
84778 +_002287_hash xfs_iext_insert 3 18667 _002287_hash NULL
84779 +_002288_hash xfs_iext_remove 3 50909 _002288_hash NULL
84780 +_002289_hash xlog_find_verify_log_record 2 18870 _002289_hash NULL
84781 +_002290_hash btrfs_alloc_free_block 3 29982 _002290_hash NULL
84782 +_002291_hash cx18_read_pos 3 4683 _002291_hash NULL
84783 +_002292_hash l2cap_sock_recvmsg 4 59886 _002292_hash NULL
84784 +_002293_hash osd_req_list_dev_partitions 4 60027 _002293_hash NULL
84785 +_002294_hash osd_req_list_partition_collections 5 38223 _002294_hash NULL
84786 +_002295_hash osst_do_scsi 4 44410 _002295_hash NULL
84787 +_002296_hash qla2x00_handle_queue_full 2 24365 _002296_hash NULL
84788 +_002297_hash rfcomm_sock_recvmsg 4 22227 _002297_hash NULL
84789 +_002298_hash scsi_execute_req 5 42088 _002298_hash NULL
84790 +_002299_hash _scsih_change_queue_depth 2 26230 _002299_hash NULL
84791 +_002300_hash spi_execute 5 28736 _002300_hash NULL
84792 +_002301_hash submit_inquiry 3 42108 _002301_hash NULL
84793 +_002302_hash tcp_dma_try_early_copy 3 37651 _002302_hash NULL
84794 +_002303_hash tun_do_read 4 50800 _002303_hash NULL
84795 +_002304_hash ubi_eba_atomic_leb_change 5 13041 _002304_hash NULL
84796 +_002305_hash ubi_leb_write 4-5 41691 _002305_hash NULL
84797 +_002307_hash unix_seqpacket_recvmsg 4 23062 _002307_hash NULL
84798 +_002308_hash write_leb 5 36957 _002308_hash NULL
84799 +_002309_hash ch_do_scsi 4 31171 _002309_hash NULL
84800 +_002310_hash dbg_leb_write 4-5 20478 _002310_hash NULL
84801 +_002312_hash scsi_mode_sense 5 16835 _002312_hash NULL
84802 +_002313_hash scsi_vpd_inquiry 4 30040 _002313_hash NULL
84803 +_002314_hash ses_recv_diag 4 47143 _002314_hash &_000673_hash
84804 +_002315_hash ses_send_diag 4 64527 _002315_hash NULL
84805 +_002316_hash spi_dv_device_echo_buffer 2-3 39846 _002316_hash NULL
84806 +_002318_hash ubifs_leb_write 4-5 61226 _002318_hash NULL
84807 +_002320_hash ubi_leb_change 4 14899 _002320_hash NULL
84808 +_002321_hash ubi_write 4-5 30809 _002321_hash NULL
84809 +_002322_hash dbg_leb_change 4 19969 _002322_hash NULL
84810 +_002323_hash gluebi_write 3 27905 _002323_hash NULL
84811 +_002324_hash scsi_get_vpd_page 4 51951 _002324_hash NULL
84812 +_002325_hash sd_do_mode_sense 5 11507 _002325_hash NULL
84813 +_002326_hash ubifs_leb_change 4 22399 _002436_hash NULL nohasharray
84814 +_002327_hash ubifs_write_node 5 15088 _002327_hash NULL
84815 +_002328_hash fixup_leb 3 43256 _002328_hash NULL
84816 +_002329_hash recover_head 3 17904 _002329_hash NULL
84817 +_002330_hash alloc_cpu_rmap 1 65363 _002330_hash NULL
84818 +_002331_hash alloc_ebda_hpc 1-2 50046 _002331_hash NULL
84819 +_002333_hash alloc_sched_domains 1 28972 _002333_hash NULL
84820 +_002334_hash amthi_read 4 45831 _002334_hash NULL
84821 +_002335_hash bcm_char_read 3 31750 _002335_hash NULL
84822 +_002336_hash BcmCopySection 5 2035 _002336_hash NULL
84823 +_002337_hash buffer_from_user 3 51826 _002337_hash NULL
84824 +_002338_hash buffer_to_user 3 35439 _002338_hash NULL
84825 +_002339_hash c4iw_init_resource_fifo 3 48090 _002339_hash NULL
84826 +_002340_hash c4iw_init_resource_fifo_random 3 25547 _002340_hash NULL
84827 +_002341_hash card_send_command 3 40757 _002341_hash NULL
84828 +_002342_hash chd_dec_fetch_cdata 3 50926 _002342_hash NULL
84829 +_002343_hash crystalhd_create_dio_pool 2 3427 _002343_hash NULL
84830 +_002344_hash crystalhd_user_data 3 18407 _002344_hash NULL
84831 +_002345_hash cxio_init_resource_fifo 3 28764 _002345_hash NULL
84832 +_002346_hash cxio_init_resource_fifo_random 3 47151 _002346_hash NULL
84833 +_002347_hash do_pages_stat 2 4437 _002347_hash NULL
84834 +_002348_hash do_read_log_to_user 4 3236 _002348_hash NULL
84835 +_002349_hash do_write_log_from_user 3 39362 _002349_hash NULL
84836 +_002350_hash dt3155_read 3 59226 _002350_hash NULL
84837 +_002351_hash easycap_alsa_vmalloc 2 14426 _002351_hash NULL
84838 +_002352_hash evm_read_key 3 54674 _002352_hash NULL
84839 +_002353_hash evm_write_key 3 27715 _002353_hash NULL
84840 +_002354_hash fir16_create 3 5574 _002354_hash NULL
84841 +_002355_hash iio_allocate_device 1 18821 _002355_hash NULL
84842 +_002356_hash __iio_allocate_kfifo 2-3 55738 _002356_hash NULL
84843 +_002358_hash __iio_allocate_sw_ring_buffer 3 4843 _002358_hash NULL
84844 +_002359_hash iio_debugfs_read_reg 3 60908 _002359_hash NULL
84845 +_002360_hash iio_debugfs_write_reg 3 22742 _002360_hash NULL
84846 +_002361_hash iio_event_chrdev_read 3 54757 _002361_hash NULL
84847 +_002362_hash iio_read_first_n_kfifo 2 57910 _002362_hash NULL
84848 +_002363_hash iio_read_first_n_sw_rb 2 51911 _002363_hash NULL
84849 +_002364_hash ioapic_setup_resources 1 35255 _002364_hash NULL
84850 +_002365_hash keymap_store 4 45406 _002365_hash NULL
84851 +_002366_hash kzalloc_node 1 24352 _002366_hash NULL
84852 +_002367_hash line6_alloc_sysex_buffer 4 28225 _002367_hash NULL
84853 +_002368_hash line6_dumpreq_initbuf 3 53123 _002368_hash NULL
84854 +_002369_hash line6_midibuf_init 2 52425 _002369_hash NULL
84855 +_002370_hash lirc_write 3 20604 _002370_hash NULL
84856 +_002371_hash _malloc 1 54077 _002371_hash NULL
84857 +_002372_hash mei_read 3 6507 _002372_hash NULL
84858 +_002373_hash mei_write 3 4005 _002373_hash NULL
84859 +_002374_hash mempool_create_node 1 44715 _002374_hash NULL
84860 +_002375_hash msg_set 3 51725 _002375_hash NULL
84861 +_002376_hash newpart 6 47485 _002376_hash NULL
84862 +_002377_hash OS_kmalloc 1 36909 _002377_hash NULL
84863 +_002378_hash pcpu_alloc_bootmem 2 62074 _002378_hash NULL
84864 +_002379_hash pcpu_get_vm_areas 3 50085 _002379_hash NULL
84865 +_002380_hash resource_from_user 3 30341 _002380_hash NULL
84866 +_002381_hash sca3000_read_data 4 57064 _002381_hash NULL
84867 +_002382_hash sca3000_read_first_n_hw_rb 2 11479 _002382_hash NULL
84868 +_002383_hash send_midi_async 3 57463 _002383_hash NULL
84869 +_002384_hash sep_create_dcb_dmatables_context 6 37551 _002384_hash NULL
84870 +_002385_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002385_hash NULL
84871 +_002386_hash sep_create_msgarea_context 4 33829 _002386_hash NULL
84872 +_002387_hash sep_lli_table_secure_dma 2-3 64042 _002387_hash NULL
84873 +_002389_hash sep_lock_user_pages 2-3 57470 _002389_hash &_002154_hash
84874 +_002391_hash sep_prepare_input_output_dma_table_in_dcb 4-5 63087 _002391_hash NULL
84875 +_002393_hash sep_read 3 17161 _002393_hash NULL
84876 +_002394_hash TransmitTcb 4 12989 _002394_hash NULL
84877 +_002395_hash ValidateDSDParamsChecksum 3 63654 _002395_hash NULL
84878 +_002396_hash Wb35Reg_BurstWrite 4 62327 _002396_hash NULL
84879 +_002397_hash __alloc_bootmem_low_node 2 25726 _002397_hash &_001499_hash
84880 +_002398_hash __alloc_bootmem_node 2 1992 _002398_hash NULL
84881 +_002399_hash alloc_irq_cpu_rmap 1 28459 _002399_hash NULL
84882 +_002400_hash alloc_ring 2-4 18278 _002400_hash NULL
84883 +_002402_hash c4iw_init_resource 2-3 30393 _002402_hash NULL
84884 +_002404_hash cxio_hal_init_resource 2-7-6 29771 _002404_hash &_000284_hash
84885 +_002407_hash cxio_hal_init_rhdl_resource 1 25104 _002407_hash NULL
84886 +_002408_hash disk_expand_part_tbl 2 30561 _002408_hash NULL
84887 +_002409_hash InterfaceTransmitPacket 3 42058 _002409_hash NULL
84888 +_002410_hash line6_dumpreq_init 3 34473 _002410_hash NULL
84889 +_002411_hash mempool_create 1 29437 _002411_hash NULL
84890 +_002412_hash pcpu_fc_alloc 2 11818 _002412_hash NULL
84891 +_002413_hash pod_alloc_sysex_buffer 3 31651 _002413_hash NULL
84892 +_002414_hash r8712_usbctrl_vendorreq 6 48489 _002414_hash NULL
84893 +_002415_hash r871x_set_wpa_ie 3 7000 _002415_hash NULL
84894 +_002416_hash sys_move_pages 2 42626 _002416_hash NULL
84895 +_002417_hash variax_alloc_sysex_buffer 3 15237 _002417_hash NULL
84896 +_002418_hash vme_user_write 3 15587 _002418_hash NULL
84897 +_002419_hash add_partition 2 55588 _002419_hash NULL
84898 +_002420_hash __alloc_bootmem_node_high 2 65076 _002420_hash NULL
84899 +_002421_hash ceph_msgpool_init 3 33312 _002421_hash NULL
84900 +_002423_hash mempool_create_kmalloc_pool 1 41650 _002423_hash NULL
84901 +_002424_hash mempool_create_page_pool 1 30189 _002424_hash NULL
84902 +_002425_hash mempool_create_slab_pool 1 62907 _002425_hash NULL
84903 +_002426_hash variax_set_raw2 4 32374 _002426_hash NULL
84904 +_002427_hash bioset_create 1 5580 _002427_hash NULL
84905 +_002428_hash bioset_integrity_create 2 62708 _002428_hash NULL
84906 +_002429_hash biovec_create_pools 2 9575 _002429_hash NULL
84907 +_002430_hash i2o_pool_alloc 4 55485 _002430_hash NULL
84908 +_002431_hash prison_create 1 43623 _002431_hash NULL
84909 +_002432_hash unlink_simple 3 47506 _002432_hash NULL
84910 +_002433_hash alloc_ieee80211 1 20063 _002433_hash NULL
84911 +_002434_hash alloc_ieee80211_rsl 1 34564 _002434_hash NULL
84912 +_002435_hash alloc_page_cgroup 1 2919 _002435_hash NULL
84913 +_002436_hash alloc_private 2 22399 _002436_hash &_002326_hash
84914 +_002437_hash alloc_rtllib 1 51136 _002437_hash NULL
84915 +_002438_hash alloc_rx_desc_ring 2 18016 _002438_hash NULL
84916 +_002439_hash alloc_subdevices 2 43300 _002439_hash NULL
84917 +_002440_hash atomic_counters_read 3 48827 _002440_hash NULL
84918 +_002441_hash atomic_stats_read 3 36228 _002441_hash NULL
84919 +_002442_hash capabilities_read 3 58457 _002442_hash NULL
84920 +_002443_hash comedi_read 3 13199 _002443_hash NULL
84921 +_002444_hash comedi_write 3 47926 _002444_hash NULL
84922 +_002445_hash compat_do_arpt_set_ctl 4 12184 _002445_hash NULL
84923 +_002446_hash compat_do_ip6t_set_ctl 4 3184 _002446_hash NULL
84924 +_002447_hash compat_do_ipt_set_ctl 4 58466 _002447_hash &_001852_hash
84925 +_002448_hash compat_filldir 3 32999 _002448_hash NULL
84926 +_002449_hash compat_filldir64 3 35354 _002449_hash NULL
84927 +_002450_hash compat_fillonedir 3 15620 _002450_hash NULL
84928 +_002451_hash compat_rw_copy_check_uvector 3 25242 _002451_hash NULL
84929 +_002452_hash compat_sock_setsockopt 5 23 _002452_hash NULL
84930 +_002453_hash compat_sys_kexec_load 2 35674 _002453_hash NULL
84931 +_002454_hash compat_sys_keyctl 4 9639 _002454_hash NULL
84932 +_002455_hash compat_sys_move_pages 2 5861 _002455_hash NULL
84933 +_002456_hash compat_sys_mq_timedsend 3 31060 _002456_hash NULL
84934 +_002457_hash compat_sys_msgrcv 2 7482 _002457_hash NULL
84935 +_002458_hash compat_sys_msgsnd 2 10738 _002458_hash NULL
84936 +_002459_hash compat_sys_semtimedop 3 3606 _002459_hash NULL
84937 +_002460_hash __copy_in_user 3 34790 _002460_hash NULL
84938 +_002461_hash copy_in_user 3 57502 _002461_hash NULL
84939 +_002462_hash dev_counters_read 3 19216 _002462_hash NULL
84940 +_002463_hash dev_names_read 3 38509 _002463_hash NULL
84941 +_002464_hash do_arpt_set_ctl 4 51053 _002464_hash NULL
84942 +_002465_hash do_ip6t_set_ctl 4 60040 _002465_hash NULL
84943 +_002466_hash do_ipt_set_ctl 4 56238 _002466_hash NULL
84944 +_002467_hash drbd_bm_resize 2 20522 _002467_hash NULL
84945 +_002468_hash driver_names_read 3 60399 _002468_hash NULL
84946 +_002469_hash driver_stats_read 3 8944 _002469_hash NULL
84947 +_002470_hash __earlyonly_bootmem_alloc 2 23824 _002470_hash NULL
84948 +_002471_hash evtchn_read 3 3569 _002471_hash NULL
84949 +_002472_hash ext_sd_execute_read_data 9 48589 _002472_hash NULL
84950 +_002473_hash ext_sd_execute_write_data 9 8175 _002473_hash NULL
84951 +_002474_hash fat_compat_ioctl_filldir 3 36328 _002474_hash NULL
84952 +_002475_hash firmwareUpload 3 32794 _002475_hash NULL
84953 +_002476_hash flash_read 3 57843 _002476_hash NULL
84954 +_002477_hash flash_write 3 62354 _002477_hash NULL
84955 +_002478_hash gather_array 3 56641 _002478_hash NULL
84956 +_002479_hash ghash_async_setkey 3 60001 _002479_hash NULL
84957 +_002480_hash gntdev_alloc_map 2 35145 _002480_hash NULL
84958 +_002481_hash gnttab_map 2 56439 _002481_hash NULL
84959 +_002482_hash gru_alloc_gts 2-3 60056 _002482_hash NULL
84960 +_002484_hash handle_eviocgbit 3 44193 _002484_hash NULL
84961 +_002485_hash hid_parse_report 3 51737 _002485_hash NULL
84962 +_002486_hash ieee80211_alloc_txb 1-2 52477 _002486_hash NULL
84963 +_002487_hash ieee80211_wx_set_gen_ie 3 51399 _002487_hash NULL
84964 +_002488_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _002488_hash NULL
84965 +_002489_hash init_cdev 1 8274 _002489_hash NULL
84966 +_002490_hash init_per_cpu 1 17880 _002490_hash NULL
84967 +_002491_hash ipath_create_cq 2 45586 _002491_hash NULL
84968 +_002492_hash ipath_get_base_info 3 7043 _002492_hash NULL
84969 +_002493_hash ipath_init_qp_table 2 25167 _002493_hash NULL
84970 +_002494_hash ipath_resize_cq 2 712 _002494_hash NULL
84971 +_002495_hash ni_gpct_device_construct 5 610 _002495_hash NULL
84972 +_002496_hash options_write 3 47243 _002496_hash NULL
84973 +_002497_hash portcntrs_1_read 3 47253 _002497_hash NULL
84974 +_002498_hash portcntrs_2_read 3 56586 _002498_hash NULL
84975 +_002499_hash portnames_read 3 41958 _002499_hash NULL
84976 +_002500_hash ptc_proc_write 3 12076 _002500_hash NULL
84977 +_002501_hash put_cmsg_compat 4 35937 _002501_hash NULL
84978 +_002502_hash qib_alloc_devdata 2 51819 _002502_hash NULL
84979 +_002503_hash qib_alloc_fast_reg_page_list 2 10507 _002503_hash NULL
84980 +_002504_hash qib_cdev_init 1 34778 _002504_hash NULL
84981 +_002505_hash qib_create_cq 2 27497 _002505_hash NULL
84982 +_002506_hash qib_diag_write 3 62133 _002506_hash NULL
84983 +_002507_hash qib_get_base_info 3 11369 _002507_hash NULL
84984 +_002508_hash qib_resize_cq 2 53090 _002508_hash NULL
84985 +_002509_hash qsfp_1_read 3 21915 _002509_hash NULL
84986 +_002510_hash qsfp_2_read 3 31491 _002510_hash NULL
84987 +_002511_hash queue_reply 3 22416 _002511_hash NULL
84988 +_002512_hash Realloc 2 34961 _002512_hash NULL
84989 +_002513_hash rfc4106_set_key 3 54519 _002513_hash NULL
84990 +_002514_hash rtllib_alloc_txb 1-2 21687 _002514_hash NULL
84991 +_002515_hash rtllib_wx_set_gen_ie 3 59808 _002515_hash NULL
84992 +_002516_hash rts51x_transfer_data_partial 6 5735 _002516_hash NULL
84993 +_002517_hash sparse_early_usemaps_alloc_node 4 9269 _002517_hash NULL
84994 +_002518_hash split 2 11691 _002518_hash NULL
84995 +_002519_hash stats_read_ul 3 32751 _002519_hash NULL
84996 +_002520_hash store_debug_level 3 35652 _002520_hash NULL
84997 +_002521_hash sys32_ipc 3 7238 _002521_hash NULL
84998 +_002522_hash sys32_rt_sigpending 2 25814 _002522_hash NULL
84999 +_002523_hash tunables_read 3 36385 _002523_hash NULL
85000 +_002524_hash tunables_write 3 59563 _002524_hash NULL
85001 +_002525_hash u32_array_read 3 2219 _002525_hash NULL
85002 +_002526_hash usb_buffer_alloc 2 36276 _002526_hash NULL
85003 +_002527_hash xenbus_file_write 3 6282 _002527_hash NULL
85004 +_002528_hash xpc_kmalloc_cacheline_aligned 1 42895 _002528_hash NULL
85005 +_002529_hash xpc_kzalloc_cacheline_aligned 1 65433 _002529_hash NULL
85006 +_002530_hash xsd_read 3 15653 _002530_hash NULL
85007 +_002531_hash compat_do_readv_writev 4 49102 _002531_hash NULL
85008 +_002532_hash compat_keyctl_instantiate_key_iov 3 57431 _003110_hash NULL nohasharray
85009 +_002533_hash compat_process_vm_rw 3-5 22254 _002533_hash NULL
85010 +_002535_hash compat_sys_setsockopt 5 3326 _002535_hash NULL
85011 +_002536_hash ipath_cdev_init 1 37752 _002536_hash NULL
85012 +_002537_hash ms_read_multiple_pages 4-5 8052 _002537_hash NULL
85013 +_002539_hash ms_write_multiple_pages 5-6 10362 _002539_hash NULL
85014 +_002541_hash sparse_mem_maps_populate_node 4 12669 _002541_hash &_002004_hash
85015 +_002542_hash vmemmap_alloc_block 1 43245 _002542_hash NULL
85016 +_002543_hash xd_read_multiple_pages 4-5 11422 _002543_hash NULL
85017 +_002545_hash xd_write_multiple_pages 5-6 53633 _002545_hash NULL
85018 +_002546_hash compat_readv 3 30273 _002546_hash NULL
85019 +_002547_hash compat_sys_process_vm_readv 3-5 15374 _002547_hash NULL
85020 +_002549_hash compat_sys_process_vm_writev 3-5 41194 _002549_hash NULL
85021 +_002551_hash compat_writev 3 60063 _002551_hash NULL
85022 +_002552_hash ms_rw_multi_sector 4 7459 _002552_hash NULL
85023 +_002553_hash sparse_early_mem_maps_alloc_node 4 36971 _002553_hash NULL
85024 +_002554_hash vmemmap_alloc_block_buf 1 61126 _002554_hash NULL
85025 +_002555_hash xd_rw 4 49020 _002555_hash NULL
85026 +_002556_hash compat_sys_preadv64 3 24283 _002556_hash NULL
85027 +_002557_hash compat_sys_pwritev64 3 51151 _002557_hash NULL
85028 +_002558_hash compat_sys_readv 3 20911 _002558_hash NULL
85029 +_002559_hash compat_sys_writev 3 5784 _002559_hash NULL
85030 +_002560_hash ms_rw 4 17220 _002560_hash NULL
85031 +_002561_hash compat_sys_preadv 3 583 _002561_hash NULL
85032 +_002562_hash compat_sys_pwritev 3 17886 _002562_hash NULL
85033 +_002563_hash alloc_apertures 1 56561 _002563_hash NULL
85034 +_002564_hash bin_uuid 3 28999 _002564_hash NULL
85035 +_002565_hash __copy_from_user_inatomic_nocache 3 49921 _002565_hash NULL
85036 +_002566_hash do_dmabuf_dirty_sou 7 3017 _002566_hash NULL
85037 +_002567_hash do_surface_dirty_sou 7 39678 _002567_hash NULL
85038 +_002568_hash drm_agp_bind_pages 3 56748 _002568_hash NULL
85039 +_002569_hash drm_calloc_large 1-2 65421 _002569_hash NULL
85040 +_002571_hash drm_fb_helper_init 3-4 19044 _002571_hash NULL
85041 +_002573_hash drm_ht_create 2 18853 _002573_hash NULL
85042 +_002574_hash drm_malloc_ab 1-2 16831 _002574_hash NULL
85043 +_002576_hash drm_mode_crtc_set_gamma_size 2 31881 _002576_hash NULL
85044 +_002577_hash drm_plane_init 6 28731 _002577_hash NULL
85045 +_002578_hash drm_property_create 4 51239 _002578_hash NULL
85046 +_002579_hash drm_property_create_blob 2 7414 _002579_hash NULL
85047 +_002580_hash drm_vblank_init 2 11362 _002580_hash NULL
85048 +_002581_hash drm_vmalloc_dma 1 14550 _002581_hash NULL
85049 +_002582_hash fb_alloc_cmap_gfp 2 20792 _002582_hash NULL
85050 +_002583_hash fbcon_prepare_logo 5 6246 _002583_hash NULL
85051 +_002584_hash fb_read 3 33506 _002584_hash NULL
85052 +_002585_hash fb_write 3 46924 _002585_hash NULL
85053 +_002586_hash framebuffer_alloc 1 59145 _002586_hash NULL
85054 +_002587_hash i915_cache_sharing_read 3 24775 _002587_hash NULL
85055 +_002588_hash i915_cache_sharing_write 3 57961 _002588_hash NULL
85056 +_002589_hash i915_max_freq_read 3 20581 _002589_hash NULL
85057 +_002590_hash i915_max_freq_write 3 11350 _002590_hash NULL
85058 +_002591_hash i915_wedged_read 3 35474 _002591_hash NULL
85059 +_002592_hash i915_wedged_write 3 47771 _002592_hash NULL
85060 +_002593_hash p9_client_read 5 19750 _002593_hash NULL
85061 +_002594_hash probe_kernel_write 3 17481 _002594_hash NULL
85062 +_002595_hash sched_feat_write 3 55202 _002595_hash NULL
85063 +_002596_hash sd_alloc_ctl_entry 1 29708 _002596_hash NULL
85064 +_002597_hash tstats_write 3 60432 _002597_hash &_000009_hash
85065 +_002598_hash ttm_bo_fbdev_io 4 9805 _002598_hash NULL
85066 +_002599_hash ttm_bo_io 5 47000 _002599_hash NULL
85067 +_002600_hash ttm_dma_page_pool_free 2 34135 _002600_hash NULL
85068 +_002601_hash ttm_page_pool_free 2 61661 _002601_hash NULL
85069 +_002602_hash vmw_execbuf_process 5 22885 _002602_hash NULL
85070 +_002603_hash vmw_fifo_reserve 2 12141 _002603_hash NULL
85071 +_002604_hash vmw_kms_present 9 38130 _002604_hash NULL
85072 +_002605_hash vmw_kms_readback 6 5727 _002605_hash NULL
85073 +_002606_hash do_dmabuf_dirty_ldu 6 52241 _002606_hash NULL
85074 +_002607_hash drm_mode_create_tv_properties 2 23122 _002607_hash NULL
85075 +_002608_hash drm_property_create_enum 5 29201 _002608_hash NULL
85076 +_002609_hash fast_user_write 5 20494 _002609_hash NULL
85077 +_002610_hash fb_alloc_cmap 2 6554 _002610_hash NULL
85078 +_002611_hash i915_gem_execbuffer_relocate_slow 7 25355 _002611_hash NULL
85079 +_002612_hash kgdb_hex2mem 3 24755 _002612_hash NULL
85080 +_002613_hash ttm_object_device_init 2 10321 _002613_hash NULL
85081 +_002614_hash ttm_object_file_init 2 27804 _002614_hash NULL
85082 +_002615_hash vmw_cursor_update_image 3-4 16332 _002615_hash NULL
85083 +_002617_hash vmw_gmr2_bind 3 21305 _002617_hash NULL
85084 +_002618_hash vmw_cursor_update_dmabuf 3-4 32045 _002618_hash NULL
85085 +_002620_hash vmw_gmr_bind 3 44130 _002620_hash NULL
85086 +_002621_hash vmw_du_crtc_cursor_set 4-5 28479 _002621_hash NULL
85087 +_002622_hash __module_alloc 1 50004 _002622_hash NULL
85088 +_002623_hash module_alloc_update_bounds_rw 1 63233 _002623_hash NULL
85089 +_002624_hash module_alloc_update_bounds_rx 1 58634 _002624_hash NULL
85090 +_002625_hash acpi_system_write_alarm 3 40205 _002625_hash NULL
85091 +_002626_hash create_table 2 16213 _002626_hash NULL
85092 +_002627_hash mem_read 3 57631 _002627_hash NULL
85093 +_002628_hash mem_write 3 22232 _002628_hash NULL
85094 +_002629_hash proc_fault_inject_read 3 36802 _002629_hash NULL
85095 +_002630_hash proc_fault_inject_write 3 21058 _002630_hash NULL
85096 +_002631_hash v9fs_fid_readn 4 60544 _002631_hash NULL
85097 +_002632_hash v9fs_file_read 3 40858 _002632_hash NULL
85098 +_002633_hash __devres_alloc 2 25598 _002633_hash NULL
85099 +_002634_hash alloc_dummy_extent_buffer 2 56374 _002634_hash NULL
85100 +_002635_hash alloc_fdtable 1 17389 _002635_hash NULL
85101 +_002636_hash alloc_large_system_hash 2 22391 _002636_hash NULL
85102 +_002637_hash alloc_ldt 2 21972 _002637_hash NULL
85103 +_002638_hash __alloc_skb 1 23940 _002638_hash NULL
85104 +_002639_hash __ata_change_queue_depth 3 23484 _002639_hash NULL
85105 +_002640_hash btrfs_alloc_free_block 3 8986 _002640_hash NULL
85106 +_002641_hash btrfs_find_device_for_logical 2 44993 _002641_hash NULL
85107 +_002642_hash ccid3_hc_rx_getsockopt 3 62331 _002642_hash NULL
85108 +_002643_hash ccid3_hc_tx_getsockopt 3 16314 _002643_hash NULL
85109 +_002644_hash cifs_readdata_alloc 1 26360 _002644_hash NULL
85110 +_002645_hash cistpl_vers_1 4 15023 _002645_hash NULL
85111 +_002646_hash cmm_read 3 57520 _002646_hash NULL
85112 +_002647_hash cosa_read 3 25966 _002647_hash NULL
85113 +_002648_hash dm_table_create 3 35687 _002648_hash NULL
85114 +_002649_hash dpcm_state_read_file 3 65489 _002649_hash NULL
85115 +_002651_hash edac_mc_alloc 4 3611 _002651_hash NULL
85116 +_002652_hash ep0_read 3 38095 _002652_hash NULL
85117 +_002653_hash event_buffer_read 3 48772 _002765_hash NULL nohasharray
85118 +_002654_hash extend_netdev_table 2 21453 _002654_hash NULL
85119 +_002655_hash extract_entropy_user 3 26952 _002655_hash NULL
85120 +_002656_hash fcoe_ctlr_device_add 3 1793 _002656_hash NULL
85121 +_002657_hash fd_do_readv 3 51297 _002657_hash NULL
85122 +_002658_hash fd_do_writev 3 29329 _002658_hash NULL
85123 +_002659_hash ffs_ep0_read 3 2672 _002659_hash NULL
85124 +_002660_hash fill_readbuf 3 32464 _002660_hash NULL
85125 +_002661_hash fw_iso_buffer_alloc 2 13704 _002661_hash NULL
85126 +_002662_hash get_fd_set 1 3866 _002662_hash NULL
85127 +_002663_hash hidraw_report_event 3 20503 _002663_hash NULL
85128 +_002664_hash ieee80211_if_read_ht_opmode 3 29044 _002664_hash NULL
85129 +_002665_hash ieee80211_if_read_num_mcast_sta 3 12419 _002665_hash NULL
85130 +_002666_hash iwl_dbgfs_calib_disabled_read 3 22649 _002666_hash NULL
85131 +_002667_hash iwl_dbgfs_rf_reset_read 3 26512 _002667_hash NULL
85132 +_002668_hash ixgbe_alloc_q_vector 4-6 24439 _002668_hash NULL
85133 +_002670_hash joydev_handle_JSIOCSAXMAP 3 48898 _002836_hash NULL nohasharray
85134 +_002671_hash joydev_handle_JSIOCSBTNMAP 3 15643 _002671_hash NULL
85135 +_002672_hash __kfifo_from_user_r 3 60345 _002672_hash NULL
85136 +_002673_hash kstrtoint_from_user 2 8778 _002673_hash NULL
85137 +_002674_hash kstrtol_from_user 2 10168 _002674_hash NULL
85138 +_002675_hash kstrtoll_from_user 2 19500 _002675_hash NULL
85139 +_002676_hash kstrtos16_from_user 2 28300 _002676_hash NULL
85140 +_002677_hash kstrtos8_from_user 2 58268 _002677_hash NULL
85141 +_002678_hash kstrtou16_from_user 2 54274 _002678_hash NULL
85142 +_002679_hash kstrtou8_from_user 2 55599 _002679_hash NULL
85143 +_002680_hash kstrtouint_from_user 2 10536 _002680_hash NULL
85144 +_002681_hash kstrtoul_from_user 2 64569 _002681_hash NULL
85145 +_002682_hash kstrtoull_from_user 2 63026 _002682_hash NULL
85146 +_002683_hash l2cap_create_iframe_pdu 3 40055 _002683_hash NULL
85147 +_002684_hash l2tp_ip6_recvmsg 4 62874 _002684_hash NULL
85148 +_002685_hash mem_cgroup_read 5 22461 _002685_hash NULL
85149 +_002686_hash nfs_fscache_get_super_cookie 3 44355 _002686_hash &_001648_hash
85150 +_002687_hash nfs_pgarray_set 2 1085 _002687_hash NULL
85151 +_002688_hash ntfs_rl_realloc 3 56831 _002688_hash &_000363_hash
85152 +_002689_hash ntfs_rl_realloc_nofail 3 32173 _002689_hash NULL
85153 +_002690_hash pn533_dep_link_up 5 22154 _002690_hash NULL
85154 +_002691_hash port_fops_write 3 54627 _002691_hash NULL
85155 +_002692_hash ptp_read 4 63251 _002692_hash NULL
85156 +_002693_hash qla4xxx_change_queue_depth 2 1268 _002693_hash NULL
85157 +_002694_hash reqsk_queue_alloc 2 40272 _002694_hash NULL
85158 +_002695_hash resize_info_buffer 2 62889 _002695_hash NULL
85159 +_002696_hash rfkill_fop_write 3 64808 _002696_hash NULL
85160 +_002697_hash rt2x00debug_write_rfcsr 3 41473 _002697_hash NULL
85161 +_002698_hash rvmalloc 1 46873 _002698_hash NULL
85162 +_002699_hash rw_copy_check_uvector 3 45748 _002699_hash NULL
85163 +_002700_hash sctp_getsockopt_active_key 2 45483 _002700_hash NULL
85164 +_002701_hash sctp_getsockopt_adaptation_layer 2 45375 _002701_hash NULL
85165 +_002702_hash sctp_getsockopt_assoc_ids 2 9043 _002702_hash NULL
85166 +_002703_hash sctp_getsockopt_associnfo 2 58169 _002703_hash NULL
85167 +_002704_hash sctp_getsockopt_assoc_number 2 6384 _002704_hash NULL
85168 +_002705_hash sctp_getsockopt_auto_asconf 2 46584 _002705_hash NULL
85169 +_002706_hash sctp_getsockopt_context 2 52490 _002706_hash NULL
85170 +_002707_hash sctp_getsockopt_default_send_param 2 63056 _002707_hash NULL
85171 +_002708_hash sctp_getsockopt_disable_fragments 2 12330 _002708_hash NULL
85172 +_002709_hash sctp_getsockopt_fragment_interleave 2 51215 _002709_hash NULL
85173 +_002710_hash sctp_getsockopt_initmsg 2 26042 _002710_hash NULL
85174 +_002711_hash sctp_getsockopt_mappedv4 2 20044 _002711_hash NULL
85175 +_002712_hash sctp_getsockopt_nodelay 2 9560 _002712_hash NULL
85176 +_002713_hash sctp_getsockopt_partial_delivery_point 2 60952 _002713_hash NULL
85177 +_002714_hash sctp_getsockopt_peeloff 2 59190 _002714_hash NULL
85178 +_002715_hash sctp_getsockopt_peer_addr_info 2 6024 _002715_hash NULL
85179 +_002716_hash sctp_getsockopt_peer_addr_params 2 53645 _002716_hash NULL
85180 +_002717_hash sctp_getsockopt_primary_addr 2 24639 _002717_hash NULL
85181 +_002718_hash sctp_getsockopt_rtoinfo 2 62027 _002718_hash NULL
85182 +_002719_hash sctp_getsockopt_sctp_status 2 56540 _002719_hash NULL
85183 +_002720_hash self_check_write 5 50856 _002720_hash NULL
85184 +_002721_hash smk_read_mapped 3 7562 _002721_hash NULL
85185 +_002722_hash smk_set_cipso 3 20379 _002722_hash NULL
85186 +_002723_hash smk_user_access 3 24440 _002723_hash NULL
85187 +_002724_hash smk_write_mapped 3 13519 _002724_hash NULL
85188 +_002725_hash smk_write_rules_list 3 18565 _002725_hash NULL
85189 +_002726_hash snd_mixart_BA0_read 5 45069 _002726_hash NULL
85190 +_002727_hash snd_mixart_BA1_read 5 5082 _002727_hash NULL
85191 +_002728_hash snd_pcm_oss_read2 3 54387 _002728_hash NULL
85192 +_002729_hash syslog_print 2 307 _002729_hash NULL
85193 +_002730_hash tcp_dma_try_early_copy 3 4457 _002730_hash NULL
85194 +_002731_hash tcp_send_rcvq 3 11316 _002731_hash NULL
85195 +_002732_hash tomoyo_init_log 2 61526 _002732_hash NULL
85196 +_002733_hash ubi_dump_flash 4 46381 _002733_hash NULL
85197 +_002734_hash ubi_eba_atomic_leb_change 5 60379 _002734_hash NULL
85198 +_002735_hash ubi_eba_write_leb 5-6 36029 _002735_hash NULL
85199 +_002737_hash ubi_eba_write_leb_st 5 44343 _002737_hash NULL
85200 +_002738_hash ubi_self_check_all_ff 4 41959 _002738_hash NULL
85201 +_002739_hash unix_bind 3 15668 _002739_hash NULL
85202 +_002740_hash usbvision_rvmalloc 1 19655 _002740_hash NULL
85203 +_002742_hash v4l2_ctrl_new 7 24927 _002742_hash NULL
85204 +_002743_hash v4l2_event_subscribe 3 53687 _002743_hash NULL
85205 +_002744_hash v9fs_direct_read 3 45546 _002744_hash NULL
85206 +_002745_hash v9fs_file_readn 4 36353 _002745_hash &_001606_hash
85207 +_002746_hash __videobuf_alloc_vb 1 5665 _002746_hash NULL
85208 +_002747_hash wm8350_write 3 24480 _002747_hash NULL
85209 +_002748_hash xfs_buf_read_uncached 3 42844 _002748_hash NULL
85210 +_002749_hash yurex_write 3 8761 _002749_hash NULL
85211 +_002750_hash alloc_skb 1 55439 _002750_hash NULL
85212 +_002751_hash alloc_skb_fclone 1 3467 _002751_hash NULL
85213 +_002752_hash ata_scsi_change_queue_depth 2 23126 _002752_hash NULL
85214 +_002753_hash ath6kl_disconnect_timeout_write 3 794 _002753_hash NULL
85215 +_002754_hash ath6kl_keepalive_write 3 45600 _002754_hash NULL
85216 +_002755_hash ath6kl_lrssi_roam_write 3 8362 _002755_hash NULL
85217 +_002756_hash ath6kl_regread_write 3 14220 _002756_hash NULL
85218 +_002757_hash core_sys_select 1 47494 _002757_hash NULL
85219 +_002758_hash do_syslog 3 56807 _002758_hash NULL
85220 +_002759_hash expand_fdtable 2 39273 _002759_hash NULL
85221 +_002760_hash fd_execute_cmd 3 1132 _002760_hash NULL
85222 +_002761_hash get_chars 3 40373 _002761_hash NULL
85223 +_002762_hash hid_report_raw_event 4 2762 _002762_hash NULL
85224 +_002763_hash inet_csk_listen_start 2 38233 _002763_hash NULL
85225 +_002764_hash kstrtou32_from_user 2 30361 _002764_hash NULL
85226 +_002765_hash l2cap_segment_sdu 4 48772 _002765_hash &_002653_hash
85227 +_002766_hash __netdev_alloc_skb 2 18595 _002766_hash NULL
85228 +_002767_hash nfs_readdata_alloc 2 65015 _002767_hash NULL
85229 +_002768_hash nfs_writedata_alloc 2 12133 _002768_hash NULL
85230 +_002769_hash ntfs_rl_append 2-4 6037 _002769_hash NULL
85231 +_002771_hash ntfs_rl_insert 2-4 4931 _002771_hash NULL
85232 +_002773_hash ntfs_rl_replace 2-4 14136 _002773_hash NULL
85233 +_002775_hash ntfs_rl_split 2-4 52328 _002775_hash NULL
85234 +_002777_hash port_fops_read 3 49626 _002777_hash NULL
85235 +_002778_hash random_read 3 13815 _002778_hash NULL
85236 +_002779_hash sg_proc_write_adio 3 45704 _002779_hash NULL
85237 +_002780_hash sg_proc_write_dressz 3 46316 _002780_hash NULL
85238 +_002781_hash tcp_sendmsg 4 30296 _002781_hash NULL
85239 +_002782_hash tomoyo_write_log2 2 34318 _002782_hash NULL
85240 +_002783_hash ubi_leb_change 4 10289 _002783_hash NULL
85241 +_002784_hash ubi_leb_write 4-5 5478 _002784_hash NULL
85242 +_002786_hash urandom_read 3 30462 _002786_hash NULL
85243 +_002787_hash v9fs_cached_file_read 3 2514 _002787_hash NULL
85244 +_002788_hash __videobuf_alloc_cached 1 12740 _002788_hash NULL
85245 +_002789_hash __videobuf_alloc_uncached 1 55711 _002789_hash NULL
85246 +_002790_hash wm8350_block_write 3 19727 _002790_hash NULL
85247 +_002791_hash alloc_tx 2 32143 _002791_hash NULL
85248 +_002792_hash alloc_wr 1-2 24635 _002792_hash NULL
85249 +_002794_hash ath6kl_endpoint_stats_write 3 59621 _002794_hash NULL
85250 +_002795_hash ath6kl_fwlog_mask_write 3 24810 _002795_hash NULL
85251 +_002796_hash ath9k_wmi_cmd 4 327 _002796_hash NULL
85252 +_002797_hash atm_alloc_charge 2 19517 _002879_hash NULL nohasharray
85253 +_002798_hash ax25_output 2 22736 _002798_hash NULL
85254 +_002799_hash bcsp_prepare_pkt 3 12961 _002799_hash NULL
85255 +_002800_hash bt_skb_alloc 1 6404 _002800_hash NULL
85256 +_002801_hash capinc_tty_write 3 28539 _002801_hash NULL
85257 +_002802_hash cfpkt_create_pfx 1-2 23594 _002802_hash NULL
85258 +_002804_hash cmd_complete 6 51629 _002804_hash NULL
85259 +_002805_hash cmtp_add_msgpart 4 9252 _002805_hash NULL
85260 +_002806_hash cmtp_send_interopmsg 7 376 _002806_hash NULL
85261 +_002807_hash cxgb3_get_cpl_reply_skb 2 10620 _002807_hash NULL
85262 +_002808_hash dbg_leb_change 4 23555 _002808_hash NULL
85263 +_002809_hash dbg_leb_write 4-5 63555 _002809_hash &_000940_hash
85264 +_002811_hash dccp_listen_start 2 35918 _002811_hash NULL
85265 +_002812_hash __dev_alloc_skb 1 28681 _002812_hash NULL
85266 +_002813_hash diva_os_alloc_message_buffer 1 64568 _002813_hash NULL
85267 +_002814_hash dn_alloc_skb 2 6631 _002814_hash NULL
85268 +_002815_hash do_pselect 1 62061 _002815_hash NULL
85269 +_002816_hash _fc_frame_alloc 1 43568 _002816_hash NULL
85270 +_002817_hash find_skb 2 20431 _002817_hash NULL
85271 +_002818_hash fm_send_cmd 5 39639 _002818_hash NULL
85272 +_002819_hash gem_alloc_skb 2 51715 _002819_hash NULL
85273 +_002820_hash get_packet 3 41914 _002820_hash NULL
85274 +_002821_hash get_packet 3 5747 _002821_hash NULL
85275 +_002822_hash get_packet_pg 4 28023 _002822_hash NULL
85276 +_002823_hash get_skb 2 63008 _002823_hash NULL
85277 +_002824_hash hidp_queue_report 3 1881 _002824_hash NULL
85278 +_002825_hash __hidp_send_ctrl_message 4 28303 _002825_hash NULL
85279 +_002826_hash hycapi_rx_capipkt 3 11602 _002826_hash NULL
85280 +_002827_hash i2400m_net_rx 5 27170 _002827_hash NULL
85281 +_002828_hash igmpv3_newpack 2 35912 _002828_hash NULL
85282 +_002829_hash inet_listen 2 14723 _002829_hash NULL
85283 +_002830_hash isdn_net_ciscohdlck_alloc_skb 2 55209 _002830_hash &_001724_hash
85284 +_002831_hash isdn_ppp_ccp_xmit_reset 6 63297 _002831_hash NULL
85285 +_002832_hash kmsg_read 3 46514 _002832_hash NULL
85286 +_002833_hash _l2_alloc_skb 1 11883 _002833_hash NULL
85287 +_002834_hash l3_alloc_skb 1 32289 _002834_hash NULL
85288 +_002835_hash llc_alloc_frame 4 64366 _002835_hash NULL
85289 +_002836_hash mac_drv_rx_init 2 48898 _002836_hash &_002670_hash
85290 +_002837_hash mgmt_event 4 12810 _002837_hash NULL
85291 +_002838_hash mI_alloc_skb 1 24770 _002838_hash NULL
85292 +_002839_hash nci_skb_alloc 2 49757 _002839_hash NULL
85293 +_002840_hash netdev_alloc_skb 2 62437 _002840_hash NULL
85294 +_002841_hash __netdev_alloc_skb_ip_align 2 55067 _002841_hash NULL
85295 +_002842_hash new_skb 1 21148 _002842_hash NULL
85296 +_002843_hash nfc_alloc_recv_skb 1 10244 _002843_hash NULL
85297 +_002844_hash nfcwilink_skb_alloc 1 16167 _002844_hash NULL
85298 +_002845_hash nfulnl_alloc_skb 2 65207 _002845_hash NULL
85299 +_002846_hash ni65_alloc_mem 3 10664 _002846_hash NULL
85300 +_002847_hash pep_alloc_skb 3 46303 _002847_hash NULL
85301 +_002848_hash pn_raw_send 2 54330 _002848_hash NULL
85302 +_002849_hash __pskb_copy 2 9038 _002849_hash NULL
85303 +_002850_hash refill_pool 2 19477 _002850_hash NULL
85304 +_002851_hash rfcomm_wmalloc 2 58090 _002851_hash NULL
85305 +_002852_hash rx 4 57944 _002852_hash NULL
85306 +_002853_hash sctp_ulpevent_new 1 33377 _002853_hash NULL
85307 +_002854_hash send_command 4 10832 _002854_hash NULL
85308 +_002855_hash skb_copy_expand 2-3 7685 _002855_hash &_000671_hash
85309 +_002857_hash sk_stream_alloc_skb 2 57622 _002857_hash NULL
85310 +_002858_hash sock_alloc_send_pskb 2 21246 _002858_hash NULL
85311 +_002859_hash sock_rmalloc 2 59740 _002859_hash &_002157_hash
85312 +_002860_hash sock_wmalloc 2 16472 _002860_hash NULL
85313 +_002861_hash solos_param_store 4 34755 _002861_hash NULL
85314 +_002862_hash sys_select 1 38827 _002862_hash NULL
85315 +_002863_hash sys_syslog 3 10746 _002863_hash NULL
85316 +_002864_hash t4vf_pktgl_to_skb 2 39005 _002864_hash NULL
85317 +_002865_hash tcp_collapse 5-6 63294 _002865_hash NULL
85318 +_002867_hash tipc_cfg_reply_alloc 1 27606 _002867_hash NULL
85319 +_002868_hash ubifs_leb_change 4 17789 _002868_hash NULL
85320 +_002869_hash ubifs_leb_write 4-5 22679 _002869_hash NULL
85321 +_002871_hash ulog_alloc_skb 1 23427 _002871_hash NULL
85322 +_002872_hash _alloc_mISDN_skb 3 52232 _002872_hash NULL
85323 +_002873_hash ath9k_multi_regread 4 65056 _002873_hash NULL
85324 +_002874_hash ath_rxbuf_alloc 2 24745 _002874_hash NULL
85325 +_002875_hash ax25_send_frame 2 19964 _002875_hash NULL
85326 +_002876_hash bchannel_get_rxbuf 2 37213 _002876_hash NULL
85327 +_002877_hash cfpkt_create 1 18197 _002877_hash NULL
85328 +_002878_hash console_store 4 36007 _002878_hash NULL
85329 +_002879_hash dev_alloc_skb 1 19517 _002879_hash &_002797_hash
85330 +_002880_hash dn_nsp_do_disc 2-6 49474 _002880_hash NULL
85331 +_002882_hash do_write_orph_node 2 64343 _002882_hash NULL
85332 +_002883_hash dsp_cmx_send_member 2 15625 _002883_hash NULL
85333 +_002884_hash fc_frame_alloc 2 1596 _002884_hash NULL
85334 +_002885_hash fc_frame_alloc_fill 2 59394 _002885_hash NULL
85335 +_002886_hash fmc_send_cmd 5 20435 _002886_hash NULL
85336 +_002887_hash hci_send_cmd 3 43810 _002887_hash NULL
85337 +_002888_hash hci_si_event 3 1404 _002888_hash NULL
85338 +_002889_hash hfcpci_empty_bfifo 4 62323 _002889_hash NULL
85339 +_002890_hash hidp_send_ctrl_message 4 43702 _002890_hash NULL
85340 +_002891_hash hysdn_sched_rx 3 60533 _002891_hash NULL
85341 +_002892_hash inet_dccp_listen 2 28565 _002892_hash NULL
85342 +_002893_hash ip6_append_data 4-5 36490 _002893_hash NULL
85343 +_002894_hash __ip_append_data 7-8 36191 _002894_hash NULL
85344 +_002895_hash l1oip_socket_recv 6 56537 _002895_hash NULL
85345 +_002896_hash l2cap_build_cmd 4 48676 _002896_hash NULL
85346 +_002897_hash l2down_create 4 21755 _002897_hash NULL
85347 +_002898_hash l2up_create 3 6430 _002898_hash NULL
85348 +_002899_hash ldisc_receive 4 41516 _002899_hash NULL
85349 +_002902_hash lro_gen_skb 6 2644 _002902_hash NULL
85350 +_002903_hash macvtap_alloc_skb 2-4-3 50629 _002903_hash NULL
85351 +_002906_hash mgmt_device_found 10 14146 _002906_hash NULL
85352 +_002907_hash nci_send_cmd 3 58206 _002907_hash NULL
85353 +_002908_hash netdev_alloc_skb_ip_align 2 40811 _002908_hash NULL
85354 +_002909_hash nfcwilink_send_bts_cmd 3 10802 _002909_hash NULL
85355 +_002910_hash nfqnl_mangle 2 14583 _002910_hash NULL
85356 +_002911_hash p54_alloc_skb 3 34366 _002911_hash &_000475_hash
85357 +_002912_hash packet_alloc_skb 2-5-4 62602 _002912_hash NULL
85358 +_002915_hash pep_indicate 5 38611 _002915_hash NULL
85359 +_002916_hash pep_reply 5 50582 _002916_hash NULL
85360 +_002917_hash pipe_handler_request 5 50774 _002917_hash &_001189_hash
85361 +_002918_hash ql_process_mac_rx_page 4 15543 _002918_hash NULL
85362 +_002919_hash ql_process_mac_rx_skb 4 6689 _002919_hash NULL
85363 +_002920_hash rfcomm_tty_write 3 51603 _002920_hash NULL
85364 +_002921_hash send_mpa_reject 3 7135 _002921_hash NULL
85365 +_002922_hash send_mpa_reply 3 32372 _002922_hash NULL
85366 +_002923_hash set_rxd_buffer_pointer 8 9950 _002923_hash NULL
85367 +_002924_hash sge_rx 3 50594 _002924_hash NULL
85368 +_002925_hash skb_cow_data 2 11565 _002925_hash NULL
85369 +_002926_hash smp_build_cmd 3 45853 _002926_hash NULL
85370 +_002927_hash sock_alloc_send_skb 2 23720 _002927_hash NULL
85371 +_002928_hash sys_pselect6 1 57449 _002928_hash NULL
85372 +_002929_hash tcp_fragment 3 20436 _002929_hash NULL
85373 +_002930_hash teiup_create 3 43201 _002930_hash NULL
85374 +_002931_hash tg3_run_loopback 2 30093 _002931_hash NULL
85375 +_002932_hash tun_alloc_skb 2-4-3 41216 _002932_hash NULL
85376 +_002935_hash ubifs_write_node 5 11258 _002935_hash NULL
85377 +_002936_hash use_pool 2 64607 _002936_hash NULL
85378 +_002937_hash vxge_rx_alloc 3 52024 _002937_hash NULL
85379 +_002938_hash add_packet 3 54433 _002938_hash NULL
85380 +_002939_hash add_rx_skb 3 8257 _002939_hash NULL
85381 +_002940_hash ath6kl_buf_alloc 1 57304 _002940_hash NULL
85382 +_002941_hash bat_iv_ogm_aggregate_new 2 2620 _002941_hash NULL
85383 +_002942_hash bnx2fc_process_l2_frame_compl 3 65072 _002942_hash NULL
85384 +_002943_hash brcmu_pkt_buf_get_skb 1 5556 _002943_hash NULL
85385 +_002944_hash br_send_bpdu 3 29669 _002944_hash NULL
85386 +_002945_hash bt_skb_send_alloc 2 6581 _002945_hash NULL
85387 +_002946_hash c4iw_reject_cr 3 28174 _002946_hash NULL
85388 +_002947_hash carl9170_rx_copy_data 2 21656 _002947_hash NULL
85389 +_002948_hash cfpkt_add_body 3 44630 _002948_hash NULL
85390 +_002949_hash cfpkt_append 3 61206 _002949_hash NULL
85391 +_002950_hash cosa_net_setup_rx 2 38594 _002950_hash NULL
85392 +_002951_hash cxgb4_pktgl_to_skb 2 61899 _002951_hash NULL
85393 +_002952_hash dn_alloc_send_pskb 2 4465 _002952_hash NULL
85394 +_002953_hash dn_nsp_return_disc 2 60296 _002953_hash NULL
85395 +_002954_hash dn_nsp_send_disc 2 23469 _002954_hash NULL
85396 +_002955_hash dsp_tone_hw_message 3 17678 _002955_hash NULL
85397 +_002956_hash dvb_net_sec 3 37884 _002956_hash NULL
85398 +_002957_hash e1000_check_copybreak 3 62448 _002957_hash NULL
85399 +_002958_hash fast_rx_path 3 59214 _002958_hash NULL
85400 +_002959_hash fc_fcp_frame_alloc 2 12624 _002959_hash NULL
85401 +_002960_hash fcoe_ctlr_send_keep_alive 3 15308 _002960_hash NULL
85402 +_002961_hash fwnet_incoming_packet 3 40380 _002961_hash NULL
85403 +_002962_hash fwnet_pd_new 4 39947 _002962_hash NULL
85404 +_002963_hash got_frame 2 16028 _002963_hash NULL
85405 +_002964_hash gsm_mux_rx_netchar 3 33336 _002964_hash NULL
85406 +_002965_hash hdlcdev_rx 3 997 _002965_hash NULL
85407 +_002966_hash hdlc_empty_fifo 2 18397 _002966_hash NULL
85408 +_002967_hash hfc_empty_fifo 2 57972 _002967_hash NULL
85409 +_002968_hash hfcpci_empty_fifo 4 2427 _002968_hash NULL
85410 +_002969_hash hfcsusb_rx_frame 3 52745 _002969_hash NULL
85411 +_002970_hash hidp_output_raw_report 3 5629 _002970_hash NULL
85412 +_002971_hash hscx_empty_fifo 2 13360 _002971_hash NULL
85413 +_002972_hash hysdn_rx_netpkt 3 16136 _002972_hash NULL
85414 +_002973_hash ieee80211_fragment 4 33112 _002973_hash NULL
85415 +_002974_hash ieee80211_probereq_get 4-6 29069 _002974_hash NULL
85416 +_002976_hash ieee80211_send_auth 5 24121 _002976_hash NULL
85417 +_002977_hash ieee80211_set_probe_resp 3 10077 _002977_hash NULL
85418 +_002978_hash ieee80211_tdls_mgmt 8 9581 _002978_hash NULL
85419 +_002979_hash ip6_ufo_append_data 5-7-6 4780 _002979_hash NULL
85420 +_002982_hash ip_ufo_append_data 6-8-7 12775 _002982_hash NULL
85421 +_002985_hash ipw_packet_received_skb 2 1230 _002985_hash NULL
85422 +_002986_hash iwch_reject_cr 3 23901 _002986_hash NULL
85423 +_002987_hash iwm_rx_packet_alloc 3 9898 _002987_hash NULL
85424 +_002988_hash ixgb_check_copybreak 3 5847 _002988_hash NULL
85425 +_002989_hash l1oip_socket_parse 4 4507 _002989_hash NULL
85426 +_002990_hash l2cap_send_cmd 4 14548 _002990_hash NULL
85427 +_002991_hash l2tp_ip6_sendmsg 4 7461 _002991_hash NULL
85428 +_002993_hash lowpan_fragment_xmit 3-4 22095 _002993_hash NULL
85429 +_002996_hash mcs_unwrap_fir 3 25733 _002996_hash NULL
85430 +_002997_hash mcs_unwrap_mir 3 9455 _002997_hash NULL
85431 +_002998_hash mld_newpack 2 50950 _002998_hash NULL
85432 +_002999_hash nfc_alloc_send_skb 4 3167 _002999_hash NULL
85433 +_003000_hash p54_download_eeprom 4 43842 _003000_hash NULL
85434 +_003002_hash ppp_tx_cp 5 62044 _003002_hash NULL
85435 +_003003_hash prism2_send_mgmt 4 62605 _003003_hash &_001876_hash
85436 +_003004_hash prism2_sta_send_mgmt 5 43916 _003004_hash NULL
85437 +_003005_hash _queue_data 4 54983 _003005_hash NULL
85438 +_003006_hash read_dma 3 55086 _003006_hash NULL
85439 +_003007_hash read_fifo 3 826 _003007_hash NULL
85440 +_003008_hash receive_copy 3 12216 _003008_hash NULL
85441 +_003009_hash rtl8169_try_rx_copy 3 705 _003009_hash NULL
85442 +_003010_hash _rtl92s_firmware_downloadcode 3 14021 _003010_hash NULL
85443 +_003011_hash rx_data 4 60442 _003011_hash NULL
85444 +_003012_hash sis190_try_rx_copy 3 57069 _003012_hash NULL
85445 +_003013_hash skge_rx_get 3 40598 _003013_hash NULL
85446 +_003014_hash tcp_mark_head_lost 2 35895 _003014_hash NULL
85447 +_003015_hash tcp_match_skb_to_sack 3-4 23568 _003015_hash NULL
85448 +_003017_hash tso_fragment 3 29050 _003017_hash NULL
85449 +_003018_hash tt_response_fill_table 1 57902 _003018_hash NULL
85450 +_003020_hash udpv6_sendmsg 4 22316 _003020_hash NULL
85451 +_003021_hash velocity_rx_copy 2 34583 _003021_hash NULL
85452 +_003022_hash W6692_empty_Bfifo 2 47804 _003022_hash NULL
85453 +_003023_hash zd_mac_rx 3 38296 _003023_hash NULL
85454 +_003024_hash ath6kl_wmi_get_new_buf 1 52304 _003024_hash NULL
85455 +_003025_hash bat_iv_ogm_queue_add 3 30870 _003025_hash NULL
85456 +_003026_hash brcmf_alloc_pkt_and_read 2 63116 _003026_hash &_001808_hash
85457 +_003027_hash brcmf_sdcard_recv_buf 6 38179 _003027_hash NULL
85458 +_003028_hash brcmf_sdcard_rwdata 5 65041 _003028_hash NULL
85459 +_003029_hash brcmf_sdcard_send_buf 6 7713 _003029_hash NULL
85460 +_003030_hash carl9170_handle_mpdu 3 11056 _003030_hash NULL
85461 +_003031_hash cfpkt_add_trail 3 27260 _003031_hash NULL
85462 +_003032_hash cfpkt_pad_trail 2 55511 _003032_hash NULL
85463 +_003033_hash dvb_net_sec_callback 2 28786 _003033_hash NULL
85464 +_003034_hash fwnet_receive_packet 9 50537 _003034_hash NULL
85465 +_003035_hash handle_rx_packet 3 58993 _003035_hash NULL
85466 +_003036_hash HDLC_irq 2 8709 _003036_hash NULL
85467 +_003037_hash hdlc_rpr_irq 2 10240 _003037_hash NULL
85468 +_003043_hash ipwireless_network_packet_received 4 51277 _003043_hash NULL
85469 +_003044_hash l2cap_bredr_sig_cmd 3 49065 _003044_hash NULL
85470 +_003045_hash l2cap_sock_alloc_skb_cb 2 33532 _003045_hash NULL
85471 +_003046_hash llcp_allocate_pdu 3 19866 _003046_hash NULL
85472 +_003047_hash ppp_cp_event 6 2965 _003047_hash NULL
85473 +_003048_hash receive_client_update_packet 3 49104 _003048_hash NULL
85474 +_003049_hash receive_server_sync_packet 3 59021 _003049_hash NULL
85475 +_003050_hash sky2_receive 2 13407 _003050_hash NULL
85476 +_003051_hash tcp_sacktag_walk 5-6 49703 _003051_hash NULL
85477 +_003053_hash tcp_write_xmit 2 64602 _003053_hash NULL
85478 +_003054_hash ath6kl_wmi_add_wow_pattern_cmd 4 12842 _003054_hash NULL
85479 +_003055_hash ath6kl_wmi_beginscan_cmd 8 25462 _003055_hash NULL
85480 +_003056_hash ath6kl_wmi_send_probe_response_cmd 6 31728 _003056_hash NULL
85481 +_003057_hash ath6kl_wmi_set_appie_cmd 5 39266 _003057_hash NULL
85482 +_003058_hash ath6kl_wmi_set_ie_cmd 6 37260 _003058_hash NULL
85483 +_003059_hash ath6kl_wmi_startscan_cmd 8 33674 _003059_hash NULL
85484 +_003060_hash ath6kl_wmi_test_cmd 3 27312 _003060_hash NULL
85485 +_003061_hash brcmf_sdbrcm_membytes 3-5 37324 _003061_hash NULL
85486 +_003063_hash brcmf_sdbrcm_read_control 3 22721 _003063_hash NULL
85487 +_003064_hash brcmf_tx_frame 3 20978 _003064_hash NULL
85488 +_003065_hash __carl9170_rx 3 56784 _003065_hash NULL
85489 +_003066_hash cfpkt_setlen 2 49343 _003066_hash NULL
85490 +_003067_hash hdlc_irq_one 2 3944 _003067_hash NULL
85491 +_003069_hash tcp_push_one 2 48816 _003069_hash NULL
85492 +_003070_hash __tcp_push_pending_frames 2 48148 _003070_hash NULL
85493 +_003071_hash brcmf_sdbrcm_bus_txctl 3 42492 _003071_hash NULL
85494 +_003072_hash carl9170_rx 3 13272 _003072_hash NULL
85495 +_003073_hash carl9170_rx_stream 3 1334 _003073_hash NULL
85496 +_003074_hash tcp_push 3 10680 _003074_hash NULL
85497 +_003075_hash create_log 2 8225 _003075_hash NULL
85498 +_003076_hash expand_files 2 17080 _003076_hash NULL
85499 +_003077_hash iio_device_alloc 1 41440 _003077_hash NULL
85500 +_003078_hash OS_mem_token_alloc 1 14276 _003078_hash NULL
85501 +_003079_hash packet_came 3 18072 _003079_hash NULL
85502 +_003080_hash softsynth_write 3 3455 _003080_hash NULL
85503 +_003081_hash alloc_fd 1 37637 _003081_hash NULL
85504 +_003082_hash sys_dup3 2 33421 _003082_hash NULL
85505 +_003083_hash do_fcntl 3 31468 _003083_hash NULL
85506 +_003084_hash sys_dup2 2 25284 _003084_hash NULL
85507 +_003085_hash sys_fcntl 3 19267 _003085_hash NULL
85508 +_003086_hash sys_fcntl64 3 29031 _003086_hash NULL
85509 +_003087_hash cmpk_message_handle_tx 4 54024 _003087_hash NULL
85510 +_003088_hash comedi_buf_alloc 3 24822 _003088_hash NULL
85511 +_003089_hash compat_rw_copy_check_uvector 3 22001 _003089_hash &_001989_hash
85512 +_003090_hash compat_sys_fcntl64 3 60256 _003090_hash NULL
85513 +_003091_hash evtchn_write 3 43278 _003091_hash NULL
85514 +_003092_hash fw_download_code 3 13249 _003092_hash NULL
85515 +_003093_hash fwSendNullPacket 2 54618 _003093_hash NULL
85516 +_003095_hash ieee80211_authentication_req 3 63973 _003095_hash NULL
85517 +_003097_hash rtllib_authentication_req 3 26713 _003097_hash NULL
85518 +_003098_hash SendTxCommandPacket 3 42901 _003098_hash NULL
85519 +_003099_hash snd_nm256_capture_copy 5 28622 _003099_hash NULL
85520 +_003100_hash snd_nm256_playback_copy 5 38567 _003100_hash NULL
85521 +_003101_hash tomoyo_init_log 2 14806 _003101_hash NULL
85522 +_003102_hash usbdux_attach_common 4 51764 _003102_hash NULL
85523 +_003103_hash compat_sys_fcntl 3 15654 _003103_hash NULL
85524 +_003104_hash ieee80211_auth_challenge 3 18810 _003104_hash NULL
85525 +_003105_hash ieee80211_rtl_auth_challenge 3 61897 _003105_hash NULL
85526 +_003106_hash resize_async_buffer 4 64031 _003106_hash &_002119_hash
85527 +_003107_hash rtllib_auth_challenge 3 12493 _003107_hash NULL
85528 +_003108_hash tomoyo_write_log2 2 11732 _003108_hash NULL
85529 +_003109_hash allocate_probes 1 40204 _003109_hash NULL
85530 +_003110_hash alloc_ftrace_hash 1 57431 _003110_hash &_002532_hash
85531 +_003111_hash __alloc_preds 2 9492 _003111_hash NULL
85532 +_003112_hash __alloc_pred_stack 2 26687 _003112_hash NULL
85533 +_003113_hash alloc_sched_domains 1 47756 _003113_hash NULL
85534 +_003114_hash alloc_trace_probe 6 38720 _003114_hash NULL
85535 +_003115_hash alloc_trace_uprobe 3 13870 _003115_hash NULL
85536 +_003116_hash arcfb_write 3 8702 _003116_hash NULL
85537 +_003117_hash ath6kl_sdio_alloc_prep_scat_req 2 51986 _003117_hash NULL
85538 +_003118_hash ath6kl_usb_post_recv_transfers 2 32892 _003118_hash NULL
85539 +_003119_hash ath6kl_usb_submit_ctrl_in 6 32880 _003119_hash &_000778_hash
85540 +_003120_hash ath6kl_usb_submit_ctrl_out 6 9978 _003120_hash NULL
85541 +_003121_hash auok190xfb_write 3 37001 _003121_hash NULL
85542 +_003122_hash beacon_interval_write 3 17952 _003122_hash NULL
85543 +_003123_hash blk_dropped_read 3 4168 _003123_hash NULL
85544 +_003124_hash blk_msg_write 3 13655 _003124_hash NULL
85545 +_003125_hash brcmf_usbdev_qinit 2 19090 _003125_hash &_001533_hash
85546 +_003126_hash brcmf_usb_dl_cmd 4 53130 _003126_hash NULL
85547 +_003127_hash broadsheetfb_write 3 39976 _003127_hash NULL
85548 +_003128_hash broadsheet_spiflash_rewrite_sector 2 54864 _003128_hash NULL
85549 +_003129_hash cyttsp_probe 4 1940 _003129_hash NULL
85550 +_003130_hash da9052_group_write 3 4534 _003130_hash NULL
85551 +_003131_hash dccpprobe_read 3 52549 _003131_hash NULL
85552 +_003132_hash drm_property_create_bitmask 5 30195 _003132_hash NULL
85553 +_003133_hash dtim_interval_write 3 30489 _003133_hash NULL
85554 +_003134_hash dynamic_ps_timeout_write 3 37713 _003134_hash NULL
85555 +_003135_hash event_enable_read 3 7074 _003135_hash NULL
85556 +_003136_hash event_enable_write 3 45238 _003136_hash NULL
85557 +_003137_hash event_filter_read 3 23494 _003137_hash NULL
85558 +_003138_hash event_filter_write 3 56609 _003138_hash NULL
85559 +_003139_hash event_id_read 3 64288 _003139_hash &_001240_hash
85560 +_003140_hash f_audio_buffer_alloc 1 41110 _003140_hash NULL
85561 +_003141_hash fb_sys_read 3 13778 _003141_hash NULL
85562 +_003142_hash fb_sys_write 3 33130 _003142_hash NULL
85563 +_003143_hash forced_ps_write 3 37209 _003143_hash NULL
85564 +_003144_hash __fprog_create 2 41263 _003144_hash NULL
85565 +_003145_hash fq_codel_zalloc 1 15378 _003145_hash NULL
85566 +_003146_hash ftrace_pid_write 3 39710 _003146_hash NULL
85567 +_003147_hash ftrace_profile_read 3 21327 _003147_hash NULL
85568 +_003148_hash ftrace_profile_write 3 53327 _003148_hash NULL
85569 +_003149_hash ftrace_write 3 29551 _003149_hash NULL
85570 +_003150_hash gdm_wimax_netif_rx 3 43423 _003150_hash &_001619_hash
85571 +_003151_hash gpio_power_write 3 1991 _003151_hash NULL
85572 +_003152_hash hecubafb_write 3 26942 _003152_hash NULL
85573 +_003153_hash hsc_msg_alloc 1 60990 _003153_hash NULL
85574 +_003154_hash hsc_write 3 55875 _003154_hash NULL
85575 +_003155_hash hsi_alloc_controller 1 41802 _003155_hash NULL
85576 +_003156_hash hsi_register_board_info 2 13820 _003156_hash NULL
85577 +_003157_hash i915_ring_stop_read 3 42549 _003157_hash NULL
85578 +_003158_hash i915_ring_stop_write 3 59010 _003158_hash NULL
85579 +_003159_hash ieee802154_alloc_device 1 13767 _003159_hash NULL
85580 +_003160_hash intel_sdvo_write_cmd 4 54377 _003160_hash &_000815_hash
85581 +_003161_hash ivtvfb_write 3 40023 _003161_hash NULL
85582 +_003162_hash metronomefb_write 3 8823 _003162_hash NULL
85583 +_003163_hash mwifiex_usb_submit_rx_urb 2 54558 _003163_hash NULL
85584 +_003164_hash nfc_hci_hcp_message_tx 6 14534 _003164_hash NULL
85585 +_003165_hash nfc_hci_set_param 5 40697 _003165_hash NULL
85586 +_003166_hash nfc_shdlc_alloc_skb 2 12741 _003166_hash NULL
85587 +_003167_hash odev_update 2 50169 _003167_hash NULL
85588 +_003168_hash oz_add_farewell 5 20652 _003168_hash NULL
85589 +_003169_hash oz_cdev_read 3 20659 _003169_hash NULL
85590 +_003170_hash oz_cdev_write 3 33852 _003170_hash NULL
85591 +_003171_hash oz_ep_alloc 2 5587 _003171_hash NULL
85592 +_003172_hash oz_events_read 3 47535 _003172_hash NULL
85593 +_003173_hash pmcraid_copy_sglist 3 38431 _003173_hash NULL
85594 +_003174_hash prctl_set_mm 3 64538 _003174_hash NULL
85595 +_003175_hash ptp_filter_init 2 36780 _003175_hash NULL
85596 +_003176_hash rb_simple_read 3 45972 _003176_hash NULL
85597 +_003177_hash rb_simple_write 3 20890 _003177_hash NULL
85598 +_003178_hash read_file_dfs 3 43145 _003178_hash NULL
85599 +_003179_hash rx_streaming_always_write 3 32357 _003179_hash NULL
85600 +_003180_hash rx_streaming_interval_write 3 50120 _003180_hash NULL
85601 +_003181_hash shmem_pread_fast 3 34147 _003181_hash NULL
85602 +_003182_hash shmem_pread_slow 3 3198 _003182_hash NULL
85603 +_003183_hash shmem_pwrite_fast 3 46842 _003183_hash NULL
85604 +_003184_hash shmem_pwrite_slow 3 31741 _003184_hash NULL
85605 +_003185_hash show_header 3 4722 _003185_hash &_000736_hash
85606 +_003186_hash split_scan_timeout_write 3 52128 _003186_hash NULL
85607 +_003187_hash stack_max_size_read 3 1445 _003187_hash NULL
85608 +_003188_hash stack_max_size_write 3 36068 _003188_hash NULL
85609 +_003189_hash subsystem_filter_read 3 62310 _003189_hash NULL
85610 +_003190_hash subsystem_filter_write 3 13022 _003190_hash NULL
85611 +_003191_hash suspend_dtim_interval_write 3 48854 _003191_hash NULL
85612 +_003192_hash system_enable_read 3 25815 _003192_hash NULL
85613 +_003193_hash system_enable_write 3 61396 _003193_hash NULL
85614 +_003194_hash trace_options_core_read 3 47390 _003194_hash NULL
85615 +_003195_hash trace_options_core_write 3 61551 _003195_hash NULL
85616 +_003196_hash trace_options_read 3 11419 _003196_hash NULL
85617 +_003197_hash trace_options_write 3 48275 _003197_hash NULL
85618 +_003198_hash trace_parser_get_init 2 31379 _003198_hash NULL
85619 +_003199_hash traceprobe_probes_write 3 64969 _003199_hash NULL
85620 +_003200_hash trace_seq_to_user 3 65398 _003200_hash NULL
85621 +_003201_hash tracing_buffers_read 3 11124 _003201_hash NULL
85622 +_003202_hash tracing_clock_write 3 27961 _003202_hash NULL
85623 +_003203_hash tracing_cpumask_read 3 7010 _003203_hash NULL
85624 +_003204_hash tracing_ctrl_read 3 46922 _003204_hash NULL
85625 +_003205_hash tracing_ctrl_write 3 42324 _003205_hash &_001726_hash
85626 +_003206_hash tracing_entries_read 3 8345 _003206_hash NULL
85627 +_003207_hash tracing_entries_write 3 60563 _003207_hash NULL
85628 +_003208_hash tracing_max_lat_read 3 8890 _003208_hash NULL
85629 +_003209_hash tracing_max_lat_write 3 8728 _003209_hash NULL
85630 +_003210_hash tracing_read_dyn_info 3 45468 _003210_hash NULL
85631 +_003211_hash tracing_readme_read 3 16493 _003211_hash NULL
85632 +_003212_hash tracing_saved_cmdlines_read 3 21434 _003212_hash NULL
85633 +_003213_hash tracing_set_trace_read 3 44122 _003213_hash NULL
85634 +_003214_hash tracing_set_trace_write 3 57096 _003214_hash NULL
85635 +_003215_hash tracing_stats_read 3 34537 _003215_hash NULL
85636 +_003216_hash tracing_total_entries_read 3 62817 _003216_hash NULL
85637 +_003217_hash tracing_trace_options_write 3 153 _003217_hash NULL
85638 +_003218_hash ttm_put_pages 2 9179 _003218_hash NULL
85639 +_003219_hash udl_prime_create 2 57159 _003219_hash NULL
85640 +_003220_hash ufx_alloc_urb_list 3 10349 _003220_hash NULL
85641 +_003221_hash u_memcpya 2-3 30139 _003221_hash NULL
85642 +_003223_hash viafb_dfph_proc_write 3 49288 _003223_hash NULL
85643 +_003224_hash viafb_dfpl_proc_write 3 627 _003224_hash NULL
85644 +_003225_hash viafb_dvp0_proc_write 3 23023 _003225_hash NULL
85645 +_003226_hash viafb_dvp1_proc_write 3 48864 _003226_hash NULL
85646 +_003227_hash viafb_vt1636_proc_write 3 16018 _003227_hash NULL
85647 +_003228_hash vivi_read 3 23073 _003228_hash NULL
85648 +_003229_hash wl1271_rx_filter_alloc_field 5 46721 _003229_hash NULL
85649 +_003230_hash wl12xx_cmd_build_probe_req 6-8 3098 _003230_hash NULL
85650 +_003232_hash wlcore_alloc_hw 1 7785 _003232_hash NULL
85651 +_003233_hash alloc_and_copy_ftrace_hash 1 29368 _003233_hash NULL
85652 +_003234_hash create_trace_probe 1 20175 _003234_hash NULL
85653 +_003235_hash create_trace_uprobe 1 13184 _003235_hash NULL
85654 +_003236_hash intel_sdvo_set_value 4 2311 _003236_hash NULL
85655 +_003237_hash mmio_read 4 40348 _003237_hash NULL
85656 +_003238_hash nfc_hci_execute_cmd 5 43882 _003238_hash NULL
85657 +_003239_hash nfc_hci_send_event 5 21452 _003239_hash NULL
85658 +_003240_hash nfc_hci_send_response 5 56462 _003240_hash NULL
85659 +_003241_hash picolcd_fb_write 3 2318 _003241_hash NULL
85660 +_003242_hash probes_write 3 29711 _003242_hash NULL
85661 +_003243_hash sys_prctl 4 8766 _003243_hash NULL
85662 +_003244_hash tracing_read_pipe 3 35312 _003244_hash NULL
85663 +_003245_hash brcmf_usb_attach 1-2 44656 _003245_hash NULL
85664 +_003247_hash dlfb_ops_write 3 64150 _003247_hash NULL
85665 +_003248_hash nfc_hci_send_cmd 5 55714 _003248_hash NULL
85666 +_003249_hash ufx_ops_write 3 54848 _003249_hash NULL
85667 +_003250_hash viafb_iga1_odev_proc_write 3 36241 _003250_hash NULL
85668 +_003251_hash viafb_iga2_odev_proc_write 3 2363 _003251_hash NULL
85669 +_003252_hash xenfb_write 3 43412 _003252_hash NULL
85670 +_003253_hash acl_alloc 1 35979 _003253_hash NULL
85671 +_003254_hash acl_alloc_stack_init 1 60630 _003254_hash NULL
85672 +_003255_hash acl_alloc_num 1-2 60778 _003255_hash NULL
85673 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
85674 new file mode 100644
85675 index 0000000..5af42b5
85676 --- /dev/null
85677 +++ b/tools/gcc/size_overflow_plugin.c
85678 @@ -0,0 +1,1558 @@
85679 +/*
85680 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
85681 + * Licensed under the GPL v2, or (at your option) v3
85682 + *
85683 + * Homepage:
85684 + * http://www.grsecurity.net/~ephox/overflow_plugin/
85685 + *
85686 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
85687 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
85688 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
85689 + *
85690 + * Usage:
85691 + * $ 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
85692 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
85693 + */
85694 +
85695 +#include "gcc-plugin.h"
85696 +#include "config.h"
85697 +#include "system.h"
85698 +#include "coretypes.h"
85699 +#include "tree.h"
85700 +#include "tree-pass.h"
85701 +#include "intl.h"
85702 +#include "plugin-version.h"
85703 +#include "tm.h"
85704 +#include "toplev.h"
85705 +#include "function.h"
85706 +#include "tree-flow.h"
85707 +#include "plugin.h"
85708 +#include "gimple.h"
85709 +#include "c-common.h"
85710 +#include "diagnostic.h"
85711 +#include "cfgloop.h"
85712 +
85713 +struct size_overflow_hash {
85714 + struct size_overflow_hash *next;
85715 + const char *name;
85716 + unsigned int param;
85717 +};
85718 +
85719 +#include "size_overflow_hash.h"
85720 +
85721 +#define __unused __attribute__((__unused__))
85722 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
85723 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
85724 +#define BEFORE_STMT true
85725 +#define AFTER_STMT false
85726 +#define CREATE_NEW_VAR NULL_TREE
85727 +#define CODES_LIMIT 32
85728 +#define MAX_PARAM 10
85729 +#define MY_STMT GF_PLF_1
85730 +#define NO_CAST_CHECK GF_PLF_2
85731 +
85732 +#if BUILDING_GCC_VERSION == 4005
85733 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
85734 +#endif
85735 +
85736 +int plugin_is_GPL_compatible;
85737 +void debug_gimple_stmt(gimple gs);
85738 +
85739 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var);
85740 +static tree report_size_overflow_decl;
85741 +static tree const_char_ptr_type_node;
85742 +static unsigned int handle_function(void);
85743 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool *potentionally_overflowed, bool before);
85744 +static tree get_size_overflow_type(gimple stmt, tree node);
85745 +
85746 +static struct plugin_info size_overflow_plugin_info = {
85747 + .version = "20120811beta",
85748 + .help = "no-size-overflow\tturn off size overflow checking\n",
85749 +};
85750 +
85751 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
85752 +{
85753 + unsigned int arg_count;
85754 +
85755 + if (TREE_CODE(*node) == FUNCTION_DECL)
85756 + arg_count = type_num_arguments(TREE_TYPE(*node));
85757 + else if (TREE_CODE(*node) == FUNCTION_TYPE || TREE_CODE(*node) == METHOD_TYPE)
85758 + arg_count = type_num_arguments(*node);
85759 + else {
85760 + *no_add_attrs = true;
85761 + error("%qE attribute only applies to functions", name);
85762 + return NULL_TREE;
85763 + }
85764 +
85765 + for (; args; args = TREE_CHAIN(args)) {
85766 + tree position = TREE_VALUE(args);
85767 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
85768 + error("handle_size_overflow_attribute: overflow parameter outside range.");
85769 + *no_add_attrs = true;
85770 + }
85771 + }
85772 + return NULL_TREE;
85773 +}
85774 +
85775 +static struct attribute_spec size_overflow_attr = {
85776 + .name = "size_overflow",
85777 + .min_length = 1,
85778 + .max_length = -1,
85779 + .decl_required = true,
85780 + .type_required = false,
85781 + .function_type_required = false,
85782 + .handler = handle_size_overflow_attribute,
85783 +#if BUILDING_GCC_VERSION >= 4007
85784 + .affects_type_identity = false
85785 +#endif
85786 +};
85787 +
85788 +static void register_attributes(void __unused *event_data, void __unused *data)
85789 +{
85790 + register_attribute(&size_overflow_attr);
85791 +}
85792 +
85793 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
85794 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
85795 +{
85796 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
85797 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
85798 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
85799 +
85800 + const unsigned int m = 0x57559429;
85801 + const unsigned int n = 0x5052acdb;
85802 + const unsigned int *key4 = (const unsigned int *)key;
85803 + unsigned int h = len;
85804 + unsigned int k = len + seed + n;
85805 + unsigned long long p;
85806 +
85807 + while (len >= 8) {
85808 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
85809 + len -= 8;
85810 + }
85811 + if (len >= 4) {
85812 + cwmixb(key4[0]) key4 += 1;
85813 + len -= 4;
85814 + }
85815 + if (len)
85816 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
85817 + cwmixb(h ^ (k + n));
85818 + return k ^ h;
85819 +
85820 +#undef cwfold
85821 +#undef cwmixa
85822 +#undef cwmixb
85823 +}
85824 +
85825 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
85826 +{
85827 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
85828 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
85829 + return fn ^ codes;
85830 +}
85831 +
85832 +static inline tree get_original_function_decl(tree fndecl)
85833 +{
85834 + if (DECL_ABSTRACT_ORIGIN(fndecl))
85835 + return DECL_ABSTRACT_ORIGIN(fndecl);
85836 + return fndecl;
85837 +}
85838 +
85839 +static inline gimple get_def_stmt(tree node)
85840 +{
85841 + gcc_assert(node != NULL_TREE);
85842 + gcc_assert(TREE_CODE(node) == SSA_NAME);
85843 + return SSA_NAME_DEF_STMT(node);
85844 +}
85845 +
85846 +static unsigned char get_tree_code(tree type)
85847 +{
85848 + switch (TREE_CODE(type)) {
85849 + case ARRAY_TYPE:
85850 + return 0;
85851 + case BOOLEAN_TYPE:
85852 + return 1;
85853 + case ENUMERAL_TYPE:
85854 + return 2;
85855 + case FUNCTION_TYPE:
85856 + return 3;
85857 + case INTEGER_TYPE:
85858 + return 4;
85859 + case POINTER_TYPE:
85860 + return 5;
85861 + case RECORD_TYPE:
85862 + return 6;
85863 + case UNION_TYPE:
85864 + return 7;
85865 + case VOID_TYPE:
85866 + return 8;
85867 + case REAL_TYPE:
85868 + return 9;
85869 + case VECTOR_TYPE:
85870 + return 10;
85871 + case REFERENCE_TYPE:
85872 + return 11;
85873 + default:
85874 + debug_tree(type);
85875 + gcc_unreachable();
85876 + }
85877 +}
85878 +
85879 +static size_t add_type_codes(tree type, unsigned char *tree_codes, size_t len)
85880 +{
85881 + gcc_assert(type != NULL_TREE);
85882 +
85883 + while (type && len < CODES_LIMIT) {
85884 + tree_codes[len] = get_tree_code(type);
85885 + len++;
85886 + type = TREE_TYPE(type);
85887 + }
85888 + return len;
85889 +}
85890 +
85891 +static unsigned int get_function_decl(tree fndecl, unsigned char *tree_codes)
85892 +{
85893 + tree arg, result, type = TREE_TYPE(fndecl);
85894 + enum tree_code code = TREE_CODE(type);
85895 + size_t len = 0;
85896 +
85897 + gcc_assert(code == FUNCTION_TYPE);
85898 +
85899 + arg = TYPE_ARG_TYPES(type);
85900 + // skip builtins __builtin_constant_p
85901 + if (!arg && DECL_BUILT_IN(fndecl))
85902 + return 0;
85903 + gcc_assert(arg != NULL_TREE);
85904 +
85905 + if (TREE_CODE_CLASS(code) == tcc_type)
85906 + result = type;
85907 + else
85908 + result = DECL_RESULT(fndecl);
85909 +
85910 + gcc_assert(result != NULL_TREE);
85911 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
85912 +
85913 + while (arg && len < CODES_LIMIT) {
85914 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
85915 + arg = TREE_CHAIN(arg);
85916 + }
85917 +
85918 + gcc_assert(len != 0);
85919 + return len;
85920 +}
85921 +
85922 +static struct size_overflow_hash *get_function_hash(tree fndecl)
85923 +{
85924 + unsigned int hash;
85925 + struct size_overflow_hash *entry;
85926 + unsigned char tree_codes[CODES_LIMIT];
85927 + size_t len;
85928 + const char *func_name = NAME(fndecl);
85929 +
85930 + len = get_function_decl(fndecl, tree_codes);
85931 + if (len == 0)
85932 + return NULL;
85933 +
85934 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
85935 +
85936 + entry = size_overflow_hash[hash];
85937 + while (entry) {
85938 + if (!strcmp(entry->name, func_name))
85939 + return entry;
85940 + entry = entry->next;
85941 + }
85942 +
85943 + return NULL;
85944 +}
85945 +
85946 +static void check_arg_type(tree var)
85947 +{
85948 + tree type = TREE_TYPE(var);
85949 + enum tree_code code = TREE_CODE(type);
85950 +
85951 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
85952 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
85953 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
85954 +}
85955 +
85956 +static int find_arg_number(tree arg, tree func)
85957 +{
85958 + tree var;
85959 + bool match = false;
85960 + unsigned int argnum = 1;
85961 +
85962 + if (TREE_CODE(arg) == SSA_NAME)
85963 + arg = SSA_NAME_VAR(arg);
85964 +
85965 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
85966 + if (strcmp(NAME(arg), NAME(var))) {
85967 + argnum++;
85968 + continue;
85969 + }
85970 + check_arg_type(var);
85971 +
85972 + match = true;
85973 + break;
85974 + }
85975 + if (!match) {
85976 + warning(0, "find_arg_number: cannot find the %s argument in %s", NAME(arg), NAME(func));
85977 + return 0;
85978 + }
85979 + return argnum;
85980 +}
85981 +
85982 +static void print_missing_msg(tree func, unsigned int argnum)
85983 +{
85984 + unsigned int new_hash;
85985 + size_t len;
85986 + unsigned char tree_codes[CODES_LIMIT];
85987 + location_t loc = DECL_SOURCE_LOCATION(func);
85988 + const char *curfunc = NAME(func);
85989 +
85990 + len = get_function_decl(func, tree_codes);
85991 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
85992 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%d+%u+", curfunc, curfunc, argnum, new_hash);
85993 +}
85994 +
85995 +static void check_missing_attribute(tree arg)
85996 +{
85997 + tree type, func = get_original_function_decl(current_function_decl);
85998 + unsigned int argnum;
85999 + struct size_overflow_hash *hash;
86000 +
86001 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
86002 +
86003 + type = TREE_TYPE(arg);
86004 +
86005 + if (TREE_CODE(type) == POINTER_TYPE)
86006 + return;
86007 +
86008 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
86009 + return;
86010 +
86011 + argnum = find_arg_number(arg, func);
86012 + if (argnum == 0)
86013 + return;
86014 +
86015 + hash = get_function_hash(func);
86016 + if (!hash || !(hash->param & (1U << argnum)))
86017 + print_missing_msg(func, argnum);
86018 +}
86019 +
86020 +static tree create_new_var(tree type)
86021 +{
86022 + tree new_var = create_tmp_var(type, "cicus");
86023 +
86024 + add_referenced_var(new_var);
86025 + mark_sym_for_renaming(new_var);
86026 + return new_var;
86027 +}
86028 +
86029 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
86030 +{
86031 + gimple assign;
86032 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
86033 + tree type = TREE_TYPE(rhs1);
86034 + tree lhs = create_new_var(type);
86035 +
86036 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
86037 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
86038 +
86039 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
86040 + update_stmt(assign);
86041 + gimple_set_plf(assign, MY_STMT, true);
86042 + return assign;
86043 +}
86044 +
86045 +static bool is_bool(tree node)
86046 +{
86047 + tree type;
86048 +
86049 + if (node == NULL_TREE)
86050 + return false;
86051 +
86052 + type = TREE_TYPE(node);
86053 + if (!INTEGRAL_TYPE_P(type))
86054 + return false;
86055 + if (TREE_CODE(type) == BOOLEAN_TYPE)
86056 + return true;
86057 + if (TYPE_PRECISION(type) == 1)
86058 + return true;
86059 + return false;
86060 +}
86061 +
86062 +static tree cast_a_tree(tree type, tree var)
86063 +{
86064 + gcc_assert(type != NULL_TREE);
86065 + gcc_assert(var != NULL_TREE);
86066 + gcc_assert(fold_convertible_p(type, var));
86067 +
86068 + return fold_convert(type, var);
86069 +}
86070 +
86071 +static gimple build_cast_stmt(tree type, tree var, tree new_var, gimple_stmt_iterator *gsi, bool before)
86072 +{
86073 + gimple assign;
86074 + location_t loc;
86075 +
86076 + gcc_assert(type != NULL_TREE && var != NULL_TREE);
86077 + if (gsi_end_p(*gsi) && before == BEFORE_STMT)
86078 + gcc_unreachable();
86079 +
86080 + if (new_var == CREATE_NEW_VAR)
86081 + new_var = create_new_var(type);
86082 +
86083 + assign = gimple_build_assign(new_var, cast_a_tree(type, var));
86084 +
86085 + if (!gsi_end_p(*gsi)) {
86086 + loc = gimple_location(gsi_stmt(*gsi));
86087 + gimple_set_location(assign, loc);
86088 + }
86089 +
86090 + gimple_set_lhs(assign, make_ssa_name(new_var, assign));
86091 +
86092 + if (before)
86093 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
86094 + else
86095 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
86096 + update_stmt(assign);
86097 + gimple_set_plf(assign, MY_STMT, true);
86098 +
86099 + return assign;
86100 +}
86101 +
86102 +static tree cast_to_new_size_overflow_type(gimple stmt, tree new_rhs1, tree size_overflow_type, bool before)
86103 +{
86104 + gimple assign;
86105 + gimple_stmt_iterator gsi;
86106 +
86107 + if (new_rhs1 == NULL_TREE)
86108 + return NULL_TREE;
86109 +
86110 + if (!useless_type_conversion_p(TREE_TYPE(new_rhs1), size_overflow_type)) {
86111 + gsi = gsi_for_stmt(stmt);
86112 + assign = build_cast_stmt(size_overflow_type, new_rhs1, CREATE_NEW_VAR, &gsi, before);
86113 + return gimple_get_lhs(assign);
86114 + }
86115 + return new_rhs1;
86116 +}
86117 +
86118 +static tree create_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, bool before)
86119 +{
86120 + tree oldstmt_rhs1, size_overflow_type, lhs;
86121 + enum tree_code code;
86122 + gimple stmt;
86123 + gimple_stmt_iterator gsi;
86124 +
86125 + if (!*potentionally_overflowed)
86126 + return NULL_TREE;
86127 +
86128 + if (rhs1 == NULL_TREE) {
86129 + debug_gimple_stmt(oldstmt);
86130 + error("create_assign: rhs1 is NULL_TREE");
86131 + gcc_unreachable();
86132 + }
86133 +
86134 + if (gimple_code(oldstmt) == GIMPLE_ASM)
86135 + lhs = rhs1;
86136 + else
86137 + lhs = gimple_get_lhs(oldstmt);
86138 +
86139 + oldstmt_rhs1 = gimple_assign_rhs1(oldstmt);
86140 + code = TREE_CODE(oldstmt_rhs1);
86141 + if (code == PARM_DECL || (code == SSA_NAME && gimple_code(get_def_stmt(oldstmt_rhs1)) == GIMPLE_NOP))
86142 + check_missing_attribute(oldstmt_rhs1);
86143 +
86144 + gsi = gsi_for_stmt(oldstmt);
86145 + pointer_set_insert(visited, oldstmt);
86146 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
86147 + basic_block next_bb, cur_bb;
86148 + edge e;
86149 +
86150 + gcc_assert(before == false);
86151 + gcc_assert(stmt_can_throw_internal(oldstmt));
86152 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
86153 + gcc_assert(!gsi_end_p(gsi));
86154 +
86155 + cur_bb = gimple_bb(oldstmt);
86156 + next_bb = cur_bb->next_bb;
86157 + e = find_edge(cur_bb, next_bb);
86158 + gcc_assert(e != NULL);
86159 + gcc_assert(e->flags & EDGE_FALLTHRU);
86160 +
86161 + gsi = gsi_after_labels(next_bb);
86162 + gcc_assert(!gsi_end_p(gsi));
86163 +
86164 + before = true;
86165 + oldstmt = gsi_stmt(gsi);
86166 + pointer_set_insert(visited, oldstmt);
86167 + }
86168 +
86169 + size_overflow_type = get_size_overflow_type(oldstmt, lhs);
86170 +
86171 + stmt = build_cast_stmt(size_overflow_type, rhs1, CREATE_NEW_VAR, &gsi, before);
86172 + gimple_set_plf(stmt, MY_STMT, true);
86173 + return gimple_get_lhs(stmt);
86174 +}
86175 +
86176 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3)
86177 +{
86178 + tree new_var, lhs = gimple_get_lhs(oldstmt);
86179 + gimple stmt;
86180 + gimple_stmt_iterator gsi;
86181 +
86182 + if (!*potentionally_overflowed)
86183 + return NULL_TREE;
86184 +
86185 + if (gimple_plf(oldstmt, MY_STMT))
86186 + return lhs;
86187 +
86188 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
86189 + rhs1 = gimple_assign_rhs1(oldstmt);
86190 + rhs1 = create_assign(visited, potentionally_overflowed, oldstmt, rhs1, BEFORE_STMT);
86191 + }
86192 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
86193 + rhs2 = gimple_assign_rhs2(oldstmt);
86194 + rhs2 = create_assign(visited, potentionally_overflowed, oldstmt, rhs2, BEFORE_STMT);
86195 + }
86196 +
86197 + stmt = gimple_copy(oldstmt);
86198 + gimple_set_location(stmt, gimple_location(oldstmt));
86199 + gimple_set_plf(stmt, MY_STMT, true);
86200 +
86201 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
86202 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
86203 +
86204 + if (is_bool(lhs))
86205 + new_var = SSA_NAME_VAR(lhs);
86206 + else
86207 + new_var = create_new_var(size_overflow_type);
86208 + new_var = make_ssa_name(new_var, stmt);
86209 + gimple_set_lhs(stmt, new_var);
86210 +
86211 + if (rhs1 != NULL_TREE) {
86212 + if (!gimple_assign_cast_p(oldstmt))
86213 + rhs1 = cast_a_tree(size_overflow_type, rhs1);
86214 + gimple_assign_set_rhs1(stmt, rhs1);
86215 + }
86216 +
86217 + if (rhs2 != NULL_TREE)
86218 + gimple_assign_set_rhs2(stmt, rhs2);
86219 +#if BUILDING_GCC_VERSION >= 4007
86220 + if (rhs3 != NULL_TREE)
86221 + gimple_assign_set_rhs3(stmt, rhs3);
86222 +#endif
86223 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
86224 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
86225 +
86226 + gsi = gsi_for_stmt(oldstmt);
86227 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
86228 + update_stmt(stmt);
86229 + pointer_set_insert(visited, oldstmt);
86230 + return gimple_get_lhs(stmt);
86231 +}
86232 +
86233 +static gimple overflow_create_phi_node(gimple oldstmt, tree var)
86234 +{
86235 + basic_block bb;
86236 + gimple phi;
86237 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
86238 +
86239 + bb = gsi_bb(gsi);
86240 +
86241 + phi = create_phi_node(var, bb);
86242 + gsi = gsi_last(phi_nodes(bb));
86243 + gsi_remove(&gsi, false);
86244 +
86245 + gsi = gsi_for_stmt(oldstmt);
86246 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
86247 + gimple_set_bb(phi, bb);
86248 + gimple_set_plf(phi, MY_STMT, true);
86249 + return phi;
86250 +}
86251 +
86252 +static basic_block create_a_first_bb(void)
86253 +{
86254 + basic_block first_bb;
86255 +
86256 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
86257 + if (dom_info_available_p(CDI_DOMINATORS))
86258 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
86259 + return first_bb;
86260 +}
86261 +
86262 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
86263 +{
86264 + basic_block bb;
86265 + gimple newstmt;
86266 + gimple_stmt_iterator gsi;
86267 + bool before = BEFORE_STMT;
86268 +
86269 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
86270 + gsi = gsi_for_stmt(get_def_stmt(arg));
86271 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
86272 + return gimple_get_lhs(newstmt);
86273 + }
86274 +
86275 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
86276 + gsi = gsi_after_labels(bb);
86277 + if (bb->index == 0) {
86278 + bb = create_a_first_bb();
86279 + gsi = gsi_start_bb(bb);
86280 + }
86281 + if (gsi_end_p(gsi))
86282 + before = AFTER_STMT;
86283 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
86284 + return gimple_get_lhs(newstmt);
86285 +}
86286 +
86287 +static gimple handle_new_phi_arg(tree arg, tree new_var, tree new_rhs)
86288 +{
86289 + gimple newstmt;
86290 + gimple_stmt_iterator gsi;
86291 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
86292 + gimple def_newstmt = get_def_stmt(new_rhs);
86293 +
86294 + gsi_insert = gsi_insert_after;
86295 + gsi = gsi_for_stmt(def_newstmt);
86296 +
86297 + switch (gimple_code(get_def_stmt(arg))) {
86298 + case GIMPLE_PHI:
86299 + newstmt = gimple_build_assign(new_var, new_rhs);
86300 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
86301 + gsi_insert = gsi_insert_before;
86302 + break;
86303 + case GIMPLE_ASM:
86304 + case GIMPLE_CALL:
86305 + newstmt = gimple_build_assign(new_var, new_rhs);
86306 + break;
86307 + case GIMPLE_ASSIGN:
86308 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
86309 + break;
86310 + default:
86311 + /* unknown gimple_code (handle_build_new_phi_arg) */
86312 + gcc_unreachable();
86313 + }
86314 +
86315 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
86316 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
86317 + gimple_set_plf(newstmt, MY_STMT, true);
86318 + update_stmt(newstmt);
86319 + return newstmt;
86320 +}
86321 +
86322 +static tree build_new_phi_arg(struct pointer_set_t *visited, bool *potentionally_overflowed, tree size_overflow_type, tree arg, tree new_var)
86323 +{
86324 + gimple newstmt;
86325 + tree new_rhs;
86326 +
86327 + new_rhs = expand(visited, potentionally_overflowed, arg);
86328 + if (new_rhs == NULL_TREE)
86329 + return NULL_TREE;
86330 +
86331 + new_rhs = cast_to_new_size_overflow_type(get_def_stmt(new_rhs), new_rhs, size_overflow_type, AFTER_STMT);
86332 +
86333 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
86334 + return gimple_get_lhs(newstmt);
86335 +}
86336 +
86337 +static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
86338 +{
86339 + gimple phi, oldstmt = get_def_stmt(var);
86340 + tree new_var, size_overflow_type;
86341 + unsigned int i, n = gimple_phi_num_args(oldstmt);
86342 +
86343 + size_overflow_type = get_size_overflow_type(oldstmt, var);
86344 +
86345 + new_var = create_new_var(size_overflow_type);
86346 +
86347 + pointer_set_insert(visited, oldstmt);
86348 + phi = overflow_create_phi_node(oldstmt, new_var);
86349 + for (i = 0; i < n; i++) {
86350 + tree arg, lhs;
86351 +
86352 + arg = gimple_phi_arg_def(oldstmt, i);
86353 + if (is_gimple_constant(arg))
86354 + arg = cast_a_tree(size_overflow_type, arg);
86355 + lhs = build_new_phi_arg(visited, potentionally_overflowed, size_overflow_type, arg, new_var);
86356 + if (lhs == NULL_TREE)
86357 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_var, i);
86358 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
86359 + }
86360 +
86361 + update_stmt(phi);
86362 + return gimple_phi_result(phi);
86363 +}
86364 +
86365 +static tree change_assign_rhs(gimple stmt, tree orig_rhs, tree new_rhs)
86366 +{
86367 + gimple assign;
86368 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
86369 + tree origtype = TREE_TYPE(orig_rhs);
86370 +
86371 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
86372 +
86373 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
86374 + return gimple_get_lhs(assign);
86375 +}
86376 +
86377 +static void change_rhs1(gimple stmt, tree new_rhs1)
86378 +{
86379 + tree assign_rhs;
86380 + tree rhs = gimple_assign_rhs1(stmt);
86381 +
86382 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
86383 + gimple_assign_set_rhs1(stmt, assign_rhs);
86384 + update_stmt(stmt);
86385 +}
86386 +
86387 +static bool check_mode_type(gimple stmt)
86388 +{
86389 + tree lhs = gimple_get_lhs(stmt);
86390 + tree lhs_type = TREE_TYPE(lhs);
86391 + tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
86392 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
86393 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
86394 +
86395 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
86396 + return false;
86397 +
86398 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
86399 + return false;
86400 +
86401 + return true;
86402 +}
86403 +
86404 +static bool check_undefined_integer_operation(gimple stmt)
86405 +{
86406 + gimple def_stmt;
86407 + tree lhs = gimple_get_lhs(stmt);
86408 + tree rhs1 = gimple_assign_rhs1(stmt);
86409 + tree rhs1_type = TREE_TYPE(rhs1);
86410 + tree lhs_type = TREE_TYPE(lhs);
86411 +
86412 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
86413 + return false;
86414 +
86415 + def_stmt = get_def_stmt(rhs1);
86416 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
86417 + return false;
86418 +
86419 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
86420 + return false;
86421 + return true;
86422 +}
86423 +
86424 +static tree handle_unary_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple stmt)
86425 +{
86426 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
86427 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
86428 + tree rhs1_type = TREE_TYPE(rhs1);
86429 + tree lhs_type = TREE_TYPE(lhs);
86430 +
86431 + *potentionally_overflowed = true;
86432 +
86433 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
86434 +
86435 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
86436 + return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
86437 +
86438 + if (gimple_plf(stmt, MY_STMT))
86439 + return lhs;
86440 +
86441 + if (gimple_plf(stmt, NO_CAST_CHECK)) {
86442 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
86443 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
86444 + return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, NULL_TREE, NULL_TREE);
86445 + }
86446 +
86447 + if (!gimple_assign_cast_p(stmt)) {
86448 + size_overflow_type = get_size_overflow_type(stmt, lhs);
86449 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
86450 + return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, NULL_TREE, NULL_TREE);
86451 + }
86452 +
86453 + if (check_undefined_integer_operation(stmt)) {
86454 + size_overflow_type = get_size_overflow_type(stmt, lhs);
86455 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
86456 + return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, NULL_TREE, NULL_TREE);
86457 + }
86458 +
86459 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
86460 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
86461 +
86462 + change_rhs1(stmt, new_rhs1);
86463 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, potentionally_overflowed, BEFORE_STMT);
86464 +
86465 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
86466 + return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
86467 +
86468 + if (!check_mode_type(stmt))
86469 + return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
86470 +
86471 + size_overflow_type = get_size_overflow_type(stmt, lhs);
86472 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
86473 +
86474 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, potentionally_overflowed, BEFORE_STMT);
86475 +
86476 + return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
86477 +}
86478 +
86479 +static tree handle_unary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
86480 +{
86481 + gimple def_stmt = get_def_stmt(lhs);
86482 + tree rhs1 = gimple_assign_rhs1(def_stmt);
86483 +
86484 + if (is_gimple_constant(rhs1))
86485 + return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
86486 +
86487 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
86488 + switch (TREE_CODE(rhs1)) {
86489 + case SSA_NAME:
86490 + return handle_unary_rhs(visited, potentionally_overflowed, def_stmt);
86491 + case ARRAY_REF:
86492 + case BIT_FIELD_REF:
86493 + case ADDR_EXPR:
86494 + case COMPONENT_REF:
86495 + case INDIRECT_REF:
86496 +#if BUILDING_GCC_VERSION >= 4006
86497 + case MEM_REF:
86498 +#endif
86499 + case PARM_DECL:
86500 + case TARGET_MEM_REF:
86501 + case VAR_DECL:
86502 + return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
86503 +
86504 + default:
86505 + debug_gimple_stmt(def_stmt);
86506 + debug_tree(rhs1);
86507 + gcc_unreachable();
86508 + }
86509 +}
86510 +
86511 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
86512 +{
86513 + gimple cond_stmt;
86514 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
86515 +
86516 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
86517 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
86518 + update_stmt(cond_stmt);
86519 +}
86520 +
86521 +static tree create_string_param(tree string)
86522 +{
86523 + tree i_type, a_type;
86524 + int length = TREE_STRING_LENGTH(string);
86525 +
86526 + gcc_assert(length > 0);
86527 +
86528 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
86529 + a_type = build_array_type(char_type_node, i_type);
86530 +
86531 + TREE_TYPE(string) = a_type;
86532 + TREE_CONSTANT(string) = 1;
86533 + TREE_READONLY(string) = 1;
86534 +
86535 + return build1(ADDR_EXPR, ptr_type_node, string);
86536 +}
86537 +
86538 +static void insert_cond_result(basic_block bb_true, gimple stmt, tree arg, bool min)
86539 +{
86540 + gimple func_stmt, def_stmt;
86541 + tree current_func, loc_file, loc_line, ssa_name;
86542 + expanded_location xloc;
86543 + char ssa_name_buf[100];
86544 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
86545 +
86546 + def_stmt = get_def_stmt(arg);
86547 + xloc = expand_location(gimple_location(def_stmt));
86548 +
86549 + if (!gimple_has_location(def_stmt)) {
86550 + xloc = expand_location(gimple_location(stmt));
86551 + if (!gimple_has_location(stmt))
86552 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
86553 + }
86554 +
86555 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
86556 +
86557 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
86558 + loc_file = create_string_param(loc_file);
86559 +
86560 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
86561 + current_func = create_string_param(current_func);
86562 +
86563 + if (min)
86564 + snprintf(ssa_name_buf, 100, "%s_%u (min)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg));
86565 + else
86566 + snprintf(ssa_name_buf, 100, "%s_%u (max)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg));
86567 + ssa_name = build_string(100, ssa_name_buf);
86568 + ssa_name = create_string_param(ssa_name);
86569 +
86570 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
86571 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
86572 +
86573 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
86574 +}
86575 +
86576 +static void __unused print_the_code_insertions(gimple stmt)
86577 +{
86578 + location_t loc = gimple_location(stmt);
86579 +
86580 + inform(loc, "Integer size_overflow check applied here.");
86581 +}
86582 +
86583 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
86584 +{
86585 + basic_block cond_bb, join_bb, bb_true;
86586 + edge e;
86587 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
86588 +
86589 + cond_bb = gimple_bb(stmt);
86590 + if (before)
86591 + gsi_prev(&gsi);
86592 + if (gsi_end_p(gsi))
86593 + e = split_block_after_labels(cond_bb);
86594 + else
86595 + e = split_block(cond_bb, gsi_stmt(gsi));
86596 + cond_bb = e->src;
86597 + join_bb = e->dest;
86598 + e->flags = EDGE_FALSE_VALUE;
86599 + e->probability = REG_BR_PROB_BASE;
86600 +
86601 + bb_true = create_empty_bb(cond_bb);
86602 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
86603 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
86604 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
86605 +
86606 + if (dom_info_available_p(CDI_DOMINATORS)) {
86607 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
86608 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
86609 + }
86610 +
86611 + if (current_loops != NULL) {
86612 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
86613 + add_bb_to_loop(bb_true, cond_bb->loop_father);
86614 + }
86615 +
86616 + insert_cond(cond_bb, arg, cond_code, type_value);
86617 + insert_cond_result(bb_true, stmt, arg, min);
86618 +
86619 +// print_the_code_insertions(stmt);
86620 +}
86621 +
86622 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool *potentionally_overflowed, bool before)
86623 +{
86624 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min, rhs_type = TREE_TYPE(rhs);
86625 + gcc_assert(rhs_type != NULL_TREE);
86626 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
86627 +
86628 + if (!*potentionally_overflowed)
86629 + return;
86630 +
86631 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
86632 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
86633 +
86634 + gcc_assert(!TREE_OVERFLOW(type_max));
86635 +
86636 + cast_rhs_type = TREE_TYPE(cast_rhs);
86637 + type_max_type = TREE_TYPE(type_max);
86638 + type_min_type = TREE_TYPE(type_min);
86639 + gcc_assert(useless_type_conversion_p(cast_rhs_type, type_max_type));
86640 + gcc_assert(useless_type_conversion_p(type_max_type, type_min_type));
86641 +
86642 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
86643 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
86644 +}
86645 +
86646 +static tree get_handle_const_assign_size_overflow_type(gimple def_stmt, tree var_rhs)
86647 +{
86648 + gimple var_rhs_def_stmt;
86649 + tree lhs = gimple_get_lhs(def_stmt);
86650 + tree lhs_type = TREE_TYPE(lhs);
86651 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
86652 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
86653 +
86654 + if (var_rhs == NULL_TREE)
86655 + return get_size_overflow_type(def_stmt, lhs);
86656 +
86657 + var_rhs_def_stmt = get_def_stmt(var_rhs);
86658 +
86659 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
86660 + return get_size_overflow_type(var_rhs_def_stmt, var_rhs);
86661 +
86662 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
86663 + return get_size_overflow_type(var_rhs_def_stmt, var_rhs);
86664 +
86665 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
86666 + return get_size_overflow_type(var_rhs_def_stmt, var_rhs);
86667 +
86668 + if (!useless_type_conversion_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
86669 + debug_gimple_stmt(def_stmt);
86670 + gcc_unreachable();
86671 + }
86672 +
86673 + return get_size_overflow_type(def_stmt, lhs);
86674 +}
86675 +
86676 +static tree handle_const_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple def_stmt, tree var_rhs, tree new_rhs1, tree new_rhs2)
86677 +{
86678 + tree new_rhs, size_overflow_type, orig_rhs;
86679 + void (*gimple_assign_set_rhs)(gimple, tree);
86680 + tree rhs1 = gimple_assign_rhs1(def_stmt);
86681 + tree rhs2 = gimple_assign_rhs2(def_stmt);
86682 + tree lhs = gimple_get_lhs(def_stmt);
86683 +
86684 + if (var_rhs == NULL_TREE)
86685 + return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
86686 +
86687 + if (new_rhs2 == NULL_TREE) {
86688 + size_overflow_type = get_handle_const_assign_size_overflow_type(def_stmt, new_rhs1);
86689 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
86690 + orig_rhs = rhs1;
86691 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
86692 + } else {
86693 + size_overflow_type = get_handle_const_assign_size_overflow_type(def_stmt, new_rhs2);
86694 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
86695 + orig_rhs = rhs2;
86696 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
86697 + }
86698 +
86699 + var_rhs = cast_to_new_size_overflow_type(def_stmt, var_rhs, size_overflow_type, BEFORE_STMT);
86700 +
86701 + if (gimple_assign_rhs_code(def_stmt) == MIN_EXPR)
86702 + return dup_assign(visited, potentionally_overflowed, def_stmt, size_overflow_type, new_rhs1, new_rhs2, NULL_TREE);
86703 +
86704 + check_size_overflow(def_stmt, size_overflow_type, var_rhs, orig_rhs, potentionally_overflowed, BEFORE_STMT);
86705 +
86706 + new_rhs = change_assign_rhs(def_stmt, orig_rhs, var_rhs);
86707 + gimple_assign_set_rhs(def_stmt, new_rhs);
86708 + update_stmt(def_stmt);
86709 +
86710 + return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
86711 +}
86712 +
86713 +static tree get_cast_def_stmt_rhs(tree new_rhs)
86714 +{
86715 + gimple def_stmt;
86716 +
86717 + def_stmt = get_def_stmt(new_rhs);
86718 + // get_size_overflow_type
86719 + if (LONG_TYPE_SIZE != GET_MODE_BITSIZE(SImode))
86720 + gcc_assert(gimple_assign_cast_p(def_stmt));
86721 + return gimple_assign_rhs1(def_stmt);
86722 +}
86723 +
86724 +static tree cast_to_int_TI_type_and_check(bool *potentionally_overflowed, gimple stmt, tree new_rhs)
86725 +{
86726 + gimple_stmt_iterator gsi;
86727 + gimple cast_stmt, def_stmt;
86728 + enum machine_mode mode = TYPE_MODE(TREE_TYPE(new_rhs));
86729 +
86730 + if (mode != TImode && mode != DImode) {
86731 + def_stmt = get_def_stmt(new_rhs);
86732 + gcc_assert(gimple_assign_cast_p(def_stmt));
86733 + new_rhs = gimple_assign_rhs1(def_stmt);
86734 + mode = TYPE_MODE(TREE_TYPE(new_rhs));
86735 + }
86736 +
86737 + gcc_assert(mode == TImode || mode == DImode);
86738 +
86739 + if (mode == TYPE_MODE(intTI_type_node) && useless_type_conversion_p(TREE_TYPE(new_rhs), intTI_type_node))
86740 + return new_rhs;
86741 +
86742 + gsi = gsi_for_stmt(stmt);
86743 + cast_stmt = build_cast_stmt(intTI_type_node, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
86744 + new_rhs = gimple_get_lhs(cast_stmt);
86745 +
86746 + if (mode == DImode)
86747 + return new_rhs;
86748 +
86749 + check_size_overflow(stmt, intTI_type_node, new_rhs, new_rhs, potentionally_overflowed, BEFORE_STMT);
86750 +
86751 + return new_rhs;
86752 +}
86753 +
86754 +static bool is_an_integer_trunction(gimple stmt)
86755 +{
86756 + gimple rhs1_def_stmt, rhs2_def_stmt;
86757 + tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1;
86758 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode;
86759 + tree rhs1 = gimple_assign_rhs1(stmt);
86760 + tree rhs2 = gimple_assign_rhs2(stmt);
86761 + enum machine_mode rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1));
86762 + enum machine_mode rhs2_mode = TYPE_MODE(TREE_TYPE(rhs2));
86763 +
86764 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
86765 + return false;
86766 +
86767 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
86768 +
86769 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR || rhs1_mode != SImode || rhs2_mode != SImode)
86770 + return false;
86771 +
86772 + rhs1_def_stmt = get_def_stmt(rhs1);
86773 + rhs2_def_stmt = get_def_stmt(rhs2);
86774 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
86775 + return false;
86776 +
86777 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
86778 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
86779 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
86780 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
86781 + if (rhs1_def_stmt_rhs1_mode != DImode || rhs2_def_stmt_rhs1_mode != DImode)
86782 + return false;
86783 +
86784 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
86785 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
86786 + return true;
86787 +}
86788 +
86789 +static tree handle_integer_truncation(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
86790 +{
86791 + tree new_rhs1, new_rhs2, size_overflow_type;
86792 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
86793 + tree new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type;
86794 + gimple assign, stmt = get_def_stmt(lhs);
86795 + tree rhs1 = gimple_assign_rhs1(stmt);
86796 + tree rhs2 = gimple_assign_rhs2(stmt);
86797 +
86798 + if (!is_an_integer_trunction(stmt))
86799 + return NULL_TREE;
86800 +
86801 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
86802 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
86803 +
86804 + new_rhs1_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs1);
86805 + new_rhs2_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs2);
86806 +
86807 + new_rhs1_def_stmt_rhs1_type = TREE_TYPE(new_rhs1_def_stmt_rhs1);
86808 + new_rhs2_def_stmt_rhs1_type = TREE_TYPE(new_rhs2_def_stmt_rhs1);
86809 +
86810 + if (!useless_type_conversion_p(new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type)) {
86811 + new_rhs1_def_stmt_rhs1 = cast_to_int_TI_type_and_check(potentionally_overflowed, stmt, new_rhs1_def_stmt_rhs1);
86812 + new_rhs2_def_stmt_rhs1 = cast_to_int_TI_type_and_check(potentionally_overflowed, stmt, new_rhs2_def_stmt_rhs1);
86813 + }
86814 +
86815 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
86816 + new_lhs = gimple_get_lhs(assign);
86817 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, potentionally_overflowed, AFTER_STMT);
86818 +
86819 + size_overflow_type = get_size_overflow_type(stmt, lhs);
86820 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
86821 + new_rhs2 = cast_to_new_size_overflow_type(stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
86822 + return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, new_rhs2, NULL_TREE);
86823 +}
86824 +
86825 +static tree handle_binary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
86826 +{
86827 + tree rhs1, rhs2, size_overflow_type, new_lhs;
86828 + gimple def_stmt = get_def_stmt(lhs);
86829 + tree new_rhs1 = NULL_TREE;
86830 + tree new_rhs2 = NULL_TREE;
86831 +
86832 + rhs1 = gimple_assign_rhs1(def_stmt);
86833 + rhs2 = gimple_assign_rhs2(def_stmt);
86834 +
86835 + /* no DImode/TImode division in the 32/64 bit kernel */
86836 + switch (gimple_assign_rhs_code(def_stmt)) {
86837 + case RDIV_EXPR:
86838 + case TRUNC_DIV_EXPR:
86839 + case CEIL_DIV_EXPR:
86840 + case FLOOR_DIV_EXPR:
86841 + case ROUND_DIV_EXPR:
86842 + case TRUNC_MOD_EXPR:
86843 + case CEIL_MOD_EXPR:
86844 + case FLOOR_MOD_EXPR:
86845 + case ROUND_MOD_EXPR:
86846 + case EXACT_DIV_EXPR:
86847 + case POINTER_PLUS_EXPR:
86848 + case BIT_AND_EXPR:
86849 + return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
86850 + default:
86851 + break;
86852 + }
86853 +
86854 + *potentionally_overflowed = true;
86855 +
86856 + new_lhs = handle_integer_truncation(visited, potentionally_overflowed, lhs);
86857 + if (new_lhs != NULL_TREE)
86858 + return new_lhs;
86859 +
86860 + if (TREE_CODE(rhs1) == SSA_NAME)
86861 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
86862 + if (TREE_CODE(rhs2) == SSA_NAME)
86863 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
86864 +
86865 + if (is_gimple_constant(rhs2))
86866 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
86867 +
86868 + if (is_gimple_constant(rhs1))
86869 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
86870 +
86871 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
86872 +
86873 + new_rhs1 = cast_to_new_size_overflow_type(def_stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
86874 + new_rhs2 = cast_to_new_size_overflow_type(def_stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
86875 +
86876 + return dup_assign(visited, potentionally_overflowed, def_stmt, size_overflow_type, new_rhs1, new_rhs2, NULL_TREE);
86877 +}
86878 +
86879 +#if BUILDING_GCC_VERSION >= 4007
86880 +static tree get_new_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree size_overflow_type, tree rhs)
86881 +{
86882 + if (is_gimple_constant(rhs))
86883 + return cast_a_tree(size_overflow_type, rhs);
86884 + if (TREE_CODE(rhs) != SSA_NAME)
86885 + return NULL_TREE;
86886 + return expand(visited, potentionally_overflowed, rhs);
86887 +}
86888 +
86889 +static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
86890 +{
86891 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
86892 + gimple def_stmt = get_def_stmt(var);
86893 +
86894 + *potentionally_overflowed = true;
86895 +
86896 + size_overflow_type = get_size_overflow_type(def_stmt, var);
86897 +
86898 + rhs1 = gimple_assign_rhs1(def_stmt);
86899 + rhs2 = gimple_assign_rhs2(def_stmt);
86900 + rhs3 = gimple_assign_rhs3(def_stmt);
86901 + new_rhs1 = get_new_rhs(visited, potentionally_overflowed, size_overflow_type, rhs1);
86902 + new_rhs2 = get_new_rhs(visited, potentionally_overflowed, size_overflow_type, rhs2);
86903 + new_rhs3 = get_new_rhs(visited, potentionally_overflowed, size_overflow_type, rhs3);
86904 +
86905 + new_rhs1 = cast_to_new_size_overflow_type(def_stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
86906 + new_rhs2 = cast_to_new_size_overflow_type(def_stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
86907 + new_rhs3 = cast_to_new_size_overflow_type(def_stmt, new_rhs3, size_overflow_type, BEFORE_STMT);
86908 +
86909 + return dup_assign(visited, potentionally_overflowed, def_stmt, size_overflow_type, new_rhs1, new_rhs2, new_rhs3);
86910 +}
86911 +#endif
86912 +
86913 +static tree get_size_overflow_type(gimple stmt, tree node)
86914 +{
86915 + tree type;
86916 +
86917 + gcc_assert(node != NULL_TREE);
86918 +
86919 + type = TREE_TYPE(node);
86920 +
86921 + if (gimple_plf(stmt, MY_STMT))
86922 + return TREE_TYPE(node);
86923 +
86924 + switch (TYPE_MODE(type)) {
86925 + case QImode:
86926 + return (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
86927 + case HImode:
86928 + return (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
86929 + case SImode:
86930 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
86931 + case DImode:
86932 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
86933 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
86934 + return (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
86935 + default:
86936 + debug_tree(node);
86937 + error("get_size_overflow_type: unsupported gcc configuration.");
86938 + gcc_unreachable();
86939 + }
86940 +}
86941 +
86942 +static tree expand_visited(gimple def_stmt)
86943 +{
86944 + gimple next_stmt;
86945 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
86946 +
86947 + gsi_next(&gsi);
86948 + next_stmt = gsi_stmt(gsi);
86949 +
86950 + switch (gimple_code(next_stmt)) {
86951 + case GIMPLE_ASSIGN:
86952 + return gimple_get_lhs(next_stmt);
86953 + case GIMPLE_PHI:
86954 + return gimple_phi_result(next_stmt);
86955 + case GIMPLE_CALL:
86956 + return gimple_call_lhs(next_stmt);
86957 + default:
86958 + return NULL_TREE;
86959 + }
86960 +}
86961 +
86962 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
86963 +{
86964 + gimple def_stmt;
86965 + enum tree_code code = TREE_CODE(TREE_TYPE(var));
86966 +
86967 + if (is_gimple_constant(var))
86968 + return NULL_TREE;
86969 +
86970 + if (TREE_CODE(var) == ADDR_EXPR)
86971 + return NULL_TREE;
86972 +
86973 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
86974 +
86975 + if (TREE_CODE(SSA_NAME_VAR(var)) == PARM_DECL)
86976 + check_missing_attribute(var);
86977 +
86978 + def_stmt = get_def_stmt(var);
86979 +
86980 + if (!def_stmt)
86981 + return NULL_TREE;
86982 +
86983 + if (gimple_plf(def_stmt, MY_STMT))
86984 + return var;
86985 +
86986 + if (pointer_set_contains(visited, def_stmt))
86987 + return expand_visited(def_stmt);
86988 +
86989 + switch (gimple_code(def_stmt)) {
86990 + case GIMPLE_NOP:
86991 + check_missing_attribute(var);
86992 + return NULL_TREE;
86993 + case GIMPLE_PHI:
86994 + return build_new_phi(visited, potentionally_overflowed, var);
86995 + case GIMPLE_CALL:
86996 + case GIMPLE_ASM:
86997 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
86998 + case GIMPLE_ASSIGN:
86999 + switch (gimple_num_ops(def_stmt)) {
87000 + case 2:
87001 + return handle_unary_ops(visited, potentionally_overflowed, var);
87002 + case 3:
87003 + return handle_binary_ops(visited, potentionally_overflowed, var);
87004 +#if BUILDING_GCC_VERSION >= 4007
87005 + case 4:
87006 + return handle_ternary_ops(visited, potentionally_overflowed, var);
87007 +#endif
87008 + }
87009 + default:
87010 + debug_gimple_stmt(def_stmt);
87011 + error("expand: unknown gimple code");
87012 + gcc_unreachable();
87013 + }
87014 +}
87015 +
87016 +static void change_function_arg(gimple stmt, tree origarg, unsigned int argnum, tree newarg)
87017 +{
87018 + gimple assign;
87019 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
87020 + tree origtype = TREE_TYPE(origarg);
87021 +
87022 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
87023 +
87024 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
87025 +
87026 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
87027 + update_stmt(stmt);
87028 +}
87029 +
87030 +static tree get_function_arg(unsigned int argnum, gimple stmt, tree fndecl)
87031 +{
87032 + const char *origid;
87033 + tree arg, origarg;
87034 +
87035 + if (!DECL_ABSTRACT_ORIGIN(fndecl)) {
87036 + gcc_assert(gimple_call_num_args(stmt) > argnum);
87037 + return gimple_call_arg(stmt, argnum);
87038 + }
87039 +
87040 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
87041 + while (origarg && argnum) {
87042 + argnum--;
87043 + origarg = TREE_CHAIN(origarg);
87044 + }
87045 +
87046 + gcc_assert(argnum == 0);
87047 +
87048 + gcc_assert(origarg != NULL_TREE);
87049 + origid = NAME(origarg);
87050 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
87051 + if (!strcmp(origid, NAME(arg)))
87052 + return arg;
87053 + }
87054 + return NULL_TREE;
87055 +}
87056 +
87057 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
87058 +{
87059 + struct pointer_set_t *visited;
87060 + tree arg, newarg;
87061 + bool potentionally_overflowed;
87062 +
87063 + arg = get_function_arg(argnum, stmt, fndecl);
87064 + if (arg == NULL_TREE)
87065 + return;
87066 +
87067 + if (is_gimple_constant(arg))
87068 + return;
87069 + if (TREE_CODE(arg) != SSA_NAME)
87070 + return;
87071 +
87072 + check_arg_type(arg);
87073 +
87074 + visited = pointer_set_create();
87075 + potentionally_overflowed = false;
87076 + newarg = expand(visited, &potentionally_overflowed, arg);
87077 + pointer_set_destroy(visited);
87078 +
87079 + if (newarg == NULL_TREE || !potentionally_overflowed)
87080 + return;
87081 +
87082 + change_function_arg(stmt, arg, argnum, newarg);
87083 +
87084 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, &potentionally_overflowed, BEFORE_STMT);
87085 +}
87086 +
87087 +static void handle_function_by_attribute(gimple stmt, tree attr, tree fndecl)
87088 +{
87089 + tree p = TREE_VALUE(attr);
87090 + do {
87091 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
87092 + p = TREE_CHAIN(p);
87093 + } while (p);
87094 +}
87095 +
87096 +static void handle_function_by_hash(gimple stmt, tree fndecl)
87097 +{
87098 + tree orig_fndecl;
87099 + unsigned int num;
87100 + struct size_overflow_hash *hash;
87101 +
87102 + orig_fndecl = get_original_function_decl(fndecl);
87103 + hash = get_function_hash(orig_fndecl);
87104 + if (!hash)
87105 + return;
87106 +
87107 + for (num = 1; num <= MAX_PARAM; num++)
87108 + if (hash->param & (1U << num))
87109 + handle_function_arg(stmt, fndecl, num - 1);
87110 +}
87111 +
87112 +static void set_plf_false(void)
87113 +{
87114 + basic_block bb;
87115 +
87116 + FOR_ALL_BB(bb) {
87117 + gimple_stmt_iterator si;
87118 +
87119 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
87120 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
87121 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
87122 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
87123 + }
87124 +}
87125 +
87126 +static unsigned int handle_function(void)
87127 +{
87128 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
87129 +
87130 + set_plf_false();
87131 +
87132 + do {
87133 + gimple_stmt_iterator gsi;
87134 + next = bb->next_bb;
87135 +
87136 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
87137 + tree fndecl, attr;
87138 + gimple stmt = gsi_stmt(gsi);
87139 +
87140 + if (!(is_gimple_call(stmt)))
87141 + continue;
87142 + fndecl = gimple_call_fndecl(stmt);
87143 + if (fndecl == NULL_TREE)
87144 + continue;
87145 + if (gimple_call_num_args(stmt) == 0)
87146 + continue;
87147 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
87148 + if (!attr || !TREE_VALUE(attr))
87149 + handle_function_by_hash(stmt, fndecl);
87150 + else
87151 + handle_function_by_attribute(stmt, attr, fndecl);
87152 + gsi = gsi_for_stmt(stmt);
87153 + next = gimple_bb(stmt)->next_bb;
87154 + }
87155 + bb = next;
87156 + } while (bb);
87157 + return 0;
87158 +}
87159 +
87160 +static struct gimple_opt_pass size_overflow_pass = {
87161 + .pass = {
87162 + .type = GIMPLE_PASS,
87163 + .name = "size_overflow",
87164 + .gate = NULL,
87165 + .execute = handle_function,
87166 + .sub = NULL,
87167 + .next = NULL,
87168 + .static_pass_number = 0,
87169 + .tv_id = TV_NONE,
87170 + .properties_required = PROP_cfg | PROP_referenced_vars,
87171 + .properties_provided = 0,
87172 + .properties_destroyed = 0,
87173 + .todo_flags_start = 0,
87174 + .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
87175 + }
87176 +};
87177 +
87178 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
87179 +{
87180 + tree fntype;
87181 +
87182 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
87183 +
87184 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
87185 + fntype = build_function_type_list(void_type_node,
87186 + const_char_ptr_type_node,
87187 + unsigned_type_node,
87188 + const_char_ptr_type_node,
87189 + const_char_ptr_type_node,
87190 + NULL_TREE);
87191 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
87192 +
87193 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
87194 + TREE_PUBLIC(report_size_overflow_decl) = 1;
87195 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
87196 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
87197 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
87198 +}
87199 +
87200 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
87201 +{
87202 + int i;
87203 + const char * const plugin_name = plugin_info->base_name;
87204 + const int argc = plugin_info->argc;
87205 + const struct plugin_argument * const argv = plugin_info->argv;
87206 + bool enable = true;
87207 +
87208 + struct register_pass_info size_overflow_pass_info = {
87209 + .pass = &size_overflow_pass.pass,
87210 + .reference_pass_name = "ssa",
87211 + .ref_pass_instance_number = 1,
87212 + .pos_op = PASS_POS_INSERT_AFTER
87213 + };
87214 +
87215 + if (!plugin_default_version_check(version, &gcc_version)) {
87216 + error(G_("incompatible gcc/plugin versions"));
87217 + return 1;
87218 + }
87219 +
87220 + for (i = 0; i < argc; ++i) {
87221 + if (!strcmp(argv[i].key, "no-size-overflow")) {
87222 + enable = false;
87223 + continue;
87224 + }
87225 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
87226 + }
87227 +
87228 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
87229 + if (enable) {
87230 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
87231 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
87232 + }
87233 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
87234 +
87235 + return 0;
87236 +}
87237 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
87238 new file mode 100644
87239 index 0000000..38d2014
87240 --- /dev/null
87241 +++ b/tools/gcc/stackleak_plugin.c
87242 @@ -0,0 +1,313 @@
87243 +/*
87244 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
87245 + * Licensed under the GPL v2
87246 + *
87247 + * Note: the choice of the license means that the compilation process is
87248 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
87249 + * but for the kernel it doesn't matter since it doesn't link against
87250 + * any of the gcc libraries
87251 + *
87252 + * gcc plugin to help implement various PaX features
87253 + *
87254 + * - track lowest stack pointer
87255 + *
87256 + * TODO:
87257 + * - initialize all local variables
87258 + *
87259 + * BUGS:
87260 + * - none known
87261 + */
87262 +#include "gcc-plugin.h"
87263 +#include "config.h"
87264 +#include "system.h"
87265 +#include "coretypes.h"
87266 +#include "tree.h"
87267 +#include "tree-pass.h"
87268 +#include "flags.h"
87269 +#include "intl.h"
87270 +#include "toplev.h"
87271 +#include "plugin.h"
87272 +//#include "expr.h" where are you...
87273 +#include "diagnostic.h"
87274 +#include "plugin-version.h"
87275 +#include "tm.h"
87276 +#include "function.h"
87277 +#include "basic-block.h"
87278 +#include "gimple.h"
87279 +#include "rtl.h"
87280 +#include "emit-rtl.h"
87281 +
87282 +extern void print_gimple_stmt(FILE *, gimple, int, int);
87283 +
87284 +int plugin_is_GPL_compatible;
87285 +
87286 +static int track_frame_size = -1;
87287 +static const char track_function[] = "pax_track_stack";
87288 +static const char check_function[] = "pax_check_alloca";
87289 +static bool init_locals;
87290 +
87291 +static struct plugin_info stackleak_plugin_info = {
87292 + .version = "201203140940",
87293 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
87294 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
87295 +};
87296 +
87297 +static bool gate_stackleak_track_stack(void);
87298 +static unsigned int execute_stackleak_tree_instrument(void);
87299 +static unsigned int execute_stackleak_final(void);
87300 +
87301 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
87302 + .pass = {
87303 + .type = GIMPLE_PASS,
87304 + .name = "stackleak_tree_instrument",
87305 + .gate = gate_stackleak_track_stack,
87306 + .execute = execute_stackleak_tree_instrument,
87307 + .sub = NULL,
87308 + .next = NULL,
87309 + .static_pass_number = 0,
87310 + .tv_id = TV_NONE,
87311 + .properties_required = PROP_gimple_leh | PROP_cfg,
87312 + .properties_provided = 0,
87313 + .properties_destroyed = 0,
87314 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
87315 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
87316 + }
87317 +};
87318 +
87319 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
87320 + .pass = {
87321 + .type = RTL_PASS,
87322 + .name = "stackleak_final",
87323 + .gate = gate_stackleak_track_stack,
87324 + .execute = execute_stackleak_final,
87325 + .sub = NULL,
87326 + .next = NULL,
87327 + .static_pass_number = 0,
87328 + .tv_id = TV_NONE,
87329 + .properties_required = 0,
87330 + .properties_provided = 0,
87331 + .properties_destroyed = 0,
87332 + .todo_flags_start = 0,
87333 + .todo_flags_finish = TODO_dump_func
87334 + }
87335 +};
87336 +
87337 +static bool gate_stackleak_track_stack(void)
87338 +{
87339 + return track_frame_size >= 0;
87340 +}
87341 +
87342 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
87343 +{
87344 + gimple check_alloca;
87345 + tree fntype, fndecl, alloca_size;
87346 +
87347 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
87348 + fndecl = build_fn_decl(check_function, fntype);
87349 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
87350 +
87351 + // insert call to void pax_check_alloca(unsigned long size)
87352 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
87353 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
87354 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
87355 +}
87356 +
87357 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
87358 +{
87359 + gimple track_stack;
87360 + tree fntype, fndecl;
87361 +
87362 + fntype = build_function_type_list(void_type_node, NULL_TREE);
87363 + fndecl = build_fn_decl(track_function, fntype);
87364 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
87365 +
87366 + // insert call to void pax_track_stack(void)
87367 + track_stack = gimple_build_call(fndecl, 0);
87368 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
87369 +}
87370 +
87371 +#if BUILDING_GCC_VERSION == 4005
87372 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
87373 +{
87374 + tree fndecl;
87375 +
87376 + if (!is_gimple_call(stmt))
87377 + return false;
87378 + fndecl = gimple_call_fndecl(stmt);
87379 + if (!fndecl)
87380 + return false;
87381 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
87382 + return false;
87383 +// print_node(stderr, "pax", fndecl, 4);
87384 + return DECL_FUNCTION_CODE(fndecl) == code;
87385 +}
87386 +#endif
87387 +
87388 +static bool is_alloca(gimple stmt)
87389 +{
87390 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
87391 + return true;
87392 +
87393 +#if BUILDING_GCC_VERSION >= 4007
87394 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
87395 + return true;
87396 +#endif
87397 +
87398 + return false;
87399 +}
87400 +
87401 +static unsigned int execute_stackleak_tree_instrument(void)
87402 +{
87403 + basic_block bb, entry_bb;
87404 + bool prologue_instrumented = false, is_leaf = true;
87405 +
87406 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
87407 +
87408 + // 1. loop through BBs and GIMPLE statements
87409 + FOR_EACH_BB(bb) {
87410 + gimple_stmt_iterator gsi;
87411 +
87412 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
87413 + gimple stmt;
87414 +
87415 + stmt = gsi_stmt(gsi);
87416 +
87417 + if (is_gimple_call(stmt))
87418 + is_leaf = false;
87419 +
87420 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
87421 + if (!is_alloca(stmt))
87422 + continue;
87423 +
87424 + // 2. insert stack overflow check before each __builtin_alloca call
87425 + stackleak_check_alloca(&gsi);
87426 +
87427 + // 3. insert track call after each __builtin_alloca call
87428 + stackleak_add_instrumentation(&gsi);
87429 + if (bb == entry_bb)
87430 + prologue_instrumented = true;
87431 + }
87432 + }
87433 +
87434 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
87435 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
87436 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
87437 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
87438 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
87439 + return 0;
87440 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
87441 + return 0;
87442 +
87443 + // 4. insert track call at the beginning
87444 + if (!prologue_instrumented) {
87445 + gimple_stmt_iterator gsi;
87446 +
87447 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
87448 + if (dom_info_available_p(CDI_DOMINATORS))
87449 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
87450 + gsi = gsi_start_bb(bb);
87451 + stackleak_add_instrumentation(&gsi);
87452 + }
87453 +
87454 + return 0;
87455 +}
87456 +
87457 +static unsigned int execute_stackleak_final(void)
87458 +{
87459 + rtx insn;
87460 +
87461 + if (cfun->calls_alloca)
87462 + return 0;
87463 +
87464 + // keep calls only if function frame is big enough
87465 + if (get_frame_size() >= track_frame_size)
87466 + return 0;
87467 +
87468 + // 1. find pax_track_stack calls
87469 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
87470 + // 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))
87471 + rtx body;
87472 +
87473 + if (!CALL_P(insn))
87474 + continue;
87475 + body = PATTERN(insn);
87476 + if (GET_CODE(body) != CALL)
87477 + continue;
87478 + body = XEXP(body, 0);
87479 + if (GET_CODE(body) != MEM)
87480 + continue;
87481 + body = XEXP(body, 0);
87482 + if (GET_CODE(body) != SYMBOL_REF)
87483 + continue;
87484 + if (strcmp(XSTR(body, 0), track_function))
87485 + continue;
87486 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
87487 + // 2. delete call
87488 + insn = delete_insn_and_edges(insn);
87489 +#if BUILDING_GCC_VERSION >= 4007
87490 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
87491 + insn = delete_insn_and_edges(insn);
87492 +#endif
87493 + }
87494 +
87495 +// print_simple_rtl(stderr, get_insns());
87496 +// print_rtl(stderr, get_insns());
87497 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
87498 +
87499 + return 0;
87500 +}
87501 +
87502 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
87503 +{
87504 + const char * const plugin_name = plugin_info->base_name;
87505 + const int argc = plugin_info->argc;
87506 + const struct plugin_argument * const argv = plugin_info->argv;
87507 + int i;
87508 + struct register_pass_info stackleak_tree_instrument_pass_info = {
87509 + .pass = &stackleak_tree_instrument_pass.pass,
87510 +// .reference_pass_name = "tree_profile",
87511 + .reference_pass_name = "optimized",
87512 + .ref_pass_instance_number = 1,
87513 + .pos_op = PASS_POS_INSERT_BEFORE
87514 + };
87515 + struct register_pass_info stackleak_final_pass_info = {
87516 + .pass = &stackleak_final_rtl_opt_pass.pass,
87517 + .reference_pass_name = "final",
87518 + .ref_pass_instance_number = 1,
87519 + .pos_op = PASS_POS_INSERT_BEFORE
87520 + };
87521 +
87522 + if (!plugin_default_version_check(version, &gcc_version)) {
87523 + error(G_("incompatible gcc/plugin versions"));
87524 + return 1;
87525 + }
87526 +
87527 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
87528 +
87529 + for (i = 0; i < argc; ++i) {
87530 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
87531 + if (!argv[i].value) {
87532 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
87533 + continue;
87534 + }
87535 + track_frame_size = atoi(argv[i].value);
87536 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
87537 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
87538 + continue;
87539 + }
87540 + if (!strcmp(argv[i].key, "initialize-locals")) {
87541 + if (argv[i].value) {
87542 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
87543 + continue;
87544 + }
87545 + init_locals = true;
87546 + continue;
87547 + }
87548 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
87549 + }
87550 +
87551 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
87552 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
87553 +
87554 + return 0;
87555 +}
87556 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
87557 index 6789d78..4afd019 100644
87558 --- a/tools/perf/util/include/asm/alternative-asm.h
87559 +++ b/tools/perf/util/include/asm/alternative-asm.h
87560 @@ -5,4 +5,7 @@
87561
87562 #define altinstruction_entry #
87563
87564 + .macro pax_force_retaddr rip=0, reload=0
87565 + .endm
87566 +
87567 #endif
87568 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
87569 index af0f22f..9a7d479 100644
87570 --- a/usr/gen_init_cpio.c
87571 +++ b/usr/gen_init_cpio.c
87572 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
87573 int retval;
87574 int rc = -1;
87575 int namesize;
87576 - int i;
87577 + unsigned int i;
87578
87579 mode |= S_IFREG;
87580
87581 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
87582 *env_var = *expanded = '\0';
87583 strncat(env_var, start + 2, end - start - 2);
87584 strncat(expanded, new_location, start - new_location);
87585 - strncat(expanded, getenv(env_var), PATH_MAX);
87586 - strncat(expanded, end + 1, PATH_MAX);
87587 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
87588 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
87589 strncpy(new_location, expanded, PATH_MAX);
87590 + new_location[PATH_MAX] = 0;
87591 } else
87592 break;
87593 }
87594 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
87595 index 44ee712..7da730b 100644
87596 --- a/virt/kvm/kvm_main.c
87597 +++ b/virt/kvm/kvm_main.c
87598 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
87599
87600 static cpumask_var_t cpus_hardware_enabled;
87601 static int kvm_usage_count = 0;
87602 -static atomic_t hardware_enable_failed;
87603 +static atomic_unchecked_t hardware_enable_failed;
87604
87605 struct kmem_cache *kvm_vcpu_cache;
87606 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
87607 @@ -2291,7 +2291,7 @@ static void hardware_enable_nolock(void *junk)
87608
87609 if (r) {
87610 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
87611 - atomic_inc(&hardware_enable_failed);
87612 + atomic_inc_unchecked(&hardware_enable_failed);
87613 printk(KERN_INFO "kvm: enabling virtualization on "
87614 "CPU%d failed\n", cpu);
87615 }
87616 @@ -2345,10 +2345,10 @@ static int hardware_enable_all(void)
87617
87618 kvm_usage_count++;
87619 if (kvm_usage_count == 1) {
87620 - atomic_set(&hardware_enable_failed, 0);
87621 + atomic_set_unchecked(&hardware_enable_failed, 0);
87622 on_each_cpu(hardware_enable_nolock, NULL, 1);
87623
87624 - if (atomic_read(&hardware_enable_failed)) {
87625 + if (atomic_read_unchecked(&hardware_enable_failed)) {
87626 hardware_disable_all_nolock();
87627 r = -EBUSY;
87628 }
87629 @@ -2709,7 +2709,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
87630 kvm_arch_vcpu_put(vcpu);
87631 }
87632
87633 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
87634 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
87635 struct module *module)
87636 {
87637 int r;
87638 @@ -2772,7 +2772,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
87639 if (!vcpu_align)
87640 vcpu_align = __alignof__(struct kvm_vcpu);
87641 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
87642 - 0, NULL);
87643 + SLAB_USERCOPY, NULL);
87644 if (!kvm_vcpu_cache) {
87645 r = -ENOMEM;
87646 goto out_free_3;
87647 @@ -2782,9 +2782,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
87648 if (r)
87649 goto out_free;
87650
87651 - kvm_chardev_ops.owner = module;
87652 - kvm_vm_fops.owner = module;
87653 - kvm_vcpu_fops.owner = module;
87654 + pax_open_kernel();
87655 + *(void **)&kvm_chardev_ops.owner = module;
87656 + *(void **)&kvm_vm_fops.owner = module;
87657 + *(void **)&kvm_vcpu_fops.owner = module;
87658 + pax_close_kernel();
87659
87660 r = misc_register(&kvm_dev);
87661 if (r) {