]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9-3.2.12-201203201932.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9-3.2.12-201203201932.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index dfa6fc6..df93044 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,9 +51,11 @@
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 @@ -70,6 +75,7 @@ Kerntypes
38 Module.markers
39 Module.symvers
40 PENDING
41 +PERF*
42 SCCS
43 System.map*
44 TAGS
45 @@ -93,19 +99,24 @@ bounds.h
46 bsetup
47 btfixupprep
48 build
49 +builtin-policy.h
50 bvmlinux
51 bzImage*
52 capability_names.h
53 capflags.c
54 classlist.h*
55 +clut_vga16.c
56 +common-cmds.h
57 comp*.log
58 compile.h*
59 conf
60 config
61 config-*
62 config_data.h*
63 +config.c
64 config.mak
65 config.mak.autogen
66 +config.tmp
67 conmakehash
68 consolemap_deftbl.c*
69 cpustr.h
70 @@ -116,9 +127,11 @@ devlist.h*
71 dnotify_test
72 docproc
73 dslm
74 +dtc-lexer.lex.c
75 elf2ecoff
76 elfconfig.h*
77 evergreen_reg_safe.h
78 +exception_policy.conf
79 fixdep
80 flask.h
81 fore200e_mkfirm
82 @@ -126,12 +139,15 @@ fore200e_pca_fw.c*
83 gconf
84 gconf.glade.h
85 gen-devlist
86 +gen-kdb_cmds.c
87 gen_crc32table
88 gen_init_cpio
89 generated
90 genheaders
91 genksyms
92 *_gray256.c
93 +hash
94 +hid-example
95 hpet_example
96 hugepage-mmap
97 hugepage-shm
98 @@ -146,7 +162,7 @@ int32.c
99 int4.c
100 int8.c
101 kallsyms
102 -kconfig
103 +kern_constants.h
104 keywords.c
105 ksym.c*
106 ksym.h*
107 @@ -154,7 +170,7 @@ kxgettext
108 lkc_defs.h
109 lex.c
110 lex.*.c
111 -linux
112 +lib1funcs.S
113 logo_*.c
114 logo_*_clut224.c
115 logo_*_mono.c
116 @@ -166,14 +182,15 @@ machtypes.h
117 map
118 map_hugetlb
119 maui_boot.h
120 -media
121 mconf
122 +mdp
123 miboot*
124 mk_elfconfig
125 mkboot
126 mkbugboot
127 mkcpustr
128 mkdep
129 +mkpiggy
130 mkprep
131 mkregtable
132 mktables
133 @@ -209,6 +226,7 @@ r300_reg_safe.h
134 r420_reg_safe.h
135 r600_reg_safe.h
136 recordmcount
137 +regdb.c
138 relocs
139 rlim_names.h
140 rn50_reg_safe.h
141 @@ -219,6 +237,7 @@ setup
142 setup.bin
143 setup.elf
144 sImage
145 +slabinfo
146 sm_tbl*
147 split-include
148 syscalltab.h
149 @@ -229,6 +248,7 @@ tftpboot.img
150 timeconst.h
151 times.h*
152 trix_boot.h
153 +user_constants.h
154 utsrelease.h*
155 vdso-syms.lds
156 vdso.lds
157 @@ -246,7 +266,9 @@ vmlinux
158 vmlinux-*
159 vmlinux.aout
160 vmlinux.bin.all
161 +vmlinux.bin.bz2
162 vmlinux.lds
163 +vmlinux.relocs
164 vmlinuz
165 voffset.h
166 vsyscall.lds
167 @@ -254,9 +276,11 @@ vsyscall_32.lds
168 wanxlfw.inc
169 uImage
170 unifdef
171 +utsrelease.h
172 wakeup.bin
173 wakeup.elf
174 wakeup.lds
175 zImage*
176 zconf.hash.c
177 +zconf.lex.c
178 zoffset.h
179 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
180 index 81c287f..d456d02 100644
181 --- a/Documentation/kernel-parameters.txt
182 +++ b/Documentation/kernel-parameters.txt
183 @@ -1935,6 +1935,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
184 the specified number of seconds. This is to be used if
185 your oopses keep scrolling off the screen.
186
187 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
188 + virtualization environments that don't cope well with the
189 + expand down segment used by UDEREF on X86-32 or the frequent
190 + page table updates on X86-64.
191 +
192 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
193 +
194 pcbit= [HW,ISDN]
195
196 pcd. [PARIDE]
197 diff --git a/Makefile b/Makefile
198 index 15e80f1..4fb87db 100644
199 --- a/Makefile
200 +++ b/Makefile
201 @@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
202
203 HOSTCC = gcc
204 HOSTCXX = g++
205 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
206 -HOSTCXXFLAGS = -O2
207 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
208 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
209 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
210
211 # Decide whether to build built-in, modular, or both.
212 # Normally, just do built-in.
213 @@ -407,8 +408,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
214 # Rules shared between *config targets and build targets
215
216 # Basic helpers built in scripts/
217 -PHONY += scripts_basic
218 -scripts_basic:
219 +PHONY += scripts_basic gcc-plugins
220 +scripts_basic: gcc-plugins
221 $(Q)$(MAKE) $(build)=scripts/basic
222 $(Q)rm -f .tmp_quiet_recordmcount
223
224 @@ -564,6 +565,53 @@ else
225 KBUILD_CFLAGS += -O2
226 endif
227
228 +ifndef DISABLE_PAX_PLUGINS
229 +ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(CC)"), y)
230 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
231 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
232 +endif
233 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
234 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
235 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
236 +endif
237 +ifdef CONFIG_KALLOCSTAT_PLUGIN
238 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
239 +endif
240 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
241 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
242 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
243 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
244 +endif
245 +ifdef CONFIG_CHECKER_PLUGIN
246 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
247 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
248 +endif
249 +endif
250 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
251 +ifdef CONFIG_PAX_SIZE_OVERFLOW
252 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
253 +endif
254 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
255 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS) $(SIZE_OVERFLOW_PLUGIN_CFLAGS)
256 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
257 +export CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN SIZE_OVERFLOW_PLUGIN
258 +ifeq ($(KBUILD_EXTMOD),)
259 +gcc-plugins:
260 + $(Q)$(MAKE) $(build)=tools/gcc
261 +else
262 +gcc-plugins: ;
263 +endif
264 +else
265 +gcc-plugins:
266 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
267 + $(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.))
268 +else
269 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
270 +endif
271 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
272 +endif
273 +endif
274 +
275 include $(srctree)/arch/$(SRCARCH)/Makefile
276
277 ifneq ($(CONFIG_FRAME_WARN),0)
278 @@ -708,7 +756,7 @@ export mod_strip_cmd
279
280
281 ifeq ($(KBUILD_EXTMOD),)
282 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
283 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
284
285 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
286 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
287 @@ -932,6 +980,8 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
288
289 # The actual objects are generated when descending,
290 # make sure no implicit rule kicks in
291 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
292 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
293 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
294
295 # Handle descending into subdirectories listed in $(vmlinux-dirs)
296 @@ -941,7 +991,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
297 # Error messages still appears in the original language
298
299 PHONY += $(vmlinux-dirs)
300 -$(vmlinux-dirs): prepare scripts
301 +$(vmlinux-dirs): gcc-plugins prepare scripts
302 $(Q)$(MAKE) $(build)=$@
303
304 # Store (new) KERNELRELASE string in include/config/kernel.release
305 @@ -985,6 +1035,7 @@ prepare0: archprepare FORCE
306 $(Q)$(MAKE) $(build)=.
307
308 # All the preparing..
309 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
310 prepare: prepare0
311
312 # Generate some files
313 @@ -1086,6 +1137,8 @@ all: modules
314 # using awk while concatenating to the final file.
315
316 PHONY += modules
317 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
318 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
319 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
320 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
321 @$(kecho) ' Building modules, stage 2.';
322 @@ -1101,7 +1154,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
323
324 # Target to prepare building external modules
325 PHONY += modules_prepare
326 -modules_prepare: prepare scripts
327 +modules_prepare: gcc-plugins prepare scripts
328
329 # Target to install modules
330 PHONY += modules_install
331 @@ -1198,6 +1251,7 @@ distclean: mrproper
332 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
333 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
334 -o -name '.*.rej' \
335 + -o -name '.*.rej' -o -name '*.so' \
336 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
337 -type f -print | xargs rm -f
338
339 @@ -1358,6 +1412,8 @@ PHONY += $(module-dirs) modules
340 $(module-dirs): crmodverdir $(objtree)/Module.symvers
341 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
342
343 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
344 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
345 modules: $(module-dirs)
346 @$(kecho) ' Building modules, stage 2.';
347 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
348 @@ -1484,17 +1540,21 @@ else
349 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
350 endif
351
352 -%.s: %.c prepare scripts FORCE
353 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
354 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
355 +%.s: %.c gcc-plugins prepare scripts FORCE
356 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
357 %.i: %.c prepare scripts FORCE
358 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
359 -%.o: %.c prepare scripts FORCE
360 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
361 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
362 +%.o: %.c gcc-plugins prepare scripts FORCE
363 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
364 %.lst: %.c prepare scripts FORCE
365 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
366 -%.s: %.S prepare scripts FORCE
367 +%.s: %.S gcc-plugins prepare scripts FORCE
368 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
369 -%.o: %.S prepare scripts FORCE
370 +%.o: %.S gcc-plugins prepare scripts FORCE
371 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
372 %.symtypes: %.c prepare scripts FORCE
373 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
374 @@ -1504,11 +1564,15 @@ endif
375 $(cmd_crmodverdir)
376 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
377 $(build)=$(build-dir)
378 -%/: prepare scripts FORCE
379 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
380 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
381 +%/: gcc-plugins prepare scripts FORCE
382 $(cmd_crmodverdir)
383 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
384 $(build)=$(build-dir)
385 -%.ko: prepare scripts FORCE
386 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
387 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
388 +%.ko: gcc-plugins prepare scripts FORCE
389 $(cmd_crmodverdir)
390 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
391 $(build)=$(build-dir) $(@:.ko=.o)
392 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
393 index 640f909..48b6597 100644
394 --- a/arch/alpha/include/asm/atomic.h
395 +++ b/arch/alpha/include/asm/atomic.h
396 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
397 #define atomic_dec(v) atomic_sub(1,(v))
398 #define atomic64_dec(v) atomic64_sub(1,(v))
399
400 +#define atomic64_read_unchecked(v) atomic64_read(v)
401 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
402 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
403 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
404 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
405 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
406 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
407 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
408 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
409 +
410 #define smp_mb__before_atomic_dec() smp_mb()
411 #define smp_mb__after_atomic_dec() smp_mb()
412 #define smp_mb__before_atomic_inc() smp_mb()
413 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
414 index ad368a9..fbe0f25 100644
415 --- a/arch/alpha/include/asm/cache.h
416 +++ b/arch/alpha/include/asm/cache.h
417 @@ -4,19 +4,19 @@
418 #ifndef __ARCH_ALPHA_CACHE_H
419 #define __ARCH_ALPHA_CACHE_H
420
421 +#include <linux/const.h>
422
423 /* Bytes per L1 (data) cache line. */
424 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
425 -# define L1_CACHE_BYTES 64
426 # define L1_CACHE_SHIFT 6
427 #else
428 /* Both EV4 and EV5 are write-through, read-allocate,
429 direct-mapped, physical.
430 */
431 -# define L1_CACHE_BYTES 32
432 # define L1_CACHE_SHIFT 5
433 #endif
434
435 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
436 #define SMP_CACHE_BYTES L1_CACHE_BYTES
437
438 #endif
439 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
440 index da5449e..7418343 100644
441 --- a/arch/alpha/include/asm/elf.h
442 +++ b/arch/alpha/include/asm/elf.h
443 @@ -90,6 +90,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
444
445 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
446
447 +#ifdef CONFIG_PAX_ASLR
448 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
449 +
450 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
451 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
452 +#endif
453 +
454 /* $0 is set by ld.so to a pointer to a function which might be
455 registered using atexit. This provides a mean for the dynamic
456 linker to call DT_FINI functions for shared libraries that have
457 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
458 index de98a73..bd4f1f8 100644
459 --- a/arch/alpha/include/asm/pgtable.h
460 +++ b/arch/alpha/include/asm/pgtable.h
461 @@ -101,6 +101,17 @@ struct vm_area_struct;
462 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
463 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
464 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
465 +
466 +#ifdef CONFIG_PAX_PAGEEXEC
467 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
468 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
469 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
470 +#else
471 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
472 +# define PAGE_COPY_NOEXEC PAGE_COPY
473 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
474 +#endif
475 +
476 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
477
478 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
479 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
480 index 2fd00b7..cfd5069 100644
481 --- a/arch/alpha/kernel/module.c
482 +++ b/arch/alpha/kernel/module.c
483 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
484
485 /* The small sections were sorted to the end of the segment.
486 The following should definitely cover them. */
487 - gp = (u64)me->module_core + me->core_size - 0x8000;
488 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
489 got = sechdrs[me->arch.gotsecindex].sh_addr;
490
491 for (i = 0; i < n; i++) {
492 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
493 index 01e8715..be0e80f 100644
494 --- a/arch/alpha/kernel/osf_sys.c
495 +++ b/arch/alpha/kernel/osf_sys.c
496 @@ -1147,7 +1147,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
497 /* At this point: (!vma || addr < vma->vm_end). */
498 if (limit - len < addr)
499 return -ENOMEM;
500 - if (!vma || addr + len <= vma->vm_start)
501 + if (check_heap_stack_gap(vma, addr, len))
502 return addr;
503 addr = vma->vm_end;
504 vma = vma->vm_next;
505 @@ -1183,6 +1183,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
506 merely specific addresses, but regions of memory -- perhaps
507 this feature should be incorporated into all ports? */
508
509 +#ifdef CONFIG_PAX_RANDMMAP
510 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
511 +#endif
512 +
513 if (addr) {
514 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
515 if (addr != (unsigned long) -ENOMEM)
516 @@ -1190,8 +1194,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
517 }
518
519 /* Next, try allocating at TASK_UNMAPPED_BASE. */
520 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
521 - len, limit);
522 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
523 +
524 if (addr != (unsigned long) -ENOMEM)
525 return addr;
526
527 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
528 index fadd5f8..904e73a 100644
529 --- a/arch/alpha/mm/fault.c
530 +++ b/arch/alpha/mm/fault.c
531 @@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
532 __reload_thread(pcb);
533 }
534
535 +#ifdef CONFIG_PAX_PAGEEXEC
536 +/*
537 + * PaX: decide what to do with offenders (regs->pc = fault address)
538 + *
539 + * returns 1 when task should be killed
540 + * 2 when patched PLT trampoline was detected
541 + * 3 when unpatched PLT trampoline was detected
542 + */
543 +static int pax_handle_fetch_fault(struct pt_regs *regs)
544 +{
545 +
546 +#ifdef CONFIG_PAX_EMUPLT
547 + int err;
548 +
549 + do { /* PaX: patched PLT emulation #1 */
550 + unsigned int ldah, ldq, jmp;
551 +
552 + err = get_user(ldah, (unsigned int *)regs->pc);
553 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
554 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
555 +
556 + if (err)
557 + break;
558 +
559 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
560 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
561 + jmp == 0x6BFB0000U)
562 + {
563 + unsigned long r27, addr;
564 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
565 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
566 +
567 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
568 + err = get_user(r27, (unsigned long *)addr);
569 + if (err)
570 + break;
571 +
572 + regs->r27 = r27;
573 + regs->pc = r27;
574 + return 2;
575 + }
576 + } while (0);
577 +
578 + do { /* PaX: patched PLT emulation #2 */
579 + unsigned int ldah, lda, br;
580 +
581 + err = get_user(ldah, (unsigned int *)regs->pc);
582 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
583 + err |= get_user(br, (unsigned int *)(regs->pc+8));
584 +
585 + if (err)
586 + break;
587 +
588 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
589 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
590 + (br & 0xFFE00000U) == 0xC3E00000U)
591 + {
592 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
593 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
594 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
595 +
596 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
597 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
598 + return 2;
599 + }
600 + } while (0);
601 +
602 + do { /* PaX: unpatched PLT emulation */
603 + unsigned int br;
604 +
605 + err = get_user(br, (unsigned int *)regs->pc);
606 +
607 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
608 + unsigned int br2, ldq, nop, jmp;
609 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
610 +
611 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
612 + err = get_user(br2, (unsigned int *)addr);
613 + err |= get_user(ldq, (unsigned int *)(addr+4));
614 + err |= get_user(nop, (unsigned int *)(addr+8));
615 + err |= get_user(jmp, (unsigned int *)(addr+12));
616 + err |= get_user(resolver, (unsigned long *)(addr+16));
617 +
618 + if (err)
619 + break;
620 +
621 + if (br2 == 0xC3600000U &&
622 + ldq == 0xA77B000CU &&
623 + nop == 0x47FF041FU &&
624 + jmp == 0x6B7B0000U)
625 + {
626 + regs->r28 = regs->pc+4;
627 + regs->r27 = addr+16;
628 + regs->pc = resolver;
629 + return 3;
630 + }
631 + }
632 + } while (0);
633 +#endif
634 +
635 + return 1;
636 +}
637 +
638 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
639 +{
640 + unsigned long i;
641 +
642 + printk(KERN_ERR "PAX: bytes at PC: ");
643 + for (i = 0; i < 5; i++) {
644 + unsigned int c;
645 + if (get_user(c, (unsigned int *)pc+i))
646 + printk(KERN_CONT "???????? ");
647 + else
648 + printk(KERN_CONT "%08x ", c);
649 + }
650 + printk("\n");
651 +}
652 +#endif
653
654 /*
655 * This routine handles page faults. It determines the address,
656 @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
657 good_area:
658 si_code = SEGV_ACCERR;
659 if (cause < 0) {
660 - if (!(vma->vm_flags & VM_EXEC))
661 + if (!(vma->vm_flags & VM_EXEC)) {
662 +
663 +#ifdef CONFIG_PAX_PAGEEXEC
664 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
665 + goto bad_area;
666 +
667 + up_read(&mm->mmap_sem);
668 + switch (pax_handle_fetch_fault(regs)) {
669 +
670 +#ifdef CONFIG_PAX_EMUPLT
671 + case 2:
672 + case 3:
673 + return;
674 +#endif
675 +
676 + }
677 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
678 + do_group_exit(SIGKILL);
679 +#else
680 goto bad_area;
681 +#endif
682 +
683 + }
684 } else if (!cause) {
685 /* Allow reads even for write-only mappings */
686 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
687 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
688 index 86976d0..683de93 100644
689 --- a/arch/arm/include/asm/atomic.h
690 +++ b/arch/arm/include/asm/atomic.h
691 @@ -15,6 +15,10 @@
692 #include <linux/types.h>
693 #include <asm/system.h>
694
695 +#ifdef CONFIG_GENERIC_ATOMIC64
696 +#include <asm-generic/atomic64.h>
697 +#endif
698 +
699 #define ATOMIC_INIT(i) { (i) }
700
701 #ifdef __KERNEL__
702 @@ -25,7 +29,15 @@
703 * atomic_set() is the clrex or dummy strex done on every exception return.
704 */
705 #define atomic_read(v) (*(volatile int *)&(v)->counter)
706 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
707 +{
708 + return v->counter;
709 +}
710 #define atomic_set(v,i) (((v)->counter) = (i))
711 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
712 +{
713 + v->counter = i;
714 +}
715
716 #if __LINUX_ARM_ARCH__ >= 6
717
718 @@ -40,6 +52,35 @@ static inline void atomic_add(int i, atomic_t *v)
719 int result;
720
721 __asm__ __volatile__("@ atomic_add\n"
722 +"1: ldrex %1, [%3]\n"
723 +" adds %0, %1, %4\n"
724 +
725 +#ifdef CONFIG_PAX_REFCOUNT
726 +" bvc 3f\n"
727 +"2: bkpt 0xf103\n"
728 +"3:\n"
729 +#endif
730 +
731 +" strex %1, %0, [%3]\n"
732 +" teq %1, #0\n"
733 +" bne 1b"
734 +
735 +#ifdef CONFIG_PAX_REFCOUNT
736 +"\n4:\n"
737 + _ASM_EXTABLE(2b, 4b)
738 +#endif
739 +
740 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
741 + : "r" (&v->counter), "Ir" (i)
742 + : "cc");
743 +}
744 +
745 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
746 +{
747 + unsigned long tmp;
748 + int result;
749 +
750 + __asm__ __volatile__("@ atomic_add_unchecked\n"
751 "1: ldrex %0, [%3]\n"
752 " add %0, %0, %4\n"
753 " strex %1, %0, [%3]\n"
754 @@ -58,6 +99,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
755 smp_mb();
756
757 __asm__ __volatile__("@ atomic_add_return\n"
758 +"1: ldrex %1, [%3]\n"
759 +" adds %0, %1, %4\n"
760 +
761 +#ifdef CONFIG_PAX_REFCOUNT
762 +" bvc 3f\n"
763 +" mov %0, %1\n"
764 +"2: bkpt 0xf103\n"
765 +"3:\n"
766 +#endif
767 +
768 +" strex %1, %0, [%3]\n"
769 +" teq %1, #0\n"
770 +" bne 1b"
771 +
772 +#ifdef CONFIG_PAX_REFCOUNT
773 +"\n4:\n"
774 + _ASM_EXTABLE(2b, 4b)
775 +#endif
776 +
777 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
778 + : "r" (&v->counter), "Ir" (i)
779 + : "cc");
780 +
781 + smp_mb();
782 +
783 + return result;
784 +}
785 +
786 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
787 +{
788 + unsigned long tmp;
789 + int result;
790 +
791 + smp_mb();
792 +
793 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
794 "1: ldrex %0, [%3]\n"
795 " add %0, %0, %4\n"
796 " strex %1, %0, [%3]\n"
797 @@ -78,6 +155,35 @@ static inline void atomic_sub(int i, atomic_t *v)
798 int result;
799
800 __asm__ __volatile__("@ atomic_sub\n"
801 +"1: ldrex %1, [%3]\n"
802 +" subs %0, %1, %4\n"
803 +
804 +#ifdef CONFIG_PAX_REFCOUNT
805 +" bvc 3f\n"
806 +"2: bkpt 0xf103\n"
807 +"3:\n"
808 +#endif
809 +
810 +" strex %1, %0, [%3]\n"
811 +" teq %1, #0\n"
812 +" bne 1b"
813 +
814 +#ifdef CONFIG_PAX_REFCOUNT
815 +"\n4:\n"
816 + _ASM_EXTABLE(2b, 4b)
817 +#endif
818 +
819 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
820 + : "r" (&v->counter), "Ir" (i)
821 + : "cc");
822 +}
823 +
824 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
825 +{
826 + unsigned long tmp;
827 + int result;
828 +
829 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
830 "1: ldrex %0, [%3]\n"
831 " sub %0, %0, %4\n"
832 " strex %1, %0, [%3]\n"
833 @@ -96,11 +202,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
834 smp_mb();
835
836 __asm__ __volatile__("@ atomic_sub_return\n"
837 -"1: ldrex %0, [%3]\n"
838 -" sub %0, %0, %4\n"
839 +"1: ldrex %1, [%3]\n"
840 +" sub %0, %1, %4\n"
841 +
842 +#ifdef CONFIG_PAX_REFCOUNT
843 +" bvc 3f\n"
844 +" mov %0, %1\n"
845 +"2: bkpt 0xf103\n"
846 +"3:\n"
847 +#endif
848 +
849 " strex %1, %0, [%3]\n"
850 " teq %1, #0\n"
851 " bne 1b"
852 +
853 +#ifdef CONFIG_PAX_REFCOUNT
854 +"\n4:\n"
855 + _ASM_EXTABLE(2b, 4b)
856 +#endif
857 +
858 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
859 : "r" (&v->counter), "Ir" (i)
860 : "cc");
861 @@ -132,6 +252,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
862 return oldval;
863 }
864
865 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
866 +{
867 + unsigned long oldval, res;
868 +
869 + smp_mb();
870 +
871 + do {
872 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
873 + "ldrex %1, [%3]\n"
874 + "mov %0, #0\n"
875 + "teq %1, %4\n"
876 + "strexeq %0, %5, [%3]\n"
877 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
878 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
879 + : "cc");
880 + } while (res);
881 +
882 + smp_mb();
883 +
884 + return oldval;
885 +}
886 +
887 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
888 {
889 unsigned long tmp, tmp2;
890 @@ -207,6 +349,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
891 #endif /* __LINUX_ARM_ARCH__ */
892
893 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
894 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
895 +{
896 + return xchg(&v->counter, new);
897 +}
898
899 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
900 {
901 @@ -219,11 +365,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
902 }
903
904 #define atomic_inc(v) atomic_add(1, v)
905 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
906 +{
907 + atomic_add_unchecked(1, v);
908 +}
909 #define atomic_dec(v) atomic_sub(1, v)
910 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
911 +{
912 + atomic_sub_unchecked(1, v);
913 +}
914
915 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
916 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
917 +{
918 + return atomic_add_return_unchecked(1, v) == 0;
919 +}
920 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
921 #define atomic_inc_return(v) (atomic_add_return(1, v))
922 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
923 +{
924 + return atomic_add_return_unchecked(1, v);
925 +}
926 #define atomic_dec_return(v) (atomic_sub_return(1, v))
927 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
928
929 @@ -239,6 +401,14 @@ typedef struct {
930 u64 __aligned(8) counter;
931 } atomic64_t;
932
933 +#ifdef CONFIG_PAX_REFCOUNT
934 +typedef struct {
935 + u64 __aligned(8) counter;
936 +} atomic64_unchecked_t;
937 +#else
938 +typedef atomic64_t atomic64_unchecked_t;
939 +#endif
940 +
941 #define ATOMIC64_INIT(i) { (i) }
942
943 static inline u64 atomic64_read(atomic64_t *v)
944 @@ -254,6 +424,19 @@ static inline u64 atomic64_read(atomic64_t *v)
945 return result;
946 }
947
948 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
949 +{
950 + u64 result;
951 +
952 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
953 +" ldrexd %0, %H0, [%1]"
954 + : "=&r" (result)
955 + : "r" (&v->counter), "Qo" (v->counter)
956 + );
957 +
958 + return result;
959 +}
960 +
961 static inline void atomic64_set(atomic64_t *v, u64 i)
962 {
963 u64 tmp;
964 @@ -268,6 +451,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
965 : "cc");
966 }
967
968 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
969 +{
970 + u64 tmp;
971 +
972 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
973 +"1: ldrexd %0, %H0, [%2]\n"
974 +" strexd %0, %3, %H3, [%2]\n"
975 +" teq %0, #0\n"
976 +" bne 1b"
977 + : "=&r" (tmp), "=Qo" (v->counter)
978 + : "r" (&v->counter), "r" (i)
979 + : "cc");
980 +}
981 +
982 static inline void atomic64_add(u64 i, atomic64_t *v)
983 {
984 u64 result;
985 @@ -276,6 +473,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
986 __asm__ __volatile__("@ atomic64_add\n"
987 "1: ldrexd %0, %H0, [%3]\n"
988 " adds %0, %0, %4\n"
989 +" adcs %H0, %H0, %H4\n"
990 +
991 +#ifdef CONFIG_PAX_REFCOUNT
992 +" bvc 3f\n"
993 +"2: bkpt 0xf103\n"
994 +"3:\n"
995 +#endif
996 +
997 +" strexd %1, %0, %H0, [%3]\n"
998 +" teq %1, #0\n"
999 +" bne 1b"
1000 +
1001 +#ifdef CONFIG_PAX_REFCOUNT
1002 +"\n4:\n"
1003 + _ASM_EXTABLE(2b, 4b)
1004 +#endif
1005 +
1006 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1007 + : "r" (&v->counter), "r" (i)
1008 + : "cc");
1009 +}
1010 +
1011 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1012 +{
1013 + u64 result;
1014 + unsigned long tmp;
1015 +
1016 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1017 +"1: ldrexd %0, %H0, [%3]\n"
1018 +" adds %0, %0, %4\n"
1019 " adc %H0, %H0, %H4\n"
1020 " strexd %1, %0, %H0, [%3]\n"
1021 " teq %1, #0\n"
1022 @@ -287,12 +514,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1023
1024 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1025 {
1026 - u64 result;
1027 - unsigned long tmp;
1028 + u64 result, tmp;
1029
1030 smp_mb();
1031
1032 __asm__ __volatile__("@ atomic64_add_return\n"
1033 +"1: ldrexd %1, %H1, [%3]\n"
1034 +" adds %0, %1, %4\n"
1035 +" adcs %H0, %H1, %H4\n"
1036 +
1037 +#ifdef CONFIG_PAX_REFCOUNT
1038 +" bvc 3f\n"
1039 +" mov %0, %1\n"
1040 +" mov %H0, %H1\n"
1041 +"2: bkpt 0xf103\n"
1042 +"3:\n"
1043 +#endif
1044 +
1045 +" strexd %1, %0, %H0, [%3]\n"
1046 +" teq %1, #0\n"
1047 +" bne 1b"
1048 +
1049 +#ifdef CONFIG_PAX_REFCOUNT
1050 +"\n4:\n"
1051 + _ASM_EXTABLE(2b, 4b)
1052 +#endif
1053 +
1054 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1055 + : "r" (&v->counter), "r" (i)
1056 + : "cc");
1057 +
1058 + smp_mb();
1059 +
1060 + return result;
1061 +}
1062 +
1063 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1064 +{
1065 + u64 result;
1066 + unsigned long tmp;
1067 +
1068 + smp_mb();
1069 +
1070 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1071 "1: ldrexd %0, %H0, [%3]\n"
1072 " adds %0, %0, %4\n"
1073 " adc %H0, %H0, %H4\n"
1074 @@ -316,6 +580,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1075 __asm__ __volatile__("@ atomic64_sub\n"
1076 "1: ldrexd %0, %H0, [%3]\n"
1077 " subs %0, %0, %4\n"
1078 +" sbcs %H0, %H0, %H4\n"
1079 +
1080 +#ifdef CONFIG_PAX_REFCOUNT
1081 +" bvc 3f\n"
1082 +"2: bkpt 0xf103\n"
1083 +"3:\n"
1084 +#endif
1085 +
1086 +" strexd %1, %0, %H0, [%3]\n"
1087 +" teq %1, #0\n"
1088 +" bne 1b"
1089 +
1090 +#ifdef CONFIG_PAX_REFCOUNT
1091 +"\n4:\n"
1092 + _ASM_EXTABLE(2b, 4b)
1093 +#endif
1094 +
1095 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1096 + : "r" (&v->counter), "r" (i)
1097 + : "cc");
1098 +}
1099 +
1100 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1101 +{
1102 + u64 result;
1103 + unsigned long tmp;
1104 +
1105 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1106 +"1: ldrexd %0, %H0, [%3]\n"
1107 +" subs %0, %0, %4\n"
1108 " sbc %H0, %H0, %H4\n"
1109 " strexd %1, %0, %H0, [%3]\n"
1110 " teq %1, #0\n"
1111 @@ -327,18 +621,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1112
1113 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1114 {
1115 - u64 result;
1116 - unsigned long tmp;
1117 + u64 result, tmp;
1118
1119 smp_mb();
1120
1121 __asm__ __volatile__("@ atomic64_sub_return\n"
1122 -"1: ldrexd %0, %H0, [%3]\n"
1123 -" subs %0, %0, %4\n"
1124 -" sbc %H0, %H0, %H4\n"
1125 +"1: ldrexd %1, %H1, [%3]\n"
1126 +" subs %0, %1, %4\n"
1127 +" sbc %H0, %H1, %H4\n"
1128 +
1129 +#ifdef CONFIG_PAX_REFCOUNT
1130 +" bvc 3f\n"
1131 +" mov %0, %1\n"
1132 +" mov %H0, %H1\n"
1133 +"2: bkpt 0xf103\n"
1134 +"3:\n"
1135 +#endif
1136 +
1137 " strexd %1, %0, %H0, [%3]\n"
1138 " teq %1, #0\n"
1139 " bne 1b"
1140 +
1141 +#ifdef CONFIG_PAX_REFCOUNT
1142 +"\n4:\n"
1143 + _ASM_EXTABLE(2b, 4b)
1144 +#endif
1145 +
1146 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1147 : "r" (&v->counter), "r" (i)
1148 : "cc");
1149 @@ -372,6 +680,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1150 return oldval;
1151 }
1152
1153 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1154 +{
1155 + u64 oldval;
1156 + unsigned long res;
1157 +
1158 + smp_mb();
1159 +
1160 + do {
1161 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1162 + "ldrexd %1, %H1, [%3]\n"
1163 + "mov %0, #0\n"
1164 + "teq %1, %4\n"
1165 + "teqeq %H1, %H4\n"
1166 + "strexdeq %0, %5, %H5, [%3]"
1167 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1168 + : "r" (&ptr->counter), "r" (old), "r" (new)
1169 + : "cc");
1170 + } while (res);
1171 +
1172 + smp_mb();
1173 +
1174 + return oldval;
1175 +}
1176 +
1177 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1178 {
1179 u64 result;
1180 @@ -395,21 +727,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1181
1182 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1183 {
1184 - u64 result;
1185 - unsigned long tmp;
1186 + u64 result, tmp;
1187
1188 smp_mb();
1189
1190 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1191 -"1: ldrexd %0, %H0, [%3]\n"
1192 -" subs %0, %0, #1\n"
1193 -" sbc %H0, %H0, #0\n"
1194 +"1: ldrexd %1, %H1, [%3]\n"
1195 +" subs %0, %1, #1\n"
1196 +" sbc %H0, %H1, #0\n"
1197 +
1198 +#ifdef CONFIG_PAX_REFCOUNT
1199 +" bvc 3f\n"
1200 +" mov %0, %1\n"
1201 +" mov %H0, %H1\n"
1202 +"2: bkpt 0xf103\n"
1203 +"3:\n"
1204 +#endif
1205 +
1206 " teq %H0, #0\n"
1207 -" bmi 2f\n"
1208 +" bmi 4f\n"
1209 " strexd %1, %0, %H0, [%3]\n"
1210 " teq %1, #0\n"
1211 " bne 1b\n"
1212 -"2:"
1213 +"4:\n"
1214 +
1215 +#ifdef CONFIG_PAX_REFCOUNT
1216 + _ASM_EXTABLE(2b, 4b)
1217 +#endif
1218 +
1219 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1220 : "r" (&v->counter)
1221 : "cc");
1222 @@ -432,13 +777,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1223 " teq %0, %5\n"
1224 " teqeq %H0, %H5\n"
1225 " moveq %1, #0\n"
1226 -" beq 2f\n"
1227 +" beq 4f\n"
1228 " adds %0, %0, %6\n"
1229 " adc %H0, %H0, %H6\n"
1230 +
1231 +#ifdef CONFIG_PAX_REFCOUNT
1232 +" bvc 3f\n"
1233 +"2: bkpt 0xf103\n"
1234 +"3:\n"
1235 +#endif
1236 +
1237 " strexd %2, %0, %H0, [%4]\n"
1238 " teq %2, #0\n"
1239 " bne 1b\n"
1240 -"2:"
1241 +"4:\n"
1242 +
1243 +#ifdef CONFIG_PAX_REFCOUNT
1244 + _ASM_EXTABLE(2b, 4b)
1245 +#endif
1246 +
1247 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1248 : "r" (&v->counter), "r" (u), "r" (a)
1249 : "cc");
1250 @@ -451,10 +808,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1251
1252 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1253 #define atomic64_inc(v) atomic64_add(1LL, (v))
1254 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1255 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1256 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1257 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1258 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1259 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1260 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1261 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1262 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1263 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1264 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1265 index 75fe66b..2255c86 100644
1266 --- a/arch/arm/include/asm/cache.h
1267 +++ b/arch/arm/include/asm/cache.h
1268 @@ -4,8 +4,10 @@
1269 #ifndef __ASMARM_CACHE_H
1270 #define __ASMARM_CACHE_H
1271
1272 +#include <linux/const.h>
1273 +
1274 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1275 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1276 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1277
1278 /*
1279 * Memory returned by kmalloc() may be used for DMA, so we must make
1280 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1281 index d5d8d5c..ad92c96 100644
1282 --- a/arch/arm/include/asm/cacheflush.h
1283 +++ b/arch/arm/include/asm/cacheflush.h
1284 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1285 void (*dma_unmap_area)(const void *, size_t, int);
1286
1287 void (*dma_flush_range)(const void *, const void *);
1288 -};
1289 +} __no_const;
1290
1291 /*
1292 * Select the calling method
1293 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1294 index 0e9ce8d..6ef1e03 100644
1295 --- a/arch/arm/include/asm/elf.h
1296 +++ b/arch/arm/include/asm/elf.h
1297 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1298 the loader. We need to make sure that it is out of the way of the program
1299 that it will "exec", and that there is sufficient room for the brk. */
1300
1301 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1302 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1303 +
1304 +#ifdef CONFIG_PAX_ASLR
1305 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1306 +
1307 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1308 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1309 +#endif
1310
1311 /* When the program starts, a1 contains a pointer to a function to be
1312 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1313 @@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1314 extern void elf_set_personality(const struct elf32_hdr *);
1315 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1316
1317 -struct mm_struct;
1318 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1319 -#define arch_randomize_brk arch_randomize_brk
1320 -
1321 extern int vectors_user_mapping(void);
1322 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
1323 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
1324 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1325 index e51b1e8..32a3113 100644
1326 --- a/arch/arm/include/asm/kmap_types.h
1327 +++ b/arch/arm/include/asm/kmap_types.h
1328 @@ -21,6 +21,7 @@ enum km_type {
1329 KM_L1_CACHE,
1330 KM_L2_CACHE,
1331 KM_KDB,
1332 + KM_CLEARPAGE,
1333 KM_TYPE_NR
1334 };
1335
1336 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1337 index 53426c6..c7baff3 100644
1338 --- a/arch/arm/include/asm/outercache.h
1339 +++ b/arch/arm/include/asm/outercache.h
1340 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1341 #endif
1342 void (*set_debug)(unsigned long);
1343 void (*resume)(void);
1344 -};
1345 +} __no_const;
1346
1347 #ifdef CONFIG_OUTER_CACHE
1348
1349 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1350 index ca94653..6ac0d56 100644
1351 --- a/arch/arm/include/asm/page.h
1352 +++ b/arch/arm/include/asm/page.h
1353 @@ -123,7 +123,7 @@ struct cpu_user_fns {
1354 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1355 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1356 unsigned long vaddr, struct vm_area_struct *vma);
1357 -};
1358 +} __no_const;
1359
1360 #ifdef MULTI_USER
1361 extern struct cpu_user_fns cpu_user;
1362 diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h
1363 index 984014b..a6d914f 100644
1364 --- a/arch/arm/include/asm/system.h
1365 +++ b/arch/arm/include/asm/system.h
1366 @@ -90,6 +90,8 @@ void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int,
1367
1368 #define xchg(ptr,x) \
1369 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1370 +#define xchg_unchecked(ptr,x) \
1371 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1372
1373 extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
1374
1375 @@ -101,7 +103,7 @@ extern int __pure cpu_architecture(void);
1376 extern void cpu_init(void);
1377
1378 void arm_machine_restart(char mode, const char *cmd);
1379 -extern void (*arm_pm_restart)(char str, const char *cmd);
1380 +extern void (*arm_pm_restart)(char str, const char *cmd) __noreturn;
1381
1382 #define UDBG_UNDEFINED (1 << 0)
1383 #define UDBG_SYSCALL (1 << 1)
1384 @@ -526,6 +528,13 @@ static inline unsigned long long __cmpxchg64_mb(volatile void *ptr,
1385
1386 #endif /* __LINUX_ARM_ARCH__ >= 6 */
1387
1388 +#define _ASM_EXTABLE(from, to) \
1389 +" .pushsection __ex_table,\"a\"\n"\
1390 +" .align 3\n" \
1391 +" .long " #from ", " #to"\n" \
1392 +" .popsection"
1393 +
1394 +
1395 #endif /* __ASSEMBLY__ */
1396
1397 #define arch_align_stack(x) (x)
1398 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1399 index b293616..96310e5 100644
1400 --- a/arch/arm/include/asm/uaccess.h
1401 +++ b/arch/arm/include/asm/uaccess.h
1402 @@ -22,6 +22,8 @@
1403 #define VERIFY_READ 0
1404 #define VERIFY_WRITE 1
1405
1406 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1407 +
1408 /*
1409 * The exception table consists of pairs of addresses: the first is the
1410 * address of an instruction that is allowed to fault, and the second is
1411 @@ -387,8 +389,23 @@ do { \
1412
1413
1414 #ifdef CONFIG_MMU
1415 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1416 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1417 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1418 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1419 +
1420 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1421 +{
1422 + if (!__builtin_constant_p(n))
1423 + check_object_size(to, n, false);
1424 + return ___copy_from_user(to, from, n);
1425 +}
1426 +
1427 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1428 +{
1429 + if (!__builtin_constant_p(n))
1430 + check_object_size(from, n, true);
1431 + return ___copy_to_user(to, from, n);
1432 +}
1433 +
1434 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1435 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1436 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1437 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1438
1439 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1440 {
1441 + if ((long)n < 0)
1442 + return n;
1443 +
1444 if (access_ok(VERIFY_READ, from, n))
1445 n = __copy_from_user(to, from, n);
1446 else /* security hole - plug it */
1447 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1448
1449 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1450 {
1451 + if ((long)n < 0)
1452 + return n;
1453 +
1454 if (access_ok(VERIFY_WRITE, to, n))
1455 n = __copy_to_user(to, from, n);
1456 return n;
1457 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1458 index 5b0bce6..becd81c 100644
1459 --- a/arch/arm/kernel/armksyms.c
1460 +++ b/arch/arm/kernel/armksyms.c
1461 @@ -95,8 +95,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1462 #ifdef CONFIG_MMU
1463 EXPORT_SYMBOL(copy_page);
1464
1465 -EXPORT_SYMBOL(__copy_from_user);
1466 -EXPORT_SYMBOL(__copy_to_user);
1467 +EXPORT_SYMBOL(___copy_from_user);
1468 +EXPORT_SYMBOL(___copy_to_user);
1469 EXPORT_SYMBOL(__clear_user);
1470
1471 EXPORT_SYMBOL(__get_user_1);
1472 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1473 index 3d0c6fb..9d326fa 100644
1474 --- a/arch/arm/kernel/process.c
1475 +++ b/arch/arm/kernel/process.c
1476 @@ -28,7 +28,6 @@
1477 #include <linux/tick.h>
1478 #include <linux/utsname.h>
1479 #include <linux/uaccess.h>
1480 -#include <linux/random.h>
1481 #include <linux/hw_breakpoint.h>
1482 #include <linux/cpuidle.h>
1483
1484 @@ -92,7 +91,7 @@ static int __init hlt_setup(char *__unused)
1485 __setup("nohlt", nohlt_setup);
1486 __setup("hlt", hlt_setup);
1487
1488 -void arm_machine_restart(char mode, const char *cmd)
1489 +__noreturn void arm_machine_restart(char mode, const char *cmd)
1490 {
1491 /* Disable interrupts first */
1492 local_irq_disable();
1493 @@ -134,7 +133,7 @@ void arm_machine_restart(char mode, const char *cmd)
1494 void (*pm_power_off)(void);
1495 EXPORT_SYMBOL(pm_power_off);
1496
1497 -void (*arm_pm_restart)(char str, const char *cmd) = arm_machine_restart;
1498 +void (*arm_pm_restart)(char str, const char *cmd) __noreturn = arm_machine_restart;
1499 EXPORT_SYMBOL_GPL(arm_pm_restart);
1500
1501 static void do_nothing(void *unused)
1502 @@ -248,6 +247,7 @@ void machine_power_off(void)
1503 machine_shutdown();
1504 if (pm_power_off)
1505 pm_power_off();
1506 + BUG();
1507 }
1508
1509 void machine_restart(char *cmd)
1510 @@ -484,12 +484,6 @@ unsigned long get_wchan(struct task_struct *p)
1511 return 0;
1512 }
1513
1514 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1515 -{
1516 - unsigned long range_end = mm->brk + 0x02000000;
1517 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1518 -}
1519 -
1520 #ifdef CONFIG_MMU
1521 /*
1522 * The vectors page is always readable from user space for the
1523 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1524 index 8fc2c8f..064c150 100644
1525 --- a/arch/arm/kernel/setup.c
1526 +++ b/arch/arm/kernel/setup.c
1527 @@ -108,13 +108,13 @@ struct processor processor __read_mostly;
1528 struct cpu_tlb_fns cpu_tlb __read_mostly;
1529 #endif
1530 #ifdef MULTI_USER
1531 -struct cpu_user_fns cpu_user __read_mostly;
1532 +struct cpu_user_fns cpu_user __read_only;
1533 #endif
1534 #ifdef MULTI_CACHE
1535 -struct cpu_cache_fns cpu_cache __read_mostly;
1536 +struct cpu_cache_fns cpu_cache __read_only;
1537 #endif
1538 #ifdef CONFIG_OUTER_CACHE
1539 -struct outer_cache_fns outer_cache __read_mostly;
1540 +struct outer_cache_fns outer_cache __read_only;
1541 EXPORT_SYMBOL(outer_cache);
1542 #endif
1543
1544 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1545 index 99a5727..a3d5bb1 100644
1546 --- a/arch/arm/kernel/traps.c
1547 +++ b/arch/arm/kernel/traps.c
1548 @@ -259,6 +259,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1549
1550 static DEFINE_RAW_SPINLOCK(die_lock);
1551
1552 +extern void gr_handle_kernel_exploit(void);
1553 +
1554 /*
1555 * This function is protected against re-entrancy.
1556 */
1557 @@ -288,6 +290,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1558 panic("Fatal exception in interrupt");
1559 if (panic_on_oops)
1560 panic("Fatal exception");
1561 +
1562 + gr_handle_kernel_exploit();
1563 +
1564 if (ret != NOTIFY_STOP)
1565 do_exit(SIGSEGV);
1566 }
1567 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1568 index 66a477a..bee61d3 100644
1569 --- a/arch/arm/lib/copy_from_user.S
1570 +++ b/arch/arm/lib/copy_from_user.S
1571 @@ -16,7 +16,7 @@
1572 /*
1573 * Prototype:
1574 *
1575 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1576 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1577 *
1578 * Purpose:
1579 *
1580 @@ -84,11 +84,11 @@
1581
1582 .text
1583
1584 -ENTRY(__copy_from_user)
1585 +ENTRY(___copy_from_user)
1586
1587 #include "copy_template.S"
1588
1589 -ENDPROC(__copy_from_user)
1590 +ENDPROC(___copy_from_user)
1591
1592 .pushsection .fixup,"ax"
1593 .align 0
1594 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1595 index 6ee2f67..d1cce76 100644
1596 --- a/arch/arm/lib/copy_page.S
1597 +++ b/arch/arm/lib/copy_page.S
1598 @@ -10,6 +10,7 @@
1599 * ASM optimised string functions
1600 */
1601 #include <linux/linkage.h>
1602 +#include <linux/const.h>
1603 #include <asm/assembler.h>
1604 #include <asm/asm-offsets.h>
1605 #include <asm/cache.h>
1606 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1607 index d066df6..df28194 100644
1608 --- a/arch/arm/lib/copy_to_user.S
1609 +++ b/arch/arm/lib/copy_to_user.S
1610 @@ -16,7 +16,7 @@
1611 /*
1612 * Prototype:
1613 *
1614 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1615 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1616 *
1617 * Purpose:
1618 *
1619 @@ -88,11 +88,11 @@
1620 .text
1621
1622 ENTRY(__copy_to_user_std)
1623 -WEAK(__copy_to_user)
1624 +WEAK(___copy_to_user)
1625
1626 #include "copy_template.S"
1627
1628 -ENDPROC(__copy_to_user)
1629 +ENDPROC(___copy_to_user)
1630 ENDPROC(__copy_to_user_std)
1631
1632 .pushsection .fixup,"ax"
1633 diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
1634 index d0ece2a..5ae2f39 100644
1635 --- a/arch/arm/lib/uaccess.S
1636 +++ b/arch/arm/lib/uaccess.S
1637 @@ -20,7 +20,7 @@
1638
1639 #define PAGE_SHIFT 12
1640
1641 -/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
1642 +/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
1643 * Purpose : copy a block to user memory from kernel memory
1644 * Params : to - user memory
1645 * : from - kernel memory
1646 @@ -40,7 +40,7 @@ USER( T(strgtb) r3, [r0], #1) @ May fault
1647 sub r2, r2, ip
1648 b .Lc2u_dest_aligned
1649
1650 -ENTRY(__copy_to_user)
1651 +ENTRY(___copy_to_user)
1652 stmfd sp!, {r2, r4 - r7, lr}
1653 cmp r2, #4
1654 blt .Lc2u_not_enough
1655 @@ -278,14 +278,14 @@ USER( T(strgeb) r3, [r0], #1) @ May fault
1656 ldrgtb r3, [r1], #0
1657 USER( T(strgtb) r3, [r0], #1) @ May fault
1658 b .Lc2u_finished
1659 -ENDPROC(__copy_to_user)
1660 +ENDPROC(___copy_to_user)
1661
1662 .pushsection .fixup,"ax"
1663 .align 0
1664 9001: ldmfd sp!, {r0, r4 - r7, pc}
1665 .popsection
1666
1667 -/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
1668 +/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
1669 * Purpose : copy a block from user memory to kernel memory
1670 * Params : to - kernel memory
1671 * : from - user memory
1672 @@ -304,7 +304,7 @@ USER( T(ldrgtb) r3, [r1], #1) @ May fault
1673 sub r2, r2, ip
1674 b .Lcfu_dest_aligned
1675
1676 -ENTRY(__copy_from_user)
1677 +ENTRY(___copy_from_user)
1678 stmfd sp!, {r0, r2, r4 - r7, lr}
1679 cmp r2, #4
1680 blt .Lcfu_not_enough
1681 @@ -544,7 +544,7 @@ USER( T(ldrgeb) r3, [r1], #1) @ May fault
1682 USER( T(ldrgtb) r3, [r1], #1) @ May fault
1683 strgtb r3, [r0], #1
1684 b .Lcfu_finished
1685 -ENDPROC(__copy_from_user)
1686 +ENDPROC(___copy_from_user)
1687
1688 .pushsection .fixup,"ax"
1689 .align 0
1690 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1691 index 025f742..8432b08 100644
1692 --- a/arch/arm/lib/uaccess_with_memcpy.c
1693 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1694 @@ -104,7 +104,7 @@ out:
1695 }
1696
1697 unsigned long
1698 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1699 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1700 {
1701 /*
1702 * This test is stubbed out of the main function above to keep
1703 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1704 index e9d5f4a..f099699 100644
1705 --- a/arch/arm/mach-omap2/board-n8x0.c
1706 +++ b/arch/arm/mach-omap2/board-n8x0.c
1707 @@ -593,7 +593,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1708 }
1709 #endif
1710
1711 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1712 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1713 .late_init = n8x0_menelaus_late_init,
1714 };
1715
1716 diff --git a/arch/arm/mach-ux500/mbox-db5500.c b/arch/arm/mach-ux500/mbox-db5500.c
1717 index 2b2d51c..0127490 100644
1718 --- a/arch/arm/mach-ux500/mbox-db5500.c
1719 +++ b/arch/arm/mach-ux500/mbox-db5500.c
1720 @@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct device *dev,
1721 return sprintf(buf, "0x%X\n", mbox_value);
1722 }
1723
1724 -static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1725 +static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1726
1727 static int mbox_show(struct seq_file *s, void *data)
1728 {
1729 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1730 index aa33949..d366075 100644
1731 --- a/arch/arm/mm/fault.c
1732 +++ b/arch/arm/mm/fault.c
1733 @@ -183,6 +183,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1734 }
1735 #endif
1736
1737 +#ifdef CONFIG_PAX_PAGEEXEC
1738 + if (fsr & FSR_LNX_PF) {
1739 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1740 + do_group_exit(SIGKILL);
1741 + }
1742 +#endif
1743 +
1744 tsk->thread.address = addr;
1745 tsk->thread.error_code = fsr;
1746 tsk->thread.trap_no = 14;
1747 @@ -384,6 +391,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1748 }
1749 #endif /* CONFIG_MMU */
1750
1751 +#ifdef CONFIG_PAX_PAGEEXEC
1752 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1753 +{
1754 + long i;
1755 +
1756 + printk(KERN_ERR "PAX: bytes at PC: ");
1757 + for (i = 0; i < 20; i++) {
1758 + unsigned char c;
1759 + if (get_user(c, (__force unsigned char __user *)pc+i))
1760 + printk(KERN_CONT "?? ");
1761 + else
1762 + printk(KERN_CONT "%02x ", c);
1763 + }
1764 + printk("\n");
1765 +
1766 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1767 + for (i = -1; i < 20; i++) {
1768 + unsigned long c;
1769 + if (get_user(c, (__force unsigned long __user *)sp+i))
1770 + printk(KERN_CONT "???????? ");
1771 + else
1772 + printk(KERN_CONT "%08lx ", c);
1773 + }
1774 + printk("\n");
1775 +}
1776 +#endif
1777 +
1778 /*
1779 * First Level Translation Fault Handler
1780 *
1781 @@ -628,6 +662,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1782 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1783 struct siginfo info;
1784
1785 +#ifdef CONFIG_PAX_REFCOUNT
1786 + if (fsr_fs(ifsr) == 2) {
1787 + unsigned int bkpt;
1788 +
1789 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1790 + current->thread.error_code = ifsr;
1791 + current->thread.trap_no = 0;
1792 + pax_report_refcount_overflow(regs);
1793 + fixup_exception(regs);
1794 + return;
1795 + }
1796 + }
1797 +#endif
1798 +
1799 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1800 return;
1801
1802 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1803 index 44b628e..623ee2a 100644
1804 --- a/arch/arm/mm/mmap.c
1805 +++ b/arch/arm/mm/mmap.c
1806 @@ -54,6 +54,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1807 if (len > TASK_SIZE)
1808 return -ENOMEM;
1809
1810 +#ifdef CONFIG_PAX_RANDMMAP
1811 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1812 +#endif
1813 +
1814 if (addr) {
1815 if (do_align)
1816 addr = COLOUR_ALIGN(addr, pgoff);
1817 @@ -61,15 +65,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1818 addr = PAGE_ALIGN(addr);
1819
1820 vma = find_vma(mm, addr);
1821 - if (TASK_SIZE - len >= addr &&
1822 - (!vma || addr + len <= vma->vm_start))
1823 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1824 return addr;
1825 }
1826 if (len > mm->cached_hole_size) {
1827 - start_addr = addr = mm->free_area_cache;
1828 + start_addr = addr = mm->free_area_cache;
1829 } else {
1830 - start_addr = addr = TASK_UNMAPPED_BASE;
1831 - mm->cached_hole_size = 0;
1832 + start_addr = addr = mm->mmap_base;
1833 + mm->cached_hole_size = 0;
1834 }
1835 /* 8 bits of randomness in 20 address space bits */
1836 if ((current->flags & PF_RANDOMIZE) &&
1837 @@ -89,14 +92,14 @@ full_search:
1838 * Start a new search - just in case we missed
1839 * some holes.
1840 */
1841 - if (start_addr != TASK_UNMAPPED_BASE) {
1842 - start_addr = addr = TASK_UNMAPPED_BASE;
1843 + if (start_addr != mm->mmap_base) {
1844 + start_addr = addr = mm->mmap_base;
1845 mm->cached_hole_size = 0;
1846 goto full_search;
1847 }
1848 return -ENOMEM;
1849 }
1850 - if (!vma || addr + len <= vma->vm_start) {
1851 + if (check_heap_stack_gap(vma, addr, len)) {
1852 /*
1853 * Remember the place where we stopped the search:
1854 */
1855 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
1856 index 4c1a363..df311d0 100644
1857 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
1858 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
1859 @@ -41,7 +41,7 @@ struct samsung_dma_ops {
1860 int (*started)(unsigned ch);
1861 int (*flush)(unsigned ch);
1862 int (*stop)(unsigned ch);
1863 -};
1864 +} __no_const;
1865
1866 extern void *samsung_dmadev_get_ops(void);
1867 extern void *s3c_dma_get_ops(void);
1868 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
1869 index 5f28cae..3d23723 100644
1870 --- a/arch/arm/plat-samsung/include/plat/ehci.h
1871 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
1872 @@ -14,7 +14,7 @@
1873 struct s5p_ehci_platdata {
1874 int (*phy_init)(struct platform_device *pdev, int type);
1875 int (*phy_exit)(struct platform_device *pdev, int type);
1876 -};
1877 +} __no_const;
1878
1879 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
1880
1881 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
1882 index c3a58a1..78fbf54 100644
1883 --- a/arch/avr32/include/asm/cache.h
1884 +++ b/arch/avr32/include/asm/cache.h
1885 @@ -1,8 +1,10 @@
1886 #ifndef __ASM_AVR32_CACHE_H
1887 #define __ASM_AVR32_CACHE_H
1888
1889 +#include <linux/const.h>
1890 +
1891 #define L1_CACHE_SHIFT 5
1892 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1893 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1894
1895 /*
1896 * Memory returned by kmalloc() may be used for DMA, so we must make
1897 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
1898 index 3b3159b..425ea94 100644
1899 --- a/arch/avr32/include/asm/elf.h
1900 +++ b/arch/avr32/include/asm/elf.h
1901 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
1902 the loader. We need to make sure that it is out of the way of the program
1903 that it will "exec", and that there is sufficient room for the brk. */
1904
1905 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1906 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1907
1908 +#ifdef CONFIG_PAX_ASLR
1909 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
1910 +
1911 +#define PAX_DELTA_MMAP_LEN 15
1912 +#define PAX_DELTA_STACK_LEN 15
1913 +#endif
1914
1915 /* This yields a mask that user programs can use to figure out what
1916 instruction set this CPU supports. This could be done in user space,
1917 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
1918 index b7f5c68..556135c 100644
1919 --- a/arch/avr32/include/asm/kmap_types.h
1920 +++ b/arch/avr32/include/asm/kmap_types.h
1921 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
1922 D(11) KM_IRQ1,
1923 D(12) KM_SOFTIRQ0,
1924 D(13) KM_SOFTIRQ1,
1925 -D(14) KM_TYPE_NR
1926 +D(14) KM_CLEARPAGE,
1927 +D(15) KM_TYPE_NR
1928 };
1929
1930 #undef D
1931 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
1932 index f7040a1..db9f300 100644
1933 --- a/arch/avr32/mm/fault.c
1934 +++ b/arch/avr32/mm/fault.c
1935 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
1936
1937 int exception_trace = 1;
1938
1939 +#ifdef CONFIG_PAX_PAGEEXEC
1940 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1941 +{
1942 + unsigned long i;
1943 +
1944 + printk(KERN_ERR "PAX: bytes at PC: ");
1945 + for (i = 0; i < 20; i++) {
1946 + unsigned char c;
1947 + if (get_user(c, (unsigned char *)pc+i))
1948 + printk(KERN_CONT "???????? ");
1949 + else
1950 + printk(KERN_CONT "%02x ", c);
1951 + }
1952 + printk("\n");
1953 +}
1954 +#endif
1955 +
1956 /*
1957 * This routine handles page faults. It determines the address and the
1958 * problem, and then passes it off to one of the appropriate routines.
1959 @@ -156,6 +173,16 @@ bad_area:
1960 up_read(&mm->mmap_sem);
1961
1962 if (user_mode(regs)) {
1963 +
1964 +#ifdef CONFIG_PAX_PAGEEXEC
1965 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1966 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
1967 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
1968 + do_group_exit(SIGKILL);
1969 + }
1970 + }
1971 +#endif
1972 +
1973 if (exception_trace && printk_ratelimit())
1974 printk("%s%s[%d]: segfault at %08lx pc %08lx "
1975 "sp %08lx ecr %lu\n",
1976 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
1977 index 568885a..f8008df 100644
1978 --- a/arch/blackfin/include/asm/cache.h
1979 +++ b/arch/blackfin/include/asm/cache.h
1980 @@ -7,6 +7,7 @@
1981 #ifndef __ARCH_BLACKFIN_CACHE_H
1982 #define __ARCH_BLACKFIN_CACHE_H
1983
1984 +#include <linux/const.h>
1985 #include <linux/linkage.h> /* for asmlinkage */
1986
1987 /*
1988 @@ -14,7 +15,7 @@
1989 * Blackfin loads 32 bytes for cache
1990 */
1991 #define L1_CACHE_SHIFT 5
1992 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1993 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1994 #define SMP_CACHE_BYTES L1_CACHE_BYTES
1995
1996 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
1997 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
1998 index aea2718..3639a60 100644
1999 --- a/arch/cris/include/arch-v10/arch/cache.h
2000 +++ b/arch/cris/include/arch-v10/arch/cache.h
2001 @@ -1,8 +1,9 @@
2002 #ifndef _ASM_ARCH_CACHE_H
2003 #define _ASM_ARCH_CACHE_H
2004
2005 +#include <linux/const.h>
2006 /* Etrax 100LX have 32-byte cache-lines. */
2007 -#define L1_CACHE_BYTES 32
2008 #define L1_CACHE_SHIFT 5
2009 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2010
2011 #endif /* _ASM_ARCH_CACHE_H */
2012 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2013 index 1de779f..336fad3 100644
2014 --- a/arch/cris/include/arch-v32/arch/cache.h
2015 +++ b/arch/cris/include/arch-v32/arch/cache.h
2016 @@ -1,11 +1,12 @@
2017 #ifndef _ASM_CRIS_ARCH_CACHE_H
2018 #define _ASM_CRIS_ARCH_CACHE_H
2019
2020 +#include <linux/const.h>
2021 #include <arch/hwregs/dma.h>
2022
2023 /* A cache-line is 32 bytes. */
2024 -#define L1_CACHE_BYTES 32
2025 #define L1_CACHE_SHIFT 5
2026 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2027
2028 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
2029
2030 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2031 index 0d8a7d6..d0c9ff5 100644
2032 --- a/arch/frv/include/asm/atomic.h
2033 +++ b/arch/frv/include/asm/atomic.h
2034 @@ -241,6 +241,16 @@ extern uint32_t __xchg_32(uint32_t i, volatile void *v);
2035 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2036 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2037
2038 +#define atomic64_read_unchecked(v) atomic64_read(v)
2039 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2040 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2041 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2042 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2043 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2044 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2045 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2046 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2047 +
2048 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2049 {
2050 int c, old;
2051 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2052 index 2797163..c2a401d 100644
2053 --- a/arch/frv/include/asm/cache.h
2054 +++ b/arch/frv/include/asm/cache.h
2055 @@ -12,10 +12,11 @@
2056 #ifndef __ASM_CACHE_H
2057 #define __ASM_CACHE_H
2058
2059 +#include <linux/const.h>
2060
2061 /* bytes per L1 cache line */
2062 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2063 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2064 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2065
2066 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2067 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2068 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2069 index f8e16b2..c73ff79 100644
2070 --- a/arch/frv/include/asm/kmap_types.h
2071 +++ b/arch/frv/include/asm/kmap_types.h
2072 @@ -23,6 +23,7 @@ enum km_type {
2073 KM_IRQ1,
2074 KM_SOFTIRQ0,
2075 KM_SOFTIRQ1,
2076 + KM_CLEARPAGE,
2077 KM_TYPE_NR
2078 };
2079
2080 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2081 index 385fd30..6c3d97e 100644
2082 --- a/arch/frv/mm/elf-fdpic.c
2083 +++ b/arch/frv/mm/elf-fdpic.c
2084 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2085 if (addr) {
2086 addr = PAGE_ALIGN(addr);
2087 vma = find_vma(current->mm, addr);
2088 - if (TASK_SIZE - len >= addr &&
2089 - (!vma || addr + len <= vma->vm_start))
2090 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2091 goto success;
2092 }
2093
2094 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2095 for (; vma; vma = vma->vm_next) {
2096 if (addr > limit)
2097 break;
2098 - if (addr + len <= vma->vm_start)
2099 + if (check_heap_stack_gap(vma, addr, len))
2100 goto success;
2101 addr = vma->vm_end;
2102 }
2103 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2104 for (; vma; vma = vma->vm_next) {
2105 if (addr > limit)
2106 break;
2107 - if (addr + len <= vma->vm_start)
2108 + if (check_heap_stack_gap(vma, addr, len))
2109 goto success;
2110 addr = vma->vm_end;
2111 }
2112 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2113 index c635028..6d9445a 100644
2114 --- a/arch/h8300/include/asm/cache.h
2115 +++ b/arch/h8300/include/asm/cache.h
2116 @@ -1,8 +1,10 @@
2117 #ifndef __ARCH_H8300_CACHE_H
2118 #define __ARCH_H8300_CACHE_H
2119
2120 +#include <linux/const.h>
2121 +
2122 /* bytes per L1 cache line */
2123 -#define L1_CACHE_BYTES 4
2124 +#define L1_CACHE_BYTES _AC(4,UL)
2125
2126 /* m68k-elf-gcc 2.95.2 doesn't like these */
2127
2128 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2129 index 0f01de2..d37d309 100644
2130 --- a/arch/hexagon/include/asm/cache.h
2131 +++ b/arch/hexagon/include/asm/cache.h
2132 @@ -21,9 +21,11 @@
2133 #ifndef __ASM_CACHE_H
2134 #define __ASM_CACHE_H
2135
2136 +#include <linux/const.h>
2137 +
2138 /* Bytes per L1 cache line */
2139 -#define L1_CACHE_SHIFT (5)
2140 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2141 +#define L1_CACHE_SHIFT 5
2142 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2143
2144 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2145 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2146 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2147 index 3fad89e..3047da5 100644
2148 --- a/arch/ia64/include/asm/atomic.h
2149 +++ b/arch/ia64/include/asm/atomic.h
2150 @@ -209,6 +209,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2151 #define atomic64_inc(v) atomic64_add(1, (v))
2152 #define atomic64_dec(v) atomic64_sub(1, (v))
2153
2154 +#define atomic64_read_unchecked(v) atomic64_read(v)
2155 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2156 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2157 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2158 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2159 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2160 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2161 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2162 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2163 +
2164 /* Atomic operations are already serializing */
2165 #define smp_mb__before_atomic_dec() barrier()
2166 #define smp_mb__after_atomic_dec() barrier()
2167 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2168 index 988254a..e1ee885 100644
2169 --- a/arch/ia64/include/asm/cache.h
2170 +++ b/arch/ia64/include/asm/cache.h
2171 @@ -1,6 +1,7 @@
2172 #ifndef _ASM_IA64_CACHE_H
2173 #define _ASM_IA64_CACHE_H
2174
2175 +#include <linux/const.h>
2176
2177 /*
2178 * Copyright (C) 1998-2000 Hewlett-Packard Co
2179 @@ -9,7 +10,7 @@
2180
2181 /* Bytes per L1 (data) cache line. */
2182 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2183 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2184 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2185
2186 #ifdef CONFIG_SMP
2187 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2188 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2189 index b5298eb..67c6e62 100644
2190 --- a/arch/ia64/include/asm/elf.h
2191 +++ b/arch/ia64/include/asm/elf.h
2192 @@ -42,6 +42,13 @@
2193 */
2194 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2195
2196 +#ifdef CONFIG_PAX_ASLR
2197 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2198 +
2199 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2200 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2201 +#endif
2202 +
2203 #define PT_IA_64_UNWIND 0x70000001
2204
2205 /* IA-64 relocations: */
2206 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2207 index 1a97af3..7529d31 100644
2208 --- a/arch/ia64/include/asm/pgtable.h
2209 +++ b/arch/ia64/include/asm/pgtable.h
2210 @@ -12,7 +12,7 @@
2211 * David Mosberger-Tang <davidm@hpl.hp.com>
2212 */
2213
2214 -
2215 +#include <linux/const.h>
2216 #include <asm/mman.h>
2217 #include <asm/page.h>
2218 #include <asm/processor.h>
2219 @@ -143,6 +143,17 @@
2220 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2221 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2222 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2223 +
2224 +#ifdef CONFIG_PAX_PAGEEXEC
2225 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2226 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2227 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2228 +#else
2229 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2230 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2231 +# define PAGE_COPY_NOEXEC PAGE_COPY
2232 +#endif
2233 +
2234 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2235 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2236 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2237 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2238 index b77768d..e0795eb 100644
2239 --- a/arch/ia64/include/asm/spinlock.h
2240 +++ b/arch/ia64/include/asm/spinlock.h
2241 @@ -72,7 +72,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2242 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2243
2244 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2245 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2246 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2247 }
2248
2249 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2250 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2251 index 449c8c0..432a3d2 100644
2252 --- a/arch/ia64/include/asm/uaccess.h
2253 +++ b/arch/ia64/include/asm/uaccess.h
2254 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2255 const void *__cu_from = (from); \
2256 long __cu_len = (n); \
2257 \
2258 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2259 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2260 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2261 __cu_len; \
2262 })
2263 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2264 long __cu_len = (n); \
2265 \
2266 __chk_user_ptr(__cu_from); \
2267 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2268 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2269 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2270 __cu_len; \
2271 })
2272 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2273 index 24603be..948052d 100644
2274 --- a/arch/ia64/kernel/module.c
2275 +++ b/arch/ia64/kernel/module.c
2276 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2277 void
2278 module_free (struct module *mod, void *module_region)
2279 {
2280 - if (mod && mod->arch.init_unw_table &&
2281 - module_region == mod->module_init) {
2282 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2283 unw_remove_unwind_table(mod->arch.init_unw_table);
2284 mod->arch.init_unw_table = NULL;
2285 }
2286 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2287 }
2288
2289 static inline int
2290 +in_init_rx (const struct module *mod, uint64_t addr)
2291 +{
2292 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2293 +}
2294 +
2295 +static inline int
2296 +in_init_rw (const struct module *mod, uint64_t addr)
2297 +{
2298 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2299 +}
2300 +
2301 +static inline int
2302 in_init (const struct module *mod, uint64_t addr)
2303 {
2304 - return addr - (uint64_t) mod->module_init < mod->init_size;
2305 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2306 +}
2307 +
2308 +static inline int
2309 +in_core_rx (const struct module *mod, uint64_t addr)
2310 +{
2311 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2312 +}
2313 +
2314 +static inline int
2315 +in_core_rw (const struct module *mod, uint64_t addr)
2316 +{
2317 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2318 }
2319
2320 static inline int
2321 in_core (const struct module *mod, uint64_t addr)
2322 {
2323 - return addr - (uint64_t) mod->module_core < mod->core_size;
2324 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2325 }
2326
2327 static inline int
2328 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2329 break;
2330
2331 case RV_BDREL:
2332 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2333 + if (in_init_rx(mod, val))
2334 + val -= (uint64_t) mod->module_init_rx;
2335 + else if (in_init_rw(mod, val))
2336 + val -= (uint64_t) mod->module_init_rw;
2337 + else if (in_core_rx(mod, val))
2338 + val -= (uint64_t) mod->module_core_rx;
2339 + else if (in_core_rw(mod, val))
2340 + val -= (uint64_t) mod->module_core_rw;
2341 break;
2342
2343 case RV_LTV:
2344 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2345 * addresses have been selected...
2346 */
2347 uint64_t gp;
2348 - if (mod->core_size > MAX_LTOFF)
2349 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2350 /*
2351 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2352 * at the end of the module.
2353 */
2354 - gp = mod->core_size - MAX_LTOFF / 2;
2355 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2356 else
2357 - gp = mod->core_size / 2;
2358 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2359 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2360 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2361 mod->arch.gp = gp;
2362 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2363 }
2364 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2365 index 609d500..7dde2a8 100644
2366 --- a/arch/ia64/kernel/sys_ia64.c
2367 +++ b/arch/ia64/kernel/sys_ia64.c
2368 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2369 if (REGION_NUMBER(addr) == RGN_HPAGE)
2370 addr = 0;
2371 #endif
2372 +
2373 +#ifdef CONFIG_PAX_RANDMMAP
2374 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2375 + addr = mm->free_area_cache;
2376 + else
2377 +#endif
2378 +
2379 if (!addr)
2380 addr = mm->free_area_cache;
2381
2382 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2383 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2384 /* At this point: (!vma || addr < vma->vm_end). */
2385 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2386 - if (start_addr != TASK_UNMAPPED_BASE) {
2387 + if (start_addr != mm->mmap_base) {
2388 /* Start a new search --- just in case we missed some holes. */
2389 - addr = TASK_UNMAPPED_BASE;
2390 + addr = mm->mmap_base;
2391 goto full_search;
2392 }
2393 return -ENOMEM;
2394 }
2395 - if (!vma || addr + len <= vma->vm_start) {
2396 + if (check_heap_stack_gap(vma, addr, len)) {
2397 /* Remember the address where we stopped this search: */
2398 mm->free_area_cache = addr + len;
2399 return addr;
2400 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2401 index 53c0ba0..2accdde 100644
2402 --- a/arch/ia64/kernel/vmlinux.lds.S
2403 +++ b/arch/ia64/kernel/vmlinux.lds.S
2404 @@ -199,7 +199,7 @@ SECTIONS {
2405 /* Per-cpu data: */
2406 . = ALIGN(PERCPU_PAGE_SIZE);
2407 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2408 - __phys_per_cpu_start = __per_cpu_load;
2409 + __phys_per_cpu_start = per_cpu_load;
2410 /*
2411 * ensure percpu data fits
2412 * into percpu page size
2413 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2414 index 20b3593..1ce77f0 100644
2415 --- a/arch/ia64/mm/fault.c
2416 +++ b/arch/ia64/mm/fault.c
2417 @@ -73,6 +73,23 @@ mapped_kernel_page_is_present (unsigned long address)
2418 return pte_present(pte);
2419 }
2420
2421 +#ifdef CONFIG_PAX_PAGEEXEC
2422 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2423 +{
2424 + unsigned long i;
2425 +
2426 + printk(KERN_ERR "PAX: bytes at PC: ");
2427 + for (i = 0; i < 8; i++) {
2428 + unsigned int c;
2429 + if (get_user(c, (unsigned int *)pc+i))
2430 + printk(KERN_CONT "???????? ");
2431 + else
2432 + printk(KERN_CONT "%08x ", c);
2433 + }
2434 + printk("\n");
2435 +}
2436 +#endif
2437 +
2438 void __kprobes
2439 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2440 {
2441 @@ -146,9 +163,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2442 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2443 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2444
2445 - if ((vma->vm_flags & mask) != mask)
2446 + if ((vma->vm_flags & mask) != mask) {
2447 +
2448 +#ifdef CONFIG_PAX_PAGEEXEC
2449 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2450 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2451 + goto bad_area;
2452 +
2453 + up_read(&mm->mmap_sem);
2454 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2455 + do_group_exit(SIGKILL);
2456 + }
2457 +#endif
2458 +
2459 goto bad_area;
2460
2461 + }
2462 +
2463 /*
2464 * If for any reason at all we couldn't handle the fault, make
2465 * sure we exit gracefully rather than endlessly redo the
2466 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2467 index 5ca674b..e0e1b70 100644
2468 --- a/arch/ia64/mm/hugetlbpage.c
2469 +++ b/arch/ia64/mm/hugetlbpage.c
2470 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2471 /* At this point: (!vmm || addr < vmm->vm_end). */
2472 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2473 return -ENOMEM;
2474 - if (!vmm || (addr + len) <= vmm->vm_start)
2475 + if (check_heap_stack_gap(vmm, addr, len))
2476 return addr;
2477 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2478 }
2479 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2480 index 00cb0e2..2ad8024 100644
2481 --- a/arch/ia64/mm/init.c
2482 +++ b/arch/ia64/mm/init.c
2483 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2484 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2485 vma->vm_end = vma->vm_start + PAGE_SIZE;
2486 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2487 +
2488 +#ifdef CONFIG_PAX_PAGEEXEC
2489 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2490 + vma->vm_flags &= ~VM_EXEC;
2491 +
2492 +#ifdef CONFIG_PAX_MPROTECT
2493 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2494 + vma->vm_flags &= ~VM_MAYEXEC;
2495 +#endif
2496 +
2497 + }
2498 +#endif
2499 +
2500 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2501 down_write(&current->mm->mmap_sem);
2502 if (insert_vm_struct(current->mm, vma)) {
2503 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2504 index 40b3ee9..8c2c112 100644
2505 --- a/arch/m32r/include/asm/cache.h
2506 +++ b/arch/m32r/include/asm/cache.h
2507 @@ -1,8 +1,10 @@
2508 #ifndef _ASM_M32R_CACHE_H
2509 #define _ASM_M32R_CACHE_H
2510
2511 +#include <linux/const.h>
2512 +
2513 /* L1 cache line size */
2514 #define L1_CACHE_SHIFT 4
2515 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2516 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2517
2518 #endif /* _ASM_M32R_CACHE_H */
2519 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2520 index 82abd15..d95ae5d 100644
2521 --- a/arch/m32r/lib/usercopy.c
2522 +++ b/arch/m32r/lib/usercopy.c
2523 @@ -14,6 +14,9 @@
2524 unsigned long
2525 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2526 {
2527 + if ((long)n < 0)
2528 + return n;
2529 +
2530 prefetch(from);
2531 if (access_ok(VERIFY_WRITE, to, n))
2532 __copy_user(to,from,n);
2533 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2534 unsigned long
2535 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2536 {
2537 + if ((long)n < 0)
2538 + return n;
2539 +
2540 prefetchw(to);
2541 if (access_ok(VERIFY_READ, from, n))
2542 __copy_user_zeroing(to,from,n);
2543 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2544 index 0395c51..5f26031 100644
2545 --- a/arch/m68k/include/asm/cache.h
2546 +++ b/arch/m68k/include/asm/cache.h
2547 @@ -4,9 +4,11 @@
2548 #ifndef __ARCH_M68K_CACHE_H
2549 #define __ARCH_M68K_CACHE_H
2550
2551 +#include <linux/const.h>
2552 +
2553 /* bytes per L1 cache line */
2554 #define L1_CACHE_SHIFT 4
2555 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2556 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2557
2558 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2559
2560 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2561 index 4efe96a..60e8699 100644
2562 --- a/arch/microblaze/include/asm/cache.h
2563 +++ b/arch/microblaze/include/asm/cache.h
2564 @@ -13,11 +13,12 @@
2565 #ifndef _ASM_MICROBLAZE_CACHE_H
2566 #define _ASM_MICROBLAZE_CACHE_H
2567
2568 +#include <linux/const.h>
2569 #include <asm/registers.h>
2570
2571 #define L1_CACHE_SHIFT 5
2572 /* word-granular cache in microblaze */
2573 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2574 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2575
2576 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2577
2578 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2579 index 1d93f81..67794d0 100644
2580 --- a/arch/mips/include/asm/atomic.h
2581 +++ b/arch/mips/include/asm/atomic.h
2582 @@ -21,6 +21,10 @@
2583 #include <asm/war.h>
2584 #include <asm/system.h>
2585
2586 +#ifdef CONFIG_GENERIC_ATOMIC64
2587 +#include <asm-generic/atomic64.h>
2588 +#endif
2589 +
2590 #define ATOMIC_INIT(i) { (i) }
2591
2592 /*
2593 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2594 */
2595 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2596
2597 +#define atomic64_read_unchecked(v) atomic64_read(v)
2598 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2599 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2600 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2601 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2602 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2603 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2604 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2605 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2606 +
2607 #endif /* CONFIG_64BIT */
2608
2609 /*
2610 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2611 index b4db69f..8f3b093 100644
2612 --- a/arch/mips/include/asm/cache.h
2613 +++ b/arch/mips/include/asm/cache.h
2614 @@ -9,10 +9,11 @@
2615 #ifndef _ASM_CACHE_H
2616 #define _ASM_CACHE_H
2617
2618 +#include <linux/const.h>
2619 #include <kmalloc.h>
2620
2621 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2622 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2623 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2624
2625 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2626 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2627 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2628 index 455c0ac..ad65fbe 100644
2629 --- a/arch/mips/include/asm/elf.h
2630 +++ b/arch/mips/include/asm/elf.h
2631 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2632 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2633 #endif
2634
2635 +#ifdef CONFIG_PAX_ASLR
2636 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2637 +
2638 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2639 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2640 +#endif
2641 +
2642 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2643 struct linux_binprm;
2644 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2645 int uses_interp);
2646
2647 -struct mm_struct;
2648 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2649 -#define arch_randomize_brk arch_randomize_brk
2650 -
2651 #endif /* _ASM_ELF_H */
2652 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2653 index e59cd1a..8e329d6 100644
2654 --- a/arch/mips/include/asm/page.h
2655 +++ b/arch/mips/include/asm/page.h
2656 @@ -93,7 +93,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2657 #ifdef CONFIG_CPU_MIPS32
2658 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2659 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2660 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2661 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2662 #else
2663 typedef struct { unsigned long long pte; } pte_t;
2664 #define pte_val(x) ((x).pte)
2665 diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
2666 index 6018c80..7c37203 100644
2667 --- a/arch/mips/include/asm/system.h
2668 +++ b/arch/mips/include/asm/system.h
2669 @@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
2670 */
2671 #define __ARCH_WANT_UNLOCKED_CTXSW
2672
2673 -extern unsigned long arch_align_stack(unsigned long sp);
2674 +#define arch_align_stack(x) ((x) & ~0xfUL)
2675
2676 #endif /* _ASM_SYSTEM_H */
2677 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2678 index 9fdd8bc..4bd7f1a 100644
2679 --- a/arch/mips/kernel/binfmt_elfn32.c
2680 +++ b/arch/mips/kernel/binfmt_elfn32.c
2681 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2682 #undef ELF_ET_DYN_BASE
2683 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2684
2685 +#ifdef CONFIG_PAX_ASLR
2686 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2687 +
2688 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2689 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2690 +#endif
2691 +
2692 #include <asm/processor.h>
2693 #include <linux/module.h>
2694 #include <linux/elfcore.h>
2695 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2696 index ff44823..97f8906 100644
2697 --- a/arch/mips/kernel/binfmt_elfo32.c
2698 +++ b/arch/mips/kernel/binfmt_elfo32.c
2699 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2700 #undef ELF_ET_DYN_BASE
2701 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2702
2703 +#ifdef CONFIG_PAX_ASLR
2704 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2705 +
2706 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2707 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2708 +#endif
2709 +
2710 #include <asm/processor.h>
2711
2712 /*
2713 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2714 index c47f96e..661d418 100644
2715 --- a/arch/mips/kernel/process.c
2716 +++ b/arch/mips/kernel/process.c
2717 @@ -481,15 +481,3 @@ unsigned long get_wchan(struct task_struct *task)
2718 out:
2719 return pc;
2720 }
2721 -
2722 -/*
2723 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2724 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2725 - */
2726 -unsigned long arch_align_stack(unsigned long sp)
2727 -{
2728 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2729 - sp -= get_random_int() & ~PAGE_MASK;
2730 -
2731 - return sp & ALMASK;
2732 -}
2733 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
2734 index 937cf33..adb39bb 100644
2735 --- a/arch/mips/mm/fault.c
2736 +++ b/arch/mips/mm/fault.c
2737 @@ -28,6 +28,23 @@
2738 #include <asm/highmem.h> /* For VMALLOC_END */
2739 #include <linux/kdebug.h>
2740
2741 +#ifdef CONFIG_PAX_PAGEEXEC
2742 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2743 +{
2744 + unsigned long i;
2745 +
2746 + printk(KERN_ERR "PAX: bytes at PC: ");
2747 + for (i = 0; i < 5; i++) {
2748 + unsigned int c;
2749 + if (get_user(c, (unsigned int *)pc+i))
2750 + printk(KERN_CONT "???????? ");
2751 + else
2752 + printk(KERN_CONT "%08x ", c);
2753 + }
2754 + printk("\n");
2755 +}
2756 +#endif
2757 +
2758 /*
2759 * This routine handles page faults. It determines the address,
2760 * and the problem, and then passes it off to one of the appropriate
2761 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
2762 index 302d779..7d35bf8 100644
2763 --- a/arch/mips/mm/mmap.c
2764 +++ b/arch/mips/mm/mmap.c
2765 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2766 do_color_align = 1;
2767
2768 /* requesting a specific address */
2769 +
2770 +#ifdef CONFIG_PAX_RANDMMAP
2771 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2772 +#endif
2773 +
2774 if (addr) {
2775 if (do_color_align)
2776 addr = COLOUR_ALIGN(addr, pgoff);
2777 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2778 addr = PAGE_ALIGN(addr);
2779
2780 vma = find_vma(mm, addr);
2781 - if (TASK_SIZE - len >= addr &&
2782 - (!vma || addr + len <= vma->vm_start))
2783 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
2784 return addr;
2785 }
2786
2787 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2788 /* At this point: (!vma || addr < vma->vm_end). */
2789 if (TASK_SIZE - len < addr)
2790 return -ENOMEM;
2791 - if (!vma || addr + len <= vma->vm_start)
2792 + if (check_heap_stack_gap(vmm, addr, len))
2793 return addr;
2794 addr = vma->vm_end;
2795 if (do_color_align)
2796 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2797 /* make sure it can fit in the remaining address space */
2798 if (likely(addr > len)) {
2799 vma = find_vma(mm, addr - len);
2800 - if (!vma || addr <= vma->vm_start) {
2801 + if (check_heap_stack_gap(vmm, addr - len, len))
2802 /* cache the address as a hint for next time */
2803 return mm->free_area_cache = addr - len;
2804 }
2805 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2806 * return with success:
2807 */
2808 vma = find_vma(mm, addr);
2809 - if (likely(!vma || addr + len <= vma->vm_start)) {
2810 + if (check_heap_stack_gap(vmm, addr, len)) {
2811 /* cache the address as a hint for next time */
2812 return mm->free_area_cache = addr;
2813 }
2814 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2815 mm->unmap_area = arch_unmap_area_topdown;
2816 }
2817 }
2818 -
2819 -static inline unsigned long brk_rnd(void)
2820 -{
2821 - unsigned long rnd = get_random_int();
2822 -
2823 - rnd = rnd << PAGE_SHIFT;
2824 - /* 8MB for 32bit, 256MB for 64bit */
2825 - if (TASK_IS_32BIT_ADDR)
2826 - rnd = rnd & 0x7ffffful;
2827 - else
2828 - rnd = rnd & 0xffffffful;
2829 -
2830 - return rnd;
2831 -}
2832 -
2833 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2834 -{
2835 - unsigned long base = mm->brk;
2836 - unsigned long ret;
2837 -
2838 - ret = PAGE_ALIGN(base + brk_rnd());
2839 -
2840 - if (ret < mm->brk)
2841 - return mm->brk;
2842 -
2843 - return ret;
2844 -}
2845 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
2846 index 967d144..db12197 100644
2847 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
2848 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
2849 @@ -11,12 +11,14 @@
2850 #ifndef _ASM_PROC_CACHE_H
2851 #define _ASM_PROC_CACHE_H
2852
2853 +#include <linux/const.h>
2854 +
2855 /* L1 cache */
2856
2857 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
2858 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
2859 -#define L1_CACHE_BYTES 16 /* bytes per entry */
2860 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
2861 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
2862 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
2863
2864 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
2865 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2866 index bcb5df2..84fabd2 100644
2867 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2868 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2869 @@ -16,13 +16,15 @@
2870 #ifndef _ASM_PROC_CACHE_H
2871 #define _ASM_PROC_CACHE_H
2872
2873 +#include <linux/const.h>
2874 +
2875 /*
2876 * L1 cache
2877 */
2878 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
2879 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
2880 -#define L1_CACHE_BYTES 32 /* bytes per entry */
2881 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
2882 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
2883 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
2884
2885 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
2886 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
2887 index 4ce7a01..449202a 100644
2888 --- a/arch/openrisc/include/asm/cache.h
2889 +++ b/arch/openrisc/include/asm/cache.h
2890 @@ -19,11 +19,13 @@
2891 #ifndef __ASM_OPENRISC_CACHE_H
2892 #define __ASM_OPENRISC_CACHE_H
2893
2894 +#include <linux/const.h>
2895 +
2896 /* FIXME: How can we replace these with values from the CPU...
2897 * they shouldn't be hard-coded!
2898 */
2899
2900 -#define L1_CACHE_BYTES 16
2901 #define L1_CACHE_SHIFT 4
2902 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2903
2904 #endif /* __ASM_OPENRISC_CACHE_H */
2905 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
2906 index 4054b31..a10c105 100644
2907 --- a/arch/parisc/include/asm/atomic.h
2908 +++ b/arch/parisc/include/asm/atomic.h
2909 @@ -335,6 +335,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2910
2911 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
2912
2913 +#define atomic64_read_unchecked(v) atomic64_read(v)
2914 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2915 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2916 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2917 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2918 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2919 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2920 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2921 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2922 +
2923 #endif /* !CONFIG_64BIT */
2924
2925
2926 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
2927 index 47f11c7..3420df2 100644
2928 --- a/arch/parisc/include/asm/cache.h
2929 +++ b/arch/parisc/include/asm/cache.h
2930 @@ -5,6 +5,7 @@
2931 #ifndef __ARCH_PARISC_CACHE_H
2932 #define __ARCH_PARISC_CACHE_H
2933
2934 +#include <linux/const.h>
2935
2936 /*
2937 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
2938 @@ -15,13 +16,13 @@
2939 * just ruin performance.
2940 */
2941 #ifdef CONFIG_PA20
2942 -#define L1_CACHE_BYTES 64
2943 #define L1_CACHE_SHIFT 6
2944 #else
2945 -#define L1_CACHE_BYTES 32
2946 #define L1_CACHE_SHIFT 5
2947 #endif
2948
2949 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2950 +
2951 #ifndef __ASSEMBLY__
2952
2953 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2954 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
2955 index 19f6cb1..6c78cf2 100644
2956 --- a/arch/parisc/include/asm/elf.h
2957 +++ b/arch/parisc/include/asm/elf.h
2958 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
2959
2960 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
2961
2962 +#ifdef CONFIG_PAX_ASLR
2963 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
2964 +
2965 +#define PAX_DELTA_MMAP_LEN 16
2966 +#define PAX_DELTA_STACK_LEN 16
2967 +#endif
2968 +
2969 /* This yields a mask that user programs can use to figure out what
2970 instruction set this CPU supports. This could be done in user space,
2971 but it's not easy, and we've already done it here. */
2972 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
2973 index 22dadeb..f6c2be4 100644
2974 --- a/arch/parisc/include/asm/pgtable.h
2975 +++ b/arch/parisc/include/asm/pgtable.h
2976 @@ -210,6 +210,17 @@ struct vm_area_struct;
2977 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
2978 #define PAGE_COPY PAGE_EXECREAD
2979 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
2980 +
2981 +#ifdef CONFIG_PAX_PAGEEXEC
2982 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
2983 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2984 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2985 +#else
2986 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2987 +# define PAGE_COPY_NOEXEC PAGE_COPY
2988 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2989 +#endif
2990 +
2991 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
2992 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
2993 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
2994 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
2995 index 5e34ccf..672bc9c 100644
2996 --- a/arch/parisc/kernel/module.c
2997 +++ b/arch/parisc/kernel/module.c
2998 @@ -98,16 +98,38 @@
2999
3000 /* three functions to determine where in the module core
3001 * or init pieces the location is */
3002 +static inline int in_init_rx(struct module *me, void *loc)
3003 +{
3004 + return (loc >= me->module_init_rx &&
3005 + loc < (me->module_init_rx + me->init_size_rx));
3006 +}
3007 +
3008 +static inline int in_init_rw(struct module *me, void *loc)
3009 +{
3010 + return (loc >= me->module_init_rw &&
3011 + loc < (me->module_init_rw + me->init_size_rw));
3012 +}
3013 +
3014 static inline int in_init(struct module *me, void *loc)
3015 {
3016 - return (loc >= me->module_init &&
3017 - loc <= (me->module_init + me->init_size));
3018 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3019 +}
3020 +
3021 +static inline int in_core_rx(struct module *me, void *loc)
3022 +{
3023 + return (loc >= me->module_core_rx &&
3024 + loc < (me->module_core_rx + me->core_size_rx));
3025 +}
3026 +
3027 +static inline int in_core_rw(struct module *me, void *loc)
3028 +{
3029 + return (loc >= me->module_core_rw &&
3030 + loc < (me->module_core_rw + me->core_size_rw));
3031 }
3032
3033 static inline int in_core(struct module *me, void *loc)
3034 {
3035 - return (loc >= me->module_core &&
3036 - loc <= (me->module_core + me->core_size));
3037 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3038 }
3039
3040 static inline int in_local(struct module *me, void *loc)
3041 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3042 }
3043
3044 /* align things a bit */
3045 - me->core_size = ALIGN(me->core_size, 16);
3046 - me->arch.got_offset = me->core_size;
3047 - me->core_size += gots * sizeof(struct got_entry);
3048 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3049 + me->arch.got_offset = me->core_size_rw;
3050 + me->core_size_rw += gots * sizeof(struct got_entry);
3051
3052 - me->core_size = ALIGN(me->core_size, 16);
3053 - me->arch.fdesc_offset = me->core_size;
3054 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3055 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3056 + me->arch.fdesc_offset = me->core_size_rw;
3057 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3058
3059 me->arch.got_max = gots;
3060 me->arch.fdesc_max = fdescs;
3061 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3062
3063 BUG_ON(value == 0);
3064
3065 - got = me->module_core + me->arch.got_offset;
3066 + got = me->module_core_rw + me->arch.got_offset;
3067 for (i = 0; got[i].addr; i++)
3068 if (got[i].addr == value)
3069 goto out;
3070 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3071 #ifdef CONFIG_64BIT
3072 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3073 {
3074 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3075 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3076
3077 if (!value) {
3078 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3079 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3080
3081 /* Create new one */
3082 fdesc->addr = value;
3083 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3084 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3085 return (Elf_Addr)fdesc;
3086 }
3087 #endif /* CONFIG_64BIT */
3088 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3089
3090 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3091 end = table + sechdrs[me->arch.unwind_section].sh_size;
3092 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3093 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3094
3095 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3096 me->arch.unwind_section, table, end, gp);
3097 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3098 index c9b9322..02d8940 100644
3099 --- a/arch/parisc/kernel/sys_parisc.c
3100 +++ b/arch/parisc/kernel/sys_parisc.c
3101 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3102 /* At this point: (!vma || addr < vma->vm_end). */
3103 if (TASK_SIZE - len < addr)
3104 return -ENOMEM;
3105 - if (!vma || addr + len <= vma->vm_start)
3106 + if (check_heap_stack_gap(vma, addr, len))
3107 return addr;
3108 addr = vma->vm_end;
3109 }
3110 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3111 /* At this point: (!vma || addr < vma->vm_end). */
3112 if (TASK_SIZE - len < addr)
3113 return -ENOMEM;
3114 - if (!vma || addr + len <= vma->vm_start)
3115 + if (check_heap_stack_gap(vma, addr, len))
3116 return addr;
3117 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3118 if (addr < vma->vm_end) /* handle wraparound */
3119 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3120 if (flags & MAP_FIXED)
3121 return addr;
3122 if (!addr)
3123 - addr = TASK_UNMAPPED_BASE;
3124 + addr = current->mm->mmap_base;
3125
3126 if (filp) {
3127 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3128 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3129 index f19e660..414fe24 100644
3130 --- a/arch/parisc/kernel/traps.c
3131 +++ b/arch/parisc/kernel/traps.c
3132 @@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3133
3134 down_read(&current->mm->mmap_sem);
3135 vma = find_vma(current->mm,regs->iaoq[0]);
3136 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3137 - && (vma->vm_flags & VM_EXEC)) {
3138 -
3139 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3140 fault_address = regs->iaoq[0];
3141 fault_space = regs->iasq[0];
3142
3143 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3144 index 18162ce..94de376 100644
3145 --- a/arch/parisc/mm/fault.c
3146 +++ b/arch/parisc/mm/fault.c
3147 @@ -15,6 +15,7 @@
3148 #include <linux/sched.h>
3149 #include <linux/interrupt.h>
3150 #include <linux/module.h>
3151 +#include <linux/unistd.h>
3152
3153 #include <asm/uaccess.h>
3154 #include <asm/traps.h>
3155 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3156 static unsigned long
3157 parisc_acctyp(unsigned long code, unsigned int inst)
3158 {
3159 - if (code == 6 || code == 16)
3160 + if (code == 6 || code == 7 || code == 16)
3161 return VM_EXEC;
3162
3163 switch (inst & 0xf0000000) {
3164 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3165 }
3166 #endif
3167
3168 +#ifdef CONFIG_PAX_PAGEEXEC
3169 +/*
3170 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3171 + *
3172 + * returns 1 when task should be killed
3173 + * 2 when rt_sigreturn trampoline was detected
3174 + * 3 when unpatched PLT trampoline was detected
3175 + */
3176 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3177 +{
3178 +
3179 +#ifdef CONFIG_PAX_EMUPLT
3180 + int err;
3181 +
3182 + do { /* PaX: unpatched PLT emulation */
3183 + unsigned int bl, depwi;
3184 +
3185 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3186 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3187 +
3188 + if (err)
3189 + break;
3190 +
3191 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3192 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3193 +
3194 + err = get_user(ldw, (unsigned int *)addr);
3195 + err |= get_user(bv, (unsigned int *)(addr+4));
3196 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3197 +
3198 + if (err)
3199 + break;
3200 +
3201 + if (ldw == 0x0E801096U &&
3202 + bv == 0xEAC0C000U &&
3203 + ldw2 == 0x0E881095U)
3204 + {
3205 + unsigned int resolver, map;
3206 +
3207 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3208 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3209 + if (err)
3210 + break;
3211 +
3212 + regs->gr[20] = instruction_pointer(regs)+8;
3213 + regs->gr[21] = map;
3214 + regs->gr[22] = resolver;
3215 + regs->iaoq[0] = resolver | 3UL;
3216 + regs->iaoq[1] = regs->iaoq[0] + 4;
3217 + return 3;
3218 + }
3219 + }
3220 + } while (0);
3221 +#endif
3222 +
3223 +#ifdef CONFIG_PAX_EMUTRAMP
3224 +
3225 +#ifndef CONFIG_PAX_EMUSIGRT
3226 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3227 + return 1;
3228 +#endif
3229 +
3230 + do { /* PaX: rt_sigreturn emulation */
3231 + unsigned int ldi1, ldi2, bel, nop;
3232 +
3233 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3234 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3235 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3236 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3237 +
3238 + if (err)
3239 + break;
3240 +
3241 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3242 + ldi2 == 0x3414015AU &&
3243 + bel == 0xE4008200U &&
3244 + nop == 0x08000240U)
3245 + {
3246 + regs->gr[25] = (ldi1 & 2) >> 1;
3247 + regs->gr[20] = __NR_rt_sigreturn;
3248 + regs->gr[31] = regs->iaoq[1] + 16;
3249 + regs->sr[0] = regs->iasq[1];
3250 + regs->iaoq[0] = 0x100UL;
3251 + regs->iaoq[1] = regs->iaoq[0] + 4;
3252 + regs->iasq[0] = regs->sr[2];
3253 + regs->iasq[1] = regs->sr[2];
3254 + return 2;
3255 + }
3256 + } while (0);
3257 +#endif
3258 +
3259 + return 1;
3260 +}
3261 +
3262 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3263 +{
3264 + unsigned long i;
3265 +
3266 + printk(KERN_ERR "PAX: bytes at PC: ");
3267 + for (i = 0; i < 5; i++) {
3268 + unsigned int c;
3269 + if (get_user(c, (unsigned int *)pc+i))
3270 + printk(KERN_CONT "???????? ");
3271 + else
3272 + printk(KERN_CONT "%08x ", c);
3273 + }
3274 + printk("\n");
3275 +}
3276 +#endif
3277 +
3278 int fixup_exception(struct pt_regs *regs)
3279 {
3280 const struct exception_table_entry *fix;
3281 @@ -192,8 +303,33 @@ good_area:
3282
3283 acc_type = parisc_acctyp(code,regs->iir);
3284
3285 - if ((vma->vm_flags & acc_type) != acc_type)
3286 + if ((vma->vm_flags & acc_type) != acc_type) {
3287 +
3288 +#ifdef CONFIG_PAX_PAGEEXEC
3289 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3290 + (address & ~3UL) == instruction_pointer(regs))
3291 + {
3292 + up_read(&mm->mmap_sem);
3293 + switch (pax_handle_fetch_fault(regs)) {
3294 +
3295 +#ifdef CONFIG_PAX_EMUPLT
3296 + case 3:
3297 + return;
3298 +#endif
3299 +
3300 +#ifdef CONFIG_PAX_EMUTRAMP
3301 + case 2:
3302 + return;
3303 +#endif
3304 +
3305 + }
3306 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3307 + do_group_exit(SIGKILL);
3308 + }
3309 +#endif
3310 +
3311 goto bad_area;
3312 + }
3313
3314 /*
3315 * If for any reason at all we couldn't handle the fault, make
3316 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3317 index 02e41b5..ec6e26c 100644
3318 --- a/arch/powerpc/include/asm/atomic.h
3319 +++ b/arch/powerpc/include/asm/atomic.h
3320 @@ -469,6 +469,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3321
3322 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3323
3324 +#define atomic64_read_unchecked(v) atomic64_read(v)
3325 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3326 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3327 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3328 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3329 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3330 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3331 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3332 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3333 +
3334 #endif /* __powerpc64__ */
3335
3336 #endif /* __KERNEL__ */
3337 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3338 index 4b50941..5605819 100644
3339 --- a/arch/powerpc/include/asm/cache.h
3340 +++ b/arch/powerpc/include/asm/cache.h
3341 @@ -3,6 +3,7 @@
3342
3343 #ifdef __KERNEL__
3344
3345 +#include <linux/const.h>
3346
3347 /* bytes per L1 cache line */
3348 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3349 @@ -22,7 +23,7 @@
3350 #define L1_CACHE_SHIFT 7
3351 #endif
3352
3353 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3354 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3355
3356 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3357
3358 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3359 index 3bf9cca..e7457d0 100644
3360 --- a/arch/powerpc/include/asm/elf.h
3361 +++ b/arch/powerpc/include/asm/elf.h
3362 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3363 the loader. We need to make sure that it is out of the way of the program
3364 that it will "exec", and that there is sufficient room for the brk. */
3365
3366 -extern unsigned long randomize_et_dyn(unsigned long base);
3367 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3368 +#define ELF_ET_DYN_BASE (0x20000000)
3369 +
3370 +#ifdef CONFIG_PAX_ASLR
3371 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3372 +
3373 +#ifdef __powerpc64__
3374 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3375 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3376 +#else
3377 +#define PAX_DELTA_MMAP_LEN 15
3378 +#define PAX_DELTA_STACK_LEN 15
3379 +#endif
3380 +#endif
3381
3382 /*
3383 * Our registers are always unsigned longs, whether we're a 32 bit
3384 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3385 (0x7ff >> (PAGE_SHIFT - 12)) : \
3386 (0x3ffff >> (PAGE_SHIFT - 12)))
3387
3388 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3389 -#define arch_randomize_brk arch_randomize_brk
3390 -
3391 #endif /* __KERNEL__ */
3392
3393 /*
3394 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3395 index bca8fdc..61e9580 100644
3396 --- a/arch/powerpc/include/asm/kmap_types.h
3397 +++ b/arch/powerpc/include/asm/kmap_types.h
3398 @@ -27,6 +27,7 @@ enum km_type {
3399 KM_PPC_SYNC_PAGE,
3400 KM_PPC_SYNC_ICACHE,
3401 KM_KDB,
3402 + KM_CLEARPAGE,
3403 KM_TYPE_NR
3404 };
3405
3406 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3407 index d4a7f64..451de1c 100644
3408 --- a/arch/powerpc/include/asm/mman.h
3409 +++ b/arch/powerpc/include/asm/mman.h
3410 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3411 }
3412 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3413
3414 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3415 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3416 {
3417 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3418 }
3419 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3420 index dd9c4fd..a2ced87 100644
3421 --- a/arch/powerpc/include/asm/page.h
3422 +++ b/arch/powerpc/include/asm/page.h
3423 @@ -141,8 +141,9 @@ extern phys_addr_t kernstart_addr;
3424 * and needs to be executable. This means the whole heap ends
3425 * up being executable.
3426 */
3427 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3428 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3429 +#define VM_DATA_DEFAULT_FLAGS32 \
3430 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3431 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3432
3433 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3434 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3435 @@ -170,6 +171,9 @@ extern phys_addr_t kernstart_addr;
3436 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3437 #endif
3438
3439 +#define ktla_ktva(addr) (addr)
3440 +#define ktva_ktla(addr) (addr)
3441 +
3442 /*
3443 * Use the top bit of the higher-level page table entries to indicate whether
3444 * the entries we point to contain hugepages. This works because we know that
3445 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3446 index fb40ede..d3ce956 100644
3447 --- a/arch/powerpc/include/asm/page_64.h
3448 +++ b/arch/powerpc/include/asm/page_64.h
3449 @@ -144,15 +144,18 @@ do { \
3450 * stack by default, so in the absence of a PT_GNU_STACK program header
3451 * we turn execute permission off.
3452 */
3453 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3454 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3455 +#define VM_STACK_DEFAULT_FLAGS32 \
3456 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3457 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3458
3459 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3460 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3461
3462 +#ifndef CONFIG_PAX_PAGEEXEC
3463 #define VM_STACK_DEFAULT_FLAGS \
3464 (is_32bit_task() ? \
3465 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3466 +#endif
3467
3468 #include <asm-generic/getorder.h>
3469
3470 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3471 index 88b0bd9..e32bc67 100644
3472 --- a/arch/powerpc/include/asm/pgtable.h
3473 +++ b/arch/powerpc/include/asm/pgtable.h
3474 @@ -2,6 +2,7 @@
3475 #define _ASM_POWERPC_PGTABLE_H
3476 #ifdef __KERNEL__
3477
3478 +#include <linux/const.h>
3479 #ifndef __ASSEMBLY__
3480 #include <asm/processor.h> /* For TASK_SIZE */
3481 #include <asm/mmu.h>
3482 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3483 index 4aad413..85d86bf 100644
3484 --- a/arch/powerpc/include/asm/pte-hash32.h
3485 +++ b/arch/powerpc/include/asm/pte-hash32.h
3486 @@ -21,6 +21,7 @@
3487 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3488 #define _PAGE_USER 0x004 /* usermode access allowed */
3489 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3490 +#define _PAGE_EXEC _PAGE_GUARDED
3491 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3492 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3493 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3494 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3495 index 559da19..7e5835c 100644
3496 --- a/arch/powerpc/include/asm/reg.h
3497 +++ b/arch/powerpc/include/asm/reg.h
3498 @@ -212,6 +212,7 @@
3499 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3500 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3501 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3502 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3503 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3504 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3505 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3506 diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h
3507 index e30a13d..2b7d994 100644
3508 --- a/arch/powerpc/include/asm/system.h
3509 +++ b/arch/powerpc/include/asm/system.h
3510 @@ -530,7 +530,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
3511 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
3512 #endif
3513
3514 -extern unsigned long arch_align_stack(unsigned long sp);
3515 +#define arch_align_stack(x) ((x) & ~0xfUL)
3516
3517 /* Used in very early kernel initialization. */
3518 extern unsigned long reloc_offset(void);
3519 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3520 index bd0fb84..a42a14b 100644
3521 --- a/arch/powerpc/include/asm/uaccess.h
3522 +++ b/arch/powerpc/include/asm/uaccess.h
3523 @@ -13,6 +13,8 @@
3524 #define VERIFY_READ 0
3525 #define VERIFY_WRITE 1
3526
3527 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3528 +
3529 /*
3530 * The fs value determines whether argument validity checking should be
3531 * performed or not. If get_fs() == USER_DS, checking is performed, with
3532 @@ -327,52 +329,6 @@ do { \
3533 extern unsigned long __copy_tofrom_user(void __user *to,
3534 const void __user *from, unsigned long size);
3535
3536 -#ifndef __powerpc64__
3537 -
3538 -static inline unsigned long copy_from_user(void *to,
3539 - const void __user *from, unsigned long n)
3540 -{
3541 - unsigned long over;
3542 -
3543 - if (access_ok(VERIFY_READ, from, n))
3544 - return __copy_tofrom_user((__force void __user *)to, from, n);
3545 - if ((unsigned long)from < TASK_SIZE) {
3546 - over = (unsigned long)from + n - TASK_SIZE;
3547 - return __copy_tofrom_user((__force void __user *)to, from,
3548 - n - over) + over;
3549 - }
3550 - return n;
3551 -}
3552 -
3553 -static inline unsigned long copy_to_user(void __user *to,
3554 - const void *from, unsigned long n)
3555 -{
3556 - unsigned long over;
3557 -
3558 - if (access_ok(VERIFY_WRITE, to, n))
3559 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3560 - if ((unsigned long)to < TASK_SIZE) {
3561 - over = (unsigned long)to + n - TASK_SIZE;
3562 - return __copy_tofrom_user(to, (__force void __user *)from,
3563 - n - over) + over;
3564 - }
3565 - return n;
3566 -}
3567 -
3568 -#else /* __powerpc64__ */
3569 -
3570 -#define __copy_in_user(to, from, size) \
3571 - __copy_tofrom_user((to), (from), (size))
3572 -
3573 -extern unsigned long copy_from_user(void *to, const void __user *from,
3574 - unsigned long n);
3575 -extern unsigned long copy_to_user(void __user *to, const void *from,
3576 - unsigned long n);
3577 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
3578 - unsigned long n);
3579 -
3580 -#endif /* __powerpc64__ */
3581 -
3582 static inline unsigned long __copy_from_user_inatomic(void *to,
3583 const void __user *from, unsigned long n)
3584 {
3585 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
3586 if (ret == 0)
3587 return 0;
3588 }
3589 +
3590 + if (!__builtin_constant_p(n))
3591 + check_object_size(to, n, false);
3592 +
3593 return __copy_tofrom_user((__force void __user *)to, from, n);
3594 }
3595
3596 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
3597 if (ret == 0)
3598 return 0;
3599 }
3600 +
3601 + if (!__builtin_constant_p(n))
3602 + check_object_size(from, n, true);
3603 +
3604 return __copy_tofrom_user(to, (__force const void __user *)from, n);
3605 }
3606
3607 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
3608 return __copy_to_user_inatomic(to, from, size);
3609 }
3610
3611 +#ifndef __powerpc64__
3612 +
3613 +static inline unsigned long __must_check copy_from_user(void *to,
3614 + const void __user *from, unsigned long n)
3615 +{
3616 + unsigned long over;
3617 +
3618 + if ((long)n < 0)
3619 + return n;
3620 +
3621 + if (access_ok(VERIFY_READ, from, n)) {
3622 + if (!__builtin_constant_p(n))
3623 + check_object_size(to, n, false);
3624 + return __copy_tofrom_user((__force void __user *)to, from, n);
3625 + }
3626 + if ((unsigned long)from < TASK_SIZE) {
3627 + over = (unsigned long)from + n - TASK_SIZE;
3628 + if (!__builtin_constant_p(n - over))
3629 + check_object_size(to, n - over, false);
3630 + return __copy_tofrom_user((__force void __user *)to, from,
3631 + n - over) + over;
3632 + }
3633 + return n;
3634 +}
3635 +
3636 +static inline unsigned long __must_check copy_to_user(void __user *to,
3637 + const void *from, unsigned long n)
3638 +{
3639 + unsigned long over;
3640 +
3641 + if ((long)n < 0)
3642 + return n;
3643 +
3644 + if (access_ok(VERIFY_WRITE, to, n)) {
3645 + if (!__builtin_constant_p(n))
3646 + check_object_size(from, n, true);
3647 + return __copy_tofrom_user(to, (__force void __user *)from, n);
3648 + }
3649 + if ((unsigned long)to < TASK_SIZE) {
3650 + over = (unsigned long)to + n - TASK_SIZE;
3651 + if (!__builtin_constant_p(n))
3652 + check_object_size(from, n - over, true);
3653 + return __copy_tofrom_user(to, (__force void __user *)from,
3654 + n - over) + over;
3655 + }
3656 + return n;
3657 +}
3658 +
3659 +#else /* __powerpc64__ */
3660 +
3661 +#define __copy_in_user(to, from, size) \
3662 + __copy_tofrom_user((to), (from), (size))
3663 +
3664 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
3665 +{
3666 + if ((long)n < 0 || n > INT_MAX)
3667 + return n;
3668 +
3669 + if (!__builtin_constant_p(n))
3670 + check_object_size(to, n, false);
3671 +
3672 + if (likely(access_ok(VERIFY_READ, from, n)))
3673 + n = __copy_from_user(to, from, n);
3674 + else
3675 + memset(to, 0, n);
3676 + return n;
3677 +}
3678 +
3679 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
3680 +{
3681 + if ((long)n < 0 || n > INT_MAX)
3682 + return n;
3683 +
3684 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
3685 + if (!__builtin_constant_p(n))
3686 + check_object_size(from, n, true);
3687 + n = __copy_to_user(to, from, n);
3688 + }
3689 + return n;
3690 +}
3691 +
3692 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
3693 + unsigned long n);
3694 +
3695 +#endif /* __powerpc64__ */
3696 +
3697 extern unsigned long __clear_user(void __user *addr, unsigned long size);
3698
3699 static inline unsigned long clear_user(void __user *addr, unsigned long size)
3700 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
3701 index 429983c..7af363b 100644
3702 --- a/arch/powerpc/kernel/exceptions-64e.S
3703 +++ b/arch/powerpc/kernel/exceptions-64e.S
3704 @@ -587,6 +587,7 @@ storage_fault_common:
3705 std r14,_DAR(r1)
3706 std r15,_DSISR(r1)
3707 addi r3,r1,STACK_FRAME_OVERHEAD
3708 + bl .save_nvgprs
3709 mr r4,r14
3710 mr r5,r15
3711 ld r14,PACA_EXGEN+EX_R14(r13)
3712 @@ -596,8 +597,7 @@ storage_fault_common:
3713 cmpdi r3,0
3714 bne- 1f
3715 b .ret_from_except_lite
3716 -1: bl .save_nvgprs
3717 - mr r5,r3
3718 +1: mr r5,r3
3719 addi r3,r1,STACK_FRAME_OVERHEAD
3720 ld r4,_DAR(r1)
3721 bl .bad_page_fault
3722 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
3723 index cf9c69b..ebc9640 100644
3724 --- a/arch/powerpc/kernel/exceptions-64s.S
3725 +++ b/arch/powerpc/kernel/exceptions-64s.S
3726 @@ -1004,10 +1004,10 @@ handle_page_fault:
3727 11: ld r4,_DAR(r1)
3728 ld r5,_DSISR(r1)
3729 addi r3,r1,STACK_FRAME_OVERHEAD
3730 + bl .save_nvgprs
3731 bl .do_page_fault
3732 cmpdi r3,0
3733 beq+ 13f
3734 - bl .save_nvgprs
3735 mr r5,r3
3736 addi r3,r1,STACK_FRAME_OVERHEAD
3737 lwz r4,_DAR(r1)
3738 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
3739 index 745c1e7..59d97a6 100644
3740 --- a/arch/powerpc/kernel/irq.c
3741 +++ b/arch/powerpc/kernel/irq.c
3742 @@ -547,9 +547,6 @@ struct irq_host *irq_alloc_host(struct device_node *of_node,
3743 host->ops = ops;
3744 host->of_node = of_node_get(of_node);
3745
3746 - if (host->ops->match == NULL)
3747 - host->ops->match = default_irq_host_match;
3748 -
3749 raw_spin_lock_irqsave(&irq_big_lock, flags);
3750
3751 /* If it's a legacy controller, check for duplicates and
3752 @@ -622,7 +619,12 @@ struct irq_host *irq_find_host(struct device_node *node)
3753 */
3754 raw_spin_lock_irqsave(&irq_big_lock, flags);
3755 list_for_each_entry(h, &irq_hosts, link)
3756 - if (h->ops->match(h, node)) {
3757 + if (h->ops->match) {
3758 + if (h->ops->match(h, node)) {
3759 + found = h;
3760 + break;
3761 + }
3762 + } else if (default_irq_host_match(h, node)) {
3763 found = h;
3764 break;
3765 }
3766 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
3767 index 0b6d796..d760ddb 100644
3768 --- a/arch/powerpc/kernel/module_32.c
3769 +++ b/arch/powerpc/kernel/module_32.c
3770 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
3771 me->arch.core_plt_section = i;
3772 }
3773 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
3774 - printk("Module doesn't contain .plt or .init.plt sections.\n");
3775 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
3776 return -ENOEXEC;
3777 }
3778
3779 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
3780
3781 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
3782 /* Init, or core PLT? */
3783 - if (location >= mod->module_core
3784 - && location < mod->module_core + mod->core_size)
3785 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
3786 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
3787 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
3788 - else
3789 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
3790 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
3791 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
3792 + else {
3793 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
3794 + return ~0UL;
3795 + }
3796
3797 /* Find this entry, or if that fails, the next avail. entry */
3798 while (entry->jump[0]) {
3799 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
3800 index 6457574..08b28d3 100644
3801 --- a/arch/powerpc/kernel/process.c
3802 +++ b/arch/powerpc/kernel/process.c
3803 @@ -660,8 +660,8 @@ void show_regs(struct pt_regs * regs)
3804 * Lookup NIP late so we have the best change of getting the
3805 * above info out without failing
3806 */
3807 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
3808 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
3809 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
3810 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
3811 #endif
3812 show_stack(current, (unsigned long *) regs->gpr[1]);
3813 if (!user_mode(regs))
3814 @@ -1165,10 +1165,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
3815 newsp = stack[0];
3816 ip = stack[STACK_FRAME_LR_SAVE];
3817 if (!firstframe || ip != lr) {
3818 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
3819 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
3820 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3821 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
3822 - printk(" (%pS)",
3823 + printk(" (%pA)",
3824 (void *)current->ret_stack[curr_frame].ret);
3825 curr_frame--;
3826 }
3827 @@ -1188,7 +1188,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
3828 struct pt_regs *regs = (struct pt_regs *)
3829 (sp + STACK_FRAME_OVERHEAD);
3830 lr = regs->link;
3831 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
3832 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
3833 regs->trap, (void *)regs->nip, (void *)lr);
3834 firstframe = 1;
3835 }
3836 @@ -1263,58 +1263,3 @@ void thread_info_cache_init(void)
3837 }
3838
3839 #endif /* THREAD_SHIFT < PAGE_SHIFT */
3840 -
3841 -unsigned long arch_align_stack(unsigned long sp)
3842 -{
3843 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3844 - sp -= get_random_int() & ~PAGE_MASK;
3845 - return sp & ~0xf;
3846 -}
3847 -
3848 -static inline unsigned long brk_rnd(void)
3849 -{
3850 - unsigned long rnd = 0;
3851 -
3852 - /* 8MB for 32bit, 1GB for 64bit */
3853 - if (is_32bit_task())
3854 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
3855 - else
3856 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
3857 -
3858 - return rnd << PAGE_SHIFT;
3859 -}
3860 -
3861 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3862 -{
3863 - unsigned long base = mm->brk;
3864 - unsigned long ret;
3865 -
3866 -#ifdef CONFIG_PPC_STD_MMU_64
3867 - /*
3868 - * If we are using 1TB segments and we are allowed to randomise
3869 - * the heap, we can put it above 1TB so it is backed by a 1TB
3870 - * segment. Otherwise the heap will be in the bottom 1TB
3871 - * which always uses 256MB segments and this may result in a
3872 - * performance penalty.
3873 - */
3874 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
3875 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
3876 -#endif
3877 -
3878 - ret = PAGE_ALIGN(base + brk_rnd());
3879 -
3880 - if (ret < mm->brk)
3881 - return mm->brk;
3882 -
3883 - return ret;
3884 -}
3885 -
3886 -unsigned long randomize_et_dyn(unsigned long base)
3887 -{
3888 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
3889 -
3890 - if (ret < base)
3891 - return base;
3892 -
3893 - return ret;
3894 -}
3895 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
3896 index 836a5a1..27289a3 100644
3897 --- a/arch/powerpc/kernel/signal_32.c
3898 +++ b/arch/powerpc/kernel/signal_32.c
3899 @@ -859,7 +859,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
3900 /* Save user registers on the stack */
3901 frame = &rt_sf->uc.uc_mcontext;
3902 addr = frame;
3903 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
3904 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3905 if (save_user_regs(regs, frame, 0, 1))
3906 goto badframe;
3907 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
3908 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
3909 index a50b5ec..547078a 100644
3910 --- a/arch/powerpc/kernel/signal_64.c
3911 +++ b/arch/powerpc/kernel/signal_64.c
3912 @@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
3913 current->thread.fpscr.val = 0;
3914
3915 /* Set up to return from userspace. */
3916 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
3917 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3918 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
3919 } else {
3920 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
3921 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
3922 index 5459d14..10f8070 100644
3923 --- a/arch/powerpc/kernel/traps.c
3924 +++ b/arch/powerpc/kernel/traps.c
3925 @@ -98,6 +98,8 @@ static void pmac_backlight_unblank(void)
3926 static inline void pmac_backlight_unblank(void) { }
3927 #endif
3928
3929 +extern void gr_handle_kernel_exploit(void);
3930 +
3931 int die(const char *str, struct pt_regs *regs, long err)
3932 {
3933 static struct {
3934 @@ -171,6 +173,8 @@ int die(const char *str, struct pt_regs *regs, long err)
3935 if (panic_on_oops)
3936 panic("Fatal exception");
3937
3938 + gr_handle_kernel_exploit();
3939 +
3940 oops_exit();
3941 do_exit(err);
3942
3943 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
3944 index 7d14bb6..1305601 100644
3945 --- a/arch/powerpc/kernel/vdso.c
3946 +++ b/arch/powerpc/kernel/vdso.c
3947 @@ -35,6 +35,7 @@
3948 #include <asm/firmware.h>
3949 #include <asm/vdso.h>
3950 #include <asm/vdso_datapage.h>
3951 +#include <asm/mman.h>
3952
3953 #include "setup.h"
3954
3955 @@ -219,7 +220,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3956 vdso_base = VDSO32_MBASE;
3957 #endif
3958
3959 - current->mm->context.vdso_base = 0;
3960 + current->mm->context.vdso_base = ~0UL;
3961
3962 /* vDSO has a problem and was disabled, just don't "enable" it for the
3963 * process
3964 @@ -239,7 +240,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3965 vdso_base = get_unmapped_area(NULL, vdso_base,
3966 (vdso_pages << PAGE_SHIFT) +
3967 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
3968 - 0, 0);
3969 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
3970 if (IS_ERR_VALUE(vdso_base)) {
3971 rc = vdso_base;
3972 goto fail_mmapsem;
3973 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
3974 index 5eea6f3..5d10396 100644
3975 --- a/arch/powerpc/lib/usercopy_64.c
3976 +++ b/arch/powerpc/lib/usercopy_64.c
3977 @@ -9,22 +9,6 @@
3978 #include <linux/module.h>
3979 #include <asm/uaccess.h>
3980
3981 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
3982 -{
3983 - if (likely(access_ok(VERIFY_READ, from, n)))
3984 - n = __copy_from_user(to, from, n);
3985 - else
3986 - memset(to, 0, n);
3987 - return n;
3988 -}
3989 -
3990 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
3991 -{
3992 - if (likely(access_ok(VERIFY_WRITE, to, n)))
3993 - n = __copy_to_user(to, from, n);
3994 - return n;
3995 -}
3996 -
3997 unsigned long copy_in_user(void __user *to, const void __user *from,
3998 unsigned long n)
3999 {
4000 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4001 return n;
4002 }
4003
4004 -EXPORT_SYMBOL(copy_from_user);
4005 -EXPORT_SYMBOL(copy_to_user);
4006 EXPORT_SYMBOL(copy_in_user);
4007
4008 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4009 index 5efe8c9..db9ceef 100644
4010 --- a/arch/powerpc/mm/fault.c
4011 +++ b/arch/powerpc/mm/fault.c
4012 @@ -32,6 +32,10 @@
4013 #include <linux/perf_event.h>
4014 #include <linux/magic.h>
4015 #include <linux/ratelimit.h>
4016 +#include <linux/slab.h>
4017 +#include <linux/pagemap.h>
4018 +#include <linux/compiler.h>
4019 +#include <linux/unistd.h>
4020
4021 #include <asm/firmware.h>
4022 #include <asm/page.h>
4023 @@ -43,6 +47,7 @@
4024 #include <asm/tlbflush.h>
4025 #include <asm/siginfo.h>
4026 #include <mm/mmu_decl.h>
4027 +#include <asm/ptrace.h>
4028
4029 #ifdef CONFIG_KPROBES
4030 static inline int notify_page_fault(struct pt_regs *regs)
4031 @@ -66,6 +71,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4032 }
4033 #endif
4034
4035 +#ifdef CONFIG_PAX_PAGEEXEC
4036 +/*
4037 + * PaX: decide what to do with offenders (regs->nip = fault address)
4038 + *
4039 + * returns 1 when task should be killed
4040 + */
4041 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4042 +{
4043 + return 1;
4044 +}
4045 +
4046 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4047 +{
4048 + unsigned long i;
4049 +
4050 + printk(KERN_ERR "PAX: bytes at PC: ");
4051 + for (i = 0; i < 5; i++) {
4052 + unsigned int c;
4053 + if (get_user(c, (unsigned int __user *)pc+i))
4054 + printk(KERN_CONT "???????? ");
4055 + else
4056 + printk(KERN_CONT "%08x ", c);
4057 + }
4058 + printk("\n");
4059 +}
4060 +#endif
4061 +
4062 /*
4063 * Check whether the instruction at regs->nip is a store using
4064 * an update addressing form which will update r1.
4065 @@ -136,7 +168,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4066 * indicate errors in DSISR but can validly be set in SRR1.
4067 */
4068 if (trap == 0x400)
4069 - error_code &= 0x48200000;
4070 + error_code &= 0x58200000;
4071 else
4072 is_write = error_code & DSISR_ISSTORE;
4073 #else
4074 @@ -259,7 +291,7 @@ good_area:
4075 * "undefined". Of those that can be set, this is the only
4076 * one which seems bad.
4077 */
4078 - if (error_code & 0x10000000)
4079 + if (error_code & DSISR_GUARDED)
4080 /* Guarded storage error. */
4081 goto bad_area;
4082 #endif /* CONFIG_8xx */
4083 @@ -274,7 +306,7 @@ good_area:
4084 * processors use the same I/D cache coherency mechanism
4085 * as embedded.
4086 */
4087 - if (error_code & DSISR_PROTFAULT)
4088 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4089 goto bad_area;
4090 #endif /* CONFIG_PPC_STD_MMU */
4091
4092 @@ -343,6 +375,23 @@ bad_area:
4093 bad_area_nosemaphore:
4094 /* User mode accesses cause a SIGSEGV */
4095 if (user_mode(regs)) {
4096 +
4097 +#ifdef CONFIG_PAX_PAGEEXEC
4098 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4099 +#ifdef CONFIG_PPC_STD_MMU
4100 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4101 +#else
4102 + if (is_exec && regs->nip == address) {
4103 +#endif
4104 + switch (pax_handle_fetch_fault(regs)) {
4105 + }
4106 +
4107 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4108 + do_group_exit(SIGKILL);
4109 + }
4110 + }
4111 +#endif
4112 +
4113 _exception(SIGSEGV, regs, code, address);
4114 return 0;
4115 }
4116 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4117 index 5a783d8..c23e14b 100644
4118 --- a/arch/powerpc/mm/mmap_64.c
4119 +++ b/arch/powerpc/mm/mmap_64.c
4120 @@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4121 */
4122 if (mmap_is_legacy()) {
4123 mm->mmap_base = TASK_UNMAPPED_BASE;
4124 +
4125 +#ifdef CONFIG_PAX_RANDMMAP
4126 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4127 + mm->mmap_base += mm->delta_mmap;
4128 +#endif
4129 +
4130 mm->get_unmapped_area = arch_get_unmapped_area;
4131 mm->unmap_area = arch_unmap_area;
4132 } else {
4133 mm->mmap_base = mmap_base();
4134 +
4135 +#ifdef CONFIG_PAX_RANDMMAP
4136 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4137 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4138 +#endif
4139 +
4140 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4141 mm->unmap_area = arch_unmap_area_topdown;
4142 }
4143 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4144 index 73709f7..6b90313 100644
4145 --- a/arch/powerpc/mm/slice.c
4146 +++ b/arch/powerpc/mm/slice.c
4147 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4148 if ((mm->task_size - len) < addr)
4149 return 0;
4150 vma = find_vma(mm, addr);
4151 - return (!vma || (addr + len) <= vma->vm_start);
4152 + return check_heap_stack_gap(vma, addr, len);
4153 }
4154
4155 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4156 @@ -256,7 +256,7 @@ full_search:
4157 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4158 continue;
4159 }
4160 - if (!vma || addr + len <= vma->vm_start) {
4161 + if (check_heap_stack_gap(vma, addr, len)) {
4162 /*
4163 * Remember the place where we stopped the search:
4164 */
4165 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4166 }
4167 }
4168
4169 - addr = mm->mmap_base;
4170 - while (addr > len) {
4171 + if (mm->mmap_base < len)
4172 + addr = -ENOMEM;
4173 + else
4174 + addr = mm->mmap_base - len;
4175 +
4176 + while (!IS_ERR_VALUE(addr)) {
4177 /* Go down by chunk size */
4178 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4179 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4180
4181 /* Check for hit with different page size */
4182 mask = slice_range_to_mask(addr, len);
4183 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4184 * return with success:
4185 */
4186 vma = find_vma(mm, addr);
4187 - if (!vma || (addr + len) <= vma->vm_start) {
4188 + if (check_heap_stack_gap(vma, addr, len)) {
4189 /* remember the address as a hint for next time */
4190 if (use_cache)
4191 mm->free_area_cache = addr;
4192 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4193 mm->cached_hole_size = vma->vm_start - addr;
4194
4195 /* try just below the current vma->vm_start */
4196 - addr = vma->vm_start;
4197 + addr = skip_heap_stack_gap(vma, len);
4198 }
4199
4200 /*
4201 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4202 if (fixed && addr > (mm->task_size - len))
4203 return -EINVAL;
4204
4205 +#ifdef CONFIG_PAX_RANDMMAP
4206 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4207 + addr = 0;
4208 +#endif
4209 +
4210 /* If hint, make sure it matches our alignment restrictions */
4211 if (!fixed && addr) {
4212 addr = _ALIGN_UP(addr, 1ul << pshift);
4213 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4214 index 8517d2a..d2738d4 100644
4215 --- a/arch/s390/include/asm/atomic.h
4216 +++ b/arch/s390/include/asm/atomic.h
4217 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4218 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4219 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4220
4221 +#define atomic64_read_unchecked(v) atomic64_read(v)
4222 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4223 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4224 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4225 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4226 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4227 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4228 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4229 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4230 +
4231 #define smp_mb__before_atomic_dec() smp_mb()
4232 #define smp_mb__after_atomic_dec() smp_mb()
4233 #define smp_mb__before_atomic_inc() smp_mb()
4234 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4235 index 2a30d5a..5e5586f 100644
4236 --- a/arch/s390/include/asm/cache.h
4237 +++ b/arch/s390/include/asm/cache.h
4238 @@ -11,8 +11,10 @@
4239 #ifndef __ARCH_S390_CACHE_H
4240 #define __ARCH_S390_CACHE_H
4241
4242 -#define L1_CACHE_BYTES 256
4243 +#include <linux/const.h>
4244 +
4245 #define L1_CACHE_SHIFT 8
4246 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4247 #define NET_SKB_PAD 32
4248
4249 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4250 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4251 index 547f1a6..0b22b53 100644
4252 --- a/arch/s390/include/asm/elf.h
4253 +++ b/arch/s390/include/asm/elf.h
4254 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
4255 the loader. We need to make sure that it is out of the way of the program
4256 that it will "exec", and that there is sufficient room for the brk. */
4257
4258 -extern unsigned long randomize_et_dyn(unsigned long base);
4259 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4260 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4261 +
4262 +#ifdef CONFIG_PAX_ASLR
4263 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4264 +
4265 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4266 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4267 +#endif
4268
4269 /* This yields a mask that user programs can use to figure out what
4270 instruction set this CPU supports. */
4271 @@ -211,7 +217,4 @@ struct linux_binprm;
4272 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4273 int arch_setup_additional_pages(struct linux_binprm *, int);
4274
4275 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4276 -#define arch_randomize_brk arch_randomize_brk
4277 -
4278 #endif
4279 diff --git a/arch/s390/include/asm/system.h b/arch/s390/include/asm/system.h
4280 index ef573c1..75a1ce6 100644
4281 --- a/arch/s390/include/asm/system.h
4282 +++ b/arch/s390/include/asm/system.h
4283 @@ -262,7 +262,7 @@ extern void (*_machine_restart)(char *command);
4284 extern void (*_machine_halt)(void);
4285 extern void (*_machine_power_off)(void);
4286
4287 -extern unsigned long arch_align_stack(unsigned long sp);
4288 +#define arch_align_stack(x) ((x) & ~0xfUL)
4289
4290 static inline int tprot(unsigned long addr)
4291 {
4292 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4293 index 2b23885..e136e31 100644
4294 --- a/arch/s390/include/asm/uaccess.h
4295 +++ b/arch/s390/include/asm/uaccess.h
4296 @@ -235,6 +235,10 @@ static inline unsigned long __must_check
4297 copy_to_user(void __user *to, const void *from, unsigned long n)
4298 {
4299 might_fault();
4300 +
4301 + if ((long)n < 0)
4302 + return n;
4303 +
4304 if (access_ok(VERIFY_WRITE, to, n))
4305 n = __copy_to_user(to, from, n);
4306 return n;
4307 @@ -260,6 +264,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4308 static inline unsigned long __must_check
4309 __copy_from_user(void *to, const void __user *from, unsigned long n)
4310 {
4311 + if ((long)n < 0)
4312 + return n;
4313 +
4314 if (__builtin_constant_p(n) && (n <= 256))
4315 return uaccess.copy_from_user_small(n, from, to);
4316 else
4317 @@ -294,6 +301,10 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
4318 unsigned int sz = __compiletime_object_size(to);
4319
4320 might_fault();
4321 +
4322 + if ((long)n < 0)
4323 + return n;
4324 +
4325 if (unlikely(sz != -1 && sz < n)) {
4326 copy_from_user_overflow();
4327 return n;
4328 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4329 index dfcb343..eda788a 100644
4330 --- a/arch/s390/kernel/module.c
4331 +++ b/arch/s390/kernel/module.c
4332 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4333
4334 /* Increase core size by size of got & plt and set start
4335 offsets for got and plt. */
4336 - me->core_size = ALIGN(me->core_size, 4);
4337 - me->arch.got_offset = me->core_size;
4338 - me->core_size += me->arch.got_size;
4339 - me->arch.plt_offset = me->core_size;
4340 - me->core_size += me->arch.plt_size;
4341 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4342 + me->arch.got_offset = me->core_size_rw;
4343 + me->core_size_rw += me->arch.got_size;
4344 + me->arch.plt_offset = me->core_size_rx;
4345 + me->core_size_rx += me->arch.plt_size;
4346 return 0;
4347 }
4348
4349 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4350 if (info->got_initialized == 0) {
4351 Elf_Addr *gotent;
4352
4353 - gotent = me->module_core + me->arch.got_offset +
4354 + gotent = me->module_core_rw + me->arch.got_offset +
4355 info->got_offset;
4356 *gotent = val;
4357 info->got_initialized = 1;
4358 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4359 else if (r_type == R_390_GOTENT ||
4360 r_type == R_390_GOTPLTENT)
4361 *(unsigned int *) loc =
4362 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4363 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4364 else if (r_type == R_390_GOT64 ||
4365 r_type == R_390_GOTPLT64)
4366 *(unsigned long *) loc = val;
4367 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4368 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4369 if (info->plt_initialized == 0) {
4370 unsigned int *ip;
4371 - ip = me->module_core + me->arch.plt_offset +
4372 + ip = me->module_core_rx + me->arch.plt_offset +
4373 info->plt_offset;
4374 #ifndef CONFIG_64BIT
4375 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4376 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4377 val - loc + 0xffffUL < 0x1ffffeUL) ||
4378 (r_type == R_390_PLT32DBL &&
4379 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4380 - val = (Elf_Addr) me->module_core +
4381 + val = (Elf_Addr) me->module_core_rx +
4382 me->arch.plt_offset +
4383 info->plt_offset;
4384 val += rela->r_addend - loc;
4385 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4386 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4387 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4388 val = val + rela->r_addend -
4389 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4390 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4391 if (r_type == R_390_GOTOFF16)
4392 *(unsigned short *) loc = val;
4393 else if (r_type == R_390_GOTOFF32)
4394 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4395 break;
4396 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4397 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4398 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4399 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4400 rela->r_addend - loc;
4401 if (r_type == R_390_GOTPC)
4402 *(unsigned int *) loc = val;
4403 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4404 index 53088e2..9f44a36 100644
4405 --- a/arch/s390/kernel/process.c
4406 +++ b/arch/s390/kernel/process.c
4407 @@ -320,39 +320,3 @@ unsigned long get_wchan(struct task_struct *p)
4408 }
4409 return 0;
4410 }
4411 -
4412 -unsigned long arch_align_stack(unsigned long sp)
4413 -{
4414 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4415 - sp -= get_random_int() & ~PAGE_MASK;
4416 - return sp & ~0xf;
4417 -}
4418 -
4419 -static inline unsigned long brk_rnd(void)
4420 -{
4421 - /* 8MB for 32bit, 1GB for 64bit */
4422 - if (is_32bit_task())
4423 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4424 - else
4425 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4426 -}
4427 -
4428 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4429 -{
4430 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4431 -
4432 - if (ret < mm->brk)
4433 - return mm->brk;
4434 - return ret;
4435 -}
4436 -
4437 -unsigned long randomize_et_dyn(unsigned long base)
4438 -{
4439 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4440 -
4441 - if (!(current->flags & PF_RANDOMIZE))
4442 - return base;
4443 - if (ret < base)
4444 - return base;
4445 - return ret;
4446 -}
4447 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4448 index a0155c0..34cc491 100644
4449 --- a/arch/s390/mm/mmap.c
4450 +++ b/arch/s390/mm/mmap.c
4451 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4452 */
4453 if (mmap_is_legacy()) {
4454 mm->mmap_base = TASK_UNMAPPED_BASE;
4455 +
4456 +#ifdef CONFIG_PAX_RANDMMAP
4457 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4458 + mm->mmap_base += mm->delta_mmap;
4459 +#endif
4460 +
4461 mm->get_unmapped_area = arch_get_unmapped_area;
4462 mm->unmap_area = arch_unmap_area;
4463 } else {
4464 mm->mmap_base = mmap_base();
4465 +
4466 +#ifdef CONFIG_PAX_RANDMMAP
4467 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4468 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4469 +#endif
4470 +
4471 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4472 mm->unmap_area = arch_unmap_area_topdown;
4473 }
4474 @@ -167,10 +179,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4475 */
4476 if (mmap_is_legacy()) {
4477 mm->mmap_base = TASK_UNMAPPED_BASE;
4478 +
4479 +#ifdef CONFIG_PAX_RANDMMAP
4480 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4481 + mm->mmap_base += mm->delta_mmap;
4482 +#endif
4483 +
4484 mm->get_unmapped_area = s390_get_unmapped_area;
4485 mm->unmap_area = arch_unmap_area;
4486 } else {
4487 mm->mmap_base = mmap_base();
4488 +
4489 +#ifdef CONFIG_PAX_RANDMMAP
4490 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4491 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4492 +#endif
4493 +
4494 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4495 mm->unmap_area = arch_unmap_area_topdown;
4496 }
4497 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4498 index ae3d59f..f65f075 100644
4499 --- a/arch/score/include/asm/cache.h
4500 +++ b/arch/score/include/asm/cache.h
4501 @@ -1,7 +1,9 @@
4502 #ifndef _ASM_SCORE_CACHE_H
4503 #define _ASM_SCORE_CACHE_H
4504
4505 +#include <linux/const.h>
4506 +
4507 #define L1_CACHE_SHIFT 4
4508 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4509 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4510
4511 #endif /* _ASM_SCORE_CACHE_H */
4512 diff --git a/arch/score/include/asm/system.h b/arch/score/include/asm/system.h
4513 index 589d5c7..669e274 100644
4514 --- a/arch/score/include/asm/system.h
4515 +++ b/arch/score/include/asm/system.h
4516 @@ -17,7 +17,7 @@ do { \
4517 #define finish_arch_switch(prev) do {} while (0)
4518
4519 typedef void (*vi_handler_t)(void);
4520 -extern unsigned long arch_align_stack(unsigned long sp);
4521 +#define arch_align_stack(x) (x)
4522
4523 #define mb() barrier()
4524 #define rmb() barrier()
4525 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4526 index 25d0803..d6c8e36 100644
4527 --- a/arch/score/kernel/process.c
4528 +++ b/arch/score/kernel/process.c
4529 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4530
4531 return task_pt_regs(task)->cp0_epc;
4532 }
4533 -
4534 -unsigned long arch_align_stack(unsigned long sp)
4535 -{
4536 - return sp;
4537 -}
4538 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4539 index ef9e555..331bd29 100644
4540 --- a/arch/sh/include/asm/cache.h
4541 +++ b/arch/sh/include/asm/cache.h
4542 @@ -9,10 +9,11 @@
4543 #define __ASM_SH_CACHE_H
4544 #ifdef __KERNEL__
4545
4546 +#include <linux/const.h>
4547 #include <linux/init.h>
4548 #include <cpu/cache.h>
4549
4550 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4551 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4552
4553 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4554
4555 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4556 index afeb710..d1d1289 100644
4557 --- a/arch/sh/mm/mmap.c
4558 +++ b/arch/sh/mm/mmap.c
4559 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4560 addr = PAGE_ALIGN(addr);
4561
4562 vma = find_vma(mm, addr);
4563 - if (TASK_SIZE - len >= addr &&
4564 - (!vma || addr + len <= vma->vm_start))
4565 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4566 return addr;
4567 }
4568
4569 @@ -106,7 +105,7 @@ full_search:
4570 }
4571 return -ENOMEM;
4572 }
4573 - if (likely(!vma || addr + len <= vma->vm_start)) {
4574 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4575 /*
4576 * Remember the place where we stopped the search:
4577 */
4578 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4579 addr = PAGE_ALIGN(addr);
4580
4581 vma = find_vma(mm, addr);
4582 - if (TASK_SIZE - len >= addr &&
4583 - (!vma || addr + len <= vma->vm_start))
4584 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4585 return addr;
4586 }
4587
4588 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4589 /* make sure it can fit in the remaining address space */
4590 if (likely(addr > len)) {
4591 vma = find_vma(mm, addr-len);
4592 - if (!vma || addr <= vma->vm_start) {
4593 + if (check_heap_stack_gap(vma, addr - len, len)) {
4594 /* remember the address as a hint for next time */
4595 return (mm->free_area_cache = addr-len);
4596 }
4597 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4598 if (unlikely(mm->mmap_base < len))
4599 goto bottomup;
4600
4601 - addr = mm->mmap_base-len;
4602 - if (do_colour_align)
4603 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4604 + addr = mm->mmap_base - len;
4605
4606 do {
4607 + if (do_colour_align)
4608 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4609 /*
4610 * Lookup failure means no vma is above this address,
4611 * else if new region fits below vma->vm_start,
4612 * return with success:
4613 */
4614 vma = find_vma(mm, addr);
4615 - if (likely(!vma || addr+len <= vma->vm_start)) {
4616 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4617 /* remember the address as a hint for next time */
4618 return (mm->free_area_cache = addr);
4619 }
4620 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4621 mm->cached_hole_size = vma->vm_start - addr;
4622
4623 /* try just below the current vma->vm_start */
4624 - addr = vma->vm_start-len;
4625 - if (do_colour_align)
4626 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4627 - } while (likely(len < vma->vm_start));
4628 + addr = skip_heap_stack_gap(vma, len);
4629 + } while (!IS_ERR_VALUE(addr));
4630
4631 bottomup:
4632 /*
4633 diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
4634 index f92602e..27060b2 100644
4635 --- a/arch/sparc/Kconfig
4636 +++ b/arch/sparc/Kconfig
4637 @@ -31,6 +31,7 @@ config SPARC
4638
4639 config SPARC32
4640 def_bool !64BIT
4641 + select GENERIC_ATOMIC64
4642
4643 config SPARC64
4644 def_bool 64BIT
4645 diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
4646 index eddcfb3..b117d90 100644
4647 --- a/arch/sparc/Makefile
4648 +++ b/arch/sparc/Makefile
4649 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
4650 # Export what is needed by arch/sparc/boot/Makefile
4651 export VMLINUX_INIT VMLINUX_MAIN
4652 VMLINUX_INIT := $(head-y) $(init-y)
4653 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
4654 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
4655 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
4656 VMLINUX_MAIN += $(drivers-y) $(net-y)
4657
4658 diff --git a/arch/sparc/include/asm/atomic_32.h b/arch/sparc/include/asm/atomic_32.h
4659 index 5c3c8b6..ba822fa 100644
4660 --- a/arch/sparc/include/asm/atomic_32.h
4661 +++ b/arch/sparc/include/asm/atomic_32.h
4662 @@ -13,6 +13,8 @@
4663
4664 #include <linux/types.h>
4665
4666 +#include <asm-generic/atomic64.h>
4667 +
4668 #ifdef __KERNEL__
4669
4670 #include <asm/system.h>
4671 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
4672 index 9f421df..b81fc12 100644
4673 --- a/arch/sparc/include/asm/atomic_64.h
4674 +++ b/arch/sparc/include/asm/atomic_64.h
4675 @@ -14,18 +14,40 @@
4676 #define ATOMIC64_INIT(i) { (i) }
4677
4678 #define atomic_read(v) (*(volatile int *)&(v)->counter)
4679 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
4680 +{
4681 + return v->counter;
4682 +}
4683 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
4684 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
4685 +{
4686 + return v->counter;
4687 +}
4688
4689 #define atomic_set(v, i) (((v)->counter) = i)
4690 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
4691 +{
4692 + v->counter = i;
4693 +}
4694 #define atomic64_set(v, i) (((v)->counter) = i)
4695 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
4696 +{
4697 + v->counter = i;
4698 +}
4699
4700 extern void atomic_add(int, atomic_t *);
4701 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
4702 extern void atomic64_add(long, atomic64_t *);
4703 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
4704 extern void atomic_sub(int, atomic_t *);
4705 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
4706 extern void atomic64_sub(long, atomic64_t *);
4707 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
4708
4709 extern int atomic_add_ret(int, atomic_t *);
4710 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
4711 extern long atomic64_add_ret(long, atomic64_t *);
4712 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
4713 extern int atomic_sub_ret(int, atomic_t *);
4714 extern long atomic64_sub_ret(long, atomic64_t *);
4715
4716 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4717 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
4718
4719 #define atomic_inc_return(v) atomic_add_ret(1, v)
4720 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
4721 +{
4722 + return atomic_add_ret_unchecked(1, v);
4723 +}
4724 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
4725 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
4726 +{
4727 + return atomic64_add_ret_unchecked(1, v);
4728 +}
4729
4730 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
4731 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
4732
4733 #define atomic_add_return(i, v) atomic_add_ret(i, v)
4734 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
4735 +{
4736 + return atomic_add_ret_unchecked(i, v);
4737 +}
4738 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
4739 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
4740 +{
4741 + return atomic64_add_ret_unchecked(i, v);
4742 +}
4743
4744 /*
4745 * atomic_inc_and_test - increment and test
4746 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4747 * other cases.
4748 */
4749 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
4750 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
4751 +{
4752 + return atomic_inc_return_unchecked(v) == 0;
4753 +}
4754 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
4755
4756 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
4757 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4758 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
4759
4760 #define atomic_inc(v) atomic_add(1, v)
4761 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
4762 +{
4763 + atomic_add_unchecked(1, v);
4764 +}
4765 #define atomic64_inc(v) atomic64_add(1, v)
4766 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
4767 +{
4768 + atomic64_add_unchecked(1, v);
4769 +}
4770
4771 #define atomic_dec(v) atomic_sub(1, v)
4772 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
4773 +{
4774 + atomic_sub_unchecked(1, v);
4775 +}
4776 #define atomic64_dec(v) atomic64_sub(1, v)
4777 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
4778 +{
4779 + atomic64_sub_unchecked(1, v);
4780 +}
4781
4782 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
4783 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
4784
4785 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
4786 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
4787 +{
4788 + return cmpxchg(&v->counter, old, new);
4789 +}
4790 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
4791 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
4792 +{
4793 + return xchg(&v->counter, new);
4794 +}
4795
4796 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
4797 {
4798 - int c, old;
4799 + int c, old, new;
4800 c = atomic_read(v);
4801 for (;;) {
4802 - if (unlikely(c == (u)))
4803 + if (unlikely(c == u))
4804 break;
4805 - old = atomic_cmpxchg((v), c, c + (a));
4806 +
4807 + asm volatile("addcc %2, %0, %0\n"
4808 +
4809 +#ifdef CONFIG_PAX_REFCOUNT
4810 + "tvs %%icc, 6\n"
4811 +#endif
4812 +
4813 + : "=r" (new)
4814 + : "0" (c), "ir" (a)
4815 + : "cc");
4816 +
4817 + old = atomic_cmpxchg(v, c, new);
4818 if (likely(old == c))
4819 break;
4820 c = old;
4821 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
4822 #define atomic64_cmpxchg(v, o, n) \
4823 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
4824 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
4825 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
4826 +{
4827 + return xchg(&v->counter, new);
4828 +}
4829
4830 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
4831 {
4832 - long c, old;
4833 + long c, old, new;
4834 c = atomic64_read(v);
4835 for (;;) {
4836 - if (unlikely(c == (u)))
4837 + if (unlikely(c == u))
4838 break;
4839 - old = atomic64_cmpxchg((v), c, c + (a));
4840 +
4841 + asm volatile("addcc %2, %0, %0\n"
4842 +
4843 +#ifdef CONFIG_PAX_REFCOUNT
4844 + "tvs %%xcc, 6\n"
4845 +#endif
4846 +
4847 + : "=r" (new)
4848 + : "0" (c), "ir" (a)
4849 + : "cc");
4850 +
4851 + old = atomic64_cmpxchg(v, c, new);
4852 if (likely(old == c))
4853 break;
4854 c = old;
4855 }
4856 - return c != (u);
4857 + return c != u;
4858 }
4859
4860 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4861 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
4862 index 69358b5..9d0d492 100644
4863 --- a/arch/sparc/include/asm/cache.h
4864 +++ b/arch/sparc/include/asm/cache.h
4865 @@ -7,10 +7,12 @@
4866 #ifndef _SPARC_CACHE_H
4867 #define _SPARC_CACHE_H
4868
4869 +#include <linux/const.h>
4870 +
4871 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
4872
4873 #define L1_CACHE_SHIFT 5
4874 -#define L1_CACHE_BYTES 32
4875 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4876
4877 #ifdef CONFIG_SPARC32
4878 #define SMP_CACHE_BYTES_SHIFT 5
4879 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
4880 index 4269ca6..e3da77f 100644
4881 --- a/arch/sparc/include/asm/elf_32.h
4882 +++ b/arch/sparc/include/asm/elf_32.h
4883 @@ -114,6 +114,13 @@ typedef struct {
4884
4885 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
4886
4887 +#ifdef CONFIG_PAX_ASLR
4888 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
4889 +
4890 +#define PAX_DELTA_MMAP_LEN 16
4891 +#define PAX_DELTA_STACK_LEN 16
4892 +#endif
4893 +
4894 /* This yields a mask that user programs can use to figure out what
4895 instruction set this cpu supports. This can NOT be done in userspace
4896 on Sparc. */
4897 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
4898 index 7df8b7f..4946269 100644
4899 --- a/arch/sparc/include/asm/elf_64.h
4900 +++ b/arch/sparc/include/asm/elf_64.h
4901 @@ -180,6 +180,13 @@ typedef struct {
4902 #define ELF_ET_DYN_BASE 0x0000010000000000UL
4903 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
4904
4905 +#ifdef CONFIG_PAX_ASLR
4906 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
4907 +
4908 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
4909 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
4910 +#endif
4911 +
4912 extern unsigned long sparc64_elf_hwcap;
4913 #define ELF_HWCAP sparc64_elf_hwcap
4914
4915 diff --git a/arch/sparc/include/asm/page_32.h b/arch/sparc/include/asm/page_32.h
4916 index 156707b..aefa786 100644
4917 --- a/arch/sparc/include/asm/page_32.h
4918 +++ b/arch/sparc/include/asm/page_32.h
4919 @@ -8,6 +8,8 @@
4920 #ifndef _SPARC_PAGE_H
4921 #define _SPARC_PAGE_H
4922
4923 +#include <linux/const.h>
4924 +
4925 #define PAGE_SHIFT 12
4926
4927 #ifndef __ASSEMBLY__
4928 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
4929 index a790cc6..091ed94 100644
4930 --- a/arch/sparc/include/asm/pgtable_32.h
4931 +++ b/arch/sparc/include/asm/pgtable_32.h
4932 @@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
4933 BTFIXUPDEF_INT(page_none)
4934 BTFIXUPDEF_INT(page_copy)
4935 BTFIXUPDEF_INT(page_readonly)
4936 +
4937 +#ifdef CONFIG_PAX_PAGEEXEC
4938 +BTFIXUPDEF_INT(page_shared_noexec)
4939 +BTFIXUPDEF_INT(page_copy_noexec)
4940 +BTFIXUPDEF_INT(page_readonly_noexec)
4941 +#endif
4942 +
4943 BTFIXUPDEF_INT(page_kernel)
4944
4945 #define PMD_SHIFT SUN4C_PMD_SHIFT
4946 @@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
4947 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
4948 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
4949
4950 +#ifdef CONFIG_PAX_PAGEEXEC
4951 +extern pgprot_t PAGE_SHARED_NOEXEC;
4952 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
4953 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
4954 +#else
4955 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4956 +# define PAGE_COPY_NOEXEC PAGE_COPY
4957 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4958 +#endif
4959 +
4960 extern unsigned long page_kernel;
4961
4962 #ifdef MODULE
4963 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
4964 index f6ae2b2..b03ffc7 100644
4965 --- a/arch/sparc/include/asm/pgtsrmmu.h
4966 +++ b/arch/sparc/include/asm/pgtsrmmu.h
4967 @@ -115,6 +115,13 @@
4968 SRMMU_EXEC | SRMMU_REF)
4969 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
4970 SRMMU_EXEC | SRMMU_REF)
4971 +
4972 +#ifdef CONFIG_PAX_PAGEEXEC
4973 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
4974 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4975 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4976 +#endif
4977 +
4978 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
4979 SRMMU_DIRTY | SRMMU_REF)
4980
4981 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
4982 index 9689176..63c18ea 100644
4983 --- a/arch/sparc/include/asm/spinlock_64.h
4984 +++ b/arch/sparc/include/asm/spinlock_64.h
4985 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
4986
4987 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
4988
4989 -static void inline arch_read_lock(arch_rwlock_t *lock)
4990 +static inline void arch_read_lock(arch_rwlock_t *lock)
4991 {
4992 unsigned long tmp1, tmp2;
4993
4994 __asm__ __volatile__ (
4995 "1: ldsw [%2], %0\n"
4996 " brlz,pn %0, 2f\n"
4997 -"4: add %0, 1, %1\n"
4998 +"4: addcc %0, 1, %1\n"
4999 +
5000 +#ifdef CONFIG_PAX_REFCOUNT
5001 +" tvs %%icc, 6\n"
5002 +#endif
5003 +
5004 " cas [%2], %0, %1\n"
5005 " cmp %0, %1\n"
5006 " bne,pn %%icc, 1b\n"
5007 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5008 " .previous"
5009 : "=&r" (tmp1), "=&r" (tmp2)
5010 : "r" (lock)
5011 - : "memory");
5012 + : "memory", "cc");
5013 }
5014
5015 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5016 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5017 {
5018 int tmp1, tmp2;
5019
5020 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5021 "1: ldsw [%2], %0\n"
5022 " brlz,a,pn %0, 2f\n"
5023 " mov 0, %0\n"
5024 -" add %0, 1, %1\n"
5025 +" addcc %0, 1, %1\n"
5026 +
5027 +#ifdef CONFIG_PAX_REFCOUNT
5028 +" tvs %%icc, 6\n"
5029 +#endif
5030 +
5031 " cas [%2], %0, %1\n"
5032 " cmp %0, %1\n"
5033 " bne,pn %%icc, 1b\n"
5034 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5035 return tmp1;
5036 }
5037
5038 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5039 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5040 {
5041 unsigned long tmp1, tmp2;
5042
5043 __asm__ __volatile__(
5044 "1: lduw [%2], %0\n"
5045 -" sub %0, 1, %1\n"
5046 +" subcc %0, 1, %1\n"
5047 +
5048 +#ifdef CONFIG_PAX_REFCOUNT
5049 +" tvs %%icc, 6\n"
5050 +#endif
5051 +
5052 " cas [%2], %0, %1\n"
5053 " cmp %0, %1\n"
5054 " bne,pn %%xcc, 1b\n"
5055 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5056 : "memory");
5057 }
5058
5059 -static void inline arch_write_lock(arch_rwlock_t *lock)
5060 +static inline void arch_write_lock(arch_rwlock_t *lock)
5061 {
5062 unsigned long mask, tmp1, tmp2;
5063
5064 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5065 : "memory");
5066 }
5067
5068 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5069 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5070 {
5071 __asm__ __volatile__(
5072 " stw %%g0, [%0]"
5073 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5074 : "memory");
5075 }
5076
5077 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5078 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5079 {
5080 unsigned long mask, tmp1, tmp2, result;
5081
5082 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5083 index fa57532..e1a4c53 100644
5084 --- a/arch/sparc/include/asm/thread_info_32.h
5085 +++ b/arch/sparc/include/asm/thread_info_32.h
5086 @@ -50,6 +50,8 @@ struct thread_info {
5087 unsigned long w_saved;
5088
5089 struct restart_block restart_block;
5090 +
5091 + unsigned long lowest_stack;
5092 };
5093
5094 /*
5095 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5096 index 60d86be..952dea1 100644
5097 --- a/arch/sparc/include/asm/thread_info_64.h
5098 +++ b/arch/sparc/include/asm/thread_info_64.h
5099 @@ -63,6 +63,8 @@ struct thread_info {
5100 struct pt_regs *kern_una_regs;
5101 unsigned int kern_una_insn;
5102
5103 + unsigned long lowest_stack;
5104 +
5105 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5106 };
5107
5108 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5109 index e88fbe5..96b0ce5 100644
5110 --- a/arch/sparc/include/asm/uaccess.h
5111 +++ b/arch/sparc/include/asm/uaccess.h
5112 @@ -1,5 +1,13 @@
5113 #ifndef ___ASM_SPARC_UACCESS_H
5114 #define ___ASM_SPARC_UACCESS_H
5115 +
5116 +#ifdef __KERNEL__
5117 +#ifndef __ASSEMBLY__
5118 +#include <linux/types.h>
5119 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5120 +#endif
5121 +#endif
5122 +
5123 #if defined(__sparc__) && defined(__arch64__)
5124 #include <asm/uaccess_64.h>
5125 #else
5126 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5127 index 8303ac4..07f333d 100644
5128 --- a/arch/sparc/include/asm/uaccess_32.h
5129 +++ b/arch/sparc/include/asm/uaccess_32.h
5130 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5131
5132 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5133 {
5134 - if (n && __access_ok((unsigned long) to, n))
5135 + if ((long)n < 0)
5136 + return n;
5137 +
5138 + if (n && __access_ok((unsigned long) to, n)) {
5139 + if (!__builtin_constant_p(n))
5140 + check_object_size(from, n, true);
5141 return __copy_user(to, (__force void __user *) from, n);
5142 - else
5143 + } else
5144 return n;
5145 }
5146
5147 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5148 {
5149 + if ((long)n < 0)
5150 + return n;
5151 +
5152 + if (!__builtin_constant_p(n))
5153 + check_object_size(from, n, true);
5154 +
5155 return __copy_user(to, (__force void __user *) from, n);
5156 }
5157
5158 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5159 {
5160 - if (n && __access_ok((unsigned long) from, n))
5161 + if ((long)n < 0)
5162 + return n;
5163 +
5164 + if (n && __access_ok((unsigned long) from, n)) {
5165 + if (!__builtin_constant_p(n))
5166 + check_object_size(to, n, false);
5167 return __copy_user((__force void __user *) to, from, n);
5168 - else
5169 + } else
5170 return n;
5171 }
5172
5173 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5174 {
5175 + if ((long)n < 0)
5176 + return n;
5177 +
5178 return __copy_user((__force void __user *) to, from, n);
5179 }
5180
5181 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5182 index 3e1449f..5293a0e 100644
5183 --- a/arch/sparc/include/asm/uaccess_64.h
5184 +++ b/arch/sparc/include/asm/uaccess_64.h
5185 @@ -10,6 +10,7 @@
5186 #include <linux/compiler.h>
5187 #include <linux/string.h>
5188 #include <linux/thread_info.h>
5189 +#include <linux/kernel.h>
5190 #include <asm/asi.h>
5191 #include <asm/system.h>
5192 #include <asm/spitfire.h>
5193 @@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5194 static inline unsigned long __must_check
5195 copy_from_user(void *to, const void __user *from, unsigned long size)
5196 {
5197 - unsigned long ret = ___copy_from_user(to, from, size);
5198 + unsigned long ret;
5199
5200 + if ((long)size < 0 || size > INT_MAX)
5201 + return size;
5202 +
5203 + if (!__builtin_constant_p(size))
5204 + check_object_size(to, size, false);
5205 +
5206 + ret = ___copy_from_user(to, from, size);
5207 if (unlikely(ret))
5208 ret = copy_from_user_fixup(to, from, size);
5209
5210 @@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5211 static inline unsigned long __must_check
5212 copy_to_user(void __user *to, const void *from, unsigned long size)
5213 {
5214 - unsigned long ret = ___copy_to_user(to, from, size);
5215 + unsigned long ret;
5216
5217 + if ((long)size < 0 || size > INT_MAX)
5218 + return size;
5219 +
5220 + if (!__builtin_constant_p(size))
5221 + check_object_size(from, size, true);
5222 +
5223 + ret = ___copy_to_user(to, from, size);
5224 if (unlikely(ret))
5225 ret = copy_to_user_fixup(to, from, size);
5226 return ret;
5227 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5228 index cb85458..e063f17 100644
5229 --- a/arch/sparc/kernel/Makefile
5230 +++ b/arch/sparc/kernel/Makefile
5231 @@ -3,7 +3,7 @@
5232 #
5233
5234 asflags-y := -ansi
5235 -ccflags-y := -Werror
5236 +#ccflags-y := -Werror
5237
5238 extra-y := head_$(BITS).o
5239 extra-y += init_task.o
5240 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5241 index f793742..4d880af 100644
5242 --- a/arch/sparc/kernel/process_32.c
5243 +++ b/arch/sparc/kernel/process_32.c
5244 @@ -204,7 +204,7 @@ void __show_backtrace(unsigned long fp)
5245 rw->ins[4], rw->ins[5],
5246 rw->ins[6],
5247 rw->ins[7]);
5248 - printk("%pS\n", (void *) rw->ins[7]);
5249 + printk("%pA\n", (void *) rw->ins[7]);
5250 rw = (struct reg_window32 *) rw->ins[6];
5251 }
5252 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5253 @@ -271,14 +271,14 @@ void show_regs(struct pt_regs *r)
5254
5255 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5256 r->psr, r->pc, r->npc, r->y, print_tainted());
5257 - printk("PC: <%pS>\n", (void *) r->pc);
5258 + printk("PC: <%pA>\n", (void *) r->pc);
5259 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5260 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5261 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5262 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5263 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5264 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5265 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5266 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5267
5268 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5269 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5270 @@ -313,7 +313,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5271 rw = (struct reg_window32 *) fp;
5272 pc = rw->ins[7];
5273 printk("[%08lx : ", pc);
5274 - printk("%pS ] ", (void *) pc);
5275 + printk("%pA ] ", (void *) pc);
5276 fp = rw->ins[6];
5277 } while (++count < 16);
5278 printk("\n");
5279 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5280 index 3739a06..48b2ff0 100644
5281 --- a/arch/sparc/kernel/process_64.c
5282 +++ b/arch/sparc/kernel/process_64.c
5283 @@ -180,14 +180,14 @@ static void show_regwindow(struct pt_regs *regs)
5284 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5285 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5286 if (regs->tstate & TSTATE_PRIV)
5287 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5288 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5289 }
5290
5291 void show_regs(struct pt_regs *regs)
5292 {
5293 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5294 regs->tpc, regs->tnpc, regs->y, print_tainted());
5295 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5296 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5297 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5298 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5299 regs->u_regs[3]);
5300 @@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
5301 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5302 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5303 regs->u_regs[15]);
5304 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5305 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5306 show_regwindow(regs);
5307 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5308 }
5309 @@ -285,7 +285,7 @@ void arch_trigger_all_cpu_backtrace(void)
5310 ((tp && tp->task) ? tp->task->pid : -1));
5311
5312 if (gp->tstate & TSTATE_PRIV) {
5313 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5314 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5315 (void *) gp->tpc,
5316 (void *) gp->o7,
5317 (void *) gp->i7,
5318 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5319 index 42b282f..28ce9f2 100644
5320 --- a/arch/sparc/kernel/sys_sparc_32.c
5321 +++ b/arch/sparc/kernel/sys_sparc_32.c
5322 @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5323 if (ARCH_SUN4C && len > 0x20000000)
5324 return -ENOMEM;
5325 if (!addr)
5326 - addr = TASK_UNMAPPED_BASE;
5327 + addr = current->mm->mmap_base;
5328
5329 if (flags & MAP_SHARED)
5330 addr = COLOUR_ALIGN(addr);
5331 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5332 }
5333 if (TASK_SIZE - PAGE_SIZE - len < addr)
5334 return -ENOMEM;
5335 - if (!vmm || addr + len <= vmm->vm_start)
5336 + if (check_heap_stack_gap(vmm, addr, len))
5337 return addr;
5338 addr = vmm->vm_end;
5339 if (flags & MAP_SHARED)
5340 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5341 index 441521a..b767073 100644
5342 --- a/arch/sparc/kernel/sys_sparc_64.c
5343 +++ b/arch/sparc/kernel/sys_sparc_64.c
5344 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5345 /* We do not accept a shared mapping if it would violate
5346 * cache aliasing constraints.
5347 */
5348 - if ((flags & MAP_SHARED) &&
5349 + if ((filp || (flags & MAP_SHARED)) &&
5350 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5351 return -EINVAL;
5352 return addr;
5353 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5354 if (filp || (flags & MAP_SHARED))
5355 do_color_align = 1;
5356
5357 +#ifdef CONFIG_PAX_RANDMMAP
5358 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5359 +#endif
5360 +
5361 if (addr) {
5362 if (do_color_align)
5363 addr = COLOUR_ALIGN(addr, pgoff);
5364 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5365 addr = PAGE_ALIGN(addr);
5366
5367 vma = find_vma(mm, addr);
5368 - if (task_size - len >= addr &&
5369 - (!vma || addr + len <= vma->vm_start))
5370 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5371 return addr;
5372 }
5373
5374 if (len > mm->cached_hole_size) {
5375 - start_addr = addr = mm->free_area_cache;
5376 + start_addr = addr = mm->free_area_cache;
5377 } else {
5378 - start_addr = addr = TASK_UNMAPPED_BASE;
5379 + start_addr = addr = mm->mmap_base;
5380 mm->cached_hole_size = 0;
5381 }
5382
5383 @@ -174,14 +177,14 @@ full_search:
5384 vma = find_vma(mm, VA_EXCLUDE_END);
5385 }
5386 if (unlikely(task_size < addr)) {
5387 - if (start_addr != TASK_UNMAPPED_BASE) {
5388 - start_addr = addr = TASK_UNMAPPED_BASE;
5389 + if (start_addr != mm->mmap_base) {
5390 + start_addr = addr = mm->mmap_base;
5391 mm->cached_hole_size = 0;
5392 goto full_search;
5393 }
5394 return -ENOMEM;
5395 }
5396 - if (likely(!vma || addr + len <= vma->vm_start)) {
5397 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5398 /*
5399 * Remember the place where we stopped the search:
5400 */
5401 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5402 /* We do not accept a shared mapping if it would violate
5403 * cache aliasing constraints.
5404 */
5405 - if ((flags & MAP_SHARED) &&
5406 + if ((filp || (flags & MAP_SHARED)) &&
5407 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5408 return -EINVAL;
5409 return addr;
5410 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5411 addr = PAGE_ALIGN(addr);
5412
5413 vma = find_vma(mm, addr);
5414 - if (task_size - len >= addr &&
5415 - (!vma || addr + len <= vma->vm_start))
5416 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5417 return addr;
5418 }
5419
5420 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5421 /* make sure it can fit in the remaining address space */
5422 if (likely(addr > len)) {
5423 vma = find_vma(mm, addr-len);
5424 - if (!vma || addr <= vma->vm_start) {
5425 + if (check_heap_stack_gap(vma, addr - len, len)) {
5426 /* remember the address as a hint for next time */
5427 return (mm->free_area_cache = addr-len);
5428 }
5429 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5430 if (unlikely(mm->mmap_base < len))
5431 goto bottomup;
5432
5433 - addr = mm->mmap_base-len;
5434 - if (do_color_align)
5435 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5436 + addr = mm->mmap_base - len;
5437
5438 do {
5439 + if (do_color_align)
5440 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5441 /*
5442 * Lookup failure means no vma is above this address,
5443 * else if new region fits below vma->vm_start,
5444 * return with success:
5445 */
5446 vma = find_vma(mm, addr);
5447 - if (likely(!vma || addr+len <= vma->vm_start)) {
5448 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5449 /* remember the address as a hint for next time */
5450 return (mm->free_area_cache = addr);
5451 }
5452 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5453 mm->cached_hole_size = vma->vm_start - addr;
5454
5455 /* try just below the current vma->vm_start */
5456 - addr = vma->vm_start-len;
5457 - if (do_color_align)
5458 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5459 - } while (likely(len < vma->vm_start));
5460 + addr = skip_heap_stack_gap(vma, len);
5461 + } while (!IS_ERR_VALUE(addr));
5462
5463 bottomup:
5464 /*
5465 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5466 gap == RLIM_INFINITY ||
5467 sysctl_legacy_va_layout) {
5468 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5469 +
5470 +#ifdef CONFIG_PAX_RANDMMAP
5471 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5472 + mm->mmap_base += mm->delta_mmap;
5473 +#endif
5474 +
5475 mm->get_unmapped_area = arch_get_unmapped_area;
5476 mm->unmap_area = arch_unmap_area;
5477 } else {
5478 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5479 gap = (task_size / 6 * 5);
5480
5481 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5482 +
5483 +#ifdef CONFIG_PAX_RANDMMAP
5484 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5485 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5486 +#endif
5487 +
5488 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5489 mm->unmap_area = arch_unmap_area_topdown;
5490 }
5491 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
5492 index 591f20c..0f1b925 100644
5493 --- a/arch/sparc/kernel/traps_32.c
5494 +++ b/arch/sparc/kernel/traps_32.c
5495 @@ -45,6 +45,8 @@ static void instruction_dump(unsigned long *pc)
5496 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
5497 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
5498
5499 +extern void gr_handle_kernel_exploit(void);
5500 +
5501 void die_if_kernel(char *str, struct pt_regs *regs)
5502 {
5503 static int die_counter;
5504 @@ -77,15 +79,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5505 count++ < 30 &&
5506 (((unsigned long) rw) >= PAGE_OFFSET) &&
5507 !(((unsigned long) rw) & 0x7)) {
5508 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
5509 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
5510 (void *) rw->ins[7]);
5511 rw = (struct reg_window32 *)rw->ins[6];
5512 }
5513 }
5514 printk("Instruction DUMP:");
5515 instruction_dump ((unsigned long *) regs->pc);
5516 - if(regs->psr & PSR_PS)
5517 + if(regs->psr & PSR_PS) {
5518 + gr_handle_kernel_exploit();
5519 do_exit(SIGKILL);
5520 + }
5521 do_exit(SIGSEGV);
5522 }
5523
5524 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
5525 index 0cbdaa4..438e4c9 100644
5526 --- a/arch/sparc/kernel/traps_64.c
5527 +++ b/arch/sparc/kernel/traps_64.c
5528 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
5529 i + 1,
5530 p->trapstack[i].tstate, p->trapstack[i].tpc,
5531 p->trapstack[i].tnpc, p->trapstack[i].tt);
5532 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
5533 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
5534 }
5535 }
5536
5537 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
5538
5539 lvl -= 0x100;
5540 if (regs->tstate & TSTATE_PRIV) {
5541 +
5542 +#ifdef CONFIG_PAX_REFCOUNT
5543 + if (lvl == 6)
5544 + pax_report_refcount_overflow(regs);
5545 +#endif
5546 +
5547 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
5548 die_if_kernel(buffer, regs);
5549 }
5550 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
5551 void bad_trap_tl1(struct pt_regs *regs, long lvl)
5552 {
5553 char buffer[32];
5554 -
5555 +
5556 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
5557 0, lvl, SIGTRAP) == NOTIFY_STOP)
5558 return;
5559
5560 +#ifdef CONFIG_PAX_REFCOUNT
5561 + if (lvl == 6)
5562 + pax_report_refcount_overflow(regs);
5563 +#endif
5564 +
5565 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
5566
5567 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
5568 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
5569 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
5570 printk("%s" "ERROR(%d): ",
5571 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
5572 - printk("TPC<%pS>\n", (void *) regs->tpc);
5573 + printk("TPC<%pA>\n", (void *) regs->tpc);
5574 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
5575 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
5576 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
5577 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5578 smp_processor_id(),
5579 (type & 0x1) ? 'I' : 'D',
5580 regs->tpc);
5581 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
5582 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
5583 panic("Irrecoverable Cheetah+ parity error.");
5584 }
5585
5586 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5587 smp_processor_id(),
5588 (type & 0x1) ? 'I' : 'D',
5589 regs->tpc);
5590 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
5591 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
5592 }
5593
5594 struct sun4v_error_entry {
5595 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
5596
5597 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
5598 regs->tpc, tl);
5599 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
5600 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
5601 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5602 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
5603 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
5604 (void *) regs->u_regs[UREG_I7]);
5605 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
5606 "pte[%lx] error[%lx]\n",
5607 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
5608
5609 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
5610 regs->tpc, tl);
5611 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
5612 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
5613 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5614 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
5615 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
5616 (void *) regs->u_regs[UREG_I7]);
5617 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
5618 "pte[%lx] error[%lx]\n",
5619 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5620 fp = (unsigned long)sf->fp + STACK_BIAS;
5621 }
5622
5623 - printk(" [%016lx] %pS\n", pc, (void *) pc);
5624 + printk(" [%016lx] %pA\n", pc, (void *) pc);
5625 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
5626 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
5627 int index = tsk->curr_ret_stack;
5628 if (tsk->ret_stack && index >= graph) {
5629 pc = tsk->ret_stack[index - graph].ret;
5630 - printk(" [%016lx] %pS\n", pc, (void *) pc);
5631 + printk(" [%016lx] %pA\n", pc, (void *) pc);
5632 graph++;
5633 }
5634 }
5635 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
5636 return (struct reg_window *) (fp + STACK_BIAS);
5637 }
5638
5639 +extern void gr_handle_kernel_exploit(void);
5640 +
5641 void die_if_kernel(char *str, struct pt_regs *regs)
5642 {
5643 static int die_counter;
5644 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5645 while (rw &&
5646 count++ < 30 &&
5647 kstack_valid(tp, (unsigned long) rw)) {
5648 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
5649 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
5650 (void *) rw->ins[7]);
5651
5652 rw = kernel_stack_up(rw);
5653 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5654 }
5655 user_instruction_dump ((unsigned int __user *) regs->tpc);
5656 }
5657 - if (regs->tstate & TSTATE_PRIV)
5658 + if (regs->tstate & TSTATE_PRIV) {
5659 + gr_handle_kernel_exploit();
5660 do_exit(SIGKILL);
5661 + }
5662 do_exit(SIGSEGV);
5663 }
5664 EXPORT_SYMBOL(die_if_kernel);
5665 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
5666 index 76e4ac1..78f8bb1 100644
5667 --- a/arch/sparc/kernel/unaligned_64.c
5668 +++ b/arch/sparc/kernel/unaligned_64.c
5669 @@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
5670 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
5671
5672 if (__ratelimit(&ratelimit)) {
5673 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
5674 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
5675 regs->tpc, (void *) regs->tpc);
5676 }
5677 }
5678 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
5679 index a3fc437..fea9957 100644
5680 --- a/arch/sparc/lib/Makefile
5681 +++ b/arch/sparc/lib/Makefile
5682 @@ -2,7 +2,7 @@
5683 #
5684
5685 asflags-y := -ansi -DST_DIV0=0x02
5686 -ccflags-y := -Werror
5687 +#ccflags-y := -Werror
5688
5689 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
5690 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
5691 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
5692 index 59186e0..f747d7a 100644
5693 --- a/arch/sparc/lib/atomic_64.S
5694 +++ b/arch/sparc/lib/atomic_64.S
5695 @@ -18,7 +18,12 @@
5696 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5697 BACKOFF_SETUP(%o2)
5698 1: lduw [%o1], %g1
5699 - add %g1, %o0, %g7
5700 + addcc %g1, %o0, %g7
5701 +
5702 +#ifdef CONFIG_PAX_REFCOUNT
5703 + tvs %icc, 6
5704 +#endif
5705 +
5706 cas [%o1], %g1, %g7
5707 cmp %g1, %g7
5708 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5709 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5710 2: BACKOFF_SPIN(%o2, %o3, 1b)
5711 .size atomic_add, .-atomic_add
5712
5713 + .globl atomic_add_unchecked
5714 + .type atomic_add_unchecked,#function
5715 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5716 + BACKOFF_SETUP(%o2)
5717 +1: lduw [%o1], %g1
5718 + add %g1, %o0, %g7
5719 + cas [%o1], %g1, %g7
5720 + cmp %g1, %g7
5721 + bne,pn %icc, 2f
5722 + nop
5723 + retl
5724 + nop
5725 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5726 + .size atomic_add_unchecked, .-atomic_add_unchecked
5727 +
5728 .globl atomic_sub
5729 .type atomic_sub,#function
5730 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5731 BACKOFF_SETUP(%o2)
5732 1: lduw [%o1], %g1
5733 - sub %g1, %o0, %g7
5734 + subcc %g1, %o0, %g7
5735 +
5736 +#ifdef CONFIG_PAX_REFCOUNT
5737 + tvs %icc, 6
5738 +#endif
5739 +
5740 cas [%o1], %g1, %g7
5741 cmp %g1, %g7
5742 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5743 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5744 2: BACKOFF_SPIN(%o2, %o3, 1b)
5745 .size atomic_sub, .-atomic_sub
5746
5747 + .globl atomic_sub_unchecked
5748 + .type atomic_sub_unchecked,#function
5749 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5750 + BACKOFF_SETUP(%o2)
5751 +1: lduw [%o1], %g1
5752 + sub %g1, %o0, %g7
5753 + cas [%o1], %g1, %g7
5754 + cmp %g1, %g7
5755 + bne,pn %icc, 2f
5756 + nop
5757 + retl
5758 + nop
5759 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5760 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
5761 +
5762 .globl atomic_add_ret
5763 .type atomic_add_ret,#function
5764 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5765 BACKOFF_SETUP(%o2)
5766 1: lduw [%o1], %g1
5767 - add %g1, %o0, %g7
5768 + addcc %g1, %o0, %g7
5769 +
5770 +#ifdef CONFIG_PAX_REFCOUNT
5771 + tvs %icc, 6
5772 +#endif
5773 +
5774 cas [%o1], %g1, %g7
5775 cmp %g1, %g7
5776 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5777 @@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5778 2: BACKOFF_SPIN(%o2, %o3, 1b)
5779 .size atomic_add_ret, .-atomic_add_ret
5780
5781 + .globl atomic_add_ret_unchecked
5782 + .type atomic_add_ret_unchecked,#function
5783 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5784 + BACKOFF_SETUP(%o2)
5785 +1: lduw [%o1], %g1
5786 + addcc %g1, %o0, %g7
5787 + cas [%o1], %g1, %g7
5788 + cmp %g1, %g7
5789 + bne,pn %icc, 2f
5790 + add %g7, %o0, %g7
5791 + sra %g7, 0, %o0
5792 + retl
5793 + nop
5794 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5795 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
5796 +
5797 .globl atomic_sub_ret
5798 .type atomic_sub_ret,#function
5799 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5800 BACKOFF_SETUP(%o2)
5801 1: lduw [%o1], %g1
5802 - sub %g1, %o0, %g7
5803 + subcc %g1, %o0, %g7
5804 +
5805 +#ifdef CONFIG_PAX_REFCOUNT
5806 + tvs %icc, 6
5807 +#endif
5808 +
5809 cas [%o1], %g1, %g7
5810 cmp %g1, %g7
5811 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5812 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5813 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5814 BACKOFF_SETUP(%o2)
5815 1: ldx [%o1], %g1
5816 - add %g1, %o0, %g7
5817 + addcc %g1, %o0, %g7
5818 +
5819 +#ifdef CONFIG_PAX_REFCOUNT
5820 + tvs %xcc, 6
5821 +#endif
5822 +
5823 casx [%o1], %g1, %g7
5824 cmp %g1, %g7
5825 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5826 @@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5827 2: BACKOFF_SPIN(%o2, %o3, 1b)
5828 .size atomic64_add, .-atomic64_add
5829
5830 + .globl atomic64_add_unchecked
5831 + .type atomic64_add_unchecked,#function
5832 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5833 + BACKOFF_SETUP(%o2)
5834 +1: ldx [%o1], %g1
5835 + addcc %g1, %o0, %g7
5836 + casx [%o1], %g1, %g7
5837 + cmp %g1, %g7
5838 + bne,pn %xcc, 2f
5839 + nop
5840 + retl
5841 + nop
5842 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5843 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
5844 +
5845 .globl atomic64_sub
5846 .type atomic64_sub,#function
5847 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5848 BACKOFF_SETUP(%o2)
5849 1: ldx [%o1], %g1
5850 - sub %g1, %o0, %g7
5851 + subcc %g1, %o0, %g7
5852 +
5853 +#ifdef CONFIG_PAX_REFCOUNT
5854 + tvs %xcc, 6
5855 +#endif
5856 +
5857 casx [%o1], %g1, %g7
5858 cmp %g1, %g7
5859 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5860 @@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5861 2: BACKOFF_SPIN(%o2, %o3, 1b)
5862 .size atomic64_sub, .-atomic64_sub
5863
5864 + .globl atomic64_sub_unchecked
5865 + .type atomic64_sub_unchecked,#function
5866 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5867 + BACKOFF_SETUP(%o2)
5868 +1: ldx [%o1], %g1
5869 + subcc %g1, %o0, %g7
5870 + casx [%o1], %g1, %g7
5871 + cmp %g1, %g7
5872 + bne,pn %xcc, 2f
5873 + nop
5874 + retl
5875 + nop
5876 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5877 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
5878 +
5879 .globl atomic64_add_ret
5880 .type atomic64_add_ret,#function
5881 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5882 BACKOFF_SETUP(%o2)
5883 1: ldx [%o1], %g1
5884 - add %g1, %o0, %g7
5885 + addcc %g1, %o0, %g7
5886 +
5887 +#ifdef CONFIG_PAX_REFCOUNT
5888 + tvs %xcc, 6
5889 +#endif
5890 +
5891 casx [%o1], %g1, %g7
5892 cmp %g1, %g7
5893 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5894 @@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5895 2: BACKOFF_SPIN(%o2, %o3, 1b)
5896 .size atomic64_add_ret, .-atomic64_add_ret
5897
5898 + .globl atomic64_add_ret_unchecked
5899 + .type atomic64_add_ret_unchecked,#function
5900 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5901 + BACKOFF_SETUP(%o2)
5902 +1: ldx [%o1], %g1
5903 + addcc %g1, %o0, %g7
5904 + casx [%o1], %g1, %g7
5905 + cmp %g1, %g7
5906 + bne,pn %xcc, 2f
5907 + add %g7, %o0, %g7
5908 + mov %g7, %o0
5909 + retl
5910 + nop
5911 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5912 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
5913 +
5914 .globl atomic64_sub_ret
5915 .type atomic64_sub_ret,#function
5916 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5917 BACKOFF_SETUP(%o2)
5918 1: ldx [%o1], %g1
5919 - sub %g1, %o0, %g7
5920 + subcc %g1, %o0, %g7
5921 +
5922 +#ifdef CONFIG_PAX_REFCOUNT
5923 + tvs %xcc, 6
5924 +#endif
5925 +
5926 casx [%o1], %g1, %g7
5927 cmp %g1, %g7
5928 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5929 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
5930 index 1b30bb3..b4a16c7 100644
5931 --- a/arch/sparc/lib/ksyms.c
5932 +++ b/arch/sparc/lib/ksyms.c
5933 @@ -142,12 +142,18 @@ EXPORT_SYMBOL(__downgrade_write);
5934
5935 /* Atomic counter implementation. */
5936 EXPORT_SYMBOL(atomic_add);
5937 +EXPORT_SYMBOL(atomic_add_unchecked);
5938 EXPORT_SYMBOL(atomic_add_ret);
5939 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
5940 EXPORT_SYMBOL(atomic_sub);
5941 +EXPORT_SYMBOL(atomic_sub_unchecked);
5942 EXPORT_SYMBOL(atomic_sub_ret);
5943 EXPORT_SYMBOL(atomic64_add);
5944 +EXPORT_SYMBOL(atomic64_add_unchecked);
5945 EXPORT_SYMBOL(atomic64_add_ret);
5946 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
5947 EXPORT_SYMBOL(atomic64_sub);
5948 +EXPORT_SYMBOL(atomic64_sub_unchecked);
5949 EXPORT_SYMBOL(atomic64_sub_ret);
5950
5951 /* Atomic bit operations. */
5952 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
5953 index 301421c..e2535d1 100644
5954 --- a/arch/sparc/mm/Makefile
5955 +++ b/arch/sparc/mm/Makefile
5956 @@ -2,7 +2,7 @@
5957 #
5958
5959 asflags-y := -ansi
5960 -ccflags-y := -Werror
5961 +#ccflags-y := -Werror
5962
5963 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
5964 obj-y += fault_$(BITS).o
5965 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
5966 index 8023fd7..c8e89e9 100644
5967 --- a/arch/sparc/mm/fault_32.c
5968 +++ b/arch/sparc/mm/fault_32.c
5969 @@ -21,6 +21,9 @@
5970 #include <linux/perf_event.h>
5971 #include <linux/interrupt.h>
5972 #include <linux/kdebug.h>
5973 +#include <linux/slab.h>
5974 +#include <linux/pagemap.h>
5975 +#include <linux/compiler.h>
5976
5977 #include <asm/system.h>
5978 #include <asm/page.h>
5979 @@ -208,6 +211,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
5980 return safe_compute_effective_address(regs, insn);
5981 }
5982
5983 +#ifdef CONFIG_PAX_PAGEEXEC
5984 +#ifdef CONFIG_PAX_DLRESOLVE
5985 +static void pax_emuplt_close(struct vm_area_struct *vma)
5986 +{
5987 + vma->vm_mm->call_dl_resolve = 0UL;
5988 +}
5989 +
5990 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
5991 +{
5992 + unsigned int *kaddr;
5993 +
5994 + vmf->page = alloc_page(GFP_HIGHUSER);
5995 + if (!vmf->page)
5996 + return VM_FAULT_OOM;
5997 +
5998 + kaddr = kmap(vmf->page);
5999 + memset(kaddr, 0, PAGE_SIZE);
6000 + kaddr[0] = 0x9DE3BFA8U; /* save */
6001 + flush_dcache_page(vmf->page);
6002 + kunmap(vmf->page);
6003 + return VM_FAULT_MAJOR;
6004 +}
6005 +
6006 +static const struct vm_operations_struct pax_vm_ops = {
6007 + .close = pax_emuplt_close,
6008 + .fault = pax_emuplt_fault
6009 +};
6010 +
6011 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6012 +{
6013 + int ret;
6014 +
6015 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6016 + vma->vm_mm = current->mm;
6017 + vma->vm_start = addr;
6018 + vma->vm_end = addr + PAGE_SIZE;
6019 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6020 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6021 + vma->vm_ops = &pax_vm_ops;
6022 +
6023 + ret = insert_vm_struct(current->mm, vma);
6024 + if (ret)
6025 + return ret;
6026 +
6027 + ++current->mm->total_vm;
6028 + return 0;
6029 +}
6030 +#endif
6031 +
6032 +/*
6033 + * PaX: decide what to do with offenders (regs->pc = fault address)
6034 + *
6035 + * returns 1 when task should be killed
6036 + * 2 when patched PLT trampoline was detected
6037 + * 3 when unpatched PLT trampoline was detected
6038 + */
6039 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6040 +{
6041 +
6042 +#ifdef CONFIG_PAX_EMUPLT
6043 + int err;
6044 +
6045 + do { /* PaX: patched PLT emulation #1 */
6046 + unsigned int sethi1, sethi2, jmpl;
6047 +
6048 + err = get_user(sethi1, (unsigned int *)regs->pc);
6049 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6050 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6051 +
6052 + if (err)
6053 + break;
6054 +
6055 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6056 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6057 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6058 + {
6059 + unsigned int addr;
6060 +
6061 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6062 + addr = regs->u_regs[UREG_G1];
6063 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6064 + regs->pc = addr;
6065 + regs->npc = addr+4;
6066 + return 2;
6067 + }
6068 + } while (0);
6069 +
6070 + { /* PaX: patched PLT emulation #2 */
6071 + unsigned int ba;
6072 +
6073 + err = get_user(ba, (unsigned int *)regs->pc);
6074 +
6075 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6076 + unsigned int addr;
6077 +
6078 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6079 + regs->pc = addr;
6080 + regs->npc = addr+4;
6081 + return 2;
6082 + }
6083 + }
6084 +
6085 + do { /* PaX: patched PLT emulation #3 */
6086 + unsigned int sethi, jmpl, nop;
6087 +
6088 + err = get_user(sethi, (unsigned int *)regs->pc);
6089 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6090 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6091 +
6092 + if (err)
6093 + break;
6094 +
6095 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6096 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6097 + nop == 0x01000000U)
6098 + {
6099 + unsigned int addr;
6100 +
6101 + addr = (sethi & 0x003FFFFFU) << 10;
6102 + regs->u_regs[UREG_G1] = addr;
6103 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6104 + regs->pc = addr;
6105 + regs->npc = addr+4;
6106 + return 2;
6107 + }
6108 + } while (0);
6109 +
6110 + do { /* PaX: unpatched PLT emulation step 1 */
6111 + unsigned int sethi, ba, nop;
6112 +
6113 + err = get_user(sethi, (unsigned int *)regs->pc);
6114 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6115 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6116 +
6117 + if (err)
6118 + break;
6119 +
6120 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6121 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6122 + nop == 0x01000000U)
6123 + {
6124 + unsigned int addr, save, call;
6125 +
6126 + if ((ba & 0xFFC00000U) == 0x30800000U)
6127 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6128 + else
6129 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6130 +
6131 + err = get_user(save, (unsigned int *)addr);
6132 + err |= get_user(call, (unsigned int *)(addr+4));
6133 + err |= get_user(nop, (unsigned int *)(addr+8));
6134 + if (err)
6135 + break;
6136 +
6137 +#ifdef CONFIG_PAX_DLRESOLVE
6138 + if (save == 0x9DE3BFA8U &&
6139 + (call & 0xC0000000U) == 0x40000000U &&
6140 + nop == 0x01000000U)
6141 + {
6142 + struct vm_area_struct *vma;
6143 + unsigned long call_dl_resolve;
6144 +
6145 + down_read(&current->mm->mmap_sem);
6146 + call_dl_resolve = current->mm->call_dl_resolve;
6147 + up_read(&current->mm->mmap_sem);
6148 + if (likely(call_dl_resolve))
6149 + goto emulate;
6150 +
6151 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6152 +
6153 + down_write(&current->mm->mmap_sem);
6154 + if (current->mm->call_dl_resolve) {
6155 + call_dl_resolve = current->mm->call_dl_resolve;
6156 + up_write(&current->mm->mmap_sem);
6157 + if (vma)
6158 + kmem_cache_free(vm_area_cachep, vma);
6159 + goto emulate;
6160 + }
6161 +
6162 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6163 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6164 + up_write(&current->mm->mmap_sem);
6165 + if (vma)
6166 + kmem_cache_free(vm_area_cachep, vma);
6167 + return 1;
6168 + }
6169 +
6170 + if (pax_insert_vma(vma, call_dl_resolve)) {
6171 + up_write(&current->mm->mmap_sem);
6172 + kmem_cache_free(vm_area_cachep, vma);
6173 + return 1;
6174 + }
6175 +
6176 + current->mm->call_dl_resolve = call_dl_resolve;
6177 + up_write(&current->mm->mmap_sem);
6178 +
6179 +emulate:
6180 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6181 + regs->pc = call_dl_resolve;
6182 + regs->npc = addr+4;
6183 + return 3;
6184 + }
6185 +#endif
6186 +
6187 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6188 + if ((save & 0xFFC00000U) == 0x05000000U &&
6189 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6190 + nop == 0x01000000U)
6191 + {
6192 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6193 + regs->u_regs[UREG_G2] = addr + 4;
6194 + addr = (save & 0x003FFFFFU) << 10;
6195 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6196 + regs->pc = addr;
6197 + regs->npc = addr+4;
6198 + return 3;
6199 + }
6200 + }
6201 + } while (0);
6202 +
6203 + do { /* PaX: unpatched PLT emulation step 2 */
6204 + unsigned int save, call, nop;
6205 +
6206 + err = get_user(save, (unsigned int *)(regs->pc-4));
6207 + err |= get_user(call, (unsigned int *)regs->pc);
6208 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6209 + if (err)
6210 + break;
6211 +
6212 + if (save == 0x9DE3BFA8U &&
6213 + (call & 0xC0000000U) == 0x40000000U &&
6214 + nop == 0x01000000U)
6215 + {
6216 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6217 +
6218 + regs->u_regs[UREG_RETPC] = regs->pc;
6219 + regs->pc = dl_resolve;
6220 + regs->npc = dl_resolve+4;
6221 + return 3;
6222 + }
6223 + } while (0);
6224 +#endif
6225 +
6226 + return 1;
6227 +}
6228 +
6229 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6230 +{
6231 + unsigned long i;
6232 +
6233 + printk(KERN_ERR "PAX: bytes at PC: ");
6234 + for (i = 0; i < 8; i++) {
6235 + unsigned int c;
6236 + if (get_user(c, (unsigned int *)pc+i))
6237 + printk(KERN_CONT "???????? ");
6238 + else
6239 + printk(KERN_CONT "%08x ", c);
6240 + }
6241 + printk("\n");
6242 +}
6243 +#endif
6244 +
6245 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6246 int text_fault)
6247 {
6248 @@ -280,6 +545,24 @@ good_area:
6249 if(!(vma->vm_flags & VM_WRITE))
6250 goto bad_area;
6251 } else {
6252 +
6253 +#ifdef CONFIG_PAX_PAGEEXEC
6254 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6255 + up_read(&mm->mmap_sem);
6256 + switch (pax_handle_fetch_fault(regs)) {
6257 +
6258 +#ifdef CONFIG_PAX_EMUPLT
6259 + case 2:
6260 + case 3:
6261 + return;
6262 +#endif
6263 +
6264 + }
6265 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6266 + do_group_exit(SIGKILL);
6267 + }
6268 +#endif
6269 +
6270 /* Allow reads even for write-only mappings */
6271 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6272 goto bad_area;
6273 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6274 index 504c062..6fcb9c6 100644
6275 --- a/arch/sparc/mm/fault_64.c
6276 +++ b/arch/sparc/mm/fault_64.c
6277 @@ -21,6 +21,9 @@
6278 #include <linux/kprobes.h>
6279 #include <linux/kdebug.h>
6280 #include <linux/percpu.h>
6281 +#include <linux/slab.h>
6282 +#include <linux/pagemap.h>
6283 +#include <linux/compiler.h>
6284
6285 #include <asm/page.h>
6286 #include <asm/pgtable.h>
6287 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6288 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6289 regs->tpc);
6290 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6291 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6292 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6293 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6294 dump_stack();
6295 unhandled_fault(regs->tpc, current, regs);
6296 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6297 show_regs(regs);
6298 }
6299
6300 +#ifdef CONFIG_PAX_PAGEEXEC
6301 +#ifdef CONFIG_PAX_DLRESOLVE
6302 +static void pax_emuplt_close(struct vm_area_struct *vma)
6303 +{
6304 + vma->vm_mm->call_dl_resolve = 0UL;
6305 +}
6306 +
6307 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6308 +{
6309 + unsigned int *kaddr;
6310 +
6311 + vmf->page = alloc_page(GFP_HIGHUSER);
6312 + if (!vmf->page)
6313 + return VM_FAULT_OOM;
6314 +
6315 + kaddr = kmap(vmf->page);
6316 + memset(kaddr, 0, PAGE_SIZE);
6317 + kaddr[0] = 0x9DE3BFA8U; /* save */
6318 + flush_dcache_page(vmf->page);
6319 + kunmap(vmf->page);
6320 + return VM_FAULT_MAJOR;
6321 +}
6322 +
6323 +static const struct vm_operations_struct pax_vm_ops = {
6324 + .close = pax_emuplt_close,
6325 + .fault = pax_emuplt_fault
6326 +};
6327 +
6328 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6329 +{
6330 + int ret;
6331 +
6332 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6333 + vma->vm_mm = current->mm;
6334 + vma->vm_start = addr;
6335 + vma->vm_end = addr + PAGE_SIZE;
6336 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6337 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6338 + vma->vm_ops = &pax_vm_ops;
6339 +
6340 + ret = insert_vm_struct(current->mm, vma);
6341 + if (ret)
6342 + return ret;
6343 +
6344 + ++current->mm->total_vm;
6345 + return 0;
6346 +}
6347 +#endif
6348 +
6349 +/*
6350 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6351 + *
6352 + * returns 1 when task should be killed
6353 + * 2 when patched PLT trampoline was detected
6354 + * 3 when unpatched PLT trampoline was detected
6355 + */
6356 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6357 +{
6358 +
6359 +#ifdef CONFIG_PAX_EMUPLT
6360 + int err;
6361 +
6362 + do { /* PaX: patched PLT emulation #1 */
6363 + unsigned int sethi1, sethi2, jmpl;
6364 +
6365 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6366 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6367 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6368 +
6369 + if (err)
6370 + break;
6371 +
6372 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6373 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6374 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6375 + {
6376 + unsigned long addr;
6377 +
6378 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6379 + addr = regs->u_regs[UREG_G1];
6380 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6381 +
6382 + if (test_thread_flag(TIF_32BIT))
6383 + addr &= 0xFFFFFFFFUL;
6384 +
6385 + regs->tpc = addr;
6386 + regs->tnpc = addr+4;
6387 + return 2;
6388 + }
6389 + } while (0);
6390 +
6391 + { /* PaX: patched PLT emulation #2 */
6392 + unsigned int ba;
6393 +
6394 + err = get_user(ba, (unsigned int *)regs->tpc);
6395 +
6396 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6397 + unsigned long addr;
6398 +
6399 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6400 +
6401 + if (test_thread_flag(TIF_32BIT))
6402 + addr &= 0xFFFFFFFFUL;
6403 +
6404 + regs->tpc = addr;
6405 + regs->tnpc = addr+4;
6406 + return 2;
6407 + }
6408 + }
6409 +
6410 + do { /* PaX: patched PLT emulation #3 */
6411 + unsigned int sethi, jmpl, nop;
6412 +
6413 + err = get_user(sethi, (unsigned int *)regs->tpc);
6414 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6415 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6416 +
6417 + if (err)
6418 + break;
6419 +
6420 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6421 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6422 + nop == 0x01000000U)
6423 + {
6424 + unsigned long addr;
6425 +
6426 + addr = (sethi & 0x003FFFFFU) << 10;
6427 + regs->u_regs[UREG_G1] = addr;
6428 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6429 +
6430 + if (test_thread_flag(TIF_32BIT))
6431 + addr &= 0xFFFFFFFFUL;
6432 +
6433 + regs->tpc = addr;
6434 + regs->tnpc = addr+4;
6435 + return 2;
6436 + }
6437 + } while (0);
6438 +
6439 + do { /* PaX: patched PLT emulation #4 */
6440 + unsigned int sethi, mov1, call, mov2;
6441 +
6442 + err = get_user(sethi, (unsigned int *)regs->tpc);
6443 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6444 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6445 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6446 +
6447 + if (err)
6448 + break;
6449 +
6450 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6451 + mov1 == 0x8210000FU &&
6452 + (call & 0xC0000000U) == 0x40000000U &&
6453 + mov2 == 0x9E100001U)
6454 + {
6455 + unsigned long addr;
6456 +
6457 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6458 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6459 +
6460 + if (test_thread_flag(TIF_32BIT))
6461 + addr &= 0xFFFFFFFFUL;
6462 +
6463 + regs->tpc = addr;
6464 + regs->tnpc = addr+4;
6465 + return 2;
6466 + }
6467 + } while (0);
6468 +
6469 + do { /* PaX: patched PLT emulation #5 */
6470 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6471 +
6472 + err = get_user(sethi, (unsigned int *)regs->tpc);
6473 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6474 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6475 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6476 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6477 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6478 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6479 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6480 +
6481 + if (err)
6482 + break;
6483 +
6484 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6485 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6486 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6487 + (or1 & 0xFFFFE000U) == 0x82106000U &&
6488 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6489 + sllx == 0x83287020U &&
6490 + jmpl == 0x81C04005U &&
6491 + nop == 0x01000000U)
6492 + {
6493 + unsigned long addr;
6494 +
6495 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6496 + regs->u_regs[UREG_G1] <<= 32;
6497 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6498 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6499 + regs->tpc = addr;
6500 + regs->tnpc = addr+4;
6501 + return 2;
6502 + }
6503 + } while (0);
6504 +
6505 + do { /* PaX: patched PLT emulation #6 */
6506 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
6507 +
6508 + err = get_user(sethi, (unsigned int *)regs->tpc);
6509 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6510 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6511 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
6512 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
6513 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
6514 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
6515 +
6516 + if (err)
6517 + break;
6518 +
6519 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6520 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6521 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6522 + sllx == 0x83287020U &&
6523 + (or & 0xFFFFE000U) == 0x8A116000U &&
6524 + jmpl == 0x81C04005U &&
6525 + nop == 0x01000000U)
6526 + {
6527 + unsigned long addr;
6528 +
6529 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
6530 + regs->u_regs[UREG_G1] <<= 32;
6531 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
6532 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6533 + regs->tpc = addr;
6534 + regs->tnpc = addr+4;
6535 + return 2;
6536 + }
6537 + } while (0);
6538 +
6539 + do { /* PaX: unpatched PLT emulation step 1 */
6540 + unsigned int sethi, ba, nop;
6541 +
6542 + err = get_user(sethi, (unsigned int *)regs->tpc);
6543 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6544 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6545 +
6546 + if (err)
6547 + break;
6548 +
6549 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6550 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6551 + nop == 0x01000000U)
6552 + {
6553 + unsigned long addr;
6554 + unsigned int save, call;
6555 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
6556 +
6557 + if ((ba & 0xFFC00000U) == 0x30800000U)
6558 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6559 + else
6560 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6561 +
6562 + if (test_thread_flag(TIF_32BIT))
6563 + addr &= 0xFFFFFFFFUL;
6564 +
6565 + err = get_user(save, (unsigned int *)addr);
6566 + err |= get_user(call, (unsigned int *)(addr+4));
6567 + err |= get_user(nop, (unsigned int *)(addr+8));
6568 + if (err)
6569 + break;
6570 +
6571 +#ifdef CONFIG_PAX_DLRESOLVE
6572 + if (save == 0x9DE3BFA8U &&
6573 + (call & 0xC0000000U) == 0x40000000U &&
6574 + nop == 0x01000000U)
6575 + {
6576 + struct vm_area_struct *vma;
6577 + unsigned long call_dl_resolve;
6578 +
6579 + down_read(&current->mm->mmap_sem);
6580 + call_dl_resolve = current->mm->call_dl_resolve;
6581 + up_read(&current->mm->mmap_sem);
6582 + if (likely(call_dl_resolve))
6583 + goto emulate;
6584 +
6585 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6586 +
6587 + down_write(&current->mm->mmap_sem);
6588 + if (current->mm->call_dl_resolve) {
6589 + call_dl_resolve = current->mm->call_dl_resolve;
6590 + up_write(&current->mm->mmap_sem);
6591 + if (vma)
6592 + kmem_cache_free(vm_area_cachep, vma);
6593 + goto emulate;
6594 + }
6595 +
6596 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6597 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6598 + up_write(&current->mm->mmap_sem);
6599 + if (vma)
6600 + kmem_cache_free(vm_area_cachep, vma);
6601 + return 1;
6602 + }
6603 +
6604 + if (pax_insert_vma(vma, call_dl_resolve)) {
6605 + up_write(&current->mm->mmap_sem);
6606 + kmem_cache_free(vm_area_cachep, vma);
6607 + return 1;
6608 + }
6609 +
6610 + current->mm->call_dl_resolve = call_dl_resolve;
6611 + up_write(&current->mm->mmap_sem);
6612 +
6613 +emulate:
6614 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6615 + regs->tpc = call_dl_resolve;
6616 + regs->tnpc = addr+4;
6617 + return 3;
6618 + }
6619 +#endif
6620 +
6621 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6622 + if ((save & 0xFFC00000U) == 0x05000000U &&
6623 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6624 + nop == 0x01000000U)
6625 + {
6626 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6627 + regs->u_regs[UREG_G2] = addr + 4;
6628 + addr = (save & 0x003FFFFFU) << 10;
6629 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6630 +
6631 + if (test_thread_flag(TIF_32BIT))
6632 + addr &= 0xFFFFFFFFUL;
6633 +
6634 + regs->tpc = addr;
6635 + regs->tnpc = addr+4;
6636 + return 3;
6637 + }
6638 +
6639 + /* PaX: 64-bit PLT stub */
6640 + err = get_user(sethi1, (unsigned int *)addr);
6641 + err |= get_user(sethi2, (unsigned int *)(addr+4));
6642 + err |= get_user(or1, (unsigned int *)(addr+8));
6643 + err |= get_user(or2, (unsigned int *)(addr+12));
6644 + err |= get_user(sllx, (unsigned int *)(addr+16));
6645 + err |= get_user(add, (unsigned int *)(addr+20));
6646 + err |= get_user(jmpl, (unsigned int *)(addr+24));
6647 + err |= get_user(nop, (unsigned int *)(addr+28));
6648 + if (err)
6649 + break;
6650 +
6651 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
6652 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6653 + (or1 & 0xFFFFE000U) == 0x88112000U &&
6654 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6655 + sllx == 0x89293020U &&
6656 + add == 0x8A010005U &&
6657 + jmpl == 0x89C14000U &&
6658 + nop == 0x01000000U)
6659 + {
6660 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6661 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6662 + regs->u_regs[UREG_G4] <<= 32;
6663 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6664 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
6665 + regs->u_regs[UREG_G4] = addr + 24;
6666 + addr = regs->u_regs[UREG_G5];
6667 + regs->tpc = addr;
6668 + regs->tnpc = addr+4;
6669 + return 3;
6670 + }
6671 + }
6672 + } while (0);
6673 +
6674 +#ifdef CONFIG_PAX_DLRESOLVE
6675 + do { /* PaX: unpatched PLT emulation step 2 */
6676 + unsigned int save, call, nop;
6677 +
6678 + err = get_user(save, (unsigned int *)(regs->tpc-4));
6679 + err |= get_user(call, (unsigned int *)regs->tpc);
6680 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
6681 + if (err)
6682 + break;
6683 +
6684 + if (save == 0x9DE3BFA8U &&
6685 + (call & 0xC0000000U) == 0x40000000U &&
6686 + nop == 0x01000000U)
6687 + {
6688 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6689 +
6690 + if (test_thread_flag(TIF_32BIT))
6691 + dl_resolve &= 0xFFFFFFFFUL;
6692 +
6693 + regs->u_regs[UREG_RETPC] = regs->tpc;
6694 + regs->tpc = dl_resolve;
6695 + regs->tnpc = dl_resolve+4;
6696 + return 3;
6697 + }
6698 + } while (0);
6699 +#endif
6700 +
6701 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
6702 + unsigned int sethi, ba, nop;
6703 +
6704 + err = get_user(sethi, (unsigned int *)regs->tpc);
6705 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6706 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6707 +
6708 + if (err)
6709 + break;
6710 +
6711 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6712 + (ba & 0xFFF00000U) == 0x30600000U &&
6713 + nop == 0x01000000U)
6714 + {
6715 + unsigned long addr;
6716 +
6717 + addr = (sethi & 0x003FFFFFU) << 10;
6718 + regs->u_regs[UREG_G1] = addr;
6719 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6720 +
6721 + if (test_thread_flag(TIF_32BIT))
6722 + addr &= 0xFFFFFFFFUL;
6723 +
6724 + regs->tpc = addr;
6725 + regs->tnpc = addr+4;
6726 + return 2;
6727 + }
6728 + } while (0);
6729 +
6730 +#endif
6731 +
6732 + return 1;
6733 +}
6734 +
6735 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6736 +{
6737 + unsigned long i;
6738 +
6739 + printk(KERN_ERR "PAX: bytes at PC: ");
6740 + for (i = 0; i < 8; i++) {
6741 + unsigned int c;
6742 + if (get_user(c, (unsigned int *)pc+i))
6743 + printk(KERN_CONT "???????? ");
6744 + else
6745 + printk(KERN_CONT "%08x ", c);
6746 + }
6747 + printk("\n");
6748 +}
6749 +#endif
6750 +
6751 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6752 {
6753 struct mm_struct *mm = current->mm;
6754 @@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6755 if (!vma)
6756 goto bad_area;
6757
6758 +#ifdef CONFIG_PAX_PAGEEXEC
6759 + /* PaX: detect ITLB misses on non-exec pages */
6760 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
6761 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
6762 + {
6763 + if (address != regs->tpc)
6764 + goto good_area;
6765 +
6766 + up_read(&mm->mmap_sem);
6767 + switch (pax_handle_fetch_fault(regs)) {
6768 +
6769 +#ifdef CONFIG_PAX_EMUPLT
6770 + case 2:
6771 + case 3:
6772 + return;
6773 +#endif
6774 +
6775 + }
6776 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
6777 + do_group_exit(SIGKILL);
6778 + }
6779 +#endif
6780 +
6781 /* Pure DTLB misses do not tell us whether the fault causing
6782 * load/store/atomic was a write or not, it only says that there
6783 * was no match. So in such a case we (carefully) read the
6784 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
6785 index 07e1453..0a7d9e9 100644
6786 --- a/arch/sparc/mm/hugetlbpage.c
6787 +++ b/arch/sparc/mm/hugetlbpage.c
6788 @@ -67,7 +67,7 @@ full_search:
6789 }
6790 return -ENOMEM;
6791 }
6792 - if (likely(!vma || addr + len <= vma->vm_start)) {
6793 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6794 /*
6795 * Remember the place where we stopped the search:
6796 */
6797 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6798 /* make sure it can fit in the remaining address space */
6799 if (likely(addr > len)) {
6800 vma = find_vma(mm, addr-len);
6801 - if (!vma || addr <= vma->vm_start) {
6802 + if (check_heap_stack_gap(vma, addr - len, len)) {
6803 /* remember the address as a hint for next time */
6804 return (mm->free_area_cache = addr-len);
6805 }
6806 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6807 if (unlikely(mm->mmap_base < len))
6808 goto bottomup;
6809
6810 - addr = (mm->mmap_base-len) & HPAGE_MASK;
6811 + addr = mm->mmap_base - len;
6812
6813 do {
6814 + addr &= HPAGE_MASK;
6815 /*
6816 * Lookup failure means no vma is above this address,
6817 * else if new region fits below vma->vm_start,
6818 * return with success:
6819 */
6820 vma = find_vma(mm, addr);
6821 - if (likely(!vma || addr+len <= vma->vm_start)) {
6822 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6823 /* remember the address as a hint for next time */
6824 return (mm->free_area_cache = addr);
6825 }
6826 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6827 mm->cached_hole_size = vma->vm_start - addr;
6828
6829 /* try just below the current vma->vm_start */
6830 - addr = (vma->vm_start-len) & HPAGE_MASK;
6831 - } while (likely(len < vma->vm_start));
6832 + addr = skip_heap_stack_gap(vma, len);
6833 + } while (!IS_ERR_VALUE(addr));
6834
6835 bottomup:
6836 /*
6837 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
6838 if (addr) {
6839 addr = ALIGN(addr, HPAGE_SIZE);
6840 vma = find_vma(mm, addr);
6841 - if (task_size - len >= addr &&
6842 - (!vma || addr + len <= vma->vm_start))
6843 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
6844 return addr;
6845 }
6846 if (mm->get_unmapped_area == arch_get_unmapped_area)
6847 diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
6848 index 7b00de6..78239f4 100644
6849 --- a/arch/sparc/mm/init_32.c
6850 +++ b/arch/sparc/mm/init_32.c
6851 @@ -316,6 +316,9 @@ extern void device_scan(void);
6852 pgprot_t PAGE_SHARED __read_mostly;
6853 EXPORT_SYMBOL(PAGE_SHARED);
6854
6855 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
6856 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
6857 +
6858 void __init paging_init(void)
6859 {
6860 switch(sparc_cpu_model) {
6861 @@ -344,17 +347,17 @@ void __init paging_init(void)
6862
6863 /* Initialize the protection map with non-constant, MMU dependent values. */
6864 protection_map[0] = PAGE_NONE;
6865 - protection_map[1] = PAGE_READONLY;
6866 - protection_map[2] = PAGE_COPY;
6867 - protection_map[3] = PAGE_COPY;
6868 + protection_map[1] = PAGE_READONLY_NOEXEC;
6869 + protection_map[2] = PAGE_COPY_NOEXEC;
6870 + protection_map[3] = PAGE_COPY_NOEXEC;
6871 protection_map[4] = PAGE_READONLY;
6872 protection_map[5] = PAGE_READONLY;
6873 protection_map[6] = PAGE_COPY;
6874 protection_map[7] = PAGE_COPY;
6875 protection_map[8] = PAGE_NONE;
6876 - protection_map[9] = PAGE_READONLY;
6877 - protection_map[10] = PAGE_SHARED;
6878 - protection_map[11] = PAGE_SHARED;
6879 + protection_map[9] = PAGE_READONLY_NOEXEC;
6880 + protection_map[10] = PAGE_SHARED_NOEXEC;
6881 + protection_map[11] = PAGE_SHARED_NOEXEC;
6882 protection_map[12] = PAGE_READONLY;
6883 protection_map[13] = PAGE_READONLY;
6884 protection_map[14] = PAGE_SHARED;
6885 diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
6886 index cbef74e..c38fead 100644
6887 --- a/arch/sparc/mm/srmmu.c
6888 +++ b/arch/sparc/mm/srmmu.c
6889 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
6890 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
6891 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
6892 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
6893 +
6894 +#ifdef CONFIG_PAX_PAGEEXEC
6895 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
6896 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
6897 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
6898 +#endif
6899 +
6900 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
6901 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
6902
6903 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
6904 index 27fe667..36d474c 100644
6905 --- a/arch/tile/include/asm/atomic_64.h
6906 +++ b/arch/tile/include/asm/atomic_64.h
6907 @@ -142,6 +142,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
6908
6909 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6910
6911 +#define atomic64_read_unchecked(v) atomic64_read(v)
6912 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6913 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6914 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6915 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6916 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
6917 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6918 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
6919 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6920 +
6921 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
6922 #define smp_mb__before_atomic_dec() smp_mb()
6923 #define smp_mb__after_atomic_dec() smp_mb()
6924 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
6925 index 392e533..536b092 100644
6926 --- a/arch/tile/include/asm/cache.h
6927 +++ b/arch/tile/include/asm/cache.h
6928 @@ -15,11 +15,12 @@
6929 #ifndef _ASM_TILE_CACHE_H
6930 #define _ASM_TILE_CACHE_H
6931
6932 +#include <linux/const.h>
6933 #include <arch/chip.h>
6934
6935 /* bytes per L1 data cache line */
6936 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
6937 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6938 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6939
6940 /* bytes per L2 cache line */
6941 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
6942 diff --git a/arch/um/Makefile b/arch/um/Makefile
6943 index 7730af6..cce5b19 100644
6944 --- a/arch/um/Makefile
6945 +++ b/arch/um/Makefile
6946 @@ -61,6 +61,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
6947 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
6948 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
6949
6950 +ifdef CONSTIFY_PLUGIN
6951 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
6952 +endif
6953 +
6954 #This will adjust *FLAGS accordingly to the platform.
6955 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
6956
6957 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
6958 index 19e1bdd..3665b77 100644
6959 --- a/arch/um/include/asm/cache.h
6960 +++ b/arch/um/include/asm/cache.h
6961 @@ -1,6 +1,7 @@
6962 #ifndef __UM_CACHE_H
6963 #define __UM_CACHE_H
6964
6965 +#include <linux/const.h>
6966
6967 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
6968 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
6969 @@ -12,6 +13,6 @@
6970 # define L1_CACHE_SHIFT 5
6971 #endif
6972
6973 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6974 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6975
6976 #endif
6977 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
6978 index 6c03acd..a5e0215 100644
6979 --- a/arch/um/include/asm/kmap_types.h
6980 +++ b/arch/um/include/asm/kmap_types.h
6981 @@ -23,6 +23,7 @@ enum km_type {
6982 KM_IRQ1,
6983 KM_SOFTIRQ0,
6984 KM_SOFTIRQ1,
6985 + KM_CLEARPAGE,
6986 KM_TYPE_NR
6987 };
6988
6989 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
6990 index 7cfc3ce..cbd1a58 100644
6991 --- a/arch/um/include/asm/page.h
6992 +++ b/arch/um/include/asm/page.h
6993 @@ -14,6 +14,9 @@
6994 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
6995 #define PAGE_MASK (~(PAGE_SIZE-1))
6996
6997 +#define ktla_ktva(addr) (addr)
6998 +#define ktva_ktla(addr) (addr)
6999 +
7000 #ifndef __ASSEMBLY__
7001
7002 struct page;
7003 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7004 index c533835..84db18e 100644
7005 --- a/arch/um/kernel/process.c
7006 +++ b/arch/um/kernel/process.c
7007 @@ -406,22 +406,6 @@ int singlestepping(void * t)
7008 return 2;
7009 }
7010
7011 -/*
7012 - * Only x86 and x86_64 have an arch_align_stack().
7013 - * All other arches have "#define arch_align_stack(x) (x)"
7014 - * in their asm/system.h
7015 - * As this is included in UML from asm-um/system-generic.h,
7016 - * we can use it to behave as the subarch does.
7017 - */
7018 -#ifndef arch_align_stack
7019 -unsigned long arch_align_stack(unsigned long sp)
7020 -{
7021 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7022 - sp -= get_random_int() % 8192;
7023 - return sp & ~0xf;
7024 -}
7025 -#endif
7026 -
7027 unsigned long get_wchan(struct task_struct *p)
7028 {
7029 unsigned long stack_page, sp, ip;
7030 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7031 index ad8f795..2c7eec6 100644
7032 --- a/arch/unicore32/include/asm/cache.h
7033 +++ b/arch/unicore32/include/asm/cache.h
7034 @@ -12,8 +12,10 @@
7035 #ifndef __UNICORE_CACHE_H__
7036 #define __UNICORE_CACHE_H__
7037
7038 -#define L1_CACHE_SHIFT (5)
7039 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7040 +#include <linux/const.h>
7041 +
7042 +#define L1_CACHE_SHIFT 5
7043 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7044
7045 /*
7046 * Memory returned by kmalloc() may be used for DMA, so we must make
7047 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7048 index efb4294..61bc18c 100644
7049 --- a/arch/x86/Kconfig
7050 +++ b/arch/x86/Kconfig
7051 @@ -235,7 +235,7 @@ config X86_HT
7052
7053 config X86_32_LAZY_GS
7054 def_bool y
7055 - depends on X86_32 && !CC_STACKPROTECTOR
7056 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7057
7058 config ARCH_HWEIGHT_CFLAGS
7059 string
7060 @@ -1022,7 +1022,7 @@ choice
7061
7062 config NOHIGHMEM
7063 bool "off"
7064 - depends on !X86_NUMAQ
7065 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7066 ---help---
7067 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7068 However, the address space of 32-bit x86 processors is only 4
7069 @@ -1059,7 +1059,7 @@ config NOHIGHMEM
7070
7071 config HIGHMEM4G
7072 bool "4GB"
7073 - depends on !X86_NUMAQ
7074 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7075 ---help---
7076 Select this if you have a 32-bit processor and between 1 and 4
7077 gigabytes of physical RAM.
7078 @@ -1113,7 +1113,7 @@ config PAGE_OFFSET
7079 hex
7080 default 0xB0000000 if VMSPLIT_3G_OPT
7081 default 0x80000000 if VMSPLIT_2G
7082 - default 0x78000000 if VMSPLIT_2G_OPT
7083 + default 0x70000000 if VMSPLIT_2G_OPT
7084 default 0x40000000 if VMSPLIT_1G
7085 default 0xC0000000
7086 depends on X86_32
7087 @@ -1496,6 +1496,7 @@ config SECCOMP
7088
7089 config CC_STACKPROTECTOR
7090 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7091 + depends on X86_64 || !PAX_MEMORY_UDEREF
7092 ---help---
7093 This option turns on the -fstack-protector GCC feature. This
7094 feature puts, at the beginning of functions, a canary value on
7095 @@ -1553,6 +1554,7 @@ config KEXEC_JUMP
7096 config PHYSICAL_START
7097 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7098 default "0x1000000"
7099 + range 0x400000 0x40000000
7100 ---help---
7101 This gives the physical address where the kernel is loaded.
7102
7103 @@ -1616,6 +1618,7 @@ config X86_NEED_RELOCS
7104 config PHYSICAL_ALIGN
7105 hex "Alignment value to which kernel should be aligned" if X86_32
7106 default "0x1000000"
7107 + range 0x400000 0x1000000 if PAX_KERNEXEC
7108 range 0x2000 0x1000000
7109 ---help---
7110 This value puts the alignment restrictions on physical address
7111 @@ -1647,9 +1650,10 @@ config HOTPLUG_CPU
7112 Say N if you want to disable CPU hotplug.
7113
7114 config COMPAT_VDSO
7115 - def_bool y
7116 + def_bool n
7117 prompt "Compat VDSO support"
7118 depends on X86_32 || IA32_EMULATION
7119 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7120 ---help---
7121 Map the 32-bit VDSO to the predictable old-style address too.
7122
7123 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7124 index e3ca7e0..b30b28a 100644
7125 --- a/arch/x86/Kconfig.cpu
7126 +++ b/arch/x86/Kconfig.cpu
7127 @@ -341,7 +341,7 @@ config X86_PPRO_FENCE
7128
7129 config X86_F00F_BUG
7130 def_bool y
7131 - depends on M586MMX || M586TSC || M586 || M486 || M386
7132 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7133
7134 config X86_INVD_BUG
7135 def_bool y
7136 @@ -365,7 +365,7 @@ config X86_POPAD_OK
7137
7138 config X86_ALIGNMENT_16
7139 def_bool y
7140 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7141 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7142
7143 config X86_INTEL_USERCOPY
7144 def_bool y
7145 @@ -411,7 +411,7 @@ config X86_CMPXCHG64
7146 # generates cmov.
7147 config X86_CMOV
7148 def_bool y
7149 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7150 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7151
7152 config X86_MINIMUM_CPU_FAMILY
7153 int
7154 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7155 index bf56e17..05f9891 100644
7156 --- a/arch/x86/Kconfig.debug
7157 +++ b/arch/x86/Kconfig.debug
7158 @@ -81,7 +81,7 @@ config X86_PTDUMP
7159 config DEBUG_RODATA
7160 bool "Write protect kernel read-only data structures"
7161 default y
7162 - depends on DEBUG_KERNEL
7163 + depends on DEBUG_KERNEL && BROKEN
7164 ---help---
7165 Mark the kernel read-only data as write-protected in the pagetables,
7166 in order to catch accidental (and incorrect) writes to such const
7167 @@ -99,7 +99,7 @@ config DEBUG_RODATA_TEST
7168
7169 config DEBUG_SET_MODULE_RONX
7170 bool "Set loadable kernel module data as NX and text as RO"
7171 - depends on MODULES
7172 + depends on MODULES && BROKEN
7173 ---help---
7174 This option helps catch unintended modifications to loadable
7175 kernel module's text and read-only data. It also prevents execution
7176 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7177 index b02e509..2631e48 100644
7178 --- a/arch/x86/Makefile
7179 +++ b/arch/x86/Makefile
7180 @@ -46,6 +46,7 @@ else
7181 UTS_MACHINE := x86_64
7182 CHECKFLAGS += -D__x86_64__ -m64
7183
7184 + biarch := $(call cc-option,-m64)
7185 KBUILD_AFLAGS += -m64
7186 KBUILD_CFLAGS += -m64
7187
7188 @@ -195,3 +196,12 @@ define archhelp
7189 echo ' FDARGS="..." arguments for the booted kernel'
7190 echo ' FDINITRD=file initrd for the booted kernel'
7191 endef
7192 +
7193 +define OLD_LD
7194 +
7195 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7196 +*** Please upgrade your binutils to 2.18 or newer
7197 +endef
7198 +
7199 +archprepare:
7200 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7201 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7202 index 95365a8..52f857b 100644
7203 --- a/arch/x86/boot/Makefile
7204 +++ b/arch/x86/boot/Makefile
7205 @@ -63,6 +63,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7206 $(call cc-option, -fno-stack-protector) \
7207 $(call cc-option, -mpreferred-stack-boundary=2)
7208 KBUILD_CFLAGS += $(call cc-option, -m32)
7209 +ifdef CONSTIFY_PLUGIN
7210 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7211 +endif
7212 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7213 GCOV_PROFILE := n
7214
7215 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7216 index 878e4b9..20537ab 100644
7217 --- a/arch/x86/boot/bitops.h
7218 +++ b/arch/x86/boot/bitops.h
7219 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7220 u8 v;
7221 const u32 *p = (const u32 *)addr;
7222
7223 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7224 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7225 return v;
7226 }
7227
7228 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7229
7230 static inline void set_bit(int nr, void *addr)
7231 {
7232 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7233 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7234 }
7235
7236 #endif /* BOOT_BITOPS_H */
7237 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7238 index c7093bd..d4247ffe0 100644
7239 --- a/arch/x86/boot/boot.h
7240 +++ b/arch/x86/boot/boot.h
7241 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7242 static inline u16 ds(void)
7243 {
7244 u16 seg;
7245 - asm("movw %%ds,%0" : "=rm" (seg));
7246 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7247 return seg;
7248 }
7249
7250 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7251 static inline int memcmp(const void *s1, const void *s2, size_t len)
7252 {
7253 u8 diff;
7254 - asm("repe; cmpsb; setnz %0"
7255 + asm volatile("repe; cmpsb; setnz %0"
7256 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7257 return diff;
7258 }
7259 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7260 index 09664ef..edc5d03 100644
7261 --- a/arch/x86/boot/compressed/Makefile
7262 +++ b/arch/x86/boot/compressed/Makefile
7263 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7264 KBUILD_CFLAGS += $(cflags-y)
7265 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7266 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7267 +ifdef CONSTIFY_PLUGIN
7268 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7269 +endif
7270
7271 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7272 GCOV_PROFILE := n
7273 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7274 index 67a655a..b924059 100644
7275 --- a/arch/x86/boot/compressed/head_32.S
7276 +++ b/arch/x86/boot/compressed/head_32.S
7277 @@ -76,7 +76,7 @@ ENTRY(startup_32)
7278 notl %eax
7279 andl %eax, %ebx
7280 #else
7281 - movl $LOAD_PHYSICAL_ADDR, %ebx
7282 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7283 #endif
7284
7285 /* Target address to relocate to for decompression */
7286 @@ -162,7 +162,7 @@ relocated:
7287 * and where it was actually loaded.
7288 */
7289 movl %ebp, %ebx
7290 - subl $LOAD_PHYSICAL_ADDR, %ebx
7291 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7292 jz 2f /* Nothing to be done if loaded at compiled addr. */
7293 /*
7294 * Process relocations.
7295 @@ -170,8 +170,7 @@ relocated:
7296
7297 1: subl $4, %edi
7298 movl (%edi), %ecx
7299 - testl %ecx, %ecx
7300 - jz 2f
7301 + jecxz 2f
7302 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7303 jmp 1b
7304 2:
7305 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7306 index 35af09d..99c9676 100644
7307 --- a/arch/x86/boot/compressed/head_64.S
7308 +++ b/arch/x86/boot/compressed/head_64.S
7309 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7310 notl %eax
7311 andl %eax, %ebx
7312 #else
7313 - movl $LOAD_PHYSICAL_ADDR, %ebx
7314 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7315 #endif
7316
7317 /* Target address to relocate to for decompression */
7318 @@ -233,7 +233,7 @@ ENTRY(startup_64)
7319 notq %rax
7320 andq %rax, %rbp
7321 #else
7322 - movq $LOAD_PHYSICAL_ADDR, %rbp
7323 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7324 #endif
7325
7326 /* Target address to relocate to for decompression */
7327 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7328 index 3a19d04..7c1d55a 100644
7329 --- a/arch/x86/boot/compressed/misc.c
7330 +++ b/arch/x86/boot/compressed/misc.c
7331 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7332 case PT_LOAD:
7333 #ifdef CONFIG_RELOCATABLE
7334 dest = output;
7335 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7336 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7337 #else
7338 dest = (void *)(phdr->p_paddr);
7339 #endif
7340 @@ -363,7 +363,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7341 error("Destination address too large");
7342 #endif
7343 #ifndef CONFIG_RELOCATABLE
7344 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7345 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7346 error("Wrong destination address");
7347 #endif
7348
7349 diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
7350 index 89bbf4e..869908e 100644
7351 --- a/arch/x86/boot/compressed/relocs.c
7352 +++ b/arch/x86/boot/compressed/relocs.c
7353 @@ -13,8 +13,11 @@
7354
7355 static void die(char *fmt, ...);
7356
7357 +#include "../../../../include/generated/autoconf.h"
7358 +
7359 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
7360 static Elf32_Ehdr ehdr;
7361 +static Elf32_Phdr *phdr;
7362 static unsigned long reloc_count, reloc_idx;
7363 static unsigned long *relocs;
7364
7365 @@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
7366 }
7367 }
7368
7369 +static void read_phdrs(FILE *fp)
7370 +{
7371 + unsigned int i;
7372 +
7373 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
7374 + if (!phdr) {
7375 + die("Unable to allocate %d program headers\n",
7376 + ehdr.e_phnum);
7377 + }
7378 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
7379 + die("Seek to %d failed: %s\n",
7380 + ehdr.e_phoff, strerror(errno));
7381 + }
7382 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
7383 + die("Cannot read ELF program headers: %s\n",
7384 + strerror(errno));
7385 + }
7386 + for(i = 0; i < ehdr.e_phnum; i++) {
7387 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
7388 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
7389 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
7390 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
7391 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
7392 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
7393 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
7394 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
7395 + }
7396 +
7397 +}
7398 +
7399 static void read_shdrs(FILE *fp)
7400 {
7401 - int i;
7402 + unsigned int i;
7403 Elf32_Shdr shdr;
7404
7405 secs = calloc(ehdr.e_shnum, sizeof(struct section));
7406 @@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
7407
7408 static void read_strtabs(FILE *fp)
7409 {
7410 - int i;
7411 + unsigned int i;
7412 for (i = 0; i < ehdr.e_shnum; i++) {
7413 struct section *sec = &secs[i];
7414 if (sec->shdr.sh_type != SHT_STRTAB) {
7415 @@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
7416
7417 static void read_symtabs(FILE *fp)
7418 {
7419 - int i,j;
7420 + unsigned int i,j;
7421 for (i = 0; i < ehdr.e_shnum; i++) {
7422 struct section *sec = &secs[i];
7423 if (sec->shdr.sh_type != SHT_SYMTAB) {
7424 @@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
7425
7426 static void read_relocs(FILE *fp)
7427 {
7428 - int i,j;
7429 + unsigned int i,j;
7430 + uint32_t base;
7431 +
7432 for (i = 0; i < ehdr.e_shnum; i++) {
7433 struct section *sec = &secs[i];
7434 if (sec->shdr.sh_type != SHT_REL) {
7435 @@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
7436 die("Cannot read symbol table: %s\n",
7437 strerror(errno));
7438 }
7439 + base = 0;
7440 + for (j = 0; j < ehdr.e_phnum; j++) {
7441 + if (phdr[j].p_type != PT_LOAD )
7442 + continue;
7443 + 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)
7444 + continue;
7445 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
7446 + break;
7447 + }
7448 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
7449 Elf32_Rel *rel = &sec->reltab[j];
7450 - rel->r_offset = elf32_to_cpu(rel->r_offset);
7451 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
7452 rel->r_info = elf32_to_cpu(rel->r_info);
7453 }
7454 }
7455 @@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
7456
7457 static void print_absolute_symbols(void)
7458 {
7459 - int i;
7460 + unsigned int i;
7461 printf("Absolute symbols\n");
7462 printf(" Num: Value Size Type Bind Visibility Name\n");
7463 for (i = 0; i < ehdr.e_shnum; i++) {
7464 struct section *sec = &secs[i];
7465 char *sym_strtab;
7466 Elf32_Sym *sh_symtab;
7467 - int j;
7468 + unsigned int j;
7469
7470 if (sec->shdr.sh_type != SHT_SYMTAB) {
7471 continue;
7472 @@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
7473
7474 static void print_absolute_relocs(void)
7475 {
7476 - int i, printed = 0;
7477 + unsigned int i, printed = 0;
7478
7479 for (i = 0; i < ehdr.e_shnum; i++) {
7480 struct section *sec = &secs[i];
7481 struct section *sec_applies, *sec_symtab;
7482 char *sym_strtab;
7483 Elf32_Sym *sh_symtab;
7484 - int j;
7485 + unsigned int j;
7486 if (sec->shdr.sh_type != SHT_REL) {
7487 continue;
7488 }
7489 @@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
7490
7491 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7492 {
7493 - int i;
7494 + unsigned int i;
7495 /* Walk through the relocations */
7496 for (i = 0; i < ehdr.e_shnum; i++) {
7497 char *sym_strtab;
7498 Elf32_Sym *sh_symtab;
7499 struct section *sec_applies, *sec_symtab;
7500 - int j;
7501 + unsigned int j;
7502 struct section *sec = &secs[i];
7503
7504 if (sec->shdr.sh_type != SHT_REL) {
7505 @@ -530,6 +574,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7506 !is_rel_reloc(sym_name(sym_strtab, sym))) {
7507 continue;
7508 }
7509 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
7510 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
7511 + continue;
7512 +
7513 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
7514 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
7515 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
7516 + continue;
7517 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
7518 + continue;
7519 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
7520 + continue;
7521 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
7522 + continue;
7523 +#endif
7524 +
7525 switch (r_type) {
7526 case R_386_NONE:
7527 case R_386_PC32:
7528 @@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, const void *vb)
7529
7530 static void emit_relocs(int as_text)
7531 {
7532 - int i;
7533 + unsigned int i;
7534 /* Count how many relocations I have and allocate space for them. */
7535 reloc_count = 0;
7536 walk_relocs(count_reloc);
7537 @@ -665,6 +725,7 @@ int main(int argc, char **argv)
7538 fname, strerror(errno));
7539 }
7540 read_ehdr(fp);
7541 + read_phdrs(fp);
7542 read_shdrs(fp);
7543 read_strtabs(fp);
7544 read_symtabs(fp);
7545 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7546 index 4d3ff03..e4972ff 100644
7547 --- a/arch/x86/boot/cpucheck.c
7548 +++ b/arch/x86/boot/cpucheck.c
7549 @@ -74,7 +74,7 @@ static int has_fpu(void)
7550 u16 fcw = -1, fsw = -1;
7551 u32 cr0;
7552
7553 - asm("movl %%cr0,%0" : "=r" (cr0));
7554 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7555 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7556 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7557 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7558 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7559 {
7560 u32 f0, f1;
7561
7562 - asm("pushfl ; "
7563 + asm volatile("pushfl ; "
7564 "pushfl ; "
7565 "popl %0 ; "
7566 "movl %0,%1 ; "
7567 @@ -115,7 +115,7 @@ static void get_flags(void)
7568 set_bit(X86_FEATURE_FPU, cpu.flags);
7569
7570 if (has_eflag(X86_EFLAGS_ID)) {
7571 - asm("cpuid"
7572 + asm volatile("cpuid"
7573 : "=a" (max_intel_level),
7574 "=b" (cpu_vendor[0]),
7575 "=d" (cpu_vendor[1]),
7576 @@ -124,7 +124,7 @@ static void get_flags(void)
7577
7578 if (max_intel_level >= 0x00000001 &&
7579 max_intel_level <= 0x0000ffff) {
7580 - asm("cpuid"
7581 + asm volatile("cpuid"
7582 : "=a" (tfms),
7583 "=c" (cpu.flags[4]),
7584 "=d" (cpu.flags[0])
7585 @@ -136,7 +136,7 @@ static void get_flags(void)
7586 cpu.model += ((tfms >> 16) & 0xf) << 4;
7587 }
7588
7589 - asm("cpuid"
7590 + asm volatile("cpuid"
7591 : "=a" (max_amd_level)
7592 : "a" (0x80000000)
7593 : "ebx", "ecx", "edx");
7594 @@ -144,7 +144,7 @@ static void get_flags(void)
7595 if (max_amd_level >= 0x80000001 &&
7596 max_amd_level <= 0x8000ffff) {
7597 u32 eax = 0x80000001;
7598 - asm("cpuid"
7599 + asm volatile("cpuid"
7600 : "+a" (eax),
7601 "=c" (cpu.flags[6]),
7602 "=d" (cpu.flags[1])
7603 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7604 u32 ecx = MSR_K7_HWCR;
7605 u32 eax, edx;
7606
7607 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7608 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7609 eax &= ~(1 << 15);
7610 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7611 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7612
7613 get_flags(); /* Make sure it really did something */
7614 err = check_flags();
7615 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7616 u32 ecx = MSR_VIA_FCR;
7617 u32 eax, edx;
7618
7619 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7620 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7621 eax |= (1<<1)|(1<<7);
7622 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7623 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7624
7625 set_bit(X86_FEATURE_CX8, cpu.flags);
7626 err = check_flags();
7627 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7628 u32 eax, edx;
7629 u32 level = 1;
7630
7631 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7632 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7633 - asm("cpuid"
7634 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7635 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7636 + asm volatile("cpuid"
7637 : "+a" (level), "=d" (cpu.flags[0])
7638 : : "ecx", "ebx");
7639 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7640 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7641
7642 err = check_flags();
7643 }
7644 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7645 index bdb4d45..0476680 100644
7646 --- a/arch/x86/boot/header.S
7647 +++ b/arch/x86/boot/header.S
7648 @@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
7649 # single linked list of
7650 # struct setup_data
7651
7652 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7653 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7654
7655 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7656 #define VO_INIT_SIZE (VO__end - VO__text)
7657 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7658 index db75d07..8e6d0af 100644
7659 --- a/arch/x86/boot/memory.c
7660 +++ b/arch/x86/boot/memory.c
7661 @@ -19,7 +19,7 @@
7662
7663 static int detect_memory_e820(void)
7664 {
7665 - int count = 0;
7666 + unsigned int count = 0;
7667 struct biosregs ireg, oreg;
7668 struct e820entry *desc = boot_params.e820_map;
7669 static struct e820entry buf; /* static so it is zeroed */
7670 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
7671 index 11e8c6e..fdbb1ed 100644
7672 --- a/arch/x86/boot/video-vesa.c
7673 +++ b/arch/x86/boot/video-vesa.c
7674 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7675
7676 boot_params.screen_info.vesapm_seg = oreg.es;
7677 boot_params.screen_info.vesapm_off = oreg.di;
7678 + boot_params.screen_info.vesapm_size = oreg.cx;
7679 }
7680
7681 /*
7682 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
7683 index 43eda28..5ab5fdb 100644
7684 --- a/arch/x86/boot/video.c
7685 +++ b/arch/x86/boot/video.c
7686 @@ -96,7 +96,7 @@ static void store_mode_params(void)
7687 static unsigned int get_entry(void)
7688 {
7689 char entry_buf[4];
7690 - int i, len = 0;
7691 + unsigned int i, len = 0;
7692 int key;
7693 unsigned int v;
7694
7695 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
7696 index 5b577d5..3c1fed4 100644
7697 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
7698 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
7699 @@ -8,6 +8,8 @@
7700 * including this sentence is retained in full.
7701 */
7702
7703 +#include <asm/alternative-asm.h>
7704 +
7705 .extern crypto_ft_tab
7706 .extern crypto_it_tab
7707 .extern crypto_fl_tab
7708 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
7709 je B192; \
7710 leaq 32(r9),r9;
7711
7712 +#define ret pax_force_retaddr 0, 1; ret
7713 +
7714 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
7715 movq r1,r2; \
7716 movq r3,r4; \
7717 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
7718 index be6d9e3..21fbbca 100644
7719 --- a/arch/x86/crypto/aesni-intel_asm.S
7720 +++ b/arch/x86/crypto/aesni-intel_asm.S
7721 @@ -31,6 +31,7 @@
7722
7723 #include <linux/linkage.h>
7724 #include <asm/inst.h>
7725 +#include <asm/alternative-asm.h>
7726
7727 #ifdef __x86_64__
7728 .data
7729 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
7730 pop %r14
7731 pop %r13
7732 pop %r12
7733 + pax_force_retaddr 0, 1
7734 ret
7735 +ENDPROC(aesni_gcm_dec)
7736
7737
7738 /*****************************************************************************
7739 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
7740 pop %r14
7741 pop %r13
7742 pop %r12
7743 + pax_force_retaddr 0, 1
7744 ret
7745 +ENDPROC(aesni_gcm_enc)
7746
7747 #endif
7748
7749 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
7750 pxor %xmm1, %xmm0
7751 movaps %xmm0, (TKEYP)
7752 add $0x10, TKEYP
7753 + pax_force_retaddr_bts
7754 ret
7755
7756 .align 4
7757 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
7758 shufps $0b01001110, %xmm2, %xmm1
7759 movaps %xmm1, 0x10(TKEYP)
7760 add $0x20, TKEYP
7761 + pax_force_retaddr_bts
7762 ret
7763
7764 .align 4
7765 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
7766
7767 movaps %xmm0, (TKEYP)
7768 add $0x10, TKEYP
7769 + pax_force_retaddr_bts
7770 ret
7771
7772 .align 4
7773 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
7774 pxor %xmm1, %xmm2
7775 movaps %xmm2, (TKEYP)
7776 add $0x10, TKEYP
7777 + pax_force_retaddr_bts
7778 ret
7779
7780 /*
7781 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
7782 #ifndef __x86_64__
7783 popl KEYP
7784 #endif
7785 + pax_force_retaddr 0, 1
7786 ret
7787 +ENDPROC(aesni_set_key)
7788
7789 /*
7790 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
7791 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
7792 popl KLEN
7793 popl KEYP
7794 #endif
7795 + pax_force_retaddr 0, 1
7796 ret
7797 +ENDPROC(aesni_enc)
7798
7799 /*
7800 * _aesni_enc1: internal ABI
7801 @@ -1959,6 +1972,7 @@ _aesni_enc1:
7802 AESENC KEY STATE
7803 movaps 0x70(TKEYP), KEY
7804 AESENCLAST KEY STATE
7805 + pax_force_retaddr_bts
7806 ret
7807
7808 /*
7809 @@ -2067,6 +2081,7 @@ _aesni_enc4:
7810 AESENCLAST KEY STATE2
7811 AESENCLAST KEY STATE3
7812 AESENCLAST KEY STATE4
7813 + pax_force_retaddr_bts
7814 ret
7815
7816 /*
7817 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
7818 popl KLEN
7819 popl KEYP
7820 #endif
7821 + pax_force_retaddr 0, 1
7822 ret
7823 +ENDPROC(aesni_dec)
7824
7825 /*
7826 * _aesni_dec1: internal ABI
7827 @@ -2146,6 +2163,7 @@ _aesni_dec1:
7828 AESDEC KEY STATE
7829 movaps 0x70(TKEYP), KEY
7830 AESDECLAST KEY STATE
7831 + pax_force_retaddr_bts
7832 ret
7833
7834 /*
7835 @@ -2254,6 +2272,7 @@ _aesni_dec4:
7836 AESDECLAST KEY STATE2
7837 AESDECLAST KEY STATE3
7838 AESDECLAST KEY STATE4
7839 + pax_force_retaddr_bts
7840 ret
7841
7842 /*
7843 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
7844 popl KEYP
7845 popl LEN
7846 #endif
7847 + pax_force_retaddr 0, 1
7848 ret
7849 +ENDPROC(aesni_ecb_enc)
7850
7851 /*
7852 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7853 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
7854 popl KEYP
7855 popl LEN
7856 #endif
7857 + pax_force_retaddr 0, 1
7858 ret
7859 +ENDPROC(aesni_ecb_dec)
7860
7861 /*
7862 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7863 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
7864 popl LEN
7865 popl IVP
7866 #endif
7867 + pax_force_retaddr 0, 1
7868 ret
7869 +ENDPROC(aesni_cbc_enc)
7870
7871 /*
7872 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7873 @@ -2498,7 +2523,9 @@ ENTRY(aesni_cbc_dec)
7874 popl LEN
7875 popl IVP
7876 #endif
7877 + pax_force_retaddr 0, 1
7878 ret
7879 +ENDPROC(aesni_cbc_dec)
7880
7881 #ifdef __x86_64__
7882 .align 16
7883 @@ -2524,6 +2551,7 @@ _aesni_inc_init:
7884 mov $1, TCTR_LOW
7885 MOVQ_R64_XMM TCTR_LOW INC
7886 MOVQ_R64_XMM CTR TCTR_LOW
7887 + pax_force_retaddr_bts
7888 ret
7889
7890 /*
7891 @@ -2552,6 +2580,7 @@ _aesni_inc:
7892 .Linc_low:
7893 movaps CTR, IV
7894 PSHUFB_XMM BSWAP_MASK IV
7895 + pax_force_retaddr_bts
7896 ret
7897
7898 /*
7899 @@ -2612,5 +2641,7 @@ ENTRY(aesni_ctr_enc)
7900 .Lctr_enc_ret:
7901 movups IV, (IVP)
7902 .Lctr_enc_just_ret:
7903 + pax_force_retaddr 0, 1
7904 ret
7905 +ENDPROC(aesni_ctr_enc)
7906 #endif
7907 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
7908 index 391d245..67f35c2 100644
7909 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
7910 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
7911 @@ -20,6 +20,8 @@
7912 *
7913 */
7914
7915 +#include <asm/alternative-asm.h>
7916 +
7917 .file "blowfish-x86_64-asm.S"
7918 .text
7919
7920 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
7921 jnz __enc_xor;
7922
7923 write_block();
7924 + pax_force_retaddr 0, 1
7925 ret;
7926 __enc_xor:
7927 xor_block();
7928 + pax_force_retaddr 0, 1
7929 ret;
7930
7931 .align 8
7932 @@ -188,6 +192,7 @@ blowfish_dec_blk:
7933
7934 movq %r11, %rbp;
7935
7936 + pax_force_retaddr 0, 1
7937 ret;
7938
7939 /**********************************************************************
7940 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
7941
7942 popq %rbx;
7943 popq %rbp;
7944 + pax_force_retaddr 0, 1
7945 ret;
7946
7947 __enc_xor4:
7948 @@ -349,6 +355,7 @@ __enc_xor4:
7949
7950 popq %rbx;
7951 popq %rbp;
7952 + pax_force_retaddr 0, 1
7953 ret;
7954
7955 .align 8
7956 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
7957 popq %rbx;
7958 popq %rbp;
7959
7960 + pax_force_retaddr 0, 1
7961 ret;
7962
7963 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
7964 index 6214a9b..1f4fc9a 100644
7965 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
7966 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
7967 @@ -1,3 +1,5 @@
7968 +#include <asm/alternative-asm.h>
7969 +
7970 # enter ECRYPT_encrypt_bytes
7971 .text
7972 .p2align 5
7973 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
7974 add %r11,%rsp
7975 mov %rdi,%rax
7976 mov %rsi,%rdx
7977 + pax_force_retaddr 0, 1
7978 ret
7979 # bytesatleast65:
7980 ._bytesatleast65:
7981 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
7982 add %r11,%rsp
7983 mov %rdi,%rax
7984 mov %rsi,%rdx
7985 + pax_force_retaddr
7986 ret
7987 # enter ECRYPT_ivsetup
7988 .text
7989 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
7990 add %r11,%rsp
7991 mov %rdi,%rax
7992 mov %rsi,%rdx
7993 + pax_force_retaddr
7994 ret
7995 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
7996 index b2c2f57..8470cab 100644
7997 --- a/arch/x86/crypto/sha1_ssse3_asm.S
7998 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
7999 @@ -28,6 +28,8 @@
8000 * (at your option) any later version.
8001 */
8002
8003 +#include <asm/alternative-asm.h>
8004 +
8005 #define CTX %rdi // arg1
8006 #define BUF %rsi // arg2
8007 #define CNT %rdx // arg3
8008 @@ -104,6 +106,7 @@
8009 pop %r12
8010 pop %rbp
8011 pop %rbx
8012 + pax_force_retaddr 0, 1
8013 ret
8014
8015 .size \name, .-\name
8016 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8017 index 5b012a2..36d5364 100644
8018 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8019 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8020 @@ -20,6 +20,8 @@
8021 *
8022 */
8023
8024 +#include <asm/alternative-asm.h>
8025 +
8026 .file "twofish-x86_64-asm-3way.S"
8027 .text
8028
8029 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8030 popq %r13;
8031 popq %r14;
8032 popq %r15;
8033 + pax_force_retaddr 0, 1
8034 ret;
8035
8036 __enc_xor3:
8037 @@ -271,6 +274,7 @@ __enc_xor3:
8038 popq %r13;
8039 popq %r14;
8040 popq %r15;
8041 + pax_force_retaddr 0, 1
8042 ret;
8043
8044 .global twofish_dec_blk_3way
8045 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8046 popq %r13;
8047 popq %r14;
8048 popq %r15;
8049 + pax_force_retaddr 0, 1
8050 ret;
8051
8052 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8053 index 7bcf3fc..f53832f 100644
8054 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8055 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8056 @@ -21,6 +21,7 @@
8057 .text
8058
8059 #include <asm/asm-offsets.h>
8060 +#include <asm/alternative-asm.h>
8061
8062 #define a_offset 0
8063 #define b_offset 4
8064 @@ -268,6 +269,7 @@ twofish_enc_blk:
8065
8066 popq R1
8067 movq $1,%rax
8068 + pax_force_retaddr 0, 1
8069 ret
8070
8071 twofish_dec_blk:
8072 @@ -319,4 +321,5 @@ twofish_dec_blk:
8073
8074 popq R1
8075 movq $1,%rax
8076 + pax_force_retaddr 0, 1
8077 ret
8078 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8079 index fd84387..887aa7e 100644
8080 --- a/arch/x86/ia32/ia32_aout.c
8081 +++ b/arch/x86/ia32/ia32_aout.c
8082 @@ -162,6 +162,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8083 unsigned long dump_start, dump_size;
8084 struct user32 dump;
8085
8086 + memset(&dump, 0, sizeof(dump));
8087 +
8088 fs = get_fs();
8089 set_fs(KERNEL_DS);
8090 has_dumped = 1;
8091 @@ -315,6 +317,13 @@ static int load_aout_binary(struct linux_binprm *bprm, struct pt_regs *regs)
8092 current->mm->free_area_cache = TASK_UNMAPPED_BASE;
8093 current->mm->cached_hole_size = 0;
8094
8095 + retval = setup_arg_pages(bprm, IA32_STACK_TOP, EXSTACK_DEFAULT);
8096 + if (retval < 0) {
8097 + /* Someone check-me: is this error path enough? */
8098 + send_sig(SIGKILL, current, 0);
8099 + return retval;
8100 + }
8101 +
8102 install_exec_creds(bprm);
8103 current->flags &= ~PF_FORKNOEXEC;
8104
8105 @@ -410,13 +419,6 @@ beyond_if:
8106
8107 set_brk(current->mm->start_brk, current->mm->brk);
8108
8109 - retval = setup_arg_pages(bprm, IA32_STACK_TOP, EXSTACK_DEFAULT);
8110 - if (retval < 0) {
8111 - /* Someone check-me: is this error path enough? */
8112 - send_sig(SIGKILL, current, 0);
8113 - return retval;
8114 - }
8115 -
8116 current->mm->start_stack =
8117 (unsigned long)create_aout_tables((char __user *)bprm->p, bprm);
8118 /* start thread */
8119 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8120 index 6557769..ef6ae89 100644
8121 --- a/arch/x86/ia32/ia32_signal.c
8122 +++ b/arch/x86/ia32/ia32_signal.c
8123 @@ -169,7 +169,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8124 }
8125 seg = get_fs();
8126 set_fs(KERNEL_DS);
8127 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8128 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8129 set_fs(seg);
8130 if (ret >= 0 && uoss_ptr) {
8131 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8132 @@ -370,7 +370,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8133 */
8134 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8135 size_t frame_size,
8136 - void **fpstate)
8137 + void __user **fpstate)
8138 {
8139 unsigned long sp;
8140
8141 @@ -391,7 +391,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8142
8143 if (used_math()) {
8144 sp = sp - sig_xstate_ia32_size;
8145 - *fpstate = (struct _fpstate_ia32 *) sp;
8146 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8147 if (save_i387_xstate_ia32(*fpstate) < 0)
8148 return (void __user *) -1L;
8149 }
8150 @@ -399,7 +399,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8151 sp -= frame_size;
8152 /* Align the stack pointer according to the i386 ABI,
8153 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8154 - sp = ((sp + 4) & -16ul) - 4;
8155 + sp = ((sp - 12) & -16ul) - 4;
8156 return (void __user *) sp;
8157 }
8158
8159 @@ -457,7 +457,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8160 * These are actually not used anymore, but left because some
8161 * gdb versions depend on them as a marker.
8162 */
8163 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8164 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8165 } put_user_catch(err);
8166
8167 if (err)
8168 @@ -499,7 +499,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8169 0xb8,
8170 __NR_ia32_rt_sigreturn,
8171 0x80cd,
8172 - 0,
8173 + 0
8174 };
8175
8176 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8177 @@ -529,16 +529,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8178
8179 if (ka->sa.sa_flags & SA_RESTORER)
8180 restorer = ka->sa.sa_restorer;
8181 + else if (current->mm->context.vdso)
8182 + /* Return stub is in 32bit vsyscall page */
8183 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8184 else
8185 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8186 - rt_sigreturn);
8187 + restorer = &frame->retcode;
8188 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8189
8190 /*
8191 * Not actually used anymore, but left because some gdb
8192 * versions need it.
8193 */
8194 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8195 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8196 } put_user_catch(err);
8197
8198 if (err)
8199 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8200 index a6253ec..4ad2120 100644
8201 --- a/arch/x86/ia32/ia32entry.S
8202 +++ b/arch/x86/ia32/ia32entry.S
8203 @@ -13,7 +13,9 @@
8204 #include <asm/thread_info.h>
8205 #include <asm/segment.h>
8206 #include <asm/irqflags.h>
8207 +#include <asm/pgtable.h>
8208 #include <linux/linkage.h>
8209 +#include <asm/alternative-asm.h>
8210
8211 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8212 #include <linux/elf-em.h>
8213 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8214 ENDPROC(native_irq_enable_sysexit)
8215 #endif
8216
8217 + .macro pax_enter_kernel_user
8218 + pax_set_fptr_mask
8219 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8220 + call pax_enter_kernel_user
8221 +#endif
8222 + .endm
8223 +
8224 + .macro pax_exit_kernel_user
8225 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8226 + call pax_exit_kernel_user
8227 +#endif
8228 +#ifdef CONFIG_PAX_RANDKSTACK
8229 + pushq %rax
8230 + pushq %r11
8231 + call pax_randomize_kstack
8232 + popq %r11
8233 + popq %rax
8234 +#endif
8235 + .endm
8236 +
8237 +.macro pax_erase_kstack
8238 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8239 + call pax_erase_kstack
8240 +#endif
8241 +.endm
8242 +
8243 /*
8244 * 32bit SYSENTER instruction entry.
8245 *
8246 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8247 CFI_REGISTER rsp,rbp
8248 SWAPGS_UNSAFE_STACK
8249 movq PER_CPU_VAR(kernel_stack), %rsp
8250 - addq $(KERNEL_STACK_OFFSET),%rsp
8251 - /*
8252 - * No need to follow this irqs on/off section: the syscall
8253 - * disabled irqs, here we enable it straight after entry:
8254 - */
8255 - ENABLE_INTERRUPTS(CLBR_NONE)
8256 movl %ebp,%ebp /* zero extension */
8257 pushq_cfi $__USER32_DS
8258 /*CFI_REL_OFFSET ss,0*/
8259 @@ -134,25 +156,39 @@ ENTRY(ia32_sysenter_target)
8260 CFI_REL_OFFSET rsp,0
8261 pushfq_cfi
8262 /*CFI_REL_OFFSET rflags,0*/
8263 - movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
8264 - CFI_REGISTER rip,r10
8265 + orl $X86_EFLAGS_IF,(%rsp)
8266 + GET_THREAD_INFO(%r11)
8267 + movl TI_sysenter_return(%r11), %r11d
8268 + CFI_REGISTER rip,r11
8269 pushq_cfi $__USER32_CS
8270 /*CFI_REL_OFFSET cs,0*/
8271 movl %eax, %eax
8272 - pushq_cfi %r10
8273 + pushq_cfi %r11
8274 CFI_REL_OFFSET rip,0
8275 pushq_cfi %rax
8276 cld
8277 SAVE_ARGS 0,1,0
8278 + pax_enter_kernel_user
8279 + /*
8280 + * No need to follow this irqs on/off section: the syscall
8281 + * disabled irqs, here we enable it straight after entry:
8282 + */
8283 + ENABLE_INTERRUPTS(CLBR_NONE)
8284 /* no need to do an access_ok check here because rbp has been
8285 32bit zero extended */
8286 +
8287 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8288 + mov $PAX_USER_SHADOW_BASE,%r11
8289 + add %r11,%rbp
8290 +#endif
8291 +
8292 1: movl (%rbp),%ebp
8293 .section __ex_table,"a"
8294 .quad 1b,ia32_badarg
8295 .previous
8296 - GET_THREAD_INFO(%r10)
8297 - orl $TS_COMPAT,TI_status(%r10)
8298 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
8299 + GET_THREAD_INFO(%r11)
8300 + orl $TS_COMPAT,TI_status(%r11)
8301 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8302 CFI_REMEMBER_STATE
8303 jnz sysenter_tracesys
8304 cmpq $(IA32_NR_syscalls-1),%rax
8305 @@ -162,13 +198,15 @@ sysenter_do_call:
8306 sysenter_dispatch:
8307 call *ia32_sys_call_table(,%rax,8)
8308 movq %rax,RAX-ARGOFFSET(%rsp)
8309 - GET_THREAD_INFO(%r10)
8310 + GET_THREAD_INFO(%r11)
8311 DISABLE_INTERRUPTS(CLBR_NONE)
8312 TRACE_IRQS_OFF
8313 - testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
8314 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8315 jnz sysexit_audit
8316 sysexit_from_sys_call:
8317 - andl $~TS_COMPAT,TI_status(%r10)
8318 + pax_exit_kernel_user
8319 + pax_erase_kstack
8320 + andl $~TS_COMPAT,TI_status(%r11)
8321 /* clear IF, that popfq doesn't enable interrupts early */
8322 andl $~0x200,EFLAGS-R11(%rsp)
8323 movl RIP-R11(%rsp),%edx /* User %eip */
8324 @@ -194,6 +232,9 @@ sysexit_from_sys_call:
8325 movl %eax,%esi /* 2nd arg: syscall number */
8326 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8327 call audit_syscall_entry
8328 +
8329 + pax_erase_kstack
8330 +
8331 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8332 cmpq $(IA32_NR_syscalls-1),%rax
8333 ja ia32_badsys
8334 @@ -205,7 +246,7 @@ sysexit_from_sys_call:
8335 .endm
8336
8337 .macro auditsys_exit exit
8338 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
8339 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8340 jnz ia32_ret_from_sys_call
8341 TRACE_IRQS_ON
8342 sti
8343 @@ -215,12 +256,12 @@ sysexit_from_sys_call:
8344 movzbl %al,%edi /* zero-extend that into %edi */
8345 inc %edi /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
8346 call audit_syscall_exit
8347 - GET_THREAD_INFO(%r10)
8348 + GET_THREAD_INFO(%r11)
8349 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall return value */
8350 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8351 cli
8352 TRACE_IRQS_OFF
8353 - testl %edi,TI_flags(%r10)
8354 + testl %edi,TI_flags(%r11)
8355 jz \exit
8356 CLEAR_RREGS -ARGOFFSET
8357 jmp int_with_check
8358 @@ -238,7 +279,7 @@ sysexit_audit:
8359
8360 sysenter_tracesys:
8361 #ifdef CONFIG_AUDITSYSCALL
8362 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
8363 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8364 jz sysenter_auditsys
8365 #endif
8366 SAVE_REST
8367 @@ -246,6 +287,9 @@ sysenter_tracesys:
8368 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8369 movq %rsp,%rdi /* &pt_regs -> arg1 */
8370 call syscall_trace_enter
8371 +
8372 + pax_erase_kstack
8373 +
8374 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8375 RESTORE_REST
8376 cmpq $(IA32_NR_syscalls-1),%rax
8377 @@ -277,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
8378 ENTRY(ia32_cstar_target)
8379 CFI_STARTPROC32 simple
8380 CFI_SIGNAL_FRAME
8381 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8382 + CFI_DEF_CFA rsp,0
8383 CFI_REGISTER rip,rcx
8384 /*CFI_REGISTER rflags,r11*/
8385 SWAPGS_UNSAFE_STACK
8386 movl %esp,%r8d
8387 CFI_REGISTER rsp,r8
8388 movq PER_CPU_VAR(kernel_stack),%rsp
8389 + SAVE_ARGS 8*6,0,0
8390 + pax_enter_kernel_user
8391 /*
8392 * No need to follow this irqs on/off section: the syscall
8393 * disabled irqs and here we enable it straight after entry:
8394 */
8395 ENABLE_INTERRUPTS(CLBR_NONE)
8396 - SAVE_ARGS 8,0,0
8397 movl %eax,%eax /* zero extension */
8398 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8399 movq %rcx,RIP-ARGOFFSET(%rsp)
8400 @@ -305,13 +350,19 @@ ENTRY(ia32_cstar_target)
8401 /* no need to do an access_ok check here because r8 has been
8402 32bit zero extended */
8403 /* hardware stack frame is complete now */
8404 +
8405 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8406 + mov $PAX_USER_SHADOW_BASE,%r11
8407 + add %r11,%r8
8408 +#endif
8409 +
8410 1: movl (%r8),%r9d
8411 .section __ex_table,"a"
8412 .quad 1b,ia32_badarg
8413 .previous
8414 - GET_THREAD_INFO(%r10)
8415 - orl $TS_COMPAT,TI_status(%r10)
8416 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
8417 + GET_THREAD_INFO(%r11)
8418 + orl $TS_COMPAT,TI_status(%r11)
8419 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8420 CFI_REMEMBER_STATE
8421 jnz cstar_tracesys
8422 cmpq $IA32_NR_syscalls-1,%rax
8423 @@ -321,13 +372,15 @@ cstar_do_call:
8424 cstar_dispatch:
8425 call *ia32_sys_call_table(,%rax,8)
8426 movq %rax,RAX-ARGOFFSET(%rsp)
8427 - GET_THREAD_INFO(%r10)
8428 + GET_THREAD_INFO(%r11)
8429 DISABLE_INTERRUPTS(CLBR_NONE)
8430 TRACE_IRQS_OFF
8431 - testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
8432 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8433 jnz sysretl_audit
8434 sysretl_from_sys_call:
8435 - andl $~TS_COMPAT,TI_status(%r10)
8436 + pax_exit_kernel_user
8437 + pax_erase_kstack
8438 + andl $~TS_COMPAT,TI_status(%r11)
8439 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8440 movl RIP-ARGOFFSET(%rsp),%ecx
8441 CFI_REGISTER rip,rcx
8442 @@ -355,7 +408,7 @@ sysretl_audit:
8443
8444 cstar_tracesys:
8445 #ifdef CONFIG_AUDITSYSCALL
8446 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
8447 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8448 jz cstar_auditsys
8449 #endif
8450 xchgl %r9d,%ebp
8451 @@ -364,6 +417,9 @@ cstar_tracesys:
8452 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8453 movq %rsp,%rdi /* &pt_regs -> arg1 */
8454 call syscall_trace_enter
8455 +
8456 + pax_erase_kstack
8457 +
8458 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8459 RESTORE_REST
8460 xchgl %ebp,%r9d
8461 @@ -409,20 +465,21 @@ ENTRY(ia32_syscall)
8462 CFI_REL_OFFSET rip,RIP-RIP
8463 PARAVIRT_ADJUST_EXCEPTION_FRAME
8464 SWAPGS
8465 - /*
8466 - * No need to follow this irqs on/off section: the syscall
8467 - * disabled irqs and here we enable it straight after entry:
8468 - */
8469 - ENABLE_INTERRUPTS(CLBR_NONE)
8470 movl %eax,%eax
8471 pushq_cfi %rax
8472 cld
8473 /* note the registers are not zero extended to the sf.
8474 this could be a problem. */
8475 SAVE_ARGS 0,1,0
8476 - GET_THREAD_INFO(%r10)
8477 - orl $TS_COMPAT,TI_status(%r10)
8478 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
8479 + pax_enter_kernel_user
8480 + /*
8481 + * No need to follow this irqs on/off section: the syscall
8482 + * disabled irqs and here we enable it straight after entry:
8483 + */
8484 + ENABLE_INTERRUPTS(CLBR_NONE)
8485 + GET_THREAD_INFO(%r11)
8486 + orl $TS_COMPAT,TI_status(%r11)
8487 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8488 jnz ia32_tracesys
8489 cmpq $(IA32_NR_syscalls-1),%rax
8490 ja ia32_badsys
8491 @@ -441,6 +498,9 @@ ia32_tracesys:
8492 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8493 movq %rsp,%rdi /* &pt_regs -> arg1 */
8494 call syscall_trace_enter
8495 +
8496 + pax_erase_kstack
8497 +
8498 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8499 RESTORE_REST
8500 cmpq $(IA32_NR_syscalls-1),%rax
8501 @@ -455,6 +515,7 @@ ia32_badsys:
8502
8503 quiet_ni_syscall:
8504 movq $-ENOSYS,%rax
8505 + pax_force_retaddr
8506 ret
8507 CFI_ENDPROC
8508
8509 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8510 index f6f5c53..b358b28 100644
8511 --- a/arch/x86/ia32/sys_ia32.c
8512 +++ b/arch/x86/ia32/sys_ia32.c
8513 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8514 */
8515 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8516 {
8517 - typeof(ubuf->st_uid) uid = 0;
8518 - typeof(ubuf->st_gid) gid = 0;
8519 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8520 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8521 SET_UID(uid, stat->uid);
8522 SET_GID(gid, stat->gid);
8523 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8524 @@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
8525 }
8526 set_fs(KERNEL_DS);
8527 ret = sys_rt_sigprocmask(how,
8528 - set ? (sigset_t __user *)&s : NULL,
8529 - oset ? (sigset_t __user *)&s : NULL,
8530 + set ? (sigset_t __force_user *)&s : NULL,
8531 + oset ? (sigset_t __force_user *)&s : NULL,
8532 sigsetsize);
8533 set_fs(old_fs);
8534 if (ret)
8535 @@ -332,7 +332,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
8536 return alarm_setitimer(seconds);
8537 }
8538
8539 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8540 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8541 int options)
8542 {
8543 return compat_sys_wait4(pid, stat_addr, options, NULL);
8544 @@ -353,7 +353,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8545 mm_segment_t old_fs = get_fs();
8546
8547 set_fs(KERNEL_DS);
8548 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8549 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8550 set_fs(old_fs);
8551 if (put_compat_timespec(&t, interval))
8552 return -EFAULT;
8553 @@ -369,7 +369,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8554 mm_segment_t old_fs = get_fs();
8555
8556 set_fs(KERNEL_DS);
8557 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8558 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8559 set_fs(old_fs);
8560 if (!ret) {
8561 switch (_NSIG_WORDS) {
8562 @@ -394,7 +394,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8563 if (copy_siginfo_from_user32(&info, uinfo))
8564 return -EFAULT;
8565 set_fs(KERNEL_DS);
8566 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8567 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8568 set_fs(old_fs);
8569 return ret;
8570 }
8571 @@ -439,7 +439,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8572 return -EFAULT;
8573
8574 set_fs(KERNEL_DS);
8575 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
8576 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
8577 count);
8578 set_fs(old_fs);
8579
8580 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8581 index 091508b..7692c6f 100644
8582 --- a/arch/x86/include/asm/alternative-asm.h
8583 +++ b/arch/x86/include/asm/alternative-asm.h
8584 @@ -4,10 +4,10 @@
8585
8586 #ifdef CONFIG_SMP
8587 .macro LOCK_PREFIX
8588 -1: lock
8589 +672: lock
8590 .section .smp_locks,"a"
8591 .balign 4
8592 - .long 1b - .
8593 + .long 672b - .
8594 .previous
8595 .endm
8596 #else
8597 @@ -15,6 +15,45 @@
8598 .endm
8599 #endif
8600
8601 +#ifdef KERNEXEC_PLUGIN
8602 + .macro pax_force_retaddr_bts rip=0
8603 + btsq $63,\rip(%rsp)
8604 + .endm
8605 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
8606 + .macro pax_force_retaddr rip=0, reload=0
8607 + btsq $63,\rip(%rsp)
8608 + .endm
8609 + .macro pax_force_fptr ptr
8610 + btsq $63,\ptr
8611 + .endm
8612 + .macro pax_set_fptr_mask
8613 + .endm
8614 +#endif
8615 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
8616 + .macro pax_force_retaddr rip=0, reload=0
8617 + .if \reload
8618 + pax_set_fptr_mask
8619 + .endif
8620 + orq %r10,\rip(%rsp)
8621 + .endm
8622 + .macro pax_force_fptr ptr
8623 + orq %r10,\ptr
8624 + .endm
8625 + .macro pax_set_fptr_mask
8626 + movabs $0x8000000000000000,%r10
8627 + .endm
8628 +#endif
8629 +#else
8630 + .macro pax_force_retaddr rip=0, reload=0
8631 + .endm
8632 + .macro pax_force_fptr ptr
8633 + .endm
8634 + .macro pax_force_retaddr_bts rip=0
8635 + .endm
8636 + .macro pax_set_fptr_mask
8637 + .endm
8638 +#endif
8639 +
8640 .macro altinstruction_entry orig alt feature orig_len alt_len
8641 .long \orig - .
8642 .long \alt - .
8643 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
8644 index 37ad100..7d47faa 100644
8645 --- a/arch/x86/include/asm/alternative.h
8646 +++ b/arch/x86/include/asm/alternative.h
8647 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
8648 ".section .discard,\"aw\",@progbits\n" \
8649 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
8650 ".previous\n" \
8651 - ".section .altinstr_replacement, \"ax\"\n" \
8652 + ".section .altinstr_replacement, \"a\"\n" \
8653 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
8654 ".previous"
8655
8656 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
8657 index 1a6c09a..fec2432 100644
8658 --- a/arch/x86/include/asm/apic.h
8659 +++ b/arch/x86/include/asm/apic.h
8660 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
8661
8662 #ifdef CONFIG_X86_LOCAL_APIC
8663
8664 -extern unsigned int apic_verbosity;
8665 +extern int apic_verbosity;
8666 extern int local_apic_timer_c2_ok;
8667
8668 extern int disable_apic;
8669 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
8670 index 20370c6..a2eb9b0 100644
8671 --- a/arch/x86/include/asm/apm.h
8672 +++ b/arch/x86/include/asm/apm.h
8673 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
8674 __asm__ __volatile__(APM_DO_ZERO_SEGS
8675 "pushl %%edi\n\t"
8676 "pushl %%ebp\n\t"
8677 - "lcall *%%cs:apm_bios_entry\n\t"
8678 + "lcall *%%ss:apm_bios_entry\n\t"
8679 "setc %%al\n\t"
8680 "popl %%ebp\n\t"
8681 "popl %%edi\n\t"
8682 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
8683 __asm__ __volatile__(APM_DO_ZERO_SEGS
8684 "pushl %%edi\n\t"
8685 "pushl %%ebp\n\t"
8686 - "lcall *%%cs:apm_bios_entry\n\t"
8687 + "lcall *%%ss:apm_bios_entry\n\t"
8688 "setc %%bl\n\t"
8689 "popl %%ebp\n\t"
8690 "popl %%edi\n\t"
8691 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
8692 index 58cb6d4..ca9010d 100644
8693 --- a/arch/x86/include/asm/atomic.h
8694 +++ b/arch/x86/include/asm/atomic.h
8695 @@ -22,7 +22,18 @@
8696 */
8697 static inline int atomic_read(const atomic_t *v)
8698 {
8699 - return (*(volatile int *)&(v)->counter);
8700 + return (*(volatile const int *)&(v)->counter);
8701 +}
8702 +
8703 +/**
8704 + * atomic_read_unchecked - read atomic variable
8705 + * @v: pointer of type atomic_unchecked_t
8706 + *
8707 + * Atomically reads the value of @v.
8708 + */
8709 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8710 +{
8711 + return (*(volatile const int *)&(v)->counter);
8712 }
8713
8714 /**
8715 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
8716 }
8717
8718 /**
8719 + * atomic_set_unchecked - set atomic variable
8720 + * @v: pointer of type atomic_unchecked_t
8721 + * @i: required value
8722 + *
8723 + * Atomically sets the value of @v to @i.
8724 + */
8725 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8726 +{
8727 + v->counter = i;
8728 +}
8729 +
8730 +/**
8731 * atomic_add - add integer to atomic variable
8732 * @i: integer value to add
8733 * @v: pointer of type atomic_t
8734 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
8735 */
8736 static inline void atomic_add(int i, atomic_t *v)
8737 {
8738 - asm volatile(LOCK_PREFIX "addl %1,%0"
8739 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8740 +
8741 +#ifdef CONFIG_PAX_REFCOUNT
8742 + "jno 0f\n"
8743 + LOCK_PREFIX "subl %1,%0\n"
8744 + "int $4\n0:\n"
8745 + _ASM_EXTABLE(0b, 0b)
8746 +#endif
8747 +
8748 + : "+m" (v->counter)
8749 + : "ir" (i));
8750 +}
8751 +
8752 +/**
8753 + * atomic_add_unchecked - add integer to atomic variable
8754 + * @i: integer value to add
8755 + * @v: pointer of type atomic_unchecked_t
8756 + *
8757 + * Atomically adds @i to @v.
8758 + */
8759 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8760 +{
8761 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8762 : "+m" (v->counter)
8763 : "ir" (i));
8764 }
8765 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
8766 */
8767 static inline void atomic_sub(int i, atomic_t *v)
8768 {
8769 - asm volatile(LOCK_PREFIX "subl %1,%0"
8770 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8771 +
8772 +#ifdef CONFIG_PAX_REFCOUNT
8773 + "jno 0f\n"
8774 + LOCK_PREFIX "addl %1,%0\n"
8775 + "int $4\n0:\n"
8776 + _ASM_EXTABLE(0b, 0b)
8777 +#endif
8778 +
8779 + : "+m" (v->counter)
8780 + : "ir" (i));
8781 +}
8782 +
8783 +/**
8784 + * atomic_sub_unchecked - subtract integer from atomic variable
8785 + * @i: integer value to subtract
8786 + * @v: pointer of type atomic_unchecked_t
8787 + *
8788 + * Atomically subtracts @i from @v.
8789 + */
8790 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8791 +{
8792 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8793 : "+m" (v->counter)
8794 : "ir" (i));
8795 }
8796 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8797 {
8798 unsigned char c;
8799
8800 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8801 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
8802 +
8803 +#ifdef CONFIG_PAX_REFCOUNT
8804 + "jno 0f\n"
8805 + LOCK_PREFIX "addl %2,%0\n"
8806 + "int $4\n0:\n"
8807 + _ASM_EXTABLE(0b, 0b)
8808 +#endif
8809 +
8810 + "sete %1\n"
8811 : "+m" (v->counter), "=qm" (c)
8812 : "ir" (i) : "memory");
8813 return c;
8814 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8815 */
8816 static inline void atomic_inc(atomic_t *v)
8817 {
8818 - asm volatile(LOCK_PREFIX "incl %0"
8819 + asm volatile(LOCK_PREFIX "incl %0\n"
8820 +
8821 +#ifdef CONFIG_PAX_REFCOUNT
8822 + "jno 0f\n"
8823 + LOCK_PREFIX "decl %0\n"
8824 + "int $4\n0:\n"
8825 + _ASM_EXTABLE(0b, 0b)
8826 +#endif
8827 +
8828 + : "+m" (v->counter));
8829 +}
8830 +
8831 +/**
8832 + * atomic_inc_unchecked - increment atomic variable
8833 + * @v: pointer of type atomic_unchecked_t
8834 + *
8835 + * Atomically increments @v by 1.
8836 + */
8837 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8838 +{
8839 + asm volatile(LOCK_PREFIX "incl %0\n"
8840 : "+m" (v->counter));
8841 }
8842
8843 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
8844 */
8845 static inline void atomic_dec(atomic_t *v)
8846 {
8847 - asm volatile(LOCK_PREFIX "decl %0"
8848 + asm volatile(LOCK_PREFIX "decl %0\n"
8849 +
8850 +#ifdef CONFIG_PAX_REFCOUNT
8851 + "jno 0f\n"
8852 + LOCK_PREFIX "incl %0\n"
8853 + "int $4\n0:\n"
8854 + _ASM_EXTABLE(0b, 0b)
8855 +#endif
8856 +
8857 + : "+m" (v->counter));
8858 +}
8859 +
8860 +/**
8861 + * atomic_dec_unchecked - decrement atomic variable
8862 + * @v: pointer of type atomic_unchecked_t
8863 + *
8864 + * Atomically decrements @v by 1.
8865 + */
8866 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8867 +{
8868 + asm volatile(LOCK_PREFIX "decl %0\n"
8869 : "+m" (v->counter));
8870 }
8871
8872 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
8873 {
8874 unsigned char c;
8875
8876 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
8877 + asm volatile(LOCK_PREFIX "decl %0\n"
8878 +
8879 +#ifdef CONFIG_PAX_REFCOUNT
8880 + "jno 0f\n"
8881 + LOCK_PREFIX "incl %0\n"
8882 + "int $4\n0:\n"
8883 + _ASM_EXTABLE(0b, 0b)
8884 +#endif
8885 +
8886 + "sete %1\n"
8887 : "+m" (v->counter), "=qm" (c)
8888 : : "memory");
8889 return c != 0;
8890 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
8891 {
8892 unsigned char c;
8893
8894 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
8895 + asm volatile(LOCK_PREFIX "incl %0\n"
8896 +
8897 +#ifdef CONFIG_PAX_REFCOUNT
8898 + "jno 0f\n"
8899 + LOCK_PREFIX "decl %0\n"
8900 + "int $4\n0:\n"
8901 + _ASM_EXTABLE(0b, 0b)
8902 +#endif
8903 +
8904 + "sete %1\n"
8905 + : "+m" (v->counter), "=qm" (c)
8906 + : : "memory");
8907 + return c != 0;
8908 +}
8909 +
8910 +/**
8911 + * atomic_inc_and_test_unchecked - increment and test
8912 + * @v: pointer of type atomic_unchecked_t
8913 + *
8914 + * Atomically increments @v by 1
8915 + * and returns true if the result is zero, or false for all
8916 + * other cases.
8917 + */
8918 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8919 +{
8920 + unsigned char c;
8921 +
8922 + asm volatile(LOCK_PREFIX "incl %0\n"
8923 + "sete %1\n"
8924 : "+m" (v->counter), "=qm" (c)
8925 : : "memory");
8926 return c != 0;
8927 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
8928 {
8929 unsigned char c;
8930
8931 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
8932 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
8933 +
8934 +#ifdef CONFIG_PAX_REFCOUNT
8935 + "jno 0f\n"
8936 + LOCK_PREFIX "subl %2,%0\n"
8937 + "int $4\n0:\n"
8938 + _ASM_EXTABLE(0b, 0b)
8939 +#endif
8940 +
8941 + "sets %1\n"
8942 : "+m" (v->counter), "=qm" (c)
8943 : "ir" (i) : "memory");
8944 return c;
8945 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
8946 goto no_xadd;
8947 #endif
8948 /* Modern 486+ processor */
8949 - return i + xadd(&v->counter, i);
8950 + return i + xadd_check_overflow(&v->counter, i);
8951
8952 #ifdef CONFIG_M386
8953 no_xadd: /* Legacy 386 processor */
8954 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
8955 }
8956
8957 /**
8958 + * atomic_add_return_unchecked - add integer and return
8959 + * @i: integer value to add
8960 + * @v: pointer of type atomic_unchecked_t
8961 + *
8962 + * Atomically adds @i to @v and returns @i + @v
8963 + */
8964 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8965 +{
8966 +#ifdef CONFIG_M386
8967 + int __i;
8968 + unsigned long flags;
8969 + if (unlikely(boot_cpu_data.x86 <= 3))
8970 + goto no_xadd;
8971 +#endif
8972 + /* Modern 486+ processor */
8973 + return i + xadd(&v->counter, i);
8974 +
8975 +#ifdef CONFIG_M386
8976 +no_xadd: /* Legacy 386 processor */
8977 + raw_local_irq_save(flags);
8978 + __i = atomic_read_unchecked(v);
8979 + atomic_set_unchecked(v, i + __i);
8980 + raw_local_irq_restore(flags);
8981 + return i + __i;
8982 +#endif
8983 +}
8984 +
8985 +/**
8986 * atomic_sub_return - subtract integer and return
8987 * @v: pointer of type atomic_t
8988 * @i: integer value to subtract
8989 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
8990 }
8991
8992 #define atomic_inc_return(v) (atomic_add_return(1, v))
8993 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8994 +{
8995 + return atomic_add_return_unchecked(1, v);
8996 +}
8997 #define atomic_dec_return(v) (atomic_sub_return(1, v))
8998
8999 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9000 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9001 return cmpxchg(&v->counter, old, new);
9002 }
9003
9004 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9005 +{
9006 + return cmpxchg(&v->counter, old, new);
9007 +}
9008 +
9009 static inline int atomic_xchg(atomic_t *v, int new)
9010 {
9011 return xchg(&v->counter, new);
9012 }
9013
9014 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9015 +{
9016 + return xchg(&v->counter, new);
9017 +}
9018 +
9019 /**
9020 * __atomic_add_unless - add unless the number is already a given value
9021 * @v: pointer of type atomic_t
9022 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9023 */
9024 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9025 {
9026 - int c, old;
9027 + int c, old, new;
9028 c = atomic_read(v);
9029 for (;;) {
9030 - if (unlikely(c == (u)))
9031 + if (unlikely(c == u))
9032 break;
9033 - old = atomic_cmpxchg((v), c, c + (a));
9034 +
9035 + asm volatile("addl %2,%0\n"
9036 +
9037 +#ifdef CONFIG_PAX_REFCOUNT
9038 + "jno 0f\n"
9039 + "subl %2,%0\n"
9040 + "int $4\n0:\n"
9041 + _ASM_EXTABLE(0b, 0b)
9042 +#endif
9043 +
9044 + : "=r" (new)
9045 + : "0" (c), "ir" (a));
9046 +
9047 + old = atomic_cmpxchg(v, c, new);
9048 if (likely(old == c))
9049 break;
9050 c = old;
9051 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9052 return c;
9053 }
9054
9055 +/**
9056 + * atomic_inc_not_zero_hint - increment if not null
9057 + * @v: pointer of type atomic_t
9058 + * @hint: probable value of the atomic before the increment
9059 + *
9060 + * This version of atomic_inc_not_zero() gives a hint of probable
9061 + * value of the atomic. This helps processor to not read the memory
9062 + * before doing the atomic read/modify/write cycle, lowering
9063 + * number of bus transactions on some arches.
9064 + *
9065 + * Returns: 0 if increment was not done, 1 otherwise.
9066 + */
9067 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9068 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9069 +{
9070 + int val, c = hint, new;
9071 +
9072 + /* sanity test, should be removed by compiler if hint is a constant */
9073 + if (!hint)
9074 + return __atomic_add_unless(v, 1, 0);
9075 +
9076 + do {
9077 + asm volatile("incl %0\n"
9078 +
9079 +#ifdef CONFIG_PAX_REFCOUNT
9080 + "jno 0f\n"
9081 + "decl %0\n"
9082 + "int $4\n0:\n"
9083 + _ASM_EXTABLE(0b, 0b)
9084 +#endif
9085 +
9086 + : "=r" (new)
9087 + : "0" (c));
9088 +
9089 + val = atomic_cmpxchg(v, c, new);
9090 + if (val == c)
9091 + return 1;
9092 + c = val;
9093 + } while (c);
9094 +
9095 + return 0;
9096 +}
9097
9098 /*
9099 * atomic_dec_if_positive - decrement by 1 if old value positive
9100 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9101 index 24098aa..1e37723 100644
9102 --- a/arch/x86/include/asm/atomic64_32.h
9103 +++ b/arch/x86/include/asm/atomic64_32.h
9104 @@ -12,6 +12,14 @@ typedef struct {
9105 u64 __aligned(8) counter;
9106 } atomic64_t;
9107
9108 +#ifdef CONFIG_PAX_REFCOUNT
9109 +typedef struct {
9110 + u64 __aligned(8) counter;
9111 +} atomic64_unchecked_t;
9112 +#else
9113 +typedef atomic64_t atomic64_unchecked_t;
9114 +#endif
9115 +
9116 #define ATOMIC64_INIT(val) { (val) }
9117
9118 #ifdef CONFIG_X86_CMPXCHG64
9119 @@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9120 }
9121
9122 /**
9123 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9124 + * @p: pointer to type atomic64_unchecked_t
9125 + * @o: expected value
9126 + * @n: new value
9127 + *
9128 + * Atomically sets @v to @n if it was equal to @o and returns
9129 + * the old value.
9130 + */
9131 +
9132 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9133 +{
9134 + return cmpxchg64(&v->counter, o, n);
9135 +}
9136 +
9137 +/**
9138 * atomic64_xchg - xchg atomic64 variable
9139 * @v: pointer to type atomic64_t
9140 * @n: value to assign
9141 @@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9142 }
9143
9144 /**
9145 + * atomic64_set_unchecked - set atomic64 variable
9146 + * @v: pointer to type atomic64_unchecked_t
9147 + * @n: value to assign
9148 + *
9149 + * Atomically sets the value of @v to @n.
9150 + */
9151 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9152 +{
9153 + unsigned high = (unsigned)(i >> 32);
9154 + unsigned low = (unsigned)i;
9155 + asm volatile(ATOMIC64_ALTERNATIVE(set)
9156 + : "+b" (low), "+c" (high)
9157 + : "S" (v)
9158 + : "eax", "edx", "memory"
9159 + );
9160 +}
9161 +
9162 +/**
9163 * atomic64_read - read atomic64 variable
9164 * @v: pointer to type atomic64_t
9165 *
9166 @@ -93,6 +134,22 @@ static inline long long atomic64_read(atomic64_t *v)
9167 }
9168
9169 /**
9170 + * atomic64_read_unchecked - read atomic64 variable
9171 + * @v: pointer to type atomic64_unchecked_t
9172 + *
9173 + * Atomically reads the value of @v and returns it.
9174 + */
9175 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9176 +{
9177 + long long r;
9178 + asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
9179 + : "=A" (r), "+c" (v)
9180 + : : "memory"
9181 + );
9182 + return r;
9183 + }
9184 +
9185 +/**
9186 * atomic64_add_return - add and return
9187 * @i: integer value to add
9188 * @v: pointer to type atomic64_t
9189 @@ -108,6 +165,22 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9190 return i;
9191 }
9192
9193 +/**
9194 + * atomic64_add_return_unchecked - add and return
9195 + * @i: integer value to add
9196 + * @v: pointer to type atomic64_unchecked_t
9197 + *
9198 + * Atomically adds @i to @v and returns @i + *@v
9199 + */
9200 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9201 +{
9202 + asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
9203 + : "+A" (i), "+c" (v)
9204 + : : "memory"
9205 + );
9206 + return i;
9207 +}
9208 +
9209 /*
9210 * Other variants with different arithmetic operators:
9211 */
9212 @@ -131,6 +204,17 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9213 return a;
9214 }
9215
9216 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9217 +{
9218 + long long a;
9219 + asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
9220 + : "=A" (a)
9221 + : "S" (v)
9222 + : "memory", "ecx"
9223 + );
9224 + return a;
9225 +}
9226 +
9227 static inline long long atomic64_dec_return(atomic64_t *v)
9228 {
9229 long long a;
9230 @@ -159,6 +243,22 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9231 }
9232
9233 /**
9234 + * atomic64_add_unchecked - add integer to atomic64 variable
9235 + * @i: integer value to add
9236 + * @v: pointer to type atomic64_unchecked_t
9237 + *
9238 + * Atomically adds @i to @v.
9239 + */
9240 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9241 +{
9242 + asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
9243 + : "+A" (i), "+c" (v)
9244 + : : "memory"
9245 + );
9246 + return i;
9247 +}
9248 +
9249 +/**
9250 * atomic64_sub - subtract the atomic64 variable
9251 * @i: integer value to subtract
9252 * @v: pointer to type atomic64_t
9253 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9254 index 0e1cbfc..5623683 100644
9255 --- a/arch/x86/include/asm/atomic64_64.h
9256 +++ b/arch/x86/include/asm/atomic64_64.h
9257 @@ -18,7 +18,19 @@
9258 */
9259 static inline long atomic64_read(const atomic64_t *v)
9260 {
9261 - return (*(volatile long *)&(v)->counter);
9262 + return (*(volatile const long *)&(v)->counter);
9263 +}
9264 +
9265 +/**
9266 + * atomic64_read_unchecked - read atomic64 variable
9267 + * @v: pointer of type atomic64_unchecked_t
9268 + *
9269 + * Atomically reads the value of @v.
9270 + * Doesn't imply a read memory barrier.
9271 + */
9272 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9273 +{
9274 + return (*(volatile const long *)&(v)->counter);
9275 }
9276
9277 /**
9278 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9279 }
9280
9281 /**
9282 + * atomic64_set_unchecked - set atomic64 variable
9283 + * @v: pointer to type atomic64_unchecked_t
9284 + * @i: required value
9285 + *
9286 + * Atomically sets the value of @v to @i.
9287 + */
9288 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9289 +{
9290 + v->counter = i;
9291 +}
9292 +
9293 +/**
9294 * atomic64_add - add integer to atomic64 variable
9295 * @i: integer value to add
9296 * @v: pointer to type atomic64_t
9297 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9298 */
9299 static inline void atomic64_add(long i, atomic64_t *v)
9300 {
9301 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9302 +
9303 +#ifdef CONFIG_PAX_REFCOUNT
9304 + "jno 0f\n"
9305 + LOCK_PREFIX "subq %1,%0\n"
9306 + "int $4\n0:\n"
9307 + _ASM_EXTABLE(0b, 0b)
9308 +#endif
9309 +
9310 + : "=m" (v->counter)
9311 + : "er" (i), "m" (v->counter));
9312 +}
9313 +
9314 +/**
9315 + * atomic64_add_unchecked - add integer to atomic64 variable
9316 + * @i: integer value to add
9317 + * @v: pointer to type atomic64_unchecked_t
9318 + *
9319 + * Atomically adds @i to @v.
9320 + */
9321 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9322 +{
9323 asm volatile(LOCK_PREFIX "addq %1,%0"
9324 : "=m" (v->counter)
9325 : "er" (i), "m" (v->counter));
9326 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9327 */
9328 static inline void atomic64_sub(long i, atomic64_t *v)
9329 {
9330 - asm volatile(LOCK_PREFIX "subq %1,%0"
9331 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9332 +
9333 +#ifdef CONFIG_PAX_REFCOUNT
9334 + "jno 0f\n"
9335 + LOCK_PREFIX "addq %1,%0\n"
9336 + "int $4\n0:\n"
9337 + _ASM_EXTABLE(0b, 0b)
9338 +#endif
9339 +
9340 + : "=m" (v->counter)
9341 + : "er" (i), "m" (v->counter));
9342 +}
9343 +
9344 +/**
9345 + * atomic64_sub_unchecked - subtract the atomic64 variable
9346 + * @i: integer value to subtract
9347 + * @v: pointer to type atomic64_unchecked_t
9348 + *
9349 + * Atomically subtracts @i from @v.
9350 + */
9351 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9352 +{
9353 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9354 : "=m" (v->counter)
9355 : "er" (i), "m" (v->counter));
9356 }
9357 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9358 {
9359 unsigned char c;
9360
9361 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9362 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9363 +
9364 +#ifdef CONFIG_PAX_REFCOUNT
9365 + "jno 0f\n"
9366 + LOCK_PREFIX "addq %2,%0\n"
9367 + "int $4\n0:\n"
9368 + _ASM_EXTABLE(0b, 0b)
9369 +#endif
9370 +
9371 + "sete %1\n"
9372 : "=m" (v->counter), "=qm" (c)
9373 : "er" (i), "m" (v->counter) : "memory");
9374 return c;
9375 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9376 */
9377 static inline void atomic64_inc(atomic64_t *v)
9378 {
9379 + asm volatile(LOCK_PREFIX "incq %0\n"
9380 +
9381 +#ifdef CONFIG_PAX_REFCOUNT
9382 + "jno 0f\n"
9383 + LOCK_PREFIX "decq %0\n"
9384 + "int $4\n0:\n"
9385 + _ASM_EXTABLE(0b, 0b)
9386 +#endif
9387 +
9388 + : "=m" (v->counter)
9389 + : "m" (v->counter));
9390 +}
9391 +
9392 +/**
9393 + * atomic64_inc_unchecked - increment atomic64 variable
9394 + * @v: pointer to type atomic64_unchecked_t
9395 + *
9396 + * Atomically increments @v by 1.
9397 + */
9398 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9399 +{
9400 asm volatile(LOCK_PREFIX "incq %0"
9401 : "=m" (v->counter)
9402 : "m" (v->counter));
9403 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9404 */
9405 static inline void atomic64_dec(atomic64_t *v)
9406 {
9407 - asm volatile(LOCK_PREFIX "decq %0"
9408 + asm volatile(LOCK_PREFIX "decq %0\n"
9409 +
9410 +#ifdef CONFIG_PAX_REFCOUNT
9411 + "jno 0f\n"
9412 + LOCK_PREFIX "incq %0\n"
9413 + "int $4\n0:\n"
9414 + _ASM_EXTABLE(0b, 0b)
9415 +#endif
9416 +
9417 + : "=m" (v->counter)
9418 + : "m" (v->counter));
9419 +}
9420 +
9421 +/**
9422 + * atomic64_dec_unchecked - decrement atomic64 variable
9423 + * @v: pointer to type atomic64_t
9424 + *
9425 + * Atomically decrements @v by 1.
9426 + */
9427 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9428 +{
9429 + asm volatile(LOCK_PREFIX "decq %0\n"
9430 : "=m" (v->counter)
9431 : "m" (v->counter));
9432 }
9433 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9434 {
9435 unsigned char c;
9436
9437 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9438 + asm volatile(LOCK_PREFIX "decq %0\n"
9439 +
9440 +#ifdef CONFIG_PAX_REFCOUNT
9441 + "jno 0f\n"
9442 + LOCK_PREFIX "incq %0\n"
9443 + "int $4\n0:\n"
9444 + _ASM_EXTABLE(0b, 0b)
9445 +#endif
9446 +
9447 + "sete %1\n"
9448 : "=m" (v->counter), "=qm" (c)
9449 : "m" (v->counter) : "memory");
9450 return c != 0;
9451 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9452 {
9453 unsigned char c;
9454
9455 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9456 + asm volatile(LOCK_PREFIX "incq %0\n"
9457 +
9458 +#ifdef CONFIG_PAX_REFCOUNT
9459 + "jno 0f\n"
9460 + LOCK_PREFIX "decq %0\n"
9461 + "int $4\n0:\n"
9462 + _ASM_EXTABLE(0b, 0b)
9463 +#endif
9464 +
9465 + "sete %1\n"
9466 : "=m" (v->counter), "=qm" (c)
9467 : "m" (v->counter) : "memory");
9468 return c != 0;
9469 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9470 {
9471 unsigned char c;
9472
9473 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9474 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9475 +
9476 +#ifdef CONFIG_PAX_REFCOUNT
9477 + "jno 0f\n"
9478 + LOCK_PREFIX "subq %2,%0\n"
9479 + "int $4\n0:\n"
9480 + _ASM_EXTABLE(0b, 0b)
9481 +#endif
9482 +
9483 + "sets %1\n"
9484 : "=m" (v->counter), "=qm" (c)
9485 : "er" (i), "m" (v->counter) : "memory");
9486 return c;
9487 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9488 */
9489 static inline long atomic64_add_return(long i, atomic64_t *v)
9490 {
9491 + return i + xadd_check_overflow(&v->counter, i);
9492 +}
9493 +
9494 +/**
9495 + * atomic64_add_return_unchecked - add and return
9496 + * @i: integer value to add
9497 + * @v: pointer to type atomic64_unchecked_t
9498 + *
9499 + * Atomically adds @i to @v and returns @i + @v
9500 + */
9501 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9502 +{
9503 return i + xadd(&v->counter, i);
9504 }
9505
9506 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9507 }
9508
9509 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9510 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9511 +{
9512 + return atomic64_add_return_unchecked(1, v);
9513 +}
9514 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9515
9516 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9517 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9518 return cmpxchg(&v->counter, old, new);
9519 }
9520
9521 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9522 +{
9523 + return cmpxchg(&v->counter, old, new);
9524 +}
9525 +
9526 static inline long atomic64_xchg(atomic64_t *v, long new)
9527 {
9528 return xchg(&v->counter, new);
9529 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
9530 */
9531 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9532 {
9533 - long c, old;
9534 + long c, old, new;
9535 c = atomic64_read(v);
9536 for (;;) {
9537 - if (unlikely(c == (u)))
9538 + if (unlikely(c == u))
9539 break;
9540 - old = atomic64_cmpxchg((v), c, c + (a));
9541 +
9542 + asm volatile("add %2,%0\n"
9543 +
9544 +#ifdef CONFIG_PAX_REFCOUNT
9545 + "jno 0f\n"
9546 + "sub %2,%0\n"
9547 + "int $4\n0:\n"
9548 + _ASM_EXTABLE(0b, 0b)
9549 +#endif
9550 +
9551 + : "=r" (new)
9552 + : "0" (c), "ir" (a));
9553 +
9554 + old = atomic64_cmpxchg(v, c, new);
9555 if (likely(old == c))
9556 break;
9557 c = old;
9558 }
9559 - return c != (u);
9560 + return c != u;
9561 }
9562
9563 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9564 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
9565 index 1775d6e..b65017f 100644
9566 --- a/arch/x86/include/asm/bitops.h
9567 +++ b/arch/x86/include/asm/bitops.h
9568 @@ -38,7 +38,7 @@
9569 * a mask operation on a byte.
9570 */
9571 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
9572 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
9573 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
9574 #define CONST_MASK(nr) (1 << ((nr) & 7))
9575
9576 /**
9577 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
9578 index 5e1a2ee..c9f9533 100644
9579 --- a/arch/x86/include/asm/boot.h
9580 +++ b/arch/x86/include/asm/boot.h
9581 @@ -11,10 +11,15 @@
9582 #include <asm/pgtable_types.h>
9583
9584 /* Physical address where kernel should be loaded. */
9585 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9586 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9587 + (CONFIG_PHYSICAL_ALIGN - 1)) \
9588 & ~(CONFIG_PHYSICAL_ALIGN - 1))
9589
9590 +#ifndef __ASSEMBLY__
9591 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
9592 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
9593 +#endif
9594 +
9595 /* Minimum kernel alignment, as a power of two */
9596 #ifdef CONFIG_X86_64
9597 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
9598 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
9599 index 48f99f1..d78ebf9 100644
9600 --- a/arch/x86/include/asm/cache.h
9601 +++ b/arch/x86/include/asm/cache.h
9602 @@ -5,12 +5,13 @@
9603
9604 /* L1 cache line size */
9605 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9606 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9607 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9608
9609 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9610 +#define __read_only __attribute__((__section__(".data..read_only")))
9611
9612 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
9613 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
9614 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
9615
9616 #ifdef CONFIG_X86_VSMP
9617 #ifdef CONFIG_SMP
9618 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
9619 index 4e12668..501d239 100644
9620 --- a/arch/x86/include/asm/cacheflush.h
9621 +++ b/arch/x86/include/asm/cacheflush.h
9622 @@ -26,7 +26,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
9623 unsigned long pg_flags = pg->flags & _PGMT_MASK;
9624
9625 if (pg_flags == _PGMT_DEFAULT)
9626 - return -1;
9627 + return ~0UL;
9628 else if (pg_flags == _PGMT_WC)
9629 return _PAGE_CACHE_WC;
9630 else if (pg_flags == _PGMT_UC_MINUS)
9631 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
9632 index 46fc474..b02b0f9 100644
9633 --- a/arch/x86/include/asm/checksum_32.h
9634 +++ b/arch/x86/include/asm/checksum_32.h
9635 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
9636 int len, __wsum sum,
9637 int *src_err_ptr, int *dst_err_ptr);
9638
9639 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
9640 + int len, __wsum sum,
9641 + int *src_err_ptr, int *dst_err_ptr);
9642 +
9643 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
9644 + int len, __wsum sum,
9645 + int *src_err_ptr, int *dst_err_ptr);
9646 +
9647 /*
9648 * Note: when you get a NULL pointer exception here this means someone
9649 * passed in an incorrect kernel address to one of these functions.
9650 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
9651 int *err_ptr)
9652 {
9653 might_sleep();
9654 - return csum_partial_copy_generic((__force void *)src, dst,
9655 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
9656 len, sum, err_ptr, NULL);
9657 }
9658
9659 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
9660 {
9661 might_sleep();
9662 if (access_ok(VERIFY_WRITE, dst, len))
9663 - return csum_partial_copy_generic(src, (__force void *)dst,
9664 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
9665 len, sum, NULL, err_ptr);
9666
9667 if (len)
9668 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
9669 index 5d3acdf..6447a02 100644
9670 --- a/arch/x86/include/asm/cmpxchg.h
9671 +++ b/arch/x86/include/asm/cmpxchg.h
9672 @@ -14,6 +14,8 @@ extern void __cmpxchg_wrong_size(void)
9673 __compiletime_error("Bad argument size for cmpxchg");
9674 extern void __xadd_wrong_size(void)
9675 __compiletime_error("Bad argument size for xadd");
9676 +extern void __xadd_check_overflow_wrong_size(void)
9677 + __compiletime_error("Bad argument size for xadd_check_overflow");
9678
9679 /*
9680 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
9681 @@ -195,6 +197,34 @@ extern void __xadd_wrong_size(void)
9682 __ret; \
9683 })
9684
9685 +#define __xadd_check_overflow(ptr, inc, lock) \
9686 + ({ \
9687 + __typeof__ (*(ptr)) __ret = (inc); \
9688 + switch (sizeof(*(ptr))) { \
9689 + case __X86_CASE_L: \
9690 + asm volatile (lock "xaddl %0, %1\n" \
9691 + "jno 0f\n" \
9692 + "mov %0,%1\n" \
9693 + "int $4\n0:\n" \
9694 + _ASM_EXTABLE(0b, 0b) \
9695 + : "+r" (__ret), "+m" (*(ptr)) \
9696 + : : "memory", "cc"); \
9697 + break; \
9698 + case __X86_CASE_Q: \
9699 + asm volatile (lock "xaddq %q0, %1\n" \
9700 + "jno 0f\n" \
9701 + "mov %0,%1\n" \
9702 + "int $4\n0:\n" \
9703 + _ASM_EXTABLE(0b, 0b) \
9704 + : "+r" (__ret), "+m" (*(ptr)) \
9705 + : : "memory", "cc"); \
9706 + break; \
9707 + default: \
9708 + __xadd_check_overflow_wrong_size(); \
9709 + } \
9710 + __ret; \
9711 + })
9712 +
9713 /*
9714 * xadd() adds "inc" to "*ptr" and atomically returns the previous
9715 * value of "*ptr".
9716 @@ -207,4 +237,6 @@ extern void __xadd_wrong_size(void)
9717 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
9718 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
9719
9720 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
9721 +
9722 #endif /* ASM_X86_CMPXCHG_H */
9723 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
9724 index f3444f7..051a196 100644
9725 --- a/arch/x86/include/asm/cpufeature.h
9726 +++ b/arch/x86/include/asm/cpufeature.h
9727 @@ -363,7 +363,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
9728 ".section .discard,\"aw\",@progbits\n"
9729 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
9730 ".previous\n"
9731 - ".section .altinstr_replacement,\"ax\"\n"
9732 + ".section .altinstr_replacement,\"a\"\n"
9733 "3: movb $1,%0\n"
9734 "4:\n"
9735 ".previous\n"
9736 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
9737 index 41935fa..3b40db8 100644
9738 --- a/arch/x86/include/asm/desc.h
9739 +++ b/arch/x86/include/asm/desc.h
9740 @@ -4,6 +4,7 @@
9741 #include <asm/desc_defs.h>
9742 #include <asm/ldt.h>
9743 #include <asm/mmu.h>
9744 +#include <asm/pgtable.h>
9745
9746 #include <linux/smp.h>
9747
9748 @@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9749
9750 desc->type = (info->read_exec_only ^ 1) << 1;
9751 desc->type |= info->contents << 2;
9752 + desc->type |= info->seg_not_present ^ 1;
9753
9754 desc->s = 1;
9755 desc->dpl = 0x3;
9756 @@ -34,17 +36,12 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9757 }
9758
9759 extern struct desc_ptr idt_descr;
9760 -extern gate_desc idt_table[];
9761 -
9762 -struct gdt_page {
9763 - struct desc_struct gdt[GDT_ENTRIES];
9764 -} __attribute__((aligned(PAGE_SIZE)));
9765 -
9766 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
9767 +extern gate_desc idt_table[256];
9768
9769 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
9770 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
9771 {
9772 - return per_cpu(gdt_page, cpu).gdt;
9773 + return cpu_gdt_table[cpu];
9774 }
9775
9776 #ifdef CONFIG_X86_64
9777 @@ -69,8 +66,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
9778 unsigned long base, unsigned dpl, unsigned flags,
9779 unsigned short seg)
9780 {
9781 - gate->a = (seg << 16) | (base & 0xffff);
9782 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
9783 + gate->gate.offset_low = base;
9784 + gate->gate.seg = seg;
9785 + gate->gate.reserved = 0;
9786 + gate->gate.type = type;
9787 + gate->gate.s = 0;
9788 + gate->gate.dpl = dpl;
9789 + gate->gate.p = 1;
9790 + gate->gate.offset_high = base >> 16;
9791 }
9792
9793 #endif
9794 @@ -115,12 +118,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
9795
9796 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
9797 {
9798 + pax_open_kernel();
9799 memcpy(&idt[entry], gate, sizeof(*gate));
9800 + pax_close_kernel();
9801 }
9802
9803 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
9804 {
9805 + pax_open_kernel();
9806 memcpy(&ldt[entry], desc, 8);
9807 + pax_close_kernel();
9808 }
9809
9810 static inline void
9811 @@ -134,7 +141,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
9812 default: size = sizeof(*gdt); break;
9813 }
9814
9815 + pax_open_kernel();
9816 memcpy(&gdt[entry], desc, size);
9817 + pax_close_kernel();
9818 }
9819
9820 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
9821 @@ -207,7 +216,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
9822
9823 static inline void native_load_tr_desc(void)
9824 {
9825 + pax_open_kernel();
9826 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
9827 + pax_close_kernel();
9828 }
9829
9830 static inline void native_load_gdt(const struct desc_ptr *dtr)
9831 @@ -244,8 +255,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
9832 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
9833 unsigned int i;
9834
9835 + pax_open_kernel();
9836 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
9837 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
9838 + pax_close_kernel();
9839 }
9840
9841 #define _LDT_empty(info) \
9842 @@ -307,7 +320,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
9843 desc->limit = (limit >> 16) & 0xf;
9844 }
9845
9846 -static inline void _set_gate(int gate, unsigned type, void *addr,
9847 +static inline void _set_gate(int gate, unsigned type, const void *addr,
9848 unsigned dpl, unsigned ist, unsigned seg)
9849 {
9850 gate_desc s;
9851 @@ -326,7 +339,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
9852 * Pentium F0 0F bugfix can have resulted in the mapped
9853 * IDT being write-protected.
9854 */
9855 -static inline void set_intr_gate(unsigned int n, void *addr)
9856 +static inline void set_intr_gate(unsigned int n, const void *addr)
9857 {
9858 BUG_ON((unsigned)n > 0xFF);
9859 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
9860 @@ -356,19 +369,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
9861 /*
9862 * This routine sets up an interrupt gate at directory privilege level 3.
9863 */
9864 -static inline void set_system_intr_gate(unsigned int n, void *addr)
9865 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
9866 {
9867 BUG_ON((unsigned)n > 0xFF);
9868 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
9869 }
9870
9871 -static inline void set_system_trap_gate(unsigned int n, void *addr)
9872 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
9873 {
9874 BUG_ON((unsigned)n > 0xFF);
9875 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
9876 }
9877
9878 -static inline void set_trap_gate(unsigned int n, void *addr)
9879 +static inline void set_trap_gate(unsigned int n, const void *addr)
9880 {
9881 BUG_ON((unsigned)n > 0xFF);
9882 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
9883 @@ -377,19 +390,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
9884 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
9885 {
9886 BUG_ON((unsigned)n > 0xFF);
9887 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
9888 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
9889 }
9890
9891 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
9892 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
9893 {
9894 BUG_ON((unsigned)n > 0xFF);
9895 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
9896 }
9897
9898 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
9899 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
9900 {
9901 BUG_ON((unsigned)n > 0xFF);
9902 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
9903 }
9904
9905 +#ifdef CONFIG_X86_32
9906 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
9907 +{
9908 + struct desc_struct d;
9909 +
9910 + if (likely(limit))
9911 + limit = (limit - 1UL) >> PAGE_SHIFT;
9912 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
9913 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
9914 +}
9915 +#endif
9916 +
9917 #endif /* _ASM_X86_DESC_H */
9918 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
9919 index 278441f..b95a174 100644
9920 --- a/arch/x86/include/asm/desc_defs.h
9921 +++ b/arch/x86/include/asm/desc_defs.h
9922 @@ -31,6 +31,12 @@ struct desc_struct {
9923 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
9924 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
9925 };
9926 + struct {
9927 + u16 offset_low;
9928 + u16 seg;
9929 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
9930 + unsigned offset_high: 16;
9931 + } gate;
9932 };
9933 } __attribute__((packed));
9934
9935 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
9936 index 908b969..a1f4eb4 100644
9937 --- a/arch/x86/include/asm/e820.h
9938 +++ b/arch/x86/include/asm/e820.h
9939 @@ -69,7 +69,7 @@ struct e820map {
9940 #define ISA_START_ADDRESS 0xa0000
9941 #define ISA_END_ADDRESS 0x100000
9942
9943 -#define BIOS_BEGIN 0x000a0000
9944 +#define BIOS_BEGIN 0x000c0000
9945 #define BIOS_END 0x00100000
9946
9947 #define BIOS_ROM_BASE 0xffe00000
9948 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
9949 index 5f962df..7289f09 100644
9950 --- a/arch/x86/include/asm/elf.h
9951 +++ b/arch/x86/include/asm/elf.h
9952 @@ -238,7 +238,25 @@ extern int force_personality32;
9953 the loader. We need to make sure that it is out of the way of the program
9954 that it will "exec", and that there is sufficient room for the brk. */
9955
9956 +#ifdef CONFIG_PAX_SEGMEXEC
9957 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
9958 +#else
9959 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
9960 +#endif
9961 +
9962 +#ifdef CONFIG_PAX_ASLR
9963 +#ifdef CONFIG_X86_32
9964 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
9965 +
9966 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9967 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9968 +#else
9969 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
9970 +
9971 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9972 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9973 +#endif
9974 +#endif
9975
9976 /* This yields a mask that user programs can use to figure out what
9977 instruction set this CPU supports. This could be done in user space,
9978 @@ -291,9 +309,7 @@ do { \
9979
9980 #define ARCH_DLINFO \
9981 do { \
9982 - if (vdso_enabled) \
9983 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
9984 - (unsigned long)current->mm->context.vdso); \
9985 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
9986 } while (0)
9987
9988 #define AT_SYSINFO 32
9989 @@ -304,7 +320,7 @@ do { \
9990
9991 #endif /* !CONFIG_X86_32 */
9992
9993 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
9994 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
9995
9996 #define VDSO_ENTRY \
9997 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
9998 @@ -318,9 +334,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
9999 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10000 #define compat_arch_setup_additional_pages syscall32_setup_pages
10001
10002 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10003 -#define arch_randomize_brk arch_randomize_brk
10004 -
10005 /*
10006 * True on X86_32 or when emulating IA32 on X86_64
10007 */
10008 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10009 index cc70c1c..d96d011 100644
10010 --- a/arch/x86/include/asm/emergency-restart.h
10011 +++ b/arch/x86/include/asm/emergency-restart.h
10012 @@ -15,6 +15,6 @@ enum reboot_type {
10013
10014 extern enum reboot_type reboot_type;
10015
10016 -extern void machine_emergency_restart(void);
10017 +extern void machine_emergency_restart(void) __noreturn;
10018
10019 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10020 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
10021 index dbe82a5..c6d8a00 100644
10022 --- a/arch/x86/include/asm/floppy.h
10023 +++ b/arch/x86/include/asm/floppy.h
10024 @@ -157,6 +157,7 @@ static unsigned long dma_mem_alloc(unsigned long size)
10025 }
10026
10027
10028 +static unsigned long vdma_mem_alloc(unsigned long size) __size_overflow(1);
10029 static unsigned long vdma_mem_alloc(unsigned long size)
10030 {
10031 return (unsigned long)vmalloc(size);
10032 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10033 index d09bb03..4ea4194 100644
10034 --- a/arch/x86/include/asm/futex.h
10035 +++ b/arch/x86/include/asm/futex.h
10036 @@ -12,16 +12,18 @@
10037 #include <asm/system.h>
10038
10039 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10040 + typecheck(u32 __user *, uaddr); \
10041 asm volatile("1:\t" insn "\n" \
10042 "2:\t.section .fixup,\"ax\"\n" \
10043 "3:\tmov\t%3, %1\n" \
10044 "\tjmp\t2b\n" \
10045 "\t.previous\n" \
10046 _ASM_EXTABLE(1b, 3b) \
10047 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10048 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10049 : "i" (-EFAULT), "0" (oparg), "1" (0))
10050
10051 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10052 + typecheck(u32 __user *, uaddr); \
10053 asm volatile("1:\tmovl %2, %0\n" \
10054 "\tmovl\t%0, %3\n" \
10055 "\t" insn "\n" \
10056 @@ -34,7 +36,7 @@
10057 _ASM_EXTABLE(1b, 4b) \
10058 _ASM_EXTABLE(2b, 4b) \
10059 : "=&a" (oldval), "=&r" (ret), \
10060 - "+m" (*uaddr), "=&r" (tem) \
10061 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10062 : "r" (oparg), "i" (-EFAULT), "1" (0))
10063
10064 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10065 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10066
10067 switch (op) {
10068 case FUTEX_OP_SET:
10069 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10070 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10071 break;
10072 case FUTEX_OP_ADD:
10073 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10074 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10075 uaddr, oparg);
10076 break;
10077 case FUTEX_OP_OR:
10078 @@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10079 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10080 return -EFAULT;
10081
10082 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10083 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10084 "2:\t.section .fixup, \"ax\"\n"
10085 "3:\tmov %3, %0\n"
10086 "\tjmp 2b\n"
10087 "\t.previous\n"
10088 _ASM_EXTABLE(1b, 3b)
10089 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10090 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10091 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10092 : "memory"
10093 );
10094 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10095 index eb92a6e..b98b2f4 100644
10096 --- a/arch/x86/include/asm/hw_irq.h
10097 +++ b/arch/x86/include/asm/hw_irq.h
10098 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10099 extern void enable_IO_APIC(void);
10100
10101 /* Statistics */
10102 -extern atomic_t irq_err_count;
10103 -extern atomic_t irq_mis_count;
10104 +extern atomic_unchecked_t irq_err_count;
10105 +extern atomic_unchecked_t irq_mis_count;
10106
10107 /* EISA */
10108 extern void eisa_set_level_irq(unsigned int irq);
10109 diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
10110 index a850b4d..bae26dc 100644
10111 --- a/arch/x86/include/asm/i387.h
10112 +++ b/arch/x86/include/asm/i387.h
10113 @@ -92,6 +92,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10114 {
10115 int err;
10116
10117 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10118 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10119 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10120 +#endif
10121 +
10122 /* See comment in fxsave() below. */
10123 #ifdef CONFIG_AS_FXSAVEQ
10124 asm volatile("1: fxrstorq %[fx]\n\t"
10125 @@ -121,6 +126,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10126 {
10127 int err;
10128
10129 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10130 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10131 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10132 +#endif
10133 +
10134 /*
10135 * Clear the bytes not touched by the fxsave and reserved
10136 * for the SW usage.
10137 @@ -424,7 +434,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
10138 static inline bool interrupted_user_mode(void)
10139 {
10140 struct pt_regs *regs = get_irq_regs();
10141 - return regs && user_mode_vm(regs);
10142 + return regs && user_mode(regs);
10143 }
10144
10145 /*
10146 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10147 index d8e8eef..99f81ae 100644
10148 --- a/arch/x86/include/asm/io.h
10149 +++ b/arch/x86/include/asm/io.h
10150 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10151
10152 #include <linux/vmalloc.h>
10153
10154 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10155 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10156 +{
10157 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10158 +}
10159 +
10160 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10161 +{
10162 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10163 +}
10164 +
10165 /*
10166 * Convert a virtual cached pointer to an uncached pointer
10167 */
10168 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10169 index bba3cf8..06bc8da 100644
10170 --- a/arch/x86/include/asm/irqflags.h
10171 +++ b/arch/x86/include/asm/irqflags.h
10172 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10173 sti; \
10174 sysexit
10175
10176 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10177 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10178 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10179 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10180 +
10181 #else
10182 #define INTERRUPT_RETURN iret
10183 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10184 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10185 index 5478825..839e88c 100644
10186 --- a/arch/x86/include/asm/kprobes.h
10187 +++ b/arch/x86/include/asm/kprobes.h
10188 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10189 #define RELATIVEJUMP_SIZE 5
10190 #define RELATIVECALL_OPCODE 0xe8
10191 #define RELATIVE_ADDR_SIZE 4
10192 -#define MAX_STACK_SIZE 64
10193 -#define MIN_STACK_SIZE(ADDR) \
10194 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10195 - THREAD_SIZE - (unsigned long)(ADDR))) \
10196 - ? (MAX_STACK_SIZE) \
10197 - : (((unsigned long)current_thread_info()) + \
10198 - THREAD_SIZE - (unsigned long)(ADDR)))
10199 +#define MAX_STACK_SIZE 64UL
10200 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10201
10202 #define flush_insn_slot(p) do { } while (0)
10203
10204 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10205 index b4973f4..a42170a 100644
10206 --- a/arch/x86/include/asm/kvm_host.h
10207 +++ b/arch/x86/include/asm/kvm_host.h
10208 @@ -459,7 +459,7 @@ struct kvm_arch {
10209 unsigned int n_requested_mmu_pages;
10210 unsigned int n_max_mmu_pages;
10211 unsigned int indirect_shadow_pages;
10212 - atomic_t invlpg_counter;
10213 + atomic_unchecked_t invlpg_counter;
10214 struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
10215 /*
10216 * Hash table of struct kvm_mmu_page.
10217 @@ -638,7 +638,7 @@ struct kvm_x86_ops {
10218 int (*check_intercept)(struct kvm_vcpu *vcpu,
10219 struct x86_instruction_info *info,
10220 enum x86_intercept_stage stage);
10221 -};
10222 +} __do_const;
10223
10224 struct kvm_arch_async_pf {
10225 u32 token;
10226 @@ -667,9 +667,9 @@ void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages);
10227 int load_pdptrs(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, unsigned long cr3);
10228
10229 int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
10230 - const void *val, int bytes);
10231 + const void *val, int bytes) __size_overflow(2);
10232 int kvm_pv_mmu_op(struct kvm_vcpu *vcpu, unsigned long bytes,
10233 - gpa_t addr, unsigned long *ret);
10234 + gpa_t addr, unsigned long *ret) __size_overflow(2,3);
10235 u8 kvm_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn);
10236
10237 extern bool tdp_enabled;
10238 @@ -730,7 +730,7 @@ void kvm_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l);
10239 int kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr);
10240
10241 int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);
10242 -int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data);
10243 +int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data) __size_overflow(3);
10244
10245 unsigned long kvm_get_rflags(struct kvm_vcpu *vcpu);
10246 void kvm_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags);
10247 @@ -755,7 +755,7 @@ int fx_init(struct kvm_vcpu *vcpu);
10248 void kvm_mmu_flush_tlb(struct kvm_vcpu *vcpu);
10249 void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
10250 const u8 *new, int bytes,
10251 - bool guest_initiated);
10252 + bool guest_initiated) __size_overflow(2);
10253 int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva);
10254 void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);
10255 int kvm_mmu_load(struct kvm_vcpu *vcpu);
10256 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10257 index 9cdae5d..300d20f 100644
10258 --- a/arch/x86/include/asm/local.h
10259 +++ b/arch/x86/include/asm/local.h
10260 @@ -18,26 +18,58 @@ typedef struct {
10261
10262 static inline void local_inc(local_t *l)
10263 {
10264 - asm volatile(_ASM_INC "%0"
10265 + asm volatile(_ASM_INC "%0\n"
10266 +
10267 +#ifdef CONFIG_PAX_REFCOUNT
10268 + "jno 0f\n"
10269 + _ASM_DEC "%0\n"
10270 + "int $4\n0:\n"
10271 + _ASM_EXTABLE(0b, 0b)
10272 +#endif
10273 +
10274 : "+m" (l->a.counter));
10275 }
10276
10277 static inline void local_dec(local_t *l)
10278 {
10279 - asm volatile(_ASM_DEC "%0"
10280 + asm volatile(_ASM_DEC "%0\n"
10281 +
10282 +#ifdef CONFIG_PAX_REFCOUNT
10283 + "jno 0f\n"
10284 + _ASM_INC "%0\n"
10285 + "int $4\n0:\n"
10286 + _ASM_EXTABLE(0b, 0b)
10287 +#endif
10288 +
10289 : "+m" (l->a.counter));
10290 }
10291
10292 static inline void local_add(long i, local_t *l)
10293 {
10294 - asm volatile(_ASM_ADD "%1,%0"
10295 + asm volatile(_ASM_ADD "%1,%0\n"
10296 +
10297 +#ifdef CONFIG_PAX_REFCOUNT
10298 + "jno 0f\n"
10299 + _ASM_SUB "%1,%0\n"
10300 + "int $4\n0:\n"
10301 + _ASM_EXTABLE(0b, 0b)
10302 +#endif
10303 +
10304 : "+m" (l->a.counter)
10305 : "ir" (i));
10306 }
10307
10308 static inline void local_sub(long i, local_t *l)
10309 {
10310 - asm volatile(_ASM_SUB "%1,%0"
10311 + asm volatile(_ASM_SUB "%1,%0\n"
10312 +
10313 +#ifdef CONFIG_PAX_REFCOUNT
10314 + "jno 0f\n"
10315 + _ASM_ADD "%1,%0\n"
10316 + "int $4\n0:\n"
10317 + _ASM_EXTABLE(0b, 0b)
10318 +#endif
10319 +
10320 : "+m" (l->a.counter)
10321 : "ir" (i));
10322 }
10323 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10324 {
10325 unsigned char c;
10326
10327 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10328 + asm volatile(_ASM_SUB "%2,%0\n"
10329 +
10330 +#ifdef CONFIG_PAX_REFCOUNT
10331 + "jno 0f\n"
10332 + _ASM_ADD "%2,%0\n"
10333 + "int $4\n0:\n"
10334 + _ASM_EXTABLE(0b, 0b)
10335 +#endif
10336 +
10337 + "sete %1\n"
10338 : "+m" (l->a.counter), "=qm" (c)
10339 : "ir" (i) : "memory");
10340 return c;
10341 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
10342 {
10343 unsigned char c;
10344
10345 - asm volatile(_ASM_DEC "%0; sete %1"
10346 + asm volatile(_ASM_DEC "%0\n"
10347 +
10348 +#ifdef CONFIG_PAX_REFCOUNT
10349 + "jno 0f\n"
10350 + _ASM_INC "%0\n"
10351 + "int $4\n0:\n"
10352 + _ASM_EXTABLE(0b, 0b)
10353 +#endif
10354 +
10355 + "sete %1\n"
10356 : "+m" (l->a.counter), "=qm" (c)
10357 : : "memory");
10358 return c != 0;
10359 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
10360 {
10361 unsigned char c;
10362
10363 - asm volatile(_ASM_INC "%0; sete %1"
10364 + asm volatile(_ASM_INC "%0\n"
10365 +
10366 +#ifdef CONFIG_PAX_REFCOUNT
10367 + "jno 0f\n"
10368 + _ASM_DEC "%0\n"
10369 + "int $4\n0:\n"
10370 + _ASM_EXTABLE(0b, 0b)
10371 +#endif
10372 +
10373 + "sete %1\n"
10374 : "+m" (l->a.counter), "=qm" (c)
10375 : : "memory");
10376 return c != 0;
10377 @@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
10378 {
10379 unsigned char c;
10380
10381 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10382 + asm volatile(_ASM_ADD "%2,%0\n"
10383 +
10384 +#ifdef CONFIG_PAX_REFCOUNT
10385 + "jno 0f\n"
10386 + _ASM_SUB "%2,%0\n"
10387 + "int $4\n0:\n"
10388 + _ASM_EXTABLE(0b, 0b)
10389 +#endif
10390 +
10391 + "sets %1\n"
10392 : "+m" (l->a.counter), "=qm" (c)
10393 : "ir" (i) : "memory");
10394 return c;
10395 @@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
10396 #endif
10397 /* Modern 486+ processor */
10398 __i = i;
10399 - asm volatile(_ASM_XADD "%0, %1;"
10400 + asm volatile(_ASM_XADD "%0, %1\n"
10401 +
10402 +#ifdef CONFIG_PAX_REFCOUNT
10403 + "jno 0f\n"
10404 + _ASM_MOV "%0,%1\n"
10405 + "int $4\n0:\n"
10406 + _ASM_EXTABLE(0b, 0b)
10407 +#endif
10408 +
10409 : "+r" (i), "+m" (l->a.counter)
10410 : : "memory");
10411 return i + __i;
10412 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10413 index 593e51d..fa69c9a 100644
10414 --- a/arch/x86/include/asm/mman.h
10415 +++ b/arch/x86/include/asm/mman.h
10416 @@ -5,4 +5,14 @@
10417
10418 #include <asm-generic/mman.h>
10419
10420 +#ifdef __KERNEL__
10421 +#ifndef __ASSEMBLY__
10422 +#ifdef CONFIG_X86_32
10423 +#define arch_mmap_check i386_mmap_check
10424 +int i386_mmap_check(unsigned long addr, unsigned long len,
10425 + unsigned long flags);
10426 +#endif
10427 +#endif
10428 +#endif
10429 +
10430 #endif /* _ASM_X86_MMAN_H */
10431 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10432 index 5f55e69..e20bfb1 100644
10433 --- a/arch/x86/include/asm/mmu.h
10434 +++ b/arch/x86/include/asm/mmu.h
10435 @@ -9,7 +9,7 @@
10436 * we put the segment information here.
10437 */
10438 typedef struct {
10439 - void *ldt;
10440 + struct desc_struct *ldt;
10441 int size;
10442
10443 #ifdef CONFIG_X86_64
10444 @@ -18,7 +18,19 @@ typedef struct {
10445 #endif
10446
10447 struct mutex lock;
10448 - void *vdso;
10449 + unsigned long vdso;
10450 +
10451 +#ifdef CONFIG_X86_32
10452 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10453 + unsigned long user_cs_base;
10454 + unsigned long user_cs_limit;
10455 +
10456 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10457 + cpumask_t cpu_user_cs_mask;
10458 +#endif
10459 +
10460 +#endif
10461 +#endif
10462 } mm_context_t;
10463
10464 #ifdef CONFIG_SMP
10465 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10466 index 6902152..399f3a2 100644
10467 --- a/arch/x86/include/asm/mmu_context.h
10468 +++ b/arch/x86/include/asm/mmu_context.h
10469 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10470
10471 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10472 {
10473 +
10474 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10475 + unsigned int i;
10476 + pgd_t *pgd;
10477 +
10478 + pax_open_kernel();
10479 + pgd = get_cpu_pgd(smp_processor_id());
10480 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10481 + set_pgd_batched(pgd+i, native_make_pgd(0));
10482 + pax_close_kernel();
10483 +#endif
10484 +
10485 #ifdef CONFIG_SMP
10486 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10487 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10488 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10489 struct task_struct *tsk)
10490 {
10491 unsigned cpu = smp_processor_id();
10492 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10493 + int tlbstate = TLBSTATE_OK;
10494 +#endif
10495
10496 if (likely(prev != next)) {
10497 #ifdef CONFIG_SMP
10498 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10499 + tlbstate = percpu_read(cpu_tlbstate.state);
10500 +#endif
10501 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10502 percpu_write(cpu_tlbstate.active_mm, next);
10503 #endif
10504 cpumask_set_cpu(cpu, mm_cpumask(next));
10505
10506 /* Re-load page tables */
10507 +#ifdef CONFIG_PAX_PER_CPU_PGD
10508 + pax_open_kernel();
10509 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10510 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10511 + pax_close_kernel();
10512 + load_cr3(get_cpu_pgd(cpu));
10513 +#else
10514 load_cr3(next->pgd);
10515 +#endif
10516
10517 /* stop flush ipis for the previous mm */
10518 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10519 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10520 */
10521 if (unlikely(prev->context.ldt != next->context.ldt))
10522 load_LDT_nolock(&next->context);
10523 - }
10524 +
10525 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10526 + if (!(__supported_pte_mask & _PAGE_NX)) {
10527 + smp_mb__before_clear_bit();
10528 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10529 + smp_mb__after_clear_bit();
10530 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10531 + }
10532 +#endif
10533 +
10534 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10535 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10536 + prev->context.user_cs_limit != next->context.user_cs_limit))
10537 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10538 #ifdef CONFIG_SMP
10539 + else if (unlikely(tlbstate != TLBSTATE_OK))
10540 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10541 +#endif
10542 +#endif
10543 +
10544 + }
10545 else {
10546 +
10547 +#ifdef CONFIG_PAX_PER_CPU_PGD
10548 + pax_open_kernel();
10549 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10550 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10551 + pax_close_kernel();
10552 + load_cr3(get_cpu_pgd(cpu));
10553 +#endif
10554 +
10555 +#ifdef CONFIG_SMP
10556 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10557 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10558
10559 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10560 * tlb flush IPI delivery. We must reload CR3
10561 * to make sure to use no freed page tables.
10562 */
10563 +
10564 +#ifndef CONFIG_PAX_PER_CPU_PGD
10565 load_cr3(next->pgd);
10566 +#endif
10567 +
10568 load_LDT_nolock(&next->context);
10569 +
10570 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10571 + if (!(__supported_pte_mask & _PAGE_NX))
10572 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10573 +#endif
10574 +
10575 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10576 +#ifdef CONFIG_PAX_PAGEEXEC
10577 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10578 +#endif
10579 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10580 +#endif
10581 +
10582 }
10583 +#endif
10584 }
10585 -#endif
10586 }
10587
10588 #define activate_mm(prev, next) \
10589 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
10590 index 9eae775..c914fea 100644
10591 --- a/arch/x86/include/asm/module.h
10592 +++ b/arch/x86/include/asm/module.h
10593 @@ -5,6 +5,7 @@
10594
10595 #ifdef CONFIG_X86_64
10596 /* X86_64 does not define MODULE_PROC_FAMILY */
10597 +#define MODULE_PROC_FAMILY ""
10598 #elif defined CONFIG_M386
10599 #define MODULE_PROC_FAMILY "386 "
10600 #elif defined CONFIG_M486
10601 @@ -59,8 +60,20 @@
10602 #error unknown processor family
10603 #endif
10604
10605 -#ifdef CONFIG_X86_32
10606 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
10607 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10608 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
10609 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
10610 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
10611 +#else
10612 +#define MODULE_PAX_KERNEXEC ""
10613 #endif
10614
10615 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10616 +#define MODULE_PAX_UDEREF "UDEREF "
10617 +#else
10618 +#define MODULE_PAX_UDEREF ""
10619 +#endif
10620 +
10621 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
10622 +
10623 #endif /* _ASM_X86_MODULE_H */
10624 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
10625 index 7639dbf..e08a58c 100644
10626 --- a/arch/x86/include/asm/page_64_types.h
10627 +++ b/arch/x86/include/asm/page_64_types.h
10628 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10629
10630 /* duplicated to the one in bootmem.h */
10631 extern unsigned long max_pfn;
10632 -extern unsigned long phys_base;
10633 +extern const unsigned long phys_base;
10634
10635 extern unsigned long __phys_addr(unsigned long);
10636 #define __phys_reloc_hide(x) (x)
10637 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
10638 index a7d2db9..edb023e 100644
10639 --- a/arch/x86/include/asm/paravirt.h
10640 +++ b/arch/x86/include/asm/paravirt.h
10641 @@ -667,6 +667,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
10642 val);
10643 }
10644
10645 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
10646 +{
10647 + pgdval_t val = native_pgd_val(pgd);
10648 +
10649 + if (sizeof(pgdval_t) > sizeof(long))
10650 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
10651 + val, (u64)val >> 32);
10652 + else
10653 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
10654 + val);
10655 +}
10656 +
10657 static inline void pgd_clear(pgd_t *pgdp)
10658 {
10659 set_pgd(pgdp, __pgd(0));
10660 @@ -748,6 +760,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
10661 pv_mmu_ops.set_fixmap(idx, phys, flags);
10662 }
10663
10664 +#ifdef CONFIG_PAX_KERNEXEC
10665 +static inline unsigned long pax_open_kernel(void)
10666 +{
10667 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10668 +}
10669 +
10670 +static inline unsigned long pax_close_kernel(void)
10671 +{
10672 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10673 +}
10674 +#else
10675 +static inline unsigned long pax_open_kernel(void) { return 0; }
10676 +static inline unsigned long pax_close_kernel(void) { return 0; }
10677 +#endif
10678 +
10679 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10680
10681 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
10682 @@ -964,7 +991,7 @@ extern void default_banner(void);
10683
10684 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10685 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10686 -#define PARA_INDIRECT(addr) *%cs:addr
10687 +#define PARA_INDIRECT(addr) *%ss:addr
10688 #endif
10689
10690 #define INTERRUPT_RETURN \
10691 @@ -1041,6 +1068,21 @@ extern void default_banner(void);
10692 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
10693 CLBR_NONE, \
10694 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
10695 +
10696 +#define GET_CR0_INTO_RDI \
10697 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
10698 + mov %rax,%rdi
10699 +
10700 +#define SET_RDI_INTO_CR0 \
10701 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
10702 +
10703 +#define GET_CR3_INTO_RDI \
10704 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
10705 + mov %rax,%rdi
10706 +
10707 +#define SET_RDI_INTO_CR3 \
10708 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
10709 +
10710 #endif /* CONFIG_X86_32 */
10711
10712 #endif /* __ASSEMBLY__ */
10713 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
10714 index 8e8b9a4..f07d725 100644
10715 --- a/arch/x86/include/asm/paravirt_types.h
10716 +++ b/arch/x86/include/asm/paravirt_types.h
10717 @@ -84,20 +84,20 @@ struct pv_init_ops {
10718 */
10719 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
10720 unsigned long addr, unsigned len);
10721 -};
10722 +} __no_const;
10723
10724
10725 struct pv_lazy_ops {
10726 /* Set deferred update mode, used for batching operations. */
10727 void (*enter)(void);
10728 void (*leave)(void);
10729 -};
10730 +} __no_const;
10731
10732 struct pv_time_ops {
10733 unsigned long long (*sched_clock)(void);
10734 unsigned long long (*steal_clock)(int cpu);
10735 unsigned long (*get_tsc_khz)(void);
10736 -};
10737 +} __no_const;
10738
10739 struct pv_cpu_ops {
10740 /* hooks for various privileged instructions */
10741 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
10742
10743 void (*start_context_switch)(struct task_struct *prev);
10744 void (*end_context_switch)(struct task_struct *next);
10745 -};
10746 +} __no_const;
10747
10748 struct pv_irq_ops {
10749 /*
10750 @@ -224,7 +224,7 @@ struct pv_apic_ops {
10751 unsigned long start_eip,
10752 unsigned long start_esp);
10753 #endif
10754 -};
10755 +} __no_const;
10756
10757 struct pv_mmu_ops {
10758 unsigned long (*read_cr2)(void);
10759 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
10760 struct paravirt_callee_save make_pud;
10761
10762 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
10763 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
10764 #endif /* PAGETABLE_LEVELS == 4 */
10765 #endif /* PAGETABLE_LEVELS >= 3 */
10766
10767 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
10768 an mfn. We can tell which is which from the index. */
10769 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
10770 phys_addr_t phys, pgprot_t flags);
10771 +
10772 +#ifdef CONFIG_PAX_KERNEXEC
10773 + unsigned long (*pax_open_kernel)(void);
10774 + unsigned long (*pax_close_kernel)(void);
10775 +#endif
10776 +
10777 };
10778
10779 struct arch_spinlock;
10780 @@ -334,7 +341,7 @@ struct pv_lock_ops {
10781 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
10782 int (*spin_trylock)(struct arch_spinlock *lock);
10783 void (*spin_unlock)(struct arch_spinlock *lock);
10784 -};
10785 +} __no_const;
10786
10787 /* This contains all the paravirt structures: we get a convenient
10788 * number for each function using the offset which we use to indicate
10789 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
10790 index b4389a4..b7ff22c 100644
10791 --- a/arch/x86/include/asm/pgalloc.h
10792 +++ b/arch/x86/include/asm/pgalloc.h
10793 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
10794 pmd_t *pmd, pte_t *pte)
10795 {
10796 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10797 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
10798 +}
10799 +
10800 +static inline void pmd_populate_user(struct mm_struct *mm,
10801 + pmd_t *pmd, pte_t *pte)
10802 +{
10803 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10804 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
10805 }
10806
10807 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
10808 index 98391db..8f6984e 100644
10809 --- a/arch/x86/include/asm/pgtable-2level.h
10810 +++ b/arch/x86/include/asm/pgtable-2level.h
10811 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
10812
10813 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10814 {
10815 + pax_open_kernel();
10816 *pmdp = pmd;
10817 + pax_close_kernel();
10818 }
10819
10820 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10821 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
10822 index effff47..f9e4035 100644
10823 --- a/arch/x86/include/asm/pgtable-3level.h
10824 +++ b/arch/x86/include/asm/pgtable-3level.h
10825 @@ -38,12 +38,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10826
10827 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10828 {
10829 + pax_open_kernel();
10830 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
10831 + pax_close_kernel();
10832 }
10833
10834 static inline void native_set_pud(pud_t *pudp, pud_t pud)
10835 {
10836 + pax_open_kernel();
10837 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
10838 + pax_close_kernel();
10839 }
10840
10841 /*
10842 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
10843 index 18601c8..3d716d1 100644
10844 --- a/arch/x86/include/asm/pgtable.h
10845 +++ b/arch/x86/include/asm/pgtable.h
10846 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
10847
10848 #ifndef __PAGETABLE_PUD_FOLDED
10849 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
10850 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
10851 #define pgd_clear(pgd) native_pgd_clear(pgd)
10852 #endif
10853
10854 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
10855
10856 #define arch_end_context_switch(prev) do {} while(0)
10857
10858 +#define pax_open_kernel() native_pax_open_kernel()
10859 +#define pax_close_kernel() native_pax_close_kernel()
10860 #endif /* CONFIG_PARAVIRT */
10861
10862 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
10863 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
10864 +
10865 +#ifdef CONFIG_PAX_KERNEXEC
10866 +static inline unsigned long native_pax_open_kernel(void)
10867 +{
10868 + unsigned long cr0;
10869 +
10870 + preempt_disable();
10871 + barrier();
10872 + cr0 = read_cr0() ^ X86_CR0_WP;
10873 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
10874 + write_cr0(cr0);
10875 + return cr0 ^ X86_CR0_WP;
10876 +}
10877 +
10878 +static inline unsigned long native_pax_close_kernel(void)
10879 +{
10880 + unsigned long cr0;
10881 +
10882 + cr0 = read_cr0() ^ X86_CR0_WP;
10883 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
10884 + write_cr0(cr0);
10885 + barrier();
10886 + preempt_enable_no_resched();
10887 + return cr0 ^ X86_CR0_WP;
10888 +}
10889 +#else
10890 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
10891 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
10892 +#endif
10893 +
10894 /*
10895 * The following only work if pte_present() is true.
10896 * Undefined behaviour if not..
10897 */
10898 +static inline int pte_user(pte_t pte)
10899 +{
10900 + return pte_val(pte) & _PAGE_USER;
10901 +}
10902 +
10903 static inline int pte_dirty(pte_t pte)
10904 {
10905 return pte_flags(pte) & _PAGE_DIRTY;
10906 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
10907 return pte_clear_flags(pte, _PAGE_RW);
10908 }
10909
10910 +static inline pte_t pte_mkread(pte_t pte)
10911 +{
10912 + return __pte(pte_val(pte) | _PAGE_USER);
10913 +}
10914 +
10915 static inline pte_t pte_mkexec(pte_t pte)
10916 {
10917 - return pte_clear_flags(pte, _PAGE_NX);
10918 +#ifdef CONFIG_X86_PAE
10919 + if (__supported_pte_mask & _PAGE_NX)
10920 + return pte_clear_flags(pte, _PAGE_NX);
10921 + else
10922 +#endif
10923 + return pte_set_flags(pte, _PAGE_USER);
10924 +}
10925 +
10926 +static inline pte_t pte_exprotect(pte_t pte)
10927 +{
10928 +#ifdef CONFIG_X86_PAE
10929 + if (__supported_pte_mask & _PAGE_NX)
10930 + return pte_set_flags(pte, _PAGE_NX);
10931 + else
10932 +#endif
10933 + return pte_clear_flags(pte, _PAGE_USER);
10934 }
10935
10936 static inline pte_t pte_mkdirty(pte_t pte)
10937 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
10938 #endif
10939
10940 #ifndef __ASSEMBLY__
10941 +
10942 +#ifdef CONFIG_PAX_PER_CPU_PGD
10943 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
10944 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
10945 +{
10946 + return cpu_pgd[cpu];
10947 +}
10948 +#endif
10949 +
10950 #include <linux/mm_types.h>
10951
10952 static inline int pte_none(pte_t pte)
10953 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
10954
10955 static inline int pgd_bad(pgd_t pgd)
10956 {
10957 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
10958 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
10959 }
10960
10961 static inline int pgd_none(pgd_t pgd)
10962 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
10963 * pgd_offset() returns a (pgd_t *)
10964 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
10965 */
10966 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
10967 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
10968 +
10969 +#ifdef CONFIG_PAX_PER_CPU_PGD
10970 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
10971 +#endif
10972 +
10973 /*
10974 * a shortcut which implies the use of the kernel's pgd, instead
10975 * of a process's
10976 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
10977 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
10978 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
10979
10980 +#ifdef CONFIG_X86_32
10981 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
10982 +#else
10983 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
10984 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
10985 +
10986 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10987 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
10988 +#else
10989 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
10990 +#endif
10991 +
10992 +#endif
10993 +
10994 #ifndef __ASSEMBLY__
10995
10996 extern int direct_gbpages;
10997 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
10998 * dst and src can be on the same page, but the range must not overlap,
10999 * and must not cross a page boundary.
11000 */
11001 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11002 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11003 {
11004 - memcpy(dst, src, count * sizeof(pgd_t));
11005 + pax_open_kernel();
11006 + while (count--)
11007 + *dst++ = *src++;
11008 + pax_close_kernel();
11009 }
11010
11011 +#ifdef CONFIG_PAX_PER_CPU_PGD
11012 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11013 +#endif
11014 +
11015 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11016 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11017 +#else
11018 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
11019 +#endif
11020
11021 #include <asm-generic/pgtable.h>
11022 #endif /* __ASSEMBLY__ */
11023 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11024 index 0c92113..34a77c6 100644
11025 --- a/arch/x86/include/asm/pgtable_32.h
11026 +++ b/arch/x86/include/asm/pgtable_32.h
11027 @@ -25,9 +25,6 @@
11028 struct mm_struct;
11029 struct vm_area_struct;
11030
11031 -extern pgd_t swapper_pg_dir[1024];
11032 -extern pgd_t initial_page_table[1024];
11033 -
11034 static inline void pgtable_cache_init(void) { }
11035 static inline void check_pgt_cache(void) { }
11036 void paging_init(void);
11037 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11038 # include <asm/pgtable-2level.h>
11039 #endif
11040
11041 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11042 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11043 +#ifdef CONFIG_X86_PAE
11044 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11045 +#endif
11046 +
11047 #if defined(CONFIG_HIGHPTE)
11048 #define pte_offset_map(dir, address) \
11049 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11050 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11051 /* Clear a kernel PTE and flush it from the TLB */
11052 #define kpte_clear_flush(ptep, vaddr) \
11053 do { \
11054 + pax_open_kernel(); \
11055 pte_clear(&init_mm, (vaddr), (ptep)); \
11056 + pax_close_kernel(); \
11057 __flush_tlb_one((vaddr)); \
11058 } while (0)
11059
11060 @@ -74,6 +79,9 @@ do { \
11061
11062 #endif /* !__ASSEMBLY__ */
11063
11064 +#define HAVE_ARCH_UNMAPPED_AREA
11065 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11066 +
11067 /*
11068 * kern_addr_valid() is (1) for FLATMEM and (0) for
11069 * SPARSEMEM and DISCONTIGMEM
11070 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11071 index ed5903b..c7fe163 100644
11072 --- a/arch/x86/include/asm/pgtable_32_types.h
11073 +++ b/arch/x86/include/asm/pgtable_32_types.h
11074 @@ -8,7 +8,7 @@
11075 */
11076 #ifdef CONFIG_X86_PAE
11077 # include <asm/pgtable-3level_types.h>
11078 -# define PMD_SIZE (1UL << PMD_SHIFT)
11079 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11080 # define PMD_MASK (~(PMD_SIZE - 1))
11081 #else
11082 # include <asm/pgtable-2level_types.h>
11083 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11084 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11085 #endif
11086
11087 +#ifdef CONFIG_PAX_KERNEXEC
11088 +#ifndef __ASSEMBLY__
11089 +extern unsigned char MODULES_EXEC_VADDR[];
11090 +extern unsigned char MODULES_EXEC_END[];
11091 +#endif
11092 +#include <asm/boot.h>
11093 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11094 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11095 +#else
11096 +#define ktla_ktva(addr) (addr)
11097 +#define ktva_ktla(addr) (addr)
11098 +#endif
11099 +
11100 #define MODULES_VADDR VMALLOC_START
11101 #define MODULES_END VMALLOC_END
11102 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11103 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11104 index 975f709..107976d 100644
11105 --- a/arch/x86/include/asm/pgtable_64.h
11106 +++ b/arch/x86/include/asm/pgtable_64.h
11107 @@ -16,10 +16,14 @@
11108
11109 extern pud_t level3_kernel_pgt[512];
11110 extern pud_t level3_ident_pgt[512];
11111 +extern pud_t level3_vmalloc_start_pgt[512];
11112 +extern pud_t level3_vmalloc_end_pgt[512];
11113 +extern pud_t level3_vmemmap_pgt[512];
11114 +extern pud_t level2_vmemmap_pgt[512];
11115 extern pmd_t level2_kernel_pgt[512];
11116 extern pmd_t level2_fixmap_pgt[512];
11117 -extern pmd_t level2_ident_pgt[512];
11118 -extern pgd_t init_level4_pgt[];
11119 +extern pmd_t level2_ident_pgt[512*2];
11120 +extern pgd_t init_level4_pgt[512];
11121
11122 #define swapper_pg_dir init_level4_pgt
11123
11124 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11125
11126 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11127 {
11128 + pax_open_kernel();
11129 *pmdp = pmd;
11130 + pax_close_kernel();
11131 }
11132
11133 static inline void native_pmd_clear(pmd_t *pmd)
11134 @@ -107,6 +113,13 @@ static inline void native_pud_clear(pud_t *pud)
11135
11136 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11137 {
11138 + pax_open_kernel();
11139 + *pgdp = pgd;
11140 + pax_close_kernel();
11141 +}
11142 +
11143 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11144 +{
11145 *pgdp = pgd;
11146 }
11147
11148 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11149 index 766ea16..5b96cb3 100644
11150 --- a/arch/x86/include/asm/pgtable_64_types.h
11151 +++ b/arch/x86/include/asm/pgtable_64_types.h
11152 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11153 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11154 #define MODULES_END _AC(0xffffffffff000000, UL)
11155 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11156 +#define MODULES_EXEC_VADDR MODULES_VADDR
11157 +#define MODULES_EXEC_END MODULES_END
11158 +
11159 +#define ktla_ktva(addr) (addr)
11160 +#define ktva_ktla(addr) (addr)
11161
11162 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11163 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11164 index 013286a..8b42f4f 100644
11165 --- a/arch/x86/include/asm/pgtable_types.h
11166 +++ b/arch/x86/include/asm/pgtable_types.h
11167 @@ -16,13 +16,12 @@
11168 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11169 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11170 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11171 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11172 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11173 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11174 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11175 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11176 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11177 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11178 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11179 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11180 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11181 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11182
11183 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11184 @@ -40,7 +39,6 @@
11185 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11186 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11187 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11188 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11189 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11190 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11191 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11192 @@ -57,8 +55,10 @@
11193
11194 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11195 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11196 -#else
11197 +#elif defined(CONFIG_KMEMCHECK)
11198 #define _PAGE_NX (_AT(pteval_t, 0))
11199 +#else
11200 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11201 #endif
11202
11203 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11204 @@ -96,6 +96,9 @@
11205 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11206 _PAGE_ACCESSED)
11207
11208 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11209 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11210 +
11211 #define __PAGE_KERNEL_EXEC \
11212 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11213 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11214 @@ -106,7 +109,7 @@
11215 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11216 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11217 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11218 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11219 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11220 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11221 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11222 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11223 @@ -168,8 +171,8 @@
11224 * bits are combined, this will alow user to access the high address mapped
11225 * VDSO in the presence of CONFIG_COMPAT_VDSO
11226 */
11227 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11228 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11229 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11230 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11231 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11232 #endif
11233
11234 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11235 {
11236 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11237 }
11238 +#endif
11239
11240 +#if PAGETABLE_LEVELS == 3
11241 +#include <asm-generic/pgtable-nopud.h>
11242 +#endif
11243 +
11244 +#if PAGETABLE_LEVELS == 2
11245 +#include <asm-generic/pgtable-nopmd.h>
11246 +#endif
11247 +
11248 +#ifndef __ASSEMBLY__
11249 #if PAGETABLE_LEVELS > 3
11250 typedef struct { pudval_t pud; } pud_t;
11251
11252 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11253 return pud.pud;
11254 }
11255 #else
11256 -#include <asm-generic/pgtable-nopud.h>
11257 -
11258 static inline pudval_t native_pud_val(pud_t pud)
11259 {
11260 return native_pgd_val(pud.pgd);
11261 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11262 return pmd.pmd;
11263 }
11264 #else
11265 -#include <asm-generic/pgtable-nopmd.h>
11266 -
11267 static inline pmdval_t native_pmd_val(pmd_t pmd)
11268 {
11269 return native_pgd_val(pmd.pud.pgd);
11270 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11271
11272 extern pteval_t __supported_pte_mask;
11273 extern void set_nx(void);
11274 -extern int nx_enabled;
11275
11276 #define pgprot_writecombine pgprot_writecombine
11277 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11278 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11279 index bb3ee36..781a6b8 100644
11280 --- a/arch/x86/include/asm/processor.h
11281 +++ b/arch/x86/include/asm/processor.h
11282 @@ -268,7 +268,7 @@ struct tss_struct {
11283
11284 } ____cacheline_aligned;
11285
11286 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11287 +extern struct tss_struct init_tss[NR_CPUS];
11288
11289 /*
11290 * Save the original ist values for checking stack pointers during debugging
11291 @@ -861,11 +861,18 @@ static inline void spin_lock_prefetch(const void *x)
11292 */
11293 #define TASK_SIZE PAGE_OFFSET
11294 #define TASK_SIZE_MAX TASK_SIZE
11295 +
11296 +#ifdef CONFIG_PAX_SEGMEXEC
11297 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11298 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11299 +#else
11300 #define STACK_TOP TASK_SIZE
11301 -#define STACK_TOP_MAX STACK_TOP
11302 +#endif
11303 +
11304 +#define STACK_TOP_MAX TASK_SIZE
11305
11306 #define INIT_THREAD { \
11307 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11308 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11309 .vm86_info = NULL, \
11310 .sysenter_cs = __KERNEL_CS, \
11311 .io_bitmap_ptr = NULL, \
11312 @@ -879,7 +886,7 @@ static inline void spin_lock_prefetch(const void *x)
11313 */
11314 #define INIT_TSS { \
11315 .x86_tss = { \
11316 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11317 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11318 .ss0 = __KERNEL_DS, \
11319 .ss1 = __KERNEL_CS, \
11320 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11321 @@ -890,11 +897,7 @@ static inline void spin_lock_prefetch(const void *x)
11322 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11323
11324 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11325 -#define KSTK_TOP(info) \
11326 -({ \
11327 - unsigned long *__ptr = (unsigned long *)(info); \
11328 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11329 -})
11330 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11331
11332 /*
11333 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11334 @@ -909,7 +912,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11335 #define task_pt_regs(task) \
11336 ({ \
11337 struct pt_regs *__regs__; \
11338 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11339 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11340 __regs__ - 1; \
11341 })
11342
11343 @@ -919,13 +922,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11344 /*
11345 * User space process size. 47bits minus one guard page.
11346 */
11347 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11348 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11349
11350 /* This decides where the kernel will search for a free chunk of vm
11351 * space during mmap's.
11352 */
11353 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11354 - 0xc0000000 : 0xFFFFe000)
11355 + 0xc0000000 : 0xFFFFf000)
11356
11357 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
11358 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11359 @@ -936,11 +939,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11360 #define STACK_TOP_MAX TASK_SIZE_MAX
11361
11362 #define INIT_THREAD { \
11363 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11364 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11365 }
11366
11367 #define INIT_TSS { \
11368 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11369 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11370 }
11371
11372 /*
11373 @@ -962,6 +965,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11374 */
11375 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11376
11377 +#ifdef CONFIG_PAX_SEGMEXEC
11378 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11379 +#endif
11380 +
11381 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11382
11383 /* Get/set a process' ability to use the timestamp counter instruction */
11384 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11385 index 3566454..4bdfb8c 100644
11386 --- a/arch/x86/include/asm/ptrace.h
11387 +++ b/arch/x86/include/asm/ptrace.h
11388 @@ -156,28 +156,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11389 }
11390
11391 /*
11392 - * user_mode_vm(regs) determines whether a register set came from user mode.
11393 + * user_mode(regs) determines whether a register set came from user mode.
11394 * This is true if V8086 mode was enabled OR if the register set was from
11395 * protected mode with RPL-3 CS value. This tricky test checks that with
11396 * one comparison. Many places in the kernel can bypass this full check
11397 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11398 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11399 + * be used.
11400 */
11401 -static inline int user_mode(struct pt_regs *regs)
11402 +static inline int user_mode_novm(struct pt_regs *regs)
11403 {
11404 #ifdef CONFIG_X86_32
11405 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11406 #else
11407 - return !!(regs->cs & 3);
11408 + return !!(regs->cs & SEGMENT_RPL_MASK);
11409 #endif
11410 }
11411
11412 -static inline int user_mode_vm(struct pt_regs *regs)
11413 +static inline int user_mode(struct pt_regs *regs)
11414 {
11415 #ifdef CONFIG_X86_32
11416 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11417 USER_RPL;
11418 #else
11419 - return user_mode(regs);
11420 + return user_mode_novm(regs);
11421 #endif
11422 }
11423
11424 @@ -193,15 +194,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11425 #ifdef CONFIG_X86_64
11426 static inline bool user_64bit_mode(struct pt_regs *regs)
11427 {
11428 + unsigned long cs = regs->cs & 0xffff;
11429 #ifndef CONFIG_PARAVIRT
11430 /*
11431 * On non-paravirt systems, this is the only long mode CPL 3
11432 * selector. We do not allow long mode selectors in the LDT.
11433 */
11434 - return regs->cs == __USER_CS;
11435 + return cs == __USER_CS;
11436 #else
11437 /* Headers are too twisted for this to go in paravirt.h. */
11438 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11439 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11440 #endif
11441 }
11442 #endif
11443 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11444 index 92f29706..a79cbbb 100644
11445 --- a/arch/x86/include/asm/reboot.h
11446 +++ b/arch/x86/include/asm/reboot.h
11447 @@ -6,19 +6,19 @@
11448 struct pt_regs;
11449
11450 struct machine_ops {
11451 - void (*restart)(char *cmd);
11452 - void (*halt)(void);
11453 - void (*power_off)(void);
11454 + void (* __noreturn restart)(char *cmd);
11455 + void (* __noreturn halt)(void);
11456 + void (* __noreturn power_off)(void);
11457 void (*shutdown)(void);
11458 void (*crash_shutdown)(struct pt_regs *);
11459 - void (*emergency_restart)(void);
11460 -};
11461 + void (* __noreturn emergency_restart)(void);
11462 +} __no_const;
11463
11464 extern struct machine_ops machine_ops;
11465
11466 void native_machine_crash_shutdown(struct pt_regs *regs);
11467 void native_machine_shutdown(void);
11468 -void machine_real_restart(unsigned int type);
11469 +void machine_real_restart(unsigned int type) __noreturn;
11470 /* These must match dispatch_table in reboot_32.S */
11471 #define MRR_BIOS 0
11472 #define MRR_APM 1
11473 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11474 index 2dbe4a7..ce1db00 100644
11475 --- a/arch/x86/include/asm/rwsem.h
11476 +++ b/arch/x86/include/asm/rwsem.h
11477 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11478 {
11479 asm volatile("# beginning down_read\n\t"
11480 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11481 +
11482 +#ifdef CONFIG_PAX_REFCOUNT
11483 + "jno 0f\n"
11484 + LOCK_PREFIX _ASM_DEC "(%1)\n"
11485 + "int $4\n0:\n"
11486 + _ASM_EXTABLE(0b, 0b)
11487 +#endif
11488 +
11489 /* adds 0x00000001 */
11490 " jns 1f\n"
11491 " call call_rwsem_down_read_failed\n"
11492 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11493 "1:\n\t"
11494 " mov %1,%2\n\t"
11495 " add %3,%2\n\t"
11496 +
11497 +#ifdef CONFIG_PAX_REFCOUNT
11498 + "jno 0f\n"
11499 + "sub %3,%2\n"
11500 + "int $4\n0:\n"
11501 + _ASM_EXTABLE(0b, 0b)
11502 +#endif
11503 +
11504 " jle 2f\n\t"
11505 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11506 " jnz 1b\n\t"
11507 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
11508 long tmp;
11509 asm volatile("# beginning down_write\n\t"
11510 LOCK_PREFIX " xadd %1,(%2)\n\t"
11511 +
11512 +#ifdef CONFIG_PAX_REFCOUNT
11513 + "jno 0f\n"
11514 + "mov %1,(%2)\n"
11515 + "int $4\n0:\n"
11516 + _ASM_EXTABLE(0b, 0b)
11517 +#endif
11518 +
11519 /* adds 0xffff0001, returns the old value */
11520 " test %1,%1\n\t"
11521 /* was the count 0 before? */
11522 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
11523 long tmp;
11524 asm volatile("# beginning __up_read\n\t"
11525 LOCK_PREFIX " xadd %1,(%2)\n\t"
11526 +
11527 +#ifdef CONFIG_PAX_REFCOUNT
11528 + "jno 0f\n"
11529 + "mov %1,(%2)\n"
11530 + "int $4\n0:\n"
11531 + _ASM_EXTABLE(0b, 0b)
11532 +#endif
11533 +
11534 /* subtracts 1, returns the old value */
11535 " jns 1f\n\t"
11536 " call call_rwsem_wake\n" /* expects old value in %edx */
11537 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
11538 long tmp;
11539 asm volatile("# beginning __up_write\n\t"
11540 LOCK_PREFIX " xadd %1,(%2)\n\t"
11541 +
11542 +#ifdef CONFIG_PAX_REFCOUNT
11543 + "jno 0f\n"
11544 + "mov %1,(%2)\n"
11545 + "int $4\n0:\n"
11546 + _ASM_EXTABLE(0b, 0b)
11547 +#endif
11548 +
11549 /* subtracts 0xffff0001, returns the old value */
11550 " jns 1f\n\t"
11551 " call call_rwsem_wake\n" /* expects old value in %edx */
11552 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11553 {
11554 asm volatile("# beginning __downgrade_write\n\t"
11555 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
11556 +
11557 +#ifdef CONFIG_PAX_REFCOUNT
11558 + "jno 0f\n"
11559 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11560 + "int $4\n0:\n"
11561 + _ASM_EXTABLE(0b, 0b)
11562 +#endif
11563 +
11564 /*
11565 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11566 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11567 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11568 */
11569 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11570 {
11571 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11572 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11573 +
11574 +#ifdef CONFIG_PAX_REFCOUNT
11575 + "jno 0f\n"
11576 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
11577 + "int $4\n0:\n"
11578 + _ASM_EXTABLE(0b, 0b)
11579 +#endif
11580 +
11581 : "+m" (sem->count)
11582 : "er" (delta));
11583 }
11584 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11585 */
11586 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
11587 {
11588 - return delta + xadd(&sem->count, delta);
11589 + return delta + xadd_check_overflow(&sem->count, delta);
11590 }
11591
11592 #endif /* __KERNEL__ */
11593 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
11594 index 5e64171..f58957e 100644
11595 --- a/arch/x86/include/asm/segment.h
11596 +++ b/arch/x86/include/asm/segment.h
11597 @@ -64,10 +64,15 @@
11598 * 26 - ESPFIX small SS
11599 * 27 - per-cpu [ offset to per-cpu data area ]
11600 * 28 - stack_canary-20 [ for stack protector ]
11601 - * 29 - unused
11602 - * 30 - unused
11603 + * 29 - PCI BIOS CS
11604 + * 30 - PCI BIOS DS
11605 * 31 - TSS for double fault handler
11606 */
11607 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
11608 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
11609 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
11610 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
11611 +
11612 #define GDT_ENTRY_TLS_MIN 6
11613 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
11614
11615 @@ -79,6 +84,8 @@
11616
11617 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
11618
11619 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
11620 +
11621 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
11622
11623 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
11624 @@ -104,6 +111,12 @@
11625 #define __KERNEL_STACK_CANARY 0
11626 #endif
11627
11628 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
11629 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
11630 +
11631 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
11632 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
11633 +
11634 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
11635
11636 /*
11637 @@ -141,7 +154,7 @@
11638 */
11639
11640 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
11641 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
11642 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
11643
11644
11645 #else
11646 @@ -165,6 +178,8 @@
11647 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
11648 #define __USER32_DS __USER_DS
11649
11650 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
11651 +
11652 #define GDT_ENTRY_TSS 8 /* needs two entries */
11653 #define GDT_ENTRY_LDT 10 /* needs two entries */
11654 #define GDT_ENTRY_TLS_MIN 12
11655 @@ -185,6 +200,7 @@
11656 #endif
11657
11658 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
11659 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
11660 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
11661 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
11662 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
11663 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
11664 index 73b11bc..d4a3b63 100644
11665 --- a/arch/x86/include/asm/smp.h
11666 +++ b/arch/x86/include/asm/smp.h
11667 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
11668 /* cpus sharing the last level cache: */
11669 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
11670 DECLARE_PER_CPU(u16, cpu_llc_id);
11671 -DECLARE_PER_CPU(int, cpu_number);
11672 +DECLARE_PER_CPU(unsigned int, cpu_number);
11673
11674 static inline struct cpumask *cpu_sibling_mask(int cpu)
11675 {
11676 @@ -77,7 +77,7 @@ struct smp_ops {
11677
11678 void (*send_call_func_ipi)(const struct cpumask *mask);
11679 void (*send_call_func_single_ipi)(int cpu);
11680 -};
11681 +} __no_const;
11682
11683 /* Globals due to paravirt */
11684 extern void set_cpu_sibling_map(int cpu);
11685 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
11686 extern int safe_smp_processor_id(void);
11687
11688 #elif defined(CONFIG_X86_64_SMP)
11689 -#define raw_smp_processor_id() (percpu_read(cpu_number))
11690 -
11691 -#define stack_smp_processor_id() \
11692 -({ \
11693 - struct thread_info *ti; \
11694 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
11695 - ti->cpu; \
11696 -})
11697 +#define raw_smp_processor_id() (percpu_read(cpu_number))
11698 +#define stack_smp_processor_id() raw_smp_processor_id()
11699 #define safe_smp_processor_id() smp_processor_id()
11700
11701 #endif
11702 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
11703 index 972c260..43ab1fd 100644
11704 --- a/arch/x86/include/asm/spinlock.h
11705 +++ b/arch/x86/include/asm/spinlock.h
11706 @@ -188,6 +188,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
11707 static inline void arch_read_lock(arch_rwlock_t *rw)
11708 {
11709 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
11710 +
11711 +#ifdef CONFIG_PAX_REFCOUNT
11712 + "jno 0f\n"
11713 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
11714 + "int $4\n0:\n"
11715 + _ASM_EXTABLE(0b, 0b)
11716 +#endif
11717 +
11718 "jns 1f\n"
11719 "call __read_lock_failed\n\t"
11720 "1:\n"
11721 @@ -197,6 +205,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
11722 static inline void arch_write_lock(arch_rwlock_t *rw)
11723 {
11724 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
11725 +
11726 +#ifdef CONFIG_PAX_REFCOUNT
11727 + "jno 0f\n"
11728 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
11729 + "int $4\n0:\n"
11730 + _ASM_EXTABLE(0b, 0b)
11731 +#endif
11732 +
11733 "jz 1f\n"
11734 "call __write_lock_failed\n\t"
11735 "1:\n"
11736 @@ -226,13 +242,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
11737
11738 static inline void arch_read_unlock(arch_rwlock_t *rw)
11739 {
11740 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
11741 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
11742 +
11743 +#ifdef CONFIG_PAX_REFCOUNT
11744 + "jno 0f\n"
11745 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
11746 + "int $4\n0:\n"
11747 + _ASM_EXTABLE(0b, 0b)
11748 +#endif
11749 +
11750 :"+m" (rw->lock) : : "memory");
11751 }
11752
11753 static inline void arch_write_unlock(arch_rwlock_t *rw)
11754 {
11755 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
11756 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
11757 +
11758 +#ifdef CONFIG_PAX_REFCOUNT
11759 + "jno 0f\n"
11760 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
11761 + "int $4\n0:\n"
11762 + _ASM_EXTABLE(0b, 0b)
11763 +#endif
11764 +
11765 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
11766 }
11767
11768 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
11769 index 1575177..cb23f52 100644
11770 --- a/arch/x86/include/asm/stackprotector.h
11771 +++ b/arch/x86/include/asm/stackprotector.h
11772 @@ -48,7 +48,7 @@
11773 * head_32 for boot CPU and setup_per_cpu_areas() for others.
11774 */
11775 #define GDT_STACK_CANARY_INIT \
11776 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
11777 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
11778
11779 /*
11780 * Initialize the stackprotector canary value.
11781 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
11782
11783 static inline void load_stack_canary_segment(void)
11784 {
11785 -#ifdef CONFIG_X86_32
11786 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
11787 asm volatile ("mov %0, %%gs" : : "r" (0));
11788 #endif
11789 }
11790 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
11791 index 70bbe39..4ae2bd4 100644
11792 --- a/arch/x86/include/asm/stacktrace.h
11793 +++ b/arch/x86/include/asm/stacktrace.h
11794 @@ -11,28 +11,20 @@
11795
11796 extern int kstack_depth_to_print;
11797
11798 -struct thread_info;
11799 +struct task_struct;
11800 struct stacktrace_ops;
11801
11802 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
11803 - unsigned long *stack,
11804 - unsigned long bp,
11805 - const struct stacktrace_ops *ops,
11806 - void *data,
11807 - unsigned long *end,
11808 - int *graph);
11809 +typedef unsigned long walk_stack_t(struct task_struct *task,
11810 + void *stack_start,
11811 + unsigned long *stack,
11812 + unsigned long bp,
11813 + const struct stacktrace_ops *ops,
11814 + void *data,
11815 + unsigned long *end,
11816 + int *graph);
11817
11818 -extern unsigned long
11819 -print_context_stack(struct thread_info *tinfo,
11820 - unsigned long *stack, unsigned long bp,
11821 - const struct stacktrace_ops *ops, void *data,
11822 - unsigned long *end, int *graph);
11823 -
11824 -extern unsigned long
11825 -print_context_stack_bp(struct thread_info *tinfo,
11826 - unsigned long *stack, unsigned long bp,
11827 - const struct stacktrace_ops *ops, void *data,
11828 - unsigned long *end, int *graph);
11829 +extern walk_stack_t print_context_stack;
11830 +extern walk_stack_t print_context_stack_bp;
11831
11832 /* Generic stack tracer with callbacks */
11833
11834 @@ -40,7 +32,7 @@ struct stacktrace_ops {
11835 void (*address)(void *data, unsigned long address, int reliable);
11836 /* On negative return stop dumping */
11837 int (*stack)(void *data, char *name);
11838 - walk_stack_t walk_stack;
11839 + walk_stack_t *walk_stack;
11840 };
11841
11842 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
11843 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
11844 index cb23852..2dde194 100644
11845 --- a/arch/x86/include/asm/sys_ia32.h
11846 +++ b/arch/x86/include/asm/sys_ia32.h
11847 @@ -40,7 +40,7 @@ asmlinkage long sys32_rt_sigprocmask(int, compat_sigset_t __user *,
11848 compat_sigset_t __user *, unsigned int);
11849 asmlinkage long sys32_alarm(unsigned int);
11850
11851 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
11852 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
11853 asmlinkage long sys32_sysfs(int, u32, u32);
11854
11855 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
11856 diff --git a/arch/x86/include/asm/syscalls.h b/arch/x86/include/asm/syscalls.h
11857 index f1d8b44..a4de8b7 100644
11858 --- a/arch/x86/include/asm/syscalls.h
11859 +++ b/arch/x86/include/asm/syscalls.h
11860 @@ -30,7 +30,7 @@ long sys_clone(unsigned long, unsigned long, void __user *,
11861 void __user *, struct pt_regs *);
11862
11863 /* kernel/ldt.c */
11864 -asmlinkage int sys_modify_ldt(int, void __user *, unsigned long);
11865 +asmlinkage int sys_modify_ldt(int, void __user *, unsigned long) __size_overflow(3);
11866
11867 /* kernel/signal.c */
11868 long sys_rt_sigreturn(struct pt_regs *);
11869 diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
11870 index 2d2f01c..f985723 100644
11871 --- a/arch/x86/include/asm/system.h
11872 +++ b/arch/x86/include/asm/system.h
11873 @@ -129,7 +129,7 @@ do { \
11874 "call __switch_to\n\t" \
11875 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
11876 __switch_canary \
11877 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
11878 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
11879 "movq %%rax,%%rdi\n\t" \
11880 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
11881 "jnz ret_from_fork\n\t" \
11882 @@ -140,7 +140,7 @@ do { \
11883 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
11884 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
11885 [_tif_fork] "i" (_TIF_FORK), \
11886 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
11887 + [thread_info] "m" (current_tinfo), \
11888 [current_task] "m" (current_task) \
11889 __switch_canary_iparam \
11890 : "memory", "cc" __EXTRA_CLOBBER)
11891 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
11892 {
11893 unsigned long __limit;
11894 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
11895 - return __limit + 1;
11896 + return __limit;
11897 }
11898
11899 static inline void native_clts(void)
11900 @@ -397,13 +397,13 @@ void enable_hlt(void);
11901
11902 void cpu_idle_wait(void);
11903
11904 -extern unsigned long arch_align_stack(unsigned long sp);
11905 +#define arch_align_stack(x) ((x) & ~0xfUL)
11906 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11907
11908 void default_idle(void);
11909 bool set_pm_idle_to_default(void);
11910
11911 -void stop_this_cpu(void *dummy);
11912 +void stop_this_cpu(void *dummy) __noreturn;
11913
11914 /*
11915 * Force strict CPU ordering.
11916 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
11917 index d7ef849..6af292e 100644
11918 --- a/arch/x86/include/asm/thread_info.h
11919 +++ b/arch/x86/include/asm/thread_info.h
11920 @@ -10,6 +10,7 @@
11921 #include <linux/compiler.h>
11922 #include <asm/page.h>
11923 #include <asm/types.h>
11924 +#include <asm/percpu.h>
11925
11926 /*
11927 * low level task data that entry.S needs immediate access to
11928 @@ -24,7 +25,6 @@ struct exec_domain;
11929 #include <linux/atomic.h>
11930
11931 struct thread_info {
11932 - struct task_struct *task; /* main task structure */
11933 struct exec_domain *exec_domain; /* execution domain */
11934 __u32 flags; /* low level flags */
11935 __u32 status; /* thread synchronous flags */
11936 @@ -34,18 +34,12 @@ struct thread_info {
11937 mm_segment_t addr_limit;
11938 struct restart_block restart_block;
11939 void __user *sysenter_return;
11940 -#ifdef CONFIG_X86_32
11941 - unsigned long previous_esp; /* ESP of the previous stack in
11942 - case of nested (IRQ) stacks
11943 - */
11944 - __u8 supervisor_stack[0];
11945 -#endif
11946 + unsigned long lowest_stack;
11947 int uaccess_err;
11948 };
11949
11950 -#define INIT_THREAD_INFO(tsk) \
11951 +#define INIT_THREAD_INFO \
11952 { \
11953 - .task = &tsk, \
11954 .exec_domain = &default_exec_domain, \
11955 .flags = 0, \
11956 .cpu = 0, \
11957 @@ -56,7 +50,7 @@ struct thread_info {
11958 }, \
11959 }
11960
11961 -#define init_thread_info (init_thread_union.thread_info)
11962 +#define init_thread_info (init_thread_union.stack)
11963 #define init_stack (init_thread_union.stack)
11964
11965 #else /* !__ASSEMBLY__ */
11966 @@ -170,45 +164,40 @@ struct thread_info {
11967 ret; \
11968 })
11969
11970 -#ifdef CONFIG_X86_32
11971 -
11972 -#define STACK_WARN (THREAD_SIZE/8)
11973 -/*
11974 - * macros/functions for gaining access to the thread information structure
11975 - *
11976 - * preempt_count needs to be 1 initially, until the scheduler is functional.
11977 - */
11978 -#ifndef __ASSEMBLY__
11979 -
11980 -
11981 -/* how to get the current stack pointer from C */
11982 -register unsigned long current_stack_pointer asm("esp") __used;
11983 -
11984 -/* how to get the thread information struct from C */
11985 -static inline struct thread_info *current_thread_info(void)
11986 -{
11987 - return (struct thread_info *)
11988 - (current_stack_pointer & ~(THREAD_SIZE - 1));
11989 -}
11990 -
11991 -#else /* !__ASSEMBLY__ */
11992 -
11993 +#ifdef __ASSEMBLY__
11994 /* how to get the thread information struct from ASM */
11995 #define GET_THREAD_INFO(reg) \
11996 - movl $-THREAD_SIZE, reg; \
11997 - andl %esp, reg
11998 + mov PER_CPU_VAR(current_tinfo), reg
11999
12000 /* use this one if reg already contains %esp */
12001 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12002 - andl $-THREAD_SIZE, reg
12003 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12004 +#else
12005 +/* how to get the thread information struct from C */
12006 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12007 +
12008 +static __always_inline struct thread_info *current_thread_info(void)
12009 +{
12010 + return percpu_read_stable(current_tinfo);
12011 +}
12012 +#endif
12013 +
12014 +#ifdef CONFIG_X86_32
12015 +
12016 +#define STACK_WARN (THREAD_SIZE/8)
12017 +/*
12018 + * macros/functions for gaining access to the thread information structure
12019 + *
12020 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12021 + */
12022 +#ifndef __ASSEMBLY__
12023 +
12024 +/* how to get the current stack pointer from C */
12025 +register unsigned long current_stack_pointer asm("esp") __used;
12026
12027 #endif
12028
12029 #else /* X86_32 */
12030
12031 -#include <asm/percpu.h>
12032 -#define KERNEL_STACK_OFFSET (5*8)
12033 -
12034 /*
12035 * macros/functions for gaining access to the thread information structure
12036 * preempt_count needs to be 1 initially, until the scheduler is functional.
12037 @@ -216,21 +205,8 @@ static inline struct thread_info *current_thread_info(void)
12038 #ifndef __ASSEMBLY__
12039 DECLARE_PER_CPU(unsigned long, kernel_stack);
12040
12041 -static inline struct thread_info *current_thread_info(void)
12042 -{
12043 - struct thread_info *ti;
12044 - ti = (void *)(percpu_read_stable(kernel_stack) +
12045 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12046 - return ti;
12047 -}
12048 -
12049 -#else /* !__ASSEMBLY__ */
12050 -
12051 -/* how to get the thread information struct from ASM */
12052 -#define GET_THREAD_INFO(reg) \
12053 - movq PER_CPU_VAR(kernel_stack),reg ; \
12054 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12055 -
12056 +/* how to get the current stack pointer from C */
12057 +register unsigned long current_stack_pointer asm("rsp") __used;
12058 #endif
12059
12060 #endif /* !X86_32 */
12061 @@ -264,5 +240,16 @@ extern void arch_task_cache_init(void);
12062 extern void free_thread_info(struct thread_info *ti);
12063 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12064 #define arch_task_cache_init arch_task_cache_init
12065 +
12066 +#define __HAVE_THREAD_FUNCTIONS
12067 +#define task_thread_info(task) (&(task)->tinfo)
12068 +#define task_stack_page(task) ((task)->stack)
12069 +#define setup_thread_stack(p, org) do {} while (0)
12070 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12071 +
12072 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12073 +extern struct task_struct *alloc_task_struct_node(int node);
12074 +extern void free_task_struct(struct task_struct *);
12075 +
12076 #endif
12077 #endif /* _ASM_X86_THREAD_INFO_H */
12078 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12079 index 36361bf..324f262 100644
12080 --- a/arch/x86/include/asm/uaccess.h
12081 +++ b/arch/x86/include/asm/uaccess.h
12082 @@ -7,12 +7,15 @@
12083 #include <linux/compiler.h>
12084 #include <linux/thread_info.h>
12085 #include <linux/string.h>
12086 +#include <linux/sched.h>
12087 #include <asm/asm.h>
12088 #include <asm/page.h>
12089
12090 #define VERIFY_READ 0
12091 #define VERIFY_WRITE 1
12092
12093 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12094 +
12095 /*
12096 * The fs value determines whether argument validity checking should be
12097 * performed or not. If get_fs() == USER_DS, checking is performed, with
12098 @@ -28,7 +31,12 @@
12099
12100 #define get_ds() (KERNEL_DS)
12101 #define get_fs() (current_thread_info()->addr_limit)
12102 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12103 +void __set_fs(mm_segment_t x);
12104 +void set_fs(mm_segment_t x);
12105 +#else
12106 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12107 +#endif
12108
12109 #define segment_eq(a, b) ((a).seg == (b).seg)
12110
12111 @@ -76,7 +84,33 @@
12112 * checks that the pointer is in the user space range - after calling
12113 * this function, memory access functions may still return -EFAULT.
12114 */
12115 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12116 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12117 +#define access_ok(type, addr, size) \
12118 +({ \
12119 + long __size = size; \
12120 + unsigned long __addr = (unsigned long)addr; \
12121 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12122 + unsigned long __end_ao = __addr + __size - 1; \
12123 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12124 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12125 + while(__addr_ao <= __end_ao) { \
12126 + char __c_ao; \
12127 + __addr_ao += PAGE_SIZE; \
12128 + if (__size > PAGE_SIZE) \
12129 + cond_resched(); \
12130 + if (__get_user(__c_ao, (char __user *)__addr)) \
12131 + break; \
12132 + if (type != VERIFY_WRITE) { \
12133 + __addr = __addr_ao; \
12134 + continue; \
12135 + } \
12136 + if (__put_user(__c_ao, (char __user *)__addr)) \
12137 + break; \
12138 + __addr = __addr_ao; \
12139 + } \
12140 + } \
12141 + __ret_ao; \
12142 +})
12143
12144 /*
12145 * The exception table consists of pairs of addresses: the first is the
12146 @@ -182,12 +216,20 @@ extern int __get_user_bad(void);
12147 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12148 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12149
12150 -
12151 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12152 +#define __copyuser_seg "gs;"
12153 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12154 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12155 +#else
12156 +#define __copyuser_seg
12157 +#define __COPYUSER_SET_ES
12158 +#define __COPYUSER_RESTORE_ES
12159 +#endif
12160
12161 #ifdef CONFIG_X86_32
12162 #define __put_user_asm_u64(x, addr, err, errret) \
12163 - asm volatile("1: movl %%eax,0(%2)\n" \
12164 - "2: movl %%edx,4(%2)\n" \
12165 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12166 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12167 "3:\n" \
12168 ".section .fixup,\"ax\"\n" \
12169 "4: movl %3,%0\n" \
12170 @@ -199,8 +241,8 @@ extern int __get_user_bad(void);
12171 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12172
12173 #define __put_user_asm_ex_u64(x, addr) \
12174 - asm volatile("1: movl %%eax,0(%1)\n" \
12175 - "2: movl %%edx,4(%1)\n" \
12176 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12177 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12178 "3:\n" \
12179 _ASM_EXTABLE(1b, 2b - 1b) \
12180 _ASM_EXTABLE(2b, 3b - 2b) \
12181 @@ -252,7 +294,7 @@ extern void __put_user_8(void);
12182 __typeof__(*(ptr)) __pu_val; \
12183 __chk_user_ptr(ptr); \
12184 might_fault(); \
12185 - __pu_val = x; \
12186 + __pu_val = (x); \
12187 switch (sizeof(*(ptr))) { \
12188 case 1: \
12189 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12190 @@ -373,7 +415,7 @@ do { \
12191 } while (0)
12192
12193 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12194 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12195 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12196 "2:\n" \
12197 ".section .fixup,\"ax\"\n" \
12198 "3: mov %3,%0\n" \
12199 @@ -381,7 +423,7 @@ do { \
12200 " jmp 2b\n" \
12201 ".previous\n" \
12202 _ASM_EXTABLE(1b, 3b) \
12203 - : "=r" (err), ltype(x) \
12204 + : "=r" (err), ltype (x) \
12205 : "m" (__m(addr)), "i" (errret), "0" (err))
12206
12207 #define __get_user_size_ex(x, ptr, size) \
12208 @@ -406,7 +448,7 @@ do { \
12209 } while (0)
12210
12211 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12212 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12213 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12214 "2:\n" \
12215 _ASM_EXTABLE(1b, 2b - 1b) \
12216 : ltype(x) : "m" (__m(addr)))
12217 @@ -423,13 +465,24 @@ do { \
12218 int __gu_err; \
12219 unsigned long __gu_val; \
12220 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12221 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12222 + (x) = (__typeof__(*(ptr)))__gu_val; \
12223 __gu_err; \
12224 })
12225
12226 /* FIXME: this hack is definitely wrong -AK */
12227 struct __large_struct { unsigned long buf[100]; };
12228 -#define __m(x) (*(struct __large_struct __user *)(x))
12229 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12230 +#define ____m(x) \
12231 +({ \
12232 + unsigned long ____x = (unsigned long)(x); \
12233 + if (____x < PAX_USER_SHADOW_BASE) \
12234 + ____x += PAX_USER_SHADOW_BASE; \
12235 + (void __user *)____x; \
12236 +})
12237 +#else
12238 +#define ____m(x) (x)
12239 +#endif
12240 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12241
12242 /*
12243 * Tell gcc we read from memory instead of writing: this is because
12244 @@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
12245 * aliasing issues.
12246 */
12247 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12248 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12249 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12250 "2:\n" \
12251 ".section .fixup,\"ax\"\n" \
12252 "3: mov %3,%0\n" \
12253 @@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
12254 ".previous\n" \
12255 _ASM_EXTABLE(1b, 3b) \
12256 : "=r"(err) \
12257 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12258 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12259
12260 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12261 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12262 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12263 "2:\n" \
12264 _ASM_EXTABLE(1b, 2b - 1b) \
12265 : : ltype(x), "m" (__m(addr)))
12266 @@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
12267 * On error, the variable @x is set to zero.
12268 */
12269
12270 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12271 +#define __get_user(x, ptr) get_user((x), (ptr))
12272 +#else
12273 #define __get_user(x, ptr) \
12274 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12275 +#endif
12276
12277 /**
12278 * __put_user: - Write a simple value into user space, with less checking.
12279 @@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
12280 * Returns zero on success, or -EFAULT on error.
12281 */
12282
12283 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12284 +#define __put_user(x, ptr) put_user((x), (ptr))
12285 +#else
12286 #define __put_user(x, ptr) \
12287 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12288 +#endif
12289
12290 #define __get_user_unaligned __get_user
12291 #define __put_user_unaligned __put_user
12292 @@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
12293 #define get_user_ex(x, ptr) do { \
12294 unsigned long __gue_val; \
12295 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12296 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12297 + (x) = (__typeof__(*(ptr)))__gue_val; \
12298 } while (0)
12299
12300 #ifdef CONFIG_X86_WP_WORKS_OK
12301 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12302 index 566e803..dfa5535 100644
12303 --- a/arch/x86/include/asm/uaccess_32.h
12304 +++ b/arch/x86/include/asm/uaccess_32.h
12305 @@ -11,15 +11,15 @@
12306 #include <asm/page.h>
12307
12308 unsigned long __must_check __copy_to_user_ll
12309 - (void __user *to, const void *from, unsigned long n);
12310 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12311 unsigned long __must_check __copy_from_user_ll
12312 - (void *to, const void __user *from, unsigned long n);
12313 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12314 unsigned long __must_check __copy_from_user_ll_nozero
12315 - (void *to, const void __user *from, unsigned long n);
12316 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12317 unsigned long __must_check __copy_from_user_ll_nocache
12318 - (void *to, const void __user *from, unsigned long n);
12319 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12320 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12321 - (void *to, const void __user *from, unsigned long n);
12322 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12323
12324 /**
12325 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12326 @@ -41,8 +41,13 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12327 */
12328
12329 static __always_inline unsigned long __must_check
12330 +__copy_to_user_inatomic(void __user *to, const void *from, unsigned long n) __size_overflow(3);
12331 +static __always_inline unsigned long __must_check
12332 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12333 {
12334 + if ((long)n < 0)
12335 + return n;
12336 +
12337 if (__builtin_constant_p(n)) {
12338 unsigned long ret;
12339
12340 @@ -61,6 +66,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12341 return ret;
12342 }
12343 }
12344 + if (!__builtin_constant_p(n))
12345 + check_object_size(from, n, true);
12346 return __copy_to_user_ll(to, from, n);
12347 }
12348
12349 @@ -79,15 +86,23 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12350 * On success, this will be zero.
12351 */
12352 static __always_inline unsigned long __must_check
12353 +__copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
12354 +static __always_inline unsigned long __must_check
12355 __copy_to_user(void __user *to, const void *from, unsigned long n)
12356 {
12357 might_fault();
12358 +
12359 return __copy_to_user_inatomic(to, from, n);
12360 }
12361
12362 static __always_inline unsigned long
12363 +__copy_from_user_inatomic(void *to, const void __user *from, unsigned long n) __size_overflow(3);
12364 +static __always_inline unsigned long
12365 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12366 {
12367 + if ((long)n < 0)
12368 + return n;
12369 +
12370 /* Avoid zeroing the tail if the copy fails..
12371 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12372 * but as the zeroing behaviour is only significant when n is not
12373 @@ -134,9 +149,15 @@ __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12374 * for explanation of why this is needed.
12375 */
12376 static __always_inline unsigned long
12377 +__copy_from_user(void *to, const void __user *from, unsigned long n) __size_overflow(3);
12378 +static __always_inline unsigned long
12379 __copy_from_user(void *to, const void __user *from, unsigned long n)
12380 {
12381 might_fault();
12382 +
12383 + if ((long)n < 0)
12384 + return n;
12385 +
12386 if (__builtin_constant_p(n)) {
12387 unsigned long ret;
12388
12389 @@ -152,13 +173,21 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12390 return ret;
12391 }
12392 }
12393 + if (!__builtin_constant_p(n))
12394 + check_object_size(to, n, false);
12395 return __copy_from_user_ll(to, from, n);
12396 }
12397
12398 static __always_inline unsigned long __copy_from_user_nocache(void *to,
12399 + const void __user *from, unsigned long n) __size_overflow(3);
12400 +static __always_inline unsigned long __copy_from_user_nocache(void *to,
12401 const void __user *from, unsigned long n)
12402 {
12403 might_fault();
12404 +
12405 + if ((long)n < 0)
12406 + return n;
12407 +
12408 if (__builtin_constant_p(n)) {
12409 unsigned long ret;
12410
12411 @@ -179,17 +208,24 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12412
12413 static __always_inline unsigned long
12414 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12415 + unsigned long n) __size_overflow(3);
12416 +static __always_inline unsigned long
12417 +__copy_from_user_inatomic_nocache(void *to, const void __user *from,
12418 unsigned long n)
12419 {
12420 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12421 + if ((long)n < 0)
12422 + return n;
12423 +
12424 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12425 }
12426
12427 -unsigned long __must_check copy_to_user(void __user *to,
12428 - const void *from, unsigned long n);
12429 -unsigned long __must_check _copy_from_user(void *to,
12430 - const void __user *from,
12431 - unsigned long n);
12432 -
12433 +extern void copy_to_user_overflow(void)
12434 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12435 + __compiletime_error("copy_to_user() buffer size is not provably correct")
12436 +#else
12437 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
12438 +#endif
12439 +;
12440
12441 extern void copy_from_user_overflow(void)
12442 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12443 @@ -199,24 +235,72 @@ extern void copy_from_user_overflow(void)
12444 #endif
12445 ;
12446
12447 -static inline unsigned long __must_check copy_from_user(void *to,
12448 - const void __user *from,
12449 - unsigned long n)
12450 +/**
12451 + * copy_to_user: - Copy a block of data into user space.
12452 + * @to: Destination address, in user space.
12453 + * @from: Source address, in kernel space.
12454 + * @n: Number of bytes to copy.
12455 + *
12456 + * Context: User context only. This function may sleep.
12457 + *
12458 + * Copy data from kernel space to user space.
12459 + *
12460 + * Returns number of bytes that could not be copied.
12461 + * On success, this will be zero.
12462 + */
12463 +static inline unsigned long __must_check
12464 +copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
12465 +static inline unsigned long __must_check
12466 +copy_to_user(void __user *to, const void *from, unsigned long n)
12467 +{
12468 + int sz = __compiletime_object_size(from);
12469 +
12470 + if (unlikely(sz != -1 && sz < n))
12471 + copy_to_user_overflow();
12472 + else if (access_ok(VERIFY_WRITE, to, n))
12473 + n = __copy_to_user(to, from, n);
12474 + return n;
12475 +}
12476 +
12477 +/**
12478 + * copy_from_user: - Copy a block of data from user space.
12479 + * @to: Destination address, in kernel space.
12480 + * @from: Source address, in user space.
12481 + * @n: Number of bytes to copy.
12482 + *
12483 + * Context: User context only. This function may sleep.
12484 + *
12485 + * Copy data from user space to kernel space.
12486 + *
12487 + * Returns number of bytes that could not be copied.
12488 + * On success, this will be zero.
12489 + *
12490 + * If some data could not be copied, this function will pad the copied
12491 + * data to the requested size using zero bytes.
12492 + */
12493 +static inline unsigned long __must_check
12494 +copy_from_user(void *to, const void __user *from, unsigned long n) __size_overflow(3);
12495 +static inline unsigned long __must_check
12496 +copy_from_user(void *to, const void __user *from, unsigned long n)
12497 {
12498 int sz = __compiletime_object_size(to);
12499
12500 - if (likely(sz == -1 || sz >= n))
12501 - n = _copy_from_user(to, from, n);
12502 - else
12503 + if (unlikely(sz != -1 && sz < n))
12504 copy_from_user_overflow();
12505 -
12506 + else if (access_ok(VERIFY_READ, from, n))
12507 + n = __copy_from_user(to, from, n);
12508 + else if ((long)n > 0) {
12509 + if (!__builtin_constant_p(n))
12510 + check_object_size(to, n, false);
12511 + memset(to, 0, n);
12512 + }
12513 return n;
12514 }
12515
12516 long __must_check strncpy_from_user(char *dst, const char __user *src,
12517 - long count);
12518 + unsigned long count);
12519 long __must_check __strncpy_from_user(char *dst,
12520 - const char __user *src, long count);
12521 + const char __user *src, unsigned long count);
12522
12523 /**
12524 * strlen_user: - Get the size of a string in user space.
12525 @@ -234,8 +318,8 @@ long __must_check __strncpy_from_user(char *dst,
12526 */
12527 #define strlen_user(str) strnlen_user(str, LONG_MAX)
12528
12529 -long strnlen_user(const char __user *str, long n);
12530 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
12531 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
12532 +long strnlen_user(const char __user *str, unsigned long n);
12533 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12534 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12535
12536 #endif /* _ASM_X86_UACCESS_32_H */
12537 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12538 index 1c66d30..8a44920 100644
12539 --- a/arch/x86/include/asm/uaccess_64.h
12540 +++ b/arch/x86/include/asm/uaccess_64.h
12541 @@ -10,6 +10,9 @@
12542 #include <asm/alternative.h>
12543 #include <asm/cpufeature.h>
12544 #include <asm/page.h>
12545 +#include <asm/pgtable.h>
12546 +
12547 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
12548
12549 /*
12550 * Copy To/From Userspace
12551 @@ -17,12 +20,14 @@
12552
12553 /* Handles exceptions in both to and from, but doesn't do access_ok */
12554 __must_check unsigned long
12555 -copy_user_generic_string(void *to, const void *from, unsigned len);
12556 +copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
12557 __must_check unsigned long
12558 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
12559 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
12560
12561 static __always_inline __must_check unsigned long
12562 -copy_user_generic(void *to, const void *from, unsigned len)
12563 +copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
12564 +static __always_inline __must_check unsigned long
12565 +copy_user_generic(void *to, const void *from, unsigned long len)
12566 {
12567 unsigned ret;
12568
12569 @@ -32,142 +37,237 @@ copy_user_generic(void *to, const void *from, unsigned len)
12570 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
12571 "=d" (len)),
12572 "1" (to), "2" (from), "3" (len)
12573 - : "memory", "rcx", "r8", "r9", "r10", "r11");
12574 + : "memory", "rcx", "r8", "r9", "r11");
12575 return ret;
12576 }
12577
12578 +static __always_inline __must_check unsigned long
12579 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
12580 +static __always_inline __must_check unsigned long
12581 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
12582 __must_check unsigned long
12583 -_copy_to_user(void __user *to, const void *from, unsigned len);
12584 -__must_check unsigned long
12585 -_copy_from_user(void *to, const void __user *from, unsigned len);
12586 -__must_check unsigned long
12587 -copy_in_user(void __user *to, const void __user *from, unsigned len);
12588 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
12589
12590 static inline unsigned long __must_check copy_from_user(void *to,
12591 const void __user *from,
12592 + unsigned long n) __size_overflow(3);
12593 +static inline unsigned long __must_check copy_from_user(void *to,
12594 + const void __user *from,
12595 unsigned long n)
12596 {
12597 - int sz = __compiletime_object_size(to);
12598 -
12599 might_fault();
12600 - if (likely(sz == -1 || sz >= n))
12601 - n = _copy_from_user(to, from, n);
12602 -#ifdef CONFIG_DEBUG_VM
12603 - else
12604 - WARN(1, "Buffer overflow detected!\n");
12605 -#endif
12606 +
12607 + if (access_ok(VERIFY_READ, from, n))
12608 + n = __copy_from_user(to, from, n);
12609 + else if (n < INT_MAX) {
12610 + if (!__builtin_constant_p(n))
12611 + check_object_size(to, n, false);
12612 + memset(to, 0, n);
12613 + }
12614 return n;
12615 }
12616
12617 static __always_inline __must_check
12618 -int copy_to_user(void __user *dst, const void *src, unsigned size)
12619 +int copy_to_user(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
12620 +static __always_inline __must_check
12621 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
12622 {
12623 might_fault();
12624
12625 - return _copy_to_user(dst, src, size);
12626 + if (access_ok(VERIFY_WRITE, dst, size))
12627 + size = __copy_to_user(dst, src, size);
12628 + return size;
12629 }
12630
12631 static __always_inline __must_check
12632 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
12633 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
12634 +static __always_inline __must_check
12635 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
12636 {
12637 - int ret = 0;
12638 + int sz = __compiletime_object_size(dst);
12639 + unsigned ret = 0;
12640
12641 might_fault();
12642 - if (!__builtin_constant_p(size))
12643 - return copy_user_generic(dst, (__force void *)src, size);
12644 +
12645 + if (size > INT_MAX)
12646 + return size;
12647 +
12648 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12649 + if (!__access_ok(VERIFY_READ, src, size))
12650 + return size;
12651 +#endif
12652 +
12653 + if (unlikely(sz != -1 && sz < size)) {
12654 +#ifdef CONFIG_DEBUG_VM
12655 + WARN(1, "Buffer overflow detected!\n");
12656 +#endif
12657 + return size;
12658 + }
12659 +
12660 + if (!__builtin_constant_p(size)) {
12661 + check_object_size(dst, size, false);
12662 +
12663 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12664 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12665 + src += PAX_USER_SHADOW_BASE;
12666 +#endif
12667 +
12668 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12669 + }
12670 switch (size) {
12671 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
12672 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
12673 ret, "b", "b", "=q", 1);
12674 return ret;
12675 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
12676 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
12677 ret, "w", "w", "=r", 2);
12678 return ret;
12679 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
12680 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
12681 ret, "l", "k", "=r", 4);
12682 return ret;
12683 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
12684 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12685 ret, "q", "", "=r", 8);
12686 return ret;
12687 case 10:
12688 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12689 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12690 ret, "q", "", "=r", 10);
12691 if (unlikely(ret))
12692 return ret;
12693 __get_user_asm(*(u16 *)(8 + (char *)dst),
12694 - (u16 __user *)(8 + (char __user *)src),
12695 + (const u16 __user *)(8 + (const char __user *)src),
12696 ret, "w", "w", "=r", 2);
12697 return ret;
12698 case 16:
12699 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12700 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12701 ret, "q", "", "=r", 16);
12702 if (unlikely(ret))
12703 return ret;
12704 __get_user_asm(*(u64 *)(8 + (char *)dst),
12705 - (u64 __user *)(8 + (char __user *)src),
12706 + (const u64 __user *)(8 + (const char __user *)src),
12707 ret, "q", "", "=r", 8);
12708 return ret;
12709 default:
12710 - return copy_user_generic(dst, (__force void *)src, size);
12711 +
12712 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12713 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12714 + src += PAX_USER_SHADOW_BASE;
12715 +#endif
12716 +
12717 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12718 }
12719 }
12720
12721 static __always_inline __must_check
12722 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
12723 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
12724 +static __always_inline __must_check
12725 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
12726 {
12727 - int ret = 0;
12728 + int sz = __compiletime_object_size(src);
12729 + unsigned ret = 0;
12730
12731 might_fault();
12732 - if (!__builtin_constant_p(size))
12733 - return copy_user_generic((__force void *)dst, src, size);
12734 +
12735 + if (size > INT_MAX)
12736 + return size;
12737 +
12738 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12739 + if (!__access_ok(VERIFY_WRITE, dst, size))
12740 + return size;
12741 +#endif
12742 +
12743 + if (unlikely(sz != -1 && sz < size)) {
12744 +#ifdef CONFIG_DEBUG_VM
12745 + WARN(1, "Buffer overflow detected!\n");
12746 +#endif
12747 + return size;
12748 + }
12749 +
12750 + if (!__builtin_constant_p(size)) {
12751 + check_object_size(src, size, true);
12752 +
12753 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12754 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12755 + dst += PAX_USER_SHADOW_BASE;
12756 +#endif
12757 +
12758 + return copy_user_generic((__force_kernel void *)dst, src, size);
12759 + }
12760 switch (size) {
12761 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
12762 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
12763 ret, "b", "b", "iq", 1);
12764 return ret;
12765 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
12766 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
12767 ret, "w", "w", "ir", 2);
12768 return ret;
12769 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
12770 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
12771 ret, "l", "k", "ir", 4);
12772 return ret;
12773 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
12774 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12775 ret, "q", "", "er", 8);
12776 return ret;
12777 case 10:
12778 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12779 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12780 ret, "q", "", "er", 10);
12781 if (unlikely(ret))
12782 return ret;
12783 asm("":::"memory");
12784 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
12785 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
12786 ret, "w", "w", "ir", 2);
12787 return ret;
12788 case 16:
12789 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12790 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12791 ret, "q", "", "er", 16);
12792 if (unlikely(ret))
12793 return ret;
12794 asm("":::"memory");
12795 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
12796 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
12797 ret, "q", "", "er", 8);
12798 return ret;
12799 default:
12800 - return copy_user_generic((__force void *)dst, src, size);
12801 +
12802 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12803 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12804 + dst += PAX_USER_SHADOW_BASE;
12805 +#endif
12806 +
12807 + return copy_user_generic((__force_kernel void *)dst, src, size);
12808 }
12809 }
12810
12811 static __always_inline __must_check
12812 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12813 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size) __size_overflow(3);
12814 +static __always_inline __must_check
12815 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
12816 {
12817 - int ret = 0;
12818 + unsigned ret = 0;
12819
12820 might_fault();
12821 - if (!__builtin_constant_p(size))
12822 - return copy_user_generic((__force void *)dst,
12823 - (__force void *)src, size);
12824 +
12825 + if (size > INT_MAX)
12826 + return size;
12827 +
12828 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12829 + if (!__access_ok(VERIFY_READ, src, size))
12830 + return size;
12831 + if (!__access_ok(VERIFY_WRITE, dst, size))
12832 + return size;
12833 +#endif
12834 +
12835 + if (!__builtin_constant_p(size)) {
12836 +
12837 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12838 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12839 + src += PAX_USER_SHADOW_BASE;
12840 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12841 + dst += PAX_USER_SHADOW_BASE;
12842 +#endif
12843 +
12844 + return copy_user_generic((__force_kernel void *)dst,
12845 + (__force_kernel const void *)src, size);
12846 + }
12847 switch (size) {
12848 case 1: {
12849 u8 tmp;
12850 - __get_user_asm(tmp, (u8 __user *)src,
12851 + __get_user_asm(tmp, (const u8 __user *)src,
12852 ret, "b", "b", "=q", 1);
12853 if (likely(!ret))
12854 __put_user_asm(tmp, (u8 __user *)dst,
12855 @@ -176,7 +276,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12856 }
12857 case 2: {
12858 u16 tmp;
12859 - __get_user_asm(tmp, (u16 __user *)src,
12860 + __get_user_asm(tmp, (const u16 __user *)src,
12861 ret, "w", "w", "=r", 2);
12862 if (likely(!ret))
12863 __put_user_asm(tmp, (u16 __user *)dst,
12864 @@ -186,7 +286,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12865
12866 case 4: {
12867 u32 tmp;
12868 - __get_user_asm(tmp, (u32 __user *)src,
12869 + __get_user_asm(tmp, (const u32 __user *)src,
12870 ret, "l", "k", "=r", 4);
12871 if (likely(!ret))
12872 __put_user_asm(tmp, (u32 __user *)dst,
12873 @@ -195,7 +295,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12874 }
12875 case 8: {
12876 u64 tmp;
12877 - __get_user_asm(tmp, (u64 __user *)src,
12878 + __get_user_asm(tmp, (const u64 __user *)src,
12879 ret, "q", "", "=r", 8);
12880 if (likely(!ret))
12881 __put_user_asm(tmp, (u64 __user *)dst,
12882 @@ -203,51 +303,103 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12883 return ret;
12884 }
12885 default:
12886 - return copy_user_generic((__force void *)dst,
12887 - (__force void *)src, size);
12888 +
12889 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12890 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12891 + src += PAX_USER_SHADOW_BASE;
12892 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12893 + dst += PAX_USER_SHADOW_BASE;
12894 +#endif
12895 +
12896 + return copy_user_generic((__force_kernel void *)dst,
12897 + (__force_kernel const void *)src, size);
12898 }
12899 }
12900
12901 __must_check long
12902 -strncpy_from_user(char *dst, const char __user *src, long count);
12903 +strncpy_from_user(char *dst, const char __user *src, unsigned long count);
12904 __must_check long
12905 -__strncpy_from_user(char *dst, const char __user *src, long count);
12906 -__must_check long strnlen_user(const char __user *str, long n);
12907 -__must_check long __strnlen_user(const char __user *str, long n);
12908 +__strncpy_from_user(char *dst, const char __user *src, unsigned long count);
12909 +__must_check long strnlen_user(const char __user *str, unsigned long n);
12910 +__must_check long __strnlen_user(const char __user *str, unsigned long n);
12911 __must_check long strlen_user(const char __user *str);
12912 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
12913 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
12914 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12915 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12916
12917 static __must_check __always_inline int
12918 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
12919 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
12920 +static __must_check __always_inline int
12921 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
12922 {
12923 - return copy_user_generic(dst, (__force const void *)src, size);
12924 + if (size > INT_MAX)
12925 + return size;
12926 +
12927 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12928 + if (!__access_ok(VERIFY_READ, src, size))
12929 + return size;
12930 +
12931 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12932 + src += PAX_USER_SHADOW_BASE;
12933 +#endif
12934 +
12935 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12936 }
12937
12938 -static __must_check __always_inline int
12939 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
12940 +static __must_check __always_inline unsigned long
12941 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
12942 +static __must_check __always_inline unsigned long
12943 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
12944 {
12945 - return copy_user_generic((__force void *)dst, src, size);
12946 + if (size > INT_MAX)
12947 + return size;
12948 +
12949 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12950 + if (!__access_ok(VERIFY_WRITE, dst, size))
12951 + return size;
12952 +
12953 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12954 + dst += PAX_USER_SHADOW_BASE;
12955 +#endif
12956 +
12957 + return copy_user_generic((__force_kernel void *)dst, src, size);
12958 }
12959
12960 -extern long __copy_user_nocache(void *dst, const void __user *src,
12961 - unsigned size, int zerorest);
12962 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
12963 + unsigned long size, int zerorest) __size_overflow(3);
12964
12965 -static inline int
12966 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12967 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
12968 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
12969 {
12970 might_sleep();
12971 +
12972 + if (size > INT_MAX)
12973 + return size;
12974 +
12975 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12976 + if (!__access_ok(VERIFY_READ, src, size))
12977 + return size;
12978 +#endif
12979 +
12980 return __copy_user_nocache(dst, src, size, 1);
12981 }
12982
12983 -static inline int
12984 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12985 - unsigned size)
12986 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12987 + unsigned long size) __size_overflow(3);
12988 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12989 + unsigned long size)
12990 {
12991 + if (size > INT_MAX)
12992 + return size;
12993 +
12994 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12995 + if (!__access_ok(VERIFY_READ, src, size))
12996 + return size;
12997 +#endif
12998 +
12999 return __copy_user_nocache(dst, src, size, 0);
13000 }
13001
13002 -unsigned long
13003 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13004 +extern unsigned long
13005 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13006
13007 #endif /* _ASM_X86_UACCESS_64_H */
13008 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13009 index bb05228..d763d5b 100644
13010 --- a/arch/x86/include/asm/vdso.h
13011 +++ b/arch/x86/include/asm/vdso.h
13012 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13013 #define VDSO32_SYMBOL(base, name) \
13014 ({ \
13015 extern const char VDSO32_##name[]; \
13016 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13017 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13018 })
13019 #endif
13020
13021 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13022 index 1971e65..1e3559b 100644
13023 --- a/arch/x86/include/asm/x86_init.h
13024 +++ b/arch/x86/include/asm/x86_init.h
13025 @@ -28,7 +28,7 @@ struct x86_init_mpparse {
13026 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13027 void (*find_smp_config)(void);
13028 void (*get_smp_config)(unsigned int early);
13029 -};
13030 +} __no_const;
13031
13032 /**
13033 * struct x86_init_resources - platform specific resource related ops
13034 @@ -42,7 +42,7 @@ struct x86_init_resources {
13035 void (*probe_roms)(void);
13036 void (*reserve_resources)(void);
13037 char *(*memory_setup)(void);
13038 -};
13039 +} __no_const;
13040
13041 /**
13042 * struct x86_init_irqs - platform specific interrupt setup
13043 @@ -55,7 +55,7 @@ struct x86_init_irqs {
13044 void (*pre_vector_init)(void);
13045 void (*intr_init)(void);
13046 void (*trap_init)(void);
13047 -};
13048 +} __no_const;
13049
13050 /**
13051 * struct x86_init_oem - oem platform specific customizing functions
13052 @@ -65,7 +65,7 @@ struct x86_init_irqs {
13053 struct x86_init_oem {
13054 void (*arch_setup)(void);
13055 void (*banner)(void);
13056 -};
13057 +} __no_const;
13058
13059 /**
13060 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13061 @@ -76,7 +76,7 @@ struct x86_init_oem {
13062 */
13063 struct x86_init_mapping {
13064 void (*pagetable_reserve)(u64 start, u64 end);
13065 -};
13066 +} __no_const;
13067
13068 /**
13069 * struct x86_init_paging - platform specific paging functions
13070 @@ -86,7 +86,7 @@ struct x86_init_mapping {
13071 struct x86_init_paging {
13072 void (*pagetable_setup_start)(pgd_t *base);
13073 void (*pagetable_setup_done)(pgd_t *base);
13074 -};
13075 +} __no_const;
13076
13077 /**
13078 * struct x86_init_timers - platform specific timer setup
13079 @@ -101,7 +101,7 @@ struct x86_init_timers {
13080 void (*tsc_pre_init)(void);
13081 void (*timer_init)(void);
13082 void (*wallclock_init)(void);
13083 -};
13084 +} __no_const;
13085
13086 /**
13087 * struct x86_init_iommu - platform specific iommu setup
13088 @@ -109,7 +109,7 @@ struct x86_init_timers {
13089 */
13090 struct x86_init_iommu {
13091 int (*iommu_init)(void);
13092 -};
13093 +} __no_const;
13094
13095 /**
13096 * struct x86_init_pci - platform specific pci init functions
13097 @@ -123,7 +123,7 @@ struct x86_init_pci {
13098 int (*init)(void);
13099 void (*init_irq)(void);
13100 void (*fixup_irqs)(void);
13101 -};
13102 +} __no_const;
13103
13104 /**
13105 * struct x86_init_ops - functions for platform specific setup
13106 @@ -139,7 +139,7 @@ struct x86_init_ops {
13107 struct x86_init_timers timers;
13108 struct x86_init_iommu iommu;
13109 struct x86_init_pci pci;
13110 -};
13111 +} __no_const;
13112
13113 /**
13114 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13115 @@ -147,7 +147,7 @@ struct x86_init_ops {
13116 */
13117 struct x86_cpuinit_ops {
13118 void (*setup_percpu_clockev)(void);
13119 -};
13120 +} __no_const;
13121
13122 /**
13123 * struct x86_platform_ops - platform specific runtime functions
13124 @@ -169,7 +169,7 @@ struct x86_platform_ops {
13125 void (*nmi_init)(void);
13126 unsigned char (*get_nmi_reason)(void);
13127 int (*i8042_detect)(void);
13128 -};
13129 +} __no_const;
13130
13131 struct pci_dev;
13132
13133 @@ -177,7 +177,7 @@ struct x86_msi_ops {
13134 int (*setup_msi_irqs)(struct pci_dev *dev, int nvec, int type);
13135 void (*teardown_msi_irq)(unsigned int irq);
13136 void (*teardown_msi_irqs)(struct pci_dev *dev);
13137 -};
13138 +} __no_const;
13139
13140 extern struct x86_init_ops x86_init;
13141 extern struct x86_cpuinit_ops x86_cpuinit;
13142 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13143 index c6ce245..ffbdab7 100644
13144 --- a/arch/x86/include/asm/xsave.h
13145 +++ b/arch/x86/include/asm/xsave.h
13146 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13147 {
13148 int err;
13149
13150 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13151 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13152 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13153 +#endif
13154 +
13155 /*
13156 * Clear the xsave header first, so that reserved fields are
13157 * initialized to zero.
13158 @@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13159 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13160 {
13161 int err;
13162 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13163 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13164 u32 lmask = mask;
13165 u32 hmask = mask >> 32;
13166
13167 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13168 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13169 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13170 +#endif
13171 +
13172 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13173 "2:\n"
13174 ".section .fixup,\"ax\"\n"
13175 diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13176 index 6a564ac..9b1340c 100644
13177 --- a/arch/x86/kernel/acpi/realmode/Makefile
13178 +++ b/arch/x86/kernel/acpi/realmode/Makefile
13179 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13180 $(call cc-option, -fno-stack-protector) \
13181 $(call cc-option, -mpreferred-stack-boundary=2)
13182 KBUILD_CFLAGS += $(call cc-option, -m32)
13183 +ifdef CONSTIFY_PLUGIN
13184 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13185 +endif
13186 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13187 GCOV_PROFILE := n
13188
13189 diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13190 index b4fd836..4358fe3 100644
13191 --- a/arch/x86/kernel/acpi/realmode/wakeup.S
13192 +++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13193 @@ -108,6 +108,9 @@ wakeup_code:
13194 /* Do any other stuff... */
13195
13196 #ifndef CONFIG_64BIT
13197 + /* Recheck NX bit overrides (64bit path does this in trampoline */
13198 + call verify_cpu
13199 +
13200 /* This could also be done in C code... */
13201 movl pmode_cr3, %eax
13202 movl %eax, %cr3
13203 @@ -131,6 +134,7 @@ wakeup_code:
13204 movl pmode_cr0, %eax
13205 movl %eax, %cr0
13206 jmp pmode_return
13207 +# include "../../verify_cpu.S"
13208 #else
13209 pushw $0
13210 pushw trampoline_segment
13211 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13212 index 103b6ab..2004d0a 100644
13213 --- a/arch/x86/kernel/acpi/sleep.c
13214 +++ b/arch/x86/kernel/acpi/sleep.c
13215 @@ -94,8 +94,12 @@ int acpi_suspend_lowlevel(void)
13216 header->trampoline_segment = trampoline_address() >> 4;
13217 #ifdef CONFIG_SMP
13218 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13219 +
13220 + pax_open_kernel();
13221 early_gdt_descr.address =
13222 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13223 + pax_close_kernel();
13224 +
13225 initial_gs = per_cpu_offset(smp_processor_id());
13226 #endif
13227 initial_code = (unsigned long)wakeup_long64;
13228 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13229 index 13ab720..95d5442 100644
13230 --- a/arch/x86/kernel/acpi/wakeup_32.S
13231 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13232 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13233 # and restore the stack ... but you need gdt for this to work
13234 movl saved_context_esp, %esp
13235
13236 - movl %cs:saved_magic, %eax
13237 - cmpl $0x12345678, %eax
13238 + cmpl $0x12345678, saved_magic
13239 jne bogus_magic
13240
13241 # jump to place where we left off
13242 - movl saved_eip, %eax
13243 - jmp *%eax
13244 + jmp *(saved_eip)
13245
13246 bogus_magic:
13247 jmp bogus_magic
13248 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13249 index 1f84794..e23f862 100644
13250 --- a/arch/x86/kernel/alternative.c
13251 +++ b/arch/x86/kernel/alternative.c
13252 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13253 */
13254 for (a = start; a < end; a++) {
13255 instr = (u8 *)&a->instr_offset + a->instr_offset;
13256 +
13257 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13258 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13259 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13260 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13261 +#endif
13262 +
13263 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13264 BUG_ON(a->replacementlen > a->instrlen);
13265 BUG_ON(a->instrlen > sizeof(insnbuf));
13266 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13267 for (poff = start; poff < end; poff++) {
13268 u8 *ptr = (u8 *)poff + *poff;
13269
13270 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13271 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13272 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13273 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13274 +#endif
13275 +
13276 if (!*poff || ptr < text || ptr >= text_end)
13277 continue;
13278 /* turn DS segment override prefix into lock prefix */
13279 - if (*ptr == 0x3e)
13280 + if (*ktla_ktva(ptr) == 0x3e)
13281 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13282 };
13283 mutex_unlock(&text_mutex);
13284 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13285 for (poff = start; poff < end; poff++) {
13286 u8 *ptr = (u8 *)poff + *poff;
13287
13288 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13289 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13290 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13291 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13292 +#endif
13293 +
13294 if (!*poff || ptr < text || ptr >= text_end)
13295 continue;
13296 /* turn lock prefix into DS segment override prefix */
13297 - if (*ptr == 0xf0)
13298 + if (*ktla_ktva(ptr) == 0xf0)
13299 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13300 };
13301 mutex_unlock(&text_mutex);
13302 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13303
13304 BUG_ON(p->len > MAX_PATCH_LEN);
13305 /* prep the buffer with the original instructions */
13306 - memcpy(insnbuf, p->instr, p->len);
13307 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13308 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13309 (unsigned long)p->instr, p->len);
13310
13311 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13312 if (smp_alt_once)
13313 free_init_pages("SMP alternatives",
13314 (unsigned long)__smp_locks,
13315 - (unsigned long)__smp_locks_end);
13316 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13317
13318 restart_nmi();
13319 }
13320 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13321 * instructions. And on the local CPU you need to be protected again NMI or MCE
13322 * handlers seeing an inconsistent instruction while you patch.
13323 */
13324 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13325 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13326 size_t len)
13327 {
13328 unsigned long flags;
13329 local_irq_save(flags);
13330 - memcpy(addr, opcode, len);
13331 +
13332 + pax_open_kernel();
13333 + memcpy(ktla_ktva(addr), opcode, len);
13334 sync_core();
13335 + pax_close_kernel();
13336 +
13337 local_irq_restore(flags);
13338 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13339 that causes hangs on some VIA CPUs. */
13340 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13341 */
13342 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13343 {
13344 - unsigned long flags;
13345 - char *vaddr;
13346 + unsigned char *vaddr = ktla_ktva(addr);
13347 struct page *pages[2];
13348 - int i;
13349 + size_t i;
13350
13351 if (!core_kernel_text((unsigned long)addr)) {
13352 - pages[0] = vmalloc_to_page(addr);
13353 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13354 + pages[0] = vmalloc_to_page(vaddr);
13355 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13356 } else {
13357 - pages[0] = virt_to_page(addr);
13358 + pages[0] = virt_to_page(vaddr);
13359 WARN_ON(!PageReserved(pages[0]));
13360 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13361 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13362 }
13363 BUG_ON(!pages[0]);
13364 - local_irq_save(flags);
13365 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13366 - if (pages[1])
13367 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13368 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13369 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13370 - clear_fixmap(FIX_TEXT_POKE0);
13371 - if (pages[1])
13372 - clear_fixmap(FIX_TEXT_POKE1);
13373 - local_flush_tlb();
13374 - sync_core();
13375 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13376 - that causes hangs on some VIA CPUs. */
13377 + text_poke_early(addr, opcode, len);
13378 for (i = 0; i < len; i++)
13379 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13380 - local_irq_restore(flags);
13381 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13382 return addr;
13383 }
13384
13385 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13386 index f98d84c..e402a69 100644
13387 --- a/arch/x86/kernel/apic/apic.c
13388 +++ b/arch/x86/kernel/apic/apic.c
13389 @@ -174,7 +174,7 @@ int first_system_vector = 0xfe;
13390 /*
13391 * Debug level, exported for io_apic.c
13392 */
13393 -unsigned int apic_verbosity;
13394 +int apic_verbosity;
13395
13396 int pic_mode;
13397
13398 @@ -1853,7 +1853,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13399 apic_write(APIC_ESR, 0);
13400 v1 = apic_read(APIC_ESR);
13401 ack_APIC_irq();
13402 - atomic_inc(&irq_err_count);
13403 + atomic_inc_unchecked(&irq_err_count);
13404
13405 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13406 smp_processor_id(), v0 , v1);
13407 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13408 index 6d939d7..0697fcc 100644
13409 --- a/arch/x86/kernel/apic/io_apic.c
13410 +++ b/arch/x86/kernel/apic/io_apic.c
13411 @@ -1096,7 +1096,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13412 }
13413 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13414
13415 -void lock_vector_lock(void)
13416 +void lock_vector_lock(void) __acquires(vector_lock)
13417 {
13418 /* Used to the online set of cpus does not change
13419 * during assign_irq_vector.
13420 @@ -1104,7 +1104,7 @@ void lock_vector_lock(void)
13421 raw_spin_lock(&vector_lock);
13422 }
13423
13424 -void unlock_vector_lock(void)
13425 +void unlock_vector_lock(void) __releases(vector_lock)
13426 {
13427 raw_spin_unlock(&vector_lock);
13428 }
13429 @@ -2510,7 +2510,7 @@ static void ack_apic_edge(struct irq_data *data)
13430 ack_APIC_irq();
13431 }
13432
13433 -atomic_t irq_mis_count;
13434 +atomic_unchecked_t irq_mis_count;
13435
13436 static void ack_apic_level(struct irq_data *data)
13437 {
13438 @@ -2576,7 +2576,7 @@ static void ack_apic_level(struct irq_data *data)
13439 * at the cpu.
13440 */
13441 if (!(v & (1 << (i & 0x1f)))) {
13442 - atomic_inc(&irq_mis_count);
13443 + atomic_inc_unchecked(&irq_mis_count);
13444
13445 eoi_ioapic_irq(irq, cfg);
13446 }
13447 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13448 index a46bd38..6b906d7 100644
13449 --- a/arch/x86/kernel/apm_32.c
13450 +++ b/arch/x86/kernel/apm_32.c
13451 @@ -411,7 +411,7 @@ static DEFINE_MUTEX(apm_mutex);
13452 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13453 * even though they are called in protected mode.
13454 */
13455 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13456 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13457 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13458
13459 static const char driver_version[] = "1.16ac"; /* no spaces */
13460 @@ -589,7 +589,10 @@ static long __apm_bios_call(void *_call)
13461 BUG_ON(cpu != 0);
13462 gdt = get_cpu_gdt_table(cpu);
13463 save_desc_40 = gdt[0x40 / 8];
13464 +
13465 + pax_open_kernel();
13466 gdt[0x40 / 8] = bad_bios_desc;
13467 + pax_close_kernel();
13468
13469 apm_irq_save(flags);
13470 APM_DO_SAVE_SEGS;
13471 @@ -598,7 +601,11 @@ static long __apm_bios_call(void *_call)
13472 &call->esi);
13473 APM_DO_RESTORE_SEGS;
13474 apm_irq_restore(flags);
13475 +
13476 + pax_open_kernel();
13477 gdt[0x40 / 8] = save_desc_40;
13478 + pax_close_kernel();
13479 +
13480 put_cpu();
13481
13482 return call->eax & 0xff;
13483 @@ -665,7 +672,10 @@ static long __apm_bios_call_simple(void *_call)
13484 BUG_ON(cpu != 0);
13485 gdt = get_cpu_gdt_table(cpu);
13486 save_desc_40 = gdt[0x40 / 8];
13487 +
13488 + pax_open_kernel();
13489 gdt[0x40 / 8] = bad_bios_desc;
13490 + pax_close_kernel();
13491
13492 apm_irq_save(flags);
13493 APM_DO_SAVE_SEGS;
13494 @@ -673,7 +683,11 @@ static long __apm_bios_call_simple(void *_call)
13495 &call->eax);
13496 APM_DO_RESTORE_SEGS;
13497 apm_irq_restore(flags);
13498 +
13499 + pax_open_kernel();
13500 gdt[0x40 / 8] = save_desc_40;
13501 + pax_close_kernel();
13502 +
13503 put_cpu();
13504 return error;
13505 }
13506 @@ -2347,12 +2361,15 @@ static int __init apm_init(void)
13507 * code to that CPU.
13508 */
13509 gdt = get_cpu_gdt_table(0);
13510 +
13511 + pax_open_kernel();
13512 set_desc_base(&gdt[APM_CS >> 3],
13513 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13514 set_desc_base(&gdt[APM_CS_16 >> 3],
13515 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13516 set_desc_base(&gdt[APM_DS >> 3],
13517 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13518 + pax_close_kernel();
13519
13520 proc_create("apm", 0, NULL, &apm_file_ops);
13521
13522 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13523 index 4f13faf..87db5d2 100644
13524 --- a/arch/x86/kernel/asm-offsets.c
13525 +++ b/arch/x86/kernel/asm-offsets.c
13526 @@ -33,6 +33,8 @@ void common(void) {
13527 OFFSET(TI_status, thread_info, status);
13528 OFFSET(TI_addr_limit, thread_info, addr_limit);
13529 OFFSET(TI_preempt_count, thread_info, preempt_count);
13530 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13531 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13532
13533 BLANK();
13534 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
13535 @@ -53,8 +55,26 @@ void common(void) {
13536 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13537 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13538 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13539 +
13540 +#ifdef CONFIG_PAX_KERNEXEC
13541 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13542 #endif
13543
13544 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13545 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13546 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13547 +#ifdef CONFIG_X86_64
13548 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13549 +#endif
13550 +#endif
13551 +
13552 +#endif
13553 +
13554 + BLANK();
13555 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13556 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13557 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13558 +
13559 #ifdef CONFIG_XEN
13560 BLANK();
13561 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13562 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13563 index e72a119..6e2955d 100644
13564 --- a/arch/x86/kernel/asm-offsets_64.c
13565 +++ b/arch/x86/kernel/asm-offsets_64.c
13566 @@ -69,6 +69,7 @@ int main(void)
13567 BLANK();
13568 #undef ENTRY
13569
13570 + DEFINE(TSS_size, sizeof(struct tss_struct));
13571 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
13572 BLANK();
13573
13574 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
13575 index 25f24dc..4094a7f 100644
13576 --- a/arch/x86/kernel/cpu/Makefile
13577 +++ b/arch/x86/kernel/cpu/Makefile
13578 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
13579 CFLAGS_REMOVE_perf_event.o = -pg
13580 endif
13581
13582 -# Make sure load_percpu_segment has no stackprotector
13583 -nostackp := $(call cc-option, -fno-stack-protector)
13584 -CFLAGS_common.o := $(nostackp)
13585 -
13586 obj-y := intel_cacheinfo.o scattered.o topology.o
13587 obj-y += proc.o capflags.o powerflags.o common.o
13588 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
13589 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
13590 index 0bab2b1..d0a1bf8 100644
13591 --- a/arch/x86/kernel/cpu/amd.c
13592 +++ b/arch/x86/kernel/cpu/amd.c
13593 @@ -664,7 +664,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
13594 unsigned int size)
13595 {
13596 /* AMD errata T13 (order #21922) */
13597 - if ((c->x86 == 6)) {
13598 + if (c->x86 == 6) {
13599 /* Duron Rev A0 */
13600 if (c->x86_model == 3 && c->x86_mask == 0)
13601 size = 64;
13602 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
13603 index aa003b1..47ea638 100644
13604 --- a/arch/x86/kernel/cpu/common.c
13605 +++ b/arch/x86/kernel/cpu/common.c
13606 @@ -84,60 +84,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
13607
13608 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
13609
13610 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
13611 -#ifdef CONFIG_X86_64
13612 - /*
13613 - * We need valid kernel segments for data and code in long mode too
13614 - * IRET will check the segment types kkeil 2000/10/28
13615 - * Also sysret mandates a special GDT layout
13616 - *
13617 - * TLS descriptors are currently at a different place compared to i386.
13618 - * Hopefully nobody expects them at a fixed place (Wine?)
13619 - */
13620 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
13621 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
13622 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
13623 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
13624 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
13625 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
13626 -#else
13627 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
13628 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13629 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
13630 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
13631 - /*
13632 - * Segments used for calling PnP BIOS have byte granularity.
13633 - * They code segments and data segments have fixed 64k limits,
13634 - * the transfer segment sizes are set at run time.
13635 - */
13636 - /* 32-bit code */
13637 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13638 - /* 16-bit code */
13639 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13640 - /* 16-bit data */
13641 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
13642 - /* 16-bit data */
13643 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
13644 - /* 16-bit data */
13645 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
13646 - /*
13647 - * The APM segments have byte granularity and their bases
13648 - * are set at run time. All have 64k limits.
13649 - */
13650 - /* 32-bit code */
13651 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13652 - /* 16-bit code */
13653 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13654 - /* data */
13655 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
13656 -
13657 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13658 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13659 - GDT_STACK_CANARY_INIT
13660 -#endif
13661 -} };
13662 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
13663 -
13664 static int __init x86_xsave_setup(char *s)
13665 {
13666 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
13667 @@ -372,7 +318,7 @@ void switch_to_new_gdt(int cpu)
13668 {
13669 struct desc_ptr gdt_descr;
13670
13671 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
13672 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
13673 gdt_descr.size = GDT_SIZE - 1;
13674 load_gdt(&gdt_descr);
13675 /* Reload the per-cpu base */
13676 @@ -844,6 +790,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
13677 /* Filter out anything that depends on CPUID levels we don't have */
13678 filter_cpuid_features(c, true);
13679
13680 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
13681 + setup_clear_cpu_cap(X86_FEATURE_SEP);
13682 +#endif
13683 +
13684 /* If the model name is still unset, do table lookup. */
13685 if (!c->x86_model_id[0]) {
13686 const char *p;
13687 @@ -1024,6 +974,9 @@ static __init int setup_disablecpuid(char *arg)
13688 }
13689 __setup("clearcpuid=", setup_disablecpuid);
13690
13691 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
13692 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
13693 +
13694 #ifdef CONFIG_X86_64
13695 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
13696
13697 @@ -1039,7 +992,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
13698 EXPORT_PER_CPU_SYMBOL(current_task);
13699
13700 DEFINE_PER_CPU(unsigned long, kernel_stack) =
13701 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
13702 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
13703 EXPORT_PER_CPU_SYMBOL(kernel_stack);
13704
13705 DEFINE_PER_CPU(char *, irq_stack_ptr) =
13706 @@ -1104,7 +1057,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
13707 {
13708 memset(regs, 0, sizeof(struct pt_regs));
13709 regs->fs = __KERNEL_PERCPU;
13710 - regs->gs = __KERNEL_STACK_CANARY;
13711 + savesegment(gs, regs->gs);
13712
13713 return regs;
13714 }
13715 @@ -1159,7 +1112,7 @@ void __cpuinit cpu_init(void)
13716 int i;
13717
13718 cpu = stack_smp_processor_id();
13719 - t = &per_cpu(init_tss, cpu);
13720 + t = init_tss + cpu;
13721 oist = &per_cpu(orig_ist, cpu);
13722
13723 #ifdef CONFIG_NUMA
13724 @@ -1185,7 +1138,7 @@ void __cpuinit cpu_init(void)
13725 switch_to_new_gdt(cpu);
13726 loadsegment(fs, 0);
13727
13728 - load_idt((const struct desc_ptr *)&idt_descr);
13729 + load_idt(&idt_descr);
13730
13731 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
13732 syscall_init();
13733 @@ -1194,7 +1147,6 @@ void __cpuinit cpu_init(void)
13734 wrmsrl(MSR_KERNEL_GS_BASE, 0);
13735 barrier();
13736
13737 - x86_configure_nx();
13738 if (cpu != 0)
13739 enable_x2apic();
13740
13741 @@ -1248,7 +1200,7 @@ void __cpuinit cpu_init(void)
13742 {
13743 int cpu = smp_processor_id();
13744 struct task_struct *curr = current;
13745 - struct tss_struct *t = &per_cpu(init_tss, cpu);
13746 + struct tss_struct *t = init_tss + cpu;
13747 struct thread_struct *thread = &curr->thread;
13748
13749 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
13750 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
13751 index 5231312..a78a987 100644
13752 --- a/arch/x86/kernel/cpu/intel.c
13753 +++ b/arch/x86/kernel/cpu/intel.c
13754 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
13755 * Update the IDT descriptor and reload the IDT so that
13756 * it uses the read-only mapped virtual address.
13757 */
13758 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
13759 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
13760 load_idt(&idt_descr);
13761 }
13762 #endif
13763 diff --git a/arch/x86/kernel/cpu/mcheck/mce-inject.c b/arch/x86/kernel/cpu/mcheck/mce-inject.c
13764 index 319882e..993534e 100644
13765 --- a/arch/x86/kernel/cpu/mcheck/mce-inject.c
13766 +++ b/arch/x86/kernel/cpu/mcheck/mce-inject.c
13767 @@ -173,6 +173,8 @@ static void raise_mce(struct mce *m)
13768
13769 /* Error injection interface */
13770 static ssize_t mce_write(struct file *filp, const char __user *ubuf,
13771 + size_t usize, loff_t *off) __size_overflow(3);
13772 +static ssize_t mce_write(struct file *filp, const char __user *ubuf,
13773 size_t usize, loff_t *off)
13774 {
13775 struct mce m;
13776 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
13777 index 2af127d..8ff7ac0 100644
13778 --- a/arch/x86/kernel/cpu/mcheck/mce.c
13779 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
13780 @@ -42,6 +42,7 @@
13781 #include <asm/processor.h>
13782 #include <asm/mce.h>
13783 #include <asm/msr.h>
13784 +#include <asm/local.h>
13785
13786 #include "mce-internal.h"
13787
13788 @@ -202,7 +203,7 @@ static void print_mce(struct mce *m)
13789 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
13790 m->cs, m->ip);
13791
13792 - if (m->cs == __KERNEL_CS)
13793 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
13794 print_symbol("{%s}", m->ip);
13795 pr_cont("\n");
13796 }
13797 @@ -235,10 +236,10 @@ static void print_mce(struct mce *m)
13798
13799 #define PANIC_TIMEOUT 5 /* 5 seconds */
13800
13801 -static atomic_t mce_paniced;
13802 +static atomic_unchecked_t mce_paniced;
13803
13804 static int fake_panic;
13805 -static atomic_t mce_fake_paniced;
13806 +static atomic_unchecked_t mce_fake_paniced;
13807
13808 /* Panic in progress. Enable interrupts and wait for final IPI */
13809 static void wait_for_panic(void)
13810 @@ -262,7 +263,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13811 /*
13812 * Make sure only one CPU runs in machine check panic
13813 */
13814 - if (atomic_inc_return(&mce_paniced) > 1)
13815 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
13816 wait_for_panic();
13817 barrier();
13818
13819 @@ -270,7 +271,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13820 console_verbose();
13821 } else {
13822 /* Don't log too much for fake panic */
13823 - if (atomic_inc_return(&mce_fake_paniced) > 1)
13824 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
13825 return;
13826 }
13827 /* First print corrected ones that are still unlogged */
13828 @@ -610,7 +611,7 @@ static int mce_timed_out(u64 *t)
13829 * might have been modified by someone else.
13830 */
13831 rmb();
13832 - if (atomic_read(&mce_paniced))
13833 + if (atomic_read_unchecked(&mce_paniced))
13834 wait_for_panic();
13835 if (!monarch_timeout)
13836 goto out;
13837 @@ -1398,7 +1399,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
13838 }
13839
13840 /* Call the installed machine check handler for this CPU setup. */
13841 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
13842 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
13843 unexpected_machine_check;
13844
13845 /*
13846 @@ -1421,7 +1422,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
13847 return;
13848 }
13849
13850 + pax_open_kernel();
13851 machine_check_vector = do_machine_check;
13852 + pax_close_kernel();
13853
13854 __mcheck_cpu_init_generic();
13855 __mcheck_cpu_init_vendor(c);
13856 @@ -1435,7 +1438,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
13857 */
13858
13859 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
13860 -static int mce_chrdev_open_count; /* #times opened */
13861 +static local_t mce_chrdev_open_count; /* #times opened */
13862 static int mce_chrdev_open_exclu; /* already open exclusive? */
13863
13864 static int mce_chrdev_open(struct inode *inode, struct file *file)
13865 @@ -1443,7 +1446,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
13866 spin_lock(&mce_chrdev_state_lock);
13867
13868 if (mce_chrdev_open_exclu ||
13869 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
13870 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
13871 spin_unlock(&mce_chrdev_state_lock);
13872
13873 return -EBUSY;
13874 @@ -1451,7 +1454,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
13875
13876 if (file->f_flags & O_EXCL)
13877 mce_chrdev_open_exclu = 1;
13878 - mce_chrdev_open_count++;
13879 + local_inc(&mce_chrdev_open_count);
13880
13881 spin_unlock(&mce_chrdev_state_lock);
13882
13883 @@ -1462,7 +1465,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
13884 {
13885 spin_lock(&mce_chrdev_state_lock);
13886
13887 - mce_chrdev_open_count--;
13888 + local_dec(&mce_chrdev_open_count);
13889 mce_chrdev_open_exclu = 0;
13890
13891 spin_unlock(&mce_chrdev_state_lock);
13892 @@ -2171,7 +2174,7 @@ struct dentry *mce_get_debugfs_dir(void)
13893 static void mce_reset(void)
13894 {
13895 cpu_missing = 0;
13896 - atomic_set(&mce_fake_paniced, 0);
13897 + atomic_set_unchecked(&mce_fake_paniced, 0);
13898 atomic_set(&mce_executing, 0);
13899 atomic_set(&mce_callin, 0);
13900 atomic_set(&global_nwo, 0);
13901 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
13902 index 5c0e653..0882b0a 100644
13903 --- a/arch/x86/kernel/cpu/mcheck/p5.c
13904 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
13905 @@ -12,6 +12,7 @@
13906 #include <asm/system.h>
13907 #include <asm/mce.h>
13908 #include <asm/msr.h>
13909 +#include <asm/pgtable.h>
13910
13911 /* By default disabled */
13912 int mce_p5_enabled __read_mostly;
13913 @@ -50,7 +51,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
13914 if (!cpu_has(c, X86_FEATURE_MCE))
13915 return;
13916
13917 + pax_open_kernel();
13918 machine_check_vector = pentium_machine_check;
13919 + pax_close_kernel();
13920 /* Make sure the vector pointer is visible before we enable MCEs: */
13921 wmb();
13922
13923 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
13924 index 54060f5..c1a7577 100644
13925 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
13926 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
13927 @@ -11,6 +11,7 @@
13928 #include <asm/system.h>
13929 #include <asm/mce.h>
13930 #include <asm/msr.h>
13931 +#include <asm/pgtable.h>
13932
13933 /* Machine check handler for WinChip C6: */
13934 static void winchip_machine_check(struct pt_regs *regs, long error_code)
13935 @@ -24,7 +25,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
13936 {
13937 u32 lo, hi;
13938
13939 + pax_open_kernel();
13940 machine_check_vector = winchip_machine_check;
13941 + pax_close_kernel();
13942 /* Make sure the vector pointer is visible before we enable MCEs: */
13943 wmb();
13944
13945 diff --git a/arch/x86/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c
13946 index 7928963..1b16001 100644
13947 --- a/arch/x86/kernel/cpu/mtrr/if.c
13948 +++ b/arch/x86/kernel/cpu/mtrr/if.c
13949 @@ -91,6 +91,8 @@ mtrr_file_del(unsigned long base, unsigned long size,
13950 * "base=%Lx size=%Lx type=%s" or "disable=%d"
13951 */
13952 static ssize_t
13953 +mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos) __size_overflow(3);
13954 +static ssize_t
13955 mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
13956 {
13957 int i, err;
13958 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
13959 index 6b96110..0da73eb 100644
13960 --- a/arch/x86/kernel/cpu/mtrr/main.c
13961 +++ b/arch/x86/kernel/cpu/mtrr/main.c
13962 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
13963 u64 size_or_mask, size_and_mask;
13964 static bool mtrr_aps_delayed_init;
13965
13966 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
13967 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
13968
13969 const struct mtrr_ops *mtrr_if;
13970
13971 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
13972 index df5e41f..816c719 100644
13973 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
13974 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
13975 @@ -25,7 +25,7 @@ struct mtrr_ops {
13976 int (*validate_add_page)(unsigned long base, unsigned long size,
13977 unsigned int type);
13978 int (*have_wrcomb)(void);
13979 -};
13980 +} __do_const;
13981
13982 extern int generic_get_free_region(unsigned long base, unsigned long size,
13983 int replace_reg);
13984 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
13985 index 2bda212..78cc605 100644
13986 --- a/arch/x86/kernel/cpu/perf_event.c
13987 +++ b/arch/x86/kernel/cpu/perf_event.c
13988 @@ -1529,7 +1529,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
13989 break;
13990
13991 perf_callchain_store(entry, frame.return_address);
13992 - fp = frame.next_frame;
13993 + fp = (const void __force_user *)frame.next_frame;
13994 }
13995 }
13996
13997 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
13998 index 13ad899..f642b9a 100644
13999 --- a/arch/x86/kernel/crash.c
14000 +++ b/arch/x86/kernel/crash.c
14001 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14002 {
14003 #ifdef CONFIG_X86_32
14004 struct pt_regs fixed_regs;
14005 -#endif
14006
14007 -#ifdef CONFIG_X86_32
14008 - if (!user_mode_vm(regs)) {
14009 + if (!user_mode(regs)) {
14010 crash_fixup_ss_esp(&fixed_regs, regs);
14011 regs = &fixed_regs;
14012 }
14013 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14014 index 37250fe..bf2ec74 100644
14015 --- a/arch/x86/kernel/doublefault_32.c
14016 +++ b/arch/x86/kernel/doublefault_32.c
14017 @@ -11,7 +11,7 @@
14018
14019 #define DOUBLEFAULT_STACKSIZE (1024)
14020 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14021 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14022 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14023
14024 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14025
14026 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14027 unsigned long gdt, tss;
14028
14029 store_gdt(&gdt_desc);
14030 - gdt = gdt_desc.address;
14031 + gdt = (unsigned long)gdt_desc.address;
14032
14033 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14034
14035 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14036 /* 0x2 bit is always set */
14037 .flags = X86_EFLAGS_SF | 0x2,
14038 .sp = STACK_START,
14039 - .es = __USER_DS,
14040 + .es = __KERNEL_DS,
14041 .cs = __KERNEL_CS,
14042 .ss = __KERNEL_DS,
14043 - .ds = __USER_DS,
14044 + .ds = __KERNEL_DS,
14045 .fs = __KERNEL_PERCPU,
14046
14047 .__cr3 = __pa_nodebug(swapper_pg_dir),
14048 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14049 index 1aae78f..aab3a3d 100644
14050 --- a/arch/x86/kernel/dumpstack.c
14051 +++ b/arch/x86/kernel/dumpstack.c
14052 @@ -2,6 +2,9 @@
14053 * Copyright (C) 1991, 1992 Linus Torvalds
14054 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14055 */
14056 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14057 +#define __INCLUDED_BY_HIDESYM 1
14058 +#endif
14059 #include <linux/kallsyms.h>
14060 #include <linux/kprobes.h>
14061 #include <linux/uaccess.h>
14062 @@ -35,9 +38,8 @@ void printk_address(unsigned long address, int reliable)
14063 static void
14064 print_ftrace_graph_addr(unsigned long addr, void *data,
14065 const struct stacktrace_ops *ops,
14066 - struct thread_info *tinfo, int *graph)
14067 + struct task_struct *task, int *graph)
14068 {
14069 - struct task_struct *task = tinfo->task;
14070 unsigned long ret_addr;
14071 int index = task->curr_ret_stack;
14072
14073 @@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14074 static inline void
14075 print_ftrace_graph_addr(unsigned long addr, void *data,
14076 const struct stacktrace_ops *ops,
14077 - struct thread_info *tinfo, int *graph)
14078 + struct task_struct *task, int *graph)
14079 { }
14080 #endif
14081
14082 @@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14083 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14084 */
14085
14086 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14087 - void *p, unsigned int size, void *end)
14088 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14089 {
14090 - void *t = tinfo;
14091 if (end) {
14092 if (p < end && p >= (end-THREAD_SIZE))
14093 return 1;
14094 @@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14095 }
14096
14097 unsigned long
14098 -print_context_stack(struct thread_info *tinfo,
14099 +print_context_stack(struct task_struct *task, void *stack_start,
14100 unsigned long *stack, unsigned long bp,
14101 const struct stacktrace_ops *ops, void *data,
14102 unsigned long *end, int *graph)
14103 {
14104 struct stack_frame *frame = (struct stack_frame *)bp;
14105
14106 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14107 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14108 unsigned long addr;
14109
14110 addr = *stack;
14111 @@ -102,7 +102,7 @@ print_context_stack(struct thread_info *tinfo,
14112 } else {
14113 ops->address(data, addr, 0);
14114 }
14115 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14116 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14117 }
14118 stack++;
14119 }
14120 @@ -111,7 +111,7 @@ print_context_stack(struct thread_info *tinfo,
14121 EXPORT_SYMBOL_GPL(print_context_stack);
14122
14123 unsigned long
14124 -print_context_stack_bp(struct thread_info *tinfo,
14125 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14126 unsigned long *stack, unsigned long bp,
14127 const struct stacktrace_ops *ops, void *data,
14128 unsigned long *end, int *graph)
14129 @@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14130 struct stack_frame *frame = (struct stack_frame *)bp;
14131 unsigned long *ret_addr = &frame->return_address;
14132
14133 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14134 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14135 unsigned long addr = *ret_addr;
14136
14137 if (!__kernel_text_address(addr))
14138 @@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14139 ops->address(data, addr, 1);
14140 frame = frame->next_frame;
14141 ret_addr = &frame->return_address;
14142 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14143 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14144 }
14145
14146 return (unsigned long)frame;
14147 @@ -186,7 +186,7 @@ void dump_stack(void)
14148
14149 bp = stack_frame(current, NULL);
14150 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14151 - current->pid, current->comm, print_tainted(),
14152 + task_pid_nr(current), current->comm, print_tainted(),
14153 init_utsname()->release,
14154 (int)strcspn(init_utsname()->version, " "),
14155 init_utsname()->version);
14156 @@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
14157 }
14158 EXPORT_SYMBOL_GPL(oops_begin);
14159
14160 +extern void gr_handle_kernel_exploit(void);
14161 +
14162 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14163 {
14164 if (regs && kexec_should_crash(current))
14165 @@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14166 panic("Fatal exception in interrupt");
14167 if (panic_on_oops)
14168 panic("Fatal exception");
14169 - do_exit(signr);
14170 +
14171 + gr_handle_kernel_exploit();
14172 +
14173 + do_group_exit(signr);
14174 }
14175
14176 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14177 @@ -269,7 +274,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14178
14179 show_registers(regs);
14180 #ifdef CONFIG_X86_32
14181 - if (user_mode_vm(regs)) {
14182 + if (user_mode(regs)) {
14183 sp = regs->sp;
14184 ss = regs->ss & 0xffff;
14185 } else {
14186 @@ -297,7 +302,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14187 unsigned long flags = oops_begin();
14188 int sig = SIGSEGV;
14189
14190 - if (!user_mode_vm(regs))
14191 + if (!user_mode(regs))
14192 report_bug(regs->ip, regs);
14193
14194 if (__die(str, regs, err))
14195 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14196 index c99f9ed..2a15d80 100644
14197 --- a/arch/x86/kernel/dumpstack_32.c
14198 +++ b/arch/x86/kernel/dumpstack_32.c
14199 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14200 bp = stack_frame(task, regs);
14201
14202 for (;;) {
14203 - struct thread_info *context;
14204 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14205
14206 - context = (struct thread_info *)
14207 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14208 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14209 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14210
14211 - stack = (unsigned long *)context->previous_esp;
14212 - if (!stack)
14213 + if (stack_start == task_stack_page(task))
14214 break;
14215 + stack = *(unsigned long **)stack_start;
14216 if (ops->stack(data, "IRQ") < 0)
14217 break;
14218 touch_nmi_watchdog();
14219 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
14220 * When in-kernel, we also print out the stack and code at the
14221 * time of the fault..
14222 */
14223 - if (!user_mode_vm(regs)) {
14224 + if (!user_mode(regs)) {
14225 unsigned int code_prologue = code_bytes * 43 / 64;
14226 unsigned int code_len = code_bytes;
14227 unsigned char c;
14228 u8 *ip;
14229 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14230
14231 printk(KERN_EMERG "Stack:\n");
14232 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14233
14234 printk(KERN_EMERG "Code: ");
14235
14236 - ip = (u8 *)regs->ip - code_prologue;
14237 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14238 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14239 /* try starting at IP */
14240 - ip = (u8 *)regs->ip;
14241 + ip = (u8 *)regs->ip + cs_base;
14242 code_len = code_len - code_prologue + 1;
14243 }
14244 for (i = 0; i < code_len; i++, ip++) {
14245 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
14246 printk(KERN_CONT " Bad EIP value.");
14247 break;
14248 }
14249 - if (ip == (u8 *)regs->ip)
14250 + if (ip == (u8 *)regs->ip + cs_base)
14251 printk(KERN_CONT "<%02x> ", c);
14252 else
14253 printk(KERN_CONT "%02x ", c);
14254 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14255 {
14256 unsigned short ud2;
14257
14258 + ip = ktla_ktva(ip);
14259 if (ip < PAGE_OFFSET)
14260 return 0;
14261 if (probe_kernel_address((unsigned short *)ip, ud2))
14262 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14263
14264 return ud2 == 0x0b0f;
14265 }
14266 +
14267 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14268 +void pax_check_alloca(unsigned long size)
14269 +{
14270 + unsigned long sp = (unsigned long)&sp, stack_left;
14271 +
14272 + /* all kernel stacks are of the same size */
14273 + stack_left = sp & (THREAD_SIZE - 1);
14274 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14275 +}
14276 +EXPORT_SYMBOL(pax_check_alloca);
14277 +#endif
14278 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14279 index 6d728d9..279514e 100644
14280 --- a/arch/x86/kernel/dumpstack_64.c
14281 +++ b/arch/x86/kernel/dumpstack_64.c
14282 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14283 unsigned long *irq_stack_end =
14284 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14285 unsigned used = 0;
14286 - struct thread_info *tinfo;
14287 int graph = 0;
14288 unsigned long dummy;
14289 + void *stack_start;
14290
14291 if (!task)
14292 task = current;
14293 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14294 * current stack address. If the stacks consist of nested
14295 * exceptions
14296 */
14297 - tinfo = task_thread_info(task);
14298 for (;;) {
14299 char *id;
14300 unsigned long *estack_end;
14301 +
14302 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14303 &used, &id);
14304
14305 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14306 if (ops->stack(data, id) < 0)
14307 break;
14308
14309 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14310 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14311 data, estack_end, &graph);
14312 ops->stack(data, "<EOE>");
14313 /*
14314 @@ -172,7 +172,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14315 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14316 if (ops->stack(data, "IRQ") < 0)
14317 break;
14318 - bp = ops->walk_stack(tinfo, stack, bp,
14319 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14320 ops, data, irq_stack_end, &graph);
14321 /*
14322 * We link to the next stack (which would be
14323 @@ -191,7 +191,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14324 /*
14325 * This handles the process stack:
14326 */
14327 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14328 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14329 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14330 put_cpu();
14331 }
14332 EXPORT_SYMBOL(dump_trace);
14333 @@ -305,3 +306,50 @@ int is_valid_bugaddr(unsigned long ip)
14334
14335 return ud2 == 0x0b0f;
14336 }
14337 +
14338 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14339 +void pax_check_alloca(unsigned long size)
14340 +{
14341 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14342 + unsigned cpu, used;
14343 + char *id;
14344 +
14345 + /* check the process stack first */
14346 + stack_start = (unsigned long)task_stack_page(current);
14347 + stack_end = stack_start + THREAD_SIZE;
14348 + if (likely(stack_start <= sp && sp < stack_end)) {
14349 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14350 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14351 + return;
14352 + }
14353 +
14354 + cpu = get_cpu();
14355 +
14356 + /* check the irq stacks */
14357 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14358 + stack_start = stack_end - IRQ_STACK_SIZE;
14359 + if (stack_start <= sp && sp < stack_end) {
14360 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14361 + put_cpu();
14362 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14363 + return;
14364 + }
14365 +
14366 + /* check the exception stacks */
14367 + used = 0;
14368 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14369 + stack_start = stack_end - EXCEPTION_STKSZ;
14370 + if (stack_end && stack_start <= sp && sp < stack_end) {
14371 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14372 + put_cpu();
14373 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14374 + return;
14375 + }
14376 +
14377 + put_cpu();
14378 +
14379 + /* unknown stack */
14380 + BUG();
14381 +}
14382 +EXPORT_SYMBOL(pax_check_alloca);
14383 +#endif
14384 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14385 index cd28a35..c72ed9a 100644
14386 --- a/arch/x86/kernel/early_printk.c
14387 +++ b/arch/x86/kernel/early_printk.c
14388 @@ -7,6 +7,7 @@
14389 #include <linux/pci_regs.h>
14390 #include <linux/pci_ids.h>
14391 #include <linux/errno.h>
14392 +#include <linux/sched.h>
14393 #include <asm/io.h>
14394 #include <asm/processor.h>
14395 #include <asm/fcntl.h>
14396 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14397 index f3f6f53..0841b66 100644
14398 --- a/arch/x86/kernel/entry_32.S
14399 +++ b/arch/x86/kernel/entry_32.S
14400 @@ -186,13 +186,146 @@
14401 /*CFI_REL_OFFSET gs, PT_GS*/
14402 .endm
14403 .macro SET_KERNEL_GS reg
14404 +
14405 +#ifdef CONFIG_CC_STACKPROTECTOR
14406 movl $(__KERNEL_STACK_CANARY), \reg
14407 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14408 + movl $(__USER_DS), \reg
14409 +#else
14410 + xorl \reg, \reg
14411 +#endif
14412 +
14413 movl \reg, %gs
14414 .endm
14415
14416 #endif /* CONFIG_X86_32_LAZY_GS */
14417
14418 -.macro SAVE_ALL
14419 +.macro pax_enter_kernel
14420 +#ifdef CONFIG_PAX_KERNEXEC
14421 + call pax_enter_kernel
14422 +#endif
14423 +.endm
14424 +
14425 +.macro pax_exit_kernel
14426 +#ifdef CONFIG_PAX_KERNEXEC
14427 + call pax_exit_kernel
14428 +#endif
14429 +.endm
14430 +
14431 +#ifdef CONFIG_PAX_KERNEXEC
14432 +ENTRY(pax_enter_kernel)
14433 +#ifdef CONFIG_PARAVIRT
14434 + pushl %eax
14435 + pushl %ecx
14436 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14437 + mov %eax, %esi
14438 +#else
14439 + mov %cr0, %esi
14440 +#endif
14441 + bts $16, %esi
14442 + jnc 1f
14443 + mov %cs, %esi
14444 + cmp $__KERNEL_CS, %esi
14445 + jz 3f
14446 + ljmp $__KERNEL_CS, $3f
14447 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14448 +2:
14449 +#ifdef CONFIG_PARAVIRT
14450 + mov %esi, %eax
14451 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14452 +#else
14453 + mov %esi, %cr0
14454 +#endif
14455 +3:
14456 +#ifdef CONFIG_PARAVIRT
14457 + popl %ecx
14458 + popl %eax
14459 +#endif
14460 + ret
14461 +ENDPROC(pax_enter_kernel)
14462 +
14463 +ENTRY(pax_exit_kernel)
14464 +#ifdef CONFIG_PARAVIRT
14465 + pushl %eax
14466 + pushl %ecx
14467 +#endif
14468 + mov %cs, %esi
14469 + cmp $__KERNEXEC_KERNEL_CS, %esi
14470 + jnz 2f
14471 +#ifdef CONFIG_PARAVIRT
14472 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14473 + mov %eax, %esi
14474 +#else
14475 + mov %cr0, %esi
14476 +#endif
14477 + btr $16, %esi
14478 + ljmp $__KERNEL_CS, $1f
14479 +1:
14480 +#ifdef CONFIG_PARAVIRT
14481 + mov %esi, %eax
14482 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14483 +#else
14484 + mov %esi, %cr0
14485 +#endif
14486 +2:
14487 +#ifdef CONFIG_PARAVIRT
14488 + popl %ecx
14489 + popl %eax
14490 +#endif
14491 + ret
14492 +ENDPROC(pax_exit_kernel)
14493 +#endif
14494 +
14495 +.macro pax_erase_kstack
14496 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14497 + call pax_erase_kstack
14498 +#endif
14499 +.endm
14500 +
14501 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14502 +/*
14503 + * ebp: thread_info
14504 + * ecx, edx: can be clobbered
14505 + */
14506 +ENTRY(pax_erase_kstack)
14507 + pushl %edi
14508 + pushl %eax
14509 +
14510 + mov TI_lowest_stack(%ebp), %edi
14511 + mov $-0xBEEF, %eax
14512 + std
14513 +
14514 +1: mov %edi, %ecx
14515 + and $THREAD_SIZE_asm - 1, %ecx
14516 + shr $2, %ecx
14517 + repne scasl
14518 + jecxz 2f
14519 +
14520 + cmp $2*16, %ecx
14521 + jc 2f
14522 +
14523 + mov $2*16, %ecx
14524 + repe scasl
14525 + jecxz 2f
14526 + jne 1b
14527 +
14528 +2: cld
14529 + mov %esp, %ecx
14530 + sub %edi, %ecx
14531 + shr $2, %ecx
14532 + rep stosl
14533 +
14534 + mov TI_task_thread_sp0(%ebp), %edi
14535 + sub $128, %edi
14536 + mov %edi, TI_lowest_stack(%ebp)
14537 +
14538 + popl %eax
14539 + popl %edi
14540 + ret
14541 +ENDPROC(pax_erase_kstack)
14542 +#endif
14543 +
14544 +.macro __SAVE_ALL _DS
14545 cld
14546 PUSH_GS
14547 pushl_cfi %fs
14548 @@ -215,7 +348,7 @@
14549 CFI_REL_OFFSET ecx, 0
14550 pushl_cfi %ebx
14551 CFI_REL_OFFSET ebx, 0
14552 - movl $(__USER_DS), %edx
14553 + movl $\_DS, %edx
14554 movl %edx, %ds
14555 movl %edx, %es
14556 movl $(__KERNEL_PERCPU), %edx
14557 @@ -223,6 +356,15 @@
14558 SET_KERNEL_GS %edx
14559 .endm
14560
14561 +.macro SAVE_ALL
14562 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
14563 + __SAVE_ALL __KERNEL_DS
14564 + pax_enter_kernel
14565 +#else
14566 + __SAVE_ALL __USER_DS
14567 +#endif
14568 +.endm
14569 +
14570 .macro RESTORE_INT_REGS
14571 popl_cfi %ebx
14572 CFI_RESTORE ebx
14573 @@ -308,7 +450,7 @@ ENTRY(ret_from_fork)
14574 popfl_cfi
14575 jmp syscall_exit
14576 CFI_ENDPROC
14577 -END(ret_from_fork)
14578 +ENDPROC(ret_from_fork)
14579
14580 /*
14581 * Interrupt exit functions should be protected against kprobes
14582 @@ -333,7 +475,15 @@ check_userspace:
14583 movb PT_CS(%esp), %al
14584 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
14585 cmpl $USER_RPL, %eax
14586 +
14587 +#ifdef CONFIG_PAX_KERNEXEC
14588 + jae resume_userspace
14589 +
14590 + PAX_EXIT_KERNEL
14591 + jmp resume_kernel
14592 +#else
14593 jb resume_kernel # not returning to v8086 or userspace
14594 +#endif
14595
14596 ENTRY(resume_userspace)
14597 LOCKDEP_SYS_EXIT
14598 @@ -345,8 +495,8 @@ ENTRY(resume_userspace)
14599 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
14600 # int/exception return?
14601 jne work_pending
14602 - jmp restore_all
14603 -END(ret_from_exception)
14604 + jmp restore_all_pax
14605 +ENDPROC(ret_from_exception)
14606
14607 #ifdef CONFIG_PREEMPT
14608 ENTRY(resume_kernel)
14609 @@ -361,7 +511,7 @@ need_resched:
14610 jz restore_all
14611 call preempt_schedule_irq
14612 jmp need_resched
14613 -END(resume_kernel)
14614 +ENDPROC(resume_kernel)
14615 #endif
14616 CFI_ENDPROC
14617 /*
14618 @@ -395,23 +545,34 @@ sysenter_past_esp:
14619 /*CFI_REL_OFFSET cs, 0*/
14620 /*
14621 * Push current_thread_info()->sysenter_return to the stack.
14622 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
14623 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
14624 */
14625 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
14626 + pushl_cfi $0
14627 CFI_REL_OFFSET eip, 0
14628
14629 pushl_cfi %eax
14630 SAVE_ALL
14631 + GET_THREAD_INFO(%ebp)
14632 + movl TI_sysenter_return(%ebp),%ebp
14633 + movl %ebp,PT_EIP(%esp)
14634 ENABLE_INTERRUPTS(CLBR_NONE)
14635
14636 /*
14637 * Load the potential sixth argument from user stack.
14638 * Careful about security.
14639 */
14640 + movl PT_OLDESP(%esp),%ebp
14641 +
14642 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14643 + mov PT_OLDSS(%esp),%ds
14644 +1: movl %ds:(%ebp),%ebp
14645 + push %ss
14646 + pop %ds
14647 +#else
14648 cmpl $__PAGE_OFFSET-3,%ebp
14649 jae syscall_fault
14650 1: movl (%ebp),%ebp
14651 +#endif
14652 +
14653 movl %ebp,PT_EBP(%esp)
14654 .section __ex_table,"a"
14655 .align 4
14656 @@ -434,12 +595,24 @@ sysenter_do_call:
14657 testl $_TIF_ALLWORK_MASK, %ecx
14658 jne sysexit_audit
14659 sysenter_exit:
14660 +
14661 +#ifdef CONFIG_PAX_RANDKSTACK
14662 + pushl_cfi %eax
14663 + movl %esp, %eax
14664 + call pax_randomize_kstack
14665 + popl_cfi %eax
14666 +#endif
14667 +
14668 + pax_erase_kstack
14669 +
14670 /* if something modifies registers it must also disable sysexit */
14671 movl PT_EIP(%esp), %edx
14672 movl PT_OLDESP(%esp), %ecx
14673 xorl %ebp,%ebp
14674 TRACE_IRQS_ON
14675 1: mov PT_FS(%esp), %fs
14676 +2: mov PT_DS(%esp), %ds
14677 +3: mov PT_ES(%esp), %es
14678 PTGS_TO_GS
14679 ENABLE_INTERRUPTS_SYSEXIT
14680
14681 @@ -456,6 +629,9 @@ sysenter_audit:
14682 movl %eax,%edx /* 2nd arg: syscall number */
14683 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
14684 call audit_syscall_entry
14685 +
14686 + pax_erase_kstack
14687 +
14688 pushl_cfi %ebx
14689 movl PT_EAX(%esp),%eax /* reload syscall number */
14690 jmp sysenter_do_call
14691 @@ -482,11 +658,17 @@ sysexit_audit:
14692
14693 CFI_ENDPROC
14694 .pushsection .fixup,"ax"
14695 -2: movl $0,PT_FS(%esp)
14696 +4: movl $0,PT_FS(%esp)
14697 + jmp 1b
14698 +5: movl $0,PT_DS(%esp)
14699 + jmp 1b
14700 +6: movl $0,PT_ES(%esp)
14701 jmp 1b
14702 .section __ex_table,"a"
14703 .align 4
14704 - .long 1b,2b
14705 + .long 1b,4b
14706 + .long 2b,5b
14707 + .long 3b,6b
14708 .popsection
14709 PTGS_TO_GS_EX
14710 ENDPROC(ia32_sysenter_target)
14711 @@ -519,6 +701,15 @@ syscall_exit:
14712 testl $_TIF_ALLWORK_MASK, %ecx # current->work
14713 jne syscall_exit_work
14714
14715 +restore_all_pax:
14716 +
14717 +#ifdef CONFIG_PAX_RANDKSTACK
14718 + movl %esp, %eax
14719 + call pax_randomize_kstack
14720 +#endif
14721 +
14722 + pax_erase_kstack
14723 +
14724 restore_all:
14725 TRACE_IRQS_IRET
14726 restore_all_notrace:
14727 @@ -578,14 +769,34 @@ ldt_ss:
14728 * compensating for the offset by changing to the ESPFIX segment with
14729 * a base address that matches for the difference.
14730 */
14731 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
14732 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
14733 mov %esp, %edx /* load kernel esp */
14734 mov PT_OLDESP(%esp), %eax /* load userspace esp */
14735 mov %dx, %ax /* eax: new kernel esp */
14736 sub %eax, %edx /* offset (low word is 0) */
14737 +#ifdef CONFIG_SMP
14738 + movl PER_CPU_VAR(cpu_number), %ebx
14739 + shll $PAGE_SHIFT_asm, %ebx
14740 + addl $cpu_gdt_table, %ebx
14741 +#else
14742 + movl $cpu_gdt_table, %ebx
14743 +#endif
14744 shr $16, %edx
14745 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
14746 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
14747 +
14748 +#ifdef CONFIG_PAX_KERNEXEC
14749 + mov %cr0, %esi
14750 + btr $16, %esi
14751 + mov %esi, %cr0
14752 +#endif
14753 +
14754 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
14755 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
14756 +
14757 +#ifdef CONFIG_PAX_KERNEXEC
14758 + bts $16, %esi
14759 + mov %esi, %cr0
14760 +#endif
14761 +
14762 pushl_cfi $__ESPFIX_SS
14763 pushl_cfi %eax /* new kernel esp */
14764 /* Disable interrupts, but do not irqtrace this section: we
14765 @@ -614,34 +825,28 @@ work_resched:
14766 movl TI_flags(%ebp), %ecx
14767 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
14768 # than syscall tracing?
14769 - jz restore_all
14770 + jz restore_all_pax
14771 testb $_TIF_NEED_RESCHED, %cl
14772 jnz work_resched
14773
14774 work_notifysig: # deal with pending signals and
14775 # notify-resume requests
14776 + movl %esp, %eax
14777 #ifdef CONFIG_VM86
14778 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
14779 - movl %esp, %eax
14780 - jne work_notifysig_v86 # returning to kernel-space or
14781 + jz 1f # returning to kernel-space or
14782 # vm86-space
14783 - xorl %edx, %edx
14784 - call do_notify_resume
14785 - jmp resume_userspace_sig
14786
14787 - ALIGN
14788 -work_notifysig_v86:
14789 pushl_cfi %ecx # save ti_flags for do_notify_resume
14790 call save_v86_state # %eax contains pt_regs pointer
14791 popl_cfi %ecx
14792 movl %eax, %esp
14793 -#else
14794 - movl %esp, %eax
14795 +1:
14796 #endif
14797 xorl %edx, %edx
14798 call do_notify_resume
14799 jmp resume_userspace_sig
14800 -END(work_pending)
14801 +ENDPROC(work_pending)
14802
14803 # perform syscall exit tracing
14804 ALIGN
14805 @@ -649,11 +854,14 @@ syscall_trace_entry:
14806 movl $-ENOSYS,PT_EAX(%esp)
14807 movl %esp, %eax
14808 call syscall_trace_enter
14809 +
14810 + pax_erase_kstack
14811 +
14812 /* What it returned is what we'll actually use. */
14813 cmpl $(nr_syscalls), %eax
14814 jnae syscall_call
14815 jmp syscall_exit
14816 -END(syscall_trace_entry)
14817 +ENDPROC(syscall_trace_entry)
14818
14819 # perform syscall exit tracing
14820 ALIGN
14821 @@ -666,20 +874,24 @@ syscall_exit_work:
14822 movl %esp, %eax
14823 call syscall_trace_leave
14824 jmp resume_userspace
14825 -END(syscall_exit_work)
14826 +ENDPROC(syscall_exit_work)
14827 CFI_ENDPROC
14828
14829 RING0_INT_FRAME # can't unwind into user space anyway
14830 syscall_fault:
14831 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14832 + push %ss
14833 + pop %ds
14834 +#endif
14835 GET_THREAD_INFO(%ebp)
14836 movl $-EFAULT,PT_EAX(%esp)
14837 jmp resume_userspace
14838 -END(syscall_fault)
14839 +ENDPROC(syscall_fault)
14840
14841 syscall_badsys:
14842 movl $-ENOSYS,PT_EAX(%esp)
14843 jmp resume_userspace
14844 -END(syscall_badsys)
14845 +ENDPROC(syscall_badsys)
14846 CFI_ENDPROC
14847 /*
14848 * End of kprobes section
14849 @@ -753,6 +965,36 @@ ptregs_clone:
14850 CFI_ENDPROC
14851 ENDPROC(ptregs_clone)
14852
14853 + ALIGN;
14854 +ENTRY(kernel_execve)
14855 + CFI_STARTPROC
14856 + pushl_cfi %ebp
14857 + sub $PT_OLDSS+4,%esp
14858 + pushl_cfi %edi
14859 + pushl_cfi %ecx
14860 + pushl_cfi %eax
14861 + lea 3*4(%esp),%edi
14862 + mov $PT_OLDSS/4+1,%ecx
14863 + xorl %eax,%eax
14864 + rep stosl
14865 + popl_cfi %eax
14866 + popl_cfi %ecx
14867 + popl_cfi %edi
14868 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
14869 + pushl_cfi %esp
14870 + call sys_execve
14871 + add $4,%esp
14872 + CFI_ADJUST_CFA_OFFSET -4
14873 + GET_THREAD_INFO(%ebp)
14874 + test %eax,%eax
14875 + jz syscall_exit
14876 + add $PT_OLDSS+4,%esp
14877 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
14878 + popl_cfi %ebp
14879 + ret
14880 + CFI_ENDPROC
14881 +ENDPROC(kernel_execve)
14882 +
14883 .macro FIXUP_ESPFIX_STACK
14884 /*
14885 * Switch back for ESPFIX stack to the normal zerobased stack
14886 @@ -762,8 +1004,15 @@ ENDPROC(ptregs_clone)
14887 * normal stack and adjusts ESP with the matching offset.
14888 */
14889 /* fixup the stack */
14890 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
14891 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
14892 +#ifdef CONFIG_SMP
14893 + movl PER_CPU_VAR(cpu_number), %ebx
14894 + shll $PAGE_SHIFT_asm, %ebx
14895 + addl $cpu_gdt_table, %ebx
14896 +#else
14897 + movl $cpu_gdt_table, %ebx
14898 +#endif
14899 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
14900 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
14901 shl $16, %eax
14902 addl %esp, %eax /* the adjusted stack pointer */
14903 pushl_cfi $__KERNEL_DS
14904 @@ -816,7 +1065,7 @@ vector=vector+1
14905 .endr
14906 2: jmp common_interrupt
14907 .endr
14908 -END(irq_entries_start)
14909 +ENDPROC(irq_entries_start)
14910
14911 .previous
14912 END(interrupt)
14913 @@ -864,7 +1113,7 @@ ENTRY(coprocessor_error)
14914 pushl_cfi $do_coprocessor_error
14915 jmp error_code
14916 CFI_ENDPROC
14917 -END(coprocessor_error)
14918 +ENDPROC(coprocessor_error)
14919
14920 ENTRY(simd_coprocessor_error)
14921 RING0_INT_FRAME
14922 @@ -885,7 +1134,7 @@ ENTRY(simd_coprocessor_error)
14923 #endif
14924 jmp error_code
14925 CFI_ENDPROC
14926 -END(simd_coprocessor_error)
14927 +ENDPROC(simd_coprocessor_error)
14928
14929 ENTRY(device_not_available)
14930 RING0_INT_FRAME
14931 @@ -893,7 +1142,7 @@ ENTRY(device_not_available)
14932 pushl_cfi $do_device_not_available
14933 jmp error_code
14934 CFI_ENDPROC
14935 -END(device_not_available)
14936 +ENDPROC(device_not_available)
14937
14938 #ifdef CONFIG_PARAVIRT
14939 ENTRY(native_iret)
14940 @@ -902,12 +1151,12 @@ ENTRY(native_iret)
14941 .align 4
14942 .long native_iret, iret_exc
14943 .previous
14944 -END(native_iret)
14945 +ENDPROC(native_iret)
14946
14947 ENTRY(native_irq_enable_sysexit)
14948 sti
14949 sysexit
14950 -END(native_irq_enable_sysexit)
14951 +ENDPROC(native_irq_enable_sysexit)
14952 #endif
14953
14954 ENTRY(overflow)
14955 @@ -916,7 +1165,7 @@ ENTRY(overflow)
14956 pushl_cfi $do_overflow
14957 jmp error_code
14958 CFI_ENDPROC
14959 -END(overflow)
14960 +ENDPROC(overflow)
14961
14962 ENTRY(bounds)
14963 RING0_INT_FRAME
14964 @@ -924,7 +1173,7 @@ ENTRY(bounds)
14965 pushl_cfi $do_bounds
14966 jmp error_code
14967 CFI_ENDPROC
14968 -END(bounds)
14969 +ENDPROC(bounds)
14970
14971 ENTRY(invalid_op)
14972 RING0_INT_FRAME
14973 @@ -932,7 +1181,7 @@ ENTRY(invalid_op)
14974 pushl_cfi $do_invalid_op
14975 jmp error_code
14976 CFI_ENDPROC
14977 -END(invalid_op)
14978 +ENDPROC(invalid_op)
14979
14980 ENTRY(coprocessor_segment_overrun)
14981 RING0_INT_FRAME
14982 @@ -940,35 +1189,35 @@ ENTRY(coprocessor_segment_overrun)
14983 pushl_cfi $do_coprocessor_segment_overrun
14984 jmp error_code
14985 CFI_ENDPROC
14986 -END(coprocessor_segment_overrun)
14987 +ENDPROC(coprocessor_segment_overrun)
14988
14989 ENTRY(invalid_TSS)
14990 RING0_EC_FRAME
14991 pushl_cfi $do_invalid_TSS
14992 jmp error_code
14993 CFI_ENDPROC
14994 -END(invalid_TSS)
14995 +ENDPROC(invalid_TSS)
14996
14997 ENTRY(segment_not_present)
14998 RING0_EC_FRAME
14999 pushl_cfi $do_segment_not_present
15000 jmp error_code
15001 CFI_ENDPROC
15002 -END(segment_not_present)
15003 +ENDPROC(segment_not_present)
15004
15005 ENTRY(stack_segment)
15006 RING0_EC_FRAME
15007 pushl_cfi $do_stack_segment
15008 jmp error_code
15009 CFI_ENDPROC
15010 -END(stack_segment)
15011 +ENDPROC(stack_segment)
15012
15013 ENTRY(alignment_check)
15014 RING0_EC_FRAME
15015 pushl_cfi $do_alignment_check
15016 jmp error_code
15017 CFI_ENDPROC
15018 -END(alignment_check)
15019 +ENDPROC(alignment_check)
15020
15021 ENTRY(divide_error)
15022 RING0_INT_FRAME
15023 @@ -976,7 +1225,7 @@ ENTRY(divide_error)
15024 pushl_cfi $do_divide_error
15025 jmp error_code
15026 CFI_ENDPROC
15027 -END(divide_error)
15028 +ENDPROC(divide_error)
15029
15030 #ifdef CONFIG_X86_MCE
15031 ENTRY(machine_check)
15032 @@ -985,7 +1234,7 @@ ENTRY(machine_check)
15033 pushl_cfi machine_check_vector
15034 jmp error_code
15035 CFI_ENDPROC
15036 -END(machine_check)
15037 +ENDPROC(machine_check)
15038 #endif
15039
15040 ENTRY(spurious_interrupt_bug)
15041 @@ -994,7 +1243,7 @@ ENTRY(spurious_interrupt_bug)
15042 pushl_cfi $do_spurious_interrupt_bug
15043 jmp error_code
15044 CFI_ENDPROC
15045 -END(spurious_interrupt_bug)
15046 +ENDPROC(spurious_interrupt_bug)
15047 /*
15048 * End of kprobes section
15049 */
15050 @@ -1109,7 +1358,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15051
15052 ENTRY(mcount)
15053 ret
15054 -END(mcount)
15055 +ENDPROC(mcount)
15056
15057 ENTRY(ftrace_caller)
15058 cmpl $0, function_trace_stop
15059 @@ -1138,7 +1387,7 @@ ftrace_graph_call:
15060 .globl ftrace_stub
15061 ftrace_stub:
15062 ret
15063 -END(ftrace_caller)
15064 +ENDPROC(ftrace_caller)
15065
15066 #else /* ! CONFIG_DYNAMIC_FTRACE */
15067
15068 @@ -1174,7 +1423,7 @@ trace:
15069 popl %ecx
15070 popl %eax
15071 jmp ftrace_stub
15072 -END(mcount)
15073 +ENDPROC(mcount)
15074 #endif /* CONFIG_DYNAMIC_FTRACE */
15075 #endif /* CONFIG_FUNCTION_TRACER */
15076
15077 @@ -1195,7 +1444,7 @@ ENTRY(ftrace_graph_caller)
15078 popl %ecx
15079 popl %eax
15080 ret
15081 -END(ftrace_graph_caller)
15082 +ENDPROC(ftrace_graph_caller)
15083
15084 .globl return_to_handler
15085 return_to_handler:
15086 @@ -1209,7 +1458,6 @@ return_to_handler:
15087 jmp *%ecx
15088 #endif
15089
15090 -.section .rodata,"a"
15091 #include "syscall_table_32.S"
15092
15093 syscall_table_size=(.-sys_call_table)
15094 @@ -1255,15 +1503,18 @@ error_code:
15095 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15096 REG_TO_PTGS %ecx
15097 SET_KERNEL_GS %ecx
15098 - movl $(__USER_DS), %ecx
15099 + movl $(__KERNEL_DS), %ecx
15100 movl %ecx, %ds
15101 movl %ecx, %es
15102 +
15103 + pax_enter_kernel
15104 +
15105 TRACE_IRQS_OFF
15106 movl %esp,%eax # pt_regs pointer
15107 call *%edi
15108 jmp ret_from_exception
15109 CFI_ENDPROC
15110 -END(page_fault)
15111 +ENDPROC(page_fault)
15112
15113 /*
15114 * Debug traps and NMI can happen at the one SYSENTER instruction
15115 @@ -1305,7 +1556,7 @@ debug_stack_correct:
15116 call do_debug
15117 jmp ret_from_exception
15118 CFI_ENDPROC
15119 -END(debug)
15120 +ENDPROC(debug)
15121
15122 /*
15123 * NMI is doubly nasty. It can happen _while_ we're handling
15124 @@ -1342,6 +1593,9 @@ nmi_stack_correct:
15125 xorl %edx,%edx # zero error code
15126 movl %esp,%eax # pt_regs pointer
15127 call do_nmi
15128 +
15129 + pax_exit_kernel
15130 +
15131 jmp restore_all_notrace
15132 CFI_ENDPROC
15133
15134 @@ -1378,12 +1632,15 @@ nmi_espfix_stack:
15135 FIXUP_ESPFIX_STACK # %eax == %esp
15136 xorl %edx,%edx # zero error code
15137 call do_nmi
15138 +
15139 + pax_exit_kernel
15140 +
15141 RESTORE_REGS
15142 lss 12+4(%esp), %esp # back to espfix stack
15143 CFI_ADJUST_CFA_OFFSET -24
15144 jmp irq_return
15145 CFI_ENDPROC
15146 -END(nmi)
15147 +ENDPROC(nmi)
15148
15149 ENTRY(int3)
15150 RING0_INT_FRAME
15151 @@ -1395,14 +1652,14 @@ ENTRY(int3)
15152 call do_int3
15153 jmp ret_from_exception
15154 CFI_ENDPROC
15155 -END(int3)
15156 +ENDPROC(int3)
15157
15158 ENTRY(general_protection)
15159 RING0_EC_FRAME
15160 pushl_cfi $do_general_protection
15161 jmp error_code
15162 CFI_ENDPROC
15163 -END(general_protection)
15164 +ENDPROC(general_protection)
15165
15166 #ifdef CONFIG_KVM_GUEST
15167 ENTRY(async_page_fault)
15168 @@ -1410,7 +1667,7 @@ ENTRY(async_page_fault)
15169 pushl_cfi $do_async_page_fault
15170 jmp error_code
15171 CFI_ENDPROC
15172 -END(async_page_fault)
15173 +ENDPROC(async_page_fault)
15174 #endif
15175
15176 /*
15177 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15178 index faf8d5e..4f16a68 100644
15179 --- a/arch/x86/kernel/entry_64.S
15180 +++ b/arch/x86/kernel/entry_64.S
15181 @@ -55,6 +55,8 @@
15182 #include <asm/paravirt.h>
15183 #include <asm/ftrace.h>
15184 #include <asm/percpu.h>
15185 +#include <asm/pgtable.h>
15186 +#include <asm/alternative-asm.h>
15187
15188 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15189 #include <linux/elf-em.h>
15190 @@ -68,8 +70,9 @@
15191 #ifdef CONFIG_FUNCTION_TRACER
15192 #ifdef CONFIG_DYNAMIC_FTRACE
15193 ENTRY(mcount)
15194 + pax_force_retaddr
15195 retq
15196 -END(mcount)
15197 +ENDPROC(mcount)
15198
15199 ENTRY(ftrace_caller)
15200 cmpl $0, function_trace_stop
15201 @@ -92,8 +95,9 @@ GLOBAL(ftrace_graph_call)
15202 #endif
15203
15204 GLOBAL(ftrace_stub)
15205 + pax_force_retaddr
15206 retq
15207 -END(ftrace_caller)
15208 +ENDPROC(ftrace_caller)
15209
15210 #else /* ! CONFIG_DYNAMIC_FTRACE */
15211 ENTRY(mcount)
15212 @@ -112,6 +116,7 @@ ENTRY(mcount)
15213 #endif
15214
15215 GLOBAL(ftrace_stub)
15216 + pax_force_retaddr
15217 retq
15218
15219 trace:
15220 @@ -121,12 +126,13 @@ trace:
15221 movq 8(%rbp), %rsi
15222 subq $MCOUNT_INSN_SIZE, %rdi
15223
15224 + pax_force_fptr ftrace_trace_function
15225 call *ftrace_trace_function
15226
15227 MCOUNT_RESTORE_FRAME
15228
15229 jmp ftrace_stub
15230 -END(mcount)
15231 +ENDPROC(mcount)
15232 #endif /* CONFIG_DYNAMIC_FTRACE */
15233 #endif /* CONFIG_FUNCTION_TRACER */
15234
15235 @@ -146,8 +152,9 @@ ENTRY(ftrace_graph_caller)
15236
15237 MCOUNT_RESTORE_FRAME
15238
15239 + pax_force_retaddr
15240 retq
15241 -END(ftrace_graph_caller)
15242 +ENDPROC(ftrace_graph_caller)
15243
15244 GLOBAL(return_to_handler)
15245 subq $24, %rsp
15246 @@ -163,6 +170,7 @@ GLOBAL(return_to_handler)
15247 movq 8(%rsp), %rdx
15248 movq (%rsp), %rax
15249 addq $24, %rsp
15250 + pax_force_fptr %rdi
15251 jmp *%rdi
15252 #endif
15253
15254 @@ -178,6 +186,282 @@ ENTRY(native_usergs_sysret64)
15255 ENDPROC(native_usergs_sysret64)
15256 #endif /* CONFIG_PARAVIRT */
15257
15258 + .macro ljmpq sel, off
15259 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15260 + .byte 0x48; ljmp *1234f(%rip)
15261 + .pushsection .rodata
15262 + .align 16
15263 + 1234: .quad \off; .word \sel
15264 + .popsection
15265 +#else
15266 + pushq $\sel
15267 + pushq $\off
15268 + lretq
15269 +#endif
15270 + .endm
15271 +
15272 + .macro pax_enter_kernel
15273 + pax_set_fptr_mask
15274 +#ifdef CONFIG_PAX_KERNEXEC
15275 + call pax_enter_kernel
15276 +#endif
15277 + .endm
15278 +
15279 + .macro pax_exit_kernel
15280 +#ifdef CONFIG_PAX_KERNEXEC
15281 + call pax_exit_kernel
15282 +#endif
15283 + .endm
15284 +
15285 +#ifdef CONFIG_PAX_KERNEXEC
15286 +ENTRY(pax_enter_kernel)
15287 + pushq %rdi
15288 +
15289 +#ifdef CONFIG_PARAVIRT
15290 + PV_SAVE_REGS(CLBR_RDI)
15291 +#endif
15292 +
15293 + GET_CR0_INTO_RDI
15294 + bts $16,%rdi
15295 + jnc 3f
15296 + mov %cs,%edi
15297 + cmp $__KERNEL_CS,%edi
15298 + jnz 2f
15299 +1:
15300 +
15301 +#ifdef CONFIG_PARAVIRT
15302 + PV_RESTORE_REGS(CLBR_RDI)
15303 +#endif
15304 +
15305 + popq %rdi
15306 + pax_force_retaddr
15307 + retq
15308 +
15309 +2: ljmpq __KERNEL_CS,1f
15310 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15311 +4: SET_RDI_INTO_CR0
15312 + jmp 1b
15313 +ENDPROC(pax_enter_kernel)
15314 +
15315 +ENTRY(pax_exit_kernel)
15316 + pushq %rdi
15317 +
15318 +#ifdef CONFIG_PARAVIRT
15319 + PV_SAVE_REGS(CLBR_RDI)
15320 +#endif
15321 +
15322 + mov %cs,%rdi
15323 + cmp $__KERNEXEC_KERNEL_CS,%edi
15324 + jz 2f
15325 +1:
15326 +
15327 +#ifdef CONFIG_PARAVIRT
15328 + PV_RESTORE_REGS(CLBR_RDI);
15329 +#endif
15330 +
15331 + popq %rdi
15332 + pax_force_retaddr
15333 + retq
15334 +
15335 +2: GET_CR0_INTO_RDI
15336 + btr $16,%rdi
15337 + ljmpq __KERNEL_CS,3f
15338 +3: SET_RDI_INTO_CR0
15339 + jmp 1b
15340 +#ifdef CONFIG_PARAVIRT
15341 + PV_RESTORE_REGS(CLBR_RDI);
15342 +#endif
15343 +
15344 + popq %rdi
15345 + pax_force_retaddr
15346 + retq
15347 +ENDPROC(pax_exit_kernel)
15348 +#endif
15349 +
15350 + .macro pax_enter_kernel_user
15351 + pax_set_fptr_mask
15352 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15353 + call pax_enter_kernel_user
15354 +#endif
15355 + .endm
15356 +
15357 + .macro pax_exit_kernel_user
15358 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15359 + call pax_exit_kernel_user
15360 +#endif
15361 +#ifdef CONFIG_PAX_RANDKSTACK
15362 + pushq %rax
15363 + call pax_randomize_kstack
15364 + popq %rax
15365 +#endif
15366 + .endm
15367 +
15368 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15369 +ENTRY(pax_enter_kernel_user)
15370 + pushq %rdi
15371 + pushq %rbx
15372 +
15373 +#ifdef CONFIG_PARAVIRT
15374 + PV_SAVE_REGS(CLBR_RDI)
15375 +#endif
15376 +
15377 + GET_CR3_INTO_RDI
15378 + mov %rdi,%rbx
15379 + add $__START_KERNEL_map,%rbx
15380 + sub phys_base(%rip),%rbx
15381 +
15382 +#ifdef CONFIG_PARAVIRT
15383 + pushq %rdi
15384 + cmpl $0, pv_info+PARAVIRT_enabled
15385 + jz 1f
15386 + i = 0
15387 + .rept USER_PGD_PTRS
15388 + mov i*8(%rbx),%rsi
15389 + mov $0,%sil
15390 + lea i*8(%rbx),%rdi
15391 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15392 + i = i + 1
15393 + .endr
15394 + jmp 2f
15395 +1:
15396 +#endif
15397 +
15398 + i = 0
15399 + .rept USER_PGD_PTRS
15400 + movb $0,i*8(%rbx)
15401 + i = i + 1
15402 + .endr
15403 +
15404 +#ifdef CONFIG_PARAVIRT
15405 +2: popq %rdi
15406 +#endif
15407 + SET_RDI_INTO_CR3
15408 +
15409 +#ifdef CONFIG_PAX_KERNEXEC
15410 + GET_CR0_INTO_RDI
15411 + bts $16,%rdi
15412 + SET_RDI_INTO_CR0
15413 +#endif
15414 +
15415 +#ifdef CONFIG_PARAVIRT
15416 + PV_RESTORE_REGS(CLBR_RDI)
15417 +#endif
15418 +
15419 + popq %rbx
15420 + popq %rdi
15421 + pax_force_retaddr
15422 + retq
15423 +ENDPROC(pax_enter_kernel_user)
15424 +
15425 +ENTRY(pax_exit_kernel_user)
15426 + push %rdi
15427 +
15428 +#ifdef CONFIG_PARAVIRT
15429 + pushq %rbx
15430 + PV_SAVE_REGS(CLBR_RDI)
15431 +#endif
15432 +
15433 +#ifdef CONFIG_PAX_KERNEXEC
15434 + GET_CR0_INTO_RDI
15435 + btr $16,%rdi
15436 + SET_RDI_INTO_CR0
15437 +#endif
15438 +
15439 + GET_CR3_INTO_RDI
15440 + add $__START_KERNEL_map,%rdi
15441 + sub phys_base(%rip),%rdi
15442 +
15443 +#ifdef CONFIG_PARAVIRT
15444 + cmpl $0, pv_info+PARAVIRT_enabled
15445 + jz 1f
15446 + mov %rdi,%rbx
15447 + i = 0
15448 + .rept USER_PGD_PTRS
15449 + mov i*8(%rbx),%rsi
15450 + mov $0x67,%sil
15451 + lea i*8(%rbx),%rdi
15452 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15453 + i = i + 1
15454 + .endr
15455 + jmp 2f
15456 +1:
15457 +#endif
15458 +
15459 + i = 0
15460 + .rept USER_PGD_PTRS
15461 + movb $0x67,i*8(%rdi)
15462 + i = i + 1
15463 + .endr
15464 +
15465 +#ifdef CONFIG_PARAVIRT
15466 +2: PV_RESTORE_REGS(CLBR_RDI)
15467 + popq %rbx
15468 +#endif
15469 +
15470 + popq %rdi
15471 + pax_force_retaddr
15472 + retq
15473 +ENDPROC(pax_exit_kernel_user)
15474 +#endif
15475 +
15476 +.macro pax_erase_kstack
15477 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15478 + call pax_erase_kstack
15479 +#endif
15480 +.endm
15481 +
15482 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15483 +/*
15484 + * r11: thread_info
15485 + * rcx, rdx: can be clobbered
15486 + */
15487 +ENTRY(pax_erase_kstack)
15488 + pushq %rdi
15489 + pushq %rax
15490 + pushq %r11
15491 +
15492 + GET_THREAD_INFO(%r11)
15493 + mov TI_lowest_stack(%r11), %rdi
15494 + mov $-0xBEEF, %rax
15495 + std
15496 +
15497 +1: mov %edi, %ecx
15498 + and $THREAD_SIZE_asm - 1, %ecx
15499 + shr $3, %ecx
15500 + repne scasq
15501 + jecxz 2f
15502 +
15503 + cmp $2*8, %ecx
15504 + jc 2f
15505 +
15506 + mov $2*8, %ecx
15507 + repe scasq
15508 + jecxz 2f
15509 + jne 1b
15510 +
15511 +2: cld
15512 + mov %esp, %ecx
15513 + sub %edi, %ecx
15514 +
15515 + cmp $THREAD_SIZE_asm, %rcx
15516 + jb 3f
15517 + ud2
15518 +3:
15519 +
15520 + shr $3, %ecx
15521 + rep stosq
15522 +
15523 + mov TI_task_thread_sp0(%r11), %rdi
15524 + sub $256, %rdi
15525 + mov %rdi, TI_lowest_stack(%r11)
15526 +
15527 + popq %r11
15528 + popq %rax
15529 + popq %rdi
15530 + pax_force_retaddr
15531 + ret
15532 +ENDPROC(pax_erase_kstack)
15533 +#endif
15534
15535 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
15536 #ifdef CONFIG_TRACE_IRQFLAGS
15537 @@ -231,8 +515,8 @@ ENDPROC(native_usergs_sysret64)
15538 .endm
15539
15540 .macro UNFAKE_STACK_FRAME
15541 - addq $8*6, %rsp
15542 - CFI_ADJUST_CFA_OFFSET -(6*8)
15543 + addq $8*6 + ARG_SKIP, %rsp
15544 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
15545 .endm
15546
15547 /*
15548 @@ -319,7 +603,7 @@ ENDPROC(native_usergs_sysret64)
15549 movq %rsp, %rsi
15550
15551 leaq -RBP(%rsp),%rdi /* arg1 for handler */
15552 - testl $3, CS(%rdi)
15553 + testb $3, CS(%rdi)
15554 je 1f
15555 SWAPGS
15556 /*
15557 @@ -355,9 +639,10 @@ ENTRY(save_rest)
15558 movq_cfi r15, R15+16
15559 movq %r11, 8(%rsp) /* return address */
15560 FIXUP_TOP_OF_STACK %r11, 16
15561 + pax_force_retaddr
15562 ret
15563 CFI_ENDPROC
15564 -END(save_rest)
15565 +ENDPROC(save_rest)
15566
15567 /* save complete stack frame */
15568 .pushsection .kprobes.text, "ax"
15569 @@ -386,9 +671,10 @@ ENTRY(save_paranoid)
15570 js 1f /* negative -> in kernel */
15571 SWAPGS
15572 xorl %ebx,%ebx
15573 -1: ret
15574 +1: pax_force_retaddr_bts
15575 + ret
15576 CFI_ENDPROC
15577 -END(save_paranoid)
15578 +ENDPROC(save_paranoid)
15579 .popsection
15580
15581 /*
15582 @@ -410,7 +696,7 @@ ENTRY(ret_from_fork)
15583
15584 RESTORE_REST
15585
15586 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15587 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15588 je int_ret_from_sys_call
15589
15590 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
15591 @@ -420,7 +706,7 @@ ENTRY(ret_from_fork)
15592 jmp ret_from_sys_call # go to the SYSRET fastpath
15593
15594 CFI_ENDPROC
15595 -END(ret_from_fork)
15596 +ENDPROC(ret_from_fork)
15597
15598 /*
15599 * System call entry. Up to 6 arguments in registers are supported.
15600 @@ -456,7 +742,7 @@ END(ret_from_fork)
15601 ENTRY(system_call)
15602 CFI_STARTPROC simple
15603 CFI_SIGNAL_FRAME
15604 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15605 + CFI_DEF_CFA rsp,0
15606 CFI_REGISTER rip,rcx
15607 /*CFI_REGISTER rflags,r11*/
15608 SWAPGS_UNSAFE_STACK
15609 @@ -469,12 +755,13 @@ ENTRY(system_call_after_swapgs)
15610
15611 movq %rsp,PER_CPU_VAR(old_rsp)
15612 movq PER_CPU_VAR(kernel_stack),%rsp
15613 + SAVE_ARGS 8*6,0
15614 + pax_enter_kernel_user
15615 /*
15616 * No need to follow this irqs off/on section - it's straight
15617 * and short:
15618 */
15619 ENABLE_INTERRUPTS(CLBR_NONE)
15620 - SAVE_ARGS 8,0
15621 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15622 movq %rcx,RIP-ARGOFFSET(%rsp)
15623 CFI_REL_OFFSET rip,RIP-ARGOFFSET
15624 @@ -484,7 +771,7 @@ ENTRY(system_call_after_swapgs)
15625 system_call_fastpath:
15626 cmpq $__NR_syscall_max,%rax
15627 ja badsys
15628 - movq %r10,%rcx
15629 + movq R10-ARGOFFSET(%rsp),%rcx
15630 call *sys_call_table(,%rax,8) # XXX: rip relative
15631 movq %rax,RAX-ARGOFFSET(%rsp)
15632 /*
15633 @@ -503,6 +790,8 @@ sysret_check:
15634 andl %edi,%edx
15635 jnz sysret_careful
15636 CFI_REMEMBER_STATE
15637 + pax_exit_kernel_user
15638 + pax_erase_kstack
15639 /*
15640 * sysretq will re-enable interrupts:
15641 */
15642 @@ -554,14 +843,18 @@ badsys:
15643 * jump back to the normal fast path.
15644 */
15645 auditsys:
15646 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
15647 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
15648 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
15649 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
15650 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
15651 movq %rax,%rsi /* 2nd arg: syscall number */
15652 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
15653 call audit_syscall_entry
15654 +
15655 + pax_erase_kstack
15656 +
15657 LOAD_ARGS 0 /* reload call-clobbered registers */
15658 + pax_set_fptr_mask
15659 jmp system_call_fastpath
15660
15661 /*
15662 @@ -591,16 +884,20 @@ tracesys:
15663 FIXUP_TOP_OF_STACK %rdi
15664 movq %rsp,%rdi
15665 call syscall_trace_enter
15666 +
15667 + pax_erase_kstack
15668 +
15669 /*
15670 * Reload arg registers from stack in case ptrace changed them.
15671 * We don't reload %rax because syscall_trace_enter() returned
15672 * the value it wants us to use in the table lookup.
15673 */
15674 LOAD_ARGS ARGOFFSET, 1
15675 + pax_set_fptr_mask
15676 RESTORE_REST
15677 cmpq $__NR_syscall_max,%rax
15678 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
15679 - movq %r10,%rcx /* fixup for C */
15680 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
15681 call *sys_call_table(,%rax,8)
15682 movq %rax,RAX-ARGOFFSET(%rsp)
15683 /* Use IRET because user could have changed frame */
15684 @@ -612,7 +909,7 @@ tracesys:
15685 GLOBAL(int_ret_from_sys_call)
15686 DISABLE_INTERRUPTS(CLBR_NONE)
15687 TRACE_IRQS_OFF
15688 - testl $3,CS-ARGOFFSET(%rsp)
15689 + testb $3,CS-ARGOFFSET(%rsp)
15690 je retint_restore_args
15691 movl $_TIF_ALLWORK_MASK,%edi
15692 /* edi: mask to check */
15693 @@ -623,6 +920,7 @@ GLOBAL(int_with_check)
15694 andl %edi,%edx
15695 jnz int_careful
15696 andl $~TS_COMPAT,TI_status(%rcx)
15697 + pax_erase_kstack
15698 jmp retint_swapgs
15699
15700 /* Either reschedule or signal or syscall exit tracking needed. */
15701 @@ -669,7 +967,7 @@ int_restore_rest:
15702 TRACE_IRQS_OFF
15703 jmp int_with_check
15704 CFI_ENDPROC
15705 -END(system_call)
15706 +ENDPROC(system_call)
15707
15708 /*
15709 * Certain special system calls that need to save a complete full stack frame.
15710 @@ -685,7 +983,7 @@ ENTRY(\label)
15711 call \func
15712 jmp ptregscall_common
15713 CFI_ENDPROC
15714 -END(\label)
15715 +ENDPROC(\label)
15716 .endm
15717
15718 PTREGSCALL stub_clone, sys_clone, %r8
15719 @@ -703,9 +1001,10 @@ ENTRY(ptregscall_common)
15720 movq_cfi_restore R12+8, r12
15721 movq_cfi_restore RBP+8, rbp
15722 movq_cfi_restore RBX+8, rbx
15723 + pax_force_retaddr
15724 ret $REST_SKIP /* pop extended registers */
15725 CFI_ENDPROC
15726 -END(ptregscall_common)
15727 +ENDPROC(ptregscall_common)
15728
15729 ENTRY(stub_execve)
15730 CFI_STARTPROC
15731 @@ -720,7 +1019,7 @@ ENTRY(stub_execve)
15732 RESTORE_REST
15733 jmp int_ret_from_sys_call
15734 CFI_ENDPROC
15735 -END(stub_execve)
15736 +ENDPROC(stub_execve)
15737
15738 /*
15739 * sigreturn is special because it needs to restore all registers on return.
15740 @@ -738,7 +1037,7 @@ ENTRY(stub_rt_sigreturn)
15741 RESTORE_REST
15742 jmp int_ret_from_sys_call
15743 CFI_ENDPROC
15744 -END(stub_rt_sigreturn)
15745 +ENDPROC(stub_rt_sigreturn)
15746
15747 /*
15748 * Build the entry stubs and pointer table with some assembler magic.
15749 @@ -773,7 +1072,7 @@ vector=vector+1
15750 2: jmp common_interrupt
15751 .endr
15752 CFI_ENDPROC
15753 -END(irq_entries_start)
15754 +ENDPROC(irq_entries_start)
15755
15756 .previous
15757 END(interrupt)
15758 @@ -793,6 +1092,16 @@ END(interrupt)
15759 subq $ORIG_RAX-RBP, %rsp
15760 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
15761 SAVE_ARGS_IRQ
15762 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15763 + testb $3, CS(%rdi)
15764 + jnz 1f
15765 + pax_enter_kernel
15766 + jmp 2f
15767 +1: pax_enter_kernel_user
15768 +2:
15769 +#else
15770 + pax_enter_kernel
15771 +#endif
15772 call \func
15773 .endm
15774
15775 @@ -824,7 +1133,7 @@ ret_from_intr:
15776
15777 exit_intr:
15778 GET_THREAD_INFO(%rcx)
15779 - testl $3,CS-ARGOFFSET(%rsp)
15780 + testb $3,CS-ARGOFFSET(%rsp)
15781 je retint_kernel
15782
15783 /* Interrupt came from user space */
15784 @@ -846,12 +1155,15 @@ retint_swapgs: /* return to user-space */
15785 * The iretq could re-enable interrupts:
15786 */
15787 DISABLE_INTERRUPTS(CLBR_ANY)
15788 + pax_exit_kernel_user
15789 TRACE_IRQS_IRETQ
15790 SWAPGS
15791 jmp restore_args
15792
15793 retint_restore_args: /* return to kernel space */
15794 DISABLE_INTERRUPTS(CLBR_ANY)
15795 + pax_exit_kernel
15796 + pax_force_retaddr RIP-ARGOFFSET
15797 /*
15798 * The iretq could re-enable interrupts:
15799 */
15800 @@ -940,7 +1252,7 @@ ENTRY(retint_kernel)
15801 #endif
15802
15803 CFI_ENDPROC
15804 -END(common_interrupt)
15805 +ENDPROC(common_interrupt)
15806 /*
15807 * End of kprobes section
15808 */
15809 @@ -956,7 +1268,7 @@ ENTRY(\sym)
15810 interrupt \do_sym
15811 jmp ret_from_intr
15812 CFI_ENDPROC
15813 -END(\sym)
15814 +ENDPROC(\sym)
15815 .endm
15816
15817 #ifdef CONFIG_SMP
15818 @@ -1021,12 +1333,22 @@ ENTRY(\sym)
15819 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15820 call error_entry
15821 DEFAULT_FRAME 0
15822 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15823 + testb $3, CS(%rsp)
15824 + jnz 1f
15825 + pax_enter_kernel
15826 + jmp 2f
15827 +1: pax_enter_kernel_user
15828 +2:
15829 +#else
15830 + pax_enter_kernel
15831 +#endif
15832 movq %rsp,%rdi /* pt_regs pointer */
15833 xorl %esi,%esi /* no error code */
15834 call \do_sym
15835 jmp error_exit /* %ebx: no swapgs flag */
15836 CFI_ENDPROC
15837 -END(\sym)
15838 +ENDPROC(\sym)
15839 .endm
15840
15841 .macro paranoidzeroentry sym do_sym
15842 @@ -1038,15 +1360,25 @@ ENTRY(\sym)
15843 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15844 call save_paranoid
15845 TRACE_IRQS_OFF
15846 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15847 + testb $3, CS(%rsp)
15848 + jnz 1f
15849 + pax_enter_kernel
15850 + jmp 2f
15851 +1: pax_enter_kernel_user
15852 +2:
15853 +#else
15854 + pax_enter_kernel
15855 +#endif
15856 movq %rsp,%rdi /* pt_regs pointer */
15857 xorl %esi,%esi /* no error code */
15858 call \do_sym
15859 jmp paranoid_exit /* %ebx: no swapgs flag */
15860 CFI_ENDPROC
15861 -END(\sym)
15862 +ENDPROC(\sym)
15863 .endm
15864
15865 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
15866 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
15867 .macro paranoidzeroentry_ist sym do_sym ist
15868 ENTRY(\sym)
15869 INTR_FRAME
15870 @@ -1056,14 +1388,30 @@ ENTRY(\sym)
15871 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15872 call save_paranoid
15873 TRACE_IRQS_OFF
15874 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15875 + testb $3, CS(%rsp)
15876 + jnz 1f
15877 + pax_enter_kernel
15878 + jmp 2f
15879 +1: pax_enter_kernel_user
15880 +2:
15881 +#else
15882 + pax_enter_kernel
15883 +#endif
15884 movq %rsp,%rdi /* pt_regs pointer */
15885 xorl %esi,%esi /* no error code */
15886 +#ifdef CONFIG_SMP
15887 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
15888 + lea init_tss(%r12), %r12
15889 +#else
15890 + lea init_tss(%rip), %r12
15891 +#endif
15892 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
15893 call \do_sym
15894 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
15895 jmp paranoid_exit /* %ebx: no swapgs flag */
15896 CFI_ENDPROC
15897 -END(\sym)
15898 +ENDPROC(\sym)
15899 .endm
15900
15901 .macro errorentry sym do_sym
15902 @@ -1074,13 +1422,23 @@ ENTRY(\sym)
15903 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15904 call error_entry
15905 DEFAULT_FRAME 0
15906 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15907 + testb $3, CS(%rsp)
15908 + jnz 1f
15909 + pax_enter_kernel
15910 + jmp 2f
15911 +1: pax_enter_kernel_user
15912 +2:
15913 +#else
15914 + pax_enter_kernel
15915 +#endif
15916 movq %rsp,%rdi /* pt_regs pointer */
15917 movq ORIG_RAX(%rsp),%rsi /* get error code */
15918 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15919 call \do_sym
15920 jmp error_exit /* %ebx: no swapgs flag */
15921 CFI_ENDPROC
15922 -END(\sym)
15923 +ENDPROC(\sym)
15924 .endm
15925
15926 /* error code is on the stack already */
15927 @@ -1093,13 +1451,23 @@ ENTRY(\sym)
15928 call save_paranoid
15929 DEFAULT_FRAME 0
15930 TRACE_IRQS_OFF
15931 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15932 + testb $3, CS(%rsp)
15933 + jnz 1f
15934 + pax_enter_kernel
15935 + jmp 2f
15936 +1: pax_enter_kernel_user
15937 +2:
15938 +#else
15939 + pax_enter_kernel
15940 +#endif
15941 movq %rsp,%rdi /* pt_regs pointer */
15942 movq ORIG_RAX(%rsp),%rsi /* get error code */
15943 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15944 call \do_sym
15945 jmp paranoid_exit /* %ebx: no swapgs flag */
15946 CFI_ENDPROC
15947 -END(\sym)
15948 +ENDPROC(\sym)
15949 .endm
15950
15951 zeroentry divide_error do_divide_error
15952 @@ -1129,9 +1497,10 @@ gs_change:
15953 2: mfence /* workaround */
15954 SWAPGS
15955 popfq_cfi
15956 + pax_force_retaddr
15957 ret
15958 CFI_ENDPROC
15959 -END(native_load_gs_index)
15960 +ENDPROC(native_load_gs_index)
15961
15962 .section __ex_table,"a"
15963 .align 8
15964 @@ -1153,13 +1522,14 @@ ENTRY(kernel_thread_helper)
15965 * Here we are in the child and the registers are set as they were
15966 * at kernel_thread() invocation in the parent.
15967 */
15968 + pax_force_fptr %rsi
15969 call *%rsi
15970 # exit
15971 mov %eax, %edi
15972 call do_exit
15973 ud2 # padding for call trace
15974 CFI_ENDPROC
15975 -END(kernel_thread_helper)
15976 +ENDPROC(kernel_thread_helper)
15977
15978 /*
15979 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
15980 @@ -1186,11 +1556,11 @@ ENTRY(kernel_execve)
15981 RESTORE_REST
15982 testq %rax,%rax
15983 je int_ret_from_sys_call
15984 - RESTORE_ARGS
15985 UNFAKE_STACK_FRAME
15986 + pax_force_retaddr
15987 ret
15988 CFI_ENDPROC
15989 -END(kernel_execve)
15990 +ENDPROC(kernel_execve)
15991
15992 /* Call softirq on interrupt stack. Interrupts are off. */
15993 ENTRY(call_softirq)
15994 @@ -1208,9 +1578,10 @@ ENTRY(call_softirq)
15995 CFI_DEF_CFA_REGISTER rsp
15996 CFI_ADJUST_CFA_OFFSET -8
15997 decl PER_CPU_VAR(irq_count)
15998 + pax_force_retaddr
15999 ret
16000 CFI_ENDPROC
16001 -END(call_softirq)
16002 +ENDPROC(call_softirq)
16003
16004 #ifdef CONFIG_XEN
16005 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16006 @@ -1248,7 +1619,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16007 decl PER_CPU_VAR(irq_count)
16008 jmp error_exit
16009 CFI_ENDPROC
16010 -END(xen_do_hypervisor_callback)
16011 +ENDPROC(xen_do_hypervisor_callback)
16012
16013 /*
16014 * Hypervisor uses this for application faults while it executes.
16015 @@ -1307,7 +1678,7 @@ ENTRY(xen_failsafe_callback)
16016 SAVE_ALL
16017 jmp error_exit
16018 CFI_ENDPROC
16019 -END(xen_failsafe_callback)
16020 +ENDPROC(xen_failsafe_callback)
16021
16022 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16023 xen_hvm_callback_vector xen_evtchn_do_upcall
16024 @@ -1356,16 +1727,31 @@ ENTRY(paranoid_exit)
16025 TRACE_IRQS_OFF
16026 testl %ebx,%ebx /* swapgs needed? */
16027 jnz paranoid_restore
16028 - testl $3,CS(%rsp)
16029 + testb $3,CS(%rsp)
16030 jnz paranoid_userspace
16031 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16032 + pax_exit_kernel
16033 + TRACE_IRQS_IRETQ 0
16034 + SWAPGS_UNSAFE_STACK
16035 + RESTORE_ALL 8
16036 + pax_force_retaddr_bts
16037 + jmp irq_return
16038 +#endif
16039 paranoid_swapgs:
16040 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16041 + pax_exit_kernel_user
16042 +#else
16043 + pax_exit_kernel
16044 +#endif
16045 TRACE_IRQS_IRETQ 0
16046 SWAPGS_UNSAFE_STACK
16047 RESTORE_ALL 8
16048 jmp irq_return
16049 paranoid_restore:
16050 + pax_exit_kernel
16051 TRACE_IRQS_IRETQ 0
16052 RESTORE_ALL 8
16053 + pax_force_retaddr_bts
16054 jmp irq_return
16055 paranoid_userspace:
16056 GET_THREAD_INFO(%rcx)
16057 @@ -1394,7 +1780,7 @@ paranoid_schedule:
16058 TRACE_IRQS_OFF
16059 jmp paranoid_userspace
16060 CFI_ENDPROC
16061 -END(paranoid_exit)
16062 +ENDPROC(paranoid_exit)
16063
16064 /*
16065 * Exception entry point. This expects an error code/orig_rax on the stack.
16066 @@ -1421,12 +1807,13 @@ ENTRY(error_entry)
16067 movq_cfi r14, R14+8
16068 movq_cfi r15, R15+8
16069 xorl %ebx,%ebx
16070 - testl $3,CS+8(%rsp)
16071 + testb $3,CS+8(%rsp)
16072 je error_kernelspace
16073 error_swapgs:
16074 SWAPGS
16075 error_sti:
16076 TRACE_IRQS_OFF
16077 + pax_force_retaddr_bts
16078 ret
16079
16080 /*
16081 @@ -1453,7 +1840,7 @@ bstep_iret:
16082 movq %rcx,RIP+8(%rsp)
16083 jmp error_swapgs
16084 CFI_ENDPROC
16085 -END(error_entry)
16086 +ENDPROC(error_entry)
16087
16088
16089 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16090 @@ -1473,7 +1860,7 @@ ENTRY(error_exit)
16091 jnz retint_careful
16092 jmp retint_swapgs
16093 CFI_ENDPROC
16094 -END(error_exit)
16095 +ENDPROC(error_exit)
16096
16097
16098 /* runs on exception stack */
16099 @@ -1485,6 +1872,16 @@ ENTRY(nmi)
16100 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16101 call save_paranoid
16102 DEFAULT_FRAME 0
16103 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16104 + testb $3, CS(%rsp)
16105 + jnz 1f
16106 + pax_enter_kernel
16107 + jmp 2f
16108 +1: pax_enter_kernel_user
16109 +2:
16110 +#else
16111 + pax_enter_kernel
16112 +#endif
16113 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16114 movq %rsp,%rdi
16115 movq $-1,%rsi
16116 @@ -1495,12 +1892,28 @@ ENTRY(nmi)
16117 DISABLE_INTERRUPTS(CLBR_NONE)
16118 testl %ebx,%ebx /* swapgs needed? */
16119 jnz nmi_restore
16120 - testl $3,CS(%rsp)
16121 + testb $3,CS(%rsp)
16122 jnz nmi_userspace
16123 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16124 + pax_exit_kernel
16125 + SWAPGS_UNSAFE_STACK
16126 + RESTORE_ALL 8
16127 + pax_force_retaddr_bts
16128 + jmp irq_return
16129 +#endif
16130 nmi_swapgs:
16131 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16132 + pax_exit_kernel_user
16133 +#else
16134 + pax_exit_kernel
16135 +#endif
16136 SWAPGS_UNSAFE_STACK
16137 + RESTORE_ALL 8
16138 + jmp irq_return
16139 nmi_restore:
16140 + pax_exit_kernel
16141 RESTORE_ALL 8
16142 + pax_force_retaddr_bts
16143 jmp irq_return
16144 nmi_userspace:
16145 GET_THREAD_INFO(%rcx)
16146 @@ -1529,14 +1942,14 @@ nmi_schedule:
16147 jmp paranoid_exit
16148 CFI_ENDPROC
16149 #endif
16150 -END(nmi)
16151 +ENDPROC(nmi)
16152
16153 ENTRY(ignore_sysret)
16154 CFI_STARTPROC
16155 mov $-ENOSYS,%eax
16156 sysret
16157 CFI_ENDPROC
16158 -END(ignore_sysret)
16159 +ENDPROC(ignore_sysret)
16160
16161 /*
16162 * End of kprobes section
16163 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16164 index c9a281f..ce2f317 100644
16165 --- a/arch/x86/kernel/ftrace.c
16166 +++ b/arch/x86/kernel/ftrace.c
16167 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
16168 static const void *mod_code_newcode; /* holds the text to write to the IP */
16169
16170 static unsigned nmi_wait_count;
16171 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
16172 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
16173
16174 int ftrace_arch_read_dyn_info(char *buf, int size)
16175 {
16176 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
16177
16178 r = snprintf(buf, size, "%u %u",
16179 nmi_wait_count,
16180 - atomic_read(&nmi_update_count));
16181 + atomic_read_unchecked(&nmi_update_count));
16182 return r;
16183 }
16184
16185 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
16186
16187 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16188 smp_rmb();
16189 + pax_open_kernel();
16190 ftrace_mod_code();
16191 - atomic_inc(&nmi_update_count);
16192 + pax_close_kernel();
16193 + atomic_inc_unchecked(&nmi_update_count);
16194 }
16195 /* Must have previous changes seen before executions */
16196 smp_mb();
16197 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16198 {
16199 unsigned char replaced[MCOUNT_INSN_SIZE];
16200
16201 + ip = ktla_ktva(ip);
16202 +
16203 /*
16204 * Note: Due to modules and __init, code can
16205 * disappear and change, we need to protect against faulting
16206 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16207 unsigned char old[MCOUNT_INSN_SIZE], *new;
16208 int ret;
16209
16210 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16211 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16212 new = ftrace_call_replace(ip, (unsigned long)func);
16213 ret = ftrace_modify_code(ip, old, new);
16214
16215 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16216 {
16217 unsigned char code[MCOUNT_INSN_SIZE];
16218
16219 + ip = ktla_ktva(ip);
16220 +
16221 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16222 return -EFAULT;
16223
16224 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16225 index 3bb0850..55a56f4 100644
16226 --- a/arch/x86/kernel/head32.c
16227 +++ b/arch/x86/kernel/head32.c
16228 @@ -19,6 +19,7 @@
16229 #include <asm/io_apic.h>
16230 #include <asm/bios_ebda.h>
16231 #include <asm/tlbflush.h>
16232 +#include <asm/boot.h>
16233
16234 static void __init i386_default_early_setup(void)
16235 {
16236 @@ -33,7 +34,7 @@ void __init i386_start_kernel(void)
16237 {
16238 memblock_init();
16239
16240 - memblock_x86_reserve_range(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
16241 + memblock_x86_reserve_range(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
16242
16243 #ifdef CONFIG_BLK_DEV_INITRD
16244 /* Reserve INITRD */
16245 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16246 index ce0be7c..c41476e 100644
16247 --- a/arch/x86/kernel/head_32.S
16248 +++ b/arch/x86/kernel/head_32.S
16249 @@ -25,6 +25,12 @@
16250 /* Physical address */
16251 #define pa(X) ((X) - __PAGE_OFFSET)
16252
16253 +#ifdef CONFIG_PAX_KERNEXEC
16254 +#define ta(X) (X)
16255 +#else
16256 +#define ta(X) ((X) - __PAGE_OFFSET)
16257 +#endif
16258 +
16259 /*
16260 * References to members of the new_cpu_data structure.
16261 */
16262 @@ -54,11 +60,7 @@
16263 * and small than max_low_pfn, otherwise will waste some page table entries
16264 */
16265
16266 -#if PTRS_PER_PMD > 1
16267 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16268 -#else
16269 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16270 -#endif
16271 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16272
16273 /* Number of possible pages in the lowmem region */
16274 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16275 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16276 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16277
16278 /*
16279 + * Real beginning of normal "text" segment
16280 + */
16281 +ENTRY(stext)
16282 +ENTRY(_stext)
16283 +
16284 +/*
16285 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16286 * %esi points to the real-mode code as a 32-bit pointer.
16287 * CS and DS must be 4 GB flat segments, but we don't depend on
16288 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16289 * can.
16290 */
16291 __HEAD
16292 +
16293 +#ifdef CONFIG_PAX_KERNEXEC
16294 + jmp startup_32
16295 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16296 +.fill PAGE_SIZE-5,1,0xcc
16297 +#endif
16298 +
16299 ENTRY(startup_32)
16300 movl pa(stack_start),%ecx
16301
16302 @@ -105,6 +120,57 @@ ENTRY(startup_32)
16303 2:
16304 leal -__PAGE_OFFSET(%ecx),%esp
16305
16306 +#ifdef CONFIG_SMP
16307 + movl $pa(cpu_gdt_table),%edi
16308 + movl $__per_cpu_load,%eax
16309 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16310 + rorl $16,%eax
16311 + movb %al,__KERNEL_PERCPU + 4(%edi)
16312 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16313 + movl $__per_cpu_end - 1,%eax
16314 + subl $__per_cpu_start,%eax
16315 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16316 +#endif
16317 +
16318 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16319 + movl $NR_CPUS,%ecx
16320 + movl $pa(cpu_gdt_table),%edi
16321 +1:
16322 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16323 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16324 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16325 + addl $PAGE_SIZE_asm,%edi
16326 + loop 1b
16327 +#endif
16328 +
16329 +#ifdef CONFIG_PAX_KERNEXEC
16330 + movl $pa(boot_gdt),%edi
16331 + movl $__LOAD_PHYSICAL_ADDR,%eax
16332 + movw %ax,__BOOT_CS + 2(%edi)
16333 + rorl $16,%eax
16334 + movb %al,__BOOT_CS + 4(%edi)
16335 + movb %ah,__BOOT_CS + 7(%edi)
16336 + rorl $16,%eax
16337 +
16338 + ljmp $(__BOOT_CS),$1f
16339 +1:
16340 +
16341 + movl $NR_CPUS,%ecx
16342 + movl $pa(cpu_gdt_table),%edi
16343 + addl $__PAGE_OFFSET,%eax
16344 +1:
16345 + movw %ax,__KERNEL_CS + 2(%edi)
16346 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16347 + rorl $16,%eax
16348 + movb %al,__KERNEL_CS + 4(%edi)
16349 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16350 + movb %ah,__KERNEL_CS + 7(%edi)
16351 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16352 + rorl $16,%eax
16353 + addl $PAGE_SIZE_asm,%edi
16354 + loop 1b
16355 +#endif
16356 +
16357 /*
16358 * Clear BSS first so that there are no surprises...
16359 */
16360 @@ -195,8 +261,11 @@ ENTRY(startup_32)
16361 movl %eax, pa(max_pfn_mapped)
16362
16363 /* Do early initialization of the fixmap area */
16364 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16365 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16366 +#ifdef CONFIG_COMPAT_VDSO
16367 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16368 +#else
16369 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16370 +#endif
16371 #else /* Not PAE */
16372
16373 page_pde_offset = (__PAGE_OFFSET >> 20);
16374 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16375 movl %eax, pa(max_pfn_mapped)
16376
16377 /* Do early initialization of the fixmap area */
16378 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16379 - movl %eax,pa(initial_page_table+0xffc)
16380 +#ifdef CONFIG_COMPAT_VDSO
16381 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16382 +#else
16383 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16384 +#endif
16385 #endif
16386
16387 #ifdef CONFIG_PARAVIRT
16388 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16389 cmpl $num_subarch_entries, %eax
16390 jae bad_subarch
16391
16392 - movl pa(subarch_entries)(,%eax,4), %eax
16393 - subl $__PAGE_OFFSET, %eax
16394 - jmp *%eax
16395 + jmp *pa(subarch_entries)(,%eax,4)
16396
16397 bad_subarch:
16398 WEAK(lguest_entry)
16399 @@ -255,10 +325,10 @@ WEAK(xen_entry)
16400 __INITDATA
16401
16402 subarch_entries:
16403 - .long default_entry /* normal x86/PC */
16404 - .long lguest_entry /* lguest hypervisor */
16405 - .long xen_entry /* Xen hypervisor */
16406 - .long default_entry /* Moorestown MID */
16407 + .long ta(default_entry) /* normal x86/PC */
16408 + .long ta(lguest_entry) /* lguest hypervisor */
16409 + .long ta(xen_entry) /* Xen hypervisor */
16410 + .long ta(default_entry) /* Moorestown MID */
16411 num_subarch_entries = (. - subarch_entries) / 4
16412 .previous
16413 #else
16414 @@ -312,6 +382,7 @@ default_entry:
16415 orl %edx,%eax
16416 movl %eax,%cr4
16417
16418 +#ifdef CONFIG_X86_PAE
16419 testb $X86_CR4_PAE, %al # check if PAE is enabled
16420 jz 6f
16421
16422 @@ -340,6 +411,9 @@ default_entry:
16423 /* Make changes effective */
16424 wrmsr
16425
16426 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16427 +#endif
16428 +
16429 6:
16430
16431 /*
16432 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
16433 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16434 movl %eax,%ss # after changing gdt.
16435
16436 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
16437 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16438 movl %eax,%ds
16439 movl %eax,%es
16440
16441 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
16442 */
16443 cmpb $0,ready
16444 jne 1f
16445 - movl $gdt_page,%eax
16446 + movl $cpu_gdt_table,%eax
16447 movl $stack_canary,%ecx
16448 +#ifdef CONFIG_SMP
16449 + addl $__per_cpu_load,%ecx
16450 +#endif
16451 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16452 shrl $16, %ecx
16453 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16454 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
16455 1:
16456 -#endif
16457 movl $(__KERNEL_STACK_CANARY),%eax
16458 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16459 + movl $(__USER_DS),%eax
16460 +#else
16461 + xorl %eax,%eax
16462 +#endif
16463 movl %eax,%gs
16464
16465 xorl %eax,%eax # Clear LDT
16466 @@ -558,22 +639,22 @@ early_page_fault:
16467 jmp early_fault
16468
16469 early_fault:
16470 - cld
16471 #ifdef CONFIG_PRINTK
16472 + cmpl $1,%ss:early_recursion_flag
16473 + je hlt_loop
16474 + incl %ss:early_recursion_flag
16475 + cld
16476 pusha
16477 movl $(__KERNEL_DS),%eax
16478 movl %eax,%ds
16479 movl %eax,%es
16480 - cmpl $2,early_recursion_flag
16481 - je hlt_loop
16482 - incl early_recursion_flag
16483 movl %cr2,%eax
16484 pushl %eax
16485 pushl %edx /* trapno */
16486 pushl $fault_msg
16487 call printk
16488 +; call dump_stack
16489 #endif
16490 - call dump_stack
16491 hlt_loop:
16492 hlt
16493 jmp hlt_loop
16494 @@ -581,8 +662,11 @@ hlt_loop:
16495 /* This is the default interrupt "handler" :-) */
16496 ALIGN
16497 ignore_int:
16498 - cld
16499 #ifdef CONFIG_PRINTK
16500 + cmpl $2,%ss:early_recursion_flag
16501 + je hlt_loop
16502 + incl %ss:early_recursion_flag
16503 + cld
16504 pushl %eax
16505 pushl %ecx
16506 pushl %edx
16507 @@ -591,9 +675,6 @@ ignore_int:
16508 movl $(__KERNEL_DS),%eax
16509 movl %eax,%ds
16510 movl %eax,%es
16511 - cmpl $2,early_recursion_flag
16512 - je hlt_loop
16513 - incl early_recursion_flag
16514 pushl 16(%esp)
16515 pushl 24(%esp)
16516 pushl 32(%esp)
16517 @@ -622,29 +703,43 @@ ENTRY(initial_code)
16518 /*
16519 * BSS section
16520 */
16521 -__PAGE_ALIGNED_BSS
16522 - .align PAGE_SIZE
16523 #ifdef CONFIG_X86_PAE
16524 +.section .initial_pg_pmd,"a",@progbits
16525 initial_pg_pmd:
16526 .fill 1024*KPMDS,4,0
16527 #else
16528 +.section .initial_page_table,"a",@progbits
16529 ENTRY(initial_page_table)
16530 .fill 1024,4,0
16531 #endif
16532 +.section .initial_pg_fixmap,"a",@progbits
16533 initial_pg_fixmap:
16534 .fill 1024,4,0
16535 +.section .empty_zero_page,"a",@progbits
16536 ENTRY(empty_zero_page)
16537 .fill 4096,1,0
16538 +.section .swapper_pg_dir,"a",@progbits
16539 ENTRY(swapper_pg_dir)
16540 +#ifdef CONFIG_X86_PAE
16541 + .fill 4,8,0
16542 +#else
16543 .fill 1024,4,0
16544 +#endif
16545 +
16546 +/*
16547 + * The IDT has to be page-aligned to simplify the Pentium
16548 + * F0 0F bug workaround.. We have a special link segment
16549 + * for this.
16550 + */
16551 +.section .idt,"a",@progbits
16552 +ENTRY(idt_table)
16553 + .fill 256,8,0
16554
16555 /*
16556 * This starts the data section.
16557 */
16558 #ifdef CONFIG_X86_PAE
16559 -__PAGE_ALIGNED_DATA
16560 - /* Page-aligned for the benefit of paravirt? */
16561 - .align PAGE_SIZE
16562 +.section .initial_page_table,"a",@progbits
16563 ENTRY(initial_page_table)
16564 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
16565 # if KPMDS == 3
16566 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
16567 # error "Kernel PMDs should be 1, 2 or 3"
16568 # endif
16569 .align PAGE_SIZE /* needs to be page-sized too */
16570 +
16571 +#ifdef CONFIG_PAX_PER_CPU_PGD
16572 +ENTRY(cpu_pgd)
16573 + .rept NR_CPUS
16574 + .fill 4,8,0
16575 + .endr
16576 +#endif
16577 +
16578 #endif
16579
16580 .data
16581 .balign 4
16582 ENTRY(stack_start)
16583 - .long init_thread_union+THREAD_SIZE
16584 + .long init_thread_union+THREAD_SIZE-8
16585
16586 +ready: .byte 0
16587 +
16588 +.section .rodata,"a",@progbits
16589 early_recursion_flag:
16590 .long 0
16591
16592 -ready: .byte 0
16593 -
16594 int_msg:
16595 .asciz "Unknown interrupt or fault at: %p %p %p\n"
16596
16597 @@ -707,7 +811,7 @@ fault_msg:
16598 .word 0 # 32 bit align gdt_desc.address
16599 boot_gdt_descr:
16600 .word __BOOT_DS+7
16601 - .long boot_gdt - __PAGE_OFFSET
16602 + .long pa(boot_gdt)
16603
16604 .word 0 # 32-bit align idt_desc.address
16605 idt_descr:
16606 @@ -718,7 +822,7 @@ idt_descr:
16607 .word 0 # 32 bit align gdt_desc.address
16608 ENTRY(early_gdt_descr)
16609 .word GDT_ENTRIES*8-1
16610 - .long gdt_page /* Overwritten for secondary CPUs */
16611 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
16612
16613 /*
16614 * The boot_gdt must mirror the equivalent in setup.S and is
16615 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
16616 .align L1_CACHE_BYTES
16617 ENTRY(boot_gdt)
16618 .fill GDT_ENTRY_BOOT_CS,8,0
16619 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
16620 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
16621 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
16622 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
16623 +
16624 + .align PAGE_SIZE_asm
16625 +ENTRY(cpu_gdt_table)
16626 + .rept NR_CPUS
16627 + .quad 0x0000000000000000 /* NULL descriptor */
16628 + .quad 0x0000000000000000 /* 0x0b reserved */
16629 + .quad 0x0000000000000000 /* 0x13 reserved */
16630 + .quad 0x0000000000000000 /* 0x1b reserved */
16631 +
16632 +#ifdef CONFIG_PAX_KERNEXEC
16633 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
16634 +#else
16635 + .quad 0x0000000000000000 /* 0x20 unused */
16636 +#endif
16637 +
16638 + .quad 0x0000000000000000 /* 0x28 unused */
16639 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
16640 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
16641 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
16642 + .quad 0x0000000000000000 /* 0x4b reserved */
16643 + .quad 0x0000000000000000 /* 0x53 reserved */
16644 + .quad 0x0000000000000000 /* 0x5b reserved */
16645 +
16646 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
16647 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
16648 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
16649 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
16650 +
16651 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
16652 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
16653 +
16654 + /*
16655 + * Segments used for calling PnP BIOS have byte granularity.
16656 + * The code segments and data segments have fixed 64k limits,
16657 + * the transfer segment sizes are set at run time.
16658 + */
16659 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
16660 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
16661 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
16662 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
16663 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
16664 +
16665 + /*
16666 + * The APM segments have byte granularity and their bases
16667 + * are set at run time. All have 64k limits.
16668 + */
16669 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
16670 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
16671 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
16672 +
16673 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
16674 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
16675 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
16676 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
16677 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
16678 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
16679 +
16680 + /* Be sure this is zeroed to avoid false validations in Xen */
16681 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
16682 + .endr
16683 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
16684 index e11e394..9aebc5d 100644
16685 --- a/arch/x86/kernel/head_64.S
16686 +++ b/arch/x86/kernel/head_64.S
16687 @@ -19,6 +19,8 @@
16688 #include <asm/cache.h>
16689 #include <asm/processor-flags.h>
16690 #include <asm/percpu.h>
16691 +#include <asm/cpufeature.h>
16692 +#include <asm/alternative-asm.h>
16693
16694 #ifdef CONFIG_PARAVIRT
16695 #include <asm/asm-offsets.h>
16696 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
16697 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
16698 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
16699 L3_START_KERNEL = pud_index(__START_KERNEL_map)
16700 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
16701 +L3_VMALLOC_START = pud_index(VMALLOC_START)
16702 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
16703 +L3_VMALLOC_END = pud_index(VMALLOC_END)
16704 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
16705 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
16706
16707 .text
16708 __HEAD
16709 @@ -85,35 +93,23 @@ startup_64:
16710 */
16711 addq %rbp, init_level4_pgt + 0(%rip)
16712 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
16713 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
16714 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
16715 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
16716 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
16717
16718 addq %rbp, level3_ident_pgt + 0(%rip)
16719 +#ifndef CONFIG_XEN
16720 + addq %rbp, level3_ident_pgt + 8(%rip)
16721 +#endif
16722
16723 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
16724 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
16725 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
16726 +
16727 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
16728 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
16729
16730 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
16731 -
16732 - /* Add an Identity mapping if I am above 1G */
16733 - leaq _text(%rip), %rdi
16734 - andq $PMD_PAGE_MASK, %rdi
16735 -
16736 - movq %rdi, %rax
16737 - shrq $PUD_SHIFT, %rax
16738 - andq $(PTRS_PER_PUD - 1), %rax
16739 - jz ident_complete
16740 -
16741 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
16742 - leaq level3_ident_pgt(%rip), %rbx
16743 - movq %rdx, 0(%rbx, %rax, 8)
16744 -
16745 - movq %rdi, %rax
16746 - shrq $PMD_SHIFT, %rax
16747 - andq $(PTRS_PER_PMD - 1), %rax
16748 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
16749 - leaq level2_spare_pgt(%rip), %rbx
16750 - movq %rdx, 0(%rbx, %rax, 8)
16751 -ident_complete:
16752 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
16753
16754 /*
16755 * Fixup the kernel text+data virtual addresses. Note that
16756 @@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
16757 * after the boot processor executes this code.
16758 */
16759
16760 - /* Enable PAE mode and PGE */
16761 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
16762 + /* Enable PAE mode and PSE/PGE */
16763 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
16764 movq %rax, %cr4
16765
16766 /* Setup early boot stage 4 level pagetables. */
16767 @@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
16768 movl $MSR_EFER, %ecx
16769 rdmsr
16770 btsl $_EFER_SCE, %eax /* Enable System Call */
16771 - btl $20,%edi /* No Execute supported? */
16772 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
16773 jnc 1f
16774 btsl $_EFER_NX, %eax
16775 + leaq init_level4_pgt(%rip), %rdi
16776 +#ifndef CONFIG_EFI
16777 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
16778 +#endif
16779 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
16780 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
16781 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
16782 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
16783 1: wrmsr /* Make changes effective */
16784
16785 /* Setup cr0 */
16786 @@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
16787 * jump. In addition we need to ensure %cs is set so we make this
16788 * a far return.
16789 */
16790 + pax_set_fptr_mask
16791 movq initial_code(%rip),%rax
16792 pushq $0 # fake return address to stop unwinder
16793 pushq $__KERNEL_CS # set correct cs
16794 @@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
16795 bad_address:
16796 jmp bad_address
16797
16798 - .section ".init.text","ax"
16799 + __INIT
16800 #ifdef CONFIG_EARLY_PRINTK
16801 .globl early_idt_handlers
16802 early_idt_handlers:
16803 @@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
16804 #endif /* EARLY_PRINTK */
16805 1: hlt
16806 jmp 1b
16807 + .previous
16808
16809 #ifdef CONFIG_EARLY_PRINTK
16810 + __INITDATA
16811 early_recursion_flag:
16812 .long 0
16813 + .previous
16814
16815 + .section .rodata,"a",@progbits
16816 early_idt_msg:
16817 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
16818 early_idt_ripmsg:
16819 .asciz "RIP %s\n"
16820 + .previous
16821 #endif /* CONFIG_EARLY_PRINTK */
16822 - .previous
16823
16824 + .section .rodata,"a",@progbits
16825 #define NEXT_PAGE(name) \
16826 .balign PAGE_SIZE; \
16827 ENTRY(name)
16828 @@ -338,7 +348,6 @@ ENTRY(name)
16829 i = i + 1 ; \
16830 .endr
16831
16832 - .data
16833 /*
16834 * This default setting generates an ident mapping at address 0x100000
16835 * and a mapping for the kernel that precisely maps virtual address
16836 @@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
16837 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16838 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
16839 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16840 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
16841 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
16842 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
16843 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
16844 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
16845 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
16846 .org init_level4_pgt + L4_START_KERNEL*8, 0
16847 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
16848 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
16849
16850 +#ifdef CONFIG_PAX_PER_CPU_PGD
16851 +NEXT_PAGE(cpu_pgd)
16852 + .rept NR_CPUS
16853 + .fill 512,8,0
16854 + .endr
16855 +#endif
16856 +
16857 NEXT_PAGE(level3_ident_pgt)
16858 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16859 +#ifdef CONFIG_XEN
16860 .fill 511,8,0
16861 +#else
16862 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
16863 + .fill 510,8,0
16864 +#endif
16865 +
16866 +NEXT_PAGE(level3_vmalloc_start_pgt)
16867 + .fill 512,8,0
16868 +
16869 +NEXT_PAGE(level3_vmalloc_end_pgt)
16870 + .fill 512,8,0
16871 +
16872 +NEXT_PAGE(level3_vmemmap_pgt)
16873 + .fill L3_VMEMMAP_START,8,0
16874 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
16875
16876 NEXT_PAGE(level3_kernel_pgt)
16877 .fill L3_START_KERNEL,8,0
16878 @@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
16879 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
16880 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16881
16882 +NEXT_PAGE(level2_vmemmap_pgt)
16883 + .fill 512,8,0
16884 +
16885 NEXT_PAGE(level2_fixmap_pgt)
16886 - .fill 506,8,0
16887 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16888 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
16889 - .fill 5,8,0
16890 + .fill 507,8,0
16891 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
16892 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
16893 + .fill 4,8,0
16894
16895 -NEXT_PAGE(level1_fixmap_pgt)
16896 +NEXT_PAGE(level1_vsyscall_pgt)
16897 .fill 512,8,0
16898
16899 -NEXT_PAGE(level2_ident_pgt)
16900 - /* Since I easily can, map the first 1G.
16901 + /* Since I easily can, map the first 2G.
16902 * Don't set NX because code runs from these pages.
16903 */
16904 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
16905 +NEXT_PAGE(level2_ident_pgt)
16906 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
16907
16908 NEXT_PAGE(level2_kernel_pgt)
16909 /*
16910 @@ -389,33 +429,55 @@ NEXT_PAGE(level2_kernel_pgt)
16911 * If you want to increase this then increase MODULES_VADDR
16912 * too.)
16913 */
16914 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
16915 - KERNEL_IMAGE_SIZE/PMD_SIZE)
16916 -
16917 -NEXT_PAGE(level2_spare_pgt)
16918 - .fill 512, 8, 0
16919 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
16920
16921 #undef PMDS
16922 #undef NEXT_PAGE
16923
16924 - .data
16925 + .align PAGE_SIZE
16926 +ENTRY(cpu_gdt_table)
16927 + .rept NR_CPUS
16928 + .quad 0x0000000000000000 /* NULL descriptor */
16929 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
16930 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
16931 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
16932 + .quad 0x00cffb000000ffff /* __USER32_CS */
16933 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
16934 + .quad 0x00affb000000ffff /* __USER_CS */
16935 +
16936 +#ifdef CONFIG_PAX_KERNEXEC
16937 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
16938 +#else
16939 + .quad 0x0 /* unused */
16940 +#endif
16941 +
16942 + .quad 0,0 /* TSS */
16943 + .quad 0,0 /* LDT */
16944 + .quad 0,0,0 /* three TLS descriptors */
16945 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
16946 + /* asm/segment.h:GDT_ENTRIES must match this */
16947 +
16948 + /* zero the remaining page */
16949 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
16950 + .endr
16951 +
16952 .align 16
16953 .globl early_gdt_descr
16954 early_gdt_descr:
16955 .word GDT_ENTRIES*8-1
16956 early_gdt_descr_base:
16957 - .quad INIT_PER_CPU_VAR(gdt_page)
16958 + .quad cpu_gdt_table
16959
16960 ENTRY(phys_base)
16961 /* This must match the first entry in level2_kernel_pgt */
16962 .quad 0x0000000000000000
16963
16964 #include "../../x86/xen/xen-head.S"
16965 -
16966 - .section .bss, "aw", @nobits
16967 +
16968 + .section .rodata,"a",@progbits
16969 .align L1_CACHE_BYTES
16970 ENTRY(idt_table)
16971 - .skip IDT_ENTRIES * 16
16972 + .fill 512,8,0
16973
16974 __PAGE_ALIGNED_BSS
16975 .align PAGE_SIZE
16976 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
16977 index 9c3bd4a..e1d9b35 100644
16978 --- a/arch/x86/kernel/i386_ksyms_32.c
16979 +++ b/arch/x86/kernel/i386_ksyms_32.c
16980 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
16981 EXPORT_SYMBOL(cmpxchg8b_emu);
16982 #endif
16983
16984 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
16985 +
16986 /* Networking helper routines. */
16987 EXPORT_SYMBOL(csum_partial_copy_generic);
16988 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
16989 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
16990
16991 EXPORT_SYMBOL(__get_user_1);
16992 EXPORT_SYMBOL(__get_user_2);
16993 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
16994
16995 EXPORT_SYMBOL(csum_partial);
16996 EXPORT_SYMBOL(empty_zero_page);
16997 +
16998 +#ifdef CONFIG_PAX_KERNEXEC
16999 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17000 +#endif
17001 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17002 index 739d859..d1d6be7 100644
17003 --- a/arch/x86/kernel/i387.c
17004 +++ b/arch/x86/kernel/i387.c
17005 @@ -188,6 +188,9 @@ int xfpregs_active(struct task_struct *target, const struct user_regset *regset)
17006
17007 int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17008 unsigned int pos, unsigned int count,
17009 + void *kbuf, void __user *ubuf) __size_overflow(4);
17010 +int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17011 + unsigned int pos, unsigned int count,
17012 void *kbuf, void __user *ubuf)
17013 {
17014 int ret;
17015 @@ -207,6 +210,9 @@ int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17016
17017 int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17018 unsigned int pos, unsigned int count,
17019 + const void *kbuf, const void __user *ubuf) __size_overflow(4);
17020 +int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17021 + unsigned int pos, unsigned int count,
17022 const void *kbuf, const void __user *ubuf)
17023 {
17024 int ret;
17025 @@ -240,6 +246,9 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17026
17027 int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17028 unsigned int pos, unsigned int count,
17029 + void *kbuf, void __user *ubuf) __size_overflow(4);
17030 +int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17031 + unsigned int pos, unsigned int count,
17032 void *kbuf, void __user *ubuf)
17033 {
17034 int ret;
17035 @@ -269,6 +278,9 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17036
17037 int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
17038 unsigned int pos, unsigned int count,
17039 + const void *kbuf, const void __user *ubuf) __size_overflow(4);
17040 +int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
17041 + unsigned int pos, unsigned int count,
17042 const void *kbuf, const void __user *ubuf)
17043 {
17044 int ret;
17045 @@ -439,6 +451,9 @@ static void convert_to_fxsr(struct task_struct *tsk,
17046
17047 int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17048 unsigned int pos, unsigned int count,
17049 + void *kbuf, void __user *ubuf) __size_overflow(3,4);
17050 +int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17051 + unsigned int pos, unsigned int count,
17052 void *kbuf, void __user *ubuf)
17053 {
17054 struct user_i387_ia32_struct env;
17055 @@ -471,6 +486,9 @@ int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17056
17057 int fpregs_set(struct task_struct *target, const struct user_regset *regset,
17058 unsigned int pos, unsigned int count,
17059 + const void *kbuf, const void __user *ubuf) __size_overflow(3,4);
17060 +int fpregs_set(struct task_struct *target, const struct user_regset *regset,
17061 + unsigned int pos, unsigned int count,
17062 const void *kbuf, const void __user *ubuf)
17063 {
17064 struct user_i387_ia32_struct env;
17065 @@ -619,6 +637,8 @@ static inline int restore_i387_fsave(struct _fpstate_ia32 __user *buf)
17066 }
17067
17068 static int restore_i387_fxsave(struct _fpstate_ia32 __user *buf,
17069 + unsigned int size) __size_overflow(2);
17070 +static int restore_i387_fxsave(struct _fpstate_ia32 __user *buf,
17071 unsigned int size)
17072 {
17073 struct task_struct *tsk = current;
17074 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17075 index 6104852..6114160 100644
17076 --- a/arch/x86/kernel/i8259.c
17077 +++ b/arch/x86/kernel/i8259.c
17078 @@ -210,7 +210,7 @@ spurious_8259A_irq:
17079 "spurious 8259A interrupt: IRQ%d.\n", irq);
17080 spurious_irq_mask |= irqmask;
17081 }
17082 - atomic_inc(&irq_err_count);
17083 + atomic_inc_unchecked(&irq_err_count);
17084 /*
17085 * Theoretically we do not have to handle this IRQ,
17086 * but in Linux this does not cause problems and is
17087 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17088 index 43e9ccf..44ccf6f 100644
17089 --- a/arch/x86/kernel/init_task.c
17090 +++ b/arch/x86/kernel/init_task.c
17091 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
17092 * way process stacks are handled. This is done by having a special
17093 * "init_task" linker map entry..
17094 */
17095 -union thread_union init_thread_union __init_task_data =
17096 - { INIT_THREAD_INFO(init_task) };
17097 +union thread_union init_thread_union __init_task_data;
17098
17099 /*
17100 * Initial task structure.
17101 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
17102 * section. Since TSS's are completely CPU-local, we want them
17103 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
17104 */
17105 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
17106 -
17107 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
17108 +EXPORT_SYMBOL(init_tss);
17109 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17110 index 8c96897..be66bfa 100644
17111 --- a/arch/x86/kernel/ioport.c
17112 +++ b/arch/x86/kernel/ioport.c
17113 @@ -6,6 +6,7 @@
17114 #include <linux/sched.h>
17115 #include <linux/kernel.h>
17116 #include <linux/capability.h>
17117 +#include <linux/security.h>
17118 #include <linux/errno.h>
17119 #include <linux/types.h>
17120 #include <linux/ioport.h>
17121 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17122
17123 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17124 return -EINVAL;
17125 +#ifdef CONFIG_GRKERNSEC_IO
17126 + if (turn_on && grsec_disable_privio) {
17127 + gr_handle_ioperm();
17128 + return -EPERM;
17129 + }
17130 +#endif
17131 if (turn_on && !capable(CAP_SYS_RAWIO))
17132 return -EPERM;
17133
17134 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17135 * because the ->io_bitmap_max value must match the bitmap
17136 * contents:
17137 */
17138 - tss = &per_cpu(init_tss, get_cpu());
17139 + tss = init_tss + get_cpu();
17140
17141 if (turn_on)
17142 bitmap_clear(t->io_bitmap_ptr, from, num);
17143 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17144 return -EINVAL;
17145 /* Trying to gain more privileges? */
17146 if (level > old) {
17147 +#ifdef CONFIG_GRKERNSEC_IO
17148 + if (grsec_disable_privio) {
17149 + gr_handle_iopl();
17150 + return -EPERM;
17151 + }
17152 +#endif
17153 if (!capable(CAP_SYS_RAWIO))
17154 return -EPERM;
17155 }
17156 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17157 index 429e0c9..17b3ece 100644
17158 --- a/arch/x86/kernel/irq.c
17159 +++ b/arch/x86/kernel/irq.c
17160 @@ -18,7 +18,7 @@
17161 #include <asm/mce.h>
17162 #include <asm/hw_irq.h>
17163
17164 -atomic_t irq_err_count;
17165 +atomic_unchecked_t irq_err_count;
17166
17167 /* Function pointer for generic interrupt vector handling */
17168 void (*x86_platform_ipi_callback)(void) = NULL;
17169 @@ -117,9 +117,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17170 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17171 seq_printf(p, " Machine check polls\n");
17172 #endif
17173 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17174 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17175 #if defined(CONFIG_X86_IO_APIC)
17176 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17177 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17178 #endif
17179 return 0;
17180 }
17181 @@ -159,10 +159,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17182
17183 u64 arch_irq_stat(void)
17184 {
17185 - u64 sum = atomic_read(&irq_err_count);
17186 + u64 sum = atomic_read_unchecked(&irq_err_count);
17187
17188 #ifdef CONFIG_X86_IO_APIC
17189 - sum += atomic_read(&irq_mis_count);
17190 + sum += atomic_read_unchecked(&irq_mis_count);
17191 #endif
17192 return sum;
17193 }
17194 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17195 index 7209070..cbcd71a 100644
17196 --- a/arch/x86/kernel/irq_32.c
17197 +++ b/arch/x86/kernel/irq_32.c
17198 @@ -36,7 +36,7 @@ static int check_stack_overflow(void)
17199 __asm__ __volatile__("andl %%esp,%0" :
17200 "=r" (sp) : "0" (THREAD_SIZE - 1));
17201
17202 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17203 + return sp < STACK_WARN;
17204 }
17205
17206 static void print_stack_overflow(void)
17207 @@ -54,8 +54,8 @@ static inline void print_stack_overflow(void) { }
17208 * per-CPU IRQ handling contexts (thread information and stack)
17209 */
17210 union irq_ctx {
17211 - struct thread_info tinfo;
17212 - u32 stack[THREAD_SIZE/sizeof(u32)];
17213 + unsigned long previous_esp;
17214 + u32 stack[THREAD_SIZE/sizeof(u32)];
17215 } __attribute__((aligned(THREAD_SIZE)));
17216
17217 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17218 @@ -75,10 +75,9 @@ static void call_on_stack(void *func, void *stack)
17219 static inline int
17220 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17221 {
17222 - union irq_ctx *curctx, *irqctx;
17223 + union irq_ctx *irqctx;
17224 u32 *isp, arg1, arg2;
17225
17226 - curctx = (union irq_ctx *) current_thread_info();
17227 irqctx = __this_cpu_read(hardirq_ctx);
17228
17229 /*
17230 @@ -87,21 +86,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17231 * handler) we can't do that and just have to keep using the
17232 * current stack (which is the irq stack already after all)
17233 */
17234 - if (unlikely(curctx == irqctx))
17235 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17236 return 0;
17237
17238 /* build the stack frame on the IRQ stack */
17239 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17240 - irqctx->tinfo.task = curctx->tinfo.task;
17241 - irqctx->tinfo.previous_esp = current_stack_pointer;
17242 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17243 + irqctx->previous_esp = current_stack_pointer;
17244
17245 - /*
17246 - * Copy the softirq bits in preempt_count so that the
17247 - * softirq checks work in the hardirq context.
17248 - */
17249 - irqctx->tinfo.preempt_count =
17250 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
17251 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
17252 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17253 + __set_fs(MAKE_MM_SEG(0));
17254 +#endif
17255
17256 if (unlikely(overflow))
17257 call_on_stack(print_stack_overflow, isp);
17258 @@ -113,6 +107,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17259 : "0" (irq), "1" (desc), "2" (isp),
17260 "D" (desc->handle_irq)
17261 : "memory", "cc", "ecx");
17262 +
17263 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17264 + __set_fs(current_thread_info()->addr_limit);
17265 +#endif
17266 +
17267 return 1;
17268 }
17269
17270 @@ -121,29 +120,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17271 */
17272 void __cpuinit irq_ctx_init(int cpu)
17273 {
17274 - union irq_ctx *irqctx;
17275 -
17276 if (per_cpu(hardirq_ctx, cpu))
17277 return;
17278
17279 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17280 - THREAD_FLAGS,
17281 - THREAD_ORDER));
17282 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17283 - irqctx->tinfo.cpu = cpu;
17284 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17285 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17286 -
17287 - per_cpu(hardirq_ctx, cpu) = irqctx;
17288 -
17289 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17290 - THREAD_FLAGS,
17291 - THREAD_ORDER));
17292 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17293 - irqctx->tinfo.cpu = cpu;
17294 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17295 -
17296 - per_cpu(softirq_ctx, cpu) = irqctx;
17297 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17298 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17299
17300 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17301 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17302 @@ -152,7 +133,6 @@ void __cpuinit irq_ctx_init(int cpu)
17303 asmlinkage void do_softirq(void)
17304 {
17305 unsigned long flags;
17306 - struct thread_info *curctx;
17307 union irq_ctx *irqctx;
17308 u32 *isp;
17309
17310 @@ -162,15 +142,22 @@ asmlinkage void do_softirq(void)
17311 local_irq_save(flags);
17312
17313 if (local_softirq_pending()) {
17314 - curctx = current_thread_info();
17315 irqctx = __this_cpu_read(softirq_ctx);
17316 - irqctx->tinfo.task = curctx->task;
17317 - irqctx->tinfo.previous_esp = current_stack_pointer;
17318 + irqctx->previous_esp = current_stack_pointer;
17319
17320 /* build the stack frame on the softirq stack */
17321 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17322 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17323 +
17324 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17325 + __set_fs(MAKE_MM_SEG(0));
17326 +#endif
17327
17328 call_on_stack(__do_softirq, isp);
17329 +
17330 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17331 + __set_fs(current_thread_info()->addr_limit);
17332 +#endif
17333 +
17334 /*
17335 * Shouldn't happen, we returned above if in_interrupt():
17336 */
17337 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17338 index 69bca46..0bac999 100644
17339 --- a/arch/x86/kernel/irq_64.c
17340 +++ b/arch/x86/kernel/irq_64.c
17341 @@ -38,7 +38,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17342 #ifdef CONFIG_DEBUG_STACKOVERFLOW
17343 u64 curbase = (u64)task_stack_page(current);
17344
17345 - if (user_mode_vm(regs))
17346 + if (user_mode(regs))
17347 return;
17348
17349 WARN_ONCE(regs->sp >= curbase &&
17350 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17351 index faba577..93b9e71 100644
17352 --- a/arch/x86/kernel/kgdb.c
17353 +++ b/arch/x86/kernel/kgdb.c
17354 @@ -124,11 +124,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17355 #ifdef CONFIG_X86_32
17356 switch (regno) {
17357 case GDB_SS:
17358 - if (!user_mode_vm(regs))
17359 + if (!user_mode(regs))
17360 *(unsigned long *)mem = __KERNEL_DS;
17361 break;
17362 case GDB_SP:
17363 - if (!user_mode_vm(regs))
17364 + if (!user_mode(regs))
17365 *(unsigned long *)mem = kernel_stack_pointer(regs);
17366 break;
17367 case GDB_GS:
17368 @@ -473,12 +473,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17369 case 'k':
17370 /* clear the trace bit */
17371 linux_regs->flags &= ~X86_EFLAGS_TF;
17372 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17373 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17374
17375 /* set the trace bit if we're stepping */
17376 if (remcomInBuffer[0] == 's') {
17377 linux_regs->flags |= X86_EFLAGS_TF;
17378 - atomic_set(&kgdb_cpu_doing_single_step,
17379 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17380 raw_smp_processor_id());
17381 }
17382
17383 @@ -543,7 +543,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17384
17385 switch (cmd) {
17386 case DIE_DEBUG:
17387 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17388 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17389 if (user_mode(regs))
17390 return single_step_cont(regs, args);
17391 break;
17392 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17393 index 7da647d..56fe348 100644
17394 --- a/arch/x86/kernel/kprobes.c
17395 +++ b/arch/x86/kernel/kprobes.c
17396 @@ -118,8 +118,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17397 } __attribute__((packed)) *insn;
17398
17399 insn = (struct __arch_relative_insn *)from;
17400 +
17401 + pax_open_kernel();
17402 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17403 insn->op = op;
17404 + pax_close_kernel();
17405 }
17406
17407 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17408 @@ -156,7 +159,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
17409 kprobe_opcode_t opcode;
17410 kprobe_opcode_t *orig_opcodes = opcodes;
17411
17412 - if (search_exception_tables((unsigned long)opcodes))
17413 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17414 return 0; /* Page fault may occur on this address. */
17415
17416 retry:
17417 @@ -317,7 +320,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17418 }
17419 }
17420 insn_get_length(&insn);
17421 + pax_open_kernel();
17422 memcpy(dest, insn.kaddr, insn.length);
17423 + pax_close_kernel();
17424
17425 #ifdef CONFIG_X86_64
17426 if (insn_rip_relative(&insn)) {
17427 @@ -341,7 +346,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17428 (u8 *) dest;
17429 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17430 disp = (u8 *) dest + insn_offset_displacement(&insn);
17431 + pax_open_kernel();
17432 *(s32 *) disp = (s32) newdisp;
17433 + pax_close_kernel();
17434 }
17435 #endif
17436 return insn.length;
17437 @@ -355,12 +362,12 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
17438 */
17439 __copy_instruction(p->ainsn.insn, p->addr, 0);
17440
17441 - if (can_boost(p->addr))
17442 + if (can_boost(ktla_ktva(p->addr)))
17443 p->ainsn.boostable = 0;
17444 else
17445 p->ainsn.boostable = -1;
17446
17447 - p->opcode = *p->addr;
17448 + p->opcode = *(ktla_ktva(p->addr));
17449 }
17450
17451 int __kprobes arch_prepare_kprobe(struct kprobe *p)
17452 @@ -477,7 +484,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17453 * nor set current_kprobe, because it doesn't use single
17454 * stepping.
17455 */
17456 - regs->ip = (unsigned long)p->ainsn.insn;
17457 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17458 preempt_enable_no_resched();
17459 return;
17460 }
17461 @@ -496,7 +503,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17462 if (p->opcode == BREAKPOINT_INSTRUCTION)
17463 regs->ip = (unsigned long)p->addr;
17464 else
17465 - regs->ip = (unsigned long)p->ainsn.insn;
17466 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17467 }
17468
17469 /*
17470 @@ -575,7 +582,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17471 setup_singlestep(p, regs, kcb, 0);
17472 return 1;
17473 }
17474 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
17475 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17476 /*
17477 * The breakpoint instruction was removed right
17478 * after we hit it. Another cpu has removed
17479 @@ -683,6 +690,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17480 " movq %rax, 152(%rsp)\n"
17481 RESTORE_REGS_STRING
17482 " popfq\n"
17483 +#ifdef KERNEXEC_PLUGIN
17484 + " btsq $63,(%rsp)\n"
17485 +#endif
17486 #else
17487 " pushf\n"
17488 SAVE_REGS_STRING
17489 @@ -820,7 +830,7 @@ static void __kprobes resume_execution(struct kprobe *p,
17490 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17491 {
17492 unsigned long *tos = stack_addr(regs);
17493 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17494 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17495 unsigned long orig_ip = (unsigned long)p->addr;
17496 kprobe_opcode_t *insn = p->ainsn.insn;
17497
17498 @@ -1002,7 +1012,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
17499 struct die_args *args = data;
17500 int ret = NOTIFY_DONE;
17501
17502 - if (args->regs && user_mode_vm(args->regs))
17503 + if (args->regs && user_mode(args->regs))
17504 return ret;
17505
17506 switch (val) {
17507 @@ -1384,7 +1394,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17508 * Verify if the address gap is in 2GB range, because this uses
17509 * a relative jump.
17510 */
17511 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17512 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17513 if (abs(rel) > 0x7fffffff)
17514 return -ERANGE;
17515
17516 @@ -1405,11 +1415,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17517 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17518
17519 /* Set probe function call */
17520 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17521 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17522
17523 /* Set returning jmp instruction at the tail of out-of-line buffer */
17524 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17525 - (u8 *)op->kp.addr + op->optinsn.size);
17526 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17527
17528 flush_icache_range((unsigned long) buf,
17529 (unsigned long) buf + TMPL_END_IDX +
17530 @@ -1431,7 +1441,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17531 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17532
17533 /* Backup instructions which will be replaced by jump address */
17534 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17535 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17536 RELATIVE_ADDR_SIZE);
17537
17538 insn_buf[0] = RELATIVEJUMP_OPCODE;
17539 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
17540 index a9c2116..a52d4fc 100644
17541 --- a/arch/x86/kernel/kvm.c
17542 +++ b/arch/x86/kernel/kvm.c
17543 @@ -437,6 +437,7 @@ static void __init paravirt_ops_setup(void)
17544 pv_mmu_ops.set_pud = kvm_set_pud;
17545 #if PAGETABLE_LEVELS == 4
17546 pv_mmu_ops.set_pgd = kvm_set_pgd;
17547 + pv_mmu_ops.set_pgd_batched = kvm_set_pgd;
17548 #endif
17549 #endif
17550 pv_mmu_ops.flush_tlb_user = kvm_flush_tlb;
17551 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17552 index ea69726..8b497c9 100644
17553 --- a/arch/x86/kernel/ldt.c
17554 +++ b/arch/x86/kernel/ldt.c
17555 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17556 if (reload) {
17557 #ifdef CONFIG_SMP
17558 preempt_disable();
17559 - load_LDT(pc);
17560 + load_LDT_nolock(pc);
17561 if (!cpumask_equal(mm_cpumask(current->mm),
17562 cpumask_of(smp_processor_id())))
17563 smp_call_function(flush_ldt, current->mm, 1);
17564 preempt_enable();
17565 #else
17566 - load_LDT(pc);
17567 + load_LDT_nolock(pc);
17568 #endif
17569 }
17570 if (oldsize) {
17571 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17572 return err;
17573
17574 for (i = 0; i < old->size; i++)
17575 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17576 + write_ldt_entry(new->ldt, i, old->ldt + i);
17577 return 0;
17578 }
17579
17580 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17581 retval = copy_ldt(&mm->context, &old_mm->context);
17582 mutex_unlock(&old_mm->context.lock);
17583 }
17584 +
17585 + if (tsk == current) {
17586 + mm->context.vdso = 0;
17587 +
17588 +#ifdef CONFIG_X86_32
17589 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17590 + mm->context.user_cs_base = 0UL;
17591 + mm->context.user_cs_limit = ~0UL;
17592 +
17593 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17594 + cpus_clear(mm->context.cpu_user_cs_mask);
17595 +#endif
17596 +
17597 +#endif
17598 +#endif
17599 +
17600 + }
17601 +
17602 return retval;
17603 }
17604
17605 @@ -141,6 +159,7 @@ void destroy_context(struct mm_struct *mm)
17606 }
17607 }
17608
17609 +static int read_ldt(void __user *ptr, unsigned long bytecount) __size_overflow(2);
17610 static int read_ldt(void __user *ptr, unsigned long bytecount)
17611 {
17612 int err;
17613 @@ -230,6 +249,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
17614 }
17615 }
17616
17617 +#ifdef CONFIG_PAX_SEGMEXEC
17618 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
17619 + error = -EINVAL;
17620 + goto out_unlock;
17621 + }
17622 +#endif
17623 +
17624 fill_ldt(&ldt, &ldt_info);
17625 if (oldmode)
17626 ldt.avl = 0;
17627 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
17628 index a3fa43b..8966f4c 100644
17629 --- a/arch/x86/kernel/machine_kexec_32.c
17630 +++ b/arch/x86/kernel/machine_kexec_32.c
17631 @@ -27,7 +27,7 @@
17632 #include <asm/cacheflush.h>
17633 #include <asm/debugreg.h>
17634
17635 -static void set_idt(void *newidt, __u16 limit)
17636 +static void set_idt(struct desc_struct *newidt, __u16 limit)
17637 {
17638 struct desc_ptr curidt;
17639
17640 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16 limit)
17641 }
17642
17643
17644 -static void set_gdt(void *newgdt, __u16 limit)
17645 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
17646 {
17647 struct desc_ptr curgdt;
17648
17649 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
17650 }
17651
17652 control_page = page_address(image->control_code_page);
17653 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
17654 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
17655
17656 relocate_kernel_ptr = control_page;
17657 page_list[PA_CONTROL_PAGE] = __pa(control_page);
17658 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
17659 index 3ca42d0..79d24cd 100644
17660 --- a/arch/x86/kernel/microcode_intel.c
17661 +++ b/arch/x86/kernel/microcode_intel.c
17662 @@ -434,15 +434,16 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
17663 return ret;
17664 }
17665
17666 +static int get_ucode_user(void *to, const void *from, size_t n) __size_overflow(3);
17667 static int get_ucode_user(void *to, const void *from, size_t n)
17668 {
17669 - return copy_from_user(to, from, n);
17670 + return copy_from_user(to, (const void __force_user *)from, n);
17671 }
17672
17673 static enum ucode_state
17674 request_microcode_user(int cpu, const void __user *buf, size_t size)
17675 {
17676 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
17677 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
17678 }
17679
17680 static void microcode_fini_cpu(int cpu)
17681 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
17682 index 925179f..267ac7a 100644
17683 --- a/arch/x86/kernel/module.c
17684 +++ b/arch/x86/kernel/module.c
17685 @@ -36,15 +36,60 @@
17686 #define DEBUGP(fmt...)
17687 #endif
17688
17689 -void *module_alloc(unsigned long size)
17690 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
17691 {
17692 - if (PAGE_ALIGN(size) > MODULES_LEN)
17693 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
17694 return NULL;
17695 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
17696 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
17697 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
17698 -1, __builtin_return_address(0));
17699 }
17700
17701 +void *module_alloc(unsigned long size)
17702 +{
17703 +
17704 +#ifdef CONFIG_PAX_KERNEXEC
17705 + return __module_alloc(size, PAGE_KERNEL);
17706 +#else
17707 + return __module_alloc(size, PAGE_KERNEL_EXEC);
17708 +#endif
17709 +
17710 +}
17711 +
17712 +#ifdef CONFIG_PAX_KERNEXEC
17713 +#ifdef CONFIG_X86_32
17714 +void *module_alloc_exec(unsigned long size)
17715 +{
17716 + struct vm_struct *area;
17717 +
17718 + if (size == 0)
17719 + return NULL;
17720 +
17721 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
17722 + return area ? area->addr : NULL;
17723 +}
17724 +EXPORT_SYMBOL(module_alloc_exec);
17725 +
17726 +void module_free_exec(struct module *mod, void *module_region)
17727 +{
17728 + vunmap(module_region);
17729 +}
17730 +EXPORT_SYMBOL(module_free_exec);
17731 +#else
17732 +void module_free_exec(struct module *mod, void *module_region)
17733 +{
17734 + module_free(mod, module_region);
17735 +}
17736 +EXPORT_SYMBOL(module_free_exec);
17737 +
17738 +void *module_alloc_exec(unsigned long size)
17739 +{
17740 + return __module_alloc(size, PAGE_KERNEL_RX);
17741 +}
17742 +EXPORT_SYMBOL(module_alloc_exec);
17743 +#endif
17744 +#endif
17745 +
17746 #ifdef CONFIG_X86_32
17747 int apply_relocate(Elf32_Shdr *sechdrs,
17748 const char *strtab,
17749 @@ -55,14 +100,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
17750 unsigned int i;
17751 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
17752 Elf32_Sym *sym;
17753 - uint32_t *location;
17754 + uint32_t *plocation, location;
17755
17756 DEBUGP("Applying relocate section %u to %u\n", relsec,
17757 sechdrs[relsec].sh_info);
17758 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
17759 /* This is where to make the change */
17760 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
17761 - + rel[i].r_offset;
17762 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
17763 + location = (uint32_t)plocation;
17764 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
17765 + plocation = ktla_ktva((void *)plocation);
17766 /* This is the symbol it is referring to. Note that all
17767 undefined symbols have been resolved. */
17768 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
17769 @@ -71,11 +118,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
17770 switch (ELF32_R_TYPE(rel[i].r_info)) {
17771 case R_386_32:
17772 /* We add the value into the location given */
17773 - *location += sym->st_value;
17774 + pax_open_kernel();
17775 + *plocation += sym->st_value;
17776 + pax_close_kernel();
17777 break;
17778 case R_386_PC32:
17779 /* Add the value, subtract its postition */
17780 - *location += sym->st_value - (uint32_t)location;
17781 + pax_open_kernel();
17782 + *plocation += sym->st_value - location;
17783 + pax_close_kernel();
17784 break;
17785 default:
17786 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
17787 @@ -120,21 +171,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
17788 case R_X86_64_NONE:
17789 break;
17790 case R_X86_64_64:
17791 + pax_open_kernel();
17792 *(u64 *)loc = val;
17793 + pax_close_kernel();
17794 break;
17795 case R_X86_64_32:
17796 + pax_open_kernel();
17797 *(u32 *)loc = val;
17798 + pax_close_kernel();
17799 if (val != *(u32 *)loc)
17800 goto overflow;
17801 break;
17802 case R_X86_64_32S:
17803 + pax_open_kernel();
17804 *(s32 *)loc = val;
17805 + pax_close_kernel();
17806 if ((s64)val != *(s32 *)loc)
17807 goto overflow;
17808 break;
17809 case R_X86_64_PC32:
17810 val -= (u64)loc;
17811 + pax_open_kernel();
17812 *(u32 *)loc = val;
17813 + pax_close_kernel();
17814 +
17815 #if 0
17816 if ((s64)val != *(s32 *)loc)
17817 goto overflow;
17818 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
17819 index e88f37b..1353db6 100644
17820 --- a/arch/x86/kernel/nmi.c
17821 +++ b/arch/x86/kernel/nmi.c
17822 @@ -408,6 +408,17 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
17823 dotraplinkage notrace __kprobes void
17824 do_nmi(struct pt_regs *regs, long error_code)
17825 {
17826 +
17827 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17828 + if (!user_mode(regs)) {
17829 + unsigned long cs = regs->cs & 0xFFFF;
17830 + unsigned long ip = ktva_ktla(regs->ip);
17831 +
17832 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
17833 + regs->ip = ip;
17834 + }
17835 +#endif
17836 +
17837 nmi_enter();
17838
17839 inc_irq_stat(__nmi_count);
17840 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
17841 index 676b8c7..870ba04 100644
17842 --- a/arch/x86/kernel/paravirt-spinlocks.c
17843 +++ b/arch/x86/kernel/paravirt-spinlocks.c
17844 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
17845 arch_spin_lock(lock);
17846 }
17847
17848 -struct pv_lock_ops pv_lock_ops = {
17849 +struct pv_lock_ops pv_lock_ops __read_only = {
17850 #ifdef CONFIG_SMP
17851 .spin_is_locked = __ticket_spin_is_locked,
17852 .spin_is_contended = __ticket_spin_is_contended,
17853 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
17854 index d90272e..6bb013b 100644
17855 --- a/arch/x86/kernel/paravirt.c
17856 +++ b/arch/x86/kernel/paravirt.c
17857 @@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
17858 {
17859 return x;
17860 }
17861 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
17862 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
17863 +#endif
17864
17865 void __init default_banner(void)
17866 {
17867 @@ -145,15 +148,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
17868 if (opfunc == NULL)
17869 /* If there's no function, patch it with a ud2a (BUG) */
17870 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
17871 - else if (opfunc == _paravirt_nop)
17872 + else if (opfunc == (void *)_paravirt_nop)
17873 /* If the operation is a nop, then nop the callsite */
17874 ret = paravirt_patch_nop();
17875
17876 /* identity functions just return their single argument */
17877 - else if (opfunc == _paravirt_ident_32)
17878 + else if (opfunc == (void *)_paravirt_ident_32)
17879 ret = paravirt_patch_ident_32(insnbuf, len);
17880 - else if (opfunc == _paravirt_ident_64)
17881 + else if (opfunc == (void *)_paravirt_ident_64)
17882 ret = paravirt_patch_ident_64(insnbuf, len);
17883 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
17884 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
17885 + ret = paravirt_patch_ident_64(insnbuf, len);
17886 +#endif
17887
17888 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
17889 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
17890 @@ -178,7 +185,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
17891 if (insn_len > len || start == NULL)
17892 insn_len = len;
17893 else
17894 - memcpy(insnbuf, start, insn_len);
17895 + memcpy(insnbuf, ktla_ktva(start), insn_len);
17896
17897 return insn_len;
17898 }
17899 @@ -302,7 +309,7 @@ void arch_flush_lazy_mmu_mode(void)
17900 preempt_enable();
17901 }
17902
17903 -struct pv_info pv_info = {
17904 +struct pv_info pv_info __read_only = {
17905 .name = "bare hardware",
17906 .paravirt_enabled = 0,
17907 .kernel_rpl = 0,
17908 @@ -313,16 +320,16 @@ struct pv_info pv_info = {
17909 #endif
17910 };
17911
17912 -struct pv_init_ops pv_init_ops = {
17913 +struct pv_init_ops pv_init_ops __read_only = {
17914 .patch = native_patch,
17915 };
17916
17917 -struct pv_time_ops pv_time_ops = {
17918 +struct pv_time_ops pv_time_ops __read_only = {
17919 .sched_clock = native_sched_clock,
17920 .steal_clock = native_steal_clock,
17921 };
17922
17923 -struct pv_irq_ops pv_irq_ops = {
17924 +struct pv_irq_ops pv_irq_ops __read_only = {
17925 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
17926 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
17927 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
17928 @@ -334,7 +341,7 @@ struct pv_irq_ops pv_irq_ops = {
17929 #endif
17930 };
17931
17932 -struct pv_cpu_ops pv_cpu_ops = {
17933 +struct pv_cpu_ops pv_cpu_ops __read_only = {
17934 .cpuid = native_cpuid,
17935 .get_debugreg = native_get_debugreg,
17936 .set_debugreg = native_set_debugreg,
17937 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
17938 .end_context_switch = paravirt_nop,
17939 };
17940
17941 -struct pv_apic_ops pv_apic_ops = {
17942 +struct pv_apic_ops pv_apic_ops __read_only = {
17943 #ifdef CONFIG_X86_LOCAL_APIC
17944 .startup_ipi_hook = paravirt_nop,
17945 #endif
17946 };
17947
17948 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
17949 +#ifdef CONFIG_X86_32
17950 +#ifdef CONFIG_X86_PAE
17951 +/* 64-bit pagetable entries */
17952 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
17953 +#else
17954 /* 32-bit pagetable entries */
17955 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
17956 +#endif
17957 #else
17958 /* 64-bit pagetable entries */
17959 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
17960 #endif
17961
17962 -struct pv_mmu_ops pv_mmu_ops = {
17963 +struct pv_mmu_ops pv_mmu_ops __read_only = {
17964
17965 .read_cr2 = native_read_cr2,
17966 .write_cr2 = native_write_cr2,
17967 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
17968 .make_pud = PTE_IDENT,
17969
17970 .set_pgd = native_set_pgd,
17971 + .set_pgd_batched = native_set_pgd_batched,
17972 #endif
17973 #endif /* PAGETABLE_LEVELS >= 3 */
17974
17975 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
17976 },
17977
17978 .set_fixmap = native_set_fixmap,
17979 +
17980 +#ifdef CONFIG_PAX_KERNEXEC
17981 + .pax_open_kernel = native_pax_open_kernel,
17982 + .pax_close_kernel = native_pax_close_kernel,
17983 +#endif
17984 +
17985 };
17986
17987 EXPORT_SYMBOL_GPL(pv_time_ops);
17988 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
17989 index 35ccf75..7a15747 100644
17990 --- a/arch/x86/kernel/pci-iommu_table.c
17991 +++ b/arch/x86/kernel/pci-iommu_table.c
17992 @@ -2,7 +2,7 @@
17993 #include <asm/iommu_table.h>
17994 #include <linux/string.h>
17995 #include <linux/kallsyms.h>
17996 -
17997 +#include <linux/sched.h>
17998
17999 #define DEBUG 1
18000
18001 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18002 index ee5d4fb..426649b 100644
18003 --- a/arch/x86/kernel/process.c
18004 +++ b/arch/x86/kernel/process.c
18005 @@ -48,16 +48,33 @@ void free_thread_xstate(struct task_struct *tsk)
18006
18007 void free_thread_info(struct thread_info *ti)
18008 {
18009 - free_thread_xstate(ti->task);
18010 free_pages((unsigned long)ti, THREAD_ORDER);
18011 }
18012
18013 +static struct kmem_cache *task_struct_cachep;
18014 +
18015 void arch_task_cache_init(void)
18016 {
18017 - task_xstate_cachep =
18018 - kmem_cache_create("task_xstate", xstate_size,
18019 + /* create a slab on which task_structs can be allocated */
18020 + task_struct_cachep =
18021 + kmem_cache_create("task_struct", sizeof(struct task_struct),
18022 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
18023 +
18024 + task_xstate_cachep =
18025 + kmem_cache_create("task_xstate", xstate_size,
18026 __alignof__(union thread_xstate),
18027 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18028 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18029 +}
18030 +
18031 +struct task_struct *alloc_task_struct_node(int node)
18032 +{
18033 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
18034 +}
18035 +
18036 +void free_task_struct(struct task_struct *task)
18037 +{
18038 + free_thread_xstate(task);
18039 + kmem_cache_free(task_struct_cachep, task);
18040 }
18041
18042 /*
18043 @@ -70,7 +87,7 @@ void exit_thread(void)
18044 unsigned long *bp = t->io_bitmap_ptr;
18045
18046 if (bp) {
18047 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18048 + struct tss_struct *tss = init_tss + get_cpu();
18049
18050 t->io_bitmap_ptr = NULL;
18051 clear_thread_flag(TIF_IO_BITMAP);
18052 @@ -106,7 +123,7 @@ void show_regs_common(void)
18053
18054 printk(KERN_CONT "\n");
18055 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18056 - current->pid, current->comm, print_tainted(),
18057 + task_pid_nr(current), current->comm, print_tainted(),
18058 init_utsname()->release,
18059 (int)strcspn(init_utsname()->version, " "),
18060 init_utsname()->version);
18061 @@ -120,6 +137,9 @@ void flush_thread(void)
18062 {
18063 struct task_struct *tsk = current;
18064
18065 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18066 + loadsegment(gs, 0);
18067 +#endif
18068 flush_ptrace_hw_breakpoint(tsk);
18069 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18070 /*
18071 @@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18072 regs.di = (unsigned long) arg;
18073
18074 #ifdef CONFIG_X86_32
18075 - regs.ds = __USER_DS;
18076 - regs.es = __USER_DS;
18077 + regs.ds = __KERNEL_DS;
18078 + regs.es = __KERNEL_DS;
18079 regs.fs = __KERNEL_PERCPU;
18080 - regs.gs = __KERNEL_STACK_CANARY;
18081 + savesegment(gs, regs.gs);
18082 #else
18083 regs.ss = __KERNEL_DS;
18084 #endif
18085 @@ -411,7 +431,7 @@ bool set_pm_idle_to_default(void)
18086
18087 return ret;
18088 }
18089 -void stop_this_cpu(void *dummy)
18090 +__noreturn void stop_this_cpu(void *dummy)
18091 {
18092 local_irq_disable();
18093 /*
18094 @@ -653,16 +673,37 @@ static int __init idle_setup(char *str)
18095 }
18096 early_param("idle", idle_setup);
18097
18098 -unsigned long arch_align_stack(unsigned long sp)
18099 +#ifdef CONFIG_PAX_RANDKSTACK
18100 +void pax_randomize_kstack(struct pt_regs *regs)
18101 {
18102 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18103 - sp -= get_random_int() % 8192;
18104 - return sp & ~0xf;
18105 -}
18106 + struct thread_struct *thread = &current->thread;
18107 + unsigned long time;
18108
18109 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18110 -{
18111 - unsigned long range_end = mm->brk + 0x02000000;
18112 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18113 -}
18114 + if (!randomize_va_space)
18115 + return;
18116 +
18117 + if (v8086_mode(regs))
18118 + return;
18119
18120 + rdtscl(time);
18121 +
18122 + /* P4 seems to return a 0 LSB, ignore it */
18123 +#ifdef CONFIG_MPENTIUM4
18124 + time &= 0x3EUL;
18125 + time <<= 2;
18126 +#elif defined(CONFIG_X86_64)
18127 + time &= 0xFUL;
18128 + time <<= 4;
18129 +#else
18130 + time &= 0x1FUL;
18131 + time <<= 3;
18132 +#endif
18133 +
18134 + thread->sp0 ^= time;
18135 + load_sp0(init_tss + smp_processor_id(), thread);
18136 +
18137 +#ifdef CONFIG_X86_64
18138 + percpu_write(kernel_stack, thread->sp0);
18139 +#endif
18140 +}
18141 +#endif
18142 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18143 index 8598296..bfadef0 100644
18144 --- a/arch/x86/kernel/process_32.c
18145 +++ b/arch/x86/kernel/process_32.c
18146 @@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18147 unsigned long thread_saved_pc(struct task_struct *tsk)
18148 {
18149 return ((unsigned long *)tsk->thread.sp)[3];
18150 +//XXX return tsk->thread.eip;
18151 }
18152
18153 #ifndef CONFIG_SMP
18154 @@ -130,15 +131,14 @@ void __show_regs(struct pt_regs *regs, int all)
18155 unsigned long sp;
18156 unsigned short ss, gs;
18157
18158 - if (user_mode_vm(regs)) {
18159 + if (user_mode(regs)) {
18160 sp = regs->sp;
18161 ss = regs->ss & 0xffff;
18162 - gs = get_user_gs(regs);
18163 } else {
18164 sp = kernel_stack_pointer(regs);
18165 savesegment(ss, ss);
18166 - savesegment(gs, gs);
18167 }
18168 + gs = get_user_gs(regs);
18169
18170 show_regs_common();
18171
18172 @@ -200,13 +200,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18173 struct task_struct *tsk;
18174 int err;
18175
18176 - childregs = task_pt_regs(p);
18177 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18178 *childregs = *regs;
18179 childregs->ax = 0;
18180 childregs->sp = sp;
18181
18182 p->thread.sp = (unsigned long) childregs;
18183 p->thread.sp0 = (unsigned long) (childregs+1);
18184 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18185
18186 p->thread.ip = (unsigned long) ret_from_fork;
18187
18188 @@ -296,7 +297,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18189 struct thread_struct *prev = &prev_p->thread,
18190 *next = &next_p->thread;
18191 int cpu = smp_processor_id();
18192 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18193 + struct tss_struct *tss = init_tss + cpu;
18194 fpu_switch_t fpu;
18195
18196 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18197 @@ -320,6 +321,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18198 */
18199 lazy_save_gs(prev->gs);
18200
18201 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18202 + __set_fs(task_thread_info(next_p)->addr_limit);
18203 +#endif
18204 +
18205 /*
18206 * Load the per-thread Thread-Local Storage descriptor.
18207 */
18208 @@ -350,6 +355,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18209 */
18210 arch_end_context_switch(next_p);
18211
18212 + percpu_write(current_task, next_p);
18213 + percpu_write(current_tinfo, &next_p->tinfo);
18214 +
18215 /*
18216 * Restore %gs if needed (which is common)
18217 */
18218 @@ -358,8 +366,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18219
18220 switch_fpu_finish(next_p, fpu);
18221
18222 - percpu_write(current_task, next_p);
18223 -
18224 return prev_p;
18225 }
18226
18227 @@ -389,4 +395,3 @@ unsigned long get_wchan(struct task_struct *p)
18228 } while (count++ < 16);
18229 return 0;
18230 }
18231 -
18232 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18233 index 6a364a6..b147d11 100644
18234 --- a/arch/x86/kernel/process_64.c
18235 +++ b/arch/x86/kernel/process_64.c
18236 @@ -89,7 +89,7 @@ static void __exit_idle(void)
18237 void exit_idle(void)
18238 {
18239 /* idle loop has pid 0 */
18240 - if (current->pid)
18241 + if (task_pid_nr(current))
18242 return;
18243 __exit_idle();
18244 }
18245 @@ -264,8 +264,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18246 struct pt_regs *childregs;
18247 struct task_struct *me = current;
18248
18249 - childregs = ((struct pt_regs *)
18250 - (THREAD_SIZE + task_stack_page(p))) - 1;
18251 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18252 *childregs = *regs;
18253
18254 childregs->ax = 0;
18255 @@ -277,6 +276,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18256 p->thread.sp = (unsigned long) childregs;
18257 p->thread.sp0 = (unsigned long) (childregs+1);
18258 p->thread.usersp = me->thread.usersp;
18259 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18260
18261 set_tsk_thread_flag(p, TIF_FORK);
18262
18263 @@ -379,7 +379,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18264 struct thread_struct *prev = &prev_p->thread;
18265 struct thread_struct *next = &next_p->thread;
18266 int cpu = smp_processor_id();
18267 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18268 + struct tss_struct *tss = init_tss + cpu;
18269 unsigned fsindex, gsindex;
18270 fpu_switch_t fpu;
18271
18272 @@ -461,10 +461,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18273 prev->usersp = percpu_read(old_rsp);
18274 percpu_write(old_rsp, next->usersp);
18275 percpu_write(current_task, next_p);
18276 + percpu_write(current_tinfo, &next_p->tinfo);
18277
18278 - percpu_write(kernel_stack,
18279 - (unsigned long)task_stack_page(next_p) +
18280 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18281 + percpu_write(kernel_stack, next->sp0);
18282
18283 /*
18284 * Now maybe reload the debug registers and handle I/O bitmaps
18285 @@ -519,12 +518,11 @@ unsigned long get_wchan(struct task_struct *p)
18286 if (!p || p == current || p->state == TASK_RUNNING)
18287 return 0;
18288 stack = (unsigned long)task_stack_page(p);
18289 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18290 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18291 return 0;
18292 fp = *(u64 *)(p->thread.sp);
18293 do {
18294 - if (fp < (unsigned long)stack ||
18295 - fp >= (unsigned long)stack+THREAD_SIZE)
18296 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18297 return 0;
18298 ip = *(u64 *)(fp+8);
18299 if (!in_sched_functions(ip))
18300 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18301 index 8252879..f367ec9 100644
18302 --- a/arch/x86/kernel/ptrace.c
18303 +++ b/arch/x86/kernel/ptrace.c
18304 @@ -791,6 +791,10 @@ static int ioperm_active(struct task_struct *target,
18305 static int ioperm_get(struct task_struct *target,
18306 const struct user_regset *regset,
18307 unsigned int pos, unsigned int count,
18308 + void *kbuf, void __user *ubuf) __size_overflow(3,4);
18309 +static int ioperm_get(struct task_struct *target,
18310 + const struct user_regset *regset,
18311 + unsigned int pos, unsigned int count,
18312 void *kbuf, void __user *ubuf)
18313 {
18314 if (!target->thread.io_bitmap_ptr)
18315 @@ -822,7 +826,7 @@ long arch_ptrace(struct task_struct *child, long request,
18316 unsigned long addr, unsigned long data)
18317 {
18318 int ret;
18319 - unsigned long __user *datap = (unsigned long __user *)data;
18320 + unsigned long __user *datap = (__force unsigned long __user *)data;
18321
18322 switch (request) {
18323 /* read the word at location addr in the USER area. */
18324 @@ -907,14 +911,14 @@ long arch_ptrace(struct task_struct *child, long request,
18325 if ((int) addr < 0)
18326 return -EIO;
18327 ret = do_get_thread_area(child, addr,
18328 - (struct user_desc __user *)data);
18329 + (__force struct user_desc __user *) data);
18330 break;
18331
18332 case PTRACE_SET_THREAD_AREA:
18333 if ((int) addr < 0)
18334 return -EIO;
18335 ret = do_set_thread_area(child, addr,
18336 - (struct user_desc __user *)data, 0);
18337 + (__force struct user_desc __user *) data, 0);
18338 break;
18339 #endif
18340
18341 @@ -1331,7 +1335,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18342 memset(info, 0, sizeof(*info));
18343 info->si_signo = SIGTRAP;
18344 info->si_code = si_code;
18345 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18346 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18347 }
18348
18349 void user_single_step_siginfo(struct task_struct *tsk,
18350 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18351 index 42eb330..139955c 100644
18352 --- a/arch/x86/kernel/pvclock.c
18353 +++ b/arch/x86/kernel/pvclock.c
18354 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18355 return pv_tsc_khz;
18356 }
18357
18358 -static atomic64_t last_value = ATOMIC64_INIT(0);
18359 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18360
18361 void pvclock_resume(void)
18362 {
18363 - atomic64_set(&last_value, 0);
18364 + atomic64_set_unchecked(&last_value, 0);
18365 }
18366
18367 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18368 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18369 * updating at the same time, and one of them could be slightly behind,
18370 * making the assumption that last_value always go forward fail to hold.
18371 */
18372 - last = atomic64_read(&last_value);
18373 + last = atomic64_read_unchecked(&last_value);
18374 do {
18375 if (ret < last)
18376 return last;
18377 - last = atomic64_cmpxchg(&last_value, last, ret);
18378 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18379 } while (unlikely(last != ret));
18380
18381 return ret;
18382 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18383 index 37a458b..e63d183 100644
18384 --- a/arch/x86/kernel/reboot.c
18385 +++ b/arch/x86/kernel/reboot.c
18386 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
18387 EXPORT_SYMBOL(pm_power_off);
18388
18389 static const struct desc_ptr no_idt = {};
18390 -static int reboot_mode;
18391 +static unsigned short reboot_mode;
18392 enum reboot_type reboot_type = BOOT_ACPI;
18393 int reboot_force;
18394
18395 @@ -324,13 +324,17 @@ core_initcall(reboot_init);
18396 extern const unsigned char machine_real_restart_asm[];
18397 extern const u64 machine_real_restart_gdt[3];
18398
18399 -void machine_real_restart(unsigned int type)
18400 +__noreturn void machine_real_restart(unsigned int type)
18401 {
18402 void *restart_va;
18403 unsigned long restart_pa;
18404 - void (*restart_lowmem)(unsigned int);
18405 + void (* __noreturn restart_lowmem)(unsigned int);
18406 u64 *lowmem_gdt;
18407
18408 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18409 + struct desc_struct *gdt;
18410 +#endif
18411 +
18412 local_irq_disable();
18413
18414 /* Write zero to CMOS register number 0x0f, which the BIOS POST
18415 @@ -356,14 +360,14 @@ void machine_real_restart(unsigned int type)
18416 boot)". This seems like a fairly standard thing that gets set by
18417 REBOOT.COM programs, and the previous reset routine did this
18418 too. */
18419 - *((unsigned short *)0x472) = reboot_mode;
18420 + *(unsigned short *)(__va(0x472)) = reboot_mode;
18421
18422 /* Patch the GDT in the low memory trampoline */
18423 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
18424
18425 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
18426 restart_pa = virt_to_phys(restart_va);
18427 - restart_lowmem = (void (*)(unsigned int))restart_pa;
18428 + restart_lowmem = (void *)restart_pa;
18429
18430 /* GDT[0]: GDT self-pointer */
18431 lowmem_gdt[0] =
18432 @@ -374,7 +378,33 @@ void machine_real_restart(unsigned int type)
18433 GDT_ENTRY(0x009b, restart_pa, 0xffff);
18434
18435 /* Jump to the identity-mapped low memory code */
18436 +
18437 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18438 + gdt = get_cpu_gdt_table(smp_processor_id());
18439 + pax_open_kernel();
18440 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18441 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18442 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18443 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18444 +#endif
18445 +#ifdef CONFIG_PAX_KERNEXEC
18446 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18447 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18448 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18449 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18450 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18451 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18452 +#endif
18453 + pax_close_kernel();
18454 +#endif
18455 +
18456 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18457 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18458 + unreachable();
18459 +#else
18460 restart_lowmem(type);
18461 +#endif
18462 +
18463 }
18464 #ifdef CONFIG_APM_MODULE
18465 EXPORT_SYMBOL(machine_real_restart);
18466 @@ -540,7 +570,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18467 * try to force a triple fault and then cycle between hitting the keyboard
18468 * controller and doing that
18469 */
18470 -static void native_machine_emergency_restart(void)
18471 +__noreturn static void native_machine_emergency_restart(void)
18472 {
18473 int i;
18474 int attempt = 0;
18475 @@ -664,13 +694,13 @@ void native_machine_shutdown(void)
18476 #endif
18477 }
18478
18479 -static void __machine_emergency_restart(int emergency)
18480 +static __noreturn void __machine_emergency_restart(int emergency)
18481 {
18482 reboot_emergency = emergency;
18483 machine_ops.emergency_restart();
18484 }
18485
18486 -static void native_machine_restart(char *__unused)
18487 +static __noreturn void native_machine_restart(char *__unused)
18488 {
18489 printk("machine restart\n");
18490
18491 @@ -679,7 +709,7 @@ static void native_machine_restart(char *__unused)
18492 __machine_emergency_restart(0);
18493 }
18494
18495 -static void native_machine_halt(void)
18496 +static __noreturn void native_machine_halt(void)
18497 {
18498 /* stop other cpus and apics */
18499 machine_shutdown();
18500 @@ -690,7 +720,7 @@ static void native_machine_halt(void)
18501 stop_this_cpu(NULL);
18502 }
18503
18504 -static void native_machine_power_off(void)
18505 +__noreturn static void native_machine_power_off(void)
18506 {
18507 if (pm_power_off) {
18508 if (!reboot_force)
18509 @@ -699,6 +729,7 @@ static void native_machine_power_off(void)
18510 }
18511 /* a fallback in case there is no PM info available */
18512 tboot_shutdown(TB_SHUTDOWN_HALT);
18513 + unreachable();
18514 }
18515
18516 struct machine_ops machine_ops = {
18517 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18518 index 7a6f3b3..bed145d7 100644
18519 --- a/arch/x86/kernel/relocate_kernel_64.S
18520 +++ b/arch/x86/kernel/relocate_kernel_64.S
18521 @@ -11,6 +11,7 @@
18522 #include <asm/kexec.h>
18523 #include <asm/processor-flags.h>
18524 #include <asm/pgtable_types.h>
18525 +#include <asm/alternative-asm.h>
18526
18527 /*
18528 * Must be relocatable PIC code callable as a C function
18529 @@ -160,13 +161,14 @@ identity_mapped:
18530 xorq %rbp, %rbp
18531 xorq %r8, %r8
18532 xorq %r9, %r9
18533 - xorq %r10, %r9
18534 + xorq %r10, %r10
18535 xorq %r11, %r11
18536 xorq %r12, %r12
18537 xorq %r13, %r13
18538 xorq %r14, %r14
18539 xorq %r15, %r15
18540
18541 + pax_force_retaddr 0, 1
18542 ret
18543
18544 1:
18545 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18546 index cf0ef98..e3f780b 100644
18547 --- a/arch/x86/kernel/setup.c
18548 +++ b/arch/x86/kernel/setup.c
18549 @@ -447,7 +447,7 @@ static void __init parse_setup_data(void)
18550
18551 switch (data->type) {
18552 case SETUP_E820_EXT:
18553 - parse_e820_ext(data);
18554 + parse_e820_ext((struct setup_data __force_kernel *)data);
18555 break;
18556 case SETUP_DTB:
18557 add_dtb(pa_data);
18558 @@ -650,7 +650,7 @@ static void __init trim_bios_range(void)
18559 * area (640->1Mb) as ram even though it is not.
18560 * take them out.
18561 */
18562 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18563 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18564 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18565 }
18566
18567 @@ -773,14 +773,14 @@ void __init setup_arch(char **cmdline_p)
18568
18569 if (!boot_params.hdr.root_flags)
18570 root_mountflags &= ~MS_RDONLY;
18571 - init_mm.start_code = (unsigned long) _text;
18572 - init_mm.end_code = (unsigned long) _etext;
18573 + init_mm.start_code = ktla_ktva((unsigned long) _text);
18574 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
18575 init_mm.end_data = (unsigned long) _edata;
18576 init_mm.brk = _brk_end;
18577
18578 - code_resource.start = virt_to_phys(_text);
18579 - code_resource.end = virt_to_phys(_etext)-1;
18580 - data_resource.start = virt_to_phys(_etext);
18581 + code_resource.start = virt_to_phys(ktla_ktva(_text));
18582 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18583 + data_resource.start = virt_to_phys(_sdata);
18584 data_resource.end = virt_to_phys(_edata)-1;
18585 bss_resource.start = virt_to_phys(&__bss_start);
18586 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18587 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18588 index 71f4727..217419b 100644
18589 --- a/arch/x86/kernel/setup_percpu.c
18590 +++ b/arch/x86/kernel/setup_percpu.c
18591 @@ -21,19 +21,17 @@
18592 #include <asm/cpu.h>
18593 #include <asm/stackprotector.h>
18594
18595 -DEFINE_PER_CPU(int, cpu_number);
18596 +#ifdef CONFIG_SMP
18597 +DEFINE_PER_CPU(unsigned int, cpu_number);
18598 EXPORT_PER_CPU_SYMBOL(cpu_number);
18599 +#endif
18600
18601 -#ifdef CONFIG_X86_64
18602 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18603 -#else
18604 -#define BOOT_PERCPU_OFFSET 0
18605 -#endif
18606
18607 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18608 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18609
18610 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18611 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18612 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
18613 };
18614 EXPORT_SYMBOL(__per_cpu_offset);
18615 @@ -96,6 +94,8 @@ static bool __init pcpu_need_numa(void)
18616 * Pointer to the allocated area on success, NULL on failure.
18617 */
18618 static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
18619 + unsigned long align) __size_overflow(2);
18620 +static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
18621 unsigned long align)
18622 {
18623 const unsigned long goal = __pa(MAX_DMA_ADDRESS);
18624 @@ -124,6 +124,8 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
18625 /*
18626 * Helpers for first chunk memory allocation
18627 */
18628 +static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align) __size_overflow(2);
18629 +
18630 static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align)
18631 {
18632 return pcpu_alloc_bootmem(cpu, size, align);
18633 @@ -155,10 +157,10 @@ static inline void setup_percpu_segment(int cpu)
18634 {
18635 #ifdef CONFIG_X86_32
18636 struct desc_struct gdt;
18637 + unsigned long base = per_cpu_offset(cpu);
18638
18639 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
18640 - 0x2 | DESCTYPE_S, 0x8);
18641 - gdt.s = 1;
18642 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
18643 + 0x83 | DESCTYPE_S, 0xC);
18644 write_gdt_entry(get_cpu_gdt_table(cpu),
18645 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
18646 #endif
18647 @@ -207,6 +209,11 @@ void __init setup_per_cpu_areas(void)
18648 /* alrighty, percpu areas up and running */
18649 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
18650 for_each_possible_cpu(cpu) {
18651 +#ifdef CONFIG_CC_STACKPROTECTOR
18652 +#ifdef CONFIG_X86_32
18653 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
18654 +#endif
18655 +#endif
18656 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
18657 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
18658 per_cpu(cpu_number, cpu) = cpu;
18659 @@ -247,6 +254,12 @@ void __init setup_per_cpu_areas(void)
18660 */
18661 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
18662 #endif
18663 +#ifdef CONFIG_CC_STACKPROTECTOR
18664 +#ifdef CONFIG_X86_32
18665 + if (!cpu)
18666 + per_cpu(stack_canary.canary, cpu) = canary;
18667 +#endif
18668 +#endif
18669 /*
18670 * Up to this point, the boot CPU has been using .init.data
18671 * area. Reload any changed state for the boot CPU.
18672 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
18673 index 54ddaeb2..22c3bdc 100644
18674 --- a/arch/x86/kernel/signal.c
18675 +++ b/arch/x86/kernel/signal.c
18676 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsigned long sp)
18677 * Align the stack pointer according to the i386 ABI,
18678 * i.e. so that on function entry ((sp + 4) & 15) == 0.
18679 */
18680 - sp = ((sp + 4) & -16ul) - 4;
18681 + sp = ((sp - 12) & -16ul) - 4;
18682 #else /* !CONFIG_X86_32 */
18683 sp = round_down(sp, 16) - 8;
18684 #endif
18685 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
18686 * Return an always-bogus address instead so we will die with SIGSEGV.
18687 */
18688 if (onsigstack && !likely(on_sig_stack(sp)))
18689 - return (void __user *)-1L;
18690 + return (__force void __user *)-1L;
18691
18692 /* save i387 state */
18693 if (used_math() && save_i387_xstate(*fpstate) < 0)
18694 - return (void __user *)-1L;
18695 + return (__force void __user *)-1L;
18696
18697 return (void __user *)sp;
18698 }
18699 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18700 }
18701
18702 if (current->mm->context.vdso)
18703 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18704 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18705 else
18706 - restorer = &frame->retcode;
18707 + restorer = (void __user *)&frame->retcode;
18708 if (ka->sa.sa_flags & SA_RESTORER)
18709 restorer = ka->sa.sa_restorer;
18710
18711 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18712 * reasons and because gdb uses it as a signature to notice
18713 * signal handler stack frames.
18714 */
18715 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
18716 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
18717
18718 if (err)
18719 return -EFAULT;
18720 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18721 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
18722
18723 /* Set up to return from userspace. */
18724 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18725 + if (current->mm->context.vdso)
18726 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18727 + else
18728 + restorer = (void __user *)&frame->retcode;
18729 if (ka->sa.sa_flags & SA_RESTORER)
18730 restorer = ka->sa.sa_restorer;
18731 put_user_ex(restorer, &frame->pretcode);
18732 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18733 * reasons and because gdb uses it as a signature to notice
18734 * signal handler stack frames.
18735 */
18736 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
18737 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
18738 } put_user_catch(err);
18739
18740 if (err)
18741 @@ -769,7 +772,7 @@ static void do_signal(struct pt_regs *regs)
18742 * X86_32: vm86 regs switched out by assembly code before reaching
18743 * here, so testing against kernel CS suffices.
18744 */
18745 - if (!user_mode(regs))
18746 + if (!user_mode_novm(regs))
18747 return;
18748
18749 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
18750 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
18751 index 9f548cb..caf76f7 100644
18752 --- a/arch/x86/kernel/smpboot.c
18753 +++ b/arch/x86/kernel/smpboot.c
18754 @@ -709,17 +709,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
18755 set_idle_for_cpu(cpu, c_idle.idle);
18756 do_rest:
18757 per_cpu(current_task, cpu) = c_idle.idle;
18758 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
18759 #ifdef CONFIG_X86_32
18760 /* Stack for startup_32 can be just as for start_secondary onwards */
18761 irq_ctx_init(cpu);
18762 #else
18763 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
18764 initial_gs = per_cpu_offset(cpu);
18765 - per_cpu(kernel_stack, cpu) =
18766 - (unsigned long)task_stack_page(c_idle.idle) -
18767 - KERNEL_STACK_OFFSET + THREAD_SIZE;
18768 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
18769 #endif
18770 +
18771 + pax_open_kernel();
18772 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
18773 + pax_close_kernel();
18774 +
18775 initial_code = (unsigned long)start_secondary;
18776 stack_start = c_idle.idle->thread.sp;
18777
18778 @@ -861,6 +864,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
18779
18780 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
18781
18782 +#ifdef CONFIG_PAX_PER_CPU_PGD
18783 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
18784 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
18785 + KERNEL_PGD_PTRS);
18786 +#endif
18787 +
18788 err = do_boot_cpu(apicid, cpu);
18789 if (err) {
18790 pr_debug("do_boot_cpu failed %d\n", err);
18791 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
18792 index c346d11..d43b163 100644
18793 --- a/arch/x86/kernel/step.c
18794 +++ b/arch/x86/kernel/step.c
18795 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
18796 struct desc_struct *desc;
18797 unsigned long base;
18798
18799 - seg &= ~7UL;
18800 + seg >>= 3;
18801
18802 mutex_lock(&child->mm->context.lock);
18803 - if (unlikely((seg >> 3) >= child->mm->context.size))
18804 + if (unlikely(seg >= child->mm->context.size))
18805 addr = -1L; /* bogus selector, access would fault */
18806 else {
18807 desc = child->mm->context.ldt + seg;
18808 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
18809 addr += base;
18810 }
18811 mutex_unlock(&child->mm->context.lock);
18812 - }
18813 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
18814 + addr = ktla_ktva(addr);
18815
18816 return addr;
18817 }
18818 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
18819 unsigned char opcode[15];
18820 unsigned long addr = convert_ip_to_linear(child, regs);
18821
18822 + if (addr == -EINVAL)
18823 + return 0;
18824 +
18825 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
18826 for (i = 0; i < copied; i++) {
18827 switch (opcode[i]) {
18828 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
18829 index 0b0cb5f..db6b9ed 100644
18830 --- a/arch/x86/kernel/sys_i386_32.c
18831 +++ b/arch/x86/kernel/sys_i386_32.c
18832 @@ -24,17 +24,224 @@
18833
18834 #include <asm/syscalls.h>
18835
18836 -/*
18837 - * Do a system call from kernel instead of calling sys_execve so we
18838 - * end up with proper pt_regs.
18839 - */
18840 -int kernel_execve(const char *filename,
18841 - const char *const argv[],
18842 - const char *const envp[])
18843 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
18844 {
18845 - long __res;
18846 - asm volatile ("int $0x80"
18847 - : "=a" (__res)
18848 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
18849 - return __res;
18850 + unsigned long pax_task_size = TASK_SIZE;
18851 +
18852 +#ifdef CONFIG_PAX_SEGMEXEC
18853 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
18854 + pax_task_size = SEGMEXEC_TASK_SIZE;
18855 +#endif
18856 +
18857 + if (len > pax_task_size || addr > pax_task_size - len)
18858 + return -EINVAL;
18859 +
18860 + return 0;
18861 +}
18862 +
18863 +unsigned long
18864 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
18865 + unsigned long len, unsigned long pgoff, unsigned long flags)
18866 +{
18867 + struct mm_struct *mm = current->mm;
18868 + struct vm_area_struct *vma;
18869 + unsigned long start_addr, pax_task_size = TASK_SIZE;
18870 +
18871 +#ifdef CONFIG_PAX_SEGMEXEC
18872 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18873 + pax_task_size = SEGMEXEC_TASK_SIZE;
18874 +#endif
18875 +
18876 + pax_task_size -= PAGE_SIZE;
18877 +
18878 + if (len > pax_task_size)
18879 + return -ENOMEM;
18880 +
18881 + if (flags & MAP_FIXED)
18882 + return addr;
18883 +
18884 +#ifdef CONFIG_PAX_RANDMMAP
18885 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18886 +#endif
18887 +
18888 + if (addr) {
18889 + addr = PAGE_ALIGN(addr);
18890 + if (pax_task_size - len >= addr) {
18891 + vma = find_vma(mm, addr);
18892 + if (check_heap_stack_gap(vma, addr, len))
18893 + return addr;
18894 + }
18895 + }
18896 + if (len > mm->cached_hole_size) {
18897 + start_addr = addr = mm->free_area_cache;
18898 + } else {
18899 + start_addr = addr = mm->mmap_base;
18900 + mm->cached_hole_size = 0;
18901 + }
18902 +
18903 +#ifdef CONFIG_PAX_PAGEEXEC
18904 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
18905 + start_addr = 0x00110000UL;
18906 +
18907 +#ifdef CONFIG_PAX_RANDMMAP
18908 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18909 + start_addr += mm->delta_mmap & 0x03FFF000UL;
18910 +#endif
18911 +
18912 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
18913 + start_addr = addr = mm->mmap_base;
18914 + else
18915 + addr = start_addr;
18916 + }
18917 +#endif
18918 +
18919 +full_search:
18920 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
18921 + /* At this point: (!vma || addr < vma->vm_end). */
18922 + if (pax_task_size - len < addr) {
18923 + /*
18924 + * Start a new search - just in case we missed
18925 + * some holes.
18926 + */
18927 + if (start_addr != mm->mmap_base) {
18928 + start_addr = addr = mm->mmap_base;
18929 + mm->cached_hole_size = 0;
18930 + goto full_search;
18931 + }
18932 + return -ENOMEM;
18933 + }
18934 + if (check_heap_stack_gap(vma, addr, len))
18935 + break;
18936 + if (addr + mm->cached_hole_size < vma->vm_start)
18937 + mm->cached_hole_size = vma->vm_start - addr;
18938 + addr = vma->vm_end;
18939 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
18940 + start_addr = addr = mm->mmap_base;
18941 + mm->cached_hole_size = 0;
18942 + goto full_search;
18943 + }
18944 + }
18945 +
18946 + /*
18947 + * Remember the place where we stopped the search:
18948 + */
18949 + mm->free_area_cache = addr + len;
18950 + return addr;
18951 +}
18952 +
18953 +unsigned long
18954 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18955 + const unsigned long len, const unsigned long pgoff,
18956 + const unsigned long flags)
18957 +{
18958 + struct vm_area_struct *vma;
18959 + struct mm_struct *mm = current->mm;
18960 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
18961 +
18962 +#ifdef CONFIG_PAX_SEGMEXEC
18963 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18964 + pax_task_size = SEGMEXEC_TASK_SIZE;
18965 +#endif
18966 +
18967 + pax_task_size -= PAGE_SIZE;
18968 +
18969 + /* requested length too big for entire address space */
18970 + if (len > pax_task_size)
18971 + return -ENOMEM;
18972 +
18973 + if (flags & MAP_FIXED)
18974 + return addr;
18975 +
18976 +#ifdef CONFIG_PAX_PAGEEXEC
18977 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
18978 + goto bottomup;
18979 +#endif
18980 +
18981 +#ifdef CONFIG_PAX_RANDMMAP
18982 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18983 +#endif
18984 +
18985 + /* requesting a specific address */
18986 + if (addr) {
18987 + addr = PAGE_ALIGN(addr);
18988 + if (pax_task_size - len >= addr) {
18989 + vma = find_vma(mm, addr);
18990 + if (check_heap_stack_gap(vma, addr, len))
18991 + return addr;
18992 + }
18993 + }
18994 +
18995 + /* check if free_area_cache is useful for us */
18996 + if (len <= mm->cached_hole_size) {
18997 + mm->cached_hole_size = 0;
18998 + mm->free_area_cache = mm->mmap_base;
18999 + }
19000 +
19001 + /* either no address requested or can't fit in requested address hole */
19002 + addr = mm->free_area_cache;
19003 +
19004 + /* make sure it can fit in the remaining address space */
19005 + if (addr > len) {
19006 + vma = find_vma(mm, addr-len);
19007 + if (check_heap_stack_gap(vma, addr - len, len))
19008 + /* remember the address as a hint for next time */
19009 + return (mm->free_area_cache = addr-len);
19010 + }
19011 +
19012 + if (mm->mmap_base < len)
19013 + goto bottomup;
19014 +
19015 + addr = mm->mmap_base-len;
19016 +
19017 + do {
19018 + /*
19019 + * Lookup failure means no vma is above this address,
19020 + * else if new region fits below vma->vm_start,
19021 + * return with success:
19022 + */
19023 + vma = find_vma(mm, addr);
19024 + if (check_heap_stack_gap(vma, addr, len))
19025 + /* remember the address as a hint for next time */
19026 + return (mm->free_area_cache = addr);
19027 +
19028 + /* remember the largest hole we saw so far */
19029 + if (addr + mm->cached_hole_size < vma->vm_start)
19030 + mm->cached_hole_size = vma->vm_start - addr;
19031 +
19032 + /* try just below the current vma->vm_start */
19033 + addr = skip_heap_stack_gap(vma, len);
19034 + } while (!IS_ERR_VALUE(addr));
19035 +
19036 +bottomup:
19037 + /*
19038 + * A failed mmap() very likely causes application failure,
19039 + * so fall back to the bottom-up function here. This scenario
19040 + * can happen with large stack limits and large mmap()
19041 + * allocations.
19042 + */
19043 +
19044 +#ifdef CONFIG_PAX_SEGMEXEC
19045 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19046 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19047 + else
19048 +#endif
19049 +
19050 + mm->mmap_base = TASK_UNMAPPED_BASE;
19051 +
19052 +#ifdef CONFIG_PAX_RANDMMAP
19053 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19054 + mm->mmap_base += mm->delta_mmap;
19055 +#endif
19056 +
19057 + mm->free_area_cache = mm->mmap_base;
19058 + mm->cached_hole_size = ~0UL;
19059 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19060 + /*
19061 + * Restore the topdown base:
19062 + */
19063 + mm->mmap_base = base;
19064 + mm->free_area_cache = base;
19065 + mm->cached_hole_size = ~0UL;
19066 +
19067 + return addr;
19068 }
19069 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19070 index 0514890..3dbebce 100644
19071 --- a/arch/x86/kernel/sys_x86_64.c
19072 +++ b/arch/x86/kernel/sys_x86_64.c
19073 @@ -95,8 +95,8 @@ out:
19074 return error;
19075 }
19076
19077 -static void find_start_end(unsigned long flags, unsigned long *begin,
19078 - unsigned long *end)
19079 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19080 + unsigned long *begin, unsigned long *end)
19081 {
19082 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
19083 unsigned long new_begin;
19084 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19085 *begin = new_begin;
19086 }
19087 } else {
19088 - *begin = TASK_UNMAPPED_BASE;
19089 + *begin = mm->mmap_base;
19090 *end = TASK_SIZE;
19091 }
19092 }
19093 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19094 if (flags & MAP_FIXED)
19095 return addr;
19096
19097 - find_start_end(flags, &begin, &end);
19098 + find_start_end(mm, flags, &begin, &end);
19099
19100 if (len > end)
19101 return -ENOMEM;
19102
19103 +#ifdef CONFIG_PAX_RANDMMAP
19104 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19105 +#endif
19106 +
19107 if (addr) {
19108 addr = PAGE_ALIGN(addr);
19109 vma = find_vma(mm, addr);
19110 - if (end - len >= addr &&
19111 - (!vma || addr + len <= vma->vm_start))
19112 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19113 return addr;
19114 }
19115 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
19116 @@ -172,7 +175,7 @@ full_search:
19117 }
19118 return -ENOMEM;
19119 }
19120 - if (!vma || addr + len <= vma->vm_start) {
19121 + if (check_heap_stack_gap(vma, addr, len)) {
19122 /*
19123 * Remember the place where we stopped the search:
19124 */
19125 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19126 {
19127 struct vm_area_struct *vma;
19128 struct mm_struct *mm = current->mm;
19129 - unsigned long addr = addr0;
19130 + unsigned long base = mm->mmap_base, addr = addr0;
19131
19132 /* requested length too big for entire address space */
19133 if (len > TASK_SIZE)
19134 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19135 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
19136 goto bottomup;
19137
19138 +#ifdef CONFIG_PAX_RANDMMAP
19139 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19140 +#endif
19141 +
19142 /* requesting a specific address */
19143 if (addr) {
19144 addr = PAGE_ALIGN(addr);
19145 - vma = find_vma(mm, addr);
19146 - if (TASK_SIZE - len >= addr &&
19147 - (!vma || addr + len <= vma->vm_start))
19148 - return addr;
19149 + if (TASK_SIZE - len >= addr) {
19150 + vma = find_vma(mm, addr);
19151 + if (check_heap_stack_gap(vma, addr, len))
19152 + return addr;
19153 + }
19154 }
19155
19156 /* check if free_area_cache is useful for us */
19157 @@ -232,7 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19158 ALIGN_TOPDOWN);
19159
19160 vma = find_vma(mm, tmp_addr);
19161 - if (!vma || tmp_addr + len <= vma->vm_start)
19162 + if (check_heap_stack_gap(vma, tmp_addr, len))
19163 /* remember the address as a hint for next time */
19164 return mm->free_area_cache = tmp_addr;
19165 }
19166 @@ -251,7 +259,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19167 * return with success:
19168 */
19169 vma = find_vma(mm, addr);
19170 - if (!vma || addr+len <= vma->vm_start)
19171 + if (check_heap_stack_gap(vma, addr, len))
19172 /* remember the address as a hint for next time */
19173 return mm->free_area_cache = addr;
19174
19175 @@ -260,8 +268,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19176 mm->cached_hole_size = vma->vm_start - addr;
19177
19178 /* try just below the current vma->vm_start */
19179 - addr = vma->vm_start-len;
19180 - } while (len < vma->vm_start);
19181 + addr = skip_heap_stack_gap(vma, len);
19182 + } while (!IS_ERR_VALUE(addr));
19183
19184 bottomup:
19185 /*
19186 @@ -270,13 +278,21 @@ bottomup:
19187 * can happen with large stack limits and large mmap()
19188 * allocations.
19189 */
19190 + mm->mmap_base = TASK_UNMAPPED_BASE;
19191 +
19192 +#ifdef CONFIG_PAX_RANDMMAP
19193 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19194 + mm->mmap_base += mm->delta_mmap;
19195 +#endif
19196 +
19197 + mm->free_area_cache = mm->mmap_base;
19198 mm->cached_hole_size = ~0UL;
19199 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19200 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19201 /*
19202 * Restore the topdown base:
19203 */
19204 - mm->free_area_cache = mm->mmap_base;
19205 + mm->mmap_base = base;
19206 + mm->free_area_cache = base;
19207 mm->cached_hole_size = ~0UL;
19208
19209 return addr;
19210 diff --git a/arch/x86/kernel/syscall_table_32.S b/arch/x86/kernel/syscall_table_32.S
19211 index 9a0e312..e6f66f2 100644
19212 --- a/arch/x86/kernel/syscall_table_32.S
19213 +++ b/arch/x86/kernel/syscall_table_32.S
19214 @@ -1,3 +1,4 @@
19215 +.section .rodata,"a",@progbits
19216 ENTRY(sys_call_table)
19217 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
19218 .long sys_exit
19219 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19220 index e2410e2..4fe3fbc 100644
19221 --- a/arch/x86/kernel/tboot.c
19222 +++ b/arch/x86/kernel/tboot.c
19223 @@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
19224
19225 void tboot_shutdown(u32 shutdown_type)
19226 {
19227 - void (*shutdown)(void);
19228 + void (* __noreturn shutdown)(void);
19229
19230 if (!tboot_enabled())
19231 return;
19232 @@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
19233
19234 switch_to_tboot_pt();
19235
19236 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19237 + shutdown = (void *)tboot->shutdown_entry;
19238 shutdown();
19239
19240 /* should not reach here */
19241 @@ -298,7 +298,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19242 tboot_shutdown(acpi_shutdown_map[sleep_state]);
19243 }
19244
19245 -static atomic_t ap_wfs_count;
19246 +static atomic_unchecked_t ap_wfs_count;
19247
19248 static int tboot_wait_for_aps(int num_aps)
19249 {
19250 @@ -322,9 +322,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19251 {
19252 switch (action) {
19253 case CPU_DYING:
19254 - atomic_inc(&ap_wfs_count);
19255 + atomic_inc_unchecked(&ap_wfs_count);
19256 if (num_online_cpus() == 1)
19257 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19258 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19259 return NOTIFY_BAD;
19260 break;
19261 }
19262 @@ -343,7 +343,7 @@ static __init int tboot_late_init(void)
19263
19264 tboot_create_trampoline();
19265
19266 - atomic_set(&ap_wfs_count, 0);
19267 + atomic_set_unchecked(&ap_wfs_count, 0);
19268 register_hotcpu_notifier(&tboot_cpu_notifier);
19269 return 0;
19270 }
19271 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19272 index dd5fbf4..b7f2232 100644
19273 --- a/arch/x86/kernel/time.c
19274 +++ b/arch/x86/kernel/time.c
19275 @@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19276 {
19277 unsigned long pc = instruction_pointer(regs);
19278
19279 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19280 + if (!user_mode(regs) && in_lock_functions(pc)) {
19281 #ifdef CONFIG_FRAME_POINTER
19282 - return *(unsigned long *)(regs->bp + sizeof(long));
19283 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19284 #else
19285 unsigned long *sp =
19286 (unsigned long *)kernel_stack_pointer(regs);
19287 @@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19288 * or above a saved flags. Eflags has bits 22-31 zero,
19289 * kernel addresses don't.
19290 */
19291 +
19292 +#ifdef CONFIG_PAX_KERNEXEC
19293 + return ktla_ktva(sp[0]);
19294 +#else
19295 if (sp[0] >> 22)
19296 return sp[0];
19297 if (sp[1] >> 22)
19298 return sp[1];
19299 #endif
19300 +
19301 +#endif
19302 }
19303 return pc;
19304 }
19305 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19306 index 6bb7b85..dd853e1 100644
19307 --- a/arch/x86/kernel/tls.c
19308 +++ b/arch/x86/kernel/tls.c
19309 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19310 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19311 return -EINVAL;
19312
19313 +#ifdef CONFIG_PAX_SEGMEXEC
19314 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19315 + return -EINVAL;
19316 +#endif
19317 +
19318 set_tls_desc(p, idx, &info, 1);
19319
19320 return 0;
19321 diff --git a/arch/x86/kernel/tls.h b/arch/x86/kernel/tls.h
19322 index 2f083a2..7d3fecc 100644
19323 --- a/arch/x86/kernel/tls.h
19324 +++ b/arch/x86/kernel/tls.h
19325 @@ -16,6 +16,6 @@
19326
19327 extern user_regset_active_fn regset_tls_active;
19328 extern user_regset_get_fn regset_tls_get;
19329 -extern user_regset_set_fn regset_tls_set;
19330 +extern user_regset_set_fn regset_tls_set __size_overflow(4);
19331
19332 #endif /* _ARCH_X86_KERNEL_TLS_H */
19333 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19334 index 451c0a7..e57f551 100644
19335 --- a/arch/x86/kernel/trampoline_32.S
19336 +++ b/arch/x86/kernel/trampoline_32.S
19337 @@ -32,6 +32,12 @@
19338 #include <asm/segment.h>
19339 #include <asm/page_types.h>
19340
19341 +#ifdef CONFIG_PAX_KERNEXEC
19342 +#define ta(X) (X)
19343 +#else
19344 +#define ta(X) ((X) - __PAGE_OFFSET)
19345 +#endif
19346 +
19347 #ifdef CONFIG_SMP
19348
19349 .section ".x86_trampoline","a"
19350 @@ -62,7 +68,7 @@ r_base = .
19351 inc %ax # protected mode (PE) bit
19352 lmsw %ax # into protected mode
19353 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19354 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19355 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
19356
19357 # These need to be in the same 64K segment as the above;
19358 # hence we don't use the boot_gdt_descr defined in head.S
19359 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19360 index 09ff517..df19fbff 100644
19361 --- a/arch/x86/kernel/trampoline_64.S
19362 +++ b/arch/x86/kernel/trampoline_64.S
19363 @@ -90,7 +90,7 @@ startup_32:
19364 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19365 movl %eax, %ds
19366
19367 - movl $X86_CR4_PAE, %eax
19368 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19369 movl %eax, %cr4 # Enable PAE mode
19370
19371 # Setup trampoline 4 level pagetables
19372 @@ -138,7 +138,7 @@ tidt:
19373 # so the kernel can live anywhere
19374 .balign 4
19375 tgdt:
19376 - .short tgdt_end - tgdt # gdt limit
19377 + .short tgdt_end - tgdt - 1 # gdt limit
19378 .long tgdt - r_base
19379 .short 0
19380 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19381 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19382 index 31d9d0f..e244dd9 100644
19383 --- a/arch/x86/kernel/traps.c
19384 +++ b/arch/x86/kernel/traps.c
19385 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19386
19387 /* Do we ignore FPU interrupts ? */
19388 char ignore_fpu_irq;
19389 -
19390 -/*
19391 - * The IDT has to be page-aligned to simplify the Pentium
19392 - * F0 0F bug workaround.
19393 - */
19394 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19395 #endif
19396
19397 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19398 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19399 }
19400
19401 static void __kprobes
19402 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19403 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19404 long error_code, siginfo_t *info)
19405 {
19406 struct task_struct *tsk = current;
19407
19408 #ifdef CONFIG_X86_32
19409 - if (regs->flags & X86_VM_MASK) {
19410 + if (v8086_mode(regs)) {
19411 /*
19412 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19413 * On nmi (interrupt 2), do_trap should not be called.
19414 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19415 }
19416 #endif
19417
19418 - if (!user_mode(regs))
19419 + if (!user_mode_novm(regs))
19420 goto kernel_trap;
19421
19422 #ifdef CONFIG_X86_32
19423 @@ -148,7 +142,7 @@ trap_signal:
19424 printk_ratelimit()) {
19425 printk(KERN_INFO
19426 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19427 - tsk->comm, tsk->pid, str,
19428 + tsk->comm, task_pid_nr(tsk), str,
19429 regs->ip, regs->sp, error_code);
19430 print_vma_addr(" in ", regs->ip);
19431 printk("\n");
19432 @@ -165,8 +159,20 @@ kernel_trap:
19433 if (!fixup_exception(regs)) {
19434 tsk->thread.error_code = error_code;
19435 tsk->thread.trap_no = trapnr;
19436 +
19437 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19438 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19439 + str = "PAX: suspicious stack segment fault";
19440 +#endif
19441 +
19442 die(str, regs, error_code);
19443 }
19444 +
19445 +#ifdef CONFIG_PAX_REFCOUNT
19446 + if (trapnr == 4)
19447 + pax_report_refcount_overflow(regs);
19448 +#endif
19449 +
19450 return;
19451
19452 #ifdef CONFIG_X86_32
19453 @@ -255,14 +261,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19454 conditional_sti(regs);
19455
19456 #ifdef CONFIG_X86_32
19457 - if (regs->flags & X86_VM_MASK)
19458 + if (v8086_mode(regs))
19459 goto gp_in_vm86;
19460 #endif
19461
19462 tsk = current;
19463 - if (!user_mode(regs))
19464 + if (!user_mode_novm(regs))
19465 goto gp_in_kernel;
19466
19467 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19468 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19469 + struct mm_struct *mm = tsk->mm;
19470 + unsigned long limit;
19471 +
19472 + down_write(&mm->mmap_sem);
19473 + limit = mm->context.user_cs_limit;
19474 + if (limit < TASK_SIZE) {
19475 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19476 + up_write(&mm->mmap_sem);
19477 + return;
19478 + }
19479 + up_write(&mm->mmap_sem);
19480 + }
19481 +#endif
19482 +
19483 tsk->thread.error_code = error_code;
19484 tsk->thread.trap_no = 13;
19485
19486 @@ -295,6 +317,13 @@ gp_in_kernel:
19487 if (notify_die(DIE_GPF, "general protection fault", regs,
19488 error_code, 13, SIGSEGV) == NOTIFY_STOP)
19489 return;
19490 +
19491 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19492 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19493 + die("PAX: suspicious general protection fault", regs, error_code);
19494 + else
19495 +#endif
19496 +
19497 die("general protection fault", regs, error_code);
19498 }
19499
19500 @@ -414,7 +443,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19501 /* It's safe to allow irq's after DR6 has been saved */
19502 preempt_conditional_sti(regs);
19503
19504 - if (regs->flags & X86_VM_MASK) {
19505 + if (v8086_mode(regs)) {
19506 handle_vm86_trap((struct kernel_vm86_regs *) regs,
19507 error_code, 1);
19508 preempt_conditional_cli(regs);
19509 @@ -428,7 +457,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19510 * We already checked v86 mode above, so we can check for kernel mode
19511 * by just checking the CPL of CS.
19512 */
19513 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19514 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19515 tsk->thread.debugreg6 &= ~DR_STEP;
19516 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19517 regs->flags &= ~X86_EFLAGS_TF;
19518 @@ -457,7 +486,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19519 return;
19520 conditional_sti(regs);
19521
19522 - if (!user_mode_vm(regs))
19523 + if (!user_mode(regs))
19524 {
19525 if (!fixup_exception(regs)) {
19526 task->thread.error_code = error_code;
19527 @@ -569,8 +598,8 @@ asmlinkage void __attribute__((weak)) smp_threshold_interrupt(void)
19528 void __math_state_restore(struct task_struct *tsk)
19529 {
19530 /* We need a safe address that is cheap to find and that is already
19531 - in L1. We've just brought in "tsk->thread.has_fpu", so use that */
19532 -#define safe_address (tsk->thread.has_fpu)
19533 + in L1. */
19534 +#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
19535
19536 /* AMD K7/K8 CPUs don't save/restore FDP/FIP/FOP unless an exception
19537 is pending. Clear the x87 state here by setting it to fixed
19538 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19539 index b9242ba..50c5edd 100644
19540 --- a/arch/x86/kernel/verify_cpu.S
19541 +++ b/arch/x86/kernel/verify_cpu.S
19542 @@ -20,6 +20,7 @@
19543 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19544 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19545 * arch/x86/kernel/head_32.S: processor startup
19546 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19547 *
19548 * verify_cpu, returns the status of longmode and SSE in register %eax.
19549 * 0: Success 1: Failure
19550 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19551 index 863f875..4307295 100644
19552 --- a/arch/x86/kernel/vm86_32.c
19553 +++ b/arch/x86/kernel/vm86_32.c
19554 @@ -41,6 +41,7 @@
19555 #include <linux/ptrace.h>
19556 #include <linux/audit.h>
19557 #include <linux/stddef.h>
19558 +#include <linux/grsecurity.h>
19559
19560 #include <asm/uaccess.h>
19561 #include <asm/io.h>
19562 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19563 do_exit(SIGSEGV);
19564 }
19565
19566 - tss = &per_cpu(init_tss, get_cpu());
19567 + tss = init_tss + get_cpu();
19568 current->thread.sp0 = current->thread.saved_sp0;
19569 current->thread.sysenter_cs = __KERNEL_CS;
19570 load_sp0(tss, &current->thread);
19571 @@ -208,6 +209,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19572 struct task_struct *tsk;
19573 int tmp, ret = -EPERM;
19574
19575 +#ifdef CONFIG_GRKERNSEC_VM86
19576 + if (!capable(CAP_SYS_RAWIO)) {
19577 + gr_handle_vm86();
19578 + goto out;
19579 + }
19580 +#endif
19581 +
19582 tsk = current;
19583 if (tsk->thread.saved_sp0)
19584 goto out;
19585 @@ -238,6 +246,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19586 int tmp, ret;
19587 struct vm86plus_struct __user *v86;
19588
19589 +#ifdef CONFIG_GRKERNSEC_VM86
19590 + if (!capable(CAP_SYS_RAWIO)) {
19591 + gr_handle_vm86();
19592 + ret = -EPERM;
19593 + goto out;
19594 + }
19595 +#endif
19596 +
19597 tsk = current;
19598 switch (cmd) {
19599 case VM86_REQUEST_IRQ:
19600 @@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19601 tsk->thread.saved_fs = info->regs32->fs;
19602 tsk->thread.saved_gs = get_user_gs(info->regs32);
19603
19604 - tss = &per_cpu(init_tss, get_cpu());
19605 + tss = init_tss + get_cpu();
19606 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19607 if (cpu_has_sep)
19608 tsk->thread.sysenter_cs = 0;
19609 @@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19610 goto cannot_handle;
19611 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19612 goto cannot_handle;
19613 - intr_ptr = (unsigned long __user *) (i << 2);
19614 + intr_ptr = (__force unsigned long __user *) (i << 2);
19615 if (get_user(segoffs, intr_ptr))
19616 goto cannot_handle;
19617 if ((segoffs >> 16) == BIOSSEG)
19618 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19619 index 0f703f1..9e15f64 100644
19620 --- a/arch/x86/kernel/vmlinux.lds.S
19621 +++ b/arch/x86/kernel/vmlinux.lds.S
19622 @@ -26,6 +26,13 @@
19623 #include <asm/page_types.h>
19624 #include <asm/cache.h>
19625 #include <asm/boot.h>
19626 +#include <asm/segment.h>
19627 +
19628 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19629 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19630 +#else
19631 +#define __KERNEL_TEXT_OFFSET 0
19632 +#endif
19633
19634 #undef i386 /* in case the preprocessor is a 32bit one */
19635
19636 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19637
19638 PHDRS {
19639 text PT_LOAD FLAGS(5); /* R_E */
19640 +#ifdef CONFIG_X86_32
19641 + module PT_LOAD FLAGS(5); /* R_E */
19642 +#endif
19643 +#ifdef CONFIG_XEN
19644 + rodata PT_LOAD FLAGS(5); /* R_E */
19645 +#else
19646 + rodata PT_LOAD FLAGS(4); /* R__ */
19647 +#endif
19648 data PT_LOAD FLAGS(6); /* RW_ */
19649 -#ifdef CONFIG_X86_64
19650 + init.begin PT_LOAD FLAGS(6); /* RW_ */
19651 #ifdef CONFIG_SMP
19652 percpu PT_LOAD FLAGS(6); /* RW_ */
19653 #endif
19654 + text.init PT_LOAD FLAGS(5); /* R_E */
19655 + text.exit PT_LOAD FLAGS(5); /* R_E */
19656 init PT_LOAD FLAGS(7); /* RWE */
19657 -#endif
19658 note PT_NOTE FLAGS(0); /* ___ */
19659 }
19660
19661 SECTIONS
19662 {
19663 #ifdef CONFIG_X86_32
19664 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19665 - phys_startup_32 = startup_32 - LOAD_OFFSET;
19666 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19667 #else
19668 - . = __START_KERNEL;
19669 - phys_startup_64 = startup_64 - LOAD_OFFSET;
19670 + . = __START_KERNEL;
19671 #endif
19672
19673 /* Text and read-only data */
19674 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
19675 - _text = .;
19676 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19677 /* bootstrapping code */
19678 +#ifdef CONFIG_X86_32
19679 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19680 +#else
19681 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19682 +#endif
19683 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19684 + _text = .;
19685 HEAD_TEXT
19686 #ifdef CONFIG_X86_32
19687 . = ALIGN(PAGE_SIZE);
19688 @@ -108,13 +128,47 @@ SECTIONS
19689 IRQENTRY_TEXT
19690 *(.fixup)
19691 *(.gnu.warning)
19692 - /* End of text section */
19693 - _etext = .;
19694 } :text = 0x9090
19695
19696 - NOTES :text :note
19697 + . += __KERNEL_TEXT_OFFSET;
19698
19699 - EXCEPTION_TABLE(16) :text = 0x9090
19700 +#ifdef CONFIG_X86_32
19701 + . = ALIGN(PAGE_SIZE);
19702 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19703 +
19704 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19705 + MODULES_EXEC_VADDR = .;
19706 + BYTE(0)
19707 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19708 + . = ALIGN(HPAGE_SIZE);
19709 + MODULES_EXEC_END = . - 1;
19710 +#endif
19711 +
19712 + } :module
19713 +#endif
19714 +
19715 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19716 + /* End of text section */
19717 + _etext = . - __KERNEL_TEXT_OFFSET;
19718 + }
19719 +
19720 +#ifdef CONFIG_X86_32
19721 + . = ALIGN(PAGE_SIZE);
19722 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
19723 + *(.idt)
19724 + . = ALIGN(PAGE_SIZE);
19725 + *(.empty_zero_page)
19726 + *(.initial_pg_fixmap)
19727 + *(.initial_pg_pmd)
19728 + *(.initial_page_table)
19729 + *(.swapper_pg_dir)
19730 + } :rodata
19731 +#endif
19732 +
19733 + . = ALIGN(PAGE_SIZE);
19734 + NOTES :rodata :note
19735 +
19736 + EXCEPTION_TABLE(16) :rodata
19737
19738 #if defined(CONFIG_DEBUG_RODATA)
19739 /* .text should occupy whole number of pages */
19740 @@ -126,16 +180,20 @@ SECTIONS
19741
19742 /* Data */
19743 .data : AT(ADDR(.data) - LOAD_OFFSET) {
19744 +
19745 +#ifdef CONFIG_PAX_KERNEXEC
19746 + . = ALIGN(HPAGE_SIZE);
19747 +#else
19748 + . = ALIGN(PAGE_SIZE);
19749 +#endif
19750 +
19751 /* Start of data section */
19752 _sdata = .;
19753
19754 /* init_task */
19755 INIT_TASK_DATA(THREAD_SIZE)
19756
19757 -#ifdef CONFIG_X86_32
19758 - /* 32 bit has nosave before _edata */
19759 NOSAVE_DATA
19760 -#endif
19761
19762 PAGE_ALIGNED_DATA(PAGE_SIZE)
19763
19764 @@ -176,12 +234,19 @@ SECTIONS
19765 #endif /* CONFIG_X86_64 */
19766
19767 /* Init code and data - will be freed after init */
19768 - . = ALIGN(PAGE_SIZE);
19769 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
19770 + BYTE(0)
19771 +
19772 +#ifdef CONFIG_PAX_KERNEXEC
19773 + . = ALIGN(HPAGE_SIZE);
19774 +#else
19775 + . = ALIGN(PAGE_SIZE);
19776 +#endif
19777 +
19778 __init_begin = .; /* paired with __init_end */
19779 - }
19780 + } :init.begin
19781
19782 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
19783 +#ifdef CONFIG_SMP
19784 /*
19785 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
19786 * output PHDR, so the next output section - .init.text - should
19787 @@ -190,12 +255,27 @@ SECTIONS
19788 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
19789 #endif
19790
19791 - INIT_TEXT_SECTION(PAGE_SIZE)
19792 -#ifdef CONFIG_X86_64
19793 - :init
19794 -#endif
19795 + . = ALIGN(PAGE_SIZE);
19796 + init_begin = .;
19797 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
19798 + VMLINUX_SYMBOL(_sinittext) = .;
19799 + INIT_TEXT
19800 + VMLINUX_SYMBOL(_einittext) = .;
19801 + . = ALIGN(PAGE_SIZE);
19802 + } :text.init
19803
19804 - INIT_DATA_SECTION(16)
19805 + /*
19806 + * .exit.text is discard at runtime, not link time, to deal with
19807 + * references from .altinstructions and .eh_frame
19808 + */
19809 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19810 + EXIT_TEXT
19811 + . = ALIGN(16);
19812 + } :text.exit
19813 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
19814 +
19815 + . = ALIGN(PAGE_SIZE);
19816 + INIT_DATA_SECTION(16) :init
19817
19818 /*
19819 * Code and data for a variety of lowlevel trampolines, to be
19820 @@ -269,19 +349,12 @@ SECTIONS
19821 }
19822
19823 . = ALIGN(8);
19824 - /*
19825 - * .exit.text is discard at runtime, not link time, to deal with
19826 - * references from .altinstructions and .eh_frame
19827 - */
19828 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
19829 - EXIT_TEXT
19830 - }
19831
19832 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
19833 EXIT_DATA
19834 }
19835
19836 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
19837 +#ifndef CONFIG_SMP
19838 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
19839 #endif
19840
19841 @@ -300,16 +373,10 @@ SECTIONS
19842 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
19843 __smp_locks = .;
19844 *(.smp_locks)
19845 - . = ALIGN(PAGE_SIZE);
19846 __smp_locks_end = .;
19847 + . = ALIGN(PAGE_SIZE);
19848 }
19849
19850 -#ifdef CONFIG_X86_64
19851 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
19852 - NOSAVE_DATA
19853 - }
19854 -#endif
19855 -
19856 /* BSS */
19857 . = ALIGN(PAGE_SIZE);
19858 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
19859 @@ -325,6 +392,7 @@ SECTIONS
19860 __brk_base = .;
19861 . += 64 * 1024; /* 64k alignment slop space */
19862 *(.brk_reservation) /* areas brk users have reserved */
19863 + . = ALIGN(HPAGE_SIZE);
19864 __brk_limit = .;
19865 }
19866
19867 @@ -351,13 +419,12 @@ SECTIONS
19868 * for the boot processor.
19869 */
19870 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
19871 -INIT_PER_CPU(gdt_page);
19872 INIT_PER_CPU(irq_stack_union);
19873
19874 /*
19875 * Build-time check on the image size:
19876 */
19877 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
19878 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
19879 "kernel image bigger than KERNEL_IMAGE_SIZE");
19880
19881 #ifdef CONFIG_SMP
19882 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
19883 index e4d4a22..47ee71f 100644
19884 --- a/arch/x86/kernel/vsyscall_64.c
19885 +++ b/arch/x86/kernel/vsyscall_64.c
19886 @@ -57,15 +57,13 @@ DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
19887 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
19888 };
19889
19890 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = NATIVE;
19891 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
19892
19893 static int __init vsyscall_setup(char *str)
19894 {
19895 if (str) {
19896 if (!strcmp("emulate", str))
19897 vsyscall_mode = EMULATE;
19898 - else if (!strcmp("native", str))
19899 - vsyscall_mode = NATIVE;
19900 else if (!strcmp("none", str))
19901 vsyscall_mode = NONE;
19902 else
19903 @@ -178,7 +176,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
19904
19905 tsk = current;
19906 if (seccomp_mode(&tsk->seccomp))
19907 - do_exit(SIGKILL);
19908 + do_group_exit(SIGKILL);
19909
19910 switch (vsyscall_nr) {
19911 case 0:
19912 @@ -220,8 +218,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
19913 return true;
19914
19915 sigsegv:
19916 - force_sig(SIGSEGV, current);
19917 - return true;
19918 + do_group_exit(SIGKILL);
19919 }
19920
19921 /*
19922 @@ -274,10 +271,7 @@ void __init map_vsyscall(void)
19923 extern char __vvar_page;
19924 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
19925
19926 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
19927 - vsyscall_mode == NATIVE
19928 - ? PAGE_KERNEL_VSYSCALL
19929 - : PAGE_KERNEL_VVAR);
19930 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
19931 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
19932 (unsigned long)VSYSCALL_START);
19933
19934 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
19935 index 9796c2f..f686fbf 100644
19936 --- a/arch/x86/kernel/x8664_ksyms_64.c
19937 +++ b/arch/x86/kernel/x8664_ksyms_64.c
19938 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
19939 EXPORT_SYMBOL(copy_user_generic_string);
19940 EXPORT_SYMBOL(copy_user_generic_unrolled);
19941 EXPORT_SYMBOL(__copy_user_nocache);
19942 -EXPORT_SYMBOL(_copy_from_user);
19943 -EXPORT_SYMBOL(_copy_to_user);
19944
19945 EXPORT_SYMBOL(copy_page);
19946 EXPORT_SYMBOL(clear_page);
19947 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
19948 index 7110911..e8cdee5 100644
19949 --- a/arch/x86/kernel/xsave.c
19950 +++ b/arch/x86/kernel/xsave.c
19951 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
19952 fx_sw_user->xstate_size > fx_sw_user->extended_size)
19953 return -EINVAL;
19954
19955 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
19956 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
19957 fx_sw_user->extended_size -
19958 FP_XSTATE_MAGIC2_SIZE));
19959 if (err)
19960 @@ -266,7 +266,7 @@ fx_only:
19961 * the other extended state.
19962 */
19963 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
19964 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
19965 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
19966 }
19967
19968 /*
19969 @@ -295,7 +295,7 @@ int restore_i387_xstate(void __user *buf)
19970 if (use_xsave())
19971 err = restore_user_xstate(buf);
19972 else
19973 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
19974 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
19975 buf);
19976 if (unlikely(err)) {
19977 /*
19978 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
19979 index f1e3be18..588efc8 100644
19980 --- a/arch/x86/kvm/emulate.c
19981 +++ b/arch/x86/kvm/emulate.c
19982 @@ -249,6 +249,7 @@ struct gprefix {
19983
19984 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
19985 do { \
19986 + unsigned long _tmp; \
19987 __asm__ __volatile__ ( \
19988 _PRE_EFLAGS("0", "4", "2") \
19989 _op _suffix " %"_x"3,%1; " \
19990 @@ -263,8 +264,6 @@ struct gprefix {
19991 /* Raw emulation: instruction has two explicit operands. */
19992 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
19993 do { \
19994 - unsigned long _tmp; \
19995 - \
19996 switch ((ctxt)->dst.bytes) { \
19997 case 2: \
19998 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
19999 @@ -280,7 +279,6 @@ struct gprefix {
20000
20001 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20002 do { \
20003 - unsigned long _tmp; \
20004 switch ((ctxt)->dst.bytes) { \
20005 case 1: \
20006 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20007 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20008 index 54abb40..a192606 100644
20009 --- a/arch/x86/kvm/lapic.c
20010 +++ b/arch/x86/kvm/lapic.c
20011 @@ -53,7 +53,7 @@
20012 #define APIC_BUS_CYCLE_NS 1
20013
20014 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20015 -#define apic_debug(fmt, arg...)
20016 +#define apic_debug(fmt, arg...) do {} while (0)
20017
20018 #define APIC_LVT_NUM 6
20019 /* 14 is the version for Xeon and Pentium 8.4.8*/
20020 diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
20021 index f1b36cf..af8a124 100644
20022 --- a/arch/x86/kvm/mmu.c
20023 +++ b/arch/x86/kvm/mmu.c
20024 @@ -3555,7 +3555,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
20025
20026 pgprintk("%s: gpa %llx bytes %d\n", __func__, gpa, bytes);
20027
20028 - invlpg_counter = atomic_read(&vcpu->kvm->arch.invlpg_counter);
20029 + invlpg_counter = atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter);
20030
20031 /*
20032 * Assume that the pte write on a page table of the same type
20033 @@ -3587,7 +3587,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
20034 }
20035
20036 spin_lock(&vcpu->kvm->mmu_lock);
20037 - if (atomic_read(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
20038 + if (atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
20039 gentry = 0;
20040 kvm_mmu_free_some_pages(vcpu);
20041 ++vcpu->kvm->stat.mmu_pte_write;
20042 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20043 index 9299410..ade2f9b 100644
20044 --- a/arch/x86/kvm/paging_tmpl.h
20045 +++ b/arch/x86/kvm/paging_tmpl.h
20046 @@ -197,7 +197,7 @@ retry_walk:
20047 if (unlikely(kvm_is_error_hva(host_addr)))
20048 goto error;
20049
20050 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20051 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20052 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20053 goto error;
20054
20055 @@ -705,7 +705,7 @@ static void FNAME(invlpg)(struct kvm_vcpu *vcpu, gva_t gva)
20056 if (need_flush)
20057 kvm_flush_remote_tlbs(vcpu->kvm);
20058
20059 - atomic_inc(&vcpu->kvm->arch.invlpg_counter);
20060 + atomic_inc_unchecked(&vcpu->kvm->arch.invlpg_counter);
20061
20062 spin_unlock(&vcpu->kvm->mmu_lock);
20063
20064 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20065 index 94a4672..1700ed1 100644
20066 --- a/arch/x86/kvm/svm.c
20067 +++ b/arch/x86/kvm/svm.c
20068 @@ -3037,6 +3037,7 @@ static int svm_set_vm_cr(struct kvm_vcpu *vcpu, u64 data)
20069 return 0;
20070 }
20071
20072 +static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data) __size_overflow(3);
20073 static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)
20074 {
20075 struct vcpu_svm *svm = to_svm(vcpu);
20076 @@ -3405,7 +3406,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20077 int cpu = raw_smp_processor_id();
20078
20079 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20080 +
20081 + pax_open_kernel();
20082 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20083 + pax_close_kernel();
20084 +
20085 load_TR_desc();
20086 }
20087
20088 @@ -3783,6 +3788,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20089 #endif
20090 #endif
20091
20092 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20093 + __set_fs(current_thread_info()->addr_limit);
20094 +#endif
20095 +
20096 reload_tss(vcpu);
20097
20098 local_irq_disable();
20099 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20100 index 4ea7678..c715f2f 100644
20101 --- a/arch/x86/kvm/vmx.c
20102 +++ b/arch/x86/kvm/vmx.c
20103 @@ -1305,7 +1305,11 @@ static void reload_tss(void)
20104 struct desc_struct *descs;
20105
20106 descs = (void *)gdt->address;
20107 +
20108 + pax_open_kernel();
20109 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20110 + pax_close_kernel();
20111 +
20112 load_TR_desc();
20113 }
20114
20115 @@ -2163,6 +2167,7 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata)
20116 * Returns 0 on success, non-0 otherwise.
20117 * Assumes vcpu_load() was already called.
20118 */
20119 +static int vmx_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data) __size_overflow(3);
20120 static int vmx_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data)
20121 {
20122 struct vcpu_vmx *vmx = to_vmx(vcpu);
20123 @@ -2633,8 +2638,11 @@ static __init int hardware_setup(void)
20124 if (!cpu_has_vmx_flexpriority())
20125 flexpriority_enabled = 0;
20126
20127 - if (!cpu_has_vmx_tpr_shadow())
20128 - kvm_x86_ops->update_cr8_intercept = NULL;
20129 + if (!cpu_has_vmx_tpr_shadow()) {
20130 + pax_open_kernel();
20131 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20132 + pax_close_kernel();
20133 + }
20134
20135 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20136 kvm_disable_largepages();
20137 @@ -3648,7 +3656,7 @@ static void vmx_set_constant_host_state(void)
20138 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20139
20140 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20141 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20142 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20143
20144 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20145 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20146 @@ -6169,6 +6177,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20147 "jmp .Lkvm_vmx_return \n\t"
20148 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20149 ".Lkvm_vmx_return: "
20150 +
20151 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20152 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20153 + ".Lkvm_vmx_return2: "
20154 +#endif
20155 +
20156 /* Save guest registers, load host registers, keep flags */
20157 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20158 "pop %0 \n\t"
20159 @@ -6217,6 +6231,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20160 #endif
20161 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20162 [wordsize]"i"(sizeof(ulong))
20163 +
20164 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20165 + ,[cs]"i"(__KERNEL_CS)
20166 +#endif
20167 +
20168 : "cc", "memory"
20169 , R"ax", R"bx", R"di", R"si"
20170 #ifdef CONFIG_X86_64
20171 @@ -6245,7 +6264,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20172 }
20173 }
20174
20175 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
20176 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20177 +
20178 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20179 + loadsegment(fs, __KERNEL_PERCPU);
20180 +#endif
20181 +
20182 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20183 + __set_fs(current_thread_info()->addr_limit);
20184 +#endif
20185 +
20186 vmx->loaded_vmcs->launched = 1;
20187
20188 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20189 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20190 index 4c938da..6cd8090 100644
20191 --- a/arch/x86/kvm/x86.c
20192 +++ b/arch/x86/kvm/x86.c
20193 @@ -907,6 +907,7 @@ static int do_set_msr(struct kvm_vcpu *vcpu, unsigned index, u64 *data)
20194 return kvm_set_msr(vcpu, index, *data);
20195 }
20196
20197 +static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock) __size_overflow(2);
20198 static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock)
20199 {
20200 int version;
20201 @@ -1345,8 +1346,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20202 {
20203 struct kvm *kvm = vcpu->kvm;
20204 int lm = is_long_mode(vcpu);
20205 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20206 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20207 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20208 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20209 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20210 : kvm->arch.xen_hvm_config.blob_size_32;
20211 u32 page_num = data & ~PAGE_MASK;
20212 @@ -2165,6 +2166,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20213 if (n < msr_list.nmsrs)
20214 goto out;
20215 r = -EFAULT;
20216 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20217 + goto out;
20218 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20219 num_msrs_to_save * sizeof(u32)))
20220 goto out;
20221 @@ -2340,15 +2343,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20222 struct kvm_cpuid2 *cpuid,
20223 struct kvm_cpuid_entry2 __user *entries)
20224 {
20225 - int r;
20226 + int r, i;
20227
20228 r = -E2BIG;
20229 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20230 goto out;
20231 r = -EFAULT;
20232 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20233 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20234 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20235 goto out;
20236 + for (i = 0; i < cpuid->nent; ++i) {
20237 + struct kvm_cpuid_entry2 cpuid_entry;
20238 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20239 + goto out;
20240 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20241 + }
20242 vcpu->arch.cpuid_nent = cpuid->nent;
20243 kvm_apic_set_version(vcpu);
20244 kvm_x86_ops->cpuid_update(vcpu);
20245 @@ -2363,15 +2371,19 @@ static int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20246 struct kvm_cpuid2 *cpuid,
20247 struct kvm_cpuid_entry2 __user *entries)
20248 {
20249 - int r;
20250 + int r, i;
20251
20252 r = -E2BIG;
20253 if (cpuid->nent < vcpu->arch.cpuid_nent)
20254 goto out;
20255 r = -EFAULT;
20256 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20257 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20258 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20259 goto out;
20260 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20261 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20262 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20263 + goto out;
20264 + }
20265 return 0;
20266
20267 out:
20268 @@ -2746,7 +2758,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20269 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20270 struct kvm_interrupt *irq)
20271 {
20272 - if (irq->irq < 0 || irq->irq >= 256)
20273 + if (irq->irq >= 256)
20274 return -EINVAL;
20275 if (irqchip_in_kernel(vcpu->kvm))
20276 return -ENXIO;
20277 @@ -3949,6 +3961,9 @@ gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva,
20278
20279 static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
20280 struct kvm_vcpu *vcpu, u32 access,
20281 + struct x86_exception *exception) __size_overflow(1,3);
20282 +static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
20283 + struct kvm_vcpu *vcpu, u32 access,
20284 struct x86_exception *exception)
20285 {
20286 void *data = val;
20287 @@ -3980,6 +3995,9 @@ out:
20288 /* used for instruction fetching */
20289 static int kvm_fetch_guest_virt(struct x86_emulate_ctxt *ctxt,
20290 gva_t addr, void *val, unsigned int bytes,
20291 + struct x86_exception *exception) __size_overflow(2,4);
20292 +static int kvm_fetch_guest_virt(struct x86_emulate_ctxt *ctxt,
20293 + gva_t addr, void *val, unsigned int bytes,
20294 struct x86_exception *exception)
20295 {
20296 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
20297 @@ -4004,6 +4022,9 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_virt);
20298
20299 static int kvm_read_guest_virt_system(struct x86_emulate_ctxt *ctxt,
20300 gva_t addr, void *val, unsigned int bytes,
20301 + struct x86_exception *exception) __size_overflow(2,4);
20302 +static int kvm_read_guest_virt_system(struct x86_emulate_ctxt *ctxt,
20303 + gva_t addr, void *val, unsigned int bytes,
20304 struct x86_exception *exception)
20305 {
20306 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
20307 @@ -4117,12 +4138,16 @@ static int read_prepare(struct kvm_vcpu *vcpu, void *val, int bytes)
20308 }
20309
20310 static int read_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20311 + void *val, int bytes) __size_overflow(2);
20312 +static int read_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20313 void *val, int bytes)
20314 {
20315 return !kvm_read_guest(vcpu->kvm, gpa, val, bytes);
20316 }
20317
20318 static int write_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20319 + void *val, int bytes) __size_overflow(2);
20320 +static int write_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20321 void *val, int bytes)
20322 {
20323 return emulator_write_phys(vcpu, gpa, val, bytes);
20324 @@ -4273,6 +4298,12 @@ static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt,
20325 const void *old,
20326 const void *new,
20327 unsigned int bytes,
20328 + struct x86_exception *exception) __size_overflow(5);
20329 +static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt,
20330 + unsigned long addr,
20331 + const void *old,
20332 + const void *new,
20333 + unsigned int bytes,
20334 struct x86_exception *exception)
20335 {
20336 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
20337 @@ -5162,7 +5193,7 @@ static void kvm_set_mmio_spte_mask(void)
20338 kvm_mmu_set_mmio_spte_mask(mask);
20339 }
20340
20341 -int kvm_arch_init(void *opaque)
20342 +int kvm_arch_init(const void *opaque)
20343 {
20344 int r;
20345 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20346 diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
20347 index d36fe23..a4b189f 100644
20348 --- a/arch/x86/kvm/x86.h
20349 +++ b/arch/x86/kvm/x86.h
20350 @@ -119,10 +119,10 @@ void kvm_write_tsc(struct kvm_vcpu *vcpu, u64 data);
20351
20352 int kvm_read_guest_virt(struct x86_emulate_ctxt *ctxt,
20353 gva_t addr, void *val, unsigned int bytes,
20354 - struct x86_exception *exception);
20355 + struct x86_exception *exception) __size_overflow(2,4);
20356
20357 int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
20358 gva_t addr, void *val, unsigned int bytes,
20359 - struct x86_exception *exception);
20360 + struct x86_exception *exception) __size_overflow(2,4);
20361
20362 #endif
20363 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20364 index cf4603b..7cdde38 100644
20365 --- a/arch/x86/lguest/boot.c
20366 +++ b/arch/x86/lguest/boot.c
20367 @@ -1195,9 +1195,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20368 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20369 * Launcher to reboot us.
20370 */
20371 -static void lguest_restart(char *reason)
20372 +static __noreturn void lguest_restart(char *reason)
20373 {
20374 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20375 + BUG();
20376 }
20377
20378 /*G:050
20379 diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
20380 index 042f682..c92afb6 100644
20381 --- a/arch/x86/lib/atomic64_32.c
20382 +++ b/arch/x86/lib/atomic64_32.c
20383 @@ -8,18 +8,30 @@
20384
20385 long long atomic64_read_cx8(long long, const atomic64_t *v);
20386 EXPORT_SYMBOL(atomic64_read_cx8);
20387 +long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
20388 +EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
20389 long long atomic64_set_cx8(long long, const atomic64_t *v);
20390 EXPORT_SYMBOL(atomic64_set_cx8);
20391 +long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
20392 +EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
20393 long long atomic64_xchg_cx8(long long, unsigned high);
20394 EXPORT_SYMBOL(atomic64_xchg_cx8);
20395 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
20396 EXPORT_SYMBOL(atomic64_add_return_cx8);
20397 +long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20398 +EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
20399 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
20400 EXPORT_SYMBOL(atomic64_sub_return_cx8);
20401 +long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20402 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
20403 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
20404 EXPORT_SYMBOL(atomic64_inc_return_cx8);
20405 +long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20406 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
20407 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
20408 EXPORT_SYMBOL(atomic64_dec_return_cx8);
20409 +long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20410 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
20411 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
20412 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
20413 int atomic64_inc_not_zero_cx8(atomic64_t *v);
20414 @@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
20415 #ifndef CONFIG_X86_CMPXCHG64
20416 long long atomic64_read_386(long long, const atomic64_t *v);
20417 EXPORT_SYMBOL(atomic64_read_386);
20418 +long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
20419 +EXPORT_SYMBOL(atomic64_read_unchecked_386);
20420 long long atomic64_set_386(long long, const atomic64_t *v);
20421 EXPORT_SYMBOL(atomic64_set_386);
20422 +long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
20423 +EXPORT_SYMBOL(atomic64_set_unchecked_386);
20424 long long atomic64_xchg_386(long long, unsigned high);
20425 EXPORT_SYMBOL(atomic64_xchg_386);
20426 long long atomic64_add_return_386(long long a, atomic64_t *v);
20427 EXPORT_SYMBOL(atomic64_add_return_386);
20428 +long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20429 +EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
20430 long long atomic64_sub_return_386(long long a, atomic64_t *v);
20431 EXPORT_SYMBOL(atomic64_sub_return_386);
20432 +long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20433 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
20434 long long atomic64_inc_return_386(long long a, atomic64_t *v);
20435 EXPORT_SYMBOL(atomic64_inc_return_386);
20436 +long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20437 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
20438 long long atomic64_dec_return_386(long long a, atomic64_t *v);
20439 EXPORT_SYMBOL(atomic64_dec_return_386);
20440 +long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20441 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
20442 long long atomic64_add_386(long long a, atomic64_t *v);
20443 EXPORT_SYMBOL(atomic64_add_386);
20444 +long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
20445 +EXPORT_SYMBOL(atomic64_add_unchecked_386);
20446 long long atomic64_sub_386(long long a, atomic64_t *v);
20447 EXPORT_SYMBOL(atomic64_sub_386);
20448 +long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
20449 +EXPORT_SYMBOL(atomic64_sub_unchecked_386);
20450 long long atomic64_inc_386(long long a, atomic64_t *v);
20451 EXPORT_SYMBOL(atomic64_inc_386);
20452 +long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
20453 +EXPORT_SYMBOL(atomic64_inc_unchecked_386);
20454 long long atomic64_dec_386(long long a, atomic64_t *v);
20455 EXPORT_SYMBOL(atomic64_dec_386);
20456 +long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
20457 +EXPORT_SYMBOL(atomic64_dec_unchecked_386);
20458 long long atomic64_dec_if_positive_386(atomic64_t *v);
20459 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
20460 int atomic64_inc_not_zero_386(atomic64_t *v);
20461 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20462 index e8e7e0d..56fd1b0 100644
20463 --- a/arch/x86/lib/atomic64_386_32.S
20464 +++ b/arch/x86/lib/atomic64_386_32.S
20465 @@ -48,6 +48,10 @@ BEGIN(read)
20466 movl (v), %eax
20467 movl 4(v), %edx
20468 RET_ENDP
20469 +BEGIN(read_unchecked)
20470 + movl (v), %eax
20471 + movl 4(v), %edx
20472 +RET_ENDP
20473 #undef v
20474
20475 #define v %esi
20476 @@ -55,6 +59,10 @@ BEGIN(set)
20477 movl %ebx, (v)
20478 movl %ecx, 4(v)
20479 RET_ENDP
20480 +BEGIN(set_unchecked)
20481 + movl %ebx, (v)
20482 + movl %ecx, 4(v)
20483 +RET_ENDP
20484 #undef v
20485
20486 #define v %esi
20487 @@ -70,6 +78,20 @@ RET_ENDP
20488 BEGIN(add)
20489 addl %eax, (v)
20490 adcl %edx, 4(v)
20491 +
20492 +#ifdef CONFIG_PAX_REFCOUNT
20493 + jno 0f
20494 + subl %eax, (v)
20495 + sbbl %edx, 4(v)
20496 + int $4
20497 +0:
20498 + _ASM_EXTABLE(0b, 0b)
20499 +#endif
20500 +
20501 +RET_ENDP
20502 +BEGIN(add_unchecked)
20503 + addl %eax, (v)
20504 + adcl %edx, 4(v)
20505 RET_ENDP
20506 #undef v
20507
20508 @@ -77,6 +99,24 @@ RET_ENDP
20509 BEGIN(add_return)
20510 addl (v), %eax
20511 adcl 4(v), %edx
20512 +
20513 +#ifdef CONFIG_PAX_REFCOUNT
20514 + into
20515 +1234:
20516 + _ASM_EXTABLE(1234b, 2f)
20517 +#endif
20518 +
20519 + movl %eax, (v)
20520 + movl %edx, 4(v)
20521 +
20522 +#ifdef CONFIG_PAX_REFCOUNT
20523 +2:
20524 +#endif
20525 +
20526 +RET_ENDP
20527 +BEGIN(add_return_unchecked)
20528 + addl (v), %eax
20529 + adcl 4(v), %edx
20530 movl %eax, (v)
20531 movl %edx, 4(v)
20532 RET_ENDP
20533 @@ -86,6 +126,20 @@ RET_ENDP
20534 BEGIN(sub)
20535 subl %eax, (v)
20536 sbbl %edx, 4(v)
20537 +
20538 +#ifdef CONFIG_PAX_REFCOUNT
20539 + jno 0f
20540 + addl %eax, (v)
20541 + adcl %edx, 4(v)
20542 + int $4
20543 +0:
20544 + _ASM_EXTABLE(0b, 0b)
20545 +#endif
20546 +
20547 +RET_ENDP
20548 +BEGIN(sub_unchecked)
20549 + subl %eax, (v)
20550 + sbbl %edx, 4(v)
20551 RET_ENDP
20552 #undef v
20553
20554 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20555 sbbl $0, %edx
20556 addl (v), %eax
20557 adcl 4(v), %edx
20558 +
20559 +#ifdef CONFIG_PAX_REFCOUNT
20560 + into
20561 +1234:
20562 + _ASM_EXTABLE(1234b, 2f)
20563 +#endif
20564 +
20565 + movl %eax, (v)
20566 + movl %edx, 4(v)
20567 +
20568 +#ifdef CONFIG_PAX_REFCOUNT
20569 +2:
20570 +#endif
20571 +
20572 +RET_ENDP
20573 +BEGIN(sub_return_unchecked)
20574 + negl %edx
20575 + negl %eax
20576 + sbbl $0, %edx
20577 + addl (v), %eax
20578 + adcl 4(v), %edx
20579 movl %eax, (v)
20580 movl %edx, 4(v)
20581 RET_ENDP
20582 @@ -105,6 +180,20 @@ RET_ENDP
20583 BEGIN(inc)
20584 addl $1, (v)
20585 adcl $0, 4(v)
20586 +
20587 +#ifdef CONFIG_PAX_REFCOUNT
20588 + jno 0f
20589 + subl $1, (v)
20590 + sbbl $0, 4(v)
20591 + int $4
20592 +0:
20593 + _ASM_EXTABLE(0b, 0b)
20594 +#endif
20595 +
20596 +RET_ENDP
20597 +BEGIN(inc_unchecked)
20598 + addl $1, (v)
20599 + adcl $0, 4(v)
20600 RET_ENDP
20601 #undef v
20602
20603 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20604 movl 4(v), %edx
20605 addl $1, %eax
20606 adcl $0, %edx
20607 +
20608 +#ifdef CONFIG_PAX_REFCOUNT
20609 + into
20610 +1234:
20611 + _ASM_EXTABLE(1234b, 2f)
20612 +#endif
20613 +
20614 + movl %eax, (v)
20615 + movl %edx, 4(v)
20616 +
20617 +#ifdef CONFIG_PAX_REFCOUNT
20618 +2:
20619 +#endif
20620 +
20621 +RET_ENDP
20622 +BEGIN(inc_return_unchecked)
20623 + movl (v), %eax
20624 + movl 4(v), %edx
20625 + addl $1, %eax
20626 + adcl $0, %edx
20627 movl %eax, (v)
20628 movl %edx, 4(v)
20629 RET_ENDP
20630 @@ -123,6 +232,20 @@ RET_ENDP
20631 BEGIN(dec)
20632 subl $1, (v)
20633 sbbl $0, 4(v)
20634 +
20635 +#ifdef CONFIG_PAX_REFCOUNT
20636 + jno 0f
20637 + addl $1, (v)
20638 + adcl $0, 4(v)
20639 + int $4
20640 +0:
20641 + _ASM_EXTABLE(0b, 0b)
20642 +#endif
20643 +
20644 +RET_ENDP
20645 +BEGIN(dec_unchecked)
20646 + subl $1, (v)
20647 + sbbl $0, 4(v)
20648 RET_ENDP
20649 #undef v
20650
20651 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20652 movl 4(v), %edx
20653 subl $1, %eax
20654 sbbl $0, %edx
20655 +
20656 +#ifdef CONFIG_PAX_REFCOUNT
20657 + into
20658 +1234:
20659 + _ASM_EXTABLE(1234b, 2f)
20660 +#endif
20661 +
20662 + movl %eax, (v)
20663 + movl %edx, 4(v)
20664 +
20665 +#ifdef CONFIG_PAX_REFCOUNT
20666 +2:
20667 +#endif
20668 +
20669 +RET_ENDP
20670 +BEGIN(dec_return_unchecked)
20671 + movl (v), %eax
20672 + movl 4(v), %edx
20673 + subl $1, %eax
20674 + sbbl $0, %edx
20675 movl %eax, (v)
20676 movl %edx, 4(v)
20677 RET_ENDP
20678 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20679 adcl %edx, %edi
20680 addl (v), %eax
20681 adcl 4(v), %edx
20682 +
20683 +#ifdef CONFIG_PAX_REFCOUNT
20684 + into
20685 +1234:
20686 + _ASM_EXTABLE(1234b, 2f)
20687 +#endif
20688 +
20689 cmpl %eax, %esi
20690 je 3f
20691 1:
20692 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20693 1:
20694 addl $1, %eax
20695 adcl $0, %edx
20696 +
20697 +#ifdef CONFIG_PAX_REFCOUNT
20698 + into
20699 +1234:
20700 + _ASM_EXTABLE(1234b, 2f)
20701 +#endif
20702 +
20703 movl %eax, (v)
20704 movl %edx, 4(v)
20705 movl $1, %eax
20706 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20707 movl 4(v), %edx
20708 subl $1, %eax
20709 sbbl $0, %edx
20710 +
20711 +#ifdef CONFIG_PAX_REFCOUNT
20712 + into
20713 +1234:
20714 + _ASM_EXTABLE(1234b, 1f)
20715 +#endif
20716 +
20717 js 1f
20718 movl %eax, (v)
20719 movl %edx, 4(v)
20720 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20721 index 391a083..d658e9f 100644
20722 --- a/arch/x86/lib/atomic64_cx8_32.S
20723 +++ b/arch/x86/lib/atomic64_cx8_32.S
20724 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20725 CFI_STARTPROC
20726
20727 read64 %ecx
20728 + pax_force_retaddr
20729 ret
20730 CFI_ENDPROC
20731 ENDPROC(atomic64_read_cx8)
20732
20733 +ENTRY(atomic64_read_unchecked_cx8)
20734 + CFI_STARTPROC
20735 +
20736 + read64 %ecx
20737 + pax_force_retaddr
20738 + ret
20739 + CFI_ENDPROC
20740 +ENDPROC(atomic64_read_unchecked_cx8)
20741 +
20742 ENTRY(atomic64_set_cx8)
20743 CFI_STARTPROC
20744
20745 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20746 cmpxchg8b (%esi)
20747 jne 1b
20748
20749 + pax_force_retaddr
20750 ret
20751 CFI_ENDPROC
20752 ENDPROC(atomic64_set_cx8)
20753
20754 +ENTRY(atomic64_set_unchecked_cx8)
20755 + CFI_STARTPROC
20756 +
20757 +1:
20758 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20759 + * are atomic on 586 and newer */
20760 + cmpxchg8b (%esi)
20761 + jne 1b
20762 +
20763 + pax_force_retaddr
20764 + ret
20765 + CFI_ENDPROC
20766 +ENDPROC(atomic64_set_unchecked_cx8)
20767 +
20768 ENTRY(atomic64_xchg_cx8)
20769 CFI_STARTPROC
20770
20771 @@ -62,12 +87,13 @@ ENTRY(atomic64_xchg_cx8)
20772 cmpxchg8b (%esi)
20773 jne 1b
20774
20775 + pax_force_retaddr
20776 ret
20777 CFI_ENDPROC
20778 ENDPROC(atomic64_xchg_cx8)
20779
20780 -.macro addsub_return func ins insc
20781 -ENTRY(atomic64_\func\()_return_cx8)
20782 +.macro addsub_return func ins insc unchecked=""
20783 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20784 CFI_STARTPROC
20785 SAVE ebp
20786 SAVE ebx
20787 @@ -84,27 +110,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20788 movl %edx, %ecx
20789 \ins\()l %esi, %ebx
20790 \insc\()l %edi, %ecx
20791 +
20792 +.ifb \unchecked
20793 +#ifdef CONFIG_PAX_REFCOUNT
20794 + into
20795 +2:
20796 + _ASM_EXTABLE(2b, 3f)
20797 +#endif
20798 +.endif
20799 +
20800 LOCK_PREFIX
20801 cmpxchg8b (%ebp)
20802 jne 1b
20803 -
20804 -10:
20805 movl %ebx, %eax
20806 movl %ecx, %edx
20807 +
20808 +.ifb \unchecked
20809 +#ifdef CONFIG_PAX_REFCOUNT
20810 +3:
20811 +#endif
20812 +.endif
20813 +
20814 RESTORE edi
20815 RESTORE esi
20816 RESTORE ebx
20817 RESTORE ebp
20818 + pax_force_retaddr
20819 ret
20820 CFI_ENDPROC
20821 -ENDPROC(atomic64_\func\()_return_cx8)
20822 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20823 .endm
20824
20825 addsub_return add add adc
20826 addsub_return sub sub sbb
20827 +addsub_return add add adc _unchecked
20828 +addsub_return sub sub sbb _unchecked
20829
20830 -.macro incdec_return func ins insc
20831 -ENTRY(atomic64_\func\()_return_cx8)
20832 +.macro incdec_return func ins insc unchecked
20833 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20834 CFI_STARTPROC
20835 SAVE ebx
20836
20837 @@ -114,21 +157,39 @@ ENTRY(atomic64_\func\()_return_cx8)
20838 movl %edx, %ecx
20839 \ins\()l $1, %ebx
20840 \insc\()l $0, %ecx
20841 +
20842 +.ifb \unchecked
20843 +#ifdef CONFIG_PAX_REFCOUNT
20844 + into
20845 +2:
20846 + _ASM_EXTABLE(2b, 3f)
20847 +#endif
20848 +.endif
20849 +
20850 LOCK_PREFIX
20851 cmpxchg8b (%esi)
20852 jne 1b
20853
20854 -10:
20855 movl %ebx, %eax
20856 movl %ecx, %edx
20857 +
20858 +.ifb \unchecked
20859 +#ifdef CONFIG_PAX_REFCOUNT
20860 +3:
20861 +#endif
20862 +.endif
20863 +
20864 RESTORE ebx
20865 + pax_force_retaddr
20866 ret
20867 CFI_ENDPROC
20868 -ENDPROC(atomic64_\func\()_return_cx8)
20869 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20870 .endm
20871
20872 incdec_return inc add adc
20873 incdec_return dec sub sbb
20874 +incdec_return inc add adc _unchecked
20875 +incdec_return dec sub sbb _unchecked
20876
20877 ENTRY(atomic64_dec_if_positive_cx8)
20878 CFI_STARTPROC
20879 @@ -140,6 +201,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
20880 movl %edx, %ecx
20881 subl $1, %ebx
20882 sbb $0, %ecx
20883 +
20884 +#ifdef CONFIG_PAX_REFCOUNT
20885 + into
20886 +1234:
20887 + _ASM_EXTABLE(1234b, 2f)
20888 +#endif
20889 +
20890 js 2f
20891 LOCK_PREFIX
20892 cmpxchg8b (%esi)
20893 @@ -149,6 +217,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
20894 movl %ebx, %eax
20895 movl %ecx, %edx
20896 RESTORE ebx
20897 + pax_force_retaddr
20898 ret
20899 CFI_ENDPROC
20900 ENDPROC(atomic64_dec_if_positive_cx8)
20901 @@ -174,6 +243,13 @@ ENTRY(atomic64_add_unless_cx8)
20902 movl %edx, %ecx
20903 addl %esi, %ebx
20904 adcl %edi, %ecx
20905 +
20906 +#ifdef CONFIG_PAX_REFCOUNT
20907 + into
20908 +1234:
20909 + _ASM_EXTABLE(1234b, 3f)
20910 +#endif
20911 +
20912 LOCK_PREFIX
20913 cmpxchg8b (%ebp)
20914 jne 1b
20915 @@ -184,6 +260,7 @@ ENTRY(atomic64_add_unless_cx8)
20916 CFI_ADJUST_CFA_OFFSET -8
20917 RESTORE ebx
20918 RESTORE ebp
20919 + pax_force_retaddr
20920 ret
20921 4:
20922 cmpl %edx, 4(%esp)
20923 @@ -206,6 +283,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
20924 movl %edx, %ecx
20925 addl $1, %ebx
20926 adcl $0, %ecx
20927 +
20928 +#ifdef CONFIG_PAX_REFCOUNT
20929 + into
20930 +1234:
20931 + _ASM_EXTABLE(1234b, 3f)
20932 +#endif
20933 +
20934 LOCK_PREFIX
20935 cmpxchg8b (%esi)
20936 jne 1b
20937 @@ -213,6 +297,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
20938 movl $1, %eax
20939 3:
20940 RESTORE ebx
20941 + pax_force_retaddr
20942 ret
20943 4:
20944 testl %edx, %edx
20945 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
20946 index 78d16a5..fbcf666 100644
20947 --- a/arch/x86/lib/checksum_32.S
20948 +++ b/arch/x86/lib/checksum_32.S
20949 @@ -28,7 +28,8 @@
20950 #include <linux/linkage.h>
20951 #include <asm/dwarf2.h>
20952 #include <asm/errno.h>
20953 -
20954 +#include <asm/segment.h>
20955 +
20956 /*
20957 * computes a partial checksum, e.g. for TCP/UDP fragments
20958 */
20959 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
20960
20961 #define ARGBASE 16
20962 #define FP 12
20963 -
20964 -ENTRY(csum_partial_copy_generic)
20965 +
20966 +ENTRY(csum_partial_copy_generic_to_user)
20967 CFI_STARTPROC
20968 +
20969 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20970 + pushl_cfi %gs
20971 + popl_cfi %es
20972 + jmp csum_partial_copy_generic
20973 +#endif
20974 +
20975 +ENTRY(csum_partial_copy_generic_from_user)
20976 +
20977 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20978 + pushl_cfi %gs
20979 + popl_cfi %ds
20980 +#endif
20981 +
20982 +ENTRY(csum_partial_copy_generic)
20983 subl $4,%esp
20984 CFI_ADJUST_CFA_OFFSET 4
20985 pushl_cfi %edi
20986 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
20987 jmp 4f
20988 SRC(1: movw (%esi), %bx )
20989 addl $2, %esi
20990 -DST( movw %bx, (%edi) )
20991 +DST( movw %bx, %es:(%edi) )
20992 addl $2, %edi
20993 addw %bx, %ax
20994 adcl $0, %eax
20995 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
20996 SRC(1: movl (%esi), %ebx )
20997 SRC( movl 4(%esi), %edx )
20998 adcl %ebx, %eax
20999 -DST( movl %ebx, (%edi) )
21000 +DST( movl %ebx, %es:(%edi) )
21001 adcl %edx, %eax
21002 -DST( movl %edx, 4(%edi) )
21003 +DST( movl %edx, %es:4(%edi) )
21004
21005 SRC( movl 8(%esi), %ebx )
21006 SRC( movl 12(%esi), %edx )
21007 adcl %ebx, %eax
21008 -DST( movl %ebx, 8(%edi) )
21009 +DST( movl %ebx, %es:8(%edi) )
21010 adcl %edx, %eax
21011 -DST( movl %edx, 12(%edi) )
21012 +DST( movl %edx, %es:12(%edi) )
21013
21014 SRC( movl 16(%esi), %ebx )
21015 SRC( movl 20(%esi), %edx )
21016 adcl %ebx, %eax
21017 -DST( movl %ebx, 16(%edi) )
21018 +DST( movl %ebx, %es:16(%edi) )
21019 adcl %edx, %eax
21020 -DST( movl %edx, 20(%edi) )
21021 +DST( movl %edx, %es:20(%edi) )
21022
21023 SRC( movl 24(%esi), %ebx )
21024 SRC( movl 28(%esi), %edx )
21025 adcl %ebx, %eax
21026 -DST( movl %ebx, 24(%edi) )
21027 +DST( movl %ebx, %es:24(%edi) )
21028 adcl %edx, %eax
21029 -DST( movl %edx, 28(%edi) )
21030 +DST( movl %edx, %es:28(%edi) )
21031
21032 lea 32(%esi), %esi
21033 lea 32(%edi), %edi
21034 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
21035 shrl $2, %edx # This clears CF
21036 SRC(3: movl (%esi), %ebx )
21037 adcl %ebx, %eax
21038 -DST( movl %ebx, (%edi) )
21039 +DST( movl %ebx, %es:(%edi) )
21040 lea 4(%esi), %esi
21041 lea 4(%edi), %edi
21042 dec %edx
21043 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
21044 jb 5f
21045 SRC( movw (%esi), %cx )
21046 leal 2(%esi), %esi
21047 -DST( movw %cx, (%edi) )
21048 +DST( movw %cx, %es:(%edi) )
21049 leal 2(%edi), %edi
21050 je 6f
21051 shll $16,%ecx
21052 SRC(5: movb (%esi), %cl )
21053 -DST( movb %cl, (%edi) )
21054 +DST( movb %cl, %es:(%edi) )
21055 6: addl %ecx, %eax
21056 adcl $0, %eax
21057 7:
21058 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
21059
21060 6001:
21061 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21062 - movl $-EFAULT, (%ebx)
21063 + movl $-EFAULT, %ss:(%ebx)
21064
21065 # zero the complete destination - computing the rest
21066 # is too much work
21067 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
21068
21069 6002:
21070 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21071 - movl $-EFAULT,(%ebx)
21072 + movl $-EFAULT,%ss:(%ebx)
21073 jmp 5000b
21074
21075 .previous
21076
21077 + pushl_cfi %ss
21078 + popl_cfi %ds
21079 + pushl_cfi %ss
21080 + popl_cfi %es
21081 popl_cfi %ebx
21082 CFI_RESTORE ebx
21083 popl_cfi %esi
21084 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
21085 popl_cfi %ecx # equivalent to addl $4,%esp
21086 ret
21087 CFI_ENDPROC
21088 -ENDPROC(csum_partial_copy_generic)
21089 +ENDPROC(csum_partial_copy_generic_to_user)
21090
21091 #else
21092
21093 /* Version for PentiumII/PPro */
21094
21095 #define ROUND1(x) \
21096 + nop; nop; nop; \
21097 SRC(movl x(%esi), %ebx ) ; \
21098 addl %ebx, %eax ; \
21099 - DST(movl %ebx, x(%edi) ) ;
21100 + DST(movl %ebx, %es:x(%edi)) ;
21101
21102 #define ROUND(x) \
21103 + nop; nop; nop; \
21104 SRC(movl x(%esi), %ebx ) ; \
21105 adcl %ebx, %eax ; \
21106 - DST(movl %ebx, x(%edi) ) ;
21107 + DST(movl %ebx, %es:x(%edi)) ;
21108
21109 #define ARGBASE 12
21110 -
21111 -ENTRY(csum_partial_copy_generic)
21112 +
21113 +ENTRY(csum_partial_copy_generic_to_user)
21114 CFI_STARTPROC
21115 +
21116 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21117 + pushl_cfi %gs
21118 + popl_cfi %es
21119 + jmp csum_partial_copy_generic
21120 +#endif
21121 +
21122 +ENTRY(csum_partial_copy_generic_from_user)
21123 +
21124 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21125 + pushl_cfi %gs
21126 + popl_cfi %ds
21127 +#endif
21128 +
21129 +ENTRY(csum_partial_copy_generic)
21130 pushl_cfi %ebx
21131 CFI_REL_OFFSET ebx, 0
21132 pushl_cfi %edi
21133 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
21134 subl %ebx, %edi
21135 lea -1(%esi),%edx
21136 andl $-32,%edx
21137 - lea 3f(%ebx,%ebx), %ebx
21138 + lea 3f(%ebx,%ebx,2), %ebx
21139 testl %esi, %esi
21140 jmp *%ebx
21141 1: addl $64,%esi
21142 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
21143 jb 5f
21144 SRC( movw (%esi), %dx )
21145 leal 2(%esi), %esi
21146 -DST( movw %dx, (%edi) )
21147 +DST( movw %dx, %es:(%edi) )
21148 leal 2(%edi), %edi
21149 je 6f
21150 shll $16,%edx
21151 5:
21152 SRC( movb (%esi), %dl )
21153 -DST( movb %dl, (%edi) )
21154 +DST( movb %dl, %es:(%edi) )
21155 6: addl %edx, %eax
21156 adcl $0, %eax
21157 7:
21158 .section .fixup, "ax"
21159 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21160 - movl $-EFAULT, (%ebx)
21161 + movl $-EFAULT, %ss:(%ebx)
21162 # zero the complete destination (computing the rest is too much work)
21163 movl ARGBASE+8(%esp),%edi # dst
21164 movl ARGBASE+12(%esp),%ecx # len
21165 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
21166 rep; stosb
21167 jmp 7b
21168 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21169 - movl $-EFAULT, (%ebx)
21170 + movl $-EFAULT, %ss:(%ebx)
21171 jmp 7b
21172 .previous
21173
21174 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21175 + pushl_cfi %ss
21176 + popl_cfi %ds
21177 + pushl_cfi %ss
21178 + popl_cfi %es
21179 +#endif
21180 +
21181 popl_cfi %esi
21182 CFI_RESTORE esi
21183 popl_cfi %edi
21184 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
21185 CFI_RESTORE ebx
21186 ret
21187 CFI_ENDPROC
21188 -ENDPROC(csum_partial_copy_generic)
21189 +ENDPROC(csum_partial_copy_generic_to_user)
21190
21191 #undef ROUND
21192 #undef ROUND1
21193 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21194 index f2145cf..cea889d 100644
21195 --- a/arch/x86/lib/clear_page_64.S
21196 +++ b/arch/x86/lib/clear_page_64.S
21197 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21198 movl $4096/8,%ecx
21199 xorl %eax,%eax
21200 rep stosq
21201 + pax_force_retaddr
21202 ret
21203 CFI_ENDPROC
21204 ENDPROC(clear_page_c)
21205 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21206 movl $4096,%ecx
21207 xorl %eax,%eax
21208 rep stosb
21209 + pax_force_retaddr
21210 ret
21211 CFI_ENDPROC
21212 ENDPROC(clear_page_c_e)
21213 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21214 leaq 64(%rdi),%rdi
21215 jnz .Lloop
21216 nop
21217 + pax_force_retaddr
21218 ret
21219 CFI_ENDPROC
21220 .Lclear_page_end:
21221 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21222
21223 #include <asm/cpufeature.h>
21224
21225 - .section .altinstr_replacement,"ax"
21226 + .section .altinstr_replacement,"a"
21227 1: .byte 0xeb /* jmp <disp8> */
21228 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21229 2: .byte 0xeb /* jmp <disp8> */
21230 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21231 index 1e572c5..2a162cd 100644
21232 --- a/arch/x86/lib/cmpxchg16b_emu.S
21233 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21234 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21235
21236 popf
21237 mov $1, %al
21238 + pax_force_retaddr
21239 ret
21240
21241 not_same:
21242 popf
21243 xor %al,%al
21244 + pax_force_retaddr
21245 ret
21246
21247 CFI_ENDPROC
21248 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21249 index 01c805b..dccb07f 100644
21250 --- a/arch/x86/lib/copy_page_64.S
21251 +++ b/arch/x86/lib/copy_page_64.S
21252 @@ -9,6 +9,7 @@ copy_page_c:
21253 CFI_STARTPROC
21254 movl $4096/8,%ecx
21255 rep movsq
21256 + pax_force_retaddr
21257 ret
21258 CFI_ENDPROC
21259 ENDPROC(copy_page_c)
21260 @@ -39,7 +40,7 @@ ENTRY(copy_page)
21261 movq 16 (%rsi), %rdx
21262 movq 24 (%rsi), %r8
21263 movq 32 (%rsi), %r9
21264 - movq 40 (%rsi), %r10
21265 + movq 40 (%rsi), %r13
21266 movq 48 (%rsi), %r11
21267 movq 56 (%rsi), %r12
21268
21269 @@ -50,7 +51,7 @@ ENTRY(copy_page)
21270 movq %rdx, 16 (%rdi)
21271 movq %r8, 24 (%rdi)
21272 movq %r9, 32 (%rdi)
21273 - movq %r10, 40 (%rdi)
21274 + movq %r13, 40 (%rdi)
21275 movq %r11, 48 (%rdi)
21276 movq %r12, 56 (%rdi)
21277
21278 @@ -69,7 +70,7 @@ ENTRY(copy_page)
21279 movq 16 (%rsi), %rdx
21280 movq 24 (%rsi), %r8
21281 movq 32 (%rsi), %r9
21282 - movq 40 (%rsi), %r10
21283 + movq 40 (%rsi), %r13
21284 movq 48 (%rsi), %r11
21285 movq 56 (%rsi), %r12
21286
21287 @@ -78,7 +79,7 @@ ENTRY(copy_page)
21288 movq %rdx, 16 (%rdi)
21289 movq %r8, 24 (%rdi)
21290 movq %r9, 32 (%rdi)
21291 - movq %r10, 40 (%rdi)
21292 + movq %r13, 40 (%rdi)
21293 movq %r11, 48 (%rdi)
21294 movq %r12, 56 (%rdi)
21295
21296 @@ -95,6 +96,7 @@ ENTRY(copy_page)
21297 CFI_RESTORE r13
21298 addq $3*8,%rsp
21299 CFI_ADJUST_CFA_OFFSET -3*8
21300 + pax_force_retaddr
21301 ret
21302 .Lcopy_page_end:
21303 CFI_ENDPROC
21304 @@ -105,7 +107,7 @@ ENDPROC(copy_page)
21305
21306 #include <asm/cpufeature.h>
21307
21308 - .section .altinstr_replacement,"ax"
21309 + .section .altinstr_replacement,"a"
21310 1: .byte 0xeb /* jmp <disp8> */
21311 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21312 2:
21313 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21314 index 0248402..821c786 100644
21315 --- a/arch/x86/lib/copy_user_64.S
21316 +++ b/arch/x86/lib/copy_user_64.S
21317 @@ -16,6 +16,7 @@
21318 #include <asm/thread_info.h>
21319 #include <asm/cpufeature.h>
21320 #include <asm/alternative-asm.h>
21321 +#include <asm/pgtable.h>
21322
21323 /*
21324 * By placing feature2 after feature1 in altinstructions section, we logically
21325 @@ -29,7 +30,7 @@
21326 .byte 0xe9 /* 32bit jump */
21327 .long \orig-1f /* by default jump to orig */
21328 1:
21329 - .section .altinstr_replacement,"ax"
21330 + .section .altinstr_replacement,"a"
21331 2: .byte 0xe9 /* near jump with 32bit immediate */
21332 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21333 3: .byte 0xe9 /* near jump with 32bit immediate */
21334 @@ -71,47 +72,20 @@
21335 #endif
21336 .endm
21337
21338 -/* Standard copy_to_user with segment limit checking */
21339 -ENTRY(_copy_to_user)
21340 - CFI_STARTPROC
21341 - GET_THREAD_INFO(%rax)
21342 - movq %rdi,%rcx
21343 - addq %rdx,%rcx
21344 - jc bad_to_user
21345 - cmpq TI_addr_limit(%rax),%rcx
21346 - ja bad_to_user
21347 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21348 - copy_user_generic_unrolled,copy_user_generic_string, \
21349 - copy_user_enhanced_fast_string
21350 - CFI_ENDPROC
21351 -ENDPROC(_copy_to_user)
21352 -
21353 -/* Standard copy_from_user with segment limit checking */
21354 -ENTRY(_copy_from_user)
21355 - CFI_STARTPROC
21356 - GET_THREAD_INFO(%rax)
21357 - movq %rsi,%rcx
21358 - addq %rdx,%rcx
21359 - jc bad_from_user
21360 - cmpq TI_addr_limit(%rax),%rcx
21361 - ja bad_from_user
21362 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21363 - copy_user_generic_unrolled,copy_user_generic_string, \
21364 - copy_user_enhanced_fast_string
21365 - CFI_ENDPROC
21366 -ENDPROC(_copy_from_user)
21367 -
21368 .section .fixup,"ax"
21369 /* must zero dest */
21370 ENTRY(bad_from_user)
21371 bad_from_user:
21372 CFI_STARTPROC
21373 + testl %edx,%edx
21374 + js bad_to_user
21375 movl %edx,%ecx
21376 xorl %eax,%eax
21377 rep
21378 stosb
21379 bad_to_user:
21380 movl %edx,%eax
21381 + pax_force_retaddr
21382 ret
21383 CFI_ENDPROC
21384 ENDPROC(bad_from_user)
21385 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
21386 jz 17f
21387 1: movq (%rsi),%r8
21388 2: movq 1*8(%rsi),%r9
21389 -3: movq 2*8(%rsi),%r10
21390 +3: movq 2*8(%rsi),%rax
21391 4: movq 3*8(%rsi),%r11
21392 5: movq %r8,(%rdi)
21393 6: movq %r9,1*8(%rdi)
21394 -7: movq %r10,2*8(%rdi)
21395 +7: movq %rax,2*8(%rdi)
21396 8: movq %r11,3*8(%rdi)
21397 9: movq 4*8(%rsi),%r8
21398 10: movq 5*8(%rsi),%r9
21399 -11: movq 6*8(%rsi),%r10
21400 +11: movq 6*8(%rsi),%rax
21401 12: movq 7*8(%rsi),%r11
21402 13: movq %r8,4*8(%rdi)
21403 14: movq %r9,5*8(%rdi)
21404 -15: movq %r10,6*8(%rdi)
21405 +15: movq %rax,6*8(%rdi)
21406 16: movq %r11,7*8(%rdi)
21407 leaq 64(%rsi),%rsi
21408 leaq 64(%rdi),%rdi
21409 @@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
21410 decl %ecx
21411 jnz 21b
21412 23: xor %eax,%eax
21413 + pax_force_retaddr
21414 ret
21415
21416 .section .fixup,"ax"
21417 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
21418 3: rep
21419 movsb
21420 4: xorl %eax,%eax
21421 + pax_force_retaddr
21422 ret
21423
21424 .section .fixup,"ax"
21425 @@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
21426 1: rep
21427 movsb
21428 2: xorl %eax,%eax
21429 + pax_force_retaddr
21430 ret
21431
21432 .section .fixup,"ax"
21433 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21434 index cb0c112..e3a6895 100644
21435 --- a/arch/x86/lib/copy_user_nocache_64.S
21436 +++ b/arch/x86/lib/copy_user_nocache_64.S
21437 @@ -8,12 +8,14 @@
21438
21439 #include <linux/linkage.h>
21440 #include <asm/dwarf2.h>
21441 +#include <asm/alternative-asm.h>
21442
21443 #define FIX_ALIGNMENT 1
21444
21445 #include <asm/current.h>
21446 #include <asm/asm-offsets.h>
21447 #include <asm/thread_info.h>
21448 +#include <asm/pgtable.h>
21449
21450 .macro ALIGN_DESTINATION
21451 #ifdef FIX_ALIGNMENT
21452 @@ -50,6 +52,15 @@
21453 */
21454 ENTRY(__copy_user_nocache)
21455 CFI_STARTPROC
21456 +
21457 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21458 + mov $PAX_USER_SHADOW_BASE,%rcx
21459 + cmp %rcx,%rsi
21460 + jae 1f
21461 + add %rcx,%rsi
21462 +1:
21463 +#endif
21464 +
21465 cmpl $8,%edx
21466 jb 20f /* less then 8 bytes, go to byte copy loop */
21467 ALIGN_DESTINATION
21468 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21469 jz 17f
21470 1: movq (%rsi),%r8
21471 2: movq 1*8(%rsi),%r9
21472 -3: movq 2*8(%rsi),%r10
21473 +3: movq 2*8(%rsi),%rax
21474 4: movq 3*8(%rsi),%r11
21475 5: movnti %r8,(%rdi)
21476 6: movnti %r9,1*8(%rdi)
21477 -7: movnti %r10,2*8(%rdi)
21478 +7: movnti %rax,2*8(%rdi)
21479 8: movnti %r11,3*8(%rdi)
21480 9: movq 4*8(%rsi),%r8
21481 10: movq 5*8(%rsi),%r9
21482 -11: movq 6*8(%rsi),%r10
21483 +11: movq 6*8(%rsi),%rax
21484 12: movq 7*8(%rsi),%r11
21485 13: movnti %r8,4*8(%rdi)
21486 14: movnti %r9,5*8(%rdi)
21487 -15: movnti %r10,6*8(%rdi)
21488 +15: movnti %rax,6*8(%rdi)
21489 16: movnti %r11,7*8(%rdi)
21490 leaq 64(%rsi),%rsi
21491 leaq 64(%rdi),%rdi
21492 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
21493 jnz 21b
21494 23: xorl %eax,%eax
21495 sfence
21496 + pax_force_retaddr
21497 ret
21498
21499 .section .fixup,"ax"
21500 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21501 index fb903b7..c92b7f7 100644
21502 --- a/arch/x86/lib/csum-copy_64.S
21503 +++ b/arch/x86/lib/csum-copy_64.S
21504 @@ -8,6 +8,7 @@
21505 #include <linux/linkage.h>
21506 #include <asm/dwarf2.h>
21507 #include <asm/errno.h>
21508 +#include <asm/alternative-asm.h>
21509
21510 /*
21511 * Checksum copy with exception handling.
21512 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
21513 CFI_RESTORE rbp
21514 addq $7*8, %rsp
21515 CFI_ADJUST_CFA_OFFSET -7*8
21516 + pax_force_retaddr 0, 1
21517 ret
21518 CFI_RESTORE_STATE
21519
21520 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21521 index 459b58a..9570bc7 100644
21522 --- a/arch/x86/lib/csum-wrappers_64.c
21523 +++ b/arch/x86/lib/csum-wrappers_64.c
21524 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21525 len -= 2;
21526 }
21527 }
21528 - isum = csum_partial_copy_generic((__force const void *)src,
21529 +
21530 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21531 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21532 + src += PAX_USER_SHADOW_BASE;
21533 +#endif
21534 +
21535 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21536 dst, len, isum, errp, NULL);
21537 if (unlikely(*errp))
21538 goto out_err;
21539 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21540 }
21541
21542 *errp = 0;
21543 - return csum_partial_copy_generic(src, (void __force *)dst,
21544 +
21545 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21546 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21547 + dst += PAX_USER_SHADOW_BASE;
21548 +#endif
21549 +
21550 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21551 len, isum, NULL, errp);
21552 }
21553 EXPORT_SYMBOL(csum_partial_copy_to_user);
21554 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21555 index 51f1504..ddac4c1 100644
21556 --- a/arch/x86/lib/getuser.S
21557 +++ b/arch/x86/lib/getuser.S
21558 @@ -33,15 +33,38 @@
21559 #include <asm/asm-offsets.h>
21560 #include <asm/thread_info.h>
21561 #include <asm/asm.h>
21562 +#include <asm/segment.h>
21563 +#include <asm/pgtable.h>
21564 +#include <asm/alternative-asm.h>
21565 +
21566 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21567 +#define __copyuser_seg gs;
21568 +#else
21569 +#define __copyuser_seg
21570 +#endif
21571
21572 .text
21573 ENTRY(__get_user_1)
21574 CFI_STARTPROC
21575 +
21576 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21577 GET_THREAD_INFO(%_ASM_DX)
21578 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21579 jae bad_get_user
21580 -1: movzb (%_ASM_AX),%edx
21581 +
21582 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21583 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21584 + cmp %_ASM_DX,%_ASM_AX
21585 + jae 1234f
21586 + add %_ASM_DX,%_ASM_AX
21587 +1234:
21588 +#endif
21589 +
21590 +#endif
21591 +
21592 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21593 xor %eax,%eax
21594 + pax_force_retaddr
21595 ret
21596 CFI_ENDPROC
21597 ENDPROC(__get_user_1)
21598 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21599 ENTRY(__get_user_2)
21600 CFI_STARTPROC
21601 add $1,%_ASM_AX
21602 +
21603 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21604 jc bad_get_user
21605 GET_THREAD_INFO(%_ASM_DX)
21606 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21607 jae bad_get_user
21608 -2: movzwl -1(%_ASM_AX),%edx
21609 +
21610 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21611 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21612 + cmp %_ASM_DX,%_ASM_AX
21613 + jae 1234f
21614 + add %_ASM_DX,%_ASM_AX
21615 +1234:
21616 +#endif
21617 +
21618 +#endif
21619 +
21620 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21621 xor %eax,%eax
21622 + pax_force_retaddr
21623 ret
21624 CFI_ENDPROC
21625 ENDPROC(__get_user_2)
21626 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21627 ENTRY(__get_user_4)
21628 CFI_STARTPROC
21629 add $3,%_ASM_AX
21630 +
21631 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21632 jc bad_get_user
21633 GET_THREAD_INFO(%_ASM_DX)
21634 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21635 jae bad_get_user
21636 -3: mov -3(%_ASM_AX),%edx
21637 +
21638 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21639 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21640 + cmp %_ASM_DX,%_ASM_AX
21641 + jae 1234f
21642 + add %_ASM_DX,%_ASM_AX
21643 +1234:
21644 +#endif
21645 +
21646 +#endif
21647 +
21648 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21649 xor %eax,%eax
21650 + pax_force_retaddr
21651 ret
21652 CFI_ENDPROC
21653 ENDPROC(__get_user_4)
21654 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21655 GET_THREAD_INFO(%_ASM_DX)
21656 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21657 jae bad_get_user
21658 +
21659 +#ifdef 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 4: movq -7(%_ASM_AX),%_ASM_DX
21668 xor %eax,%eax
21669 + pax_force_retaddr
21670 ret
21671 CFI_ENDPROC
21672 ENDPROC(__get_user_8)
21673 @@ -91,6 +152,7 @@ bad_get_user:
21674 CFI_STARTPROC
21675 xor %edx,%edx
21676 mov $(-EFAULT),%_ASM_AX
21677 + pax_force_retaddr
21678 ret
21679 CFI_ENDPROC
21680 END(bad_get_user)
21681 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21682 index 374562e..a75830b 100644
21683 --- a/arch/x86/lib/insn.c
21684 +++ b/arch/x86/lib/insn.c
21685 @@ -21,6 +21,11 @@
21686 #include <linux/string.h>
21687 #include <asm/inat.h>
21688 #include <asm/insn.h>
21689 +#ifdef __KERNEL__
21690 +#include <asm/pgtable_types.h>
21691 +#else
21692 +#define ktla_ktva(addr) addr
21693 +#endif
21694
21695 /* Verify next sizeof(t) bytes can be on the same instruction */
21696 #define validate_next(t, insn, n) \
21697 @@ -49,8 +54,8 @@
21698 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21699 {
21700 memset(insn, 0, sizeof(*insn));
21701 - insn->kaddr = kaddr;
21702 - insn->next_byte = kaddr;
21703 + insn->kaddr = ktla_ktva(kaddr);
21704 + insn->next_byte = ktla_ktva(kaddr);
21705 insn->x86_64 = x86_64 ? 1 : 0;
21706 insn->opnd_bytes = 4;
21707 if (x86_64)
21708 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21709 index 05a95e7..326f2fa 100644
21710 --- a/arch/x86/lib/iomap_copy_64.S
21711 +++ b/arch/x86/lib/iomap_copy_64.S
21712 @@ -17,6 +17,7 @@
21713
21714 #include <linux/linkage.h>
21715 #include <asm/dwarf2.h>
21716 +#include <asm/alternative-asm.h>
21717
21718 /*
21719 * override generic version in lib/iomap_copy.c
21720 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21721 CFI_STARTPROC
21722 movl %edx,%ecx
21723 rep movsd
21724 + pax_force_retaddr
21725 ret
21726 CFI_ENDPROC
21727 ENDPROC(__iowrite32_copy)
21728 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21729 index efbf2a0..8893637 100644
21730 --- a/arch/x86/lib/memcpy_64.S
21731 +++ b/arch/x86/lib/memcpy_64.S
21732 @@ -34,6 +34,7 @@
21733 rep movsq
21734 movl %edx, %ecx
21735 rep movsb
21736 + pax_force_retaddr
21737 ret
21738 .Lmemcpy_e:
21739 .previous
21740 @@ -51,6 +52,7 @@
21741
21742 movl %edx, %ecx
21743 rep movsb
21744 + pax_force_retaddr
21745 ret
21746 .Lmemcpy_e_e:
21747 .previous
21748 @@ -81,13 +83,13 @@ ENTRY(memcpy)
21749 */
21750 movq 0*8(%rsi), %r8
21751 movq 1*8(%rsi), %r9
21752 - movq 2*8(%rsi), %r10
21753 + movq 2*8(%rsi), %rcx
21754 movq 3*8(%rsi), %r11
21755 leaq 4*8(%rsi), %rsi
21756
21757 movq %r8, 0*8(%rdi)
21758 movq %r9, 1*8(%rdi)
21759 - movq %r10, 2*8(%rdi)
21760 + movq %rcx, 2*8(%rdi)
21761 movq %r11, 3*8(%rdi)
21762 leaq 4*8(%rdi), %rdi
21763 jae .Lcopy_forward_loop
21764 @@ -110,12 +112,12 @@ ENTRY(memcpy)
21765 subq $0x20, %rdx
21766 movq -1*8(%rsi), %r8
21767 movq -2*8(%rsi), %r9
21768 - movq -3*8(%rsi), %r10
21769 + movq -3*8(%rsi), %rcx
21770 movq -4*8(%rsi), %r11
21771 leaq -4*8(%rsi), %rsi
21772 movq %r8, -1*8(%rdi)
21773 movq %r9, -2*8(%rdi)
21774 - movq %r10, -3*8(%rdi)
21775 + movq %rcx, -3*8(%rdi)
21776 movq %r11, -4*8(%rdi)
21777 leaq -4*8(%rdi), %rdi
21778 jae .Lcopy_backward_loop
21779 @@ -135,12 +137,13 @@ ENTRY(memcpy)
21780 */
21781 movq 0*8(%rsi), %r8
21782 movq 1*8(%rsi), %r9
21783 - movq -2*8(%rsi, %rdx), %r10
21784 + movq -2*8(%rsi, %rdx), %rcx
21785 movq -1*8(%rsi, %rdx), %r11
21786 movq %r8, 0*8(%rdi)
21787 movq %r9, 1*8(%rdi)
21788 - movq %r10, -2*8(%rdi, %rdx)
21789 + movq %rcx, -2*8(%rdi, %rdx)
21790 movq %r11, -1*8(%rdi, %rdx)
21791 + pax_force_retaddr
21792 retq
21793 .p2align 4
21794 .Lless_16bytes:
21795 @@ -153,6 +156,7 @@ ENTRY(memcpy)
21796 movq -1*8(%rsi, %rdx), %r9
21797 movq %r8, 0*8(%rdi)
21798 movq %r9, -1*8(%rdi, %rdx)
21799 + pax_force_retaddr
21800 retq
21801 .p2align 4
21802 .Lless_8bytes:
21803 @@ -166,6 +170,7 @@ ENTRY(memcpy)
21804 movl -4(%rsi, %rdx), %r8d
21805 movl %ecx, (%rdi)
21806 movl %r8d, -4(%rdi, %rdx)
21807 + pax_force_retaddr
21808 retq
21809 .p2align 4
21810 .Lless_3bytes:
21811 @@ -183,6 +188,7 @@ ENTRY(memcpy)
21812 jnz .Lloop_1
21813
21814 .Lend:
21815 + pax_force_retaddr
21816 retq
21817 CFI_ENDPROC
21818 ENDPROC(memcpy)
21819 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
21820 index ee16461..c39c199 100644
21821 --- a/arch/x86/lib/memmove_64.S
21822 +++ b/arch/x86/lib/memmove_64.S
21823 @@ -61,13 +61,13 @@ ENTRY(memmove)
21824 5:
21825 sub $0x20, %rdx
21826 movq 0*8(%rsi), %r11
21827 - movq 1*8(%rsi), %r10
21828 + movq 1*8(%rsi), %rcx
21829 movq 2*8(%rsi), %r9
21830 movq 3*8(%rsi), %r8
21831 leaq 4*8(%rsi), %rsi
21832
21833 movq %r11, 0*8(%rdi)
21834 - movq %r10, 1*8(%rdi)
21835 + movq %rcx, 1*8(%rdi)
21836 movq %r9, 2*8(%rdi)
21837 movq %r8, 3*8(%rdi)
21838 leaq 4*8(%rdi), %rdi
21839 @@ -81,10 +81,10 @@ ENTRY(memmove)
21840 4:
21841 movq %rdx, %rcx
21842 movq -8(%rsi, %rdx), %r11
21843 - lea -8(%rdi, %rdx), %r10
21844 + lea -8(%rdi, %rdx), %r9
21845 shrq $3, %rcx
21846 rep movsq
21847 - movq %r11, (%r10)
21848 + movq %r11, (%r9)
21849 jmp 13f
21850 .Lmemmove_end_forward:
21851
21852 @@ -95,14 +95,14 @@ ENTRY(memmove)
21853 7:
21854 movq %rdx, %rcx
21855 movq (%rsi), %r11
21856 - movq %rdi, %r10
21857 + movq %rdi, %r9
21858 leaq -8(%rsi, %rdx), %rsi
21859 leaq -8(%rdi, %rdx), %rdi
21860 shrq $3, %rcx
21861 std
21862 rep movsq
21863 cld
21864 - movq %r11, (%r10)
21865 + movq %r11, (%r9)
21866 jmp 13f
21867
21868 /*
21869 @@ -127,13 +127,13 @@ ENTRY(memmove)
21870 8:
21871 subq $0x20, %rdx
21872 movq -1*8(%rsi), %r11
21873 - movq -2*8(%rsi), %r10
21874 + movq -2*8(%rsi), %rcx
21875 movq -3*8(%rsi), %r9
21876 movq -4*8(%rsi), %r8
21877 leaq -4*8(%rsi), %rsi
21878
21879 movq %r11, -1*8(%rdi)
21880 - movq %r10, -2*8(%rdi)
21881 + movq %rcx, -2*8(%rdi)
21882 movq %r9, -3*8(%rdi)
21883 movq %r8, -4*8(%rdi)
21884 leaq -4*8(%rdi), %rdi
21885 @@ -151,11 +151,11 @@ ENTRY(memmove)
21886 * Move data from 16 bytes to 31 bytes.
21887 */
21888 movq 0*8(%rsi), %r11
21889 - movq 1*8(%rsi), %r10
21890 + movq 1*8(%rsi), %rcx
21891 movq -2*8(%rsi, %rdx), %r9
21892 movq -1*8(%rsi, %rdx), %r8
21893 movq %r11, 0*8(%rdi)
21894 - movq %r10, 1*8(%rdi)
21895 + movq %rcx, 1*8(%rdi)
21896 movq %r9, -2*8(%rdi, %rdx)
21897 movq %r8, -1*8(%rdi, %rdx)
21898 jmp 13f
21899 @@ -167,9 +167,9 @@ ENTRY(memmove)
21900 * Move data from 8 bytes to 15 bytes.
21901 */
21902 movq 0*8(%rsi), %r11
21903 - movq -1*8(%rsi, %rdx), %r10
21904 + movq -1*8(%rsi, %rdx), %r9
21905 movq %r11, 0*8(%rdi)
21906 - movq %r10, -1*8(%rdi, %rdx)
21907 + movq %r9, -1*8(%rdi, %rdx)
21908 jmp 13f
21909 10:
21910 cmpq $4, %rdx
21911 @@ -178,9 +178,9 @@ ENTRY(memmove)
21912 * Move data from 4 bytes to 7 bytes.
21913 */
21914 movl (%rsi), %r11d
21915 - movl -4(%rsi, %rdx), %r10d
21916 + movl -4(%rsi, %rdx), %r9d
21917 movl %r11d, (%rdi)
21918 - movl %r10d, -4(%rdi, %rdx)
21919 + movl %r9d, -4(%rdi, %rdx)
21920 jmp 13f
21921 11:
21922 cmp $2, %rdx
21923 @@ -189,9 +189,9 @@ ENTRY(memmove)
21924 * Move data from 2 bytes to 3 bytes.
21925 */
21926 movw (%rsi), %r11w
21927 - movw -2(%rsi, %rdx), %r10w
21928 + movw -2(%rsi, %rdx), %r9w
21929 movw %r11w, (%rdi)
21930 - movw %r10w, -2(%rdi, %rdx)
21931 + movw %r9w, -2(%rdi, %rdx)
21932 jmp 13f
21933 12:
21934 cmp $1, %rdx
21935 @@ -202,6 +202,7 @@ ENTRY(memmove)
21936 movb (%rsi), %r11b
21937 movb %r11b, (%rdi)
21938 13:
21939 + pax_force_retaddr
21940 retq
21941 CFI_ENDPROC
21942
21943 @@ -210,6 +211,7 @@ ENTRY(memmove)
21944 /* Forward moving data. */
21945 movq %rdx, %rcx
21946 rep movsb
21947 + pax_force_retaddr
21948 retq
21949 .Lmemmove_end_forward_efs:
21950 .previous
21951 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
21952 index 79bd454..dff325a 100644
21953 --- a/arch/x86/lib/memset_64.S
21954 +++ b/arch/x86/lib/memset_64.S
21955 @@ -31,6 +31,7 @@
21956 movl %r8d,%ecx
21957 rep stosb
21958 movq %r9,%rax
21959 + pax_force_retaddr
21960 ret
21961 .Lmemset_e:
21962 .previous
21963 @@ -53,6 +54,7 @@
21964 movl %edx,%ecx
21965 rep stosb
21966 movq %r9,%rax
21967 + pax_force_retaddr
21968 ret
21969 .Lmemset_e_e:
21970 .previous
21971 @@ -60,13 +62,13 @@
21972 ENTRY(memset)
21973 ENTRY(__memset)
21974 CFI_STARTPROC
21975 - movq %rdi,%r10
21976 movq %rdx,%r11
21977
21978 /* expand byte value */
21979 movzbl %sil,%ecx
21980 movabs $0x0101010101010101,%rax
21981 mul %rcx /* with rax, clobbers rdx */
21982 + movq %rdi,%rdx
21983
21984 /* align dst */
21985 movl %edi,%r9d
21986 @@ -120,7 +122,8 @@ ENTRY(__memset)
21987 jnz .Lloop_1
21988
21989 .Lende:
21990 - movq %r10,%rax
21991 + movq %rdx,%rax
21992 + pax_force_retaddr
21993 ret
21994
21995 CFI_RESTORE_STATE
21996 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
21997 index c9f2d9b..e7fd2c0 100644
21998 --- a/arch/x86/lib/mmx_32.c
21999 +++ b/arch/x86/lib/mmx_32.c
22000 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22001 {
22002 void *p;
22003 int i;
22004 + unsigned long cr0;
22005
22006 if (unlikely(in_interrupt()))
22007 return __memcpy(to, from, len);
22008 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22009 kernel_fpu_begin();
22010
22011 __asm__ __volatile__ (
22012 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22013 - " prefetch 64(%0)\n"
22014 - " prefetch 128(%0)\n"
22015 - " prefetch 192(%0)\n"
22016 - " prefetch 256(%0)\n"
22017 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22018 + " prefetch 64(%1)\n"
22019 + " prefetch 128(%1)\n"
22020 + " prefetch 192(%1)\n"
22021 + " prefetch 256(%1)\n"
22022 "2: \n"
22023 ".section .fixup, \"ax\"\n"
22024 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22025 + "3: \n"
22026 +
22027 +#ifdef CONFIG_PAX_KERNEXEC
22028 + " movl %%cr0, %0\n"
22029 + " movl %0, %%eax\n"
22030 + " andl $0xFFFEFFFF, %%eax\n"
22031 + " movl %%eax, %%cr0\n"
22032 +#endif
22033 +
22034 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22035 +
22036 +#ifdef CONFIG_PAX_KERNEXEC
22037 + " movl %0, %%cr0\n"
22038 +#endif
22039 +
22040 " jmp 2b\n"
22041 ".previous\n"
22042 _ASM_EXTABLE(1b, 3b)
22043 - : : "r" (from));
22044 + : "=&r" (cr0) : "r" (from) : "ax");
22045
22046 for ( ; i > 5; i--) {
22047 __asm__ __volatile__ (
22048 - "1: prefetch 320(%0)\n"
22049 - "2: movq (%0), %%mm0\n"
22050 - " movq 8(%0), %%mm1\n"
22051 - " movq 16(%0), %%mm2\n"
22052 - " movq 24(%0), %%mm3\n"
22053 - " movq %%mm0, (%1)\n"
22054 - " movq %%mm1, 8(%1)\n"
22055 - " movq %%mm2, 16(%1)\n"
22056 - " movq %%mm3, 24(%1)\n"
22057 - " movq 32(%0), %%mm0\n"
22058 - " movq 40(%0), %%mm1\n"
22059 - " movq 48(%0), %%mm2\n"
22060 - " movq 56(%0), %%mm3\n"
22061 - " movq %%mm0, 32(%1)\n"
22062 - " movq %%mm1, 40(%1)\n"
22063 - " movq %%mm2, 48(%1)\n"
22064 - " movq %%mm3, 56(%1)\n"
22065 + "1: prefetch 320(%1)\n"
22066 + "2: movq (%1), %%mm0\n"
22067 + " movq 8(%1), %%mm1\n"
22068 + " movq 16(%1), %%mm2\n"
22069 + " movq 24(%1), %%mm3\n"
22070 + " movq %%mm0, (%2)\n"
22071 + " movq %%mm1, 8(%2)\n"
22072 + " movq %%mm2, 16(%2)\n"
22073 + " movq %%mm3, 24(%2)\n"
22074 + " movq 32(%1), %%mm0\n"
22075 + " movq 40(%1), %%mm1\n"
22076 + " movq 48(%1), %%mm2\n"
22077 + " movq 56(%1), %%mm3\n"
22078 + " movq %%mm0, 32(%2)\n"
22079 + " movq %%mm1, 40(%2)\n"
22080 + " movq %%mm2, 48(%2)\n"
22081 + " movq %%mm3, 56(%2)\n"
22082 ".section .fixup, \"ax\"\n"
22083 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22084 + "3:\n"
22085 +
22086 +#ifdef CONFIG_PAX_KERNEXEC
22087 + " movl %%cr0, %0\n"
22088 + " movl %0, %%eax\n"
22089 + " andl $0xFFFEFFFF, %%eax\n"
22090 + " movl %%eax, %%cr0\n"
22091 +#endif
22092 +
22093 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22094 +
22095 +#ifdef CONFIG_PAX_KERNEXEC
22096 + " movl %0, %%cr0\n"
22097 +#endif
22098 +
22099 " jmp 2b\n"
22100 ".previous\n"
22101 _ASM_EXTABLE(1b, 3b)
22102 - : : "r" (from), "r" (to) : "memory");
22103 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22104
22105 from += 64;
22106 to += 64;
22107 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22108 static void fast_copy_page(void *to, void *from)
22109 {
22110 int i;
22111 + unsigned long cr0;
22112
22113 kernel_fpu_begin();
22114
22115 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22116 * but that is for later. -AV
22117 */
22118 __asm__ __volatile__(
22119 - "1: prefetch (%0)\n"
22120 - " prefetch 64(%0)\n"
22121 - " prefetch 128(%0)\n"
22122 - " prefetch 192(%0)\n"
22123 - " prefetch 256(%0)\n"
22124 + "1: prefetch (%1)\n"
22125 + " prefetch 64(%1)\n"
22126 + " prefetch 128(%1)\n"
22127 + " prefetch 192(%1)\n"
22128 + " prefetch 256(%1)\n"
22129 "2: \n"
22130 ".section .fixup, \"ax\"\n"
22131 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22132 + "3: \n"
22133 +
22134 +#ifdef CONFIG_PAX_KERNEXEC
22135 + " movl %%cr0, %0\n"
22136 + " movl %0, %%eax\n"
22137 + " andl $0xFFFEFFFF, %%eax\n"
22138 + " movl %%eax, %%cr0\n"
22139 +#endif
22140 +
22141 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22142 +
22143 +#ifdef CONFIG_PAX_KERNEXEC
22144 + " movl %0, %%cr0\n"
22145 +#endif
22146 +
22147 " jmp 2b\n"
22148 ".previous\n"
22149 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22150 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22151
22152 for (i = 0; i < (4096-320)/64; i++) {
22153 __asm__ __volatile__ (
22154 - "1: prefetch 320(%0)\n"
22155 - "2: movq (%0), %%mm0\n"
22156 - " movntq %%mm0, (%1)\n"
22157 - " movq 8(%0), %%mm1\n"
22158 - " movntq %%mm1, 8(%1)\n"
22159 - " movq 16(%0), %%mm2\n"
22160 - " movntq %%mm2, 16(%1)\n"
22161 - " movq 24(%0), %%mm3\n"
22162 - " movntq %%mm3, 24(%1)\n"
22163 - " movq 32(%0), %%mm4\n"
22164 - " movntq %%mm4, 32(%1)\n"
22165 - " movq 40(%0), %%mm5\n"
22166 - " movntq %%mm5, 40(%1)\n"
22167 - " movq 48(%0), %%mm6\n"
22168 - " movntq %%mm6, 48(%1)\n"
22169 - " movq 56(%0), %%mm7\n"
22170 - " movntq %%mm7, 56(%1)\n"
22171 + "1: prefetch 320(%1)\n"
22172 + "2: movq (%1), %%mm0\n"
22173 + " movntq %%mm0, (%2)\n"
22174 + " movq 8(%1), %%mm1\n"
22175 + " movntq %%mm1, 8(%2)\n"
22176 + " movq 16(%1), %%mm2\n"
22177 + " movntq %%mm2, 16(%2)\n"
22178 + " movq 24(%1), %%mm3\n"
22179 + " movntq %%mm3, 24(%2)\n"
22180 + " movq 32(%1), %%mm4\n"
22181 + " movntq %%mm4, 32(%2)\n"
22182 + " movq 40(%1), %%mm5\n"
22183 + " movntq %%mm5, 40(%2)\n"
22184 + " movq 48(%1), %%mm6\n"
22185 + " movntq %%mm6, 48(%2)\n"
22186 + " movq 56(%1), %%mm7\n"
22187 + " movntq %%mm7, 56(%2)\n"
22188 ".section .fixup, \"ax\"\n"
22189 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22190 + "3:\n"
22191 +
22192 +#ifdef CONFIG_PAX_KERNEXEC
22193 + " movl %%cr0, %0\n"
22194 + " movl %0, %%eax\n"
22195 + " andl $0xFFFEFFFF, %%eax\n"
22196 + " movl %%eax, %%cr0\n"
22197 +#endif
22198 +
22199 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22200 +
22201 +#ifdef CONFIG_PAX_KERNEXEC
22202 + " movl %0, %%cr0\n"
22203 +#endif
22204 +
22205 " jmp 2b\n"
22206 ".previous\n"
22207 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22208 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22209
22210 from += 64;
22211 to += 64;
22212 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22213 static void fast_copy_page(void *to, void *from)
22214 {
22215 int i;
22216 + unsigned long cr0;
22217
22218 kernel_fpu_begin();
22219
22220 __asm__ __volatile__ (
22221 - "1: prefetch (%0)\n"
22222 - " prefetch 64(%0)\n"
22223 - " prefetch 128(%0)\n"
22224 - " prefetch 192(%0)\n"
22225 - " prefetch 256(%0)\n"
22226 + "1: prefetch (%1)\n"
22227 + " prefetch 64(%1)\n"
22228 + " prefetch 128(%1)\n"
22229 + " prefetch 192(%1)\n"
22230 + " prefetch 256(%1)\n"
22231 "2: \n"
22232 ".section .fixup, \"ax\"\n"
22233 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22234 + "3: \n"
22235 +
22236 +#ifdef CONFIG_PAX_KERNEXEC
22237 + " movl %%cr0, %0\n"
22238 + " movl %0, %%eax\n"
22239 + " andl $0xFFFEFFFF, %%eax\n"
22240 + " movl %%eax, %%cr0\n"
22241 +#endif
22242 +
22243 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22244 +
22245 +#ifdef CONFIG_PAX_KERNEXEC
22246 + " movl %0, %%cr0\n"
22247 +#endif
22248 +
22249 " jmp 2b\n"
22250 ".previous\n"
22251 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22252 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22253
22254 for (i = 0; i < 4096/64; i++) {
22255 __asm__ __volatile__ (
22256 - "1: prefetch 320(%0)\n"
22257 - "2: movq (%0), %%mm0\n"
22258 - " movq 8(%0), %%mm1\n"
22259 - " movq 16(%0), %%mm2\n"
22260 - " movq 24(%0), %%mm3\n"
22261 - " movq %%mm0, (%1)\n"
22262 - " movq %%mm1, 8(%1)\n"
22263 - " movq %%mm2, 16(%1)\n"
22264 - " movq %%mm3, 24(%1)\n"
22265 - " movq 32(%0), %%mm0\n"
22266 - " movq 40(%0), %%mm1\n"
22267 - " movq 48(%0), %%mm2\n"
22268 - " movq 56(%0), %%mm3\n"
22269 - " movq %%mm0, 32(%1)\n"
22270 - " movq %%mm1, 40(%1)\n"
22271 - " movq %%mm2, 48(%1)\n"
22272 - " movq %%mm3, 56(%1)\n"
22273 + "1: prefetch 320(%1)\n"
22274 + "2: movq (%1), %%mm0\n"
22275 + " movq 8(%1), %%mm1\n"
22276 + " movq 16(%1), %%mm2\n"
22277 + " movq 24(%1), %%mm3\n"
22278 + " movq %%mm0, (%2)\n"
22279 + " movq %%mm1, 8(%2)\n"
22280 + " movq %%mm2, 16(%2)\n"
22281 + " movq %%mm3, 24(%2)\n"
22282 + " movq 32(%1), %%mm0\n"
22283 + " movq 40(%1), %%mm1\n"
22284 + " movq 48(%1), %%mm2\n"
22285 + " movq 56(%1), %%mm3\n"
22286 + " movq %%mm0, 32(%2)\n"
22287 + " movq %%mm1, 40(%2)\n"
22288 + " movq %%mm2, 48(%2)\n"
22289 + " movq %%mm3, 56(%2)\n"
22290 ".section .fixup, \"ax\"\n"
22291 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22292 + "3:\n"
22293 +
22294 +#ifdef CONFIG_PAX_KERNEXEC
22295 + " movl %%cr0, %0\n"
22296 + " movl %0, %%eax\n"
22297 + " andl $0xFFFEFFFF, %%eax\n"
22298 + " movl %%eax, %%cr0\n"
22299 +#endif
22300 +
22301 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22302 +
22303 +#ifdef CONFIG_PAX_KERNEXEC
22304 + " movl %0, %%cr0\n"
22305 +#endif
22306 +
22307 " jmp 2b\n"
22308 ".previous\n"
22309 _ASM_EXTABLE(1b, 3b)
22310 - : : "r" (from), "r" (to) : "memory");
22311 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22312
22313 from += 64;
22314 to += 64;
22315 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22316 index 69fa106..adda88b 100644
22317 --- a/arch/x86/lib/msr-reg.S
22318 +++ b/arch/x86/lib/msr-reg.S
22319 @@ -3,6 +3,7 @@
22320 #include <asm/dwarf2.h>
22321 #include <asm/asm.h>
22322 #include <asm/msr.h>
22323 +#include <asm/alternative-asm.h>
22324
22325 #ifdef CONFIG_X86_64
22326 /*
22327 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22328 CFI_STARTPROC
22329 pushq_cfi %rbx
22330 pushq_cfi %rbp
22331 - movq %rdi, %r10 /* Save pointer */
22332 + movq %rdi, %r9 /* Save pointer */
22333 xorl %r11d, %r11d /* Return value */
22334 movl (%rdi), %eax
22335 movl 4(%rdi), %ecx
22336 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22337 movl 28(%rdi), %edi
22338 CFI_REMEMBER_STATE
22339 1: \op
22340 -2: movl %eax, (%r10)
22341 +2: movl %eax, (%r9)
22342 movl %r11d, %eax /* Return value */
22343 - movl %ecx, 4(%r10)
22344 - movl %edx, 8(%r10)
22345 - movl %ebx, 12(%r10)
22346 - movl %ebp, 20(%r10)
22347 - movl %esi, 24(%r10)
22348 - movl %edi, 28(%r10)
22349 + movl %ecx, 4(%r9)
22350 + movl %edx, 8(%r9)
22351 + movl %ebx, 12(%r9)
22352 + movl %ebp, 20(%r9)
22353 + movl %esi, 24(%r9)
22354 + movl %edi, 28(%r9)
22355 popq_cfi %rbp
22356 popq_cfi %rbx
22357 + pax_force_retaddr
22358 ret
22359 3:
22360 CFI_RESTORE_STATE
22361 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22362 index 36b0d15..d381858 100644
22363 --- a/arch/x86/lib/putuser.S
22364 +++ b/arch/x86/lib/putuser.S
22365 @@ -15,7 +15,9 @@
22366 #include <asm/thread_info.h>
22367 #include <asm/errno.h>
22368 #include <asm/asm.h>
22369 -
22370 +#include <asm/segment.h>
22371 +#include <asm/pgtable.h>
22372 +#include <asm/alternative-asm.h>
22373
22374 /*
22375 * __put_user_X
22376 @@ -29,52 +31,119 @@
22377 * as they get called from within inline assembly.
22378 */
22379
22380 -#define ENTER CFI_STARTPROC ; \
22381 - GET_THREAD_INFO(%_ASM_BX)
22382 -#define EXIT ret ; \
22383 +#define ENTER CFI_STARTPROC
22384 +#define EXIT pax_force_retaddr; ret ; \
22385 CFI_ENDPROC
22386
22387 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22388 +#define _DEST %_ASM_CX,%_ASM_BX
22389 +#else
22390 +#define _DEST %_ASM_CX
22391 +#endif
22392 +
22393 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22394 +#define __copyuser_seg gs;
22395 +#else
22396 +#define __copyuser_seg
22397 +#endif
22398 +
22399 .text
22400 ENTRY(__put_user_1)
22401 ENTER
22402 +
22403 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22404 + GET_THREAD_INFO(%_ASM_BX)
22405 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22406 jae bad_put_user
22407 -1: movb %al,(%_ASM_CX)
22408 +
22409 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22410 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22411 + cmp %_ASM_BX,%_ASM_CX
22412 + jb 1234f
22413 + xor %ebx,%ebx
22414 +1234:
22415 +#endif
22416 +
22417 +#endif
22418 +
22419 +1: __copyuser_seg movb %al,(_DEST)
22420 xor %eax,%eax
22421 EXIT
22422 ENDPROC(__put_user_1)
22423
22424 ENTRY(__put_user_2)
22425 ENTER
22426 +
22427 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22428 + GET_THREAD_INFO(%_ASM_BX)
22429 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22430 sub $1,%_ASM_BX
22431 cmp %_ASM_BX,%_ASM_CX
22432 jae bad_put_user
22433 -2: movw %ax,(%_ASM_CX)
22434 +
22435 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22436 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22437 + cmp %_ASM_BX,%_ASM_CX
22438 + jb 1234f
22439 + xor %ebx,%ebx
22440 +1234:
22441 +#endif
22442 +
22443 +#endif
22444 +
22445 +2: __copyuser_seg movw %ax,(_DEST)
22446 xor %eax,%eax
22447 EXIT
22448 ENDPROC(__put_user_2)
22449
22450 ENTRY(__put_user_4)
22451 ENTER
22452 +
22453 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22454 + GET_THREAD_INFO(%_ASM_BX)
22455 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22456 sub $3,%_ASM_BX
22457 cmp %_ASM_BX,%_ASM_CX
22458 jae bad_put_user
22459 -3: movl %eax,(%_ASM_CX)
22460 +
22461 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22462 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22463 + cmp %_ASM_BX,%_ASM_CX
22464 + jb 1234f
22465 + xor %ebx,%ebx
22466 +1234:
22467 +#endif
22468 +
22469 +#endif
22470 +
22471 +3: __copyuser_seg movl %eax,(_DEST)
22472 xor %eax,%eax
22473 EXIT
22474 ENDPROC(__put_user_4)
22475
22476 ENTRY(__put_user_8)
22477 ENTER
22478 +
22479 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22480 + GET_THREAD_INFO(%_ASM_BX)
22481 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22482 sub $7,%_ASM_BX
22483 cmp %_ASM_BX,%_ASM_CX
22484 jae bad_put_user
22485 -4: mov %_ASM_AX,(%_ASM_CX)
22486 +
22487 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22488 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22489 + cmp %_ASM_BX,%_ASM_CX
22490 + jb 1234f
22491 + xor %ebx,%ebx
22492 +1234:
22493 +#endif
22494 +
22495 +#endif
22496 +
22497 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22498 #ifdef CONFIG_X86_32
22499 -5: movl %edx,4(%_ASM_CX)
22500 +5: __copyuser_seg movl %edx,4(_DEST)
22501 #endif
22502 xor %eax,%eax
22503 EXIT
22504 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22505 index 1cad221..de671ee 100644
22506 --- a/arch/x86/lib/rwlock.S
22507 +++ b/arch/x86/lib/rwlock.S
22508 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22509 FRAME
22510 0: LOCK_PREFIX
22511 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22512 +
22513 +#ifdef CONFIG_PAX_REFCOUNT
22514 + jno 1234f
22515 + LOCK_PREFIX
22516 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22517 + int $4
22518 +1234:
22519 + _ASM_EXTABLE(1234b, 1234b)
22520 +#endif
22521 +
22522 1: rep; nop
22523 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22524 jne 1b
22525 LOCK_PREFIX
22526 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22527 +
22528 +#ifdef CONFIG_PAX_REFCOUNT
22529 + jno 1234f
22530 + LOCK_PREFIX
22531 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22532 + int $4
22533 +1234:
22534 + _ASM_EXTABLE(1234b, 1234b)
22535 +#endif
22536 +
22537 jnz 0b
22538 ENDFRAME
22539 + pax_force_retaddr
22540 ret
22541 CFI_ENDPROC
22542 END(__write_lock_failed)
22543 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22544 FRAME
22545 0: LOCK_PREFIX
22546 READ_LOCK_SIZE(inc) (%__lock_ptr)
22547 +
22548 +#ifdef CONFIG_PAX_REFCOUNT
22549 + jno 1234f
22550 + LOCK_PREFIX
22551 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22552 + int $4
22553 +1234:
22554 + _ASM_EXTABLE(1234b, 1234b)
22555 +#endif
22556 +
22557 1: rep; nop
22558 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22559 js 1b
22560 LOCK_PREFIX
22561 READ_LOCK_SIZE(dec) (%__lock_ptr)
22562 +
22563 +#ifdef CONFIG_PAX_REFCOUNT
22564 + jno 1234f
22565 + LOCK_PREFIX
22566 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22567 + int $4
22568 +1234:
22569 + _ASM_EXTABLE(1234b, 1234b)
22570 +#endif
22571 +
22572 js 0b
22573 ENDFRAME
22574 + pax_force_retaddr
22575 ret
22576 CFI_ENDPROC
22577 END(__read_lock_failed)
22578 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22579 index 5dff5f0..cadebf4 100644
22580 --- a/arch/x86/lib/rwsem.S
22581 +++ b/arch/x86/lib/rwsem.S
22582 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22583 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22584 CFI_RESTORE __ASM_REG(dx)
22585 restore_common_regs
22586 + pax_force_retaddr
22587 ret
22588 CFI_ENDPROC
22589 ENDPROC(call_rwsem_down_read_failed)
22590 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22591 movq %rax,%rdi
22592 call rwsem_down_write_failed
22593 restore_common_regs
22594 + pax_force_retaddr
22595 ret
22596 CFI_ENDPROC
22597 ENDPROC(call_rwsem_down_write_failed)
22598 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22599 movq %rax,%rdi
22600 call rwsem_wake
22601 restore_common_regs
22602 -1: ret
22603 +1: pax_force_retaddr
22604 + ret
22605 CFI_ENDPROC
22606 ENDPROC(call_rwsem_wake)
22607
22608 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22609 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22610 CFI_RESTORE __ASM_REG(dx)
22611 restore_common_regs
22612 + pax_force_retaddr
22613 ret
22614 CFI_ENDPROC
22615 ENDPROC(call_rwsem_downgrade_wake)
22616 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22617 index a63efd6..ccecad8 100644
22618 --- a/arch/x86/lib/thunk_64.S
22619 +++ b/arch/x86/lib/thunk_64.S
22620 @@ -8,6 +8,7 @@
22621 #include <linux/linkage.h>
22622 #include <asm/dwarf2.h>
22623 #include <asm/calling.h>
22624 +#include <asm/alternative-asm.h>
22625
22626 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22627 .macro THUNK name, func, put_ret_addr_in_rdi=0
22628 @@ -41,5 +42,6 @@
22629 SAVE_ARGS
22630 restore:
22631 RESTORE_ARGS
22632 + pax_force_retaddr
22633 ret
22634 CFI_ENDPROC
22635 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22636 index e218d5d..1e01930 100644
22637 --- a/arch/x86/lib/usercopy_32.c
22638 +++ b/arch/x86/lib/usercopy_32.c
22639 @@ -43,7 +43,7 @@ do { \
22640 __asm__ __volatile__( \
22641 " testl %1,%1\n" \
22642 " jz 2f\n" \
22643 - "0: lodsb\n" \
22644 + "0: "__copyuser_seg"lodsb\n" \
22645 " stosb\n" \
22646 " testb %%al,%%al\n" \
22647 " jz 1f\n" \
22648 @@ -83,7 +83,7 @@ do { \
22649 * and returns @count.
22650 */
22651 long
22652 -__strncpy_from_user(char *dst, const char __user *src, long count)
22653 +__strncpy_from_user(char *dst, const char __user *src, unsigned long count)
22654 {
22655 long res;
22656 __do_strncpy_from_user(dst, src, count, res);
22657 @@ -110,7 +110,7 @@ EXPORT_SYMBOL(__strncpy_from_user);
22658 * and returns @count.
22659 */
22660 long
22661 -strncpy_from_user(char *dst, const char __user *src, long count)
22662 +strncpy_from_user(char *dst, const char __user *src, unsigned long count)
22663 {
22664 long res = -EFAULT;
22665 if (access_ok(VERIFY_READ, src, 1))
22666 @@ -128,10 +128,12 @@ do { \
22667 int __d0; \
22668 might_fault(); \
22669 __asm__ __volatile__( \
22670 + __COPYUSER_SET_ES \
22671 "0: rep; stosl\n" \
22672 " movl %2,%0\n" \
22673 "1: rep; stosb\n" \
22674 "2:\n" \
22675 + __COPYUSER_RESTORE_ES \
22676 ".section .fixup,\"ax\"\n" \
22677 "3: lea 0(%2,%0,4),%0\n" \
22678 " jmp 2b\n" \
22679 @@ -192,7 +194,7 @@ EXPORT_SYMBOL(__clear_user);
22680 * On exception, returns 0.
22681 * If the string is too long, returns a value greater than @n.
22682 */
22683 -long strnlen_user(const char __user *s, long n)
22684 +long strnlen_user(const char __user *s, unsigned long n)
22685 {
22686 unsigned long mask = -__addr_ok(s);
22687 unsigned long res, tmp;
22688 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
22689 might_fault();
22690
22691 __asm__ __volatile__(
22692 + __COPYUSER_SET_ES
22693 " testl %0, %0\n"
22694 " jz 3f\n"
22695 " andl %0,%%ecx\n"
22696 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
22697 " subl %%ecx,%0\n"
22698 " addl %0,%%eax\n"
22699 "1:\n"
22700 + __COPYUSER_RESTORE_ES
22701 ".section .fixup,\"ax\"\n"
22702 "2: xorl %%eax,%%eax\n"
22703 " jmp 1b\n"
22704 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
22705
22706 #ifdef CONFIG_X86_INTEL_USERCOPY
22707 static unsigned long
22708 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22709 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22710 {
22711 int d0, d1;
22712 __asm__ __volatile__(
22713 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22714 " .align 2,0x90\n"
22715 "3: movl 0(%4), %%eax\n"
22716 "4: movl 4(%4), %%edx\n"
22717 - "5: movl %%eax, 0(%3)\n"
22718 - "6: movl %%edx, 4(%3)\n"
22719 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22720 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22721 "7: movl 8(%4), %%eax\n"
22722 "8: movl 12(%4),%%edx\n"
22723 - "9: movl %%eax, 8(%3)\n"
22724 - "10: movl %%edx, 12(%3)\n"
22725 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22726 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22727 "11: movl 16(%4), %%eax\n"
22728 "12: movl 20(%4), %%edx\n"
22729 - "13: movl %%eax, 16(%3)\n"
22730 - "14: movl %%edx, 20(%3)\n"
22731 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22732 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22733 "15: movl 24(%4), %%eax\n"
22734 "16: movl 28(%4), %%edx\n"
22735 - "17: movl %%eax, 24(%3)\n"
22736 - "18: movl %%edx, 28(%3)\n"
22737 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22738 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22739 "19: movl 32(%4), %%eax\n"
22740 "20: movl 36(%4), %%edx\n"
22741 - "21: movl %%eax, 32(%3)\n"
22742 - "22: movl %%edx, 36(%3)\n"
22743 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22744 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22745 "23: movl 40(%4), %%eax\n"
22746 "24: movl 44(%4), %%edx\n"
22747 - "25: movl %%eax, 40(%3)\n"
22748 - "26: movl %%edx, 44(%3)\n"
22749 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22750 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22751 "27: movl 48(%4), %%eax\n"
22752 "28: movl 52(%4), %%edx\n"
22753 - "29: movl %%eax, 48(%3)\n"
22754 - "30: movl %%edx, 52(%3)\n"
22755 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22756 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22757 "31: movl 56(%4), %%eax\n"
22758 "32: movl 60(%4), %%edx\n"
22759 - "33: movl %%eax, 56(%3)\n"
22760 - "34: movl %%edx, 60(%3)\n"
22761 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22762 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22763 " addl $-64, %0\n"
22764 " addl $64, %4\n"
22765 " addl $64, %3\n"
22766 @@ -278,10 +282,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22767 " shrl $2, %0\n"
22768 " andl $3, %%eax\n"
22769 " cld\n"
22770 + __COPYUSER_SET_ES
22771 "99: rep; movsl\n"
22772 "36: movl %%eax, %0\n"
22773 "37: rep; movsb\n"
22774 "100:\n"
22775 + __COPYUSER_RESTORE_ES
22776 ".section .fixup,\"ax\"\n"
22777 "101: lea 0(%%eax,%0,4),%0\n"
22778 " jmp 100b\n"
22779 @@ -334,46 +340,155 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22780 }
22781
22782 static unsigned long
22783 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22784 +{
22785 + int d0, d1;
22786 + __asm__ __volatile__(
22787 + " .align 2,0x90\n"
22788 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22789 + " cmpl $67, %0\n"
22790 + " jbe 3f\n"
22791 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22792 + " .align 2,0x90\n"
22793 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22794 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22795 + "5: movl %%eax, 0(%3)\n"
22796 + "6: movl %%edx, 4(%3)\n"
22797 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22798 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22799 + "9: movl %%eax, 8(%3)\n"
22800 + "10: movl %%edx, 12(%3)\n"
22801 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22802 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22803 + "13: movl %%eax, 16(%3)\n"
22804 + "14: movl %%edx, 20(%3)\n"
22805 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22806 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22807 + "17: movl %%eax, 24(%3)\n"
22808 + "18: movl %%edx, 28(%3)\n"
22809 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22810 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22811 + "21: movl %%eax, 32(%3)\n"
22812 + "22: movl %%edx, 36(%3)\n"
22813 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22814 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22815 + "25: movl %%eax, 40(%3)\n"
22816 + "26: movl %%edx, 44(%3)\n"
22817 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22818 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22819 + "29: movl %%eax, 48(%3)\n"
22820 + "30: movl %%edx, 52(%3)\n"
22821 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22822 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22823 + "33: movl %%eax, 56(%3)\n"
22824 + "34: movl %%edx, 60(%3)\n"
22825 + " addl $-64, %0\n"
22826 + " addl $64, %4\n"
22827 + " addl $64, %3\n"
22828 + " cmpl $63, %0\n"
22829 + " ja 1b\n"
22830 + "35: movl %0, %%eax\n"
22831 + " shrl $2, %0\n"
22832 + " andl $3, %%eax\n"
22833 + " cld\n"
22834 + "99: rep; "__copyuser_seg" movsl\n"
22835 + "36: movl %%eax, %0\n"
22836 + "37: rep; "__copyuser_seg" movsb\n"
22837 + "100:\n"
22838 + ".section .fixup,\"ax\"\n"
22839 + "101: lea 0(%%eax,%0,4),%0\n"
22840 + " jmp 100b\n"
22841 + ".previous\n"
22842 + ".section __ex_table,\"a\"\n"
22843 + " .align 4\n"
22844 + " .long 1b,100b\n"
22845 + " .long 2b,100b\n"
22846 + " .long 3b,100b\n"
22847 + " .long 4b,100b\n"
22848 + " .long 5b,100b\n"
22849 + " .long 6b,100b\n"
22850 + " .long 7b,100b\n"
22851 + " .long 8b,100b\n"
22852 + " .long 9b,100b\n"
22853 + " .long 10b,100b\n"
22854 + " .long 11b,100b\n"
22855 + " .long 12b,100b\n"
22856 + " .long 13b,100b\n"
22857 + " .long 14b,100b\n"
22858 + " .long 15b,100b\n"
22859 + " .long 16b,100b\n"
22860 + " .long 17b,100b\n"
22861 + " .long 18b,100b\n"
22862 + " .long 19b,100b\n"
22863 + " .long 20b,100b\n"
22864 + " .long 21b,100b\n"
22865 + " .long 22b,100b\n"
22866 + " .long 23b,100b\n"
22867 + " .long 24b,100b\n"
22868 + " .long 25b,100b\n"
22869 + " .long 26b,100b\n"
22870 + " .long 27b,100b\n"
22871 + " .long 28b,100b\n"
22872 + " .long 29b,100b\n"
22873 + " .long 30b,100b\n"
22874 + " .long 31b,100b\n"
22875 + " .long 32b,100b\n"
22876 + " .long 33b,100b\n"
22877 + " .long 34b,100b\n"
22878 + " .long 35b,100b\n"
22879 + " .long 36b,100b\n"
22880 + " .long 37b,100b\n"
22881 + " .long 99b,101b\n"
22882 + ".previous"
22883 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
22884 + : "1"(to), "2"(from), "0"(size)
22885 + : "eax", "edx", "memory");
22886 + return size;
22887 +}
22888 +
22889 +static unsigned long
22890 +__copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size) __size_overflow(3);
22891 +static unsigned long
22892 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22893 {
22894 int d0, d1;
22895 __asm__ __volatile__(
22896 " .align 2,0x90\n"
22897 - "0: movl 32(%4), %%eax\n"
22898 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22899 " cmpl $67, %0\n"
22900 " jbe 2f\n"
22901 - "1: movl 64(%4), %%eax\n"
22902 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22903 " .align 2,0x90\n"
22904 - "2: movl 0(%4), %%eax\n"
22905 - "21: movl 4(%4), %%edx\n"
22906 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22907 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22908 " movl %%eax, 0(%3)\n"
22909 " movl %%edx, 4(%3)\n"
22910 - "3: movl 8(%4), %%eax\n"
22911 - "31: movl 12(%4),%%edx\n"
22912 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22913 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22914 " movl %%eax, 8(%3)\n"
22915 " movl %%edx, 12(%3)\n"
22916 - "4: movl 16(%4), %%eax\n"
22917 - "41: movl 20(%4), %%edx\n"
22918 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22919 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22920 " movl %%eax, 16(%3)\n"
22921 " movl %%edx, 20(%3)\n"
22922 - "10: movl 24(%4), %%eax\n"
22923 - "51: movl 28(%4), %%edx\n"
22924 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22925 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22926 " movl %%eax, 24(%3)\n"
22927 " movl %%edx, 28(%3)\n"
22928 - "11: movl 32(%4), %%eax\n"
22929 - "61: movl 36(%4), %%edx\n"
22930 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22931 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22932 " movl %%eax, 32(%3)\n"
22933 " movl %%edx, 36(%3)\n"
22934 - "12: movl 40(%4), %%eax\n"
22935 - "71: movl 44(%4), %%edx\n"
22936 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22937 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22938 " movl %%eax, 40(%3)\n"
22939 " movl %%edx, 44(%3)\n"
22940 - "13: movl 48(%4), %%eax\n"
22941 - "81: movl 52(%4), %%edx\n"
22942 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22943 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22944 " movl %%eax, 48(%3)\n"
22945 " movl %%edx, 52(%3)\n"
22946 - "14: movl 56(%4), %%eax\n"
22947 - "91: movl 60(%4), %%edx\n"
22948 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22949 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22950 " movl %%eax, 56(%3)\n"
22951 " movl %%edx, 60(%3)\n"
22952 " addl $-64, %0\n"
22953 @@ -385,9 +500,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22954 " shrl $2, %0\n"
22955 " andl $3, %%eax\n"
22956 " cld\n"
22957 - "6: rep; movsl\n"
22958 + "6: rep; "__copyuser_seg" movsl\n"
22959 " movl %%eax,%0\n"
22960 - "7: rep; movsb\n"
22961 + "7: rep; "__copyuser_seg" movsb\n"
22962 "8:\n"
22963 ".section .fixup,\"ax\"\n"
22964 "9: lea 0(%%eax,%0,4),%0\n"
22965 @@ -434,47 +549,49 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22966 */
22967
22968 static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22969 + const void __user *from, unsigned long size) __size_overflow(3);
22970 +static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22971 const void __user *from, unsigned long size)
22972 {
22973 int d0, d1;
22974
22975 __asm__ __volatile__(
22976 " .align 2,0x90\n"
22977 - "0: movl 32(%4), %%eax\n"
22978 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22979 " cmpl $67, %0\n"
22980 " jbe 2f\n"
22981 - "1: movl 64(%4), %%eax\n"
22982 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22983 " .align 2,0x90\n"
22984 - "2: movl 0(%4), %%eax\n"
22985 - "21: movl 4(%4), %%edx\n"
22986 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22987 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22988 " movnti %%eax, 0(%3)\n"
22989 " movnti %%edx, 4(%3)\n"
22990 - "3: movl 8(%4), %%eax\n"
22991 - "31: movl 12(%4),%%edx\n"
22992 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22993 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22994 " movnti %%eax, 8(%3)\n"
22995 " movnti %%edx, 12(%3)\n"
22996 - "4: movl 16(%4), %%eax\n"
22997 - "41: movl 20(%4), %%edx\n"
22998 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22999 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23000 " movnti %%eax, 16(%3)\n"
23001 " movnti %%edx, 20(%3)\n"
23002 - "10: movl 24(%4), %%eax\n"
23003 - "51: movl 28(%4), %%edx\n"
23004 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23005 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23006 " movnti %%eax, 24(%3)\n"
23007 " movnti %%edx, 28(%3)\n"
23008 - "11: movl 32(%4), %%eax\n"
23009 - "61: movl 36(%4), %%edx\n"
23010 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23011 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23012 " movnti %%eax, 32(%3)\n"
23013 " movnti %%edx, 36(%3)\n"
23014 - "12: movl 40(%4), %%eax\n"
23015 - "71: movl 44(%4), %%edx\n"
23016 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23017 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23018 " movnti %%eax, 40(%3)\n"
23019 " movnti %%edx, 44(%3)\n"
23020 - "13: movl 48(%4), %%eax\n"
23021 - "81: movl 52(%4), %%edx\n"
23022 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23023 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23024 " movnti %%eax, 48(%3)\n"
23025 " movnti %%edx, 52(%3)\n"
23026 - "14: movl 56(%4), %%eax\n"
23027 - "91: movl 60(%4), %%edx\n"
23028 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23029 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23030 " movnti %%eax, 56(%3)\n"
23031 " movnti %%edx, 60(%3)\n"
23032 " addl $-64, %0\n"
23033 @@ -487,9 +604,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23034 " shrl $2, %0\n"
23035 " andl $3, %%eax\n"
23036 " cld\n"
23037 - "6: rep; movsl\n"
23038 + "6: rep; "__copyuser_seg" movsl\n"
23039 " movl %%eax,%0\n"
23040 - "7: rep; movsb\n"
23041 + "7: rep; "__copyuser_seg" movsb\n"
23042 "8:\n"
23043 ".section .fixup,\"ax\"\n"
23044 "9: lea 0(%%eax,%0,4),%0\n"
23045 @@ -531,47 +648,49 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23046 }
23047
23048 static unsigned long __copy_user_intel_nocache(void *to,
23049 + const void __user *from, unsigned long size) __size_overflow(3);
23050 +static unsigned long __copy_user_intel_nocache(void *to,
23051 const void __user *from, unsigned long size)
23052 {
23053 int d0, d1;
23054
23055 __asm__ __volatile__(
23056 " .align 2,0x90\n"
23057 - "0: movl 32(%4), %%eax\n"
23058 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23059 " cmpl $67, %0\n"
23060 " jbe 2f\n"
23061 - "1: movl 64(%4), %%eax\n"
23062 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23063 " .align 2,0x90\n"
23064 - "2: movl 0(%4), %%eax\n"
23065 - "21: movl 4(%4), %%edx\n"
23066 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23067 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23068 " movnti %%eax, 0(%3)\n"
23069 " movnti %%edx, 4(%3)\n"
23070 - "3: movl 8(%4), %%eax\n"
23071 - "31: movl 12(%4),%%edx\n"
23072 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23073 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23074 " movnti %%eax, 8(%3)\n"
23075 " movnti %%edx, 12(%3)\n"
23076 - "4: movl 16(%4), %%eax\n"
23077 - "41: movl 20(%4), %%edx\n"
23078 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23079 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23080 " movnti %%eax, 16(%3)\n"
23081 " movnti %%edx, 20(%3)\n"
23082 - "10: movl 24(%4), %%eax\n"
23083 - "51: movl 28(%4), %%edx\n"
23084 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23085 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23086 " movnti %%eax, 24(%3)\n"
23087 " movnti %%edx, 28(%3)\n"
23088 - "11: movl 32(%4), %%eax\n"
23089 - "61: movl 36(%4), %%edx\n"
23090 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23091 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23092 " movnti %%eax, 32(%3)\n"
23093 " movnti %%edx, 36(%3)\n"
23094 - "12: movl 40(%4), %%eax\n"
23095 - "71: movl 44(%4), %%edx\n"
23096 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23097 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23098 " movnti %%eax, 40(%3)\n"
23099 " movnti %%edx, 44(%3)\n"
23100 - "13: movl 48(%4), %%eax\n"
23101 - "81: movl 52(%4), %%edx\n"
23102 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23103 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23104 " movnti %%eax, 48(%3)\n"
23105 " movnti %%edx, 52(%3)\n"
23106 - "14: movl 56(%4), %%eax\n"
23107 - "91: movl 60(%4), %%edx\n"
23108 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23109 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23110 " movnti %%eax, 56(%3)\n"
23111 " movnti %%edx, 60(%3)\n"
23112 " addl $-64, %0\n"
23113 @@ -584,9 +703,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23114 " shrl $2, %0\n"
23115 " andl $3, %%eax\n"
23116 " cld\n"
23117 - "6: rep; movsl\n"
23118 + "6: rep; "__copyuser_seg" movsl\n"
23119 " movl %%eax,%0\n"
23120 - "7: rep; movsb\n"
23121 + "7: rep; "__copyuser_seg" movsb\n"
23122 "8:\n"
23123 ".section .fixup,\"ax\"\n"
23124 "9: lea 0(%%eax,%0,4),%0\n"
23125 @@ -629,32 +748,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23126 */
23127 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23128 unsigned long size);
23129 -unsigned long __copy_user_intel(void __user *to, const void *from,
23130 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23131 + unsigned long size);
23132 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23133 unsigned long size);
23134 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23135 const void __user *from, unsigned long size);
23136 #endif /* CONFIG_X86_INTEL_USERCOPY */
23137
23138 /* Generic arbitrary sized copy. */
23139 -#define __copy_user(to, from, size) \
23140 +#define __copy_user(to, from, size, prefix, set, restore) \
23141 do { \
23142 int __d0, __d1, __d2; \
23143 __asm__ __volatile__( \
23144 + set \
23145 " cmp $7,%0\n" \
23146 " jbe 1f\n" \
23147 " movl %1,%0\n" \
23148 " negl %0\n" \
23149 " andl $7,%0\n" \
23150 " subl %0,%3\n" \
23151 - "4: rep; movsb\n" \
23152 + "4: rep; "prefix"movsb\n" \
23153 " movl %3,%0\n" \
23154 " shrl $2,%0\n" \
23155 " andl $3,%3\n" \
23156 " .align 2,0x90\n" \
23157 - "0: rep; movsl\n" \
23158 + "0: rep; "prefix"movsl\n" \
23159 " movl %3,%0\n" \
23160 - "1: rep; movsb\n" \
23161 + "1: rep; "prefix"movsb\n" \
23162 "2:\n" \
23163 + restore \
23164 ".section .fixup,\"ax\"\n" \
23165 "5: addl %3,%0\n" \
23166 " jmp 2b\n" \
23167 @@ -682,14 +805,14 @@ do { \
23168 " negl %0\n" \
23169 " andl $7,%0\n" \
23170 " subl %0,%3\n" \
23171 - "4: rep; movsb\n" \
23172 + "4: rep; "__copyuser_seg"movsb\n" \
23173 " movl %3,%0\n" \
23174 " shrl $2,%0\n" \
23175 " andl $3,%3\n" \
23176 " .align 2,0x90\n" \
23177 - "0: rep; movsl\n" \
23178 + "0: rep; "__copyuser_seg"movsl\n" \
23179 " movl %3,%0\n" \
23180 - "1: rep; movsb\n" \
23181 + "1: rep; "__copyuser_seg"movsb\n" \
23182 "2:\n" \
23183 ".section .fixup,\"ax\"\n" \
23184 "5: addl %3,%0\n" \
23185 @@ -775,9 +898,9 @@ survive:
23186 }
23187 #endif
23188 if (movsl_is_ok(to, from, n))
23189 - __copy_user(to, from, n);
23190 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23191 else
23192 - n = __copy_user_intel(to, from, n);
23193 + n = __generic_copy_to_user_intel(to, from, n);
23194 return n;
23195 }
23196 EXPORT_SYMBOL(__copy_to_user_ll);
23197 @@ -797,10 +920,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23198 unsigned long n)
23199 {
23200 if (movsl_is_ok(to, from, n))
23201 - __copy_user(to, from, n);
23202 + __copy_user(to, from, n, __copyuser_seg, "", "");
23203 else
23204 - n = __copy_user_intel((void __user *)to,
23205 - (const void *)from, n);
23206 + n = __generic_copy_from_user_intel(to, from, n);
23207 return n;
23208 }
23209 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23210 @@ -827,65 +949,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23211 if (n > 64 && cpu_has_xmm2)
23212 n = __copy_user_intel_nocache(to, from, n);
23213 else
23214 - __copy_user(to, from, n);
23215 + __copy_user(to, from, n, __copyuser_seg, "", "");
23216 #else
23217 - __copy_user(to, from, n);
23218 + __copy_user(to, from, n, __copyuser_seg, "", "");
23219 #endif
23220 return n;
23221 }
23222 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23223
23224 -/**
23225 - * copy_to_user: - Copy a block of data into user space.
23226 - * @to: Destination address, in user space.
23227 - * @from: Source address, in kernel space.
23228 - * @n: Number of bytes to copy.
23229 - *
23230 - * Context: User context only. This function may sleep.
23231 - *
23232 - * Copy data from kernel space to user space.
23233 - *
23234 - * Returns number of bytes that could not be copied.
23235 - * On success, this will be zero.
23236 - */
23237 -unsigned long
23238 -copy_to_user(void __user *to, const void *from, unsigned long n)
23239 -{
23240 - if (access_ok(VERIFY_WRITE, to, n))
23241 - n = __copy_to_user(to, from, n);
23242 - return n;
23243 -}
23244 -EXPORT_SYMBOL(copy_to_user);
23245 -
23246 -/**
23247 - * copy_from_user: - Copy a block of data from user space.
23248 - * @to: Destination address, in kernel space.
23249 - * @from: Source address, in user space.
23250 - * @n: Number of bytes to copy.
23251 - *
23252 - * Context: User context only. This function may sleep.
23253 - *
23254 - * Copy data from user space to kernel space.
23255 - *
23256 - * Returns number of bytes that could not be copied.
23257 - * On success, this will be zero.
23258 - *
23259 - * If some data could not be copied, this function will pad the copied
23260 - * data to the requested size using zero bytes.
23261 - */
23262 -unsigned long
23263 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23264 -{
23265 - if (access_ok(VERIFY_READ, from, n))
23266 - n = __copy_from_user(to, from, n);
23267 - else
23268 - memset(to, 0, n);
23269 - return n;
23270 -}
23271 -EXPORT_SYMBOL(_copy_from_user);
23272 -
23273 void copy_from_user_overflow(void)
23274 {
23275 WARN(1, "Buffer overflow detected!\n");
23276 }
23277 EXPORT_SYMBOL(copy_from_user_overflow);
23278 +
23279 +void copy_to_user_overflow(void)
23280 +{
23281 + WARN(1, "Buffer overflow detected!\n");
23282 +}
23283 +EXPORT_SYMBOL(copy_to_user_overflow);
23284 +
23285 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23286 +void __set_fs(mm_segment_t x)
23287 +{
23288 + switch (x.seg) {
23289 + case 0:
23290 + loadsegment(gs, 0);
23291 + break;
23292 + case TASK_SIZE_MAX:
23293 + loadsegment(gs, __USER_DS);
23294 + break;
23295 + case -1UL:
23296 + loadsegment(gs, __KERNEL_DS);
23297 + break;
23298 + default:
23299 + BUG();
23300 + }
23301 + return;
23302 +}
23303 +EXPORT_SYMBOL(__set_fs);
23304 +
23305 +void set_fs(mm_segment_t x)
23306 +{
23307 + current_thread_info()->addr_limit = x;
23308 + __set_fs(x);
23309 +}
23310 +EXPORT_SYMBOL(set_fs);
23311 +#endif
23312 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23313 index b7c2849..bab76d3 100644
23314 --- a/arch/x86/lib/usercopy_64.c
23315 +++ b/arch/x86/lib/usercopy_64.c
23316 @@ -39,16 +39,22 @@ do { \
23317 } while (0)
23318
23319 long
23320 -__strncpy_from_user(char *dst, const char __user *src, long count)
23321 +__strncpy_from_user(char *dst, const char __user *src, unsigned long count)
23322 {
23323 long res;
23324 +
23325 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23326 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
23327 + src += PAX_USER_SHADOW_BASE;
23328 +#endif
23329 +
23330 __do_strncpy_from_user(dst, src, count, res);
23331 return res;
23332 }
23333 EXPORT_SYMBOL(__strncpy_from_user);
23334
23335 long
23336 -strncpy_from_user(char *dst, const char __user *src, long count)
23337 +strncpy_from_user(char *dst, const char __user *src, unsigned long count)
23338 {
23339 long res = -EFAULT;
23340 if (access_ok(VERIFY_READ, src, 1))
23341 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23342 {
23343 long __d0;
23344 might_fault();
23345 +
23346 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23347 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23348 + addr += PAX_USER_SHADOW_BASE;
23349 +#endif
23350 +
23351 /* no memory constraint because it doesn't change any memory gcc knows
23352 about */
23353 asm volatile(
23354 @@ -107,7 +119,7 @@ EXPORT_SYMBOL(clear_user);
23355 * Return 0 on exception, a value greater than N if too long
23356 */
23357
23358 -long __strnlen_user(const char __user *s, long n)
23359 +long __strnlen_user(const char __user *s, unsigned long n)
23360 {
23361 long res = 0;
23362 char c;
23363 @@ -125,7 +137,7 @@ long __strnlen_user(const char __user *s, long n)
23364 }
23365 EXPORT_SYMBOL(__strnlen_user);
23366
23367 -long strnlen_user(const char __user *s, long n)
23368 +long strnlen_user(const char __user *s, unsigned long n)
23369 {
23370 if (!access_ok(VERIFY_READ, s, 1))
23371 return 0;
23372 @@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
23373 }
23374 EXPORT_SYMBOL(strlen_user);
23375
23376 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23377 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23378 {
23379 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23380 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23381 - }
23382 - return len;
23383 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23384 +
23385 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23386 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23387 + to += PAX_USER_SHADOW_BASE;
23388 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23389 + from += PAX_USER_SHADOW_BASE;
23390 +#endif
23391 +
23392 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23393 + }
23394 + return len;
23395 }
23396 EXPORT_SYMBOL(copy_in_user);
23397
23398 @@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
23399 * it is not necessary to optimize tail handling.
23400 */
23401 unsigned long
23402 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23403 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23404 {
23405 char c;
23406 unsigned zero_len;
23407 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23408 index d0474ad..36e9257 100644
23409 --- a/arch/x86/mm/extable.c
23410 +++ b/arch/x86/mm/extable.c
23411 @@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
23412 const struct exception_table_entry *fixup;
23413
23414 #ifdef CONFIG_PNPBIOS
23415 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23416 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23417 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23418 extern u32 pnp_bios_is_utter_crap;
23419 pnp_bios_is_utter_crap = 1;
23420 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23421 index 5db0490..2ddce45 100644
23422 --- a/arch/x86/mm/fault.c
23423 +++ b/arch/x86/mm/fault.c
23424 @@ -13,11 +13,18 @@
23425 #include <linux/perf_event.h> /* perf_sw_event */
23426 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23427 #include <linux/prefetch.h> /* prefetchw */
23428 +#include <linux/unistd.h>
23429 +#include <linux/compiler.h>
23430
23431 #include <asm/traps.h> /* dotraplinkage, ... */
23432 #include <asm/pgalloc.h> /* pgd_*(), ... */
23433 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23434 #include <asm/fixmap.h> /* VSYSCALL_START */
23435 +#include <asm/tlbflush.h>
23436 +
23437 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23438 +#include <asm/stacktrace.h>
23439 +#endif
23440
23441 /*
23442 * Page fault error code bits:
23443 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23444 int ret = 0;
23445
23446 /* kprobe_running() needs smp_processor_id() */
23447 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23448 + if (kprobes_built_in() && !user_mode(regs)) {
23449 preempt_disable();
23450 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23451 ret = 1;
23452 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23453 return !instr_lo || (instr_lo>>1) == 1;
23454 case 0x00:
23455 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23456 - if (probe_kernel_address(instr, opcode))
23457 + if (user_mode(regs)) {
23458 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23459 + return 0;
23460 + } else if (probe_kernel_address(instr, opcode))
23461 return 0;
23462
23463 *prefetch = (instr_lo == 0xF) &&
23464 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23465 while (instr < max_instr) {
23466 unsigned char opcode;
23467
23468 - if (probe_kernel_address(instr, opcode))
23469 + if (user_mode(regs)) {
23470 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23471 + break;
23472 + } else if (probe_kernel_address(instr, opcode))
23473 break;
23474
23475 instr++;
23476 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23477 force_sig_info(si_signo, &info, tsk);
23478 }
23479
23480 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23481 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23482 +#endif
23483 +
23484 +#ifdef CONFIG_PAX_EMUTRAMP
23485 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23486 +#endif
23487 +
23488 +#ifdef CONFIG_PAX_PAGEEXEC
23489 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23490 +{
23491 + pgd_t *pgd;
23492 + pud_t *pud;
23493 + pmd_t *pmd;
23494 +
23495 + pgd = pgd_offset(mm, address);
23496 + if (!pgd_present(*pgd))
23497 + return NULL;
23498 + pud = pud_offset(pgd, address);
23499 + if (!pud_present(*pud))
23500 + return NULL;
23501 + pmd = pmd_offset(pud, address);
23502 + if (!pmd_present(*pmd))
23503 + return NULL;
23504 + return pmd;
23505 +}
23506 +#endif
23507 +
23508 DEFINE_SPINLOCK(pgd_lock);
23509 LIST_HEAD(pgd_list);
23510
23511 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23512 for (address = VMALLOC_START & PMD_MASK;
23513 address >= TASK_SIZE && address < FIXADDR_TOP;
23514 address += PMD_SIZE) {
23515 +
23516 +#ifdef CONFIG_PAX_PER_CPU_PGD
23517 + unsigned long cpu;
23518 +#else
23519 struct page *page;
23520 +#endif
23521
23522 spin_lock(&pgd_lock);
23523 +
23524 +#ifdef CONFIG_PAX_PER_CPU_PGD
23525 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23526 + pgd_t *pgd = get_cpu_pgd(cpu);
23527 + pmd_t *ret;
23528 +#else
23529 list_for_each_entry(page, &pgd_list, lru) {
23530 + pgd_t *pgd = page_address(page);
23531 spinlock_t *pgt_lock;
23532 pmd_t *ret;
23533
23534 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23535 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23536
23537 spin_lock(pgt_lock);
23538 - ret = vmalloc_sync_one(page_address(page), address);
23539 +#endif
23540 +
23541 + ret = vmalloc_sync_one(pgd, address);
23542 +
23543 +#ifndef CONFIG_PAX_PER_CPU_PGD
23544 spin_unlock(pgt_lock);
23545 +#endif
23546
23547 if (!ret)
23548 break;
23549 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23550 * an interrupt in the middle of a task switch..
23551 */
23552 pgd_paddr = read_cr3();
23553 +
23554 +#ifdef CONFIG_PAX_PER_CPU_PGD
23555 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23556 +#endif
23557 +
23558 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23559 if (!pmd_k)
23560 return -1;
23561 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23562 * happen within a race in page table update. In the later
23563 * case just flush:
23564 */
23565 +
23566 +#ifdef CONFIG_PAX_PER_CPU_PGD
23567 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23568 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23569 +#else
23570 pgd = pgd_offset(current->active_mm, address);
23571 +#endif
23572 +
23573 pgd_ref = pgd_offset_k(address);
23574 if (pgd_none(*pgd_ref))
23575 return -1;
23576 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23577 static int is_errata100(struct pt_regs *regs, unsigned long address)
23578 {
23579 #ifdef CONFIG_X86_64
23580 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23581 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23582 return 1;
23583 #endif
23584 return 0;
23585 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23586 }
23587
23588 static const char nx_warning[] = KERN_CRIT
23589 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23590 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23591
23592 static void
23593 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23594 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23595 if (!oops_may_print())
23596 return;
23597
23598 - if (error_code & PF_INSTR) {
23599 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23600 unsigned int level;
23601
23602 pte_t *pte = lookup_address(address, &level);
23603
23604 if (pte && pte_present(*pte) && !pte_exec(*pte))
23605 - printk(nx_warning, current_uid());
23606 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
23607 }
23608
23609 +#ifdef CONFIG_PAX_KERNEXEC
23610 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23611 + if (current->signal->curr_ip)
23612 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23613 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23614 + else
23615 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23616 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23617 + }
23618 +#endif
23619 +
23620 printk(KERN_ALERT "BUG: unable to handle kernel ");
23621 if (address < PAGE_SIZE)
23622 printk(KERN_CONT "NULL pointer dereference");
23623 @@ -739,6 +820,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23624 }
23625 #endif
23626
23627 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23628 + if (pax_is_fetch_fault(regs, error_code, address)) {
23629 +
23630 +#ifdef CONFIG_PAX_EMUTRAMP
23631 + switch (pax_handle_fetch_fault(regs)) {
23632 + case 2:
23633 + return;
23634 + }
23635 +#endif
23636 +
23637 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23638 + do_group_exit(SIGKILL);
23639 + }
23640 +#endif
23641 +
23642 if (unlikely(show_unhandled_signals))
23643 show_signal_msg(regs, error_code, address, tsk);
23644
23645 @@ -835,7 +931,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23646 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23647 printk(KERN_ERR
23648 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23649 - tsk->comm, tsk->pid, address);
23650 + tsk->comm, task_pid_nr(tsk), address);
23651 code = BUS_MCEERR_AR;
23652 }
23653 #endif
23654 @@ -890,6 +986,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23655 return 1;
23656 }
23657
23658 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23659 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23660 +{
23661 + pte_t *pte;
23662 + pmd_t *pmd;
23663 + spinlock_t *ptl;
23664 + unsigned char pte_mask;
23665 +
23666 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23667 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23668 + return 0;
23669 +
23670 + /* PaX: it's our fault, let's handle it if we can */
23671 +
23672 + /* PaX: take a look at read faults before acquiring any locks */
23673 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23674 + /* instruction fetch attempt from a protected page in user mode */
23675 + up_read(&mm->mmap_sem);
23676 +
23677 +#ifdef CONFIG_PAX_EMUTRAMP
23678 + switch (pax_handle_fetch_fault(regs)) {
23679 + case 2:
23680 + return 1;
23681 + }
23682 +#endif
23683 +
23684 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23685 + do_group_exit(SIGKILL);
23686 + }
23687 +
23688 + pmd = pax_get_pmd(mm, address);
23689 + if (unlikely(!pmd))
23690 + return 0;
23691 +
23692 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23693 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23694 + pte_unmap_unlock(pte, ptl);
23695 + return 0;
23696 + }
23697 +
23698 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23699 + /* write attempt to a protected page in user mode */
23700 + pte_unmap_unlock(pte, ptl);
23701 + return 0;
23702 + }
23703 +
23704 +#ifdef CONFIG_SMP
23705 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23706 +#else
23707 + if (likely(address > get_limit(regs->cs)))
23708 +#endif
23709 + {
23710 + set_pte(pte, pte_mkread(*pte));
23711 + __flush_tlb_one(address);
23712 + pte_unmap_unlock(pte, ptl);
23713 + up_read(&mm->mmap_sem);
23714 + return 1;
23715 + }
23716 +
23717 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23718 +
23719 + /*
23720 + * PaX: fill DTLB with user rights and retry
23721 + */
23722 + __asm__ __volatile__ (
23723 + "orb %2,(%1)\n"
23724 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23725 +/*
23726 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23727 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23728 + * page fault when examined during a TLB load attempt. this is true not only
23729 + * for PTEs holding a non-present entry but also present entries that will
23730 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23731 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23732 + * for our target pages since their PTEs are simply not in the TLBs at all.
23733 +
23734 + * the best thing in omitting it is that we gain around 15-20% speed in the
23735 + * fast path of the page fault handler and can get rid of tracing since we
23736 + * can no longer flush unintended entries.
23737 + */
23738 + "invlpg (%0)\n"
23739 +#endif
23740 + __copyuser_seg"testb $0,(%0)\n"
23741 + "xorb %3,(%1)\n"
23742 + :
23743 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23744 + : "memory", "cc");
23745 + pte_unmap_unlock(pte, ptl);
23746 + up_read(&mm->mmap_sem);
23747 + return 1;
23748 +}
23749 +#endif
23750 +
23751 /*
23752 * Handle a spurious fault caused by a stale TLB entry.
23753 *
23754 @@ -962,6 +1151,9 @@ int show_unhandled_signals = 1;
23755 static inline int
23756 access_error(unsigned long error_code, struct vm_area_struct *vma)
23757 {
23758 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23759 + return 1;
23760 +
23761 if (error_code & PF_WRITE) {
23762 /* write, present and write, not present: */
23763 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23764 @@ -995,18 +1187,32 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23765 {
23766 struct vm_area_struct *vma;
23767 struct task_struct *tsk;
23768 - unsigned long address;
23769 struct mm_struct *mm;
23770 int fault;
23771 int write = error_code & PF_WRITE;
23772 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23773 (write ? FAULT_FLAG_WRITE : 0);
23774
23775 - tsk = current;
23776 - mm = tsk->mm;
23777 -
23778 /* Get the faulting address: */
23779 - address = read_cr2();
23780 + unsigned long address = read_cr2();
23781 +
23782 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23783 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23784 + if (!search_exception_tables(regs->ip)) {
23785 + bad_area_nosemaphore(regs, error_code, address);
23786 + return;
23787 + }
23788 + if (address < PAX_USER_SHADOW_BASE) {
23789 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23790 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23791 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23792 + } else
23793 + address -= PAX_USER_SHADOW_BASE;
23794 + }
23795 +#endif
23796 +
23797 + tsk = current;
23798 + mm = tsk->mm;
23799
23800 /*
23801 * Detect and handle instructions that would cause a page fault for
23802 @@ -1067,7 +1273,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23803 * User-mode registers count as a user access even for any
23804 * potential system fault or CPU buglet:
23805 */
23806 - if (user_mode_vm(regs)) {
23807 + if (user_mode(regs)) {
23808 local_irq_enable();
23809 error_code |= PF_USER;
23810 } else {
23811 @@ -1122,6 +1328,11 @@ retry:
23812 might_sleep();
23813 }
23814
23815 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23816 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23817 + return;
23818 +#endif
23819 +
23820 vma = find_vma(mm, address);
23821 if (unlikely(!vma)) {
23822 bad_area(regs, error_code, address);
23823 @@ -1133,18 +1344,24 @@ retry:
23824 bad_area(regs, error_code, address);
23825 return;
23826 }
23827 - if (error_code & PF_USER) {
23828 - /*
23829 - * Accessing the stack below %sp is always a bug.
23830 - * The large cushion allows instructions like enter
23831 - * and pusha to work. ("enter $65535, $31" pushes
23832 - * 32 pointers and then decrements %sp by 65535.)
23833 - */
23834 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23835 - bad_area(regs, error_code, address);
23836 - return;
23837 - }
23838 + /*
23839 + * Accessing the stack below %sp is always a bug.
23840 + * The large cushion allows instructions like enter
23841 + * and pusha to work. ("enter $65535, $31" pushes
23842 + * 32 pointers and then decrements %sp by 65535.)
23843 + */
23844 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23845 + bad_area(regs, error_code, address);
23846 + return;
23847 }
23848 +
23849 +#ifdef CONFIG_PAX_SEGMEXEC
23850 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23851 + bad_area(regs, error_code, address);
23852 + return;
23853 + }
23854 +#endif
23855 +
23856 if (unlikely(expand_stack(vma, address))) {
23857 bad_area(regs, error_code, address);
23858 return;
23859 @@ -1199,3 +1416,292 @@ good_area:
23860
23861 up_read(&mm->mmap_sem);
23862 }
23863 +
23864 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23865 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23866 +{
23867 + struct mm_struct *mm = current->mm;
23868 + unsigned long ip = regs->ip;
23869 +
23870 + if (v8086_mode(regs))
23871 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
23872 +
23873 +#ifdef CONFIG_PAX_PAGEEXEC
23874 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
23875 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
23876 + return true;
23877 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
23878 + return true;
23879 + return false;
23880 + }
23881 +#endif
23882 +
23883 +#ifdef CONFIG_PAX_SEGMEXEC
23884 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
23885 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
23886 + return true;
23887 + return false;
23888 + }
23889 +#endif
23890 +
23891 + return false;
23892 +}
23893 +#endif
23894 +
23895 +#ifdef CONFIG_PAX_EMUTRAMP
23896 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
23897 +{
23898 + int err;
23899 +
23900 + do { /* PaX: libffi trampoline emulation */
23901 + unsigned char mov, jmp;
23902 + unsigned int addr1, addr2;
23903 +
23904 +#ifdef CONFIG_X86_64
23905 + if ((regs->ip + 9) >> 32)
23906 + break;
23907 +#endif
23908 +
23909 + err = get_user(mov, (unsigned char __user *)regs->ip);
23910 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23911 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23912 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23913 +
23914 + if (err)
23915 + break;
23916 +
23917 + if (mov == 0xB8 && jmp == 0xE9) {
23918 + regs->ax = addr1;
23919 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23920 + return 2;
23921 + }
23922 + } while (0);
23923 +
23924 + do { /* PaX: gcc trampoline emulation #1 */
23925 + unsigned char mov1, mov2;
23926 + unsigned short jmp;
23927 + unsigned int addr1, addr2;
23928 +
23929 +#ifdef CONFIG_X86_64
23930 + if ((regs->ip + 11) >> 32)
23931 + break;
23932 +#endif
23933 +
23934 + err = get_user(mov1, (unsigned char __user *)regs->ip);
23935 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23936 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
23937 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23938 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
23939 +
23940 + if (err)
23941 + break;
23942 +
23943 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
23944 + regs->cx = addr1;
23945 + regs->ax = addr2;
23946 + regs->ip = addr2;
23947 + return 2;
23948 + }
23949 + } while (0);
23950 +
23951 + do { /* PaX: gcc trampoline emulation #2 */
23952 + unsigned char mov, jmp;
23953 + unsigned int addr1, addr2;
23954 +
23955 +#ifdef CONFIG_X86_64
23956 + if ((regs->ip + 9) >> 32)
23957 + break;
23958 +#endif
23959 +
23960 + err = get_user(mov, (unsigned char __user *)regs->ip);
23961 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23962 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23963 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23964 +
23965 + if (err)
23966 + break;
23967 +
23968 + if (mov == 0xB9 && jmp == 0xE9) {
23969 + regs->cx = addr1;
23970 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23971 + return 2;
23972 + }
23973 + } while (0);
23974 +
23975 + return 1; /* PaX in action */
23976 +}
23977 +
23978 +#ifdef CONFIG_X86_64
23979 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
23980 +{
23981 + int err;
23982 +
23983 + do { /* PaX: libffi trampoline emulation */
23984 + unsigned short mov1, mov2, jmp1;
23985 + unsigned char stcclc, jmp2;
23986 + unsigned long addr1, addr2;
23987 +
23988 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23989 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23990 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23991 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23992 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
23993 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
23994 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
23995 +
23996 + if (err)
23997 + break;
23998 +
23999 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24000 + regs->r11 = addr1;
24001 + regs->r10 = addr2;
24002 + if (stcclc == 0xF8)
24003 + regs->flags &= ~X86_EFLAGS_CF;
24004 + else
24005 + regs->flags |= X86_EFLAGS_CF;
24006 + regs->ip = addr1;
24007 + return 2;
24008 + }
24009 + } while (0);
24010 +
24011 + do { /* PaX: gcc trampoline emulation #1 */
24012 + unsigned short mov1, mov2, jmp1;
24013 + unsigned char jmp2;
24014 + unsigned int addr1;
24015 + unsigned long addr2;
24016 +
24017 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24018 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24019 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24020 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24021 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24022 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24023 +
24024 + if (err)
24025 + break;
24026 +
24027 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24028 + regs->r11 = addr1;
24029 + regs->r10 = addr2;
24030 + regs->ip = addr1;
24031 + return 2;
24032 + }
24033 + } while (0);
24034 +
24035 + do { /* PaX: gcc trampoline emulation #2 */
24036 + unsigned short mov1, mov2, jmp1;
24037 + unsigned char jmp2;
24038 + unsigned long addr1, addr2;
24039 +
24040 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24041 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24042 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24043 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24044 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24045 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24046 +
24047 + if (err)
24048 + break;
24049 +
24050 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24051 + regs->r11 = addr1;
24052 + regs->r10 = addr2;
24053 + regs->ip = addr1;
24054 + return 2;
24055 + }
24056 + } while (0);
24057 +
24058 + return 1; /* PaX in action */
24059 +}
24060 +#endif
24061 +
24062 +/*
24063 + * PaX: decide what to do with offenders (regs->ip = fault address)
24064 + *
24065 + * returns 1 when task should be killed
24066 + * 2 when gcc trampoline was detected
24067 + */
24068 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24069 +{
24070 + if (v8086_mode(regs))
24071 + return 1;
24072 +
24073 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24074 + return 1;
24075 +
24076 +#ifdef CONFIG_X86_32
24077 + return pax_handle_fetch_fault_32(regs);
24078 +#else
24079 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24080 + return pax_handle_fetch_fault_32(regs);
24081 + else
24082 + return pax_handle_fetch_fault_64(regs);
24083 +#endif
24084 +}
24085 +#endif
24086 +
24087 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24088 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24089 +{
24090 + long i;
24091 +
24092 + printk(KERN_ERR "PAX: bytes at PC: ");
24093 + for (i = 0; i < 20; i++) {
24094 + unsigned char c;
24095 + if (get_user(c, (unsigned char __force_user *)pc+i))
24096 + printk(KERN_CONT "?? ");
24097 + else
24098 + printk(KERN_CONT "%02x ", c);
24099 + }
24100 + printk("\n");
24101 +
24102 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24103 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24104 + unsigned long c;
24105 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24106 +#ifdef CONFIG_X86_32
24107 + printk(KERN_CONT "???????? ");
24108 +#else
24109 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24110 + printk(KERN_CONT "???????? ???????? ");
24111 + else
24112 + printk(KERN_CONT "???????????????? ");
24113 +#endif
24114 + } else {
24115 +#ifdef CONFIG_X86_64
24116 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24117 + printk(KERN_CONT "%08x ", (unsigned int)c);
24118 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24119 + } else
24120 +#endif
24121 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24122 + }
24123 + }
24124 + printk("\n");
24125 +}
24126 +#endif
24127 +
24128 +/**
24129 + * probe_kernel_write(): safely attempt to write to a location
24130 + * @dst: address to write to
24131 + * @src: pointer to the data that shall be written
24132 + * @size: size of the data chunk
24133 + *
24134 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24135 + * happens, handle that and return -EFAULT.
24136 + */
24137 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24138 +{
24139 + long ret;
24140 + mm_segment_t old_fs = get_fs();
24141 +
24142 + set_fs(KERNEL_DS);
24143 + pagefault_disable();
24144 + pax_open_kernel();
24145 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24146 + pax_close_kernel();
24147 + pagefault_enable();
24148 + set_fs(old_fs);
24149 +
24150 + return ret ? -EFAULT : 0;
24151 +}
24152 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24153 index dd74e46..7d26398 100644
24154 --- a/arch/x86/mm/gup.c
24155 +++ b/arch/x86/mm/gup.c
24156 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24157 addr = start;
24158 len = (unsigned long) nr_pages << PAGE_SHIFT;
24159 end = start + len;
24160 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24161 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24162 (void __user *)start, len)))
24163 return 0;
24164
24165 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24166 index f4f29b1..5cac4fb 100644
24167 --- a/arch/x86/mm/highmem_32.c
24168 +++ b/arch/x86/mm/highmem_32.c
24169 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24170 idx = type + KM_TYPE_NR*smp_processor_id();
24171 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24172 BUG_ON(!pte_none(*(kmap_pte-idx)));
24173 +
24174 + pax_open_kernel();
24175 set_pte(kmap_pte-idx, mk_pte(page, prot));
24176 + pax_close_kernel();
24177 +
24178 arch_flush_lazy_mmu_mode();
24179
24180 return (void *)vaddr;
24181 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24182 index f581a18..29efd37 100644
24183 --- a/arch/x86/mm/hugetlbpage.c
24184 +++ b/arch/x86/mm/hugetlbpage.c
24185 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24186 struct hstate *h = hstate_file(file);
24187 struct mm_struct *mm = current->mm;
24188 struct vm_area_struct *vma;
24189 - unsigned long start_addr;
24190 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24191 +
24192 +#ifdef CONFIG_PAX_SEGMEXEC
24193 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24194 + pax_task_size = SEGMEXEC_TASK_SIZE;
24195 +#endif
24196 +
24197 + pax_task_size -= PAGE_SIZE;
24198
24199 if (len > mm->cached_hole_size) {
24200 - start_addr = mm->free_area_cache;
24201 + start_addr = mm->free_area_cache;
24202 } else {
24203 - start_addr = TASK_UNMAPPED_BASE;
24204 - mm->cached_hole_size = 0;
24205 + start_addr = mm->mmap_base;
24206 + mm->cached_hole_size = 0;
24207 }
24208
24209 full_search:
24210 @@ -280,26 +287,27 @@ full_search:
24211
24212 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24213 /* At this point: (!vma || addr < vma->vm_end). */
24214 - if (TASK_SIZE - len < addr) {
24215 + if (pax_task_size - len < addr) {
24216 /*
24217 * Start a new search - just in case we missed
24218 * some holes.
24219 */
24220 - if (start_addr != TASK_UNMAPPED_BASE) {
24221 - start_addr = TASK_UNMAPPED_BASE;
24222 + if (start_addr != mm->mmap_base) {
24223 + start_addr = mm->mmap_base;
24224 mm->cached_hole_size = 0;
24225 goto full_search;
24226 }
24227 return -ENOMEM;
24228 }
24229 - if (!vma || addr + len <= vma->vm_start) {
24230 - mm->free_area_cache = addr + len;
24231 - return addr;
24232 - }
24233 + if (check_heap_stack_gap(vma, addr, len))
24234 + break;
24235 if (addr + mm->cached_hole_size < vma->vm_start)
24236 mm->cached_hole_size = vma->vm_start - addr;
24237 addr = ALIGN(vma->vm_end, huge_page_size(h));
24238 }
24239 +
24240 + mm->free_area_cache = addr + len;
24241 + return addr;
24242 }
24243
24244 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24245 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24246 {
24247 struct hstate *h = hstate_file(file);
24248 struct mm_struct *mm = current->mm;
24249 - struct vm_area_struct *vma, *prev_vma;
24250 - unsigned long base = mm->mmap_base, addr = addr0;
24251 + struct vm_area_struct *vma;
24252 + unsigned long base = mm->mmap_base, addr;
24253 unsigned long largest_hole = mm->cached_hole_size;
24254 - int first_time = 1;
24255
24256 /* don't allow allocations above current base */
24257 if (mm->free_area_cache > base)
24258 @@ -321,64 +328,63 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24259 largest_hole = 0;
24260 mm->free_area_cache = base;
24261 }
24262 -try_again:
24263 +
24264 /* make sure it can fit in the remaining address space */
24265 if (mm->free_area_cache < len)
24266 goto fail;
24267
24268 /* either no address requested or can't fit in requested address hole */
24269 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24270 + addr = (mm->free_area_cache - len);
24271 do {
24272 + addr &= huge_page_mask(h);
24273 + vma = find_vma(mm, addr);
24274 /*
24275 * Lookup failure means no vma is above this address,
24276 * i.e. return with success:
24277 - */
24278 - if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
24279 - return addr;
24280 -
24281 - /*
24282 * new region fits between prev_vma->vm_end and
24283 * vma->vm_start, use it:
24284 */
24285 - if (addr + len <= vma->vm_start &&
24286 - (!prev_vma || (addr >= prev_vma->vm_end))) {
24287 + if (check_heap_stack_gap(vma, addr, len)) {
24288 /* remember the address as a hint for next time */
24289 - mm->cached_hole_size = largest_hole;
24290 - return (mm->free_area_cache = addr);
24291 - } else {
24292 - /* pull free_area_cache down to the first hole */
24293 - if (mm->free_area_cache == vma->vm_end) {
24294 - mm->free_area_cache = vma->vm_start;
24295 - mm->cached_hole_size = largest_hole;
24296 - }
24297 + mm->cached_hole_size = largest_hole;
24298 + return (mm->free_area_cache = addr);
24299 + }
24300 + /* pull free_area_cache down to the first hole */
24301 + if (mm->free_area_cache == vma->vm_end) {
24302 + mm->free_area_cache = vma->vm_start;
24303 + mm->cached_hole_size = largest_hole;
24304 }
24305
24306 /* remember the largest hole we saw so far */
24307 if (addr + largest_hole < vma->vm_start)
24308 - largest_hole = vma->vm_start - addr;
24309 + largest_hole = vma->vm_start - addr;
24310
24311 /* try just below the current vma->vm_start */
24312 - addr = (vma->vm_start - len) & huge_page_mask(h);
24313 - } while (len <= vma->vm_start);
24314 + addr = skip_heap_stack_gap(vma, len);
24315 + } while (!IS_ERR_VALUE(addr));
24316
24317 fail:
24318 /*
24319 - * if hint left us with no space for the requested
24320 - * mapping then try again:
24321 - */
24322 - if (first_time) {
24323 - mm->free_area_cache = base;
24324 - largest_hole = 0;
24325 - first_time = 0;
24326 - goto try_again;
24327 - }
24328 - /*
24329 * A failed mmap() very likely causes application failure,
24330 * so fall back to the bottom-up function here. This scenario
24331 * can happen with large stack limits and large mmap()
24332 * allocations.
24333 */
24334 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24335 +
24336 +#ifdef CONFIG_PAX_SEGMEXEC
24337 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24338 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24339 + else
24340 +#endif
24341 +
24342 + mm->mmap_base = TASK_UNMAPPED_BASE;
24343 +
24344 +#ifdef CONFIG_PAX_RANDMMAP
24345 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24346 + mm->mmap_base += mm->delta_mmap;
24347 +#endif
24348 +
24349 + mm->free_area_cache = mm->mmap_base;
24350 mm->cached_hole_size = ~0UL;
24351 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24352 len, pgoff, flags);
24353 @@ -386,6 +392,7 @@ fail:
24354 /*
24355 * Restore the topdown base:
24356 */
24357 + mm->mmap_base = base;
24358 mm->free_area_cache = base;
24359 mm->cached_hole_size = ~0UL;
24360
24361 @@ -399,10 +406,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24362 struct hstate *h = hstate_file(file);
24363 struct mm_struct *mm = current->mm;
24364 struct vm_area_struct *vma;
24365 + unsigned long pax_task_size = TASK_SIZE;
24366
24367 if (len & ~huge_page_mask(h))
24368 return -EINVAL;
24369 - if (len > TASK_SIZE)
24370 +
24371 +#ifdef CONFIG_PAX_SEGMEXEC
24372 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24373 + pax_task_size = SEGMEXEC_TASK_SIZE;
24374 +#endif
24375 +
24376 + pax_task_size -= PAGE_SIZE;
24377 +
24378 + if (len > pax_task_size)
24379 return -ENOMEM;
24380
24381 if (flags & MAP_FIXED) {
24382 @@ -414,8 +430,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24383 if (addr) {
24384 addr = ALIGN(addr, huge_page_size(h));
24385 vma = find_vma(mm, addr);
24386 - if (TASK_SIZE - len >= addr &&
24387 - (!vma || addr + len <= vma->vm_start))
24388 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24389 return addr;
24390 }
24391 if (mm->get_unmapped_area == arch_get_unmapped_area)
24392 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24393 index 87488b9..399f416 100644
24394 --- a/arch/x86/mm/init.c
24395 +++ b/arch/x86/mm/init.c
24396 @@ -15,6 +15,7 @@
24397 #include <asm/tlbflush.h>
24398 #include <asm/tlb.h>
24399 #include <asm/proto.h>
24400 +#include <asm/desc.h>
24401
24402 unsigned long __initdata pgt_buf_start;
24403 unsigned long __meminitdata pgt_buf_end;
24404 @@ -31,7 +32,7 @@ int direct_gbpages
24405 static void __init find_early_table_space(unsigned long end, int use_pse,
24406 int use_gbpages)
24407 {
24408 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24409 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24410 phys_addr_t base;
24411
24412 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24413 @@ -312,8 +313,29 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24414 */
24415 int devmem_is_allowed(unsigned long pagenr)
24416 {
24417 +#ifdef CONFIG_GRKERNSEC_KMEM
24418 + /* allow BDA */
24419 + if (!pagenr)
24420 + return 1;
24421 + /* allow EBDA */
24422 + if ((0x9f000 >> PAGE_SHIFT) == pagenr)
24423 + return 1;
24424 +#else
24425 + if (!pagenr)
24426 + return 1;
24427 +#ifdef CONFIG_VM86
24428 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24429 + return 1;
24430 +#endif
24431 +#endif
24432 +
24433 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24434 + return 1;
24435 +#ifdef CONFIG_GRKERNSEC_KMEM
24436 + /* throw out everything else below 1MB */
24437 if (pagenr <= 256)
24438 - return 1;
24439 + return 0;
24440 +#endif
24441 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24442 return 0;
24443 if (!page_is_ram(pagenr))
24444 @@ -372,6 +394,86 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24445
24446 void free_initmem(void)
24447 {
24448 +
24449 +#ifdef CONFIG_PAX_KERNEXEC
24450 +#ifdef CONFIG_X86_32
24451 + /* PaX: limit KERNEL_CS to actual size */
24452 + unsigned long addr, limit;
24453 + struct desc_struct d;
24454 + int cpu;
24455 +
24456 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24457 + limit = (limit - 1UL) >> PAGE_SHIFT;
24458 +
24459 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24460 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24461 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24462 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24463 + }
24464 +
24465 + /* PaX: make KERNEL_CS read-only */
24466 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24467 + if (!paravirt_enabled())
24468 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24469 +/*
24470 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24471 + pgd = pgd_offset_k(addr);
24472 + pud = pud_offset(pgd, addr);
24473 + pmd = pmd_offset(pud, addr);
24474 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24475 + }
24476 +*/
24477 +#ifdef CONFIG_X86_PAE
24478 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24479 +/*
24480 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24481 + pgd = pgd_offset_k(addr);
24482 + pud = pud_offset(pgd, addr);
24483 + pmd = pmd_offset(pud, addr);
24484 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24485 + }
24486 +*/
24487 +#endif
24488 +
24489 +#ifdef CONFIG_MODULES
24490 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24491 +#endif
24492 +
24493 +#else
24494 + pgd_t *pgd;
24495 + pud_t *pud;
24496 + pmd_t *pmd;
24497 + unsigned long addr, end;
24498 +
24499 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24500 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24501 + pgd = pgd_offset_k(addr);
24502 + pud = pud_offset(pgd, addr);
24503 + pmd = pmd_offset(pud, addr);
24504 + if (!pmd_present(*pmd))
24505 + continue;
24506 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24507 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24508 + else
24509 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24510 + }
24511 +
24512 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24513 + end = addr + KERNEL_IMAGE_SIZE;
24514 + for (; addr < end; addr += PMD_SIZE) {
24515 + pgd = pgd_offset_k(addr);
24516 + pud = pud_offset(pgd, addr);
24517 + pmd = pmd_offset(pud, addr);
24518 + if (!pmd_present(*pmd))
24519 + continue;
24520 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24521 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24522 + }
24523 +#endif
24524 +
24525 + flush_tlb_all();
24526 +#endif
24527 +
24528 free_init_pages("unused kernel memory",
24529 (unsigned long)(&__init_begin),
24530 (unsigned long)(&__init_end));
24531 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24532 index 29f7c6d..b46b35b 100644
24533 --- a/arch/x86/mm/init_32.c
24534 +++ b/arch/x86/mm/init_32.c
24535 @@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
24536 }
24537
24538 /*
24539 - * Creates a middle page table and puts a pointer to it in the
24540 - * given global directory entry. This only returns the gd entry
24541 - * in non-PAE compilation mode, since the middle layer is folded.
24542 - */
24543 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24544 -{
24545 - pud_t *pud;
24546 - pmd_t *pmd_table;
24547 -
24548 -#ifdef CONFIG_X86_PAE
24549 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24550 - if (after_bootmem)
24551 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24552 - else
24553 - pmd_table = (pmd_t *)alloc_low_page();
24554 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24555 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24556 - pud = pud_offset(pgd, 0);
24557 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24558 -
24559 - return pmd_table;
24560 - }
24561 -#endif
24562 - pud = pud_offset(pgd, 0);
24563 - pmd_table = pmd_offset(pud, 0);
24564 -
24565 - return pmd_table;
24566 -}
24567 -
24568 -/*
24569 * Create a page table and place a pointer to it in a middle page
24570 * directory entry:
24571 */
24572 @@ -123,13 +93,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24573 page_table = (pte_t *)alloc_low_page();
24574
24575 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24576 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24577 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24578 +#else
24579 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24580 +#endif
24581 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24582 }
24583
24584 return pte_offset_kernel(pmd, 0);
24585 }
24586
24587 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24588 +{
24589 + pud_t *pud;
24590 + pmd_t *pmd_table;
24591 +
24592 + pud = pud_offset(pgd, 0);
24593 + pmd_table = pmd_offset(pud, 0);
24594 +
24595 + return pmd_table;
24596 +}
24597 +
24598 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24599 {
24600 int pgd_idx = pgd_index(vaddr);
24601 @@ -203,6 +188,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24602 int pgd_idx, pmd_idx;
24603 unsigned long vaddr;
24604 pgd_t *pgd;
24605 + pud_t *pud;
24606 pmd_t *pmd;
24607 pte_t *pte = NULL;
24608
24609 @@ -212,8 +198,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24610 pgd = pgd_base + pgd_idx;
24611
24612 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24613 - pmd = one_md_table_init(pgd);
24614 - pmd = pmd + pmd_index(vaddr);
24615 + pud = pud_offset(pgd, vaddr);
24616 + pmd = pmd_offset(pud, vaddr);
24617 +
24618 +#ifdef CONFIG_X86_PAE
24619 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24620 +#endif
24621 +
24622 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24623 pmd++, pmd_idx++) {
24624 pte = page_table_kmap_check(one_page_table_init(pmd),
24625 @@ -225,11 +216,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24626 }
24627 }
24628
24629 -static inline int is_kernel_text(unsigned long addr)
24630 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24631 {
24632 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24633 - return 1;
24634 - return 0;
24635 + if ((start > ktla_ktva((unsigned long)_etext) ||
24636 + end <= ktla_ktva((unsigned long)_stext)) &&
24637 + (start > ktla_ktva((unsigned long)_einittext) ||
24638 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24639 +
24640 +#ifdef CONFIG_ACPI_SLEEP
24641 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24642 +#endif
24643 +
24644 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24645 + return 0;
24646 + return 1;
24647 }
24648
24649 /*
24650 @@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned long start,
24651 unsigned long last_map_addr = end;
24652 unsigned long start_pfn, end_pfn;
24653 pgd_t *pgd_base = swapper_pg_dir;
24654 - int pgd_idx, pmd_idx, pte_ofs;
24655 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24656 unsigned long pfn;
24657 pgd_t *pgd;
24658 + pud_t *pud;
24659 pmd_t *pmd;
24660 pte_t *pte;
24661 unsigned pages_2m, pages_4k;
24662 @@ -281,8 +282,13 @@ repeat:
24663 pfn = start_pfn;
24664 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24665 pgd = pgd_base + pgd_idx;
24666 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24667 - pmd = one_md_table_init(pgd);
24668 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24669 + pud = pud_offset(pgd, 0);
24670 + pmd = pmd_offset(pud, 0);
24671 +
24672 +#ifdef CONFIG_X86_PAE
24673 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24674 +#endif
24675
24676 if (pfn >= end_pfn)
24677 continue;
24678 @@ -294,14 +300,13 @@ repeat:
24679 #endif
24680 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24681 pmd++, pmd_idx++) {
24682 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24683 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24684
24685 /*
24686 * Map with big pages if possible, otherwise
24687 * create normal page tables:
24688 */
24689 if (use_pse) {
24690 - unsigned int addr2;
24691 pgprot_t prot = PAGE_KERNEL_LARGE;
24692 /*
24693 * first pass will use the same initial
24694 @@ -311,11 +316,7 @@ repeat:
24695 __pgprot(PTE_IDENT_ATTR |
24696 _PAGE_PSE);
24697
24698 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24699 - PAGE_OFFSET + PAGE_SIZE-1;
24700 -
24701 - if (is_kernel_text(addr) ||
24702 - is_kernel_text(addr2))
24703 + if (is_kernel_text(address, address + PMD_SIZE))
24704 prot = PAGE_KERNEL_LARGE_EXEC;
24705
24706 pages_2m++;
24707 @@ -332,7 +333,7 @@ repeat:
24708 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24709 pte += pte_ofs;
24710 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24711 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24712 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24713 pgprot_t prot = PAGE_KERNEL;
24714 /*
24715 * first pass will use the same initial
24716 @@ -340,7 +341,7 @@ repeat:
24717 */
24718 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24719
24720 - if (is_kernel_text(addr))
24721 + if (is_kernel_text(address, address + PAGE_SIZE))
24722 prot = PAGE_KERNEL_EXEC;
24723
24724 pages_4k++;
24725 @@ -472,7 +473,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24726
24727 pud = pud_offset(pgd, va);
24728 pmd = pmd_offset(pud, va);
24729 - if (!pmd_present(*pmd))
24730 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24731 break;
24732
24733 pte = pte_offset_kernel(pmd, va);
24734 @@ -524,12 +525,10 @@ void __init early_ioremap_page_table_range_init(void)
24735
24736 static void __init pagetable_init(void)
24737 {
24738 - pgd_t *pgd_base = swapper_pg_dir;
24739 -
24740 - permanent_kmaps_init(pgd_base);
24741 + permanent_kmaps_init(swapper_pg_dir);
24742 }
24743
24744 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24745 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24746 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24747
24748 /* user-defined highmem size */
24749 @@ -757,6 +756,12 @@ void __init mem_init(void)
24750
24751 pci_iommu_alloc();
24752
24753 +#ifdef CONFIG_PAX_PER_CPU_PGD
24754 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24755 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24756 + KERNEL_PGD_PTRS);
24757 +#endif
24758 +
24759 #ifdef CONFIG_FLATMEM
24760 BUG_ON(!mem_map);
24761 #endif
24762 @@ -774,7 +779,7 @@ void __init mem_init(void)
24763 set_highmem_pages_init();
24764
24765 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24766 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24767 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24768 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24769
24770 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24771 @@ -815,10 +820,10 @@ void __init mem_init(void)
24772 ((unsigned long)&__init_end -
24773 (unsigned long)&__init_begin) >> 10,
24774
24775 - (unsigned long)&_etext, (unsigned long)&_edata,
24776 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24777 + (unsigned long)&_sdata, (unsigned long)&_edata,
24778 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24779
24780 - (unsigned long)&_text, (unsigned long)&_etext,
24781 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24782 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24783
24784 /*
24785 @@ -896,6 +901,7 @@ void set_kernel_text_rw(void)
24786 if (!kernel_set_to_readonly)
24787 return;
24788
24789 + start = ktla_ktva(start);
24790 pr_debug("Set kernel text: %lx - %lx for read write\n",
24791 start, start+size);
24792
24793 @@ -910,6 +916,7 @@ void set_kernel_text_ro(void)
24794 if (!kernel_set_to_readonly)
24795 return;
24796
24797 + start = ktla_ktva(start);
24798 pr_debug("Set kernel text: %lx - %lx for read only\n",
24799 start, start+size);
24800
24801 @@ -938,6 +945,7 @@ void mark_rodata_ro(void)
24802 unsigned long start = PFN_ALIGN(_text);
24803 unsigned long size = PFN_ALIGN(_etext) - start;
24804
24805 + start = ktla_ktva(start);
24806 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24807 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24808 size >> 10);
24809 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24810 index bbaaa00..796fa65 100644
24811 --- a/arch/x86/mm/init_64.c
24812 +++ b/arch/x86/mm/init_64.c
24813 @@ -75,7 +75,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24814 * around without checking the pgd every time.
24815 */
24816
24817 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24818 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24819 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24820
24821 int force_personality32;
24822 @@ -108,12 +108,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24823
24824 for (address = start; address <= end; address += PGDIR_SIZE) {
24825 const pgd_t *pgd_ref = pgd_offset_k(address);
24826 +
24827 +#ifdef CONFIG_PAX_PER_CPU_PGD
24828 + unsigned long cpu;
24829 +#else
24830 struct page *page;
24831 +#endif
24832
24833 if (pgd_none(*pgd_ref))
24834 continue;
24835
24836 spin_lock(&pgd_lock);
24837 +
24838 +#ifdef CONFIG_PAX_PER_CPU_PGD
24839 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24840 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
24841 +#else
24842 list_for_each_entry(page, &pgd_list, lru) {
24843 pgd_t *pgd;
24844 spinlock_t *pgt_lock;
24845 @@ -122,6 +132,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24846 /* the pgt_lock only for Xen */
24847 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24848 spin_lock(pgt_lock);
24849 +#endif
24850
24851 if (pgd_none(*pgd))
24852 set_pgd(pgd, *pgd_ref);
24853 @@ -129,7 +140,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24854 BUG_ON(pgd_page_vaddr(*pgd)
24855 != pgd_page_vaddr(*pgd_ref));
24856
24857 +#ifndef CONFIG_PAX_PER_CPU_PGD
24858 spin_unlock(pgt_lock);
24859 +#endif
24860 +
24861 }
24862 spin_unlock(&pgd_lock);
24863 }
24864 @@ -203,7 +217,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
24865 pmd = fill_pmd(pud, vaddr);
24866 pte = fill_pte(pmd, vaddr);
24867
24868 + pax_open_kernel();
24869 set_pte(pte, new_pte);
24870 + pax_close_kernel();
24871
24872 /*
24873 * It's enough to flush this one mapping.
24874 @@ -262,14 +278,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
24875 pgd = pgd_offset_k((unsigned long)__va(phys));
24876 if (pgd_none(*pgd)) {
24877 pud = (pud_t *) spp_getpage();
24878 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
24879 - _PAGE_USER));
24880 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
24881 }
24882 pud = pud_offset(pgd, (unsigned long)__va(phys));
24883 if (pud_none(*pud)) {
24884 pmd = (pmd_t *) spp_getpage();
24885 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
24886 - _PAGE_USER));
24887 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
24888 }
24889 pmd = pmd_offset(pud, phys);
24890 BUG_ON(!pmd_none(*pmd));
24891 @@ -330,7 +344,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
24892 if (pfn >= pgt_buf_top)
24893 panic("alloc_low_page: ran out of memory");
24894
24895 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24896 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24897 clear_page(adr);
24898 *phys = pfn * PAGE_SIZE;
24899 return adr;
24900 @@ -346,7 +360,7 @@ static __ref void *map_low_page(void *virt)
24901
24902 phys = __pa(virt);
24903 left = phys & (PAGE_SIZE - 1);
24904 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24905 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24906 adr = (void *)(((unsigned long)adr) | left);
24907
24908 return adr;
24909 @@ -693,6 +707,12 @@ void __init mem_init(void)
24910
24911 pci_iommu_alloc();
24912
24913 +#ifdef CONFIG_PAX_PER_CPU_PGD
24914 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24915 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24916 + KERNEL_PGD_PTRS);
24917 +#endif
24918 +
24919 /* clear_bss() already clear the empty_zero_page */
24920
24921 reservedpages = 0;
24922 @@ -853,8 +873,8 @@ int kern_addr_valid(unsigned long addr)
24923 static struct vm_area_struct gate_vma = {
24924 .vm_start = VSYSCALL_START,
24925 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
24926 - .vm_page_prot = PAGE_READONLY_EXEC,
24927 - .vm_flags = VM_READ | VM_EXEC
24928 + .vm_page_prot = PAGE_READONLY,
24929 + .vm_flags = VM_READ
24930 };
24931
24932 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
24933 @@ -888,7 +908,7 @@ int in_gate_area_no_mm(unsigned long addr)
24934
24935 const char *arch_vma_name(struct vm_area_struct *vma)
24936 {
24937 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24938 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24939 return "[vdso]";
24940 if (vma == &gate_vma)
24941 return "[vsyscall]";
24942 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
24943 index 7b179b4..6bd1777 100644
24944 --- a/arch/x86/mm/iomap_32.c
24945 +++ b/arch/x86/mm/iomap_32.c
24946 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
24947 type = kmap_atomic_idx_push();
24948 idx = type + KM_TYPE_NR * smp_processor_id();
24949 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24950 +
24951 + pax_open_kernel();
24952 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
24953 + pax_close_kernel();
24954 +
24955 arch_flush_lazy_mmu_mode();
24956
24957 return (void *)vaddr;
24958 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
24959 index be1ef57..55f0160 100644
24960 --- a/arch/x86/mm/ioremap.c
24961 +++ b/arch/x86/mm/ioremap.c
24962 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
24963 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
24964 int is_ram = page_is_ram(pfn);
24965
24966 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
24967 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
24968 return NULL;
24969 WARN_ON_ONCE(is_ram);
24970 }
24971 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
24972
24973 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
24974 if (page_is_ram(start >> PAGE_SHIFT))
24975 +#ifdef CONFIG_HIGHMEM
24976 + if ((start >> PAGE_SHIFT) < max_low_pfn)
24977 +#endif
24978 return __va(phys);
24979
24980 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
24981 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
24982 early_param("early_ioremap_debug", early_ioremap_debug_setup);
24983
24984 static __initdata int after_paging_init;
24985 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
24986 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
24987
24988 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
24989 {
24990 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
24991 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
24992
24993 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
24994 - memset(bm_pte, 0, sizeof(bm_pte));
24995 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
24996 + pmd_populate_user(&init_mm, pmd, bm_pte);
24997
24998 /*
24999 * The boot-ioremap range spans multiple pmds, for which
25000 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25001 index d87dd6d..bf3fa66 100644
25002 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25003 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25004 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25005 * memory (e.g. tracked pages)? For now, we need this to avoid
25006 * invoking kmemcheck for PnP BIOS calls.
25007 */
25008 - if (regs->flags & X86_VM_MASK)
25009 + if (v8086_mode(regs))
25010 return false;
25011 - if (regs->cs != __KERNEL_CS)
25012 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25013 return false;
25014
25015 pte = kmemcheck_pte_lookup(address);
25016 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25017 index 845df68..1d8d29f 100644
25018 --- a/arch/x86/mm/mmap.c
25019 +++ b/arch/x86/mm/mmap.c
25020 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25021 * Leave an at least ~128 MB hole with possible stack randomization.
25022 */
25023 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25024 -#define MAX_GAP (TASK_SIZE/6*5)
25025 +#define MAX_GAP (pax_task_size/6*5)
25026
25027 static int mmap_is_legacy(void)
25028 {
25029 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25030 return rnd << PAGE_SHIFT;
25031 }
25032
25033 -static unsigned long mmap_base(void)
25034 +static unsigned long mmap_base(struct mm_struct *mm)
25035 {
25036 unsigned long gap = rlimit(RLIMIT_STACK);
25037 + unsigned long pax_task_size = TASK_SIZE;
25038 +
25039 +#ifdef CONFIG_PAX_SEGMEXEC
25040 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25041 + pax_task_size = SEGMEXEC_TASK_SIZE;
25042 +#endif
25043
25044 if (gap < MIN_GAP)
25045 gap = MIN_GAP;
25046 else if (gap > MAX_GAP)
25047 gap = MAX_GAP;
25048
25049 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25050 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25051 }
25052
25053 /*
25054 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25055 * does, but not when emulating X86_32
25056 */
25057 -static unsigned long mmap_legacy_base(void)
25058 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25059 {
25060 - if (mmap_is_ia32())
25061 + if (mmap_is_ia32()) {
25062 +
25063 +#ifdef CONFIG_PAX_SEGMEXEC
25064 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25065 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25066 + else
25067 +#endif
25068 +
25069 return TASK_UNMAPPED_BASE;
25070 - else
25071 + } else
25072 return TASK_UNMAPPED_BASE + mmap_rnd();
25073 }
25074
25075 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25076 void arch_pick_mmap_layout(struct mm_struct *mm)
25077 {
25078 if (mmap_is_legacy()) {
25079 - mm->mmap_base = mmap_legacy_base();
25080 + mm->mmap_base = mmap_legacy_base(mm);
25081 +
25082 +#ifdef CONFIG_PAX_RANDMMAP
25083 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25084 + mm->mmap_base += mm->delta_mmap;
25085 +#endif
25086 +
25087 mm->get_unmapped_area = arch_get_unmapped_area;
25088 mm->unmap_area = arch_unmap_area;
25089 } else {
25090 - mm->mmap_base = mmap_base();
25091 + mm->mmap_base = mmap_base(mm);
25092 +
25093 +#ifdef CONFIG_PAX_RANDMMAP
25094 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25095 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25096 +#endif
25097 +
25098 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25099 mm->unmap_area = arch_unmap_area_topdown;
25100 }
25101 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25102 index de54b9b..799051e 100644
25103 --- a/arch/x86/mm/mmio-mod.c
25104 +++ b/arch/x86/mm/mmio-mod.c
25105 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25106 break;
25107 default:
25108 {
25109 - unsigned char *ip = (unsigned char *)instptr;
25110 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25111 my_trace->opcode = MMIO_UNKNOWN_OP;
25112 my_trace->width = 0;
25113 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25114 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25115 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25116 void __iomem *addr)
25117 {
25118 - static atomic_t next_id;
25119 + static atomic_unchecked_t next_id;
25120 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25121 /* These are page-unaligned. */
25122 struct mmiotrace_map map = {
25123 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25124 .private = trace
25125 },
25126 .phys = offset,
25127 - .id = atomic_inc_return(&next_id)
25128 + .id = atomic_inc_return_unchecked(&next_id)
25129 };
25130 map.map_id = trace->id;
25131
25132 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25133 index b008656..773eac2 100644
25134 --- a/arch/x86/mm/pageattr-test.c
25135 +++ b/arch/x86/mm/pageattr-test.c
25136 @@ -36,7 +36,7 @@ enum {
25137
25138 static int pte_testbit(pte_t pte)
25139 {
25140 - return pte_flags(pte) & _PAGE_UNUSED1;
25141 + return pte_flags(pte) & _PAGE_CPA_TEST;
25142 }
25143
25144 struct split_state {
25145 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25146 index f9e5267..77b1a40 100644
25147 --- a/arch/x86/mm/pageattr.c
25148 +++ b/arch/x86/mm/pageattr.c
25149 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25150 */
25151 #ifdef CONFIG_PCI_BIOS
25152 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25153 - pgprot_val(forbidden) |= _PAGE_NX;
25154 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25155 #endif
25156
25157 /*
25158 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25159 * Does not cover __inittext since that is gone later on. On
25160 * 64bit we do not enforce !NX on the low mapping
25161 */
25162 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25163 - pgprot_val(forbidden) |= _PAGE_NX;
25164 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25165 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25166
25167 +#ifdef CONFIG_DEBUG_RODATA
25168 /*
25169 * The .rodata section needs to be read-only. Using the pfn
25170 * catches all aliases.
25171 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25172 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25173 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25174 pgprot_val(forbidden) |= _PAGE_RW;
25175 +#endif
25176
25177 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25178 /*
25179 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25180 }
25181 #endif
25182
25183 +#ifdef CONFIG_PAX_KERNEXEC
25184 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25185 + pgprot_val(forbidden) |= _PAGE_RW;
25186 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25187 + }
25188 +#endif
25189 +
25190 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25191
25192 return prot;
25193 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25194 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25195 {
25196 /* change init_mm */
25197 + pax_open_kernel();
25198 set_pte_atomic(kpte, pte);
25199 +
25200 #ifdef CONFIG_X86_32
25201 if (!SHARED_KERNEL_PMD) {
25202 +
25203 +#ifdef CONFIG_PAX_PER_CPU_PGD
25204 + unsigned long cpu;
25205 +#else
25206 struct page *page;
25207 +#endif
25208
25209 +#ifdef CONFIG_PAX_PER_CPU_PGD
25210 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25211 + pgd_t *pgd = get_cpu_pgd(cpu);
25212 +#else
25213 list_for_each_entry(page, &pgd_list, lru) {
25214 - pgd_t *pgd;
25215 + pgd_t *pgd = (pgd_t *)page_address(page);
25216 +#endif
25217 +
25218 pud_t *pud;
25219 pmd_t *pmd;
25220
25221 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25222 + pgd += pgd_index(address);
25223 pud = pud_offset(pgd, address);
25224 pmd = pmd_offset(pud, address);
25225 set_pte_atomic((pte_t *)pmd, pte);
25226 }
25227 }
25228 #endif
25229 + pax_close_kernel();
25230 }
25231
25232 static int
25233 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25234 index f6ff57b..481690f 100644
25235 --- a/arch/x86/mm/pat.c
25236 +++ b/arch/x86/mm/pat.c
25237 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
25238
25239 if (!entry) {
25240 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
25241 - current->comm, current->pid, start, end);
25242 + current->comm, task_pid_nr(current), start, end);
25243 return -EINVAL;
25244 }
25245
25246 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25247 while (cursor < to) {
25248 if (!devmem_is_allowed(pfn)) {
25249 printk(KERN_INFO
25250 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
25251 - current->comm, from, to);
25252 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
25253 + current->comm, from, to, cursor);
25254 return 0;
25255 }
25256 cursor += PAGE_SIZE;
25257 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25258 printk(KERN_INFO
25259 "%s:%d ioremap_change_attr failed %s "
25260 "for %Lx-%Lx\n",
25261 - current->comm, current->pid,
25262 + current->comm, task_pid_nr(current),
25263 cattr_name(flags),
25264 base, (unsigned long long)(base + size));
25265 return -EINVAL;
25266 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25267 if (want_flags != flags) {
25268 printk(KERN_WARNING
25269 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
25270 - current->comm, current->pid,
25271 + current->comm, task_pid_nr(current),
25272 cattr_name(want_flags),
25273 (unsigned long long)paddr,
25274 (unsigned long long)(paddr + size),
25275 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25276 free_memtype(paddr, paddr + size);
25277 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25278 " for %Lx-%Lx, got %s\n",
25279 - current->comm, current->pid,
25280 + current->comm, task_pid_nr(current),
25281 cattr_name(want_flags),
25282 (unsigned long long)paddr,
25283 (unsigned long long)(paddr + size),
25284 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25285 index 9f0614d..92ae64a 100644
25286 --- a/arch/x86/mm/pf_in.c
25287 +++ b/arch/x86/mm/pf_in.c
25288 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25289 int i;
25290 enum reason_type rv = OTHERS;
25291
25292 - p = (unsigned char *)ins_addr;
25293 + p = (unsigned char *)ktla_ktva(ins_addr);
25294 p += skip_prefix(p, &prf);
25295 p += get_opcode(p, &opcode);
25296
25297 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25298 struct prefix_bits prf;
25299 int i;
25300
25301 - p = (unsigned char *)ins_addr;
25302 + p = (unsigned char *)ktla_ktva(ins_addr);
25303 p += skip_prefix(p, &prf);
25304 p += get_opcode(p, &opcode);
25305
25306 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25307 struct prefix_bits prf;
25308 int i;
25309
25310 - p = (unsigned char *)ins_addr;
25311 + p = (unsigned char *)ktla_ktva(ins_addr);
25312 p += skip_prefix(p, &prf);
25313 p += get_opcode(p, &opcode);
25314
25315 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25316 struct prefix_bits prf;
25317 int i;
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 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25324 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(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 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25333 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25334 index 8573b83..c3b1a30 100644
25335 --- a/arch/x86/mm/pgtable.c
25336 +++ b/arch/x86/mm/pgtable.c
25337 @@ -84,10 +84,52 @@ static inline void pgd_list_del(pgd_t *pgd)
25338 list_del(&page->lru);
25339 }
25340
25341 -#define UNSHARED_PTRS_PER_PGD \
25342 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25343 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25344 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25345
25346 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
25347 +{
25348 + while (count--)
25349 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25350 +}
25351 +#endif
25352
25353 +#ifdef CONFIG_PAX_PER_CPU_PGD
25354 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
25355 +{
25356 + while (count--)
25357 +
25358 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25359 + *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
25360 +#else
25361 + *dst++ = *src++;
25362 +#endif
25363 +
25364 +}
25365 +#endif
25366 +
25367 +#ifdef CONFIG_X86_64
25368 +#define pxd_t pud_t
25369 +#define pyd_t pgd_t
25370 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25371 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25372 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25373 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25374 +#define PYD_SIZE PGDIR_SIZE
25375 +#else
25376 +#define pxd_t pmd_t
25377 +#define pyd_t pud_t
25378 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25379 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25380 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25381 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25382 +#define PYD_SIZE PUD_SIZE
25383 +#endif
25384 +
25385 +#ifdef CONFIG_PAX_PER_CPU_PGD
25386 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25387 +static inline void pgd_dtor(pgd_t *pgd) {}
25388 +#else
25389 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25390 {
25391 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25392 @@ -128,6 +170,7 @@ static void pgd_dtor(pgd_t *pgd)
25393 pgd_list_del(pgd);
25394 spin_unlock(&pgd_lock);
25395 }
25396 +#endif
25397
25398 /*
25399 * List of all pgd's needed for non-PAE so it can invalidate entries
25400 @@ -140,7 +183,7 @@ static void pgd_dtor(pgd_t *pgd)
25401 * -- wli
25402 */
25403
25404 -#ifdef CONFIG_X86_PAE
25405 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25406 /*
25407 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25408 * updating the top-level pagetable entries to guarantee the
25409 @@ -152,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25410 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25411 * and initialize the kernel pmds here.
25412 */
25413 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25414 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25415
25416 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25417 {
25418 @@ -170,36 +213,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25419 */
25420 flush_tlb_mm(mm);
25421 }
25422 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25423 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25424 #else /* !CONFIG_X86_PAE */
25425
25426 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25427 -#define PREALLOCATED_PMDS 0
25428 +#define PREALLOCATED_PXDS 0
25429
25430 #endif /* CONFIG_X86_PAE */
25431
25432 -static void free_pmds(pmd_t *pmds[])
25433 +static void free_pxds(pxd_t *pxds[])
25434 {
25435 int i;
25436
25437 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25438 - if (pmds[i])
25439 - free_page((unsigned long)pmds[i]);
25440 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25441 + if (pxds[i])
25442 + free_page((unsigned long)pxds[i]);
25443 }
25444
25445 -static int preallocate_pmds(pmd_t *pmds[])
25446 +static int preallocate_pxds(pxd_t *pxds[])
25447 {
25448 int i;
25449 bool failed = false;
25450
25451 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25452 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25453 - if (pmd == NULL)
25454 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25455 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25456 + if (pxd == NULL)
25457 failed = true;
25458 - pmds[i] = pmd;
25459 + pxds[i] = pxd;
25460 }
25461
25462 if (failed) {
25463 - free_pmds(pmds);
25464 + free_pxds(pxds);
25465 return -ENOMEM;
25466 }
25467
25468 @@ -212,51 +257,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25469 * preallocate which never got a corresponding vma will need to be
25470 * freed manually.
25471 */
25472 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25473 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25474 {
25475 int i;
25476
25477 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25478 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25479 pgd_t pgd = pgdp[i];
25480
25481 if (pgd_val(pgd) != 0) {
25482 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25483 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25484
25485 - pgdp[i] = native_make_pgd(0);
25486 + set_pgd(pgdp + i, native_make_pgd(0));
25487
25488 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25489 - pmd_free(mm, pmd);
25490 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25491 + pxd_free(mm, pxd);
25492 }
25493 }
25494 }
25495
25496 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25497 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25498 {
25499 - pud_t *pud;
25500 + pyd_t *pyd;
25501 unsigned long addr;
25502 int i;
25503
25504 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25505 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25506 return;
25507
25508 - pud = pud_offset(pgd, 0);
25509 +#ifdef CONFIG_X86_64
25510 + pyd = pyd_offset(mm, 0L);
25511 +#else
25512 + pyd = pyd_offset(pgd, 0L);
25513 +#endif
25514
25515 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25516 - i++, pud++, addr += PUD_SIZE) {
25517 - pmd_t *pmd = pmds[i];
25518 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25519 + i++, pyd++, addr += PYD_SIZE) {
25520 + pxd_t *pxd = pxds[i];
25521
25522 if (i >= KERNEL_PGD_BOUNDARY)
25523 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25524 - sizeof(pmd_t) * PTRS_PER_PMD);
25525 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25526 + sizeof(pxd_t) * PTRS_PER_PMD);
25527
25528 - pud_populate(mm, pud, pmd);
25529 + pyd_populate(mm, pyd, pxd);
25530 }
25531 }
25532
25533 pgd_t *pgd_alloc(struct mm_struct *mm)
25534 {
25535 pgd_t *pgd;
25536 - pmd_t *pmds[PREALLOCATED_PMDS];
25537 + pxd_t *pxds[PREALLOCATED_PXDS];
25538
25539 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25540
25541 @@ -265,11 +314,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25542
25543 mm->pgd = pgd;
25544
25545 - if (preallocate_pmds(pmds) != 0)
25546 + if (preallocate_pxds(pxds) != 0)
25547 goto out_free_pgd;
25548
25549 if (paravirt_pgd_alloc(mm) != 0)
25550 - goto out_free_pmds;
25551 + goto out_free_pxds;
25552
25553 /*
25554 * Make sure that pre-populating the pmds is atomic with
25555 @@ -279,14 +328,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25556 spin_lock(&pgd_lock);
25557
25558 pgd_ctor(mm, pgd);
25559 - pgd_prepopulate_pmd(mm, pgd, pmds);
25560 + pgd_prepopulate_pxd(mm, pgd, pxds);
25561
25562 spin_unlock(&pgd_lock);
25563
25564 return pgd;
25565
25566 -out_free_pmds:
25567 - free_pmds(pmds);
25568 +out_free_pxds:
25569 + free_pxds(pxds);
25570 out_free_pgd:
25571 free_page((unsigned long)pgd);
25572 out:
25573 @@ -295,7 +344,7 @@ out:
25574
25575 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25576 {
25577 - pgd_mop_up_pmds(mm, pgd);
25578 + pgd_mop_up_pxds(mm, pgd);
25579 pgd_dtor(pgd);
25580 paravirt_pgd_free(mm, pgd);
25581 free_page((unsigned long)pgd);
25582 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25583 index cac7184..09a39fa 100644
25584 --- a/arch/x86/mm/pgtable_32.c
25585 +++ b/arch/x86/mm/pgtable_32.c
25586 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25587 return;
25588 }
25589 pte = pte_offset_kernel(pmd, vaddr);
25590 +
25591 + pax_open_kernel();
25592 if (pte_val(pteval))
25593 set_pte_at(&init_mm, vaddr, pte, pteval);
25594 else
25595 pte_clear(&init_mm, vaddr, pte);
25596 + pax_close_kernel();
25597
25598 /*
25599 * It's enough to flush this one mapping.
25600 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25601 index 410531d..0f16030 100644
25602 --- a/arch/x86/mm/setup_nx.c
25603 +++ b/arch/x86/mm/setup_nx.c
25604 @@ -5,8 +5,10 @@
25605 #include <asm/pgtable.h>
25606 #include <asm/proto.h>
25607
25608 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25609 static int disable_nx __cpuinitdata;
25610
25611 +#ifndef CONFIG_PAX_PAGEEXEC
25612 /*
25613 * noexec = on|off
25614 *
25615 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25616 return 0;
25617 }
25618 early_param("noexec", noexec_setup);
25619 +#endif
25620 +
25621 +#endif
25622
25623 void __cpuinit x86_configure_nx(void)
25624 {
25625 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25626 if (cpu_has_nx && !disable_nx)
25627 __supported_pte_mask |= _PAGE_NX;
25628 else
25629 +#endif
25630 __supported_pte_mask &= ~_PAGE_NX;
25631 }
25632
25633 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25634 index d6c0418..06a0ad5 100644
25635 --- a/arch/x86/mm/tlb.c
25636 +++ b/arch/x86/mm/tlb.c
25637 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
25638 BUG();
25639 cpumask_clear_cpu(cpu,
25640 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
25641 +
25642 +#ifndef CONFIG_PAX_PER_CPU_PGD
25643 load_cr3(swapper_pg_dir);
25644 +#endif
25645 +
25646 }
25647 EXPORT_SYMBOL_GPL(leave_mm);
25648
25649 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25650 index 6687022..ceabcfa 100644
25651 --- a/arch/x86/net/bpf_jit.S
25652 +++ b/arch/x86/net/bpf_jit.S
25653 @@ -9,6 +9,7 @@
25654 */
25655 #include <linux/linkage.h>
25656 #include <asm/dwarf2.h>
25657 +#include <asm/alternative-asm.h>
25658
25659 /*
25660 * Calling convention :
25661 @@ -35,6 +36,7 @@ sk_load_word:
25662 jle bpf_slow_path_word
25663 mov (SKBDATA,%rsi),%eax
25664 bswap %eax /* ntohl() */
25665 + pax_force_retaddr
25666 ret
25667
25668
25669 @@ -53,6 +55,7 @@ sk_load_half:
25670 jle bpf_slow_path_half
25671 movzwl (SKBDATA,%rsi),%eax
25672 rol $8,%ax # ntohs()
25673 + pax_force_retaddr
25674 ret
25675
25676 sk_load_byte_ind:
25677 @@ -66,6 +69,7 @@ sk_load_byte:
25678 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25679 jle bpf_slow_path_byte
25680 movzbl (SKBDATA,%rsi),%eax
25681 + pax_force_retaddr
25682 ret
25683
25684 /**
25685 @@ -82,6 +86,7 @@ ENTRY(sk_load_byte_msh)
25686 movzbl (SKBDATA,%rsi),%ebx
25687 and $15,%bl
25688 shl $2,%bl
25689 + pax_force_retaddr
25690 ret
25691 CFI_ENDPROC
25692 ENDPROC(sk_load_byte_msh)
25693 @@ -91,6 +96,7 @@ bpf_error:
25694 xor %eax,%eax
25695 mov -8(%rbp),%rbx
25696 leaveq
25697 + pax_force_retaddr
25698 ret
25699
25700 /* rsi contains offset and can be scratched */
25701 @@ -113,6 +119,7 @@ bpf_slow_path_word:
25702 js bpf_error
25703 mov -12(%rbp),%eax
25704 bswap %eax
25705 + pax_force_retaddr
25706 ret
25707
25708 bpf_slow_path_half:
25709 @@ -121,12 +128,14 @@ bpf_slow_path_half:
25710 mov -12(%rbp),%ax
25711 rol $8,%ax
25712 movzwl %ax,%eax
25713 + pax_force_retaddr
25714 ret
25715
25716 bpf_slow_path_byte:
25717 bpf_slow_path_common(1)
25718 js bpf_error
25719 movzbl -12(%rbp),%eax
25720 + pax_force_retaddr
25721 ret
25722
25723 bpf_slow_path_byte_msh:
25724 @@ -137,4 +146,5 @@ bpf_slow_path_byte_msh:
25725 and $15,%al
25726 shl $2,%al
25727 xchg %eax,%ebx
25728 + pax_force_retaddr
25729 ret
25730 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25731 index 7c1b765..8c072c6 100644
25732 --- a/arch/x86/net/bpf_jit_comp.c
25733 +++ b/arch/x86/net/bpf_jit_comp.c
25734 @@ -117,6 +117,10 @@ static inline void bpf_flush_icache(void *start, void *end)
25735 set_fs(old_fs);
25736 }
25737
25738 +struct bpf_jit_work {
25739 + struct work_struct work;
25740 + void *image;
25741 +};
25742
25743 void bpf_jit_compile(struct sk_filter *fp)
25744 {
25745 @@ -141,6 +145,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25746 if (addrs == NULL)
25747 return;
25748
25749 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25750 + if (!fp->work)
25751 + goto out;
25752 +
25753 /* Before first pass, make a rough estimation of addrs[]
25754 * each bpf instruction is translated to less than 64 bytes
25755 */
25756 @@ -476,7 +484,7 @@ void bpf_jit_compile(struct sk_filter *fp)
25757 func = sk_load_word;
25758 common_load: seen |= SEEN_DATAREF;
25759 if ((int)K < 0)
25760 - goto out;
25761 + goto error;
25762 t_offset = func - (image + addrs[i]);
25763 EMIT1_off32(0xbe, K); /* mov imm32,%esi */
25764 EMIT1_off32(0xe8, t_offset); /* call */
25765 @@ -586,17 +594,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25766 break;
25767 default:
25768 /* hmm, too complex filter, give up with jit compiler */
25769 - goto out;
25770 + goto error;
25771 }
25772 ilen = prog - temp;
25773 if (image) {
25774 if (unlikely(proglen + ilen > oldproglen)) {
25775 pr_err("bpb_jit_compile fatal error\n");
25776 - kfree(addrs);
25777 - module_free(NULL, image);
25778 - return;
25779 + module_free_exec(NULL, image);
25780 + goto error;
25781 }
25782 + pax_open_kernel();
25783 memcpy(image + proglen, temp, ilen);
25784 + pax_close_kernel();
25785 }
25786 proglen += ilen;
25787 addrs[i] = proglen;
25788 @@ -617,11 +626,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25789 break;
25790 }
25791 if (proglen == oldproglen) {
25792 - image = module_alloc(max_t(unsigned int,
25793 - proglen,
25794 - sizeof(struct work_struct)));
25795 + image = module_alloc_exec(proglen);
25796 if (!image)
25797 - goto out;
25798 + goto error;
25799 }
25800 oldproglen = proglen;
25801 }
25802 @@ -637,7 +644,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25803 bpf_flush_icache(image, image + proglen);
25804
25805 fp->bpf_func = (void *)image;
25806 - }
25807 + } else
25808 +error:
25809 + kfree(fp->work);
25810 +
25811 out:
25812 kfree(addrs);
25813 return;
25814 @@ -645,18 +655,20 @@ out:
25815
25816 static void jit_free_defer(struct work_struct *arg)
25817 {
25818 - module_free(NULL, arg);
25819 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
25820 + kfree(arg);
25821 }
25822
25823 /* run from softirq, we must use a work_struct to call
25824 - * module_free() from process context
25825 + * module_free_exec() from process context
25826 */
25827 void bpf_jit_free(struct sk_filter *fp)
25828 {
25829 if (fp->bpf_func != sk_run_filter) {
25830 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
25831 + struct work_struct *work = &fp->work->work;
25832
25833 INIT_WORK(work, jit_free_defer);
25834 + fp->work->image = fp->bpf_func;
25835 schedule_work(work);
25836 }
25837 }
25838 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
25839 index bff89df..377758a 100644
25840 --- a/arch/x86/oprofile/backtrace.c
25841 +++ b/arch/x86/oprofile/backtrace.c
25842 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
25843 struct stack_frame_ia32 *fp;
25844 unsigned long bytes;
25845
25846 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25847 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25848 if (bytes != sizeof(bufhead))
25849 return NULL;
25850
25851 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
25852 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
25853
25854 oprofile_add_trace(bufhead[0].return_address);
25855
25856 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
25857 struct stack_frame bufhead[2];
25858 unsigned long bytes;
25859
25860 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25861 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25862 if (bytes != sizeof(bufhead))
25863 return NULL;
25864
25865 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
25866 {
25867 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
25868
25869 - if (!user_mode_vm(regs)) {
25870 + if (!user_mode(regs)) {
25871 unsigned long stack = kernel_stack_pointer(regs);
25872 if (depth)
25873 dump_trace(NULL, regs, (unsigned long *)stack, 0,
25874 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
25875 index cb29191..036766d 100644
25876 --- a/arch/x86/pci/mrst.c
25877 +++ b/arch/x86/pci/mrst.c
25878 @@ -234,7 +234,9 @@ int __init pci_mrst_init(void)
25879 printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n");
25880 pci_mmcfg_late_init();
25881 pcibios_enable_irq = mrst_pci_irq_enable;
25882 - pci_root_ops = pci_mrst_ops;
25883 + pax_open_kernel();
25884 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
25885 + pax_close_kernel();
25886 /* Continue with standard init */
25887 return 1;
25888 }
25889 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
25890 index db0e9a5..0372c14 100644
25891 --- a/arch/x86/pci/pcbios.c
25892 +++ b/arch/x86/pci/pcbios.c
25893 @@ -79,50 +79,93 @@ union bios32 {
25894 static struct {
25895 unsigned long address;
25896 unsigned short segment;
25897 -} bios32_indirect = { 0, __KERNEL_CS };
25898 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
25899
25900 /*
25901 * Returns the entry point for the given service, NULL on error
25902 */
25903
25904 -static unsigned long bios32_service(unsigned long service)
25905 +static unsigned long __devinit bios32_service(unsigned long service)
25906 {
25907 unsigned char return_code; /* %al */
25908 unsigned long address; /* %ebx */
25909 unsigned long length; /* %ecx */
25910 unsigned long entry; /* %edx */
25911 unsigned long flags;
25912 + struct desc_struct d, *gdt;
25913
25914 local_irq_save(flags);
25915 - __asm__("lcall *(%%edi); cld"
25916 +
25917 + gdt = get_cpu_gdt_table(smp_processor_id());
25918 +
25919 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
25920 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25921 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
25922 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25923 +
25924 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
25925 : "=a" (return_code),
25926 "=b" (address),
25927 "=c" (length),
25928 "=d" (entry)
25929 : "0" (service),
25930 "1" (0),
25931 - "D" (&bios32_indirect));
25932 + "D" (&bios32_indirect),
25933 + "r"(__PCIBIOS_DS)
25934 + : "memory");
25935 +
25936 + pax_open_kernel();
25937 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
25938 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
25939 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
25940 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
25941 + pax_close_kernel();
25942 +
25943 local_irq_restore(flags);
25944
25945 switch (return_code) {
25946 - case 0:
25947 - return address + entry;
25948 - case 0x80: /* Not present */
25949 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
25950 - return 0;
25951 - default: /* Shouldn't happen */
25952 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
25953 - service, return_code);
25954 + case 0: {
25955 + int cpu;
25956 + unsigned char flags;
25957 +
25958 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
25959 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
25960 + printk(KERN_WARNING "bios32_service: not valid\n");
25961 return 0;
25962 + }
25963 + address = address + PAGE_OFFSET;
25964 + length += 16UL; /* some BIOSs underreport this... */
25965 + flags = 4;
25966 + if (length >= 64*1024*1024) {
25967 + length >>= PAGE_SHIFT;
25968 + flags |= 8;
25969 + }
25970 +
25971 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
25972 + gdt = get_cpu_gdt_table(cpu);
25973 + pack_descriptor(&d, address, length, 0x9b, flags);
25974 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25975 + pack_descriptor(&d, address, length, 0x93, flags);
25976 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25977 + }
25978 + return entry;
25979 + }
25980 + case 0x80: /* Not present */
25981 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
25982 + return 0;
25983 + default: /* Shouldn't happen */
25984 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
25985 + service, return_code);
25986 + return 0;
25987 }
25988 }
25989
25990 static struct {
25991 unsigned long address;
25992 unsigned short segment;
25993 -} pci_indirect = { 0, __KERNEL_CS };
25994 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
25995
25996 -static int pci_bios_present;
25997 +static int pci_bios_present __read_only;
25998
25999 static int __devinit check_pcibios(void)
26000 {
26001 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26002 unsigned long flags, pcibios_entry;
26003
26004 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26005 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26006 + pci_indirect.address = pcibios_entry;
26007
26008 local_irq_save(flags);
26009 - __asm__(
26010 - "lcall *(%%edi); cld\n\t"
26011 + __asm__("movw %w6, %%ds\n\t"
26012 + "lcall *%%ss:(%%edi); cld\n\t"
26013 + "push %%ss\n\t"
26014 + "pop %%ds\n\t"
26015 "jc 1f\n\t"
26016 "xor %%ah, %%ah\n"
26017 "1:"
26018 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26019 "=b" (ebx),
26020 "=c" (ecx)
26021 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26022 - "D" (&pci_indirect)
26023 + "D" (&pci_indirect),
26024 + "r" (__PCIBIOS_DS)
26025 : "memory");
26026 local_irq_restore(flags);
26027
26028 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26029
26030 switch (len) {
26031 case 1:
26032 - __asm__("lcall *(%%esi); cld\n\t"
26033 + __asm__("movw %w6, %%ds\n\t"
26034 + "lcall *%%ss:(%%esi); cld\n\t"
26035 + "push %%ss\n\t"
26036 + "pop %%ds\n\t"
26037 "jc 1f\n\t"
26038 "xor %%ah, %%ah\n"
26039 "1:"
26040 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26041 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26042 "b" (bx),
26043 "D" ((long)reg),
26044 - "S" (&pci_indirect));
26045 + "S" (&pci_indirect),
26046 + "r" (__PCIBIOS_DS));
26047 /*
26048 * Zero-extend the result beyond 8 bits, do not trust the
26049 * BIOS having done it:
26050 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26051 *value &= 0xff;
26052 break;
26053 case 2:
26054 - __asm__("lcall *(%%esi); cld\n\t"
26055 + __asm__("movw %w6, %%ds\n\t"
26056 + "lcall *%%ss:(%%esi); cld\n\t"
26057 + "push %%ss\n\t"
26058 + "pop %%ds\n\t"
26059 "jc 1f\n\t"
26060 "xor %%ah, %%ah\n"
26061 "1:"
26062 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26063 : "1" (PCIBIOS_READ_CONFIG_WORD),
26064 "b" (bx),
26065 "D" ((long)reg),
26066 - "S" (&pci_indirect));
26067 + "S" (&pci_indirect),
26068 + "r" (__PCIBIOS_DS));
26069 /*
26070 * Zero-extend the result beyond 16 bits, do not trust the
26071 * BIOS having done it:
26072 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26073 *value &= 0xffff;
26074 break;
26075 case 4:
26076 - __asm__("lcall *(%%esi); cld\n\t"
26077 + __asm__("movw %w6, %%ds\n\t"
26078 + "lcall *%%ss:(%%esi); cld\n\t"
26079 + "push %%ss\n\t"
26080 + "pop %%ds\n\t"
26081 "jc 1f\n\t"
26082 "xor %%ah, %%ah\n"
26083 "1:"
26084 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26085 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26086 "b" (bx),
26087 "D" ((long)reg),
26088 - "S" (&pci_indirect));
26089 + "S" (&pci_indirect),
26090 + "r" (__PCIBIOS_DS));
26091 break;
26092 }
26093
26094 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26095
26096 switch (len) {
26097 case 1:
26098 - __asm__("lcall *(%%esi); cld\n\t"
26099 + __asm__("movw %w6, %%ds\n\t"
26100 + "lcall *%%ss:(%%esi); cld\n\t"
26101 + "push %%ss\n\t"
26102 + "pop %%ds\n\t"
26103 "jc 1f\n\t"
26104 "xor %%ah, %%ah\n"
26105 "1:"
26106 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26107 "c" (value),
26108 "b" (bx),
26109 "D" ((long)reg),
26110 - "S" (&pci_indirect));
26111 + "S" (&pci_indirect),
26112 + "r" (__PCIBIOS_DS));
26113 break;
26114 case 2:
26115 - __asm__("lcall *(%%esi); cld\n\t"
26116 + __asm__("movw %w6, %%ds\n\t"
26117 + "lcall *%%ss:(%%esi); cld\n\t"
26118 + "push %%ss\n\t"
26119 + "pop %%ds\n\t"
26120 "jc 1f\n\t"
26121 "xor %%ah, %%ah\n"
26122 "1:"
26123 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26124 "c" (value),
26125 "b" (bx),
26126 "D" ((long)reg),
26127 - "S" (&pci_indirect));
26128 + "S" (&pci_indirect),
26129 + "r" (__PCIBIOS_DS));
26130 break;
26131 case 4:
26132 - __asm__("lcall *(%%esi); cld\n\t"
26133 + __asm__("movw %w6, %%ds\n\t"
26134 + "lcall *%%ss:(%%esi); cld\n\t"
26135 + "push %%ss\n\t"
26136 + "pop %%ds\n\t"
26137 "jc 1f\n\t"
26138 "xor %%ah, %%ah\n"
26139 "1:"
26140 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26141 "c" (value),
26142 "b" (bx),
26143 "D" ((long)reg),
26144 - "S" (&pci_indirect));
26145 + "S" (&pci_indirect),
26146 + "r" (__PCIBIOS_DS));
26147 break;
26148 }
26149
26150 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26151
26152 DBG("PCI: Fetching IRQ routing table... ");
26153 __asm__("push %%es\n\t"
26154 + "movw %w8, %%ds\n\t"
26155 "push %%ds\n\t"
26156 "pop %%es\n\t"
26157 - "lcall *(%%esi); cld\n\t"
26158 + "lcall *%%ss:(%%esi); cld\n\t"
26159 "pop %%es\n\t"
26160 + "push %%ss\n\t"
26161 + "pop %%ds\n"
26162 "jc 1f\n\t"
26163 "xor %%ah, %%ah\n"
26164 "1:"
26165 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26166 "1" (0),
26167 "D" ((long) &opt),
26168 "S" (&pci_indirect),
26169 - "m" (opt)
26170 + "m" (opt),
26171 + "r" (__PCIBIOS_DS)
26172 : "memory");
26173 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26174 if (ret & 0xff00)
26175 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26176 {
26177 int ret;
26178
26179 - __asm__("lcall *(%%esi); cld\n\t"
26180 + __asm__("movw %w5, %%ds\n\t"
26181 + "lcall *%%ss:(%%esi); cld\n\t"
26182 + "push %%ss\n\t"
26183 + "pop %%ds\n"
26184 "jc 1f\n\t"
26185 "xor %%ah, %%ah\n"
26186 "1:"
26187 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26188 : "0" (PCIBIOS_SET_PCI_HW_INT),
26189 "b" ((dev->bus->number << 8) | dev->devfn),
26190 "c" ((irq << 8) | (pin + 10)),
26191 - "S" (&pci_indirect));
26192 + "S" (&pci_indirect),
26193 + "r" (__PCIBIOS_DS));
26194 return !(ret & 0xff00);
26195 }
26196 EXPORT_SYMBOL(pcibios_set_irq_routing);
26197 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26198 index 40e4469..1ab536e 100644
26199 --- a/arch/x86/platform/efi/efi_32.c
26200 +++ b/arch/x86/platform/efi/efi_32.c
26201 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26202 {
26203 struct desc_ptr gdt_descr;
26204
26205 +#ifdef CONFIG_PAX_KERNEXEC
26206 + struct desc_struct d;
26207 +#endif
26208 +
26209 local_irq_save(efi_rt_eflags);
26210
26211 load_cr3(initial_page_table);
26212 __flush_tlb_all();
26213
26214 +#ifdef CONFIG_PAX_KERNEXEC
26215 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26216 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26217 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26218 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26219 +#endif
26220 +
26221 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26222 gdt_descr.size = GDT_SIZE - 1;
26223 load_gdt(&gdt_descr);
26224 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26225 {
26226 struct desc_ptr gdt_descr;
26227
26228 +#ifdef CONFIG_PAX_KERNEXEC
26229 + struct desc_struct d;
26230 +
26231 + memset(&d, 0, sizeof d);
26232 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26233 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26234 +#endif
26235 +
26236 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26237 gdt_descr.size = GDT_SIZE - 1;
26238 load_gdt(&gdt_descr);
26239 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26240 index fbe66e6..c5c0dd2 100644
26241 --- a/arch/x86/platform/efi/efi_stub_32.S
26242 +++ b/arch/x86/platform/efi/efi_stub_32.S
26243 @@ -6,7 +6,9 @@
26244 */
26245
26246 #include <linux/linkage.h>
26247 +#include <linux/init.h>
26248 #include <asm/page_types.h>
26249 +#include <asm/segment.h>
26250
26251 /*
26252 * efi_call_phys(void *, ...) is a function with variable parameters.
26253 @@ -20,7 +22,7 @@
26254 * service functions will comply with gcc calling convention, too.
26255 */
26256
26257 -.text
26258 +__INIT
26259 ENTRY(efi_call_phys)
26260 /*
26261 * 0. The function can only be called in Linux kernel. So CS has been
26262 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
26263 * The mapping of lower virtual memory has been created in prelog and
26264 * epilog.
26265 */
26266 - movl $1f, %edx
26267 - subl $__PAGE_OFFSET, %edx
26268 - jmp *%edx
26269 + movl $(__KERNEXEC_EFI_DS), %edx
26270 + mov %edx, %ds
26271 + mov %edx, %es
26272 + mov %edx, %ss
26273 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
26274 1:
26275
26276 /*
26277 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
26278 * parameter 2, ..., param n. To make things easy, we save the return
26279 * address of efi_call_phys in a global variable.
26280 */
26281 - popl %edx
26282 - movl %edx, saved_return_addr
26283 - /* get the function pointer into ECX*/
26284 - popl %ecx
26285 - movl %ecx, efi_rt_function_ptr
26286 - movl $2f, %edx
26287 - subl $__PAGE_OFFSET, %edx
26288 - pushl %edx
26289 + popl (saved_return_addr)
26290 + popl (efi_rt_function_ptr)
26291
26292 /*
26293 * 3. Clear PG bit in %CR0.
26294 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
26295 /*
26296 * 5. Call the physical function.
26297 */
26298 - jmp *%ecx
26299 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26300
26301 -2:
26302 /*
26303 * 6. After EFI runtime service returns, control will return to
26304 * following instruction. We'd better readjust stack pointer first.
26305 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
26306 movl %cr0, %edx
26307 orl $0x80000000, %edx
26308 movl %edx, %cr0
26309 - jmp 1f
26310 -1:
26311 +
26312 /*
26313 * 8. Now restore the virtual mode from flat mode by
26314 * adding EIP with PAGE_OFFSET.
26315 */
26316 - movl $1f, %edx
26317 - jmp *%edx
26318 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
26319 1:
26320 + movl $(__KERNEL_DS), %edx
26321 + mov %edx, %ds
26322 + mov %edx, %es
26323 + mov %edx, %ss
26324
26325 /*
26326 * 9. Balance the stack. And because EAX contain the return value,
26327 * we'd better not clobber it.
26328 */
26329 - leal efi_rt_function_ptr, %edx
26330 - movl (%edx), %ecx
26331 - pushl %ecx
26332 + pushl (efi_rt_function_ptr)
26333
26334 /*
26335 - * 10. Push the saved return address onto the stack and return.
26336 + * 10. Return to the saved return address.
26337 */
26338 - leal saved_return_addr, %edx
26339 - movl (%edx), %ecx
26340 - pushl %ecx
26341 - ret
26342 + jmpl *(saved_return_addr)
26343 ENDPROC(efi_call_phys)
26344 .previous
26345
26346 -.data
26347 +__INITDATA
26348 saved_return_addr:
26349 .long 0
26350 efi_rt_function_ptr:
26351 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26352 index 4c07cca..2c8427d 100644
26353 --- a/arch/x86/platform/efi/efi_stub_64.S
26354 +++ b/arch/x86/platform/efi/efi_stub_64.S
26355 @@ -7,6 +7,7 @@
26356 */
26357
26358 #include <linux/linkage.h>
26359 +#include <asm/alternative-asm.h>
26360
26361 #define SAVE_XMM \
26362 mov %rsp, %rax; \
26363 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26364 call *%rdi
26365 addq $32, %rsp
26366 RESTORE_XMM
26367 + pax_force_retaddr 0, 1
26368 ret
26369 ENDPROC(efi_call0)
26370
26371 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26372 call *%rdi
26373 addq $32, %rsp
26374 RESTORE_XMM
26375 + pax_force_retaddr 0, 1
26376 ret
26377 ENDPROC(efi_call1)
26378
26379 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26380 call *%rdi
26381 addq $32, %rsp
26382 RESTORE_XMM
26383 + pax_force_retaddr 0, 1
26384 ret
26385 ENDPROC(efi_call2)
26386
26387 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26388 call *%rdi
26389 addq $32, %rsp
26390 RESTORE_XMM
26391 + pax_force_retaddr 0, 1
26392 ret
26393 ENDPROC(efi_call3)
26394
26395 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26396 call *%rdi
26397 addq $32, %rsp
26398 RESTORE_XMM
26399 + pax_force_retaddr 0, 1
26400 ret
26401 ENDPROC(efi_call4)
26402
26403 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26404 call *%rdi
26405 addq $48, %rsp
26406 RESTORE_XMM
26407 + pax_force_retaddr 0, 1
26408 ret
26409 ENDPROC(efi_call5)
26410
26411 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26412 call *%rdi
26413 addq $48, %rsp
26414 RESTORE_XMM
26415 + pax_force_retaddr 0, 1
26416 ret
26417 ENDPROC(efi_call6)
26418 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26419 index ad4ec1c..686479e 100644
26420 --- a/arch/x86/platform/mrst/mrst.c
26421 +++ b/arch/x86/platform/mrst/mrst.c
26422 @@ -76,18 +76,20 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26423 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26424 int sfi_mrtc_num;
26425
26426 -static void mrst_power_off(void)
26427 +static __noreturn void mrst_power_off(void)
26428 {
26429 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
26430 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 1);
26431 + BUG();
26432 }
26433
26434 -static void mrst_reboot(void)
26435 +static __noreturn void mrst_reboot(void)
26436 {
26437 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
26438 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
26439 else
26440 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26441 + BUG();
26442 }
26443
26444 /* parse all the mtimer info to a static mtimer array */
26445 diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
26446 index 81aee5a..9ad9aae 100644
26447 --- a/arch/x86/platform/uv/tlb_uv.c
26448 +++ b/arch/x86/platform/uv/tlb_uv.c
26449 @@ -1433,6 +1433,8 @@ static ssize_t tunables_read(struct file *file, char __user *userbuf,
26450 * 0: display meaning of the statistics
26451 */
26452 static ssize_t ptc_proc_write(struct file *file, const char __user *user,
26453 + size_t count, loff_t *data) __size_overflow(3);
26454 +static ssize_t ptc_proc_write(struct file *file, const char __user *user,
26455 size_t count, loff_t *data)
26456 {
26457 int cpu;
26458 @@ -1548,6 +1550,8 @@ static int parse_tunables_write(struct bau_control *bcp, char *instr,
26459 * Handle a write to debugfs. (/sys/kernel/debug/sgi_uv/bau_tunables)
26460 */
26461 static ssize_t tunables_write(struct file *file, const char __user *user,
26462 + size_t count, loff_t *data) __size_overflow(3);
26463 +static ssize_t tunables_write(struct file *file, const char __user *user,
26464 size_t count, loff_t *data)
26465 {
26466 int cpu;
26467 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26468 index f10c0af..3ec1f95 100644
26469 --- a/arch/x86/power/cpu.c
26470 +++ b/arch/x86/power/cpu.c
26471 @@ -131,7 +131,7 @@ static void do_fpu_end(void)
26472 static void fix_processor_context(void)
26473 {
26474 int cpu = smp_processor_id();
26475 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26476 + struct tss_struct *t = init_tss + cpu;
26477
26478 set_tss_desc(cpu, t); /*
26479 * This just modifies memory; should not be
26480 @@ -141,7 +141,9 @@ static void fix_processor_context(void)
26481 */
26482
26483 #ifdef CONFIG_X86_64
26484 + pax_open_kernel();
26485 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26486 + pax_close_kernel();
26487
26488 syscall_init(); /* This sets MSR_*STAR and related */
26489 #endif
26490 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26491 index 5d17950..2253fc9 100644
26492 --- a/arch/x86/vdso/Makefile
26493 +++ b/arch/x86/vdso/Makefile
26494 @@ -137,7 +137,7 @@ quiet_cmd_vdso = VDSO $@
26495 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26496 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26497
26498 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26499 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26500 GCOV_PROFILE := n
26501
26502 #
26503 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26504 index 468d591..8e80a0a 100644
26505 --- a/arch/x86/vdso/vdso32-setup.c
26506 +++ b/arch/x86/vdso/vdso32-setup.c
26507 @@ -25,6 +25,7 @@
26508 #include <asm/tlbflush.h>
26509 #include <asm/vdso.h>
26510 #include <asm/proto.h>
26511 +#include <asm/mman.h>
26512
26513 enum {
26514 VDSO_DISABLED = 0,
26515 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26516 void enable_sep_cpu(void)
26517 {
26518 int cpu = get_cpu();
26519 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26520 + struct tss_struct *tss = init_tss + cpu;
26521
26522 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26523 put_cpu();
26524 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26525 gate_vma.vm_start = FIXADDR_USER_START;
26526 gate_vma.vm_end = FIXADDR_USER_END;
26527 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26528 - gate_vma.vm_page_prot = __P101;
26529 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26530 /*
26531 * Make sure the vDSO gets into every core dump.
26532 * Dumping its contents makes post-mortem fully interpretable later
26533 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26534 if (compat)
26535 addr = VDSO_HIGH_BASE;
26536 else {
26537 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26538 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26539 if (IS_ERR_VALUE(addr)) {
26540 ret = addr;
26541 goto up_fail;
26542 }
26543 }
26544
26545 - current->mm->context.vdso = (void *)addr;
26546 + current->mm->context.vdso = addr;
26547
26548 if (compat_uses_vma || !compat) {
26549 /*
26550 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26551 }
26552
26553 current_thread_info()->sysenter_return =
26554 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26555 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26556
26557 up_fail:
26558 if (ret)
26559 - current->mm->context.vdso = NULL;
26560 + current->mm->context.vdso = 0;
26561
26562 up_write(&mm->mmap_sem);
26563
26564 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
26565
26566 const char *arch_vma_name(struct vm_area_struct *vma)
26567 {
26568 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26569 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26570 return "[vdso]";
26571 +
26572 +#ifdef CONFIG_PAX_SEGMEXEC
26573 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26574 + return "[vdso]";
26575 +#endif
26576 +
26577 return NULL;
26578 }
26579
26580 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26581 * Check to see if the corresponding task was created in compat vdso
26582 * mode.
26583 */
26584 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26585 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26586 return &gate_vma;
26587 return NULL;
26588 }
26589 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26590 index 153407c..611cba9 100644
26591 --- a/arch/x86/vdso/vma.c
26592 +++ b/arch/x86/vdso/vma.c
26593 @@ -16,8 +16,6 @@
26594 #include <asm/vdso.h>
26595 #include <asm/page.h>
26596
26597 -unsigned int __read_mostly vdso_enabled = 1;
26598 -
26599 extern char vdso_start[], vdso_end[];
26600 extern unsigned short vdso_sync_cpuid;
26601
26602 @@ -96,7 +94,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26603 * unaligned here as a result of stack start randomization.
26604 */
26605 addr = PAGE_ALIGN(addr);
26606 - addr = align_addr(addr, NULL, ALIGN_VDSO);
26607
26608 return addr;
26609 }
26610 @@ -106,40 +103,35 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26611 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26612 {
26613 struct mm_struct *mm = current->mm;
26614 - unsigned long addr;
26615 + unsigned long addr = 0;
26616 int ret;
26617
26618 - if (!vdso_enabled)
26619 - return 0;
26620 -
26621 down_write(&mm->mmap_sem);
26622 +
26623 +#ifdef CONFIG_PAX_RANDMMAP
26624 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26625 +#endif
26626 +
26627 addr = vdso_addr(mm->start_stack, vdso_size);
26628 + addr = align_addr(addr, NULL, ALIGN_VDSO);
26629 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
26630 if (IS_ERR_VALUE(addr)) {
26631 ret = addr;
26632 goto up_fail;
26633 }
26634
26635 - current->mm->context.vdso = (void *)addr;
26636 + mm->context.vdso = addr;
26637
26638 ret = install_special_mapping(mm, addr, vdso_size,
26639 VM_READ|VM_EXEC|
26640 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
26641 VM_ALWAYSDUMP,
26642 vdso_pages);
26643 - if (ret) {
26644 - current->mm->context.vdso = NULL;
26645 - goto up_fail;
26646 - }
26647 +
26648 + if (ret)
26649 + mm->context.vdso = 0;
26650
26651 up_fail:
26652 up_write(&mm->mmap_sem);
26653 return ret;
26654 }
26655 -
26656 -static __init int vdso_setup(char *s)
26657 -{
26658 - vdso_enabled = simple_strtoul(s, NULL, 0);
26659 - return 0;
26660 -}
26661 -__setup("vdso=", vdso_setup);
26662 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
26663 index 1f92865..c843b20 100644
26664 --- a/arch/x86/xen/enlighten.c
26665 +++ b/arch/x86/xen/enlighten.c
26666 @@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
26667
26668 struct shared_info xen_dummy_shared_info;
26669
26670 -void *xen_initial_gdt;
26671 -
26672 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
26673 __read_mostly int xen_have_vector_callback;
26674 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
26675 @@ -1029,7 +1027,7 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
26676 #endif
26677 };
26678
26679 -static void xen_reboot(int reason)
26680 +static __noreturn void xen_reboot(int reason)
26681 {
26682 struct sched_shutdown r = { .reason = reason };
26683
26684 @@ -1037,17 +1035,17 @@ static void xen_reboot(int reason)
26685 BUG();
26686 }
26687
26688 -static void xen_restart(char *msg)
26689 +static __noreturn void xen_restart(char *msg)
26690 {
26691 xen_reboot(SHUTDOWN_reboot);
26692 }
26693
26694 -static void xen_emergency_restart(void)
26695 +static __noreturn void xen_emergency_restart(void)
26696 {
26697 xen_reboot(SHUTDOWN_reboot);
26698 }
26699
26700 -static void xen_machine_halt(void)
26701 +static __noreturn void xen_machine_halt(void)
26702 {
26703 xen_reboot(SHUTDOWN_poweroff);
26704 }
26705 @@ -1153,7 +1151,17 @@ asmlinkage void __init xen_start_kernel(void)
26706 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
26707
26708 /* Work out if we support NX */
26709 - x86_configure_nx();
26710 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26711 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
26712 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
26713 + unsigned l, h;
26714 +
26715 + __supported_pte_mask |= _PAGE_NX;
26716 + rdmsr(MSR_EFER, l, h);
26717 + l |= EFER_NX;
26718 + wrmsr(MSR_EFER, l, h);
26719 + }
26720 +#endif
26721
26722 xen_setup_features();
26723
26724 @@ -1184,13 +1192,6 @@ asmlinkage void __init xen_start_kernel(void)
26725
26726 machine_ops = xen_machine_ops;
26727
26728 - /*
26729 - * The only reliable way to retain the initial address of the
26730 - * percpu gdt_page is to remember it here, so we can go and
26731 - * mark it RW later, when the initial percpu area is freed.
26732 - */
26733 - xen_initial_gdt = &per_cpu(gdt_page, 0);
26734 -
26735 xen_smp_init();
26736
26737 #ifdef CONFIG_ACPI_NUMA
26738 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
26739 index 87f6673..e2555a6 100644
26740 --- a/arch/x86/xen/mmu.c
26741 +++ b/arch/x86/xen/mmu.c
26742 @@ -1733,6 +1733,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
26743 convert_pfn_mfn(init_level4_pgt);
26744 convert_pfn_mfn(level3_ident_pgt);
26745 convert_pfn_mfn(level3_kernel_pgt);
26746 + convert_pfn_mfn(level3_vmalloc_start_pgt);
26747 + convert_pfn_mfn(level3_vmalloc_end_pgt);
26748 + convert_pfn_mfn(level3_vmemmap_pgt);
26749
26750 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
26751 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
26752 @@ -1751,7 +1754,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
26753 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
26754 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
26755 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
26756 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
26757 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
26758 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
26759 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
26760 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
26761 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
26762 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
26763
26764 @@ -1962,6 +1969,7 @@ static void __init xen_post_allocator_init(void)
26765 pv_mmu_ops.set_pud = xen_set_pud;
26766 #if PAGETABLE_LEVELS == 4
26767 pv_mmu_ops.set_pgd = xen_set_pgd;
26768 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
26769 #endif
26770
26771 /* This will work as long as patching hasn't happened yet
26772 @@ -2043,6 +2051,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
26773 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
26774 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
26775 .set_pgd = xen_set_pgd_hyper,
26776 + .set_pgd_batched = xen_set_pgd_hyper,
26777
26778 .alloc_pud = xen_alloc_pmd_init,
26779 .release_pud = xen_release_pmd_init,
26780 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
26781 index 041d4fe..7666b7e 100644
26782 --- a/arch/x86/xen/smp.c
26783 +++ b/arch/x86/xen/smp.c
26784 @@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
26785 {
26786 BUG_ON(smp_processor_id() != 0);
26787 native_smp_prepare_boot_cpu();
26788 -
26789 - /* We've switched to the "real" per-cpu gdt, so make sure the
26790 - old memory can be recycled */
26791 - make_lowmem_page_readwrite(xen_initial_gdt);
26792 -
26793 xen_filter_cpu_maps();
26794 xen_setup_vcpu_info_placement();
26795 }
26796 @@ -275,12 +270,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
26797 gdt = get_cpu_gdt_table(cpu);
26798
26799 ctxt->flags = VGCF_IN_KERNEL;
26800 - ctxt->user_regs.ds = __USER_DS;
26801 - ctxt->user_regs.es = __USER_DS;
26802 + ctxt->user_regs.ds = __KERNEL_DS;
26803 + ctxt->user_regs.es = __KERNEL_DS;
26804 ctxt->user_regs.ss = __KERNEL_DS;
26805 #ifdef CONFIG_X86_32
26806 ctxt->user_regs.fs = __KERNEL_PERCPU;
26807 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
26808 + savesegment(gs, ctxt->user_regs.gs);
26809 #else
26810 ctxt->gs_base_kernel = per_cpu_offset(cpu);
26811 #endif
26812 @@ -331,13 +326,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
26813 int rc;
26814
26815 per_cpu(current_task, cpu) = idle;
26816 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
26817 #ifdef CONFIG_X86_32
26818 irq_ctx_init(cpu);
26819 #else
26820 clear_tsk_thread_flag(idle, TIF_FORK);
26821 - per_cpu(kernel_stack, cpu) =
26822 - (unsigned long)task_stack_page(idle) -
26823 - KERNEL_STACK_OFFSET + THREAD_SIZE;
26824 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26825 #endif
26826 xen_setup_runstate_info(cpu);
26827 xen_setup_timer(cpu);
26828 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
26829 index b040b0e..8cc4fe0 100644
26830 --- a/arch/x86/xen/xen-asm_32.S
26831 +++ b/arch/x86/xen/xen-asm_32.S
26832 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
26833 ESP_OFFSET=4 # bytes pushed onto stack
26834
26835 /*
26836 - * Store vcpu_info pointer for easy access. Do it this way to
26837 - * avoid having to reload %fs
26838 + * Store vcpu_info pointer for easy access.
26839 */
26840 #ifdef CONFIG_SMP
26841 - GET_THREAD_INFO(%eax)
26842 - movl TI_cpu(%eax), %eax
26843 - movl __per_cpu_offset(,%eax,4), %eax
26844 - mov xen_vcpu(%eax), %eax
26845 + push %fs
26846 + mov $(__KERNEL_PERCPU), %eax
26847 + mov %eax, %fs
26848 + mov PER_CPU_VAR(xen_vcpu), %eax
26849 + pop %fs
26850 #else
26851 movl xen_vcpu, %eax
26852 #endif
26853 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
26854 index aaa7291..3f77960 100644
26855 --- a/arch/x86/xen/xen-head.S
26856 +++ b/arch/x86/xen/xen-head.S
26857 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
26858 #ifdef CONFIG_X86_32
26859 mov %esi,xen_start_info
26860 mov $init_thread_union+THREAD_SIZE,%esp
26861 +#ifdef CONFIG_SMP
26862 + movl $cpu_gdt_table,%edi
26863 + movl $__per_cpu_load,%eax
26864 + movw %ax,__KERNEL_PERCPU + 2(%edi)
26865 + rorl $16,%eax
26866 + movb %al,__KERNEL_PERCPU + 4(%edi)
26867 + movb %ah,__KERNEL_PERCPU + 7(%edi)
26868 + movl $__per_cpu_end - 1,%eax
26869 + subl $__per_cpu_start,%eax
26870 + movw %ax,__KERNEL_PERCPU + 0(%edi)
26871 +#endif
26872 #else
26873 mov %rsi,xen_start_info
26874 mov $init_thread_union+THREAD_SIZE,%rsp
26875 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
26876 index b095739..8c17bcd 100644
26877 --- a/arch/x86/xen/xen-ops.h
26878 +++ b/arch/x86/xen/xen-ops.h
26879 @@ -10,8 +10,6 @@
26880 extern const char xen_hypervisor_callback[];
26881 extern const char xen_failsafe_callback[];
26882
26883 -extern void *xen_initial_gdt;
26884 -
26885 struct trap_info;
26886 void xen_copy_trap_info(struct trap_info *traps);
26887
26888 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
26889 index 525bd3d..ef888b1 100644
26890 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
26891 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
26892 @@ -119,9 +119,9 @@
26893 ----------------------------------------------------------------------*/
26894
26895 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
26896 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
26897 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
26898 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
26899 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26900
26901 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
26902 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
26903 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
26904 index 2f33760..835e50a 100644
26905 --- a/arch/xtensa/variants/fsf/include/variant/core.h
26906 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
26907 @@ -11,6 +11,7 @@
26908 #ifndef _XTENSA_CORE_H
26909 #define _XTENSA_CORE_H
26910
26911 +#include <linux/const.h>
26912
26913 /****************************************************************************
26914 Parameters Useful for Any Code, USER or PRIVILEGED
26915 @@ -112,9 +113,9 @@
26916 ----------------------------------------------------------------------*/
26917
26918 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
26919 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
26920 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
26921 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
26922 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26923
26924 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
26925 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
26926 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
26927 index af00795..2bb8105 100644
26928 --- a/arch/xtensa/variants/s6000/include/variant/core.h
26929 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
26930 @@ -11,6 +11,7 @@
26931 #ifndef _XTENSA_CORE_CONFIGURATION_H
26932 #define _XTENSA_CORE_CONFIGURATION_H
26933
26934 +#include <linux/const.h>
26935
26936 /****************************************************************************
26937 Parameters Useful for Any Code, USER or PRIVILEGED
26938 @@ -118,9 +119,9 @@
26939 ----------------------------------------------------------------------*/
26940
26941 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
26942 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
26943 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
26944 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
26945 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26946
26947 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
26948 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
26949 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
26950 index 58916af..9cb880b 100644
26951 --- a/block/blk-iopoll.c
26952 +++ b/block/blk-iopoll.c
26953 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
26954 }
26955 EXPORT_SYMBOL(blk_iopoll_complete);
26956
26957 -static void blk_iopoll_softirq(struct softirq_action *h)
26958 +static void blk_iopoll_softirq(void)
26959 {
26960 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
26961 int rearm = 0, budget = blk_iopoll_budget;
26962 diff --git a/block/blk-map.c b/block/blk-map.c
26963 index 623e1cd..ca1e109 100644
26964 --- a/block/blk-map.c
26965 +++ b/block/blk-map.c
26966 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
26967 if (!len || !kbuf)
26968 return -EINVAL;
26969
26970 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
26971 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
26972 if (do_copy)
26973 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
26974 else
26975 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
26976 index 1366a89..e17f54b 100644
26977 --- a/block/blk-softirq.c
26978 +++ b/block/blk-softirq.c
26979 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
26980 * Softirq action handler - move entries to local list and loop over them
26981 * while passing them to the queue registered handler.
26982 */
26983 -static void blk_done_softirq(struct softirq_action *h)
26984 +static void blk_done_softirq(void)
26985 {
26986 struct list_head *cpu_list, local_list;
26987
26988 diff --git a/block/bsg.c b/block/bsg.c
26989 index c0ab25c..9d49f8f 100644
26990 --- a/block/bsg.c
26991 +++ b/block/bsg.c
26992 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
26993 struct sg_io_v4 *hdr, struct bsg_device *bd,
26994 fmode_t has_write_perm)
26995 {
26996 + unsigned char tmpcmd[sizeof(rq->__cmd)];
26997 + unsigned char *cmdptr;
26998 +
26999 if (hdr->request_len > BLK_MAX_CDB) {
27000 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27001 if (!rq->cmd)
27002 return -ENOMEM;
27003 - }
27004 + cmdptr = rq->cmd;
27005 + } else
27006 + cmdptr = tmpcmd;
27007
27008 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27009 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27010 hdr->request_len))
27011 return -EFAULT;
27012
27013 + if (cmdptr != rq->cmd)
27014 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27015 +
27016 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27017 if (blk_verify_command(rq->cmd, has_write_perm))
27018 return -EPERM;
27019 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27020 index 7b72502..646105c 100644
27021 --- a/block/compat_ioctl.c
27022 +++ b/block/compat_ioctl.c
27023 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27024 err |= __get_user(f->spec1, &uf->spec1);
27025 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27026 err |= __get_user(name, &uf->name);
27027 - f->name = compat_ptr(name);
27028 + f->name = (void __force_kernel *)compat_ptr(name);
27029 if (err) {
27030 err = -EFAULT;
27031 goto out;
27032 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27033 index 688be8a..8a37d98 100644
27034 --- a/block/scsi_ioctl.c
27035 +++ b/block/scsi_ioctl.c
27036 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27037 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27038 struct sg_io_hdr *hdr, fmode_t mode)
27039 {
27040 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27041 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27042 + unsigned char *cmdptr;
27043 +
27044 + if (rq->cmd != rq->__cmd)
27045 + cmdptr = rq->cmd;
27046 + else
27047 + cmdptr = tmpcmd;
27048 +
27049 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27050 return -EFAULT;
27051 +
27052 + if (cmdptr != rq->cmd)
27053 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27054 +
27055 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27056 return -EPERM;
27057
27058 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27059 int err;
27060 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27061 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27062 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27063 + unsigned char *cmdptr;
27064
27065 if (!sic)
27066 return -EINVAL;
27067 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27068 */
27069 err = -EFAULT;
27070 rq->cmd_len = cmdlen;
27071 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27072 +
27073 + if (rq->cmd != rq->__cmd)
27074 + cmdptr = rq->cmd;
27075 + else
27076 + cmdptr = tmpcmd;
27077 +
27078 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27079 goto error;
27080
27081 + if (rq->cmd != cmdptr)
27082 + memcpy(rq->cmd, cmdptr, cmdlen);
27083 +
27084 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27085 goto error;
27086
27087 diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
27088 index a0f768c..1da9c73 100644
27089 --- a/crypto/ablkcipher.c
27090 +++ b/crypto/ablkcipher.c
27091 @@ -307,6 +307,8 @@ int ablkcipher_walk_phys(struct ablkcipher_request *req,
27092 EXPORT_SYMBOL_GPL(ablkcipher_walk_phys);
27093
27094 static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
27095 + unsigned int keylen) __size_overflow(3);
27096 +static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
27097 unsigned int keylen)
27098 {
27099 struct ablkcipher_alg *cipher = crypto_ablkcipher_alg(tfm);
27100 @@ -329,6 +331,8 @@ static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
27101 }
27102
27103 static int setkey(struct crypto_ablkcipher *tfm, const u8 *key,
27104 + unsigned int keylen) __size_overflow(3);
27105 +static int setkey(struct crypto_ablkcipher *tfm, const u8 *key,
27106 unsigned int keylen)
27107 {
27108 struct ablkcipher_alg *cipher = crypto_ablkcipher_alg(tfm);
27109 diff --git a/crypto/aead.c b/crypto/aead.c
27110 index 04add3dc..983032f 100644
27111 --- a/crypto/aead.c
27112 +++ b/crypto/aead.c
27113 @@ -27,6 +27,8 @@
27114 #include "internal.h"
27115
27116 static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
27117 + unsigned int keylen) __size_overflow(3);
27118 +static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
27119 unsigned int keylen)
27120 {
27121 struct aead_alg *aead = crypto_aead_alg(tfm);
27122 @@ -48,6 +50,7 @@ static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
27123 return ret;
27124 }
27125
27126 +static int setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) __size_overflow(3);
27127 static int setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen)
27128 {
27129 struct aead_alg *aead = crypto_aead_alg(tfm);
27130 diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
27131 index 1e61d1a..cf06b86 100644
27132 --- a/crypto/blkcipher.c
27133 +++ b/crypto/blkcipher.c
27134 @@ -359,6 +359,8 @@ int blkcipher_walk_virt_block(struct blkcipher_desc *desc,
27135 EXPORT_SYMBOL_GPL(blkcipher_walk_virt_block);
27136
27137 static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27138 + unsigned int keylen) __size_overflow(3);
27139 +static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27140 unsigned int keylen)
27141 {
27142 struct blkcipher_alg *cipher = &tfm->__crt_alg->cra_blkcipher;
27143 @@ -380,6 +382,7 @@ static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27144 return ret;
27145 }
27146
27147 +static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) __size_overflow(3);
27148 static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
27149 {
27150 struct blkcipher_alg *cipher = &tfm->__crt_alg->cra_blkcipher;
27151 diff --git a/crypto/cipher.c b/crypto/cipher.c
27152 index 39541e0..802d956 100644
27153 --- a/crypto/cipher.c
27154 +++ b/crypto/cipher.c
27155 @@ -21,6 +21,8 @@
27156 #include "internal.h"
27157
27158 static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27159 + unsigned int keylen) __size_overflow(3);
27160 +static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27161 unsigned int keylen)
27162 {
27163 struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher;
27164 @@ -43,6 +45,7 @@ static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27165
27166 }
27167
27168 +static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) __size_overflow(3);
27169 static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
27170 {
27171 struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher;
27172 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27173 index 671d4d6..5f24030 100644
27174 --- a/crypto/cryptd.c
27175 +++ b/crypto/cryptd.c
27176 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27177
27178 struct cryptd_blkcipher_request_ctx {
27179 crypto_completion_t complete;
27180 -};
27181 +} __no_const;
27182
27183 struct cryptd_hash_ctx {
27184 struct crypto_shash *child;
27185 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27186
27187 struct cryptd_aead_request_ctx {
27188 crypto_completion_t complete;
27189 -};
27190 +} __no_const;
27191
27192 static void cryptd_queue_worker(struct work_struct *work);
27193
27194 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27195 index 5d41894..22021e4 100644
27196 --- a/drivers/acpi/apei/cper.c
27197 +++ b/drivers/acpi/apei/cper.c
27198 @@ -38,12 +38,12 @@
27199 */
27200 u64 cper_next_record_id(void)
27201 {
27202 - static atomic64_t seq;
27203 + static atomic64_unchecked_t seq;
27204
27205 - if (!atomic64_read(&seq))
27206 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27207 + if (!atomic64_read_unchecked(&seq))
27208 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27209
27210 - return atomic64_inc_return(&seq);
27211 + return atomic64_inc_return_unchecked(&seq);
27212 }
27213 EXPORT_SYMBOL_GPL(cper_next_record_id);
27214
27215 diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
27216 index 7711d94..8622811 100644
27217 --- a/drivers/acpi/battery.c
27218 +++ b/drivers/acpi/battery.c
27219 @@ -787,6 +787,9 @@ static int acpi_battery_print_alarm(struct seq_file *seq, int result)
27220
27221 static ssize_t acpi_battery_write_alarm(struct file *file,
27222 const char __user * buffer,
27223 + size_t count, loff_t * ppos) __size_overflow(3);
27224 +static ssize_t acpi_battery_write_alarm(struct file *file,
27225 + const char __user * buffer,
27226 size_t count, loff_t * ppos)
27227 {
27228 int result = 0;
27229 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27230 index 6c47ae9..abfdd63 100644
27231 --- a/drivers/acpi/ec_sys.c
27232 +++ b/drivers/acpi/ec_sys.c
27233 @@ -12,6 +12,7 @@
27234 #include <linux/acpi.h>
27235 #include <linux/debugfs.h>
27236 #include <linux/module.h>
27237 +#include <linux/uaccess.h>
27238 #include "internal.h"
27239
27240 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27241 @@ -40,7 +41,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27242 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27243 */
27244 unsigned int size = EC_SPACE_SIZE;
27245 - u8 *data = (u8 *) buf;
27246 + u8 data;
27247 loff_t init_off = *off;
27248 int err = 0;
27249
27250 @@ -53,9 +54,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27251 size = count;
27252
27253 while (size) {
27254 - err = ec_read(*off, &data[*off - init_off]);
27255 + err = ec_read(*off, &data);
27256 if (err)
27257 return err;
27258 + if (put_user(data, &buf[*off - init_off]))
27259 + return -EFAULT;
27260 *off += 1;
27261 size--;
27262 }
27263 @@ -71,7 +74,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27264
27265 unsigned int size = count;
27266 loff_t init_off = *off;
27267 - u8 *data = (u8 *) buf;
27268 int err = 0;
27269
27270 if (*off >= EC_SPACE_SIZE)
27271 @@ -82,7 +84,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27272 }
27273
27274 while (size) {
27275 - u8 byte_write = data[*off - init_off];
27276 + u8 byte_write;
27277 + if (get_user(byte_write, &buf[*off - init_off]))
27278 + return -EFAULT;
27279 err = ec_write(*off, byte_write);
27280 if (err)
27281 return err;
27282 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27283 index 251c7b62..000462d 100644
27284 --- a/drivers/acpi/proc.c
27285 +++ b/drivers/acpi/proc.c
27286 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27287 size_t count, loff_t * ppos)
27288 {
27289 struct list_head *node, *next;
27290 - char strbuf[5];
27291 - char str[5] = "";
27292 - unsigned int len = count;
27293 + char strbuf[5] = {0};
27294
27295 - if (len > 4)
27296 - len = 4;
27297 - if (len < 0)
27298 + if (count > 4)
27299 + count = 4;
27300 + if (copy_from_user(strbuf, buffer, count))
27301 return -EFAULT;
27302 -
27303 - if (copy_from_user(strbuf, buffer, len))
27304 - return -EFAULT;
27305 - strbuf[len] = '\0';
27306 - sscanf(strbuf, "%s", str);
27307 + strbuf[count] = '\0';
27308
27309 mutex_lock(&acpi_device_lock);
27310 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27311 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27312 if (!dev->wakeup.flags.valid)
27313 continue;
27314
27315 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27316 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27317 if (device_can_wakeup(&dev->dev)) {
27318 bool enable = !device_may_wakeup(&dev->dev);
27319 device_set_wakeup_enable(&dev->dev, enable);
27320 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27321 index 9d7bc9f..a6fc091 100644
27322 --- a/drivers/acpi/processor_driver.c
27323 +++ b/drivers/acpi/processor_driver.c
27324 @@ -473,7 +473,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27325 return 0;
27326 #endif
27327
27328 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27329 + BUG_ON(pr->id >= nr_cpu_ids);
27330
27331 /*
27332 * Buggy BIOS check
27333 diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
27334 index 6e36d0c..f319944 100644
27335 --- a/drivers/acpi/sbs.c
27336 +++ b/drivers/acpi/sbs.c
27337 @@ -655,6 +655,9 @@ static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
27338
27339 static ssize_t
27340 acpi_battery_write_alarm(struct file *file, const char __user * buffer,
27341 + size_t count, loff_t * ppos) __size_overflow(3);
27342 +static ssize_t
27343 +acpi_battery_write_alarm(struct file *file, const char __user * buffer,
27344 size_t count, loff_t * ppos)
27345 {
27346 struct seq_file *seq = file->private_data;
27347 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27348 index c04ad68..0b99473 100644
27349 --- a/drivers/ata/libata-core.c
27350 +++ b/drivers/ata/libata-core.c
27351 @@ -4733,7 +4733,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27352 struct ata_port *ap;
27353 unsigned int tag;
27354
27355 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27356 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27357 ap = qc->ap;
27358
27359 qc->flags = 0;
27360 @@ -4749,7 +4749,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27361 struct ata_port *ap;
27362 struct ata_link *link;
27363
27364 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27365 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27366 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27367 ap = qc->ap;
27368 link = qc->dev->link;
27369 @@ -5754,6 +5754,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27370 return;
27371
27372 spin_lock(&lock);
27373 + pax_open_kernel();
27374
27375 for (cur = ops->inherits; cur; cur = cur->inherits) {
27376 void **inherit = (void **)cur;
27377 @@ -5767,8 +5768,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27378 if (IS_ERR(*pp))
27379 *pp = NULL;
27380
27381 - ops->inherits = NULL;
27382 + *(struct ata_port_operations **)&ops->inherits = NULL;
27383
27384 + pax_close_kernel();
27385 spin_unlock(&lock);
27386 }
27387
27388 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27389 index e8574bb..f9f6a72 100644
27390 --- a/drivers/ata/pata_arasan_cf.c
27391 +++ b/drivers/ata/pata_arasan_cf.c
27392 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27393 /* Handle platform specific quirks */
27394 if (pdata->quirk) {
27395 if (pdata->quirk & CF_BROKEN_PIO) {
27396 - ap->ops->set_piomode = NULL;
27397 + pax_open_kernel();
27398 + *(void **)&ap->ops->set_piomode = NULL;
27399 + pax_close_kernel();
27400 ap->pio_mask = 0;
27401 }
27402 if (pdata->quirk & CF_BROKEN_MWDMA)
27403 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27404 index f9b983a..887b9d8 100644
27405 --- a/drivers/atm/adummy.c
27406 +++ b/drivers/atm/adummy.c
27407 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27408 vcc->pop(vcc, skb);
27409 else
27410 dev_kfree_skb_any(skb);
27411 - atomic_inc(&vcc->stats->tx);
27412 + atomic_inc_unchecked(&vcc->stats->tx);
27413
27414 return 0;
27415 }
27416 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27417 index f8f41e0..1f987dd 100644
27418 --- a/drivers/atm/ambassador.c
27419 +++ b/drivers/atm/ambassador.c
27420 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27421 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27422
27423 // VC layer stats
27424 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27425 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27426
27427 // free the descriptor
27428 kfree (tx_descr);
27429 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27430 dump_skb ("<<<", vc, skb);
27431
27432 // VC layer stats
27433 - atomic_inc(&atm_vcc->stats->rx);
27434 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27435 __net_timestamp(skb);
27436 // end of our responsibility
27437 atm_vcc->push (atm_vcc, skb);
27438 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27439 } else {
27440 PRINTK (KERN_INFO, "dropped over-size frame");
27441 // should we count this?
27442 - atomic_inc(&atm_vcc->stats->rx_drop);
27443 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27444 }
27445
27446 } else {
27447 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27448 }
27449
27450 if (check_area (skb->data, skb->len)) {
27451 - atomic_inc(&atm_vcc->stats->tx_err);
27452 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27453 return -ENOMEM; // ?
27454 }
27455
27456 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27457 index b22d71c..d6e1049 100644
27458 --- a/drivers/atm/atmtcp.c
27459 +++ b/drivers/atm/atmtcp.c
27460 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27461 if (vcc->pop) vcc->pop(vcc,skb);
27462 else dev_kfree_skb(skb);
27463 if (dev_data) return 0;
27464 - atomic_inc(&vcc->stats->tx_err);
27465 + atomic_inc_unchecked(&vcc->stats->tx_err);
27466 return -ENOLINK;
27467 }
27468 size = skb->len+sizeof(struct atmtcp_hdr);
27469 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27470 if (!new_skb) {
27471 if (vcc->pop) vcc->pop(vcc,skb);
27472 else dev_kfree_skb(skb);
27473 - atomic_inc(&vcc->stats->tx_err);
27474 + atomic_inc_unchecked(&vcc->stats->tx_err);
27475 return -ENOBUFS;
27476 }
27477 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27478 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27479 if (vcc->pop) vcc->pop(vcc,skb);
27480 else dev_kfree_skb(skb);
27481 out_vcc->push(out_vcc,new_skb);
27482 - atomic_inc(&vcc->stats->tx);
27483 - atomic_inc(&out_vcc->stats->rx);
27484 + atomic_inc_unchecked(&vcc->stats->tx);
27485 + atomic_inc_unchecked(&out_vcc->stats->rx);
27486 return 0;
27487 }
27488
27489 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27490 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27491 read_unlock(&vcc_sklist_lock);
27492 if (!out_vcc) {
27493 - atomic_inc(&vcc->stats->tx_err);
27494 + atomic_inc_unchecked(&vcc->stats->tx_err);
27495 goto done;
27496 }
27497 skb_pull(skb,sizeof(struct atmtcp_hdr));
27498 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27499 __net_timestamp(new_skb);
27500 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27501 out_vcc->push(out_vcc,new_skb);
27502 - atomic_inc(&vcc->stats->tx);
27503 - atomic_inc(&out_vcc->stats->rx);
27504 + atomic_inc_unchecked(&vcc->stats->tx);
27505 + atomic_inc_unchecked(&out_vcc->stats->rx);
27506 done:
27507 if (vcc->pop) vcc->pop(vcc,skb);
27508 else dev_kfree_skb(skb);
27509 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27510 index 956e9ac..133516d 100644
27511 --- a/drivers/atm/eni.c
27512 +++ b/drivers/atm/eni.c
27513 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27514 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27515 vcc->dev->number);
27516 length = 0;
27517 - atomic_inc(&vcc->stats->rx_err);
27518 + atomic_inc_unchecked(&vcc->stats->rx_err);
27519 }
27520 else {
27521 length = ATM_CELL_SIZE-1; /* no HEC */
27522 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27523 size);
27524 }
27525 eff = length = 0;
27526 - atomic_inc(&vcc->stats->rx_err);
27527 + atomic_inc_unchecked(&vcc->stats->rx_err);
27528 }
27529 else {
27530 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27531 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27532 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27533 vcc->dev->number,vcc->vci,length,size << 2,descr);
27534 length = eff = 0;
27535 - atomic_inc(&vcc->stats->rx_err);
27536 + atomic_inc_unchecked(&vcc->stats->rx_err);
27537 }
27538 }
27539 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27540 @@ -771,7 +771,7 @@ rx_dequeued++;
27541 vcc->push(vcc,skb);
27542 pushed++;
27543 }
27544 - atomic_inc(&vcc->stats->rx);
27545 + atomic_inc_unchecked(&vcc->stats->rx);
27546 }
27547 wake_up(&eni_dev->rx_wait);
27548 }
27549 @@ -1229,7 +1229,7 @@ static void dequeue_tx(struct atm_dev *dev)
27550 PCI_DMA_TODEVICE);
27551 if (vcc->pop) vcc->pop(vcc,skb);
27552 else dev_kfree_skb_irq(skb);
27553 - atomic_inc(&vcc->stats->tx);
27554 + atomic_inc_unchecked(&vcc->stats->tx);
27555 wake_up(&eni_dev->tx_wait);
27556 dma_complete++;
27557 }
27558 @@ -1569,7 +1569,7 @@ tx_complete++;
27559 /*--------------------------------- entries ---------------------------------*/
27560
27561
27562 -static const char *media_name[] __devinitdata = {
27563 +static const char *media_name[] __devinitconst = {
27564 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27565 "UTP", "05?", "06?", "07?", /* 4- 7 */
27566 "TAXI","09?", "10?", "11?", /* 8-11 */
27567 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27568 index 5072f8a..fa52520d 100644
27569 --- a/drivers/atm/firestream.c
27570 +++ b/drivers/atm/firestream.c
27571 @@ -750,7 +750,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27572 }
27573 }
27574
27575 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27576 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27577
27578 fs_dprintk (FS_DEBUG_TXMEM, "i");
27579 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27580 @@ -817,7 +817,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27581 #endif
27582 skb_put (skb, qe->p1 & 0xffff);
27583 ATM_SKB(skb)->vcc = atm_vcc;
27584 - atomic_inc(&atm_vcc->stats->rx);
27585 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27586 __net_timestamp(skb);
27587 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27588 atm_vcc->push (atm_vcc, skb);
27589 @@ -838,12 +838,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27590 kfree (pe);
27591 }
27592 if (atm_vcc)
27593 - atomic_inc(&atm_vcc->stats->rx_drop);
27594 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27595 break;
27596 case 0x1f: /* Reassembly abort: no buffers. */
27597 /* Silently increment error counter. */
27598 if (atm_vcc)
27599 - atomic_inc(&atm_vcc->stats->rx_drop);
27600 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27601 break;
27602 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27603 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27604 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27605 index 361f5ae..7fc552d 100644
27606 --- a/drivers/atm/fore200e.c
27607 +++ b/drivers/atm/fore200e.c
27608 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27609 #endif
27610 /* check error condition */
27611 if (*entry->status & STATUS_ERROR)
27612 - atomic_inc(&vcc->stats->tx_err);
27613 + atomic_inc_unchecked(&vcc->stats->tx_err);
27614 else
27615 - atomic_inc(&vcc->stats->tx);
27616 + atomic_inc_unchecked(&vcc->stats->tx);
27617 }
27618 }
27619
27620 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27621 if (skb == NULL) {
27622 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27623
27624 - atomic_inc(&vcc->stats->rx_drop);
27625 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27626 return -ENOMEM;
27627 }
27628
27629 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27630
27631 dev_kfree_skb_any(skb);
27632
27633 - atomic_inc(&vcc->stats->rx_drop);
27634 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27635 return -ENOMEM;
27636 }
27637
27638 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27639
27640 vcc->push(vcc, skb);
27641 - atomic_inc(&vcc->stats->rx);
27642 + atomic_inc_unchecked(&vcc->stats->rx);
27643
27644 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27645
27646 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27647 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27648 fore200e->atm_dev->number,
27649 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27650 - atomic_inc(&vcc->stats->rx_err);
27651 + atomic_inc_unchecked(&vcc->stats->rx_err);
27652 }
27653 }
27654
27655 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27656 goto retry_here;
27657 }
27658
27659 - atomic_inc(&vcc->stats->tx_err);
27660 + atomic_inc_unchecked(&vcc->stats->tx_err);
27661
27662 fore200e->tx_sat++;
27663 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27664 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
27665 index 9a51df4..f3bb5f8 100644
27666 --- a/drivers/atm/he.c
27667 +++ b/drivers/atm/he.c
27668 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27669
27670 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27671 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27672 - atomic_inc(&vcc->stats->rx_drop);
27673 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27674 goto return_host_buffers;
27675 }
27676
27677 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27678 RBRQ_LEN_ERR(he_dev->rbrq_head)
27679 ? "LEN_ERR" : "",
27680 vcc->vpi, vcc->vci);
27681 - atomic_inc(&vcc->stats->rx_err);
27682 + atomic_inc_unchecked(&vcc->stats->rx_err);
27683 goto return_host_buffers;
27684 }
27685
27686 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27687 vcc->push(vcc, skb);
27688 spin_lock(&he_dev->global_lock);
27689
27690 - atomic_inc(&vcc->stats->rx);
27691 + atomic_inc_unchecked(&vcc->stats->rx);
27692
27693 return_host_buffers:
27694 ++pdus_assembled;
27695 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
27696 tpd->vcc->pop(tpd->vcc, tpd->skb);
27697 else
27698 dev_kfree_skb_any(tpd->skb);
27699 - atomic_inc(&tpd->vcc->stats->tx_err);
27700 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
27701 }
27702 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
27703 return;
27704 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27705 vcc->pop(vcc, skb);
27706 else
27707 dev_kfree_skb_any(skb);
27708 - atomic_inc(&vcc->stats->tx_err);
27709 + atomic_inc_unchecked(&vcc->stats->tx_err);
27710 return -EINVAL;
27711 }
27712
27713 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27714 vcc->pop(vcc, skb);
27715 else
27716 dev_kfree_skb_any(skb);
27717 - atomic_inc(&vcc->stats->tx_err);
27718 + atomic_inc_unchecked(&vcc->stats->tx_err);
27719 return -EINVAL;
27720 }
27721 #endif
27722 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27723 vcc->pop(vcc, skb);
27724 else
27725 dev_kfree_skb_any(skb);
27726 - atomic_inc(&vcc->stats->tx_err);
27727 + atomic_inc_unchecked(&vcc->stats->tx_err);
27728 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27729 return -ENOMEM;
27730 }
27731 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27732 vcc->pop(vcc, skb);
27733 else
27734 dev_kfree_skb_any(skb);
27735 - atomic_inc(&vcc->stats->tx_err);
27736 + atomic_inc_unchecked(&vcc->stats->tx_err);
27737 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27738 return -ENOMEM;
27739 }
27740 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27741 __enqueue_tpd(he_dev, tpd, cid);
27742 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27743
27744 - atomic_inc(&vcc->stats->tx);
27745 + atomic_inc_unchecked(&vcc->stats->tx);
27746
27747 return 0;
27748 }
27749 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
27750 index b812103..e391a49 100644
27751 --- a/drivers/atm/horizon.c
27752 +++ b/drivers/atm/horizon.c
27753 @@ -1035,7 +1035,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
27754 {
27755 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
27756 // VC layer stats
27757 - atomic_inc(&vcc->stats->rx);
27758 + atomic_inc_unchecked(&vcc->stats->rx);
27759 __net_timestamp(skb);
27760 // end of our responsibility
27761 vcc->push (vcc, skb);
27762 @@ -1187,7 +1187,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
27763 dev->tx_iovec = NULL;
27764
27765 // VC layer stats
27766 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27767 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27768
27769 // free the skb
27770 hrz_kfree_skb (skb);
27771 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
27772 index 1c05212..c28e200 100644
27773 --- a/drivers/atm/idt77252.c
27774 +++ b/drivers/atm/idt77252.c
27775 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
27776 else
27777 dev_kfree_skb(skb);
27778
27779 - atomic_inc(&vcc->stats->tx);
27780 + atomic_inc_unchecked(&vcc->stats->tx);
27781 }
27782
27783 atomic_dec(&scq->used);
27784 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27785 if ((sb = dev_alloc_skb(64)) == NULL) {
27786 printk("%s: Can't allocate buffers for aal0.\n",
27787 card->name);
27788 - atomic_add(i, &vcc->stats->rx_drop);
27789 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
27790 break;
27791 }
27792 if (!atm_charge(vcc, sb->truesize)) {
27793 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
27794 card->name);
27795 - atomic_add(i - 1, &vcc->stats->rx_drop);
27796 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
27797 dev_kfree_skb(sb);
27798 break;
27799 }
27800 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27801 ATM_SKB(sb)->vcc = vcc;
27802 __net_timestamp(sb);
27803 vcc->push(vcc, sb);
27804 - atomic_inc(&vcc->stats->rx);
27805 + atomic_inc_unchecked(&vcc->stats->rx);
27806
27807 cell += ATM_CELL_PAYLOAD;
27808 }
27809 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27810 "(CDC: %08x)\n",
27811 card->name, len, rpp->len, readl(SAR_REG_CDC));
27812 recycle_rx_pool_skb(card, rpp);
27813 - atomic_inc(&vcc->stats->rx_err);
27814 + atomic_inc_unchecked(&vcc->stats->rx_err);
27815 return;
27816 }
27817 if (stat & SAR_RSQE_CRC) {
27818 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
27819 recycle_rx_pool_skb(card, rpp);
27820 - atomic_inc(&vcc->stats->rx_err);
27821 + atomic_inc_unchecked(&vcc->stats->rx_err);
27822 return;
27823 }
27824 if (skb_queue_len(&rpp->queue) > 1) {
27825 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27826 RXPRINTK("%s: Can't alloc RX skb.\n",
27827 card->name);
27828 recycle_rx_pool_skb(card, rpp);
27829 - atomic_inc(&vcc->stats->rx_err);
27830 + atomic_inc_unchecked(&vcc->stats->rx_err);
27831 return;
27832 }
27833 if (!atm_charge(vcc, skb->truesize)) {
27834 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27835 __net_timestamp(skb);
27836
27837 vcc->push(vcc, skb);
27838 - atomic_inc(&vcc->stats->rx);
27839 + atomic_inc_unchecked(&vcc->stats->rx);
27840
27841 return;
27842 }
27843 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27844 __net_timestamp(skb);
27845
27846 vcc->push(vcc, skb);
27847 - atomic_inc(&vcc->stats->rx);
27848 + atomic_inc_unchecked(&vcc->stats->rx);
27849
27850 if (skb->truesize > SAR_FB_SIZE_3)
27851 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
27852 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
27853 if (vcc->qos.aal != ATM_AAL0) {
27854 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
27855 card->name, vpi, vci);
27856 - atomic_inc(&vcc->stats->rx_drop);
27857 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27858 goto drop;
27859 }
27860
27861 if ((sb = dev_alloc_skb(64)) == NULL) {
27862 printk("%s: Can't allocate buffers for AAL0.\n",
27863 card->name);
27864 - atomic_inc(&vcc->stats->rx_err);
27865 + atomic_inc_unchecked(&vcc->stats->rx_err);
27866 goto drop;
27867 }
27868
27869 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
27870 ATM_SKB(sb)->vcc = vcc;
27871 __net_timestamp(sb);
27872 vcc->push(vcc, sb);
27873 - atomic_inc(&vcc->stats->rx);
27874 + atomic_inc_unchecked(&vcc->stats->rx);
27875
27876 drop:
27877 skb_pull(queue, 64);
27878 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27879
27880 if (vc == NULL) {
27881 printk("%s: NULL connection in send().\n", card->name);
27882 - atomic_inc(&vcc->stats->tx_err);
27883 + atomic_inc_unchecked(&vcc->stats->tx_err);
27884 dev_kfree_skb(skb);
27885 return -EINVAL;
27886 }
27887 if (!test_bit(VCF_TX, &vc->flags)) {
27888 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
27889 - atomic_inc(&vcc->stats->tx_err);
27890 + atomic_inc_unchecked(&vcc->stats->tx_err);
27891 dev_kfree_skb(skb);
27892 return -EINVAL;
27893 }
27894 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27895 break;
27896 default:
27897 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
27898 - atomic_inc(&vcc->stats->tx_err);
27899 + atomic_inc_unchecked(&vcc->stats->tx_err);
27900 dev_kfree_skb(skb);
27901 return -EINVAL;
27902 }
27903
27904 if (skb_shinfo(skb)->nr_frags != 0) {
27905 printk("%s: No scatter-gather yet.\n", card->name);
27906 - atomic_inc(&vcc->stats->tx_err);
27907 + atomic_inc_unchecked(&vcc->stats->tx_err);
27908 dev_kfree_skb(skb);
27909 return -EINVAL;
27910 }
27911 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27912
27913 err = queue_skb(card, vc, skb, oam);
27914 if (err) {
27915 - atomic_inc(&vcc->stats->tx_err);
27916 + atomic_inc_unchecked(&vcc->stats->tx_err);
27917 dev_kfree_skb(skb);
27918 return err;
27919 }
27920 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
27921 skb = dev_alloc_skb(64);
27922 if (!skb) {
27923 printk("%s: Out of memory in send_oam().\n", card->name);
27924 - atomic_inc(&vcc->stats->tx_err);
27925 + atomic_inc_unchecked(&vcc->stats->tx_err);
27926 return -ENOMEM;
27927 }
27928 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
27929 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
27930 index 3d0c2b0..45441fa 100644
27931 --- a/drivers/atm/iphase.c
27932 +++ b/drivers/atm/iphase.c
27933 @@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
27934 status = (u_short) (buf_desc_ptr->desc_mode);
27935 if (status & (RX_CER | RX_PTE | RX_OFL))
27936 {
27937 - atomic_inc(&vcc->stats->rx_err);
27938 + atomic_inc_unchecked(&vcc->stats->rx_err);
27939 IF_ERR(printk("IA: bad packet, dropping it");)
27940 if (status & RX_CER) {
27941 IF_ERR(printk(" cause: packet CRC error\n");)
27942 @@ -1169,7 +1169,7 @@ static int rx_pkt(struct atm_dev *dev)
27943 len = dma_addr - buf_addr;
27944 if (len > iadev->rx_buf_sz) {
27945 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
27946 - atomic_inc(&vcc->stats->rx_err);
27947 + atomic_inc_unchecked(&vcc->stats->rx_err);
27948 goto out_free_desc;
27949 }
27950
27951 @@ -1319,7 +1319,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27952 ia_vcc = INPH_IA_VCC(vcc);
27953 if (ia_vcc == NULL)
27954 {
27955 - atomic_inc(&vcc->stats->rx_err);
27956 + atomic_inc_unchecked(&vcc->stats->rx_err);
27957 dev_kfree_skb_any(skb);
27958 atm_return(vcc, atm_guess_pdu2truesize(len));
27959 goto INCR_DLE;
27960 @@ -1331,7 +1331,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27961 if ((length > iadev->rx_buf_sz) || (length >
27962 (skb->len - sizeof(struct cpcs_trailer))))
27963 {
27964 - atomic_inc(&vcc->stats->rx_err);
27965 + atomic_inc_unchecked(&vcc->stats->rx_err);
27966 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
27967 length, skb->len);)
27968 dev_kfree_skb_any(skb);
27969 @@ -1347,7 +1347,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27970
27971 IF_RX(printk("rx_dle_intr: skb push");)
27972 vcc->push(vcc,skb);
27973 - atomic_inc(&vcc->stats->rx);
27974 + atomic_inc_unchecked(&vcc->stats->rx);
27975 iadev->rx_pkt_cnt++;
27976 }
27977 INCR_DLE:
27978 @@ -2827,15 +2827,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
27979 {
27980 struct k_sonet_stats *stats;
27981 stats = &PRIV(_ia_dev[board])->sonet_stats;
27982 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
27983 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
27984 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
27985 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
27986 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
27987 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
27988 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
27989 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
27990 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
27991 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
27992 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
27993 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
27994 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
27995 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
27996 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
27997 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
27998 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
27999 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28000 }
28001 ia_cmds.status = 0;
28002 break;
28003 @@ -2940,7 +2940,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28004 if ((desc == 0) || (desc > iadev->num_tx_desc))
28005 {
28006 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28007 - atomic_inc(&vcc->stats->tx);
28008 + atomic_inc_unchecked(&vcc->stats->tx);
28009 if (vcc->pop)
28010 vcc->pop(vcc, skb);
28011 else
28012 @@ -3045,14 +3045,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28013 ATM_DESC(skb) = vcc->vci;
28014 skb_queue_tail(&iadev->tx_dma_q, skb);
28015
28016 - atomic_inc(&vcc->stats->tx);
28017 + atomic_inc_unchecked(&vcc->stats->tx);
28018 iadev->tx_pkt_cnt++;
28019 /* Increment transaction counter */
28020 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28021
28022 #if 0
28023 /* add flow control logic */
28024 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28025 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28026 if (iavcc->vc_desc_cnt > 10) {
28027 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28028 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28029 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28030 index f556969..0da15eb 100644
28031 --- a/drivers/atm/lanai.c
28032 +++ b/drivers/atm/lanai.c
28033 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28034 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28035 lanai_endtx(lanai, lvcc);
28036 lanai_free_skb(lvcc->tx.atmvcc, skb);
28037 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28038 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28039 }
28040
28041 /* Try to fill the buffer - don't call unless there is backlog */
28042 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28043 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28044 __net_timestamp(skb);
28045 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28046 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28047 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28048 out:
28049 lvcc->rx.buf.ptr = end;
28050 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28051 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28052 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28053 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28054 lanai->stats.service_rxnotaal5++;
28055 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28056 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28057 return 0;
28058 }
28059 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28060 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28061 int bytes;
28062 read_unlock(&vcc_sklist_lock);
28063 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28064 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28065 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28066 lvcc->stats.x.aal5.service_trash++;
28067 bytes = (SERVICE_GET_END(s) * 16) -
28068 (((unsigned long) lvcc->rx.buf.ptr) -
28069 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28070 }
28071 if (s & SERVICE_STREAM) {
28072 read_unlock(&vcc_sklist_lock);
28073 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28074 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28075 lvcc->stats.x.aal5.service_stream++;
28076 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28077 "PDU on VCI %d!\n", lanai->number, vci);
28078 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28079 return 0;
28080 }
28081 DPRINTK("got rx crc error on vci %d\n", vci);
28082 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28083 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28084 lvcc->stats.x.aal5.service_rxcrc++;
28085 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28086 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28087 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28088 index 1c70c45..300718d 100644
28089 --- a/drivers/atm/nicstar.c
28090 +++ b/drivers/atm/nicstar.c
28091 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28092 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28093 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28094 card->index);
28095 - atomic_inc(&vcc->stats->tx_err);
28096 + atomic_inc_unchecked(&vcc->stats->tx_err);
28097 dev_kfree_skb_any(skb);
28098 return -EINVAL;
28099 }
28100 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28101 if (!vc->tx) {
28102 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28103 card->index);
28104 - atomic_inc(&vcc->stats->tx_err);
28105 + atomic_inc_unchecked(&vcc->stats->tx_err);
28106 dev_kfree_skb_any(skb);
28107 return -EINVAL;
28108 }
28109 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28110 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28111 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28112 card->index);
28113 - atomic_inc(&vcc->stats->tx_err);
28114 + atomic_inc_unchecked(&vcc->stats->tx_err);
28115 dev_kfree_skb_any(skb);
28116 return -EINVAL;
28117 }
28118
28119 if (skb_shinfo(skb)->nr_frags != 0) {
28120 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28121 - atomic_inc(&vcc->stats->tx_err);
28122 + atomic_inc_unchecked(&vcc->stats->tx_err);
28123 dev_kfree_skb_any(skb);
28124 return -EINVAL;
28125 }
28126 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28127 }
28128
28129 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28130 - atomic_inc(&vcc->stats->tx_err);
28131 + atomic_inc_unchecked(&vcc->stats->tx_err);
28132 dev_kfree_skb_any(skb);
28133 return -EIO;
28134 }
28135 - atomic_inc(&vcc->stats->tx);
28136 + atomic_inc_unchecked(&vcc->stats->tx);
28137
28138 return 0;
28139 }
28140 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28141 printk
28142 ("nicstar%d: Can't allocate buffers for aal0.\n",
28143 card->index);
28144 - atomic_add(i, &vcc->stats->rx_drop);
28145 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28146 break;
28147 }
28148 if (!atm_charge(vcc, sb->truesize)) {
28149 RXPRINTK
28150 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28151 card->index);
28152 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28153 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28154 dev_kfree_skb_any(sb);
28155 break;
28156 }
28157 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28158 ATM_SKB(sb)->vcc = vcc;
28159 __net_timestamp(sb);
28160 vcc->push(vcc, sb);
28161 - atomic_inc(&vcc->stats->rx);
28162 + atomic_inc_unchecked(&vcc->stats->rx);
28163 cell += ATM_CELL_PAYLOAD;
28164 }
28165
28166 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28167 if (iovb == NULL) {
28168 printk("nicstar%d: Out of iovec buffers.\n",
28169 card->index);
28170 - atomic_inc(&vcc->stats->rx_drop);
28171 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28172 recycle_rx_buf(card, skb);
28173 return;
28174 }
28175 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28176 small or large buffer itself. */
28177 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28178 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28179 - atomic_inc(&vcc->stats->rx_err);
28180 + atomic_inc_unchecked(&vcc->stats->rx_err);
28181 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28182 NS_MAX_IOVECS);
28183 NS_PRV_IOVCNT(iovb) = 0;
28184 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28185 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28186 card->index);
28187 which_list(card, skb);
28188 - atomic_inc(&vcc->stats->rx_err);
28189 + atomic_inc_unchecked(&vcc->stats->rx_err);
28190 recycle_rx_buf(card, skb);
28191 vc->rx_iov = NULL;
28192 recycle_iov_buf(card, iovb);
28193 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28194 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28195 card->index);
28196 which_list(card, skb);
28197 - atomic_inc(&vcc->stats->rx_err);
28198 + atomic_inc_unchecked(&vcc->stats->rx_err);
28199 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28200 NS_PRV_IOVCNT(iovb));
28201 vc->rx_iov = NULL;
28202 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28203 printk(" - PDU size mismatch.\n");
28204 else
28205 printk(".\n");
28206 - atomic_inc(&vcc->stats->rx_err);
28207 + atomic_inc_unchecked(&vcc->stats->rx_err);
28208 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28209 NS_PRV_IOVCNT(iovb));
28210 vc->rx_iov = NULL;
28211 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28212 /* skb points to a small buffer */
28213 if (!atm_charge(vcc, skb->truesize)) {
28214 push_rxbufs(card, skb);
28215 - atomic_inc(&vcc->stats->rx_drop);
28216 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28217 } else {
28218 skb_put(skb, len);
28219 dequeue_sm_buf(card, skb);
28220 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28221 ATM_SKB(skb)->vcc = vcc;
28222 __net_timestamp(skb);
28223 vcc->push(vcc, skb);
28224 - atomic_inc(&vcc->stats->rx);
28225 + atomic_inc_unchecked(&vcc->stats->rx);
28226 }
28227 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28228 struct sk_buff *sb;
28229 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28230 if (len <= NS_SMBUFSIZE) {
28231 if (!atm_charge(vcc, sb->truesize)) {
28232 push_rxbufs(card, sb);
28233 - atomic_inc(&vcc->stats->rx_drop);
28234 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28235 } else {
28236 skb_put(sb, len);
28237 dequeue_sm_buf(card, sb);
28238 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28239 ATM_SKB(sb)->vcc = vcc;
28240 __net_timestamp(sb);
28241 vcc->push(vcc, sb);
28242 - atomic_inc(&vcc->stats->rx);
28243 + atomic_inc_unchecked(&vcc->stats->rx);
28244 }
28245
28246 push_rxbufs(card, skb);
28247 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28248
28249 if (!atm_charge(vcc, skb->truesize)) {
28250 push_rxbufs(card, skb);
28251 - atomic_inc(&vcc->stats->rx_drop);
28252 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28253 } else {
28254 dequeue_lg_buf(card, skb);
28255 #ifdef NS_USE_DESTRUCTORS
28256 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28257 ATM_SKB(skb)->vcc = vcc;
28258 __net_timestamp(skb);
28259 vcc->push(vcc, skb);
28260 - atomic_inc(&vcc->stats->rx);
28261 + atomic_inc_unchecked(&vcc->stats->rx);
28262 }
28263
28264 push_rxbufs(card, sb);
28265 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28266 printk
28267 ("nicstar%d: Out of huge buffers.\n",
28268 card->index);
28269 - atomic_inc(&vcc->stats->rx_drop);
28270 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28271 recycle_iovec_rx_bufs(card,
28272 (struct iovec *)
28273 iovb->data,
28274 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28275 card->hbpool.count++;
28276 } else
28277 dev_kfree_skb_any(hb);
28278 - atomic_inc(&vcc->stats->rx_drop);
28279 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28280 } else {
28281 /* Copy the small buffer to the huge buffer */
28282 sb = (struct sk_buff *)iov->iov_base;
28283 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28284 #endif /* NS_USE_DESTRUCTORS */
28285 __net_timestamp(hb);
28286 vcc->push(vcc, hb);
28287 - atomic_inc(&vcc->stats->rx);
28288 + atomic_inc_unchecked(&vcc->stats->rx);
28289 }
28290 }
28291
28292 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28293 index 5d1d076..12fbca4 100644
28294 --- a/drivers/atm/solos-pci.c
28295 +++ b/drivers/atm/solos-pci.c
28296 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28297 }
28298 atm_charge(vcc, skb->truesize);
28299 vcc->push(vcc, skb);
28300 - atomic_inc(&vcc->stats->rx);
28301 + atomic_inc_unchecked(&vcc->stats->rx);
28302 break;
28303
28304 case PKT_STATUS:
28305 @@ -1008,7 +1008,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28306 vcc = SKB_CB(oldskb)->vcc;
28307
28308 if (vcc) {
28309 - atomic_inc(&vcc->stats->tx);
28310 + atomic_inc_unchecked(&vcc->stats->tx);
28311 solos_pop(vcc, oldskb);
28312 } else
28313 dev_kfree_skb_irq(oldskb);
28314 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28315 index 90f1ccc..04c4a1e 100644
28316 --- a/drivers/atm/suni.c
28317 +++ b/drivers/atm/suni.c
28318 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28319
28320
28321 #define ADD_LIMITED(s,v) \
28322 - atomic_add((v),&stats->s); \
28323 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28324 + atomic_add_unchecked((v),&stats->s); \
28325 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28326
28327
28328 static void suni_hz(unsigned long from_timer)
28329 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28330 index 5120a96..e2572bd 100644
28331 --- a/drivers/atm/uPD98402.c
28332 +++ b/drivers/atm/uPD98402.c
28333 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28334 struct sonet_stats tmp;
28335 int error = 0;
28336
28337 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28338 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28339 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28340 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28341 if (zero && !error) {
28342 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28343
28344
28345 #define ADD_LIMITED(s,v) \
28346 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28347 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28348 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28349 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28350 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28351 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28352
28353
28354 static void stat_event(struct atm_dev *dev)
28355 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28356 if (reason & uPD98402_INT_PFM) stat_event(dev);
28357 if (reason & uPD98402_INT_PCO) {
28358 (void) GET(PCOCR); /* clear interrupt cause */
28359 - atomic_add(GET(HECCT),
28360 + atomic_add_unchecked(GET(HECCT),
28361 &PRIV(dev)->sonet_stats.uncorr_hcs);
28362 }
28363 if ((reason & uPD98402_INT_RFO) &&
28364 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28365 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28366 uPD98402_INT_LOS),PIMR); /* enable them */
28367 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28368 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28369 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28370 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28371 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28372 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28373 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28374 return 0;
28375 }
28376
28377 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28378 index d889f56..17eb71e 100644
28379 --- a/drivers/atm/zatm.c
28380 +++ b/drivers/atm/zatm.c
28381 @@ -460,7 +460,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28382 }
28383 if (!size) {
28384 dev_kfree_skb_irq(skb);
28385 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28386 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28387 continue;
28388 }
28389 if (!atm_charge(vcc,skb->truesize)) {
28390 @@ -470,7 +470,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28391 skb->len = size;
28392 ATM_SKB(skb)->vcc = vcc;
28393 vcc->push(vcc,skb);
28394 - atomic_inc(&vcc->stats->rx);
28395 + atomic_inc_unchecked(&vcc->stats->rx);
28396 }
28397 zout(pos & 0xffff,MTA(mbx));
28398 #if 0 /* probably a stupid idea */
28399 @@ -734,7 +734,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28400 skb_queue_head(&zatm_vcc->backlog,skb);
28401 break;
28402 }
28403 - atomic_inc(&vcc->stats->tx);
28404 + atomic_inc_unchecked(&vcc->stats->tx);
28405 wake_up(&zatm_vcc->tx_wait);
28406 }
28407
28408 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28409 index a4760e0..51283cf 100644
28410 --- a/drivers/base/devtmpfs.c
28411 +++ b/drivers/base/devtmpfs.c
28412 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28413 if (!thread)
28414 return 0;
28415
28416 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28417 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28418 if (err)
28419 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28420 else
28421 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28422 index caf995f..6f76697 100644
28423 --- a/drivers/base/power/wakeup.c
28424 +++ b/drivers/base/power/wakeup.c
28425 @@ -30,14 +30,14 @@ bool events_check_enabled;
28426 * They need to be modified together atomically, so it's better to use one
28427 * atomic variable to hold them both.
28428 */
28429 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28430 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28431
28432 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28433 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28434
28435 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28436 {
28437 - unsigned int comb = atomic_read(&combined_event_count);
28438 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
28439
28440 *cnt = (comb >> IN_PROGRESS_BITS);
28441 *inpr = comb & MAX_IN_PROGRESS;
28442 @@ -353,7 +353,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28443 ws->last_time = ktime_get();
28444
28445 /* Increment the counter of events in progress. */
28446 - atomic_inc(&combined_event_count);
28447 + atomic_inc_unchecked(&combined_event_count);
28448 }
28449
28450 /**
28451 @@ -443,7 +443,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28452 * Increment the counter of registered wakeup events and decrement the
28453 * couter of wakeup events in progress simultaneously.
28454 */
28455 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
28456 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28457 }
28458
28459 /**
28460 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28461 index b0f553b..77b928b 100644
28462 --- a/drivers/block/cciss.c
28463 +++ b/drivers/block/cciss.c
28464 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28465 int err;
28466 u32 cp;
28467
28468 + memset(&arg64, 0, sizeof(arg64));
28469 +
28470 err = 0;
28471 err |=
28472 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28473 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28474 while (!list_empty(&h->reqQ)) {
28475 c = list_entry(h->reqQ.next, CommandList_struct, list);
28476 /* can't do anything if fifo is full */
28477 - if ((h->access.fifo_full(h))) {
28478 + if ((h->access->fifo_full(h))) {
28479 dev_warn(&h->pdev->dev, "fifo full\n");
28480 break;
28481 }
28482 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28483 h->Qdepth--;
28484
28485 /* Tell the controller execute command */
28486 - h->access.submit_command(h, c);
28487 + h->access->submit_command(h, c);
28488
28489 /* Put job onto the completed Q */
28490 addQ(&h->cmpQ, c);
28491 @@ -3443,17 +3445,17 @@ startio:
28492
28493 static inline unsigned long get_next_completion(ctlr_info_t *h)
28494 {
28495 - return h->access.command_completed(h);
28496 + return h->access->command_completed(h);
28497 }
28498
28499 static inline int interrupt_pending(ctlr_info_t *h)
28500 {
28501 - return h->access.intr_pending(h);
28502 + return h->access->intr_pending(h);
28503 }
28504
28505 static inline long interrupt_not_for_us(ctlr_info_t *h)
28506 {
28507 - return ((h->access.intr_pending(h) == 0) ||
28508 + return ((h->access->intr_pending(h) == 0) ||
28509 (h->interrupts_enabled == 0));
28510 }
28511
28512 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28513 u32 a;
28514
28515 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28516 - return h->access.command_completed(h);
28517 + return h->access->command_completed(h);
28518
28519 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28520 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28521 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28522 trans_support & CFGTBL_Trans_use_short_tags);
28523
28524 /* Change the access methods to the performant access methods */
28525 - h->access = SA5_performant_access;
28526 + h->access = &SA5_performant_access;
28527 h->transMethod = CFGTBL_Trans_Performant;
28528
28529 return;
28530 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28531 if (prod_index < 0)
28532 return -ENODEV;
28533 h->product_name = products[prod_index].product_name;
28534 - h->access = *(products[prod_index].access);
28535 + h->access = products[prod_index].access;
28536
28537 if (cciss_board_disabled(h)) {
28538 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28539 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28540 }
28541
28542 /* make sure the board interrupts are off */
28543 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28544 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28545 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28546 if (rc)
28547 goto clean2;
28548 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28549 * fake ones to scoop up any residual completions.
28550 */
28551 spin_lock_irqsave(&h->lock, flags);
28552 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28553 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28554 spin_unlock_irqrestore(&h->lock, flags);
28555 free_irq(h->intr[h->intr_mode], h);
28556 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28557 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28558 dev_info(&h->pdev->dev, "Board READY.\n");
28559 dev_info(&h->pdev->dev,
28560 "Waiting for stale completions to drain.\n");
28561 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28562 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28563 msleep(10000);
28564 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28565 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28566
28567 rc = controller_reset_failed(h->cfgtable);
28568 if (rc)
28569 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28570 cciss_scsi_setup(h);
28571
28572 /* Turn the interrupts on so we can service requests */
28573 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28574 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28575
28576 /* Get the firmware version */
28577 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28578 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28579 kfree(flush_buf);
28580 if (return_code != IO_OK)
28581 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28582 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28583 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28584 free_irq(h->intr[h->intr_mode], h);
28585 }
28586
28587 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28588 index 7fda30e..eb5dfe0 100644
28589 --- a/drivers/block/cciss.h
28590 +++ b/drivers/block/cciss.h
28591 @@ -101,7 +101,7 @@ struct ctlr_info
28592 /* information about each logical volume */
28593 drive_info_struct *drv[CISS_MAX_LUN];
28594
28595 - struct access_method access;
28596 + struct access_method *access;
28597
28598 /* queue and queue Info */
28599 struct list_head reqQ;
28600 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28601 index 9125bbe..eede5c8 100644
28602 --- a/drivers/block/cpqarray.c
28603 +++ b/drivers/block/cpqarray.c
28604 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28605 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28606 goto Enomem4;
28607 }
28608 - hba[i]->access.set_intr_mask(hba[i], 0);
28609 + hba[i]->access->set_intr_mask(hba[i], 0);
28610 if (request_irq(hba[i]->intr, do_ida_intr,
28611 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28612 {
28613 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28614 add_timer(&hba[i]->timer);
28615
28616 /* Enable IRQ now that spinlock and rate limit timer are set up */
28617 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28618 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28619
28620 for(j=0; j<NWD; j++) {
28621 struct gendisk *disk = ida_gendisk[i][j];
28622 @@ -694,7 +694,7 @@ DBGINFO(
28623 for(i=0; i<NR_PRODUCTS; i++) {
28624 if (board_id == products[i].board_id) {
28625 c->product_name = products[i].product_name;
28626 - c->access = *(products[i].access);
28627 + c->access = products[i].access;
28628 break;
28629 }
28630 }
28631 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28632 hba[ctlr]->intr = intr;
28633 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28634 hba[ctlr]->product_name = products[j].product_name;
28635 - hba[ctlr]->access = *(products[j].access);
28636 + hba[ctlr]->access = products[j].access;
28637 hba[ctlr]->ctlr = ctlr;
28638 hba[ctlr]->board_id = board_id;
28639 hba[ctlr]->pci_dev = NULL; /* not PCI */
28640 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28641
28642 while((c = h->reqQ) != NULL) {
28643 /* Can't do anything if we're busy */
28644 - if (h->access.fifo_full(h) == 0)
28645 + if (h->access->fifo_full(h) == 0)
28646 return;
28647
28648 /* Get the first entry from the request Q */
28649 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28650 h->Qdepth--;
28651
28652 /* Tell the controller to do our bidding */
28653 - h->access.submit_command(h, c);
28654 + h->access->submit_command(h, c);
28655
28656 /* Get onto the completion Q */
28657 addQ(&h->cmpQ, c);
28658 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28659 unsigned long flags;
28660 __u32 a,a1;
28661
28662 - istat = h->access.intr_pending(h);
28663 + istat = h->access->intr_pending(h);
28664 /* Is this interrupt for us? */
28665 if (istat == 0)
28666 return IRQ_NONE;
28667 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28668 */
28669 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
28670 if (istat & FIFO_NOT_EMPTY) {
28671 - while((a = h->access.command_completed(h))) {
28672 + while((a = h->access->command_completed(h))) {
28673 a1 = a; a &= ~3;
28674 if ((c = h->cmpQ) == NULL)
28675 {
28676 @@ -1449,11 +1449,11 @@ static int sendcmd(
28677 /*
28678 * Disable interrupt
28679 */
28680 - info_p->access.set_intr_mask(info_p, 0);
28681 + info_p->access->set_intr_mask(info_p, 0);
28682 /* Make sure there is room in the command FIFO */
28683 /* Actually it should be completely empty at this time. */
28684 for (i = 200000; i > 0; i--) {
28685 - temp = info_p->access.fifo_full(info_p);
28686 + temp = info_p->access->fifo_full(info_p);
28687 if (temp != 0) {
28688 break;
28689 }
28690 @@ -1466,7 +1466,7 @@ DBG(
28691 /*
28692 * Send the cmd
28693 */
28694 - info_p->access.submit_command(info_p, c);
28695 + info_p->access->submit_command(info_p, c);
28696 complete = pollcomplete(ctlr);
28697
28698 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
28699 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
28700 * we check the new geometry. Then turn interrupts back on when
28701 * we're done.
28702 */
28703 - host->access.set_intr_mask(host, 0);
28704 + host->access->set_intr_mask(host, 0);
28705 getgeometry(ctlr);
28706 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
28707 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
28708
28709 for(i=0; i<NWD; i++) {
28710 struct gendisk *disk = ida_gendisk[ctlr][i];
28711 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
28712 /* Wait (up to 2 seconds) for a command to complete */
28713
28714 for (i = 200000; i > 0; i--) {
28715 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
28716 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
28717 if (done == 0) {
28718 udelay(10); /* a short fixed delay */
28719 } else
28720 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
28721 index be73e9d..7fbf140 100644
28722 --- a/drivers/block/cpqarray.h
28723 +++ b/drivers/block/cpqarray.h
28724 @@ -99,7 +99,7 @@ struct ctlr_info {
28725 drv_info_t drv[NWD];
28726 struct proc_dir_entry *proc;
28727
28728 - struct access_method access;
28729 + struct access_method *access;
28730
28731 cmdlist_t *reqQ;
28732 cmdlist_t *cmpQ;
28733 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
28734 index 9cf2035..bffca95 100644
28735 --- a/drivers/block/drbd/drbd_int.h
28736 +++ b/drivers/block/drbd/drbd_int.h
28737 @@ -736,7 +736,7 @@ struct drbd_request;
28738 struct drbd_epoch {
28739 struct list_head list;
28740 unsigned int barrier_nr;
28741 - atomic_t epoch_size; /* increased on every request added. */
28742 + atomic_unchecked_t epoch_size; /* increased on every request added. */
28743 atomic_t active; /* increased on every req. added, and dec on every finished. */
28744 unsigned long flags;
28745 };
28746 @@ -1108,7 +1108,7 @@ struct drbd_conf {
28747 void *int_dig_in;
28748 void *int_dig_vv;
28749 wait_queue_head_t seq_wait;
28750 - atomic_t packet_seq;
28751 + atomic_unchecked_t packet_seq;
28752 unsigned int peer_seq;
28753 spinlock_t peer_seq_lock;
28754 unsigned int minor;
28755 @@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
28756
28757 static inline void drbd_tcp_cork(struct socket *sock)
28758 {
28759 - int __user val = 1;
28760 + int val = 1;
28761 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
28762 - (char __user *)&val, sizeof(val));
28763 + (char __force_user *)&val, sizeof(val));
28764 }
28765
28766 static inline void drbd_tcp_uncork(struct socket *sock)
28767 {
28768 - int __user val = 0;
28769 + int val = 0;
28770 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
28771 - (char __user *)&val, sizeof(val));
28772 + (char __force_user *)&val, sizeof(val));
28773 }
28774
28775 static inline void drbd_tcp_nodelay(struct socket *sock)
28776 {
28777 - int __user val = 1;
28778 + int val = 1;
28779 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
28780 - (char __user *)&val, sizeof(val));
28781 + (char __force_user *)&val, sizeof(val));
28782 }
28783
28784 static inline void drbd_tcp_quickack(struct socket *sock)
28785 {
28786 - int __user val = 2;
28787 + int val = 2;
28788 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
28789 - (char __user *)&val, sizeof(val));
28790 + (char __force_user *)&val, sizeof(val));
28791 }
28792
28793 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
28794 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
28795 index 0358e55..bc33689 100644
28796 --- a/drivers/block/drbd/drbd_main.c
28797 +++ b/drivers/block/drbd/drbd_main.c
28798 @@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
28799 p.sector = sector;
28800 p.block_id = block_id;
28801 p.blksize = blksize;
28802 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
28803 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
28804
28805 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
28806 return false;
28807 @@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
28808 p.sector = cpu_to_be64(req->sector);
28809 p.block_id = (unsigned long)req;
28810 p.seq_num = cpu_to_be32(req->seq_num =
28811 - atomic_add_return(1, &mdev->packet_seq));
28812 + atomic_add_return_unchecked(1, &mdev->packet_seq));
28813
28814 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
28815
28816 @@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
28817 atomic_set(&mdev->unacked_cnt, 0);
28818 atomic_set(&mdev->local_cnt, 0);
28819 atomic_set(&mdev->net_cnt, 0);
28820 - atomic_set(&mdev->packet_seq, 0);
28821 + atomic_set_unchecked(&mdev->packet_seq, 0);
28822 atomic_set(&mdev->pp_in_use, 0);
28823 atomic_set(&mdev->pp_in_use_by_net, 0);
28824 atomic_set(&mdev->rs_sect_in, 0);
28825 @@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
28826 mdev->receiver.t_state);
28827
28828 /* no need to lock it, I'm the only thread alive */
28829 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
28830 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
28831 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
28832 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
28833 mdev->al_writ_cnt =
28834 mdev->bm_writ_cnt =
28835 mdev->read_cnt =
28836 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
28837 index af2a250..219c74b 100644
28838 --- a/drivers/block/drbd/drbd_nl.c
28839 +++ b/drivers/block/drbd/drbd_nl.c
28840 @@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
28841 module_put(THIS_MODULE);
28842 }
28843
28844 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
28845 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
28846
28847 static unsigned short *
28848 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
28849 @@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
28850 cn_reply->id.idx = CN_IDX_DRBD;
28851 cn_reply->id.val = CN_VAL_DRBD;
28852
28853 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28854 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28855 cn_reply->ack = 0; /* not used here. */
28856 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28857 (int)((char *)tl - (char *)reply->tag_list);
28858 @@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
28859 cn_reply->id.idx = CN_IDX_DRBD;
28860 cn_reply->id.val = CN_VAL_DRBD;
28861
28862 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28863 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28864 cn_reply->ack = 0; /* not used here. */
28865 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28866 (int)((char *)tl - (char *)reply->tag_list);
28867 @@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
28868 cn_reply->id.idx = CN_IDX_DRBD;
28869 cn_reply->id.val = CN_VAL_DRBD;
28870
28871 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
28872 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
28873 cn_reply->ack = 0; // not used here.
28874 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28875 (int)((char*)tl - (char*)reply->tag_list);
28876 @@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
28877 cn_reply->id.idx = CN_IDX_DRBD;
28878 cn_reply->id.val = CN_VAL_DRBD;
28879
28880 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28881 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28882 cn_reply->ack = 0; /* not used here. */
28883 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28884 (int)((char *)tl - (char *)reply->tag_list);
28885 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
28886 index 43beaca..4a5b1dd 100644
28887 --- a/drivers/block/drbd/drbd_receiver.c
28888 +++ b/drivers/block/drbd/drbd_receiver.c
28889 @@ -894,7 +894,7 @@ retry:
28890 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
28891 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
28892
28893 - atomic_set(&mdev->packet_seq, 0);
28894 + atomic_set_unchecked(&mdev->packet_seq, 0);
28895 mdev->peer_seq = 0;
28896
28897 drbd_thread_start(&mdev->asender);
28898 @@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
28899 do {
28900 next_epoch = NULL;
28901
28902 - epoch_size = atomic_read(&epoch->epoch_size);
28903 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
28904
28905 switch (ev & ~EV_CLEANUP) {
28906 case EV_PUT:
28907 @@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
28908 rv = FE_DESTROYED;
28909 } else {
28910 epoch->flags = 0;
28911 - atomic_set(&epoch->epoch_size, 0);
28912 + atomic_set_unchecked(&epoch->epoch_size, 0);
28913 /* atomic_set(&epoch->active, 0); is already zero */
28914 if (rv == FE_STILL_LIVE)
28915 rv = FE_RECYCLED;
28916 @@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
28917 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
28918 drbd_flush(mdev);
28919
28920 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
28921 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
28922 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
28923 if (epoch)
28924 break;
28925 }
28926
28927 epoch = mdev->current_epoch;
28928 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
28929 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
28930
28931 D_ASSERT(atomic_read(&epoch->active) == 0);
28932 D_ASSERT(epoch->flags == 0);
28933 @@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
28934 }
28935
28936 epoch->flags = 0;
28937 - atomic_set(&epoch->epoch_size, 0);
28938 + atomic_set_unchecked(&epoch->epoch_size, 0);
28939 atomic_set(&epoch->active, 0);
28940
28941 spin_lock(&mdev->epoch_lock);
28942 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
28943 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
28944 list_add(&epoch->list, &mdev->current_epoch->list);
28945 mdev->current_epoch = epoch;
28946 mdev->epochs++;
28947 @@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
28948 spin_unlock(&mdev->peer_seq_lock);
28949
28950 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
28951 - atomic_inc(&mdev->current_epoch->epoch_size);
28952 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
28953 return drbd_drain_block(mdev, data_size);
28954 }
28955
28956 @@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
28957
28958 spin_lock(&mdev->epoch_lock);
28959 e->epoch = mdev->current_epoch;
28960 - atomic_inc(&e->epoch->epoch_size);
28961 + atomic_inc_unchecked(&e->epoch->epoch_size);
28962 atomic_inc(&e->epoch->active);
28963 spin_unlock(&mdev->epoch_lock);
28964
28965 @@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
28966 D_ASSERT(list_empty(&mdev->done_ee));
28967
28968 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
28969 - atomic_set(&mdev->current_epoch->epoch_size, 0);
28970 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
28971 D_ASSERT(list_empty(&mdev->current_epoch->list));
28972 }
28973
28974 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
28975 index 1e888c9..05cf1b0 100644
28976 --- a/drivers/block/loop.c
28977 +++ b/drivers/block/loop.c
28978 @@ -227,7 +227,7 @@ static int __do_lo_send_write(struct file *file,
28979 mm_segment_t old_fs = get_fs();
28980
28981 set_fs(get_ds());
28982 - bw = file->f_op->write(file, buf, len, &pos);
28983 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
28984 set_fs(old_fs);
28985 if (likely(bw == len))
28986 return 0;
28987 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
28988 index 4364303..9adf4ee 100644
28989 --- a/drivers/char/Kconfig
28990 +++ b/drivers/char/Kconfig
28991 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
28992
28993 config DEVKMEM
28994 bool "/dev/kmem virtual device support"
28995 - default y
28996 + default n
28997 + depends on !GRKERNSEC_KMEM
28998 help
28999 Say Y here if you want to support the /dev/kmem device. The
29000 /dev/kmem device is rarely used, but can be used for certain
29001 @@ -596,6 +597,7 @@ config DEVPORT
29002 bool
29003 depends on !M68K
29004 depends on ISA || PCI
29005 + depends on !GRKERNSEC_KMEM
29006 default y
29007
29008 source "drivers/s390/char/Kconfig"
29009 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29010 index 2e04433..22afc64 100644
29011 --- a/drivers/char/agp/frontend.c
29012 +++ b/drivers/char/agp/frontend.c
29013 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29014 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29015 return -EFAULT;
29016
29017 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29018 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29019 return -EFAULT;
29020
29021 client = agp_find_client_by_pid(reserve.pid);
29022 diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
29023 index 095ab90..afad0a4 100644
29024 --- a/drivers/char/briq_panel.c
29025 +++ b/drivers/char/briq_panel.c
29026 @@ -9,6 +9,7 @@
29027 #include <linux/types.h>
29028 #include <linux/errno.h>
29029 #include <linux/tty.h>
29030 +#include <linux/mutex.h>
29031 #include <linux/timer.h>
29032 #include <linux/kernel.h>
29033 #include <linux/wait.h>
29034 @@ -34,6 +35,7 @@ static int vfd_is_open;
29035 static unsigned char vfd[40];
29036 static int vfd_cursor;
29037 static unsigned char ledpb, led;
29038 +static DEFINE_MUTEX(vfd_mutex);
29039
29040 static void update_vfd(void)
29041 {
29042 @@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
29043 if (!vfd_is_open)
29044 return -EBUSY;
29045
29046 + mutex_lock(&vfd_mutex);
29047 for (;;) {
29048 char c;
29049 if (!indx)
29050 break;
29051 - if (get_user(c, buf))
29052 + if (get_user(c, buf)) {
29053 + mutex_unlock(&vfd_mutex);
29054 return -EFAULT;
29055 + }
29056 if (esc) {
29057 set_led(c);
29058 esc = 0;
29059 @@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
29060 buf++;
29061 }
29062 update_vfd();
29063 + mutex_unlock(&vfd_mutex);
29064
29065 return len;
29066 }
29067 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29068 index f773a9d..65cd683 100644
29069 --- a/drivers/char/genrtc.c
29070 +++ b/drivers/char/genrtc.c
29071 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
29072 switch (cmd) {
29073
29074 case RTC_PLL_GET:
29075 + memset(&pll, 0, sizeof(pll));
29076 if (get_rtc_pll(&pll))
29077 return -EINVAL;
29078 else
29079 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29080 index 0833896..cccce52 100644
29081 --- a/drivers/char/hpet.c
29082 +++ b/drivers/char/hpet.c
29083 @@ -572,7 +572,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29084 }
29085
29086 static int
29087 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29088 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29089 struct hpet_info *info)
29090 {
29091 struct hpet_timer __iomem *timer;
29092 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29093 index 58c0e63..46c16bf 100644
29094 --- a/drivers/char/ipmi/ipmi_msghandler.c
29095 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29096 @@ -415,7 +415,7 @@ struct ipmi_smi {
29097 struct proc_dir_entry *proc_dir;
29098 char proc_dir_name[10];
29099
29100 - atomic_t stats[IPMI_NUM_STATS];
29101 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29102
29103 /*
29104 * run_to_completion duplicate of smb_info, smi_info
29105 @@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29106
29107
29108 #define ipmi_inc_stat(intf, stat) \
29109 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29110 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29111 #define ipmi_get_stat(intf, stat) \
29112 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29113 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29114
29115 static int is_lan_addr(struct ipmi_addr *addr)
29116 {
29117 @@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29118 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29119 init_waitqueue_head(&intf->waitq);
29120 for (i = 0; i < IPMI_NUM_STATS; i++)
29121 - atomic_set(&intf->stats[i], 0);
29122 + atomic_set_unchecked(&intf->stats[i], 0);
29123
29124 intf->proc_dir = NULL;
29125
29126 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29127 index 9397ab4..d01bee1 100644
29128 --- a/drivers/char/ipmi/ipmi_si_intf.c
29129 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29130 @@ -277,7 +277,7 @@ struct smi_info {
29131 unsigned char slave_addr;
29132
29133 /* Counters and things for the proc filesystem. */
29134 - atomic_t stats[SI_NUM_STATS];
29135 + atomic_unchecked_t stats[SI_NUM_STATS];
29136
29137 struct task_struct *thread;
29138
29139 @@ -286,9 +286,9 @@ struct smi_info {
29140 };
29141
29142 #define smi_inc_stat(smi, stat) \
29143 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29144 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29145 #define smi_get_stat(smi, stat) \
29146 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29147 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29148
29149 #define SI_MAX_PARMS 4
29150
29151 @@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info *new_smi)
29152 atomic_set(&new_smi->req_events, 0);
29153 new_smi->run_to_completion = 0;
29154 for (i = 0; i < SI_NUM_STATS; i++)
29155 - atomic_set(&new_smi->stats[i], 0);
29156 + atomic_set_unchecked(&new_smi->stats[i], 0);
29157
29158 new_smi->interrupt_disabled = 1;
29159 atomic_set(&new_smi->stop_operation, 0);
29160 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29161 index 1aeaaba..e018570 100644
29162 --- a/drivers/char/mbcs.c
29163 +++ b/drivers/char/mbcs.c
29164 @@ -800,7 +800,7 @@ static int mbcs_remove(struct cx_dev *dev)
29165 return 0;
29166 }
29167
29168 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29169 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29170 {
29171 .part_num = MBCS_PART_NUM,
29172 .mfg_num = MBCS_MFG_NUM,
29173 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29174 index 1451790..f705c30 100644
29175 --- a/drivers/char/mem.c
29176 +++ b/drivers/char/mem.c
29177 @@ -18,6 +18,7 @@
29178 #include <linux/raw.h>
29179 #include <linux/tty.h>
29180 #include <linux/capability.h>
29181 +#include <linux/security.h>
29182 #include <linux/ptrace.h>
29183 #include <linux/device.h>
29184 #include <linux/highmem.h>
29185 @@ -35,6 +36,10 @@
29186 # include <linux/efi.h>
29187 #endif
29188
29189 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29190 +extern const struct file_operations grsec_fops;
29191 +#endif
29192 +
29193 static inline unsigned long size_inside_page(unsigned long start,
29194 unsigned long size)
29195 {
29196 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29197
29198 while (cursor < to) {
29199 if (!devmem_is_allowed(pfn)) {
29200 +#ifdef CONFIG_GRKERNSEC_KMEM
29201 + gr_handle_mem_readwrite(from, to);
29202 +#else
29203 printk(KERN_INFO
29204 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29205 current->comm, from, to);
29206 +#endif
29207 return 0;
29208 }
29209 cursor += PAGE_SIZE;
29210 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29211 }
29212 return 1;
29213 }
29214 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29215 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29216 +{
29217 + return 0;
29218 +}
29219 #else
29220 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29221 {
29222 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29223
29224 while (count > 0) {
29225 unsigned long remaining;
29226 + char *temp;
29227
29228 sz = size_inside_page(p, count);
29229
29230 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29231 if (!ptr)
29232 return -EFAULT;
29233
29234 - remaining = copy_to_user(buf, ptr, sz);
29235 +#ifdef CONFIG_PAX_USERCOPY
29236 + temp = kmalloc(sz, GFP_KERNEL);
29237 + if (!temp) {
29238 + unxlate_dev_mem_ptr(p, ptr);
29239 + return -ENOMEM;
29240 + }
29241 + memcpy(temp, ptr, sz);
29242 +#else
29243 + temp = ptr;
29244 +#endif
29245 +
29246 + remaining = copy_to_user(buf, temp, sz);
29247 +
29248 +#ifdef CONFIG_PAX_USERCOPY
29249 + kfree(temp);
29250 +#endif
29251 +
29252 unxlate_dev_mem_ptr(p, ptr);
29253 if (remaining)
29254 return -EFAULT;
29255 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29256 size_t count, loff_t *ppos)
29257 {
29258 unsigned long p = *ppos;
29259 - ssize_t low_count, read, sz;
29260 + ssize_t low_count, read, sz, err = 0;
29261 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29262 - int err = 0;
29263
29264 read = 0;
29265 if (p < (unsigned long) high_memory) {
29266 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29267 }
29268 #endif
29269 while (low_count > 0) {
29270 + char *temp;
29271 +
29272 sz = size_inside_page(p, low_count);
29273
29274 /*
29275 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29276 */
29277 kbuf = xlate_dev_kmem_ptr((char *)p);
29278
29279 - if (copy_to_user(buf, kbuf, sz))
29280 +#ifdef CONFIG_PAX_USERCOPY
29281 + temp = kmalloc(sz, GFP_KERNEL);
29282 + if (!temp)
29283 + return -ENOMEM;
29284 + memcpy(temp, kbuf, sz);
29285 +#else
29286 + temp = kbuf;
29287 +#endif
29288 +
29289 + err = copy_to_user(buf, temp, sz);
29290 +
29291 +#ifdef CONFIG_PAX_USERCOPY
29292 + kfree(temp);
29293 +#endif
29294 +
29295 + if (err)
29296 return -EFAULT;
29297 buf += sz;
29298 p += sz;
29299 @@ -867,6 +914,9 @@ static const struct memdev {
29300 #ifdef CONFIG_CRASH_DUMP
29301 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29302 #endif
29303 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29304 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29305 +#endif
29306 };
29307
29308 static int memory_open(struct inode *inode, struct file *filp)
29309 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29310 index da3cfee..a5a6606 100644
29311 --- a/drivers/char/nvram.c
29312 +++ b/drivers/char/nvram.c
29313 @@ -248,7 +248,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29314
29315 spin_unlock_irq(&rtc_lock);
29316
29317 - if (copy_to_user(buf, contents, tmp - contents))
29318 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29319 return -EFAULT;
29320
29321 *ppos = i;
29322 diff --git a/drivers/char/random.c b/drivers/char/random.c
29323 index 6035ab8..bdfe4fd 100644
29324 --- a/drivers/char/random.c
29325 +++ b/drivers/char/random.c
29326 @@ -261,8 +261,13 @@
29327 /*
29328 * Configuration information
29329 */
29330 +#ifdef CONFIG_GRKERNSEC_RANDNET
29331 +#define INPUT_POOL_WORDS 512
29332 +#define OUTPUT_POOL_WORDS 128
29333 +#else
29334 #define INPUT_POOL_WORDS 128
29335 #define OUTPUT_POOL_WORDS 32
29336 +#endif
29337 #define SEC_XFER_SIZE 512
29338 #define EXTRACT_SIZE 10
29339
29340 @@ -300,10 +305,17 @@ static struct poolinfo {
29341 int poolwords;
29342 int tap1, tap2, tap3, tap4, tap5;
29343 } poolinfo_table[] = {
29344 +#ifdef CONFIG_GRKERNSEC_RANDNET
29345 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29346 + { 512, 411, 308, 208, 104, 1 },
29347 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29348 + { 128, 103, 76, 51, 25, 1 },
29349 +#else
29350 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29351 { 128, 103, 76, 51, 25, 1 },
29352 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29353 { 32, 26, 20, 14, 7, 1 },
29354 +#endif
29355 #if 0
29356 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29357 { 2048, 1638, 1231, 819, 411, 1 },
29358 @@ -909,7 +921,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29359
29360 extract_buf(r, tmp);
29361 i = min_t(int, nbytes, EXTRACT_SIZE);
29362 - if (copy_to_user(buf, tmp, i)) {
29363 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29364 ret = -EFAULT;
29365 break;
29366 }
29367 @@ -1228,7 +1240,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29368 #include <linux/sysctl.h>
29369
29370 static int min_read_thresh = 8, min_write_thresh;
29371 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29372 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29373 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29374 static char sysctl_bootid[16];
29375
29376 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29377 index 1ee8ce7..b778bef 100644
29378 --- a/drivers/char/sonypi.c
29379 +++ b/drivers/char/sonypi.c
29380 @@ -55,6 +55,7 @@
29381 #include <asm/uaccess.h>
29382 #include <asm/io.h>
29383 #include <asm/system.h>
29384 +#include <asm/local.h>
29385
29386 #include <linux/sonypi.h>
29387
29388 @@ -491,7 +492,7 @@ static struct sonypi_device {
29389 spinlock_t fifo_lock;
29390 wait_queue_head_t fifo_proc_list;
29391 struct fasync_struct *fifo_async;
29392 - int open_count;
29393 + local_t open_count;
29394 int model;
29395 struct input_dev *input_jog_dev;
29396 struct input_dev *input_key_dev;
29397 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29398 static int sonypi_misc_release(struct inode *inode, struct file *file)
29399 {
29400 mutex_lock(&sonypi_device.lock);
29401 - sonypi_device.open_count--;
29402 + local_dec(&sonypi_device.open_count);
29403 mutex_unlock(&sonypi_device.lock);
29404 return 0;
29405 }
29406 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29407 {
29408 mutex_lock(&sonypi_device.lock);
29409 /* Flush input queue on first open */
29410 - if (!sonypi_device.open_count)
29411 + if (!local_read(&sonypi_device.open_count))
29412 kfifo_reset(&sonypi_device.fifo);
29413 - sonypi_device.open_count++;
29414 + local_inc(&sonypi_device.open_count);
29415 mutex_unlock(&sonypi_device.lock);
29416
29417 return 0;
29418 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29419 index 361a1df..2471eee 100644
29420 --- a/drivers/char/tpm/tpm.c
29421 +++ b/drivers/char/tpm/tpm.c
29422 @@ -414,7 +414,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29423 chip->vendor.req_complete_val)
29424 goto out_recv;
29425
29426 - if ((status == chip->vendor.req_canceled)) {
29427 + if (status == chip->vendor.req_canceled) {
29428 dev_err(chip->dev, "Operation Canceled\n");
29429 rc = -ECANCELED;
29430 goto out;
29431 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29432 index 0636520..169c1d0 100644
29433 --- a/drivers/char/tpm/tpm_bios.c
29434 +++ b/drivers/char/tpm/tpm_bios.c
29435 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29436 event = addr;
29437
29438 if ((event->event_type == 0 && event->event_size == 0) ||
29439 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29440 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29441 return NULL;
29442
29443 return addr;
29444 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29445 return NULL;
29446
29447 if ((event->event_type == 0 && event->event_size == 0) ||
29448 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29449 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29450 return NULL;
29451
29452 (*pos)++;
29453 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29454 int i;
29455
29456 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29457 - seq_putc(m, data[i]);
29458 + if (!seq_putc(m, data[i]))
29459 + return -EFAULT;
29460
29461 return 0;
29462 }
29463 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29464 log->bios_event_log_end = log->bios_event_log + len;
29465
29466 virt = acpi_os_map_memory(start, len);
29467 + if (!virt) {
29468 + kfree(log->bios_event_log);
29469 + log->bios_event_log = NULL;
29470 + return -EFAULT;
29471 + }
29472
29473 - memcpy(log->bios_event_log, virt, len);
29474 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29475
29476 acpi_os_unmap_memory(virt, len);
29477 return 0;
29478 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29479 index 8e3c46d..c139b99 100644
29480 --- a/drivers/char/virtio_console.c
29481 +++ b/drivers/char/virtio_console.c
29482 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29483 if (to_user) {
29484 ssize_t ret;
29485
29486 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29487 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29488 if (ret)
29489 return -EFAULT;
29490 } else {
29491 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29492 if (!port_has_data(port) && !port->host_connected)
29493 return 0;
29494
29495 - return fill_readbuf(port, ubuf, count, true);
29496 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29497 }
29498
29499 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29500 diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
29501 index eb1d864..39ee5a7 100644
29502 --- a/drivers/dma/dmatest.c
29503 +++ b/drivers/dma/dmatest.c
29504 @@ -591,7 +591,7 @@ static int dmatest_add_channel(struct dma_chan *chan)
29505 }
29506 if (dma_has_cap(DMA_PQ, dma_dev->cap_mask)) {
29507 cnt = dmatest_add_threads(dtc, DMA_PQ);
29508 - thread_count += cnt > 0 ?: 0;
29509 + thread_count += cnt > 0 ? cnt : 0;
29510 }
29511
29512 pr_info("dmatest: Started %u threads using %s\n",
29513 diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
29514 index c9eee6d..f9d5280 100644
29515 --- a/drivers/edac/amd64_edac.c
29516 +++ b/drivers/edac/amd64_edac.c
29517 @@ -2685,7 +2685,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
29518 * PCI core identifies what devices are on a system during boot, and then
29519 * inquiry this table to see if this driver is for a given device found.
29520 */
29521 -static const struct pci_device_id amd64_pci_table[] __devinitdata = {
29522 +static const struct pci_device_id amd64_pci_table[] __devinitconst = {
29523 {
29524 .vendor = PCI_VENDOR_ID_AMD,
29525 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
29526 diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
29527 index e47e73b..348e0bd 100644
29528 --- a/drivers/edac/amd76x_edac.c
29529 +++ b/drivers/edac/amd76x_edac.c
29530 @@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
29531 edac_mc_free(mci);
29532 }
29533
29534 -static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
29535 +static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
29536 {
29537 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29538 AMD762},
29539 diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
29540 index 1af531a..3a8ff27 100644
29541 --- a/drivers/edac/e752x_edac.c
29542 +++ b/drivers/edac/e752x_edac.c
29543 @@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
29544 edac_mc_free(mci);
29545 }
29546
29547 -static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
29548 +static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
29549 {
29550 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29551 E7520},
29552 diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
29553 index 6ffb6d2..383d8d7 100644
29554 --- a/drivers/edac/e7xxx_edac.c
29555 +++ b/drivers/edac/e7xxx_edac.c
29556 @@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
29557 edac_mc_free(mci);
29558 }
29559
29560 -static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
29561 +static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
29562 {
29563 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29564 E7205},
29565 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29566 index 495198a..ac08c85 100644
29567 --- a/drivers/edac/edac_pci_sysfs.c
29568 +++ b/drivers/edac/edac_pci_sysfs.c
29569 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29570 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29571 static int edac_pci_poll_msec = 1000; /* one second workq period */
29572
29573 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
29574 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29575 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29576 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29577
29578 static struct kobject *edac_pci_top_main_kobj;
29579 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29580 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29581 edac_printk(KERN_CRIT, EDAC_PCI,
29582 "Signaled System Error on %s\n",
29583 pci_name(dev));
29584 - atomic_inc(&pci_nonparity_count);
29585 + atomic_inc_unchecked(&pci_nonparity_count);
29586 }
29587
29588 if (status & (PCI_STATUS_PARITY)) {
29589 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29590 "Master Data Parity Error on %s\n",
29591 pci_name(dev));
29592
29593 - atomic_inc(&pci_parity_count);
29594 + atomic_inc_unchecked(&pci_parity_count);
29595 }
29596
29597 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29598 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29599 "Detected Parity Error on %s\n",
29600 pci_name(dev));
29601
29602 - atomic_inc(&pci_parity_count);
29603 + atomic_inc_unchecked(&pci_parity_count);
29604 }
29605 }
29606
29607 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29608 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29609 "Signaled System Error on %s\n",
29610 pci_name(dev));
29611 - atomic_inc(&pci_nonparity_count);
29612 + atomic_inc_unchecked(&pci_nonparity_count);
29613 }
29614
29615 if (status & (PCI_STATUS_PARITY)) {
29616 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29617 "Master Data Parity Error on "
29618 "%s\n", pci_name(dev));
29619
29620 - atomic_inc(&pci_parity_count);
29621 + atomic_inc_unchecked(&pci_parity_count);
29622 }
29623
29624 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29625 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29626 "Detected Parity Error on %s\n",
29627 pci_name(dev));
29628
29629 - atomic_inc(&pci_parity_count);
29630 + atomic_inc_unchecked(&pci_parity_count);
29631 }
29632 }
29633 }
29634 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29635 if (!check_pci_errors)
29636 return;
29637
29638 - before_count = atomic_read(&pci_parity_count);
29639 + before_count = atomic_read_unchecked(&pci_parity_count);
29640
29641 /* scan all PCI devices looking for a Parity Error on devices and
29642 * bridges.
29643 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29644 /* Only if operator has selected panic on PCI Error */
29645 if (edac_pci_get_panic_on_pe()) {
29646 /* If the count is different 'after' from 'before' */
29647 - if (before_count != atomic_read(&pci_parity_count))
29648 + if (before_count != atomic_read_unchecked(&pci_parity_count))
29649 panic("EDAC: PCI Parity Error");
29650 }
29651 }
29652 diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
29653 index c0510b3..6e2a954 100644
29654 --- a/drivers/edac/i3000_edac.c
29655 +++ b/drivers/edac/i3000_edac.c
29656 @@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
29657 edac_mc_free(mci);
29658 }
29659
29660 -static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
29661 +static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
29662 {
29663 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29664 I3000},
29665 diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
29666 index aa08497..7e6822a 100644
29667 --- a/drivers/edac/i3200_edac.c
29668 +++ b/drivers/edac/i3200_edac.c
29669 @@ -456,7 +456,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
29670 edac_mc_free(mci);
29671 }
29672
29673 -static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
29674 +static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
29675 {
29676 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29677 I3200},
29678 diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
29679 index 4dc3ac2..67d05a6 100644
29680 --- a/drivers/edac/i5000_edac.c
29681 +++ b/drivers/edac/i5000_edac.c
29682 @@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
29683 *
29684 * The "E500P" device is the first device supported.
29685 */
29686 -static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
29687 +static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
29688 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
29689 .driver_data = I5000P},
29690
29691 diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
29692 index bcbdeec..9886d16 100644
29693 --- a/drivers/edac/i5100_edac.c
29694 +++ b/drivers/edac/i5100_edac.c
29695 @@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
29696 edac_mc_free(mci);
29697 }
29698
29699 -static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
29700 +static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
29701 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
29702 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
29703 { 0, }
29704 diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
29705 index 74d6ec34..baff517 100644
29706 --- a/drivers/edac/i5400_edac.c
29707 +++ b/drivers/edac/i5400_edac.c
29708 @@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
29709 *
29710 * The "E500P" device is the first device supported.
29711 */
29712 -static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
29713 +static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
29714 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
29715 {0,} /* 0 terminated list. */
29716 };
29717 diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
29718 index 6104dba..e7ea8e1 100644
29719 --- a/drivers/edac/i7300_edac.c
29720 +++ b/drivers/edac/i7300_edac.c
29721 @@ -1192,7 +1192,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
29722 *
29723 * Has only 8086:360c PCI ID
29724 */
29725 -static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
29726 +static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
29727 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
29728 {0,} /* 0 terminated list. */
29729 };
29730 diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
29731 index 70ad892..178943c 100644
29732 --- a/drivers/edac/i7core_edac.c
29733 +++ b/drivers/edac/i7core_edac.c
29734 @@ -391,7 +391,7 @@ static const struct pci_id_table pci_dev_table[] = {
29735 /*
29736 * pci_device_id table for which devices we are looking for
29737 */
29738 -static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
29739 +static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
29740 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
29741 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
29742 {0,} /* 0 terminated list. */
29743 diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
29744 index 4329d39..f3022ef 100644
29745 --- a/drivers/edac/i82443bxgx_edac.c
29746 +++ b/drivers/edac/i82443bxgx_edac.c
29747 @@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
29748
29749 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
29750
29751 -static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
29752 +static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
29753 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
29754 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
29755 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
29756 diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
29757 index 931a057..fd28340 100644
29758 --- a/drivers/edac/i82860_edac.c
29759 +++ b/drivers/edac/i82860_edac.c
29760 @@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
29761 edac_mc_free(mci);
29762 }
29763
29764 -static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
29765 +static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
29766 {
29767 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29768 I82860},
29769 diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
29770 index 33864c6..01edc61 100644
29771 --- a/drivers/edac/i82875p_edac.c
29772 +++ b/drivers/edac/i82875p_edac.c
29773 @@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
29774 edac_mc_free(mci);
29775 }
29776
29777 -static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
29778 +static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
29779 {
29780 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29781 I82875P},
29782 diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
29783 index a5da732..983363b 100644
29784 --- a/drivers/edac/i82975x_edac.c
29785 +++ b/drivers/edac/i82975x_edac.c
29786 @@ -604,7 +604,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
29787 edac_mc_free(mci);
29788 }
29789
29790 -static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
29791 +static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
29792 {
29793 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29794 I82975X
29795 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29796 index 0106747..0b40417 100644
29797 --- a/drivers/edac/mce_amd.h
29798 +++ b/drivers/edac/mce_amd.h
29799 @@ -83,7 +83,7 @@ struct amd_decoder_ops {
29800 bool (*dc_mce)(u16, u8);
29801 bool (*ic_mce)(u16, u8);
29802 bool (*nb_mce)(u16, u8);
29803 -};
29804 +} __no_const;
29805
29806 void amd_report_gart_errors(bool);
29807 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29808 diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
29809 index b153674..ad2ba9b 100644
29810 --- a/drivers/edac/r82600_edac.c
29811 +++ b/drivers/edac/r82600_edac.c
29812 @@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
29813 edac_mc_free(mci);
29814 }
29815
29816 -static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
29817 +static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
29818 {
29819 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
29820 },
29821 diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
29822 index 7a402bf..af0b211 100644
29823 --- a/drivers/edac/sb_edac.c
29824 +++ b/drivers/edac/sb_edac.c
29825 @@ -367,7 +367,7 @@ static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
29826 /*
29827 * pci_device_id table for which devices we are looking for
29828 */
29829 -static const struct pci_device_id sbridge_pci_tbl[] __devinitdata = {
29830 +static const struct pci_device_id sbridge_pci_tbl[] __devinitconst = {
29831 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
29832 {0,} /* 0 terminated list. */
29833 };
29834 diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
29835 index b6f47de..c5acf3a 100644
29836 --- a/drivers/edac/x38_edac.c
29837 +++ b/drivers/edac/x38_edac.c
29838 @@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
29839 edac_mc_free(mci);
29840 }
29841
29842 -static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
29843 +static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
29844 {
29845 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29846 X38},
29847 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29848 index 85661b0..c784559a 100644
29849 --- a/drivers/firewire/core-card.c
29850 +++ b/drivers/firewire/core-card.c
29851 @@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
29852
29853 void fw_core_remove_card(struct fw_card *card)
29854 {
29855 - struct fw_card_driver dummy_driver = dummy_driver_template;
29856 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
29857
29858 card->driver->update_phy_reg(card, 4,
29859 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29860 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29861 index 4799393..37bd3ab 100644
29862 --- a/drivers/firewire/core-cdev.c
29863 +++ b/drivers/firewire/core-cdev.c
29864 @@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
29865 int ret;
29866
29867 if ((request->channels == 0 && request->bandwidth == 0) ||
29868 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29869 - request->bandwidth < 0)
29870 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29871 return -EINVAL;
29872
29873 r = kmalloc(sizeof(*r), GFP_KERNEL);
29874 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
29875 index 855ab3f..11f4bbd 100644
29876 --- a/drivers/firewire/core-transaction.c
29877 +++ b/drivers/firewire/core-transaction.c
29878 @@ -37,6 +37,7 @@
29879 #include <linux/timer.h>
29880 #include <linux/types.h>
29881 #include <linux/workqueue.h>
29882 +#include <linux/sched.h>
29883
29884 #include <asm/byteorder.h>
29885
29886 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
29887 index b45be57..5fad18b 100644
29888 --- a/drivers/firewire/core.h
29889 +++ b/drivers/firewire/core.h
29890 @@ -101,6 +101,7 @@ struct fw_card_driver {
29891
29892 int (*stop_iso)(struct fw_iso_context *ctx);
29893 };
29894 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
29895
29896 void fw_card_initialize(struct fw_card *card,
29897 const struct fw_card_driver *driver, struct device *device);
29898 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
29899 index 153980b..4b4d046 100644
29900 --- a/drivers/firmware/dmi_scan.c
29901 +++ b/drivers/firmware/dmi_scan.c
29902 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
29903 }
29904 }
29905 else {
29906 - /*
29907 - * no iounmap() for that ioremap(); it would be a no-op, but
29908 - * it's so early in setup that sucker gets confused into doing
29909 - * what it shouldn't if we actually call it.
29910 - */
29911 p = dmi_ioremap(0xF0000, 0x10000);
29912 if (p == NULL)
29913 goto error;
29914 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
29915 if (buf == NULL)
29916 return -1;
29917
29918 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
29919 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
29920
29921 iounmap(buf);
29922 return 0;
29923 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
29924 index 98723cb..10ca85b 100644
29925 --- a/drivers/gpio/gpio-vr41xx.c
29926 +++ b/drivers/gpio/gpio-vr41xx.c
29927 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
29928 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
29929 maskl, pendl, maskh, pendh);
29930
29931 - atomic_inc(&irq_err_count);
29932 + atomic_inc_unchecked(&irq_err_count);
29933
29934 return -EINVAL;
29935 }
29936 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
29937 index 8323fc3..5c1d755 100644
29938 --- a/drivers/gpu/drm/drm_crtc.c
29939 +++ b/drivers/gpu/drm/drm_crtc.c
29940 @@ -1379,7 +1379,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
29941 */
29942 if ((out_resp->count_modes >= mode_count) && mode_count) {
29943 copied = 0;
29944 - mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
29945 + mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
29946 list_for_each_entry(mode, &connector->modes, head) {
29947 drm_crtc_convert_to_umode(&u_mode, mode);
29948 if (copy_to_user(mode_ptr + copied,
29949 @@ -1394,8 +1394,8 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
29950
29951 if ((out_resp->count_props >= props_count) && props_count) {
29952 copied = 0;
29953 - prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
29954 - prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
29955 + prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr);
29956 + prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr);
29957 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
29958 if (connector->property_ids[i] != 0) {
29959 if (put_user(connector->property_ids[i],
29960 @@ -1417,7 +1417,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
29961
29962 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
29963 copied = 0;
29964 - encoder_ptr = (uint32_t *)(unsigned long)(out_resp->encoders_ptr);
29965 + encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
29966 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
29967 if (connector->encoder_ids[i] != 0) {
29968 if (put_user(connector->encoder_ids[i],
29969 @@ -1576,7 +1576,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
29970 }
29971
29972 for (i = 0; i < crtc_req->count_connectors; i++) {
29973 - set_connectors_ptr = (uint32_t *)(unsigned long)crtc_req->set_connectors_ptr;
29974 + set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
29975 if (get_user(out_id, &set_connectors_ptr[i])) {
29976 ret = -EFAULT;
29977 goto out;
29978 @@ -1857,7 +1857,7 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
29979 fb = obj_to_fb(obj);
29980
29981 num_clips = r->num_clips;
29982 - clips_ptr = (struct drm_clip_rect *)(unsigned long)r->clips_ptr;
29983 + clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr;
29984
29985 if (!num_clips != !clips_ptr) {
29986 ret = -EINVAL;
29987 @@ -2283,7 +2283,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
29988 out_resp->flags = property->flags;
29989
29990 if ((out_resp->count_values >= value_count) && value_count) {
29991 - values_ptr = (uint64_t *)(unsigned long)out_resp->values_ptr;
29992 + values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
29993 for (i = 0; i < value_count; i++) {
29994 if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
29995 ret = -EFAULT;
29996 @@ -2296,7 +2296,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
29997 if (property->flags & DRM_MODE_PROP_ENUM) {
29998 if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
29999 copied = 0;
30000 - enum_ptr = (struct drm_mode_property_enum *)(unsigned long)out_resp->enum_blob_ptr;
30001 + enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
30002 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
30003
30004 if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
30005 @@ -2319,7 +2319,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
30006 if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
30007 copied = 0;
30008 blob_id_ptr = (uint32_t *)(unsigned long)out_resp->enum_blob_ptr;
30009 - blob_length_ptr = (uint32_t *)(unsigned long)out_resp->values_ptr;
30010 + blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr;
30011
30012 list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
30013 if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
30014 @@ -2380,7 +2380,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
30015 struct drm_mode_get_blob *out_resp = data;
30016 struct drm_property_blob *blob;
30017 int ret = 0;
30018 - void *blob_ptr;
30019 + void __user *blob_ptr;
30020
30021 if (!drm_core_check_feature(dev, DRIVER_MODESET))
30022 return -EINVAL;
30023 @@ -2394,7 +2394,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
30024 blob = obj_to_blob(obj);
30025
30026 if (out_resp->length == blob->length) {
30027 - blob_ptr = (void *)(unsigned long)out_resp->data;
30028 + blob_ptr = (void __user *)(unsigned long)out_resp->data;
30029 if (copy_to_user(blob_ptr, blob->data, blob->length)){
30030 ret = -EFAULT;
30031 goto done;
30032 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30033 index d2619d7..bd6bd00 100644
30034 --- a/drivers/gpu/drm/drm_crtc_helper.c
30035 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30036 @@ -279,7 +279,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30037 struct drm_crtc *tmp;
30038 int crtc_mask = 1;
30039
30040 - WARN(!crtc, "checking null crtc?\n");
30041 + BUG_ON(!crtc);
30042
30043 dev = crtc->dev;
30044
30045 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30046 index 40c187c..5746164 100644
30047 --- a/drivers/gpu/drm/drm_drv.c
30048 +++ b/drivers/gpu/drm/drm_drv.c
30049 @@ -308,7 +308,7 @@ module_exit(drm_core_exit);
30050 /**
30051 * Copy and IOCTL return string to user space
30052 */
30053 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30054 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30055 {
30056 int len;
30057
30058 @@ -387,7 +387,7 @@ long drm_ioctl(struct file *filp,
30059
30060 dev = file_priv->minor->dev;
30061 atomic_inc(&dev->ioctl_count);
30062 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30063 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30064 ++file_priv->ioctl_count;
30065
30066 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30067 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30068 index 828bf65..cdaa0e9 100644
30069 --- a/drivers/gpu/drm/drm_fops.c
30070 +++ b/drivers/gpu/drm/drm_fops.c
30071 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30072 }
30073
30074 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30075 - atomic_set(&dev->counts[i], 0);
30076 + atomic_set_unchecked(&dev->counts[i], 0);
30077
30078 dev->sigdata.lock = NULL;
30079
30080 @@ -135,8 +135,8 @@ int drm_open(struct inode *inode, struct file *filp)
30081
30082 retcode = drm_open_helper(inode, filp, dev);
30083 if (!retcode) {
30084 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30085 - if (!dev->open_count++)
30086 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30087 + if (local_inc_return(&dev->open_count) == 1)
30088 retcode = drm_setup(dev);
30089 }
30090 if (!retcode) {
30091 @@ -473,7 +473,7 @@ int drm_release(struct inode *inode, struct file *filp)
30092
30093 mutex_lock(&drm_global_mutex);
30094
30095 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30096 + DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
30097
30098 if (dev->driver->preclose)
30099 dev->driver->preclose(dev, file_priv);
30100 @@ -485,7 +485,7 @@ int drm_release(struct inode *inode, struct file *filp)
30101 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30102 task_pid_nr(current),
30103 (long)old_encode_dev(file_priv->minor->device),
30104 - dev->open_count);
30105 + local_read(&dev->open_count));
30106
30107 /* Release any auth tokens that might point to this file_priv,
30108 (do that under the drm_global_mutex) */
30109 @@ -571,8 +571,8 @@ int drm_release(struct inode *inode, struct file *filp)
30110 * End inline drm_release
30111 */
30112
30113 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30114 - if (!--dev->open_count) {
30115 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30116 + if (local_dec_and_test(&dev->open_count)) {
30117 if (atomic_read(&dev->ioctl_count)) {
30118 DRM_ERROR("Device busy: %d\n",
30119 atomic_read(&dev->ioctl_count));
30120 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30121 index c87dc96..326055d 100644
30122 --- a/drivers/gpu/drm/drm_global.c
30123 +++ b/drivers/gpu/drm/drm_global.c
30124 @@ -36,7 +36,7 @@
30125 struct drm_global_item {
30126 struct mutex mutex;
30127 void *object;
30128 - int refcount;
30129 + atomic_t refcount;
30130 };
30131
30132 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30133 @@ -49,7 +49,7 @@ void drm_global_init(void)
30134 struct drm_global_item *item = &glob[i];
30135 mutex_init(&item->mutex);
30136 item->object = NULL;
30137 - item->refcount = 0;
30138 + atomic_set(&item->refcount, 0);
30139 }
30140 }
30141
30142 @@ -59,7 +59,7 @@ void drm_global_release(void)
30143 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30144 struct drm_global_item *item = &glob[i];
30145 BUG_ON(item->object != NULL);
30146 - BUG_ON(item->refcount != 0);
30147 + BUG_ON(atomic_read(&item->refcount) != 0);
30148 }
30149 }
30150
30151 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30152 void *object;
30153
30154 mutex_lock(&item->mutex);
30155 - if (item->refcount == 0) {
30156 + if (atomic_read(&item->refcount) == 0) {
30157 item->object = kzalloc(ref->size, GFP_KERNEL);
30158 if (unlikely(item->object == NULL)) {
30159 ret = -ENOMEM;
30160 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30161 goto out_err;
30162
30163 }
30164 - ++item->refcount;
30165 + atomic_inc(&item->refcount);
30166 ref->object = item->object;
30167 object = item->object;
30168 mutex_unlock(&item->mutex);
30169 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30170 struct drm_global_item *item = &glob[ref->global_type];
30171
30172 mutex_lock(&item->mutex);
30173 - BUG_ON(item->refcount == 0);
30174 + BUG_ON(atomic_read(&item->refcount) == 0);
30175 BUG_ON(ref->object != item->object);
30176 - if (--item->refcount == 0) {
30177 + if (atomic_dec_and_test(&item->refcount)) {
30178 ref->release(ref);
30179 item->object = NULL;
30180 }
30181 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30182 index ab1162d..42587b2 100644
30183 --- a/drivers/gpu/drm/drm_info.c
30184 +++ b/drivers/gpu/drm/drm_info.c
30185 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30186 struct drm_local_map *map;
30187 struct drm_map_list *r_list;
30188
30189 - /* Hardcoded from _DRM_FRAME_BUFFER,
30190 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30191 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30192 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30193 + static const char * const types[] = {
30194 + [_DRM_FRAME_BUFFER] = "FB",
30195 + [_DRM_REGISTERS] = "REG",
30196 + [_DRM_SHM] = "SHM",
30197 + [_DRM_AGP] = "AGP",
30198 + [_DRM_SCATTER_GATHER] = "SG",
30199 + [_DRM_CONSISTENT] = "PCI",
30200 + [_DRM_GEM] = "GEM" };
30201 const char *type;
30202 int i;
30203
30204 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30205 map = r_list->map;
30206 if (!map)
30207 continue;
30208 - if (map->type < 0 || map->type > 5)
30209 + if (map->type >= ARRAY_SIZE(types))
30210 type = "??";
30211 else
30212 type = types[map->type];
30213 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30214 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30215 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30216 vma->vm_flags & VM_IO ? 'i' : '-',
30217 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30218 + 0);
30219 +#else
30220 vma->vm_pgoff);
30221 +#endif
30222
30223 #if defined(__i386__)
30224 pgprot = pgprot_val(vma->vm_page_prot);
30225 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30226 index ddd70db..40321e6 100644
30227 --- a/drivers/gpu/drm/drm_ioc32.c
30228 +++ b/drivers/gpu/drm/drm_ioc32.c
30229 @@ -456,7 +456,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30230 request = compat_alloc_user_space(nbytes);
30231 if (!access_ok(VERIFY_WRITE, request, nbytes))
30232 return -EFAULT;
30233 - list = (struct drm_buf_desc *) (request + 1);
30234 + list = (struct drm_buf_desc __user *) (request + 1);
30235
30236 if (__put_user(count, &request->count)
30237 || __put_user(list, &request->list))
30238 @@ -517,7 +517,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30239 request = compat_alloc_user_space(nbytes);
30240 if (!access_ok(VERIFY_WRITE, request, nbytes))
30241 return -EFAULT;
30242 - list = (struct drm_buf_pub *) (request + 1);
30243 + list = (struct drm_buf_pub __user *) (request + 1);
30244
30245 if (__put_user(count, &request->count)
30246 || __put_user(list, &request->list))
30247 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30248 index 904d7e9..ab88581 100644
30249 --- a/drivers/gpu/drm/drm_ioctl.c
30250 +++ b/drivers/gpu/drm/drm_ioctl.c
30251 @@ -256,7 +256,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30252 stats->data[i].value =
30253 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30254 else
30255 - stats->data[i].value = atomic_read(&dev->counts[i]);
30256 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30257 stats->data[i].type = dev->types[i];
30258 }
30259
30260 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30261 index 632ae24..244cf4a 100644
30262 --- a/drivers/gpu/drm/drm_lock.c
30263 +++ b/drivers/gpu/drm/drm_lock.c
30264 @@ -89,7 +89,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30265 if (drm_lock_take(&master->lock, lock->context)) {
30266 master->lock.file_priv = file_priv;
30267 master->lock.lock_time = jiffies;
30268 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30269 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30270 break; /* Got lock */
30271 }
30272
30273 @@ -160,7 +160,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30274 return -EINVAL;
30275 }
30276
30277 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30278 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30279
30280 if (drm_lock_free(&master->lock, lock->context)) {
30281 /* FIXME: Should really bail out here. */
30282 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30283 index 8f371e8..9f85d52 100644
30284 --- a/drivers/gpu/drm/i810/i810_dma.c
30285 +++ b/drivers/gpu/drm/i810/i810_dma.c
30286 @@ -950,8 +950,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30287 dma->buflist[vertex->idx],
30288 vertex->discard, vertex->used);
30289
30290 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30291 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30292 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30293 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30294 sarea_priv->last_enqueue = dev_priv->counter - 1;
30295 sarea_priv->last_dispatch = (int)hw_status[5];
30296
30297 @@ -1111,8 +1111,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30298 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30299 mc->last_render);
30300
30301 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30302 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30303 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30304 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30305 sarea_priv->last_enqueue = dev_priv->counter - 1;
30306 sarea_priv->last_dispatch = (int)hw_status[5];
30307
30308 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30309 index c9339f4..f5e1b9d 100644
30310 --- a/drivers/gpu/drm/i810/i810_drv.h
30311 +++ b/drivers/gpu/drm/i810/i810_drv.h
30312 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30313 int page_flipping;
30314
30315 wait_queue_head_t irq_queue;
30316 - atomic_t irq_received;
30317 - atomic_t irq_emitted;
30318 + atomic_unchecked_t irq_received;
30319 + atomic_unchecked_t irq_emitted;
30320
30321 int front_offset;
30322 } drm_i810_private_t;
30323 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30324 index b2e3c97..58cf079 100644
30325 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30326 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30327 @@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30328 I915_READ(GTIMR));
30329 }
30330 seq_printf(m, "Interrupts received: %d\n",
30331 - atomic_read(&dev_priv->irq_received));
30332 + atomic_read_unchecked(&dev_priv->irq_received));
30333 for (i = 0; i < I915_NUM_RINGS; i++) {
30334 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30335 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30336 @@ -1232,7 +1232,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
30337 return ret;
30338
30339 if (opregion->header)
30340 - seq_write(m, opregion->header, OPREGION_SIZE);
30341 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
30342
30343 mutex_unlock(&dev->struct_mutex);
30344
30345 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30346 index c4da951..3c59c5c 100644
30347 --- a/drivers/gpu/drm/i915/i915_dma.c
30348 +++ b/drivers/gpu/drm/i915/i915_dma.c
30349 @@ -1172,7 +1172,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30350 bool can_switch;
30351
30352 spin_lock(&dev->count_lock);
30353 - can_switch = (dev->open_count == 0);
30354 + can_switch = (local_read(&dev->open_count) == 0);
30355 spin_unlock(&dev->count_lock);
30356 return can_switch;
30357 }
30358 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30359 index ae294a0..1755461 100644
30360 --- a/drivers/gpu/drm/i915/i915_drv.h
30361 +++ b/drivers/gpu/drm/i915/i915_drv.h
30362 @@ -229,7 +229,7 @@ struct drm_i915_display_funcs {
30363 /* render clock increase/decrease */
30364 /* display clock increase/decrease */
30365 /* pll clock increase/decrease */
30366 -};
30367 +} __no_const;
30368
30369 struct intel_device_info {
30370 u8 gen;
30371 @@ -318,7 +318,7 @@ typedef struct drm_i915_private {
30372 int current_page;
30373 int page_flipping;
30374
30375 - atomic_t irq_received;
30376 + atomic_unchecked_t irq_received;
30377
30378 /* protects the irq masks */
30379 spinlock_t irq_lock;
30380 @@ -893,7 +893,7 @@ struct drm_i915_gem_object {
30381 * will be page flipped away on the next vblank. When it
30382 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30383 */
30384 - atomic_t pending_flip;
30385 + atomic_unchecked_t pending_flip;
30386 };
30387
30388 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30389 @@ -1273,7 +1273,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
30390 extern void intel_teardown_gmbus(struct drm_device *dev);
30391 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30392 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30393 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30394 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30395 {
30396 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30397 }
30398 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30399 index b9da890..cad1d98 100644
30400 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30401 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30402 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30403 i915_gem_clflush_object(obj);
30404
30405 if (obj->base.pending_write_domain)
30406 - cd->flips |= atomic_read(&obj->pending_flip);
30407 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30408
30409 /* The actual obj->write_domain will be updated with
30410 * pending_write_domain after we emit the accumulated flush for all
30411 @@ -882,9 +882,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30412
30413 static int
30414 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30415 - int count)
30416 + unsigned int count)
30417 {
30418 - int i;
30419 + unsigned int i;
30420
30421 for (i = 0; i < count; i++) {
30422 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30423 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30424 index d47a53b..61154c2 100644
30425 --- a/drivers/gpu/drm/i915/i915_irq.c
30426 +++ b/drivers/gpu/drm/i915/i915_irq.c
30427 @@ -475,7 +475,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30428 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30429 struct drm_i915_master_private *master_priv;
30430
30431 - atomic_inc(&dev_priv->irq_received);
30432 + atomic_inc_unchecked(&dev_priv->irq_received);
30433
30434 /* disable master interrupt before clearing iir */
30435 de_ier = I915_READ(DEIER);
30436 @@ -566,7 +566,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30437 struct drm_i915_master_private *master_priv;
30438 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
30439
30440 - atomic_inc(&dev_priv->irq_received);
30441 + atomic_inc_unchecked(&dev_priv->irq_received);
30442
30443 if (IS_GEN6(dev))
30444 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
30445 @@ -1231,7 +1231,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
30446 int ret = IRQ_NONE, pipe;
30447 bool blc_event = false;
30448
30449 - atomic_inc(&dev_priv->irq_received);
30450 + atomic_inc_unchecked(&dev_priv->irq_received);
30451
30452 iir = I915_READ(IIR);
30453
30454 @@ -1750,7 +1750,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30455 {
30456 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30457
30458 - atomic_set(&dev_priv->irq_received, 0);
30459 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30460
30461 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30462 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30463 @@ -1938,7 +1938,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
30464 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30465 int pipe;
30466
30467 - atomic_set(&dev_priv->irq_received, 0);
30468 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30469
30470 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30471 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30472 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30473 index 9ec9755..6d1cf2d 100644
30474 --- a/drivers/gpu/drm/i915/intel_display.c
30475 +++ b/drivers/gpu/drm/i915/intel_display.c
30476 @@ -2230,7 +2230,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
30477
30478 wait_event(dev_priv->pending_flip_queue,
30479 atomic_read(&dev_priv->mm.wedged) ||
30480 - atomic_read(&obj->pending_flip) == 0);
30481 + atomic_read_unchecked(&obj->pending_flip) == 0);
30482
30483 /* Big Hammer, we also need to ensure that any pending
30484 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30485 @@ -2851,7 +2851,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
30486 obj = to_intel_framebuffer(crtc->fb)->obj;
30487 dev_priv = crtc->dev->dev_private;
30488 wait_event(dev_priv->pending_flip_queue,
30489 - atomic_read(&obj->pending_flip) == 0);
30490 + atomic_read_unchecked(&obj->pending_flip) == 0);
30491 }
30492
30493 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
30494 @@ -6952,7 +6952,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30495
30496 atomic_clear_mask(1 << intel_crtc->plane,
30497 &obj->pending_flip.counter);
30498 - if (atomic_read(&obj->pending_flip) == 0)
30499 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
30500 wake_up(&dev_priv->pending_flip_queue);
30501
30502 schedule_work(&work->work);
30503 @@ -7242,7 +7242,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30504 /* Block clients from rendering to the new back buffer until
30505 * the flip occurs and the object is no longer visible.
30506 */
30507 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30508 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30509
30510 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30511 if (ret)
30512 @@ -7256,7 +7256,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30513 return 0;
30514
30515 cleanup_pending:
30516 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30517 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30518 drm_gem_object_unreference(&work->old_fb_obj->base);
30519 drm_gem_object_unreference(&obj->base);
30520 mutex_unlock(&dev->struct_mutex);
30521 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30522 index 54558a0..2d97005 100644
30523 --- a/drivers/gpu/drm/mga/mga_drv.h
30524 +++ b/drivers/gpu/drm/mga/mga_drv.h
30525 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30526 u32 clear_cmd;
30527 u32 maccess;
30528
30529 - atomic_t vbl_received; /**< Number of vblanks received. */
30530 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30531 wait_queue_head_t fence_queue;
30532 - atomic_t last_fence_retired;
30533 + atomic_unchecked_t last_fence_retired;
30534 u32 next_fence_to_post;
30535
30536 unsigned int fb_cpp;
30537 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30538 index 2581202..f230a8d9 100644
30539 --- a/drivers/gpu/drm/mga/mga_irq.c
30540 +++ b/drivers/gpu/drm/mga/mga_irq.c
30541 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30542 if (crtc != 0)
30543 return 0;
30544
30545 - return atomic_read(&dev_priv->vbl_received);
30546 + return atomic_read_unchecked(&dev_priv->vbl_received);
30547 }
30548
30549
30550 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30551 /* VBLANK interrupt */
30552 if (status & MGA_VLINEPEN) {
30553 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30554 - atomic_inc(&dev_priv->vbl_received);
30555 + atomic_inc_unchecked(&dev_priv->vbl_received);
30556 drm_handle_vblank(dev, 0);
30557 handled = 1;
30558 }
30559 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30560 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30561 MGA_WRITE(MGA_PRIMEND, prim_end);
30562
30563 - atomic_inc(&dev_priv->last_fence_retired);
30564 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30565 DRM_WAKEUP(&dev_priv->fence_queue);
30566 handled = 1;
30567 }
30568 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30569 * using fences.
30570 */
30571 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30572 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30573 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30574 - *sequence) <= (1 << 23)));
30575
30576 *sequence = cur_fence;
30577 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30578 index 5fc201b..7b032b9 100644
30579 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30580 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30581 @@ -201,7 +201,7 @@ struct methods {
30582 const char desc[8];
30583 void (*loadbios)(struct drm_device *, uint8_t *);
30584 const bool rw;
30585 -};
30586 +} __do_const;
30587
30588 static struct methods shadow_methods[] = {
30589 { "PRAMIN", load_vbios_pramin, true },
30590 @@ -5474,7 +5474,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30591 struct bit_table {
30592 const char id;
30593 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30594 -};
30595 +} __no_const;
30596
30597 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30598
30599 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30600 index 4c0be3a..5757582 100644
30601 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30602 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30603 @@ -238,7 +238,7 @@ struct nouveau_channel {
30604 struct list_head pending;
30605 uint32_t sequence;
30606 uint32_t sequence_ack;
30607 - atomic_t last_sequence_irq;
30608 + atomic_unchecked_t last_sequence_irq;
30609 struct nouveau_vma vma;
30610 } fence;
30611
30612 @@ -319,7 +319,7 @@ struct nouveau_exec_engine {
30613 u32 handle, u16 class);
30614 void (*set_tile_region)(struct drm_device *dev, int i);
30615 void (*tlb_flush)(struct drm_device *, int engine);
30616 -};
30617 +} __no_const;
30618
30619 struct nouveau_instmem_engine {
30620 void *priv;
30621 @@ -341,13 +341,13 @@ struct nouveau_instmem_engine {
30622 struct nouveau_mc_engine {
30623 int (*init)(struct drm_device *dev);
30624 void (*takedown)(struct drm_device *dev);
30625 -};
30626 +} __no_const;
30627
30628 struct nouveau_timer_engine {
30629 int (*init)(struct drm_device *dev);
30630 void (*takedown)(struct drm_device *dev);
30631 uint64_t (*read)(struct drm_device *dev);
30632 -};
30633 +} __no_const;
30634
30635 struct nouveau_fb_engine {
30636 int num_tiles;
30637 @@ -558,7 +558,7 @@ struct nouveau_vram_engine {
30638 void (*put)(struct drm_device *, struct nouveau_mem **);
30639
30640 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30641 -};
30642 +} __no_const;
30643
30644 struct nouveau_engine {
30645 struct nouveau_instmem_engine instmem;
30646 @@ -706,7 +706,7 @@ struct drm_nouveau_private {
30647 struct drm_global_reference mem_global_ref;
30648 struct ttm_bo_global_ref bo_global_ref;
30649 struct ttm_bo_device bdev;
30650 - atomic_t validate_sequence;
30651 + atomic_unchecked_t validate_sequence;
30652 } ttm;
30653
30654 struct {
30655 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
30656 index 2f6daae..c9d7b9e 100644
30657 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
30658 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
30659 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
30660 if (USE_REFCNT(dev))
30661 sequence = nvchan_rd32(chan, 0x48);
30662 else
30663 - sequence = atomic_read(&chan->fence.last_sequence_irq);
30664 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
30665
30666 if (chan->fence.sequence_ack == sequence)
30667 goto out;
30668 @@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
30669 return ret;
30670 }
30671
30672 - atomic_set(&chan->fence.last_sequence_irq, 0);
30673 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
30674 return 0;
30675 }
30676
30677 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30678 index 7ce3fde..cb3ea04 100644
30679 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30680 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30681 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30682 int trycnt = 0;
30683 int ret, i;
30684
30685 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30686 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30687 retry:
30688 if (++trycnt > 100000) {
30689 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30690 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30691 index d8831ab..0ba8356 100644
30692 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30693 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30694 @@ -542,7 +542,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30695 bool can_switch;
30696
30697 spin_lock(&dev->count_lock);
30698 - can_switch = (dev->open_count == 0);
30699 + can_switch = (local_read(&dev->open_count) == 0);
30700 spin_unlock(&dev->count_lock);
30701 return can_switch;
30702 }
30703 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
30704 index dbdea8e..cd6eeeb 100644
30705 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
30706 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
30707 @@ -554,7 +554,7 @@ static int
30708 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
30709 u32 class, u32 mthd, u32 data)
30710 {
30711 - atomic_set(&chan->fence.last_sequence_irq, data);
30712 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
30713 return 0;
30714 }
30715
30716 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30717 index bcac90b..53bfc76 100644
30718 --- a/drivers/gpu/drm/r128/r128_cce.c
30719 +++ b/drivers/gpu/drm/r128/r128_cce.c
30720 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30721
30722 /* GH: Simple idle check.
30723 */
30724 - atomic_set(&dev_priv->idle_count, 0);
30725 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30726
30727 /* We don't support anything other than bus-mastering ring mode,
30728 * but the ring can be in either AGP or PCI space for the ring
30729 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30730 index 930c71b..499aded 100644
30731 --- a/drivers/gpu/drm/r128/r128_drv.h
30732 +++ b/drivers/gpu/drm/r128/r128_drv.h
30733 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30734 int is_pci;
30735 unsigned long cce_buffers_offset;
30736
30737 - atomic_t idle_count;
30738 + atomic_unchecked_t idle_count;
30739
30740 int page_flipping;
30741 int current_page;
30742 u32 crtc_offset;
30743 u32 crtc_offset_cntl;
30744
30745 - atomic_t vbl_received;
30746 + atomic_unchecked_t vbl_received;
30747
30748 u32 color_fmt;
30749 unsigned int front_offset;
30750 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30751 index 429d5a0..7e899ed 100644
30752 --- a/drivers/gpu/drm/r128/r128_irq.c
30753 +++ b/drivers/gpu/drm/r128/r128_irq.c
30754 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30755 if (crtc != 0)
30756 return 0;
30757
30758 - return atomic_read(&dev_priv->vbl_received);
30759 + return atomic_read_unchecked(&dev_priv->vbl_received);
30760 }
30761
30762 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30763 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30764 /* VBLANK interrupt */
30765 if (status & R128_CRTC_VBLANK_INT) {
30766 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30767 - atomic_inc(&dev_priv->vbl_received);
30768 + atomic_inc_unchecked(&dev_priv->vbl_received);
30769 drm_handle_vblank(dev, 0);
30770 return IRQ_HANDLED;
30771 }
30772 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30773 index a9e33ce..09edd4b 100644
30774 --- a/drivers/gpu/drm/r128/r128_state.c
30775 +++ b/drivers/gpu/drm/r128/r128_state.c
30776 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30777
30778 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30779 {
30780 - if (atomic_read(&dev_priv->idle_count) == 0)
30781 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30782 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30783 else
30784 - atomic_set(&dev_priv->idle_count, 0);
30785 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30786 }
30787
30788 #endif
30789 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30790 index 5a82b6b..9e69c73 100644
30791 --- a/drivers/gpu/drm/radeon/mkregtable.c
30792 +++ b/drivers/gpu/drm/radeon/mkregtable.c
30793 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30794 regex_t mask_rex;
30795 regmatch_t match[4];
30796 char buf[1024];
30797 - size_t end;
30798 + long end;
30799 int len;
30800 int done = 0;
30801 int r;
30802 unsigned o;
30803 struct offset *offset;
30804 char last_reg_s[10];
30805 - int last_reg;
30806 + unsigned long last_reg;
30807
30808 if (regcomp
30809 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30810 diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c
30811 index cb1acff..8861bc5 100644
30812 --- a/drivers/gpu/drm/radeon/r600_cs.c
30813 +++ b/drivers/gpu/drm/radeon/r600_cs.c
30814 @@ -1304,6 +1304,7 @@ static int r600_check_texture_resource(struct radeon_cs_parser *p, u32 idx,
30815 h0 = G_038004_TEX_HEIGHT(word1) + 1;
30816 d0 = G_038004_TEX_DEPTH(word1);
30817 nfaces = 1;
30818 + array = 0;
30819 switch (G_038000_DIM(word0)) {
30820 case V_038000_SQ_TEX_DIM_1D:
30821 case V_038000_SQ_TEX_DIM_2D:
30822 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30823 index 8227e76..ce0b195 100644
30824 --- a/drivers/gpu/drm/radeon/radeon.h
30825 +++ b/drivers/gpu/drm/radeon/radeon.h
30826 @@ -192,7 +192,7 @@ extern int sumo_get_temp(struct radeon_device *rdev);
30827 */
30828 struct radeon_fence_driver {
30829 uint32_t scratch_reg;
30830 - atomic_t seq;
30831 + atomic_unchecked_t seq;
30832 uint32_t last_seq;
30833 unsigned long last_jiffies;
30834 unsigned long last_timeout;
30835 @@ -530,7 +530,7 @@ struct r600_blit_cp_primitives {
30836 int x2, int y2);
30837 void (*draw_auto)(struct radeon_device *rdev);
30838 void (*set_default_state)(struct radeon_device *rdev);
30839 -};
30840 +} __no_const;
30841
30842 struct r600_blit {
30843 struct mutex mutex;
30844 @@ -954,7 +954,7 @@ struct radeon_asic {
30845 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
30846 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30847 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30848 -};
30849 +} __no_const;
30850
30851 /*
30852 * Asic structures
30853 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30854 index 9231564..78b00fd 100644
30855 --- a/drivers/gpu/drm/radeon/radeon_device.c
30856 +++ b/drivers/gpu/drm/radeon/radeon_device.c
30857 @@ -687,7 +687,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30858 bool can_switch;
30859
30860 spin_lock(&dev->count_lock);
30861 - can_switch = (dev->open_count == 0);
30862 + can_switch = (local_read(&dev->open_count) == 0);
30863 spin_unlock(&dev->count_lock);
30864 return can_switch;
30865 }
30866 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30867 index a1b59ca..86f2d44 100644
30868 --- a/drivers/gpu/drm/radeon/radeon_drv.h
30869 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
30870 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30871
30872 /* SW interrupt */
30873 wait_queue_head_t swi_queue;
30874 - atomic_t swi_emitted;
30875 + atomic_unchecked_t swi_emitted;
30876 int vblank_crtc;
30877 uint32_t irq_enable_reg;
30878 uint32_t r500_disp_irq_reg;
30879 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
30880 index 76ec0e9..6feb1a3 100644
30881 --- a/drivers/gpu/drm/radeon/radeon_fence.c
30882 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
30883 @@ -78,7 +78,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
30884 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
30885 return 0;
30886 }
30887 - fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
30888 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
30889 if (!rdev->cp.ready)
30890 /* FIXME: cp is not running assume everythings is done right
30891 * away
30892 @@ -373,7 +373,7 @@ int radeon_fence_driver_init(struct radeon_device *rdev)
30893 return r;
30894 }
30895 radeon_fence_write(rdev, 0);
30896 - atomic_set(&rdev->fence_drv.seq, 0);
30897 + atomic_set_unchecked(&rdev->fence_drv.seq, 0);
30898 INIT_LIST_HEAD(&rdev->fence_drv.created);
30899 INIT_LIST_HEAD(&rdev->fence_drv.emited);
30900 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
30901 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30902 index 48b7cea..342236f 100644
30903 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30904 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30905 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30906 request = compat_alloc_user_space(sizeof(*request));
30907 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30908 || __put_user(req32.param, &request->param)
30909 - || __put_user((void __user *)(unsigned long)req32.value,
30910 + || __put_user((unsigned long)req32.value,
30911 &request->value))
30912 return -EFAULT;
30913
30914 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30915 index 00da384..32f972d 100644
30916 --- a/drivers/gpu/drm/radeon/radeon_irq.c
30917 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
30918 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30919 unsigned int ret;
30920 RING_LOCALS;
30921
30922 - atomic_inc(&dev_priv->swi_emitted);
30923 - ret = atomic_read(&dev_priv->swi_emitted);
30924 + atomic_inc_unchecked(&dev_priv->swi_emitted);
30925 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30926
30927 BEGIN_RING(4);
30928 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30929 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30930 drm_radeon_private_t *dev_priv =
30931 (drm_radeon_private_t *) dev->dev_private;
30932
30933 - atomic_set(&dev_priv->swi_emitted, 0);
30934 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30935 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30936
30937 dev->max_vblank_count = 0x001fffff;
30938 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30939 index e8422ae..d22d4a8 100644
30940 --- a/drivers/gpu/drm/radeon/radeon_state.c
30941 +++ b/drivers/gpu/drm/radeon/radeon_state.c
30942 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30943 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30944 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30945
30946 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30947 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30948 sarea_priv->nbox * sizeof(depth_boxes[0])))
30949 return -EFAULT;
30950
30951 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30952 {
30953 drm_radeon_private_t *dev_priv = dev->dev_private;
30954 drm_radeon_getparam_t *param = data;
30955 - int value;
30956 + int value = 0;
30957
30958 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30959
30960 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30961 index 0b5468b..9c4b308 100644
30962 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
30963 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30964 @@ -672,8 +672,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30965 }
30966 if (unlikely(ttm_vm_ops == NULL)) {
30967 ttm_vm_ops = vma->vm_ops;
30968 - radeon_ttm_vm_ops = *ttm_vm_ops;
30969 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30970 + pax_open_kernel();
30971 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
30972 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30973 + pax_close_kernel();
30974 }
30975 vma->vm_ops = &radeon_ttm_vm_ops;
30976 return 0;
30977 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
30978 index a9049ed..501f284 100644
30979 --- a/drivers/gpu/drm/radeon/rs690.c
30980 +++ b/drivers/gpu/drm/radeon/rs690.c
30981 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
30982 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
30983 rdev->pm.sideport_bandwidth.full)
30984 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
30985 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
30986 + read_delay_latency.full = dfixed_const(800 * 1000);
30987 read_delay_latency.full = dfixed_div(read_delay_latency,
30988 rdev->pm.igp_sideport_mclk);
30989 + a.full = dfixed_const(370);
30990 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
30991 } else {
30992 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
30993 rdev->pm.k8_bandwidth.full)
30994 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30995 index 727e93d..1565650 100644
30996 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
30997 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30998 @@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
30999 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31000 struct shrink_control *sc)
31001 {
31002 - static atomic_t start_pool = ATOMIC_INIT(0);
31003 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31004 unsigned i;
31005 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31006 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31007 struct ttm_page_pool *pool;
31008 int shrink_pages = sc->nr_to_scan;
31009
31010 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31011 index 9cf87d9..2000b7d 100644
31012 --- a/drivers/gpu/drm/via/via_drv.h
31013 +++ b/drivers/gpu/drm/via/via_drv.h
31014 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31015 typedef uint32_t maskarray_t[5];
31016
31017 typedef struct drm_via_irq {
31018 - atomic_t irq_received;
31019 + atomic_unchecked_t irq_received;
31020 uint32_t pending_mask;
31021 uint32_t enable_mask;
31022 wait_queue_head_t irq_queue;
31023 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31024 struct timeval last_vblank;
31025 int last_vblank_valid;
31026 unsigned usec_per_vblank;
31027 - atomic_t vbl_received;
31028 + atomic_unchecked_t vbl_received;
31029 drm_via_state_t hc_state;
31030 char pci_buf[VIA_PCI_BUF_SIZE];
31031 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31032 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31033 index d391f48..10c8ca3 100644
31034 --- a/drivers/gpu/drm/via/via_irq.c
31035 +++ b/drivers/gpu/drm/via/via_irq.c
31036 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31037 if (crtc != 0)
31038 return 0;
31039
31040 - return atomic_read(&dev_priv->vbl_received);
31041 + return atomic_read_unchecked(&dev_priv->vbl_received);
31042 }
31043
31044 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31045 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31046
31047 status = VIA_READ(VIA_REG_INTERRUPT);
31048 if (status & VIA_IRQ_VBLANK_PENDING) {
31049 - atomic_inc(&dev_priv->vbl_received);
31050 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31051 + atomic_inc_unchecked(&dev_priv->vbl_received);
31052 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31053 do_gettimeofday(&cur_vblank);
31054 if (dev_priv->last_vblank_valid) {
31055 dev_priv->usec_per_vblank =
31056 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31057 dev_priv->last_vblank = cur_vblank;
31058 dev_priv->last_vblank_valid = 1;
31059 }
31060 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31061 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31062 DRM_DEBUG("US per vblank is: %u\n",
31063 dev_priv->usec_per_vblank);
31064 }
31065 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31066
31067 for (i = 0; i < dev_priv->num_irqs; ++i) {
31068 if (status & cur_irq->pending_mask) {
31069 - atomic_inc(&cur_irq->irq_received);
31070 + atomic_inc_unchecked(&cur_irq->irq_received);
31071 DRM_WAKEUP(&cur_irq->irq_queue);
31072 handled = 1;
31073 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31074 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31075 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31076 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31077 masks[irq][4]));
31078 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31079 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31080 } else {
31081 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31082 (((cur_irq_sequence =
31083 - atomic_read(&cur_irq->irq_received)) -
31084 + atomic_read_unchecked(&cur_irq->irq_received)) -
31085 *sequence) <= (1 << 23)));
31086 }
31087 *sequence = cur_irq_sequence;
31088 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31089 }
31090
31091 for (i = 0; i < dev_priv->num_irqs; ++i) {
31092 - atomic_set(&cur_irq->irq_received, 0);
31093 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31094 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31095 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31096 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31097 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31098 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31099 case VIA_IRQ_RELATIVE:
31100 irqwait->request.sequence +=
31101 - atomic_read(&cur_irq->irq_received);
31102 + atomic_read_unchecked(&cur_irq->irq_received);
31103 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31104 case VIA_IRQ_ABSOLUTE:
31105 break;
31106 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31107 index dc27970..f18b008 100644
31108 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31109 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31110 @@ -260,7 +260,7 @@ struct vmw_private {
31111 * Fencing and IRQs.
31112 */
31113
31114 - atomic_t marker_seq;
31115 + atomic_unchecked_t marker_seq;
31116 wait_queue_head_t fence_queue;
31117 wait_queue_head_t fifo_queue;
31118 int fence_queue_waiters; /* Protected by hw_mutex */
31119 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31120 index a0c2f12..68ae6cb 100644
31121 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31122 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31123 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31124 (unsigned int) min,
31125 (unsigned int) fifo->capabilities);
31126
31127 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31128 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31129 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31130 vmw_marker_queue_init(&fifo->marker_queue);
31131 return vmw_fifo_send_fence(dev_priv, &dummy);
31132 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31133 if (reserveable)
31134 iowrite32(bytes, fifo_mem +
31135 SVGA_FIFO_RESERVED);
31136 - return fifo_mem + (next_cmd >> 2);
31137 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31138 } else {
31139 need_bounce = true;
31140 }
31141 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31142
31143 fm = vmw_fifo_reserve(dev_priv, bytes);
31144 if (unlikely(fm == NULL)) {
31145 - *seqno = atomic_read(&dev_priv->marker_seq);
31146 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31147 ret = -ENOMEM;
31148 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31149 false, 3*HZ);
31150 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31151 }
31152
31153 do {
31154 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31155 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31156 } while (*seqno == 0);
31157
31158 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31159 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31160 index cabc95f..14b3d77 100644
31161 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31162 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31163 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31164 * emitted. Then the fence is stale and signaled.
31165 */
31166
31167 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31168 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31169 > VMW_FENCE_WRAP);
31170
31171 return ret;
31172 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31173
31174 if (fifo_idle)
31175 down_read(&fifo_state->rwsem);
31176 - signal_seq = atomic_read(&dev_priv->marker_seq);
31177 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31178 ret = 0;
31179
31180 for (;;) {
31181 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31182 index 8a8725c..afed796 100644
31183 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31184 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31185 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31186 while (!vmw_lag_lt(queue, us)) {
31187 spin_lock(&queue->lock);
31188 if (list_empty(&queue->head))
31189 - seqno = atomic_read(&dev_priv->marker_seq);
31190 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31191 else {
31192 marker = list_first_entry(&queue->head,
31193 struct vmw_marker, head);
31194 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31195 index bb656d8..4169fca 100644
31196 --- a/drivers/hid/hid-core.c
31197 +++ b/drivers/hid/hid-core.c
31198 @@ -2012,7 +2012,7 @@ static bool hid_ignore(struct hid_device *hdev)
31199
31200 int hid_add_device(struct hid_device *hdev)
31201 {
31202 - static atomic_t id = ATOMIC_INIT(0);
31203 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31204 int ret;
31205
31206 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31207 @@ -2027,7 +2027,7 @@ int hid_add_device(struct hid_device *hdev)
31208 /* XXX hack, any other cleaner solution after the driver core
31209 * is converted to allow more than 20 bytes as the device name? */
31210 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31211 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31212 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31213
31214 hid_debug_register(hdev, dev_name(&hdev->dev));
31215 ret = device_add(&hdev->dev);
31216 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31217 index 4ef02b2..8a96831 100644
31218 --- a/drivers/hid/usbhid/hiddev.c
31219 +++ b/drivers/hid/usbhid/hiddev.c
31220 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31221 break;
31222
31223 case HIDIOCAPPLICATION:
31224 - if (arg < 0 || arg >= hid->maxapplication)
31225 + if (arg >= hid->maxapplication)
31226 break;
31227
31228 for (i = 0; i < hid->maxcollection; i++)
31229 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31230 index 4065374..10ed7dc 100644
31231 --- a/drivers/hv/channel.c
31232 +++ b/drivers/hv/channel.c
31233 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31234 int ret = 0;
31235 int t;
31236
31237 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31238 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31239 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31240 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31241
31242 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31243 if (ret)
31244 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31245 index 0fb100e..baf87e5 100644
31246 --- a/drivers/hv/hv.c
31247 +++ b/drivers/hv/hv.c
31248 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31249 u64 output_address = (output) ? virt_to_phys(output) : 0;
31250 u32 output_address_hi = output_address >> 32;
31251 u32 output_address_lo = output_address & 0xFFFFFFFF;
31252 - void *hypercall_page = hv_context.hypercall_page;
31253 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31254
31255 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31256 "=a"(hv_status_lo) : "d" (control_hi),
31257 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31258 index 0aee112..b72d21f 100644
31259 --- a/drivers/hv/hyperv_vmbus.h
31260 +++ b/drivers/hv/hyperv_vmbus.h
31261 @@ -556,7 +556,7 @@ enum vmbus_connect_state {
31262 struct vmbus_connection {
31263 enum vmbus_connect_state conn_state;
31264
31265 - atomic_t next_gpadl_handle;
31266 + atomic_unchecked_t next_gpadl_handle;
31267
31268 /*
31269 * Represents channel interrupts. Each bit position represents a
31270 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31271 index d2d0a2a..90b8f4d 100644
31272 --- a/drivers/hv/vmbus_drv.c
31273 +++ b/drivers/hv/vmbus_drv.c
31274 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31275 {
31276 int ret = 0;
31277
31278 - static atomic_t device_num = ATOMIC_INIT(0);
31279 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31280
31281 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31282 - atomic_inc_return(&device_num));
31283 + atomic_inc_return_unchecked(&device_num));
31284
31285 child_device_obj->device.bus = &hv_bus;
31286 child_device_obj->device.parent = &hv_acpi_dev->dev;
31287 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31288 index 66f6729..2d6de0a 100644
31289 --- a/drivers/hwmon/acpi_power_meter.c
31290 +++ b/drivers/hwmon/acpi_power_meter.c
31291 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31292 return res;
31293
31294 temp /= 1000;
31295 - if (temp < 0)
31296 - return -EINVAL;
31297
31298 mutex_lock(&resource->lock);
31299 resource->trip[attr->index - 7] = temp;
31300 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31301 index 5357925..6cf0418 100644
31302 --- a/drivers/hwmon/sht15.c
31303 +++ b/drivers/hwmon/sht15.c
31304 @@ -166,7 +166,7 @@ struct sht15_data {
31305 int supply_uV;
31306 bool supply_uV_valid;
31307 struct work_struct update_supply_work;
31308 - atomic_t interrupt_handled;
31309 + atomic_unchecked_t interrupt_handled;
31310 };
31311
31312 /**
31313 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31314 return ret;
31315
31316 gpio_direction_input(data->pdata->gpio_data);
31317 - atomic_set(&data->interrupt_handled, 0);
31318 + atomic_set_unchecked(&data->interrupt_handled, 0);
31319
31320 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31321 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31322 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31323 /* Only relevant if the interrupt hasn't occurred. */
31324 - if (!atomic_read(&data->interrupt_handled))
31325 + if (!atomic_read_unchecked(&data->interrupt_handled))
31326 schedule_work(&data->read_work);
31327 }
31328 ret = wait_event_timeout(data->wait_queue,
31329 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31330
31331 /* First disable the interrupt */
31332 disable_irq_nosync(irq);
31333 - atomic_inc(&data->interrupt_handled);
31334 + atomic_inc_unchecked(&data->interrupt_handled);
31335 /* Then schedule a reading work struct */
31336 if (data->state != SHT15_READING_NOTHING)
31337 schedule_work(&data->read_work);
31338 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31339 * If not, then start the interrupt again - care here as could
31340 * have gone low in meantime so verify it hasn't!
31341 */
31342 - atomic_set(&data->interrupt_handled, 0);
31343 + atomic_set_unchecked(&data->interrupt_handled, 0);
31344 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31345 /* If still not occurred or another handler has been scheduled */
31346 if (gpio_get_value(data->pdata->gpio_data)
31347 - || atomic_read(&data->interrupt_handled))
31348 + || atomic_read_unchecked(&data->interrupt_handled))
31349 return;
31350 }
31351
31352 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31353 index 378fcb5..5e91fa8 100644
31354 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31355 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31356 @@ -43,7 +43,7 @@
31357 extern struct i2c_adapter amd756_smbus;
31358
31359 static struct i2c_adapter *s4882_adapter;
31360 -static struct i2c_algorithm *s4882_algo;
31361 +static i2c_algorithm_no_const *s4882_algo;
31362
31363 /* Wrapper access functions for multiplexed SMBus */
31364 static DEFINE_MUTEX(amd756_lock);
31365 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31366 index 29015eb..af2d8e9 100644
31367 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31368 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31369 @@ -41,7 +41,7 @@
31370 extern struct i2c_adapter *nforce2_smbus;
31371
31372 static struct i2c_adapter *s4985_adapter;
31373 -static struct i2c_algorithm *s4985_algo;
31374 +static i2c_algorithm_no_const *s4985_algo;
31375
31376 /* Wrapper access functions for multiplexed SMBus */
31377 static DEFINE_MUTEX(nforce2_lock);
31378 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31379 index d7a4833..7fae376 100644
31380 --- a/drivers/i2c/i2c-mux.c
31381 +++ b/drivers/i2c/i2c-mux.c
31382 @@ -28,7 +28,7 @@
31383 /* multiplexer per channel data */
31384 struct i2c_mux_priv {
31385 struct i2c_adapter adap;
31386 - struct i2c_algorithm algo;
31387 + i2c_algorithm_no_const algo;
31388
31389 struct i2c_adapter *parent;
31390 void *mux_dev; /* the mux chip/device */
31391 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31392 index 57d00ca..0145194 100644
31393 --- a/drivers/ide/aec62xx.c
31394 +++ b/drivers/ide/aec62xx.c
31395 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31396 .cable_detect = atp86x_cable_detect,
31397 };
31398
31399 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31400 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31401 { /* 0: AEC6210 */
31402 .name = DRV_NAME,
31403 .init_chipset = init_chipset_aec62xx,
31404 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31405 index 2c8016a..911a27c 100644
31406 --- a/drivers/ide/alim15x3.c
31407 +++ b/drivers/ide/alim15x3.c
31408 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31409 .dma_sff_read_status = ide_dma_sff_read_status,
31410 };
31411
31412 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31413 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31414 .name = DRV_NAME,
31415 .init_chipset = init_chipset_ali15x3,
31416 .init_hwif = init_hwif_ali15x3,
31417 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31418 index 3747b25..56fc995 100644
31419 --- a/drivers/ide/amd74xx.c
31420 +++ b/drivers/ide/amd74xx.c
31421 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31422 .udma_mask = udma, \
31423 }
31424
31425 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31426 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31427 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31428 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31429 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31430 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31431 index 15f0ead..cb43480 100644
31432 --- a/drivers/ide/atiixp.c
31433 +++ b/drivers/ide/atiixp.c
31434 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31435 .cable_detect = atiixp_cable_detect,
31436 };
31437
31438 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31439 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31440 { /* 0: IXP200/300/400/700 */
31441 .name = DRV_NAME,
31442 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31443 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31444 index 5f80312..d1fc438 100644
31445 --- a/drivers/ide/cmd64x.c
31446 +++ b/drivers/ide/cmd64x.c
31447 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31448 .dma_sff_read_status = ide_dma_sff_read_status,
31449 };
31450
31451 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31452 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31453 { /* 0: CMD643 */
31454 .name = DRV_NAME,
31455 .init_chipset = init_chipset_cmd64x,
31456 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31457 index 2c1e5f7..1444762 100644
31458 --- a/drivers/ide/cs5520.c
31459 +++ b/drivers/ide/cs5520.c
31460 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31461 .set_dma_mode = cs5520_set_dma_mode,
31462 };
31463
31464 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31465 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31466 .name = DRV_NAME,
31467 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31468 .port_ops = &cs5520_port_ops,
31469 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31470 index 4dc4eb9..49b40ad 100644
31471 --- a/drivers/ide/cs5530.c
31472 +++ b/drivers/ide/cs5530.c
31473 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31474 .udma_filter = cs5530_udma_filter,
31475 };
31476
31477 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31478 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31479 .name = DRV_NAME,
31480 .init_chipset = init_chipset_cs5530,
31481 .init_hwif = init_hwif_cs5530,
31482 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31483 index 5059faf..18d4c85 100644
31484 --- a/drivers/ide/cs5535.c
31485 +++ b/drivers/ide/cs5535.c
31486 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31487 .cable_detect = cs5535_cable_detect,
31488 };
31489
31490 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31491 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31492 .name = DRV_NAME,
31493 .port_ops = &cs5535_port_ops,
31494 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31495 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31496 index 847553f..3ffb49d 100644
31497 --- a/drivers/ide/cy82c693.c
31498 +++ b/drivers/ide/cy82c693.c
31499 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31500 .set_dma_mode = cy82c693_set_dma_mode,
31501 };
31502
31503 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31504 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31505 .name = DRV_NAME,
31506 .init_iops = init_iops_cy82c693,
31507 .port_ops = &cy82c693_port_ops,
31508 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31509 index 58c51cd..4aec3b8 100644
31510 --- a/drivers/ide/hpt366.c
31511 +++ b/drivers/ide/hpt366.c
31512 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31513 }
31514 };
31515
31516 -static const struct hpt_info hpt36x __devinitdata = {
31517 +static const struct hpt_info hpt36x __devinitconst = {
31518 .chip_name = "HPT36x",
31519 .chip_type = HPT36x,
31520 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31521 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31522 .timings = &hpt36x_timings
31523 };
31524
31525 -static const struct hpt_info hpt370 __devinitdata = {
31526 +static const struct hpt_info hpt370 __devinitconst = {
31527 .chip_name = "HPT370",
31528 .chip_type = HPT370,
31529 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31530 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31531 .timings = &hpt37x_timings
31532 };
31533
31534 -static const struct hpt_info hpt370a __devinitdata = {
31535 +static const struct hpt_info hpt370a __devinitconst = {
31536 .chip_name = "HPT370A",
31537 .chip_type = HPT370A,
31538 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31539 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31540 .timings = &hpt37x_timings
31541 };
31542
31543 -static const struct hpt_info hpt374 __devinitdata = {
31544 +static const struct hpt_info hpt374 __devinitconst = {
31545 .chip_name = "HPT374",
31546 .chip_type = HPT374,
31547 .udma_mask = ATA_UDMA5,
31548 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31549 .timings = &hpt37x_timings
31550 };
31551
31552 -static const struct hpt_info hpt372 __devinitdata = {
31553 +static const struct hpt_info hpt372 __devinitconst = {
31554 .chip_name = "HPT372",
31555 .chip_type = HPT372,
31556 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31557 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31558 .timings = &hpt37x_timings
31559 };
31560
31561 -static const struct hpt_info hpt372a __devinitdata = {
31562 +static const struct hpt_info hpt372a __devinitconst = {
31563 .chip_name = "HPT372A",
31564 .chip_type = HPT372A,
31565 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31566 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31567 .timings = &hpt37x_timings
31568 };
31569
31570 -static const struct hpt_info hpt302 __devinitdata = {
31571 +static const struct hpt_info hpt302 __devinitconst = {
31572 .chip_name = "HPT302",
31573 .chip_type = HPT302,
31574 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31575 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31576 .timings = &hpt37x_timings
31577 };
31578
31579 -static const struct hpt_info hpt371 __devinitdata = {
31580 +static const struct hpt_info hpt371 __devinitconst = {
31581 .chip_name = "HPT371",
31582 .chip_type = HPT371,
31583 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31584 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31585 .timings = &hpt37x_timings
31586 };
31587
31588 -static const struct hpt_info hpt372n __devinitdata = {
31589 +static const struct hpt_info hpt372n __devinitconst = {
31590 .chip_name = "HPT372N",
31591 .chip_type = HPT372N,
31592 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31593 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31594 .timings = &hpt37x_timings
31595 };
31596
31597 -static const struct hpt_info hpt302n __devinitdata = {
31598 +static const struct hpt_info hpt302n __devinitconst = {
31599 .chip_name = "HPT302N",
31600 .chip_type = HPT302N,
31601 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31602 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31603 .timings = &hpt37x_timings
31604 };
31605
31606 -static const struct hpt_info hpt371n __devinitdata = {
31607 +static const struct hpt_info hpt371n __devinitconst = {
31608 .chip_name = "HPT371N",
31609 .chip_type = HPT371N,
31610 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31611 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31612 .dma_sff_read_status = ide_dma_sff_read_status,
31613 };
31614
31615 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31616 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31617 { /* 0: HPT36x */
31618 .name = DRV_NAME,
31619 .init_chipset = init_chipset_hpt366,
31620 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31621 index 8126824..55a2798 100644
31622 --- a/drivers/ide/ide-cd.c
31623 +++ b/drivers/ide/ide-cd.c
31624 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31625 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31626 if ((unsigned long)buf & alignment
31627 || blk_rq_bytes(rq) & q->dma_pad_mask
31628 - || object_is_on_stack(buf))
31629 + || object_starts_on_stack(buf))
31630 drive->dma = 0;
31631 }
31632 }
31633 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31634 index a743e68..1cfd674 100644
31635 --- a/drivers/ide/ide-pci-generic.c
31636 +++ b/drivers/ide/ide-pci-generic.c
31637 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31638 .udma_mask = ATA_UDMA6, \
31639 }
31640
31641 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31642 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31643 /* 0: Unknown */
31644 DECLARE_GENERIC_PCI_DEV(0),
31645
31646 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31647 index 560e66d..d5dd180 100644
31648 --- a/drivers/ide/it8172.c
31649 +++ b/drivers/ide/it8172.c
31650 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31651 .set_dma_mode = it8172_set_dma_mode,
31652 };
31653
31654 -static const struct ide_port_info it8172_port_info __devinitdata = {
31655 +static const struct ide_port_info it8172_port_info __devinitconst = {
31656 .name = DRV_NAME,
31657 .port_ops = &it8172_port_ops,
31658 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31659 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31660 index 46816ba..1847aeb 100644
31661 --- a/drivers/ide/it8213.c
31662 +++ b/drivers/ide/it8213.c
31663 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31664 .cable_detect = it8213_cable_detect,
31665 };
31666
31667 -static const struct ide_port_info it8213_chipset __devinitdata = {
31668 +static const struct ide_port_info it8213_chipset __devinitconst = {
31669 .name = DRV_NAME,
31670 .enablebits = { {0x41, 0x80, 0x80} },
31671 .port_ops = &it8213_port_ops,
31672 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31673 index 2e3169f..c5611db 100644
31674 --- a/drivers/ide/it821x.c
31675 +++ b/drivers/ide/it821x.c
31676 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31677 .cable_detect = it821x_cable_detect,
31678 };
31679
31680 -static const struct ide_port_info it821x_chipset __devinitdata = {
31681 +static const struct ide_port_info it821x_chipset __devinitconst = {
31682 .name = DRV_NAME,
31683 .init_chipset = init_chipset_it821x,
31684 .init_hwif = init_hwif_it821x,
31685 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31686 index 74c2c4a..efddd7d 100644
31687 --- a/drivers/ide/jmicron.c
31688 +++ b/drivers/ide/jmicron.c
31689 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31690 .cable_detect = jmicron_cable_detect,
31691 };
31692
31693 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31694 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31695 .name = DRV_NAME,
31696 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31697 .port_ops = &jmicron_port_ops,
31698 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31699 index 95327a2..73f78d8 100644
31700 --- a/drivers/ide/ns87415.c
31701 +++ b/drivers/ide/ns87415.c
31702 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31703 .dma_sff_read_status = superio_dma_sff_read_status,
31704 };
31705
31706 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31707 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31708 .name = DRV_NAME,
31709 .init_hwif = init_hwif_ns87415,
31710 .tp_ops = &ns87415_tp_ops,
31711 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31712 index 1a53a4c..39edc66 100644
31713 --- a/drivers/ide/opti621.c
31714 +++ b/drivers/ide/opti621.c
31715 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31716 .set_pio_mode = opti621_set_pio_mode,
31717 };
31718
31719 -static const struct ide_port_info opti621_chipset __devinitdata = {
31720 +static const struct ide_port_info opti621_chipset __devinitconst = {
31721 .name = DRV_NAME,
31722 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31723 .port_ops = &opti621_port_ops,
31724 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31725 index 9546fe2..2e5ceb6 100644
31726 --- a/drivers/ide/pdc202xx_new.c
31727 +++ b/drivers/ide/pdc202xx_new.c
31728 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31729 .udma_mask = udma, \
31730 }
31731
31732 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31733 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31734 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31735 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31736 };
31737 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31738 index 3a35ec6..5634510 100644
31739 --- a/drivers/ide/pdc202xx_old.c
31740 +++ b/drivers/ide/pdc202xx_old.c
31741 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31742 .max_sectors = sectors, \
31743 }
31744
31745 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31746 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31747 { /* 0: PDC20246 */
31748 .name = DRV_NAME,
31749 .init_chipset = init_chipset_pdc202xx,
31750 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31751 index 1892e81..fe0fd60 100644
31752 --- a/drivers/ide/piix.c
31753 +++ b/drivers/ide/piix.c
31754 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31755 .udma_mask = udma, \
31756 }
31757
31758 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
31759 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
31760 /* 0: MPIIX */
31761 { /*
31762 * MPIIX actually has only a single IDE channel mapped to
31763 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31764 index a6414a8..c04173e 100644
31765 --- a/drivers/ide/rz1000.c
31766 +++ b/drivers/ide/rz1000.c
31767 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31768 }
31769 }
31770
31771 -static const struct ide_port_info rz1000_chipset __devinitdata = {
31772 +static const struct ide_port_info rz1000_chipset __devinitconst = {
31773 .name = DRV_NAME,
31774 .host_flags = IDE_HFLAG_NO_DMA,
31775 };
31776 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31777 index 356b9b5..d4758eb 100644
31778 --- a/drivers/ide/sc1200.c
31779 +++ b/drivers/ide/sc1200.c
31780 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31781 .dma_sff_read_status = ide_dma_sff_read_status,
31782 };
31783
31784 -static const struct ide_port_info sc1200_chipset __devinitdata = {
31785 +static const struct ide_port_info sc1200_chipset __devinitconst = {
31786 .name = DRV_NAME,
31787 .port_ops = &sc1200_port_ops,
31788 .dma_ops = &sc1200_dma_ops,
31789 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31790 index b7f5b0c..9701038 100644
31791 --- a/drivers/ide/scc_pata.c
31792 +++ b/drivers/ide/scc_pata.c
31793 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31794 .dma_sff_read_status = scc_dma_sff_read_status,
31795 };
31796
31797 -static const struct ide_port_info scc_chipset __devinitdata = {
31798 +static const struct ide_port_info scc_chipset __devinitconst = {
31799 .name = "sccIDE",
31800 .init_iops = init_iops_scc,
31801 .init_dma = scc_init_dma,
31802 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31803 index 35fb8da..24d72ef 100644
31804 --- a/drivers/ide/serverworks.c
31805 +++ b/drivers/ide/serverworks.c
31806 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31807 .cable_detect = svwks_cable_detect,
31808 };
31809
31810 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31811 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31812 { /* 0: OSB4 */
31813 .name = DRV_NAME,
31814 .init_chipset = init_chipset_svwks,
31815 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31816 index ddeda44..46f7e30 100644
31817 --- a/drivers/ide/siimage.c
31818 +++ b/drivers/ide/siimage.c
31819 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31820 .udma_mask = ATA_UDMA6, \
31821 }
31822
31823 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31824 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31825 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31826 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31827 };
31828 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31829 index 4a00225..09e61b4 100644
31830 --- a/drivers/ide/sis5513.c
31831 +++ b/drivers/ide/sis5513.c
31832 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31833 .cable_detect = sis_cable_detect,
31834 };
31835
31836 -static const struct ide_port_info sis5513_chipset __devinitdata = {
31837 +static const struct ide_port_info sis5513_chipset __devinitconst = {
31838 .name = DRV_NAME,
31839 .init_chipset = init_chipset_sis5513,
31840 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31841 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31842 index f21dc2a..d051cd2 100644
31843 --- a/drivers/ide/sl82c105.c
31844 +++ b/drivers/ide/sl82c105.c
31845 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31846 .dma_sff_read_status = ide_dma_sff_read_status,
31847 };
31848
31849 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
31850 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
31851 .name = DRV_NAME,
31852 .init_chipset = init_chipset_sl82c105,
31853 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31854 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31855 index 864ffe0..863a5e9 100644
31856 --- a/drivers/ide/slc90e66.c
31857 +++ b/drivers/ide/slc90e66.c
31858 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31859 .cable_detect = slc90e66_cable_detect,
31860 };
31861
31862 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
31863 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
31864 .name = DRV_NAME,
31865 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31866 .port_ops = &slc90e66_port_ops,
31867 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31868 index 4799d5c..1794678 100644
31869 --- a/drivers/ide/tc86c001.c
31870 +++ b/drivers/ide/tc86c001.c
31871 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31872 .dma_sff_read_status = ide_dma_sff_read_status,
31873 };
31874
31875 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
31876 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
31877 .name = DRV_NAME,
31878 .init_hwif = init_hwif_tc86c001,
31879 .port_ops = &tc86c001_port_ops,
31880 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31881 index 281c914..55ce1b8 100644
31882 --- a/drivers/ide/triflex.c
31883 +++ b/drivers/ide/triflex.c
31884 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31885 .set_dma_mode = triflex_set_mode,
31886 };
31887
31888 -static const struct ide_port_info triflex_device __devinitdata = {
31889 +static const struct ide_port_info triflex_device __devinitconst = {
31890 .name = DRV_NAME,
31891 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31892 .port_ops = &triflex_port_ops,
31893 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31894 index 4b42ca0..e494a98 100644
31895 --- a/drivers/ide/trm290.c
31896 +++ b/drivers/ide/trm290.c
31897 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31898 .dma_check = trm290_dma_check,
31899 };
31900
31901 -static const struct ide_port_info trm290_chipset __devinitdata = {
31902 +static const struct ide_port_info trm290_chipset __devinitconst = {
31903 .name = DRV_NAME,
31904 .init_hwif = init_hwif_trm290,
31905 .tp_ops = &trm290_tp_ops,
31906 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31907 index f46f49c..eb77678 100644
31908 --- a/drivers/ide/via82cxxx.c
31909 +++ b/drivers/ide/via82cxxx.c
31910 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31911 .cable_detect = via82cxxx_cable_detect,
31912 };
31913
31914 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31915 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31916 .name = DRV_NAME,
31917 .init_chipset = init_chipset_via82cxxx,
31918 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31919 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31920 index eb0e2cc..14241c7 100644
31921 --- a/drivers/ieee802154/fakehard.c
31922 +++ b/drivers/ieee802154/fakehard.c
31923 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31924 phy->transmit_power = 0xbf;
31925
31926 dev->netdev_ops = &fake_ops;
31927 - dev->ml_priv = &fake_mlme;
31928 + dev->ml_priv = (void *)&fake_mlme;
31929
31930 priv = netdev_priv(dev);
31931 priv->phy = phy;
31932 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31933 index 8b72f39..55df4c8 100644
31934 --- a/drivers/infiniband/core/cm.c
31935 +++ b/drivers/infiniband/core/cm.c
31936 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31937
31938 struct cm_counter_group {
31939 struct kobject obj;
31940 - atomic_long_t counter[CM_ATTR_COUNT];
31941 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31942 };
31943
31944 struct cm_counter_attribute {
31945 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31946 struct ib_mad_send_buf *msg = NULL;
31947 int ret;
31948
31949 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31950 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31951 counter[CM_REQ_COUNTER]);
31952
31953 /* Quick state check to discard duplicate REQs. */
31954 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
31955 if (!cm_id_priv)
31956 return;
31957
31958 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31959 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31960 counter[CM_REP_COUNTER]);
31961 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
31962 if (ret)
31963 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
31964 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
31965 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
31966 spin_unlock_irq(&cm_id_priv->lock);
31967 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31968 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31969 counter[CM_RTU_COUNTER]);
31970 goto out;
31971 }
31972 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
31973 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
31974 dreq_msg->local_comm_id);
31975 if (!cm_id_priv) {
31976 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31977 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31978 counter[CM_DREQ_COUNTER]);
31979 cm_issue_drep(work->port, work->mad_recv_wc);
31980 return -EINVAL;
31981 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
31982 case IB_CM_MRA_REP_RCVD:
31983 break;
31984 case IB_CM_TIMEWAIT:
31985 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31986 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31987 counter[CM_DREQ_COUNTER]);
31988 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31989 goto unlock;
31990 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
31991 cm_free_msg(msg);
31992 goto deref;
31993 case IB_CM_DREQ_RCVD:
31994 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31995 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31996 counter[CM_DREQ_COUNTER]);
31997 goto unlock;
31998 default:
31999 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32000 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32001 cm_id_priv->msg, timeout)) {
32002 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32003 - atomic_long_inc(&work->port->
32004 + atomic_long_inc_unchecked(&work->port->
32005 counter_group[CM_RECV_DUPLICATES].
32006 counter[CM_MRA_COUNTER]);
32007 goto out;
32008 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32009 break;
32010 case IB_CM_MRA_REQ_RCVD:
32011 case IB_CM_MRA_REP_RCVD:
32012 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32013 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32014 counter[CM_MRA_COUNTER]);
32015 /* fall through */
32016 default:
32017 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32018 case IB_CM_LAP_IDLE:
32019 break;
32020 case IB_CM_MRA_LAP_SENT:
32021 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32022 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32023 counter[CM_LAP_COUNTER]);
32024 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32025 goto unlock;
32026 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32027 cm_free_msg(msg);
32028 goto deref;
32029 case IB_CM_LAP_RCVD:
32030 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32031 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32032 counter[CM_LAP_COUNTER]);
32033 goto unlock;
32034 default:
32035 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32036 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32037 if (cur_cm_id_priv) {
32038 spin_unlock_irq(&cm.lock);
32039 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32040 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32041 counter[CM_SIDR_REQ_COUNTER]);
32042 goto out; /* Duplicate message. */
32043 }
32044 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32045 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32046 msg->retries = 1;
32047
32048 - atomic_long_add(1 + msg->retries,
32049 + atomic_long_add_unchecked(1 + msg->retries,
32050 &port->counter_group[CM_XMIT].counter[attr_index]);
32051 if (msg->retries)
32052 - atomic_long_add(msg->retries,
32053 + atomic_long_add_unchecked(msg->retries,
32054 &port->counter_group[CM_XMIT_RETRIES].
32055 counter[attr_index]);
32056
32057 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32058 }
32059
32060 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32061 - atomic_long_inc(&port->counter_group[CM_RECV].
32062 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32063 counter[attr_id - CM_ATTR_ID_OFFSET]);
32064
32065 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32066 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32067 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32068
32069 return sprintf(buf, "%ld\n",
32070 - atomic_long_read(&group->counter[cm_attr->index]));
32071 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32072 }
32073
32074 static const struct sysfs_ops cm_counter_ops = {
32075 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32076 index 176c8f9..2627b62 100644
32077 --- a/drivers/infiniband/core/fmr_pool.c
32078 +++ b/drivers/infiniband/core/fmr_pool.c
32079 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32080
32081 struct task_struct *thread;
32082
32083 - atomic_t req_ser;
32084 - atomic_t flush_ser;
32085 + atomic_unchecked_t req_ser;
32086 + atomic_unchecked_t flush_ser;
32087
32088 wait_queue_head_t force_wait;
32089 };
32090 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32091 struct ib_fmr_pool *pool = pool_ptr;
32092
32093 do {
32094 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32095 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32096 ib_fmr_batch_release(pool);
32097
32098 - atomic_inc(&pool->flush_ser);
32099 + atomic_inc_unchecked(&pool->flush_ser);
32100 wake_up_interruptible(&pool->force_wait);
32101
32102 if (pool->flush_function)
32103 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32104 }
32105
32106 set_current_state(TASK_INTERRUPTIBLE);
32107 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32108 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32109 !kthread_should_stop())
32110 schedule();
32111 __set_current_state(TASK_RUNNING);
32112 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32113 pool->dirty_watermark = params->dirty_watermark;
32114 pool->dirty_len = 0;
32115 spin_lock_init(&pool->pool_lock);
32116 - atomic_set(&pool->req_ser, 0);
32117 - atomic_set(&pool->flush_ser, 0);
32118 + atomic_set_unchecked(&pool->req_ser, 0);
32119 + atomic_set_unchecked(&pool->flush_ser, 0);
32120 init_waitqueue_head(&pool->force_wait);
32121
32122 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32123 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32124 }
32125 spin_unlock_irq(&pool->pool_lock);
32126
32127 - serial = atomic_inc_return(&pool->req_ser);
32128 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32129 wake_up_process(pool->thread);
32130
32131 if (wait_event_interruptible(pool->force_wait,
32132 - atomic_read(&pool->flush_ser) - serial >= 0))
32133 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32134 return -EINTR;
32135
32136 return 0;
32137 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32138 } else {
32139 list_add_tail(&fmr->list, &pool->dirty_list);
32140 if (++pool->dirty_len >= pool->dirty_watermark) {
32141 - atomic_inc(&pool->req_ser);
32142 + atomic_inc_unchecked(&pool->req_ser);
32143 wake_up_process(pool->thread);
32144 }
32145 }
32146 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32147 index 40c8353..946b0e4 100644
32148 --- a/drivers/infiniband/hw/cxgb4/mem.c
32149 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32150 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32151 int err;
32152 struct fw_ri_tpte tpt;
32153 u32 stag_idx;
32154 - static atomic_t key;
32155 + static atomic_unchecked_t key;
32156
32157 if (c4iw_fatal_error(rdev))
32158 return -EIO;
32159 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32160 &rdev->resource.tpt_fifo_lock);
32161 if (!stag_idx)
32162 return -ENOMEM;
32163 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32164 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32165 }
32166 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32167 __func__, stag_state, type, pdid, stag_idx);
32168 diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c
32169 index 31ae1b1..641d285 100644
32170 --- a/drivers/infiniband/hw/ipath/ipath_fs.c
32171 +++ b/drivers/infiniband/hw/ipath/ipath_fs.c
32172 @@ -126,6 +126,8 @@ static const struct file_operations atomic_counters_ops = {
32173 };
32174
32175 static ssize_t flash_read(struct file *file, char __user *buf,
32176 + size_t count, loff_t *ppos) __size_overflow(3);
32177 +static ssize_t flash_read(struct file *file, char __user *buf,
32178 size_t count, loff_t *ppos)
32179 {
32180 struct ipath_devdata *dd;
32181 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32182 index 79b3dbc..96e5fcc 100644
32183 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32184 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32185 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32186 struct ib_atomic_eth *ateth;
32187 struct ipath_ack_entry *e;
32188 u64 vaddr;
32189 - atomic64_t *maddr;
32190 + atomic64_unchecked_t *maddr;
32191 u64 sdata;
32192 u32 rkey;
32193 u8 next;
32194 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32195 IB_ACCESS_REMOTE_ATOMIC)))
32196 goto nack_acc_unlck;
32197 /* Perform atomic OP and save result. */
32198 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32199 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32200 sdata = be64_to_cpu(ateth->swap_data);
32201 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32202 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32203 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32204 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32205 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32206 be64_to_cpu(ateth->compare_data),
32207 sdata);
32208 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32209 index 1f95bba..9530f87 100644
32210 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32211 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32212 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32213 unsigned long flags;
32214 struct ib_wc wc;
32215 u64 sdata;
32216 - atomic64_t *maddr;
32217 + atomic64_unchecked_t *maddr;
32218 enum ib_wc_status send_status;
32219
32220 /*
32221 @@ -382,11 +382,11 @@ again:
32222 IB_ACCESS_REMOTE_ATOMIC)))
32223 goto acc_err;
32224 /* Perform atomic OP and save result. */
32225 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32226 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32227 sdata = wqe->wr.wr.atomic.compare_add;
32228 *(u64 *) sqp->s_sge.sge.vaddr =
32229 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32230 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32231 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32232 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32233 sdata, wqe->wr.wr.atomic.swap);
32234 goto send_comp;
32235 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32236 index 5965b3d..16817fb 100644
32237 --- a/drivers/infiniband/hw/nes/nes.c
32238 +++ b/drivers/infiniband/hw/nes/nes.c
32239 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32240 LIST_HEAD(nes_adapter_list);
32241 static LIST_HEAD(nes_dev_list);
32242
32243 -atomic_t qps_destroyed;
32244 +atomic_unchecked_t qps_destroyed;
32245
32246 static unsigned int ee_flsh_adapter;
32247 static unsigned int sysfs_nonidx_addr;
32248 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32249 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32250 struct nes_adapter *nesadapter = nesdev->nesadapter;
32251
32252 - atomic_inc(&qps_destroyed);
32253 + atomic_inc_unchecked(&qps_destroyed);
32254
32255 /* Free the control structures */
32256
32257 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32258 index 568b4f1..5ea3eff 100644
32259 --- a/drivers/infiniband/hw/nes/nes.h
32260 +++ b/drivers/infiniband/hw/nes/nes.h
32261 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32262 extern unsigned int wqm_quanta;
32263 extern struct list_head nes_adapter_list;
32264
32265 -extern atomic_t cm_connects;
32266 -extern atomic_t cm_accepts;
32267 -extern atomic_t cm_disconnects;
32268 -extern atomic_t cm_closes;
32269 -extern atomic_t cm_connecteds;
32270 -extern atomic_t cm_connect_reqs;
32271 -extern atomic_t cm_rejects;
32272 -extern atomic_t mod_qp_timouts;
32273 -extern atomic_t qps_created;
32274 -extern atomic_t qps_destroyed;
32275 -extern atomic_t sw_qps_destroyed;
32276 +extern atomic_unchecked_t cm_connects;
32277 +extern atomic_unchecked_t cm_accepts;
32278 +extern atomic_unchecked_t cm_disconnects;
32279 +extern atomic_unchecked_t cm_closes;
32280 +extern atomic_unchecked_t cm_connecteds;
32281 +extern atomic_unchecked_t cm_connect_reqs;
32282 +extern atomic_unchecked_t cm_rejects;
32283 +extern atomic_unchecked_t mod_qp_timouts;
32284 +extern atomic_unchecked_t qps_created;
32285 +extern atomic_unchecked_t qps_destroyed;
32286 +extern atomic_unchecked_t sw_qps_destroyed;
32287 extern u32 mh_detected;
32288 extern u32 mh_pauses_sent;
32289 extern u32 cm_packets_sent;
32290 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32291 extern u32 cm_packets_received;
32292 extern u32 cm_packets_dropped;
32293 extern u32 cm_packets_retrans;
32294 -extern atomic_t cm_listens_created;
32295 -extern atomic_t cm_listens_destroyed;
32296 +extern atomic_unchecked_t cm_listens_created;
32297 +extern atomic_unchecked_t cm_listens_destroyed;
32298 extern u32 cm_backlog_drops;
32299 -extern atomic_t cm_loopbacks;
32300 -extern atomic_t cm_nodes_created;
32301 -extern atomic_t cm_nodes_destroyed;
32302 -extern atomic_t cm_accel_dropped_pkts;
32303 -extern atomic_t cm_resets_recvd;
32304 -extern atomic_t pau_qps_created;
32305 -extern atomic_t pau_qps_destroyed;
32306 +extern atomic_unchecked_t cm_loopbacks;
32307 +extern atomic_unchecked_t cm_nodes_created;
32308 +extern atomic_unchecked_t cm_nodes_destroyed;
32309 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32310 +extern atomic_unchecked_t cm_resets_recvd;
32311 +extern atomic_unchecked_t pau_qps_created;
32312 +extern atomic_unchecked_t pau_qps_destroyed;
32313
32314 extern u32 int_mod_timer_init;
32315 extern u32 int_mod_cq_depth_256;
32316 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32317 index 0a52d72..0642f36 100644
32318 --- a/drivers/infiniband/hw/nes/nes_cm.c
32319 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32320 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32321 u32 cm_packets_retrans;
32322 u32 cm_packets_created;
32323 u32 cm_packets_received;
32324 -atomic_t cm_listens_created;
32325 -atomic_t cm_listens_destroyed;
32326 +atomic_unchecked_t cm_listens_created;
32327 +atomic_unchecked_t cm_listens_destroyed;
32328 u32 cm_backlog_drops;
32329 -atomic_t cm_loopbacks;
32330 -atomic_t cm_nodes_created;
32331 -atomic_t cm_nodes_destroyed;
32332 -atomic_t cm_accel_dropped_pkts;
32333 -atomic_t cm_resets_recvd;
32334 +atomic_unchecked_t cm_loopbacks;
32335 +atomic_unchecked_t cm_nodes_created;
32336 +atomic_unchecked_t cm_nodes_destroyed;
32337 +atomic_unchecked_t cm_accel_dropped_pkts;
32338 +atomic_unchecked_t cm_resets_recvd;
32339
32340 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32341 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32342 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32343
32344 static struct nes_cm_core *g_cm_core;
32345
32346 -atomic_t cm_connects;
32347 -atomic_t cm_accepts;
32348 -atomic_t cm_disconnects;
32349 -atomic_t cm_closes;
32350 -atomic_t cm_connecteds;
32351 -atomic_t cm_connect_reqs;
32352 -atomic_t cm_rejects;
32353 +atomic_unchecked_t cm_connects;
32354 +atomic_unchecked_t cm_accepts;
32355 +atomic_unchecked_t cm_disconnects;
32356 +atomic_unchecked_t cm_closes;
32357 +atomic_unchecked_t cm_connecteds;
32358 +atomic_unchecked_t cm_connect_reqs;
32359 +atomic_unchecked_t cm_rejects;
32360
32361 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32362 {
32363 @@ -1271,7 +1271,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32364 kfree(listener);
32365 listener = NULL;
32366 ret = 0;
32367 - atomic_inc(&cm_listens_destroyed);
32368 + atomic_inc_unchecked(&cm_listens_destroyed);
32369 } else {
32370 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32371 }
32372 @@ -1473,7 +1473,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32373 cm_node->rem_mac);
32374
32375 add_hte_node(cm_core, cm_node);
32376 - atomic_inc(&cm_nodes_created);
32377 + atomic_inc_unchecked(&cm_nodes_created);
32378
32379 return cm_node;
32380 }
32381 @@ -1531,7 +1531,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32382 }
32383
32384 atomic_dec(&cm_core->node_cnt);
32385 - atomic_inc(&cm_nodes_destroyed);
32386 + atomic_inc_unchecked(&cm_nodes_destroyed);
32387 nesqp = cm_node->nesqp;
32388 if (nesqp) {
32389 nesqp->cm_node = NULL;
32390 @@ -1595,7 +1595,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32391
32392 static void drop_packet(struct sk_buff *skb)
32393 {
32394 - atomic_inc(&cm_accel_dropped_pkts);
32395 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32396 dev_kfree_skb_any(skb);
32397 }
32398
32399 @@ -1658,7 +1658,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32400 {
32401
32402 int reset = 0; /* whether to send reset in case of err.. */
32403 - atomic_inc(&cm_resets_recvd);
32404 + atomic_inc_unchecked(&cm_resets_recvd);
32405 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32406 " refcnt=%d\n", cm_node, cm_node->state,
32407 atomic_read(&cm_node->ref_count));
32408 @@ -2299,7 +2299,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32409 rem_ref_cm_node(cm_node->cm_core, cm_node);
32410 return NULL;
32411 }
32412 - atomic_inc(&cm_loopbacks);
32413 + atomic_inc_unchecked(&cm_loopbacks);
32414 loopbackremotenode->loopbackpartner = cm_node;
32415 loopbackremotenode->tcp_cntxt.rcv_wscale =
32416 NES_CM_DEFAULT_RCV_WND_SCALE;
32417 @@ -2574,7 +2574,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32418 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32419 else {
32420 rem_ref_cm_node(cm_core, cm_node);
32421 - atomic_inc(&cm_accel_dropped_pkts);
32422 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32423 dev_kfree_skb_any(skb);
32424 }
32425 break;
32426 @@ -2880,7 +2880,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32427
32428 if ((cm_id) && (cm_id->event_handler)) {
32429 if (issue_disconn) {
32430 - atomic_inc(&cm_disconnects);
32431 + atomic_inc_unchecked(&cm_disconnects);
32432 cm_event.event = IW_CM_EVENT_DISCONNECT;
32433 cm_event.status = disconn_status;
32434 cm_event.local_addr = cm_id->local_addr;
32435 @@ -2902,7 +2902,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32436 }
32437
32438 if (issue_close) {
32439 - atomic_inc(&cm_closes);
32440 + atomic_inc_unchecked(&cm_closes);
32441 nes_disconnect(nesqp, 1);
32442
32443 cm_id->provider_data = nesqp;
32444 @@ -3038,7 +3038,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32445
32446 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32447 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32448 - atomic_inc(&cm_accepts);
32449 + atomic_inc_unchecked(&cm_accepts);
32450
32451 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32452 netdev_refcnt_read(nesvnic->netdev));
32453 @@ -3240,7 +3240,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32454 struct nes_cm_core *cm_core;
32455 u8 *start_buff;
32456
32457 - atomic_inc(&cm_rejects);
32458 + atomic_inc_unchecked(&cm_rejects);
32459 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32460 loopback = cm_node->loopbackpartner;
32461 cm_core = cm_node->cm_core;
32462 @@ -3300,7 +3300,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32463 ntohl(cm_id->local_addr.sin_addr.s_addr),
32464 ntohs(cm_id->local_addr.sin_port));
32465
32466 - atomic_inc(&cm_connects);
32467 + atomic_inc_unchecked(&cm_connects);
32468 nesqp->active_conn = 1;
32469
32470 /* cache the cm_id in the qp */
32471 @@ -3406,7 +3406,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32472 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32473 return err;
32474 }
32475 - atomic_inc(&cm_listens_created);
32476 + atomic_inc_unchecked(&cm_listens_created);
32477 }
32478
32479 cm_id->add_ref(cm_id);
32480 @@ -3507,7 +3507,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32481
32482 if (nesqp->destroyed)
32483 return;
32484 - atomic_inc(&cm_connecteds);
32485 + atomic_inc_unchecked(&cm_connecteds);
32486 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32487 " local port 0x%04X. jiffies = %lu.\n",
32488 nesqp->hwqp.qp_id,
32489 @@ -3694,7 +3694,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32490
32491 cm_id->add_ref(cm_id);
32492 ret = cm_id->event_handler(cm_id, &cm_event);
32493 - atomic_inc(&cm_closes);
32494 + atomic_inc_unchecked(&cm_closes);
32495 cm_event.event = IW_CM_EVENT_CLOSE;
32496 cm_event.status = 0;
32497 cm_event.provider_data = cm_id->provider_data;
32498 @@ -3730,7 +3730,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32499 return;
32500 cm_id = cm_node->cm_id;
32501
32502 - atomic_inc(&cm_connect_reqs);
32503 + atomic_inc_unchecked(&cm_connect_reqs);
32504 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32505 cm_node, cm_id, jiffies);
32506
32507 @@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32508 return;
32509 cm_id = cm_node->cm_id;
32510
32511 - atomic_inc(&cm_connect_reqs);
32512 + atomic_inc_unchecked(&cm_connect_reqs);
32513 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32514 cm_node, cm_id, jiffies);
32515
32516 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32517 index b3b2a24..7bfaf1e 100644
32518 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32519 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32520 @@ -40,8 +40,8 @@
32521 #include "nes.h"
32522 #include "nes_mgt.h"
32523
32524 -atomic_t pau_qps_created;
32525 -atomic_t pau_qps_destroyed;
32526 +atomic_unchecked_t pau_qps_created;
32527 +atomic_unchecked_t pau_qps_destroyed;
32528
32529 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32530 {
32531 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32532 {
32533 struct sk_buff *skb;
32534 unsigned long flags;
32535 - atomic_inc(&pau_qps_destroyed);
32536 + atomic_inc_unchecked(&pau_qps_destroyed);
32537
32538 /* Free packets that have not yet been forwarded */
32539 /* Lock is acquired by skb_dequeue when removing the skb */
32540 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32541 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32542 skb_queue_head_init(&nesqp->pau_list);
32543 spin_lock_init(&nesqp->pau_lock);
32544 - atomic_inc(&pau_qps_created);
32545 + atomic_inc_unchecked(&pau_qps_created);
32546 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32547 }
32548
32549 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32550 index c00d2f3..8834298 100644
32551 --- a/drivers/infiniband/hw/nes/nes_nic.c
32552 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32553 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32554 target_stat_values[++index] = mh_detected;
32555 target_stat_values[++index] = mh_pauses_sent;
32556 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32557 - target_stat_values[++index] = atomic_read(&cm_connects);
32558 - target_stat_values[++index] = atomic_read(&cm_accepts);
32559 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32560 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32561 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32562 - target_stat_values[++index] = atomic_read(&cm_rejects);
32563 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32564 - target_stat_values[++index] = atomic_read(&qps_created);
32565 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32566 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32567 - target_stat_values[++index] = atomic_read(&cm_closes);
32568 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32569 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32570 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32571 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32572 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32573 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32574 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32575 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32576 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32577 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32578 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32579 target_stat_values[++index] = cm_packets_sent;
32580 target_stat_values[++index] = cm_packets_bounced;
32581 target_stat_values[++index] = cm_packets_created;
32582 target_stat_values[++index] = cm_packets_received;
32583 target_stat_values[++index] = cm_packets_dropped;
32584 target_stat_values[++index] = cm_packets_retrans;
32585 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32586 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32587 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32588 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32589 target_stat_values[++index] = cm_backlog_drops;
32590 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32591 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32592 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32593 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32594 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32595 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32596 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32597 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32598 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32599 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32600 target_stat_values[++index] = nesadapter->free_4kpbl;
32601 target_stat_values[++index] = nesadapter->free_256pbl;
32602 target_stat_values[++index] = int_mod_timer_init;
32603 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32604 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32605 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32606 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32607 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32608 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32609 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32610 }
32611
32612 /**
32613 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32614 index 5095bc4..41e8fff 100644
32615 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32616 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32617 @@ -46,9 +46,9 @@
32618
32619 #include <rdma/ib_umem.h>
32620
32621 -atomic_t mod_qp_timouts;
32622 -atomic_t qps_created;
32623 -atomic_t sw_qps_destroyed;
32624 +atomic_unchecked_t mod_qp_timouts;
32625 +atomic_unchecked_t qps_created;
32626 +atomic_unchecked_t sw_qps_destroyed;
32627
32628 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32629
32630 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32631 if (init_attr->create_flags)
32632 return ERR_PTR(-EINVAL);
32633
32634 - atomic_inc(&qps_created);
32635 + atomic_inc_unchecked(&qps_created);
32636 switch (init_attr->qp_type) {
32637 case IB_QPT_RC:
32638 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32639 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32640 struct iw_cm_event cm_event;
32641 int ret = 0;
32642
32643 - atomic_inc(&sw_qps_destroyed);
32644 + atomic_inc_unchecked(&sw_qps_destroyed);
32645 nesqp->destroyed = 1;
32646
32647 /* Blow away the connection if it exists. */
32648 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32649 index b881bdc..c2e360c 100644
32650 --- a/drivers/infiniband/hw/qib/qib.h
32651 +++ b/drivers/infiniband/hw/qib/qib.h
32652 @@ -51,6 +51,7 @@
32653 #include <linux/completion.h>
32654 #include <linux/kref.h>
32655 #include <linux/sched.h>
32656 +#include <linux/slab.h>
32657
32658 #include "qib_common.h"
32659 #include "qib_verbs.h"
32660 diff --git a/drivers/infiniband/hw/qib/qib_fs.c b/drivers/infiniband/hw/qib/qib_fs.c
32661 index df7fa25..0c854f0 100644
32662 --- a/drivers/infiniband/hw/qib/qib_fs.c
32663 +++ b/drivers/infiniband/hw/qib/qib_fs.c
32664 @@ -267,6 +267,8 @@ static const struct file_operations qsfp_ops[] = {
32665 };
32666
32667 static ssize_t flash_read(struct file *file, char __user *buf,
32668 + size_t count, loff_t *ppos) __size_overflow(3);
32669 +static ssize_t flash_read(struct file *file, char __user *buf,
32670 size_t count, loff_t *ppos)
32671 {
32672 struct qib_devdata *dd;
32673 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32674 index c351aa4..e6967c2 100644
32675 --- a/drivers/input/gameport/gameport.c
32676 +++ b/drivers/input/gameport/gameport.c
32677 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32678 */
32679 static void gameport_init_port(struct gameport *gameport)
32680 {
32681 - static atomic_t gameport_no = ATOMIC_INIT(0);
32682 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32683
32684 __module_get(THIS_MODULE);
32685
32686 mutex_init(&gameport->drv_mutex);
32687 device_initialize(&gameport->dev);
32688 dev_set_name(&gameport->dev, "gameport%lu",
32689 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32690 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32691 gameport->dev.bus = &gameport_bus;
32692 gameport->dev.release = gameport_release_port;
32693 if (gameport->parent)
32694 diff --git a/drivers/input/input.c b/drivers/input/input.c
32695 index da38d97..2aa0b79 100644
32696 --- a/drivers/input/input.c
32697 +++ b/drivers/input/input.c
32698 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32699 */
32700 int input_register_device(struct input_dev *dev)
32701 {
32702 - static atomic_t input_no = ATOMIC_INIT(0);
32703 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32704 struct input_handler *handler;
32705 const char *path;
32706 int error;
32707 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32708 dev->setkeycode = input_default_setkeycode;
32709
32710 dev_set_name(&dev->dev, "input%ld",
32711 - (unsigned long) atomic_inc_return(&input_no) - 1);
32712 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32713
32714 error = device_add(&dev->dev);
32715 if (error)
32716 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32717 index b8d8611..7a4a04b 100644
32718 --- a/drivers/input/joystick/sidewinder.c
32719 +++ b/drivers/input/joystick/sidewinder.c
32720 @@ -30,6 +30,7 @@
32721 #include <linux/kernel.h>
32722 #include <linux/module.h>
32723 #include <linux/slab.h>
32724 +#include <linux/sched.h>
32725 #include <linux/init.h>
32726 #include <linux/input.h>
32727 #include <linux/gameport.h>
32728 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32729 index d728875..844c89b 100644
32730 --- a/drivers/input/joystick/xpad.c
32731 +++ b/drivers/input/joystick/xpad.c
32732 @@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32733
32734 static int xpad_led_probe(struct usb_xpad *xpad)
32735 {
32736 - static atomic_t led_seq = ATOMIC_INIT(0);
32737 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32738 long led_no;
32739 struct xpad_led *led;
32740 struct led_classdev *led_cdev;
32741 @@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32742 if (!led)
32743 return -ENOMEM;
32744
32745 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32746 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32747
32748 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32749 led->xpad = xpad;
32750 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32751 index 0110b5a..d3ad144 100644
32752 --- a/drivers/input/mousedev.c
32753 +++ b/drivers/input/mousedev.c
32754 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32755
32756 spin_unlock_irq(&client->packet_lock);
32757
32758 - if (copy_to_user(buffer, data, count))
32759 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32760 return -EFAULT;
32761
32762 return count;
32763 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32764 index ba70058..571d25d 100644
32765 --- a/drivers/input/serio/serio.c
32766 +++ b/drivers/input/serio/serio.c
32767 @@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
32768 */
32769 static void serio_init_port(struct serio *serio)
32770 {
32771 - static atomic_t serio_no = ATOMIC_INIT(0);
32772 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32773
32774 __module_get(THIS_MODULE);
32775
32776 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
32777 mutex_init(&serio->drv_mutex);
32778 device_initialize(&serio->dev);
32779 dev_set_name(&serio->dev, "serio%ld",
32780 - (long)atomic_inc_return(&serio_no) - 1);
32781 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32782 serio->dev.bus = &serio_bus;
32783 serio->dev.release = serio_release_port;
32784 serio->dev.groups = serio_device_attr_groups;
32785 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32786 index e44933d..9ba484a 100644
32787 --- a/drivers/isdn/capi/capi.c
32788 +++ b/drivers/isdn/capi/capi.c
32789 @@ -83,8 +83,8 @@ struct capiminor {
32790
32791 struct capi20_appl *ap;
32792 u32 ncci;
32793 - atomic_t datahandle;
32794 - atomic_t msgid;
32795 + atomic_unchecked_t datahandle;
32796 + atomic_unchecked_t msgid;
32797
32798 struct tty_port port;
32799 int ttyinstop;
32800 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32801 capimsg_setu16(s, 2, mp->ap->applid);
32802 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32803 capimsg_setu8 (s, 5, CAPI_RESP);
32804 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32805 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32806 capimsg_setu32(s, 8, mp->ncci);
32807 capimsg_setu16(s, 12, datahandle);
32808 }
32809 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
32810 mp->outbytes -= len;
32811 spin_unlock_bh(&mp->outlock);
32812
32813 - datahandle = atomic_inc_return(&mp->datahandle);
32814 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32815 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32816 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32817 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32818 capimsg_setu16(skb->data, 2, mp->ap->applid);
32819 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32820 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32821 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32822 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32823 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32824 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32825 capimsg_setu16(skb->data, 16, len); /* Data length */
32826 diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
32827 index db621db..825ea1a 100644
32828 --- a/drivers/isdn/gigaset/common.c
32829 +++ b/drivers/isdn/gigaset/common.c
32830 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
32831 cs->commands_pending = 0;
32832 cs->cur_at_seq = 0;
32833 cs->gotfwver = -1;
32834 - cs->open_count = 0;
32835 + local_set(&cs->open_count, 0);
32836 cs->dev = NULL;
32837 cs->tty = NULL;
32838 cs->tty_dev = NULL;
32839 diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
32840 index 212efaf..f187c6b 100644
32841 --- a/drivers/isdn/gigaset/gigaset.h
32842 +++ b/drivers/isdn/gigaset/gigaset.h
32843 @@ -35,6 +35,7 @@
32844 #include <linux/tty_driver.h>
32845 #include <linux/list.h>
32846 #include <linux/atomic.h>
32847 +#include <asm/local.h>
32848
32849 #define GIG_VERSION {0, 5, 0, 0}
32850 #define GIG_COMPAT {0, 4, 0, 0}
32851 @@ -433,7 +434,7 @@ struct cardstate {
32852 spinlock_t cmdlock;
32853 unsigned curlen, cmdbytes;
32854
32855 - unsigned open_count;
32856 + local_t open_count;
32857 struct tty_struct *tty;
32858 struct tasklet_struct if_wake_tasklet;
32859 unsigned control_state;
32860 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32861 index ee0a549..a7c9798 100644
32862 --- a/drivers/isdn/gigaset/interface.c
32863 +++ b/drivers/isdn/gigaset/interface.c
32864 @@ -163,9 +163,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32865 }
32866 tty->driver_data = cs;
32867
32868 - ++cs->open_count;
32869 -
32870 - if (cs->open_count == 1) {
32871 + if (local_inc_return(&cs->open_count) == 1) {
32872 spin_lock_irqsave(&cs->lock, flags);
32873 cs->tty = tty;
32874 spin_unlock_irqrestore(&cs->lock, flags);
32875 @@ -193,10 +191,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32876
32877 if (!cs->connected)
32878 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32879 - else if (!cs->open_count)
32880 + else if (!local_read(&cs->open_count))
32881 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32882 else {
32883 - if (!--cs->open_count) {
32884 + if (!local_dec_return(&cs->open_count)) {
32885 spin_lock_irqsave(&cs->lock, flags);
32886 cs->tty = NULL;
32887 spin_unlock_irqrestore(&cs->lock, flags);
32888 @@ -231,7 +229,7 @@ static int if_ioctl(struct tty_struct *tty,
32889 if (!cs->connected) {
32890 gig_dbg(DEBUG_IF, "not connected");
32891 retval = -ENODEV;
32892 - } else if (!cs->open_count)
32893 + } else if (!local_read(&cs->open_count))
32894 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32895 else {
32896 retval = 0;
32897 @@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
32898 retval = -ENODEV;
32899 goto done;
32900 }
32901 - if (!cs->open_count) {
32902 + if (!local_read(&cs->open_count)) {
32903 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32904 retval = -ENODEV;
32905 goto done;
32906 @@ -414,7 +412,7 @@ static int if_write_room(struct tty_struct *tty)
32907 if (!cs->connected) {
32908 gig_dbg(DEBUG_IF, "not connected");
32909 retval = -ENODEV;
32910 - } else if (!cs->open_count)
32911 + } else if (!local_read(&cs->open_count))
32912 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32913 else if (cs->mstate != MS_LOCKED) {
32914 dev_warn(cs->dev, "can't write to unlocked device\n");
32915 @@ -444,7 +442,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
32916
32917 if (!cs->connected)
32918 gig_dbg(DEBUG_IF, "not connected");
32919 - else if (!cs->open_count)
32920 + else if (!local_read(&cs->open_count))
32921 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32922 else if (cs->mstate != MS_LOCKED)
32923 dev_warn(cs->dev, "can't write to unlocked device\n");
32924 @@ -472,7 +470,7 @@ static void if_throttle(struct tty_struct *tty)
32925
32926 if (!cs->connected)
32927 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32928 - else if (!cs->open_count)
32929 + else if (!local_read(&cs->open_count))
32930 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32931 else
32932 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
32933 @@ -496,7 +494,7 @@ static void if_unthrottle(struct tty_struct *tty)
32934
32935 if (!cs->connected)
32936 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32937 - else if (!cs->open_count)
32938 + else if (!local_read(&cs->open_count))
32939 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32940 else
32941 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
32942 @@ -527,7 +525,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
32943 goto out;
32944 }
32945
32946 - if (!cs->open_count) {
32947 + if (!local_read(&cs->open_count)) {
32948 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32949 goto out;
32950 }
32951 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32952 index 2a57da59..e7a12ed 100644
32953 --- a/drivers/isdn/hardware/avm/b1.c
32954 +++ b/drivers/isdn/hardware/avm/b1.c
32955 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
32956 }
32957 if (left) {
32958 if (t4file->user) {
32959 - if (copy_from_user(buf, dp, left))
32960 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32961 return -EFAULT;
32962 } else {
32963 memcpy(buf, dp, left);
32964 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
32965 }
32966 if (left) {
32967 if (config->user) {
32968 - if (copy_from_user(buf, dp, left))
32969 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32970 return -EFAULT;
32971 } else {
32972 memcpy(buf, dp, left);
32973 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32974 index 85784a7..a19ca98 100644
32975 --- a/drivers/isdn/hardware/eicon/divasync.h
32976 +++ b/drivers/isdn/hardware/eicon/divasync.h
32977 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32978 } diva_didd_add_adapter_t;
32979 typedef struct _diva_didd_remove_adapter {
32980 IDI_CALL p_request;
32981 -} diva_didd_remove_adapter_t;
32982 +} __no_const diva_didd_remove_adapter_t;
32983 typedef struct _diva_didd_read_adapter_array {
32984 void * buffer;
32985 dword length;
32986 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32987 index a3bd163..8956575 100644
32988 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32989 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32990 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32991 typedef struct _diva_os_idi_adapter_interface {
32992 diva_init_card_proc_t cleanup_adapter_proc;
32993 diva_cmd_card_proc_t cmd_proc;
32994 -} diva_os_idi_adapter_interface_t;
32995 +} __no_const diva_os_idi_adapter_interface_t;
32996
32997 typedef struct _diva_os_xdi_adapter {
32998 struct list_head link;
32999 diff --git a/drivers/isdn/i4l/isdn_net.c b/drivers/isdn/i4l/isdn_net.c
33000 index 2339d73..802ab87a 100644
33001 --- a/drivers/isdn/i4l/isdn_net.c
33002 +++ b/drivers/isdn/i4l/isdn_net.c
33003 @@ -1901,7 +1901,7 @@ static int isdn_net_header(struct sk_buff *skb, struct net_device *dev,
33004 {
33005 isdn_net_local *lp = netdev_priv(dev);
33006 unsigned char *p;
33007 - ushort len = 0;
33008 + int len = 0;
33009
33010 switch (lp->p_encap) {
33011 case ISDN_NET_ENCAP_ETHER:
33012 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33013 index 1f355bb..43f1fea 100644
33014 --- a/drivers/isdn/icn/icn.c
33015 +++ b/drivers/isdn/icn/icn.c
33016 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
33017 if (count > len)
33018 count = len;
33019 if (user) {
33020 - if (copy_from_user(msg, buf, count))
33021 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33022 return -EFAULT;
33023 } else
33024 memcpy(msg, buf, count);
33025 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33026 index b5fdcb7..5b6c59f 100644
33027 --- a/drivers/lguest/core.c
33028 +++ b/drivers/lguest/core.c
33029 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33030 * it's worked so far. The end address needs +1 because __get_vm_area
33031 * allocates an extra guard page, so we need space for that.
33032 */
33033 +
33034 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33035 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33036 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33037 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33038 +#else
33039 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33040 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33041 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33042 +#endif
33043 +
33044 if (!switcher_vma) {
33045 err = -ENOMEM;
33046 printk("lguest: could not map switcher pages high\n");
33047 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33048 * Now the Switcher is mapped at the right address, we can't fail!
33049 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33050 */
33051 - memcpy(switcher_vma->addr, start_switcher_text,
33052 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33053 end_switcher_text - start_switcher_text);
33054
33055 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33056 diff --git a/drivers/lguest/lguest_user.c b/drivers/lguest/lguest_user.c
33057 index ff4a0bc..f5fdd9c 100644
33058 --- a/drivers/lguest/lguest_user.c
33059 +++ b/drivers/lguest/lguest_user.c
33060 @@ -198,6 +198,7 @@ static int user_send_irq(struct lg_cpu *cpu, const unsigned long __user *input)
33061 * Once our Guest is initialized, the Launcher makes it run by reading
33062 * from /dev/lguest.
33063 */
33064 +static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o) __size_overflow(3);
33065 static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o)
33066 {
33067 struct lguest *lg = file->private_data;
33068 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33069 index 65af42f..530c87a 100644
33070 --- a/drivers/lguest/x86/core.c
33071 +++ b/drivers/lguest/x86/core.c
33072 @@ -59,7 +59,7 @@ static struct {
33073 /* Offset from where switcher.S was compiled to where we've copied it */
33074 static unsigned long switcher_offset(void)
33075 {
33076 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33077 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33078 }
33079
33080 /* This cpu's struct lguest_pages. */
33081 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33082 * These copies are pretty cheap, so we do them unconditionally: */
33083 /* Save the current Host top-level page directory.
33084 */
33085 +
33086 +#ifdef CONFIG_PAX_PER_CPU_PGD
33087 + pages->state.host_cr3 = read_cr3();
33088 +#else
33089 pages->state.host_cr3 = __pa(current->mm->pgd);
33090 +#endif
33091 +
33092 /*
33093 * Set up the Guest's page tables to see this CPU's pages (and no
33094 * other CPU's pages).
33095 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33096 * compiled-in switcher code and the high-mapped copy we just made.
33097 */
33098 for (i = 0; i < IDT_ENTRIES; i++)
33099 - default_idt_entries[i] += switcher_offset();
33100 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33101
33102 /*
33103 * Set up the Switcher's per-cpu areas.
33104 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33105 * it will be undisturbed when we switch. To change %cs and jump we
33106 * need this structure to feed to Intel's "lcall" instruction.
33107 */
33108 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33109 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33110 lguest_entry.segment = LGUEST_CS;
33111
33112 /*
33113 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33114 index 40634b0..4f5855e 100644
33115 --- a/drivers/lguest/x86/switcher_32.S
33116 +++ b/drivers/lguest/x86/switcher_32.S
33117 @@ -87,6 +87,7 @@
33118 #include <asm/page.h>
33119 #include <asm/segment.h>
33120 #include <asm/lguest.h>
33121 +#include <asm/processor-flags.h>
33122
33123 // We mark the start of the code to copy
33124 // It's placed in .text tho it's never run here
33125 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33126 // Changes type when we load it: damn Intel!
33127 // For after we switch over our page tables
33128 // That entry will be read-only: we'd crash.
33129 +
33130 +#ifdef CONFIG_PAX_KERNEXEC
33131 + mov %cr0, %edx
33132 + xor $X86_CR0_WP, %edx
33133 + mov %edx, %cr0
33134 +#endif
33135 +
33136 movl $(GDT_ENTRY_TSS*8), %edx
33137 ltr %dx
33138
33139 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33140 // Let's clear it again for our return.
33141 // The GDT descriptor of the Host
33142 // Points to the table after two "size" bytes
33143 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33144 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33145 // Clear "used" from type field (byte 5, bit 2)
33146 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33147 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33148 +
33149 +#ifdef CONFIG_PAX_KERNEXEC
33150 + mov %cr0, %eax
33151 + xor $X86_CR0_WP, %eax
33152 + mov %eax, %cr0
33153 +#endif
33154
33155 // Once our page table's switched, the Guest is live!
33156 // The Host fades as we run this final step.
33157 @@ -295,13 +309,12 @@ deliver_to_host:
33158 // I consulted gcc, and it gave
33159 // These instructions, which I gladly credit:
33160 leal (%edx,%ebx,8), %eax
33161 - movzwl (%eax),%edx
33162 - movl 4(%eax), %eax
33163 - xorw %ax, %ax
33164 - orl %eax, %edx
33165 + movl 4(%eax), %edx
33166 + movw (%eax), %dx
33167 // Now the address of the handler's in %edx
33168 // We call it now: its "iret" drops us home.
33169 - jmp *%edx
33170 + ljmp $__KERNEL_CS, $1f
33171 +1: jmp *%edx
33172
33173 // Every interrupt can come to us here
33174 // But we must truly tell each apart.
33175 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33176 index 4daf9e5..b8d1d0f 100644
33177 --- a/drivers/macintosh/macio_asic.c
33178 +++ b/drivers/macintosh/macio_asic.c
33179 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33180 * MacIO is matched against any Apple ID, it's probe() function
33181 * will then decide wether it applies or not
33182 */
33183 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33184 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33185 .vendor = PCI_VENDOR_ID_APPLE,
33186 .device = PCI_ANY_ID,
33187 .subvendor = PCI_ANY_ID,
33188 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33189 index 1ce84ed..0fdd40a 100644
33190 --- a/drivers/md/dm-ioctl.c
33191 +++ b/drivers/md/dm-ioctl.c
33192 @@ -1589,7 +1589,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33193 cmd == DM_LIST_VERSIONS_CMD)
33194 return 0;
33195
33196 - if ((cmd == DM_DEV_CREATE_CMD)) {
33197 + if (cmd == DM_DEV_CREATE_CMD) {
33198 if (!*param->name) {
33199 DMWARN("name not supplied when creating device");
33200 return -EINVAL;
33201 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33202 index 9bfd057..01180bc 100644
33203 --- a/drivers/md/dm-raid1.c
33204 +++ b/drivers/md/dm-raid1.c
33205 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33206
33207 struct mirror {
33208 struct mirror_set *ms;
33209 - atomic_t error_count;
33210 + atomic_unchecked_t error_count;
33211 unsigned long error_type;
33212 struct dm_dev *dev;
33213 sector_t offset;
33214 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33215 struct mirror *m;
33216
33217 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33218 - if (!atomic_read(&m->error_count))
33219 + if (!atomic_read_unchecked(&m->error_count))
33220 return m;
33221
33222 return NULL;
33223 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33224 * simple way to tell if a device has encountered
33225 * errors.
33226 */
33227 - atomic_inc(&m->error_count);
33228 + atomic_inc_unchecked(&m->error_count);
33229
33230 if (test_and_set_bit(error_type, &m->error_type))
33231 return;
33232 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33233 struct mirror *m = get_default_mirror(ms);
33234
33235 do {
33236 - if (likely(!atomic_read(&m->error_count)))
33237 + if (likely(!atomic_read_unchecked(&m->error_count)))
33238 return m;
33239
33240 if (m-- == ms->mirror)
33241 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33242 {
33243 struct mirror *default_mirror = get_default_mirror(m->ms);
33244
33245 - return !atomic_read(&default_mirror->error_count);
33246 + return !atomic_read_unchecked(&default_mirror->error_count);
33247 }
33248
33249 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33250 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33251 */
33252 if (likely(region_in_sync(ms, region, 1)))
33253 m = choose_mirror(ms, bio->bi_sector);
33254 - else if (m && atomic_read(&m->error_count))
33255 + else if (m && atomic_read_unchecked(&m->error_count))
33256 m = NULL;
33257
33258 if (likely(m))
33259 @@ -937,7 +937,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33260 }
33261
33262 ms->mirror[mirror].ms = ms;
33263 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33264 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33265 ms->mirror[mirror].error_type = 0;
33266 ms->mirror[mirror].offset = offset;
33267
33268 @@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_target *ti)
33269 */
33270 static char device_status_char(struct mirror *m)
33271 {
33272 - if (!atomic_read(&(m->error_count)))
33273 + if (!atomic_read_unchecked(&(m->error_count)))
33274 return 'A';
33275
33276 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33277 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33278 index 3d80cf0..b77cc47 100644
33279 --- a/drivers/md/dm-stripe.c
33280 +++ b/drivers/md/dm-stripe.c
33281 @@ -20,7 +20,7 @@ struct stripe {
33282 struct dm_dev *dev;
33283 sector_t physical_start;
33284
33285 - atomic_t error_count;
33286 + atomic_unchecked_t error_count;
33287 };
33288
33289 struct stripe_c {
33290 @@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33291 kfree(sc);
33292 return r;
33293 }
33294 - atomic_set(&(sc->stripe[i].error_count), 0);
33295 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33296 }
33297
33298 ti->private = sc;
33299 @@ -314,7 +314,7 @@ static int stripe_status(struct dm_target *ti,
33300 DMEMIT("%d ", sc->stripes);
33301 for (i = 0; i < sc->stripes; i++) {
33302 DMEMIT("%s ", sc->stripe[i].dev->name);
33303 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33304 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33305 'D' : 'A';
33306 }
33307 buffer[i] = '\0';
33308 @@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33309 */
33310 for (i = 0; i < sc->stripes; i++)
33311 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33312 - atomic_inc(&(sc->stripe[i].error_count));
33313 - if (atomic_read(&(sc->stripe[i].error_count)) <
33314 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33315 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33316 DM_IO_ERROR_THRESHOLD)
33317 schedule_work(&sc->trigger_event);
33318 }
33319 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33320 index 8e91321..fd17aef 100644
33321 --- a/drivers/md/dm-table.c
33322 +++ b/drivers/md/dm-table.c
33323 @@ -391,7 +391,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33324 if (!dev_size)
33325 return 0;
33326
33327 - if ((start >= dev_size) || (start + len > dev_size)) {
33328 + if ((start >= dev_size) || (len > dev_size - start)) {
33329 DMWARN("%s: %s too small for target: "
33330 "start=%llu, len=%llu, dev_size=%llu",
33331 dm_device_name(ti->table->md), bdevname(bdev, b),
33332 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33333 index 237571a..fb6d19b 100644
33334 --- a/drivers/md/dm-thin-metadata.c
33335 +++ b/drivers/md/dm-thin-metadata.c
33336 @@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33337
33338 pmd->info.tm = tm;
33339 pmd->info.levels = 2;
33340 - pmd->info.value_type.context = pmd->data_sm;
33341 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33342 pmd->info.value_type.size = sizeof(__le64);
33343 pmd->info.value_type.inc = data_block_inc;
33344 pmd->info.value_type.dec = data_block_dec;
33345 @@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33346
33347 pmd->bl_info.tm = tm;
33348 pmd->bl_info.levels = 1;
33349 - pmd->bl_info.value_type.context = pmd->data_sm;
33350 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33351 pmd->bl_info.value_type.size = sizeof(__le64);
33352 pmd->bl_info.value_type.inc = data_block_inc;
33353 pmd->bl_info.value_type.dec = data_block_dec;
33354 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33355 index 4720f68..78d1df7 100644
33356 --- a/drivers/md/dm.c
33357 +++ b/drivers/md/dm.c
33358 @@ -177,9 +177,9 @@ struct mapped_device {
33359 /*
33360 * Event handling.
33361 */
33362 - atomic_t event_nr;
33363 + atomic_unchecked_t event_nr;
33364 wait_queue_head_t eventq;
33365 - atomic_t uevent_seq;
33366 + atomic_unchecked_t uevent_seq;
33367 struct list_head uevent_list;
33368 spinlock_t uevent_lock; /* Protect access to uevent_list */
33369
33370 @@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
33371 rwlock_init(&md->map_lock);
33372 atomic_set(&md->holders, 1);
33373 atomic_set(&md->open_count, 0);
33374 - atomic_set(&md->event_nr, 0);
33375 - atomic_set(&md->uevent_seq, 0);
33376 + atomic_set_unchecked(&md->event_nr, 0);
33377 + atomic_set_unchecked(&md->uevent_seq, 0);
33378 INIT_LIST_HEAD(&md->uevent_list);
33379 spin_lock_init(&md->uevent_lock);
33380
33381 @@ -1980,7 +1980,7 @@ static void event_callback(void *context)
33382
33383 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33384
33385 - atomic_inc(&md->event_nr);
33386 + atomic_inc_unchecked(&md->event_nr);
33387 wake_up(&md->eventq);
33388 }
33389
33390 @@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33391
33392 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33393 {
33394 - return atomic_add_return(1, &md->uevent_seq);
33395 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33396 }
33397
33398 uint32_t dm_get_event_nr(struct mapped_device *md)
33399 {
33400 - return atomic_read(&md->event_nr);
33401 + return atomic_read_unchecked(&md->event_nr);
33402 }
33403
33404 int dm_wait_event(struct mapped_device *md, int event_nr)
33405 {
33406 return wait_event_interruptible(md->eventq,
33407 - (event_nr != atomic_read(&md->event_nr)));
33408 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33409 }
33410
33411 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33412 diff --git a/drivers/md/md.c b/drivers/md/md.c
33413 index f47f1f8..b7f559e 100644
33414 --- a/drivers/md/md.c
33415 +++ b/drivers/md/md.c
33416 @@ -278,10 +278,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33417 * start build, activate spare
33418 */
33419 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33420 -static atomic_t md_event_count;
33421 +static atomic_unchecked_t md_event_count;
33422 void md_new_event(struct mddev *mddev)
33423 {
33424 - atomic_inc(&md_event_count);
33425 + atomic_inc_unchecked(&md_event_count);
33426 wake_up(&md_event_waiters);
33427 }
33428 EXPORT_SYMBOL_GPL(md_new_event);
33429 @@ -291,7 +291,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33430 */
33431 static void md_new_event_inintr(struct mddev *mddev)
33432 {
33433 - atomic_inc(&md_event_count);
33434 + atomic_inc_unchecked(&md_event_count);
33435 wake_up(&md_event_waiters);
33436 }
33437
33438 @@ -1525,7 +1525,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33439
33440 rdev->preferred_minor = 0xffff;
33441 rdev->data_offset = le64_to_cpu(sb->data_offset);
33442 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33443 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33444
33445 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33446 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33447 @@ -1742,7 +1742,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33448 else
33449 sb->resync_offset = cpu_to_le64(0);
33450
33451 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33452 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33453
33454 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33455 sb->size = cpu_to_le64(mddev->dev_sectors);
33456 @@ -2639,7 +2639,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33457 static ssize_t
33458 errors_show(struct md_rdev *rdev, char *page)
33459 {
33460 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33461 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33462 }
33463
33464 static ssize_t
33465 @@ -2648,7 +2648,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33466 char *e;
33467 unsigned long n = simple_strtoul(buf, &e, 10);
33468 if (*buf && (*e == 0 || *e == '\n')) {
33469 - atomic_set(&rdev->corrected_errors, n);
33470 + atomic_set_unchecked(&rdev->corrected_errors, n);
33471 return len;
33472 }
33473 return -EINVAL;
33474 @@ -3039,8 +3039,8 @@ int md_rdev_init(struct md_rdev *rdev)
33475 rdev->sb_loaded = 0;
33476 rdev->bb_page = NULL;
33477 atomic_set(&rdev->nr_pending, 0);
33478 - atomic_set(&rdev->read_errors, 0);
33479 - atomic_set(&rdev->corrected_errors, 0);
33480 + atomic_set_unchecked(&rdev->read_errors, 0);
33481 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33482
33483 INIT_LIST_HEAD(&rdev->same_set);
33484 init_waitqueue_head(&rdev->blocked_wait);
33485 @@ -6683,7 +6683,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33486
33487 spin_unlock(&pers_lock);
33488 seq_printf(seq, "\n");
33489 - seq->poll_event = atomic_read(&md_event_count);
33490 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33491 return 0;
33492 }
33493 if (v == (void*)2) {
33494 @@ -6772,7 +6772,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33495 chunk_kb ? "KB" : "B");
33496 if (bitmap->file) {
33497 seq_printf(seq, ", file: ");
33498 - seq_path(seq, &bitmap->file->f_path, " \t\n");
33499 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
33500 }
33501
33502 seq_printf(seq, "\n");
33503 @@ -6803,7 +6803,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33504 return error;
33505
33506 seq = file->private_data;
33507 - seq->poll_event = atomic_read(&md_event_count);
33508 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33509 return error;
33510 }
33511
33512 @@ -6817,7 +6817,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33513 /* always allow read */
33514 mask = POLLIN | POLLRDNORM;
33515
33516 - if (seq->poll_event != atomic_read(&md_event_count))
33517 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33518 mask |= POLLERR | POLLPRI;
33519 return mask;
33520 }
33521 @@ -6861,7 +6861,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33522 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33523 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33524 (int)part_stat_read(&disk->part0, sectors[1]) -
33525 - atomic_read(&disk->sync_io);
33526 + atomic_read_unchecked(&disk->sync_io);
33527 /* sync IO will cause sync_io to increase before the disk_stats
33528 * as sync_io is counted when a request starts, and
33529 * disk_stats is counted when it completes.
33530 diff --git a/drivers/md/md.h b/drivers/md/md.h
33531 index cf742d9..7c7c745 100644
33532 --- a/drivers/md/md.h
33533 +++ b/drivers/md/md.h
33534 @@ -120,13 +120,13 @@ struct md_rdev {
33535 * only maintained for arrays that
33536 * support hot removal
33537 */
33538 - atomic_t read_errors; /* number of consecutive read errors that
33539 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33540 * we have tried to ignore.
33541 */
33542 struct timespec last_read_error; /* monotonic time since our
33543 * last read error
33544 */
33545 - atomic_t corrected_errors; /* number of corrected read errors,
33546 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33547 * for reporting to userspace and storing
33548 * in superblock.
33549 */
33550 @@ -410,7 +410,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33551
33552 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33553 {
33554 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33555 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33556 }
33557
33558 struct md_personality
33559 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33560 index 50ed53b..4f29d7d 100644
33561 --- a/drivers/md/persistent-data/dm-space-map-checker.c
33562 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
33563 @@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
33564 /*----------------------------------------------------------------*/
33565
33566 struct sm_checker {
33567 - struct dm_space_map sm;
33568 + dm_space_map_no_const sm;
33569
33570 struct count_array old_counts;
33571 struct count_array counts;
33572 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33573 index fc469ba..2d91555 100644
33574 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33575 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33576 @@ -23,7 +23,7 @@
33577 * Space map interface.
33578 */
33579 struct sm_disk {
33580 - struct dm_space_map sm;
33581 + dm_space_map_no_const sm;
33582
33583 struct ll_disk ll;
33584 struct ll_disk old_ll;
33585 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33586 index e89ae5e..062e4c2 100644
33587 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33588 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33589 @@ -43,7 +43,7 @@ struct block_op {
33590 };
33591
33592 struct sm_metadata {
33593 - struct dm_space_map sm;
33594 + dm_space_map_no_const sm;
33595
33596 struct ll_disk ll;
33597 struct ll_disk old_ll;
33598 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33599 index 1cbfc6b..56e1dbb 100644
33600 --- a/drivers/md/persistent-data/dm-space-map.h
33601 +++ b/drivers/md/persistent-data/dm-space-map.h
33602 @@ -60,6 +60,7 @@ struct dm_space_map {
33603 int (*root_size)(struct dm_space_map *sm, size_t *result);
33604 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33605 };
33606 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33607
33608 /*----------------------------------------------------------------*/
33609
33610 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33611 index 7d9e071..015b1d5 100644
33612 --- a/drivers/md/raid1.c
33613 +++ b/drivers/md/raid1.c
33614 @@ -1568,7 +1568,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33615 if (r1_sync_page_io(rdev, sect, s,
33616 bio->bi_io_vec[idx].bv_page,
33617 READ) != 0)
33618 - atomic_add(s, &rdev->corrected_errors);
33619 + atomic_add_unchecked(s, &rdev->corrected_errors);
33620 }
33621 sectors -= s;
33622 sect += s;
33623 @@ -1781,7 +1781,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33624 test_bit(In_sync, &rdev->flags)) {
33625 if (r1_sync_page_io(rdev, sect, s,
33626 conf->tmppage, READ)) {
33627 - atomic_add(s, &rdev->corrected_errors);
33628 + atomic_add_unchecked(s, &rdev->corrected_errors);
33629 printk(KERN_INFO
33630 "md/raid1:%s: read error corrected "
33631 "(%d sectors at %llu on %s)\n",
33632 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33633 index 685ddf3..955b087 100644
33634 --- a/drivers/md/raid10.c
33635 +++ b/drivers/md/raid10.c
33636 @@ -1440,7 +1440,7 @@ static void end_sync_read(struct bio *bio, int error)
33637 /* The write handler will notice the lack of
33638 * R10BIO_Uptodate and record any errors etc
33639 */
33640 - atomic_add(r10_bio->sectors,
33641 + atomic_add_unchecked(r10_bio->sectors,
33642 &conf->mirrors[d].rdev->corrected_errors);
33643
33644 /* for reconstruct, we always reschedule after a read.
33645 @@ -1740,7 +1740,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33646 {
33647 struct timespec cur_time_mon;
33648 unsigned long hours_since_last;
33649 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33650 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33651
33652 ktime_get_ts(&cur_time_mon);
33653
33654 @@ -1762,9 +1762,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33655 * overflowing the shift of read_errors by hours_since_last.
33656 */
33657 if (hours_since_last >= 8 * sizeof(read_errors))
33658 - atomic_set(&rdev->read_errors, 0);
33659 + atomic_set_unchecked(&rdev->read_errors, 0);
33660 else
33661 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33662 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33663 }
33664
33665 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33666 @@ -1814,8 +1814,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33667 return;
33668
33669 check_decay_read_errors(mddev, rdev);
33670 - atomic_inc(&rdev->read_errors);
33671 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33672 + atomic_inc_unchecked(&rdev->read_errors);
33673 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33674 char b[BDEVNAME_SIZE];
33675 bdevname(rdev->bdev, b);
33676
33677 @@ -1823,7 +1823,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33678 "md/raid10:%s: %s: Raid device exceeded "
33679 "read_error threshold [cur %d:max %d]\n",
33680 mdname(mddev), b,
33681 - atomic_read(&rdev->read_errors), max_read_errors);
33682 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33683 printk(KERN_NOTICE
33684 "md/raid10:%s: %s: Failing raid device\n",
33685 mdname(mddev), b);
33686 @@ -1968,7 +1968,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33687 (unsigned long long)(
33688 sect + rdev->data_offset),
33689 bdevname(rdev->bdev, b));
33690 - atomic_add(s, &rdev->corrected_errors);
33691 + atomic_add_unchecked(s, &rdev->corrected_errors);
33692 }
33693
33694 rdev_dec_pending(rdev, mddev);
33695 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33696 index 858fdbb..b2dac95 100644
33697 --- a/drivers/md/raid5.c
33698 +++ b/drivers/md/raid5.c
33699 @@ -1610,19 +1610,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
33700 (unsigned long long)(sh->sector
33701 + rdev->data_offset),
33702 bdevname(rdev->bdev, b));
33703 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33704 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33705 clear_bit(R5_ReadError, &sh->dev[i].flags);
33706 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33707 }
33708 - if (atomic_read(&conf->disks[i].rdev->read_errors))
33709 - atomic_set(&conf->disks[i].rdev->read_errors, 0);
33710 + if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
33711 + atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
33712 } else {
33713 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
33714 int retry = 0;
33715 rdev = conf->disks[i].rdev;
33716
33717 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33718 - atomic_inc(&rdev->read_errors);
33719 + atomic_inc_unchecked(&rdev->read_errors);
33720 if (conf->mddev->degraded >= conf->max_degraded)
33721 printk_ratelimited(
33722 KERN_WARNING
33723 @@ -1642,7 +1642,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33724 (unsigned long long)(sh->sector
33725 + rdev->data_offset),
33726 bdn);
33727 - else if (atomic_read(&rdev->read_errors)
33728 + else if (atomic_read_unchecked(&rdev->read_errors)
33729 > conf->max_nr_stripes)
33730 printk(KERN_WARNING
33731 "md/raid:%s: Too many read errors, failing device %s.\n",
33732 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33733 index ba9a643..e474ab5 100644
33734 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33735 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33736 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33737 .subvendor = _subvend, .subdevice = _subdev, \
33738 .driver_data = (unsigned long)&_driverdata }
33739
33740 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33741 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33742 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33743 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33744 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33745 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33746 index a7d876f..8c21b61 100644
33747 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33748 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33749 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33750 union {
33751 dmx_ts_cb ts;
33752 dmx_section_cb sec;
33753 - } cb;
33754 + } __no_const cb;
33755
33756 struct dvb_demux *demux;
33757 void *priv;
33758 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33759 index f732877..d38c35a 100644
33760 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33761 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33762 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33763 const struct dvb_device *template, void *priv, int type)
33764 {
33765 struct dvb_device *dvbdev;
33766 - struct file_operations *dvbdevfops;
33767 + file_operations_no_const *dvbdevfops;
33768 struct device *clsdev;
33769 int minor;
33770 int id;
33771 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33772 index 9f2a02c..5920f88 100644
33773 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33774 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33775 @@ -1069,7 +1069,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33776 struct dib0700_adapter_state {
33777 int (*set_param_save) (struct dvb_frontend *,
33778 struct dvb_frontend_parameters *);
33779 -};
33780 +} __no_const;
33781
33782 static int dib7070_set_param_override(struct dvb_frontend *fe,
33783 struct dvb_frontend_parameters *fep)
33784 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33785 index f103ec1..5e8968b 100644
33786 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33787 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33788 @@ -95,7 +95,7 @@ struct su3000_state {
33789
33790 struct s6x0_state {
33791 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33792 -};
33793 +} __no_const;
33794
33795 /* debug */
33796 static int dvb_usb_dw2102_debug;
33797 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33798 index 404f63a..4796533 100644
33799 --- a/drivers/media/dvb/frontends/dib3000.h
33800 +++ b/drivers/media/dvb/frontends/dib3000.h
33801 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33802 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33803 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33804 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33805 -};
33806 +} __no_const;
33807
33808 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33809 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33810 diff --git a/drivers/media/dvb/frontends/ds3000.c b/drivers/media/dvb/frontends/ds3000.c
33811 index 90bf573..e8463da 100644
33812 --- a/drivers/media/dvb/frontends/ds3000.c
33813 +++ b/drivers/media/dvb/frontends/ds3000.c
33814 @@ -1210,7 +1210,7 @@ static int ds3000_set_frontend(struct dvb_frontend *fe,
33815
33816 for (i = 0; i < 30 ; i++) {
33817 ds3000_read_status(fe, &status);
33818 - if (status && FE_HAS_LOCK)
33819 + if (status & FE_HAS_LOCK)
33820 break;
33821
33822 msleep(10);
33823 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33824 index 0564192..75b16f5 100644
33825 --- a/drivers/media/dvb/ngene/ngene-cards.c
33826 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33827 @@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
33828
33829 /****************************************************************************/
33830
33831 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33832 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33833 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33834 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33835 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33836 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33837 index 16a089f..ab1667d 100644
33838 --- a/drivers/media/radio/radio-cadet.c
33839 +++ b/drivers/media/radio/radio-cadet.c
33840 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33841 unsigned char readbuf[RDS_BUFFER];
33842 int i = 0;
33843
33844 + if (count > RDS_BUFFER)
33845 + return -EFAULT;
33846 mutex_lock(&dev->lock);
33847 if (dev->rdsstat == 0) {
33848 dev->rdsstat = 1;
33849 diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
33850 index 61287fc..8b08712 100644
33851 --- a/drivers/media/rc/redrat3.c
33852 +++ b/drivers/media/rc/redrat3.c
33853 @@ -905,7 +905,7 @@ static int redrat3_set_tx_carrier(struct rc_dev *dev, u32 carrier)
33854 return carrier;
33855 }
33856
33857 -static int redrat3_transmit_ir(struct rc_dev *rcdev, int *txbuf, u32 n)
33858 +static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, u32 n)
33859 {
33860 struct redrat3_dev *rr3 = rcdev->priv;
33861 struct device *dev = rr3->dev;
33862 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33863 index 9cde353..8c6a1c3 100644
33864 --- a/drivers/media/video/au0828/au0828.h
33865 +++ b/drivers/media/video/au0828/au0828.h
33866 @@ -191,7 +191,7 @@ struct au0828_dev {
33867
33868 /* I2C */
33869 struct i2c_adapter i2c_adap;
33870 - struct i2c_algorithm i2c_algo;
33871 + i2c_algorithm_no_const i2c_algo;
33872 struct i2c_client i2c_client;
33873 u32 i2c_rc;
33874
33875 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33876 index 68d1240..46b32eb 100644
33877 --- a/drivers/media/video/cx88/cx88-alsa.c
33878 +++ b/drivers/media/video/cx88/cx88-alsa.c
33879 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33880 * Only boards with eeprom and byte 1 at eeprom=1 have it
33881 */
33882
33883 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33884 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33885 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33886 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33887 {0, }
33888 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33889 index ee0d0b3..63f6b78 100644
33890 --- a/drivers/media/video/omap/omap_vout.c
33891 +++ b/drivers/media/video/omap/omap_vout.c
33892 @@ -64,7 +64,6 @@ enum omap_vout_channels {
33893 OMAP_VIDEO2,
33894 };
33895
33896 -static struct videobuf_queue_ops video_vbq_ops;
33897 /* Variables configurable through module params*/
33898 static u32 video1_numbuffers = 3;
33899 static u32 video2_numbuffers = 3;
33900 @@ -999,6 +998,12 @@ static int omap_vout_open(struct file *file)
33901 {
33902 struct videobuf_queue *q;
33903 struct omap_vout_device *vout = NULL;
33904 + static struct videobuf_queue_ops video_vbq_ops = {
33905 + .buf_setup = omap_vout_buffer_setup,
33906 + .buf_prepare = omap_vout_buffer_prepare,
33907 + .buf_release = omap_vout_buffer_release,
33908 + .buf_queue = omap_vout_buffer_queue,
33909 + };
33910
33911 vout = video_drvdata(file);
33912 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33913 @@ -1016,10 +1021,6 @@ static int omap_vout_open(struct file *file)
33914 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33915
33916 q = &vout->vbq;
33917 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33918 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33919 - video_vbq_ops.buf_release = omap_vout_buffer_release;
33920 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33921 spin_lock_init(&vout->vbq_lock);
33922
33923 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33924 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33925 index 305e6aa..0143317 100644
33926 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33927 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33928 @@ -196,7 +196,7 @@ struct pvr2_hdw {
33929
33930 /* I2C stuff */
33931 struct i2c_adapter i2c_adap;
33932 - struct i2c_algorithm i2c_algo;
33933 + i2c_algorithm_no_const i2c_algo;
33934 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33935 int i2c_cx25840_hack_state;
33936 int i2c_linked;
33937 diff --git a/drivers/media/video/saa7164/saa7164-encoder.c b/drivers/media/video/saa7164/saa7164-encoder.c
33938 index 2fd38a0..ddec3c4 100644
33939 --- a/drivers/media/video/saa7164/saa7164-encoder.c
33940 +++ b/drivers/media/video/saa7164/saa7164-encoder.c
33941 @@ -1136,6 +1136,8 @@ struct saa7164_user_buffer *saa7164_enc_next_buf(struct saa7164_port *port)
33942 }
33943
33944 static ssize_t fops_read(struct file *file, char __user *buffer,
33945 + size_t count, loff_t *pos) __size_overflow(3);
33946 +static ssize_t fops_read(struct file *file, char __user *buffer,
33947 size_t count, loff_t *pos)
33948 {
33949 struct saa7164_encoder_fh *fh = file->private_data;
33950 diff --git a/drivers/media/video/saa7164/saa7164-vbi.c b/drivers/media/video/saa7164/saa7164-vbi.c
33951 index e2e0341..b80056c 100644
33952 --- a/drivers/media/video/saa7164/saa7164-vbi.c
33953 +++ b/drivers/media/video/saa7164/saa7164-vbi.c
33954 @@ -1081,6 +1081,8 @@ struct saa7164_user_buffer *saa7164_vbi_next_buf(struct saa7164_port *port)
33955 }
33956
33957 static ssize_t fops_read(struct file *file, char __user *buffer,
33958 + size_t count, loff_t *pos) __size_overflow(3);
33959 +static ssize_t fops_read(struct file *file, char __user *buffer,
33960 size_t count, loff_t *pos)
33961 {
33962 struct saa7164_vbi_fh *fh = file->private_data;
33963 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33964 index a0895bf..b7ebb1b 100644
33965 --- a/drivers/media/video/timblogiw.c
33966 +++ b/drivers/media/video/timblogiw.c
33967 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33968
33969 /* Platform device functions */
33970
33971 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33972 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33973 .vidioc_querycap = timblogiw_querycap,
33974 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33975 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33976 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33977 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33978 };
33979
33980 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33981 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33982 .owner = THIS_MODULE,
33983 .open = timblogiw_open,
33984 .release = timblogiw_close,
33985 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33986 index e9c6a60..daf6a33 100644
33987 --- a/drivers/message/fusion/mptbase.c
33988 +++ b/drivers/message/fusion/mptbase.c
33989 @@ -6753,8 +6753,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33990 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33991 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33992
33993 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33994 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33995 +#else
33996 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33997 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33998 +#endif
33999 +
34000 /*
34001 * Rounding UP to nearest 4-kB boundary here...
34002 */
34003 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34004 index 9d95042..b808101 100644
34005 --- a/drivers/message/fusion/mptsas.c
34006 +++ b/drivers/message/fusion/mptsas.c
34007 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34008 return 0;
34009 }
34010
34011 +static inline void
34012 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34013 +{
34014 + if (phy_info->port_details) {
34015 + phy_info->port_details->rphy = rphy;
34016 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34017 + ioc->name, rphy));
34018 + }
34019 +
34020 + if (rphy) {
34021 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34022 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34023 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34024 + ioc->name, rphy, rphy->dev.release));
34025 + }
34026 +}
34027 +
34028 /* no mutex */
34029 static void
34030 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34031 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34032 return NULL;
34033 }
34034
34035 -static inline void
34036 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34037 -{
34038 - if (phy_info->port_details) {
34039 - phy_info->port_details->rphy = rphy;
34040 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34041 - ioc->name, rphy));
34042 - }
34043 -
34044 - if (rphy) {
34045 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34046 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34047 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34048 - ioc->name, rphy, rphy->dev.release));
34049 - }
34050 -}
34051 -
34052 static inline struct sas_port *
34053 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34054 {
34055 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34056 index 0c3ced7..1fe34ec 100644
34057 --- a/drivers/message/fusion/mptscsih.c
34058 +++ b/drivers/message/fusion/mptscsih.c
34059 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34060
34061 h = shost_priv(SChost);
34062
34063 - if (h) {
34064 - if (h->info_kbuf == NULL)
34065 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34066 - return h->info_kbuf;
34067 - h->info_kbuf[0] = '\0';
34068 + if (!h)
34069 + return NULL;
34070
34071 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34072 - h->info_kbuf[size-1] = '\0';
34073 - }
34074 + if (h->info_kbuf == NULL)
34075 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34076 + return h->info_kbuf;
34077 + h->info_kbuf[0] = '\0';
34078 +
34079 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34080 + h->info_kbuf[size-1] = '\0';
34081
34082 return h->info_kbuf;
34083 }
34084 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34085 index 07dbeaf..5533142 100644
34086 --- a/drivers/message/i2o/i2o_proc.c
34087 +++ b/drivers/message/i2o/i2o_proc.c
34088 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
34089 "Array Controller Device"
34090 };
34091
34092 -static char *chtostr(u8 * chars, int n)
34093 -{
34094 - char tmp[256];
34095 - tmp[0] = 0;
34096 - return strncat(tmp, (char *)chars, n);
34097 -}
34098 -
34099 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34100 char *group)
34101 {
34102 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34103
34104 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34105 seq_printf(seq, "%-#8x", ddm_table.module_id);
34106 - seq_printf(seq, "%-29s",
34107 - chtostr(ddm_table.module_name_version, 28));
34108 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34109 seq_printf(seq, "%9d ", ddm_table.data_size);
34110 seq_printf(seq, "%8d", ddm_table.code_size);
34111
34112 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34113
34114 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34115 seq_printf(seq, "%-#8x", dst->module_id);
34116 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
34117 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
34118 + seq_printf(seq, "%-.28s", dst->module_name_version);
34119 + seq_printf(seq, "%-.8s", dst->date);
34120 seq_printf(seq, "%8d ", dst->module_size);
34121 seq_printf(seq, "%8d ", dst->mpb_size);
34122 seq_printf(seq, "0x%04x", dst->module_flags);
34123 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34124 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34125 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34126 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34127 - seq_printf(seq, "Vendor info : %s\n",
34128 - chtostr((u8 *) (work32 + 2), 16));
34129 - seq_printf(seq, "Product info : %s\n",
34130 - chtostr((u8 *) (work32 + 6), 16));
34131 - seq_printf(seq, "Description : %s\n",
34132 - chtostr((u8 *) (work32 + 10), 16));
34133 - seq_printf(seq, "Product rev. : %s\n",
34134 - chtostr((u8 *) (work32 + 14), 8));
34135 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34136 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34137 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34138 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34139
34140 seq_printf(seq, "Serial number : ");
34141 print_serial_number(seq, (u8 *) (work32 + 16),
34142 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34143 }
34144
34145 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34146 - seq_printf(seq, "Module name : %s\n",
34147 - chtostr(result.module_name, 24));
34148 - seq_printf(seq, "Module revision : %s\n",
34149 - chtostr(result.module_rev, 8));
34150 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34151 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34152
34153 seq_printf(seq, "Serial number : ");
34154 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34155 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34156 return 0;
34157 }
34158
34159 - seq_printf(seq, "Device name : %s\n",
34160 - chtostr(result.device_name, 64));
34161 - seq_printf(seq, "Service name : %s\n",
34162 - chtostr(result.service_name, 64));
34163 - seq_printf(seq, "Physical name : %s\n",
34164 - chtostr(result.physical_location, 64));
34165 - seq_printf(seq, "Instance number : %s\n",
34166 - chtostr(result.instance_number, 4));
34167 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34168 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34169 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34170 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34171
34172 return 0;
34173 }
34174 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34175 index a8c08f3..155fe3d 100644
34176 --- a/drivers/message/i2o/iop.c
34177 +++ b/drivers/message/i2o/iop.c
34178 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34179
34180 spin_lock_irqsave(&c->context_list_lock, flags);
34181
34182 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34183 - atomic_inc(&c->context_list_counter);
34184 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34185 + atomic_inc_unchecked(&c->context_list_counter);
34186
34187 - entry->context = atomic_read(&c->context_list_counter);
34188 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34189
34190 list_add(&entry->list, &c->context_list);
34191
34192 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34193
34194 #if BITS_PER_LONG == 64
34195 spin_lock_init(&c->context_list_lock);
34196 - atomic_set(&c->context_list_counter, 0);
34197 + atomic_set_unchecked(&c->context_list_counter, 0);
34198 INIT_LIST_HEAD(&c->context_list);
34199 #endif
34200
34201 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34202 index 7ce65f4..e66e9bc 100644
34203 --- a/drivers/mfd/abx500-core.c
34204 +++ b/drivers/mfd/abx500-core.c
34205 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34206
34207 struct abx500_device_entry {
34208 struct list_head list;
34209 - struct abx500_ops ops;
34210 + abx500_ops_no_const ops;
34211 struct device *dev;
34212 };
34213
34214 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34215 index 5c2a06a..8fa077c 100644
34216 --- a/drivers/mfd/janz-cmodio.c
34217 +++ b/drivers/mfd/janz-cmodio.c
34218 @@ -13,6 +13,7 @@
34219
34220 #include <linux/kernel.h>
34221 #include <linux/module.h>
34222 +#include <linux/slab.h>
34223 #include <linux/init.h>
34224 #include <linux/pci.h>
34225 #include <linux/interrupt.h>
34226 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34227 index 29d12a7..f900ba4 100644
34228 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34229 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34230 @@ -464,7 +464,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34231 * the lid is closed. This leads to interrupts as soon as a little move
34232 * is done.
34233 */
34234 - atomic_inc(&lis3->count);
34235 + atomic_inc_unchecked(&lis3->count);
34236
34237 wake_up_interruptible(&lis3->misc_wait);
34238 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34239 @@ -550,7 +550,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34240 if (lis3->pm_dev)
34241 pm_runtime_get_sync(lis3->pm_dev);
34242
34243 - atomic_set(&lis3->count, 0);
34244 + atomic_set_unchecked(&lis3->count, 0);
34245 return 0;
34246 }
34247
34248 @@ -583,7 +583,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34249 add_wait_queue(&lis3->misc_wait, &wait);
34250 while (true) {
34251 set_current_state(TASK_INTERRUPTIBLE);
34252 - data = atomic_xchg(&lis3->count, 0);
34253 + data = atomic_xchg_unchecked(&lis3->count, 0);
34254 if (data)
34255 break;
34256
34257 @@ -624,7 +624,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34258 struct lis3lv02d, miscdev);
34259
34260 poll_wait(file, &lis3->misc_wait, wait);
34261 - if (atomic_read(&lis3->count))
34262 + if (atomic_read_unchecked(&lis3->count))
34263 return POLLIN | POLLRDNORM;
34264 return 0;
34265 }
34266 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34267 index 2b1482a..5d33616 100644
34268 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34269 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34270 @@ -266,7 +266,7 @@ struct lis3lv02d {
34271 struct input_polled_dev *idev; /* input device */
34272 struct platform_device *pdev; /* platform device */
34273 struct regulator_bulk_data regulators[2];
34274 - atomic_t count; /* interrupt count after last read */
34275 + atomic_unchecked_t count; /* interrupt count after last read */
34276 union axis_conversion ac; /* hw -> logical axis */
34277 int mapped_btns[3];
34278
34279 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34280 index 2f30bad..c4c13d0 100644
34281 --- a/drivers/misc/sgi-gru/gruhandles.c
34282 +++ b/drivers/misc/sgi-gru/gruhandles.c
34283 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34284 unsigned long nsec;
34285
34286 nsec = CLKS2NSEC(clks);
34287 - atomic_long_inc(&mcs_op_statistics[op].count);
34288 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34289 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34290 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34291 if (mcs_op_statistics[op].max < nsec)
34292 mcs_op_statistics[op].max = nsec;
34293 }
34294 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34295 index 7768b87..f8aac38 100644
34296 --- a/drivers/misc/sgi-gru/gruprocfs.c
34297 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34298 @@ -32,9 +32,9 @@
34299
34300 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34301
34302 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34303 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34304 {
34305 - unsigned long val = atomic_long_read(v);
34306 + unsigned long val = atomic_long_read_unchecked(v);
34307
34308 seq_printf(s, "%16lu %s\n", val, id);
34309 }
34310 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34311
34312 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34313 for (op = 0; op < mcsop_last; op++) {
34314 - count = atomic_long_read(&mcs_op_statistics[op].count);
34315 - total = atomic_long_read(&mcs_op_statistics[op].total);
34316 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34317 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34318 max = mcs_op_statistics[op].max;
34319 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34320 count ? total / count : 0, max);
34321 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34322 index 5c3ce24..4915ccb 100644
34323 --- a/drivers/misc/sgi-gru/grutables.h
34324 +++ b/drivers/misc/sgi-gru/grutables.h
34325 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34326 * GRU statistics.
34327 */
34328 struct gru_stats_s {
34329 - atomic_long_t vdata_alloc;
34330 - atomic_long_t vdata_free;
34331 - atomic_long_t gts_alloc;
34332 - atomic_long_t gts_free;
34333 - atomic_long_t gms_alloc;
34334 - atomic_long_t gms_free;
34335 - atomic_long_t gts_double_allocate;
34336 - atomic_long_t assign_context;
34337 - atomic_long_t assign_context_failed;
34338 - atomic_long_t free_context;
34339 - atomic_long_t load_user_context;
34340 - atomic_long_t load_kernel_context;
34341 - atomic_long_t lock_kernel_context;
34342 - atomic_long_t unlock_kernel_context;
34343 - atomic_long_t steal_user_context;
34344 - atomic_long_t steal_kernel_context;
34345 - atomic_long_t steal_context_failed;
34346 - atomic_long_t nopfn;
34347 - atomic_long_t asid_new;
34348 - atomic_long_t asid_next;
34349 - atomic_long_t asid_wrap;
34350 - atomic_long_t asid_reuse;
34351 - atomic_long_t intr;
34352 - atomic_long_t intr_cbr;
34353 - atomic_long_t intr_tfh;
34354 - atomic_long_t intr_spurious;
34355 - atomic_long_t intr_mm_lock_failed;
34356 - atomic_long_t call_os;
34357 - atomic_long_t call_os_wait_queue;
34358 - atomic_long_t user_flush_tlb;
34359 - atomic_long_t user_unload_context;
34360 - atomic_long_t user_exception;
34361 - atomic_long_t set_context_option;
34362 - atomic_long_t check_context_retarget_intr;
34363 - atomic_long_t check_context_unload;
34364 - atomic_long_t tlb_dropin;
34365 - atomic_long_t tlb_preload_page;
34366 - atomic_long_t tlb_dropin_fail_no_asid;
34367 - atomic_long_t tlb_dropin_fail_upm;
34368 - atomic_long_t tlb_dropin_fail_invalid;
34369 - atomic_long_t tlb_dropin_fail_range_active;
34370 - atomic_long_t tlb_dropin_fail_idle;
34371 - atomic_long_t tlb_dropin_fail_fmm;
34372 - atomic_long_t tlb_dropin_fail_no_exception;
34373 - atomic_long_t tfh_stale_on_fault;
34374 - atomic_long_t mmu_invalidate_range;
34375 - atomic_long_t mmu_invalidate_page;
34376 - atomic_long_t flush_tlb;
34377 - atomic_long_t flush_tlb_gru;
34378 - atomic_long_t flush_tlb_gru_tgh;
34379 - atomic_long_t flush_tlb_gru_zero_asid;
34380 + atomic_long_unchecked_t vdata_alloc;
34381 + atomic_long_unchecked_t vdata_free;
34382 + atomic_long_unchecked_t gts_alloc;
34383 + atomic_long_unchecked_t gts_free;
34384 + atomic_long_unchecked_t gms_alloc;
34385 + atomic_long_unchecked_t gms_free;
34386 + atomic_long_unchecked_t gts_double_allocate;
34387 + atomic_long_unchecked_t assign_context;
34388 + atomic_long_unchecked_t assign_context_failed;
34389 + atomic_long_unchecked_t free_context;
34390 + atomic_long_unchecked_t load_user_context;
34391 + atomic_long_unchecked_t load_kernel_context;
34392 + atomic_long_unchecked_t lock_kernel_context;
34393 + atomic_long_unchecked_t unlock_kernel_context;
34394 + atomic_long_unchecked_t steal_user_context;
34395 + atomic_long_unchecked_t steal_kernel_context;
34396 + atomic_long_unchecked_t steal_context_failed;
34397 + atomic_long_unchecked_t nopfn;
34398 + atomic_long_unchecked_t asid_new;
34399 + atomic_long_unchecked_t asid_next;
34400 + atomic_long_unchecked_t asid_wrap;
34401 + atomic_long_unchecked_t asid_reuse;
34402 + atomic_long_unchecked_t intr;
34403 + atomic_long_unchecked_t intr_cbr;
34404 + atomic_long_unchecked_t intr_tfh;
34405 + atomic_long_unchecked_t intr_spurious;
34406 + atomic_long_unchecked_t intr_mm_lock_failed;
34407 + atomic_long_unchecked_t call_os;
34408 + atomic_long_unchecked_t call_os_wait_queue;
34409 + atomic_long_unchecked_t user_flush_tlb;
34410 + atomic_long_unchecked_t user_unload_context;
34411 + atomic_long_unchecked_t user_exception;
34412 + atomic_long_unchecked_t set_context_option;
34413 + atomic_long_unchecked_t check_context_retarget_intr;
34414 + atomic_long_unchecked_t check_context_unload;
34415 + atomic_long_unchecked_t tlb_dropin;
34416 + atomic_long_unchecked_t tlb_preload_page;
34417 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34418 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34419 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34420 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34421 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34422 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34423 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34424 + atomic_long_unchecked_t tfh_stale_on_fault;
34425 + atomic_long_unchecked_t mmu_invalidate_range;
34426 + atomic_long_unchecked_t mmu_invalidate_page;
34427 + atomic_long_unchecked_t flush_tlb;
34428 + atomic_long_unchecked_t flush_tlb_gru;
34429 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34430 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34431
34432 - atomic_long_t copy_gpa;
34433 - atomic_long_t read_gpa;
34434 + atomic_long_unchecked_t copy_gpa;
34435 + atomic_long_unchecked_t read_gpa;
34436
34437 - atomic_long_t mesq_receive;
34438 - atomic_long_t mesq_receive_none;
34439 - atomic_long_t mesq_send;
34440 - atomic_long_t mesq_send_failed;
34441 - atomic_long_t mesq_noop;
34442 - atomic_long_t mesq_send_unexpected_error;
34443 - atomic_long_t mesq_send_lb_overflow;
34444 - atomic_long_t mesq_send_qlimit_reached;
34445 - atomic_long_t mesq_send_amo_nacked;
34446 - atomic_long_t mesq_send_put_nacked;
34447 - atomic_long_t mesq_page_overflow;
34448 - atomic_long_t mesq_qf_locked;
34449 - atomic_long_t mesq_qf_noop_not_full;
34450 - atomic_long_t mesq_qf_switch_head_failed;
34451 - atomic_long_t mesq_qf_unexpected_error;
34452 - atomic_long_t mesq_noop_unexpected_error;
34453 - atomic_long_t mesq_noop_lb_overflow;
34454 - atomic_long_t mesq_noop_qlimit_reached;
34455 - atomic_long_t mesq_noop_amo_nacked;
34456 - atomic_long_t mesq_noop_put_nacked;
34457 - atomic_long_t mesq_noop_page_overflow;
34458 + atomic_long_unchecked_t mesq_receive;
34459 + atomic_long_unchecked_t mesq_receive_none;
34460 + atomic_long_unchecked_t mesq_send;
34461 + atomic_long_unchecked_t mesq_send_failed;
34462 + atomic_long_unchecked_t mesq_noop;
34463 + atomic_long_unchecked_t mesq_send_unexpected_error;
34464 + atomic_long_unchecked_t mesq_send_lb_overflow;
34465 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34466 + atomic_long_unchecked_t mesq_send_amo_nacked;
34467 + atomic_long_unchecked_t mesq_send_put_nacked;
34468 + atomic_long_unchecked_t mesq_page_overflow;
34469 + atomic_long_unchecked_t mesq_qf_locked;
34470 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34471 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34472 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34473 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34474 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34475 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34476 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34477 + atomic_long_unchecked_t mesq_noop_put_nacked;
34478 + atomic_long_unchecked_t mesq_noop_page_overflow;
34479
34480 };
34481
34482 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34483 tghop_invalidate, mcsop_last};
34484
34485 struct mcs_op_statistic {
34486 - atomic_long_t count;
34487 - atomic_long_t total;
34488 + atomic_long_unchecked_t count;
34489 + atomic_long_unchecked_t total;
34490 unsigned long max;
34491 };
34492
34493 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34494
34495 #define STAT(id) do { \
34496 if (gru_options & OPT_STATS) \
34497 - atomic_long_inc(&gru_stats.id); \
34498 + atomic_long_inc_unchecked(&gru_stats.id); \
34499 } while (0)
34500
34501 #ifdef CONFIG_SGI_GRU_DEBUG
34502 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34503 index 851b2f2..a4ec097 100644
34504 --- a/drivers/misc/sgi-xp/xp.h
34505 +++ b/drivers/misc/sgi-xp/xp.h
34506 @@ -289,7 +289,7 @@ struct xpc_interface {
34507 xpc_notify_func, void *);
34508 void (*received) (short, int, void *);
34509 enum xp_retval (*partid_to_nasids) (short, void *);
34510 -};
34511 +} __no_const;
34512
34513 extern struct xpc_interface xpc_interface;
34514
34515 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34516 index b94d5f7..7f494c5 100644
34517 --- a/drivers/misc/sgi-xp/xpc.h
34518 +++ b/drivers/misc/sgi-xp/xpc.h
34519 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34520 void (*received_payload) (struct xpc_channel *, void *);
34521 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34522 };
34523 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34524
34525 /* struct xpc_partition act_state values (for XPC HB) */
34526
34527 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34528 /* found in xpc_main.c */
34529 extern struct device *xpc_part;
34530 extern struct device *xpc_chan;
34531 -extern struct xpc_arch_operations xpc_arch_ops;
34532 +extern xpc_arch_operations_no_const xpc_arch_ops;
34533 extern int xpc_disengage_timelimit;
34534 extern int xpc_disengage_timedout;
34535 extern int xpc_activate_IRQ_rcvd;
34536 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34537 index 8d082b4..aa749ae 100644
34538 --- a/drivers/misc/sgi-xp/xpc_main.c
34539 +++ b/drivers/misc/sgi-xp/xpc_main.c
34540 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34541 .notifier_call = xpc_system_die,
34542 };
34543
34544 -struct xpc_arch_operations xpc_arch_ops;
34545 +xpc_arch_operations_no_const xpc_arch_ops;
34546
34547 /*
34548 * Timer function to enforce the timelimit on the partition disengage.
34549 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34550 index 6878a94..fe5c5f1 100644
34551 --- a/drivers/mmc/host/sdhci-pci.c
34552 +++ b/drivers/mmc/host/sdhci-pci.c
34553 @@ -673,7 +673,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34554 .probe = via_probe,
34555 };
34556
34557 -static const struct pci_device_id pci_ids[] __devinitdata = {
34558 +static const struct pci_device_id pci_ids[] __devinitconst = {
34559 {
34560 .vendor = PCI_VENDOR_ID_RICOH,
34561 .device = PCI_DEVICE_ID_RICOH_R5C822,
34562 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34563 index e9fad91..0a7a16a 100644
34564 --- a/drivers/mtd/devices/doc2000.c
34565 +++ b/drivers/mtd/devices/doc2000.c
34566 @@ -773,7 +773,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34567
34568 /* The ECC will not be calculated correctly if less than 512 is written */
34569 /* DBB-
34570 - if (len != 0x200 && eccbuf)
34571 + if (len != 0x200)
34572 printk(KERN_WARNING
34573 "ECC needs a full sector write (adr: %lx size %lx)\n",
34574 (long) to, (long) len);
34575 diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
34576 index a3f7a27..234016e 100644
34577 --- a/drivers/mtd/devices/doc2001.c
34578 +++ b/drivers/mtd/devices/doc2001.c
34579 @@ -392,7 +392,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
34580 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
34581
34582 /* Don't allow read past end of device */
34583 - if (from >= this->totlen)
34584 + if (from >= this->totlen || !len)
34585 return -EINVAL;
34586
34587 /* Don't allow a single read to cross a 512-byte block boundary */
34588 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34589 index 3984d48..28aa897 100644
34590 --- a/drivers/mtd/nand/denali.c
34591 +++ b/drivers/mtd/nand/denali.c
34592 @@ -26,6 +26,7 @@
34593 #include <linux/pci.h>
34594 #include <linux/mtd/mtd.h>
34595 #include <linux/module.h>
34596 +#include <linux/slab.h>
34597
34598 #include "denali.h"
34599
34600 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34601 index ac40925..483b753 100644
34602 --- a/drivers/mtd/nftlmount.c
34603 +++ b/drivers/mtd/nftlmount.c
34604 @@ -24,6 +24,7 @@
34605 #include <asm/errno.h>
34606 #include <linux/delay.h>
34607 #include <linux/slab.h>
34608 +#include <linux/sched.h>
34609 #include <linux/mtd/mtd.h>
34610 #include <linux/mtd/nand.h>
34611 #include <linux/mtd/nftl.h>
34612 diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
34613 index 6c3fb5a..5b2eeb0 100644
34614 --- a/drivers/mtd/ubi/build.c
34615 +++ b/drivers/mtd/ubi/build.c
34616 @@ -1311,7 +1311,7 @@ module_exit(ubi_exit);
34617 static int __init bytes_str_to_int(const char *str)
34618 {
34619 char *endp;
34620 - unsigned long result;
34621 + unsigned long result, scale = 1;
34622
34623 result = simple_strtoul(str, &endp, 0);
34624 if (str == endp || result >= INT_MAX) {
34625 @@ -1322,11 +1322,11 @@ static int __init bytes_str_to_int(const char *str)
34626
34627 switch (*endp) {
34628 case 'G':
34629 - result *= 1024;
34630 + scale *= 1024;
34631 case 'M':
34632 - result *= 1024;
34633 + scale *= 1024;
34634 case 'K':
34635 - result *= 1024;
34636 + scale *= 1024;
34637 if (endp[1] == 'i' && endp[2] == 'B')
34638 endp += 2;
34639 case '\0':
34640 @@ -1337,7 +1337,13 @@ static int __init bytes_str_to_int(const char *str)
34641 return -EINVAL;
34642 }
34643
34644 - return result;
34645 + if (result*scale >= INT_MAX) {
34646 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
34647 + str);
34648 + return -EINVAL;
34649 + }
34650 +
34651 + return result*scale;
34652 }
34653
34654 /**
34655 diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c
34656 index ab80c0d..aec8580 100644
34657 --- a/drivers/mtd/ubi/debug.c
34658 +++ b/drivers/mtd/ubi/debug.c
34659 @@ -338,6 +338,8 @@ out:
34660
34661 /* Write an UBI debugfs file */
34662 static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
34663 + size_t count, loff_t *ppos) __size_overflow(3);
34664 +static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
34665 size_t count, loff_t *ppos)
34666 {
34667 unsigned long ubi_num = (unsigned long)file->private_data;
34668 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34669 index 1feae59..c2a61d2 100644
34670 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34671 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34672 @@ -2857,7 +2857,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34673 */
34674
34675 #define ATL2_PARAM(X, desc) \
34676 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34677 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34678 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34679 MODULE_PARM_DESC(X, desc);
34680 #else
34681 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34682 index 9a517c2..a50cfcb 100644
34683 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34684 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34685 @@ -449,7 +449,7 @@ struct bnx2x_rx_mode_obj {
34686
34687 int (*wait_comp)(struct bnx2x *bp,
34688 struct bnx2x_rx_mode_ramrod_params *p);
34689 -};
34690 +} __no_const;
34691
34692 /********************** Set multicast group ***********************************/
34693
34694 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34695 index 94b4bd0..73c02de 100644
34696 --- a/drivers/net/ethernet/broadcom/tg3.h
34697 +++ b/drivers/net/ethernet/broadcom/tg3.h
34698 @@ -134,6 +134,7 @@
34699 #define CHIPREV_ID_5750_A0 0x4000
34700 #define CHIPREV_ID_5750_A1 0x4001
34701 #define CHIPREV_ID_5750_A3 0x4003
34702 +#define CHIPREV_ID_5750_C1 0x4201
34703 #define CHIPREV_ID_5750_C2 0x4202
34704 #define CHIPREV_ID_5752_A0_HW 0x5000
34705 #define CHIPREV_ID_5752_A0 0x6000
34706 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34707 index c5f5479..2e8c260 100644
34708 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34709 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34710 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34711 */
34712 struct l2t_skb_cb {
34713 arp_failure_handler_func arp_failure_handler;
34714 -};
34715 +} __no_const;
34716
34717 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34718
34719 diff --git a/drivers/net/ethernet/chelsio/cxgb3/sge.c b/drivers/net/ethernet/chelsio/cxgb3/sge.c
34720 index cfb60e1..9c76da7 100644
34721 --- a/drivers/net/ethernet/chelsio/cxgb3/sge.c
34722 +++ b/drivers/net/ethernet/chelsio/cxgb3/sge.c
34723 @@ -611,6 +611,8 @@ static void recycle_rx_buf(struct adapter *adap, struct sge_fl *q,
34724 * of the SW ring.
34725 */
34726 static void *alloc_ring(struct pci_dev *pdev, size_t nelem, size_t elem_size,
34727 + size_t sw_size, dma_addr_t * phys, void *metadata) __size_overflow(2,4);
34728 +static void *alloc_ring(struct pci_dev *pdev, size_t nelem, size_t elem_size,
34729 size_t sw_size, dma_addr_t * phys, void *metadata)
34730 {
34731 size_t len = nelem * elem_size;
34732 diff --git a/drivers/net/ethernet/chelsio/cxgb4/sge.c b/drivers/net/ethernet/chelsio/cxgb4/sge.c
34733 index 140254c..5b8a0a6 100644
34734 --- a/drivers/net/ethernet/chelsio/cxgb4/sge.c
34735 +++ b/drivers/net/ethernet/chelsio/cxgb4/sge.c
34736 @@ -593,6 +593,9 @@ static inline void __refill_fl(struct adapter *adap, struct sge_fl *fl)
34737 */
34738 static void *alloc_ring(struct device *dev, size_t nelem, size_t elem_size,
34739 size_t sw_size, dma_addr_t *phys, void *metadata,
34740 + size_t stat_size, int node) __size_overflow(2,4);
34741 +static void *alloc_ring(struct device *dev, size_t nelem, size_t elem_size,
34742 + size_t sw_size, dma_addr_t *phys, void *metadata,
34743 size_t stat_size, int node)
34744 {
34745 size_t len = nelem * elem_size + stat_size;
34746 diff --git a/drivers/net/ethernet/chelsio/cxgb4vf/sge.c b/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
34747 index 8d5d55a..a3c3474 100644
34748 --- a/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
34749 +++ b/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
34750 @@ -730,6 +730,9 @@ static inline void __refill_fl(struct adapter *adapter, struct sge_fl *fl)
34751 */
34752 static void *alloc_ring(struct device *dev, size_t nelem, size_t hwsize,
34753 size_t swsize, dma_addr_t *busaddrp, void *swringp,
34754 + size_t stat_size) __size_overflow(2,4);
34755 +static void *alloc_ring(struct device *dev, size_t nelem, size_t hwsize,
34756 + size_t swsize, dma_addr_t *busaddrp, void *swringp,
34757 size_t stat_size)
34758 {
34759 /*
34760 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34761 index 871bcaa..4043505 100644
34762 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34763 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34764 @@ -5397,7 +5397,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34765 for (i=0; i<ETH_ALEN; i++) {
34766 tmp.addr[i] = dev->dev_addr[i];
34767 }
34768 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34769 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34770 break;
34771
34772 case DE4X5_SET_HWADDR: /* Set the hardware address */
34773 @@ -5437,7 +5437,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34774 spin_lock_irqsave(&lp->lock, flags);
34775 memcpy(&statbuf, &lp->pktStats, ioc->len);
34776 spin_unlock_irqrestore(&lp->lock, flags);
34777 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34778 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34779 return -EFAULT;
34780 break;
34781 }
34782 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34783 index 14d5b61..1398636 100644
34784 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34785 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34786 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34787 {NULL}};
34788
34789
34790 -static const char *block_name[] __devinitdata = {
34791 +static const char *block_name[] __devinitconst = {
34792 "21140 non-MII",
34793 "21140 MII PHY",
34794 "21142 Serial PHY",
34795 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34796 index 4d01219..b58d26d 100644
34797 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34798 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34799 @@ -236,7 +236,7 @@ struct pci_id_info {
34800 int drv_flags; /* Driver use, intended as capability flags. */
34801 };
34802
34803 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34804 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34805 { /* Sometime a Level-One switch card. */
34806 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34807 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34808 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34809 index dcd7f7a..ecb7fb3 100644
34810 --- a/drivers/net/ethernet/dlink/sundance.c
34811 +++ b/drivers/net/ethernet/dlink/sundance.c
34812 @@ -218,7 +218,7 @@ enum {
34813 struct pci_id_info {
34814 const char *name;
34815 };
34816 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34817 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34818 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34819 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34820 {"D-Link DFE-580TX 4 port Server Adapter"},
34821 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34822 index bf266a0..e024af7 100644
34823 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34824 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34825 @@ -397,7 +397,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34826
34827 if (wrapped)
34828 newacc += 65536;
34829 - ACCESS_ONCE(*acc) = newacc;
34830 + ACCESS_ONCE_RW(*acc) = newacc;
34831 }
34832
34833 void be_parse_stats(struct be_adapter *adapter)
34834 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34835 index fb5579a..debdffa 100644
34836 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34837 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34838 @@ -30,6 +30,8 @@
34839 #include <linux/netdevice.h>
34840 #include <linux/phy.h>
34841 #include <linux/platform_device.h>
34842 +#include <linux/interrupt.h>
34843 +#include <linux/irqreturn.h>
34844 #include <net/ip.h>
34845
34846 #include "ftgmac100.h"
34847 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34848 index a127cb2..0d043cd 100644
34849 --- a/drivers/net/ethernet/faraday/ftmac100.c
34850 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34851 @@ -30,6 +30,8 @@
34852 #include <linux/module.h>
34853 #include <linux/netdevice.h>
34854 #include <linux/platform_device.h>
34855 +#include <linux/interrupt.h>
34856 +#include <linux/irqreturn.h>
34857
34858 #include "ftmac100.h"
34859
34860 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34861 index 61d2bdd..7f1154a 100644
34862 --- a/drivers/net/ethernet/fealnx.c
34863 +++ b/drivers/net/ethernet/fealnx.c
34864 @@ -150,7 +150,7 @@ struct chip_info {
34865 int flags;
34866 };
34867
34868 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34869 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34870 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34871 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34872 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34873 diff --git a/drivers/net/ethernet/intel/e1000e/80003es2lan.c b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34874 index e1159e5..e18684d 100644
34875 --- a/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34876 +++ b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34877 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
34878 {
34879 struct e1000_hw *hw = &adapter->hw;
34880 struct e1000_mac_info *mac = &hw->mac;
34881 - struct e1000_mac_operations *func = &mac->ops;
34882 + e1000_mac_operations_no_const *func = &mac->ops;
34883
34884 /* Set media type */
34885 switch (adapter->pdev->device) {
34886 diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
34887 index a3e65fd..f451444 100644
34888 --- a/drivers/net/ethernet/intel/e1000e/82571.c
34889 +++ b/drivers/net/ethernet/intel/e1000e/82571.c
34890 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
34891 {
34892 struct e1000_hw *hw = &adapter->hw;
34893 struct e1000_mac_info *mac = &hw->mac;
34894 - struct e1000_mac_operations *func = &mac->ops;
34895 + e1000_mac_operations_no_const *func = &mac->ops;
34896 u32 swsm = 0;
34897 u32 swsm2 = 0;
34898 bool force_clear_smbi = false;
34899 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34900 index 2967039..ca8c40c 100644
34901 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34902 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34903 @@ -778,6 +778,7 @@ struct e1000_mac_operations {
34904 void (*write_vfta)(struct e1000_hw *, u32, u32);
34905 s32 (*read_mac_addr)(struct e1000_hw *);
34906 };
34907 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34908
34909 /*
34910 * When to use various PHY register access functions:
34911 @@ -818,6 +819,7 @@ struct e1000_phy_operations {
34912 void (*power_up)(struct e1000_hw *);
34913 void (*power_down)(struct e1000_hw *);
34914 };
34915 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34916
34917 /* Function pointers for the NVM. */
34918 struct e1000_nvm_operations {
34919 @@ -829,9 +831,10 @@ struct e1000_nvm_operations {
34920 s32 (*validate)(struct e1000_hw *);
34921 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34922 };
34923 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34924
34925 struct e1000_mac_info {
34926 - struct e1000_mac_operations ops;
34927 + e1000_mac_operations_no_const ops;
34928 u8 addr[ETH_ALEN];
34929 u8 perm_addr[ETH_ALEN];
34930
34931 @@ -872,7 +875,7 @@ struct e1000_mac_info {
34932 };
34933
34934 struct e1000_phy_info {
34935 - struct e1000_phy_operations ops;
34936 + e1000_phy_operations_no_const ops;
34937
34938 enum e1000_phy_type type;
34939
34940 @@ -906,7 +909,7 @@ struct e1000_phy_info {
34941 };
34942
34943 struct e1000_nvm_info {
34944 - struct e1000_nvm_operations ops;
34945 + e1000_nvm_operations_no_const ops;
34946
34947 enum e1000_nvm_type type;
34948 enum e1000_nvm_override override;
34949 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34950 index 4519a13..f97fcd0 100644
34951 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34952 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34953 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
34954 s32 (*read_mac_addr)(struct e1000_hw *);
34955 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
34956 };
34957 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34958
34959 struct e1000_phy_operations {
34960 s32 (*acquire)(struct e1000_hw *);
34961 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
34962 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34963 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34964 };
34965 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34966
34967 struct e1000_nvm_operations {
34968 s32 (*acquire)(struct e1000_hw *);
34969 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
34970 s32 (*update)(struct e1000_hw *);
34971 s32 (*validate)(struct e1000_hw *);
34972 };
34973 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34974
34975 struct e1000_info {
34976 s32 (*get_invariants)(struct e1000_hw *);
34977 @@ -350,7 +353,7 @@ struct e1000_info {
34978 extern const struct e1000_info e1000_82575_info;
34979
34980 struct e1000_mac_info {
34981 - struct e1000_mac_operations ops;
34982 + e1000_mac_operations_no_const ops;
34983
34984 u8 addr[6];
34985 u8 perm_addr[6];
34986 @@ -388,7 +391,7 @@ struct e1000_mac_info {
34987 };
34988
34989 struct e1000_phy_info {
34990 - struct e1000_phy_operations ops;
34991 + e1000_phy_operations_no_const ops;
34992
34993 enum e1000_phy_type type;
34994
34995 @@ -423,7 +426,7 @@ struct e1000_phy_info {
34996 };
34997
34998 struct e1000_nvm_info {
34999 - struct e1000_nvm_operations ops;
35000 + e1000_nvm_operations_no_const ops;
35001 enum e1000_nvm_type type;
35002 enum e1000_nvm_override override;
35003
35004 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
35005 s32 (*check_for_ack)(struct e1000_hw *, u16);
35006 s32 (*check_for_rst)(struct e1000_hw *, u16);
35007 };
35008 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35009
35010 struct e1000_mbx_stats {
35011 u32 msgs_tx;
35012 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
35013 };
35014
35015 struct e1000_mbx_info {
35016 - struct e1000_mbx_operations ops;
35017 + e1000_mbx_operations_no_const ops;
35018 struct e1000_mbx_stats stats;
35019 u32 timeout;
35020 u32 usec_delay;
35021 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35022 index d7ed58f..64cde36 100644
35023 --- a/drivers/net/ethernet/intel/igbvf/vf.h
35024 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
35025 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
35026 s32 (*read_mac_addr)(struct e1000_hw *);
35027 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35028 };
35029 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35030
35031 struct e1000_mac_info {
35032 - struct e1000_mac_operations ops;
35033 + e1000_mac_operations_no_const ops;
35034 u8 addr[6];
35035 u8 perm_addr[6];
35036
35037 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35038 s32 (*check_for_ack)(struct e1000_hw *);
35039 s32 (*check_for_rst)(struct e1000_hw *);
35040 };
35041 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35042
35043 struct e1000_mbx_stats {
35044 u32 msgs_tx;
35045 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35046 };
35047
35048 struct e1000_mbx_info {
35049 - struct e1000_mbx_operations ops;
35050 + e1000_mbx_operations_no_const ops;
35051 struct e1000_mbx_stats stats;
35052 u32 timeout;
35053 u32 usec_delay;
35054 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35055 index 6c5cca8..de8ef63 100644
35056 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35057 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35058 @@ -2708,6 +2708,7 @@ struct ixgbe_eeprom_operations {
35059 s32 (*update_checksum)(struct ixgbe_hw *);
35060 u16 (*calc_checksum)(struct ixgbe_hw *);
35061 };
35062 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35063
35064 struct ixgbe_mac_operations {
35065 s32 (*init_hw)(struct ixgbe_hw *);
35066 @@ -2769,6 +2770,7 @@ struct ixgbe_mac_operations {
35067 /* Manageability interface */
35068 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
35069 };
35070 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35071
35072 struct ixgbe_phy_operations {
35073 s32 (*identify)(struct ixgbe_hw *);
35074 @@ -2788,9 +2790,10 @@ struct ixgbe_phy_operations {
35075 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35076 s32 (*check_overtemp)(struct ixgbe_hw *);
35077 };
35078 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35079
35080 struct ixgbe_eeprom_info {
35081 - struct ixgbe_eeprom_operations ops;
35082 + ixgbe_eeprom_operations_no_const ops;
35083 enum ixgbe_eeprom_type type;
35084 u32 semaphore_delay;
35085 u16 word_size;
35086 @@ -2800,7 +2803,7 @@ struct ixgbe_eeprom_info {
35087
35088 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35089 struct ixgbe_mac_info {
35090 - struct ixgbe_mac_operations ops;
35091 + ixgbe_mac_operations_no_const ops;
35092 enum ixgbe_mac_type type;
35093 u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
35094 u8 perm_addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
35095 @@ -2828,7 +2831,7 @@ struct ixgbe_mac_info {
35096 };
35097
35098 struct ixgbe_phy_info {
35099 - struct ixgbe_phy_operations ops;
35100 + ixgbe_phy_operations_no_const ops;
35101 struct mdio_if_info mdio;
35102 enum ixgbe_phy_type type;
35103 u32 id;
35104 @@ -2856,6 +2859,7 @@ struct ixgbe_mbx_operations {
35105 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35106 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35107 };
35108 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35109
35110 struct ixgbe_mbx_stats {
35111 u32 msgs_tx;
35112 @@ -2867,7 +2871,7 @@ struct ixgbe_mbx_stats {
35113 };
35114
35115 struct ixgbe_mbx_info {
35116 - struct ixgbe_mbx_operations ops;
35117 + ixgbe_mbx_operations_no_const ops;
35118 struct ixgbe_mbx_stats stats;
35119 u32 timeout;
35120 u32 usec_delay;
35121 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35122 index 10306b4..28df758 100644
35123 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35124 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35125 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35126 s32 (*clear_vfta)(struct ixgbe_hw *);
35127 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35128 };
35129 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35130
35131 enum ixgbe_mac_type {
35132 ixgbe_mac_unknown = 0,
35133 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35134 };
35135
35136 struct ixgbe_mac_info {
35137 - struct ixgbe_mac_operations ops;
35138 + ixgbe_mac_operations_no_const ops;
35139 u8 addr[6];
35140 u8 perm_addr[6];
35141
35142 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35143 s32 (*check_for_ack)(struct ixgbe_hw *);
35144 s32 (*check_for_rst)(struct ixgbe_hw *);
35145 };
35146 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35147
35148 struct ixgbe_mbx_stats {
35149 u32 msgs_tx;
35150 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35151 };
35152
35153 struct ixgbe_mbx_info {
35154 - struct ixgbe_mbx_operations ops;
35155 + ixgbe_mbx_operations_no_const ops;
35156 struct ixgbe_mbx_stats stats;
35157 u32 timeout;
35158 u32 udelay;
35159 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
35160 index 94bbc85..78c12e6 100644
35161 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
35162 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
35163 @@ -40,6 +40,7 @@
35164 #include <linux/dma-mapping.h>
35165 #include <linux/slab.h>
35166 #include <linux/io-mapping.h>
35167 +#include <linux/sched.h>
35168
35169 #include <linux/mlx4/device.h>
35170 #include <linux/mlx4/doorbell.h>
35171 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35172 index 5046a64..71ca936 100644
35173 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35174 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35175 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35176 void (*link_down)(struct __vxge_hw_device *devh);
35177 void (*crit_err)(struct __vxge_hw_device *devh,
35178 enum vxge_hw_event type, u64 ext_data);
35179 -};
35180 +} __no_const;
35181
35182 /*
35183 * struct __vxge_hw_blockpool_entry - Block private data structure
35184 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35185 index 4a518a3..936b334 100644
35186 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35187 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35188 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35189 struct vxge_hw_mempool_dma *dma_object,
35190 u32 index,
35191 u32 is_last);
35192 -};
35193 +} __no_const;
35194
35195 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35196 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35197 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35198 index 0cf2351..56c4cef 100644
35199 --- a/drivers/net/ethernet/realtek/r8169.c
35200 +++ b/drivers/net/ethernet/realtek/r8169.c
35201 @@ -698,17 +698,17 @@ struct rtl8169_private {
35202 struct mdio_ops {
35203 void (*write)(void __iomem *, int, int);
35204 int (*read)(void __iomem *, int);
35205 - } mdio_ops;
35206 + } __no_const mdio_ops;
35207
35208 struct pll_power_ops {
35209 void (*down)(struct rtl8169_private *);
35210 void (*up)(struct rtl8169_private *);
35211 - } pll_power_ops;
35212 + } __no_const pll_power_ops;
35213
35214 struct jumbo_ops {
35215 void (*enable)(struct rtl8169_private *);
35216 void (*disable)(struct rtl8169_private *);
35217 - } jumbo_ops;
35218 + } __no_const jumbo_ops;
35219
35220 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35221 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35222 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35223 index 1b4658c..a30dabb 100644
35224 --- a/drivers/net/ethernet/sis/sis190.c
35225 +++ b/drivers/net/ethernet/sis/sis190.c
35226 @@ -1624,7 +1624,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35227 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35228 struct net_device *dev)
35229 {
35230 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35231 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35232 struct sis190_private *tp = netdev_priv(dev);
35233 struct pci_dev *isa_bridge;
35234 u8 reg, tmp8;
35235 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35236 index 41e6b33..8e89b0f 100644
35237 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35238 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35239 @@ -139,8 +139,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35240
35241 writel(value, ioaddr + MMC_CNTRL);
35242
35243 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35244 - MMC_CNTRL, value);
35245 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35246 +// MMC_CNTRL, value);
35247 }
35248
35249 /* To mask all all interrupts.*/
35250 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35251 index 486b404..0d6677d 100644
35252 --- a/drivers/net/ppp/ppp_generic.c
35253 +++ b/drivers/net/ppp/ppp_generic.c
35254 @@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35255 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35256 struct ppp_stats stats;
35257 struct ppp_comp_stats cstats;
35258 - char *vers;
35259
35260 switch (cmd) {
35261 case SIOCGPPPSTATS:
35262 @@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35263 break;
35264
35265 case SIOCGPPPVER:
35266 - vers = PPP_VERSION;
35267 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35268 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35269 break;
35270 err = 0;
35271 break;
35272 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
35273 index 515f122..41dd273 100644
35274 --- a/drivers/net/tokenring/abyss.c
35275 +++ b/drivers/net/tokenring/abyss.c
35276 @@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
35277
35278 static int __init abyss_init (void)
35279 {
35280 - abyss_netdev_ops = tms380tr_netdev_ops;
35281 + pax_open_kernel();
35282 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35283
35284 - abyss_netdev_ops.ndo_open = abyss_open;
35285 - abyss_netdev_ops.ndo_stop = abyss_close;
35286 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
35287 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
35288 + pax_close_kernel();
35289
35290 return pci_register_driver(&abyss_driver);
35291 }
35292 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
35293 index 6153cfd..cf69c1c 100644
35294 --- a/drivers/net/tokenring/madgemc.c
35295 +++ b/drivers/net/tokenring/madgemc.c
35296 @@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
35297
35298 static int __init madgemc_init (void)
35299 {
35300 - madgemc_netdev_ops = tms380tr_netdev_ops;
35301 - madgemc_netdev_ops.ndo_open = madgemc_open;
35302 - madgemc_netdev_ops.ndo_stop = madgemc_close;
35303 + pax_open_kernel();
35304 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35305 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
35306 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
35307 + pax_close_kernel();
35308
35309 return mca_register_driver (&madgemc_driver);
35310 }
35311 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
35312 index 8d362e6..f91cc52 100644
35313 --- a/drivers/net/tokenring/proteon.c
35314 +++ b/drivers/net/tokenring/proteon.c
35315 @@ -353,9 +353,11 @@ static int __init proteon_init(void)
35316 struct platform_device *pdev;
35317 int i, num = 0, err = 0;
35318
35319 - proteon_netdev_ops = tms380tr_netdev_ops;
35320 - proteon_netdev_ops.ndo_open = proteon_open;
35321 - proteon_netdev_ops.ndo_stop = tms380tr_close;
35322 + pax_open_kernel();
35323 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35324 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
35325 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
35326 + pax_close_kernel();
35327
35328 err = platform_driver_register(&proteon_driver);
35329 if (err)
35330 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
35331 index 46db5c5..37c1536 100644
35332 --- a/drivers/net/tokenring/skisa.c
35333 +++ b/drivers/net/tokenring/skisa.c
35334 @@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
35335 struct platform_device *pdev;
35336 int i, num = 0, err = 0;
35337
35338 - sk_isa_netdev_ops = tms380tr_netdev_ops;
35339 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
35340 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35341 + pax_open_kernel();
35342 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35343 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
35344 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35345 + pax_close_kernel();
35346
35347 err = platform_driver_register(&sk_isa_driver);
35348 if (err)
35349 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35350 index 7bea9c6..7ef073c 100644
35351 --- a/drivers/net/tun.c
35352 +++ b/drivers/net/tun.c
35353 @@ -359,7 +359,7 @@ static void tun_free_netdev(struct net_device *dev)
35354 {
35355 struct tun_struct *tun = netdev_priv(dev);
35356
35357 - sock_put(tun->socket.sk);
35358 + sk_release_kernel(tun->socket.sk);
35359 }
35360
35361 /* Net device open. */
35362 @@ -979,10 +979,18 @@ static int tun_recvmsg(struct kiocb *iocb, struct socket *sock,
35363 return ret;
35364 }
35365
35366 +static int tun_release(struct socket *sock)
35367 +{
35368 + if (sock->sk)
35369 + sock_put(sock->sk);
35370 + return 0;
35371 +}
35372 +
35373 /* Ops structure to mimic raw sockets with tun */
35374 static const struct proto_ops tun_socket_ops = {
35375 .sendmsg = tun_sendmsg,
35376 .recvmsg = tun_recvmsg,
35377 + .release = tun_release,
35378 };
35379
35380 static struct proto tun_proto = {
35381 @@ -1109,10 +1117,11 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
35382 tun->vnet_hdr_sz = sizeof(struct virtio_net_hdr);
35383
35384 err = -ENOMEM;
35385 - sk = sk_alloc(net, AF_UNSPEC, GFP_KERNEL, &tun_proto);
35386 + sk = sk_alloc(&init_net, AF_UNSPEC, GFP_KERNEL, &tun_proto);
35387 if (!sk)
35388 goto err_free_dev;
35389
35390 + sk_change_net(sk, net);
35391 tun->socket.wq = &tun->wq;
35392 init_waitqueue_head(&tun->wq.wait);
35393 tun->socket.ops = &tun_socket_ops;
35394 @@ -1173,7 +1182,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
35395 return 0;
35396
35397 err_free_sk:
35398 - sock_put(sk);
35399 + tun_free_netdev(dev);
35400 err_free_dev:
35401 free_netdev(dev);
35402 failed:
35403 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35404 index 304fe78..db112fa 100644
35405 --- a/drivers/net/usb/hso.c
35406 +++ b/drivers/net/usb/hso.c
35407 @@ -71,7 +71,7 @@
35408 #include <asm/byteorder.h>
35409 #include <linux/serial_core.h>
35410 #include <linux/serial.h>
35411 -
35412 +#include <asm/local.h>
35413
35414 #define MOD_AUTHOR "Option Wireless"
35415 #define MOD_DESCRIPTION "USB High Speed Option driver"
35416 @@ -257,7 +257,7 @@ struct hso_serial {
35417
35418 /* from usb_serial_port */
35419 struct tty_struct *tty;
35420 - int open_count;
35421 + local_t open_count;
35422 spinlock_t serial_lock;
35423
35424 int (*write_data) (struct hso_serial *serial);
35425 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35426 struct urb *urb;
35427
35428 urb = serial->rx_urb[0];
35429 - if (serial->open_count > 0) {
35430 + if (local_read(&serial->open_count) > 0) {
35431 count = put_rxbuf_data(urb, serial);
35432 if (count == -1)
35433 return;
35434 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35435 DUMP1(urb->transfer_buffer, urb->actual_length);
35436
35437 /* Anyone listening? */
35438 - if (serial->open_count == 0)
35439 + if (local_read(&serial->open_count) == 0)
35440 return;
35441
35442 if (status == 0) {
35443 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35444 spin_unlock_irq(&serial->serial_lock);
35445
35446 /* check for port already opened, if not set the termios */
35447 - serial->open_count++;
35448 - if (serial->open_count == 1) {
35449 + if (local_inc_return(&serial->open_count) == 1) {
35450 serial->rx_state = RX_IDLE;
35451 /* Force default termio settings */
35452 _hso_serial_set_termios(tty, NULL);
35453 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35454 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35455 if (result) {
35456 hso_stop_serial_device(serial->parent);
35457 - serial->open_count--;
35458 + local_dec(&serial->open_count);
35459 kref_put(&serial->parent->ref, hso_serial_ref_free);
35460 }
35461 } else {
35462 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35463
35464 /* reset the rts and dtr */
35465 /* do the actual close */
35466 - serial->open_count--;
35467 + local_dec(&serial->open_count);
35468
35469 - if (serial->open_count <= 0) {
35470 - serial->open_count = 0;
35471 + if (local_read(&serial->open_count) <= 0) {
35472 + local_set(&serial->open_count, 0);
35473 spin_lock_irq(&serial->serial_lock);
35474 if (serial->tty == tty) {
35475 serial->tty->driver_data = NULL;
35476 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35477
35478 /* the actual setup */
35479 spin_lock_irqsave(&serial->serial_lock, flags);
35480 - if (serial->open_count)
35481 + if (local_read(&serial->open_count))
35482 _hso_serial_set_termios(tty, old);
35483 else
35484 tty->termios = old;
35485 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
35486 D1("Pending read interrupt on port %d\n", i);
35487 spin_lock(&serial->serial_lock);
35488 if (serial->rx_state == RX_IDLE &&
35489 - serial->open_count > 0) {
35490 + local_read(&serial->open_count) > 0) {
35491 /* Setup and send a ctrl req read on
35492 * port i */
35493 if (!serial->rx_urb_filled[0]) {
35494 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
35495 /* Start all serial ports */
35496 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35497 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35498 - if (dev2ser(serial_table[i])->open_count) {
35499 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
35500 result =
35501 hso_start_serial_device(serial_table[i], GFP_NOIO);
35502 hso_kick_transmit(dev2ser(serial_table[i]));
35503 diff --git a/drivers/net/vmxnet3/vmxnet3_ethtool.c b/drivers/net/vmxnet3/vmxnet3_ethtool.c
35504 index e662cbc..8d4a102 100644
35505 --- a/drivers/net/vmxnet3/vmxnet3_ethtool.c
35506 +++ b/drivers/net/vmxnet3/vmxnet3_ethtool.c
35507 @@ -601,8 +601,7 @@ vmxnet3_set_rss_indir(struct net_device *netdev,
35508 * Return with error code if any of the queue indices
35509 * is out of range
35510 */
35511 - if (p->ring_index[i] < 0 ||
35512 - p->ring_index[i] >= adapter->num_rx_queues)
35513 + if (p->ring_index[i] >= adapter->num_rx_queues)
35514 return -EINVAL;
35515 }
35516
35517 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35518 index 0f9ee46..e2d6e65 100644
35519 --- a/drivers/net/wireless/ath/ath.h
35520 +++ b/drivers/net/wireless/ath/ath.h
35521 @@ -119,6 +119,7 @@ struct ath_ops {
35522 void (*write_flush) (void *);
35523 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35524 };
35525 +typedef struct ath_ops __no_const ath_ops_no_const;
35526
35527 struct ath_common;
35528 struct ath_bus_ops;
35529 diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
35530 index 8c5ce8b..abf101b 100644
35531 --- a/drivers/net/wireless/ath/ath5k/debug.c
35532 +++ b/drivers/net/wireless/ath/ath5k/debug.c
35533 @@ -343,6 +343,9 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
35534
35535 static ssize_t write_file_debug(struct file *file,
35536 const char __user *userbuf,
35537 + size_t count, loff_t *ppos) __size_overflow(3);
35538 +static ssize_t write_file_debug(struct file *file,
35539 + const char __user *userbuf,
35540 size_t count, loff_t *ppos)
35541 {
35542 struct ath5k_hw *ah = file->private_data;
35543 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35544 index b592016..fe47870 100644
35545 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35546 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35547 @@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35548 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35549 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35550
35551 - ACCESS_ONCE(ads->ds_link) = i->link;
35552 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35553 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35554 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35555
35556 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35557 ctl6 = SM(i->keytype, AR_EncrType);
35558 @@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35559
35560 if ((i->is_first || i->is_last) &&
35561 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35562 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35563 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35564 | set11nTries(i->rates, 1)
35565 | set11nTries(i->rates, 2)
35566 | set11nTries(i->rates, 3)
35567 | (i->dur_update ? AR_DurUpdateEna : 0)
35568 | SM(0, AR_BurstDur);
35569
35570 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35571 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35572 | set11nRate(i->rates, 1)
35573 | set11nRate(i->rates, 2)
35574 | set11nRate(i->rates, 3);
35575 } else {
35576 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35577 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35578 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35579 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35580 }
35581
35582 if (!i->is_first) {
35583 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35584 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35585 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35586 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35587 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35588 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35589 return;
35590 }
35591
35592 @@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35593 break;
35594 }
35595
35596 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35597 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35598 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35599 | SM(i->txpower, AR_XmitPower)
35600 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35601 @@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35602 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35603 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35604
35605 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35606 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35607 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35608 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35609
35610 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35611 return;
35612
35613 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35614 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35615 | set11nPktDurRTSCTS(i->rates, 1);
35616
35617 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35618 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35619 | set11nPktDurRTSCTS(i->rates, 3);
35620
35621 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35622 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35623 | set11nRateFlags(i->rates, 1)
35624 | set11nRateFlags(i->rates, 2)
35625 | set11nRateFlags(i->rates, 3)
35626 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35627 index f5ae3c6..7936af3 100644
35628 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35629 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35630 @@ -35,47 +35,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35631 (i->qcu << AR_TxQcuNum_S) | 0x17;
35632
35633 checksum += val;
35634 - ACCESS_ONCE(ads->info) = val;
35635 + ACCESS_ONCE_RW(ads->info) = val;
35636
35637 checksum += i->link;
35638 - ACCESS_ONCE(ads->link) = i->link;
35639 + ACCESS_ONCE_RW(ads->link) = i->link;
35640
35641 checksum += i->buf_addr[0];
35642 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35643 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35644 checksum += i->buf_addr[1];
35645 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35646 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35647 checksum += i->buf_addr[2];
35648 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35649 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35650 checksum += i->buf_addr[3];
35651 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35652 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35653
35654 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35655 - ACCESS_ONCE(ads->ctl3) = val;
35656 + ACCESS_ONCE_RW(ads->ctl3) = val;
35657 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35658 - ACCESS_ONCE(ads->ctl5) = val;
35659 + ACCESS_ONCE_RW(ads->ctl5) = val;
35660 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35661 - ACCESS_ONCE(ads->ctl7) = val;
35662 + ACCESS_ONCE_RW(ads->ctl7) = val;
35663 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35664 - ACCESS_ONCE(ads->ctl9) = val;
35665 + ACCESS_ONCE_RW(ads->ctl9) = val;
35666
35667 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35668 - ACCESS_ONCE(ads->ctl10) = checksum;
35669 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35670
35671 if (i->is_first || i->is_last) {
35672 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35673 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35674 | set11nTries(i->rates, 1)
35675 | set11nTries(i->rates, 2)
35676 | set11nTries(i->rates, 3)
35677 | (i->dur_update ? AR_DurUpdateEna : 0)
35678 | SM(0, AR_BurstDur);
35679
35680 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35681 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35682 | set11nRate(i->rates, 1)
35683 | set11nRate(i->rates, 2)
35684 | set11nRate(i->rates, 3);
35685 } else {
35686 - ACCESS_ONCE(ads->ctl13) = 0;
35687 - ACCESS_ONCE(ads->ctl14) = 0;
35688 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35689 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35690 }
35691
35692 ads->ctl20 = 0;
35693 @@ -84,17 +84,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35694
35695 ctl17 = SM(i->keytype, AR_EncrType);
35696 if (!i->is_first) {
35697 - ACCESS_ONCE(ads->ctl11) = 0;
35698 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35699 - ACCESS_ONCE(ads->ctl15) = 0;
35700 - ACCESS_ONCE(ads->ctl16) = 0;
35701 - ACCESS_ONCE(ads->ctl17) = ctl17;
35702 - ACCESS_ONCE(ads->ctl18) = 0;
35703 - ACCESS_ONCE(ads->ctl19) = 0;
35704 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35705 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35706 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35707 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35708 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35709 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35710 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35711 return;
35712 }
35713
35714 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35715 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35716 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35717 | SM(i->txpower, AR_XmitPower)
35718 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35719 @@ -130,22 +130,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35720 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35721 ctl12 |= SM(val, AR_PAPRDChainMask);
35722
35723 - ACCESS_ONCE(ads->ctl12) = ctl12;
35724 - ACCESS_ONCE(ads->ctl17) = ctl17;
35725 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35726 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35727
35728 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35729 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35730 | set11nPktDurRTSCTS(i->rates, 1);
35731
35732 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35733 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35734 | set11nPktDurRTSCTS(i->rates, 3);
35735
35736 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35737 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35738 | set11nRateFlags(i->rates, 1)
35739 | set11nRateFlags(i->rates, 2)
35740 | set11nRateFlags(i->rates, 3)
35741 | SM(i->rtscts_rate, AR_RTSCTSRate);
35742
35743 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35744 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35745 }
35746
35747 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35748 diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
35749 index 2741203..837a960 100644
35750 --- a/drivers/net/wireless/ath/ath9k/debug.c
35751 +++ b/drivers/net/wireless/ath/ath9k/debug.c
35752 @@ -60,6 +60,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
35753 }
35754
35755 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35756 + size_t count, loff_t *ppos) __size_overflow(3);
35757 +static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35758 size_t count, loff_t *ppos)
35759 {
35760 struct ath_softc *sc = file->private_data;
35761 diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
35762 index d3ff33c..c98bcda 100644
35763 --- a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
35764 +++ b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
35765 @@ -464,6 +464,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
35766 }
35767
35768 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35769 + size_t count, loff_t *ppos) __size_overflow(3);
35770 +static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
35771 size_t count, loff_t *ppos)
35772 {
35773 struct ath9k_htc_priv *priv = file->private_data;
35774 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35775 index 1bd8edf..10c6d30 100644
35776 --- a/drivers/net/wireless/ath/ath9k/hw.h
35777 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35778 @@ -605,7 +605,7 @@ struct ath_hw_private_ops {
35779
35780 /* ANI */
35781 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35782 -};
35783 +} __no_const;
35784
35785 /**
35786 * struct ath_hw_ops - callbacks used by hardware code and driver code
35787 @@ -635,7 +635,7 @@ struct ath_hw_ops {
35788 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35789 struct ath_hw_antcomb_conf *antconf);
35790
35791 -};
35792 +} __no_const;
35793
35794 struct ath_nf_limits {
35795 s16 max;
35796 @@ -655,7 +655,7 @@ enum ath_cal_list {
35797 #define AH_FASTCC 0x4
35798
35799 struct ath_hw {
35800 - struct ath_ops reg_ops;
35801 + ath_ops_no_const reg_ops;
35802
35803 struct ieee80211_hw *hw;
35804 struct ath_common common;
35805 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35806 index bea8524..c677c06 100644
35807 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35808 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35809 @@ -547,7 +547,7 @@ struct phy_func_ptr {
35810 void (*carrsuppr)(struct brcms_phy *);
35811 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35812 void (*detach)(struct brcms_phy *);
35813 -};
35814 +} __no_const;
35815
35816 struct brcms_phy {
35817 struct brcms_phy_pub pubpi_ro;
35818 diff --git a/drivers/net/wireless/iwlegacy/iwl3945-base.c b/drivers/net/wireless/iwlegacy/iwl3945-base.c
35819 index 05f2ad1..ae00eea 100644
35820 --- a/drivers/net/wireless/iwlegacy/iwl3945-base.c
35821 +++ b/drivers/net/wireless/iwlegacy/iwl3945-base.c
35822 @@ -3685,7 +3685,9 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
35823 */
35824 if (iwl3945_mod_params.disable_hw_scan) {
35825 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
35826 - iwl3945_hw_ops.hw_scan = NULL;
35827 + pax_open_kernel();
35828 + *(void **)&iwl3945_hw_ops.hw_scan = NULL;
35829 + pax_close_kernel();
35830 }
35831
35832 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
35833 diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
35834 index 69a77e2..552b42c 100644
35835 --- a/drivers/net/wireless/iwlwifi/iwl-debug.h
35836 +++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
35837 @@ -71,8 +71,8 @@ do { \
35838 } while (0)
35839
35840 #else
35841 -#define IWL_DEBUG(m, level, fmt, args...)
35842 -#define IWL_DEBUG_LIMIT(m, level, fmt, args...)
35843 +#define IWL_DEBUG(m, level, fmt, args...) do {} while (0)
35844 +#define IWL_DEBUG_LIMIT(m, level, fmt, args...) do {} while (0)
35845 #define iwl_print_hex_dump(m, level, p, len)
35846 #endif /* CONFIG_IWLWIFI_DEBUG */
35847
35848 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35849 index 523ad55..f8c5dc5 100644
35850 --- a/drivers/net/wireless/mac80211_hwsim.c
35851 +++ b/drivers/net/wireless/mac80211_hwsim.c
35852 @@ -1678,9 +1678,11 @@ static int __init init_mac80211_hwsim(void)
35853 return -EINVAL;
35854
35855 if (fake_hw_scan) {
35856 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35857 - mac80211_hwsim_ops.sw_scan_start = NULL;
35858 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35859 + pax_open_kernel();
35860 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35861 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35862 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35863 + pax_close_kernel();
35864 }
35865
35866 spin_lock_init(&hwsim_radio_lock);
35867 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35868 index 30f138b..c904585 100644
35869 --- a/drivers/net/wireless/mwifiex/main.h
35870 +++ b/drivers/net/wireless/mwifiex/main.h
35871 @@ -543,7 +543,7 @@ struct mwifiex_if_ops {
35872 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
35873 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
35874 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35875 -};
35876 +} __no_const;
35877
35878 struct mwifiex_adapter {
35879 u8 iface_type;
35880 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35881 index 0c13840..a5c3ed6 100644
35882 --- a/drivers/net/wireless/rndis_wlan.c
35883 +++ b/drivers/net/wireless/rndis_wlan.c
35884 @@ -1275,7 +1275,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35885
35886 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35887
35888 - if (rts_threshold < 0 || rts_threshold > 2347)
35889 + if (rts_threshold > 2347)
35890 rts_threshold = 2347;
35891
35892 tmp = cpu_to_le32(rts_threshold);
35893 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
35894 index a77f1bb..c608b2b 100644
35895 --- a/drivers/net/wireless/wl1251/wl1251.h
35896 +++ b/drivers/net/wireless/wl1251/wl1251.h
35897 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35898 void (*reset)(struct wl1251 *wl);
35899 void (*enable_irq)(struct wl1251 *wl);
35900 void (*disable_irq)(struct wl1251 *wl);
35901 -};
35902 +} __no_const;
35903
35904 struct wl1251 {
35905 struct ieee80211_hw *hw;
35906 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35907 index f34b5b2..b5abb9f 100644
35908 --- a/drivers/oprofile/buffer_sync.c
35909 +++ b/drivers/oprofile/buffer_sync.c
35910 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35911 if (cookie == NO_COOKIE)
35912 offset = pc;
35913 if (cookie == INVALID_COOKIE) {
35914 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35915 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35916 offset = pc;
35917 }
35918 if (cookie != last_cookie) {
35919 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35920 /* add userspace sample */
35921
35922 if (!mm) {
35923 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35924 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35925 return 0;
35926 }
35927
35928 cookie = lookup_dcookie(mm, s->eip, &offset);
35929
35930 if (cookie == INVALID_COOKIE) {
35931 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35932 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35933 return 0;
35934 }
35935
35936 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35937 /* ignore backtraces if failed to add a sample */
35938 if (state == sb_bt_start) {
35939 state = sb_bt_ignore;
35940 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35941 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35942 }
35943 }
35944 release_mm(mm);
35945 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35946 index c0cc4e7..44d4e54 100644
35947 --- a/drivers/oprofile/event_buffer.c
35948 +++ b/drivers/oprofile/event_buffer.c
35949 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35950 }
35951
35952 if (buffer_pos == buffer_size) {
35953 - atomic_inc(&oprofile_stats.event_lost_overflow);
35954 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35955 return;
35956 }
35957
35958 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35959 index f8c752e..28bf4fc 100644
35960 --- a/drivers/oprofile/oprof.c
35961 +++ b/drivers/oprofile/oprof.c
35962 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35963 if (oprofile_ops.switch_events())
35964 return;
35965
35966 - atomic_inc(&oprofile_stats.multiplex_counter);
35967 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35968 start_switch_worker();
35969 }
35970
35971 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
35972 index 84a208d..f07d177 100644
35973 --- a/drivers/oprofile/oprofile_files.c
35974 +++ b/drivers/oprofile/oprofile_files.c
35975 @@ -36,6 +36,8 @@ static ssize_t timeout_read(struct file *file, char __user *buf,
35976
35977
35978 static ssize_t timeout_write(struct file *file, char const __user *buf,
35979 + size_t count, loff_t *offset) __size_overflow(3);
35980 +static ssize_t timeout_write(struct file *file, char const __user *buf,
35981 size_t count, loff_t *offset)
35982 {
35983 unsigned long val;
35984 @@ -72,6 +74,7 @@ static ssize_t depth_read(struct file *file, char __user *buf, size_t count, lof
35985 }
35986
35987
35988 +static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
35989 static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
35990 {
35991 unsigned long val;
35992 @@ -126,12 +129,14 @@ static const struct file_operations cpu_type_fops = {
35993 };
35994
35995
35996 +static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset) __size_overflow(3);
35997 static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
35998 {
35999 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
36000 }
36001
36002
36003 +static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
36004 static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
36005 {
36006 unsigned long val;
36007 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36008 index 917d28e..d62d981 100644
36009 --- a/drivers/oprofile/oprofile_stats.c
36010 +++ b/drivers/oprofile/oprofile_stats.c
36011 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36012 cpu_buf->sample_invalid_eip = 0;
36013 }
36014
36015 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36016 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36017 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36018 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36019 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36020 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36021 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36022 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36023 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36024 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36025 }
36026
36027
36028 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36029 index 38b6fc0..b5cbfce 100644
36030 --- a/drivers/oprofile/oprofile_stats.h
36031 +++ b/drivers/oprofile/oprofile_stats.h
36032 @@ -13,11 +13,11 @@
36033 #include <linux/atomic.h>
36034
36035 struct oprofile_stat_struct {
36036 - atomic_t sample_lost_no_mm;
36037 - atomic_t sample_lost_no_mapping;
36038 - atomic_t bt_lost_no_mapping;
36039 - atomic_t event_lost_overflow;
36040 - atomic_t multiplex_counter;
36041 + atomic_unchecked_t sample_lost_no_mm;
36042 + atomic_unchecked_t sample_lost_no_mapping;
36043 + atomic_unchecked_t bt_lost_no_mapping;
36044 + atomic_unchecked_t event_lost_overflow;
36045 + atomic_unchecked_t multiplex_counter;
36046 };
36047
36048 extern struct oprofile_stat_struct oprofile_stats;
36049 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36050 index 2f0aa0f..d5246c3 100644
36051 --- a/drivers/oprofile/oprofilefs.c
36052 +++ b/drivers/oprofile/oprofilefs.c
36053 @@ -97,6 +97,7 @@ static ssize_t ulong_read_file(struct file *file, char __user *buf, size_t count
36054 }
36055
36056
36057 +static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
36058 static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset)
36059 {
36060 unsigned long value;
36061 @@ -193,7 +194,7 @@ static const struct file_operations atomic_ro_fops = {
36062
36063
36064 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36065 - char const *name, atomic_t *val)
36066 + char const *name, atomic_unchecked_t *val)
36067 {
36068 return __oprofilefs_create_file(sb, root, name,
36069 &atomic_ro_fops, 0444, val);
36070 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36071 index 3f56bc0..707d642 100644
36072 --- a/drivers/parport/procfs.c
36073 +++ b/drivers/parport/procfs.c
36074 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36075
36076 *ppos += len;
36077
36078 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36079 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36080 }
36081
36082 #ifdef CONFIG_PARPORT_1284
36083 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36084
36085 *ppos += len;
36086
36087 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36088 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36089 }
36090 #endif /* IEEE1284.3 support. */
36091
36092 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36093 index 9fff878..ad0ad53 100644
36094 --- a/drivers/pci/hotplug/cpci_hotplug.h
36095 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36096 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36097 int (*hardware_test) (struct slot* slot, u32 value);
36098 u8 (*get_power) (struct slot* slot);
36099 int (*set_power) (struct slot* slot, int value);
36100 -};
36101 +} __no_const;
36102
36103 struct cpci_hp_controller {
36104 unsigned int irq;
36105 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36106 index 76ba8a1..20ca857 100644
36107 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36108 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36109 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36110
36111 void compaq_nvram_init (void __iomem *rom_start)
36112 {
36113 +
36114 +#ifndef CONFIG_PAX_KERNEXEC
36115 if (rom_start) {
36116 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36117 }
36118 +#endif
36119 +
36120 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36121
36122 /* initialize our int15 lock */
36123 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36124 index 24f049e..051f66e 100644
36125 --- a/drivers/pci/pcie/aspm.c
36126 +++ b/drivers/pci/pcie/aspm.c
36127 @@ -27,9 +27,9 @@
36128 #define MODULE_PARAM_PREFIX "pcie_aspm."
36129
36130 /* Note: those are not register definitions */
36131 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36132 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36133 -#define ASPM_STATE_L1 (4) /* L1 state */
36134 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36135 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36136 +#define ASPM_STATE_L1 (4U) /* L1 state */
36137 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36138 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36139
36140 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36141 index dfee1b3..a454fb6 100644
36142 --- a/drivers/pci/probe.c
36143 +++ b/drivers/pci/probe.c
36144 @@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36145 u32 l, sz, mask;
36146 u16 orig_cmd;
36147
36148 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36149 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36150
36151 if (!dev->mmio_always_on) {
36152 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
36153 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36154 index 27911b5..5b6db88 100644
36155 --- a/drivers/pci/proc.c
36156 +++ b/drivers/pci/proc.c
36157 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36158 static int __init pci_proc_init(void)
36159 {
36160 struct pci_dev *dev = NULL;
36161 +
36162 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36163 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36164 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36165 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36166 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36167 +#endif
36168 +#else
36169 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36170 +#endif
36171 proc_create("devices", 0, proc_bus_pci_dir,
36172 &proc_bus_pci_dev_operations);
36173 proc_initialized = 1;
36174 diff --git a/drivers/platform/x86/asus_acpi.c b/drivers/platform/x86/asus_acpi.c
36175 index d9312b3..59f63f2 100644
36176 --- a/drivers/platform/x86/asus_acpi.c
36177 +++ b/drivers/platform/x86/asus_acpi.c
36178 @@ -887,6 +887,8 @@ static int lcd_proc_open(struct inode *inode, struct file *file)
36179 }
36180
36181 static ssize_t lcd_proc_write(struct file *file, const char __user *buffer,
36182 + size_t count, loff_t *pos) __size_overflow(3);
36183 +static ssize_t lcd_proc_write(struct file *file, const char __user *buffer,
36184 size_t count, loff_t *pos)
36185 {
36186 int rv, value;
36187 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36188 index 7b82868..b9344c9 100644
36189 --- a/drivers/platform/x86/thinkpad_acpi.c
36190 +++ b/drivers/platform/x86/thinkpad_acpi.c
36191 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
36192 return 0;
36193 }
36194
36195 -void static hotkey_mask_warn_incomplete_mask(void)
36196 +static void hotkey_mask_warn_incomplete_mask(void)
36197 {
36198 /* log only what the user can fix... */
36199 const u32 wantedmask = hotkey_driver_mask &
36200 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36201 }
36202 }
36203
36204 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36205 - struct tp_nvram_state *newn,
36206 - const u32 event_mask)
36207 -{
36208 -
36209 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36210 do { \
36211 if ((event_mask & (1 << __scancode)) && \
36212 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36213 tpacpi_hotkey_send_key(__scancode); \
36214 } while (0)
36215
36216 - void issue_volchange(const unsigned int oldvol,
36217 - const unsigned int newvol)
36218 - {
36219 - unsigned int i = oldvol;
36220 +static void issue_volchange(const unsigned int oldvol,
36221 + const unsigned int newvol,
36222 + const u32 event_mask)
36223 +{
36224 + unsigned int i = oldvol;
36225
36226 - while (i > newvol) {
36227 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36228 - i--;
36229 - }
36230 - while (i < newvol) {
36231 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36232 - i++;
36233 - }
36234 + while (i > newvol) {
36235 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36236 + i--;
36237 }
36238 + while (i < newvol) {
36239 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36240 + i++;
36241 + }
36242 +}
36243
36244 - void issue_brightnesschange(const unsigned int oldbrt,
36245 - const unsigned int newbrt)
36246 - {
36247 - unsigned int i = oldbrt;
36248 +static void issue_brightnesschange(const unsigned int oldbrt,
36249 + const unsigned int newbrt,
36250 + const u32 event_mask)
36251 +{
36252 + unsigned int i = oldbrt;
36253
36254 - while (i > newbrt) {
36255 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36256 - i--;
36257 - }
36258 - while (i < newbrt) {
36259 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36260 - i++;
36261 - }
36262 + while (i > newbrt) {
36263 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36264 + i--;
36265 + }
36266 + while (i < newbrt) {
36267 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36268 + i++;
36269 }
36270 +}
36271
36272 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36273 + struct tp_nvram_state *newn,
36274 + const u32 event_mask)
36275 +{
36276 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36277 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36278 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36279 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36280 oldn->volume_level != newn->volume_level) {
36281 /* recently muted, or repeated mute keypress, or
36282 * multiple presses ending in mute */
36283 - issue_volchange(oldn->volume_level, newn->volume_level);
36284 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36285 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36286 }
36287 } else {
36288 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36289 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36290 }
36291 if (oldn->volume_level != newn->volume_level) {
36292 - issue_volchange(oldn->volume_level, newn->volume_level);
36293 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36294 } else if (oldn->volume_toggle != newn->volume_toggle) {
36295 /* repeated vol up/down keypress at end of scale ? */
36296 if (newn->volume_level == 0)
36297 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36298 /* handle brightness */
36299 if (oldn->brightness_level != newn->brightness_level) {
36300 issue_brightnesschange(oldn->brightness_level,
36301 - newn->brightness_level);
36302 + newn->brightness_level,
36303 + event_mask);
36304 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36305 /* repeated key presses that didn't change state */
36306 if (newn->brightness_level == 0)
36307 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36308 && !tp_features.bright_unkfw)
36309 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36310 }
36311 +}
36312
36313 #undef TPACPI_COMPARE_KEY
36314 #undef TPACPI_MAY_SEND_KEY
36315 -}
36316
36317 /*
36318 * Polling driver
36319 diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
36320 index dcdc1f4..85cee16 100644
36321 --- a/drivers/platform/x86/toshiba_acpi.c
36322 +++ b/drivers/platform/x86/toshiba_acpi.c
36323 @@ -517,6 +517,8 @@ static int set_lcd_status(struct backlight_device *bd)
36324 }
36325
36326 static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
36327 + size_t count, loff_t *pos) __size_overflow(3);
36328 +static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
36329 size_t count, loff_t *pos)
36330 {
36331 struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
36332 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36333 index b859d16..5cc6b1a 100644
36334 --- a/drivers/pnp/pnpbios/bioscalls.c
36335 +++ b/drivers/pnp/pnpbios/bioscalls.c
36336 @@ -59,7 +59,7 @@ do { \
36337 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36338 } while(0)
36339
36340 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36341 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36342 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36343
36344 /*
36345 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36346
36347 cpu = get_cpu();
36348 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36349 +
36350 + pax_open_kernel();
36351 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36352 + pax_close_kernel();
36353
36354 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36355 spin_lock_irqsave(&pnp_bios_lock, flags);
36356 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36357 :"memory");
36358 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36359
36360 + pax_open_kernel();
36361 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36362 + pax_close_kernel();
36363 +
36364 put_cpu();
36365
36366 /* If we get here and this is set then the PnP BIOS faulted on us. */
36367 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36368 return status;
36369 }
36370
36371 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36372 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36373 {
36374 int i;
36375
36376 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36377 pnp_bios_callpoint.offset = header->fields.pm16offset;
36378 pnp_bios_callpoint.segment = PNP_CS16;
36379
36380 + pax_open_kernel();
36381 +
36382 for_each_possible_cpu(i) {
36383 struct desc_struct *gdt = get_cpu_gdt_table(i);
36384 if (!gdt)
36385 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36386 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36387 (unsigned long)__va(header->fields.pm16dseg));
36388 }
36389 +
36390 + pax_close_kernel();
36391 }
36392 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36393 index b0ecacb..7c9da2e 100644
36394 --- a/drivers/pnp/resource.c
36395 +++ b/drivers/pnp/resource.c
36396 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36397 return 1;
36398
36399 /* check if the resource is valid */
36400 - if (*irq < 0 || *irq > 15)
36401 + if (*irq > 15)
36402 return 0;
36403
36404 /* check if the resource is reserved */
36405 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36406 return 1;
36407
36408 /* check if the resource is valid */
36409 - if (*dma < 0 || *dma == 4 || *dma > 7)
36410 + if (*dma == 4 || *dma > 7)
36411 return 0;
36412
36413 /* check if the resource is reserved */
36414 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36415 index bb16f5b..c751eef 100644
36416 --- a/drivers/power/bq27x00_battery.c
36417 +++ b/drivers/power/bq27x00_battery.c
36418 @@ -67,7 +67,7 @@
36419 struct bq27x00_device_info;
36420 struct bq27x00_access_methods {
36421 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36422 -};
36423 +} __no_const;
36424
36425 enum bq27x00_chip { BQ27000, BQ27500 };
36426
36427 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36428 index 33f5d9a..d957d3f 100644
36429 --- a/drivers/regulator/max8660.c
36430 +++ b/drivers/regulator/max8660.c
36431 @@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36432 max8660->shadow_regs[MAX8660_OVER1] = 5;
36433 } else {
36434 /* Otherwise devices can be toggled via software */
36435 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36436 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36437 + pax_open_kernel();
36438 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36439 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36440 + pax_close_kernel();
36441 }
36442
36443 /*
36444 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36445 index 023d17d..74ef35b 100644
36446 --- a/drivers/regulator/mc13892-regulator.c
36447 +++ b/drivers/regulator/mc13892-regulator.c
36448 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36449 }
36450 mc13xxx_unlock(mc13892);
36451
36452 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36453 + pax_open_kernel();
36454 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36455 = mc13892_vcam_set_mode;
36456 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36457 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36458 = mc13892_vcam_get_mode;
36459 + pax_close_kernel();
36460 for (i = 0; i < pdata->num_regulators; i++) {
36461 init_data = &pdata->regulators[i];
36462 priv->regulators[i] = regulator_register(
36463 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36464 index cace6d3..f623fda 100644
36465 --- a/drivers/rtc/rtc-dev.c
36466 +++ b/drivers/rtc/rtc-dev.c
36467 @@ -14,6 +14,7 @@
36468 #include <linux/module.h>
36469 #include <linux/rtc.h>
36470 #include <linux/sched.h>
36471 +#include <linux/grsecurity.h>
36472 #include "rtc-core.h"
36473
36474 static dev_t rtc_devt;
36475 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36476 if (copy_from_user(&tm, uarg, sizeof(tm)))
36477 return -EFAULT;
36478
36479 + gr_log_timechange();
36480 +
36481 return rtc_set_time(rtc, &tm);
36482
36483 case RTC_PIE_ON:
36484 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36485 index ffb5878..e6d785c 100644
36486 --- a/drivers/scsi/aacraid/aacraid.h
36487 +++ b/drivers/scsi/aacraid/aacraid.h
36488 @@ -492,7 +492,7 @@ struct adapter_ops
36489 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36490 /* Administrative operations */
36491 int (*adapter_comm)(struct aac_dev * dev, int comm);
36492 -};
36493 +} __no_const;
36494
36495 /*
36496 * Define which interrupt handler needs to be installed
36497 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36498 index 705e13e..91c873c 100644
36499 --- a/drivers/scsi/aacraid/linit.c
36500 +++ b/drivers/scsi/aacraid/linit.c
36501 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36502 #elif defined(__devinitconst)
36503 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36504 #else
36505 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36506 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36507 #endif
36508 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36509 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36510 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36511 index d5ff142..49c0ebb 100644
36512 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36513 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36514 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36515 .lldd_control_phy = asd_control_phy,
36516 };
36517
36518 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36519 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36520 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36521 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36522 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36523 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36524 index a796de9..1ef20e1 100644
36525 --- a/drivers/scsi/bfa/bfa.h
36526 +++ b/drivers/scsi/bfa/bfa.h
36527 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36528 u32 *end);
36529 int cpe_vec_q0;
36530 int rme_vec_q0;
36531 -};
36532 +} __no_const;
36533 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36534
36535 struct bfa_faa_cbfn_s {
36536 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36537 index e07bd47..cd1bbbb 100644
36538 --- a/drivers/scsi/bfa/bfa_fcpim.c
36539 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36540 @@ -4121,7 +4121,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36541
36542 bfa_iotag_attach(fcp);
36543
36544 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36545 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36546 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36547 (fcp->num_itns * sizeof(struct bfa_itn_s));
36548 memset(fcp->itn_arr, 0,
36549 @@ -4179,7 +4179,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36550 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36551 {
36552 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36553 - struct bfa_itn_s *itn;
36554 + bfa_itn_s_no_const *itn;
36555
36556 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36557 itn->isr = isr;
36558 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36559 index 1080bcb..a3b39e3 100644
36560 --- a/drivers/scsi/bfa/bfa_fcpim.h
36561 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36562 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36563 struct bfa_itn_s {
36564 bfa_isr_func_t isr;
36565 };
36566 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36567
36568 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36569 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36570 @@ -149,7 +150,7 @@ struct bfa_fcp_mod_s {
36571 struct list_head iotag_tio_free_q; /* free IO resources */
36572 struct list_head iotag_unused_q; /* unused IO resources*/
36573 struct bfa_iotag_s *iotag_arr;
36574 - struct bfa_itn_s *itn_arr;
36575 + bfa_itn_s_no_const *itn_arr;
36576 int num_ioim_reqs;
36577 int num_fwtio_reqs;
36578 int num_itns;
36579 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36580 index 546d46b..642fa5b 100644
36581 --- a/drivers/scsi/bfa/bfa_ioc.h
36582 +++ b/drivers/scsi/bfa/bfa_ioc.h
36583 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36584 bfa_ioc_disable_cbfn_t disable_cbfn;
36585 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36586 bfa_ioc_reset_cbfn_t reset_cbfn;
36587 -};
36588 +} __no_const;
36589
36590 /*
36591 * IOC event notification mechanism.
36592 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36593 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36594 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36595 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36596 -};
36597 +} __no_const;
36598
36599 /*
36600 * Queue element to wait for room in request queue. FIFO order is
36601 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36602 index 351dc0b..951dc32 100644
36603 --- a/drivers/scsi/hosts.c
36604 +++ b/drivers/scsi/hosts.c
36605 @@ -42,7 +42,7 @@
36606 #include "scsi_logging.h"
36607
36608
36609 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
36610 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36611
36612
36613 static void scsi_host_cls_release(struct device *dev)
36614 @@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36615 * subtract one because we increment first then return, but we need to
36616 * know what the next host number was before increment
36617 */
36618 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36619 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36620 shost->dma_channel = 0xff;
36621
36622 /* These three are default values which can be overridden */
36623 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36624 index 865d452..e9b7fa7 100644
36625 --- a/drivers/scsi/hpsa.c
36626 +++ b/drivers/scsi/hpsa.c
36627 @@ -505,7 +505,7 @@ static inline u32 next_command(struct ctlr_info *h)
36628 u32 a;
36629
36630 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36631 - return h->access.command_completed(h);
36632 + return h->access->command_completed(h);
36633
36634 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36635 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36636 @@ -2989,7 +2989,7 @@ static void start_io(struct ctlr_info *h)
36637 while (!list_empty(&h->reqQ)) {
36638 c = list_entry(h->reqQ.next, struct CommandList, list);
36639 /* can't do anything if fifo is full */
36640 - if ((h->access.fifo_full(h))) {
36641 + if ((h->access->fifo_full(h))) {
36642 dev_warn(&h->pdev->dev, "fifo full\n");
36643 break;
36644 }
36645 @@ -2999,7 +2999,7 @@ static void start_io(struct ctlr_info *h)
36646 h->Qdepth--;
36647
36648 /* Tell the controller execute command */
36649 - h->access.submit_command(h, c);
36650 + h->access->submit_command(h, c);
36651
36652 /* Put job onto the completed Q */
36653 addQ(&h->cmpQ, c);
36654 @@ -3008,17 +3008,17 @@ static void start_io(struct ctlr_info *h)
36655
36656 static inline unsigned long get_next_completion(struct ctlr_info *h)
36657 {
36658 - return h->access.command_completed(h);
36659 + return h->access->command_completed(h);
36660 }
36661
36662 static inline bool interrupt_pending(struct ctlr_info *h)
36663 {
36664 - return h->access.intr_pending(h);
36665 + return h->access->intr_pending(h);
36666 }
36667
36668 static inline long interrupt_not_for_us(struct ctlr_info *h)
36669 {
36670 - return (h->access.intr_pending(h) == 0) ||
36671 + return (h->access->intr_pending(h) == 0) ||
36672 (h->interrupts_enabled == 0);
36673 }
36674
36675 @@ -3917,7 +3917,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36676 if (prod_index < 0)
36677 return -ENODEV;
36678 h->product_name = products[prod_index].product_name;
36679 - h->access = *(products[prod_index].access);
36680 + h->access = products[prod_index].access;
36681
36682 if (hpsa_board_disabled(h->pdev)) {
36683 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36684 @@ -4162,7 +4162,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36685
36686 assert_spin_locked(&lockup_detector_lock);
36687 remove_ctlr_from_lockup_detector_list(h);
36688 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36689 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36690 spin_lock_irqsave(&h->lock, flags);
36691 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36692 spin_unlock_irqrestore(&h->lock, flags);
36693 @@ -4340,7 +4340,7 @@ reinit_after_soft_reset:
36694 }
36695
36696 /* make sure the board interrupts are off */
36697 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36698 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36699
36700 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36701 goto clean2;
36702 @@ -4374,7 +4374,7 @@ reinit_after_soft_reset:
36703 * fake ones to scoop up any residual completions.
36704 */
36705 spin_lock_irqsave(&h->lock, flags);
36706 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36707 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36708 spin_unlock_irqrestore(&h->lock, flags);
36709 free_irq(h->intr[h->intr_mode], h);
36710 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36711 @@ -4393,9 +4393,9 @@ reinit_after_soft_reset:
36712 dev_info(&h->pdev->dev, "Board READY.\n");
36713 dev_info(&h->pdev->dev,
36714 "Waiting for stale completions to drain.\n");
36715 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36716 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36717 msleep(10000);
36718 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36719 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36720
36721 rc = controller_reset_failed(h->cfgtable);
36722 if (rc)
36723 @@ -4416,7 +4416,7 @@ reinit_after_soft_reset:
36724 }
36725
36726 /* Turn the interrupts on so we can service requests */
36727 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36728 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36729
36730 hpsa_hba_inquiry(h);
36731 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36732 @@ -4468,7 +4468,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36733 * To write all data in the battery backed cache to disks
36734 */
36735 hpsa_flush_cache(h);
36736 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36737 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36738 free_irq(h->intr[h->intr_mode], h);
36739 #ifdef CONFIG_PCI_MSI
36740 if (h->msix_vector)
36741 @@ -4632,7 +4632,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36742 return;
36743 }
36744 /* Change the access methods to the performant access methods */
36745 - h->access = SA5_performant_access;
36746 + h->access = &SA5_performant_access;
36747 h->transMethod = CFGTBL_Trans_Performant;
36748 }
36749
36750 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36751 index 91edafb..a9b88ec 100644
36752 --- a/drivers/scsi/hpsa.h
36753 +++ b/drivers/scsi/hpsa.h
36754 @@ -73,7 +73,7 @@ struct ctlr_info {
36755 unsigned int msix_vector;
36756 unsigned int msi_vector;
36757 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36758 - struct access_method access;
36759 + struct access_method *access;
36760
36761 /* queue and queue Info */
36762 struct list_head reqQ;
36763 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36764 index f2df059..a3a9930 100644
36765 --- a/drivers/scsi/ips.h
36766 +++ b/drivers/scsi/ips.h
36767 @@ -1027,7 +1027,7 @@ typedef struct {
36768 int (*intr)(struct ips_ha *);
36769 void (*enableint)(struct ips_ha *);
36770 uint32_t (*statupd)(struct ips_ha *);
36771 -} ips_hw_func_t;
36772 +} __no_const ips_hw_func_t;
36773
36774 typedef struct ips_ha {
36775 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36776 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36777 index 9de9db2..1e09660 100644
36778 --- a/drivers/scsi/libfc/fc_exch.c
36779 +++ b/drivers/scsi/libfc/fc_exch.c
36780 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
36781 * all together if not used XXX
36782 */
36783 struct {
36784 - atomic_t no_free_exch;
36785 - atomic_t no_free_exch_xid;
36786 - atomic_t xid_not_found;
36787 - atomic_t xid_busy;
36788 - atomic_t seq_not_found;
36789 - atomic_t non_bls_resp;
36790 + atomic_unchecked_t no_free_exch;
36791 + atomic_unchecked_t no_free_exch_xid;
36792 + atomic_unchecked_t xid_not_found;
36793 + atomic_unchecked_t xid_busy;
36794 + atomic_unchecked_t seq_not_found;
36795 + atomic_unchecked_t non_bls_resp;
36796 } stats;
36797 };
36798
36799 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36800 /* allocate memory for exchange */
36801 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36802 if (!ep) {
36803 - atomic_inc(&mp->stats.no_free_exch);
36804 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36805 goto out;
36806 }
36807 memset(ep, 0, sizeof(*ep));
36808 @@ -780,7 +780,7 @@ out:
36809 return ep;
36810 err:
36811 spin_unlock_bh(&pool->lock);
36812 - atomic_inc(&mp->stats.no_free_exch_xid);
36813 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36814 mempool_free(ep, mp->ep_pool);
36815 return NULL;
36816 }
36817 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36818 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36819 ep = fc_exch_find(mp, xid);
36820 if (!ep) {
36821 - atomic_inc(&mp->stats.xid_not_found);
36822 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36823 reject = FC_RJT_OX_ID;
36824 goto out;
36825 }
36826 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36827 ep = fc_exch_find(mp, xid);
36828 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36829 if (ep) {
36830 - atomic_inc(&mp->stats.xid_busy);
36831 + atomic_inc_unchecked(&mp->stats.xid_busy);
36832 reject = FC_RJT_RX_ID;
36833 goto rel;
36834 }
36835 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36836 }
36837 xid = ep->xid; /* get our XID */
36838 } else if (!ep) {
36839 - atomic_inc(&mp->stats.xid_not_found);
36840 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36841 reject = FC_RJT_RX_ID; /* XID not found */
36842 goto out;
36843 }
36844 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36845 } else {
36846 sp = &ep->seq;
36847 if (sp->id != fh->fh_seq_id) {
36848 - atomic_inc(&mp->stats.seq_not_found);
36849 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36850 if (f_ctl & FC_FC_END_SEQ) {
36851 /*
36852 * Update sequence_id based on incoming last
36853 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36854
36855 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36856 if (!ep) {
36857 - atomic_inc(&mp->stats.xid_not_found);
36858 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36859 goto out;
36860 }
36861 if (ep->esb_stat & ESB_ST_COMPLETE) {
36862 - atomic_inc(&mp->stats.xid_not_found);
36863 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36864 goto rel;
36865 }
36866 if (ep->rxid == FC_XID_UNKNOWN)
36867 ep->rxid = ntohs(fh->fh_rx_id);
36868 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36869 - atomic_inc(&mp->stats.xid_not_found);
36870 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36871 goto rel;
36872 }
36873 if (ep->did != ntoh24(fh->fh_s_id) &&
36874 ep->did != FC_FID_FLOGI) {
36875 - atomic_inc(&mp->stats.xid_not_found);
36876 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36877 goto rel;
36878 }
36879 sof = fr_sof(fp);
36880 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36881 sp->ssb_stat |= SSB_ST_RESP;
36882 sp->id = fh->fh_seq_id;
36883 } else if (sp->id != fh->fh_seq_id) {
36884 - atomic_inc(&mp->stats.seq_not_found);
36885 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36886 goto rel;
36887 }
36888
36889 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36890 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36891
36892 if (!sp)
36893 - atomic_inc(&mp->stats.xid_not_found);
36894 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36895 else
36896 - atomic_inc(&mp->stats.non_bls_resp);
36897 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36898
36899 fc_frame_free(fp);
36900 }
36901 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36902 index db9238f..4378ed2 100644
36903 --- a/drivers/scsi/libsas/sas_ata.c
36904 +++ b/drivers/scsi/libsas/sas_ata.c
36905 @@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
36906 .postreset = ata_std_postreset,
36907 .error_handler = ata_std_error_handler,
36908 .post_internal_cmd = sas_ata_post_internal,
36909 - .qc_defer = ata_std_qc_defer,
36910 + .qc_defer = ata_std_qc_defer,
36911 .qc_prep = ata_noop_qc_prep,
36912 .qc_issue = sas_ata_qc_issue,
36913 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36914 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36915 index bb4c8e0..f33d849 100644
36916 --- a/drivers/scsi/lpfc/lpfc.h
36917 +++ b/drivers/scsi/lpfc/lpfc.h
36918 @@ -425,7 +425,7 @@ struct lpfc_vport {
36919 struct dentry *debug_nodelist;
36920 struct dentry *vport_debugfs_root;
36921 struct lpfc_debugfs_trc *disc_trc;
36922 - atomic_t disc_trc_cnt;
36923 + atomic_unchecked_t disc_trc_cnt;
36924 #endif
36925 uint8_t stat_data_enabled;
36926 uint8_t stat_data_blocked;
36927 @@ -835,8 +835,8 @@ struct lpfc_hba {
36928 struct timer_list fabric_block_timer;
36929 unsigned long bit_flags;
36930 #define FABRIC_COMANDS_BLOCKED 0
36931 - atomic_t num_rsrc_err;
36932 - atomic_t num_cmd_success;
36933 + atomic_unchecked_t num_rsrc_err;
36934 + atomic_unchecked_t num_cmd_success;
36935 unsigned long last_rsrc_error_time;
36936 unsigned long last_ramp_down_time;
36937 unsigned long last_ramp_up_time;
36938 @@ -866,7 +866,7 @@ struct lpfc_hba {
36939
36940 struct dentry *debug_slow_ring_trc;
36941 struct lpfc_debugfs_trc *slow_ring_trc;
36942 - atomic_t slow_ring_trc_cnt;
36943 + atomic_unchecked_t slow_ring_trc_cnt;
36944 /* iDiag debugfs sub-directory */
36945 struct dentry *idiag_root;
36946 struct dentry *idiag_pci_cfg;
36947 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36948 index 2838259..a07cfb5 100644
36949 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36950 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36951 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36952
36953 #include <linux/debugfs.h>
36954
36955 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36956 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36957 static unsigned long lpfc_debugfs_start_time = 0L;
36958
36959 /* iDiag */
36960 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36961 lpfc_debugfs_enable = 0;
36962
36963 len = 0;
36964 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36965 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36966 (lpfc_debugfs_max_disc_trc - 1);
36967 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36968 dtp = vport->disc_trc + i;
36969 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36970 lpfc_debugfs_enable = 0;
36971
36972 len = 0;
36973 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36974 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36975 (lpfc_debugfs_max_slow_ring_trc - 1);
36976 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36977 dtp = phba->slow_ring_trc + i;
36978 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36979 !vport || !vport->disc_trc)
36980 return;
36981
36982 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36983 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36984 (lpfc_debugfs_max_disc_trc - 1);
36985 dtp = vport->disc_trc + index;
36986 dtp->fmt = fmt;
36987 dtp->data1 = data1;
36988 dtp->data2 = data2;
36989 dtp->data3 = data3;
36990 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36991 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36992 dtp->jif = jiffies;
36993 #endif
36994 return;
36995 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36996 !phba || !phba->slow_ring_trc)
36997 return;
36998
36999 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37000 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37001 (lpfc_debugfs_max_slow_ring_trc - 1);
37002 dtp = phba->slow_ring_trc + index;
37003 dtp->fmt = fmt;
37004 dtp->data1 = data1;
37005 dtp->data2 = data2;
37006 dtp->data3 = data3;
37007 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37008 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37009 dtp->jif = jiffies;
37010 #endif
37011 return;
37012 @@ -3986,7 +3986,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37013 "slow_ring buffer\n");
37014 goto debug_failed;
37015 }
37016 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37017 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37018 memset(phba->slow_ring_trc, 0,
37019 (sizeof(struct lpfc_debugfs_trc) *
37020 lpfc_debugfs_max_slow_ring_trc));
37021 @@ -4032,7 +4032,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37022 "buffer\n");
37023 goto debug_failed;
37024 }
37025 - atomic_set(&vport->disc_trc_cnt, 0);
37026 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37027
37028 snprintf(name, sizeof(name), "discovery_trace");
37029 vport->debug_disc_trc =
37030 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37031 index 55bc4fc..a2a109c 100644
37032 --- a/drivers/scsi/lpfc/lpfc_init.c
37033 +++ b/drivers/scsi/lpfc/lpfc_init.c
37034 @@ -10027,8 +10027,10 @@ lpfc_init(void)
37035 printk(LPFC_COPYRIGHT "\n");
37036
37037 if (lpfc_enable_npiv) {
37038 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37039 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37040 + pax_open_kernel();
37041 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37042 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37043 + pax_close_kernel();
37044 }
37045 lpfc_transport_template =
37046 fc_attach_transport(&lpfc_transport_functions);
37047 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37048 index 2e1e54e..1af0a0d 100644
37049 --- a/drivers/scsi/lpfc/lpfc_scsi.c
37050 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
37051 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37052 uint32_t evt_posted;
37053
37054 spin_lock_irqsave(&phba->hbalock, flags);
37055 - atomic_inc(&phba->num_rsrc_err);
37056 + atomic_inc_unchecked(&phba->num_rsrc_err);
37057 phba->last_rsrc_error_time = jiffies;
37058
37059 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37060 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37061 unsigned long flags;
37062 struct lpfc_hba *phba = vport->phba;
37063 uint32_t evt_posted;
37064 - atomic_inc(&phba->num_cmd_success);
37065 + atomic_inc_unchecked(&phba->num_cmd_success);
37066
37067 if (vport->cfg_lun_queue_depth <= queue_depth)
37068 return;
37069 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37070 unsigned long num_rsrc_err, num_cmd_success;
37071 int i;
37072
37073 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37074 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37075 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37076 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37077
37078 vports = lpfc_create_vport_work_array(phba);
37079 if (vports != NULL)
37080 @@ -411,8 +411,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37081 }
37082 }
37083 lpfc_destroy_vport_work_array(phba, vports);
37084 - atomic_set(&phba->num_rsrc_err, 0);
37085 - atomic_set(&phba->num_cmd_success, 0);
37086 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37087 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37088 }
37089
37090 /**
37091 @@ -446,8 +446,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37092 }
37093 }
37094 lpfc_destroy_vport_work_array(phba, vports);
37095 - atomic_set(&phba->num_rsrc_err, 0);
37096 - atomic_set(&phba->num_cmd_success, 0);
37097 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37098 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37099 }
37100
37101 /**
37102 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37103 index 5163edb..7b142bc 100644
37104 --- a/drivers/scsi/pmcraid.c
37105 +++ b/drivers/scsi/pmcraid.c
37106 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37107 res->scsi_dev = scsi_dev;
37108 scsi_dev->hostdata = res;
37109 res->change_detected = 0;
37110 - atomic_set(&res->read_failures, 0);
37111 - atomic_set(&res->write_failures, 0);
37112 + atomic_set_unchecked(&res->read_failures, 0);
37113 + atomic_set_unchecked(&res->write_failures, 0);
37114 rc = 0;
37115 }
37116 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37117 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37118
37119 /* If this was a SCSI read/write command keep count of errors */
37120 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37121 - atomic_inc(&res->read_failures);
37122 + atomic_inc_unchecked(&res->read_failures);
37123 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37124 - atomic_inc(&res->write_failures);
37125 + atomic_inc_unchecked(&res->write_failures);
37126
37127 if (!RES_IS_GSCSI(res->cfg_entry) &&
37128 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37129 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37130 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37131 * hrrq_id assigned here in queuecommand
37132 */
37133 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37134 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37135 pinstance->num_hrrq;
37136 cmd->cmd_done = pmcraid_io_done;
37137
37138 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37139 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37140 * hrrq_id assigned here in queuecommand
37141 */
37142 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37143 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37144 pinstance->num_hrrq;
37145
37146 if (request_size) {
37147 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37148
37149 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37150 /* add resources only after host is added into system */
37151 - if (!atomic_read(&pinstance->expose_resources))
37152 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37153 return;
37154
37155 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37156 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37157 init_waitqueue_head(&pinstance->reset_wait_q);
37158
37159 atomic_set(&pinstance->outstanding_cmds, 0);
37160 - atomic_set(&pinstance->last_message_id, 0);
37161 - atomic_set(&pinstance->expose_resources, 0);
37162 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37163 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37164
37165 INIT_LIST_HEAD(&pinstance->free_res_q);
37166 INIT_LIST_HEAD(&pinstance->used_res_q);
37167 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37168 /* Schedule worker thread to handle CCN and take care of adding and
37169 * removing devices to OS
37170 */
37171 - atomic_set(&pinstance->expose_resources, 1);
37172 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37173 schedule_work(&pinstance->worker_q);
37174 return rc;
37175
37176 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37177 index ca496c7..9c791d5 100644
37178 --- a/drivers/scsi/pmcraid.h
37179 +++ b/drivers/scsi/pmcraid.h
37180 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37181 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37182
37183 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37184 - atomic_t last_message_id;
37185 + atomic_unchecked_t last_message_id;
37186
37187 /* configuration table */
37188 struct pmcraid_config_table *cfg_table;
37189 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37190 atomic_t outstanding_cmds;
37191
37192 /* should add/delete resources to mid-layer now ?*/
37193 - atomic_t expose_resources;
37194 + atomic_unchecked_t expose_resources;
37195
37196
37197
37198 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37199 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37200 };
37201 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37202 - atomic_t read_failures; /* count of failed READ commands */
37203 - atomic_t write_failures; /* count of failed WRITE commands */
37204 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37205 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37206
37207 /* To indicate add/delete/modify during CCN */
37208 u8 change_detected;
37209 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37210 index fcf052c..a8025a4 100644
37211 --- a/drivers/scsi/qla2xxx/qla_def.h
37212 +++ b/drivers/scsi/qla2xxx/qla_def.h
37213 @@ -2244,7 +2244,7 @@ struct isp_operations {
37214 int (*get_flash_version) (struct scsi_qla_host *, void *);
37215 int (*start_scsi) (srb_t *);
37216 int (*abort_isp) (struct scsi_qla_host *);
37217 -};
37218 +} __no_const;
37219
37220 /* MSI-X Support *************************************************************/
37221
37222 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37223 index fd5edc6..4906148 100644
37224 --- a/drivers/scsi/qla4xxx/ql4_def.h
37225 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37226 @@ -258,7 +258,7 @@ struct ddb_entry {
37227 * (4000 only) */
37228 atomic_t relogin_timer; /* Max Time to wait for
37229 * relogin to complete */
37230 - atomic_t relogin_retry_count; /* Num of times relogin has been
37231 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37232 * retried */
37233 uint32_t default_time2wait; /* Default Min time between
37234 * relogins (+aens) */
37235 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37236 index 4169c8b..a8b896b 100644
37237 --- a/drivers/scsi/qla4xxx/ql4_os.c
37238 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37239 @@ -2104,12 +2104,12 @@ void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37240 */
37241 if (!iscsi_is_session_online(cls_sess)) {
37242 /* Reset retry relogin timer */
37243 - atomic_inc(&ddb_entry->relogin_retry_count);
37244 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37245 DEBUG2(ql4_printk(KERN_INFO, ha,
37246 "%s: index[%d] relogin timed out-retrying"
37247 " relogin (%d), retry (%d)\n", __func__,
37248 ddb_entry->fw_ddb_index,
37249 - atomic_read(&ddb_entry->relogin_retry_count),
37250 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37251 ddb_entry->default_time2wait + 4));
37252 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37253 atomic_set(&ddb_entry->retry_relogin_timer,
37254 @@ -3835,7 +3835,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37255
37256 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37257 atomic_set(&ddb_entry->relogin_timer, 0);
37258 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37259 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37260
37261 ddb_entry->default_relogin_timeout =
37262 le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37263 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37264 index 2aeb2e9..46e3925 100644
37265 --- a/drivers/scsi/scsi.c
37266 +++ b/drivers/scsi/scsi.c
37267 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37268 unsigned long timeout;
37269 int rtn = 0;
37270
37271 - atomic_inc(&cmd->device->iorequest_cnt);
37272 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37273
37274 /* check if the device is still usable */
37275 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37276 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37277 index f85cfa6..a57c9e8 100644
37278 --- a/drivers/scsi/scsi_lib.c
37279 +++ b/drivers/scsi/scsi_lib.c
37280 @@ -1416,7 +1416,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37281 shost = sdev->host;
37282 scsi_init_cmd_errh(cmd);
37283 cmd->result = DID_NO_CONNECT << 16;
37284 - atomic_inc(&cmd->device->iorequest_cnt);
37285 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37286
37287 /*
37288 * SCSI request completion path will do scsi_device_unbusy(),
37289 @@ -1442,9 +1442,9 @@ static void scsi_softirq_done(struct request *rq)
37290
37291 INIT_LIST_HEAD(&cmd->eh_entry);
37292
37293 - atomic_inc(&cmd->device->iodone_cnt);
37294 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37295 if (cmd->result)
37296 - atomic_inc(&cmd->device->ioerr_cnt);
37297 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37298
37299 disposition = scsi_decide_disposition(cmd);
37300 if (disposition != SUCCESS &&
37301 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37302 index 04c2a27..9d8bd66 100644
37303 --- a/drivers/scsi/scsi_sysfs.c
37304 +++ b/drivers/scsi/scsi_sysfs.c
37305 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37306 char *buf) \
37307 { \
37308 struct scsi_device *sdev = to_scsi_device(dev); \
37309 - unsigned long long count = atomic_read(&sdev->field); \
37310 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37311 return snprintf(buf, 20, "0x%llx\n", count); \
37312 } \
37313 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37314 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37315 index 84a1fdf..693b0d6 100644
37316 --- a/drivers/scsi/scsi_tgt_lib.c
37317 +++ b/drivers/scsi/scsi_tgt_lib.c
37318 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37319 int err;
37320
37321 dprintk("%lx %u\n", uaddr, len);
37322 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37323 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37324 if (err) {
37325 /*
37326 * TODO: need to fixup sg_tablesize, max_segment_size,
37327 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37328 index 1b21491..1b7f60e 100644
37329 --- a/drivers/scsi/scsi_transport_fc.c
37330 +++ b/drivers/scsi/scsi_transport_fc.c
37331 @@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37332 * Netlink Infrastructure
37333 */
37334
37335 -static atomic_t fc_event_seq;
37336 +static atomic_unchecked_t fc_event_seq;
37337
37338 /**
37339 * fc_get_event_number - Obtain the next sequential FC event number
37340 @@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
37341 u32
37342 fc_get_event_number(void)
37343 {
37344 - return atomic_add_return(1, &fc_event_seq);
37345 + return atomic_add_return_unchecked(1, &fc_event_seq);
37346 }
37347 EXPORT_SYMBOL(fc_get_event_number);
37348
37349 @@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
37350 {
37351 int error;
37352
37353 - atomic_set(&fc_event_seq, 0);
37354 + atomic_set_unchecked(&fc_event_seq, 0);
37355
37356 error = transport_class_register(&fc_host_class);
37357 if (error)
37358 @@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37359 char *cp;
37360
37361 *val = simple_strtoul(buf, &cp, 0);
37362 - if ((*cp && (*cp != '\n')) || (*val < 0))
37363 + if (*cp && (*cp != '\n'))
37364 return -EINVAL;
37365 /*
37366 * Check for overflow; dev_loss_tmo is u32
37367 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37368 index 96029e6..4d77fa0 100644
37369 --- a/drivers/scsi/scsi_transport_iscsi.c
37370 +++ b/drivers/scsi/scsi_transport_iscsi.c
37371 @@ -79,7 +79,7 @@ struct iscsi_internal {
37372 struct transport_container session_cont;
37373 };
37374
37375 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37376 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37377 static struct workqueue_struct *iscsi_eh_timer_workq;
37378
37379 static DEFINE_IDA(iscsi_sess_ida);
37380 @@ -1062,7 +1062,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37381 int err;
37382
37383 ihost = shost->shost_data;
37384 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37385 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37386
37387 if (target_id == ISCSI_MAX_TARGET) {
37388 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37389 @@ -2663,7 +2663,7 @@ static __init int iscsi_transport_init(void)
37390 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37391 ISCSI_TRANSPORT_VERSION);
37392
37393 - atomic_set(&iscsi_session_nr, 0);
37394 + atomic_set_unchecked(&iscsi_session_nr, 0);
37395
37396 err = class_register(&iscsi_transport_class);
37397 if (err)
37398 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37399 index 21a045e..ec89e03 100644
37400 --- a/drivers/scsi/scsi_transport_srp.c
37401 +++ b/drivers/scsi/scsi_transport_srp.c
37402 @@ -33,7 +33,7 @@
37403 #include "scsi_transport_srp_internal.h"
37404
37405 struct srp_host_attrs {
37406 - atomic_t next_port_id;
37407 + atomic_unchecked_t next_port_id;
37408 };
37409 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37410
37411 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37412 struct Scsi_Host *shost = dev_to_shost(dev);
37413 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37414
37415 - atomic_set(&srp_host->next_port_id, 0);
37416 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37417 return 0;
37418 }
37419
37420 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37421 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37422 rport->roles = ids->roles;
37423
37424 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37425 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37426 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37427
37428 transport_setup_device(&rport->dev);
37429 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37430 index 441a1c5..07cece7 100644
37431 --- a/drivers/scsi/sg.c
37432 +++ b/drivers/scsi/sg.c
37433 @@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37434 sdp->disk->disk_name,
37435 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37436 NULL,
37437 - (char *)arg);
37438 + (char __user *)arg);
37439 case BLKTRACESTART:
37440 return blk_trace_startstop(sdp->device->request_queue, 1);
37441 case BLKTRACESTOP:
37442 @@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
37443 const struct file_operations * fops;
37444 };
37445
37446 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
37447 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
37448 {"allow_dio", &adio_fops},
37449 {"debug", &debug_fops},
37450 {"def_reserved_size", &dressz_fops},
37451 @@ -2327,7 +2327,7 @@ sg_proc_init(void)
37452 {
37453 int k, mask;
37454 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
37455 - struct sg_proc_leaf * leaf;
37456 + const struct sg_proc_leaf * leaf;
37457
37458 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
37459 if (!sg_proc_sgp)
37460 diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
37461 index f64250e..1ee3049 100644
37462 --- a/drivers/spi/spi-dw-pci.c
37463 +++ b/drivers/spi/spi-dw-pci.c
37464 @@ -149,7 +149,7 @@ static int spi_resume(struct pci_dev *pdev)
37465 #define spi_resume NULL
37466 #endif
37467
37468 -static const struct pci_device_id pci_ids[] __devinitdata = {
37469 +static const struct pci_device_id pci_ids[] __devinitconst = {
37470 /* Intel MID platform SPI controller 0 */
37471 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
37472 {},
37473 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37474 index 77eae99..b7cdcc9 100644
37475 --- a/drivers/spi/spi.c
37476 +++ b/drivers/spi/spi.c
37477 @@ -1024,7 +1024,7 @@ int spi_bus_unlock(struct spi_master *master)
37478 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37479
37480 /* portable code must never pass more than 32 bytes */
37481 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37482 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37483
37484 static u8 *buf;
37485
37486 diff --git a/drivers/staging/gma500/power.c b/drivers/staging/gma500/power.c
37487 index 436fe97..4082570 100644
37488 --- a/drivers/staging/gma500/power.c
37489 +++ b/drivers/staging/gma500/power.c
37490 @@ -266,7 +266,7 @@ bool gma_power_begin(struct drm_device *dev, bool force_on)
37491 ret = gma_resume_pci(dev->pdev);
37492 if (ret == 0) {
37493 /* FIXME: we want to defer this for Medfield/Oaktrail */
37494 - gma_resume_display(dev);
37495 + gma_resume_display(dev->pdev);
37496 psb_irq_preinstall(dev);
37497 psb_irq_postinstall(dev);
37498 pm_runtime_get(&dev->pdev->dev);
37499 diff --git a/drivers/staging/hv/rndis_filter.c b/drivers/staging/hv/rndis_filter.c
37500 index bafccb3..e3ac78d 100644
37501 --- a/drivers/staging/hv/rndis_filter.c
37502 +++ b/drivers/staging/hv/rndis_filter.c
37503 @@ -42,7 +42,7 @@ struct rndis_device {
37504
37505 enum rndis_device_state state;
37506 bool link_state;
37507 - atomic_t new_req_id;
37508 + atomic_unchecked_t new_req_id;
37509
37510 spinlock_t request_lock;
37511 struct list_head req_list;
37512 @@ -116,7 +116,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
37513 * template
37514 */
37515 set = &rndis_msg->msg.set_req;
37516 - set->req_id = atomic_inc_return(&dev->new_req_id);
37517 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
37518
37519 /* Add to the request list */
37520 spin_lock_irqsave(&dev->request_lock, flags);
37521 @@ -646,7 +646,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
37522
37523 /* Setup the rndis set */
37524 halt = &request->request_msg.msg.halt_req;
37525 - halt->req_id = atomic_inc_return(&dev->new_req_id);
37526 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
37527
37528 /* Ignore return since this msg is optional. */
37529 rndis_filter_send_request(dev, request);
37530 diff --git a/drivers/staging/iio/buffer_generic.h b/drivers/staging/iio/buffer_generic.h
37531 index 9e8f010..af9efb56 100644
37532 --- a/drivers/staging/iio/buffer_generic.h
37533 +++ b/drivers/staging/iio/buffer_generic.h
37534 @@ -64,7 +64,7 @@ struct iio_buffer_access_funcs {
37535
37536 int (*is_enabled)(struct iio_buffer *buffer);
37537 int (*enable)(struct iio_buffer *buffer);
37538 -};
37539 +} __no_const;
37540
37541 /**
37542 * struct iio_buffer_setup_ops - buffer setup related callbacks
37543 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37544 index 8b307b4..a97ac91 100644
37545 --- a/drivers/staging/octeon/ethernet-rx.c
37546 +++ b/drivers/staging/octeon/ethernet-rx.c
37547 @@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37548 /* Increment RX stats for virtual ports */
37549 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37550 #ifdef CONFIG_64BIT
37551 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37552 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37553 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37554 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37555 #else
37556 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37557 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37558 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37559 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37560 #endif
37561 }
37562 netif_receive_skb(skb);
37563 @@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37564 dev->name);
37565 */
37566 #ifdef CONFIG_64BIT
37567 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37568 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37569 #else
37570 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37571 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37572 #endif
37573 dev_kfree_skb_irq(skb);
37574 }
37575 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37576 index 076f866..2308070 100644
37577 --- a/drivers/staging/octeon/ethernet.c
37578 +++ b/drivers/staging/octeon/ethernet.c
37579 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37580 * since the RX tasklet also increments it.
37581 */
37582 #ifdef CONFIG_64BIT
37583 - atomic64_add(rx_status.dropped_packets,
37584 - (atomic64_t *)&priv->stats.rx_dropped);
37585 + atomic64_add_unchecked(rx_status.dropped_packets,
37586 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37587 #else
37588 - atomic_add(rx_status.dropped_packets,
37589 - (atomic_t *)&priv->stats.rx_dropped);
37590 + atomic_add_unchecked(rx_status.dropped_packets,
37591 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37592 #endif
37593 }
37594
37595 diff --git a/drivers/staging/pohmelfs/inode.c b/drivers/staging/pohmelfs/inode.c
37596 index 7a19555..466456d 100644
37597 --- a/drivers/staging/pohmelfs/inode.c
37598 +++ b/drivers/staging/pohmelfs/inode.c
37599 @@ -1861,7 +1861,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
37600 mutex_init(&psb->mcache_lock);
37601 psb->mcache_root = RB_ROOT;
37602 psb->mcache_timeout = msecs_to_jiffies(5000);
37603 - atomic_long_set(&psb->mcache_gen, 0);
37604 + atomic_long_set_unchecked(&psb->mcache_gen, 0);
37605
37606 psb->trans_max_pages = 100;
37607
37608 @@ -1876,7 +1876,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
37609 INIT_LIST_HEAD(&psb->crypto_ready_list);
37610 INIT_LIST_HEAD(&psb->crypto_active_list);
37611
37612 - atomic_set(&psb->trans_gen, 1);
37613 + atomic_set_unchecked(&psb->trans_gen, 1);
37614 atomic_long_set(&psb->total_inodes, 0);
37615
37616 mutex_init(&psb->state_lock);
37617 diff --git a/drivers/staging/pohmelfs/mcache.c b/drivers/staging/pohmelfs/mcache.c
37618 index e22665c..a2a9390 100644
37619 --- a/drivers/staging/pohmelfs/mcache.c
37620 +++ b/drivers/staging/pohmelfs/mcache.c
37621 @@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_alloc(struct pohmelfs_sb *psb, u64 start
37622 m->data = data;
37623 m->start = start;
37624 m->size = size;
37625 - m->gen = atomic_long_inc_return(&psb->mcache_gen);
37626 + m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
37627
37628 mutex_lock(&psb->mcache_lock);
37629 err = pohmelfs_mcache_insert(psb, m);
37630 diff --git a/drivers/staging/pohmelfs/netfs.h b/drivers/staging/pohmelfs/netfs.h
37631 index 985b6b7..7699e05 100644
37632 --- a/drivers/staging/pohmelfs/netfs.h
37633 +++ b/drivers/staging/pohmelfs/netfs.h
37634 @@ -571,14 +571,14 @@ struct pohmelfs_config;
37635 struct pohmelfs_sb {
37636 struct rb_root mcache_root;
37637 struct mutex mcache_lock;
37638 - atomic_long_t mcache_gen;
37639 + atomic_long_unchecked_t mcache_gen;
37640 unsigned long mcache_timeout;
37641
37642 unsigned int idx;
37643
37644 unsigned int trans_retries;
37645
37646 - atomic_t trans_gen;
37647 + atomic_unchecked_t trans_gen;
37648
37649 unsigned int crypto_attached_size;
37650 unsigned int crypto_align_size;
37651 diff --git a/drivers/staging/pohmelfs/trans.c b/drivers/staging/pohmelfs/trans.c
37652 index 06c1a74..866eebc 100644
37653 --- a/drivers/staging/pohmelfs/trans.c
37654 +++ b/drivers/staging/pohmelfs/trans.c
37655 @@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_trans *t, struct pohmelfs_sb *psb)
37656 int err;
37657 struct netfs_cmd *cmd = t->iovec.iov_base;
37658
37659 - t->gen = atomic_inc_return(&psb->trans_gen);
37660 + t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
37661
37662 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
37663 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
37664 diff --git a/drivers/staging/rtl8192e/rtllib_module.c b/drivers/staging/rtl8192e/rtllib_module.c
37665 index c36a140..dd27fda 100644
37666 --- a/drivers/staging/rtl8192e/rtllib_module.c
37667 +++ b/drivers/staging/rtl8192e/rtllib_module.c
37668 @@ -228,6 +228,8 @@ static int show_debug_level(char *page, char **start, off_t offset,
37669 }
37670
37671 static int store_debug_level(struct file *file, const char __user *buffer,
37672 + unsigned long count, void *data) __size_overflow(3);
37673 +static int store_debug_level(struct file *file, const char __user *buffer,
37674 unsigned long count, void *data)
37675 {
37676 char buf[] = "0x00000000";
37677 diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
37678 index e3d47bc..85f4d0d 100644
37679 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
37680 +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
37681 @@ -250,6 +250,8 @@ static int show_debug_level(char *page, char **start, off_t offset,
37682 }
37683
37684 static int store_debug_level(struct file *file, const char *buffer,
37685 + unsigned long count, void *data) __size_overflow(3);
37686 +static int store_debug_level(struct file *file, const char *buffer,
37687 unsigned long count, void *data)
37688 {
37689 char buf[] = "0x00000000";
37690 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37691 index 86308a0..feaa925 100644
37692 --- a/drivers/staging/rtl8712/rtl871x_io.h
37693 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37694 @@ -108,7 +108,7 @@ struct _io_ops {
37695 u8 *pmem);
37696 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37697 u8 *pmem);
37698 -};
37699 +} __no_const;
37700
37701 struct io_req {
37702 struct list_head list;
37703 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37704 index c7b5e8b..783d6cb 100644
37705 --- a/drivers/staging/sbe-2t3e3/netdev.c
37706 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37707 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37708 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37709
37710 if (rlen)
37711 - if (copy_to_user(data, &resp, rlen))
37712 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37713 return -EFAULT;
37714
37715 return 0;
37716 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37717 index be21617..0954e45 100644
37718 --- a/drivers/staging/usbip/usbip_common.h
37719 +++ b/drivers/staging/usbip/usbip_common.h
37720 @@ -289,7 +289,7 @@ struct usbip_device {
37721 void (*shutdown)(struct usbip_device *);
37722 void (*reset)(struct usbip_device *);
37723 void (*unusable)(struct usbip_device *);
37724 - } eh_ops;
37725 + } __no_const eh_ops;
37726 };
37727
37728 #if 0
37729 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37730 index 88b3298..3783eee 100644
37731 --- a/drivers/staging/usbip/vhci.h
37732 +++ b/drivers/staging/usbip/vhci.h
37733 @@ -88,7 +88,7 @@ struct vhci_hcd {
37734 unsigned resuming:1;
37735 unsigned long re_timeout;
37736
37737 - atomic_t seqnum;
37738 + atomic_unchecked_t seqnum;
37739
37740 /*
37741 * NOTE:
37742 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37743 index 2ee97e2..0420b86 100644
37744 --- a/drivers/staging/usbip/vhci_hcd.c
37745 +++ b/drivers/staging/usbip/vhci_hcd.c
37746 @@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
37747 return;
37748 }
37749
37750 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37751 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37752 if (priv->seqnum == 0xffff)
37753 dev_info(&urb->dev->dev, "seqnum max\n");
37754
37755 @@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37756 return -ENOMEM;
37757 }
37758
37759 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37760 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37761 if (unlink->seqnum == 0xffff)
37762 pr_info("seqnum max\n");
37763
37764 @@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
37765 vdev->rhport = rhport;
37766 }
37767
37768 - atomic_set(&vhci->seqnum, 0);
37769 + atomic_set_unchecked(&vhci->seqnum, 0);
37770 spin_lock_init(&vhci->lock);
37771
37772 hcd->power_budget = 0; /* no limit */
37773 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37774 index 3872b8c..fe6d2f4 100644
37775 --- a/drivers/staging/usbip/vhci_rx.c
37776 +++ b/drivers/staging/usbip/vhci_rx.c
37777 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37778 if (!urb) {
37779 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37780 pr_info("max seqnum %d\n",
37781 - atomic_read(&the_controller->seqnum));
37782 + atomic_read_unchecked(&the_controller->seqnum));
37783 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37784 return;
37785 }
37786 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37787 index 7735027..30eed13 100644
37788 --- a/drivers/staging/vt6655/hostap.c
37789 +++ b/drivers/staging/vt6655/hostap.c
37790 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37791 *
37792 */
37793
37794 +static net_device_ops_no_const apdev_netdev_ops;
37795 +
37796 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37797 {
37798 PSDevice apdev_priv;
37799 struct net_device *dev = pDevice->dev;
37800 int ret;
37801 - const struct net_device_ops apdev_netdev_ops = {
37802 - .ndo_start_xmit = pDevice->tx_80211,
37803 - };
37804
37805 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37806
37807 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37808 *apdev_priv = *pDevice;
37809 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37810
37811 + /* only half broken now */
37812 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37813 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37814
37815 pDevice->apdev->type = ARPHRD_IEEE80211;
37816 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37817 index 51b5adf..098e320 100644
37818 --- a/drivers/staging/vt6656/hostap.c
37819 +++ b/drivers/staging/vt6656/hostap.c
37820 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37821 *
37822 */
37823
37824 +static net_device_ops_no_const apdev_netdev_ops;
37825 +
37826 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37827 {
37828 PSDevice apdev_priv;
37829 struct net_device *dev = pDevice->dev;
37830 int ret;
37831 - const struct net_device_ops apdev_netdev_ops = {
37832 - .ndo_start_xmit = pDevice->tx_80211,
37833 - };
37834
37835 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37836
37837 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37838 *apdev_priv = *pDevice;
37839 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37840
37841 + /* only half broken now */
37842 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37843 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37844
37845 pDevice->apdev->type = ARPHRD_IEEE80211;
37846 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37847 index 7843dfd..3db105f 100644
37848 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37849 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37850 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37851
37852 struct usbctlx_completor {
37853 int (*complete) (struct usbctlx_completor *);
37854 -};
37855 +} __no_const;
37856
37857 static int
37858 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37859 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37860 index 1ca66ea..76f1343 100644
37861 --- a/drivers/staging/zcache/tmem.c
37862 +++ b/drivers/staging/zcache/tmem.c
37863 @@ -39,7 +39,7 @@
37864 * A tmem host implementation must use this function to register callbacks
37865 * for memory allocation.
37866 */
37867 -static struct tmem_hostops tmem_hostops;
37868 +static tmem_hostops_no_const tmem_hostops;
37869
37870 static void tmem_objnode_tree_init(void);
37871
37872 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37873 * A tmem host implementation must use this function to register
37874 * callbacks for a page-accessible memory (PAM) implementation
37875 */
37876 -static struct tmem_pamops tmem_pamops;
37877 +static tmem_pamops_no_const tmem_pamops;
37878
37879 void tmem_register_pamops(struct tmem_pamops *m)
37880 {
37881 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37882 index ed147c4..94fc3c6 100644
37883 --- a/drivers/staging/zcache/tmem.h
37884 +++ b/drivers/staging/zcache/tmem.h
37885 @@ -180,6 +180,7 @@ struct tmem_pamops {
37886 void (*new_obj)(struct tmem_obj *);
37887 int (*replace_in_obj)(void *, struct tmem_obj *);
37888 };
37889 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37890 extern void tmem_register_pamops(struct tmem_pamops *m);
37891
37892 /* memory allocation methods provided by the host implementation */
37893 @@ -189,6 +190,7 @@ struct tmem_hostops {
37894 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37895 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37896 };
37897 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37898 extern void tmem_register_hostops(struct tmem_hostops *m);
37899
37900 /* core tmem accessor functions */
37901 diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
37902 index 03d3528..6bbe82f 100644
37903 --- a/drivers/target/iscsi/iscsi_target.c
37904 +++ b/drivers/target/iscsi/iscsi_target.c
37905 @@ -1364,7 +1364,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
37906 * outstanding_r2ts reaches zero, go ahead and send the delayed
37907 * TASK_ABORTED status.
37908 */
37909 - if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
37910 + if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
37911 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
37912 if (--cmd->outstanding_r2ts < 1) {
37913 iscsit_stop_dataout_timer(cmd);
37914 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
37915 index 6845228..df77141 100644
37916 --- a/drivers/target/target_core_tmr.c
37917 +++ b/drivers/target/target_core_tmr.c
37918 @@ -250,7 +250,7 @@ static void core_tmr_drain_task_list(
37919 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
37920 cmd->t_task_list_num,
37921 atomic_read(&cmd->t_task_cdbs_left),
37922 - atomic_read(&cmd->t_task_cdbs_sent),
37923 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37924 atomic_read(&cmd->t_transport_active),
37925 atomic_read(&cmd->t_transport_stop),
37926 atomic_read(&cmd->t_transport_sent));
37927 @@ -281,7 +281,7 @@ static void core_tmr_drain_task_list(
37928 pr_debug("LUN_RESET: got t_transport_active = 1 for"
37929 " task: %p, t_fe_count: %d dev: %p\n", task,
37930 fe_count, dev);
37931 - atomic_set(&cmd->t_transport_aborted, 1);
37932 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37933 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37934
37935 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37936 @@ -289,7 +289,7 @@ static void core_tmr_drain_task_list(
37937 }
37938 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
37939 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
37940 - atomic_set(&cmd->t_transport_aborted, 1);
37941 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37942 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37943
37944 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37945 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37946 index cdb774b..8753593 100644
37947 --- a/drivers/target/target_core_transport.c
37948 +++ b/drivers/target/target_core_transport.c
37949 @@ -1343,7 +1343,7 @@ struct se_device *transport_add_device_to_core_hba(
37950
37951 dev->queue_depth = dev_limits->queue_depth;
37952 atomic_set(&dev->depth_left, dev->queue_depth);
37953 - atomic_set(&dev->dev_ordered_id, 0);
37954 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37955
37956 se_dev_set_default_attribs(dev, dev_limits);
37957
37958 @@ -1530,7 +1530,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37959 * Used to determine when ORDERED commands should go from
37960 * Dormant to Active status.
37961 */
37962 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37963 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37964 smp_mb__after_atomic_inc();
37965 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37966 cmd->se_ordered_id, cmd->sam_task_attr,
37967 @@ -1800,7 +1800,7 @@ static void transport_generic_request_failure(struct se_cmd *cmd)
37968 " t_transport_active: %d t_transport_stop: %d"
37969 " t_transport_sent: %d\n", cmd->t_task_list_num,
37970 atomic_read(&cmd->t_task_cdbs_left),
37971 - atomic_read(&cmd->t_task_cdbs_sent),
37972 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37973 atomic_read(&cmd->t_task_cdbs_ex_left),
37974 atomic_read(&cmd->t_transport_active),
37975 atomic_read(&cmd->t_transport_stop),
37976 @@ -2089,9 +2089,9 @@ check_depth:
37977
37978 spin_lock_irqsave(&cmd->t_state_lock, flags);
37979 task->task_flags |= (TF_ACTIVE | TF_SENT);
37980 - atomic_inc(&cmd->t_task_cdbs_sent);
37981 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
37982
37983 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
37984 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
37985 cmd->t_task_list_num)
37986 atomic_set(&cmd->t_transport_sent, 1);
37987
37988 @@ -4297,7 +4297,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
37989 atomic_set(&cmd->transport_lun_stop, 0);
37990 }
37991 if (!atomic_read(&cmd->t_transport_active) ||
37992 - atomic_read(&cmd->t_transport_aborted)) {
37993 + atomic_read_unchecked(&cmd->t_transport_aborted)) {
37994 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37995 return false;
37996 }
37997 @@ -4546,7 +4546,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
37998 {
37999 int ret = 0;
38000
38001 - if (atomic_read(&cmd->t_transport_aborted) != 0) {
38002 + if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
38003 if (!send_status ||
38004 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
38005 return 1;
38006 @@ -4583,7 +4583,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
38007 */
38008 if (cmd->data_direction == DMA_TO_DEVICE) {
38009 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
38010 - atomic_inc(&cmd->t_transport_aborted);
38011 + atomic_inc_unchecked(&cmd->t_transport_aborted);
38012 smp_mb__after_atomic_inc();
38013 }
38014 }
38015 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
38016 index b9040be..e3f5aab 100644
38017 --- a/drivers/tty/hvc/hvcs.c
38018 +++ b/drivers/tty/hvc/hvcs.c
38019 @@ -83,6 +83,7 @@
38020 #include <asm/hvcserver.h>
38021 #include <asm/uaccess.h>
38022 #include <asm/vio.h>
38023 +#include <asm/local.h>
38024
38025 /*
38026 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
38027 @@ -270,7 +271,7 @@ struct hvcs_struct {
38028 unsigned int index;
38029
38030 struct tty_struct *tty;
38031 - int open_count;
38032 + local_t open_count;
38033
38034 /*
38035 * Used to tell the driver kernel_thread what operations need to take
38036 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
38037
38038 spin_lock_irqsave(&hvcsd->lock, flags);
38039
38040 - if (hvcsd->open_count > 0) {
38041 + if (local_read(&hvcsd->open_count) > 0) {
38042 spin_unlock_irqrestore(&hvcsd->lock, flags);
38043 printk(KERN_INFO "HVCS: vterm state unchanged. "
38044 "The hvcs device node is still in use.\n");
38045 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
38046 if ((retval = hvcs_partner_connect(hvcsd)))
38047 goto error_release;
38048
38049 - hvcsd->open_count = 1;
38050 + local_set(&hvcsd->open_count, 1);
38051 hvcsd->tty = tty;
38052 tty->driver_data = hvcsd;
38053
38054 @@ -1179,7 +1180,7 @@ fast_open:
38055
38056 spin_lock_irqsave(&hvcsd->lock, flags);
38057 kref_get(&hvcsd->kref);
38058 - hvcsd->open_count++;
38059 + local_inc(&hvcsd->open_count);
38060 hvcsd->todo_mask |= HVCS_SCHED_READ;
38061 spin_unlock_irqrestore(&hvcsd->lock, flags);
38062
38063 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38064 hvcsd = tty->driver_data;
38065
38066 spin_lock_irqsave(&hvcsd->lock, flags);
38067 - if (--hvcsd->open_count == 0) {
38068 + if (local_dec_and_test(&hvcsd->open_count)) {
38069
38070 vio_disable_interrupts(hvcsd->vdev);
38071
38072 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38073 free_irq(irq, hvcsd);
38074 kref_put(&hvcsd->kref, destroy_hvcs_struct);
38075 return;
38076 - } else if (hvcsd->open_count < 0) {
38077 + } else if (local_read(&hvcsd->open_count) < 0) {
38078 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
38079 " is missmanaged.\n",
38080 - hvcsd->vdev->unit_address, hvcsd->open_count);
38081 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
38082 }
38083
38084 spin_unlock_irqrestore(&hvcsd->lock, flags);
38085 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38086
38087 spin_lock_irqsave(&hvcsd->lock, flags);
38088 /* Preserve this so that we know how many kref refs to put */
38089 - temp_open_count = hvcsd->open_count;
38090 + temp_open_count = local_read(&hvcsd->open_count);
38091
38092 /*
38093 * Don't kref put inside the spinlock because the destruction
38094 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38095 hvcsd->tty->driver_data = NULL;
38096 hvcsd->tty = NULL;
38097
38098 - hvcsd->open_count = 0;
38099 + local_set(&hvcsd->open_count, 0);
38100
38101 /* This will drop any buffered data on the floor which is OK in a hangup
38102 * scenario. */
38103 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
38104 * the middle of a write operation? This is a crummy place to do this
38105 * but we want to keep it all in the spinlock.
38106 */
38107 - if (hvcsd->open_count <= 0) {
38108 + if (local_read(&hvcsd->open_count) <= 0) {
38109 spin_unlock_irqrestore(&hvcsd->lock, flags);
38110 return -ENODEV;
38111 }
38112 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38113 {
38114 struct hvcs_struct *hvcsd = tty->driver_data;
38115
38116 - if (!hvcsd || hvcsd->open_count <= 0)
38117 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
38118 return 0;
38119
38120 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38121 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38122 index ef92869..f4ebd88 100644
38123 --- a/drivers/tty/ipwireless/tty.c
38124 +++ b/drivers/tty/ipwireless/tty.c
38125 @@ -29,6 +29,7 @@
38126 #include <linux/tty_driver.h>
38127 #include <linux/tty_flip.h>
38128 #include <linux/uaccess.h>
38129 +#include <asm/local.h>
38130
38131 #include "tty.h"
38132 #include "network.h"
38133 @@ -51,7 +52,7 @@ struct ipw_tty {
38134 int tty_type;
38135 struct ipw_network *network;
38136 struct tty_struct *linux_tty;
38137 - int open_count;
38138 + local_t open_count;
38139 unsigned int control_lines;
38140 struct mutex ipw_tty_mutex;
38141 int tx_bytes_queued;
38142 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38143 mutex_unlock(&tty->ipw_tty_mutex);
38144 return -ENODEV;
38145 }
38146 - if (tty->open_count == 0)
38147 + if (local_read(&tty->open_count) == 0)
38148 tty->tx_bytes_queued = 0;
38149
38150 - tty->open_count++;
38151 + local_inc(&tty->open_count);
38152
38153 tty->linux_tty = linux_tty;
38154 linux_tty->driver_data = tty;
38155 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38156
38157 static void do_ipw_close(struct ipw_tty *tty)
38158 {
38159 - tty->open_count--;
38160 -
38161 - if (tty->open_count == 0) {
38162 + if (local_dec_return(&tty->open_count) == 0) {
38163 struct tty_struct *linux_tty = tty->linux_tty;
38164
38165 if (linux_tty != NULL) {
38166 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38167 return;
38168
38169 mutex_lock(&tty->ipw_tty_mutex);
38170 - if (tty->open_count == 0) {
38171 + if (local_read(&tty->open_count) == 0) {
38172 mutex_unlock(&tty->ipw_tty_mutex);
38173 return;
38174 }
38175 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38176 return;
38177 }
38178
38179 - if (!tty->open_count) {
38180 + if (!local_read(&tty->open_count)) {
38181 mutex_unlock(&tty->ipw_tty_mutex);
38182 return;
38183 }
38184 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38185 return -ENODEV;
38186
38187 mutex_lock(&tty->ipw_tty_mutex);
38188 - if (!tty->open_count) {
38189 + if (!local_read(&tty->open_count)) {
38190 mutex_unlock(&tty->ipw_tty_mutex);
38191 return -EINVAL;
38192 }
38193 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38194 if (!tty)
38195 return -ENODEV;
38196
38197 - if (!tty->open_count)
38198 + if (!local_read(&tty->open_count))
38199 return -EINVAL;
38200
38201 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38202 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38203 if (!tty)
38204 return 0;
38205
38206 - if (!tty->open_count)
38207 + if (!local_read(&tty->open_count))
38208 return 0;
38209
38210 return tty->tx_bytes_queued;
38211 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38212 if (!tty)
38213 return -ENODEV;
38214
38215 - if (!tty->open_count)
38216 + if (!local_read(&tty->open_count))
38217 return -EINVAL;
38218
38219 return get_control_lines(tty);
38220 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38221 if (!tty)
38222 return -ENODEV;
38223
38224 - if (!tty->open_count)
38225 + if (!local_read(&tty->open_count))
38226 return -EINVAL;
38227
38228 return set_control_lines(tty, set, clear);
38229 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38230 if (!tty)
38231 return -ENODEV;
38232
38233 - if (!tty->open_count)
38234 + if (!local_read(&tty->open_count))
38235 return -EINVAL;
38236
38237 /* FIXME: Exactly how is the tty object locked here .. */
38238 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38239 against a parallel ioctl etc */
38240 mutex_lock(&ttyj->ipw_tty_mutex);
38241 }
38242 - while (ttyj->open_count)
38243 + while (local_read(&ttyj->open_count))
38244 do_ipw_close(ttyj);
38245 ipwireless_disassociate_network_ttys(network,
38246 ttyj->channel_idx);
38247 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38248 index fc7bbba..9527e93 100644
38249 --- a/drivers/tty/n_gsm.c
38250 +++ b/drivers/tty/n_gsm.c
38251 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38252 kref_init(&dlci->ref);
38253 mutex_init(&dlci->mutex);
38254 dlci->fifo = &dlci->_fifo;
38255 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38256 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38257 kfree(dlci);
38258 return NULL;
38259 }
38260 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38261 index 39d6ab6..eb97f41 100644
38262 --- a/drivers/tty/n_tty.c
38263 +++ b/drivers/tty/n_tty.c
38264 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38265 {
38266 *ops = tty_ldisc_N_TTY;
38267 ops->owner = NULL;
38268 - ops->refcount = ops->flags = 0;
38269 + atomic_set(&ops->refcount, 0);
38270 + ops->flags = 0;
38271 }
38272 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38273 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38274 index e18604b..a7d5a11 100644
38275 --- a/drivers/tty/pty.c
38276 +++ b/drivers/tty/pty.c
38277 @@ -773,8 +773,10 @@ static void __init unix98_pty_init(void)
38278 register_sysctl_table(pty_root_table);
38279
38280 /* Now create the /dev/ptmx special device */
38281 + pax_open_kernel();
38282 tty_default_fops(&ptmx_fops);
38283 - ptmx_fops.open = ptmx_open;
38284 + *(void **)&ptmx_fops.open = ptmx_open;
38285 + pax_close_kernel();
38286
38287 cdev_init(&ptmx_cdev, &ptmx_fops);
38288 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38289 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38290 index 2b42a01..32a2ed3 100644
38291 --- a/drivers/tty/serial/kgdboc.c
38292 +++ b/drivers/tty/serial/kgdboc.c
38293 @@ -24,8 +24,9 @@
38294 #define MAX_CONFIG_LEN 40
38295
38296 static struct kgdb_io kgdboc_io_ops;
38297 +static struct kgdb_io kgdboc_io_ops_console;
38298
38299 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38300 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38301 static int configured = -1;
38302
38303 static char config[MAX_CONFIG_LEN];
38304 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38305 kgdboc_unregister_kbd();
38306 if (configured == 1)
38307 kgdb_unregister_io_module(&kgdboc_io_ops);
38308 + else if (configured == 2)
38309 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38310 }
38311
38312 static int configure_kgdboc(void)
38313 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38314 int err;
38315 char *cptr = config;
38316 struct console *cons;
38317 + int is_console = 0;
38318
38319 err = kgdboc_option_setup(config);
38320 if (err || !strlen(config) || isspace(config[0]))
38321 goto noconfig;
38322
38323 err = -ENODEV;
38324 - kgdboc_io_ops.is_console = 0;
38325 kgdb_tty_driver = NULL;
38326
38327 kgdboc_use_kms = 0;
38328 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38329 int idx;
38330 if (cons->device && cons->device(cons, &idx) == p &&
38331 idx == tty_line) {
38332 - kgdboc_io_ops.is_console = 1;
38333 + is_console = 1;
38334 break;
38335 }
38336 cons = cons->next;
38337 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38338 kgdb_tty_line = tty_line;
38339
38340 do_register:
38341 - err = kgdb_register_io_module(&kgdboc_io_ops);
38342 + if (is_console) {
38343 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38344 + configured = 2;
38345 + } else {
38346 + err = kgdb_register_io_module(&kgdboc_io_ops);
38347 + configured = 1;
38348 + }
38349 if (err)
38350 goto noconfig;
38351
38352 - configured = 1;
38353 -
38354 return 0;
38355
38356 noconfig:
38357 @@ -213,7 +220,7 @@ noconfig:
38358 static int __init init_kgdboc(void)
38359 {
38360 /* Already configured? */
38361 - if (configured == 1)
38362 + if (configured >= 1)
38363 return 0;
38364
38365 return configure_kgdboc();
38366 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38367 if (config[len - 1] == '\n')
38368 config[len - 1] = '\0';
38369
38370 - if (configured == 1)
38371 + if (configured >= 1)
38372 cleanup_kgdboc();
38373
38374 /* Go and configure with the new params. */
38375 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38376 .post_exception = kgdboc_post_exp_handler,
38377 };
38378
38379 +static struct kgdb_io kgdboc_io_ops_console = {
38380 + .name = "kgdboc",
38381 + .read_char = kgdboc_get_char,
38382 + .write_char = kgdboc_put_char,
38383 + .pre_exception = kgdboc_pre_exp_handler,
38384 + .post_exception = kgdboc_post_exp_handler,
38385 + .is_console = 1
38386 +};
38387 +
38388 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38389 /* This is only available if kgdboc is a built in for early debugging */
38390 static int __init kgdboc_early_init(char *opt)
38391 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38392 index 05085be..67eadb0 100644
38393 --- a/drivers/tty/tty_io.c
38394 +++ b/drivers/tty/tty_io.c
38395 @@ -3240,7 +3240,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38396
38397 void tty_default_fops(struct file_operations *fops)
38398 {
38399 - *fops = tty_fops;
38400 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38401 }
38402
38403 /*
38404 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38405 index 8e0924f..4204eb4 100644
38406 --- a/drivers/tty/tty_ldisc.c
38407 +++ b/drivers/tty/tty_ldisc.c
38408 @@ -75,7 +75,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38409 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38410 struct tty_ldisc_ops *ldo = ld->ops;
38411
38412 - ldo->refcount--;
38413 + atomic_dec(&ldo->refcount);
38414 module_put(ldo->owner);
38415 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38416
38417 @@ -110,7 +110,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38418 spin_lock_irqsave(&tty_ldisc_lock, flags);
38419 tty_ldiscs[disc] = new_ldisc;
38420 new_ldisc->num = disc;
38421 - new_ldisc->refcount = 0;
38422 + atomic_set(&new_ldisc->refcount, 0);
38423 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38424
38425 return ret;
38426 @@ -138,7 +138,7 @@ int tty_unregister_ldisc(int disc)
38427 return -EINVAL;
38428
38429 spin_lock_irqsave(&tty_ldisc_lock, flags);
38430 - if (tty_ldiscs[disc]->refcount)
38431 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38432 ret = -EBUSY;
38433 else
38434 tty_ldiscs[disc] = NULL;
38435 @@ -159,7 +159,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38436 if (ldops) {
38437 ret = ERR_PTR(-EAGAIN);
38438 if (try_module_get(ldops->owner)) {
38439 - ldops->refcount++;
38440 + atomic_inc(&ldops->refcount);
38441 ret = ldops;
38442 }
38443 }
38444 @@ -172,7 +172,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38445 unsigned long flags;
38446
38447 spin_lock_irqsave(&tty_ldisc_lock, flags);
38448 - ldops->refcount--;
38449 + atomic_dec(&ldops->refcount);
38450 module_put(ldops->owner);
38451 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38452 }
38453 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38454 index a605549..6bd3c96 100644
38455 --- a/drivers/tty/vt/keyboard.c
38456 +++ b/drivers/tty/vt/keyboard.c
38457 @@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38458 kbd->kbdmode == VC_OFF) &&
38459 value != KVAL(K_SAK))
38460 return; /* SAK is allowed even in raw mode */
38461 +
38462 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38463 + {
38464 + void *func = fn_handler[value];
38465 + if (func == fn_show_state || func == fn_show_ptregs ||
38466 + func == fn_show_mem)
38467 + return;
38468 + }
38469 +#endif
38470 +
38471 fn_handler[value](vc);
38472 }
38473
38474 diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
38475 index 65447c5..0526f0a 100644
38476 --- a/drivers/tty/vt/vt_ioctl.c
38477 +++ b/drivers/tty/vt/vt_ioctl.c
38478 @@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38479 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38480 return -EFAULT;
38481
38482 - if (!capable(CAP_SYS_TTY_CONFIG))
38483 - perm = 0;
38484 -
38485 switch (cmd) {
38486 case KDGKBENT:
38487 key_map = key_maps[s];
38488 @@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38489 val = (i ? K_HOLE : K_NOSUCHMAP);
38490 return put_user(val, &user_kbe->kb_value);
38491 case KDSKBENT:
38492 + if (!capable(CAP_SYS_TTY_CONFIG))
38493 + perm = 0;
38494 +
38495 if (!perm)
38496 return -EPERM;
38497 if (!i && v == K_NOSUCHMAP) {
38498 @@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38499 int i, j, k;
38500 int ret;
38501
38502 - if (!capable(CAP_SYS_TTY_CONFIG))
38503 - perm = 0;
38504 -
38505 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38506 if (!kbs) {
38507 ret = -ENOMEM;
38508 @@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38509 kfree(kbs);
38510 return ((p && *p) ? -EOVERFLOW : 0);
38511 case KDSKBSENT:
38512 + if (!capable(CAP_SYS_TTY_CONFIG))
38513 + perm = 0;
38514 +
38515 if (!perm) {
38516 ret = -EPERM;
38517 goto reterr;
38518 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38519 index a783d53..cb30d94 100644
38520 --- a/drivers/uio/uio.c
38521 +++ b/drivers/uio/uio.c
38522 @@ -25,6 +25,7 @@
38523 #include <linux/kobject.h>
38524 #include <linux/cdev.h>
38525 #include <linux/uio_driver.h>
38526 +#include <asm/local.h>
38527
38528 #define UIO_MAX_DEVICES (1U << MINORBITS)
38529
38530 @@ -32,10 +33,10 @@ struct uio_device {
38531 struct module *owner;
38532 struct device *dev;
38533 int minor;
38534 - atomic_t event;
38535 + atomic_unchecked_t event;
38536 struct fasync_struct *async_queue;
38537 wait_queue_head_t wait;
38538 - int vma_count;
38539 + local_t vma_count;
38540 struct uio_info *info;
38541 struct kobject *map_dir;
38542 struct kobject *portio_dir;
38543 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38544 struct device_attribute *attr, char *buf)
38545 {
38546 struct uio_device *idev = dev_get_drvdata(dev);
38547 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38548 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38549 }
38550
38551 static struct device_attribute uio_class_attributes[] = {
38552 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38553 {
38554 struct uio_device *idev = info->uio_dev;
38555
38556 - atomic_inc(&idev->event);
38557 + atomic_inc_unchecked(&idev->event);
38558 wake_up_interruptible(&idev->wait);
38559 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38560 }
38561 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38562 }
38563
38564 listener->dev = idev;
38565 - listener->event_count = atomic_read(&idev->event);
38566 + listener->event_count = atomic_read_unchecked(&idev->event);
38567 filep->private_data = listener;
38568
38569 if (idev->info->open) {
38570 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38571 return -EIO;
38572
38573 poll_wait(filep, &idev->wait, wait);
38574 - if (listener->event_count != atomic_read(&idev->event))
38575 + if (listener->event_count != atomic_read_unchecked(&idev->event))
38576 return POLLIN | POLLRDNORM;
38577 return 0;
38578 }
38579 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38580 do {
38581 set_current_state(TASK_INTERRUPTIBLE);
38582
38583 - event_count = atomic_read(&idev->event);
38584 + event_count = atomic_read_unchecked(&idev->event);
38585 if (event_count != listener->event_count) {
38586 if (copy_to_user(buf, &event_count, count))
38587 retval = -EFAULT;
38588 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38589 static void uio_vma_open(struct vm_area_struct *vma)
38590 {
38591 struct uio_device *idev = vma->vm_private_data;
38592 - idev->vma_count++;
38593 + local_inc(&idev->vma_count);
38594 }
38595
38596 static void uio_vma_close(struct vm_area_struct *vma)
38597 {
38598 struct uio_device *idev = vma->vm_private_data;
38599 - idev->vma_count--;
38600 + local_dec(&idev->vma_count);
38601 }
38602
38603 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38604 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38605 idev->owner = owner;
38606 idev->info = info;
38607 init_waitqueue_head(&idev->wait);
38608 - atomic_set(&idev->event, 0);
38609 + atomic_set_unchecked(&idev->event, 0);
38610
38611 ret = uio_get_minor(idev);
38612 if (ret)
38613 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38614 index a845f8b..4f54072 100644
38615 --- a/drivers/usb/atm/cxacru.c
38616 +++ b/drivers/usb/atm/cxacru.c
38617 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38618 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38619 if (ret < 2)
38620 return -EINVAL;
38621 - if (index < 0 || index > 0x7f)
38622 + if (index > 0x7f)
38623 return -EINVAL;
38624 pos += tmp;
38625
38626 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38627 index d3448ca..d2864ca 100644
38628 --- a/drivers/usb/atm/usbatm.c
38629 +++ b/drivers/usb/atm/usbatm.c
38630 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38631 if (printk_ratelimit())
38632 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38633 __func__, vpi, vci);
38634 - atomic_inc(&vcc->stats->rx_err);
38635 + atomic_inc_unchecked(&vcc->stats->rx_err);
38636 return;
38637 }
38638
38639 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38640 if (length > ATM_MAX_AAL5_PDU) {
38641 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38642 __func__, length, vcc);
38643 - atomic_inc(&vcc->stats->rx_err);
38644 + atomic_inc_unchecked(&vcc->stats->rx_err);
38645 goto out;
38646 }
38647
38648 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38649 if (sarb->len < pdu_length) {
38650 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38651 __func__, pdu_length, sarb->len, vcc);
38652 - atomic_inc(&vcc->stats->rx_err);
38653 + atomic_inc_unchecked(&vcc->stats->rx_err);
38654 goto out;
38655 }
38656
38657 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38658 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38659 __func__, vcc);
38660 - atomic_inc(&vcc->stats->rx_err);
38661 + atomic_inc_unchecked(&vcc->stats->rx_err);
38662 goto out;
38663 }
38664
38665 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38666 if (printk_ratelimit())
38667 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38668 __func__, length);
38669 - atomic_inc(&vcc->stats->rx_drop);
38670 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38671 goto out;
38672 }
38673
38674 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38675
38676 vcc->push(vcc, skb);
38677
38678 - atomic_inc(&vcc->stats->rx);
38679 + atomic_inc_unchecked(&vcc->stats->rx);
38680 out:
38681 skb_trim(sarb, 0);
38682 }
38683 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38684 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38685
38686 usbatm_pop(vcc, skb);
38687 - atomic_inc(&vcc->stats->tx);
38688 + atomic_inc_unchecked(&vcc->stats->tx);
38689
38690 skb = skb_dequeue(&instance->sndqueue);
38691 }
38692 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38693 if (!left--)
38694 return sprintf(page,
38695 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38696 - atomic_read(&atm_dev->stats.aal5.tx),
38697 - atomic_read(&atm_dev->stats.aal5.tx_err),
38698 - atomic_read(&atm_dev->stats.aal5.rx),
38699 - atomic_read(&atm_dev->stats.aal5.rx_err),
38700 - atomic_read(&atm_dev->stats.aal5.rx_drop));
38701 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38702 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38703 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38704 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38705 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38706
38707 if (!left--) {
38708 if (instance->disconnected)
38709 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38710 index d956965..4179a77 100644
38711 --- a/drivers/usb/core/devices.c
38712 +++ b/drivers/usb/core/devices.c
38713 @@ -126,7 +126,7 @@ static const char format_endpt[] =
38714 * time it gets called.
38715 */
38716 static struct device_connect_event {
38717 - atomic_t count;
38718 + atomic_unchecked_t count;
38719 wait_queue_head_t wait;
38720 } device_event = {
38721 .count = ATOMIC_INIT(1),
38722 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38723
38724 void usbfs_conn_disc_event(void)
38725 {
38726 - atomic_add(2, &device_event.count);
38727 + atomic_add_unchecked(2, &device_event.count);
38728 wake_up(&device_event.wait);
38729 }
38730
38731 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38732
38733 poll_wait(file, &device_event.wait, wait);
38734
38735 - event_count = atomic_read(&device_event.count);
38736 + event_count = atomic_read_unchecked(&device_event.count);
38737 if (file->f_version != event_count) {
38738 file->f_version = event_count;
38739 return POLLIN | POLLRDNORM;
38740 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38741 index 1fc8f12..20647c1 100644
38742 --- a/drivers/usb/early/ehci-dbgp.c
38743 +++ b/drivers/usb/early/ehci-dbgp.c
38744 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38745
38746 #ifdef CONFIG_KGDB
38747 static struct kgdb_io kgdbdbgp_io_ops;
38748 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38749 +static struct kgdb_io kgdbdbgp_io_ops_console;
38750 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38751 #else
38752 #define dbgp_kgdb_mode (0)
38753 #endif
38754 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38755 .write_char = kgdbdbgp_write_char,
38756 };
38757
38758 +static struct kgdb_io kgdbdbgp_io_ops_console = {
38759 + .name = "kgdbdbgp",
38760 + .read_char = kgdbdbgp_read_char,
38761 + .write_char = kgdbdbgp_write_char,
38762 + .is_console = 1
38763 +};
38764 +
38765 static int kgdbdbgp_wait_time;
38766
38767 static int __init kgdbdbgp_parse_config(char *str)
38768 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38769 ptr++;
38770 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38771 }
38772 - kgdb_register_io_module(&kgdbdbgp_io_ops);
38773 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38774 + if (early_dbgp_console.index != -1)
38775 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38776 + else
38777 + kgdb_register_io_module(&kgdbdbgp_io_ops);
38778
38779 return 0;
38780 }
38781 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38782 index d6bea3e..60b250e 100644
38783 --- a/drivers/usb/wusbcore/wa-hc.h
38784 +++ b/drivers/usb/wusbcore/wa-hc.h
38785 @@ -192,7 +192,7 @@ struct wahc {
38786 struct list_head xfer_delayed_list;
38787 spinlock_t xfer_list_lock;
38788 struct work_struct xfer_work;
38789 - atomic_t xfer_id_count;
38790 + atomic_unchecked_t xfer_id_count;
38791 };
38792
38793
38794 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38795 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38796 spin_lock_init(&wa->xfer_list_lock);
38797 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38798 - atomic_set(&wa->xfer_id_count, 1);
38799 + atomic_set_unchecked(&wa->xfer_id_count, 1);
38800 }
38801
38802 /**
38803 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38804 index 57c01ab..8a05959 100644
38805 --- a/drivers/usb/wusbcore/wa-xfer.c
38806 +++ b/drivers/usb/wusbcore/wa-xfer.c
38807 @@ -296,7 +296,7 @@ out:
38808 */
38809 static void wa_xfer_id_init(struct wa_xfer *xfer)
38810 {
38811 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38812 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38813 }
38814
38815 /*
38816 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38817 index c14c42b..f955cc2 100644
38818 --- a/drivers/vhost/vhost.c
38819 +++ b/drivers/vhost/vhost.c
38820 @@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38821 return 0;
38822 }
38823
38824 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38825 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38826 {
38827 struct file *eventfp, *filep = NULL,
38828 *pollstart = NULL, *pollstop = NULL;
38829 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38830 index b0b2ac3..89a4399 100644
38831 --- a/drivers/video/aty/aty128fb.c
38832 +++ b/drivers/video/aty/aty128fb.c
38833 @@ -148,7 +148,7 @@ enum {
38834 };
38835
38836 /* Must match above enum */
38837 -static const char *r128_family[] __devinitdata = {
38838 +static const char *r128_family[] __devinitconst = {
38839 "AGP",
38840 "PCI",
38841 "PRO AGP",
38842 diff --git a/drivers/video/backlight/s6e63m0.c b/drivers/video/backlight/s6e63m0.c
38843 index e132157..516db70 100644
38844 --- a/drivers/video/backlight/s6e63m0.c
38845 +++ b/drivers/video/backlight/s6e63m0.c
38846 @@ -690,7 +690,7 @@ static ssize_t s6e63m0_sysfs_store_gamma_mode(struct device *dev,
38847 struct backlight_device *bd = NULL;
38848 int brightness, rc;
38849
38850 - rc = strict_strtoul(buf, 0, (unsigned long *)&lcd->gamma_mode);
38851 + rc = kstrtouint(buf, 0, &lcd->gamma_mode);
38852 if (rc < 0)
38853 return rc;
38854
38855 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38856 index 5c3960d..15cf8fc 100644
38857 --- a/drivers/video/fbcmap.c
38858 +++ b/drivers/video/fbcmap.c
38859 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38860 rc = -ENODEV;
38861 goto out;
38862 }
38863 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38864 - !info->fbops->fb_setcmap)) {
38865 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38866 rc = -EINVAL;
38867 goto out1;
38868 }
38869 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38870 index ad93629..e020fc3 100644
38871 --- a/drivers/video/fbmem.c
38872 +++ b/drivers/video/fbmem.c
38873 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38874 image->dx += image->width + 8;
38875 }
38876 } else if (rotate == FB_ROTATE_UD) {
38877 - for (x = 0; x < num && image->dx >= 0; x++) {
38878 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38879 info->fbops->fb_imageblit(info, image);
38880 image->dx -= image->width + 8;
38881 }
38882 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38883 image->dy += image->height + 8;
38884 }
38885 } else if (rotate == FB_ROTATE_CCW) {
38886 - for (x = 0; x < num && image->dy >= 0; x++) {
38887 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
38888 info->fbops->fb_imageblit(info, image);
38889 image->dy -= image->height + 8;
38890 }
38891 @@ -1143,7 +1143,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38892 return -EFAULT;
38893 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
38894 return -EINVAL;
38895 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
38896 + if (con2fb.framebuffer >= FB_MAX)
38897 return -EINVAL;
38898 if (!registered_fb[con2fb.framebuffer])
38899 request_module("fb%d", con2fb.framebuffer);
38900 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
38901 index 5a5d092..265c5ed 100644
38902 --- a/drivers/video/geode/gx1fb_core.c
38903 +++ b/drivers/video/geode/gx1fb_core.c
38904 @@ -29,7 +29,7 @@ static int crt_option = 1;
38905 static char panel_option[32] = "";
38906
38907 /* Modes relevant to the GX1 (taken from modedb.c) */
38908 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
38909 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
38910 /* 640x480-60 VESA */
38911 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
38912 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38913 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
38914 index 0fad23f..0e9afa4 100644
38915 --- a/drivers/video/gxt4500.c
38916 +++ b/drivers/video/gxt4500.c
38917 @@ -156,7 +156,7 @@ struct gxt4500_par {
38918 static char *mode_option;
38919
38920 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
38921 -static const struct fb_videomode defaultmode __devinitdata = {
38922 +static const struct fb_videomode defaultmode __devinitconst = {
38923 .refresh = 60,
38924 .xres = 1280,
38925 .yres = 1024,
38926 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
38927 return 0;
38928 }
38929
38930 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
38931 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
38932 .id = "IBM GXT4500P",
38933 .type = FB_TYPE_PACKED_PIXELS,
38934 .visual = FB_VISUAL_PSEUDOCOLOR,
38935 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
38936 index 7672d2e..b56437f 100644
38937 --- a/drivers/video/i810/i810_accel.c
38938 +++ b/drivers/video/i810/i810_accel.c
38939 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
38940 }
38941 }
38942 printk("ringbuffer lockup!!!\n");
38943 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
38944 i810_report_error(mmio);
38945 par->dev_flags |= LOCKUP;
38946 info->pixmap.scan_align = 1;
38947 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
38948 index 318f6fb..9a389c1 100644
38949 --- a/drivers/video/i810/i810_main.c
38950 +++ b/drivers/video/i810/i810_main.c
38951 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
38952 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
38953
38954 /* PCI */
38955 -static const char *i810_pci_list[] __devinitdata = {
38956 +static const char *i810_pci_list[] __devinitconst = {
38957 "Intel(R) 810 Framebuffer Device" ,
38958 "Intel(R) 810-DC100 Framebuffer Device" ,
38959 "Intel(R) 810E Framebuffer Device" ,
38960 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
38961 index de36693..3c63fc2 100644
38962 --- a/drivers/video/jz4740_fb.c
38963 +++ b/drivers/video/jz4740_fb.c
38964 @@ -136,7 +136,7 @@ struct jzfb {
38965 uint32_t pseudo_palette[16];
38966 };
38967
38968 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
38969 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
38970 .id = "JZ4740 FB",
38971 .type = FB_TYPE_PACKED_PIXELS,
38972 .visual = FB_VISUAL_TRUECOLOR,
38973 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
38974 index 3c14e43..eafa544 100644
38975 --- a/drivers/video/logo/logo_linux_clut224.ppm
38976 +++ b/drivers/video/logo/logo_linux_clut224.ppm
38977 @@ -1,1604 +1,1123 @@
38978 P3
38979 -# Standard 224-color Linux logo
38980 80 80
38981 255
38982 - 0 0 0 0 0 0 0 0 0 0 0 0
38983 - 0 0 0 0 0 0 0 0 0 0 0 0
38984 - 0 0 0 0 0 0 0 0 0 0 0 0
38985 - 0 0 0 0 0 0 0 0 0 0 0 0
38986 - 0 0 0 0 0 0 0 0 0 0 0 0
38987 - 0 0 0 0 0 0 0 0 0 0 0 0
38988 - 0 0 0 0 0 0 0 0 0 0 0 0
38989 - 0 0 0 0 0 0 0 0 0 0 0 0
38990 - 0 0 0 0 0 0 0 0 0 0 0 0
38991 - 6 6 6 6 6 6 10 10 10 10 10 10
38992 - 10 10 10 6 6 6 6 6 6 6 6 6
38993 - 0 0 0 0 0 0 0 0 0 0 0 0
38994 - 0 0 0 0 0 0 0 0 0 0 0 0
38995 - 0 0 0 0 0 0 0 0 0 0 0 0
38996 - 0 0 0 0 0 0 0 0 0 0 0 0
38997 - 0 0 0 0 0 0 0 0 0 0 0 0
38998 - 0 0 0 0 0 0 0 0 0 0 0 0
38999 - 0 0 0 0 0 0 0 0 0 0 0 0
39000 - 0 0 0 0 0 0 0 0 0 0 0 0
39001 - 0 0 0 0 0 0 0 0 0 0 0 0
39002 - 0 0 0 0 0 0 0 0 0 0 0 0
39003 - 0 0 0 0 0 0 0 0 0 0 0 0
39004 - 0 0 0 0 0 0 0 0 0 0 0 0
39005 - 0 0 0 0 0 0 0 0 0 0 0 0
39006 - 0 0 0 0 0 0 0 0 0 0 0 0
39007 - 0 0 0 0 0 0 0 0 0 0 0 0
39008 - 0 0 0 0 0 0 0 0 0 0 0 0
39009 - 0 0 0 0 0 0 0 0 0 0 0 0
39010 - 0 0 0 6 6 6 10 10 10 14 14 14
39011 - 22 22 22 26 26 26 30 30 30 34 34 34
39012 - 30 30 30 30 30 30 26 26 26 18 18 18
39013 - 14 14 14 10 10 10 6 6 6 0 0 0
39014 - 0 0 0 0 0 0 0 0 0 0 0 0
39015 - 0 0 0 0 0 0 0 0 0 0 0 0
39016 - 0 0 0 0 0 0 0 0 0 0 0 0
39017 - 0 0 0 0 0 0 0 0 0 0 0 0
39018 - 0 0 0 0 0 0 0 0 0 0 0 0
39019 - 0 0 0 0 0 0 0 0 0 0 0 0
39020 - 0 0 0 0 0 0 0 0 0 0 0 0
39021 - 0 0 0 0 0 0 0 0 0 0 0 0
39022 - 0 0 0 0 0 0 0 0 0 0 0 0
39023 - 0 0 0 0 0 1 0 0 1 0 0 0
39024 - 0 0 0 0 0 0 0 0 0 0 0 0
39025 - 0 0 0 0 0 0 0 0 0 0 0 0
39026 - 0 0 0 0 0 0 0 0 0 0 0 0
39027 - 0 0 0 0 0 0 0 0 0 0 0 0
39028 - 0 0 0 0 0 0 0 0 0 0 0 0
39029 - 0 0 0 0 0 0 0 0 0 0 0 0
39030 - 6 6 6 14 14 14 26 26 26 42 42 42
39031 - 54 54 54 66 66 66 78 78 78 78 78 78
39032 - 78 78 78 74 74 74 66 66 66 54 54 54
39033 - 42 42 42 26 26 26 18 18 18 10 10 10
39034 - 6 6 6 0 0 0 0 0 0 0 0 0
39035 - 0 0 0 0 0 0 0 0 0 0 0 0
39036 - 0 0 0 0 0 0 0 0 0 0 0 0
39037 - 0 0 0 0 0 0 0 0 0 0 0 0
39038 - 0 0 0 0 0 0 0 0 0 0 0 0
39039 - 0 0 0 0 0 0 0 0 0 0 0 0
39040 - 0 0 0 0 0 0 0 0 0 0 0 0
39041 - 0 0 0 0 0 0 0 0 0 0 0 0
39042 - 0 0 0 0 0 0 0 0 0 0 0 0
39043 - 0 0 1 0 0 0 0 0 0 0 0 0
39044 - 0 0 0 0 0 0 0 0 0 0 0 0
39045 - 0 0 0 0 0 0 0 0 0 0 0 0
39046 - 0 0 0 0 0 0 0 0 0 0 0 0
39047 - 0 0 0 0 0 0 0 0 0 0 0 0
39048 - 0 0 0 0 0 0 0 0 0 0 0 0
39049 - 0 0 0 0 0 0 0 0 0 10 10 10
39050 - 22 22 22 42 42 42 66 66 66 86 86 86
39051 - 66 66 66 38 38 38 38 38 38 22 22 22
39052 - 26 26 26 34 34 34 54 54 54 66 66 66
39053 - 86 86 86 70 70 70 46 46 46 26 26 26
39054 - 14 14 14 6 6 6 0 0 0 0 0 0
39055 - 0 0 0 0 0 0 0 0 0 0 0 0
39056 - 0 0 0 0 0 0 0 0 0 0 0 0
39057 - 0 0 0 0 0 0 0 0 0 0 0 0
39058 - 0 0 0 0 0 0 0 0 0 0 0 0
39059 - 0 0 0 0 0 0 0 0 0 0 0 0
39060 - 0 0 0 0 0 0 0 0 0 0 0 0
39061 - 0 0 0 0 0 0 0 0 0 0 0 0
39062 - 0 0 0 0 0 0 0 0 0 0 0 0
39063 - 0 0 1 0 0 1 0 0 1 0 0 0
39064 - 0 0 0 0 0 0 0 0 0 0 0 0
39065 - 0 0 0 0 0 0 0 0 0 0 0 0
39066 - 0 0 0 0 0 0 0 0 0 0 0 0
39067 - 0 0 0 0 0 0 0 0 0 0 0 0
39068 - 0 0 0 0 0 0 0 0 0 0 0 0
39069 - 0 0 0 0 0 0 10 10 10 26 26 26
39070 - 50 50 50 82 82 82 58 58 58 6 6 6
39071 - 2 2 6 2 2 6 2 2 6 2 2 6
39072 - 2 2 6 2 2 6 2 2 6 2 2 6
39073 - 6 6 6 54 54 54 86 86 86 66 66 66
39074 - 38 38 38 18 18 18 6 6 6 0 0 0
39075 - 0 0 0 0 0 0 0 0 0 0 0 0
39076 - 0 0 0 0 0 0 0 0 0 0 0 0
39077 - 0 0 0 0 0 0 0 0 0 0 0 0
39078 - 0 0 0 0 0 0 0 0 0 0 0 0
39079 - 0 0 0 0 0 0 0 0 0 0 0 0
39080 - 0 0 0 0 0 0 0 0 0 0 0 0
39081 - 0 0 0 0 0 0 0 0 0 0 0 0
39082 - 0 0 0 0 0 0 0 0 0 0 0 0
39083 - 0 0 0 0 0 0 0 0 0 0 0 0
39084 - 0 0 0 0 0 0 0 0 0 0 0 0
39085 - 0 0 0 0 0 0 0 0 0 0 0 0
39086 - 0 0 0 0 0 0 0 0 0 0 0 0
39087 - 0 0 0 0 0 0 0 0 0 0 0 0
39088 - 0 0 0 0 0 0 0 0 0 0 0 0
39089 - 0 0 0 6 6 6 22 22 22 50 50 50
39090 - 78 78 78 34 34 34 2 2 6 2 2 6
39091 - 2 2 6 2 2 6 2 2 6 2 2 6
39092 - 2 2 6 2 2 6 2 2 6 2 2 6
39093 - 2 2 6 2 2 6 6 6 6 70 70 70
39094 - 78 78 78 46 46 46 22 22 22 6 6 6
39095 - 0 0 0 0 0 0 0 0 0 0 0 0
39096 - 0 0 0 0 0 0 0 0 0 0 0 0
39097 - 0 0 0 0 0 0 0 0 0 0 0 0
39098 - 0 0 0 0 0 0 0 0 0 0 0 0
39099 - 0 0 0 0 0 0 0 0 0 0 0 0
39100 - 0 0 0 0 0 0 0 0 0 0 0 0
39101 - 0 0 0 0 0 0 0 0 0 0 0 0
39102 - 0 0 0 0 0 0 0 0 0 0 0 0
39103 - 0 0 1 0 0 1 0 0 1 0 0 0
39104 - 0 0 0 0 0 0 0 0 0 0 0 0
39105 - 0 0 0 0 0 0 0 0 0 0 0 0
39106 - 0 0 0 0 0 0 0 0 0 0 0 0
39107 - 0 0 0 0 0 0 0 0 0 0 0 0
39108 - 0 0 0 0 0 0 0 0 0 0 0 0
39109 - 6 6 6 18 18 18 42 42 42 82 82 82
39110 - 26 26 26 2 2 6 2 2 6 2 2 6
39111 - 2 2 6 2 2 6 2 2 6 2 2 6
39112 - 2 2 6 2 2 6 2 2 6 14 14 14
39113 - 46 46 46 34 34 34 6 6 6 2 2 6
39114 - 42 42 42 78 78 78 42 42 42 18 18 18
39115 - 6 6 6 0 0 0 0 0 0 0 0 0
39116 - 0 0 0 0 0 0 0 0 0 0 0 0
39117 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 0 0 0 1 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 - 10 10 10 30 30 30 66 66 66 58 58 58
39130 - 2 2 6 2 2 6 2 2 6 2 2 6
39131 - 2 2 6 2 2 6 2 2 6 2 2 6
39132 - 2 2 6 2 2 6 2 2 6 26 26 26
39133 - 86 86 86 101 101 101 46 46 46 10 10 10
39134 - 2 2 6 58 58 58 70 70 70 34 34 34
39135 - 10 10 10 0 0 0 0 0 0 0 0 0
39136 - 0 0 0 0 0 0 0 0 0 0 0 0
39137 - 0 0 0 0 0 0 0 0 0 0 0 0
39138 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 0 0 0
39144 - 0 0 0 0 0 0 0 0 0 0 0 0
39145 - 0 0 0 0 0 0 0 0 0 0 0 0
39146 - 0 0 0 0 0 0 0 0 0 0 0 0
39147 - 0 0 0 0 0 0 0 0 0 0 0 0
39148 - 0 0 0 0 0 0 0 0 0 0 0 0
39149 - 14 14 14 42 42 42 86 86 86 10 10 10
39150 - 2 2 6 2 2 6 2 2 6 2 2 6
39151 - 2 2 6 2 2 6 2 2 6 2 2 6
39152 - 2 2 6 2 2 6 2 2 6 30 30 30
39153 - 94 94 94 94 94 94 58 58 58 26 26 26
39154 - 2 2 6 6 6 6 78 78 78 54 54 54
39155 - 22 22 22 6 6 6 0 0 0 0 0 0
39156 - 0 0 0 0 0 0 0 0 0 0 0 0
39157 - 0 0 0 0 0 0 0 0 0 0 0 0
39158 - 0 0 0 0 0 0 0 0 0 0 0 0
39159 - 0 0 0 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 0 0 0 0 0 0 0 6 6 6
39169 - 22 22 22 62 62 62 62 62 62 2 2 6
39170 - 2 2 6 2 2 6 2 2 6 2 2 6
39171 - 2 2 6 2 2 6 2 2 6 2 2 6
39172 - 2 2 6 2 2 6 2 2 6 26 26 26
39173 - 54 54 54 38 38 38 18 18 18 10 10 10
39174 - 2 2 6 2 2 6 34 34 34 82 82 82
39175 - 38 38 38 14 14 14 0 0 0 0 0 0
39176 - 0 0 0 0 0 0 0 0 0 0 0 0
39177 - 0 0 0 0 0 0 0 0 0 0 0 0
39178 - 0 0 0 0 0 0 0 0 0 0 0 0
39179 - 0 0 0 0 0 0 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 1 0 0 1 0 0 0
39184 - 0 0 0 0 0 0 0 0 0 0 0 0
39185 - 0 0 0 0 0 0 0 0 0 0 0 0
39186 - 0 0 0 0 0 0 0 0 0 0 0 0
39187 - 0 0 0 0 0 0 0 0 0 0 0 0
39188 - 0 0 0 0 0 0 0 0 0 6 6 6
39189 - 30 30 30 78 78 78 30 30 30 2 2 6
39190 - 2 2 6 2 2 6 2 2 6 2 2 6
39191 - 2 2 6 2 2 6 2 2 6 2 2 6
39192 - 2 2 6 2 2 6 2 2 6 10 10 10
39193 - 10 10 10 2 2 6 2 2 6 2 2 6
39194 - 2 2 6 2 2 6 2 2 6 78 78 78
39195 - 50 50 50 18 18 18 6 6 6 0 0 0
39196 - 0 0 0 0 0 0 0 0 0 0 0 0
39197 - 0 0 0 0 0 0 0 0 0 0 0 0
39198 - 0 0 0 0 0 0 0 0 0 0 0 0
39199 - 0 0 0 0 0 0 0 0 0 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 1 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 10 10 10
39209 - 38 38 38 86 86 86 14 14 14 2 2 6
39210 - 2 2 6 2 2 6 2 2 6 2 2 6
39211 - 2 2 6 2 2 6 2 2 6 2 2 6
39212 - 2 2 6 2 2 6 2 2 6 2 2 6
39213 - 2 2 6 2 2 6 2 2 6 2 2 6
39214 - 2 2 6 2 2 6 2 2 6 54 54 54
39215 - 66 66 66 26 26 26 6 6 6 0 0 0
39216 - 0 0 0 0 0 0 0 0 0 0 0 0
39217 - 0 0 0 0 0 0 0 0 0 0 0 0
39218 - 0 0 0 0 0 0 0 0 0 0 0 0
39219 - 0 0 0 0 0 0 0 0 0 0 0 0
39220 - 0 0 0 0 0 0 0 0 0 0 0 0
39221 - 0 0 0 0 0 0 0 0 0 0 0 0
39222 - 0 0 0 0 0 0 0 0 0 0 0 0
39223 - 0 0 0 0 0 1 0 0 1 0 0 0
39224 - 0 0 0 0 0 0 0 0 0 0 0 0
39225 - 0 0 0 0 0 0 0 0 0 0 0 0
39226 - 0 0 0 0 0 0 0 0 0 0 0 0
39227 - 0 0 0 0 0 0 0 0 0 0 0 0
39228 - 0 0 0 0 0 0 0 0 0 14 14 14
39229 - 42 42 42 82 82 82 2 2 6 2 2 6
39230 - 2 2 6 6 6 6 10 10 10 2 2 6
39231 - 2 2 6 2 2 6 2 2 6 2 2 6
39232 - 2 2 6 2 2 6 2 2 6 6 6 6
39233 - 14 14 14 10 10 10 2 2 6 2 2 6
39234 - 2 2 6 2 2 6 2 2 6 18 18 18
39235 - 82 82 82 34 34 34 10 10 10 0 0 0
39236 - 0 0 0 0 0 0 0 0 0 0 0 0
39237 - 0 0 0 0 0 0 0 0 0 0 0 0
39238 - 0 0 0 0 0 0 0 0 0 0 0 0
39239 - 0 0 0 0 0 0 0 0 0 0 0 0
39240 - 0 0 0 0 0 0 0 0 0 0 0 0
39241 - 0 0 0 0 0 0 0 0 0 0 0 0
39242 - 0 0 0 0 0 0 0 0 0 0 0 0
39243 - 0 0 1 0 0 0 0 0 0 0 0 0
39244 - 0 0 0 0 0 0 0 0 0 0 0 0
39245 - 0 0 0 0 0 0 0 0 0 0 0 0
39246 - 0 0 0 0 0 0 0 0 0 0 0 0
39247 - 0 0 0 0 0 0 0 0 0 0 0 0
39248 - 0 0 0 0 0 0 0 0 0 14 14 14
39249 - 46 46 46 86 86 86 2 2 6 2 2 6
39250 - 6 6 6 6 6 6 22 22 22 34 34 34
39251 - 6 6 6 2 2 6 2 2 6 2 2 6
39252 - 2 2 6 2 2 6 18 18 18 34 34 34
39253 - 10 10 10 50 50 50 22 22 22 2 2 6
39254 - 2 2 6 2 2 6 2 2 6 10 10 10
39255 - 86 86 86 42 42 42 14 14 14 0 0 0
39256 - 0 0 0 0 0 0 0 0 0 0 0 0
39257 - 0 0 0 0 0 0 0 0 0 0 0 0
39258 - 0 0 0 0 0 0 0 0 0 0 0 0
39259 - 0 0 0 0 0 0 0 0 0 0 0 0
39260 - 0 0 0 0 0 0 0 0 0 0 0 0
39261 - 0 0 0 0 0 0 0 0 0 0 0 0
39262 - 0 0 0 0 0 0 0 0 0 0 0 0
39263 - 0 0 1 0 0 1 0 0 1 0 0 0
39264 - 0 0 0 0 0 0 0 0 0 0 0 0
39265 - 0 0 0 0 0 0 0 0 0 0 0 0
39266 - 0 0 0 0 0 0 0 0 0 0 0 0
39267 - 0 0 0 0 0 0 0 0 0 0 0 0
39268 - 0 0 0 0 0 0 0 0 0 14 14 14
39269 - 46 46 46 86 86 86 2 2 6 2 2 6
39270 - 38 38 38 116 116 116 94 94 94 22 22 22
39271 - 22 22 22 2 2 6 2 2 6 2 2 6
39272 - 14 14 14 86 86 86 138 138 138 162 162 162
39273 -154 154 154 38 38 38 26 26 26 6 6 6
39274 - 2 2 6 2 2 6 2 2 6 2 2 6
39275 - 86 86 86 46 46 46 14 14 14 0 0 0
39276 - 0 0 0 0 0 0 0 0 0 0 0 0
39277 - 0 0 0 0 0 0 0 0 0 0 0 0
39278 - 0 0 0 0 0 0 0 0 0 0 0 0
39279 - 0 0 0 0 0 0 0 0 0 0 0 0
39280 - 0 0 0 0 0 0 0 0 0 0 0 0
39281 - 0 0 0 0 0 0 0 0 0 0 0 0
39282 - 0 0 0 0 0 0 0 0 0 0 0 0
39283 - 0 0 0 0 0 0 0 0 0 0 0 0
39284 - 0 0 0 0 0 0 0 0 0 0 0 0
39285 - 0 0 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 14 14 14
39289 - 46 46 46 86 86 86 2 2 6 14 14 14
39290 -134 134 134 198 198 198 195 195 195 116 116 116
39291 - 10 10 10 2 2 6 2 2 6 6 6 6
39292 -101 98 89 187 187 187 210 210 210 218 218 218
39293 -214 214 214 134 134 134 14 14 14 6 6 6
39294 - 2 2 6 2 2 6 2 2 6 2 2 6
39295 - 86 86 86 50 50 50 18 18 18 6 6 6
39296 - 0 0 0 0 0 0 0 0 0 0 0 0
39297 - 0 0 0 0 0 0 0 0 0 0 0 0
39298 - 0 0 0 0 0 0 0 0 0 0 0 0
39299 - 0 0 0 0 0 0 0 0 0 0 0 0
39300 - 0 0 0 0 0 0 0 0 0 0 0 0
39301 - 0 0 0 0 0 0 0 0 0 0 0 0
39302 - 0 0 0 0 0 0 0 0 1 0 0 0
39303 - 0 0 1 0 0 1 0 0 1 0 0 0
39304 - 0 0 0 0 0 0 0 0 0 0 0 0
39305 - 0 0 0 0 0 0 0 0 0 0 0 0
39306 - 0 0 0 0 0 0 0 0 0 0 0 0
39307 - 0 0 0 0 0 0 0 0 0 0 0 0
39308 - 0 0 0 0 0 0 0 0 0 14 14 14
39309 - 46 46 46 86 86 86 2 2 6 54 54 54
39310 -218 218 218 195 195 195 226 226 226 246 246 246
39311 - 58 58 58 2 2 6 2 2 6 30 30 30
39312 -210 210 210 253 253 253 174 174 174 123 123 123
39313 -221 221 221 234 234 234 74 74 74 2 2 6
39314 - 2 2 6 2 2 6 2 2 6 2 2 6
39315 - 70 70 70 58 58 58 22 22 22 6 6 6
39316 - 0 0 0 0 0 0 0 0 0 0 0 0
39317 - 0 0 0 0 0 0 0 0 0 0 0 0
39318 - 0 0 0 0 0 0 0 0 0 0 0 0
39319 - 0 0 0 0 0 0 0 0 0 0 0 0
39320 - 0 0 0 0 0 0 0 0 0 0 0 0
39321 - 0 0 0 0 0 0 0 0 0 0 0 0
39322 - 0 0 0 0 0 0 0 0 0 0 0 0
39323 - 0 0 0 0 0 0 0 0 0 0 0 0
39324 - 0 0 0 0 0 0 0 0 0 0 0 0
39325 - 0 0 0 0 0 0 0 0 0 0 0 0
39326 - 0 0 0 0 0 0 0 0 0 0 0 0
39327 - 0 0 0 0 0 0 0 0 0 0 0 0
39328 - 0 0 0 0 0 0 0 0 0 14 14 14
39329 - 46 46 46 82 82 82 2 2 6 106 106 106
39330 -170 170 170 26 26 26 86 86 86 226 226 226
39331 -123 123 123 10 10 10 14 14 14 46 46 46
39332 -231 231 231 190 190 190 6 6 6 70 70 70
39333 - 90 90 90 238 238 238 158 158 158 2 2 6
39334 - 2 2 6 2 2 6 2 2 6 2 2 6
39335 - 70 70 70 58 58 58 22 22 22 6 6 6
39336 - 0 0 0 0 0 0 0 0 0 0 0 0
39337 - 0 0 0 0 0 0 0 0 0 0 0 0
39338 - 0 0 0 0 0 0 0 0 0 0 0 0
39339 - 0 0 0 0 0 0 0 0 0 0 0 0
39340 - 0 0 0 0 0 0 0 0 0 0 0 0
39341 - 0 0 0 0 0 0 0 0 0 0 0 0
39342 - 0 0 0 0 0 0 0 0 1 0 0 0
39343 - 0 0 1 0 0 1 0 0 1 0 0 0
39344 - 0 0 0 0 0 0 0 0 0 0 0 0
39345 - 0 0 0 0 0 0 0 0 0 0 0 0
39346 - 0 0 0 0 0 0 0 0 0 0 0 0
39347 - 0 0 0 0 0 0 0 0 0 0 0 0
39348 - 0 0 0 0 0 0 0 0 0 14 14 14
39349 - 42 42 42 86 86 86 6 6 6 116 116 116
39350 -106 106 106 6 6 6 70 70 70 149 149 149
39351 -128 128 128 18 18 18 38 38 38 54 54 54
39352 -221 221 221 106 106 106 2 2 6 14 14 14
39353 - 46 46 46 190 190 190 198 198 198 2 2 6
39354 - 2 2 6 2 2 6 2 2 6 2 2 6
39355 - 74 74 74 62 62 62 22 22 22 6 6 6
39356 - 0 0 0 0 0 0 0 0 0 0 0 0
39357 - 0 0 0 0 0 0 0 0 0 0 0 0
39358 - 0 0 0 0 0 0 0 0 0 0 0 0
39359 - 0 0 0 0 0 0 0 0 0 0 0 0
39360 - 0 0 0 0 0 0 0 0 0 0 0 0
39361 - 0 0 0 0 0 0 0 0 0 0 0 0
39362 - 0 0 0 0 0 0 0 0 1 0 0 0
39363 - 0 0 1 0 0 0 0 0 1 0 0 0
39364 - 0 0 0 0 0 0 0 0 0 0 0 0
39365 - 0 0 0 0 0 0 0 0 0 0 0 0
39366 - 0 0 0 0 0 0 0 0 0 0 0 0
39367 - 0 0 0 0 0 0 0 0 0 0 0 0
39368 - 0 0 0 0 0 0 0 0 0 14 14 14
39369 - 42 42 42 94 94 94 14 14 14 101 101 101
39370 -128 128 128 2 2 6 18 18 18 116 116 116
39371 -118 98 46 121 92 8 121 92 8 98 78 10
39372 -162 162 162 106 106 106 2 2 6 2 2 6
39373 - 2 2 6 195 195 195 195 195 195 6 6 6
39374 - 2 2 6 2 2 6 2 2 6 2 2 6
39375 - 74 74 74 62 62 62 22 22 22 6 6 6
39376 - 0 0 0 0 0 0 0 0 0 0 0 0
39377 - 0 0 0 0 0 0 0 0 0 0 0 0
39378 - 0 0 0 0 0 0 0 0 0 0 0 0
39379 - 0 0 0 0 0 0 0 0 0 0 0 0
39380 - 0 0 0 0 0 0 0 0 0 0 0 0
39381 - 0 0 0 0 0 0 0 0 0 0 0 0
39382 - 0 0 0 0 0 0 0 0 1 0 0 1
39383 - 0 0 1 0 0 0 0 0 1 0 0 0
39384 - 0 0 0 0 0 0 0 0 0 0 0 0
39385 - 0 0 0 0 0 0 0 0 0 0 0 0
39386 - 0 0 0 0 0 0 0 0 0 0 0 0
39387 - 0 0 0 0 0 0 0 0 0 0 0 0
39388 - 0 0 0 0 0 0 0 0 0 10 10 10
39389 - 38 38 38 90 90 90 14 14 14 58 58 58
39390 -210 210 210 26 26 26 54 38 6 154 114 10
39391 -226 170 11 236 186 11 225 175 15 184 144 12
39392 -215 174 15 175 146 61 37 26 9 2 2 6
39393 - 70 70 70 246 246 246 138 138 138 2 2 6
39394 - 2 2 6 2 2 6 2 2 6 2 2 6
39395 - 70 70 70 66 66 66 26 26 26 6 6 6
39396 - 0 0 0 0 0 0 0 0 0 0 0 0
39397 - 0 0 0 0 0 0 0 0 0 0 0 0
39398 - 0 0 0 0 0 0 0 0 0 0 0 0
39399 - 0 0 0 0 0 0 0 0 0 0 0 0
39400 - 0 0 0 0 0 0 0 0 0 0 0 0
39401 - 0 0 0 0 0 0 0 0 0 0 0 0
39402 - 0 0 0 0 0 0 0 0 0 0 0 0
39403 - 0 0 0 0 0 0 0 0 0 0 0 0
39404 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39409 - 38 38 38 86 86 86 14 14 14 10 10 10
39410 -195 195 195 188 164 115 192 133 9 225 175 15
39411 -239 182 13 234 190 10 232 195 16 232 200 30
39412 -245 207 45 241 208 19 232 195 16 184 144 12
39413 -218 194 134 211 206 186 42 42 42 2 2 6
39414 - 2 2 6 2 2 6 2 2 6 2 2 6
39415 - 50 50 50 74 74 74 30 30 30 6 6 6
39416 - 0 0 0 0 0 0 0 0 0 0 0 0
39417 - 0 0 0 0 0 0 0 0 0 0 0 0
39418 - 0 0 0 0 0 0 0 0 0 0 0 0
39419 - 0 0 0 0 0 0 0 0 0 0 0 0
39420 - 0 0 0 0 0 0 0 0 0 0 0 0
39421 - 0 0 0 0 0 0 0 0 0 0 0 0
39422 - 0 0 0 0 0 0 0 0 0 0 0 0
39423 - 0 0 0 0 0 0 0 0 0 0 0 0
39424 - 0 0 0 0 0 0 0 0 0 0 0 0
39425 - 0 0 0 0 0 0 0 0 0 0 0 0
39426 - 0 0 0 0 0 0 0 0 0 0 0 0
39427 - 0 0 0 0 0 0 0 0 0 0 0 0
39428 - 0 0 0 0 0 0 0 0 0 10 10 10
39429 - 34 34 34 86 86 86 14 14 14 2 2 6
39430 -121 87 25 192 133 9 219 162 10 239 182 13
39431 -236 186 11 232 195 16 241 208 19 244 214 54
39432 -246 218 60 246 218 38 246 215 20 241 208 19
39433 -241 208 19 226 184 13 121 87 25 2 2 6
39434 - 2 2 6 2 2 6 2 2 6 2 2 6
39435 - 50 50 50 82 82 82 34 34 34 10 10 10
39436 - 0 0 0 0 0 0 0 0 0 0 0 0
39437 - 0 0 0 0 0 0 0 0 0 0 0 0
39438 - 0 0 0 0 0 0 0 0 0 0 0 0
39439 - 0 0 0 0 0 0 0 0 0 0 0 0
39440 - 0 0 0 0 0 0 0 0 0 0 0 0
39441 - 0 0 0 0 0 0 0 0 0 0 0 0
39442 - 0 0 0 0 0 0 0 0 0 0 0 0
39443 - 0 0 0 0 0 0 0 0 0 0 0 0
39444 - 0 0 0 0 0 0 0 0 0 0 0 0
39445 - 0 0 0 0 0 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 10 10 10
39449 - 34 34 34 82 82 82 30 30 30 61 42 6
39450 -180 123 7 206 145 10 230 174 11 239 182 13
39451 -234 190 10 238 202 15 241 208 19 246 218 74
39452 -246 218 38 246 215 20 246 215 20 246 215 20
39453 -226 184 13 215 174 15 184 144 12 6 6 6
39454 - 2 2 6 2 2 6 2 2 6 2 2 6
39455 - 26 26 26 94 94 94 42 42 42 14 14 14
39456 - 0 0 0 0 0 0 0 0 0 0 0 0
39457 - 0 0 0 0 0 0 0 0 0 0 0 0
39458 - 0 0 0 0 0 0 0 0 0 0 0 0
39459 - 0 0 0 0 0 0 0 0 0 0 0 0
39460 - 0 0 0 0 0 0 0 0 0 0 0 0
39461 - 0 0 0 0 0 0 0 0 0 0 0 0
39462 - 0 0 0 0 0 0 0 0 0 0 0 0
39463 - 0 0 0 0 0 0 0 0 0 0 0 0
39464 - 0 0 0 0 0 0 0 0 0 0 0 0
39465 - 0 0 0 0 0 0 0 0 0 0 0 0
39466 - 0 0 0 0 0 0 0 0 0 0 0 0
39467 - 0 0 0 0 0 0 0 0 0 0 0 0
39468 - 0 0 0 0 0 0 0 0 0 10 10 10
39469 - 30 30 30 78 78 78 50 50 50 104 69 6
39470 -192 133 9 216 158 10 236 178 12 236 186 11
39471 -232 195 16 241 208 19 244 214 54 245 215 43
39472 -246 215 20 246 215 20 241 208 19 198 155 10
39473 -200 144 11 216 158 10 156 118 10 2 2 6
39474 - 2 2 6 2 2 6 2 2 6 2 2 6
39475 - 6 6 6 90 90 90 54 54 54 18 18 18
39476 - 6 6 6 0 0 0 0 0 0 0 0 0
39477 - 0 0 0 0 0 0 0 0 0 0 0 0
39478 - 0 0 0 0 0 0 0 0 0 0 0 0
39479 - 0 0 0 0 0 0 0 0 0 0 0 0
39480 - 0 0 0 0 0 0 0 0 0 0 0 0
39481 - 0 0 0 0 0 0 0 0 0 0 0 0
39482 - 0 0 0 0 0 0 0 0 0 0 0 0
39483 - 0 0 0 0 0 0 0 0 0 0 0 0
39484 - 0 0 0 0 0 0 0 0 0 0 0 0
39485 - 0 0 0 0 0 0 0 0 0 0 0 0
39486 - 0 0 0 0 0 0 0 0 0 0 0 0
39487 - 0 0 0 0 0 0 0 0 0 0 0 0
39488 - 0 0 0 0 0 0 0 0 0 10 10 10
39489 - 30 30 30 78 78 78 46 46 46 22 22 22
39490 -137 92 6 210 162 10 239 182 13 238 190 10
39491 -238 202 15 241 208 19 246 215 20 246 215 20
39492 -241 208 19 203 166 17 185 133 11 210 150 10
39493 -216 158 10 210 150 10 102 78 10 2 2 6
39494 - 6 6 6 54 54 54 14 14 14 2 2 6
39495 - 2 2 6 62 62 62 74 74 74 30 30 30
39496 - 10 10 10 0 0 0 0 0 0 0 0 0
39497 - 0 0 0 0 0 0 0 0 0 0 0 0
39498 - 0 0 0 0 0 0 0 0 0 0 0 0
39499 - 0 0 0 0 0 0 0 0 0 0 0 0
39500 - 0 0 0 0 0 0 0 0 0 0 0 0
39501 - 0 0 0 0 0 0 0 0 0 0 0 0
39502 - 0 0 0 0 0 0 0 0 0 0 0 0
39503 - 0 0 0 0 0 0 0 0 0 0 0 0
39504 - 0 0 0 0 0 0 0 0 0 0 0 0
39505 - 0 0 0 0 0 0 0 0 0 0 0 0
39506 - 0 0 0 0 0 0 0 0 0 0 0 0
39507 - 0 0 0 0 0 0 0 0 0 0 0 0
39508 - 0 0 0 0 0 0 0 0 0 10 10 10
39509 - 34 34 34 78 78 78 50 50 50 6 6 6
39510 - 94 70 30 139 102 15 190 146 13 226 184 13
39511 -232 200 30 232 195 16 215 174 15 190 146 13
39512 -168 122 10 192 133 9 210 150 10 213 154 11
39513 -202 150 34 182 157 106 101 98 89 2 2 6
39514 - 2 2 6 78 78 78 116 116 116 58 58 58
39515 - 2 2 6 22 22 22 90 90 90 46 46 46
39516 - 18 18 18 6 6 6 0 0 0 0 0 0
39517 - 0 0 0 0 0 0 0 0 0 0 0 0
39518 - 0 0 0 0 0 0 0 0 0 0 0 0
39519 - 0 0 0 0 0 0 0 0 0 0 0 0
39520 - 0 0 0 0 0 0 0 0 0 0 0 0
39521 - 0 0 0 0 0 0 0 0 0 0 0 0
39522 - 0 0 0 0 0 0 0 0 0 0 0 0
39523 - 0 0 0 0 0 0 0 0 0 0 0 0
39524 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39529 - 38 38 38 86 86 86 50 50 50 6 6 6
39530 -128 128 128 174 154 114 156 107 11 168 122 10
39531 -198 155 10 184 144 12 197 138 11 200 144 11
39532 -206 145 10 206 145 10 197 138 11 188 164 115
39533 -195 195 195 198 198 198 174 174 174 14 14 14
39534 - 2 2 6 22 22 22 116 116 116 116 116 116
39535 - 22 22 22 2 2 6 74 74 74 70 70 70
39536 - 30 30 30 10 10 10 0 0 0 0 0 0
39537 - 0 0 0 0 0 0 0 0 0 0 0 0
39538 - 0 0 0 0 0 0 0 0 0 0 0 0
39539 - 0 0 0 0 0 0 0 0 0 0 0 0
39540 - 0 0 0 0 0 0 0 0 0 0 0 0
39541 - 0 0 0 0 0 0 0 0 0 0 0 0
39542 - 0 0 0 0 0 0 0 0 0 0 0 0
39543 - 0 0 0 0 0 0 0 0 0 0 0 0
39544 - 0 0 0 0 0 0 0 0 0 0 0 0
39545 - 0 0 0 0 0 0 0 0 0 0 0 0
39546 - 0 0 0 0 0 0 0 0 0 0 0 0
39547 - 0 0 0 0 0 0 0 0 0 0 0 0
39548 - 0 0 0 0 0 0 6 6 6 18 18 18
39549 - 50 50 50 101 101 101 26 26 26 10 10 10
39550 -138 138 138 190 190 190 174 154 114 156 107 11
39551 -197 138 11 200 144 11 197 138 11 192 133 9
39552 -180 123 7 190 142 34 190 178 144 187 187 187
39553 -202 202 202 221 221 221 214 214 214 66 66 66
39554 - 2 2 6 2 2 6 50 50 50 62 62 62
39555 - 6 6 6 2 2 6 10 10 10 90 90 90
39556 - 50 50 50 18 18 18 6 6 6 0 0 0
39557 - 0 0 0 0 0 0 0 0 0 0 0 0
39558 - 0 0 0 0 0 0 0 0 0 0 0 0
39559 - 0 0 0 0 0 0 0 0 0 0 0 0
39560 - 0 0 0 0 0 0 0 0 0 0 0 0
39561 - 0 0 0 0 0 0 0 0 0 0 0 0
39562 - 0 0 0 0 0 0 0 0 0 0 0 0
39563 - 0 0 0 0 0 0 0 0 0 0 0 0
39564 - 0 0 0 0 0 0 0 0 0 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 10 10 10 34 34 34
39569 - 74 74 74 74 74 74 2 2 6 6 6 6
39570 -144 144 144 198 198 198 190 190 190 178 166 146
39571 -154 121 60 156 107 11 156 107 11 168 124 44
39572 -174 154 114 187 187 187 190 190 190 210 210 210
39573 -246 246 246 253 253 253 253 253 253 182 182 182
39574 - 6 6 6 2 2 6 2 2 6 2 2 6
39575 - 2 2 6 2 2 6 2 2 6 62 62 62
39576 - 74 74 74 34 34 34 14 14 14 0 0 0
39577 - 0 0 0 0 0 0 0 0 0 0 0 0
39578 - 0 0 0 0 0 0 0 0 0 0 0 0
39579 - 0 0 0 0 0 0 0 0 0 0 0 0
39580 - 0 0 0 0 0 0 0 0 0 0 0 0
39581 - 0 0 0 0 0 0 0 0 0 0 0 0
39582 - 0 0 0 0 0 0 0 0 0 0 0 0
39583 - 0 0 0 0 0 0 0 0 0 0 0 0
39584 - 0 0 0 0 0 0 0 0 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 10 10 10 22 22 22 54 54 54
39589 - 94 94 94 18 18 18 2 2 6 46 46 46
39590 -234 234 234 221 221 221 190 190 190 190 190 190
39591 -190 190 190 187 187 187 187 187 187 190 190 190
39592 -190 190 190 195 195 195 214 214 214 242 242 242
39593 -253 253 253 253 253 253 253 253 253 253 253 253
39594 - 82 82 82 2 2 6 2 2 6 2 2 6
39595 - 2 2 6 2 2 6 2 2 6 14 14 14
39596 - 86 86 86 54 54 54 22 22 22 6 6 6
39597 - 0 0 0 0 0 0 0 0 0 0 0 0
39598 - 0 0 0 0 0 0 0 0 0 0 0 0
39599 - 0 0 0 0 0 0 0 0 0 0 0 0
39600 - 0 0 0 0 0 0 0 0 0 0 0 0
39601 - 0 0 0 0 0 0 0 0 0 0 0 0
39602 - 0 0 0 0 0 0 0 0 0 0 0 0
39603 - 0 0 0 0 0 0 0 0 0 0 0 0
39604 - 0 0 0 0 0 0 0 0 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 - 6 6 6 18 18 18 46 46 46 90 90 90
39609 - 46 46 46 18 18 18 6 6 6 182 182 182
39610 -253 253 253 246 246 246 206 206 206 190 190 190
39611 -190 190 190 190 190 190 190 190 190 190 190 190
39612 -206 206 206 231 231 231 250 250 250 253 253 253
39613 -253 253 253 253 253 253 253 253 253 253 253 253
39614 -202 202 202 14 14 14 2 2 6 2 2 6
39615 - 2 2 6 2 2 6 2 2 6 2 2 6
39616 - 42 42 42 86 86 86 42 42 42 18 18 18
39617 - 6 6 6 0 0 0 0 0 0 0 0 0
39618 - 0 0 0 0 0 0 0 0 0 0 0 0
39619 - 0 0 0 0 0 0 0 0 0 0 0 0
39620 - 0 0 0 0 0 0 0 0 0 0 0 0
39621 - 0 0 0 0 0 0 0 0 0 0 0 0
39622 - 0 0 0 0 0 0 0 0 0 0 0 0
39623 - 0 0 0 0 0 0 0 0 0 0 0 0
39624 - 0 0 0 0 0 0 0 0 0 0 0 0
39625 - 0 0 0 0 0 0 0 0 0 0 0 0
39626 - 0 0 0 0 0 0 0 0 0 0 0 0
39627 - 0 0 0 0 0 0 0 0 0 6 6 6
39628 - 14 14 14 38 38 38 74 74 74 66 66 66
39629 - 2 2 6 6 6 6 90 90 90 250 250 250
39630 -253 253 253 253 253 253 238 238 238 198 198 198
39631 -190 190 190 190 190 190 195 195 195 221 221 221
39632 -246 246 246 253 253 253 253 253 253 253 253 253
39633 -253 253 253 253 253 253 253 253 253 253 253 253
39634 -253 253 253 82 82 82 2 2 6 2 2 6
39635 - 2 2 6 2 2 6 2 2 6 2 2 6
39636 - 2 2 6 78 78 78 70 70 70 34 34 34
39637 - 14 14 14 6 6 6 0 0 0 0 0 0
39638 - 0 0 0 0 0 0 0 0 0 0 0 0
39639 - 0 0 0 0 0 0 0 0 0 0 0 0
39640 - 0 0 0 0 0 0 0 0 0 0 0 0
39641 - 0 0 0 0 0 0 0 0 0 0 0 0
39642 - 0 0 0 0 0 0 0 0 0 0 0 0
39643 - 0 0 0 0 0 0 0 0 0 0 0 0
39644 - 0 0 0 0 0 0 0 0 0 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 14 14 14
39648 - 34 34 34 66 66 66 78 78 78 6 6 6
39649 - 2 2 6 18 18 18 218 218 218 253 253 253
39650 -253 253 253 253 253 253 253 253 253 246 246 246
39651 -226 226 226 231 231 231 246 246 246 253 253 253
39652 -253 253 253 253 253 253 253 253 253 253 253 253
39653 -253 253 253 253 253 253 253 253 253 253 253 253
39654 -253 253 253 178 178 178 2 2 6 2 2 6
39655 - 2 2 6 2 2 6 2 2 6 2 2 6
39656 - 2 2 6 18 18 18 90 90 90 62 62 62
39657 - 30 30 30 10 10 10 0 0 0 0 0 0
39658 - 0 0 0 0 0 0 0 0 0 0 0 0
39659 - 0 0 0 0 0 0 0 0 0 0 0 0
39660 - 0 0 0 0 0 0 0 0 0 0 0 0
39661 - 0 0 0 0 0 0 0 0 0 0 0 0
39662 - 0 0 0 0 0 0 0 0 0 0 0 0
39663 - 0 0 0 0 0 0 0 0 0 0 0 0
39664 - 0 0 0 0 0 0 0 0 0 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 10 10 10 26 26 26
39668 - 58 58 58 90 90 90 18 18 18 2 2 6
39669 - 2 2 6 110 110 110 253 253 253 253 253 253
39670 -253 253 253 253 253 253 253 253 253 253 253 253
39671 -250 250 250 253 253 253 253 253 253 253 253 253
39672 -253 253 253 253 253 253 253 253 253 253 253 253
39673 -253 253 253 253 253 253 253 253 253 253 253 253
39674 -253 253 253 231 231 231 18 18 18 2 2 6
39675 - 2 2 6 2 2 6 2 2 6 2 2 6
39676 - 2 2 6 2 2 6 18 18 18 94 94 94
39677 - 54 54 54 26 26 26 10 10 10 0 0 0
39678 - 0 0 0 0 0 0 0 0 0 0 0 0
39679 - 0 0 0 0 0 0 0 0 0 0 0 0
39680 - 0 0 0 0 0 0 0 0 0 0 0 0
39681 - 0 0 0 0 0 0 0 0 0 0 0 0
39682 - 0 0 0 0 0 0 0 0 0 0 0 0
39683 - 0 0 0 0 0 0 0 0 0 0 0 0
39684 - 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
39688 - 90 90 90 26 26 26 2 2 6 2 2 6
39689 - 14 14 14 195 195 195 250 250 250 253 253 253
39690 -253 253 253 253 253 253 253 253 253 253 253 253
39691 -253 253 253 253 253 253 253 253 253 253 253 253
39692 -253 253 253 253 253 253 253 253 253 253 253 253
39693 -253 253 253 253 253 253 253 253 253 253 253 253
39694 -250 250 250 242 242 242 54 54 54 2 2 6
39695 - 2 2 6 2 2 6 2 2 6 2 2 6
39696 - 2 2 6 2 2 6 2 2 6 38 38 38
39697 - 86 86 86 50 50 50 22 22 22 6 6 6
39698 - 0 0 0 0 0 0 0 0 0 0 0 0
39699 - 0 0 0 0 0 0 0 0 0 0 0 0
39700 - 0 0 0 0 0 0 0 0 0 0 0 0
39701 - 0 0 0 0 0 0 0 0 0 0 0 0
39702 - 0 0 0 0 0 0 0 0 0 0 0 0
39703 - 0 0 0 0 0 0 0 0 0 0 0 0
39704 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 14 14 14 38 38 38 82 82 82
39708 - 34 34 34 2 2 6 2 2 6 2 2 6
39709 - 42 42 42 195 195 195 246 246 246 253 253 253
39710 -253 253 253 253 253 253 253 253 253 250 250 250
39711 -242 242 242 242 242 242 250 250 250 253 253 253
39712 -253 253 253 253 253 253 253 253 253 253 253 253
39713 -253 253 253 250 250 250 246 246 246 238 238 238
39714 -226 226 226 231 231 231 101 101 101 6 6 6
39715 - 2 2 6 2 2 6 2 2 6 2 2 6
39716 - 2 2 6 2 2 6 2 2 6 2 2 6
39717 - 38 38 38 82 82 82 42 42 42 14 14 14
39718 - 6 6 6 0 0 0 0 0 0 0 0 0
39719 - 0 0 0 0 0 0 0 0 0 0 0 0
39720 - 0 0 0 0 0 0 0 0 0 0 0 0
39721 - 0 0 0 0 0 0 0 0 0 0 0 0
39722 - 0 0 0 0 0 0 0 0 0 0 0 0
39723 - 0 0 0 0 0 0 0 0 0 0 0 0
39724 - 0 0 0 0 0 0 0 0 0 0 0 0
39725 - 0 0 0 0 0 0 0 0 0 0 0 0
39726 - 0 0 0 0 0 0 0 0 0 0 0 0
39727 - 10 10 10 26 26 26 62 62 62 66 66 66
39728 - 2 2 6 2 2 6 2 2 6 6 6 6
39729 - 70 70 70 170 170 170 206 206 206 234 234 234
39730 -246 246 246 250 250 250 250 250 250 238 238 238
39731 -226 226 226 231 231 231 238 238 238 250 250 250
39732 -250 250 250 250 250 250 246 246 246 231 231 231
39733 -214 214 214 206 206 206 202 202 202 202 202 202
39734 -198 198 198 202 202 202 182 182 182 18 18 18
39735 - 2 2 6 2 2 6 2 2 6 2 2 6
39736 - 2 2 6 2 2 6 2 2 6 2 2 6
39737 - 2 2 6 62 62 62 66 66 66 30 30 30
39738 - 10 10 10 0 0 0 0 0 0 0 0 0
39739 - 0 0 0 0 0 0 0 0 0 0 0 0
39740 - 0 0 0 0 0 0 0 0 0 0 0 0
39741 - 0 0 0 0 0 0 0 0 0 0 0 0
39742 - 0 0 0 0 0 0 0 0 0 0 0 0
39743 - 0 0 0 0 0 0 0 0 0 0 0 0
39744 - 0 0 0 0 0 0 0 0 0 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 - 14 14 14 42 42 42 82 82 82 18 18 18
39748 - 2 2 6 2 2 6 2 2 6 10 10 10
39749 - 94 94 94 182 182 182 218 218 218 242 242 242
39750 -250 250 250 253 253 253 253 253 253 250 250 250
39751 -234 234 234 253 253 253 253 253 253 253 253 253
39752 -253 253 253 253 253 253 253 253 253 246 246 246
39753 -238 238 238 226 226 226 210 210 210 202 202 202
39754 -195 195 195 195 195 195 210 210 210 158 158 158
39755 - 6 6 6 14 14 14 50 50 50 14 14 14
39756 - 2 2 6 2 2 6 2 2 6 2 2 6
39757 - 2 2 6 6 6 6 86 86 86 46 46 46
39758 - 18 18 18 6 6 6 0 0 0 0 0 0
39759 - 0 0 0 0 0 0 0 0 0 0 0 0
39760 - 0 0 0 0 0 0 0 0 0 0 0 0
39761 - 0 0 0 0 0 0 0 0 0 0 0 0
39762 - 0 0 0 0 0 0 0 0 0 0 0 0
39763 - 0 0 0 0 0 0 0 0 0 0 0 0
39764 - 0 0 0 0 0 0 0 0 0 0 0 0
39765 - 0 0 0 0 0 0 0 0 0 0 0 0
39766 - 0 0 0 0 0 0 0 0 0 6 6 6
39767 - 22 22 22 54 54 54 70 70 70 2 2 6
39768 - 2 2 6 10 10 10 2 2 6 22 22 22
39769 -166 166 166 231 231 231 250 250 250 253 253 253
39770 -253 253 253 253 253 253 253 253 253 250 250 250
39771 -242 242 242 253 253 253 253 253 253 253 253 253
39772 -253 253 253 253 253 253 253 253 253 253 253 253
39773 -253 253 253 253 253 253 253 253 253 246 246 246
39774 -231 231 231 206 206 206 198 198 198 226 226 226
39775 - 94 94 94 2 2 6 6 6 6 38 38 38
39776 - 30 30 30 2 2 6 2 2 6 2 2 6
39777 - 2 2 6 2 2 6 62 62 62 66 66 66
39778 - 26 26 26 10 10 10 0 0 0 0 0 0
39779 - 0 0 0 0 0 0 0 0 0 0 0 0
39780 - 0 0 0 0 0 0 0 0 0 0 0 0
39781 - 0 0 0 0 0 0 0 0 0 0 0 0
39782 - 0 0 0 0 0 0 0 0 0 0 0 0
39783 - 0 0 0 0 0 0 0 0 0 0 0 0
39784 - 0 0 0 0 0 0 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 10 10 10
39787 - 30 30 30 74 74 74 50 50 50 2 2 6
39788 - 26 26 26 26 26 26 2 2 6 106 106 106
39789 -238 238 238 253 253 253 253 253 253 253 253 253
39790 -253 253 253 253 253 253 253 253 253 253 253 253
39791 -253 253 253 253 253 253 253 253 253 253 253 253
39792 -253 253 253 253 253 253 253 253 253 253 253 253
39793 -253 253 253 253 253 253 253 253 253 253 253 253
39794 -253 253 253 246 246 246 218 218 218 202 202 202
39795 -210 210 210 14 14 14 2 2 6 2 2 6
39796 - 30 30 30 22 22 22 2 2 6 2 2 6
39797 - 2 2 6 2 2 6 18 18 18 86 86 86
39798 - 42 42 42 14 14 14 0 0 0 0 0 0
39799 - 0 0 0 0 0 0 0 0 0 0 0 0
39800 - 0 0 0 0 0 0 0 0 0 0 0 0
39801 - 0 0 0 0 0 0 0 0 0 0 0 0
39802 - 0 0 0 0 0 0 0 0 0 0 0 0
39803 - 0 0 0 0 0 0 0 0 0 0 0 0
39804 - 0 0 0 0 0 0 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 14 14 14
39807 - 42 42 42 90 90 90 22 22 22 2 2 6
39808 - 42 42 42 2 2 6 18 18 18 218 218 218
39809 -253 253 253 253 253 253 253 253 253 253 253 253
39810 -253 253 253 253 253 253 253 253 253 253 253 253
39811 -253 253 253 253 253 253 253 253 253 253 253 253
39812 -253 253 253 253 253 253 253 253 253 253 253 253
39813 -253 253 253 253 253 253 253 253 253 253 253 253
39814 -253 253 253 253 253 253 250 250 250 221 221 221
39815 -218 218 218 101 101 101 2 2 6 14 14 14
39816 - 18 18 18 38 38 38 10 10 10 2 2 6
39817 - 2 2 6 2 2 6 2 2 6 78 78 78
39818 - 58 58 58 22 22 22 6 6 6 0 0 0
39819 - 0 0 0 0 0 0 0 0 0 0 0 0
39820 - 0 0 0 0 0 0 0 0 0 0 0 0
39821 - 0 0 0 0 0 0 0 0 0 0 0 0
39822 - 0 0 0 0 0 0 0 0 0 0 0 0
39823 - 0 0 0 0 0 0 0 0 0 0 0 0
39824 - 0 0 0 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 6 6 6 18 18 18
39827 - 54 54 54 82 82 82 2 2 6 26 26 26
39828 - 22 22 22 2 2 6 123 123 123 253 253 253
39829 -253 253 253 253 253 253 253 253 253 253 253 253
39830 -253 253 253 253 253 253 253 253 253 253 253 253
39831 -253 253 253 253 253 253 253 253 253 253 253 253
39832 -253 253 253 253 253 253 253 253 253 253 253 253
39833 -253 253 253 253 253 253 253 253 253 253 253 253
39834 -253 253 253 253 253 253 253 253 253 250 250 250
39835 -238 238 238 198 198 198 6 6 6 38 38 38
39836 - 58 58 58 26 26 26 38 38 38 2 2 6
39837 - 2 2 6 2 2 6 2 2 6 46 46 46
39838 - 78 78 78 30 30 30 10 10 10 0 0 0
39839 - 0 0 0 0 0 0 0 0 0 0 0 0
39840 - 0 0 0 0 0 0 0 0 0 0 0 0
39841 - 0 0 0 0 0 0 0 0 0 0 0 0
39842 - 0 0 0 0 0 0 0 0 0 0 0 0
39843 - 0 0 0 0 0 0 0 0 0 0 0 0
39844 - 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 10 10 10 30 30 30
39847 - 74 74 74 58 58 58 2 2 6 42 42 42
39848 - 2 2 6 22 22 22 231 231 231 253 253 253
39849 -253 253 253 253 253 253 253 253 253 253 253 253
39850 -253 253 253 253 253 253 253 253 253 250 250 250
39851 -253 253 253 253 253 253 253 253 253 253 253 253
39852 -253 253 253 253 253 253 253 253 253 253 253 253
39853 -253 253 253 253 253 253 253 253 253 253 253 253
39854 -253 253 253 253 253 253 253 253 253 253 253 253
39855 -253 253 253 246 246 246 46 46 46 38 38 38
39856 - 42 42 42 14 14 14 38 38 38 14 14 14
39857 - 2 2 6 2 2 6 2 2 6 6 6 6
39858 - 86 86 86 46 46 46 14 14 14 0 0 0
39859 - 0 0 0 0 0 0 0 0 0 0 0 0
39860 - 0 0 0 0 0 0 0 0 0 0 0 0
39861 - 0 0 0 0 0 0 0 0 0 0 0 0
39862 - 0 0 0 0 0 0 0 0 0 0 0 0
39863 - 0 0 0 0 0 0 0 0 0 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 6 6 6 14 14 14 42 42 42
39867 - 90 90 90 18 18 18 18 18 18 26 26 26
39868 - 2 2 6 116 116 116 253 253 253 253 253 253
39869 -253 253 253 253 253 253 253 253 253 253 253 253
39870 -253 253 253 253 253 253 250 250 250 238 238 238
39871 -253 253 253 253 253 253 253 253 253 253 253 253
39872 -253 253 253 253 253 253 253 253 253 253 253 253
39873 -253 253 253 253 253 253 253 253 253 253 253 253
39874 -253 253 253 253 253 253 253 253 253 253 253 253
39875 -253 253 253 253 253 253 94 94 94 6 6 6
39876 - 2 2 6 2 2 6 10 10 10 34 34 34
39877 - 2 2 6 2 2 6 2 2 6 2 2 6
39878 - 74 74 74 58 58 58 22 22 22 6 6 6
39879 - 0 0 0 0 0 0 0 0 0 0 0 0
39880 - 0 0 0 0 0 0 0 0 0 0 0 0
39881 - 0 0 0 0 0 0 0 0 0 0 0 0
39882 - 0 0 0 0 0 0 0 0 0 0 0 0
39883 - 0 0 0 0 0 0 0 0 0 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 10 10 10 26 26 26 66 66 66
39887 - 82 82 82 2 2 6 38 38 38 6 6 6
39888 - 14 14 14 210 210 210 253 253 253 253 253 253
39889 -253 253 253 253 253 253 253 253 253 253 253 253
39890 -253 253 253 253 253 253 246 246 246 242 242 242
39891 -253 253 253 253 253 253 253 253 253 253 253 253
39892 -253 253 253 253 253 253 253 253 253 253 253 253
39893 -253 253 253 253 253 253 253 253 253 253 253 253
39894 -253 253 253 253 253 253 253 253 253 253 253 253
39895 -253 253 253 253 253 253 144 144 144 2 2 6
39896 - 2 2 6 2 2 6 2 2 6 46 46 46
39897 - 2 2 6 2 2 6 2 2 6 2 2 6
39898 - 42 42 42 74 74 74 30 30 30 10 10 10
39899 - 0 0 0 0 0 0 0 0 0 0 0 0
39900 - 0 0 0 0 0 0 0 0 0 0 0 0
39901 - 0 0 0 0 0 0 0 0 0 0 0 0
39902 - 0 0 0 0 0 0 0 0 0 0 0 0
39903 - 0 0 0 0 0 0 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 - 6 6 6 14 14 14 42 42 42 90 90 90
39907 - 26 26 26 6 6 6 42 42 42 2 2 6
39908 - 74 74 74 250 250 250 253 253 253 253 253 253
39909 -253 253 253 253 253 253 253 253 253 253 253 253
39910 -253 253 253 253 253 253 242 242 242 242 242 242
39911 -253 253 253 253 253 253 253 253 253 253 253 253
39912 -253 253 253 253 253 253 253 253 253 253 253 253
39913 -253 253 253 253 253 253 253 253 253 253 253 253
39914 -253 253 253 253 253 253 253 253 253 253 253 253
39915 -253 253 253 253 253 253 182 182 182 2 2 6
39916 - 2 2 6 2 2 6 2 2 6 46 46 46
39917 - 2 2 6 2 2 6 2 2 6 2 2 6
39918 - 10 10 10 86 86 86 38 38 38 10 10 10
39919 - 0 0 0 0 0 0 0 0 0 0 0 0
39920 - 0 0 0 0 0 0 0 0 0 0 0 0
39921 - 0 0 0 0 0 0 0 0 0 0 0 0
39922 - 0 0 0 0 0 0 0 0 0 0 0 0
39923 - 0 0 0 0 0 0 0 0 0 0 0 0
39924 - 0 0 0 0 0 0 0 0 0 0 0 0
39925 - 0 0 0 0 0 0 0 0 0 0 0 0
39926 - 10 10 10 26 26 26 66 66 66 82 82 82
39927 - 2 2 6 22 22 22 18 18 18 2 2 6
39928 -149 149 149 253 253 253 253 253 253 253 253 253
39929 -253 253 253 253 253 253 253 253 253 253 253 253
39930 -253 253 253 253 253 253 234 234 234 242 242 242
39931 -253 253 253 253 253 253 253 253 253 253 253 253
39932 -253 253 253 253 253 253 253 253 253 253 253 253
39933 -253 253 253 253 253 253 253 253 253 253 253 253
39934 -253 253 253 253 253 253 253 253 253 253 253 253
39935 -253 253 253 253 253 253 206 206 206 2 2 6
39936 - 2 2 6 2 2 6 2 2 6 38 38 38
39937 - 2 2 6 2 2 6 2 2 6 2 2 6
39938 - 6 6 6 86 86 86 46 46 46 14 14 14
39939 - 0 0 0 0 0 0 0 0 0 0 0 0
39940 - 0 0 0 0 0 0 0 0 0 0 0 0
39941 - 0 0 0 0 0 0 0 0 0 0 0 0
39942 - 0 0 0 0 0 0 0 0 0 0 0 0
39943 - 0 0 0 0 0 0 0 0 0 0 0 0
39944 - 0 0 0 0 0 0 0 0 0 0 0 0
39945 - 0 0 0 0 0 0 0 0 0 6 6 6
39946 - 18 18 18 46 46 46 86 86 86 18 18 18
39947 - 2 2 6 34 34 34 10 10 10 6 6 6
39948 -210 210 210 253 253 253 253 253 253 253 253 253
39949 -253 253 253 253 253 253 253 253 253 253 253 253
39950 -253 253 253 253 253 253 234 234 234 242 242 242
39951 -253 253 253 253 253 253 253 253 253 253 253 253
39952 -253 253 253 253 253 253 253 253 253 253 253 253
39953 -253 253 253 253 253 253 253 253 253 253 253 253
39954 -253 253 253 253 253 253 253 253 253 253 253 253
39955 -253 253 253 253 253 253 221 221 221 6 6 6
39956 - 2 2 6 2 2 6 6 6 6 30 30 30
39957 - 2 2 6 2 2 6 2 2 6 2 2 6
39958 - 2 2 6 82 82 82 54 54 54 18 18 18
39959 - 6 6 6 0 0 0 0 0 0 0 0 0
39960 - 0 0 0 0 0 0 0 0 0 0 0 0
39961 - 0 0 0 0 0 0 0 0 0 0 0 0
39962 - 0 0 0 0 0 0 0 0 0 0 0 0
39963 - 0 0 0 0 0 0 0 0 0 0 0 0
39964 - 0 0 0 0 0 0 0 0 0 0 0 0
39965 - 0 0 0 0 0 0 0 0 0 10 10 10
39966 - 26 26 26 66 66 66 62 62 62 2 2 6
39967 - 2 2 6 38 38 38 10 10 10 26 26 26
39968 -238 238 238 253 253 253 253 253 253 253 253 253
39969 -253 253 253 253 253 253 253 253 253 253 253 253
39970 -253 253 253 253 253 253 231 231 231 238 238 238
39971 -253 253 253 253 253 253 253 253 253 253 253 253
39972 -253 253 253 253 253 253 253 253 253 253 253 253
39973 -253 253 253 253 253 253 253 253 253 253 253 253
39974 -253 253 253 253 253 253 253 253 253 253 253 253
39975 -253 253 253 253 253 253 231 231 231 6 6 6
39976 - 2 2 6 2 2 6 10 10 10 30 30 30
39977 - 2 2 6 2 2 6 2 2 6 2 2 6
39978 - 2 2 6 66 66 66 58 58 58 22 22 22
39979 - 6 6 6 0 0 0 0 0 0 0 0 0
39980 - 0 0 0 0 0 0 0 0 0 0 0 0
39981 - 0 0 0 0 0 0 0 0 0 0 0 0
39982 - 0 0 0 0 0 0 0 0 0 0 0 0
39983 - 0 0 0 0 0 0 0 0 0 0 0 0
39984 - 0 0 0 0 0 0 0 0 0 0 0 0
39985 - 0 0 0 0 0 0 0 0 0 10 10 10
39986 - 38 38 38 78 78 78 6 6 6 2 2 6
39987 - 2 2 6 46 46 46 14 14 14 42 42 42
39988 -246 246 246 253 253 253 253 253 253 253 253 253
39989 -253 253 253 253 253 253 253 253 253 253 253 253
39990 -253 253 253 253 253 253 231 231 231 242 242 242
39991 -253 253 253 253 253 253 253 253 253 253 253 253
39992 -253 253 253 253 253 253 253 253 253 253 253 253
39993 -253 253 253 253 253 253 253 253 253 253 253 253
39994 -253 253 253 253 253 253 253 253 253 253 253 253
39995 -253 253 253 253 253 253 234 234 234 10 10 10
39996 - 2 2 6 2 2 6 22 22 22 14 14 14
39997 - 2 2 6 2 2 6 2 2 6 2 2 6
39998 - 2 2 6 66 66 66 62 62 62 22 22 22
39999 - 6 6 6 0 0 0 0 0 0 0 0 0
40000 - 0 0 0 0 0 0 0 0 0 0 0 0
40001 - 0 0 0 0 0 0 0 0 0 0 0 0
40002 - 0 0 0 0 0 0 0 0 0 0 0 0
40003 - 0 0 0 0 0 0 0 0 0 0 0 0
40004 - 0 0 0 0 0 0 0 0 0 0 0 0
40005 - 0 0 0 0 0 0 6 6 6 18 18 18
40006 - 50 50 50 74 74 74 2 2 6 2 2 6
40007 - 14 14 14 70 70 70 34 34 34 62 62 62
40008 -250 250 250 253 253 253 253 253 253 253 253 253
40009 -253 253 253 253 253 253 253 253 253 253 253 253
40010 -253 253 253 253 253 253 231 231 231 246 246 246
40011 -253 253 253 253 253 253 253 253 253 253 253 253
40012 -253 253 253 253 253 253 253 253 253 253 253 253
40013 -253 253 253 253 253 253 253 253 253 253 253 253
40014 -253 253 253 253 253 253 253 253 253 253 253 253
40015 -253 253 253 253 253 253 234 234 234 14 14 14
40016 - 2 2 6 2 2 6 30 30 30 2 2 6
40017 - 2 2 6 2 2 6 2 2 6 2 2 6
40018 - 2 2 6 66 66 66 62 62 62 22 22 22
40019 - 6 6 6 0 0 0 0 0 0 0 0 0
40020 - 0 0 0 0 0 0 0 0 0 0 0 0
40021 - 0 0 0 0 0 0 0 0 0 0 0 0
40022 - 0 0 0 0 0 0 0 0 0 0 0 0
40023 - 0 0 0 0 0 0 0 0 0 0 0 0
40024 - 0 0 0 0 0 0 0 0 0 0 0 0
40025 - 0 0 0 0 0 0 6 6 6 18 18 18
40026 - 54 54 54 62 62 62 2 2 6 2 2 6
40027 - 2 2 6 30 30 30 46 46 46 70 70 70
40028 -250 250 250 253 253 253 253 253 253 253 253 253
40029 -253 253 253 253 253 253 253 253 253 253 253 253
40030 -253 253 253 253 253 253 231 231 231 246 246 246
40031 -253 253 253 253 253 253 253 253 253 253 253 253
40032 -253 253 253 253 253 253 253 253 253 253 253 253
40033 -253 253 253 253 253 253 253 253 253 253 253 253
40034 -253 253 253 253 253 253 253 253 253 253 253 253
40035 -253 253 253 253 253 253 226 226 226 10 10 10
40036 - 2 2 6 6 6 6 30 30 30 2 2 6
40037 - 2 2 6 2 2 6 2 2 6 2 2 6
40038 - 2 2 6 66 66 66 58 58 58 22 22 22
40039 - 6 6 6 0 0 0 0 0 0 0 0 0
40040 - 0 0 0 0 0 0 0 0 0 0 0 0
40041 - 0 0 0 0 0 0 0 0 0 0 0 0
40042 - 0 0 0 0 0 0 0 0 0 0 0 0
40043 - 0 0 0 0 0 0 0 0 0 0 0 0
40044 - 0 0 0 0 0 0 0 0 0 0 0 0
40045 - 0 0 0 0 0 0 6 6 6 22 22 22
40046 - 58 58 58 62 62 62 2 2 6 2 2 6
40047 - 2 2 6 2 2 6 30 30 30 78 78 78
40048 -250 250 250 253 253 253 253 253 253 253 253 253
40049 -253 253 253 253 253 253 253 253 253 253 253 253
40050 -253 253 253 253 253 253 231 231 231 246 246 246
40051 -253 253 253 253 253 253 253 253 253 253 253 253
40052 -253 253 253 253 253 253 253 253 253 253 253 253
40053 -253 253 253 253 253 253 253 253 253 253 253 253
40054 -253 253 253 253 253 253 253 253 253 253 253 253
40055 -253 253 253 253 253 253 206 206 206 2 2 6
40056 - 22 22 22 34 34 34 18 14 6 22 22 22
40057 - 26 26 26 18 18 18 6 6 6 2 2 6
40058 - 2 2 6 82 82 82 54 54 54 18 18 18
40059 - 6 6 6 0 0 0 0 0 0 0 0 0
40060 - 0 0 0 0 0 0 0 0 0 0 0 0
40061 - 0 0 0 0 0 0 0 0 0 0 0 0
40062 - 0 0 0 0 0 0 0 0 0 0 0 0
40063 - 0 0 0 0 0 0 0 0 0 0 0 0
40064 - 0 0 0 0 0 0 0 0 0 0 0 0
40065 - 0 0 0 0 0 0 6 6 6 26 26 26
40066 - 62 62 62 106 106 106 74 54 14 185 133 11
40067 -210 162 10 121 92 8 6 6 6 62 62 62
40068 -238 238 238 253 253 253 253 253 253 253 253 253
40069 -253 253 253 253 253 253 253 253 253 253 253 253
40070 -253 253 253 253 253 253 231 231 231 246 246 246
40071 -253 253 253 253 253 253 253 253 253 253 253 253
40072 -253 253 253 253 253 253 253 253 253 253 253 253
40073 -253 253 253 253 253 253 253 253 253 253 253 253
40074 -253 253 253 253 253 253 253 253 253 253 253 253
40075 -253 253 253 253 253 253 158 158 158 18 18 18
40076 - 14 14 14 2 2 6 2 2 6 2 2 6
40077 - 6 6 6 18 18 18 66 66 66 38 38 38
40078 - 6 6 6 94 94 94 50 50 50 18 18 18
40079 - 6 6 6 0 0 0 0 0 0 0 0 0
40080 - 0 0 0 0 0 0 0 0 0 0 0 0
40081 - 0 0 0 0 0 0 0 0 0 0 0 0
40082 - 0 0 0 0 0 0 0 0 0 0 0 0
40083 - 0 0 0 0 0 0 0 0 0 0 0 0
40084 - 0 0 0 0 0 0 0 0 0 6 6 6
40085 - 10 10 10 10 10 10 18 18 18 38 38 38
40086 - 78 78 78 142 134 106 216 158 10 242 186 14
40087 -246 190 14 246 190 14 156 118 10 10 10 10
40088 - 90 90 90 238 238 238 253 253 253 253 253 253
40089 -253 253 253 253 253 253 253 253 253 253 253 253
40090 -253 253 253 253 253 253 231 231 231 250 250 250
40091 -253 253 253 253 253 253 253 253 253 253 253 253
40092 -253 253 253 253 253 253 253 253 253 253 253 253
40093 -253 253 253 253 253 253 253 253 253 253 253 253
40094 -253 253 253 253 253 253 253 253 253 246 230 190
40095 -238 204 91 238 204 91 181 142 44 37 26 9
40096 - 2 2 6 2 2 6 2 2 6 2 2 6
40097 - 2 2 6 2 2 6 38 38 38 46 46 46
40098 - 26 26 26 106 106 106 54 54 54 18 18 18
40099 - 6 6 6 0 0 0 0 0 0 0 0 0
40100 - 0 0 0 0 0 0 0 0 0 0 0 0
40101 - 0 0 0 0 0 0 0 0 0 0 0 0
40102 - 0 0 0 0 0 0 0 0 0 0 0 0
40103 - 0 0 0 0 0 0 0 0 0 0 0 0
40104 - 0 0 0 6 6 6 14 14 14 22 22 22
40105 - 30 30 30 38 38 38 50 50 50 70 70 70
40106 -106 106 106 190 142 34 226 170 11 242 186 14
40107 -246 190 14 246 190 14 246 190 14 154 114 10
40108 - 6 6 6 74 74 74 226 226 226 253 253 253
40109 -253 253 253 253 253 253 253 253 253 253 253 253
40110 -253 253 253 253 253 253 231 231 231 250 250 250
40111 -253 253 253 253 253 253 253 253 253 253 253 253
40112 -253 253 253 253 253 253 253 253 253 253 253 253
40113 -253 253 253 253 253 253 253 253 253 253 253 253
40114 -253 253 253 253 253 253 253 253 253 228 184 62
40115 -241 196 14 241 208 19 232 195 16 38 30 10
40116 - 2 2 6 2 2 6 2 2 6 2 2 6
40117 - 2 2 6 6 6 6 30 30 30 26 26 26
40118 -203 166 17 154 142 90 66 66 66 26 26 26
40119 - 6 6 6 0 0 0 0 0 0 0 0 0
40120 - 0 0 0 0 0 0 0 0 0 0 0 0
40121 - 0 0 0 0 0 0 0 0 0 0 0 0
40122 - 0 0 0 0 0 0 0 0 0 0 0 0
40123 - 0 0 0 0 0 0 0 0 0 0 0 0
40124 - 6 6 6 18 18 18 38 38 38 58 58 58
40125 - 78 78 78 86 86 86 101 101 101 123 123 123
40126 -175 146 61 210 150 10 234 174 13 246 186 14
40127 -246 190 14 246 190 14 246 190 14 238 190 10
40128 -102 78 10 2 2 6 46 46 46 198 198 198
40129 -253 253 253 253 253 253 253 253 253 253 253 253
40130 -253 253 253 253 253 253 234 234 234 242 242 242
40131 -253 253 253 253 253 253 253 253 253 253 253 253
40132 -253 253 253 253 253 253 253 253 253 253 253 253
40133 -253 253 253 253 253 253 253 253 253 253 253 253
40134 -253 253 253 253 253 253 253 253 253 224 178 62
40135 -242 186 14 241 196 14 210 166 10 22 18 6
40136 - 2 2 6 2 2 6 2 2 6 2 2 6
40137 - 2 2 6 2 2 6 6 6 6 121 92 8
40138 -238 202 15 232 195 16 82 82 82 34 34 34
40139 - 10 10 10 0 0 0 0 0 0 0 0 0
40140 - 0 0 0 0 0 0 0 0 0 0 0 0
40141 - 0 0 0 0 0 0 0 0 0 0 0 0
40142 - 0 0 0 0 0 0 0 0 0 0 0 0
40143 - 0 0 0 0 0 0 0 0 0 0 0 0
40144 - 14 14 14 38 38 38 70 70 70 154 122 46
40145 -190 142 34 200 144 11 197 138 11 197 138 11
40146 -213 154 11 226 170 11 242 186 14 246 190 14
40147 -246 190 14 246 190 14 246 190 14 246 190 14
40148 -225 175 15 46 32 6 2 2 6 22 22 22
40149 -158 158 158 250 250 250 253 253 253 253 253 253
40150 -253 253 253 253 253 253 253 253 253 253 253 253
40151 -253 253 253 253 253 253 253 253 253 253 253 253
40152 -253 253 253 253 253 253 253 253 253 253 253 253
40153 -253 253 253 253 253 253 253 253 253 253 253 253
40154 -253 253 253 250 250 250 242 242 242 224 178 62
40155 -239 182 13 236 186 11 213 154 11 46 32 6
40156 - 2 2 6 2 2 6 2 2 6 2 2 6
40157 - 2 2 6 2 2 6 61 42 6 225 175 15
40158 -238 190 10 236 186 11 112 100 78 42 42 42
40159 - 14 14 14 0 0 0 0 0 0 0 0 0
40160 - 0 0 0 0 0 0 0 0 0 0 0 0
40161 - 0 0 0 0 0 0 0 0 0 0 0 0
40162 - 0 0 0 0 0 0 0 0 0 0 0 0
40163 - 0 0 0 0 0 0 0 0 0 6 6 6
40164 - 22 22 22 54 54 54 154 122 46 213 154 11
40165 -226 170 11 230 174 11 226 170 11 226 170 11
40166 -236 178 12 242 186 14 246 190 14 246 190 14
40167 -246 190 14 246 190 14 246 190 14 246 190 14
40168 -241 196 14 184 144 12 10 10 10 2 2 6
40169 - 6 6 6 116 116 116 242 242 242 253 253 253
40170 -253 253 253 253 253 253 253 253 253 253 253 253
40171 -253 253 253 253 253 253 253 253 253 253 253 253
40172 -253 253 253 253 253 253 253 253 253 253 253 253
40173 -253 253 253 253 253 253 253 253 253 253 253 253
40174 -253 253 253 231 231 231 198 198 198 214 170 54
40175 -236 178 12 236 178 12 210 150 10 137 92 6
40176 - 18 14 6 2 2 6 2 2 6 2 2 6
40177 - 6 6 6 70 47 6 200 144 11 236 178 12
40178 -239 182 13 239 182 13 124 112 88 58 58 58
40179 - 22 22 22 6 6 6 0 0 0 0 0 0
40180 - 0 0 0 0 0 0 0 0 0 0 0 0
40181 - 0 0 0 0 0 0 0 0 0 0 0 0
40182 - 0 0 0 0 0 0 0 0 0 0 0 0
40183 - 0 0 0 0 0 0 0 0 0 10 10 10
40184 - 30 30 30 70 70 70 180 133 36 226 170 11
40185 -239 182 13 242 186 14 242 186 14 246 186 14
40186 -246 190 14 246 190 14 246 190 14 246 190 14
40187 -246 190 14 246 190 14 246 190 14 246 190 14
40188 -246 190 14 232 195 16 98 70 6 2 2 6
40189 - 2 2 6 2 2 6 66 66 66 221 221 221
40190 -253 253 253 253 253 253 253 253 253 253 253 253
40191 -253 253 253 253 253 253 253 253 253 253 253 253
40192 -253 253 253 253 253 253 253 253 253 253 253 253
40193 -253 253 253 253 253 253 253 253 253 253 253 253
40194 -253 253 253 206 206 206 198 198 198 214 166 58
40195 -230 174 11 230 174 11 216 158 10 192 133 9
40196 -163 110 8 116 81 8 102 78 10 116 81 8
40197 -167 114 7 197 138 11 226 170 11 239 182 13
40198 -242 186 14 242 186 14 162 146 94 78 78 78
40199 - 34 34 34 14 14 14 6 6 6 0 0 0
40200 - 0 0 0 0 0 0 0 0 0 0 0 0
40201 - 0 0 0 0 0 0 0 0 0 0 0 0
40202 - 0 0 0 0 0 0 0 0 0 0 0 0
40203 - 0 0 0 0 0 0 0 0 0 6 6 6
40204 - 30 30 30 78 78 78 190 142 34 226 170 11
40205 -239 182 13 246 190 14 246 190 14 246 190 14
40206 -246 190 14 246 190 14 246 190 14 246 190 14
40207 -246 190 14 246 190 14 246 190 14 246 190 14
40208 -246 190 14 241 196 14 203 166 17 22 18 6
40209 - 2 2 6 2 2 6 2 2 6 38 38 38
40210 -218 218 218 253 253 253 253 253 253 253 253 253
40211 -253 253 253 253 253 253 253 253 253 253 253 253
40212 -253 253 253 253 253 253 253 253 253 253 253 253
40213 -253 253 253 253 253 253 253 253 253 253 253 253
40214 -250 250 250 206 206 206 198 198 198 202 162 69
40215 -226 170 11 236 178 12 224 166 10 210 150 10
40216 -200 144 11 197 138 11 192 133 9 197 138 11
40217 -210 150 10 226 170 11 242 186 14 246 190 14
40218 -246 190 14 246 186 14 225 175 15 124 112 88
40219 - 62 62 62 30 30 30 14 14 14 6 6 6
40220 - 0 0 0 0 0 0 0 0 0 0 0 0
40221 - 0 0 0 0 0 0 0 0 0 0 0 0
40222 - 0 0 0 0 0 0 0 0 0 0 0 0
40223 - 0 0 0 0 0 0 0 0 0 10 10 10
40224 - 30 30 30 78 78 78 174 135 50 224 166 10
40225 -239 182 13 246 190 14 246 190 14 246 190 14
40226 -246 190 14 246 190 14 246 190 14 246 190 14
40227 -246 190 14 246 190 14 246 190 14 246 190 14
40228 -246 190 14 246 190 14 241 196 14 139 102 15
40229 - 2 2 6 2 2 6 2 2 6 2 2 6
40230 - 78 78 78 250 250 250 253 253 253 253 253 253
40231 -253 253 253 253 253 253 253 253 253 253 253 253
40232 -253 253 253 253 253 253 253 253 253 253 253 253
40233 -253 253 253 253 253 253 253 253 253 253 253 253
40234 -250 250 250 214 214 214 198 198 198 190 150 46
40235 -219 162 10 236 178 12 234 174 13 224 166 10
40236 -216 158 10 213 154 11 213 154 11 216 158 10
40237 -226 170 11 239 182 13 246 190 14 246 190 14
40238 -246 190 14 246 190 14 242 186 14 206 162 42
40239 -101 101 101 58 58 58 30 30 30 14 14 14
40240 - 6 6 6 0 0 0 0 0 0 0 0 0
40241 - 0 0 0 0 0 0 0 0 0 0 0 0
40242 - 0 0 0 0 0 0 0 0 0 0 0 0
40243 - 0 0 0 0 0 0 0 0 0 10 10 10
40244 - 30 30 30 74 74 74 174 135 50 216 158 10
40245 -236 178 12 246 190 14 246 190 14 246 190 14
40246 -246 190 14 246 190 14 246 190 14 246 190 14
40247 -246 190 14 246 190 14 246 190 14 246 190 14
40248 -246 190 14 246 190 14 241 196 14 226 184 13
40249 - 61 42 6 2 2 6 2 2 6 2 2 6
40250 - 22 22 22 238 238 238 253 253 253 253 253 253
40251 -253 253 253 253 253 253 253 253 253 253 253 253
40252 -253 253 253 253 253 253 253 253 253 253 253 253
40253 -253 253 253 253 253 253 253 253 253 253 253 253
40254 -253 253 253 226 226 226 187 187 187 180 133 36
40255 -216 158 10 236 178 12 239 182 13 236 178 12
40256 -230 174 11 226 170 11 226 170 11 230 174 11
40257 -236 178 12 242 186 14 246 190 14 246 190 14
40258 -246 190 14 246 190 14 246 186 14 239 182 13
40259 -206 162 42 106 106 106 66 66 66 34 34 34
40260 - 14 14 14 6 6 6 0 0 0 0 0 0
40261 - 0 0 0 0 0 0 0 0 0 0 0 0
40262 - 0 0 0 0 0 0 0 0 0 0 0 0
40263 - 0 0 0 0 0 0 0 0 0 6 6 6
40264 - 26 26 26 70 70 70 163 133 67 213 154 11
40265 -236 178 12 246 190 14 246 190 14 246 190 14
40266 -246 190 14 246 190 14 246 190 14 246 190 14
40267 -246 190 14 246 190 14 246 190 14 246 190 14
40268 -246 190 14 246 190 14 246 190 14 241 196 14
40269 -190 146 13 18 14 6 2 2 6 2 2 6
40270 - 46 46 46 246 246 246 253 253 253 253 253 253
40271 -253 253 253 253 253 253 253 253 253 253 253 253
40272 -253 253 253 253 253 253 253 253 253 253 253 253
40273 -253 253 253 253 253 253 253 253 253 253 253 253
40274 -253 253 253 221 221 221 86 86 86 156 107 11
40275 -216 158 10 236 178 12 242 186 14 246 186 14
40276 -242 186 14 239 182 13 239 182 13 242 186 14
40277 -242 186 14 246 186 14 246 190 14 246 190 14
40278 -246 190 14 246 190 14 246 190 14 246 190 14
40279 -242 186 14 225 175 15 142 122 72 66 66 66
40280 - 30 30 30 10 10 10 0 0 0 0 0 0
40281 - 0 0 0 0 0 0 0 0 0 0 0 0
40282 - 0 0 0 0 0 0 0 0 0 0 0 0
40283 - 0 0 0 0 0 0 0 0 0 6 6 6
40284 - 26 26 26 70 70 70 163 133 67 210 150 10
40285 -236 178 12 246 190 14 246 190 14 246 190 14
40286 -246 190 14 246 190 14 246 190 14 246 190 14
40287 -246 190 14 246 190 14 246 190 14 246 190 14
40288 -246 190 14 246 190 14 246 190 14 246 190 14
40289 -232 195 16 121 92 8 34 34 34 106 106 106
40290 -221 221 221 253 253 253 253 253 253 253 253 253
40291 -253 253 253 253 253 253 253 253 253 253 253 253
40292 -253 253 253 253 253 253 253 253 253 253 253 253
40293 -253 253 253 253 253 253 253 253 253 253 253 253
40294 -242 242 242 82 82 82 18 14 6 163 110 8
40295 -216 158 10 236 178 12 242 186 14 246 190 14
40296 -246 190 14 246 190 14 246 190 14 246 190 14
40297 -246 190 14 246 190 14 246 190 14 246 190 14
40298 -246 190 14 246 190 14 246 190 14 246 190 14
40299 -246 190 14 246 190 14 242 186 14 163 133 67
40300 - 46 46 46 18 18 18 6 6 6 0 0 0
40301 - 0 0 0 0 0 0 0 0 0 0 0 0
40302 - 0 0 0 0 0 0 0 0 0 0 0 0
40303 - 0 0 0 0 0 0 0 0 0 10 10 10
40304 - 30 30 30 78 78 78 163 133 67 210 150 10
40305 -236 178 12 246 186 14 246 190 14 246 190 14
40306 -246 190 14 246 190 14 246 190 14 246 190 14
40307 -246 190 14 246 190 14 246 190 14 246 190 14
40308 -246 190 14 246 190 14 246 190 14 246 190 14
40309 -241 196 14 215 174 15 190 178 144 253 253 253
40310 -253 253 253 253 253 253 253 253 253 253 253 253
40311 -253 253 253 253 253 253 253 253 253 253 253 253
40312 -253 253 253 253 253 253 253 253 253 253 253 253
40313 -253 253 253 253 253 253 253 253 253 218 218 218
40314 - 58 58 58 2 2 6 22 18 6 167 114 7
40315 -216 158 10 236 178 12 246 186 14 246 190 14
40316 -246 190 14 246 190 14 246 190 14 246 190 14
40317 -246 190 14 246 190 14 246 190 14 246 190 14
40318 -246 190 14 246 190 14 246 190 14 246 190 14
40319 -246 190 14 246 186 14 242 186 14 190 150 46
40320 - 54 54 54 22 22 22 6 6 6 0 0 0
40321 - 0 0 0 0 0 0 0 0 0 0 0 0
40322 - 0 0 0 0 0 0 0 0 0 0 0 0
40323 - 0 0 0 0 0 0 0 0 0 14 14 14
40324 - 38 38 38 86 86 86 180 133 36 213 154 11
40325 -236 178 12 246 186 14 246 190 14 246 190 14
40326 -246 190 14 246 190 14 246 190 14 246 190 14
40327 -246 190 14 246 190 14 246 190 14 246 190 14
40328 -246 190 14 246 190 14 246 190 14 246 190 14
40329 -246 190 14 232 195 16 190 146 13 214 214 214
40330 -253 253 253 253 253 253 253 253 253 253 253 253
40331 -253 253 253 253 253 253 253 253 253 253 253 253
40332 -253 253 253 253 253 253 253 253 253 253 253 253
40333 -253 253 253 250 250 250 170 170 170 26 26 26
40334 - 2 2 6 2 2 6 37 26 9 163 110 8
40335 -219 162 10 239 182 13 246 186 14 246 190 14
40336 -246 190 14 246 190 14 246 190 14 246 190 14
40337 -246 190 14 246 190 14 246 190 14 246 190 14
40338 -246 190 14 246 190 14 246 190 14 246 190 14
40339 -246 186 14 236 178 12 224 166 10 142 122 72
40340 - 46 46 46 18 18 18 6 6 6 0 0 0
40341 - 0 0 0 0 0 0 0 0 0 0 0 0
40342 - 0 0 0 0 0 0 0 0 0 0 0 0
40343 - 0 0 0 0 0 0 6 6 6 18 18 18
40344 - 50 50 50 109 106 95 192 133 9 224 166 10
40345 -242 186 14 246 190 14 246 190 14 246 190 14
40346 -246 190 14 246 190 14 246 190 14 246 190 14
40347 -246 190 14 246 190 14 246 190 14 246 190 14
40348 -246 190 14 246 190 14 246 190 14 246 190 14
40349 -242 186 14 226 184 13 210 162 10 142 110 46
40350 -226 226 226 253 253 253 253 253 253 253 253 253
40351 -253 253 253 253 253 253 253 253 253 253 253 253
40352 -253 253 253 253 253 253 253 253 253 253 253 253
40353 -198 198 198 66 66 66 2 2 6 2 2 6
40354 - 2 2 6 2 2 6 50 34 6 156 107 11
40355 -219 162 10 239 182 13 246 186 14 246 190 14
40356 -246 190 14 246 190 14 246 190 14 246 190 14
40357 -246 190 14 246 190 14 246 190 14 246 190 14
40358 -246 190 14 246 190 14 246 190 14 242 186 14
40359 -234 174 13 213 154 11 154 122 46 66 66 66
40360 - 30 30 30 10 10 10 0 0 0 0 0 0
40361 - 0 0 0 0 0 0 0 0 0 0 0 0
40362 - 0 0 0 0 0 0 0 0 0 0 0 0
40363 - 0 0 0 0 0 0 6 6 6 22 22 22
40364 - 58 58 58 154 121 60 206 145 10 234 174 13
40365 -242 186 14 246 186 14 246 190 14 246 190 14
40366 -246 190 14 246 190 14 246 190 14 246 190 14
40367 -246 190 14 246 190 14 246 190 14 246 190 14
40368 -246 190 14 246 190 14 246 190 14 246 190 14
40369 -246 186 14 236 178 12 210 162 10 163 110 8
40370 - 61 42 6 138 138 138 218 218 218 250 250 250
40371 -253 253 253 253 253 253 253 253 253 250 250 250
40372 -242 242 242 210 210 210 144 144 144 66 66 66
40373 - 6 6 6 2 2 6 2 2 6 2 2 6
40374 - 2 2 6 2 2 6 61 42 6 163 110 8
40375 -216 158 10 236 178 12 246 190 14 246 190 14
40376 -246 190 14 246 190 14 246 190 14 246 190 14
40377 -246 190 14 246 190 14 246 190 14 246 190 14
40378 -246 190 14 239 182 13 230 174 11 216 158 10
40379 -190 142 34 124 112 88 70 70 70 38 38 38
40380 - 18 18 18 6 6 6 0 0 0 0 0 0
40381 - 0 0 0 0 0 0 0 0 0 0 0 0
40382 - 0 0 0 0 0 0 0 0 0 0 0 0
40383 - 0 0 0 0 0 0 6 6 6 22 22 22
40384 - 62 62 62 168 124 44 206 145 10 224 166 10
40385 -236 178 12 239 182 13 242 186 14 242 186 14
40386 -246 186 14 246 190 14 246 190 14 246 190 14
40387 -246 190 14 246 190 14 246 190 14 246 190 14
40388 -246 190 14 246 190 14 246 190 14 246 190 14
40389 -246 190 14 236 178 12 216 158 10 175 118 6
40390 - 80 54 7 2 2 6 6 6 6 30 30 30
40391 - 54 54 54 62 62 62 50 50 50 38 38 38
40392 - 14 14 14 2 2 6 2 2 6 2 2 6
40393 - 2 2 6 2 2 6 2 2 6 2 2 6
40394 - 2 2 6 6 6 6 80 54 7 167 114 7
40395 -213 154 11 236 178 12 246 190 14 246 190 14
40396 -246 190 14 246 190 14 246 190 14 246 190 14
40397 -246 190 14 242 186 14 239 182 13 239 182 13
40398 -230 174 11 210 150 10 174 135 50 124 112 88
40399 - 82 82 82 54 54 54 34 34 34 18 18 18
40400 - 6 6 6 0 0 0 0 0 0 0 0 0
40401 - 0 0 0 0 0 0 0 0 0 0 0 0
40402 - 0 0 0 0 0 0 0 0 0 0 0 0
40403 - 0 0 0 0 0 0 6 6 6 18 18 18
40404 - 50 50 50 158 118 36 192 133 9 200 144 11
40405 -216 158 10 219 162 10 224 166 10 226 170 11
40406 -230 174 11 236 178 12 239 182 13 239 182 13
40407 -242 186 14 246 186 14 246 190 14 246 190 14
40408 -246 190 14 246 190 14 246 190 14 246 190 14
40409 -246 186 14 230 174 11 210 150 10 163 110 8
40410 -104 69 6 10 10 10 2 2 6 2 2 6
40411 - 2 2 6 2 2 6 2 2 6 2 2 6
40412 - 2 2 6 2 2 6 2 2 6 2 2 6
40413 - 2 2 6 2 2 6 2 2 6 2 2 6
40414 - 2 2 6 6 6 6 91 60 6 167 114 7
40415 -206 145 10 230 174 11 242 186 14 246 190 14
40416 -246 190 14 246 190 14 246 186 14 242 186 14
40417 -239 182 13 230 174 11 224 166 10 213 154 11
40418 -180 133 36 124 112 88 86 86 86 58 58 58
40419 - 38 38 38 22 22 22 10 10 10 6 6 6
40420 - 0 0 0 0 0 0 0 0 0 0 0 0
40421 - 0 0 0 0 0 0 0 0 0 0 0 0
40422 - 0 0 0 0 0 0 0 0 0 0 0 0
40423 - 0 0 0 0 0 0 0 0 0 14 14 14
40424 - 34 34 34 70 70 70 138 110 50 158 118 36
40425 -167 114 7 180 123 7 192 133 9 197 138 11
40426 -200 144 11 206 145 10 213 154 11 219 162 10
40427 -224 166 10 230 174 11 239 182 13 242 186 14
40428 -246 186 14 246 186 14 246 186 14 246 186 14
40429 -239 182 13 216 158 10 185 133 11 152 99 6
40430 -104 69 6 18 14 6 2 2 6 2 2 6
40431 - 2 2 6 2 2 6 2 2 6 2 2 6
40432 - 2 2 6 2 2 6 2 2 6 2 2 6
40433 - 2 2 6 2 2 6 2 2 6 2 2 6
40434 - 2 2 6 6 6 6 80 54 7 152 99 6
40435 -192 133 9 219 162 10 236 178 12 239 182 13
40436 -246 186 14 242 186 14 239 182 13 236 178 12
40437 -224 166 10 206 145 10 192 133 9 154 121 60
40438 - 94 94 94 62 62 62 42 42 42 22 22 22
40439 - 14 14 14 6 6 6 0 0 0 0 0 0
40440 - 0 0 0 0 0 0 0 0 0 0 0 0
40441 - 0 0 0 0 0 0 0 0 0 0 0 0
40442 - 0 0 0 0 0 0 0 0 0 0 0 0
40443 - 0 0 0 0 0 0 0 0 0 6 6 6
40444 - 18 18 18 34 34 34 58 58 58 78 78 78
40445 -101 98 89 124 112 88 142 110 46 156 107 11
40446 -163 110 8 167 114 7 175 118 6 180 123 7
40447 -185 133 11 197 138 11 210 150 10 219 162 10
40448 -226 170 11 236 178 12 236 178 12 234 174 13
40449 -219 162 10 197 138 11 163 110 8 130 83 6
40450 - 91 60 6 10 10 10 2 2 6 2 2 6
40451 - 18 18 18 38 38 38 38 38 38 38 38 38
40452 - 38 38 38 38 38 38 38 38 38 38 38 38
40453 - 38 38 38 38 38 38 26 26 26 2 2 6
40454 - 2 2 6 6 6 6 70 47 6 137 92 6
40455 -175 118 6 200 144 11 219 162 10 230 174 11
40456 -234 174 13 230 174 11 219 162 10 210 150 10
40457 -192 133 9 163 110 8 124 112 88 82 82 82
40458 - 50 50 50 30 30 30 14 14 14 6 6 6
40459 - 0 0 0 0 0 0 0 0 0 0 0 0
40460 - 0 0 0 0 0 0 0 0 0 0 0 0
40461 - 0 0 0 0 0 0 0 0 0 0 0 0
40462 - 0 0 0 0 0 0 0 0 0 0 0 0
40463 - 0 0 0 0 0 0 0 0 0 0 0 0
40464 - 6 6 6 14 14 14 22 22 22 34 34 34
40465 - 42 42 42 58 58 58 74 74 74 86 86 86
40466 -101 98 89 122 102 70 130 98 46 121 87 25
40467 -137 92 6 152 99 6 163 110 8 180 123 7
40468 -185 133 11 197 138 11 206 145 10 200 144 11
40469 -180 123 7 156 107 11 130 83 6 104 69 6
40470 - 50 34 6 54 54 54 110 110 110 101 98 89
40471 - 86 86 86 82 82 82 78 78 78 78 78 78
40472 - 78 78 78 78 78 78 78 78 78 78 78 78
40473 - 78 78 78 82 82 82 86 86 86 94 94 94
40474 -106 106 106 101 101 101 86 66 34 124 80 6
40475 -156 107 11 180 123 7 192 133 9 200 144 11
40476 -206 145 10 200 144 11 192 133 9 175 118 6
40477 -139 102 15 109 106 95 70 70 70 42 42 42
40478 - 22 22 22 10 10 10 0 0 0 0 0 0
40479 - 0 0 0 0 0 0 0 0 0 0 0 0
40480 - 0 0 0 0 0 0 0 0 0 0 0 0
40481 - 0 0 0 0 0 0 0 0 0 0 0 0
40482 - 0 0 0 0 0 0 0 0 0 0 0 0
40483 - 0 0 0 0 0 0 0 0 0 0 0 0
40484 - 0 0 0 0 0 0 6 6 6 10 10 10
40485 - 14 14 14 22 22 22 30 30 30 38 38 38
40486 - 50 50 50 62 62 62 74 74 74 90 90 90
40487 -101 98 89 112 100 78 121 87 25 124 80 6
40488 -137 92 6 152 99 6 152 99 6 152 99 6
40489 -138 86 6 124 80 6 98 70 6 86 66 30
40490 -101 98 89 82 82 82 58 58 58 46 46 46
40491 - 38 38 38 34 34 34 34 34 34 34 34 34
40492 - 34 34 34 34 34 34 34 34 34 34 34 34
40493 - 34 34 34 34 34 34 38 38 38 42 42 42
40494 - 54 54 54 82 82 82 94 86 76 91 60 6
40495 -134 86 6 156 107 11 167 114 7 175 118 6
40496 -175 118 6 167 114 7 152 99 6 121 87 25
40497 -101 98 89 62 62 62 34 34 34 18 18 18
40498 - 6 6 6 0 0 0 0 0 0 0 0 0
40499 - 0 0 0 0 0 0 0 0 0 0 0 0
40500 - 0 0 0 0 0 0 0 0 0 0 0 0
40501 - 0 0 0 0 0 0 0 0 0 0 0 0
40502 - 0 0 0 0 0 0 0 0 0 0 0 0
40503 - 0 0 0 0 0 0 0 0 0 0 0 0
40504 - 0 0 0 0 0 0 0 0 0 0 0 0
40505 - 0 0 0 6 6 6 6 6 6 10 10 10
40506 - 18 18 18 22 22 22 30 30 30 42 42 42
40507 - 50 50 50 66 66 66 86 86 86 101 98 89
40508 -106 86 58 98 70 6 104 69 6 104 69 6
40509 -104 69 6 91 60 6 82 62 34 90 90 90
40510 - 62 62 62 38 38 38 22 22 22 14 14 14
40511 - 10 10 10 10 10 10 10 10 10 10 10 10
40512 - 10 10 10 10 10 10 6 6 6 10 10 10
40513 - 10 10 10 10 10 10 10 10 10 14 14 14
40514 - 22 22 22 42 42 42 70 70 70 89 81 66
40515 - 80 54 7 104 69 6 124 80 6 137 92 6
40516 -134 86 6 116 81 8 100 82 52 86 86 86
40517 - 58 58 58 30 30 30 14 14 14 6 6 6
40518 - 0 0 0 0 0 0 0 0 0 0 0 0
40519 - 0 0 0 0 0 0 0 0 0 0 0 0
40520 - 0 0 0 0 0 0 0 0 0 0 0 0
40521 - 0 0 0 0 0 0 0 0 0 0 0 0
40522 - 0 0 0 0 0 0 0 0 0 0 0 0
40523 - 0 0 0 0 0 0 0 0 0 0 0 0
40524 - 0 0 0 0 0 0 0 0 0 0 0 0
40525 - 0 0 0 0 0 0 0 0 0 0 0 0
40526 - 0 0 0 6 6 6 10 10 10 14 14 14
40527 - 18 18 18 26 26 26 38 38 38 54 54 54
40528 - 70 70 70 86 86 86 94 86 76 89 81 66
40529 - 89 81 66 86 86 86 74 74 74 50 50 50
40530 - 30 30 30 14 14 14 6 6 6 0 0 0
40531 - 0 0 0 0 0 0 0 0 0 0 0 0
40532 - 0 0 0 0 0 0 0 0 0 0 0 0
40533 - 0 0 0 0 0 0 0 0 0 0 0 0
40534 - 6 6 6 18 18 18 34 34 34 58 58 58
40535 - 82 82 82 89 81 66 89 81 66 89 81 66
40536 - 94 86 66 94 86 76 74 74 74 50 50 50
40537 - 26 26 26 14 14 14 6 6 6 0 0 0
40538 - 0 0 0 0 0 0 0 0 0 0 0 0
40539 - 0 0 0 0 0 0 0 0 0 0 0 0
40540 - 0 0 0 0 0 0 0 0 0 0 0 0
40541 - 0 0 0 0 0 0 0 0 0 0 0 0
40542 - 0 0 0 0 0 0 0 0 0 0 0 0
40543 - 0 0 0 0 0 0 0 0 0 0 0 0
40544 - 0 0 0 0 0 0 0 0 0 0 0 0
40545 - 0 0 0 0 0 0 0 0 0 0 0 0
40546 - 0 0 0 0 0 0 0 0 0 0 0 0
40547 - 6 6 6 6 6 6 14 14 14 18 18 18
40548 - 30 30 30 38 38 38 46 46 46 54 54 54
40549 - 50 50 50 42 42 42 30 30 30 18 18 18
40550 - 10 10 10 0 0 0 0 0 0 0 0 0
40551 - 0 0 0 0 0 0 0 0 0 0 0 0
40552 - 0 0 0 0 0 0 0 0 0 0 0 0
40553 - 0 0 0 0 0 0 0 0 0 0 0 0
40554 - 0 0 0 6 6 6 14 14 14 26 26 26
40555 - 38 38 38 50 50 50 58 58 58 58 58 58
40556 - 54 54 54 42 42 42 30 30 30 18 18 18
40557 - 10 10 10 0 0 0 0 0 0 0 0 0
40558 - 0 0 0 0 0 0 0 0 0 0 0 0
40559 - 0 0 0 0 0 0 0 0 0 0 0 0
40560 - 0 0 0 0 0 0 0 0 0 0 0 0
40561 - 0 0 0 0 0 0 0 0 0 0 0 0
40562 - 0 0 0 0 0 0 0 0 0 0 0 0
40563 - 0 0 0 0 0 0 0 0 0 0 0 0
40564 - 0 0 0 0 0 0 0 0 0 0 0 0
40565 - 0 0 0 0 0 0 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 6 6 6
40568 - 6 6 6 10 10 10 14 14 14 18 18 18
40569 - 18 18 18 14 14 14 10 10 10 6 6 6
40570 - 0 0 0 0 0 0 0 0 0 0 0 0
40571 - 0 0 0 0 0 0 0 0 0 0 0 0
40572 - 0 0 0 0 0 0 0 0 0 0 0 0
40573 - 0 0 0 0 0 0 0 0 0 0 0 0
40574 - 0 0 0 0 0 0 0 0 0 6 6 6
40575 - 14 14 14 18 18 18 22 22 22 22 22 22
40576 - 18 18 18 14 14 14 10 10 10 6 6 6
40577 - 0 0 0 0 0 0 0 0 0 0 0 0
40578 - 0 0 0 0 0 0 0 0 0 0 0 0
40579 - 0 0 0 0 0 0 0 0 0 0 0 0
40580 - 0 0 0 0 0 0 0 0 0 0 0 0
40581 - 0 0 0 0 0 0 0 0 0 0 0 0
40582 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40587 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40588 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40589 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40593 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40594 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40595 +4 4 4 4 4 4
40596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40601 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40602 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40603 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40608 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40609 +4 4 4 4 4 4
40610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40615 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40617 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40621 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40622 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40623 +4 4 4 4 4 4
40624 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40629 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40636 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40637 +4 4 4 4 4 4
40638 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40643 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40645 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40650 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40651 +4 4 4 4 4 4
40652 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40657 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40664 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40665 +4 4 4 4 4 4
40666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40670 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40671 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40675 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40676 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40677 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40678 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40679 +4 4 4 4 4 4
40680 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40684 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40685 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40686 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40687 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40689 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40690 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40691 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40692 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40693 +4 4 4 4 4 4
40694 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40698 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40699 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40700 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40701 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40703 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40704 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40705 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40706 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40707 +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 5 5 5 5 5 5 2 2 2 0 0 0
40712 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40713 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40714 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
40717 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40718 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40719 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40720 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40721 +4 4 4 4 4 4
40722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40725 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40726 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40727 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40728 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40729 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40730 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40731 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40732 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40733 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40734 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40735 +4 4 4 4 4 4
40736 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40739 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40740 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40741 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40742 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40743 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40744 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40745 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40746 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40747 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40748 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40749 +4 4 4 4 4 4
40750 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40752 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40753 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40754 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40755 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40756 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40757 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40758 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40759 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40760 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40761 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40762 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40763 +4 4 4 4 4 4
40764 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40766 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40767 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40768 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40769 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40770 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40771 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40772 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40773 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40774 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40775 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40776 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40777 +4 4 4 4 4 4
40778 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40780 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40781 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40782 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40783 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40784 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40785 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40786 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40787 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40788 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40789 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40790 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40791 +4 4 4 4 4 4
40792 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40794 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40795 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40796 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40797 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40798 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40799 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40800 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40801 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40802 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40803 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40804 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40805 +4 4 4 4 4 4
40806 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40807 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40808 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40809 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40810 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40811 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40812 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40813 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40814 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40815 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40816 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40817 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40818 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40819 +4 4 4 4 4 4
40820 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40821 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40822 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40823 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40824 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40825 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40826 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40827 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40828 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40829 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40830 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40831 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40832 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40833 +0 0 0 4 4 4
40834 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40835 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40836 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40837 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40838 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40839 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40840 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40841 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40842 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40843 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40844 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40845 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40846 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40847 +2 0 0 0 0 0
40848 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40849 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40850 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40851 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40852 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40853 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40854 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40855 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40856 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40857 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40858 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40859 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40860 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40861 +37 38 37 0 0 0
40862 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40863 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40864 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40865 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40866 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40867 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40868 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40869 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40870 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40871 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40872 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40873 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40874 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
40875 +85 115 134 4 0 0
40876 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
40877 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
40878 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
40879 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
40880 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
40881 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
40882 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
40883 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
40884 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
40885 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
40886 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
40887 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
40888 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
40889 +60 73 81 4 0 0
40890 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
40891 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
40892 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
40893 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
40894 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
40895 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
40896 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
40897 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
40898 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
40899 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
40900 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
40901 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
40902 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
40903 +16 19 21 4 0 0
40904 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
40905 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
40906 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
40907 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
40908 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
40909 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
40910 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
40911 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
40912 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
40913 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
40914 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
40915 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
40916 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
40917 +4 0 0 4 3 3
40918 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
40919 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
40920 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
40921 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
40922 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
40923 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
40924 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
40925 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
40926 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
40927 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
40928 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
40929 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
40930 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
40931 +3 2 2 4 4 4
40932 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
40933 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
40934 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
40935 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40936 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
40937 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
40938 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
40939 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
40940 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
40941 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
40942 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
40943 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
40944 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
40945 +4 4 4 4 4 4
40946 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
40947 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
40948 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
40949 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
40950 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
40951 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
40952 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
40953 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
40954 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
40955 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
40956 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
40957 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
40958 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
40959 +4 4 4 4 4 4
40960 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
40961 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
40962 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
40963 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
40964 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
40965 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40966 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
40967 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
40968 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
40969 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
40970 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
40971 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
40972 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
40973 +5 5 5 5 5 5
40974 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
40975 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
40976 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
40977 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
40978 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
40979 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40980 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
40981 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
40982 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
40983 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
40984 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
40985 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
40986 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40987 +5 5 5 4 4 4
40988 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
40989 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
40990 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
40991 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
40992 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40993 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
40994 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
40995 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
40996 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
40997 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
40998 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
40999 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41001 +4 4 4 4 4 4
41002 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41003 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41004 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41005 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41006 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41007 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41008 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41009 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41010 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41011 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41012 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41013 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41015 +4 4 4 4 4 4
41016 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41017 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41018 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41019 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41020 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41021 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41022 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41023 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41024 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41025 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41026 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41029 +4 4 4 4 4 4
41030 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41031 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41032 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41033 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41034 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41035 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41036 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41037 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41038 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41039 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41040 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41041 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41043 +4 4 4 4 4 4
41044 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41045 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41046 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41047 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41048 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41049 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41050 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41051 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41052 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41053 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41054 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41055 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41056 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41057 +4 4 4 4 4 4
41058 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41059 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41060 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41061 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41062 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41063 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41064 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41065 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41066 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41067 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41068 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41071 +4 4 4 4 4 4
41072 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41073 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41074 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41075 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41076 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41077 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41078 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41079 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41080 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41081 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41082 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41085 +4 4 4 4 4 4
41086 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41087 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41088 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41089 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41090 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41091 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41092 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41093 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41094 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41095 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41096 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41099 +4 4 4 4 4 4
41100 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41101 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41102 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41103 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41104 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41105 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41106 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41107 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41108 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41109 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41110 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41113 +4 4 4 4 4 4
41114 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41115 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41116 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41117 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41118 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41119 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41120 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41121 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41122 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41123 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41124 +4 0 0 3 3 3 5 5 5 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41127 +4 4 4 4 4 4
41128 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41129 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41130 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41131 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41132 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41133 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41134 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41135 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41136 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41137 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41138 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41141 +4 4 4 4 4 4
41142 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41143 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41144 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41145 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41146 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41147 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41148 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41149 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41150 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41151 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41152 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41155 +4 4 4 4 4 4
41156 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41157 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41158 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41159 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41160 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41161 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41162 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41163 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41164 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41165 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41166 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41169 +4 4 4 4 4 4
41170 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41171 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41172 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41173 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41174 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41175 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41176 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41177 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41178 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41179 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41180 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41183 +4 4 4 4 4 4
41184 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41185 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41186 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41187 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41188 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41189 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41190 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41191 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41192 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41193 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41194 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41197 +4 4 4 4 4 4
41198 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41199 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41200 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41201 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41202 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41203 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41204 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41205 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41206 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41207 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41208 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41211 +4 4 4 4 4 4
41212 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41213 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41214 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41215 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41216 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41217 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41218 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41219 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41220 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41221 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41222 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41225 +4 4 4 4 4 4
41226 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41227 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41228 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41229 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41230 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41231 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41232 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41233 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41234 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41235 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41236 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41239 +4 4 4 4 4 4
41240 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41241 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41242 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41243 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41244 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41245 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41246 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41247 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41248 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41249 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41250 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41253 +4 4 4 4 4 4
41254 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41255 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41256 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41257 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41258 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41259 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41260 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41261 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41262 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41263 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41264 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41267 +4 4 4 4 4 4
41268 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41269 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41270 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41271 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41272 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41273 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41274 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41275 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41276 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41277 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41278 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41281 +4 4 4 4 4 4
41282 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41283 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41284 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41285 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41286 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41287 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41288 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41289 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41290 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41291 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41292 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41295 +4 4 4 4 4 4
41296 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41297 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41298 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41299 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41300 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41301 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41302 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41303 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41304 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41305 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41306 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41309 +4 4 4 4 4 4
41310 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41311 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41312 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41313 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41314 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41315 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41316 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41317 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41318 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41319 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41320 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41323 +4 4 4 4 4 4
41324 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41325 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41326 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41327 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41328 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41329 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41330 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41331 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41332 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41333 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41334 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41337 +4 4 4 4 4 4
41338 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41339 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41340 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41341 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41342 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41343 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41344 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41345 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41346 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41347 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41348 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41351 +4 4 4 4 4 4
41352 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41353 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41354 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41355 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41356 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41357 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41358 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41359 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41360 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41361 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41362 +0 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
41365 +4 4 4 4 4 4
41366 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41367 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41368 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41369 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41370 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41371 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41372 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41373 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41374 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41375 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41376 +4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41379 +4 4 4 4 4 4
41380 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41381 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41382 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41383 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41384 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41385 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41386 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41387 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41388 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41389 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41390 +5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41393 +4 4 4 4 4 4
41394 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41395 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41396 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41397 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41398 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41399 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41400 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41401 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41402 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41403 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
41407 +4 4 4 4 4 4
41408 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41409 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41410 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41411 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41412 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41413 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41414 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41415 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41416 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41417 +13 16 17 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
41421 +4 4 4 4 4 4
41422 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41423 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41424 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41425 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41426 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41427 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41428 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41429 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41430 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41431 +4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41435 +4 4 4 4 4 4
41436 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41437 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41438 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41439 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41440 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41441 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41442 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41443 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41444 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41445 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41447 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41448 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41449 +4 4 4 4 4 4
41450 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41451 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41452 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41453 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41454 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41455 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41456 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41457 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41458 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41461 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41462 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41463 +4 4 4 4 4 4
41464 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41465 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41466 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41467 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41468 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41469 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41470 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41471 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41472 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41475 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41477 +4 4 4 4 4 4
41478 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41479 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41480 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41481 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41482 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41483 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41484 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41485 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41486 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41489 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41491 +4 4 4 4 4 4
41492 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41493 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41494 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41495 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41496 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41497 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41498 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41499 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41504 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41505 +4 4 4 4 4 4
41506 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41507 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41508 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41509 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41510 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41511 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41512 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41513 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41517 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41518 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41519 +4 4 4 4 4 4
41520 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41521 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41522 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41523 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41524 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41525 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41526 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41527 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
41528 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41530 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41531 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41532 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41533 +4 4 4 4 4 4
41534 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41535 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41536 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41537 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41538 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41539 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41540 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41541 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41542 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41543 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41544 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41545 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41546 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41547 +4 4 4 4 4 4
41548 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41549 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41550 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41551 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41552 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41553 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41554 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41555 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41556 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41557 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41559 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41560 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41561 +4 4 4 4 4 4
41562 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41564 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41565 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41566 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41567 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41568 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41569 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41570 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41575 +4 4 4 4 4 4
41576 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41579 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41580 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41581 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41582 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
41583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
41589 +4 4 4 4 4 4
41590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41593 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41594 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41595 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41596 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41597 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41603 +4 4 4 4 4 4
41604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41607 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41608 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41609 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41610 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
41611 +4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41617 +4 4 4 4 4 4
41618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41621 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41622 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41623 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41624 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
41631 +4 4 4 4 4 4
41632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41636 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41637 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41638 +6 6 6 4 3 3 5 5 5 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41645 +4 4 4 4 4 4
41646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41650 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41651 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41652 +4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41659 +4 4 4 4 4 4
41660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41664 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41665 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41666 +5 5 5 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41673 +4 4 4 4 4 4
41674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41678 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41679 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41680 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41687 +4 4 4 4 4 4
41688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41691 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41692 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41693 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41694 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41701 +4 4 4 4 4 4
41702 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41703 index 3473e75..c930142 100644
41704 --- a/drivers/video/udlfb.c
41705 +++ b/drivers/video/udlfb.c
41706 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41707 dlfb_urb_completion(urb);
41708
41709 error:
41710 - atomic_add(bytes_sent, &dev->bytes_sent);
41711 - atomic_add(bytes_identical, &dev->bytes_identical);
41712 - atomic_add(width*height*2, &dev->bytes_rendered);
41713 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41714 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41715 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41716 end_cycles = get_cycles();
41717 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41718 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41719 >> 10)), /* Kcycles */
41720 &dev->cpu_kcycles_used);
41721
41722 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41723 dlfb_urb_completion(urb);
41724
41725 error:
41726 - atomic_add(bytes_sent, &dev->bytes_sent);
41727 - atomic_add(bytes_identical, &dev->bytes_identical);
41728 - atomic_add(bytes_rendered, &dev->bytes_rendered);
41729 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41730 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41731 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41732 end_cycles = get_cycles();
41733 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41734 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41735 >> 10)), /* Kcycles */
41736 &dev->cpu_kcycles_used);
41737 }
41738 @@ -1368,7 +1368,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41739 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41740 struct dlfb_data *dev = fb_info->par;
41741 return snprintf(buf, PAGE_SIZE, "%u\n",
41742 - atomic_read(&dev->bytes_rendered));
41743 + atomic_read_unchecked(&dev->bytes_rendered));
41744 }
41745
41746 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41747 @@ -1376,7 +1376,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41748 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41749 struct dlfb_data *dev = fb_info->par;
41750 return snprintf(buf, PAGE_SIZE, "%u\n",
41751 - atomic_read(&dev->bytes_identical));
41752 + atomic_read_unchecked(&dev->bytes_identical));
41753 }
41754
41755 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41756 @@ -1384,7 +1384,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41757 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41758 struct dlfb_data *dev = fb_info->par;
41759 return snprintf(buf, PAGE_SIZE, "%u\n",
41760 - atomic_read(&dev->bytes_sent));
41761 + atomic_read_unchecked(&dev->bytes_sent));
41762 }
41763
41764 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41765 @@ -1392,7 +1392,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41766 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41767 struct dlfb_data *dev = fb_info->par;
41768 return snprintf(buf, PAGE_SIZE, "%u\n",
41769 - atomic_read(&dev->cpu_kcycles_used));
41770 + atomic_read_unchecked(&dev->cpu_kcycles_used));
41771 }
41772
41773 static ssize_t edid_show(
41774 @@ -1449,10 +1449,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41775 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41776 struct dlfb_data *dev = fb_info->par;
41777
41778 - atomic_set(&dev->bytes_rendered, 0);
41779 - atomic_set(&dev->bytes_identical, 0);
41780 - atomic_set(&dev->bytes_sent, 0);
41781 - atomic_set(&dev->cpu_kcycles_used, 0);
41782 + atomic_set_unchecked(&dev->bytes_rendered, 0);
41783 + atomic_set_unchecked(&dev->bytes_identical, 0);
41784 + atomic_set_unchecked(&dev->bytes_sent, 0);
41785 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41786
41787 return count;
41788 }
41789 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41790 index 7f8472c..9842e87 100644
41791 --- a/drivers/video/uvesafb.c
41792 +++ b/drivers/video/uvesafb.c
41793 @@ -19,6 +19,7 @@
41794 #include <linux/io.h>
41795 #include <linux/mutex.h>
41796 #include <linux/slab.h>
41797 +#include <linux/moduleloader.h>
41798 #include <video/edid.h>
41799 #include <video/uvesafb.h>
41800 #ifdef CONFIG_X86
41801 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
41802 NULL,
41803 };
41804
41805 - return call_usermodehelper(v86d_path, argv, envp, 1);
41806 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
41807 }
41808
41809 /*
41810 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41811 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41812 par->pmi_setpal = par->ypan = 0;
41813 } else {
41814 +
41815 +#ifdef CONFIG_PAX_KERNEXEC
41816 +#ifdef CONFIG_MODULES
41817 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41818 +#endif
41819 + if (!par->pmi_code) {
41820 + par->pmi_setpal = par->ypan = 0;
41821 + return 0;
41822 + }
41823 +#endif
41824 +
41825 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41826 + task->t.regs.edi);
41827 +
41828 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41829 + pax_open_kernel();
41830 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41831 + pax_close_kernel();
41832 +
41833 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41834 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41835 +#else
41836 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41837 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41838 +#endif
41839 +
41840 printk(KERN_INFO "uvesafb: protected mode interface info at "
41841 "%04x:%04x\n",
41842 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41843 @@ -1821,6 +1844,11 @@ out:
41844 if (par->vbe_modes)
41845 kfree(par->vbe_modes);
41846
41847 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41848 + if (par->pmi_code)
41849 + module_free_exec(NULL, par->pmi_code);
41850 +#endif
41851 +
41852 framebuffer_release(info);
41853 return err;
41854 }
41855 @@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platform_device *dev)
41856 kfree(par->vbe_state_orig);
41857 if (par->vbe_state_saved)
41858 kfree(par->vbe_state_saved);
41859 +
41860 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41861 + if (par->pmi_code)
41862 + module_free_exec(NULL, par->pmi_code);
41863 +#endif
41864 +
41865 }
41866
41867 framebuffer_release(info);
41868 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
41869 index 501b340..86bd4cf 100644
41870 --- a/drivers/video/vesafb.c
41871 +++ b/drivers/video/vesafb.c
41872 @@ -9,6 +9,7 @@
41873 */
41874
41875 #include <linux/module.h>
41876 +#include <linux/moduleloader.h>
41877 #include <linux/kernel.h>
41878 #include <linux/errno.h>
41879 #include <linux/string.h>
41880 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
41881 static int vram_total __initdata; /* Set total amount of memory */
41882 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
41883 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
41884 -static void (*pmi_start)(void) __read_mostly;
41885 -static void (*pmi_pal) (void) __read_mostly;
41886 +static void (*pmi_start)(void) __read_only;
41887 +static void (*pmi_pal) (void) __read_only;
41888 static int depth __read_mostly;
41889 static int vga_compat __read_mostly;
41890 /* --------------------------------------------------------------------- */
41891 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
41892 unsigned int size_vmode;
41893 unsigned int size_remap;
41894 unsigned int size_total;
41895 + void *pmi_code = NULL;
41896
41897 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
41898 return -ENODEV;
41899 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
41900 size_remap = size_total;
41901 vesafb_fix.smem_len = size_remap;
41902
41903 -#ifndef __i386__
41904 - screen_info.vesapm_seg = 0;
41905 -#endif
41906 -
41907 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
41908 printk(KERN_WARNING
41909 "vesafb: cannot reserve video memory at 0x%lx\n",
41910 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
41911 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
41912 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
41913
41914 +#ifdef __i386__
41915 +
41916 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41917 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
41918 + if (!pmi_code)
41919 +#elif !defined(CONFIG_PAX_KERNEXEC)
41920 + if (0)
41921 +#endif
41922 +
41923 +#endif
41924 + screen_info.vesapm_seg = 0;
41925 +
41926 if (screen_info.vesapm_seg) {
41927 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
41928 - screen_info.vesapm_seg,screen_info.vesapm_off);
41929 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
41930 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
41931 }
41932
41933 if (screen_info.vesapm_seg < 0xc000)
41934 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
41935
41936 if (ypan || pmi_setpal) {
41937 unsigned short *pmi_base;
41938 +
41939 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
41940 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
41941 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
41942 +
41943 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41944 + pax_open_kernel();
41945 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
41946 +#else
41947 + pmi_code = pmi_base;
41948 +#endif
41949 +
41950 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
41951 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
41952 +
41953 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41954 + pmi_start = ktva_ktla(pmi_start);
41955 + pmi_pal = ktva_ktla(pmi_pal);
41956 + pax_close_kernel();
41957 +#endif
41958 +
41959 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
41960 if (pmi_base[3]) {
41961 printk(KERN_INFO "vesafb: pmi: ports = ");
41962 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
41963 info->node, info->fix.id);
41964 return 0;
41965 err:
41966 +
41967 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41968 + module_free_exec(NULL, pmi_code);
41969 +#endif
41970 +
41971 if (info->screen_base)
41972 iounmap(info->screen_base);
41973 framebuffer_release(info);
41974 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
41975 index 88714ae..16c2e11 100644
41976 --- a/drivers/video/via/via_clock.h
41977 +++ b/drivers/video/via/via_clock.h
41978 @@ -56,7 +56,7 @@ struct via_clock {
41979
41980 void (*set_engine_pll_state)(u8 state);
41981 void (*set_engine_pll)(struct via_pll_config config);
41982 -};
41983 +} __no_const;
41984
41985
41986 static inline u32 get_pll_internal_frequency(u32 ref_freq,
41987 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
41988 index e56c934..fc22f4b 100644
41989 --- a/drivers/xen/xen-pciback/conf_space.h
41990 +++ b/drivers/xen/xen-pciback/conf_space.h
41991 @@ -44,15 +44,15 @@ struct config_field {
41992 struct {
41993 conf_dword_write write;
41994 conf_dword_read read;
41995 - } dw;
41996 + } __no_const dw;
41997 struct {
41998 conf_word_write write;
41999 conf_word_read read;
42000 - } w;
42001 + } __no_const w;
42002 struct {
42003 conf_byte_write write;
42004 conf_byte_read read;
42005 - } b;
42006 + } __no_const b;
42007 } u;
42008 struct list_head list;
42009 };
42010 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42011 index 879ed88..bc03a01 100644
42012 --- a/fs/9p/vfs_inode.c
42013 +++ b/fs/9p/vfs_inode.c
42014 @@ -1286,7 +1286,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42015 void
42016 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42017 {
42018 - char *s = nd_get_link(nd);
42019 + const char *s = nd_get_link(nd);
42020
42021 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
42022 IS_ERR(s) ? "<error>" : s);
42023 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42024 index 79e2ca7..5828ad1 100644
42025 --- a/fs/Kconfig.binfmt
42026 +++ b/fs/Kconfig.binfmt
42027 @@ -86,7 +86,7 @@ config HAVE_AOUT
42028
42029 config BINFMT_AOUT
42030 tristate "Kernel support for a.out and ECOFF binaries"
42031 - depends on HAVE_AOUT
42032 + depends on HAVE_AOUT && BROKEN
42033 ---help---
42034 A.out (Assembler.OUTput) is a set of formats for libraries and
42035 executables used in the earliest versions of UNIX. Linux used
42036 diff --git a/fs/aio.c b/fs/aio.c
42037 index b9d64d8..86cb1d5 100644
42038 --- a/fs/aio.c
42039 +++ b/fs/aio.c
42040 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42041 size += sizeof(struct io_event) * nr_events;
42042 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42043
42044 - if (nr_pages < 0)
42045 + if (nr_pages <= 0)
42046 return -EINVAL;
42047
42048 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42049 @@ -1461,22 +1461,27 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42050 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42051 {
42052 ssize_t ret;
42053 + struct iovec iovstack;
42054
42055 #ifdef CONFIG_COMPAT
42056 if (compat)
42057 ret = compat_rw_copy_check_uvector(type,
42058 (struct compat_iovec __user *)kiocb->ki_buf,
42059 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42060 + kiocb->ki_nbytes, 1, &iovstack,
42061 &kiocb->ki_iovec, 1);
42062 else
42063 #endif
42064 ret = rw_copy_check_uvector(type,
42065 (struct iovec __user *)kiocb->ki_buf,
42066 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42067 + kiocb->ki_nbytes, 1, &iovstack,
42068 &kiocb->ki_iovec, 1);
42069 if (ret < 0)
42070 goto out;
42071
42072 + if (kiocb->ki_iovec == &iovstack) {
42073 + kiocb->ki_inline_vec = iovstack;
42074 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42075 + }
42076 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42077 kiocb->ki_cur_seg = 0;
42078 /* ki_nbytes/left now reflect bytes instead of segs */
42079 diff --git a/fs/attr.c b/fs/attr.c
42080 index 7ee7ba4..0c61a60 100644
42081 --- a/fs/attr.c
42082 +++ b/fs/attr.c
42083 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42084 unsigned long limit;
42085
42086 limit = rlimit(RLIMIT_FSIZE);
42087 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42088 if (limit != RLIM_INFINITY && offset > limit)
42089 goto out_sig;
42090 if (offset > inode->i_sb->s_maxbytes)
42091 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42092 index 6861f61..a25f010 100644
42093 --- a/fs/autofs4/waitq.c
42094 +++ b/fs/autofs4/waitq.c
42095 @@ -60,7 +60,7 @@ static int autofs4_write(struct file *file, const void *addr, int bytes)
42096 {
42097 unsigned long sigpipe, flags;
42098 mm_segment_t fs;
42099 - const char *data = (const char *)addr;
42100 + const char __user *data = (const char __force_user *)addr;
42101 ssize_t wr = 0;
42102
42103 /** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
42104 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42105 index 8342ca6..82fd192 100644
42106 --- a/fs/befs/linuxvfs.c
42107 +++ b/fs/befs/linuxvfs.c
42108 @@ -503,7 +503,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42109 {
42110 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42111 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42112 - char *link = nd_get_link(nd);
42113 + const char *link = nd_get_link(nd);
42114 if (!IS_ERR(link))
42115 kfree(link);
42116 }
42117 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42118 index a6395bd..f1e376a 100644
42119 --- a/fs/binfmt_aout.c
42120 +++ b/fs/binfmt_aout.c
42121 @@ -16,6 +16,7 @@
42122 #include <linux/string.h>
42123 #include <linux/fs.h>
42124 #include <linux/file.h>
42125 +#include <linux/security.h>
42126 #include <linux/stat.h>
42127 #include <linux/fcntl.h>
42128 #include <linux/ptrace.h>
42129 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42130 #endif
42131 # define START_STACK(u) ((void __user *)u.start_stack)
42132
42133 + memset(&dump, 0, sizeof(dump));
42134 +
42135 fs = get_fs();
42136 set_fs(KERNEL_DS);
42137 has_dumped = 1;
42138 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42139
42140 /* If the size of the dump file exceeds the rlimit, then see what would happen
42141 if we wrote the stack, but not the data area. */
42142 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42143 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42144 dump.u_dsize = 0;
42145
42146 /* Make sure we have enough room to write the stack and data areas. */
42147 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42148 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42149 dump.u_ssize = 0;
42150
42151 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42152 rlim = rlimit(RLIMIT_DATA);
42153 if (rlim >= RLIM_INFINITY)
42154 rlim = ~0;
42155 +
42156 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42157 if (ex.a_data + ex.a_bss > rlim)
42158 return -ENOMEM;
42159
42160 @@ -259,9 +266,37 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42161 current->mm->free_area_cache = current->mm->mmap_base;
42162 current->mm->cached_hole_size = 0;
42163
42164 + retval = setup_arg_pages(bprm, STACK_TOP, EXSTACK_DEFAULT);
42165 + if (retval < 0) {
42166 + /* Someone check-me: is this error path enough? */
42167 + send_sig(SIGKILL, current, 0);
42168 + return retval;
42169 + }
42170 +
42171 install_exec_creds(bprm);
42172 current->flags &= ~PF_FORKNOEXEC;
42173
42174 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42175 + current->mm->pax_flags = 0UL;
42176 +#endif
42177 +
42178 +#ifdef CONFIG_PAX_PAGEEXEC
42179 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42180 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42181 +
42182 +#ifdef CONFIG_PAX_EMUTRAMP
42183 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42184 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42185 +#endif
42186 +
42187 +#ifdef CONFIG_PAX_MPROTECT
42188 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42189 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42190 +#endif
42191 +
42192 + }
42193 +#endif
42194 +
42195 if (N_MAGIC(ex) == OMAGIC) {
42196 unsigned long text_addr, map_size;
42197 loff_t pos;
42198 @@ -334,7 +369,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42199
42200 down_write(&current->mm->mmap_sem);
42201 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42202 - PROT_READ | PROT_WRITE | PROT_EXEC,
42203 + PROT_READ | PROT_WRITE,
42204 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42205 fd_offset + ex.a_text);
42206 up_write(&current->mm->mmap_sem);
42207 @@ -352,13 +387,6 @@ beyond_if:
42208 return retval;
42209 }
42210
42211 - retval = setup_arg_pages(bprm, STACK_TOP, EXSTACK_DEFAULT);
42212 - if (retval < 0) {
42213 - /* Someone check-me: is this error path enough? */
42214 - send_sig(SIGKILL, current, 0);
42215 - return retval;
42216 - }
42217 -
42218 current->mm->start_stack =
42219 (unsigned long) create_aout_tables((char __user *) bprm->p, bprm);
42220 #ifdef __alpha__
42221 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42222 index 6ff96c6..b5fb43a 100644
42223 --- a/fs/binfmt_elf.c
42224 +++ b/fs/binfmt_elf.c
42225 @@ -32,6 +32,7 @@
42226 #include <linux/elf.h>
42227 #include <linux/utsname.h>
42228 #include <linux/coredump.h>
42229 +#include <linux/xattr.h>
42230 #include <asm/uaccess.h>
42231 #include <asm/param.h>
42232 #include <asm/page.h>
42233 @@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42234 #define elf_core_dump NULL
42235 #endif
42236
42237 +#ifdef CONFIG_PAX_MPROTECT
42238 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42239 +#endif
42240 +
42241 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42242 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42243 #else
42244 @@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
42245 .load_binary = load_elf_binary,
42246 .load_shlib = load_elf_library,
42247 .core_dump = elf_core_dump,
42248 +
42249 +#ifdef CONFIG_PAX_MPROTECT
42250 + .handle_mprotect= elf_handle_mprotect,
42251 +#endif
42252 +
42253 .min_coredump = ELF_EXEC_PAGESIZE,
42254 };
42255
42256 @@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
42257
42258 static int set_brk(unsigned long start, unsigned long end)
42259 {
42260 + unsigned long e = end;
42261 +
42262 start = ELF_PAGEALIGN(start);
42263 end = ELF_PAGEALIGN(end);
42264 if (end > start) {
42265 @@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
42266 if (BAD_ADDR(addr))
42267 return addr;
42268 }
42269 - current->mm->start_brk = current->mm->brk = end;
42270 + current->mm->start_brk = current->mm->brk = e;
42271 return 0;
42272 }
42273
42274 @@ -148,12 +160,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42275 elf_addr_t __user *u_rand_bytes;
42276 const char *k_platform = ELF_PLATFORM;
42277 const char *k_base_platform = ELF_BASE_PLATFORM;
42278 - unsigned char k_rand_bytes[16];
42279 + u32 k_rand_bytes[4];
42280 int items;
42281 elf_addr_t *elf_info;
42282 int ei_index = 0;
42283 const struct cred *cred = current_cred();
42284 struct vm_area_struct *vma;
42285 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42286
42287 /*
42288 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42289 @@ -195,8 +208,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42290 * Generate 16 random bytes for userspace PRNG seeding.
42291 */
42292 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42293 - u_rand_bytes = (elf_addr_t __user *)
42294 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42295 + srandom32(k_rand_bytes[0] ^ random32());
42296 + srandom32(k_rand_bytes[1] ^ random32());
42297 + srandom32(k_rand_bytes[2] ^ random32());
42298 + srandom32(k_rand_bytes[3] ^ random32());
42299 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42300 + u_rand_bytes = (elf_addr_t __user *) p;
42301 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42302 return -EFAULT;
42303
42304 @@ -308,9 +325,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42305 return -EFAULT;
42306 current->mm->env_end = p;
42307
42308 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42309 +
42310 /* Put the elf_info on the stack in the right place. */
42311 sp = (elf_addr_t __user *)envp + 1;
42312 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42313 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42314 return -EFAULT;
42315 return 0;
42316 }
42317 @@ -381,10 +400,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42318 {
42319 struct elf_phdr *elf_phdata;
42320 struct elf_phdr *eppnt;
42321 - unsigned long load_addr = 0;
42322 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42323 int load_addr_set = 0;
42324 unsigned long last_bss = 0, elf_bss = 0;
42325 - unsigned long error = ~0UL;
42326 + unsigned long error = -EINVAL;
42327 unsigned long total_size;
42328 int retval, i, size;
42329
42330 @@ -430,6 +449,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42331 goto out_close;
42332 }
42333
42334 +#ifdef CONFIG_PAX_SEGMEXEC
42335 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42336 + pax_task_size = SEGMEXEC_TASK_SIZE;
42337 +#endif
42338 +
42339 eppnt = elf_phdata;
42340 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42341 if (eppnt->p_type == PT_LOAD) {
42342 @@ -473,8 +497,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42343 k = load_addr + eppnt->p_vaddr;
42344 if (BAD_ADDR(k) ||
42345 eppnt->p_filesz > eppnt->p_memsz ||
42346 - eppnt->p_memsz > TASK_SIZE ||
42347 - TASK_SIZE - eppnt->p_memsz < k) {
42348 + eppnt->p_memsz > pax_task_size ||
42349 + pax_task_size - eppnt->p_memsz < k) {
42350 error = -ENOMEM;
42351 goto out_close;
42352 }
42353 @@ -528,6 +552,351 @@ out:
42354 return error;
42355 }
42356
42357 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42358 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42359 +{
42360 + unsigned long pax_flags = 0UL;
42361 +
42362 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42363 +
42364 +#ifdef CONFIG_PAX_PAGEEXEC
42365 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42366 + pax_flags |= MF_PAX_PAGEEXEC;
42367 +#endif
42368 +
42369 +#ifdef CONFIG_PAX_SEGMEXEC
42370 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42371 + pax_flags |= MF_PAX_SEGMEXEC;
42372 +#endif
42373 +
42374 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42375 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42376 + if ((__supported_pte_mask & _PAGE_NX))
42377 + pax_flags &= ~MF_PAX_SEGMEXEC;
42378 + else
42379 + pax_flags &= ~MF_PAX_PAGEEXEC;
42380 + }
42381 +#endif
42382 +
42383 +#ifdef CONFIG_PAX_EMUTRAMP
42384 + if (elf_phdata->p_flags & PF_EMUTRAMP)
42385 + pax_flags |= MF_PAX_EMUTRAMP;
42386 +#endif
42387 +
42388 +#ifdef CONFIG_PAX_MPROTECT
42389 + if (elf_phdata->p_flags & PF_MPROTECT)
42390 + pax_flags |= MF_PAX_MPROTECT;
42391 +#endif
42392 +
42393 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42394 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42395 + pax_flags |= MF_PAX_RANDMMAP;
42396 +#endif
42397 +
42398 +#endif
42399 +
42400 + return pax_flags;
42401 +}
42402 +
42403 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42404 +{
42405 + unsigned long pax_flags = 0UL;
42406 +
42407 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42408 +
42409 +#ifdef CONFIG_PAX_PAGEEXEC
42410 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42411 + pax_flags |= MF_PAX_PAGEEXEC;
42412 +#endif
42413 +
42414 +#ifdef CONFIG_PAX_SEGMEXEC
42415 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42416 + pax_flags |= MF_PAX_SEGMEXEC;
42417 +#endif
42418 +
42419 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42420 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42421 + if ((__supported_pte_mask & _PAGE_NX))
42422 + pax_flags &= ~MF_PAX_SEGMEXEC;
42423 + else
42424 + pax_flags &= ~MF_PAX_PAGEEXEC;
42425 + }
42426 +#endif
42427 +
42428 +#ifdef CONFIG_PAX_EMUTRAMP
42429 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42430 + pax_flags |= MF_PAX_EMUTRAMP;
42431 +#endif
42432 +
42433 +#ifdef CONFIG_PAX_MPROTECT
42434 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42435 + pax_flags |= MF_PAX_MPROTECT;
42436 +#endif
42437 +
42438 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42439 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42440 + pax_flags |= MF_PAX_RANDMMAP;
42441 +#endif
42442 +
42443 +#endif
42444 +
42445 + return pax_flags;
42446 +}
42447 +
42448 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42449 +{
42450 + unsigned long pax_flags = 0UL;
42451 +
42452 +#ifdef CONFIG_PAX_EI_PAX
42453 +
42454 +#ifdef CONFIG_PAX_PAGEEXEC
42455 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42456 + pax_flags |= MF_PAX_PAGEEXEC;
42457 +#endif
42458 +
42459 +#ifdef CONFIG_PAX_SEGMEXEC
42460 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42461 + pax_flags |= MF_PAX_SEGMEXEC;
42462 +#endif
42463 +
42464 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42465 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42466 + if ((__supported_pte_mask & _PAGE_NX))
42467 + pax_flags &= ~MF_PAX_SEGMEXEC;
42468 + else
42469 + pax_flags &= ~MF_PAX_PAGEEXEC;
42470 + }
42471 +#endif
42472 +
42473 +#ifdef CONFIG_PAX_EMUTRAMP
42474 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42475 + pax_flags |= MF_PAX_EMUTRAMP;
42476 +#endif
42477 +
42478 +#ifdef CONFIG_PAX_MPROTECT
42479 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42480 + pax_flags |= MF_PAX_MPROTECT;
42481 +#endif
42482 +
42483 +#ifdef CONFIG_PAX_ASLR
42484 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42485 + pax_flags |= MF_PAX_RANDMMAP;
42486 +#endif
42487 +
42488 +#else
42489 +
42490 +#ifdef CONFIG_PAX_PAGEEXEC
42491 + pax_flags |= MF_PAX_PAGEEXEC;
42492 +#endif
42493 +
42494 +#ifdef CONFIG_PAX_MPROTECT
42495 + pax_flags |= MF_PAX_MPROTECT;
42496 +#endif
42497 +
42498 +#ifdef CONFIG_PAX_RANDMMAP
42499 + pax_flags |= MF_PAX_RANDMMAP;
42500 +#endif
42501 +
42502 +#ifdef CONFIG_PAX_SEGMEXEC
42503 + if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
42504 + pax_flags &= ~MF_PAX_PAGEEXEC;
42505 + pax_flags |= MF_PAX_SEGMEXEC;
42506 + }
42507 +#endif
42508 +
42509 +#endif
42510 +
42511 + return pax_flags;
42512 +}
42513 +
42514 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42515 +{
42516 +
42517 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42518 + unsigned long i;
42519 +
42520 + for (i = 0UL; i < elf_ex->e_phnum; i++)
42521 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42522 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42523 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42524 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42525 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42526 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42527 + return ~0UL;
42528 +
42529 +#ifdef CONFIG_PAX_SOFTMODE
42530 + if (pax_softmode)
42531 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42532 + else
42533 +#endif
42534 +
42535 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42536 + break;
42537 + }
42538 +#endif
42539 +
42540 + return ~0UL;
42541 +}
42542 +
42543 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42544 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42545 +{
42546 + unsigned long pax_flags = 0UL;
42547 +
42548 +#ifdef CONFIG_PAX_PAGEEXEC
42549 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42550 + pax_flags |= MF_PAX_PAGEEXEC;
42551 +#endif
42552 +
42553 +#ifdef CONFIG_PAX_SEGMEXEC
42554 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42555 + pax_flags |= MF_PAX_SEGMEXEC;
42556 +#endif
42557 +
42558 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42559 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42560 + if ((__supported_pte_mask & _PAGE_NX))
42561 + pax_flags &= ~MF_PAX_SEGMEXEC;
42562 + else
42563 + pax_flags &= ~MF_PAX_PAGEEXEC;
42564 + }
42565 +#endif
42566 +
42567 +#ifdef CONFIG_PAX_EMUTRAMP
42568 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42569 + pax_flags |= MF_PAX_EMUTRAMP;
42570 +#endif
42571 +
42572 +#ifdef CONFIG_PAX_MPROTECT
42573 + if (pax_flags_softmode & MF_PAX_MPROTECT)
42574 + pax_flags |= MF_PAX_MPROTECT;
42575 +#endif
42576 +
42577 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42578 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42579 + pax_flags |= MF_PAX_RANDMMAP;
42580 +#endif
42581 +
42582 + return pax_flags;
42583 +}
42584 +
42585 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42586 +{
42587 + unsigned long pax_flags = 0UL;
42588 +
42589 +#ifdef CONFIG_PAX_PAGEEXEC
42590 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42591 + pax_flags |= MF_PAX_PAGEEXEC;
42592 +#endif
42593 +
42594 +#ifdef CONFIG_PAX_SEGMEXEC
42595 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42596 + pax_flags |= MF_PAX_SEGMEXEC;
42597 +#endif
42598 +
42599 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42600 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42601 + if ((__supported_pte_mask & _PAGE_NX))
42602 + pax_flags &= ~MF_PAX_SEGMEXEC;
42603 + else
42604 + pax_flags &= ~MF_PAX_PAGEEXEC;
42605 + }
42606 +#endif
42607 +
42608 +#ifdef CONFIG_PAX_EMUTRAMP
42609 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42610 + pax_flags |= MF_PAX_EMUTRAMP;
42611 +#endif
42612 +
42613 +#ifdef CONFIG_PAX_MPROTECT
42614 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42615 + pax_flags |= MF_PAX_MPROTECT;
42616 +#endif
42617 +
42618 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42619 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42620 + pax_flags |= MF_PAX_RANDMMAP;
42621 +#endif
42622 +
42623 + return pax_flags;
42624 +}
42625 +#endif
42626 +
42627 +static unsigned long pax_parse_xattr_pax(struct file * const file)
42628 +{
42629 +
42630 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42631 + ssize_t xattr_size, i;
42632 + unsigned char xattr_value[5];
42633 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42634 +
42635 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42636 + if (xattr_size <= 0)
42637 + return ~0UL;
42638 +
42639 + for (i = 0; i < xattr_size; i++)
42640 + switch (xattr_value[i]) {
42641 + default:
42642 + return ~0UL;
42643 +
42644 +#define parse_flag(option1, option2, flag) \
42645 + case option1: \
42646 + pax_flags_hardmode |= MF_PAX_##flag; \
42647 + break; \
42648 + case option2: \
42649 + pax_flags_softmode |= MF_PAX_##flag; \
42650 + break;
42651 +
42652 + parse_flag('p', 'P', PAGEEXEC);
42653 + parse_flag('e', 'E', EMUTRAMP);
42654 + parse_flag('m', 'M', MPROTECT);
42655 + parse_flag('r', 'R', RANDMMAP);
42656 + parse_flag('s', 'S', SEGMEXEC);
42657 +
42658 +#undef parse_flag
42659 + }
42660 +
42661 + if (pax_flags_hardmode & pax_flags_softmode)
42662 + return ~0UL;
42663 +
42664 +#ifdef CONFIG_PAX_SOFTMODE
42665 + if (pax_softmode)
42666 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42667 + else
42668 +#endif
42669 +
42670 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42671 +#else
42672 + return ~0UL;
42673 +#endif
42674 +
42675 +}
42676 +
42677 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42678 +{
42679 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42680 +
42681 + pax_flags = pax_parse_ei_pax(elf_ex);
42682 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42683 + xattr_pax_flags = pax_parse_xattr_pax(file);
42684 +
42685 + if (pt_pax_flags == ~0UL)
42686 + pt_pax_flags = xattr_pax_flags;
42687 + else if (xattr_pax_flags == ~0UL)
42688 + xattr_pax_flags = pt_pax_flags;
42689 + if (pt_pax_flags != xattr_pax_flags)
42690 + return -EINVAL;
42691 + if (pt_pax_flags != ~0UL)
42692 + pax_flags = pt_pax_flags;
42693 +
42694 + if (0 > pax_check_flags(&pax_flags))
42695 + return -EINVAL;
42696 +
42697 + current->mm->pax_flags = pax_flags;
42698 + return 0;
42699 +}
42700 +#endif
42701 +
42702 /*
42703 * These are the functions used to load ELF style executables and shared
42704 * libraries. There is no binary dependent code anywhere else.
42705 @@ -544,6 +913,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42706 {
42707 unsigned int random_variable = 0;
42708
42709 +#ifdef CONFIG_PAX_RANDUSTACK
42710 + if (randomize_va_space)
42711 + return stack_top - current->mm->delta_stack;
42712 +#endif
42713 +
42714 if ((current->flags & PF_RANDOMIZE) &&
42715 !(current->personality & ADDR_NO_RANDOMIZE)) {
42716 random_variable = get_random_int() & STACK_RND_MASK;
42717 @@ -562,7 +936,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42718 unsigned long load_addr = 0, load_bias = 0;
42719 int load_addr_set = 0;
42720 char * elf_interpreter = NULL;
42721 - unsigned long error;
42722 + unsigned long error = 0;
42723 struct elf_phdr *elf_ppnt, *elf_phdata;
42724 unsigned long elf_bss, elf_brk;
42725 int retval, i;
42726 @@ -572,11 +946,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42727 unsigned long start_code, end_code, start_data, end_data;
42728 unsigned long reloc_func_desc __maybe_unused = 0;
42729 int executable_stack = EXSTACK_DEFAULT;
42730 - unsigned long def_flags = 0;
42731 struct {
42732 struct elfhdr elf_ex;
42733 struct elfhdr interp_elf_ex;
42734 } *loc;
42735 + unsigned long pax_task_size = TASK_SIZE;
42736
42737 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42738 if (!loc) {
42739 @@ -713,11 +1087,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42740
42741 /* OK, This is the point of no return */
42742 current->flags &= ~PF_FORKNOEXEC;
42743 - current->mm->def_flags = def_flags;
42744 +
42745 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42746 + current->mm->pax_flags = 0UL;
42747 +#endif
42748 +
42749 +#ifdef CONFIG_PAX_DLRESOLVE
42750 + current->mm->call_dl_resolve = 0UL;
42751 +#endif
42752 +
42753 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42754 + current->mm->call_syscall = 0UL;
42755 +#endif
42756 +
42757 +#ifdef CONFIG_PAX_ASLR
42758 + current->mm->delta_mmap = 0UL;
42759 + current->mm->delta_stack = 0UL;
42760 +#endif
42761 +
42762 + current->mm->def_flags = 0;
42763 +
42764 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42765 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42766 + send_sig(SIGKILL, current, 0);
42767 + goto out_free_dentry;
42768 + }
42769 +#endif
42770 +
42771 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42772 + pax_set_initial_flags(bprm);
42773 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42774 + if (pax_set_initial_flags_func)
42775 + (pax_set_initial_flags_func)(bprm);
42776 +#endif
42777 +
42778 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42779 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42780 + current->mm->context.user_cs_limit = PAGE_SIZE;
42781 + current->mm->def_flags |= VM_PAGEEXEC;
42782 + }
42783 +#endif
42784 +
42785 +#ifdef CONFIG_PAX_SEGMEXEC
42786 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42787 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42788 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42789 + pax_task_size = SEGMEXEC_TASK_SIZE;
42790 + current->mm->def_flags |= VM_NOHUGEPAGE;
42791 + }
42792 +#endif
42793 +
42794 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42795 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42796 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42797 + put_cpu();
42798 + }
42799 +#endif
42800
42801 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42802 may depend on the personality. */
42803 SET_PERSONALITY(loc->elf_ex);
42804 +
42805 +#ifdef CONFIG_PAX_ASLR
42806 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42807 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42808 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42809 + }
42810 +#endif
42811 +
42812 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42813 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42814 + executable_stack = EXSTACK_DISABLE_X;
42815 + current->personality &= ~READ_IMPLIES_EXEC;
42816 + } else
42817 +#endif
42818 +
42819 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42820 current->personality |= READ_IMPLIES_EXEC;
42821
42822 @@ -808,6 +1252,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42823 #else
42824 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42825 #endif
42826 +
42827 +#ifdef CONFIG_PAX_RANDMMAP
42828 + /* PaX: randomize base address at the default exe base if requested */
42829 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42830 +#ifdef CONFIG_SPARC64
42831 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42832 +#else
42833 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42834 +#endif
42835 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42836 + elf_flags |= MAP_FIXED;
42837 + }
42838 +#endif
42839 +
42840 }
42841
42842 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42843 @@ -840,9 +1298,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42844 * allowed task size. Note that p_filesz must always be
42845 * <= p_memsz so it is only necessary to check p_memsz.
42846 */
42847 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42848 - elf_ppnt->p_memsz > TASK_SIZE ||
42849 - TASK_SIZE - elf_ppnt->p_memsz < k) {
42850 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42851 + elf_ppnt->p_memsz > pax_task_size ||
42852 + pax_task_size - elf_ppnt->p_memsz < k) {
42853 /* set_brk can never work. Avoid overflows. */
42854 send_sig(SIGKILL, current, 0);
42855 retval = -EINVAL;
42856 @@ -870,6 +1328,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42857 start_data += load_bias;
42858 end_data += load_bias;
42859
42860 +#ifdef CONFIG_PAX_RANDMMAP
42861 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
42862 + elf_brk += PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42863 +#endif
42864 +
42865 /* Calling set_brk effectively mmaps the pages that we need
42866 * for the bss and break sections. We must do this before
42867 * mapping in the interpreter, to make sure it doesn't wind
42868 @@ -881,9 +1344,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42869 goto out_free_dentry;
42870 }
42871 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42872 - send_sig(SIGSEGV, current, 0);
42873 - retval = -EFAULT; /* Nobody gets to see this, but.. */
42874 - goto out_free_dentry;
42875 + /*
42876 + * This bss-zeroing can fail if the ELF
42877 + * file specifies odd protections. So
42878 + * we don't check the return value
42879 + */
42880 }
42881
42882 if (elf_interpreter) {
42883 @@ -1098,7 +1563,7 @@ out:
42884 * Decide what to dump of a segment, part, all or none.
42885 */
42886 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42887 - unsigned long mm_flags)
42888 + unsigned long mm_flags, long signr)
42889 {
42890 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42891
42892 @@ -1132,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42893 if (vma->vm_file == NULL)
42894 return 0;
42895
42896 - if (FILTER(MAPPED_PRIVATE))
42897 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42898 goto whole;
42899
42900 /*
42901 @@ -1354,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42902 {
42903 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42904 int i = 0;
42905 - do
42906 + do {
42907 i += 2;
42908 - while (auxv[i - 2] != AT_NULL);
42909 + } while (auxv[i - 2] != AT_NULL);
42910 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
42911 }
42912
42913 @@ -1862,14 +2327,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
42914 }
42915
42916 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
42917 - unsigned long mm_flags)
42918 + struct coredump_params *cprm)
42919 {
42920 struct vm_area_struct *vma;
42921 size_t size = 0;
42922
42923 for (vma = first_vma(current, gate_vma); vma != NULL;
42924 vma = next_vma(vma, gate_vma))
42925 - size += vma_dump_size(vma, mm_flags);
42926 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42927 return size;
42928 }
42929
42930 @@ -1963,7 +2428,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42931
42932 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
42933
42934 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
42935 + offset += elf_core_vma_data_size(gate_vma, cprm);
42936 offset += elf_core_extra_data_size();
42937 e_shoff = offset;
42938
42939 @@ -1977,10 +2442,12 @@ static int elf_core_dump(struct coredump_params *cprm)
42940 offset = dataoff;
42941
42942 size += sizeof(*elf);
42943 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42944 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
42945 goto end_coredump;
42946
42947 size += sizeof(*phdr4note);
42948 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42949 if (size > cprm->limit
42950 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
42951 goto end_coredump;
42952 @@ -1994,7 +2461,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42953 phdr.p_offset = offset;
42954 phdr.p_vaddr = vma->vm_start;
42955 phdr.p_paddr = 0;
42956 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
42957 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42958 phdr.p_memsz = vma->vm_end - vma->vm_start;
42959 offset += phdr.p_filesz;
42960 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
42961 @@ -2005,6 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42962 phdr.p_align = ELF_EXEC_PAGESIZE;
42963
42964 size += sizeof(phdr);
42965 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42966 if (size > cprm->limit
42967 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
42968 goto end_coredump;
42969 @@ -2029,7 +2497,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42970 unsigned long addr;
42971 unsigned long end;
42972
42973 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
42974 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42975
42976 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
42977 struct page *page;
42978 @@ -2038,6 +2506,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42979 page = get_dump_page(addr);
42980 if (page) {
42981 void *kaddr = kmap(page);
42982 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
42983 stop = ((size += PAGE_SIZE) > cprm->limit) ||
42984 !dump_write(cprm->file, kaddr,
42985 PAGE_SIZE);
42986 @@ -2055,6 +2524,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42987
42988 if (e_phnum == PN_XNUM) {
42989 size += sizeof(*shdr4extnum);
42990 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42991 if (size > cprm->limit
42992 || !dump_write(cprm->file, shdr4extnum,
42993 sizeof(*shdr4extnum)))
42994 @@ -2075,6 +2545,97 @@ out:
42995
42996 #endif /* CONFIG_ELF_CORE */
42997
42998 +#ifdef CONFIG_PAX_MPROTECT
42999 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43000 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43001 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43002 + *
43003 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43004 + * basis because we want to allow the common case and not the special ones.
43005 + */
43006 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43007 +{
43008 + struct elfhdr elf_h;
43009 + struct elf_phdr elf_p;
43010 + unsigned long i;
43011 + unsigned long oldflags;
43012 + bool is_textrel_rw, is_textrel_rx, is_relro;
43013 +
43014 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43015 + return;
43016 +
43017 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43018 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43019 +
43020 +#ifdef CONFIG_PAX_ELFRELOCS
43021 + /* possible TEXTREL */
43022 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43023 + 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);
43024 +#else
43025 + is_textrel_rw = false;
43026 + is_textrel_rx = false;
43027 +#endif
43028 +
43029 + /* possible RELRO */
43030 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43031 +
43032 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43033 + return;
43034 +
43035 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43036 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43037 +
43038 +#ifdef CONFIG_PAX_ETEXECRELOCS
43039 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43040 +#else
43041 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43042 +#endif
43043 +
43044 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43045 + !elf_check_arch(&elf_h) ||
43046 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43047 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43048 + return;
43049 +
43050 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43051 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43052 + return;
43053 + switch (elf_p.p_type) {
43054 + case PT_DYNAMIC:
43055 + if (!is_textrel_rw && !is_textrel_rx)
43056 + continue;
43057 + i = 0UL;
43058 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43059 + elf_dyn dyn;
43060 +
43061 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43062 + return;
43063 + if (dyn.d_tag == DT_NULL)
43064 + return;
43065 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43066 + gr_log_textrel(vma);
43067 + if (is_textrel_rw)
43068 + vma->vm_flags |= VM_MAYWRITE;
43069 + else
43070 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43071 + vma->vm_flags &= ~VM_MAYWRITE;
43072 + return;
43073 + }
43074 + i++;
43075 + }
43076 + return;
43077 +
43078 + case PT_GNU_RELRO:
43079 + if (!is_relro)
43080 + continue;
43081 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43082 + vma->vm_flags &= ~VM_MAYWRITE;
43083 + return;
43084 + }
43085 + }
43086 +}
43087 +#endif
43088 +
43089 static int __init init_elf_binfmt(void)
43090 {
43091 return register_binfmt(&elf_format);
43092 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43093 index 1bffbe0..c8c283e 100644
43094 --- a/fs/binfmt_flat.c
43095 +++ b/fs/binfmt_flat.c
43096 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43097 realdatastart = (unsigned long) -ENOMEM;
43098 printk("Unable to allocate RAM for process data, errno %d\n",
43099 (int)-realdatastart);
43100 + down_write(&current->mm->mmap_sem);
43101 do_munmap(current->mm, textpos, text_len);
43102 + up_write(&current->mm->mmap_sem);
43103 ret = realdatastart;
43104 goto err;
43105 }
43106 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43107 }
43108 if (IS_ERR_VALUE(result)) {
43109 printk("Unable to read data+bss, errno %d\n", (int)-result);
43110 + down_write(&current->mm->mmap_sem);
43111 do_munmap(current->mm, textpos, text_len);
43112 do_munmap(current->mm, realdatastart, len);
43113 + up_write(&current->mm->mmap_sem);
43114 ret = result;
43115 goto err;
43116 }
43117 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43118 }
43119 if (IS_ERR_VALUE(result)) {
43120 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43121 + down_write(&current->mm->mmap_sem);
43122 do_munmap(current->mm, textpos, text_len + data_len + extra +
43123 MAX_SHARED_LIBS * sizeof(unsigned long));
43124 + up_write(&current->mm->mmap_sem);
43125 ret = result;
43126 goto err;
43127 }
43128 diff --git a/fs/bio.c b/fs/bio.c
43129 index b1fe82c..84da0a9 100644
43130 --- a/fs/bio.c
43131 +++ b/fs/bio.c
43132 @@ -1233,7 +1233,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43133 const int read = bio_data_dir(bio) == READ;
43134 struct bio_map_data *bmd = bio->bi_private;
43135 int i;
43136 - char *p = bmd->sgvecs[0].iov_base;
43137 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43138
43139 __bio_for_each_segment(bvec, bio, i, 0) {
43140 char *addr = page_address(bvec->bv_page);
43141 diff --git a/fs/block_dev.c b/fs/block_dev.c
43142 index abe9b48..5df59e8 100644
43143 --- a/fs/block_dev.c
43144 +++ b/fs/block_dev.c
43145 @@ -681,7 +681,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43146 else if (bdev->bd_contains == bdev)
43147 return true; /* is a whole device which isn't held */
43148
43149 - else if (whole->bd_holder == bd_may_claim)
43150 + else if (whole->bd_holder == (void *)bd_may_claim)
43151 return true; /* is a partition of a device that is being partitioned */
43152 else if (whole->bd_holder != NULL)
43153 return false; /* is a partition of a held device */
43154 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43155 index dede441..f2a2507 100644
43156 --- a/fs/btrfs/ctree.c
43157 +++ b/fs/btrfs/ctree.c
43158 @@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43159 free_extent_buffer(buf);
43160 add_root_to_dirty_list(root);
43161 } else {
43162 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43163 - parent_start = parent->start;
43164 - else
43165 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43166 + if (parent)
43167 + parent_start = parent->start;
43168 + else
43169 + parent_start = 0;
43170 + } else
43171 parent_start = 0;
43172
43173 WARN_ON(trans->transid != btrfs_header_generation(parent));
43174 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43175 index fd1a06d..6e9033d 100644
43176 --- a/fs/btrfs/inode.c
43177 +++ b/fs/btrfs/inode.c
43178 @@ -6895,7 +6895,7 @@ fail:
43179 return -ENOMEM;
43180 }
43181
43182 -static int btrfs_getattr(struct vfsmount *mnt,
43183 +int btrfs_getattr(struct vfsmount *mnt,
43184 struct dentry *dentry, struct kstat *stat)
43185 {
43186 struct inode *inode = dentry->d_inode;
43187 @@ -6909,6 +6909,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43188 return 0;
43189 }
43190
43191 +EXPORT_SYMBOL(btrfs_getattr);
43192 +
43193 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43194 +{
43195 + return BTRFS_I(inode)->root->anon_dev;
43196 +}
43197 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43198 +
43199 /*
43200 * If a file is moved, it will inherit the cow and compression flags of the new
43201 * directory.
43202 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43203 index c04f02c..f5c9e2e 100644
43204 --- a/fs/btrfs/ioctl.c
43205 +++ b/fs/btrfs/ioctl.c
43206 @@ -2733,9 +2733,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43207 for (i = 0; i < num_types; i++) {
43208 struct btrfs_space_info *tmp;
43209
43210 + /* Don't copy in more than we allocated */
43211 if (!slot_count)
43212 break;
43213
43214 + slot_count--;
43215 +
43216 info = NULL;
43217 rcu_read_lock();
43218 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43219 @@ -2757,15 +2760,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43220 memcpy(dest, &space, sizeof(space));
43221 dest++;
43222 space_args.total_spaces++;
43223 - slot_count--;
43224 }
43225 - if (!slot_count)
43226 - break;
43227 }
43228 up_read(&info->groups_sem);
43229 }
43230
43231 - user_dest = (struct btrfs_ioctl_space_info *)
43232 + user_dest = (struct btrfs_ioctl_space_info __user *)
43233 (arg + sizeof(struct btrfs_ioctl_space_args));
43234
43235 if (copy_to_user(user_dest, dest_orig, alloc_size))
43236 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43237 index cfb5543..1ae7347 100644
43238 --- a/fs/btrfs/relocation.c
43239 +++ b/fs/btrfs/relocation.c
43240 @@ -1244,7 +1244,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43241 }
43242 spin_unlock(&rc->reloc_root_tree.lock);
43243
43244 - BUG_ON((struct btrfs_root *)node->data != root);
43245 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43246
43247 if (!del) {
43248 spin_lock(&rc->reloc_root_tree.lock);
43249 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43250 index 622f469..e8d2d55 100644
43251 --- a/fs/cachefiles/bind.c
43252 +++ b/fs/cachefiles/bind.c
43253 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43254 args);
43255
43256 /* start by checking things over */
43257 - ASSERT(cache->fstop_percent >= 0 &&
43258 - cache->fstop_percent < cache->fcull_percent &&
43259 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43260 cache->fcull_percent < cache->frun_percent &&
43261 cache->frun_percent < 100);
43262
43263 - ASSERT(cache->bstop_percent >= 0 &&
43264 - cache->bstop_percent < cache->bcull_percent &&
43265 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43266 cache->bcull_percent < cache->brun_percent &&
43267 cache->brun_percent < 100);
43268
43269 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43270 index 0a1467b..6a53245 100644
43271 --- a/fs/cachefiles/daemon.c
43272 +++ b/fs/cachefiles/daemon.c
43273 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43274 if (n > buflen)
43275 return -EMSGSIZE;
43276
43277 - if (copy_to_user(_buffer, buffer, n) != 0)
43278 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43279 return -EFAULT;
43280
43281 return n;
43282 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43283 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43284 return -EIO;
43285
43286 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43287 + if (datalen > PAGE_SIZE - 1)
43288 return -EOPNOTSUPP;
43289
43290 /* drag the command string into the kernel so we can parse it */
43291 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43292 if (args[0] != '%' || args[1] != '\0')
43293 return -EINVAL;
43294
43295 - if (fstop < 0 || fstop >= cache->fcull_percent)
43296 + if (fstop >= cache->fcull_percent)
43297 return cachefiles_daemon_range_error(cache, args);
43298
43299 cache->fstop_percent = fstop;
43300 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43301 if (args[0] != '%' || args[1] != '\0')
43302 return -EINVAL;
43303
43304 - if (bstop < 0 || bstop >= cache->bcull_percent)
43305 + if (bstop >= cache->bcull_percent)
43306 return cachefiles_daemon_range_error(cache, args);
43307
43308 cache->bstop_percent = bstop;
43309 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43310 index bd6bc1b..b627b53 100644
43311 --- a/fs/cachefiles/internal.h
43312 +++ b/fs/cachefiles/internal.h
43313 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43314 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43315 struct rb_root active_nodes; /* active nodes (can't be culled) */
43316 rwlock_t active_lock; /* lock for active_nodes */
43317 - atomic_t gravecounter; /* graveyard uniquifier */
43318 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43319 unsigned frun_percent; /* when to stop culling (% files) */
43320 unsigned fcull_percent; /* when to start culling (% files) */
43321 unsigned fstop_percent; /* when to stop allocating (% files) */
43322 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43323 * proc.c
43324 */
43325 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43326 -extern atomic_t cachefiles_lookup_histogram[HZ];
43327 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43328 -extern atomic_t cachefiles_create_histogram[HZ];
43329 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43330 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43331 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43332
43333 extern int __init cachefiles_proc_init(void);
43334 extern void cachefiles_proc_cleanup(void);
43335 static inline
43336 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43337 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43338 {
43339 unsigned long jif = jiffies - start_jif;
43340 if (jif >= HZ)
43341 jif = HZ - 1;
43342 - atomic_inc(&histogram[jif]);
43343 + atomic_inc_unchecked(&histogram[jif]);
43344 }
43345
43346 #else
43347 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43348 index a0358c2..d6137f2 100644
43349 --- a/fs/cachefiles/namei.c
43350 +++ b/fs/cachefiles/namei.c
43351 @@ -318,7 +318,7 @@ try_again:
43352 /* first step is to make up a grave dentry in the graveyard */
43353 sprintf(nbuffer, "%08x%08x",
43354 (uint32_t) get_seconds(),
43355 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43356 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43357
43358 /* do the multiway lock magic */
43359 trap = lock_rename(cache->graveyard, dir);
43360 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43361 index eccd339..4c1d995 100644
43362 --- a/fs/cachefiles/proc.c
43363 +++ b/fs/cachefiles/proc.c
43364 @@ -14,9 +14,9 @@
43365 #include <linux/seq_file.h>
43366 #include "internal.h"
43367
43368 -atomic_t cachefiles_lookup_histogram[HZ];
43369 -atomic_t cachefiles_mkdir_histogram[HZ];
43370 -atomic_t cachefiles_create_histogram[HZ];
43371 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43372 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43373 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43374
43375 /*
43376 * display the latency histogram
43377 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43378 return 0;
43379 default:
43380 index = (unsigned long) v - 3;
43381 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43382 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43383 - z = atomic_read(&cachefiles_create_histogram[index]);
43384 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43385 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43386 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43387 if (x == 0 && y == 0 && z == 0)
43388 return 0;
43389
43390 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43391 index 0e3c092..818480e 100644
43392 --- a/fs/cachefiles/rdwr.c
43393 +++ b/fs/cachefiles/rdwr.c
43394 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43395 old_fs = get_fs();
43396 set_fs(KERNEL_DS);
43397 ret = file->f_op->write(
43398 - file, (const void __user *) data, len, &pos);
43399 + file, (const void __force_user *) data, len, &pos);
43400 set_fs(old_fs);
43401 kunmap(page);
43402 if (ret != len)
43403 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43404 index 9895400..fa40a7d 100644
43405 --- a/fs/ceph/dir.c
43406 +++ b/fs/ceph/dir.c
43407 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43408 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43409 struct ceph_mds_client *mdsc = fsc->mdsc;
43410 unsigned frag = fpos_frag(filp->f_pos);
43411 - int off = fpos_off(filp->f_pos);
43412 + unsigned int off = fpos_off(filp->f_pos);
43413 int err;
43414 u32 ftype;
43415 struct ceph_mds_reply_info_parsed *rinfo;
43416 diff --git a/fs/cifs/asn1.c b/fs/cifs/asn1.c
43417 index cfd1ce3..6b13a74 100644
43418 --- a/fs/cifs/asn1.c
43419 +++ b/fs/cifs/asn1.c
43420 @@ -416,6 +416,9 @@ asn1_subid_decode(struct asn1_ctx *ctx, unsigned long *subid)
43421
43422 static int
43423 asn1_oid_decode(struct asn1_ctx *ctx,
43424 + unsigned char *eoc, unsigned long **oid, unsigned int *len) __size_overflow(2);
43425 +static int
43426 +asn1_oid_decode(struct asn1_ctx *ctx,
43427 unsigned char *eoc, unsigned long **oid, unsigned int *len)
43428 {
43429 unsigned long subid;
43430 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43431 index 84e8c07..6170d31 100644
43432 --- a/fs/cifs/cifs_debug.c
43433 +++ b/fs/cifs/cifs_debug.c
43434 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43435
43436 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43437 #ifdef CONFIG_CIFS_STATS2
43438 - atomic_set(&totBufAllocCount, 0);
43439 - atomic_set(&totSmBufAllocCount, 0);
43440 + atomic_set_unchecked(&totBufAllocCount, 0);
43441 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43442 #endif /* CONFIG_CIFS_STATS2 */
43443 spin_lock(&cifs_tcp_ses_lock);
43444 list_for_each(tmp1, &cifs_tcp_ses_list) {
43445 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43446 tcon = list_entry(tmp3,
43447 struct cifs_tcon,
43448 tcon_list);
43449 - atomic_set(&tcon->num_smbs_sent, 0);
43450 - atomic_set(&tcon->num_writes, 0);
43451 - atomic_set(&tcon->num_reads, 0);
43452 - atomic_set(&tcon->num_oplock_brks, 0);
43453 - atomic_set(&tcon->num_opens, 0);
43454 - atomic_set(&tcon->num_posixopens, 0);
43455 - atomic_set(&tcon->num_posixmkdirs, 0);
43456 - atomic_set(&tcon->num_closes, 0);
43457 - atomic_set(&tcon->num_deletes, 0);
43458 - atomic_set(&tcon->num_mkdirs, 0);
43459 - atomic_set(&tcon->num_rmdirs, 0);
43460 - atomic_set(&tcon->num_renames, 0);
43461 - atomic_set(&tcon->num_t2renames, 0);
43462 - atomic_set(&tcon->num_ffirst, 0);
43463 - atomic_set(&tcon->num_fnext, 0);
43464 - atomic_set(&tcon->num_fclose, 0);
43465 - atomic_set(&tcon->num_hardlinks, 0);
43466 - atomic_set(&tcon->num_symlinks, 0);
43467 - atomic_set(&tcon->num_locks, 0);
43468 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43469 + atomic_set_unchecked(&tcon->num_writes, 0);
43470 + atomic_set_unchecked(&tcon->num_reads, 0);
43471 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43472 + atomic_set_unchecked(&tcon->num_opens, 0);
43473 + atomic_set_unchecked(&tcon->num_posixopens, 0);
43474 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43475 + atomic_set_unchecked(&tcon->num_closes, 0);
43476 + atomic_set_unchecked(&tcon->num_deletes, 0);
43477 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
43478 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
43479 + atomic_set_unchecked(&tcon->num_renames, 0);
43480 + atomic_set_unchecked(&tcon->num_t2renames, 0);
43481 + atomic_set_unchecked(&tcon->num_ffirst, 0);
43482 + atomic_set_unchecked(&tcon->num_fnext, 0);
43483 + atomic_set_unchecked(&tcon->num_fclose, 0);
43484 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
43485 + atomic_set_unchecked(&tcon->num_symlinks, 0);
43486 + atomic_set_unchecked(&tcon->num_locks, 0);
43487 }
43488 }
43489 }
43490 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43491 smBufAllocCount.counter, cifs_min_small);
43492 #ifdef CONFIG_CIFS_STATS2
43493 seq_printf(m, "Total Large %d Small %d Allocations\n",
43494 - atomic_read(&totBufAllocCount),
43495 - atomic_read(&totSmBufAllocCount));
43496 + atomic_read_unchecked(&totBufAllocCount),
43497 + atomic_read_unchecked(&totSmBufAllocCount));
43498 #endif /* CONFIG_CIFS_STATS2 */
43499
43500 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43501 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43502 if (tcon->need_reconnect)
43503 seq_puts(m, "\tDISCONNECTED ");
43504 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43505 - atomic_read(&tcon->num_smbs_sent),
43506 - atomic_read(&tcon->num_oplock_brks));
43507 + atomic_read_unchecked(&tcon->num_smbs_sent),
43508 + atomic_read_unchecked(&tcon->num_oplock_brks));
43509 seq_printf(m, "\nReads: %d Bytes: %lld",
43510 - atomic_read(&tcon->num_reads),
43511 + atomic_read_unchecked(&tcon->num_reads),
43512 (long long)(tcon->bytes_read));
43513 seq_printf(m, "\nWrites: %d Bytes: %lld",
43514 - atomic_read(&tcon->num_writes),
43515 + atomic_read_unchecked(&tcon->num_writes),
43516 (long long)(tcon->bytes_written));
43517 seq_printf(m, "\nFlushes: %d",
43518 - atomic_read(&tcon->num_flushes));
43519 + atomic_read_unchecked(&tcon->num_flushes));
43520 seq_printf(m, "\nLocks: %d HardLinks: %d "
43521 "Symlinks: %d",
43522 - atomic_read(&tcon->num_locks),
43523 - atomic_read(&tcon->num_hardlinks),
43524 - atomic_read(&tcon->num_symlinks));
43525 + atomic_read_unchecked(&tcon->num_locks),
43526 + atomic_read_unchecked(&tcon->num_hardlinks),
43527 + atomic_read_unchecked(&tcon->num_symlinks));
43528 seq_printf(m, "\nOpens: %d Closes: %d "
43529 "Deletes: %d",
43530 - atomic_read(&tcon->num_opens),
43531 - atomic_read(&tcon->num_closes),
43532 - atomic_read(&tcon->num_deletes));
43533 + atomic_read_unchecked(&tcon->num_opens),
43534 + atomic_read_unchecked(&tcon->num_closes),
43535 + atomic_read_unchecked(&tcon->num_deletes));
43536 seq_printf(m, "\nPosix Opens: %d "
43537 "Posix Mkdirs: %d",
43538 - atomic_read(&tcon->num_posixopens),
43539 - atomic_read(&tcon->num_posixmkdirs));
43540 + atomic_read_unchecked(&tcon->num_posixopens),
43541 + atomic_read_unchecked(&tcon->num_posixmkdirs));
43542 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43543 - atomic_read(&tcon->num_mkdirs),
43544 - atomic_read(&tcon->num_rmdirs));
43545 + atomic_read_unchecked(&tcon->num_mkdirs),
43546 + atomic_read_unchecked(&tcon->num_rmdirs));
43547 seq_printf(m, "\nRenames: %d T2 Renames %d",
43548 - atomic_read(&tcon->num_renames),
43549 - atomic_read(&tcon->num_t2renames));
43550 + atomic_read_unchecked(&tcon->num_renames),
43551 + atomic_read_unchecked(&tcon->num_t2renames));
43552 seq_printf(m, "\nFindFirst: %d FNext %d "
43553 "FClose %d",
43554 - atomic_read(&tcon->num_ffirst),
43555 - atomic_read(&tcon->num_fnext),
43556 - atomic_read(&tcon->num_fclose));
43557 + atomic_read_unchecked(&tcon->num_ffirst),
43558 + atomic_read_unchecked(&tcon->num_fnext),
43559 + atomic_read_unchecked(&tcon->num_fclose));
43560 }
43561 }
43562 }
43563 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43564 index 8f1fe32..38f9e27 100644
43565 --- a/fs/cifs/cifsfs.c
43566 +++ b/fs/cifs/cifsfs.c
43567 @@ -989,7 +989,7 @@ cifs_init_request_bufs(void)
43568 cifs_req_cachep = kmem_cache_create("cifs_request",
43569 CIFSMaxBufSize +
43570 MAX_CIFS_HDR_SIZE, 0,
43571 - SLAB_HWCACHE_ALIGN, NULL);
43572 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43573 if (cifs_req_cachep == NULL)
43574 return -ENOMEM;
43575
43576 @@ -1016,7 +1016,7 @@ cifs_init_request_bufs(void)
43577 efficient to alloc 1 per page off the slab compared to 17K (5page)
43578 alloc of large cifs buffers even when page debugging is on */
43579 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43580 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43581 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43582 NULL);
43583 if (cifs_sm_req_cachep == NULL) {
43584 mempool_destroy(cifs_req_poolp);
43585 @@ -1101,8 +1101,8 @@ init_cifs(void)
43586 atomic_set(&bufAllocCount, 0);
43587 atomic_set(&smBufAllocCount, 0);
43588 #ifdef CONFIG_CIFS_STATS2
43589 - atomic_set(&totBufAllocCount, 0);
43590 - atomic_set(&totSmBufAllocCount, 0);
43591 + atomic_set_unchecked(&totBufAllocCount, 0);
43592 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43593 #endif /* CONFIG_CIFS_STATS2 */
43594
43595 atomic_set(&midCount, 0);
43596 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43597 index 8238aa1..0347196 100644
43598 --- a/fs/cifs/cifsglob.h
43599 +++ b/fs/cifs/cifsglob.h
43600 @@ -392,28 +392,28 @@ struct cifs_tcon {
43601 __u16 Flags; /* optional support bits */
43602 enum statusEnum tidStatus;
43603 #ifdef CONFIG_CIFS_STATS
43604 - atomic_t num_smbs_sent;
43605 - atomic_t num_writes;
43606 - atomic_t num_reads;
43607 - atomic_t num_flushes;
43608 - atomic_t num_oplock_brks;
43609 - atomic_t num_opens;
43610 - atomic_t num_closes;
43611 - atomic_t num_deletes;
43612 - atomic_t num_mkdirs;
43613 - atomic_t num_posixopens;
43614 - atomic_t num_posixmkdirs;
43615 - atomic_t num_rmdirs;
43616 - atomic_t num_renames;
43617 - atomic_t num_t2renames;
43618 - atomic_t num_ffirst;
43619 - atomic_t num_fnext;
43620 - atomic_t num_fclose;
43621 - atomic_t num_hardlinks;
43622 - atomic_t num_symlinks;
43623 - atomic_t num_locks;
43624 - atomic_t num_acl_get;
43625 - atomic_t num_acl_set;
43626 + atomic_unchecked_t num_smbs_sent;
43627 + atomic_unchecked_t num_writes;
43628 + atomic_unchecked_t num_reads;
43629 + atomic_unchecked_t num_flushes;
43630 + atomic_unchecked_t num_oplock_brks;
43631 + atomic_unchecked_t num_opens;
43632 + atomic_unchecked_t num_closes;
43633 + atomic_unchecked_t num_deletes;
43634 + atomic_unchecked_t num_mkdirs;
43635 + atomic_unchecked_t num_posixopens;
43636 + atomic_unchecked_t num_posixmkdirs;
43637 + atomic_unchecked_t num_rmdirs;
43638 + atomic_unchecked_t num_renames;
43639 + atomic_unchecked_t num_t2renames;
43640 + atomic_unchecked_t num_ffirst;
43641 + atomic_unchecked_t num_fnext;
43642 + atomic_unchecked_t num_fclose;
43643 + atomic_unchecked_t num_hardlinks;
43644 + atomic_unchecked_t num_symlinks;
43645 + atomic_unchecked_t num_locks;
43646 + atomic_unchecked_t num_acl_get;
43647 + atomic_unchecked_t num_acl_set;
43648 #ifdef CONFIG_CIFS_STATS2
43649 unsigned long long time_writes;
43650 unsigned long long time_reads;
43651 @@ -628,7 +628,7 @@ convert_delimiter(char *path, char delim)
43652 }
43653
43654 #ifdef CONFIG_CIFS_STATS
43655 -#define cifs_stats_inc atomic_inc
43656 +#define cifs_stats_inc atomic_inc_unchecked
43657
43658 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43659 unsigned int bytes)
43660 @@ -985,8 +985,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43661 /* Various Debug counters */
43662 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43663 #ifdef CONFIG_CIFS_STATS2
43664 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43665 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43666 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43667 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43668 #endif
43669 GLOBAL_EXTERN atomic_t smBufAllocCount;
43670 GLOBAL_EXTERN atomic_t midCount;
43671 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43672 index 6b0e064..94e6c3c 100644
43673 --- a/fs/cifs/link.c
43674 +++ b/fs/cifs/link.c
43675 @@ -600,7 +600,7 @@ symlink_exit:
43676
43677 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43678 {
43679 - char *p = nd_get_link(nd);
43680 + const char *p = nd_get_link(nd);
43681 if (!IS_ERR(p))
43682 kfree(p);
43683 }
43684 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43685 index 703ef5c..2a44ed5 100644
43686 --- a/fs/cifs/misc.c
43687 +++ b/fs/cifs/misc.c
43688 @@ -156,7 +156,7 @@ cifs_buf_get(void)
43689 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43690 atomic_inc(&bufAllocCount);
43691 #ifdef CONFIG_CIFS_STATS2
43692 - atomic_inc(&totBufAllocCount);
43693 + atomic_inc_unchecked(&totBufAllocCount);
43694 #endif /* CONFIG_CIFS_STATS2 */
43695 }
43696
43697 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43698 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43699 atomic_inc(&smBufAllocCount);
43700 #ifdef CONFIG_CIFS_STATS2
43701 - atomic_inc(&totSmBufAllocCount);
43702 + atomic_inc_unchecked(&totSmBufAllocCount);
43703 #endif /* CONFIG_CIFS_STATS2 */
43704
43705 }
43706 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43707 index 6901578..d402eb5 100644
43708 --- a/fs/coda/cache.c
43709 +++ b/fs/coda/cache.c
43710 @@ -24,7 +24,7 @@
43711 #include "coda_linux.h"
43712 #include "coda_cache.h"
43713
43714 -static atomic_t permission_epoch = ATOMIC_INIT(0);
43715 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43716
43717 /* replace or extend an acl cache hit */
43718 void coda_cache_enter(struct inode *inode, int mask)
43719 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43720 struct coda_inode_info *cii = ITOC(inode);
43721
43722 spin_lock(&cii->c_lock);
43723 - cii->c_cached_epoch = atomic_read(&permission_epoch);
43724 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43725 if (cii->c_uid != current_fsuid()) {
43726 cii->c_uid = current_fsuid();
43727 cii->c_cached_perm = mask;
43728 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43729 {
43730 struct coda_inode_info *cii = ITOC(inode);
43731 spin_lock(&cii->c_lock);
43732 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43733 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43734 spin_unlock(&cii->c_lock);
43735 }
43736
43737 /* remove all acl caches */
43738 void coda_cache_clear_all(struct super_block *sb)
43739 {
43740 - atomic_inc(&permission_epoch);
43741 + atomic_inc_unchecked(&permission_epoch);
43742 }
43743
43744
43745 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43746 spin_lock(&cii->c_lock);
43747 hit = (mask & cii->c_cached_perm) == mask &&
43748 cii->c_uid == current_fsuid() &&
43749 - cii->c_cached_epoch == atomic_read(&permission_epoch);
43750 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43751 spin_unlock(&cii->c_lock);
43752
43753 return hit;
43754 diff --git a/fs/compat.c b/fs/compat.c
43755 index c987875..08771ca 100644
43756 --- a/fs/compat.c
43757 +++ b/fs/compat.c
43758 @@ -132,8 +132,8 @@ asmlinkage long compat_sys_utimes(const char __user *filename, struct compat_tim
43759 static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
43760 {
43761 compat_ino_t ino = stat->ino;
43762 - typeof(ubuf->st_uid) uid = 0;
43763 - typeof(ubuf->st_gid) gid = 0;
43764 + typeof(((struct compat_stat *)0)->st_uid) uid = 0;
43765 + typeof(((struct compat_stat *)0)->st_gid) gid = 0;
43766 int err;
43767
43768 SET_UID(uid, stat->uid);
43769 @@ -504,7 +504,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43770
43771 set_fs(KERNEL_DS);
43772 /* The __user pointer cast is valid because of the set_fs() */
43773 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43774 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43775 set_fs(oldfs);
43776 /* truncating is ok because it's a user address */
43777 if (!ret)
43778 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43779 goto out;
43780
43781 ret = -EINVAL;
43782 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43783 + if (nr_segs > UIO_MAXIOV)
43784 goto out;
43785 if (nr_segs > fast_segs) {
43786 ret = -ENOMEM;
43787 @@ -845,6 +845,7 @@ struct compat_old_linux_dirent {
43788
43789 struct compat_readdir_callback {
43790 struct compat_old_linux_dirent __user *dirent;
43791 + struct file * file;
43792 int result;
43793 };
43794
43795 @@ -862,6 +863,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43796 buf->result = -EOVERFLOW;
43797 return -EOVERFLOW;
43798 }
43799 +
43800 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43801 + return 0;
43802 +
43803 buf->result++;
43804 dirent = buf->dirent;
43805 if (!access_ok(VERIFY_WRITE, dirent,
43806 @@ -894,6 +899,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43807
43808 buf.result = 0;
43809 buf.dirent = dirent;
43810 + buf.file = file;
43811
43812 error = vfs_readdir(file, compat_fillonedir, &buf);
43813 if (buf.result)
43814 @@ -914,6 +920,7 @@ struct compat_linux_dirent {
43815 struct compat_getdents_callback {
43816 struct compat_linux_dirent __user *current_dir;
43817 struct compat_linux_dirent __user *previous;
43818 + struct file * file;
43819 int count;
43820 int error;
43821 };
43822 @@ -935,6 +942,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43823 buf->error = -EOVERFLOW;
43824 return -EOVERFLOW;
43825 }
43826 +
43827 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43828 + return 0;
43829 +
43830 dirent = buf->previous;
43831 if (dirent) {
43832 if (__put_user(offset, &dirent->d_off))
43833 @@ -982,6 +993,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43834 buf.previous = NULL;
43835 buf.count = count;
43836 buf.error = 0;
43837 + buf.file = file;
43838
43839 error = vfs_readdir(file, compat_filldir, &buf);
43840 if (error >= 0)
43841 @@ -1003,6 +1015,7 @@ out:
43842 struct compat_getdents_callback64 {
43843 struct linux_dirent64 __user *current_dir;
43844 struct linux_dirent64 __user *previous;
43845 + struct file * file;
43846 int count;
43847 int error;
43848 };
43849 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43850 buf->error = -EINVAL; /* only used if we fail.. */
43851 if (reclen > buf->count)
43852 return -EINVAL;
43853 +
43854 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43855 + return 0;
43856 +
43857 dirent = buf->previous;
43858
43859 if (dirent) {
43860 @@ -1070,13 +1087,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43861 buf.previous = NULL;
43862 buf.count = count;
43863 buf.error = 0;
43864 + buf.file = file;
43865
43866 error = vfs_readdir(file, compat_filldir64, &buf);
43867 if (error >= 0)
43868 error = buf.error;
43869 lastdirent = buf.previous;
43870 if (lastdirent) {
43871 - typeof(lastdirent->d_off) d_off = file->f_pos;
43872 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43873 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43874 error = -EFAULT;
43875 else
43876 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43877 index 112e45a..b59845b 100644
43878 --- a/fs/compat_binfmt_elf.c
43879 +++ b/fs/compat_binfmt_elf.c
43880 @@ -30,11 +30,13 @@
43881 #undef elf_phdr
43882 #undef elf_shdr
43883 #undef elf_note
43884 +#undef elf_dyn
43885 #undef elf_addr_t
43886 #define elfhdr elf32_hdr
43887 #define elf_phdr elf32_phdr
43888 #define elf_shdr elf32_shdr
43889 #define elf_note elf32_note
43890 +#define elf_dyn Elf32_Dyn
43891 #define elf_addr_t Elf32_Addr
43892
43893 /*
43894 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43895 index 51352de..93292ff 100644
43896 --- a/fs/compat_ioctl.c
43897 +++ b/fs/compat_ioctl.c
43898 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43899
43900 err = get_user(palp, &up->palette);
43901 err |= get_user(length, &up->length);
43902 + if (err)
43903 + return -EFAULT;
43904
43905 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
43906 err = put_user(compat_ptr(palp), &up_native->palette);
43907 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
43908 return -EFAULT;
43909 if (__get_user(udata, &ss32->iomem_base))
43910 return -EFAULT;
43911 - ss.iomem_base = compat_ptr(udata);
43912 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
43913 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
43914 __get_user(ss.port_high, &ss32->port_high))
43915 return -EFAULT;
43916 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
43917 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
43918 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
43919 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
43920 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43921 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43922 return -EFAULT;
43923
43924 return ioctl_preallocate(file, p);
43925 @@ -1644,8 +1646,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
43926 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
43927 {
43928 unsigned int a, b;
43929 - a = *(unsigned int *)p;
43930 - b = *(unsigned int *)q;
43931 + a = *(const unsigned int *)p;
43932 + b = *(const unsigned int *)q;
43933 if (a > b)
43934 return 1;
43935 if (a < b)
43936 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
43937 index 9a37a9b..35792b6 100644
43938 --- a/fs/configfs/dir.c
43939 +++ b/fs/configfs/dir.c
43940 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43941 }
43942 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
43943 struct configfs_dirent *next;
43944 - const char * name;
43945 + const unsigned char * name;
43946 + char d_name[sizeof(next->s_dentry->d_iname)];
43947 int len;
43948 struct inode *inode = NULL;
43949
43950 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43951 continue;
43952
43953 name = configfs_get_name(next);
43954 - len = strlen(name);
43955 + if (next->s_dentry && name == next->s_dentry->d_iname) {
43956 + len = next->s_dentry->d_name.len;
43957 + memcpy(d_name, name, len);
43958 + name = d_name;
43959 + } else
43960 + len = strlen(name);
43961
43962 /*
43963 * We'll have a dentry and an inode for
43964 diff --git a/fs/dcache.c b/fs/dcache.c
43965 index f7908ae..920a680 100644
43966 --- a/fs/dcache.c
43967 +++ b/fs/dcache.c
43968 @@ -3042,7 +3042,7 @@ void __init vfs_caches_init(unsigned long mempages)
43969 mempages -= reserve;
43970
43971 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
43972 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
43973 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
43974
43975 dcache_init();
43976 inode_init();
43977 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
43978 index f3a257d..715ac0f 100644
43979 --- a/fs/debugfs/inode.c
43980 +++ b/fs/debugfs/inode.c
43981 @@ -261,7 +261,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
43982 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
43983 {
43984 return debugfs_create_file(name,
43985 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
43986 + S_IFDIR | S_IRWXU,
43987 +#else
43988 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
43989 +#endif
43990 parent, NULL, NULL);
43991 }
43992 EXPORT_SYMBOL_GPL(debugfs_create_dir);
43993 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
43994 index af11098..81e3bbe 100644
43995 --- a/fs/ecryptfs/inode.c
43996 +++ b/fs/ecryptfs/inode.c
43997 @@ -691,7 +691,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
43998 old_fs = get_fs();
43999 set_fs(get_ds());
44000 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44001 - (char __user *)lower_buf,
44002 + (char __force_user *)lower_buf,
44003 lower_bufsiz);
44004 set_fs(old_fs);
44005 if (rc < 0)
44006 @@ -737,7 +737,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
44007 }
44008 old_fs = get_fs();
44009 set_fs(get_ds());
44010 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
44011 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
44012 set_fs(old_fs);
44013 if (rc < 0) {
44014 kfree(buf);
44015 @@ -752,7 +752,7 @@ out:
44016 static void
44017 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44018 {
44019 - char *buf = nd_get_link(nd);
44020 + const char *buf = nd_get_link(nd);
44021 if (!IS_ERR(buf)) {
44022 /* Free the char* */
44023 kfree(buf);
44024 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44025 index 0dc5a3d..d3cdeea 100644
44026 --- a/fs/ecryptfs/miscdev.c
44027 +++ b/fs/ecryptfs/miscdev.c
44028 @@ -328,7 +328,7 @@ check_list:
44029 goto out_unlock_msg_ctx;
44030 i = 5;
44031 if (msg_ctx->msg) {
44032 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44033 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44034 goto out_unlock_msg_ctx;
44035 i += packet_length_size;
44036 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44037 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44038 index 608c1c3..7d040a8 100644
44039 --- a/fs/ecryptfs/read_write.c
44040 +++ b/fs/ecryptfs/read_write.c
44041 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44042 return -EIO;
44043 fs_save = get_fs();
44044 set_fs(get_ds());
44045 - rc = vfs_write(lower_file, data, size, &offset);
44046 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44047 set_fs(fs_save);
44048 mark_inode_dirty_sync(ecryptfs_inode);
44049 return rc;
44050 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44051 return -EIO;
44052 fs_save = get_fs();
44053 set_fs(get_ds());
44054 - rc = vfs_read(lower_file, data, size, &offset);
44055 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44056 set_fs(fs_save);
44057 return rc;
44058 }
44059 diff --git a/fs/exec.c b/fs/exec.c
44060 index 3625464..ff895b9 100644
44061 --- a/fs/exec.c
44062 +++ b/fs/exec.c
44063 @@ -55,12 +55,28 @@
44064 #include <linux/pipe_fs_i.h>
44065 #include <linux/oom.h>
44066 #include <linux/compat.h>
44067 +#include <linux/random.h>
44068 +#include <linux/seq_file.h>
44069 +
44070 +#ifdef CONFIG_PAX_REFCOUNT
44071 +#include <linux/kallsyms.h>
44072 +#include <linux/kdebug.h>
44073 +#endif
44074
44075 #include <asm/uaccess.h>
44076 #include <asm/mmu_context.h>
44077 #include <asm/tlb.h>
44078 #include "internal.h"
44079
44080 +#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
44081 +void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
44082 +#endif
44083 +
44084 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44085 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44086 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44087 +#endif
44088 +
44089 int core_uses_pid;
44090 char core_pattern[CORENAME_MAX_SIZE] = "core";
44091 unsigned int core_pipe_limit;
44092 @@ -70,7 +86,7 @@ struct core_name {
44093 char *corename;
44094 int used, size;
44095 };
44096 -static atomic_t call_count = ATOMIC_INIT(1);
44097 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44098
44099 /* The maximal length of core_pattern is also specified in sysctl.c */
44100
44101 @@ -188,18 +204,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44102 int write)
44103 {
44104 struct page *page;
44105 - int ret;
44106
44107 -#ifdef CONFIG_STACK_GROWSUP
44108 - if (write) {
44109 - ret = expand_downwards(bprm->vma, pos);
44110 - if (ret < 0)
44111 - return NULL;
44112 - }
44113 -#endif
44114 - ret = get_user_pages(current, bprm->mm, pos,
44115 - 1, write, 1, &page, NULL);
44116 - if (ret <= 0)
44117 + if (0 > expand_downwards(bprm->vma, pos))
44118 + return NULL;
44119 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44120 return NULL;
44121
44122 if (write) {
44123 @@ -215,6 +223,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44124 if (size <= ARG_MAX)
44125 return page;
44126
44127 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44128 + // only allow 512KB for argv+env on suid/sgid binaries
44129 + // to prevent easy ASLR exhaustion
44130 + if (((bprm->cred->euid != current_euid()) ||
44131 + (bprm->cred->egid != current_egid())) &&
44132 + (size > (512 * 1024))) {
44133 + put_page(page);
44134 + return NULL;
44135 + }
44136 +#endif
44137 +
44138 /*
44139 * Limit to 1/4-th the stack size for the argv+env strings.
44140 * This ensures that:
44141 @@ -274,6 +293,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44142 vma->vm_end = STACK_TOP_MAX;
44143 vma->vm_start = vma->vm_end - PAGE_SIZE;
44144 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44145 +
44146 +#ifdef CONFIG_PAX_SEGMEXEC
44147 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44148 +#endif
44149 +
44150 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44151 INIT_LIST_HEAD(&vma->anon_vma_chain);
44152
44153 @@ -288,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44154 mm->stack_vm = mm->total_vm = 1;
44155 up_write(&mm->mmap_sem);
44156 bprm->p = vma->vm_end - sizeof(void *);
44157 +
44158 +#ifdef CONFIG_PAX_RANDUSTACK
44159 + if (randomize_va_space)
44160 + bprm->p ^= random32() & ~PAGE_MASK;
44161 +#endif
44162 +
44163 return 0;
44164 err:
44165 up_write(&mm->mmap_sem);
44166 @@ -396,19 +426,7 @@ err:
44167 return err;
44168 }
44169
44170 -struct user_arg_ptr {
44171 -#ifdef CONFIG_COMPAT
44172 - bool is_compat;
44173 -#endif
44174 - union {
44175 - const char __user *const __user *native;
44176 -#ifdef CONFIG_COMPAT
44177 - compat_uptr_t __user *compat;
44178 -#endif
44179 - } ptr;
44180 -};
44181 -
44182 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44183 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44184 {
44185 const char __user *native;
44186
44187 @@ -417,14 +435,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44188 compat_uptr_t compat;
44189
44190 if (get_user(compat, argv.ptr.compat + nr))
44191 - return ERR_PTR(-EFAULT);
44192 + return (const char __force_user *)ERR_PTR(-EFAULT);
44193
44194 return compat_ptr(compat);
44195 }
44196 #endif
44197
44198 if (get_user(native, argv.ptr.native + nr))
44199 - return ERR_PTR(-EFAULT);
44200 + return (const char __force_user *)ERR_PTR(-EFAULT);
44201
44202 return native;
44203 }
44204 @@ -443,7 +461,7 @@ static int count(struct user_arg_ptr argv, int max)
44205 if (!p)
44206 break;
44207
44208 - if (IS_ERR(p))
44209 + if (IS_ERR((const char __force_kernel *)p))
44210 return -EFAULT;
44211
44212 if (i++ >= max)
44213 @@ -477,7 +495,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44214
44215 ret = -EFAULT;
44216 str = get_user_arg_ptr(argv, argc);
44217 - if (IS_ERR(str))
44218 + if (IS_ERR((const char __force_kernel *)str))
44219 goto out;
44220
44221 len = strnlen_user(str, MAX_ARG_STRLEN);
44222 @@ -559,7 +577,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44223 int r;
44224 mm_segment_t oldfs = get_fs();
44225 struct user_arg_ptr argv = {
44226 - .ptr.native = (const char __user *const __user *)__argv,
44227 + .ptr.native = (const char __force_user *const __force_user *)__argv,
44228 };
44229
44230 set_fs(KERNEL_DS);
44231 @@ -594,7 +612,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44232 unsigned long new_end = old_end - shift;
44233 struct mmu_gather tlb;
44234
44235 - BUG_ON(new_start > new_end);
44236 + if (new_start >= new_end || new_start < mmap_min_addr)
44237 + return -ENOMEM;
44238
44239 /*
44240 * ensure there are no vmas between where we want to go
44241 @@ -603,6 +622,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44242 if (vma != find_vma(mm, new_start))
44243 return -EFAULT;
44244
44245 +#ifdef CONFIG_PAX_SEGMEXEC
44246 + BUG_ON(pax_find_mirror_vma(vma));
44247 +#endif
44248 +
44249 /*
44250 * cover the whole range: [new_start, old_end)
44251 */
44252 @@ -683,10 +706,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44253 stack_top = arch_align_stack(stack_top);
44254 stack_top = PAGE_ALIGN(stack_top);
44255
44256 - if (unlikely(stack_top < mmap_min_addr) ||
44257 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44258 - return -ENOMEM;
44259 -
44260 stack_shift = vma->vm_end - stack_top;
44261
44262 bprm->p -= stack_shift;
44263 @@ -698,8 +717,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44264 bprm->exec -= stack_shift;
44265
44266 down_write(&mm->mmap_sem);
44267 +
44268 + /* Move stack pages down in memory. */
44269 + if (stack_shift) {
44270 + ret = shift_arg_pages(vma, stack_shift);
44271 + if (ret)
44272 + goto out_unlock;
44273 + }
44274 +
44275 vm_flags = VM_STACK_FLAGS;
44276
44277 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44278 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44279 + vm_flags &= ~VM_EXEC;
44280 +
44281 +#ifdef CONFIG_PAX_MPROTECT
44282 + if (mm->pax_flags & MF_PAX_MPROTECT)
44283 + vm_flags &= ~VM_MAYEXEC;
44284 +#endif
44285 +
44286 + }
44287 +#endif
44288 +
44289 /*
44290 * Adjust stack execute permissions; explicitly enable for
44291 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44292 @@ -718,13 +757,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44293 goto out_unlock;
44294 BUG_ON(prev != vma);
44295
44296 - /* Move stack pages down in memory. */
44297 - if (stack_shift) {
44298 - ret = shift_arg_pages(vma, stack_shift);
44299 - if (ret)
44300 - goto out_unlock;
44301 - }
44302 -
44303 /* mprotect_fixup is overkill to remove the temporary stack flags */
44304 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44305
44306 @@ -805,7 +837,7 @@ int kernel_read(struct file *file, loff_t offset,
44307 old_fs = get_fs();
44308 set_fs(get_ds());
44309 /* The cast to a user pointer is valid due to the set_fs() */
44310 - result = vfs_read(file, (void __user *)addr, count, &pos);
44311 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
44312 set_fs(old_fs);
44313 return result;
44314 }
44315 @@ -1067,6 +1099,21 @@ void set_task_comm(struct task_struct *tsk, char *buf)
44316 perf_event_comm(tsk);
44317 }
44318
44319 +static void filename_to_taskname(char *tcomm, const char *fn, unsigned int len)
44320 +{
44321 + int i, ch;
44322 +
44323 + /* Copies the binary name from after last slash */
44324 + for (i = 0; (ch = *(fn++)) != '\0';) {
44325 + if (ch == '/')
44326 + i = 0; /* overwrite what we wrote */
44327 + else
44328 + if (i < len - 1)
44329 + tcomm[i++] = ch;
44330 + }
44331 + tcomm[i] = '\0';
44332 +}
44333 +
44334 int flush_old_exec(struct linux_binprm * bprm)
44335 {
44336 int retval;
44337 @@ -1081,6 +1128,7 @@ int flush_old_exec(struct linux_binprm * bprm)
44338
44339 set_mm_exe_file(bprm->mm, bprm->file);
44340
44341 + filename_to_taskname(bprm->tcomm, bprm->filename, sizeof(bprm->tcomm));
44342 /*
44343 * Release all of the old mmap stuff
44344 */
44345 @@ -1112,10 +1160,6 @@ EXPORT_SYMBOL(would_dump);
44346
44347 void setup_new_exec(struct linux_binprm * bprm)
44348 {
44349 - int i, ch;
44350 - const char *name;
44351 - char tcomm[sizeof(current->comm)];
44352 -
44353 arch_pick_mmap_layout(current->mm);
44354
44355 /* This is the point of no return */
44356 @@ -1126,18 +1170,7 @@ void setup_new_exec(struct linux_binprm * bprm)
44357 else
44358 set_dumpable(current->mm, suid_dumpable);
44359
44360 - name = bprm->filename;
44361 -
44362 - /* Copies the binary name from after last slash */
44363 - for (i=0; (ch = *(name++)) != '\0';) {
44364 - if (ch == '/')
44365 - i = 0; /* overwrite what we wrote */
44366 - else
44367 - if (i < (sizeof(tcomm) - 1))
44368 - tcomm[i++] = ch;
44369 - }
44370 - tcomm[i] = '\0';
44371 - set_task_comm(current, tcomm);
44372 + set_task_comm(current, bprm->tcomm);
44373
44374 /* Set the new mm task size. We have to do that late because it may
44375 * depend on TIF_32BIT which is only updated in flush_thread() on
44376 @@ -1247,7 +1280,7 @@ int check_unsafe_exec(struct linux_binprm *bprm)
44377 }
44378 rcu_read_unlock();
44379
44380 - if (p->fs->users > n_fs) {
44381 + if (atomic_read(&p->fs->users) > n_fs) {
44382 bprm->unsafe |= LSM_UNSAFE_SHARE;
44383 } else {
44384 res = -EAGAIN;
44385 @@ -1442,6 +1475,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
44386
44387 EXPORT_SYMBOL(search_binary_handler);
44388
44389 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44390 +static DEFINE_PER_CPU(u64, exec_counter);
44391 +static int __init init_exec_counters(void)
44392 +{
44393 + unsigned int cpu;
44394 +
44395 + for_each_possible_cpu(cpu) {
44396 + per_cpu(exec_counter, cpu) = (u64)cpu;
44397 + }
44398 +
44399 + return 0;
44400 +}
44401 +early_initcall(init_exec_counters);
44402 +static inline void increment_exec_counter(void)
44403 +{
44404 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
44405 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
44406 +}
44407 +#else
44408 +static inline void increment_exec_counter(void) {}
44409 +#endif
44410 +
44411 /*
44412 * sys_execve() executes a new program.
44413 */
44414 @@ -1450,6 +1505,11 @@ static int do_execve_common(const char *filename,
44415 struct user_arg_ptr envp,
44416 struct pt_regs *regs)
44417 {
44418 +#ifdef CONFIG_GRKERNSEC
44419 + struct file *old_exec_file;
44420 + struct acl_subject_label *old_acl;
44421 + struct rlimit old_rlim[RLIM_NLIMITS];
44422 +#endif
44423 struct linux_binprm *bprm;
44424 struct file *file;
44425 struct files_struct *displaced;
44426 @@ -1457,6 +1517,8 @@ static int do_execve_common(const char *filename,
44427 int retval;
44428 const struct cred *cred = current_cred();
44429
44430 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44431 +
44432 /*
44433 * We move the actual failure in case of RLIMIT_NPROC excess from
44434 * set*uid() to execve() because too many poorly written programs
44435 @@ -1497,12 +1559,27 @@ static int do_execve_common(const char *filename,
44436 if (IS_ERR(file))
44437 goto out_unmark;
44438
44439 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
44440 + retval = -EPERM;
44441 + goto out_file;
44442 + }
44443 +
44444 sched_exec();
44445
44446 bprm->file = file;
44447 bprm->filename = filename;
44448 bprm->interp = filename;
44449
44450 + if (gr_process_user_ban()) {
44451 + retval = -EPERM;
44452 + goto out_file;
44453 + }
44454 +
44455 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44456 + retval = -EACCES;
44457 + goto out_file;
44458 + }
44459 +
44460 retval = bprm_mm_init(bprm);
44461 if (retval)
44462 goto out_file;
44463 @@ -1519,24 +1596,65 @@ static int do_execve_common(const char *filename,
44464 if (retval < 0)
44465 goto out;
44466
44467 +#ifdef CONFIG_GRKERNSEC
44468 + old_acl = current->acl;
44469 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44470 + old_exec_file = current->exec_file;
44471 + get_file(file);
44472 + current->exec_file = file;
44473 +#endif
44474 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44475 + /* limit suid stack to 8MB
44476 + we saved the old limits above and will restore them if this exec fails
44477 + */
44478 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44479 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44480 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44481 +#endif
44482 +
44483 + if (!gr_tpe_allow(file)) {
44484 + retval = -EACCES;
44485 + goto out_fail;
44486 + }
44487 +
44488 + if (gr_check_crash_exec(file)) {
44489 + retval = -EACCES;
44490 + goto out_fail;
44491 + }
44492 +
44493 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44494 + bprm->unsafe);
44495 + if (retval < 0)
44496 + goto out_fail;
44497 +
44498 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44499 if (retval < 0)
44500 - goto out;
44501 + goto out_fail;
44502
44503 bprm->exec = bprm->p;
44504 retval = copy_strings(bprm->envc, envp, bprm);
44505 if (retval < 0)
44506 - goto out;
44507 + goto out_fail;
44508
44509 retval = copy_strings(bprm->argc, argv, bprm);
44510 if (retval < 0)
44511 - goto out;
44512 + goto out_fail;
44513 +
44514 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44515 +
44516 + gr_handle_exec_args(bprm, argv);
44517
44518 retval = search_binary_handler(bprm,regs);
44519 if (retval < 0)
44520 - goto out;
44521 + goto out_fail;
44522 +#ifdef CONFIG_GRKERNSEC
44523 + if (old_exec_file)
44524 + fput(old_exec_file);
44525 +#endif
44526
44527 /* execve succeeded */
44528 +
44529 + increment_exec_counter();
44530 current->fs->in_exec = 0;
44531 current->in_execve = 0;
44532 acct_update_integrals(current);
44533 @@ -1545,6 +1663,14 @@ static int do_execve_common(const char *filename,
44534 put_files_struct(displaced);
44535 return retval;
44536
44537 +out_fail:
44538 +#ifdef CONFIG_GRKERNSEC
44539 + current->acl = old_acl;
44540 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44541 + fput(current->exec_file);
44542 + current->exec_file = old_exec_file;
44543 +#endif
44544 +
44545 out:
44546 if (bprm->mm) {
44547 acct_arg_size(bprm, 0);
44548 @@ -1618,7 +1744,7 @@ static int expand_corename(struct core_name *cn)
44549 {
44550 char *old_corename = cn->corename;
44551
44552 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44553 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44554 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44555
44556 if (!cn->corename) {
44557 @@ -1715,7 +1841,7 @@ static int format_corename(struct core_name *cn, long signr)
44558 int pid_in_pattern = 0;
44559 int err = 0;
44560
44561 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44562 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44563 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44564 cn->used = 0;
44565
44566 @@ -1812,6 +1938,228 @@ out:
44567 return ispipe;
44568 }
44569
44570 +int pax_check_flags(unsigned long *flags)
44571 +{
44572 + int retval = 0;
44573 +
44574 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44575 + if (*flags & MF_PAX_SEGMEXEC)
44576 + {
44577 + *flags &= ~MF_PAX_SEGMEXEC;
44578 + retval = -EINVAL;
44579 + }
44580 +#endif
44581 +
44582 + if ((*flags & MF_PAX_PAGEEXEC)
44583 +
44584 +#ifdef CONFIG_PAX_PAGEEXEC
44585 + && (*flags & MF_PAX_SEGMEXEC)
44586 +#endif
44587 +
44588 + )
44589 + {
44590 + *flags &= ~MF_PAX_PAGEEXEC;
44591 + retval = -EINVAL;
44592 + }
44593 +
44594 + if ((*flags & MF_PAX_MPROTECT)
44595 +
44596 +#ifdef CONFIG_PAX_MPROTECT
44597 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44598 +#endif
44599 +
44600 + )
44601 + {
44602 + *flags &= ~MF_PAX_MPROTECT;
44603 + retval = -EINVAL;
44604 + }
44605 +
44606 + if ((*flags & MF_PAX_EMUTRAMP)
44607 +
44608 +#ifdef CONFIG_PAX_EMUTRAMP
44609 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44610 +#endif
44611 +
44612 + )
44613 + {
44614 + *flags &= ~MF_PAX_EMUTRAMP;
44615 + retval = -EINVAL;
44616 + }
44617 +
44618 + return retval;
44619 +}
44620 +
44621 +EXPORT_SYMBOL(pax_check_flags);
44622 +
44623 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44624 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44625 +{
44626 + struct task_struct *tsk = current;
44627 + struct mm_struct *mm = current->mm;
44628 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44629 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44630 + char *path_exec = NULL;
44631 + char *path_fault = NULL;
44632 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
44633 +
44634 + if (buffer_exec && buffer_fault) {
44635 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44636 +
44637 + down_read(&mm->mmap_sem);
44638 + vma = mm->mmap;
44639 + while (vma && (!vma_exec || !vma_fault)) {
44640 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44641 + vma_exec = vma;
44642 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44643 + vma_fault = vma;
44644 + vma = vma->vm_next;
44645 + }
44646 + if (vma_exec) {
44647 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44648 + if (IS_ERR(path_exec))
44649 + path_exec = "<path too long>";
44650 + else {
44651 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44652 + if (path_exec) {
44653 + *path_exec = 0;
44654 + path_exec = buffer_exec;
44655 + } else
44656 + path_exec = "<path too long>";
44657 + }
44658 + }
44659 + if (vma_fault) {
44660 + start = vma_fault->vm_start;
44661 + end = vma_fault->vm_end;
44662 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44663 + if (vma_fault->vm_file) {
44664 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44665 + if (IS_ERR(path_fault))
44666 + path_fault = "<path too long>";
44667 + else {
44668 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44669 + if (path_fault) {
44670 + *path_fault = 0;
44671 + path_fault = buffer_fault;
44672 + } else
44673 + path_fault = "<path too long>";
44674 + }
44675 + } else
44676 + path_fault = "<anonymous mapping>";
44677 + }
44678 + up_read(&mm->mmap_sem);
44679 + }
44680 + if (tsk->signal->curr_ip)
44681 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44682 + else
44683 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44684 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44685 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44686 + task_uid(tsk), task_euid(tsk), pc, sp);
44687 + free_page((unsigned long)buffer_exec);
44688 + free_page((unsigned long)buffer_fault);
44689 + pax_report_insns(regs, pc, sp);
44690 + do_coredump(SIGKILL, SIGKILL, regs);
44691 +}
44692 +#endif
44693 +
44694 +#ifdef CONFIG_PAX_REFCOUNT
44695 +void pax_report_refcount_overflow(struct pt_regs *regs)
44696 +{
44697 + if (current->signal->curr_ip)
44698 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44699 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44700 + else
44701 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44702 + current->comm, task_pid_nr(current), current_uid(), current_euid());
44703 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44704 + show_regs(regs);
44705 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44706 +}
44707 +#endif
44708 +
44709 +#ifdef CONFIG_PAX_USERCOPY
44710 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44711 +int object_is_on_stack(const void *obj, unsigned long len)
44712 +{
44713 + const void * const stack = task_stack_page(current);
44714 + const void * const stackend = stack + THREAD_SIZE;
44715 +
44716 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44717 + const void *frame = NULL;
44718 + const void *oldframe;
44719 +#endif
44720 +
44721 + if (obj + len < obj)
44722 + return -1;
44723 +
44724 + if (obj + len <= stack || stackend <= obj)
44725 + return 0;
44726 +
44727 + if (obj < stack || stackend < obj + len)
44728 + return -1;
44729 +
44730 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44731 + oldframe = __builtin_frame_address(1);
44732 + if (oldframe)
44733 + frame = __builtin_frame_address(2);
44734 + /*
44735 + low ----------------------------------------------> high
44736 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
44737 + ^----------------^
44738 + allow copies only within here
44739 + */
44740 + while (stack <= frame && frame < stackend) {
44741 + /* if obj + len extends past the last frame, this
44742 + check won't pass and the next frame will be 0,
44743 + causing us to bail out and correctly report
44744 + the copy as invalid
44745 + */
44746 + if (obj + len <= frame)
44747 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44748 + oldframe = frame;
44749 + frame = *(const void * const *)frame;
44750 + }
44751 + return -1;
44752 +#else
44753 + return 1;
44754 +#endif
44755 +}
44756 +
44757 +__noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44758 +{
44759 + if (current->signal->curr_ip)
44760 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44761 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44762 + else
44763 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44764 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44765 + dump_stack();
44766 + gr_handle_kernel_exploit();
44767 + do_group_exit(SIGKILL);
44768 +}
44769 +#endif
44770 +
44771 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44772 +void pax_track_stack(void)
44773 +{
44774 + unsigned long sp = (unsigned long)&sp;
44775 + if (sp < current_thread_info()->lowest_stack &&
44776 + sp > (unsigned long)task_stack_page(current))
44777 + current_thread_info()->lowest_stack = sp;
44778 +}
44779 +EXPORT_SYMBOL(pax_track_stack);
44780 +#endif
44781 +
44782 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
44783 +void report_size_overflow(const char *file, unsigned int line, const char *func)
44784 +{
44785 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44786 + dump_stack();
44787 + do_group_exit(SIGKILL);
44788 +}
44789 +EXPORT_SYMBOL(report_size_overflow);
44790 +#endif
44791 +
44792 static int zap_process(struct task_struct *start, int exit_code)
44793 {
44794 struct task_struct *t;
44795 @@ -2023,17 +2371,17 @@ static void wait_for_dump_helpers(struct file *file)
44796 pipe = file->f_path.dentry->d_inode->i_pipe;
44797
44798 pipe_lock(pipe);
44799 - pipe->readers++;
44800 - pipe->writers--;
44801 + atomic_inc(&pipe->readers);
44802 + atomic_dec(&pipe->writers);
44803
44804 - while ((pipe->readers > 1) && (!signal_pending(current))) {
44805 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44806 wake_up_interruptible_sync(&pipe->wait);
44807 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44808 pipe_wait(pipe);
44809 }
44810
44811 - pipe->readers--;
44812 - pipe->writers++;
44813 + atomic_dec(&pipe->readers);
44814 + atomic_inc(&pipe->writers);
44815 pipe_unlock(pipe);
44816
44817 }
44818 @@ -2094,7 +2442,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44819 int retval = 0;
44820 int flag = 0;
44821 int ispipe;
44822 - static atomic_t core_dump_count = ATOMIC_INIT(0);
44823 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44824 struct coredump_params cprm = {
44825 .signr = signr,
44826 .regs = regs,
44827 @@ -2109,6 +2457,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44828
44829 audit_core_dumps(signr);
44830
44831 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44832 + gr_handle_brute_attach(current, cprm.mm_flags);
44833 +
44834 binfmt = mm->binfmt;
44835 if (!binfmt || !binfmt->core_dump)
44836 goto fail;
44837 @@ -2176,7 +2527,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44838 }
44839 cprm.limit = RLIM_INFINITY;
44840
44841 - dump_count = atomic_inc_return(&core_dump_count);
44842 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
44843 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44844 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44845 task_tgid_vnr(current), current->comm);
44846 @@ -2203,6 +2554,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44847 } else {
44848 struct inode *inode;
44849
44850 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44851 +
44852 if (cprm.limit < binfmt->min_coredump)
44853 goto fail_unlock;
44854
44855 @@ -2246,7 +2599,7 @@ close_fail:
44856 filp_close(cprm.file, NULL);
44857 fail_dropcount:
44858 if (ispipe)
44859 - atomic_dec(&core_dump_count);
44860 + atomic_dec_unchecked(&core_dump_count);
44861 fail_unlock:
44862 kfree(cn.corename);
44863 fail_corename:
44864 @@ -2265,7 +2618,7 @@ fail:
44865 */
44866 int dump_write(struct file *file, const void *addr, int nr)
44867 {
44868 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44869 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44870 }
44871 EXPORT_SYMBOL(dump_write);
44872
44873 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
44874 index a8cbe1b..fed04cb 100644
44875 --- a/fs/ext2/balloc.c
44876 +++ b/fs/ext2/balloc.c
44877 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
44878
44879 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44880 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44881 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44882 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
44883 sbi->s_resuid != current_fsuid() &&
44884 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44885 return 0;
44886 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
44887 index a203892..4e64db5 100644
44888 --- a/fs/ext3/balloc.c
44889 +++ b/fs/ext3/balloc.c
44890 @@ -1446,9 +1446,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
44891
44892 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44893 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44894 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44895 + if (free_blocks < root_blocks + 1 &&
44896 !use_reservation && sbi->s_resuid != current_fsuid() &&
44897 - (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44898 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
44899 + !capable_nolog(CAP_SYS_RESOURCE)) {
44900 return 0;
44901 }
44902 return 1;
44903 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
44904 index 12ccacd..a6035fce0 100644
44905 --- a/fs/ext4/balloc.c
44906 +++ b/fs/ext4/balloc.c
44907 @@ -436,8 +436,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
44908 /* Hm, nope. Are (enough) root reserved clusters available? */
44909 if (sbi->s_resuid == current_fsuid() ||
44910 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
44911 - capable(CAP_SYS_RESOURCE) ||
44912 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
44913 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
44914 + capable_nolog(CAP_SYS_RESOURCE)) {
44915
44916 if (free_clusters >= (nclusters + dirty_clusters))
44917 return 1;
44918 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
44919 index 5b0e26a..0aa002d 100644
44920 --- a/fs/ext4/ext4.h
44921 +++ b/fs/ext4/ext4.h
44922 @@ -1208,19 +1208,19 @@ struct ext4_sb_info {
44923 unsigned long s_mb_last_start;
44924
44925 /* stats for buddy allocator */
44926 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
44927 - atomic_t s_bal_success; /* we found long enough chunks */
44928 - atomic_t s_bal_allocated; /* in blocks */
44929 - atomic_t s_bal_ex_scanned; /* total extents scanned */
44930 - atomic_t s_bal_goals; /* goal hits */
44931 - atomic_t s_bal_breaks; /* too long searches */
44932 - atomic_t s_bal_2orders; /* 2^order hits */
44933 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
44934 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
44935 + atomic_unchecked_t s_bal_allocated; /* in blocks */
44936 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
44937 + atomic_unchecked_t s_bal_goals; /* goal hits */
44938 + atomic_unchecked_t s_bal_breaks; /* too long searches */
44939 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
44940 spinlock_t s_bal_lock;
44941 unsigned long s_mb_buddies_generated;
44942 unsigned long long s_mb_generation_time;
44943 - atomic_t s_mb_lost_chunks;
44944 - atomic_t s_mb_preallocated;
44945 - atomic_t s_mb_discarded;
44946 + atomic_unchecked_t s_mb_lost_chunks;
44947 + atomic_unchecked_t s_mb_preallocated;
44948 + atomic_unchecked_t s_mb_discarded;
44949 atomic_t s_lock_busy;
44950
44951 /* locality groups */
44952 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
44953 index e2d8be8..c7f0ce9 100644
44954 --- a/fs/ext4/mballoc.c
44955 +++ b/fs/ext4/mballoc.c
44956 @@ -1794,7 +1794,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
44957 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
44958
44959 if (EXT4_SB(sb)->s_mb_stats)
44960 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
44961 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
44962
44963 break;
44964 }
44965 @@ -2088,7 +2088,7 @@ repeat:
44966 ac->ac_status = AC_STATUS_CONTINUE;
44967 ac->ac_flags |= EXT4_MB_HINT_FIRST;
44968 cr = 3;
44969 - atomic_inc(&sbi->s_mb_lost_chunks);
44970 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
44971 goto repeat;
44972 }
44973 }
44974 @@ -2592,25 +2592,25 @@ int ext4_mb_release(struct super_block *sb)
44975 if (sbi->s_mb_stats) {
44976 ext4_msg(sb, KERN_INFO,
44977 "mballoc: %u blocks %u reqs (%u success)",
44978 - atomic_read(&sbi->s_bal_allocated),
44979 - atomic_read(&sbi->s_bal_reqs),
44980 - atomic_read(&sbi->s_bal_success));
44981 + atomic_read_unchecked(&sbi->s_bal_allocated),
44982 + atomic_read_unchecked(&sbi->s_bal_reqs),
44983 + atomic_read_unchecked(&sbi->s_bal_success));
44984 ext4_msg(sb, KERN_INFO,
44985 "mballoc: %u extents scanned, %u goal hits, "
44986 "%u 2^N hits, %u breaks, %u lost",
44987 - atomic_read(&sbi->s_bal_ex_scanned),
44988 - atomic_read(&sbi->s_bal_goals),
44989 - atomic_read(&sbi->s_bal_2orders),
44990 - atomic_read(&sbi->s_bal_breaks),
44991 - atomic_read(&sbi->s_mb_lost_chunks));
44992 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
44993 + atomic_read_unchecked(&sbi->s_bal_goals),
44994 + atomic_read_unchecked(&sbi->s_bal_2orders),
44995 + atomic_read_unchecked(&sbi->s_bal_breaks),
44996 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
44997 ext4_msg(sb, KERN_INFO,
44998 "mballoc: %lu generated and it took %Lu",
44999 sbi->s_mb_buddies_generated,
45000 sbi->s_mb_generation_time);
45001 ext4_msg(sb, KERN_INFO,
45002 "mballoc: %u preallocated, %u discarded",
45003 - atomic_read(&sbi->s_mb_preallocated),
45004 - atomic_read(&sbi->s_mb_discarded));
45005 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45006 + atomic_read_unchecked(&sbi->s_mb_discarded));
45007 }
45008
45009 free_percpu(sbi->s_locality_groups);
45010 @@ -3096,16 +3096,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45011 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45012
45013 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45014 - atomic_inc(&sbi->s_bal_reqs);
45015 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45016 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45017 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45018 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45019 - atomic_inc(&sbi->s_bal_success);
45020 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45021 + atomic_inc_unchecked(&sbi->s_bal_success);
45022 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45023 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45024 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45025 - atomic_inc(&sbi->s_bal_goals);
45026 + atomic_inc_unchecked(&sbi->s_bal_goals);
45027 if (ac->ac_found > sbi->s_mb_max_to_scan)
45028 - atomic_inc(&sbi->s_bal_breaks);
45029 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45030 }
45031
45032 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45033 @@ -3509,7 +3509,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45034 trace_ext4_mb_new_inode_pa(ac, pa);
45035
45036 ext4_mb_use_inode_pa(ac, pa);
45037 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45038 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45039
45040 ei = EXT4_I(ac->ac_inode);
45041 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45042 @@ -3569,7 +3569,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45043 trace_ext4_mb_new_group_pa(ac, pa);
45044
45045 ext4_mb_use_group_pa(ac, pa);
45046 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45047 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45048
45049 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45050 lg = ac->ac_lg;
45051 @@ -3658,7 +3658,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45052 * from the bitmap and continue.
45053 */
45054 }
45055 - atomic_add(free, &sbi->s_mb_discarded);
45056 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45057
45058 return err;
45059 }
45060 @@ -3676,7 +3676,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45061 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45062 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45063 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45064 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45065 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45066 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45067
45068 return 0;
45069 diff --git a/fs/fcntl.c b/fs/fcntl.c
45070 index 22764c7..86372c9 100644
45071 --- a/fs/fcntl.c
45072 +++ b/fs/fcntl.c
45073 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45074 if (err)
45075 return err;
45076
45077 + if (gr_handle_chroot_fowner(pid, type))
45078 + return -ENOENT;
45079 + if (gr_check_protected_task_fowner(pid, type))
45080 + return -EACCES;
45081 +
45082 f_modown(filp, pid, type, force);
45083 return 0;
45084 }
45085 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
45086
45087 static int f_setown_ex(struct file *filp, unsigned long arg)
45088 {
45089 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45090 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45091 struct f_owner_ex owner;
45092 struct pid *pid;
45093 int type;
45094 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45095
45096 static int f_getown_ex(struct file *filp, unsigned long arg)
45097 {
45098 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45099 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45100 struct f_owner_ex owner;
45101 int ret = 0;
45102
45103 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45104 switch (cmd) {
45105 case F_DUPFD:
45106 case F_DUPFD_CLOEXEC:
45107 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45108 if (arg >= rlimit(RLIMIT_NOFILE))
45109 break;
45110 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45111 diff --git a/fs/fifo.c b/fs/fifo.c
45112 index b1a524d..4ee270e 100644
45113 --- a/fs/fifo.c
45114 +++ b/fs/fifo.c
45115 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45116 */
45117 filp->f_op = &read_pipefifo_fops;
45118 pipe->r_counter++;
45119 - if (pipe->readers++ == 0)
45120 + if (atomic_inc_return(&pipe->readers) == 1)
45121 wake_up_partner(inode);
45122
45123 - if (!pipe->writers) {
45124 + if (!atomic_read(&pipe->writers)) {
45125 if ((filp->f_flags & O_NONBLOCK)) {
45126 /* suppress POLLHUP until we have
45127 * seen a writer */
45128 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45129 * errno=ENXIO when there is no process reading the FIFO.
45130 */
45131 ret = -ENXIO;
45132 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45133 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45134 goto err;
45135
45136 filp->f_op = &write_pipefifo_fops;
45137 pipe->w_counter++;
45138 - if (!pipe->writers++)
45139 + if (atomic_inc_return(&pipe->writers) == 1)
45140 wake_up_partner(inode);
45141
45142 - if (!pipe->readers) {
45143 + if (!atomic_read(&pipe->readers)) {
45144 wait_for_partner(inode, &pipe->r_counter);
45145 if (signal_pending(current))
45146 goto err_wr;
45147 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45148 */
45149 filp->f_op = &rdwr_pipefifo_fops;
45150
45151 - pipe->readers++;
45152 - pipe->writers++;
45153 + atomic_inc(&pipe->readers);
45154 + atomic_inc(&pipe->writers);
45155 pipe->r_counter++;
45156 pipe->w_counter++;
45157 - if (pipe->readers == 1 || pipe->writers == 1)
45158 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45159 wake_up_partner(inode);
45160 break;
45161
45162 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45163 return 0;
45164
45165 err_rd:
45166 - if (!--pipe->readers)
45167 + if (atomic_dec_and_test(&pipe->readers))
45168 wake_up_interruptible(&pipe->wait);
45169 ret = -ERESTARTSYS;
45170 goto err;
45171
45172 err_wr:
45173 - if (!--pipe->writers)
45174 + if (atomic_dec_and_test(&pipe->writers))
45175 wake_up_interruptible(&pipe->wait);
45176 ret = -ERESTARTSYS;
45177 goto err;
45178
45179 err:
45180 - if (!pipe->readers && !pipe->writers)
45181 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45182 free_pipe_info(inode);
45183
45184 err_nocleanup:
45185 diff --git a/fs/file.c b/fs/file.c
45186 index 4c6992d..104cdea 100644
45187 --- a/fs/file.c
45188 +++ b/fs/file.c
45189 @@ -15,6 +15,7 @@
45190 #include <linux/slab.h>
45191 #include <linux/vmalloc.h>
45192 #include <linux/file.h>
45193 +#include <linux/security.h>
45194 #include <linux/fdtable.h>
45195 #include <linux/bitops.h>
45196 #include <linux/interrupt.h>
45197 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
45198 * N.B. For clone tasks sharing a files structure, this test
45199 * will limit the total number of files that can be opened.
45200 */
45201 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45202 if (nr >= rlimit(RLIMIT_NOFILE))
45203 return -EMFILE;
45204
45205 diff --git a/fs/filesystems.c b/fs/filesystems.c
45206 index 0845f84..7b4ebef 100644
45207 --- a/fs/filesystems.c
45208 +++ b/fs/filesystems.c
45209 @@ -274,7 +274,12 @@ struct file_system_type *get_fs_type(const char *name)
45210 int len = dot ? dot - name : strlen(name);
45211
45212 fs = __get_fs_type(name, len);
45213 +
45214 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45215 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45216 +#else
45217 if (!fs && (request_module("%.*s", len, name) == 0))
45218 +#endif
45219 fs = __get_fs_type(name, len);
45220
45221 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45222 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45223 index 78b519c..a8b4979 100644
45224 --- a/fs/fs_struct.c
45225 +++ b/fs/fs_struct.c
45226 @@ -4,6 +4,7 @@
45227 #include <linux/path.h>
45228 #include <linux/slab.h>
45229 #include <linux/fs_struct.h>
45230 +#include <linux/grsecurity.h>
45231 #include "internal.h"
45232
45233 static inline void path_get_longterm(struct path *path)
45234 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45235 old_root = fs->root;
45236 fs->root = *path;
45237 path_get_longterm(path);
45238 + gr_set_chroot_entries(current, path);
45239 write_seqcount_end(&fs->seq);
45240 spin_unlock(&fs->lock);
45241 if (old_root.dentry)
45242 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45243 && fs->root.mnt == old_root->mnt) {
45244 path_get_longterm(new_root);
45245 fs->root = *new_root;
45246 + gr_set_chroot_entries(p, new_root);
45247 count++;
45248 }
45249 if (fs->pwd.dentry == old_root->dentry
45250 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
45251 spin_lock(&fs->lock);
45252 write_seqcount_begin(&fs->seq);
45253 tsk->fs = NULL;
45254 - kill = !--fs->users;
45255 + gr_clear_chroot_entries(tsk);
45256 + kill = !atomic_dec_return(&fs->users);
45257 write_seqcount_end(&fs->seq);
45258 spin_unlock(&fs->lock);
45259 task_unlock(tsk);
45260 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45261 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45262 /* We don't need to lock fs - think why ;-) */
45263 if (fs) {
45264 - fs->users = 1;
45265 + atomic_set(&fs->users, 1);
45266 fs->in_exec = 0;
45267 spin_lock_init(&fs->lock);
45268 seqcount_init(&fs->seq);
45269 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45270 spin_lock(&old->lock);
45271 fs->root = old->root;
45272 path_get_longterm(&fs->root);
45273 + /* instead of calling gr_set_chroot_entries here,
45274 + we call it from every caller of this function
45275 + */
45276 fs->pwd = old->pwd;
45277 path_get_longterm(&fs->pwd);
45278 spin_unlock(&old->lock);
45279 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
45280
45281 task_lock(current);
45282 spin_lock(&fs->lock);
45283 - kill = !--fs->users;
45284 + kill = !atomic_dec_return(&fs->users);
45285 current->fs = new_fs;
45286 + gr_set_chroot_entries(current, &new_fs->root);
45287 spin_unlock(&fs->lock);
45288 task_unlock(current);
45289
45290 @@ -164,13 +172,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45291
45292 int current_umask(void)
45293 {
45294 - return current->fs->umask;
45295 + return current->fs->umask | gr_acl_umask();
45296 }
45297 EXPORT_SYMBOL(current_umask);
45298
45299 /* to be mentioned only in INIT_TASK */
45300 struct fs_struct init_fs = {
45301 - .users = 1,
45302 + .users = ATOMIC_INIT(1),
45303 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45304 .seq = SEQCNT_ZERO,
45305 .umask = 0022,
45306 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
45307 task_lock(current);
45308
45309 spin_lock(&init_fs.lock);
45310 - init_fs.users++;
45311 + atomic_inc(&init_fs.users);
45312 spin_unlock(&init_fs.lock);
45313
45314 spin_lock(&fs->lock);
45315 current->fs = &init_fs;
45316 - kill = !--fs->users;
45317 + gr_set_chroot_entries(current, &current->fs->root);
45318 + kill = !atomic_dec_return(&fs->users);
45319 spin_unlock(&fs->lock);
45320
45321 task_unlock(current);
45322 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45323 index 9905350..02eaec4 100644
45324 --- a/fs/fscache/cookie.c
45325 +++ b/fs/fscache/cookie.c
45326 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45327 parent ? (char *) parent->def->name : "<no-parent>",
45328 def->name, netfs_data);
45329
45330 - fscache_stat(&fscache_n_acquires);
45331 + fscache_stat_unchecked(&fscache_n_acquires);
45332
45333 /* if there's no parent cookie, then we don't create one here either */
45334 if (!parent) {
45335 - fscache_stat(&fscache_n_acquires_null);
45336 + fscache_stat_unchecked(&fscache_n_acquires_null);
45337 _leave(" [no parent]");
45338 return NULL;
45339 }
45340 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45341 /* allocate and initialise a cookie */
45342 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45343 if (!cookie) {
45344 - fscache_stat(&fscache_n_acquires_oom);
45345 + fscache_stat_unchecked(&fscache_n_acquires_oom);
45346 _leave(" [ENOMEM]");
45347 return NULL;
45348 }
45349 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45350
45351 switch (cookie->def->type) {
45352 case FSCACHE_COOKIE_TYPE_INDEX:
45353 - fscache_stat(&fscache_n_cookie_index);
45354 + fscache_stat_unchecked(&fscache_n_cookie_index);
45355 break;
45356 case FSCACHE_COOKIE_TYPE_DATAFILE:
45357 - fscache_stat(&fscache_n_cookie_data);
45358 + fscache_stat_unchecked(&fscache_n_cookie_data);
45359 break;
45360 default:
45361 - fscache_stat(&fscache_n_cookie_special);
45362 + fscache_stat_unchecked(&fscache_n_cookie_special);
45363 break;
45364 }
45365
45366 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45367 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45368 atomic_dec(&parent->n_children);
45369 __fscache_cookie_put(cookie);
45370 - fscache_stat(&fscache_n_acquires_nobufs);
45371 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45372 _leave(" = NULL");
45373 return NULL;
45374 }
45375 }
45376
45377 - fscache_stat(&fscache_n_acquires_ok);
45378 + fscache_stat_unchecked(&fscache_n_acquires_ok);
45379 _leave(" = %p", cookie);
45380 return cookie;
45381 }
45382 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45383 cache = fscache_select_cache_for_object(cookie->parent);
45384 if (!cache) {
45385 up_read(&fscache_addremove_sem);
45386 - fscache_stat(&fscache_n_acquires_no_cache);
45387 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45388 _leave(" = -ENOMEDIUM [no cache]");
45389 return -ENOMEDIUM;
45390 }
45391 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45392 object = cache->ops->alloc_object(cache, cookie);
45393 fscache_stat_d(&fscache_n_cop_alloc_object);
45394 if (IS_ERR(object)) {
45395 - fscache_stat(&fscache_n_object_no_alloc);
45396 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
45397 ret = PTR_ERR(object);
45398 goto error;
45399 }
45400
45401 - fscache_stat(&fscache_n_object_alloc);
45402 + fscache_stat_unchecked(&fscache_n_object_alloc);
45403
45404 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45405
45406 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45407 struct fscache_object *object;
45408 struct hlist_node *_p;
45409
45410 - fscache_stat(&fscache_n_updates);
45411 + fscache_stat_unchecked(&fscache_n_updates);
45412
45413 if (!cookie) {
45414 - fscache_stat(&fscache_n_updates_null);
45415 + fscache_stat_unchecked(&fscache_n_updates_null);
45416 _leave(" [no cookie]");
45417 return;
45418 }
45419 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45420 struct fscache_object *object;
45421 unsigned long event;
45422
45423 - fscache_stat(&fscache_n_relinquishes);
45424 + fscache_stat_unchecked(&fscache_n_relinquishes);
45425 if (retire)
45426 - fscache_stat(&fscache_n_relinquishes_retire);
45427 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45428
45429 if (!cookie) {
45430 - fscache_stat(&fscache_n_relinquishes_null);
45431 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
45432 _leave(" [no cookie]");
45433 return;
45434 }
45435 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45436
45437 /* wait for the cookie to finish being instantiated (or to fail) */
45438 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45439 - fscache_stat(&fscache_n_relinquishes_waitcrt);
45440 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45441 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45442 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45443 }
45444 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45445 index f6aad48..88dcf26 100644
45446 --- a/fs/fscache/internal.h
45447 +++ b/fs/fscache/internal.h
45448 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45449 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45450 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45451
45452 -extern atomic_t fscache_n_op_pend;
45453 -extern atomic_t fscache_n_op_run;
45454 -extern atomic_t fscache_n_op_enqueue;
45455 -extern atomic_t fscache_n_op_deferred_release;
45456 -extern atomic_t fscache_n_op_release;
45457 -extern atomic_t fscache_n_op_gc;
45458 -extern atomic_t fscache_n_op_cancelled;
45459 -extern atomic_t fscache_n_op_rejected;
45460 +extern atomic_unchecked_t fscache_n_op_pend;
45461 +extern atomic_unchecked_t fscache_n_op_run;
45462 +extern atomic_unchecked_t fscache_n_op_enqueue;
45463 +extern atomic_unchecked_t fscache_n_op_deferred_release;
45464 +extern atomic_unchecked_t fscache_n_op_release;
45465 +extern atomic_unchecked_t fscache_n_op_gc;
45466 +extern atomic_unchecked_t fscache_n_op_cancelled;
45467 +extern atomic_unchecked_t fscache_n_op_rejected;
45468
45469 -extern atomic_t fscache_n_attr_changed;
45470 -extern atomic_t fscache_n_attr_changed_ok;
45471 -extern atomic_t fscache_n_attr_changed_nobufs;
45472 -extern atomic_t fscache_n_attr_changed_nomem;
45473 -extern atomic_t fscache_n_attr_changed_calls;
45474 +extern atomic_unchecked_t fscache_n_attr_changed;
45475 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
45476 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45477 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45478 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
45479
45480 -extern atomic_t fscache_n_allocs;
45481 -extern atomic_t fscache_n_allocs_ok;
45482 -extern atomic_t fscache_n_allocs_wait;
45483 -extern atomic_t fscache_n_allocs_nobufs;
45484 -extern atomic_t fscache_n_allocs_intr;
45485 -extern atomic_t fscache_n_allocs_object_dead;
45486 -extern atomic_t fscache_n_alloc_ops;
45487 -extern atomic_t fscache_n_alloc_op_waits;
45488 +extern atomic_unchecked_t fscache_n_allocs;
45489 +extern atomic_unchecked_t fscache_n_allocs_ok;
45490 +extern atomic_unchecked_t fscache_n_allocs_wait;
45491 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
45492 +extern atomic_unchecked_t fscache_n_allocs_intr;
45493 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
45494 +extern atomic_unchecked_t fscache_n_alloc_ops;
45495 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
45496
45497 -extern atomic_t fscache_n_retrievals;
45498 -extern atomic_t fscache_n_retrievals_ok;
45499 -extern atomic_t fscache_n_retrievals_wait;
45500 -extern atomic_t fscache_n_retrievals_nodata;
45501 -extern atomic_t fscache_n_retrievals_nobufs;
45502 -extern atomic_t fscache_n_retrievals_intr;
45503 -extern atomic_t fscache_n_retrievals_nomem;
45504 -extern atomic_t fscache_n_retrievals_object_dead;
45505 -extern atomic_t fscache_n_retrieval_ops;
45506 -extern atomic_t fscache_n_retrieval_op_waits;
45507 +extern atomic_unchecked_t fscache_n_retrievals;
45508 +extern atomic_unchecked_t fscache_n_retrievals_ok;
45509 +extern atomic_unchecked_t fscache_n_retrievals_wait;
45510 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
45511 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45512 +extern atomic_unchecked_t fscache_n_retrievals_intr;
45513 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
45514 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45515 +extern atomic_unchecked_t fscache_n_retrieval_ops;
45516 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45517
45518 -extern atomic_t fscache_n_stores;
45519 -extern atomic_t fscache_n_stores_ok;
45520 -extern atomic_t fscache_n_stores_again;
45521 -extern atomic_t fscache_n_stores_nobufs;
45522 -extern atomic_t fscache_n_stores_oom;
45523 -extern atomic_t fscache_n_store_ops;
45524 -extern atomic_t fscache_n_store_calls;
45525 -extern atomic_t fscache_n_store_pages;
45526 -extern atomic_t fscache_n_store_radix_deletes;
45527 -extern atomic_t fscache_n_store_pages_over_limit;
45528 +extern atomic_unchecked_t fscache_n_stores;
45529 +extern atomic_unchecked_t fscache_n_stores_ok;
45530 +extern atomic_unchecked_t fscache_n_stores_again;
45531 +extern atomic_unchecked_t fscache_n_stores_nobufs;
45532 +extern atomic_unchecked_t fscache_n_stores_oom;
45533 +extern atomic_unchecked_t fscache_n_store_ops;
45534 +extern atomic_unchecked_t fscache_n_store_calls;
45535 +extern atomic_unchecked_t fscache_n_store_pages;
45536 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
45537 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45538
45539 -extern atomic_t fscache_n_store_vmscan_not_storing;
45540 -extern atomic_t fscache_n_store_vmscan_gone;
45541 -extern atomic_t fscache_n_store_vmscan_busy;
45542 -extern atomic_t fscache_n_store_vmscan_cancelled;
45543 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45544 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45545 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45546 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45547
45548 -extern atomic_t fscache_n_marks;
45549 -extern atomic_t fscache_n_uncaches;
45550 +extern atomic_unchecked_t fscache_n_marks;
45551 +extern atomic_unchecked_t fscache_n_uncaches;
45552
45553 -extern atomic_t fscache_n_acquires;
45554 -extern atomic_t fscache_n_acquires_null;
45555 -extern atomic_t fscache_n_acquires_no_cache;
45556 -extern atomic_t fscache_n_acquires_ok;
45557 -extern atomic_t fscache_n_acquires_nobufs;
45558 -extern atomic_t fscache_n_acquires_oom;
45559 +extern atomic_unchecked_t fscache_n_acquires;
45560 +extern atomic_unchecked_t fscache_n_acquires_null;
45561 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
45562 +extern atomic_unchecked_t fscache_n_acquires_ok;
45563 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
45564 +extern atomic_unchecked_t fscache_n_acquires_oom;
45565
45566 -extern atomic_t fscache_n_updates;
45567 -extern atomic_t fscache_n_updates_null;
45568 -extern atomic_t fscache_n_updates_run;
45569 +extern atomic_unchecked_t fscache_n_updates;
45570 +extern atomic_unchecked_t fscache_n_updates_null;
45571 +extern atomic_unchecked_t fscache_n_updates_run;
45572
45573 -extern atomic_t fscache_n_relinquishes;
45574 -extern atomic_t fscache_n_relinquishes_null;
45575 -extern atomic_t fscache_n_relinquishes_waitcrt;
45576 -extern atomic_t fscache_n_relinquishes_retire;
45577 +extern atomic_unchecked_t fscache_n_relinquishes;
45578 +extern atomic_unchecked_t fscache_n_relinquishes_null;
45579 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45580 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
45581
45582 -extern atomic_t fscache_n_cookie_index;
45583 -extern atomic_t fscache_n_cookie_data;
45584 -extern atomic_t fscache_n_cookie_special;
45585 +extern atomic_unchecked_t fscache_n_cookie_index;
45586 +extern atomic_unchecked_t fscache_n_cookie_data;
45587 +extern atomic_unchecked_t fscache_n_cookie_special;
45588
45589 -extern atomic_t fscache_n_object_alloc;
45590 -extern atomic_t fscache_n_object_no_alloc;
45591 -extern atomic_t fscache_n_object_lookups;
45592 -extern atomic_t fscache_n_object_lookups_negative;
45593 -extern atomic_t fscache_n_object_lookups_positive;
45594 -extern atomic_t fscache_n_object_lookups_timed_out;
45595 -extern atomic_t fscache_n_object_created;
45596 -extern atomic_t fscache_n_object_avail;
45597 -extern atomic_t fscache_n_object_dead;
45598 +extern atomic_unchecked_t fscache_n_object_alloc;
45599 +extern atomic_unchecked_t fscache_n_object_no_alloc;
45600 +extern atomic_unchecked_t fscache_n_object_lookups;
45601 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
45602 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
45603 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45604 +extern atomic_unchecked_t fscache_n_object_created;
45605 +extern atomic_unchecked_t fscache_n_object_avail;
45606 +extern atomic_unchecked_t fscache_n_object_dead;
45607
45608 -extern atomic_t fscache_n_checkaux_none;
45609 -extern atomic_t fscache_n_checkaux_okay;
45610 -extern atomic_t fscache_n_checkaux_update;
45611 -extern atomic_t fscache_n_checkaux_obsolete;
45612 +extern atomic_unchecked_t fscache_n_checkaux_none;
45613 +extern atomic_unchecked_t fscache_n_checkaux_okay;
45614 +extern atomic_unchecked_t fscache_n_checkaux_update;
45615 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45616
45617 extern atomic_t fscache_n_cop_alloc_object;
45618 extern atomic_t fscache_n_cop_lookup_object;
45619 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45620 atomic_inc(stat);
45621 }
45622
45623 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45624 +{
45625 + atomic_inc_unchecked(stat);
45626 +}
45627 +
45628 static inline void fscache_stat_d(atomic_t *stat)
45629 {
45630 atomic_dec(stat);
45631 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45632
45633 #define __fscache_stat(stat) (NULL)
45634 #define fscache_stat(stat) do {} while (0)
45635 +#define fscache_stat_unchecked(stat) do {} while (0)
45636 #define fscache_stat_d(stat) do {} while (0)
45637 #endif
45638
45639 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45640 index b6b897c..0ffff9c 100644
45641 --- a/fs/fscache/object.c
45642 +++ b/fs/fscache/object.c
45643 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45644 /* update the object metadata on disk */
45645 case FSCACHE_OBJECT_UPDATING:
45646 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45647 - fscache_stat(&fscache_n_updates_run);
45648 + fscache_stat_unchecked(&fscache_n_updates_run);
45649 fscache_stat(&fscache_n_cop_update_object);
45650 object->cache->ops->update_object(object);
45651 fscache_stat_d(&fscache_n_cop_update_object);
45652 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45653 spin_lock(&object->lock);
45654 object->state = FSCACHE_OBJECT_DEAD;
45655 spin_unlock(&object->lock);
45656 - fscache_stat(&fscache_n_object_dead);
45657 + fscache_stat_unchecked(&fscache_n_object_dead);
45658 goto terminal_transit;
45659
45660 /* handle the parent cache of this object being withdrawn from
45661 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45662 spin_lock(&object->lock);
45663 object->state = FSCACHE_OBJECT_DEAD;
45664 spin_unlock(&object->lock);
45665 - fscache_stat(&fscache_n_object_dead);
45666 + fscache_stat_unchecked(&fscache_n_object_dead);
45667 goto terminal_transit;
45668
45669 /* complain about the object being woken up once it is
45670 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45671 parent->cookie->def->name, cookie->def->name,
45672 object->cache->tag->name);
45673
45674 - fscache_stat(&fscache_n_object_lookups);
45675 + fscache_stat_unchecked(&fscache_n_object_lookups);
45676 fscache_stat(&fscache_n_cop_lookup_object);
45677 ret = object->cache->ops->lookup_object(object);
45678 fscache_stat_d(&fscache_n_cop_lookup_object);
45679 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45680 if (ret == -ETIMEDOUT) {
45681 /* probably stuck behind another object, so move this one to
45682 * the back of the queue */
45683 - fscache_stat(&fscache_n_object_lookups_timed_out);
45684 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45685 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45686 }
45687
45688 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45689
45690 spin_lock(&object->lock);
45691 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45692 - fscache_stat(&fscache_n_object_lookups_negative);
45693 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45694
45695 /* transit here to allow write requests to begin stacking up
45696 * and read requests to begin returning ENODATA */
45697 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45698 * result, in which case there may be data available */
45699 spin_lock(&object->lock);
45700 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45701 - fscache_stat(&fscache_n_object_lookups_positive);
45702 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45703
45704 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45705
45706 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45707 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45708 } else {
45709 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45710 - fscache_stat(&fscache_n_object_created);
45711 + fscache_stat_unchecked(&fscache_n_object_created);
45712
45713 object->state = FSCACHE_OBJECT_AVAILABLE;
45714 spin_unlock(&object->lock);
45715 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45716 fscache_enqueue_dependents(object);
45717
45718 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45719 - fscache_stat(&fscache_n_object_avail);
45720 + fscache_stat_unchecked(&fscache_n_object_avail);
45721
45722 _leave("");
45723 }
45724 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45725 enum fscache_checkaux result;
45726
45727 if (!object->cookie->def->check_aux) {
45728 - fscache_stat(&fscache_n_checkaux_none);
45729 + fscache_stat_unchecked(&fscache_n_checkaux_none);
45730 return FSCACHE_CHECKAUX_OKAY;
45731 }
45732
45733 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45734 switch (result) {
45735 /* entry okay as is */
45736 case FSCACHE_CHECKAUX_OKAY:
45737 - fscache_stat(&fscache_n_checkaux_okay);
45738 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
45739 break;
45740
45741 /* entry requires update */
45742 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45743 - fscache_stat(&fscache_n_checkaux_update);
45744 + fscache_stat_unchecked(&fscache_n_checkaux_update);
45745 break;
45746
45747 /* entry requires deletion */
45748 case FSCACHE_CHECKAUX_OBSOLETE:
45749 - fscache_stat(&fscache_n_checkaux_obsolete);
45750 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45751 break;
45752
45753 default:
45754 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45755 index 30afdfa..2256596 100644
45756 --- a/fs/fscache/operation.c
45757 +++ b/fs/fscache/operation.c
45758 @@ -17,7 +17,7 @@
45759 #include <linux/slab.h>
45760 #include "internal.h"
45761
45762 -atomic_t fscache_op_debug_id;
45763 +atomic_unchecked_t fscache_op_debug_id;
45764 EXPORT_SYMBOL(fscache_op_debug_id);
45765
45766 /**
45767 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45768 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45769 ASSERTCMP(atomic_read(&op->usage), >, 0);
45770
45771 - fscache_stat(&fscache_n_op_enqueue);
45772 + fscache_stat_unchecked(&fscache_n_op_enqueue);
45773 switch (op->flags & FSCACHE_OP_TYPE) {
45774 case FSCACHE_OP_ASYNC:
45775 _debug("queue async");
45776 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45777 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45778 if (op->processor)
45779 fscache_enqueue_operation(op);
45780 - fscache_stat(&fscache_n_op_run);
45781 + fscache_stat_unchecked(&fscache_n_op_run);
45782 }
45783
45784 /*
45785 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45786 if (object->n_ops > 1) {
45787 atomic_inc(&op->usage);
45788 list_add_tail(&op->pend_link, &object->pending_ops);
45789 - fscache_stat(&fscache_n_op_pend);
45790 + fscache_stat_unchecked(&fscache_n_op_pend);
45791 } else if (!list_empty(&object->pending_ops)) {
45792 atomic_inc(&op->usage);
45793 list_add_tail(&op->pend_link, &object->pending_ops);
45794 - fscache_stat(&fscache_n_op_pend);
45795 + fscache_stat_unchecked(&fscache_n_op_pend);
45796 fscache_start_operations(object);
45797 } else {
45798 ASSERTCMP(object->n_in_progress, ==, 0);
45799 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45800 object->n_exclusive++; /* reads and writes must wait */
45801 atomic_inc(&op->usage);
45802 list_add_tail(&op->pend_link, &object->pending_ops);
45803 - fscache_stat(&fscache_n_op_pend);
45804 + fscache_stat_unchecked(&fscache_n_op_pend);
45805 ret = 0;
45806 } else {
45807 /* not allowed to submit ops in any other state */
45808 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45809 if (object->n_exclusive > 0) {
45810 atomic_inc(&op->usage);
45811 list_add_tail(&op->pend_link, &object->pending_ops);
45812 - fscache_stat(&fscache_n_op_pend);
45813 + fscache_stat_unchecked(&fscache_n_op_pend);
45814 } else if (!list_empty(&object->pending_ops)) {
45815 atomic_inc(&op->usage);
45816 list_add_tail(&op->pend_link, &object->pending_ops);
45817 - fscache_stat(&fscache_n_op_pend);
45818 + fscache_stat_unchecked(&fscache_n_op_pend);
45819 fscache_start_operations(object);
45820 } else {
45821 ASSERTCMP(object->n_exclusive, ==, 0);
45822 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45823 object->n_ops++;
45824 atomic_inc(&op->usage);
45825 list_add_tail(&op->pend_link, &object->pending_ops);
45826 - fscache_stat(&fscache_n_op_pend);
45827 + fscache_stat_unchecked(&fscache_n_op_pend);
45828 ret = 0;
45829 } else if (object->state == FSCACHE_OBJECT_DYING ||
45830 object->state == FSCACHE_OBJECT_LC_DYING ||
45831 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45832 - fscache_stat(&fscache_n_op_rejected);
45833 + fscache_stat_unchecked(&fscache_n_op_rejected);
45834 ret = -ENOBUFS;
45835 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45836 fscache_report_unexpected_submission(object, op, ostate);
45837 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45838
45839 ret = -EBUSY;
45840 if (!list_empty(&op->pend_link)) {
45841 - fscache_stat(&fscache_n_op_cancelled);
45842 + fscache_stat_unchecked(&fscache_n_op_cancelled);
45843 list_del_init(&op->pend_link);
45844 object->n_ops--;
45845 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45846 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45847 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
45848 BUG();
45849
45850 - fscache_stat(&fscache_n_op_release);
45851 + fscache_stat_unchecked(&fscache_n_op_release);
45852
45853 if (op->release) {
45854 op->release(op);
45855 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
45856 * lock, and defer it otherwise */
45857 if (!spin_trylock(&object->lock)) {
45858 _debug("defer put");
45859 - fscache_stat(&fscache_n_op_deferred_release);
45860 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
45861
45862 cache = object->cache;
45863 spin_lock(&cache->op_gc_list_lock);
45864 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
45865
45866 _debug("GC DEFERRED REL OBJ%x OP%x",
45867 object->debug_id, op->debug_id);
45868 - fscache_stat(&fscache_n_op_gc);
45869 + fscache_stat_unchecked(&fscache_n_op_gc);
45870
45871 ASSERTCMP(atomic_read(&op->usage), ==, 0);
45872
45873 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
45874 index 3f7a59b..cf196cc 100644
45875 --- a/fs/fscache/page.c
45876 +++ b/fs/fscache/page.c
45877 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45878 val = radix_tree_lookup(&cookie->stores, page->index);
45879 if (!val) {
45880 rcu_read_unlock();
45881 - fscache_stat(&fscache_n_store_vmscan_not_storing);
45882 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
45883 __fscache_uncache_page(cookie, page);
45884 return true;
45885 }
45886 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45887 spin_unlock(&cookie->stores_lock);
45888
45889 if (xpage) {
45890 - fscache_stat(&fscache_n_store_vmscan_cancelled);
45891 - fscache_stat(&fscache_n_store_radix_deletes);
45892 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
45893 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45894 ASSERTCMP(xpage, ==, page);
45895 } else {
45896 - fscache_stat(&fscache_n_store_vmscan_gone);
45897 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
45898 }
45899
45900 wake_up_bit(&cookie->flags, 0);
45901 @@ -107,7 +107,7 @@ page_busy:
45902 /* we might want to wait here, but that could deadlock the allocator as
45903 * the work threads writing to the cache may all end up sleeping
45904 * on memory allocation */
45905 - fscache_stat(&fscache_n_store_vmscan_busy);
45906 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
45907 return false;
45908 }
45909 EXPORT_SYMBOL(__fscache_maybe_release_page);
45910 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
45911 FSCACHE_COOKIE_STORING_TAG);
45912 if (!radix_tree_tag_get(&cookie->stores, page->index,
45913 FSCACHE_COOKIE_PENDING_TAG)) {
45914 - fscache_stat(&fscache_n_store_radix_deletes);
45915 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45916 xpage = radix_tree_delete(&cookie->stores, page->index);
45917 }
45918 spin_unlock(&cookie->stores_lock);
45919 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
45920
45921 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
45922
45923 - fscache_stat(&fscache_n_attr_changed_calls);
45924 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
45925
45926 if (fscache_object_is_active(object)) {
45927 fscache_stat(&fscache_n_cop_attr_changed);
45928 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45929
45930 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45931
45932 - fscache_stat(&fscache_n_attr_changed);
45933 + fscache_stat_unchecked(&fscache_n_attr_changed);
45934
45935 op = kzalloc(sizeof(*op), GFP_KERNEL);
45936 if (!op) {
45937 - fscache_stat(&fscache_n_attr_changed_nomem);
45938 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
45939 _leave(" = -ENOMEM");
45940 return -ENOMEM;
45941 }
45942 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45943 if (fscache_submit_exclusive_op(object, op) < 0)
45944 goto nobufs;
45945 spin_unlock(&cookie->lock);
45946 - fscache_stat(&fscache_n_attr_changed_ok);
45947 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
45948 fscache_put_operation(op);
45949 _leave(" = 0");
45950 return 0;
45951 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45952 nobufs:
45953 spin_unlock(&cookie->lock);
45954 kfree(op);
45955 - fscache_stat(&fscache_n_attr_changed_nobufs);
45956 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
45957 _leave(" = %d", -ENOBUFS);
45958 return -ENOBUFS;
45959 }
45960 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
45961 /* allocate a retrieval operation and attempt to submit it */
45962 op = kzalloc(sizeof(*op), GFP_NOIO);
45963 if (!op) {
45964 - fscache_stat(&fscache_n_retrievals_nomem);
45965 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45966 return NULL;
45967 }
45968
45969 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45970 return 0;
45971 }
45972
45973 - fscache_stat(&fscache_n_retrievals_wait);
45974 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
45975
45976 jif = jiffies;
45977 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
45978 fscache_wait_bit_interruptible,
45979 TASK_INTERRUPTIBLE) != 0) {
45980 - fscache_stat(&fscache_n_retrievals_intr);
45981 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45982 _leave(" = -ERESTARTSYS");
45983 return -ERESTARTSYS;
45984 }
45985 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45986 */
45987 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45988 struct fscache_retrieval *op,
45989 - atomic_t *stat_op_waits,
45990 - atomic_t *stat_object_dead)
45991 + atomic_unchecked_t *stat_op_waits,
45992 + atomic_unchecked_t *stat_object_dead)
45993 {
45994 int ret;
45995
45996 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45997 goto check_if_dead;
45998
45999 _debug(">>> WT");
46000 - fscache_stat(stat_op_waits);
46001 + fscache_stat_unchecked(stat_op_waits);
46002 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46003 fscache_wait_bit_interruptible,
46004 TASK_INTERRUPTIBLE) < 0) {
46005 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46006
46007 check_if_dead:
46008 if (unlikely(fscache_object_is_dead(object))) {
46009 - fscache_stat(stat_object_dead);
46010 + fscache_stat_unchecked(stat_object_dead);
46011 return -ENOBUFS;
46012 }
46013 return 0;
46014 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46015
46016 _enter("%p,%p,,,", cookie, page);
46017
46018 - fscache_stat(&fscache_n_retrievals);
46019 + fscache_stat_unchecked(&fscache_n_retrievals);
46020
46021 if (hlist_empty(&cookie->backing_objects))
46022 goto nobufs;
46023 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46024 goto nobufs_unlock;
46025 spin_unlock(&cookie->lock);
46026
46027 - fscache_stat(&fscache_n_retrieval_ops);
46028 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46029
46030 /* pin the netfs read context in case we need to do the actual netfs
46031 * read because we've encountered a cache read failure */
46032 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46033
46034 error:
46035 if (ret == -ENOMEM)
46036 - fscache_stat(&fscache_n_retrievals_nomem);
46037 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46038 else if (ret == -ERESTARTSYS)
46039 - fscache_stat(&fscache_n_retrievals_intr);
46040 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46041 else if (ret == -ENODATA)
46042 - fscache_stat(&fscache_n_retrievals_nodata);
46043 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46044 else if (ret < 0)
46045 - fscache_stat(&fscache_n_retrievals_nobufs);
46046 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46047 else
46048 - fscache_stat(&fscache_n_retrievals_ok);
46049 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46050
46051 fscache_put_retrieval(op);
46052 _leave(" = %d", ret);
46053 @@ -429,7 +429,7 @@ nobufs_unlock:
46054 spin_unlock(&cookie->lock);
46055 kfree(op);
46056 nobufs:
46057 - fscache_stat(&fscache_n_retrievals_nobufs);
46058 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46059 _leave(" = -ENOBUFS");
46060 return -ENOBUFS;
46061 }
46062 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46063
46064 _enter("%p,,%d,,,", cookie, *nr_pages);
46065
46066 - fscache_stat(&fscache_n_retrievals);
46067 + fscache_stat_unchecked(&fscache_n_retrievals);
46068
46069 if (hlist_empty(&cookie->backing_objects))
46070 goto nobufs;
46071 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46072 goto nobufs_unlock;
46073 spin_unlock(&cookie->lock);
46074
46075 - fscache_stat(&fscache_n_retrieval_ops);
46076 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46077
46078 /* pin the netfs read context in case we need to do the actual netfs
46079 * read because we've encountered a cache read failure */
46080 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46081
46082 error:
46083 if (ret == -ENOMEM)
46084 - fscache_stat(&fscache_n_retrievals_nomem);
46085 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46086 else if (ret == -ERESTARTSYS)
46087 - fscache_stat(&fscache_n_retrievals_intr);
46088 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46089 else if (ret == -ENODATA)
46090 - fscache_stat(&fscache_n_retrievals_nodata);
46091 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46092 else if (ret < 0)
46093 - fscache_stat(&fscache_n_retrievals_nobufs);
46094 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46095 else
46096 - fscache_stat(&fscache_n_retrievals_ok);
46097 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46098
46099 fscache_put_retrieval(op);
46100 _leave(" = %d", ret);
46101 @@ -545,7 +545,7 @@ nobufs_unlock:
46102 spin_unlock(&cookie->lock);
46103 kfree(op);
46104 nobufs:
46105 - fscache_stat(&fscache_n_retrievals_nobufs);
46106 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46107 _leave(" = -ENOBUFS");
46108 return -ENOBUFS;
46109 }
46110 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46111
46112 _enter("%p,%p,,,", cookie, page);
46113
46114 - fscache_stat(&fscache_n_allocs);
46115 + fscache_stat_unchecked(&fscache_n_allocs);
46116
46117 if (hlist_empty(&cookie->backing_objects))
46118 goto nobufs;
46119 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46120 goto nobufs_unlock;
46121 spin_unlock(&cookie->lock);
46122
46123 - fscache_stat(&fscache_n_alloc_ops);
46124 + fscache_stat_unchecked(&fscache_n_alloc_ops);
46125
46126 ret = fscache_wait_for_retrieval_activation(
46127 object, op,
46128 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46129
46130 error:
46131 if (ret == -ERESTARTSYS)
46132 - fscache_stat(&fscache_n_allocs_intr);
46133 + fscache_stat_unchecked(&fscache_n_allocs_intr);
46134 else if (ret < 0)
46135 - fscache_stat(&fscache_n_allocs_nobufs);
46136 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46137 else
46138 - fscache_stat(&fscache_n_allocs_ok);
46139 + fscache_stat_unchecked(&fscache_n_allocs_ok);
46140
46141 fscache_put_retrieval(op);
46142 _leave(" = %d", ret);
46143 @@ -625,7 +625,7 @@ nobufs_unlock:
46144 spin_unlock(&cookie->lock);
46145 kfree(op);
46146 nobufs:
46147 - fscache_stat(&fscache_n_allocs_nobufs);
46148 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46149 _leave(" = -ENOBUFS");
46150 return -ENOBUFS;
46151 }
46152 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46153
46154 spin_lock(&cookie->stores_lock);
46155
46156 - fscache_stat(&fscache_n_store_calls);
46157 + fscache_stat_unchecked(&fscache_n_store_calls);
46158
46159 /* find a page to store */
46160 page = NULL;
46161 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46162 page = results[0];
46163 _debug("gang %d [%lx]", n, page->index);
46164 if (page->index > op->store_limit) {
46165 - fscache_stat(&fscache_n_store_pages_over_limit);
46166 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46167 goto superseded;
46168 }
46169
46170 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46171 spin_unlock(&cookie->stores_lock);
46172 spin_unlock(&object->lock);
46173
46174 - fscache_stat(&fscache_n_store_pages);
46175 + fscache_stat_unchecked(&fscache_n_store_pages);
46176 fscache_stat(&fscache_n_cop_write_page);
46177 ret = object->cache->ops->write_page(op, page);
46178 fscache_stat_d(&fscache_n_cop_write_page);
46179 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46180 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46181 ASSERT(PageFsCache(page));
46182
46183 - fscache_stat(&fscache_n_stores);
46184 + fscache_stat_unchecked(&fscache_n_stores);
46185
46186 op = kzalloc(sizeof(*op), GFP_NOIO);
46187 if (!op)
46188 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46189 spin_unlock(&cookie->stores_lock);
46190 spin_unlock(&object->lock);
46191
46192 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46193 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46194 op->store_limit = object->store_limit;
46195
46196 if (fscache_submit_op(object, &op->op) < 0)
46197 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46198
46199 spin_unlock(&cookie->lock);
46200 radix_tree_preload_end();
46201 - fscache_stat(&fscache_n_store_ops);
46202 - fscache_stat(&fscache_n_stores_ok);
46203 + fscache_stat_unchecked(&fscache_n_store_ops);
46204 + fscache_stat_unchecked(&fscache_n_stores_ok);
46205
46206 /* the work queue now carries its own ref on the object */
46207 fscache_put_operation(&op->op);
46208 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46209 return 0;
46210
46211 already_queued:
46212 - fscache_stat(&fscache_n_stores_again);
46213 + fscache_stat_unchecked(&fscache_n_stores_again);
46214 already_pending:
46215 spin_unlock(&cookie->stores_lock);
46216 spin_unlock(&object->lock);
46217 spin_unlock(&cookie->lock);
46218 radix_tree_preload_end();
46219 kfree(op);
46220 - fscache_stat(&fscache_n_stores_ok);
46221 + fscache_stat_unchecked(&fscache_n_stores_ok);
46222 _leave(" = 0");
46223 return 0;
46224
46225 @@ -851,14 +851,14 @@ nobufs:
46226 spin_unlock(&cookie->lock);
46227 radix_tree_preload_end();
46228 kfree(op);
46229 - fscache_stat(&fscache_n_stores_nobufs);
46230 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46231 _leave(" = -ENOBUFS");
46232 return -ENOBUFS;
46233
46234 nomem_free:
46235 kfree(op);
46236 nomem:
46237 - fscache_stat(&fscache_n_stores_oom);
46238 + fscache_stat_unchecked(&fscache_n_stores_oom);
46239 _leave(" = -ENOMEM");
46240 return -ENOMEM;
46241 }
46242 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46243 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46244 ASSERTCMP(page, !=, NULL);
46245
46246 - fscache_stat(&fscache_n_uncaches);
46247 + fscache_stat_unchecked(&fscache_n_uncaches);
46248
46249 /* cache withdrawal may beat us to it */
46250 if (!PageFsCache(page))
46251 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46252 unsigned long loop;
46253
46254 #ifdef CONFIG_FSCACHE_STATS
46255 - atomic_add(pagevec->nr, &fscache_n_marks);
46256 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46257 #endif
46258
46259 for (loop = 0; loop < pagevec->nr; loop++) {
46260 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46261 index 4765190..2a067f2 100644
46262 --- a/fs/fscache/stats.c
46263 +++ b/fs/fscache/stats.c
46264 @@ -18,95 +18,95 @@
46265 /*
46266 * operation counters
46267 */
46268 -atomic_t fscache_n_op_pend;
46269 -atomic_t fscache_n_op_run;
46270 -atomic_t fscache_n_op_enqueue;
46271 -atomic_t fscache_n_op_requeue;
46272 -atomic_t fscache_n_op_deferred_release;
46273 -atomic_t fscache_n_op_release;
46274 -atomic_t fscache_n_op_gc;
46275 -atomic_t fscache_n_op_cancelled;
46276 -atomic_t fscache_n_op_rejected;
46277 +atomic_unchecked_t fscache_n_op_pend;
46278 +atomic_unchecked_t fscache_n_op_run;
46279 +atomic_unchecked_t fscache_n_op_enqueue;
46280 +atomic_unchecked_t fscache_n_op_requeue;
46281 +atomic_unchecked_t fscache_n_op_deferred_release;
46282 +atomic_unchecked_t fscache_n_op_release;
46283 +atomic_unchecked_t fscache_n_op_gc;
46284 +atomic_unchecked_t fscache_n_op_cancelled;
46285 +atomic_unchecked_t fscache_n_op_rejected;
46286
46287 -atomic_t fscache_n_attr_changed;
46288 -atomic_t fscache_n_attr_changed_ok;
46289 -atomic_t fscache_n_attr_changed_nobufs;
46290 -atomic_t fscache_n_attr_changed_nomem;
46291 -atomic_t fscache_n_attr_changed_calls;
46292 +atomic_unchecked_t fscache_n_attr_changed;
46293 +atomic_unchecked_t fscache_n_attr_changed_ok;
46294 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
46295 +atomic_unchecked_t fscache_n_attr_changed_nomem;
46296 +atomic_unchecked_t fscache_n_attr_changed_calls;
46297
46298 -atomic_t fscache_n_allocs;
46299 -atomic_t fscache_n_allocs_ok;
46300 -atomic_t fscache_n_allocs_wait;
46301 -atomic_t fscache_n_allocs_nobufs;
46302 -atomic_t fscache_n_allocs_intr;
46303 -atomic_t fscache_n_allocs_object_dead;
46304 -atomic_t fscache_n_alloc_ops;
46305 -atomic_t fscache_n_alloc_op_waits;
46306 +atomic_unchecked_t fscache_n_allocs;
46307 +atomic_unchecked_t fscache_n_allocs_ok;
46308 +atomic_unchecked_t fscache_n_allocs_wait;
46309 +atomic_unchecked_t fscache_n_allocs_nobufs;
46310 +atomic_unchecked_t fscache_n_allocs_intr;
46311 +atomic_unchecked_t fscache_n_allocs_object_dead;
46312 +atomic_unchecked_t fscache_n_alloc_ops;
46313 +atomic_unchecked_t fscache_n_alloc_op_waits;
46314
46315 -atomic_t fscache_n_retrievals;
46316 -atomic_t fscache_n_retrievals_ok;
46317 -atomic_t fscache_n_retrievals_wait;
46318 -atomic_t fscache_n_retrievals_nodata;
46319 -atomic_t fscache_n_retrievals_nobufs;
46320 -atomic_t fscache_n_retrievals_intr;
46321 -atomic_t fscache_n_retrievals_nomem;
46322 -atomic_t fscache_n_retrievals_object_dead;
46323 -atomic_t fscache_n_retrieval_ops;
46324 -atomic_t fscache_n_retrieval_op_waits;
46325 +atomic_unchecked_t fscache_n_retrievals;
46326 +atomic_unchecked_t fscache_n_retrievals_ok;
46327 +atomic_unchecked_t fscache_n_retrievals_wait;
46328 +atomic_unchecked_t fscache_n_retrievals_nodata;
46329 +atomic_unchecked_t fscache_n_retrievals_nobufs;
46330 +atomic_unchecked_t fscache_n_retrievals_intr;
46331 +atomic_unchecked_t fscache_n_retrievals_nomem;
46332 +atomic_unchecked_t fscache_n_retrievals_object_dead;
46333 +atomic_unchecked_t fscache_n_retrieval_ops;
46334 +atomic_unchecked_t fscache_n_retrieval_op_waits;
46335
46336 -atomic_t fscache_n_stores;
46337 -atomic_t fscache_n_stores_ok;
46338 -atomic_t fscache_n_stores_again;
46339 -atomic_t fscache_n_stores_nobufs;
46340 -atomic_t fscache_n_stores_oom;
46341 -atomic_t fscache_n_store_ops;
46342 -atomic_t fscache_n_store_calls;
46343 -atomic_t fscache_n_store_pages;
46344 -atomic_t fscache_n_store_radix_deletes;
46345 -atomic_t fscache_n_store_pages_over_limit;
46346 +atomic_unchecked_t fscache_n_stores;
46347 +atomic_unchecked_t fscache_n_stores_ok;
46348 +atomic_unchecked_t fscache_n_stores_again;
46349 +atomic_unchecked_t fscache_n_stores_nobufs;
46350 +atomic_unchecked_t fscache_n_stores_oom;
46351 +atomic_unchecked_t fscache_n_store_ops;
46352 +atomic_unchecked_t fscache_n_store_calls;
46353 +atomic_unchecked_t fscache_n_store_pages;
46354 +atomic_unchecked_t fscache_n_store_radix_deletes;
46355 +atomic_unchecked_t fscache_n_store_pages_over_limit;
46356
46357 -atomic_t fscache_n_store_vmscan_not_storing;
46358 -atomic_t fscache_n_store_vmscan_gone;
46359 -atomic_t fscache_n_store_vmscan_busy;
46360 -atomic_t fscache_n_store_vmscan_cancelled;
46361 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46362 +atomic_unchecked_t fscache_n_store_vmscan_gone;
46363 +atomic_unchecked_t fscache_n_store_vmscan_busy;
46364 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46365
46366 -atomic_t fscache_n_marks;
46367 -atomic_t fscache_n_uncaches;
46368 +atomic_unchecked_t fscache_n_marks;
46369 +atomic_unchecked_t fscache_n_uncaches;
46370
46371 -atomic_t fscache_n_acquires;
46372 -atomic_t fscache_n_acquires_null;
46373 -atomic_t fscache_n_acquires_no_cache;
46374 -atomic_t fscache_n_acquires_ok;
46375 -atomic_t fscache_n_acquires_nobufs;
46376 -atomic_t fscache_n_acquires_oom;
46377 +atomic_unchecked_t fscache_n_acquires;
46378 +atomic_unchecked_t fscache_n_acquires_null;
46379 +atomic_unchecked_t fscache_n_acquires_no_cache;
46380 +atomic_unchecked_t fscache_n_acquires_ok;
46381 +atomic_unchecked_t fscache_n_acquires_nobufs;
46382 +atomic_unchecked_t fscache_n_acquires_oom;
46383
46384 -atomic_t fscache_n_updates;
46385 -atomic_t fscache_n_updates_null;
46386 -atomic_t fscache_n_updates_run;
46387 +atomic_unchecked_t fscache_n_updates;
46388 +atomic_unchecked_t fscache_n_updates_null;
46389 +atomic_unchecked_t fscache_n_updates_run;
46390
46391 -atomic_t fscache_n_relinquishes;
46392 -atomic_t fscache_n_relinquishes_null;
46393 -atomic_t fscache_n_relinquishes_waitcrt;
46394 -atomic_t fscache_n_relinquishes_retire;
46395 +atomic_unchecked_t fscache_n_relinquishes;
46396 +atomic_unchecked_t fscache_n_relinquishes_null;
46397 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46398 +atomic_unchecked_t fscache_n_relinquishes_retire;
46399
46400 -atomic_t fscache_n_cookie_index;
46401 -atomic_t fscache_n_cookie_data;
46402 -atomic_t fscache_n_cookie_special;
46403 +atomic_unchecked_t fscache_n_cookie_index;
46404 +atomic_unchecked_t fscache_n_cookie_data;
46405 +atomic_unchecked_t fscache_n_cookie_special;
46406
46407 -atomic_t fscache_n_object_alloc;
46408 -atomic_t fscache_n_object_no_alloc;
46409 -atomic_t fscache_n_object_lookups;
46410 -atomic_t fscache_n_object_lookups_negative;
46411 -atomic_t fscache_n_object_lookups_positive;
46412 -atomic_t fscache_n_object_lookups_timed_out;
46413 -atomic_t fscache_n_object_created;
46414 -atomic_t fscache_n_object_avail;
46415 -atomic_t fscache_n_object_dead;
46416 +atomic_unchecked_t fscache_n_object_alloc;
46417 +atomic_unchecked_t fscache_n_object_no_alloc;
46418 +atomic_unchecked_t fscache_n_object_lookups;
46419 +atomic_unchecked_t fscache_n_object_lookups_negative;
46420 +atomic_unchecked_t fscache_n_object_lookups_positive;
46421 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
46422 +atomic_unchecked_t fscache_n_object_created;
46423 +atomic_unchecked_t fscache_n_object_avail;
46424 +atomic_unchecked_t fscache_n_object_dead;
46425
46426 -atomic_t fscache_n_checkaux_none;
46427 -atomic_t fscache_n_checkaux_okay;
46428 -atomic_t fscache_n_checkaux_update;
46429 -atomic_t fscache_n_checkaux_obsolete;
46430 +atomic_unchecked_t fscache_n_checkaux_none;
46431 +atomic_unchecked_t fscache_n_checkaux_okay;
46432 +atomic_unchecked_t fscache_n_checkaux_update;
46433 +atomic_unchecked_t fscache_n_checkaux_obsolete;
46434
46435 atomic_t fscache_n_cop_alloc_object;
46436 atomic_t fscache_n_cop_lookup_object;
46437 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46438 seq_puts(m, "FS-Cache statistics\n");
46439
46440 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46441 - atomic_read(&fscache_n_cookie_index),
46442 - atomic_read(&fscache_n_cookie_data),
46443 - atomic_read(&fscache_n_cookie_special));
46444 + atomic_read_unchecked(&fscache_n_cookie_index),
46445 + atomic_read_unchecked(&fscache_n_cookie_data),
46446 + atomic_read_unchecked(&fscache_n_cookie_special));
46447
46448 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46449 - atomic_read(&fscache_n_object_alloc),
46450 - atomic_read(&fscache_n_object_no_alloc),
46451 - atomic_read(&fscache_n_object_avail),
46452 - atomic_read(&fscache_n_object_dead));
46453 + atomic_read_unchecked(&fscache_n_object_alloc),
46454 + atomic_read_unchecked(&fscache_n_object_no_alloc),
46455 + atomic_read_unchecked(&fscache_n_object_avail),
46456 + atomic_read_unchecked(&fscache_n_object_dead));
46457 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46458 - atomic_read(&fscache_n_checkaux_none),
46459 - atomic_read(&fscache_n_checkaux_okay),
46460 - atomic_read(&fscache_n_checkaux_update),
46461 - atomic_read(&fscache_n_checkaux_obsolete));
46462 + atomic_read_unchecked(&fscache_n_checkaux_none),
46463 + atomic_read_unchecked(&fscache_n_checkaux_okay),
46464 + atomic_read_unchecked(&fscache_n_checkaux_update),
46465 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46466
46467 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46468 - atomic_read(&fscache_n_marks),
46469 - atomic_read(&fscache_n_uncaches));
46470 + atomic_read_unchecked(&fscache_n_marks),
46471 + atomic_read_unchecked(&fscache_n_uncaches));
46472
46473 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46474 " oom=%u\n",
46475 - atomic_read(&fscache_n_acquires),
46476 - atomic_read(&fscache_n_acquires_null),
46477 - atomic_read(&fscache_n_acquires_no_cache),
46478 - atomic_read(&fscache_n_acquires_ok),
46479 - atomic_read(&fscache_n_acquires_nobufs),
46480 - atomic_read(&fscache_n_acquires_oom));
46481 + atomic_read_unchecked(&fscache_n_acquires),
46482 + atomic_read_unchecked(&fscache_n_acquires_null),
46483 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
46484 + atomic_read_unchecked(&fscache_n_acquires_ok),
46485 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
46486 + atomic_read_unchecked(&fscache_n_acquires_oom));
46487
46488 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46489 - atomic_read(&fscache_n_object_lookups),
46490 - atomic_read(&fscache_n_object_lookups_negative),
46491 - atomic_read(&fscache_n_object_lookups_positive),
46492 - atomic_read(&fscache_n_object_created),
46493 - atomic_read(&fscache_n_object_lookups_timed_out));
46494 + atomic_read_unchecked(&fscache_n_object_lookups),
46495 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
46496 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
46497 + atomic_read_unchecked(&fscache_n_object_created),
46498 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46499
46500 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46501 - atomic_read(&fscache_n_updates),
46502 - atomic_read(&fscache_n_updates_null),
46503 - atomic_read(&fscache_n_updates_run));
46504 + atomic_read_unchecked(&fscache_n_updates),
46505 + atomic_read_unchecked(&fscache_n_updates_null),
46506 + atomic_read_unchecked(&fscache_n_updates_run));
46507
46508 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46509 - atomic_read(&fscache_n_relinquishes),
46510 - atomic_read(&fscache_n_relinquishes_null),
46511 - atomic_read(&fscache_n_relinquishes_waitcrt),
46512 - atomic_read(&fscache_n_relinquishes_retire));
46513 + atomic_read_unchecked(&fscache_n_relinquishes),
46514 + atomic_read_unchecked(&fscache_n_relinquishes_null),
46515 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46516 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
46517
46518 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46519 - atomic_read(&fscache_n_attr_changed),
46520 - atomic_read(&fscache_n_attr_changed_ok),
46521 - atomic_read(&fscache_n_attr_changed_nobufs),
46522 - atomic_read(&fscache_n_attr_changed_nomem),
46523 - atomic_read(&fscache_n_attr_changed_calls));
46524 + atomic_read_unchecked(&fscache_n_attr_changed),
46525 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
46526 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46527 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46528 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
46529
46530 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46531 - atomic_read(&fscache_n_allocs),
46532 - atomic_read(&fscache_n_allocs_ok),
46533 - atomic_read(&fscache_n_allocs_wait),
46534 - atomic_read(&fscache_n_allocs_nobufs),
46535 - atomic_read(&fscache_n_allocs_intr));
46536 + atomic_read_unchecked(&fscache_n_allocs),
46537 + atomic_read_unchecked(&fscache_n_allocs_ok),
46538 + atomic_read_unchecked(&fscache_n_allocs_wait),
46539 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
46540 + atomic_read_unchecked(&fscache_n_allocs_intr));
46541 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46542 - atomic_read(&fscache_n_alloc_ops),
46543 - atomic_read(&fscache_n_alloc_op_waits),
46544 - atomic_read(&fscache_n_allocs_object_dead));
46545 + atomic_read_unchecked(&fscache_n_alloc_ops),
46546 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
46547 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
46548
46549 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46550 " int=%u oom=%u\n",
46551 - atomic_read(&fscache_n_retrievals),
46552 - atomic_read(&fscache_n_retrievals_ok),
46553 - atomic_read(&fscache_n_retrievals_wait),
46554 - atomic_read(&fscache_n_retrievals_nodata),
46555 - atomic_read(&fscache_n_retrievals_nobufs),
46556 - atomic_read(&fscache_n_retrievals_intr),
46557 - atomic_read(&fscache_n_retrievals_nomem));
46558 + atomic_read_unchecked(&fscache_n_retrievals),
46559 + atomic_read_unchecked(&fscache_n_retrievals_ok),
46560 + atomic_read_unchecked(&fscache_n_retrievals_wait),
46561 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
46562 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46563 + atomic_read_unchecked(&fscache_n_retrievals_intr),
46564 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
46565 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46566 - atomic_read(&fscache_n_retrieval_ops),
46567 - atomic_read(&fscache_n_retrieval_op_waits),
46568 - atomic_read(&fscache_n_retrievals_object_dead));
46569 + atomic_read_unchecked(&fscache_n_retrieval_ops),
46570 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46571 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46572
46573 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46574 - atomic_read(&fscache_n_stores),
46575 - atomic_read(&fscache_n_stores_ok),
46576 - atomic_read(&fscache_n_stores_again),
46577 - atomic_read(&fscache_n_stores_nobufs),
46578 - atomic_read(&fscache_n_stores_oom));
46579 + atomic_read_unchecked(&fscache_n_stores),
46580 + atomic_read_unchecked(&fscache_n_stores_ok),
46581 + atomic_read_unchecked(&fscache_n_stores_again),
46582 + atomic_read_unchecked(&fscache_n_stores_nobufs),
46583 + atomic_read_unchecked(&fscache_n_stores_oom));
46584 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46585 - atomic_read(&fscache_n_store_ops),
46586 - atomic_read(&fscache_n_store_calls),
46587 - atomic_read(&fscache_n_store_pages),
46588 - atomic_read(&fscache_n_store_radix_deletes),
46589 - atomic_read(&fscache_n_store_pages_over_limit));
46590 + atomic_read_unchecked(&fscache_n_store_ops),
46591 + atomic_read_unchecked(&fscache_n_store_calls),
46592 + atomic_read_unchecked(&fscache_n_store_pages),
46593 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
46594 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46595
46596 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46597 - atomic_read(&fscache_n_store_vmscan_not_storing),
46598 - atomic_read(&fscache_n_store_vmscan_gone),
46599 - atomic_read(&fscache_n_store_vmscan_busy),
46600 - atomic_read(&fscache_n_store_vmscan_cancelled));
46601 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46602 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46603 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46604 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46605
46606 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46607 - atomic_read(&fscache_n_op_pend),
46608 - atomic_read(&fscache_n_op_run),
46609 - atomic_read(&fscache_n_op_enqueue),
46610 - atomic_read(&fscache_n_op_cancelled),
46611 - atomic_read(&fscache_n_op_rejected));
46612 + atomic_read_unchecked(&fscache_n_op_pend),
46613 + atomic_read_unchecked(&fscache_n_op_run),
46614 + atomic_read_unchecked(&fscache_n_op_enqueue),
46615 + atomic_read_unchecked(&fscache_n_op_cancelled),
46616 + atomic_read_unchecked(&fscache_n_op_rejected));
46617 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46618 - atomic_read(&fscache_n_op_deferred_release),
46619 - atomic_read(&fscache_n_op_release),
46620 - atomic_read(&fscache_n_op_gc));
46621 + atomic_read_unchecked(&fscache_n_op_deferred_release),
46622 + atomic_read_unchecked(&fscache_n_op_release),
46623 + atomic_read_unchecked(&fscache_n_op_gc));
46624
46625 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46626 atomic_read(&fscache_n_cop_alloc_object),
46627 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46628 index 3426521..3b75162 100644
46629 --- a/fs/fuse/cuse.c
46630 +++ b/fs/fuse/cuse.c
46631 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
46632 INIT_LIST_HEAD(&cuse_conntbl[i]);
46633
46634 /* inherit and extend fuse_dev_operations */
46635 - cuse_channel_fops = fuse_dev_operations;
46636 - cuse_channel_fops.owner = THIS_MODULE;
46637 - cuse_channel_fops.open = cuse_channel_open;
46638 - cuse_channel_fops.release = cuse_channel_release;
46639 + pax_open_kernel();
46640 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46641 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46642 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
46643 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
46644 + pax_close_kernel();
46645
46646 cuse_class = class_create(THIS_MODULE, "cuse");
46647 if (IS_ERR(cuse_class))
46648 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46649 index 2aaf3ea..8e50863 100644
46650 --- a/fs/fuse/dev.c
46651 +++ b/fs/fuse/dev.c
46652 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46653 ret = 0;
46654 pipe_lock(pipe);
46655
46656 - if (!pipe->readers) {
46657 + if (!atomic_read(&pipe->readers)) {
46658 send_sig(SIGPIPE, current, 0);
46659 if (!ret)
46660 ret = -EPIPE;
46661 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46662 index 9f63e49..d8a64c0 100644
46663 --- a/fs/fuse/dir.c
46664 +++ b/fs/fuse/dir.c
46665 @@ -1147,7 +1147,7 @@ static char *read_link(struct dentry *dentry)
46666 return link;
46667 }
46668
46669 -static void free_link(char *link)
46670 +static void free_link(const char *link)
46671 {
46672 if (!IS_ERR(link))
46673 free_page((unsigned long) link);
46674 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46675 index cfd4959..a780959 100644
46676 --- a/fs/gfs2/inode.c
46677 +++ b/fs/gfs2/inode.c
46678 @@ -1490,7 +1490,7 @@ out:
46679
46680 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46681 {
46682 - char *s = nd_get_link(nd);
46683 + const char *s = nd_get_link(nd);
46684 if (!IS_ERR(s))
46685 kfree(s);
46686 }
46687 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46688 index 0be5a78..9cfb853 100644
46689 --- a/fs/hugetlbfs/inode.c
46690 +++ b/fs/hugetlbfs/inode.c
46691 @@ -915,7 +915,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46692 .kill_sb = kill_litter_super,
46693 };
46694
46695 -static struct vfsmount *hugetlbfs_vfsmount;
46696 +struct vfsmount *hugetlbfs_vfsmount;
46697
46698 static int can_do_hugetlb_shm(void)
46699 {
46700 diff --git a/fs/inode.c b/fs/inode.c
46701 index ee4e66b..9a39f9c 100644
46702 --- a/fs/inode.c
46703 +++ b/fs/inode.c
46704 @@ -787,8 +787,8 @@ unsigned int get_next_ino(void)
46705
46706 #ifdef CONFIG_SMP
46707 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46708 - static atomic_t shared_last_ino;
46709 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46710 + static atomic_unchecked_t shared_last_ino;
46711 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46712
46713 res = next - LAST_INO_BATCH;
46714 }
46715 @@ -855,8 +855,7 @@ void lockdep_annotate_inode_mutex_key(struct inode *inode)
46716 struct file_system_type *type = inode->i_sb->s_type;
46717
46718 /* Set new key only if filesystem hasn't already changed it */
46719 - if (!lockdep_match_class(&inode->i_mutex,
46720 - &type->i_mutex_key)) {
46721 + if (lockdep_match_class(&inode->i_mutex, &type->i_mutex_key)) {
46722 /*
46723 * ensure nobody is actually holding i_mutex
46724 */
46725 @@ -883,6 +882,7 @@ void unlock_new_inode(struct inode *inode)
46726 spin_lock(&inode->i_lock);
46727 WARN_ON(!(inode->i_state & I_NEW));
46728 inode->i_state &= ~I_NEW;
46729 + smp_mb();
46730 wake_up_bit(&inode->i_state, __I_NEW);
46731 spin_unlock(&inode->i_lock);
46732 }
46733 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46734 index e513f19..2ab1351 100644
46735 --- a/fs/jffs2/erase.c
46736 +++ b/fs/jffs2/erase.c
46737 @@ -439,7 +439,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46738 struct jffs2_unknown_node marker = {
46739 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46740 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46741 - .totlen = cpu_to_je32(c->cleanmarker_size)
46742 + .totlen = cpu_to_je32(c->cleanmarker_size),
46743 + .hdr_crc = cpu_to_je32(0)
46744 };
46745
46746 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46747 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46748 index b09e51d..e482afa 100644
46749 --- a/fs/jffs2/wbuf.c
46750 +++ b/fs/jffs2/wbuf.c
46751 @@ -1011,7 +1011,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46752 {
46753 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46754 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46755 - .totlen = constant_cpu_to_je32(8)
46756 + .totlen = constant_cpu_to_je32(8),
46757 + .hdr_crc = constant_cpu_to_je32(0)
46758 };
46759
46760 /*
46761 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46762 index a44eff0..462e07d 100644
46763 --- a/fs/jfs/super.c
46764 +++ b/fs/jfs/super.c
46765 @@ -802,7 +802,7 @@ static int __init init_jfs_fs(void)
46766
46767 jfs_inode_cachep =
46768 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46769 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46770 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46771 init_once);
46772 if (jfs_inode_cachep == NULL)
46773 return -ENOMEM;
46774 diff --git a/fs/libfs.c b/fs/libfs.c
46775 index f6d411e..e82a08d 100644
46776 --- a/fs/libfs.c
46777 +++ b/fs/libfs.c
46778 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46779
46780 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46781 struct dentry *next;
46782 + char d_name[sizeof(next->d_iname)];
46783 + const unsigned char *name;
46784 +
46785 next = list_entry(p, struct dentry, d_u.d_child);
46786 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46787 if (!simple_positive(next)) {
46788 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46789
46790 spin_unlock(&next->d_lock);
46791 spin_unlock(&dentry->d_lock);
46792 - if (filldir(dirent, next->d_name.name,
46793 + name = next->d_name.name;
46794 + if (name == next->d_iname) {
46795 + memcpy(d_name, name, next->d_name.len);
46796 + name = d_name;
46797 + }
46798 + if (filldir(dirent, name,
46799 next->d_name.len, filp->f_pos,
46800 next->d_inode->i_ino,
46801 dt_type(next->d_inode)) < 0)
46802 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46803 index 8392cb8..80d6193 100644
46804 --- a/fs/lockd/clntproc.c
46805 +++ b/fs/lockd/clntproc.c
46806 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46807 /*
46808 * Cookie counter for NLM requests
46809 */
46810 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46811 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46812
46813 void nlmclnt_next_cookie(struct nlm_cookie *c)
46814 {
46815 - u32 cookie = atomic_inc_return(&nlm_cookie);
46816 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46817
46818 memcpy(c->data, &cookie, 4);
46819 c->len=4;
46820 diff --git a/fs/locks.c b/fs/locks.c
46821 index 637694b..f84a121 100644
46822 --- a/fs/locks.c
46823 +++ b/fs/locks.c
46824 @@ -2074,16 +2074,16 @@ void locks_remove_flock(struct file *filp)
46825 return;
46826
46827 if (filp->f_op && filp->f_op->flock) {
46828 - struct file_lock fl = {
46829 + struct file_lock flock = {
46830 .fl_pid = current->tgid,
46831 .fl_file = filp,
46832 .fl_flags = FL_FLOCK,
46833 .fl_type = F_UNLCK,
46834 .fl_end = OFFSET_MAX,
46835 };
46836 - filp->f_op->flock(filp, F_SETLKW, &fl);
46837 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
46838 - fl.fl_ops->fl_release_private(&fl);
46839 + filp->f_op->flock(filp, F_SETLKW, &flock);
46840 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
46841 + flock.fl_ops->fl_release_private(&flock);
46842 }
46843
46844 lock_flocks();
46845 diff --git a/fs/namei.c b/fs/namei.c
46846 index 9680cef..a19f203 100644
46847 --- a/fs/namei.c
46848 +++ b/fs/namei.c
46849 @@ -279,16 +279,32 @@ int generic_permission(struct inode *inode, int mask)
46850 if (ret != -EACCES)
46851 return ret;
46852
46853 +#ifdef CONFIG_GRKERNSEC
46854 + /* we'll block if we have to log due to a denied capability use */
46855 + if (mask & MAY_NOT_BLOCK)
46856 + return -ECHILD;
46857 +#endif
46858 +
46859 if (S_ISDIR(inode->i_mode)) {
46860 /* DACs are overridable for directories */
46861 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46862 - return 0;
46863 if (!(mask & MAY_WRITE))
46864 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46865 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46866 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46867 return 0;
46868 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46869 + return 0;
46870 return -EACCES;
46871 }
46872 /*
46873 + * Searching includes executable on directories, else just read.
46874 + */
46875 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46876 + if (mask == MAY_READ)
46877 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46878 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46879 + return 0;
46880 +
46881 + /*
46882 * Read/write DACs are always overridable.
46883 * Executable DACs are overridable when there is
46884 * at least one exec bit set.
46885 @@ -297,14 +313,6 @@ int generic_permission(struct inode *inode, int mask)
46886 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46887 return 0;
46888
46889 - /*
46890 - * Searching includes executable on directories, else just read.
46891 - */
46892 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46893 - if (mask == MAY_READ)
46894 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46895 - return 0;
46896 -
46897 return -EACCES;
46898 }
46899
46900 @@ -653,11 +661,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
46901 return error;
46902 }
46903
46904 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
46905 + dentry->d_inode, dentry, nd->path.mnt)) {
46906 + error = -EACCES;
46907 + *p = ERR_PTR(error); /* no ->put_link(), please */
46908 + path_put(&nd->path);
46909 + return error;
46910 + }
46911 +
46912 nd->last_type = LAST_BIND;
46913 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
46914 error = PTR_ERR(*p);
46915 if (!IS_ERR(*p)) {
46916 - char *s = nd_get_link(nd);
46917 + const char *s = nd_get_link(nd);
46918 error = 0;
46919 if (s)
46920 error = __vfs_follow_link(nd, s);
46921 @@ -1624,6 +1640,21 @@ static int path_lookupat(int dfd, const char *name,
46922 if (!err)
46923 err = complete_walk(nd);
46924
46925 + if (!(nd->flags & LOOKUP_PARENT)) {
46926 +#ifdef CONFIG_GRKERNSEC
46927 + if (flags & LOOKUP_RCU) {
46928 + if (!err)
46929 + path_put(&nd->path);
46930 + err = -ECHILD;
46931 + } else
46932 +#endif
46933 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46934 + if (!err)
46935 + path_put(&nd->path);
46936 + err = -ENOENT;
46937 + }
46938 + }
46939 +
46940 if (!err && nd->flags & LOOKUP_DIRECTORY) {
46941 if (!nd->inode->i_op->lookup) {
46942 path_put(&nd->path);
46943 @@ -1651,6 +1682,15 @@ static int do_path_lookup(int dfd, const char *name,
46944 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
46945
46946 if (likely(!retval)) {
46947 + if (*name != '/' && nd->path.dentry && nd->inode) {
46948 +#ifdef CONFIG_GRKERNSEC
46949 + if (flags & LOOKUP_RCU)
46950 + return -ECHILD;
46951 +#endif
46952 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
46953 + return -ENOENT;
46954 + }
46955 +
46956 if (unlikely(!audit_dummy_context())) {
46957 if (nd->path.dentry && nd->inode)
46958 audit_inode(name, nd->path.dentry);
46959 @@ -2048,6 +2088,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
46960 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
46961 return -EPERM;
46962
46963 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
46964 + return -EPERM;
46965 + if (gr_handle_rawio(inode))
46966 + return -EPERM;
46967 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
46968 + return -EACCES;
46969 +
46970 return 0;
46971 }
46972
46973 @@ -2109,6 +2156,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46974 error = complete_walk(nd);
46975 if (error)
46976 return ERR_PTR(error);
46977 +#ifdef CONFIG_GRKERNSEC
46978 + if (nd->flags & LOOKUP_RCU) {
46979 + error = -ECHILD;
46980 + goto exit;
46981 + }
46982 +#endif
46983 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46984 + error = -ENOENT;
46985 + goto exit;
46986 + }
46987 audit_inode(pathname, nd->path.dentry);
46988 if (open_flag & O_CREAT) {
46989 error = -EISDIR;
46990 @@ -2119,6 +2176,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46991 error = complete_walk(nd);
46992 if (error)
46993 return ERR_PTR(error);
46994 +#ifdef CONFIG_GRKERNSEC
46995 + if (nd->flags & LOOKUP_RCU) {
46996 + error = -ECHILD;
46997 + goto exit;
46998 + }
46999 +#endif
47000 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47001 + error = -ENOENT;
47002 + goto exit;
47003 + }
47004 audit_inode(pathname, dir);
47005 goto ok;
47006 }
47007 @@ -2140,6 +2207,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47008 error = complete_walk(nd);
47009 if (error)
47010 return ERR_PTR(error);
47011 +#ifdef CONFIG_GRKERNSEC
47012 + if (nd->flags & LOOKUP_RCU) {
47013 + error = -ECHILD;
47014 + goto exit;
47015 + }
47016 +#endif
47017 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47018 + error = -ENOENT;
47019 + goto exit;
47020 + }
47021
47022 error = -ENOTDIR;
47023 if (nd->flags & LOOKUP_DIRECTORY) {
47024 @@ -2180,6 +2257,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47025 /* Negative dentry, just create the file */
47026 if (!dentry->d_inode) {
47027 int mode = op->mode;
47028 +
47029 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
47030 + error = -EACCES;
47031 + goto exit_mutex_unlock;
47032 + }
47033 +
47034 if (!IS_POSIXACL(dir->d_inode))
47035 mode &= ~current_umask();
47036 /*
47037 @@ -2203,6 +2286,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47038 error = vfs_create(dir->d_inode, dentry, mode, nd);
47039 if (error)
47040 goto exit_mutex_unlock;
47041 + else
47042 + gr_handle_create(path->dentry, path->mnt);
47043 mutex_unlock(&dir->d_inode->i_mutex);
47044 dput(nd->path.dentry);
47045 nd->path.dentry = dentry;
47046 @@ -2212,6 +2297,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47047 /*
47048 * It already exists.
47049 */
47050 +
47051 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
47052 + error = -ENOENT;
47053 + goto exit_mutex_unlock;
47054 + }
47055 +
47056 + /* only check if O_CREAT is specified, all other checks need to go
47057 + into may_open */
47058 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47059 + error = -EACCES;
47060 + goto exit_mutex_unlock;
47061 + }
47062 +
47063 mutex_unlock(&dir->d_inode->i_mutex);
47064 audit_inode(pathname, path->dentry);
47065
47066 @@ -2424,6 +2522,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47067 *path = nd.path;
47068 return dentry;
47069 eexist:
47070 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47071 + dput(dentry);
47072 + dentry = ERR_PTR(-ENOENT);
47073 + goto fail;
47074 + }
47075 dput(dentry);
47076 dentry = ERR_PTR(-EEXIST);
47077 fail:
47078 @@ -2446,6 +2549,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47079 }
47080 EXPORT_SYMBOL(user_path_create);
47081
47082 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47083 +{
47084 + char *tmp = getname(pathname);
47085 + struct dentry *res;
47086 + if (IS_ERR(tmp))
47087 + return ERR_CAST(tmp);
47088 + res = kern_path_create(dfd, tmp, path, is_dir);
47089 + if (IS_ERR(res))
47090 + putname(tmp);
47091 + else
47092 + *to = tmp;
47093 + return res;
47094 +}
47095 +
47096 int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
47097 {
47098 int error = may_create(dir, dentry);
47099 @@ -2513,6 +2630,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
47100 error = mnt_want_write(path.mnt);
47101 if (error)
47102 goto out_dput;
47103 +
47104 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47105 + error = -EPERM;
47106 + goto out_drop_write;
47107 + }
47108 +
47109 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47110 + error = -EACCES;
47111 + goto out_drop_write;
47112 + }
47113 +
47114 error = security_path_mknod(&path, dentry, mode, dev);
47115 if (error)
47116 goto out_drop_write;
47117 @@ -2530,6 +2658,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
47118 }
47119 out_drop_write:
47120 mnt_drop_write(path.mnt);
47121 +
47122 + if (!error)
47123 + gr_handle_create(dentry, path.mnt);
47124 out_dput:
47125 dput(dentry);
47126 mutex_unlock(&path.dentry->d_inode->i_mutex);
47127 @@ -2579,12 +2710,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
47128 error = mnt_want_write(path.mnt);
47129 if (error)
47130 goto out_dput;
47131 +
47132 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47133 + error = -EACCES;
47134 + goto out_drop_write;
47135 + }
47136 +
47137 error = security_path_mkdir(&path, dentry, mode);
47138 if (error)
47139 goto out_drop_write;
47140 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47141 out_drop_write:
47142 mnt_drop_write(path.mnt);
47143 +
47144 + if (!error)
47145 + gr_handle_create(dentry, path.mnt);
47146 out_dput:
47147 dput(dentry);
47148 mutex_unlock(&path.dentry->d_inode->i_mutex);
47149 @@ -2664,6 +2804,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47150 char * name;
47151 struct dentry *dentry;
47152 struct nameidata nd;
47153 + ino_t saved_ino = 0;
47154 + dev_t saved_dev = 0;
47155
47156 error = user_path_parent(dfd, pathname, &nd, &name);
47157 if (error)
47158 @@ -2692,6 +2834,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
47159 error = -ENOENT;
47160 goto exit3;
47161 }
47162 +
47163 + saved_ino = dentry->d_inode->i_ino;
47164 + saved_dev = gr_get_dev_from_dentry(dentry);
47165 +
47166 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47167 + error = -EACCES;
47168 + goto exit3;
47169 + }
47170 +
47171 error = mnt_want_write(nd.path.mnt);
47172 if (error)
47173 goto exit3;
47174 @@ -2699,6 +2850,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47175 if (error)
47176 goto exit4;
47177 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47178 + if (!error && (saved_dev || saved_ino))
47179 + gr_handle_delete(saved_ino, saved_dev);
47180 exit4:
47181 mnt_drop_write(nd.path.mnt);
47182 exit3:
47183 @@ -2761,6 +2914,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47184 struct dentry *dentry;
47185 struct nameidata nd;
47186 struct inode *inode = NULL;
47187 + ino_t saved_ino = 0;
47188 + dev_t saved_dev = 0;
47189
47190 error = user_path_parent(dfd, pathname, &nd, &name);
47191 if (error)
47192 @@ -2783,6 +2938,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47193 if (!inode)
47194 goto slashes;
47195 ihold(inode);
47196 +
47197 + if (inode->i_nlink <= 1) {
47198 + saved_ino = inode->i_ino;
47199 + saved_dev = gr_get_dev_from_dentry(dentry);
47200 + }
47201 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47202 + error = -EACCES;
47203 + goto exit2;
47204 + }
47205 +
47206 error = mnt_want_write(nd.path.mnt);
47207 if (error)
47208 goto exit2;
47209 @@ -2790,6 +2955,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47210 if (error)
47211 goto exit3;
47212 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
47213 + if (!error && (saved_ino || saved_dev))
47214 + gr_handle_delete(saved_ino, saved_dev);
47215 exit3:
47216 mnt_drop_write(nd.path.mnt);
47217 exit2:
47218 @@ -2865,10 +3032,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
47219 error = mnt_want_write(path.mnt);
47220 if (error)
47221 goto out_dput;
47222 +
47223 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47224 + error = -EACCES;
47225 + goto out_drop_write;
47226 + }
47227 +
47228 error = security_path_symlink(&path, dentry, from);
47229 if (error)
47230 goto out_drop_write;
47231 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47232 + if (!error)
47233 + gr_handle_create(dentry, path.mnt);
47234 out_drop_write:
47235 mnt_drop_write(path.mnt);
47236 out_dput:
47237 @@ -2940,6 +3115,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47238 {
47239 struct dentry *new_dentry;
47240 struct path old_path, new_path;
47241 + char *to = NULL;
47242 int how = 0;
47243 int error;
47244
47245 @@ -2963,7 +3139,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47246 if (error)
47247 return error;
47248
47249 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47250 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47251 error = PTR_ERR(new_dentry);
47252 if (IS_ERR(new_dentry))
47253 goto out;
47254 @@ -2974,13 +3150,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47255 error = mnt_want_write(new_path.mnt);
47256 if (error)
47257 goto out_dput;
47258 +
47259 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47260 + old_path.dentry->d_inode,
47261 + old_path.dentry->d_inode->i_mode, to)) {
47262 + error = -EACCES;
47263 + goto out_drop_write;
47264 + }
47265 +
47266 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47267 + old_path.dentry, old_path.mnt, to)) {
47268 + error = -EACCES;
47269 + goto out_drop_write;
47270 + }
47271 +
47272 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47273 if (error)
47274 goto out_drop_write;
47275 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47276 + if (!error)
47277 + gr_handle_create(new_dentry, new_path.mnt);
47278 out_drop_write:
47279 mnt_drop_write(new_path.mnt);
47280 out_dput:
47281 + putname(to);
47282 dput(new_dentry);
47283 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47284 path_put(&new_path);
47285 @@ -3208,6 +3401,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47286 if (new_dentry == trap)
47287 goto exit5;
47288
47289 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47290 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
47291 + to);
47292 + if (error)
47293 + goto exit5;
47294 +
47295 error = mnt_want_write(oldnd.path.mnt);
47296 if (error)
47297 goto exit5;
47298 @@ -3217,6 +3416,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47299 goto exit6;
47300 error = vfs_rename(old_dir->d_inode, old_dentry,
47301 new_dir->d_inode, new_dentry);
47302 + if (!error)
47303 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47304 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47305 exit6:
47306 mnt_drop_write(oldnd.path.mnt);
47307 exit5:
47308 @@ -3242,6 +3444,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47309
47310 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47311 {
47312 + char tmpbuf[64];
47313 + const char *newlink;
47314 int len;
47315
47316 len = PTR_ERR(link);
47317 @@ -3251,7 +3455,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47318 len = strlen(link);
47319 if (len > (unsigned) buflen)
47320 len = buflen;
47321 - if (copy_to_user(buffer, link, len))
47322 +
47323 + if (len < sizeof(tmpbuf)) {
47324 + memcpy(tmpbuf, link, len);
47325 + newlink = tmpbuf;
47326 + } else
47327 + newlink = link;
47328 +
47329 + if (copy_to_user(buffer, newlink, len))
47330 len = -EFAULT;
47331 out:
47332 return len;
47333 diff --git a/fs/namespace.c b/fs/namespace.c
47334 index cfc6d44..b4632a5 100644
47335 --- a/fs/namespace.c
47336 +++ b/fs/namespace.c
47337 @@ -1326,6 +1326,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
47338 if (!(sb->s_flags & MS_RDONLY))
47339 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47340 up_write(&sb->s_umount);
47341 +
47342 + gr_log_remount(mnt->mnt_devname, retval);
47343 +
47344 return retval;
47345 }
47346
47347 @@ -1345,6 +1348,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
47348 br_write_unlock(vfsmount_lock);
47349 up_write(&namespace_sem);
47350 release_mounts(&umount_list);
47351 +
47352 + gr_log_unmount(mnt->mnt_devname, retval);
47353 +
47354 return retval;
47355 }
47356
47357 @@ -2336,6 +2342,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47358 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47359 MS_STRICTATIME);
47360
47361 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47362 + retval = -EPERM;
47363 + goto dput_out;
47364 + }
47365 +
47366 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47367 + retval = -EPERM;
47368 + goto dput_out;
47369 + }
47370 +
47371 if (flags & MS_REMOUNT)
47372 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47373 data_page);
47374 @@ -2350,6 +2366,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47375 dev_name, data_page);
47376 dput_out:
47377 path_put(&path);
47378 +
47379 + gr_log_mount(dev_name, dir_name, retval);
47380 +
47381 return retval;
47382 }
47383
47384 @@ -2605,6 +2624,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47385 if (error)
47386 goto out2;
47387
47388 + if (gr_handle_chroot_pivot()) {
47389 + error = -EPERM;
47390 + goto out2;
47391 + }
47392 +
47393 get_fs_root(current->fs, &root);
47394 error = lock_mount(&old);
47395 if (error)
47396 diff --git a/fs/ncpfs/ncplib_kernel.h b/fs/ncpfs/ncplib_kernel.h
47397 index 09881e6..308ff20 100644
47398 --- a/fs/ncpfs/ncplib_kernel.h
47399 +++ b/fs/ncpfs/ncplib_kernel.h
47400 @@ -130,7 +130,7 @@ static inline int ncp_is_nfs_extras(struct ncp_server* server, unsigned int voln
47401 int ncp__io2vol(struct ncp_server *, unsigned char *, unsigned int *,
47402 const unsigned char *, unsigned int, int);
47403 int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
47404 - const unsigned char *, unsigned int, int);
47405 + const unsigned char *, unsigned int, int) __size_overflow(5);
47406
47407 #define NCP_ESC ':'
47408 #define NCP_IO_TABLE(sb) (NCP_SBP(sb)->nls_io)
47409 @@ -146,7 +146,7 @@ int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
47410 int ncp__io2vol(unsigned char *, unsigned int *,
47411 const unsigned char *, unsigned int, int);
47412 int ncp__vol2io(unsigned char *, unsigned int *,
47413 - const unsigned char *, unsigned int, int);
47414 + const unsigned char *, unsigned int, int) __size_overflow(5);
47415
47416 #define NCP_IO_TABLE(sb) NULL
47417 #define ncp_tolower(t, c) tolower(c)
47418 diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
47419 index 3db6b82..a57597e 100644
47420 --- a/fs/nfs/blocklayout/blocklayout.c
47421 +++ b/fs/nfs/blocklayout/blocklayout.c
47422 @@ -90,7 +90,7 @@ static int is_writable(struct pnfs_block_extent *be, sector_t isect)
47423 */
47424 struct parallel_io {
47425 struct kref refcnt;
47426 - struct rpc_call_ops call_ops;
47427 + rpc_call_ops_no_const call_ops;
47428 void (*pnfs_callback) (void *data);
47429 void *data;
47430 };
47431 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47432 index 50a15fa..ca113f9 100644
47433 --- a/fs/nfs/inode.c
47434 +++ b/fs/nfs/inode.c
47435 @@ -150,7 +150,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47436 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47437 nfsi->attrtimeo_timestamp = jiffies;
47438
47439 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47440 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47441 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47442 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47443 else
47444 @@ -1002,16 +1002,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47445 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47446 }
47447
47448 -static atomic_long_t nfs_attr_generation_counter;
47449 +static atomic_long_unchecked_t nfs_attr_generation_counter;
47450
47451 static unsigned long nfs_read_attr_generation_counter(void)
47452 {
47453 - return atomic_long_read(&nfs_attr_generation_counter);
47454 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47455 }
47456
47457 unsigned long nfs_inc_attr_generation_counter(void)
47458 {
47459 - return atomic_long_inc_return(&nfs_attr_generation_counter);
47460 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47461 }
47462
47463 void nfs_fattr_init(struct nfs_fattr *fattr)
47464 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47465 index 7a2e442..8e544cc 100644
47466 --- a/fs/nfsd/vfs.c
47467 +++ b/fs/nfsd/vfs.c
47468 @@ -914,7 +914,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47469 } else {
47470 oldfs = get_fs();
47471 set_fs(KERNEL_DS);
47472 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47473 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47474 set_fs(oldfs);
47475 }
47476
47477 @@ -1018,7 +1018,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47478
47479 /* Write the data. */
47480 oldfs = get_fs(); set_fs(KERNEL_DS);
47481 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47482 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47483 set_fs(oldfs);
47484 if (host_err < 0)
47485 goto out_nfserr;
47486 @@ -1553,7 +1553,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47487 */
47488
47489 oldfs = get_fs(); set_fs(KERNEL_DS);
47490 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
47491 + host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
47492 set_fs(oldfs);
47493
47494 if (host_err < 0)
47495 diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c
47496 index d327140..501b7f8 100644
47497 --- a/fs/nilfs2/the_nilfs.c
47498 +++ b/fs/nilfs2/the_nilfs.c
47499 @@ -409,6 +409,12 @@ static int nilfs_store_disk_layout(struct the_nilfs *nilfs,
47500 nilfs->ns_first_data_block = le64_to_cpu(sbp->s_first_data_block);
47501 nilfs->ns_r_segments_percentage =
47502 le32_to_cpu(sbp->s_r_segments_percentage);
47503 + if (nilfs->ns_r_segments_percentage < 1 ||
47504 + nilfs->ns_r_segments_percentage > 99) {
47505 + printk(KERN_ERR "NILFS: invalid reserved segments percentage.\n");
47506 + return -EINVAL;
47507 + }
47508 +
47509 nilfs_set_nsegments(nilfs, le64_to_cpu(sbp->s_nsegments));
47510 nilfs->ns_crc_seed = le32_to_cpu(sbp->s_crc_seed);
47511 return 0;
47512 @@ -515,6 +521,7 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs,
47513 brelse(sbh[1]);
47514 sbh[1] = NULL;
47515 sbp[1] = NULL;
47516 + valid[1] = 0;
47517 swp = 0;
47518 }
47519 if (!valid[swp]) {
47520 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47521 index 9fde1c0..14e8827 100644
47522 --- a/fs/notify/fanotify/fanotify_user.c
47523 +++ b/fs/notify/fanotify/fanotify_user.c
47524 @@ -276,7 +276,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47525 goto out_close_fd;
47526
47527 ret = -EFAULT;
47528 - if (copy_to_user(buf, &fanotify_event_metadata,
47529 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47530 + copy_to_user(buf, &fanotify_event_metadata,
47531 fanotify_event_metadata.event_len))
47532 goto out_kill_access_response;
47533
47534 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47535 index ee18815..7aa5d01 100644
47536 --- a/fs/notify/notification.c
47537 +++ b/fs/notify/notification.c
47538 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47539 * get set to 0 so it will never get 'freed'
47540 */
47541 static struct fsnotify_event *q_overflow_event;
47542 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47543 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47544
47545 /**
47546 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47547 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47548 */
47549 u32 fsnotify_get_cookie(void)
47550 {
47551 - return atomic_inc_return(&fsnotify_sync_cookie);
47552 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47553 }
47554 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47555
47556 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47557 index 99e3610..02c1068 100644
47558 --- a/fs/ntfs/dir.c
47559 +++ b/fs/ntfs/dir.c
47560 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
47561 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47562 ~(s64)(ndir->itype.index.block_size - 1)));
47563 /* Bounds checks. */
47564 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47565 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47566 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47567 "inode 0x%lx or driver bug.", vdir->i_ino);
47568 goto err_out;
47569 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47570 index c587e2d..3641eaa 100644
47571 --- a/fs/ntfs/file.c
47572 +++ b/fs/ntfs/file.c
47573 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47574 #endif /* NTFS_RW */
47575 };
47576
47577 -const struct file_operations ntfs_empty_file_ops = {};
47578 +const struct file_operations ntfs_empty_file_ops __read_only;
47579
47580 -const struct inode_operations ntfs_empty_inode_ops = {};
47581 +const struct inode_operations ntfs_empty_inode_ops __read_only;
47582 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47583 index 210c352..a174f83 100644
47584 --- a/fs/ocfs2/localalloc.c
47585 +++ b/fs/ocfs2/localalloc.c
47586 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47587 goto bail;
47588 }
47589
47590 - atomic_inc(&osb->alloc_stats.moves);
47591 + atomic_inc_unchecked(&osb->alloc_stats.moves);
47592
47593 bail:
47594 if (handle)
47595 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47596 index d355e6e..578d905 100644
47597 --- a/fs/ocfs2/ocfs2.h
47598 +++ b/fs/ocfs2/ocfs2.h
47599 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
47600
47601 struct ocfs2_alloc_stats
47602 {
47603 - atomic_t moves;
47604 - atomic_t local_data;
47605 - atomic_t bitmap_data;
47606 - atomic_t bg_allocs;
47607 - atomic_t bg_extends;
47608 + atomic_unchecked_t moves;
47609 + atomic_unchecked_t local_data;
47610 + atomic_unchecked_t bitmap_data;
47611 + atomic_unchecked_t bg_allocs;
47612 + atomic_unchecked_t bg_extends;
47613 };
47614
47615 enum ocfs2_local_alloc_state
47616 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47617 index ba5d97e..c77db25 100644
47618 --- a/fs/ocfs2/suballoc.c
47619 +++ b/fs/ocfs2/suballoc.c
47620 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47621 mlog_errno(status);
47622 goto bail;
47623 }
47624 - atomic_inc(&osb->alloc_stats.bg_extends);
47625 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47626
47627 /* You should never ask for this much metadata */
47628 BUG_ON(bits_wanted >
47629 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47630 mlog_errno(status);
47631 goto bail;
47632 }
47633 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47634 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47635
47636 *suballoc_loc = res.sr_bg_blkno;
47637 *suballoc_bit_start = res.sr_bit_offset;
47638 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47639 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47640 res->sr_bits);
47641
47642 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47643 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47644
47645 BUG_ON(res->sr_bits != 1);
47646
47647 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47648 mlog_errno(status);
47649 goto bail;
47650 }
47651 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47652 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47653
47654 BUG_ON(res.sr_bits != 1);
47655
47656 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47657 cluster_start,
47658 num_clusters);
47659 if (!status)
47660 - atomic_inc(&osb->alloc_stats.local_data);
47661 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
47662 } else {
47663 if (min_clusters > (osb->bitmap_cpg - 1)) {
47664 /* The only paths asking for contiguousness
47665 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47666 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47667 res.sr_bg_blkno,
47668 res.sr_bit_offset);
47669 - atomic_inc(&osb->alloc_stats.bitmap_data);
47670 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47671 *num_clusters = res.sr_bits;
47672 }
47673 }
47674 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47675 index 4994f8b..eaab8eb 100644
47676 --- a/fs/ocfs2/super.c
47677 +++ b/fs/ocfs2/super.c
47678 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47679 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47680 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47681 "Stats",
47682 - atomic_read(&osb->alloc_stats.bitmap_data),
47683 - atomic_read(&osb->alloc_stats.local_data),
47684 - atomic_read(&osb->alloc_stats.bg_allocs),
47685 - atomic_read(&osb->alloc_stats.moves),
47686 - atomic_read(&osb->alloc_stats.bg_extends));
47687 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47688 + atomic_read_unchecked(&osb->alloc_stats.local_data),
47689 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47690 + atomic_read_unchecked(&osb->alloc_stats.moves),
47691 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47692
47693 out += snprintf(buf + out, len - out,
47694 "%10s => State: %u Descriptor: %llu Size: %u bits "
47695 @@ -2119,11 +2119,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47696 spin_lock_init(&osb->osb_xattr_lock);
47697 ocfs2_init_steal_slots(osb);
47698
47699 - atomic_set(&osb->alloc_stats.moves, 0);
47700 - atomic_set(&osb->alloc_stats.local_data, 0);
47701 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
47702 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
47703 - atomic_set(&osb->alloc_stats.bg_extends, 0);
47704 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47705 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47706 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47707 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47708 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47709
47710 /* Copy the blockcheck stats from the superblock probe */
47711 osb->osb_ecc_stats = *stats;
47712 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
47713 index 5d22872..523db20 100644
47714 --- a/fs/ocfs2/symlink.c
47715 +++ b/fs/ocfs2/symlink.c
47716 @@ -142,7 +142,7 @@ bail:
47717
47718 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47719 {
47720 - char *link = nd_get_link(nd);
47721 + const char *link = nd_get_link(nd);
47722 if (!IS_ERR(link))
47723 kfree(link);
47724 }
47725 diff --git a/fs/open.c b/fs/open.c
47726 index 22c41b5..78894cf 100644
47727 --- a/fs/open.c
47728 +++ b/fs/open.c
47729 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47730 error = locks_verify_truncate(inode, NULL, length);
47731 if (!error)
47732 error = security_path_truncate(&path);
47733 +
47734 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47735 + error = -EACCES;
47736 +
47737 if (!error)
47738 error = do_truncate(path.dentry, length, 0, NULL);
47739
47740 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47741 if (__mnt_is_readonly(path.mnt))
47742 res = -EROFS;
47743
47744 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47745 + res = -EACCES;
47746 +
47747 out_path_release:
47748 path_put(&path);
47749 out:
47750 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47751 if (error)
47752 goto dput_and_out;
47753
47754 + gr_log_chdir(path.dentry, path.mnt);
47755 +
47756 set_fs_pwd(current->fs, &path);
47757
47758 dput_and_out:
47759 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47760 goto out_putf;
47761
47762 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47763 +
47764 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47765 + error = -EPERM;
47766 +
47767 + if (!error)
47768 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47769 +
47770 if (!error)
47771 set_fs_pwd(current->fs, &file->f_path);
47772 out_putf:
47773 @@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47774 if (error)
47775 goto dput_and_out;
47776
47777 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47778 + goto dput_and_out;
47779 +
47780 set_fs_root(current->fs, &path);
47781 +
47782 + gr_handle_chroot_chdir(&path);
47783 +
47784 error = 0;
47785 dput_and_out:
47786 path_put(&path);
47787 @@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
47788 if (error)
47789 return error;
47790 mutex_lock(&inode->i_mutex);
47791 +
47792 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47793 + error = -EACCES;
47794 + goto out_unlock;
47795 + }
47796 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47797 + error = -EACCES;
47798 + goto out_unlock;
47799 + }
47800 +
47801 error = security_path_chmod(path->dentry, path->mnt, mode);
47802 if (error)
47803 goto out_unlock;
47804 @@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47805 int error;
47806 struct iattr newattrs;
47807
47808 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
47809 + return -EACCES;
47810 +
47811 newattrs.ia_valid = ATTR_CTIME;
47812 if (user != (uid_t) -1) {
47813 newattrs.ia_valid |= ATTR_UID;
47814 diff --git a/fs/partitions/efi.c b/fs/partitions/efi.c
47815 index 6296b40..417c00f 100644
47816 --- a/fs/partitions/efi.c
47817 +++ b/fs/partitions/efi.c
47818 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
47819 if (!gpt)
47820 return NULL;
47821
47822 + if (!le32_to_cpu(gpt->num_partition_entries))
47823 + return NULL;
47824 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
47825 + if (!pte)
47826 + return NULL;
47827 +
47828 count = le32_to_cpu(gpt->num_partition_entries) *
47829 le32_to_cpu(gpt->sizeof_partition_entry);
47830 - if (!count)
47831 - return NULL;
47832 - pte = kzalloc(count, GFP_KERNEL);
47833 - if (!pte)
47834 - return NULL;
47835 -
47836 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
47837 (u8 *) pte,
47838 count) < count) {
47839 diff --git a/fs/partitions/ldm.c b/fs/partitions/ldm.c
47840 index bd8ae78..539d250 100644
47841 --- a/fs/partitions/ldm.c
47842 +++ b/fs/partitions/ldm.c
47843 @@ -1324,7 +1324,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
47844 goto found;
47845 }
47846
47847 - f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
47848 + f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
47849 if (!f) {
47850 ldm_crit ("Out of memory.");
47851 return false;
47852 diff --git a/fs/pipe.c b/fs/pipe.c
47853 index 4065f07..68c0706 100644
47854 --- a/fs/pipe.c
47855 +++ b/fs/pipe.c
47856 @@ -420,9 +420,9 @@ redo:
47857 }
47858 if (bufs) /* More to do? */
47859 continue;
47860 - if (!pipe->writers)
47861 + if (!atomic_read(&pipe->writers))
47862 break;
47863 - if (!pipe->waiting_writers) {
47864 + if (!atomic_read(&pipe->waiting_writers)) {
47865 /* syscall merging: Usually we must not sleep
47866 * if O_NONBLOCK is set, or if we got some data.
47867 * But if a writer sleeps in kernel space, then
47868 @@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47869 mutex_lock(&inode->i_mutex);
47870 pipe = inode->i_pipe;
47871
47872 - if (!pipe->readers) {
47873 + if (!atomic_read(&pipe->readers)) {
47874 send_sig(SIGPIPE, current, 0);
47875 ret = -EPIPE;
47876 goto out;
47877 @@ -530,7 +530,7 @@ redo1:
47878 for (;;) {
47879 int bufs;
47880
47881 - if (!pipe->readers) {
47882 + if (!atomic_read(&pipe->readers)) {
47883 send_sig(SIGPIPE, current, 0);
47884 if (!ret)
47885 ret = -EPIPE;
47886 @@ -616,9 +616,9 @@ redo2:
47887 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47888 do_wakeup = 0;
47889 }
47890 - pipe->waiting_writers++;
47891 + atomic_inc(&pipe->waiting_writers);
47892 pipe_wait(pipe);
47893 - pipe->waiting_writers--;
47894 + atomic_dec(&pipe->waiting_writers);
47895 }
47896 out:
47897 mutex_unlock(&inode->i_mutex);
47898 @@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47899 mask = 0;
47900 if (filp->f_mode & FMODE_READ) {
47901 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
47902 - if (!pipe->writers && filp->f_version != pipe->w_counter)
47903 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
47904 mask |= POLLHUP;
47905 }
47906
47907 @@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47908 * Most Unices do not set POLLERR for FIFOs but on Linux they
47909 * behave exactly like pipes for poll().
47910 */
47911 - if (!pipe->readers)
47912 + if (!atomic_read(&pipe->readers))
47913 mask |= POLLERR;
47914 }
47915
47916 @@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int decr, int decw)
47917
47918 mutex_lock(&inode->i_mutex);
47919 pipe = inode->i_pipe;
47920 - pipe->readers -= decr;
47921 - pipe->writers -= decw;
47922 + atomic_sub(decr, &pipe->readers);
47923 + atomic_sub(decw, &pipe->writers);
47924
47925 - if (!pipe->readers && !pipe->writers) {
47926 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
47927 free_pipe_info(inode);
47928 } else {
47929 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
47930 @@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
47931
47932 if (inode->i_pipe) {
47933 ret = 0;
47934 - inode->i_pipe->readers++;
47935 + atomic_inc(&inode->i_pipe->readers);
47936 }
47937
47938 mutex_unlock(&inode->i_mutex);
47939 @@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
47940
47941 if (inode->i_pipe) {
47942 ret = 0;
47943 - inode->i_pipe->writers++;
47944 + atomic_inc(&inode->i_pipe->writers);
47945 }
47946
47947 mutex_unlock(&inode->i_mutex);
47948 @@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
47949 if (inode->i_pipe) {
47950 ret = 0;
47951 if (filp->f_mode & FMODE_READ)
47952 - inode->i_pipe->readers++;
47953 + atomic_inc(&inode->i_pipe->readers);
47954 if (filp->f_mode & FMODE_WRITE)
47955 - inode->i_pipe->writers++;
47956 + atomic_inc(&inode->i_pipe->writers);
47957 }
47958
47959 mutex_unlock(&inode->i_mutex);
47960 @@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
47961 inode->i_pipe = NULL;
47962 }
47963
47964 -static struct vfsmount *pipe_mnt __read_mostly;
47965 +struct vfsmount *pipe_mnt __read_mostly;
47966
47967 /*
47968 * pipefs_dname() is called from d_path().
47969 @@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(void)
47970 goto fail_iput;
47971 inode->i_pipe = pipe;
47972
47973 - pipe->readers = pipe->writers = 1;
47974 + atomic_set(&pipe->readers, 1);
47975 + atomic_set(&pipe->writers, 1);
47976 inode->i_fop = &rdwr_pipefifo_fops;
47977
47978 /*
47979 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
47980 index 15af622..0e9f4467 100644
47981 --- a/fs/proc/Kconfig
47982 +++ b/fs/proc/Kconfig
47983 @@ -30,12 +30,12 @@ config PROC_FS
47984
47985 config PROC_KCORE
47986 bool "/proc/kcore support" if !ARM
47987 - depends on PROC_FS && MMU
47988 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
47989
47990 config PROC_VMCORE
47991 bool "/proc/vmcore support"
47992 - depends on PROC_FS && CRASH_DUMP
47993 - default y
47994 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
47995 + default n
47996 help
47997 Exports the dump image of crashed kernel in ELF format.
47998
47999 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48000 limited in memory.
48001
48002 config PROC_PAGE_MONITOR
48003 - default y
48004 - depends on PROC_FS && MMU
48005 + default n
48006 + depends on PROC_FS && MMU && !GRKERNSEC
48007 bool "Enable /proc page monitoring" if EXPERT
48008 help
48009 Various /proc files exist to monitor process memory utilization:
48010 diff --git a/fs/proc/array.c b/fs/proc/array.c
48011 index 3a1dafd..bf1bd84 100644
48012 --- a/fs/proc/array.c
48013 +++ b/fs/proc/array.c
48014 @@ -60,6 +60,7 @@
48015 #include <linux/tty.h>
48016 #include <linux/string.h>
48017 #include <linux/mman.h>
48018 +#include <linux/grsecurity.h>
48019 #include <linux/proc_fs.h>
48020 #include <linux/ioport.h>
48021 #include <linux/uaccess.h>
48022 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48023 seq_putc(m, '\n');
48024 }
48025
48026 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48027 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48028 +{
48029 + if (p->mm)
48030 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48031 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48032 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48033 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48034 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48035 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48036 + else
48037 + seq_printf(m, "PaX:\t-----\n");
48038 +}
48039 +#endif
48040 +
48041 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48042 struct pid *pid, struct task_struct *task)
48043 {
48044 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48045 task_cpus_allowed(m, task);
48046 cpuset_task_status_allowed(m, task);
48047 task_context_switch_counts(m, task);
48048 +
48049 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48050 + task_pax(m, task);
48051 +#endif
48052 +
48053 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48054 + task_grsec_rbac(m, task);
48055 +#endif
48056 +
48057 return 0;
48058 }
48059
48060 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48061 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48062 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48063 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48064 +#endif
48065 +
48066 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48067 struct pid *pid, struct task_struct *task, int whole)
48068 {
48069 @@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48070 char tcomm[sizeof(task->comm)];
48071 unsigned long flags;
48072
48073 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48074 + if (current->exec_id != m->exec_id) {
48075 + gr_log_badprocpid("stat");
48076 + return 0;
48077 + }
48078 +#endif
48079 +
48080 state = *get_task_state(task);
48081 vsize = eip = esp = 0;
48082 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
48083 @@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48084 gtime = task->gtime;
48085 }
48086
48087 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48088 + if (PAX_RAND_FLAGS(mm)) {
48089 + eip = 0;
48090 + esp = 0;
48091 + wchan = 0;
48092 + }
48093 +#endif
48094 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48095 + wchan = 0;
48096 + eip =0;
48097 + esp =0;
48098 +#endif
48099 +
48100 /* scale priority and nice values from timeslices to -20..20 */
48101 /* to make it look like a "normal" Unix priority/nice value */
48102 priority = task_prio(task);
48103 @@ -489,9 +540,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48104 vsize,
48105 mm ? get_mm_rss(mm) : 0,
48106 rsslim,
48107 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48108 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
48109 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
48110 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
48111 +#else
48112 mm ? (permitted ? mm->start_code : 1) : 0,
48113 mm ? (permitted ? mm->end_code : 1) : 0,
48114 (permitted && mm) ? mm->start_stack : 0,
48115 +#endif
48116 esp,
48117 eip,
48118 /* The signal information here is obsolete.
48119 @@ -533,8 +590,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48120 struct pid *pid, struct task_struct *task)
48121 {
48122 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48123 - struct mm_struct *mm = get_task_mm(task);
48124 + struct mm_struct *mm;
48125
48126 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48127 + if (current->exec_id != m->exec_id) {
48128 + gr_log_badprocpid("statm");
48129 + return 0;
48130 + }
48131 +#endif
48132 + mm = get_task_mm(task);
48133 if (mm) {
48134 size = task_statm(mm, &shared, &text, &data, &resident);
48135 mmput(mm);
48136 @@ -544,3 +608,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48137
48138 return 0;
48139 }
48140 +
48141 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48142 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48143 +{
48144 + u32 curr_ip = 0;
48145 + unsigned long flags;
48146 +
48147 + if (lock_task_sighand(task, &flags)) {
48148 + curr_ip = task->signal->curr_ip;
48149 + unlock_task_sighand(task, &flags);
48150 + }
48151 +
48152 + return sprintf(buffer, "%pI4\n", &curr_ip);
48153 +}
48154 +#endif
48155 diff --git a/fs/proc/base.c b/fs/proc/base.c
48156 index 1ace83d..f5e575d 100644
48157 --- a/fs/proc/base.c
48158 +++ b/fs/proc/base.c
48159 @@ -107,6 +107,22 @@ struct pid_entry {
48160 union proc_op op;
48161 };
48162
48163 +struct getdents_callback {
48164 + struct linux_dirent __user * current_dir;
48165 + struct linux_dirent __user * previous;
48166 + struct file * file;
48167 + int count;
48168 + int error;
48169 +};
48170 +
48171 +static int gr_fake_filldir(void * __buf, const char *name, int namlen,
48172 + loff_t offset, u64 ino, unsigned int d_type)
48173 +{
48174 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
48175 + buf->error = -EINVAL;
48176 + return 0;
48177 +}
48178 +
48179 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48180 .name = (NAME), \
48181 .len = sizeof(NAME) - 1, \
48182 @@ -194,26 +210,6 @@ static int proc_root_link(struct inode *inode, struct path *path)
48183 return result;
48184 }
48185
48186 -static struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
48187 -{
48188 - struct mm_struct *mm;
48189 - int err;
48190 -
48191 - err = mutex_lock_killable(&task->signal->cred_guard_mutex);
48192 - if (err)
48193 - return ERR_PTR(err);
48194 -
48195 - mm = get_task_mm(task);
48196 - if (mm && mm != current->mm &&
48197 - !ptrace_may_access(task, mode)) {
48198 - mmput(mm);
48199 - mm = ERR_PTR(-EACCES);
48200 - }
48201 - mutex_unlock(&task->signal->cred_guard_mutex);
48202 -
48203 - return mm;
48204 -}
48205 -
48206 struct mm_struct *mm_for_maps(struct task_struct *task)
48207 {
48208 return mm_access(task, PTRACE_MODE_READ);
48209 @@ -229,6 +225,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48210 if (!mm->arg_end)
48211 goto out_mm; /* Shh! No looking before we're done */
48212
48213 + if (gr_acl_handle_procpidmem(task))
48214 + goto out_mm;
48215 +
48216 len = mm->arg_end - mm->arg_start;
48217
48218 if (len > PAGE_SIZE)
48219 @@ -256,12 +255,28 @@ out:
48220 return res;
48221 }
48222
48223 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48224 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48225 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48226 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48227 +#endif
48228 +
48229 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48230 {
48231 struct mm_struct *mm = mm_for_maps(task);
48232 int res = PTR_ERR(mm);
48233 if (mm && !IS_ERR(mm)) {
48234 unsigned int nwords = 0;
48235 +
48236 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48237 + /* allow if we're currently ptracing this task */
48238 + if (PAX_RAND_FLAGS(mm) &&
48239 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48240 + mmput(mm);
48241 + return 0;
48242 + }
48243 +#endif
48244 +
48245 do {
48246 nwords += 2;
48247 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48248 @@ -275,7 +290,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48249 }
48250
48251
48252 -#ifdef CONFIG_KALLSYMS
48253 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48254 /*
48255 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48256 * Returns the resolved symbol. If that fails, simply return the address.
48257 @@ -314,7 +329,7 @@ static void unlock_trace(struct task_struct *task)
48258 mutex_unlock(&task->signal->cred_guard_mutex);
48259 }
48260
48261 -#ifdef CONFIG_STACKTRACE
48262 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48263
48264 #define MAX_STACK_TRACE_DEPTH 64
48265
48266 @@ -505,7 +520,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48267 return count;
48268 }
48269
48270 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48271 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48272 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48273 {
48274 long nr;
48275 @@ -534,7 +549,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48276 /************************************************************************/
48277
48278 /* permission checks */
48279 -static int proc_fd_access_allowed(struct inode *inode)
48280 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48281 {
48282 struct task_struct *task;
48283 int allowed = 0;
48284 @@ -544,7 +559,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48285 */
48286 task = get_proc_task(inode);
48287 if (task) {
48288 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48289 + if (log)
48290 + allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
48291 + else
48292 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48293 put_task_struct(task);
48294 }
48295 return allowed;
48296 @@ -786,6 +804,10 @@ static int mem_open(struct inode* inode, struct file* file)
48297 file->f_mode |= FMODE_UNSIGNED_OFFSET;
48298 file->private_data = mm;
48299
48300 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48301 + file->f_version = current->exec_id;
48302 +#endif
48303 +
48304 return 0;
48305 }
48306
48307 @@ -797,6 +819,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
48308 ssize_t copied;
48309 char *page;
48310
48311 +#ifdef CONFIG_GRKERNSEC
48312 + if (write)
48313 + return -EPERM;
48314 +#endif
48315 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48316 + if (file->f_version != current->exec_id) {
48317 + gr_log_badprocpid("mem");
48318 + return 0;
48319 + }
48320 +#endif
48321 +
48322 if (!mm)
48323 return 0;
48324
48325 @@ -897,6 +930,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48326 if (!task)
48327 goto out_no_task;
48328
48329 + if (gr_acl_handle_procpidmem(task))
48330 + goto out;
48331 +
48332 ret = -ENOMEM;
48333 page = (char *)__get_free_page(GFP_TEMPORARY);
48334 if (!page)
48335 @@ -1519,7 +1555,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48336 path_put(&nd->path);
48337
48338 /* Are we allowed to snoop on the tasks file descriptors? */
48339 - if (!proc_fd_access_allowed(inode))
48340 + if (!proc_fd_access_allowed(inode,0))
48341 goto out;
48342
48343 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
48344 @@ -1558,8 +1594,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48345 struct path path;
48346
48347 /* Are we allowed to snoop on the tasks file descriptors? */
48348 - if (!proc_fd_access_allowed(inode))
48349 - goto out;
48350 + /* logging this is needed for learning on chromium to work properly,
48351 + but we don't want to flood the logs from 'ps' which does a readlink
48352 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48353 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
48354 + */
48355 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48356 + if (!proc_fd_access_allowed(inode,0))
48357 + goto out;
48358 + } else {
48359 + if (!proc_fd_access_allowed(inode,1))
48360 + goto out;
48361 + }
48362
48363 error = PROC_I(inode)->op.proc_get_link(inode, &path);
48364 if (error)
48365 @@ -1624,7 +1670,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48366 rcu_read_lock();
48367 cred = __task_cred(task);
48368 inode->i_uid = cred->euid;
48369 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48370 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48371 +#else
48372 inode->i_gid = cred->egid;
48373 +#endif
48374 rcu_read_unlock();
48375 }
48376 security_task_to_inode(task, inode);
48377 @@ -1642,6 +1692,9 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48378 struct inode *inode = dentry->d_inode;
48379 struct task_struct *task;
48380 const struct cred *cred;
48381 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48382 + const struct cred *tmpcred = current_cred();
48383 +#endif
48384
48385 generic_fillattr(inode, stat);
48386
48387 @@ -1649,13 +1702,41 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48388 stat->uid = 0;
48389 stat->gid = 0;
48390 task = pid_task(proc_pid(inode), PIDTYPE_PID);
48391 +
48392 + if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
48393 + rcu_read_unlock();
48394 + return -ENOENT;
48395 + }
48396 +
48397 if (task) {
48398 + cred = __task_cred(task);
48399 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48400 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48401 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48402 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48403 +#endif
48404 + ) {
48405 +#endif
48406 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48407 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48408 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48409 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48410 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48411 +#endif
48412 task_dumpable(task)) {
48413 - cred = __task_cred(task);
48414 stat->uid = cred->euid;
48415 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48416 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48417 +#else
48418 stat->gid = cred->egid;
48419 +#endif
48420 }
48421 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48422 + } else {
48423 + rcu_read_unlock();
48424 + return -ENOENT;
48425 + }
48426 +#endif
48427 }
48428 rcu_read_unlock();
48429 return 0;
48430 @@ -1692,11 +1773,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48431
48432 if (task) {
48433 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48434 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48435 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48436 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48437 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48438 +#endif
48439 task_dumpable(task)) {
48440 rcu_read_lock();
48441 cred = __task_cred(task);
48442 inode->i_uid = cred->euid;
48443 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48444 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48445 +#else
48446 inode->i_gid = cred->egid;
48447 +#endif
48448 rcu_read_unlock();
48449 } else {
48450 inode->i_uid = 0;
48451 @@ -1814,7 +1904,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48452 int fd = proc_fd(inode);
48453
48454 if (task) {
48455 - files = get_files_struct(task);
48456 + if (!gr_acl_handle_procpidmem(task))
48457 + files = get_files_struct(task);
48458 put_task_struct(task);
48459 }
48460 if (files) {
48461 @@ -2082,11 +2173,21 @@ static const struct file_operations proc_fd_operations = {
48462 */
48463 static int proc_fd_permission(struct inode *inode, int mask)
48464 {
48465 + struct task_struct *task;
48466 int rv = generic_permission(inode, mask);
48467 - if (rv == 0)
48468 - return 0;
48469 +
48470 if (task_pid(current) == proc_pid(inode))
48471 rv = 0;
48472 +
48473 + task = get_proc_task(inode);
48474 + if (task == NULL)
48475 + return rv;
48476 +
48477 + if (gr_acl_handle_procpidmem(task))
48478 + rv = -EACCES;
48479 +
48480 + put_task_struct(task);
48481 +
48482 return rv;
48483 }
48484
48485 @@ -2196,6 +2297,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48486 if (!task)
48487 goto out_no_task;
48488
48489 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48490 + goto out;
48491 +
48492 /*
48493 * Yes, it does not scale. And it should not. Don't add
48494 * new entries into /proc/<tgid>/ without very good reasons.
48495 @@ -2240,6 +2344,9 @@ static int proc_pident_readdir(struct file *filp,
48496 if (!task)
48497 goto out_no_task;
48498
48499 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48500 + goto out;
48501 +
48502 ret = 0;
48503 i = filp->f_pos;
48504 switch (i) {
48505 @@ -2510,7 +2617,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48506 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48507 void *cookie)
48508 {
48509 - char *s = nd_get_link(nd);
48510 + const char *s = nd_get_link(nd);
48511 if (!IS_ERR(s))
48512 __putname(s);
48513 }
48514 @@ -2708,7 +2815,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48515 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48516 #endif
48517 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48518 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48519 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48520 INF("syscall", S_IRUGO, proc_pid_syscall),
48521 #endif
48522 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48523 @@ -2733,10 +2840,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48524 #ifdef CONFIG_SECURITY
48525 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48526 #endif
48527 -#ifdef CONFIG_KALLSYMS
48528 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48529 INF("wchan", S_IRUGO, proc_pid_wchan),
48530 #endif
48531 -#ifdef CONFIG_STACKTRACE
48532 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48533 ONE("stack", S_IRUGO, proc_pid_stack),
48534 #endif
48535 #ifdef CONFIG_SCHEDSTATS
48536 @@ -2770,6 +2877,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48537 #ifdef CONFIG_HARDWALL
48538 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48539 #endif
48540 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48541 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48542 +#endif
48543 };
48544
48545 static int proc_tgid_base_readdir(struct file * filp,
48546 @@ -2895,7 +3005,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48547 if (!inode)
48548 goto out;
48549
48550 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48551 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48552 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48553 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48554 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48555 +#else
48556 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48557 +#endif
48558 inode->i_op = &proc_tgid_base_inode_operations;
48559 inode->i_fop = &proc_tgid_base_operations;
48560 inode->i_flags|=S_IMMUTABLE;
48561 @@ -2937,7 +3054,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48562 if (!task)
48563 goto out;
48564
48565 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48566 + goto out_put_task;
48567 +
48568 result = proc_pid_instantiate(dir, dentry, task, NULL);
48569 +out_put_task:
48570 put_task_struct(task);
48571 out:
48572 return result;
48573 @@ -3002,6 +3123,11 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
48574 {
48575 unsigned int nr;
48576 struct task_struct *reaper;
48577 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48578 + const struct cred *tmpcred = current_cred();
48579 + const struct cred *itercred;
48580 +#endif
48581 + filldir_t __filldir = filldir;
48582 struct tgid_iter iter;
48583 struct pid_namespace *ns;
48584
48585 @@ -3025,8 +3151,27 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
48586 for (iter = next_tgid(ns, iter);
48587 iter.task;
48588 iter.tgid += 1, iter = next_tgid(ns, iter)) {
48589 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48590 + rcu_read_lock();
48591 + itercred = __task_cred(iter.task);
48592 +#endif
48593 + if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
48594 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48595 + || (tmpcred->uid && (itercred->uid != tmpcred->uid)
48596 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48597 + && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48598 +#endif
48599 + )
48600 +#endif
48601 + )
48602 + __filldir = &gr_fake_filldir;
48603 + else
48604 + __filldir = filldir;
48605 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48606 + rcu_read_unlock();
48607 +#endif
48608 filp->f_pos = iter.tgid + TGID_OFFSET;
48609 - if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
48610 + if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
48611 put_task_struct(iter.task);
48612 goto out;
48613 }
48614 @@ -3054,7 +3199,7 @@ static const struct pid_entry tid_base_stuff[] = {
48615 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48616 #endif
48617 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48618 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48619 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48620 INF("syscall", S_IRUGO, proc_pid_syscall),
48621 #endif
48622 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48623 @@ -3078,10 +3223,10 @@ static const struct pid_entry tid_base_stuff[] = {
48624 #ifdef CONFIG_SECURITY
48625 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48626 #endif
48627 -#ifdef CONFIG_KALLSYMS
48628 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48629 INF("wchan", S_IRUGO, proc_pid_wchan),
48630 #endif
48631 -#ifdef CONFIG_STACKTRACE
48632 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48633 ONE("stack", S_IRUGO, proc_pid_stack),
48634 #endif
48635 #ifdef CONFIG_SCHEDSTATS
48636 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48637 index 82676e3..5f8518a 100644
48638 --- a/fs/proc/cmdline.c
48639 +++ b/fs/proc/cmdline.c
48640 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48641
48642 static int __init proc_cmdline_init(void)
48643 {
48644 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48645 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48646 +#else
48647 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48648 +#endif
48649 return 0;
48650 }
48651 module_init(proc_cmdline_init);
48652 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48653 index b143471..bb105e5 100644
48654 --- a/fs/proc/devices.c
48655 +++ b/fs/proc/devices.c
48656 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48657
48658 static int __init proc_devices_init(void)
48659 {
48660 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48661 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48662 +#else
48663 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48664 +#endif
48665 return 0;
48666 }
48667 module_init(proc_devices_init);
48668 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48669 index 7737c54..7172574 100644
48670 --- a/fs/proc/inode.c
48671 +++ b/fs/proc/inode.c
48672 @@ -18,12 +18,18 @@
48673 #include <linux/module.h>
48674 #include <linux/sysctl.h>
48675 #include <linux/slab.h>
48676 +#include <linux/grsecurity.h>
48677
48678 #include <asm/system.h>
48679 #include <asm/uaccess.h>
48680
48681 #include "internal.h"
48682
48683 +#ifdef CONFIG_PROC_SYSCTL
48684 +extern const struct inode_operations proc_sys_inode_operations;
48685 +extern const struct inode_operations proc_sys_dir_operations;
48686 +#endif
48687 +
48688 static void proc_evict_inode(struct inode *inode)
48689 {
48690 struct proc_dir_entry *de;
48691 @@ -49,6 +55,13 @@ static void proc_evict_inode(struct inode *inode)
48692 ns_ops = PROC_I(inode)->ns_ops;
48693 if (ns_ops && ns_ops->put)
48694 ns_ops->put(PROC_I(inode)->ns);
48695 +
48696 +#ifdef CONFIG_PROC_SYSCTL
48697 + if (inode->i_op == &proc_sys_inode_operations ||
48698 + inode->i_op == &proc_sys_dir_operations)
48699 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48700 +#endif
48701 +
48702 }
48703
48704 static struct kmem_cache * proc_inode_cachep;
48705 @@ -440,7 +453,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48706 if (de->mode) {
48707 inode->i_mode = de->mode;
48708 inode->i_uid = de->uid;
48709 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48710 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48711 +#else
48712 inode->i_gid = de->gid;
48713 +#endif
48714 }
48715 if (de->size)
48716 inode->i_size = de->size;
48717 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48718 index 7838e5c..ff92cbc 100644
48719 --- a/fs/proc/internal.h
48720 +++ b/fs/proc/internal.h
48721 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48722 struct pid *pid, struct task_struct *task);
48723 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48724 struct pid *pid, struct task_struct *task);
48725 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48726 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48727 +#endif
48728 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48729
48730 extern const struct file_operations proc_maps_operations;
48731 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48732 index d245cb2..f4e8498 100644
48733 --- a/fs/proc/kcore.c
48734 +++ b/fs/proc/kcore.c
48735 @@ -478,9 +478,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48736 * the addresses in the elf_phdr on our list.
48737 */
48738 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48739 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48740 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48741 + if (tsz > buflen)
48742 tsz = buflen;
48743 -
48744 +
48745 while (buflen) {
48746 struct kcore_list *m;
48747
48748 @@ -509,20 +510,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48749 kfree(elf_buf);
48750 } else {
48751 if (kern_addr_valid(start)) {
48752 - unsigned long n;
48753 + char *elf_buf;
48754 + mm_segment_t oldfs;
48755
48756 - n = copy_to_user(buffer, (char *)start, tsz);
48757 - /*
48758 - * We cannot distingush between fault on source
48759 - * and fault on destination. When this happens
48760 - * we clear too and hope it will trigger the
48761 - * EFAULT again.
48762 - */
48763 - if (n) {
48764 - if (clear_user(buffer + tsz - n,
48765 - n))
48766 + elf_buf = kmalloc(tsz, GFP_KERNEL);
48767 + if (!elf_buf)
48768 + return -ENOMEM;
48769 + oldfs = get_fs();
48770 + set_fs(KERNEL_DS);
48771 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48772 + set_fs(oldfs);
48773 + if (copy_to_user(buffer, elf_buf, tsz)) {
48774 + kfree(elf_buf);
48775 return -EFAULT;
48776 + }
48777 }
48778 + set_fs(oldfs);
48779 + kfree(elf_buf);
48780 } else {
48781 if (clear_user(buffer, tsz))
48782 return -EFAULT;
48783 @@ -542,6 +546,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48784
48785 static int open_kcore(struct inode *inode, struct file *filp)
48786 {
48787 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48788 + return -EPERM;
48789 +#endif
48790 if (!capable(CAP_SYS_RAWIO))
48791 return -EPERM;
48792 if (kcore_need_update)
48793 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48794 index 80e4645..53e5fcf 100644
48795 --- a/fs/proc/meminfo.c
48796 +++ b/fs/proc/meminfo.c
48797 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48798 vmi.used >> 10,
48799 vmi.largest_chunk >> 10
48800 #ifdef CONFIG_MEMORY_FAILURE
48801 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48802 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48803 #endif
48804 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48805 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48806 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48807 index b1822dd..df622cb 100644
48808 --- a/fs/proc/nommu.c
48809 +++ b/fs/proc/nommu.c
48810 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48811 if (len < 1)
48812 len = 1;
48813 seq_printf(m, "%*c", len, ' ');
48814 - seq_path(m, &file->f_path, "");
48815 + seq_path(m, &file->f_path, "\n\\");
48816 }
48817
48818 seq_putc(m, '\n');
48819 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48820 index f738024..876984a 100644
48821 --- a/fs/proc/proc_net.c
48822 +++ b/fs/proc/proc_net.c
48823 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48824 struct task_struct *task;
48825 struct nsproxy *ns;
48826 struct net *net = NULL;
48827 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48828 + const struct cred *cred = current_cred();
48829 +#endif
48830 +
48831 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48832 + if (cred->fsuid)
48833 + return net;
48834 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48835 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48836 + return net;
48837 +#endif
48838
48839 rcu_read_lock();
48840 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48841 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48842 index a6b6217..1e0579d 100644
48843 --- a/fs/proc/proc_sysctl.c
48844 +++ b/fs/proc/proc_sysctl.c
48845 @@ -9,11 +9,13 @@
48846 #include <linux/namei.h>
48847 #include "internal.h"
48848
48849 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
48850 +
48851 static const struct dentry_operations proc_sys_dentry_operations;
48852 static const struct file_operations proc_sys_file_operations;
48853 -static const struct inode_operations proc_sys_inode_operations;
48854 +const struct inode_operations proc_sys_inode_operations;
48855 static const struct file_operations proc_sys_dir_file_operations;
48856 -static const struct inode_operations proc_sys_dir_operations;
48857 +const struct inode_operations proc_sys_dir_operations;
48858
48859 void proc_sys_poll_notify(struct ctl_table_poll *poll)
48860 {
48861 @@ -131,8 +133,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48862
48863 err = NULL;
48864 d_set_d_op(dentry, &proc_sys_dentry_operations);
48865 +
48866 + gr_handle_proc_create(dentry, inode);
48867 +
48868 d_add(dentry, inode);
48869
48870 + if (gr_handle_sysctl(p, MAY_EXEC))
48871 + err = ERR_PTR(-ENOENT);
48872 +
48873 out:
48874 sysctl_head_finish(head);
48875 return err;
48876 @@ -163,6 +171,12 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48877 if (!table->proc_handler)
48878 goto out;
48879
48880 +#ifdef CONFIG_GRKERNSEC
48881 + error = -EPERM;
48882 + if (write && !capable(CAP_SYS_ADMIN))
48883 + goto out;
48884 +#endif
48885 +
48886 /* careful: calling conventions are nasty here */
48887 res = count;
48888 error = table->proc_handler(table, write, buf, &res, ppos);
48889 @@ -245,6 +259,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
48890 return -ENOMEM;
48891 } else {
48892 d_set_d_op(child, &proc_sys_dentry_operations);
48893 +
48894 + gr_handle_proc_create(child, inode);
48895 +
48896 d_add(child, inode);
48897 }
48898 } else {
48899 @@ -273,6 +290,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
48900 if (*pos < file->f_pos)
48901 continue;
48902
48903 + if (gr_handle_sysctl(table, 0))
48904 + continue;
48905 +
48906 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
48907 if (res)
48908 return res;
48909 @@ -398,6 +418,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
48910 if (IS_ERR(head))
48911 return PTR_ERR(head);
48912
48913 + if (table && gr_handle_sysctl(table, MAY_EXEC))
48914 + return -ENOENT;
48915 +
48916 generic_fillattr(inode, stat);
48917 if (table)
48918 stat->mode = (stat->mode & S_IFMT) | table->mode;
48919 @@ -420,13 +443,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
48920 .llseek = generic_file_llseek,
48921 };
48922
48923 -static const struct inode_operations proc_sys_inode_operations = {
48924 +const struct inode_operations proc_sys_inode_operations = {
48925 .permission = proc_sys_permission,
48926 .setattr = proc_sys_setattr,
48927 .getattr = proc_sys_getattr,
48928 };
48929
48930 -static const struct inode_operations proc_sys_dir_operations = {
48931 +const struct inode_operations proc_sys_dir_operations = {
48932 .lookup = proc_sys_lookup,
48933 .permission = proc_sys_permission,
48934 .setattr = proc_sys_setattr,
48935 diff --git a/fs/proc/root.c b/fs/proc/root.c
48936 index 03102d9..4ae347e 100644
48937 --- a/fs/proc/root.c
48938 +++ b/fs/proc/root.c
48939 @@ -121,7 +121,15 @@ void __init proc_root_init(void)
48940 #ifdef CONFIG_PROC_DEVICETREE
48941 proc_device_tree_init();
48942 #endif
48943 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48944 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48945 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
48946 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48947 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48948 +#endif
48949 +#else
48950 proc_mkdir("bus", NULL);
48951 +#endif
48952 proc_sys_init();
48953 }
48954
48955 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
48956 index 7dcd2a2..b2f410e 100644
48957 --- a/fs/proc/task_mmu.c
48958 +++ b/fs/proc/task_mmu.c
48959 @@ -11,6 +11,7 @@
48960 #include <linux/rmap.h>
48961 #include <linux/swap.h>
48962 #include <linux/swapops.h>
48963 +#include <linux/grsecurity.h>
48964
48965 #include <asm/elf.h>
48966 #include <asm/uaccess.h>
48967 @@ -52,8 +53,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48968 "VmExe:\t%8lu kB\n"
48969 "VmLib:\t%8lu kB\n"
48970 "VmPTE:\t%8lu kB\n"
48971 - "VmSwap:\t%8lu kB\n",
48972 - hiwater_vm << (PAGE_SHIFT-10),
48973 + "VmSwap:\t%8lu kB\n"
48974 +
48975 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48976 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
48977 +#endif
48978 +
48979 + ,hiwater_vm << (PAGE_SHIFT-10),
48980 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
48981 mm->locked_vm << (PAGE_SHIFT-10),
48982 mm->pinned_vm << (PAGE_SHIFT-10),
48983 @@ -62,7 +68,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48984 data << (PAGE_SHIFT-10),
48985 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
48986 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
48987 - swap << (PAGE_SHIFT-10));
48988 + swap << (PAGE_SHIFT-10)
48989 +
48990 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48991 + , mm->context.user_cs_base, mm->context.user_cs_limit
48992 +#endif
48993 +
48994 + );
48995 }
48996
48997 unsigned long task_vsize(struct mm_struct *mm)
48998 @@ -209,6 +221,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
48999 return ret;
49000 }
49001
49002 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49003 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49004 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49005 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49006 +#endif
49007 +
49008 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49009 {
49010 struct mm_struct *mm = vma->vm_mm;
49011 @@ -227,13 +245,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49012 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49013 }
49014
49015 - /* We don't show the stack guard page in /proc/maps */
49016 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49017 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49018 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49019 +#else
49020 start = vma->vm_start;
49021 - if (stack_guard_page_start(vma, start))
49022 - start += PAGE_SIZE;
49023 end = vma->vm_end;
49024 - if (stack_guard_page_end(vma, end))
49025 - end -= PAGE_SIZE;
49026 +#endif
49027
49028 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49029 start,
49030 @@ -242,7 +260,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49031 flags & VM_WRITE ? 'w' : '-',
49032 flags & VM_EXEC ? 'x' : '-',
49033 flags & VM_MAYSHARE ? 's' : 'p',
49034 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49035 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49036 +#else
49037 pgoff,
49038 +#endif
49039 MAJOR(dev), MINOR(dev), ino, &len);
49040
49041 /*
49042 @@ -251,7 +273,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49043 */
49044 if (file) {
49045 pad_len_spaces(m, len);
49046 - seq_path(m, &file->f_path, "\n");
49047 + seq_path(m, &file->f_path, "\n\\");
49048 } else {
49049 const char *name = arch_vma_name(vma);
49050 if (!name) {
49051 @@ -259,8 +281,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49052 if (vma->vm_start <= mm->brk &&
49053 vma->vm_end >= mm->start_brk) {
49054 name = "[heap]";
49055 - } else if (vma->vm_start <= mm->start_stack &&
49056 - vma->vm_end >= mm->start_stack) {
49057 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49058 + (vma->vm_start <= mm->start_stack &&
49059 + vma->vm_end >= mm->start_stack)) {
49060 name = "[stack]";
49061 }
49062 } else {
49063 @@ -281,6 +304,13 @@ static int show_map(struct seq_file *m, void *v)
49064 struct proc_maps_private *priv = m->private;
49065 struct task_struct *task = priv->task;
49066
49067 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49068 + if (current->exec_id != m->exec_id) {
49069 + gr_log_badprocpid("maps");
49070 + return 0;
49071 + }
49072 +#endif
49073 +
49074 show_map_vma(m, vma);
49075
49076 if (m->count < m->size) /* vma is copied successfully */
49077 @@ -434,12 +464,23 @@ static int show_smap(struct seq_file *m, void *v)
49078 .private = &mss,
49079 };
49080
49081 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49082 + if (current->exec_id != m->exec_id) {
49083 + gr_log_badprocpid("smaps");
49084 + return 0;
49085 + }
49086 +#endif
49087 memset(&mss, 0, sizeof mss);
49088 - mss.vma = vma;
49089 - /* mmap_sem is held in m_start */
49090 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49091 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49092 -
49093 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49094 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49095 +#endif
49096 + mss.vma = vma;
49097 + /* mmap_sem is held in m_start */
49098 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49099 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49100 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49101 + }
49102 +#endif
49103 show_map_vma(m, vma);
49104
49105 seq_printf(m,
49106 @@ -457,7 +498,11 @@ static int show_smap(struct seq_file *m, void *v)
49107 "KernelPageSize: %8lu kB\n"
49108 "MMUPageSize: %8lu kB\n"
49109 "Locked: %8lu kB\n",
49110 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49111 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49112 +#else
49113 (vma->vm_end - vma->vm_start) >> 10,
49114 +#endif
49115 mss.resident >> 10,
49116 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49117 mss.shared_clean >> 10,
49118 @@ -1015,6 +1060,13 @@ static int show_numa_map(struct seq_file *m, void *v)
49119 int n;
49120 char buffer[50];
49121
49122 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49123 + if (current->exec_id != m->exec_id) {
49124 + gr_log_badprocpid("numa_maps");
49125 + return 0;
49126 + }
49127 +#endif
49128 +
49129 if (!mm)
49130 return 0;
49131
49132 @@ -1032,11 +1084,15 @@ static int show_numa_map(struct seq_file *m, void *v)
49133 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49134 mpol_cond_put(pol);
49135
49136 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49137 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49138 +#else
49139 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49140 +#endif
49141
49142 if (file) {
49143 seq_printf(m, " file=");
49144 - seq_path(m, &file->f_path, "\n\t= ");
49145 + seq_path(m, &file->f_path, "\n\t\\= ");
49146 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49147 seq_printf(m, " heap");
49148 } else if (vma->vm_start <= mm->start_stack &&
49149 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49150 index 980de54..2a4db5f 100644
49151 --- a/fs/proc/task_nommu.c
49152 +++ b/fs/proc/task_nommu.c
49153 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49154 else
49155 bytes += kobjsize(mm);
49156
49157 - if (current->fs && current->fs->users > 1)
49158 + if (current->fs && atomic_read(&current->fs->users) > 1)
49159 sbytes += kobjsize(current->fs);
49160 else
49161 bytes += kobjsize(current->fs);
49162 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
49163
49164 if (file) {
49165 pad_len_spaces(m, len);
49166 - seq_path(m, &file->f_path, "");
49167 + seq_path(m, &file->f_path, "\n\\");
49168 } else if (mm) {
49169 if (vma->vm_start <= mm->start_stack &&
49170 vma->vm_end >= mm->start_stack) {
49171 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49172 index d67908b..d13f6a6 100644
49173 --- a/fs/quota/netlink.c
49174 +++ b/fs/quota/netlink.c
49175 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49176 void quota_send_warning(short type, unsigned int id, dev_t dev,
49177 const char warntype)
49178 {
49179 - static atomic_t seq;
49180 + static atomic_unchecked_t seq;
49181 struct sk_buff *skb;
49182 void *msg_head;
49183 int ret;
49184 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49185 "VFS: Not enough memory to send quota warning.\n");
49186 return;
49187 }
49188 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49189 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49190 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49191 if (!msg_head) {
49192 printk(KERN_ERR
49193 diff --git a/fs/readdir.c b/fs/readdir.c
49194 index 356f715..c918d38 100644
49195 --- a/fs/readdir.c
49196 +++ b/fs/readdir.c
49197 @@ -17,6 +17,7 @@
49198 #include <linux/security.h>
49199 #include <linux/syscalls.h>
49200 #include <linux/unistd.h>
49201 +#include <linux/namei.h>
49202
49203 #include <asm/uaccess.h>
49204
49205 @@ -67,6 +68,7 @@ struct old_linux_dirent {
49206
49207 struct readdir_callback {
49208 struct old_linux_dirent __user * dirent;
49209 + struct file * file;
49210 int result;
49211 };
49212
49213 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49214 buf->result = -EOVERFLOW;
49215 return -EOVERFLOW;
49216 }
49217 +
49218 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49219 + return 0;
49220 +
49221 buf->result++;
49222 dirent = buf->dirent;
49223 if (!access_ok(VERIFY_WRITE, dirent,
49224 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49225
49226 buf.result = 0;
49227 buf.dirent = dirent;
49228 + buf.file = file;
49229
49230 error = vfs_readdir(file, fillonedir, &buf);
49231 if (buf.result)
49232 @@ -142,6 +149,7 @@ struct linux_dirent {
49233 struct getdents_callback {
49234 struct linux_dirent __user * current_dir;
49235 struct linux_dirent __user * previous;
49236 + struct file * file;
49237 int count;
49238 int error;
49239 };
49240 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49241 buf->error = -EOVERFLOW;
49242 return -EOVERFLOW;
49243 }
49244 +
49245 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49246 + return 0;
49247 +
49248 dirent = buf->previous;
49249 if (dirent) {
49250 if (__put_user(offset, &dirent->d_off))
49251 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49252 buf.previous = NULL;
49253 buf.count = count;
49254 buf.error = 0;
49255 + buf.file = file;
49256
49257 error = vfs_readdir(file, filldir, &buf);
49258 if (error >= 0)
49259 @@ -229,6 +242,7 @@ out:
49260 struct getdents_callback64 {
49261 struct linux_dirent64 __user * current_dir;
49262 struct linux_dirent64 __user * previous;
49263 + struct file *file;
49264 int count;
49265 int error;
49266 };
49267 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49268 buf->error = -EINVAL; /* only used if we fail.. */
49269 if (reclen > buf->count)
49270 return -EINVAL;
49271 +
49272 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49273 + return 0;
49274 +
49275 dirent = buf->previous;
49276 if (dirent) {
49277 if (__put_user(offset, &dirent->d_off))
49278 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49279
49280 buf.current_dir = dirent;
49281 buf.previous = NULL;
49282 + buf.file = file;
49283 buf.count = count;
49284 buf.error = 0;
49285
49286 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49287 error = buf.error;
49288 lastdirent = buf.previous;
49289 if (lastdirent) {
49290 - typeof(lastdirent->d_off) d_off = file->f_pos;
49291 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49292 if (__put_user(d_off, &lastdirent->d_off))
49293 error = -EFAULT;
49294 else
49295 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
49296 index 60c0804..d814f98 100644
49297 --- a/fs/reiserfs/do_balan.c
49298 +++ b/fs/reiserfs/do_balan.c
49299 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
49300 return;
49301 }
49302
49303 - atomic_inc(&(fs_generation(tb->tb_sb)));
49304 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
49305 do_balance_starts(tb);
49306
49307 /* balance leaf returns 0 except if combining L R and S into
49308 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
49309 index 7a99811..a7c96c4 100644
49310 --- a/fs/reiserfs/procfs.c
49311 +++ b/fs/reiserfs/procfs.c
49312 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
49313 "SMALL_TAILS " : "NO_TAILS ",
49314 replay_only(sb) ? "REPLAY_ONLY " : "",
49315 convert_reiserfs(sb) ? "CONV " : "",
49316 - atomic_read(&r->s_generation_counter),
49317 + atomic_read_unchecked(&r->s_generation_counter),
49318 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
49319 SF(s_do_balance), SF(s_unneeded_left_neighbor),
49320 SF(s_good_search_by_key_reada), SF(s_bmaps),
49321 diff --git a/fs/select.c b/fs/select.c
49322 index d33418f..2a5345e 100644
49323 --- a/fs/select.c
49324 +++ b/fs/select.c
49325 @@ -20,6 +20,7 @@
49326 #include <linux/module.h>
49327 #include <linux/slab.h>
49328 #include <linux/poll.h>
49329 +#include <linux/security.h>
49330 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
49331 #include <linux/file.h>
49332 #include <linux/fdtable.h>
49333 @@ -837,6 +838,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
49334 struct poll_list *walk = head;
49335 unsigned long todo = nfds;
49336
49337 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
49338 if (nfds > rlimit(RLIMIT_NOFILE))
49339 return -EINVAL;
49340
49341 diff --git a/fs/seq_file.c b/fs/seq_file.c
49342 index dba43c3..4b3f701 100644
49343 --- a/fs/seq_file.c
49344 +++ b/fs/seq_file.c
49345 @@ -9,6 +9,7 @@
49346 #include <linux/module.h>
49347 #include <linux/seq_file.h>
49348 #include <linux/slab.h>
49349 +#include <linux/sched.h>
49350
49351 #include <asm/uaccess.h>
49352 #include <asm/page.h>
49353 @@ -40,6 +41,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
49354 memset(p, 0, sizeof(*p));
49355 mutex_init(&p->lock);
49356 p->op = op;
49357 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49358 + p->exec_id = current->exec_id;
49359 +#endif
49360
49361 /*
49362 * Wrappers around seq_open(e.g. swaps_open) need to be
49363 @@ -549,7 +553,7 @@ static void single_stop(struct seq_file *p, void *v)
49364 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49365 void *data)
49366 {
49367 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49368 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49369 int res = -ENOMEM;
49370
49371 if (op) {
49372 diff --git a/fs/splice.c b/fs/splice.c
49373 index fa2defa..8601650 100644
49374 --- a/fs/splice.c
49375 +++ b/fs/splice.c
49376 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49377 pipe_lock(pipe);
49378
49379 for (;;) {
49380 - if (!pipe->readers) {
49381 + if (!atomic_read(&pipe->readers)) {
49382 send_sig(SIGPIPE, current, 0);
49383 if (!ret)
49384 ret = -EPIPE;
49385 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49386 do_wakeup = 0;
49387 }
49388
49389 - pipe->waiting_writers++;
49390 + atomic_inc(&pipe->waiting_writers);
49391 pipe_wait(pipe);
49392 - pipe->waiting_writers--;
49393 + atomic_dec(&pipe->waiting_writers);
49394 }
49395
49396 pipe_unlock(pipe);
49397 @@ -560,7 +560,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49398 old_fs = get_fs();
49399 set_fs(get_ds());
49400 /* The cast to a user pointer is valid due to the set_fs() */
49401 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49402 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49403 set_fs(old_fs);
49404
49405 return res;
49406 @@ -575,7 +575,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49407 old_fs = get_fs();
49408 set_fs(get_ds());
49409 /* The cast to a user pointer is valid due to the set_fs() */
49410 - res = vfs_write(file, (const char __user *)buf, count, &pos);
49411 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49412 set_fs(old_fs);
49413
49414 return res;
49415 @@ -626,7 +626,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49416 goto err;
49417
49418 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49419 - vec[i].iov_base = (void __user *) page_address(page);
49420 + vec[i].iov_base = (void __force_user *) page_address(page);
49421 vec[i].iov_len = this_len;
49422 spd.pages[i] = page;
49423 spd.nr_pages++;
49424 @@ -846,10 +846,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49425 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49426 {
49427 while (!pipe->nrbufs) {
49428 - if (!pipe->writers)
49429 + if (!atomic_read(&pipe->writers))
49430 return 0;
49431
49432 - if (!pipe->waiting_writers && sd->num_spliced)
49433 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49434 return 0;
49435
49436 if (sd->flags & SPLICE_F_NONBLOCK)
49437 @@ -1182,7 +1182,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49438 * out of the pipe right after the splice_to_pipe(). So set
49439 * PIPE_READERS appropriately.
49440 */
49441 - pipe->readers = 1;
49442 + atomic_set(&pipe->readers, 1);
49443
49444 current->splice_pipe = pipe;
49445 }
49446 @@ -1734,9 +1734,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49447 ret = -ERESTARTSYS;
49448 break;
49449 }
49450 - if (!pipe->writers)
49451 + if (!atomic_read(&pipe->writers))
49452 break;
49453 - if (!pipe->waiting_writers) {
49454 + if (!atomic_read(&pipe->waiting_writers)) {
49455 if (flags & SPLICE_F_NONBLOCK) {
49456 ret = -EAGAIN;
49457 break;
49458 @@ -1768,7 +1768,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49459 pipe_lock(pipe);
49460
49461 while (pipe->nrbufs >= pipe->buffers) {
49462 - if (!pipe->readers) {
49463 + if (!atomic_read(&pipe->readers)) {
49464 send_sig(SIGPIPE, current, 0);
49465 ret = -EPIPE;
49466 break;
49467 @@ -1781,9 +1781,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49468 ret = -ERESTARTSYS;
49469 break;
49470 }
49471 - pipe->waiting_writers++;
49472 + atomic_inc(&pipe->waiting_writers);
49473 pipe_wait(pipe);
49474 - pipe->waiting_writers--;
49475 + atomic_dec(&pipe->waiting_writers);
49476 }
49477
49478 pipe_unlock(pipe);
49479 @@ -1819,14 +1819,14 @@ retry:
49480 pipe_double_lock(ipipe, opipe);
49481
49482 do {
49483 - if (!opipe->readers) {
49484 + if (!atomic_read(&opipe->readers)) {
49485 send_sig(SIGPIPE, current, 0);
49486 if (!ret)
49487 ret = -EPIPE;
49488 break;
49489 }
49490
49491 - if (!ipipe->nrbufs && !ipipe->writers)
49492 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49493 break;
49494
49495 /*
49496 @@ -1923,7 +1923,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49497 pipe_double_lock(ipipe, opipe);
49498
49499 do {
49500 - if (!opipe->readers) {
49501 + if (!atomic_read(&opipe->readers)) {
49502 send_sig(SIGPIPE, current, 0);
49503 if (!ret)
49504 ret = -EPIPE;
49505 @@ -1968,7 +1968,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49506 * return EAGAIN if we have the potential of some data in the
49507 * future, otherwise just return 0
49508 */
49509 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49510 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49511 ret = -EAGAIN;
49512
49513 pipe_unlock(ipipe);
49514 diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
49515 index a475983..9c6a1f0 100644
49516 --- a/fs/sysfs/bin.c
49517 +++ b/fs/sysfs/bin.c
49518 @@ -67,6 +67,8 @@ fill_read(struct file *file, char *buffer, loff_t off, size_t count)
49519 }
49520
49521 static ssize_t
49522 +read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off) __size_overflow(3);
49523 +static ssize_t
49524 read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
49525 {
49526 struct bin_buffer *bb = file->private_data;
49527 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49528 index 7fdf6a7..e6cd8ad 100644
49529 --- a/fs/sysfs/dir.c
49530 +++ b/fs/sysfs/dir.c
49531 @@ -642,6 +642,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49532 struct sysfs_dirent *sd;
49533 int rc;
49534
49535 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49536 + const char *parent_name = parent_sd->s_name;
49537 +
49538 + mode = S_IFDIR | S_IRWXU;
49539 +
49540 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49541 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49542 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49543 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49544 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49545 +#endif
49546 +
49547 /* allocate */
49548 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49549 if (!sd)
49550 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49551 index 779789a..f58193c 100644
49552 --- a/fs/sysfs/file.c
49553 +++ b/fs/sysfs/file.c
49554 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49555
49556 struct sysfs_open_dirent {
49557 atomic_t refcnt;
49558 - atomic_t event;
49559 + atomic_unchecked_t event;
49560 wait_queue_head_t poll;
49561 struct list_head buffers; /* goes through sysfs_buffer.list */
49562 };
49563 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49564 if (!sysfs_get_active(attr_sd))
49565 return -ENODEV;
49566
49567 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49568 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49569 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49570
49571 sysfs_put_active(attr_sd);
49572 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49573 return -ENOMEM;
49574
49575 atomic_set(&new_od->refcnt, 0);
49576 - atomic_set(&new_od->event, 1);
49577 + atomic_set_unchecked(&new_od->event, 1);
49578 init_waitqueue_head(&new_od->poll);
49579 INIT_LIST_HEAD(&new_od->buffers);
49580 goto retry;
49581 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49582
49583 sysfs_put_active(attr_sd);
49584
49585 - if (buffer->event != atomic_read(&od->event))
49586 + if (buffer->event != atomic_read_unchecked(&od->event))
49587 goto trigger;
49588
49589 return DEFAULT_POLLMASK;
49590 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49591
49592 od = sd->s_attr.open;
49593 if (od) {
49594 - atomic_inc(&od->event);
49595 + atomic_inc_unchecked(&od->event);
49596 wake_up_interruptible(&od->poll);
49597 }
49598
49599 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49600 index a7ac78f..02158e1 100644
49601 --- a/fs/sysfs/symlink.c
49602 +++ b/fs/sysfs/symlink.c
49603 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49604
49605 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49606 {
49607 - char *page = nd_get_link(nd);
49608 + const char *page = nd_get_link(nd);
49609 if (!IS_ERR(page))
49610 free_page((unsigned long)page);
49611 }
49612 diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
49613 index b09ba2d..1cad1a8 100644
49614 --- a/fs/ubifs/debug.c
49615 +++ b/fs/ubifs/debug.c
49616 @@ -2817,6 +2817,7 @@ static ssize_t dfs_file_read(struct file *file, char __user *u, size_t count,
49617 * debugfs file. Returns %0 or %1 in case of success and a negative error code
49618 * in case of failure.
49619 */
49620 +static int interpret_user_input(const char __user *u, size_t count) __size_overflow(2);
49621 static int interpret_user_input(const char __user *u, size_t count)
49622 {
49623 size_t buf_size;
49624 @@ -2835,6 +2836,8 @@ static int interpret_user_input(const char __user *u, size_t count)
49625 }
49626
49627 static ssize_t dfs_file_write(struct file *file, const char __user *u,
49628 + size_t count, loff_t *ppos) __size_overflow(3);
49629 +static ssize_t dfs_file_write(struct file *file, const char __user *u,
49630 size_t count, loff_t *ppos)
49631 {
49632 struct ubifs_info *c = file->private_data;
49633 diff --git a/fs/udf/file.c b/fs/udf/file.c
49634 index dca0c38..d567b84 100644
49635 --- a/fs/udf/file.c
49636 +++ b/fs/udf/file.c
49637 @@ -201,12 +201,10 @@ out:
49638 static int udf_release_file(struct inode *inode, struct file *filp)
49639 {
49640 if (filp->f_mode & FMODE_WRITE) {
49641 - mutex_lock(&inode->i_mutex);
49642 down_write(&UDF_I(inode)->i_data_sem);
49643 udf_discard_prealloc(inode);
49644 udf_truncate_tail_extent(inode);
49645 up_write(&UDF_I(inode)->i_data_sem);
49646 - mutex_unlock(&inode->i_mutex);
49647 }
49648 return 0;
49649 }
49650 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49651 index c175b4d..8f36a16 100644
49652 --- a/fs/udf/misc.c
49653 +++ b/fs/udf/misc.c
49654 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49655
49656 u8 udf_tag_checksum(const struct tag *t)
49657 {
49658 - u8 *data = (u8 *)t;
49659 + const u8 *data = (const u8 *)t;
49660 u8 checksum = 0;
49661 int i;
49662 for (i = 0; i < sizeof(struct tag); ++i)
49663 diff --git a/fs/utimes.c b/fs/utimes.c
49664 index ba653f3..06ea4b1 100644
49665 --- a/fs/utimes.c
49666 +++ b/fs/utimes.c
49667 @@ -1,6 +1,7 @@
49668 #include <linux/compiler.h>
49669 #include <linux/file.h>
49670 #include <linux/fs.h>
49671 +#include <linux/security.h>
49672 #include <linux/linkage.h>
49673 #include <linux/mount.h>
49674 #include <linux/namei.h>
49675 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49676 goto mnt_drop_write_and_out;
49677 }
49678 }
49679 +
49680 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
49681 + error = -EACCES;
49682 + goto mnt_drop_write_and_out;
49683 + }
49684 +
49685 mutex_lock(&inode->i_mutex);
49686 error = notify_change(path->dentry, &newattrs);
49687 mutex_unlock(&inode->i_mutex);
49688 diff --git a/fs/xattr.c b/fs/xattr.c
49689 index 67583de..c5aad14 100644
49690 --- a/fs/xattr.c
49691 +++ b/fs/xattr.c
49692 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49693 * Extended attribute SET operations
49694 */
49695 static long
49696 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
49697 +setxattr(struct path *path, const char __user *name, const void __user *value,
49698 size_t size, int flags)
49699 {
49700 int error;
49701 @@ -339,7 +339,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49702 return PTR_ERR(kvalue);
49703 }
49704
49705 - error = vfs_setxattr(d, kname, kvalue, size, flags);
49706 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49707 + error = -EACCES;
49708 + goto out;
49709 + }
49710 +
49711 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49712 +out:
49713 kfree(kvalue);
49714 return error;
49715 }
49716 @@ -356,7 +362,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49717 return error;
49718 error = mnt_want_write(path.mnt);
49719 if (!error) {
49720 - error = setxattr(path.dentry, name, value, size, flags);
49721 + error = setxattr(&path, name, value, size, flags);
49722 mnt_drop_write(path.mnt);
49723 }
49724 path_put(&path);
49725 @@ -375,7 +381,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49726 return error;
49727 error = mnt_want_write(path.mnt);
49728 if (!error) {
49729 - error = setxattr(path.dentry, name, value, size, flags);
49730 + error = setxattr(&path, name, value, size, flags);
49731 mnt_drop_write(path.mnt);
49732 }
49733 path_put(&path);
49734 @@ -386,17 +392,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49735 const void __user *,value, size_t, size, int, flags)
49736 {
49737 struct file *f;
49738 - struct dentry *dentry;
49739 int error = -EBADF;
49740
49741 f = fget(fd);
49742 if (!f)
49743 return error;
49744 - dentry = f->f_path.dentry;
49745 - audit_inode(NULL, dentry);
49746 + audit_inode(NULL, f->f_path.dentry);
49747 error = mnt_want_write_file(f);
49748 if (!error) {
49749 - error = setxattr(dentry, name, value, size, flags);
49750 + error = setxattr(&f->f_path, name, value, size, flags);
49751 mnt_drop_write(f->f_path.mnt);
49752 }
49753 fput(f);
49754 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49755 index 8d5a506..7f62712 100644
49756 --- a/fs/xattr_acl.c
49757 +++ b/fs/xattr_acl.c
49758 @@ -17,8 +17,8 @@
49759 struct posix_acl *
49760 posix_acl_from_xattr(const void *value, size_t size)
49761 {
49762 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49763 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49764 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49765 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49766 int count;
49767 struct posix_acl *acl;
49768 struct posix_acl_entry *acl_e;
49769 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49770 index d0ab788..827999b 100644
49771 --- a/fs/xfs/xfs_bmap.c
49772 +++ b/fs/xfs/xfs_bmap.c
49773 @@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
49774 int nmap,
49775 int ret_nmap);
49776 #else
49777 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49778 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49779 #endif /* DEBUG */
49780
49781 STATIC int
49782 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49783 index 79d05e8..e3e5861 100644
49784 --- a/fs/xfs/xfs_dir2_sf.c
49785 +++ b/fs/xfs/xfs_dir2_sf.c
49786 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
49787 }
49788
49789 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49790 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49791 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49792 + char name[sfep->namelen];
49793 + memcpy(name, sfep->name, sfep->namelen);
49794 + if (filldir(dirent, name, sfep->namelen,
49795 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
49796 + *offset = off & 0x7fffffff;
49797 + return 0;
49798 + }
49799 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49800 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49801 *offset = off & 0x7fffffff;
49802 return 0;
49803 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49804 index d99a905..9f88202 100644
49805 --- a/fs/xfs/xfs_ioctl.c
49806 +++ b/fs/xfs/xfs_ioctl.c
49807 @@ -128,7 +128,7 @@ xfs_find_handle(
49808 }
49809
49810 error = -EFAULT;
49811 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49812 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49813 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49814 goto out_put;
49815
49816 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49817 index 23ce927..e274cc1 100644
49818 --- a/fs/xfs/xfs_iops.c
49819 +++ b/fs/xfs/xfs_iops.c
49820 @@ -447,7 +447,7 @@ xfs_vn_put_link(
49821 struct nameidata *nd,
49822 void *p)
49823 {
49824 - char *s = nd_get_link(nd);
49825 + const char *s = nd_get_link(nd);
49826
49827 if (!IS_ERR(s))
49828 kfree(s);
49829 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49830 new file mode 100644
49831 index 0000000..4089e05
49832 --- /dev/null
49833 +++ b/grsecurity/Kconfig
49834 @@ -0,0 +1,1078 @@
49835 +#
49836 +# grecurity configuration
49837 +#
49838 +
49839 +menu "Grsecurity"
49840 +
49841 +config GRKERNSEC
49842 + bool "Grsecurity"
49843 + select CRYPTO
49844 + select CRYPTO_SHA256
49845 + help
49846 + If you say Y here, you will be able to configure many features
49847 + that will enhance the security of your system. It is highly
49848 + recommended that you say Y here and read through the help
49849 + for each option so that you fully understand the features and
49850 + can evaluate their usefulness for your machine.
49851 +
49852 +choice
49853 + prompt "Security Level"
49854 + depends on GRKERNSEC
49855 + default GRKERNSEC_CUSTOM
49856 +
49857 +config GRKERNSEC_LOW
49858 + bool "Low"
49859 + select GRKERNSEC_LINK
49860 + select GRKERNSEC_FIFO
49861 + select GRKERNSEC_RANDNET
49862 + select GRKERNSEC_DMESG
49863 + select GRKERNSEC_CHROOT
49864 + select GRKERNSEC_CHROOT_CHDIR
49865 +
49866 + help
49867 + If you choose this option, several of the grsecurity options will
49868 + be enabled that will give you greater protection against a number
49869 + of attacks, while assuring that none of your software will have any
49870 + conflicts with the additional security measures. If you run a lot
49871 + of unusual software, or you are having problems with the higher
49872 + security levels, you should say Y here. With this option, the
49873 + following features are enabled:
49874 +
49875 + - Linking restrictions
49876 + - FIFO restrictions
49877 + - Restricted dmesg
49878 + - Enforced chdir("/") on chroot
49879 + - Runtime module disabling
49880 +
49881 +config GRKERNSEC_MEDIUM
49882 + bool "Medium"
49883 + select PAX
49884 + select PAX_EI_PAX
49885 + select PAX_PT_PAX_FLAGS
49886 + select PAX_HAVE_ACL_FLAGS
49887 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49888 + select GRKERNSEC_CHROOT
49889 + select GRKERNSEC_CHROOT_SYSCTL
49890 + select GRKERNSEC_LINK
49891 + select GRKERNSEC_FIFO
49892 + select GRKERNSEC_DMESG
49893 + select GRKERNSEC_RANDNET
49894 + select GRKERNSEC_FORKFAIL
49895 + select GRKERNSEC_TIME
49896 + select GRKERNSEC_SIGNAL
49897 + select GRKERNSEC_CHROOT
49898 + select GRKERNSEC_CHROOT_UNIX
49899 + select GRKERNSEC_CHROOT_MOUNT
49900 + select GRKERNSEC_CHROOT_PIVOT
49901 + select GRKERNSEC_CHROOT_DOUBLE
49902 + select GRKERNSEC_CHROOT_CHDIR
49903 + select GRKERNSEC_CHROOT_MKNOD
49904 + select GRKERNSEC_PROC
49905 + select GRKERNSEC_PROC_USERGROUP
49906 + select PAX_RANDUSTACK
49907 + select PAX_ASLR
49908 + select PAX_RANDMMAP
49909 + select PAX_REFCOUNT if (X86 || SPARC64)
49910 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
49911 +
49912 + help
49913 + If you say Y here, several features in addition to those included
49914 + in the low additional security level will be enabled. These
49915 + features provide even more security to your system, though in rare
49916 + cases they may be incompatible with very old or poorly written
49917 + software. If you enable this option, make sure that your auth
49918 + service (identd) is running as gid 1001. With this option,
49919 + the following features (in addition to those provided in the
49920 + low additional security level) will be enabled:
49921 +
49922 + - Failed fork logging
49923 + - Time change logging
49924 + - Signal logging
49925 + - Deny mounts in chroot
49926 + - Deny double chrooting
49927 + - Deny sysctl writes in chroot
49928 + - Deny mknod in chroot
49929 + - Deny access to abstract AF_UNIX sockets out of chroot
49930 + - Deny pivot_root in chroot
49931 + - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
49932 + - /proc restrictions with special GID set to 10 (usually wheel)
49933 + - Address Space Layout Randomization (ASLR)
49934 + - Prevent exploitation of most refcount overflows
49935 + - Bounds checking of copying between the kernel and userland
49936 +
49937 +config GRKERNSEC_HIGH
49938 + bool "High"
49939 + select GRKERNSEC_LINK
49940 + select GRKERNSEC_FIFO
49941 + select GRKERNSEC_DMESG
49942 + select GRKERNSEC_FORKFAIL
49943 + select GRKERNSEC_TIME
49944 + select GRKERNSEC_SIGNAL
49945 + select GRKERNSEC_CHROOT
49946 + select GRKERNSEC_CHROOT_SHMAT
49947 + select GRKERNSEC_CHROOT_UNIX
49948 + select GRKERNSEC_CHROOT_MOUNT
49949 + select GRKERNSEC_CHROOT_FCHDIR
49950 + select GRKERNSEC_CHROOT_PIVOT
49951 + select GRKERNSEC_CHROOT_DOUBLE
49952 + select GRKERNSEC_CHROOT_CHDIR
49953 + select GRKERNSEC_CHROOT_MKNOD
49954 + select GRKERNSEC_CHROOT_CAPS
49955 + select GRKERNSEC_CHROOT_SYSCTL
49956 + select GRKERNSEC_CHROOT_FINDTASK
49957 + select GRKERNSEC_SYSFS_RESTRICT
49958 + select GRKERNSEC_PROC
49959 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49960 + select GRKERNSEC_HIDESYM
49961 + select GRKERNSEC_BRUTE
49962 + select GRKERNSEC_PROC_USERGROUP
49963 + select GRKERNSEC_KMEM
49964 + select GRKERNSEC_RESLOG
49965 + select GRKERNSEC_RANDNET
49966 + select GRKERNSEC_PROC_ADD
49967 + select GRKERNSEC_CHROOT_CHMOD
49968 + select GRKERNSEC_CHROOT_NICE
49969 + select GRKERNSEC_SETXID
49970 + select GRKERNSEC_AUDIT_MOUNT
49971 + select GRKERNSEC_MODHARDEN if (MODULES)
49972 + select GRKERNSEC_HARDEN_PTRACE
49973 + select GRKERNSEC_PTRACE_READEXEC
49974 + select GRKERNSEC_VM86 if (X86_32)
49975 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
49976 + select PAX
49977 + select PAX_RANDUSTACK
49978 + select PAX_ASLR
49979 + select PAX_RANDMMAP
49980 + select PAX_NOEXEC
49981 + select PAX_MPROTECT
49982 + select PAX_EI_PAX
49983 + select PAX_PT_PAX_FLAGS
49984 + select PAX_HAVE_ACL_FLAGS
49985 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
49986 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
49987 + select PAX_RANDKSTACK if (X86_TSC && X86)
49988 + select PAX_SEGMEXEC if (X86_32)
49989 + select PAX_PAGEEXEC
49990 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
49991 + select PAX_EMUTRAMP if (PARISC)
49992 + select PAX_EMUSIGRT if (PARISC)
49993 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
49994 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
49995 + select PAX_REFCOUNT if (X86 || SPARC64)
49996 + select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
49997 + help
49998 + If you say Y here, many of the features of grsecurity will be
49999 + enabled, which will protect you against many kinds of attacks
50000 + against your system. The heightened security comes at a cost
50001 + of an increased chance of incompatibilities with rare software
50002 + on your machine. Since this security level enables PaX, you should
50003 + view <http://pax.grsecurity.net> and read about the PaX
50004 + project. While you are there, download chpax and run it on
50005 + binaries that cause problems with PaX. Also remember that
50006 + since the /proc restrictions are enabled, you must run your
50007 + identd as gid 1001. This security level enables the following
50008 + features in addition to those listed in the low and medium
50009 + security levels:
50010 +
50011 + - Additional /proc restrictions
50012 + - Chmod restrictions in chroot
50013 + - No signals, ptrace, or viewing of processes outside of chroot
50014 + - Capability restrictions in chroot
50015 + - Deny fchdir out of chroot
50016 + - Priority restrictions in chroot
50017 + - Segmentation-based implementation of PaX
50018 + - Mprotect restrictions
50019 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
50020 + - Kernel stack randomization
50021 + - Mount/unmount/remount logging
50022 + - Kernel symbol hiding
50023 + - Hardening of module auto-loading
50024 + - Ptrace restrictions
50025 + - Restricted vm86 mode
50026 + - Restricted sysfs/debugfs
50027 + - Active kernel exploit response
50028 +
50029 +config GRKERNSEC_CUSTOM
50030 + bool "Custom"
50031 + help
50032 + If you say Y here, you will be able to configure every grsecurity
50033 + option, which allows you to enable many more features that aren't
50034 + covered in the basic security levels. These additional features
50035 + include TPE, socket restrictions, and the sysctl system for
50036 + grsecurity. It is advised that you read through the help for
50037 + each option to determine its usefulness in your situation.
50038 +
50039 +endchoice
50040 +
50041 +menu "Memory Protections"
50042 +depends on GRKERNSEC
50043 +
50044 +config GRKERNSEC_KMEM
50045 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50046 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50047 + help
50048 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50049 + be written to or read from to modify or leak the contents of the running
50050 + kernel. /dev/port will also not be allowed to be opened. If you have module
50051 + support disabled, enabling this will close up four ways that are
50052 + currently used to insert malicious code into the running kernel.
50053 + Even with all these features enabled, we still highly recommend that
50054 + you use the RBAC system, as it is still possible for an attacker to
50055 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50056 + If you are not using XFree86, you may be able to stop this additional
50057 + case by enabling the 'Disable privileged I/O' option. Though nothing
50058 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50059 + but only to video memory, which is the only writing we allow in this
50060 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50061 + not be allowed to mprotect it with PROT_WRITE later.
50062 + It is highly recommended that you say Y here if you meet all the
50063 + conditions above.
50064 +
50065 +config GRKERNSEC_VM86
50066 + bool "Restrict VM86 mode"
50067 + depends on X86_32
50068 +
50069 + help
50070 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50071 + make use of a special execution mode on 32bit x86 processors called
50072 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50073 + video cards and will still work with this option enabled. The purpose
50074 + of the option is to prevent exploitation of emulation errors in
50075 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50076 + Nearly all users should be able to enable this option.
50077 +
50078 +config GRKERNSEC_IO
50079 + bool "Disable privileged I/O"
50080 + depends on X86
50081 + select RTC_CLASS
50082 + select RTC_INTF_DEV
50083 + select RTC_DRV_CMOS
50084 +
50085 + help
50086 + If you say Y here, all ioperm and iopl calls will return an error.
50087 + Ioperm and iopl can be used to modify the running kernel.
50088 + Unfortunately, some programs need this access to operate properly,
50089 + the most notable of which are XFree86 and hwclock. hwclock can be
50090 + remedied by having RTC support in the kernel, so real-time
50091 + clock support is enabled if this option is enabled, to ensure
50092 + that hwclock operates correctly. XFree86 still will not
50093 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50094 + IF YOU USE XFree86. If you use XFree86 and you still want to
50095 + protect your kernel against modification, use the RBAC system.
50096 +
50097 +config GRKERNSEC_PROC_MEMMAP
50098 + bool "Harden ASLR against information leaks and entropy reduction"
50099 + default y if (PAX_NOEXEC || PAX_ASLR)
50100 + depends on PAX_NOEXEC || PAX_ASLR
50101 + help
50102 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50103 + give no information about the addresses of its mappings if
50104 + PaX features that rely on random addresses are enabled on the task.
50105 + In addition to sanitizing this information and disabling other
50106 + dangerous sources of information, this option causes reads of sensitive
50107 + /proc/<pid> entries where the file descriptor was opened in a different
50108 + task than the one performing the read. Such attempts are logged.
50109 + This option also limits argv/env strings for suid/sgid binaries
50110 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50111 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50112 + binaries to prevent alternative mmap layouts from being abused.
50113 +
50114 + If you use PaX it is essential that you say Y here as it closes up
50115 + several holes that make full ASLR useless locally.
50116 +
50117 +config GRKERNSEC_BRUTE
50118 + bool "Deter exploit bruteforcing"
50119 + help
50120 + If you say Y here, attempts to bruteforce exploits against forking
50121 + daemons such as apache or sshd, as well as against suid/sgid binaries
50122 + will be deterred. When a child of a forking daemon is killed by PaX
50123 + or crashes due to an illegal instruction or other suspicious signal,
50124 + the parent process will be delayed 30 seconds upon every subsequent
50125 + fork until the administrator is able to assess the situation and
50126 + restart the daemon.
50127 + In the suid/sgid case, the attempt is logged, the user has all their
50128 + processes terminated, and they are prevented from executing any further
50129 + processes for 15 minutes.
50130 + It is recommended that you also enable signal logging in the auditing
50131 + section so that logs are generated when a process triggers a suspicious
50132 + signal.
50133 + If the sysctl option is enabled, a sysctl option with name
50134 + "deter_bruteforce" is created.
50135 +
50136 +
50137 +config GRKERNSEC_MODHARDEN
50138 + bool "Harden module auto-loading"
50139 + depends on MODULES
50140 + help
50141 + If you say Y here, module auto-loading in response to use of some
50142 + feature implemented by an unloaded module will be restricted to
50143 + root users. Enabling this option helps defend against attacks
50144 + by unprivileged users who abuse the auto-loading behavior to
50145 + cause a vulnerable module to load that is then exploited.
50146 +
50147 + If this option prevents a legitimate use of auto-loading for a
50148 + non-root user, the administrator can execute modprobe manually
50149 + with the exact name of the module mentioned in the alert log.
50150 + Alternatively, the administrator can add the module to the list
50151 + of modules loaded at boot by modifying init scripts.
50152 +
50153 + Modification of init scripts will most likely be needed on
50154 + Ubuntu servers with encrypted home directory support enabled,
50155 + as the first non-root user logging in will cause the ecb(aes),
50156 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50157 +
50158 +config GRKERNSEC_HIDESYM
50159 + bool "Hide kernel symbols"
50160 + help
50161 + If you say Y here, getting information on loaded modules, and
50162 + displaying all kernel symbols through a syscall will be restricted
50163 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50164 + /proc/kallsyms will be restricted to the root user. The RBAC
50165 + system can hide that entry even from root.
50166 +
50167 + This option also prevents leaking of kernel addresses through
50168 + several /proc entries.
50169 +
50170 + Note that this option is only effective provided the following
50171 + conditions are met:
50172 + 1) The kernel using grsecurity is not precompiled by some distribution
50173 + 2) You have also enabled GRKERNSEC_DMESG
50174 + 3) You are using the RBAC system and hiding other files such as your
50175 + kernel image and System.map. Alternatively, enabling this option
50176 + causes the permissions on /boot, /lib/modules, and the kernel
50177 + source directory to change at compile time to prevent
50178 + reading by non-root users.
50179 + If the above conditions are met, this option will aid in providing a
50180 + useful protection against local kernel exploitation of overflows
50181 + and arbitrary read/write vulnerabilities.
50182 +
50183 +config GRKERNSEC_KERN_LOCKOUT
50184 + bool "Active kernel exploit response"
50185 + depends on X86 || ARM || PPC || SPARC
50186 + help
50187 + If you say Y here, when a PaX alert is triggered due to suspicious
50188 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50189 + or an OOPs occurs due to bad memory accesses, instead of just
50190 + terminating the offending process (and potentially allowing
50191 + a subsequent exploit from the same user), we will take one of two
50192 + actions:
50193 + If the user was root, we will panic the system
50194 + If the user was non-root, we will log the attempt, terminate
50195 + all processes owned by the user, then prevent them from creating
50196 + any new processes until the system is restarted
50197 + This deters repeated kernel exploitation/bruteforcing attempts
50198 + and is useful for later forensics.
50199 +
50200 +endmenu
50201 +menu "Role Based Access Control Options"
50202 +depends on GRKERNSEC
50203 +
50204 +config GRKERNSEC_RBAC_DEBUG
50205 + bool
50206 +
50207 +config GRKERNSEC_NO_RBAC
50208 + bool "Disable RBAC system"
50209 + help
50210 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50211 + preventing the RBAC system from being enabled. You should only say Y
50212 + here if you have no intention of using the RBAC system, so as to prevent
50213 + an attacker with root access from misusing the RBAC system to hide files
50214 + and processes when loadable module support and /dev/[k]mem have been
50215 + locked down.
50216 +
50217 +config GRKERNSEC_ACL_HIDEKERN
50218 + bool "Hide kernel processes"
50219 + help
50220 + If you say Y here, all kernel threads will be hidden to all
50221 + processes but those whose subject has the "view hidden processes"
50222 + flag.
50223 +
50224 +config GRKERNSEC_ACL_MAXTRIES
50225 + int "Maximum tries before password lockout"
50226 + default 3
50227 + help
50228 + This option enforces the maximum number of times a user can attempt
50229 + to authorize themselves with the grsecurity RBAC system before being
50230 + denied the ability to attempt authorization again for a specified time.
50231 + The lower the number, the harder it will be to brute-force a password.
50232 +
50233 +config GRKERNSEC_ACL_TIMEOUT
50234 + int "Time to wait after max password tries, in seconds"
50235 + default 30
50236 + help
50237 + This option specifies the time the user must wait after attempting to
50238 + authorize to the RBAC system with the maximum number of invalid
50239 + passwords. The higher the number, the harder it will be to brute-force
50240 + a password.
50241 +
50242 +endmenu
50243 +menu "Filesystem Protections"
50244 +depends on GRKERNSEC
50245 +
50246 +config GRKERNSEC_PROC
50247 + bool "Proc restrictions"
50248 + help
50249 + If you say Y here, the permissions of the /proc filesystem
50250 + will be altered to enhance system security and privacy. You MUST
50251 + choose either a user only restriction or a user and group restriction.
50252 + Depending upon the option you choose, you can either restrict users to
50253 + see only the processes they themselves run, or choose a group that can
50254 + view all processes and files normally restricted to root if you choose
50255 + the "restrict to user only" option. NOTE: If you're running identd or
50256 + ntpd as a non-root user, you will have to run it as the group you
50257 + specify here.
50258 +
50259 +config GRKERNSEC_PROC_USER
50260 + bool "Restrict /proc to user only"
50261 + depends on GRKERNSEC_PROC
50262 + help
50263 + If you say Y here, non-root users will only be able to view their own
50264 + processes, and restricts them from viewing network-related information,
50265 + and viewing kernel symbol and module information.
50266 +
50267 +config GRKERNSEC_PROC_USERGROUP
50268 + bool "Allow special group"
50269 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50270 + help
50271 + If you say Y here, you will be able to select a group that will be
50272 + able to view all processes and network-related information. If you've
50273 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50274 + remain hidden. This option is useful if you want to run identd as
50275 + a non-root user.
50276 +
50277 +config GRKERNSEC_PROC_GID
50278 + int "GID for special group"
50279 + depends on GRKERNSEC_PROC_USERGROUP
50280 + default 1001
50281 +
50282 +config GRKERNSEC_PROC_ADD
50283 + bool "Additional restrictions"
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 + help
50293 + If you say Y here, /tmp race exploits will be prevented, since users
50294 + will no longer be able to follow symlinks owned by other users in
50295 + world-writable +t directories (e.g. /tmp), unless the owner of the
50296 + symlink is the owner of the directory. users will also not be
50297 + able to hardlink to files they do not own. If the sysctl option is
50298 + enabled, a sysctl option with name "linking_restrictions" is created.
50299 +
50300 +config GRKERNSEC_FIFO
50301 + bool "FIFO restrictions"
50302 + help
50303 + If you say Y here, users will not be able to write to FIFOs they don't
50304 + own in world-writable +t directories (e.g. /tmp), unless the owner of
50305 + the FIFO is the same owner of the directory it's held in. If the sysctl
50306 + option is enabled, a sysctl option with name "fifo_restrictions" is
50307 + created.
50308 +
50309 +config GRKERNSEC_SYSFS_RESTRICT
50310 + bool "Sysfs/debugfs restriction"
50311 + depends on SYSFS
50312 + help
50313 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50314 + any filesystem normally mounted under it (e.g. debugfs) will be
50315 + mostly accessible only by root. These filesystems generally provide access
50316 + to hardware and debug information that isn't appropriate for unprivileged
50317 + users of the system. Sysfs and debugfs have also become a large source
50318 + of new vulnerabilities, ranging from infoleaks to local compromise.
50319 + There has been very little oversight with an eye toward security involved
50320 + in adding new exporters of information to these filesystems, so their
50321 + use is discouraged.
50322 + For reasons of compatibility, a few directories have been whitelisted
50323 + for access by non-root users:
50324 + /sys/fs/selinux
50325 + /sys/fs/fuse
50326 + /sys/devices/system/cpu
50327 +
50328 +config GRKERNSEC_ROFS
50329 + bool "Runtime read-only mount protection"
50330 + help
50331 + If you say Y here, a sysctl option with name "romount_protect" will
50332 + be created. By setting this option to 1 at runtime, filesystems
50333 + will be protected in the following ways:
50334 + * No new writable mounts will be allowed
50335 + * Existing read-only mounts won't be able to be remounted read/write
50336 + * Write operations will be denied on all block devices
50337 + This option acts independently of grsec_lock: once it is set to 1,
50338 + it cannot be turned off. Therefore, please be mindful of the resulting
50339 + behavior if this option is enabled in an init script on a read-only
50340 + filesystem. This feature is mainly intended for secure embedded systems.
50341 +
50342 +config GRKERNSEC_CHROOT
50343 + bool "Chroot jail restrictions"
50344 + help
50345 + If you say Y here, you will be able to choose several options that will
50346 + make breaking out of a chrooted jail much more difficult. If you
50347 + encounter no software incompatibilities with the following options, it
50348 + is recommended that you enable each one.
50349 +
50350 +config GRKERNSEC_CHROOT_MOUNT
50351 + bool "Deny mounts"
50352 + depends on GRKERNSEC_CHROOT
50353 + help
50354 + If you say Y here, processes inside a chroot will not be able to
50355 + mount or remount filesystems. If the sysctl option is enabled, a
50356 + sysctl option with name "chroot_deny_mount" is created.
50357 +
50358 +config GRKERNSEC_CHROOT_DOUBLE
50359 + bool "Deny double-chroots"
50360 + depends on GRKERNSEC_CHROOT
50361 + help
50362 + If you say Y here, processes inside a chroot will not be able to chroot
50363 + again outside the chroot. This is a widely used method of breaking
50364 + out of a chroot jail and should not be allowed. If the sysctl
50365 + option is enabled, a sysctl option with name
50366 + "chroot_deny_chroot" is created.
50367 +
50368 +config GRKERNSEC_CHROOT_PIVOT
50369 + bool "Deny pivot_root in chroot"
50370 + depends on GRKERNSEC_CHROOT
50371 + help
50372 + If you say Y here, processes inside a chroot will not be able to use
50373 + a function called pivot_root() that was introduced in Linux 2.3.41. It
50374 + works similar to chroot in that it changes the root filesystem. This
50375 + function could be misused in a chrooted process to attempt to break out
50376 + of the chroot, and therefore should not be allowed. If the sysctl
50377 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
50378 + created.
50379 +
50380 +config GRKERNSEC_CHROOT_CHDIR
50381 + bool "Enforce chdir(\"/\") on all chroots"
50382 + depends on GRKERNSEC_CHROOT
50383 + help
50384 + If you say Y here, the current working directory of all newly-chrooted
50385 + applications will be set to the the root directory of the chroot.
50386 + The man page on chroot(2) states:
50387 + Note that this call does not change the current working
50388 + directory, so that `.' can be outside the tree rooted at
50389 + `/'. In particular, the super-user can escape from a
50390 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50391 +
50392 + It is recommended that you say Y here, since it's not known to break
50393 + any software. If the sysctl option is enabled, a sysctl option with
50394 + name "chroot_enforce_chdir" is created.
50395 +
50396 +config GRKERNSEC_CHROOT_CHMOD
50397 + bool "Deny (f)chmod +s"
50398 + depends on GRKERNSEC_CHROOT
50399 + help
50400 + If you say Y here, processes inside a chroot will not be able to chmod
50401 + or fchmod files to make them have suid or sgid bits. This protects
50402 + against another published method of breaking a chroot. If the sysctl
50403 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
50404 + created.
50405 +
50406 +config GRKERNSEC_CHROOT_FCHDIR
50407 + bool "Deny fchdir out of chroot"
50408 + depends on GRKERNSEC_CHROOT
50409 + help
50410 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
50411 + to a file descriptor of the chrooting process that points to a directory
50412 + outside the filesystem will be stopped. If the sysctl option
50413 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50414 +
50415 +config GRKERNSEC_CHROOT_MKNOD
50416 + bool "Deny mknod"
50417 + depends on GRKERNSEC_CHROOT
50418 + help
50419 + If you say Y here, processes inside a chroot will not be allowed to
50420 + mknod. The problem with using mknod inside a chroot is that it
50421 + would allow an attacker to create a device entry that is the same
50422 + as one on the physical root of your system, which could range from
50423 + anything from the console device to a device for your harddrive (which
50424 + they could then use to wipe the drive or steal data). It is recommended
50425 + that you say Y here, unless you run into software incompatibilities.
50426 + If the sysctl option is enabled, a sysctl option with name
50427 + "chroot_deny_mknod" is created.
50428 +
50429 +config GRKERNSEC_CHROOT_SHMAT
50430 + bool "Deny shmat() out of chroot"
50431 + depends on GRKERNSEC_CHROOT
50432 + help
50433 + If you say Y here, processes inside a chroot will not be able to attach
50434 + to shared memory segments that were created outside of the chroot jail.
50435 + It is recommended that you say Y here. If the sysctl option is enabled,
50436 + a sysctl option with name "chroot_deny_shmat" is created.
50437 +
50438 +config GRKERNSEC_CHROOT_UNIX
50439 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
50440 + depends on GRKERNSEC_CHROOT
50441 + help
50442 + If you say Y here, processes inside a chroot will not be able to
50443 + connect to abstract (meaning not belonging to a filesystem) Unix
50444 + domain sockets that were bound outside of a chroot. It is recommended
50445 + that you say Y here. If the sysctl option is enabled, a sysctl option
50446 + with name "chroot_deny_unix" is created.
50447 +
50448 +config GRKERNSEC_CHROOT_FINDTASK
50449 + bool "Protect outside processes"
50450 + depends on GRKERNSEC_CHROOT
50451 + help
50452 + If you say Y here, processes inside a chroot will not be able to
50453 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50454 + getsid, or view any process outside of the chroot. If the sysctl
50455 + option is enabled, a sysctl option with name "chroot_findtask" is
50456 + created.
50457 +
50458 +config GRKERNSEC_CHROOT_NICE
50459 + bool "Restrict priority changes"
50460 + depends on GRKERNSEC_CHROOT
50461 + help
50462 + If you say Y here, processes inside a chroot will not be able to raise
50463 + the priority of processes in the chroot, or alter the priority of
50464 + processes outside the chroot. This provides more security than simply
50465 + removing CAP_SYS_NICE from the process' capability set. If the
50466 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50467 + is created.
50468 +
50469 +config GRKERNSEC_CHROOT_SYSCTL
50470 + bool "Deny sysctl writes"
50471 + depends on GRKERNSEC_CHROOT
50472 + help
50473 + If you say Y here, an attacker in a chroot will not be able to
50474 + write to sysctl entries, either by sysctl(2) or through a /proc
50475 + interface. It is strongly recommended that you say Y here. If the
50476 + sysctl option is enabled, a sysctl option with name
50477 + "chroot_deny_sysctl" is created.
50478 +
50479 +config GRKERNSEC_CHROOT_CAPS
50480 + bool "Capability restrictions"
50481 + depends on GRKERNSEC_CHROOT
50482 + help
50483 + If you say Y here, the capabilities on all processes within a
50484 + chroot jail will be lowered to stop module insertion, raw i/o,
50485 + system and net admin tasks, rebooting the system, modifying immutable
50486 + files, modifying IPC owned by another, and changing the system time.
50487 + This is left an option because it can break some apps. Disable this
50488 + if your chrooted apps are having problems performing those kinds of
50489 + tasks. If the sysctl option is enabled, a sysctl option with
50490 + name "chroot_caps" is created.
50491 +
50492 +endmenu
50493 +menu "Kernel Auditing"
50494 +depends on GRKERNSEC
50495 +
50496 +config GRKERNSEC_AUDIT_GROUP
50497 + bool "Single group for auditing"
50498 + help
50499 + If you say Y here, the exec, chdir, and (un)mount logging features
50500 + will only operate on a group you specify. This option is recommended
50501 + if you only want to watch certain users instead of having a large
50502 + amount of logs from the entire system. If the sysctl option is enabled,
50503 + a sysctl option with name "audit_group" is created.
50504 +
50505 +config GRKERNSEC_AUDIT_GID
50506 + int "GID for auditing"
50507 + depends on GRKERNSEC_AUDIT_GROUP
50508 + default 1007
50509 +
50510 +config GRKERNSEC_EXECLOG
50511 + bool "Exec logging"
50512 + help
50513 + If you say Y here, all execve() calls will be logged (since the
50514 + other exec*() calls are frontends to execve(), all execution
50515 + will be logged). Useful for shell-servers that like to keep track
50516 + of their users. If the sysctl option is enabled, a sysctl option with
50517 + name "exec_logging" is created.
50518 + WARNING: This option when enabled will produce a LOT of logs, especially
50519 + on an active system.
50520 +
50521 +config GRKERNSEC_RESLOG
50522 + bool "Resource logging"
50523 + help
50524 + If you say Y here, all attempts to overstep resource limits will
50525 + be logged with the resource name, the requested size, and the current
50526 + limit. It is highly recommended that you say Y here. If the sysctl
50527 + option is enabled, a sysctl option with name "resource_logging" is
50528 + created. If the RBAC system is enabled, the sysctl value is ignored.
50529 +
50530 +config GRKERNSEC_CHROOT_EXECLOG
50531 + bool "Log execs within chroot"
50532 + help
50533 + If you say Y here, all executions inside a chroot jail will be logged
50534 + to syslog. This can cause a large amount of logs if certain
50535 + applications (eg. djb's daemontools) are installed on the system, and
50536 + is therefore left as an option. If the sysctl option is enabled, a
50537 + sysctl option with name "chroot_execlog" is created.
50538 +
50539 +config GRKERNSEC_AUDIT_PTRACE
50540 + bool "Ptrace logging"
50541 + help
50542 + If you say Y here, all attempts to attach to a process via ptrace
50543 + will be logged. If the sysctl option is enabled, a sysctl option
50544 + with name "audit_ptrace" is created.
50545 +
50546 +config GRKERNSEC_AUDIT_CHDIR
50547 + bool "Chdir logging"
50548 + help
50549 + If you say Y here, all chdir() calls will be logged. If the sysctl
50550 + option is enabled, a sysctl option with name "audit_chdir" is created.
50551 +
50552 +config GRKERNSEC_AUDIT_MOUNT
50553 + bool "(Un)Mount logging"
50554 + help
50555 + If you say Y here, all mounts and unmounts will be logged. If the
50556 + sysctl option is enabled, a sysctl option with name "audit_mount" is
50557 + created.
50558 +
50559 +config GRKERNSEC_SIGNAL
50560 + bool "Signal logging"
50561 + help
50562 + If you say Y here, certain important signals will be logged, such as
50563 + SIGSEGV, which will as a result inform you of when a error in a program
50564 + occurred, which in some cases could mean a possible exploit attempt.
50565 + If the sysctl option is enabled, a sysctl option with name
50566 + "signal_logging" is created.
50567 +
50568 +config GRKERNSEC_FORKFAIL
50569 + bool "Fork failure logging"
50570 + help
50571 + If you say Y here, all failed fork() attempts will be logged.
50572 + This could suggest a fork bomb, or someone attempting to overstep
50573 + their process limit. If the sysctl option is enabled, a sysctl option
50574 + with name "forkfail_logging" is created.
50575 +
50576 +config GRKERNSEC_TIME
50577 + bool "Time change logging"
50578 + help
50579 + If you say Y here, any changes of the system clock will be logged.
50580 + If the sysctl option is enabled, a sysctl option with name
50581 + "timechange_logging" is created.
50582 +
50583 +config GRKERNSEC_PROC_IPADDR
50584 + bool "/proc/<pid>/ipaddr support"
50585 + help
50586 + If you say Y here, a new entry will be added to each /proc/<pid>
50587 + directory that contains the IP address of the person using the task.
50588 + The IP is carried across local TCP and AF_UNIX stream sockets.
50589 + This information can be useful for IDS/IPSes to perform remote response
50590 + to a local attack. The entry is readable by only the owner of the
50591 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50592 + the RBAC system), and thus does not create privacy concerns.
50593 +
50594 +config GRKERNSEC_RWXMAP_LOG
50595 + bool 'Denied RWX mmap/mprotect logging'
50596 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50597 + help
50598 + If you say Y here, calls to mmap() and mprotect() with explicit
50599 + usage of PROT_WRITE and PROT_EXEC together will be logged when
50600 + denied by the PAX_MPROTECT feature. If the sysctl option is
50601 + enabled, a sysctl option with name "rwxmap_logging" is created.
50602 +
50603 +config GRKERNSEC_AUDIT_TEXTREL
50604 + bool 'ELF text relocations logging (READ HELP)'
50605 + depends on PAX_MPROTECT
50606 + help
50607 + If you say Y here, text relocations will be logged with the filename
50608 + of the offending library or binary. The purpose of the feature is
50609 + to help Linux distribution developers get rid of libraries and
50610 + binaries that need text relocations which hinder the future progress
50611 + of PaX. Only Linux distribution developers should say Y here, and
50612 + never on a production machine, as this option creates an information
50613 + leak that could aid an attacker in defeating the randomization of
50614 + a single memory region. If the sysctl option is enabled, a sysctl
50615 + option with name "audit_textrel" is created.
50616 +
50617 +endmenu
50618 +
50619 +menu "Executable Protections"
50620 +depends on GRKERNSEC
50621 +
50622 +config GRKERNSEC_DMESG
50623 + bool "Dmesg(8) restriction"
50624 + help
50625 + If you say Y here, non-root users will not be able to use dmesg(8)
50626 + to view up to the last 4kb of messages in the kernel's log buffer.
50627 + The kernel's log buffer often contains kernel addresses and other
50628 + identifying information useful to an attacker in fingerprinting a
50629 + system for a targeted exploit.
50630 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
50631 + created.
50632 +
50633 +config GRKERNSEC_HARDEN_PTRACE
50634 + bool "Deter ptrace-based process snooping"
50635 + help
50636 + If you say Y here, TTY sniffers and other malicious monitoring
50637 + programs implemented through ptrace will be defeated. If you
50638 + have been using the RBAC system, this option has already been
50639 + enabled for several years for all users, with the ability to make
50640 + fine-grained exceptions.
50641 +
50642 + This option only affects the ability of non-root users to ptrace
50643 + processes that are not a descendent of the ptracing process.
50644 + This means that strace ./binary and gdb ./binary will still work,
50645 + but attaching to arbitrary processes will not. If the sysctl
50646 + option is enabled, a sysctl option with name "harden_ptrace" is
50647 + created.
50648 +
50649 +config GRKERNSEC_PTRACE_READEXEC
50650 + bool "Require read access to ptrace sensitive binaries"
50651 + help
50652 + If you say Y here, unprivileged users will not be able to ptrace unreadable
50653 + binaries. This option is useful in environments that
50654 + remove the read bits (e.g. file mode 4711) from suid binaries to
50655 + prevent infoleaking of their contents. This option adds
50656 + consistency to the use of that file mode, as the binary could normally
50657 + be read out when run without privileges while ptracing.
50658 +
50659 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50660 + is created.
50661 +
50662 +config GRKERNSEC_SETXID
50663 + bool "Enforce consistent multithreaded privileges"
50664 + help
50665 + If you say Y here, a change from a root uid to a non-root uid
50666 + in a multithreaded application will cause the resulting uids,
50667 + gids, supplementary groups, and capabilities in that thread
50668 + to be propagated to the other threads of the process. In most
50669 + cases this is unnecessary, as glibc will emulate this behavior
50670 + on behalf of the application. Other libcs do not act in the
50671 + same way, allowing the other threads of the process to continue
50672 + running with root privileges. If the sysctl option is enabled,
50673 + a sysctl option with name "consistent_setxid" is created.
50674 +
50675 +config GRKERNSEC_TPE
50676 + bool "Trusted Path Execution (TPE)"
50677 + help
50678 + If you say Y here, you will be able to choose a gid to add to the
50679 + supplementary groups of users you want to mark as "untrusted."
50680 + These users will not be able to execute any files that are not in
50681 + root-owned directories writable only by root. If the sysctl option
50682 + is enabled, a sysctl option with name "tpe" is created.
50683 +
50684 +config GRKERNSEC_TPE_ALL
50685 + bool "Partially restrict all non-root users"
50686 + depends on GRKERNSEC_TPE
50687 + help
50688 + If you say Y here, all non-root users will be covered under
50689 + a weaker TPE restriction. This is separate from, and in addition to,
50690 + the main TPE options that you have selected elsewhere. Thus, if a
50691 + "trusted" GID is chosen, this restriction applies to even that GID.
50692 + Under this restriction, all non-root users will only be allowed to
50693 + execute files in directories they own that are not group or
50694 + world-writable, or in directories owned by root and writable only by
50695 + root. If the sysctl option is enabled, a sysctl option with name
50696 + "tpe_restrict_all" is created.
50697 +
50698 +config GRKERNSEC_TPE_INVERT
50699 + bool "Invert GID option"
50700 + depends on GRKERNSEC_TPE
50701 + help
50702 + If you say Y here, the group you specify in the TPE configuration will
50703 + decide what group TPE restrictions will be *disabled* for. This
50704 + option is useful if you want TPE restrictions to be applied to most
50705 + users on the system. If the sysctl option is enabled, a sysctl option
50706 + with name "tpe_invert" is created. Unlike other sysctl options, this
50707 + entry will default to on for backward-compatibility.
50708 +
50709 +config GRKERNSEC_TPE_GID
50710 + int "GID for untrusted users"
50711 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50712 + default 1005
50713 + help
50714 + Setting this GID determines what group TPE restrictions will be
50715 + *enabled* for. If the sysctl option is enabled, a sysctl option
50716 + with name "tpe_gid" is created.
50717 +
50718 +config GRKERNSEC_TPE_GID
50719 + int "GID for trusted users"
50720 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50721 + default 1005
50722 + help
50723 + Setting this GID determines what group TPE restrictions will be
50724 + *disabled* for. If the sysctl option is enabled, a sysctl option
50725 + with name "tpe_gid" is created.
50726 +
50727 +endmenu
50728 +menu "Network Protections"
50729 +depends on GRKERNSEC
50730 +
50731 +config GRKERNSEC_RANDNET
50732 + bool "Larger entropy pools"
50733 + help
50734 + If you say Y here, the entropy pools used for many features of Linux
50735 + and grsecurity will be doubled in size. Since several grsecurity
50736 + features use additional randomness, it is recommended that you say Y
50737 + here. Saying Y here has a similar effect as modifying
50738 + /proc/sys/kernel/random/poolsize.
50739 +
50740 +config GRKERNSEC_BLACKHOLE
50741 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50742 + depends on NET
50743 + help
50744 + If you say Y here, neither TCP resets nor ICMP
50745 + destination-unreachable packets will be sent in response to packets
50746 + sent to ports for which no associated listening process exists.
50747 + This feature supports both IPV4 and IPV6 and exempts the
50748 + loopback interface from blackholing. Enabling this feature
50749 + makes a host more resilient to DoS attacks and reduces network
50750 + visibility against scanners.
50751 +
50752 + The blackhole feature as-implemented is equivalent to the FreeBSD
50753 + blackhole feature, as it prevents RST responses to all packets, not
50754 + just SYNs. Under most application behavior this causes no
50755 + problems, but applications (like haproxy) may not close certain
50756 + connections in a way that cleanly terminates them on the remote
50757 + end, leaving the remote host in LAST_ACK state. Because of this
50758 + side-effect and to prevent intentional LAST_ACK DoSes, this
50759 + feature also adds automatic mitigation against such attacks.
50760 + The mitigation drastically reduces the amount of time a socket
50761 + can spend in LAST_ACK state. If you're using haproxy and not
50762 + all servers it connects to have this option enabled, consider
50763 + disabling this feature on the haproxy host.
50764 +
50765 + If the sysctl option is enabled, two sysctl options with names
50766 + "ip_blackhole" and "lastack_retries" will be created.
50767 + While "ip_blackhole" takes the standard zero/non-zero on/off
50768 + toggle, "lastack_retries" uses the same kinds of values as
50769 + "tcp_retries1" and "tcp_retries2". The default value of 4
50770 + prevents a socket from lasting more than 45 seconds in LAST_ACK
50771 + state.
50772 +
50773 +config GRKERNSEC_SOCKET
50774 + bool "Socket restrictions"
50775 + depends on NET
50776 + help
50777 + If you say Y here, you will be able to choose from several options.
50778 + If you assign a GID on your system and add it to the supplementary
50779 + groups of users you want to restrict socket access to, this patch
50780 + will perform up to three things, based on the option(s) you choose.
50781 +
50782 +config GRKERNSEC_SOCKET_ALL
50783 + bool "Deny any sockets to group"
50784 + depends on GRKERNSEC_SOCKET
50785 + help
50786 + If you say Y here, you will be able to choose a GID of whose users will
50787 + be unable to connect to other hosts from your machine or run server
50788 + applications from your machine. If the sysctl option is enabled, a
50789 + sysctl option with name "socket_all" is created.
50790 +
50791 +config GRKERNSEC_SOCKET_ALL_GID
50792 + int "GID to deny all sockets for"
50793 + depends on GRKERNSEC_SOCKET_ALL
50794 + default 1004
50795 + help
50796 + Here you can choose the GID to disable socket access for. Remember to
50797 + add the users you want socket access disabled for to the GID
50798 + specified here. If the sysctl option is enabled, a sysctl option
50799 + with name "socket_all_gid" is created.
50800 +
50801 +config GRKERNSEC_SOCKET_CLIENT
50802 + bool "Deny client sockets to group"
50803 + depends on GRKERNSEC_SOCKET
50804 + help
50805 + If you say Y here, you will be able to choose a GID of whose users will
50806 + be unable to connect to other hosts from your machine, but will be
50807 + able to run servers. If this option is enabled, all users in the group
50808 + you specify will have to use passive mode when initiating ftp transfers
50809 + from the shell on your machine. If the sysctl option is enabled, a
50810 + sysctl option with name "socket_client" is created.
50811 +
50812 +config GRKERNSEC_SOCKET_CLIENT_GID
50813 + int "GID to deny client sockets for"
50814 + depends on GRKERNSEC_SOCKET_CLIENT
50815 + default 1003
50816 + help
50817 + Here you can choose the GID to disable client socket access for.
50818 + Remember to add the users you want client socket access disabled for to
50819 + the GID specified here. If the sysctl option is enabled, a sysctl
50820 + option with name "socket_client_gid" is created.
50821 +
50822 +config GRKERNSEC_SOCKET_SERVER
50823 + bool "Deny server sockets to group"
50824 + depends on GRKERNSEC_SOCKET
50825 + help
50826 + If you say Y here, you will be able to choose a GID of whose users will
50827 + be unable to run server applications from your machine. If the sysctl
50828 + option is enabled, a sysctl option with name "socket_server" is created.
50829 +
50830 +config GRKERNSEC_SOCKET_SERVER_GID
50831 + int "GID to deny server sockets for"
50832 + depends on GRKERNSEC_SOCKET_SERVER
50833 + default 1002
50834 + help
50835 + Here you can choose the GID to disable server socket access for.
50836 + Remember to add the users you want server socket access disabled for to
50837 + the GID specified here. If the sysctl option is enabled, a sysctl
50838 + option with name "socket_server_gid" is created.
50839 +
50840 +endmenu
50841 +menu "Sysctl support"
50842 +depends on GRKERNSEC && SYSCTL
50843 +
50844 +config GRKERNSEC_SYSCTL
50845 + bool "Sysctl support"
50846 + help
50847 + If you say Y here, you will be able to change the options that
50848 + grsecurity runs with at bootup, without having to recompile your
50849 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50850 + to enable (1) or disable (0) various features. All the sysctl entries
50851 + are mutable until the "grsec_lock" entry is set to a non-zero value.
50852 + All features enabled in the kernel configuration are disabled at boot
50853 + if you do not say Y to the "Turn on features by default" option.
50854 + All options should be set at startup, and the grsec_lock entry should
50855 + be set to a non-zero value after all the options are set.
50856 + *THIS IS EXTREMELY IMPORTANT*
50857 +
50858 +config GRKERNSEC_SYSCTL_DISTRO
50859 + bool "Extra sysctl support for distro makers (READ HELP)"
50860 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50861 + help
50862 + If you say Y here, additional sysctl options will be created
50863 + for features that affect processes running as root. Therefore,
50864 + it is critical when using this option that the grsec_lock entry be
50865 + enabled after boot. Only distros with prebuilt kernel packages
50866 + with this option enabled that can ensure grsec_lock is enabled
50867 + after boot should use this option.
50868 + *Failure to set grsec_lock after boot makes all grsec features
50869 + this option covers useless*
50870 +
50871 + Currently this option creates the following sysctl entries:
50872 + "Disable Privileged I/O": "disable_priv_io"
50873 +
50874 +config GRKERNSEC_SYSCTL_ON
50875 + bool "Turn on features by default"
50876 + depends on GRKERNSEC_SYSCTL
50877 + help
50878 + If you say Y here, instead of having all features enabled in the
50879 + kernel configuration disabled at boot time, the features will be
50880 + enabled at boot time. It is recommended you say Y here unless
50881 + there is some reason you would want all sysctl-tunable features to
50882 + be disabled by default. As mentioned elsewhere, it is important
50883 + to enable the grsec_lock entry once you have finished modifying
50884 + the sysctl entries.
50885 +
50886 +endmenu
50887 +menu "Logging Options"
50888 +depends on GRKERNSEC
50889 +
50890 +config GRKERNSEC_FLOODTIME
50891 + int "Seconds in between log messages (minimum)"
50892 + default 10
50893 + help
50894 + This option allows you to enforce the number of seconds between
50895 + grsecurity log messages. The default should be suitable for most
50896 + people, however, if you choose to change it, choose a value small enough
50897 + to allow informative logs to be produced, but large enough to
50898 + prevent flooding.
50899 +
50900 +config GRKERNSEC_FLOODBURST
50901 + int "Number of messages in a burst (maximum)"
50902 + default 6
50903 + help
50904 + This option allows you to choose the maximum number of messages allowed
50905 + within the flood time interval you chose in a separate option. The
50906 + default should be suitable for most people, however if you find that
50907 + many of your logs are being interpreted as flooding, you may want to
50908 + raise this value.
50909 +
50910 +endmenu
50911 +
50912 +endmenu
50913 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50914 new file mode 100644
50915 index 0000000..1b9afa9
50916 --- /dev/null
50917 +++ b/grsecurity/Makefile
50918 @@ -0,0 +1,38 @@
50919 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50920 +# during 2001-2009 it has been completely redesigned by Brad Spengler
50921 +# into an RBAC system
50922 +#
50923 +# All code in this directory and various hooks inserted throughout the kernel
50924 +# are copyright Brad Spengler - Open Source Security, Inc., and released
50925 +# under the GPL v2 or higher
50926 +
50927 +KBUILD_CFLAGS += -Werror
50928 +
50929 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50930 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
50931 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50932 +
50933 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50934 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50935 + gracl_learn.o grsec_log.o
50936 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50937 +
50938 +ifdef CONFIG_NET
50939 +obj-y += grsec_sock.o
50940 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50941 +endif
50942 +
50943 +ifndef CONFIG_GRKERNSEC
50944 +obj-y += grsec_disabled.o
50945 +endif
50946 +
50947 +ifdef CONFIG_GRKERNSEC_HIDESYM
50948 +extra-y := grsec_hidesym.o
50949 +$(obj)/grsec_hidesym.o:
50950 + @-chmod -f 500 /boot
50951 + @-chmod -f 500 /lib/modules
50952 + @-chmod -f 500 /lib64/modules
50953 + @-chmod -f 500 /lib32/modules
50954 + @-chmod -f 700 .
50955 + @echo ' grsec: protected kernel image paths'
50956 +endif
50957 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50958 new file mode 100644
50959 index 0000000..19b3cba
50960 --- /dev/null
50961 +++ b/grsecurity/gracl.c
50962 @@ -0,0 +1,4133 @@
50963 +#include <linux/kernel.h>
50964 +#include <linux/module.h>
50965 +#include <linux/sched.h>
50966 +#include <linux/mm.h>
50967 +#include <linux/file.h>
50968 +#include <linux/fs.h>
50969 +#include <linux/namei.h>
50970 +#include <linux/mount.h>
50971 +#include <linux/tty.h>
50972 +#include <linux/proc_fs.h>
50973 +#include <linux/lglock.h>
50974 +#include <linux/slab.h>
50975 +#include <linux/vmalloc.h>
50976 +#include <linux/types.h>
50977 +#include <linux/sysctl.h>
50978 +#include <linux/netdevice.h>
50979 +#include <linux/ptrace.h>
50980 +#include <linux/gracl.h>
50981 +#include <linux/gralloc.h>
50982 +#include <linux/security.h>
50983 +#include <linux/grinternal.h>
50984 +#include <linux/pid_namespace.h>
50985 +#include <linux/fdtable.h>
50986 +#include <linux/percpu.h>
50987 +
50988 +#include <asm/uaccess.h>
50989 +#include <asm/errno.h>
50990 +#include <asm/mman.h>
50991 +
50992 +static struct acl_role_db acl_role_set;
50993 +static struct name_db name_set;
50994 +static struct inodev_db inodev_set;
50995 +
50996 +/* for keeping track of userspace pointers used for subjects, so we
50997 + can share references in the kernel as well
50998 +*/
50999 +
51000 +static struct path real_root;
51001 +
51002 +static struct acl_subj_map_db subj_map_set;
51003 +
51004 +static struct acl_role_label *default_role;
51005 +
51006 +static struct acl_role_label *role_list;
51007 +
51008 +static u16 acl_sp_role_value;
51009 +
51010 +extern char *gr_shared_page[4];
51011 +static DEFINE_MUTEX(gr_dev_mutex);
51012 +DEFINE_RWLOCK(gr_inode_lock);
51013 +
51014 +struct gr_arg *gr_usermode;
51015 +
51016 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51017 +
51018 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51019 +extern void gr_clear_learn_entries(void);
51020 +
51021 +#ifdef CONFIG_GRKERNSEC_RESLOG
51022 +extern void gr_log_resource(const struct task_struct *task,
51023 + const int res, const unsigned long wanted, const int gt);
51024 +#endif
51025 +
51026 +unsigned char *gr_system_salt;
51027 +unsigned char *gr_system_sum;
51028 +
51029 +static struct sprole_pw **acl_special_roles = NULL;
51030 +static __u16 num_sprole_pws = 0;
51031 +
51032 +static struct acl_role_label *kernel_role = NULL;
51033 +
51034 +static unsigned int gr_auth_attempts = 0;
51035 +static unsigned long gr_auth_expires = 0UL;
51036 +
51037 +#ifdef CONFIG_NET
51038 +extern struct vfsmount *sock_mnt;
51039 +#endif
51040 +
51041 +extern struct vfsmount *pipe_mnt;
51042 +extern struct vfsmount *shm_mnt;
51043 +#ifdef CONFIG_HUGETLBFS
51044 +extern struct vfsmount *hugetlbfs_vfsmount;
51045 +#endif
51046 +
51047 +static struct acl_object_label *fakefs_obj_rw;
51048 +static struct acl_object_label *fakefs_obj_rwx;
51049 +
51050 +extern int gr_init_uidset(void);
51051 +extern void gr_free_uidset(void);
51052 +extern void gr_remove_uid(uid_t uid);
51053 +extern int gr_find_uid(uid_t uid);
51054 +
51055 +DECLARE_BRLOCK(vfsmount_lock);
51056 +
51057 +__inline__ int
51058 +gr_acl_is_enabled(void)
51059 +{
51060 + return (gr_status & GR_READY);
51061 +}
51062 +
51063 +#ifdef CONFIG_BTRFS_FS
51064 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51065 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51066 +#endif
51067 +
51068 +static inline dev_t __get_dev(const struct dentry *dentry)
51069 +{
51070 +#ifdef CONFIG_BTRFS_FS
51071 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51072 + return get_btrfs_dev_from_inode(dentry->d_inode);
51073 + else
51074 +#endif
51075 + return dentry->d_inode->i_sb->s_dev;
51076 +}
51077 +
51078 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51079 +{
51080 + return __get_dev(dentry);
51081 +}
51082 +
51083 +static char gr_task_roletype_to_char(struct task_struct *task)
51084 +{
51085 + switch (task->role->roletype &
51086 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51087 + GR_ROLE_SPECIAL)) {
51088 + case GR_ROLE_DEFAULT:
51089 + return 'D';
51090 + case GR_ROLE_USER:
51091 + return 'U';
51092 + case GR_ROLE_GROUP:
51093 + return 'G';
51094 + case GR_ROLE_SPECIAL:
51095 + return 'S';
51096 + }
51097 +
51098 + return 'X';
51099 +}
51100 +
51101 +char gr_roletype_to_char(void)
51102 +{
51103 + return gr_task_roletype_to_char(current);
51104 +}
51105 +
51106 +__inline__ int
51107 +gr_acl_tpe_check(void)
51108 +{
51109 + if (unlikely(!(gr_status & GR_READY)))
51110 + return 0;
51111 + if (current->role->roletype & GR_ROLE_TPE)
51112 + return 1;
51113 + else
51114 + return 0;
51115 +}
51116 +
51117 +int
51118 +gr_handle_rawio(const struct inode *inode)
51119 +{
51120 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51121 + if (inode && S_ISBLK(inode->i_mode) &&
51122 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51123 + !capable(CAP_SYS_RAWIO))
51124 + return 1;
51125 +#endif
51126 + return 0;
51127 +}
51128 +
51129 +static int
51130 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51131 +{
51132 + if (likely(lena != lenb))
51133 + return 0;
51134 +
51135 + return !memcmp(a, b, lena);
51136 +}
51137 +
51138 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51139 +{
51140 + *buflen -= namelen;
51141 + if (*buflen < 0)
51142 + return -ENAMETOOLONG;
51143 + *buffer -= namelen;
51144 + memcpy(*buffer, str, namelen);
51145 + return 0;
51146 +}
51147 +
51148 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51149 +{
51150 + return prepend(buffer, buflen, name->name, name->len);
51151 +}
51152 +
51153 +static int prepend_path(const struct path *path, struct path *root,
51154 + char **buffer, int *buflen)
51155 +{
51156 + struct dentry *dentry = path->dentry;
51157 + struct vfsmount *vfsmnt = path->mnt;
51158 + bool slash = false;
51159 + int error = 0;
51160 +
51161 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51162 + struct dentry * parent;
51163 +
51164 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51165 + /* Global root? */
51166 + if (vfsmnt->mnt_parent == vfsmnt) {
51167 + goto out;
51168 + }
51169 + dentry = vfsmnt->mnt_mountpoint;
51170 + vfsmnt = vfsmnt->mnt_parent;
51171 + continue;
51172 + }
51173 + parent = dentry->d_parent;
51174 + prefetch(parent);
51175 + spin_lock(&dentry->d_lock);
51176 + error = prepend_name(buffer, buflen, &dentry->d_name);
51177 + spin_unlock(&dentry->d_lock);
51178 + if (!error)
51179 + error = prepend(buffer, buflen, "/", 1);
51180 + if (error)
51181 + break;
51182 +
51183 + slash = true;
51184 + dentry = parent;
51185 + }
51186 +
51187 +out:
51188 + if (!error && !slash)
51189 + error = prepend(buffer, buflen, "/", 1);
51190 +
51191 + return error;
51192 +}
51193 +
51194 +/* this must be called with vfsmount_lock and rename_lock held */
51195 +
51196 +static char *__our_d_path(const struct path *path, struct path *root,
51197 + char *buf, int buflen)
51198 +{
51199 + char *res = buf + buflen;
51200 + int error;
51201 +
51202 + prepend(&res, &buflen, "\0", 1);
51203 + error = prepend_path(path, root, &res, &buflen);
51204 + if (error)
51205 + return ERR_PTR(error);
51206 +
51207 + return res;
51208 +}
51209 +
51210 +static char *
51211 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51212 +{
51213 + char *retval;
51214 +
51215 + retval = __our_d_path(path, root, buf, buflen);
51216 + if (unlikely(IS_ERR(retval)))
51217 + retval = strcpy(buf, "<path too long>");
51218 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51219 + retval[1] = '\0';
51220 +
51221 + return retval;
51222 +}
51223 +
51224 +static char *
51225 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51226 + char *buf, int buflen)
51227 +{
51228 + struct path path;
51229 + char *res;
51230 +
51231 + path.dentry = (struct dentry *)dentry;
51232 + path.mnt = (struct vfsmount *)vfsmnt;
51233 +
51234 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51235 + by the RBAC system */
51236 + res = gen_full_path(&path, &real_root, buf, buflen);
51237 +
51238 + return res;
51239 +}
51240 +
51241 +static char *
51242 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51243 + char *buf, int buflen)
51244 +{
51245 + char *res;
51246 + struct path path;
51247 + struct path root;
51248 + struct task_struct *reaper = &init_task;
51249 +
51250 + path.dentry = (struct dentry *)dentry;
51251 + path.mnt = (struct vfsmount *)vfsmnt;
51252 +
51253 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51254 + get_fs_root(reaper->fs, &root);
51255 +
51256 + write_seqlock(&rename_lock);
51257 + br_read_lock(vfsmount_lock);
51258 + res = gen_full_path(&path, &root, buf, buflen);
51259 + br_read_unlock(vfsmount_lock);
51260 + write_sequnlock(&rename_lock);
51261 +
51262 + path_put(&root);
51263 + return res;
51264 +}
51265 +
51266 +static char *
51267 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51268 +{
51269 + char *ret;
51270 + write_seqlock(&rename_lock);
51271 + br_read_lock(vfsmount_lock);
51272 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51273 + PAGE_SIZE);
51274 + br_read_unlock(vfsmount_lock);
51275 + write_sequnlock(&rename_lock);
51276 + return ret;
51277 +}
51278 +
51279 +static char *
51280 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51281 +{
51282 + char *ret;
51283 + char *buf;
51284 + int buflen;
51285 +
51286 + write_seqlock(&rename_lock);
51287 + br_read_lock(vfsmount_lock);
51288 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51289 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51290 + buflen = (int)(ret - buf);
51291 + if (buflen >= 5)
51292 + prepend(&ret, &buflen, "/proc", 5);
51293 + else
51294 + ret = strcpy(buf, "<path too long>");
51295 + br_read_unlock(vfsmount_lock);
51296 + write_sequnlock(&rename_lock);
51297 + return ret;
51298 +}
51299 +
51300 +char *
51301 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51302 +{
51303 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51304 + PAGE_SIZE);
51305 +}
51306 +
51307 +char *
51308 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51309 +{
51310 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51311 + PAGE_SIZE);
51312 +}
51313 +
51314 +char *
51315 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51316 +{
51317 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51318 + PAGE_SIZE);
51319 +}
51320 +
51321 +char *
51322 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51323 +{
51324 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51325 + PAGE_SIZE);
51326 +}
51327 +
51328 +char *
51329 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51330 +{
51331 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51332 + PAGE_SIZE);
51333 +}
51334 +
51335 +__inline__ __u32
51336 +to_gr_audit(const __u32 reqmode)
51337 +{
51338 + /* masks off auditable permission flags, then shifts them to create
51339 + auditing flags, and adds the special case of append auditing if
51340 + we're requesting write */
51341 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51342 +}
51343 +
51344 +struct acl_subject_label *
51345 +lookup_subject_map(const struct acl_subject_label *userp)
51346 +{
51347 + unsigned int index = shash(userp, subj_map_set.s_size);
51348 + struct subject_map *match;
51349 +
51350 + match = subj_map_set.s_hash[index];
51351 +
51352 + while (match && match->user != userp)
51353 + match = match->next;
51354 +
51355 + if (match != NULL)
51356 + return match->kernel;
51357 + else
51358 + return NULL;
51359 +}
51360 +
51361 +static void
51362 +insert_subj_map_entry(struct subject_map *subjmap)
51363 +{
51364 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51365 + struct subject_map **curr;
51366 +
51367 + subjmap->prev = NULL;
51368 +
51369 + curr = &subj_map_set.s_hash[index];
51370 + if (*curr != NULL)
51371 + (*curr)->prev = subjmap;
51372 +
51373 + subjmap->next = *curr;
51374 + *curr = subjmap;
51375 +
51376 + return;
51377 +}
51378 +
51379 +static struct acl_role_label *
51380 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51381 + const gid_t gid)
51382 +{
51383 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51384 + struct acl_role_label *match;
51385 + struct role_allowed_ip *ipp;
51386 + unsigned int x;
51387 + u32 curr_ip = task->signal->curr_ip;
51388 +
51389 + task->signal->saved_ip = curr_ip;
51390 +
51391 + match = acl_role_set.r_hash[index];
51392 +
51393 + while (match) {
51394 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51395 + for (x = 0; x < match->domain_child_num; x++) {
51396 + if (match->domain_children[x] == uid)
51397 + goto found;
51398 + }
51399 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51400 + break;
51401 + match = match->next;
51402 + }
51403 +found:
51404 + if (match == NULL) {
51405 + try_group:
51406 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51407 + match = acl_role_set.r_hash[index];
51408 +
51409 + while (match) {
51410 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51411 + for (x = 0; x < match->domain_child_num; x++) {
51412 + if (match->domain_children[x] == gid)
51413 + goto found2;
51414 + }
51415 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51416 + break;
51417 + match = match->next;
51418 + }
51419 +found2:
51420 + if (match == NULL)
51421 + match = default_role;
51422 + if (match->allowed_ips == NULL)
51423 + return match;
51424 + else {
51425 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51426 + if (likely
51427 + ((ntohl(curr_ip) & ipp->netmask) ==
51428 + (ntohl(ipp->addr) & ipp->netmask)))
51429 + return match;
51430 + }
51431 + match = default_role;
51432 + }
51433 + } else if (match->allowed_ips == NULL) {
51434 + return match;
51435 + } else {
51436 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51437 + if (likely
51438 + ((ntohl(curr_ip) & ipp->netmask) ==
51439 + (ntohl(ipp->addr) & ipp->netmask)))
51440 + return match;
51441 + }
51442 + goto try_group;
51443 + }
51444 +
51445 + return match;
51446 +}
51447 +
51448 +struct acl_subject_label *
51449 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51450 + const struct acl_role_label *role)
51451 +{
51452 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51453 + struct acl_subject_label *match;
51454 +
51455 + match = role->subj_hash[index];
51456 +
51457 + while (match && (match->inode != ino || match->device != dev ||
51458 + (match->mode & GR_DELETED))) {
51459 + match = match->next;
51460 + }
51461 +
51462 + if (match && !(match->mode & GR_DELETED))
51463 + return match;
51464 + else
51465 + return NULL;
51466 +}
51467 +
51468 +struct acl_subject_label *
51469 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51470 + const struct acl_role_label *role)
51471 +{
51472 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51473 + struct acl_subject_label *match;
51474 +
51475 + match = role->subj_hash[index];
51476 +
51477 + while (match && (match->inode != ino || match->device != dev ||
51478 + !(match->mode & GR_DELETED))) {
51479 + match = match->next;
51480 + }
51481 +
51482 + if (match && (match->mode & GR_DELETED))
51483 + return match;
51484 + else
51485 + return NULL;
51486 +}
51487 +
51488 +static struct acl_object_label *
51489 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51490 + const struct acl_subject_label *subj)
51491 +{
51492 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51493 + struct acl_object_label *match;
51494 +
51495 + match = subj->obj_hash[index];
51496 +
51497 + while (match && (match->inode != ino || match->device != dev ||
51498 + (match->mode & GR_DELETED))) {
51499 + match = match->next;
51500 + }
51501 +
51502 + if (match && !(match->mode & GR_DELETED))
51503 + return match;
51504 + else
51505 + return NULL;
51506 +}
51507 +
51508 +static struct acl_object_label *
51509 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51510 + const struct acl_subject_label *subj)
51511 +{
51512 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51513 + struct acl_object_label *match;
51514 +
51515 + match = subj->obj_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 +
51525 + match = subj->obj_hash[index];
51526 +
51527 + while (match && (match->inode != ino || match->device != dev ||
51528 + (match->mode & GR_DELETED))) {
51529 + match = match->next;
51530 + }
51531 +
51532 + if (match && !(match->mode & GR_DELETED))
51533 + return match;
51534 + else
51535 + return NULL;
51536 +}
51537 +
51538 +static struct name_entry *
51539 +lookup_name_entry(const char *name)
51540 +{
51541 + unsigned int len = strlen(name);
51542 + unsigned int key = full_name_hash(name, len);
51543 + unsigned int index = key % name_set.n_size;
51544 + struct name_entry *match;
51545 +
51546 + match = name_set.n_hash[index];
51547 +
51548 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51549 + match = match->next;
51550 +
51551 + return match;
51552 +}
51553 +
51554 +static struct name_entry *
51555 +lookup_name_entry_create(const char *name)
51556 +{
51557 + unsigned int len = strlen(name);
51558 + unsigned int key = full_name_hash(name, len);
51559 + unsigned int index = key % name_set.n_size;
51560 + struct name_entry *match;
51561 +
51562 + match = name_set.n_hash[index];
51563 +
51564 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51565 + !match->deleted))
51566 + match = match->next;
51567 +
51568 + if (match && match->deleted)
51569 + return match;
51570 +
51571 + match = name_set.n_hash[index];
51572 +
51573 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51574 + match->deleted))
51575 + match = match->next;
51576 +
51577 + if (match && !match->deleted)
51578 + return match;
51579 + else
51580 + return NULL;
51581 +}
51582 +
51583 +static struct inodev_entry *
51584 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
51585 +{
51586 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
51587 + struct inodev_entry *match;
51588 +
51589 + match = inodev_set.i_hash[index];
51590 +
51591 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51592 + match = match->next;
51593 +
51594 + return match;
51595 +}
51596 +
51597 +static void
51598 +insert_inodev_entry(struct inodev_entry *entry)
51599 +{
51600 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51601 + inodev_set.i_size);
51602 + struct inodev_entry **curr;
51603 +
51604 + entry->prev = NULL;
51605 +
51606 + curr = &inodev_set.i_hash[index];
51607 + if (*curr != NULL)
51608 + (*curr)->prev = entry;
51609 +
51610 + entry->next = *curr;
51611 + *curr = entry;
51612 +
51613 + return;
51614 +}
51615 +
51616 +static void
51617 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51618 +{
51619 + unsigned int index =
51620 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51621 + struct acl_role_label **curr;
51622 + struct acl_role_label *tmp;
51623 +
51624 + curr = &acl_role_set.r_hash[index];
51625 +
51626 + /* if role was already inserted due to domains and already has
51627 + a role in the same bucket as it attached, then we need to
51628 + combine these two buckets
51629 + */
51630 + if (role->next) {
51631 + tmp = role->next;
51632 + while (tmp->next)
51633 + tmp = tmp->next;
51634 + tmp->next = *curr;
51635 + } else
51636 + role->next = *curr;
51637 + *curr = role;
51638 +
51639 + return;
51640 +}
51641 +
51642 +static void
51643 +insert_acl_role_label(struct acl_role_label *role)
51644 +{
51645 + int i;
51646 +
51647 + if (role_list == NULL) {
51648 + role_list = role;
51649 + role->prev = NULL;
51650 + } else {
51651 + role->prev = role_list;
51652 + role_list = role;
51653 + }
51654 +
51655 + /* used for hash chains */
51656 + role->next = NULL;
51657 +
51658 + if (role->roletype & GR_ROLE_DOMAIN) {
51659 + for (i = 0; i < role->domain_child_num; i++)
51660 + __insert_acl_role_label(role, role->domain_children[i]);
51661 + } else
51662 + __insert_acl_role_label(role, role->uidgid);
51663 +}
51664 +
51665 +static int
51666 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51667 +{
51668 + struct name_entry **curr, *nentry;
51669 + struct inodev_entry *ientry;
51670 + unsigned int len = strlen(name);
51671 + unsigned int key = full_name_hash(name, len);
51672 + unsigned int index = key % name_set.n_size;
51673 +
51674 + curr = &name_set.n_hash[index];
51675 +
51676 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51677 + curr = &((*curr)->next);
51678 +
51679 + if (*curr != NULL)
51680 + return 1;
51681 +
51682 + nentry = acl_alloc(sizeof (struct name_entry));
51683 + if (nentry == NULL)
51684 + return 0;
51685 + ientry = acl_alloc(sizeof (struct inodev_entry));
51686 + if (ientry == NULL)
51687 + return 0;
51688 + ientry->nentry = nentry;
51689 +
51690 + nentry->key = key;
51691 + nentry->name = name;
51692 + nentry->inode = inode;
51693 + nentry->device = device;
51694 + nentry->len = len;
51695 + nentry->deleted = deleted;
51696 +
51697 + nentry->prev = NULL;
51698 + curr = &name_set.n_hash[index];
51699 + if (*curr != NULL)
51700 + (*curr)->prev = nentry;
51701 + nentry->next = *curr;
51702 + *curr = nentry;
51703 +
51704 + /* insert us into the table searchable by inode/dev */
51705 + insert_inodev_entry(ientry);
51706 +
51707 + return 1;
51708 +}
51709 +
51710 +static void
51711 +insert_acl_obj_label(struct acl_object_label *obj,
51712 + struct acl_subject_label *subj)
51713 +{
51714 + unsigned int index =
51715 + fhash(obj->inode, obj->device, subj->obj_hash_size);
51716 + struct acl_object_label **curr;
51717 +
51718 +
51719 + obj->prev = NULL;
51720 +
51721 + curr = &subj->obj_hash[index];
51722 + if (*curr != NULL)
51723 + (*curr)->prev = obj;
51724 +
51725 + obj->next = *curr;
51726 + *curr = obj;
51727 +
51728 + return;
51729 +}
51730 +
51731 +static void
51732 +insert_acl_subj_label(struct acl_subject_label *obj,
51733 + struct acl_role_label *role)
51734 +{
51735 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51736 + struct acl_subject_label **curr;
51737 +
51738 + obj->prev = NULL;
51739 +
51740 + curr = &role->subj_hash[index];
51741 + if (*curr != NULL)
51742 + (*curr)->prev = obj;
51743 +
51744 + obj->next = *curr;
51745 + *curr = obj;
51746 +
51747 + return;
51748 +}
51749 +
51750 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51751 +
51752 +static void *
51753 +create_table(__u32 * len, int elementsize)
51754 +{
51755 + unsigned int table_sizes[] = {
51756 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51757 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51758 + 4194301, 8388593, 16777213, 33554393, 67108859
51759 + };
51760 + void *newtable = NULL;
51761 + unsigned int pwr = 0;
51762 +
51763 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51764 + table_sizes[pwr] <= *len)
51765 + pwr++;
51766 +
51767 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51768 + return newtable;
51769 +
51770 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51771 + newtable =
51772 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51773 + else
51774 + newtable = vmalloc(table_sizes[pwr] * elementsize);
51775 +
51776 + *len = table_sizes[pwr];
51777 +
51778 + return newtable;
51779 +}
51780 +
51781 +static int
51782 +init_variables(const struct gr_arg *arg)
51783 +{
51784 + struct task_struct *reaper = &init_task;
51785 + unsigned int stacksize;
51786 +
51787 + subj_map_set.s_size = arg->role_db.num_subjects;
51788 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51789 + name_set.n_size = arg->role_db.num_objects;
51790 + inodev_set.i_size = arg->role_db.num_objects;
51791 +
51792 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
51793 + !name_set.n_size || !inodev_set.i_size)
51794 + return 1;
51795 +
51796 + if (!gr_init_uidset())
51797 + return 1;
51798 +
51799 + /* set up the stack that holds allocation info */
51800 +
51801 + stacksize = arg->role_db.num_pointers + 5;
51802 +
51803 + if (!acl_alloc_stack_init(stacksize))
51804 + return 1;
51805 +
51806 + /* grab reference for the real root dentry and vfsmount */
51807 + get_fs_root(reaper->fs, &real_root);
51808 +
51809 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51810 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51811 +#endif
51812 +
51813 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51814 + if (fakefs_obj_rw == NULL)
51815 + return 1;
51816 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51817 +
51818 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51819 + if (fakefs_obj_rwx == NULL)
51820 + return 1;
51821 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51822 +
51823 + subj_map_set.s_hash =
51824 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51825 + acl_role_set.r_hash =
51826 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51827 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51828 + inodev_set.i_hash =
51829 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51830 +
51831 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51832 + !name_set.n_hash || !inodev_set.i_hash)
51833 + return 1;
51834 +
51835 + memset(subj_map_set.s_hash, 0,
51836 + sizeof(struct subject_map *) * subj_map_set.s_size);
51837 + memset(acl_role_set.r_hash, 0,
51838 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
51839 + memset(name_set.n_hash, 0,
51840 + sizeof (struct name_entry *) * name_set.n_size);
51841 + memset(inodev_set.i_hash, 0,
51842 + sizeof (struct inodev_entry *) * inodev_set.i_size);
51843 +
51844 + return 0;
51845 +}
51846 +
51847 +/* free information not needed after startup
51848 + currently contains user->kernel pointer mappings for subjects
51849 +*/
51850 +
51851 +static void
51852 +free_init_variables(void)
51853 +{
51854 + __u32 i;
51855 +
51856 + if (subj_map_set.s_hash) {
51857 + for (i = 0; i < subj_map_set.s_size; i++) {
51858 + if (subj_map_set.s_hash[i]) {
51859 + kfree(subj_map_set.s_hash[i]);
51860 + subj_map_set.s_hash[i] = NULL;
51861 + }
51862 + }
51863 +
51864 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51865 + PAGE_SIZE)
51866 + kfree(subj_map_set.s_hash);
51867 + else
51868 + vfree(subj_map_set.s_hash);
51869 + }
51870 +
51871 + return;
51872 +}
51873 +
51874 +static void
51875 +free_variables(void)
51876 +{
51877 + struct acl_subject_label *s;
51878 + struct acl_role_label *r;
51879 + struct task_struct *task, *task2;
51880 + unsigned int x;
51881 +
51882 + gr_clear_learn_entries();
51883 +
51884 + read_lock(&tasklist_lock);
51885 + do_each_thread(task2, task) {
51886 + task->acl_sp_role = 0;
51887 + task->acl_role_id = 0;
51888 + task->acl = NULL;
51889 + task->role = NULL;
51890 + } while_each_thread(task2, task);
51891 + read_unlock(&tasklist_lock);
51892 +
51893 + /* release the reference to the real root dentry and vfsmount */
51894 + path_put(&real_root);
51895 + memset(&real_root, 0, sizeof(real_root));
51896 +
51897 + /* free all object hash tables */
51898 +
51899 + FOR_EACH_ROLE_START(r)
51900 + if (r->subj_hash == NULL)
51901 + goto next_role;
51902 + FOR_EACH_SUBJECT_START(r, s, x)
51903 + if (s->obj_hash == NULL)
51904 + break;
51905 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51906 + kfree(s->obj_hash);
51907 + else
51908 + vfree(s->obj_hash);
51909 + FOR_EACH_SUBJECT_END(s, x)
51910 + FOR_EACH_NESTED_SUBJECT_START(r, s)
51911 + if (s->obj_hash == NULL)
51912 + break;
51913 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51914 + kfree(s->obj_hash);
51915 + else
51916 + vfree(s->obj_hash);
51917 + FOR_EACH_NESTED_SUBJECT_END(s)
51918 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51919 + kfree(r->subj_hash);
51920 + else
51921 + vfree(r->subj_hash);
51922 + r->subj_hash = NULL;
51923 +next_role:
51924 + FOR_EACH_ROLE_END(r)
51925 +
51926 + acl_free_all();
51927 +
51928 + if (acl_role_set.r_hash) {
51929 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
51930 + PAGE_SIZE)
51931 + kfree(acl_role_set.r_hash);
51932 + else
51933 + vfree(acl_role_set.r_hash);
51934 + }
51935 + if (name_set.n_hash) {
51936 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
51937 + PAGE_SIZE)
51938 + kfree(name_set.n_hash);
51939 + else
51940 + vfree(name_set.n_hash);
51941 + }
51942 +
51943 + if (inodev_set.i_hash) {
51944 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
51945 + PAGE_SIZE)
51946 + kfree(inodev_set.i_hash);
51947 + else
51948 + vfree(inodev_set.i_hash);
51949 + }
51950 +
51951 + gr_free_uidset();
51952 +
51953 + memset(&name_set, 0, sizeof (struct name_db));
51954 + memset(&inodev_set, 0, sizeof (struct inodev_db));
51955 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
51956 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
51957 +
51958 + default_role = NULL;
51959 + role_list = NULL;
51960 +
51961 + return;
51962 +}
51963 +
51964 +static __u32
51965 +count_user_objs(struct acl_object_label *userp)
51966 +{
51967 + struct acl_object_label o_tmp;
51968 + __u32 num = 0;
51969 +
51970 + while (userp) {
51971 + if (copy_from_user(&o_tmp, userp,
51972 + sizeof (struct acl_object_label)))
51973 + break;
51974 +
51975 + userp = o_tmp.prev;
51976 + num++;
51977 + }
51978 +
51979 + return num;
51980 +}
51981 +
51982 +static struct acl_subject_label *
51983 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
51984 +
51985 +static int
51986 +copy_user_glob(struct acl_object_label *obj)
51987 +{
51988 + struct acl_object_label *g_tmp, **guser;
51989 + unsigned int len;
51990 + char *tmp;
51991 +
51992 + if (obj->globbed == NULL)
51993 + return 0;
51994 +
51995 + guser = &obj->globbed;
51996 + while (*guser) {
51997 + g_tmp = (struct acl_object_label *)
51998 + acl_alloc(sizeof (struct acl_object_label));
51999 + if (g_tmp == NULL)
52000 + return -ENOMEM;
52001 +
52002 + if (copy_from_user(g_tmp, *guser,
52003 + sizeof (struct acl_object_label)))
52004 + return -EFAULT;
52005 +
52006 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52007 +
52008 + if (!len || len >= PATH_MAX)
52009 + return -EINVAL;
52010 +
52011 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52012 + return -ENOMEM;
52013 +
52014 + if (copy_from_user(tmp, g_tmp->filename, len))
52015 + return -EFAULT;
52016 + tmp[len-1] = '\0';
52017 + g_tmp->filename = tmp;
52018 +
52019 + *guser = g_tmp;
52020 + guser = &(g_tmp->next);
52021 + }
52022 +
52023 + return 0;
52024 +}
52025 +
52026 +static int
52027 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52028 + struct acl_role_label *role)
52029 +{
52030 + struct acl_object_label *o_tmp;
52031 + unsigned int len;
52032 + int ret;
52033 + char *tmp;
52034 +
52035 + while (userp) {
52036 + if ((o_tmp = (struct acl_object_label *)
52037 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52038 + return -ENOMEM;
52039 +
52040 + if (copy_from_user(o_tmp, userp,
52041 + sizeof (struct acl_object_label)))
52042 + return -EFAULT;
52043 +
52044 + userp = o_tmp->prev;
52045 +
52046 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52047 +
52048 + if (!len || len >= PATH_MAX)
52049 + return -EINVAL;
52050 +
52051 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52052 + return -ENOMEM;
52053 +
52054 + if (copy_from_user(tmp, o_tmp->filename, len))
52055 + return -EFAULT;
52056 + tmp[len-1] = '\0';
52057 + o_tmp->filename = tmp;
52058 +
52059 + insert_acl_obj_label(o_tmp, subj);
52060 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52061 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52062 + return -ENOMEM;
52063 +
52064 + ret = copy_user_glob(o_tmp);
52065 + if (ret)
52066 + return ret;
52067 +
52068 + if (o_tmp->nested) {
52069 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52070 + if (IS_ERR(o_tmp->nested))
52071 + return PTR_ERR(o_tmp->nested);
52072 +
52073 + /* insert into nested subject list */
52074 + o_tmp->nested->next = role->hash->first;
52075 + role->hash->first = o_tmp->nested;
52076 + }
52077 + }
52078 +
52079 + return 0;
52080 +}
52081 +
52082 +static __u32
52083 +count_user_subjs(struct acl_subject_label *userp)
52084 +{
52085 + struct acl_subject_label s_tmp;
52086 + __u32 num = 0;
52087 +
52088 + while (userp) {
52089 + if (copy_from_user(&s_tmp, userp,
52090 + sizeof (struct acl_subject_label)))
52091 + break;
52092 +
52093 + userp = s_tmp.prev;
52094 + /* do not count nested subjects against this count, since
52095 + they are not included in the hash table, but are
52096 + attached to objects. We have already counted
52097 + the subjects in userspace for the allocation
52098 + stack
52099 + */
52100 + if (!(s_tmp.mode & GR_NESTED))
52101 + num++;
52102 + }
52103 +
52104 + return num;
52105 +}
52106 +
52107 +static int
52108 +copy_user_allowedips(struct acl_role_label *rolep)
52109 +{
52110 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52111 +
52112 + ruserip = rolep->allowed_ips;
52113 +
52114 + while (ruserip) {
52115 + rlast = rtmp;
52116 +
52117 + if ((rtmp = (struct role_allowed_ip *)
52118 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52119 + return -ENOMEM;
52120 +
52121 + if (copy_from_user(rtmp, ruserip,
52122 + sizeof (struct role_allowed_ip)))
52123 + return -EFAULT;
52124 +
52125 + ruserip = rtmp->prev;
52126 +
52127 + if (!rlast) {
52128 + rtmp->prev = NULL;
52129 + rolep->allowed_ips = rtmp;
52130 + } else {
52131 + rlast->next = rtmp;
52132 + rtmp->prev = rlast;
52133 + }
52134 +
52135 + if (!ruserip)
52136 + rtmp->next = NULL;
52137 + }
52138 +
52139 + return 0;
52140 +}
52141 +
52142 +static int
52143 +copy_user_transitions(struct acl_role_label *rolep)
52144 +{
52145 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52146 +
52147 + unsigned int len;
52148 + char *tmp;
52149 +
52150 + rusertp = rolep->transitions;
52151 +
52152 + while (rusertp) {
52153 + rlast = rtmp;
52154 +
52155 + if ((rtmp = (struct role_transition *)
52156 + acl_alloc(sizeof (struct role_transition))) == NULL)
52157 + return -ENOMEM;
52158 +
52159 + if (copy_from_user(rtmp, rusertp,
52160 + sizeof (struct role_transition)))
52161 + return -EFAULT;
52162 +
52163 + rusertp = rtmp->prev;
52164 +
52165 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52166 +
52167 + if (!len || len >= GR_SPROLE_LEN)
52168 + return -EINVAL;
52169 +
52170 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52171 + return -ENOMEM;
52172 +
52173 + if (copy_from_user(tmp, rtmp->rolename, len))
52174 + return -EFAULT;
52175 + tmp[len-1] = '\0';
52176 + rtmp->rolename = tmp;
52177 +
52178 + if (!rlast) {
52179 + rtmp->prev = NULL;
52180 + rolep->transitions = rtmp;
52181 + } else {
52182 + rlast->next = rtmp;
52183 + rtmp->prev = rlast;
52184 + }
52185 +
52186 + if (!rusertp)
52187 + rtmp->next = NULL;
52188 + }
52189 +
52190 + return 0;
52191 +}
52192 +
52193 +static struct acl_subject_label *
52194 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52195 +{
52196 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52197 + unsigned int len;
52198 + char *tmp;
52199 + __u32 num_objs;
52200 + struct acl_ip_label **i_tmp, *i_utmp2;
52201 + struct gr_hash_struct ghash;
52202 + struct subject_map *subjmap;
52203 + unsigned int i_num;
52204 + int err;
52205 +
52206 + s_tmp = lookup_subject_map(userp);
52207 +
52208 + /* we've already copied this subject into the kernel, just return
52209 + the reference to it, and don't copy it over again
52210 + */
52211 + if (s_tmp)
52212 + return(s_tmp);
52213 +
52214 + if ((s_tmp = (struct acl_subject_label *)
52215 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52216 + return ERR_PTR(-ENOMEM);
52217 +
52218 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52219 + if (subjmap == NULL)
52220 + return ERR_PTR(-ENOMEM);
52221 +
52222 + subjmap->user = userp;
52223 + subjmap->kernel = s_tmp;
52224 + insert_subj_map_entry(subjmap);
52225 +
52226 + if (copy_from_user(s_tmp, userp,
52227 + sizeof (struct acl_subject_label)))
52228 + return ERR_PTR(-EFAULT);
52229 +
52230 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52231 +
52232 + if (!len || len >= PATH_MAX)
52233 + return ERR_PTR(-EINVAL);
52234 +
52235 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52236 + return ERR_PTR(-ENOMEM);
52237 +
52238 + if (copy_from_user(tmp, s_tmp->filename, len))
52239 + return ERR_PTR(-EFAULT);
52240 + tmp[len-1] = '\0';
52241 + s_tmp->filename = tmp;
52242 +
52243 + if (!strcmp(s_tmp->filename, "/"))
52244 + role->root_label = s_tmp;
52245 +
52246 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52247 + return ERR_PTR(-EFAULT);
52248 +
52249 + /* copy user and group transition tables */
52250 +
52251 + if (s_tmp->user_trans_num) {
52252 + uid_t *uidlist;
52253 +
52254 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52255 + if (uidlist == NULL)
52256 + return ERR_PTR(-ENOMEM);
52257 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52258 + return ERR_PTR(-EFAULT);
52259 +
52260 + s_tmp->user_transitions = uidlist;
52261 + }
52262 +
52263 + if (s_tmp->group_trans_num) {
52264 + gid_t *gidlist;
52265 +
52266 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52267 + if (gidlist == NULL)
52268 + return ERR_PTR(-ENOMEM);
52269 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52270 + return ERR_PTR(-EFAULT);
52271 +
52272 + s_tmp->group_transitions = gidlist;
52273 + }
52274 +
52275 + /* set up object hash table */
52276 + num_objs = count_user_objs(ghash.first);
52277 +
52278 + s_tmp->obj_hash_size = num_objs;
52279 + s_tmp->obj_hash =
52280 + (struct acl_object_label **)
52281 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52282 +
52283 + if (!s_tmp->obj_hash)
52284 + return ERR_PTR(-ENOMEM);
52285 +
52286 + memset(s_tmp->obj_hash, 0,
52287 + s_tmp->obj_hash_size *
52288 + sizeof (struct acl_object_label *));
52289 +
52290 + /* add in objects */
52291 + err = copy_user_objs(ghash.first, s_tmp, role);
52292 +
52293 + if (err)
52294 + return ERR_PTR(err);
52295 +
52296 + /* set pointer for parent subject */
52297 + if (s_tmp->parent_subject) {
52298 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52299 +
52300 + if (IS_ERR(s_tmp2))
52301 + return s_tmp2;
52302 +
52303 + s_tmp->parent_subject = s_tmp2;
52304 + }
52305 +
52306 + /* add in ip acls */
52307 +
52308 + if (!s_tmp->ip_num) {
52309 + s_tmp->ips = NULL;
52310 + goto insert;
52311 + }
52312 +
52313 + i_tmp =
52314 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52315 + sizeof (struct acl_ip_label *));
52316 +
52317 + if (!i_tmp)
52318 + return ERR_PTR(-ENOMEM);
52319 +
52320 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52321 + *(i_tmp + i_num) =
52322 + (struct acl_ip_label *)
52323 + acl_alloc(sizeof (struct acl_ip_label));
52324 + if (!*(i_tmp + i_num))
52325 + return ERR_PTR(-ENOMEM);
52326 +
52327 + if (copy_from_user
52328 + (&i_utmp2, s_tmp->ips + i_num,
52329 + sizeof (struct acl_ip_label *)))
52330 + return ERR_PTR(-EFAULT);
52331 +
52332 + if (copy_from_user
52333 + (*(i_tmp + i_num), i_utmp2,
52334 + sizeof (struct acl_ip_label)))
52335 + return ERR_PTR(-EFAULT);
52336 +
52337 + if ((*(i_tmp + i_num))->iface == NULL)
52338 + continue;
52339 +
52340 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52341 + if (!len || len >= IFNAMSIZ)
52342 + return ERR_PTR(-EINVAL);
52343 + tmp = acl_alloc(len);
52344 + if (tmp == NULL)
52345 + return ERR_PTR(-ENOMEM);
52346 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52347 + return ERR_PTR(-EFAULT);
52348 + (*(i_tmp + i_num))->iface = tmp;
52349 + }
52350 +
52351 + s_tmp->ips = i_tmp;
52352 +
52353 +insert:
52354 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52355 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52356 + return ERR_PTR(-ENOMEM);
52357 +
52358 + return s_tmp;
52359 +}
52360 +
52361 +static int
52362 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52363 +{
52364 + struct acl_subject_label s_pre;
52365 + struct acl_subject_label * ret;
52366 + int err;
52367 +
52368 + while (userp) {
52369 + if (copy_from_user(&s_pre, userp,
52370 + sizeof (struct acl_subject_label)))
52371 + return -EFAULT;
52372 +
52373 + /* do not add nested subjects here, add
52374 + while parsing objects
52375 + */
52376 +
52377 + if (s_pre.mode & GR_NESTED) {
52378 + userp = s_pre.prev;
52379 + continue;
52380 + }
52381 +
52382 + ret = do_copy_user_subj(userp, role);
52383 +
52384 + err = PTR_ERR(ret);
52385 + if (IS_ERR(ret))
52386 + return err;
52387 +
52388 + insert_acl_subj_label(ret, role);
52389 +
52390 + userp = s_pre.prev;
52391 + }
52392 +
52393 + return 0;
52394 +}
52395 +
52396 +static int
52397 +copy_user_acl(struct gr_arg *arg)
52398 +{
52399 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52400 + struct sprole_pw *sptmp;
52401 + struct gr_hash_struct *ghash;
52402 + uid_t *domainlist;
52403 + unsigned int r_num;
52404 + unsigned int len;
52405 + char *tmp;
52406 + int err = 0;
52407 + __u16 i;
52408 + __u32 num_subjs;
52409 +
52410 + /* we need a default and kernel role */
52411 + if (arg->role_db.num_roles < 2)
52412 + return -EINVAL;
52413 +
52414 + /* copy special role authentication info from userspace */
52415 +
52416 + num_sprole_pws = arg->num_sprole_pws;
52417 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52418 +
52419 + if (!acl_special_roles && num_sprole_pws)
52420 + return -ENOMEM;
52421 +
52422 + for (i = 0; i < num_sprole_pws; i++) {
52423 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52424 + if (!sptmp)
52425 + return -ENOMEM;
52426 + if (copy_from_user(sptmp, arg->sprole_pws + i,
52427 + sizeof (struct sprole_pw)))
52428 + return -EFAULT;
52429 +
52430 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52431 +
52432 + if (!len || len >= GR_SPROLE_LEN)
52433 + return -EINVAL;
52434 +
52435 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52436 + return -ENOMEM;
52437 +
52438 + if (copy_from_user(tmp, sptmp->rolename, len))
52439 + return -EFAULT;
52440 +
52441 + tmp[len-1] = '\0';
52442 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52443 + printk(KERN_ALERT "Copying special role %s\n", tmp);
52444 +#endif
52445 + sptmp->rolename = tmp;
52446 + acl_special_roles[i] = sptmp;
52447 + }
52448 +
52449 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52450 +
52451 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52452 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
52453 +
52454 + if (!r_tmp)
52455 + return -ENOMEM;
52456 +
52457 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
52458 + sizeof (struct acl_role_label *)))
52459 + return -EFAULT;
52460 +
52461 + if (copy_from_user(r_tmp, r_utmp2,
52462 + sizeof (struct acl_role_label)))
52463 + return -EFAULT;
52464 +
52465 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52466 +
52467 + if (!len || len >= PATH_MAX)
52468 + return -EINVAL;
52469 +
52470 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52471 + return -ENOMEM;
52472 +
52473 + if (copy_from_user(tmp, r_tmp->rolename, len))
52474 + return -EFAULT;
52475 +
52476 + tmp[len-1] = '\0';
52477 + r_tmp->rolename = tmp;
52478 +
52479 + if (!strcmp(r_tmp->rolename, "default")
52480 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52481 + default_role = r_tmp;
52482 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52483 + kernel_role = r_tmp;
52484 + }
52485 +
52486 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52487 + return -ENOMEM;
52488 +
52489 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52490 + return -EFAULT;
52491 +
52492 + r_tmp->hash = ghash;
52493 +
52494 + num_subjs = count_user_subjs(r_tmp->hash->first);
52495 +
52496 + r_tmp->subj_hash_size = num_subjs;
52497 + r_tmp->subj_hash =
52498 + (struct acl_subject_label **)
52499 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52500 +
52501 + if (!r_tmp->subj_hash)
52502 + return -ENOMEM;
52503 +
52504 + err = copy_user_allowedips(r_tmp);
52505 + if (err)
52506 + return err;
52507 +
52508 + /* copy domain info */
52509 + if (r_tmp->domain_children != NULL) {
52510 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52511 + if (domainlist == NULL)
52512 + return -ENOMEM;
52513 +
52514 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52515 + return -EFAULT;
52516 +
52517 + r_tmp->domain_children = domainlist;
52518 + }
52519 +
52520 + err = copy_user_transitions(r_tmp);
52521 + if (err)
52522 + return err;
52523 +
52524 + memset(r_tmp->subj_hash, 0,
52525 + r_tmp->subj_hash_size *
52526 + sizeof (struct acl_subject_label *));
52527 +
52528 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52529 +
52530 + if (err)
52531 + return err;
52532 +
52533 + /* set nested subject list to null */
52534 + r_tmp->hash->first = NULL;
52535 +
52536 + insert_acl_role_label(r_tmp);
52537 + }
52538 +
52539 + if (default_role == NULL || kernel_role == NULL)
52540 + return -EINVAL;
52541 +
52542 + return err;
52543 +}
52544 +
52545 +static int
52546 +gracl_init(struct gr_arg *args)
52547 +{
52548 + int error = 0;
52549 +
52550 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52551 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52552 +
52553 + if (init_variables(args)) {
52554 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52555 + error = -ENOMEM;
52556 + free_variables();
52557 + goto out;
52558 + }
52559 +
52560 + error = copy_user_acl(args);
52561 + free_init_variables();
52562 + if (error) {
52563 + free_variables();
52564 + goto out;
52565 + }
52566 +
52567 + if ((error = gr_set_acls(0))) {
52568 + free_variables();
52569 + goto out;
52570 + }
52571 +
52572 + pax_open_kernel();
52573 + gr_status |= GR_READY;
52574 + pax_close_kernel();
52575 +
52576 + out:
52577 + return error;
52578 +}
52579 +
52580 +/* derived from glibc fnmatch() 0: match, 1: no match*/
52581 +
52582 +static int
52583 +glob_match(const char *p, const char *n)
52584 +{
52585 + char c;
52586 +
52587 + while ((c = *p++) != '\0') {
52588 + switch (c) {
52589 + case '?':
52590 + if (*n == '\0')
52591 + return 1;
52592 + else if (*n == '/')
52593 + return 1;
52594 + break;
52595 + case '\\':
52596 + if (*n != c)
52597 + return 1;
52598 + break;
52599 + case '*':
52600 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
52601 + if (*n == '/')
52602 + return 1;
52603 + else if (c == '?') {
52604 + if (*n == '\0')
52605 + return 1;
52606 + else
52607 + ++n;
52608 + }
52609 + }
52610 + if (c == '\0') {
52611 + return 0;
52612 + } else {
52613 + const char *endp;
52614 +
52615 + if ((endp = strchr(n, '/')) == NULL)
52616 + endp = n + strlen(n);
52617 +
52618 + if (c == '[') {
52619 + for (--p; n < endp; ++n)
52620 + if (!glob_match(p, n))
52621 + return 0;
52622 + } else if (c == '/') {
52623 + while (*n != '\0' && *n != '/')
52624 + ++n;
52625 + if (*n == '/' && !glob_match(p, n + 1))
52626 + return 0;
52627 + } else {
52628 + for (--p; n < endp; ++n)
52629 + if (*n == c && !glob_match(p, n))
52630 + return 0;
52631 + }
52632 +
52633 + return 1;
52634 + }
52635 + case '[':
52636 + {
52637 + int not;
52638 + char cold;
52639 +
52640 + if (*n == '\0' || *n == '/')
52641 + return 1;
52642 +
52643 + not = (*p == '!' || *p == '^');
52644 + if (not)
52645 + ++p;
52646 +
52647 + c = *p++;
52648 + for (;;) {
52649 + unsigned char fn = (unsigned char)*n;
52650 +
52651 + if (c == '\0')
52652 + return 1;
52653 + else {
52654 + if (c == fn)
52655 + goto matched;
52656 + cold = c;
52657 + c = *p++;
52658 +
52659 + if (c == '-' && *p != ']') {
52660 + unsigned char cend = *p++;
52661 +
52662 + if (cend == '\0')
52663 + return 1;
52664 +
52665 + if (cold <= fn && fn <= cend)
52666 + goto matched;
52667 +
52668 + c = *p++;
52669 + }
52670 + }
52671 +
52672 + if (c == ']')
52673 + break;
52674 + }
52675 + if (!not)
52676 + return 1;
52677 + break;
52678 + matched:
52679 + while (c != ']') {
52680 + if (c == '\0')
52681 + return 1;
52682 +
52683 + c = *p++;
52684 + }
52685 + if (not)
52686 + return 1;
52687 + }
52688 + break;
52689 + default:
52690 + if (c != *n)
52691 + return 1;
52692 + }
52693 +
52694 + ++n;
52695 + }
52696 +
52697 + if (*n == '\0')
52698 + return 0;
52699 +
52700 + if (*n == '/')
52701 + return 0;
52702 +
52703 + return 1;
52704 +}
52705 +
52706 +static struct acl_object_label *
52707 +chk_glob_label(struct acl_object_label *globbed,
52708 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52709 +{
52710 + struct acl_object_label *tmp;
52711 +
52712 + if (*path == NULL)
52713 + *path = gr_to_filename_nolock(dentry, mnt);
52714 +
52715 + tmp = globbed;
52716 +
52717 + while (tmp) {
52718 + if (!glob_match(tmp->filename, *path))
52719 + return tmp;
52720 + tmp = tmp->next;
52721 + }
52722 +
52723 + return NULL;
52724 +}
52725 +
52726 +static struct acl_object_label *
52727 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52728 + const ino_t curr_ino, const dev_t curr_dev,
52729 + const struct acl_subject_label *subj, char **path, const int checkglob)
52730 +{
52731 + struct acl_subject_label *tmpsubj;
52732 + struct acl_object_label *retval;
52733 + struct acl_object_label *retval2;
52734 +
52735 + tmpsubj = (struct acl_subject_label *) subj;
52736 + read_lock(&gr_inode_lock);
52737 + do {
52738 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52739 + if (retval) {
52740 + if (checkglob && retval->globbed) {
52741 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52742 + if (retval2)
52743 + retval = retval2;
52744 + }
52745 + break;
52746 + }
52747 + } while ((tmpsubj = tmpsubj->parent_subject));
52748 + read_unlock(&gr_inode_lock);
52749 +
52750 + return retval;
52751 +}
52752 +
52753 +static __inline__ struct acl_object_label *
52754 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52755 + struct dentry *curr_dentry,
52756 + const struct acl_subject_label *subj, char **path, const int checkglob)
52757 +{
52758 + int newglob = checkglob;
52759 + ino_t inode;
52760 + dev_t device;
52761 +
52762 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52763 + as we don't want a / * rule to match instead of the / object
52764 + don't do this for create lookups that call this function though, since they're looking up
52765 + on the parent and thus need globbing checks on all paths
52766 + */
52767 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52768 + newglob = GR_NO_GLOB;
52769 +
52770 + spin_lock(&curr_dentry->d_lock);
52771 + inode = curr_dentry->d_inode->i_ino;
52772 + device = __get_dev(curr_dentry);
52773 + spin_unlock(&curr_dentry->d_lock);
52774 +
52775 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52776 +}
52777 +
52778 +static struct acl_object_label *
52779 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52780 + const struct acl_subject_label *subj, char *path, const int checkglob)
52781 +{
52782 + struct dentry *dentry = (struct dentry *) l_dentry;
52783 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52784 + struct acl_object_label *retval;
52785 + struct dentry *parent;
52786 +
52787 + write_seqlock(&rename_lock);
52788 + br_read_lock(vfsmount_lock);
52789 +
52790 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52791 +#ifdef CONFIG_NET
52792 + mnt == sock_mnt ||
52793 +#endif
52794 +#ifdef CONFIG_HUGETLBFS
52795 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52796 +#endif
52797 + /* ignore Eric Biederman */
52798 + IS_PRIVATE(l_dentry->d_inode))) {
52799 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52800 + goto out;
52801 + }
52802 +
52803 + for (;;) {
52804 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52805 + break;
52806 +
52807 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52808 + if (mnt->mnt_parent == mnt)
52809 + break;
52810 +
52811 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52812 + if (retval != NULL)
52813 + goto out;
52814 +
52815 + dentry = mnt->mnt_mountpoint;
52816 + mnt = mnt->mnt_parent;
52817 + continue;
52818 + }
52819 +
52820 + parent = dentry->d_parent;
52821 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52822 + if (retval != NULL)
52823 + goto out;
52824 +
52825 + dentry = parent;
52826 + }
52827 +
52828 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52829 +
52830 + /* real_root is pinned so we don't have to hold a reference */
52831 + if (retval == NULL)
52832 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52833 +out:
52834 + br_read_unlock(vfsmount_lock);
52835 + write_sequnlock(&rename_lock);
52836 +
52837 + BUG_ON(retval == NULL);
52838 +
52839 + return retval;
52840 +}
52841 +
52842 +static __inline__ struct acl_object_label *
52843 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52844 + const struct acl_subject_label *subj)
52845 +{
52846 + char *path = NULL;
52847 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52848 +}
52849 +
52850 +static __inline__ struct acl_object_label *
52851 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52852 + const struct acl_subject_label *subj)
52853 +{
52854 + char *path = NULL;
52855 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52856 +}
52857 +
52858 +static __inline__ struct acl_object_label *
52859 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52860 + const struct acl_subject_label *subj, char *path)
52861 +{
52862 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52863 +}
52864 +
52865 +static struct acl_subject_label *
52866 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52867 + const struct acl_role_label *role)
52868 +{
52869 + struct dentry *dentry = (struct dentry *) l_dentry;
52870 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52871 + struct acl_subject_label *retval;
52872 + struct dentry *parent;
52873 +
52874 + write_seqlock(&rename_lock);
52875 + br_read_lock(vfsmount_lock);
52876 +
52877 + for (;;) {
52878 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52879 + break;
52880 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52881 + if (mnt->mnt_parent == mnt)
52882 + break;
52883 +
52884 + spin_lock(&dentry->d_lock);
52885 + read_lock(&gr_inode_lock);
52886 + retval =
52887 + lookup_acl_subj_label(dentry->d_inode->i_ino,
52888 + __get_dev(dentry), role);
52889 + read_unlock(&gr_inode_lock);
52890 + spin_unlock(&dentry->d_lock);
52891 + if (retval != NULL)
52892 + goto out;
52893 +
52894 + dentry = mnt->mnt_mountpoint;
52895 + mnt = mnt->mnt_parent;
52896 + continue;
52897 + }
52898 +
52899 + spin_lock(&dentry->d_lock);
52900 + read_lock(&gr_inode_lock);
52901 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52902 + __get_dev(dentry), role);
52903 + read_unlock(&gr_inode_lock);
52904 + parent = dentry->d_parent;
52905 + spin_unlock(&dentry->d_lock);
52906 +
52907 + if (retval != NULL)
52908 + goto out;
52909 +
52910 + dentry = parent;
52911 + }
52912 +
52913 + spin_lock(&dentry->d_lock);
52914 + read_lock(&gr_inode_lock);
52915 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52916 + __get_dev(dentry), role);
52917 + read_unlock(&gr_inode_lock);
52918 + spin_unlock(&dentry->d_lock);
52919 +
52920 + if (unlikely(retval == NULL)) {
52921 + /* real_root is pinned, we don't need to hold a reference */
52922 + read_lock(&gr_inode_lock);
52923 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
52924 + __get_dev(real_root.dentry), role);
52925 + read_unlock(&gr_inode_lock);
52926 + }
52927 +out:
52928 + br_read_unlock(vfsmount_lock);
52929 + write_sequnlock(&rename_lock);
52930 +
52931 + BUG_ON(retval == NULL);
52932 +
52933 + return retval;
52934 +}
52935 +
52936 +static void
52937 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
52938 +{
52939 + struct task_struct *task = current;
52940 + const struct cred *cred = current_cred();
52941 +
52942 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52943 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52944 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52945 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
52946 +
52947 + return;
52948 +}
52949 +
52950 +static void
52951 +gr_log_learn_sysctl(const char *path, const __u32 mode)
52952 +{
52953 + struct task_struct *task = current;
52954 + const struct cred *cred = current_cred();
52955 +
52956 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52957 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52958 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52959 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
52960 +
52961 + return;
52962 +}
52963 +
52964 +static void
52965 +gr_log_learn_id_change(const char type, const unsigned int real,
52966 + const unsigned int effective, const unsigned int fs)
52967 +{
52968 + struct task_struct *task = current;
52969 + const struct cred *cred = current_cred();
52970 +
52971 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
52972 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52973 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52974 + type, real, effective, fs, &task->signal->saved_ip);
52975 +
52976 + return;
52977 +}
52978 +
52979 +__u32
52980 +gr_search_file(const struct dentry * dentry, const __u32 mode,
52981 + const struct vfsmount * mnt)
52982 +{
52983 + __u32 retval = mode;
52984 + struct acl_subject_label *curracl;
52985 + struct acl_object_label *currobj;
52986 +
52987 + if (unlikely(!(gr_status & GR_READY)))
52988 + return (mode & ~GR_AUDITS);
52989 +
52990 + curracl = current->acl;
52991 +
52992 + currobj = chk_obj_label(dentry, mnt, curracl);
52993 + retval = currobj->mode & mode;
52994 +
52995 + /* if we're opening a specified transfer file for writing
52996 + (e.g. /dev/initctl), then transfer our role to init
52997 + */
52998 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
52999 + current->role->roletype & GR_ROLE_PERSIST)) {
53000 + struct task_struct *task = init_pid_ns.child_reaper;
53001 +
53002 + if (task->role != current->role) {
53003 + task->acl_sp_role = 0;
53004 + task->acl_role_id = current->acl_role_id;
53005 + task->role = current->role;
53006 + rcu_read_lock();
53007 + read_lock(&grsec_exec_file_lock);
53008 + gr_apply_subject_to_task(task);
53009 + read_unlock(&grsec_exec_file_lock);
53010 + rcu_read_unlock();
53011 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53012 + }
53013 + }
53014 +
53015 + if (unlikely
53016 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53017 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53018 + __u32 new_mode = mode;
53019 +
53020 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53021 +
53022 + retval = new_mode;
53023 +
53024 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53025 + new_mode |= GR_INHERIT;
53026 +
53027 + if (!(mode & GR_NOLEARN))
53028 + gr_log_learn(dentry, mnt, new_mode);
53029 + }
53030 +
53031 + return retval;
53032 +}
53033 +
53034 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53035 + const struct dentry *parent,
53036 + const struct vfsmount *mnt)
53037 +{
53038 + struct name_entry *match;
53039 + struct acl_object_label *matchpo;
53040 + struct acl_subject_label *curracl;
53041 + char *path;
53042 +
53043 + if (unlikely(!(gr_status & GR_READY)))
53044 + return NULL;
53045 +
53046 + preempt_disable();
53047 + path = gr_to_filename_rbac(new_dentry, mnt);
53048 + match = lookup_name_entry_create(path);
53049 +
53050 + curracl = current->acl;
53051 +
53052 + if (match) {
53053 + read_lock(&gr_inode_lock);
53054 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53055 + read_unlock(&gr_inode_lock);
53056 +
53057 + if (matchpo) {
53058 + preempt_enable();
53059 + return matchpo;
53060 + }
53061 + }
53062 +
53063 + // lookup parent
53064 +
53065 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53066 +
53067 + preempt_enable();
53068 + return matchpo;
53069 +}
53070 +
53071 +__u32
53072 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53073 + const struct vfsmount * mnt, const __u32 mode)
53074 +{
53075 + struct acl_object_label *matchpo;
53076 + __u32 retval;
53077 +
53078 + if (unlikely(!(gr_status & GR_READY)))
53079 + return (mode & ~GR_AUDITS);
53080 +
53081 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53082 +
53083 + retval = matchpo->mode & mode;
53084 +
53085 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53086 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53087 + __u32 new_mode = mode;
53088 +
53089 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53090 +
53091 + gr_log_learn(new_dentry, mnt, new_mode);
53092 + return new_mode;
53093 + }
53094 +
53095 + return retval;
53096 +}
53097 +
53098 +__u32
53099 +gr_check_link(const struct dentry * new_dentry,
53100 + const struct dentry * parent_dentry,
53101 + const struct vfsmount * parent_mnt,
53102 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53103 +{
53104 + struct acl_object_label *obj;
53105 + __u32 oldmode, newmode;
53106 + __u32 needmode;
53107 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53108 + GR_DELETE | GR_INHERIT;
53109 +
53110 + if (unlikely(!(gr_status & GR_READY)))
53111 + return (GR_CREATE | GR_LINK);
53112 +
53113 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53114 + oldmode = obj->mode;
53115 +
53116 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53117 + newmode = obj->mode;
53118 +
53119 + needmode = newmode & checkmodes;
53120 +
53121 + // old name for hardlink must have at least the permissions of the new name
53122 + if ((oldmode & needmode) != needmode)
53123 + goto bad;
53124 +
53125 + // if old name had restrictions/auditing, make sure the new name does as well
53126 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53127 +
53128 + // don't allow hardlinking of suid/sgid files without permission
53129 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53130 + needmode |= GR_SETID;
53131 +
53132 + if ((newmode & needmode) != needmode)
53133 + goto bad;
53134 +
53135 + // enforce minimum permissions
53136 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53137 + return newmode;
53138 +bad:
53139 + needmode = oldmode;
53140 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53141 + needmode |= GR_SETID;
53142 +
53143 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53144 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53145 + return (GR_CREATE | GR_LINK);
53146 + } else if (newmode & GR_SUPPRESS)
53147 + return GR_SUPPRESS;
53148 + else
53149 + return 0;
53150 +}
53151 +
53152 +int
53153 +gr_check_hidden_task(const struct task_struct *task)
53154 +{
53155 + if (unlikely(!(gr_status & GR_READY)))
53156 + return 0;
53157 +
53158 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53159 + return 1;
53160 +
53161 + return 0;
53162 +}
53163 +
53164 +int
53165 +gr_check_protected_task(const struct task_struct *task)
53166 +{
53167 + if (unlikely(!(gr_status & GR_READY) || !task))
53168 + return 0;
53169 +
53170 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53171 + task->acl != current->acl)
53172 + return 1;
53173 +
53174 + return 0;
53175 +}
53176 +
53177 +int
53178 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53179 +{
53180 + struct task_struct *p;
53181 + int ret = 0;
53182 +
53183 + if (unlikely(!(gr_status & GR_READY) || !pid))
53184 + return ret;
53185 +
53186 + read_lock(&tasklist_lock);
53187 + do_each_pid_task(pid, type, p) {
53188 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53189 + p->acl != current->acl) {
53190 + ret = 1;
53191 + goto out;
53192 + }
53193 + } while_each_pid_task(pid, type, p);
53194 +out:
53195 + read_unlock(&tasklist_lock);
53196 +
53197 + return ret;
53198 +}
53199 +
53200 +void
53201 +gr_copy_label(struct task_struct *tsk)
53202 +{
53203 + /* plain copying of fields is already done by dup_task_struct */
53204 + tsk->signal->used_accept = 0;
53205 + tsk->acl_sp_role = 0;
53206 + //tsk->acl_role_id = current->acl_role_id;
53207 + //tsk->acl = current->acl;
53208 + //tsk->role = current->role;
53209 + tsk->signal->curr_ip = current->signal->curr_ip;
53210 + tsk->signal->saved_ip = current->signal->saved_ip;
53211 + if (current->exec_file)
53212 + get_file(current->exec_file);
53213 + //tsk->exec_file = current->exec_file;
53214 + //tsk->is_writable = current->is_writable;
53215 + if (unlikely(current->signal->used_accept)) {
53216 + current->signal->curr_ip = 0;
53217 + current->signal->saved_ip = 0;
53218 + }
53219 +
53220 + return;
53221 +}
53222 +
53223 +static void
53224 +gr_set_proc_res(struct task_struct *task)
53225 +{
53226 + struct acl_subject_label *proc;
53227 + unsigned short i;
53228 +
53229 + proc = task->acl;
53230 +
53231 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53232 + return;
53233 +
53234 + for (i = 0; i < RLIM_NLIMITS; i++) {
53235 + if (!(proc->resmask & (1 << i)))
53236 + continue;
53237 +
53238 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53239 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53240 + }
53241 +
53242 + return;
53243 +}
53244 +
53245 +extern int __gr_process_user_ban(struct user_struct *user);
53246 +
53247 +int
53248 +gr_check_user_change(int real, int effective, int fs)
53249 +{
53250 + unsigned int i;
53251 + __u16 num;
53252 + uid_t *uidlist;
53253 + int curuid;
53254 + int realok = 0;
53255 + int effectiveok = 0;
53256 + int fsok = 0;
53257 +
53258 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53259 + struct user_struct *user;
53260 +
53261 + if (real == -1)
53262 + goto skipit;
53263 +
53264 + user = find_user(real);
53265 + if (user == NULL)
53266 + goto skipit;
53267 +
53268 + if (__gr_process_user_ban(user)) {
53269 + /* for find_user */
53270 + free_uid(user);
53271 + return 1;
53272 + }
53273 +
53274 + /* for find_user */
53275 + free_uid(user);
53276 +
53277 +skipit:
53278 +#endif
53279 +
53280 + if (unlikely(!(gr_status & GR_READY)))
53281 + return 0;
53282 +
53283 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53284 + gr_log_learn_id_change('u', real, effective, fs);
53285 +
53286 + num = current->acl->user_trans_num;
53287 + uidlist = current->acl->user_transitions;
53288 +
53289 + if (uidlist == NULL)
53290 + return 0;
53291 +
53292 + if (real == -1)
53293 + realok = 1;
53294 + if (effective == -1)
53295 + effectiveok = 1;
53296 + if (fs == -1)
53297 + fsok = 1;
53298 +
53299 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
53300 + for (i = 0; i < num; i++) {
53301 + curuid = (int)uidlist[i];
53302 + if (real == curuid)
53303 + realok = 1;
53304 + if (effective == curuid)
53305 + effectiveok = 1;
53306 + if (fs == curuid)
53307 + fsok = 1;
53308 + }
53309 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
53310 + for (i = 0; i < num; i++) {
53311 + curuid = (int)uidlist[i];
53312 + if (real == curuid)
53313 + break;
53314 + if (effective == curuid)
53315 + break;
53316 + if (fs == curuid)
53317 + break;
53318 + }
53319 + /* not in deny list */
53320 + if (i == num) {
53321 + realok = 1;
53322 + effectiveok = 1;
53323 + fsok = 1;
53324 + }
53325 + }
53326 +
53327 + if (realok && effectiveok && fsok)
53328 + return 0;
53329 + else {
53330 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53331 + return 1;
53332 + }
53333 +}
53334 +
53335 +int
53336 +gr_check_group_change(int real, int effective, int fs)
53337 +{
53338 + unsigned int i;
53339 + __u16 num;
53340 + gid_t *gidlist;
53341 + int curgid;
53342 + int realok = 0;
53343 + int effectiveok = 0;
53344 + int fsok = 0;
53345 +
53346 + if (unlikely(!(gr_status & GR_READY)))
53347 + return 0;
53348 +
53349 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53350 + gr_log_learn_id_change('g', real, effective, fs);
53351 +
53352 + num = current->acl->group_trans_num;
53353 + gidlist = current->acl->group_transitions;
53354 +
53355 + if (gidlist == NULL)
53356 + return 0;
53357 +
53358 + if (real == -1)
53359 + realok = 1;
53360 + if (effective == -1)
53361 + effectiveok = 1;
53362 + if (fs == -1)
53363 + fsok = 1;
53364 +
53365 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53366 + for (i = 0; i < num; i++) {
53367 + curgid = (int)gidlist[i];
53368 + if (real == curgid)
53369 + realok = 1;
53370 + if (effective == curgid)
53371 + effectiveok = 1;
53372 + if (fs == curgid)
53373 + fsok = 1;
53374 + }
53375 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
53376 + for (i = 0; i < num; i++) {
53377 + curgid = (int)gidlist[i];
53378 + if (real == curgid)
53379 + break;
53380 + if (effective == curgid)
53381 + break;
53382 + if (fs == curgid)
53383 + break;
53384 + }
53385 + /* not in deny list */
53386 + if (i == num) {
53387 + realok = 1;
53388 + effectiveok = 1;
53389 + fsok = 1;
53390 + }
53391 + }
53392 +
53393 + if (realok && effectiveok && fsok)
53394 + return 0;
53395 + else {
53396 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53397 + return 1;
53398 + }
53399 +}
53400 +
53401 +extern int gr_acl_is_capable(const int cap);
53402 +
53403 +void
53404 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53405 +{
53406 + struct acl_role_label *role = task->role;
53407 + struct acl_subject_label *subj = NULL;
53408 + struct acl_object_label *obj;
53409 + struct file *filp;
53410 +
53411 + if (unlikely(!(gr_status & GR_READY)))
53412 + return;
53413 +
53414 + filp = task->exec_file;
53415 +
53416 + /* kernel process, we'll give them the kernel role */
53417 + if (unlikely(!filp)) {
53418 + task->role = kernel_role;
53419 + task->acl = kernel_role->root_label;
53420 + return;
53421 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53422 + role = lookup_acl_role_label(task, uid, gid);
53423 +
53424 + /* don't change the role if we're not a privileged process */
53425 + if (role && task->role != role &&
53426 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53427 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53428 + return;
53429 +
53430 + /* perform subject lookup in possibly new role
53431 + we can use this result below in the case where role == task->role
53432 + */
53433 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53434 +
53435 + /* if we changed uid/gid, but result in the same role
53436 + and are using inheritance, don't lose the inherited subject
53437 + if current subject is other than what normal lookup
53438 + would result in, we arrived via inheritance, don't
53439 + lose subject
53440 + */
53441 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53442 + (subj == task->acl)))
53443 + task->acl = subj;
53444 +
53445 + task->role = role;
53446 +
53447 + task->is_writable = 0;
53448 +
53449 + /* ignore additional mmap checks for processes that are writable
53450 + by the default ACL */
53451 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53452 + if (unlikely(obj->mode & GR_WRITE))
53453 + task->is_writable = 1;
53454 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53455 + if (unlikely(obj->mode & GR_WRITE))
53456 + task->is_writable = 1;
53457 +
53458 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53459 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53460 +#endif
53461 +
53462 + gr_set_proc_res(task);
53463 +
53464 + return;
53465 +}
53466 +
53467 +int
53468 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53469 + const int unsafe_flags)
53470 +{
53471 + struct task_struct *task = current;
53472 + struct acl_subject_label *newacl;
53473 + struct acl_object_label *obj;
53474 + __u32 retmode;
53475 +
53476 + if (unlikely(!(gr_status & GR_READY)))
53477 + return 0;
53478 +
53479 + newacl = chk_subj_label(dentry, mnt, task->role);
53480 +
53481 + task_lock(task);
53482 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53483 + !(task->role->roletype & GR_ROLE_GOD) &&
53484 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53485 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53486 + task_unlock(task);
53487 + if (unsafe_flags & LSM_UNSAFE_SHARE)
53488 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53489 + else
53490 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53491 + return -EACCES;
53492 + }
53493 + task_unlock(task);
53494 +
53495 + obj = chk_obj_label(dentry, mnt, task->acl);
53496 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53497 +
53498 + if (!(task->acl->mode & GR_INHERITLEARN) &&
53499 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53500 + if (obj->nested)
53501 + task->acl = obj->nested;
53502 + else
53503 + task->acl = newacl;
53504 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53505 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53506 +
53507 + task->is_writable = 0;
53508 +
53509 + /* ignore additional mmap checks for processes that are writable
53510 + by the default ACL */
53511 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
53512 + if (unlikely(obj->mode & GR_WRITE))
53513 + task->is_writable = 1;
53514 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
53515 + if (unlikely(obj->mode & GR_WRITE))
53516 + task->is_writable = 1;
53517 +
53518 + gr_set_proc_res(task);
53519 +
53520 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53521 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53522 +#endif
53523 + return 0;
53524 +}
53525 +
53526 +/* always called with valid inodev ptr */
53527 +static void
53528 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53529 +{
53530 + struct acl_object_label *matchpo;
53531 + struct acl_subject_label *matchps;
53532 + struct acl_subject_label *subj;
53533 + struct acl_role_label *role;
53534 + unsigned int x;
53535 +
53536 + FOR_EACH_ROLE_START(role)
53537 + FOR_EACH_SUBJECT_START(role, subj, x)
53538 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53539 + matchpo->mode |= GR_DELETED;
53540 + FOR_EACH_SUBJECT_END(subj,x)
53541 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53542 + if (subj->inode == ino && subj->device == dev)
53543 + subj->mode |= GR_DELETED;
53544 + FOR_EACH_NESTED_SUBJECT_END(subj)
53545 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53546 + matchps->mode |= GR_DELETED;
53547 + FOR_EACH_ROLE_END(role)
53548 +
53549 + inodev->nentry->deleted = 1;
53550 +
53551 + return;
53552 +}
53553 +
53554 +void
53555 +gr_handle_delete(const ino_t ino, const dev_t dev)
53556 +{
53557 + struct inodev_entry *inodev;
53558 +
53559 + if (unlikely(!(gr_status & GR_READY)))
53560 + return;
53561 +
53562 + write_lock(&gr_inode_lock);
53563 + inodev = lookup_inodev_entry(ino, dev);
53564 + if (inodev != NULL)
53565 + do_handle_delete(inodev, ino, dev);
53566 + write_unlock(&gr_inode_lock);
53567 +
53568 + return;
53569 +}
53570 +
53571 +static void
53572 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53573 + const ino_t newinode, const dev_t newdevice,
53574 + struct acl_subject_label *subj)
53575 +{
53576 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53577 + struct acl_object_label *match;
53578 +
53579 + match = subj->obj_hash[index];
53580 +
53581 + while (match && (match->inode != oldinode ||
53582 + match->device != olddevice ||
53583 + !(match->mode & GR_DELETED)))
53584 + match = match->next;
53585 +
53586 + if (match && (match->inode == oldinode)
53587 + && (match->device == olddevice)
53588 + && (match->mode & GR_DELETED)) {
53589 + if (match->prev == NULL) {
53590 + subj->obj_hash[index] = match->next;
53591 + if (match->next != NULL)
53592 + match->next->prev = NULL;
53593 + } else {
53594 + match->prev->next = match->next;
53595 + if (match->next != NULL)
53596 + match->next->prev = match->prev;
53597 + }
53598 + match->prev = NULL;
53599 + match->next = NULL;
53600 + match->inode = newinode;
53601 + match->device = newdevice;
53602 + match->mode &= ~GR_DELETED;
53603 +
53604 + insert_acl_obj_label(match, subj);
53605 + }
53606 +
53607 + return;
53608 +}
53609 +
53610 +static void
53611 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53612 + const ino_t newinode, const dev_t newdevice,
53613 + struct acl_role_label *role)
53614 +{
53615 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53616 + struct acl_subject_label *match;
53617 +
53618 + match = role->subj_hash[index];
53619 +
53620 + while (match && (match->inode != oldinode ||
53621 + match->device != olddevice ||
53622 + !(match->mode & GR_DELETED)))
53623 + match = match->next;
53624 +
53625 + if (match && (match->inode == oldinode)
53626 + && (match->device == olddevice)
53627 + && (match->mode & GR_DELETED)) {
53628 + if (match->prev == NULL) {
53629 + role->subj_hash[index] = match->next;
53630 + if (match->next != NULL)
53631 + match->next->prev = NULL;
53632 + } else {
53633 + match->prev->next = match->next;
53634 + if (match->next != NULL)
53635 + match->next->prev = match->prev;
53636 + }
53637 + match->prev = NULL;
53638 + match->next = NULL;
53639 + match->inode = newinode;
53640 + match->device = newdevice;
53641 + match->mode &= ~GR_DELETED;
53642 +
53643 + insert_acl_subj_label(match, role);
53644 + }
53645 +
53646 + return;
53647 +}
53648 +
53649 +static void
53650 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53651 + const ino_t newinode, const dev_t newdevice)
53652 +{
53653 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53654 + struct inodev_entry *match;
53655 +
53656 + match = inodev_set.i_hash[index];
53657 +
53658 + while (match && (match->nentry->inode != oldinode ||
53659 + match->nentry->device != olddevice || !match->nentry->deleted))
53660 + match = match->next;
53661 +
53662 + if (match && (match->nentry->inode == oldinode)
53663 + && (match->nentry->device == olddevice) &&
53664 + match->nentry->deleted) {
53665 + if (match->prev == NULL) {
53666 + inodev_set.i_hash[index] = match->next;
53667 + if (match->next != NULL)
53668 + match->next->prev = NULL;
53669 + } else {
53670 + match->prev->next = match->next;
53671 + if (match->next != NULL)
53672 + match->next->prev = match->prev;
53673 + }
53674 + match->prev = NULL;
53675 + match->next = NULL;
53676 + match->nentry->inode = newinode;
53677 + match->nentry->device = newdevice;
53678 + match->nentry->deleted = 0;
53679 +
53680 + insert_inodev_entry(match);
53681 + }
53682 +
53683 + return;
53684 +}
53685 +
53686 +static void
53687 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53688 +{
53689 + struct acl_subject_label *subj;
53690 + struct acl_role_label *role;
53691 + unsigned int x;
53692 +
53693 + FOR_EACH_ROLE_START(role)
53694 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53695 +
53696 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53697 + if ((subj->inode == ino) && (subj->device == dev)) {
53698 + subj->inode = ino;
53699 + subj->device = dev;
53700 + }
53701 + FOR_EACH_NESTED_SUBJECT_END(subj)
53702 + FOR_EACH_SUBJECT_START(role, subj, x)
53703 + update_acl_obj_label(matchn->inode, matchn->device,
53704 + ino, dev, subj);
53705 + FOR_EACH_SUBJECT_END(subj,x)
53706 + FOR_EACH_ROLE_END(role)
53707 +
53708 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53709 +
53710 + return;
53711 +}
53712 +
53713 +static void
53714 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53715 + const struct vfsmount *mnt)
53716 +{
53717 + ino_t ino = dentry->d_inode->i_ino;
53718 + dev_t dev = __get_dev(dentry);
53719 +
53720 + __do_handle_create(matchn, ino, dev);
53721 +
53722 + return;
53723 +}
53724 +
53725 +void
53726 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53727 +{
53728 + struct name_entry *matchn;
53729 +
53730 + if (unlikely(!(gr_status & GR_READY)))
53731 + return;
53732 +
53733 + preempt_disable();
53734 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53735 +
53736 + if (unlikely((unsigned long)matchn)) {
53737 + write_lock(&gr_inode_lock);
53738 + do_handle_create(matchn, dentry, mnt);
53739 + write_unlock(&gr_inode_lock);
53740 + }
53741 + preempt_enable();
53742 +
53743 + return;
53744 +}
53745 +
53746 +void
53747 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53748 +{
53749 + struct name_entry *matchn;
53750 +
53751 + if (unlikely(!(gr_status & GR_READY)))
53752 + return;
53753 +
53754 + preempt_disable();
53755 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53756 +
53757 + if (unlikely((unsigned long)matchn)) {
53758 + write_lock(&gr_inode_lock);
53759 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53760 + write_unlock(&gr_inode_lock);
53761 + }
53762 + preempt_enable();
53763 +
53764 + return;
53765 +}
53766 +
53767 +void
53768 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53769 + struct dentry *old_dentry,
53770 + struct dentry *new_dentry,
53771 + struct vfsmount *mnt, const __u8 replace)
53772 +{
53773 + struct name_entry *matchn;
53774 + struct inodev_entry *inodev;
53775 + struct inode *inode = new_dentry->d_inode;
53776 + ino_t old_ino = old_dentry->d_inode->i_ino;
53777 + dev_t old_dev = __get_dev(old_dentry);
53778 +
53779 + /* vfs_rename swaps the name and parent link for old_dentry and
53780 + new_dentry
53781 + at this point, old_dentry has the new name, parent link, and inode
53782 + for the renamed file
53783 + if a file is being replaced by a rename, new_dentry has the inode
53784 + and name for the replaced file
53785 + */
53786 +
53787 + if (unlikely(!(gr_status & GR_READY)))
53788 + return;
53789 +
53790 + preempt_disable();
53791 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53792 +
53793 + /* we wouldn't have to check d_inode if it weren't for
53794 + NFS silly-renaming
53795 + */
53796 +
53797 + write_lock(&gr_inode_lock);
53798 + if (unlikely(replace && inode)) {
53799 + ino_t new_ino = inode->i_ino;
53800 + dev_t new_dev = __get_dev(new_dentry);
53801 +
53802 + inodev = lookup_inodev_entry(new_ino, new_dev);
53803 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53804 + do_handle_delete(inodev, new_ino, new_dev);
53805 + }
53806 +
53807 + inodev = lookup_inodev_entry(old_ino, old_dev);
53808 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53809 + do_handle_delete(inodev, old_ino, old_dev);
53810 +
53811 + if (unlikely((unsigned long)matchn))
53812 + do_handle_create(matchn, old_dentry, mnt);
53813 +
53814 + write_unlock(&gr_inode_lock);
53815 + preempt_enable();
53816 +
53817 + return;
53818 +}
53819 +
53820 +static int
53821 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53822 + unsigned char **sum)
53823 +{
53824 + struct acl_role_label *r;
53825 + struct role_allowed_ip *ipp;
53826 + struct role_transition *trans;
53827 + unsigned int i;
53828 + int found = 0;
53829 + u32 curr_ip = current->signal->curr_ip;
53830 +
53831 + current->signal->saved_ip = curr_ip;
53832 +
53833 + /* check transition table */
53834 +
53835 + for (trans = current->role->transitions; trans; trans = trans->next) {
53836 + if (!strcmp(rolename, trans->rolename)) {
53837 + found = 1;
53838 + break;
53839 + }
53840 + }
53841 +
53842 + if (!found)
53843 + return 0;
53844 +
53845 + /* handle special roles that do not require authentication
53846 + and check ip */
53847 +
53848 + FOR_EACH_ROLE_START(r)
53849 + if (!strcmp(rolename, r->rolename) &&
53850 + (r->roletype & GR_ROLE_SPECIAL)) {
53851 + found = 0;
53852 + if (r->allowed_ips != NULL) {
53853 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53854 + if ((ntohl(curr_ip) & ipp->netmask) ==
53855 + (ntohl(ipp->addr) & ipp->netmask))
53856 + found = 1;
53857 + }
53858 + } else
53859 + found = 2;
53860 + if (!found)
53861 + return 0;
53862 +
53863 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53864 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53865 + *salt = NULL;
53866 + *sum = NULL;
53867 + return 1;
53868 + }
53869 + }
53870 + FOR_EACH_ROLE_END(r)
53871 +
53872 + for (i = 0; i < num_sprole_pws; i++) {
53873 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53874 + *salt = acl_special_roles[i]->salt;
53875 + *sum = acl_special_roles[i]->sum;
53876 + return 1;
53877 + }
53878 + }
53879 +
53880 + return 0;
53881 +}
53882 +
53883 +static void
53884 +assign_special_role(char *rolename)
53885 +{
53886 + struct acl_object_label *obj;
53887 + struct acl_role_label *r;
53888 + struct acl_role_label *assigned = NULL;
53889 + struct task_struct *tsk;
53890 + struct file *filp;
53891 +
53892 + FOR_EACH_ROLE_START(r)
53893 + if (!strcmp(rolename, r->rolename) &&
53894 + (r->roletype & GR_ROLE_SPECIAL)) {
53895 + assigned = r;
53896 + break;
53897 + }
53898 + FOR_EACH_ROLE_END(r)
53899 +
53900 + if (!assigned)
53901 + return;
53902 +
53903 + read_lock(&tasklist_lock);
53904 + read_lock(&grsec_exec_file_lock);
53905 +
53906 + tsk = current->real_parent;
53907 + if (tsk == NULL)
53908 + goto out_unlock;
53909 +
53910 + filp = tsk->exec_file;
53911 + if (filp == NULL)
53912 + goto out_unlock;
53913 +
53914 + tsk->is_writable = 0;
53915 +
53916 + tsk->acl_sp_role = 1;
53917 + tsk->acl_role_id = ++acl_sp_role_value;
53918 + tsk->role = assigned;
53919 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53920 +
53921 + /* ignore additional mmap checks for processes that are writable
53922 + by the default ACL */
53923 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53924 + if (unlikely(obj->mode & GR_WRITE))
53925 + tsk->is_writable = 1;
53926 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
53927 + if (unlikely(obj->mode & GR_WRITE))
53928 + tsk->is_writable = 1;
53929 +
53930 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53931 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
53932 +#endif
53933 +
53934 +out_unlock:
53935 + read_unlock(&grsec_exec_file_lock);
53936 + read_unlock(&tasklist_lock);
53937 + return;
53938 +}
53939 +
53940 +int gr_check_secure_terminal(struct task_struct *task)
53941 +{
53942 + struct task_struct *p, *p2, *p3;
53943 + struct files_struct *files;
53944 + struct fdtable *fdt;
53945 + struct file *our_file = NULL, *file;
53946 + int i;
53947 +
53948 + if (task->signal->tty == NULL)
53949 + return 1;
53950 +
53951 + files = get_files_struct(task);
53952 + if (files != NULL) {
53953 + rcu_read_lock();
53954 + fdt = files_fdtable(files);
53955 + for (i=0; i < fdt->max_fds; i++) {
53956 + file = fcheck_files(files, i);
53957 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
53958 + get_file(file);
53959 + our_file = file;
53960 + }
53961 + }
53962 + rcu_read_unlock();
53963 + put_files_struct(files);
53964 + }
53965 +
53966 + if (our_file == NULL)
53967 + return 1;
53968 +
53969 + read_lock(&tasklist_lock);
53970 + do_each_thread(p2, p) {
53971 + files = get_files_struct(p);
53972 + if (files == NULL ||
53973 + (p->signal && p->signal->tty == task->signal->tty)) {
53974 + if (files != NULL)
53975 + put_files_struct(files);
53976 + continue;
53977 + }
53978 + rcu_read_lock();
53979 + fdt = files_fdtable(files);
53980 + for (i=0; i < fdt->max_fds; i++) {
53981 + file = fcheck_files(files, i);
53982 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
53983 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
53984 + p3 = task;
53985 + while (p3->pid > 0) {
53986 + if (p3 == p)
53987 + break;
53988 + p3 = p3->real_parent;
53989 + }
53990 + if (p3 == p)
53991 + break;
53992 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
53993 + gr_handle_alertkill(p);
53994 + rcu_read_unlock();
53995 + put_files_struct(files);
53996 + read_unlock(&tasklist_lock);
53997 + fput(our_file);
53998 + return 0;
53999 + }
54000 + }
54001 + rcu_read_unlock();
54002 + put_files_struct(files);
54003 + } while_each_thread(p2, p);
54004 + read_unlock(&tasklist_lock);
54005 +
54006 + fput(our_file);
54007 + return 1;
54008 +}
54009 +
54010 +ssize_t
54011 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54012 +{
54013 + struct gr_arg_wrapper uwrap;
54014 + unsigned char *sprole_salt = NULL;
54015 + unsigned char *sprole_sum = NULL;
54016 + int error = sizeof (struct gr_arg_wrapper);
54017 + int error2 = 0;
54018 +
54019 + mutex_lock(&gr_dev_mutex);
54020 +
54021 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54022 + error = -EPERM;
54023 + goto out;
54024 + }
54025 +
54026 + if (count != sizeof (struct gr_arg_wrapper)) {
54027 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54028 + error = -EINVAL;
54029 + goto out;
54030 + }
54031 +
54032 +
54033 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54034 + gr_auth_expires = 0;
54035 + gr_auth_attempts = 0;
54036 + }
54037 +
54038 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54039 + error = -EFAULT;
54040 + goto out;
54041 + }
54042 +
54043 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54044 + error = -EINVAL;
54045 + goto out;
54046 + }
54047 +
54048 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54049 + error = -EFAULT;
54050 + goto out;
54051 + }
54052 +
54053 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54054 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54055 + time_after(gr_auth_expires, get_seconds())) {
54056 + error = -EBUSY;
54057 + goto out;
54058 + }
54059 +
54060 + /* if non-root trying to do anything other than use a special role,
54061 + do not attempt authentication, do not count towards authentication
54062 + locking
54063 + */
54064 +
54065 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54066 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54067 + current_uid()) {
54068 + error = -EPERM;
54069 + goto out;
54070 + }
54071 +
54072 + /* ensure pw and special role name are null terminated */
54073 +
54074 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54075 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54076 +
54077 + /* Okay.
54078 + * We have our enough of the argument structure..(we have yet
54079 + * to copy_from_user the tables themselves) . Copy the tables
54080 + * only if we need them, i.e. for loading operations. */
54081 +
54082 + switch (gr_usermode->mode) {
54083 + case GR_STATUS:
54084 + if (gr_status & GR_READY) {
54085 + error = 1;
54086 + if (!gr_check_secure_terminal(current))
54087 + error = 3;
54088 + } else
54089 + error = 2;
54090 + goto out;
54091 + case GR_SHUTDOWN:
54092 + if ((gr_status & GR_READY)
54093 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54094 + pax_open_kernel();
54095 + gr_status &= ~GR_READY;
54096 + pax_close_kernel();
54097 +
54098 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54099 + free_variables();
54100 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54101 + memset(gr_system_salt, 0, GR_SALT_LEN);
54102 + memset(gr_system_sum, 0, GR_SHA_LEN);
54103 + } else if (gr_status & GR_READY) {
54104 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54105 + error = -EPERM;
54106 + } else {
54107 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54108 + error = -EAGAIN;
54109 + }
54110 + break;
54111 + case GR_ENABLE:
54112 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54113 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54114 + else {
54115 + if (gr_status & GR_READY)
54116 + error = -EAGAIN;
54117 + else
54118 + error = error2;
54119 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54120 + }
54121 + break;
54122 + case GR_RELOAD:
54123 + if (!(gr_status & GR_READY)) {
54124 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54125 + error = -EAGAIN;
54126 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54127 + preempt_disable();
54128 +
54129 + pax_open_kernel();
54130 + gr_status &= ~GR_READY;
54131 + pax_close_kernel();
54132 +
54133 + free_variables();
54134 + if (!(error2 = gracl_init(gr_usermode))) {
54135 + preempt_enable();
54136 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54137 + } else {
54138 + preempt_enable();
54139 + error = error2;
54140 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54141 + }
54142 + } else {
54143 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54144 + error = -EPERM;
54145 + }
54146 + break;
54147 + case GR_SEGVMOD:
54148 + if (unlikely(!(gr_status & GR_READY))) {
54149 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54150 + error = -EAGAIN;
54151 + break;
54152 + }
54153 +
54154 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54155 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54156 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54157 + struct acl_subject_label *segvacl;
54158 + segvacl =
54159 + lookup_acl_subj_label(gr_usermode->segv_inode,
54160 + gr_usermode->segv_device,
54161 + current->role);
54162 + if (segvacl) {
54163 + segvacl->crashes = 0;
54164 + segvacl->expires = 0;
54165 + }
54166 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54167 + gr_remove_uid(gr_usermode->segv_uid);
54168 + }
54169 + } else {
54170 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54171 + error = -EPERM;
54172 + }
54173 + break;
54174 + case GR_SPROLE:
54175 + case GR_SPROLEPAM:
54176 + if (unlikely(!(gr_status & GR_READY))) {
54177 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54178 + error = -EAGAIN;
54179 + break;
54180 + }
54181 +
54182 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54183 + current->role->expires = 0;
54184 + current->role->auth_attempts = 0;
54185 + }
54186 +
54187 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54188 + time_after(current->role->expires, get_seconds())) {
54189 + error = -EBUSY;
54190 + goto out;
54191 + }
54192 +
54193 + if (lookup_special_role_auth
54194 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54195 + && ((!sprole_salt && !sprole_sum)
54196 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54197 + char *p = "";
54198 + assign_special_role(gr_usermode->sp_role);
54199 + read_lock(&tasklist_lock);
54200 + if (current->real_parent)
54201 + p = current->real_parent->role->rolename;
54202 + read_unlock(&tasklist_lock);
54203 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54204 + p, acl_sp_role_value);
54205 + } else {
54206 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54207 + error = -EPERM;
54208 + if(!(current->role->auth_attempts++))
54209 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54210 +
54211 + goto out;
54212 + }
54213 + break;
54214 + case GR_UNSPROLE:
54215 + if (unlikely(!(gr_status & GR_READY))) {
54216 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54217 + error = -EAGAIN;
54218 + break;
54219 + }
54220 +
54221 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54222 + char *p = "";
54223 + int i = 0;
54224 +
54225 + read_lock(&tasklist_lock);
54226 + if (current->real_parent) {
54227 + p = current->real_parent->role->rolename;
54228 + i = current->real_parent->acl_role_id;
54229 + }
54230 + read_unlock(&tasklist_lock);
54231 +
54232 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54233 + gr_set_acls(1);
54234 + } else {
54235 + error = -EPERM;
54236 + goto out;
54237 + }
54238 + break;
54239 + default:
54240 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54241 + error = -EINVAL;
54242 + break;
54243 + }
54244 +
54245 + if (error != -EPERM)
54246 + goto out;
54247 +
54248 + if(!(gr_auth_attempts++))
54249 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54250 +
54251 + out:
54252 + mutex_unlock(&gr_dev_mutex);
54253 + return error;
54254 +}
54255 +
54256 +/* must be called with
54257 + rcu_read_lock();
54258 + read_lock(&tasklist_lock);
54259 + read_lock(&grsec_exec_file_lock);
54260 +*/
54261 +int gr_apply_subject_to_task(struct task_struct *task)
54262 +{
54263 + struct acl_object_label *obj;
54264 + char *tmpname;
54265 + struct acl_subject_label *tmpsubj;
54266 + struct file *filp;
54267 + struct name_entry *nmatch;
54268 +
54269 + filp = task->exec_file;
54270 + if (filp == NULL)
54271 + return 0;
54272 +
54273 + /* the following is to apply the correct subject
54274 + on binaries running when the RBAC system
54275 + is enabled, when the binaries have been
54276 + replaced or deleted since their execution
54277 + -----
54278 + when the RBAC system starts, the inode/dev
54279 + from exec_file will be one the RBAC system
54280 + is unaware of. It only knows the inode/dev
54281 + of the present file on disk, or the absence
54282 + of it.
54283 + */
54284 + preempt_disable();
54285 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54286 +
54287 + nmatch = lookup_name_entry(tmpname);
54288 + preempt_enable();
54289 + tmpsubj = NULL;
54290 + if (nmatch) {
54291 + if (nmatch->deleted)
54292 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54293 + else
54294 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54295 + if (tmpsubj != NULL)
54296 + task->acl = tmpsubj;
54297 + }
54298 + if (tmpsubj == NULL)
54299 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54300 + task->role);
54301 + if (task->acl) {
54302 + task->is_writable = 0;
54303 + /* ignore additional mmap checks for processes that are writable
54304 + by the default ACL */
54305 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54306 + if (unlikely(obj->mode & GR_WRITE))
54307 + task->is_writable = 1;
54308 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54309 + if (unlikely(obj->mode & GR_WRITE))
54310 + task->is_writable = 1;
54311 +
54312 + gr_set_proc_res(task);
54313 +
54314 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54315 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54316 +#endif
54317 + } else {
54318 + return 1;
54319 + }
54320 +
54321 + return 0;
54322 +}
54323 +
54324 +int
54325 +gr_set_acls(const int type)
54326 +{
54327 + struct task_struct *task, *task2;
54328 + struct acl_role_label *role = current->role;
54329 + __u16 acl_role_id = current->acl_role_id;
54330 + const struct cred *cred;
54331 + int ret;
54332 +
54333 + rcu_read_lock();
54334 + read_lock(&tasklist_lock);
54335 + read_lock(&grsec_exec_file_lock);
54336 + do_each_thread(task2, task) {
54337 + /* check to see if we're called from the exit handler,
54338 + if so, only replace ACLs that have inherited the admin
54339 + ACL */
54340 +
54341 + if (type && (task->role != role ||
54342 + task->acl_role_id != acl_role_id))
54343 + continue;
54344 +
54345 + task->acl_role_id = 0;
54346 + task->acl_sp_role = 0;
54347 +
54348 + if (task->exec_file) {
54349 + cred = __task_cred(task);
54350 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54351 + ret = gr_apply_subject_to_task(task);
54352 + if (ret) {
54353 + read_unlock(&grsec_exec_file_lock);
54354 + read_unlock(&tasklist_lock);
54355 + rcu_read_unlock();
54356 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54357 + return ret;
54358 + }
54359 + } else {
54360 + // it's a kernel process
54361 + task->role = kernel_role;
54362 + task->acl = kernel_role->root_label;
54363 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54364 + task->acl->mode &= ~GR_PROCFIND;
54365 +#endif
54366 + }
54367 + } while_each_thread(task2, task);
54368 + read_unlock(&grsec_exec_file_lock);
54369 + read_unlock(&tasklist_lock);
54370 + rcu_read_unlock();
54371 +
54372 + return 0;
54373 +}
54374 +
54375 +void
54376 +gr_learn_resource(const struct task_struct *task,
54377 + const int res, const unsigned long wanted, const int gt)
54378 +{
54379 + struct acl_subject_label *acl;
54380 + const struct cred *cred;
54381 +
54382 + if (unlikely((gr_status & GR_READY) &&
54383 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54384 + goto skip_reslog;
54385 +
54386 +#ifdef CONFIG_GRKERNSEC_RESLOG
54387 + gr_log_resource(task, res, wanted, gt);
54388 +#endif
54389 + skip_reslog:
54390 +
54391 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54392 + return;
54393 +
54394 + acl = task->acl;
54395 +
54396 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54397 + !(acl->resmask & (1 << (unsigned short) res))))
54398 + return;
54399 +
54400 + if (wanted >= acl->res[res].rlim_cur) {
54401 + unsigned long res_add;
54402 +
54403 + res_add = wanted;
54404 + switch (res) {
54405 + case RLIMIT_CPU:
54406 + res_add += GR_RLIM_CPU_BUMP;
54407 + break;
54408 + case RLIMIT_FSIZE:
54409 + res_add += GR_RLIM_FSIZE_BUMP;
54410 + break;
54411 + case RLIMIT_DATA:
54412 + res_add += GR_RLIM_DATA_BUMP;
54413 + break;
54414 + case RLIMIT_STACK:
54415 + res_add += GR_RLIM_STACK_BUMP;
54416 + break;
54417 + case RLIMIT_CORE:
54418 + res_add += GR_RLIM_CORE_BUMP;
54419 + break;
54420 + case RLIMIT_RSS:
54421 + res_add += GR_RLIM_RSS_BUMP;
54422 + break;
54423 + case RLIMIT_NPROC:
54424 + res_add += GR_RLIM_NPROC_BUMP;
54425 + break;
54426 + case RLIMIT_NOFILE:
54427 + res_add += GR_RLIM_NOFILE_BUMP;
54428 + break;
54429 + case RLIMIT_MEMLOCK:
54430 + res_add += GR_RLIM_MEMLOCK_BUMP;
54431 + break;
54432 + case RLIMIT_AS:
54433 + res_add += GR_RLIM_AS_BUMP;
54434 + break;
54435 + case RLIMIT_LOCKS:
54436 + res_add += GR_RLIM_LOCKS_BUMP;
54437 + break;
54438 + case RLIMIT_SIGPENDING:
54439 + res_add += GR_RLIM_SIGPENDING_BUMP;
54440 + break;
54441 + case RLIMIT_MSGQUEUE:
54442 + res_add += GR_RLIM_MSGQUEUE_BUMP;
54443 + break;
54444 + case RLIMIT_NICE:
54445 + res_add += GR_RLIM_NICE_BUMP;
54446 + break;
54447 + case RLIMIT_RTPRIO:
54448 + res_add += GR_RLIM_RTPRIO_BUMP;
54449 + break;
54450 + case RLIMIT_RTTIME:
54451 + res_add += GR_RLIM_RTTIME_BUMP;
54452 + break;
54453 + }
54454 +
54455 + acl->res[res].rlim_cur = res_add;
54456 +
54457 + if (wanted > acl->res[res].rlim_max)
54458 + acl->res[res].rlim_max = res_add;
54459 +
54460 + /* only log the subject filename, since resource logging is supported for
54461 + single-subject learning only */
54462 + rcu_read_lock();
54463 + cred = __task_cred(task);
54464 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54465 + task->role->roletype, cred->uid, cred->gid, acl->filename,
54466 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54467 + "", (unsigned long) res, &task->signal->saved_ip);
54468 + rcu_read_unlock();
54469 + }
54470 +
54471 + return;
54472 +}
54473 +
54474 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54475 +void
54476 +pax_set_initial_flags(struct linux_binprm *bprm)
54477 +{
54478 + struct task_struct *task = current;
54479 + struct acl_subject_label *proc;
54480 + unsigned long flags;
54481 +
54482 + if (unlikely(!(gr_status & GR_READY)))
54483 + return;
54484 +
54485 + flags = pax_get_flags(task);
54486 +
54487 + proc = task->acl;
54488 +
54489 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54490 + flags &= ~MF_PAX_PAGEEXEC;
54491 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54492 + flags &= ~MF_PAX_SEGMEXEC;
54493 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54494 + flags &= ~MF_PAX_RANDMMAP;
54495 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54496 + flags &= ~MF_PAX_EMUTRAMP;
54497 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54498 + flags &= ~MF_PAX_MPROTECT;
54499 +
54500 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54501 + flags |= MF_PAX_PAGEEXEC;
54502 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54503 + flags |= MF_PAX_SEGMEXEC;
54504 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54505 + flags |= MF_PAX_RANDMMAP;
54506 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54507 + flags |= MF_PAX_EMUTRAMP;
54508 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54509 + flags |= MF_PAX_MPROTECT;
54510 +
54511 + pax_set_flags(task, flags);
54512 +
54513 + return;
54514 +}
54515 +#endif
54516 +
54517 +#ifdef CONFIG_SYSCTL
54518 +/* Eric Biederman likes breaking userland ABI and every inode-based security
54519 + system to save 35kb of memory */
54520 +
54521 +/* we modify the passed in filename, but adjust it back before returning */
54522 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
54523 +{
54524 + struct name_entry *nmatch;
54525 + char *p, *lastp = NULL;
54526 + struct acl_object_label *obj = NULL, *tmp;
54527 + struct acl_subject_label *tmpsubj;
54528 + char c = '\0';
54529 +
54530 + read_lock(&gr_inode_lock);
54531 +
54532 + p = name + len - 1;
54533 + do {
54534 + nmatch = lookup_name_entry(name);
54535 + if (lastp != NULL)
54536 + *lastp = c;
54537 +
54538 + if (nmatch == NULL)
54539 + goto next_component;
54540 + tmpsubj = current->acl;
54541 + do {
54542 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
54543 + if (obj != NULL) {
54544 + tmp = obj->globbed;
54545 + while (tmp) {
54546 + if (!glob_match(tmp->filename, name)) {
54547 + obj = tmp;
54548 + goto found_obj;
54549 + }
54550 + tmp = tmp->next;
54551 + }
54552 + goto found_obj;
54553 + }
54554 + } while ((tmpsubj = tmpsubj->parent_subject));
54555 +next_component:
54556 + /* end case */
54557 + if (p == name)
54558 + break;
54559 +
54560 + while (*p != '/')
54561 + p--;
54562 + if (p == name)
54563 + lastp = p + 1;
54564 + else {
54565 + lastp = p;
54566 + p--;
54567 + }
54568 + c = *lastp;
54569 + *lastp = '\0';
54570 + } while (1);
54571 +found_obj:
54572 + read_unlock(&gr_inode_lock);
54573 + /* obj returned will always be non-null */
54574 + return obj;
54575 +}
54576 +
54577 +/* returns 0 when allowing, non-zero on error
54578 + op of 0 is used for readdir, so we don't log the names of hidden files
54579 +*/
54580 +__u32
54581 +gr_handle_sysctl(const struct ctl_table *table, const int op)
54582 +{
54583 + struct ctl_table *tmp;
54584 + const char *proc_sys = "/proc/sys";
54585 + char *path;
54586 + struct acl_object_label *obj;
54587 + unsigned short len = 0, pos = 0, depth = 0, i;
54588 + __u32 err = 0;
54589 + __u32 mode = 0;
54590 +
54591 + if (unlikely(!(gr_status & GR_READY)))
54592 + return 0;
54593 +
54594 + /* for now, ignore operations on non-sysctl entries if it's not a
54595 + readdir*/
54596 + if (table->child != NULL && op != 0)
54597 + return 0;
54598 +
54599 + mode |= GR_FIND;
54600 + /* it's only a read if it's an entry, read on dirs is for readdir */
54601 + if (op & MAY_READ)
54602 + mode |= GR_READ;
54603 + if (op & MAY_WRITE)
54604 + mode |= GR_WRITE;
54605 +
54606 + preempt_disable();
54607 +
54608 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54609 +
54610 + /* it's only a read/write if it's an actual entry, not a dir
54611 + (which are opened for readdir)
54612 + */
54613 +
54614 + /* convert the requested sysctl entry into a pathname */
54615 +
54616 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54617 + len += strlen(tmp->procname);
54618 + len++;
54619 + depth++;
54620 + }
54621 +
54622 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
54623 + /* deny */
54624 + goto out;
54625 + }
54626 +
54627 + memset(path, 0, PAGE_SIZE);
54628 +
54629 + memcpy(path, proc_sys, strlen(proc_sys));
54630 +
54631 + pos += strlen(proc_sys);
54632 +
54633 + for (; depth > 0; depth--) {
54634 + path[pos] = '/';
54635 + pos++;
54636 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54637 + if (depth == i) {
54638 + memcpy(path + pos, tmp->procname,
54639 + strlen(tmp->procname));
54640 + pos += strlen(tmp->procname);
54641 + }
54642 + i++;
54643 + }
54644 + }
54645 +
54646 + obj = gr_lookup_by_name(path, pos);
54647 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
54648 +
54649 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
54650 + ((err & mode) != mode))) {
54651 + __u32 new_mode = mode;
54652 +
54653 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54654 +
54655 + err = 0;
54656 + gr_log_learn_sysctl(path, new_mode);
54657 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
54658 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
54659 + err = -ENOENT;
54660 + } else if (!(err & GR_FIND)) {
54661 + err = -ENOENT;
54662 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
54663 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
54664 + path, (mode & GR_READ) ? " reading" : "",
54665 + (mode & GR_WRITE) ? " writing" : "");
54666 + err = -EACCES;
54667 + } else if ((err & mode) != mode) {
54668 + err = -EACCES;
54669 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
54670 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
54671 + path, (mode & GR_READ) ? " reading" : "",
54672 + (mode & GR_WRITE) ? " writing" : "");
54673 + err = 0;
54674 + } else
54675 + err = 0;
54676 +
54677 + out:
54678 + preempt_enable();
54679 +
54680 + return err;
54681 +}
54682 +#endif
54683 +
54684 +int
54685 +gr_handle_proc_ptrace(struct task_struct *task)
54686 +{
54687 + struct file *filp;
54688 + struct task_struct *tmp = task;
54689 + struct task_struct *curtemp = current;
54690 + __u32 retmode;
54691 +
54692 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54693 + if (unlikely(!(gr_status & GR_READY)))
54694 + return 0;
54695 +#endif
54696 +
54697 + read_lock(&tasklist_lock);
54698 + read_lock(&grsec_exec_file_lock);
54699 + filp = task->exec_file;
54700 +
54701 + while (tmp->pid > 0) {
54702 + if (tmp == curtemp)
54703 + break;
54704 + tmp = tmp->real_parent;
54705 + }
54706 +
54707 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54708 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54709 + read_unlock(&grsec_exec_file_lock);
54710 + read_unlock(&tasklist_lock);
54711 + return 1;
54712 + }
54713 +
54714 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54715 + if (!(gr_status & GR_READY)) {
54716 + read_unlock(&grsec_exec_file_lock);
54717 + read_unlock(&tasklist_lock);
54718 + return 0;
54719 + }
54720 +#endif
54721 +
54722 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54723 + read_unlock(&grsec_exec_file_lock);
54724 + read_unlock(&tasklist_lock);
54725 +
54726 + if (retmode & GR_NOPTRACE)
54727 + return 1;
54728 +
54729 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54730 + && (current->acl != task->acl || (current->acl != current->role->root_label
54731 + && current->pid != task->pid)))
54732 + return 1;
54733 +
54734 + return 0;
54735 +}
54736 +
54737 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54738 +{
54739 + if (unlikely(!(gr_status & GR_READY)))
54740 + return;
54741 +
54742 + if (!(current->role->roletype & GR_ROLE_GOD))
54743 + return;
54744 +
54745 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54746 + p->role->rolename, gr_task_roletype_to_char(p),
54747 + p->acl->filename);
54748 +}
54749 +
54750 +int
54751 +gr_handle_ptrace(struct task_struct *task, const long request)
54752 +{
54753 + struct task_struct *tmp = task;
54754 + struct task_struct *curtemp = current;
54755 + __u32 retmode;
54756 +
54757 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54758 + if (unlikely(!(gr_status & GR_READY)))
54759 + return 0;
54760 +#endif
54761 +
54762 + read_lock(&tasklist_lock);
54763 + while (tmp->pid > 0) {
54764 + if (tmp == curtemp)
54765 + break;
54766 + tmp = tmp->real_parent;
54767 + }
54768 +
54769 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54770 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54771 + read_unlock(&tasklist_lock);
54772 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54773 + return 1;
54774 + }
54775 + read_unlock(&tasklist_lock);
54776 +
54777 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54778 + if (!(gr_status & GR_READY))
54779 + return 0;
54780 +#endif
54781 +
54782 + read_lock(&grsec_exec_file_lock);
54783 + if (unlikely(!task->exec_file)) {
54784 + read_unlock(&grsec_exec_file_lock);
54785 + return 0;
54786 + }
54787 +
54788 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54789 + read_unlock(&grsec_exec_file_lock);
54790 +
54791 + if (retmode & GR_NOPTRACE) {
54792 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54793 + return 1;
54794 + }
54795 +
54796 + if (retmode & GR_PTRACERD) {
54797 + switch (request) {
54798 + case PTRACE_SEIZE:
54799 + case PTRACE_POKETEXT:
54800 + case PTRACE_POKEDATA:
54801 + case PTRACE_POKEUSR:
54802 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54803 + case PTRACE_SETREGS:
54804 + case PTRACE_SETFPREGS:
54805 +#endif
54806 +#ifdef CONFIG_X86
54807 + case PTRACE_SETFPXREGS:
54808 +#endif
54809 +#ifdef CONFIG_ALTIVEC
54810 + case PTRACE_SETVRREGS:
54811 +#endif
54812 + return 1;
54813 + default:
54814 + return 0;
54815 + }
54816 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
54817 + !(current->role->roletype & GR_ROLE_GOD) &&
54818 + (current->acl != task->acl)) {
54819 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54820 + return 1;
54821 + }
54822 +
54823 + return 0;
54824 +}
54825 +
54826 +static int is_writable_mmap(const struct file *filp)
54827 +{
54828 + struct task_struct *task = current;
54829 + struct acl_object_label *obj, *obj2;
54830 +
54831 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54832 + !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))) {
54833 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54834 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54835 + task->role->root_label);
54836 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54837 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54838 + return 1;
54839 + }
54840 + }
54841 + return 0;
54842 +}
54843 +
54844 +int
54845 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54846 +{
54847 + __u32 mode;
54848 +
54849 + if (unlikely(!file || !(prot & PROT_EXEC)))
54850 + return 1;
54851 +
54852 + if (is_writable_mmap(file))
54853 + return 0;
54854 +
54855 + mode =
54856 + gr_search_file(file->f_path.dentry,
54857 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54858 + file->f_path.mnt);
54859 +
54860 + if (!gr_tpe_allow(file))
54861 + return 0;
54862 +
54863 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54864 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54865 + return 0;
54866 + } else if (unlikely(!(mode & GR_EXEC))) {
54867 + return 0;
54868 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54869 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54870 + return 1;
54871 + }
54872 +
54873 + return 1;
54874 +}
54875 +
54876 +int
54877 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54878 +{
54879 + __u32 mode;
54880 +
54881 + if (unlikely(!file || !(prot & PROT_EXEC)))
54882 + return 1;
54883 +
54884 + if (is_writable_mmap(file))
54885 + return 0;
54886 +
54887 + mode =
54888 + gr_search_file(file->f_path.dentry,
54889 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54890 + file->f_path.mnt);
54891 +
54892 + if (!gr_tpe_allow(file))
54893 + return 0;
54894 +
54895 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54896 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54897 + return 0;
54898 + } else if (unlikely(!(mode & GR_EXEC))) {
54899 + return 0;
54900 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54901 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54902 + return 1;
54903 + }
54904 +
54905 + return 1;
54906 +}
54907 +
54908 +void
54909 +gr_acl_handle_psacct(struct task_struct *task, const long code)
54910 +{
54911 + unsigned long runtime;
54912 + unsigned long cputime;
54913 + unsigned int wday, cday;
54914 + __u8 whr, chr;
54915 + __u8 wmin, cmin;
54916 + __u8 wsec, csec;
54917 + struct timespec timeval;
54918 +
54919 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54920 + !(task->acl->mode & GR_PROCACCT)))
54921 + return;
54922 +
54923 + do_posix_clock_monotonic_gettime(&timeval);
54924 + runtime = timeval.tv_sec - task->start_time.tv_sec;
54925 + wday = runtime / (3600 * 24);
54926 + runtime -= wday * (3600 * 24);
54927 + whr = runtime / 3600;
54928 + runtime -= whr * 3600;
54929 + wmin = runtime / 60;
54930 + runtime -= wmin * 60;
54931 + wsec = runtime;
54932 +
54933 + cputime = (task->utime + task->stime) / HZ;
54934 + cday = cputime / (3600 * 24);
54935 + cputime -= cday * (3600 * 24);
54936 + chr = cputime / 3600;
54937 + cputime -= chr * 3600;
54938 + cmin = cputime / 60;
54939 + cputime -= cmin * 60;
54940 + csec = cputime;
54941 +
54942 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
54943 +
54944 + return;
54945 +}
54946 +
54947 +void gr_set_kernel_label(struct task_struct *task)
54948 +{
54949 + if (gr_status & GR_READY) {
54950 + task->role = kernel_role;
54951 + task->acl = kernel_role->root_label;
54952 + }
54953 + return;
54954 +}
54955 +
54956 +#ifdef CONFIG_TASKSTATS
54957 +int gr_is_taskstats_denied(int pid)
54958 +{
54959 + struct task_struct *task;
54960 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54961 + const struct cred *cred;
54962 +#endif
54963 + int ret = 0;
54964 +
54965 + /* restrict taskstats viewing to un-chrooted root users
54966 + who have the 'view' subject flag if the RBAC system is enabled
54967 + */
54968 +
54969 + rcu_read_lock();
54970 + read_lock(&tasklist_lock);
54971 + task = find_task_by_vpid(pid);
54972 + if (task) {
54973 +#ifdef CONFIG_GRKERNSEC_CHROOT
54974 + if (proc_is_chrooted(task))
54975 + ret = -EACCES;
54976 +#endif
54977 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54978 + cred = __task_cred(task);
54979 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54980 + if (cred->uid != 0)
54981 + ret = -EACCES;
54982 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54983 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54984 + ret = -EACCES;
54985 +#endif
54986 +#endif
54987 + if (gr_status & GR_READY) {
54988 + if (!(task->acl->mode & GR_VIEW))
54989 + ret = -EACCES;
54990 + }
54991 + } else
54992 + ret = -ENOENT;
54993 +
54994 + read_unlock(&tasklist_lock);
54995 + rcu_read_unlock();
54996 +
54997 + return ret;
54998 +}
54999 +#endif
55000 +
55001 +/* AUXV entries are filled via a descendant of search_binary_handler
55002 + after we've already applied the subject for the target
55003 +*/
55004 +int gr_acl_enable_at_secure(void)
55005 +{
55006 + if (unlikely(!(gr_status & GR_READY)))
55007 + return 0;
55008 +
55009 + if (current->acl->mode & GR_ATSECURE)
55010 + return 1;
55011 +
55012 + return 0;
55013 +}
55014 +
55015 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55016 +{
55017 + struct task_struct *task = current;
55018 + struct dentry *dentry = file->f_path.dentry;
55019 + struct vfsmount *mnt = file->f_path.mnt;
55020 + struct acl_object_label *obj, *tmp;
55021 + struct acl_subject_label *subj;
55022 + unsigned int bufsize;
55023 + int is_not_root;
55024 + char *path;
55025 + dev_t dev = __get_dev(dentry);
55026 +
55027 + if (unlikely(!(gr_status & GR_READY)))
55028 + return 1;
55029 +
55030 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55031 + return 1;
55032 +
55033 + /* ignore Eric Biederman */
55034 + if (IS_PRIVATE(dentry->d_inode))
55035 + return 1;
55036 +
55037 + subj = task->acl;
55038 + do {
55039 + obj = lookup_acl_obj_label(ino, dev, subj);
55040 + if (obj != NULL)
55041 + return (obj->mode & GR_FIND) ? 1 : 0;
55042 + } while ((subj = subj->parent_subject));
55043 +
55044 + /* this is purely an optimization since we're looking for an object
55045 + for the directory we're doing a readdir on
55046 + if it's possible for any globbed object to match the entry we're
55047 + filling into the directory, then the object we find here will be
55048 + an anchor point with attached globbed objects
55049 + */
55050 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55051 + if (obj->globbed == NULL)
55052 + return (obj->mode & GR_FIND) ? 1 : 0;
55053 +
55054 + is_not_root = ((obj->filename[0] == '/') &&
55055 + (obj->filename[1] == '\0')) ? 0 : 1;
55056 + bufsize = PAGE_SIZE - namelen - is_not_root;
55057 +
55058 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55059 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55060 + return 1;
55061 +
55062 + preempt_disable();
55063 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55064 + bufsize);
55065 +
55066 + bufsize = strlen(path);
55067 +
55068 + /* if base is "/", don't append an additional slash */
55069 + if (is_not_root)
55070 + *(path + bufsize) = '/';
55071 + memcpy(path + bufsize + is_not_root, name, namelen);
55072 + *(path + bufsize + namelen + is_not_root) = '\0';
55073 +
55074 + tmp = obj->globbed;
55075 + while (tmp) {
55076 + if (!glob_match(tmp->filename, path)) {
55077 + preempt_enable();
55078 + return (tmp->mode & GR_FIND) ? 1 : 0;
55079 + }
55080 + tmp = tmp->next;
55081 + }
55082 + preempt_enable();
55083 + return (obj->mode & GR_FIND) ? 1 : 0;
55084 +}
55085 +
55086 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55087 +EXPORT_SYMBOL(gr_acl_is_enabled);
55088 +#endif
55089 +EXPORT_SYMBOL(gr_learn_resource);
55090 +EXPORT_SYMBOL(gr_set_kernel_label);
55091 +#ifdef CONFIG_SECURITY
55092 +EXPORT_SYMBOL(gr_check_user_change);
55093 +EXPORT_SYMBOL(gr_check_group_change);
55094 +#endif
55095 +
55096 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55097 new file mode 100644
55098 index 0000000..34fefda
55099 --- /dev/null
55100 +++ b/grsecurity/gracl_alloc.c
55101 @@ -0,0 +1,105 @@
55102 +#include <linux/kernel.h>
55103 +#include <linux/mm.h>
55104 +#include <linux/slab.h>
55105 +#include <linux/vmalloc.h>
55106 +#include <linux/gracl.h>
55107 +#include <linux/grsecurity.h>
55108 +
55109 +static unsigned long alloc_stack_next = 1;
55110 +static unsigned long alloc_stack_size = 1;
55111 +static void **alloc_stack;
55112 +
55113 +static __inline__ int
55114 +alloc_pop(void)
55115 +{
55116 + if (alloc_stack_next == 1)
55117 + return 0;
55118 +
55119 + kfree(alloc_stack[alloc_stack_next - 2]);
55120 +
55121 + alloc_stack_next--;
55122 +
55123 + return 1;
55124 +}
55125 +
55126 +static __inline__ int
55127 +alloc_push(void *buf)
55128 +{
55129 + if (alloc_stack_next >= alloc_stack_size)
55130 + return 1;
55131 +
55132 + alloc_stack[alloc_stack_next - 1] = buf;
55133 +
55134 + alloc_stack_next++;
55135 +
55136 + return 0;
55137 +}
55138 +
55139 +void *
55140 +acl_alloc(unsigned long len)
55141 +{
55142 + void *ret = NULL;
55143 +
55144 + if (!len || len > PAGE_SIZE)
55145 + goto out;
55146 +
55147 + ret = kmalloc(len, GFP_KERNEL);
55148 +
55149 + if (ret) {
55150 + if (alloc_push(ret)) {
55151 + kfree(ret);
55152 + ret = NULL;
55153 + }
55154 + }
55155 +
55156 +out:
55157 + return ret;
55158 +}
55159 +
55160 +void *
55161 +acl_alloc_num(unsigned long num, unsigned long len)
55162 +{
55163 + if (!len || (num > (PAGE_SIZE / len)))
55164 + return NULL;
55165 +
55166 + return acl_alloc(num * len);
55167 +}
55168 +
55169 +void
55170 +acl_free_all(void)
55171 +{
55172 + if (gr_acl_is_enabled() || !alloc_stack)
55173 + return;
55174 +
55175 + while (alloc_pop()) ;
55176 +
55177 + if (alloc_stack) {
55178 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55179 + kfree(alloc_stack);
55180 + else
55181 + vfree(alloc_stack);
55182 + }
55183 +
55184 + alloc_stack = NULL;
55185 + alloc_stack_size = 1;
55186 + alloc_stack_next = 1;
55187 +
55188 + return;
55189 +}
55190 +
55191 +int
55192 +acl_alloc_stack_init(unsigned long size)
55193 +{
55194 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55195 + alloc_stack =
55196 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55197 + else
55198 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55199 +
55200 + alloc_stack_size = size;
55201 +
55202 + if (!alloc_stack)
55203 + return 0;
55204 + else
55205 + return 1;
55206 +}
55207 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55208 new file mode 100644
55209 index 0000000..955ddfb
55210 --- /dev/null
55211 +++ b/grsecurity/gracl_cap.c
55212 @@ -0,0 +1,101 @@
55213 +#include <linux/kernel.h>
55214 +#include <linux/module.h>
55215 +#include <linux/sched.h>
55216 +#include <linux/gracl.h>
55217 +#include <linux/grsecurity.h>
55218 +#include <linux/grinternal.h>
55219 +
55220 +extern const char *captab_log[];
55221 +extern int captab_log_entries;
55222 +
55223 +int
55224 +gr_acl_is_capable(const int cap)
55225 +{
55226 + struct task_struct *task = current;
55227 + const struct cred *cred = current_cred();
55228 + struct acl_subject_label *curracl;
55229 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55230 + kernel_cap_t cap_audit = __cap_empty_set;
55231 +
55232 + if (!gr_acl_is_enabled())
55233 + return 1;
55234 +
55235 + curracl = task->acl;
55236 +
55237 + cap_drop = curracl->cap_lower;
55238 + cap_mask = curracl->cap_mask;
55239 + cap_audit = curracl->cap_invert_audit;
55240 +
55241 + while ((curracl = curracl->parent_subject)) {
55242 + /* if the cap isn't specified in the current computed mask but is specified in the
55243 + current level subject, and is lowered in the current level subject, then add
55244 + it to the set of dropped capabilities
55245 + otherwise, add the current level subject's mask to the current computed mask
55246 + */
55247 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55248 + cap_raise(cap_mask, cap);
55249 + if (cap_raised(curracl->cap_lower, cap))
55250 + cap_raise(cap_drop, cap);
55251 + if (cap_raised(curracl->cap_invert_audit, cap))
55252 + cap_raise(cap_audit, cap);
55253 + }
55254 + }
55255 +
55256 + if (!cap_raised(cap_drop, cap)) {
55257 + if (cap_raised(cap_audit, cap))
55258 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55259 + return 1;
55260 + }
55261 +
55262 + curracl = task->acl;
55263 +
55264 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55265 + && cap_raised(cred->cap_effective, cap)) {
55266 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55267 + task->role->roletype, cred->uid,
55268 + cred->gid, task->exec_file ?
55269 + gr_to_filename(task->exec_file->f_path.dentry,
55270 + task->exec_file->f_path.mnt) : curracl->filename,
55271 + curracl->filename, 0UL,
55272 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55273 + return 1;
55274 + }
55275 +
55276 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55277 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55278 + return 0;
55279 +}
55280 +
55281 +int
55282 +gr_acl_is_capable_nolog(const int cap)
55283 +{
55284 + struct acl_subject_label *curracl;
55285 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55286 +
55287 + if (!gr_acl_is_enabled())
55288 + return 1;
55289 +
55290 + curracl = current->acl;
55291 +
55292 + cap_drop = curracl->cap_lower;
55293 + cap_mask = curracl->cap_mask;
55294 +
55295 + while ((curracl = curracl->parent_subject)) {
55296 + /* if the cap isn't specified in the current computed mask but is specified in the
55297 + current level subject, and is lowered in the current level subject, then add
55298 + it to the set of dropped capabilities
55299 + otherwise, add the current level subject's mask to the current computed mask
55300 + */
55301 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55302 + cap_raise(cap_mask, cap);
55303 + if (cap_raised(curracl->cap_lower, cap))
55304 + cap_raise(cap_drop, cap);
55305 + }
55306 + }
55307 +
55308 + if (!cap_raised(cap_drop, cap))
55309 + return 1;
55310 +
55311 + return 0;
55312 +}
55313 +
55314 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55315 new file mode 100644
55316 index 0000000..88d0e87
55317 --- /dev/null
55318 +++ b/grsecurity/gracl_fs.c
55319 @@ -0,0 +1,435 @@
55320 +#include <linux/kernel.h>
55321 +#include <linux/sched.h>
55322 +#include <linux/types.h>
55323 +#include <linux/fs.h>
55324 +#include <linux/file.h>
55325 +#include <linux/stat.h>
55326 +#include <linux/grsecurity.h>
55327 +#include <linux/grinternal.h>
55328 +#include <linux/gracl.h>
55329 +
55330 +umode_t
55331 +gr_acl_umask(void)
55332 +{
55333 + if (unlikely(!gr_acl_is_enabled()))
55334 + return 0;
55335 +
55336 + return current->role->umask;
55337 +}
55338 +
55339 +__u32
55340 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55341 + const struct vfsmount * mnt)
55342 +{
55343 + __u32 mode;
55344 +
55345 + if (unlikely(!dentry->d_inode))
55346 + return GR_FIND;
55347 +
55348 + mode =
55349 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55350 +
55351 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55352 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55353 + return mode;
55354 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55355 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55356 + return 0;
55357 + } else if (unlikely(!(mode & GR_FIND)))
55358 + return 0;
55359 +
55360 + return GR_FIND;
55361 +}
55362 +
55363 +__u32
55364 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55365 + int acc_mode)
55366 +{
55367 + __u32 reqmode = GR_FIND;
55368 + __u32 mode;
55369 +
55370 + if (unlikely(!dentry->d_inode))
55371 + return reqmode;
55372 +
55373 + if (acc_mode & MAY_APPEND)
55374 + reqmode |= GR_APPEND;
55375 + else if (acc_mode & MAY_WRITE)
55376 + reqmode |= GR_WRITE;
55377 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55378 + reqmode |= GR_READ;
55379 +
55380 + mode =
55381 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55382 + mnt);
55383 +
55384 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55385 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55386 + reqmode & GR_READ ? " reading" : "",
55387 + reqmode & GR_WRITE ? " writing" : reqmode &
55388 + GR_APPEND ? " appending" : "");
55389 + return reqmode;
55390 + } else
55391 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55392 + {
55393 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55394 + reqmode & GR_READ ? " reading" : "",
55395 + reqmode & GR_WRITE ? " writing" : reqmode &
55396 + GR_APPEND ? " appending" : "");
55397 + return 0;
55398 + } else if (unlikely((mode & reqmode) != reqmode))
55399 + return 0;
55400 +
55401 + return reqmode;
55402 +}
55403 +
55404 +__u32
55405 +gr_acl_handle_creat(const struct dentry * dentry,
55406 + const struct dentry * p_dentry,
55407 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55408 + const int imode)
55409 +{
55410 + __u32 reqmode = GR_WRITE | GR_CREATE;
55411 + __u32 mode;
55412 +
55413 + if (acc_mode & MAY_APPEND)
55414 + reqmode |= GR_APPEND;
55415 + // if a directory was required or the directory already exists, then
55416 + // don't count this open as a read
55417 + if ((acc_mode & MAY_READ) &&
55418 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55419 + reqmode |= GR_READ;
55420 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
55421 + reqmode |= GR_SETID;
55422 +
55423 + mode =
55424 + gr_check_create(dentry, p_dentry, p_mnt,
55425 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55426 +
55427 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55428 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55429 + reqmode & GR_READ ? " reading" : "",
55430 + reqmode & GR_WRITE ? " writing" : reqmode &
55431 + GR_APPEND ? " appending" : "");
55432 + return reqmode;
55433 + } else
55434 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55435 + {
55436 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55437 + reqmode & GR_READ ? " reading" : "",
55438 + reqmode & GR_WRITE ? " writing" : reqmode &
55439 + GR_APPEND ? " appending" : "");
55440 + return 0;
55441 + } else if (unlikely((mode & reqmode) != reqmode))
55442 + return 0;
55443 +
55444 + return reqmode;
55445 +}
55446 +
55447 +__u32
55448 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55449 + const int fmode)
55450 +{
55451 + __u32 mode, reqmode = GR_FIND;
55452 +
55453 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55454 + reqmode |= GR_EXEC;
55455 + if (fmode & S_IWOTH)
55456 + reqmode |= GR_WRITE;
55457 + if (fmode & S_IROTH)
55458 + reqmode |= GR_READ;
55459 +
55460 + mode =
55461 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55462 + mnt);
55463 +
55464 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55465 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55466 + reqmode & GR_READ ? " reading" : "",
55467 + reqmode & GR_WRITE ? " writing" : "",
55468 + reqmode & GR_EXEC ? " executing" : "");
55469 + return reqmode;
55470 + } else
55471 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55472 + {
55473 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55474 + reqmode & GR_READ ? " reading" : "",
55475 + reqmode & GR_WRITE ? " writing" : "",
55476 + reqmode & GR_EXEC ? " executing" : "");
55477 + return 0;
55478 + } else if (unlikely((mode & reqmode) != reqmode))
55479 + return 0;
55480 +
55481 + return reqmode;
55482 +}
55483 +
55484 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55485 +{
55486 + __u32 mode;
55487 +
55488 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55489 +
55490 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55491 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55492 + return mode;
55493 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55494 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55495 + return 0;
55496 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55497 + return 0;
55498 +
55499 + return (reqmode);
55500 +}
55501 +
55502 +__u32
55503 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55504 +{
55505 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55506 +}
55507 +
55508 +__u32
55509 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55510 +{
55511 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55512 +}
55513 +
55514 +__u32
55515 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55516 +{
55517 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55518 +}
55519 +
55520 +__u32
55521 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55522 +{
55523 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55524 +}
55525 +
55526 +__u32
55527 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55528 + umode_t *modeptr)
55529 +{
55530 + umode_t mode;
55531 +
55532 + *modeptr &= ~gr_acl_umask();
55533 + mode = *modeptr;
55534 +
55535 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55536 + return 1;
55537 +
55538 + if (unlikely(mode & (S_ISUID | S_ISGID))) {
55539 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55540 + GR_CHMOD_ACL_MSG);
55541 + } else {
55542 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55543 + }
55544 +}
55545 +
55546 +__u32
55547 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55548 +{
55549 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55550 +}
55551 +
55552 +__u32
55553 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55554 +{
55555 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55556 +}
55557 +
55558 +__u32
55559 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55560 +{
55561 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55562 +}
55563 +
55564 +__u32
55565 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55566 +{
55567 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55568 + GR_UNIXCONNECT_ACL_MSG);
55569 +}
55570 +
55571 +/* hardlinks require at minimum create and link permission,
55572 + any additional privilege required is based on the
55573 + privilege of the file being linked to
55574 +*/
55575 +__u32
55576 +gr_acl_handle_link(const struct dentry * new_dentry,
55577 + const struct dentry * parent_dentry,
55578 + const struct vfsmount * parent_mnt,
55579 + const struct dentry * old_dentry,
55580 + const struct vfsmount * old_mnt, const char *to)
55581 +{
55582 + __u32 mode;
55583 + __u32 needmode = GR_CREATE | GR_LINK;
55584 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55585 +
55586 + mode =
55587 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55588 + old_mnt);
55589 +
55590 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55591 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55592 + return mode;
55593 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55594 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55595 + return 0;
55596 + } else if (unlikely((mode & needmode) != needmode))
55597 + return 0;
55598 +
55599 + return 1;
55600 +}
55601 +
55602 +__u32
55603 +gr_acl_handle_symlink(const struct dentry * new_dentry,
55604 + const struct dentry * parent_dentry,
55605 + const struct vfsmount * parent_mnt, const char *from)
55606 +{
55607 + __u32 needmode = GR_WRITE | GR_CREATE;
55608 + __u32 mode;
55609 +
55610 + mode =
55611 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
55612 + GR_CREATE | GR_AUDIT_CREATE |
55613 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55614 +
55615 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55616 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55617 + return mode;
55618 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55619 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55620 + return 0;
55621 + } else if (unlikely((mode & needmode) != needmode))
55622 + return 0;
55623 +
55624 + return (GR_WRITE | GR_CREATE);
55625 +}
55626 +
55627 +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)
55628 +{
55629 + __u32 mode;
55630 +
55631 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55632 +
55633 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55634 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55635 + return mode;
55636 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55637 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55638 + return 0;
55639 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55640 + return 0;
55641 +
55642 + return (reqmode);
55643 +}
55644 +
55645 +__u32
55646 +gr_acl_handle_mknod(const struct dentry * new_dentry,
55647 + const struct dentry * parent_dentry,
55648 + const struct vfsmount * parent_mnt,
55649 + const int mode)
55650 +{
55651 + __u32 reqmode = GR_WRITE | GR_CREATE;
55652 + if (unlikely(mode & (S_ISUID | S_ISGID)))
55653 + reqmode |= GR_SETID;
55654 +
55655 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55656 + reqmode, GR_MKNOD_ACL_MSG);
55657 +}
55658 +
55659 +__u32
55660 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
55661 + const struct dentry *parent_dentry,
55662 + const struct vfsmount *parent_mnt)
55663 +{
55664 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55665 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55666 +}
55667 +
55668 +#define RENAME_CHECK_SUCCESS(old, new) \
55669 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55670 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55671 +
55672 +int
55673 +gr_acl_handle_rename(struct dentry *new_dentry,
55674 + struct dentry *parent_dentry,
55675 + const struct vfsmount *parent_mnt,
55676 + struct dentry *old_dentry,
55677 + struct inode *old_parent_inode,
55678 + struct vfsmount *old_mnt, const char *newname)
55679 +{
55680 + __u32 comp1, comp2;
55681 + int error = 0;
55682 +
55683 + if (unlikely(!gr_acl_is_enabled()))
55684 + return 0;
55685 +
55686 + if (!new_dentry->d_inode) {
55687 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55688 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55689 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55690 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55691 + GR_DELETE | GR_AUDIT_DELETE |
55692 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55693 + GR_SUPPRESS, old_mnt);
55694 + } else {
55695 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55696 + GR_CREATE | GR_DELETE |
55697 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55698 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55699 + GR_SUPPRESS, parent_mnt);
55700 + comp2 =
55701 + gr_search_file(old_dentry,
55702 + GR_READ | GR_WRITE | GR_AUDIT_READ |
55703 + GR_DELETE | GR_AUDIT_DELETE |
55704 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55705 + }
55706 +
55707 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55708 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55709 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55710 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55711 + && !(comp2 & GR_SUPPRESS)) {
55712 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55713 + error = -EACCES;
55714 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55715 + error = -EACCES;
55716 +
55717 + return error;
55718 +}
55719 +
55720 +void
55721 +gr_acl_handle_exit(void)
55722 +{
55723 + u16 id;
55724 + char *rolename;
55725 + struct file *exec_file;
55726 +
55727 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55728 + !(current->role->roletype & GR_ROLE_PERSIST))) {
55729 + id = current->acl_role_id;
55730 + rolename = current->role->rolename;
55731 + gr_set_acls(1);
55732 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55733 + }
55734 +
55735 + write_lock(&grsec_exec_file_lock);
55736 + exec_file = current->exec_file;
55737 + current->exec_file = NULL;
55738 + write_unlock(&grsec_exec_file_lock);
55739 +
55740 + if (exec_file)
55741 + fput(exec_file);
55742 +}
55743 +
55744 +int
55745 +gr_acl_handle_procpidmem(const struct task_struct *task)
55746 +{
55747 + if (unlikely(!gr_acl_is_enabled()))
55748 + return 0;
55749 +
55750 + if (task != current && task->acl->mode & GR_PROTPROCFD)
55751 + return -EACCES;
55752 +
55753 + return 0;
55754 +}
55755 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55756 new file mode 100644
55757 index 0000000..17050ca
55758 --- /dev/null
55759 +++ b/grsecurity/gracl_ip.c
55760 @@ -0,0 +1,381 @@
55761 +#include <linux/kernel.h>
55762 +#include <asm/uaccess.h>
55763 +#include <asm/errno.h>
55764 +#include <net/sock.h>
55765 +#include <linux/file.h>
55766 +#include <linux/fs.h>
55767 +#include <linux/net.h>
55768 +#include <linux/in.h>
55769 +#include <linux/skbuff.h>
55770 +#include <linux/ip.h>
55771 +#include <linux/udp.h>
55772 +#include <linux/types.h>
55773 +#include <linux/sched.h>
55774 +#include <linux/netdevice.h>
55775 +#include <linux/inetdevice.h>
55776 +#include <linux/gracl.h>
55777 +#include <linux/grsecurity.h>
55778 +#include <linux/grinternal.h>
55779 +
55780 +#define GR_BIND 0x01
55781 +#define GR_CONNECT 0x02
55782 +#define GR_INVERT 0x04
55783 +#define GR_BINDOVERRIDE 0x08
55784 +#define GR_CONNECTOVERRIDE 0x10
55785 +#define GR_SOCK_FAMILY 0x20
55786 +
55787 +static const char * gr_protocols[IPPROTO_MAX] = {
55788 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55789 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55790 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55791 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55792 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55793 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55794 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55795 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55796 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55797 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55798 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55799 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55800 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55801 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55802 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55803 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55804 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55805 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55806 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55807 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55808 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55809 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55810 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55811 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55812 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55813 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55814 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55815 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55816 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55817 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55818 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55819 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55820 + };
55821 +
55822 +static const char * gr_socktypes[SOCK_MAX] = {
55823 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55824 + "unknown:7", "unknown:8", "unknown:9", "packet"
55825 + };
55826 +
55827 +static const char * gr_sockfamilies[AF_MAX+1] = {
55828 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55829 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55830 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55831 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55832 + };
55833 +
55834 +const char *
55835 +gr_proto_to_name(unsigned char proto)
55836 +{
55837 + return gr_protocols[proto];
55838 +}
55839 +
55840 +const char *
55841 +gr_socktype_to_name(unsigned char type)
55842 +{
55843 + return gr_socktypes[type];
55844 +}
55845 +
55846 +const char *
55847 +gr_sockfamily_to_name(unsigned char family)
55848 +{
55849 + return gr_sockfamilies[family];
55850 +}
55851 +
55852 +int
55853 +gr_search_socket(const int domain, const int type, const int protocol)
55854 +{
55855 + struct acl_subject_label *curr;
55856 + const struct cred *cred = current_cred();
55857 +
55858 + if (unlikely(!gr_acl_is_enabled()))
55859 + goto exit;
55860 +
55861 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
55862 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55863 + goto exit; // let the kernel handle it
55864 +
55865 + curr = current->acl;
55866 +
55867 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55868 + /* the family is allowed, if this is PF_INET allow it only if
55869 + the extra sock type/protocol checks pass */
55870 + if (domain == PF_INET)
55871 + goto inet_check;
55872 + goto exit;
55873 + } else {
55874 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55875 + __u32 fakeip = 0;
55876 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55877 + current->role->roletype, cred->uid,
55878 + cred->gid, current->exec_file ?
55879 + gr_to_filename(current->exec_file->f_path.dentry,
55880 + current->exec_file->f_path.mnt) :
55881 + curr->filename, curr->filename,
55882 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55883 + &current->signal->saved_ip);
55884 + goto exit;
55885 + }
55886 + goto exit_fail;
55887 + }
55888 +
55889 +inet_check:
55890 + /* the rest of this checking is for IPv4 only */
55891 + if (!curr->ips)
55892 + goto exit;
55893 +
55894 + if ((curr->ip_type & (1 << type)) &&
55895 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55896 + goto exit;
55897 +
55898 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55899 + /* we don't place acls on raw sockets , and sometimes
55900 + dgram/ip sockets are opened for ioctl and not
55901 + bind/connect, so we'll fake a bind learn log */
55902 + if (type == SOCK_RAW || type == SOCK_PACKET) {
55903 + __u32 fakeip = 0;
55904 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55905 + current->role->roletype, cred->uid,
55906 + cred->gid, current->exec_file ?
55907 + gr_to_filename(current->exec_file->f_path.dentry,
55908 + current->exec_file->f_path.mnt) :
55909 + curr->filename, curr->filename,
55910 + &fakeip, 0, type,
55911 + protocol, GR_CONNECT, &current->signal->saved_ip);
55912 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55913 + __u32 fakeip = 0;
55914 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55915 + current->role->roletype, cred->uid,
55916 + cred->gid, current->exec_file ?
55917 + gr_to_filename(current->exec_file->f_path.dentry,
55918 + current->exec_file->f_path.mnt) :
55919 + curr->filename, curr->filename,
55920 + &fakeip, 0, type,
55921 + protocol, GR_BIND, &current->signal->saved_ip);
55922 + }
55923 + /* we'll log when they use connect or bind */
55924 + goto exit;
55925 + }
55926 +
55927 +exit_fail:
55928 + if (domain == PF_INET)
55929 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
55930 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
55931 + else
55932 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55933 + gr_socktype_to_name(type), protocol);
55934 +
55935 + return 0;
55936 +exit:
55937 + return 1;
55938 +}
55939 +
55940 +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)
55941 +{
55942 + if ((ip->mode & mode) &&
55943 + (ip_port >= ip->low) &&
55944 + (ip_port <= ip->high) &&
55945 + ((ntohl(ip_addr) & our_netmask) ==
55946 + (ntohl(our_addr) & our_netmask))
55947 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55948 + && (ip->type & (1 << type))) {
55949 + if (ip->mode & GR_INVERT)
55950 + return 2; // specifically denied
55951 + else
55952 + return 1; // allowed
55953 + }
55954 +
55955 + return 0; // not specifically allowed, may continue parsing
55956 +}
55957 +
55958 +static int
55959 +gr_search_connectbind(const int full_mode, struct sock *sk,
55960 + struct sockaddr_in *addr, const int type)
55961 +{
55962 + char iface[IFNAMSIZ] = {0};
55963 + struct acl_subject_label *curr;
55964 + struct acl_ip_label *ip;
55965 + struct inet_sock *isk;
55966 + struct net_device *dev;
55967 + struct in_device *idev;
55968 + unsigned long i;
55969 + int ret;
55970 + int mode = full_mode & (GR_BIND | GR_CONNECT);
55971 + __u32 ip_addr = 0;
55972 + __u32 our_addr;
55973 + __u32 our_netmask;
55974 + char *p;
55975 + __u16 ip_port = 0;
55976 + const struct cred *cred = current_cred();
55977 +
55978 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55979 + return 0;
55980 +
55981 + curr = current->acl;
55982 + isk = inet_sk(sk);
55983 +
55984 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55985 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55986 + addr->sin_addr.s_addr = curr->inaddr_any_override;
55987 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55988 + struct sockaddr_in saddr;
55989 + int err;
55990 +
55991 + saddr.sin_family = AF_INET;
55992 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
55993 + saddr.sin_port = isk->inet_sport;
55994 +
55995 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55996 + if (err)
55997 + return err;
55998 +
55999 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56000 + if (err)
56001 + return err;
56002 + }
56003 +
56004 + if (!curr->ips)
56005 + return 0;
56006 +
56007 + ip_addr = addr->sin_addr.s_addr;
56008 + ip_port = ntohs(addr->sin_port);
56009 +
56010 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56011 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56012 + current->role->roletype, cred->uid,
56013 + cred->gid, current->exec_file ?
56014 + gr_to_filename(current->exec_file->f_path.dentry,
56015 + current->exec_file->f_path.mnt) :
56016 + curr->filename, curr->filename,
56017 + &ip_addr, ip_port, type,
56018 + sk->sk_protocol, mode, &current->signal->saved_ip);
56019 + return 0;
56020 + }
56021 +
56022 + for (i = 0; i < curr->ip_num; i++) {
56023 + ip = *(curr->ips + i);
56024 + if (ip->iface != NULL) {
56025 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56026 + p = strchr(iface, ':');
56027 + if (p != NULL)
56028 + *p = '\0';
56029 + dev = dev_get_by_name(sock_net(sk), iface);
56030 + if (dev == NULL)
56031 + continue;
56032 + idev = in_dev_get(dev);
56033 + if (idev == NULL) {
56034 + dev_put(dev);
56035 + continue;
56036 + }
56037 + rcu_read_lock();
56038 + for_ifa(idev) {
56039 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56040 + our_addr = ifa->ifa_address;
56041 + our_netmask = 0xffffffff;
56042 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56043 + if (ret == 1) {
56044 + rcu_read_unlock();
56045 + in_dev_put(idev);
56046 + dev_put(dev);
56047 + return 0;
56048 + } else if (ret == 2) {
56049 + rcu_read_unlock();
56050 + in_dev_put(idev);
56051 + dev_put(dev);
56052 + goto denied;
56053 + }
56054 + }
56055 + } endfor_ifa(idev);
56056 + rcu_read_unlock();
56057 + in_dev_put(idev);
56058 + dev_put(dev);
56059 + } else {
56060 + our_addr = ip->addr;
56061 + our_netmask = ip->netmask;
56062 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56063 + if (ret == 1)
56064 + return 0;
56065 + else if (ret == 2)
56066 + goto denied;
56067 + }
56068 + }
56069 +
56070 +denied:
56071 + if (mode == GR_BIND)
56072 + 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));
56073 + else if (mode == GR_CONNECT)
56074 + 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));
56075 +
56076 + return -EACCES;
56077 +}
56078 +
56079 +int
56080 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56081 +{
56082 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56083 +}
56084 +
56085 +int
56086 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56087 +{
56088 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56089 +}
56090 +
56091 +int gr_search_listen(struct socket *sock)
56092 +{
56093 + struct sock *sk = sock->sk;
56094 + struct sockaddr_in addr;
56095 +
56096 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56097 + addr.sin_port = inet_sk(sk)->inet_sport;
56098 +
56099 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56100 +}
56101 +
56102 +int gr_search_accept(struct socket *sock)
56103 +{
56104 + struct sock *sk = sock->sk;
56105 + struct sockaddr_in addr;
56106 +
56107 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56108 + addr.sin_port = inet_sk(sk)->inet_sport;
56109 +
56110 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56111 +}
56112 +
56113 +int
56114 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56115 +{
56116 + if (addr)
56117 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56118 + else {
56119 + struct sockaddr_in sin;
56120 + const struct inet_sock *inet = inet_sk(sk);
56121 +
56122 + sin.sin_addr.s_addr = inet->inet_daddr;
56123 + sin.sin_port = inet->inet_dport;
56124 +
56125 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56126 + }
56127 +}
56128 +
56129 +int
56130 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56131 +{
56132 + struct sockaddr_in sin;
56133 +
56134 + if (unlikely(skb->len < sizeof (struct udphdr)))
56135 + return 0; // skip this packet
56136 +
56137 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56138 + sin.sin_port = udp_hdr(skb)->source;
56139 +
56140 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56141 +}
56142 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56143 new file mode 100644
56144 index 0000000..25f54ef
56145 --- /dev/null
56146 +++ b/grsecurity/gracl_learn.c
56147 @@ -0,0 +1,207 @@
56148 +#include <linux/kernel.h>
56149 +#include <linux/mm.h>
56150 +#include <linux/sched.h>
56151 +#include <linux/poll.h>
56152 +#include <linux/string.h>
56153 +#include <linux/file.h>
56154 +#include <linux/types.h>
56155 +#include <linux/vmalloc.h>
56156 +#include <linux/grinternal.h>
56157 +
56158 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56159 + size_t count, loff_t *ppos);
56160 +extern int gr_acl_is_enabled(void);
56161 +
56162 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56163 +static int gr_learn_attached;
56164 +
56165 +/* use a 512k buffer */
56166 +#define LEARN_BUFFER_SIZE (512 * 1024)
56167 +
56168 +static DEFINE_SPINLOCK(gr_learn_lock);
56169 +static DEFINE_MUTEX(gr_learn_user_mutex);
56170 +
56171 +/* we need to maintain two buffers, so that the kernel context of grlearn
56172 + uses a semaphore around the userspace copying, and the other kernel contexts
56173 + use a spinlock when copying into the buffer, since they cannot sleep
56174 +*/
56175 +static char *learn_buffer;
56176 +static char *learn_buffer_user;
56177 +static int learn_buffer_len;
56178 +static int learn_buffer_user_len;
56179 +
56180 +static ssize_t
56181 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56182 +{
56183 + DECLARE_WAITQUEUE(wait, current);
56184 + ssize_t retval = 0;
56185 +
56186 + add_wait_queue(&learn_wait, &wait);
56187 + set_current_state(TASK_INTERRUPTIBLE);
56188 + do {
56189 + mutex_lock(&gr_learn_user_mutex);
56190 + spin_lock(&gr_learn_lock);
56191 + if (learn_buffer_len)
56192 + break;
56193 + spin_unlock(&gr_learn_lock);
56194 + mutex_unlock(&gr_learn_user_mutex);
56195 + if (file->f_flags & O_NONBLOCK) {
56196 + retval = -EAGAIN;
56197 + goto out;
56198 + }
56199 + if (signal_pending(current)) {
56200 + retval = -ERESTARTSYS;
56201 + goto out;
56202 + }
56203 +
56204 + schedule();
56205 + } while (1);
56206 +
56207 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56208 + learn_buffer_user_len = learn_buffer_len;
56209 + retval = learn_buffer_len;
56210 + learn_buffer_len = 0;
56211 +
56212 + spin_unlock(&gr_learn_lock);
56213 +
56214 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56215 + retval = -EFAULT;
56216 +
56217 + mutex_unlock(&gr_learn_user_mutex);
56218 +out:
56219 + set_current_state(TASK_RUNNING);
56220 + remove_wait_queue(&learn_wait, &wait);
56221 + return retval;
56222 +}
56223 +
56224 +static unsigned int
56225 +poll_learn(struct file * file, poll_table * wait)
56226 +{
56227 + poll_wait(file, &learn_wait, wait);
56228 +
56229 + if (learn_buffer_len)
56230 + return (POLLIN | POLLRDNORM);
56231 +
56232 + return 0;
56233 +}
56234 +
56235 +void
56236 +gr_clear_learn_entries(void)
56237 +{
56238 + char *tmp;
56239 +
56240 + mutex_lock(&gr_learn_user_mutex);
56241 + spin_lock(&gr_learn_lock);
56242 + tmp = learn_buffer;
56243 + learn_buffer = NULL;
56244 + spin_unlock(&gr_learn_lock);
56245 + if (tmp)
56246 + vfree(tmp);
56247 + if (learn_buffer_user != NULL) {
56248 + vfree(learn_buffer_user);
56249 + learn_buffer_user = NULL;
56250 + }
56251 + learn_buffer_len = 0;
56252 + mutex_unlock(&gr_learn_user_mutex);
56253 +
56254 + return;
56255 +}
56256 +
56257 +void
56258 +gr_add_learn_entry(const char *fmt, ...)
56259 +{
56260 + va_list args;
56261 + unsigned int len;
56262 +
56263 + if (!gr_learn_attached)
56264 + return;
56265 +
56266 + spin_lock(&gr_learn_lock);
56267 +
56268 + /* leave a gap at the end so we know when it's "full" but don't have to
56269 + compute the exact length of the string we're trying to append
56270 + */
56271 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56272 + spin_unlock(&gr_learn_lock);
56273 + wake_up_interruptible(&learn_wait);
56274 + return;
56275 + }
56276 + if (learn_buffer == NULL) {
56277 + spin_unlock(&gr_learn_lock);
56278 + return;
56279 + }
56280 +
56281 + va_start(args, fmt);
56282 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56283 + va_end(args);
56284 +
56285 + learn_buffer_len += len + 1;
56286 +
56287 + spin_unlock(&gr_learn_lock);
56288 + wake_up_interruptible(&learn_wait);
56289 +
56290 + return;
56291 +}
56292 +
56293 +static int
56294 +open_learn(struct inode *inode, struct file *file)
56295 +{
56296 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56297 + return -EBUSY;
56298 + if (file->f_mode & FMODE_READ) {
56299 + int retval = 0;
56300 + mutex_lock(&gr_learn_user_mutex);
56301 + if (learn_buffer == NULL)
56302 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56303 + if (learn_buffer_user == NULL)
56304 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56305 + if (learn_buffer == NULL) {
56306 + retval = -ENOMEM;
56307 + goto out_error;
56308 + }
56309 + if (learn_buffer_user == NULL) {
56310 + retval = -ENOMEM;
56311 + goto out_error;
56312 + }
56313 + learn_buffer_len = 0;
56314 + learn_buffer_user_len = 0;
56315 + gr_learn_attached = 1;
56316 +out_error:
56317 + mutex_unlock(&gr_learn_user_mutex);
56318 + return retval;
56319 + }
56320 + return 0;
56321 +}
56322 +
56323 +static int
56324 +close_learn(struct inode *inode, struct file *file)
56325 +{
56326 + if (file->f_mode & FMODE_READ) {
56327 + char *tmp = NULL;
56328 + mutex_lock(&gr_learn_user_mutex);
56329 + spin_lock(&gr_learn_lock);
56330 + tmp = learn_buffer;
56331 + learn_buffer = NULL;
56332 + spin_unlock(&gr_learn_lock);
56333 + if (tmp)
56334 + vfree(tmp);
56335 + if (learn_buffer_user != NULL) {
56336 + vfree(learn_buffer_user);
56337 + learn_buffer_user = NULL;
56338 + }
56339 + learn_buffer_len = 0;
56340 + learn_buffer_user_len = 0;
56341 + gr_learn_attached = 0;
56342 + mutex_unlock(&gr_learn_user_mutex);
56343 + }
56344 +
56345 + return 0;
56346 +}
56347 +
56348 +const struct file_operations grsec_fops = {
56349 + .read = read_learn,
56350 + .write = write_grsec_handler,
56351 + .open = open_learn,
56352 + .release = close_learn,
56353 + .poll = poll_learn,
56354 +};
56355 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56356 new file mode 100644
56357 index 0000000..39645c9
56358 --- /dev/null
56359 +++ b/grsecurity/gracl_res.c
56360 @@ -0,0 +1,68 @@
56361 +#include <linux/kernel.h>
56362 +#include <linux/sched.h>
56363 +#include <linux/gracl.h>
56364 +#include <linux/grinternal.h>
56365 +
56366 +static const char *restab_log[] = {
56367 + [RLIMIT_CPU] = "RLIMIT_CPU",
56368 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56369 + [RLIMIT_DATA] = "RLIMIT_DATA",
56370 + [RLIMIT_STACK] = "RLIMIT_STACK",
56371 + [RLIMIT_CORE] = "RLIMIT_CORE",
56372 + [RLIMIT_RSS] = "RLIMIT_RSS",
56373 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56374 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56375 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56376 + [RLIMIT_AS] = "RLIMIT_AS",
56377 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56378 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56379 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56380 + [RLIMIT_NICE] = "RLIMIT_NICE",
56381 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56382 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56383 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56384 +};
56385 +
56386 +void
56387 +gr_log_resource(const struct task_struct *task,
56388 + const int res, const unsigned long wanted, const int gt)
56389 +{
56390 + const struct cred *cred;
56391 + unsigned long rlim;
56392 +
56393 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56394 + return;
56395 +
56396 + // not yet supported resource
56397 + if (unlikely(!restab_log[res]))
56398 + return;
56399 +
56400 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56401 + rlim = task_rlimit_max(task, res);
56402 + else
56403 + rlim = task_rlimit(task, res);
56404 +
56405 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56406 + return;
56407 +
56408 + rcu_read_lock();
56409 + cred = __task_cred(task);
56410 +
56411 + if (res == RLIMIT_NPROC &&
56412 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56413 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56414 + goto out_rcu_unlock;
56415 + else if (res == RLIMIT_MEMLOCK &&
56416 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56417 + goto out_rcu_unlock;
56418 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56419 + goto out_rcu_unlock;
56420 + rcu_read_unlock();
56421 +
56422 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56423 +
56424 + return;
56425 +out_rcu_unlock:
56426 + rcu_read_unlock();
56427 + return;
56428 +}
56429 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56430 new file mode 100644
56431 index 0000000..5556be3
56432 --- /dev/null
56433 +++ b/grsecurity/gracl_segv.c
56434 @@ -0,0 +1,299 @@
56435 +#include <linux/kernel.h>
56436 +#include <linux/mm.h>
56437 +#include <asm/uaccess.h>
56438 +#include <asm/errno.h>
56439 +#include <asm/mman.h>
56440 +#include <net/sock.h>
56441 +#include <linux/file.h>
56442 +#include <linux/fs.h>
56443 +#include <linux/net.h>
56444 +#include <linux/in.h>
56445 +#include <linux/slab.h>
56446 +#include <linux/types.h>
56447 +#include <linux/sched.h>
56448 +#include <linux/timer.h>
56449 +#include <linux/gracl.h>
56450 +#include <linux/grsecurity.h>
56451 +#include <linux/grinternal.h>
56452 +
56453 +static struct crash_uid *uid_set;
56454 +static unsigned short uid_used;
56455 +static DEFINE_SPINLOCK(gr_uid_lock);
56456 +extern rwlock_t gr_inode_lock;
56457 +extern struct acl_subject_label *
56458 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56459 + struct acl_role_label *role);
56460 +
56461 +#ifdef CONFIG_BTRFS_FS
56462 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56463 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56464 +#endif
56465 +
56466 +static inline dev_t __get_dev(const struct dentry *dentry)
56467 +{
56468 +#ifdef CONFIG_BTRFS_FS
56469 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56470 + return get_btrfs_dev_from_inode(dentry->d_inode);
56471 + else
56472 +#endif
56473 + return dentry->d_inode->i_sb->s_dev;
56474 +}
56475 +
56476 +int
56477 +gr_init_uidset(void)
56478 +{
56479 + uid_set =
56480 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56481 + uid_used = 0;
56482 +
56483 + return uid_set ? 1 : 0;
56484 +}
56485 +
56486 +void
56487 +gr_free_uidset(void)
56488 +{
56489 + if (uid_set)
56490 + kfree(uid_set);
56491 +
56492 + return;
56493 +}
56494 +
56495 +int
56496 +gr_find_uid(const uid_t uid)
56497 +{
56498 + struct crash_uid *tmp = uid_set;
56499 + uid_t buid;
56500 + int low = 0, high = uid_used - 1, mid;
56501 +
56502 + while (high >= low) {
56503 + mid = (low + high) >> 1;
56504 + buid = tmp[mid].uid;
56505 + if (buid == uid)
56506 + return mid;
56507 + if (buid > uid)
56508 + high = mid - 1;
56509 + if (buid < uid)
56510 + low = mid + 1;
56511 + }
56512 +
56513 + return -1;
56514 +}
56515 +
56516 +static __inline__ void
56517 +gr_insertsort(void)
56518 +{
56519 + unsigned short i, j;
56520 + struct crash_uid index;
56521 +
56522 + for (i = 1; i < uid_used; i++) {
56523 + index = uid_set[i];
56524 + j = i;
56525 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56526 + uid_set[j] = uid_set[j - 1];
56527 + j--;
56528 + }
56529 + uid_set[j] = index;
56530 + }
56531 +
56532 + return;
56533 +}
56534 +
56535 +static __inline__ void
56536 +gr_insert_uid(const uid_t uid, const unsigned long expires)
56537 +{
56538 + int loc;
56539 +
56540 + if (uid_used == GR_UIDTABLE_MAX)
56541 + return;
56542 +
56543 + loc = gr_find_uid(uid);
56544 +
56545 + if (loc >= 0) {
56546 + uid_set[loc].expires = expires;
56547 + return;
56548 + }
56549 +
56550 + uid_set[uid_used].uid = uid;
56551 + uid_set[uid_used].expires = expires;
56552 + uid_used++;
56553 +
56554 + gr_insertsort();
56555 +
56556 + return;
56557 +}
56558 +
56559 +void
56560 +gr_remove_uid(const unsigned short loc)
56561 +{
56562 + unsigned short i;
56563 +
56564 + for (i = loc + 1; i < uid_used; i++)
56565 + uid_set[i - 1] = uid_set[i];
56566 +
56567 + uid_used--;
56568 +
56569 + return;
56570 +}
56571 +
56572 +int
56573 +gr_check_crash_uid(const uid_t uid)
56574 +{
56575 + int loc;
56576 + int ret = 0;
56577 +
56578 + if (unlikely(!gr_acl_is_enabled()))
56579 + return 0;
56580 +
56581 + spin_lock(&gr_uid_lock);
56582 + loc = gr_find_uid(uid);
56583 +
56584 + if (loc < 0)
56585 + goto out_unlock;
56586 +
56587 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
56588 + gr_remove_uid(loc);
56589 + else
56590 + ret = 1;
56591 +
56592 +out_unlock:
56593 + spin_unlock(&gr_uid_lock);
56594 + return ret;
56595 +}
56596 +
56597 +static __inline__ int
56598 +proc_is_setxid(const struct cred *cred)
56599 +{
56600 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
56601 + cred->uid != cred->fsuid)
56602 + return 1;
56603 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
56604 + cred->gid != cred->fsgid)
56605 + return 1;
56606 +
56607 + return 0;
56608 +}
56609 +
56610 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
56611 +
56612 +void
56613 +gr_handle_crash(struct task_struct *task, const int sig)
56614 +{
56615 + struct acl_subject_label *curr;
56616 + struct task_struct *tsk, *tsk2;
56617 + const struct cred *cred;
56618 + const struct cred *cred2;
56619 +
56620 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56621 + return;
56622 +
56623 + if (unlikely(!gr_acl_is_enabled()))
56624 + return;
56625 +
56626 + curr = task->acl;
56627 +
56628 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
56629 + return;
56630 +
56631 + if (time_before_eq(curr->expires, get_seconds())) {
56632 + curr->expires = 0;
56633 + curr->crashes = 0;
56634 + }
56635 +
56636 + curr->crashes++;
56637 +
56638 + if (!curr->expires)
56639 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56640 +
56641 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56642 + time_after(curr->expires, get_seconds())) {
56643 + rcu_read_lock();
56644 + cred = __task_cred(task);
56645 + if (cred->uid && proc_is_setxid(cred)) {
56646 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56647 + spin_lock(&gr_uid_lock);
56648 + gr_insert_uid(cred->uid, curr->expires);
56649 + spin_unlock(&gr_uid_lock);
56650 + curr->expires = 0;
56651 + curr->crashes = 0;
56652 + read_lock(&tasklist_lock);
56653 + do_each_thread(tsk2, tsk) {
56654 + cred2 = __task_cred(tsk);
56655 + if (tsk != task && cred2->uid == cred->uid)
56656 + gr_fake_force_sig(SIGKILL, tsk);
56657 + } while_each_thread(tsk2, tsk);
56658 + read_unlock(&tasklist_lock);
56659 + } else {
56660 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56661 + read_lock(&tasklist_lock);
56662 + read_lock(&grsec_exec_file_lock);
56663 + do_each_thread(tsk2, tsk) {
56664 + if (likely(tsk != task)) {
56665 + // if this thread has the same subject as the one that triggered
56666 + // RES_CRASH and it's the same binary, kill it
56667 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56668 + gr_fake_force_sig(SIGKILL, tsk);
56669 + }
56670 + } while_each_thread(tsk2, tsk);
56671 + read_unlock(&grsec_exec_file_lock);
56672 + read_unlock(&tasklist_lock);
56673 + }
56674 + rcu_read_unlock();
56675 + }
56676 +
56677 + return;
56678 +}
56679 +
56680 +int
56681 +gr_check_crash_exec(const struct file *filp)
56682 +{
56683 + struct acl_subject_label *curr;
56684 +
56685 + if (unlikely(!gr_acl_is_enabled()))
56686 + return 0;
56687 +
56688 + read_lock(&gr_inode_lock);
56689 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56690 + __get_dev(filp->f_path.dentry),
56691 + current->role);
56692 + read_unlock(&gr_inode_lock);
56693 +
56694 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56695 + (!curr->crashes && !curr->expires))
56696 + return 0;
56697 +
56698 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56699 + time_after(curr->expires, get_seconds()))
56700 + return 1;
56701 + else if (time_before_eq(curr->expires, get_seconds())) {
56702 + curr->crashes = 0;
56703 + curr->expires = 0;
56704 + }
56705 +
56706 + return 0;
56707 +}
56708 +
56709 +void
56710 +gr_handle_alertkill(struct task_struct *task)
56711 +{
56712 + struct acl_subject_label *curracl;
56713 + __u32 curr_ip;
56714 + struct task_struct *p, *p2;
56715 +
56716 + if (unlikely(!gr_acl_is_enabled()))
56717 + return;
56718 +
56719 + curracl = task->acl;
56720 + curr_ip = task->signal->curr_ip;
56721 +
56722 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56723 + read_lock(&tasklist_lock);
56724 + do_each_thread(p2, p) {
56725 + if (p->signal->curr_ip == curr_ip)
56726 + gr_fake_force_sig(SIGKILL, p);
56727 + } while_each_thread(p2, p);
56728 + read_unlock(&tasklist_lock);
56729 + } else if (curracl->mode & GR_KILLPROC)
56730 + gr_fake_force_sig(SIGKILL, task);
56731 +
56732 + return;
56733 +}
56734 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56735 new file mode 100644
56736 index 0000000..9d83a69
56737 --- /dev/null
56738 +++ b/grsecurity/gracl_shm.c
56739 @@ -0,0 +1,40 @@
56740 +#include <linux/kernel.h>
56741 +#include <linux/mm.h>
56742 +#include <linux/sched.h>
56743 +#include <linux/file.h>
56744 +#include <linux/ipc.h>
56745 +#include <linux/gracl.h>
56746 +#include <linux/grsecurity.h>
56747 +#include <linux/grinternal.h>
56748 +
56749 +int
56750 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56751 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56752 +{
56753 + struct task_struct *task;
56754 +
56755 + if (!gr_acl_is_enabled())
56756 + return 1;
56757 +
56758 + rcu_read_lock();
56759 + read_lock(&tasklist_lock);
56760 +
56761 + task = find_task_by_vpid(shm_cprid);
56762 +
56763 + if (unlikely(!task))
56764 + task = find_task_by_vpid(shm_lapid);
56765 +
56766 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56767 + (task->pid == shm_lapid)) &&
56768 + (task->acl->mode & GR_PROTSHM) &&
56769 + (task->acl != current->acl))) {
56770 + read_unlock(&tasklist_lock);
56771 + rcu_read_unlock();
56772 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56773 + return 0;
56774 + }
56775 + read_unlock(&tasklist_lock);
56776 + rcu_read_unlock();
56777 +
56778 + return 1;
56779 +}
56780 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56781 new file mode 100644
56782 index 0000000..bc0be01
56783 --- /dev/null
56784 +++ b/grsecurity/grsec_chdir.c
56785 @@ -0,0 +1,19 @@
56786 +#include <linux/kernel.h>
56787 +#include <linux/sched.h>
56788 +#include <linux/fs.h>
56789 +#include <linux/file.h>
56790 +#include <linux/grsecurity.h>
56791 +#include <linux/grinternal.h>
56792 +
56793 +void
56794 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56795 +{
56796 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56797 + if ((grsec_enable_chdir && grsec_enable_group &&
56798 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56799 + !grsec_enable_group)) {
56800 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56801 + }
56802 +#endif
56803 + return;
56804 +}
56805 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56806 new file mode 100644
56807 index 0000000..a2dc675
56808 --- /dev/null
56809 +++ b/grsecurity/grsec_chroot.c
56810 @@ -0,0 +1,351 @@
56811 +#include <linux/kernel.h>
56812 +#include <linux/module.h>
56813 +#include <linux/sched.h>
56814 +#include <linux/file.h>
56815 +#include <linux/fs.h>
56816 +#include <linux/mount.h>
56817 +#include <linux/types.h>
56818 +#include <linux/pid_namespace.h>
56819 +#include <linux/grsecurity.h>
56820 +#include <linux/grinternal.h>
56821 +
56822 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56823 +{
56824 +#ifdef CONFIG_GRKERNSEC
56825 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56826 + path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
56827 + task->gr_is_chrooted = 1;
56828 + else
56829 + task->gr_is_chrooted = 0;
56830 +
56831 + task->gr_chroot_dentry = path->dentry;
56832 +#endif
56833 + return;
56834 +}
56835 +
56836 +void gr_clear_chroot_entries(struct task_struct *task)
56837 +{
56838 +#ifdef CONFIG_GRKERNSEC
56839 + task->gr_is_chrooted = 0;
56840 + task->gr_chroot_dentry = NULL;
56841 +#endif
56842 + return;
56843 +}
56844 +
56845 +int
56846 +gr_handle_chroot_unix(const pid_t pid)
56847 +{
56848 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56849 + struct task_struct *p;
56850 +
56851 + if (unlikely(!grsec_enable_chroot_unix))
56852 + return 1;
56853 +
56854 + if (likely(!proc_is_chrooted(current)))
56855 + return 1;
56856 +
56857 + rcu_read_lock();
56858 + read_lock(&tasklist_lock);
56859 + p = find_task_by_vpid_unrestricted(pid);
56860 + if (unlikely(p && !have_same_root(current, p))) {
56861 + read_unlock(&tasklist_lock);
56862 + rcu_read_unlock();
56863 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56864 + return 0;
56865 + }
56866 + read_unlock(&tasklist_lock);
56867 + rcu_read_unlock();
56868 +#endif
56869 + return 1;
56870 +}
56871 +
56872 +int
56873 +gr_handle_chroot_nice(void)
56874 +{
56875 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56876 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56877 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56878 + return -EPERM;
56879 + }
56880 +#endif
56881 + return 0;
56882 +}
56883 +
56884 +int
56885 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56886 +{
56887 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56888 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56889 + && proc_is_chrooted(current)) {
56890 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56891 + return -EACCES;
56892 + }
56893 +#endif
56894 + return 0;
56895 +}
56896 +
56897 +int
56898 +gr_handle_chroot_rawio(const struct inode *inode)
56899 +{
56900 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56901 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56902 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56903 + return 1;
56904 +#endif
56905 + return 0;
56906 +}
56907 +
56908 +int
56909 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56910 +{
56911 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56912 + struct task_struct *p;
56913 + int ret = 0;
56914 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56915 + return ret;
56916 +
56917 + read_lock(&tasklist_lock);
56918 + do_each_pid_task(pid, type, p) {
56919 + if (!have_same_root(current, p)) {
56920 + ret = 1;
56921 + goto out;
56922 + }
56923 + } while_each_pid_task(pid, type, p);
56924 +out:
56925 + read_unlock(&tasklist_lock);
56926 + return ret;
56927 +#endif
56928 + return 0;
56929 +}
56930 +
56931 +int
56932 +gr_pid_is_chrooted(struct task_struct *p)
56933 +{
56934 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56935 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56936 + return 0;
56937 +
56938 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56939 + !have_same_root(current, p)) {
56940 + return 1;
56941 + }
56942 +#endif
56943 + return 0;
56944 +}
56945 +
56946 +EXPORT_SYMBOL(gr_pid_is_chrooted);
56947 +
56948 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56949 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56950 +{
56951 + struct path path, currentroot;
56952 + int ret = 0;
56953 +
56954 + path.dentry = (struct dentry *)u_dentry;
56955 + path.mnt = (struct vfsmount *)u_mnt;
56956 + get_fs_root(current->fs, &currentroot);
56957 + if (path_is_under(&path, &currentroot))
56958 + ret = 1;
56959 + path_put(&currentroot);
56960 +
56961 + return ret;
56962 +}
56963 +#endif
56964 +
56965 +int
56966 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56967 +{
56968 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56969 + if (!grsec_enable_chroot_fchdir)
56970 + return 1;
56971 +
56972 + if (!proc_is_chrooted(current))
56973 + return 1;
56974 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56975 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56976 + return 0;
56977 + }
56978 +#endif
56979 + return 1;
56980 +}
56981 +
56982 +int
56983 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56984 + const time_t shm_createtime)
56985 +{
56986 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56987 + struct task_struct *p;
56988 + time_t starttime;
56989 +
56990 + if (unlikely(!grsec_enable_chroot_shmat))
56991 + return 1;
56992 +
56993 + if (likely(!proc_is_chrooted(current)))
56994 + return 1;
56995 +
56996 + rcu_read_lock();
56997 + read_lock(&tasklist_lock);
56998 +
56999 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57000 + starttime = p->start_time.tv_sec;
57001 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57002 + if (have_same_root(current, p)) {
57003 + goto allow;
57004 + } else {
57005 + read_unlock(&tasklist_lock);
57006 + rcu_read_unlock();
57007 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57008 + return 0;
57009 + }
57010 + }
57011 + /* creator exited, pid reuse, fall through to next check */
57012 + }
57013 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57014 + if (unlikely(!have_same_root(current, p))) {
57015 + read_unlock(&tasklist_lock);
57016 + rcu_read_unlock();
57017 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57018 + return 0;
57019 + }
57020 + }
57021 +
57022 +allow:
57023 + read_unlock(&tasklist_lock);
57024 + rcu_read_unlock();
57025 +#endif
57026 + return 1;
57027 +}
57028 +
57029 +void
57030 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57031 +{
57032 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57033 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57034 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57035 +#endif
57036 + return;
57037 +}
57038 +
57039 +int
57040 +gr_handle_chroot_mknod(const struct dentry *dentry,
57041 + const struct vfsmount *mnt, const int mode)
57042 +{
57043 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57044 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57045 + proc_is_chrooted(current)) {
57046 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57047 + return -EPERM;
57048 + }
57049 +#endif
57050 + return 0;
57051 +}
57052 +
57053 +int
57054 +gr_handle_chroot_mount(const struct dentry *dentry,
57055 + const struct vfsmount *mnt, const char *dev_name)
57056 +{
57057 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57058 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57059 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57060 + return -EPERM;
57061 + }
57062 +#endif
57063 + return 0;
57064 +}
57065 +
57066 +int
57067 +gr_handle_chroot_pivot(void)
57068 +{
57069 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57070 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57071 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57072 + return -EPERM;
57073 + }
57074 +#endif
57075 + return 0;
57076 +}
57077 +
57078 +int
57079 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57080 +{
57081 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57082 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57083 + !gr_is_outside_chroot(dentry, mnt)) {
57084 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57085 + return -EPERM;
57086 + }
57087 +#endif
57088 + return 0;
57089 +}
57090 +
57091 +extern const char *captab_log[];
57092 +extern int captab_log_entries;
57093 +
57094 +int
57095 +gr_chroot_is_capable(const int cap)
57096 +{
57097 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57098 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
57099 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57100 + if (cap_raised(chroot_caps, cap)) {
57101 + const struct cred *creds = current_cred();
57102 + if (cap_raised(creds->cap_effective, cap) && cap < captab_log_entries) {
57103 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, current, captab_log[cap]);
57104 + }
57105 + return 0;
57106 + }
57107 + }
57108 +#endif
57109 + return 1;
57110 +}
57111 +
57112 +int
57113 +gr_chroot_is_capable_nolog(const int cap)
57114 +{
57115 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57116 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
57117 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57118 + if (cap_raised(chroot_caps, cap)) {
57119 + return 0;
57120 + }
57121 + }
57122 +#endif
57123 + return 1;
57124 +}
57125 +
57126 +int
57127 +gr_handle_chroot_sysctl(const int op)
57128 +{
57129 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57130 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57131 + proc_is_chrooted(current))
57132 + return -EACCES;
57133 +#endif
57134 + return 0;
57135 +}
57136 +
57137 +void
57138 +gr_handle_chroot_chdir(struct path *path)
57139 +{
57140 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57141 + if (grsec_enable_chroot_chdir)
57142 + set_fs_pwd(current->fs, path);
57143 +#endif
57144 + return;
57145 +}
57146 +
57147 +int
57148 +gr_handle_chroot_chmod(const struct dentry *dentry,
57149 + const struct vfsmount *mnt, const int mode)
57150 +{
57151 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57152 + /* allow chmod +s on directories, but not files */
57153 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57154 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57155 + proc_is_chrooted(current)) {
57156 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57157 + return -EPERM;
57158 + }
57159 +#endif
57160 + return 0;
57161 +}
57162 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57163 new file mode 100644
57164 index 0000000..213ad8b
57165 --- /dev/null
57166 +++ b/grsecurity/grsec_disabled.c
57167 @@ -0,0 +1,437 @@
57168 +#include <linux/kernel.h>
57169 +#include <linux/module.h>
57170 +#include <linux/sched.h>
57171 +#include <linux/file.h>
57172 +#include <linux/fs.h>
57173 +#include <linux/kdev_t.h>
57174 +#include <linux/net.h>
57175 +#include <linux/in.h>
57176 +#include <linux/ip.h>
57177 +#include <linux/skbuff.h>
57178 +#include <linux/sysctl.h>
57179 +
57180 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57181 +void
57182 +pax_set_initial_flags(struct linux_binprm *bprm)
57183 +{
57184 + return;
57185 +}
57186 +#endif
57187 +
57188 +#ifdef CONFIG_SYSCTL
57189 +__u32
57190 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57191 +{
57192 + return 0;
57193 +}
57194 +#endif
57195 +
57196 +#ifdef CONFIG_TASKSTATS
57197 +int gr_is_taskstats_denied(int pid)
57198 +{
57199 + return 0;
57200 +}
57201 +#endif
57202 +
57203 +int
57204 +gr_acl_is_enabled(void)
57205 +{
57206 + return 0;
57207 +}
57208 +
57209 +void
57210 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57211 +{
57212 + return;
57213 +}
57214 +
57215 +int
57216 +gr_handle_rawio(const struct inode *inode)
57217 +{
57218 + return 0;
57219 +}
57220 +
57221 +void
57222 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57223 +{
57224 + return;
57225 +}
57226 +
57227 +int
57228 +gr_handle_ptrace(struct task_struct *task, const long request)
57229 +{
57230 + return 0;
57231 +}
57232 +
57233 +int
57234 +gr_handle_proc_ptrace(struct task_struct *task)
57235 +{
57236 + return 0;
57237 +}
57238 +
57239 +void
57240 +gr_learn_resource(const struct task_struct *task,
57241 + const int res, const unsigned long wanted, const int gt)
57242 +{
57243 + return;
57244 +}
57245 +
57246 +int
57247 +gr_set_acls(const int type)
57248 +{
57249 + return 0;
57250 +}
57251 +
57252 +int
57253 +gr_check_hidden_task(const struct task_struct *tsk)
57254 +{
57255 + return 0;
57256 +}
57257 +
57258 +int
57259 +gr_check_protected_task(const struct task_struct *task)
57260 +{
57261 + return 0;
57262 +}
57263 +
57264 +int
57265 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57266 +{
57267 + return 0;
57268 +}
57269 +
57270 +void
57271 +gr_copy_label(struct task_struct *tsk)
57272 +{
57273 + return;
57274 +}
57275 +
57276 +void
57277 +gr_set_pax_flags(struct task_struct *task)
57278 +{
57279 + return;
57280 +}
57281 +
57282 +int
57283 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57284 + const int unsafe_share)
57285 +{
57286 + return 0;
57287 +}
57288 +
57289 +void
57290 +gr_handle_delete(const ino_t ino, const dev_t dev)
57291 +{
57292 + return;
57293 +}
57294 +
57295 +void
57296 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57297 +{
57298 + return;
57299 +}
57300 +
57301 +void
57302 +gr_handle_crash(struct task_struct *task, const int sig)
57303 +{
57304 + return;
57305 +}
57306 +
57307 +int
57308 +gr_check_crash_exec(const struct file *filp)
57309 +{
57310 + return 0;
57311 +}
57312 +
57313 +int
57314 +gr_check_crash_uid(const uid_t uid)
57315 +{
57316 + return 0;
57317 +}
57318 +
57319 +void
57320 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57321 + struct dentry *old_dentry,
57322 + struct dentry *new_dentry,
57323 + struct vfsmount *mnt, const __u8 replace)
57324 +{
57325 + return;
57326 +}
57327 +
57328 +int
57329 +gr_search_socket(const int family, const int type, const int protocol)
57330 +{
57331 + return 1;
57332 +}
57333 +
57334 +int
57335 +gr_search_connectbind(const int mode, const struct socket *sock,
57336 + const struct sockaddr_in *addr)
57337 +{
57338 + return 0;
57339 +}
57340 +
57341 +void
57342 +gr_handle_alertkill(struct task_struct *task)
57343 +{
57344 + return;
57345 +}
57346 +
57347 +__u32
57348 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57349 +{
57350 + return 1;
57351 +}
57352 +
57353 +__u32
57354 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57355 + const struct vfsmount * mnt)
57356 +{
57357 + return 1;
57358 +}
57359 +
57360 +__u32
57361 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57362 + int acc_mode)
57363 +{
57364 + return 1;
57365 +}
57366 +
57367 +__u32
57368 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57369 +{
57370 + return 1;
57371 +}
57372 +
57373 +__u32
57374 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57375 +{
57376 + return 1;
57377 +}
57378 +
57379 +int
57380 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57381 + unsigned int *vm_flags)
57382 +{
57383 + return 1;
57384 +}
57385 +
57386 +__u32
57387 +gr_acl_handle_truncate(const struct dentry * dentry,
57388 + const struct vfsmount * mnt)
57389 +{
57390 + return 1;
57391 +}
57392 +
57393 +__u32
57394 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57395 +{
57396 + return 1;
57397 +}
57398 +
57399 +__u32
57400 +gr_acl_handle_access(const struct dentry * dentry,
57401 + const struct vfsmount * mnt, const int fmode)
57402 +{
57403 + return 1;
57404 +}
57405 +
57406 +__u32
57407 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57408 + umode_t *mode)
57409 +{
57410 + return 1;
57411 +}
57412 +
57413 +__u32
57414 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57415 +{
57416 + return 1;
57417 +}
57418 +
57419 +__u32
57420 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57421 +{
57422 + return 1;
57423 +}
57424 +
57425 +void
57426 +grsecurity_init(void)
57427 +{
57428 + return;
57429 +}
57430 +
57431 +umode_t gr_acl_umask(void)
57432 +{
57433 + return 0;
57434 +}
57435 +
57436 +__u32
57437 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57438 + const struct dentry * parent_dentry,
57439 + const struct vfsmount * parent_mnt,
57440 + const int mode)
57441 +{
57442 + return 1;
57443 +}
57444 +
57445 +__u32
57446 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57447 + const struct dentry * parent_dentry,
57448 + const struct vfsmount * parent_mnt)
57449 +{
57450 + return 1;
57451 +}
57452 +
57453 +__u32
57454 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57455 + const struct dentry * parent_dentry,
57456 + const struct vfsmount * parent_mnt, const char *from)
57457 +{
57458 + return 1;
57459 +}
57460 +
57461 +__u32
57462 +gr_acl_handle_link(const struct dentry * new_dentry,
57463 + const struct dentry * parent_dentry,
57464 + const struct vfsmount * parent_mnt,
57465 + const struct dentry * old_dentry,
57466 + const struct vfsmount * old_mnt, const char *to)
57467 +{
57468 + return 1;
57469 +}
57470 +
57471 +int
57472 +gr_acl_handle_rename(const struct dentry *new_dentry,
57473 + const struct dentry *parent_dentry,
57474 + const struct vfsmount *parent_mnt,
57475 + const struct dentry *old_dentry,
57476 + const struct inode *old_parent_inode,
57477 + const struct vfsmount *old_mnt, const char *newname)
57478 +{
57479 + return 0;
57480 +}
57481 +
57482 +int
57483 +gr_acl_handle_filldir(const struct file *file, const char *name,
57484 + const int namelen, const ino_t ino)
57485 +{
57486 + return 1;
57487 +}
57488 +
57489 +int
57490 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57491 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57492 +{
57493 + return 1;
57494 +}
57495 +
57496 +int
57497 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57498 +{
57499 + return 0;
57500 +}
57501 +
57502 +int
57503 +gr_search_accept(const struct socket *sock)
57504 +{
57505 + return 0;
57506 +}
57507 +
57508 +int
57509 +gr_search_listen(const struct socket *sock)
57510 +{
57511 + return 0;
57512 +}
57513 +
57514 +int
57515 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57516 +{
57517 + return 0;
57518 +}
57519 +
57520 +__u32
57521 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57522 +{
57523 + return 1;
57524 +}
57525 +
57526 +__u32
57527 +gr_acl_handle_creat(const struct dentry * dentry,
57528 + const struct dentry * p_dentry,
57529 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57530 + const int imode)
57531 +{
57532 + return 1;
57533 +}
57534 +
57535 +void
57536 +gr_acl_handle_exit(void)
57537 +{
57538 + return;
57539 +}
57540 +
57541 +int
57542 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57543 +{
57544 + return 1;
57545 +}
57546 +
57547 +void
57548 +gr_set_role_label(const uid_t uid, const gid_t gid)
57549 +{
57550 + return;
57551 +}
57552 +
57553 +int
57554 +gr_acl_handle_procpidmem(const struct task_struct *task)
57555 +{
57556 + return 0;
57557 +}
57558 +
57559 +int
57560 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57561 +{
57562 + return 0;
57563 +}
57564 +
57565 +int
57566 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57567 +{
57568 + return 0;
57569 +}
57570 +
57571 +void
57572 +gr_set_kernel_label(struct task_struct *task)
57573 +{
57574 + return;
57575 +}
57576 +
57577 +int
57578 +gr_check_user_change(int real, int effective, int fs)
57579 +{
57580 + return 0;
57581 +}
57582 +
57583 +int
57584 +gr_check_group_change(int real, int effective, int fs)
57585 +{
57586 + return 0;
57587 +}
57588 +
57589 +int gr_acl_enable_at_secure(void)
57590 +{
57591 + return 0;
57592 +}
57593 +
57594 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57595 +{
57596 + return dentry->d_inode->i_sb->s_dev;
57597 +}
57598 +
57599 +EXPORT_SYMBOL(gr_learn_resource);
57600 +EXPORT_SYMBOL(gr_set_kernel_label);
57601 +#ifdef CONFIG_SECURITY
57602 +EXPORT_SYMBOL(gr_check_user_change);
57603 +EXPORT_SYMBOL(gr_check_group_change);
57604 +#endif
57605 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57606 new file mode 100644
57607 index 0000000..2b05ada
57608 --- /dev/null
57609 +++ b/grsecurity/grsec_exec.c
57610 @@ -0,0 +1,146 @@
57611 +#include <linux/kernel.h>
57612 +#include <linux/sched.h>
57613 +#include <linux/file.h>
57614 +#include <linux/binfmts.h>
57615 +#include <linux/fs.h>
57616 +#include <linux/types.h>
57617 +#include <linux/grdefs.h>
57618 +#include <linux/grsecurity.h>
57619 +#include <linux/grinternal.h>
57620 +#include <linux/capability.h>
57621 +#include <linux/module.h>
57622 +
57623 +#include <asm/uaccess.h>
57624 +
57625 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57626 +static char gr_exec_arg_buf[132];
57627 +static DEFINE_MUTEX(gr_exec_arg_mutex);
57628 +#endif
57629 +
57630 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57631 +
57632 +void
57633 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57634 +{
57635 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57636 + char *grarg = gr_exec_arg_buf;
57637 + unsigned int i, x, execlen = 0;
57638 + char c;
57639 +
57640 + if (!((grsec_enable_execlog && grsec_enable_group &&
57641 + in_group_p(grsec_audit_gid))
57642 + || (grsec_enable_execlog && !grsec_enable_group)))
57643 + return;
57644 +
57645 + mutex_lock(&gr_exec_arg_mutex);
57646 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
57647 +
57648 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
57649 + const char __user *p;
57650 + unsigned int len;
57651 +
57652 + p = get_user_arg_ptr(argv, i);
57653 + if (IS_ERR(p))
57654 + goto log;
57655 +
57656 + len = strnlen_user(p, 128 - execlen);
57657 + if (len > 128 - execlen)
57658 + len = 128 - execlen;
57659 + else if (len > 0)
57660 + len--;
57661 + if (copy_from_user(grarg + execlen, p, len))
57662 + goto log;
57663 +
57664 + /* rewrite unprintable characters */
57665 + for (x = 0; x < len; x++) {
57666 + c = *(grarg + execlen + x);
57667 + if (c < 32 || c > 126)
57668 + *(grarg + execlen + x) = ' ';
57669 + }
57670 +
57671 + execlen += len;
57672 + *(grarg + execlen) = ' ';
57673 + *(grarg + execlen + 1) = '\0';
57674 + execlen++;
57675 + }
57676 +
57677 + log:
57678 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57679 + bprm->file->f_path.mnt, grarg);
57680 + mutex_unlock(&gr_exec_arg_mutex);
57681 +#endif
57682 + return;
57683 +}
57684 +
57685 +#ifdef CONFIG_GRKERNSEC
57686 +extern int gr_acl_is_capable(const int cap);
57687 +extern int gr_acl_is_capable_nolog(const int cap);
57688 +extern int gr_chroot_is_capable(const int cap);
57689 +extern int gr_chroot_is_capable_nolog(const int cap);
57690 +#endif
57691 +
57692 +const char *captab_log[] = {
57693 + "CAP_CHOWN",
57694 + "CAP_DAC_OVERRIDE",
57695 + "CAP_DAC_READ_SEARCH",
57696 + "CAP_FOWNER",
57697 + "CAP_FSETID",
57698 + "CAP_KILL",
57699 + "CAP_SETGID",
57700 + "CAP_SETUID",
57701 + "CAP_SETPCAP",
57702 + "CAP_LINUX_IMMUTABLE",
57703 + "CAP_NET_BIND_SERVICE",
57704 + "CAP_NET_BROADCAST",
57705 + "CAP_NET_ADMIN",
57706 + "CAP_NET_RAW",
57707 + "CAP_IPC_LOCK",
57708 + "CAP_IPC_OWNER",
57709 + "CAP_SYS_MODULE",
57710 + "CAP_SYS_RAWIO",
57711 + "CAP_SYS_CHROOT",
57712 + "CAP_SYS_PTRACE",
57713 + "CAP_SYS_PACCT",
57714 + "CAP_SYS_ADMIN",
57715 + "CAP_SYS_BOOT",
57716 + "CAP_SYS_NICE",
57717 + "CAP_SYS_RESOURCE",
57718 + "CAP_SYS_TIME",
57719 + "CAP_SYS_TTY_CONFIG",
57720 + "CAP_MKNOD",
57721 + "CAP_LEASE",
57722 + "CAP_AUDIT_WRITE",
57723 + "CAP_AUDIT_CONTROL",
57724 + "CAP_SETFCAP",
57725 + "CAP_MAC_OVERRIDE",
57726 + "CAP_MAC_ADMIN",
57727 + "CAP_SYSLOG",
57728 + "CAP_WAKE_ALARM"
57729 +};
57730 +
57731 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57732 +
57733 +int gr_is_capable(const int cap)
57734 +{
57735 +#ifdef CONFIG_GRKERNSEC
57736 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57737 + return 1;
57738 + return 0;
57739 +#else
57740 + return 1;
57741 +#endif
57742 +}
57743 +
57744 +int gr_is_capable_nolog(const int cap)
57745 +{
57746 +#ifdef CONFIG_GRKERNSEC
57747 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57748 + return 1;
57749 + return 0;
57750 +#else
57751 + return 1;
57752 +#endif
57753 +}
57754 +
57755 +EXPORT_SYMBOL(gr_is_capable);
57756 +EXPORT_SYMBOL(gr_is_capable_nolog);
57757 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57758 new file mode 100644
57759 index 0000000..d3ee748
57760 --- /dev/null
57761 +++ b/grsecurity/grsec_fifo.c
57762 @@ -0,0 +1,24 @@
57763 +#include <linux/kernel.h>
57764 +#include <linux/sched.h>
57765 +#include <linux/fs.h>
57766 +#include <linux/file.h>
57767 +#include <linux/grinternal.h>
57768 +
57769 +int
57770 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57771 + const struct dentry *dir, const int flag, const int acc_mode)
57772 +{
57773 +#ifdef CONFIG_GRKERNSEC_FIFO
57774 + const struct cred *cred = current_cred();
57775 +
57776 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57777 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57778 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57779 + (cred->fsuid != dentry->d_inode->i_uid)) {
57780 + if (!inode_permission(dentry->d_inode, acc_mode))
57781 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57782 + return -EACCES;
57783 + }
57784 +#endif
57785 + return 0;
57786 +}
57787 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57788 new file mode 100644
57789 index 0000000..8ca18bf
57790 --- /dev/null
57791 +++ b/grsecurity/grsec_fork.c
57792 @@ -0,0 +1,23 @@
57793 +#include <linux/kernel.h>
57794 +#include <linux/sched.h>
57795 +#include <linux/grsecurity.h>
57796 +#include <linux/grinternal.h>
57797 +#include <linux/errno.h>
57798 +
57799 +void
57800 +gr_log_forkfail(const int retval)
57801 +{
57802 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57803 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57804 + switch (retval) {
57805 + case -EAGAIN:
57806 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57807 + break;
57808 + case -ENOMEM:
57809 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57810 + break;
57811 + }
57812 + }
57813 +#endif
57814 + return;
57815 +}
57816 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57817 new file mode 100644
57818 index 0000000..01ddde4
57819 --- /dev/null
57820 +++ b/grsecurity/grsec_init.c
57821 @@ -0,0 +1,277 @@
57822 +#include <linux/kernel.h>
57823 +#include <linux/sched.h>
57824 +#include <linux/mm.h>
57825 +#include <linux/gracl.h>
57826 +#include <linux/slab.h>
57827 +#include <linux/vmalloc.h>
57828 +#include <linux/percpu.h>
57829 +#include <linux/module.h>
57830 +
57831 +int grsec_enable_ptrace_readexec;
57832 +int grsec_enable_setxid;
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_TPE
58077 + grsec_enable_tpe = 1;
58078 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58079 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58080 + grsec_enable_tpe_all = 1;
58081 +#endif
58082 +#endif
58083 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58084 + grsec_enable_socket_all = 1;
58085 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58086 +#endif
58087 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58088 + grsec_enable_socket_client = 1;
58089 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58090 +#endif
58091 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58092 + grsec_enable_socket_server = 1;
58093 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58094 +#endif
58095 +#endif
58096 +
58097 + return;
58098 +}
58099 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58100 new file mode 100644
58101 index 0000000..3efe141
58102 --- /dev/null
58103 +++ b/grsecurity/grsec_link.c
58104 @@ -0,0 +1,43 @@
58105 +#include <linux/kernel.h>
58106 +#include <linux/sched.h>
58107 +#include <linux/fs.h>
58108 +#include <linux/file.h>
58109 +#include <linux/grinternal.h>
58110 +
58111 +int
58112 +gr_handle_follow_link(const struct inode *parent,
58113 + const struct inode *inode,
58114 + const struct dentry *dentry, const struct vfsmount *mnt)
58115 +{
58116 +#ifdef CONFIG_GRKERNSEC_LINK
58117 + const struct cred *cred = current_cred();
58118 +
58119 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58120 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
58121 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
58122 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58123 + return -EACCES;
58124 + }
58125 +#endif
58126 + return 0;
58127 +}
58128 +
58129 +int
58130 +gr_handle_hardlink(const struct dentry *dentry,
58131 + const struct vfsmount *mnt,
58132 + struct inode *inode, const int mode, const char *to)
58133 +{
58134 +#ifdef CONFIG_GRKERNSEC_LINK
58135 + const struct cred *cred = current_cred();
58136 +
58137 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
58138 + (!S_ISREG(mode) || (mode & S_ISUID) ||
58139 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
58140 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58141 + !capable(CAP_FOWNER) && cred->uid) {
58142 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58143 + return -EPERM;
58144 + }
58145 +#endif
58146 + return 0;
58147 +}
58148 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58149 new file mode 100644
58150 index 0000000..a45d2e9
58151 --- /dev/null
58152 +++ b/grsecurity/grsec_log.c
58153 @@ -0,0 +1,322 @@
58154 +#include <linux/kernel.h>
58155 +#include <linux/sched.h>
58156 +#include <linux/file.h>
58157 +#include <linux/tty.h>
58158 +#include <linux/fs.h>
58159 +#include <linux/grinternal.h>
58160 +
58161 +#ifdef CONFIG_TREE_PREEMPT_RCU
58162 +#define DISABLE_PREEMPT() preempt_disable()
58163 +#define ENABLE_PREEMPT() preempt_enable()
58164 +#else
58165 +#define DISABLE_PREEMPT()
58166 +#define ENABLE_PREEMPT()
58167 +#endif
58168 +
58169 +#define BEGIN_LOCKS(x) \
58170 + DISABLE_PREEMPT(); \
58171 + rcu_read_lock(); \
58172 + read_lock(&tasklist_lock); \
58173 + read_lock(&grsec_exec_file_lock); \
58174 + if (x != GR_DO_AUDIT) \
58175 + spin_lock(&grsec_alert_lock); \
58176 + else \
58177 + spin_lock(&grsec_audit_lock)
58178 +
58179 +#define END_LOCKS(x) \
58180 + if (x != GR_DO_AUDIT) \
58181 + spin_unlock(&grsec_alert_lock); \
58182 + else \
58183 + spin_unlock(&grsec_audit_lock); \
58184 + read_unlock(&grsec_exec_file_lock); \
58185 + read_unlock(&tasklist_lock); \
58186 + rcu_read_unlock(); \
58187 + ENABLE_PREEMPT(); \
58188 + if (x == GR_DONT_AUDIT) \
58189 + gr_handle_alertkill(current)
58190 +
58191 +enum {
58192 + FLOODING,
58193 + NO_FLOODING
58194 +};
58195 +
58196 +extern char *gr_alert_log_fmt;
58197 +extern char *gr_audit_log_fmt;
58198 +extern char *gr_alert_log_buf;
58199 +extern char *gr_audit_log_buf;
58200 +
58201 +static int gr_log_start(int audit)
58202 +{
58203 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58204 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58205 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58206 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58207 + unsigned long curr_secs = get_seconds();
58208 +
58209 + if (audit == GR_DO_AUDIT)
58210 + goto set_fmt;
58211 +
58212 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58213 + grsec_alert_wtime = curr_secs;
58214 + grsec_alert_fyet = 0;
58215 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58216 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58217 + grsec_alert_fyet++;
58218 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58219 + grsec_alert_wtime = curr_secs;
58220 + grsec_alert_fyet++;
58221 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58222 + return FLOODING;
58223 + }
58224 + else return FLOODING;
58225 +
58226 +set_fmt:
58227 +#endif
58228 + memset(buf, 0, PAGE_SIZE);
58229 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58230 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58231 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58232 + } else if (current->signal->curr_ip) {
58233 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58234 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58235 + } else if (gr_acl_is_enabled()) {
58236 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58237 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58238 + } else {
58239 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58240 + strcpy(buf, fmt);
58241 + }
58242 +
58243 + return NO_FLOODING;
58244 +}
58245 +
58246 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58247 + __attribute__ ((format (printf, 2, 0)));
58248 +
58249 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58250 +{
58251 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58252 + unsigned int len = strlen(buf);
58253 +
58254 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58255 +
58256 + return;
58257 +}
58258 +
58259 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58260 + __attribute__ ((format (printf, 2, 3)));
58261 +
58262 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58263 +{
58264 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58265 + unsigned int len = strlen(buf);
58266 + va_list ap;
58267 +
58268 + va_start(ap, msg);
58269 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58270 + va_end(ap);
58271 +
58272 + return;
58273 +}
58274 +
58275 +static void gr_log_end(int audit, int append_default)
58276 +{
58277 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58278 +
58279 + if (append_default) {
58280 + unsigned int len = strlen(buf);
58281 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58282 + }
58283 +
58284 + printk("%s\n", buf);
58285 +
58286 + return;
58287 +}
58288 +
58289 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58290 +{
58291 + int logtype;
58292 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58293 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58294 + void *voidptr = NULL;
58295 + int num1 = 0, num2 = 0;
58296 + unsigned long ulong1 = 0, ulong2 = 0;
58297 + struct dentry *dentry = NULL;
58298 + struct vfsmount *mnt = NULL;
58299 + struct file *file = NULL;
58300 + struct task_struct *task = NULL;
58301 + const struct cred *cred, *pcred;
58302 + va_list ap;
58303 +
58304 + BEGIN_LOCKS(audit);
58305 + logtype = gr_log_start(audit);
58306 + if (logtype == FLOODING) {
58307 + END_LOCKS(audit);
58308 + return;
58309 + }
58310 + va_start(ap, argtypes);
58311 + switch (argtypes) {
58312 + case GR_TTYSNIFF:
58313 + task = va_arg(ap, struct task_struct *);
58314 + 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);
58315 + break;
58316 + case GR_SYSCTL_HIDDEN:
58317 + str1 = va_arg(ap, char *);
58318 + gr_log_middle_varargs(audit, msg, result, str1);
58319 + break;
58320 + case GR_RBAC:
58321 + dentry = va_arg(ap, struct dentry *);
58322 + mnt = va_arg(ap, struct vfsmount *);
58323 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58324 + break;
58325 + case GR_RBAC_STR:
58326 + dentry = va_arg(ap, struct dentry *);
58327 + mnt = va_arg(ap, struct vfsmount *);
58328 + str1 = va_arg(ap, char *);
58329 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58330 + break;
58331 + case GR_STR_RBAC:
58332 + str1 = va_arg(ap, char *);
58333 + dentry = va_arg(ap, struct dentry *);
58334 + mnt = va_arg(ap, struct vfsmount *);
58335 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58336 + break;
58337 + case GR_RBAC_MODE2:
58338 + dentry = va_arg(ap, struct dentry *);
58339 + mnt = va_arg(ap, struct vfsmount *);
58340 + str1 = va_arg(ap, char *);
58341 + str2 = va_arg(ap, char *);
58342 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58343 + break;
58344 + case GR_RBAC_MODE3:
58345 + dentry = va_arg(ap, struct dentry *);
58346 + mnt = va_arg(ap, struct vfsmount *);
58347 + str1 = va_arg(ap, char *);
58348 + str2 = va_arg(ap, char *);
58349 + str3 = va_arg(ap, char *);
58350 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58351 + break;
58352 + case GR_FILENAME:
58353 + dentry = va_arg(ap, struct dentry *);
58354 + mnt = va_arg(ap, struct vfsmount *);
58355 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58356 + break;
58357 + case GR_STR_FILENAME:
58358 + str1 = va_arg(ap, char *);
58359 + dentry = va_arg(ap, struct dentry *);
58360 + mnt = va_arg(ap, struct vfsmount *);
58361 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58362 + break;
58363 + case GR_FILENAME_STR:
58364 + dentry = va_arg(ap, struct dentry *);
58365 + mnt = va_arg(ap, struct vfsmount *);
58366 + str1 = va_arg(ap, char *);
58367 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58368 + break;
58369 + case GR_FILENAME_TWO_INT:
58370 + dentry = va_arg(ap, struct dentry *);
58371 + mnt = va_arg(ap, struct vfsmount *);
58372 + num1 = va_arg(ap, int);
58373 + num2 = va_arg(ap, int);
58374 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58375 + break;
58376 + case GR_FILENAME_TWO_INT_STR:
58377 + dentry = va_arg(ap, struct dentry *);
58378 + mnt = va_arg(ap, struct vfsmount *);
58379 + num1 = va_arg(ap, int);
58380 + num2 = va_arg(ap, int);
58381 + str1 = va_arg(ap, char *);
58382 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58383 + break;
58384 + case GR_TEXTREL:
58385 + file = va_arg(ap, struct file *);
58386 + ulong1 = va_arg(ap, unsigned long);
58387 + ulong2 = va_arg(ap, unsigned long);
58388 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58389 + break;
58390 + case GR_PTRACE:
58391 + task = va_arg(ap, struct task_struct *);
58392 + 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);
58393 + break;
58394 + case GR_RESOURCE:
58395 + task = va_arg(ap, struct task_struct *);
58396 + cred = __task_cred(task);
58397 + pcred = __task_cred(task->real_parent);
58398 + ulong1 = va_arg(ap, unsigned long);
58399 + str1 = va_arg(ap, char *);
58400 + ulong2 = va_arg(ap, unsigned long);
58401 + 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);
58402 + break;
58403 + case GR_CAP:
58404 + task = va_arg(ap, struct task_struct *);
58405 + cred = __task_cred(task);
58406 + pcred = __task_cred(task->real_parent);
58407 + str1 = va_arg(ap, char *);
58408 + 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);
58409 + break;
58410 + case GR_SIG:
58411 + str1 = va_arg(ap, char *);
58412 + voidptr = va_arg(ap, void *);
58413 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58414 + break;
58415 + case GR_SIG2:
58416 + task = va_arg(ap, struct task_struct *);
58417 + cred = __task_cred(task);
58418 + pcred = __task_cred(task->real_parent);
58419 + num1 = va_arg(ap, int);
58420 + 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);
58421 + break;
58422 + case GR_CRASH1:
58423 + task = va_arg(ap, struct task_struct *);
58424 + cred = __task_cred(task);
58425 + pcred = __task_cred(task->real_parent);
58426 + ulong1 = va_arg(ap, unsigned long);
58427 + 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);
58428 + break;
58429 + case GR_CRASH2:
58430 + task = va_arg(ap, struct task_struct *);
58431 + cred = __task_cred(task);
58432 + pcred = __task_cred(task->real_parent);
58433 + ulong1 = va_arg(ap, unsigned long);
58434 + 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);
58435 + break;
58436 + case GR_RWXMAP:
58437 + file = va_arg(ap, struct file *);
58438 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58439 + break;
58440 + case GR_PSACCT:
58441 + {
58442 + unsigned int wday, cday;
58443 + __u8 whr, chr;
58444 + __u8 wmin, cmin;
58445 + __u8 wsec, csec;
58446 + char cur_tty[64] = { 0 };
58447 + char parent_tty[64] = { 0 };
58448 +
58449 + task = va_arg(ap, struct task_struct *);
58450 + wday = va_arg(ap, unsigned int);
58451 + cday = va_arg(ap, unsigned int);
58452 + whr = va_arg(ap, int);
58453 + chr = va_arg(ap, int);
58454 + wmin = va_arg(ap, int);
58455 + cmin = va_arg(ap, int);
58456 + wsec = va_arg(ap, int);
58457 + csec = va_arg(ap, int);
58458 + ulong1 = va_arg(ap, unsigned long);
58459 + cred = __task_cred(task);
58460 + pcred = __task_cred(task->real_parent);
58461 +
58462 + 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);
58463 + }
58464 + break;
58465 + default:
58466 + gr_log_middle(audit, msg, ap);
58467 + }
58468 + va_end(ap);
58469 + // these don't need DEFAULTSECARGS printed on the end
58470 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58471 + gr_log_end(audit, 0);
58472 + else
58473 + gr_log_end(audit, 1);
58474 + END_LOCKS(audit);
58475 +}
58476 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58477 new file mode 100644
58478 index 0000000..f536303
58479 --- /dev/null
58480 +++ b/grsecurity/grsec_mem.c
58481 @@ -0,0 +1,40 @@
58482 +#include <linux/kernel.h>
58483 +#include <linux/sched.h>
58484 +#include <linux/mm.h>
58485 +#include <linux/mman.h>
58486 +#include <linux/grinternal.h>
58487 +
58488 +void
58489 +gr_handle_ioperm(void)
58490 +{
58491 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58492 + return;
58493 +}
58494 +
58495 +void
58496 +gr_handle_iopl(void)
58497 +{
58498 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58499 + return;
58500 +}
58501 +
58502 +void
58503 +gr_handle_mem_readwrite(u64 from, u64 to)
58504 +{
58505 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58506 + return;
58507 +}
58508 +
58509 +void
58510 +gr_handle_vm86(void)
58511 +{
58512 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58513 + return;
58514 +}
58515 +
58516 +void
58517 +gr_log_badprocpid(const char *entry)
58518 +{
58519 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58520 + return;
58521 +}
58522 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58523 new file mode 100644
58524 index 0000000..2131422
58525 --- /dev/null
58526 +++ b/grsecurity/grsec_mount.c
58527 @@ -0,0 +1,62 @@
58528 +#include <linux/kernel.h>
58529 +#include <linux/sched.h>
58530 +#include <linux/mount.h>
58531 +#include <linux/grsecurity.h>
58532 +#include <linux/grinternal.h>
58533 +
58534 +void
58535 +gr_log_remount(const char *devname, const int retval)
58536 +{
58537 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58538 + if (grsec_enable_mount && (retval >= 0))
58539 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58540 +#endif
58541 + return;
58542 +}
58543 +
58544 +void
58545 +gr_log_unmount(const char *devname, const int retval)
58546 +{
58547 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58548 + if (grsec_enable_mount && (retval >= 0))
58549 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58550 +#endif
58551 + return;
58552 +}
58553 +
58554 +void
58555 +gr_log_mount(const char *from, const char *to, const int retval)
58556 +{
58557 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58558 + if (grsec_enable_mount && (retval >= 0))
58559 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58560 +#endif
58561 + return;
58562 +}
58563 +
58564 +int
58565 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58566 +{
58567 +#ifdef CONFIG_GRKERNSEC_ROFS
58568 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58569 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58570 + return -EPERM;
58571 + } else
58572 + return 0;
58573 +#endif
58574 + return 0;
58575 +}
58576 +
58577 +int
58578 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58579 +{
58580 +#ifdef CONFIG_GRKERNSEC_ROFS
58581 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58582 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58583 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58584 + return -EPERM;
58585 + } else
58586 + return 0;
58587 +#endif
58588 + return 0;
58589 +}
58590 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58591 new file mode 100644
58592 index 0000000..a3b12a0
58593 --- /dev/null
58594 +++ b/grsecurity/grsec_pax.c
58595 @@ -0,0 +1,36 @@
58596 +#include <linux/kernel.h>
58597 +#include <linux/sched.h>
58598 +#include <linux/mm.h>
58599 +#include <linux/file.h>
58600 +#include <linux/grinternal.h>
58601 +#include <linux/grsecurity.h>
58602 +
58603 +void
58604 +gr_log_textrel(struct vm_area_struct * vma)
58605 +{
58606 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58607 + if (grsec_enable_audit_textrel)
58608 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58609 +#endif
58610 + return;
58611 +}
58612 +
58613 +void
58614 +gr_log_rwxmmap(struct file *file)
58615 +{
58616 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58617 + if (grsec_enable_log_rwxmaps)
58618 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58619 +#endif
58620 + return;
58621 +}
58622 +
58623 +void
58624 +gr_log_rwxmprotect(struct file *file)
58625 +{
58626 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58627 + if (grsec_enable_log_rwxmaps)
58628 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58629 +#endif
58630 + return;
58631 +}
58632 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58633 new file mode 100644
58634 index 0000000..f7f29aa
58635 --- /dev/null
58636 +++ b/grsecurity/grsec_ptrace.c
58637 @@ -0,0 +1,30 @@
58638 +#include <linux/kernel.h>
58639 +#include <linux/sched.h>
58640 +#include <linux/grinternal.h>
58641 +#include <linux/security.h>
58642 +
58643 +void
58644 +gr_audit_ptrace(struct task_struct *task)
58645 +{
58646 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58647 + if (grsec_enable_audit_ptrace)
58648 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58649 +#endif
58650 + return;
58651 +}
58652 +
58653 +int
58654 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
58655 +{
58656 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58657 + const struct dentry *dentry = file->f_path.dentry;
58658 + const struct vfsmount *mnt = file->f_path.mnt;
58659 +
58660 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58661 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58662 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58663 + return -EACCES;
58664 + }
58665 +#endif
58666 + return 0;
58667 +}
58668 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58669 new file mode 100644
58670 index 0000000..7a5b2de
58671 --- /dev/null
58672 +++ b/grsecurity/grsec_sig.c
58673 @@ -0,0 +1,207 @@
58674 +#include <linux/kernel.h>
58675 +#include <linux/sched.h>
58676 +#include <linux/delay.h>
58677 +#include <linux/grsecurity.h>
58678 +#include <linux/grinternal.h>
58679 +#include <linux/hardirq.h>
58680 +
58681 +char *signames[] = {
58682 + [SIGSEGV] = "Segmentation fault",
58683 + [SIGILL] = "Illegal instruction",
58684 + [SIGABRT] = "Abort",
58685 + [SIGBUS] = "Invalid alignment/Bus error"
58686 +};
58687 +
58688 +void
58689 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58690 +{
58691 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58692 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58693 + (sig == SIGABRT) || (sig == SIGBUS))) {
58694 + if (t->pid == current->pid) {
58695 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58696 + } else {
58697 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58698 + }
58699 + }
58700 +#endif
58701 + return;
58702 +}
58703 +
58704 +int
58705 +gr_handle_signal(const struct task_struct *p, const int sig)
58706 +{
58707 +#ifdef CONFIG_GRKERNSEC
58708 + /* ignore the 0 signal for protected task checks */
58709 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58710 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58711 + return -EPERM;
58712 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58713 + return -EPERM;
58714 + }
58715 +#endif
58716 + return 0;
58717 +}
58718 +
58719 +#ifdef CONFIG_GRKERNSEC
58720 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58721 +
58722 +int gr_fake_force_sig(int sig, struct task_struct *t)
58723 +{
58724 + unsigned long int flags;
58725 + int ret, blocked, ignored;
58726 + struct k_sigaction *action;
58727 +
58728 + spin_lock_irqsave(&t->sighand->siglock, flags);
58729 + action = &t->sighand->action[sig-1];
58730 + ignored = action->sa.sa_handler == SIG_IGN;
58731 + blocked = sigismember(&t->blocked, sig);
58732 + if (blocked || ignored) {
58733 + action->sa.sa_handler = SIG_DFL;
58734 + if (blocked) {
58735 + sigdelset(&t->blocked, sig);
58736 + recalc_sigpending_and_wake(t);
58737 + }
58738 + }
58739 + if (action->sa.sa_handler == SIG_DFL)
58740 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
58741 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58742 +
58743 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
58744 +
58745 + return ret;
58746 +}
58747 +#endif
58748 +
58749 +#ifdef CONFIG_GRKERNSEC_BRUTE
58750 +#define GR_USER_BAN_TIME (15 * 60)
58751 +
58752 +static int __get_dumpable(unsigned long mm_flags)
58753 +{
58754 + int ret;
58755 +
58756 + ret = mm_flags & MMF_DUMPABLE_MASK;
58757 + return (ret >= 2) ? 2 : ret;
58758 +}
58759 +#endif
58760 +
58761 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58762 +{
58763 +#ifdef CONFIG_GRKERNSEC_BRUTE
58764 + uid_t uid = 0;
58765 +
58766 + if (!grsec_enable_brute)
58767 + return;
58768 +
58769 + rcu_read_lock();
58770 + read_lock(&tasklist_lock);
58771 + read_lock(&grsec_exec_file_lock);
58772 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58773 + p->real_parent->brute = 1;
58774 + else {
58775 + const struct cred *cred = __task_cred(p), *cred2;
58776 + struct task_struct *tsk, *tsk2;
58777 +
58778 + if (!__get_dumpable(mm_flags) && cred->uid) {
58779 + struct user_struct *user;
58780 +
58781 + uid = cred->uid;
58782 +
58783 + /* this is put upon execution past expiration */
58784 + user = find_user(uid);
58785 + if (user == NULL)
58786 + goto unlock;
58787 + user->banned = 1;
58788 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58789 + if (user->ban_expires == ~0UL)
58790 + user->ban_expires--;
58791 +
58792 + do_each_thread(tsk2, tsk) {
58793 + cred2 = __task_cred(tsk);
58794 + if (tsk != p && cred2->uid == uid)
58795 + gr_fake_force_sig(SIGKILL, tsk);
58796 + } while_each_thread(tsk2, tsk);
58797 + }
58798 + }
58799 +unlock:
58800 + read_unlock(&grsec_exec_file_lock);
58801 + read_unlock(&tasklist_lock);
58802 + rcu_read_unlock();
58803 +
58804 + if (uid)
58805 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
58806 +
58807 +#endif
58808 + return;
58809 +}
58810 +
58811 +void gr_handle_brute_check(void)
58812 +{
58813 +#ifdef CONFIG_GRKERNSEC_BRUTE
58814 + if (current->brute)
58815 + msleep(30 * 1000);
58816 +#endif
58817 + return;
58818 +}
58819 +
58820 +void gr_handle_kernel_exploit(void)
58821 +{
58822 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58823 + const struct cred *cred;
58824 + struct task_struct *tsk, *tsk2;
58825 + struct user_struct *user;
58826 + uid_t uid;
58827 +
58828 + if (in_irq() || in_serving_softirq() || in_nmi())
58829 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58830 +
58831 + uid = current_uid();
58832 +
58833 + if (uid == 0)
58834 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
58835 + else {
58836 + /* kill all the processes of this user, hold a reference
58837 + to their creds struct, and prevent them from creating
58838 + another process until system reset
58839 + */
58840 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
58841 + /* we intentionally leak this ref */
58842 + user = get_uid(current->cred->user);
58843 + if (user) {
58844 + user->banned = 1;
58845 + user->ban_expires = ~0UL;
58846 + }
58847 +
58848 + read_lock(&tasklist_lock);
58849 + do_each_thread(tsk2, tsk) {
58850 + cred = __task_cred(tsk);
58851 + if (cred->uid == uid)
58852 + gr_fake_force_sig(SIGKILL, tsk);
58853 + } while_each_thread(tsk2, tsk);
58854 + read_unlock(&tasklist_lock);
58855 + }
58856 +#endif
58857 +}
58858 +
58859 +int __gr_process_user_ban(struct user_struct *user)
58860 +{
58861 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58862 + if (unlikely(user->banned)) {
58863 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58864 + user->banned = 0;
58865 + user->ban_expires = 0;
58866 + free_uid(user);
58867 + } else
58868 + return -EPERM;
58869 + }
58870 +#endif
58871 + return 0;
58872 +}
58873 +
58874 +int gr_process_user_ban(void)
58875 +{
58876 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58877 + return __gr_process_user_ban(current->cred->user);
58878 +#endif
58879 + return 0;
58880 +}
58881 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58882 new file mode 100644
58883 index 0000000..4030d57
58884 --- /dev/null
58885 +++ b/grsecurity/grsec_sock.c
58886 @@ -0,0 +1,244 @@
58887 +#include <linux/kernel.h>
58888 +#include <linux/module.h>
58889 +#include <linux/sched.h>
58890 +#include <linux/file.h>
58891 +#include <linux/net.h>
58892 +#include <linux/in.h>
58893 +#include <linux/ip.h>
58894 +#include <net/sock.h>
58895 +#include <net/inet_sock.h>
58896 +#include <linux/grsecurity.h>
58897 +#include <linux/grinternal.h>
58898 +#include <linux/gracl.h>
58899 +
58900 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58901 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58902 +
58903 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
58904 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
58905 +
58906 +#ifdef CONFIG_UNIX_MODULE
58907 +EXPORT_SYMBOL(gr_acl_handle_unix);
58908 +EXPORT_SYMBOL(gr_acl_handle_mknod);
58909 +EXPORT_SYMBOL(gr_handle_chroot_unix);
58910 +EXPORT_SYMBOL(gr_handle_create);
58911 +#endif
58912 +
58913 +#ifdef CONFIG_GRKERNSEC
58914 +#define gr_conn_table_size 32749
58915 +struct conn_table_entry {
58916 + struct conn_table_entry *next;
58917 + struct signal_struct *sig;
58918 +};
58919 +
58920 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58921 +DEFINE_SPINLOCK(gr_conn_table_lock);
58922 +
58923 +extern const char * gr_socktype_to_name(unsigned char type);
58924 +extern const char * gr_proto_to_name(unsigned char proto);
58925 +extern const char * gr_sockfamily_to_name(unsigned char family);
58926 +
58927 +static __inline__ int
58928 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58929 +{
58930 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58931 +}
58932 +
58933 +static __inline__ int
58934 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58935 + __u16 sport, __u16 dport)
58936 +{
58937 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58938 + sig->gr_sport == sport && sig->gr_dport == dport))
58939 + return 1;
58940 + else
58941 + return 0;
58942 +}
58943 +
58944 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58945 +{
58946 + struct conn_table_entry **match;
58947 + unsigned int index;
58948 +
58949 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58950 + sig->gr_sport, sig->gr_dport,
58951 + gr_conn_table_size);
58952 +
58953 + newent->sig = sig;
58954 +
58955 + match = &gr_conn_table[index];
58956 + newent->next = *match;
58957 + *match = newent;
58958 +
58959 + return;
58960 +}
58961 +
58962 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58963 +{
58964 + struct conn_table_entry *match, *last = NULL;
58965 + unsigned int index;
58966 +
58967 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58968 + sig->gr_sport, sig->gr_dport,
58969 + gr_conn_table_size);
58970 +
58971 + match = gr_conn_table[index];
58972 + while (match && !conn_match(match->sig,
58973 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58974 + sig->gr_dport)) {
58975 + last = match;
58976 + match = match->next;
58977 + }
58978 +
58979 + if (match) {
58980 + if (last)
58981 + last->next = match->next;
58982 + else
58983 + gr_conn_table[index] = NULL;
58984 + kfree(match);
58985 + }
58986 +
58987 + return;
58988 +}
58989 +
58990 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
58991 + __u16 sport, __u16 dport)
58992 +{
58993 + struct conn_table_entry *match;
58994 + unsigned int index;
58995 +
58996 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
58997 +
58998 + match = gr_conn_table[index];
58999 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59000 + match = match->next;
59001 +
59002 + if (match)
59003 + return match->sig;
59004 + else
59005 + return NULL;
59006 +}
59007 +
59008 +#endif
59009 +
59010 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59011 +{
59012 +#ifdef CONFIG_GRKERNSEC
59013 + struct signal_struct *sig = task->signal;
59014 + struct conn_table_entry *newent;
59015 +
59016 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59017 + if (newent == NULL)
59018 + return;
59019 + /* no bh lock needed since we are called with bh disabled */
59020 + spin_lock(&gr_conn_table_lock);
59021 + gr_del_task_from_ip_table_nolock(sig);
59022 + sig->gr_saddr = inet->inet_rcv_saddr;
59023 + sig->gr_daddr = inet->inet_daddr;
59024 + sig->gr_sport = inet->inet_sport;
59025 + sig->gr_dport = inet->inet_dport;
59026 + gr_add_to_task_ip_table_nolock(sig, newent);
59027 + spin_unlock(&gr_conn_table_lock);
59028 +#endif
59029 + return;
59030 +}
59031 +
59032 +void gr_del_task_from_ip_table(struct task_struct *task)
59033 +{
59034 +#ifdef CONFIG_GRKERNSEC
59035 + spin_lock_bh(&gr_conn_table_lock);
59036 + gr_del_task_from_ip_table_nolock(task->signal);
59037 + spin_unlock_bh(&gr_conn_table_lock);
59038 +#endif
59039 + return;
59040 +}
59041 +
59042 +void
59043 +gr_attach_curr_ip(const struct sock *sk)
59044 +{
59045 +#ifdef CONFIG_GRKERNSEC
59046 + struct signal_struct *p, *set;
59047 + const struct inet_sock *inet = inet_sk(sk);
59048 +
59049 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59050 + return;
59051 +
59052 + set = current->signal;
59053 +
59054 + spin_lock_bh(&gr_conn_table_lock);
59055 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59056 + inet->inet_dport, inet->inet_sport);
59057 + if (unlikely(p != NULL)) {
59058 + set->curr_ip = p->curr_ip;
59059 + set->used_accept = 1;
59060 + gr_del_task_from_ip_table_nolock(p);
59061 + spin_unlock_bh(&gr_conn_table_lock);
59062 + return;
59063 + }
59064 + spin_unlock_bh(&gr_conn_table_lock);
59065 +
59066 + set->curr_ip = inet->inet_daddr;
59067 + set->used_accept = 1;
59068 +#endif
59069 + return;
59070 +}
59071 +
59072 +int
59073 +gr_handle_sock_all(const int family, const int type, const int protocol)
59074 +{
59075 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59076 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59077 + (family != AF_UNIX)) {
59078 + if (family == AF_INET)
59079 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59080 + else
59081 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59082 + return -EACCES;
59083 + }
59084 +#endif
59085 + return 0;
59086 +}
59087 +
59088 +int
59089 +gr_handle_sock_server(const struct sockaddr *sck)
59090 +{
59091 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59092 + if (grsec_enable_socket_server &&
59093 + in_group_p(grsec_socket_server_gid) &&
59094 + sck && (sck->sa_family != AF_UNIX) &&
59095 + (sck->sa_family != AF_LOCAL)) {
59096 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59097 + return -EACCES;
59098 + }
59099 +#endif
59100 + return 0;
59101 +}
59102 +
59103 +int
59104 +gr_handle_sock_server_other(const struct sock *sck)
59105 +{
59106 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59107 + if (grsec_enable_socket_server &&
59108 + in_group_p(grsec_socket_server_gid) &&
59109 + sck && (sck->sk_family != AF_UNIX) &&
59110 + (sck->sk_family != AF_LOCAL)) {
59111 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59112 + return -EACCES;
59113 + }
59114 +#endif
59115 + return 0;
59116 +}
59117 +
59118 +int
59119 +gr_handle_sock_client(const struct sockaddr *sck)
59120 +{
59121 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59122 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59123 + sck && (sck->sa_family != AF_UNIX) &&
59124 + (sck->sa_family != AF_LOCAL)) {
59125 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59126 + return -EACCES;
59127 + }
59128 +#endif
59129 + return 0;
59130 +}
59131 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59132 new file mode 100644
59133 index 0000000..a1aedd7
59134 --- /dev/null
59135 +++ b/grsecurity/grsec_sysctl.c
59136 @@ -0,0 +1,451 @@
59137 +#include <linux/kernel.h>
59138 +#include <linux/sched.h>
59139 +#include <linux/sysctl.h>
59140 +#include <linux/grsecurity.h>
59141 +#include <linux/grinternal.h>
59142 +
59143 +int
59144 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59145 +{
59146 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59147 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59148 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59149 + return -EACCES;
59150 + }
59151 +#endif
59152 + return 0;
59153 +}
59154 +
59155 +#ifdef CONFIG_GRKERNSEC_ROFS
59156 +static int __maybe_unused one = 1;
59157 +#endif
59158 +
59159 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59160 +struct ctl_table grsecurity_table[] = {
59161 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59162 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59163 +#ifdef CONFIG_GRKERNSEC_IO
59164 + {
59165 + .procname = "disable_priv_io",
59166 + .data = &grsec_disable_privio,
59167 + .maxlen = sizeof(int),
59168 + .mode = 0600,
59169 + .proc_handler = &proc_dointvec,
59170 + },
59171 +#endif
59172 +#endif
59173 +#ifdef CONFIG_GRKERNSEC_LINK
59174 + {
59175 + .procname = "linking_restrictions",
59176 + .data = &grsec_enable_link,
59177 + .maxlen = sizeof(int),
59178 + .mode = 0600,
59179 + .proc_handler = &proc_dointvec,
59180 + },
59181 +#endif
59182 +#ifdef CONFIG_GRKERNSEC_BRUTE
59183 + {
59184 + .procname = "deter_bruteforce",
59185 + .data = &grsec_enable_brute,
59186 + .maxlen = sizeof(int),
59187 + .mode = 0600,
59188 + .proc_handler = &proc_dointvec,
59189 + },
59190 +#endif
59191 +#ifdef CONFIG_GRKERNSEC_FIFO
59192 + {
59193 + .procname = "fifo_restrictions",
59194 + .data = &grsec_enable_fifo,
59195 + .maxlen = sizeof(int),
59196 + .mode = 0600,
59197 + .proc_handler = &proc_dointvec,
59198 + },
59199 +#endif
59200 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59201 + {
59202 + .procname = "ptrace_readexec",
59203 + .data = &grsec_enable_ptrace_readexec,
59204 + .maxlen = sizeof(int),
59205 + .mode = 0600,
59206 + .proc_handler = &proc_dointvec,
59207 + },
59208 +#endif
59209 +#ifdef CONFIG_GRKERNSEC_SETXID
59210 + {
59211 + .procname = "consistent_setxid",
59212 + .data = &grsec_enable_setxid,
59213 + .maxlen = sizeof(int),
59214 + .mode = 0600,
59215 + .proc_handler = &proc_dointvec,
59216 + },
59217 +#endif
59218 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59219 + {
59220 + .procname = "ip_blackhole",
59221 + .data = &grsec_enable_blackhole,
59222 + .maxlen = sizeof(int),
59223 + .mode = 0600,
59224 + .proc_handler = &proc_dointvec,
59225 + },
59226 + {
59227 + .procname = "lastack_retries",
59228 + .data = &grsec_lastack_retries,
59229 + .maxlen = sizeof(int),
59230 + .mode = 0600,
59231 + .proc_handler = &proc_dointvec,
59232 + },
59233 +#endif
59234 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59235 + {
59236 + .procname = "exec_logging",
59237 + .data = &grsec_enable_execlog,
59238 + .maxlen = sizeof(int),
59239 + .mode = 0600,
59240 + .proc_handler = &proc_dointvec,
59241 + },
59242 +#endif
59243 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59244 + {
59245 + .procname = "rwxmap_logging",
59246 + .data = &grsec_enable_log_rwxmaps,
59247 + .maxlen = sizeof(int),
59248 + .mode = 0600,
59249 + .proc_handler = &proc_dointvec,
59250 + },
59251 +#endif
59252 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59253 + {
59254 + .procname = "signal_logging",
59255 + .data = &grsec_enable_signal,
59256 + .maxlen = sizeof(int),
59257 + .mode = 0600,
59258 + .proc_handler = &proc_dointvec,
59259 + },
59260 +#endif
59261 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59262 + {
59263 + .procname = "forkfail_logging",
59264 + .data = &grsec_enable_forkfail,
59265 + .maxlen = sizeof(int),
59266 + .mode = 0600,
59267 + .proc_handler = &proc_dointvec,
59268 + },
59269 +#endif
59270 +#ifdef CONFIG_GRKERNSEC_TIME
59271 + {
59272 + .procname = "timechange_logging",
59273 + .data = &grsec_enable_time,
59274 + .maxlen = sizeof(int),
59275 + .mode = 0600,
59276 + .proc_handler = &proc_dointvec,
59277 + },
59278 +#endif
59279 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59280 + {
59281 + .procname = "chroot_deny_shmat",
59282 + .data = &grsec_enable_chroot_shmat,
59283 + .maxlen = sizeof(int),
59284 + .mode = 0600,
59285 + .proc_handler = &proc_dointvec,
59286 + },
59287 +#endif
59288 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59289 + {
59290 + .procname = "chroot_deny_unix",
59291 + .data = &grsec_enable_chroot_unix,
59292 + .maxlen = sizeof(int),
59293 + .mode = 0600,
59294 + .proc_handler = &proc_dointvec,
59295 + },
59296 +#endif
59297 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59298 + {
59299 + .procname = "chroot_deny_mount",
59300 + .data = &grsec_enable_chroot_mount,
59301 + .maxlen = sizeof(int),
59302 + .mode = 0600,
59303 + .proc_handler = &proc_dointvec,
59304 + },
59305 +#endif
59306 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59307 + {
59308 + .procname = "chroot_deny_fchdir",
59309 + .data = &grsec_enable_chroot_fchdir,
59310 + .maxlen = sizeof(int),
59311 + .mode = 0600,
59312 + .proc_handler = &proc_dointvec,
59313 + },
59314 +#endif
59315 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59316 + {
59317 + .procname = "chroot_deny_chroot",
59318 + .data = &grsec_enable_chroot_double,
59319 + .maxlen = sizeof(int),
59320 + .mode = 0600,
59321 + .proc_handler = &proc_dointvec,
59322 + },
59323 +#endif
59324 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59325 + {
59326 + .procname = "chroot_deny_pivot",
59327 + .data = &grsec_enable_chroot_pivot,
59328 + .maxlen = sizeof(int),
59329 + .mode = 0600,
59330 + .proc_handler = &proc_dointvec,
59331 + },
59332 +#endif
59333 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59334 + {
59335 + .procname = "chroot_enforce_chdir",
59336 + .data = &grsec_enable_chroot_chdir,
59337 + .maxlen = sizeof(int),
59338 + .mode = 0600,
59339 + .proc_handler = &proc_dointvec,
59340 + },
59341 +#endif
59342 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59343 + {
59344 + .procname = "chroot_deny_chmod",
59345 + .data = &grsec_enable_chroot_chmod,
59346 + .maxlen = sizeof(int),
59347 + .mode = 0600,
59348 + .proc_handler = &proc_dointvec,
59349 + },
59350 +#endif
59351 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59352 + {
59353 + .procname = "chroot_deny_mknod",
59354 + .data = &grsec_enable_chroot_mknod,
59355 + .maxlen = sizeof(int),
59356 + .mode = 0600,
59357 + .proc_handler = &proc_dointvec,
59358 + },
59359 +#endif
59360 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59361 + {
59362 + .procname = "chroot_restrict_nice",
59363 + .data = &grsec_enable_chroot_nice,
59364 + .maxlen = sizeof(int),
59365 + .mode = 0600,
59366 + .proc_handler = &proc_dointvec,
59367 + },
59368 +#endif
59369 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59370 + {
59371 + .procname = "chroot_execlog",
59372 + .data = &grsec_enable_chroot_execlog,
59373 + .maxlen = sizeof(int),
59374 + .mode = 0600,
59375 + .proc_handler = &proc_dointvec,
59376 + },
59377 +#endif
59378 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59379 + {
59380 + .procname = "chroot_caps",
59381 + .data = &grsec_enable_chroot_caps,
59382 + .maxlen = sizeof(int),
59383 + .mode = 0600,
59384 + .proc_handler = &proc_dointvec,
59385 + },
59386 +#endif
59387 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59388 + {
59389 + .procname = "chroot_deny_sysctl",
59390 + .data = &grsec_enable_chroot_sysctl,
59391 + .maxlen = sizeof(int),
59392 + .mode = 0600,
59393 + .proc_handler = &proc_dointvec,
59394 + },
59395 +#endif
59396 +#ifdef CONFIG_GRKERNSEC_TPE
59397 + {
59398 + .procname = "tpe",
59399 + .data = &grsec_enable_tpe,
59400 + .maxlen = sizeof(int),
59401 + .mode = 0600,
59402 + .proc_handler = &proc_dointvec,
59403 + },
59404 + {
59405 + .procname = "tpe_gid",
59406 + .data = &grsec_tpe_gid,
59407 + .maxlen = sizeof(int),
59408 + .mode = 0600,
59409 + .proc_handler = &proc_dointvec,
59410 + },
59411 +#endif
59412 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59413 + {
59414 + .procname = "tpe_invert",
59415 + .data = &grsec_enable_tpe_invert,
59416 + .maxlen = sizeof(int),
59417 + .mode = 0600,
59418 + .proc_handler = &proc_dointvec,
59419 + },
59420 +#endif
59421 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59422 + {
59423 + .procname = "tpe_restrict_all",
59424 + .data = &grsec_enable_tpe_all,
59425 + .maxlen = sizeof(int),
59426 + .mode = 0600,
59427 + .proc_handler = &proc_dointvec,
59428 + },
59429 +#endif
59430 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59431 + {
59432 + .procname = "socket_all",
59433 + .data = &grsec_enable_socket_all,
59434 + .maxlen = sizeof(int),
59435 + .mode = 0600,
59436 + .proc_handler = &proc_dointvec,
59437 + },
59438 + {
59439 + .procname = "socket_all_gid",
59440 + .data = &grsec_socket_all_gid,
59441 + .maxlen = sizeof(int),
59442 + .mode = 0600,
59443 + .proc_handler = &proc_dointvec,
59444 + },
59445 +#endif
59446 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59447 + {
59448 + .procname = "socket_client",
59449 + .data = &grsec_enable_socket_client,
59450 + .maxlen = sizeof(int),
59451 + .mode = 0600,
59452 + .proc_handler = &proc_dointvec,
59453 + },
59454 + {
59455 + .procname = "socket_client_gid",
59456 + .data = &grsec_socket_client_gid,
59457 + .maxlen = sizeof(int),
59458 + .mode = 0600,
59459 + .proc_handler = &proc_dointvec,
59460 + },
59461 +#endif
59462 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59463 + {
59464 + .procname = "socket_server",
59465 + .data = &grsec_enable_socket_server,
59466 + .maxlen = sizeof(int),
59467 + .mode = 0600,
59468 + .proc_handler = &proc_dointvec,
59469 + },
59470 + {
59471 + .procname = "socket_server_gid",
59472 + .data = &grsec_socket_server_gid,
59473 + .maxlen = sizeof(int),
59474 + .mode = 0600,
59475 + .proc_handler = &proc_dointvec,
59476 + },
59477 +#endif
59478 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59479 + {
59480 + .procname = "audit_group",
59481 + .data = &grsec_enable_group,
59482 + .maxlen = sizeof(int),
59483 + .mode = 0600,
59484 + .proc_handler = &proc_dointvec,
59485 + },
59486 + {
59487 + .procname = "audit_gid",
59488 + .data = &grsec_audit_gid,
59489 + .maxlen = sizeof(int),
59490 + .mode = 0600,
59491 + .proc_handler = &proc_dointvec,
59492 + },
59493 +#endif
59494 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59495 + {
59496 + .procname = "audit_chdir",
59497 + .data = &grsec_enable_chdir,
59498 + .maxlen = sizeof(int),
59499 + .mode = 0600,
59500 + .proc_handler = &proc_dointvec,
59501 + },
59502 +#endif
59503 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59504 + {
59505 + .procname = "audit_mount",
59506 + .data = &grsec_enable_mount,
59507 + .maxlen = sizeof(int),
59508 + .mode = 0600,
59509 + .proc_handler = &proc_dointvec,
59510 + },
59511 +#endif
59512 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59513 + {
59514 + .procname = "audit_textrel",
59515 + .data = &grsec_enable_audit_textrel,
59516 + .maxlen = sizeof(int),
59517 + .mode = 0600,
59518 + .proc_handler = &proc_dointvec,
59519 + },
59520 +#endif
59521 +#ifdef CONFIG_GRKERNSEC_DMESG
59522 + {
59523 + .procname = "dmesg",
59524 + .data = &grsec_enable_dmesg,
59525 + .maxlen = sizeof(int),
59526 + .mode = 0600,
59527 + .proc_handler = &proc_dointvec,
59528 + },
59529 +#endif
59530 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59531 + {
59532 + .procname = "chroot_findtask",
59533 + .data = &grsec_enable_chroot_findtask,
59534 + .maxlen = sizeof(int),
59535 + .mode = 0600,
59536 + .proc_handler = &proc_dointvec,
59537 + },
59538 +#endif
59539 +#ifdef CONFIG_GRKERNSEC_RESLOG
59540 + {
59541 + .procname = "resource_logging",
59542 + .data = &grsec_resource_logging,
59543 + .maxlen = sizeof(int),
59544 + .mode = 0600,
59545 + .proc_handler = &proc_dointvec,
59546 + },
59547 +#endif
59548 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59549 + {
59550 + .procname = "audit_ptrace",
59551 + .data = &grsec_enable_audit_ptrace,
59552 + .maxlen = sizeof(int),
59553 + .mode = 0600,
59554 + .proc_handler = &proc_dointvec,
59555 + },
59556 +#endif
59557 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59558 + {
59559 + .procname = "harden_ptrace",
59560 + .data = &grsec_enable_harden_ptrace,
59561 + .maxlen = sizeof(int),
59562 + .mode = 0600,
59563 + .proc_handler = &proc_dointvec,
59564 + },
59565 +#endif
59566 + {
59567 + .procname = "grsec_lock",
59568 + .data = &grsec_lock,
59569 + .maxlen = sizeof(int),
59570 + .mode = 0600,
59571 + .proc_handler = &proc_dointvec,
59572 + },
59573 +#endif
59574 +#ifdef CONFIG_GRKERNSEC_ROFS
59575 + {
59576 + .procname = "romount_protect",
59577 + .data = &grsec_enable_rofs,
59578 + .maxlen = sizeof(int),
59579 + .mode = 0600,
59580 + .proc_handler = &proc_dointvec_minmax,
59581 + .extra1 = &one,
59582 + .extra2 = &one,
59583 + },
59584 +#endif
59585 + { }
59586 +};
59587 +#endif
59588 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59589 new file mode 100644
59590 index 0000000..0dc13c3
59591 --- /dev/null
59592 +++ b/grsecurity/grsec_time.c
59593 @@ -0,0 +1,16 @@
59594 +#include <linux/kernel.h>
59595 +#include <linux/sched.h>
59596 +#include <linux/grinternal.h>
59597 +#include <linux/module.h>
59598 +
59599 +void
59600 +gr_log_timechange(void)
59601 +{
59602 +#ifdef CONFIG_GRKERNSEC_TIME
59603 + if (grsec_enable_time)
59604 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59605 +#endif
59606 + return;
59607 +}
59608 +
59609 +EXPORT_SYMBOL(gr_log_timechange);
59610 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59611 new file mode 100644
59612 index 0000000..07e0dc0
59613 --- /dev/null
59614 +++ b/grsecurity/grsec_tpe.c
59615 @@ -0,0 +1,73 @@
59616 +#include <linux/kernel.h>
59617 +#include <linux/sched.h>
59618 +#include <linux/file.h>
59619 +#include <linux/fs.h>
59620 +#include <linux/grinternal.h>
59621 +
59622 +extern int gr_acl_tpe_check(void);
59623 +
59624 +int
59625 +gr_tpe_allow(const struct file *file)
59626 +{
59627 +#ifdef CONFIG_GRKERNSEC
59628 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59629 + const struct cred *cred = current_cred();
59630 + char *msg = NULL;
59631 + char *msg2 = NULL;
59632 +
59633 + // never restrict root
59634 + if (!cred->uid)
59635 + return 1;
59636 +
59637 + if (grsec_enable_tpe) {
59638 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59639 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59640 + msg = "not being in trusted group";
59641 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59642 + msg = "being in untrusted group";
59643 +#else
59644 + if (in_group_p(grsec_tpe_gid))
59645 + msg = "being in untrusted group";
59646 +#endif
59647 + }
59648 + if (!msg && gr_acl_tpe_check())
59649 + msg = "being in untrusted role";
59650 +
59651 + // not in any affected group/role
59652 + if (!msg)
59653 + goto next_check;
59654 +
59655 + if (inode->i_uid)
59656 + msg2 = "file in non-root-owned directory";
59657 + else if (inode->i_mode & S_IWOTH)
59658 + msg2 = "file in world-writable directory";
59659 + else if (inode->i_mode & S_IWGRP)
59660 + msg2 = "file in group-writable directory";
59661 +
59662 + if (msg && msg2) {
59663 + char fullmsg[70] = {0};
59664 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59665 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59666 + return 0;
59667 + }
59668 + msg = NULL;
59669 +next_check:
59670 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59671 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59672 + return 1;
59673 +
59674 + if (inode->i_uid && (inode->i_uid != cred->uid))
59675 + msg = "directory not owned by user";
59676 + else if (inode->i_mode & S_IWOTH)
59677 + msg = "file in world-writable directory";
59678 + else if (inode->i_mode & S_IWGRP)
59679 + msg = "file in group-writable directory";
59680 +
59681 + if (msg) {
59682 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59683 + return 0;
59684 + }
59685 +#endif
59686 +#endif
59687 + return 1;
59688 +}
59689 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59690 new file mode 100644
59691 index 0000000..9f7b1ac
59692 --- /dev/null
59693 +++ b/grsecurity/grsum.c
59694 @@ -0,0 +1,61 @@
59695 +#include <linux/err.h>
59696 +#include <linux/kernel.h>
59697 +#include <linux/sched.h>
59698 +#include <linux/mm.h>
59699 +#include <linux/scatterlist.h>
59700 +#include <linux/crypto.h>
59701 +#include <linux/gracl.h>
59702 +
59703 +
59704 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59705 +#error "crypto and sha256 must be built into the kernel"
59706 +#endif
59707 +
59708 +int
59709 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59710 +{
59711 + char *p;
59712 + struct crypto_hash *tfm;
59713 + struct hash_desc desc;
59714 + struct scatterlist sg;
59715 + unsigned char temp_sum[GR_SHA_LEN];
59716 + volatile int retval = 0;
59717 + volatile int dummy = 0;
59718 + unsigned int i;
59719 +
59720 + sg_init_table(&sg, 1);
59721 +
59722 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59723 + if (IS_ERR(tfm)) {
59724 + /* should never happen, since sha256 should be built in */
59725 + return 1;
59726 + }
59727 +
59728 + desc.tfm = tfm;
59729 + desc.flags = 0;
59730 +
59731 + crypto_hash_init(&desc);
59732 +
59733 + p = salt;
59734 + sg_set_buf(&sg, p, GR_SALT_LEN);
59735 + crypto_hash_update(&desc, &sg, sg.length);
59736 +
59737 + p = entry->pw;
59738 + sg_set_buf(&sg, p, strlen(p));
59739 +
59740 + crypto_hash_update(&desc, &sg, sg.length);
59741 +
59742 + crypto_hash_final(&desc, temp_sum);
59743 +
59744 + memset(entry->pw, 0, GR_PW_LEN);
59745 +
59746 + for (i = 0; i < GR_SHA_LEN; i++)
59747 + if (sum[i] != temp_sum[i])
59748 + retval = 1;
59749 + else
59750 + dummy = 1; // waste a cycle
59751 +
59752 + crypto_free_hash(tfm);
59753 +
59754 + return retval;
59755 +}
59756 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59757 index 6cd5b64..f620d2d 100644
59758 --- a/include/acpi/acpi_bus.h
59759 +++ b/include/acpi/acpi_bus.h
59760 @@ -107,7 +107,7 @@ struct acpi_device_ops {
59761 acpi_op_bind bind;
59762 acpi_op_unbind unbind;
59763 acpi_op_notify notify;
59764 -};
59765 +} __no_const;
59766
59767 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59768
59769 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59770 index b7babf0..71e4e74 100644
59771 --- a/include/asm-generic/atomic-long.h
59772 +++ b/include/asm-generic/atomic-long.h
59773 @@ -22,6 +22,12 @@
59774
59775 typedef atomic64_t atomic_long_t;
59776
59777 +#ifdef CONFIG_PAX_REFCOUNT
59778 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
59779 +#else
59780 +typedef atomic64_t atomic_long_unchecked_t;
59781 +#endif
59782 +
59783 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59784
59785 static inline long atomic_long_read(atomic_long_t *l)
59786 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59787 return (long)atomic64_read(v);
59788 }
59789
59790 +#ifdef CONFIG_PAX_REFCOUNT
59791 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59792 +{
59793 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59794 +
59795 + return (long)atomic64_read_unchecked(v);
59796 +}
59797 +#endif
59798 +
59799 static inline void atomic_long_set(atomic_long_t *l, long i)
59800 {
59801 atomic64_t *v = (atomic64_t *)l;
59802 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59803 atomic64_set(v, i);
59804 }
59805
59806 +#ifdef CONFIG_PAX_REFCOUNT
59807 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59808 +{
59809 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59810 +
59811 + atomic64_set_unchecked(v, i);
59812 +}
59813 +#endif
59814 +
59815 static inline void atomic_long_inc(atomic_long_t *l)
59816 {
59817 atomic64_t *v = (atomic64_t *)l;
59818 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59819 atomic64_inc(v);
59820 }
59821
59822 +#ifdef CONFIG_PAX_REFCOUNT
59823 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59824 +{
59825 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59826 +
59827 + atomic64_inc_unchecked(v);
59828 +}
59829 +#endif
59830 +
59831 static inline void atomic_long_dec(atomic_long_t *l)
59832 {
59833 atomic64_t *v = (atomic64_t *)l;
59834 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59835 atomic64_dec(v);
59836 }
59837
59838 +#ifdef CONFIG_PAX_REFCOUNT
59839 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59840 +{
59841 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59842 +
59843 + atomic64_dec_unchecked(v);
59844 +}
59845 +#endif
59846 +
59847 static inline void atomic_long_add(long i, atomic_long_t *l)
59848 {
59849 atomic64_t *v = (atomic64_t *)l;
59850 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59851 atomic64_add(i, v);
59852 }
59853
59854 +#ifdef CONFIG_PAX_REFCOUNT
59855 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59856 +{
59857 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59858 +
59859 + atomic64_add_unchecked(i, v);
59860 +}
59861 +#endif
59862 +
59863 static inline void atomic_long_sub(long i, atomic_long_t *l)
59864 {
59865 atomic64_t *v = (atomic64_t *)l;
59866 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59867 atomic64_sub(i, v);
59868 }
59869
59870 +#ifdef CONFIG_PAX_REFCOUNT
59871 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59872 +{
59873 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59874 +
59875 + atomic64_sub_unchecked(i, v);
59876 +}
59877 +#endif
59878 +
59879 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59880 {
59881 atomic64_t *v = (atomic64_t *)l;
59882 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59883 return (long)atomic64_inc_return(v);
59884 }
59885
59886 +#ifdef CONFIG_PAX_REFCOUNT
59887 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59888 +{
59889 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59890 +
59891 + return (long)atomic64_inc_return_unchecked(v);
59892 +}
59893 +#endif
59894 +
59895 static inline long atomic_long_dec_return(atomic_long_t *l)
59896 {
59897 atomic64_t *v = (atomic64_t *)l;
59898 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59899
59900 typedef atomic_t atomic_long_t;
59901
59902 +#ifdef CONFIG_PAX_REFCOUNT
59903 +typedef atomic_unchecked_t atomic_long_unchecked_t;
59904 +#else
59905 +typedef atomic_t atomic_long_unchecked_t;
59906 +#endif
59907 +
59908 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59909 static inline long atomic_long_read(atomic_long_t *l)
59910 {
59911 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59912 return (long)atomic_read(v);
59913 }
59914
59915 +#ifdef CONFIG_PAX_REFCOUNT
59916 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59917 +{
59918 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59919 +
59920 + return (long)atomic_read_unchecked(v);
59921 +}
59922 +#endif
59923 +
59924 static inline void atomic_long_set(atomic_long_t *l, long i)
59925 {
59926 atomic_t *v = (atomic_t *)l;
59927 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59928 atomic_set(v, i);
59929 }
59930
59931 +#ifdef CONFIG_PAX_REFCOUNT
59932 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59933 +{
59934 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59935 +
59936 + atomic_set_unchecked(v, i);
59937 +}
59938 +#endif
59939 +
59940 static inline void atomic_long_inc(atomic_long_t *l)
59941 {
59942 atomic_t *v = (atomic_t *)l;
59943 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59944 atomic_inc(v);
59945 }
59946
59947 +#ifdef CONFIG_PAX_REFCOUNT
59948 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59949 +{
59950 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59951 +
59952 + atomic_inc_unchecked(v);
59953 +}
59954 +#endif
59955 +
59956 static inline void atomic_long_dec(atomic_long_t *l)
59957 {
59958 atomic_t *v = (atomic_t *)l;
59959 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59960 atomic_dec(v);
59961 }
59962
59963 +#ifdef CONFIG_PAX_REFCOUNT
59964 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59965 +{
59966 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59967 +
59968 + atomic_dec_unchecked(v);
59969 +}
59970 +#endif
59971 +
59972 static inline void atomic_long_add(long i, atomic_long_t *l)
59973 {
59974 atomic_t *v = (atomic_t *)l;
59975 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59976 atomic_add(i, v);
59977 }
59978
59979 +#ifdef CONFIG_PAX_REFCOUNT
59980 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59981 +{
59982 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59983 +
59984 + atomic_add_unchecked(i, v);
59985 +}
59986 +#endif
59987 +
59988 static inline void atomic_long_sub(long i, atomic_long_t *l)
59989 {
59990 atomic_t *v = (atomic_t *)l;
59991 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59992 atomic_sub(i, v);
59993 }
59994
59995 +#ifdef CONFIG_PAX_REFCOUNT
59996 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59997 +{
59998 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59999 +
60000 + atomic_sub_unchecked(i, v);
60001 +}
60002 +#endif
60003 +
60004 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60005 {
60006 atomic_t *v = (atomic_t *)l;
60007 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60008 return (long)atomic_inc_return(v);
60009 }
60010
60011 +#ifdef CONFIG_PAX_REFCOUNT
60012 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60013 +{
60014 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60015 +
60016 + return (long)atomic_inc_return_unchecked(v);
60017 +}
60018 +#endif
60019 +
60020 static inline long atomic_long_dec_return(atomic_long_t *l)
60021 {
60022 atomic_t *v = (atomic_t *)l;
60023 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60024
60025 #endif /* BITS_PER_LONG == 64 */
60026
60027 +#ifdef CONFIG_PAX_REFCOUNT
60028 +static inline void pax_refcount_needs_these_functions(void)
60029 +{
60030 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60031 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60032 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60033 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60034 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60035 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60036 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60037 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60038 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60039 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60040 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60041 +
60042 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60043 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60044 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60045 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60046 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60047 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60048 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60049 +}
60050 +#else
60051 +#define atomic_read_unchecked(v) atomic_read(v)
60052 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60053 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60054 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60055 +#define atomic_inc_unchecked(v) atomic_inc(v)
60056 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60057 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60058 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60059 +#define atomic_dec_unchecked(v) atomic_dec(v)
60060 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60061 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60062 +
60063 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60064 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60065 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60066 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60067 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60068 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60069 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60070 +#endif
60071 +
60072 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60073 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60074 index b18ce4f..2ee2843 100644
60075 --- a/include/asm-generic/atomic64.h
60076 +++ b/include/asm-generic/atomic64.h
60077 @@ -16,6 +16,8 @@ typedef struct {
60078 long long counter;
60079 } atomic64_t;
60080
60081 +typedef atomic64_t atomic64_unchecked_t;
60082 +
60083 #define ATOMIC64_INIT(i) { (i) }
60084
60085 extern long long atomic64_read(const atomic64_t *v);
60086 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60087 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60088 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60089
60090 +#define atomic64_read_unchecked(v) atomic64_read(v)
60091 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60092 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60093 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60094 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60095 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60096 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60097 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60098 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60099 +
60100 #endif /* _ASM_GENERIC_ATOMIC64_H */
60101 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60102 index 1bfcfe5..e04c5c9 100644
60103 --- a/include/asm-generic/cache.h
60104 +++ b/include/asm-generic/cache.h
60105 @@ -6,7 +6,7 @@
60106 * cache lines need to provide their own cache.h.
60107 */
60108
60109 -#define L1_CACHE_SHIFT 5
60110 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60111 +#define L1_CACHE_SHIFT 5UL
60112 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60113
60114 #endif /* __ASM_GENERIC_CACHE_H */
60115 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60116 index 0d68a1e..b74a761 100644
60117 --- a/include/asm-generic/emergency-restart.h
60118 +++ b/include/asm-generic/emergency-restart.h
60119 @@ -1,7 +1,7 @@
60120 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60121 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60122
60123 -static inline void machine_emergency_restart(void)
60124 +static inline __noreturn void machine_emergency_restart(void)
60125 {
60126 machine_restart(NULL);
60127 }
60128 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60129 index 0232ccb..13d9165 100644
60130 --- a/include/asm-generic/kmap_types.h
60131 +++ b/include/asm-generic/kmap_types.h
60132 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
60133 KMAP_D(17) KM_NMI,
60134 KMAP_D(18) KM_NMI_PTE,
60135 KMAP_D(19) KM_KDB,
60136 +KMAP_D(20) KM_CLEARPAGE,
60137 /*
60138 * Remember to update debug_kmap_atomic() when adding new kmap types!
60139 */
60140 -KMAP_D(20) KM_TYPE_NR
60141 +KMAP_D(21) KM_TYPE_NR
60142 };
60143
60144 #undef KMAP_D
60145 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60146 index 9ceb03b..2efbcbd 100644
60147 --- a/include/asm-generic/local.h
60148 +++ b/include/asm-generic/local.h
60149 @@ -39,6 +39,7 @@ typedef struct
60150 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60151 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60152 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60153 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60154
60155 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60156 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60157 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60158 index 725612b..9cc513a 100644
60159 --- a/include/asm-generic/pgtable-nopmd.h
60160 +++ b/include/asm-generic/pgtable-nopmd.h
60161 @@ -1,14 +1,19 @@
60162 #ifndef _PGTABLE_NOPMD_H
60163 #define _PGTABLE_NOPMD_H
60164
60165 -#ifndef __ASSEMBLY__
60166 -
60167 #include <asm-generic/pgtable-nopud.h>
60168
60169 -struct mm_struct;
60170 -
60171 #define __PAGETABLE_PMD_FOLDED
60172
60173 +#define PMD_SHIFT PUD_SHIFT
60174 +#define PTRS_PER_PMD 1
60175 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60176 +#define PMD_MASK (~(PMD_SIZE-1))
60177 +
60178 +#ifndef __ASSEMBLY__
60179 +
60180 +struct mm_struct;
60181 +
60182 /*
60183 * Having the pmd type consist of a pud gets the size right, and allows
60184 * us to conceptually access the pud entry that this pmd is folded into
60185 @@ -16,11 +21,6 @@ struct mm_struct;
60186 */
60187 typedef struct { pud_t pud; } pmd_t;
60188
60189 -#define PMD_SHIFT PUD_SHIFT
60190 -#define PTRS_PER_PMD 1
60191 -#define PMD_SIZE (1UL << PMD_SHIFT)
60192 -#define PMD_MASK (~(PMD_SIZE-1))
60193 -
60194 /*
60195 * The "pud_xxx()" functions here are trivial for a folded two-level
60196 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60197 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60198 index 810431d..ccc3638 100644
60199 --- a/include/asm-generic/pgtable-nopud.h
60200 +++ b/include/asm-generic/pgtable-nopud.h
60201 @@ -1,10 +1,15 @@
60202 #ifndef _PGTABLE_NOPUD_H
60203 #define _PGTABLE_NOPUD_H
60204
60205 -#ifndef __ASSEMBLY__
60206 -
60207 #define __PAGETABLE_PUD_FOLDED
60208
60209 +#define PUD_SHIFT PGDIR_SHIFT
60210 +#define PTRS_PER_PUD 1
60211 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60212 +#define PUD_MASK (~(PUD_SIZE-1))
60213 +
60214 +#ifndef __ASSEMBLY__
60215 +
60216 /*
60217 * Having the pud type consist of a pgd gets the size right, and allows
60218 * us to conceptually access the pgd entry that this pud is folded into
60219 @@ -12,11 +17,6 @@
60220 */
60221 typedef struct { pgd_t pgd; } pud_t;
60222
60223 -#define PUD_SHIFT PGDIR_SHIFT
60224 -#define PTRS_PER_PUD 1
60225 -#define PUD_SIZE (1UL << PUD_SHIFT)
60226 -#define PUD_MASK (~(PUD_SIZE-1))
60227 -
60228 /*
60229 * The "pgd_xxx()" functions here are trivial for a folded two-level
60230 * setup: the pud is never bad, and a pud always exists (as it's folded
60231 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60232 index 76bff2b..c7a14e2 100644
60233 --- a/include/asm-generic/pgtable.h
60234 +++ b/include/asm-generic/pgtable.h
60235 @@ -443,6 +443,14 @@ static inline int pmd_write(pmd_t pmd)
60236 #endif /* __HAVE_ARCH_PMD_WRITE */
60237 #endif
60238
60239 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60240 +static inline unsigned long pax_open_kernel(void) { return 0; }
60241 +#endif
60242 +
60243 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60244 +static inline unsigned long pax_close_kernel(void) { return 0; }
60245 +#endif
60246 +
60247 #endif /* !__ASSEMBLY__ */
60248
60249 #endif /* _ASM_GENERIC_PGTABLE_H */
60250 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
60251 index ac68c99..90d3439 100644
60252 --- a/include/asm-generic/uaccess.h
60253 +++ b/include/asm-generic/uaccess.h
60254 @@ -76,6 +76,8 @@ extern unsigned long search_exception_table(unsigned long);
60255 */
60256 #ifndef __copy_from_user
60257 static inline __must_check long __copy_from_user(void *to,
60258 + const void __user * from, unsigned long n) __size_overflow(3);
60259 +static inline __must_check long __copy_from_user(void *to,
60260 const void __user * from, unsigned long n)
60261 {
60262 if (__builtin_constant_p(n)) {
60263 @@ -106,6 +108,8 @@ static inline __must_check long __copy_from_user(void *to,
60264
60265 #ifndef __copy_to_user
60266 static inline __must_check long __copy_to_user(void __user *to,
60267 + const void *from, unsigned long n) __size_overflow(3);
60268 +static inline __must_check long __copy_to_user(void __user *to,
60269 const void *from, unsigned long n)
60270 {
60271 if (__builtin_constant_p(n)) {
60272 @@ -224,6 +228,7 @@ extern int __put_user_bad(void) __attribute__((noreturn));
60273 -EFAULT; \
60274 })
60275
60276 +static inline int __get_user_fn(size_t size, const void __user *ptr, void *x) __size_overflow(1);
60277 static inline int __get_user_fn(size_t size, const void __user *ptr, void *x)
60278 {
60279 size = __copy_from_user(x, ptr, size);
60280 @@ -240,6 +245,7 @@ extern int __get_user_bad(void) __attribute__((noreturn));
60281 #define __copy_to_user_inatomic __copy_to_user
60282 #endif
60283
60284 +static inline long copy_from_user(void *to, const void __user * from, unsigned long n) __size_overflow(3);
60285 static inline long copy_from_user(void *to,
60286 const void __user * from, unsigned long n)
60287 {
60288 @@ -250,6 +256,7 @@ static inline long copy_from_user(void *to,
60289 return n;
60290 }
60291
60292 +static inline long copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
60293 static inline long copy_to_user(void __user *to,
60294 const void *from, unsigned long n)
60295 {
60296 @@ -309,6 +316,8 @@ static inline long strlen_user(const char __user *src)
60297 */
60298 #ifndef __clear_user
60299 static inline __must_check unsigned long
60300 +__clear_user(void __user *to, unsigned long n) __size_overflow(2);
60301 +static inline __must_check unsigned long
60302 __clear_user(void __user *to, unsigned long n)
60303 {
60304 memset((void __force *)to, 0, n);
60305 @@ -317,6 +326,8 @@ __clear_user(void __user *to, unsigned long n)
60306 #endif
60307
60308 static inline __must_check unsigned long
60309 +clear_user(void __user *to, unsigned long n) __size_overflow(2);
60310 +static inline __must_check unsigned long
60311 clear_user(void __user *to, unsigned long n)
60312 {
60313 might_sleep();
60314 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60315 index b5e2e4c..6a5373e 100644
60316 --- a/include/asm-generic/vmlinux.lds.h
60317 +++ b/include/asm-generic/vmlinux.lds.h
60318 @@ -217,6 +217,7 @@
60319 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60320 VMLINUX_SYMBOL(__start_rodata) = .; \
60321 *(.rodata) *(.rodata.*) \
60322 + *(.data..read_only) \
60323 *(__vermagic) /* Kernel version magic */ \
60324 . = ALIGN(8); \
60325 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60326 @@ -722,17 +723,18 @@
60327 * section in the linker script will go there too. @phdr should have
60328 * a leading colon.
60329 *
60330 - * Note that this macros defines __per_cpu_load as an absolute symbol.
60331 + * Note that this macros defines per_cpu_load as an absolute symbol.
60332 * If there is no need to put the percpu section at a predetermined
60333 * address, use PERCPU_SECTION.
60334 */
60335 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60336 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
60337 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60338 + per_cpu_load = .; \
60339 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60340 - LOAD_OFFSET) { \
60341 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60342 PERCPU_INPUT(cacheline) \
60343 } phdr \
60344 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60345 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60346
60347 /**
60348 * PERCPU_SECTION - define output section for percpu area, simple version
60349 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60350 index bf4b2dc..2d0762f 100644
60351 --- a/include/drm/drmP.h
60352 +++ b/include/drm/drmP.h
60353 @@ -72,6 +72,7 @@
60354 #include <linux/workqueue.h>
60355 #include <linux/poll.h>
60356 #include <asm/pgalloc.h>
60357 +#include <asm/local.h>
60358 #include "drm.h"
60359
60360 #include <linux/idr.h>
60361 @@ -1038,7 +1039,7 @@ struct drm_device {
60362
60363 /** \name Usage Counters */
60364 /*@{ */
60365 - int open_count; /**< Outstanding files open */
60366 + local_t open_count; /**< Outstanding files open */
60367 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60368 atomic_t vma_count; /**< Outstanding vma areas open */
60369 int buf_use; /**< Buffers in use -- cannot alloc */
60370 @@ -1049,7 +1050,7 @@ struct drm_device {
60371 /*@{ */
60372 unsigned long counters;
60373 enum drm_stat_type types[15];
60374 - atomic_t counts[15];
60375 + atomic_unchecked_t counts[15];
60376 /*@} */
60377
60378 struct list_head filelist;
60379 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60380 index 73b0712..0b7ef2f 100644
60381 --- a/include/drm/drm_crtc_helper.h
60382 +++ b/include/drm/drm_crtc_helper.h
60383 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
60384
60385 /* disable crtc when not in use - more explicit than dpms off */
60386 void (*disable)(struct drm_crtc *crtc);
60387 -};
60388 +} __no_const;
60389
60390 struct drm_encoder_helper_funcs {
60391 void (*dpms)(struct drm_encoder *encoder, int mode);
60392 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
60393 struct drm_connector *connector);
60394 /* disable encoder when not in use - more explicit than dpms off */
60395 void (*disable)(struct drm_encoder *encoder);
60396 -};
60397 +} __no_const;
60398
60399 struct drm_connector_helper_funcs {
60400 int (*get_modes)(struct drm_connector *connector);
60401 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60402 index 26c1f78..6722682 100644
60403 --- a/include/drm/ttm/ttm_memory.h
60404 +++ b/include/drm/ttm/ttm_memory.h
60405 @@ -47,7 +47,7 @@
60406
60407 struct ttm_mem_shrink {
60408 int (*do_shrink) (struct ttm_mem_shrink *);
60409 -};
60410 +} __no_const;
60411
60412 /**
60413 * struct ttm_mem_global - Global memory accounting structure.
60414 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60415 index e86dfca..40cc55f 100644
60416 --- a/include/linux/a.out.h
60417 +++ b/include/linux/a.out.h
60418 @@ -39,6 +39,14 @@ enum machine_type {
60419 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60420 };
60421
60422 +/* Constants for the N_FLAGS field */
60423 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60424 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60425 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60426 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60427 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60428 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60429 +
60430 #if !defined (N_MAGIC)
60431 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60432 #endif
60433 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60434 index 49a83ca..df96b54 100644
60435 --- a/include/linux/atmdev.h
60436 +++ b/include/linux/atmdev.h
60437 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60438 #endif
60439
60440 struct k_atm_aal_stats {
60441 -#define __HANDLE_ITEM(i) atomic_t i
60442 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
60443 __AAL_STAT_ITEMS
60444 #undef __HANDLE_ITEM
60445 };
60446 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60447 index fd88a39..8a801b4 100644
60448 --- a/include/linux/binfmts.h
60449 +++ b/include/linux/binfmts.h
60450 @@ -18,7 +18,7 @@ struct pt_regs;
60451 #define BINPRM_BUF_SIZE 128
60452
60453 #ifdef __KERNEL__
60454 -#include <linux/list.h>
60455 +#include <linux/sched.h>
60456
60457 #define CORENAME_MAX_SIZE 128
60458
60459 @@ -58,6 +58,7 @@ struct linux_binprm {
60460 unsigned interp_flags;
60461 unsigned interp_data;
60462 unsigned long loader, exec;
60463 + char tcomm[TASK_COMM_LEN];
60464 };
60465
60466 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
60467 @@ -88,6 +89,7 @@ struct linux_binfmt {
60468 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60469 int (*load_shlib)(struct file *);
60470 int (*core_dump)(struct coredump_params *cprm);
60471 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60472 unsigned long min_coredump; /* minimal dump size */
60473 };
60474
60475 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60476 index 0ed1eb0..3ab569b 100644
60477 --- a/include/linux/blkdev.h
60478 +++ b/include/linux/blkdev.h
60479 @@ -1315,7 +1315,7 @@ struct block_device_operations {
60480 /* this callback is with swap_lock and sometimes page table lock held */
60481 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60482 struct module *owner;
60483 -};
60484 +} __do_const;
60485
60486 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60487 unsigned long);
60488 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60489 index 4d1a074..88f929a 100644
60490 --- a/include/linux/blktrace_api.h
60491 +++ b/include/linux/blktrace_api.h
60492 @@ -162,7 +162,7 @@ struct blk_trace {
60493 struct dentry *dir;
60494 struct dentry *dropped_file;
60495 struct dentry *msg_file;
60496 - atomic_t dropped;
60497 + atomic_unchecked_t dropped;
60498 };
60499
60500 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60501 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60502 index 83195fb..0b0f77d 100644
60503 --- a/include/linux/byteorder/little_endian.h
60504 +++ b/include/linux/byteorder/little_endian.h
60505 @@ -42,51 +42,51 @@
60506
60507 static inline __le64 __cpu_to_le64p(const __u64 *p)
60508 {
60509 - return (__force __le64)*p;
60510 + return (__force const __le64)*p;
60511 }
60512 static inline __u64 __le64_to_cpup(const __le64 *p)
60513 {
60514 - return (__force __u64)*p;
60515 + return (__force const __u64)*p;
60516 }
60517 static inline __le32 __cpu_to_le32p(const __u32 *p)
60518 {
60519 - return (__force __le32)*p;
60520 + return (__force const __le32)*p;
60521 }
60522 static inline __u32 __le32_to_cpup(const __le32 *p)
60523 {
60524 - return (__force __u32)*p;
60525 + return (__force const __u32)*p;
60526 }
60527 static inline __le16 __cpu_to_le16p(const __u16 *p)
60528 {
60529 - return (__force __le16)*p;
60530 + return (__force const __le16)*p;
60531 }
60532 static inline __u16 __le16_to_cpup(const __le16 *p)
60533 {
60534 - return (__force __u16)*p;
60535 + return (__force const __u16)*p;
60536 }
60537 static inline __be64 __cpu_to_be64p(const __u64 *p)
60538 {
60539 - return (__force __be64)__swab64p(p);
60540 + return (__force const __be64)__swab64p(p);
60541 }
60542 static inline __u64 __be64_to_cpup(const __be64 *p)
60543 {
60544 - return __swab64p((__u64 *)p);
60545 + return __swab64p((const __u64 *)p);
60546 }
60547 static inline __be32 __cpu_to_be32p(const __u32 *p)
60548 {
60549 - return (__force __be32)__swab32p(p);
60550 + return (__force const __be32)__swab32p(p);
60551 }
60552 static inline __u32 __be32_to_cpup(const __be32 *p)
60553 {
60554 - return __swab32p((__u32 *)p);
60555 + return __swab32p((const __u32 *)p);
60556 }
60557 static inline __be16 __cpu_to_be16p(const __u16 *p)
60558 {
60559 - return (__force __be16)__swab16p(p);
60560 + return (__force const __be16)__swab16p(p);
60561 }
60562 static inline __u16 __be16_to_cpup(const __be16 *p)
60563 {
60564 - return __swab16p((__u16 *)p);
60565 + return __swab16p((const __u16 *)p);
60566 }
60567 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60568 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60569 diff --git a/include/linux/cache.h b/include/linux/cache.h
60570 index 4c57065..4307975 100644
60571 --- a/include/linux/cache.h
60572 +++ b/include/linux/cache.h
60573 @@ -16,6 +16,10 @@
60574 #define __read_mostly
60575 #endif
60576
60577 +#ifndef __read_only
60578 +#define __read_only __read_mostly
60579 +#endif
60580 +
60581 #ifndef ____cacheline_aligned
60582 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60583 #endif
60584 diff --git a/include/linux/capability.h b/include/linux/capability.h
60585 index a63d13d..069bfd5 100644
60586 --- a/include/linux/capability.h
60587 +++ b/include/linux/capability.h
60588 @@ -548,6 +548,9 @@ extern bool capable(int cap);
60589 extern bool ns_capable(struct user_namespace *ns, int cap);
60590 extern bool task_ns_capable(struct task_struct *t, int cap);
60591 extern bool nsown_capable(int cap);
60592 +extern bool task_ns_capable_nolog(struct task_struct *t, int cap);
60593 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60594 +extern bool capable_nolog(int cap);
60595
60596 /* audit system wants to get cap info from files as well */
60597 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60598 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60599 index 04ffb2e..6799180 100644
60600 --- a/include/linux/cleancache.h
60601 +++ b/include/linux/cleancache.h
60602 @@ -31,7 +31,7 @@ struct cleancache_ops {
60603 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
60604 void (*flush_inode)(int, struct cleancache_filekey);
60605 void (*flush_fs)(int);
60606 -};
60607 +} __no_const;
60608
60609 extern struct cleancache_ops
60610 cleancache_register_ops(struct cleancache_ops *ops);
60611 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60612 index dfadc96..d90deca 100644
60613 --- a/include/linux/compiler-gcc4.h
60614 +++ b/include/linux/compiler-gcc4.h
60615 @@ -31,6 +31,15 @@
60616
60617
60618 #if __GNUC_MINOR__ >= 5
60619 +
60620 +#ifdef CONSTIFY_PLUGIN
60621 +#define __no_const __attribute__((no_const))
60622 +#define __do_const __attribute__((do_const))
60623 +#endif
60624 +
60625 +#ifdef SIZE_OVERFLOW_PLUGIN
60626 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60627 +#endif
60628 /*
60629 * Mark a position in code as unreachable. This can be used to
60630 * suppress control flow warnings after asm blocks that transfer
60631 @@ -46,6 +55,11 @@
60632 #define __noclone __attribute__((__noclone__))
60633
60634 #endif
60635 +
60636 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60637 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60638 +#define __bos0(ptr) __bos((ptr), 0)
60639 +#define __bos1(ptr) __bos((ptr), 1)
60640 #endif
60641
60642 #if __GNUC_MINOR__ > 0
60643 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60644 index 320d6c9..1221a6b 100644
60645 --- a/include/linux/compiler.h
60646 +++ b/include/linux/compiler.h
60647 @@ -5,31 +5,62 @@
60648
60649 #ifdef __CHECKER__
60650 # define __user __attribute__((noderef, address_space(1)))
60651 +# define __force_user __force __user
60652 # define __kernel __attribute__((address_space(0)))
60653 +# define __force_kernel __force __kernel
60654 # define __safe __attribute__((safe))
60655 # define __force __attribute__((force))
60656 # define __nocast __attribute__((nocast))
60657 # define __iomem __attribute__((noderef, address_space(2)))
60658 +# define __force_iomem __force __iomem
60659 # define __acquires(x) __attribute__((context(x,0,1)))
60660 # define __releases(x) __attribute__((context(x,1,0)))
60661 # define __acquire(x) __context__(x,1)
60662 # define __release(x) __context__(x,-1)
60663 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60664 # define __percpu __attribute__((noderef, address_space(3)))
60665 +# define __force_percpu __force __percpu
60666 #ifdef CONFIG_SPARSE_RCU_POINTER
60667 # define __rcu __attribute__((noderef, address_space(4)))
60668 +# define __force_rcu __force __rcu
60669 #else
60670 # define __rcu
60671 +# define __force_rcu
60672 #endif
60673 extern void __chk_user_ptr(const volatile void __user *);
60674 extern void __chk_io_ptr(const volatile void __iomem *);
60675 +#elif defined(CHECKER_PLUGIN)
60676 +//# define __user
60677 +//# define __force_user
60678 +//# define __kernel
60679 +//# define __force_kernel
60680 +# define __safe
60681 +# define __force
60682 +# define __nocast
60683 +# define __iomem
60684 +# define __force_iomem
60685 +# define __chk_user_ptr(x) (void)0
60686 +# define __chk_io_ptr(x) (void)0
60687 +# define __builtin_warning(x, y...) (1)
60688 +# define __acquires(x)
60689 +# define __releases(x)
60690 +# define __acquire(x) (void)0
60691 +# define __release(x) (void)0
60692 +# define __cond_lock(x,c) (c)
60693 +# define __percpu
60694 +# define __force_percpu
60695 +# define __rcu
60696 +# define __force_rcu
60697 #else
60698 # define __user
60699 +# define __force_user
60700 # define __kernel
60701 +# define __force_kernel
60702 # define __safe
60703 # define __force
60704 # define __nocast
60705 # define __iomem
60706 +# define __force_iomem
60707 # define __chk_user_ptr(x) (void)0
60708 # define __chk_io_ptr(x) (void)0
60709 # define __builtin_warning(x, y...) (1)
60710 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60711 # define __release(x) (void)0
60712 # define __cond_lock(x,c) (c)
60713 # define __percpu
60714 +# define __force_percpu
60715 # define __rcu
60716 +# define __force_rcu
60717 #endif
60718
60719 #ifdef __KERNEL__
60720 @@ -264,6 +297,17 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60721 # define __attribute_const__ /* unimplemented */
60722 #endif
60723
60724 +#ifndef __no_const
60725 +# define __no_const
60726 +#endif
60727 +
60728 +#ifndef __do_const
60729 +# define __do_const
60730 +#endif
60731 +
60732 +#ifndef __size_overflow
60733 +# define __size_overflow(...)
60734 +#endif
60735 /*
60736 * Tell gcc if a function is cold. The compiler will assume any path
60737 * directly leading to the call is unlikely.
60738 @@ -273,6 +317,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60739 #define __cold
60740 #endif
60741
60742 +#ifndef __alloc_size
60743 +#define __alloc_size(...)
60744 +#endif
60745 +
60746 +#ifndef __bos
60747 +#define __bos(ptr, arg)
60748 +#endif
60749 +
60750 +#ifndef __bos0
60751 +#define __bos0(ptr)
60752 +#endif
60753 +
60754 +#ifndef __bos1
60755 +#define __bos1(ptr)
60756 +#endif
60757 +
60758 /* Simple shorthand for a section definition */
60759 #ifndef __section
60760 # define __section(S) __attribute__ ((__section__(#S)))
60761 @@ -306,6 +366,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60762 * use is to mediate communication between process-level code and irq/NMI
60763 * handlers, all running on the same CPU.
60764 */
60765 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60766 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60767 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60768
60769 #endif /* __LINUX_COMPILER_H */
60770 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
60771 index e9eaec5..bfeb9bb 100644
60772 --- a/include/linux/cpuset.h
60773 +++ b/include/linux/cpuset.h
60774 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
60775 * nodemask.
60776 */
60777 smp_mb();
60778 - --ACCESS_ONCE(current->mems_allowed_change_disable);
60779 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
60780 }
60781
60782 static inline void set_mems_allowed(nodemask_t nodemask)
60783 diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h
60784 index b936763..48685ee 100644
60785 --- a/include/linux/crash_dump.h
60786 +++ b/include/linux/crash_dump.h
60787 @@ -14,7 +14,7 @@ extern unsigned long long elfcorehdr_addr;
60788 extern unsigned long long elfcorehdr_size;
60789
60790 extern ssize_t copy_oldmem_page(unsigned long, char *, size_t,
60791 - unsigned long, int);
60792 + unsigned long, int) __size_overflow(3);
60793
60794 /* Architecture code defines this if there are other possible ELF
60795 * machine types, e.g. on bi-arch capable hardware. */
60796 diff --git a/include/linux/cred.h b/include/linux/cred.h
60797 index 4030896..8d6f342 100644
60798 --- a/include/linux/cred.h
60799 +++ b/include/linux/cred.h
60800 @@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60801 static inline void validate_process_creds(void)
60802 {
60803 }
60804 +static inline void validate_task_creds(struct task_struct *task)
60805 +{
60806 +}
60807 #endif
60808
60809 /**
60810 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60811 index 8a94217..15d49e3 100644
60812 --- a/include/linux/crypto.h
60813 +++ b/include/linux/crypto.h
60814 @@ -365,7 +365,7 @@ struct cipher_tfm {
60815 const u8 *key, unsigned int keylen);
60816 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60817 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60818 -};
60819 +} __no_const;
60820
60821 struct hash_tfm {
60822 int (*init)(struct hash_desc *desc);
60823 @@ -386,13 +386,13 @@ struct compress_tfm {
60824 int (*cot_decompress)(struct crypto_tfm *tfm,
60825 const u8 *src, unsigned int slen,
60826 u8 *dst, unsigned int *dlen);
60827 -};
60828 +} __no_const;
60829
60830 struct rng_tfm {
60831 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60832 unsigned int dlen);
60833 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60834 -};
60835 +} __no_const;
60836
60837 #define crt_ablkcipher crt_u.ablkcipher
60838 #define crt_aead crt_u.aead
60839 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60840 index 7925bf0..d5143d2 100644
60841 --- a/include/linux/decompress/mm.h
60842 +++ b/include/linux/decompress/mm.h
60843 @@ -77,7 +77,7 @@ static void free(void *where)
60844 * warnings when not needed (indeed large_malloc / large_free are not
60845 * needed by inflate */
60846
60847 -#define malloc(a) kmalloc(a, GFP_KERNEL)
60848 +#define malloc(a) kmalloc((a), GFP_KERNEL)
60849 #define free(a) kfree(a)
60850
60851 #define large_malloc(a) vmalloc(a)
60852 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60853 index e13117c..e9fc938 100644
60854 --- a/include/linux/dma-mapping.h
60855 +++ b/include/linux/dma-mapping.h
60856 @@ -46,7 +46,7 @@ struct dma_map_ops {
60857 u64 (*get_required_mask)(struct device *dev);
60858 #endif
60859 int is_phys;
60860 -};
60861 +} __do_const;
60862
60863 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60864
60865 diff --git a/include/linux/efi.h b/include/linux/efi.h
60866 index 2362a0b..cfaf8fcc 100644
60867 --- a/include/linux/efi.h
60868 +++ b/include/linux/efi.h
60869 @@ -446,7 +446,7 @@ struct efivar_operations {
60870 efi_get_variable_t *get_variable;
60871 efi_get_next_variable_t *get_next_variable;
60872 efi_set_variable_t *set_variable;
60873 -};
60874 +} __no_const;
60875
60876 struct efivars {
60877 /*
60878 diff --git a/include/linux/elf.h b/include/linux/elf.h
60879 index 31f0508..5421c01 100644
60880 --- a/include/linux/elf.h
60881 +++ b/include/linux/elf.h
60882 @@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
60883 #define PT_GNU_EH_FRAME 0x6474e550
60884
60885 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60886 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60887 +
60888 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60889 +
60890 +/* Constants for the e_flags field */
60891 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60892 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60893 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60894 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
60895 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60896 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60897
60898 /*
60899 * Extended Numbering
60900 @@ -106,6 +117,8 @@ typedef __s64 Elf64_Sxword;
60901 #define DT_DEBUG 21
60902 #define DT_TEXTREL 22
60903 #define DT_JMPREL 23
60904 +#define DT_FLAGS 30
60905 + #define DF_TEXTREL 0x00000004
60906 #define DT_ENCODING 32
60907 #define OLD_DT_LOOS 0x60000000
60908 #define DT_LOOS 0x6000000d
60909 @@ -252,6 +265,19 @@ typedef struct elf64_hdr {
60910 #define PF_W 0x2
60911 #define PF_X 0x1
60912
60913 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60914 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60915 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60916 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60917 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60918 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60919 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60920 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60921 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60922 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60923 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60924 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60925 +
60926 typedef struct elf32_phdr{
60927 Elf32_Word p_type;
60928 Elf32_Off p_offset;
60929 @@ -344,6 +370,8 @@ typedef struct elf64_shdr {
60930 #define EI_OSABI 7
60931 #define EI_PAD 8
60932
60933 +#define EI_PAX 14
60934 +
60935 #define ELFMAG0 0x7f /* EI_MAG */
60936 #define ELFMAG1 'E'
60937 #define ELFMAG2 'L'
60938 @@ -423,6 +451,7 @@ extern Elf32_Dyn _DYNAMIC [];
60939 #define elf_note elf32_note
60940 #define elf_addr_t Elf32_Off
60941 #define Elf_Half Elf32_Half
60942 +#define elf_dyn Elf32_Dyn
60943
60944 #else
60945
60946 @@ -433,6 +462,7 @@ extern Elf64_Dyn _DYNAMIC [];
60947 #define elf_note elf64_note
60948 #define elf_addr_t Elf64_Off
60949 #define Elf_Half Elf64_Half
60950 +#define elf_dyn Elf64_Dyn
60951
60952 #endif
60953
60954 diff --git a/include/linux/filter.h b/include/linux/filter.h
60955 index 8eeb205..d59bfa2 100644
60956 --- a/include/linux/filter.h
60957 +++ b/include/linux/filter.h
60958 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
60959
60960 struct sk_buff;
60961 struct sock;
60962 +struct bpf_jit_work;
60963
60964 struct sk_filter
60965 {
60966 @@ -141,6 +142,9 @@ struct sk_filter
60967 unsigned int len; /* Number of filter blocks */
60968 unsigned int (*bpf_func)(const struct sk_buff *skb,
60969 const struct sock_filter *filter);
60970 +#ifdef CONFIG_BPF_JIT
60971 + struct bpf_jit_work *work;
60972 +#endif
60973 struct rcu_head rcu;
60974 struct sock_filter insns[0];
60975 };
60976 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60977 index 84ccf8e..2e9b14c 100644
60978 --- a/include/linux/firewire.h
60979 +++ b/include/linux/firewire.h
60980 @@ -428,7 +428,7 @@ struct fw_iso_context {
60981 union {
60982 fw_iso_callback_t sc;
60983 fw_iso_mc_callback_t mc;
60984 - } callback;
60985 + } __no_const callback;
60986 void *callback_data;
60987 };
60988
60989 diff --git a/include/linux/fs.h b/include/linux/fs.h
60990 index 10b2288..09180e4 100644
60991 --- a/include/linux/fs.h
60992 +++ b/include/linux/fs.h
60993 @@ -1609,7 +1609,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 2a53f10..0187fdf 100644
61040 --- a/include/linux/fsnotify.h
61041 +++ b/include/linux/fsnotify.h
61042 @@ -314,7 +314,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 91d0e0a3..035666b 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 c3da42d..c70e0df 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 @@ -254,7 +254,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 c6f7f6a..aa0f7d3 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/gracl.h b/include/linux/gracl.h
61099 new file mode 100644
61100 index 0000000..8a130b6
61101 --- /dev/null
61102 +++ b/include/linux/gracl.h
61103 @@ -0,0 +1,319 @@
61104 +#ifndef GR_ACL_H
61105 +#define GR_ACL_H
61106 +
61107 +#include <linux/grdefs.h>
61108 +#include <linux/resource.h>
61109 +#include <linux/capability.h>
61110 +#include <linux/dcache.h>
61111 +#include <asm/resource.h>
61112 +
61113 +/* Major status information */
61114 +
61115 +#define GR_VERSION "grsecurity 2.9"
61116 +#define GRSECURITY_VERSION 0x2900
61117 +
61118 +enum {
61119 + GR_SHUTDOWN = 0,
61120 + GR_ENABLE = 1,
61121 + GR_SPROLE = 2,
61122 + GR_RELOAD = 3,
61123 + GR_SEGVMOD = 4,
61124 + GR_STATUS = 5,
61125 + GR_UNSPROLE = 6,
61126 + GR_PASSSET = 7,
61127 + GR_SPROLEPAM = 8,
61128 +};
61129 +
61130 +/* Password setup definitions
61131 + * kernel/grhash.c */
61132 +enum {
61133 + GR_PW_LEN = 128,
61134 + GR_SALT_LEN = 16,
61135 + GR_SHA_LEN = 32,
61136 +};
61137 +
61138 +enum {
61139 + GR_SPROLE_LEN = 64,
61140 +};
61141 +
61142 +enum {
61143 + GR_NO_GLOB = 0,
61144 + GR_REG_GLOB,
61145 + GR_CREATE_GLOB
61146 +};
61147 +
61148 +#define GR_NLIMITS 32
61149 +
61150 +/* Begin Data Structures */
61151 +
61152 +struct sprole_pw {
61153 + unsigned char *rolename;
61154 + unsigned char salt[GR_SALT_LEN];
61155 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61156 +};
61157 +
61158 +struct name_entry {
61159 + __u32 key;
61160 + ino_t inode;
61161 + dev_t device;
61162 + char *name;
61163 + __u16 len;
61164 + __u8 deleted;
61165 + struct name_entry *prev;
61166 + struct name_entry *next;
61167 +};
61168 +
61169 +struct inodev_entry {
61170 + struct name_entry *nentry;
61171 + struct inodev_entry *prev;
61172 + struct inodev_entry *next;
61173 +};
61174 +
61175 +struct acl_role_db {
61176 + struct acl_role_label **r_hash;
61177 + __u32 r_size;
61178 +};
61179 +
61180 +struct inodev_db {
61181 + struct inodev_entry **i_hash;
61182 + __u32 i_size;
61183 +};
61184 +
61185 +struct name_db {
61186 + struct name_entry **n_hash;
61187 + __u32 n_size;
61188 +};
61189 +
61190 +struct crash_uid {
61191 + uid_t uid;
61192 + unsigned long expires;
61193 +};
61194 +
61195 +struct gr_hash_struct {
61196 + void **table;
61197 + void **nametable;
61198 + void *first;
61199 + __u32 table_size;
61200 + __u32 used_size;
61201 + int type;
61202 +};
61203 +
61204 +/* Userspace Grsecurity ACL data structures */
61205 +
61206 +struct acl_subject_label {
61207 + char *filename;
61208 + ino_t inode;
61209 + dev_t device;
61210 + __u32 mode;
61211 + kernel_cap_t cap_mask;
61212 + kernel_cap_t cap_lower;
61213 + kernel_cap_t cap_invert_audit;
61214 +
61215 + struct rlimit res[GR_NLIMITS];
61216 + __u32 resmask;
61217 +
61218 + __u8 user_trans_type;
61219 + __u8 group_trans_type;
61220 + uid_t *user_transitions;
61221 + gid_t *group_transitions;
61222 + __u16 user_trans_num;
61223 + __u16 group_trans_num;
61224 +
61225 + __u32 sock_families[2];
61226 + __u32 ip_proto[8];
61227 + __u32 ip_type;
61228 + struct acl_ip_label **ips;
61229 + __u32 ip_num;
61230 + __u32 inaddr_any_override;
61231 +
61232 + __u32 crashes;
61233 + unsigned long expires;
61234 +
61235 + struct acl_subject_label *parent_subject;
61236 + struct gr_hash_struct *hash;
61237 + struct acl_subject_label *prev;
61238 + struct acl_subject_label *next;
61239 +
61240 + struct acl_object_label **obj_hash;
61241 + __u32 obj_hash_size;
61242 + __u16 pax_flags;
61243 +};
61244 +
61245 +struct role_allowed_ip {
61246 + __u32 addr;
61247 + __u32 netmask;
61248 +
61249 + struct role_allowed_ip *prev;
61250 + struct role_allowed_ip *next;
61251 +};
61252 +
61253 +struct role_transition {
61254 + char *rolename;
61255 +
61256 + struct role_transition *prev;
61257 + struct role_transition *next;
61258 +};
61259 +
61260 +struct acl_role_label {
61261 + char *rolename;
61262 + uid_t uidgid;
61263 + __u16 roletype;
61264 +
61265 + __u16 auth_attempts;
61266 + unsigned long expires;
61267 +
61268 + struct acl_subject_label *root_label;
61269 + struct gr_hash_struct *hash;
61270 +
61271 + struct acl_role_label *prev;
61272 + struct acl_role_label *next;
61273 +
61274 + struct role_transition *transitions;
61275 + struct role_allowed_ip *allowed_ips;
61276 + uid_t *domain_children;
61277 + __u16 domain_child_num;
61278 +
61279 + umode_t umask;
61280 +
61281 + struct acl_subject_label **subj_hash;
61282 + __u32 subj_hash_size;
61283 +};
61284 +
61285 +struct user_acl_role_db {
61286 + struct acl_role_label **r_table;
61287 + __u32 num_pointers; /* Number of allocations to track */
61288 + __u32 num_roles; /* Number of roles */
61289 + __u32 num_domain_children; /* Number of domain children */
61290 + __u32 num_subjects; /* Number of subjects */
61291 + __u32 num_objects; /* Number of objects */
61292 +};
61293 +
61294 +struct acl_object_label {
61295 + char *filename;
61296 + ino_t inode;
61297 + dev_t device;
61298 + __u32 mode;
61299 +
61300 + struct acl_subject_label *nested;
61301 + struct acl_object_label *globbed;
61302 +
61303 + /* next two structures not used */
61304 +
61305 + struct acl_object_label *prev;
61306 + struct acl_object_label *next;
61307 +};
61308 +
61309 +struct acl_ip_label {
61310 + char *iface;
61311 + __u32 addr;
61312 + __u32 netmask;
61313 + __u16 low, high;
61314 + __u8 mode;
61315 + __u32 type;
61316 + __u32 proto[8];
61317 +
61318 + /* next two structures not used */
61319 +
61320 + struct acl_ip_label *prev;
61321 + struct acl_ip_label *next;
61322 +};
61323 +
61324 +struct gr_arg {
61325 + struct user_acl_role_db role_db;
61326 + unsigned char pw[GR_PW_LEN];
61327 + unsigned char salt[GR_SALT_LEN];
61328 + unsigned char sum[GR_SHA_LEN];
61329 + unsigned char sp_role[GR_SPROLE_LEN];
61330 + struct sprole_pw *sprole_pws;
61331 + dev_t segv_device;
61332 + ino_t segv_inode;
61333 + uid_t segv_uid;
61334 + __u16 num_sprole_pws;
61335 + __u16 mode;
61336 +};
61337 +
61338 +struct gr_arg_wrapper {
61339 + struct gr_arg *arg;
61340 + __u32 version;
61341 + __u32 size;
61342 +};
61343 +
61344 +struct subject_map {
61345 + struct acl_subject_label *user;
61346 + struct acl_subject_label *kernel;
61347 + struct subject_map *prev;
61348 + struct subject_map *next;
61349 +};
61350 +
61351 +struct acl_subj_map_db {
61352 + struct subject_map **s_hash;
61353 + __u32 s_size;
61354 +};
61355 +
61356 +/* End Data Structures Section */
61357 +
61358 +/* Hash functions generated by empirical testing by Brad Spengler
61359 + Makes good use of the low bits of the inode. Generally 0-1 times
61360 + in loop for successful match. 0-3 for unsuccessful match.
61361 + Shift/add algorithm with modulus of table size and an XOR*/
61362 +
61363 +static __inline__ unsigned int
61364 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61365 +{
61366 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
61367 +}
61368 +
61369 + static __inline__ unsigned int
61370 +shash(const struct acl_subject_label *userp, const unsigned int sz)
61371 +{
61372 + return ((const unsigned long)userp % sz);
61373 +}
61374 +
61375 +static __inline__ unsigned int
61376 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61377 +{
61378 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61379 +}
61380 +
61381 +static __inline__ unsigned int
61382 +nhash(const char *name, const __u16 len, const unsigned int sz)
61383 +{
61384 + return full_name_hash((const unsigned char *)name, len) % sz;
61385 +}
61386 +
61387 +#define FOR_EACH_ROLE_START(role) \
61388 + role = role_list; \
61389 + while (role) {
61390 +
61391 +#define FOR_EACH_ROLE_END(role) \
61392 + role = role->prev; \
61393 + }
61394 +
61395 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61396 + subj = NULL; \
61397 + iter = 0; \
61398 + while (iter < role->subj_hash_size) { \
61399 + if (subj == NULL) \
61400 + subj = role->subj_hash[iter]; \
61401 + if (subj == NULL) { \
61402 + iter++; \
61403 + continue; \
61404 + }
61405 +
61406 +#define FOR_EACH_SUBJECT_END(subj,iter) \
61407 + subj = subj->next; \
61408 + if (subj == NULL) \
61409 + iter++; \
61410 + }
61411 +
61412 +
61413 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61414 + subj = role->hash->first; \
61415 + while (subj != NULL) {
61416 +
61417 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61418 + subj = subj->next; \
61419 + }
61420 +
61421 +#endif
61422 +
61423 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61424 new file mode 100644
61425 index 0000000..323ecf2
61426 --- /dev/null
61427 +++ b/include/linux/gralloc.h
61428 @@ -0,0 +1,9 @@
61429 +#ifndef __GRALLOC_H
61430 +#define __GRALLOC_H
61431 +
61432 +void acl_free_all(void);
61433 +int acl_alloc_stack_init(unsigned long size);
61434 +void *acl_alloc(unsigned long len);
61435 +void *acl_alloc_num(unsigned long num, unsigned long len);
61436 +
61437 +#endif
61438 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61439 new file mode 100644
61440 index 0000000..b30e9bc
61441 --- /dev/null
61442 +++ b/include/linux/grdefs.h
61443 @@ -0,0 +1,140 @@
61444 +#ifndef GRDEFS_H
61445 +#define GRDEFS_H
61446 +
61447 +/* Begin grsecurity status declarations */
61448 +
61449 +enum {
61450 + GR_READY = 0x01,
61451 + GR_STATUS_INIT = 0x00 // disabled state
61452 +};
61453 +
61454 +/* Begin ACL declarations */
61455 +
61456 +/* Role flags */
61457 +
61458 +enum {
61459 + GR_ROLE_USER = 0x0001,
61460 + GR_ROLE_GROUP = 0x0002,
61461 + GR_ROLE_DEFAULT = 0x0004,
61462 + GR_ROLE_SPECIAL = 0x0008,
61463 + GR_ROLE_AUTH = 0x0010,
61464 + GR_ROLE_NOPW = 0x0020,
61465 + GR_ROLE_GOD = 0x0040,
61466 + GR_ROLE_LEARN = 0x0080,
61467 + GR_ROLE_TPE = 0x0100,
61468 + GR_ROLE_DOMAIN = 0x0200,
61469 + GR_ROLE_PAM = 0x0400,
61470 + GR_ROLE_PERSIST = 0x0800
61471 +};
61472 +
61473 +/* ACL Subject and Object mode flags */
61474 +enum {
61475 + GR_DELETED = 0x80000000
61476 +};
61477 +
61478 +/* ACL Object-only mode flags */
61479 +enum {
61480 + GR_READ = 0x00000001,
61481 + GR_APPEND = 0x00000002,
61482 + GR_WRITE = 0x00000004,
61483 + GR_EXEC = 0x00000008,
61484 + GR_FIND = 0x00000010,
61485 + GR_INHERIT = 0x00000020,
61486 + GR_SETID = 0x00000040,
61487 + GR_CREATE = 0x00000080,
61488 + GR_DELETE = 0x00000100,
61489 + GR_LINK = 0x00000200,
61490 + GR_AUDIT_READ = 0x00000400,
61491 + GR_AUDIT_APPEND = 0x00000800,
61492 + GR_AUDIT_WRITE = 0x00001000,
61493 + GR_AUDIT_EXEC = 0x00002000,
61494 + GR_AUDIT_FIND = 0x00004000,
61495 + GR_AUDIT_INHERIT= 0x00008000,
61496 + GR_AUDIT_SETID = 0x00010000,
61497 + GR_AUDIT_CREATE = 0x00020000,
61498 + GR_AUDIT_DELETE = 0x00040000,
61499 + GR_AUDIT_LINK = 0x00080000,
61500 + GR_PTRACERD = 0x00100000,
61501 + GR_NOPTRACE = 0x00200000,
61502 + GR_SUPPRESS = 0x00400000,
61503 + GR_NOLEARN = 0x00800000,
61504 + GR_INIT_TRANSFER= 0x01000000
61505 +};
61506 +
61507 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61508 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61509 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61510 +
61511 +/* ACL subject-only mode flags */
61512 +enum {
61513 + GR_KILL = 0x00000001,
61514 + GR_VIEW = 0x00000002,
61515 + GR_PROTECTED = 0x00000004,
61516 + GR_LEARN = 0x00000008,
61517 + GR_OVERRIDE = 0x00000010,
61518 + /* just a placeholder, this mode is only used in userspace */
61519 + GR_DUMMY = 0x00000020,
61520 + GR_PROTSHM = 0x00000040,
61521 + GR_KILLPROC = 0x00000080,
61522 + GR_KILLIPPROC = 0x00000100,
61523 + /* just a placeholder, this mode is only used in userspace */
61524 + GR_NOTROJAN = 0x00000200,
61525 + GR_PROTPROCFD = 0x00000400,
61526 + GR_PROCACCT = 0x00000800,
61527 + GR_RELAXPTRACE = 0x00001000,
61528 + GR_NESTED = 0x00002000,
61529 + GR_INHERITLEARN = 0x00004000,
61530 + GR_PROCFIND = 0x00008000,
61531 + GR_POVERRIDE = 0x00010000,
61532 + GR_KERNELAUTH = 0x00020000,
61533 + GR_ATSECURE = 0x00040000,
61534 + GR_SHMEXEC = 0x00080000
61535 +};
61536 +
61537 +enum {
61538 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61539 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61540 + GR_PAX_ENABLE_MPROTECT = 0x0004,
61541 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
61542 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61543 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61544 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61545 + GR_PAX_DISABLE_MPROTECT = 0x0400,
61546 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
61547 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61548 +};
61549 +
61550 +enum {
61551 + GR_ID_USER = 0x01,
61552 + GR_ID_GROUP = 0x02,
61553 +};
61554 +
61555 +enum {
61556 + GR_ID_ALLOW = 0x01,
61557 + GR_ID_DENY = 0x02,
61558 +};
61559 +
61560 +#define GR_CRASH_RES 31
61561 +#define GR_UIDTABLE_MAX 500
61562 +
61563 +/* begin resource learning section */
61564 +enum {
61565 + GR_RLIM_CPU_BUMP = 60,
61566 + GR_RLIM_FSIZE_BUMP = 50000,
61567 + GR_RLIM_DATA_BUMP = 10000,
61568 + GR_RLIM_STACK_BUMP = 1000,
61569 + GR_RLIM_CORE_BUMP = 10000,
61570 + GR_RLIM_RSS_BUMP = 500000,
61571 + GR_RLIM_NPROC_BUMP = 1,
61572 + GR_RLIM_NOFILE_BUMP = 5,
61573 + GR_RLIM_MEMLOCK_BUMP = 50000,
61574 + GR_RLIM_AS_BUMP = 500000,
61575 + GR_RLIM_LOCKS_BUMP = 2,
61576 + GR_RLIM_SIGPENDING_BUMP = 5,
61577 + GR_RLIM_MSGQUEUE_BUMP = 10000,
61578 + GR_RLIM_NICE_BUMP = 1,
61579 + GR_RLIM_RTPRIO_BUMP = 1,
61580 + GR_RLIM_RTTIME_BUMP = 1000000
61581 +};
61582 +
61583 +#endif
61584 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61585 new file mode 100644
61586 index 0000000..da390f1
61587 --- /dev/null
61588 +++ b/include/linux/grinternal.h
61589 @@ -0,0 +1,221 @@
61590 +#ifndef __GRINTERNAL_H
61591 +#define __GRINTERNAL_H
61592 +
61593 +#ifdef CONFIG_GRKERNSEC
61594 +
61595 +#include <linux/fs.h>
61596 +#include <linux/mnt_namespace.h>
61597 +#include <linux/nsproxy.h>
61598 +#include <linux/gracl.h>
61599 +#include <linux/grdefs.h>
61600 +#include <linux/grmsg.h>
61601 +
61602 +void gr_add_learn_entry(const char *fmt, ...)
61603 + __attribute__ ((format (printf, 1, 2)));
61604 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61605 + const struct vfsmount *mnt);
61606 +__u32 gr_check_create(const struct dentry *new_dentry,
61607 + const struct dentry *parent,
61608 + const struct vfsmount *mnt, const __u32 mode);
61609 +int gr_check_protected_task(const struct task_struct *task);
61610 +__u32 to_gr_audit(const __u32 reqmode);
61611 +int gr_set_acls(const int type);
61612 +int gr_apply_subject_to_task(struct task_struct *task);
61613 +int gr_acl_is_enabled(void);
61614 +char gr_roletype_to_char(void);
61615 +
61616 +void gr_handle_alertkill(struct task_struct *task);
61617 +char *gr_to_filename(const struct dentry *dentry,
61618 + const struct vfsmount *mnt);
61619 +char *gr_to_filename1(const struct dentry *dentry,
61620 + const struct vfsmount *mnt);
61621 +char *gr_to_filename2(const struct dentry *dentry,
61622 + const struct vfsmount *mnt);
61623 +char *gr_to_filename3(const struct dentry *dentry,
61624 + const struct vfsmount *mnt);
61625 +
61626 +extern int grsec_enable_ptrace_readexec;
61627 +extern int grsec_enable_harden_ptrace;
61628 +extern int grsec_enable_link;
61629 +extern int grsec_enable_fifo;
61630 +extern int grsec_enable_execve;
61631 +extern int grsec_enable_shm;
61632 +extern int grsec_enable_execlog;
61633 +extern int grsec_enable_signal;
61634 +extern int grsec_enable_audit_ptrace;
61635 +extern int grsec_enable_forkfail;
61636 +extern int grsec_enable_time;
61637 +extern int grsec_enable_rofs;
61638 +extern int grsec_enable_chroot_shmat;
61639 +extern int grsec_enable_chroot_mount;
61640 +extern int grsec_enable_chroot_double;
61641 +extern int grsec_enable_chroot_pivot;
61642 +extern int grsec_enable_chroot_chdir;
61643 +extern int grsec_enable_chroot_chmod;
61644 +extern int grsec_enable_chroot_mknod;
61645 +extern int grsec_enable_chroot_fchdir;
61646 +extern int grsec_enable_chroot_nice;
61647 +extern int grsec_enable_chroot_execlog;
61648 +extern int grsec_enable_chroot_caps;
61649 +extern int grsec_enable_chroot_sysctl;
61650 +extern int grsec_enable_chroot_unix;
61651 +extern int grsec_enable_tpe;
61652 +extern int grsec_tpe_gid;
61653 +extern int grsec_enable_tpe_all;
61654 +extern int grsec_enable_tpe_invert;
61655 +extern int grsec_enable_socket_all;
61656 +extern int grsec_socket_all_gid;
61657 +extern int grsec_enable_socket_client;
61658 +extern int grsec_socket_client_gid;
61659 +extern int grsec_enable_socket_server;
61660 +extern int grsec_socket_server_gid;
61661 +extern int grsec_audit_gid;
61662 +extern int grsec_enable_group;
61663 +extern int grsec_enable_audit_textrel;
61664 +extern int grsec_enable_log_rwxmaps;
61665 +extern int grsec_enable_mount;
61666 +extern int grsec_enable_chdir;
61667 +extern int grsec_resource_logging;
61668 +extern int grsec_enable_blackhole;
61669 +extern int grsec_lastack_retries;
61670 +extern int grsec_enable_brute;
61671 +extern int grsec_lock;
61672 +
61673 +extern spinlock_t grsec_alert_lock;
61674 +extern unsigned long grsec_alert_wtime;
61675 +extern unsigned long grsec_alert_fyet;
61676 +
61677 +extern spinlock_t grsec_audit_lock;
61678 +
61679 +extern rwlock_t grsec_exec_file_lock;
61680 +
61681 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61682 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61683 + (tsk)->exec_file->f_vfsmnt) : "/")
61684 +
61685 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61686 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61687 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61688 +
61689 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61690 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
61691 + (tsk)->exec_file->f_vfsmnt) : "/")
61692 +
61693 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61694 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61695 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61696 +
61697 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61698 +
61699 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61700 +
61701 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61702 + (task)->pid, (cred)->uid, \
61703 + (cred)->euid, (cred)->gid, (cred)->egid, \
61704 + gr_parent_task_fullpath(task), \
61705 + (task)->real_parent->comm, (task)->real_parent->pid, \
61706 + (pcred)->uid, (pcred)->euid, \
61707 + (pcred)->gid, (pcred)->egid
61708 +
61709 +#define GR_CHROOT_CAPS {{ \
61710 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61711 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61712 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61713 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61714 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61715 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61716 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61717 +
61718 +#define security_learn(normal_msg,args...) \
61719 +({ \
61720 + read_lock(&grsec_exec_file_lock); \
61721 + gr_add_learn_entry(normal_msg "\n", ## args); \
61722 + read_unlock(&grsec_exec_file_lock); \
61723 +})
61724 +
61725 +enum {
61726 + GR_DO_AUDIT,
61727 + GR_DONT_AUDIT,
61728 + /* used for non-audit messages that we shouldn't kill the task on */
61729 + GR_DONT_AUDIT_GOOD
61730 +};
61731 +
61732 +enum {
61733 + GR_TTYSNIFF,
61734 + GR_RBAC,
61735 + GR_RBAC_STR,
61736 + GR_STR_RBAC,
61737 + GR_RBAC_MODE2,
61738 + GR_RBAC_MODE3,
61739 + GR_FILENAME,
61740 + GR_SYSCTL_HIDDEN,
61741 + GR_NOARGS,
61742 + GR_ONE_INT,
61743 + GR_ONE_INT_TWO_STR,
61744 + GR_ONE_STR,
61745 + GR_STR_INT,
61746 + GR_TWO_STR_INT,
61747 + GR_TWO_INT,
61748 + GR_TWO_U64,
61749 + GR_THREE_INT,
61750 + GR_FIVE_INT_TWO_STR,
61751 + GR_TWO_STR,
61752 + GR_THREE_STR,
61753 + GR_FOUR_STR,
61754 + GR_STR_FILENAME,
61755 + GR_FILENAME_STR,
61756 + GR_FILENAME_TWO_INT,
61757 + GR_FILENAME_TWO_INT_STR,
61758 + GR_TEXTREL,
61759 + GR_PTRACE,
61760 + GR_RESOURCE,
61761 + GR_CAP,
61762 + GR_SIG,
61763 + GR_SIG2,
61764 + GR_CRASH1,
61765 + GR_CRASH2,
61766 + GR_PSACCT,
61767 + GR_RWXMAP
61768 +};
61769 +
61770 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61771 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61772 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61773 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61774 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61775 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61776 +#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)
61777 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61778 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61779 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61780 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61781 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61782 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61783 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61784 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61785 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61786 +#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)
61787 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61788 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61789 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61790 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61791 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61792 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61793 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61794 +#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)
61795 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61796 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61797 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61798 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61799 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61800 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61801 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61802 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61803 +#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)
61804 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61805 +
61806 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61807 +
61808 +#endif
61809 +
61810 +#endif
61811 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61812 new file mode 100644
61813 index 0000000..ae576a1
61814 --- /dev/null
61815 +++ b/include/linux/grmsg.h
61816 @@ -0,0 +1,109 @@
61817 +#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"
61818 +#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"
61819 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61820 +#define GR_STOPMOD_MSG "denied modification of module state by "
61821 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61822 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61823 +#define GR_IOPERM_MSG "denied use of ioperm() by "
61824 +#define GR_IOPL_MSG "denied use of iopl() by "
61825 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
61826 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
61827 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
61828 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
61829 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
61830 +#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"
61831 +#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"
61832 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
61833 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
61834 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
61835 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
61836 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
61837 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
61838 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
61839 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
61840 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
61841 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
61842 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
61843 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
61844 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
61845 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
61846 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
61847 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61848 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61849 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61850 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61851 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
61852 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61853 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61854 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61855 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61856 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61857 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61858 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61859 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61860 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61861 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61862 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61863 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61864 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61865 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61866 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61867 +#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"
61868 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
61869 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61870 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61871 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61872 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61873 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61874 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61875 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61876 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61877 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61878 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61879 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61880 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61881 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61882 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61883 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61884 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61885 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61886 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61887 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61888 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
61889 +#define GR_NICE_CHROOT_MSG "denied priority change by "
61890 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61891 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61892 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61893 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61894 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
61895 +#define GR_TIME_MSG "time set by "
61896 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
61897 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
61898 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
61899 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
61900 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
61901 +#define GR_BIND_MSG "denied bind() by "
61902 +#define GR_CONNECT_MSG "denied connect() by "
61903 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
61904 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
61905 +#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"
61906 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
61907 +#define GR_CAP_ACL_MSG "use of %s denied for "
61908 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
61909 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
61910 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
61911 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
61912 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
61913 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
61914 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
61915 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
61916 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
61917 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
61918 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
61919 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
61920 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
61921 +#define GR_VM86_MSG "denied use of vm86 by "
61922 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
61923 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
61924 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
61925 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
61926 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
61927 new file mode 100644
61928 index 0000000..2ccf677
61929 --- /dev/null
61930 +++ b/include/linux/grsecurity.h
61931 @@ -0,0 +1,229 @@
61932 +#ifndef GR_SECURITY_H
61933 +#define GR_SECURITY_H
61934 +#include <linux/fs.h>
61935 +#include <linux/fs_struct.h>
61936 +#include <linux/binfmts.h>
61937 +#include <linux/gracl.h>
61938 +
61939 +/* notify of brain-dead configs */
61940 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61941 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
61942 +#endif
61943 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
61944 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
61945 +#endif
61946 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
61947 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
61948 +#endif
61949 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
61950 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
61951 +#endif
61952 +
61953 +#include <linux/compat.h>
61954 +
61955 +struct user_arg_ptr {
61956 +#ifdef CONFIG_COMPAT
61957 + bool is_compat;
61958 +#endif
61959 + union {
61960 + const char __user *const __user *native;
61961 +#ifdef CONFIG_COMPAT
61962 + compat_uptr_t __user *compat;
61963 +#endif
61964 + } ptr;
61965 +};
61966 +
61967 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
61968 +void gr_handle_brute_check(void);
61969 +void gr_handle_kernel_exploit(void);
61970 +int gr_process_user_ban(void);
61971 +
61972 +char gr_roletype_to_char(void);
61973 +
61974 +int gr_acl_enable_at_secure(void);
61975 +
61976 +int gr_check_user_change(int real, int effective, int fs);
61977 +int gr_check_group_change(int real, int effective, int fs);
61978 +
61979 +void gr_del_task_from_ip_table(struct task_struct *p);
61980 +
61981 +int gr_pid_is_chrooted(struct task_struct *p);
61982 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
61983 +int gr_handle_chroot_nice(void);
61984 +int gr_handle_chroot_sysctl(const int op);
61985 +int gr_handle_chroot_setpriority(struct task_struct *p,
61986 + const int niceval);
61987 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
61988 +int gr_handle_chroot_chroot(const struct dentry *dentry,
61989 + const struct vfsmount *mnt);
61990 +void gr_handle_chroot_chdir(struct path *path);
61991 +int gr_handle_chroot_chmod(const struct dentry *dentry,
61992 + const struct vfsmount *mnt, const int mode);
61993 +int gr_handle_chroot_mknod(const struct dentry *dentry,
61994 + const struct vfsmount *mnt, const int mode);
61995 +int gr_handle_chroot_mount(const struct dentry *dentry,
61996 + const struct vfsmount *mnt,
61997 + const char *dev_name);
61998 +int gr_handle_chroot_pivot(void);
61999 +int gr_handle_chroot_unix(const pid_t pid);
62000 +
62001 +int gr_handle_rawio(const struct inode *inode);
62002 +
62003 +void gr_handle_ioperm(void);
62004 +void gr_handle_iopl(void);
62005 +
62006 +umode_t gr_acl_umask(void);
62007 +
62008 +int gr_tpe_allow(const struct file *file);
62009 +
62010 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62011 +void gr_clear_chroot_entries(struct task_struct *task);
62012 +
62013 +void gr_log_forkfail(const int retval);
62014 +void gr_log_timechange(void);
62015 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62016 +void gr_log_chdir(const struct dentry *dentry,
62017 + const struct vfsmount *mnt);
62018 +void gr_log_chroot_exec(const struct dentry *dentry,
62019 + const struct vfsmount *mnt);
62020 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62021 +void gr_log_remount(const char *devname, const int retval);
62022 +void gr_log_unmount(const char *devname, const int retval);
62023 +void gr_log_mount(const char *from, const char *to, const int retval);
62024 +void gr_log_textrel(struct vm_area_struct *vma);
62025 +void gr_log_rwxmmap(struct file *file);
62026 +void gr_log_rwxmprotect(struct file *file);
62027 +
62028 +int gr_handle_follow_link(const struct inode *parent,
62029 + const struct inode *inode,
62030 + const struct dentry *dentry,
62031 + const struct vfsmount *mnt);
62032 +int gr_handle_fifo(const struct dentry *dentry,
62033 + const struct vfsmount *mnt,
62034 + const struct dentry *dir, const int flag,
62035 + const int acc_mode);
62036 +int gr_handle_hardlink(const struct dentry *dentry,
62037 + const struct vfsmount *mnt,
62038 + struct inode *inode,
62039 + const int mode, const char *to);
62040 +
62041 +int gr_is_capable(const int cap);
62042 +int gr_is_capable_nolog(const int cap);
62043 +void gr_learn_resource(const struct task_struct *task, const int limit,
62044 + const unsigned long wanted, const int gt);
62045 +void gr_copy_label(struct task_struct *tsk);
62046 +void gr_handle_crash(struct task_struct *task, const int sig);
62047 +int gr_handle_signal(const struct task_struct *p, const int sig);
62048 +int gr_check_crash_uid(const uid_t uid);
62049 +int gr_check_protected_task(const struct task_struct *task);
62050 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62051 +int gr_acl_handle_mmap(const struct file *file,
62052 + const unsigned long prot);
62053 +int gr_acl_handle_mprotect(const struct file *file,
62054 + const unsigned long prot);
62055 +int gr_check_hidden_task(const struct task_struct *tsk);
62056 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62057 + const struct vfsmount *mnt);
62058 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62059 + const struct vfsmount *mnt);
62060 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62061 + const struct vfsmount *mnt, const int fmode);
62062 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62063 + const struct vfsmount *mnt, umode_t *mode);
62064 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62065 + const struct vfsmount *mnt);
62066 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62067 + const struct vfsmount *mnt);
62068 +int gr_handle_ptrace(struct task_struct *task, const long request);
62069 +int gr_handle_proc_ptrace(struct task_struct *task);
62070 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62071 + const struct vfsmount *mnt);
62072 +int gr_check_crash_exec(const struct file *filp);
62073 +int gr_acl_is_enabled(void);
62074 +void gr_set_kernel_label(struct task_struct *task);
62075 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62076 + const gid_t gid);
62077 +int gr_set_proc_label(const struct dentry *dentry,
62078 + const struct vfsmount *mnt,
62079 + const int unsafe_flags);
62080 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62081 + const struct vfsmount *mnt);
62082 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62083 + const struct vfsmount *mnt, int acc_mode);
62084 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62085 + const struct dentry *p_dentry,
62086 + const struct vfsmount *p_mnt,
62087 + int open_flags, int acc_mode, const int imode);
62088 +void gr_handle_create(const struct dentry *dentry,
62089 + const struct vfsmount *mnt);
62090 +void gr_handle_proc_create(const struct dentry *dentry,
62091 + const struct inode *inode);
62092 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62093 + const struct dentry *parent_dentry,
62094 + const struct vfsmount *parent_mnt,
62095 + const int mode);
62096 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62097 + const struct dentry *parent_dentry,
62098 + const struct vfsmount *parent_mnt);
62099 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62100 + const struct vfsmount *mnt);
62101 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62102 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62103 + const struct vfsmount *mnt);
62104 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62105 + const struct dentry *parent_dentry,
62106 + const struct vfsmount *parent_mnt,
62107 + const char *from);
62108 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62109 + const struct dentry *parent_dentry,
62110 + const struct vfsmount *parent_mnt,
62111 + const struct dentry *old_dentry,
62112 + const struct vfsmount *old_mnt, const char *to);
62113 +int gr_acl_handle_rename(struct dentry *new_dentry,
62114 + struct dentry *parent_dentry,
62115 + const struct vfsmount *parent_mnt,
62116 + struct dentry *old_dentry,
62117 + struct inode *old_parent_inode,
62118 + struct vfsmount *old_mnt, const char *newname);
62119 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62120 + struct dentry *old_dentry,
62121 + struct dentry *new_dentry,
62122 + struct vfsmount *mnt, const __u8 replace);
62123 +__u32 gr_check_link(const struct dentry *new_dentry,
62124 + const struct dentry *parent_dentry,
62125 + const struct vfsmount *parent_mnt,
62126 + const struct dentry *old_dentry,
62127 + const struct vfsmount *old_mnt);
62128 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62129 + const unsigned int namelen, const ino_t ino);
62130 +
62131 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62132 + const struct vfsmount *mnt);
62133 +void gr_acl_handle_exit(void);
62134 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62135 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62136 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62137 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62138 +void gr_audit_ptrace(struct task_struct *task);
62139 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62140 +
62141 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62142 +
62143 +#ifdef CONFIG_GRKERNSEC
62144 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62145 +void gr_handle_vm86(void);
62146 +void gr_handle_mem_readwrite(u64 from, u64 to);
62147 +
62148 +void gr_log_badprocpid(const char *entry);
62149 +
62150 +extern int grsec_enable_dmesg;
62151 +extern int grsec_disable_privio;
62152 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62153 +extern int grsec_enable_chroot_findtask;
62154 +#endif
62155 +#ifdef CONFIG_GRKERNSEC_SETXID
62156 +extern int grsec_enable_setxid;
62157 +#endif
62158 +#endif
62159 +
62160 +#endif
62161 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62162 new file mode 100644
62163 index 0000000..e7ffaaf
62164 --- /dev/null
62165 +++ b/include/linux/grsock.h
62166 @@ -0,0 +1,19 @@
62167 +#ifndef __GRSOCK_H
62168 +#define __GRSOCK_H
62169 +
62170 +extern void gr_attach_curr_ip(const struct sock *sk);
62171 +extern int gr_handle_sock_all(const int family, const int type,
62172 + const int protocol);
62173 +extern int gr_handle_sock_server(const struct sockaddr *sck);
62174 +extern int gr_handle_sock_server_other(const struct sock *sck);
62175 +extern int gr_handle_sock_client(const struct sockaddr *sck);
62176 +extern int gr_search_connect(struct socket * sock,
62177 + struct sockaddr_in * addr);
62178 +extern int gr_search_bind(struct socket * sock,
62179 + struct sockaddr_in * addr);
62180 +extern int gr_search_listen(struct socket * sock);
62181 +extern int gr_search_accept(struct socket * sock);
62182 +extern int gr_search_socket(const int domain, const int type,
62183 + const int protocol);
62184 +
62185 +#endif
62186 diff --git a/include/linux/hid.h b/include/linux/hid.h
62187 index c235e4e..f0cf7a0 100644
62188 --- a/include/linux/hid.h
62189 +++ b/include/linux/hid.h
62190 @@ -679,7 +679,7 @@ struct hid_ll_driver {
62191 unsigned int code, int value);
62192
62193 int (*parse)(struct hid_device *hdev);
62194 -};
62195 +} __no_const;
62196
62197 #define PM_HINT_FULLON 1<<5
62198 #define PM_HINT_NORMAL 1<<1
62199 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62200 index 3a93f73..b19d0b3 100644
62201 --- a/include/linux/highmem.h
62202 +++ b/include/linux/highmem.h
62203 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
62204 kunmap_atomic(kaddr, KM_USER0);
62205 }
62206
62207 +static inline void sanitize_highpage(struct page *page)
62208 +{
62209 + void *kaddr;
62210 + unsigned long flags;
62211 +
62212 + local_irq_save(flags);
62213 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
62214 + clear_page(kaddr);
62215 + kunmap_atomic(kaddr, KM_CLEARPAGE);
62216 + local_irq_restore(flags);
62217 +}
62218 +
62219 static inline void zero_user_segments(struct page *page,
62220 unsigned start1, unsigned end1,
62221 unsigned start2, unsigned end2)
62222 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62223 index 07d103a..04ec65b 100644
62224 --- a/include/linux/i2c.h
62225 +++ b/include/linux/i2c.h
62226 @@ -364,6 +364,7 @@ struct i2c_algorithm {
62227 /* To determine what the adapter supports */
62228 u32 (*functionality) (struct i2c_adapter *);
62229 };
62230 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62231
62232 /*
62233 * i2c_adapter is the structure used to identify a physical i2c bus along
62234 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62235 index a6deef4..c56a7f2 100644
62236 --- a/include/linux/i2o.h
62237 +++ b/include/linux/i2o.h
62238 @@ -564,7 +564,7 @@ struct i2o_controller {
62239 struct i2o_device *exec; /* Executive */
62240 #if BITS_PER_LONG == 64
62241 spinlock_t context_list_lock; /* lock for context_list */
62242 - atomic_t context_list_counter; /* needed for unique contexts */
62243 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62244 struct list_head context_list; /* list of context id's
62245 and pointers */
62246 #endif
62247 diff --git a/include/linux/init.h b/include/linux/init.h
62248 index 9146f39..885354d 100644
62249 --- a/include/linux/init.h
62250 +++ b/include/linux/init.h
62251 @@ -293,13 +293,13 @@ void __init parse_early_options(char *cmdline);
62252
62253 /* Each module must use one module_init(). */
62254 #define module_init(initfn) \
62255 - static inline initcall_t __inittest(void) \
62256 + static inline __used initcall_t __inittest(void) \
62257 { return initfn; } \
62258 int init_module(void) __attribute__((alias(#initfn)));
62259
62260 /* This is only required if you want to be unloadable. */
62261 #define module_exit(exitfn) \
62262 - static inline exitcall_t __exittest(void) \
62263 + static inline __used exitcall_t __exittest(void) \
62264 { return exitfn; } \
62265 void cleanup_module(void) __attribute__((alias(#exitfn)));
62266
62267 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62268 index 32574ee..00d4ef1 100644
62269 --- a/include/linux/init_task.h
62270 +++ b/include/linux/init_task.h
62271 @@ -128,6 +128,12 @@ extern struct cred init_cred;
62272
62273 #define INIT_TASK_COMM "swapper"
62274
62275 +#ifdef CONFIG_X86
62276 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62277 +#else
62278 +#define INIT_TASK_THREAD_INFO
62279 +#endif
62280 +
62281 /*
62282 * INIT_TASK is used to set up the first task table, touch at
62283 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62284 @@ -166,6 +172,7 @@ extern struct cred init_cred;
62285 RCU_INIT_POINTER(.cred, &init_cred), \
62286 .comm = INIT_TASK_COMM, \
62287 .thread = INIT_THREAD, \
62288 + INIT_TASK_THREAD_INFO \
62289 .fs = &init_fs, \
62290 .files = &init_files, \
62291 .signal = &init_signals, \
62292 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62293 index e6ca56d..8583707 100644
62294 --- a/include/linux/intel-iommu.h
62295 +++ b/include/linux/intel-iommu.h
62296 @@ -296,7 +296,7 @@ struct iommu_flush {
62297 u8 fm, u64 type);
62298 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62299 unsigned int size_order, u64 type);
62300 -};
62301 +} __no_const;
62302
62303 enum {
62304 SR_DMAR_FECTL_REG,
62305 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62306 index a64b00e..464d8bc 100644
62307 --- a/include/linux/interrupt.h
62308 +++ b/include/linux/interrupt.h
62309 @@ -441,7 +441,7 @@ enum
62310 /* map softirq index to softirq name. update 'softirq_to_name' in
62311 * kernel/softirq.c when adding a new softirq.
62312 */
62313 -extern char *softirq_to_name[NR_SOFTIRQS];
62314 +extern const char * const softirq_to_name[NR_SOFTIRQS];
62315
62316 /* softirq mask and active fields moved to irq_cpustat_t in
62317 * asm/hardirq.h to get better cache usage. KAO
62318 @@ -449,12 +449,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62319
62320 struct softirq_action
62321 {
62322 - void (*action)(struct softirq_action *);
62323 + void (*action)(void);
62324 };
62325
62326 asmlinkage void do_softirq(void);
62327 asmlinkage void __do_softirq(void);
62328 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62329 +extern void open_softirq(int nr, void (*action)(void));
62330 extern void softirq_init(void);
62331 static inline void __raise_softirq_irqoff(unsigned int nr)
62332 {
62333 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62334 index 3875719..4cd454c 100644
62335 --- a/include/linux/kallsyms.h
62336 +++ b/include/linux/kallsyms.h
62337 @@ -15,7 +15,8 @@
62338
62339 struct module;
62340
62341 -#ifdef CONFIG_KALLSYMS
62342 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62343 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62344 /* Lookup the address for a symbol. Returns 0 if not found. */
62345 unsigned long kallsyms_lookup_name(const char *name);
62346
62347 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62348 /* Stupid that this does nothing, but I didn't create this mess. */
62349 #define __print_symbol(fmt, addr)
62350 #endif /*CONFIG_KALLSYMS*/
62351 +#else /* when included by kallsyms.c, vsnprintf.c, or
62352 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62353 +extern void __print_symbol(const char *fmt, unsigned long address);
62354 +extern int sprint_backtrace(char *buffer, unsigned long address);
62355 +extern int sprint_symbol(char *buffer, unsigned long address);
62356 +const char *kallsyms_lookup(unsigned long addr,
62357 + unsigned long *symbolsize,
62358 + unsigned long *offset,
62359 + char **modname, char *namebuf);
62360 +#endif
62361
62362 /* This macro allows us to keep printk typechecking */
62363 static __printf(1, 2)
62364 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62365 index fa39183..40160be 100644
62366 --- a/include/linux/kgdb.h
62367 +++ b/include/linux/kgdb.h
62368 @@ -53,7 +53,7 @@ extern int kgdb_connected;
62369 extern int kgdb_io_module_registered;
62370
62371 extern atomic_t kgdb_setting_breakpoint;
62372 -extern atomic_t kgdb_cpu_doing_single_step;
62373 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62374
62375 extern struct task_struct *kgdb_usethread;
62376 extern struct task_struct *kgdb_contthread;
62377 @@ -251,7 +251,7 @@ struct kgdb_arch {
62378 void (*disable_hw_break)(struct pt_regs *regs);
62379 void (*remove_all_hw_break)(void);
62380 void (*correct_hw_break)(void);
62381 -};
62382 +} __do_const;
62383
62384 /**
62385 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62386 @@ -276,7 +276,7 @@ struct kgdb_io {
62387 void (*pre_exception) (void);
62388 void (*post_exception) (void);
62389 int is_console;
62390 -};
62391 +} __do_const;
62392
62393 extern struct kgdb_arch arch_kgdb_ops;
62394
62395 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62396 index b16f653..eb908f4 100644
62397 --- a/include/linux/kmod.h
62398 +++ b/include/linux/kmod.h
62399 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62400 * usually useless though. */
62401 extern __printf(2, 3)
62402 int __request_module(bool wait, const char *name, ...);
62403 +extern __printf(3, 4)
62404 +int ___request_module(bool wait, char *param_name, const char *name, ...);
62405 #define request_module(mod...) __request_module(true, mod)
62406 #define request_module_nowait(mod...) __request_module(false, mod)
62407 #define try_then_request_module(x, mod...) \
62408 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62409 index d526231..c9599fc 100644
62410 --- a/include/linux/kvm_host.h
62411 +++ b/include/linux/kvm_host.h
62412 @@ -308,7 +308,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62413 void vcpu_load(struct kvm_vcpu *vcpu);
62414 void vcpu_put(struct kvm_vcpu *vcpu);
62415
62416 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62417 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62418 struct module *module);
62419 void kvm_exit(void);
62420
62421 @@ -385,20 +385,20 @@ void kvm_get_pfn(pfn_t pfn);
62422 int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
62423 int len);
62424 int kvm_read_guest_atomic(struct kvm *kvm, gpa_t gpa, void *data,
62425 - unsigned long len);
62426 -int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len);
62427 + unsigned long len) __size_overflow(4);
62428 +int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len) __size_overflow(2,4);
62429 int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
62430 - void *data, unsigned long len);
62431 + void *data, unsigned long len) __size_overflow(4);
62432 int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
62433 int offset, int len);
62434 int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
62435 - unsigned long len);
62436 + unsigned long len) __size_overflow(2,4);
62437 int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
62438 - void *data, unsigned long len);
62439 + void *data, unsigned long len) __size_overflow(4);
62440 int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
62441 gpa_t gpa);
62442 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
62443 -int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len);
62444 +int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len) __size_overflow(2,3);
62445 struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
62446 int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn);
62447 unsigned long kvm_host_page_size(struct kvm *kvm, gfn_t gfn);
62448 @@ -454,7 +454,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62449 struct kvm_guest_debug *dbg);
62450 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62451
62452 -int kvm_arch_init(void *opaque);
62453 +int kvm_arch_init(const void *opaque);
62454 void kvm_arch_exit(void);
62455
62456 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62457 @@ -690,7 +690,7 @@ int kvm_setup_default_irq_routing(struct kvm *kvm);
62458 int kvm_set_irq_routing(struct kvm *kvm,
62459 const struct kvm_irq_routing_entry *entries,
62460 unsigned nr,
62461 - unsigned flags);
62462 + unsigned flags) __size_overflow(3);
62463 void kvm_free_irq_routing(struct kvm *kvm);
62464
62465 #else
62466 diff --git a/include/linux/libata.h b/include/linux/libata.h
62467 index cafc09a..d7e7829 100644
62468 --- a/include/linux/libata.h
62469 +++ b/include/linux/libata.h
62470 @@ -909,7 +909,7 @@ struct ata_port_operations {
62471 * fields must be pointers.
62472 */
62473 const struct ata_port_operations *inherits;
62474 -};
62475 +} __do_const;
62476
62477 struct ata_port_info {
62478 unsigned long flags;
62479 diff --git a/include/linux/mca.h b/include/linux/mca.h
62480 index 3797270..7765ede 100644
62481 --- a/include/linux/mca.h
62482 +++ b/include/linux/mca.h
62483 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
62484 int region);
62485 void * (*mca_transform_memory)(struct mca_device *,
62486 void *memory);
62487 -};
62488 +} __no_const;
62489
62490 struct mca_bus {
62491 u64 default_dma_mask;
62492 diff --git a/include/linux/memory.h b/include/linux/memory.h
62493 index 935699b..11042cc 100644
62494 --- a/include/linux/memory.h
62495 +++ b/include/linux/memory.h
62496 @@ -144,7 +144,7 @@ struct memory_accessor {
62497 size_t count);
62498 ssize_t (*write)(struct memory_accessor *, const char *buf,
62499 off_t offset, size_t count);
62500 -};
62501 +} __no_const;
62502
62503 /*
62504 * Kernel text modification mutex, used for code patching. Users of this lock
62505 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62506 index 9970337..9444122 100644
62507 --- a/include/linux/mfd/abx500.h
62508 +++ b/include/linux/mfd/abx500.h
62509 @@ -188,6 +188,7 @@ struct abx500_ops {
62510 int (*event_registers_startup_state_get) (struct device *, u8 *);
62511 int (*startup_irq_enabled) (struct device *, unsigned int);
62512 };
62513 +typedef struct abx500_ops __no_const abx500_ops_no_const;
62514
62515 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62516 void abx500_remove_ops(struct device *dev);
62517 diff --git a/include/linux/mm.h b/include/linux/mm.h
62518 index 4baadd1..2e0b45e 100644
62519 --- a/include/linux/mm.h
62520 +++ b/include/linux/mm.h
62521 @@ -115,7 +115,14 @@ extern unsigned int kobjsize(const void *objp);
62522
62523 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62524 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62525 +
62526 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62527 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62528 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62529 +#else
62530 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62531 +#endif
62532 +
62533 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62534 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62535
62536 @@ -1012,34 +1019,6 @@ int set_page_dirty(struct page *page);
62537 int set_page_dirty_lock(struct page *page);
62538 int clear_page_dirty_for_io(struct page *page);
62539
62540 -/* Is the vma a continuation of the stack vma above it? */
62541 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62542 -{
62543 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62544 -}
62545 -
62546 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
62547 - unsigned long addr)
62548 -{
62549 - return (vma->vm_flags & VM_GROWSDOWN) &&
62550 - (vma->vm_start == addr) &&
62551 - !vma_growsdown(vma->vm_prev, addr);
62552 -}
62553 -
62554 -/* Is the vma a continuation of the stack vma below it? */
62555 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62556 -{
62557 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62558 -}
62559 -
62560 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
62561 - unsigned long addr)
62562 -{
62563 - return (vma->vm_flags & VM_GROWSUP) &&
62564 - (vma->vm_end == addr) &&
62565 - !vma_growsup(vma->vm_next, addr);
62566 -}
62567 -
62568 extern unsigned long move_page_tables(struct vm_area_struct *vma,
62569 unsigned long old_addr, struct vm_area_struct *new_vma,
62570 unsigned long new_addr, unsigned long len);
62571 @@ -1134,6 +1113,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
62572 }
62573 #endif
62574
62575 +#ifdef CONFIG_MMU
62576 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62577 +#else
62578 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62579 +{
62580 + return __pgprot(0);
62581 +}
62582 +#endif
62583 +
62584 int vma_wants_writenotify(struct vm_area_struct *vma);
62585
62586 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62587 @@ -1419,6 +1407,7 @@ out:
62588 }
62589
62590 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62591 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62592
62593 extern unsigned long do_brk(unsigned long, unsigned long);
62594
62595 @@ -1476,6 +1465,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62596 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62597 struct vm_area_struct **pprev);
62598
62599 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62600 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62601 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62602 +
62603 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62604 NULL if none. Assume start_addr < end_addr. */
62605 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62606 @@ -1492,15 +1485,6 @@ static inline unsigned long vma_pages(struct vm_area_struct *vma)
62607 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
62608 }
62609
62610 -#ifdef CONFIG_MMU
62611 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
62612 -#else
62613 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62614 -{
62615 - return __pgprot(0);
62616 -}
62617 -#endif
62618 -
62619 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62620 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62621 unsigned long pfn, unsigned long size, pgprot_t);
62622 @@ -1614,7 +1598,7 @@ extern int unpoison_memory(unsigned long pfn);
62623 extern int sysctl_memory_failure_early_kill;
62624 extern int sysctl_memory_failure_recovery;
62625 extern void shake_page(struct page *p, int access);
62626 -extern atomic_long_t mce_bad_pages;
62627 +extern atomic_long_unchecked_t mce_bad_pages;
62628 extern int soft_offline_page(struct page *page, int flags);
62629
62630 extern void dump_page(struct page *page);
62631 @@ -1628,5 +1612,11 @@ extern void copy_user_huge_page(struct page *dst, struct page *src,
62632 unsigned int pages_per_huge_page);
62633 #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
62634
62635 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62636 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62637 +#else
62638 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62639 +#endif
62640 +
62641 #endif /* __KERNEL__ */
62642 #endif /* _LINUX_MM_H */
62643 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62644 index 5b42f1b..759e4b4 100644
62645 --- a/include/linux/mm_types.h
62646 +++ b/include/linux/mm_types.h
62647 @@ -253,6 +253,8 @@ struct vm_area_struct {
62648 #ifdef CONFIG_NUMA
62649 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62650 #endif
62651 +
62652 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62653 };
62654
62655 struct core_thread {
62656 @@ -389,6 +391,24 @@ struct mm_struct {
62657 #ifdef CONFIG_CPUMASK_OFFSTACK
62658 struct cpumask cpumask_allocation;
62659 #endif
62660 +
62661 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62662 + unsigned long pax_flags;
62663 +#endif
62664 +
62665 +#ifdef CONFIG_PAX_DLRESOLVE
62666 + unsigned long call_dl_resolve;
62667 +#endif
62668 +
62669 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
62670 + unsigned long call_syscall;
62671 +#endif
62672 +
62673 +#ifdef CONFIG_PAX_ASLR
62674 + unsigned long delta_mmap; /* randomized offset */
62675 + unsigned long delta_stack; /* randomized offset */
62676 +#endif
62677 +
62678 };
62679
62680 static inline void mm_init_cpumask(struct mm_struct *mm)
62681 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
62682 index 1d1b1e1..2a13c78 100644
62683 --- a/include/linux/mmu_notifier.h
62684 +++ b/include/linux/mmu_notifier.h
62685 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62686 */
62687 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62688 ({ \
62689 - pte_t __pte; \
62690 + pte_t ___pte; \
62691 struct vm_area_struct *___vma = __vma; \
62692 unsigned long ___address = __address; \
62693 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62694 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62695 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62696 - __pte; \
62697 + ___pte; \
62698 })
62699
62700 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62701 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62702 index 188cb2f..d78409b 100644
62703 --- a/include/linux/mmzone.h
62704 +++ b/include/linux/mmzone.h
62705 @@ -369,7 +369,7 @@ struct zone {
62706 unsigned long flags; /* zone flags, see below */
62707
62708 /* Zone statistics */
62709 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62710 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62711
62712 /*
62713 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62714 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62715 index 468819c..17b9db3 100644
62716 --- a/include/linux/mod_devicetable.h
62717 +++ b/include/linux/mod_devicetable.h
62718 @@ -12,7 +12,7 @@
62719 typedef unsigned long kernel_ulong_t;
62720 #endif
62721
62722 -#define PCI_ANY_ID (~0)
62723 +#define PCI_ANY_ID ((__u16)~0)
62724
62725 struct pci_device_id {
62726 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62727 @@ -131,7 +131,7 @@ struct usb_device_id {
62728 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
62729 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
62730
62731 -#define HID_ANY_ID (~0)
62732 +#define HID_ANY_ID (~0U)
62733
62734 struct hid_device_id {
62735 __u16 bus;
62736 diff --git a/include/linux/module.h b/include/linux/module.h
62737 index 3cb7839..511cb87 100644
62738 --- a/include/linux/module.h
62739 +++ b/include/linux/module.h
62740 @@ -17,6 +17,7 @@
62741 #include <linux/moduleparam.h>
62742 #include <linux/tracepoint.h>
62743 #include <linux/export.h>
62744 +#include <linux/fs.h>
62745
62746 #include <linux/percpu.h>
62747 #include <asm/module.h>
62748 @@ -261,19 +262,16 @@ struct module
62749 int (*init)(void);
62750
62751 /* If this is non-NULL, vfree after init() returns */
62752 - void *module_init;
62753 + void *module_init_rx, *module_init_rw;
62754
62755 /* Here is the actual code + data, vfree'd on unload. */
62756 - void *module_core;
62757 + void *module_core_rx, *module_core_rw;
62758
62759 /* Here are the sizes of the init and core sections */
62760 - unsigned int init_size, core_size;
62761 + unsigned int init_size_rw, core_size_rw;
62762
62763 /* The size of the executable code in each section. */
62764 - unsigned int init_text_size, core_text_size;
62765 -
62766 - /* Size of RO sections of the module (text+rodata) */
62767 - unsigned int init_ro_size, core_ro_size;
62768 + unsigned int init_size_rx, core_size_rx;
62769
62770 /* Arch-specific module values */
62771 struct mod_arch_specific arch;
62772 @@ -329,6 +327,10 @@ struct module
62773 #ifdef CONFIG_EVENT_TRACING
62774 struct ftrace_event_call **trace_events;
62775 unsigned int num_trace_events;
62776 + struct file_operations trace_id;
62777 + struct file_operations trace_enable;
62778 + struct file_operations trace_format;
62779 + struct file_operations trace_filter;
62780 #endif
62781 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62782 unsigned int num_ftrace_callsites;
62783 @@ -379,16 +381,46 @@ bool is_module_address(unsigned long addr);
62784 bool is_module_percpu_address(unsigned long addr);
62785 bool is_module_text_address(unsigned long addr);
62786
62787 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62788 +{
62789 +
62790 +#ifdef CONFIG_PAX_KERNEXEC
62791 + if (ktla_ktva(addr) >= (unsigned long)start &&
62792 + ktla_ktva(addr) < (unsigned long)start + size)
62793 + return 1;
62794 +#endif
62795 +
62796 + return ((void *)addr >= start && (void *)addr < start + size);
62797 +}
62798 +
62799 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
62800 +{
62801 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
62802 +}
62803 +
62804 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
62805 +{
62806 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
62807 +}
62808 +
62809 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
62810 +{
62811 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
62812 +}
62813 +
62814 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
62815 +{
62816 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
62817 +}
62818 +
62819 static inline int within_module_core(unsigned long addr, struct module *mod)
62820 {
62821 - return (unsigned long)mod->module_core <= addr &&
62822 - addr < (unsigned long)mod->module_core + mod->core_size;
62823 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62824 }
62825
62826 static inline int within_module_init(unsigned long addr, struct module *mod)
62827 {
62828 - return (unsigned long)mod->module_init <= addr &&
62829 - addr < (unsigned long)mod->module_init + mod->init_size;
62830 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62831 }
62832
62833 /* Search for module by name: must hold module_mutex. */
62834 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62835 index b2be02e..edb10c9 100644
62836 --- a/include/linux/moduleloader.h
62837 +++ b/include/linux/moduleloader.h
62838 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62839
62840 /* Allocator used for allocating struct module, core sections and init
62841 sections. Returns NULL on failure. */
62842 -void *module_alloc(unsigned long size);
62843 +void *module_alloc(unsigned long size) __size_overflow(1);
62844 +
62845 +#ifdef CONFIG_PAX_KERNEXEC
62846 +void *module_alloc_exec(unsigned long size);
62847 +#else
62848 +#define module_alloc_exec(x) module_alloc(x)
62849 +#endif
62850
62851 /* Free memory returned from module_alloc. */
62852 void module_free(struct module *mod, void *module_region);
62853
62854 +#ifdef CONFIG_PAX_KERNEXEC
62855 +void module_free_exec(struct module *mod, void *module_region);
62856 +#else
62857 +#define module_free_exec(x, y) module_free((x), (y))
62858 +#endif
62859 +
62860 /* Apply the given relocation to the (simplified) ELF. Return -error
62861 or 0. */
62862 int apply_relocate(Elf_Shdr *sechdrs,
62863 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
62864 index 7939f63..ec6df57 100644
62865 --- a/include/linux/moduleparam.h
62866 +++ b/include/linux/moduleparam.h
62867 @@ -260,7 +260,7 @@ static inline void __kernel_param_unlock(void)
62868 * @len is usually just sizeof(string).
62869 */
62870 #define module_param_string(name, string, len, perm) \
62871 - static const struct kparam_string __param_string_##name \
62872 + static const struct kparam_string __param_string_##name __used \
62873 = { len, string }; \
62874 __module_param_call(MODULE_PARAM_PREFIX, name, \
62875 &param_ops_string, \
62876 @@ -395,7 +395,7 @@ extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
62877 * module_param_named() for why this might be necessary.
62878 */
62879 #define module_param_array_named(name, array, type, nump, perm) \
62880 - static const struct kparam_array __param_arr_##name \
62881 + static const struct kparam_array __param_arr_##name __used \
62882 = { .max = ARRAY_SIZE(array), .num = nump, \
62883 .ops = &param_ops_##type, \
62884 .elemsize = sizeof(array[0]), .elem = array }; \
62885 diff --git a/include/linux/mtd/map.h b/include/linux/mtd/map.h
62886 index a9e6ba4..0f9e29b 100644
62887 --- a/include/linux/mtd/map.h
62888 +++ b/include/linux/mtd/map.h
62889 @@ -25,6 +25,7 @@
62890 #include <linux/types.h>
62891 #include <linux/list.h>
62892 #include <linux/string.h>
62893 +#include <linux/kernel.h>
62894 #include <linux/bug.h>
62895
62896
62897 diff --git a/include/linux/namei.h b/include/linux/namei.h
62898 index ffc0213..2c1f2cb 100644
62899 --- a/include/linux/namei.h
62900 +++ b/include/linux/namei.h
62901 @@ -24,7 +24,7 @@ struct nameidata {
62902 unsigned seq;
62903 int last_type;
62904 unsigned depth;
62905 - char *saved_names[MAX_NESTED_LINKS + 1];
62906 + const char *saved_names[MAX_NESTED_LINKS + 1];
62907
62908 /* Intent data */
62909 union {
62910 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
62911 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
62912 extern void unlock_rename(struct dentry *, struct dentry *);
62913
62914 -static inline void nd_set_link(struct nameidata *nd, char *path)
62915 +static inline void nd_set_link(struct nameidata *nd, const char *path)
62916 {
62917 nd->saved_names[nd->depth] = path;
62918 }
62919
62920 -static inline char *nd_get_link(struct nameidata *nd)
62921 +static inline const char *nd_get_link(const struct nameidata *nd)
62922 {
62923 return nd->saved_names[nd->depth];
62924 }
62925 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
62926 index a82ad4d..90d15b7 100644
62927 --- a/include/linux/netdevice.h
62928 +++ b/include/linux/netdevice.h
62929 @@ -949,6 +949,7 @@ struct net_device_ops {
62930 int (*ndo_set_features)(struct net_device *dev,
62931 u32 features);
62932 };
62933 +typedef struct net_device_ops __no_const net_device_ops_no_const;
62934
62935 /*
62936 * The DEVICE structure.
62937 @@ -1088,7 +1089,7 @@ struct net_device {
62938 int iflink;
62939
62940 struct net_device_stats stats;
62941 - atomic_long_t rx_dropped; /* dropped packets by core network
62942 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
62943 * Do not use this in drivers.
62944 */
62945
62946 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
62947 new file mode 100644
62948 index 0000000..33f4af8
62949 --- /dev/null
62950 +++ b/include/linux/netfilter/xt_gradm.h
62951 @@ -0,0 +1,9 @@
62952 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
62953 +#define _LINUX_NETFILTER_XT_GRADM_H 1
62954 +
62955 +struct xt_gradm_mtinfo {
62956 + __u16 flags;
62957 + __u16 invflags;
62958 +};
62959 +
62960 +#endif
62961 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
62962 index c65a18a..0c05f3a 100644
62963 --- a/include/linux/of_pdt.h
62964 +++ b/include/linux/of_pdt.h
62965 @@ -32,7 +32,7 @@ struct of_pdt_ops {
62966
62967 /* return 0 on success; fill in 'len' with number of bytes in path */
62968 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
62969 -};
62970 +} __no_const;
62971
62972 extern void *prom_early_alloc(unsigned long size);
62973
62974 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
62975 index a4c5624..2dabfb7 100644
62976 --- a/include/linux/oprofile.h
62977 +++ b/include/linux/oprofile.h
62978 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
62979 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
62980 char const * name, ulong * val);
62981
62982 -/** Create a file for read-only access to an atomic_t. */
62983 +/** Create a file for read-only access to an atomic_unchecked_t. */
62984 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
62985 - char const * name, atomic_t * val);
62986 + char const * name, atomic_unchecked_t * val);
62987
62988 /** create a directory */
62989 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
62990 @@ -163,7 +163,7 @@ ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user * buf, size_t co
62991 * Read an ASCII string for a number from a userspace buffer and fill *val on success.
62992 * Returns 0 on success, < 0 on error.
62993 */
62994 -int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count);
62995 +int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count) __size_overflow(3);
62996
62997 /** lock for read/write safety */
62998 extern raw_spinlock_t oprofilefs_lock;
62999 diff --git a/include/linux/padata.h b/include/linux/padata.h
63000 index 4633b2f..988bc08 100644
63001 --- a/include/linux/padata.h
63002 +++ b/include/linux/padata.h
63003 @@ -129,7 +129,7 @@ struct parallel_data {
63004 struct padata_instance *pinst;
63005 struct padata_parallel_queue __percpu *pqueue;
63006 struct padata_serial_queue __percpu *squeue;
63007 - atomic_t seq_nr;
63008 + atomic_unchecked_t seq_nr;
63009 atomic_t reorder_objects;
63010 atomic_t refcnt;
63011 unsigned int max_seq_nr;
63012 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63013 index b1f8912..c955bff 100644
63014 --- a/include/linux/perf_event.h
63015 +++ b/include/linux/perf_event.h
63016 @@ -748,8 +748,8 @@ struct perf_event {
63017
63018 enum perf_event_active_state state;
63019 unsigned int attach_state;
63020 - local64_t count;
63021 - atomic64_t child_count;
63022 + local64_t count; /* PaX: fix it one day */
63023 + atomic64_unchecked_t child_count;
63024
63025 /*
63026 * These are the total time in nanoseconds that the event
63027 @@ -800,8 +800,8 @@ struct perf_event {
63028 * These accumulate total time (in nanoseconds) that children
63029 * events have been enabled and running, respectively.
63030 */
63031 - atomic64_t child_total_time_enabled;
63032 - atomic64_t child_total_time_running;
63033 + atomic64_unchecked_t child_total_time_enabled;
63034 + atomic64_unchecked_t child_total_time_running;
63035
63036 /*
63037 * Protect attach/detach and child_list:
63038 diff --git a/include/linux/personality.h b/include/linux/personality.h
63039 index 8fc7dd1a..c19d89e 100644
63040 --- a/include/linux/personality.h
63041 +++ b/include/linux/personality.h
63042 @@ -44,6 +44,7 @@ enum {
63043 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63044 ADDR_NO_RANDOMIZE | \
63045 ADDR_COMPAT_LAYOUT | \
63046 + ADDR_LIMIT_3GB | \
63047 MMAP_PAGE_ZERO)
63048
63049 /*
63050 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63051 index 77257c9..51d473a 100644
63052 --- a/include/linux/pipe_fs_i.h
63053 +++ b/include/linux/pipe_fs_i.h
63054 @@ -46,9 +46,9 @@ struct pipe_buffer {
63055 struct pipe_inode_info {
63056 wait_queue_head_t wait;
63057 unsigned int nrbufs, curbuf, buffers;
63058 - unsigned int readers;
63059 - unsigned int writers;
63060 - unsigned int waiting_writers;
63061 + atomic_t readers;
63062 + atomic_t writers;
63063 + atomic_t waiting_writers;
63064 unsigned int r_counter;
63065 unsigned int w_counter;
63066 struct page *tmp_page;
63067 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63068 index d3085e7..fd01052 100644
63069 --- a/include/linux/pm_runtime.h
63070 +++ b/include/linux/pm_runtime.h
63071 @@ -95,7 +95,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63072
63073 static inline void pm_runtime_mark_last_busy(struct device *dev)
63074 {
63075 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63076 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63077 }
63078
63079 #else /* !CONFIG_PM_RUNTIME */
63080 diff --git a/include/linux/poison.h b/include/linux/poison.h
63081 index 79159de..f1233a9 100644
63082 --- a/include/linux/poison.h
63083 +++ b/include/linux/poison.h
63084 @@ -19,8 +19,8 @@
63085 * under normal circumstances, used to verify that nobody uses
63086 * non-initialized list entries.
63087 */
63088 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63089 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63090 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63091 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63092
63093 /********** include/linux/timer.h **********/
63094 /*
63095 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63096 index 58969b2..ead129b 100644
63097 --- a/include/linux/preempt.h
63098 +++ b/include/linux/preempt.h
63099 @@ -123,7 +123,7 @@ struct preempt_ops {
63100 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63101 void (*sched_out)(struct preempt_notifier *notifier,
63102 struct task_struct *next);
63103 -};
63104 +} __no_const;
63105
63106 /**
63107 * preempt_notifier - key for installing preemption notifiers
63108 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63109 index 643b96c..ef55a9c 100644
63110 --- a/include/linux/proc_fs.h
63111 +++ b/include/linux/proc_fs.h
63112 @@ -155,6 +155,19 @@ static inline struct proc_dir_entry *proc_create(const char *name, mode_t mode,
63113 return proc_create_data(name, mode, parent, proc_fops, NULL);
63114 }
63115
63116 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
63117 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63118 +{
63119 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63120 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63121 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63122 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63123 +#else
63124 + return proc_create_data(name, mode, parent, proc_fops, NULL);
63125 +#endif
63126 +}
63127 +
63128 +
63129 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63130 mode_t mode, struct proc_dir_entry *base,
63131 read_proc_t *read_proc, void * data)
63132 @@ -258,7 +271,7 @@ union proc_op {
63133 int (*proc_show)(struct seq_file *m,
63134 struct pid_namespace *ns, struct pid *pid,
63135 struct task_struct *task);
63136 -};
63137 +} __no_const;
63138
63139 struct ctl_table_header;
63140 struct ctl_table;
63141 diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
63142 index 800f113..e9ee2e3 100644
63143 --- a/include/linux/ptrace.h
63144 +++ b/include/linux/ptrace.h
63145 @@ -129,10 +129,12 @@ extern void __ptrace_unlink(struct task_struct *child);
63146 extern void exit_ptrace(struct task_struct *tracer);
63147 #define PTRACE_MODE_READ 1
63148 #define PTRACE_MODE_ATTACH 2
63149 -/* Returns 0 on success, -errno on denial. */
63150 -extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
63151 /* Returns true on success, false on denial. */
63152 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
63153 +/* Returns true on success, false on denial. */
63154 +extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
63155 +/* Returns true on success, false on denial. */
63156 +extern bool ptrace_may_access_nolock(struct task_struct *task, unsigned int mode);
63157
63158 static inline int ptrace_reparented(struct task_struct *child)
63159 {
63160 diff --git a/include/linux/random.h b/include/linux/random.h
63161 index 8f74538..02a1012 100644
63162 --- a/include/linux/random.h
63163 +++ b/include/linux/random.h
63164 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
63165
63166 u32 prandom32(struct rnd_state *);
63167
63168 +static inline unsigned long pax_get_random_long(void)
63169 +{
63170 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63171 +}
63172 +
63173 /*
63174 * Handle minimum values for seeds
63175 */
63176 static inline u32 __seed(u32 x, u32 m)
63177 {
63178 - return (x < m) ? x + m : x;
63179 + return (x <= m) ? x + m + 1 : x;
63180 }
63181
63182 /**
63183 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63184 index e0879a7..a12f962 100644
63185 --- a/include/linux/reboot.h
63186 +++ b/include/linux/reboot.h
63187 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63188 * Architecture-specific implementations of sys_reboot commands.
63189 */
63190
63191 -extern void machine_restart(char *cmd);
63192 -extern void machine_halt(void);
63193 -extern void machine_power_off(void);
63194 +extern void machine_restart(char *cmd) __noreturn;
63195 +extern void machine_halt(void) __noreturn;
63196 +extern void machine_power_off(void) __noreturn;
63197
63198 extern void machine_shutdown(void);
63199 struct pt_regs;
63200 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63201 */
63202
63203 extern void kernel_restart_prepare(char *cmd);
63204 -extern void kernel_restart(char *cmd);
63205 -extern void kernel_halt(void);
63206 -extern void kernel_power_off(void);
63207 +extern void kernel_restart(char *cmd) __noreturn;
63208 +extern void kernel_halt(void) __noreturn;
63209 +extern void kernel_power_off(void) __noreturn;
63210
63211 extern int C_A_D; /* for sysctl */
63212 void ctrl_alt_del(void);
63213 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63214 * Emergency restart, callable from an interrupt handler.
63215 */
63216
63217 -extern void emergency_restart(void);
63218 +extern void emergency_restart(void) __noreturn;
63219 #include <asm/emergency-restart.h>
63220
63221 #endif
63222 diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
63223 index 96d465f..b084e05 100644
63224 --- a/include/linux/reiserfs_fs.h
63225 +++ b/include/linux/reiserfs_fs.h
63226 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
63227 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
63228
63229 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
63230 -#define get_generation(s) atomic_read (&fs_generation(s))
63231 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
63232 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
63233 #define __fs_changed(gen,s) (gen != get_generation (s))
63234 #define fs_changed(gen,s) \
63235 diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
63236 index 52c83b6..18ed7eb 100644
63237 --- a/include/linux/reiserfs_fs_sb.h
63238 +++ b/include/linux/reiserfs_fs_sb.h
63239 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
63240 /* Comment? -Hans */
63241 wait_queue_head_t s_wait;
63242 /* To be obsoleted soon by per buffer seals.. -Hans */
63243 - atomic_t s_generation_counter; // increased by one every time the
63244 + atomic_unchecked_t s_generation_counter; // increased by one every time the
63245 // tree gets re-balanced
63246 unsigned long s_properties; /* File system properties. Currently holds
63247 on-disk FS format */
63248 diff --git a/include/linux/relay.h b/include/linux/relay.h
63249 index 14a86bc..17d0700 100644
63250 --- a/include/linux/relay.h
63251 +++ b/include/linux/relay.h
63252 @@ -159,7 +159,7 @@ struct rchan_callbacks
63253 * The callback should return 0 if successful, negative if not.
63254 */
63255 int (*remove_buf_file)(struct dentry *dentry);
63256 -};
63257 +} __no_const;
63258
63259 /*
63260 * CONFIG_RELAY kernel API, kernel/relay.c
63261 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63262 index c6c6084..5bf1212 100644
63263 --- a/include/linux/rfkill.h
63264 +++ b/include/linux/rfkill.h
63265 @@ -147,6 +147,7 @@ struct rfkill_ops {
63266 void (*query)(struct rfkill *rfkill, void *data);
63267 int (*set_block)(void *data, bool blocked);
63268 };
63269 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63270
63271 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63272 /**
63273 diff --git a/include/linux/rio.h b/include/linux/rio.h
63274 index 4d50611..c6858a2 100644
63275 --- a/include/linux/rio.h
63276 +++ b/include/linux/rio.h
63277 @@ -315,7 +315,7 @@ struct rio_ops {
63278 int mbox, void *buffer, size_t len);
63279 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63280 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63281 -};
63282 +} __no_const;
63283
63284 #define RIO_RESOURCE_MEM 0x00000100
63285 #define RIO_RESOURCE_DOORBELL 0x00000200
63286 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63287 index 2148b12..519b820 100644
63288 --- a/include/linux/rmap.h
63289 +++ b/include/linux/rmap.h
63290 @@ -119,8 +119,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63291 void anon_vma_init(void); /* create anon_vma_cachep */
63292 int anon_vma_prepare(struct vm_area_struct *);
63293 void unlink_anon_vmas(struct vm_area_struct *);
63294 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63295 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63296 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63297 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63298 void __anon_vma_link(struct vm_area_struct *);
63299
63300 static inline void anon_vma_merge(struct vm_area_struct *vma,
63301 diff --git a/include/linux/sched.h b/include/linux/sched.h
63302 index 1c4f3e9..342eb1f 100644
63303 --- a/include/linux/sched.h
63304 +++ b/include/linux/sched.h
63305 @@ -101,6 +101,7 @@ struct bio_list;
63306 struct fs_struct;
63307 struct perf_event_context;
63308 struct blk_plug;
63309 +struct linux_binprm;
63310
63311 /*
63312 * List of flags we want to share for kernel threads,
63313 @@ -380,10 +381,13 @@ struct user_namespace;
63314 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63315
63316 extern int sysctl_max_map_count;
63317 +extern unsigned long sysctl_heap_stack_gap;
63318
63319 #include <linux/aio.h>
63320
63321 #ifdef CONFIG_MMU
63322 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63323 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63324 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63325 extern unsigned long
63326 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63327 @@ -629,6 +633,17 @@ struct signal_struct {
63328 #ifdef CONFIG_TASKSTATS
63329 struct taskstats *stats;
63330 #endif
63331 +
63332 +#ifdef CONFIG_GRKERNSEC
63333 + u32 curr_ip;
63334 + u32 saved_ip;
63335 + u32 gr_saddr;
63336 + u32 gr_daddr;
63337 + u16 gr_sport;
63338 + u16 gr_dport;
63339 + u8 used_accept:1;
63340 +#endif
63341 +
63342 #ifdef CONFIG_AUDIT
63343 unsigned audit_tty;
63344 struct tty_audit_buf *tty_audit_buf;
63345 @@ -710,6 +725,11 @@ struct user_struct {
63346 struct key *session_keyring; /* UID's default session keyring */
63347 #endif
63348
63349 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63350 + unsigned int banned;
63351 + unsigned long ban_expires;
63352 +#endif
63353 +
63354 /* Hash table maintenance information */
63355 struct hlist_node uidhash_node;
63356 uid_t uid;
63357 @@ -1337,8 +1357,8 @@ struct task_struct {
63358 struct list_head thread_group;
63359
63360 struct completion *vfork_done; /* for vfork() */
63361 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63362 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63363 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63364 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63365
63366 cputime_t utime, stime, utimescaled, stimescaled;
63367 cputime_t gtime;
63368 @@ -1354,13 +1374,6 @@ struct task_struct {
63369 struct task_cputime cputime_expires;
63370 struct list_head cpu_timers[3];
63371
63372 -/* process credentials */
63373 - const struct cred __rcu *real_cred; /* objective and real subjective task
63374 - * credentials (COW) */
63375 - const struct cred __rcu *cred; /* effective (overridable) subjective task
63376 - * credentials (COW) */
63377 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63378 -
63379 char comm[TASK_COMM_LEN]; /* executable name excluding path
63380 - access with [gs]et_task_comm (which lock
63381 it with task_lock())
63382 @@ -1377,8 +1390,16 @@ struct task_struct {
63383 #endif
63384 /* CPU-specific state of this task */
63385 struct thread_struct thread;
63386 +/* thread_info moved to task_struct */
63387 +#ifdef CONFIG_X86
63388 + struct thread_info tinfo;
63389 +#endif
63390 /* filesystem information */
63391 struct fs_struct *fs;
63392 +
63393 + const struct cred __rcu *cred; /* effective (overridable) subjective task
63394 + * credentials (COW) */
63395 +
63396 /* open file information */
63397 struct files_struct *files;
63398 /* namespaces */
63399 @@ -1425,6 +1446,11 @@ struct task_struct {
63400 struct rt_mutex_waiter *pi_blocked_on;
63401 #endif
63402
63403 +/* process credentials */
63404 + const struct cred __rcu *real_cred; /* objective and real subjective task
63405 + * credentials (COW) */
63406 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63407 +
63408 #ifdef CONFIG_DEBUG_MUTEXES
63409 /* mutex deadlock detection */
63410 struct mutex_waiter *blocked_on;
63411 @@ -1540,6 +1566,27 @@ struct task_struct {
63412 unsigned long default_timer_slack_ns;
63413
63414 struct list_head *scm_work_list;
63415 +
63416 +#ifdef CONFIG_GRKERNSEC
63417 + /* grsecurity */
63418 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63419 + u64 exec_id;
63420 +#endif
63421 +#ifdef CONFIG_GRKERNSEC_SETXID
63422 + const struct cred *delayed_cred;
63423 +#endif
63424 + struct dentry *gr_chroot_dentry;
63425 + struct acl_subject_label *acl;
63426 + struct acl_role_label *role;
63427 + struct file *exec_file;
63428 + u16 acl_role_id;
63429 + /* is this the task that authenticated to the special role */
63430 + u8 acl_sp_role;
63431 + u8 is_writable;
63432 + u8 brute;
63433 + u8 gr_is_chrooted;
63434 +#endif
63435 +
63436 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63437 /* Index of current stored address in ret_stack */
63438 int curr_ret_stack;
63439 @@ -1574,6 +1621,51 @@ struct task_struct {
63440 #endif
63441 };
63442
63443 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63444 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63445 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63446 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63447 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63448 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63449 +
63450 +#ifdef CONFIG_PAX_SOFTMODE
63451 +extern int pax_softmode;
63452 +#endif
63453 +
63454 +extern int pax_check_flags(unsigned long *);
63455 +
63456 +/* if tsk != current then task_lock must be held on it */
63457 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63458 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
63459 +{
63460 + if (likely(tsk->mm))
63461 + return tsk->mm->pax_flags;
63462 + else
63463 + return 0UL;
63464 +}
63465 +
63466 +/* if tsk != current then task_lock must be held on it */
63467 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63468 +{
63469 + if (likely(tsk->mm)) {
63470 + tsk->mm->pax_flags = flags;
63471 + return 0;
63472 + }
63473 + return -EINVAL;
63474 +}
63475 +#endif
63476 +
63477 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63478 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
63479 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63480 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63481 +#endif
63482 +
63483 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63484 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63485 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
63486 +extern __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
63487 +
63488 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63489 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63490
63491 @@ -2081,7 +2173,9 @@ void yield(void);
63492 extern struct exec_domain default_exec_domain;
63493
63494 union thread_union {
63495 +#ifndef CONFIG_X86
63496 struct thread_info thread_info;
63497 +#endif
63498 unsigned long stack[THREAD_SIZE/sizeof(long)];
63499 };
63500
63501 @@ -2114,6 +2208,7 @@ extern struct pid_namespace init_pid_ns;
63502 */
63503
63504 extern struct task_struct *find_task_by_vpid(pid_t nr);
63505 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63506 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63507 struct pid_namespace *ns);
63508
63509 @@ -2235,6 +2330,12 @@ static inline void mmdrop(struct mm_struct * mm)
63510 extern void mmput(struct mm_struct *);
63511 /* Grab a reference to a task's mm, if it is not already going away */
63512 extern struct mm_struct *get_task_mm(struct task_struct *task);
63513 +/*
63514 + * Grab a reference to a task's mm, if it is not already going away
63515 + * and ptrace_may_access with the mode parameter passed to it
63516 + * succeeds.
63517 + */
63518 +extern struct mm_struct *mm_access(struct task_struct *task, unsigned int mode);
63519 /* Remove the current tasks stale references to the old mm_struct */
63520 extern void mm_release(struct task_struct *, struct mm_struct *);
63521 /* Allocate a new mm structure and copy contents from tsk->mm */
63522 @@ -2251,7 +2352,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63523 extern void exit_itimers(struct signal_struct *);
63524 extern void flush_itimer_signals(void);
63525
63526 -extern NORET_TYPE void do_group_exit(int);
63527 +extern __noreturn void do_group_exit(int);
63528
63529 extern void daemonize(const char *, ...);
63530 extern int allow_signal(int);
63531 @@ -2416,13 +2517,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63532
63533 #endif
63534
63535 -static inline int object_is_on_stack(void *obj)
63536 +static inline int object_starts_on_stack(void *obj)
63537 {
63538 - void *stack = task_stack_page(current);
63539 + const void *stack = task_stack_page(current);
63540
63541 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63542 }
63543
63544 +#ifdef CONFIG_PAX_USERCOPY
63545 +extern int object_is_on_stack(const void *obj, unsigned long len);
63546 +#endif
63547 +
63548 extern void thread_info_cache_init(void);
63549
63550 #ifdef CONFIG_DEBUG_STACK_USAGE
63551 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63552 index 899fbb4..1cb4138 100644
63553 --- a/include/linux/screen_info.h
63554 +++ b/include/linux/screen_info.h
63555 @@ -43,7 +43,8 @@ struct screen_info {
63556 __u16 pages; /* 0x32 */
63557 __u16 vesa_attributes; /* 0x34 */
63558 __u32 capabilities; /* 0x36 */
63559 - __u8 _reserved[6]; /* 0x3a */
63560 + __u16 vesapm_size; /* 0x3a */
63561 + __u8 _reserved[4]; /* 0x3c */
63562 } __attribute__((packed));
63563
63564 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63565 diff --git a/include/linux/security.h b/include/linux/security.h
63566 index e8c619d..e0cbd1c 100644
63567 --- a/include/linux/security.h
63568 +++ b/include/linux/security.h
63569 @@ -37,6 +37,7 @@
63570 #include <linux/xfrm.h>
63571 #include <linux/slab.h>
63572 #include <linux/xattr.h>
63573 +#include <linux/grsecurity.h>
63574 #include <net/flow.h>
63575
63576 /* Maximum number of letters for an LSM name string */
63577 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63578 index 0b69a46..b2ffa4c 100644
63579 --- a/include/linux/seq_file.h
63580 +++ b/include/linux/seq_file.h
63581 @@ -24,6 +24,9 @@ struct seq_file {
63582 struct mutex lock;
63583 const struct seq_operations *op;
63584 int poll_event;
63585 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63586 + u64 exec_id;
63587 +#endif
63588 void *private;
63589 };
63590
63591 @@ -33,6 +36,7 @@ struct seq_operations {
63592 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63593 int (*show) (struct seq_file *m, void *v);
63594 };
63595 +typedef struct seq_operations __no_const seq_operations_no_const;
63596
63597 #define SEQ_SKIP 1
63598
63599 diff --git a/include/linux/shm.h b/include/linux/shm.h
63600 index 92808b8..c28cac4 100644
63601 --- a/include/linux/shm.h
63602 +++ b/include/linux/shm.h
63603 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63604
63605 /* The task created the shm object. NULL if the task is dead. */
63606 struct task_struct *shm_creator;
63607 +#ifdef CONFIG_GRKERNSEC
63608 + time_t shm_createtime;
63609 + pid_t shm_lapid;
63610 +#endif
63611 };
63612
63613 /* shm_mode upper byte flags */
63614 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63615 index 6cf8b53..bcce844 100644
63616 --- a/include/linux/skbuff.h
63617 +++ b/include/linux/skbuff.h
63618 @@ -642,7 +642,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63619 */
63620 static inline int skb_queue_empty(const struct sk_buff_head *list)
63621 {
63622 - return list->next == (struct sk_buff *)list;
63623 + return list->next == (const struct sk_buff *)list;
63624 }
63625
63626 /**
63627 @@ -655,7 +655,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63628 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63629 const struct sk_buff *skb)
63630 {
63631 - return skb->next == (struct sk_buff *)list;
63632 + return skb->next == (const struct sk_buff *)list;
63633 }
63634
63635 /**
63636 @@ -668,7 +668,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63637 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63638 const struct sk_buff *skb)
63639 {
63640 - return skb->prev == (struct sk_buff *)list;
63641 + return skb->prev == (const struct sk_buff *)list;
63642 }
63643
63644 /**
63645 @@ -1533,7 +1533,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63646 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63647 */
63648 #ifndef NET_SKB_PAD
63649 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63650 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63651 #endif
63652
63653 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63654 diff --git a/include/linux/slab.h b/include/linux/slab.h
63655 index 573c809..07e1f43 100644
63656 --- a/include/linux/slab.h
63657 +++ b/include/linux/slab.h
63658 @@ -11,12 +11,20 @@
63659
63660 #include <linux/gfp.h>
63661 #include <linux/types.h>
63662 +#include <linux/err.h>
63663
63664 /*
63665 * Flags to pass to kmem_cache_create().
63666 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63667 */
63668 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63669 +
63670 +#ifdef CONFIG_PAX_USERCOPY
63671 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63672 +#else
63673 +#define SLAB_USERCOPY 0x00000000UL
63674 +#endif
63675 +
63676 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63677 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63678 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63679 @@ -87,10 +95,13 @@
63680 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63681 * Both make kfree a no-op.
63682 */
63683 -#define ZERO_SIZE_PTR ((void *)16)
63684 +#define ZERO_SIZE_PTR \
63685 +({ \
63686 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63687 + (void *)(-MAX_ERRNO-1L); \
63688 +})
63689
63690 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63691 - (unsigned long)ZERO_SIZE_PTR)
63692 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63693
63694 /*
63695 * struct kmem_cache related prototypes
63696 @@ -156,11 +167,12 @@ unsigned int kmem_cache_size(struct kmem_cache *);
63697 /*
63698 * Common kmalloc functions provided by all allocators
63699 */
63700 -void * __must_check __krealloc(const void *, size_t, gfp_t);
63701 -void * __must_check krealloc(const void *, size_t, gfp_t);
63702 +void * __must_check __krealloc(const void *, size_t, gfp_t) __size_overflow(2);
63703 +void * __must_check krealloc(const void *, size_t, gfp_t) __size_overflow(2);
63704 void kfree(const void *);
63705 void kzfree(const void *);
63706 size_t ksize(const void *);
63707 +void check_object_size(const void *ptr, unsigned long n, bool to);
63708
63709 /*
63710 * Allocator specific definitions. These are mainly used to establish optimized
63711 @@ -287,7 +299,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
63712 */
63713 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63714 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63715 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63716 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
63717 #define kmalloc_track_caller(size, flags) \
63718 __kmalloc_track_caller(size, flags, _RET_IP_)
63719 #else
63720 @@ -306,7 +318,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63721 */
63722 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63723 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63724 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
63725 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
63726 #define kmalloc_node_track_caller(size, flags, node) \
63727 __kmalloc_node_track_caller(size, flags, node, \
63728 _RET_IP_)
63729 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
63730 index d00e0ba..d61fb1f 100644
63731 --- a/include/linux/slab_def.h
63732 +++ b/include/linux/slab_def.h
63733 @@ -68,10 +68,10 @@ struct kmem_cache {
63734 unsigned long node_allocs;
63735 unsigned long node_frees;
63736 unsigned long node_overflow;
63737 - atomic_t allochit;
63738 - atomic_t allocmiss;
63739 - atomic_t freehit;
63740 - atomic_t freemiss;
63741 + atomic_unchecked_t allochit;
63742 + atomic_unchecked_t allocmiss;
63743 + atomic_unchecked_t freehit;
63744 + atomic_unchecked_t freemiss;
63745
63746 /*
63747 * If debugging is enabled, then the allocator can add additional
63748 @@ -109,7 +109,7 @@ struct cache_sizes {
63749 extern struct cache_sizes malloc_sizes[];
63750
63751 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63752 -void *__kmalloc(size_t size, gfp_t flags);
63753 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63754
63755 #ifdef CONFIG_TRACING
63756 extern void *kmem_cache_alloc_trace(size_t size,
63757 @@ -127,6 +127,7 @@ static inline size_t slab_buffer_size(struct kmem_cache *cachep)
63758 }
63759 #endif
63760
63761 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63762 static __always_inline void *kmalloc(size_t size, gfp_t flags)
63763 {
63764 struct kmem_cache *cachep;
63765 @@ -162,7 +163,7 @@ found:
63766 }
63767
63768 #ifdef CONFIG_NUMA
63769 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
63770 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63771 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63772
63773 #ifdef CONFIG_TRACING
63774 @@ -181,6 +182,7 @@ kmem_cache_alloc_node_trace(size_t size,
63775 }
63776 #endif
63777
63778 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63779 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63780 {
63781 struct kmem_cache *cachep;
63782 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
63783 index 0ec00b3..65e7e0e 100644
63784 --- a/include/linux/slob_def.h
63785 +++ b/include/linux/slob_def.h
63786 @@ -9,8 +9,9 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
63787 return kmem_cache_alloc_node(cachep, flags, -1);
63788 }
63789
63790 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63791 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63792
63793 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63794 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63795 {
63796 return __kmalloc_node(size, flags, node);
63797 @@ -24,11 +25,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63798 * kmalloc is the normal method of allocating memory
63799 * in the kernel.
63800 */
63801 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63802 static __always_inline void *kmalloc(size_t size, gfp_t flags)
63803 {
63804 return __kmalloc_node(size, flags, -1);
63805 }
63806
63807 +static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63808 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
63809 {
63810 return kmalloc(size, flags);
63811 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
63812 index a32bcfd..d26bd6e 100644
63813 --- a/include/linux/slub_def.h
63814 +++ b/include/linux/slub_def.h
63815 @@ -89,7 +89,7 @@ struct kmem_cache {
63816 struct kmem_cache_order_objects max;
63817 struct kmem_cache_order_objects min;
63818 gfp_t allocflags; /* gfp flags to use on each alloc */
63819 - int refcount; /* Refcount for slab cache destroy */
63820 + atomic_t refcount; /* Refcount for slab cache destroy */
63821 void (*ctor)(void *);
63822 int inuse; /* Offset to metadata */
63823 int align; /* Alignment */
63824 @@ -204,6 +204,7 @@ static __always_inline int kmalloc_index(size_t size)
63825 * This ought to end up with a global pointer to the right cache
63826 * in kmalloc_caches.
63827 */
63828 +static __always_inline struct kmem_cache *kmalloc_slab(size_t size) __size_overflow(1);
63829 static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63830 {
63831 int index = kmalloc_index(size);
63832 @@ -215,9 +216,11 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63833 }
63834
63835 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63836 -void *__kmalloc(size_t size, gfp_t flags);
63837 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
63838
63839 static __always_inline void *
63840 +kmalloc_order(size_t size, gfp_t flags, unsigned int order) __size_overflow(1);
63841 +static __always_inline void *
63842 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
63843 {
63844 void *ret = (void *) __get_free_pages(flags | __GFP_COMP, order);
63845 @@ -256,12 +259,14 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
63846 }
63847 #endif
63848
63849 +static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
63850 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
63851 {
63852 unsigned int order = get_order(size);
63853 return kmalloc_order_trace(size, flags, order);
63854 }
63855
63856 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63857 static __always_inline void *kmalloc(size_t size, gfp_t flags)
63858 {
63859 if (__builtin_constant_p(size)) {
63860 @@ -281,7 +286,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63861 }
63862
63863 #ifdef CONFIG_NUMA
63864 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63865 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63866 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63867
63868 #ifdef CONFIG_TRACING
63869 @@ -298,6 +303,7 @@ kmem_cache_alloc_node_trace(struct kmem_cache *s,
63870 }
63871 #endif
63872
63873 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63874 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63875 {
63876 if (__builtin_constant_p(size) &&
63877 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
63878 index de8832d..0147b46 100644
63879 --- a/include/linux/sonet.h
63880 +++ b/include/linux/sonet.h
63881 @@ -61,7 +61,7 @@ struct sonet_stats {
63882 #include <linux/atomic.h>
63883
63884 struct k_sonet_stats {
63885 -#define __HANDLE_ITEM(i) atomic_t i
63886 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
63887 __SONET_ITEMS
63888 #undef __HANDLE_ITEM
63889 };
63890 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
63891 index 3d8f9c4..69f1c0a 100644
63892 --- a/include/linux/sunrpc/clnt.h
63893 +++ b/include/linux/sunrpc/clnt.h
63894 @@ -172,9 +172,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
63895 {
63896 switch (sap->sa_family) {
63897 case AF_INET:
63898 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
63899 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
63900 case AF_INET6:
63901 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
63902 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
63903 }
63904 return 0;
63905 }
63906 @@ -207,7 +207,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
63907 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
63908 const struct sockaddr *src)
63909 {
63910 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
63911 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
63912 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
63913
63914 dsin->sin_family = ssin->sin_family;
63915 @@ -310,7 +310,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
63916 if (sa->sa_family != AF_INET6)
63917 return 0;
63918
63919 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
63920 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
63921 }
63922
63923 #endif /* __KERNEL__ */
63924 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
63925 index e775689..9e206d9 100644
63926 --- a/include/linux/sunrpc/sched.h
63927 +++ b/include/linux/sunrpc/sched.h
63928 @@ -105,6 +105,7 @@ struct rpc_call_ops {
63929 void (*rpc_call_done)(struct rpc_task *, void *);
63930 void (*rpc_release)(void *);
63931 };
63932 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
63933
63934 struct rpc_task_setup {
63935 struct rpc_task *task;
63936 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
63937 index c14fe86..393245e 100644
63938 --- a/include/linux/sunrpc/svc_rdma.h
63939 +++ b/include/linux/sunrpc/svc_rdma.h
63940 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
63941 extern unsigned int svcrdma_max_requests;
63942 extern unsigned int svcrdma_max_req_size;
63943
63944 -extern atomic_t rdma_stat_recv;
63945 -extern atomic_t rdma_stat_read;
63946 -extern atomic_t rdma_stat_write;
63947 -extern atomic_t rdma_stat_sq_starve;
63948 -extern atomic_t rdma_stat_rq_starve;
63949 -extern atomic_t rdma_stat_rq_poll;
63950 -extern atomic_t rdma_stat_rq_prod;
63951 -extern atomic_t rdma_stat_sq_poll;
63952 -extern atomic_t rdma_stat_sq_prod;
63953 +extern atomic_unchecked_t rdma_stat_recv;
63954 +extern atomic_unchecked_t rdma_stat_read;
63955 +extern atomic_unchecked_t rdma_stat_write;
63956 +extern atomic_unchecked_t rdma_stat_sq_starve;
63957 +extern atomic_unchecked_t rdma_stat_rq_starve;
63958 +extern atomic_unchecked_t rdma_stat_rq_poll;
63959 +extern atomic_unchecked_t rdma_stat_rq_prod;
63960 +extern atomic_unchecked_t rdma_stat_sq_poll;
63961 +extern atomic_unchecked_t rdma_stat_sq_prod;
63962
63963 #define RPCRDMA_VERSION 1
63964
63965 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
63966 index 703cfa33..0b8ca72ac 100644
63967 --- a/include/linux/sysctl.h
63968 +++ b/include/linux/sysctl.h
63969 @@ -155,7 +155,11 @@ enum
63970 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
63971 };
63972
63973 -
63974 +#ifdef CONFIG_PAX_SOFTMODE
63975 +enum {
63976 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
63977 +};
63978 +#endif
63979
63980 /* CTL_VM names: */
63981 enum
63982 @@ -968,6 +972,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
63983
63984 extern int proc_dostring(struct ctl_table *, int,
63985 void __user *, size_t *, loff_t *);
63986 +extern int proc_dostring_modpriv(struct ctl_table *, int,
63987 + void __user *, size_t *, loff_t *);
63988 extern int proc_dointvec(struct ctl_table *, int,
63989 void __user *, size_t *, loff_t *);
63990 extern int proc_dointvec_minmax(struct ctl_table *, int,
63991 diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
63992 index a71a292..51bd91d 100644
63993 --- a/include/linux/tracehook.h
63994 +++ b/include/linux/tracehook.h
63995 @@ -54,12 +54,12 @@ struct linux_binprm;
63996 /*
63997 * ptrace report for syscall entry and exit looks identical.
63998 */
63999 -static inline void ptrace_report_syscall(struct pt_regs *regs)
64000 +static inline int ptrace_report_syscall(struct pt_regs *regs)
64001 {
64002 int ptrace = current->ptrace;
64003
64004 if (!(ptrace & PT_PTRACED))
64005 - return;
64006 + return 0;
64007
64008 ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
64009
64010 @@ -72,6 +72,8 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
64011 send_sig(current->exit_code, current, 1);
64012 current->exit_code = 0;
64013 }
64014 +
64015 + return fatal_signal_pending(current);
64016 }
64017
64018 /**
64019 @@ -96,8 +98,7 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
64020 static inline __must_check int tracehook_report_syscall_entry(
64021 struct pt_regs *regs)
64022 {
64023 - ptrace_report_syscall(regs);
64024 - return 0;
64025 + return ptrace_report_syscall(regs);
64026 }
64027
64028 /**
64029 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64030 index ff7dc08..893e1bd 100644
64031 --- a/include/linux/tty_ldisc.h
64032 +++ b/include/linux/tty_ldisc.h
64033 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
64034
64035 struct module *owner;
64036
64037 - int refcount;
64038 + atomic_t refcount;
64039 };
64040
64041 struct tty_ldisc {
64042 diff --git a/include/linux/types.h b/include/linux/types.h
64043 index 57a9723..dbe234a 100644
64044 --- a/include/linux/types.h
64045 +++ b/include/linux/types.h
64046 @@ -213,10 +213,26 @@ typedef struct {
64047 int counter;
64048 } atomic_t;
64049
64050 +#ifdef CONFIG_PAX_REFCOUNT
64051 +typedef struct {
64052 + int counter;
64053 +} atomic_unchecked_t;
64054 +#else
64055 +typedef atomic_t atomic_unchecked_t;
64056 +#endif
64057 +
64058 #ifdef CONFIG_64BIT
64059 typedef struct {
64060 long counter;
64061 } atomic64_t;
64062 +
64063 +#ifdef CONFIG_PAX_REFCOUNT
64064 +typedef struct {
64065 + long counter;
64066 +} atomic64_unchecked_t;
64067 +#else
64068 +typedef atomic64_t atomic64_unchecked_t;
64069 +#endif
64070 #endif
64071
64072 struct list_head {
64073 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64074 index 5ca0951..53a2fff 100644
64075 --- a/include/linux/uaccess.h
64076 +++ b/include/linux/uaccess.h
64077 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64078 long ret; \
64079 mm_segment_t old_fs = get_fs(); \
64080 \
64081 - set_fs(KERNEL_DS); \
64082 pagefault_disable(); \
64083 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64084 - pagefault_enable(); \
64085 + set_fs(KERNEL_DS); \
64086 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64087 set_fs(old_fs); \
64088 + pagefault_enable(); \
64089 ret; \
64090 })
64091
64092 @@ -105,7 +105,7 @@ extern long __probe_kernel_read(void *dst, const void *src, size_t size);
64093 * Safely write to address @dst from the buffer at @src. If a kernel fault
64094 * happens, handle that and return -EFAULT.
64095 */
64096 -extern long notrace probe_kernel_write(void *dst, const void *src, size_t size);
64097 +extern long notrace probe_kernel_write(void *dst, const void *src, size_t size) __size_overflow(3);
64098 extern long notrace __probe_kernel_write(void *dst, const void *src, size_t size);
64099
64100 #endif /* __LINUX_UACCESS_H__ */
64101 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64102 index 99c1b4d..bb94261 100644
64103 --- a/include/linux/unaligned/access_ok.h
64104 +++ b/include/linux/unaligned/access_ok.h
64105 @@ -6,32 +6,32 @@
64106
64107 static inline u16 get_unaligned_le16(const void *p)
64108 {
64109 - return le16_to_cpup((__le16 *)p);
64110 + return le16_to_cpup((const __le16 *)p);
64111 }
64112
64113 static inline u32 get_unaligned_le32(const void *p)
64114 {
64115 - return le32_to_cpup((__le32 *)p);
64116 + return le32_to_cpup((const __le32 *)p);
64117 }
64118
64119 static inline u64 get_unaligned_le64(const void *p)
64120 {
64121 - return le64_to_cpup((__le64 *)p);
64122 + return le64_to_cpup((const __le64 *)p);
64123 }
64124
64125 static inline u16 get_unaligned_be16(const void *p)
64126 {
64127 - return be16_to_cpup((__be16 *)p);
64128 + return be16_to_cpup((const __be16 *)p);
64129 }
64130
64131 static inline u32 get_unaligned_be32(const void *p)
64132 {
64133 - return be32_to_cpup((__be32 *)p);
64134 + return be32_to_cpup((const __be32 *)p);
64135 }
64136
64137 static inline u64 get_unaligned_be64(const void *p)
64138 {
64139 - return be64_to_cpup((__be64 *)p);
64140 + return be64_to_cpup((const __be64 *)p);
64141 }
64142
64143 static inline void put_unaligned_le16(u16 val, void *p)
64144 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64145 index e5a40c3..20ab0f6 100644
64146 --- a/include/linux/usb/renesas_usbhs.h
64147 +++ b/include/linux/usb/renesas_usbhs.h
64148 @@ -39,7 +39,7 @@ enum {
64149 */
64150 struct renesas_usbhs_driver_callback {
64151 int (*notify_hotplug)(struct platform_device *pdev);
64152 -};
64153 +} __no_const;
64154
64155 /*
64156 * callback functions for platform
64157 @@ -89,7 +89,7 @@ struct renesas_usbhs_platform_callback {
64158 * VBUS control is needed for Host
64159 */
64160 int (*set_vbus)(struct platform_device *pdev, int enable);
64161 -};
64162 +} __no_const;
64163
64164 /*
64165 * parameters for renesas usbhs
64166 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64167 index 6f8fbcf..8259001 100644
64168 --- a/include/linux/vermagic.h
64169 +++ b/include/linux/vermagic.h
64170 @@ -25,9 +25,35 @@
64171 #define MODULE_ARCH_VERMAGIC ""
64172 #endif
64173
64174 +#ifdef CONFIG_PAX_REFCOUNT
64175 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
64176 +#else
64177 +#define MODULE_PAX_REFCOUNT ""
64178 +#endif
64179 +
64180 +#ifdef CONSTIFY_PLUGIN
64181 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64182 +#else
64183 +#define MODULE_CONSTIFY_PLUGIN ""
64184 +#endif
64185 +
64186 +#ifdef STACKLEAK_PLUGIN
64187 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64188 +#else
64189 +#define MODULE_STACKLEAK_PLUGIN ""
64190 +#endif
64191 +
64192 +#ifdef CONFIG_GRKERNSEC
64193 +#define MODULE_GRSEC "GRSEC "
64194 +#else
64195 +#define MODULE_GRSEC ""
64196 +#endif
64197 +
64198 #define VERMAGIC_STRING \
64199 UTS_RELEASE " " \
64200 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64201 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64202 - MODULE_ARCH_VERMAGIC
64203 + MODULE_ARCH_VERMAGIC \
64204 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64205 + MODULE_GRSEC
64206
64207 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64208 index 4bde182..c42a656 100644
64209 --- a/include/linux/vmalloc.h
64210 +++ b/include/linux/vmalloc.h
64211 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64212 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64213 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64214 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64215 +
64216 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64217 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64218 +#endif
64219 +
64220 /* bits [20..32] reserved for arch specific ioremap internals */
64221
64222 /*
64223 @@ -51,18 +56,18 @@ static inline void vmalloc_init(void)
64224 }
64225 #endif
64226
64227 -extern void *vmalloc(unsigned long size);
64228 -extern void *vzalloc(unsigned long size);
64229 -extern void *vmalloc_user(unsigned long size);
64230 -extern void *vmalloc_node(unsigned long size, int node);
64231 -extern void *vzalloc_node(unsigned long size, int node);
64232 -extern void *vmalloc_exec(unsigned long size);
64233 -extern void *vmalloc_32(unsigned long size);
64234 -extern void *vmalloc_32_user(unsigned long size);
64235 -extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64236 +extern void *vmalloc(unsigned long size) __size_overflow(1);
64237 +extern void *vzalloc(unsigned long size) __size_overflow(1);
64238 +extern void *vmalloc_user(unsigned long size) __size_overflow(1);
64239 +extern void *vmalloc_node(unsigned long size, int node) __size_overflow(1);
64240 +extern void *vzalloc_node(unsigned long size, int node) __size_overflow(1);
64241 +extern void *vmalloc_exec(unsigned long size) __size_overflow(1);
64242 +extern void *vmalloc_32(unsigned long size) __size_overflow(1);
64243 +extern void *vmalloc_32_user(unsigned long size) __size_overflow(1);
64244 +extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot) __size_overflow(1);
64245 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64246 unsigned long start, unsigned long end, gfp_t gfp_mask,
64247 - pgprot_t prot, int node, void *caller);
64248 + pgprot_t prot, int node, void *caller) __size_overflow(1);
64249 extern void vfree(const void *addr);
64250
64251 extern void *vmap(struct page **pages, unsigned int count,
64252 @@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64253 extern void free_vm_area(struct vm_struct *area);
64254
64255 /* for /dev/kmem */
64256 -extern long vread(char *buf, char *addr, unsigned long count);
64257 -extern long vwrite(char *buf, char *addr, unsigned long count);
64258 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64259 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64260
64261 /*
64262 * Internals. Dont't use..
64263 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64264 index 65efb92..137adbb 100644
64265 --- a/include/linux/vmstat.h
64266 +++ b/include/linux/vmstat.h
64267 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64268 /*
64269 * Zone based page accounting with per cpu differentials.
64270 */
64271 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64272 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64273
64274 static inline void zone_page_state_add(long x, struct zone *zone,
64275 enum zone_stat_item item)
64276 {
64277 - atomic_long_add(x, &zone->vm_stat[item]);
64278 - atomic_long_add(x, &vm_stat[item]);
64279 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64280 + atomic_long_add_unchecked(x, &vm_stat[item]);
64281 }
64282
64283 static inline unsigned long global_page_state(enum zone_stat_item item)
64284 {
64285 - long x = atomic_long_read(&vm_stat[item]);
64286 + long x = atomic_long_read_unchecked(&vm_stat[item]);
64287 #ifdef CONFIG_SMP
64288 if (x < 0)
64289 x = 0;
64290 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64291 static inline unsigned long zone_page_state(struct zone *zone,
64292 enum zone_stat_item item)
64293 {
64294 - long x = atomic_long_read(&zone->vm_stat[item]);
64295 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64296 #ifdef CONFIG_SMP
64297 if (x < 0)
64298 x = 0;
64299 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64300 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64301 enum zone_stat_item item)
64302 {
64303 - long x = atomic_long_read(&zone->vm_stat[item]);
64304 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64305
64306 #ifdef CONFIG_SMP
64307 int cpu;
64308 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64309
64310 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64311 {
64312 - atomic_long_inc(&zone->vm_stat[item]);
64313 - atomic_long_inc(&vm_stat[item]);
64314 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64315 + atomic_long_inc_unchecked(&vm_stat[item]);
64316 }
64317
64318 static inline void __inc_zone_page_state(struct page *page,
64319 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
64320
64321 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64322 {
64323 - atomic_long_dec(&zone->vm_stat[item]);
64324 - atomic_long_dec(&vm_stat[item]);
64325 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64326 + atomic_long_dec_unchecked(&vm_stat[item]);
64327 }
64328
64329 static inline void __dec_zone_page_state(struct page *page,
64330 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64331 index e5d1220..ef6e406 100644
64332 --- a/include/linux/xattr.h
64333 +++ b/include/linux/xattr.h
64334 @@ -57,6 +57,11 @@
64335 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64336 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64337
64338 +/* User namespace */
64339 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64340 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
64341 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64342 +
64343 #ifdef __KERNEL__
64344
64345 #include <linux/types.h>
64346 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64347 index 4aeff96..b378cdc 100644
64348 --- a/include/media/saa7146_vv.h
64349 +++ b/include/media/saa7146_vv.h
64350 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
64351 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64352
64353 /* the extension can override this */
64354 - struct v4l2_ioctl_ops ops;
64355 + v4l2_ioctl_ops_no_const ops;
64356 /* pointer to the saa7146 core ops */
64357 const struct v4l2_ioctl_ops *core_ops;
64358
64359 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64360 index c7c40f1..4f01585 100644
64361 --- a/include/media/v4l2-dev.h
64362 +++ b/include/media/v4l2-dev.h
64363 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
64364
64365
64366 struct v4l2_file_operations {
64367 - struct module *owner;
64368 + struct module * const owner;
64369 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
64370 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
64371 unsigned int (*poll) (struct file *, struct poll_table_struct *);
64372 @@ -68,6 +68,7 @@ struct v4l2_file_operations {
64373 int (*open) (struct file *);
64374 int (*release) (struct file *);
64375 };
64376 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64377
64378 /*
64379 * Newer version of video_device, handled by videodev2.c
64380 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64381 index 4d1c74a..65e1221 100644
64382 --- a/include/media/v4l2-ioctl.h
64383 +++ b/include/media/v4l2-ioctl.h
64384 @@ -274,7 +274,7 @@ struct v4l2_ioctl_ops {
64385 long (*vidioc_default) (struct file *file, void *fh,
64386 bool valid_prio, int cmd, void *arg);
64387 };
64388 -
64389 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64390
64391 /* v4l debugging and diagnostics */
64392
64393 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64394 index 8d55251..dfe5b0a 100644
64395 --- a/include/net/caif/caif_hsi.h
64396 +++ b/include/net/caif/caif_hsi.h
64397 @@ -98,7 +98,7 @@ struct cfhsi_drv {
64398 void (*rx_done_cb) (struct cfhsi_drv *drv);
64399 void (*wake_up_cb) (struct cfhsi_drv *drv);
64400 void (*wake_down_cb) (struct cfhsi_drv *drv);
64401 -};
64402 +} __no_const;
64403
64404 /* Structure implemented by HSI device. */
64405 struct cfhsi_dev {
64406 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64407 index 9e5425b..8136ffc 100644
64408 --- a/include/net/caif/cfctrl.h
64409 +++ b/include/net/caif/cfctrl.h
64410 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
64411 void (*radioset_rsp)(void);
64412 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64413 struct cflayer *client_layer);
64414 -};
64415 +} __no_const;
64416
64417 /* Link Setup Parameters for CAIF-Links. */
64418 struct cfctrl_link_param {
64419 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
64420 struct cfctrl {
64421 struct cfsrvl serv;
64422 struct cfctrl_rsp res;
64423 - atomic_t req_seq_no;
64424 - atomic_t rsp_seq_no;
64425 + atomic_unchecked_t req_seq_no;
64426 + atomic_unchecked_t rsp_seq_no;
64427 struct list_head list;
64428 /* Protects from simultaneous access to first_req list */
64429 spinlock_t info_list_lock;
64430 diff --git a/include/net/flow.h b/include/net/flow.h
64431 index 2a7eefd..3250f3b 100644
64432 --- a/include/net/flow.h
64433 +++ b/include/net/flow.h
64434 @@ -218,6 +218,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64435
64436 extern void flow_cache_flush(void);
64437 extern void flow_cache_flush_deferred(void);
64438 -extern atomic_t flow_cache_genid;
64439 +extern atomic_unchecked_t flow_cache_genid;
64440
64441 #endif
64442 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64443 index e9ff3fc..9d3e5c7 100644
64444 --- a/include/net/inetpeer.h
64445 +++ b/include/net/inetpeer.h
64446 @@ -48,8 +48,8 @@ struct inet_peer {
64447 */
64448 union {
64449 struct {
64450 - atomic_t rid; /* Frag reception counter */
64451 - atomic_t ip_id_count; /* IP ID for the next packet */
64452 + atomic_unchecked_t rid; /* Frag reception counter */
64453 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64454 __u32 tcp_ts;
64455 __u32 tcp_ts_stamp;
64456 };
64457 @@ -113,11 +113,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64458 more++;
64459 inet_peer_refcheck(p);
64460 do {
64461 - old = atomic_read(&p->ip_id_count);
64462 + old = atomic_read_unchecked(&p->ip_id_count);
64463 new = old + more;
64464 if (!new)
64465 new = 1;
64466 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64467 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64468 return new;
64469 }
64470
64471 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64472 index 10422ef..662570f 100644
64473 --- a/include/net/ip_fib.h
64474 +++ b/include/net/ip_fib.h
64475 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64476
64477 #define FIB_RES_SADDR(net, res) \
64478 ((FIB_RES_NH(res).nh_saddr_genid == \
64479 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64480 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64481 FIB_RES_NH(res).nh_saddr : \
64482 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64483 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64484 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64485 index e5a7b9a..f4fc44b 100644
64486 --- a/include/net/ip_vs.h
64487 +++ b/include/net/ip_vs.h
64488 @@ -509,7 +509,7 @@ struct ip_vs_conn {
64489 struct ip_vs_conn *control; /* Master control connection */
64490 atomic_t n_control; /* Number of controlled ones */
64491 struct ip_vs_dest *dest; /* real server */
64492 - atomic_t in_pkts; /* incoming packet counter */
64493 + atomic_unchecked_t in_pkts; /* incoming packet counter */
64494
64495 /* packet transmitter for different forwarding methods. If it
64496 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64497 @@ -647,7 +647,7 @@ struct ip_vs_dest {
64498 __be16 port; /* port number of the server */
64499 union nf_inet_addr addr; /* IP address of the server */
64500 volatile unsigned flags; /* dest status flags */
64501 - atomic_t conn_flags; /* flags to copy to conn */
64502 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
64503 atomic_t weight; /* server weight */
64504
64505 atomic_t refcnt; /* reference counter */
64506 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64507 index 69b610a..fe3962c 100644
64508 --- a/include/net/irda/ircomm_core.h
64509 +++ b/include/net/irda/ircomm_core.h
64510 @@ -51,7 +51,7 @@ typedef struct {
64511 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64512 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64513 struct ircomm_info *);
64514 -} call_t;
64515 +} __no_const call_t;
64516
64517 struct ircomm_cb {
64518 irda_queue_t queue;
64519 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64520 index 59ba38bc..d515662 100644
64521 --- a/include/net/irda/ircomm_tty.h
64522 +++ b/include/net/irda/ircomm_tty.h
64523 @@ -35,6 +35,7 @@
64524 #include <linux/termios.h>
64525 #include <linux/timer.h>
64526 #include <linux/tty.h> /* struct tty_struct */
64527 +#include <asm/local.h>
64528
64529 #include <net/irda/irias_object.h>
64530 #include <net/irda/ircomm_core.h>
64531 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64532 unsigned short close_delay;
64533 unsigned short closing_wait; /* time to wait before closing */
64534
64535 - int open_count;
64536 - int blocked_open; /* # of blocked opens */
64537 + local_t open_count;
64538 + local_t blocked_open; /* # of blocked opens */
64539
64540 /* Protect concurent access to :
64541 * o self->open_count
64542 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64543 index f2419cf..473679f 100644
64544 --- a/include/net/iucv/af_iucv.h
64545 +++ b/include/net/iucv/af_iucv.h
64546 @@ -139,7 +139,7 @@ struct iucv_sock {
64547 struct iucv_sock_list {
64548 struct hlist_head head;
64549 rwlock_t lock;
64550 - atomic_t autobind_name;
64551 + atomic_unchecked_t autobind_name;
64552 };
64553
64554 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64555 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64556 index 2720884..3aa5c25 100644
64557 --- a/include/net/neighbour.h
64558 +++ b/include/net/neighbour.h
64559 @@ -122,7 +122,7 @@ struct neigh_ops {
64560 void (*error_report)(struct neighbour *, struct sk_buff *);
64561 int (*output)(struct neighbour *, struct sk_buff *);
64562 int (*connected_output)(struct neighbour *, struct sk_buff *);
64563 -};
64564 +} __do_const;
64565
64566 struct pneigh_entry {
64567 struct pneigh_entry *next;
64568 diff --git a/include/net/netlink.h b/include/net/netlink.h
64569 index cb1f350..3279d2c 100644
64570 --- a/include/net/netlink.h
64571 +++ b/include/net/netlink.h
64572 @@ -569,7 +569,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64573 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64574 {
64575 if (mark)
64576 - skb_trim(skb, (unsigned char *) mark - skb->data);
64577 + skb_trim(skb, (const unsigned char *) mark - skb->data);
64578 }
64579
64580 /**
64581 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64582 index d786b4f..4c3dd41 100644
64583 --- a/include/net/netns/ipv4.h
64584 +++ b/include/net/netns/ipv4.h
64585 @@ -56,8 +56,8 @@ struct netns_ipv4 {
64586
64587 unsigned int sysctl_ping_group_range[2];
64588
64589 - atomic_t rt_genid;
64590 - atomic_t dev_addr_genid;
64591 + atomic_unchecked_t rt_genid;
64592 + atomic_unchecked_t dev_addr_genid;
64593
64594 #ifdef CONFIG_IP_MROUTE
64595 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64596 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64597 index 6a72a58..e6a127d 100644
64598 --- a/include/net/sctp/sctp.h
64599 +++ b/include/net/sctp/sctp.h
64600 @@ -318,9 +318,9 @@ do { \
64601
64602 #else /* SCTP_DEBUG */
64603
64604 -#define SCTP_DEBUG_PRINTK(whatever...)
64605 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64606 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64607 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64608 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64609 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64610 #define SCTP_ENABLE_DEBUG
64611 #define SCTP_DISABLE_DEBUG
64612 #define SCTP_ASSERT(expr, str, func)
64613 diff --git a/include/net/sock.h b/include/net/sock.h
64614 index 32e3937..87a1dbc 100644
64615 --- a/include/net/sock.h
64616 +++ b/include/net/sock.h
64617 @@ -277,7 +277,7 @@ struct sock {
64618 #ifdef CONFIG_RPS
64619 __u32 sk_rxhash;
64620 #endif
64621 - atomic_t sk_drops;
64622 + atomic_unchecked_t sk_drops;
64623 int sk_rcvbuf;
64624
64625 struct sk_filter __rcu *sk_filter;
64626 @@ -1402,7 +1402,7 @@ static inline void sk_nocaps_add(struct sock *sk, int flags)
64627 }
64628
64629 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64630 - char __user *from, char *to,
64631 + char __user *from, unsigned char *to,
64632 int copy, int offset)
64633 {
64634 if (skb->ip_summed == CHECKSUM_NONE) {
64635 diff --git a/include/net/tcp.h b/include/net/tcp.h
64636 index bb18c4d..bb87972 100644
64637 --- a/include/net/tcp.h
64638 +++ b/include/net/tcp.h
64639 @@ -1409,7 +1409,7 @@ struct tcp_seq_afinfo {
64640 char *name;
64641 sa_family_t family;
64642 const struct file_operations *seq_fops;
64643 - struct seq_operations seq_ops;
64644 + seq_operations_no_const seq_ops;
64645 };
64646
64647 struct tcp_iter_state {
64648 diff --git a/include/net/udp.h b/include/net/udp.h
64649 index 3b285f4..0219639 100644
64650 --- a/include/net/udp.h
64651 +++ b/include/net/udp.h
64652 @@ -237,7 +237,7 @@ struct udp_seq_afinfo {
64653 sa_family_t family;
64654 struct udp_table *udp_table;
64655 const struct file_operations *seq_fops;
64656 - struct seq_operations seq_ops;
64657 + seq_operations_no_const seq_ops;
64658 };
64659
64660 struct udp_iter_state {
64661 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64662 index b203e14..1df3991 100644
64663 --- a/include/net/xfrm.h
64664 +++ b/include/net/xfrm.h
64665 @@ -505,7 +505,7 @@ struct xfrm_policy {
64666 struct timer_list timer;
64667
64668 struct flow_cache_object flo;
64669 - atomic_t genid;
64670 + atomic_unchecked_t genid;
64671 u32 priority;
64672 u32 index;
64673 struct xfrm_mark mark;
64674 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64675 index 1a046b1..ee0bef0 100644
64676 --- a/include/rdma/iw_cm.h
64677 +++ b/include/rdma/iw_cm.h
64678 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
64679 int backlog);
64680
64681 int (*destroy_listen)(struct iw_cm_id *cm_id);
64682 -};
64683 +} __no_const;
64684
64685 /**
64686 * iw_create_cm_id - Create an IW CM identifier.
64687 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64688 index 5d1a758..1dbf795 100644
64689 --- a/include/scsi/libfc.h
64690 +++ b/include/scsi/libfc.h
64691 @@ -748,6 +748,7 @@ struct libfc_function_template {
64692 */
64693 void (*disc_stop_final) (struct fc_lport *);
64694 };
64695 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64696
64697 /**
64698 * struct fc_disc - Discovery context
64699 @@ -851,7 +852,7 @@ struct fc_lport {
64700 struct fc_vport *vport;
64701
64702 /* Operational Information */
64703 - struct libfc_function_template tt;
64704 + libfc_function_template_no_const tt;
64705 u8 link_up;
64706 u8 qfull;
64707 enum fc_lport_state state;
64708 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64709 index 5591ed5..13eb457 100644
64710 --- a/include/scsi/scsi_device.h
64711 +++ b/include/scsi/scsi_device.h
64712 @@ -161,9 +161,9 @@ struct scsi_device {
64713 unsigned int max_device_blocked; /* what device_blocked counts down from */
64714 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64715
64716 - atomic_t iorequest_cnt;
64717 - atomic_t iodone_cnt;
64718 - atomic_t ioerr_cnt;
64719 + atomic_unchecked_t iorequest_cnt;
64720 + atomic_unchecked_t iodone_cnt;
64721 + atomic_unchecked_t ioerr_cnt;
64722
64723 struct device sdev_gendev,
64724 sdev_dev;
64725 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64726 index 2a65167..91e01f8 100644
64727 --- a/include/scsi/scsi_transport_fc.h
64728 +++ b/include/scsi/scsi_transport_fc.h
64729 @@ -711,7 +711,7 @@ struct fc_function_template {
64730 unsigned long show_host_system_hostname:1;
64731
64732 unsigned long disable_target_scan:1;
64733 -};
64734 +} __do_const;
64735
64736
64737 /**
64738 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64739 index 030b87c..98a6954 100644
64740 --- a/include/sound/ak4xxx-adda.h
64741 +++ b/include/sound/ak4xxx-adda.h
64742 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64743 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64744 unsigned char val);
64745 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64746 -};
64747 +} __no_const;
64748
64749 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64750
64751 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64752 index 8c05e47..2b5df97 100644
64753 --- a/include/sound/hwdep.h
64754 +++ b/include/sound/hwdep.h
64755 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
64756 struct snd_hwdep_dsp_status *status);
64757 int (*dsp_load)(struct snd_hwdep *hw,
64758 struct snd_hwdep_dsp_image *image);
64759 -};
64760 +} __no_const;
64761
64762 struct snd_hwdep {
64763 struct snd_card *card;
64764 diff --git a/include/sound/info.h b/include/sound/info.h
64765 index 5492cc4..1a65278 100644
64766 --- a/include/sound/info.h
64767 +++ b/include/sound/info.h
64768 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
64769 struct snd_info_buffer *buffer);
64770 void (*write)(struct snd_info_entry *entry,
64771 struct snd_info_buffer *buffer);
64772 -};
64773 +} __no_const;
64774
64775 struct snd_info_entry_ops {
64776 int (*open)(struct snd_info_entry *entry,
64777 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
64778 index 0cf91b2..b70cae4 100644
64779 --- a/include/sound/pcm.h
64780 +++ b/include/sound/pcm.h
64781 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
64782 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
64783 int (*ack)(struct snd_pcm_substream *substream);
64784 };
64785 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
64786
64787 /*
64788 *
64789 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
64790 index af1b49e..a5d55a5 100644
64791 --- a/include/sound/sb16_csp.h
64792 +++ b/include/sound/sb16_csp.h
64793 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
64794 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
64795 int (*csp_stop) (struct snd_sb_csp * p);
64796 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
64797 -};
64798 +} __no_const;
64799
64800 /*
64801 * CSP private data
64802 diff --git a/include/sound/soc.h b/include/sound/soc.h
64803 index 11cfb59..e3f93f4 100644
64804 --- a/include/sound/soc.h
64805 +++ b/include/sound/soc.h
64806 @@ -683,7 +683,7 @@ struct snd_soc_platform_driver {
64807 /* platform IO - used for platform DAPM */
64808 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
64809 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
64810 -};
64811 +} __do_const;
64812
64813 struct snd_soc_platform {
64814 const char *name;
64815 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
64816 index 444cd6b..3327cc5 100644
64817 --- a/include/sound/ymfpci.h
64818 +++ b/include/sound/ymfpci.h
64819 @@ -358,7 +358,7 @@ struct snd_ymfpci {
64820 spinlock_t reg_lock;
64821 spinlock_t voice_lock;
64822 wait_queue_head_t interrupt_sleep;
64823 - atomic_t interrupt_sleep_count;
64824 + atomic_unchecked_t interrupt_sleep_count;
64825 struct snd_info_entry *proc_entry;
64826 const struct firmware *dsp_microcode;
64827 const struct firmware *controller_microcode;
64828 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
64829 index 94bbec3..3a8c6b0 100644
64830 --- a/include/target/target_core_base.h
64831 +++ b/include/target/target_core_base.h
64832 @@ -346,7 +346,7 @@ struct t10_reservation_ops {
64833 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
64834 int (*t10_pr_register)(struct se_cmd *);
64835 int (*t10_pr_clear)(struct se_cmd *);
64836 -};
64837 +} __no_const;
64838
64839 struct t10_reservation {
64840 /* Reservation effects all target ports */
64841 @@ -465,8 +465,8 @@ struct se_cmd {
64842 atomic_t t_se_count;
64843 atomic_t t_task_cdbs_left;
64844 atomic_t t_task_cdbs_ex_left;
64845 - atomic_t t_task_cdbs_sent;
64846 - atomic_t t_transport_aborted;
64847 + atomic_unchecked_t t_task_cdbs_sent;
64848 + atomic_unchecked_t t_transport_aborted;
64849 atomic_t t_transport_active;
64850 atomic_t t_transport_complete;
64851 atomic_t t_transport_queue_active;
64852 @@ -705,7 +705,7 @@ struct se_device {
64853 /* Active commands on this virtual SE device */
64854 atomic_t simple_cmds;
64855 atomic_t depth_left;
64856 - atomic_t dev_ordered_id;
64857 + atomic_unchecked_t dev_ordered_id;
64858 atomic_t execute_tasks;
64859 atomic_t dev_ordered_sync;
64860 atomic_t dev_qf_count;
64861 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
64862 index 1c09820..7f5ec79 100644
64863 --- a/include/trace/events/irq.h
64864 +++ b/include/trace/events/irq.h
64865 @@ -36,7 +36,7 @@ struct softirq_action;
64866 */
64867 TRACE_EVENT(irq_handler_entry,
64868
64869 - TP_PROTO(int irq, struct irqaction *action),
64870 + TP_PROTO(int irq, const struct irqaction *action),
64871
64872 TP_ARGS(irq, action),
64873
64874 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
64875 */
64876 TRACE_EVENT(irq_handler_exit,
64877
64878 - TP_PROTO(int irq, struct irqaction *action, int ret),
64879 + TP_PROTO(int irq, const struct irqaction *action, int ret),
64880
64881 TP_ARGS(irq, action, ret),
64882
64883 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
64884 index c41f308..6918de3 100644
64885 --- a/include/video/udlfb.h
64886 +++ b/include/video/udlfb.h
64887 @@ -52,10 +52,10 @@ struct dlfb_data {
64888 u32 pseudo_palette[256];
64889 int blank_mode; /*one of FB_BLANK_ */
64890 /* blit-only rendering path metrics, exposed through sysfs */
64891 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64892 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
64893 - atomic_t bytes_sent; /* to usb, after compression including overhead */
64894 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
64895 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64896 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
64897 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
64898 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
64899 };
64900
64901 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
64902 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
64903 index 0993a22..32ba2fe 100644
64904 --- a/include/video/uvesafb.h
64905 +++ b/include/video/uvesafb.h
64906 @@ -177,6 +177,7 @@ struct uvesafb_par {
64907 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
64908 u8 pmi_setpal; /* PMI for palette changes */
64909 u16 *pmi_base; /* protected mode interface location */
64910 + u8 *pmi_code; /* protected mode code location */
64911 void *pmi_start;
64912 void *pmi_pal;
64913 u8 *vbe_state_orig; /*
64914 diff --git a/init/Kconfig b/init/Kconfig
64915 index 43298f9..2f56c12 100644
64916 --- a/init/Kconfig
64917 +++ b/init/Kconfig
64918 @@ -1214,7 +1214,7 @@ config SLUB_DEBUG
64919
64920 config COMPAT_BRK
64921 bool "Disable heap randomization"
64922 - default y
64923 + default n
64924 help
64925 Randomizing heap placement makes heap exploits harder, but it
64926 also breaks ancient binaries (including anything libc5 based).
64927 diff --git a/init/do_mounts.c b/init/do_mounts.c
64928 index db6e5ee..7677ff7 100644
64929 --- a/init/do_mounts.c
64930 +++ b/init/do_mounts.c
64931 @@ -325,11 +325,11 @@ static void __init get_fs_names(char *page)
64932
64933 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
64934 {
64935 - int err = sys_mount(name, "/root", fs, flags, data);
64936 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
64937 if (err)
64938 return err;
64939
64940 - sys_chdir((const char __user __force *)"/root");
64941 + sys_chdir((const char __force_user*)"/root");
64942 ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
64943 printk(KERN_INFO
64944 "VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
64945 @@ -448,18 +448,18 @@ void __init change_floppy(char *fmt, ...)
64946 va_start(args, fmt);
64947 vsprintf(buf, fmt, args);
64948 va_end(args);
64949 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
64950 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
64951 if (fd >= 0) {
64952 sys_ioctl(fd, FDEJECT, 0);
64953 sys_close(fd);
64954 }
64955 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
64956 - fd = sys_open("/dev/console", O_RDWR, 0);
64957 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
64958 if (fd >= 0) {
64959 sys_ioctl(fd, TCGETS, (long)&termios);
64960 termios.c_lflag &= ~ICANON;
64961 sys_ioctl(fd, TCSETSF, (long)&termios);
64962 - sys_read(fd, &c, 1);
64963 + sys_read(fd, (char __user *)&c, 1);
64964 termios.c_lflag |= ICANON;
64965 sys_ioctl(fd, TCSETSF, (long)&termios);
64966 sys_close(fd);
64967 @@ -553,6 +553,6 @@ void __init prepare_namespace(void)
64968 mount_root();
64969 out:
64970 devtmpfs_mount("dev");
64971 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64972 - sys_chroot((const char __user __force *)".");
64973 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64974 + sys_chroot((const char __force_user *)".");
64975 }
64976 diff --git a/init/do_mounts.h b/init/do_mounts.h
64977 index f5b978a..69dbfe8 100644
64978 --- a/init/do_mounts.h
64979 +++ b/init/do_mounts.h
64980 @@ -15,15 +15,15 @@ extern int root_mountflags;
64981
64982 static inline int create_dev(char *name, dev_t dev)
64983 {
64984 - sys_unlink(name);
64985 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
64986 + sys_unlink((char __force_user *)name);
64987 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
64988 }
64989
64990 #if BITS_PER_LONG == 32
64991 static inline u32 bstat(char *name)
64992 {
64993 struct stat64 stat;
64994 - if (sys_stat64(name, &stat) != 0)
64995 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
64996 return 0;
64997 if (!S_ISBLK(stat.st_mode))
64998 return 0;
64999 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65000 static inline u32 bstat(char *name)
65001 {
65002 struct stat stat;
65003 - if (sys_newstat(name, &stat) != 0)
65004 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65005 return 0;
65006 if (!S_ISBLK(stat.st_mode))
65007 return 0;
65008 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65009 index 3098a38..253064e 100644
65010 --- a/init/do_mounts_initrd.c
65011 +++ b/init/do_mounts_initrd.c
65012 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
65013 create_dev("/dev/root.old", Root_RAM0);
65014 /* mount initrd on rootfs' /root */
65015 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65016 - sys_mkdir("/old", 0700);
65017 - root_fd = sys_open("/", 0, 0);
65018 - old_fd = sys_open("/old", 0, 0);
65019 + sys_mkdir((const char __force_user *)"/old", 0700);
65020 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
65021 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65022 /* move initrd over / and chdir/chroot in initrd root */
65023 - sys_chdir("/root");
65024 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65025 - sys_chroot(".");
65026 + sys_chdir((const char __force_user *)"/root");
65027 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65028 + sys_chroot((const char __force_user *)".");
65029
65030 /*
65031 * In case that a resume from disk is carried out by linuxrc or one of
65032 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
65033
65034 /* move initrd to rootfs' /old */
65035 sys_fchdir(old_fd);
65036 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
65037 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65038 /* switch root and cwd back to / of rootfs */
65039 sys_fchdir(root_fd);
65040 - sys_chroot(".");
65041 + sys_chroot((const char __force_user *)".");
65042 sys_close(old_fd);
65043 sys_close(root_fd);
65044
65045 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65046 - sys_chdir("/old");
65047 + sys_chdir((const char __force_user *)"/old");
65048 return;
65049 }
65050
65051 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
65052 mount_root();
65053
65054 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65055 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65056 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65057 if (!error)
65058 printk("okay\n");
65059 else {
65060 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
65061 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65062 if (error == -ENOENT)
65063 printk("/initrd does not exist. Ignored.\n");
65064 else
65065 printk("failed\n");
65066 printk(KERN_NOTICE "Unmounting old root\n");
65067 - sys_umount("/old", MNT_DETACH);
65068 + sys_umount((char __force_user *)"/old", MNT_DETACH);
65069 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65070 if (fd < 0) {
65071 error = fd;
65072 @@ -116,11 +116,11 @@ int __init initrd_load(void)
65073 * mounted in the normal path.
65074 */
65075 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65076 - sys_unlink("/initrd.image");
65077 + sys_unlink((const char __force_user *)"/initrd.image");
65078 handle_initrd();
65079 return 1;
65080 }
65081 }
65082 - sys_unlink("/initrd.image");
65083 + sys_unlink((const char __force_user *)"/initrd.image");
65084 return 0;
65085 }
65086 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65087 index 32c4799..c27ee74 100644
65088 --- a/init/do_mounts_md.c
65089 +++ b/init/do_mounts_md.c
65090 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
65091 partitioned ? "_d" : "", minor,
65092 md_setup_args[ent].device_names);
65093
65094 - fd = sys_open(name, 0, 0);
65095 + fd = sys_open((char __force_user *)name, 0, 0);
65096 if (fd < 0) {
65097 printk(KERN_ERR "md: open failed - cannot start "
65098 "array %s\n", name);
65099 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
65100 * array without it
65101 */
65102 sys_close(fd);
65103 - fd = sys_open(name, 0, 0);
65104 + fd = sys_open((char __force_user *)name, 0, 0);
65105 sys_ioctl(fd, BLKRRPART, 0);
65106 }
65107 sys_close(fd);
65108 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
65109
65110 wait_for_device_probe();
65111
65112 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
65113 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65114 if (fd >= 0) {
65115 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65116 sys_close(fd);
65117 diff --git a/init/initramfs.c b/init/initramfs.c
65118 index 2531811..040d4d4 100644
65119 --- a/init/initramfs.c
65120 +++ b/init/initramfs.c
65121 @@ -74,7 +74,7 @@ static void __init free_hash(void)
65122 }
65123 }
65124
65125 -static long __init do_utime(char __user *filename, time_t mtime)
65126 +static long __init do_utime(__force char __user *filename, time_t mtime)
65127 {
65128 struct timespec t[2];
65129
65130 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
65131 struct dir_entry *de, *tmp;
65132 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65133 list_del(&de->list);
65134 - do_utime(de->name, de->mtime);
65135 + do_utime((char __force_user *)de->name, de->mtime);
65136 kfree(de->name);
65137 kfree(de);
65138 }
65139 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
65140 if (nlink >= 2) {
65141 char *old = find_link(major, minor, ino, mode, collected);
65142 if (old)
65143 - return (sys_link(old, collected) < 0) ? -1 : 1;
65144 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65145 }
65146 return 0;
65147 }
65148 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, mode_t mode)
65149 {
65150 struct stat st;
65151
65152 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65153 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65154 if (S_ISDIR(st.st_mode))
65155 - sys_rmdir(path);
65156 + sys_rmdir((char __force_user *)path);
65157 else
65158 - sys_unlink(path);
65159 + sys_unlink((char __force_user *)path);
65160 }
65161 }
65162
65163 @@ -305,7 +305,7 @@ static int __init do_name(void)
65164 int openflags = O_WRONLY|O_CREAT;
65165 if (ml != 1)
65166 openflags |= O_TRUNC;
65167 - wfd = sys_open(collected, openflags, mode);
65168 + wfd = sys_open((char __force_user *)collected, openflags, mode);
65169
65170 if (wfd >= 0) {
65171 sys_fchown(wfd, uid, gid);
65172 @@ -317,17 +317,17 @@ static int __init do_name(void)
65173 }
65174 }
65175 } else if (S_ISDIR(mode)) {
65176 - sys_mkdir(collected, mode);
65177 - sys_chown(collected, uid, gid);
65178 - sys_chmod(collected, mode);
65179 + sys_mkdir((char __force_user *)collected, mode);
65180 + sys_chown((char __force_user *)collected, uid, gid);
65181 + sys_chmod((char __force_user *)collected, mode);
65182 dir_add(collected, mtime);
65183 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65184 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65185 if (maybe_link() == 0) {
65186 - sys_mknod(collected, mode, rdev);
65187 - sys_chown(collected, uid, gid);
65188 - sys_chmod(collected, mode);
65189 - do_utime(collected, mtime);
65190 + sys_mknod((char __force_user *)collected, mode, rdev);
65191 + sys_chown((char __force_user *)collected, uid, gid);
65192 + sys_chmod((char __force_user *)collected, mode);
65193 + do_utime((char __force_user *)collected, mtime);
65194 }
65195 }
65196 return 0;
65197 @@ -336,15 +336,15 @@ static int __init do_name(void)
65198 static int __init do_copy(void)
65199 {
65200 if (count >= body_len) {
65201 - sys_write(wfd, victim, body_len);
65202 + sys_write(wfd, (char __force_user *)victim, body_len);
65203 sys_close(wfd);
65204 - do_utime(vcollected, mtime);
65205 + do_utime((char __force_user *)vcollected, mtime);
65206 kfree(vcollected);
65207 eat(body_len);
65208 state = SkipIt;
65209 return 0;
65210 } else {
65211 - sys_write(wfd, victim, count);
65212 + sys_write(wfd, (char __force_user *)victim, count);
65213 body_len -= count;
65214 eat(count);
65215 return 1;
65216 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
65217 {
65218 collected[N_ALIGN(name_len) + body_len] = '\0';
65219 clean_path(collected, 0);
65220 - sys_symlink(collected + N_ALIGN(name_len), collected);
65221 - sys_lchown(collected, uid, gid);
65222 - do_utime(collected, mtime);
65223 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
65224 + sys_lchown((char __force_user *)collected, uid, gid);
65225 + do_utime((char __force_user *)collected, mtime);
65226 state = SkipIt;
65227 next_state = Reset;
65228 return 0;
65229 diff --git a/init/main.c b/init/main.c
65230 index 217ed23..ec5406f 100644
65231 --- a/init/main.c
65232 +++ b/init/main.c
65233 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
65234 extern void tc_init(void);
65235 #endif
65236
65237 +extern void grsecurity_init(void);
65238 +
65239 /*
65240 * Debug helper: via this flag we know that we are in 'early bootup code'
65241 * where only the boot processor is running with IRQ disabled. This means
65242 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
65243
65244 __setup("reset_devices", set_reset_devices);
65245
65246 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
65247 +extern char pax_enter_kernel_user[];
65248 +extern char pax_exit_kernel_user[];
65249 +extern pgdval_t clone_pgd_mask;
65250 +#endif
65251 +
65252 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
65253 +static int __init setup_pax_nouderef(char *str)
65254 +{
65255 +#ifdef CONFIG_X86_32
65256 + unsigned int cpu;
65257 + struct desc_struct *gdt;
65258 +
65259 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
65260 + gdt = get_cpu_gdt_table(cpu);
65261 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
65262 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
65263 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
65264 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
65265 + }
65266 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
65267 +#else
65268 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
65269 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
65270 + clone_pgd_mask = ~(pgdval_t)0UL;
65271 +#endif
65272 +
65273 + return 0;
65274 +}
65275 +early_param("pax_nouderef", setup_pax_nouderef);
65276 +#endif
65277 +
65278 +#ifdef CONFIG_PAX_SOFTMODE
65279 +int pax_softmode;
65280 +
65281 +static int __init setup_pax_softmode(char *str)
65282 +{
65283 + get_option(&str, &pax_softmode);
65284 + return 1;
65285 +}
65286 +__setup("pax_softmode=", setup_pax_softmode);
65287 +#endif
65288 +
65289 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
65290 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
65291 static const char *panic_later, *panic_param;
65292 @@ -681,6 +726,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
65293 {
65294 int count = preempt_count();
65295 int ret;
65296 + const char *msg1 = "", *msg2 = "";
65297
65298 if (initcall_debug)
65299 ret = do_one_initcall_debug(fn);
65300 @@ -693,15 +739,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
65301 sprintf(msgbuf, "error code %d ", ret);
65302
65303 if (preempt_count() != count) {
65304 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
65305 + msg1 = " preemption imbalance";
65306 preempt_count() = count;
65307 }
65308 if (irqs_disabled()) {
65309 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
65310 + msg2 = " disabled interrupts";
65311 local_irq_enable();
65312 }
65313 - if (msgbuf[0]) {
65314 - printk("initcall %pF returned with %s\n", fn, msgbuf);
65315 + if (msgbuf[0] || *msg1 || *msg2) {
65316 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
65317 }
65318
65319 return ret;
65320 @@ -820,7 +866,7 @@ static int __init kernel_init(void * unused)
65321 do_basic_setup();
65322
65323 /* Open the /dev/console on the rootfs, this should never fail */
65324 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65325 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65326 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65327
65328 (void) sys_dup(0);
65329 @@ -833,11 +879,13 @@ static int __init kernel_init(void * unused)
65330 if (!ramdisk_execute_command)
65331 ramdisk_execute_command = "/init";
65332
65333 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65334 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65335 ramdisk_execute_command = NULL;
65336 prepare_namespace();
65337 }
65338
65339 + grsecurity_init();
65340 +
65341 /*
65342 * Ok, we have completed the initial bootup, and
65343 * we're essentially up and running. Get rid of the
65344 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65345 index 5b4293d..f179875 100644
65346 --- a/ipc/mqueue.c
65347 +++ b/ipc/mqueue.c
65348 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65349 mq_bytes = (mq_msg_tblsz +
65350 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
65351
65352 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65353 spin_lock(&mq_lock);
65354 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65355 u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE)) {
65356 diff --git a/ipc/msg.c b/ipc/msg.c
65357 index 7385de2..a8180e08 100644
65358 --- a/ipc/msg.c
65359 +++ b/ipc/msg.c
65360 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65361 return security_msg_queue_associate(msq, msgflg);
65362 }
65363
65364 +static struct ipc_ops msg_ops = {
65365 + .getnew = newque,
65366 + .associate = msg_security,
65367 + .more_checks = NULL
65368 +};
65369 +
65370 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65371 {
65372 struct ipc_namespace *ns;
65373 - struct ipc_ops msg_ops;
65374 struct ipc_params msg_params;
65375
65376 ns = current->nsproxy->ipc_ns;
65377
65378 - msg_ops.getnew = newque;
65379 - msg_ops.associate = msg_security;
65380 - msg_ops.more_checks = NULL;
65381 -
65382 msg_params.key = key;
65383 msg_params.flg = msgflg;
65384
65385 diff --git a/ipc/sem.c b/ipc/sem.c
65386 index 5215a81..cfc0cac 100644
65387 --- a/ipc/sem.c
65388 +++ b/ipc/sem.c
65389 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65390 return 0;
65391 }
65392
65393 +static struct ipc_ops sem_ops = {
65394 + .getnew = newary,
65395 + .associate = sem_security,
65396 + .more_checks = sem_more_checks
65397 +};
65398 +
65399 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65400 {
65401 struct ipc_namespace *ns;
65402 - struct ipc_ops sem_ops;
65403 struct ipc_params sem_params;
65404
65405 ns = current->nsproxy->ipc_ns;
65406 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65407 if (nsems < 0 || nsems > ns->sc_semmsl)
65408 return -EINVAL;
65409
65410 - sem_ops.getnew = newary;
65411 - sem_ops.associate = sem_security;
65412 - sem_ops.more_checks = sem_more_checks;
65413 -
65414 sem_params.key = key;
65415 sem_params.flg = semflg;
65416 sem_params.u.nsems = nsems;
65417 diff --git a/ipc/shm.c b/ipc/shm.c
65418 index b76be5b..859e750 100644
65419 --- a/ipc/shm.c
65420 +++ b/ipc/shm.c
65421 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65422 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65423 #endif
65424
65425 +#ifdef CONFIG_GRKERNSEC
65426 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65427 + const time_t shm_createtime, const uid_t cuid,
65428 + const int shmid);
65429 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65430 + const time_t shm_createtime);
65431 +#endif
65432 +
65433 void shm_init_ns(struct ipc_namespace *ns)
65434 {
65435 ns->shm_ctlmax = SHMMAX;
65436 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65437 shp->shm_lprid = 0;
65438 shp->shm_atim = shp->shm_dtim = 0;
65439 shp->shm_ctim = get_seconds();
65440 +#ifdef CONFIG_GRKERNSEC
65441 + {
65442 + struct timespec timeval;
65443 + do_posix_clock_monotonic_gettime(&timeval);
65444 +
65445 + shp->shm_createtime = timeval.tv_sec;
65446 + }
65447 +#endif
65448 shp->shm_segsz = size;
65449 shp->shm_nattch = 0;
65450 shp->shm_file = file;
65451 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65452 return 0;
65453 }
65454
65455 +static struct ipc_ops shm_ops = {
65456 + .getnew = newseg,
65457 + .associate = shm_security,
65458 + .more_checks = shm_more_checks
65459 +};
65460 +
65461 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65462 {
65463 struct ipc_namespace *ns;
65464 - struct ipc_ops shm_ops;
65465 struct ipc_params shm_params;
65466
65467 ns = current->nsproxy->ipc_ns;
65468
65469 - shm_ops.getnew = newseg;
65470 - shm_ops.associate = shm_security;
65471 - shm_ops.more_checks = shm_more_checks;
65472 -
65473 shm_params.key = key;
65474 shm_params.flg = shmflg;
65475 shm_params.u.size = size;
65476 @@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65477 f_mode = FMODE_READ | FMODE_WRITE;
65478 }
65479 if (shmflg & SHM_EXEC) {
65480 +
65481 +#ifdef CONFIG_PAX_MPROTECT
65482 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
65483 + goto out;
65484 +#endif
65485 +
65486 prot |= PROT_EXEC;
65487 acc_mode |= S_IXUGO;
65488 }
65489 @@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65490 if (err)
65491 goto out_unlock;
65492
65493 +#ifdef CONFIG_GRKERNSEC
65494 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65495 + shp->shm_perm.cuid, shmid) ||
65496 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65497 + err = -EACCES;
65498 + goto out_unlock;
65499 + }
65500 +#endif
65501 +
65502 path = shp->shm_file->f_path;
65503 path_get(&path);
65504 shp->shm_nattch++;
65505 +#ifdef CONFIG_GRKERNSEC
65506 + shp->shm_lapid = current->pid;
65507 +#endif
65508 size = i_size_read(path.dentry->d_inode);
65509 shm_unlock(shp);
65510
65511 diff --git a/kernel/acct.c b/kernel/acct.c
65512 index fa7eb3d..7faf116 100644
65513 --- a/kernel/acct.c
65514 +++ b/kernel/acct.c
65515 @@ -570,7 +570,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65516 */
65517 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65518 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65519 - file->f_op->write(file, (char *)&ac,
65520 + file->f_op->write(file, (char __force_user *)&ac,
65521 sizeof(acct_t), &file->f_pos);
65522 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65523 set_fs(fs);
65524 diff --git a/kernel/audit.c b/kernel/audit.c
65525 index 09fae26..ed71d5b 100644
65526 --- a/kernel/audit.c
65527 +++ b/kernel/audit.c
65528 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65529 3) suppressed due to audit_rate_limit
65530 4) suppressed due to audit_backlog_limit
65531 */
65532 -static atomic_t audit_lost = ATOMIC_INIT(0);
65533 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65534
65535 /* The netlink socket. */
65536 static struct sock *audit_sock;
65537 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65538 unsigned long now;
65539 int print;
65540
65541 - atomic_inc(&audit_lost);
65542 + atomic_inc_unchecked(&audit_lost);
65543
65544 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65545
65546 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65547 printk(KERN_WARNING
65548 "audit: audit_lost=%d audit_rate_limit=%d "
65549 "audit_backlog_limit=%d\n",
65550 - atomic_read(&audit_lost),
65551 + atomic_read_unchecked(&audit_lost),
65552 audit_rate_limit,
65553 audit_backlog_limit);
65554 audit_panic(message);
65555 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65556 status_set.pid = audit_pid;
65557 status_set.rate_limit = audit_rate_limit;
65558 status_set.backlog_limit = audit_backlog_limit;
65559 - status_set.lost = atomic_read(&audit_lost);
65560 + status_set.lost = atomic_read_unchecked(&audit_lost);
65561 status_set.backlog = skb_queue_len(&audit_skb_queue);
65562 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65563 &status_set, sizeof(status_set));
65564 @@ -1260,12 +1260,13 @@ static void audit_log_vformat(struct audit_buffer *ab, const char *fmt,
65565 avail = audit_expand(ab,
65566 max_t(unsigned, AUDIT_BUFSIZ, 1+len-avail));
65567 if (!avail)
65568 - goto out;
65569 + goto out_va_end;
65570 len = vsnprintf(skb_tail_pointer(skb), avail, fmt, args2);
65571 }
65572 - va_end(args2);
65573 if (len > 0)
65574 skb_put(skb, len);
65575 +out_va_end:
65576 + va_end(args2);
65577 out:
65578 return;
65579 }
65580 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65581 index 47b7fc1..c003c33 100644
65582 --- a/kernel/auditsc.c
65583 +++ b/kernel/auditsc.c
65584 @@ -1166,8 +1166,8 @@ static void audit_log_execve_info(struct audit_context *context,
65585 struct audit_buffer **ab,
65586 struct audit_aux_data_execve *axi)
65587 {
65588 - int i;
65589 - size_t len, len_sent = 0;
65590 + int i, len;
65591 + size_t len_sent = 0;
65592 const char __user *p;
65593 char *buf;
65594
65595 @@ -2118,7 +2118,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65596 }
65597
65598 /* global counter which is incremented every time something logs in */
65599 -static atomic_t session_id = ATOMIC_INIT(0);
65600 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65601
65602 /**
65603 * audit_set_loginuid - set a task's audit_context loginuid
65604 @@ -2131,7 +2131,7 @@ static atomic_t session_id = ATOMIC_INIT(0);
65605 */
65606 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
65607 {
65608 - unsigned int sessionid = atomic_inc_return(&session_id);
65609 + unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
65610 struct audit_context *context = task->audit_context;
65611
65612 if (context && context->in_syscall) {
65613 diff --git a/kernel/capability.c b/kernel/capability.c
65614 index b463871..fa3ea1f 100644
65615 --- a/kernel/capability.c
65616 +++ b/kernel/capability.c
65617 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65618 * before modification is attempted and the application
65619 * fails.
65620 */
65621 + if (tocopy > ARRAY_SIZE(kdata))
65622 + return -EFAULT;
65623 +
65624 if (copy_to_user(dataptr, kdata, tocopy
65625 * sizeof(struct __user_cap_data_struct))) {
65626 return -EFAULT;
65627 @@ -374,7 +377,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
65628 BUG();
65629 }
65630
65631 - if (security_capable(ns, current_cred(), cap) == 0) {
65632 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable(cap)) {
65633 current->flags |= PF_SUPERPRIV;
65634 return true;
65635 }
65636 @@ -382,6 +385,27 @@ bool ns_capable(struct user_namespace *ns, int cap)
65637 }
65638 EXPORT_SYMBOL(ns_capable);
65639
65640 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
65641 +{
65642 + if (unlikely(!cap_valid(cap))) {
65643 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
65644 + BUG();
65645 + }
65646 +
65647 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable_nolog(cap)) {
65648 + current->flags |= PF_SUPERPRIV;
65649 + return true;
65650 + }
65651 + return false;
65652 +}
65653 +EXPORT_SYMBOL(ns_capable_nolog);
65654 +
65655 +bool capable_nolog(int cap)
65656 +{
65657 + return ns_capable_nolog(&init_user_ns, cap);
65658 +}
65659 +EXPORT_SYMBOL(capable_nolog);
65660 +
65661 /**
65662 * task_ns_capable - Determine whether current task has a superior
65663 * capability targeted at a specific task's user namespace.
65664 @@ -396,6 +420,12 @@ bool task_ns_capable(struct task_struct *t, int cap)
65665 }
65666 EXPORT_SYMBOL(task_ns_capable);
65667
65668 +bool task_ns_capable_nolog(struct task_struct *t, int cap)
65669 +{
65670 + return ns_capable_nolog(task_cred_xxx(t, user)->user_ns, cap);
65671 +}
65672 +EXPORT_SYMBOL(task_ns_capable_nolog);
65673 +
65674 /**
65675 * nsown_capable - Check superior capability to one's own user_ns
65676 * @cap: The capability in question
65677 diff --git a/kernel/compat.c b/kernel/compat.c
65678 index f346ced..aa2b1f4 100644
65679 --- a/kernel/compat.c
65680 +++ b/kernel/compat.c
65681 @@ -13,6 +13,7 @@
65682
65683 #include <linux/linkage.h>
65684 #include <linux/compat.h>
65685 +#include <linux/module.h>
65686 #include <linux/errno.h>
65687 #include <linux/time.h>
65688 #include <linux/signal.h>
65689 @@ -168,7 +169,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
65690 mm_segment_t oldfs;
65691 long ret;
65692
65693 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
65694 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
65695 oldfs = get_fs();
65696 set_fs(KERNEL_DS);
65697 ret = hrtimer_nanosleep_restart(restart);
65698 @@ -200,7 +201,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
65699 oldfs = get_fs();
65700 set_fs(KERNEL_DS);
65701 ret = hrtimer_nanosleep(&tu,
65702 - rmtp ? (struct timespec __user *)&rmt : NULL,
65703 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
65704 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
65705 set_fs(oldfs);
65706
65707 @@ -309,7 +310,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
65708 mm_segment_t old_fs = get_fs();
65709
65710 set_fs(KERNEL_DS);
65711 - ret = sys_sigpending((old_sigset_t __user *) &s);
65712 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
65713 set_fs(old_fs);
65714 if (ret == 0)
65715 ret = put_user(s, set);
65716 @@ -332,8 +333,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
65717 old_fs = get_fs();
65718 set_fs(KERNEL_DS);
65719 ret = sys_sigprocmask(how,
65720 - set ? (old_sigset_t __user *) &s : NULL,
65721 - oset ? (old_sigset_t __user *) &s : NULL);
65722 + set ? (old_sigset_t __force_user *) &s : NULL,
65723 + oset ? (old_sigset_t __force_user *) &s : NULL);
65724 set_fs(old_fs);
65725 if (ret == 0)
65726 if (oset)
65727 @@ -370,7 +371,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
65728 mm_segment_t old_fs = get_fs();
65729
65730 set_fs(KERNEL_DS);
65731 - ret = sys_old_getrlimit(resource, &r);
65732 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
65733 set_fs(old_fs);
65734
65735 if (!ret) {
65736 @@ -442,7 +443,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
65737 mm_segment_t old_fs = get_fs();
65738
65739 set_fs(KERNEL_DS);
65740 - ret = sys_getrusage(who, (struct rusage __user *) &r);
65741 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
65742 set_fs(old_fs);
65743
65744 if (ret)
65745 @@ -469,8 +470,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
65746 set_fs (KERNEL_DS);
65747 ret = sys_wait4(pid,
65748 (stat_addr ?
65749 - (unsigned int __user *) &status : NULL),
65750 - options, (struct rusage __user *) &r);
65751 + (unsigned int __force_user *) &status : NULL),
65752 + options, (struct rusage __force_user *) &r);
65753 set_fs (old_fs);
65754
65755 if (ret > 0) {
65756 @@ -495,8 +496,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
65757 memset(&info, 0, sizeof(info));
65758
65759 set_fs(KERNEL_DS);
65760 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
65761 - uru ? (struct rusage __user *)&ru : NULL);
65762 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
65763 + uru ? (struct rusage __force_user *)&ru : NULL);
65764 set_fs(old_fs);
65765
65766 if ((ret < 0) || (info.si_signo == 0))
65767 @@ -626,8 +627,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
65768 oldfs = get_fs();
65769 set_fs(KERNEL_DS);
65770 err = sys_timer_settime(timer_id, flags,
65771 - (struct itimerspec __user *) &newts,
65772 - (struct itimerspec __user *) &oldts);
65773 + (struct itimerspec __force_user *) &newts,
65774 + (struct itimerspec __force_user *) &oldts);
65775 set_fs(oldfs);
65776 if (!err && old && put_compat_itimerspec(old, &oldts))
65777 return -EFAULT;
65778 @@ -644,7 +645,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
65779 oldfs = get_fs();
65780 set_fs(KERNEL_DS);
65781 err = sys_timer_gettime(timer_id,
65782 - (struct itimerspec __user *) &ts);
65783 + (struct itimerspec __force_user *) &ts);
65784 set_fs(oldfs);
65785 if (!err && put_compat_itimerspec(setting, &ts))
65786 return -EFAULT;
65787 @@ -663,7 +664,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
65788 oldfs = get_fs();
65789 set_fs(KERNEL_DS);
65790 err = sys_clock_settime(which_clock,
65791 - (struct timespec __user *) &ts);
65792 + (struct timespec __force_user *) &ts);
65793 set_fs(oldfs);
65794 return err;
65795 }
65796 @@ -678,7 +679,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
65797 oldfs = get_fs();
65798 set_fs(KERNEL_DS);
65799 err = sys_clock_gettime(which_clock,
65800 - (struct timespec __user *) &ts);
65801 + (struct timespec __force_user *) &ts);
65802 set_fs(oldfs);
65803 if (!err && put_compat_timespec(&ts, tp))
65804 return -EFAULT;
65805 @@ -698,7 +699,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
65806
65807 oldfs = get_fs();
65808 set_fs(KERNEL_DS);
65809 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
65810 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
65811 set_fs(oldfs);
65812
65813 err = compat_put_timex(utp, &txc);
65814 @@ -718,7 +719,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
65815 oldfs = get_fs();
65816 set_fs(KERNEL_DS);
65817 err = sys_clock_getres(which_clock,
65818 - (struct timespec __user *) &ts);
65819 + (struct timespec __force_user *) &ts);
65820 set_fs(oldfs);
65821 if (!err && tp && put_compat_timespec(&ts, tp))
65822 return -EFAULT;
65823 @@ -730,9 +731,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
65824 long err;
65825 mm_segment_t oldfs;
65826 struct timespec tu;
65827 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
65828 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
65829
65830 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
65831 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
65832 oldfs = get_fs();
65833 set_fs(KERNEL_DS);
65834 err = clock_nanosleep_restart(restart);
65835 @@ -764,8 +765,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
65836 oldfs = get_fs();
65837 set_fs(KERNEL_DS);
65838 err = sys_clock_nanosleep(which_clock, flags,
65839 - (struct timespec __user *) &in,
65840 - (struct timespec __user *) &out);
65841 + (struct timespec __force_user *) &in,
65842 + (struct timespec __force_user *) &out);
65843 set_fs(oldfs);
65844
65845 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
65846 diff --git a/kernel/configs.c b/kernel/configs.c
65847 index 42e8fa0..9e7406b 100644
65848 --- a/kernel/configs.c
65849 +++ b/kernel/configs.c
65850 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
65851 struct proc_dir_entry *entry;
65852
65853 /* create the current config file */
65854 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
65855 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
65856 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
65857 + &ikconfig_file_ops);
65858 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65859 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
65860 + &ikconfig_file_ops);
65861 +#endif
65862 +#else
65863 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
65864 &ikconfig_file_ops);
65865 +#endif
65866 +
65867 if (!entry)
65868 return -ENOMEM;
65869
65870 diff --git a/kernel/cred.c b/kernel/cred.c
65871 index 5791612..a3c04dc 100644
65872 --- a/kernel/cred.c
65873 +++ b/kernel/cred.c
65874 @@ -204,6 +204,15 @@ void exit_creds(struct task_struct *tsk)
65875 validate_creds(cred);
65876 put_cred(cred);
65877 }
65878 +
65879 +#ifdef CONFIG_GRKERNSEC_SETXID
65880 + cred = (struct cred *) tsk->delayed_cred;
65881 + if (cred) {
65882 + tsk->delayed_cred = NULL;
65883 + validate_creds(cred);
65884 + put_cred(cred);
65885 + }
65886 +#endif
65887 }
65888
65889 /**
65890 @@ -470,7 +479,7 @@ error_put:
65891 * Always returns 0 thus allowing this function to be tail-called at the end
65892 * of, say, sys_setgid().
65893 */
65894 -int commit_creds(struct cred *new)
65895 +static int __commit_creds(struct cred *new)
65896 {
65897 struct task_struct *task = current;
65898 const struct cred *old = task->real_cred;
65899 @@ -489,6 +498,8 @@ int commit_creds(struct cred *new)
65900
65901 get_cred(new); /* we will require a ref for the subj creds too */
65902
65903 + gr_set_role_label(task, new->uid, new->gid);
65904 +
65905 /* dumpability changes */
65906 if (old->euid != new->euid ||
65907 old->egid != new->egid ||
65908 @@ -538,6 +549,92 @@ int commit_creds(struct cred *new)
65909 put_cred(old);
65910 return 0;
65911 }
65912 +#ifdef CONFIG_GRKERNSEC_SETXID
65913 +extern int set_user(struct cred *new);
65914 +
65915 +void gr_delayed_cred_worker(void)
65916 +{
65917 + const struct cred *new = current->delayed_cred;
65918 + struct cred *ncred;
65919 +
65920 + current->delayed_cred = NULL;
65921 +
65922 + if (current_uid() && new != NULL) {
65923 + // from doing get_cred on it when queueing this
65924 + put_cred(new);
65925 + return;
65926 + } else if (new == NULL)
65927 + return;
65928 +
65929 + ncred = prepare_creds();
65930 + if (!ncred)
65931 + goto die;
65932 + // uids
65933 + ncred->uid = new->uid;
65934 + ncred->euid = new->euid;
65935 + ncred->suid = new->suid;
65936 + ncred->fsuid = new->fsuid;
65937 + // gids
65938 + ncred->gid = new->gid;
65939 + ncred->egid = new->egid;
65940 + ncred->sgid = new->sgid;
65941 + ncred->fsgid = new->fsgid;
65942 + // groups
65943 + if (set_groups(ncred, new->group_info) < 0) {
65944 + abort_creds(ncred);
65945 + goto die;
65946 + }
65947 + // caps
65948 + ncred->securebits = new->securebits;
65949 + ncred->cap_inheritable = new->cap_inheritable;
65950 + ncred->cap_permitted = new->cap_permitted;
65951 + ncred->cap_effective = new->cap_effective;
65952 + ncred->cap_bset = new->cap_bset;
65953 +
65954 + if (set_user(ncred)) {
65955 + abort_creds(ncred);
65956 + goto die;
65957 + }
65958 +
65959 + // from doing get_cred on it when queueing this
65960 + put_cred(new);
65961 +
65962 + __commit_creds(ncred);
65963 + return;
65964 +die:
65965 + // from doing get_cred on it when queueing this
65966 + put_cred(new);
65967 + do_group_exit(SIGKILL);
65968 +}
65969 +#endif
65970 +
65971 +int commit_creds(struct cred *new)
65972 +{
65973 +#ifdef CONFIG_GRKERNSEC_SETXID
65974 + struct task_struct *t;
65975 +
65976 + /* we won't get called with tasklist_lock held for writing
65977 + and interrupts disabled as the cred struct in that case is
65978 + init_cred
65979 + */
65980 + if (grsec_enable_setxid && !current_is_single_threaded() &&
65981 + !current_uid() && new->uid) {
65982 + rcu_read_lock();
65983 + read_lock(&tasklist_lock);
65984 + for (t = next_thread(current); t != current;
65985 + t = next_thread(t)) {
65986 + if (t->delayed_cred == NULL) {
65987 + t->delayed_cred = get_cred(new);
65988 + set_tsk_need_resched(t);
65989 + }
65990 + }
65991 + read_unlock(&tasklist_lock);
65992 + rcu_read_unlock();
65993 + }
65994 +#endif
65995 + return __commit_creds(new);
65996 +}
65997 +
65998 EXPORT_SYMBOL(commit_creds);
65999
66000 /**
66001 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66002 index 0d7c087..01b8cef 100644
66003 --- a/kernel/debug/debug_core.c
66004 +++ b/kernel/debug/debug_core.c
66005 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66006 */
66007 static atomic_t masters_in_kgdb;
66008 static atomic_t slaves_in_kgdb;
66009 -static atomic_t kgdb_break_tasklet_var;
66010 +static atomic_unchecked_t kgdb_break_tasklet_var;
66011 atomic_t kgdb_setting_breakpoint;
66012
66013 struct task_struct *kgdb_usethread;
66014 @@ -129,7 +129,7 @@ int kgdb_single_step;
66015 static pid_t kgdb_sstep_pid;
66016
66017 /* to keep track of the CPU which is doing the single stepping*/
66018 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66019 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66020
66021 /*
66022 * If you are debugging a problem where roundup (the collection of
66023 @@ -542,7 +542,7 @@ return_normal:
66024 * kernel will only try for the value of sstep_tries before
66025 * giving up and continuing on.
66026 */
66027 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66028 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66029 (kgdb_info[cpu].task &&
66030 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66031 atomic_set(&kgdb_active, -1);
66032 @@ -636,8 +636,8 @@ cpu_master_loop:
66033 }
66034
66035 kgdb_restore:
66036 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66037 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66038 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66039 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66040 if (kgdb_info[sstep_cpu].task)
66041 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66042 else
66043 @@ -834,18 +834,18 @@ static void kgdb_unregister_callbacks(void)
66044 static void kgdb_tasklet_bpt(unsigned long ing)
66045 {
66046 kgdb_breakpoint();
66047 - atomic_set(&kgdb_break_tasklet_var, 0);
66048 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66049 }
66050
66051 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66052
66053 void kgdb_schedule_breakpoint(void)
66054 {
66055 - if (atomic_read(&kgdb_break_tasklet_var) ||
66056 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66057 atomic_read(&kgdb_active) != -1 ||
66058 atomic_read(&kgdb_setting_breakpoint))
66059 return;
66060 - atomic_inc(&kgdb_break_tasklet_var);
66061 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
66062 tasklet_schedule(&kgdb_tasklet_breakpoint);
66063 }
66064 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66065 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66066 index 63786e7..0780cac 100644
66067 --- a/kernel/debug/kdb/kdb_main.c
66068 +++ b/kernel/debug/kdb/kdb_main.c
66069 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
66070 list_for_each_entry(mod, kdb_modules, list) {
66071
66072 kdb_printf("%-20s%8u 0x%p ", mod->name,
66073 - mod->core_size, (void *)mod);
66074 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
66075 #ifdef CONFIG_MODULE_UNLOAD
66076 kdb_printf("%4d ", module_refcount(mod));
66077 #endif
66078 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
66079 kdb_printf(" (Loading)");
66080 else
66081 kdb_printf(" (Live)");
66082 - kdb_printf(" 0x%p", mod->module_core);
66083 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
66084
66085 #ifdef CONFIG_MODULE_UNLOAD
66086 {
66087 diff --git a/kernel/events/core.c b/kernel/events/core.c
66088 index 58690af..d903d75 100644
66089 --- a/kernel/events/core.c
66090 +++ b/kernel/events/core.c
66091 @@ -173,7 +173,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
66092 return 0;
66093 }
66094
66095 -static atomic64_t perf_event_id;
66096 +static atomic64_unchecked_t perf_event_id;
66097
66098 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
66099 enum event_type_t event_type);
66100 @@ -2540,7 +2540,7 @@ static void __perf_event_read(void *info)
66101
66102 static inline u64 perf_event_count(struct perf_event *event)
66103 {
66104 - return local64_read(&event->count) + atomic64_read(&event->child_count);
66105 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
66106 }
66107
66108 static u64 perf_event_read(struct perf_event *event)
66109 @@ -3065,9 +3065,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
66110 mutex_lock(&event->child_mutex);
66111 total += perf_event_read(event);
66112 *enabled += event->total_time_enabled +
66113 - atomic64_read(&event->child_total_time_enabled);
66114 + atomic64_read_unchecked(&event->child_total_time_enabled);
66115 *running += event->total_time_running +
66116 - atomic64_read(&event->child_total_time_running);
66117 + atomic64_read_unchecked(&event->child_total_time_running);
66118
66119 list_for_each_entry(child, &event->child_list, child_list) {
66120 total += perf_event_read(child);
66121 @@ -3474,10 +3474,10 @@ void perf_event_update_userpage(struct perf_event *event)
66122 userpg->offset -= local64_read(&event->hw.prev_count);
66123
66124 userpg->time_enabled = enabled +
66125 - atomic64_read(&event->child_total_time_enabled);
66126 + atomic64_read_unchecked(&event->child_total_time_enabled);
66127
66128 userpg->time_running = running +
66129 - atomic64_read(&event->child_total_time_running);
66130 + atomic64_read_unchecked(&event->child_total_time_running);
66131
66132 barrier();
66133 ++userpg->lock;
66134 @@ -3906,11 +3906,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
66135 values[n++] = perf_event_count(event);
66136 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
66137 values[n++] = enabled +
66138 - atomic64_read(&event->child_total_time_enabled);
66139 + atomic64_read_unchecked(&event->child_total_time_enabled);
66140 }
66141 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
66142 values[n++] = running +
66143 - atomic64_read(&event->child_total_time_running);
66144 + atomic64_read_unchecked(&event->child_total_time_running);
66145 }
66146 if (read_format & PERF_FORMAT_ID)
66147 values[n++] = primary_event_id(event);
66148 @@ -4561,12 +4561,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
66149 * need to add enough zero bytes after the string to handle
66150 * the 64bit alignment we do later.
66151 */
66152 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
66153 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
66154 if (!buf) {
66155 name = strncpy(tmp, "//enomem", sizeof(tmp));
66156 goto got_name;
66157 }
66158 - name = d_path(&file->f_path, buf, PATH_MAX);
66159 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
66160 if (IS_ERR(name)) {
66161 name = strncpy(tmp, "//toolong", sizeof(tmp));
66162 goto got_name;
66163 @@ -5921,7 +5921,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
66164 event->parent = parent_event;
66165
66166 event->ns = get_pid_ns(current->nsproxy->pid_ns);
66167 - event->id = atomic64_inc_return(&perf_event_id);
66168 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
66169
66170 event->state = PERF_EVENT_STATE_INACTIVE;
66171
66172 @@ -6443,10 +6443,10 @@ static void sync_child_event(struct perf_event *child_event,
66173 /*
66174 * Add back the child's count to the parent's count:
66175 */
66176 - atomic64_add(child_val, &parent_event->child_count);
66177 - atomic64_add(child_event->total_time_enabled,
66178 + atomic64_add_unchecked(child_val, &parent_event->child_count);
66179 + atomic64_add_unchecked(child_event->total_time_enabled,
66180 &parent_event->child_total_time_enabled);
66181 - atomic64_add(child_event->total_time_running,
66182 + atomic64_add_unchecked(child_event->total_time_running,
66183 &parent_event->child_total_time_running);
66184
66185 /*
66186 diff --git a/kernel/exit.c b/kernel/exit.c
66187 index e6e01b9..0a21b0a 100644
66188 --- a/kernel/exit.c
66189 +++ b/kernel/exit.c
66190 @@ -57,6 +57,10 @@
66191 #include <asm/pgtable.h>
66192 #include <asm/mmu_context.h>
66193
66194 +#ifdef CONFIG_GRKERNSEC
66195 +extern rwlock_t grsec_exec_file_lock;
66196 +#endif
66197 +
66198 static void exit_mm(struct task_struct * tsk);
66199
66200 static void __unhash_process(struct task_struct *p, bool group_dead)
66201 @@ -168,6 +172,10 @@ void release_task(struct task_struct * p)
66202 struct task_struct *leader;
66203 int zap_leader;
66204 repeat:
66205 +#ifdef CONFIG_NET
66206 + gr_del_task_from_ip_table(p);
66207 +#endif
66208 +
66209 /* don't need to get the RCU readlock here - the process is dead and
66210 * can't be modifying its own credentials. But shut RCU-lockdep up */
66211 rcu_read_lock();
66212 @@ -380,7 +388,7 @@ int allow_signal(int sig)
66213 * know it'll be handled, so that they don't get converted to
66214 * SIGKILL or just silently dropped.
66215 */
66216 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
66217 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
66218 recalc_sigpending();
66219 spin_unlock_irq(&current->sighand->siglock);
66220 return 0;
66221 @@ -416,6 +424,17 @@ void daemonize(const char *name, ...)
66222 vsnprintf(current->comm, sizeof(current->comm), name, args);
66223 va_end(args);
66224
66225 +#ifdef CONFIG_GRKERNSEC
66226 + write_lock(&grsec_exec_file_lock);
66227 + if (current->exec_file) {
66228 + fput(current->exec_file);
66229 + current->exec_file = NULL;
66230 + }
66231 + write_unlock(&grsec_exec_file_lock);
66232 +#endif
66233 +
66234 + gr_set_kernel_label(current);
66235 +
66236 /*
66237 * If we were started as result of loading a module, close all of the
66238 * user space pages. We don't need them, and if we didn't close them
66239 @@ -893,6 +912,8 @@ NORET_TYPE void do_exit(long code)
66240 struct task_struct *tsk = current;
66241 int group_dead;
66242
66243 + set_fs(USER_DS);
66244 +
66245 profile_task_exit(tsk);
66246
66247 WARN_ON(blk_needs_flush_plug(tsk));
66248 @@ -909,7 +930,6 @@ NORET_TYPE void do_exit(long code)
66249 * mm_release()->clear_child_tid() from writing to a user-controlled
66250 * kernel address.
66251 */
66252 - set_fs(USER_DS);
66253
66254 ptrace_event(PTRACE_EVENT_EXIT, code);
66255
66256 @@ -971,6 +991,9 @@ NORET_TYPE void do_exit(long code)
66257 tsk->exit_code = code;
66258 taskstats_exit(tsk, group_dead);
66259
66260 + gr_acl_handle_psacct(tsk, code);
66261 + gr_acl_handle_exit();
66262 +
66263 exit_mm(tsk);
66264
66265 if (group_dead)
66266 @@ -1068,7 +1091,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
66267 * Take down every thread in the group. This is called by fatal signals
66268 * as well as by sys_exit_group (below).
66269 */
66270 -NORET_TYPE void
66271 +__noreturn void
66272 do_group_exit(int exit_code)
66273 {
66274 struct signal_struct *sig = current->signal;
66275 diff --git a/kernel/fork.c b/kernel/fork.c
66276 index 0acf42c0..9e40e2e 100644
66277 --- a/kernel/fork.c
66278 +++ b/kernel/fork.c
66279 @@ -281,7 +281,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
66280 *stackend = STACK_END_MAGIC; /* for overflow detection */
66281
66282 #ifdef CONFIG_CC_STACKPROTECTOR
66283 - tsk->stack_canary = get_random_int();
66284 + tsk->stack_canary = pax_get_random_long();
66285 #endif
66286
66287 /*
66288 @@ -305,13 +305,77 @@ out:
66289 }
66290
66291 #ifdef CONFIG_MMU
66292 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
66293 +{
66294 + struct vm_area_struct *tmp;
66295 + unsigned long charge;
66296 + struct mempolicy *pol;
66297 + struct file *file;
66298 +
66299 + charge = 0;
66300 + if (mpnt->vm_flags & VM_ACCOUNT) {
66301 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66302 + if (security_vm_enough_memory(len))
66303 + goto fail_nomem;
66304 + charge = len;
66305 + }
66306 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66307 + if (!tmp)
66308 + goto fail_nomem;
66309 + *tmp = *mpnt;
66310 + tmp->vm_mm = mm;
66311 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
66312 + pol = mpol_dup(vma_policy(mpnt));
66313 + if (IS_ERR(pol))
66314 + goto fail_nomem_policy;
66315 + vma_set_policy(tmp, pol);
66316 + if (anon_vma_fork(tmp, mpnt))
66317 + goto fail_nomem_anon_vma_fork;
66318 + tmp->vm_flags &= ~VM_LOCKED;
66319 + tmp->vm_next = tmp->vm_prev = NULL;
66320 + tmp->vm_mirror = NULL;
66321 + file = tmp->vm_file;
66322 + if (file) {
66323 + struct inode *inode = file->f_path.dentry->d_inode;
66324 + struct address_space *mapping = file->f_mapping;
66325 +
66326 + get_file(file);
66327 + if (tmp->vm_flags & VM_DENYWRITE)
66328 + atomic_dec(&inode->i_writecount);
66329 + mutex_lock(&mapping->i_mmap_mutex);
66330 + if (tmp->vm_flags & VM_SHARED)
66331 + mapping->i_mmap_writable++;
66332 + flush_dcache_mmap_lock(mapping);
66333 + /* insert tmp into the share list, just after mpnt */
66334 + vma_prio_tree_add(tmp, mpnt);
66335 + flush_dcache_mmap_unlock(mapping);
66336 + mutex_unlock(&mapping->i_mmap_mutex);
66337 + }
66338 +
66339 + /*
66340 + * Clear hugetlb-related page reserves for children. This only
66341 + * affects MAP_PRIVATE mappings. Faults generated by the child
66342 + * are not guaranteed to succeed, even if read-only
66343 + */
66344 + if (is_vm_hugetlb_page(tmp))
66345 + reset_vma_resv_huge_pages(tmp);
66346 +
66347 + return tmp;
66348 +
66349 +fail_nomem_anon_vma_fork:
66350 + mpol_put(pol);
66351 +fail_nomem_policy:
66352 + kmem_cache_free(vm_area_cachep, tmp);
66353 +fail_nomem:
66354 + vm_unacct_memory(charge);
66355 + return NULL;
66356 +}
66357 +
66358 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66359 {
66360 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66361 struct rb_node **rb_link, *rb_parent;
66362 int retval;
66363 - unsigned long charge;
66364 - struct mempolicy *pol;
66365
66366 down_write(&oldmm->mmap_sem);
66367 flush_cache_dup_mm(oldmm);
66368 @@ -323,8 +387,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66369 mm->locked_vm = 0;
66370 mm->mmap = NULL;
66371 mm->mmap_cache = NULL;
66372 - mm->free_area_cache = oldmm->mmap_base;
66373 - mm->cached_hole_size = ~0UL;
66374 + mm->free_area_cache = oldmm->free_area_cache;
66375 + mm->cached_hole_size = oldmm->cached_hole_size;
66376 mm->map_count = 0;
66377 cpumask_clear(mm_cpumask(mm));
66378 mm->mm_rb = RB_ROOT;
66379 @@ -340,8 +404,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66380
66381 prev = NULL;
66382 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66383 - struct file *file;
66384 -
66385 if (mpnt->vm_flags & VM_DONTCOPY) {
66386 long pages = vma_pages(mpnt);
66387 mm->total_vm -= pages;
66388 @@ -349,53 +411,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66389 -pages);
66390 continue;
66391 }
66392 - charge = 0;
66393 - if (mpnt->vm_flags & VM_ACCOUNT) {
66394 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66395 - if (security_vm_enough_memory(len))
66396 - goto fail_nomem;
66397 - charge = len;
66398 + tmp = dup_vma(mm, mpnt);
66399 + if (!tmp) {
66400 + retval = -ENOMEM;
66401 + goto out;
66402 }
66403 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66404 - if (!tmp)
66405 - goto fail_nomem;
66406 - *tmp = *mpnt;
66407 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
66408 - pol = mpol_dup(vma_policy(mpnt));
66409 - retval = PTR_ERR(pol);
66410 - if (IS_ERR(pol))
66411 - goto fail_nomem_policy;
66412 - vma_set_policy(tmp, pol);
66413 - tmp->vm_mm = mm;
66414 - if (anon_vma_fork(tmp, mpnt))
66415 - goto fail_nomem_anon_vma_fork;
66416 - tmp->vm_flags &= ~VM_LOCKED;
66417 - tmp->vm_next = tmp->vm_prev = NULL;
66418 - file = tmp->vm_file;
66419 - if (file) {
66420 - struct inode *inode = file->f_path.dentry->d_inode;
66421 - struct address_space *mapping = file->f_mapping;
66422 -
66423 - get_file(file);
66424 - if (tmp->vm_flags & VM_DENYWRITE)
66425 - atomic_dec(&inode->i_writecount);
66426 - mutex_lock(&mapping->i_mmap_mutex);
66427 - if (tmp->vm_flags & VM_SHARED)
66428 - mapping->i_mmap_writable++;
66429 - flush_dcache_mmap_lock(mapping);
66430 - /* insert tmp into the share list, just after mpnt */
66431 - vma_prio_tree_add(tmp, mpnt);
66432 - flush_dcache_mmap_unlock(mapping);
66433 - mutex_unlock(&mapping->i_mmap_mutex);
66434 - }
66435 -
66436 - /*
66437 - * Clear hugetlb-related page reserves for children. This only
66438 - * affects MAP_PRIVATE mappings. Faults generated by the child
66439 - * are not guaranteed to succeed, even if read-only
66440 - */
66441 - if (is_vm_hugetlb_page(tmp))
66442 - reset_vma_resv_huge_pages(tmp);
66443
66444 /*
66445 * Link in the new vma and copy the page table entries.
66446 @@ -418,6 +438,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66447 if (retval)
66448 goto out;
66449 }
66450 +
66451 +#ifdef CONFIG_PAX_SEGMEXEC
66452 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66453 + struct vm_area_struct *mpnt_m;
66454 +
66455 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66456 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66457 +
66458 + if (!mpnt->vm_mirror)
66459 + continue;
66460 +
66461 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66462 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66463 + mpnt->vm_mirror = mpnt_m;
66464 + } else {
66465 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66466 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66467 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66468 + mpnt->vm_mirror->vm_mirror = mpnt;
66469 + }
66470 + }
66471 + BUG_ON(mpnt_m);
66472 + }
66473 +#endif
66474 +
66475 /* a new mm has just been created */
66476 arch_dup_mmap(oldmm, mm);
66477 retval = 0;
66478 @@ -426,14 +471,6 @@ out:
66479 flush_tlb_mm(oldmm);
66480 up_write(&oldmm->mmap_sem);
66481 return retval;
66482 -fail_nomem_anon_vma_fork:
66483 - mpol_put(pol);
66484 -fail_nomem_policy:
66485 - kmem_cache_free(vm_area_cachep, tmp);
66486 -fail_nomem:
66487 - retval = -ENOMEM;
66488 - vm_unacct_memory(charge);
66489 - goto out;
66490 }
66491
66492 static inline int mm_alloc_pgd(struct mm_struct *mm)
66493 @@ -645,6 +682,26 @@ struct mm_struct *get_task_mm(struct task_struct *task)
66494 }
66495 EXPORT_SYMBOL_GPL(get_task_mm);
66496
66497 +struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66498 +{
66499 + struct mm_struct *mm;
66500 + int err;
66501 +
66502 + err = mutex_lock_killable(&task->signal->cred_guard_mutex);
66503 + if (err)
66504 + return ERR_PTR(err);
66505 +
66506 + mm = get_task_mm(task);
66507 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66508 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66509 + mmput(mm);
66510 + mm = ERR_PTR(-EACCES);
66511 + }
66512 + mutex_unlock(&task->signal->cred_guard_mutex);
66513 +
66514 + return mm;
66515 +}
66516 +
66517 /* Please note the differences between mmput and mm_release.
66518 * mmput is called whenever we stop holding onto a mm_struct,
66519 * error success whatever.
66520 @@ -830,13 +887,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66521 spin_unlock(&fs->lock);
66522 return -EAGAIN;
66523 }
66524 - fs->users++;
66525 + atomic_inc(&fs->users);
66526 spin_unlock(&fs->lock);
66527 return 0;
66528 }
66529 tsk->fs = copy_fs_struct(fs);
66530 if (!tsk->fs)
66531 return -ENOMEM;
66532 + gr_set_chroot_entries(tsk, &tsk->fs->root);
66533 return 0;
66534 }
66535
66536 @@ -1100,6 +1158,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66537 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66538 #endif
66539 retval = -EAGAIN;
66540 +
66541 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66542 +
66543 if (atomic_read(&p->real_cred->user->processes) >=
66544 task_rlimit(p, RLIMIT_NPROC)) {
66545 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66546 @@ -1259,6 +1320,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66547 if (clone_flags & CLONE_THREAD)
66548 p->tgid = current->tgid;
66549
66550 + gr_copy_label(p);
66551 +
66552 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
66553 /*
66554 * Clear TID on mm_release()?
66555 @@ -1421,6 +1484,8 @@ bad_fork_cleanup_count:
66556 bad_fork_free:
66557 free_task(p);
66558 fork_out:
66559 + gr_log_forkfail(retval);
66560 +
66561 return ERR_PTR(retval);
66562 }
66563
66564 @@ -1521,6 +1586,8 @@ long do_fork(unsigned long clone_flags,
66565 if (clone_flags & CLONE_PARENT_SETTID)
66566 put_user(nr, parent_tidptr);
66567
66568 + gr_handle_brute_check();
66569 +
66570 if (clone_flags & CLONE_VFORK) {
66571 p->vfork_done = &vfork;
66572 init_completion(&vfork);
66573 @@ -1630,7 +1697,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66574 return 0;
66575
66576 /* don't need lock here; in the worst case we'll do useless copy */
66577 - if (fs->users == 1)
66578 + if (atomic_read(&fs->users) == 1)
66579 return 0;
66580
66581 *new_fsp = copy_fs_struct(fs);
66582 @@ -1719,7 +1786,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66583 fs = current->fs;
66584 spin_lock(&fs->lock);
66585 current->fs = new_fs;
66586 - if (--fs->users)
66587 + gr_set_chroot_entries(current, &current->fs->root);
66588 + if (atomic_dec_return(&fs->users))
66589 new_fs = NULL;
66590 else
66591 new_fs = fs;
66592 diff --git a/kernel/futex.c b/kernel/futex.c
66593 index 1614be2..37abc7e 100644
66594 --- a/kernel/futex.c
66595 +++ b/kernel/futex.c
66596 @@ -54,6 +54,7 @@
66597 #include <linux/mount.h>
66598 #include <linux/pagemap.h>
66599 #include <linux/syscalls.h>
66600 +#include <linux/ptrace.h>
66601 #include <linux/signal.h>
66602 #include <linux/export.h>
66603 #include <linux/magic.h>
66604 @@ -238,6 +239,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
66605 struct page *page, *page_head;
66606 int err, ro = 0;
66607
66608 +#ifdef CONFIG_PAX_SEGMEXEC
66609 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
66610 + return -EFAULT;
66611 +#endif
66612 +
66613 /*
66614 * The futex address must be "naturally" aligned.
66615 */
66616 @@ -2459,6 +2465,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
66617 if (!p)
66618 goto err_unlock;
66619 ret = -EPERM;
66620 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66621 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
66622 + goto err_unlock;
66623 +#endif
66624 pcred = __task_cred(p);
66625 /* If victim is in different user_ns, then uids are not
66626 comparable, so we must have CAP_SYS_PTRACE */
66627 @@ -2724,6 +2734,7 @@ static int __init futex_init(void)
66628 {
66629 u32 curval;
66630 int i;
66631 + mm_segment_t oldfs;
66632
66633 /*
66634 * This will fail and we want it. Some arch implementations do
66635 @@ -2735,8 +2746,11 @@ static int __init futex_init(void)
66636 * implementation, the non-functional ones will return
66637 * -ENOSYS.
66638 */
66639 + oldfs = get_fs();
66640 + set_fs(USER_DS);
66641 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
66642 futex_cmpxchg_enabled = 1;
66643 + set_fs(oldfs);
66644
66645 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
66646 plist_head_init(&futex_queues[i].chain);
66647 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
66648 index 5f9e689..582d46d 100644
66649 --- a/kernel/futex_compat.c
66650 +++ b/kernel/futex_compat.c
66651 @@ -10,6 +10,7 @@
66652 #include <linux/compat.h>
66653 #include <linux/nsproxy.h>
66654 #include <linux/futex.h>
66655 +#include <linux/ptrace.h>
66656
66657 #include <asm/uaccess.h>
66658
66659 @@ -136,7 +137,8 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
66660 {
66661 struct compat_robust_list_head __user *head;
66662 unsigned long ret;
66663 - const struct cred *cred = current_cred(), *pcred;
66664 + const struct cred *cred = current_cred();
66665 + const struct cred *pcred;
66666
66667 if (!futex_cmpxchg_enabled)
66668 return -ENOSYS;
66669 @@ -152,6 +154,10 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
66670 if (!p)
66671 goto err_unlock;
66672 ret = -EPERM;
66673 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66674 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
66675 + goto err_unlock;
66676 +#endif
66677 pcred = __task_cred(p);
66678 /* If victim is in different user_ns, then uids are not
66679 comparable, so we must have CAP_SYS_PTRACE */
66680 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
66681 index 9b22d03..6295b62 100644
66682 --- a/kernel/gcov/base.c
66683 +++ b/kernel/gcov/base.c
66684 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
66685 }
66686
66687 #ifdef CONFIG_MODULES
66688 -static inline int within(void *addr, void *start, unsigned long size)
66689 -{
66690 - return ((addr >= start) && (addr < start + size));
66691 -}
66692 -
66693 /* Update list and generate events when modules are unloaded. */
66694 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66695 void *data)
66696 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66697 prev = NULL;
66698 /* Remove entries located in module from linked list. */
66699 for (info = gcov_info_head; info; info = info->next) {
66700 - if (within(info, mod->module_core, mod->core_size)) {
66701 + if (within_module_core_rw((unsigned long)info, mod)) {
66702 if (prev)
66703 prev->next = info->next;
66704 else
66705 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
66706 index ae34bf5..4e2f3d0 100644
66707 --- a/kernel/hrtimer.c
66708 +++ b/kernel/hrtimer.c
66709 @@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
66710 local_irq_restore(flags);
66711 }
66712
66713 -static void run_hrtimer_softirq(struct softirq_action *h)
66714 +static void run_hrtimer_softirq(void)
66715 {
66716 hrtimer_peek_ahead_timers();
66717 }
66718 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
66719 index 66ff710..05a5128 100644
66720 --- a/kernel/jump_label.c
66721 +++ b/kernel/jump_label.c
66722 @@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
66723
66724 size = (((unsigned long)stop - (unsigned long)start)
66725 / sizeof(struct jump_entry));
66726 + pax_open_kernel();
66727 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
66728 + pax_close_kernel();
66729 }
66730
66731 static void jump_label_update(struct jump_label_key *key, int enable);
66732 @@ -303,10 +305,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
66733 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
66734 struct jump_entry *iter;
66735
66736 + pax_open_kernel();
66737 for (iter = iter_start; iter < iter_stop; iter++) {
66738 if (within_module_init(iter->code, mod))
66739 iter->code = 0;
66740 }
66741 + pax_close_kernel();
66742 }
66743
66744 static int
66745 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
66746 index 079f1d3..a407562 100644
66747 --- a/kernel/kallsyms.c
66748 +++ b/kernel/kallsyms.c
66749 @@ -11,6 +11,9 @@
66750 * Changed the compression method from stem compression to "table lookup"
66751 * compression (see scripts/kallsyms.c for a more complete description)
66752 */
66753 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66754 +#define __INCLUDED_BY_HIDESYM 1
66755 +#endif
66756 #include <linux/kallsyms.h>
66757 #include <linux/module.h>
66758 #include <linux/init.h>
66759 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
66760
66761 static inline int is_kernel_inittext(unsigned long addr)
66762 {
66763 + if (system_state != SYSTEM_BOOTING)
66764 + return 0;
66765 +
66766 if (addr >= (unsigned long)_sinittext
66767 && addr <= (unsigned long)_einittext)
66768 return 1;
66769 return 0;
66770 }
66771
66772 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66773 +#ifdef CONFIG_MODULES
66774 +static inline int is_module_text(unsigned long addr)
66775 +{
66776 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
66777 + return 1;
66778 +
66779 + addr = ktla_ktva(addr);
66780 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
66781 +}
66782 +#else
66783 +static inline int is_module_text(unsigned long addr)
66784 +{
66785 + return 0;
66786 +}
66787 +#endif
66788 +#endif
66789 +
66790 static inline int is_kernel_text(unsigned long addr)
66791 {
66792 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
66793 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
66794
66795 static inline int is_kernel(unsigned long addr)
66796 {
66797 +
66798 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66799 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
66800 + return 1;
66801 +
66802 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
66803 +#else
66804 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
66805 +#endif
66806 +
66807 return 1;
66808 return in_gate_area_no_mm(addr);
66809 }
66810
66811 static int is_ksym_addr(unsigned long addr)
66812 {
66813 +
66814 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66815 + if (is_module_text(addr))
66816 + return 0;
66817 +#endif
66818 +
66819 if (all_var)
66820 return is_kernel(addr);
66821
66822 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
66823
66824 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
66825 {
66826 - iter->name[0] = '\0';
66827 iter->nameoff = get_symbol_offset(new_pos);
66828 iter->pos = new_pos;
66829 }
66830 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
66831 {
66832 struct kallsym_iter *iter = m->private;
66833
66834 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66835 + if (current_uid())
66836 + return 0;
66837 +#endif
66838 +
66839 /* Some debugging symbols have no name. Ignore them. */
66840 if (!iter->name[0])
66841 return 0;
66842 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
66843 struct kallsym_iter *iter;
66844 int ret;
66845
66846 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
66847 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
66848 if (!iter)
66849 return -ENOMEM;
66850 reset_iter(iter, 0);
66851 diff --git a/kernel/kexec.c b/kernel/kexec.c
66852 index dc7bc08..4601964 100644
66853 --- a/kernel/kexec.c
66854 +++ b/kernel/kexec.c
66855 @@ -1048,7 +1048,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
66856 unsigned long flags)
66857 {
66858 struct compat_kexec_segment in;
66859 - struct kexec_segment out, __user *ksegments;
66860 + struct kexec_segment out;
66861 + struct kexec_segment __user *ksegments;
66862 unsigned long i, result;
66863
66864 /* Don't allow clients that don't understand the native
66865 diff --git a/kernel/kmod.c b/kernel/kmod.c
66866 index a4bea97..7a1ae9a 100644
66867 --- a/kernel/kmod.c
66868 +++ b/kernel/kmod.c
66869 @@ -73,13 +73,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
66870 * If module auto-loading support is disabled then this function
66871 * becomes a no-operation.
66872 */
66873 -int __request_module(bool wait, const char *fmt, ...)
66874 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
66875 {
66876 - va_list args;
66877 char module_name[MODULE_NAME_LEN];
66878 unsigned int max_modprobes;
66879 int ret;
66880 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
66881 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
66882 static char *envp[] = { "HOME=/",
66883 "TERM=linux",
66884 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
66885 @@ -88,9 +87,7 @@ int __request_module(bool wait, const char *fmt, ...)
66886 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
66887 static int kmod_loop_msg;
66888
66889 - va_start(args, fmt);
66890 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
66891 - va_end(args);
66892 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
66893 if (ret >= MODULE_NAME_LEN)
66894 return -ENAMETOOLONG;
66895
66896 @@ -98,6 +95,20 @@ int __request_module(bool wait, const char *fmt, ...)
66897 if (ret)
66898 return ret;
66899
66900 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66901 + if (!current_uid()) {
66902 + /* hack to workaround consolekit/udisks stupidity */
66903 + read_lock(&tasklist_lock);
66904 + if (!strcmp(current->comm, "mount") &&
66905 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
66906 + read_unlock(&tasklist_lock);
66907 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
66908 + return -EPERM;
66909 + }
66910 + read_unlock(&tasklist_lock);
66911 + }
66912 +#endif
66913 +
66914 /* If modprobe needs a service that is in a module, we get a recursive
66915 * loop. Limit the number of running kmod threads to max_threads/2 or
66916 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
66917 @@ -133,6 +144,47 @@ int __request_module(bool wait, const char *fmt, ...)
66918 atomic_dec(&kmod_concurrent);
66919 return ret;
66920 }
66921 +
66922 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
66923 +{
66924 + va_list args;
66925 + int ret;
66926 +
66927 + va_start(args, fmt);
66928 + ret = ____request_module(wait, module_param, fmt, args);
66929 + va_end(args);
66930 +
66931 + return ret;
66932 +}
66933 +
66934 +int __request_module(bool wait, const char *fmt, ...)
66935 +{
66936 + va_list args;
66937 + int ret;
66938 +
66939 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66940 + if (current_uid()) {
66941 + char module_param[MODULE_NAME_LEN];
66942 +
66943 + memset(module_param, 0, sizeof(module_param));
66944 +
66945 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
66946 +
66947 + va_start(args, fmt);
66948 + ret = ____request_module(wait, module_param, fmt, args);
66949 + va_end(args);
66950 +
66951 + return ret;
66952 + }
66953 +#endif
66954 +
66955 + va_start(args, fmt);
66956 + ret = ____request_module(wait, NULL, fmt, args);
66957 + va_end(args);
66958 +
66959 + return ret;
66960 +}
66961 +
66962 EXPORT_SYMBOL(__request_module);
66963 #endif /* CONFIG_MODULES */
66964
66965 @@ -222,7 +274,7 @@ static int wait_for_helper(void *data)
66966 *
66967 * Thus the __user pointer cast is valid here.
66968 */
66969 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
66970 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
66971
66972 /*
66973 * If ret is 0, either ____call_usermodehelper failed and the
66974 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
66975 index bc90b87..43c7d8c 100644
66976 --- a/kernel/kprobes.c
66977 +++ b/kernel/kprobes.c
66978 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
66979 * kernel image and loaded module images reside. This is required
66980 * so x86_64 can correctly handle the %rip-relative fixups.
66981 */
66982 - kip->insns = module_alloc(PAGE_SIZE);
66983 + kip->insns = module_alloc_exec(PAGE_SIZE);
66984 if (!kip->insns) {
66985 kfree(kip);
66986 return NULL;
66987 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
66988 */
66989 if (!list_is_singular(&kip->list)) {
66990 list_del(&kip->list);
66991 - module_free(NULL, kip->insns);
66992 + module_free_exec(NULL, kip->insns);
66993 kfree(kip);
66994 }
66995 return 1;
66996 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
66997 {
66998 int i, err = 0;
66999 unsigned long offset = 0, size = 0;
67000 - char *modname, namebuf[128];
67001 + char *modname, namebuf[KSYM_NAME_LEN];
67002 const char *symbol_name;
67003 void *addr;
67004 struct kprobe_blackpoint *kb;
67005 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67006 const char *sym = NULL;
67007 unsigned int i = *(loff_t *) v;
67008 unsigned long offset = 0;
67009 - char *modname, namebuf[128];
67010 + char *modname, namebuf[KSYM_NAME_LEN];
67011
67012 head = &kprobe_table[i];
67013 preempt_disable();
67014 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67015 index b2e08c9..01d8049 100644
67016 --- a/kernel/lockdep.c
67017 +++ b/kernel/lockdep.c
67018 @@ -592,6 +592,10 @@ static int static_obj(void *obj)
67019 end = (unsigned long) &_end,
67020 addr = (unsigned long) obj;
67021
67022 +#ifdef CONFIG_PAX_KERNEXEC
67023 + start = ktla_ktva(start);
67024 +#endif
67025 +
67026 /*
67027 * static variable?
67028 */
67029 @@ -731,6 +735,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67030 if (!static_obj(lock->key)) {
67031 debug_locks_off();
67032 printk("INFO: trying to register non-static key.\n");
67033 + printk("lock:%pS key:%pS.\n", lock, lock->key);
67034 printk("the code is fine but needs lockdep annotation.\n");
67035 printk("turning off the locking correctness validator.\n");
67036 dump_stack();
67037 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67038 if (!class)
67039 return 0;
67040 }
67041 - atomic_inc((atomic_t *)&class->ops);
67042 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67043 if (very_verbose(class)) {
67044 printk("\nacquire class [%p] %s", class->key, class->name);
67045 if (class->name_version > 1)
67046 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67047 index 91c32a0..b2c71c5 100644
67048 --- a/kernel/lockdep_proc.c
67049 +++ b/kernel/lockdep_proc.c
67050 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67051
67052 static void print_name(struct seq_file *m, struct lock_class *class)
67053 {
67054 - char str[128];
67055 + char str[KSYM_NAME_LEN];
67056 const char *name = class->name;
67057
67058 if (!name) {
67059 diff --git a/kernel/module.c b/kernel/module.c
67060 index 178333c..04e3408 100644
67061 --- a/kernel/module.c
67062 +++ b/kernel/module.c
67063 @@ -58,6 +58,7 @@
67064 #include <linux/jump_label.h>
67065 #include <linux/pfn.h>
67066 #include <linux/bsearch.h>
67067 +#include <linux/grsecurity.h>
67068
67069 #define CREATE_TRACE_POINTS
67070 #include <trace/events/module.h>
67071 @@ -119,7 +120,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
67072
67073 /* Bounds of module allocation, for speeding __module_address.
67074 * Protected by module_mutex. */
67075 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
67076 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
67077 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
67078
67079 int register_module_notifier(struct notifier_block * nb)
67080 {
67081 @@ -284,7 +286,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67082 return true;
67083
67084 list_for_each_entry_rcu(mod, &modules, list) {
67085 - struct symsearch arr[] = {
67086 + struct symsearch modarr[] = {
67087 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
67088 NOT_GPL_ONLY, false },
67089 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
67090 @@ -306,7 +308,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67091 #endif
67092 };
67093
67094 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
67095 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
67096 return true;
67097 }
67098 return false;
67099 @@ -438,7 +440,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
67100 static int percpu_modalloc(struct module *mod,
67101 unsigned long size, unsigned long align)
67102 {
67103 - if (align > PAGE_SIZE) {
67104 + if (align-1 >= PAGE_SIZE) {
67105 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
67106 mod->name, align, PAGE_SIZE);
67107 align = PAGE_SIZE;
67108 @@ -1183,7 +1185,7 @@ resolve_symbol_wait(struct module *mod,
67109 */
67110 #ifdef CONFIG_SYSFS
67111
67112 -#ifdef CONFIG_KALLSYMS
67113 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67114 static inline bool sect_empty(const Elf_Shdr *sect)
67115 {
67116 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
67117 @@ -1649,21 +1651,21 @@ static void set_section_ro_nx(void *base,
67118
67119 static void unset_module_core_ro_nx(struct module *mod)
67120 {
67121 - set_page_attributes(mod->module_core + mod->core_text_size,
67122 - mod->module_core + mod->core_size,
67123 + set_page_attributes(mod->module_core_rw,
67124 + mod->module_core_rw + mod->core_size_rw,
67125 set_memory_x);
67126 - set_page_attributes(mod->module_core,
67127 - mod->module_core + mod->core_ro_size,
67128 + set_page_attributes(mod->module_core_rx,
67129 + mod->module_core_rx + mod->core_size_rx,
67130 set_memory_rw);
67131 }
67132
67133 static void unset_module_init_ro_nx(struct module *mod)
67134 {
67135 - set_page_attributes(mod->module_init + mod->init_text_size,
67136 - mod->module_init + mod->init_size,
67137 + set_page_attributes(mod->module_init_rw,
67138 + mod->module_init_rw + mod->init_size_rw,
67139 set_memory_x);
67140 - set_page_attributes(mod->module_init,
67141 - mod->module_init + mod->init_ro_size,
67142 + set_page_attributes(mod->module_init_rx,
67143 + mod->module_init_rx + mod->init_size_rx,
67144 set_memory_rw);
67145 }
67146
67147 @@ -1674,14 +1676,14 @@ void set_all_modules_text_rw(void)
67148
67149 mutex_lock(&module_mutex);
67150 list_for_each_entry_rcu(mod, &modules, list) {
67151 - if ((mod->module_core) && (mod->core_text_size)) {
67152 - set_page_attributes(mod->module_core,
67153 - mod->module_core + mod->core_text_size,
67154 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
67155 + set_page_attributes(mod->module_core_rx,
67156 + mod->module_core_rx + mod->core_size_rx,
67157 set_memory_rw);
67158 }
67159 - if ((mod->module_init) && (mod->init_text_size)) {
67160 - set_page_attributes(mod->module_init,
67161 - mod->module_init + mod->init_text_size,
67162 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
67163 + set_page_attributes(mod->module_init_rx,
67164 + mod->module_init_rx + mod->init_size_rx,
67165 set_memory_rw);
67166 }
67167 }
67168 @@ -1695,14 +1697,14 @@ void set_all_modules_text_ro(void)
67169
67170 mutex_lock(&module_mutex);
67171 list_for_each_entry_rcu(mod, &modules, list) {
67172 - if ((mod->module_core) && (mod->core_text_size)) {
67173 - set_page_attributes(mod->module_core,
67174 - mod->module_core + mod->core_text_size,
67175 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
67176 + set_page_attributes(mod->module_core_rx,
67177 + mod->module_core_rx + mod->core_size_rx,
67178 set_memory_ro);
67179 }
67180 - if ((mod->module_init) && (mod->init_text_size)) {
67181 - set_page_attributes(mod->module_init,
67182 - mod->module_init + mod->init_text_size,
67183 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
67184 + set_page_attributes(mod->module_init_rx,
67185 + mod->module_init_rx + mod->init_size_rx,
67186 set_memory_ro);
67187 }
67188 }
67189 @@ -1748,16 +1750,19 @@ static void free_module(struct module *mod)
67190
67191 /* This may be NULL, but that's OK */
67192 unset_module_init_ro_nx(mod);
67193 - module_free(mod, mod->module_init);
67194 + module_free(mod, mod->module_init_rw);
67195 + module_free_exec(mod, mod->module_init_rx);
67196 kfree(mod->args);
67197 percpu_modfree(mod);
67198
67199 /* Free lock-classes: */
67200 - lockdep_free_key_range(mod->module_core, mod->core_size);
67201 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
67202 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
67203
67204 /* Finally, free the core (containing the module structure) */
67205 unset_module_core_ro_nx(mod);
67206 - module_free(mod, mod->module_core);
67207 + module_free_exec(mod, mod->module_core_rx);
67208 + module_free(mod, mod->module_core_rw);
67209
67210 #ifdef CONFIG_MPU
67211 update_protections(current->mm);
67212 @@ -1826,10 +1831,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67213 unsigned int i;
67214 int ret = 0;
67215 const struct kernel_symbol *ksym;
67216 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67217 + int is_fs_load = 0;
67218 + int register_filesystem_found = 0;
67219 + char *p;
67220 +
67221 + p = strstr(mod->args, "grsec_modharden_fs");
67222 + if (p) {
67223 + char *endptr = p + strlen("grsec_modharden_fs");
67224 + /* copy \0 as well */
67225 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
67226 + is_fs_load = 1;
67227 + }
67228 +#endif
67229
67230 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
67231 const char *name = info->strtab + sym[i].st_name;
67232
67233 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67234 + /* it's a real shame this will never get ripped and copied
67235 + upstream! ;(
67236 + */
67237 + if (is_fs_load && !strcmp(name, "register_filesystem"))
67238 + register_filesystem_found = 1;
67239 +#endif
67240 +
67241 switch (sym[i].st_shndx) {
67242 case SHN_COMMON:
67243 /* We compiled with -fno-common. These are not
67244 @@ -1850,7 +1876,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67245 ksym = resolve_symbol_wait(mod, info, name);
67246 /* Ok if resolved. */
67247 if (ksym && !IS_ERR(ksym)) {
67248 + pax_open_kernel();
67249 sym[i].st_value = ksym->value;
67250 + pax_close_kernel();
67251 break;
67252 }
67253
67254 @@ -1869,11 +1897,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67255 secbase = (unsigned long)mod_percpu(mod);
67256 else
67257 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
67258 + pax_open_kernel();
67259 sym[i].st_value += secbase;
67260 + pax_close_kernel();
67261 break;
67262 }
67263 }
67264
67265 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67266 + if (is_fs_load && !register_filesystem_found) {
67267 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
67268 + ret = -EPERM;
67269 + }
67270 +#endif
67271 +
67272 return ret;
67273 }
67274
67275 @@ -1977,22 +2014,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
67276 || s->sh_entsize != ~0UL
67277 || strstarts(sname, ".init"))
67278 continue;
67279 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
67280 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67281 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
67282 + else
67283 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
67284 DEBUGP("\t%s\n", name);
67285 }
67286 - switch (m) {
67287 - case 0: /* executable */
67288 - mod->core_size = debug_align(mod->core_size);
67289 - mod->core_text_size = mod->core_size;
67290 - break;
67291 - case 1: /* RO: text and ro-data */
67292 - mod->core_size = debug_align(mod->core_size);
67293 - mod->core_ro_size = mod->core_size;
67294 - break;
67295 - case 3: /* whole core */
67296 - mod->core_size = debug_align(mod->core_size);
67297 - break;
67298 - }
67299 }
67300
67301 DEBUGP("Init section allocation order:\n");
67302 @@ -2006,23 +2033,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67303 || s->sh_entsize != ~0UL
67304 || !strstarts(sname, ".init"))
67305 continue;
67306 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67307 - | INIT_OFFSET_MASK);
67308 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67309 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67310 + else
67311 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67312 + s->sh_entsize |= INIT_OFFSET_MASK;
67313 DEBUGP("\t%s\n", sname);
67314 }
67315 - switch (m) {
67316 - case 0: /* executable */
67317 - mod->init_size = debug_align(mod->init_size);
67318 - mod->init_text_size = mod->init_size;
67319 - break;
67320 - case 1: /* RO: text and ro-data */
67321 - mod->init_size = debug_align(mod->init_size);
67322 - mod->init_ro_size = mod->init_size;
67323 - break;
67324 - case 3: /* whole init */
67325 - mod->init_size = debug_align(mod->init_size);
67326 - break;
67327 - }
67328 }
67329 }
67330
67331 @@ -2187,7 +2204,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67332
67333 /* Put symbol section at end of init part of module. */
67334 symsect->sh_flags |= SHF_ALLOC;
67335 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67336 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67337 info->index.sym) | INIT_OFFSET_MASK;
67338 DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
67339
67340 @@ -2204,19 +2221,19 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67341 }
67342
67343 /* Append room for core symbols at end of core part. */
67344 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67345 - mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67346 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67347 + mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67348
67349 /* Put string table section at end of init part of module. */
67350 strsect->sh_flags |= SHF_ALLOC;
67351 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67352 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67353 info->index.str) | INIT_OFFSET_MASK;
67354 DEBUGP("\t%s\n", info->secstrings + strsect->sh_name);
67355
67356 /* Append room for core symbols' strings at end of core part. */
67357 - info->stroffs = mod->core_size;
67358 + info->stroffs = mod->core_size_rx;
67359 __set_bit(0, info->strmap);
67360 - mod->core_size += bitmap_weight(info->strmap, strsect->sh_size);
67361 + mod->core_size_rx += bitmap_weight(info->strmap, strsect->sh_size);
67362 }
67363
67364 static void add_kallsyms(struct module *mod, const struct load_info *info)
67365 @@ -2232,11 +2249,13 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67366 /* Make sure we get permanent strtab: don't use info->strtab. */
67367 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67368
67369 + pax_open_kernel();
67370 +
67371 /* Set types up while we still have access to sections. */
67372 for (i = 0; i < mod->num_symtab; i++)
67373 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67374
67375 - mod->core_symtab = dst = mod->module_core + info->symoffs;
67376 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67377 src = mod->symtab;
67378 *dst = *src;
67379 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
67380 @@ -2249,10 +2268,12 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67381 }
67382 mod->core_num_syms = ndst;
67383
67384 - mod->core_strtab = s = mod->module_core + info->stroffs;
67385 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67386 for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i)
67387 if (test_bit(i, info->strmap))
67388 *++s = mod->strtab[i];
67389 +
67390 + pax_close_kernel();
67391 }
67392 #else
67393 static inline void layout_symtab(struct module *mod, struct load_info *info)
67394 @@ -2286,17 +2307,33 @@ void * __weak module_alloc(unsigned long size)
67395 return size == 0 ? NULL : vmalloc_exec(size);
67396 }
67397
67398 -static void *module_alloc_update_bounds(unsigned long size)
67399 +static void *module_alloc_update_bounds_rw(unsigned long size)
67400 {
67401 void *ret = module_alloc(size);
67402
67403 if (ret) {
67404 mutex_lock(&module_mutex);
67405 /* Update module bounds. */
67406 - if ((unsigned long)ret < module_addr_min)
67407 - module_addr_min = (unsigned long)ret;
67408 - if ((unsigned long)ret + size > module_addr_max)
67409 - module_addr_max = (unsigned long)ret + size;
67410 + if ((unsigned long)ret < module_addr_min_rw)
67411 + module_addr_min_rw = (unsigned long)ret;
67412 + if ((unsigned long)ret + size > module_addr_max_rw)
67413 + module_addr_max_rw = (unsigned long)ret + size;
67414 + mutex_unlock(&module_mutex);
67415 + }
67416 + return ret;
67417 +}
67418 +
67419 +static void *module_alloc_update_bounds_rx(unsigned long size)
67420 +{
67421 + void *ret = module_alloc_exec(size);
67422 +
67423 + if (ret) {
67424 + mutex_lock(&module_mutex);
67425 + /* Update module bounds. */
67426 + if ((unsigned long)ret < module_addr_min_rx)
67427 + module_addr_min_rx = (unsigned long)ret;
67428 + if ((unsigned long)ret + size > module_addr_max_rx)
67429 + module_addr_max_rx = (unsigned long)ret + size;
67430 mutex_unlock(&module_mutex);
67431 }
67432 return ret;
67433 @@ -2474,8 +2511,14 @@ static struct module *setup_load_info(struct load_info *info)
67434 static int check_modinfo(struct module *mod, struct load_info *info)
67435 {
67436 const char *modmagic = get_modinfo(info, "vermagic");
67437 + const char *license = get_modinfo(info, "license");
67438 int err;
67439
67440 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67441 + if (!license || !license_is_gpl_compatible(license))
67442 + return -ENOEXEC;
67443 +#endif
67444 +
67445 /* This is allowed: modprobe --force will invalidate it. */
67446 if (!modmagic) {
67447 err = try_to_force_load(mod, "bad vermagic");
67448 @@ -2498,7 +2541,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67449 }
67450
67451 /* Set up license info based on the info section */
67452 - set_license(mod, get_modinfo(info, "license"));
67453 + set_license(mod, license);
67454
67455 return 0;
67456 }
67457 @@ -2592,7 +2635,7 @@ static int move_module(struct module *mod, struct load_info *info)
67458 void *ptr;
67459
67460 /* Do the allocs. */
67461 - ptr = module_alloc_update_bounds(mod->core_size);
67462 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67463 /*
67464 * The pointer to this block is stored in the module structure
67465 * which is inside the block. Just mark it as not being a
67466 @@ -2602,23 +2645,50 @@ static int move_module(struct module *mod, struct load_info *info)
67467 if (!ptr)
67468 return -ENOMEM;
67469
67470 - memset(ptr, 0, mod->core_size);
67471 - mod->module_core = ptr;
67472 + memset(ptr, 0, mod->core_size_rw);
67473 + mod->module_core_rw = ptr;
67474
67475 - ptr = module_alloc_update_bounds(mod->init_size);
67476 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67477 /*
67478 * The pointer to this block is stored in the module structure
67479 * which is inside the block. This block doesn't need to be
67480 * scanned as it contains data and code that will be freed
67481 * after the module is initialized.
67482 */
67483 - kmemleak_ignore(ptr);
67484 - if (!ptr && mod->init_size) {
67485 - module_free(mod, mod->module_core);
67486 + kmemleak_not_leak(ptr);
67487 + if (!ptr && mod->init_size_rw) {
67488 + module_free(mod, mod->module_core_rw);
67489 return -ENOMEM;
67490 }
67491 - memset(ptr, 0, mod->init_size);
67492 - mod->module_init = ptr;
67493 + memset(ptr, 0, mod->init_size_rw);
67494 + mod->module_init_rw = ptr;
67495 +
67496 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67497 + kmemleak_not_leak(ptr);
67498 + if (!ptr) {
67499 + module_free(mod, mod->module_init_rw);
67500 + module_free(mod, mod->module_core_rw);
67501 + return -ENOMEM;
67502 + }
67503 +
67504 + pax_open_kernel();
67505 + memset(ptr, 0, mod->core_size_rx);
67506 + pax_close_kernel();
67507 + mod->module_core_rx = ptr;
67508 +
67509 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67510 + kmemleak_not_leak(ptr);
67511 + if (!ptr && mod->init_size_rx) {
67512 + module_free_exec(mod, mod->module_core_rx);
67513 + module_free(mod, mod->module_init_rw);
67514 + module_free(mod, mod->module_core_rw);
67515 + return -ENOMEM;
67516 + }
67517 +
67518 + pax_open_kernel();
67519 + memset(ptr, 0, mod->init_size_rx);
67520 + pax_close_kernel();
67521 + mod->module_init_rx = ptr;
67522
67523 /* Transfer each section which specifies SHF_ALLOC */
67524 DEBUGP("final section addresses:\n");
67525 @@ -2629,16 +2699,45 @@ static int move_module(struct module *mod, struct load_info *info)
67526 if (!(shdr->sh_flags & SHF_ALLOC))
67527 continue;
67528
67529 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
67530 - dest = mod->module_init
67531 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67532 - else
67533 - dest = mod->module_core + shdr->sh_entsize;
67534 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67535 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67536 + dest = mod->module_init_rw
67537 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67538 + else
67539 + dest = mod->module_init_rx
67540 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67541 + } else {
67542 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67543 + dest = mod->module_core_rw + shdr->sh_entsize;
67544 + else
67545 + dest = mod->module_core_rx + shdr->sh_entsize;
67546 + }
67547 +
67548 + if (shdr->sh_type != SHT_NOBITS) {
67549 +
67550 +#ifdef CONFIG_PAX_KERNEXEC
67551 +#ifdef CONFIG_X86_64
67552 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67553 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67554 +#endif
67555 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67556 + pax_open_kernel();
67557 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67558 + pax_close_kernel();
67559 + } else
67560 +#endif
67561
67562 - if (shdr->sh_type != SHT_NOBITS)
67563 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67564 + }
67565 /* Update sh_addr to point to copy in image. */
67566 - shdr->sh_addr = (unsigned long)dest;
67567 +
67568 +#ifdef CONFIG_PAX_KERNEXEC
67569 + if (shdr->sh_flags & SHF_EXECINSTR)
67570 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
67571 + else
67572 +#endif
67573 +
67574 + shdr->sh_addr = (unsigned long)dest;
67575 DEBUGP("\t0x%lx %s\n",
67576 shdr->sh_addr, info->secstrings + shdr->sh_name);
67577 }
67578 @@ -2689,12 +2788,12 @@ static void flush_module_icache(const struct module *mod)
67579 * Do it before processing of module parameters, so the module
67580 * can provide parameter accessor functions of its own.
67581 */
67582 - if (mod->module_init)
67583 - flush_icache_range((unsigned long)mod->module_init,
67584 - (unsigned long)mod->module_init
67585 - + mod->init_size);
67586 - flush_icache_range((unsigned long)mod->module_core,
67587 - (unsigned long)mod->module_core + mod->core_size);
67588 + if (mod->module_init_rx)
67589 + flush_icache_range((unsigned long)mod->module_init_rx,
67590 + (unsigned long)mod->module_init_rx
67591 + + mod->init_size_rx);
67592 + flush_icache_range((unsigned long)mod->module_core_rx,
67593 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
67594
67595 set_fs(old_fs);
67596 }
67597 @@ -2774,8 +2873,10 @@ static void module_deallocate(struct module *mod, struct load_info *info)
67598 {
67599 kfree(info->strmap);
67600 percpu_modfree(mod);
67601 - module_free(mod, mod->module_init);
67602 - module_free(mod, mod->module_core);
67603 + module_free_exec(mod, mod->module_init_rx);
67604 + module_free_exec(mod, mod->module_core_rx);
67605 + module_free(mod, mod->module_init_rw);
67606 + module_free(mod, mod->module_core_rw);
67607 }
67608
67609 int __weak module_finalize(const Elf_Ehdr *hdr,
67610 @@ -2839,9 +2940,38 @@ static struct module *load_module(void __user *umod,
67611 if (err)
67612 goto free_unload;
67613
67614 + /* Now copy in args */
67615 + mod->args = strndup_user(uargs, ~0UL >> 1);
67616 + if (IS_ERR(mod->args)) {
67617 + err = PTR_ERR(mod->args);
67618 + goto free_unload;
67619 + }
67620 +
67621 /* Set up MODINFO_ATTR fields */
67622 setup_modinfo(mod, &info);
67623
67624 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67625 + {
67626 + char *p, *p2;
67627 +
67628 + if (strstr(mod->args, "grsec_modharden_netdev")) {
67629 + 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);
67630 + err = -EPERM;
67631 + goto free_modinfo;
67632 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
67633 + p += strlen("grsec_modharden_normal");
67634 + p2 = strstr(p, "_");
67635 + if (p2) {
67636 + *p2 = '\0';
67637 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
67638 + *p2 = '_';
67639 + }
67640 + err = -EPERM;
67641 + goto free_modinfo;
67642 + }
67643 + }
67644 +#endif
67645 +
67646 /* Fix up syms, so that st_value is a pointer to location. */
67647 err = simplify_symbols(mod, &info);
67648 if (err < 0)
67649 @@ -2857,13 +2987,6 @@ static struct module *load_module(void __user *umod,
67650
67651 flush_module_icache(mod);
67652
67653 - /* Now copy in args */
67654 - mod->args = strndup_user(uargs, ~0UL >> 1);
67655 - if (IS_ERR(mod->args)) {
67656 - err = PTR_ERR(mod->args);
67657 - goto free_arch_cleanup;
67658 - }
67659 -
67660 /* Mark state as coming so strong_try_module_get() ignores us. */
67661 mod->state = MODULE_STATE_COMING;
67662
67663 @@ -2921,11 +3044,10 @@ static struct module *load_module(void __user *umod,
67664 unlock:
67665 mutex_unlock(&module_mutex);
67666 synchronize_sched();
67667 - kfree(mod->args);
67668 - free_arch_cleanup:
67669 module_arch_cleanup(mod);
67670 free_modinfo:
67671 free_modinfo(mod);
67672 + kfree(mod->args);
67673 free_unload:
67674 module_unload_free(mod);
67675 free_module:
67676 @@ -2966,16 +3088,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67677 MODULE_STATE_COMING, mod);
67678
67679 /* Set RO and NX regions for core */
67680 - set_section_ro_nx(mod->module_core,
67681 - mod->core_text_size,
67682 - mod->core_ro_size,
67683 - mod->core_size);
67684 + set_section_ro_nx(mod->module_core_rx,
67685 + mod->core_size_rx,
67686 + mod->core_size_rx,
67687 + mod->core_size_rx);
67688
67689 /* Set RO and NX regions for init */
67690 - set_section_ro_nx(mod->module_init,
67691 - mod->init_text_size,
67692 - mod->init_ro_size,
67693 - mod->init_size);
67694 + set_section_ro_nx(mod->module_init_rx,
67695 + mod->init_size_rx,
67696 + mod->init_size_rx,
67697 + mod->init_size_rx);
67698
67699 do_mod_ctors(mod);
67700 /* Start the module */
67701 @@ -3021,11 +3143,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67702 mod->strtab = mod->core_strtab;
67703 #endif
67704 unset_module_init_ro_nx(mod);
67705 - module_free(mod, mod->module_init);
67706 - mod->module_init = NULL;
67707 - mod->init_size = 0;
67708 - mod->init_ro_size = 0;
67709 - mod->init_text_size = 0;
67710 + module_free(mod, mod->module_init_rw);
67711 + module_free_exec(mod, mod->module_init_rx);
67712 + mod->module_init_rw = NULL;
67713 + mod->module_init_rx = NULL;
67714 + mod->init_size_rw = 0;
67715 + mod->init_size_rx = 0;
67716 mutex_unlock(&module_mutex);
67717
67718 return 0;
67719 @@ -3056,10 +3179,16 @@ static const char *get_ksymbol(struct module *mod,
67720 unsigned long nextval;
67721
67722 /* At worse, next value is at end of module */
67723 - if (within_module_init(addr, mod))
67724 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
67725 + if (within_module_init_rx(addr, mod))
67726 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
67727 + else if (within_module_init_rw(addr, mod))
67728 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
67729 + else if (within_module_core_rx(addr, mod))
67730 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
67731 + else if (within_module_core_rw(addr, mod))
67732 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
67733 else
67734 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
67735 + return NULL;
67736
67737 /* Scan for closest preceding symbol, and next symbol. (ELF
67738 starts real symbols at 1). */
67739 @@ -3307,7 +3436,7 @@ static int m_show(struct seq_file *m, void *p)
67740 char buf[8];
67741
67742 seq_printf(m, "%s %u",
67743 - mod->name, mod->init_size + mod->core_size);
67744 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
67745 print_unload_info(m, mod);
67746
67747 /* Informative for users. */
67748 @@ -3316,7 +3445,7 @@ static int m_show(struct seq_file *m, void *p)
67749 mod->state == MODULE_STATE_COMING ? "Loading":
67750 "Live");
67751 /* Used by oprofile and other similar tools. */
67752 - seq_printf(m, " 0x%pK", mod->module_core);
67753 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
67754
67755 /* Taints info */
67756 if (mod->taints)
67757 @@ -3352,7 +3481,17 @@ static const struct file_operations proc_modules_operations = {
67758
67759 static int __init proc_modules_init(void)
67760 {
67761 +#ifndef CONFIG_GRKERNSEC_HIDESYM
67762 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67763 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67764 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67765 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
67766 +#else
67767 proc_create("modules", 0, NULL, &proc_modules_operations);
67768 +#endif
67769 +#else
67770 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67771 +#endif
67772 return 0;
67773 }
67774 module_init(proc_modules_init);
67775 @@ -3411,12 +3550,12 @@ struct module *__module_address(unsigned long addr)
67776 {
67777 struct module *mod;
67778
67779 - if (addr < module_addr_min || addr > module_addr_max)
67780 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
67781 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
67782 return NULL;
67783
67784 list_for_each_entry_rcu(mod, &modules, list)
67785 - if (within_module_core(addr, mod)
67786 - || within_module_init(addr, mod))
67787 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
67788 return mod;
67789 return NULL;
67790 }
67791 @@ -3450,11 +3589,20 @@ bool is_module_text_address(unsigned long addr)
67792 */
67793 struct module *__module_text_address(unsigned long addr)
67794 {
67795 - struct module *mod = __module_address(addr);
67796 + struct module *mod;
67797 +
67798 +#ifdef CONFIG_X86_32
67799 + addr = ktla_ktva(addr);
67800 +#endif
67801 +
67802 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
67803 + return NULL;
67804 +
67805 + mod = __module_address(addr);
67806 +
67807 if (mod) {
67808 /* Make sure it's within the text section. */
67809 - if (!within(addr, mod->module_init, mod->init_text_size)
67810 - && !within(addr, mod->module_core, mod->core_text_size))
67811 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
67812 mod = NULL;
67813 }
67814 return mod;
67815 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
67816 index 7e3443f..b2a1e6b 100644
67817 --- a/kernel/mutex-debug.c
67818 +++ b/kernel/mutex-debug.c
67819 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
67820 }
67821
67822 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67823 - struct thread_info *ti)
67824 + struct task_struct *task)
67825 {
67826 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
67827
67828 /* Mark the current thread as blocked on the lock: */
67829 - ti->task->blocked_on = waiter;
67830 + task->blocked_on = waiter;
67831 }
67832
67833 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67834 - struct thread_info *ti)
67835 + struct task_struct *task)
67836 {
67837 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
67838 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
67839 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
67840 - ti->task->blocked_on = NULL;
67841 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
67842 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
67843 + task->blocked_on = NULL;
67844
67845 list_del_init(&waiter->list);
67846 waiter->task = NULL;
67847 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
67848 index 0799fd3..d06ae3b 100644
67849 --- a/kernel/mutex-debug.h
67850 +++ b/kernel/mutex-debug.h
67851 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
67852 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
67853 extern void debug_mutex_add_waiter(struct mutex *lock,
67854 struct mutex_waiter *waiter,
67855 - struct thread_info *ti);
67856 + struct task_struct *task);
67857 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67858 - struct thread_info *ti);
67859 + struct task_struct *task);
67860 extern void debug_mutex_unlock(struct mutex *lock);
67861 extern void debug_mutex_init(struct mutex *lock, const char *name,
67862 struct lock_class_key *key);
67863 diff --git a/kernel/mutex.c b/kernel/mutex.c
67864 index 89096dd..f91ebc5 100644
67865 --- a/kernel/mutex.c
67866 +++ b/kernel/mutex.c
67867 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67868 spin_lock_mutex(&lock->wait_lock, flags);
67869
67870 debug_mutex_lock_common(lock, &waiter);
67871 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
67872 + debug_mutex_add_waiter(lock, &waiter, task);
67873
67874 /* add waiting tasks to the end of the waitqueue (FIFO): */
67875 list_add_tail(&waiter.list, &lock->wait_list);
67876 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67877 * TASK_UNINTERRUPTIBLE case.)
67878 */
67879 if (unlikely(signal_pending_state(state, task))) {
67880 - mutex_remove_waiter(lock, &waiter,
67881 - task_thread_info(task));
67882 + mutex_remove_waiter(lock, &waiter, task);
67883 mutex_release(&lock->dep_map, 1, ip);
67884 spin_unlock_mutex(&lock->wait_lock, flags);
67885
67886 @@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67887 done:
67888 lock_acquired(&lock->dep_map, ip);
67889 /* got the lock - rejoice! */
67890 - mutex_remove_waiter(lock, &waiter, current_thread_info());
67891 + mutex_remove_waiter(lock, &waiter, task);
67892 mutex_set_owner(lock);
67893
67894 /* set it to 0 if there are no waiters left: */
67895 diff --git a/kernel/padata.c b/kernel/padata.c
67896 index b452599..5d68f4e 100644
67897 --- a/kernel/padata.c
67898 +++ b/kernel/padata.c
67899 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
67900 padata->pd = pd;
67901 padata->cb_cpu = cb_cpu;
67902
67903 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
67904 - atomic_set(&pd->seq_nr, -1);
67905 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
67906 + atomic_set_unchecked(&pd->seq_nr, -1);
67907
67908 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
67909 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
67910
67911 target_cpu = padata_cpu_hash(padata);
67912 queue = per_cpu_ptr(pd->pqueue, target_cpu);
67913 @@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
67914 padata_init_pqueues(pd);
67915 padata_init_squeues(pd);
67916 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
67917 - atomic_set(&pd->seq_nr, -1);
67918 + atomic_set_unchecked(&pd->seq_nr, -1);
67919 atomic_set(&pd->reorder_objects, 0);
67920 atomic_set(&pd->refcnt, 0);
67921 pd->pinst = pinst;
67922 diff --git a/kernel/panic.c b/kernel/panic.c
67923 index 3458469..342c500 100644
67924 --- a/kernel/panic.c
67925 +++ b/kernel/panic.c
67926 @@ -78,7 +78,11 @@ NORET_TYPE void panic(const char * fmt, ...)
67927 va_end(args);
67928 printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf);
67929 #ifdef CONFIG_DEBUG_BUGVERBOSE
67930 - dump_stack();
67931 + /*
67932 + * Avoid nested stack-dumping if a panic occurs during oops processing
67933 + */
67934 + if (!oops_in_progress)
67935 + dump_stack();
67936 #endif
67937
67938 /*
67939 @@ -382,7 +386,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
67940 const char *board;
67941
67942 printk(KERN_WARNING "------------[ cut here ]------------\n");
67943 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
67944 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
67945 board = dmi_get_system_info(DMI_PRODUCT_NAME);
67946 if (board)
67947 printk(KERN_WARNING "Hardware name: %s\n", board);
67948 @@ -437,7 +441,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
67949 */
67950 void __stack_chk_fail(void)
67951 {
67952 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
67953 + dump_stack();
67954 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
67955 __builtin_return_address(0));
67956 }
67957 EXPORT_SYMBOL(__stack_chk_fail);
67958 diff --git a/kernel/pid.c b/kernel/pid.c
67959 index fa5f722..0c93e57 100644
67960 --- a/kernel/pid.c
67961 +++ b/kernel/pid.c
67962 @@ -33,6 +33,7 @@
67963 #include <linux/rculist.h>
67964 #include <linux/bootmem.h>
67965 #include <linux/hash.h>
67966 +#include <linux/security.h>
67967 #include <linux/pid_namespace.h>
67968 #include <linux/init_task.h>
67969 #include <linux/syscalls.h>
67970 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
67971
67972 int pid_max = PID_MAX_DEFAULT;
67973
67974 -#define RESERVED_PIDS 300
67975 +#define RESERVED_PIDS 500
67976
67977 int pid_max_min = RESERVED_PIDS + 1;
67978 int pid_max_max = PID_MAX_LIMIT;
67979 @@ -418,10 +419,18 @@ EXPORT_SYMBOL(pid_task);
67980 */
67981 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
67982 {
67983 + struct task_struct *task;
67984 +
67985 rcu_lockdep_assert(rcu_read_lock_held(),
67986 "find_task_by_pid_ns() needs rcu_read_lock()"
67987 " protection");
67988 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67989 +
67990 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67991 +
67992 + if (gr_pid_is_chrooted(task))
67993 + return NULL;
67994 +
67995 + return task;
67996 }
67997
67998 struct task_struct *find_task_by_vpid(pid_t vnr)
67999 @@ -429,6 +438,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68000 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68001 }
68002
68003 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68004 +{
68005 + rcu_lockdep_assert(rcu_read_lock_held(),
68006 + "find_task_by_pid_ns() needs rcu_read_lock()"
68007 + " protection");
68008 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68009 +}
68010 +
68011 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68012 {
68013 struct pid *pid;
68014 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68015 index e7cb76d..75eceb3 100644
68016 --- a/kernel/posix-cpu-timers.c
68017 +++ b/kernel/posix-cpu-timers.c
68018 @@ -6,6 +6,7 @@
68019 #include <linux/posix-timers.h>
68020 #include <linux/errno.h>
68021 #include <linux/math64.h>
68022 +#include <linux/security.h>
68023 #include <asm/uaccess.h>
68024 #include <linux/kernel_stat.h>
68025 #include <trace/events/timer.h>
68026 @@ -1606,14 +1607,14 @@ struct k_clock clock_posix_cpu = {
68027
68028 static __init int init_posix_cpu_timers(void)
68029 {
68030 - struct k_clock process = {
68031 + static struct k_clock process = {
68032 .clock_getres = process_cpu_clock_getres,
68033 .clock_get = process_cpu_clock_get,
68034 .timer_create = process_cpu_timer_create,
68035 .nsleep = process_cpu_nsleep,
68036 .nsleep_restart = process_cpu_nsleep_restart,
68037 };
68038 - struct k_clock thread = {
68039 + static struct k_clock thread = {
68040 .clock_getres = thread_cpu_clock_getres,
68041 .clock_get = thread_cpu_clock_get,
68042 .timer_create = thread_cpu_timer_create,
68043 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68044 index 69185ae..cc2847a 100644
68045 --- a/kernel/posix-timers.c
68046 +++ b/kernel/posix-timers.c
68047 @@ -43,6 +43,7 @@
68048 #include <linux/idr.h>
68049 #include <linux/posix-clock.h>
68050 #include <linux/posix-timers.h>
68051 +#include <linux/grsecurity.h>
68052 #include <linux/syscalls.h>
68053 #include <linux/wait.h>
68054 #include <linux/workqueue.h>
68055 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68056 * which we beg off on and pass to do_sys_settimeofday().
68057 */
68058
68059 -static struct k_clock posix_clocks[MAX_CLOCKS];
68060 +static struct k_clock *posix_clocks[MAX_CLOCKS];
68061
68062 /*
68063 * These ones are defined below.
68064 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68065 */
68066 static __init int init_posix_timers(void)
68067 {
68068 - struct k_clock clock_realtime = {
68069 + static struct k_clock clock_realtime = {
68070 .clock_getres = hrtimer_get_res,
68071 .clock_get = posix_clock_realtime_get,
68072 .clock_set = posix_clock_realtime_set,
68073 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68074 .timer_get = common_timer_get,
68075 .timer_del = common_timer_del,
68076 };
68077 - struct k_clock clock_monotonic = {
68078 + static struct k_clock clock_monotonic = {
68079 .clock_getres = hrtimer_get_res,
68080 .clock_get = posix_ktime_get_ts,
68081 .nsleep = common_nsleep,
68082 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
68083 .timer_get = common_timer_get,
68084 .timer_del = common_timer_del,
68085 };
68086 - struct k_clock clock_monotonic_raw = {
68087 + static struct k_clock clock_monotonic_raw = {
68088 .clock_getres = hrtimer_get_res,
68089 .clock_get = posix_get_monotonic_raw,
68090 };
68091 - struct k_clock clock_realtime_coarse = {
68092 + static struct k_clock clock_realtime_coarse = {
68093 .clock_getres = posix_get_coarse_res,
68094 .clock_get = posix_get_realtime_coarse,
68095 };
68096 - struct k_clock clock_monotonic_coarse = {
68097 + static struct k_clock clock_monotonic_coarse = {
68098 .clock_getres = posix_get_coarse_res,
68099 .clock_get = posix_get_monotonic_coarse,
68100 };
68101 - struct k_clock clock_boottime = {
68102 + static struct k_clock clock_boottime = {
68103 .clock_getres = hrtimer_get_res,
68104 .clock_get = posix_get_boottime,
68105 .nsleep = common_nsleep,
68106 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
68107 return;
68108 }
68109
68110 - posix_clocks[clock_id] = *new_clock;
68111 + posix_clocks[clock_id] = new_clock;
68112 }
68113 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
68114
68115 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
68116 return (id & CLOCKFD_MASK) == CLOCKFD ?
68117 &clock_posix_dynamic : &clock_posix_cpu;
68118
68119 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
68120 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
68121 return NULL;
68122 - return &posix_clocks[id];
68123 + return posix_clocks[id];
68124 }
68125
68126 static int common_timer_create(struct k_itimer *new_timer)
68127 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
68128 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
68129 return -EFAULT;
68130
68131 + /* only the CLOCK_REALTIME clock can be set, all other clocks
68132 + have their clock_set fptr set to a nosettime dummy function
68133 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
68134 + call common_clock_set, which calls do_sys_settimeofday, which
68135 + we hook
68136 + */
68137 +
68138 return kc->clock_set(which_clock, &new_tp);
68139 }
68140
68141 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
68142 index d523593..68197a4 100644
68143 --- a/kernel/power/poweroff.c
68144 +++ b/kernel/power/poweroff.c
68145 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
68146 .enable_mask = SYSRQ_ENABLE_BOOT,
68147 };
68148
68149 -static int pm_sysrq_init(void)
68150 +static int __init pm_sysrq_init(void)
68151 {
68152 register_sysrq_key('o', &sysrq_poweroff_op);
68153 return 0;
68154 diff --git a/kernel/power/process.c b/kernel/power/process.c
68155 index 3d4b954..11af930 100644
68156 --- a/kernel/power/process.c
68157 +++ b/kernel/power/process.c
68158 @@ -41,6 +41,7 @@ static int try_to_freeze_tasks(bool sig_only)
68159 u64 elapsed_csecs64;
68160 unsigned int elapsed_csecs;
68161 bool wakeup = false;
68162 + bool timedout = false;
68163
68164 do_gettimeofday(&start);
68165
68166 @@ -51,6 +52,8 @@ static int try_to_freeze_tasks(bool sig_only)
68167
68168 while (true) {
68169 todo = 0;
68170 + if (time_after(jiffies, end_time))
68171 + timedout = true;
68172 read_lock(&tasklist_lock);
68173 do_each_thread(g, p) {
68174 if (frozen(p) || !freezable(p))
68175 @@ -71,9 +74,13 @@ static int try_to_freeze_tasks(bool sig_only)
68176 * try_to_stop() after schedule() in ptrace/signal
68177 * stop sees TIF_FREEZE.
68178 */
68179 - if (!task_is_stopped_or_traced(p) &&
68180 - !freezer_should_skip(p))
68181 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
68182 todo++;
68183 + if (timedout) {
68184 + printk(KERN_ERR "Task refusing to freeze:\n");
68185 + sched_show_task(p);
68186 + }
68187 + }
68188 } while_each_thread(g, p);
68189 read_unlock(&tasklist_lock);
68190
68191 @@ -82,7 +89,7 @@ static int try_to_freeze_tasks(bool sig_only)
68192 todo += wq_busy;
68193 }
68194
68195 - if (!todo || time_after(jiffies, end_time))
68196 + if (!todo || timedout)
68197 break;
68198
68199 if (pm_wakeup_pending()) {
68200 diff --git a/kernel/printk.c b/kernel/printk.c
68201 index 7982a0a..2095fdc 100644
68202 --- a/kernel/printk.c
68203 +++ b/kernel/printk.c
68204 @@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
68205 if (from_file && type != SYSLOG_ACTION_OPEN)
68206 return 0;
68207
68208 +#ifdef CONFIG_GRKERNSEC_DMESG
68209 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
68210 + return -EPERM;
68211 +#endif
68212 +
68213 if (syslog_action_restricted(type)) {
68214 if (capable(CAP_SYSLOG))
68215 return 0;
68216 diff --git a/kernel/profile.c b/kernel/profile.c
68217 index 76b8e77..a2930e8 100644
68218 --- a/kernel/profile.c
68219 +++ b/kernel/profile.c
68220 @@ -39,7 +39,7 @@ struct profile_hit {
68221 /* Oprofile timer tick hook */
68222 static int (*timer_hook)(struct pt_regs *) __read_mostly;
68223
68224 -static atomic_t *prof_buffer;
68225 +static atomic_unchecked_t *prof_buffer;
68226 static unsigned long prof_len, prof_shift;
68227
68228 int prof_on __read_mostly;
68229 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
68230 hits[i].pc = 0;
68231 continue;
68232 }
68233 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68234 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68235 hits[i].hits = hits[i].pc = 0;
68236 }
68237 }
68238 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68239 * Add the current hit(s) and flush the write-queue out
68240 * to the global buffer:
68241 */
68242 - atomic_add(nr_hits, &prof_buffer[pc]);
68243 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
68244 for (i = 0; i < NR_PROFILE_HIT; ++i) {
68245 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68246 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68247 hits[i].pc = hits[i].hits = 0;
68248 }
68249 out:
68250 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68251 {
68252 unsigned long pc;
68253 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
68254 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68255 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68256 }
68257 #endif /* !CONFIG_SMP */
68258
68259 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
68260 return -EFAULT;
68261 buf++; p++; count--; read++;
68262 }
68263 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
68264 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
68265 if (copy_to_user(buf, (void *)pnt, count))
68266 return -EFAULT;
68267 read += count;
68268 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
68269 }
68270 #endif
68271 profile_discard_flip_buffers();
68272 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
68273 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
68274 return count;
68275 }
68276
68277 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
68278 index 78ab24a..332c915 100644
68279 --- a/kernel/ptrace.c
68280 +++ b/kernel/ptrace.c
68281 @@ -172,7 +172,8 @@ int ptrace_check_attach(struct task_struct *child, bool ignore_state)
68282 return ret;
68283 }
68284
68285 -int __ptrace_may_access(struct task_struct *task, unsigned int mode)
68286 +static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
68287 + unsigned int log)
68288 {
68289 const struct cred *cred = current_cred(), *tcred;
68290
68291 @@ -198,7 +199,8 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
68292 cred->gid == tcred->sgid &&
68293 cred->gid == tcred->gid))
68294 goto ok;
68295 - if (ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE))
68296 + if ((!log && ns_capable_nolog(tcred->user->user_ns, CAP_SYS_PTRACE)) ||
68297 + (log && ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE)))
68298 goto ok;
68299 rcu_read_unlock();
68300 return -EPERM;
68301 @@ -207,7 +209,9 @@ ok:
68302 smp_rmb();
68303 if (task->mm)
68304 dumpable = get_dumpable(task->mm);
68305 - if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
68306 + if (!dumpable &&
68307 + ((!log && !task_ns_capable_nolog(task, CAP_SYS_PTRACE)) ||
68308 + (log && !task_ns_capable(task, CAP_SYS_PTRACE))))
68309 return -EPERM;
68310
68311 return security_ptrace_access_check(task, mode);
68312 @@ -217,7 +221,21 @@ bool ptrace_may_access(struct task_struct *task, unsigned int mode)
68313 {
68314 int err;
68315 task_lock(task);
68316 - err = __ptrace_may_access(task, mode);
68317 + err = __ptrace_may_access(task, mode, 0);
68318 + task_unlock(task);
68319 + return !err;
68320 +}
68321 +
68322 +bool ptrace_may_access_nolock(struct task_struct *task, unsigned int mode)
68323 +{
68324 + return __ptrace_may_access(task, mode, 0);
68325 +}
68326 +
68327 +bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
68328 +{
68329 + int err;
68330 + task_lock(task);
68331 + err = __ptrace_may_access(task, mode, 1);
68332 task_unlock(task);
68333 return !err;
68334 }
68335 @@ -262,7 +280,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68336 goto out;
68337
68338 task_lock(task);
68339 - retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
68340 + retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
68341 task_unlock(task);
68342 if (retval)
68343 goto unlock_creds;
68344 @@ -277,7 +295,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68345 task->ptrace = PT_PTRACED;
68346 if (seize)
68347 task->ptrace |= PT_SEIZED;
68348 - if (task_ns_capable(task, CAP_SYS_PTRACE))
68349 + if (task_ns_capable_nolog(task, CAP_SYS_PTRACE))
68350 task->ptrace |= PT_PTRACE_CAP;
68351
68352 __ptrace_link(task, current);
68353 @@ -483,7 +501,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68354 break;
68355 return -EIO;
68356 }
68357 - if (copy_to_user(dst, buf, retval))
68358 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
68359 return -EFAULT;
68360 copied += retval;
68361 src += retval;
68362 @@ -680,7 +698,7 @@ int ptrace_request(struct task_struct *child, long request,
68363 bool seized = child->ptrace & PT_SEIZED;
68364 int ret = -EIO;
68365 siginfo_t siginfo, *si;
68366 - void __user *datavp = (void __user *) data;
68367 + void __user *datavp = (__force void __user *) data;
68368 unsigned long __user *datalp = datavp;
68369 unsigned long flags;
68370
68371 @@ -882,14 +900,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
68372 goto out;
68373 }
68374
68375 + if (gr_handle_ptrace(child, request)) {
68376 + ret = -EPERM;
68377 + goto out_put_task_struct;
68378 + }
68379 +
68380 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68381 ret = ptrace_attach(child, request, data);
68382 /*
68383 * Some architectures need to do book-keeping after
68384 * a ptrace attach.
68385 */
68386 - if (!ret)
68387 + if (!ret) {
68388 arch_ptrace_attach(child);
68389 + gr_audit_ptrace(child);
68390 + }
68391 goto out_put_task_struct;
68392 }
68393
68394 @@ -915,7 +940,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68395 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68396 if (copied != sizeof(tmp))
68397 return -EIO;
68398 - return put_user(tmp, (unsigned long __user *)data);
68399 + return put_user(tmp, (__force unsigned long __user *)data);
68400 }
68401
68402 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68403 @@ -1025,14 +1050,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68404 goto out;
68405 }
68406
68407 + if (gr_handle_ptrace(child, request)) {
68408 + ret = -EPERM;
68409 + goto out_put_task_struct;
68410 + }
68411 +
68412 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68413 ret = ptrace_attach(child, request, data);
68414 /*
68415 * Some architectures need to do book-keeping after
68416 * a ptrace attach.
68417 */
68418 - if (!ret)
68419 + if (!ret) {
68420 arch_ptrace_attach(child);
68421 + gr_audit_ptrace(child);
68422 + }
68423 goto out_put_task_struct;
68424 }
68425
68426 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
68427 index 636af6d..8af70ab 100644
68428 --- a/kernel/rcutiny.c
68429 +++ b/kernel/rcutiny.c
68430 @@ -46,7 +46,7 @@
68431 struct rcu_ctrlblk;
68432 static void invoke_rcu_callbacks(void);
68433 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
68434 -static void rcu_process_callbacks(struct softirq_action *unused);
68435 +static void rcu_process_callbacks(void);
68436 static void __call_rcu(struct rcu_head *head,
68437 void (*func)(struct rcu_head *rcu),
68438 struct rcu_ctrlblk *rcp);
68439 @@ -186,7 +186,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
68440 RCU_TRACE(trace_rcu_batch_end(rcp->name, cb_count));
68441 }
68442
68443 -static void rcu_process_callbacks(struct softirq_action *unused)
68444 +static void rcu_process_callbacks(void)
68445 {
68446 __rcu_process_callbacks(&rcu_sched_ctrlblk);
68447 __rcu_process_callbacks(&rcu_bh_ctrlblk);
68448 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68449 index 764825c..3aa6ac4 100644
68450 --- a/kernel/rcutorture.c
68451 +++ b/kernel/rcutorture.c
68452 @@ -138,12 +138,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68453 { 0 };
68454 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68455 { 0 };
68456 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68457 -static atomic_t n_rcu_torture_alloc;
68458 -static atomic_t n_rcu_torture_alloc_fail;
68459 -static atomic_t n_rcu_torture_free;
68460 -static atomic_t n_rcu_torture_mberror;
68461 -static atomic_t n_rcu_torture_error;
68462 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68463 +static atomic_unchecked_t n_rcu_torture_alloc;
68464 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
68465 +static atomic_unchecked_t n_rcu_torture_free;
68466 +static atomic_unchecked_t n_rcu_torture_mberror;
68467 +static atomic_unchecked_t n_rcu_torture_error;
68468 static long n_rcu_torture_boost_ktrerror;
68469 static long n_rcu_torture_boost_rterror;
68470 static long n_rcu_torture_boost_failure;
68471 @@ -223,11 +223,11 @@ rcu_torture_alloc(void)
68472
68473 spin_lock_bh(&rcu_torture_lock);
68474 if (list_empty(&rcu_torture_freelist)) {
68475 - atomic_inc(&n_rcu_torture_alloc_fail);
68476 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68477 spin_unlock_bh(&rcu_torture_lock);
68478 return NULL;
68479 }
68480 - atomic_inc(&n_rcu_torture_alloc);
68481 + atomic_inc_unchecked(&n_rcu_torture_alloc);
68482 p = rcu_torture_freelist.next;
68483 list_del_init(p);
68484 spin_unlock_bh(&rcu_torture_lock);
68485 @@ -240,7 +240,7 @@ rcu_torture_alloc(void)
68486 static void
68487 rcu_torture_free(struct rcu_torture *p)
68488 {
68489 - atomic_inc(&n_rcu_torture_free);
68490 + atomic_inc_unchecked(&n_rcu_torture_free);
68491 spin_lock_bh(&rcu_torture_lock);
68492 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68493 spin_unlock_bh(&rcu_torture_lock);
68494 @@ -360,7 +360,7 @@ rcu_torture_cb(struct rcu_head *p)
68495 i = rp->rtort_pipe_count;
68496 if (i > RCU_TORTURE_PIPE_LEN)
68497 i = RCU_TORTURE_PIPE_LEN;
68498 - atomic_inc(&rcu_torture_wcount[i]);
68499 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68500 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68501 rp->rtort_mbtest = 0;
68502 rcu_torture_free(rp);
68503 @@ -407,7 +407,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68504 i = rp->rtort_pipe_count;
68505 if (i > RCU_TORTURE_PIPE_LEN)
68506 i = RCU_TORTURE_PIPE_LEN;
68507 - atomic_inc(&rcu_torture_wcount[i]);
68508 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68509 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68510 rp->rtort_mbtest = 0;
68511 list_del(&rp->rtort_free);
68512 @@ -872,7 +872,7 @@ rcu_torture_writer(void *arg)
68513 i = old_rp->rtort_pipe_count;
68514 if (i > RCU_TORTURE_PIPE_LEN)
68515 i = RCU_TORTURE_PIPE_LEN;
68516 - atomic_inc(&rcu_torture_wcount[i]);
68517 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68518 old_rp->rtort_pipe_count++;
68519 cur_ops->deferred_free(old_rp);
68520 }
68521 @@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
68522 return;
68523 }
68524 if (p->rtort_mbtest == 0)
68525 - atomic_inc(&n_rcu_torture_mberror);
68526 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68527 spin_lock(&rand_lock);
68528 cur_ops->read_delay(&rand);
68529 n_rcu_torture_timers++;
68530 @@ -1001,7 +1001,7 @@ rcu_torture_reader(void *arg)
68531 continue;
68532 }
68533 if (p->rtort_mbtest == 0)
68534 - atomic_inc(&n_rcu_torture_mberror);
68535 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68536 cur_ops->read_delay(&rand);
68537 preempt_disable();
68538 pipe_count = p->rtort_pipe_count;
68539 @@ -1060,16 +1060,16 @@ rcu_torture_printk(char *page)
68540 rcu_torture_current,
68541 rcu_torture_current_version,
68542 list_empty(&rcu_torture_freelist),
68543 - atomic_read(&n_rcu_torture_alloc),
68544 - atomic_read(&n_rcu_torture_alloc_fail),
68545 - atomic_read(&n_rcu_torture_free),
68546 - atomic_read(&n_rcu_torture_mberror),
68547 + atomic_read_unchecked(&n_rcu_torture_alloc),
68548 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68549 + atomic_read_unchecked(&n_rcu_torture_free),
68550 + atomic_read_unchecked(&n_rcu_torture_mberror),
68551 n_rcu_torture_boost_ktrerror,
68552 n_rcu_torture_boost_rterror,
68553 n_rcu_torture_boost_failure,
68554 n_rcu_torture_boosts,
68555 n_rcu_torture_timers);
68556 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68557 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68558 n_rcu_torture_boost_ktrerror != 0 ||
68559 n_rcu_torture_boost_rterror != 0 ||
68560 n_rcu_torture_boost_failure != 0)
68561 @@ -1077,7 +1077,7 @@ rcu_torture_printk(char *page)
68562 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68563 if (i > 1) {
68564 cnt += sprintf(&page[cnt], "!!! ");
68565 - atomic_inc(&n_rcu_torture_error);
68566 + atomic_inc_unchecked(&n_rcu_torture_error);
68567 WARN_ON_ONCE(1);
68568 }
68569 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68570 @@ -1091,7 +1091,7 @@ rcu_torture_printk(char *page)
68571 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68572 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68573 cnt += sprintf(&page[cnt], " %d",
68574 - atomic_read(&rcu_torture_wcount[i]));
68575 + atomic_read_unchecked(&rcu_torture_wcount[i]));
68576 }
68577 cnt += sprintf(&page[cnt], "\n");
68578 if (cur_ops->stats)
68579 @@ -1401,7 +1401,7 @@ rcu_torture_cleanup(void)
68580
68581 if (cur_ops->cleanup)
68582 cur_ops->cleanup();
68583 - if (atomic_read(&n_rcu_torture_error))
68584 + if (atomic_read_unchecked(&n_rcu_torture_error))
68585 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68586 else
68587 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
68588 @@ -1465,17 +1465,17 @@ rcu_torture_init(void)
68589
68590 rcu_torture_current = NULL;
68591 rcu_torture_current_version = 0;
68592 - atomic_set(&n_rcu_torture_alloc, 0);
68593 - atomic_set(&n_rcu_torture_alloc_fail, 0);
68594 - atomic_set(&n_rcu_torture_free, 0);
68595 - atomic_set(&n_rcu_torture_mberror, 0);
68596 - atomic_set(&n_rcu_torture_error, 0);
68597 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68598 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68599 + atomic_set_unchecked(&n_rcu_torture_free, 0);
68600 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68601 + atomic_set_unchecked(&n_rcu_torture_error, 0);
68602 n_rcu_torture_boost_ktrerror = 0;
68603 n_rcu_torture_boost_rterror = 0;
68604 n_rcu_torture_boost_failure = 0;
68605 n_rcu_torture_boosts = 0;
68606 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68607 - atomic_set(&rcu_torture_wcount[i], 0);
68608 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68609 for_each_possible_cpu(cpu) {
68610 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68611 per_cpu(rcu_torture_count, cpu)[i] = 0;
68612 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68613 index 6b76d81..7afc1b3 100644
68614 --- a/kernel/rcutree.c
68615 +++ b/kernel/rcutree.c
68616 @@ -367,9 +367,9 @@ void rcu_enter_nohz(void)
68617 trace_rcu_dyntick("Start");
68618 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68619 smp_mb__before_atomic_inc(); /* See above. */
68620 - atomic_inc(&rdtp->dynticks);
68621 + atomic_inc_unchecked(&rdtp->dynticks);
68622 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68623 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68624 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68625 local_irq_restore(flags);
68626 }
68627
68628 @@ -391,10 +391,10 @@ void rcu_exit_nohz(void)
68629 return;
68630 }
68631 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68632 - atomic_inc(&rdtp->dynticks);
68633 + atomic_inc_unchecked(&rdtp->dynticks);
68634 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68635 smp_mb__after_atomic_inc(); /* See above. */
68636 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68637 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68638 trace_rcu_dyntick("End");
68639 local_irq_restore(flags);
68640 }
68641 @@ -411,14 +411,14 @@ void rcu_nmi_enter(void)
68642 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68643
68644 if (rdtp->dynticks_nmi_nesting == 0 &&
68645 - (atomic_read(&rdtp->dynticks) & 0x1))
68646 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
68647 return;
68648 rdtp->dynticks_nmi_nesting++;
68649 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
68650 - atomic_inc(&rdtp->dynticks);
68651 + atomic_inc_unchecked(&rdtp->dynticks);
68652 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68653 smp_mb__after_atomic_inc(); /* See above. */
68654 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68655 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68656 }
68657
68658 /**
68659 @@ -437,9 +437,9 @@ void rcu_nmi_exit(void)
68660 return;
68661 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68662 smp_mb__before_atomic_inc(); /* See above. */
68663 - atomic_inc(&rdtp->dynticks);
68664 + atomic_inc_unchecked(&rdtp->dynticks);
68665 smp_mb__after_atomic_inc(); /* Force delay to next write. */
68666 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68667 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68668 }
68669
68670 /**
68671 @@ -474,7 +474,7 @@ void rcu_irq_exit(void)
68672 */
68673 static int dyntick_save_progress_counter(struct rcu_data *rdp)
68674 {
68675 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
68676 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68677 return 0;
68678 }
68679
68680 @@ -489,7 +489,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
68681 unsigned int curr;
68682 unsigned int snap;
68683
68684 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
68685 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68686 snap = (unsigned int)rdp->dynticks_snap;
68687
68688 /*
68689 @@ -1552,7 +1552,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
68690 /*
68691 * Do RCU core processing for the current CPU.
68692 */
68693 -static void rcu_process_callbacks(struct softirq_action *unused)
68694 +static void rcu_process_callbacks(void)
68695 {
68696 trace_rcu_utilization("Start RCU core");
68697 __rcu_process_callbacks(&rcu_sched_state,
68698 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
68699 index 849ce9e..74bc9de 100644
68700 --- a/kernel/rcutree.h
68701 +++ b/kernel/rcutree.h
68702 @@ -86,7 +86,7 @@
68703 struct rcu_dynticks {
68704 int dynticks_nesting; /* Track irq/process nesting level. */
68705 int dynticks_nmi_nesting; /* Track NMI nesting level. */
68706 - atomic_t dynticks; /* Even value for dynticks-idle, else odd. */
68707 + atomic_unchecked_t dynticks; /* Even value for dynticks-idle, else odd. */
68708 };
68709
68710 /* RCU's kthread states for tracing. */
68711 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
68712 index 4b9b9f8..2326053 100644
68713 --- a/kernel/rcutree_plugin.h
68714 +++ b/kernel/rcutree_plugin.h
68715 @@ -842,7 +842,7 @@ void synchronize_rcu_expedited(void)
68716
68717 /* Clean up and exit. */
68718 smp_mb(); /* ensure expedited GP seen before counter increment. */
68719 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
68720 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
68721 unlock_mb_ret:
68722 mutex_unlock(&sync_rcu_preempt_exp_mutex);
68723 mb_ret:
68724 @@ -1815,8 +1815,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
68725
68726 #else /* #ifndef CONFIG_SMP */
68727
68728 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
68729 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
68730 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
68731 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
68732
68733 static int synchronize_sched_expedited_cpu_stop(void *data)
68734 {
68735 @@ -1871,7 +1871,7 @@ void synchronize_sched_expedited(void)
68736 int firstsnap, s, snap, trycount = 0;
68737
68738 /* Note that atomic_inc_return() implies full memory barrier. */
68739 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
68740 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
68741 get_online_cpus();
68742
68743 /*
68744 @@ -1892,7 +1892,7 @@ void synchronize_sched_expedited(void)
68745 }
68746
68747 /* Check to see if someone else did our work for us. */
68748 - s = atomic_read(&sync_sched_expedited_done);
68749 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68750 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
68751 smp_mb(); /* ensure test happens before caller kfree */
68752 return;
68753 @@ -1907,7 +1907,7 @@ void synchronize_sched_expedited(void)
68754 * grace period works for us.
68755 */
68756 get_online_cpus();
68757 - snap = atomic_read(&sync_sched_expedited_started) - 1;
68758 + snap = atomic_read_unchecked(&sync_sched_expedited_started) - 1;
68759 smp_mb(); /* ensure read is before try_stop_cpus(). */
68760 }
68761
68762 @@ -1918,12 +1918,12 @@ void synchronize_sched_expedited(void)
68763 * than we did beat us to the punch.
68764 */
68765 do {
68766 - s = atomic_read(&sync_sched_expedited_done);
68767 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68768 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
68769 smp_mb(); /* ensure test happens before caller kfree */
68770 break;
68771 }
68772 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
68773 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
68774
68775 put_online_cpus();
68776 }
68777 @@ -1985,7 +1985,7 @@ int rcu_needs_cpu(int cpu)
68778 for_each_online_cpu(thatcpu) {
68779 if (thatcpu == cpu)
68780 continue;
68781 - snap = atomic_add_return(0, &per_cpu(rcu_dynticks,
68782 + snap = atomic_add_return_unchecked(0, &per_cpu(rcu_dynticks,
68783 thatcpu).dynticks);
68784 smp_mb(); /* Order sampling of snap with end of grace period. */
68785 if ((snap & 0x1) != 0) {
68786 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
68787 index 9feffa4..54058df 100644
68788 --- a/kernel/rcutree_trace.c
68789 +++ b/kernel/rcutree_trace.c
68790 @@ -69,7 +69,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
68791 rdp->qs_pending);
68792 #ifdef CONFIG_NO_HZ
68793 seq_printf(m, " dt=%d/%d/%d df=%lu",
68794 - atomic_read(&rdp->dynticks->dynticks),
68795 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68796 rdp->dynticks->dynticks_nesting,
68797 rdp->dynticks->dynticks_nmi_nesting,
68798 rdp->dynticks_fqs);
68799 @@ -143,7 +143,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
68800 rdp->qs_pending);
68801 #ifdef CONFIG_NO_HZ
68802 seq_printf(m, ",%d,%d,%d,%lu",
68803 - atomic_read(&rdp->dynticks->dynticks),
68804 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68805 rdp->dynticks->dynticks_nesting,
68806 rdp->dynticks->dynticks_nmi_nesting,
68807 rdp->dynticks_fqs);
68808 diff --git a/kernel/resource.c b/kernel/resource.c
68809 index 7640b3a..5879283 100644
68810 --- a/kernel/resource.c
68811 +++ b/kernel/resource.c
68812 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
68813
68814 static int __init ioresources_init(void)
68815 {
68816 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68817 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68818 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
68819 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
68820 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68821 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
68822 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
68823 +#endif
68824 +#else
68825 proc_create("ioports", 0, NULL, &proc_ioports_operations);
68826 proc_create("iomem", 0, NULL, &proc_iomem_operations);
68827 +#endif
68828 return 0;
68829 }
68830 __initcall(ioresources_init);
68831 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
68832 index 3d9f31c..7fefc9e 100644
68833 --- a/kernel/rtmutex-tester.c
68834 +++ b/kernel/rtmutex-tester.c
68835 @@ -20,7 +20,7 @@
68836 #define MAX_RT_TEST_MUTEXES 8
68837
68838 static spinlock_t rttest_lock;
68839 -static atomic_t rttest_event;
68840 +static atomic_unchecked_t rttest_event;
68841
68842 struct test_thread_data {
68843 int opcode;
68844 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68845
68846 case RTTEST_LOCKCONT:
68847 td->mutexes[td->opdata] = 1;
68848 - td->event = atomic_add_return(1, &rttest_event);
68849 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68850 return 0;
68851
68852 case RTTEST_RESET:
68853 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68854 return 0;
68855
68856 case RTTEST_RESETEVENT:
68857 - atomic_set(&rttest_event, 0);
68858 + atomic_set_unchecked(&rttest_event, 0);
68859 return 0;
68860
68861 default:
68862 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68863 return ret;
68864
68865 td->mutexes[id] = 1;
68866 - td->event = atomic_add_return(1, &rttest_event);
68867 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68868 rt_mutex_lock(&mutexes[id]);
68869 - td->event = atomic_add_return(1, &rttest_event);
68870 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68871 td->mutexes[id] = 4;
68872 return 0;
68873
68874 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68875 return ret;
68876
68877 td->mutexes[id] = 1;
68878 - td->event = atomic_add_return(1, &rttest_event);
68879 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68880 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
68881 - td->event = atomic_add_return(1, &rttest_event);
68882 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68883 td->mutexes[id] = ret ? 0 : 4;
68884 return ret ? -EINTR : 0;
68885
68886 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68887 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
68888 return ret;
68889
68890 - td->event = atomic_add_return(1, &rttest_event);
68891 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68892 rt_mutex_unlock(&mutexes[id]);
68893 - td->event = atomic_add_return(1, &rttest_event);
68894 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68895 td->mutexes[id] = 0;
68896 return 0;
68897
68898 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68899 break;
68900
68901 td->mutexes[dat] = 2;
68902 - td->event = atomic_add_return(1, &rttest_event);
68903 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68904 break;
68905
68906 default:
68907 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68908 return;
68909
68910 td->mutexes[dat] = 3;
68911 - td->event = atomic_add_return(1, &rttest_event);
68912 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68913 break;
68914
68915 case RTTEST_LOCKNOWAIT:
68916 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68917 return;
68918
68919 td->mutexes[dat] = 1;
68920 - td->event = atomic_add_return(1, &rttest_event);
68921 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68922 return;
68923
68924 default:
68925 diff --git a/kernel/sched.c b/kernel/sched.c
68926 index d6b149c..896cbb8 100644
68927 --- a/kernel/sched.c
68928 +++ b/kernel/sched.c
68929 @@ -4389,6 +4389,19 @@ pick_next_task(struct rq *rq)
68930 BUG(); /* the idle class will always have a runnable task */
68931 }
68932
68933 +#ifdef CONFIG_GRKERNSEC_SETXID
68934 +extern void gr_delayed_cred_worker(void);
68935 +static inline void gr_cred_schedule(void)
68936 +{
68937 + if (unlikely(current->delayed_cred))
68938 + gr_delayed_cred_worker();
68939 +}
68940 +#else
68941 +static inline void gr_cred_schedule(void)
68942 +{
68943 +}
68944 +#endif
68945 +
68946 /*
68947 * __schedule() is the main scheduler function.
68948 */
68949 @@ -4408,6 +4421,8 @@ need_resched:
68950
68951 schedule_debug(prev);
68952
68953 + gr_cred_schedule();
68954 +
68955 if (sched_feat(HRTICK))
68956 hrtick_clear(rq);
68957
68958 @@ -5098,6 +5113,8 @@ int can_nice(const struct task_struct *p, const int nice)
68959 /* convert nice value [19,-20] to rlimit style value [1,40] */
68960 int nice_rlim = 20 - nice;
68961
68962 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
68963 +
68964 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
68965 capable(CAP_SYS_NICE));
68966 }
68967 @@ -5131,7 +5148,8 @@ SYSCALL_DEFINE1(nice, int, increment)
68968 if (nice > 19)
68969 nice = 19;
68970
68971 - if (increment < 0 && !can_nice(current, nice))
68972 + if (increment < 0 && (!can_nice(current, nice) ||
68973 + gr_handle_chroot_nice()))
68974 return -EPERM;
68975
68976 retval = security_task_setnice(current, nice);
68977 @@ -5288,6 +5306,7 @@ recheck:
68978 unsigned long rlim_rtprio =
68979 task_rlimit(p, RLIMIT_RTPRIO);
68980
68981 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
68982 /* can't set/change the rt policy */
68983 if (policy != p->policy && !rlim_rtprio)
68984 return -EPERM;
68985 diff --git a/kernel/sched_autogroup.c b/kernel/sched_autogroup.c
68986 index 429242f..d7cca82 100644
68987 --- a/kernel/sched_autogroup.c
68988 +++ b/kernel/sched_autogroup.c
68989 @@ -7,7 +7,7 @@
68990
68991 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
68992 static struct autogroup autogroup_default;
68993 -static atomic_t autogroup_seq_nr;
68994 +static atomic_unchecked_t autogroup_seq_nr;
68995
68996 static void __init autogroup_init(struct task_struct *init_task)
68997 {
68998 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
68999
69000 kref_init(&ag->kref);
69001 init_rwsem(&ag->lock);
69002 - ag->id = atomic_inc_return(&autogroup_seq_nr);
69003 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69004 ag->tg = tg;
69005 #ifdef CONFIG_RT_GROUP_SCHED
69006 /*
69007 diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
69008 index 8a39fa3..34f3dbc 100644
69009 --- a/kernel/sched_fair.c
69010 +++ b/kernel/sched_fair.c
69011 @@ -4801,7 +4801,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69012 * run_rebalance_domains is triggered when needed from the scheduler tick.
69013 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69014 */
69015 -static void run_rebalance_domains(struct softirq_action *h)
69016 +static void run_rebalance_domains(void)
69017 {
69018 int this_cpu = smp_processor_id();
69019 struct rq *this_rq = cpu_rq(this_cpu);
69020 diff --git a/kernel/signal.c b/kernel/signal.c
69021 index 2065515..aed2987 100644
69022 --- a/kernel/signal.c
69023 +++ b/kernel/signal.c
69024 @@ -45,12 +45,12 @@ static struct kmem_cache *sigqueue_cachep;
69025
69026 int print_fatal_signals __read_mostly;
69027
69028 -static void __user *sig_handler(struct task_struct *t, int sig)
69029 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
69030 {
69031 return t->sighand->action[sig - 1].sa.sa_handler;
69032 }
69033
69034 -static int sig_handler_ignored(void __user *handler, int sig)
69035 +static int sig_handler_ignored(__sighandler_t handler, int sig)
69036 {
69037 /* Is it explicitly or implicitly ignored? */
69038 return handler == SIG_IGN ||
69039 @@ -60,7 +60,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69040 static int sig_task_ignored(struct task_struct *t, int sig,
69041 int from_ancestor_ns)
69042 {
69043 - void __user *handler;
69044 + __sighandler_t handler;
69045
69046 handler = sig_handler(t, sig);
69047
69048 @@ -364,6 +364,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69049 atomic_inc(&user->sigpending);
69050 rcu_read_unlock();
69051
69052 + if (!override_rlimit)
69053 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69054 +
69055 if (override_rlimit ||
69056 atomic_read(&user->sigpending) <=
69057 task_rlimit(t, RLIMIT_SIGPENDING)) {
69058 @@ -488,7 +491,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69059
69060 int unhandled_signal(struct task_struct *tsk, int sig)
69061 {
69062 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69063 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69064 if (is_global_init(tsk))
69065 return 1;
69066 if (handler != SIG_IGN && handler != SIG_DFL)
69067 @@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69068 }
69069 }
69070
69071 + /* allow glibc communication via tgkill to other threads in our
69072 + thread group */
69073 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69074 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69075 + && gr_handle_signal(t, sig))
69076 + return -EPERM;
69077 +
69078 return security_task_kill(t, info, sig, 0);
69079 }
69080
69081 @@ -1165,7 +1175,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69082 return send_signal(sig, info, p, 1);
69083 }
69084
69085 -static int
69086 +int
69087 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69088 {
69089 return send_signal(sig, info, t, 0);
69090 @@ -1202,6 +1212,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69091 unsigned long int flags;
69092 int ret, blocked, ignored;
69093 struct k_sigaction *action;
69094 + int is_unhandled = 0;
69095
69096 spin_lock_irqsave(&t->sighand->siglock, flags);
69097 action = &t->sighand->action[sig-1];
69098 @@ -1216,9 +1227,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69099 }
69100 if (action->sa.sa_handler == SIG_DFL)
69101 t->signal->flags &= ~SIGNAL_UNKILLABLE;
69102 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
69103 + is_unhandled = 1;
69104 ret = specific_send_sig_info(sig, info, t);
69105 spin_unlock_irqrestore(&t->sighand->siglock, flags);
69106
69107 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
69108 + normal operation */
69109 + if (is_unhandled) {
69110 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
69111 + gr_handle_crash(t, sig);
69112 + }
69113 +
69114 return ret;
69115 }
69116
69117 @@ -1285,8 +1305,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69118 ret = check_kill_permission(sig, info, p);
69119 rcu_read_unlock();
69120
69121 - if (!ret && sig)
69122 + if (!ret && sig) {
69123 ret = do_send_sig_info(sig, info, p, true);
69124 + if (!ret)
69125 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
69126 + }
69127
69128 return ret;
69129 }
69130 @@ -2754,7 +2777,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
69131 int error = -ESRCH;
69132
69133 rcu_read_lock();
69134 - p = find_task_by_vpid(pid);
69135 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69136 + /* allow glibc communication via tgkill to other threads in our
69137 + thread group */
69138 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
69139 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
69140 + p = find_task_by_vpid_unrestricted(pid);
69141 + else
69142 +#endif
69143 + p = find_task_by_vpid(pid);
69144 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
69145 error = check_kill_permission(sig, info, p);
69146 /*
69147 diff --git a/kernel/smp.c b/kernel/smp.c
69148 index db197d6..17aef0b 100644
69149 --- a/kernel/smp.c
69150 +++ b/kernel/smp.c
69151 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
69152 }
69153 EXPORT_SYMBOL(smp_call_function);
69154
69155 -void ipi_call_lock(void)
69156 +void ipi_call_lock(void) __acquires(call_function.lock)
69157 {
69158 raw_spin_lock(&call_function.lock);
69159 }
69160
69161 -void ipi_call_unlock(void)
69162 +void ipi_call_unlock(void) __releases(call_function.lock)
69163 {
69164 raw_spin_unlock(&call_function.lock);
69165 }
69166
69167 -void ipi_call_lock_irq(void)
69168 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
69169 {
69170 raw_spin_lock_irq(&call_function.lock);
69171 }
69172
69173 -void ipi_call_unlock_irq(void)
69174 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
69175 {
69176 raw_spin_unlock_irq(&call_function.lock);
69177 }
69178 diff --git a/kernel/softirq.c b/kernel/softirq.c
69179 index 2c71d91..1021f81 100644
69180 --- a/kernel/softirq.c
69181 +++ b/kernel/softirq.c
69182 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
69183
69184 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
69185
69186 -char *softirq_to_name[NR_SOFTIRQS] = {
69187 +const char * const softirq_to_name[NR_SOFTIRQS] = {
69188 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
69189 "TASKLET", "SCHED", "HRTIMER", "RCU"
69190 };
69191 @@ -235,7 +235,7 @@ restart:
69192 kstat_incr_softirqs_this_cpu(vec_nr);
69193
69194 trace_softirq_entry(vec_nr);
69195 - h->action(h);
69196 + h->action();
69197 trace_softirq_exit(vec_nr);
69198 if (unlikely(prev_count != preempt_count())) {
69199 printk(KERN_ERR "huh, entered softirq %u %s %p"
69200 @@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
69201 local_irq_restore(flags);
69202 }
69203
69204 -void open_softirq(int nr, void (*action)(struct softirq_action *))
69205 +void open_softirq(int nr, void (*action)(void))
69206 {
69207 - softirq_vec[nr].action = action;
69208 + pax_open_kernel();
69209 + *(void **)&softirq_vec[nr].action = action;
69210 + pax_close_kernel();
69211 }
69212
69213 /*
69214 @@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
69215
69216 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
69217
69218 -static void tasklet_action(struct softirq_action *a)
69219 +static void tasklet_action(void)
69220 {
69221 struct tasklet_struct *list;
69222
69223 @@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
69224 }
69225 }
69226
69227 -static void tasklet_hi_action(struct softirq_action *a)
69228 +static void tasklet_hi_action(void)
69229 {
69230 struct tasklet_struct *list;
69231
69232 diff --git a/kernel/sys.c b/kernel/sys.c
69233 index 481611f..0754d86 100644
69234 --- a/kernel/sys.c
69235 +++ b/kernel/sys.c
69236 @@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
69237 error = -EACCES;
69238 goto out;
69239 }
69240 +
69241 + if (gr_handle_chroot_setpriority(p, niceval)) {
69242 + error = -EACCES;
69243 + goto out;
69244 + }
69245 +
69246 no_nice = security_task_setnice(p, niceval);
69247 if (no_nice) {
69248 error = no_nice;
69249 @@ -572,6 +578,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
69250 goto error;
69251 }
69252
69253 + if (gr_check_group_change(new->gid, new->egid, -1))
69254 + goto error;
69255 +
69256 if (rgid != (gid_t) -1 ||
69257 (egid != (gid_t) -1 && egid != old->gid))
69258 new->sgid = new->egid;
69259 @@ -601,6 +610,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
69260 old = current_cred();
69261
69262 retval = -EPERM;
69263 +
69264 + if (gr_check_group_change(gid, gid, gid))
69265 + goto error;
69266 +
69267 if (nsown_capable(CAP_SETGID))
69268 new->gid = new->egid = new->sgid = new->fsgid = gid;
69269 else if (gid == old->gid || gid == old->sgid)
69270 @@ -618,7 +631,7 @@ error:
69271 /*
69272 * change the user struct in a credentials set to match the new UID
69273 */
69274 -static int set_user(struct cred *new)
69275 +int set_user(struct cred *new)
69276 {
69277 struct user_struct *new_user;
69278
69279 @@ -688,6 +701,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
69280 goto error;
69281 }
69282
69283 + if (gr_check_user_change(new->uid, new->euid, -1))
69284 + goto error;
69285 +
69286 if (new->uid != old->uid) {
69287 retval = set_user(new);
69288 if (retval < 0)
69289 @@ -732,6 +748,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
69290 old = current_cred();
69291
69292 retval = -EPERM;
69293 +
69294 + if (gr_check_crash_uid(uid))
69295 + goto error;
69296 + if (gr_check_user_change(uid, uid, uid))
69297 + goto error;
69298 +
69299 if (nsown_capable(CAP_SETUID)) {
69300 new->suid = new->uid = uid;
69301 if (uid != old->uid) {
69302 @@ -786,6 +808,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
69303 goto error;
69304 }
69305
69306 + if (gr_check_user_change(ruid, euid, -1))
69307 + goto error;
69308 +
69309 if (ruid != (uid_t) -1) {
69310 new->uid = ruid;
69311 if (ruid != old->uid) {
69312 @@ -850,6 +875,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
69313 goto error;
69314 }
69315
69316 + if (gr_check_group_change(rgid, egid, -1))
69317 + goto error;
69318 +
69319 if (rgid != (gid_t) -1)
69320 new->gid = rgid;
69321 if (egid != (gid_t) -1)
69322 @@ -896,6 +924,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69323 old = current_cred();
69324 old_fsuid = old->fsuid;
69325
69326 + if (gr_check_user_change(-1, -1, uid))
69327 + goto error;
69328 +
69329 if (uid == old->uid || uid == old->euid ||
69330 uid == old->suid || uid == old->fsuid ||
69331 nsown_capable(CAP_SETUID)) {
69332 @@ -906,6 +937,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69333 }
69334 }
69335
69336 +error:
69337 abort_creds(new);
69338 return old_fsuid;
69339
69340 @@ -932,12 +964,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
69341 if (gid == old->gid || gid == old->egid ||
69342 gid == old->sgid || gid == old->fsgid ||
69343 nsown_capable(CAP_SETGID)) {
69344 + if (gr_check_group_change(-1, -1, gid))
69345 + goto error;
69346 +
69347 if (gid != old_fsgid) {
69348 new->fsgid = gid;
69349 goto change_okay;
69350 }
69351 }
69352
69353 +error:
69354 abort_creds(new);
69355 return old_fsgid;
69356
69357 @@ -1189,7 +1225,10 @@ static int override_release(char __user *release, int len)
69358 }
69359 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
69360 snprintf(buf, len, "2.6.%u%s", v, rest);
69361 - ret = copy_to_user(release, buf, len);
69362 + if (len > sizeof(buf))
69363 + ret = -EFAULT;
69364 + else
69365 + ret = copy_to_user(release, buf, len);
69366 }
69367 return ret;
69368 }
69369 @@ -1243,19 +1282,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
69370 return -EFAULT;
69371
69372 down_read(&uts_sem);
69373 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
69374 + error = __copy_to_user(name->sysname, &utsname()->sysname,
69375 __OLD_UTS_LEN);
69376 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69377 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69378 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
69379 __OLD_UTS_LEN);
69380 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69381 - error |= __copy_to_user(&name->release, &utsname()->release,
69382 + error |= __copy_to_user(name->release, &utsname()->release,
69383 __OLD_UTS_LEN);
69384 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69385 - error |= __copy_to_user(&name->version, &utsname()->version,
69386 + error |= __copy_to_user(name->version, &utsname()->version,
69387 __OLD_UTS_LEN);
69388 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69389 - error |= __copy_to_user(&name->machine, &utsname()->machine,
69390 + error |= __copy_to_user(name->machine, &utsname()->machine,
69391 __OLD_UTS_LEN);
69392 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69393 up_read(&uts_sem);
69394 @@ -1720,7 +1759,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69395 error = get_dumpable(me->mm);
69396 break;
69397 case PR_SET_DUMPABLE:
69398 - if (arg2 < 0 || arg2 > 1) {
69399 + if (arg2 > 1) {
69400 error = -EINVAL;
69401 break;
69402 }
69403 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69404 index ae27196..7506d69 100644
69405 --- a/kernel/sysctl.c
69406 +++ b/kernel/sysctl.c
69407 @@ -86,6 +86,13 @@
69408
69409
69410 #if defined(CONFIG_SYSCTL)
69411 +#include <linux/grsecurity.h>
69412 +#include <linux/grinternal.h>
69413 +
69414 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
69415 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
69416 + const int op);
69417 +extern int gr_handle_chroot_sysctl(const int op);
69418
69419 /* External variables not in a header file. */
69420 extern int sysctl_overcommit_memory;
69421 @@ -191,6 +198,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69422 }
69423
69424 #endif
69425 +extern struct ctl_table grsecurity_table[];
69426
69427 static struct ctl_table root_table[];
69428 static struct ctl_table_root sysctl_table_root;
69429 @@ -220,6 +228,20 @@ extern struct ctl_table epoll_table[];
69430 int sysctl_legacy_va_layout;
69431 #endif
69432
69433 +#ifdef CONFIG_PAX_SOFTMODE
69434 +static ctl_table pax_table[] = {
69435 + {
69436 + .procname = "softmode",
69437 + .data = &pax_softmode,
69438 + .maxlen = sizeof(unsigned int),
69439 + .mode = 0600,
69440 + .proc_handler = &proc_dointvec,
69441 + },
69442 +
69443 + { }
69444 +};
69445 +#endif
69446 +
69447 /* The default sysctl tables: */
69448
69449 static struct ctl_table root_table[] = {
69450 @@ -266,6 +288,22 @@ static int max_extfrag_threshold = 1000;
69451 #endif
69452
69453 static struct ctl_table kern_table[] = {
69454 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69455 + {
69456 + .procname = "grsecurity",
69457 + .mode = 0500,
69458 + .child = grsecurity_table,
69459 + },
69460 +#endif
69461 +
69462 +#ifdef CONFIG_PAX_SOFTMODE
69463 + {
69464 + .procname = "pax",
69465 + .mode = 0500,
69466 + .child = pax_table,
69467 + },
69468 +#endif
69469 +
69470 {
69471 .procname = "sched_child_runs_first",
69472 .data = &sysctl_sched_child_runs_first,
69473 @@ -550,7 +588,7 @@ static struct ctl_table kern_table[] = {
69474 .data = &modprobe_path,
69475 .maxlen = KMOD_PATH_LEN,
69476 .mode = 0644,
69477 - .proc_handler = proc_dostring,
69478 + .proc_handler = proc_dostring_modpriv,
69479 },
69480 {
69481 .procname = "modules_disabled",
69482 @@ -717,16 +755,20 @@ static struct ctl_table kern_table[] = {
69483 .extra1 = &zero,
69484 .extra2 = &one,
69485 },
69486 +#endif
69487 {
69488 .procname = "kptr_restrict",
69489 .data = &kptr_restrict,
69490 .maxlen = sizeof(int),
69491 .mode = 0644,
69492 .proc_handler = proc_dmesg_restrict,
69493 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69494 + .extra1 = &two,
69495 +#else
69496 .extra1 = &zero,
69497 +#endif
69498 .extra2 = &two,
69499 },
69500 -#endif
69501 {
69502 .procname = "ngroups_max",
69503 .data = &ngroups_max,
69504 @@ -1216,6 +1258,13 @@ static struct ctl_table vm_table[] = {
69505 .proc_handler = proc_dointvec_minmax,
69506 .extra1 = &zero,
69507 },
69508 + {
69509 + .procname = "heap_stack_gap",
69510 + .data = &sysctl_heap_stack_gap,
69511 + .maxlen = sizeof(sysctl_heap_stack_gap),
69512 + .mode = 0644,
69513 + .proc_handler = proc_doulongvec_minmax,
69514 + },
69515 #else
69516 {
69517 .procname = "nr_trim_pages",
69518 @@ -1720,6 +1769,17 @@ static int test_perm(int mode, int op)
69519 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
69520 {
69521 int mode;
69522 + int error;
69523 +
69524 + if (table->parent != NULL && table->parent->procname != NULL &&
69525 + table->procname != NULL &&
69526 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
69527 + return -EACCES;
69528 + if (gr_handle_chroot_sysctl(op))
69529 + return -EACCES;
69530 + error = gr_handle_sysctl(table, op);
69531 + if (error)
69532 + return error;
69533
69534 if (root->permissions)
69535 mode = root->permissions(root, current->nsproxy, table);
69536 @@ -2124,6 +2184,16 @@ int proc_dostring(struct ctl_table *table, int write,
69537 buffer, lenp, ppos);
69538 }
69539
69540 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69541 + void __user *buffer, size_t *lenp, loff_t *ppos)
69542 +{
69543 + if (write && !capable(CAP_SYS_MODULE))
69544 + return -EPERM;
69545 +
69546 + return _proc_do_string(table->data, table->maxlen, write,
69547 + buffer, lenp, ppos);
69548 +}
69549 +
69550 static size_t proc_skip_spaces(char **buf)
69551 {
69552 size_t ret;
69553 @@ -2229,6 +2299,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69554 len = strlen(tmp);
69555 if (len > *size)
69556 len = *size;
69557 + if (len > sizeof(tmp))
69558 + len = sizeof(tmp);
69559 if (copy_to_user(*buf, tmp, len))
69560 return -EFAULT;
69561 *size -= len;
69562 @@ -2545,8 +2617,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
69563 *i = val;
69564 } else {
69565 val = convdiv * (*i) / convmul;
69566 - if (!first)
69567 + if (!first) {
69568 err = proc_put_char(&buffer, &left, '\t');
69569 + if (err)
69570 + break;
69571 + }
69572 err = proc_put_long(&buffer, &left, val, false);
69573 if (err)
69574 break;
69575 @@ -2941,6 +3016,12 @@ int proc_dostring(struct ctl_table *table, int write,
69576 return -ENOSYS;
69577 }
69578
69579 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69580 + void __user *buffer, size_t *lenp, loff_t *ppos)
69581 +{
69582 + return -ENOSYS;
69583 +}
69584 +
69585 int proc_dointvec(struct ctl_table *table, int write,
69586 void __user *buffer, size_t *lenp, loff_t *ppos)
69587 {
69588 @@ -2997,6 +3078,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
69589 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
69590 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
69591 EXPORT_SYMBOL(proc_dostring);
69592 +EXPORT_SYMBOL(proc_dostring_modpriv);
69593 EXPORT_SYMBOL(proc_doulongvec_minmax);
69594 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
69595 EXPORT_SYMBOL(register_sysctl_table);
69596 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
69597 index a650694..aaeeb20 100644
69598 --- a/kernel/sysctl_binary.c
69599 +++ b/kernel/sysctl_binary.c
69600 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
69601 int i;
69602
69603 set_fs(KERNEL_DS);
69604 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69605 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69606 set_fs(old_fs);
69607 if (result < 0)
69608 goto out_kfree;
69609 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
69610 }
69611
69612 set_fs(KERNEL_DS);
69613 - result = vfs_write(file, buffer, str - buffer, &pos);
69614 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69615 set_fs(old_fs);
69616 if (result < 0)
69617 goto out_kfree;
69618 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
69619 int i;
69620
69621 set_fs(KERNEL_DS);
69622 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69623 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69624 set_fs(old_fs);
69625 if (result < 0)
69626 goto out_kfree;
69627 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
69628 }
69629
69630 set_fs(KERNEL_DS);
69631 - result = vfs_write(file, buffer, str - buffer, &pos);
69632 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69633 set_fs(old_fs);
69634 if (result < 0)
69635 goto out_kfree;
69636 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
69637 int i;
69638
69639 set_fs(KERNEL_DS);
69640 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69641 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69642 set_fs(old_fs);
69643 if (result < 0)
69644 goto out;
69645 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69646 __le16 dnaddr;
69647
69648 set_fs(KERNEL_DS);
69649 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69650 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69651 set_fs(old_fs);
69652 if (result < 0)
69653 goto out;
69654 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69655 le16_to_cpu(dnaddr) & 0x3ff);
69656
69657 set_fs(KERNEL_DS);
69658 - result = vfs_write(file, buf, len, &pos);
69659 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
69660 set_fs(old_fs);
69661 if (result < 0)
69662 goto out;
69663 diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
69664 index 362da65..ab8ef8c 100644
69665 --- a/kernel/sysctl_check.c
69666 +++ b/kernel/sysctl_check.c
69667 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
69668 set_fail(&fail, table, "Directory with extra2");
69669 } else {
69670 if ((table->proc_handler == proc_dostring) ||
69671 + (table->proc_handler == proc_dostring_modpriv) ||
69672 (table->proc_handler == proc_dointvec) ||
69673 (table->proc_handler == proc_dointvec_minmax) ||
69674 (table->proc_handler == proc_dointvec_jiffies) ||
69675 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
69676 index e660464..c8b9e67 100644
69677 --- a/kernel/taskstats.c
69678 +++ b/kernel/taskstats.c
69679 @@ -27,9 +27,12 @@
69680 #include <linux/cgroup.h>
69681 #include <linux/fs.h>
69682 #include <linux/file.h>
69683 +#include <linux/grsecurity.h>
69684 #include <net/genetlink.h>
69685 #include <linux/atomic.h>
69686
69687 +extern int gr_is_taskstats_denied(int pid);
69688 +
69689 /*
69690 * Maximum length of a cpumask that can be specified in
69691 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
69692 @@ -556,6 +559,9 @@ err:
69693
69694 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
69695 {
69696 + if (gr_is_taskstats_denied(current->pid))
69697 + return -EACCES;
69698 +
69699 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
69700 return cmd_attr_register_cpumask(info);
69701 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
69702 diff --git a/kernel/time.c b/kernel/time.c
69703 index 73e416d..cfc6f69 100644
69704 --- a/kernel/time.c
69705 +++ b/kernel/time.c
69706 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
69707 return error;
69708
69709 if (tz) {
69710 + /* we log in do_settimeofday called below, so don't log twice
69711 + */
69712 + if (!tv)
69713 + gr_log_timechange();
69714 +
69715 /* SMP safe, global irq locking makes it work. */
69716 sys_tz = *tz;
69717 update_vsyscall_tz();
69718 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
69719 index 8a46f5d..bbe6f9c 100644
69720 --- a/kernel/time/alarmtimer.c
69721 +++ b/kernel/time/alarmtimer.c
69722 @@ -773,7 +773,7 @@ static int __init alarmtimer_init(void)
69723 struct platform_device *pdev;
69724 int error = 0;
69725 int i;
69726 - struct k_clock alarm_clock = {
69727 + static struct k_clock alarm_clock = {
69728 .clock_getres = alarm_clock_getres,
69729 .clock_get = alarm_clock_get,
69730 .timer_create = alarm_timer_create,
69731 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
69732 index fd4a7b1..fae5c2a 100644
69733 --- a/kernel/time/tick-broadcast.c
69734 +++ b/kernel/time/tick-broadcast.c
69735 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
69736 * then clear the broadcast bit.
69737 */
69738 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
69739 - int cpu = smp_processor_id();
69740 + cpu = smp_processor_id();
69741
69742 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
69743 tick_broadcast_clear_oneshot(cpu);
69744 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
69745 index 2378413..be455fd 100644
69746 --- a/kernel/time/timekeeping.c
69747 +++ b/kernel/time/timekeeping.c
69748 @@ -14,6 +14,7 @@
69749 #include <linux/init.h>
69750 #include <linux/mm.h>
69751 #include <linux/sched.h>
69752 +#include <linux/grsecurity.h>
69753 #include <linux/syscore_ops.h>
69754 #include <linux/clocksource.h>
69755 #include <linux/jiffies.h>
69756 @@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
69757 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
69758 return -EINVAL;
69759
69760 + gr_log_timechange();
69761 +
69762 write_seqlock_irqsave(&xtime_lock, flags);
69763
69764 timekeeping_forward_now();
69765 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
69766 index 3258455..f35227d 100644
69767 --- a/kernel/time/timer_list.c
69768 +++ b/kernel/time/timer_list.c
69769 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
69770
69771 static void print_name_offset(struct seq_file *m, void *sym)
69772 {
69773 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69774 + SEQ_printf(m, "<%p>", NULL);
69775 +#else
69776 char symname[KSYM_NAME_LEN];
69777
69778 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
69779 SEQ_printf(m, "<%pK>", sym);
69780 else
69781 SEQ_printf(m, "%s", symname);
69782 +#endif
69783 }
69784
69785 static void
69786 @@ -112,7 +116,11 @@ next_one:
69787 static void
69788 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
69789 {
69790 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69791 + SEQ_printf(m, " .base: %p\n", NULL);
69792 +#else
69793 SEQ_printf(m, " .base: %pK\n", base);
69794 +#endif
69795 SEQ_printf(m, " .index: %d\n",
69796 base->index);
69797 SEQ_printf(m, " .resolution: %Lu nsecs\n",
69798 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
69799 {
69800 struct proc_dir_entry *pe;
69801
69802 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69803 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
69804 +#else
69805 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
69806 +#endif
69807 if (!pe)
69808 return -ENOMEM;
69809 return 0;
69810 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
69811 index 0b537f2..9e71eca 100644
69812 --- a/kernel/time/timer_stats.c
69813 +++ b/kernel/time/timer_stats.c
69814 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
69815 static unsigned long nr_entries;
69816 static struct entry entries[MAX_ENTRIES];
69817
69818 -static atomic_t overflow_count;
69819 +static atomic_unchecked_t overflow_count;
69820
69821 /*
69822 * The entries are in a hash-table, for fast lookup:
69823 @@ -140,7 +140,7 @@ static void reset_entries(void)
69824 nr_entries = 0;
69825 memset(entries, 0, sizeof(entries));
69826 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
69827 - atomic_set(&overflow_count, 0);
69828 + atomic_set_unchecked(&overflow_count, 0);
69829 }
69830
69831 static struct entry *alloc_entry(void)
69832 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69833 if (likely(entry))
69834 entry->count++;
69835 else
69836 - atomic_inc(&overflow_count);
69837 + atomic_inc_unchecked(&overflow_count);
69838
69839 out_unlock:
69840 raw_spin_unlock_irqrestore(lock, flags);
69841 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69842
69843 static void print_name_offset(struct seq_file *m, unsigned long addr)
69844 {
69845 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69846 + seq_printf(m, "<%p>", NULL);
69847 +#else
69848 char symname[KSYM_NAME_LEN];
69849
69850 if (lookup_symbol_name(addr, symname) < 0)
69851 seq_printf(m, "<%p>", (void *)addr);
69852 else
69853 seq_printf(m, "%s", symname);
69854 +#endif
69855 }
69856
69857 static int tstats_show(struct seq_file *m, void *v)
69858 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
69859
69860 seq_puts(m, "Timer Stats Version: v0.2\n");
69861 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
69862 - if (atomic_read(&overflow_count))
69863 + if (atomic_read_unchecked(&overflow_count))
69864 seq_printf(m, "Overflow: %d entries\n",
69865 - atomic_read(&overflow_count));
69866 + atomic_read_unchecked(&overflow_count));
69867
69868 for (i = 0; i < nr_entries; i++) {
69869 entry = entries + i;
69870 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
69871 {
69872 struct proc_dir_entry *pe;
69873
69874 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69875 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
69876 +#else
69877 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
69878 +#endif
69879 if (!pe)
69880 return -ENOMEM;
69881 return 0;
69882 diff --git a/kernel/timer.c b/kernel/timer.c
69883 index 9c3c62b..441690e 100644
69884 --- a/kernel/timer.c
69885 +++ b/kernel/timer.c
69886 @@ -1304,7 +1304,7 @@ void update_process_times(int user_tick)
69887 /*
69888 * This function runs timers and the timer-tq in bottom half context.
69889 */
69890 -static void run_timer_softirq(struct softirq_action *h)
69891 +static void run_timer_softirq(void)
69892 {
69893 struct tvec_base *base = __this_cpu_read(tvec_bases);
69894
69895 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
69896 index 16fc34a..efd8bb8 100644
69897 --- a/kernel/trace/blktrace.c
69898 +++ b/kernel/trace/blktrace.c
69899 @@ -324,7 +324,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
69900 struct blk_trace *bt = filp->private_data;
69901 char buf[16];
69902
69903 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
69904 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
69905
69906 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
69907 }
69908 @@ -389,7 +389,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
69909 return 1;
69910
69911 bt = buf->chan->private_data;
69912 - atomic_inc(&bt->dropped);
69913 + atomic_inc_unchecked(&bt->dropped);
69914 return 0;
69915 }
69916
69917 @@ -490,7 +490,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
69918
69919 bt->dir = dir;
69920 bt->dev = dev;
69921 - atomic_set(&bt->dropped, 0);
69922 + atomic_set_unchecked(&bt->dropped, 0);
69923
69924 ret = -EIO;
69925 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
69926 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
69927 index 25b4f4d..6f4772d 100644
69928 --- a/kernel/trace/ftrace.c
69929 +++ b/kernel/trace/ftrace.c
69930 @@ -1587,12 +1587,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
69931 if (unlikely(ftrace_disabled))
69932 return 0;
69933
69934 + ret = ftrace_arch_code_modify_prepare();
69935 + FTRACE_WARN_ON(ret);
69936 + if (ret)
69937 + return 0;
69938 +
69939 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
69940 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
69941 if (ret) {
69942 ftrace_bug(ret, ip);
69943 - return 0;
69944 }
69945 - return 1;
69946 + return ret ? 0 : 1;
69947 }
69948
69949 /*
69950 @@ -2608,7 +2613,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
69951
69952 int
69953 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
69954 - void *data)
69955 + void *data)
69956 {
69957 struct ftrace_func_probe *entry;
69958 struct ftrace_page *pg;
69959 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
69960 index f2bd275..adaf3a2 100644
69961 --- a/kernel/trace/trace.c
69962 +++ b/kernel/trace/trace.c
69963 @@ -4201,10 +4201,9 @@ static const struct file_operations tracing_dyn_info_fops = {
69964 };
69965 #endif
69966
69967 -static struct dentry *d_tracer;
69968 -
69969 struct dentry *tracing_init_dentry(void)
69970 {
69971 + static struct dentry *d_tracer;
69972 static int once;
69973
69974 if (d_tracer)
69975 @@ -4224,10 +4223,9 @@ struct dentry *tracing_init_dentry(void)
69976 return d_tracer;
69977 }
69978
69979 -static struct dentry *d_percpu;
69980 -
69981 struct dentry *tracing_dentry_percpu(void)
69982 {
69983 + static struct dentry *d_percpu;
69984 static int once;
69985 struct dentry *d_tracer;
69986
69987 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
69988 index c212a7f..7b02394 100644
69989 --- a/kernel/trace/trace_events.c
69990 +++ b/kernel/trace/trace_events.c
69991 @@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
69992 struct ftrace_module_file_ops {
69993 struct list_head list;
69994 struct module *mod;
69995 - struct file_operations id;
69996 - struct file_operations enable;
69997 - struct file_operations format;
69998 - struct file_operations filter;
69999 };
70000
70001 static struct ftrace_module_file_ops *
70002 @@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
70003
70004 file_ops->mod = mod;
70005
70006 - file_ops->id = ftrace_event_id_fops;
70007 - file_ops->id.owner = mod;
70008 -
70009 - file_ops->enable = ftrace_enable_fops;
70010 - file_ops->enable.owner = mod;
70011 -
70012 - file_ops->filter = ftrace_event_filter_fops;
70013 - file_ops->filter.owner = mod;
70014 -
70015 - file_ops->format = ftrace_event_format_fops;
70016 - file_ops->format.owner = mod;
70017 + pax_open_kernel();
70018 + *(void **)&mod->trace_id.owner = mod;
70019 + *(void **)&mod->trace_enable.owner = mod;
70020 + *(void **)&mod->trace_filter.owner = mod;
70021 + *(void **)&mod->trace_format.owner = mod;
70022 + pax_close_kernel();
70023
70024 list_add(&file_ops->list, &ftrace_module_file_list);
70025
70026 @@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
70027
70028 for_each_event(call, start, end) {
70029 __trace_add_event_call(*call, mod,
70030 - &file_ops->id, &file_ops->enable,
70031 - &file_ops->filter, &file_ops->format);
70032 + &mod->trace_id, &mod->trace_enable,
70033 + &mod->trace_filter, &mod->trace_format);
70034 }
70035 }
70036
70037 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
70038 index 00d527c..7c5b1a3 100644
70039 --- a/kernel/trace/trace_kprobe.c
70040 +++ b/kernel/trace/trace_kprobe.c
70041 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
70042 long ret;
70043 int maxlen = get_rloc_len(*(u32 *)dest);
70044 u8 *dst = get_rloc_data(dest);
70045 - u8 *src = addr;
70046 + const u8 __user *src = (const u8 __force_user *)addr;
70047 mm_segment_t old_fs = get_fs();
70048 if (!maxlen)
70049 return;
70050 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
70051 pagefault_disable();
70052 do
70053 ret = __copy_from_user_inatomic(dst++, src++, 1);
70054 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
70055 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
70056 dst[-1] = '\0';
70057 pagefault_enable();
70058 set_fs(old_fs);
70059 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
70060 ((u8 *)get_rloc_data(dest))[0] = '\0';
70061 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
70062 } else
70063 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
70064 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
70065 get_rloc_offs(*(u32 *)dest));
70066 }
70067 /* Return the length of string -- including null terminal byte */
70068 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
70069 set_fs(KERNEL_DS);
70070 pagefault_disable();
70071 do {
70072 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
70073 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
70074 len++;
70075 } while (c && ret == 0 && len < MAX_STRING_SIZE);
70076 pagefault_enable();
70077 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70078 index fd3c8aa..5f324a6 100644
70079 --- a/kernel/trace/trace_mmiotrace.c
70080 +++ b/kernel/trace/trace_mmiotrace.c
70081 @@ -24,7 +24,7 @@ struct header_iter {
70082 static struct trace_array *mmio_trace_array;
70083 static bool overrun_detected;
70084 static unsigned long prev_overruns;
70085 -static atomic_t dropped_count;
70086 +static atomic_unchecked_t dropped_count;
70087
70088 static void mmio_reset_data(struct trace_array *tr)
70089 {
70090 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70091
70092 static unsigned long count_overruns(struct trace_iterator *iter)
70093 {
70094 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
70095 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70096 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70097
70098 if (over > prev_overruns)
70099 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70100 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70101 sizeof(*entry), 0, pc);
70102 if (!event) {
70103 - atomic_inc(&dropped_count);
70104 + atomic_inc_unchecked(&dropped_count);
70105 return;
70106 }
70107 entry = ring_buffer_event_data(event);
70108 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70109 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70110 sizeof(*entry), 0, pc);
70111 if (!event) {
70112 - atomic_inc(&dropped_count);
70113 + atomic_inc_unchecked(&dropped_count);
70114 return;
70115 }
70116 entry = ring_buffer_event_data(event);
70117 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
70118 index 5199930..26c73a0 100644
70119 --- a/kernel/trace/trace_output.c
70120 +++ b/kernel/trace/trace_output.c
70121 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
70122
70123 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
70124 if (!IS_ERR(p)) {
70125 - p = mangle_path(s->buffer + s->len, p, "\n");
70126 + p = mangle_path(s->buffer + s->len, p, "\n\\");
70127 if (p) {
70128 s->len = p - s->buffer;
70129 return 1;
70130 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
70131 index 77575b3..6e623d1 100644
70132 --- a/kernel/trace/trace_stack.c
70133 +++ b/kernel/trace/trace_stack.c
70134 @@ -50,7 +50,7 @@ static inline void check_stack(void)
70135 return;
70136
70137 /* we do not handle interrupt stacks yet */
70138 - if (!object_is_on_stack(&this_size))
70139 + if (!object_starts_on_stack(&this_size))
70140 return;
70141
70142 local_irq_save(flags);
70143 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
70144 index 209b379..7f76423 100644
70145 --- a/kernel/trace/trace_workqueue.c
70146 +++ b/kernel/trace/trace_workqueue.c
70147 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
70148 int cpu;
70149 pid_t pid;
70150 /* Can be inserted from interrupt or user context, need to be atomic */
70151 - atomic_t inserted;
70152 + atomic_unchecked_t inserted;
70153 /*
70154 * Don't need to be atomic, works are serialized in a single workqueue thread
70155 * on a single CPU.
70156 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
70157 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
70158 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
70159 if (node->pid == wq_thread->pid) {
70160 - atomic_inc(&node->inserted);
70161 + atomic_inc_unchecked(&node->inserted);
70162 goto found;
70163 }
70164 }
70165 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
70166 tsk = get_pid_task(pid, PIDTYPE_PID);
70167 if (tsk) {
70168 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
70169 - atomic_read(&cws->inserted), cws->executed,
70170 + atomic_read_unchecked(&cws->inserted), cws->executed,
70171 tsk->comm);
70172 put_task_struct(tsk);
70173 }
70174 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
70175 index 82928f5..92da771 100644
70176 --- a/lib/Kconfig.debug
70177 +++ b/lib/Kconfig.debug
70178 @@ -1103,6 +1103,7 @@ config LATENCYTOP
70179 depends on DEBUG_KERNEL
70180 depends on STACKTRACE_SUPPORT
70181 depends on PROC_FS
70182 + depends on !GRKERNSEC_HIDESYM
70183 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
70184 select KALLSYMS
70185 select KALLSYMS_ALL
70186 diff --git a/lib/bitmap.c b/lib/bitmap.c
70187 index 0d4a127..33a06c7 100644
70188 --- a/lib/bitmap.c
70189 +++ b/lib/bitmap.c
70190 @@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
70191 {
70192 int c, old_c, totaldigits, ndigits, nchunks, nbits;
70193 u32 chunk;
70194 - const char __user __force *ubuf = (const char __user __force *)buf;
70195 + const char __user *ubuf = (const char __force_user *)buf;
70196
70197 bitmap_zero(maskp, nmaskbits);
70198
70199 @@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
70200 {
70201 if (!access_ok(VERIFY_READ, ubuf, ulen))
70202 return -EFAULT;
70203 - return __bitmap_parse((const char __force *)ubuf,
70204 + return __bitmap_parse((const char __force_kernel *)ubuf,
70205 ulen, 1, maskp, nmaskbits);
70206
70207 }
70208 @@ -596,7 +596,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
70209 {
70210 unsigned a, b;
70211 int c, old_c, totaldigits;
70212 - const char __user __force *ubuf = (const char __user __force *)buf;
70213 + const char __user *ubuf = (const char __force_user *)buf;
70214 int exp_digit, in_range;
70215
70216 totaldigits = c = 0;
70217 @@ -696,7 +696,7 @@ int bitmap_parselist_user(const char __user *ubuf,
70218 {
70219 if (!access_ok(VERIFY_READ, ubuf, ulen))
70220 return -EFAULT;
70221 - return __bitmap_parselist((const char __force *)ubuf,
70222 + return __bitmap_parselist((const char __force_kernel *)ubuf,
70223 ulen, 1, maskp, nmaskbits);
70224 }
70225 EXPORT_SYMBOL(bitmap_parselist_user);
70226 diff --git a/lib/bug.c b/lib/bug.c
70227 index 1955209..cbbb2ad 100644
70228 --- a/lib/bug.c
70229 +++ b/lib/bug.c
70230 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
70231 return BUG_TRAP_TYPE_NONE;
70232
70233 bug = find_bug(bugaddr);
70234 + if (!bug)
70235 + return BUG_TRAP_TYPE_NONE;
70236
70237 file = NULL;
70238 line = 0;
70239 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
70240 index a78b7c6..2c73084 100644
70241 --- a/lib/debugobjects.c
70242 +++ b/lib/debugobjects.c
70243 @@ -284,7 +284,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
70244 if (limit > 4)
70245 return;
70246
70247 - is_on_stack = object_is_on_stack(addr);
70248 + is_on_stack = object_starts_on_stack(addr);
70249 if (is_on_stack == onstack)
70250 return;
70251
70252 diff --git a/lib/devres.c b/lib/devres.c
70253 index 7c0e953..f642b5c 100644
70254 --- a/lib/devres.c
70255 +++ b/lib/devres.c
70256 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
70257 void devm_iounmap(struct device *dev, void __iomem *addr)
70258 {
70259 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
70260 - (void *)addr));
70261 + (void __force *)addr));
70262 iounmap(addr);
70263 }
70264 EXPORT_SYMBOL(devm_iounmap);
70265 @@ -141,7 +141,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
70266 {
70267 ioport_unmap(addr);
70268 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
70269 - devm_ioport_map_match, (void *)addr));
70270 + devm_ioport_map_match, (void __force *)addr));
70271 }
70272 EXPORT_SYMBOL(devm_ioport_unmap);
70273
70274 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
70275 index fea790a..ebb0e82 100644
70276 --- a/lib/dma-debug.c
70277 +++ b/lib/dma-debug.c
70278 @@ -925,7 +925,7 @@ out:
70279
70280 static void check_for_stack(struct device *dev, void *addr)
70281 {
70282 - if (object_is_on_stack(addr))
70283 + if (object_starts_on_stack(addr))
70284 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
70285 "stack [addr=%p]\n", addr);
70286 }
70287 diff --git a/lib/extable.c b/lib/extable.c
70288 index 4cac81e..63e9b8f 100644
70289 --- a/lib/extable.c
70290 +++ b/lib/extable.c
70291 @@ -13,6 +13,7 @@
70292 #include <linux/init.h>
70293 #include <linux/sort.h>
70294 #include <asm/uaccess.h>
70295 +#include <asm/pgtable.h>
70296
70297 #ifndef ARCH_HAS_SORT_EXTABLE
70298 /*
70299 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
70300 void sort_extable(struct exception_table_entry *start,
70301 struct exception_table_entry *finish)
70302 {
70303 + pax_open_kernel();
70304 sort(start, finish - start, sizeof(struct exception_table_entry),
70305 cmp_ex, NULL);
70306 + pax_close_kernel();
70307 }
70308
70309 #ifdef CONFIG_MODULES
70310 diff --git a/lib/inflate.c b/lib/inflate.c
70311 index 013a761..c28f3fc 100644
70312 --- a/lib/inflate.c
70313 +++ b/lib/inflate.c
70314 @@ -269,7 +269,7 @@ static void free(void *where)
70315 malloc_ptr = free_mem_ptr;
70316 }
70317 #else
70318 -#define malloc(a) kmalloc(a, GFP_KERNEL)
70319 +#define malloc(a) kmalloc((a), GFP_KERNEL)
70320 #define free(a) kfree(a)
70321 #endif
70322
70323 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70324 index bd2bea9..6b3c95e 100644
70325 --- a/lib/is_single_threaded.c
70326 +++ b/lib/is_single_threaded.c
70327 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70328 struct task_struct *p, *t;
70329 bool ret;
70330
70331 + if (!mm)
70332 + return true;
70333 +
70334 if (atomic_read(&task->signal->live) != 1)
70335 return false;
70336
70337 diff --git a/lib/kref.c b/lib/kref.c
70338 index 3efb882..8492f4c 100644
70339 --- a/lib/kref.c
70340 +++ b/lib/kref.c
70341 @@ -52,7 +52,7 @@ void kref_get(struct kref *kref)
70342 */
70343 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
70344 {
70345 - WARN_ON(release == NULL);
70346 + BUG_ON(release == NULL);
70347 WARN_ON(release == (void (*)(struct kref *))kfree);
70348
70349 if (atomic_dec_and_test(&kref->refcount)) {
70350 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70351 index d9df745..e73c2fe 100644
70352 --- a/lib/radix-tree.c
70353 +++ b/lib/radix-tree.c
70354 @@ -80,7 +80,7 @@ struct radix_tree_preload {
70355 int nr;
70356 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
70357 };
70358 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70359 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70360
70361 static inline void *ptr_to_indirect(void *ptr)
70362 {
70363 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70364 index 993599e..f1dbc14 100644
70365 --- a/lib/vsprintf.c
70366 +++ b/lib/vsprintf.c
70367 @@ -16,6 +16,9 @@
70368 * - scnprintf and vscnprintf
70369 */
70370
70371 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70372 +#define __INCLUDED_BY_HIDESYM 1
70373 +#endif
70374 #include <stdarg.h>
70375 #include <linux/module.h>
70376 #include <linux/types.h>
70377 @@ -413,7 +416,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70378 char sym[KSYM_SYMBOL_LEN];
70379 if (ext == 'B')
70380 sprint_backtrace(sym, value);
70381 - else if (ext != 'f' && ext != 's')
70382 + else if (ext != 'f' && ext != 's' && ext != 'a')
70383 sprint_symbol(sym, value);
70384 else
70385 kallsyms_lookup(value, NULL, NULL, NULL, sym);
70386 @@ -777,7 +780,11 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
70387 return string(buf, end, uuid, spec);
70388 }
70389
70390 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70391 +int kptr_restrict __read_mostly = 2;
70392 +#else
70393 int kptr_restrict __read_mostly;
70394 +#endif
70395
70396 /*
70397 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70398 @@ -791,6 +798,8 @@ int kptr_restrict __read_mostly;
70399 * - 'S' For symbolic direct pointers with offset
70400 * - 's' For symbolic direct pointers without offset
70401 * - 'B' For backtraced symbolic direct pointers with offset
70402 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70403 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70404 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70405 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70406 * - 'M' For a 6-byte MAC address, it prints the address in the
70407 @@ -835,12 +844,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70408 {
70409 if (!ptr && *fmt != 'K') {
70410 /*
70411 - * Print (null) with the same width as a pointer so it makes
70412 + * Print (nil) with the same width as a pointer so it makes
70413 * tabular output look nice.
70414 */
70415 if (spec.field_width == -1)
70416 spec.field_width = 2 * sizeof(void *);
70417 - return string(buf, end, "(null)", spec);
70418 + return string(buf, end, "(nil)", spec);
70419 }
70420
70421 switch (*fmt) {
70422 @@ -850,6 +859,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70423 /* Fallthrough */
70424 case 'S':
70425 case 's':
70426 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70427 + break;
70428 +#else
70429 + return symbol_string(buf, end, ptr, spec, *fmt);
70430 +#endif
70431 + case 'A':
70432 + case 'a':
70433 case 'B':
70434 return symbol_string(buf, end, ptr, spec, *fmt);
70435 case 'R':
70436 @@ -878,9 +894,15 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70437 case 'U':
70438 return uuid_string(buf, end, ptr, spec, fmt);
70439 case 'V':
70440 - return buf + vsnprintf(buf, end > buf ? end - buf : 0,
70441 - ((struct va_format *)ptr)->fmt,
70442 - *(((struct va_format *)ptr)->va));
70443 + {
70444 + va_list va;
70445 +
70446 + va_copy(va, *((struct va_format *)ptr)->va);
70447 + buf += vsnprintf(buf, end > buf ? end - buf : 0,
70448 + ((struct va_format *)ptr)->fmt, va);
70449 + va_end(va);
70450 + return buf;
70451 + }
70452 case 'K':
70453 /*
70454 * %pK cannot be used in IRQ context because its test
70455 @@ -1608,11 +1630,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70456 typeof(type) value; \
70457 if (sizeof(type) == 8) { \
70458 args = PTR_ALIGN(args, sizeof(u32)); \
70459 - *(u32 *)&value = *(u32 *)args; \
70460 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70461 + *(u32 *)&value = *(const u32 *)args; \
70462 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70463 } else { \
70464 args = PTR_ALIGN(args, sizeof(type)); \
70465 - value = *(typeof(type) *)args; \
70466 + value = *(const typeof(type) *)args; \
70467 } \
70468 args += sizeof(type); \
70469 value; \
70470 @@ -1675,7 +1697,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70471 case FORMAT_TYPE_STR: {
70472 const char *str_arg = args;
70473 args += strlen(str_arg) + 1;
70474 - str = string(str, end, (char *)str_arg, spec);
70475 + str = string(str, end, str_arg, spec);
70476 break;
70477 }
70478
70479 diff --git a/localversion-grsec b/localversion-grsec
70480 new file mode 100644
70481 index 0000000..7cd6065
70482 --- /dev/null
70483 +++ b/localversion-grsec
70484 @@ -0,0 +1 @@
70485 +-grsec
70486 diff --git a/mm/Kconfig b/mm/Kconfig
70487 index 011b110..b492af2 100644
70488 --- a/mm/Kconfig
70489 +++ b/mm/Kconfig
70490 @@ -241,10 +241,10 @@ config KSM
70491 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70492
70493 config DEFAULT_MMAP_MIN_ADDR
70494 - int "Low address space to protect from user allocation"
70495 + int "Low address space to protect from user allocation"
70496 depends on MMU
70497 - default 4096
70498 - help
70499 + default 65536
70500 + help
70501 This is the portion of low virtual memory which should be protected
70502 from userspace allocation. Keeping a user from writing to low pages
70503 can help reduce the impact of kernel NULL pointer bugs.
70504 diff --git a/mm/filemap.c b/mm/filemap.c
70505 index 03c5b0e..a01e793 100644
70506 --- a/mm/filemap.c
70507 +++ b/mm/filemap.c
70508 @@ -1770,7 +1770,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70509 struct address_space *mapping = file->f_mapping;
70510
70511 if (!mapping->a_ops->readpage)
70512 - return -ENOEXEC;
70513 + return -ENODEV;
70514 file_accessed(file);
70515 vma->vm_ops = &generic_file_vm_ops;
70516 vma->vm_flags |= VM_CAN_NONLINEAR;
70517 @@ -2176,6 +2176,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70518 *pos = i_size_read(inode);
70519
70520 if (limit != RLIM_INFINITY) {
70521 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70522 if (*pos >= limit) {
70523 send_sig(SIGXFSZ, current, 0);
70524 return -EFBIG;
70525 diff --git a/mm/fremap.c b/mm/fremap.c
70526 index 9ed4fd4..c42648d 100644
70527 --- a/mm/fremap.c
70528 +++ b/mm/fremap.c
70529 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70530 retry:
70531 vma = find_vma(mm, start);
70532
70533 +#ifdef CONFIG_PAX_SEGMEXEC
70534 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70535 + goto out;
70536 +#endif
70537 +
70538 /*
70539 * Make sure the vma is shared, that it supports prefaulting,
70540 * and that the remapped range is valid and fully within
70541 diff --git a/mm/highmem.c b/mm/highmem.c
70542 index 57d82c6..e9e0552 100644
70543 --- a/mm/highmem.c
70544 +++ b/mm/highmem.c
70545 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70546 * So no dangers, even with speculative execution.
70547 */
70548 page = pte_page(pkmap_page_table[i]);
70549 + pax_open_kernel();
70550 pte_clear(&init_mm, (unsigned long)page_address(page),
70551 &pkmap_page_table[i]);
70552 -
70553 + pax_close_kernel();
70554 set_page_address(page, NULL);
70555 need_flush = 1;
70556 }
70557 @@ -186,9 +187,11 @@ start:
70558 }
70559 }
70560 vaddr = PKMAP_ADDR(last_pkmap_nr);
70561 +
70562 + pax_open_kernel();
70563 set_pte_at(&init_mm, vaddr,
70564 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70565 -
70566 + pax_close_kernel();
70567 pkmap_count[last_pkmap_nr] = 1;
70568 set_page_address(page, (void *)vaddr);
70569
70570 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70571 index 8f005e9..1cb1036 100644
70572 --- a/mm/huge_memory.c
70573 +++ b/mm/huge_memory.c
70574 @@ -704,7 +704,7 @@ out:
70575 * run pte_offset_map on the pmd, if an huge pmd could
70576 * materialize from under us from a different thread.
70577 */
70578 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70579 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70580 return VM_FAULT_OOM;
70581 /* if an huge pmd materialized from under us just retry later */
70582 if (unlikely(pmd_trans_huge(*pmd)))
70583 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70584 index 2316840..b418671 100644
70585 --- a/mm/hugetlb.c
70586 +++ b/mm/hugetlb.c
70587 @@ -2347,6 +2347,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70588 return 1;
70589 }
70590
70591 +#ifdef CONFIG_PAX_SEGMEXEC
70592 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70593 +{
70594 + struct mm_struct *mm = vma->vm_mm;
70595 + struct vm_area_struct *vma_m;
70596 + unsigned long address_m;
70597 + pte_t *ptep_m;
70598 +
70599 + vma_m = pax_find_mirror_vma(vma);
70600 + if (!vma_m)
70601 + return;
70602 +
70603 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70604 + address_m = address + SEGMEXEC_TASK_SIZE;
70605 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70606 + get_page(page_m);
70607 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
70608 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70609 +}
70610 +#endif
70611 +
70612 /*
70613 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70614 */
70615 @@ -2450,6 +2471,11 @@ retry_avoidcopy:
70616 make_huge_pte(vma, new_page, 1));
70617 page_remove_rmap(old_page);
70618 hugepage_add_new_anon_rmap(new_page, vma, address);
70619 +
70620 +#ifdef CONFIG_PAX_SEGMEXEC
70621 + pax_mirror_huge_pte(vma, address, new_page);
70622 +#endif
70623 +
70624 /* Make the old page be freed below */
70625 new_page = old_page;
70626 mmu_notifier_invalidate_range_end(mm,
70627 @@ -2601,6 +2627,10 @@ retry:
70628 && (vma->vm_flags & VM_SHARED)));
70629 set_huge_pte_at(mm, address, ptep, new_pte);
70630
70631 +#ifdef CONFIG_PAX_SEGMEXEC
70632 + pax_mirror_huge_pte(vma, address, page);
70633 +#endif
70634 +
70635 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
70636 /* Optimization, do the COW without a second fault */
70637 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
70638 @@ -2630,6 +2660,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70639 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
70640 struct hstate *h = hstate_vma(vma);
70641
70642 +#ifdef CONFIG_PAX_SEGMEXEC
70643 + struct vm_area_struct *vma_m;
70644 +#endif
70645 +
70646 ptep = huge_pte_offset(mm, address);
70647 if (ptep) {
70648 entry = huge_ptep_get(ptep);
70649 @@ -2641,6 +2675,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70650 VM_FAULT_SET_HINDEX(h - hstates);
70651 }
70652
70653 +#ifdef CONFIG_PAX_SEGMEXEC
70654 + vma_m = pax_find_mirror_vma(vma);
70655 + if (vma_m) {
70656 + unsigned long address_m;
70657 +
70658 + if (vma->vm_start > vma_m->vm_start) {
70659 + address_m = address;
70660 + address -= SEGMEXEC_TASK_SIZE;
70661 + vma = vma_m;
70662 + h = hstate_vma(vma);
70663 + } else
70664 + address_m = address + SEGMEXEC_TASK_SIZE;
70665 +
70666 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
70667 + return VM_FAULT_OOM;
70668 + address_m &= HPAGE_MASK;
70669 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
70670 + }
70671 +#endif
70672 +
70673 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
70674 if (!ptep)
70675 return VM_FAULT_OOM;
70676 diff --git a/mm/internal.h b/mm/internal.h
70677 index 2189af4..f2ca332 100644
70678 --- a/mm/internal.h
70679 +++ b/mm/internal.h
70680 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
70681 * in mm/page_alloc.c
70682 */
70683 extern void __free_pages_bootmem(struct page *page, unsigned int order);
70684 +extern void free_compound_page(struct page *page);
70685 extern void prep_compound_page(struct page *page, unsigned long order);
70686 #ifdef CONFIG_MEMORY_FAILURE
70687 extern bool is_free_buddy_page(struct page *page);
70688 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
70689 index f3b2a00..61da94d 100644
70690 --- a/mm/kmemleak.c
70691 +++ b/mm/kmemleak.c
70692 @@ -357,7 +357,7 @@ static void print_unreferenced(struct seq_file *seq,
70693
70694 for (i = 0; i < object->trace_len; i++) {
70695 void *ptr = (void *)object->trace[i];
70696 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
70697 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
70698 }
70699 }
70700
70701 diff --git a/mm/maccess.c b/mm/maccess.c
70702 index d53adf9..03a24bf 100644
70703 --- a/mm/maccess.c
70704 +++ b/mm/maccess.c
70705 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
70706 set_fs(KERNEL_DS);
70707 pagefault_disable();
70708 ret = __copy_from_user_inatomic(dst,
70709 - (__force const void __user *)src, size);
70710 + (const void __force_user *)src, size);
70711 pagefault_enable();
70712 set_fs(old_fs);
70713
70714 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
70715
70716 set_fs(KERNEL_DS);
70717 pagefault_disable();
70718 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
70719 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
70720 pagefault_enable();
70721 set_fs(old_fs);
70722
70723 diff --git a/mm/madvise.c b/mm/madvise.c
70724 index 74bf193..feb6fd3 100644
70725 --- a/mm/madvise.c
70726 +++ b/mm/madvise.c
70727 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
70728 pgoff_t pgoff;
70729 unsigned long new_flags = vma->vm_flags;
70730
70731 +#ifdef CONFIG_PAX_SEGMEXEC
70732 + struct vm_area_struct *vma_m;
70733 +#endif
70734 +
70735 switch (behavior) {
70736 case MADV_NORMAL:
70737 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
70738 @@ -110,6 +114,13 @@ success:
70739 /*
70740 * vm_flags is protected by the mmap_sem held in write mode.
70741 */
70742 +
70743 +#ifdef CONFIG_PAX_SEGMEXEC
70744 + vma_m = pax_find_mirror_vma(vma);
70745 + if (vma_m)
70746 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
70747 +#endif
70748 +
70749 vma->vm_flags = new_flags;
70750
70751 out:
70752 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70753 struct vm_area_struct ** prev,
70754 unsigned long start, unsigned long end)
70755 {
70756 +
70757 +#ifdef CONFIG_PAX_SEGMEXEC
70758 + struct vm_area_struct *vma_m;
70759 +#endif
70760 +
70761 *prev = vma;
70762 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
70763 return -EINVAL;
70764 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70765 zap_page_range(vma, start, end - start, &details);
70766 } else
70767 zap_page_range(vma, start, end - start, NULL);
70768 +
70769 +#ifdef CONFIG_PAX_SEGMEXEC
70770 + vma_m = pax_find_mirror_vma(vma);
70771 + if (vma_m) {
70772 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
70773 + struct zap_details details = {
70774 + .nonlinear_vma = vma_m,
70775 + .last_index = ULONG_MAX,
70776 + };
70777 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
70778 + } else
70779 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
70780 + }
70781 +#endif
70782 +
70783 return 0;
70784 }
70785
70786 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
70787 if (end < start)
70788 goto out;
70789
70790 +#ifdef CONFIG_PAX_SEGMEXEC
70791 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70792 + if (end > SEGMEXEC_TASK_SIZE)
70793 + goto out;
70794 + } else
70795 +#endif
70796 +
70797 + if (end > TASK_SIZE)
70798 + goto out;
70799 +
70800 error = 0;
70801 if (end == start)
70802 goto out;
70803 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
70804 index 06d3479..0778eef 100644
70805 --- a/mm/memory-failure.c
70806 +++ b/mm/memory-failure.c
70807 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
70808
70809 int sysctl_memory_failure_recovery __read_mostly = 1;
70810
70811 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70812 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70813
70814 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
70815
70816 @@ -202,7 +202,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
70817 si.si_signo = SIGBUS;
70818 si.si_errno = 0;
70819 si.si_code = BUS_MCEERR_AO;
70820 - si.si_addr = (void *)addr;
70821 + si.si_addr = (void __user *)addr;
70822 #ifdef __ARCH_SI_TRAPNO
70823 si.si_trapno = trapno;
70824 #endif
70825 @@ -1010,7 +1010,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70826 }
70827
70828 nr_pages = 1 << compound_trans_order(hpage);
70829 - atomic_long_add(nr_pages, &mce_bad_pages);
70830 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
70831
70832 /*
70833 * We need/can do nothing about count=0 pages.
70834 @@ -1040,7 +1040,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70835 if (!PageHWPoison(hpage)
70836 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
70837 || (p != hpage && TestSetPageHWPoison(hpage))) {
70838 - atomic_long_sub(nr_pages, &mce_bad_pages);
70839 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70840 return 0;
70841 }
70842 set_page_hwpoison_huge_page(hpage);
70843 @@ -1098,7 +1098,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70844 }
70845 if (hwpoison_filter(p)) {
70846 if (TestClearPageHWPoison(p))
70847 - atomic_long_sub(nr_pages, &mce_bad_pages);
70848 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70849 unlock_page(hpage);
70850 put_page(hpage);
70851 return 0;
70852 @@ -1315,7 +1315,7 @@ int unpoison_memory(unsigned long pfn)
70853 return 0;
70854 }
70855 if (TestClearPageHWPoison(p))
70856 - atomic_long_sub(nr_pages, &mce_bad_pages);
70857 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70858 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
70859 return 0;
70860 }
70861 @@ -1329,7 +1329,7 @@ int unpoison_memory(unsigned long pfn)
70862 */
70863 if (TestClearPageHWPoison(page)) {
70864 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
70865 - atomic_long_sub(nr_pages, &mce_bad_pages);
70866 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70867 freeit = 1;
70868 if (PageHuge(page))
70869 clear_page_hwpoison_huge_page(page);
70870 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
70871 }
70872 done:
70873 if (!PageHWPoison(hpage))
70874 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
70875 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
70876 set_page_hwpoison_huge_page(hpage);
70877 dequeue_hwpoisoned_huge_page(hpage);
70878 /* keep elevated page count for bad page */
70879 @@ -1573,7 +1573,7 @@ int soft_offline_page(struct page *page, int flags)
70880 return ret;
70881
70882 done:
70883 - atomic_long_add(1, &mce_bad_pages);
70884 + atomic_long_add_unchecked(1, &mce_bad_pages);
70885 SetPageHWPoison(page);
70886 /* keep elevated page count for bad page */
70887 return ret;
70888 diff --git a/mm/memory.c b/mm/memory.c
70889 index 829d437..3d3926a 100644
70890 --- a/mm/memory.c
70891 +++ b/mm/memory.c
70892 @@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
70893 return;
70894
70895 pmd = pmd_offset(pud, start);
70896 +
70897 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
70898 pud_clear(pud);
70899 pmd_free_tlb(tlb, pmd, start);
70900 +#endif
70901 +
70902 }
70903
70904 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70905 @@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70906 if (end - 1 > ceiling - 1)
70907 return;
70908
70909 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
70910 pud = pud_offset(pgd, start);
70911 pgd_clear(pgd);
70912 pud_free_tlb(tlb, pud, start);
70913 +#endif
70914 +
70915 }
70916
70917 /*
70918 @@ -1566,12 +1573,6 @@ no_page_table:
70919 return page;
70920 }
70921
70922 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
70923 -{
70924 - return stack_guard_page_start(vma, addr) ||
70925 - stack_guard_page_end(vma, addr+PAGE_SIZE);
70926 -}
70927 -
70928 /**
70929 * __get_user_pages() - pin user pages in memory
70930 * @tsk: task_struct of target task
70931 @@ -1644,10 +1645,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70932 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
70933 i = 0;
70934
70935 - do {
70936 + while (nr_pages) {
70937 struct vm_area_struct *vma;
70938
70939 - vma = find_extend_vma(mm, start);
70940 + vma = find_vma(mm, start);
70941 if (!vma && in_gate_area(mm, start)) {
70942 unsigned long pg = start & PAGE_MASK;
70943 pgd_t *pgd;
70944 @@ -1695,7 +1696,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70945 goto next_page;
70946 }
70947
70948 - if (!vma ||
70949 + if (!vma || start < vma->vm_start ||
70950 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
70951 !(vm_flags & vma->vm_flags))
70952 return i ? : -EFAULT;
70953 @@ -1722,11 +1723,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70954 int ret;
70955 unsigned int fault_flags = 0;
70956
70957 - /* For mlock, just skip the stack guard page. */
70958 - if (foll_flags & FOLL_MLOCK) {
70959 - if (stack_guard_page(vma, start))
70960 - goto next_page;
70961 - }
70962 if (foll_flags & FOLL_WRITE)
70963 fault_flags |= FAULT_FLAG_WRITE;
70964 if (nonblocking)
70965 @@ -1800,7 +1796,7 @@ next_page:
70966 start += PAGE_SIZE;
70967 nr_pages--;
70968 } while (nr_pages && start < vma->vm_end);
70969 - } while (nr_pages);
70970 + }
70971 return i;
70972 }
70973 EXPORT_SYMBOL(__get_user_pages);
70974 @@ -2007,6 +2003,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
70975 page_add_file_rmap(page);
70976 set_pte_at(mm, addr, pte, mk_pte(page, prot));
70977
70978 +#ifdef CONFIG_PAX_SEGMEXEC
70979 + pax_mirror_file_pte(vma, addr, page, ptl);
70980 +#endif
70981 +
70982 retval = 0;
70983 pte_unmap_unlock(pte, ptl);
70984 return retval;
70985 @@ -2041,10 +2041,22 @@ out:
70986 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
70987 struct page *page)
70988 {
70989 +
70990 +#ifdef CONFIG_PAX_SEGMEXEC
70991 + struct vm_area_struct *vma_m;
70992 +#endif
70993 +
70994 if (addr < vma->vm_start || addr >= vma->vm_end)
70995 return -EFAULT;
70996 if (!page_count(page))
70997 return -EINVAL;
70998 +
70999 +#ifdef CONFIG_PAX_SEGMEXEC
71000 + vma_m = pax_find_mirror_vma(vma);
71001 + if (vma_m)
71002 + vma_m->vm_flags |= VM_INSERTPAGE;
71003 +#endif
71004 +
71005 vma->vm_flags |= VM_INSERTPAGE;
71006 return insert_page(vma, addr, page, vma->vm_page_prot);
71007 }
71008 @@ -2130,6 +2142,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71009 unsigned long pfn)
71010 {
71011 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71012 + BUG_ON(vma->vm_mirror);
71013
71014 if (addr < vma->vm_start || addr >= vma->vm_end)
71015 return -EFAULT;
71016 @@ -2445,6 +2458,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71017 copy_user_highpage(dst, src, va, vma);
71018 }
71019
71020 +#ifdef CONFIG_PAX_SEGMEXEC
71021 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71022 +{
71023 + struct mm_struct *mm = vma->vm_mm;
71024 + spinlock_t *ptl;
71025 + pte_t *pte, entry;
71026 +
71027 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71028 + entry = *pte;
71029 + if (!pte_present(entry)) {
71030 + if (!pte_none(entry)) {
71031 + BUG_ON(pte_file(entry));
71032 + free_swap_and_cache(pte_to_swp_entry(entry));
71033 + pte_clear_not_present_full(mm, address, pte, 0);
71034 + }
71035 + } else {
71036 + struct page *page;
71037 +
71038 + flush_cache_page(vma, address, pte_pfn(entry));
71039 + entry = ptep_clear_flush(vma, address, pte);
71040 + BUG_ON(pte_dirty(entry));
71041 + page = vm_normal_page(vma, address, entry);
71042 + if (page) {
71043 + update_hiwater_rss(mm);
71044 + if (PageAnon(page))
71045 + dec_mm_counter_fast(mm, MM_ANONPAGES);
71046 + else
71047 + dec_mm_counter_fast(mm, MM_FILEPAGES);
71048 + page_remove_rmap(page);
71049 + page_cache_release(page);
71050 + }
71051 + }
71052 + pte_unmap_unlock(pte, ptl);
71053 +}
71054 +
71055 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
71056 + *
71057 + * the ptl of the lower mapped page is held on entry and is not released on exit
71058 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71059 + */
71060 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71061 +{
71062 + struct mm_struct *mm = vma->vm_mm;
71063 + unsigned long address_m;
71064 + spinlock_t *ptl_m;
71065 + struct vm_area_struct *vma_m;
71066 + pmd_t *pmd_m;
71067 + pte_t *pte_m, entry_m;
71068 +
71069 + BUG_ON(!page_m || !PageAnon(page_m));
71070 +
71071 + vma_m = pax_find_mirror_vma(vma);
71072 + if (!vma_m)
71073 + return;
71074 +
71075 + BUG_ON(!PageLocked(page_m));
71076 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71077 + address_m = address + SEGMEXEC_TASK_SIZE;
71078 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71079 + pte_m = pte_offset_map(pmd_m, address_m);
71080 + ptl_m = pte_lockptr(mm, pmd_m);
71081 + if (ptl != ptl_m) {
71082 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71083 + if (!pte_none(*pte_m))
71084 + goto out;
71085 + }
71086 +
71087 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71088 + page_cache_get(page_m);
71089 + page_add_anon_rmap(page_m, vma_m, address_m);
71090 + inc_mm_counter_fast(mm, MM_ANONPAGES);
71091 + set_pte_at(mm, address_m, pte_m, entry_m);
71092 + update_mmu_cache(vma_m, address_m, entry_m);
71093 +out:
71094 + if (ptl != ptl_m)
71095 + spin_unlock(ptl_m);
71096 + pte_unmap(pte_m);
71097 + unlock_page(page_m);
71098 +}
71099 +
71100 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71101 +{
71102 + struct mm_struct *mm = vma->vm_mm;
71103 + unsigned long address_m;
71104 + spinlock_t *ptl_m;
71105 + struct vm_area_struct *vma_m;
71106 + pmd_t *pmd_m;
71107 + pte_t *pte_m, entry_m;
71108 +
71109 + BUG_ON(!page_m || PageAnon(page_m));
71110 +
71111 + vma_m = pax_find_mirror_vma(vma);
71112 + if (!vma_m)
71113 + return;
71114 +
71115 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71116 + address_m = address + SEGMEXEC_TASK_SIZE;
71117 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71118 + pte_m = pte_offset_map(pmd_m, address_m);
71119 + ptl_m = pte_lockptr(mm, pmd_m);
71120 + if (ptl != ptl_m) {
71121 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71122 + if (!pte_none(*pte_m))
71123 + goto out;
71124 + }
71125 +
71126 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71127 + page_cache_get(page_m);
71128 + page_add_file_rmap(page_m);
71129 + inc_mm_counter_fast(mm, MM_FILEPAGES);
71130 + set_pte_at(mm, address_m, pte_m, entry_m);
71131 + update_mmu_cache(vma_m, address_m, entry_m);
71132 +out:
71133 + if (ptl != ptl_m)
71134 + spin_unlock(ptl_m);
71135 + pte_unmap(pte_m);
71136 +}
71137 +
71138 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
71139 +{
71140 + struct mm_struct *mm = vma->vm_mm;
71141 + unsigned long address_m;
71142 + spinlock_t *ptl_m;
71143 + struct vm_area_struct *vma_m;
71144 + pmd_t *pmd_m;
71145 + pte_t *pte_m, entry_m;
71146 +
71147 + vma_m = pax_find_mirror_vma(vma);
71148 + if (!vma_m)
71149 + return;
71150 +
71151 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71152 + address_m = address + SEGMEXEC_TASK_SIZE;
71153 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71154 + pte_m = pte_offset_map(pmd_m, address_m);
71155 + ptl_m = pte_lockptr(mm, pmd_m);
71156 + if (ptl != ptl_m) {
71157 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71158 + if (!pte_none(*pte_m))
71159 + goto out;
71160 + }
71161 +
71162 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
71163 + set_pte_at(mm, address_m, pte_m, entry_m);
71164 +out:
71165 + if (ptl != ptl_m)
71166 + spin_unlock(ptl_m);
71167 + pte_unmap(pte_m);
71168 +}
71169 +
71170 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
71171 +{
71172 + struct page *page_m;
71173 + pte_t entry;
71174 +
71175 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
71176 + goto out;
71177 +
71178 + entry = *pte;
71179 + page_m = vm_normal_page(vma, address, entry);
71180 + if (!page_m)
71181 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
71182 + else if (PageAnon(page_m)) {
71183 + if (pax_find_mirror_vma(vma)) {
71184 + pte_unmap_unlock(pte, ptl);
71185 + lock_page(page_m);
71186 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
71187 + if (pte_same(entry, *pte))
71188 + pax_mirror_anon_pte(vma, address, page_m, ptl);
71189 + else
71190 + unlock_page(page_m);
71191 + }
71192 + } else
71193 + pax_mirror_file_pte(vma, address, page_m, ptl);
71194 +
71195 +out:
71196 + pte_unmap_unlock(pte, ptl);
71197 +}
71198 +#endif
71199 +
71200 /*
71201 * This routine handles present pages, when users try to write
71202 * to a shared page. It is done by copying the page to a new address
71203 @@ -2656,6 +2849,12 @@ gotten:
71204 */
71205 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71206 if (likely(pte_same(*page_table, orig_pte))) {
71207 +
71208 +#ifdef CONFIG_PAX_SEGMEXEC
71209 + if (pax_find_mirror_vma(vma))
71210 + BUG_ON(!trylock_page(new_page));
71211 +#endif
71212 +
71213 if (old_page) {
71214 if (!PageAnon(old_page)) {
71215 dec_mm_counter_fast(mm, MM_FILEPAGES);
71216 @@ -2707,6 +2906,10 @@ gotten:
71217 page_remove_rmap(old_page);
71218 }
71219
71220 +#ifdef CONFIG_PAX_SEGMEXEC
71221 + pax_mirror_anon_pte(vma, address, new_page, ptl);
71222 +#endif
71223 +
71224 /* Free the old page.. */
71225 new_page = old_page;
71226 ret |= VM_FAULT_WRITE;
71227 @@ -2986,6 +3189,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71228 swap_free(entry);
71229 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
71230 try_to_free_swap(page);
71231 +
71232 +#ifdef CONFIG_PAX_SEGMEXEC
71233 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
71234 +#endif
71235 +
71236 unlock_page(page);
71237 if (swapcache) {
71238 /*
71239 @@ -3009,6 +3217,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71240
71241 /* No need to invalidate - it was non-present before */
71242 update_mmu_cache(vma, address, page_table);
71243 +
71244 +#ifdef CONFIG_PAX_SEGMEXEC
71245 + pax_mirror_anon_pte(vma, address, page, ptl);
71246 +#endif
71247 +
71248 unlock:
71249 pte_unmap_unlock(page_table, ptl);
71250 out:
71251 @@ -3028,40 +3241,6 @@ out_release:
71252 }
71253
71254 /*
71255 - * This is like a special single-page "expand_{down|up}wards()",
71256 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
71257 - * doesn't hit another vma.
71258 - */
71259 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
71260 -{
71261 - address &= PAGE_MASK;
71262 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
71263 - struct vm_area_struct *prev = vma->vm_prev;
71264 -
71265 - /*
71266 - * Is there a mapping abutting this one below?
71267 - *
71268 - * That's only ok if it's the same stack mapping
71269 - * that has gotten split..
71270 - */
71271 - if (prev && prev->vm_end == address)
71272 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
71273 -
71274 - expand_downwards(vma, address - PAGE_SIZE);
71275 - }
71276 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
71277 - struct vm_area_struct *next = vma->vm_next;
71278 -
71279 - /* As VM_GROWSDOWN but s/below/above/ */
71280 - if (next && next->vm_start == address + PAGE_SIZE)
71281 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
71282 -
71283 - expand_upwards(vma, address + PAGE_SIZE);
71284 - }
71285 - return 0;
71286 -}
71287 -
71288 -/*
71289 * We enter with non-exclusive mmap_sem (to exclude vma changes,
71290 * but allow concurrent faults), and pte mapped but not yet locked.
71291 * We return with mmap_sem still held, but pte unmapped and unlocked.
71292 @@ -3070,27 +3249,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71293 unsigned long address, pte_t *page_table, pmd_t *pmd,
71294 unsigned int flags)
71295 {
71296 - struct page *page;
71297 + struct page *page = NULL;
71298 spinlock_t *ptl;
71299 pte_t entry;
71300
71301 - pte_unmap(page_table);
71302 -
71303 - /* Check if we need to add a guard page to the stack */
71304 - if (check_stack_guard_page(vma, address) < 0)
71305 - return VM_FAULT_SIGBUS;
71306 -
71307 - /* Use the zero-page for reads */
71308 if (!(flags & FAULT_FLAG_WRITE)) {
71309 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71310 vma->vm_page_prot));
71311 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71312 + ptl = pte_lockptr(mm, pmd);
71313 + spin_lock(ptl);
71314 if (!pte_none(*page_table))
71315 goto unlock;
71316 goto setpte;
71317 }
71318
71319 /* Allocate our own private page. */
71320 + pte_unmap(page_table);
71321 +
71322 if (unlikely(anon_vma_prepare(vma)))
71323 goto oom;
71324 page = alloc_zeroed_user_highpage_movable(vma, address);
71325 @@ -3109,6 +3284,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71326 if (!pte_none(*page_table))
71327 goto release;
71328
71329 +#ifdef CONFIG_PAX_SEGMEXEC
71330 + if (pax_find_mirror_vma(vma))
71331 + BUG_ON(!trylock_page(page));
71332 +#endif
71333 +
71334 inc_mm_counter_fast(mm, MM_ANONPAGES);
71335 page_add_new_anon_rmap(page, vma, address);
71336 setpte:
71337 @@ -3116,6 +3296,12 @@ setpte:
71338
71339 /* No need to invalidate - it was non-present before */
71340 update_mmu_cache(vma, address, page_table);
71341 +
71342 +#ifdef CONFIG_PAX_SEGMEXEC
71343 + if (page)
71344 + pax_mirror_anon_pte(vma, address, page, ptl);
71345 +#endif
71346 +
71347 unlock:
71348 pte_unmap_unlock(page_table, ptl);
71349 return 0;
71350 @@ -3259,6 +3445,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71351 */
71352 /* Only go through if we didn't race with anybody else... */
71353 if (likely(pte_same(*page_table, orig_pte))) {
71354 +
71355 +#ifdef CONFIG_PAX_SEGMEXEC
71356 + if (anon && pax_find_mirror_vma(vma))
71357 + BUG_ON(!trylock_page(page));
71358 +#endif
71359 +
71360 flush_icache_page(vma, page);
71361 entry = mk_pte(page, vma->vm_page_prot);
71362 if (flags & FAULT_FLAG_WRITE)
71363 @@ -3278,6 +3470,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71364
71365 /* no need to invalidate: a not-present page won't be cached */
71366 update_mmu_cache(vma, address, page_table);
71367 +
71368 +#ifdef CONFIG_PAX_SEGMEXEC
71369 + if (anon)
71370 + pax_mirror_anon_pte(vma, address, page, ptl);
71371 + else
71372 + pax_mirror_file_pte(vma, address, page, ptl);
71373 +#endif
71374 +
71375 } else {
71376 if (cow_page)
71377 mem_cgroup_uncharge_page(cow_page);
71378 @@ -3431,6 +3631,12 @@ int handle_pte_fault(struct mm_struct *mm,
71379 if (flags & FAULT_FLAG_WRITE)
71380 flush_tlb_fix_spurious_fault(vma, address);
71381 }
71382 +
71383 +#ifdef CONFIG_PAX_SEGMEXEC
71384 + pax_mirror_pte(vma, address, pte, pmd, ptl);
71385 + return 0;
71386 +#endif
71387 +
71388 unlock:
71389 pte_unmap_unlock(pte, ptl);
71390 return 0;
71391 @@ -3447,6 +3653,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71392 pmd_t *pmd;
71393 pte_t *pte;
71394
71395 +#ifdef CONFIG_PAX_SEGMEXEC
71396 + struct vm_area_struct *vma_m;
71397 +#endif
71398 +
71399 __set_current_state(TASK_RUNNING);
71400
71401 count_vm_event(PGFAULT);
71402 @@ -3458,6 +3668,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71403 if (unlikely(is_vm_hugetlb_page(vma)))
71404 return hugetlb_fault(mm, vma, address, flags);
71405
71406 +#ifdef CONFIG_PAX_SEGMEXEC
71407 + vma_m = pax_find_mirror_vma(vma);
71408 + if (vma_m) {
71409 + unsigned long address_m;
71410 + pgd_t *pgd_m;
71411 + pud_t *pud_m;
71412 + pmd_t *pmd_m;
71413 +
71414 + if (vma->vm_start > vma_m->vm_start) {
71415 + address_m = address;
71416 + address -= SEGMEXEC_TASK_SIZE;
71417 + vma = vma_m;
71418 + } else
71419 + address_m = address + SEGMEXEC_TASK_SIZE;
71420 +
71421 + pgd_m = pgd_offset(mm, address_m);
71422 + pud_m = pud_alloc(mm, pgd_m, address_m);
71423 + if (!pud_m)
71424 + return VM_FAULT_OOM;
71425 + pmd_m = pmd_alloc(mm, pud_m, address_m);
71426 + if (!pmd_m)
71427 + return VM_FAULT_OOM;
71428 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71429 + return VM_FAULT_OOM;
71430 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71431 + }
71432 +#endif
71433 +
71434 pgd = pgd_offset(mm, address);
71435 pud = pud_alloc(mm, pgd, address);
71436 if (!pud)
71437 @@ -3487,7 +3725,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71438 * run pte_offset_map on the pmd, if an huge pmd could
71439 * materialize from under us from a different thread.
71440 */
71441 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71442 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71443 return VM_FAULT_OOM;
71444 /* if an huge pmd materialized from under us just retry later */
71445 if (unlikely(pmd_trans_huge(*pmd)))
71446 @@ -3591,7 +3829,7 @@ static int __init gate_vma_init(void)
71447 gate_vma.vm_start = FIXADDR_USER_START;
71448 gate_vma.vm_end = FIXADDR_USER_END;
71449 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71450 - gate_vma.vm_page_prot = __P101;
71451 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71452 /*
71453 * Make sure the vDSO gets into every core dump.
71454 * Dumping its contents makes post-mortem fully interpretable later
71455 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71456 index c3fdbcb..2e8ef90 100644
71457 --- a/mm/mempolicy.c
71458 +++ b/mm/mempolicy.c
71459 @@ -640,6 +640,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71460 unsigned long vmstart;
71461 unsigned long vmend;
71462
71463 +#ifdef CONFIG_PAX_SEGMEXEC
71464 + struct vm_area_struct *vma_m;
71465 +#endif
71466 +
71467 vma = find_vma_prev(mm, start, &prev);
71468 if (!vma || vma->vm_start > start)
71469 return -EFAULT;
71470 @@ -678,6 +682,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71471 err = policy_vma(vma, new_pol);
71472 if (err)
71473 goto out;
71474 +
71475 +#ifdef CONFIG_PAX_SEGMEXEC
71476 + vma_m = pax_find_mirror_vma(vma);
71477 + if (vma_m) {
71478 + err = policy_vma(vma_m, new_pol);
71479 + if (err)
71480 + goto out;
71481 + }
71482 +#endif
71483 +
71484 }
71485
71486 out:
71487 @@ -1111,6 +1125,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71488
71489 if (end < start)
71490 return -EINVAL;
71491 +
71492 +#ifdef CONFIG_PAX_SEGMEXEC
71493 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71494 + if (end > SEGMEXEC_TASK_SIZE)
71495 + return -EINVAL;
71496 + } else
71497 +#endif
71498 +
71499 + if (end > TASK_SIZE)
71500 + return -EINVAL;
71501 +
71502 if (end == start)
71503 return 0;
71504
71505 @@ -1329,6 +1354,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71506 if (!mm)
71507 goto out;
71508
71509 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71510 + if (mm != current->mm &&
71511 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71512 + err = -EPERM;
71513 + goto out;
71514 + }
71515 +#endif
71516 +
71517 /*
71518 * Check if this process has the right to modify the specified
71519 * process. The right exists if the process has administrative
71520 @@ -1338,8 +1371,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71521 rcu_read_lock();
71522 tcred = __task_cred(task);
71523 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71524 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
71525 - !capable(CAP_SYS_NICE)) {
71526 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71527 rcu_read_unlock();
71528 err = -EPERM;
71529 goto out;
71530 diff --git a/mm/migrate.c b/mm/migrate.c
71531 index 177aca4..ab3a744 100644
71532 --- a/mm/migrate.c
71533 +++ b/mm/migrate.c
71534 @@ -1313,6 +1313,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71535 if (!mm)
71536 return -EINVAL;
71537
71538 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71539 + if (mm != current->mm &&
71540 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71541 + err = -EPERM;
71542 + goto out;
71543 + }
71544 +#endif
71545 +
71546 /*
71547 * Check if this process has the right to modify the specified
71548 * process. The right exists if the process has administrative
71549 @@ -1322,8 +1330,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71550 rcu_read_lock();
71551 tcred = __task_cred(task);
71552 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71553 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
71554 - !capable(CAP_SYS_NICE)) {
71555 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71556 rcu_read_unlock();
71557 err = -EPERM;
71558 goto out;
71559 diff --git a/mm/mlock.c b/mm/mlock.c
71560 index 4f4f53b..9511904 100644
71561 --- a/mm/mlock.c
71562 +++ b/mm/mlock.c
71563 @@ -13,6 +13,7 @@
71564 #include <linux/pagemap.h>
71565 #include <linux/mempolicy.h>
71566 #include <linux/syscalls.h>
71567 +#include <linux/security.h>
71568 #include <linux/sched.h>
71569 #include <linux/export.h>
71570 #include <linux/rmap.h>
71571 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
71572 return -EINVAL;
71573 if (end == start)
71574 return 0;
71575 + if (end > TASK_SIZE)
71576 + return -EINVAL;
71577 +
71578 vma = find_vma_prev(current->mm, start, &prev);
71579 if (!vma || vma->vm_start > start)
71580 return -ENOMEM;
71581 @@ -395,6 +399,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
71582 for (nstart = start ; ; ) {
71583 vm_flags_t newflags;
71584
71585 +#ifdef CONFIG_PAX_SEGMEXEC
71586 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71587 + break;
71588 +#endif
71589 +
71590 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
71591
71592 newflags = vma->vm_flags | VM_LOCKED;
71593 @@ -500,6 +509,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
71594 lock_limit >>= PAGE_SHIFT;
71595
71596 /* check against resource limits */
71597 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
71598 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
71599 error = do_mlock(start, len, 1);
71600 up_write(&current->mm->mmap_sem);
71601 @@ -523,17 +533,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
71602 static int do_mlockall(int flags)
71603 {
71604 struct vm_area_struct * vma, * prev = NULL;
71605 - unsigned int def_flags = 0;
71606
71607 if (flags & MCL_FUTURE)
71608 - def_flags = VM_LOCKED;
71609 - current->mm->def_flags = def_flags;
71610 + current->mm->def_flags |= VM_LOCKED;
71611 + else
71612 + current->mm->def_flags &= ~VM_LOCKED;
71613 if (flags == MCL_FUTURE)
71614 goto out;
71615
71616 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
71617 vm_flags_t newflags;
71618
71619 +#ifdef CONFIG_PAX_SEGMEXEC
71620 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71621 + break;
71622 +#endif
71623 +
71624 + BUG_ON(vma->vm_end > TASK_SIZE);
71625 newflags = vma->vm_flags | VM_LOCKED;
71626 if (!(flags & MCL_CURRENT))
71627 newflags &= ~VM_LOCKED;
71628 @@ -566,6 +582,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
71629 lock_limit >>= PAGE_SHIFT;
71630
71631 ret = -ENOMEM;
71632 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
71633 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
71634 capable(CAP_IPC_LOCK))
71635 ret = do_mlockall(flags);
71636 diff --git a/mm/mmap.c b/mm/mmap.c
71637 index eae90af..c930262 100644
71638 --- a/mm/mmap.c
71639 +++ b/mm/mmap.c
71640 @@ -46,6 +46,16 @@
71641 #define arch_rebalance_pgtables(addr, len) (addr)
71642 #endif
71643
71644 +static inline void verify_mm_writelocked(struct mm_struct *mm)
71645 +{
71646 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
71647 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71648 + up_read(&mm->mmap_sem);
71649 + BUG();
71650 + }
71651 +#endif
71652 +}
71653 +
71654 static void unmap_region(struct mm_struct *mm,
71655 struct vm_area_struct *vma, struct vm_area_struct *prev,
71656 unsigned long start, unsigned long end);
71657 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
71658 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
71659 *
71660 */
71661 -pgprot_t protection_map[16] = {
71662 +pgprot_t protection_map[16] __read_only = {
71663 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
71664 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
71665 };
71666
71667 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
71668 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
71669 {
71670 - return __pgprot(pgprot_val(protection_map[vm_flags &
71671 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
71672 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
71673 pgprot_val(arch_vm_get_page_prot(vm_flags)));
71674 +
71675 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71676 + if (!(__supported_pte_mask & _PAGE_NX) &&
71677 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
71678 + (vm_flags & (VM_READ | VM_WRITE)))
71679 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
71680 +#endif
71681 +
71682 + return prot;
71683 }
71684 EXPORT_SYMBOL(vm_get_page_prot);
71685
71686 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
71687 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
71688 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
71689 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
71690 /*
71691 * Make sure vm_committed_as in one cacheline and not cacheline shared with
71692 * other variables. It can be updated by several CPUs frequently.
71693 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
71694 struct vm_area_struct *next = vma->vm_next;
71695
71696 might_sleep();
71697 + BUG_ON(vma->vm_mirror);
71698 if (vma->vm_ops && vma->vm_ops->close)
71699 vma->vm_ops->close(vma);
71700 if (vma->vm_file) {
71701 @@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
71702 * not page aligned -Ram Gupta
71703 */
71704 rlim = rlimit(RLIMIT_DATA);
71705 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
71706 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
71707 (mm->end_data - mm->start_data) > rlim)
71708 goto out;
71709 @@ -689,6 +711,12 @@ static int
71710 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
71711 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71712 {
71713 +
71714 +#ifdef CONFIG_PAX_SEGMEXEC
71715 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
71716 + return 0;
71717 +#endif
71718 +
71719 if (is_mergeable_vma(vma, file, vm_flags) &&
71720 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71721 if (vma->vm_pgoff == vm_pgoff)
71722 @@ -708,6 +736,12 @@ static int
71723 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71724 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71725 {
71726 +
71727 +#ifdef CONFIG_PAX_SEGMEXEC
71728 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
71729 + return 0;
71730 +#endif
71731 +
71732 if (is_mergeable_vma(vma, file, vm_flags) &&
71733 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71734 pgoff_t vm_pglen;
71735 @@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71736 struct vm_area_struct *vma_merge(struct mm_struct *mm,
71737 struct vm_area_struct *prev, unsigned long addr,
71738 unsigned long end, unsigned long vm_flags,
71739 - struct anon_vma *anon_vma, struct file *file,
71740 + struct anon_vma *anon_vma, struct file *file,
71741 pgoff_t pgoff, struct mempolicy *policy)
71742 {
71743 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
71744 struct vm_area_struct *area, *next;
71745 int err;
71746
71747 +#ifdef CONFIG_PAX_SEGMEXEC
71748 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
71749 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
71750 +
71751 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
71752 +#endif
71753 +
71754 /*
71755 * We later require that vma->vm_flags == vm_flags,
71756 * so this tests vma->vm_flags & VM_SPECIAL, too.
71757 @@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71758 if (next && next->vm_end == end) /* cases 6, 7, 8 */
71759 next = next->vm_next;
71760
71761 +#ifdef CONFIG_PAX_SEGMEXEC
71762 + if (prev)
71763 + prev_m = pax_find_mirror_vma(prev);
71764 + if (area)
71765 + area_m = pax_find_mirror_vma(area);
71766 + if (next)
71767 + next_m = pax_find_mirror_vma(next);
71768 +#endif
71769 +
71770 /*
71771 * Can it merge with the predecessor?
71772 */
71773 @@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71774 /* cases 1, 6 */
71775 err = vma_adjust(prev, prev->vm_start,
71776 next->vm_end, prev->vm_pgoff, NULL);
71777 - } else /* cases 2, 5, 7 */
71778 +
71779 +#ifdef CONFIG_PAX_SEGMEXEC
71780 + if (!err && prev_m)
71781 + err = vma_adjust(prev_m, prev_m->vm_start,
71782 + next_m->vm_end, prev_m->vm_pgoff, NULL);
71783 +#endif
71784 +
71785 + } else { /* cases 2, 5, 7 */
71786 err = vma_adjust(prev, prev->vm_start,
71787 end, prev->vm_pgoff, NULL);
71788 +
71789 +#ifdef CONFIG_PAX_SEGMEXEC
71790 + if (!err && prev_m)
71791 + err = vma_adjust(prev_m, prev_m->vm_start,
71792 + end_m, prev_m->vm_pgoff, NULL);
71793 +#endif
71794 +
71795 + }
71796 if (err)
71797 return NULL;
71798 khugepaged_enter_vma_merge(prev);
71799 @@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71800 mpol_equal(policy, vma_policy(next)) &&
71801 can_vma_merge_before(next, vm_flags,
71802 anon_vma, file, pgoff+pglen)) {
71803 - if (prev && addr < prev->vm_end) /* case 4 */
71804 + if (prev && addr < prev->vm_end) { /* case 4 */
71805 err = vma_adjust(prev, prev->vm_start,
71806 addr, prev->vm_pgoff, NULL);
71807 - else /* cases 3, 8 */
71808 +
71809 +#ifdef CONFIG_PAX_SEGMEXEC
71810 + if (!err && prev_m)
71811 + err = vma_adjust(prev_m, prev_m->vm_start,
71812 + addr_m, prev_m->vm_pgoff, NULL);
71813 +#endif
71814 +
71815 + } else { /* cases 3, 8 */
71816 err = vma_adjust(area, addr, next->vm_end,
71817 next->vm_pgoff - pglen, NULL);
71818 +
71819 +#ifdef CONFIG_PAX_SEGMEXEC
71820 + if (!err && area_m)
71821 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
71822 + next_m->vm_pgoff - pglen, NULL);
71823 +#endif
71824 +
71825 + }
71826 if (err)
71827 return NULL;
71828 khugepaged_enter_vma_merge(area);
71829 @@ -921,14 +1001,11 @@ none:
71830 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
71831 struct file *file, long pages)
71832 {
71833 - const unsigned long stack_flags
71834 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
71835 -
71836 if (file) {
71837 mm->shared_vm += pages;
71838 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
71839 mm->exec_vm += pages;
71840 - } else if (flags & stack_flags)
71841 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
71842 mm->stack_vm += pages;
71843 if (flags & (VM_RESERVED|VM_IO))
71844 mm->reserved_vm += pages;
71845 @@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71846 * (the exception is when the underlying filesystem is noexec
71847 * mounted, in which case we dont add PROT_EXEC.)
71848 */
71849 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
71850 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
71851 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
71852 prot |= PROT_EXEC;
71853
71854 @@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71855 /* Obtain the address to map to. we verify (or select) it and ensure
71856 * that it represents a valid section of the address space.
71857 */
71858 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
71859 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
71860 if (addr & ~PAGE_MASK)
71861 return addr;
71862
71863 @@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71864 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
71865 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
71866
71867 +#ifdef CONFIG_PAX_MPROTECT
71868 + if (mm->pax_flags & MF_PAX_MPROTECT) {
71869 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
71870 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
71871 + gr_log_rwxmmap(file);
71872 +
71873 +#ifdef CONFIG_PAX_EMUPLT
71874 + vm_flags &= ~VM_EXEC;
71875 +#else
71876 + return -EPERM;
71877 +#endif
71878 +
71879 + }
71880 +
71881 + if (!(vm_flags & VM_EXEC))
71882 + vm_flags &= ~VM_MAYEXEC;
71883 +#else
71884 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71885 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71886 +#endif
71887 + else
71888 + vm_flags &= ~VM_MAYWRITE;
71889 + }
71890 +#endif
71891 +
71892 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71893 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
71894 + vm_flags &= ~VM_PAGEEXEC;
71895 +#endif
71896 +
71897 if (flags & MAP_LOCKED)
71898 if (!can_do_mlock())
71899 return -EPERM;
71900 @@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71901 locked += mm->locked_vm;
71902 lock_limit = rlimit(RLIMIT_MEMLOCK);
71903 lock_limit >>= PAGE_SHIFT;
71904 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71905 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
71906 return -EAGAIN;
71907 }
71908 @@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71909 if (error)
71910 return error;
71911
71912 + if (!gr_acl_handle_mmap(file, prot))
71913 + return -EACCES;
71914 +
71915 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
71916 }
71917 EXPORT_SYMBOL(do_mmap_pgoff);
71918 @@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
71919 vm_flags_t vm_flags = vma->vm_flags;
71920
71921 /* If it was private or non-writable, the write bit is already clear */
71922 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
71923 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
71924 return 0;
71925
71926 /* The backer wishes to know when pages are first written to? */
71927 @@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
71928 unsigned long charged = 0;
71929 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
71930
71931 +#ifdef CONFIG_PAX_SEGMEXEC
71932 + struct vm_area_struct *vma_m = NULL;
71933 +#endif
71934 +
71935 + /*
71936 + * mm->mmap_sem is required to protect against another thread
71937 + * changing the mappings in case we sleep.
71938 + */
71939 + verify_mm_writelocked(mm);
71940 +
71941 /* Clear old maps */
71942 error = -ENOMEM;
71943 -munmap_back:
71944 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71945 if (vma && vma->vm_start < addr + len) {
71946 if (do_munmap(mm, addr, len))
71947 return -ENOMEM;
71948 - goto munmap_back;
71949 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71950 + BUG_ON(vma && vma->vm_start < addr + len);
71951 }
71952
71953 /* Check against address space limit. */
71954 @@ -1258,6 +1379,16 @@ munmap_back:
71955 goto unacct_error;
71956 }
71957
71958 +#ifdef CONFIG_PAX_SEGMEXEC
71959 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
71960 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71961 + if (!vma_m) {
71962 + error = -ENOMEM;
71963 + goto free_vma;
71964 + }
71965 + }
71966 +#endif
71967 +
71968 vma->vm_mm = mm;
71969 vma->vm_start = addr;
71970 vma->vm_end = addr + len;
71971 @@ -1266,8 +1397,9 @@ munmap_back:
71972 vma->vm_pgoff = pgoff;
71973 INIT_LIST_HEAD(&vma->anon_vma_chain);
71974
71975 + error = -EINVAL; /* when rejecting VM_GROWSDOWN|VM_GROWSUP */
71976 +
71977 if (file) {
71978 - error = -EINVAL;
71979 if (vm_flags & (VM_GROWSDOWN|VM_GROWSUP))
71980 goto free_vma;
71981 if (vm_flags & VM_DENYWRITE) {
71982 @@ -1281,6 +1413,19 @@ munmap_back:
71983 error = file->f_op->mmap(file, vma);
71984 if (error)
71985 goto unmap_and_free_vma;
71986 +
71987 +#ifdef CONFIG_PAX_SEGMEXEC
71988 + if (vma_m && (vm_flags & VM_EXECUTABLE))
71989 + added_exe_file_vma(mm);
71990 +#endif
71991 +
71992 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71993 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
71994 + vma->vm_flags |= VM_PAGEEXEC;
71995 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71996 + }
71997 +#endif
71998 +
71999 if (vm_flags & VM_EXECUTABLE)
72000 added_exe_file_vma(mm);
72001
72002 @@ -1293,6 +1438,8 @@ munmap_back:
72003 pgoff = vma->vm_pgoff;
72004 vm_flags = vma->vm_flags;
72005 } else if (vm_flags & VM_SHARED) {
72006 + if (unlikely(vm_flags & (VM_GROWSDOWN|VM_GROWSUP)))
72007 + goto free_vma;
72008 error = shmem_zero_setup(vma);
72009 if (error)
72010 goto free_vma;
72011 @@ -1316,6 +1463,11 @@ munmap_back:
72012 vma_link(mm, vma, prev, rb_link, rb_parent);
72013 file = vma->vm_file;
72014
72015 +#ifdef CONFIG_PAX_SEGMEXEC
72016 + if (vma_m)
72017 + BUG_ON(pax_mirror_vma(vma_m, vma));
72018 +#endif
72019 +
72020 /* Once vma denies write, undo our temporary denial count */
72021 if (correct_wcount)
72022 atomic_inc(&inode->i_writecount);
72023 @@ -1324,6 +1476,7 @@ out:
72024
72025 mm->total_vm += len >> PAGE_SHIFT;
72026 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72027 + track_exec_limit(mm, addr, addr + len, vm_flags);
72028 if (vm_flags & VM_LOCKED) {
72029 if (!mlock_vma_pages_range(vma, addr, addr + len))
72030 mm->locked_vm += (len >> PAGE_SHIFT);
72031 @@ -1341,6 +1494,12 @@ unmap_and_free_vma:
72032 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72033 charged = 0;
72034 free_vma:
72035 +
72036 +#ifdef CONFIG_PAX_SEGMEXEC
72037 + if (vma_m)
72038 + kmem_cache_free(vm_area_cachep, vma_m);
72039 +#endif
72040 +
72041 kmem_cache_free(vm_area_cachep, vma);
72042 unacct_error:
72043 if (charged)
72044 @@ -1348,6 +1507,44 @@ unacct_error:
72045 return error;
72046 }
72047
72048 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72049 +{
72050 + if (!vma) {
72051 +#ifdef CONFIG_STACK_GROWSUP
72052 + if (addr > sysctl_heap_stack_gap)
72053 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72054 + else
72055 + vma = find_vma(current->mm, 0);
72056 + if (vma && (vma->vm_flags & VM_GROWSUP))
72057 + return false;
72058 +#endif
72059 + return true;
72060 + }
72061 +
72062 + if (addr + len > vma->vm_start)
72063 + return false;
72064 +
72065 + if (vma->vm_flags & VM_GROWSDOWN)
72066 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72067 +#ifdef CONFIG_STACK_GROWSUP
72068 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
72069 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
72070 +#endif
72071 +
72072 + return true;
72073 +}
72074 +
72075 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
72076 +{
72077 + if (vma->vm_start < len)
72078 + return -ENOMEM;
72079 + if (!(vma->vm_flags & VM_GROWSDOWN))
72080 + return vma->vm_start - len;
72081 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
72082 + return vma->vm_start - len - sysctl_heap_stack_gap;
72083 + return -ENOMEM;
72084 +}
72085 +
72086 /* Get an address range which is currently unmapped.
72087 * For shmat() with addr=0.
72088 *
72089 @@ -1374,18 +1571,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
72090 if (flags & MAP_FIXED)
72091 return addr;
72092
72093 +#ifdef CONFIG_PAX_RANDMMAP
72094 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72095 +#endif
72096 +
72097 if (addr) {
72098 addr = PAGE_ALIGN(addr);
72099 - vma = find_vma(mm, addr);
72100 - if (TASK_SIZE - len >= addr &&
72101 - (!vma || addr + len <= vma->vm_start))
72102 - return addr;
72103 + if (TASK_SIZE - len >= addr) {
72104 + vma = find_vma(mm, addr);
72105 + if (check_heap_stack_gap(vma, addr, len))
72106 + return addr;
72107 + }
72108 }
72109 if (len > mm->cached_hole_size) {
72110 - start_addr = addr = mm->free_area_cache;
72111 + start_addr = addr = mm->free_area_cache;
72112 } else {
72113 - start_addr = addr = TASK_UNMAPPED_BASE;
72114 - mm->cached_hole_size = 0;
72115 + start_addr = addr = mm->mmap_base;
72116 + mm->cached_hole_size = 0;
72117 }
72118
72119 full_search:
72120 @@ -1396,34 +1598,40 @@ full_search:
72121 * Start a new search - just in case we missed
72122 * some holes.
72123 */
72124 - if (start_addr != TASK_UNMAPPED_BASE) {
72125 - addr = TASK_UNMAPPED_BASE;
72126 - start_addr = addr;
72127 + if (start_addr != mm->mmap_base) {
72128 + start_addr = addr = mm->mmap_base;
72129 mm->cached_hole_size = 0;
72130 goto full_search;
72131 }
72132 return -ENOMEM;
72133 }
72134 - if (!vma || addr + len <= vma->vm_start) {
72135 - /*
72136 - * Remember the place where we stopped the search:
72137 - */
72138 - mm->free_area_cache = addr + len;
72139 - return addr;
72140 - }
72141 + if (check_heap_stack_gap(vma, addr, len))
72142 + break;
72143 if (addr + mm->cached_hole_size < vma->vm_start)
72144 mm->cached_hole_size = vma->vm_start - addr;
72145 addr = vma->vm_end;
72146 }
72147 +
72148 + /*
72149 + * Remember the place where we stopped the search:
72150 + */
72151 + mm->free_area_cache = addr + len;
72152 + return addr;
72153 }
72154 #endif
72155
72156 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
72157 {
72158 +
72159 +#ifdef CONFIG_PAX_SEGMEXEC
72160 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72161 + return;
72162 +#endif
72163 +
72164 /*
72165 * Is this a new hole at the lowest possible address?
72166 */
72167 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
72168 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
72169 mm->free_area_cache = addr;
72170 mm->cached_hole_size = ~0UL;
72171 }
72172 @@ -1441,7 +1649,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72173 {
72174 struct vm_area_struct *vma;
72175 struct mm_struct *mm = current->mm;
72176 - unsigned long addr = addr0;
72177 + unsigned long base = mm->mmap_base, addr = addr0;
72178
72179 /* requested length too big for entire address space */
72180 if (len > TASK_SIZE)
72181 @@ -1450,13 +1658,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72182 if (flags & MAP_FIXED)
72183 return addr;
72184
72185 +#ifdef CONFIG_PAX_RANDMMAP
72186 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72187 +#endif
72188 +
72189 /* requesting a specific address */
72190 if (addr) {
72191 addr = PAGE_ALIGN(addr);
72192 - vma = find_vma(mm, addr);
72193 - if (TASK_SIZE - len >= addr &&
72194 - (!vma || addr + len <= vma->vm_start))
72195 - return addr;
72196 + if (TASK_SIZE - len >= addr) {
72197 + vma = find_vma(mm, addr);
72198 + if (check_heap_stack_gap(vma, addr, len))
72199 + return addr;
72200 + }
72201 }
72202
72203 /* check if free_area_cache is useful for us */
72204 @@ -1471,7 +1684,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72205 /* make sure it can fit in the remaining address space */
72206 if (addr > len) {
72207 vma = find_vma(mm, addr-len);
72208 - if (!vma || addr <= vma->vm_start)
72209 + if (check_heap_stack_gap(vma, addr - len, len))
72210 /* remember the address as a hint for next time */
72211 return (mm->free_area_cache = addr-len);
72212 }
72213 @@ -1488,7 +1701,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72214 * return with success:
72215 */
72216 vma = find_vma(mm, addr);
72217 - if (!vma || addr+len <= vma->vm_start)
72218 + if (check_heap_stack_gap(vma, addr, len))
72219 /* remember the address as a hint for next time */
72220 return (mm->free_area_cache = addr);
72221
72222 @@ -1497,8 +1710,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72223 mm->cached_hole_size = vma->vm_start - addr;
72224
72225 /* try just below the current vma->vm_start */
72226 - addr = vma->vm_start-len;
72227 - } while (len < vma->vm_start);
72228 + addr = skip_heap_stack_gap(vma, len);
72229 + } while (!IS_ERR_VALUE(addr));
72230
72231 bottomup:
72232 /*
72233 @@ -1507,13 +1720,21 @@ bottomup:
72234 * can happen with large stack limits and large mmap()
72235 * allocations.
72236 */
72237 + mm->mmap_base = TASK_UNMAPPED_BASE;
72238 +
72239 +#ifdef CONFIG_PAX_RANDMMAP
72240 + if (mm->pax_flags & MF_PAX_RANDMMAP)
72241 + mm->mmap_base += mm->delta_mmap;
72242 +#endif
72243 +
72244 + mm->free_area_cache = mm->mmap_base;
72245 mm->cached_hole_size = ~0UL;
72246 - mm->free_area_cache = TASK_UNMAPPED_BASE;
72247 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
72248 /*
72249 * Restore the topdown base:
72250 */
72251 - mm->free_area_cache = mm->mmap_base;
72252 + mm->mmap_base = base;
72253 + mm->free_area_cache = base;
72254 mm->cached_hole_size = ~0UL;
72255
72256 return addr;
72257 @@ -1522,6 +1743,12 @@ bottomup:
72258
72259 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72260 {
72261 +
72262 +#ifdef CONFIG_PAX_SEGMEXEC
72263 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72264 + return;
72265 +#endif
72266 +
72267 /*
72268 * Is this a new hole at the highest possible address?
72269 */
72270 @@ -1529,8 +1756,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72271 mm->free_area_cache = addr;
72272
72273 /* dont allow allocations above current base */
72274 - if (mm->free_area_cache > mm->mmap_base)
72275 + if (mm->free_area_cache > mm->mmap_base) {
72276 mm->free_area_cache = mm->mmap_base;
72277 + mm->cached_hole_size = ~0UL;
72278 + }
72279 }
72280
72281 unsigned long
72282 @@ -1603,40 +1832,50 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
72283
72284 EXPORT_SYMBOL(find_vma);
72285
72286 -/* Same as find_vma, but also return a pointer to the previous VMA in *pprev. */
72287 +/*
72288 + * Same as find_vma, but also return a pointer to the previous VMA in *pprev.
72289 + */
72290 struct vm_area_struct *
72291 find_vma_prev(struct mm_struct *mm, unsigned long addr,
72292 struct vm_area_struct **pprev)
72293 {
72294 - struct vm_area_struct *vma = NULL, *prev = NULL;
72295 - struct rb_node *rb_node;
72296 - if (!mm)
72297 - goto out;
72298 -
72299 - /* Guard against addr being lower than the first VMA */
72300 - vma = mm->mmap;
72301 -
72302 - /* Go through the RB tree quickly. */
72303 - rb_node = mm->mm_rb.rb_node;
72304 -
72305 - while (rb_node) {
72306 - struct vm_area_struct *vma_tmp;
72307 - vma_tmp = rb_entry(rb_node, struct vm_area_struct, vm_rb);
72308 -
72309 - if (addr < vma_tmp->vm_end) {
72310 - rb_node = rb_node->rb_left;
72311 - } else {
72312 - prev = vma_tmp;
72313 - if (!prev->vm_next || (addr < prev->vm_next->vm_end))
72314 - break;
72315 + struct vm_area_struct *vma;
72316 +
72317 + vma = find_vma(mm, addr);
72318 + if (vma) {
72319 + *pprev = vma->vm_prev;
72320 + } else {
72321 + struct rb_node *rb_node = mm->mm_rb.rb_node;
72322 + *pprev = NULL;
72323 + while (rb_node) {
72324 + *pprev = rb_entry(rb_node, struct vm_area_struct, vm_rb);
72325 rb_node = rb_node->rb_right;
72326 }
72327 }
72328 + return vma;
72329 +}
72330 +
72331 +#ifdef CONFIG_PAX_SEGMEXEC
72332 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
72333 +{
72334 + struct vm_area_struct *vma_m;
72335
72336 -out:
72337 - *pprev = prev;
72338 - return prev ? prev->vm_next : vma;
72339 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
72340 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
72341 + BUG_ON(vma->vm_mirror);
72342 + return NULL;
72343 + }
72344 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
72345 + vma_m = vma->vm_mirror;
72346 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
72347 + BUG_ON(vma->vm_file != vma_m->vm_file);
72348 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
72349 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
72350 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
72351 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
72352 + return vma_m;
72353 }
72354 +#endif
72355
72356 /*
72357 * Verify that the stack growth is acceptable and
72358 @@ -1654,6 +1893,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72359 return -ENOMEM;
72360
72361 /* Stack limit test */
72362 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
72363 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72364 return -ENOMEM;
72365
72366 @@ -1664,6 +1904,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72367 locked = mm->locked_vm + grow;
72368 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72369 limit >>= PAGE_SHIFT;
72370 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72371 if (locked > limit && !capable(CAP_IPC_LOCK))
72372 return -ENOMEM;
72373 }
72374 @@ -1694,37 +1935,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72375 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72376 * vma is the last one with address > vma->vm_end. Have to extend vma.
72377 */
72378 +#ifndef CONFIG_IA64
72379 +static
72380 +#endif
72381 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72382 {
72383 int error;
72384 + bool locknext;
72385
72386 if (!(vma->vm_flags & VM_GROWSUP))
72387 return -EFAULT;
72388
72389 + /* Also guard against wrapping around to address 0. */
72390 + if (address < PAGE_ALIGN(address+1))
72391 + address = PAGE_ALIGN(address+1);
72392 + else
72393 + return -ENOMEM;
72394 +
72395 /*
72396 * We must make sure the anon_vma is allocated
72397 * so that the anon_vma locking is not a noop.
72398 */
72399 if (unlikely(anon_vma_prepare(vma)))
72400 return -ENOMEM;
72401 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72402 + if (locknext && anon_vma_prepare(vma->vm_next))
72403 + return -ENOMEM;
72404 vma_lock_anon_vma(vma);
72405 + if (locknext)
72406 + vma_lock_anon_vma(vma->vm_next);
72407
72408 /*
72409 * vma->vm_start/vm_end cannot change under us because the caller
72410 * is required to hold the mmap_sem in read mode. We need the
72411 - * anon_vma lock to serialize against concurrent expand_stacks.
72412 - * Also guard against wrapping around to address 0.
72413 + * anon_vma locks to serialize against concurrent expand_stacks
72414 + * and expand_upwards.
72415 */
72416 - if (address < PAGE_ALIGN(address+4))
72417 - address = PAGE_ALIGN(address+4);
72418 - else {
72419 - vma_unlock_anon_vma(vma);
72420 - return -ENOMEM;
72421 - }
72422 error = 0;
72423
72424 /* Somebody else might have raced and expanded it already */
72425 - if (address > vma->vm_end) {
72426 + 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)
72427 + error = -ENOMEM;
72428 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72429 unsigned long size, grow;
72430
72431 size = address - vma->vm_start;
72432 @@ -1739,6 +1991,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72433 }
72434 }
72435 }
72436 + if (locknext)
72437 + vma_unlock_anon_vma(vma->vm_next);
72438 vma_unlock_anon_vma(vma);
72439 khugepaged_enter_vma_merge(vma);
72440 return error;
72441 @@ -1752,6 +2006,8 @@ int expand_downwards(struct vm_area_struct *vma,
72442 unsigned long address)
72443 {
72444 int error;
72445 + bool lockprev = false;
72446 + struct vm_area_struct *prev;
72447
72448 /*
72449 * We must make sure the anon_vma is allocated
72450 @@ -1765,6 +2021,15 @@ int expand_downwards(struct vm_area_struct *vma,
72451 if (error)
72452 return error;
72453
72454 + prev = vma->vm_prev;
72455 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72456 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72457 +#endif
72458 + if (lockprev && anon_vma_prepare(prev))
72459 + return -ENOMEM;
72460 + if (lockprev)
72461 + vma_lock_anon_vma(prev);
72462 +
72463 vma_lock_anon_vma(vma);
72464
72465 /*
72466 @@ -1774,9 +2039,17 @@ int expand_downwards(struct vm_area_struct *vma,
72467 */
72468
72469 /* Somebody else might have raced and expanded it already */
72470 - if (address < vma->vm_start) {
72471 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72472 + error = -ENOMEM;
72473 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72474 unsigned long size, grow;
72475
72476 +#ifdef CONFIG_PAX_SEGMEXEC
72477 + struct vm_area_struct *vma_m;
72478 +
72479 + vma_m = pax_find_mirror_vma(vma);
72480 +#endif
72481 +
72482 size = vma->vm_end - address;
72483 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72484
72485 @@ -1786,11 +2059,22 @@ int expand_downwards(struct vm_area_struct *vma,
72486 if (!error) {
72487 vma->vm_start = address;
72488 vma->vm_pgoff -= grow;
72489 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72490 +
72491 +#ifdef CONFIG_PAX_SEGMEXEC
72492 + if (vma_m) {
72493 + vma_m->vm_start -= grow << PAGE_SHIFT;
72494 + vma_m->vm_pgoff -= grow;
72495 + }
72496 +#endif
72497 +
72498 perf_event_mmap(vma);
72499 }
72500 }
72501 }
72502 vma_unlock_anon_vma(vma);
72503 + if (lockprev)
72504 + vma_unlock_anon_vma(prev);
72505 khugepaged_enter_vma_merge(vma);
72506 return error;
72507 }
72508 @@ -1860,6 +2144,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72509 do {
72510 long nrpages = vma_pages(vma);
72511
72512 +#ifdef CONFIG_PAX_SEGMEXEC
72513 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72514 + vma = remove_vma(vma);
72515 + continue;
72516 + }
72517 +#endif
72518 +
72519 mm->total_vm -= nrpages;
72520 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
72521 vma = remove_vma(vma);
72522 @@ -1905,6 +2196,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72523 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72524 vma->vm_prev = NULL;
72525 do {
72526 +
72527 +#ifdef CONFIG_PAX_SEGMEXEC
72528 + if (vma->vm_mirror) {
72529 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72530 + vma->vm_mirror->vm_mirror = NULL;
72531 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
72532 + vma->vm_mirror = NULL;
72533 + }
72534 +#endif
72535 +
72536 rb_erase(&vma->vm_rb, &mm->mm_rb);
72537 mm->map_count--;
72538 tail_vma = vma;
72539 @@ -1933,14 +2234,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72540 struct vm_area_struct *new;
72541 int err = -ENOMEM;
72542
72543 +#ifdef CONFIG_PAX_SEGMEXEC
72544 + struct vm_area_struct *vma_m, *new_m = NULL;
72545 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72546 +#endif
72547 +
72548 if (is_vm_hugetlb_page(vma) && (addr &
72549 ~(huge_page_mask(hstate_vma(vma)))))
72550 return -EINVAL;
72551
72552 +#ifdef CONFIG_PAX_SEGMEXEC
72553 + vma_m = pax_find_mirror_vma(vma);
72554 +#endif
72555 +
72556 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72557 if (!new)
72558 goto out_err;
72559
72560 +#ifdef CONFIG_PAX_SEGMEXEC
72561 + if (vma_m) {
72562 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72563 + if (!new_m) {
72564 + kmem_cache_free(vm_area_cachep, new);
72565 + goto out_err;
72566 + }
72567 + }
72568 +#endif
72569 +
72570 /* most fields are the same, copy all, and then fixup */
72571 *new = *vma;
72572
72573 @@ -1953,6 +2273,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72574 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72575 }
72576
72577 +#ifdef CONFIG_PAX_SEGMEXEC
72578 + if (vma_m) {
72579 + *new_m = *vma_m;
72580 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
72581 + new_m->vm_mirror = new;
72582 + new->vm_mirror = new_m;
72583 +
72584 + if (new_below)
72585 + new_m->vm_end = addr_m;
72586 + else {
72587 + new_m->vm_start = addr_m;
72588 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72589 + }
72590 + }
72591 +#endif
72592 +
72593 pol = mpol_dup(vma_policy(vma));
72594 if (IS_ERR(pol)) {
72595 err = PTR_ERR(pol);
72596 @@ -1978,6 +2314,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72597 else
72598 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72599
72600 +#ifdef CONFIG_PAX_SEGMEXEC
72601 + if (!err && vma_m) {
72602 + if (anon_vma_clone(new_m, vma_m))
72603 + goto out_free_mpol;
72604 +
72605 + mpol_get(pol);
72606 + vma_set_policy(new_m, pol);
72607 +
72608 + if (new_m->vm_file) {
72609 + get_file(new_m->vm_file);
72610 + if (vma_m->vm_flags & VM_EXECUTABLE)
72611 + added_exe_file_vma(mm);
72612 + }
72613 +
72614 + if (new_m->vm_ops && new_m->vm_ops->open)
72615 + new_m->vm_ops->open(new_m);
72616 +
72617 + if (new_below)
72618 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72619 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72620 + else
72621 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72622 +
72623 + if (err) {
72624 + if (new_m->vm_ops && new_m->vm_ops->close)
72625 + new_m->vm_ops->close(new_m);
72626 + if (new_m->vm_file) {
72627 + if (vma_m->vm_flags & VM_EXECUTABLE)
72628 + removed_exe_file_vma(mm);
72629 + fput(new_m->vm_file);
72630 + }
72631 + mpol_put(pol);
72632 + }
72633 + }
72634 +#endif
72635 +
72636 /* Success. */
72637 if (!err)
72638 return 0;
72639 @@ -1990,10 +2362,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72640 removed_exe_file_vma(mm);
72641 fput(new->vm_file);
72642 }
72643 - unlink_anon_vmas(new);
72644 out_free_mpol:
72645 mpol_put(pol);
72646 out_free_vma:
72647 +
72648 +#ifdef CONFIG_PAX_SEGMEXEC
72649 + if (new_m) {
72650 + unlink_anon_vmas(new_m);
72651 + kmem_cache_free(vm_area_cachep, new_m);
72652 + }
72653 +#endif
72654 +
72655 + unlink_anon_vmas(new);
72656 kmem_cache_free(vm_area_cachep, new);
72657 out_err:
72658 return err;
72659 @@ -2006,6 +2386,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72660 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72661 unsigned long addr, int new_below)
72662 {
72663 +
72664 +#ifdef CONFIG_PAX_SEGMEXEC
72665 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72666 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
72667 + if (mm->map_count >= sysctl_max_map_count-1)
72668 + return -ENOMEM;
72669 + } else
72670 +#endif
72671 +
72672 if (mm->map_count >= sysctl_max_map_count)
72673 return -ENOMEM;
72674
72675 @@ -2017,11 +2406,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72676 * work. This now handles partial unmappings.
72677 * Jeremy Fitzhardinge <jeremy@goop.org>
72678 */
72679 +#ifdef CONFIG_PAX_SEGMEXEC
72680 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72681 {
72682 + int ret = __do_munmap(mm, start, len);
72683 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
72684 + return ret;
72685 +
72686 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
72687 +}
72688 +
72689 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72690 +#else
72691 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72692 +#endif
72693 +{
72694 unsigned long end;
72695 struct vm_area_struct *vma, *prev, *last;
72696
72697 + /*
72698 + * mm->mmap_sem is required to protect against another thread
72699 + * changing the mappings in case we sleep.
72700 + */
72701 + verify_mm_writelocked(mm);
72702 +
72703 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
72704 return -EINVAL;
72705
72706 @@ -2096,6 +2504,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72707 /* Fix up all other VM information */
72708 remove_vma_list(mm, vma);
72709
72710 + track_exec_limit(mm, start, end, 0UL);
72711 +
72712 return 0;
72713 }
72714
72715 @@ -2108,22 +2518,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
72716
72717 profile_munmap(addr);
72718
72719 +#ifdef CONFIG_PAX_SEGMEXEC
72720 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
72721 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
72722 + return -EINVAL;
72723 +#endif
72724 +
72725 down_write(&mm->mmap_sem);
72726 ret = do_munmap(mm, addr, len);
72727 up_write(&mm->mmap_sem);
72728 return ret;
72729 }
72730
72731 -static inline void verify_mm_writelocked(struct mm_struct *mm)
72732 -{
72733 -#ifdef CONFIG_DEBUG_VM
72734 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72735 - WARN_ON(1);
72736 - up_read(&mm->mmap_sem);
72737 - }
72738 -#endif
72739 -}
72740 -
72741 /*
72742 * this is really a simplified "do_mmap". it only handles
72743 * anonymous maps. eventually we may be able to do some
72744 @@ -2137,6 +2543,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72745 struct rb_node ** rb_link, * rb_parent;
72746 pgoff_t pgoff = addr >> PAGE_SHIFT;
72747 int error;
72748 + unsigned long charged;
72749
72750 len = PAGE_ALIGN(len);
72751 if (!len)
72752 @@ -2148,16 +2555,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72753
72754 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
72755
72756 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
72757 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
72758 + flags &= ~VM_EXEC;
72759 +
72760 +#ifdef CONFIG_PAX_MPROTECT
72761 + if (mm->pax_flags & MF_PAX_MPROTECT)
72762 + flags &= ~VM_MAYEXEC;
72763 +#endif
72764 +
72765 + }
72766 +#endif
72767 +
72768 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
72769 if (error & ~PAGE_MASK)
72770 return error;
72771
72772 + charged = len >> PAGE_SHIFT;
72773 +
72774 /*
72775 * mlock MCL_FUTURE?
72776 */
72777 if (mm->def_flags & VM_LOCKED) {
72778 unsigned long locked, lock_limit;
72779 - locked = len >> PAGE_SHIFT;
72780 + locked = charged;
72781 locked += mm->locked_vm;
72782 lock_limit = rlimit(RLIMIT_MEMLOCK);
72783 lock_limit >>= PAGE_SHIFT;
72784 @@ -2174,22 +2595,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72785 /*
72786 * Clear old maps. this also does some error checking for us
72787 */
72788 - munmap_back:
72789 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72790 if (vma && vma->vm_start < addr + len) {
72791 if (do_munmap(mm, addr, len))
72792 return -ENOMEM;
72793 - goto munmap_back;
72794 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72795 + BUG_ON(vma && vma->vm_start < addr + len);
72796 }
72797
72798 /* Check against address space limits *after* clearing old maps... */
72799 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
72800 + if (!may_expand_vm(mm, charged))
72801 return -ENOMEM;
72802
72803 if (mm->map_count > sysctl_max_map_count)
72804 return -ENOMEM;
72805
72806 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
72807 + if (security_vm_enough_memory(charged))
72808 return -ENOMEM;
72809
72810 /* Can we just expand an old private anonymous mapping? */
72811 @@ -2203,7 +2624,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72812 */
72813 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72814 if (!vma) {
72815 - vm_unacct_memory(len >> PAGE_SHIFT);
72816 + vm_unacct_memory(charged);
72817 return -ENOMEM;
72818 }
72819
72820 @@ -2217,11 +2638,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72821 vma_link(mm, vma, prev, rb_link, rb_parent);
72822 out:
72823 perf_event_mmap(vma);
72824 - mm->total_vm += len >> PAGE_SHIFT;
72825 + mm->total_vm += charged;
72826 if (flags & VM_LOCKED) {
72827 if (!mlock_vma_pages_range(vma, addr, addr + len))
72828 - mm->locked_vm += (len >> PAGE_SHIFT);
72829 + mm->locked_vm += charged;
72830 }
72831 + track_exec_limit(mm, addr, addr + len, flags);
72832 return addr;
72833 }
72834
72835 @@ -2268,8 +2690,10 @@ void exit_mmap(struct mm_struct *mm)
72836 * Walk the list again, actually closing and freeing it,
72837 * with preemption enabled, without holding any MM locks.
72838 */
72839 - while (vma)
72840 + while (vma) {
72841 + vma->vm_mirror = NULL;
72842 vma = remove_vma(vma);
72843 + }
72844
72845 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
72846 }
72847 @@ -2283,6 +2707,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72848 struct vm_area_struct * __vma, * prev;
72849 struct rb_node ** rb_link, * rb_parent;
72850
72851 +#ifdef CONFIG_PAX_SEGMEXEC
72852 + struct vm_area_struct *vma_m = NULL;
72853 +#endif
72854 +
72855 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
72856 + return -EPERM;
72857 +
72858 /*
72859 * The vm_pgoff of a purely anonymous vma should be irrelevant
72860 * until its first write fault, when page's anon_vma and index
72861 @@ -2305,7 +2736,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72862 if ((vma->vm_flags & VM_ACCOUNT) &&
72863 security_vm_enough_memory_mm(mm, vma_pages(vma)))
72864 return -ENOMEM;
72865 +
72866 +#ifdef CONFIG_PAX_SEGMEXEC
72867 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
72868 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72869 + if (!vma_m)
72870 + return -ENOMEM;
72871 + }
72872 +#endif
72873 +
72874 vma_link(mm, vma, prev, rb_link, rb_parent);
72875 +
72876 +#ifdef CONFIG_PAX_SEGMEXEC
72877 + if (vma_m)
72878 + BUG_ON(pax_mirror_vma(vma_m, vma));
72879 +#endif
72880 +
72881 return 0;
72882 }
72883
72884 @@ -2323,6 +2769,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72885 struct rb_node **rb_link, *rb_parent;
72886 struct mempolicy *pol;
72887
72888 + BUG_ON(vma->vm_mirror);
72889 +
72890 /*
72891 * If anonymous vma has not yet been faulted, update new pgoff
72892 * to match new location, to increase its chance of merging.
72893 @@ -2373,6 +2821,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72894 return NULL;
72895 }
72896
72897 +#ifdef CONFIG_PAX_SEGMEXEC
72898 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
72899 +{
72900 + struct vm_area_struct *prev_m;
72901 + struct rb_node **rb_link_m, *rb_parent_m;
72902 + struct mempolicy *pol_m;
72903 +
72904 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
72905 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
72906 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
72907 + *vma_m = *vma;
72908 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
72909 + if (anon_vma_clone(vma_m, vma))
72910 + return -ENOMEM;
72911 + pol_m = vma_policy(vma_m);
72912 + mpol_get(pol_m);
72913 + vma_set_policy(vma_m, pol_m);
72914 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
72915 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
72916 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
72917 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
72918 + if (vma_m->vm_file)
72919 + get_file(vma_m->vm_file);
72920 + if (vma_m->vm_ops && vma_m->vm_ops->open)
72921 + vma_m->vm_ops->open(vma_m);
72922 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
72923 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
72924 + vma_m->vm_mirror = vma;
72925 + vma->vm_mirror = vma_m;
72926 + return 0;
72927 +}
72928 +#endif
72929 +
72930 /*
72931 * Return true if the calling process may expand its vm space by the passed
72932 * number of pages
72933 @@ -2383,7 +2864,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
72934 unsigned long lim;
72935
72936 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
72937 -
72938 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
72939 if (cur + npages > lim)
72940 return 0;
72941 return 1;
72942 @@ -2454,6 +2935,22 @@ int install_special_mapping(struct mm_struct *mm,
72943 vma->vm_start = addr;
72944 vma->vm_end = addr + len;
72945
72946 +#ifdef CONFIG_PAX_MPROTECT
72947 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72948 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72949 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
72950 + return -EPERM;
72951 + if (!(vm_flags & VM_EXEC))
72952 + vm_flags &= ~VM_MAYEXEC;
72953 +#else
72954 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72955 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72956 +#endif
72957 + else
72958 + vm_flags &= ~VM_MAYWRITE;
72959 + }
72960 +#endif
72961 +
72962 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
72963 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72964
72965 diff --git a/mm/mprotect.c b/mm/mprotect.c
72966 index 5a688a2..27e031c 100644
72967 --- a/mm/mprotect.c
72968 +++ b/mm/mprotect.c
72969 @@ -23,10 +23,16 @@
72970 #include <linux/mmu_notifier.h>
72971 #include <linux/migrate.h>
72972 #include <linux/perf_event.h>
72973 +
72974 +#ifdef CONFIG_PAX_MPROTECT
72975 +#include <linux/elf.h>
72976 +#endif
72977 +
72978 #include <asm/uaccess.h>
72979 #include <asm/pgtable.h>
72980 #include <asm/cacheflush.h>
72981 #include <asm/tlbflush.h>
72982 +#include <asm/mmu_context.h>
72983
72984 #ifndef pgprot_modify
72985 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
72986 @@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
72987 flush_tlb_range(vma, start, end);
72988 }
72989
72990 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72991 +/* called while holding the mmap semaphor for writing except stack expansion */
72992 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
72993 +{
72994 + unsigned long oldlimit, newlimit = 0UL;
72995 +
72996 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
72997 + return;
72998 +
72999 + spin_lock(&mm->page_table_lock);
73000 + oldlimit = mm->context.user_cs_limit;
73001 + if ((prot & VM_EXEC) && oldlimit < end)
73002 + /* USER_CS limit moved up */
73003 + newlimit = end;
73004 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73005 + /* USER_CS limit moved down */
73006 + newlimit = start;
73007 +
73008 + if (newlimit) {
73009 + mm->context.user_cs_limit = newlimit;
73010 +
73011 +#ifdef CONFIG_SMP
73012 + wmb();
73013 + cpus_clear(mm->context.cpu_user_cs_mask);
73014 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73015 +#endif
73016 +
73017 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73018 + }
73019 + spin_unlock(&mm->page_table_lock);
73020 + if (newlimit == end) {
73021 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
73022 +
73023 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
73024 + if (is_vm_hugetlb_page(vma))
73025 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73026 + else
73027 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73028 + }
73029 +}
73030 +#endif
73031 +
73032 int
73033 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73034 unsigned long start, unsigned long end, unsigned long newflags)
73035 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73036 int error;
73037 int dirty_accountable = 0;
73038
73039 +#ifdef CONFIG_PAX_SEGMEXEC
73040 + struct vm_area_struct *vma_m = NULL;
73041 + unsigned long start_m, end_m;
73042 +
73043 + start_m = start + SEGMEXEC_TASK_SIZE;
73044 + end_m = end + SEGMEXEC_TASK_SIZE;
73045 +#endif
73046 +
73047 if (newflags == oldflags) {
73048 *pprev = vma;
73049 return 0;
73050 }
73051
73052 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73053 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73054 +
73055 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73056 + return -ENOMEM;
73057 +
73058 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73059 + return -ENOMEM;
73060 + }
73061 +
73062 /*
73063 * If we make a private mapping writable we increase our commit;
73064 * but (without finer accounting) cannot reduce our commit if we
73065 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73066 }
73067 }
73068
73069 +#ifdef CONFIG_PAX_SEGMEXEC
73070 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73071 + if (start != vma->vm_start) {
73072 + error = split_vma(mm, vma, start, 1);
73073 + if (error)
73074 + goto fail;
73075 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73076 + *pprev = (*pprev)->vm_next;
73077 + }
73078 +
73079 + if (end != vma->vm_end) {
73080 + error = split_vma(mm, vma, end, 0);
73081 + if (error)
73082 + goto fail;
73083 + }
73084 +
73085 + if (pax_find_mirror_vma(vma)) {
73086 + error = __do_munmap(mm, start_m, end_m - start_m);
73087 + if (error)
73088 + goto fail;
73089 + } else {
73090 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73091 + if (!vma_m) {
73092 + error = -ENOMEM;
73093 + goto fail;
73094 + }
73095 + vma->vm_flags = newflags;
73096 + error = pax_mirror_vma(vma_m, vma);
73097 + if (error) {
73098 + vma->vm_flags = oldflags;
73099 + goto fail;
73100 + }
73101 + }
73102 + }
73103 +#endif
73104 +
73105 /*
73106 * First try to merge with previous and/or next vma.
73107 */
73108 @@ -204,9 +306,21 @@ success:
73109 * vm_flags and vm_page_prot are protected by the mmap_sem
73110 * held in write mode.
73111 */
73112 +
73113 +#ifdef CONFIG_PAX_SEGMEXEC
73114 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73115 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73116 +#endif
73117 +
73118 vma->vm_flags = newflags;
73119 +
73120 +#ifdef CONFIG_PAX_MPROTECT
73121 + if (mm->binfmt && mm->binfmt->handle_mprotect)
73122 + mm->binfmt->handle_mprotect(vma, newflags);
73123 +#endif
73124 +
73125 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
73126 - vm_get_page_prot(newflags));
73127 + vm_get_page_prot(vma->vm_flags));
73128
73129 if (vma_wants_writenotify(vma)) {
73130 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
73131 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73132 end = start + len;
73133 if (end <= start)
73134 return -ENOMEM;
73135 +
73136 +#ifdef CONFIG_PAX_SEGMEXEC
73137 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73138 + if (end > SEGMEXEC_TASK_SIZE)
73139 + return -EINVAL;
73140 + } else
73141 +#endif
73142 +
73143 + if (end > TASK_SIZE)
73144 + return -EINVAL;
73145 +
73146 if (!arch_validate_prot(prot))
73147 return -EINVAL;
73148
73149 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73150 /*
73151 * Does the application expect PROT_READ to imply PROT_EXEC:
73152 */
73153 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73154 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73155 prot |= PROT_EXEC;
73156
73157 vm_flags = calc_vm_prot_bits(prot);
73158 @@ -287,6 +412,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73159 if (start > vma->vm_start)
73160 prev = vma;
73161
73162 +#ifdef CONFIG_PAX_MPROTECT
73163 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
73164 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
73165 +#endif
73166 +
73167 for (nstart = start ; ; ) {
73168 unsigned long newflags;
73169
73170 @@ -296,6 +426,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73171
73172 /* newflags >> 4 shift VM_MAY% in place of VM_% */
73173 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
73174 + if (prot & (PROT_WRITE | PROT_EXEC))
73175 + gr_log_rwxmprotect(vma->vm_file);
73176 +
73177 + error = -EACCES;
73178 + goto out;
73179 + }
73180 +
73181 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
73182 error = -EACCES;
73183 goto out;
73184 }
73185 @@ -310,6 +448,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73186 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
73187 if (error)
73188 goto out;
73189 +
73190 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
73191 +
73192 nstart = tmp;
73193
73194 if (nstart < prev->vm_end)
73195 diff --git a/mm/mremap.c b/mm/mremap.c
73196 index d6959cb..18a402a 100644
73197 --- a/mm/mremap.c
73198 +++ b/mm/mremap.c
73199 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
73200 continue;
73201 pte = ptep_get_and_clear(mm, old_addr, old_pte);
73202 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
73203 +
73204 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73205 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
73206 + pte = pte_exprotect(pte);
73207 +#endif
73208 +
73209 set_pte_at(mm, new_addr, new_pte, pte);
73210 }
73211
73212 @@ -290,6 +296,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
73213 if (is_vm_hugetlb_page(vma))
73214 goto Einval;
73215
73216 +#ifdef CONFIG_PAX_SEGMEXEC
73217 + if (pax_find_mirror_vma(vma))
73218 + goto Einval;
73219 +#endif
73220 +
73221 /* We can't remap across vm area boundaries */
73222 if (old_len > vma->vm_end - addr)
73223 goto Efault;
73224 @@ -346,20 +357,25 @@ static unsigned long mremap_to(unsigned long addr,
73225 unsigned long ret = -EINVAL;
73226 unsigned long charged = 0;
73227 unsigned long map_flags;
73228 + unsigned long pax_task_size = TASK_SIZE;
73229
73230 if (new_addr & ~PAGE_MASK)
73231 goto out;
73232
73233 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
73234 +#ifdef CONFIG_PAX_SEGMEXEC
73235 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73236 + pax_task_size = SEGMEXEC_TASK_SIZE;
73237 +#endif
73238 +
73239 + pax_task_size -= PAGE_SIZE;
73240 +
73241 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
73242 goto out;
73243
73244 /* Check if the location we're moving into overlaps the
73245 * old location at all, and fail if it does.
73246 */
73247 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
73248 - goto out;
73249 -
73250 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
73251 + if (addr + old_len > new_addr && new_addr + new_len > addr)
73252 goto out;
73253
73254 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
73255 @@ -431,6 +447,7 @@ unsigned long do_mremap(unsigned long addr,
73256 struct vm_area_struct *vma;
73257 unsigned long ret = -EINVAL;
73258 unsigned long charged = 0;
73259 + unsigned long pax_task_size = TASK_SIZE;
73260
73261 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
73262 goto out;
73263 @@ -449,6 +466,17 @@ unsigned long do_mremap(unsigned long addr,
73264 if (!new_len)
73265 goto out;
73266
73267 +#ifdef CONFIG_PAX_SEGMEXEC
73268 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73269 + pax_task_size = SEGMEXEC_TASK_SIZE;
73270 +#endif
73271 +
73272 + pax_task_size -= PAGE_SIZE;
73273 +
73274 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
73275 + old_len > pax_task_size || addr > pax_task_size-old_len)
73276 + goto out;
73277 +
73278 if (flags & MREMAP_FIXED) {
73279 if (flags & MREMAP_MAYMOVE)
73280 ret = mremap_to(addr, old_len, new_addr, new_len);
73281 @@ -498,6 +526,7 @@ unsigned long do_mremap(unsigned long addr,
73282 addr + new_len);
73283 }
73284 ret = addr;
73285 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
73286 goto out;
73287 }
73288 }
73289 @@ -524,7 +553,13 @@ unsigned long do_mremap(unsigned long addr,
73290 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
73291 if (ret)
73292 goto out;
73293 +
73294 + map_flags = vma->vm_flags;
73295 ret = move_vma(vma, addr, old_len, new_len, new_addr);
73296 + if (!(ret & ~PAGE_MASK)) {
73297 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
73298 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
73299 + }
73300 }
73301 out:
73302 if (ret & ~PAGE_MASK)
73303 diff --git a/mm/nobootmem.c b/mm/nobootmem.c
73304 index 7fa41b4..6087460 100644
73305 --- a/mm/nobootmem.c
73306 +++ b/mm/nobootmem.c
73307 @@ -110,19 +110,30 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end)
73308 unsigned long __init free_all_memory_core_early(int nodeid)
73309 {
73310 int i;
73311 - u64 start, end;
73312 + u64 start, end, startrange, endrange;
73313 unsigned long count = 0;
73314 - struct range *range = NULL;
73315 + struct range *range = NULL, rangerange = { 0, 0 };
73316 int nr_range;
73317
73318 nr_range = get_free_all_memory_range(&range, nodeid);
73319 + startrange = __pa(range) >> PAGE_SHIFT;
73320 + endrange = (__pa(range + nr_range) - 1) >> PAGE_SHIFT;
73321
73322 for (i = 0; i < nr_range; i++) {
73323 start = range[i].start;
73324 end = range[i].end;
73325 + if (start <= endrange && startrange < end) {
73326 + BUG_ON(rangerange.start | rangerange.end);
73327 + rangerange = range[i];
73328 + continue;
73329 + }
73330 count += end - start;
73331 __free_pages_memory(start, end);
73332 }
73333 + start = rangerange.start;
73334 + end = rangerange.end;
73335 + count += end - start;
73336 + __free_pages_memory(start, end);
73337
73338 return count;
73339 }
73340 diff --git a/mm/nommu.c b/mm/nommu.c
73341 index f59e170..34e2a2b 100644
73342 --- a/mm/nommu.c
73343 +++ b/mm/nommu.c
73344 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
73345 int sysctl_overcommit_ratio = 50; /* default is 50% */
73346 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
73347 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
73348 -int heap_stack_gap = 0;
73349
73350 atomic_long_t mmap_pages_allocated;
73351
73352 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
73353 EXPORT_SYMBOL(find_vma);
73354
73355 /*
73356 - * find a VMA
73357 - * - we don't extend stack VMAs under NOMMU conditions
73358 - */
73359 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
73360 -{
73361 - return find_vma(mm, addr);
73362 -}
73363 -
73364 -/*
73365 * expand a stack to a given address
73366 * - not supported under NOMMU conditions
73367 */
73368 @@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73369
73370 /* most fields are the same, copy all, and then fixup */
73371 *new = *vma;
73372 + INIT_LIST_HEAD(&new->anon_vma_chain);
73373 *region = *vma->vm_region;
73374 new->vm_region = region;
73375
73376 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
73377 index 485be89..c059ad3 100644
73378 --- a/mm/page_alloc.c
73379 +++ b/mm/page_alloc.c
73380 @@ -341,7 +341,7 @@ out:
73381 * This usage means that zero-order pages may not be compound.
73382 */
73383
73384 -static void free_compound_page(struct page *page)
73385 +void free_compound_page(struct page *page)
73386 {
73387 __free_pages_ok(page, compound_order(page));
73388 }
73389 @@ -654,6 +654,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73390 int i;
73391 int bad = 0;
73392
73393 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73394 + unsigned long index = 1UL << order;
73395 +#endif
73396 +
73397 trace_mm_page_free_direct(page, order);
73398 kmemcheck_free_shadow(page, order);
73399
73400 @@ -669,6 +673,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73401 debug_check_no_obj_freed(page_address(page),
73402 PAGE_SIZE << order);
73403 }
73404 +
73405 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73406 + for (; index; --index)
73407 + sanitize_highpage(page + index - 1);
73408 +#endif
73409 +
73410 arch_free_page(page, order);
73411 kernel_map_pages(page, 1 << order, 0);
73412
73413 @@ -784,8 +794,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73414 arch_alloc_page(page, order);
73415 kernel_map_pages(page, 1 << order, 1);
73416
73417 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
73418 if (gfp_flags & __GFP_ZERO)
73419 prep_zero_page(page, order, gfp_flags);
73420 +#endif
73421
73422 if (order && (gfp_flags & __GFP_COMP))
73423 prep_compound_page(page, order);
73424 @@ -3357,7 +3369,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73425 unsigned long pfn;
73426
73427 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73428 +#ifdef CONFIG_X86_32
73429 + /* boot failures in VMware 8 on 32bit vanilla since
73430 + this change */
73431 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73432 +#else
73433 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73434 +#endif
73435 return 1;
73436 }
73437 return 0;
73438 diff --git a/mm/percpu.c b/mm/percpu.c
73439 index 716eb4a..8d10419 100644
73440 --- a/mm/percpu.c
73441 +++ b/mm/percpu.c
73442 @@ -121,7 +121,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73443 static unsigned int pcpu_high_unit_cpu __read_mostly;
73444
73445 /* the address of the first chunk which starts with the kernel static area */
73446 -void *pcpu_base_addr __read_mostly;
73447 +void *pcpu_base_addr __read_only;
73448 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73449
73450 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73451 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73452 index e920aa3..137702a 100644
73453 --- a/mm/process_vm_access.c
73454 +++ b/mm/process_vm_access.c
73455 @@ -13,6 +13,7 @@
73456 #include <linux/uio.h>
73457 #include <linux/sched.h>
73458 #include <linux/highmem.h>
73459 +#include <linux/security.h>
73460 #include <linux/ptrace.h>
73461 #include <linux/slab.h>
73462 #include <linux/syscalls.h>
73463 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73464 size_t iov_l_curr_offset = 0;
73465 ssize_t iov_len;
73466
73467 + return -ENOSYS; // PaX: until properly audited
73468 +
73469 /*
73470 * Work out how many pages of struct pages we're going to need
73471 * when eventually calling get_user_pages
73472 */
73473 for (i = 0; i < riovcnt; i++) {
73474 iov_len = rvec[i].iov_len;
73475 - if (iov_len > 0) {
73476 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
73477 - + iov_len)
73478 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73479 - / PAGE_SIZE + 1;
73480 - nr_pages = max(nr_pages, nr_pages_iov);
73481 - }
73482 + if (iov_len <= 0)
73483 + continue;
73484 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73485 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73486 + nr_pages = max(nr_pages, nr_pages_iov);
73487 }
73488
73489 if (nr_pages == 0)
73490 @@ -298,23 +299,23 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73491 goto free_proc_pages;
73492 }
73493
73494 - task_lock(task);
73495 - if (__ptrace_may_access(task, PTRACE_MODE_ATTACH)) {
73496 - task_unlock(task);
73497 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73498 rc = -EPERM;
73499 goto put_task_struct;
73500 }
73501 - mm = task->mm;
73502
73503 - if (!mm || (task->flags & PF_KTHREAD)) {
73504 - task_unlock(task);
73505 - rc = -EINVAL;
73506 + mm = mm_access(task, PTRACE_MODE_ATTACH);
73507 + if (!mm || IS_ERR(mm)) {
73508 + rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73509 + /*
73510 + * Explicitly map EACCES to EPERM as EPERM is a more a
73511 + * appropriate error code for process_vw_readv/writev
73512 + */
73513 + if (rc == -EACCES)
73514 + rc = -EPERM;
73515 goto put_task_struct;
73516 }
73517
73518 - atomic_inc(&mm->mm_users);
73519 - task_unlock(task);
73520 -
73521 for (i = 0; i < riovcnt && iov_l_curr_idx < liovcnt; i++) {
73522 rc = process_vm_rw_single_vec(
73523 (unsigned long)rvec[i].iov_base, rvec[i].iov_len,
73524 diff --git a/mm/rmap.c b/mm/rmap.c
73525 index a4fd368..e0ffec7 100644
73526 --- a/mm/rmap.c
73527 +++ b/mm/rmap.c
73528 @@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73529 struct anon_vma *anon_vma = vma->anon_vma;
73530 struct anon_vma_chain *avc;
73531
73532 +#ifdef CONFIG_PAX_SEGMEXEC
73533 + struct anon_vma_chain *avc_m = NULL;
73534 +#endif
73535 +
73536 might_sleep();
73537 if (unlikely(!anon_vma)) {
73538 struct mm_struct *mm = vma->vm_mm;
73539 @@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73540 if (!avc)
73541 goto out_enomem;
73542
73543 +#ifdef CONFIG_PAX_SEGMEXEC
73544 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73545 + if (!avc_m)
73546 + goto out_enomem_free_avc;
73547 +#endif
73548 +
73549 anon_vma = find_mergeable_anon_vma(vma);
73550 allocated = NULL;
73551 if (!anon_vma) {
73552 @@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73553 /* page_table_lock to protect against threads */
73554 spin_lock(&mm->page_table_lock);
73555 if (likely(!vma->anon_vma)) {
73556 +
73557 +#ifdef CONFIG_PAX_SEGMEXEC
73558 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73559 +
73560 + if (vma_m) {
73561 + BUG_ON(vma_m->anon_vma);
73562 + vma_m->anon_vma = anon_vma;
73563 + avc_m->anon_vma = anon_vma;
73564 + avc_m->vma = vma;
73565 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
73566 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
73567 + avc_m = NULL;
73568 + }
73569 +#endif
73570 +
73571 vma->anon_vma = anon_vma;
73572 avc->anon_vma = anon_vma;
73573 avc->vma = vma;
73574 @@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73575
73576 if (unlikely(allocated))
73577 put_anon_vma(allocated);
73578 +
73579 +#ifdef CONFIG_PAX_SEGMEXEC
73580 + if (unlikely(avc_m))
73581 + anon_vma_chain_free(avc_m);
73582 +#endif
73583 +
73584 if (unlikely(avc))
73585 anon_vma_chain_free(avc);
73586 }
73587 return 0;
73588
73589 out_enomem_free_avc:
73590 +
73591 +#ifdef CONFIG_PAX_SEGMEXEC
73592 + if (avc_m)
73593 + anon_vma_chain_free(avc_m);
73594 +#endif
73595 +
73596 anon_vma_chain_free(avc);
73597 out_enomem:
73598 return -ENOMEM;
73599 @@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
73600 * Attach the anon_vmas from src to dst.
73601 * Returns 0 on success, -ENOMEM on failure.
73602 */
73603 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73604 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73605 {
73606 struct anon_vma_chain *avc, *pavc;
73607 struct anon_vma *root = NULL;
73608 @@ -276,7 +313,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73609 * the corresponding VMA in the parent process is attached to.
73610 * Returns 0 on success, non-zero on failure.
73611 */
73612 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73613 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73614 {
73615 struct anon_vma_chain *avc;
73616 struct anon_vma *anon_vma;
73617 diff --git a/mm/shmem.c b/mm/shmem.c
73618 index 6c253f7..367e20a 100644
73619 --- a/mm/shmem.c
73620 +++ b/mm/shmem.c
73621 @@ -31,7 +31,7 @@
73622 #include <linux/export.h>
73623 #include <linux/swap.h>
73624
73625 -static struct vfsmount *shm_mnt;
73626 +struct vfsmount *shm_mnt;
73627
73628 #ifdef CONFIG_SHMEM
73629 /*
73630 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
73631 #define BOGO_DIRENT_SIZE 20
73632
73633 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73634 -#define SHORT_SYMLINK_LEN 128
73635 +#define SHORT_SYMLINK_LEN 64
73636
73637 struct shmem_xattr {
73638 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73639 @@ -2180,8 +2180,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73640 int err = -ENOMEM;
73641
73642 /* Round up to L1_CACHE_BYTES to resist false sharing */
73643 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73644 - L1_CACHE_BYTES), GFP_KERNEL);
73645 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73646 if (!sbinfo)
73647 return -ENOMEM;
73648
73649 diff --git a/mm/slab.c b/mm/slab.c
73650 index 83311c9a..fcf8f86 100644
73651 --- a/mm/slab.c
73652 +++ b/mm/slab.c
73653 @@ -151,7 +151,7 @@
73654
73655 /* Legal flag mask for kmem_cache_create(). */
73656 #if DEBUG
73657 -# define CREATE_MASK (SLAB_RED_ZONE | \
73658 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73659 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73660 SLAB_CACHE_DMA | \
73661 SLAB_STORE_USER | \
73662 @@ -159,7 +159,7 @@
73663 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73664 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73665 #else
73666 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73667 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73668 SLAB_CACHE_DMA | \
73669 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73670 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73671 @@ -288,7 +288,7 @@ struct kmem_list3 {
73672 * Need this for bootstrapping a per node allocator.
73673 */
73674 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73675 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73676 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73677 #define CACHE_CACHE 0
73678 #define SIZE_AC MAX_NUMNODES
73679 #define SIZE_L3 (2 * MAX_NUMNODES)
73680 @@ -389,10 +389,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73681 if ((x)->max_freeable < i) \
73682 (x)->max_freeable = i; \
73683 } while (0)
73684 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73685 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73686 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73687 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73688 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73689 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73690 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73691 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73692 #else
73693 #define STATS_INC_ACTIVE(x) do { } while (0)
73694 #define STATS_DEC_ACTIVE(x) do { } while (0)
73695 @@ -538,7 +538,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73696 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73697 */
73698 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
73699 - const struct slab *slab, void *obj)
73700 + const struct slab *slab, const void *obj)
73701 {
73702 u32 offset = (obj - slab->s_mem);
73703 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
73704 @@ -564,7 +564,7 @@ struct cache_names {
73705 static struct cache_names __initdata cache_names[] = {
73706 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
73707 #include <linux/kmalloc_sizes.h>
73708 - {NULL,}
73709 + {NULL}
73710 #undef CACHE
73711 };
73712
73713 @@ -1572,7 +1572,7 @@ void __init kmem_cache_init(void)
73714 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
73715 sizes[INDEX_AC].cs_size,
73716 ARCH_KMALLOC_MINALIGN,
73717 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73718 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73719 NULL);
73720
73721 if (INDEX_AC != INDEX_L3) {
73722 @@ -1580,7 +1580,7 @@ void __init kmem_cache_init(void)
73723 kmem_cache_create(names[INDEX_L3].name,
73724 sizes[INDEX_L3].cs_size,
73725 ARCH_KMALLOC_MINALIGN,
73726 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73727 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73728 NULL);
73729 }
73730
73731 @@ -1598,7 +1598,7 @@ void __init kmem_cache_init(void)
73732 sizes->cs_cachep = kmem_cache_create(names->name,
73733 sizes->cs_size,
73734 ARCH_KMALLOC_MINALIGN,
73735 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73736 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73737 NULL);
73738 }
73739 #ifdef CONFIG_ZONE_DMA
73740 @@ -4322,10 +4322,10 @@ static int s_show(struct seq_file *m, void *p)
73741 }
73742 /* cpu stats */
73743 {
73744 - unsigned long allochit = atomic_read(&cachep->allochit);
73745 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
73746 - unsigned long freehit = atomic_read(&cachep->freehit);
73747 - unsigned long freemiss = atomic_read(&cachep->freemiss);
73748 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
73749 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
73750 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
73751 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
73752
73753 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
73754 allochit, allocmiss, freehit, freemiss);
73755 @@ -4584,13 +4584,62 @@ static int __init slab_proc_init(void)
73756 {
73757 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
73758 #ifdef CONFIG_DEBUG_SLAB_LEAK
73759 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
73760 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
73761 #endif
73762 return 0;
73763 }
73764 module_init(slab_proc_init);
73765 #endif
73766
73767 +void check_object_size(const void *ptr, unsigned long n, bool to)
73768 +{
73769 +
73770 +#ifdef CONFIG_PAX_USERCOPY
73771 + struct page *page;
73772 + struct kmem_cache *cachep = NULL;
73773 + struct slab *slabp;
73774 + unsigned int objnr;
73775 + unsigned long offset;
73776 + const char *type;
73777 +
73778 + if (!n)
73779 + return;
73780 +
73781 + type = "<null>";
73782 + if (ZERO_OR_NULL_PTR(ptr))
73783 + goto report;
73784 +
73785 + if (!virt_addr_valid(ptr))
73786 + return;
73787 +
73788 + page = virt_to_head_page(ptr);
73789 +
73790 + type = "<process stack>";
73791 + if (!PageSlab(page)) {
73792 + if (object_is_on_stack(ptr, n) == -1)
73793 + goto report;
73794 + return;
73795 + }
73796 +
73797 + cachep = page_get_cache(page);
73798 + type = cachep->name;
73799 + if (!(cachep->flags & SLAB_USERCOPY))
73800 + goto report;
73801 +
73802 + slabp = page_get_slab(page);
73803 + objnr = obj_to_index(cachep, slabp, ptr);
73804 + BUG_ON(objnr >= cachep->num);
73805 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
73806 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
73807 + return;
73808 +
73809 +report:
73810 + pax_report_usercopy(ptr, n, to, type);
73811 +#endif
73812 +
73813 +}
73814 +EXPORT_SYMBOL(check_object_size);
73815 +
73816 /**
73817 * ksize - get the actual amount of memory allocated for a given object
73818 * @objp: Pointer to the object
73819 diff --git a/mm/slob.c b/mm/slob.c
73820 index 8105be4..e045f96 100644
73821 --- a/mm/slob.c
73822 +++ b/mm/slob.c
73823 @@ -29,7 +29,7 @@
73824 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
73825 * alloc_pages() directly, allocating compound pages so the page order
73826 * does not have to be separately tracked, and also stores the exact
73827 - * allocation size in page->private so that it can be used to accurately
73828 + * allocation size in slob_page->size so that it can be used to accurately
73829 * provide ksize(). These objects are detected in kfree() because slob_page()
73830 * is false for them.
73831 *
73832 @@ -58,6 +58,7 @@
73833 */
73834
73835 #include <linux/kernel.h>
73836 +#include <linux/sched.h>
73837 #include <linux/slab.h>
73838 #include <linux/mm.h>
73839 #include <linux/swap.h> /* struct reclaim_state */
73840 @@ -102,7 +103,8 @@ struct slob_page {
73841 unsigned long flags; /* mandatory */
73842 atomic_t _count; /* mandatory */
73843 slobidx_t units; /* free units left in page */
73844 - unsigned long pad[2];
73845 + unsigned long pad[1];
73846 + unsigned long size; /* size when >=PAGE_SIZE */
73847 slob_t *free; /* first free slob_t in page */
73848 struct list_head list; /* linked list of free pages */
73849 };
73850 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
73851 */
73852 static inline int is_slob_page(struct slob_page *sp)
73853 {
73854 - return PageSlab((struct page *)sp);
73855 + return PageSlab((struct page *)sp) && !sp->size;
73856 }
73857
73858 static inline void set_slob_page(struct slob_page *sp)
73859 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
73860
73861 static inline struct slob_page *slob_page(const void *addr)
73862 {
73863 - return (struct slob_page *)virt_to_page(addr);
73864 + return (struct slob_page *)virt_to_head_page(addr);
73865 }
73866
73867 /*
73868 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
73869 /*
73870 * Return the size of a slob block.
73871 */
73872 -static slobidx_t slob_units(slob_t *s)
73873 +static slobidx_t slob_units(const slob_t *s)
73874 {
73875 if (s->units > 0)
73876 return s->units;
73877 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
73878 /*
73879 * Return the next free slob block pointer after this one.
73880 */
73881 -static slob_t *slob_next(slob_t *s)
73882 +static slob_t *slob_next(const slob_t *s)
73883 {
73884 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
73885 slobidx_t next;
73886 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
73887 /*
73888 * Returns true if s is the last free block in its page.
73889 */
73890 -static int slob_last(slob_t *s)
73891 +static int slob_last(const slob_t *s)
73892 {
73893 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
73894 }
73895 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
73896 if (!page)
73897 return NULL;
73898
73899 + set_slob_page(page);
73900 return page_address(page);
73901 }
73902
73903 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
73904 if (!b)
73905 return NULL;
73906 sp = slob_page(b);
73907 - set_slob_page(sp);
73908
73909 spin_lock_irqsave(&slob_lock, flags);
73910 sp->units = SLOB_UNITS(PAGE_SIZE);
73911 sp->free = b;
73912 + sp->size = 0;
73913 INIT_LIST_HEAD(&sp->list);
73914 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
73915 set_slob_page_free(sp, slob_list);
73916 @@ -476,10 +479,9 @@ out:
73917 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
73918 */
73919
73920 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73921 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
73922 {
73923 - unsigned int *m;
73924 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73925 + slob_t *m;
73926 void *ret;
73927
73928 gfp &= gfp_allowed_mask;
73929 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73930
73931 if (!m)
73932 return NULL;
73933 - *m = size;
73934 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
73935 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
73936 + m[0].units = size;
73937 + m[1].units = align;
73938 ret = (void *)m + align;
73939
73940 trace_kmalloc_node(_RET_IP_, ret,
73941 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73942 gfp |= __GFP_COMP;
73943 ret = slob_new_pages(gfp, order, node);
73944 if (ret) {
73945 - struct page *page;
73946 - page = virt_to_page(ret);
73947 - page->private = size;
73948 + struct slob_page *sp;
73949 + sp = slob_page(ret);
73950 + sp->size = size;
73951 }
73952
73953 trace_kmalloc_node(_RET_IP_, ret,
73954 size, PAGE_SIZE << order, gfp, node);
73955 }
73956
73957 - kmemleak_alloc(ret, size, 1, gfp);
73958 + return ret;
73959 +}
73960 +
73961 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73962 +{
73963 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73964 + void *ret = __kmalloc_node_align(size, gfp, node, align);
73965 +
73966 + if (!ZERO_OR_NULL_PTR(ret))
73967 + kmemleak_alloc(ret, size, 1, gfp);
73968 return ret;
73969 }
73970 EXPORT_SYMBOL(__kmalloc_node);
73971 @@ -533,13 +547,92 @@ void kfree(const void *block)
73972 sp = slob_page(block);
73973 if (is_slob_page(sp)) {
73974 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73975 - unsigned int *m = (unsigned int *)(block - align);
73976 - slob_free(m, *m + align);
73977 - } else
73978 + slob_t *m = (slob_t *)(block - align);
73979 + slob_free(m, m[0].units + align);
73980 + } else {
73981 + clear_slob_page(sp);
73982 + free_slob_page(sp);
73983 + sp->size = 0;
73984 put_page(&sp->page);
73985 + }
73986 }
73987 EXPORT_SYMBOL(kfree);
73988
73989 +void check_object_size(const void *ptr, unsigned long n, bool to)
73990 +{
73991 +
73992 +#ifdef CONFIG_PAX_USERCOPY
73993 + struct slob_page *sp;
73994 + const slob_t *free;
73995 + const void *base;
73996 + unsigned long flags;
73997 + const char *type;
73998 +
73999 + if (!n)
74000 + return;
74001 +
74002 + type = "<null>";
74003 + if (ZERO_OR_NULL_PTR(ptr))
74004 + goto report;
74005 +
74006 + if (!virt_addr_valid(ptr))
74007 + return;
74008 +
74009 + type = "<process stack>";
74010 + sp = slob_page(ptr);
74011 + if (!PageSlab((struct page *)sp)) {
74012 + if (object_is_on_stack(ptr, n) == -1)
74013 + goto report;
74014 + return;
74015 + }
74016 +
74017 + type = "<slob>";
74018 + if (sp->size) {
74019 + base = page_address(&sp->page);
74020 + if (base <= ptr && n <= sp->size - (ptr - base))
74021 + return;
74022 + goto report;
74023 + }
74024 +
74025 + /* some tricky double walking to find the chunk */
74026 + spin_lock_irqsave(&slob_lock, flags);
74027 + base = (void *)((unsigned long)ptr & PAGE_MASK);
74028 + free = sp->free;
74029 +
74030 + while (!slob_last(free) && (void *)free <= ptr) {
74031 + base = free + slob_units(free);
74032 + free = slob_next(free);
74033 + }
74034 +
74035 + while (base < (void *)free) {
74036 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74037 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
74038 + int offset;
74039 +
74040 + if (ptr < base + align)
74041 + break;
74042 +
74043 + offset = ptr - base - align;
74044 + if (offset >= m) {
74045 + base += size;
74046 + continue;
74047 + }
74048 +
74049 + if (n > m - offset)
74050 + break;
74051 +
74052 + spin_unlock_irqrestore(&slob_lock, flags);
74053 + return;
74054 + }
74055 +
74056 + spin_unlock_irqrestore(&slob_lock, flags);
74057 +report:
74058 + pax_report_usercopy(ptr, n, to, type);
74059 +#endif
74060 +
74061 +}
74062 +EXPORT_SYMBOL(check_object_size);
74063 +
74064 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74065 size_t ksize(const void *block)
74066 {
74067 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
74068 sp = slob_page(block);
74069 if (is_slob_page(sp)) {
74070 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74071 - unsigned int *m = (unsigned int *)(block - align);
74072 - return SLOB_UNITS(*m) * SLOB_UNIT;
74073 + slob_t *m = (slob_t *)(block - align);
74074 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74075 } else
74076 - return sp->page.private;
74077 + return sp->size;
74078 }
74079 EXPORT_SYMBOL(ksize);
74080
74081 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74082 {
74083 struct kmem_cache *c;
74084
74085 +#ifdef CONFIG_PAX_USERCOPY
74086 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
74087 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74088 +#else
74089 c = slob_alloc(sizeof(struct kmem_cache),
74090 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74091 +#endif
74092
74093 if (c) {
74094 c->name = name;
74095 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
74096
74097 lockdep_trace_alloc(flags);
74098
74099 +#ifdef CONFIG_PAX_USERCOPY
74100 + b = __kmalloc_node_align(c->size, flags, node, c->align);
74101 +#else
74102 if (c->size < PAGE_SIZE) {
74103 b = slob_alloc(c->size, flags, c->align, node);
74104 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74105 SLOB_UNITS(c->size) * SLOB_UNIT,
74106 flags, node);
74107 } else {
74108 + struct slob_page *sp;
74109 +
74110 b = slob_new_pages(flags, get_order(c->size), node);
74111 + sp = slob_page(b);
74112 + sp->size = c->size;
74113 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74114 PAGE_SIZE << get_order(c->size),
74115 flags, node);
74116 }
74117 +#endif
74118
74119 if (c->ctor)
74120 c->ctor(b);
74121 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74122
74123 static void __kmem_cache_free(void *b, int size)
74124 {
74125 - if (size < PAGE_SIZE)
74126 + struct slob_page *sp = slob_page(b);
74127 +
74128 + if (is_slob_page(sp))
74129 slob_free(b, size);
74130 - else
74131 + else {
74132 + clear_slob_page(sp);
74133 + free_slob_page(sp);
74134 + sp->size = 0;
74135 slob_free_pages(b, get_order(size));
74136 + }
74137 }
74138
74139 static void kmem_rcu_free(struct rcu_head *head)
74140 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
74141
74142 void kmem_cache_free(struct kmem_cache *c, void *b)
74143 {
74144 + int size = c->size;
74145 +
74146 +#ifdef CONFIG_PAX_USERCOPY
74147 + if (size + c->align < PAGE_SIZE) {
74148 + size += c->align;
74149 + b -= c->align;
74150 + }
74151 +#endif
74152 +
74153 kmemleak_free_recursive(b, c->flags);
74154 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74155 struct slob_rcu *slob_rcu;
74156 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74157 - slob_rcu->size = c->size;
74158 + slob_rcu = b + (size - sizeof(struct slob_rcu));
74159 + slob_rcu->size = size;
74160 call_rcu(&slob_rcu->head, kmem_rcu_free);
74161 } else {
74162 - __kmem_cache_free(b, c->size);
74163 + __kmem_cache_free(b, size);
74164 }
74165
74166 +#ifdef CONFIG_PAX_USERCOPY
74167 + trace_kfree(_RET_IP_, b);
74168 +#else
74169 trace_kmem_cache_free(_RET_IP_, b);
74170 +#endif
74171 +
74172 }
74173 EXPORT_SYMBOL(kmem_cache_free);
74174
74175 diff --git a/mm/slub.c b/mm/slub.c
74176 index 1a919f0..1739c9b 100644
74177 --- a/mm/slub.c
74178 +++ b/mm/slub.c
74179 @@ -208,7 +208,7 @@ struct track {
74180
74181 enum track_item { TRACK_ALLOC, TRACK_FREE };
74182
74183 -#ifdef CONFIG_SYSFS
74184 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74185 static int sysfs_slab_add(struct kmem_cache *);
74186 static int sysfs_slab_alias(struct kmem_cache *, const char *);
74187 static void sysfs_slab_remove(struct kmem_cache *);
74188 @@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
74189 if (!t->addr)
74190 return;
74191
74192 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74193 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74194 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
74195 #ifdef CONFIG_STACKTRACE
74196 {
74197 @@ -2559,6 +2559,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
74198
74199 page = virt_to_head_page(x);
74200
74201 + BUG_ON(!PageSlab(page));
74202 +
74203 slab_free(s, page, x, _RET_IP_);
74204
74205 trace_kmem_cache_free(_RET_IP_, x);
74206 @@ -2592,7 +2594,7 @@ static int slub_min_objects;
74207 * Merge control. If this is set then no merging of slab caches will occur.
74208 * (Could be removed. This was introduced to pacify the merge skeptics.)
74209 */
74210 -static int slub_nomerge;
74211 +static int slub_nomerge = 1;
74212
74213 /*
74214 * Calculate the order of allocation given an slab object size.
74215 @@ -3042,7 +3044,7 @@ static int kmem_cache_open(struct kmem_cache *s,
74216 else
74217 s->cpu_partial = 30;
74218
74219 - s->refcount = 1;
74220 + atomic_set(&s->refcount, 1);
74221 #ifdef CONFIG_NUMA
74222 s->remote_node_defrag_ratio = 1000;
74223 #endif
74224 @@ -3146,8 +3148,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
74225 void kmem_cache_destroy(struct kmem_cache *s)
74226 {
74227 down_write(&slub_lock);
74228 - s->refcount--;
74229 - if (!s->refcount) {
74230 + if (atomic_dec_and_test(&s->refcount)) {
74231 list_del(&s->list);
74232 up_write(&slub_lock);
74233 if (kmem_cache_close(s)) {
74234 @@ -3358,6 +3359,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
74235 EXPORT_SYMBOL(__kmalloc_node);
74236 #endif
74237
74238 +void check_object_size(const void *ptr, unsigned long n, bool to)
74239 +{
74240 +
74241 +#ifdef CONFIG_PAX_USERCOPY
74242 + struct page *page;
74243 + struct kmem_cache *s = NULL;
74244 + unsigned long offset;
74245 + const char *type;
74246 +
74247 + if (!n)
74248 + return;
74249 +
74250 + type = "<null>";
74251 + if (ZERO_OR_NULL_PTR(ptr))
74252 + goto report;
74253 +
74254 + if (!virt_addr_valid(ptr))
74255 + return;
74256 +
74257 + page = virt_to_head_page(ptr);
74258 +
74259 + type = "<process stack>";
74260 + if (!PageSlab(page)) {
74261 + if (object_is_on_stack(ptr, n) == -1)
74262 + goto report;
74263 + return;
74264 + }
74265 +
74266 + s = page->slab;
74267 + type = s->name;
74268 + if (!(s->flags & SLAB_USERCOPY))
74269 + goto report;
74270 +
74271 + offset = (ptr - page_address(page)) % s->size;
74272 + if (offset <= s->objsize && n <= s->objsize - offset)
74273 + return;
74274 +
74275 +report:
74276 + pax_report_usercopy(ptr, n, to, type);
74277 +#endif
74278 +
74279 +}
74280 +EXPORT_SYMBOL(check_object_size);
74281 +
74282 size_t ksize(const void *object)
74283 {
74284 struct page *page;
74285 @@ -3632,7 +3677,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
74286 int node;
74287
74288 list_add(&s->list, &slab_caches);
74289 - s->refcount = -1;
74290 + atomic_set(&s->refcount, -1);
74291
74292 for_each_node_state(node, N_NORMAL_MEMORY) {
74293 struct kmem_cache_node *n = get_node(s, node);
74294 @@ -3749,17 +3794,17 @@ void __init kmem_cache_init(void)
74295
74296 /* Caches that are not of the two-to-the-power-of size */
74297 if (KMALLOC_MIN_SIZE <= 32) {
74298 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
74299 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
74300 caches++;
74301 }
74302
74303 if (KMALLOC_MIN_SIZE <= 64) {
74304 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
74305 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
74306 caches++;
74307 }
74308
74309 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
74310 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
74311 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
74312 caches++;
74313 }
74314
74315 @@ -3827,7 +3872,7 @@ static int slab_unmergeable(struct kmem_cache *s)
74316 /*
74317 * We may have set a slab to be unmergeable during bootstrap.
74318 */
74319 - if (s->refcount < 0)
74320 + if (atomic_read(&s->refcount) < 0)
74321 return 1;
74322
74323 return 0;
74324 @@ -3886,7 +3931,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74325 down_write(&slub_lock);
74326 s = find_mergeable(size, align, flags, name, ctor);
74327 if (s) {
74328 - s->refcount++;
74329 + atomic_inc(&s->refcount);
74330 /*
74331 * Adjust the object sizes so that we clear
74332 * the complete object on kzalloc.
74333 @@ -3895,7 +3940,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74334 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
74335
74336 if (sysfs_slab_alias(s, name)) {
74337 - s->refcount--;
74338 + atomic_dec(&s->refcount);
74339 goto err;
74340 }
74341 up_write(&slub_lock);
74342 @@ -4023,7 +4068,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
74343 }
74344 #endif
74345
74346 -#ifdef CONFIG_SYSFS
74347 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74348 static int count_inuse(struct page *page)
74349 {
74350 return page->inuse;
74351 @@ -4410,12 +4455,12 @@ static void resiliency_test(void)
74352 validate_slab_cache(kmalloc_caches[9]);
74353 }
74354 #else
74355 -#ifdef CONFIG_SYSFS
74356 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74357 static void resiliency_test(void) {};
74358 #endif
74359 #endif
74360
74361 -#ifdef CONFIG_SYSFS
74362 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74363 enum slab_stat_type {
74364 SL_ALL, /* All slabs */
74365 SL_PARTIAL, /* Only partially allocated slabs */
74366 @@ -4656,7 +4701,7 @@ SLAB_ATTR_RO(ctor);
74367
74368 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74369 {
74370 - return sprintf(buf, "%d\n", s->refcount - 1);
74371 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74372 }
74373 SLAB_ATTR_RO(aliases);
74374
74375 @@ -5223,6 +5268,7 @@ static char *create_unique_id(struct kmem_cache *s)
74376 return name;
74377 }
74378
74379 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74380 static int sysfs_slab_add(struct kmem_cache *s)
74381 {
74382 int err;
74383 @@ -5285,6 +5331,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
74384 kobject_del(&s->kobj);
74385 kobject_put(&s->kobj);
74386 }
74387 +#endif
74388
74389 /*
74390 * Need to buffer aliases during bootup until sysfs becomes
74391 @@ -5298,6 +5345,7 @@ struct saved_alias {
74392
74393 static struct saved_alias *alias_list;
74394
74395 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74396 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74397 {
74398 struct saved_alias *al;
74399 @@ -5320,6 +5368,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74400 alias_list = al;
74401 return 0;
74402 }
74403 +#endif
74404
74405 static int __init slab_sysfs_init(void)
74406 {
74407 diff --git a/mm/swap.c b/mm/swap.c
74408 index 55b266d..a532537 100644
74409 --- a/mm/swap.c
74410 +++ b/mm/swap.c
74411 @@ -31,6 +31,7 @@
74412 #include <linux/backing-dev.h>
74413 #include <linux/memcontrol.h>
74414 #include <linux/gfp.h>
74415 +#include <linux/hugetlb.h>
74416
74417 #include "internal.h"
74418
74419 @@ -71,6 +72,8 @@ static void __put_compound_page(struct page *page)
74420
74421 __page_cache_release(page);
74422 dtor = get_compound_page_dtor(page);
74423 + if (!PageHuge(page))
74424 + BUG_ON(dtor != free_compound_page);
74425 (*dtor)(page);
74426 }
74427
74428 diff --git a/mm/swapfile.c b/mm/swapfile.c
74429 index b1cd120..aaae885 100644
74430 --- a/mm/swapfile.c
74431 +++ b/mm/swapfile.c
74432 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
74433
74434 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74435 /* Activity counter to indicate that a swapon or swapoff has occurred */
74436 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
74437 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74438
74439 static inline unsigned char swap_count(unsigned char ent)
74440 {
74441 @@ -1670,7 +1670,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74442 }
74443 filp_close(swap_file, NULL);
74444 err = 0;
74445 - atomic_inc(&proc_poll_event);
74446 + atomic_inc_unchecked(&proc_poll_event);
74447 wake_up_interruptible(&proc_poll_wait);
74448
74449 out_dput:
74450 @@ -1686,8 +1686,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74451
74452 poll_wait(file, &proc_poll_wait, wait);
74453
74454 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
74455 - seq->poll_event = atomic_read(&proc_poll_event);
74456 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74457 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74458 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74459 }
74460
74461 @@ -1785,7 +1785,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74462 return ret;
74463
74464 seq = file->private_data;
74465 - seq->poll_event = atomic_read(&proc_poll_event);
74466 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74467 return 0;
74468 }
74469
74470 @@ -2123,7 +2123,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74471 (p->flags & SWP_DISCARDABLE) ? "D" : "");
74472
74473 mutex_unlock(&swapon_mutex);
74474 - atomic_inc(&proc_poll_event);
74475 + atomic_inc_unchecked(&proc_poll_event);
74476 wake_up_interruptible(&proc_poll_wait);
74477
74478 if (S_ISREG(inode->i_mode))
74479 diff --git a/mm/util.c b/mm/util.c
74480 index 136ac4f..f917fa9 100644
74481 --- a/mm/util.c
74482 +++ b/mm/util.c
74483 @@ -243,6 +243,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
74484 void arch_pick_mmap_layout(struct mm_struct *mm)
74485 {
74486 mm->mmap_base = TASK_UNMAPPED_BASE;
74487 +
74488 +#ifdef CONFIG_PAX_RANDMMAP
74489 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74490 + mm->mmap_base += mm->delta_mmap;
74491 +#endif
74492 +
74493 mm->get_unmapped_area = arch_get_unmapped_area;
74494 mm->unmap_area = arch_unmap_area;
74495 }
74496 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74497 index 27be2f0..633e5cc 100644
74498 --- a/mm/vmalloc.c
74499 +++ b/mm/vmalloc.c
74500 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74501
74502 pte = pte_offset_kernel(pmd, addr);
74503 do {
74504 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74505 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74506 +
74507 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74508 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74509 + BUG_ON(!pte_exec(*pte));
74510 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74511 + continue;
74512 + }
74513 +#endif
74514 +
74515 + {
74516 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74517 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74518 + }
74519 } while (pte++, addr += PAGE_SIZE, addr != end);
74520 }
74521
74522 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74523 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74524 {
74525 pte_t *pte;
74526 + int ret = -ENOMEM;
74527
74528 /*
74529 * nr is a running index into the array which helps higher level
74530 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74531 pte = pte_alloc_kernel(pmd, addr);
74532 if (!pte)
74533 return -ENOMEM;
74534 +
74535 + pax_open_kernel();
74536 do {
74537 struct page *page = pages[*nr];
74538
74539 - if (WARN_ON(!pte_none(*pte)))
74540 - return -EBUSY;
74541 - if (WARN_ON(!page))
74542 - return -ENOMEM;
74543 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74544 + if (pgprot_val(prot) & _PAGE_NX)
74545 +#endif
74546 +
74547 + if (WARN_ON(!pte_none(*pte))) {
74548 + ret = -EBUSY;
74549 + goto out;
74550 + }
74551 + if (WARN_ON(!page)) {
74552 + ret = -ENOMEM;
74553 + goto out;
74554 + }
74555 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74556 (*nr)++;
74557 } while (pte++, addr += PAGE_SIZE, addr != end);
74558 - return 0;
74559 + ret = 0;
74560 +out:
74561 + pax_close_kernel();
74562 + return ret;
74563 }
74564
74565 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74566 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74567 * and fall back on vmalloc() if that fails. Others
74568 * just put it in the vmalloc space.
74569 */
74570 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
74571 +#ifdef CONFIG_MODULES
74572 +#ifdef MODULES_VADDR
74573 unsigned long addr = (unsigned long)x;
74574 if (addr >= MODULES_VADDR && addr < MODULES_END)
74575 return 1;
74576 #endif
74577 +
74578 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74579 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
74580 + return 1;
74581 +#endif
74582 +
74583 +#endif
74584 +
74585 return is_vmalloc_addr(x);
74586 }
74587
74588 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
74589
74590 if (!pgd_none(*pgd)) {
74591 pud_t *pud = pud_offset(pgd, addr);
74592 +#ifdef CONFIG_X86
74593 + if (!pud_large(*pud))
74594 +#endif
74595 if (!pud_none(*pud)) {
74596 pmd_t *pmd = pmd_offset(pud, addr);
74597 +#ifdef CONFIG_X86
74598 + if (!pmd_large(*pmd))
74599 +#endif
74600 if (!pmd_none(*pmd)) {
74601 pte_t *ptep, pte;
74602
74603 @@ -1294,6 +1334,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
74604 struct vm_struct *area;
74605
74606 BUG_ON(in_interrupt());
74607 +
74608 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74609 + if (flags & VM_KERNEXEC) {
74610 + if (start != VMALLOC_START || end != VMALLOC_END)
74611 + return NULL;
74612 + start = (unsigned long)MODULES_EXEC_VADDR;
74613 + end = (unsigned long)MODULES_EXEC_END;
74614 + }
74615 +#endif
74616 +
74617 if (flags & VM_IOREMAP) {
74618 int bit = fls(size);
74619
74620 @@ -1526,6 +1576,11 @@ void *vmap(struct page **pages, unsigned int count,
74621 if (count > totalram_pages)
74622 return NULL;
74623
74624 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74625 + if (!(pgprot_val(prot) & _PAGE_NX))
74626 + flags |= VM_KERNEXEC;
74627 +#endif
74628 +
74629 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
74630 __builtin_return_address(0));
74631 if (!area)
74632 @@ -1627,6 +1682,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
74633 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
74634 goto fail;
74635
74636 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74637 + if (!(pgprot_val(prot) & _PAGE_NX))
74638 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
74639 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
74640 + else
74641 +#endif
74642 +
74643 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
74644 start, end, node, gfp_mask, caller);
74645 if (!area)
74646 @@ -1800,10 +1862,9 @@ EXPORT_SYMBOL(vzalloc_node);
74647 * For tight control over page level allocator and protection flags
74648 * use __vmalloc() instead.
74649 */
74650 -
74651 void *vmalloc_exec(unsigned long size)
74652 {
74653 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
74654 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
74655 -1, __builtin_return_address(0));
74656 }
74657
74658 @@ -2098,6 +2159,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
74659 unsigned long uaddr = vma->vm_start;
74660 unsigned long usize = vma->vm_end - vma->vm_start;
74661
74662 + BUG_ON(vma->vm_mirror);
74663 +
74664 if ((PAGE_SIZE-1) & (unsigned long)addr)
74665 return -EINVAL;
74666
74667 diff --git a/mm/vmstat.c b/mm/vmstat.c
74668 index 8fd603b..cf0d930 100644
74669 --- a/mm/vmstat.c
74670 +++ b/mm/vmstat.c
74671 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
74672 *
74673 * vm_stat contains the global counters
74674 */
74675 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74676 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74677 EXPORT_SYMBOL(vm_stat);
74678
74679 #ifdef CONFIG_SMP
74680 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
74681 v = p->vm_stat_diff[i];
74682 p->vm_stat_diff[i] = 0;
74683 local_irq_restore(flags);
74684 - atomic_long_add(v, &zone->vm_stat[i]);
74685 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
74686 global_diff[i] += v;
74687 #ifdef CONFIG_NUMA
74688 /* 3 seconds idle till flush */
74689 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
74690
74691 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
74692 if (global_diff[i])
74693 - atomic_long_add(global_diff[i], &vm_stat[i]);
74694 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
74695 }
74696
74697 #endif
74698 @@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
74699 start_cpu_timer(cpu);
74700 #endif
74701 #ifdef CONFIG_PROC_FS
74702 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
74703 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
74704 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
74705 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
74706 + {
74707 + mode_t gr_mode = S_IRUGO;
74708 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74709 + gr_mode = S_IRUSR;
74710 +#endif
74711 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
74712 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
74713 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74714 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
74715 +#else
74716 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
74717 +#endif
74718 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
74719 + }
74720 #endif
74721 return 0;
74722 }
74723 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
74724 index 5471628..cef8398 100644
74725 --- a/net/8021q/vlan.c
74726 +++ b/net/8021q/vlan.c
74727 @@ -588,8 +588,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
74728 err = -EPERM;
74729 if (!capable(CAP_NET_ADMIN))
74730 break;
74731 - if ((args.u.name_type >= 0) &&
74732 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
74733 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
74734 struct vlan_net *vn;
74735
74736 vn = net_generic(net, vlan_net_id);
74737 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
74738 index fdfdb57..38d368c 100644
74739 --- a/net/9p/trans_fd.c
74740 +++ b/net/9p/trans_fd.c
74741 @@ -423,7 +423,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
74742 oldfs = get_fs();
74743 set_fs(get_ds());
74744 /* The cast to a user pointer is valid due to the set_fs() */
74745 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
74746 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
74747 set_fs(oldfs);
74748
74749 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
74750 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
74751 index f41f026..fe76ea8 100644
74752 --- a/net/atm/atm_misc.c
74753 +++ b/net/atm/atm_misc.c
74754 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
74755 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
74756 return 1;
74757 atm_return(vcc, truesize);
74758 - atomic_inc(&vcc->stats->rx_drop);
74759 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74760 return 0;
74761 }
74762 EXPORT_SYMBOL(atm_charge);
74763 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
74764 }
74765 }
74766 atm_return(vcc, guess);
74767 - atomic_inc(&vcc->stats->rx_drop);
74768 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74769 return NULL;
74770 }
74771 EXPORT_SYMBOL(atm_alloc_charge);
74772 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
74773
74774 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74775 {
74776 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74777 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74778 __SONET_ITEMS
74779 #undef __HANDLE_ITEM
74780 }
74781 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
74782
74783 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74784 {
74785 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74786 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
74787 __SONET_ITEMS
74788 #undef __HANDLE_ITEM
74789 }
74790 diff --git a/net/atm/lec.h b/net/atm/lec.h
74791 index dfc0719..47c5322 100644
74792 --- a/net/atm/lec.h
74793 +++ b/net/atm/lec.h
74794 @@ -48,7 +48,7 @@ struct lane2_ops {
74795 const u8 *tlvs, u32 sizeoftlvs);
74796 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
74797 const u8 *tlvs, u32 sizeoftlvs);
74798 -};
74799 +} __no_const;
74800
74801 /*
74802 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
74803 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
74804 index 0919a88..a23d54e 100644
74805 --- a/net/atm/mpc.h
74806 +++ b/net/atm/mpc.h
74807 @@ -33,7 +33,7 @@ struct mpoa_client {
74808 struct mpc_parameters parameters; /* parameters for this client */
74809
74810 const struct net_device_ops *old_ops;
74811 - struct net_device_ops new_ops;
74812 + net_device_ops_no_const new_ops;
74813 };
74814
74815
74816 diff --git a/net/atm/proc.c b/net/atm/proc.c
74817 index 0d020de..011c7bb 100644
74818 --- a/net/atm/proc.c
74819 +++ b/net/atm/proc.c
74820 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
74821 const struct k_atm_aal_stats *stats)
74822 {
74823 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
74824 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
74825 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
74826 - atomic_read(&stats->rx_drop));
74827 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
74828 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
74829 + atomic_read_unchecked(&stats->rx_drop));
74830 }
74831
74832 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
74833 diff --git a/net/atm/resources.c b/net/atm/resources.c
74834 index 23f45ce..c748f1a 100644
74835 --- a/net/atm/resources.c
74836 +++ b/net/atm/resources.c
74837 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
74838 static void copy_aal_stats(struct k_atm_aal_stats *from,
74839 struct atm_aal_stats *to)
74840 {
74841 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74842 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74843 __AAL_STAT_ITEMS
74844 #undef __HANDLE_ITEM
74845 }
74846 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
74847 static void subtract_aal_stats(struct k_atm_aal_stats *from,
74848 struct atm_aal_stats *to)
74849 {
74850 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74851 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
74852 __AAL_STAT_ITEMS
74853 #undef __HANDLE_ITEM
74854 }
74855 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
74856 index 3512e25..2b33401 100644
74857 --- a/net/batman-adv/bat_iv_ogm.c
74858 +++ b/net/batman-adv/bat_iv_ogm.c
74859 @@ -541,7 +541,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
74860
74861 /* change sequence number to network order */
74862 batman_ogm_packet->seqno =
74863 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
74864 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
74865
74866 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
74867 batman_ogm_packet->tt_crc = htons((uint16_t)
74868 @@ -561,7 +561,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
74869 else
74870 batman_ogm_packet->gw_flags = NO_FLAGS;
74871
74872 - atomic_inc(&hard_iface->seqno);
74873 + atomic_inc_unchecked(&hard_iface->seqno);
74874
74875 slide_own_bcast_window(hard_iface);
74876 bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
74877 @@ -922,7 +922,7 @@ static void bat_ogm_process(const struct ethhdr *ethhdr,
74878 return;
74879
74880 /* could be changed by schedule_own_packet() */
74881 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
74882 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
74883
74884 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
74885
74886 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
74887 index 7704df4..beb4e16 100644
74888 --- a/net/batman-adv/hard-interface.c
74889 +++ b/net/batman-adv/hard-interface.c
74890 @@ -326,8 +326,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
74891 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
74892 dev_add_pack(&hard_iface->batman_adv_ptype);
74893
74894 - atomic_set(&hard_iface->seqno, 1);
74895 - atomic_set(&hard_iface->frag_seqno, 1);
74896 + atomic_set_unchecked(&hard_iface->seqno, 1);
74897 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
74898 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
74899 hard_iface->net_dev->name);
74900
74901 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
74902 index f9cc957..efd9dae 100644
74903 --- a/net/batman-adv/soft-interface.c
74904 +++ b/net/batman-adv/soft-interface.c
74905 @@ -634,7 +634,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
74906
74907 /* set broadcast sequence number */
74908 bcast_packet->seqno =
74909 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
74910 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
74911
74912 add_bcast_packet_to_list(bat_priv, skb, 1);
74913
74914 @@ -828,7 +828,7 @@ struct net_device *softif_create(const char *name)
74915 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
74916
74917 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
74918 - atomic_set(&bat_priv->bcast_seqno, 1);
74919 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
74920 atomic_set(&bat_priv->ttvn, 0);
74921 atomic_set(&bat_priv->tt_local_changes, 0);
74922 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
74923 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
74924 index ab8d0fe..ceba3fd 100644
74925 --- a/net/batman-adv/types.h
74926 +++ b/net/batman-adv/types.h
74927 @@ -38,8 +38,8 @@ struct hard_iface {
74928 int16_t if_num;
74929 char if_status;
74930 struct net_device *net_dev;
74931 - atomic_t seqno;
74932 - atomic_t frag_seqno;
74933 + atomic_unchecked_t seqno;
74934 + atomic_unchecked_t frag_seqno;
74935 unsigned char *packet_buff;
74936 int packet_len;
74937 struct kobject *hardif_obj;
74938 @@ -154,7 +154,7 @@ struct bat_priv {
74939 atomic_t orig_interval; /* uint */
74940 atomic_t hop_penalty; /* uint */
74941 atomic_t log_level; /* uint */
74942 - atomic_t bcast_seqno;
74943 + atomic_unchecked_t bcast_seqno;
74944 atomic_t bcast_queue_left;
74945 atomic_t batman_queue_left;
74946 atomic_t ttvn; /* translation table version number */
74947 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
74948 index 07d1c1d..7e9bea9 100644
74949 --- a/net/batman-adv/unicast.c
74950 +++ b/net/batman-adv/unicast.c
74951 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
74952 frag1->flags = UNI_FRAG_HEAD | large_tail;
74953 frag2->flags = large_tail;
74954
74955 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
74956 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
74957 frag1->seqno = htons(seqno - 1);
74958 frag2->seqno = htons(seqno);
74959
74960 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
74961 index c1c597e..05ebb40 100644
74962 --- a/net/bluetooth/hci_conn.c
74963 +++ b/net/bluetooth/hci_conn.c
74964 @@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
74965 memset(&cp, 0, sizeof(cp));
74966
74967 cp.handle = cpu_to_le16(conn->handle);
74968 - memcpy(cp.ltk, ltk, sizeof(ltk));
74969 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
74970
74971 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
74972 }
74973 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
74974 index 17b5b1c..826d872 100644
74975 --- a/net/bluetooth/l2cap_core.c
74976 +++ b/net/bluetooth/l2cap_core.c
74977 @@ -2176,8 +2176,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
74978 break;
74979
74980 case L2CAP_CONF_RFC:
74981 - if (olen == sizeof(rfc))
74982 - memcpy(&rfc, (void *)val, olen);
74983 + if (olen != sizeof(rfc))
74984 + break;
74985 +
74986 + memcpy(&rfc, (void *)val, olen);
74987
74988 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
74989 rfc.mode != chan->mode)
74990 @@ -2265,8 +2267,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
74991
74992 switch (type) {
74993 case L2CAP_CONF_RFC:
74994 - if (olen == sizeof(rfc))
74995 - memcpy(&rfc, (void *)val, olen);
74996 + if (olen != sizeof(rfc))
74997 + break;
74998 +
74999 + memcpy(&rfc, (void *)val, olen);
75000 goto done;
75001 }
75002 }
75003 diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
75004 index 8eb6b15..e3db7ab 100644
75005 --- a/net/bridge/br_multicast.c
75006 +++ b/net/bridge/br_multicast.c
75007 @@ -1488,7 +1488,7 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br,
75008 nexthdr = ip6h->nexthdr;
75009 offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr);
75010
75011 - if (offset < 0 || nexthdr != IPPROTO_ICMPV6)
75012 + if (nexthdr != IPPROTO_ICMPV6)
75013 return 0;
75014
75015 /* Okay, we found ICMPv6 header */
75016 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
75017 index 5864cc4..121f3a30 100644
75018 --- a/net/bridge/netfilter/ebtables.c
75019 +++ b/net/bridge/netfilter/ebtables.c
75020 @@ -1513,7 +1513,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
75021 tmp.valid_hooks = t->table->valid_hooks;
75022 }
75023 mutex_unlock(&ebt_mutex);
75024 - if (copy_to_user(user, &tmp, *len) != 0){
75025 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
75026 BUGPRINT("c2u Didn't work\n");
75027 ret = -EFAULT;
75028 break;
75029 diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
75030 index a986280..13444a1 100644
75031 --- a/net/caif/caif_socket.c
75032 +++ b/net/caif/caif_socket.c
75033 @@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
75034 #ifdef CONFIG_DEBUG_FS
75035 struct debug_fs_counter {
75036 atomic_t caif_nr_socks;
75037 - atomic_t caif_sock_create;
75038 - atomic_t num_connect_req;
75039 - atomic_t num_connect_resp;
75040 - atomic_t num_connect_fail_resp;
75041 - atomic_t num_disconnect;
75042 - atomic_t num_remote_shutdown_ind;
75043 - atomic_t num_tx_flow_off_ind;
75044 - atomic_t num_tx_flow_on_ind;
75045 - atomic_t num_rx_flow_off;
75046 - atomic_t num_rx_flow_on;
75047 + atomic_unchecked_t caif_sock_create;
75048 + atomic_unchecked_t num_connect_req;
75049 + atomic_unchecked_t num_connect_resp;
75050 + atomic_unchecked_t num_connect_fail_resp;
75051 + atomic_unchecked_t num_disconnect;
75052 + atomic_unchecked_t num_remote_shutdown_ind;
75053 + atomic_unchecked_t num_tx_flow_off_ind;
75054 + atomic_unchecked_t num_tx_flow_on_ind;
75055 + atomic_unchecked_t num_rx_flow_off;
75056 + atomic_unchecked_t num_rx_flow_on;
75057 };
75058 static struct debug_fs_counter cnt;
75059 #define dbfs_atomic_inc(v) atomic_inc_return(v)
75060 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
75061 #define dbfs_atomic_dec(v) atomic_dec_return(v)
75062 #else
75063 #define dbfs_atomic_inc(v) 0
75064 @@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75065 atomic_read(&cf_sk->sk.sk_rmem_alloc),
75066 sk_rcvbuf_lowwater(cf_sk));
75067 set_rx_flow_off(cf_sk);
75068 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
75069 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
75070 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
75071 }
75072
75073 @@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75074 set_rx_flow_off(cf_sk);
75075 if (net_ratelimit())
75076 pr_debug("sending flow OFF due to rmem_schedule\n");
75077 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
75078 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
75079 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
75080 }
75081 skb->dev = NULL;
75082 @@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
75083 switch (flow) {
75084 case CAIF_CTRLCMD_FLOW_ON_IND:
75085 /* OK from modem to start sending again */
75086 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
75087 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
75088 set_tx_flow_on(cf_sk);
75089 cf_sk->sk.sk_state_change(&cf_sk->sk);
75090 break;
75091
75092 case CAIF_CTRLCMD_FLOW_OFF_IND:
75093 /* Modem asks us to shut up */
75094 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
75095 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
75096 set_tx_flow_off(cf_sk);
75097 cf_sk->sk.sk_state_change(&cf_sk->sk);
75098 break;
75099 @@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
75100 /* We're now connected */
75101 caif_client_register_refcnt(&cf_sk->layer,
75102 cfsk_hold, cfsk_put);
75103 - dbfs_atomic_inc(&cnt.num_connect_resp);
75104 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
75105 cf_sk->sk.sk_state = CAIF_CONNECTED;
75106 set_tx_flow_on(cf_sk);
75107 cf_sk->sk.sk_state_change(&cf_sk->sk);
75108 @@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
75109
75110 case CAIF_CTRLCMD_INIT_FAIL_RSP:
75111 /* Connect request failed */
75112 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
75113 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
75114 cf_sk->sk.sk_err = ECONNREFUSED;
75115 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
75116 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
75117 @@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
75118
75119 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
75120 /* Modem has closed this connection, or device is down. */
75121 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
75122 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
75123 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
75124 cf_sk->sk.sk_err = ECONNRESET;
75125 set_rx_flow_on(cf_sk);
75126 @@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
75127 return;
75128
75129 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
75130 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
75131 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
75132 set_rx_flow_on(cf_sk);
75133 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
75134 }
75135 @@ -854,7 +855,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
75136 /*ifindex = id of the interface.*/
75137 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
75138
75139 - dbfs_atomic_inc(&cnt.num_connect_req);
75140 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
75141 cf_sk->layer.receive = caif_sktrecv_cb;
75142
75143 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
75144 @@ -943,7 +944,7 @@ static int caif_release(struct socket *sock)
75145 spin_unlock_bh(&sk->sk_receive_queue.lock);
75146 sock->sk = NULL;
75147
75148 - dbfs_atomic_inc(&cnt.num_disconnect);
75149 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
75150
75151 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
75152 if (cf_sk->debugfs_socket_dir != NULL)
75153 @@ -1122,7 +1123,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
75154 cf_sk->conn_req.protocol = protocol;
75155 /* Increase the number of sockets created. */
75156 dbfs_atomic_inc(&cnt.caif_nr_socks);
75157 - num = dbfs_atomic_inc(&cnt.caif_sock_create);
75158 + num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
75159 #ifdef CONFIG_DEBUG_FS
75160 if (!IS_ERR(debugfsdir)) {
75161
75162 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
75163 index 5cf5222..6f704ad 100644
75164 --- a/net/caif/cfctrl.c
75165 +++ b/net/caif/cfctrl.c
75166 @@ -9,6 +9,7 @@
75167 #include <linux/stddef.h>
75168 #include <linux/spinlock.h>
75169 #include <linux/slab.h>
75170 +#include <linux/sched.h>
75171 #include <net/caif/caif_layer.h>
75172 #include <net/caif/cfpkt.h>
75173 #include <net/caif/cfctrl.h>
75174 @@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
75175 memset(&dev_info, 0, sizeof(dev_info));
75176 dev_info.id = 0xff;
75177 cfsrvl_init(&this->serv, 0, &dev_info, false);
75178 - atomic_set(&this->req_seq_no, 1);
75179 - atomic_set(&this->rsp_seq_no, 1);
75180 + atomic_set_unchecked(&this->req_seq_no, 1);
75181 + atomic_set_unchecked(&this->rsp_seq_no, 1);
75182 this->serv.layer.receive = cfctrl_recv;
75183 sprintf(this->serv.layer.name, "ctrl");
75184 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75185 @@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
75186 struct cfctrl_request_info *req)
75187 {
75188 spin_lock_bh(&ctrl->info_list_lock);
75189 - atomic_inc(&ctrl->req_seq_no);
75190 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
75191 + atomic_inc_unchecked(&ctrl->req_seq_no);
75192 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75193 list_add_tail(&req->list, &ctrl->list);
75194 spin_unlock_bh(&ctrl->info_list_lock);
75195 }
75196 @@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
75197 if (p != first)
75198 pr_warn("Requests are not received in order\n");
75199
75200 - atomic_set(&ctrl->rsp_seq_no,
75201 + atomic_set_unchecked(&ctrl->rsp_seq_no,
75202 p->sequence_no);
75203 list_del(&p->list);
75204 goto out;
75205 diff --git a/net/can/gw.c b/net/can/gw.c
75206 index 3d79b12..8de85fa 100644
75207 --- a/net/can/gw.c
75208 +++ b/net/can/gw.c
75209 @@ -96,7 +96,7 @@ struct cf_mod {
75210 struct {
75211 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
75212 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
75213 - } csumfunc;
75214 + } __no_const csumfunc;
75215 };
75216
75217
75218 diff --git a/net/compat.c b/net/compat.c
75219 index 6def90e..c6992fa 100644
75220 --- a/net/compat.c
75221 +++ b/net/compat.c
75222 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
75223 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
75224 __get_user(kmsg->msg_flags, &umsg->msg_flags))
75225 return -EFAULT;
75226 - kmsg->msg_name = compat_ptr(tmp1);
75227 - kmsg->msg_iov = compat_ptr(tmp2);
75228 - kmsg->msg_control = compat_ptr(tmp3);
75229 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
75230 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
75231 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
75232 return 0;
75233 }
75234
75235 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75236
75237 if (kern_msg->msg_namelen) {
75238 if (mode == VERIFY_READ) {
75239 - int err = move_addr_to_kernel(kern_msg->msg_name,
75240 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
75241 kern_msg->msg_namelen,
75242 kern_address);
75243 if (err < 0)
75244 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75245 kern_msg->msg_name = NULL;
75246
75247 tot_len = iov_from_user_compat_to_kern(kern_iov,
75248 - (struct compat_iovec __user *)kern_msg->msg_iov,
75249 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
75250 kern_msg->msg_iovlen);
75251 if (tot_len >= 0)
75252 kern_msg->msg_iov = kern_iov;
75253 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75254
75255 #define CMSG_COMPAT_FIRSTHDR(msg) \
75256 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
75257 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
75258 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
75259 (struct compat_cmsghdr __user *)NULL)
75260
75261 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
75262 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
75263 (ucmlen) <= (unsigned long) \
75264 ((mhdr)->msg_controllen - \
75265 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
75266 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
75267
75268 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
75269 struct compat_cmsghdr __user *cmsg, int cmsg_len)
75270 {
75271 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
75272 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
75273 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
75274 msg->msg_controllen)
75275 return NULL;
75276 return (struct compat_cmsghdr __user *)ptr;
75277 @@ -221,7 +221,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75278 {
75279 struct compat_timeval ctv;
75280 struct compat_timespec cts[3];
75281 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75282 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75283 struct compat_cmsghdr cmhdr;
75284 int cmlen;
75285
75286 @@ -273,7 +273,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75287
75288 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
75289 {
75290 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75291 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75292 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
75293 int fdnum = scm->fp->count;
75294 struct file **fp = scm->fp->fp;
75295 @@ -370,7 +370,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
75296 return -EFAULT;
75297 old_fs = get_fs();
75298 set_fs(KERNEL_DS);
75299 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
75300 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
75301 set_fs(old_fs);
75302
75303 return err;
75304 @@ -431,7 +431,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
75305 len = sizeof(ktime);
75306 old_fs = get_fs();
75307 set_fs(KERNEL_DS);
75308 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
75309 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
75310 set_fs(old_fs);
75311
75312 if (!err) {
75313 @@ -566,7 +566,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75314 case MCAST_JOIN_GROUP:
75315 case MCAST_LEAVE_GROUP:
75316 {
75317 - struct compat_group_req __user *gr32 = (void *)optval;
75318 + struct compat_group_req __user *gr32 = (void __user *)optval;
75319 struct group_req __user *kgr =
75320 compat_alloc_user_space(sizeof(struct group_req));
75321 u32 interface;
75322 @@ -587,7 +587,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75323 case MCAST_BLOCK_SOURCE:
75324 case MCAST_UNBLOCK_SOURCE:
75325 {
75326 - struct compat_group_source_req __user *gsr32 = (void *)optval;
75327 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
75328 struct group_source_req __user *kgsr = compat_alloc_user_space(
75329 sizeof(struct group_source_req));
75330 u32 interface;
75331 @@ -608,7 +608,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75332 }
75333 case MCAST_MSFILTER:
75334 {
75335 - struct compat_group_filter __user *gf32 = (void *)optval;
75336 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75337 struct group_filter __user *kgf;
75338 u32 interface, fmode, numsrc;
75339
75340 @@ -646,7 +646,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
75341 char __user *optval, int __user *optlen,
75342 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
75343 {
75344 - struct compat_group_filter __user *gf32 = (void *)optval;
75345 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75346 struct group_filter __user *kgf;
75347 int __user *koptlen;
75348 u32 interface, fmode, numsrc;
75349 diff --git a/net/core/datagram.c b/net/core/datagram.c
75350 index 68bbf9f..5ef0d12 100644
75351 --- a/net/core/datagram.c
75352 +++ b/net/core/datagram.c
75353 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
75354 }
75355
75356 kfree_skb(skb);
75357 - atomic_inc(&sk->sk_drops);
75358 + atomic_inc_unchecked(&sk->sk_drops);
75359 sk_mem_reclaim_partial(sk);
75360
75361 return err;
75362 diff --git a/net/core/dev.c b/net/core/dev.c
75363 index c56cacf..b28e35f 100644
75364 --- a/net/core/dev.c
75365 +++ b/net/core/dev.c
75366 @@ -1139,10 +1139,14 @@ void dev_load(struct net *net, const char *name)
75367 if (no_module && capable(CAP_NET_ADMIN))
75368 no_module = request_module("netdev-%s", name);
75369 if (no_module && capable(CAP_SYS_MODULE)) {
75370 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
75371 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
75372 +#else
75373 if (!request_module("%s", name))
75374 pr_err("Loading kernel module for a network device "
75375 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
75376 "instead\n", name);
75377 +#endif
75378 }
75379 }
75380 EXPORT_SYMBOL(dev_load);
75381 @@ -1573,7 +1577,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75382 {
75383 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
75384 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
75385 - atomic_long_inc(&dev->rx_dropped);
75386 + atomic_long_inc_unchecked(&dev->rx_dropped);
75387 kfree_skb(skb);
75388 return NET_RX_DROP;
75389 }
75390 @@ -1583,7 +1587,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75391 nf_reset(skb);
75392
75393 if (unlikely(!is_skb_forwardable(dev, skb))) {
75394 - atomic_long_inc(&dev->rx_dropped);
75395 + atomic_long_inc_unchecked(&dev->rx_dropped);
75396 kfree_skb(skb);
75397 return NET_RX_DROP;
75398 }
75399 @@ -2036,7 +2040,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
75400
75401 struct dev_gso_cb {
75402 void (*destructor)(struct sk_buff *skb);
75403 -};
75404 +} __no_const;
75405
75406 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75407
75408 @@ -2970,7 +2974,7 @@ enqueue:
75409
75410 local_irq_restore(flags);
75411
75412 - atomic_long_inc(&skb->dev->rx_dropped);
75413 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75414 kfree_skb(skb);
75415 return NET_RX_DROP;
75416 }
75417 @@ -3044,7 +3048,7 @@ int netif_rx_ni(struct sk_buff *skb)
75418 }
75419 EXPORT_SYMBOL(netif_rx_ni);
75420
75421 -static void net_tx_action(struct softirq_action *h)
75422 +static void net_tx_action(void)
75423 {
75424 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75425
75426 @@ -3333,7 +3337,7 @@ ncls:
75427 if (pt_prev) {
75428 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
75429 } else {
75430 - atomic_long_inc(&skb->dev->rx_dropped);
75431 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75432 kfree_skb(skb);
75433 /* Jamal, now you will not able to escape explaining
75434 * me how you were going to use this. :-)
75435 @@ -3897,7 +3901,7 @@ void netif_napi_del(struct napi_struct *napi)
75436 }
75437 EXPORT_SYMBOL(netif_napi_del);
75438
75439 -static void net_rx_action(struct softirq_action *h)
75440 +static void net_rx_action(void)
75441 {
75442 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75443 unsigned long time_limit = jiffies + 2;
75444 @@ -5955,7 +5959,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75445 } else {
75446 netdev_stats_to_stats64(storage, &dev->stats);
75447 }
75448 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75449 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75450 return storage;
75451 }
75452 EXPORT_SYMBOL(dev_get_stats);
75453 diff --git a/net/core/flow.c b/net/core/flow.c
75454 index e318c7e..168b1d0 100644
75455 --- a/net/core/flow.c
75456 +++ b/net/core/flow.c
75457 @@ -61,7 +61,7 @@ struct flow_cache {
75458 struct timer_list rnd_timer;
75459 };
75460
75461 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
75462 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75463 EXPORT_SYMBOL(flow_cache_genid);
75464 static struct flow_cache flow_cache_global;
75465 static struct kmem_cache *flow_cachep __read_mostly;
75466 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75467
75468 static int flow_entry_valid(struct flow_cache_entry *fle)
75469 {
75470 - if (atomic_read(&flow_cache_genid) != fle->genid)
75471 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75472 return 0;
75473 if (fle->object && !fle->object->ops->check(fle->object))
75474 return 0;
75475 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75476 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75477 fcp->hash_count++;
75478 }
75479 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75480 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75481 flo = fle->object;
75482 if (!flo)
75483 goto ret_object;
75484 @@ -280,7 +280,7 @@ nocache:
75485 }
75486 flo = resolver(net, key, family, dir, flo, ctx);
75487 if (fle) {
75488 - fle->genid = atomic_read(&flow_cache_genid);
75489 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
75490 if (!IS_ERR(flo))
75491 fle->object = flo;
75492 else
75493 diff --git a/net/core/iovec.c b/net/core/iovec.c
75494 index c40f27e..7f49254 100644
75495 --- a/net/core/iovec.c
75496 +++ b/net/core/iovec.c
75497 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75498 if (m->msg_namelen) {
75499 if (mode == VERIFY_READ) {
75500 void __user *namep;
75501 - namep = (void __user __force *) m->msg_name;
75502 + namep = (void __force_user *) m->msg_name;
75503 err = move_addr_to_kernel(namep, m->msg_namelen,
75504 address);
75505 if (err < 0)
75506 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75507 }
75508
75509 size = m->msg_iovlen * sizeof(struct iovec);
75510 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75511 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75512 return -EFAULT;
75513
75514 m->msg_iov = iov;
75515 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75516 index 9083e82..1673203 100644
75517 --- a/net/core/rtnetlink.c
75518 +++ b/net/core/rtnetlink.c
75519 @@ -57,7 +57,7 @@ struct rtnl_link {
75520 rtnl_doit_func doit;
75521 rtnl_dumpit_func dumpit;
75522 rtnl_calcit_func calcit;
75523 -};
75524 +} __no_const;
75525
75526 static DEFINE_MUTEX(rtnl_mutex);
75527 static u16 min_ifinfo_dump_size;
75528 diff --git a/net/core/scm.c b/net/core/scm.c
75529 index ff52ad0..aff1c0f 100644
75530 --- a/net/core/scm.c
75531 +++ b/net/core/scm.c
75532 @@ -220,7 +220,7 @@ EXPORT_SYMBOL(__scm_send);
75533 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75534 {
75535 struct cmsghdr __user *cm
75536 - = (__force struct cmsghdr __user *)msg->msg_control;
75537 + = (struct cmsghdr __force_user *)msg->msg_control;
75538 struct cmsghdr cmhdr;
75539 int cmlen = CMSG_LEN(len);
75540 int err;
75541 @@ -243,7 +243,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75542 err = -EFAULT;
75543 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75544 goto out;
75545 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75546 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75547 goto out;
75548 cmlen = CMSG_SPACE(len);
75549 if (msg->msg_controllen < cmlen)
75550 @@ -259,7 +259,7 @@ EXPORT_SYMBOL(put_cmsg);
75551 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75552 {
75553 struct cmsghdr __user *cm
75554 - = (__force struct cmsghdr __user*)msg->msg_control;
75555 + = (struct cmsghdr __force_user *)msg->msg_control;
75556
75557 int fdmax = 0;
75558 int fdnum = scm->fp->count;
75559 @@ -279,7 +279,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75560 if (fdnum < fdmax)
75561 fdmax = fdnum;
75562
75563 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75564 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75565 i++, cmfptr++)
75566 {
75567 int new_fd;
75568 diff --git a/net/core/sock.c b/net/core/sock.c
75569 index b23f174..b9a0d26 100644
75570 --- a/net/core/sock.c
75571 +++ b/net/core/sock.c
75572 @@ -289,7 +289,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75573 struct sk_buff_head *list = &sk->sk_receive_queue;
75574
75575 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
75576 - atomic_inc(&sk->sk_drops);
75577 + atomic_inc_unchecked(&sk->sk_drops);
75578 trace_sock_rcvqueue_full(sk, skb);
75579 return -ENOMEM;
75580 }
75581 @@ -299,7 +299,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75582 return err;
75583
75584 if (!sk_rmem_schedule(sk, skb->truesize)) {
75585 - atomic_inc(&sk->sk_drops);
75586 + atomic_inc_unchecked(&sk->sk_drops);
75587 return -ENOBUFS;
75588 }
75589
75590 @@ -319,7 +319,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75591 skb_dst_force(skb);
75592
75593 spin_lock_irqsave(&list->lock, flags);
75594 - skb->dropcount = atomic_read(&sk->sk_drops);
75595 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75596 __skb_queue_tail(list, skb);
75597 spin_unlock_irqrestore(&list->lock, flags);
75598
75599 @@ -339,7 +339,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75600 skb->dev = NULL;
75601
75602 if (sk_rcvqueues_full(sk, skb)) {
75603 - atomic_inc(&sk->sk_drops);
75604 + atomic_inc_unchecked(&sk->sk_drops);
75605 goto discard_and_relse;
75606 }
75607 if (nested)
75608 @@ -357,7 +357,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75609 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75610 } else if (sk_add_backlog(sk, skb)) {
75611 bh_unlock_sock(sk);
75612 - atomic_inc(&sk->sk_drops);
75613 + atomic_inc_unchecked(&sk->sk_drops);
75614 goto discard_and_relse;
75615 }
75616
75617 @@ -917,7 +917,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75618 if (len > sizeof(peercred))
75619 len = sizeof(peercred);
75620 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
75621 - if (copy_to_user(optval, &peercred, len))
75622 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
75623 return -EFAULT;
75624 goto lenout;
75625 }
75626 @@ -930,7 +930,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75627 return -ENOTCONN;
75628 if (lv < len)
75629 return -EINVAL;
75630 - if (copy_to_user(optval, address, len))
75631 + if (len > sizeof(address) || copy_to_user(optval, address, len))
75632 return -EFAULT;
75633 goto lenout;
75634 }
75635 @@ -963,7 +963,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75636
75637 if (len > lv)
75638 len = lv;
75639 - if (copy_to_user(optval, &v, len))
75640 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
75641 return -EFAULT;
75642 lenout:
75643 if (put_user(len, optlen))
75644 @@ -2020,7 +2020,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
75645 */
75646 smp_wmb();
75647 atomic_set(&sk->sk_refcnt, 1);
75648 - atomic_set(&sk->sk_drops, 0);
75649 + atomic_set_unchecked(&sk->sk_drops, 0);
75650 }
75651 EXPORT_SYMBOL(sock_init_data);
75652
75653 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
75654 index 02e75d1..9a57a7c 100644
75655 --- a/net/decnet/sysctl_net_decnet.c
75656 +++ b/net/decnet/sysctl_net_decnet.c
75657 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
75658
75659 if (len > *lenp) len = *lenp;
75660
75661 - if (copy_to_user(buffer, addr, len))
75662 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
75663 return -EFAULT;
75664
75665 *lenp = len;
75666 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
75667
75668 if (len > *lenp) len = *lenp;
75669
75670 - if (copy_to_user(buffer, devname, len))
75671 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
75672 return -EFAULT;
75673
75674 *lenp = len;
75675 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
75676 index 39a2d29..f39c0fe 100644
75677 --- a/net/econet/Kconfig
75678 +++ b/net/econet/Kconfig
75679 @@ -4,7 +4,7 @@
75680
75681 config ECONET
75682 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
75683 - depends on EXPERIMENTAL && INET
75684 + depends on EXPERIMENTAL && INET && BROKEN
75685 ---help---
75686 Econet is a fairly old and slow networking protocol mainly used by
75687 Acorn computers to access file and print servers. It uses native
75688 diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
75689 index 36d1440..44ff28b 100644
75690 --- a/net/ipv4/ah4.c
75691 +++ b/net/ipv4/ah4.c
75692 @@ -19,6 +19,8 @@ struct ah_skb_cb {
75693 #define AH_SKB_CB(__skb) ((struct ah_skb_cb *)&((__skb)->cb[0]))
75694
75695 static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
75696 + unsigned int size) __size_overflow(3);
75697 +static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
75698 unsigned int size)
75699 {
75700 unsigned int len;
75701 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
75702 index 92fc5f6..b790d91 100644
75703 --- a/net/ipv4/fib_frontend.c
75704 +++ b/net/ipv4/fib_frontend.c
75705 @@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
75706 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75707 fib_sync_up(dev);
75708 #endif
75709 - atomic_inc(&net->ipv4.dev_addr_genid);
75710 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75711 rt_cache_flush(dev_net(dev), -1);
75712 break;
75713 case NETDEV_DOWN:
75714 fib_del_ifaddr(ifa, NULL);
75715 - atomic_inc(&net->ipv4.dev_addr_genid);
75716 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75717 if (ifa->ifa_dev->ifa_list == NULL) {
75718 /* Last address was deleted from this interface.
75719 * Disable IP.
75720 @@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
75721 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75722 fib_sync_up(dev);
75723 #endif
75724 - atomic_inc(&net->ipv4.dev_addr_genid);
75725 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75726 rt_cache_flush(dev_net(dev), -1);
75727 break;
75728 case NETDEV_DOWN:
75729 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
75730 index 80106d8..232e898 100644
75731 --- a/net/ipv4/fib_semantics.c
75732 +++ b/net/ipv4/fib_semantics.c
75733 @@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
75734 nh->nh_saddr = inet_select_addr(nh->nh_dev,
75735 nh->nh_gw,
75736 nh->nh_parent->fib_scope);
75737 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
75738 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
75739
75740 return nh->nh_saddr;
75741 }
75742 diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
75743 index ccee270..db23c3c 100644
75744 --- a/net/ipv4/inet_diag.c
75745 +++ b/net/ipv4/inet_diag.c
75746 @@ -114,8 +114,14 @@ static int inet_csk_diag_fill(struct sock *sk,
75747 r->idiag_retrans = 0;
75748
75749 r->id.idiag_if = sk->sk_bound_dev_if;
75750 +
75751 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75752 + r->id.idiag_cookie[0] = 0;
75753 + r->id.idiag_cookie[1] = 0;
75754 +#else
75755 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
75756 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
75757 +#endif
75758
75759 r->id.idiag_sport = inet->inet_sport;
75760 r->id.idiag_dport = inet->inet_dport;
75761 @@ -210,8 +216,15 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
75762 r->idiag_family = tw->tw_family;
75763 r->idiag_retrans = 0;
75764 r->id.idiag_if = tw->tw_bound_dev_if;
75765 +
75766 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75767 + r->id.idiag_cookie[0] = 0;
75768 + r->id.idiag_cookie[1] = 0;
75769 +#else
75770 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
75771 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
75772 +#endif
75773 +
75774 r->id.idiag_sport = tw->tw_sport;
75775 r->id.idiag_dport = tw->tw_dport;
75776 r->id.idiag_src[0] = tw->tw_rcv_saddr;
75777 @@ -294,12 +307,14 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
75778 if (sk == NULL)
75779 goto unlock;
75780
75781 +#ifndef CONFIG_GRKERNSEC_HIDESYM
75782 err = -ESTALE;
75783 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
75784 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
75785 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
75786 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
75787 goto out;
75788 +#endif
75789
75790 err = -ENOMEM;
75791 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
75792 @@ -589,8 +604,14 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
75793 r->idiag_retrans = req->retrans;
75794
75795 r->id.idiag_if = sk->sk_bound_dev_if;
75796 +
75797 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75798 + r->id.idiag_cookie[0] = 0;
75799 + r->id.idiag_cookie[1] = 0;
75800 +#else
75801 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
75802 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
75803 +#endif
75804
75805 tmo = req->expires - jiffies;
75806 if (tmo < 0)
75807 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
75808 index 984ec65..97ac518 100644
75809 --- a/net/ipv4/inet_hashtables.c
75810 +++ b/net/ipv4/inet_hashtables.c
75811 @@ -18,12 +18,15 @@
75812 #include <linux/sched.h>
75813 #include <linux/slab.h>
75814 #include <linux/wait.h>
75815 +#include <linux/security.h>
75816
75817 #include <net/inet_connection_sock.h>
75818 #include <net/inet_hashtables.h>
75819 #include <net/secure_seq.h>
75820 #include <net/ip.h>
75821
75822 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
75823 +
75824 /*
75825 * Allocate and initialize a new local port bind bucket.
75826 * The bindhash mutex for snum's hash chain must be held here.
75827 @@ -530,6 +533,8 @@ ok:
75828 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
75829 spin_unlock(&head->lock);
75830
75831 + gr_update_task_in_ip_table(current, inet_sk(sk));
75832 +
75833 if (tw) {
75834 inet_twsk_deschedule(tw, death_row);
75835 while (twrefcnt) {
75836 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
75837 index 86f13c67..59a35b5 100644
75838 --- a/net/ipv4/inetpeer.c
75839 +++ b/net/ipv4/inetpeer.c
75840 @@ -436,8 +436,8 @@ relookup:
75841 if (p) {
75842 p->daddr = *daddr;
75843 atomic_set(&p->refcnt, 1);
75844 - atomic_set(&p->rid, 0);
75845 - atomic_set(&p->ip_id_count,
75846 + atomic_set_unchecked(&p->rid, 0);
75847 + atomic_set_unchecked(&p->ip_id_count,
75848 (daddr->family == AF_INET) ?
75849 secure_ip_id(daddr->addr.a4) :
75850 secure_ipv6_id(daddr->addr.a6));
75851 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
75852 index fdaabf2..0ec3205 100644
75853 --- a/net/ipv4/ip_fragment.c
75854 +++ b/net/ipv4/ip_fragment.c
75855 @@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
75856 return 0;
75857
75858 start = qp->rid;
75859 - end = atomic_inc_return(&peer->rid);
75860 + end = atomic_inc_return_unchecked(&peer->rid);
75861 qp->rid = end;
75862
75863 rc = qp->q.fragments && (end - start) > max;
75864 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
75865 index 09ff51b..d3968eb 100644
75866 --- a/net/ipv4/ip_sockglue.c
75867 +++ b/net/ipv4/ip_sockglue.c
75868 @@ -1111,7 +1111,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75869 len = min_t(unsigned int, len, opt->optlen);
75870 if (put_user(len, optlen))
75871 return -EFAULT;
75872 - if (copy_to_user(optval, opt->__data, len))
75873 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
75874 + copy_to_user(optval, opt->__data, len))
75875 return -EFAULT;
75876 return 0;
75877 }
75878 @@ -1239,7 +1240,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75879 if (sk->sk_type != SOCK_STREAM)
75880 return -ENOPROTOOPT;
75881
75882 - msg.msg_control = optval;
75883 + msg.msg_control = (void __force_kernel *)optval;
75884 msg.msg_controllen = len;
75885 msg.msg_flags = flags;
75886
75887 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
75888 index 99ec116..c5628fe 100644
75889 --- a/net/ipv4/ipconfig.c
75890 +++ b/net/ipv4/ipconfig.c
75891 @@ -318,7 +318,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
75892
75893 mm_segment_t oldfs = get_fs();
75894 set_fs(get_ds());
75895 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75896 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75897 set_fs(oldfs);
75898 return res;
75899 }
75900 @@ -329,7 +329,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
75901
75902 mm_segment_t oldfs = get_fs();
75903 set_fs(get_ds());
75904 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75905 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75906 set_fs(oldfs);
75907 return res;
75908 }
75909 @@ -340,7 +340,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
75910
75911 mm_segment_t oldfs = get_fs();
75912 set_fs(get_ds());
75913 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
75914 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
75915 set_fs(oldfs);
75916 return res;
75917 }
75918 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
75919 index fd7a3f6..e5be655 100644
75920 --- a/net/ipv4/netfilter/arp_tables.c
75921 +++ b/net/ipv4/netfilter/arp_tables.c
75922 @@ -984,6 +984,11 @@ static int __do_replace(struct net *net, const char *name,
75923 unsigned int valid_hooks,
75924 struct xt_table_info *newinfo,
75925 unsigned int num_counters,
75926 + void __user *counters_ptr) __size_overflow(5);
75927 +static int __do_replace(struct net *net, const char *name,
75928 + unsigned int valid_hooks,
75929 + struct xt_table_info *newinfo,
75930 + unsigned int num_counters,
75931 void __user *counters_ptr)
75932 {
75933 int ret;
75934 @@ -1104,6 +1109,8 @@ static int do_replace(struct net *net, const void __user *user,
75935 }
75936
75937 static int do_add_counters(struct net *net, const void __user *user,
75938 + unsigned int len, int compat) __size_overflow(3);
75939 +static int do_add_counters(struct net *net, const void __user *user,
75940 unsigned int len, int compat)
75941 {
75942 unsigned int i, curcpu;
75943 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
75944 index 24e556e..a8daf7a 100644
75945 --- a/net/ipv4/netfilter/ip_tables.c
75946 +++ b/net/ipv4/netfilter/ip_tables.c
75947 @@ -1172,6 +1172,10 @@ get_entries(struct net *net, struct ipt_get_entries __user *uptr,
75948 static int
75949 __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
75950 struct xt_table_info *newinfo, unsigned int num_counters,
75951 + void __user *counters_ptr) __size_overflow(5);
75952 +static int
75953 +__do_replace(struct net *net, const char *name, unsigned int valid_hooks,
75954 + struct xt_table_info *newinfo, unsigned int num_counters,
75955 void __user *counters_ptr)
75956 {
75957 int ret;
75958 @@ -1293,6 +1297,9 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
75959
75960 static int
75961 do_add_counters(struct net *net, const void __user *user,
75962 + unsigned int len, int compat) __size_overflow(3);
75963 +static int
75964 +do_add_counters(struct net *net, const void __user *user,
75965 unsigned int len, int compat)
75966 {
75967 unsigned int i, curcpu;
75968 diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
75969 index 2133c30..0e8047e 100644
75970 --- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
75971 +++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
75972 @@ -435,6 +435,10 @@ static unsigned char asn1_subid_decode(struct asn1_ctx *ctx,
75973 static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
75974 unsigned char *eoc,
75975 unsigned long **oid,
75976 + unsigned int *len) __size_overflow(2);
75977 +static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
75978 + unsigned char *eoc,
75979 + unsigned long **oid,
75980 unsigned int *len)
75981 {
75982 unsigned long subid;
75983 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
75984 index 43d4c3b..1914409 100644
75985 --- a/net/ipv4/ping.c
75986 +++ b/net/ipv4/ping.c
75987 @@ -836,7 +836,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
75988 sk_rmem_alloc_get(sp),
75989 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75990 atomic_read(&sp->sk_refcnt), sp,
75991 - atomic_read(&sp->sk_drops), len);
75992 + atomic_read_unchecked(&sp->sk_drops), len);
75993 }
75994
75995 static int ping_seq_show(struct seq_file *seq, void *v)
75996 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
75997 index 007e2eb..85a18a0 100644
75998 --- a/net/ipv4/raw.c
75999 +++ b/net/ipv4/raw.c
76000 @@ -303,7 +303,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
76001 int raw_rcv(struct sock *sk, struct sk_buff *skb)
76002 {
76003 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
76004 - atomic_inc(&sk->sk_drops);
76005 + atomic_inc_unchecked(&sk->sk_drops);
76006 kfree_skb(skb);
76007 return NET_RX_DROP;
76008 }
76009 @@ -738,16 +738,20 @@ static int raw_init(struct sock *sk)
76010
76011 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76012 {
76013 + struct icmp_filter filter;
76014 +
76015 if (optlen > sizeof(struct icmp_filter))
76016 optlen = sizeof(struct icmp_filter);
76017 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
76018 + if (copy_from_user(&filter, optval, optlen))
76019 return -EFAULT;
76020 + raw_sk(sk)->filter = filter;
76021 return 0;
76022 }
76023
76024 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76025 {
76026 int len, ret = -EFAULT;
76027 + struct icmp_filter filter;
76028
76029 if (get_user(len, optlen))
76030 goto out;
76031 @@ -757,8 +761,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
76032 if (len > sizeof(struct icmp_filter))
76033 len = sizeof(struct icmp_filter);
76034 ret = -EFAULT;
76035 - if (put_user(len, optlen) ||
76036 - copy_to_user(optval, &raw_sk(sk)->filter, len))
76037 + filter = raw_sk(sk)->filter;
76038 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
76039 goto out;
76040 ret = 0;
76041 out: return ret;
76042 @@ -986,7 +990,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76043 sk_wmem_alloc_get(sp),
76044 sk_rmem_alloc_get(sp),
76045 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76046 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76047 + atomic_read(&sp->sk_refcnt),
76048 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76049 + NULL,
76050 +#else
76051 + sp,
76052 +#endif
76053 + atomic_read_unchecked(&sp->sk_drops));
76054 }
76055
76056 static int raw_seq_show(struct seq_file *seq, void *v)
76057 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
76058 index 94cdbc5..0cb0063 100644
76059 --- a/net/ipv4/route.c
76060 +++ b/net/ipv4/route.c
76061 @@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
76062
76063 static inline int rt_genid(struct net *net)
76064 {
76065 - return atomic_read(&net->ipv4.rt_genid);
76066 + return atomic_read_unchecked(&net->ipv4.rt_genid);
76067 }
76068
76069 #ifdef CONFIG_PROC_FS
76070 @@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
76071 unsigned char shuffle;
76072
76073 get_random_bytes(&shuffle, sizeof(shuffle));
76074 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76075 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76076 redirect_genid++;
76077 }
76078
76079 @@ -3022,7 +3022,7 @@ static int rt_fill_info(struct net *net,
76080 error = rt->dst.error;
76081 if (peer) {
76082 inet_peer_refcheck(rt->peer);
76083 - id = atomic_read(&peer->ip_id_count) & 0xffff;
76084 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
76085 if (peer->tcp_ts_stamp) {
76086 ts = peer->tcp_ts;
76087 tsage = get_seconds() - peer->tcp_ts_stamp;
76088 diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
76089 index 90f6544..769c0e9 100644
76090 --- a/net/ipv4/syncookies.c
76091 +++ b/net/ipv4/syncookies.c
76092 @@ -278,6 +278,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
76093 struct rtable *rt;
76094 __u8 rcv_wscale;
76095 bool ecn_ok = false;
76096 + struct flowi4 fl4;
76097
76098 if (!sysctl_tcp_syncookies || !th->ack || th->rst)
76099 goto out;
76100 @@ -346,20 +347,16 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
76101 * hasn't changed since we received the original syn, but I see
76102 * no easy way to do this.
76103 */
76104 - {
76105 - struct flowi4 fl4;
76106 -
76107 - flowi4_init_output(&fl4, 0, sk->sk_mark, RT_CONN_FLAGS(sk),
76108 - RT_SCOPE_UNIVERSE, IPPROTO_TCP,
76109 - inet_sk_flowi_flags(sk),
76110 - (opt && opt->srr) ? opt->faddr : ireq->rmt_addr,
76111 - ireq->loc_addr, th->source, th->dest);
76112 - security_req_classify_flow(req, flowi4_to_flowi(&fl4));
76113 - rt = ip_route_output_key(sock_net(sk), &fl4);
76114 - if (IS_ERR(rt)) {
76115 - reqsk_free(req);
76116 - goto out;
76117 - }
76118 + flowi4_init_output(&fl4, 0, sk->sk_mark, RT_CONN_FLAGS(sk),
76119 + RT_SCOPE_UNIVERSE, IPPROTO_TCP,
76120 + inet_sk_flowi_flags(sk),
76121 + (opt && opt->srr) ? opt->faddr : ireq->rmt_addr,
76122 + ireq->loc_addr, th->source, th->dest);
76123 + security_req_classify_flow(req, flowi4_to_flowi(&fl4));
76124 + rt = ip_route_output_key(sock_net(sk), &fl4);
76125 + if (IS_ERR(rt)) {
76126 + reqsk_free(req);
76127 + goto out;
76128 }
76129
76130 /* Try to redo what tcp_v4_send_synack did. */
76131 @@ -373,5 +370,10 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
76132 ireq->rcv_wscale = rcv_wscale;
76133
76134 ret = get_cookie_sock(sk, skb, req, &rt->dst);
76135 + /* ip_queue_xmit() depends on our flow being setup
76136 + * Normal sockets get it right from inet_csk_route_child_sock()
76137 + */
76138 + if (ret)
76139 + inet_sk(ret)->cork.fl.u.ip4 = fl4;
76140 out: return ret;
76141 }
76142 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
76143 index eb90aa8..74908e1 100644
76144 --- a/net/ipv4/tcp_ipv4.c
76145 +++ b/net/ipv4/tcp_ipv4.c
76146 @@ -87,6 +87,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
76147 int sysctl_tcp_low_latency __read_mostly;
76148 EXPORT_SYMBOL(sysctl_tcp_low_latency);
76149
76150 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76151 +extern int grsec_enable_blackhole;
76152 +#endif
76153
76154 #ifdef CONFIG_TCP_MD5SIG
76155 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
76156 @@ -1465,9 +1468,13 @@ struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
76157 inet_csk(newsk)->icsk_ext_hdr_len = inet_opt->opt.optlen;
76158 newinet->inet_id = newtp->write_seq ^ jiffies;
76159
76160 - if (!dst && (dst = inet_csk_route_child_sock(sk, newsk, req)) == NULL)
76161 - goto put_and_exit;
76162 -
76163 + if (!dst) {
76164 + dst = inet_csk_route_child_sock(sk, newsk, req);
76165 + if (!dst)
76166 + goto put_and_exit;
76167 + } else {
76168 + /* syncookie case : see end of cookie_v4_check() */
76169 + }
76170 sk_setup_caps(newsk, dst);
76171
76172 tcp_mtup_init(newsk);
76173 @@ -1632,6 +1639,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
76174 return 0;
76175
76176 reset:
76177 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76178 + if (!grsec_enable_blackhole)
76179 +#endif
76180 tcp_v4_send_reset(rsk, skb);
76181 discard:
76182 kfree_skb(skb);
76183 @@ -1694,12 +1704,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
76184 TCP_SKB_CB(skb)->sacked = 0;
76185
76186 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76187 - if (!sk)
76188 + if (!sk) {
76189 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76190 + ret = 1;
76191 +#endif
76192 goto no_tcp_socket;
76193 -
76194 + }
76195 process:
76196 - if (sk->sk_state == TCP_TIME_WAIT)
76197 + if (sk->sk_state == TCP_TIME_WAIT) {
76198 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76199 + ret = 2;
76200 +#endif
76201 goto do_time_wait;
76202 + }
76203
76204 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
76205 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76206 @@ -1749,6 +1766,10 @@ no_tcp_socket:
76207 bad_packet:
76208 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76209 } else {
76210 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76211 + if (!grsec_enable_blackhole || (ret == 1 &&
76212 + (skb->dev->flags & IFF_LOOPBACK)))
76213 +#endif
76214 tcp_v4_send_reset(NULL, skb);
76215 }
76216
76217 @@ -2409,7 +2430,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
76218 0, /* non standard timer */
76219 0, /* open_requests have no inode */
76220 atomic_read(&sk->sk_refcnt),
76221 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76222 + NULL,
76223 +#else
76224 req,
76225 +#endif
76226 len);
76227 }
76228
76229 @@ -2459,7 +2484,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
76230 sock_i_uid(sk),
76231 icsk->icsk_probes_out,
76232 sock_i_ino(sk),
76233 - atomic_read(&sk->sk_refcnt), sk,
76234 + atomic_read(&sk->sk_refcnt),
76235 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76236 + NULL,
76237 +#else
76238 + sk,
76239 +#endif
76240 jiffies_to_clock_t(icsk->icsk_rto),
76241 jiffies_to_clock_t(icsk->icsk_ack.ato),
76242 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76243 @@ -2487,7 +2517,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
76244 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
76245 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76246 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76247 - atomic_read(&tw->tw_refcnt), tw, len);
76248 + atomic_read(&tw->tw_refcnt),
76249 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76250 + NULL,
76251 +#else
76252 + tw,
76253 +#endif
76254 + len);
76255 }
76256
76257 #define TMPSZ 150
76258 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
76259 index 66363b6..b0654a3 100644
76260 --- a/net/ipv4/tcp_minisocks.c
76261 +++ b/net/ipv4/tcp_minisocks.c
76262 @@ -27,6 +27,10 @@
76263 #include <net/inet_common.h>
76264 #include <net/xfrm.h>
76265
76266 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76267 +extern int grsec_enable_blackhole;
76268 +#endif
76269 +
76270 int sysctl_tcp_syncookies __read_mostly = 1;
76271 EXPORT_SYMBOL(sysctl_tcp_syncookies);
76272
76273 @@ -751,6 +755,10 @@ listen_overflow:
76274
76275 embryonic_reset:
76276 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76277 +
76278 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76279 + if (!grsec_enable_blackhole)
76280 +#endif
76281 if (!(flg & TCP_FLAG_RST))
76282 req->rsk_ops->send_reset(sk, skb);
76283
76284 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
76285 index 85ee7eb..53277ab 100644
76286 --- a/net/ipv4/tcp_probe.c
76287 +++ b/net/ipv4/tcp_probe.c
76288 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
76289 if (cnt + width >= len)
76290 break;
76291
76292 - if (copy_to_user(buf + cnt, tbuf, width))
76293 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76294 return -EFAULT;
76295 cnt += width;
76296 }
76297 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
76298 index 2e0f0af..e2948bf 100644
76299 --- a/net/ipv4/tcp_timer.c
76300 +++ b/net/ipv4/tcp_timer.c
76301 @@ -22,6 +22,10 @@
76302 #include <linux/gfp.h>
76303 #include <net/tcp.h>
76304
76305 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76306 +extern int grsec_lastack_retries;
76307 +#endif
76308 +
76309 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76310 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76311 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76312 @@ -199,6 +203,13 @@ static int tcp_write_timeout(struct sock *sk)
76313 }
76314 }
76315
76316 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76317 + if ((sk->sk_state == TCP_LAST_ACK) &&
76318 + (grsec_lastack_retries > 0) &&
76319 + (grsec_lastack_retries < retry_until))
76320 + retry_until = grsec_lastack_retries;
76321 +#endif
76322 +
76323 if (retransmits_timed_out(sk, retry_until,
76324 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
76325 /* Has it gone just too far? */
76326 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
76327 index 5a65eea..bd913a1 100644
76328 --- a/net/ipv4/udp.c
76329 +++ b/net/ipv4/udp.c
76330 @@ -86,6 +86,7 @@
76331 #include <linux/types.h>
76332 #include <linux/fcntl.h>
76333 #include <linux/module.h>
76334 +#include <linux/security.h>
76335 #include <linux/socket.h>
76336 #include <linux/sockios.h>
76337 #include <linux/igmp.h>
76338 @@ -108,6 +109,10 @@
76339 #include <trace/events/udp.h>
76340 #include "udp_impl.h"
76341
76342 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76343 +extern int grsec_enable_blackhole;
76344 +#endif
76345 +
76346 struct udp_table udp_table __read_mostly;
76347 EXPORT_SYMBOL(udp_table);
76348
76349 @@ -565,6 +570,9 @@ found:
76350 return s;
76351 }
76352
76353 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76354 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76355 +
76356 /*
76357 * This routine is called by the ICMP module when it gets some
76358 * sort of error condition. If err < 0 then the socket should
76359 @@ -856,9 +864,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
76360 dport = usin->sin_port;
76361 if (dport == 0)
76362 return -EINVAL;
76363 +
76364 + err = gr_search_udp_sendmsg(sk, usin);
76365 + if (err)
76366 + return err;
76367 } else {
76368 if (sk->sk_state != TCP_ESTABLISHED)
76369 return -EDESTADDRREQ;
76370 +
76371 + err = gr_search_udp_sendmsg(sk, NULL);
76372 + if (err)
76373 + return err;
76374 +
76375 daddr = inet->inet_daddr;
76376 dport = inet->inet_dport;
76377 /* Open fast path for connected socket.
76378 @@ -1099,7 +1116,7 @@ static unsigned int first_packet_length(struct sock *sk)
76379 udp_lib_checksum_complete(skb)) {
76380 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76381 IS_UDPLITE(sk));
76382 - atomic_inc(&sk->sk_drops);
76383 + atomic_inc_unchecked(&sk->sk_drops);
76384 __skb_unlink(skb, rcvq);
76385 __skb_queue_tail(&list_kill, skb);
76386 }
76387 @@ -1185,6 +1202,10 @@ try_again:
76388 if (!skb)
76389 goto out;
76390
76391 + err = gr_search_udp_recvmsg(sk, skb);
76392 + if (err)
76393 + goto out_free;
76394 +
76395 ulen = skb->len - sizeof(struct udphdr);
76396 copied = len;
76397 if (copied > ulen)
76398 @@ -1487,7 +1508,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76399
76400 drop:
76401 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76402 - atomic_inc(&sk->sk_drops);
76403 + atomic_inc_unchecked(&sk->sk_drops);
76404 kfree_skb(skb);
76405 return -1;
76406 }
76407 @@ -1506,7 +1527,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76408 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76409
76410 if (!skb1) {
76411 - atomic_inc(&sk->sk_drops);
76412 + atomic_inc_unchecked(&sk->sk_drops);
76413 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76414 IS_UDPLITE(sk));
76415 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76416 @@ -1675,6 +1696,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76417 goto csum_error;
76418
76419 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76420 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76421 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76422 +#endif
76423 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76424
76425 /*
76426 @@ -2098,8 +2122,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
76427 sk_wmem_alloc_get(sp),
76428 sk_rmem_alloc_get(sp),
76429 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76430 - atomic_read(&sp->sk_refcnt), sp,
76431 - atomic_read(&sp->sk_drops), len);
76432 + atomic_read(&sp->sk_refcnt),
76433 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76434 + NULL,
76435 +#else
76436 + sp,
76437 +#endif
76438 + atomic_read_unchecked(&sp->sk_drops), len);
76439 }
76440
76441 int udp4_seq_show(struct seq_file *seq, void *v)
76442 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
76443 index a5521c5..984a2f4 100644
76444 --- a/net/ipv6/addrconf.c
76445 +++ b/net/ipv6/addrconf.c
76446 @@ -2153,7 +2153,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
76447 p.iph.ihl = 5;
76448 p.iph.protocol = IPPROTO_IPV6;
76449 p.iph.ttl = 64;
76450 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
76451 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
76452
76453 if (ops->ndo_do_ioctl) {
76454 mm_segment_t oldfs = get_fs();
76455 diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c
76456 index 4c0f894..fca5d15 100644
76457 --- a/net/ipv6/ah6.c
76458 +++ b/net/ipv6/ah6.c
76459 @@ -56,6 +56,8 @@ struct ah_skb_cb {
76460 #define AH_SKB_CB(__skb) ((struct ah_skb_cb *)&((__skb)->cb[0]))
76461
76462 static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
76463 + unsigned int size) __size_overflow(3);
76464 +static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
76465 unsigned int size)
76466 {
76467 unsigned int len;
76468 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
76469 index 1567fb1..29af910 100644
76470 --- a/net/ipv6/inet6_connection_sock.c
76471 +++ b/net/ipv6/inet6_connection_sock.c
76472 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
76473 #ifdef CONFIG_XFRM
76474 {
76475 struct rt6_info *rt = (struct rt6_info *)dst;
76476 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76477 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76478 }
76479 #endif
76480 }
76481 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
76482 #ifdef CONFIG_XFRM
76483 if (dst) {
76484 struct rt6_info *rt = (struct rt6_info *)dst;
76485 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76486 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76487 __sk_dst_reset(sk);
76488 dst = NULL;
76489 }
76490 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
76491 index 26cb08c..8af9877 100644
76492 --- a/net/ipv6/ipv6_sockglue.c
76493 +++ b/net/ipv6/ipv6_sockglue.c
76494 @@ -960,7 +960,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76495 if (sk->sk_type != SOCK_STREAM)
76496 return -ENOPROTOOPT;
76497
76498 - msg.msg_control = optval;
76499 + msg.msg_control = (void __force_kernel *)optval;
76500 msg.msg_controllen = len;
76501 msg.msg_flags = flags;
76502
76503 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
76504 index 94874b0..dc413fa 100644
76505 --- a/net/ipv6/netfilter/ip6_tables.c
76506 +++ b/net/ipv6/netfilter/ip6_tables.c
76507 @@ -1194,6 +1194,10 @@ get_entries(struct net *net, struct ip6t_get_entries __user *uptr,
76508 static int
76509 __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
76510 struct xt_table_info *newinfo, unsigned int num_counters,
76511 + void __user *counters_ptr) __size_overflow(5);
76512 +static int
76513 +__do_replace(struct net *net, const char *name, unsigned int valid_hooks,
76514 + struct xt_table_info *newinfo, unsigned int num_counters,
76515 void __user *counters_ptr)
76516 {
76517 int ret;
76518 @@ -1315,6 +1319,9 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
76519
76520 static int
76521 do_add_counters(struct net *net, const void __user *user, unsigned int len,
76522 + int compat) __size_overflow(3);
76523 +static int
76524 +do_add_counters(struct net *net, const void __user *user, unsigned int len,
76525 int compat)
76526 {
76527 unsigned int i, curcpu;
76528 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76529 index 361ebf3..d5628fb 100644
76530 --- a/net/ipv6/raw.c
76531 +++ b/net/ipv6/raw.c
76532 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
76533 {
76534 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
76535 skb_checksum_complete(skb)) {
76536 - atomic_inc(&sk->sk_drops);
76537 + atomic_inc_unchecked(&sk->sk_drops);
76538 kfree_skb(skb);
76539 return NET_RX_DROP;
76540 }
76541 @@ -404,7 +404,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76542 struct raw6_sock *rp = raw6_sk(sk);
76543
76544 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76545 - atomic_inc(&sk->sk_drops);
76546 + atomic_inc_unchecked(&sk->sk_drops);
76547 kfree_skb(skb);
76548 return NET_RX_DROP;
76549 }
76550 @@ -428,7 +428,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76551
76552 if (inet->hdrincl) {
76553 if (skb_checksum_complete(skb)) {
76554 - atomic_inc(&sk->sk_drops);
76555 + atomic_inc_unchecked(&sk->sk_drops);
76556 kfree_skb(skb);
76557 return NET_RX_DROP;
76558 }
76559 @@ -601,7 +601,7 @@ out:
76560 return err;
76561 }
76562
76563 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76564 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76565 struct flowi6 *fl6, struct dst_entry **dstp,
76566 unsigned int flags)
76567 {
76568 @@ -909,12 +909,15 @@ do_confirm:
76569 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76570 char __user *optval, int optlen)
76571 {
76572 + struct icmp6_filter filter;
76573 +
76574 switch (optname) {
76575 case ICMPV6_FILTER:
76576 if (optlen > sizeof(struct icmp6_filter))
76577 optlen = sizeof(struct icmp6_filter);
76578 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76579 + if (copy_from_user(&filter, optval, optlen))
76580 return -EFAULT;
76581 + raw6_sk(sk)->filter = filter;
76582 return 0;
76583 default:
76584 return -ENOPROTOOPT;
76585 @@ -927,6 +930,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76586 char __user *optval, int __user *optlen)
76587 {
76588 int len;
76589 + struct icmp6_filter filter;
76590
76591 switch (optname) {
76592 case ICMPV6_FILTER:
76593 @@ -938,7 +942,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76594 len = sizeof(struct icmp6_filter);
76595 if (put_user(len, optlen))
76596 return -EFAULT;
76597 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76598 + filter = raw6_sk(sk)->filter;
76599 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
76600 return -EFAULT;
76601 return 0;
76602 default:
76603 @@ -1245,7 +1250,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76604 0, 0L, 0,
76605 sock_i_uid(sp), 0,
76606 sock_i_ino(sp),
76607 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76608 + atomic_read(&sp->sk_refcnt),
76609 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76610 + NULL,
76611 +#else
76612 + sp,
76613 +#endif
76614 + atomic_read_unchecked(&sp->sk_drops));
76615 }
76616
76617 static int raw6_seq_show(struct seq_file *seq, void *v)
76618 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76619 index b859e4a..f9d1589 100644
76620 --- a/net/ipv6/tcp_ipv6.c
76621 +++ b/net/ipv6/tcp_ipv6.c
76622 @@ -93,6 +93,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76623 }
76624 #endif
76625
76626 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76627 +extern int grsec_enable_blackhole;
76628 +#endif
76629 +
76630 static void tcp_v6_hash(struct sock *sk)
76631 {
76632 if (sk->sk_state != TCP_CLOSE) {
76633 @@ -1651,6 +1655,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76634 return 0;
76635
76636 reset:
76637 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76638 + if (!grsec_enable_blackhole)
76639 +#endif
76640 tcp_v6_send_reset(sk, skb);
76641 discard:
76642 if (opt_skb)
76643 @@ -1730,12 +1737,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76644 TCP_SKB_CB(skb)->sacked = 0;
76645
76646 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76647 - if (!sk)
76648 + if (!sk) {
76649 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76650 + ret = 1;
76651 +#endif
76652 goto no_tcp_socket;
76653 + }
76654
76655 process:
76656 - if (sk->sk_state == TCP_TIME_WAIT)
76657 + if (sk->sk_state == TCP_TIME_WAIT) {
76658 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76659 + ret = 2;
76660 +#endif
76661 goto do_time_wait;
76662 + }
76663
76664 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76665 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76666 @@ -1783,6 +1798,10 @@ no_tcp_socket:
76667 bad_packet:
76668 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76669 } else {
76670 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76671 + if (!grsec_enable_blackhole || (ret == 1 &&
76672 + (skb->dev->flags & IFF_LOOPBACK)))
76673 +#endif
76674 tcp_v6_send_reset(NULL, skb);
76675 }
76676
76677 @@ -2043,7 +2062,13 @@ static void get_openreq6(struct seq_file *seq,
76678 uid,
76679 0, /* non standard timer */
76680 0, /* open_requests have no inode */
76681 - 0, req);
76682 + 0,
76683 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76684 + NULL
76685 +#else
76686 + req
76687 +#endif
76688 + );
76689 }
76690
76691 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76692 @@ -2093,7 +2118,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76693 sock_i_uid(sp),
76694 icsk->icsk_probes_out,
76695 sock_i_ino(sp),
76696 - atomic_read(&sp->sk_refcnt), sp,
76697 + atomic_read(&sp->sk_refcnt),
76698 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76699 + NULL,
76700 +#else
76701 + sp,
76702 +#endif
76703 jiffies_to_clock_t(icsk->icsk_rto),
76704 jiffies_to_clock_t(icsk->icsk_ack.ato),
76705 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76706 @@ -2128,7 +2158,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76707 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76708 tw->tw_substate, 0, 0,
76709 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76710 - atomic_read(&tw->tw_refcnt), tw);
76711 + atomic_read(&tw->tw_refcnt),
76712 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76713 + NULL
76714 +#else
76715 + tw
76716 +#endif
76717 + );
76718 }
76719
76720 static int tcp6_seq_show(struct seq_file *seq, void *v)
76721 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76722 index 8c25419..47a51ae 100644
76723 --- a/net/ipv6/udp.c
76724 +++ b/net/ipv6/udp.c
76725 @@ -50,6 +50,10 @@
76726 #include <linux/seq_file.h>
76727 #include "udp_impl.h"
76728
76729 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76730 +extern int grsec_enable_blackhole;
76731 +#endif
76732 +
76733 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76734 {
76735 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76736 @@ -549,7 +553,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
76737
76738 return 0;
76739 drop:
76740 - atomic_inc(&sk->sk_drops);
76741 + atomic_inc_unchecked(&sk->sk_drops);
76742 drop_no_sk_drops_inc:
76743 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76744 kfree_skb(skb);
76745 @@ -625,7 +629,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76746 continue;
76747 }
76748 drop:
76749 - atomic_inc(&sk->sk_drops);
76750 + atomic_inc_unchecked(&sk->sk_drops);
76751 UDP6_INC_STATS_BH(sock_net(sk),
76752 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
76753 UDP6_INC_STATS_BH(sock_net(sk),
76754 @@ -780,6 +784,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76755 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
76756 proto == IPPROTO_UDPLITE);
76757
76758 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76759 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76760 +#endif
76761 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76762
76763 kfree_skb(skb);
76764 @@ -796,7 +803,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76765 if (!sock_owned_by_user(sk))
76766 udpv6_queue_rcv_skb(sk, skb);
76767 else if (sk_add_backlog(sk, skb)) {
76768 - atomic_inc(&sk->sk_drops);
76769 + atomic_inc_unchecked(&sk->sk_drops);
76770 bh_unlock_sock(sk);
76771 sock_put(sk);
76772 goto discard;
76773 @@ -1407,8 +1414,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
76774 0, 0L, 0,
76775 sock_i_uid(sp), 0,
76776 sock_i_ino(sp),
76777 - atomic_read(&sp->sk_refcnt), sp,
76778 - atomic_read(&sp->sk_drops));
76779 + atomic_read(&sp->sk_refcnt),
76780 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76781 + NULL,
76782 +#else
76783 + sp,
76784 +#endif
76785 + atomic_read_unchecked(&sp->sk_drops));
76786 }
76787
76788 int udp6_seq_show(struct seq_file *seq, void *v)
76789 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
76790 index 253695d..9481ce8 100644
76791 --- a/net/irda/ircomm/ircomm_tty.c
76792 +++ b/net/irda/ircomm/ircomm_tty.c
76793 @@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76794 add_wait_queue(&self->open_wait, &wait);
76795
76796 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76797 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76798 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76799
76800 /* As far as I can see, we protect open_count - Jean II */
76801 spin_lock_irqsave(&self->spinlock, flags);
76802 if (!tty_hung_up_p(filp)) {
76803 extra_count = 1;
76804 - self->open_count--;
76805 + local_dec(&self->open_count);
76806 }
76807 spin_unlock_irqrestore(&self->spinlock, flags);
76808 - self->blocked_open++;
76809 + local_inc(&self->blocked_open);
76810
76811 while (1) {
76812 if (tty->termios->c_cflag & CBAUD) {
76813 @@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76814 }
76815
76816 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76817 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76818 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76819
76820 schedule();
76821 }
76822 @@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76823 if (extra_count) {
76824 /* ++ is not atomic, so this should be protected - Jean II */
76825 spin_lock_irqsave(&self->spinlock, flags);
76826 - self->open_count++;
76827 + local_inc(&self->open_count);
76828 spin_unlock_irqrestore(&self->spinlock, flags);
76829 }
76830 - self->blocked_open--;
76831 + local_dec(&self->blocked_open);
76832
76833 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76834 - __FILE__,__LINE__, tty->driver->name, self->open_count);
76835 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76836
76837 if (!retval)
76838 self->flags |= ASYNC_NORMAL_ACTIVE;
76839 @@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
76840 }
76841 /* ++ is not atomic, so this should be protected - Jean II */
76842 spin_lock_irqsave(&self->spinlock, flags);
76843 - self->open_count++;
76844 + local_inc(&self->open_count);
76845
76846 tty->driver_data = self;
76847 self->tty = tty;
76848 spin_unlock_irqrestore(&self->spinlock, flags);
76849
76850 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
76851 - self->line, self->open_count);
76852 + self->line, local_read(&self->open_count));
76853
76854 /* Not really used by us, but lets do it anyway */
76855 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
76856 @@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76857 return;
76858 }
76859
76860 - if ((tty->count == 1) && (self->open_count != 1)) {
76861 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
76862 /*
76863 * Uh, oh. tty->count is 1, which means that the tty
76864 * structure will be freed. state->count should always
76865 @@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76866 */
76867 IRDA_DEBUG(0, "%s(), bad serial port count; "
76868 "tty->count is 1, state->count is %d\n", __func__ ,
76869 - self->open_count);
76870 - self->open_count = 1;
76871 + local_read(&self->open_count));
76872 + local_set(&self->open_count, 1);
76873 }
76874
76875 - if (--self->open_count < 0) {
76876 + if (local_dec_return(&self->open_count) < 0) {
76877 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
76878 - __func__, self->line, self->open_count);
76879 - self->open_count = 0;
76880 + __func__, self->line, local_read(&self->open_count));
76881 + local_set(&self->open_count, 0);
76882 }
76883 - if (self->open_count) {
76884 + if (local_read(&self->open_count)) {
76885 spin_unlock_irqrestore(&self->spinlock, flags);
76886
76887 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
76888 @@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76889 tty->closing = 0;
76890 self->tty = NULL;
76891
76892 - if (self->blocked_open) {
76893 + if (local_read(&self->blocked_open)) {
76894 if (self->close_delay)
76895 schedule_timeout_interruptible(self->close_delay);
76896 wake_up_interruptible(&self->open_wait);
76897 @@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
76898 spin_lock_irqsave(&self->spinlock, flags);
76899 self->flags &= ~ASYNC_NORMAL_ACTIVE;
76900 self->tty = NULL;
76901 - self->open_count = 0;
76902 + local_set(&self->open_count, 0);
76903 spin_unlock_irqrestore(&self->spinlock, flags);
76904
76905 wake_up_interruptible(&self->open_wait);
76906 @@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
76907 seq_putc(m, '\n');
76908
76909 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
76910 - seq_printf(m, "Open count: %d\n", self->open_count);
76911 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
76912 seq_printf(m, "Max data size: %d\n", self->max_data_size);
76913 seq_printf(m, "Max header size: %d\n", self->max_header_size);
76914
76915 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
76916 index 274d150..656a144 100644
76917 --- a/net/iucv/af_iucv.c
76918 +++ b/net/iucv/af_iucv.c
76919 @@ -787,10 +787,10 @@ static int iucv_sock_autobind(struct sock *sk)
76920
76921 write_lock_bh(&iucv_sk_list.lock);
76922
76923 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
76924 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76925 while (__iucv_get_sock_by_name(name)) {
76926 sprintf(name, "%08x",
76927 - atomic_inc_return(&iucv_sk_list.autobind_name));
76928 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76929 }
76930
76931 write_unlock_bh(&iucv_sk_list.lock);
76932 diff --git a/net/key/af_key.c b/net/key/af_key.c
76933 index 1e733e9..3d73c9f 100644
76934 --- a/net/key/af_key.c
76935 +++ b/net/key/af_key.c
76936 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
76937 static u32 get_acqseq(void)
76938 {
76939 u32 res;
76940 - static atomic_t acqseq;
76941 + static atomic_unchecked_t acqseq;
76942
76943 do {
76944 - res = atomic_inc_return(&acqseq);
76945 + res = atomic_inc_return_unchecked(&acqseq);
76946 } while (!res);
76947 return res;
76948 }
76949 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
76950 index 73495f1..ad51356 100644
76951 --- a/net/mac80211/ieee80211_i.h
76952 +++ b/net/mac80211/ieee80211_i.h
76953 @@ -27,6 +27,7 @@
76954 #include <net/ieee80211_radiotap.h>
76955 #include <net/cfg80211.h>
76956 #include <net/mac80211.h>
76957 +#include <asm/local.h>
76958 #include "key.h"
76959 #include "sta_info.h"
76960
76961 @@ -764,7 +765,7 @@ struct ieee80211_local {
76962 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
76963 spinlock_t queue_stop_reason_lock;
76964
76965 - int open_count;
76966 + local_t open_count;
76967 int monitors, cooked_mntrs;
76968 /* number of interfaces with corresponding FIF_ flags */
76969 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
76970 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
76971 index 30d7355..e260095 100644
76972 --- a/net/mac80211/iface.c
76973 +++ b/net/mac80211/iface.c
76974 @@ -211,7 +211,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76975 break;
76976 }
76977
76978 - if (local->open_count == 0) {
76979 + if (local_read(&local->open_count) == 0) {
76980 res = drv_start(local);
76981 if (res)
76982 goto err_del_bss;
76983 @@ -235,7 +235,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76984 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
76985
76986 if (!is_valid_ether_addr(dev->dev_addr)) {
76987 - if (!local->open_count)
76988 + if (!local_read(&local->open_count))
76989 drv_stop(local);
76990 return -EADDRNOTAVAIL;
76991 }
76992 @@ -327,7 +327,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76993 mutex_unlock(&local->mtx);
76994
76995 if (coming_up)
76996 - local->open_count++;
76997 + local_inc(&local->open_count);
76998
76999 if (hw_reconf_flags) {
77000 ieee80211_hw_config(local, hw_reconf_flags);
77001 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77002 err_del_interface:
77003 drv_remove_interface(local, &sdata->vif);
77004 err_stop:
77005 - if (!local->open_count)
77006 + if (!local_read(&local->open_count))
77007 drv_stop(local);
77008 err_del_bss:
77009 sdata->bss = NULL;
77010 @@ -472,7 +472,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77011 }
77012
77013 if (going_down)
77014 - local->open_count--;
77015 + local_dec(&local->open_count);
77016
77017 switch (sdata->vif.type) {
77018 case NL80211_IFTYPE_AP_VLAN:
77019 @@ -531,7 +531,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77020
77021 ieee80211_recalc_ps(local, -1);
77022
77023 - if (local->open_count == 0) {
77024 + if (local_read(&local->open_count) == 0) {
77025 if (local->ops->napi_poll)
77026 napi_disable(&local->napi);
77027 ieee80211_clear_tx_pending(local);
77028 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
77029 index 7d9b21d..0687004 100644
77030 --- a/net/mac80211/main.c
77031 +++ b/net/mac80211/main.c
77032 @@ -163,7 +163,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
77033 local->hw.conf.power_level = power;
77034 }
77035
77036 - if (changed && local->open_count) {
77037 + if (changed && local_read(&local->open_count)) {
77038 ret = drv_config(local, changed);
77039 /*
77040 * Goal:
77041 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
77042 index 9ee7164..56c5061 100644
77043 --- a/net/mac80211/pm.c
77044 +++ b/net/mac80211/pm.c
77045 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77046 struct ieee80211_sub_if_data *sdata;
77047 struct sta_info *sta;
77048
77049 - if (!local->open_count)
77050 + if (!local_read(&local->open_count))
77051 goto suspend;
77052
77053 ieee80211_scan_cancel(local);
77054 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77055 cancel_work_sync(&local->dynamic_ps_enable_work);
77056 del_timer_sync(&local->dynamic_ps_timer);
77057
77058 - local->wowlan = wowlan && local->open_count;
77059 + local->wowlan = wowlan && local_read(&local->open_count);
77060 if (local->wowlan) {
77061 int err = drv_suspend(local, wowlan);
77062 if (err < 0) {
77063 @@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77064 }
77065
77066 /* stop hardware - this must stop RX */
77067 - if (local->open_count)
77068 + if (local_read(&local->open_count))
77069 ieee80211_stop_device(local);
77070
77071 suspend:
77072 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
77073 index 7d84b87..6a69cd9 100644
77074 --- a/net/mac80211/rate.c
77075 +++ b/net/mac80211/rate.c
77076 @@ -401,7 +401,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
77077
77078 ASSERT_RTNL();
77079
77080 - if (local->open_count)
77081 + if (local_read(&local->open_count))
77082 return -EBUSY;
77083
77084 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
77085 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
77086 index c97a065..ff61928 100644
77087 --- a/net/mac80211/rc80211_pid_debugfs.c
77088 +++ b/net/mac80211/rc80211_pid_debugfs.c
77089 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
77090
77091 spin_unlock_irqrestore(&events->lock, status);
77092
77093 - if (copy_to_user(buf, pb, p))
77094 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
77095 return -EFAULT;
77096
77097 return p;
77098 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
77099 index d5230ec..c604b21 100644
77100 --- a/net/mac80211/util.c
77101 +++ b/net/mac80211/util.c
77102 @@ -1000,7 +1000,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
77103 drv_set_coverage_class(local, hw->wiphy->coverage_class);
77104
77105 /* everything else happens only if HW was up & running */
77106 - if (!local->open_count)
77107 + if (!local_read(&local->open_count))
77108 goto wake_up;
77109
77110 /*
77111 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
77112 index d5597b7..ab6d39c 100644
77113 --- a/net/netfilter/Kconfig
77114 +++ b/net/netfilter/Kconfig
77115 @@ -779,6 +779,16 @@ config NETFILTER_XT_MATCH_ESP
77116
77117 To compile it as a module, choose M here. If unsure, say N.
77118
77119 +config NETFILTER_XT_MATCH_GRADM
77120 + tristate '"gradm" match support'
77121 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
77122 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
77123 + ---help---
77124 + The gradm match allows to match on grsecurity RBAC being enabled.
77125 + It is useful when iptables rules are applied early on bootup to
77126 + prevent connections to the machine (except from a trusted host)
77127 + while the RBAC system is disabled.
77128 +
77129 config NETFILTER_XT_MATCH_HASHLIMIT
77130 tristate '"hashlimit" match support'
77131 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
77132 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
77133 index 1a02853..5d8c22e 100644
77134 --- a/net/netfilter/Makefile
77135 +++ b/net/netfilter/Makefile
77136 @@ -81,6 +81,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
77137 obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
77138 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77139 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77140 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77141 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77142 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77143 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77144 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
77145 index 29fa5ba..8debc79 100644
77146 --- a/net/netfilter/ipvs/ip_vs_conn.c
77147 +++ b/net/netfilter/ipvs/ip_vs_conn.c
77148 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
77149 /* Increase the refcnt counter of the dest */
77150 atomic_inc(&dest->refcnt);
77151
77152 - conn_flags = atomic_read(&dest->conn_flags);
77153 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
77154 if (cp->protocol != IPPROTO_UDP)
77155 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77156 /* Bind with the destination and its corresponding transmitter */
77157 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
77158 atomic_set(&cp->refcnt, 1);
77159
77160 atomic_set(&cp->n_control, 0);
77161 - atomic_set(&cp->in_pkts, 0);
77162 + atomic_set_unchecked(&cp->in_pkts, 0);
77163
77164 atomic_inc(&ipvs->conn_count);
77165 if (flags & IP_VS_CONN_F_NO_CPORT)
77166 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
77167
77168 /* Don't drop the entry if its number of incoming packets is not
77169 located in [0, 8] */
77170 - i = atomic_read(&cp->in_pkts);
77171 + i = atomic_read_unchecked(&cp->in_pkts);
77172 if (i > 8 || i < 0) return 0;
77173
77174 if (!todrop_rate[i]) return 0;
77175 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
77176 index 6dc7d7d..e45913a 100644
77177 --- a/net/netfilter/ipvs/ip_vs_core.c
77178 +++ b/net/netfilter/ipvs/ip_vs_core.c
77179 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
77180 ret = cp->packet_xmit(skb, cp, pd->pp);
77181 /* do not touch skb anymore */
77182
77183 - atomic_inc(&cp->in_pkts);
77184 + atomic_inc_unchecked(&cp->in_pkts);
77185 ip_vs_conn_put(cp);
77186 return ret;
77187 }
77188 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
77189 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77190 pkts = sysctl_sync_threshold(ipvs);
77191 else
77192 - pkts = atomic_add_return(1, &cp->in_pkts);
77193 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77194
77195 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
77196 cp->protocol == IPPROTO_SCTP) {
77197 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
77198 index e1a66cf..0910076 100644
77199 --- a/net/netfilter/ipvs/ip_vs_ctl.c
77200 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
77201 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
77202 ip_vs_rs_hash(ipvs, dest);
77203 write_unlock_bh(&ipvs->rs_lock);
77204 }
77205 - atomic_set(&dest->conn_flags, conn_flags);
77206 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
77207
77208 /* bind the service */
77209 if (!dest->svc) {
77210 @@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77211 " %-7s %-6d %-10d %-10d\n",
77212 &dest->addr.in6,
77213 ntohs(dest->port),
77214 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77215 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77216 atomic_read(&dest->weight),
77217 atomic_read(&dest->activeconns),
77218 atomic_read(&dest->inactconns));
77219 @@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77220 "%-7s %-6d %-10d %-10d\n",
77221 ntohl(dest->addr.ip),
77222 ntohs(dest->port),
77223 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77224 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77225 atomic_read(&dest->weight),
77226 atomic_read(&dest->activeconns),
77227 atomic_read(&dest->inactconns));
77228 @@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
77229
77230 entry.addr = dest->addr.ip;
77231 entry.port = dest->port;
77232 - entry.conn_flags = atomic_read(&dest->conn_flags);
77233 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77234 entry.weight = atomic_read(&dest->weight);
77235 entry.u_threshold = dest->u_threshold;
77236 entry.l_threshold = dest->l_threshold;
77237 @@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
77238 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
77239
77240 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77241 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77242 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77243 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
77244 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
77245 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
77246 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
77247 index 2b6678c0..aaa41fc 100644
77248 --- a/net/netfilter/ipvs/ip_vs_sync.c
77249 +++ b/net/netfilter/ipvs/ip_vs_sync.c
77250 @@ -649,7 +649,7 @@ control:
77251 * i.e only increment in_pkts for Templates.
77252 */
77253 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
77254 - int pkts = atomic_add_return(1, &cp->in_pkts);
77255 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77256
77257 if (pkts % sysctl_sync_period(ipvs) != 1)
77258 return;
77259 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
77260
77261 if (opt)
77262 memcpy(&cp->in_seq, opt, sizeof(*opt));
77263 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77264 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77265 cp->state = state;
77266 cp->old_state = cp->state;
77267 /*
77268 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
77269 index aa2d720..d8aa111 100644
77270 --- a/net/netfilter/ipvs/ip_vs_xmit.c
77271 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
77272 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
77273 else
77274 rc = NF_ACCEPT;
77275 /* do not touch skb anymore */
77276 - atomic_inc(&cp->in_pkts);
77277 + atomic_inc_unchecked(&cp->in_pkts);
77278 goto out;
77279 }
77280
77281 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
77282 else
77283 rc = NF_ACCEPT;
77284 /* do not touch skb anymore */
77285 - atomic_inc(&cp->in_pkts);
77286 + atomic_inc_unchecked(&cp->in_pkts);
77287 goto out;
77288 }
77289
77290 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
77291 index 66b2c54..c7884e3 100644
77292 --- a/net/netfilter/nfnetlink_log.c
77293 +++ b/net/netfilter/nfnetlink_log.c
77294 @@ -70,7 +70,7 @@ struct nfulnl_instance {
77295 };
77296
77297 static DEFINE_SPINLOCK(instances_lock);
77298 -static atomic_t global_seq;
77299 +static atomic_unchecked_t global_seq;
77300
77301 #define INSTANCE_BUCKETS 16
77302 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77303 @@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
77304 /* global sequence number */
77305 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
77306 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
77307 - htonl(atomic_inc_return(&global_seq)));
77308 + htonl(atomic_inc_return_unchecked(&global_seq)));
77309
77310 if (data_len) {
77311 struct nlattr *nla;
77312 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
77313 new file mode 100644
77314 index 0000000..6905327
77315 --- /dev/null
77316 +++ b/net/netfilter/xt_gradm.c
77317 @@ -0,0 +1,51 @@
77318 +/*
77319 + * gradm match for netfilter
77320 + * Copyright © Zbigniew Krzystolik, 2010
77321 + *
77322 + * This program is free software; you can redistribute it and/or modify
77323 + * it under the terms of the GNU General Public License; either version
77324 + * 2 or 3 as published by the Free Software Foundation.
77325 + */
77326 +#include <linux/module.h>
77327 +#include <linux/moduleparam.h>
77328 +#include <linux/skbuff.h>
77329 +#include <linux/netfilter/x_tables.h>
77330 +#include <linux/grsecurity.h>
77331 +#include <linux/netfilter/xt_gradm.h>
77332 +
77333 +static bool
77334 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
77335 +{
77336 + const struct xt_gradm_mtinfo *info = par->matchinfo;
77337 + bool retval = false;
77338 + if (gr_acl_is_enabled())
77339 + retval = true;
77340 + return retval ^ info->invflags;
77341 +}
77342 +
77343 +static struct xt_match gradm_mt_reg __read_mostly = {
77344 + .name = "gradm",
77345 + .revision = 0,
77346 + .family = NFPROTO_UNSPEC,
77347 + .match = gradm_mt,
77348 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
77349 + .me = THIS_MODULE,
77350 +};
77351 +
77352 +static int __init gradm_mt_init(void)
77353 +{
77354 + return xt_register_match(&gradm_mt_reg);
77355 +}
77356 +
77357 +static void __exit gradm_mt_exit(void)
77358 +{
77359 + xt_unregister_match(&gradm_mt_reg);
77360 +}
77361 +
77362 +module_init(gradm_mt_init);
77363 +module_exit(gradm_mt_exit);
77364 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
77365 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
77366 +MODULE_LICENSE("GPL");
77367 +MODULE_ALIAS("ipt_gradm");
77368 +MODULE_ALIAS("ip6t_gradm");
77369 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
77370 index 4fe4fb4..87a89e5 100644
77371 --- a/net/netfilter/xt_statistic.c
77372 +++ b/net/netfilter/xt_statistic.c
77373 @@ -19,7 +19,7 @@
77374 #include <linux/module.h>
77375
77376 struct xt_statistic_priv {
77377 - atomic_t count;
77378 + atomic_unchecked_t count;
77379 } ____cacheline_aligned_in_smp;
77380
77381 MODULE_LICENSE("GPL");
77382 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
77383 break;
77384 case XT_STATISTIC_MODE_NTH:
77385 do {
77386 - oval = atomic_read(&info->master->count);
77387 + oval = atomic_read_unchecked(&info->master->count);
77388 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
77389 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
77390 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
77391 if (nval == 0)
77392 ret = !ret;
77393 break;
77394 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
77395 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
77396 if (info->master == NULL)
77397 return -ENOMEM;
77398 - atomic_set(&info->master->count, info->u.nth.count);
77399 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
77400
77401 return 0;
77402 }
77403 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
77404 index 1201b6d..bcff8c6 100644
77405 --- a/net/netlink/af_netlink.c
77406 +++ b/net/netlink/af_netlink.c
77407 @@ -742,7 +742,7 @@ static void netlink_overrun(struct sock *sk)
77408 sk->sk_error_report(sk);
77409 }
77410 }
77411 - atomic_inc(&sk->sk_drops);
77412 + atomic_inc_unchecked(&sk->sk_drops);
77413 }
77414
77415 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
77416 @@ -1999,7 +1999,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
77417 sk_wmem_alloc_get(s),
77418 nlk->cb,
77419 atomic_read(&s->sk_refcnt),
77420 - atomic_read(&s->sk_drops),
77421 + atomic_read_unchecked(&s->sk_drops),
77422 sock_i_ino(s)
77423 );
77424
77425 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
77426 index 732152f..60bb09e 100644
77427 --- a/net/netrom/af_netrom.c
77428 +++ b/net/netrom/af_netrom.c
77429 @@ -839,6 +839,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77430 struct sock *sk = sock->sk;
77431 struct nr_sock *nr = nr_sk(sk);
77432
77433 + memset(sax, 0, sizeof(*sax));
77434 lock_sock(sk);
77435 if (peer != 0) {
77436 if (sk->sk_state != TCP_ESTABLISHED) {
77437 @@ -853,7 +854,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77438 *uaddr_len = sizeof(struct full_sockaddr_ax25);
77439 } else {
77440 sax->fsa_ax25.sax25_family = AF_NETROM;
77441 - sax->fsa_ax25.sax25_ndigis = 0;
77442 sax->fsa_ax25.sax25_call = nr->source_addr;
77443 *uaddr_len = sizeof(struct sockaddr_ax25);
77444 }
77445 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
77446 index d9d4970..d5a6a68 100644
77447 --- a/net/packet/af_packet.c
77448 +++ b/net/packet/af_packet.c
77449 @@ -1675,7 +1675,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77450
77451 spin_lock(&sk->sk_receive_queue.lock);
77452 po->stats.tp_packets++;
77453 - skb->dropcount = atomic_read(&sk->sk_drops);
77454 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77455 __skb_queue_tail(&sk->sk_receive_queue, skb);
77456 spin_unlock(&sk->sk_receive_queue.lock);
77457 sk->sk_data_ready(sk, skb->len);
77458 @@ -1684,7 +1684,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77459 drop_n_acct:
77460 spin_lock(&sk->sk_receive_queue.lock);
77461 po->stats.tp_drops++;
77462 - atomic_inc(&sk->sk_drops);
77463 + atomic_inc_unchecked(&sk->sk_drops);
77464 spin_unlock(&sk->sk_receive_queue.lock);
77465
77466 drop_n_restore:
77467 @@ -3266,7 +3266,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77468 case PACKET_HDRLEN:
77469 if (len > sizeof(int))
77470 len = sizeof(int);
77471 - if (copy_from_user(&val, optval, len))
77472 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
77473 return -EFAULT;
77474 switch (val) {
77475 case TPACKET_V1:
77476 @@ -3316,7 +3316,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77477
77478 if (put_user(len, optlen))
77479 return -EFAULT;
77480 - if (copy_to_user(optval, data, len))
77481 + if (len > sizeof(st) || copy_to_user(optval, data, len))
77482 return -EFAULT;
77483 return 0;
77484 }
77485 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
77486 index d65f699..05aa6ce 100644
77487 --- a/net/phonet/af_phonet.c
77488 +++ b/net/phonet/af_phonet.c
77489 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
77490 {
77491 struct phonet_protocol *pp;
77492
77493 - if (protocol >= PHONET_NPROTO)
77494 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77495 return NULL;
77496
77497 rcu_read_lock();
77498 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
77499 {
77500 int err = 0;
77501
77502 - if (protocol >= PHONET_NPROTO)
77503 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77504 return -EINVAL;
77505
77506 err = proto_register(pp->prot, 1);
77507 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
77508 index 2ba6e9f..409573f 100644
77509 --- a/net/phonet/pep.c
77510 +++ b/net/phonet/pep.c
77511 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77512
77513 case PNS_PEP_CTRL_REQ:
77514 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
77515 - atomic_inc(&sk->sk_drops);
77516 + atomic_inc_unchecked(&sk->sk_drops);
77517 break;
77518 }
77519 __skb_pull(skb, 4);
77520 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77521 }
77522
77523 if (pn->rx_credits == 0) {
77524 - atomic_inc(&sk->sk_drops);
77525 + atomic_inc_unchecked(&sk->sk_drops);
77526 err = -ENOBUFS;
77527 break;
77528 }
77529 @@ -557,7 +557,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
77530 }
77531
77532 if (pn->rx_credits == 0) {
77533 - atomic_inc(&sk->sk_drops);
77534 + atomic_inc_unchecked(&sk->sk_drops);
77535 err = NET_RX_DROP;
77536 break;
77537 }
77538 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
77539 index 4c7eff3..59c727f 100644
77540 --- a/net/phonet/socket.c
77541 +++ b/net/phonet/socket.c
77542 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
77543 pn->resource, sk->sk_state,
77544 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
77545 sock_i_uid(sk), sock_i_ino(sk),
77546 - atomic_read(&sk->sk_refcnt), sk,
77547 - atomic_read(&sk->sk_drops), &len);
77548 + atomic_read(&sk->sk_refcnt),
77549 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77550 + NULL,
77551 +#else
77552 + sk,
77553 +#endif
77554 + atomic_read_unchecked(&sk->sk_drops), &len);
77555 }
77556 seq_printf(seq, "%*s\n", 127 - len, "");
77557 return 0;
77558 diff --git a/net/rds/cong.c b/net/rds/cong.c
77559 index e5b65ac..f3b6fb7 100644
77560 --- a/net/rds/cong.c
77561 +++ b/net/rds/cong.c
77562 @@ -78,7 +78,7 @@
77563 * finds that the saved generation number is smaller than the global generation
77564 * number, it wakes up the process.
77565 */
77566 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
77567 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
77568
77569 /*
77570 * Congestion monitoring
77571 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
77572 rdsdebug("waking map %p for %pI4\n",
77573 map, &map->m_addr);
77574 rds_stats_inc(s_cong_update_received);
77575 - atomic_inc(&rds_cong_generation);
77576 + atomic_inc_unchecked(&rds_cong_generation);
77577 if (waitqueue_active(&map->m_waitq))
77578 wake_up(&map->m_waitq);
77579 if (waitqueue_active(&rds_poll_waitq))
77580 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
77581
77582 int rds_cong_updated_since(unsigned long *recent)
77583 {
77584 - unsigned long gen = atomic_read(&rds_cong_generation);
77585 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
77586
77587 if (likely(*recent == gen))
77588 return 0;
77589 diff --git a/net/rds/ib.h b/net/rds/ib.h
77590 index edfaaaf..8c89879 100644
77591 --- a/net/rds/ib.h
77592 +++ b/net/rds/ib.h
77593 @@ -128,7 +128,7 @@ struct rds_ib_connection {
77594 /* sending acks */
77595 unsigned long i_ack_flags;
77596 #ifdef KERNEL_HAS_ATOMIC64
77597 - atomic64_t i_ack_next; /* next ACK to send */
77598 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77599 #else
77600 spinlock_t i_ack_lock; /* protect i_ack_next */
77601 u64 i_ack_next; /* next ACK to send */
77602 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
77603 index 51c8689..36c555f 100644
77604 --- a/net/rds/ib_cm.c
77605 +++ b/net/rds/ib_cm.c
77606 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
77607 /* Clear the ACK state */
77608 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77609 #ifdef KERNEL_HAS_ATOMIC64
77610 - atomic64_set(&ic->i_ack_next, 0);
77611 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77612 #else
77613 ic->i_ack_next = 0;
77614 #endif
77615 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
77616 index e29e0ca..fa3a6a3 100644
77617 --- a/net/rds/ib_recv.c
77618 +++ b/net/rds/ib_recv.c
77619 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77620 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
77621 int ack_required)
77622 {
77623 - atomic64_set(&ic->i_ack_next, seq);
77624 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77625 if (ack_required) {
77626 smp_mb__before_clear_bit();
77627 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77628 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77629 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77630 smp_mb__after_clear_bit();
77631
77632 - return atomic64_read(&ic->i_ack_next);
77633 + return atomic64_read_unchecked(&ic->i_ack_next);
77634 }
77635 #endif
77636
77637 diff --git a/net/rds/iw.h b/net/rds/iw.h
77638 index 04ce3b1..48119a6 100644
77639 --- a/net/rds/iw.h
77640 +++ b/net/rds/iw.h
77641 @@ -134,7 +134,7 @@ struct rds_iw_connection {
77642 /* sending acks */
77643 unsigned long i_ack_flags;
77644 #ifdef KERNEL_HAS_ATOMIC64
77645 - atomic64_t i_ack_next; /* next ACK to send */
77646 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77647 #else
77648 spinlock_t i_ack_lock; /* protect i_ack_next */
77649 u64 i_ack_next; /* next ACK to send */
77650 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
77651 index 9556d28..f046d0e 100644
77652 --- a/net/rds/iw_cm.c
77653 +++ b/net/rds/iw_cm.c
77654 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
77655 /* Clear the ACK state */
77656 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77657 #ifdef KERNEL_HAS_ATOMIC64
77658 - atomic64_set(&ic->i_ack_next, 0);
77659 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77660 #else
77661 ic->i_ack_next = 0;
77662 #endif
77663 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
77664 index 5e57347..3916042 100644
77665 --- a/net/rds/iw_recv.c
77666 +++ b/net/rds/iw_recv.c
77667 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77668 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
77669 int ack_required)
77670 {
77671 - atomic64_set(&ic->i_ack_next, seq);
77672 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77673 if (ack_required) {
77674 smp_mb__before_clear_bit();
77675 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77676 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77677 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77678 smp_mb__after_clear_bit();
77679
77680 - return atomic64_read(&ic->i_ack_next);
77681 + return atomic64_read_unchecked(&ic->i_ack_next);
77682 }
77683 #endif
77684
77685 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
77686 index edac9ef..16bcb98 100644
77687 --- a/net/rds/tcp.c
77688 +++ b/net/rds/tcp.c
77689 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
77690 int val = 1;
77691
77692 set_fs(KERNEL_DS);
77693 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
77694 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
77695 sizeof(val));
77696 set_fs(oldfs);
77697 }
77698 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
77699 index 1b4fd68..2234175 100644
77700 --- a/net/rds/tcp_send.c
77701 +++ b/net/rds/tcp_send.c
77702 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
77703
77704 oldfs = get_fs();
77705 set_fs(KERNEL_DS);
77706 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
77707 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
77708 sizeof(val));
77709 set_fs(oldfs);
77710 }
77711 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
77712 index 74c064c..fdec26f 100644
77713 --- a/net/rxrpc/af_rxrpc.c
77714 +++ b/net/rxrpc/af_rxrpc.c
77715 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
77716 __be32 rxrpc_epoch;
77717
77718 /* current debugging ID */
77719 -atomic_t rxrpc_debug_id;
77720 +atomic_unchecked_t rxrpc_debug_id;
77721
77722 /* count of skbs currently in use */
77723 atomic_t rxrpc_n_skbs;
77724 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
77725 index f99cfce..cc529dd 100644
77726 --- a/net/rxrpc/ar-ack.c
77727 +++ b/net/rxrpc/ar-ack.c
77728 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77729
77730 _enter("{%d,%d,%d,%d},",
77731 call->acks_hard, call->acks_unacked,
77732 - atomic_read(&call->sequence),
77733 + atomic_read_unchecked(&call->sequence),
77734 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
77735
77736 stop = 0;
77737 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77738
77739 /* each Tx packet has a new serial number */
77740 sp->hdr.serial =
77741 - htonl(atomic_inc_return(&call->conn->serial));
77742 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
77743
77744 hdr = (struct rxrpc_header *) txb->head;
77745 hdr->serial = sp->hdr.serial;
77746 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
77747 */
77748 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
77749 {
77750 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
77751 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
77752 }
77753
77754 /*
77755 @@ -629,7 +629,7 @@ process_further:
77756
77757 latest = ntohl(sp->hdr.serial);
77758 hard = ntohl(ack.firstPacket);
77759 - tx = atomic_read(&call->sequence);
77760 + tx = atomic_read_unchecked(&call->sequence);
77761
77762 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77763 latest,
77764 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
77765 goto maybe_reschedule;
77766
77767 send_ACK_with_skew:
77768 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
77769 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
77770 ntohl(ack.serial));
77771 send_ACK:
77772 mtu = call->conn->trans->peer->if_mtu;
77773 @@ -1173,7 +1173,7 @@ send_ACK:
77774 ackinfo.rxMTU = htonl(5692);
77775 ackinfo.jumbo_max = htonl(4);
77776
77777 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77778 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77779 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77780 ntohl(hdr.serial),
77781 ntohs(ack.maxSkew),
77782 @@ -1191,7 +1191,7 @@ send_ACK:
77783 send_message:
77784 _debug("send message");
77785
77786 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77787 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77788 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
77789 send_message_2:
77790
77791 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
77792 index bf656c2..48f9d27 100644
77793 --- a/net/rxrpc/ar-call.c
77794 +++ b/net/rxrpc/ar-call.c
77795 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
77796 spin_lock_init(&call->lock);
77797 rwlock_init(&call->state_lock);
77798 atomic_set(&call->usage, 1);
77799 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
77800 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77801 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
77802
77803 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
77804 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
77805 index 4106ca9..a338d7a 100644
77806 --- a/net/rxrpc/ar-connection.c
77807 +++ b/net/rxrpc/ar-connection.c
77808 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
77809 rwlock_init(&conn->lock);
77810 spin_lock_init(&conn->state_lock);
77811 atomic_set(&conn->usage, 1);
77812 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
77813 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77814 conn->avail_calls = RXRPC_MAXCALLS;
77815 conn->size_align = 4;
77816 conn->header_size = sizeof(struct rxrpc_header);
77817 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
77818 index e7ed43a..6afa140 100644
77819 --- a/net/rxrpc/ar-connevent.c
77820 +++ b/net/rxrpc/ar-connevent.c
77821 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
77822
77823 len = iov[0].iov_len + iov[1].iov_len;
77824
77825 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77826 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77827 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
77828
77829 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77830 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
77831 index 1a2b0633..e8d1382 100644
77832 --- a/net/rxrpc/ar-input.c
77833 +++ b/net/rxrpc/ar-input.c
77834 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
77835 /* track the latest serial number on this connection for ACK packet
77836 * information */
77837 serial = ntohl(sp->hdr.serial);
77838 - hi_serial = atomic_read(&call->conn->hi_serial);
77839 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
77840 while (serial > hi_serial)
77841 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
77842 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
77843 serial);
77844
77845 /* request ACK generation for any ACK or DATA packet that requests
77846 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
77847 index 8e22bd3..f66d1c0 100644
77848 --- a/net/rxrpc/ar-internal.h
77849 +++ b/net/rxrpc/ar-internal.h
77850 @@ -272,8 +272,8 @@ struct rxrpc_connection {
77851 int error; /* error code for local abort */
77852 int debug_id; /* debug ID for printks */
77853 unsigned call_counter; /* call ID counter */
77854 - atomic_t serial; /* packet serial number counter */
77855 - atomic_t hi_serial; /* highest serial number received */
77856 + atomic_unchecked_t serial; /* packet serial number counter */
77857 + atomic_unchecked_t hi_serial; /* highest serial number received */
77858 u8 avail_calls; /* number of calls available */
77859 u8 size_align; /* data size alignment (for security) */
77860 u8 header_size; /* rxrpc + security header size */
77861 @@ -346,7 +346,7 @@ struct rxrpc_call {
77862 spinlock_t lock;
77863 rwlock_t state_lock; /* lock for state transition */
77864 atomic_t usage;
77865 - atomic_t sequence; /* Tx data packet sequence counter */
77866 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
77867 u32 abort_code; /* local/remote abort code */
77868 enum { /* current state of call */
77869 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
77870 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
77871 */
77872 extern atomic_t rxrpc_n_skbs;
77873 extern __be32 rxrpc_epoch;
77874 -extern atomic_t rxrpc_debug_id;
77875 +extern atomic_unchecked_t rxrpc_debug_id;
77876 extern struct workqueue_struct *rxrpc_workqueue;
77877
77878 /*
77879 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
77880 index 87f7135..74d3703 100644
77881 --- a/net/rxrpc/ar-local.c
77882 +++ b/net/rxrpc/ar-local.c
77883 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
77884 spin_lock_init(&local->lock);
77885 rwlock_init(&local->services_lock);
77886 atomic_set(&local->usage, 1);
77887 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
77888 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77889 memcpy(&local->srx, srx, sizeof(*srx));
77890 }
77891
77892 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
77893 index 338d793..47391d0 100644
77894 --- a/net/rxrpc/ar-output.c
77895 +++ b/net/rxrpc/ar-output.c
77896 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
77897 sp->hdr.cid = call->cid;
77898 sp->hdr.callNumber = call->call_id;
77899 sp->hdr.seq =
77900 - htonl(atomic_inc_return(&call->sequence));
77901 + htonl(atomic_inc_return_unchecked(&call->sequence));
77902 sp->hdr.serial =
77903 - htonl(atomic_inc_return(&conn->serial));
77904 + htonl(atomic_inc_return_unchecked(&conn->serial));
77905 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
77906 sp->hdr.userStatus = 0;
77907 sp->hdr.securityIndex = conn->security_ix;
77908 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
77909 index 2754f09..b20e38f 100644
77910 --- a/net/rxrpc/ar-peer.c
77911 +++ b/net/rxrpc/ar-peer.c
77912 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
77913 INIT_LIST_HEAD(&peer->error_targets);
77914 spin_lock_init(&peer->lock);
77915 atomic_set(&peer->usage, 1);
77916 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
77917 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77918 memcpy(&peer->srx, srx, sizeof(*srx));
77919
77920 rxrpc_assess_MTU_size(peer);
77921 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
77922 index 38047f7..9f48511 100644
77923 --- a/net/rxrpc/ar-proc.c
77924 +++ b/net/rxrpc/ar-proc.c
77925 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
77926 atomic_read(&conn->usage),
77927 rxrpc_conn_states[conn->state],
77928 key_serial(conn->key),
77929 - atomic_read(&conn->serial),
77930 - atomic_read(&conn->hi_serial));
77931 + atomic_read_unchecked(&conn->serial),
77932 + atomic_read_unchecked(&conn->hi_serial));
77933
77934 return 0;
77935 }
77936 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
77937 index 92df566..87ec1bf 100644
77938 --- a/net/rxrpc/ar-transport.c
77939 +++ b/net/rxrpc/ar-transport.c
77940 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
77941 spin_lock_init(&trans->client_lock);
77942 rwlock_init(&trans->conn_lock);
77943 atomic_set(&trans->usage, 1);
77944 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
77945 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77946
77947 if (peer->srx.transport.family == AF_INET) {
77948 switch (peer->srx.transport_type) {
77949 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
77950 index 7635107..4670276 100644
77951 --- a/net/rxrpc/rxkad.c
77952 +++ b/net/rxrpc/rxkad.c
77953 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
77954
77955 len = iov[0].iov_len + iov[1].iov_len;
77956
77957 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77958 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77959 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
77960
77961 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77962 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
77963
77964 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
77965
77966 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
77967 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77968 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
77969
77970 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
77971 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
77972 index 1e2eee8..ce3967e 100644
77973 --- a/net/sctp/proc.c
77974 +++ b/net/sctp/proc.c
77975 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
77976 seq_printf(seq,
77977 "%8pK %8pK %-3d %-3d %-2d %-4d "
77978 "%4d %8d %8d %7d %5lu %-5d %5d ",
77979 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
77980 + assoc, sk,
77981 + sctp_sk(sk)->type, sk->sk_state,
77982 assoc->state, hash,
77983 assoc->assoc_id,
77984 assoc->sndbuf_used,
77985 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
77986 index 54a7cd2..944edae 100644
77987 --- a/net/sctp/socket.c
77988 +++ b/net/sctp/socket.c
77989 @@ -4574,7 +4574,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
77990 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
77991 if (space_left < addrlen)
77992 return -ENOMEM;
77993 - if (copy_to_user(to, &temp, addrlen))
77994 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
77995 return -EFAULT;
77996 to += addrlen;
77997 cnt++;
77998 diff --git a/net/socket.c b/net/socket.c
77999 index 2dce67a..1e91168 100644
78000 --- a/net/socket.c
78001 +++ b/net/socket.c
78002 @@ -88,6 +88,7 @@
78003 #include <linux/nsproxy.h>
78004 #include <linux/magic.h>
78005 #include <linux/slab.h>
78006 +#include <linux/in.h>
78007
78008 #include <asm/uaccess.h>
78009 #include <asm/unistd.h>
78010 @@ -105,6 +106,8 @@
78011 #include <linux/sockios.h>
78012 #include <linux/atalk.h>
78013
78014 +#include <linux/grsock.h>
78015 +
78016 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
78017 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
78018 unsigned long nr_segs, loff_t pos);
78019 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
78020 &sockfs_dentry_operations, SOCKFS_MAGIC);
78021 }
78022
78023 -static struct vfsmount *sock_mnt __read_mostly;
78024 +struct vfsmount *sock_mnt __read_mostly;
78025
78026 static struct file_system_type sock_fs_type = {
78027 .name = "sockfs",
78028 @@ -1187,6 +1190,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
78029 return -EAFNOSUPPORT;
78030 if (type < 0 || type >= SOCK_MAX)
78031 return -EINVAL;
78032 + if (protocol < 0)
78033 + return -EINVAL;
78034
78035 /* Compatibility.
78036
78037 @@ -1319,6 +1324,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
78038 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
78039 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
78040
78041 + if(!gr_search_socket(family, type, protocol)) {
78042 + retval = -EACCES;
78043 + goto out;
78044 + }
78045 +
78046 + if (gr_handle_sock_all(family, type, protocol)) {
78047 + retval = -EACCES;
78048 + goto out;
78049 + }
78050 +
78051 retval = sock_create(family, type, protocol, &sock);
78052 if (retval < 0)
78053 goto out;
78054 @@ -1431,6 +1446,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
78055 if (sock) {
78056 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
78057 if (err >= 0) {
78058 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
78059 + err = -EACCES;
78060 + goto error;
78061 + }
78062 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
78063 + if (err)
78064 + goto error;
78065 +
78066 err = security_socket_bind(sock,
78067 (struct sockaddr *)&address,
78068 addrlen);
78069 @@ -1439,6 +1462,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
78070 (struct sockaddr *)
78071 &address, addrlen);
78072 }
78073 +error:
78074 fput_light(sock->file, fput_needed);
78075 }
78076 return err;
78077 @@ -1462,10 +1486,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
78078 if ((unsigned)backlog > somaxconn)
78079 backlog = somaxconn;
78080
78081 + if (gr_handle_sock_server_other(sock->sk)) {
78082 + err = -EPERM;
78083 + goto error;
78084 + }
78085 +
78086 + err = gr_search_listen(sock);
78087 + if (err)
78088 + goto error;
78089 +
78090 err = security_socket_listen(sock, backlog);
78091 if (!err)
78092 err = sock->ops->listen(sock, backlog);
78093
78094 +error:
78095 fput_light(sock->file, fput_needed);
78096 }
78097 return err;
78098 @@ -1509,6 +1543,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78099 newsock->type = sock->type;
78100 newsock->ops = sock->ops;
78101
78102 + if (gr_handle_sock_server_other(sock->sk)) {
78103 + err = -EPERM;
78104 + sock_release(newsock);
78105 + goto out_put;
78106 + }
78107 +
78108 + err = gr_search_accept(sock);
78109 + if (err) {
78110 + sock_release(newsock);
78111 + goto out_put;
78112 + }
78113 +
78114 /*
78115 * We don't need try_module_get here, as the listening socket (sock)
78116 * has the protocol module (sock->ops->owner) held.
78117 @@ -1547,6 +1593,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78118 fd_install(newfd, newfile);
78119 err = newfd;
78120
78121 + gr_attach_curr_ip(newsock->sk);
78122 +
78123 out_put:
78124 fput_light(sock->file, fput_needed);
78125 out:
78126 @@ -1579,6 +1627,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78127 int, addrlen)
78128 {
78129 struct socket *sock;
78130 + struct sockaddr *sck;
78131 struct sockaddr_storage address;
78132 int err, fput_needed;
78133
78134 @@ -1589,6 +1638,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78135 if (err < 0)
78136 goto out_put;
78137
78138 + sck = (struct sockaddr *)&address;
78139 +
78140 + if (gr_handle_sock_client(sck)) {
78141 + err = -EACCES;
78142 + goto out_put;
78143 + }
78144 +
78145 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
78146 + if (err)
78147 + goto out_put;
78148 +
78149 err =
78150 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
78151 if (err)
78152 @@ -1950,7 +2010,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
78153 * checking falls down on this.
78154 */
78155 if (copy_from_user(ctl_buf,
78156 - (void __user __force *)msg_sys->msg_control,
78157 + (void __force_user *)msg_sys->msg_control,
78158 ctl_len))
78159 goto out_freectl;
78160 msg_sys->msg_control = ctl_buf;
78161 @@ -2120,7 +2180,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
78162 * kernel msghdr to use the kernel address space)
78163 */
78164
78165 - uaddr = (__force void __user *)msg_sys->msg_name;
78166 + uaddr = (void __force_user *)msg_sys->msg_name;
78167 uaddr_len = COMPAT_NAMELEN(msg);
78168 if (MSG_CMSG_COMPAT & flags) {
78169 err = verify_compat_iovec(msg_sys, iov,
78170 @@ -2748,7 +2808,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78171 }
78172
78173 ifr = compat_alloc_user_space(buf_size);
78174 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
78175 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
78176
78177 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
78178 return -EFAULT;
78179 @@ -2772,12 +2832,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78180 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
78181
78182 if (copy_in_user(rxnfc, compat_rxnfc,
78183 - (void *)(&rxnfc->fs.m_ext + 1) -
78184 - (void *)rxnfc) ||
78185 + (void __user *)(&rxnfc->fs.m_ext + 1) -
78186 + (void __user *)rxnfc) ||
78187 copy_in_user(&rxnfc->fs.ring_cookie,
78188 &compat_rxnfc->fs.ring_cookie,
78189 - (void *)(&rxnfc->fs.location + 1) -
78190 - (void *)&rxnfc->fs.ring_cookie) ||
78191 + (void __user *)(&rxnfc->fs.location + 1) -
78192 + (void __user *)&rxnfc->fs.ring_cookie) ||
78193 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
78194 sizeof(rxnfc->rule_cnt)))
78195 return -EFAULT;
78196 @@ -2789,12 +2849,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78197
78198 if (convert_out) {
78199 if (copy_in_user(compat_rxnfc, rxnfc,
78200 - (const void *)(&rxnfc->fs.m_ext + 1) -
78201 - (const void *)rxnfc) ||
78202 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
78203 + (const void __user *)rxnfc) ||
78204 copy_in_user(&compat_rxnfc->fs.ring_cookie,
78205 &rxnfc->fs.ring_cookie,
78206 - (const void *)(&rxnfc->fs.location + 1) -
78207 - (const void *)&rxnfc->fs.ring_cookie) ||
78208 + (const void __user *)(&rxnfc->fs.location + 1) -
78209 + (const void __user *)&rxnfc->fs.ring_cookie) ||
78210 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
78211 sizeof(rxnfc->rule_cnt)))
78212 return -EFAULT;
78213 @@ -2864,7 +2924,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
78214 old_fs = get_fs();
78215 set_fs(KERNEL_DS);
78216 err = dev_ioctl(net, cmd,
78217 - (struct ifreq __user __force *) &kifr);
78218 + (struct ifreq __force_user *) &kifr);
78219 set_fs(old_fs);
78220
78221 return err;
78222 @@ -2973,7 +3033,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
78223
78224 old_fs = get_fs();
78225 set_fs(KERNEL_DS);
78226 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
78227 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
78228 set_fs(old_fs);
78229
78230 if (cmd == SIOCGIFMAP && !err) {
78231 @@ -3078,7 +3138,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
78232 ret |= __get_user(rtdev, &(ur4->rt_dev));
78233 if (rtdev) {
78234 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
78235 - r4.rt_dev = (char __user __force *)devname;
78236 + r4.rt_dev = (char __force_user *)devname;
78237 devname[15] = 0;
78238 } else
78239 r4.rt_dev = NULL;
78240 @@ -3318,8 +3378,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
78241 int __user *uoptlen;
78242 int err;
78243
78244 - uoptval = (char __user __force *) optval;
78245 - uoptlen = (int __user __force *) optlen;
78246 + uoptval = (char __force_user *) optval;
78247 + uoptlen = (int __force_user *) optlen;
78248
78249 set_fs(KERNEL_DS);
78250 if (level == SOL_SOCKET)
78251 @@ -3339,7 +3399,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
78252 char __user *uoptval;
78253 int err;
78254
78255 - uoptval = (char __user __force *) optval;
78256 + uoptval = (char __force_user *) optval;
78257
78258 set_fs(KERNEL_DS);
78259 if (level == SOL_SOCKET)
78260 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
78261 index 00a1a2a..6a0138a 100644
78262 --- a/net/sunrpc/sched.c
78263 +++ b/net/sunrpc/sched.c
78264 @@ -238,9 +238,9 @@ static int rpc_wait_bit_killable(void *word)
78265 #ifdef RPC_DEBUG
78266 static void rpc_task_set_debuginfo(struct rpc_task *task)
78267 {
78268 - static atomic_t rpc_pid;
78269 + static atomic_unchecked_t rpc_pid;
78270
78271 - task->tk_pid = atomic_inc_return(&rpc_pid);
78272 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
78273 }
78274 #else
78275 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
78276 diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
78277 index 71bed1c..5dff36d 100644
78278 --- a/net/sunrpc/svcsock.c
78279 +++ b/net/sunrpc/svcsock.c
78280 @@ -396,7 +396,7 @@ static int svc_partial_recvfrom(struct svc_rqst *rqstp,
78281 int buflen, unsigned int base)
78282 {
78283 size_t save_iovlen;
78284 - void __user *save_iovbase;
78285 + void *save_iovbase;
78286 unsigned int i;
78287 int ret;
78288
78289 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
78290 index 09af4fa..77110a9 100644
78291 --- a/net/sunrpc/xprtrdma/svc_rdma.c
78292 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
78293 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
78294 static unsigned int min_max_inline = 4096;
78295 static unsigned int max_max_inline = 65536;
78296
78297 -atomic_t rdma_stat_recv;
78298 -atomic_t rdma_stat_read;
78299 -atomic_t rdma_stat_write;
78300 -atomic_t rdma_stat_sq_starve;
78301 -atomic_t rdma_stat_rq_starve;
78302 -atomic_t rdma_stat_rq_poll;
78303 -atomic_t rdma_stat_rq_prod;
78304 -atomic_t rdma_stat_sq_poll;
78305 -atomic_t rdma_stat_sq_prod;
78306 +atomic_unchecked_t rdma_stat_recv;
78307 +atomic_unchecked_t rdma_stat_read;
78308 +atomic_unchecked_t rdma_stat_write;
78309 +atomic_unchecked_t rdma_stat_sq_starve;
78310 +atomic_unchecked_t rdma_stat_rq_starve;
78311 +atomic_unchecked_t rdma_stat_rq_poll;
78312 +atomic_unchecked_t rdma_stat_rq_prod;
78313 +atomic_unchecked_t rdma_stat_sq_poll;
78314 +atomic_unchecked_t rdma_stat_sq_prod;
78315
78316 /* Temporary NFS request map and context caches */
78317 struct kmem_cache *svc_rdma_map_cachep;
78318 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *table, int write,
78319 len -= *ppos;
78320 if (len > *lenp)
78321 len = *lenp;
78322 - if (len && copy_to_user(buffer, str_buf, len))
78323 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
78324 return -EFAULT;
78325 *lenp = len;
78326 *ppos += len;
78327 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] = {
78328 {
78329 .procname = "rdma_stat_read",
78330 .data = &rdma_stat_read,
78331 - .maxlen = sizeof(atomic_t),
78332 + .maxlen = sizeof(atomic_unchecked_t),
78333 .mode = 0644,
78334 .proc_handler = read_reset_stat,
78335 },
78336 {
78337 .procname = "rdma_stat_recv",
78338 .data = &rdma_stat_recv,
78339 - .maxlen = sizeof(atomic_t),
78340 + .maxlen = sizeof(atomic_unchecked_t),
78341 .mode = 0644,
78342 .proc_handler = read_reset_stat,
78343 },
78344 {
78345 .procname = "rdma_stat_write",
78346 .data = &rdma_stat_write,
78347 - .maxlen = sizeof(atomic_t),
78348 + .maxlen = sizeof(atomic_unchecked_t),
78349 .mode = 0644,
78350 .proc_handler = read_reset_stat,
78351 },
78352 {
78353 .procname = "rdma_stat_sq_starve",
78354 .data = &rdma_stat_sq_starve,
78355 - .maxlen = sizeof(atomic_t),
78356 + .maxlen = sizeof(atomic_unchecked_t),
78357 .mode = 0644,
78358 .proc_handler = read_reset_stat,
78359 },
78360 {
78361 .procname = "rdma_stat_rq_starve",
78362 .data = &rdma_stat_rq_starve,
78363 - .maxlen = sizeof(atomic_t),
78364 + .maxlen = sizeof(atomic_unchecked_t),
78365 .mode = 0644,
78366 .proc_handler = read_reset_stat,
78367 },
78368 {
78369 .procname = "rdma_stat_rq_poll",
78370 .data = &rdma_stat_rq_poll,
78371 - .maxlen = sizeof(atomic_t),
78372 + .maxlen = sizeof(atomic_unchecked_t),
78373 .mode = 0644,
78374 .proc_handler = read_reset_stat,
78375 },
78376 {
78377 .procname = "rdma_stat_rq_prod",
78378 .data = &rdma_stat_rq_prod,
78379 - .maxlen = sizeof(atomic_t),
78380 + .maxlen = sizeof(atomic_unchecked_t),
78381 .mode = 0644,
78382 .proc_handler = read_reset_stat,
78383 },
78384 {
78385 .procname = "rdma_stat_sq_poll",
78386 .data = &rdma_stat_sq_poll,
78387 - .maxlen = sizeof(atomic_t),
78388 + .maxlen = sizeof(atomic_unchecked_t),
78389 .mode = 0644,
78390 .proc_handler = read_reset_stat,
78391 },
78392 {
78393 .procname = "rdma_stat_sq_prod",
78394 .data = &rdma_stat_sq_prod,
78395 - .maxlen = sizeof(atomic_t),
78396 + .maxlen = sizeof(atomic_unchecked_t),
78397 .mode = 0644,
78398 .proc_handler = read_reset_stat,
78399 },
78400 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78401 index df67211..c354b13 100644
78402 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78403 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78404 @@ -499,7 +499,7 @@ next_sge:
78405 svc_rdma_put_context(ctxt, 0);
78406 goto out;
78407 }
78408 - atomic_inc(&rdma_stat_read);
78409 + atomic_inc_unchecked(&rdma_stat_read);
78410
78411 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
78412 chl_map->ch[ch_no].count -= read_wr.num_sge;
78413 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78414 dto_q);
78415 list_del_init(&ctxt->dto_q);
78416 } else {
78417 - atomic_inc(&rdma_stat_rq_starve);
78418 + atomic_inc_unchecked(&rdma_stat_rq_starve);
78419 clear_bit(XPT_DATA, &xprt->xpt_flags);
78420 ctxt = NULL;
78421 }
78422 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78423 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
78424 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
78425 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
78426 - atomic_inc(&rdma_stat_recv);
78427 + atomic_inc_unchecked(&rdma_stat_recv);
78428
78429 /* Build up the XDR from the receive buffers. */
78430 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
78431 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78432 index 249a835..fb2794b 100644
78433 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78434 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78435 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
78436 write_wr.wr.rdma.remote_addr = to;
78437
78438 /* Post It */
78439 - atomic_inc(&rdma_stat_write);
78440 + atomic_inc_unchecked(&rdma_stat_write);
78441 if (svc_rdma_send(xprt, &write_wr))
78442 goto err;
78443 return 0;
78444 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78445 index ba1296d..0fec1a5 100644
78446 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
78447 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78448 @@ -300,7 +300,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78449 return;
78450
78451 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
78452 - atomic_inc(&rdma_stat_rq_poll);
78453 + atomic_inc_unchecked(&rdma_stat_rq_poll);
78454
78455 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
78456 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
78457 @@ -322,7 +322,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78458 }
78459
78460 if (ctxt)
78461 - atomic_inc(&rdma_stat_rq_prod);
78462 + atomic_inc_unchecked(&rdma_stat_rq_prod);
78463
78464 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
78465 /*
78466 @@ -394,7 +394,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78467 return;
78468
78469 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
78470 - atomic_inc(&rdma_stat_sq_poll);
78471 + atomic_inc_unchecked(&rdma_stat_sq_poll);
78472 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
78473 if (wc.status != IB_WC_SUCCESS)
78474 /* Close the transport */
78475 @@ -412,7 +412,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78476 }
78477
78478 if (ctxt)
78479 - atomic_inc(&rdma_stat_sq_prod);
78480 + atomic_inc_unchecked(&rdma_stat_sq_prod);
78481 }
78482
78483 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
78484 @@ -1274,7 +1274,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
78485 spin_lock_bh(&xprt->sc_lock);
78486 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
78487 spin_unlock_bh(&xprt->sc_lock);
78488 - atomic_inc(&rdma_stat_sq_starve);
78489 + atomic_inc_unchecked(&rdma_stat_sq_starve);
78490
78491 /* See if we can opportunistically reap SQ WR to make room */
78492 sq_cq_reap(xprt);
78493 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
78494 index e758139..d29ea47 100644
78495 --- a/net/sysctl_net.c
78496 +++ b/net/sysctl_net.c
78497 @@ -47,7 +47,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
78498 struct ctl_table *table)
78499 {
78500 /* Allow network administrator to have same access as root. */
78501 - if (capable(CAP_NET_ADMIN)) {
78502 + if (capable_nolog(CAP_NET_ADMIN)) {
78503 int mode = (table->mode >> 6) & 7;
78504 return (mode << 6) | (mode << 3) | mode;
78505 }
78506 diff --git a/net/tipc/link.c b/net/tipc/link.c
78507 index ae98a72..7bb6056 100644
78508 --- a/net/tipc/link.c
78509 +++ b/net/tipc/link.c
78510 @@ -1203,7 +1203,7 @@ static int link_send_sections_long(struct tipc_port *sender,
78511 struct tipc_msg fragm_hdr;
78512 struct sk_buff *buf, *buf_chain, *prev;
78513 u32 fragm_crs, fragm_rest, hsz, sect_rest;
78514 - const unchar *sect_crs;
78515 + const unchar __user *sect_crs;
78516 int curr_sect;
78517 u32 fragm_no;
78518
78519 @@ -1247,7 +1247,7 @@ again:
78520
78521 if (!sect_rest) {
78522 sect_rest = msg_sect[++curr_sect].iov_len;
78523 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
78524 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
78525 }
78526
78527 if (sect_rest < fragm_rest)
78528 @@ -1266,7 +1266,7 @@ error:
78529 }
78530 } else
78531 skb_copy_to_linear_data_offset(buf, fragm_crs,
78532 - sect_crs, sz);
78533 + (const void __force_kernel *)sect_crs, sz);
78534 sect_crs += sz;
78535 sect_rest -= sz;
78536 fragm_crs += sz;
78537 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
78538 index 83d5096..dcba497 100644
78539 --- a/net/tipc/msg.c
78540 +++ b/net/tipc/msg.c
78541 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
78542 msg_sect[cnt].iov_len);
78543 else
78544 skb_copy_to_linear_data_offset(*buf, pos,
78545 - msg_sect[cnt].iov_base,
78546 + (const void __force_kernel *)msg_sect[cnt].iov_base,
78547 msg_sect[cnt].iov_len);
78548 pos += msg_sect[cnt].iov_len;
78549 }
78550 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
78551 index 1983717..4d6102c 100644
78552 --- a/net/tipc/subscr.c
78553 +++ b/net/tipc/subscr.c
78554 @@ -101,7 +101,7 @@ static void subscr_send_event(struct subscription *sub,
78555 {
78556 struct iovec msg_sect;
78557
78558 - msg_sect.iov_base = (void *)&sub->evt;
78559 + msg_sect.iov_base = (void __force_user *)&sub->evt;
78560 msg_sect.iov_len = sizeof(struct tipc_event);
78561
78562 sub->evt.event = htohl(event, sub->swap);
78563 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
78564 index d99678a..3514a21 100644
78565 --- a/net/unix/af_unix.c
78566 +++ b/net/unix/af_unix.c
78567 @@ -767,6 +767,12 @@ static struct sock *unix_find_other(struct net *net,
78568 err = -ECONNREFUSED;
78569 if (!S_ISSOCK(inode->i_mode))
78570 goto put_fail;
78571 +
78572 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
78573 + err = -EACCES;
78574 + goto put_fail;
78575 + }
78576 +
78577 u = unix_find_socket_byinode(inode);
78578 if (!u)
78579 goto put_fail;
78580 @@ -787,6 +793,13 @@ static struct sock *unix_find_other(struct net *net,
78581 if (u) {
78582 struct dentry *dentry;
78583 dentry = unix_sk(u)->dentry;
78584 +
78585 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
78586 + err = -EPERM;
78587 + sock_put(u);
78588 + goto fail;
78589 + }
78590 +
78591 if (dentry)
78592 touch_atime(unix_sk(u)->mnt, dentry);
78593 } else
78594 @@ -869,11 +882,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
78595 err = security_path_mknod(&path, dentry, mode, 0);
78596 if (err)
78597 goto out_mknod_drop_write;
78598 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
78599 + err = -EACCES;
78600 + goto out_mknod_drop_write;
78601 + }
78602 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
78603 out_mknod_drop_write:
78604 mnt_drop_write(path.mnt);
78605 if (err)
78606 goto out_mknod_dput;
78607 +
78608 + gr_handle_create(dentry, path.mnt);
78609 +
78610 mutex_unlock(&path.dentry->d_inode->i_mutex);
78611 dput(path.dentry);
78612 path.dentry = dentry;
78613 diff --git a/net/wireless/core.h b/net/wireless/core.h
78614 index b9ec306..b4a563e 100644
78615 --- a/net/wireless/core.h
78616 +++ b/net/wireless/core.h
78617 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
78618 struct mutex mtx;
78619
78620 /* rfkill support */
78621 - struct rfkill_ops rfkill_ops;
78622 + rfkill_ops_no_const rfkill_ops;
78623 struct rfkill *rfkill;
78624 struct work_struct rfkill_sync;
78625
78626 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
78627 index 0af7f54..c916d2f 100644
78628 --- a/net/wireless/wext-core.c
78629 +++ b/net/wireless/wext-core.c
78630 @@ -747,8 +747,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78631 */
78632
78633 /* Support for very large requests */
78634 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
78635 - (user_length > descr->max_tokens)) {
78636 + if (user_length > descr->max_tokens) {
78637 /* Allow userspace to GET more than max so
78638 * we can support any size GET requests.
78639 * There is still a limit : -ENOMEM.
78640 @@ -785,22 +784,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78641 }
78642 }
78643
78644 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
78645 - /*
78646 - * If this is a GET, but not NOMAX, it means that the extra
78647 - * data is not bounded by userspace, but by max_tokens. Thus
78648 - * set the length to max_tokens. This matches the extra data
78649 - * allocation.
78650 - * The driver should fill it with the number of tokens it
78651 - * provided, and it may check iwp->length rather than having
78652 - * knowledge of max_tokens. If the driver doesn't change the
78653 - * iwp->length, this ioctl just copies back max_token tokens
78654 - * filled with zeroes. Hopefully the driver isn't claiming
78655 - * them to be valid data.
78656 - */
78657 - iwp->length = descr->max_tokens;
78658 - }
78659 -
78660 err = handler(dev, info, (union iwreq_data *) iwp, extra);
78661
78662 iwp->length += essid_compat;
78663 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
78664 index 9049a5c..cfa6f5c 100644
78665 --- a/net/xfrm/xfrm_policy.c
78666 +++ b/net/xfrm/xfrm_policy.c
78667 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
78668 {
78669 policy->walk.dead = 1;
78670
78671 - atomic_inc(&policy->genid);
78672 + atomic_inc_unchecked(&policy->genid);
78673
78674 if (del_timer(&policy->timer))
78675 xfrm_pol_put(policy);
78676 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
78677 hlist_add_head(&policy->bydst, chain);
78678 xfrm_pol_hold(policy);
78679 net->xfrm.policy_count[dir]++;
78680 - atomic_inc(&flow_cache_genid);
78681 + atomic_inc_unchecked(&flow_cache_genid);
78682 if (delpol)
78683 __xfrm_policy_unlink(delpol, dir);
78684 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
78685 @@ -1530,7 +1530,7 @@ free_dst:
78686 goto out;
78687 }
78688
78689 -static int inline
78690 +static inline int
78691 xfrm_dst_alloc_copy(void **target, const void *src, int size)
78692 {
78693 if (!*target) {
78694 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
78695 return 0;
78696 }
78697
78698 -static int inline
78699 +static inline int
78700 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78701 {
78702 #ifdef CONFIG_XFRM_SUB_POLICY
78703 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78704 #endif
78705 }
78706
78707 -static int inline
78708 +static inline int
78709 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
78710 {
78711 #ifdef CONFIG_XFRM_SUB_POLICY
78712 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
78713
78714 xdst->num_pols = num_pols;
78715 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
78716 - xdst->policy_genid = atomic_read(&pols[0]->genid);
78717 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
78718
78719 return xdst;
78720 }
78721 @@ -2345,7 +2345,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
78722 if (xdst->xfrm_genid != dst->xfrm->genid)
78723 return 0;
78724 if (xdst->num_pols > 0 &&
78725 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
78726 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
78727 return 0;
78728
78729 mtu = dst_mtu(dst->child);
78730 @@ -2882,7 +2882,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
78731 sizeof(pol->xfrm_vec[i].saddr));
78732 pol->xfrm_vec[i].encap_family = mp->new_family;
78733 /* flush bundles */
78734 - atomic_inc(&pol->genid);
78735 + atomic_inc_unchecked(&pol->genid);
78736 }
78737 }
78738
78739 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
78740 index d2b366c..51ff91ebc 100644
78741 --- a/scripts/Makefile.build
78742 +++ b/scripts/Makefile.build
78743 @@ -109,7 +109,7 @@ endif
78744 endif
78745
78746 # Do not include host rules unless needed
78747 -ifneq ($(hostprogs-y)$(hostprogs-m),)
78748 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
78749 include scripts/Makefile.host
78750 endif
78751
78752 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
78753 index 686cb0d..9d653bf 100644
78754 --- a/scripts/Makefile.clean
78755 +++ b/scripts/Makefile.clean
78756 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
78757 __clean-files := $(extra-y) $(always) \
78758 $(targets) $(clean-files) \
78759 $(host-progs) \
78760 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
78761 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
78762 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
78763
78764 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
78765
78766 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
78767 index 1ac414f..a1c1451 100644
78768 --- a/scripts/Makefile.host
78769 +++ b/scripts/Makefile.host
78770 @@ -31,6 +31,7 @@
78771 # Note: Shared libraries consisting of C++ files are not supported
78772
78773 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
78774 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
78775
78776 # C code
78777 # Executables compiled from a single .c file
78778 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
78779 # Shared libaries (only .c supported)
78780 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
78781 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
78782 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
78783 # Remove .so files from "xxx-objs"
78784 host-cobjs := $(filter-out %.so,$(host-cobjs))
78785
78786 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
78787 index cb1f50c..cef2a7c 100644
78788 --- a/scripts/basic/fixdep.c
78789 +++ b/scripts/basic/fixdep.c
78790 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
78791 /*
78792 * Lookup a value in the configuration string.
78793 */
78794 -static int is_defined_config(const char *name, int len, unsigned int hash)
78795 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
78796 {
78797 struct item *aux;
78798
78799 @@ -211,10 +211,10 @@ static void clear_config(void)
78800 /*
78801 * Record the use of a CONFIG_* word.
78802 */
78803 -static void use_config(const char *m, int slen)
78804 +static void use_config(const char *m, unsigned int slen)
78805 {
78806 unsigned int hash = strhash(m, slen);
78807 - int c, i;
78808 + unsigned int c, i;
78809
78810 if (is_defined_config(m, slen, hash))
78811 return;
78812 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
78813
78814 static void parse_config_file(const char *map, size_t len)
78815 {
78816 - const int *end = (const int *) (map + len);
78817 + const unsigned int *end = (const unsigned int *) (map + len);
78818 /* start at +1, so that p can never be < map */
78819 - const int *m = (const int *) map + 1;
78820 + const unsigned int *m = (const unsigned int *) map + 1;
78821 const char *p, *q;
78822
78823 for (; m < end; m++) {
78824 @@ -406,7 +406,7 @@ static void print_deps(void)
78825 static void traps(void)
78826 {
78827 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
78828 - int *p = (int *)test;
78829 + unsigned int *p = (unsigned int *)test;
78830
78831 if (*p != INT_CONF) {
78832 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
78833 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
78834 new file mode 100644
78835 index 0000000..8729101
78836 --- /dev/null
78837 +++ b/scripts/gcc-plugin.sh
78838 @@ -0,0 +1,2 @@
78839 +#!/bin/sh
78840 +echo -e "#include \"gcc-plugin.h\"\n#include \"tree.h\"\n#include \"tm.h\"\n#include \"rtl.h\"" | $1 -x c -shared - -o /dev/null -I`$2 -print-file-name=plugin`/include >/dev/null 2>&1 && echo "y"
78841 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
78842 index f936d1f..a66d95f 100644
78843 --- a/scripts/mod/file2alias.c
78844 +++ b/scripts/mod/file2alias.c
78845 @@ -72,7 +72,7 @@ static void device_id_check(const char *modname, const char *device_id,
78846 unsigned long size, unsigned long id_size,
78847 void *symval)
78848 {
78849 - int i;
78850 + unsigned int i;
78851
78852 if (size % id_size || size < id_size) {
78853 if (cross_build != 0)
78854 @@ -102,7 +102,7 @@ static void device_id_check(const char *modname, const char *device_id,
78855 /* USB is special because the bcdDevice can be matched against a numeric range */
78856 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
78857 static void do_usb_entry(struct usb_device_id *id,
78858 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
78859 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
78860 unsigned char range_lo, unsigned char range_hi,
78861 unsigned char max, struct module *mod)
78862 {
78863 @@ -203,7 +203,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
78864 {
78865 unsigned int devlo, devhi;
78866 unsigned char chi, clo, max;
78867 - int ndigits;
78868 + unsigned int ndigits;
78869
78870 id->match_flags = TO_NATIVE(id->match_flags);
78871 id->idVendor = TO_NATIVE(id->idVendor);
78872 @@ -437,7 +437,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
78873 for (i = 0; i < count; i++) {
78874 const char *id = (char *)devs[i].id;
78875 char acpi_id[sizeof(devs[0].id)];
78876 - int j;
78877 + unsigned int j;
78878
78879 buf_printf(&mod->dev_table_buf,
78880 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78881 @@ -467,7 +467,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78882
78883 for (j = 0; j < PNP_MAX_DEVICES; j++) {
78884 const char *id = (char *)card->devs[j].id;
78885 - int i2, j2;
78886 + unsigned int i2, j2;
78887 int dup = 0;
78888
78889 if (!id[0])
78890 @@ -493,7 +493,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78891 /* add an individual alias for every device entry */
78892 if (!dup) {
78893 char acpi_id[sizeof(card->devs[0].id)];
78894 - int k;
78895 + unsigned int k;
78896
78897 buf_printf(&mod->dev_table_buf,
78898 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78899 @@ -807,7 +807,7 @@ static void dmi_ascii_filter(char *d, const char *s)
78900 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
78901 char *alias)
78902 {
78903 - int i, j;
78904 + unsigned int i, j;
78905
78906 sprintf(alias, "dmi*");
78907
78908 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
78909 index 2bd594e..d43245e 100644
78910 --- a/scripts/mod/modpost.c
78911 +++ b/scripts/mod/modpost.c
78912 @@ -919,6 +919,7 @@ enum mismatch {
78913 ANY_INIT_TO_ANY_EXIT,
78914 ANY_EXIT_TO_ANY_INIT,
78915 EXPORT_TO_INIT_EXIT,
78916 + DATA_TO_TEXT
78917 };
78918
78919 struct sectioncheck {
78920 @@ -1027,6 +1028,12 @@ const struct sectioncheck sectioncheck[] = {
78921 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
78922 .mismatch = EXPORT_TO_INIT_EXIT,
78923 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
78924 +},
78925 +/* Do not reference code from writable data */
78926 +{
78927 + .fromsec = { DATA_SECTIONS, NULL },
78928 + .tosec = { TEXT_SECTIONS, NULL },
78929 + .mismatch = DATA_TO_TEXT
78930 }
78931 };
78932
78933 @@ -1149,10 +1156,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
78934 continue;
78935 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
78936 continue;
78937 - if (sym->st_value == addr)
78938 - return sym;
78939 /* Find a symbol nearby - addr are maybe negative */
78940 d = sym->st_value - addr;
78941 + if (d == 0)
78942 + return sym;
78943 if (d < 0)
78944 d = addr - sym->st_value;
78945 if (d < distance) {
78946 @@ -1431,6 +1438,14 @@ static void report_sec_mismatch(const char *modname,
78947 tosym, prl_to, prl_to, tosym);
78948 free(prl_to);
78949 break;
78950 + case DATA_TO_TEXT:
78951 +/*
78952 + fprintf(stderr,
78953 + "The variable %s references\n"
78954 + "the %s %s%s%s\n",
78955 + fromsym, to, sec2annotation(tosec), tosym, to_p);
78956 +*/
78957 + break;
78958 }
78959 fprintf(stderr, "\n");
78960 }
78961 @@ -1656,7 +1671,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
78962 static void check_sec_ref(struct module *mod, const char *modname,
78963 struct elf_info *elf)
78964 {
78965 - int i;
78966 + unsigned int i;
78967 Elf_Shdr *sechdrs = elf->sechdrs;
78968
78969 /* Walk through all sections */
78970 @@ -1754,7 +1769,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
78971 va_end(ap);
78972 }
78973
78974 -void buf_write(struct buffer *buf, const char *s, int len)
78975 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
78976 {
78977 if (buf->size - buf->pos < len) {
78978 buf->size += len + SZ;
78979 @@ -1972,7 +1987,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
78980 if (fstat(fileno(file), &st) < 0)
78981 goto close_write;
78982
78983 - if (st.st_size != b->pos)
78984 + if (st.st_size != (off_t)b->pos)
78985 goto close_write;
78986
78987 tmp = NOFAIL(malloc(b->pos));
78988 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
78989 index 2031119..b5433af 100644
78990 --- a/scripts/mod/modpost.h
78991 +++ b/scripts/mod/modpost.h
78992 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
78993
78994 struct buffer {
78995 char *p;
78996 - int pos;
78997 - int size;
78998 + unsigned int pos;
78999 + unsigned int size;
79000 };
79001
79002 void __attribute__((format(printf, 2, 3)))
79003 buf_printf(struct buffer *buf, const char *fmt, ...);
79004
79005 void
79006 -buf_write(struct buffer *buf, const char *s, int len);
79007 +buf_write(struct buffer *buf, const char *s, unsigned int len);
79008
79009 struct module {
79010 struct module *next;
79011 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
79012 index 9dfcd6d..099068e 100644
79013 --- a/scripts/mod/sumversion.c
79014 +++ b/scripts/mod/sumversion.c
79015 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
79016 goto out;
79017 }
79018
79019 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
79020 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
79021 warn("writing sum in %s failed: %s\n",
79022 filename, strerror(errno));
79023 goto out;
79024 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
79025 index 5c11312..72742b5 100644
79026 --- a/scripts/pnmtologo.c
79027 +++ b/scripts/pnmtologo.c
79028 @@ -237,14 +237,14 @@ static void write_header(void)
79029 fprintf(out, " * Linux logo %s\n", logoname);
79030 fputs(" */\n\n", out);
79031 fputs("#include <linux/linux_logo.h>\n\n", out);
79032 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
79033 + fprintf(out, "static unsigned char %s_data[] = {\n",
79034 logoname);
79035 }
79036
79037 static void write_footer(void)
79038 {
79039 fputs("\n};\n\n", out);
79040 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
79041 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
79042 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
79043 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
79044 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
79045 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
79046 fputs("\n};\n\n", out);
79047
79048 /* write logo clut */
79049 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
79050 + fprintf(out, "static unsigned char %s_clut[] = {\n",
79051 logoname);
79052 write_hex_cnt = 0;
79053 for (i = 0; i < logo_clutsize; i++) {
79054 diff --git a/security/Kconfig b/security/Kconfig
79055 index 51bd5a0..58c5b70 100644
79056 --- a/security/Kconfig
79057 +++ b/security/Kconfig
79058 @@ -4,6 +4,639 @@
79059
79060 menu "Security options"
79061
79062 +source grsecurity/Kconfig
79063 +
79064 +menu "PaX"
79065 +
79066 + config ARCH_TRACK_EXEC_LIMIT
79067 + bool
79068 +
79069 + config PAX_KERNEXEC_PLUGIN
79070 + bool
79071 +
79072 + config PAX_PER_CPU_PGD
79073 + bool
79074 +
79075 + config TASK_SIZE_MAX_SHIFT
79076 + int
79077 + depends on X86_64
79078 + default 47 if !PAX_PER_CPU_PGD
79079 + default 42 if PAX_PER_CPU_PGD
79080 +
79081 + config PAX_ENABLE_PAE
79082 + bool
79083 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
79084 +
79085 +config PAX
79086 + bool "Enable various PaX features"
79087 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
79088 + help
79089 + This allows you to enable various PaX features. PaX adds
79090 + intrusion prevention mechanisms to the kernel that reduce
79091 + the risks posed by exploitable memory corruption bugs.
79092 +
79093 +menu "PaX Control"
79094 + depends on PAX
79095 +
79096 +config PAX_SOFTMODE
79097 + bool 'Support soft mode'
79098 + help
79099 + Enabling this option will allow you to run PaX in soft mode, that
79100 + is, PaX features will not be enforced by default, only on executables
79101 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
79102 + support as they are the only way to mark executables for soft mode use.
79103 +
79104 + Soft mode can be activated by using the "pax_softmode=1" kernel command
79105 + line option on boot. Furthermore you can control various PaX features
79106 + at runtime via the entries in /proc/sys/kernel/pax.
79107 +
79108 +config PAX_EI_PAX
79109 + bool 'Use legacy ELF header marking'
79110 + help
79111 + Enabling this option will allow you to control PaX features on
79112 + a per executable basis via the 'chpax' utility available at
79113 + http://pax.grsecurity.net/. The control flags will be read from
79114 + an otherwise reserved part of the ELF header. This marking has
79115 + numerous drawbacks (no support for soft-mode, toolchain does not
79116 + know about the non-standard use of the ELF header) therefore it
79117 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
79118 + support.
79119 +
79120 + If you have applications not marked by the PT_PAX_FLAGS ELF program
79121 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
79122 + option otherwise they will not get any protection.
79123 +
79124 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
79125 + support as well, they will override the legacy EI_PAX marks.
79126 +
79127 +config PAX_PT_PAX_FLAGS
79128 + bool 'Use ELF program header marking'
79129 + help
79130 + Enabling this option will allow you to control PaX features on
79131 + a per executable basis via the 'paxctl' utility available at
79132 + http://pax.grsecurity.net/. The control flags will be read from
79133 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
79134 + has the benefits of supporting both soft mode and being fully
79135 + integrated into the toolchain (the binutils patch is available
79136 + from http://pax.grsecurity.net).
79137 +
79138 + If you have applications not marked by the PT_PAX_FLAGS ELF program
79139 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
79140 + support otherwise they will not get any protection.
79141 +
79142 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79143 + must make sure that the marks are the same if a binary has both marks.
79144 +
79145 + Note that if you enable the legacy EI_PAX marking support as well,
79146 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
79147 +
79148 +config PAX_XATTR_PAX_FLAGS
79149 + bool 'Use filesystem extended attributes marking'
79150 + select CIFS_XATTR if CIFS
79151 + select EXT2_FS_XATTR if EXT2_FS
79152 + select EXT3_FS_XATTR if EXT3_FS
79153 + select EXT4_FS_XATTR if EXT4_FS
79154 + select JFFS2_FS_XATTR if JFFS2_FS
79155 + select REISERFS_FS_XATTR if REISERFS_FS
79156 + select SQUASHFS_XATTR if SQUASHFS
79157 + select TMPFS_XATTR if TMPFS
79158 + select UBIFS_FS_XATTR if UBIFS_FS
79159 + help
79160 + Enabling this option will allow you to control PaX features on
79161 + a per executable basis via the 'setfattr' utility. The control
79162 + flags will be read from the user.pax.flags extended attribute of
79163 + the file. This marking has the benefit of supporting binary-only
79164 + applications that self-check themselves (e.g., skype) and would
79165 + not tolerate chpax/paxctl changes. The main drawback is that
79166 + extended attributes are not supported by some filesystems (e.g.,
79167 + isofs, udf, vfat) so copying files through such filesystems will
79168 + lose the extended attributes and these PaX markings.
79169 +
79170 + If you have applications not marked by the PT_PAX_FLAGS ELF program
79171 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
79172 + support otherwise they will not get any protection.
79173 +
79174 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79175 + must make sure that the marks are the same if a binary has both marks.
79176 +
79177 + Note that if you enable the legacy EI_PAX marking support as well,
79178 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
79179 +
79180 +choice
79181 + prompt 'MAC system integration'
79182 + default PAX_HAVE_ACL_FLAGS
79183 + help
79184 + Mandatory Access Control systems have the option of controlling
79185 + PaX flags on a per executable basis, choose the method supported
79186 + by your particular system.
79187 +
79188 + - "none": if your MAC system does not interact with PaX,
79189 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
79190 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
79191 +
79192 + NOTE: this option is for developers/integrators only.
79193 +
79194 + config PAX_NO_ACL_FLAGS
79195 + bool 'none'
79196 +
79197 + config PAX_HAVE_ACL_FLAGS
79198 + bool 'direct'
79199 +
79200 + config PAX_HOOK_ACL_FLAGS
79201 + bool 'hook'
79202 +endchoice
79203 +
79204 +endmenu
79205 +
79206 +menu "Non-executable pages"
79207 + depends on PAX
79208 +
79209 +config PAX_NOEXEC
79210 + bool "Enforce non-executable pages"
79211 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
79212 + help
79213 + By design some architectures do not allow for protecting memory
79214 + pages against execution or even if they do, Linux does not make
79215 + use of this feature. In practice this means that if a page is
79216 + readable (such as the stack or heap) it is also executable.
79217 +
79218 + There is a well known exploit technique that makes use of this
79219 + fact and a common programming mistake where an attacker can
79220 + introduce code of his choice somewhere in the attacked program's
79221 + memory (typically the stack or the heap) and then execute it.
79222 +
79223 + If the attacked program was running with different (typically
79224 + higher) privileges than that of the attacker, then he can elevate
79225 + his own privilege level (e.g. get a root shell, write to files for
79226 + which he does not have write access to, etc).
79227 +
79228 + Enabling this option will let you choose from various features
79229 + that prevent the injection and execution of 'foreign' code in
79230 + a program.
79231 +
79232 + This will also break programs that rely on the old behaviour and
79233 + expect that dynamically allocated memory via the malloc() family
79234 + of functions is executable (which it is not). Notable examples
79235 + are the XFree86 4.x server, the java runtime and wine.
79236 +
79237 +config PAX_PAGEEXEC
79238 + bool "Paging based non-executable pages"
79239 + 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)
79240 + select S390_SWITCH_AMODE if S390
79241 + select S390_EXEC_PROTECT if S390
79242 + select ARCH_TRACK_EXEC_LIMIT if X86_32
79243 + help
79244 + This implementation is based on the paging feature of the CPU.
79245 + On i386 without hardware non-executable bit support there is a
79246 + variable but usually low performance impact, however on Intel's
79247 + P4 core based CPUs it is very high so you should not enable this
79248 + for kernels meant to be used on such CPUs.
79249 +
79250 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
79251 + with hardware non-executable bit support there is no performance
79252 + impact, on ppc the impact is negligible.
79253 +
79254 + Note that several architectures require various emulations due to
79255 + badly designed userland ABIs, this will cause a performance impact
79256 + but will disappear as soon as userland is fixed. For example, ppc
79257 + userland MUST have been built with secure-plt by a recent toolchain.
79258 +
79259 +config PAX_SEGMEXEC
79260 + bool "Segmentation based non-executable pages"
79261 + depends on PAX_NOEXEC && X86_32
79262 + help
79263 + This implementation is based on the segmentation feature of the
79264 + CPU and has a very small performance impact, however applications
79265 + will be limited to a 1.5 GB address space instead of the normal
79266 + 3 GB.
79267 +
79268 +config PAX_EMUTRAMP
79269 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
79270 + default y if PARISC
79271 + help
79272 + There are some programs and libraries that for one reason or
79273 + another attempt to execute special small code snippets from
79274 + non-executable memory pages. Most notable examples are the
79275 + signal handler return code generated by the kernel itself and
79276 + the GCC trampolines.
79277 +
79278 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
79279 + such programs will no longer work under your kernel.
79280 +
79281 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
79282 + utilities to enable trampoline emulation for the affected programs
79283 + yet still have the protection provided by the non-executable pages.
79284 +
79285 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
79286 + your system will not even boot.
79287 +
79288 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
79289 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
79290 + for the affected files.
79291 +
79292 + NOTE: enabling this feature *may* open up a loophole in the
79293 + protection provided by non-executable pages that an attacker
79294 + could abuse. Therefore the best solution is to not have any
79295 + files on your system that would require this option. This can
79296 + be achieved by not using libc5 (which relies on the kernel
79297 + signal handler return code) and not using or rewriting programs
79298 + that make use of the nested function implementation of GCC.
79299 + Skilled users can just fix GCC itself so that it implements
79300 + nested function calls in a way that does not interfere with PaX.
79301 +
79302 +config PAX_EMUSIGRT
79303 + bool "Automatically emulate sigreturn trampolines"
79304 + depends on PAX_EMUTRAMP && PARISC
79305 + default y
79306 + help
79307 + Enabling this option will have the kernel automatically detect
79308 + and emulate signal return trampolines executing on the stack
79309 + that would otherwise lead to task termination.
79310 +
79311 + This solution is intended as a temporary one for users with
79312 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
79313 + Modula-3 runtime, etc) or executables linked to such, basically
79314 + everything that does not specify its own SA_RESTORER function in
79315 + normal executable memory like glibc 2.1+ does.
79316 +
79317 + On parisc you MUST enable this option, otherwise your system will
79318 + not even boot.
79319 +
79320 + NOTE: this feature cannot be disabled on a per executable basis
79321 + and since it *does* open up a loophole in the protection provided
79322 + by non-executable pages, the best solution is to not have any
79323 + files on your system that would require this option.
79324 +
79325 +config PAX_MPROTECT
79326 + bool "Restrict mprotect()"
79327 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
79328 + help
79329 + Enabling this option will prevent programs from
79330 + - changing the executable status of memory pages that were
79331 + not originally created as executable,
79332 + - making read-only executable pages writable again,
79333 + - creating executable pages from anonymous memory,
79334 + - making read-only-after-relocations (RELRO) data pages writable again.
79335 +
79336 + You should say Y here to complete the protection provided by
79337 + the enforcement of non-executable pages.
79338 +
79339 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79340 + this feature on a per file basis.
79341 +
79342 +config PAX_MPROTECT_COMPAT
79343 + bool "Use legacy/compat protection demoting (read help)"
79344 + depends on PAX_MPROTECT
79345 + default n
79346 + help
79347 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
79348 + by sending the proper error code to the application. For some broken
79349 + userland, this can cause problems with Python or other applications. The
79350 + current implementation however allows for applications like clamav to
79351 + detect if JIT compilation/execution is allowed and to fall back gracefully
79352 + to an interpreter-based mode if it does not. While we encourage everyone
79353 + to use the current implementation as-is and push upstream to fix broken
79354 + userland (note that the RWX logging option can assist with this), in some
79355 + environments this may not be possible. Having to disable MPROTECT
79356 + completely on certain binaries reduces the security benefit of PaX,
79357 + so this option is provided for those environments to revert to the old
79358 + behavior.
79359 +
79360 +config PAX_ELFRELOCS
79361 + bool "Allow ELF text relocations (read help)"
79362 + depends on PAX_MPROTECT
79363 + default n
79364 + help
79365 + Non-executable pages and mprotect() restrictions are effective
79366 + in preventing the introduction of new executable code into an
79367 + attacked task's address space. There remain only two venues
79368 + for this kind of attack: if the attacker can execute already
79369 + existing code in the attacked task then he can either have it
79370 + create and mmap() a file containing his code or have it mmap()
79371 + an already existing ELF library that does not have position
79372 + independent code in it and use mprotect() on it to make it
79373 + writable and copy his code there. While protecting against
79374 + the former approach is beyond PaX, the latter can be prevented
79375 + by having only PIC ELF libraries on one's system (which do not
79376 + need to relocate their code). If you are sure this is your case,
79377 + as is the case with all modern Linux distributions, then leave
79378 + this option disabled. You should say 'n' here.
79379 +
79380 +config PAX_ETEXECRELOCS
79381 + bool "Allow ELF ET_EXEC text relocations"
79382 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
79383 + select PAX_ELFRELOCS
79384 + default y
79385 + help
79386 + On some architectures there are incorrectly created applications
79387 + that require text relocations and would not work without enabling
79388 + this option. If you are an alpha, ia64 or parisc user, you should
79389 + enable this option and disable it once you have made sure that
79390 + none of your applications need it.
79391 +
79392 +config PAX_EMUPLT
79393 + bool "Automatically emulate ELF PLT"
79394 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
79395 + default y
79396 + help
79397 + Enabling this option will have the kernel automatically detect
79398 + and emulate the Procedure Linkage Table entries in ELF files.
79399 + On some architectures such entries are in writable memory, and
79400 + become non-executable leading to task termination. Therefore
79401 + it is mandatory that you enable this option on alpha, parisc,
79402 + sparc and sparc64, otherwise your system would not even boot.
79403 +
79404 + NOTE: this feature *does* open up a loophole in the protection
79405 + provided by the non-executable pages, therefore the proper
79406 + solution is to modify the toolchain to produce a PLT that does
79407 + not need to be writable.
79408 +
79409 +config PAX_DLRESOLVE
79410 + bool 'Emulate old glibc resolver stub'
79411 + depends on PAX_EMUPLT && SPARC
79412 + default n
79413 + help
79414 + This option is needed if userland has an old glibc (before 2.4)
79415 + that puts a 'save' instruction into the runtime generated resolver
79416 + stub that needs special emulation.
79417 +
79418 +config PAX_KERNEXEC
79419 + bool "Enforce non-executable kernel pages"
79420 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
79421 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
79422 + select PAX_KERNEXEC_PLUGIN if X86_64
79423 + help
79424 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
79425 + that is, enabling this option will make it harder to inject
79426 + and execute 'foreign' code in kernel memory itself.
79427 +
79428 + Note that on x86_64 kernels there is a known regression when
79429 + this feature and KVM/VMX are both enabled in the host kernel.
79430 +
79431 +choice
79432 + prompt "Return Address Instrumentation Method"
79433 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
79434 + depends on PAX_KERNEXEC_PLUGIN
79435 + help
79436 + Select the method used to instrument function pointer dereferences.
79437 + Note that binary modules cannot be instrumented by this approach.
79438 +
79439 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
79440 + bool "bts"
79441 + help
79442 + This method is compatible with binary only modules but has
79443 + a higher runtime overhead.
79444 +
79445 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
79446 + bool "or"
79447 + depends on !PARAVIRT
79448 + help
79449 + This method is incompatible with binary only modules but has
79450 + a lower runtime overhead.
79451 +endchoice
79452 +
79453 +config PAX_KERNEXEC_PLUGIN_METHOD
79454 + string
79455 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
79456 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
79457 + default ""
79458 +
79459 +config PAX_KERNEXEC_MODULE_TEXT
79460 + int "Minimum amount of memory reserved for module code"
79461 + default "4"
79462 + depends on PAX_KERNEXEC && X86_32 && MODULES
79463 + help
79464 + Due to implementation details the kernel must reserve a fixed
79465 + amount of memory for module code at compile time that cannot be
79466 + changed at runtime. Here you can specify the minimum amount
79467 + in MB that will be reserved. Due to the same implementation
79468 + details this size will always be rounded up to the next 2/4 MB
79469 + boundary (depends on PAE) so the actually available memory for
79470 + module code will usually be more than this minimum.
79471 +
79472 + The default 4 MB should be enough for most users but if you have
79473 + an excessive number of modules (e.g., most distribution configs
79474 + compile many drivers as modules) or use huge modules such as
79475 + nvidia's kernel driver, you will need to adjust this amount.
79476 + A good rule of thumb is to look at your currently loaded kernel
79477 + modules and add up their sizes.
79478 +
79479 +endmenu
79480 +
79481 +menu "Address Space Layout Randomization"
79482 + depends on PAX
79483 +
79484 +config PAX_ASLR
79485 + bool "Address Space Layout Randomization"
79486 + help
79487 + Many if not most exploit techniques rely on the knowledge of
79488 + certain addresses in the attacked program. The following options
79489 + will allow the kernel to apply a certain amount of randomization
79490 + to specific parts of the program thereby forcing an attacker to
79491 + guess them in most cases. Any failed guess will most likely crash
79492 + the attacked program which allows the kernel to detect such attempts
79493 + and react on them. PaX itself provides no reaction mechanisms,
79494 + instead it is strongly encouraged that you make use of Nergal's
79495 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
79496 + (http://www.grsecurity.net/) built-in crash detection features or
79497 + develop one yourself.
79498 +
79499 + By saying Y here you can choose to randomize the following areas:
79500 + - top of the task's kernel stack
79501 + - top of the task's userland stack
79502 + - base address for mmap() requests that do not specify one
79503 + (this includes all libraries)
79504 + - base address of the main executable
79505 +
79506 + It is strongly recommended to say Y here as address space layout
79507 + randomization has negligible impact on performance yet it provides
79508 + a very effective protection.
79509 +
79510 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79511 + this feature on a per file basis.
79512 +
79513 +config PAX_RANDKSTACK
79514 + bool "Randomize kernel stack base"
79515 + depends on X86_TSC && X86
79516 + help
79517 + By saying Y here the kernel will randomize every task's kernel
79518 + stack on every system call. This will not only force an attacker
79519 + to guess it but also prevent him from making use of possible
79520 + leaked information about it.
79521 +
79522 + Since the kernel stack is a rather scarce resource, randomization
79523 + may cause unexpected stack overflows, therefore you should very
79524 + carefully test your system. Note that once enabled in the kernel
79525 + configuration, this feature cannot be disabled on a per file basis.
79526 +
79527 +config PAX_RANDUSTACK
79528 + bool "Randomize user stack base"
79529 + depends on PAX_ASLR
79530 + help
79531 + By saying Y here the kernel will randomize every task's userland
79532 + stack. The randomization is done in two steps where the second
79533 + one may apply a big amount of shift to the top of the stack and
79534 + cause problems for programs that want to use lots of memory (more
79535 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
79536 + For this reason the second step can be controlled by 'chpax' or
79537 + 'paxctl' on a per file basis.
79538 +
79539 +config PAX_RANDMMAP
79540 + bool "Randomize mmap() base"
79541 + depends on PAX_ASLR
79542 + help
79543 + By saying Y here the kernel will use a randomized base address for
79544 + mmap() requests that do not specify one themselves. As a result
79545 + all dynamically loaded libraries will appear at random addresses
79546 + and therefore be harder to exploit by a technique where an attacker
79547 + attempts to execute library code for his purposes (e.g. spawn a
79548 + shell from an exploited program that is running at an elevated
79549 + privilege level).
79550 +
79551 + Furthermore, if a program is relinked as a dynamic ELF file, its
79552 + base address will be randomized as well, completing the full
79553 + randomization of the address space layout. Attacking such programs
79554 + becomes a guess game. You can find an example of doing this at
79555 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
79556 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
79557 +
79558 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
79559 + feature on a per file basis.
79560 +
79561 +endmenu
79562 +
79563 +menu "Miscellaneous hardening features"
79564 +
79565 +config PAX_MEMORY_SANITIZE
79566 + bool "Sanitize all freed memory"
79567 + depends on !HIBERNATION
79568 + help
79569 + By saying Y here the kernel will erase memory pages as soon as they
79570 + are freed. This in turn reduces the lifetime of data stored in the
79571 + pages, making it less likely that sensitive information such as
79572 + passwords, cryptographic secrets, etc stay in memory for too long.
79573 +
79574 + This is especially useful for programs whose runtime is short, long
79575 + lived processes and the kernel itself benefit from this as long as
79576 + they operate on whole memory pages and ensure timely freeing of pages
79577 + that may hold sensitive information.
79578 +
79579 + The tradeoff is performance impact, on a single CPU system kernel
79580 + compilation sees a 3% slowdown, other systems and workloads may vary
79581 + and you are advised to test this feature on your expected workload
79582 + before deploying it.
79583 +
79584 + Note that this feature does not protect data stored in live pages,
79585 + e.g., process memory swapped to disk may stay there for a long time.
79586 +
79587 +config PAX_MEMORY_STACKLEAK
79588 + bool "Sanitize kernel stack"
79589 + depends on X86
79590 + help
79591 + By saying Y here the kernel will erase the kernel stack before it
79592 + returns from a system call. This in turn reduces the information
79593 + that a kernel stack leak bug can reveal.
79594 +
79595 + Note that such a bug can still leak information that was put on
79596 + the stack by the current system call (the one eventually triggering
79597 + the bug) but traces of earlier system calls on the kernel stack
79598 + cannot leak anymore.
79599 +
79600 + The tradeoff is performance impact: on a single CPU system kernel
79601 + compilation sees a 1% slowdown, other systems and workloads may vary
79602 + and you are advised to test this feature on your expected workload
79603 + before deploying it.
79604 +
79605 + Note: full support for this feature requires gcc with plugin support
79606 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
79607 + versions means that functions with large enough stack frames may
79608 + leave uninitialized memory behind that may be exposed to a later
79609 + syscall leaking the stack.
79610 +
79611 +config PAX_MEMORY_UDEREF
79612 + bool "Prevent invalid userland pointer dereference"
79613 + depends on X86 && !UML_X86 && !XEN
79614 + select PAX_PER_CPU_PGD if X86_64
79615 + help
79616 + By saying Y here the kernel will be prevented from dereferencing
79617 + userland pointers in contexts where the kernel expects only kernel
79618 + pointers. This is both a useful runtime debugging feature and a
79619 + security measure that prevents exploiting a class of kernel bugs.
79620 +
79621 + The tradeoff is that some virtualization solutions may experience
79622 + a huge slowdown and therefore you should not enable this feature
79623 + for kernels meant to run in such environments. Whether a given VM
79624 + solution is affected or not is best determined by simply trying it
79625 + out, the performance impact will be obvious right on boot as this
79626 + mechanism engages from very early on. A good rule of thumb is that
79627 + VMs running on CPUs without hardware virtualization support (i.e.,
79628 + the majority of IA-32 CPUs) will likely experience the slowdown.
79629 +
79630 +config PAX_REFCOUNT
79631 + bool "Prevent various kernel object reference counter overflows"
79632 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
79633 + help
79634 + By saying Y here the kernel will detect and prevent overflowing
79635 + various (but not all) kinds of object reference counters. Such
79636 + overflows can normally occur due to bugs only and are often, if
79637 + not always, exploitable.
79638 +
79639 + The tradeoff is that data structures protected by an overflowed
79640 + refcount will never be freed and therefore will leak memory. Note
79641 + that this leak also happens even without this protection but in
79642 + that case the overflow can eventually trigger the freeing of the
79643 + data structure while it is still being used elsewhere, resulting
79644 + in the exploitable situation that this feature prevents.
79645 +
79646 + Since this has a negligible performance impact, you should enable
79647 + this feature.
79648 +
79649 +config PAX_USERCOPY
79650 + bool "Harden heap object copies between kernel and userland"
79651 + depends on X86 || PPC || SPARC || ARM
79652 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
79653 + help
79654 + By saying Y here the kernel will enforce the size of heap objects
79655 + when they are copied in either direction between the kernel and
79656 + userland, even if only a part of the heap object is copied.
79657 +
79658 + Specifically, this checking prevents information leaking from the
79659 + kernel heap during kernel to userland copies (if the kernel heap
79660 + object is otherwise fully initialized) and prevents kernel heap
79661 + overflows during userland to kernel copies.
79662 +
79663 + Note that the current implementation provides the strictest bounds
79664 + checks for the SLUB allocator.
79665 +
79666 + Enabling this option also enables per-slab cache protection against
79667 + data in a given cache being copied into/out of via userland
79668 + accessors. Though the whitelist of regions will be reduced over
79669 + time, it notably protects important data structures like task structs.
79670 +
79671 + If frame pointers are enabled on x86, this option will also restrict
79672 + copies into and out of the kernel stack to local variables within a
79673 + single frame.
79674 +
79675 + Since this has a negligible performance impact, you should enable
79676 + this feature.
79677 +
79678 +config PAX_SIZE_OVERFLOW
79679 + bool "Prevent various integer overflows in function size parameters"
79680 + help
79681 + By saying Y here the kernel recomputes expressions of function
79682 + arguments marked by a size_overflow attribute with double integer
79683 + precision (DImode/TImode for 32/64 bit integer types).
79684 +
79685 + The recomputed argument is checked against INT_MAX and an event
79686 + is logged on overflow and the triggering process is killed.
79687 +
79688 + Homepage:
79689 + http://www.grsecurity.net/~ephox/overflow_plugin/
79690 +
79691 +endmenu
79692 +
79693 +endmenu
79694 +
79695 config KEYS
79696 bool "Enable access key retention support"
79697 help
79698 @@ -169,7 +802,7 @@ config INTEL_TXT
79699 config LSM_MMAP_MIN_ADDR
79700 int "Low address space for LSM to protect from user allocation"
79701 depends on SECURITY && SECURITY_SELINUX
79702 - default 32768 if ARM
79703 + default 32768 if ALPHA || ARM || PARISC || SPARC32
79704 default 65536
79705 help
79706 This is the portion of low virtual memory which should be protected
79707 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
79708 index 3783202..1852837 100644
79709 --- a/security/apparmor/lsm.c
79710 +++ b/security/apparmor/lsm.c
79711 @@ -621,7 +621,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
79712 return error;
79713 }
79714
79715 -static struct security_operations apparmor_ops = {
79716 +static struct security_operations apparmor_ops __read_only = {
79717 .name = "apparmor",
79718
79719 .ptrace_access_check = apparmor_ptrace_access_check,
79720 diff --git a/security/commoncap.c b/security/commoncap.c
79721 index ee4f848..a320c64 100644
79722 --- a/security/commoncap.c
79723 +++ b/security/commoncap.c
79724 @@ -28,6 +28,7 @@
79725 #include <linux/prctl.h>
79726 #include <linux/securebits.h>
79727 #include <linux/user_namespace.h>
79728 +#include <net/sock.h>
79729
79730 /*
79731 * If a non-root user executes a setuid-root binary in
79732 @@ -58,7 +59,7 @@ int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
79733
79734 int cap_netlink_recv(struct sk_buff *skb, int cap)
79735 {
79736 - if (!cap_raised(current_cap(), cap))
79737 + if (!cap_raised(current_cap(), cap) || !gr_is_capable(cap))
79738 return -EPERM;
79739 return 0;
79740 }
79741 @@ -579,6 +580,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
79742 {
79743 const struct cred *cred = current_cred();
79744
79745 + if (gr_acl_enable_at_secure())
79746 + return 1;
79747 +
79748 if (cred->uid != 0) {
79749 if (bprm->cap_effective)
79750 return 1;
79751 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
79752 index 3ccf7ac..d73ad64 100644
79753 --- a/security/integrity/ima/ima.h
79754 +++ b/security/integrity/ima/ima.h
79755 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
79756 extern spinlock_t ima_queue_lock;
79757
79758 struct ima_h_table {
79759 - atomic_long_t len; /* number of stored measurements in the list */
79760 - atomic_long_t violations;
79761 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
79762 + atomic_long_unchecked_t violations;
79763 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
79764 };
79765 extern struct ima_h_table ima_htable;
79766 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
79767 index 88a2788..581ab92 100644
79768 --- a/security/integrity/ima/ima_api.c
79769 +++ b/security/integrity/ima/ima_api.c
79770 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
79771 int result;
79772
79773 /* can overflow, only indicator */
79774 - atomic_long_inc(&ima_htable.violations);
79775 + atomic_long_inc_unchecked(&ima_htable.violations);
79776
79777 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
79778 if (!entry) {
79779 diff --git a/security/integrity/ima/ima_audit.c b/security/integrity/ima/ima_audit.c
79780 index c5c5a72..2ad942f 100644
79781 --- a/security/integrity/ima/ima_audit.c
79782 +++ b/security/integrity/ima/ima_audit.c
79783 @@ -56,9 +56,11 @@ void integrity_audit_msg(int audit_msgno, struct inode *inode,
79784 audit_log_format(ab, " name=");
79785 audit_log_untrustedstring(ab, fname);
79786 }
79787 - if (inode)
79788 - audit_log_format(ab, " dev=%s ino=%lu",
79789 - inode->i_sb->s_id, inode->i_ino);
79790 + if (inode) {
79791 + audit_log_format(ab, " dev=");
79792 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
79793 + audit_log_format(ab, " ino=%lu", inode->i_ino);
79794 + }
79795 audit_log_format(ab, " res=%d", !result ? 0 : 1);
79796 audit_log_end(ab);
79797 }
79798 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
79799 index e1aa2b4..52027bf 100644
79800 --- a/security/integrity/ima/ima_fs.c
79801 +++ b/security/integrity/ima/ima_fs.c
79802 @@ -28,12 +28,12 @@
79803 static int valid_policy = 1;
79804 #define TMPBUFLEN 12
79805 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
79806 - loff_t *ppos, atomic_long_t *val)
79807 + loff_t *ppos, atomic_long_unchecked_t *val)
79808 {
79809 char tmpbuf[TMPBUFLEN];
79810 ssize_t len;
79811
79812 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
79813 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
79814 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
79815 }
79816
79817 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
79818 index 55a6271..ad829c3 100644
79819 --- a/security/integrity/ima/ima_queue.c
79820 +++ b/security/integrity/ima/ima_queue.c
79821 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
79822 INIT_LIST_HEAD(&qe->later);
79823 list_add_tail_rcu(&qe->later, &ima_measurements);
79824
79825 - atomic_long_inc(&ima_htable.len);
79826 + atomic_long_inc_unchecked(&ima_htable.len);
79827 key = ima_hash_key(entry->digest);
79828 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
79829 return 0;
79830 diff --git a/security/keys/compat.c b/security/keys/compat.c
79831 index 4c48e13..7abdac9 100644
79832 --- a/security/keys/compat.c
79833 +++ b/security/keys/compat.c
79834 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
79835 if (ret == 0)
79836 goto no_payload_free;
79837
79838 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
79839 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
79840
79841 if (iov != iovstack)
79842 kfree(iov);
79843 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
79844 index 0b3f5d7..892c8a6 100644
79845 --- a/security/keys/keyctl.c
79846 +++ b/security/keys/keyctl.c
79847 @@ -921,7 +921,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
79848 /*
79849 * Copy the iovec data from userspace
79850 */
79851 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
79852 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
79853 unsigned ioc)
79854 {
79855 for (; ioc > 0; ioc--) {
79856 @@ -943,7 +943,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
79857 * If successful, 0 will be returned.
79858 */
79859 long keyctl_instantiate_key_common(key_serial_t id,
79860 - const struct iovec *payload_iov,
79861 + const struct iovec __user *payload_iov,
79862 unsigned ioc,
79863 size_t plen,
79864 key_serial_t ringid)
79865 @@ -1038,7 +1038,7 @@ long keyctl_instantiate_key(key_serial_t id,
79866 [0].iov_len = plen
79867 };
79868
79869 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
79870 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
79871 }
79872
79873 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
79874 @@ -1071,7 +1071,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
79875 if (ret == 0)
79876 goto no_payload_free;
79877
79878 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
79879 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
79880
79881 if (iov != iovstack)
79882 kfree(iov);
79883 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
79884 index 37a7f3b..86dc19f 100644
79885 --- a/security/keys/keyring.c
79886 +++ b/security/keys/keyring.c
79887 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
79888 ret = -EFAULT;
79889
79890 for (loop = 0; loop < klist->nkeys; loop++) {
79891 + key_serial_t serial;
79892 key = klist->keys[loop];
79893 + serial = key->serial;
79894
79895 tmp = sizeof(key_serial_t);
79896 if (tmp > buflen)
79897 tmp = buflen;
79898
79899 - if (copy_to_user(buffer,
79900 - &key->serial,
79901 - tmp) != 0)
79902 + if (copy_to_user(buffer, &serial, tmp))
79903 goto error;
79904
79905 buflen -= tmp;
79906 diff --git a/security/lsm_audit.c b/security/lsm_audit.c
79907 index 893af8a..ba9237c 100644
79908 --- a/security/lsm_audit.c
79909 +++ b/security/lsm_audit.c
79910 @@ -234,10 +234,11 @@ static void dump_common_audit_data(struct audit_buffer *ab,
79911 audit_log_d_path(ab, "path=", &a->u.path);
79912
79913 inode = a->u.path.dentry->d_inode;
79914 - if (inode)
79915 - audit_log_format(ab, " dev=%s ino=%lu",
79916 - inode->i_sb->s_id,
79917 - inode->i_ino);
79918 + if (inode) {
79919 + audit_log_format(ab, " dev=");
79920 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
79921 + audit_log_format(ab, " ino=%lu", inode->i_ino);
79922 + }
79923 break;
79924 }
79925 case LSM_AUDIT_DATA_DENTRY: {
79926 @@ -247,10 +248,11 @@ static void dump_common_audit_data(struct audit_buffer *ab,
79927 audit_log_untrustedstring(ab, a->u.dentry->d_name.name);
79928
79929 inode = a->u.dentry->d_inode;
79930 - if (inode)
79931 - audit_log_format(ab, " dev=%s ino=%lu",
79932 - inode->i_sb->s_id,
79933 - inode->i_ino);
79934 + if (inode) {
79935 + audit_log_format(ab, " dev=");
79936 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
79937 + audit_log_format(ab, " ino=%lu", inode->i_ino);
79938 + }
79939 break;
79940 }
79941 case LSM_AUDIT_DATA_INODE: {
79942 @@ -265,8 +267,9 @@ static void dump_common_audit_data(struct audit_buffer *ab,
79943 dentry->d_name.name);
79944 dput(dentry);
79945 }
79946 - audit_log_format(ab, " dev=%s ino=%lu", inode->i_sb->s_id,
79947 - inode->i_ino);
79948 + audit_log_format(ab, " dev=");
79949 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
79950 + audit_log_format(ab, " ino=%lu", inode->i_ino);
79951 break;
79952 }
79953 case LSM_AUDIT_DATA_TASK:
79954 diff --git a/security/min_addr.c b/security/min_addr.c
79955 index f728728..6457a0c 100644
79956 --- a/security/min_addr.c
79957 +++ b/security/min_addr.c
79958 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
79959 */
79960 static void update_mmap_min_addr(void)
79961 {
79962 +#ifndef SPARC
79963 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
79964 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
79965 mmap_min_addr = dac_mmap_min_addr;
79966 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
79967 #else
79968 mmap_min_addr = dac_mmap_min_addr;
79969 #endif
79970 +#endif
79971 }
79972
79973 /*
79974 diff --git a/security/security.c b/security/security.c
79975 index e2f684a..8d62ef5 100644
79976 --- a/security/security.c
79977 +++ b/security/security.c
79978 @@ -26,8 +26,8 @@
79979 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
79980 CONFIG_DEFAULT_SECURITY;
79981
79982 -static struct security_operations *security_ops;
79983 -static struct security_operations default_security_ops = {
79984 +static struct security_operations *security_ops __read_only;
79985 +static struct security_operations default_security_ops __read_only = {
79986 .name = "default",
79987 };
79988
79989 @@ -68,7 +68,9 @@ int __init security_init(void)
79990
79991 void reset_security_ops(void)
79992 {
79993 + pax_open_kernel();
79994 security_ops = &default_security_ops;
79995 + pax_close_kernel();
79996 }
79997
79998 /* Save user chosen LSM */
79999 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
80000 index 1126c10..effb32b 100644
80001 --- a/security/selinux/hooks.c
80002 +++ b/security/selinux/hooks.c
80003 @@ -94,8 +94,6 @@
80004
80005 #define NUM_SEL_MNT_OPTS 5
80006
80007 -extern struct security_operations *security_ops;
80008 -
80009 /* SECMARK reference count */
80010 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
80011
80012 @@ -5449,7 +5447,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
80013
80014 #endif
80015
80016 -static struct security_operations selinux_ops = {
80017 +static struct security_operations selinux_ops __read_only = {
80018 .name = "selinux",
80019
80020 .ptrace_access_check = selinux_ptrace_access_check,
80021 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
80022 index b43813c..74be837 100644
80023 --- a/security/selinux/include/xfrm.h
80024 +++ b/security/selinux/include/xfrm.h
80025 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
80026
80027 static inline void selinux_xfrm_notify_policyload(void)
80028 {
80029 - atomic_inc(&flow_cache_genid);
80030 + atomic_inc_unchecked(&flow_cache_genid);
80031 }
80032 #else
80033 static inline int selinux_xfrm_enabled(void)
80034 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
80035 index 7db62b4..ee4d949 100644
80036 --- a/security/smack/smack_lsm.c
80037 +++ b/security/smack/smack_lsm.c
80038 @@ -3481,7 +3481,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
80039 return 0;
80040 }
80041
80042 -struct security_operations smack_ops = {
80043 +struct security_operations smack_ops __read_only = {
80044 .name = "smack",
80045
80046 .ptrace_access_check = smack_ptrace_access_check,
80047 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
80048 index 4b327b6..646c57a 100644
80049 --- a/security/tomoyo/tomoyo.c
80050 +++ b/security/tomoyo/tomoyo.c
80051 @@ -504,7 +504,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
80052 * tomoyo_security_ops is a "struct security_operations" which is used for
80053 * registering TOMOYO.
80054 */
80055 -static struct security_operations tomoyo_security_ops = {
80056 +static struct security_operations tomoyo_security_ops __read_only = {
80057 .name = "tomoyo",
80058 .cred_alloc_blank = tomoyo_cred_alloc_blank,
80059 .cred_prepare = tomoyo_cred_prepare,
80060 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
80061 index 762af68..7103453 100644
80062 --- a/sound/aoa/codecs/onyx.c
80063 +++ b/sound/aoa/codecs/onyx.c
80064 @@ -54,7 +54,7 @@ struct onyx {
80065 spdif_locked:1,
80066 analog_locked:1,
80067 original_mute:2;
80068 - int open_count;
80069 + local_t open_count;
80070 struct codec_info *codec_info;
80071
80072 /* mutex serializes concurrent access to the device
80073 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
80074 struct onyx *onyx = cii->codec_data;
80075
80076 mutex_lock(&onyx->mutex);
80077 - onyx->open_count++;
80078 + local_inc(&onyx->open_count);
80079 mutex_unlock(&onyx->mutex);
80080
80081 return 0;
80082 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
80083 struct onyx *onyx = cii->codec_data;
80084
80085 mutex_lock(&onyx->mutex);
80086 - onyx->open_count--;
80087 - if (!onyx->open_count)
80088 + if (local_dec_and_test(&onyx->open_count))
80089 onyx->spdif_locked = onyx->analog_locked = 0;
80090 mutex_unlock(&onyx->mutex);
80091
80092 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
80093 index ffd2025..df062c9 100644
80094 --- a/sound/aoa/codecs/onyx.h
80095 +++ b/sound/aoa/codecs/onyx.h
80096 @@ -11,6 +11,7 @@
80097 #include <linux/i2c.h>
80098 #include <asm/pmac_low_i2c.h>
80099 #include <asm/prom.h>
80100 +#include <asm/local.h>
80101
80102 /* PCM3052 register definitions */
80103
80104 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
80105 index 3cc4b86..af0a951 100644
80106 --- a/sound/core/oss/pcm_oss.c
80107 +++ b/sound/core/oss/pcm_oss.c
80108 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
80109 if (in_kernel) {
80110 mm_segment_t fs;
80111 fs = snd_enter_user();
80112 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80113 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80114 snd_leave_user(fs);
80115 } else {
80116 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80117 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80118 }
80119 if (ret != -EPIPE && ret != -ESTRPIPE)
80120 break;
80121 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
80122 if (in_kernel) {
80123 mm_segment_t fs;
80124 fs = snd_enter_user();
80125 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80126 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80127 snd_leave_user(fs);
80128 } else {
80129 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80130 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80131 }
80132 if (ret == -EPIPE) {
80133 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
80134 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
80135 struct snd_pcm_plugin_channel *channels;
80136 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
80137 if (!in_kernel) {
80138 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
80139 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
80140 return -EFAULT;
80141 buf = runtime->oss.buffer;
80142 }
80143 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
80144 }
80145 } else {
80146 tmp = snd_pcm_oss_write2(substream,
80147 - (const char __force *)buf,
80148 + (const char __force_kernel *)buf,
80149 runtime->oss.period_bytes, 0);
80150 if (tmp <= 0)
80151 goto err;
80152 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
80153 struct snd_pcm_runtime *runtime = substream->runtime;
80154 snd_pcm_sframes_t frames, frames1;
80155 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
80156 - char __user *final_dst = (char __force __user *)buf;
80157 + char __user *final_dst = (char __force_user *)buf;
80158 if (runtime->oss.plugin_first) {
80159 struct snd_pcm_plugin_channel *channels;
80160 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
80161 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
80162 xfer += tmp;
80163 runtime->oss.buffer_used -= tmp;
80164 } else {
80165 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
80166 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
80167 runtime->oss.period_bytes, 0);
80168 if (tmp <= 0)
80169 goto err;
80170 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
80171 size1);
80172 size1 /= runtime->channels; /* frames */
80173 fs = snd_enter_user();
80174 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
80175 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
80176 snd_leave_user(fs);
80177 }
80178 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
80179 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
80180 index 91cdf94..4085161 100644
80181 --- a/sound/core/pcm_compat.c
80182 +++ b/sound/core/pcm_compat.c
80183 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
80184 int err;
80185
80186 fs = snd_enter_user();
80187 - err = snd_pcm_delay(substream, &delay);
80188 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
80189 snd_leave_user(fs);
80190 if (err < 0)
80191 return err;
80192 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
80193 index 25ed9fe..24c46e9 100644
80194 --- a/sound/core/pcm_native.c
80195 +++ b/sound/core/pcm_native.c
80196 @@ -2765,11 +2765,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
80197 switch (substream->stream) {
80198 case SNDRV_PCM_STREAM_PLAYBACK:
80199 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
80200 - (void __user *)arg);
80201 + (void __force_user *)arg);
80202 break;
80203 case SNDRV_PCM_STREAM_CAPTURE:
80204 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
80205 - (void __user *)arg);
80206 + (void __force_user *)arg);
80207 break;
80208 default:
80209 result = -EINVAL;
80210 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
80211 index 5cf8d65..912a79c 100644
80212 --- a/sound/core/seq/seq_device.c
80213 +++ b/sound/core/seq/seq_device.c
80214 @@ -64,7 +64,7 @@ struct ops_list {
80215 int argsize; /* argument size */
80216
80217 /* operators */
80218 - struct snd_seq_dev_ops ops;
80219 + struct snd_seq_dev_ops *ops;
80220
80221 /* registred devices */
80222 struct list_head dev_list; /* list of devices */
80223 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
80224
80225 mutex_lock(&ops->reg_mutex);
80226 /* copy driver operators */
80227 - ops->ops = *entry;
80228 + ops->ops = entry;
80229 ops->driver |= DRIVER_LOADED;
80230 ops->argsize = argsize;
80231
80232 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
80233 dev->name, ops->id, ops->argsize, dev->argsize);
80234 return -EINVAL;
80235 }
80236 - if (ops->ops.init_device(dev) >= 0) {
80237 + if (ops->ops->init_device(dev) >= 0) {
80238 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
80239 ops->num_init_devices++;
80240 } else {
80241 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
80242 dev->name, ops->id, ops->argsize, dev->argsize);
80243 return -EINVAL;
80244 }
80245 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
80246 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
80247 dev->status = SNDRV_SEQ_DEVICE_FREE;
80248 dev->driver_data = NULL;
80249 ops->num_init_devices--;
80250 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
80251 index f24bf9a..1f7b67c 100644
80252 --- a/sound/drivers/mts64.c
80253 +++ b/sound/drivers/mts64.c
80254 @@ -29,6 +29,7 @@
80255 #include <sound/initval.h>
80256 #include <sound/rawmidi.h>
80257 #include <sound/control.h>
80258 +#include <asm/local.h>
80259
80260 #define CARD_NAME "Miditerminal 4140"
80261 #define DRIVER_NAME "MTS64"
80262 @@ -67,7 +68,7 @@ struct mts64 {
80263 struct pardevice *pardev;
80264 int pardev_claimed;
80265
80266 - int open_count;
80267 + local_t open_count;
80268 int current_midi_output_port;
80269 int current_midi_input_port;
80270 u8 mode[MTS64_NUM_INPUT_PORTS];
80271 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
80272 {
80273 struct mts64 *mts = substream->rmidi->private_data;
80274
80275 - if (mts->open_count == 0) {
80276 + if (local_read(&mts->open_count) == 0) {
80277 /* We don't need a spinlock here, because this is just called
80278 if the device has not been opened before.
80279 So there aren't any IRQs from the device */
80280 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
80281
80282 msleep(50);
80283 }
80284 - ++(mts->open_count);
80285 + local_inc(&mts->open_count);
80286
80287 return 0;
80288 }
80289 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
80290 struct mts64 *mts = substream->rmidi->private_data;
80291 unsigned long flags;
80292
80293 - --(mts->open_count);
80294 - if (mts->open_count == 0) {
80295 + if (local_dec_return(&mts->open_count) == 0) {
80296 /* We need the spinlock_irqsave here because we can still
80297 have IRQs at this point */
80298 spin_lock_irqsave(&mts->lock, flags);
80299 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
80300
80301 msleep(500);
80302
80303 - } else if (mts->open_count < 0)
80304 - mts->open_count = 0;
80305 + } else if (local_read(&mts->open_count) < 0)
80306 + local_set(&mts->open_count, 0);
80307
80308 return 0;
80309 }
80310 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
80311 index b953fb4..1999c01 100644
80312 --- a/sound/drivers/opl4/opl4_lib.c
80313 +++ b/sound/drivers/opl4/opl4_lib.c
80314 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
80315 MODULE_DESCRIPTION("OPL4 driver");
80316 MODULE_LICENSE("GPL");
80317
80318 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
80319 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
80320 {
80321 int timeout = 10;
80322 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
80323 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
80324 index f664823..590c745 100644
80325 --- a/sound/drivers/portman2x4.c
80326 +++ b/sound/drivers/portman2x4.c
80327 @@ -48,6 +48,7 @@
80328 #include <sound/initval.h>
80329 #include <sound/rawmidi.h>
80330 #include <sound/control.h>
80331 +#include <asm/local.h>
80332
80333 #define CARD_NAME "Portman 2x4"
80334 #define DRIVER_NAME "portman"
80335 @@ -85,7 +86,7 @@ struct portman {
80336 struct pardevice *pardev;
80337 int pardev_claimed;
80338
80339 - int open_count;
80340 + local_t open_count;
80341 int mode[PORTMAN_NUM_INPUT_PORTS];
80342 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
80343 };
80344 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
80345 index 87657dd..a8268d4 100644
80346 --- a/sound/firewire/amdtp.c
80347 +++ b/sound/firewire/amdtp.c
80348 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
80349 ptr = s->pcm_buffer_pointer + data_blocks;
80350 if (ptr >= pcm->runtime->buffer_size)
80351 ptr -= pcm->runtime->buffer_size;
80352 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
80353 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
80354
80355 s->pcm_period_pointer += data_blocks;
80356 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
80357 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
80358 */
80359 void amdtp_out_stream_update(struct amdtp_out_stream *s)
80360 {
80361 - ACCESS_ONCE(s->source_node_id_field) =
80362 + ACCESS_ONCE_RW(s->source_node_id_field) =
80363 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
80364 }
80365 EXPORT_SYMBOL(amdtp_out_stream_update);
80366 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
80367 index 537a9cb..8e8c8e9 100644
80368 --- a/sound/firewire/amdtp.h
80369 +++ b/sound/firewire/amdtp.h
80370 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
80371 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
80372 struct snd_pcm_substream *pcm)
80373 {
80374 - ACCESS_ONCE(s->pcm) = pcm;
80375 + ACCESS_ONCE_RW(s->pcm) = pcm;
80376 }
80377
80378 /**
80379 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
80380 index cd094ec..eca1277 100644
80381 --- a/sound/firewire/isight.c
80382 +++ b/sound/firewire/isight.c
80383 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
80384 ptr += count;
80385 if (ptr >= runtime->buffer_size)
80386 ptr -= runtime->buffer_size;
80387 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
80388 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
80389
80390 isight->period_counter += count;
80391 if (isight->period_counter >= runtime->period_size) {
80392 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
80393 if (err < 0)
80394 return err;
80395
80396 - ACCESS_ONCE(isight->pcm_active) = true;
80397 + ACCESS_ONCE_RW(isight->pcm_active) = true;
80398
80399 return 0;
80400 }
80401 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
80402 {
80403 struct isight *isight = substream->private_data;
80404
80405 - ACCESS_ONCE(isight->pcm_active) = false;
80406 + ACCESS_ONCE_RW(isight->pcm_active) = false;
80407
80408 mutex_lock(&isight->mutex);
80409 isight_stop_streaming(isight);
80410 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
80411
80412 switch (cmd) {
80413 case SNDRV_PCM_TRIGGER_START:
80414 - ACCESS_ONCE(isight->pcm_running) = true;
80415 + ACCESS_ONCE_RW(isight->pcm_running) = true;
80416 break;
80417 case SNDRV_PCM_TRIGGER_STOP:
80418 - ACCESS_ONCE(isight->pcm_running) = false;
80419 + ACCESS_ONCE_RW(isight->pcm_running) = false;
80420 break;
80421 default:
80422 return -EINVAL;
80423 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
80424 index c94578d..0794ac1 100644
80425 --- a/sound/isa/cmi8330.c
80426 +++ b/sound/isa/cmi8330.c
80427 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
80428
80429 struct snd_pcm *pcm;
80430 struct snd_cmi8330_stream {
80431 - struct snd_pcm_ops ops;
80432 + snd_pcm_ops_no_const ops;
80433 snd_pcm_open_callback_t open;
80434 void *private_data; /* sb or wss */
80435 } streams[2];
80436 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
80437 index 733b014..56ce96f 100644
80438 --- a/sound/oss/sb_audio.c
80439 +++ b/sound/oss/sb_audio.c
80440 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
80441 buf16 = (signed short *)(localbuf + localoffs);
80442 while (c)
80443 {
80444 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
80445 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
80446 if (copy_from_user(lbuf8,
80447 userbuf+useroffs + p,
80448 locallen))
80449 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
80450 index 09d4648..cf234c7 100644
80451 --- a/sound/oss/swarm_cs4297a.c
80452 +++ b/sound/oss/swarm_cs4297a.c
80453 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
80454 {
80455 struct cs4297a_state *s;
80456 u32 pwr, id;
80457 - mm_segment_t fs;
80458 int rval;
80459 #ifndef CONFIG_BCM_CS4297A_CSWARM
80460 u64 cfg;
80461 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
80462 if (!rval) {
80463 char *sb1250_duart_present;
80464
80465 +#if 0
80466 + mm_segment_t fs;
80467 fs = get_fs();
80468 set_fs(KERNEL_DS);
80469 -#if 0
80470 val = SOUND_MASK_LINE;
80471 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
80472 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
80473 val = initvol[i].vol;
80474 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
80475 }
80476 + set_fs(fs);
80477 // cs4297a_write_ac97(s, 0x18, 0x0808);
80478 #else
80479 // cs4297a_write_ac97(s, 0x5e, 0x180);
80480 cs4297a_write_ac97(s, 0x02, 0x0808);
80481 cs4297a_write_ac97(s, 0x18, 0x0808);
80482 #endif
80483 - set_fs(fs);
80484
80485 list_add(&s->list, &cs4297a_devs);
80486
80487 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
80488 index 71f6744..d8aeae7 100644
80489 --- a/sound/pci/hda/hda_codec.h
80490 +++ b/sound/pci/hda/hda_codec.h
80491 @@ -614,7 +614,7 @@ struct hda_bus_ops {
80492 /* notify power-up/down from codec to controller */
80493 void (*pm_notify)(struct hda_bus *bus);
80494 #endif
80495 -};
80496 +} __no_const;
80497
80498 /* template to pass to the bus constructor */
80499 struct hda_bus_template {
80500 @@ -716,6 +716,7 @@ struct hda_codec_ops {
80501 #endif
80502 void (*reboot_notify)(struct hda_codec *codec);
80503 };
80504 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
80505
80506 /* record for amp information cache */
80507 struct hda_cache_head {
80508 @@ -746,7 +747,7 @@ struct hda_pcm_ops {
80509 struct snd_pcm_substream *substream);
80510 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
80511 struct snd_pcm_substream *substream);
80512 -};
80513 +} __no_const;
80514
80515 /* PCM information for each substream */
80516 struct hda_pcm_stream {
80517 @@ -804,7 +805,7 @@ struct hda_codec {
80518 const char *modelname; /* model name for preset */
80519
80520 /* set by patch */
80521 - struct hda_codec_ops patch_ops;
80522 + hda_codec_ops_no_const patch_ops;
80523
80524 /* PCM to create, set by patch_ops.build_pcms callback */
80525 unsigned int num_pcms;
80526 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
80527 index 0da778a..bc38b84 100644
80528 --- a/sound/pci/ice1712/ice1712.h
80529 +++ b/sound/pci/ice1712/ice1712.h
80530 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
80531 unsigned int mask_flags; /* total mask bits */
80532 struct snd_akm4xxx_ops {
80533 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
80534 - } ops;
80535 + } __no_const ops;
80536 };
80537
80538 struct snd_ice1712_spdif {
80539 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
80540 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80541 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80542 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80543 - } ops;
80544 + } __no_const ops;
80545 };
80546
80547
80548 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
80549 index 03ee4e3..be86b46 100644
80550 --- a/sound/pci/ymfpci/ymfpci_main.c
80551 +++ b/sound/pci/ymfpci/ymfpci_main.c
80552 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
80553 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
80554 break;
80555 }
80556 - if (atomic_read(&chip->interrupt_sleep_count)) {
80557 - atomic_set(&chip->interrupt_sleep_count, 0);
80558 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80559 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80560 wake_up(&chip->interrupt_sleep);
80561 }
80562 __end:
80563 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
80564 continue;
80565 init_waitqueue_entry(&wait, current);
80566 add_wait_queue(&chip->interrupt_sleep, &wait);
80567 - atomic_inc(&chip->interrupt_sleep_count);
80568 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
80569 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
80570 remove_wait_queue(&chip->interrupt_sleep, &wait);
80571 }
80572 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
80573 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
80574 spin_unlock(&chip->reg_lock);
80575
80576 - if (atomic_read(&chip->interrupt_sleep_count)) {
80577 - atomic_set(&chip->interrupt_sleep_count, 0);
80578 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80579 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80580 wake_up(&chip->interrupt_sleep);
80581 }
80582 }
80583 @@ -2382,7 +2382,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
80584 spin_lock_init(&chip->reg_lock);
80585 spin_lock_init(&chip->voice_lock);
80586 init_waitqueue_head(&chip->interrupt_sleep);
80587 - atomic_set(&chip->interrupt_sleep_count, 0);
80588 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80589 chip->card = card;
80590 chip->pci = pci;
80591 chip->irq = -1;
80592 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
80593 index ee15337..e2187a6 100644
80594 --- a/sound/soc/soc-pcm.c
80595 +++ b/sound/soc/soc-pcm.c
80596 @@ -583,7 +583,7 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
80597 }
80598
80599 /* ASoC PCM operations */
80600 -static struct snd_pcm_ops soc_pcm_ops = {
80601 +static snd_pcm_ops_no_const soc_pcm_ops = {
80602 .open = soc_pcm_open,
80603 .close = soc_pcm_close,
80604 .hw_params = soc_pcm_hw_params,
80605 diff --git a/sound/usb/card.h b/sound/usb/card.h
80606 index a39edcc..1014050 100644
80607 --- a/sound/usb/card.h
80608 +++ b/sound/usb/card.h
80609 @@ -44,6 +44,7 @@ struct snd_urb_ops {
80610 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
80611 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
80612 };
80613 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
80614
80615 struct snd_usb_substream {
80616 struct snd_usb_stream *stream;
80617 @@ -93,7 +94,7 @@ struct snd_usb_substream {
80618 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
80619 spinlock_t lock;
80620
80621 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
80622 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
80623 int last_frame_number; /* stored frame number */
80624 int last_delay; /* stored delay */
80625 };
80626 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
80627 new file mode 100644
80628 index 0000000..ca64170
80629 --- /dev/null
80630 +++ b/tools/gcc/Makefile
80631 @@ -0,0 +1,26 @@
80632 +#CC := gcc
80633 +#PLUGIN_SOURCE_FILES := pax_plugin.c
80634 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
80635 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
80636 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
80637 +
80638 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
80639 +CFLAGS_size_overflow_plugin.o := -Wno-missing-initializer
80640 +
80641 +hostlibs-y := constify_plugin.so
80642 +hostlibs-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
80643 +hostlibs-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
80644 +hostlibs-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
80645 +hostlibs-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
80646 +hostlibs-y += colorize_plugin.so
80647 +hostlibs-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
80648 +
80649 +always := $(hostlibs-y)
80650 +
80651 +constify_plugin-objs := constify_plugin.o
80652 +stackleak_plugin-objs := stackleak_plugin.o
80653 +kallocstat_plugin-objs := kallocstat_plugin.o
80654 +kernexec_plugin-objs := kernexec_plugin.o
80655 +checker_plugin-objs := checker_plugin.o
80656 +colorize_plugin-objs := colorize_plugin.o
80657 +size_overflow_plugin-objs := size_overflow_plugin.o
80658 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
80659 new file mode 100644
80660 index 0000000..d41b5af
80661 --- /dev/null
80662 +++ b/tools/gcc/checker_plugin.c
80663 @@ -0,0 +1,171 @@
80664 +/*
80665 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80666 + * Licensed under the GPL v2
80667 + *
80668 + * Note: the choice of the license means that the compilation process is
80669 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80670 + * but for the kernel it doesn't matter since it doesn't link against
80671 + * any of the gcc libraries
80672 + *
80673 + * gcc plugin to implement various sparse (source code checker) features
80674 + *
80675 + * TODO:
80676 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
80677 + *
80678 + * BUGS:
80679 + * - none known
80680 + */
80681 +#include "gcc-plugin.h"
80682 +#include "config.h"
80683 +#include "system.h"
80684 +#include "coretypes.h"
80685 +#include "tree.h"
80686 +#include "tree-pass.h"
80687 +#include "flags.h"
80688 +#include "intl.h"
80689 +#include "toplev.h"
80690 +#include "plugin.h"
80691 +//#include "expr.h" where are you...
80692 +#include "diagnostic.h"
80693 +#include "plugin-version.h"
80694 +#include "tm.h"
80695 +#include "function.h"
80696 +#include "basic-block.h"
80697 +#include "gimple.h"
80698 +#include "rtl.h"
80699 +#include "emit-rtl.h"
80700 +#include "tree-flow.h"
80701 +#include "target.h"
80702 +
80703 +extern void c_register_addr_space (const char *str, addr_space_t as);
80704 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
80705 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
80706 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
80707 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
80708 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
80709 +
80710 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80711 +extern rtx emit_move_insn(rtx x, rtx y);
80712 +
80713 +int plugin_is_GPL_compatible;
80714 +
80715 +static struct plugin_info checker_plugin_info = {
80716 + .version = "201111150100",
80717 +};
80718 +
80719 +#define ADDR_SPACE_KERNEL 0
80720 +#define ADDR_SPACE_FORCE_KERNEL 1
80721 +#define ADDR_SPACE_USER 2
80722 +#define ADDR_SPACE_FORCE_USER 3
80723 +#define ADDR_SPACE_IOMEM 0
80724 +#define ADDR_SPACE_FORCE_IOMEM 0
80725 +#define ADDR_SPACE_PERCPU 0
80726 +#define ADDR_SPACE_FORCE_PERCPU 0
80727 +#define ADDR_SPACE_RCU 0
80728 +#define ADDR_SPACE_FORCE_RCU 0
80729 +
80730 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
80731 +{
80732 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
80733 +}
80734 +
80735 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
80736 +{
80737 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
80738 +}
80739 +
80740 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
80741 +{
80742 + return default_addr_space_valid_pointer_mode(mode, as);
80743 +}
80744 +
80745 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
80746 +{
80747 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
80748 +}
80749 +
80750 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
80751 +{
80752 + return default_addr_space_legitimize_address(x, oldx, mode, as);
80753 +}
80754 +
80755 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
80756 +{
80757 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
80758 + return true;
80759 +
80760 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
80761 + return true;
80762 +
80763 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
80764 + return true;
80765 +
80766 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
80767 + return true;
80768 +
80769 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
80770 + return true;
80771 +
80772 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
80773 + return true;
80774 +
80775 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
80776 + return true;
80777 +
80778 + return subset == superset;
80779 +}
80780 +
80781 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
80782 +{
80783 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
80784 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
80785 +
80786 + return op;
80787 +}
80788 +
80789 +static void register_checker_address_spaces(void *event_data, void *data)
80790 +{
80791 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
80792 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
80793 + c_register_addr_space("__user", ADDR_SPACE_USER);
80794 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
80795 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
80796 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
80797 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
80798 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
80799 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
80800 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
80801 +
80802 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
80803 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
80804 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
80805 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
80806 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
80807 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
80808 + targetm.addr_space.convert = checker_addr_space_convert;
80809 +}
80810 +
80811 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80812 +{
80813 + const char * const plugin_name = plugin_info->base_name;
80814 + const int argc = plugin_info->argc;
80815 + const struct plugin_argument * const argv = plugin_info->argv;
80816 + int i;
80817 +
80818 + if (!plugin_default_version_check(version, &gcc_version)) {
80819 + error(G_("incompatible gcc/plugin versions"));
80820 + return 1;
80821 + }
80822 +
80823 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
80824 +
80825 + for (i = 0; i < argc; ++i)
80826 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80827 +
80828 + if (TARGET_64BIT == 0)
80829 + return 0;
80830 +
80831 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
80832 +
80833 + return 0;
80834 +}
80835 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
80836 new file mode 100644
80837 index 0000000..ee950d0
80838 --- /dev/null
80839 +++ b/tools/gcc/colorize_plugin.c
80840 @@ -0,0 +1,147 @@
80841 +/*
80842 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
80843 + * Licensed under the GPL v2
80844 + *
80845 + * Note: the choice of the license means that the compilation process is
80846 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80847 + * but for the kernel it doesn't matter since it doesn't link against
80848 + * any of the gcc libraries
80849 + *
80850 + * gcc plugin to colorize diagnostic output
80851 + *
80852 + */
80853 +
80854 +#include "gcc-plugin.h"
80855 +#include "config.h"
80856 +#include "system.h"
80857 +#include "coretypes.h"
80858 +#include "tree.h"
80859 +#include "tree-pass.h"
80860 +#include "flags.h"
80861 +#include "intl.h"
80862 +#include "toplev.h"
80863 +#include "plugin.h"
80864 +#include "diagnostic.h"
80865 +#include "plugin-version.h"
80866 +#include "tm.h"
80867 +
80868 +int plugin_is_GPL_compatible;
80869 +
80870 +static struct plugin_info colorize_plugin_info = {
80871 + .version = "201203092200",
80872 +};
80873 +
80874 +#define GREEN "\033[32m\033[2m"
80875 +#define LIGHTGREEN "\033[32m\033[1m"
80876 +#define YELLOW "\033[33m\033[2m"
80877 +#define LIGHTYELLOW "\033[33m\033[1m"
80878 +#define RED "\033[31m\033[2m"
80879 +#define LIGHTRED "\033[31m\033[1m"
80880 +#define BLUE "\033[34m\033[2m"
80881 +#define LIGHTBLUE "\033[34m\033[1m"
80882 +#define BRIGHT "\033[m\033[1m"
80883 +#define NORMAL "\033[m"
80884 +
80885 +static diagnostic_starter_fn old_starter;
80886 +static diagnostic_finalizer_fn old_finalizer;
80887 +
80888 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
80889 +{
80890 + const char *color;
80891 + char *newprefix;
80892 +
80893 + switch (diagnostic->kind) {
80894 + case DK_NOTE:
80895 + color = LIGHTBLUE;
80896 + break;
80897 +
80898 + case DK_PEDWARN:
80899 + case DK_WARNING:
80900 + color = LIGHTYELLOW;
80901 + break;
80902 +
80903 + case DK_ERROR:
80904 + case DK_FATAL:
80905 + case DK_ICE:
80906 + case DK_PERMERROR:
80907 + case DK_SORRY:
80908 + color = LIGHTRED;
80909 + break;
80910 +
80911 + default:
80912 + color = NORMAL;
80913 + }
80914 +
80915 + old_starter(context, diagnostic);
80916 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
80917 + return;
80918 + pp_destroy_prefix(context->printer);
80919 + pp_set_prefix(context->printer, newprefix);
80920 +}
80921 +
80922 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
80923 +{
80924 + old_finalizer(context, diagnostic);
80925 +}
80926 +
80927 +static void colorize_arm(void)
80928 +{
80929 + old_starter = diagnostic_starter(global_dc);
80930 + old_finalizer = diagnostic_finalizer(global_dc);
80931 +
80932 + diagnostic_starter(global_dc) = start_colorize;
80933 + diagnostic_finalizer(global_dc) = finalize_colorize;
80934 +}
80935 +
80936 +static unsigned int execute_colorize_rearm(void)
80937 +{
80938 + if (diagnostic_starter(global_dc) == start_colorize)
80939 + return 0;
80940 +
80941 + colorize_arm();
80942 + return 0;
80943 +}
80944 +
80945 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
80946 + .pass = {
80947 + .type = SIMPLE_IPA_PASS,
80948 + .name = "colorize_rearm",
80949 + .gate = NULL,
80950 + .execute = execute_colorize_rearm,
80951 + .sub = NULL,
80952 + .next = NULL,
80953 + .static_pass_number = 0,
80954 + .tv_id = TV_NONE,
80955 + .properties_required = 0,
80956 + .properties_provided = 0,
80957 + .properties_destroyed = 0,
80958 + .todo_flags_start = 0,
80959 + .todo_flags_finish = 0
80960 + }
80961 +};
80962 +
80963 +static void colorize_start_unit(void *gcc_data, void *user_data)
80964 +{
80965 + colorize_arm();
80966 +}
80967 +
80968 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80969 +{
80970 + const char * const plugin_name = plugin_info->base_name;
80971 + struct register_pass_info colorize_rearm_pass_info = {
80972 + .pass = &pass_ipa_colorize_rearm.pass,
80973 + .reference_pass_name = "*free_lang_data",
80974 + .ref_pass_instance_number = 0,
80975 + .pos_op = PASS_POS_INSERT_AFTER
80976 + };
80977 +
80978 + if (!plugin_default_version_check(version, &gcc_version)) {
80979 + error(G_("incompatible gcc/plugin versions"));
80980 + return 1;
80981 + }
80982 +
80983 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
80984 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
80985 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
80986 + return 0;
80987 +}
80988 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
80989 new file mode 100644
80990 index 0000000..704a564
80991 --- /dev/null
80992 +++ b/tools/gcc/constify_plugin.c
80993 @@ -0,0 +1,303 @@
80994 +/*
80995 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
80996 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
80997 + * Licensed under the GPL v2, or (at your option) v3
80998 + *
80999 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
81000 + *
81001 + * Homepage:
81002 + * http://www.grsecurity.net/~ephox/const_plugin/
81003 + *
81004 + * Usage:
81005 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
81006 + * $ gcc -fplugin=constify_plugin.so test.c -O2
81007 + */
81008 +
81009 +#include "gcc-plugin.h"
81010 +#include "config.h"
81011 +#include "system.h"
81012 +#include "coretypes.h"
81013 +#include "tree.h"
81014 +#include "tree-pass.h"
81015 +#include "flags.h"
81016 +#include "intl.h"
81017 +#include "toplev.h"
81018 +#include "plugin.h"
81019 +#include "diagnostic.h"
81020 +#include "plugin-version.h"
81021 +#include "tm.h"
81022 +#include "function.h"
81023 +#include "basic-block.h"
81024 +#include "gimple.h"
81025 +#include "rtl.h"
81026 +#include "emit-rtl.h"
81027 +#include "tree-flow.h"
81028 +
81029 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
81030 +
81031 +int plugin_is_GPL_compatible;
81032 +
81033 +static struct plugin_info const_plugin_info = {
81034 + .version = "201111150100",
81035 + .help = "no-constify\tturn off constification\n",
81036 +};
81037 +
81038 +static void constify_type(tree type);
81039 +static bool walk_struct(tree node);
81040 +
81041 +static tree deconstify_type(tree old_type)
81042 +{
81043 + tree new_type, field;
81044 +
81045 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
81046 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
81047 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
81048 + DECL_FIELD_CONTEXT(field) = new_type;
81049 + TYPE_READONLY(new_type) = 0;
81050 + C_TYPE_FIELDS_READONLY(new_type) = 0;
81051 + return new_type;
81052 +}
81053 +
81054 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81055 +{
81056 + tree type;
81057 +
81058 + *no_add_attrs = true;
81059 + if (TREE_CODE(*node) == FUNCTION_DECL) {
81060 + error("%qE attribute does not apply to functions", name);
81061 + return NULL_TREE;
81062 + }
81063 +
81064 + if (TREE_CODE(*node) == VAR_DECL) {
81065 + error("%qE attribute does not apply to variables", name);
81066 + return NULL_TREE;
81067 + }
81068 +
81069 + if (TYPE_P(*node)) {
81070 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
81071 + *no_add_attrs = false;
81072 + else
81073 + error("%qE attribute applies to struct and union types only", name);
81074 + return NULL_TREE;
81075 + }
81076 +
81077 + type = TREE_TYPE(*node);
81078 +
81079 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
81080 + error("%qE attribute applies to struct and union types only", name);
81081 + return NULL_TREE;
81082 + }
81083 +
81084 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
81085 + error("%qE attribute is already applied to the type", name);
81086 + return NULL_TREE;
81087 + }
81088 +
81089 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
81090 + error("%qE attribute used on type that is not constified", name);
81091 + return NULL_TREE;
81092 + }
81093 +
81094 + if (TREE_CODE(*node) == TYPE_DECL) {
81095 + TREE_TYPE(*node) = deconstify_type(type);
81096 + TREE_READONLY(*node) = 0;
81097 + return NULL_TREE;
81098 + }
81099 +
81100 + return NULL_TREE;
81101 +}
81102 +
81103 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81104 +{
81105 + *no_add_attrs = true;
81106 + if (!TYPE_P(*node)) {
81107 + error("%qE attribute applies to types only", name);
81108 + return NULL_TREE;
81109 + }
81110 +
81111 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
81112 + error("%qE attribute applies to struct and union types only", name);
81113 + return NULL_TREE;
81114 + }
81115 +
81116 + *no_add_attrs = false;
81117 + constify_type(*node);
81118 + return NULL_TREE;
81119 +}
81120 +
81121 +static struct attribute_spec no_const_attr = {
81122 + .name = "no_const",
81123 + .min_length = 0,
81124 + .max_length = 0,
81125 + .decl_required = false,
81126 + .type_required = false,
81127 + .function_type_required = false,
81128 + .handler = handle_no_const_attribute,
81129 +#if BUILDING_GCC_VERSION >= 4007
81130 + .affects_type_identity = true
81131 +#endif
81132 +};
81133 +
81134 +static struct attribute_spec do_const_attr = {
81135 + .name = "do_const",
81136 + .min_length = 0,
81137 + .max_length = 0,
81138 + .decl_required = false,
81139 + .type_required = false,
81140 + .function_type_required = false,
81141 + .handler = handle_do_const_attribute,
81142 +#if BUILDING_GCC_VERSION >= 4007
81143 + .affects_type_identity = true
81144 +#endif
81145 +};
81146 +
81147 +static void register_attributes(void *event_data, void *data)
81148 +{
81149 + register_attribute(&no_const_attr);
81150 + register_attribute(&do_const_attr);
81151 +}
81152 +
81153 +static void constify_type(tree type)
81154 +{
81155 + TYPE_READONLY(type) = 1;
81156 + C_TYPE_FIELDS_READONLY(type) = 1;
81157 +}
81158 +
81159 +static bool is_fptr(tree field)
81160 +{
81161 + tree ptr = TREE_TYPE(field);
81162 +
81163 + if (TREE_CODE(ptr) != POINTER_TYPE)
81164 + return false;
81165 +
81166 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
81167 +}
81168 +
81169 +static bool walk_struct(tree node)
81170 +{
81171 + tree field;
81172 +
81173 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node)))
81174 + return false;
81175 +
81176 + if (TYPE_FIELDS(node) == NULL_TREE)
81177 + return false;
81178 +
81179 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
81180 + tree type = TREE_TYPE(field);
81181 + enum tree_code code = TREE_CODE(type);
81182 + if (code == RECORD_TYPE || code == UNION_TYPE) {
81183 + if (!(walk_struct(type)))
81184 + return false;
81185 + } else if (!is_fptr(field) && !TREE_READONLY(field))
81186 + return false;
81187 + }
81188 + return true;
81189 +}
81190 +
81191 +static void finish_type(void *event_data, void *data)
81192 +{
81193 + tree type = (tree)event_data;
81194 +
81195 + if (type == NULL_TREE)
81196 + return;
81197 +
81198 + if (TYPE_READONLY(type))
81199 + return;
81200 +
81201 + if (walk_struct(type))
81202 + constify_type(type);
81203 +}
81204 +
81205 +static unsigned int check_local_variables(void);
81206 +
81207 +struct gimple_opt_pass pass_local_variable = {
81208 + {
81209 + .type = GIMPLE_PASS,
81210 + .name = "check_local_variables",
81211 + .gate = NULL,
81212 + .execute = check_local_variables,
81213 + .sub = NULL,
81214 + .next = NULL,
81215 + .static_pass_number = 0,
81216 + .tv_id = TV_NONE,
81217 + .properties_required = 0,
81218 + .properties_provided = 0,
81219 + .properties_destroyed = 0,
81220 + .todo_flags_start = 0,
81221 + .todo_flags_finish = 0
81222 + }
81223 +};
81224 +
81225 +static unsigned int check_local_variables(void)
81226 +{
81227 + tree var;
81228 + referenced_var_iterator rvi;
81229 +
81230 +#if BUILDING_GCC_VERSION == 4005
81231 + FOR_EACH_REFERENCED_VAR(var, rvi) {
81232 +#else
81233 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
81234 +#endif
81235 + tree type = TREE_TYPE(var);
81236 +
81237 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
81238 + continue;
81239 +
81240 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
81241 + continue;
81242 +
81243 + if (!TYPE_READONLY(type))
81244 + continue;
81245 +
81246 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
81247 +// continue;
81248 +
81249 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
81250 +// continue;
81251 +
81252 + if (walk_struct(type)) {
81253 + error("constified variable %qE cannot be local", var);
81254 + return 1;
81255 + }
81256 + }
81257 + return 0;
81258 +}
81259 +
81260 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81261 +{
81262 + const char * const plugin_name = plugin_info->base_name;
81263 + const int argc = plugin_info->argc;
81264 + const struct plugin_argument * const argv = plugin_info->argv;
81265 + int i;
81266 + bool constify = true;
81267 +
81268 + struct register_pass_info local_variable_pass_info = {
81269 + .pass = &pass_local_variable.pass,
81270 + .reference_pass_name = "*referenced_vars",
81271 + .ref_pass_instance_number = 0,
81272 + .pos_op = PASS_POS_INSERT_AFTER
81273 + };
81274 +
81275 + if (!plugin_default_version_check(version, &gcc_version)) {
81276 + error(G_("incompatible gcc/plugin versions"));
81277 + return 1;
81278 + }
81279 +
81280 + for (i = 0; i < argc; ++i) {
81281 + if (!(strcmp(argv[i].key, "no-constify"))) {
81282 + constify = false;
81283 + continue;
81284 + }
81285 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81286 + }
81287 +
81288 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
81289 + if (constify) {
81290 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
81291 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
81292 + }
81293 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
81294 +
81295 + return 0;
81296 +}
81297 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
81298 new file mode 100644
81299 index 0000000..a5eabce
81300 --- /dev/null
81301 +++ b/tools/gcc/kallocstat_plugin.c
81302 @@ -0,0 +1,167 @@
81303 +/*
81304 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81305 + * Licensed under the GPL v2
81306 + *
81307 + * Note: the choice of the license means that the compilation process is
81308 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81309 + * but for the kernel it doesn't matter since it doesn't link against
81310 + * any of the gcc libraries
81311 + *
81312 + * gcc plugin to find the distribution of k*alloc sizes
81313 + *
81314 + * TODO:
81315 + *
81316 + * BUGS:
81317 + * - none known
81318 + */
81319 +#include "gcc-plugin.h"
81320 +#include "config.h"
81321 +#include "system.h"
81322 +#include "coretypes.h"
81323 +#include "tree.h"
81324 +#include "tree-pass.h"
81325 +#include "flags.h"
81326 +#include "intl.h"
81327 +#include "toplev.h"
81328 +#include "plugin.h"
81329 +//#include "expr.h" where are you...
81330 +#include "diagnostic.h"
81331 +#include "plugin-version.h"
81332 +#include "tm.h"
81333 +#include "function.h"
81334 +#include "basic-block.h"
81335 +#include "gimple.h"
81336 +#include "rtl.h"
81337 +#include "emit-rtl.h"
81338 +
81339 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81340 +
81341 +int plugin_is_GPL_compatible;
81342 +
81343 +static const char * const kalloc_functions[] = {
81344 + "__kmalloc",
81345 + "kmalloc",
81346 + "kmalloc_large",
81347 + "kmalloc_node",
81348 + "kmalloc_order",
81349 + "kmalloc_order_trace",
81350 + "kmalloc_slab",
81351 + "kzalloc",
81352 + "kzalloc_node",
81353 +};
81354 +
81355 +static struct plugin_info kallocstat_plugin_info = {
81356 + .version = "201111150100",
81357 +};
81358 +
81359 +static unsigned int execute_kallocstat(void);
81360 +
81361 +static struct gimple_opt_pass kallocstat_pass = {
81362 + .pass = {
81363 + .type = GIMPLE_PASS,
81364 + .name = "kallocstat",
81365 + .gate = NULL,
81366 + .execute = execute_kallocstat,
81367 + .sub = NULL,
81368 + .next = NULL,
81369 + .static_pass_number = 0,
81370 + .tv_id = TV_NONE,
81371 + .properties_required = 0,
81372 + .properties_provided = 0,
81373 + .properties_destroyed = 0,
81374 + .todo_flags_start = 0,
81375 + .todo_flags_finish = 0
81376 + }
81377 +};
81378 +
81379 +static bool is_kalloc(const char *fnname)
81380 +{
81381 + size_t i;
81382 +
81383 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
81384 + if (!strcmp(fnname, kalloc_functions[i]))
81385 + return true;
81386 + return false;
81387 +}
81388 +
81389 +static unsigned int execute_kallocstat(void)
81390 +{
81391 + basic_block bb;
81392 +
81393 + // 1. loop through BBs and GIMPLE statements
81394 + FOR_EACH_BB(bb) {
81395 + gimple_stmt_iterator gsi;
81396 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81397 + // gimple match:
81398 + tree fndecl, size;
81399 + gimple call_stmt;
81400 + const char *fnname;
81401 +
81402 + // is it a call
81403 + call_stmt = gsi_stmt(gsi);
81404 + if (!is_gimple_call(call_stmt))
81405 + continue;
81406 + fndecl = gimple_call_fndecl(call_stmt);
81407 + if (fndecl == NULL_TREE)
81408 + continue;
81409 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
81410 + continue;
81411 +
81412 + // is it a call to k*alloc
81413 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
81414 + if (!is_kalloc(fnname))
81415 + continue;
81416 +
81417 + // is the size arg the result of a simple const assignment
81418 + size = gimple_call_arg(call_stmt, 0);
81419 + while (true) {
81420 + gimple def_stmt;
81421 + expanded_location xloc;
81422 + size_t size_val;
81423 +
81424 + if (TREE_CODE(size) != SSA_NAME)
81425 + break;
81426 + def_stmt = SSA_NAME_DEF_STMT(size);
81427 + if (!def_stmt || !is_gimple_assign(def_stmt))
81428 + break;
81429 + if (gimple_num_ops(def_stmt) != 2)
81430 + break;
81431 + size = gimple_assign_rhs1(def_stmt);
81432 + if (!TREE_CONSTANT(size))
81433 + continue;
81434 + xloc = expand_location(gimple_location(def_stmt));
81435 + if (!xloc.file)
81436 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
81437 + size_val = TREE_INT_CST_LOW(size);
81438 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
81439 + break;
81440 + }
81441 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81442 +//debug_tree(gimple_call_fn(call_stmt));
81443 +//print_node(stderr, "pax", fndecl, 4);
81444 + }
81445 + }
81446 +
81447 + return 0;
81448 +}
81449 +
81450 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81451 +{
81452 + const char * const plugin_name = plugin_info->base_name;
81453 + struct register_pass_info kallocstat_pass_info = {
81454 + .pass = &kallocstat_pass.pass,
81455 + .reference_pass_name = "ssa",
81456 + .ref_pass_instance_number = 0,
81457 + .pos_op = PASS_POS_INSERT_AFTER
81458 + };
81459 +
81460 + if (!plugin_default_version_check(version, &gcc_version)) {
81461 + error(G_("incompatible gcc/plugin versions"));
81462 + return 1;
81463 + }
81464 +
81465 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
81466 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
81467 +
81468 + return 0;
81469 +}
81470 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
81471 new file mode 100644
81472 index 0000000..008f159
81473 --- /dev/null
81474 +++ b/tools/gcc/kernexec_plugin.c
81475 @@ -0,0 +1,427 @@
81476 +/*
81477 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81478 + * Licensed under the GPL v2
81479 + *
81480 + * Note: the choice of the license means that the compilation process is
81481 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81482 + * but for the kernel it doesn't matter since it doesn't link against
81483 + * any of the gcc libraries
81484 + *
81485 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
81486 + *
81487 + * TODO:
81488 + *
81489 + * BUGS:
81490 + * - none known
81491 + */
81492 +#include "gcc-plugin.h"
81493 +#include "config.h"
81494 +#include "system.h"
81495 +#include "coretypes.h"
81496 +#include "tree.h"
81497 +#include "tree-pass.h"
81498 +#include "flags.h"
81499 +#include "intl.h"
81500 +#include "toplev.h"
81501 +#include "plugin.h"
81502 +//#include "expr.h" where are you...
81503 +#include "diagnostic.h"
81504 +#include "plugin-version.h"
81505 +#include "tm.h"
81506 +#include "function.h"
81507 +#include "basic-block.h"
81508 +#include "gimple.h"
81509 +#include "rtl.h"
81510 +#include "emit-rtl.h"
81511 +#include "tree-flow.h"
81512 +
81513 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81514 +extern rtx emit_move_insn(rtx x, rtx y);
81515 +
81516 +int plugin_is_GPL_compatible;
81517 +
81518 +static struct plugin_info kernexec_plugin_info = {
81519 + .version = "201111291120",
81520 + .help = "method=[bts|or]\tinstrumentation method\n"
81521 +};
81522 +
81523 +static unsigned int execute_kernexec_reload(void);
81524 +static unsigned int execute_kernexec_fptr(void);
81525 +static unsigned int execute_kernexec_retaddr(void);
81526 +static bool kernexec_cmodel_check(void);
81527 +
81528 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
81529 +static void (*kernexec_instrument_retaddr)(rtx);
81530 +
81531 +static struct gimple_opt_pass kernexec_reload_pass = {
81532 + .pass = {
81533 + .type = GIMPLE_PASS,
81534 + .name = "kernexec_reload",
81535 + .gate = kernexec_cmodel_check,
81536 + .execute = execute_kernexec_reload,
81537 + .sub = NULL,
81538 + .next = NULL,
81539 + .static_pass_number = 0,
81540 + .tv_id = TV_NONE,
81541 + .properties_required = 0,
81542 + .properties_provided = 0,
81543 + .properties_destroyed = 0,
81544 + .todo_flags_start = 0,
81545 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81546 + }
81547 +};
81548 +
81549 +static struct gimple_opt_pass kernexec_fptr_pass = {
81550 + .pass = {
81551 + .type = GIMPLE_PASS,
81552 + .name = "kernexec_fptr",
81553 + .gate = kernexec_cmodel_check,
81554 + .execute = execute_kernexec_fptr,
81555 + .sub = NULL,
81556 + .next = NULL,
81557 + .static_pass_number = 0,
81558 + .tv_id = TV_NONE,
81559 + .properties_required = 0,
81560 + .properties_provided = 0,
81561 + .properties_destroyed = 0,
81562 + .todo_flags_start = 0,
81563 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81564 + }
81565 +};
81566 +
81567 +static struct rtl_opt_pass kernexec_retaddr_pass = {
81568 + .pass = {
81569 + .type = RTL_PASS,
81570 + .name = "kernexec_retaddr",
81571 + .gate = kernexec_cmodel_check,
81572 + .execute = execute_kernexec_retaddr,
81573 + .sub = NULL,
81574 + .next = NULL,
81575 + .static_pass_number = 0,
81576 + .tv_id = TV_NONE,
81577 + .properties_required = 0,
81578 + .properties_provided = 0,
81579 + .properties_destroyed = 0,
81580 + .todo_flags_start = 0,
81581 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
81582 + }
81583 +};
81584 +
81585 +static bool kernexec_cmodel_check(void)
81586 +{
81587 + tree section;
81588 +
81589 + if (ix86_cmodel != CM_KERNEL)
81590 + return false;
81591 +
81592 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
81593 + if (!section || !TREE_VALUE(section))
81594 + return true;
81595 +
81596 + section = TREE_VALUE(TREE_VALUE(section));
81597 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
81598 + return true;
81599 +
81600 + return false;
81601 +}
81602 +
81603 +/*
81604 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
81605 + */
81606 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
81607 +{
81608 + gimple asm_movabs_stmt;
81609 +
81610 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
81611 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
81612 + gimple_asm_set_volatile(asm_movabs_stmt, true);
81613 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
81614 + update_stmt(asm_movabs_stmt);
81615 +}
81616 +
81617 +/*
81618 + * find all asm() stmts that clobber r10 and add a reload of r10
81619 + */
81620 +static unsigned int execute_kernexec_reload(void)
81621 +{
81622 + basic_block bb;
81623 +
81624 + // 1. loop through BBs and GIMPLE statements
81625 + FOR_EACH_BB(bb) {
81626 + gimple_stmt_iterator gsi;
81627 +
81628 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81629 + // gimple match: __asm__ ("" : : : "r10");
81630 + gimple asm_stmt;
81631 + size_t nclobbers;
81632 +
81633 + // is it an asm ...
81634 + asm_stmt = gsi_stmt(gsi);
81635 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
81636 + continue;
81637 +
81638 + // ... clobbering r10
81639 + nclobbers = gimple_asm_nclobbers(asm_stmt);
81640 + while (nclobbers--) {
81641 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
81642 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
81643 + continue;
81644 + kernexec_reload_fptr_mask(&gsi);
81645 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
81646 + break;
81647 + }
81648 + }
81649 + }
81650 +
81651 + return 0;
81652 +}
81653 +
81654 +/*
81655 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
81656 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
81657 + */
81658 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
81659 +{
81660 + gimple assign_intptr, assign_new_fptr, call_stmt;
81661 + tree intptr, old_fptr, new_fptr, kernexec_mask;
81662 +
81663 + call_stmt = gsi_stmt(*gsi);
81664 + old_fptr = gimple_call_fn(call_stmt);
81665 +
81666 + // create temporary unsigned long variable used for bitops and cast fptr to it
81667 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
81668 + add_referenced_var(intptr);
81669 + mark_sym_for_renaming(intptr);
81670 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
81671 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
81672 + update_stmt(assign_intptr);
81673 +
81674 + // apply logical or to temporary unsigned long and bitmask
81675 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
81676 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
81677 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
81678 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
81679 + update_stmt(assign_intptr);
81680 +
81681 + // cast temporary unsigned long back to a temporary fptr variable
81682 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec");
81683 + add_referenced_var(new_fptr);
81684 + mark_sym_for_renaming(new_fptr);
81685 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
81686 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
81687 + update_stmt(assign_new_fptr);
81688 +
81689 + // replace call stmt fn with the new fptr
81690 + gimple_call_set_fn(call_stmt, new_fptr);
81691 + update_stmt(call_stmt);
81692 +}
81693 +
81694 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
81695 +{
81696 + gimple asm_or_stmt, call_stmt;
81697 + tree old_fptr, new_fptr, input, output;
81698 + VEC(tree, gc) *inputs = NULL;
81699 + VEC(tree, gc) *outputs = NULL;
81700 +
81701 + call_stmt = gsi_stmt(*gsi);
81702 + old_fptr = gimple_call_fn(call_stmt);
81703 +
81704 + // create temporary fptr variable
81705 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
81706 + add_referenced_var(new_fptr);
81707 + mark_sym_for_renaming(new_fptr);
81708 +
81709 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
81710 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
81711 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
81712 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
81713 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
81714 + VEC_safe_push(tree, gc, inputs, input);
81715 + VEC_safe_push(tree, gc, outputs, output);
81716 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
81717 + gimple_asm_set_volatile(asm_or_stmt, true);
81718 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
81719 + update_stmt(asm_or_stmt);
81720 +
81721 + // replace call stmt fn with the new fptr
81722 + gimple_call_set_fn(call_stmt, new_fptr);
81723 + update_stmt(call_stmt);
81724 +}
81725 +
81726 +/*
81727 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
81728 + */
81729 +static unsigned int execute_kernexec_fptr(void)
81730 +{
81731 + basic_block bb;
81732 +
81733 + // 1. loop through BBs and GIMPLE statements
81734 + FOR_EACH_BB(bb) {
81735 + gimple_stmt_iterator gsi;
81736 +
81737 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81738 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
81739 + tree fn;
81740 + gimple call_stmt;
81741 +
81742 + // is it a call ...
81743 + call_stmt = gsi_stmt(gsi);
81744 + if (!is_gimple_call(call_stmt))
81745 + continue;
81746 + fn = gimple_call_fn(call_stmt);
81747 + if (TREE_CODE(fn) == ADDR_EXPR)
81748 + continue;
81749 + if (TREE_CODE(fn) != SSA_NAME)
81750 + gcc_unreachable();
81751 +
81752 + // ... through a function pointer
81753 + fn = SSA_NAME_VAR(fn);
81754 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
81755 + continue;
81756 + fn = TREE_TYPE(fn);
81757 + if (TREE_CODE(fn) != POINTER_TYPE)
81758 + continue;
81759 + fn = TREE_TYPE(fn);
81760 + if (TREE_CODE(fn) != FUNCTION_TYPE)
81761 + continue;
81762 +
81763 + kernexec_instrument_fptr(&gsi);
81764 +
81765 +//debug_tree(gimple_call_fn(call_stmt));
81766 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81767 + }
81768 + }
81769 +
81770 + return 0;
81771 +}
81772 +
81773 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
81774 +static void kernexec_instrument_retaddr_bts(rtx insn)
81775 +{
81776 + rtx btsq;
81777 + rtvec argvec, constraintvec, labelvec;
81778 + int line;
81779 +
81780 + // create asm volatile("btsq $63,(%%rsp)":::)
81781 + argvec = rtvec_alloc(0);
81782 + constraintvec = rtvec_alloc(0);
81783 + labelvec = rtvec_alloc(0);
81784 + line = expand_location(RTL_LOCATION(insn)).line;
81785 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81786 + MEM_VOLATILE_P(btsq) = 1;
81787 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
81788 + emit_insn_before(btsq, insn);
81789 +}
81790 +
81791 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
81792 +static void kernexec_instrument_retaddr_or(rtx insn)
81793 +{
81794 + rtx orq;
81795 + rtvec argvec, constraintvec, labelvec;
81796 + int line;
81797 +
81798 + // create asm volatile("orq %%r10,(%%rsp)":::)
81799 + argvec = rtvec_alloc(0);
81800 + constraintvec = rtvec_alloc(0);
81801 + labelvec = rtvec_alloc(0);
81802 + line = expand_location(RTL_LOCATION(insn)).line;
81803 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81804 + MEM_VOLATILE_P(orq) = 1;
81805 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
81806 + emit_insn_before(orq, insn);
81807 +}
81808 +
81809 +/*
81810 + * find all asm level function returns and forcibly set the highest bit of the return address
81811 + */
81812 +static unsigned int execute_kernexec_retaddr(void)
81813 +{
81814 + rtx insn;
81815 +
81816 + // 1. find function returns
81817 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
81818 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
81819 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
81820 + rtx body;
81821 +
81822 + // is it a retn
81823 + if (!JUMP_P(insn))
81824 + continue;
81825 + body = PATTERN(insn);
81826 + if (GET_CODE(body) == PARALLEL)
81827 + body = XVECEXP(body, 0, 0);
81828 + if (GET_CODE(body) != RETURN)
81829 + continue;
81830 + kernexec_instrument_retaddr(insn);
81831 + }
81832 +
81833 +// print_simple_rtl(stderr, get_insns());
81834 +// print_rtl(stderr, get_insns());
81835 +
81836 + return 0;
81837 +}
81838 +
81839 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81840 +{
81841 + const char * const plugin_name = plugin_info->base_name;
81842 + const int argc = plugin_info->argc;
81843 + const struct plugin_argument * const argv = plugin_info->argv;
81844 + int i;
81845 + struct register_pass_info kernexec_reload_pass_info = {
81846 + .pass = &kernexec_reload_pass.pass,
81847 + .reference_pass_name = "ssa",
81848 + .ref_pass_instance_number = 0,
81849 + .pos_op = PASS_POS_INSERT_AFTER
81850 + };
81851 + struct register_pass_info kernexec_fptr_pass_info = {
81852 + .pass = &kernexec_fptr_pass.pass,
81853 + .reference_pass_name = "ssa",
81854 + .ref_pass_instance_number = 0,
81855 + .pos_op = PASS_POS_INSERT_AFTER
81856 + };
81857 + struct register_pass_info kernexec_retaddr_pass_info = {
81858 + .pass = &kernexec_retaddr_pass.pass,
81859 + .reference_pass_name = "pro_and_epilogue",
81860 + .ref_pass_instance_number = 0,
81861 + .pos_op = PASS_POS_INSERT_AFTER
81862 + };
81863 +
81864 + if (!plugin_default_version_check(version, &gcc_version)) {
81865 + error(G_("incompatible gcc/plugin versions"));
81866 + return 1;
81867 + }
81868 +
81869 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
81870 +
81871 + if (TARGET_64BIT == 0)
81872 + return 0;
81873 +
81874 + for (i = 0; i < argc; ++i) {
81875 + if (!strcmp(argv[i].key, "method")) {
81876 + if (!argv[i].value) {
81877 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81878 + continue;
81879 + }
81880 + if (!strcmp(argv[i].value, "bts")) {
81881 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
81882 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
81883 + } else if (!strcmp(argv[i].value, "or")) {
81884 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
81885 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
81886 + fix_register("r10", 1, 1);
81887 + } else
81888 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
81889 + continue;
81890 + }
81891 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81892 + }
81893 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
81894 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
81895 +
81896 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
81897 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
81898 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
81899 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
81900 +
81901 + return 0;
81902 +}
81903 diff --git a/tools/gcc/size_overflow_hash1.h b/tools/gcc/size_overflow_hash1.h
81904 new file mode 100644
81905 index 0000000..55a1292
81906 --- /dev/null
81907 +++ b/tools/gcc/size_overflow_hash1.h
81908 @@ -0,0 +1,2760 @@
81909 +struct size_overflow_hash size_overflow_hash1[65536] = {
81910 + [10013].file = "security/smack/smackfs.c",
81911 + [10013].name = "smk_write_direct",
81912 + [10013].param3 = 1,
81913 + [10167].file = "sound/core/oss/pcm_plugin.c",
81914 + [10167].name = "snd_pcm_plugin_build",
81915 + [10167].param5 = 1,
81916 + [1020].file = "drivers/usb/misc/usbtest.c",
81917 + [1020].name = "test_unaligned_bulk",
81918 + [1020].param3 = 1,
81919 + [1022].file = "sound/pci/rme9652/rme9652.c",
81920 + [1022].name = "snd_rme9652_playback_copy",
81921 + [1022].param5 = 1,
81922 + [10341].file = "fs/nfsd/nfs4xdr.c",
81923 + [10341].name = "read_buf",
81924 + [10341].param2 = 1,
81925 + [10357].file = "net/sunrpc/cache.c",
81926 + [10357].name = "cache_read",
81927 + [10357].param3 = 1,
81928 + [10397].file = "drivers/gpu/drm/i915/i915_debugfs.c",
81929 + [10397].name = "i915_wedged_write",
81930 + [10397].param3 = 1,
81931 + [10414].file = "drivers/tty/vt/vt.c",
81932 + [10414].name = "vc_do_resize",
81933 + [10414].param3 = 1,
81934 + [10414].param4 = 1,
81935 + [10496].file = "drivers/bluetooth/hci_vhci.c",
81936 + [10496].name = "vhci_read",
81937 + [10496].param3 = 1,
81938 + [10565].file = "drivers/input/touchscreen/ad7879-spi.c",
81939 + [10565].name = "ad7879_spi_multi_read",
81940 + [10565].param3 = 1,
81941 + [10623].file = "drivers/infiniband/core/user_mad.c",
81942 + [10623].name = "ib_umad_write",
81943 + [10623].param3 = 1,
81944 + [10707].file = "fs/nfs/idmap.c",
81945 + [10707].name = "nfs_idmap_request_key",
81946 + [10707].param2 = 1,
81947 + [10773].file = "drivers/input/mousedev.c",
81948 + [10773].name = "mousedev_read",
81949 + [10773].param3 = 1,
81950 + [10777].file = "fs/ntfs/file.c",
81951 + [10777].name = "ntfs_file_buffered_write",
81952 + [10777].param6 = 1,
81953 + [10919].file = "net/ipv4/netfilter/arp_tables.c",
81954 + [10919].name = "do_arpt_set_ctl",
81955 + [10919].param4 = 1,
81956 + [11054].file = "drivers/net/wireless/libertas/debugfs.c",
81957 + [11054].name = "lbs_wrmac_write",
81958 + [11054].param3 = 1,
81959 + [11068].file = "drivers/net/wireless/libertas/debugfs.c",
81960 + [11068].name = "lbs_wrrf_write",
81961 + [11068].param3 = 1,
81962 + [11364].file = "fs/ext4/super.c",
81963 + [11364].name = "ext4_kvzalloc",
81964 + [11364].param1 = 1,
81965 + [11402].file = "drivers/net/wireless/libertas/debugfs.c",
81966 + [11402].name = "lbs_threshold_write",
81967 + [11402].param5 = 1,
81968 + [11494].file = "drivers/video/via/viafbdev.c",
81969 + [11494].name = "viafb_dvp1_proc_write",
81970 + [11494].param3 = 1,
81971 + [11616].file = "security/selinux/selinuxfs.c",
81972 + [11616].name = "sel_write_enforce",
81973 + [11616].param3 = 1,
81974 + [11699].file = "drivers/net/ethernet/neterion/vxge/vxge-config.h",
81975 + [11699].name = "vxge_os_dma_malloc",
81976 + [11699].param2 = 1,
81977 + [11766].file = "drivers/block/paride/pt.c",
81978 + [11766].name = "pt_read",
81979 + [11766].param3 = 1,
81980 + [11784].file = "fs/bio.c",
81981 + [11784].name = "bio_kmalloc",
81982 + [11784].param2 = 1,
81983 + [11814].file = "drivers/staging/speakup/kobjects.c",
81984 + [11814].name = "keymap_store",
81985 + [11814].param4 = 1,
81986 + [11912].file = "net/sunrpc/cache.c",
81987 + [11912].name = "cache_write_pipefs",
81988 + [11912].param3 = 1,
81989 + [11919].file = "drivers/lguest/core.c",
81990 + [11919].name = "__lgread",
81991 + [11919].param4 = 1,
81992 + [11986].file = "drivers/net/usb/asix.c",
81993 + [11986].name = "asix_read_cmd",
81994 + [11986].param5 = 1,
81995 + [12059].file = "drivers/net/wireless/libertas/debugfs.c",
81996 + [12059].name = "lbs_debugfs_write",
81997 + [12059].param3 = 1,
81998 + [12071].file = "lib/kstrtox.c",
81999 + [12071].name = "kstrtou8_from_user",
82000 + [12071].param2 = 1,
82001 + [12151].file = "fs/compat.c",
82002 + [12151].name = "compat_rw_copy_check_uvector",
82003 + [12151].param3 = 1,
82004 + [12205].file = "fs/reiserfs/journal.c",
82005 + [12205].name = "reiserfs_allocate_list_bitmaps",
82006 + [12205].param3 = 1,
82007 + [12234].file = "include/acpi/platform/aclinux.h",
82008 + [12234].name = "acpi_os_allocate",
82009 + [12234].param1 = 1,
82010 + [1227].file = "lib/cpu_rmap.c",
82011 + [1227].name = "alloc_cpu_rmap",
82012 + [1227].param1 = 1,
82013 + [12395].file = "drivers/char/hw_random/core.c",
82014 + [12395].name = "rng_dev_read",
82015 + [12395].param3 = 1,
82016 + [1248].file = "kernel/kprobes.c",
82017 + [1248].name = "write_enabled_file_bool",
82018 + [1248].param3 = 1,
82019 + [12501].file = "net/mac80211/debugfs.c",
82020 + [12501].name = "uapsd_max_sp_len_write",
82021 + [12501].param3 = 1,
82022 + [12591].file = "sound/core/pcm_lib.c",
82023 + [12591].name = "snd_pcm_lib_writev_transfer",
82024 + [12591].param5 = 1,
82025 + [12602].file = "net/sunrpc/cache.c",
82026 + [12602].name = "cache_downcall",
82027 + [12602].param3 = 1,
82028 + [12712].file = "drivers/net/wimax/i2400m/fw.c",
82029 + [12712].name = "i2400m_zrealloc_2x",
82030 + [12712].param3 = 1,
82031 + [12755].file = "sound/drivers/opl4/opl4_proc.c",
82032 + [12755].name = "snd_opl4_mem_proc_read",
82033 + [12755].param5 = 1,
82034 + [12833].file = "net/sctp/auth.c",
82035 + [12833].name = "sctp_auth_create_key",
82036 + [12833].param1 = 1,
82037 + [12840].file = "net/sctp/tsnmap.c",
82038 + [12840].name = "sctp_tsnmap_mark",
82039 + [12840].param2 = 1,
82040 + [12896].file = "drivers/net/wireless/wl12xx/debugfs.c",
82041 + [12896].name = "beacon_filtering_write",
82042 + [12896].param3 = 1,
82043 + [12931].file = "drivers/hid/hid-roccat.c",
82044 + [12931].name = "roccat_read",
82045 + [12931].param3 = 1,
82046 + [12954].file = "fs/proc/base.c",
82047 + [12954].name = "oom_adjust_write",
82048 + [12954].param3 = 1,
82049 + [13013].file = "drivers/media/dvb/ttpci/av7110_ca.c",
82050 + [13013].name = "dvb_ca_write",
82051 + [13013].param3 = 1,
82052 + [13103].file = "drivers/acpi/acpica/utobject.c",
82053 + [13103].name = "acpi_ut_create_string_object",
82054 + [13103].param1 = 1,
82055 + [13121].file = "net/ipv4/ip_sockglue.c",
82056 + [13121].name = "do_ip_setsockopt",
82057 + [13121].param5 = 1,
82058 + [13337].file = "net/core/iovec.c",
82059 + [13337].name = "csum_partial_copy_fromiovecend",
82060 + [13337].param4 = 1,
82061 + [13339].file = "security/smack/smackfs.c",
82062 + [13339].name = "smk_write_netlbladdr",
82063 + [13339].param3 = 1,
82064 + [13342].file = "fs/jbd2/journal.c",
82065 + [13342].name = "jbd2_alloc",
82066 + [13342].param1 = 1,
82067 + [13412].file = "fs/proc/base.c",
82068 + [13412].name = "oom_score_adj_write",
82069 + [13412].param3 = 1,
82070 + [13659].file = "drivers/net/wan/hdlc.c",
82071 + [13659].name = "attach_hdlc_protocol",
82072 + [13659].param3 = 1,
82073 + [13708].file = "drivers/usb/misc/usbtest.c",
82074 + [13708].name = "simple_alloc_urb",
82075 + [13708].param3 = 1,
82076 + [13863].file = "drivers/net/wireless/iwlwifi/iwl-agn-rs.c",
82077 + [13863].name = "rs_sta_dbgfs_scale_table_write",
82078 + [13863].param3 = 1,
82079 + [13924].file = "net/ipv4/netfilter/ip_tables.c",
82080 + [13924].name = "do_ipt_set_ctl",
82081 + [13924].param4 = 1,
82082 + [14019].file = "net/dns_resolver/dns_key.c",
82083 + [14019].name = "dns_resolver_instantiate",
82084 + [14019].param2 = 1,
82085 + [14019].param3 = 1,
82086 + [14025].file = "net/ax25/af_ax25.c",
82087 + [14025].name = "ax25_setsockopt",
82088 + [14025].param5 = 1,
82089 + [14029].file = "drivers/spi/spidev.c",
82090 + [14029].name = "spidev_compat_ioctl",
82091 + [14029].param2 = 1,
82092 + [14031].file = "drivers/net/wireless/ath/ath5k/debug.c",
82093 + [14031].name = "write_file_beacon",
82094 + [14031].param3 = 1,
82095 + [14086].file = "fs/nfs/nfs4proc.c",
82096 + [14086].name = "nfs4_reset_slot_table",
82097 + [14086].param2 = 1,
82098 + [14090].file = "drivers/bluetooth/btmrvl_debugfs.c",
82099 + [14090].name = "btmrvl_hsmode_write",
82100 + [14090].param3 = 1,
82101 + [14125].file = "kernel/module.c",
82102 + [14125].name = "load_module",
82103 + [14125].param2 = 1,
82104 + [14149].file = "drivers/hid/hidraw.c",
82105 + [14149].name = "hidraw_ioctl",
82106 + [14149].param2 = 1,
82107 + [14153].file = "drivers/staging/bcm/led_control.c",
82108 + [14153].name = "ValidateDSDParamsChecksum",
82109 + [14153].param3 = 1,
82110 + [14174].file = "sound/pci/es1938.c",
82111 + [14174].name = "snd_es1938_capture_copy",
82112 + [14174].param5 = 1,
82113 + [14207].file = "drivers/media/video/v4l2-event.c",
82114 + [14207].name = "v4l2_event_subscribe",
82115 + [14207].param3 = 1,
82116 + [14241].file = "drivers/platform/x86/asus_acpi.c",
82117 + [14241].name = "brn_proc_write",
82118 + [14241].param3 = 1,
82119 + [14299].file = "sound/core/oss/pcm_plugin.c",
82120 + [14299].name = "snd_pcm_plugin_alloc",
82121 + [14299].param2 = 1,
82122 + [14345].file = "fs/cachefiles/daemon.c",
82123 + [14345].name = "cachefiles_daemon_write",
82124 + [14345].param3 = 1,
82125 + [14347].file = "drivers/media/dvb/dvb-core/dvb_ca_en50221.c",
82126 + [14347].name = "dvb_ca_en50221_io_write",
82127 + [14347].param3 = 1,
82128 + [14462].file = "fs/namei.c",
82129 + [14462].name = "sys_rmdir",
82130 + [14462].param1 = 1,
82131 + [14478].file = "drivers/char/random.c",
82132 + [14478].name = "random_write",
82133 + [14478].param3 = 1,
82134 + [1458].file = "drivers/misc/lkdtm.c",
82135 + [1458].name = "direct_entry",
82136 + [1458].param3 = 1,
82137 + [145].file = "lib/xz/xz_dec_test.c",
82138 + [145].name = "xz_dec_test_write",
82139 + [145].param3 = 1,
82140 + [14646].file = "fs/compat.c",
82141 + [14646].name = "compat_writev",
82142 + [14646].param3 = 1,
82143 + [14736].file = "drivers/usb/misc/usbtest.c",
82144 + [14736].name = "unlink_queued",
82145 + [14736].param3 = 1,
82146 + [14842].file = "fs/namei.c",
82147 + [14842].name = "sys_renameat",
82148 + [14842].param2 = 1,
82149 + [14842].param4 = 1,
82150 + [15017].file = "drivers/edac/edac_device.c",
82151 + [15017].name = "edac_device_alloc_ctl_info",
82152 + [15017].param1 = 1,
82153 + [15087].file = "fs/bio.c",
82154 + [15087].name = "bio_map_kern",
82155 + [15087].param2 = 1,
82156 + [15087].param3 = 1,
82157 + [15112].file = "drivers/xen/evtchn.c",
82158 + [15112].name = "evtchn_write",
82159 + [15112].param3 = 1,
82160 + [15274].file = "crypto/shash.c",
82161 + [15274].name = "crypto_shash_setkey",
82162 + [15274].param3 = 1,
82163 + [15361].file = "drivers/char/agp/generic.c",
82164 + [15361].name = "agp_allocate_memory",
82165 + [15361].param2 = 1,
82166 + [15497].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
82167 + [15497].name = "ts_read",
82168 + [15497].param3 = 1,
82169 + [15551].file = "net/ipv4/netfilter/ipt_CLUSTERIP.c",
82170 + [15551].name = "clusterip_proc_write",
82171 + [15551].param3 = 1,
82172 + [15701].file = "drivers/hid/hid-roccat-common.c",
82173 + [15701].name = "roccat_common_receive",
82174 + [15701].param4 = 1,
82175 + [1572].file = "net/ceph/pagevec.c",
82176 + [1572].name = "ceph_copy_page_vector_to_user",
82177 + [1572].param4 = 1,
82178 + [15814].file = "net/mac80211/debugfs_netdev.c",
82179 + [15814].name = "ieee80211_if_write",
82180 + [15814].param3 = 1,
82181 + [15883].file = "security/keys/keyctl.c",
82182 + [15883].name = "sys_add_key",
82183 + [15883].param4 = 1,
82184 + [15884].file = "fs/exofs/super.c",
82185 + [15884].name = "exofs_read_lookup_dev_table",
82186 + [15884].param3 = 1,
82187 + [1603].file = "fs/debugfs/file.c",
82188 + [1603].name = "write_file_bool",
82189 + [1603].param3 = 1,
82190 + [16073].file = "net/sctp/socket.c",
82191 + [16073].name = "sctp_setsockopt",
82192 + [16073].param5 = 1,
82193 + [16138].file = "security/selinux/ss/services.c",
82194 + [16138].name = "security_context_to_sid_force",
82195 + [16138].param2 = 1,
82196 + [16166].file = "drivers/platform/x86/thinkpad_acpi.c",
82197 + [16166].name = "dispatch_proc_write",
82198 + [16166].param3 = 1,
82199 + [16229].file = "drivers/scsi/scsi_transport_iscsi.c",
82200 + [16229].name = "iscsi_offload_mesg",
82201 + [16229].param5 = 1,
82202 + [16353].file = "drivers/base/regmap/regmap.c",
82203 + [16353].name = "regmap_raw_write",
82204 + [16353].param4 = 1,
82205 + [16383].file = "fs/proc/base.c",
82206 + [16383].name = "comm_write",
82207 + [16383].param3 = 1,
82208 + [16447].file = "drivers/hid/usbhid/hiddev.c",
82209 + [16447].name = "hiddev_ioctl",
82210 + [16447].param2 = 1,
82211 + [16453].file = "include/linux/slab.h",
82212 + [16453].name = "kzalloc",
82213 + [16453].param1 = 1,
82214 + [16535].file = "fs/proc/generic.c",
82215 + [16535].name = "proc_file_read",
82216 + [16535].param3 = 1,
82217 + [16605].file = "fs/ecryptfs/miscdev.c",
82218 + [16605].name = "ecryptfs_send_miscdev",
82219 + [16605].param2 = 1,
82220 + [16606].file = "drivers/ide/ide-tape.c",
82221 + [16606].name = "idetape_chrdev_write",
82222 + [16606].param3 = 1,
82223 + [16741].file = "fs/namei.c",
82224 + [16741].name = "sys_unlinkat",
82225 + [16741].param2 = 1,
82226 + [16911].file = "drivers/media/dvb/ttpci/av7110_hw.c",
82227 + [16911].name = "LoadBitmap",
82228 + [16911].param2 = 1,
82229 + [17075].file = "sound/isa/gus/gus_dram.c",
82230 + [17075].name = "snd_gus_dram_write",
82231 + [17075].param4 = 1,
82232 + [17133].file = "drivers/usb/misc/iowarrior.c",
82233 + [17133].name = "iowarrior_read",
82234 + [17133].param3 = 1,
82235 + [17139].file = "fs/ubifs/xattr.c",
82236 + [17139].name = "ubifs_setxattr",
82237 + [17139].param4 = 1,
82238 + [17185].file = "net/wireless/scan.c",
82239 + [17185].name = "cfg80211_inform_bss",
82240 + [17185].param8 = 1,
82241 + [17349].file = "net/tipc/link.c",
82242 + [17349].name = "tipc_link_send_sections_fast",
82243 + [17349].param4 = 1,
82244 + [17377].file = "drivers/usb/class/cdc-wdm.c",
82245 + [17377].name = "wdm_write",
82246 + [17377].param3 = 1,
82247 + [17459].file = "drivers/usb/misc/rio500.c",
82248 + [17459].name = "write_rio",
82249 + [17459].param3 = 1,
82250 + [17460].file = "fs/nfsd/nfscache.c",
82251 + [17460].name = "nfsd_cache_update",
82252 + [17460].param3 = 1,
82253 + [17492].file = "net/dccp/proto.c",
82254 + [17492].name = "do_dccp_setsockopt",
82255 + [17492].param5 = 1,
82256 + [1754].file = "sound/core/oss/pcm_oss.c",
82257 + [1754].name = "snd_pcm_oss_write",
82258 + [1754].param3 = 1,
82259 + [17571].file = "drivers/ptp/ptp_chardev.c",
82260 + [17571].name = "ptp_read",
82261 + [17571].param4 = 1,
82262 + [17684].file = "fs/namei.c",
82263 + [17684].name = "sys_mknod",
82264 + [17684].param1 = 1,
82265 + [17718].file = "net/caif/caif_socket.c",
82266 + [17718].name = "setsockopt",
82267 + [17718].param5 = 1,
82268 + [17875].file = "fs/namei.c",
82269 + [17875].name = "sys_linkat",
82270 + [17875].param2 = 1,
82271 + [17875].param4 = 1,
82272 + [17946].file = "drivers/net/wireless/libertas/if_spi.c",
82273 + [17946].name = "if_spi_host_to_card",
82274 + [17946].param4 = 1,
82275 + [1800].file = "drivers/media/dvb/dvb-core/dmxdev.c",
82276 + [1800].name = "dvb_dvr_do_ioctl",
82277 + [1800].param3 = 1,
82278 + [18102].file = "net/netlink/af_netlink.c",
82279 + [18102].name = "netlink_change_ngroups",
82280 + [18102].param2 = 1,
82281 + [18183].file = "drivers/tty/tty_buffer.c",
82282 + [18183].name = "tty_insert_flip_string_fixed_flag",
82283 + [18183].param4 = 1,
82284 + [18224].file = "drivers/xen/grant-table.c",
82285 + [18224].name = "gnttab_map",
82286 + [18224].param2 = 1,
82287 + [18232].file = "fs/nfs/write.c",
82288 + [18232].name = "nfs_writedata_alloc",
82289 + [18232].param1 = 1,
82290 + [18277].file = "drivers/char/virtio_console.c",
82291 + [18277].name = "port_fops_write",
82292 + [18277].param3 = 1,
82293 + [18303].file = "fs/xattr.c",
82294 + [18303].name = "getxattr",
82295 + [18303].param4 = 1,
82296 + [18353].file = "net/rfkill/core.c",
82297 + [18353].name = "rfkill_fop_read",
82298 + [18353].param3 = 1,
82299 + [18386].file = "fs/read_write.c",
82300 + [18386].name = "vfs_readv",
82301 + [18386].param3 = 1,
82302 + [18391].file = "fs/ocfs2/stack_user.c",
82303 + [18391].name = "ocfs2_control_write",
82304 + [18391].param3 = 1,
82305 + [183].file = "crypto/ahash.c",
82306 + [183].name = "crypto_ahash_setkey",
82307 + [183].param3 = 1,
82308 + [18406].file = "drivers/media/video/tm6000/tm6000-core.c",
82309 + [18406].name = "tm6000_read_write_usb",
82310 + [18406].param7 = 1,
82311 + [1845].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
82312 + [1845].name = "rt2x00debug_write_rf",
82313 + [1845].param3 = 1,
82314 + [18465].file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
82315 + [18465].name = "cxgb_alloc_mem",
82316 + [18465].param1 = 1,
82317 + [1858].file = "net/ipv6/netfilter/ip6_tables.c",
82318 + [1858].name = "do_ip6t_set_ctl",
82319 + [1858].param4 = 1,
82320 + [18659].file = "drivers/media/dvb/dvb-core/dvbdev.c",
82321 + [18659].name = "dvb_usercopy",
82322 + [18659].param2 = 1,
82323 + [18775].file = "drivers/net/wireless/ath/ath5k/debug.c",
82324 + [18775].name = "write_file_frameerrors",
82325 + [18775].param3 = 1,
82326 + [18928].file = "drivers/staging/speakup/devsynth.c",
82327 + [18928].name = "speakup_file_write",
82328 + [18928].param3 = 1,
82329 + [18988].file = "drivers/staging/vme/devices/vme_user.c",
82330 + [18988].name = "vme_user_read",
82331 + [18988].param3 = 1,
82332 + [19012].file = "drivers/acpi/event.c",
82333 + [19012].name = "acpi_system_read_event",
82334 + [19012].param3 = 1,
82335 + [19028].file = "mm/filemap.c",
82336 + [19028].name = "iov_iter_copy_from_user_atomic",
82337 + [19028].param4 = 1,
82338 + [19107].file = "security/smack/smackfs.c",
82339 + [19107].name = "smk_write_load_list",
82340 + [19107].param3 = 1,
82341 + [19261].file = "net/netlabel/netlabel_domainhash.c",
82342 + [19261].name = "netlbl_domhsh_init",
82343 + [19261].param1 = 1,
82344 + [19274].file = "net/core/pktgen.c",
82345 + [19274].name = "pktgen_if_write",
82346 + [19274].param3 = 1,
82347 + [19286].file = "drivers/base/regmap/regmap.c",
82348 + [19286].name = "_regmap_raw_write",
82349 + [19286].param4 = 1,
82350 + [19288].file = "net/ipv6/raw.c",
82351 + [19288].name = "rawv6_setsockopt",
82352 + [19288].param5 = 1,
82353 + [19308].file = "drivers/char/mem.c",
82354 + [19308].name = "read_oldmem",
82355 + [19308].param3 = 1,
82356 + [19332].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
82357 + [19332].name = "iwl_dbgfs_plcp_delta_write",
82358 + [19332].param3 = 1,
82359 + [19349].file = "drivers/acpi/acpica/utobject.c",
82360 + [19349].name = "acpi_ut_create_package_object",
82361 + [19349].param1 = 1,
82362 + [19504].file = "drivers/usb/serial/garmin_gps.c",
82363 + [19504].name = "pkt_add",
82364 + [19504].param3 = 1,
82365 + [19522].file = "mm/percpu.c",
82366 + [19522].name = "pcpu_mem_zalloc",
82367 + [19522].param1 = 1,
82368 + [19548].file = "drivers/scsi/qla2xxx/qla_init.c",
82369 + [19548].name = "qla2x00_get_ctx_sp",
82370 + [19548].param3 = 1,
82371 + [19738].file = "fs/sysfs/file.c",
82372 + [19738].name = "sysfs_write_file",
82373 + [19738].param3 = 1,
82374 + [19833].file = "drivers/xen/xenfs/privcmd.c",
82375 + [19833].name = "gather_array",
82376 + [19833].param3 = 1,
82377 + [19909].file = "drivers/net/wireless/libertas/debugfs.c",
82378 + [19909].name = "lbs_sleepparams_write",
82379 + [19909].param3 = 1,
82380 + [19920].file = "drivers/input/joydev.c",
82381 + [19920].name = "joydev_ioctl",
82382 + [19920].param2 = 1,
82383 + [19931].file = "drivers/usb/misc/ftdi-elan.c",
82384 + [19931].name = "ftdi_elan_write",
82385 + [19931].param3 = 1,
82386 + [19943].file = "drivers/net/wireless/ath/ath9k/debug.c",
82387 + [19943].name = "write_file_regval",
82388 + [19943].param3 = 1,
82389 + [19960].file = "drivers/usb/class/usblp.c",
82390 + [19960].name = "usblp_read",
82391 + [19960].param3 = 1,
82392 + [20023].file = "drivers/media/video/gspca/gspca.c",
82393 + [20023].name = "dev_read",
82394 + [20023].param3 = 1,
82395 + [20113].file = "drivers/net/wireless/libertas/debugfs.c",
82396 + [20113].name = "lbs_rdmac_write",
82397 + [20113].param3 = 1,
82398 + [20314].file = "drivers/gpu/drm/drm_hashtab.c",
82399 + [20314].name = "drm_ht_create",
82400 + [20314].param2 = 1,
82401 + [20376].file = "mm/nobootmem.c",
82402 + [20376].name = "__alloc_bootmem_nopanic",
82403 + [20376].param1 = 1,
82404 + [20606].file = "fs/nilfs2/mdt.c",
82405 + [20606].name = "nilfs_mdt_init",
82406 + [20606].param3 = 1,
82407 + [20611].file = "net/netfilter/x_tables.c",
82408 + [20611].name = "xt_alloc_table_info",
82409 + [20611].param1 = 1,
82410 + [20713].file = "drivers/gpu/drm/ttm/ttm_bo_vm.c",
82411 + [20713].name = "ttm_bo_io",
82412 + [20713].param5 = 1,
82413 + [20730].file = "drivers/media/video/videobuf2-vmalloc.c",
82414 + [20730].name = "vb2_vmalloc_alloc",
82415 + [20730].param2 = 1,
82416 + [20801].file = "drivers/vhost/vhost.c",
82417 + [20801].name = "vhost_add_used_n",
82418 + [20801].param3 = 1,
82419 + [20835].file = "drivers/isdn/i4l/isdn_common.c",
82420 + [20835].name = "isdn_read",
82421 + [20835].param3 = 1,
82422 + [20951].file = "crypto/rng.c",
82423 + [20951].name = "rngapi_reset",
82424 + [20951].param3 = 1,
82425 + [21134].file = "drivers/video/via/viafbdev.c",
82426 + [21134].name = "viafb_dfph_proc_write",
82427 + [21134].param3 = 1,
82428 + [21193].file = "net/wireless/sme.c",
82429 + [21193].name = "cfg80211_disconnected",
82430 + [21193].param4 = 1,
82431 + [21277].file = "drivers/usb/storage/shuttle_usbat.c",
82432 + [21277].name = "usbat_flash_write_data",
82433 + [21277].param4 = 1,
82434 + [21312].file = "lib/ts_kmp.c",
82435 + [21312].name = "kmp_init",
82436 + [21312].param2 = 1,
82437 + [21335].file = "net/econet/af_econet.c",
82438 + [21335].name = "econet_sendmsg",
82439 + [21335].param4 = 1,
82440 + [21397].file = "net/core/sock.c",
82441 + [21397].name = "sock_setsockopt",
82442 + [21397].param5 = 1,
82443 + [21406].file = "fs/libfs.c",
82444 + [21406].name = "simple_write_to_buffer",
82445 + [21406].param2 = 1,
82446 + [21406].param5 = 1,
82447 + [21451].file = "net/netfilter/ipvs/ip_vs_ctl.c",
82448 + [21451].name = "do_ip_vs_set_ctl",
82449 + [21451].param4 = 1,
82450 + [21459].file = "security/smack/smackfs.c",
82451 + [21459].name = "smk_write_doi",
82452 + [21459].param3 = 1,
82453 + [21468].file = "drivers/char/virtio_console.c",
82454 + [21468].name = "port_fops_read",
82455 + [21468].param3 = 1,
82456 + [21511].file = "drivers/input/ff-core.c",
82457 + [21511].name = "input_ff_create",
82458 + [21511].param2 = 1,
82459 + [21538].file = "net/bluetooth/l2cap_sock.c",
82460 + [21538].name = "l2cap_sock_setsockopt",
82461 + [21538].param5 = 1,
82462 + [21608].file = "drivers/char/tpm/tpm.c",
82463 + [21608].name = "tpm_write",
82464 + [21608].param3 = 1,
82465 + [2160].file = "drivers/net/wireless/ray_cs.c",
82466 + [2160].name = "int_proc_write",
82467 + [2160].param3 = 1,
82468 + [21632].file = "fs/afs/cell.c",
82469 + [21632].name = "afs_cell_create",
82470 + [21632].param2 = 1,
82471 + [21679].file = "drivers/net/wireless/ath/carl9170/debug.c",
82472 + [21679].name = "carl9170_debugfs_write",
82473 + [21679].param3 = 1,
82474 + [21712].file = "net/rxrpc/ar-output.c",
82475 + [21712].name = "rxrpc_send_data",
82476 + [21712].param5 = 1,
82477 + [2180].file = "drivers/char/ppdev.c",
82478 + [2180].name = "pp_write",
82479 + [2180].param3 = 1,
82480 + [21946].file = "fs/nfs/idmap.c",
82481 + [21946].name = "nfs_map_name_to_uid",
82482 + [21946].param3 = 1,
82483 + [22085].file = "drivers/staging/sep/sep_driver.c",
82484 + [22085].name = "sep_lock_user_pages",
82485 + [22085].param2 = 1,
82486 + [22085].param3 = 1,
82487 + [22187].file = "fs/namei.c",
82488 + [22187].name = "user_path_at_empty",
82489 + [22187].param2 = 1,
82490 + [22190].file = "drivers/char/tpm/tpm.c",
82491 + [22190].name = "tpm_read",
82492 + [22190].param3 = 1,
82493 + [22204].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
82494 + [22204].name = "iwl_dbgfs_echo_test_write",
82495 + [22204].param3 = 1,
82496 + [22291].file = "net/core/pktgen.c",
82497 + [22291].name = "pgctrl_write",
82498 + [22291].param3 = 1,
82499 + [22439].file = "fs/afs/rxrpc.c",
82500 + [22439].name = "afs_alloc_flat_call",
82501 + [22439].param2 = 1,
82502 + [22439].param3 = 1,
82503 + [2243].file = "drivers/scsi/scsi_tgt_lib.c",
82504 + [2243].name = "scsi_tgt_kspace_exec",
82505 + [2243].param8 = 1,
82506 + [22546].file = "drivers/char/pcmcia/cm4040_cs.c",
82507 + [22546].name = "cm4040_read",
82508 + [22546].param3 = 1,
82509 + [22742].file = "drivers/tty/tty_buffer.c",
82510 + [22742].name = "tty_insert_flip_string_flags",
82511 + [22742].param4 = 1,
82512 + [22772].file = "drivers/target/iscsi/iscsi_target_erl1.c",
82513 + [22772].name = "iscsit_dump_data_payload",
82514 + [22772].param2 = 1,
82515 + [2286].file = "drivers/scsi/mvumi.c",
82516 + [2286].name = "mvumi_alloc_mem_resource",
82517 + [2286].param3 = 1,
82518 + [22904].file = "security/selinux/ss/services.c",
82519 + [22904].name = "security_context_to_sid_default",
82520 + [22904].param2 = 1,
82521 + [22932].file = "fs/compat.c",
82522 + [22932].name = "compat_sys_writev",
82523 + [22932].param3 = 1,
82524 + [2302].file = "drivers/media/video/stk-webcam.c",
82525 + [2302].name = "v4l_stk_read",
82526 + [2302].param3 = 1,
82527 + [23037].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
82528 + [23037].name = "iwl_dbgfs_wd_timeout_write",
82529 + [23037].param3 = 1,
82530 + [2307].file = "drivers/pcmcia/cistpl.c",
82531 + [2307].name = "pcmcia_replace_cis",
82532 + [2307].param3 = 1,
82533 + [23093].file = "drivers/scsi/st.c",
82534 + [23093].name = "st_read",
82535 + [23093].param3 = 1,
82536 + [23117].file = "drivers/media/dvb/ttpci/av7110_av.c",
82537 + [23117].name = "dvb_audio_write",
82538 + [23117].param3 = 1,
82539 + [2324].file = "net/ieee802154/wpan-class.c",
82540 + [2324].name = "wpan_phy_alloc",
82541 + [2324].param1 = 1,
82542 + [23535].file = "ipc/sem.c",
82543 + [23535].name = "sys_semtimedop",
82544 + [23535].param3 = 1,
82545 + [2357].file = "drivers/usb/serial/garmin_gps.c",
82546 + [2357].name = "garmin_read_process",
82547 + [2357].param3 = 1,
82548 + [23589].file = "kernel/relay.c",
82549 + [23589].name = "subbuf_read_actor",
82550 + [23589].param3 = 1,
82551 + [23619].file = "drivers/tty/tty_buffer.c",
82552 + [23619].name = "tty_buffer_request_room",
82553 + [23619].param2 = 1,
82554 + [23640].file = "drivers/usb/host/ehci-dbg.c",
82555 + [23640].name = "debug_lpm_write",
82556 + [23640].param3 = 1,
82557 + [23684].file = "drivers/net/wireless/iwlegacy/iwl-debugfs.c",
82558 + [23684].name = "iwl_legacy_dbgfs_clear_traffic_statistics_write",
82559 + [23684].param3 = 1,
82560 + [23848].file = "crypto/blkcipher.c",
82561 + [23848].name = "async_setkey",
82562 + [23848].param3 = 1,
82563 + [2386].file = "drivers/acpi/acpica/exnames.c",
82564 + [2386].name = "acpi_ex_allocate_name_string",
82565 + [2386].param2 = 1,
82566 + [23883].file = "drivers/net/wireless/iwlwifi/iwl-trans-pcie.c",
82567 + [23883].name = "iwl_dbgfs_interrupt_write",
82568 + [23883].param3 = 1,
82569 + [23999].file = "sound/pci/rme9652/hdsp.c",
82570 + [23999].name = "snd_hdsp_capture_copy",
82571 + [23999].param5 = 1,
82572 + [24072].file = "drivers/staging/pohmelfs/inode.c",
82573 + [24072].name = "pohmelfs_send_readpages",
82574 + [24072].param3 = 1,
82575 + [24233].file = "drivers/pci/pcie/aer/aer_inject.c",
82576 + [24233].name = "aer_inject_write",
82577 + [24233].param3 = 1,
82578 + [24263].file = "kernel/cgroup.c",
82579 + [24263].name = "cgroup_file_write",
82580 + [24263].param3 = 1,
82581 + [24313].file = "drivers/staging/frontier/tranzport.c",
82582 + [24313].name = "usb_tranzport_write",
82583 + [24313].param3 = 1,
82584 + [24359].file = "kernel/power/qos.c",
82585 + [24359].name = "pm_qos_power_write",
82586 + [24359].param3 = 1,
82587 + [24410].file = "drivers/net/wireless/ipw2x00/libipw_module.c",
82588 + [24410].name = "debug_level_proc_write",
82589 + [24410].param3 = 1,
82590 + [24457].file = "fs/btrfs/backref.c",
82591 + [24457].name = "init_data_container",
82592 + [24457].param1 = 1,
82593 + [24539].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
82594 + [24539].name = "vmw_framebuffer_dmabuf_dirty",
82595 + [24539].param6 = 1,
82596 + [24719].file = "drivers/input/evdev.c",
82597 + [24719].name = "bits_to_user",
82598 + [24719].param2 = 1,
82599 + [24719].param3 = 1,
82600 + [2472].file = "net/ipv4/netfilter/ip_tables.c",
82601 + [2472].name = "compat_do_ipt_set_ctl",
82602 + [2472].param4 = 1,
82603 + [24755].file = "drivers/infiniband/hw/qib/qib_diag.c",
82604 + [24755].name = "qib_diag_write",
82605 + [24755].param3 = 1,
82606 + [24805].file = "security/keys/user_defined.c",
82607 + [24805].name = "user_update",
82608 + [24805].param3 = 1,
82609 + [25036].file = "fs/pipe.c",
82610 + [25036].name = "pipe_iov_copy_from_user",
82611 + [25036].param3 = 1,
82612 + [25127].file = "drivers/scsi/device_handler/scsi_dh_alua.c",
82613 + [25127].name = "realloc_buffer",
82614 + [25127].param2 = 1,
82615 + [25157].file = "security/keys/request_key_auth.c",
82616 + [25157].name = "request_key_auth_new",
82617 + [25157].param3 = 1,
82618 + [25158].file = "drivers/net/ethernet/mellanox/mlx4/en_rx.c",
82619 + [25158].name = "mlx4_en_create_rx_ring",
82620 + [25158].param3 = 1,
82621 + [25223].file = "drivers/platform/x86/toshiba_acpi.c",
82622 + [25223].name = "fan_proc_write",
82623 + [25223].param3 = 1,
82624 + [25267].file = "fs/configfs/file.c",
82625 + [25267].name = "configfs_write_file",
82626 + [25267].param3 = 1,
82627 + [25356].file = "net/core/dev.c",
82628 + [25356].name = "alloc_netdev_mqs",
82629 + [25356].param4 = 1,
82630 + [25356].param5 = 1,
82631 + [25495].file = "drivers/scsi/bfa/bfad_debugfs.c",
82632 + [25495].name = "bfad_debugfs_write_regwr",
82633 + [25495].param3 = 1,
82634 + [25558].file = "fs/proc/task_mmu.c",
82635 + [25558].name = "clear_refs_write",
82636 + [25558].param3 = 1,
82637 + [25692].file = "drivers/net/wireless/ath/ath6kl/wmi.c",
82638 + [25692].name = "ath6kl_wmi_send_action_cmd",
82639 + [25692].param6 = 1,
82640 + [2609].file = "lib/kstrtox.c",
82641 + [2609].name = "kstrtoul_from_user",
82642 + [2609].param2 = 1,
82643 + [26100].file = "sound/core/info.c",
82644 + [26100].name = "snd_info_entry_write",
82645 + [26100].param3 = 1,
82646 + [26215].file = "drivers/md/dm-table.c",
82647 + [26215].name = "dm_table_create",
82648 + [26215].param3 = 1,
82649 + [26256].file = "fs/hpfs/name.c",
82650 + [26256].name = "hpfs_translate_name",
82651 + [26256].param3 = 1,
82652 + [26404].file = "drivers/net/wireless/mwifiex/debugfs.c",
82653 + [26404].name = "mwifiex_rdeeprom_write",
82654 + [26404].param3 = 1,
82655 + [26494].file = "kernel/signal.c",
82656 + [26494].name = "sys_rt_sigpending",
82657 + [26494].param2 = 1,
82658 + [26497].file = "security/keys/keyctl.c",
82659 + [26497].name = "sys_keyctl",
82660 + [26497].param4 = 1,
82661 + [26533].file = "drivers/block/aoe/aoechr.c",
82662 + [26533].name = "aoechr_write",
82663 + [26533].param3 = 1,
82664 + [26560].file = "crypto/algapi.c",
82665 + [26560].name = "crypto_alloc_instance2",
82666 + [26560].param3 = 1,
82667 + [26620].file = "net/bluetooth/mgmt.c",
82668 + [26620].name = "mgmt_control",
82669 + [26620].param3 = 1,
82670 + [26701].file = "drivers/mtd/chips/cfi_util.c",
82671 + [26701].name = "cfi_read_pri",
82672 + [26701].param3 = 1,
82673 + [26757].file = "fs/xattr.c",
82674 + [26757].name = "sys_fgetxattr",
82675 + [26757].param4 = 1,
82676 + [2678].file = "drivers/platform/x86/asus_acpi.c",
82677 + [2678].name = "disp_proc_write",
82678 + [2678].param3 = 1,
82679 + [26834].file = "drivers/gpu/drm/drm_drv.c",
82680 + [26834].name = "drm_ioctl",
82681 + [26834].param2 = 1,
82682 + [26843].file = "drivers/firewire/core-cdev.c",
82683 + [26843].name = "fw_device_op_compat_ioctl",
82684 + [26843].param2 = 1,
82685 + [26845].file = "drivers/scsi/qla2xxx/qla_bsg.c",
82686 + [26845].name = "qla2x00_get_ctx_bsg_sp",
82687 + [26845].param3 = 1,
82688 + [26962].file = "drivers/usb/class/usbtmc.c",
82689 + [26962].name = "usbtmc_write",
82690 + [26962].param3 = 1,
82691 + [26966].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
82692 + [26966].name = "ts_write",
82693 + [26966].param3 = 1,
82694 + [27004].file = "drivers/misc/hpilo.c",
82695 + [27004].name = "ilo_write",
82696 + [27004].param3 = 1,
82697 + [27025].file = "fs/ntfs/file.c",
82698 + [27025].name = "__ntfs_copy_from_user_iovec_inatomic",
82699 + [27025].param3 = 1,
82700 + [27025].param4 = 1,
82701 + [27061].file = "drivers/firewire/core-cdev.c",
82702 + [27061].name = "iso_callback",
82703 + [27061].param3 = 1,
82704 + [2711].file = "drivers/media/dvb/dvb-core/dvb_ringbuffer.c",
82705 + [2711].name = "dvb_ringbuffer_read_user",
82706 + [2711].param3 = 1,
82707 + [27129].file = "fs/lockd/mon.c",
82708 + [27129].name = "nsm_get_handle",
82709 + [27129].param4 = 1,
82710 + [27142].file = "fs/proc/kcore.c",
82711 + [27142].name = "read_kcore",
82712 + [27142].param3 = 1,
82713 + [27164].file = "include/drm/drm_mem_util.h",
82714 + [27164].name = "drm_calloc_large",
82715 + [27164].param1 = 1,
82716 + [2722].file = "drivers/gpu/drm/ttm/ttm_page_alloc.c",
82717 + [2722].name = "ttm_alloc_new_pages",
82718 + [2722].param5 = 1,
82719 + [27232].file = "security/apparmor/lib.c",
82720 + [27232].name = "kvmalloc",
82721 + [27232].param1 = 1,
82722 + [27275].file = "drivers/scsi/cxgbi/libcxgbi.c",
82723 + [27275].name = "cxgbi_ddp_reserve",
82724 + [27275].param4 = 1,
82725 + [27280].file = "drivers/net/ethernet/mellanox/mlx4/en_tx.c",
82726 + [27280].name = "mlx4_en_create_tx_ring",
82727 + [27280].param4 = 1,
82728 + [27290].file = "security/selinux/ss/services.c",
82729 + [27290].name = "security_context_to_sid_core",
82730 + [27290].param2 = 1,
82731 + [27302].file = "fs/proc/base.c",
82732 + [27302].name = "proc_loginuid_write",
82733 + [27302].param3 = 1,
82734 + [27472].file = "security/selinux/selinuxfs.c",
82735 + [27472].name = "sel_write_load",
82736 + [27472].param3 = 1,
82737 + [27491].file = "fs/proc/base.c",
82738 + [27491].name = "proc_pid_attr_write",
82739 + [27491].param3 = 1,
82740 + [27568].file = "drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c",
82741 + [27568].name = "t4_alloc_mem",
82742 + [27568].param1 = 1,
82743 + [27582].file = "drivers/platform/x86/asus_acpi.c",
82744 + [27582].name = "ledd_proc_write",
82745 + [27582].param3 = 1,
82746 + [27695].file = "fs/namei.c",
82747 + [27695].name = "sys_link",
82748 + [27695].param1 = 1,
82749 + [27695].param2 = 1,
82750 + [27697].file = "drivers/staging/mei/iorw.c",
82751 + [27697].name = "amthi_read",
82752 + [27697].param4 = 1,
82753 + [27927].file = "drivers/tty/tty_io.c",
82754 + [27927].name = "redirected_tty_write",
82755 + [27927].param3 = 1,
82756 + [28040].file = "kernel/kfifo.c",
82757 + [28040].name = "__kfifo_alloc",
82758 + [28040].param2 = 1,
82759 + [28040].param3 = 1,
82760 + [28092].file = "fs/select.c",
82761 + [28092].name = "do_sys_poll",
82762 + [28092].param2 = 1,
82763 + [28170].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
82764 + [28170].name = "iwl_dbgfs_ucode_tracing_write",
82765 + [28170].param3 = 1,
82766 + [28247].file = "net/sctp/tsnmap.c",
82767 + [28247].name = "sctp_tsnmap_init",
82768 + [28247].param2 = 1,
82769 + [28265].file = "fs/notify/fanotify/fanotify_user.c",
82770 + [28265].name = "fanotify_write",
82771 + [28265].param3 = 1,
82772 + [28316].file = "drivers/input/joydev.c",
82773 + [28316].name = "joydev_ioctl_common",
82774 + [28316].param2 = 1,
82775 + [28360].file = "drivers/hid/usbhid/hiddev.c",
82776 + [28360].name = "hiddev_compat_ioctl",
82777 + [28360].param2 = 1,
82778 + [28407].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
82779 + [28407].name = "rt2x00debug_write_csr",
82780 + [28407].param3 = 1,
82781 + [28462].file = "net/rfkill/core.c",
82782 + [28462].name = "rfkill_fop_write",
82783 + [28462].param3 = 1,
82784 + [28635].file = "drivers/gpu/drm/drm_sman.c",
82785 + [28635].name = "drm_sman_init",
82786 + [28635].param2 = 1,
82787 + [28655].file = "drivers/infiniband/hw/mthca/mthca_allocator.c",
82788 + [28655].name = "mthca_alloc_init",
82789 + [28655].param2 = 1,
82790 + [28688].file = "mm/mempolicy.c",
82791 + [28688].name = "compat_sys_get_mempolicy",
82792 + [28688].param3 = 1,
82793 + [28783].file = "drivers/gpu/drm/i915/i915_debugfs.c",
82794 + [28783].name = "i915_cache_sharing_write",
82795 + [28783].param3 = 1,
82796 + [28787].file = "drivers/media/video/videobuf2-core.c",
82797 + [28787].name = "vb2_write",
82798 + [28787].param3 = 1,
82799 + [28879].file = "drivers/base/map.c",
82800 + [28879].name = "kobj_map",
82801 + [28879].param2 = 1,
82802 + [28879].param3 = 1,
82803 + [28889].file = "drivers/char/pcmcia/cm4040_cs.c",
82804 + [28889].name = "cm4040_write",
82805 + [28889].param3 = 1,
82806 + [29073].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
82807 + [29073].name = "vmw_kms_readback",
82808 + [29073].param6 = 1,
82809 + [29085].file = "security/apparmor/apparmorfs.c",
82810 + [29085].name = "profile_load",
82811 + [29085].param3 = 1,
82812 + [29092].file = "lib/lru_cache.c",
82813 + [29092].name = "lc_create",
82814 + [29092].param3 = 1,
82815 + [29189].file = "drivers/gpu/drm/ttm/ttm_page_alloc.c",
82816 + [29189].name = "ttm_put_pages",
82817 + [29189].param2 = 1,
82818 + [29257].file = "drivers/vhost/vhost.c",
82819 + [29257].name = "vhost_add_used_and_signal_n",
82820 + [29257].param4 = 1,
82821 + [29366].file = "drivers/char/pcmcia/cm4000_cs.c",
82822 + [29366].name = "cmm_read",
82823 + [29366].param3 = 1,
82824 + [29405].file = "drivers/media/dvb/dvb-usb/dw2102.c",
82825 + [29405].name = "dw210x_op_rw",
82826 + [29405].param6 = 1,
82827 + [29437].file = "drivers/net/wireless/iwlegacy/iwl-4965-rs.c",
82828 + [29437].name = "iwl4965_rs_sta_dbgfs_scale_table_write",
82829 + [29437].param3 = 1,
82830 + [29465].file = "drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c",
82831 + [29465].name = "mem_read",
82832 + [29465].param3 = 1,
82833 + [29714].file = "drivers/scsi/cxgbi/libcxgbi.c",
82834 + [29714].name = "cxgbi_device_register",
82835 + [29714].param1 = 1,
82836 + [29714].param2 = 1,
82837 + [29859].file = "net/rds/page.c",
82838 + [29859].name = "rds_page_copy_user",
82839 + [29859].param4 = 1,
82840 + [29875].file = "sound/isa/gus/gus_pcm.c",
82841 + [29875].name = "snd_gf1_pcm_playback_copy",
82842 + [29875].param5 = 1,
82843 + [29905].file = "mm/nobootmem.c",
82844 + [29905].name = "___alloc_bootmem",
82845 + [29905].param1 = 1,
82846 + [2995].file = "mm/page_alloc.c",
82847 + [2995].name = "alloc_large_system_hash",
82848 + [2995].param2 = 1,
82849 + [30242].file = "fs/cifs/cifssmb.c",
82850 + [30242].name = "cifs_readdata_alloc",
82851 + [30242].param1 = 1,
82852 + [30341].file = "drivers/infiniband/hw/qib/qib_verbs.c",
82853 + [30341].name = "qib_verbs_send",
82854 + [30341].param3 = 1,
82855 + [30341].param5 = 1,
82856 + [30438].file = "mm/filemap_xip.c",
82857 + [30438].name = "xip_file_read",
82858 + [30438].param3 = 1,
82859 + [30449].file = "drivers/telephony/ixj.c",
82860 + [30449].name = "ixj_read",
82861 + [30449].param3 = 1,
82862 + [30489].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
82863 + [30489].name = "iwl_dbgfs_rx_handlers_write",
82864 + [30489].param3 = 1,
82865 + [30693].file = "fs/namei.c",
82866 + [30693].name = "sys_rename",
82867 + [30693].param1 = 1,
82868 + [30693].param2 = 1,
82869 + [307].file = "drivers/base/regmap/regmap-debugfs.c",
82870 + [307].name = "regmap_map_read_file",
82871 + [307].param3 = 1,
82872 + [30970].file = "drivers/usb/misc/ldusb.c",
82873 + [30970].name = "ld_usb_read",
82874 + [30970].param3 = 1,
82875 + [31155].file = "drivers/staging/frontier/alphatrack.c",
82876 + [31155].name = "usb_alphatrack_write",
82877 + [31155].param3 = 1,
82878 + [31207].file = "drivers/platform/x86/asus_acpi.c",
82879 + [31207].name = "parse_arg",
82880 + [31207].param2 = 1,
82881 + [31348].file = "kernel/sched.c",
82882 + [31348].name = "sys_sched_getaffinity",
82883 + [31348].param2 = 1,
82884 + [31465].file = "net/rds/message.c",
82885 + [31465].name = "rds_message_map_pages",
82886 + [31465].param2 = 1,
82887 + [31492].file = "drivers/hid/hidraw.c",
82888 + [31492].name = "hidraw_read",
82889 + [31492].param3 = 1,
82890 + [31649].file = "fs/ecryptfs/crypto.c",
82891 + [31649].name = "ecryptfs_decode_and_decrypt_filename",
82892 + [31649].param5 = 1,
82893 + [3170].file = "security/integrity/ima/ima_fs.c",
82894 + [3170].name = "ima_write_policy",
82895 + [3170].param3 = 1,
82896 + [31730].file = "net/dccp/proto.c",
82897 + [31730].name = "dccp_setsockopt",
82898 + [31730].param5 = 1,
82899 + [31782].file = "drivers/misc/pti.c",
82900 + [31782].name = "pti_char_write",
82901 + [31782].param3 = 1,
82902 + [31789].file = "fs/file.c",
82903 + [31789].name = "alloc_fdmem",
82904 + [31789].param1 = 1,
82905 + [31957].file = "fs/afs/proc.c",
82906 + [31957].name = "afs_proc_cells_write",
82907 + [31957].param3 = 1,
82908 + [32025].file = "drivers/nfc/pn544.c",
82909 + [32025].name = "pn544_write",
82910 + [32025].param3 = 1,
82911 + [32182].file = "net/sunrpc/cache.c",
82912 + [32182].name = "cache_write",
82913 + [32182].param3 = 1,
82914 + [32326].file = "drivers/tty/n_r3964.c",
82915 + [32326].name = "r3964_write",
82916 + [32326].param4 = 1,
82917 + [32402].file = "net/ceph/pagevec.c",
82918 + [32402].name = "ceph_copy_user_to_page_vector",
82919 + [32402].param4 = 1,
82920 + [3241].file = "drivers/usb/wusbcore/crypto.c",
82921 + [3241].name = "wusb_prf",
82922 + [3241].param7 = 1,
82923 + [32459].file = "drivers/media/radio/radio-wl1273.c",
82924 + [32459].name = "wl1273_fm_fops_write",
82925 + [32459].param3 = 1,
82926 + [32560].file = "drivers/input/input-mt.c",
82927 + [32560].name = "input_mt_init_slots",
82928 + [32560].param2 = 1,
82929 + [32574].file = "mm/mempolicy.c",
82930 + [32574].name = "sys_get_mempolicy",
82931 + [32574].param3 = 1,
82932 + [32608].file = "security/selinux/selinuxfs.c",
82933 + [32608].name = "sel_write_checkreqprot",
82934 + [32608].param3 = 1,
82935 + [32950].file = "fs/reiserfs/resize.c",
82936 + [32950].name = "reiserfs_resize",
82937 + [32950].param2 = 1,
82938 + [33010].file = "drivers/media/dvb/dvb-core/dvb_ringbuffer.c",
82939 + [33010].name = "dvb_ringbuffer_pkt_read_user",
82940 + [33010].param5 = 1,
82941 + [33268].file = "mm/maccess.c",
82942 + [33268].name = "__probe_kernel_write",
82943 + [33268].param3 = 1,
82944 + [33280].file = "fs/xfs/kmem.c",
82945 + [33280].name = "kmem_realloc",
82946 + [33280].param2 = 1,
82947 + [33375].file = "drivers/staging/rtl8712/osdep_service.h",
82948 + [33375].name = "_malloc",
82949 + [33375].param1 = 1,
82950 + [33637].file = "net/9p/client.c",
82951 + [33637].name = "p9_client_read",
82952 + [33637].param5 = 1,
82953 + [33669].file = "fs/gfs2/glock.c",
82954 + [33669].name = "gfs2_glock_nq_m",
82955 + [33669].param1 = 1,
82956 + [33810].file = "net/mac80211/util.c",
82957 + [33810].name = "ieee80211_send_probe_req",
82958 + [33810].param6 = 1,
82959 + [3384].file = "drivers/block/paride/pg.c",
82960 + [3384].name = "pg_write",
82961 + [3384].param3 = 1,
82962 + [34016].file = "drivers/tty/tty_buffer.c",
82963 + [34016].name = "tty_prepare_flip_string_flags",
82964 + [34016].param4 = 1,
82965 + [34105].file = "fs/libfs.c",
82966 + [34105].name = "simple_read_from_buffer",
82967 + [34105].param2 = 1,
82968 + [34105].param5 = 1,
82969 + [34120].file = "drivers/media/video/pvrusb2/pvrusb2-io.c",
82970 + [34120].name = "pvr2_stream_buffer_count",
82971 + [34120].param2 = 1,
82972 + [34226].file = "mm/shmem.c",
82973 + [34226].name = "shmem_xattr_set",
82974 + [34226].param4 = 1,
82975 + [34251].file = "drivers/staging/cxt1e1/sbecom_inline_linux.h",
82976 + [34251].name = "OS_kmalloc",
82977 + [34251].param1 = 1,
82978 + [34276].file = "drivers/media/video/videobuf2-core.c",
82979 + [34276].name = "__vb2_perform_fileio",
82980 + [34276].param3 = 1,
82981 + [34278].file = "fs/ubifs/debug.c",
82982 + [34278].name = "dfs_global_file_write",
82983 + [34278].param3 = 1,
82984 + [34432].file = "drivers/edac/edac_pci.c",
82985 + [34432].name = "edac_pci_alloc_ctl_info",
82986 + [34432].param1 = 1,
82987 + [34551].file = "fs/ocfs2/stack_user.c",
82988 + [34551].name = "ocfs2_control_cfu",
82989 + [34551].param2 = 1,
82990 + [34666].file = "fs/cifs/cifs_debug.c",
82991 + [34666].name = "cifs_security_flags_proc_write",
82992 + [34666].param3 = 1,
82993 + [34672].file = "drivers/tty/tty_io.c",
82994 + [34672].name = "tty_write",
82995 + [34672].param3 = 1,
82996 + [34760].file = "include/acpi/platform/aclinux.h",
82997 + [34760].name = "acpi_os_allocate_zeroed",
82998 + [34760].param1 = 1,
82999 + [34802].file = "drivers/scsi/cxgbi/libcxgbi.h",
83000 + [34802].name = "cxgbi_alloc_big_mem",
83001 + [34802].param1 = 1,
83002 + [34847].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
83003 + [34847].name = "iwl_dbgfs_clear_traffic_statistics_write",
83004 + [34847].param3 = 1,
83005 + [34863].file = "drivers/video/fbsysfs.c",
83006 + [34863].name = "framebuffer_alloc",
83007 + [34863].param1 = 1,
83008 + [34882].file = "drivers/platform/x86/toshiba_acpi.c",
83009 + [34882].name = "video_proc_write",
83010 + [34882].param3 = 1,
83011 + [34988].file = "drivers/net/wireless/libertas/debugfs.c",
83012 + [34988].name = "lbs_rdrf_write",
83013 + [34988].param3 = 1,
83014 + [35007].file = "drivers/usb/mon/mon_bin.c",
83015 + [35007].name = "mon_bin_read",
83016 + [35007].param3 = 1,
83017 + [35050].file = "fs/ocfs2/dlmfs/dlmfs.c",
83018 + [35050].name = "dlmfs_file_write",
83019 + [35050].param3 = 1,
83020 + [35119].file = "fs/xattr.c",
83021 + [35119].name = "sys_llistxattr",
83022 + [35119].param3 = 1,
83023 + [35129].file = "mm/nobootmem.c",
83024 + [35129].name = "___alloc_bootmem_nopanic",
83025 + [35129].param1 = 1,
83026 + [35176].file = "drivers/usb/misc/ldusb.c",
83027 + [35176].name = "ld_usb_write",
83028 + [35176].param3 = 1,
83029 + [35234].file = "net/irda/irnet/irnet_ppp.c",
83030 + [35234].name = "irnet_ctrl_write",
83031 + [35234].param3 = 1,
83032 + [35256].file = "sound/core/memory.c",
83033 + [35256].name = "copy_from_user_toio",
83034 + [35256].param3 = 1,
83035 + [35268].file = "security/keys/request_key_auth.c",
83036 + [35268].name = "request_key_auth_read",
83037 + [35268].param3 = 1,
83038 + [3541].file = "drivers/mtd/ubi/cdev.c",
83039 + [3541].name = "vol_cdev_write",
83040 + [3541].param3 = 1,
83041 + [35443].file = "sound/core/pcm_memory.c",
83042 + [35443].name = "_snd_pcm_lib_alloc_vmalloc_buffer",
83043 + [35443].param2 = 1,
83044 + [35449].file = "fs/namei.c",
83045 + [35449].name = "sys_mkdir",
83046 + [35449].param1 = 1,
83047 + [35542].file = "drivers/tty/ipwireless/hardware.c",
83048 + [35542].name = "ipwireless_send_packet",
83049 + [35542].param4 = 1,
83050 + [35556].file = "fs/read_write.c",
83051 + [35556].name = "sys_readv",
83052 + [35556].param3 = 1,
83053 + [35610].file = "net/batman-adv/translation-table.c",
83054 + [35610].name = "tt_save_orig_buffer",
83055 + [35610].param4 = 1,
83056 + [35693].file = "drivers/staging/mei/main.c",
83057 + [35693].name = "mei_read",
83058 + [35693].param3 = 1,
83059 + [35729].file = "include/linux/skbuff.h",
83060 + [35729].name = "__dev_alloc_skb",
83061 + [35729].param1 = 1,
83062 + [35731].file = "drivers/usb/class/cdc-wdm.c",
83063 + [35731].name = "wdm_read",
83064 + [35731].param3 = 1,
83065 + [35796].file = "drivers/mtd/nand/nand_bch.c",
83066 + [35796].name = "nand_bch_init",
83067 + [35796].param2 = 1,
83068 + [35796].param3 = 1,
83069 + [35880].file = "fs/ecryptfs/crypto.c",
83070 + [35880].name = "ecryptfs_encrypt_and_encode_filename",
83071 + [35880].param6 = 1,
83072 + [3604].file = "net/batman-adv/translation-table.c",
83073 + [3604].name = "tt_update_orig",
83074 + [3604].param4 = 1,
83075 + [36080].file = "drivers/media/video/v4l2-ioctl.c",
83076 + [36080].name = "video_usercopy",
83077 + [36080].param2 = 1,
83078 + [36149].file = "fs/udf/inode.c",
83079 + [36149].name = "udf_alloc_i_data",
83080 + [36149].param2 = 1,
83081 + [36183].file = "drivers/tty/vt/vc_screen.c",
83082 + [36183].name = "vcs_read",
83083 + [36183].param3 = 1,
83084 + [36199].file = "net/sunrpc/auth_gss/auth_gss.c",
83085 + [36199].name = "gss_pipe_downcall",
83086 + [36199].param3 = 1,
83087 + [3630].file = "drivers/video/broadsheetfb.c",
83088 + [3630].name = "broadsheetfb_write",
83089 + [3630].param3 = 1,
83090 + [3632].file = "drivers/firewire/core-cdev.c",
83091 + [3632].name = "fw_device_op_read",
83092 + [3632].param3 = 1,
83093 + [36490].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
83094 + [36490].name = "ath6kl_cfg80211_connect_event",
83095 + [36490].param7 = 1,
83096 + [36522].file = "drivers/hid/hidraw.c",
83097 + [36522].name = "hidraw_send_report",
83098 + [36522].param3 = 1,
83099 + [36560].file = "net/sunrpc/cache.c",
83100 + [36560].name = "write_flush",
83101 + [36560].param3 = 1,
83102 + [36633].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
83103 + [36633].name = "rt2x00debug_read_queue_stats",
83104 + [36633].param3 = 1,
83105 + [3665].file = "drivers/media/video/ivtv/ivtvfb.c",
83106 + [3665].name = "ivtvfb_write",
83107 + [3665].param3 = 1,
83108 + [36981].file = "drivers/video/via/viafbdev.c",
83109 + [36981].name = "viafb_dfpl_proc_write",
83110 + [36981].param3 = 1,
83111 + [37034].file = "fs/cifs/cifssmb.c",
83112 + [37034].name = "cifs_writedata_alloc",
83113 + [37034].param1 = 1,
83114 + [37044].file = "sound/firewire/packets-buffer.c",
83115 + [37044].name = "iso_packets_buffer_init",
83116 + [37044].param3 = 1,
83117 + [37115].file = "drivers/tty/tty_buffer.c",
83118 + [37115].name = "tty_prepare_flip_string",
83119 + [37115].param3 = 1,
83120 + [37163].file = "net/core/skbuff.c",
83121 + [37163].name = "__netdev_alloc_skb",
83122 + [37163].param2 = 1,
83123 + [37204].file = "drivers/isdn/hardware/eicon/divasi.c",
83124 + [37204].name = "um_idi_read",
83125 + [37204].param3 = 1,
83126 + [37233].file = "fs/ocfs2/cluster/tcp.c",
83127 + [37233].name = "o2net_send_message_vec",
83128 + [37233].param4 = 1,
83129 + [37309].file = "drivers/mtd/mtdchar.c",
83130 + [37309].name = "mtd_do_readoob",
83131 + [37309].param4 = 1,
83132 + [37382].file = "drivers/staging/pohmelfs/inode.c",
83133 + [37382].name = "pohmelfs_readpages_trans_complete",
83134 + [37382].param2 = 1,
83135 + [37384].file = "drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c",
83136 + [37384].name = "vmw_fifo_reserve",
83137 + [37384].param2 = 1,
83138 + [37497].file = "net/mac80211/util.c",
83139 + [37497].name = "ieee80211_build_probe_req",
83140 + [37497].param7 = 1,
83141 + [37594].file = "include/linux/poll.h",
83142 + [37594].name = "get_fd_set",
83143 + [37594].param1 = 1,
83144 + [37611].file = "drivers/xen/xenbus/xenbus_xs.c",
83145 + [37611].name = "split",
83146 + [37611].param2 = 1,
83147 + [37661].file = "mm/filemap.c",
83148 + [37661].name = "file_read_actor",
83149 + [37661].param4 = 1,
83150 + [37872].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
83151 + [37872].name = "iwl_dbgfs_protection_mode_write",
83152 + [37872].param3 = 1,
83153 + [37976].file = "drivers/platform/x86/asus_acpi.c",
83154 + [37976].name = "bluetooth_proc_write",
83155 + [37976].param3 = 1,
83156 + [3797].file = "sound/pci/asihpi/hpicmn.c",
83157 + [3797].name = "hpi_alloc_control_cache",
83158 + [3797].param1 = 1,
83159 + [3801].file = "drivers/block/paride/pt.c",
83160 + [3801].name = "pt_write",
83161 + [3801].param3 = 1,
83162 + [38057].file = "fs/coda/psdev.c",
83163 + [38057].name = "coda_psdev_write",
83164 + [38057].param3 = 1,
83165 + [38186].file = "kernel/signal.c",
83166 + [38186].name = "do_sigpending",
83167 + [38186].param2 = 1,
83168 + [38401].file = "drivers/xen/xenfs/xenbus.c",
83169 + [38401].name = "queue_reply",
83170 + [38401].param3 = 1,
83171 + [3841].file = "drivers/platform/x86/asus_acpi.c",
83172 + [3841].name = "write_led",
83173 + [3841].param2 = 1,
83174 + [38532].file = "fs/afs/cell.c",
83175 + [38532].name = "afs_cell_lookup",
83176 + [38532].param2 = 1,
83177 + [38576].file = "drivers/i2c/i2c-dev.c",
83178 + [38576].name = "i2cdev_read",
83179 + [38576].param3 = 1,
83180 + [38747].file = "fs/xattr.c",
83181 + [38747].name = "sys_lgetxattr",
83182 + [38747].param4 = 1,
83183 + [38972].file = "security/smack/smackfs.c",
83184 + [38972].name = "smk_write_logging",
83185 + [38972].param3 = 1,
83186 + [39001].file = "net/xfrm/xfrm_hash.c",
83187 + [39001].name = "xfrm_hash_alloc",
83188 + [39001].param1 = 1,
83189 + [39044].file = "lib/kstrtox.c",
83190 + [39044].name = "kstrtos16_from_user",
83191 + [39044].param2 = 1,
83192 + [39052].file = "drivers/input/evdev.c",
83193 + [39052].name = "evdev_ioctl",
83194 + [39052].param2 = 1,
83195 + [39154].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
83196 + [39154].name = "iwl_dbgfs_clear_ucode_statistics_write",
83197 + [39154].param3 = 1,
83198 + [39155].file = "drivers/xen/grant-table.c",
83199 + [39155].name = "get_free_entries",
83200 + [39155].param1 = 1,
83201 + [39254].file = "drivers/char/pcmcia/cm4000_cs.c",
83202 + [39254].name = "cmm_write",
83203 + [39254].param3 = 1,
83204 + [39415].file = "fs/pstore/inode.c",
83205 + [39415].name = "pstore_mkfile",
83206 + [39415].param5 = 1,
83207 + [39417].file = "drivers/block/DAC960.c",
83208 + [39417].name = "dac960_user_command_proc_write",
83209 + [39417].param3 = 1,
83210 + [39479].file = "drivers/ide/ide-tape.c",
83211 + [39479].name = "idetape_chrdev_read",
83212 + [39479].param3 = 1,
83213 + [39573].file = "drivers/hid/hid-picolcd.c",
83214 + [39573].name = "picolcd_debug_reset_write",
83215 + [39573].param3 = 1,
83216 + [39583].file = "drivers/net/ethernet/broadcom/cnic.c",
83217 + [39583].name = "cnic_init_id_tbl",
83218 + [39583].param2 = 1,
83219 + [39606].file = "drivers/bluetooth/hci_vhci.c",
83220 + [39606].name = "vhci_write",
83221 + [39606].param3 = 1,
83222 + [39638].file = "security/selinux/selinuxfs.c",
83223 + [39638].name = "sel_write_avc_cache_threshold",
83224 + [39638].param3 = 1,
83225 + [39645].file = "drivers/media/dvb/dvb-core/dvbdev.c",
83226 + [39645].name = "dvb_generic_ioctl",
83227 + [39645].param2 = 1,
83228 + [39741].file = "drivers/video/via/viafbdev.c",
83229 + [39741].name = "viafb_iga2_odev_proc_write",
83230 + [39741].param3 = 1,
83231 + [39888].file = "net/core/skbuff.c",
83232 + [39888].name = "__alloc_skb",
83233 + [39888].param1 = 1,
83234 + [40043].file = "drivers/media/video/v4l2-ioctl.c",
83235 + [40043].name = "video_ioctl2",
83236 + [40043].param2 = 1,
83237 + [40049].file = "drivers/bluetooth/btmrvl_debugfs.c",
83238 + [40049].name = "btmrvl_psmode_write",
83239 + [40049].param3 = 1,
83240 + [40075].file = "drivers/media/video/c-qcam.c",
83241 + [40075].name = "qc_capture",
83242 + [40075].param3 = 1,
83243 + [40163].file = "fs/ncpfs/file.c",
83244 + [40163].name = "ncp_file_write",
83245 + [40163].param3 = 1,
83246 + [40240].file = "drivers/char/nvram.c",
83247 + [40240].name = "nvram_write",
83248 + [40240].param3 = 1,
83249 + [40256].file = "drivers/tty/vt/vc_screen.c",
83250 + [40256].name = "vcs_write",
83251 + [40256].param3 = 1,
83252 + [40302].file = "sound/isa/gus/gus_dram.c",
83253 + [40302].name = "snd_gus_dram_poke",
83254 + [40302].param4 = 1,
83255 + [40355].file = "drivers/staging/mei/main.c",
83256 + [40355].name = "mei_write",
83257 + [40355].param3 = 1,
83258 + [40373].file = "fs/cifs/cifs_spnego.c",
83259 + [40373].name = "cifs_spnego_key_instantiate",
83260 + [40373].param3 = 1,
83261 + [40412].file = "fs/namei.c",
83262 + [40412].name = "user_path_at",
83263 + [40412].param2 = 1,
83264 + [40578].file = "sound/soc/soc-core.c",
83265 + [40578].name = "codec_reg_write_file",
83266 + [40578].param3 = 1,
83267 + [40678].file = "drivers/net/wireless/iwlegacy/iwl-debugfs.c",
83268 + [40678].name = "iwl_legacy_dbgfs_traffic_log_write",
83269 + [40678].param3 = 1,
83270 + [40713].file = "net/mac80211/debugfs.c",
83271 + [40713].name = "noack_write",
83272 + [40713].param3 = 1,
83273 + [40754].file = "fs/btrfs/delayed-inode.c",
83274 + [40754].name = "btrfs_alloc_delayed_item",
83275 + [40754].param1 = 1,
83276 + [40786].file = "net/ipv4/netfilter/nf_nat_snmp_basic.c",
83277 + [40786].name = "asn1_octets_decode",
83278 + [40786].param2 = 1,
83279 + [40901].file = "drivers/block/drbd/drbd_bitmap.c",
83280 + [40901].name = "drbd_bm_resize",
83281 + [40901].param2 = 1,
83282 + [40952].file = "drivers/misc/sgi-xp/xpc_partition.c",
83283 + [40952].name = "xpc_kmalloc_cacheline_aligned",
83284 + [40952].param1 = 1,
83285 + [41000].file = "sound/core/pcm_native.c",
83286 + [41000].name = "snd_pcm_aio_read",
83287 + [41000].param3 = 1,
83288 + [41003].file = "fs/namei.c",
83289 + [41003].name = "user_path_parent",
83290 + [41003].param2 = 1,
83291 + [41005].file = "net/bridge/netfilter/ebtables.c",
83292 + [41005].name = "copy_counters_to_user",
83293 + [41005].param5 = 1,
83294 + [41090].file = "drivers/net/wireless/iwlegacy/iwl-debugfs.c",
83295 + [41090].name = "iwl_legacy_dbgfs_sram_write",
83296 + [41090].param3 = 1,
83297 + [41122].file = "fs/binfmt_misc.c",
83298 + [41122].name = "bm_status_write",
83299 + [41122].param3 = 1,
83300 + [41230].file = "drivers/usb/storage/datafab.c",
83301 + [41230].name = "datafab_read_data",
83302 + [41230].param4 = 1,
83303 + [41249].file = "drivers/media/video/zr364xx.c",
83304 + [41249].name = "send_control_msg",
83305 + [41249].param6 = 1,
83306 + [41302].file = "net/dns_resolver/dns_query.c",
83307 + [41302].name = "dns_query",
83308 + [41302].param3 = 1,
83309 + [41418].file = "fs/libfs.c",
83310 + [41418].name = "simple_attr_write",
83311 + [41418].param3 = 1,
83312 + [4155].file = "kernel/kexec.c",
83313 + [4155].name = "do_kimage_alloc",
83314 + [4155].param3 = 1,
83315 + [41592].file = "net/sctp/ssnmap.c",
83316 + [41592].name = "sctp_ssnmap_new",
83317 + [41592].param1 = 1,
83318 + [41592].param2 = 1,
83319 + [41616].file = "net/core/filter.c",
83320 + [41616].name = "sk_chk_filter",
83321 + [41616].param2 = 1,
83322 + [41676].file = "fs/compat.c",
83323 + [41676].name = "compat_sys_preadv",
83324 + [41676].param3 = 1,
83325 + [41727].file = "drivers/media/video/meye.c",
83326 + [41727].name = "rvmalloc",
83327 + [41727].param1 = 1,
83328 + [41884].file = "sound/core/oss/pcm_plugin.c",
83329 + [41884].name = "snd_pcm_plug_alloc",
83330 + [41884].param2 = 1,
83331 + [41924].file = "security/keys/keyctl.c",
83332 + [41924].name = "keyctl_get_security",
83333 + [41924].param3 = 1,
83334 + [4202].file = "drivers/edac/edac_mc.c",
83335 + [4202].name = "edac_mc_alloc",
83336 + [4202].param1 = 1,
83337 + [42143].file = "drivers/media/video/c-qcam.c",
83338 + [42143].name = "qcam_read",
83339 + [42143].param3 = 1,
83340 + [42206].file = "fs/quota/quota_tree.c",
83341 + [42206].name = "getdqbuf",
83342 + [42206].param1 = 1,
83343 + [42270].file = "net/wireless/scan.c",
83344 + [42270].name = "cfg80211_inform_bss_frame",
83345 + [42270].param4 = 1,
83346 + [4233].file = "fs/select.c",
83347 + [4233].name = "sys_poll",
83348 + [4233].param2 = 1,
83349 + [42378].file = "drivers/net/wireless/ath/ath6kl/debug.c",
83350 + [42378].name = "ath6kl_regread_write",
83351 + [42378].param3 = 1,
83352 + [42420].file = "drivers/net/wireless/hostap/hostap_ioctl.c",
83353 + [42420].name = "prism2_set_genericelement",
83354 + [42420].param3 = 1,
83355 + [42466].file = "drivers/scsi/lpfc/lpfc_debugfs.c",
83356 + [42466].name = "lpfc_idiag_cmd_get",
83357 + [42466].param2 = 1,
83358 + [42472].file = "fs/compat.c",
83359 + [42472].name = "compat_readv",
83360 + [42472].param3 = 1,
83361 + [42483].file = "drivers/media/video/videobuf-dma-sg.c",
83362 + [42483].name = "videobuf_dma_init_user_locked",
83363 + [42483].param3 = 1,
83364 + [42483].param4 = 1,
83365 + [42562].file = "kernel/kfifo.c",
83366 + [42562].name = "__kfifo_to_user_r",
83367 + [42562].param3 = 1,
83368 + [42666].file = "drivers/pcmcia/cistpl.c",
83369 + [42666].name = "read_cis_cache",
83370 + [42666].param4 = 1,
83371 + [42882].file = "security/keys/user_defined.c",
83372 + [42882].name = "user_instantiate",
83373 + [42882].param3 = 1,
83374 + [42964].file = "drivers/video/fb_sys_fops.c",
83375 + [42964].name = "fb_sys_read",
83376 + [42964].param3 = 1,
83377 + [43023].file = "drivers/usb/misc/usblcd.c",
83378 + [43023].name = "lcd_write",
83379 + [43023].param3 = 1,
83380 + [4324].file = "drivers/video/fbmem.c",
83381 + [4324].name = "fb_read",
83382 + [4324].param3 = 1,
83383 + [43380].file = "drivers/scsi/bfa/bfad_debugfs.c",
83384 + [43380].name = "bfad_debugfs_write_regrd",
83385 + [43380].param3 = 1,
83386 + [43393].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
83387 + [43393].name = "iwl_dbgfs_sram_write",
83388 + [43393].param3 = 1,
83389 + [4344].file = "fs/namei.c",
83390 + [4344].name = "sys_mkdirat",
83391 + [4344].param2 = 1,
83392 + [43510].file = "kernel/kexec.c",
83393 + [43510].name = "compat_sys_kexec_load",
83394 + [43510].param2 = 1,
83395 + [43515].file = "drivers/usb/storage/jumpshot.c",
83396 + [43515].name = "jumpshot_read_data",
83397 + [43515].param4 = 1,
83398 + [43540].file = "include/rdma/ib_verbs.h",
83399 + [43540].name = "ib_copy_to_udata",
83400 + [43540].param3 = 1,
83401 + [4357].file = "security/tomoyo/securityfs_if.c",
83402 + [4357].name = "tomoyo_read_self",
83403 + [4357].param3 = 1,
83404 + [43590].file = "security/smack/smackfs.c",
83405 + [43590].name = "smk_write_onlycap",
83406 + [43590].param3 = 1,
83407 + [43596].file = "drivers/usb/core/buffer.c",
83408 + [43596].name = "hcd_buffer_alloc",
83409 + [43596].param2 = 1,
83410 + [43632].file = "drivers/media/video/videobuf2-core.c",
83411 + [43632].name = "vb2_read",
83412 + [43632].param3 = 1,
83413 + [43731].file = "drivers/hid/hid-picolcd.c",
83414 + [43731].name = "picolcd_debug_eeprom_read",
83415 + [43731].param3 = 1,
83416 + [43777].file = "drivers/acpi/acpica/utobject.c",
83417 + [43777].name = "acpi_ut_create_buffer_object",
83418 + [43777].param1 = 1,
83419 + [43834].file = "security/apparmor/apparmorfs.c",
83420 + [43834].name = "profile_replace",
83421 + [43834].param3 = 1,
83422 + [43899].file = "drivers/media/rc/imon.c",
83423 + [43899].name = "vfd_write",
83424 + [43899].param3 = 1,
83425 + [43982].file = "drivers/platform/x86/toshiba_acpi.c",
83426 + [43982].name = "keys_proc_write",
83427 + [43982].param3 = 1,
83428 + [44039].file = "drivers/video/via/viafbdev.c",
83429 + [44039].name = "odev_update",
83430 + [44039].param2 = 1,
83431 + [44050].file = "fs/nfs/idmap.c",
83432 + [44050].name = "nfs_map_group_to_gid",
83433 + [44050].param3 = 1,
83434 + [44125].file = "fs/ext4/super.c",
83435 + [44125].name = "ext4_kvmalloc",
83436 + [44125].param1 = 1,
83437 + [44180].file = "drivers/video/via/viafbdev.c",
83438 + [44180].name = "viafb_vt1636_proc_write",
83439 + [44180].param3 = 1,
83440 + [44290].file = "drivers/net/usb/dm9601.c",
83441 + [44290].name = "dm_read",
83442 + [44290].param3 = 1,
83443 + [44298].file = "drivers/scsi/pmcraid.c",
83444 + [44298].name = "pmcraid_copy_sglist",
83445 + [44298].param3 = 1,
83446 + [44365].file = "fs/namei.c",
83447 + [44365].name = "do_rmdir",
83448 + [44365].param2 = 1,
83449 + [44640].file = "fs/select.c",
83450 + [44640].name = "sys_ppoll",
83451 + [44640].param2 = 1,
83452 + [44649].file = "mm/page_cgroup.c",
83453 + [44649].name = "swap_cgroup_swapon",
83454 + [44649].param2 = 1,
83455 + [44656].file = "drivers/net/wireless/iwlegacy/iwl-debugfs.c",
83456 + [44656].name = "iwl_legacy_dbgfs_wd_timeout_write",
83457 + [44656].param3 = 1,
83458 + [4471].file = "fs/ntfs/malloc.h",
83459 + [4471].name = "__ntfs_malloc",
83460 + [4471].param1 = 1,
83461 + [44773].file = "drivers/staging/vme/devices/vme_user.c",
83462 + [44773].name = "vme_user_write",
83463 + [44773].param3 = 1,
83464 + [44825].file = "drivers/scsi/osd/osd_initiator.c",
83465 + [44825].name = "_osd_realloc_seg",
83466 + [44825].param3 = 1,
83467 + [44943].file = "mm/util.c",
83468 + [44943].name = "kmemdup",
83469 + [44943].param2 = 1,
83470 + [44990].file = "drivers/media/video/pvrusb2/pvrusb2-ioread.c",
83471 + [44990].name = "pvr2_ioread_set_sync_key",
83472 + [44990].param3 = 1,
83473 + [45000].file = "fs/afs/proc.c",
83474 + [45000].name = "afs_proc_rootcell_write",
83475 + [45000].param3 = 1,
83476 + [45119].file = "drivers/usb/misc/yurex.c",
83477 + [45119].name = "yurex_write",
83478 + [45119].param3 = 1,
83479 + [45169].file = "drivers/video/metronomefb.c",
83480 + [45169].name = "metronomefb_write",
83481 + [45169].param3 = 1,
83482 + [45200].file = "drivers/scsi/scsi_proc.c",
83483 + [45200].name = "proc_scsi_write_proc",
83484 + [45200].param3 = 1,
83485 + [45217].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
83486 + [45217].name = "iwl_dbgfs_debug_level_write",
83487 + [45217].param3 = 1,
83488 + [45231].file = "fs/ecryptfs/crypto.c",
83489 + [45231].name = "ecryptfs_copy_filename",
83490 + [45231].param4 = 1,
83491 + [45233].file = "net/rds/info.c",
83492 + [45233].name = "rds_info_getsockopt",
83493 + [45233].param3 = 1,
83494 + [45244].file = "drivers/mfd/ab3100-core.c",
83495 + [45244].name = "ab3100_get_set_reg",
83496 + [45244].param3 = 1,
83497 + [45264].file = "drivers/net/wireless/ath/ath5k/debug.c",
83498 + [45264].name = "write_file_ani",
83499 + [45264].param3 = 1,
83500 + [45326].file = "drivers/mtd/ubi/cdev.c",
83501 + [45326].name = "vol_cdev_read",
83502 + [45326].param3 = 1,
83503 + [45335].file = "fs/read_write.c",
83504 + [45335].name = "vfs_writev",
83505 + [45335].param3 = 1,
83506 + [45421].file = "drivers/message/fusion/mptctl.c",
83507 + [45421].name = "mptctl_do_mpt_command",
83508 + [45421].param3 = 1,
83509 + [45534].file = "drivers/net/wireless/ath/carl9170/cmd.c",
83510 + [45534].name = "carl9170_cmd_buf",
83511 + [45534].param3 = 1,
83512 + [45576].file = "net/netfilter/xt_recent.c",
83513 + [45576].name = "recent_mt_proc_write",
83514 + [45576].param3 = 1,
83515 + [45586].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
83516 + [45586].name = "rt2x00debug_write_bbp",
83517 + [45586].param3 = 1,
83518 + [45629].file = "lib/bch.c",
83519 + [45629].name = "bch_alloc",
83520 + [45629].param1 = 1,
83521 + [45633].file = "drivers/input/evdev.c",
83522 + [45633].name = "evdev_do_ioctl",
83523 + [45633].param2 = 1,
83524 + [45740].file = "drivers/net/wireless/ath/ath6kl/debug.c",
83525 + [45740].name = "ath6kl_lrssi_roam_write",
83526 + [45740].param3 = 1,
83527 + [45747].file = "net/netlink/af_netlink.c",
83528 + [45747].name = "__netlink_change_ngroups",
83529 + [45747].param2 = 1,
83530 + [45930].file = "security/apparmor/apparmorfs.c",
83531 + [45930].name = "profile_remove",
83532 + [45930].param3 = 1,
83533 + [45954].file = "drivers/usb/misc/legousbtower.c",
83534 + [45954].name = "tower_write",
83535 + [45954].param3 = 1,
83536 + [45995].file = "fs/namei.c",
83537 + [45995].name = "sys_mknodat",
83538 + [45995].param2 = 1,
83539 + [46072].file = "drivers/video/arcfb.c",
83540 + [46072].name = "arcfb_write",
83541 + [46072].param3 = 1,
83542 + [46140].file = "sound/core/memalloc.c",
83543 + [46140].name = "snd_mem_proc_write",
83544 + [46140].param3 = 1,
83545 + [4614].file = "sound/core/pcm_lib.c",
83546 + [4614].name = "snd_pcm_lib_write_transfer",
83547 + [4614].param5 = 1,
83548 + [4616].file = "net/sunrpc/cache.c",
83549 + [4616].name = "cache_do_downcall",
83550 + [4616].param3 = 1,
83551 + [46243].file = "fs/binfmt_misc.c",
83552 + [46243].name = "bm_register_write",
83553 + [46243].param3 = 1,
83554 + [46250].file = "fs/xattr.c",
83555 + [46250].name = "sys_getxattr",
83556 + [46250].param4 = 1,
83557 + [46343].file = "fs/compat.c",
83558 + [46343].name = "compat_do_readv_writev",
83559 + [46343].param4 = 1,
83560 + [4644].file = "drivers/net/usb/mcs7830.c",
83561 + [4644].name = "mcs7830_get_reg",
83562 + [4644].param3 = 1,
83563 + [46605].file = "sound/core/oss/pcm_oss.c",
83564 + [46605].name = "snd_pcm_oss_sync1",
83565 + [46605].param2 = 1,
83566 + [46630].file = "net/decnet/af_decnet.c",
83567 + [46630].name = "__dn_setsockopt",
83568 + [46630].param5 = 1,
83569 + [46655].file = "drivers/media/video/hdpvr/hdpvr-video.c",
83570 + [46655].name = "hdpvr_read",
83571 + [46655].param3 = 1,
83572 + [46685].file = "drivers/gpu/drm/ttm/ttm_bo_vm.c",
83573 + [46685].name = "ttm_bo_fbdev_io",
83574 + [46685].param4 = 1,
83575 + [46752].file = "drivers/staging/pohmelfs/dir.c",
83576 + [46752].name = "pohmelfs_name_alloc",
83577 + [46752].param1 = 1,
83578 + [46881].file = "drivers/char/lp.c",
83579 + [46881].name = "lp_write",
83580 + [46881].param3 = 1,
83581 + [47130].file = "kernel/kfifo.c",
83582 + [47130].name = "kfifo_copy_to_user",
83583 + [47130].param3 = 1,
83584 + [47265].file = "drivers/scsi/bnx2fc/bnx2fc_io.c",
83585 + [47265].name = "bnx2fc_cmd_mgr_alloc",
83586 + [47265].param2 = 1,
83587 + [47265].param3 = 1,
83588 + [47342].file = "fs/proc/base.c",
83589 + [47342].name = "sched_autogroup_write",
83590 + [47342].param3 = 1,
83591 + [47363].file = "drivers/input/evdev.c",
83592 + [47363].name = "evdev_ioctl_handler",
83593 + [47363].param2 = 1,
83594 + [47385].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
83595 + [47385].name = "zd_usb_iowrite16v",
83596 + [47385].param3 = 1,
83597 + [47463].file = "fs/xfs/kmem.c",
83598 + [47463].name = "kmem_zalloc",
83599 + [47463].param1 = 1,
83600 + [47636].file = "drivers/usb/class/usblp.c",
83601 + [47636].name = "usblp_ioctl",
83602 + [47636].param2 = 1,
83603 + [47637].file = "drivers/block/cciss.c",
83604 + [47637].name = "cciss_proc_write",
83605 + [47637].param3 = 1,
83606 + [47652].file = "lib/kstrtox.c",
83607 + [47652].name = "kstrtoll_from_user",
83608 + [47652].param2 = 1,
83609 + [47881].file = "security/selinux/selinuxfs.c",
83610 + [47881].name = "sel_write_disable",
83611 + [47881].param3 = 1,
83612 + [48010].file = "drivers/net/wireless/ath/ath9k/debug.c",
83613 + [48010].name = "write_file_rx_chainmask",
83614 + [48010].param3 = 1,
83615 + [48155].file = "net/sctp/sm_make_chunk.c",
83616 + [48155].name = "sctp_make_abort_user",
83617 + [48155].param3 = 1,
83618 + [48182].file = "crypto/cryptd.c",
83619 + [48182].name = "cryptd_alloc_instance",
83620 + [48182].param2 = 1,
83621 + [48248].file = "security/keys/keyctl.c",
83622 + [48248].name = "keyctl_instantiate_key",
83623 + [48248].param3 = 1,
83624 + [48461].file = "drivers/gpu/drm/drm_memory.c",
83625 + [48461].name = "agp_remap",
83626 + [48461].param2 = 1,
83627 + [48642].file = "fs/hugetlbfs/inode.c",
83628 + [48642].name = "hugetlbfs_read",
83629 + [48642].param3 = 1,
83630 + [48720].file = "drivers/gpu/drm/i915/i915_debugfs.c",
83631 + [48720].name = "i915_max_freq_write",
83632 + [48720].param3 = 1,
83633 + [48768].file = "net/irda/irnet/irnet_ppp.c",
83634 + [48768].name = "dev_irnet_write",
83635 + [48768].param3 = 1,
83636 + [48856].file = "drivers/acpi/acpica/utalloc.c",
83637 + [48856].name = "acpi_ut_initialize_buffer",
83638 + [48856].param2 = 1,
83639 + [48941].file = "drivers/gpu/drm/nouveau/nouveau_vm.c",
83640 + [48941].name = "nouveau_vm_new",
83641 + [48941].param2 = 1,
83642 + [48941].param3 = 1,
83643 + [49126].file = "lib/prio_heap.c",
83644 + [49126].name = "heap_init",
83645 + [49126].param2 = 1,
83646 + [49143].file = "sound/core/oss/pcm_oss.c",
83647 + [49143].name = "snd_pcm_oss_write2",
83648 + [49143].param3 = 1,
83649 + [49216].file = "fs/read_write.c",
83650 + [49216].name = "do_readv_writev",
83651 + [49216].param4 = 1,
83652 + [49354].file = "drivers/media/video/cx18/cx18-fileops.c",
83653 + [49354].name = "cx18_v4l2_read",
83654 + [49354].param3 = 1,
83655 + [49448].file = "drivers/isdn/gigaset/common.c",
83656 + [49448].name = "gigaset_initdriver",
83657 + [49448].param2 = 1,
83658 + [49494].file = "drivers/virtio/virtio_ring.c",
83659 + [49494].name = "vring_new_virtqueue",
83660 + [49494].param1 = 1,
83661 + [49507].file = "fs/namei.c",
83662 + [49507].name = "sys_symlink",
83663 + [49507].param1 = 1,
83664 + [49604].file = "crypto/af_alg.c",
83665 + [49604].name = "alg_setsockopt",
83666 + [49604].param5 = 1,
83667 + [49646].file = "drivers/tty/vt/vt.c",
83668 + [49646].name = "vc_resize",
83669 + [49646].param2 = 1,
83670 + [49646].param3 = 1,
83671 + [49663].file = "drivers/media/video/uvc/uvc_driver.c",
83672 + [49663].name = "uvc_simplify_fraction",
83673 + [49663].param3 = 1,
83674 + [49718].file = "drivers/hid/hid-roccat-common.c",
83675 + [49718].name = "roccat_common_send",
83676 + [49718].param4 = 1,
83677 + [4972].file = "drivers/video/fb_sys_fops.c",
83678 + [4972].name = "fb_sys_write",
83679 + [4972].param3 = 1,
83680 + [49746].file = "net/ipv4/netfilter/arp_tables.c",
83681 + [49746].name = "compat_do_arpt_set_ctl",
83682 + [49746].param4 = 1,
83683 + [49780].file = "net/mac80211/key.c",
83684 + [49780].name = "ieee80211_key_alloc",
83685 + [49780].param3 = 1,
83686 + [49845].file = "mm/vmalloc.c",
83687 + [49845].name = "__vmalloc_node",
83688 + [49845].param1 = 1,
83689 + [49935].file = "fs/xfs/kmem.c",
83690 + [49935].name = "kmem_zalloc_greedy",
83691 + [49935].param2 = 1,
83692 + [49935].param3 = 1,
83693 + [50001].file = "sound/pci/ctxfi/ctresource.c",
83694 + [50001].name = "rsc_mgr_init",
83695 + [50001].param3 = 1,
83696 + [50022].file = "drivers/usb/storage/shuttle_usbat.c",
83697 + [50022].name = "usbat_flash_read_data",
83698 + [50022].param4 = 1,
83699 + [50096].file = "drivers/net/wireless/libertas/debugfs.c",
83700 + [50096].name = "lbs_rdbbp_write",
83701 + [50096].param3 = 1,
83702 + [50102].file = "drivers/telephony/ixj.c",
83703 + [50102].name = "ixj_write",
83704 + [50102].param3 = 1,
83705 + [50238].file = "drivers/net/wireless/iwlegacy/iwl-debugfs.c",
83706 + [50238].name = "iwl_legacy_dbgfs_clear_ucode_statistics_write",
83707 + [50238].param3 = 1,
83708 + [50267].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
83709 + [50267].name = "rt2x00debug_read_crypto_stats",
83710 + [50267].param3 = 1,
83711 + [50398].file = "fs/proc/base.c",
83712 + [50398].name = "mem_write",
83713 + [50398].param3 = 1,
83714 + [50518].file = "drivers/gpu/drm/nouveau/nouveau_gem.c",
83715 + [50518].name = "u_memcpya",
83716 + [50518].param2 = 1,
83717 + [50518].param3 = 1,
83718 + [5052].file = "drivers/char/ppdev.c",
83719 + [5052].name = "pp_read",
83720 + [5052].param3 = 1,
83721 + [50562].file = "drivers/media/video/zoran/zoran_procfs.c",
83722 + [50562].name = "zoran_write",
83723 + [50562].param3 = 1,
83724 + [50653].file = "net/sunrpc/cache.c",
83725 + [50653].name = "cache_write_procfs",
83726 + [50653].param3 = 1,
83727 + [50692].file = "lib/ts_bm.c",
83728 + [50692].name = "bm_init",
83729 + [50692].param2 = 1,
83730 + [50813].file = "mm/vmalloc.c",
83731 + [50813].name = "__vmalloc_node_flags",
83732 + [50813].param1 = 1,
83733 + [5087].file = "drivers/atm/solos-pci.c",
83734 + [5087].name = "console_store",
83735 + [5087].param4 = 1,
83736 + [5102].file = "drivers/usb/misc/usbtest.c",
83737 + [5102].name = "usbtest_alloc_urb",
83738 + [5102].param3 = 1,
83739 + [5102].param5 = 1,
83740 + [51052].file = "drivers/base/firmware_class.c",
83741 + [51052].name = "firmware_data_write",
83742 + [51052].param6 = 1,
83743 + [51177].file = "net/sunrpc/xprtrdma/transport.c",
83744 + [51177].name = "xprt_rdma_allocate",
83745 + [51177].param2 = 1,
83746 + [51182].file = "drivers/misc/sgi-xp/xpc_main.c",
83747 + [51182].name = "xpc_kzalloc_cacheline_aligned",
83748 + [51182].param1 = 1,
83749 + [51250].file = "fs/read_write.c",
83750 + [51250].name = "rw_copy_check_uvector",
83751 + [51250].param3 = 1,
83752 + [51253].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
83753 + [51253].name = "rt2x00debug_write_eeprom",
83754 + [51253].param3 = 1,
83755 + [51284].file = "drivers/net/wireless/iwlegacy/iwl-debugfs.c",
83756 + [51284].name = "iwl_legacy_dbgfs_interrupt_write",
83757 + [51284].param3 = 1,
83758 + [51323].file = "sound/pci/ac97/ac97_pcm.c",
83759 + [51323].name = "snd_ac97_pcm_assign",
83760 + [51323].param2 = 1,
83761 + [51340].file = "drivers/usb/class/usblp.c",
83762 + [51340].name = "usblp_write",
83763 + [51340].param3 = 1,
83764 + [51471].file = "drivers/block/floppy.c",
83765 + [51471].name = "fd_locked_ioctl",
83766 + [51471].param3 = 1,
83767 + [5197].file = "net/core/dev.c",
83768 + [5197].name = "dev_set_alias",
83769 + [5197].param3 = 1,
83770 + [51998].file = "drivers/net/macvtap.c",
83771 + [51998].name = "macvtap_get_user",
83772 + [51998].param4 = 1,
83773 + [5204].file = "drivers/media/video/usbvision/usbvision-video.c",
83774 + [5204].name = "usbvision_v4l2_read",
83775 + [5204].param3 = 1,
83776 + [52086].file = "drivers/usb/image/mdc800.c",
83777 + [52086].name = "mdc800_device_read",
83778 + [52086].param3 = 1,
83779 + [52172].file = "drivers/pcmcia/cistpl.c",
83780 + [52172].name = "pccard_store_cis",
83781 + [52172].param6 = 1,
83782 + [52173].file = "drivers/misc/ibmasm/ibmasmfs.c",
83783 + [52173].name = "remote_settings_file_write",
83784 + [52173].param3 = 1,
83785 + [52199].file = "mm/nobootmem.c",
83786 + [52199].name = "__alloc_bootmem",
83787 + [52199].param1 = 1,
83788 + [52201].file = "drivers/video/via/viafbdev.c",
83789 + [52201].name = "viafb_dvp0_proc_write",
83790 + [52201].param3 = 1,
83791 + [5233].file = "include/linux/poll.h",
83792 + [5233].name = "set_fd_set",
83793 + [5233].param1 = 1,
83794 + [52343].file = "drivers/usb/misc/adutux.c",
83795 + [52343].name = "adu_read",
83796 + [52343].param3 = 1,
83797 + [52364].file = "sound/core/pcm_lib.c",
83798 + [52364].name = "snd_pcm_lib_readv_transfer",
83799 + [52364].param5 = 1,
83800 + [52401].file = "drivers/staging/rtl8712/rtl871x_ioctl_linux.c",
83801 + [52401].name = "r871x_set_wpa_ie",
83802 + [52401].param3 = 1,
83803 + [52699].file = "lib/ts_fsm.c",
83804 + [52699].name = "fsm_init",
83805 + [52699].param2 = 1,
83806 + [52721].file = "security/keys/encrypted-keys/encrypted.c",
83807 + [52721].name = "encrypted_instantiate",
83808 + [52721].param3 = 1,
83809 + [53041].file = "fs/libfs.c",
83810 + [53041].name = "simple_transaction_get",
83811 + [53041].param3 = 1,
83812 + [5313].file = "fs/gfs2/quota.c",
83813 + [5313].name = "do_sync",
83814 + [5313].param1 = 1,
83815 + [53209].file = "drivers/usb/host/ehci-sched.c",
83816 + [53209].name = "iso_sched_alloc",
83817 + [53209].param1 = 1,
83818 + [53302].file = "drivers/firewire/core-cdev.c",
83819 + [53302].name = "dispatch_ioctl",
83820 + [53302].param2 = 1,
83821 + [53355].file = "fs/ceph/dir.c",
83822 + [53355].name = "ceph_read_dir",
83823 + [53355].param3 = 1,
83824 + [53405].file = "drivers/media/video/videobuf-core.c",
83825 + [53405].name = "__videobuf_copy_to_user",
83826 + [53405].param4 = 1,
83827 + [53407].file = "net/wireless/sme.c",
83828 + [53407].name = "cfg80211_connect_result",
83829 + [53407].param4 = 1,
83830 + [53407].param6 = 1,
83831 + [53426].file = "fs/libfs.c",
83832 + [53426].name = "simple_transaction_read",
83833 + [53426].param3 = 1,
83834 + [5344].file = "security/selinux/ss/hashtab.c",
83835 + [5344].name = "hashtab_create",
83836 + [5344].param3 = 1,
83837 + [53468].file = "drivers/char/mem.c",
83838 + [53468].name = "write_mem",
83839 + [53468].param3 = 1,
83840 + [53513].file = "drivers/mmc/core/mmc_ops.c",
83841 + [53513].name = "mmc_send_bus_test",
83842 + [53513].param4 = 1,
83843 + [53539].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
83844 + [53539].name = "iwl_dbgfs_txfifo_flush_write",
83845 + [53539].param3 = 1,
83846 + [53626].file = "drivers/block/paride/pg.c",
83847 + [53626].name = "pg_read",
83848 + [53626].param3 = 1,
83849 + [53631].file = "mm/util.c",
83850 + [53631].name = "memdup_user",
83851 + [53631].param2 = 1,
83852 + [53680].file = "lib/kstrtox.c",
83853 + [53680].name = "kstrtol_from_user",
83854 + [53680].param2 = 1,
83855 + [5389].file = "drivers/infiniband/core/uverbs_cmd.c",
83856 + [5389].name = "ib_uverbs_unmarshall_recv",
83857 + [5389].param5 = 1,
83858 + [53901].file = "net/rds/message.c",
83859 + [53901].name = "rds_message_alloc",
83860 + [53901].param1 = 1,
83861 + [53904].file = "fs/namei.c",
83862 + [53904].name = "sys_unlink",
83863 + [53904].param1 = 1,
83864 + [5410].file = "kernel/kexec.c",
83865 + [5410].name = "sys_kexec_load",
83866 + [5410].param2 = 1,
83867 + [54182].file = "drivers/block/rbd.c",
83868 + [54182].name = "rbd_snap_add",
83869 + [54182].param4 = 1,
83870 + [5419].file = "drivers/net/wireless/iwlegacy/iwl-debugfs.c",
83871 + [5419].name = "iwl_legacy_dbgfs_disable_ht40_write",
83872 + [5419].param3 = 1,
83873 + [54201].file = "drivers/platform/x86/asus_acpi.c",
83874 + [54201].name = "mled_proc_write",
83875 + [54201].param3 = 1,
83876 + [5422].file = "fs/namei.c",
83877 + [5422].name = "do_unlinkat",
83878 + [5422].param2 = 1,
83879 + [54252].file = "drivers/scsi/st.c",
83880 + [54252].name = "st_write",
83881 + [54252].param3 = 1,
83882 + [54263].file = "security/keys/trusted.c",
83883 + [54263].name = "trusted_instantiate",
83884 + [54263].param3 = 1,
83885 + [54298].file = "drivers/usb/wusbcore/crypto.c",
83886 + [54298].name = "wusb_ccm_mac",
83887 + [54298].param7 = 1,
83888 + [54318].file = "include/drm/drm_mem_util.h",
83889 + [54318].name = "drm_malloc_ab",
83890 + [54318].param1 = 1,
83891 + [54318].param2 = 1,
83892 + [54335].file = "drivers/md/dm-table.c",
83893 + [54335].name = "dm_vcalloc",
83894 + [54335].param1 = 1,
83895 + [54335].param2 = 1,
83896 + [54339].file = "security/smack/smackfs.c",
83897 + [54339].name = "smk_write_cipso",
83898 + [54339].param3 = 1,
83899 + [5438].file = "sound/core/memory.c",
83900 + [5438].name = "copy_to_user_fromio",
83901 + [5438].param3 = 1,
83902 + [54401].file = "lib/dynamic_debug.c",
83903 + [54401].name = "ddebug_proc_write",
83904 + [54401].param3 = 1,
83905 + [54427].file = "drivers/usb/storage/jumpshot.c",
83906 + [54427].name = "jumpshot_write_data",
83907 + [54427].param4 = 1,
83908 + [54467].file = "net/packet/af_packet.c",
83909 + [54467].name = "packet_setsockopt",
83910 + [54467].param5 = 1,
83911 + [54573].file = "ipc/sem.c",
83912 + [54573].name = "sys_semop",
83913 + [54573].param3 = 1,
83914 + [54643].file = "drivers/isdn/hardware/eicon/divasi.c",
83915 + [54643].name = "um_idi_write",
83916 + [54643].param3 = 1,
83917 + [54657].file = "mm/migrate.c",
83918 + [54657].name = "do_pages_stat",
83919 + [54657].param2 = 1,
83920 + [54663].file = "drivers/isdn/hardware/eicon/platform.h",
83921 + [54663].name = "diva_os_malloc",
83922 + [54663].param2 = 1,
83923 + [54751].file = "drivers/infiniband/core/device.c",
83924 + [54751].name = "ib_alloc_device",
83925 + [54751].param1 = 1,
83926 + [54806].file = "drivers/scsi/lpfc/lpfc_debugfs.c",
83927 + [54806].name = "lpfc_debugfs_dif_err_write",
83928 + [54806].param3 = 1,
83929 + [5494].file = "fs/cifs/cifsacl.c",
83930 + [5494].name = "cifs_idmap_key_instantiate",
83931 + [5494].param3 = 1,
83932 + [55066].file = "net/ipv6/ipv6_sockglue.c",
83933 + [55066].name = "do_ipv6_setsockopt",
83934 + [55066].param5 = 1,
83935 + [55105].file = "drivers/base/devres.c",
83936 + [55105].name = "devres_alloc",
83937 + [55105].param2 = 1,
83938 + [55115].file = "net/sctp/probe.c",
83939 + [55115].name = "sctpprobe_read",
83940 + [55115].param3 = 1,
83941 + [55155].file = "net/bluetooth/rfcomm/sock.c",
83942 + [55155].name = "rfcomm_sock_setsockopt",
83943 + [55155].param5 = 1,
83944 + [55187].file = "security/keys/keyctl.c",
83945 + [55187].name = "keyctl_describe_key",
83946 + [55187].param3 = 1,
83947 + [5524].file = "lib/kstrtox.c",
83948 + [5524].name = "kstrtos8_from_user",
83949 + [5524].param2 = 1,
83950 + [55253].file = "drivers/net/wireless/ray_cs.c",
83951 + [55253].name = "ray_cs_essid_proc_write",
83952 + [55253].param3 = 1,
83953 + [5548].file = "drivers/media/media-entity.c",
83954 + [5548].name = "media_entity_init",
83955 + [5548].param2 = 1,
83956 + [5548].param4 = 1,
83957 + [55580].file = "drivers/usb/mon/mon_bin.c",
83958 + [55580].name = "copy_from_buf",
83959 + [55580].param2 = 1,
83960 + [55682].file = "drivers/net/wireless/libertas/debugfs.c",
83961 + [55682].name = "lbs_host_sleep_write",
83962 + [55682].param3 = 1,
83963 + [55712].file = "drivers/char/mem.c",
83964 + [55712].name = "read_zero",
83965 + [55712].param3 = 1,
83966 + [55857].file = "drivers/net/wireless/ath/ath9k/debug.c",
83967 + [55857].name = "write_file_tx_chainmask",
83968 + [55857].param3 = 1,
83969 + [55978].file = "drivers/usb/misc/iowarrior.c",
83970 + [55978].name = "iowarrior_write",
83971 + [55978].param3 = 1,
83972 + [5599].file = "drivers/char/random.c",
83973 + [5599].name = "write_pool",
83974 + [5599].param3 = 1,
83975 + [56090].file = "drivers/media/video/videobuf-dma-sg.c",
83976 + [56090].name = "__videobuf_alloc_vb",
83977 + [56090].param1 = 1,
83978 + [56199].file = "fs/binfmt_misc.c",
83979 + [56199].name = "parse_command",
83980 + [56199].param2 = 1,
83981 + [56218].file = "drivers/mmc/card/mmc_test.c",
83982 + [56218].name = "mtf_test_write",
83983 + [56218].param3 = 1,
83984 + [56416].file = "drivers/misc/lkdtm.c",
83985 + [56416].name = "do_register_entry",
83986 + [56416].param4 = 1,
83987 + [56432].file = "drivers/mfd/aat2870-core.c",
83988 + [56432].name = "aat2870_reg_write_file",
83989 + [56432].param3 = 1,
83990 + [56471].file = "include/linux/slab.h",
83991 + [56471].name = "kcalloc",
83992 + [56471].param1 = 1,
83993 + [56471].param2 = 1,
83994 + [56513].file = "fs/cifs/connect.c",
83995 + [56513].name = "cifs_readv_from_socket",
83996 + [56513].param3 = 1,
83997 + [56544].file = "drivers/block/drbd/drbd_receiver.c",
83998 + [56544].name = "receive_DataRequest",
83999 + [56544].param3 = 1,
84000 + [5661].file = "lib/dma-debug.c",
84001 + [5661].name = "filter_write",
84002 + [5661].param3 = 1,
84003 + [56672].file = "drivers/char/agp/generic.c",
84004 + [56672].name = "agp_alloc_page_array",
84005 + [56672].param1 = 1,
84006 + [56843].file = "drivers/scsi/scsi_transport_iscsi.c",
84007 + [56843].name = "iscsi_recv_pdu",
84008 + [56843].param4 = 1,
84009 + [57120].file = "lib/kstrtox.c",
84010 + [57120].name = "kstrtouint_from_user",
84011 + [57120].param2 = 1,
84012 + [57128].file = "drivers/pnp/pnpbios/proc.c",
84013 + [57128].name = "pnpbios_proc_write",
84014 + [57128].param3 = 1,
84015 + [57190].file = "drivers/char/agp/generic.c",
84016 + [57190].name = "agp_generic_alloc_user",
84017 + [57190].param1 = 1,
84018 + [57471].file = "drivers/media/video/sn9c102/sn9c102_core.c",
84019 + [57471].name = "sn9c102_read",
84020 + [57471].param3 = 1,
84021 + [57605].file = "net/netlink/af_netlink.c",
84022 + [57605].name = "netlink_kernel_create",
84023 + [57605].param3 = 1,
84024 + [57670].file = "drivers/bluetooth/btmrvl_debugfs.c",
84025 + [57670].name = "btmrvl_pscmd_write",
84026 + [57670].param3 = 1,
84027 + [57675].file = "drivers/net/wireless/ath/ath9k/debug.c",
84028 + [57675].name = "write_file_regidx",
84029 + [57675].param3 = 1,
84030 + [57724].file = "net/bluetooth/hci_sock.c",
84031 + [57724].name = "hci_sock_setsockopt",
84032 + [57724].param5 = 1,
84033 + [57748].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
84034 + [57748].name = "iwl_dbgfs_missed_beacon_write",
84035 + [57748].param3 = 1,
84036 + [57786].file = "net/ipv6/netfilter/ip6_tables.c",
84037 + [57786].name = "compat_do_ip6t_set_ctl",
84038 + [57786].param4 = 1,
84039 + [57872].file = "fs/ceph/xattr.c",
84040 + [57872].name = "ceph_setxattr",
84041 + [57872].param4 = 1,
84042 + [57927].file = "fs/read_write.c",
84043 + [57927].name = "sys_preadv",
84044 + [57927].param3 = 1,
84045 + [58020].file = "drivers/firewire/core-cdev.c",
84046 + [58020].name = "fw_device_op_ioctl",
84047 + [58020].param2 = 1,
84048 + [58043].file = "kernel/auditfilter.c",
84049 + [58043].name = "audit_unpack_string",
84050 + [58043].param3 = 1,
84051 + [5805].file = "drivers/xen/grant-table.c",
84052 + [5805].name = "gnttab_alloc_grant_references",
84053 + [5805].param1 = 1,
84054 + [58087].file = "kernel/module.c",
84055 + [58087].name = "module_alloc_update_bounds_rw",
84056 + [58087].param1 = 1,
84057 + [58107].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
84058 + [58107].name = "iwl_dbgfs_sleep_level_override_write",
84059 + [58107].param3 = 1,
84060 + [58124].file = "drivers/usb/misc/usbtest.c",
84061 + [58124].name = "ctrl_out",
84062 + [58124].param3 = 1,
84063 + [58124].param5 = 1,
84064 + [58263].file = "security/keys/keyring.c",
84065 + [58263].name = "keyring_read",
84066 + [58263].param3 = 1,
84067 + [58278].file = "drivers/net/wireless/iwlwifi/iwl-trans-pcie.c",
84068 + [58278].name = "iwl_dbgfs_log_event_write",
84069 + [58278].param3 = 1,
84070 + [5830].file = "drivers/gpu/vga/vga_switcheroo.c",
84071 + [5830].name = "vga_switcheroo_debugfs_write",
84072 + [5830].param3 = 1,
84073 + [58320].file = "drivers/scsi/scsi_proc.c",
84074 + [58320].name = "proc_scsi_write",
84075 + [58320].param3 = 1,
84076 + [58344].file = "net/sunrpc/cache.c",
84077 + [58344].name = "read_flush",
84078 + [58344].param3 = 1,
84079 + [58392].file = "fs/namei.c",
84080 + [58392].name = "getname_flags",
84081 + [58392].param1 = 1,
84082 + [58418].file = "kernel/module.c",
84083 + [58418].name = "sys_init_module",
84084 + [58418].param2 = 1,
84085 + [58502].file = "sound/core/sgbuf.c",
84086 + [58502].name = "snd_malloc_sgbuf_pages",
84087 + [58502].param2 = 1,
84088 + [58597].file = "kernel/kfifo.c",
84089 + [58597].name = "__kfifo_to_user",
84090 + [58597].param3 = 1,
84091 + [58641].file = "drivers/usb/misc/adutux.c",
84092 + [58641].name = "adu_write",
84093 + [58641].param3 = 1,
84094 + [58709].file = "fs/compat.c",
84095 + [58709].name = "compat_sys_pwritev",
84096 + [58709].param3 = 1,
84097 + [58769].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
84098 + [58769].name = "zd_usb_read_fw",
84099 + [58769].param4 = 1,
84100 + [5876].file = "drivers/net/ppp/ppp_generic.c",
84101 + [5876].name = "ppp_write",
84102 + [5876].param3 = 1,
84103 + [58826].file = "net/sunrpc/xprt.c",
84104 + [58826].name = "xprt_alloc",
84105 + [58826].param2 = 1,
84106 + [58867].file = "drivers/platform/x86/asus_acpi.c",
84107 + [58867].name = "wled_proc_write",
84108 + [58867].param3 = 1,
84109 + [58878].file = "drivers/net/wireless/libertas/debugfs.c",
84110 + [58878].name = "lbs_wrbbp_write",
84111 + [58878].param3 = 1,
84112 + [58888].file = "fs/xattr.c",
84113 + [58888].name = "listxattr",
84114 + [58888].param3 = 1,
84115 + [58912].file = "drivers/lguest/core.c",
84116 + [58912].name = "__lgwrite",
84117 + [58912].param4 = 1,
84118 + [58918].file = "sound/core/pcm_native.c",
84119 + [58918].name = "snd_pcm_aio_write",
84120 + [58918].param3 = 1,
84121 + [58919].file = "net/netlabel/netlabel_unlabeled.c",
84122 + [58919].name = "netlbl_unlabel_init",
84123 + [58919].param1 = 1,
84124 + [58942].file = "drivers/block/aoe/aoedev.c",
84125 + [58942].name = "aoedev_flush",
84126 + [58942].param2 = 1,
84127 + [58958].file = "fs/fuse/control.c",
84128 + [58958].name = "fuse_conn_limit_write",
84129 + [58958].param3 = 1,
84130 + [58].file = "lib/kstrtox.c",
84131 + [58].name = "kstrtoull_from_user",
84132 + [58].param2 = 1,
84133 + [59034].file = "drivers/acpi/acpica/dsobject.c",
84134 + [59034].name = "acpi_ds_build_internal_package_obj",
84135 + [59034].param3 = 1,
84136 + [59073].file = "drivers/staging/speakup/i18n.c",
84137 + [59073].name = "msg_set",
84138 + [59073].param3 = 1,
84139 + [59108].file = "drivers/net/wireless/ath/ath5k/debug.c",
84140 + [59108].name = "write_file_queue",
84141 + [59108].param3 = 1,
84142 + [59297].file = "drivers/media/dvb/ttpci/av7110_av.c",
84143 + [59297].name = "dvb_play",
84144 + [59297].param3 = 1,
84145 + [59472].file = "drivers/misc/ibmasm/ibmasmfs.c",
84146 + [59472].name = "command_file_write",
84147 + [59472].param3 = 1,
84148 + [59505].file = "drivers/media/video/pvrusb2/pvrusb2-ioread.c",
84149 + [59505].name = "pvr2_ioread_read",
84150 + [59505].param3 = 1,
84151 + [59681].file = "fs/xfs/kmem.c",
84152 + [59681].name = "kmem_alloc",
84153 + [59681].param1 = 1,
84154 + [5968].file = "net/sunrpc/sched.c",
84155 + [5968].name = "rpc_malloc",
84156 + [5968].param2 = 1,
84157 + [59794].file = "mm/mincore.c",
84158 + [59794].name = "sys_mincore",
84159 + [59794].param1 = 1,
84160 + [59794].param2 = 1,
84161 + [59838].file = "net/netlink/af_netlink.c",
84162 + [59838].name = "nl_pid_hash_zalloc",
84163 + [59838].param1 = 1,
84164 + [59856].file = "drivers/base/devres.c",
84165 + [59856].name = "devm_kzalloc",
84166 + [59856].param2 = 1,
84167 + [59991].file = "drivers/media/video/uvc/uvc_queue.c",
84168 + [59991].name = "uvc_alloc_buffers",
84169 + [59991].param2 = 1,
84170 + [59991].param3 = 1,
84171 + [60005].file = "fs/namei.c",
84172 + [60005].name = "getname",
84173 + [60005].param1 = 1,
84174 + [60066].file = "mm/filemap.c",
84175 + [60066].name = "iov_iter_copy_from_user",
84176 + [60066].param4 = 1,
84177 + [60198].file = "fs/nfs/nfs4proc.c",
84178 + [60198].name = "nfs4_write_cached_acl",
84179 + [60198].param3 = 1,
84180 + [60330].file = "drivers/media/video/w9966.c",
84181 + [60330].name = "w9966_v4l_read",
84182 + [60330].param3 = 1,
84183 + [6041].file = "drivers/mtd/mtdchar.c",
84184 + [6041].name = "mtd_write",
84185 + [6041].param3 = 1,
84186 + [60436].file = "drivers/net/macvtap.c",
84187 + [60436].name = "macvtap_sendmsg",
84188 + [60436].param4 = 1,
84189 + [60483].file = "drivers/char/virtio_console.c",
84190 + [60483].name = "fill_readbuf",
84191 + [60483].param3 = 1,
84192 + [604].file = "drivers/staging/rtl8712/usb_ops_linux.c",
84193 + [604].name = "r8712_usbctrl_vendorreq",
84194 + [604].param6 = 1,
84195 + [60543].file = "drivers/usb/class/usbtmc.c",
84196 + [60543].name = "usbtmc_read",
84197 + [60543].param3 = 1,
84198 + [60683].file = "sound/drivers/opl4/opl4_proc.c",
84199 + [60683].name = "snd_opl4_mem_proc_write",
84200 + [60683].param5 = 1,
84201 + [60693].file = "drivers/misc/hpilo.c",
84202 + [60693].name = "ilo_read",
84203 + [60693].param3 = 1,
84204 + [60744].file = "sound/pci/emu10k1/emuproc.c",
84205 + [60744].name = "snd_emu10k1_fx8010_read",
84206 + [60744].param5 = 1,
84207 + [60833].file = "drivers/block/aoe/aoenet.c",
84208 + [60833].name = "set_aoe_iflist",
84209 + [60833].param2 = 1,
84210 + [60878].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
84211 + [60878].name = "rt2x00debug_read_queue_dump",
84212 + [60878].param3 = 1,
84213 + [60882].file = "drivers/input/joydev.c",
84214 + [60882].name = "joydev_compat_ioctl",
84215 + [60882].param2 = 1,
84216 + [60891].file = "kernel/sched.c",
84217 + [60891].name = "sys_sched_setaffinity",
84218 + [60891].param2 = 1,
84219 + [60927].file = "drivers/net/wireless/ath/ath9k/debug.c",
84220 + [60927].name = "write_file_disable_ani",
84221 + [60927].param3 = 1,
84222 + [60928].file = "drivers/staging/bcm/Bcmchar.c",
84223 + [60928].name = "bcm_char_read",
84224 + [60928].param3 = 1,
84225 + [61058].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
84226 + [61058].name = "iwl_dbgfs_disable_ht40_write",
84227 + [61058].param3 = 1,
84228 + [61120].file = "drivers/char/mem.c",
84229 + [61120].name = "read_mem",
84230 + [61120].param3 = 1,
84231 + [61222].file = "net/sunrpc/rpc_pipe.c",
84232 + [61222].name = "rpc_pipe_generic_upcall",
84233 + [61222].param4 = 1,
84234 + [61254].file = "drivers/scsi/scsi_devinfo.c",
84235 + [61254].name = "proc_scsi_devinfo_write",
84236 + [61254].param3 = 1,
84237 + [61283].file = "drivers/net/wireless/ath/ath6kl/debug.c",
84238 + [61283].name = "ath6kl_fwlog_read",
84239 + [61283].param3 = 1,
84240 + [61289].file = "security/apparmor/apparmorfs.c",
84241 + [61289].name = "aa_simple_write_to_buffer",
84242 + [61289].param4 = 1,
84243 + [61389].file = "include/linux/slab.h",
84244 + [61389].name = "kzalloc_node",
84245 + [61389].param1 = 1,
84246 + [61546].file = "mm/filemap.c",
84247 + [61546].name = "__iovec_copy_from_user_inatomic",
84248 + [61546].param3 = 1,
84249 + [61546].param4 = 1,
84250 + [61552].file = "drivers/input/evdev.c",
84251 + [61552].name = "str_to_user",
84252 + [61552].param2 = 1,
84253 + [61673].file = "security/keys/trusted.c",
84254 + [61673].name = "trusted_update",
84255 + [61673].param3 = 1,
84256 + [61676].file = "kernel/module.c",
84257 + [61676].name = "module_alloc_update_bounds_rx",
84258 + [61676].param1 = 1,
84259 + [61770].file = "drivers/media/video/et61x251/et61x251_core.c",
84260 + [61770].name = "et61x251_read",
84261 + [61770].param3 = 1,
84262 + [6186].file = "drivers/char/mem.c",
84263 + [6186].name = "read_kmem",
84264 + [6186].param3 = 1,
84265 + [61932].file = "drivers/message/fusion/mptctl.c",
84266 + [61932].name = "__mptctl_ioctl",
84267 + [61932].param2 = 1,
84268 + [62081].file = "drivers/net/irda/vlsi_ir.c",
84269 + [62081].name = "vlsi_alloc_ring",
84270 + [62081].param3 = 1,
84271 + [62116].file = "fs/libfs.c",
84272 + [62116].name = "simple_attr_read",
84273 + [62116].param3 = 1,
84274 + [6225].file = "drivers/block/floppy.c",
84275 + [6225].name = "fd_ioctl",
84276 + [6225].param3 = 1,
84277 + [62294].file = "sound/core/info.c",
84278 + [62294].name = "resize_info_buffer",
84279 + [62294].param2 = 1,
84280 + [62378].file = "net/ipv4/tcp.c",
84281 + [62378].name = "do_tcp_setsockopt",
84282 + [62378].param5 = 1,
84283 + [62387].file = "fs/nfs/idmap.c",
84284 + [62387].name = "nfs_idmap_lookup_id",
84285 + [62387].param2 = 1,
84286 + [62453].file = "fs/namei.c",
84287 + [62453].name = "user_path_create",
84288 + [62453].param2 = 1,
84289 + [62495].file = "drivers/block/floppy.c",
84290 + [62495].name = "fallback_on_nodma_alloc",
84291 + [62495].param2 = 1,
84292 + [62498].file = "fs/xattr.c",
84293 + [62498].name = "sys_listxattr",
84294 + [62498].param3 = 1,
84295 + [62583].file = "drivers/net/wireless/mwifiex/debugfs.c",
84296 + [62583].name = "mwifiex_regrdwr_write",
84297 + [62583].param3 = 1,
84298 + [625].file = "fs/read_write.c",
84299 + [625].name = "sys_pwritev",
84300 + [625].param3 = 1,
84301 + [62669].file = "drivers/platform/x86/asus_acpi.c",
84302 + [62669].name = "tled_proc_write",
84303 + [62669].param3 = 1,
84304 + [62714].file = "security/keys/keyctl.c",
84305 + [62714].name = "keyctl_update_key",
84306 + [62714].param3 = 1,
84307 + [62799].file = "fs/proc/task_mmu.c",
84308 + [62799].name = "pagemap_read",
84309 + [62799].param3 = 1,
84310 + [62811].file = "drivers/usb/misc/legousbtower.c",
84311 + [62811].name = "tower_read",
84312 + [62811].param3 = 1,
84313 + [62851].file = "fs/proc/vmcore.c",
84314 + [62851].name = "read_vmcore",
84315 + [62851].param3 = 1,
84316 + [62925].file = "include/rdma/ib_verbs.h",
84317 + [62925].name = "ib_copy_from_udata",
84318 + [62925].param3 = 1,
84319 + [62967].file = "security/keys/encrypted-keys/encrypted.c",
84320 + [62967].name = "encrypted_update",
84321 + [62967].param3 = 1,
84322 + [62970].file = "net/sched/sch_api.c",
84323 + [62970].name = "qdisc_class_hash_alloc",
84324 + [62970].param1 = 1,
84325 + [62999].file = "net/core/neighbour.c",
84326 + [62999].name = "neigh_hash_alloc",
84327 + [62999].param1 = 1,
84328 + [63004].file = "drivers/usb/storage/datafab.c",
84329 + [63004].name = "datafab_write_data",
84330 + [63004].param4 = 1,
84331 + [63007].file = "fs/proc/base.c",
84332 + [63007].name = "proc_coredump_filter_write",
84333 + [63007].param3 = 1,
84334 + [63010].file = "drivers/gpu/drm/ttm/ttm_page_alloc.c",
84335 + [63010].name = "ttm_page_pool_free",
84336 + [63010].param2 = 1,
84337 + [63076].file = "fs/cifs/xattr.c",
84338 + [63076].name = "cifs_setxattr",
84339 + [63076].param4 = 1,
84340 + [63091].file = "drivers/net/usb/pegasus.c",
84341 + [63091].name = "get_registers",
84342 + [63091].param3 = 1,
84343 + [63169].file = "drivers/scsi/sg.c",
84344 + [63169].name = "sg_read",
84345 + [63169].param3 = 1,
84346 + [6331].file = "drivers/atm/solos-pci.c",
84347 + [6331].name = "solos_param_store",
84348 + [6331].param4 = 1,
84349 + [63367].file = "net/netfilter/ipset/ip_set_core.c",
84350 + [63367].name = "ip_set_alloc",
84351 + [63367].param1 = 1,
84352 + [63473].file = "drivers/staging/pohmelfs/trans.c",
84353 + [63473].name = "netfs_trans_alloc",
84354 + [63473].param2 = 1,
84355 + [63473].param4 = 1,
84356 + [63489].file = "drivers/bluetooth/btmrvl_debugfs.c",
84357 + [63489].name = "btmrvl_hscfgcmd_write",
84358 + [63489].param3 = 1,
84359 + [63490].file = "crypto/shash.c",
84360 + [63490].name = "shash_compat_setkey",
84361 + [63490].param3 = 1,
84362 + [63583].file = "drivers/char/mem.c",
84363 + [63583].name = "write_kmem",
84364 + [63583].param3 = 1,
84365 + [63605].file = "mm/mempool.c",
84366 + [63605].name = "mempool_kmalloc",
84367 + [63605].param2 = 1,
84368 + [63717].file = "drivers/net/wireless/iwlwifi/iwl-trans-pcie.c",
84369 + [63717].name = "iwl_dbgfs_csr_write",
84370 + [63717].param3 = 1,
84371 + [63748].file = "drivers/staging/crystalhd/crystalhd_misc.c",
84372 + [63748].name = "crystalhd_map_dio",
84373 + [63748].param3 = 1,
84374 + [63765].file = "fs/seq_file.c",
84375 + [63765].name = "seq_read",
84376 + [63765].param3 = 1,
84377 + [63777].file = "drivers/virtio/virtio_ring.c",
84378 + [63777].name = "virtqueue_add_buf_gfp",
84379 + [63777].param3 = 1,
84380 + [63777].param4 = 1,
84381 + [63961].file = "fs/xattr.c",
84382 + [63961].name = "sys_flistxattr",
84383 + [63961].param3 = 1,
84384 + [63988].file = "drivers/input/evdev.c",
84385 + [63988].name = "evdev_ioctl_compat",
84386 + [63988].param2 = 1,
84387 + [64118].file = "fs/namei.c",
84388 + [64118].name = "sys_symlinkat",
84389 + [64118].param1 = 1,
84390 + [64156].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
84391 + [64156].name = "ath6kl_mgmt_tx",
84392 + [64156].param9 = 1,
84393 + [64227].file = "mm/nobootmem.c",
84394 + [64227].name = "__alloc_bootmem_node_nopanic",
84395 + [64227].param2 = 1,
84396 + [64312].file = "drivers/video/hecubafb.c",
84397 + [64312].name = "hecubafb_write",
84398 + [64312].param3 = 1,
84399 + [64351].file = "kernel/kfifo.c",
84400 + [64351].name = "kfifo_copy_from_user",
84401 + [64351].param3 = 1,
84402 + [64392].file = "drivers/mmc/core/mmc_ops.c",
84403 + [64392].name = "mmc_send_cxd_data",
84404 + [64392].param5 = 1,
84405 + [64471].file = "drivers/bluetooth/btmrvl_debugfs.c",
84406 + [64471].name = "btmrvl_hscmd_write",
84407 + [64471].param3 = 1,
84408 + [64667].file = "sound/core/oss/pcm_oss.c",
84409 + [64667].name = "snd_pcm_oss_read",
84410 + [64667].param3 = 1,
84411 + [64689].file = "sound/isa/gus/gus_dram.c",
84412 + [64689].name = "snd_gus_dram_read",
84413 + [64689].param4 = 1,
84414 + [64692].file = "fs/binfmt_misc.c",
84415 + [64692].name = "bm_entry_write",
84416 + [64692].param3 = 1,
84417 + [64705].file = "drivers/staging/iio/accel/sca3000_ring.c",
84418 + [64705].name = "sca3000_read_first_n_hw_rb",
84419 + [64705].param2 = 1,
84420 + [64743].file = "fs/ocfs2/dlmfs/dlmfs.c",
84421 + [64743].name = "dlmfs_file_read",
84422 + [64743].param3 = 1,
84423 + [6477].file = "net/bluetooth/mgmt.c",
84424 + [6477].name = "mgmt_pending_add",
84425 + [6477].param5 = 1,
84426 + [64898].file = "drivers/media/video/videobuf-dma-sg.c",
84427 + [64898].name = "videobuf_dma_init_user",
84428 + [64898].param3 = 1,
84429 + [64898].param4 = 1,
84430 + [64906].file = "drivers/net/wireless/b43legacy/debugfs.c",
84431 + [64906].name = "b43legacy_debugfs_write",
84432 + [64906].param3 = 1,
84433 + [64961].file = "drivers/spi/spidev.c",
84434 + [64961].name = "spidev_ioctl",
84435 + [64961].param2 = 1,
84436 + [65033].file = "crypto/shash.c",
84437 + [65033].name = "shash_async_setkey",
84438 + [65033].param3 = 1,
84439 + [65093].file = "security/integrity/evm/evm_secfs.c",
84440 + [65093].name = "evm_write_key",
84441 + [65093].param3 = 1,
84442 + [65098].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
84443 + [65098].name = "iwl_dbgfs_traffic_log_write",
84444 + [65098].param3 = 1,
84445 + [6514].file = "mm/nobootmem.c",
84446 + [6514].name = "__alloc_bootmem_low",
84447 + [6514].param1 = 1,
84448 + [65169].file = "net/core/skbuff.c",
84449 + [65169].name = "dev_alloc_skb",
84450 + [65169].param1 = 1,
84451 + [6517].file = "drivers/md/dm-table.c",
84452 + [6517].name = "alloc_targets",
84453 + [6517].param2 = 1,
84454 + [65195].file = "fs/jffs2/xattr.c",
84455 + [65195].name = "do_jffs2_setxattr",
84456 + [65195].param5 = 1,
84457 + [65237].file = "kernel/profile.c",
84458 + [65237].name = "read_profile",
84459 + [65237].param3 = 1,
84460 + [65345].file = "lib/xz/xz_dec_lzma2.c",
84461 + [65345].name = "xz_dec_lzma2_create",
84462 + [65345].param2 = 1,
84463 + [65364].file = "sound/core/pcm_lib.c",
84464 + [65364].name = "snd_pcm_lib_read_transfer",
84465 + [65364].param5 = 1,
84466 + [65409].file = "net/802/garp.c",
84467 + [65409].name = "garp_request_join",
84468 + [65409].param4 = 1,
84469 + [65432].file = "drivers/hid/hid-roccat-kone.c",
84470 + [65432].name = "kone_receive",
84471 + [65432].param4 = 1,
84472 + [65452].file = "drivers/message/fusion/mptctl.c",
84473 + [65452].name = "mptctl_ioctl",
84474 + [65452].param2 = 1,
84475 + [65514].file = "drivers/media/video/gspca/t613.c",
84476 + [65514].name = "reg_w_ixbuf",
84477 + [65514].param4 = 1,
84478 + [6551].file = "drivers/usb/host/xhci-mem.c",
84479 + [6551].name = "xhci_alloc_stream_info",
84480 + [6551].param3 = 1,
84481 + [65535].file = "drivers/media/dvb/dvb-usb/opera1.c",
84482 + [65535].name = "opera1_xilinx_rw",
84483 + [65535].param5 = 1,
84484 + [6657].file = "drivers/hid/hid-roccat-kone.c",
84485 + [6657].name = "kone_send",
84486 + [6657].param4 = 1,
84487 + [6672].file = "drivers/net/wireless/b43/debugfs.c",
84488 + [6672].name = "b43_debugfs_write",
84489 + [6672].param3 = 1,
84490 + [6691].file = "drivers/acpi/proc.c",
84491 + [6691].name = "acpi_system_write_wakeup_device",
84492 + [6691].param3 = 1,
84493 + [6772].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
84494 + [6772].name = "iwl_dbgfs_force_reset_write",
84495 + [6772].param3 = 1,
84496 + [6780].file = "sound/core/info.c",
84497 + [6780].name = "snd_info_entry_read",
84498 + [6780].param3 = 1,
84499 + [6800].file = "drivers/net/wireless/iwlegacy/iwl-debugfs.c",
84500 + [6800].name = "iwl_legacy_dbgfs_missed_beacon_write",
84501 + [6800].param3 = 1,
84502 + [680].file = "drivers/misc/ibmasm/ibmasmfs.c",
84503 + [680].name = "command_file_read",
84504 + [680].param3 = 1,
84505 + [6865].file = "drivers/staging/iio/ring_sw.c",
84506 + [6865].name = "iio_read_first_n_sw_rb",
84507 + [6865].param2 = 1,
84508 + [6867].file = "fs/coda/psdev.c",
84509 + [6867].name = "coda_psdev_read",
84510 + [6867].param3 = 1,
84511 + [6891].file = "drivers/bluetooth/btmrvl_debugfs.c",
84512 + [6891].name = "btmrvl_gpiogap_write",
84513 + [6891].param3 = 1,
84514 + [6944].file = "drivers/ide/ide-proc.c",
84515 + [6944].name = "ide_settings_proc_write",
84516 + [6944].param3 = 1,
84517 + [6950].file = "drivers/isdn/capi/capi.c",
84518 + [6950].name = "capi_write",
84519 + [6950].param3 = 1,
84520 + [697].file = "sound/isa/gus/gus_dram.c",
84521 + [697].name = "snd_gus_dram_peek",
84522 + [697].param4 = 1,
84523 + [7066].file = "security/keys/keyctl.c",
84524 + [7066].name = "keyctl_instantiate_key_common",
84525 + [7066].param4 = 1,
84526 + [7129].file = "mm/maccess.c",
84527 + [7129].name = "__probe_kernel_read",
84528 + [7129].param3 = 1,
84529 + [720].file = "sound/pci/rme9652/hdsp.c",
84530 + [720].name = "snd_hdsp_playback_copy",
84531 + [720].param5 = 1,
84532 + [7411].file = "drivers/vhost/vhost.c",
84533 + [7411].name = "__vhost_add_used_n",
84534 + [7411].param3 = 1,
84535 + [7488].file = "security/keys/user_defined.c",
84536 + [7488].name = "user_read",
84537 + [7488].param3 = 1,
84538 + [7551].file = "drivers/input/touchscreen/ad7879-spi.c",
84539 + [7551].name = "ad7879_spi_xfer",
84540 + [7551].param3 = 1,
84541 + [7676].file = "drivers/acpi/custom_method.c",
84542 + [7676].name = "cm_write",
84543 + [7676].param3 = 1,
84544 + [7832].file = "drivers/net/wireless/ath/ath5k/debug.c",
84545 + [7832].name = "write_file_antenna",
84546 + [7832].param3 = 1,
84547 + [7843].file = "fs/compat.c",
84548 + [7843].name = "compat_sys_readv",
84549 + [7843].param3 = 1,
84550 + [7958].file = "drivers/gpu/vga/vgaarb.c",
84551 + [7958].name = "vga_arb_write",
84552 + [7958].param3 = 1,
84553 + [7976].file = "drivers/usb/gadget/rndis.c",
84554 + [7976].name = "rndis_add_response",
84555 + [7976].param2 = 1,
84556 + [8014].file = "net/netfilter/ipset/ip_set_list_set.c",
84557 + [8014].name = "init_list_set",
84558 + [8014].param2 = 1,
84559 + [8014].param3 = 1,
84560 + [8087].file = "drivers/video/via/viafbdev.c",
84561 + [8087].name = "viafb_iga1_odev_proc_write",
84562 + [8087].param3 = 1,
84563 + [8126].file = "sound/soc/soc-core.c",
84564 + [8126].name = "codec_reg_read_file",
84565 + [8126].param3 = 1,
84566 + [8185].file = "drivers/net/wireless/ath/ath6kl/debug.c",
84567 + [8185].name = "ath6kl_regwrite_write",
84568 + [8185].param3 = 1,
84569 + [8317].file = "security/smack/smackfs.c",
84570 + [8317].name = "smk_write_ambient",
84571 + [8317].param3 = 1,
84572 + [8334].file = "drivers/scsi/sg.c",
84573 + [8334].name = "sg_proc_write_adio",
84574 + [8334].param3 = 1,
84575 + [8481].file = "drivers/isdn/i4l/isdn_common.c",
84576 + [8481].name = "isdn_write",
84577 + [8481].param3 = 1,
84578 + [8536].file = "fs/cifs/dns_resolve.c",
84579 + [8536].name = "dns_resolve_server_name_to_ip",
84580 + [8536].param1 = 1,
84581 + [8650].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
84582 + [8650].name = "vmw_kms_present",
84583 + [8650].param9 = 1,
84584 + [865].file = "drivers/base/regmap/regmap-debugfs.c",
84585 + [865].name = "regmap_access_read_file",
84586 + [865].param3 = 1,
84587 + [8663].file = "net/bridge/netfilter/ebtables.c",
84588 + [8663].name = "do_update_counters",
84589 + [8663].param4 = 1,
84590 + [8684].file = "fs/read_write.c",
84591 + [8684].name = "sys_writev",
84592 + [8684].param3 = 1,
84593 + [8699].file = "security/selinux/selinuxfs.c",
84594 + [8699].name = "sel_commit_bools_write",
84595 + [8699].param3 = 1,
84596 + [8714].file = "lib/kstrtox.c",
84597 + [8714].name = "kstrtou16_from_user",
84598 + [8714].param2 = 1,
84599 + [8764].file = "drivers/usb/core/devio.c",
84600 + [8764].name = "usbdev_read",
84601 + [8764].param3 = 1,
84602 + [8802].file = "fs/dlm/user.c",
84603 + [8802].name = "device_write",
84604 + [8802].param3 = 1,
84605 + [8810].file = "net/mac80211/debugfs_sta.c",
84606 + [8810].name = "sta_agg_status_write",
84607 + [8810].param3 = 1,
84608 + [8815].file = "security/tomoyo/securityfs_if.c",
84609 + [8815].name = "tomoyo_write_self",
84610 + [8815].param3 = 1,
84611 + [8821].file = "net/wireless/sme.c",
84612 + [8821].name = "cfg80211_roamed",
84613 + [8821].param5 = 1,
84614 + [8821].param7 = 1,
84615 + [8833].file = "security/selinux/ss/services.c",
84616 + [8833].name = "security_context_to_sid",
84617 + [8833].param2 = 1,
84618 + [8851].file = "net/key/af_key.c",
84619 + [8851].name = "pfkey_sendmsg",
84620 + [8851].param4 = 1,
84621 + [8917].file = "net/ipv4/raw.c",
84622 + [8917].name = "raw_setsockopt",
84623 + [8917].param5 = 1,
84624 + [8983].file = "include/linux/skbuff.h",
84625 + [8983].name = "alloc_skb",
84626 + [8983].param1 = 1,
84627 + [9226].file = "mm/migrate.c",
84628 + [9226].name = "sys_move_pages",
84629 + [9226].param2 = 1,
84630 + [9341].file = "drivers/acpi/apei/erst-dbg.c",
84631 + [9341].name = "erst_dbg_write",
84632 + [9341].param3 = 1,
84633 + [9463].file = "drivers/infiniband/hw/ipath/ipath_verbs.c",
84634 + [9463].name = "ipath_verbs_send",
84635 + [9463].param3 = 1,
84636 + [9463].param5 = 1,
84637 + [9546].file = "drivers/video/fbmem.c",
84638 + [9546].name = "fb_write",
84639 + [9546].param3 = 1,
84640 + [9601].file = "kernel/kfifo.c",
84641 + [9601].name = "__kfifo_from_user",
84642 + [9601].param3 = 1,
84643 + [9618].file = "security/selinux/selinuxfs.c",
84644 + [9618].name = "sel_write_bool",
84645 + [9618].param3 = 1,
84646 + [9768].file = "drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c",
84647 + [9768].name = "vmw_execbuf_process",
84648 + [9768].param5 = 1,
84649 + [9828].file = "drivers/media/dvb/dvb-core/dmxdev.c",
84650 + [9828].name = "dvb_demux_do_ioctl",
84651 + [9828].param3 = 1,
84652 + [9870].file = "net/atm/addr.c",
84653 + [9870].name = "atm_get_addr",
84654 + [9870].param3 = 1,
84655 + [9962].file = "drivers/scsi/sg.c",
84656 + [9962].name = "sg_proc_write_dressz",
84657 + [9962].param3 = 1,
84658 + [9977].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
84659 + [9977].name = "zd_usb_iowrite16v_async",
84660 + [9977].param3 = 1,
84661 + [16344].collision = 1,
84662 + [30494].collision = 1,
84663 + [31291].collision = 1,
84664 + [33040].collision = 1,
84665 + [38314].collision = 1,
84666 + [54338].collision = 1,
84667 + [60651].collision = 1,
84668 +};
84669 diff --git a/tools/gcc/size_overflow_hash2.h b/tools/gcc/size_overflow_hash2.h
84670 new file mode 100644
84671 index 0000000..8ed7d96
84672 --- /dev/null
84673 +++ b/tools/gcc/size_overflow_hash2.h
84674 @@ -0,0 +1,44 @@
84675 +struct size_overflow_hash size_overflow_hash2[65536] = {
84676 + [2118].file = "fs/ntfs/malloc.h",
84677 + [2118].name = "ntfs_malloc_nofs",
84678 + [2118].param1 = 1,
84679 + [22224].file = "fs/proc/vmcore.c",
84680 + [22224].name = "read_from_oldmem",
84681 + [22224].param2 = 1,
84682 + [26518].file = "drivers/gpu/vga/vgaarb.c",
84683 + [26518].name = "vga_arb_read",
84684 + [26518].param3 = 1,
84685 + [26569].file = "lib/kstrtox.c",
84686 + [26569].name = "kstrtoint_from_user",
84687 + [26569].param2 = 1,
84688 + [30632].file = "drivers/ide/ide-proc.c",
84689 + [30632].name = "ide_driver_proc_write",
84690 + [30632].param3 = 1,
84691 + [36150].file = "net/ceph/buffer.c",
84692 + [36150].name = "ceph_buffer_new",
84693 + [36150].param1 = 1,
84694 + [39024].file = "lib/scatterlist.c",
84695 + [39024].name = "sg_kmalloc",
84696 + [39024].param1 = 1,
84697 + [39105].file = "drivers/gpu/drm/ttm/ttm_tt.c",
84698 + [39105].name = "ttm_tt_create",
84699 + [39105].param2 = 1,
84700 + [43208].file = "fs/nfs/read.c",
84701 + [43208].name = "nfs_readdata_alloc",
84702 + [43208].param1 = 1,
84703 + [46911].file = "drivers/media/video/ivtv/ivtv-fileops.c",
84704 + [46911].name = "ivtv_v4l2_read",
84705 + [46911].param3 = 1,
84706 + [50359].file = "kernel/sched.c",
84707 + [50359].name = "alloc_sched_domains",
84708 + [50359].param1 = 1,
84709 + [52857].file = "sound/pci/rme9652/rme9652.c",
84710 + [52857].name = "snd_rme9652_capture_copy",
84711 + [52857].param5 = 1,
84712 + [57500].file = "drivers/spi/spidev.c",
84713 + [57500].name = "spidev_write",
84714 + [57500].param3 = 1,
84715 + [65149].file = "fs/nilfs2/ioctl.c",
84716 + [65149].name = "nilfs_ioctl_wrap_copy",
84717 + [65149].param4 = 1,
84718 +};
84719 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
84720 new file mode 100644
84721 index 0000000..a9ae886
84722 --- /dev/null
84723 +++ b/tools/gcc/size_overflow_plugin.c
84724 @@ -0,0 +1,1042 @@
84725 +/*
84726 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
84727 + * Licensed under the GPL v2, or (at your option) v3
84728 + *
84729 + * Homepage:
84730 + * http://www.grsecurity.net/~ephox/overflow_plugin/
84731 + *
84732 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
84733 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
84734 + * The recomputed argument is checked against INT_MAX and an event is logged on overflow and the triggering process is killed.
84735 + *
84736 + * Usage:
84737 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o size_overflow_plugin.so size_overflow_plugin.c
84738 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
84739 + */
84740 +
84741 +#include "gcc-plugin.h"
84742 +#include "config.h"
84743 +#include "system.h"
84744 +#include "coretypes.h"
84745 +#include "tree.h"
84746 +#include "tree-pass.h"
84747 +#include "intl.h"
84748 +#include "plugin-version.h"
84749 +#include "tm.h"
84750 +#include "toplev.h"
84751 +#include "function.h"
84752 +#include "tree-flow.h"
84753 +#include "plugin.h"
84754 +#include "gimple.h"
84755 +#include "c-common.h"
84756 +#include "diagnostic.h"
84757 +
84758 +struct size_overflow_hash {
84759 + const char *name;
84760 + const char *file;
84761 + unsigned short collision:1;
84762 + unsigned short param1:1;
84763 + unsigned short param2:1;
84764 + unsigned short param3:1;
84765 + unsigned short param4:1;
84766 + unsigned short param5:1;
84767 + unsigned short param6:1;
84768 + unsigned short param7:1;
84769 + unsigned short param8:1;
84770 + unsigned short param9:1;
84771 +};
84772 +
84773 +#include "size_overflow_hash1.h"
84774 +#include "size_overflow_hash2.h"
84775 +
84776 +#define __unused __attribute__((__unused__))
84777 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
84778 +#define BEFORE_STMT true
84779 +#define AFTER_STMT false
84780 +#define CREATE_NEW_VAR NULL_TREE
84781 +
84782 +int plugin_is_GPL_compatible;
84783 +void debug_gimple_stmt (gimple gs);
84784 +
84785 +static tree expand(struct pointer_set_t *visited, tree var);
84786 +static tree signed_size_overflow_type;
84787 +static tree unsigned_size_overflow_type;
84788 +static tree report_size_overflow_decl;
84789 +static tree const_char_ptr_type_node;
84790 +static unsigned int handle_function(void);
84791 +
84792 +static struct plugin_info size_overflow_plugin_info = {
84793 + .version = "20120311beta",
84794 + .help = "no-size_overflow\tturn off size overflow checking\n",
84795 +};
84796 +
84797 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
84798 +{
84799 + unsigned int arg_count = type_num_arguments(*node);
84800 +
84801 + for (; args; args = TREE_CHAIN(args)) {
84802 + tree position = TREE_VALUE(args);
84803 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
84804 + error("handle_size_overflow_attribute: overflow parameter outside range.");
84805 + *no_add_attrs = true;
84806 + }
84807 + }
84808 + return NULL_TREE;
84809 +}
84810 +
84811 +static struct attribute_spec no_size_overflow_attr = {
84812 + .name = "size_overflow",
84813 + .min_length = 1,
84814 + .max_length = -1,
84815 + .decl_required = false,
84816 + .type_required = true,
84817 + .function_type_required = true,
84818 + .handler = handle_size_overflow_attribute
84819 +};
84820 +
84821 +static void register_attributes(void __unused *event_data, void __unused *data)
84822 +{
84823 + register_attribute(&no_size_overflow_attr);
84824 +}
84825 +
84826 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
84827 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
84828 +{
84829 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
84830 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
84831 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
84832 +
84833 + const unsigned int m = 0x57559429;
84834 + const unsigned int n = 0x5052acdb;
84835 + const unsigned int *key4 = (const unsigned int *)key;
84836 + unsigned int h = len;
84837 + unsigned int k = len + seed + n;
84838 + unsigned long long p;
84839 +
84840 + while (len >= 8) {
84841 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
84842 + len -= 8;
84843 + }
84844 + if (len >= 4) {
84845 + cwmixb(key4[0]) key4 += 1;
84846 + len -= 4;
84847 + }
84848 + if (len)
84849 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
84850 + cwmixb(h ^ (k + n));
84851 + return k ^ h;
84852 +
84853 +#undef cwfold
84854 +#undef cwmixa
84855 +#undef cwmixb
84856 +}
84857 +
84858 +static inline unsigned int size_overflow_hash(const char *fndecl, unsigned int seed)
84859 +{
84860 + return CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
84861 +}
84862 +
84863 +static inline tree get_original_function_decl(tree fndecl)
84864 +{
84865 + if (DECL_ABSTRACT_ORIGIN(fndecl))
84866 + return DECL_ABSTRACT_ORIGIN(fndecl);
84867 + return fndecl;
84868 +}
84869 +
84870 +static inline gimple get_def_stmt(tree node)
84871 +{
84872 + gcc_assert(TREE_CODE(node) == SSA_NAME);
84873 + return SSA_NAME_DEF_STMT(node);
84874 +}
84875 +
84876 +static struct size_overflow_hash *get_function_hash(tree fndecl)
84877 +{
84878 + unsigned int hash;
84879 + const char *func = NAME(fndecl);
84880 +
84881 + hash = size_overflow_hash(func, 0);
84882 +
84883 + if (size_overflow_hash1[hash].collision) {
84884 + hash = size_overflow_hash(func, 23432);
84885 + return &size_overflow_hash2[hash];
84886 + }
84887 + return &size_overflow_hash1[hash];
84888 +}
84889 +
84890 +static void check_missing_attribute(tree arg)
84891 +{
84892 + tree var, func = get_original_function_decl(current_function_decl);
84893 + const char *curfunc = NAME(func);
84894 + unsigned int new_hash, argnum = 1;
84895 + struct size_overflow_hash *hash;
84896 + location_t loc;
84897 + expanded_location xloc;
84898 + bool match = false;
84899 +
84900 + loc = DECL_SOURCE_LOCATION(func);
84901 + xloc = expand_location(loc);
84902 +
84903 + if (lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(func))))
84904 + return;
84905 +
84906 + hash = get_function_hash(func);
84907 + if (hash->name && !strcmp(hash->name, NAME(func)) && !strcmp(hash->file, xloc.file))
84908 + return;
84909 +
84910 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
84911 +
84912 + if (TREE_CODE(arg) == SSA_NAME)
84913 + arg = SSA_NAME_VAR(arg);
84914 +
84915 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
84916 + if (strcmp(NAME(arg), NAME(var))) {
84917 + argnum++;
84918 + continue;
84919 + }
84920 + match = true;
84921 + if (!TYPE_UNSIGNED(TREE_TYPE(var)))
84922 + return;
84923 + break;
84924 + }
84925 + if (!match) {
84926 + warning(0, "check_missing_attribute: cannot find the %s argument in %s", NAME(arg), NAME(func));
84927 + return;
84928 + }
84929 +
84930 +#define check_param(num) \
84931 + if (num == argnum && hash->param##num) \
84932 + return;
84933 + check_param(1);
84934 + check_param(2);
84935 + check_param(3);
84936 + check_param(4);
84937 + check_param(5);
84938 + check_param(6);
84939 + check_param(7);
84940 + check_param(8);
84941 + check_param(9);
84942 +#undef check_param
84943 +
84944 + new_hash = size_overflow_hash(curfunc, 0);
84945 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%d+%u+%s", curfunc, curfunc, argnum, new_hash, xloc.file);
84946 +}
84947 +
84948 +static tree create_new_var(tree type)
84949 +{
84950 + tree new_var = create_tmp_var(type, "cicus");
84951 +
84952 + add_referenced_var(new_var);
84953 + mark_sym_for_renaming(new_var);
84954 + return new_var;
84955 +}
84956 +
84957 +static bool is_bool(tree node)
84958 +{
84959 + tree type;
84960 +
84961 + if (node == NULL_TREE)
84962 + return false;
84963 +
84964 + type = TREE_TYPE(node);
84965 + if (!INTEGRAL_TYPE_P(type))
84966 + return false;
84967 + if (TREE_CODE(type) == BOOLEAN_TYPE)
84968 + return true;
84969 + if (TYPE_PRECISION(type) == 1)
84970 + return true;
84971 + return false;
84972 +}
84973 +
84974 +static gimple build_cast_stmt(tree type, tree var, tree new_var, location_t loc)
84975 +{
84976 + gimple assign;
84977 +
84978 + if (new_var == CREATE_NEW_VAR)
84979 + new_var = create_new_var(type);
84980 +
84981 + assign = gimple_build_assign(new_var, fold_convert(type, var));
84982 + gimple_set_location(assign, loc);
84983 + gimple_set_lhs(assign, make_ssa_name(new_var, assign));
84984 +
84985 + return assign;
84986 +}
84987 +
84988 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
84989 +{
84990 + tree oldstmt_rhs1;
84991 + enum tree_code code;
84992 + gimple stmt;
84993 + gimple_stmt_iterator gsi;
84994 +
84995 + if (is_bool(rhs1)) {
84996 + pointer_set_insert(visited, oldstmt);
84997 + return gimple_get_lhs(oldstmt);
84998 + }
84999 +
85000 + if (rhs1 == NULL_TREE) {
85001 + debug_gimple_stmt(oldstmt);
85002 + error("create_assign: rhs1 is NULL_TREE");
85003 + gcc_unreachable();
85004 + }
85005 +
85006 + oldstmt_rhs1 = gimple_assign_rhs1(oldstmt);
85007 + code = TREE_CODE(oldstmt_rhs1);
85008 + if (code == PARM_DECL || (code == SSA_NAME && gimple_code(get_def_stmt(oldstmt_rhs1)) == GIMPLE_NOP))
85009 + check_missing_attribute(oldstmt_rhs1);
85010 +
85011 + stmt = build_cast_stmt(signed_size_overflow_type, rhs1, CREATE_NEW_VAR, gimple_location(oldstmt));
85012 + gsi = gsi_for_stmt(oldstmt);
85013 + if (before)
85014 + gsi_insert_before(&gsi, stmt, GSI_NEW_STMT);
85015 + else
85016 + gsi_insert_after(&gsi, stmt, GSI_NEW_STMT);
85017 + update_stmt(stmt);
85018 + pointer_set_insert(visited, oldstmt);
85019 + return gimple_get_lhs(stmt);
85020 +}
85021 +
85022 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, tree rhs2, tree __unused rhs3)
85023 +{
85024 + tree new_var, lhs = gimple_get_lhs(oldstmt);
85025 + gimple stmt;
85026 + gimple_stmt_iterator gsi;
85027 +
85028 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
85029 + rhs1 = gimple_assign_rhs1(oldstmt);
85030 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
85031 + }
85032 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
85033 + rhs2 = gimple_assign_rhs2(oldstmt);
85034 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
85035 + }
85036 +
85037 + stmt = gimple_copy(oldstmt);
85038 + gimple_set_location(stmt, gimple_location(oldstmt));
85039 +
85040 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
85041 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
85042 +
85043 + if (is_bool(lhs))
85044 + new_var = SSA_NAME_VAR(lhs);
85045 + else
85046 + new_var = create_new_var(signed_size_overflow_type);
85047 + new_var = make_ssa_name(new_var, stmt);
85048 + gimple_set_lhs(stmt, new_var);
85049 +
85050 + if (rhs1 != NULL_TREE) {
85051 + if (!gimple_assign_cast_p(oldstmt))
85052 + rhs1 = fold_convert(signed_size_overflow_type, rhs1);
85053 + gimple_assign_set_rhs1(stmt, rhs1);
85054 + }
85055 +
85056 + if (rhs2 != NULL_TREE)
85057 + gimple_assign_set_rhs2(stmt, rhs2);
85058 +#if BUILDING_GCC_VERSION >= 4007
85059 + if (rhs3 != NULL_TREE)
85060 + gimple_assign_set_rhs3(stmt, rhs3);
85061 +#endif
85062 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
85063 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
85064 +
85065 + gsi = gsi_for_stmt(oldstmt);
85066 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
85067 + update_stmt(stmt);
85068 + pointer_set_insert(visited, oldstmt);
85069 + return gimple_get_lhs(stmt);
85070 +}
85071 +
85072 +static gimple overflow_create_phi_node(gimple oldstmt, tree var)
85073 +{
85074 + basic_block bb;
85075 + gimple phi;
85076 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
85077 +
85078 + bb = gsi_bb(gsi);
85079 + phi = make_phi_node(var, EDGE_COUNT(bb->preds));
85080 +
85081 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
85082 + gimple_set_bb(phi, bb);
85083 + return phi;
85084 +}
85085 +
85086 +static tree signed_cast_constant(tree node)
85087 +{
85088 + gcc_assert(is_gimple_constant(node));
85089 +
85090 + if (TYPE_PRECISION(signed_size_overflow_type) == TYPE_PRECISION(TREE_TYPE(node)))
85091 + return build_int_cst_wide(signed_size_overflow_type, TREE_INT_CST_LOW(node), TREE_INT_CST_HIGH(node));
85092 + else
85093 + return build_int_cst(signed_size_overflow_type, int_cst_value(node));
85094 +}
85095 +
85096 +static gimple cast_old_phi_arg(gimple oldstmt, tree arg, tree new_var)
85097 +{
85098 + basic_block first_bb;
85099 + gimple newstmt;
85100 + gimple_stmt_iterator gsi;
85101 +
85102 + newstmt = build_cast_stmt(signed_size_overflow_type, arg, new_var, gimple_location(oldstmt));
85103 +
85104 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
85105 + if (dom_info_available_p(CDI_DOMINATORS))
85106 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
85107 + gsi = gsi_start_bb(first_bb);
85108 +
85109 + gsi_insert_before(&gsi, newstmt, GSI_NEW_STMT);
85110 + return newstmt;
85111 +}
85112 +
85113 +static gimple handle_new_phi_arg(tree arg, tree new_var, tree new_rhs)
85114 +{
85115 + gimple newstmt;
85116 + gimple_stmt_iterator gsi;
85117 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
85118 + gimple def_newstmt = get_def_stmt(new_rhs);
85119 +
85120 + gsi_insert = gsi_insert_after;
85121 + gsi = gsi_for_stmt(def_newstmt);
85122 +
85123 + switch (gimple_code(get_def_stmt(arg))) {
85124 + case GIMPLE_PHI:
85125 + newstmt = gimple_build_assign(new_var, new_rhs);
85126 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
85127 + gsi_insert = gsi_insert_before;
85128 + break;
85129 + case GIMPLE_ASM:
85130 + case GIMPLE_CALL:
85131 + newstmt = gimple_build_assign(new_var, new_rhs);
85132 + break;
85133 + case GIMPLE_ASSIGN:
85134 + newstmt = gimple_copy(def_newstmt);
85135 + break;
85136 + default:
85137 + /* unknown gimple_code (build_new_phi_arg) */
85138 + gcc_unreachable();
85139 + }
85140 +
85141 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
85142 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
85143 + return newstmt;
85144 +}
85145 +
85146 +static tree build_new_phi_arg(struct pointer_set_t *visited, gimple oldstmt, tree arg, tree new_var)
85147 +{
85148 + gimple newstmt;
85149 + tree new_rhs;
85150 +
85151 + if (is_gimple_constant(arg))
85152 + return signed_cast_constant(arg);
85153 +
85154 + pointer_set_insert(visited, oldstmt);
85155 + new_rhs = expand(visited, arg);
85156 + if (new_rhs == NULL_TREE) {
85157 + gcc_assert(TREE_CODE(TREE_TYPE(arg)) != VOID_TYPE);
85158 + newstmt = cast_old_phi_arg(oldstmt, arg, new_var);
85159 + } else
85160 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
85161 + update_stmt(newstmt);
85162 + return gimple_get_lhs(newstmt);
85163 +}
85164 +
85165 +static tree build_new_phi(struct pointer_set_t *visited, gimple oldstmt)
85166 +{
85167 + gimple phi;
85168 + tree new_var = create_new_var(signed_size_overflow_type);
85169 + unsigned int i, n = gimple_phi_num_args(oldstmt);
85170 +
85171 + phi = overflow_create_phi_node(oldstmt, new_var);
85172 +
85173 + for (i = 0; i < n; i++) {
85174 + tree arg, lhs;
85175 +
85176 + arg = gimple_phi_arg_def(oldstmt, i);
85177 + lhs = build_new_phi_arg(visited, oldstmt, arg, new_var);
85178 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
85179 + }
85180 + update_stmt(phi);
85181 + return gimple_phi_result(phi);
85182 +}
85183 +
85184 +static tree handle_unary_ops(struct pointer_set_t *visited, tree var)
85185 +{
85186 + gimple def_stmt = get_def_stmt(var);
85187 + tree new_rhs1, rhs1 = gimple_assign_rhs1(def_stmt);
85188 +
85189 + if (is_gimple_constant(rhs1))
85190 + return dup_assign(visited, def_stmt, signed_cast_constant(rhs1), NULL_TREE, NULL_TREE);
85191 +
85192 + switch (TREE_CODE(rhs1)) {
85193 + case SSA_NAME:
85194 + new_rhs1 = expand(visited, rhs1);
85195 + break;
85196 + case ARRAY_REF:
85197 + case ADDR_EXPR:
85198 + case COMPONENT_REF:
85199 + case COND_EXPR:
85200 + case INDIRECT_REF:
85201 +#if BUILDING_GCC_VERSION >= 4006
85202 + case MEM_REF:
85203 +#endif
85204 + case PARM_DECL:
85205 + case TARGET_MEM_REF:
85206 + case VAR_DECL:
85207 + return create_assign(visited, def_stmt, var, AFTER_STMT);
85208 + default:
85209 + debug_gimple_stmt(def_stmt);
85210 + debug_tree(rhs1);
85211 + gcc_unreachable();
85212 + }
85213 +
85214 + if (new_rhs1 == NULL_TREE)
85215 + return create_assign(visited, def_stmt, rhs1, AFTER_STMT);
85216 + return dup_assign(visited, def_stmt, new_rhs1, NULL_TREE, NULL_TREE);
85217 +}
85218 +
85219 +static tree transform_mult_overflow(tree rhs, tree const_rhs, tree log2const_rhs, location_t loc)
85220 +{
85221 + tree new_def_rhs;
85222 +
85223 + if (!is_gimple_constant(rhs))
85224 + return NULL_TREE;
85225 +
85226 + new_def_rhs = fold_build2_loc(loc, MULT_EXPR, TREE_TYPE(const_rhs), rhs, const_rhs);
85227 + new_def_rhs = signed_cast_constant(new_def_rhs);
85228 + if (int_cst_value(new_def_rhs) >= 0)
85229 + return NULL_TREE;
85230 + return fold_build2_loc(loc, RSHIFT_EXPR, TREE_TYPE(new_def_rhs), new_def_rhs, log2const_rhs);
85231 +}
85232 +
85233 +static tree handle_intentional_mult_overflow(struct pointer_set_t *visited, tree rhs, tree const_rhs)
85234 +{
85235 + gimple new_def_stmt, def_stmt;
85236 + tree def_rhs1, def_rhs2, new_def_rhs;
85237 + location_t loc;
85238 + tree log2const_rhs;
85239 + int log2 = exact_log2(TREE_INT_CST_LOW(const_rhs));
85240 +
85241 + if (log2 == -1) {
85242 +// warning(0, "Possibly unhandled intentional integer truncation");
85243 + return NULL_TREE;
85244 + }
85245 +
85246 + def_stmt = get_def_stmt(rhs);
85247 + loc = gimple_location(def_stmt);
85248 + def_rhs1 = gimple_assign_rhs1(def_stmt);
85249 + def_rhs2 = gimple_assign_rhs2(def_stmt);
85250 + new_def_stmt = get_def_stmt(expand(visited, rhs));
85251 + log2const_rhs = build_int_cstu(TREE_TYPE(const_rhs), log2);
85252 +
85253 + new_def_rhs = transform_mult_overflow(def_rhs1, const_rhs, log2const_rhs, loc);
85254 + if (new_def_rhs != NULL_TREE) {
85255 + gimple_assign_set_rhs1(new_def_stmt, new_def_rhs);
85256 + } else {
85257 + new_def_rhs = transform_mult_overflow(def_rhs2, const_rhs, log2const_rhs, loc);
85258 + if (new_def_rhs != NULL_TREE)
85259 + gimple_assign_set_rhs2(new_def_stmt, new_def_rhs);
85260 + }
85261 + if (new_def_rhs == NULL_TREE)
85262 + return NULL_TREE;
85263 +
85264 + update_stmt(new_def_stmt);
85265 +// warning(0, "Handle integer truncation (gcc optimization)");
85266 + return gimple_get_lhs(new_def_stmt);
85267 +}
85268 +
85269 +static bool is_mult_overflow(gimple def_stmt, tree rhs1)
85270 +{
85271 + gimple rhs1_def_stmt = get_def_stmt(rhs1);
85272 +
85273 + if (gimple_assign_rhs_code(def_stmt) != MULT_EXPR)
85274 + return false;
85275 + if (gimple_code(rhs1_def_stmt) != GIMPLE_ASSIGN)
85276 + return false;
85277 + if (gimple_assign_rhs_code(rhs1_def_stmt) != PLUS_EXPR)
85278 + return false;
85279 + return true;
85280 +}
85281 +
85282 +static tree handle_intentional_overflow(struct pointer_set_t *visited, gimple def_stmt, tree rhs1, tree rhs2)
85283 +{
85284 + if (is_mult_overflow(def_stmt, rhs1))
85285 + return handle_intentional_mult_overflow(visited, rhs1, rhs2);
85286 + return NULL_TREE;
85287 +}
85288 +
85289 +static tree handle_binary_ops(struct pointer_set_t *visited, tree var)
85290 +{
85291 + tree rhs1, rhs2;
85292 + gimple def_stmt = get_def_stmt(var);
85293 + tree new_rhs1 = NULL_TREE;
85294 + tree new_rhs2 = NULL_TREE;
85295 +
85296 + rhs1 = gimple_assign_rhs1(def_stmt);
85297 + rhs2 = gimple_assign_rhs2(def_stmt);
85298 +
85299 + /* no DImode/TImode division in the 32/64 bit kernel */
85300 + switch (gimple_assign_rhs_code(def_stmt)) {
85301 + case RDIV_EXPR:
85302 + case TRUNC_DIV_EXPR:
85303 + case CEIL_DIV_EXPR:
85304 + case FLOOR_DIV_EXPR:
85305 + case ROUND_DIV_EXPR:
85306 + case TRUNC_MOD_EXPR:
85307 + case CEIL_MOD_EXPR:
85308 + case FLOOR_MOD_EXPR:
85309 + case ROUND_MOD_EXPR:
85310 + case EXACT_DIV_EXPR:
85311 + case POINTER_PLUS_EXPR:
85312 + /* logical AND cannot cause an overflow */
85313 + case BIT_AND_EXPR:
85314 + return create_assign(visited, def_stmt, var, AFTER_STMT);
85315 + default:
85316 + break;
85317 + }
85318 +
85319 + if (is_gimple_constant(rhs2)) {
85320 + new_rhs2 = signed_cast_constant(rhs2);
85321 + new_rhs1 = handle_intentional_overflow(visited, def_stmt, rhs1, rhs2);
85322 + }
85323 +
85324 + if (is_gimple_constant(rhs1)) {
85325 + new_rhs1 = signed_cast_constant(rhs1);
85326 + new_rhs2 = handle_intentional_overflow(visited, def_stmt, rhs2, rhs1);
85327 + }
85328 +
85329 + if (new_rhs1 == NULL_TREE && TREE_CODE(rhs1) == SSA_NAME)
85330 + new_rhs1 = expand(visited, rhs1);
85331 + if (new_rhs2 == NULL_TREE && TREE_CODE(rhs2) == SSA_NAME)
85332 + new_rhs2 = expand(visited, rhs2);
85333 +
85334 + return dup_assign(visited, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
85335 +}
85336 +
85337 +#if BUILDING_GCC_VERSION >= 4007
85338 +static tree get_new_rhs(struct pointer_set_t *visited, tree rhs)
85339 +{
85340 + if (is_gimple_constant(rhs))
85341 + return signed_cast_constant(rhs);
85342 + if (TREE_CODE(rhs) != SSA_NAME)
85343 + return NULL_TREE;
85344 + return expand(visited, rhs);
85345 +}
85346 +
85347 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree var)
85348 +{
85349 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3;
85350 + gimple def_stmt = get_def_stmt(var);
85351 +
85352 + rhs1 = gimple_assign_rhs1(def_stmt);
85353 + rhs2 = gimple_assign_rhs2(def_stmt);
85354 + rhs3 = gimple_assign_rhs3(def_stmt);
85355 + new_rhs1 = get_new_rhs(visited, rhs1);
85356 + new_rhs2 = get_new_rhs(visited, rhs2);
85357 + new_rhs3 = get_new_rhs(visited, rhs3);
85358 +
85359 + if (new_rhs1 == NULL_TREE && new_rhs2 != NULL_TREE && new_rhs3 != NULL_TREE)
85360 + return dup_assign(visited, def_stmt, new_rhs1, new_rhs2, new_rhs3);
85361 + error("handle_ternary_ops: unknown rhs");
85362 + gcc_unreachable();
85363 +}
85364 +#endif
85365 +
85366 +static void set_size_overflow_type(tree node)
85367 +{
85368 + switch (TYPE_MODE(TREE_TYPE(node))) {
85369 + case SImode:
85370 + signed_size_overflow_type = intDI_type_node;
85371 + unsigned_size_overflow_type = unsigned_intDI_type_node;
85372 + break;
85373 + case DImode:
85374 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode)) {
85375 + signed_size_overflow_type = intDI_type_node;
85376 + unsigned_size_overflow_type = unsigned_intDI_type_node;
85377 + } else {
85378 + signed_size_overflow_type = intTI_type_node;
85379 + unsigned_size_overflow_type = unsigned_intTI_type_node;
85380 + }
85381 + break;
85382 + default:
85383 + error("set_size_overflow_type: unsupported gcc configuration.");
85384 + gcc_unreachable();
85385 + }
85386 +}
85387 +
85388 +static tree expand_visited(gimple def_stmt)
85389 +{
85390 + gimple tmp;
85391 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
85392 +
85393 + gsi_next(&gsi);
85394 + tmp = gsi_stmt(gsi);
85395 + switch (gimple_code(tmp)) {
85396 + case GIMPLE_ASSIGN:
85397 + return gimple_get_lhs(tmp);
85398 + case GIMPLE_PHI:
85399 + return gimple_phi_result(tmp);
85400 + case GIMPLE_CALL:
85401 + return gimple_call_lhs(tmp);
85402 + default:
85403 + return NULL_TREE;
85404 + }
85405 +}
85406 +
85407 +static tree expand(struct pointer_set_t *visited, tree var)
85408 +{
85409 + gimple def_stmt;
85410 +
85411 + if (is_gimple_constant(var))
85412 + return NULL_TREE;
85413 +
85414 + if (TREE_CODE(var) == ADDR_EXPR)
85415 + return NULL_TREE;
85416 +
85417 + if (SSA_NAME_IS_DEFAULT_DEF(var))
85418 + return NULL_TREE;
85419 +
85420 + def_stmt = get_def_stmt(var);
85421 +
85422 + if (!def_stmt)
85423 + return NULL_TREE;
85424 +
85425 + if (pointer_set_contains(visited, def_stmt))
85426 + return expand_visited(def_stmt);
85427 +
85428 + switch (gimple_code(def_stmt)) {
85429 + case GIMPLE_NOP:
85430 + check_missing_attribute(var);
85431 + return NULL_TREE;
85432 + case GIMPLE_PHI:
85433 + return build_new_phi(visited, def_stmt);
85434 + case GIMPLE_CALL:
85435 + case GIMPLE_ASM:
85436 + gcc_assert(TREE_CODE(TREE_TYPE(var)) != VOID_TYPE);
85437 + return create_assign(visited, def_stmt, var, AFTER_STMT);
85438 + case GIMPLE_ASSIGN:
85439 + switch (gimple_num_ops(def_stmt)) {
85440 + case 2:
85441 + return handle_unary_ops(visited, var);
85442 + case 3:
85443 + return handle_binary_ops(visited, var);
85444 +#if BUILDING_GCC_VERSION >= 4007
85445 + case 4:
85446 + return handle_ternary_ops(visited, var);
85447 +#endif
85448 + }
85449 + default:
85450 + debug_gimple_stmt(def_stmt);
85451 + error("expand: unknown gimple code");
85452 + gcc_unreachable();
85453 + }
85454 +}
85455 +
85456 +static void change_function_arg(gimple func_stmt, tree origarg, unsigned int argnum, tree newarg)
85457 +{
85458 + gimple assign, stmt;
85459 + gimple_stmt_iterator gsi = gsi_for_stmt(func_stmt);
85460 + tree origtype = TREE_TYPE(origarg);
85461 +
85462 + stmt = gsi_stmt(gsi);
85463 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
85464 +
85465 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, gimple_location(stmt));
85466 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
85467 + update_stmt(assign);
85468 +
85469 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
85470 + update_stmt(stmt);
85471 +}
85472 +
85473 +static tree get_function_arg(unsigned int argnum, gimple stmt, tree fndecl)
85474 +{
85475 + const char *origid;
85476 + tree arg, origarg;
85477 +
85478 + if (!DECL_ABSTRACT_ORIGIN(fndecl)) {
85479 + gcc_assert(gimple_call_num_args(stmt) > argnum);
85480 + return gimple_call_arg(stmt, argnum);
85481 + }
85482 +
85483 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
85484 + while (origarg && argnum) {
85485 + argnum--;
85486 + origarg = TREE_CHAIN(origarg);
85487 + }
85488 +
85489 + gcc_assert(argnum == 0);
85490 +
85491 + gcc_assert(origarg != NULL_TREE);
85492 + origid = NAME(origarg);
85493 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
85494 + if (!strcmp(origid, NAME(arg)))
85495 + return arg;
85496 + }
85497 + return NULL_TREE;
85498 +}
85499 +
85500 +static void insert_cond(tree arg, basic_block cond_bb)
85501 +{
85502 + gimple cond_stmt;
85503 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
85504 +
85505 + cond_stmt = gimple_build_cond(GT_EXPR, arg, build_int_cstu(signed_size_overflow_type, 0x7fffffff), NULL_TREE, NULL_TREE);
85506 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
85507 + update_stmt(cond_stmt);
85508 +}
85509 +
85510 +static tree create_string_param(tree string)
85511 +{
85512 + tree array_ref = build4(ARRAY_REF, TREE_TYPE(string), string, integer_zero_node, NULL, NULL);
85513 +
85514 + return build1(ADDR_EXPR, ptr_type_node, array_ref);
85515 +}
85516 +
85517 +static void insert_cond_result(basic_block bb_true, gimple stmt, tree arg)
85518 +{
85519 + gimple func_stmt, def_stmt;
85520 + tree current_func, loc_file, loc_line;
85521 + expanded_location xloc;
85522 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
85523 +
85524 + def_stmt = get_def_stmt(arg);
85525 + xloc = expand_location(gimple_location(def_stmt));
85526 +
85527 + if (!gimple_has_location(def_stmt)) {
85528 + xloc = expand_location(gimple_location(stmt));
85529 + gcc_assert(gimple_has_location(stmt));
85530 + }
85531 +
85532 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
85533 +
85534 + loc_file = build_string(strlen(xloc.file), xloc.file);
85535 + TREE_TYPE(loc_file) = char_array_type_node;
85536 + loc_file = create_string_param(loc_file);
85537 +
85538 + current_func = build_string(IDENTIFIER_LENGTH(DECL_NAME(current_function_decl)), NAME(current_function_decl));
85539 + TREE_TYPE(current_func) = char_array_type_node;
85540 + current_func = create_string_param(current_func);
85541 +
85542 + // void report_size_overflow(const char *file, unsigned int line, const char *func)
85543 + func_stmt = gimple_build_call(report_size_overflow_decl, 3, loc_file, loc_line, current_func);
85544 +
85545 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
85546 +}
85547 +
85548 +static void insert_check_size_overflow(gimple stmt, tree arg)
85549 +{
85550 + basic_block cond_bb, join_bb, bb_true;
85551 + edge e;
85552 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85553 +
85554 + cond_bb = gimple_bb(stmt);
85555 + gsi_prev(&gsi);
85556 + if (gsi_end_p(gsi))
85557 + e = split_block_after_labels(cond_bb);
85558 + else
85559 + e = split_block(cond_bb, gsi_stmt(gsi));
85560 + cond_bb = e->src;
85561 + join_bb = e->dest;
85562 + e->flags = EDGE_FALSE_VALUE;
85563 + e->probability = REG_BR_PROB_BASE;
85564 +
85565 + bb_true = create_empty_bb(cond_bb);
85566 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
85567 +
85568 + if (dom_info_available_p(CDI_DOMINATORS)) {
85569 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
85570 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
85571 + }
85572 +
85573 + insert_cond(arg, cond_bb);
85574 + insert_cond_result(bb_true, stmt, arg);
85575 +}
85576 +
85577 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
85578 +{
85579 + struct pointer_set_t *visited;
85580 + tree arg, newarg;
85581 + gimple ucast_stmt;
85582 + gimple_stmt_iterator gsi;
85583 + location_t loc = gimple_location(stmt);
85584 +
85585 + arg = get_function_arg(argnum, stmt, fndecl);
85586 + if (arg == NULL_TREE)
85587 + return;
85588 +
85589 + if (is_gimple_constant(arg))
85590 + return;
85591 + if (TREE_CODE(arg) != SSA_NAME)
85592 + return;
85593 +
85594 + set_size_overflow_type(arg);
85595 + visited = pointer_set_create();
85596 + newarg = expand(visited, arg);
85597 + pointer_set_destroy(visited);
85598 +
85599 + if (newarg == NULL_TREE)
85600 + return;
85601 +
85602 + change_function_arg(stmt, arg, argnum, newarg);
85603 +
85604 + ucast_stmt = build_cast_stmt(unsigned_size_overflow_type, newarg, CREATE_NEW_VAR, loc);
85605 + gsi = gsi_for_stmt(stmt);
85606 + gsi_insert_before(&gsi, ucast_stmt, GSI_SAME_STMT);
85607 +
85608 + insert_check_size_overflow(stmt, gimple_get_lhs(ucast_stmt));
85609 +// inform(loc, "Integer size_overflow check applied here.");
85610 +}
85611 +
85612 +static void handle_function_by_attribute(gimple stmt, tree attr, tree fndecl)
85613 +{
85614 + tree p = TREE_VALUE(attr);
85615 + do {
85616 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
85617 + p = TREE_CHAIN(p);
85618 + } while (p);
85619 +}
85620 +
85621 +static void handle_function_by_hash(gimple stmt, tree fndecl)
85622 +{
85623 + struct size_overflow_hash *hash;
85624 + expanded_location xloc;
85625 +
85626 + hash = get_function_hash(fndecl);
85627 + xloc = expand_location(DECL_SOURCE_LOCATION(fndecl));
85628 +
85629 + fndecl = get_original_function_decl(fndecl);
85630 + if (!hash->name || !hash->file)
85631 + return;
85632 + if (strcmp(hash->name, NAME(fndecl)) || strcmp(hash->file, xloc.file))
85633 + return;
85634 +
85635 +#define search_param(argnum) \
85636 + if (hash->param##argnum) \
85637 + handle_function_arg(stmt, fndecl, argnum - 1);
85638 +
85639 + search_param(1);
85640 + search_param(2);
85641 + search_param(3);
85642 + search_param(4);
85643 + search_param(5);
85644 + search_param(6);
85645 + search_param(7);
85646 + search_param(8);
85647 + search_param(9);
85648 +#undef search_param
85649 +}
85650 +
85651 +static unsigned int handle_function(void)
85652 +{
85653 + basic_block bb = ENTRY_BLOCK_PTR->next_bb;
85654 + int saved_last_basic_block = last_basic_block;
85655 +
85656 + do {
85657 + gimple_stmt_iterator gsi;
85658 + basic_block next = bb->next_bb;
85659 +
85660 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85661 + tree fndecl, attr;
85662 + gimple stmt = gsi_stmt(gsi);
85663 +
85664 + if (!(is_gimple_call(stmt)))
85665 + continue;
85666 + fndecl = gimple_call_fndecl(stmt);
85667 + if (fndecl == NULL_TREE)
85668 + continue;
85669 + if (gimple_call_num_args(stmt) == 0)
85670 + continue;
85671 + attr = lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(fndecl)));
85672 + if (!attr || !TREE_VALUE(attr))
85673 + handle_function_by_hash(stmt, fndecl);
85674 + else
85675 + handle_function_by_attribute(stmt, attr, fndecl);
85676 + gsi = gsi_for_stmt(stmt);
85677 + }
85678 + bb = next;
85679 + } while (bb && bb->index <= saved_last_basic_block);
85680 + return 0;
85681 +}
85682 +
85683 +static struct gimple_opt_pass size_overflow_pass = {
85684 + .pass = {
85685 + .type = GIMPLE_PASS,
85686 + .name = "size_overflow",
85687 + .gate = NULL,
85688 + .execute = handle_function,
85689 + .sub = NULL,
85690 + .next = NULL,
85691 + .static_pass_number = 0,
85692 + .tv_id = TV_NONE,
85693 + .properties_required = PROP_cfg | PROP_referenced_vars,
85694 + .properties_provided = 0,
85695 + .properties_destroyed = 0,
85696 + .todo_flags_start = 0,
85697 + .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
85698 + }
85699 +};
85700 +
85701 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
85702 +{
85703 + tree fntype;
85704 +
85705 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
85706 +
85707 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func)
85708 + fntype = build_function_type_list(void_type_node,
85709 + const_char_ptr_type_node,
85710 + unsigned_type_node,
85711 + const_char_ptr_type_node,
85712 + NULL_TREE);
85713 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
85714 +
85715 + TREE_PUBLIC(report_size_overflow_decl) = 1;
85716 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
85717 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
85718 +}
85719 +
85720 +extern struct gimple_opt_pass pass_dce;
85721 +
85722 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85723 +{
85724 + int i;
85725 + const char * const plugin_name = plugin_info->base_name;
85726 + const int argc = plugin_info->argc;
85727 + const struct plugin_argument * const argv = plugin_info->argv;
85728 + bool enable = true;
85729 +
85730 + struct register_pass_info size_overflow_pass_info = {
85731 + .pass = &size_overflow_pass.pass,
85732 + .reference_pass_name = "mudflap2",
85733 + .ref_pass_instance_number = 1,
85734 + .pos_op = PASS_POS_INSERT_BEFORE
85735 + };
85736 +
85737 + struct register_pass_info dce_pass_info = {
85738 + .pass = &pass_dce.pass,
85739 + .reference_pass_name = "mudflap2",
85740 + .ref_pass_instance_number = 1,
85741 + .pos_op = PASS_POS_INSERT_BEFORE
85742 + };
85743 +
85744 + if (!plugin_default_version_check(version, &gcc_version)) {
85745 + error(G_("incompatible gcc/plugin versions"));
85746 + return 1;
85747 + }
85748 +
85749 + for (i = 0; i < argc; ++i) {
85750 + if (!(strcmp(argv[i].key, "no-size_overflow"))) {
85751 + enable = false;
85752 + continue;
85753 + }
85754 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85755 + }
85756 +
85757 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
85758 + if (enable) {
85759 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
85760 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
85761 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
85762 + }
85763 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
85764 +
85765 + return 0;
85766 +}
85767 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
85768 new file mode 100644
85769 index 0000000..b87ec9d
85770 --- /dev/null
85771 +++ b/tools/gcc/stackleak_plugin.c
85772 @@ -0,0 +1,313 @@
85773 +/*
85774 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
85775 + * Licensed under the GPL v2
85776 + *
85777 + * Note: the choice of the license means that the compilation process is
85778 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85779 + * but for the kernel it doesn't matter since it doesn't link against
85780 + * any of the gcc libraries
85781 + *
85782 + * gcc plugin to help implement various PaX features
85783 + *
85784 + * - track lowest stack pointer
85785 + *
85786 + * TODO:
85787 + * - initialize all local variables
85788 + *
85789 + * BUGS:
85790 + * - none known
85791 + */
85792 +#include "gcc-plugin.h"
85793 +#include "config.h"
85794 +#include "system.h"
85795 +#include "coretypes.h"
85796 +#include "tree.h"
85797 +#include "tree-pass.h"
85798 +#include "flags.h"
85799 +#include "intl.h"
85800 +#include "toplev.h"
85801 +#include "plugin.h"
85802 +//#include "expr.h" where are you...
85803 +#include "diagnostic.h"
85804 +#include "plugin-version.h"
85805 +#include "tm.h"
85806 +#include "function.h"
85807 +#include "basic-block.h"
85808 +#include "gimple.h"
85809 +#include "rtl.h"
85810 +#include "emit-rtl.h"
85811 +
85812 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85813 +
85814 +int plugin_is_GPL_compatible;
85815 +
85816 +static int track_frame_size = -1;
85817 +static const char track_function[] = "pax_track_stack";
85818 +static const char check_function[] = "pax_check_alloca";
85819 +static bool init_locals;
85820 +
85821 +static struct plugin_info stackleak_plugin_info = {
85822 + .version = "201203140940",
85823 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
85824 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
85825 +};
85826 +
85827 +static bool gate_stackleak_track_stack(void);
85828 +static unsigned int execute_stackleak_tree_instrument(void);
85829 +static unsigned int execute_stackleak_final(void);
85830 +
85831 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
85832 + .pass = {
85833 + .type = GIMPLE_PASS,
85834 + .name = "stackleak_tree_instrument",
85835 + .gate = gate_stackleak_track_stack,
85836 + .execute = execute_stackleak_tree_instrument,
85837 + .sub = NULL,
85838 + .next = NULL,
85839 + .static_pass_number = 0,
85840 + .tv_id = TV_NONE,
85841 + .properties_required = PROP_gimple_leh | PROP_cfg,
85842 + .properties_provided = 0,
85843 + .properties_destroyed = 0,
85844 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
85845 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
85846 + }
85847 +};
85848 +
85849 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
85850 + .pass = {
85851 + .type = RTL_PASS,
85852 + .name = "stackleak_final",
85853 + .gate = gate_stackleak_track_stack,
85854 + .execute = execute_stackleak_final,
85855 + .sub = NULL,
85856 + .next = NULL,
85857 + .static_pass_number = 0,
85858 + .tv_id = TV_NONE,
85859 + .properties_required = 0,
85860 + .properties_provided = 0,
85861 + .properties_destroyed = 0,
85862 + .todo_flags_start = 0,
85863 + .todo_flags_finish = TODO_dump_func
85864 + }
85865 +};
85866 +
85867 +static bool gate_stackleak_track_stack(void)
85868 +{
85869 + return track_frame_size >= 0;
85870 +}
85871 +
85872 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
85873 +{
85874 + gimple check_alloca;
85875 + tree fntype, fndecl, alloca_size;
85876 +
85877 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
85878 + fndecl = build_fn_decl(check_function, fntype);
85879 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
85880 +
85881 + // insert call to void pax_check_alloca(unsigned long size)
85882 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
85883 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
85884 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
85885 +}
85886 +
85887 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
85888 +{
85889 + gimple track_stack;
85890 + tree fntype, fndecl;
85891 +
85892 + fntype = build_function_type_list(void_type_node, NULL_TREE);
85893 + fndecl = build_fn_decl(track_function, fntype);
85894 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
85895 +
85896 + // insert call to void pax_track_stack(void)
85897 + track_stack = gimple_build_call(fndecl, 0);
85898 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
85899 +}
85900 +
85901 +#if BUILDING_GCC_VERSION == 4005
85902 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
85903 +{
85904 + tree fndecl;
85905 +
85906 + if (!is_gimple_call(stmt))
85907 + return false;
85908 + fndecl = gimple_call_fndecl(stmt);
85909 + if (!fndecl)
85910 + return false;
85911 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
85912 + return false;
85913 +// print_node(stderr, "pax", fndecl, 4);
85914 + return DECL_FUNCTION_CODE(fndecl) == code;
85915 +}
85916 +#endif
85917 +
85918 +static bool is_alloca(gimple stmt)
85919 +{
85920 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
85921 + return true;
85922 +
85923 +#if BUILDING_GCC_VERSION >= 4007
85924 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
85925 + return true;
85926 +#endif
85927 +
85928 + return false;
85929 +}
85930 +
85931 +static unsigned int execute_stackleak_tree_instrument(void)
85932 +{
85933 + basic_block bb, entry_bb;
85934 + bool prologue_instrumented = false, is_leaf = true;
85935 +
85936 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
85937 +
85938 + // 1. loop through BBs and GIMPLE statements
85939 + FOR_EACH_BB(bb) {
85940 + gimple_stmt_iterator gsi;
85941 +
85942 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85943 + gimple stmt;
85944 +
85945 + stmt = gsi_stmt(gsi);
85946 +
85947 + if (is_gimple_call(stmt))
85948 + is_leaf = false;
85949 +
85950 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
85951 + if (!is_alloca(stmt))
85952 + continue;
85953 +
85954 + // 2. insert stack overflow check before each __builtin_alloca call
85955 + stackleak_check_alloca(&gsi);
85956 +
85957 + // 3. insert track call after each __builtin_alloca call
85958 + stackleak_add_instrumentation(&gsi);
85959 + if (bb == entry_bb)
85960 + prologue_instrumented = true;
85961 + }
85962 + }
85963 +
85964 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
85965 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
85966 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
85967 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
85968 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
85969 + return 0;
85970 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
85971 + return 0;
85972 +
85973 + // 4. insert track call at the beginning
85974 + if (!prologue_instrumented) {
85975 + gimple_stmt_iterator gsi;
85976 +
85977 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
85978 + if (dom_info_available_p(CDI_DOMINATORS))
85979 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
85980 + gsi = gsi_start_bb(bb);
85981 + stackleak_add_instrumentation(&gsi);
85982 + }
85983 +
85984 + return 0;
85985 +}
85986 +
85987 +static unsigned int execute_stackleak_final(void)
85988 +{
85989 + rtx insn;
85990 +
85991 + if (cfun->calls_alloca)
85992 + return 0;
85993 +
85994 + // keep calls only if function frame is big enough
85995 + if (get_frame_size() >= track_frame_size)
85996 + return 0;
85997 +
85998 + // 1. find pax_track_stack calls
85999 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
86000 + // 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))
86001 + rtx body;
86002 +
86003 + if (!CALL_P(insn))
86004 + continue;
86005 + body = PATTERN(insn);
86006 + if (GET_CODE(body) != CALL)
86007 + continue;
86008 + body = XEXP(body, 0);
86009 + if (GET_CODE(body) != MEM)
86010 + continue;
86011 + body = XEXP(body, 0);
86012 + if (GET_CODE(body) != SYMBOL_REF)
86013 + continue;
86014 + if (strcmp(XSTR(body, 0), track_function))
86015 + continue;
86016 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
86017 + // 2. delete call
86018 + insn = delete_insn_and_edges(insn);
86019 +#if BUILDING_GCC_VERSION >= 4007
86020 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
86021 + insn = delete_insn_and_edges(insn);
86022 +#endif
86023 + }
86024 +
86025 +// print_simple_rtl(stderr, get_insns());
86026 +// print_rtl(stderr, get_insns());
86027 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
86028 +
86029 + return 0;
86030 +}
86031 +
86032 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86033 +{
86034 + const char * const plugin_name = plugin_info->base_name;
86035 + const int argc = plugin_info->argc;
86036 + const struct plugin_argument * const argv = plugin_info->argv;
86037 + int i;
86038 + struct register_pass_info stackleak_tree_instrument_pass_info = {
86039 + .pass = &stackleak_tree_instrument_pass.pass,
86040 +// .reference_pass_name = "tree_profile",
86041 + .reference_pass_name = "optimized",
86042 + .ref_pass_instance_number = 0,
86043 + .pos_op = PASS_POS_INSERT_BEFORE
86044 + };
86045 + struct register_pass_info stackleak_final_pass_info = {
86046 + .pass = &stackleak_final_rtl_opt_pass.pass,
86047 + .reference_pass_name = "final",
86048 + .ref_pass_instance_number = 0,
86049 + .pos_op = PASS_POS_INSERT_BEFORE
86050 + };
86051 +
86052 + if (!plugin_default_version_check(version, &gcc_version)) {
86053 + error(G_("incompatible gcc/plugin versions"));
86054 + return 1;
86055 + }
86056 +
86057 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
86058 +
86059 + for (i = 0; i < argc; ++i) {
86060 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
86061 + if (!argv[i].value) {
86062 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86063 + continue;
86064 + }
86065 + track_frame_size = atoi(argv[i].value);
86066 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
86067 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
86068 + continue;
86069 + }
86070 + if (!strcmp(argv[i].key, "initialize-locals")) {
86071 + if (argv[i].value) {
86072 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
86073 + continue;
86074 + }
86075 + init_locals = true;
86076 + continue;
86077 + }
86078 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86079 + }
86080 +
86081 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
86082 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
86083 +
86084 + return 0;
86085 +}
86086 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
86087 index 6789d78..4afd019 100644
86088 --- a/tools/perf/util/include/asm/alternative-asm.h
86089 +++ b/tools/perf/util/include/asm/alternative-asm.h
86090 @@ -5,4 +5,7 @@
86091
86092 #define altinstruction_entry #
86093
86094 + .macro pax_force_retaddr rip=0, reload=0
86095 + .endm
86096 +
86097 #endif
86098 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
86099 index af0f22f..9a7d479 100644
86100 --- a/usr/gen_init_cpio.c
86101 +++ b/usr/gen_init_cpio.c
86102 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
86103 int retval;
86104 int rc = -1;
86105 int namesize;
86106 - int i;
86107 + unsigned int i;
86108
86109 mode |= S_IFREG;
86110
86111 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
86112 *env_var = *expanded = '\0';
86113 strncat(env_var, start + 2, end - start - 2);
86114 strncat(expanded, new_location, start - new_location);
86115 - strncat(expanded, getenv(env_var), PATH_MAX);
86116 - strncat(expanded, end + 1, PATH_MAX);
86117 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
86118 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
86119 strncpy(new_location, expanded, PATH_MAX);
86120 + new_location[PATH_MAX] = 0;
86121 } else
86122 break;
86123 }
86124 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
86125 index d9cfb78..4f27c10 100644
86126 --- a/virt/kvm/kvm_main.c
86127 +++ b/virt/kvm/kvm_main.c
86128 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
86129
86130 static cpumask_var_t cpus_hardware_enabled;
86131 static int kvm_usage_count = 0;
86132 -static atomic_t hardware_enable_failed;
86133 +static atomic_unchecked_t hardware_enable_failed;
86134
86135 struct kmem_cache *kvm_vcpu_cache;
86136 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
86137 @@ -2268,7 +2268,7 @@ static void hardware_enable_nolock(void *junk)
86138
86139 if (r) {
86140 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
86141 - atomic_inc(&hardware_enable_failed);
86142 + atomic_inc_unchecked(&hardware_enable_failed);
86143 printk(KERN_INFO "kvm: enabling virtualization on "
86144 "CPU%d failed\n", cpu);
86145 }
86146 @@ -2322,10 +2322,10 @@ static int hardware_enable_all(void)
86147
86148 kvm_usage_count++;
86149 if (kvm_usage_count == 1) {
86150 - atomic_set(&hardware_enable_failed, 0);
86151 + atomic_set_unchecked(&hardware_enable_failed, 0);
86152 on_each_cpu(hardware_enable_nolock, NULL, 1);
86153
86154 - if (atomic_read(&hardware_enable_failed)) {
86155 + if (atomic_read_unchecked(&hardware_enable_failed)) {
86156 hardware_disable_all_nolock();
86157 r = -EBUSY;
86158 }
86159 @@ -2676,7 +2676,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
86160 kvm_arch_vcpu_put(vcpu);
86161 }
86162
86163 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86164 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86165 struct module *module)
86166 {
86167 int r;
86168 @@ -2739,7 +2739,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86169 if (!vcpu_align)
86170 vcpu_align = __alignof__(struct kvm_vcpu);
86171 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
86172 - 0, NULL);
86173 + SLAB_USERCOPY, NULL);
86174 if (!kvm_vcpu_cache) {
86175 r = -ENOMEM;
86176 goto out_free_3;
86177 @@ -2749,9 +2749,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86178 if (r)
86179 goto out_free;
86180
86181 - kvm_chardev_ops.owner = module;
86182 - kvm_vm_fops.owner = module;
86183 - kvm_vcpu_fops.owner = module;
86184 + pax_open_kernel();
86185 + *(void **)&kvm_chardev_ops.owner = module;
86186 + *(void **)&kvm_vm_fops.owner = module;
86187 + *(void **)&kvm_vcpu_fops.owner = module;
86188 + pax_close_kernel();
86189
86190 r = misc_register(&kvm_dev);
86191 if (r) {