]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9-3.2.9-201203112136.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9-3.2.9-201203112136.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index dfa6fc6..0aa3907 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -5,6 +5,7 @@
6 *.cis
7 *.cpio
8 *.csp
9 +*.dbg
10 *.dsp
11 *.dvi
12 *.elf
13 @@ -14,6 +15,7 @@
14 *.gcov
15 *.gen.S
16 *.gif
17 +*.gmo
18 *.grep
19 *.grp
20 *.gz
21 @@ -48,9 +50,11 @@
22 *.tab.h
23 *.tex
24 *.ver
25 +*.vim
26 *.xml
27 *.xz
28 *_MODULES
29 +*_reg_safe.h
30 *_vga16.c
31 *~
32 \#*#
33 @@ -70,6 +74,7 @@ Kerntypes
34 Module.markers
35 Module.symvers
36 PENDING
37 +PERF*
38 SCCS
39 System.map*
40 TAGS
41 @@ -93,19 +98,24 @@ bounds.h
42 bsetup
43 btfixupprep
44 build
45 +builtin-policy.h
46 bvmlinux
47 bzImage*
48 capability_names.h
49 capflags.c
50 classlist.h*
51 +clut_vga16.c
52 +common-cmds.h
53 comp*.log
54 compile.h*
55 conf
56 config
57 config-*
58 config_data.h*
59 +config.c
60 config.mak
61 config.mak.autogen
62 +config.tmp
63 conmakehash
64 consolemap_deftbl.c*
65 cpustr.h
66 @@ -119,6 +129,7 @@ dslm
67 elf2ecoff
68 elfconfig.h*
69 evergreen_reg_safe.h
70 +exception_policy.conf
71 fixdep
72 flask.h
73 fore200e_mkfirm
74 @@ -126,12 +137,15 @@ fore200e_pca_fw.c*
75 gconf
76 gconf.glade.h
77 gen-devlist
78 +gen-kdb_cmds.c
79 gen_crc32table
80 gen_init_cpio
81 generated
82 genheaders
83 genksyms
84 *_gray256.c
85 +hash
86 +hid-example
87 hpet_example
88 hugepage-mmap
89 hugepage-shm
90 @@ -146,7 +160,7 @@ int32.c
91 int4.c
92 int8.c
93 kallsyms
94 -kconfig
95 +kern_constants.h
96 keywords.c
97 ksym.c*
98 ksym.h*
99 @@ -154,7 +168,7 @@ kxgettext
100 lkc_defs.h
101 lex.c
102 lex.*.c
103 -linux
104 +lib1funcs.S
105 logo_*.c
106 logo_*_clut224.c
107 logo_*_mono.c
108 @@ -166,14 +180,15 @@ machtypes.h
109 map
110 map_hugetlb
111 maui_boot.h
112 -media
113 mconf
114 +mdp
115 miboot*
116 mk_elfconfig
117 mkboot
118 mkbugboot
119 mkcpustr
120 mkdep
121 +mkpiggy
122 mkprep
123 mkregtable
124 mktables
125 @@ -209,6 +224,7 @@ r300_reg_safe.h
126 r420_reg_safe.h
127 r600_reg_safe.h
128 recordmcount
129 +regdb.c
130 relocs
131 rlim_names.h
132 rn50_reg_safe.h
133 @@ -219,6 +235,7 @@ setup
134 setup.bin
135 setup.elf
136 sImage
137 +slabinfo
138 sm_tbl*
139 split-include
140 syscalltab.h
141 @@ -229,6 +246,7 @@ tftpboot.img
142 timeconst.h
143 times.h*
144 trix_boot.h
145 +user_constants.h
146 utsrelease.h*
147 vdso-syms.lds
148 vdso.lds
149 @@ -246,7 +264,9 @@ vmlinux
150 vmlinux-*
151 vmlinux.aout
152 vmlinux.bin.all
153 +vmlinux.bin.bz2
154 vmlinux.lds
155 +vmlinux.relocs
156 vmlinuz
157 voffset.h
158 vsyscall.lds
159 @@ -254,9 +274,11 @@ vsyscall_32.lds
160 wanxlfw.inc
161 uImage
162 unifdef
163 +utsrelease.h
164 wakeup.bin
165 wakeup.elf
166 wakeup.lds
167 zImage*
168 zconf.hash.c
169 +zconf.lex.c
170 zoffset.h
171 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
172 index 81c287f..d456d02 100644
173 --- a/Documentation/kernel-parameters.txt
174 +++ b/Documentation/kernel-parameters.txt
175 @@ -1935,6 +1935,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
176 the specified number of seconds. This is to be used if
177 your oopses keep scrolling off the screen.
178
179 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
180 + virtualization environments that don't cope well with the
181 + expand down segment used by UDEREF on X86-32 or the frequent
182 + page table updates on X86-64.
183 +
184 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
185 +
186 pcbit= [HW,ISDN]
187
188 pcd. [PARIDE]
189 diff --git a/Makefile b/Makefile
190 index 5f1739b..abd56ea 100644
191 --- a/Makefile
192 +++ b/Makefile
193 @@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
194
195 HOSTCC = gcc
196 HOSTCXX = g++
197 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
198 -HOSTCXXFLAGS = -O2
199 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
200 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
201 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
202
203 # Decide whether to build built-in, modular, or both.
204 # Normally, just do built-in.
205 @@ -407,8 +408,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
206 # Rules shared between *config targets and build targets
207
208 # Basic helpers built in scripts/
209 -PHONY += scripts_basic
210 -scripts_basic:
211 +PHONY += scripts_basic gcc-plugins
212 +scripts_basic: gcc-plugins
213 $(Q)$(MAKE) $(build)=scripts/basic
214 $(Q)rm -f .tmp_quiet_recordmcount
215
216 @@ -564,6 +565,50 @@ else
217 KBUILD_CFLAGS += -O2
218 endif
219
220 +ifndef DISABLE_PAX_PLUGINS
221 +ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(CC)"), y)
222 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
223 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
224 +endif
225 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
226 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
227 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
228 +endif
229 +ifdef CONFIG_KALLOCSTAT_PLUGIN
230 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
231 +endif
232 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
233 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
234 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
235 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
236 +endif
237 +ifdef CONFIG_CHECKER_PLUGIN
238 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
239 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
240 +endif
241 +endif
242 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
243 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
244 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
245 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
246 +export CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN
247 +ifeq ($(KBUILD_EXTMOD),)
248 +gcc-plugins:
249 + $(Q)$(MAKE) $(build)=tools/gcc
250 +else
251 +gcc-plugins: ;
252 +endif
253 +else
254 +gcc-plugins:
255 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
256 + $(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.))
257 +else
258 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
259 +endif
260 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
261 +endif
262 +endif
263 +
264 include $(srctree)/arch/$(SRCARCH)/Makefile
265
266 ifneq ($(CONFIG_FRAME_WARN),0)
267 @@ -708,7 +753,7 @@ export mod_strip_cmd
268
269
270 ifeq ($(KBUILD_EXTMOD),)
271 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
272 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
273
274 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
275 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
276 @@ -932,6 +977,8 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
277
278 # The actual objects are generated when descending,
279 # make sure no implicit rule kicks in
280 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
281 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
282 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
283
284 # Handle descending into subdirectories listed in $(vmlinux-dirs)
285 @@ -941,7 +988,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
286 # Error messages still appears in the original language
287
288 PHONY += $(vmlinux-dirs)
289 -$(vmlinux-dirs): prepare scripts
290 +$(vmlinux-dirs): gcc-plugins prepare scripts
291 $(Q)$(MAKE) $(build)=$@
292
293 # Store (new) KERNELRELASE string in include/config/kernel.release
294 @@ -985,6 +1032,7 @@ prepare0: archprepare FORCE
295 $(Q)$(MAKE) $(build)=.
296
297 # All the preparing..
298 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
299 prepare: prepare0
300
301 # Generate some files
302 @@ -1086,6 +1134,8 @@ all: modules
303 # using awk while concatenating to the final file.
304
305 PHONY += modules
306 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
307 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
308 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
309 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
310 @$(kecho) ' Building modules, stage 2.';
311 @@ -1101,7 +1151,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
312
313 # Target to prepare building external modules
314 PHONY += modules_prepare
315 -modules_prepare: prepare scripts
316 +modules_prepare: gcc-plugins prepare scripts
317
318 # Target to install modules
319 PHONY += modules_install
320 @@ -1198,6 +1248,7 @@ distclean: mrproper
321 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
322 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
323 -o -name '.*.rej' \
324 + -o -name '.*.rej' -o -name '*.so' \
325 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
326 -type f -print | xargs rm -f
327
328 @@ -1358,6 +1409,8 @@ PHONY += $(module-dirs) modules
329 $(module-dirs): crmodverdir $(objtree)/Module.symvers
330 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
331
332 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
333 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
334 modules: $(module-dirs)
335 @$(kecho) ' Building modules, stage 2.';
336 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
337 @@ -1484,17 +1537,21 @@ else
338 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
339 endif
340
341 -%.s: %.c prepare scripts FORCE
342 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
343 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
344 +%.s: %.c gcc-plugins prepare scripts FORCE
345 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
346 %.i: %.c prepare scripts FORCE
347 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
348 -%.o: %.c prepare scripts FORCE
349 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
350 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
351 +%.o: %.c gcc-plugins prepare scripts FORCE
352 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
353 %.lst: %.c prepare scripts FORCE
354 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
355 -%.s: %.S prepare scripts FORCE
356 +%.s: %.S gcc-plugins prepare scripts FORCE
357 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
358 -%.o: %.S prepare scripts FORCE
359 +%.o: %.S gcc-plugins prepare scripts FORCE
360 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
361 %.symtypes: %.c prepare scripts FORCE
362 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
363 @@ -1504,11 +1561,15 @@ endif
364 $(cmd_crmodverdir)
365 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
366 $(build)=$(build-dir)
367 -%/: prepare scripts FORCE
368 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
369 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
370 +%/: gcc-plugins prepare scripts FORCE
371 $(cmd_crmodverdir)
372 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
373 $(build)=$(build-dir)
374 -%.ko: prepare scripts FORCE
375 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
376 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
377 +%.ko: gcc-plugins prepare scripts FORCE
378 $(cmd_crmodverdir)
379 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
380 $(build)=$(build-dir) $(@:.ko=.o)
381 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
382 index 640f909..48b6597 100644
383 --- a/arch/alpha/include/asm/atomic.h
384 +++ b/arch/alpha/include/asm/atomic.h
385 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
386 #define atomic_dec(v) atomic_sub(1,(v))
387 #define atomic64_dec(v) atomic64_sub(1,(v))
388
389 +#define atomic64_read_unchecked(v) atomic64_read(v)
390 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
391 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
392 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
393 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
394 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
395 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
396 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
397 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
398 +
399 #define smp_mb__before_atomic_dec() smp_mb()
400 #define smp_mb__after_atomic_dec() smp_mb()
401 #define smp_mb__before_atomic_inc() smp_mb()
402 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
403 index ad368a9..fbe0f25 100644
404 --- a/arch/alpha/include/asm/cache.h
405 +++ b/arch/alpha/include/asm/cache.h
406 @@ -4,19 +4,19 @@
407 #ifndef __ARCH_ALPHA_CACHE_H
408 #define __ARCH_ALPHA_CACHE_H
409
410 +#include <linux/const.h>
411
412 /* Bytes per L1 (data) cache line. */
413 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
414 -# define L1_CACHE_BYTES 64
415 # define L1_CACHE_SHIFT 6
416 #else
417 /* Both EV4 and EV5 are write-through, read-allocate,
418 direct-mapped, physical.
419 */
420 -# define L1_CACHE_BYTES 32
421 # define L1_CACHE_SHIFT 5
422 #endif
423
424 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
425 #define SMP_CACHE_BYTES L1_CACHE_BYTES
426
427 #endif
428 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
429 index da5449e..7418343 100644
430 --- a/arch/alpha/include/asm/elf.h
431 +++ b/arch/alpha/include/asm/elf.h
432 @@ -90,6 +90,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
433
434 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
435
436 +#ifdef CONFIG_PAX_ASLR
437 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
438 +
439 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
440 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
441 +#endif
442 +
443 /* $0 is set by ld.so to a pointer to a function which might be
444 registered using atexit. This provides a mean for the dynamic
445 linker to call DT_FINI functions for shared libraries that have
446 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
447 index de98a73..bd4f1f8 100644
448 --- a/arch/alpha/include/asm/pgtable.h
449 +++ b/arch/alpha/include/asm/pgtable.h
450 @@ -101,6 +101,17 @@ struct vm_area_struct;
451 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
452 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
453 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
454 +
455 +#ifdef CONFIG_PAX_PAGEEXEC
456 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
457 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
458 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
459 +#else
460 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
461 +# define PAGE_COPY_NOEXEC PAGE_COPY
462 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
463 +#endif
464 +
465 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
466
467 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
468 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
469 index 2fd00b7..cfd5069 100644
470 --- a/arch/alpha/kernel/module.c
471 +++ b/arch/alpha/kernel/module.c
472 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
473
474 /* The small sections were sorted to the end of the segment.
475 The following should definitely cover them. */
476 - gp = (u64)me->module_core + me->core_size - 0x8000;
477 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
478 got = sechdrs[me->arch.gotsecindex].sh_addr;
479
480 for (i = 0; i < n; i++) {
481 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
482 index 01e8715..be0e80f 100644
483 --- a/arch/alpha/kernel/osf_sys.c
484 +++ b/arch/alpha/kernel/osf_sys.c
485 @@ -1147,7 +1147,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
486 /* At this point: (!vma || addr < vma->vm_end). */
487 if (limit - len < addr)
488 return -ENOMEM;
489 - if (!vma || addr + len <= vma->vm_start)
490 + if (check_heap_stack_gap(vma, addr, len))
491 return addr;
492 addr = vma->vm_end;
493 vma = vma->vm_next;
494 @@ -1183,6 +1183,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
495 merely specific addresses, but regions of memory -- perhaps
496 this feature should be incorporated into all ports? */
497
498 +#ifdef CONFIG_PAX_RANDMMAP
499 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
500 +#endif
501 +
502 if (addr) {
503 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
504 if (addr != (unsigned long) -ENOMEM)
505 @@ -1190,8 +1194,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
506 }
507
508 /* Next, try allocating at TASK_UNMAPPED_BASE. */
509 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
510 - len, limit);
511 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
512 +
513 if (addr != (unsigned long) -ENOMEM)
514 return addr;
515
516 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
517 index fadd5f8..904e73a 100644
518 --- a/arch/alpha/mm/fault.c
519 +++ b/arch/alpha/mm/fault.c
520 @@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
521 __reload_thread(pcb);
522 }
523
524 +#ifdef CONFIG_PAX_PAGEEXEC
525 +/*
526 + * PaX: decide what to do with offenders (regs->pc = fault address)
527 + *
528 + * returns 1 when task should be killed
529 + * 2 when patched PLT trampoline was detected
530 + * 3 when unpatched PLT trampoline was detected
531 + */
532 +static int pax_handle_fetch_fault(struct pt_regs *regs)
533 +{
534 +
535 +#ifdef CONFIG_PAX_EMUPLT
536 + int err;
537 +
538 + do { /* PaX: patched PLT emulation #1 */
539 + unsigned int ldah, ldq, jmp;
540 +
541 + err = get_user(ldah, (unsigned int *)regs->pc);
542 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
543 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
544 +
545 + if (err)
546 + break;
547 +
548 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
549 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
550 + jmp == 0x6BFB0000U)
551 + {
552 + unsigned long r27, addr;
553 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
554 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
555 +
556 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
557 + err = get_user(r27, (unsigned long *)addr);
558 + if (err)
559 + break;
560 +
561 + regs->r27 = r27;
562 + regs->pc = r27;
563 + return 2;
564 + }
565 + } while (0);
566 +
567 + do { /* PaX: patched PLT emulation #2 */
568 + unsigned int ldah, lda, br;
569 +
570 + err = get_user(ldah, (unsigned int *)regs->pc);
571 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
572 + err |= get_user(br, (unsigned int *)(regs->pc+8));
573 +
574 + if (err)
575 + break;
576 +
577 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
578 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
579 + (br & 0xFFE00000U) == 0xC3E00000U)
580 + {
581 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
582 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
583 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
584 +
585 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
586 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
587 + return 2;
588 + }
589 + } while (0);
590 +
591 + do { /* PaX: unpatched PLT emulation */
592 + unsigned int br;
593 +
594 + err = get_user(br, (unsigned int *)regs->pc);
595 +
596 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
597 + unsigned int br2, ldq, nop, jmp;
598 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
599 +
600 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
601 + err = get_user(br2, (unsigned int *)addr);
602 + err |= get_user(ldq, (unsigned int *)(addr+4));
603 + err |= get_user(nop, (unsigned int *)(addr+8));
604 + err |= get_user(jmp, (unsigned int *)(addr+12));
605 + err |= get_user(resolver, (unsigned long *)(addr+16));
606 +
607 + if (err)
608 + break;
609 +
610 + if (br2 == 0xC3600000U &&
611 + ldq == 0xA77B000CU &&
612 + nop == 0x47FF041FU &&
613 + jmp == 0x6B7B0000U)
614 + {
615 + regs->r28 = regs->pc+4;
616 + regs->r27 = addr+16;
617 + regs->pc = resolver;
618 + return 3;
619 + }
620 + }
621 + } while (0);
622 +#endif
623 +
624 + return 1;
625 +}
626 +
627 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
628 +{
629 + unsigned long i;
630 +
631 + printk(KERN_ERR "PAX: bytes at PC: ");
632 + for (i = 0; i < 5; i++) {
633 + unsigned int c;
634 + if (get_user(c, (unsigned int *)pc+i))
635 + printk(KERN_CONT "???????? ");
636 + else
637 + printk(KERN_CONT "%08x ", c);
638 + }
639 + printk("\n");
640 +}
641 +#endif
642
643 /*
644 * This routine handles page faults. It determines the address,
645 @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
646 good_area:
647 si_code = SEGV_ACCERR;
648 if (cause < 0) {
649 - if (!(vma->vm_flags & VM_EXEC))
650 + if (!(vma->vm_flags & VM_EXEC)) {
651 +
652 +#ifdef CONFIG_PAX_PAGEEXEC
653 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
654 + goto bad_area;
655 +
656 + up_read(&mm->mmap_sem);
657 + switch (pax_handle_fetch_fault(regs)) {
658 +
659 +#ifdef CONFIG_PAX_EMUPLT
660 + case 2:
661 + case 3:
662 + return;
663 +#endif
664 +
665 + }
666 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
667 + do_group_exit(SIGKILL);
668 +#else
669 goto bad_area;
670 +#endif
671 +
672 + }
673 } else if (!cause) {
674 /* Allow reads even for write-only mappings */
675 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
676 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
677 index 86976d0..35bff41 100644
678 --- a/arch/arm/include/asm/atomic.h
679 +++ b/arch/arm/include/asm/atomic.h
680 @@ -15,6 +15,10 @@
681 #include <linux/types.h>
682 #include <asm/system.h>
683
684 +#ifdef CONFIG_GENERIC_ATOMIC64
685 +#include <asm-generic/atomic64.h>
686 +#endif
687 +
688 #define ATOMIC_INIT(i) { (i) }
689
690 #ifdef __KERNEL__
691 @@ -27,6 +31,9 @@
692 #define atomic_read(v) (*(volatile int *)&(v)->counter)
693 #define atomic_set(v,i) (((v)->counter) = (i))
694
695 +#define atomic_read_unchecked(v) (*(volatile int *)&(v)->counter)
696 +#define atomic_set_unchecked(v,i) (((v)->counter) = (i))
697 +
698 #if __LINUX_ARM_ARCH__ >= 6
699
700 /*
701 @@ -42,6 +49,28 @@ static inline void atomic_add(int i, atomic_t *v)
702 __asm__ __volatile__("@ atomic_add\n"
703 "1: ldrex %0, [%3]\n"
704 " add %0, %0, %4\n"
705 +
706 +#ifdef CONFIG_PAX_REFCOUNT
707 + "bvc 2f\n"
708 + "\tbkpt 0xf103\n2:\n"
709 +#endif
710 +
711 +" strex %1, %0, [%3]\n"
712 +" teq %1, #0\n"
713 +" bne 1b"
714 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
715 + : "r" (&v->counter), "Ir" (i)
716 + : "cc");
717 +}
718 +
719 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
720 +{
721 + unsigned long tmp;
722 + int result;
723 +
724 + __asm__ __volatile__("@ atomic_add_unchecked\n"
725 +"1: ldrex %0, [%3]\n"
726 +" add %0, %0, %4\n"
727 " strex %1, %0, [%3]\n"
728 " teq %1, #0\n"
729 " bne 1b"
730 @@ -60,6 +89,34 @@ static inline int atomic_add_return(int i, atomic_t *v)
731 __asm__ __volatile__("@ atomic_add_return\n"
732 "1: ldrex %0, [%3]\n"
733 " add %0, %0, %4\n"
734 +
735 +#ifdef CONFIG_PAX_REFCOUNT
736 + "bvc 2f\n"
737 + "\tbkpt 0xf103\n2:\n"
738 +#endif
739 +
740 +" strex %1, %0, [%3]\n"
741 +" teq %1, #0\n"
742 +" bne 1b"
743 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
744 + : "r" (&v->counter), "Ir" (i)
745 + : "cc");
746 +
747 + smp_mb();
748 +
749 + return result;
750 +}
751 +
752 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
753 +{
754 + unsigned long tmp;
755 + int result;
756 +
757 + smp_mb();
758 +
759 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
760 +"1: ldrex %0, [%3]\n"
761 +" add %0, %0, %4\n"
762 " strex %1, %0, [%3]\n"
763 " teq %1, #0\n"
764 " bne 1b"
765 @@ -80,6 +137,28 @@ static inline void atomic_sub(int i, atomic_t *v)
766 __asm__ __volatile__("@ atomic_sub\n"
767 "1: ldrex %0, [%3]\n"
768 " sub %0, %0, %4\n"
769 +
770 +#ifdef CONFIG_PAX_REFCOUNT
771 + "bvc 2f\n"
772 + "\tbkpt 0xf103\n2:\n"
773 +#endif
774 +
775 +" strex %1, %0, [%3]\n"
776 +" teq %1, #0\n"
777 +" bne 1b"
778 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
779 + : "r" (&v->counter), "Ir" (i)
780 + : "cc");
781 +}
782 +
783 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
784 +{
785 + unsigned long tmp;
786 + int result;
787 +
788 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
789 +"1: ldrex %0, [%3]\n"
790 +" sub %0, %0, %4\n"
791 " strex %1, %0, [%3]\n"
792 " teq %1, #0\n"
793 " bne 1b"
794 @@ -132,6 +211,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
795 return oldval;
796 }
797
798 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
799 +{
800 + unsigned long oldval, res;
801 +
802 + smp_mb();
803 +
804 + do {
805 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
806 + "ldrex %1, [%3]\n"
807 + "mov %0, #0\n"
808 + "teq %1, %4\n"
809 + "strexeq %0, %5, [%3]\n"
810 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
811 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
812 + : "cc");
813 + } while (res);
814 +
815 + smp_mb();
816 +
817 + return oldval;
818 +}
819 +
820 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
821 {
822 unsigned long tmp, tmp2;
823 @@ -207,6 +308,7 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
824 #endif /* __LINUX_ARM_ARCH__ */
825
826 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
827 +#define atomic_xchg_unchecked(v, new) (xchg_unchecked(&((v)->counter), new))
828
829 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
830 {
831 @@ -219,11 +321,15 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
832 }
833
834 #define atomic_inc(v) atomic_add(1, v)
835 +#define atomic_inc_unchecked(v) atomic_add_unchecked(1, v)
836 #define atomic_dec(v) atomic_sub(1, v)
837 +#define atomic_dec_unchecked(v) atomic_sub_unchecked(1, v)
838
839 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
840 +#define atomic_inc_and_test_unchecked(v) (atomic_add_return_unchecked(1, v) == 0)
841 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
842 #define atomic_inc_return(v) (atomic_add_return(1, v))
843 +#define atomic_inc_return_unchecked(v) (atomic_add_return_unchecked(1, v))
844 #define atomic_dec_return(v) (atomic_sub_return(1, v))
845 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
846
847 @@ -239,6 +345,14 @@ typedef struct {
848 u64 __aligned(8) counter;
849 } atomic64_t;
850
851 +#ifdef CONFIG_PAX_REFCOUNT
852 +typedef struct {
853 + u64 __aligned(8) counter;
854 +} atomic64_unchecked_t;
855 +#else
856 +typedef atomic64_t atomic64_unchecked_t;
857 +#endif
858 +
859 #define ATOMIC64_INIT(i) { (i) }
860
861 static inline u64 atomic64_read(atomic64_t *v)
862 @@ -254,6 +368,19 @@ static inline u64 atomic64_read(atomic64_t *v)
863 return result;
864 }
865
866 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
867 +{
868 + u64 result;
869 +
870 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
871 +" ldrexd %0, %H0, [%1]"
872 + : "=&r" (result)
873 + : "r" (&v->counter), "Qo" (v->counter)
874 + );
875 +
876 + return result;
877 +}
878 +
879 static inline void atomic64_set(atomic64_t *v, u64 i)
880 {
881 u64 tmp;
882 @@ -268,6 +395,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
883 : "cc");
884 }
885
886 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
887 +{
888 + u64 tmp;
889 +
890 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
891 +"1: ldrexd %0, %H0, [%2]\n"
892 +" strexd %0, %3, %H3, [%2]\n"
893 +" teq %0, #0\n"
894 +" bne 1b"
895 + : "=&r" (tmp), "=Qo" (v->counter)
896 + : "r" (&v->counter), "r" (i)
897 + : "cc");
898 +}
899 +
900 static inline void atomic64_add(u64 i, atomic64_t *v)
901 {
902 u64 result;
903 @@ -277,6 +418,29 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
904 "1: ldrexd %0, %H0, [%3]\n"
905 " adds %0, %0, %4\n"
906 " adc %H0, %H0, %H4\n"
907 +
908 +#ifdef CONFIG_PAX_REFCOUNT
909 + "bvc 2f\n"
910 + "\tbkpt 0xf103\n2:\n"
911 +#endif
912 +
913 +" strexd %1, %0, %H0, [%3]\n"
914 +" teq %1, #0\n"
915 +" bne 1b"
916 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
917 + : "r" (&v->counter), "r" (i)
918 + : "cc");
919 +}
920 +
921 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
922 +{
923 + u64 result;
924 + unsigned long tmp;
925 +
926 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
927 +"1: ldrexd %0, %H0, [%3]\n"
928 +" adds %0, %0, %4\n"
929 +" adc %H0, %H0, %H4\n"
930 " strexd %1, %0, %H0, [%3]\n"
931 " teq %1, #0\n"
932 " bne 1b"
933 @@ -296,6 +460,35 @@ static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
934 "1: ldrexd %0, %H0, [%3]\n"
935 " adds %0, %0, %4\n"
936 " adc %H0, %H0, %H4\n"
937 +
938 +#ifdef CONFIG_PAX_REFCOUNT
939 + "bvc 2f\n"
940 + "\tbkpt 0xf103\n2:\n"
941 +#endif
942 +
943 +" strexd %1, %0, %H0, [%3]\n"
944 +" teq %1, #0\n"
945 +" bne 1b"
946 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
947 + : "r" (&v->counter), "r" (i)
948 + : "cc");
949 +
950 + smp_mb();
951 +
952 + return result;
953 +}
954 +
955 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
956 +{
957 + u64 result;
958 + unsigned long tmp;
959 +
960 + smp_mb();
961 +
962 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
963 +"1: ldrexd %0, %H0, [%3]\n"
964 +" adds %0, %0, %4\n"
965 +" adc %H0, %H0, %H4\n"
966 " strexd %1, %0, %H0, [%3]\n"
967 " teq %1, #0\n"
968 " bne 1b"
969 @@ -317,6 +510,29 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
970 "1: ldrexd %0, %H0, [%3]\n"
971 " subs %0, %0, %4\n"
972 " sbc %H0, %H0, %H4\n"
973 +
974 +#ifdef CONFIG_PAX_REFCOUNT
975 + "bvc 2f\n"
976 + "\tbkpt 0xf103\n2:\n"
977 +#endif
978 +
979 +" strexd %1, %0, %H0, [%3]\n"
980 +" teq %1, #0\n"
981 +" bne 1b"
982 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
983 + : "r" (&v->counter), "r" (i)
984 + : "cc");
985 +}
986 +
987 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
988 +{
989 + u64 result;
990 + unsigned long tmp;
991 +
992 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
993 +"1: ldrexd %0, %H0, [%3]\n"
994 +" subs %0, %0, %4\n"
995 +" sbc %H0, %H0, %H4\n"
996 " strexd %1, %0, %H0, [%3]\n"
997 " teq %1, #0\n"
998 " bne 1b"
999 @@ -372,6 +588,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1000 return oldval;
1001 }
1002
1003 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1004 +{
1005 + u64 oldval;
1006 + unsigned long res;
1007 +
1008 + smp_mb();
1009 +
1010 + do {
1011 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1012 + "ldrexd %1, %H1, [%3]\n"
1013 + "mov %0, #0\n"
1014 + "teq %1, %4\n"
1015 + "teqeq %H1, %H4\n"
1016 + "strexdeq %0, %5, %H5, [%3]"
1017 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1018 + : "r" (&ptr->counter), "r" (old), "r" (new)
1019 + : "cc");
1020 + } while (res);
1021 +
1022 + smp_mb();
1023 +
1024 + return oldval;
1025 +}
1026 +
1027 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1028 {
1029 u64 result;
1030 @@ -451,10 +691,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1031
1032 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1033 #define atomic64_inc(v) atomic64_add(1LL, (v))
1034 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1035 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1036 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1037 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1038 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1039 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1040 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1041 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1042 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1043 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1044 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1045 index 75fe66b..2255c86 100644
1046 --- a/arch/arm/include/asm/cache.h
1047 +++ b/arch/arm/include/asm/cache.h
1048 @@ -4,8 +4,10 @@
1049 #ifndef __ASMARM_CACHE_H
1050 #define __ASMARM_CACHE_H
1051
1052 +#include <linux/const.h>
1053 +
1054 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1055 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1056 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1057
1058 /*
1059 * Memory returned by kmalloc() may be used for DMA, so we must make
1060 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1061 index d5d8d5c..ad92c96 100644
1062 --- a/arch/arm/include/asm/cacheflush.h
1063 +++ b/arch/arm/include/asm/cacheflush.h
1064 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1065 void (*dma_unmap_area)(const void *, size_t, int);
1066
1067 void (*dma_flush_range)(const void *, const void *);
1068 -};
1069 +} __no_const;
1070
1071 /*
1072 * Select the calling method
1073 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1074 index 0e9ce8d..6ef1e03 100644
1075 --- a/arch/arm/include/asm/elf.h
1076 +++ b/arch/arm/include/asm/elf.h
1077 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1078 the loader. We need to make sure that it is out of the way of the program
1079 that it will "exec", and that there is sufficient room for the brk. */
1080
1081 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1082 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1083 +
1084 +#ifdef CONFIG_PAX_ASLR
1085 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1086 +
1087 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1088 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1089 +#endif
1090
1091 /* When the program starts, a1 contains a pointer to a function to be
1092 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1093 @@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1094 extern void elf_set_personality(const struct elf32_hdr *);
1095 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1096
1097 -struct mm_struct;
1098 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1099 -#define arch_randomize_brk arch_randomize_brk
1100 -
1101 extern int vectors_user_mapping(void);
1102 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
1103 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
1104 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1105 index e51b1e8..32a3113 100644
1106 --- a/arch/arm/include/asm/kmap_types.h
1107 +++ b/arch/arm/include/asm/kmap_types.h
1108 @@ -21,6 +21,7 @@ enum km_type {
1109 KM_L1_CACHE,
1110 KM_L2_CACHE,
1111 KM_KDB,
1112 + KM_CLEARPAGE,
1113 KM_TYPE_NR
1114 };
1115
1116 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1117 index 53426c6..c7baff3 100644
1118 --- a/arch/arm/include/asm/outercache.h
1119 +++ b/arch/arm/include/asm/outercache.h
1120 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1121 #endif
1122 void (*set_debug)(unsigned long);
1123 void (*resume)(void);
1124 -};
1125 +} __no_const;
1126
1127 #ifdef CONFIG_OUTER_CACHE
1128
1129 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1130 index ca94653..6ac0d56 100644
1131 --- a/arch/arm/include/asm/page.h
1132 +++ b/arch/arm/include/asm/page.h
1133 @@ -123,7 +123,7 @@ struct cpu_user_fns {
1134 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1135 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1136 unsigned long vaddr, struct vm_area_struct *vma);
1137 -};
1138 +} __no_const;
1139
1140 #ifdef MULTI_USER
1141 extern struct cpu_user_fns cpu_user;
1142 diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h
1143 index 984014b..92345b9 100644
1144 --- a/arch/arm/include/asm/system.h
1145 +++ b/arch/arm/include/asm/system.h
1146 @@ -90,6 +90,8 @@ void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int,
1147
1148 #define xchg(ptr,x) \
1149 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1150 +#define xchg_unchecked(ptr,x) \
1151 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1152
1153 extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
1154
1155 @@ -101,7 +103,7 @@ extern int __pure cpu_architecture(void);
1156 extern void cpu_init(void);
1157
1158 void arm_machine_restart(char mode, const char *cmd);
1159 -extern void (*arm_pm_restart)(char str, const char *cmd);
1160 +extern void (*arm_pm_restart)(char str, const char *cmd) __noreturn;
1161
1162 #define UDBG_UNDEFINED (1 << 0)
1163 #define UDBG_SYSCALL (1 << 1)
1164 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1165 index b293616..96310e5 100644
1166 --- a/arch/arm/include/asm/uaccess.h
1167 +++ b/arch/arm/include/asm/uaccess.h
1168 @@ -22,6 +22,8 @@
1169 #define VERIFY_READ 0
1170 #define VERIFY_WRITE 1
1171
1172 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1173 +
1174 /*
1175 * The exception table consists of pairs of addresses: the first is the
1176 * address of an instruction that is allowed to fault, and the second is
1177 @@ -387,8 +389,23 @@ do { \
1178
1179
1180 #ifdef CONFIG_MMU
1181 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1182 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1183 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1184 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1185 +
1186 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1187 +{
1188 + if (!__builtin_constant_p(n))
1189 + check_object_size(to, n, false);
1190 + return ___copy_from_user(to, from, n);
1191 +}
1192 +
1193 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1194 +{
1195 + if (!__builtin_constant_p(n))
1196 + check_object_size(from, n, true);
1197 + return ___copy_to_user(to, from, n);
1198 +}
1199 +
1200 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1201 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1202 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1203 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1204
1205 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1206 {
1207 + if ((long)n < 0)
1208 + return n;
1209 +
1210 if (access_ok(VERIFY_READ, from, n))
1211 n = __copy_from_user(to, from, n);
1212 else /* security hole - plug it */
1213 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1214
1215 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1216 {
1217 + if ((long)n < 0)
1218 + return n;
1219 +
1220 if (access_ok(VERIFY_WRITE, to, n))
1221 n = __copy_to_user(to, from, n);
1222 return n;
1223 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1224 index 5b0bce6..becd81c 100644
1225 --- a/arch/arm/kernel/armksyms.c
1226 +++ b/arch/arm/kernel/armksyms.c
1227 @@ -95,8 +95,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1228 #ifdef CONFIG_MMU
1229 EXPORT_SYMBOL(copy_page);
1230
1231 -EXPORT_SYMBOL(__copy_from_user);
1232 -EXPORT_SYMBOL(__copy_to_user);
1233 +EXPORT_SYMBOL(___copy_from_user);
1234 +EXPORT_SYMBOL(___copy_to_user);
1235 EXPORT_SYMBOL(__clear_user);
1236
1237 EXPORT_SYMBOL(__get_user_1);
1238 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1239 index 3d0c6fb..9d326fa 100644
1240 --- a/arch/arm/kernel/process.c
1241 +++ b/arch/arm/kernel/process.c
1242 @@ -28,7 +28,6 @@
1243 #include <linux/tick.h>
1244 #include <linux/utsname.h>
1245 #include <linux/uaccess.h>
1246 -#include <linux/random.h>
1247 #include <linux/hw_breakpoint.h>
1248 #include <linux/cpuidle.h>
1249
1250 @@ -92,7 +91,7 @@ static int __init hlt_setup(char *__unused)
1251 __setup("nohlt", nohlt_setup);
1252 __setup("hlt", hlt_setup);
1253
1254 -void arm_machine_restart(char mode, const char *cmd)
1255 +__noreturn void arm_machine_restart(char mode, const char *cmd)
1256 {
1257 /* Disable interrupts first */
1258 local_irq_disable();
1259 @@ -134,7 +133,7 @@ void arm_machine_restart(char mode, const char *cmd)
1260 void (*pm_power_off)(void);
1261 EXPORT_SYMBOL(pm_power_off);
1262
1263 -void (*arm_pm_restart)(char str, const char *cmd) = arm_machine_restart;
1264 +void (*arm_pm_restart)(char str, const char *cmd) __noreturn = arm_machine_restart;
1265 EXPORT_SYMBOL_GPL(arm_pm_restart);
1266
1267 static void do_nothing(void *unused)
1268 @@ -248,6 +247,7 @@ void machine_power_off(void)
1269 machine_shutdown();
1270 if (pm_power_off)
1271 pm_power_off();
1272 + BUG();
1273 }
1274
1275 void machine_restart(char *cmd)
1276 @@ -484,12 +484,6 @@ unsigned long get_wchan(struct task_struct *p)
1277 return 0;
1278 }
1279
1280 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1281 -{
1282 - unsigned long range_end = mm->brk + 0x02000000;
1283 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1284 -}
1285 -
1286 #ifdef CONFIG_MMU
1287 /*
1288 * The vectors page is always readable from user space for the
1289 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1290 index 8fc2c8f..064c150 100644
1291 --- a/arch/arm/kernel/setup.c
1292 +++ b/arch/arm/kernel/setup.c
1293 @@ -108,13 +108,13 @@ struct processor processor __read_mostly;
1294 struct cpu_tlb_fns cpu_tlb __read_mostly;
1295 #endif
1296 #ifdef MULTI_USER
1297 -struct cpu_user_fns cpu_user __read_mostly;
1298 +struct cpu_user_fns cpu_user __read_only;
1299 #endif
1300 #ifdef MULTI_CACHE
1301 -struct cpu_cache_fns cpu_cache __read_mostly;
1302 +struct cpu_cache_fns cpu_cache __read_only;
1303 #endif
1304 #ifdef CONFIG_OUTER_CACHE
1305 -struct outer_cache_fns outer_cache __read_mostly;
1306 +struct outer_cache_fns outer_cache __read_only;
1307 EXPORT_SYMBOL(outer_cache);
1308 #endif
1309
1310 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1311 index 99a5727..a3d5bb1 100644
1312 --- a/arch/arm/kernel/traps.c
1313 +++ b/arch/arm/kernel/traps.c
1314 @@ -259,6 +259,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1315
1316 static DEFINE_RAW_SPINLOCK(die_lock);
1317
1318 +extern void gr_handle_kernel_exploit(void);
1319 +
1320 /*
1321 * This function is protected against re-entrancy.
1322 */
1323 @@ -288,6 +290,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1324 panic("Fatal exception in interrupt");
1325 if (panic_on_oops)
1326 panic("Fatal exception");
1327 +
1328 + gr_handle_kernel_exploit();
1329 +
1330 if (ret != NOTIFY_STOP)
1331 do_exit(SIGSEGV);
1332 }
1333 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1334 index 66a477a..bee61d3 100644
1335 --- a/arch/arm/lib/copy_from_user.S
1336 +++ b/arch/arm/lib/copy_from_user.S
1337 @@ -16,7 +16,7 @@
1338 /*
1339 * Prototype:
1340 *
1341 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1342 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1343 *
1344 * Purpose:
1345 *
1346 @@ -84,11 +84,11 @@
1347
1348 .text
1349
1350 -ENTRY(__copy_from_user)
1351 +ENTRY(___copy_from_user)
1352
1353 #include "copy_template.S"
1354
1355 -ENDPROC(__copy_from_user)
1356 +ENDPROC(___copy_from_user)
1357
1358 .pushsection .fixup,"ax"
1359 .align 0
1360 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1361 index 6ee2f67..d1cce76 100644
1362 --- a/arch/arm/lib/copy_page.S
1363 +++ b/arch/arm/lib/copy_page.S
1364 @@ -10,6 +10,7 @@
1365 * ASM optimised string functions
1366 */
1367 #include <linux/linkage.h>
1368 +#include <linux/const.h>
1369 #include <asm/assembler.h>
1370 #include <asm/asm-offsets.h>
1371 #include <asm/cache.h>
1372 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1373 index d066df6..df28194 100644
1374 --- a/arch/arm/lib/copy_to_user.S
1375 +++ b/arch/arm/lib/copy_to_user.S
1376 @@ -16,7 +16,7 @@
1377 /*
1378 * Prototype:
1379 *
1380 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1381 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1382 *
1383 * Purpose:
1384 *
1385 @@ -88,11 +88,11 @@
1386 .text
1387
1388 ENTRY(__copy_to_user_std)
1389 -WEAK(__copy_to_user)
1390 +WEAK(___copy_to_user)
1391
1392 #include "copy_template.S"
1393
1394 -ENDPROC(__copy_to_user)
1395 +ENDPROC(___copy_to_user)
1396 ENDPROC(__copy_to_user_std)
1397
1398 .pushsection .fixup,"ax"
1399 diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
1400 index d0ece2a..5ae2f39 100644
1401 --- a/arch/arm/lib/uaccess.S
1402 +++ b/arch/arm/lib/uaccess.S
1403 @@ -20,7 +20,7 @@
1404
1405 #define PAGE_SHIFT 12
1406
1407 -/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
1408 +/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
1409 * Purpose : copy a block to user memory from kernel memory
1410 * Params : to - user memory
1411 * : from - kernel memory
1412 @@ -40,7 +40,7 @@ USER( T(strgtb) r3, [r0], #1) @ May fault
1413 sub r2, r2, ip
1414 b .Lc2u_dest_aligned
1415
1416 -ENTRY(__copy_to_user)
1417 +ENTRY(___copy_to_user)
1418 stmfd sp!, {r2, r4 - r7, lr}
1419 cmp r2, #4
1420 blt .Lc2u_not_enough
1421 @@ -278,14 +278,14 @@ USER( T(strgeb) r3, [r0], #1) @ May fault
1422 ldrgtb r3, [r1], #0
1423 USER( T(strgtb) r3, [r0], #1) @ May fault
1424 b .Lc2u_finished
1425 -ENDPROC(__copy_to_user)
1426 +ENDPROC(___copy_to_user)
1427
1428 .pushsection .fixup,"ax"
1429 .align 0
1430 9001: ldmfd sp!, {r0, r4 - r7, pc}
1431 .popsection
1432
1433 -/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
1434 +/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
1435 * Purpose : copy a block from user memory to kernel memory
1436 * Params : to - kernel memory
1437 * : from - user memory
1438 @@ -304,7 +304,7 @@ USER( T(ldrgtb) r3, [r1], #1) @ May fault
1439 sub r2, r2, ip
1440 b .Lcfu_dest_aligned
1441
1442 -ENTRY(__copy_from_user)
1443 +ENTRY(___copy_from_user)
1444 stmfd sp!, {r0, r2, r4 - r7, lr}
1445 cmp r2, #4
1446 blt .Lcfu_not_enough
1447 @@ -544,7 +544,7 @@ USER( T(ldrgeb) r3, [r1], #1) @ May fault
1448 USER( T(ldrgtb) r3, [r1], #1) @ May fault
1449 strgtb r3, [r0], #1
1450 b .Lcfu_finished
1451 -ENDPROC(__copy_from_user)
1452 +ENDPROC(___copy_from_user)
1453
1454 .pushsection .fixup,"ax"
1455 .align 0
1456 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1457 index 025f742..8432b08 100644
1458 --- a/arch/arm/lib/uaccess_with_memcpy.c
1459 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1460 @@ -104,7 +104,7 @@ out:
1461 }
1462
1463 unsigned long
1464 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1465 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1466 {
1467 /*
1468 * This test is stubbed out of the main function above to keep
1469 diff --git a/arch/arm/mach-ux500/mbox-db5500.c b/arch/arm/mach-ux500/mbox-db5500.c
1470 index 2b2d51c..0127490 100644
1471 --- a/arch/arm/mach-ux500/mbox-db5500.c
1472 +++ b/arch/arm/mach-ux500/mbox-db5500.c
1473 @@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct device *dev,
1474 return sprintf(buf, "0x%X\n", mbox_value);
1475 }
1476
1477 -static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1478 +static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1479
1480 static int mbox_show(struct seq_file *s, void *data)
1481 {
1482 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1483 index aa33949..b242a2f 100644
1484 --- a/arch/arm/mm/fault.c
1485 +++ b/arch/arm/mm/fault.c
1486 @@ -183,6 +183,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1487 }
1488 #endif
1489
1490 +#ifdef CONFIG_PAX_PAGEEXEC
1491 + if (fsr & FSR_LNX_PF) {
1492 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1493 + do_group_exit(SIGKILL);
1494 + }
1495 +#endif
1496 +
1497 tsk->thread.address = addr;
1498 tsk->thread.error_code = fsr;
1499 tsk->thread.trap_no = 14;
1500 @@ -384,6 +391,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1501 }
1502 #endif /* CONFIG_MMU */
1503
1504 +#ifdef CONFIG_PAX_PAGEEXEC
1505 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1506 +{
1507 + long i;
1508 +
1509 + printk(KERN_ERR "PAX: bytes at PC: ");
1510 + for (i = 0; i < 20; i++) {
1511 + unsigned char c;
1512 + if (get_user(c, (__force unsigned char __user *)pc+i))
1513 + printk(KERN_CONT "?? ");
1514 + else
1515 + printk(KERN_CONT "%02x ", c);
1516 + }
1517 + printk("\n");
1518 +
1519 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1520 + for (i = -1; i < 20; i++) {
1521 + unsigned long c;
1522 + if (get_user(c, (__force unsigned long __user *)sp+i))
1523 + printk(KERN_CONT "???????? ");
1524 + else
1525 + printk(KERN_CONT "%08lx ", c);
1526 + }
1527 + printk("\n");
1528 +}
1529 +#endif
1530 +
1531 /*
1532 * First Level Translation Fault Handler
1533 *
1534 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1535 index 44b628e..623ee2a 100644
1536 --- a/arch/arm/mm/mmap.c
1537 +++ b/arch/arm/mm/mmap.c
1538 @@ -54,6 +54,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1539 if (len > TASK_SIZE)
1540 return -ENOMEM;
1541
1542 +#ifdef CONFIG_PAX_RANDMMAP
1543 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1544 +#endif
1545 +
1546 if (addr) {
1547 if (do_align)
1548 addr = COLOUR_ALIGN(addr, pgoff);
1549 @@ -61,15 +65,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1550 addr = PAGE_ALIGN(addr);
1551
1552 vma = find_vma(mm, addr);
1553 - if (TASK_SIZE - len >= addr &&
1554 - (!vma || addr + len <= vma->vm_start))
1555 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1556 return addr;
1557 }
1558 if (len > mm->cached_hole_size) {
1559 - start_addr = addr = mm->free_area_cache;
1560 + start_addr = addr = mm->free_area_cache;
1561 } else {
1562 - start_addr = addr = TASK_UNMAPPED_BASE;
1563 - mm->cached_hole_size = 0;
1564 + start_addr = addr = mm->mmap_base;
1565 + mm->cached_hole_size = 0;
1566 }
1567 /* 8 bits of randomness in 20 address space bits */
1568 if ((current->flags & PF_RANDOMIZE) &&
1569 @@ -89,14 +92,14 @@ full_search:
1570 * Start a new search - just in case we missed
1571 * some holes.
1572 */
1573 - if (start_addr != TASK_UNMAPPED_BASE) {
1574 - start_addr = addr = TASK_UNMAPPED_BASE;
1575 + if (start_addr != mm->mmap_base) {
1576 + start_addr = addr = mm->mmap_base;
1577 mm->cached_hole_size = 0;
1578 goto full_search;
1579 }
1580 return -ENOMEM;
1581 }
1582 - if (!vma || addr + len <= vma->vm_start) {
1583 + if (check_heap_stack_gap(vma, addr, len)) {
1584 /*
1585 * Remember the place where we stopped the search:
1586 */
1587 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
1588 index 4c1a363..df311d0 100644
1589 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
1590 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
1591 @@ -41,7 +41,7 @@ struct samsung_dma_ops {
1592 int (*started)(unsigned ch);
1593 int (*flush)(unsigned ch);
1594 int (*stop)(unsigned ch);
1595 -};
1596 +} __no_const;
1597
1598 extern void *samsung_dmadev_get_ops(void);
1599 extern void *s3c_dma_get_ops(void);
1600 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
1601 index 5f28cae..3d23723 100644
1602 --- a/arch/arm/plat-samsung/include/plat/ehci.h
1603 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
1604 @@ -14,7 +14,7 @@
1605 struct s5p_ehci_platdata {
1606 int (*phy_init)(struct platform_device *pdev, int type);
1607 int (*phy_exit)(struct platform_device *pdev, int type);
1608 -};
1609 +} __no_const;
1610
1611 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
1612
1613 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
1614 index c3a58a1..78fbf54 100644
1615 --- a/arch/avr32/include/asm/cache.h
1616 +++ b/arch/avr32/include/asm/cache.h
1617 @@ -1,8 +1,10 @@
1618 #ifndef __ASM_AVR32_CACHE_H
1619 #define __ASM_AVR32_CACHE_H
1620
1621 +#include <linux/const.h>
1622 +
1623 #define L1_CACHE_SHIFT 5
1624 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1625 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1626
1627 /*
1628 * Memory returned by kmalloc() may be used for DMA, so we must make
1629 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
1630 index 3b3159b..425ea94 100644
1631 --- a/arch/avr32/include/asm/elf.h
1632 +++ b/arch/avr32/include/asm/elf.h
1633 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
1634 the loader. We need to make sure that it is out of the way of the program
1635 that it will "exec", and that there is sufficient room for the brk. */
1636
1637 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1638 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1639
1640 +#ifdef CONFIG_PAX_ASLR
1641 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
1642 +
1643 +#define PAX_DELTA_MMAP_LEN 15
1644 +#define PAX_DELTA_STACK_LEN 15
1645 +#endif
1646
1647 /* This yields a mask that user programs can use to figure out what
1648 instruction set this CPU supports. This could be done in user space,
1649 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
1650 index b7f5c68..556135c 100644
1651 --- a/arch/avr32/include/asm/kmap_types.h
1652 +++ b/arch/avr32/include/asm/kmap_types.h
1653 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
1654 D(11) KM_IRQ1,
1655 D(12) KM_SOFTIRQ0,
1656 D(13) KM_SOFTIRQ1,
1657 -D(14) KM_TYPE_NR
1658 +D(14) KM_CLEARPAGE,
1659 +D(15) KM_TYPE_NR
1660 };
1661
1662 #undef D
1663 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
1664 index f7040a1..db9f300 100644
1665 --- a/arch/avr32/mm/fault.c
1666 +++ b/arch/avr32/mm/fault.c
1667 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
1668
1669 int exception_trace = 1;
1670
1671 +#ifdef CONFIG_PAX_PAGEEXEC
1672 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1673 +{
1674 + unsigned long i;
1675 +
1676 + printk(KERN_ERR "PAX: bytes at PC: ");
1677 + for (i = 0; i < 20; i++) {
1678 + unsigned char c;
1679 + if (get_user(c, (unsigned char *)pc+i))
1680 + printk(KERN_CONT "???????? ");
1681 + else
1682 + printk(KERN_CONT "%02x ", c);
1683 + }
1684 + printk("\n");
1685 +}
1686 +#endif
1687 +
1688 /*
1689 * This routine handles page faults. It determines the address and the
1690 * problem, and then passes it off to one of the appropriate routines.
1691 @@ -156,6 +173,16 @@ bad_area:
1692 up_read(&mm->mmap_sem);
1693
1694 if (user_mode(regs)) {
1695 +
1696 +#ifdef CONFIG_PAX_PAGEEXEC
1697 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1698 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
1699 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
1700 + do_group_exit(SIGKILL);
1701 + }
1702 + }
1703 +#endif
1704 +
1705 if (exception_trace && printk_ratelimit())
1706 printk("%s%s[%d]: segfault at %08lx pc %08lx "
1707 "sp %08lx ecr %lu\n",
1708 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
1709 index 568885a..f8008df 100644
1710 --- a/arch/blackfin/include/asm/cache.h
1711 +++ b/arch/blackfin/include/asm/cache.h
1712 @@ -7,6 +7,7 @@
1713 #ifndef __ARCH_BLACKFIN_CACHE_H
1714 #define __ARCH_BLACKFIN_CACHE_H
1715
1716 +#include <linux/const.h>
1717 #include <linux/linkage.h> /* for asmlinkage */
1718
1719 /*
1720 @@ -14,7 +15,7 @@
1721 * Blackfin loads 32 bytes for cache
1722 */
1723 #define L1_CACHE_SHIFT 5
1724 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1725 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1726 #define SMP_CACHE_BYTES L1_CACHE_BYTES
1727
1728 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
1729 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
1730 index aea2718..3639a60 100644
1731 --- a/arch/cris/include/arch-v10/arch/cache.h
1732 +++ b/arch/cris/include/arch-v10/arch/cache.h
1733 @@ -1,8 +1,9 @@
1734 #ifndef _ASM_ARCH_CACHE_H
1735 #define _ASM_ARCH_CACHE_H
1736
1737 +#include <linux/const.h>
1738 /* Etrax 100LX have 32-byte cache-lines. */
1739 -#define L1_CACHE_BYTES 32
1740 #define L1_CACHE_SHIFT 5
1741 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1742
1743 #endif /* _ASM_ARCH_CACHE_H */
1744 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
1745 index 1de779f..336fad3 100644
1746 --- a/arch/cris/include/arch-v32/arch/cache.h
1747 +++ b/arch/cris/include/arch-v32/arch/cache.h
1748 @@ -1,11 +1,12 @@
1749 #ifndef _ASM_CRIS_ARCH_CACHE_H
1750 #define _ASM_CRIS_ARCH_CACHE_H
1751
1752 +#include <linux/const.h>
1753 #include <arch/hwregs/dma.h>
1754
1755 /* A cache-line is 32 bytes. */
1756 -#define L1_CACHE_BYTES 32
1757 #define L1_CACHE_SHIFT 5
1758 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1759
1760 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
1761
1762 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
1763 index 0d8a7d6..d0c9ff5 100644
1764 --- a/arch/frv/include/asm/atomic.h
1765 +++ b/arch/frv/include/asm/atomic.h
1766 @@ -241,6 +241,16 @@ extern uint32_t __xchg_32(uint32_t i, volatile void *v);
1767 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
1768 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
1769
1770 +#define atomic64_read_unchecked(v) atomic64_read(v)
1771 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
1772 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
1773 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
1774 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
1775 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
1776 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
1777 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
1778 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
1779 +
1780 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
1781 {
1782 int c, old;
1783 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
1784 index 2797163..c2a401d 100644
1785 --- a/arch/frv/include/asm/cache.h
1786 +++ b/arch/frv/include/asm/cache.h
1787 @@ -12,10 +12,11 @@
1788 #ifndef __ASM_CACHE_H
1789 #define __ASM_CACHE_H
1790
1791 +#include <linux/const.h>
1792
1793 /* bytes per L1 cache line */
1794 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
1795 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1796 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1797
1798 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
1799 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
1800 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
1801 index f8e16b2..c73ff79 100644
1802 --- a/arch/frv/include/asm/kmap_types.h
1803 +++ b/arch/frv/include/asm/kmap_types.h
1804 @@ -23,6 +23,7 @@ enum km_type {
1805 KM_IRQ1,
1806 KM_SOFTIRQ0,
1807 KM_SOFTIRQ1,
1808 + KM_CLEARPAGE,
1809 KM_TYPE_NR
1810 };
1811
1812 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
1813 index 385fd30..6c3d97e 100644
1814 --- a/arch/frv/mm/elf-fdpic.c
1815 +++ b/arch/frv/mm/elf-fdpic.c
1816 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1817 if (addr) {
1818 addr = PAGE_ALIGN(addr);
1819 vma = find_vma(current->mm, addr);
1820 - if (TASK_SIZE - len >= addr &&
1821 - (!vma || addr + len <= vma->vm_start))
1822 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1823 goto success;
1824 }
1825
1826 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1827 for (; vma; vma = vma->vm_next) {
1828 if (addr > limit)
1829 break;
1830 - if (addr + len <= vma->vm_start)
1831 + if (check_heap_stack_gap(vma, addr, len))
1832 goto success;
1833 addr = vma->vm_end;
1834 }
1835 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1836 for (; vma; vma = vma->vm_next) {
1837 if (addr > limit)
1838 break;
1839 - if (addr + len <= vma->vm_start)
1840 + if (check_heap_stack_gap(vma, addr, len))
1841 goto success;
1842 addr = vma->vm_end;
1843 }
1844 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
1845 index c635028..6d9445a 100644
1846 --- a/arch/h8300/include/asm/cache.h
1847 +++ b/arch/h8300/include/asm/cache.h
1848 @@ -1,8 +1,10 @@
1849 #ifndef __ARCH_H8300_CACHE_H
1850 #define __ARCH_H8300_CACHE_H
1851
1852 +#include <linux/const.h>
1853 +
1854 /* bytes per L1 cache line */
1855 -#define L1_CACHE_BYTES 4
1856 +#define L1_CACHE_BYTES _AC(4,UL)
1857
1858 /* m68k-elf-gcc 2.95.2 doesn't like these */
1859
1860 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
1861 index 0f01de2..d37d309 100644
1862 --- a/arch/hexagon/include/asm/cache.h
1863 +++ b/arch/hexagon/include/asm/cache.h
1864 @@ -21,9 +21,11 @@
1865 #ifndef __ASM_CACHE_H
1866 #define __ASM_CACHE_H
1867
1868 +#include <linux/const.h>
1869 +
1870 /* Bytes per L1 cache line */
1871 -#define L1_CACHE_SHIFT (5)
1872 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1873 +#define L1_CACHE_SHIFT 5
1874 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1875
1876 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
1877 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
1878 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
1879 index 3fad89e..3047da5 100644
1880 --- a/arch/ia64/include/asm/atomic.h
1881 +++ b/arch/ia64/include/asm/atomic.h
1882 @@ -209,6 +209,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
1883 #define atomic64_inc(v) atomic64_add(1, (v))
1884 #define atomic64_dec(v) atomic64_sub(1, (v))
1885
1886 +#define atomic64_read_unchecked(v) atomic64_read(v)
1887 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
1888 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
1889 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
1890 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
1891 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
1892 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
1893 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
1894 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
1895 +
1896 /* Atomic operations are already serializing */
1897 #define smp_mb__before_atomic_dec() barrier()
1898 #define smp_mb__after_atomic_dec() barrier()
1899 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
1900 index 988254a..e1ee885 100644
1901 --- a/arch/ia64/include/asm/cache.h
1902 +++ b/arch/ia64/include/asm/cache.h
1903 @@ -1,6 +1,7 @@
1904 #ifndef _ASM_IA64_CACHE_H
1905 #define _ASM_IA64_CACHE_H
1906
1907 +#include <linux/const.h>
1908
1909 /*
1910 * Copyright (C) 1998-2000 Hewlett-Packard Co
1911 @@ -9,7 +10,7 @@
1912
1913 /* Bytes per L1 (data) cache line. */
1914 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
1915 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1916 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1917
1918 #ifdef CONFIG_SMP
1919 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
1920 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
1921 index b5298eb..67c6e62 100644
1922 --- a/arch/ia64/include/asm/elf.h
1923 +++ b/arch/ia64/include/asm/elf.h
1924 @@ -42,6 +42,13 @@
1925 */
1926 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
1927
1928 +#ifdef CONFIG_PAX_ASLR
1929 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
1930 +
1931 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1932 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1933 +#endif
1934 +
1935 #define PT_IA_64_UNWIND 0x70000001
1936
1937 /* IA-64 relocations: */
1938 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
1939 index 1a97af3..7529d31 100644
1940 --- a/arch/ia64/include/asm/pgtable.h
1941 +++ b/arch/ia64/include/asm/pgtable.h
1942 @@ -12,7 +12,7 @@
1943 * David Mosberger-Tang <davidm@hpl.hp.com>
1944 */
1945
1946 -
1947 +#include <linux/const.h>
1948 #include <asm/mman.h>
1949 #include <asm/page.h>
1950 #include <asm/processor.h>
1951 @@ -143,6 +143,17 @@
1952 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1953 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1954 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
1955 +
1956 +#ifdef CONFIG_PAX_PAGEEXEC
1957 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
1958 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1959 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1960 +#else
1961 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
1962 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
1963 +# define PAGE_COPY_NOEXEC PAGE_COPY
1964 +#endif
1965 +
1966 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
1967 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
1968 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
1969 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
1970 index b77768d..e0795eb 100644
1971 --- a/arch/ia64/include/asm/spinlock.h
1972 +++ b/arch/ia64/include/asm/spinlock.h
1973 @@ -72,7 +72,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
1974 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
1975
1976 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
1977 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
1978 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
1979 }
1980
1981 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
1982 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
1983 index 449c8c0..432a3d2 100644
1984 --- a/arch/ia64/include/asm/uaccess.h
1985 +++ b/arch/ia64/include/asm/uaccess.h
1986 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
1987 const void *__cu_from = (from); \
1988 long __cu_len = (n); \
1989 \
1990 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
1991 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
1992 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
1993 __cu_len; \
1994 })
1995 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
1996 long __cu_len = (n); \
1997 \
1998 __chk_user_ptr(__cu_from); \
1999 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2000 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2001 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2002 __cu_len; \
2003 })
2004 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2005 index 24603be..948052d 100644
2006 --- a/arch/ia64/kernel/module.c
2007 +++ b/arch/ia64/kernel/module.c
2008 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2009 void
2010 module_free (struct module *mod, void *module_region)
2011 {
2012 - if (mod && mod->arch.init_unw_table &&
2013 - module_region == mod->module_init) {
2014 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2015 unw_remove_unwind_table(mod->arch.init_unw_table);
2016 mod->arch.init_unw_table = NULL;
2017 }
2018 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2019 }
2020
2021 static inline int
2022 +in_init_rx (const struct module *mod, uint64_t addr)
2023 +{
2024 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2025 +}
2026 +
2027 +static inline int
2028 +in_init_rw (const struct module *mod, uint64_t addr)
2029 +{
2030 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2031 +}
2032 +
2033 +static inline int
2034 in_init (const struct module *mod, uint64_t addr)
2035 {
2036 - return addr - (uint64_t) mod->module_init < mod->init_size;
2037 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2038 +}
2039 +
2040 +static inline int
2041 +in_core_rx (const struct module *mod, uint64_t addr)
2042 +{
2043 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2044 +}
2045 +
2046 +static inline int
2047 +in_core_rw (const struct module *mod, uint64_t addr)
2048 +{
2049 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2050 }
2051
2052 static inline int
2053 in_core (const struct module *mod, uint64_t addr)
2054 {
2055 - return addr - (uint64_t) mod->module_core < mod->core_size;
2056 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2057 }
2058
2059 static inline int
2060 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2061 break;
2062
2063 case RV_BDREL:
2064 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2065 + if (in_init_rx(mod, val))
2066 + val -= (uint64_t) mod->module_init_rx;
2067 + else if (in_init_rw(mod, val))
2068 + val -= (uint64_t) mod->module_init_rw;
2069 + else if (in_core_rx(mod, val))
2070 + val -= (uint64_t) mod->module_core_rx;
2071 + else if (in_core_rw(mod, val))
2072 + val -= (uint64_t) mod->module_core_rw;
2073 break;
2074
2075 case RV_LTV:
2076 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2077 * addresses have been selected...
2078 */
2079 uint64_t gp;
2080 - if (mod->core_size > MAX_LTOFF)
2081 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2082 /*
2083 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2084 * at the end of the module.
2085 */
2086 - gp = mod->core_size - MAX_LTOFF / 2;
2087 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2088 else
2089 - gp = mod->core_size / 2;
2090 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2091 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2092 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2093 mod->arch.gp = gp;
2094 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2095 }
2096 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2097 index 609d500..7dde2a8 100644
2098 --- a/arch/ia64/kernel/sys_ia64.c
2099 +++ b/arch/ia64/kernel/sys_ia64.c
2100 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2101 if (REGION_NUMBER(addr) == RGN_HPAGE)
2102 addr = 0;
2103 #endif
2104 +
2105 +#ifdef CONFIG_PAX_RANDMMAP
2106 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2107 + addr = mm->free_area_cache;
2108 + else
2109 +#endif
2110 +
2111 if (!addr)
2112 addr = mm->free_area_cache;
2113
2114 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2115 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2116 /* At this point: (!vma || addr < vma->vm_end). */
2117 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2118 - if (start_addr != TASK_UNMAPPED_BASE) {
2119 + if (start_addr != mm->mmap_base) {
2120 /* Start a new search --- just in case we missed some holes. */
2121 - addr = TASK_UNMAPPED_BASE;
2122 + addr = mm->mmap_base;
2123 goto full_search;
2124 }
2125 return -ENOMEM;
2126 }
2127 - if (!vma || addr + len <= vma->vm_start) {
2128 + if (check_heap_stack_gap(vma, addr, len)) {
2129 /* Remember the address where we stopped this search: */
2130 mm->free_area_cache = addr + len;
2131 return addr;
2132 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2133 index 53c0ba0..2accdde 100644
2134 --- a/arch/ia64/kernel/vmlinux.lds.S
2135 +++ b/arch/ia64/kernel/vmlinux.lds.S
2136 @@ -199,7 +199,7 @@ SECTIONS {
2137 /* Per-cpu data: */
2138 . = ALIGN(PERCPU_PAGE_SIZE);
2139 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2140 - __phys_per_cpu_start = __per_cpu_load;
2141 + __phys_per_cpu_start = per_cpu_load;
2142 /*
2143 * ensure percpu data fits
2144 * into percpu page size
2145 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2146 index 20b3593..1ce77f0 100644
2147 --- a/arch/ia64/mm/fault.c
2148 +++ b/arch/ia64/mm/fault.c
2149 @@ -73,6 +73,23 @@ mapped_kernel_page_is_present (unsigned long address)
2150 return pte_present(pte);
2151 }
2152
2153 +#ifdef CONFIG_PAX_PAGEEXEC
2154 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2155 +{
2156 + unsigned long i;
2157 +
2158 + printk(KERN_ERR "PAX: bytes at PC: ");
2159 + for (i = 0; i < 8; i++) {
2160 + unsigned int c;
2161 + if (get_user(c, (unsigned int *)pc+i))
2162 + printk(KERN_CONT "???????? ");
2163 + else
2164 + printk(KERN_CONT "%08x ", c);
2165 + }
2166 + printk("\n");
2167 +}
2168 +#endif
2169 +
2170 void __kprobes
2171 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2172 {
2173 @@ -146,9 +163,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2174 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2175 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2176
2177 - if ((vma->vm_flags & mask) != mask)
2178 + if ((vma->vm_flags & mask) != mask) {
2179 +
2180 +#ifdef CONFIG_PAX_PAGEEXEC
2181 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2182 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2183 + goto bad_area;
2184 +
2185 + up_read(&mm->mmap_sem);
2186 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2187 + do_group_exit(SIGKILL);
2188 + }
2189 +#endif
2190 +
2191 goto bad_area;
2192
2193 + }
2194 +
2195 /*
2196 * If for any reason at all we couldn't handle the fault, make
2197 * sure we exit gracefully rather than endlessly redo the
2198 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2199 index 5ca674b..e0e1b70 100644
2200 --- a/arch/ia64/mm/hugetlbpage.c
2201 +++ b/arch/ia64/mm/hugetlbpage.c
2202 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2203 /* At this point: (!vmm || addr < vmm->vm_end). */
2204 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2205 return -ENOMEM;
2206 - if (!vmm || (addr + len) <= vmm->vm_start)
2207 + if (check_heap_stack_gap(vmm, addr, len))
2208 return addr;
2209 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2210 }
2211 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2212 index 00cb0e2..2ad8024 100644
2213 --- a/arch/ia64/mm/init.c
2214 +++ b/arch/ia64/mm/init.c
2215 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2216 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2217 vma->vm_end = vma->vm_start + PAGE_SIZE;
2218 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2219 +
2220 +#ifdef CONFIG_PAX_PAGEEXEC
2221 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2222 + vma->vm_flags &= ~VM_EXEC;
2223 +
2224 +#ifdef CONFIG_PAX_MPROTECT
2225 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2226 + vma->vm_flags &= ~VM_MAYEXEC;
2227 +#endif
2228 +
2229 + }
2230 +#endif
2231 +
2232 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2233 down_write(&current->mm->mmap_sem);
2234 if (insert_vm_struct(current->mm, vma)) {
2235 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2236 index 40b3ee9..8c2c112 100644
2237 --- a/arch/m32r/include/asm/cache.h
2238 +++ b/arch/m32r/include/asm/cache.h
2239 @@ -1,8 +1,10 @@
2240 #ifndef _ASM_M32R_CACHE_H
2241 #define _ASM_M32R_CACHE_H
2242
2243 +#include <linux/const.h>
2244 +
2245 /* L1 cache line size */
2246 #define L1_CACHE_SHIFT 4
2247 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2248 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2249
2250 #endif /* _ASM_M32R_CACHE_H */
2251 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2252 index 82abd15..d95ae5d 100644
2253 --- a/arch/m32r/lib/usercopy.c
2254 +++ b/arch/m32r/lib/usercopy.c
2255 @@ -14,6 +14,9 @@
2256 unsigned long
2257 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2258 {
2259 + if ((long)n < 0)
2260 + return n;
2261 +
2262 prefetch(from);
2263 if (access_ok(VERIFY_WRITE, to, n))
2264 __copy_user(to,from,n);
2265 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2266 unsigned long
2267 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2268 {
2269 + if ((long)n < 0)
2270 + return n;
2271 +
2272 prefetchw(to);
2273 if (access_ok(VERIFY_READ, from, n))
2274 __copy_user_zeroing(to,from,n);
2275 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2276 index 0395c51..5f26031 100644
2277 --- a/arch/m68k/include/asm/cache.h
2278 +++ b/arch/m68k/include/asm/cache.h
2279 @@ -4,9 +4,11 @@
2280 #ifndef __ARCH_M68K_CACHE_H
2281 #define __ARCH_M68K_CACHE_H
2282
2283 +#include <linux/const.h>
2284 +
2285 /* bytes per L1 cache line */
2286 #define L1_CACHE_SHIFT 4
2287 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2288 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2289
2290 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2291
2292 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2293 index 4efe96a..60e8699 100644
2294 --- a/arch/microblaze/include/asm/cache.h
2295 +++ b/arch/microblaze/include/asm/cache.h
2296 @@ -13,11 +13,12 @@
2297 #ifndef _ASM_MICROBLAZE_CACHE_H
2298 #define _ASM_MICROBLAZE_CACHE_H
2299
2300 +#include <linux/const.h>
2301 #include <asm/registers.h>
2302
2303 #define L1_CACHE_SHIFT 5
2304 /* word-granular cache in microblaze */
2305 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2306 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2307
2308 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2309
2310 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2311 index 1d93f81..67794d0 100644
2312 --- a/arch/mips/include/asm/atomic.h
2313 +++ b/arch/mips/include/asm/atomic.h
2314 @@ -21,6 +21,10 @@
2315 #include <asm/war.h>
2316 #include <asm/system.h>
2317
2318 +#ifdef CONFIG_GENERIC_ATOMIC64
2319 +#include <asm-generic/atomic64.h>
2320 +#endif
2321 +
2322 #define ATOMIC_INIT(i) { (i) }
2323
2324 /*
2325 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2326 */
2327 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2328
2329 +#define atomic64_read_unchecked(v) atomic64_read(v)
2330 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2331 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2332 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2333 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2334 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2335 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2336 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2337 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2338 +
2339 #endif /* CONFIG_64BIT */
2340
2341 /*
2342 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2343 index b4db69f..8f3b093 100644
2344 --- a/arch/mips/include/asm/cache.h
2345 +++ b/arch/mips/include/asm/cache.h
2346 @@ -9,10 +9,11 @@
2347 #ifndef _ASM_CACHE_H
2348 #define _ASM_CACHE_H
2349
2350 +#include <linux/const.h>
2351 #include <kmalloc.h>
2352
2353 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2354 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2355 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2356
2357 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2358 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2359 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2360 index 455c0ac..ad65fbe 100644
2361 --- a/arch/mips/include/asm/elf.h
2362 +++ b/arch/mips/include/asm/elf.h
2363 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2364 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2365 #endif
2366
2367 +#ifdef CONFIG_PAX_ASLR
2368 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2369 +
2370 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2371 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2372 +#endif
2373 +
2374 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2375 struct linux_binprm;
2376 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2377 int uses_interp);
2378
2379 -struct mm_struct;
2380 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2381 -#define arch_randomize_brk arch_randomize_brk
2382 -
2383 #endif /* _ASM_ELF_H */
2384 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2385 index e59cd1a..8e329d6 100644
2386 --- a/arch/mips/include/asm/page.h
2387 +++ b/arch/mips/include/asm/page.h
2388 @@ -93,7 +93,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2389 #ifdef CONFIG_CPU_MIPS32
2390 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2391 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2392 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2393 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2394 #else
2395 typedef struct { unsigned long long pte; } pte_t;
2396 #define pte_val(x) ((x).pte)
2397 diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
2398 index 6018c80..7c37203 100644
2399 --- a/arch/mips/include/asm/system.h
2400 +++ b/arch/mips/include/asm/system.h
2401 @@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
2402 */
2403 #define __ARCH_WANT_UNLOCKED_CTXSW
2404
2405 -extern unsigned long arch_align_stack(unsigned long sp);
2406 +#define arch_align_stack(x) ((x) & ~0xfUL)
2407
2408 #endif /* _ASM_SYSTEM_H */
2409 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2410 index 9fdd8bc..4bd7f1a 100644
2411 --- a/arch/mips/kernel/binfmt_elfn32.c
2412 +++ b/arch/mips/kernel/binfmt_elfn32.c
2413 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2414 #undef ELF_ET_DYN_BASE
2415 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2416
2417 +#ifdef CONFIG_PAX_ASLR
2418 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2419 +
2420 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2421 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2422 +#endif
2423 +
2424 #include <asm/processor.h>
2425 #include <linux/module.h>
2426 #include <linux/elfcore.h>
2427 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2428 index ff44823..97f8906 100644
2429 --- a/arch/mips/kernel/binfmt_elfo32.c
2430 +++ b/arch/mips/kernel/binfmt_elfo32.c
2431 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2432 #undef ELF_ET_DYN_BASE
2433 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2434
2435 +#ifdef CONFIG_PAX_ASLR
2436 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2437 +
2438 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2439 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2440 +#endif
2441 +
2442 #include <asm/processor.h>
2443
2444 /*
2445 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2446 index c47f96e..661d418 100644
2447 --- a/arch/mips/kernel/process.c
2448 +++ b/arch/mips/kernel/process.c
2449 @@ -481,15 +481,3 @@ unsigned long get_wchan(struct task_struct *task)
2450 out:
2451 return pc;
2452 }
2453 -
2454 -/*
2455 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2456 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2457 - */
2458 -unsigned long arch_align_stack(unsigned long sp)
2459 -{
2460 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2461 - sp -= get_random_int() & ~PAGE_MASK;
2462 -
2463 - return sp & ALMASK;
2464 -}
2465 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
2466 index 937cf33..adb39bb 100644
2467 --- a/arch/mips/mm/fault.c
2468 +++ b/arch/mips/mm/fault.c
2469 @@ -28,6 +28,23 @@
2470 #include <asm/highmem.h> /* For VMALLOC_END */
2471 #include <linux/kdebug.h>
2472
2473 +#ifdef CONFIG_PAX_PAGEEXEC
2474 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2475 +{
2476 + unsigned long i;
2477 +
2478 + printk(KERN_ERR "PAX: bytes at PC: ");
2479 + for (i = 0; i < 5; i++) {
2480 + unsigned int c;
2481 + if (get_user(c, (unsigned int *)pc+i))
2482 + printk(KERN_CONT "???????? ");
2483 + else
2484 + printk(KERN_CONT "%08x ", c);
2485 + }
2486 + printk("\n");
2487 +}
2488 +#endif
2489 +
2490 /*
2491 * This routine handles page faults. It determines the address,
2492 * and the problem, and then passes it off to one of the appropriate
2493 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
2494 index 302d779..7d35bf8 100644
2495 --- a/arch/mips/mm/mmap.c
2496 +++ b/arch/mips/mm/mmap.c
2497 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2498 do_color_align = 1;
2499
2500 /* requesting a specific address */
2501 +
2502 +#ifdef CONFIG_PAX_RANDMMAP
2503 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2504 +#endif
2505 +
2506 if (addr) {
2507 if (do_color_align)
2508 addr = COLOUR_ALIGN(addr, pgoff);
2509 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2510 addr = PAGE_ALIGN(addr);
2511
2512 vma = find_vma(mm, addr);
2513 - if (TASK_SIZE - len >= addr &&
2514 - (!vma || addr + len <= vma->vm_start))
2515 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
2516 return addr;
2517 }
2518
2519 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2520 /* At this point: (!vma || addr < vma->vm_end). */
2521 if (TASK_SIZE - len < addr)
2522 return -ENOMEM;
2523 - if (!vma || addr + len <= vma->vm_start)
2524 + if (check_heap_stack_gap(vmm, addr, len))
2525 return addr;
2526 addr = vma->vm_end;
2527 if (do_color_align)
2528 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2529 /* make sure it can fit in the remaining address space */
2530 if (likely(addr > len)) {
2531 vma = find_vma(mm, addr - len);
2532 - if (!vma || addr <= vma->vm_start) {
2533 + if (check_heap_stack_gap(vmm, addr - len, len))
2534 /* cache the address as a hint for next time */
2535 return mm->free_area_cache = addr - len;
2536 }
2537 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2538 * return with success:
2539 */
2540 vma = find_vma(mm, addr);
2541 - if (likely(!vma || addr + len <= vma->vm_start)) {
2542 + if (check_heap_stack_gap(vmm, addr, len)) {
2543 /* cache the address as a hint for next time */
2544 return mm->free_area_cache = addr;
2545 }
2546 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2547 mm->unmap_area = arch_unmap_area_topdown;
2548 }
2549 }
2550 -
2551 -static inline unsigned long brk_rnd(void)
2552 -{
2553 - unsigned long rnd = get_random_int();
2554 -
2555 - rnd = rnd << PAGE_SHIFT;
2556 - /* 8MB for 32bit, 256MB for 64bit */
2557 - if (TASK_IS_32BIT_ADDR)
2558 - rnd = rnd & 0x7ffffful;
2559 - else
2560 - rnd = rnd & 0xffffffful;
2561 -
2562 - return rnd;
2563 -}
2564 -
2565 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2566 -{
2567 - unsigned long base = mm->brk;
2568 - unsigned long ret;
2569 -
2570 - ret = PAGE_ALIGN(base + brk_rnd());
2571 -
2572 - if (ret < mm->brk)
2573 - return mm->brk;
2574 -
2575 - return ret;
2576 -}
2577 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
2578 index 967d144..db12197 100644
2579 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
2580 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
2581 @@ -11,12 +11,14 @@
2582 #ifndef _ASM_PROC_CACHE_H
2583 #define _ASM_PROC_CACHE_H
2584
2585 +#include <linux/const.h>
2586 +
2587 /* L1 cache */
2588
2589 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
2590 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
2591 -#define L1_CACHE_BYTES 16 /* bytes per entry */
2592 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
2593 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
2594 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
2595
2596 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
2597 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2598 index bcb5df2..84fabd2 100644
2599 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2600 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2601 @@ -16,13 +16,15 @@
2602 #ifndef _ASM_PROC_CACHE_H
2603 #define _ASM_PROC_CACHE_H
2604
2605 +#include <linux/const.h>
2606 +
2607 /*
2608 * L1 cache
2609 */
2610 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
2611 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
2612 -#define L1_CACHE_BYTES 32 /* bytes per entry */
2613 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
2614 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
2615 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
2616
2617 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
2618 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
2619 index 4ce7a01..449202a 100644
2620 --- a/arch/openrisc/include/asm/cache.h
2621 +++ b/arch/openrisc/include/asm/cache.h
2622 @@ -19,11 +19,13 @@
2623 #ifndef __ASM_OPENRISC_CACHE_H
2624 #define __ASM_OPENRISC_CACHE_H
2625
2626 +#include <linux/const.h>
2627 +
2628 /* FIXME: How can we replace these with values from the CPU...
2629 * they shouldn't be hard-coded!
2630 */
2631
2632 -#define L1_CACHE_BYTES 16
2633 #define L1_CACHE_SHIFT 4
2634 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2635
2636 #endif /* __ASM_OPENRISC_CACHE_H */
2637 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
2638 index 4054b31..a10c105 100644
2639 --- a/arch/parisc/include/asm/atomic.h
2640 +++ b/arch/parisc/include/asm/atomic.h
2641 @@ -335,6 +335,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2642
2643 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
2644
2645 +#define atomic64_read_unchecked(v) atomic64_read(v)
2646 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2647 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2648 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2649 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2650 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2651 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2652 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2653 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2654 +
2655 #endif /* !CONFIG_64BIT */
2656
2657
2658 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
2659 index 47f11c7..3420df2 100644
2660 --- a/arch/parisc/include/asm/cache.h
2661 +++ b/arch/parisc/include/asm/cache.h
2662 @@ -5,6 +5,7 @@
2663 #ifndef __ARCH_PARISC_CACHE_H
2664 #define __ARCH_PARISC_CACHE_H
2665
2666 +#include <linux/const.h>
2667
2668 /*
2669 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
2670 @@ -15,13 +16,13 @@
2671 * just ruin performance.
2672 */
2673 #ifdef CONFIG_PA20
2674 -#define L1_CACHE_BYTES 64
2675 #define L1_CACHE_SHIFT 6
2676 #else
2677 -#define L1_CACHE_BYTES 32
2678 #define L1_CACHE_SHIFT 5
2679 #endif
2680
2681 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2682 +
2683 #ifndef __ASSEMBLY__
2684
2685 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2686 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
2687 index 19f6cb1..6c78cf2 100644
2688 --- a/arch/parisc/include/asm/elf.h
2689 +++ b/arch/parisc/include/asm/elf.h
2690 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
2691
2692 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
2693
2694 +#ifdef CONFIG_PAX_ASLR
2695 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
2696 +
2697 +#define PAX_DELTA_MMAP_LEN 16
2698 +#define PAX_DELTA_STACK_LEN 16
2699 +#endif
2700 +
2701 /* This yields a mask that user programs can use to figure out what
2702 instruction set this CPU supports. This could be done in user space,
2703 but it's not easy, and we've already done it here. */
2704 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
2705 index 22dadeb..f6c2be4 100644
2706 --- a/arch/parisc/include/asm/pgtable.h
2707 +++ b/arch/parisc/include/asm/pgtable.h
2708 @@ -210,6 +210,17 @@ struct vm_area_struct;
2709 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
2710 #define PAGE_COPY PAGE_EXECREAD
2711 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
2712 +
2713 +#ifdef CONFIG_PAX_PAGEEXEC
2714 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
2715 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2716 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2717 +#else
2718 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2719 +# define PAGE_COPY_NOEXEC PAGE_COPY
2720 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2721 +#endif
2722 +
2723 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
2724 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
2725 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
2726 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
2727 index 5e34ccf..672bc9c 100644
2728 --- a/arch/parisc/kernel/module.c
2729 +++ b/arch/parisc/kernel/module.c
2730 @@ -98,16 +98,38 @@
2731
2732 /* three functions to determine where in the module core
2733 * or init pieces the location is */
2734 +static inline int in_init_rx(struct module *me, void *loc)
2735 +{
2736 + return (loc >= me->module_init_rx &&
2737 + loc < (me->module_init_rx + me->init_size_rx));
2738 +}
2739 +
2740 +static inline int in_init_rw(struct module *me, void *loc)
2741 +{
2742 + return (loc >= me->module_init_rw &&
2743 + loc < (me->module_init_rw + me->init_size_rw));
2744 +}
2745 +
2746 static inline int in_init(struct module *me, void *loc)
2747 {
2748 - return (loc >= me->module_init &&
2749 - loc <= (me->module_init + me->init_size));
2750 + return in_init_rx(me, loc) || in_init_rw(me, loc);
2751 +}
2752 +
2753 +static inline int in_core_rx(struct module *me, void *loc)
2754 +{
2755 + return (loc >= me->module_core_rx &&
2756 + loc < (me->module_core_rx + me->core_size_rx));
2757 +}
2758 +
2759 +static inline int in_core_rw(struct module *me, void *loc)
2760 +{
2761 + return (loc >= me->module_core_rw &&
2762 + loc < (me->module_core_rw + me->core_size_rw));
2763 }
2764
2765 static inline int in_core(struct module *me, void *loc)
2766 {
2767 - return (loc >= me->module_core &&
2768 - loc <= (me->module_core + me->core_size));
2769 + return in_core_rx(me, loc) || in_core_rw(me, loc);
2770 }
2771
2772 static inline int in_local(struct module *me, void *loc)
2773 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
2774 }
2775
2776 /* align things a bit */
2777 - me->core_size = ALIGN(me->core_size, 16);
2778 - me->arch.got_offset = me->core_size;
2779 - me->core_size += gots * sizeof(struct got_entry);
2780 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
2781 + me->arch.got_offset = me->core_size_rw;
2782 + me->core_size_rw += gots * sizeof(struct got_entry);
2783
2784 - me->core_size = ALIGN(me->core_size, 16);
2785 - me->arch.fdesc_offset = me->core_size;
2786 - me->core_size += fdescs * sizeof(Elf_Fdesc);
2787 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
2788 + me->arch.fdesc_offset = me->core_size_rw;
2789 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
2790
2791 me->arch.got_max = gots;
2792 me->arch.fdesc_max = fdescs;
2793 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
2794
2795 BUG_ON(value == 0);
2796
2797 - got = me->module_core + me->arch.got_offset;
2798 + got = me->module_core_rw + me->arch.got_offset;
2799 for (i = 0; got[i].addr; i++)
2800 if (got[i].addr == value)
2801 goto out;
2802 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
2803 #ifdef CONFIG_64BIT
2804 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
2805 {
2806 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
2807 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
2808
2809 if (!value) {
2810 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
2811 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
2812
2813 /* Create new one */
2814 fdesc->addr = value;
2815 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
2816 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
2817 return (Elf_Addr)fdesc;
2818 }
2819 #endif /* CONFIG_64BIT */
2820 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
2821
2822 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
2823 end = table + sechdrs[me->arch.unwind_section].sh_size;
2824 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
2825 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
2826
2827 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
2828 me->arch.unwind_section, table, end, gp);
2829 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
2830 index c9b9322..02d8940 100644
2831 --- a/arch/parisc/kernel/sys_parisc.c
2832 +++ b/arch/parisc/kernel/sys_parisc.c
2833 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
2834 /* At this point: (!vma || addr < vma->vm_end). */
2835 if (TASK_SIZE - len < addr)
2836 return -ENOMEM;
2837 - if (!vma || addr + len <= vma->vm_start)
2838 + if (check_heap_stack_gap(vma, addr, len))
2839 return addr;
2840 addr = vma->vm_end;
2841 }
2842 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
2843 /* At this point: (!vma || addr < vma->vm_end). */
2844 if (TASK_SIZE - len < addr)
2845 return -ENOMEM;
2846 - if (!vma || addr + len <= vma->vm_start)
2847 + if (check_heap_stack_gap(vma, addr, len))
2848 return addr;
2849 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
2850 if (addr < vma->vm_end) /* handle wraparound */
2851 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
2852 if (flags & MAP_FIXED)
2853 return addr;
2854 if (!addr)
2855 - addr = TASK_UNMAPPED_BASE;
2856 + addr = current->mm->mmap_base;
2857
2858 if (filp) {
2859 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
2860 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
2861 index f19e660..414fe24 100644
2862 --- a/arch/parisc/kernel/traps.c
2863 +++ b/arch/parisc/kernel/traps.c
2864 @@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
2865
2866 down_read(&current->mm->mmap_sem);
2867 vma = find_vma(current->mm,regs->iaoq[0]);
2868 - if (vma && (regs->iaoq[0] >= vma->vm_start)
2869 - && (vma->vm_flags & VM_EXEC)) {
2870 -
2871 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
2872 fault_address = regs->iaoq[0];
2873 fault_space = regs->iasq[0];
2874
2875 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
2876 index 18162ce..94de376 100644
2877 --- a/arch/parisc/mm/fault.c
2878 +++ b/arch/parisc/mm/fault.c
2879 @@ -15,6 +15,7 @@
2880 #include <linux/sched.h>
2881 #include <linux/interrupt.h>
2882 #include <linux/module.h>
2883 +#include <linux/unistd.h>
2884
2885 #include <asm/uaccess.h>
2886 #include <asm/traps.h>
2887 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
2888 static unsigned long
2889 parisc_acctyp(unsigned long code, unsigned int inst)
2890 {
2891 - if (code == 6 || code == 16)
2892 + if (code == 6 || code == 7 || code == 16)
2893 return VM_EXEC;
2894
2895 switch (inst & 0xf0000000) {
2896 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
2897 }
2898 #endif
2899
2900 +#ifdef CONFIG_PAX_PAGEEXEC
2901 +/*
2902 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
2903 + *
2904 + * returns 1 when task should be killed
2905 + * 2 when rt_sigreturn trampoline was detected
2906 + * 3 when unpatched PLT trampoline was detected
2907 + */
2908 +static int pax_handle_fetch_fault(struct pt_regs *regs)
2909 +{
2910 +
2911 +#ifdef CONFIG_PAX_EMUPLT
2912 + int err;
2913 +
2914 + do { /* PaX: unpatched PLT emulation */
2915 + unsigned int bl, depwi;
2916 +
2917 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
2918 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
2919 +
2920 + if (err)
2921 + break;
2922 +
2923 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
2924 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
2925 +
2926 + err = get_user(ldw, (unsigned int *)addr);
2927 + err |= get_user(bv, (unsigned int *)(addr+4));
2928 + err |= get_user(ldw2, (unsigned int *)(addr+8));
2929 +
2930 + if (err)
2931 + break;
2932 +
2933 + if (ldw == 0x0E801096U &&
2934 + bv == 0xEAC0C000U &&
2935 + ldw2 == 0x0E881095U)
2936 + {
2937 + unsigned int resolver, map;
2938 +
2939 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
2940 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
2941 + if (err)
2942 + break;
2943 +
2944 + regs->gr[20] = instruction_pointer(regs)+8;
2945 + regs->gr[21] = map;
2946 + regs->gr[22] = resolver;
2947 + regs->iaoq[0] = resolver | 3UL;
2948 + regs->iaoq[1] = regs->iaoq[0] + 4;
2949 + return 3;
2950 + }
2951 + }
2952 + } while (0);
2953 +#endif
2954 +
2955 +#ifdef CONFIG_PAX_EMUTRAMP
2956 +
2957 +#ifndef CONFIG_PAX_EMUSIGRT
2958 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
2959 + return 1;
2960 +#endif
2961 +
2962 + do { /* PaX: rt_sigreturn emulation */
2963 + unsigned int ldi1, ldi2, bel, nop;
2964 +
2965 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
2966 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
2967 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
2968 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
2969 +
2970 + if (err)
2971 + break;
2972 +
2973 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
2974 + ldi2 == 0x3414015AU &&
2975 + bel == 0xE4008200U &&
2976 + nop == 0x08000240U)
2977 + {
2978 + regs->gr[25] = (ldi1 & 2) >> 1;
2979 + regs->gr[20] = __NR_rt_sigreturn;
2980 + regs->gr[31] = regs->iaoq[1] + 16;
2981 + regs->sr[0] = regs->iasq[1];
2982 + regs->iaoq[0] = 0x100UL;
2983 + regs->iaoq[1] = regs->iaoq[0] + 4;
2984 + regs->iasq[0] = regs->sr[2];
2985 + regs->iasq[1] = regs->sr[2];
2986 + return 2;
2987 + }
2988 + } while (0);
2989 +#endif
2990 +
2991 + return 1;
2992 +}
2993 +
2994 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2995 +{
2996 + unsigned long i;
2997 +
2998 + printk(KERN_ERR "PAX: bytes at PC: ");
2999 + for (i = 0; i < 5; i++) {
3000 + unsigned int c;
3001 + if (get_user(c, (unsigned int *)pc+i))
3002 + printk(KERN_CONT "???????? ");
3003 + else
3004 + printk(KERN_CONT "%08x ", c);
3005 + }
3006 + printk("\n");
3007 +}
3008 +#endif
3009 +
3010 int fixup_exception(struct pt_regs *regs)
3011 {
3012 const struct exception_table_entry *fix;
3013 @@ -192,8 +303,33 @@ good_area:
3014
3015 acc_type = parisc_acctyp(code,regs->iir);
3016
3017 - if ((vma->vm_flags & acc_type) != acc_type)
3018 + if ((vma->vm_flags & acc_type) != acc_type) {
3019 +
3020 +#ifdef CONFIG_PAX_PAGEEXEC
3021 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3022 + (address & ~3UL) == instruction_pointer(regs))
3023 + {
3024 + up_read(&mm->mmap_sem);
3025 + switch (pax_handle_fetch_fault(regs)) {
3026 +
3027 +#ifdef CONFIG_PAX_EMUPLT
3028 + case 3:
3029 + return;
3030 +#endif
3031 +
3032 +#ifdef CONFIG_PAX_EMUTRAMP
3033 + case 2:
3034 + return;
3035 +#endif
3036 +
3037 + }
3038 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3039 + do_group_exit(SIGKILL);
3040 + }
3041 +#endif
3042 +
3043 goto bad_area;
3044 + }
3045
3046 /*
3047 * If for any reason at all we couldn't handle the fault, make
3048 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3049 index 02e41b5..ec6e26c 100644
3050 --- a/arch/powerpc/include/asm/atomic.h
3051 +++ b/arch/powerpc/include/asm/atomic.h
3052 @@ -469,6 +469,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3053
3054 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3055
3056 +#define atomic64_read_unchecked(v) atomic64_read(v)
3057 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3058 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3059 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3060 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3061 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3062 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3063 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3064 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3065 +
3066 #endif /* __powerpc64__ */
3067
3068 #endif /* __KERNEL__ */
3069 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3070 index 4b50941..5605819 100644
3071 --- a/arch/powerpc/include/asm/cache.h
3072 +++ b/arch/powerpc/include/asm/cache.h
3073 @@ -3,6 +3,7 @@
3074
3075 #ifdef __KERNEL__
3076
3077 +#include <linux/const.h>
3078
3079 /* bytes per L1 cache line */
3080 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3081 @@ -22,7 +23,7 @@
3082 #define L1_CACHE_SHIFT 7
3083 #endif
3084
3085 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3086 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3087
3088 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3089
3090 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3091 index 3bf9cca..e7457d0 100644
3092 --- a/arch/powerpc/include/asm/elf.h
3093 +++ b/arch/powerpc/include/asm/elf.h
3094 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3095 the loader. We need to make sure that it is out of the way of the program
3096 that it will "exec", and that there is sufficient room for the brk. */
3097
3098 -extern unsigned long randomize_et_dyn(unsigned long base);
3099 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3100 +#define ELF_ET_DYN_BASE (0x20000000)
3101 +
3102 +#ifdef CONFIG_PAX_ASLR
3103 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3104 +
3105 +#ifdef __powerpc64__
3106 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3107 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3108 +#else
3109 +#define PAX_DELTA_MMAP_LEN 15
3110 +#define PAX_DELTA_STACK_LEN 15
3111 +#endif
3112 +#endif
3113
3114 /*
3115 * Our registers are always unsigned longs, whether we're a 32 bit
3116 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3117 (0x7ff >> (PAGE_SHIFT - 12)) : \
3118 (0x3ffff >> (PAGE_SHIFT - 12)))
3119
3120 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3121 -#define arch_randomize_brk arch_randomize_brk
3122 -
3123 #endif /* __KERNEL__ */
3124
3125 /*
3126 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3127 index bca8fdc..61e9580 100644
3128 --- a/arch/powerpc/include/asm/kmap_types.h
3129 +++ b/arch/powerpc/include/asm/kmap_types.h
3130 @@ -27,6 +27,7 @@ enum km_type {
3131 KM_PPC_SYNC_PAGE,
3132 KM_PPC_SYNC_ICACHE,
3133 KM_KDB,
3134 + KM_CLEARPAGE,
3135 KM_TYPE_NR
3136 };
3137
3138 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3139 index d4a7f64..451de1c 100644
3140 --- a/arch/powerpc/include/asm/mman.h
3141 +++ b/arch/powerpc/include/asm/mman.h
3142 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3143 }
3144 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3145
3146 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3147 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3148 {
3149 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3150 }
3151 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3152 index dd9c4fd..a2ced87 100644
3153 --- a/arch/powerpc/include/asm/page.h
3154 +++ b/arch/powerpc/include/asm/page.h
3155 @@ -141,8 +141,9 @@ extern phys_addr_t kernstart_addr;
3156 * and needs to be executable. This means the whole heap ends
3157 * up being executable.
3158 */
3159 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3160 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3161 +#define VM_DATA_DEFAULT_FLAGS32 \
3162 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3163 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3164
3165 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3166 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3167 @@ -170,6 +171,9 @@ extern phys_addr_t kernstart_addr;
3168 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3169 #endif
3170
3171 +#define ktla_ktva(addr) (addr)
3172 +#define ktva_ktla(addr) (addr)
3173 +
3174 /*
3175 * Use the top bit of the higher-level page table entries to indicate whether
3176 * the entries we point to contain hugepages. This works because we know that
3177 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3178 index fb40ede..d3ce956 100644
3179 --- a/arch/powerpc/include/asm/page_64.h
3180 +++ b/arch/powerpc/include/asm/page_64.h
3181 @@ -144,15 +144,18 @@ do { \
3182 * stack by default, so in the absence of a PT_GNU_STACK program header
3183 * we turn execute permission off.
3184 */
3185 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3186 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3187 +#define VM_STACK_DEFAULT_FLAGS32 \
3188 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3189 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3190
3191 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3192 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3193
3194 +#ifndef CONFIG_PAX_PAGEEXEC
3195 #define VM_STACK_DEFAULT_FLAGS \
3196 (is_32bit_task() ? \
3197 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3198 +#endif
3199
3200 #include <asm-generic/getorder.h>
3201
3202 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3203 index 88b0bd9..e32bc67 100644
3204 --- a/arch/powerpc/include/asm/pgtable.h
3205 +++ b/arch/powerpc/include/asm/pgtable.h
3206 @@ -2,6 +2,7 @@
3207 #define _ASM_POWERPC_PGTABLE_H
3208 #ifdef __KERNEL__
3209
3210 +#include <linux/const.h>
3211 #ifndef __ASSEMBLY__
3212 #include <asm/processor.h> /* For TASK_SIZE */
3213 #include <asm/mmu.h>
3214 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3215 index 4aad413..85d86bf 100644
3216 --- a/arch/powerpc/include/asm/pte-hash32.h
3217 +++ b/arch/powerpc/include/asm/pte-hash32.h
3218 @@ -21,6 +21,7 @@
3219 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3220 #define _PAGE_USER 0x004 /* usermode access allowed */
3221 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3222 +#define _PAGE_EXEC _PAGE_GUARDED
3223 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3224 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3225 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3226 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3227 index 559da19..7e5835c 100644
3228 --- a/arch/powerpc/include/asm/reg.h
3229 +++ b/arch/powerpc/include/asm/reg.h
3230 @@ -212,6 +212,7 @@
3231 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3232 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3233 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3234 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3235 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3236 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3237 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3238 diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h
3239 index e30a13d..2b7d994 100644
3240 --- a/arch/powerpc/include/asm/system.h
3241 +++ b/arch/powerpc/include/asm/system.h
3242 @@ -530,7 +530,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
3243 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
3244 #endif
3245
3246 -extern unsigned long arch_align_stack(unsigned long sp);
3247 +#define arch_align_stack(x) ((x) & ~0xfUL)
3248
3249 /* Used in very early kernel initialization. */
3250 extern unsigned long reloc_offset(void);
3251 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3252 index bd0fb84..a42a14b 100644
3253 --- a/arch/powerpc/include/asm/uaccess.h
3254 +++ b/arch/powerpc/include/asm/uaccess.h
3255 @@ -13,6 +13,8 @@
3256 #define VERIFY_READ 0
3257 #define VERIFY_WRITE 1
3258
3259 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3260 +
3261 /*
3262 * The fs value determines whether argument validity checking should be
3263 * performed or not. If get_fs() == USER_DS, checking is performed, with
3264 @@ -327,52 +329,6 @@ do { \
3265 extern unsigned long __copy_tofrom_user(void __user *to,
3266 const void __user *from, unsigned long size);
3267
3268 -#ifndef __powerpc64__
3269 -
3270 -static inline unsigned long copy_from_user(void *to,
3271 - const void __user *from, unsigned long n)
3272 -{
3273 - unsigned long over;
3274 -
3275 - if (access_ok(VERIFY_READ, from, n))
3276 - return __copy_tofrom_user((__force void __user *)to, from, n);
3277 - if ((unsigned long)from < TASK_SIZE) {
3278 - over = (unsigned long)from + n - TASK_SIZE;
3279 - return __copy_tofrom_user((__force void __user *)to, from,
3280 - n - over) + over;
3281 - }
3282 - return n;
3283 -}
3284 -
3285 -static inline unsigned long copy_to_user(void __user *to,
3286 - const void *from, unsigned long n)
3287 -{
3288 - unsigned long over;
3289 -
3290 - if (access_ok(VERIFY_WRITE, to, n))
3291 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3292 - if ((unsigned long)to < TASK_SIZE) {
3293 - over = (unsigned long)to + n - TASK_SIZE;
3294 - return __copy_tofrom_user(to, (__force void __user *)from,
3295 - n - over) + over;
3296 - }
3297 - return n;
3298 -}
3299 -
3300 -#else /* __powerpc64__ */
3301 -
3302 -#define __copy_in_user(to, from, size) \
3303 - __copy_tofrom_user((to), (from), (size))
3304 -
3305 -extern unsigned long copy_from_user(void *to, const void __user *from,
3306 - unsigned long n);
3307 -extern unsigned long copy_to_user(void __user *to, const void *from,
3308 - unsigned long n);
3309 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
3310 - unsigned long n);
3311 -
3312 -#endif /* __powerpc64__ */
3313 -
3314 static inline unsigned long __copy_from_user_inatomic(void *to,
3315 const void __user *from, unsigned long n)
3316 {
3317 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
3318 if (ret == 0)
3319 return 0;
3320 }
3321 +
3322 + if (!__builtin_constant_p(n))
3323 + check_object_size(to, n, false);
3324 +
3325 return __copy_tofrom_user((__force void __user *)to, from, n);
3326 }
3327
3328 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
3329 if (ret == 0)
3330 return 0;
3331 }
3332 +
3333 + if (!__builtin_constant_p(n))
3334 + check_object_size(from, n, true);
3335 +
3336 return __copy_tofrom_user(to, (__force const void __user *)from, n);
3337 }
3338
3339 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
3340 return __copy_to_user_inatomic(to, from, size);
3341 }
3342
3343 +#ifndef __powerpc64__
3344 +
3345 +static inline unsigned long __must_check copy_from_user(void *to,
3346 + const void __user *from, unsigned long n)
3347 +{
3348 + unsigned long over;
3349 +
3350 + if ((long)n < 0)
3351 + return n;
3352 +
3353 + if (access_ok(VERIFY_READ, from, n)) {
3354 + if (!__builtin_constant_p(n))
3355 + check_object_size(to, n, false);
3356 + return __copy_tofrom_user((__force void __user *)to, from, n);
3357 + }
3358 + if ((unsigned long)from < TASK_SIZE) {
3359 + over = (unsigned long)from + n - TASK_SIZE;
3360 + if (!__builtin_constant_p(n - over))
3361 + check_object_size(to, n - over, false);
3362 + return __copy_tofrom_user((__force void __user *)to, from,
3363 + n - over) + over;
3364 + }
3365 + return n;
3366 +}
3367 +
3368 +static inline unsigned long __must_check copy_to_user(void __user *to,
3369 + const void *from, unsigned long n)
3370 +{
3371 + unsigned long over;
3372 +
3373 + if ((long)n < 0)
3374 + return n;
3375 +
3376 + if (access_ok(VERIFY_WRITE, to, n)) {
3377 + if (!__builtin_constant_p(n))
3378 + check_object_size(from, n, true);
3379 + return __copy_tofrom_user(to, (__force void __user *)from, n);
3380 + }
3381 + if ((unsigned long)to < TASK_SIZE) {
3382 + over = (unsigned long)to + n - TASK_SIZE;
3383 + if (!__builtin_constant_p(n))
3384 + check_object_size(from, n - over, true);
3385 + return __copy_tofrom_user(to, (__force void __user *)from,
3386 + n - over) + over;
3387 + }
3388 + return n;
3389 +}
3390 +
3391 +#else /* __powerpc64__ */
3392 +
3393 +#define __copy_in_user(to, from, size) \
3394 + __copy_tofrom_user((to), (from), (size))
3395 +
3396 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
3397 +{
3398 + if ((long)n < 0 || n > INT_MAX)
3399 + return n;
3400 +
3401 + if (!__builtin_constant_p(n))
3402 + check_object_size(to, n, false);
3403 +
3404 + if (likely(access_ok(VERIFY_READ, from, n)))
3405 + n = __copy_from_user(to, from, n);
3406 + else
3407 + memset(to, 0, n);
3408 + return n;
3409 +}
3410 +
3411 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
3412 +{
3413 + if ((long)n < 0 || n > INT_MAX)
3414 + return n;
3415 +
3416 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
3417 + if (!__builtin_constant_p(n))
3418 + check_object_size(from, n, true);
3419 + n = __copy_to_user(to, from, n);
3420 + }
3421 + return n;
3422 +}
3423 +
3424 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
3425 + unsigned long n);
3426 +
3427 +#endif /* __powerpc64__ */
3428 +
3429 extern unsigned long __clear_user(void __user *addr, unsigned long size);
3430
3431 static inline unsigned long clear_user(void __user *addr, unsigned long size)
3432 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
3433 index 429983c..7af363b 100644
3434 --- a/arch/powerpc/kernel/exceptions-64e.S
3435 +++ b/arch/powerpc/kernel/exceptions-64e.S
3436 @@ -587,6 +587,7 @@ storage_fault_common:
3437 std r14,_DAR(r1)
3438 std r15,_DSISR(r1)
3439 addi r3,r1,STACK_FRAME_OVERHEAD
3440 + bl .save_nvgprs
3441 mr r4,r14
3442 mr r5,r15
3443 ld r14,PACA_EXGEN+EX_R14(r13)
3444 @@ -596,8 +597,7 @@ storage_fault_common:
3445 cmpdi r3,0
3446 bne- 1f
3447 b .ret_from_except_lite
3448 -1: bl .save_nvgprs
3449 - mr r5,r3
3450 +1: mr r5,r3
3451 addi r3,r1,STACK_FRAME_OVERHEAD
3452 ld r4,_DAR(r1)
3453 bl .bad_page_fault
3454 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
3455 index cf9c69b..ebc9640 100644
3456 --- a/arch/powerpc/kernel/exceptions-64s.S
3457 +++ b/arch/powerpc/kernel/exceptions-64s.S
3458 @@ -1004,10 +1004,10 @@ handle_page_fault:
3459 11: ld r4,_DAR(r1)
3460 ld r5,_DSISR(r1)
3461 addi r3,r1,STACK_FRAME_OVERHEAD
3462 + bl .save_nvgprs
3463 bl .do_page_fault
3464 cmpdi r3,0
3465 beq+ 13f
3466 - bl .save_nvgprs
3467 mr r5,r3
3468 addi r3,r1,STACK_FRAME_OVERHEAD
3469 lwz r4,_DAR(r1)
3470 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
3471 index 745c1e7..59d97a6 100644
3472 --- a/arch/powerpc/kernel/irq.c
3473 +++ b/arch/powerpc/kernel/irq.c
3474 @@ -547,9 +547,6 @@ struct irq_host *irq_alloc_host(struct device_node *of_node,
3475 host->ops = ops;
3476 host->of_node = of_node_get(of_node);
3477
3478 - if (host->ops->match == NULL)
3479 - host->ops->match = default_irq_host_match;
3480 -
3481 raw_spin_lock_irqsave(&irq_big_lock, flags);
3482
3483 /* If it's a legacy controller, check for duplicates and
3484 @@ -622,7 +619,12 @@ struct irq_host *irq_find_host(struct device_node *node)
3485 */
3486 raw_spin_lock_irqsave(&irq_big_lock, flags);
3487 list_for_each_entry(h, &irq_hosts, link)
3488 - if (h->ops->match(h, node)) {
3489 + if (h->ops->match) {
3490 + if (h->ops->match(h, node)) {
3491 + found = h;
3492 + break;
3493 + }
3494 + } else if (default_irq_host_match(h, node)) {
3495 found = h;
3496 break;
3497 }
3498 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
3499 index 0b6d796..d760ddb 100644
3500 --- a/arch/powerpc/kernel/module_32.c
3501 +++ b/arch/powerpc/kernel/module_32.c
3502 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
3503 me->arch.core_plt_section = i;
3504 }
3505 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
3506 - printk("Module doesn't contain .plt or .init.plt sections.\n");
3507 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
3508 return -ENOEXEC;
3509 }
3510
3511 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
3512
3513 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
3514 /* Init, or core PLT? */
3515 - if (location >= mod->module_core
3516 - && location < mod->module_core + mod->core_size)
3517 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
3518 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
3519 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
3520 - else
3521 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
3522 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
3523 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
3524 + else {
3525 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
3526 + return ~0UL;
3527 + }
3528
3529 /* Find this entry, or if that fails, the next avail. entry */
3530 while (entry->jump[0]) {
3531 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
3532 index 6457574..08b28d3 100644
3533 --- a/arch/powerpc/kernel/process.c
3534 +++ b/arch/powerpc/kernel/process.c
3535 @@ -660,8 +660,8 @@ void show_regs(struct pt_regs * regs)
3536 * Lookup NIP late so we have the best change of getting the
3537 * above info out without failing
3538 */
3539 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
3540 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
3541 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
3542 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
3543 #endif
3544 show_stack(current, (unsigned long *) regs->gpr[1]);
3545 if (!user_mode(regs))
3546 @@ -1165,10 +1165,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
3547 newsp = stack[0];
3548 ip = stack[STACK_FRAME_LR_SAVE];
3549 if (!firstframe || ip != lr) {
3550 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
3551 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
3552 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3553 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
3554 - printk(" (%pS)",
3555 + printk(" (%pA)",
3556 (void *)current->ret_stack[curr_frame].ret);
3557 curr_frame--;
3558 }
3559 @@ -1188,7 +1188,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
3560 struct pt_regs *regs = (struct pt_regs *)
3561 (sp + STACK_FRAME_OVERHEAD);
3562 lr = regs->link;
3563 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
3564 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
3565 regs->trap, (void *)regs->nip, (void *)lr);
3566 firstframe = 1;
3567 }
3568 @@ -1263,58 +1263,3 @@ void thread_info_cache_init(void)
3569 }
3570
3571 #endif /* THREAD_SHIFT < PAGE_SHIFT */
3572 -
3573 -unsigned long arch_align_stack(unsigned long sp)
3574 -{
3575 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3576 - sp -= get_random_int() & ~PAGE_MASK;
3577 - return sp & ~0xf;
3578 -}
3579 -
3580 -static inline unsigned long brk_rnd(void)
3581 -{
3582 - unsigned long rnd = 0;
3583 -
3584 - /* 8MB for 32bit, 1GB for 64bit */
3585 - if (is_32bit_task())
3586 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
3587 - else
3588 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
3589 -
3590 - return rnd << PAGE_SHIFT;
3591 -}
3592 -
3593 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3594 -{
3595 - unsigned long base = mm->brk;
3596 - unsigned long ret;
3597 -
3598 -#ifdef CONFIG_PPC_STD_MMU_64
3599 - /*
3600 - * If we are using 1TB segments and we are allowed to randomise
3601 - * the heap, we can put it above 1TB so it is backed by a 1TB
3602 - * segment. Otherwise the heap will be in the bottom 1TB
3603 - * which always uses 256MB segments and this may result in a
3604 - * performance penalty.
3605 - */
3606 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
3607 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
3608 -#endif
3609 -
3610 - ret = PAGE_ALIGN(base + brk_rnd());
3611 -
3612 - if (ret < mm->brk)
3613 - return mm->brk;
3614 -
3615 - return ret;
3616 -}
3617 -
3618 -unsigned long randomize_et_dyn(unsigned long base)
3619 -{
3620 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
3621 -
3622 - if (ret < base)
3623 - return base;
3624 -
3625 - return ret;
3626 -}
3627 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
3628 index 836a5a1..27289a3 100644
3629 --- a/arch/powerpc/kernel/signal_32.c
3630 +++ b/arch/powerpc/kernel/signal_32.c
3631 @@ -859,7 +859,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
3632 /* Save user registers on the stack */
3633 frame = &rt_sf->uc.uc_mcontext;
3634 addr = frame;
3635 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
3636 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3637 if (save_user_regs(regs, frame, 0, 1))
3638 goto badframe;
3639 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
3640 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
3641 index a50b5ec..547078a 100644
3642 --- a/arch/powerpc/kernel/signal_64.c
3643 +++ b/arch/powerpc/kernel/signal_64.c
3644 @@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
3645 current->thread.fpscr.val = 0;
3646
3647 /* Set up to return from userspace. */
3648 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
3649 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3650 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
3651 } else {
3652 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
3653 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
3654 index 5459d14..10f8070 100644
3655 --- a/arch/powerpc/kernel/traps.c
3656 +++ b/arch/powerpc/kernel/traps.c
3657 @@ -98,6 +98,8 @@ static void pmac_backlight_unblank(void)
3658 static inline void pmac_backlight_unblank(void) { }
3659 #endif
3660
3661 +extern void gr_handle_kernel_exploit(void);
3662 +
3663 int die(const char *str, struct pt_regs *regs, long err)
3664 {
3665 static struct {
3666 @@ -171,6 +173,8 @@ int die(const char *str, struct pt_regs *regs, long err)
3667 if (panic_on_oops)
3668 panic("Fatal exception");
3669
3670 + gr_handle_kernel_exploit();
3671 +
3672 oops_exit();
3673 do_exit(err);
3674
3675 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
3676 index 7d14bb6..1305601 100644
3677 --- a/arch/powerpc/kernel/vdso.c
3678 +++ b/arch/powerpc/kernel/vdso.c
3679 @@ -35,6 +35,7 @@
3680 #include <asm/firmware.h>
3681 #include <asm/vdso.h>
3682 #include <asm/vdso_datapage.h>
3683 +#include <asm/mman.h>
3684
3685 #include "setup.h"
3686
3687 @@ -219,7 +220,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3688 vdso_base = VDSO32_MBASE;
3689 #endif
3690
3691 - current->mm->context.vdso_base = 0;
3692 + current->mm->context.vdso_base = ~0UL;
3693
3694 /* vDSO has a problem and was disabled, just don't "enable" it for the
3695 * process
3696 @@ -239,7 +240,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3697 vdso_base = get_unmapped_area(NULL, vdso_base,
3698 (vdso_pages << PAGE_SHIFT) +
3699 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
3700 - 0, 0);
3701 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
3702 if (IS_ERR_VALUE(vdso_base)) {
3703 rc = vdso_base;
3704 goto fail_mmapsem;
3705 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
3706 index 5eea6f3..5d10396 100644
3707 --- a/arch/powerpc/lib/usercopy_64.c
3708 +++ b/arch/powerpc/lib/usercopy_64.c
3709 @@ -9,22 +9,6 @@
3710 #include <linux/module.h>
3711 #include <asm/uaccess.h>
3712
3713 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
3714 -{
3715 - if (likely(access_ok(VERIFY_READ, from, n)))
3716 - n = __copy_from_user(to, from, n);
3717 - else
3718 - memset(to, 0, n);
3719 - return n;
3720 -}
3721 -
3722 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
3723 -{
3724 - if (likely(access_ok(VERIFY_WRITE, to, n)))
3725 - n = __copy_to_user(to, from, n);
3726 - return n;
3727 -}
3728 -
3729 unsigned long copy_in_user(void __user *to, const void __user *from,
3730 unsigned long n)
3731 {
3732 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
3733 return n;
3734 }
3735
3736 -EXPORT_SYMBOL(copy_from_user);
3737 -EXPORT_SYMBOL(copy_to_user);
3738 EXPORT_SYMBOL(copy_in_user);
3739
3740 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
3741 index 5efe8c9..db9ceef 100644
3742 --- a/arch/powerpc/mm/fault.c
3743 +++ b/arch/powerpc/mm/fault.c
3744 @@ -32,6 +32,10 @@
3745 #include <linux/perf_event.h>
3746 #include <linux/magic.h>
3747 #include <linux/ratelimit.h>
3748 +#include <linux/slab.h>
3749 +#include <linux/pagemap.h>
3750 +#include <linux/compiler.h>
3751 +#include <linux/unistd.h>
3752
3753 #include <asm/firmware.h>
3754 #include <asm/page.h>
3755 @@ -43,6 +47,7 @@
3756 #include <asm/tlbflush.h>
3757 #include <asm/siginfo.h>
3758 #include <mm/mmu_decl.h>
3759 +#include <asm/ptrace.h>
3760
3761 #ifdef CONFIG_KPROBES
3762 static inline int notify_page_fault(struct pt_regs *regs)
3763 @@ -66,6 +71,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
3764 }
3765 #endif
3766
3767 +#ifdef CONFIG_PAX_PAGEEXEC
3768 +/*
3769 + * PaX: decide what to do with offenders (regs->nip = fault address)
3770 + *
3771 + * returns 1 when task should be killed
3772 + */
3773 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3774 +{
3775 + return 1;
3776 +}
3777 +
3778 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3779 +{
3780 + unsigned long i;
3781 +
3782 + printk(KERN_ERR "PAX: bytes at PC: ");
3783 + for (i = 0; i < 5; i++) {
3784 + unsigned int c;
3785 + if (get_user(c, (unsigned int __user *)pc+i))
3786 + printk(KERN_CONT "???????? ");
3787 + else
3788 + printk(KERN_CONT "%08x ", c);
3789 + }
3790 + printk("\n");
3791 +}
3792 +#endif
3793 +
3794 /*
3795 * Check whether the instruction at regs->nip is a store using
3796 * an update addressing form which will update r1.
3797 @@ -136,7 +168,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
3798 * indicate errors in DSISR but can validly be set in SRR1.
3799 */
3800 if (trap == 0x400)
3801 - error_code &= 0x48200000;
3802 + error_code &= 0x58200000;
3803 else
3804 is_write = error_code & DSISR_ISSTORE;
3805 #else
3806 @@ -259,7 +291,7 @@ good_area:
3807 * "undefined". Of those that can be set, this is the only
3808 * one which seems bad.
3809 */
3810 - if (error_code & 0x10000000)
3811 + if (error_code & DSISR_GUARDED)
3812 /* Guarded storage error. */
3813 goto bad_area;
3814 #endif /* CONFIG_8xx */
3815 @@ -274,7 +306,7 @@ good_area:
3816 * processors use the same I/D cache coherency mechanism
3817 * as embedded.
3818 */
3819 - if (error_code & DSISR_PROTFAULT)
3820 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
3821 goto bad_area;
3822 #endif /* CONFIG_PPC_STD_MMU */
3823
3824 @@ -343,6 +375,23 @@ bad_area:
3825 bad_area_nosemaphore:
3826 /* User mode accesses cause a SIGSEGV */
3827 if (user_mode(regs)) {
3828 +
3829 +#ifdef CONFIG_PAX_PAGEEXEC
3830 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
3831 +#ifdef CONFIG_PPC_STD_MMU
3832 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
3833 +#else
3834 + if (is_exec && regs->nip == address) {
3835 +#endif
3836 + switch (pax_handle_fetch_fault(regs)) {
3837 + }
3838 +
3839 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
3840 + do_group_exit(SIGKILL);
3841 + }
3842 + }
3843 +#endif
3844 +
3845 _exception(SIGSEGV, regs, code, address);
3846 return 0;
3847 }
3848 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
3849 index 5a783d8..c23e14b 100644
3850 --- a/arch/powerpc/mm/mmap_64.c
3851 +++ b/arch/powerpc/mm/mmap_64.c
3852 @@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3853 */
3854 if (mmap_is_legacy()) {
3855 mm->mmap_base = TASK_UNMAPPED_BASE;
3856 +
3857 +#ifdef CONFIG_PAX_RANDMMAP
3858 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3859 + mm->mmap_base += mm->delta_mmap;
3860 +#endif
3861 +
3862 mm->get_unmapped_area = arch_get_unmapped_area;
3863 mm->unmap_area = arch_unmap_area;
3864 } else {
3865 mm->mmap_base = mmap_base();
3866 +
3867 +#ifdef CONFIG_PAX_RANDMMAP
3868 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3869 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3870 +#endif
3871 +
3872 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3873 mm->unmap_area = arch_unmap_area_topdown;
3874 }
3875 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
3876 index 73709f7..6b90313 100644
3877 --- a/arch/powerpc/mm/slice.c
3878 +++ b/arch/powerpc/mm/slice.c
3879 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
3880 if ((mm->task_size - len) < addr)
3881 return 0;
3882 vma = find_vma(mm, addr);
3883 - return (!vma || (addr + len) <= vma->vm_start);
3884 + return check_heap_stack_gap(vma, addr, len);
3885 }
3886
3887 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
3888 @@ -256,7 +256,7 @@ full_search:
3889 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
3890 continue;
3891 }
3892 - if (!vma || addr + len <= vma->vm_start) {
3893 + if (check_heap_stack_gap(vma, addr, len)) {
3894 /*
3895 * Remember the place where we stopped the search:
3896 */
3897 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
3898 }
3899 }
3900
3901 - addr = mm->mmap_base;
3902 - while (addr > len) {
3903 + if (mm->mmap_base < len)
3904 + addr = -ENOMEM;
3905 + else
3906 + addr = mm->mmap_base - len;
3907 +
3908 + while (!IS_ERR_VALUE(addr)) {
3909 /* Go down by chunk size */
3910 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
3911 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
3912
3913 /* Check for hit with different page size */
3914 mask = slice_range_to_mask(addr, len);
3915 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
3916 * return with success:
3917 */
3918 vma = find_vma(mm, addr);
3919 - if (!vma || (addr + len) <= vma->vm_start) {
3920 + if (check_heap_stack_gap(vma, addr, len)) {
3921 /* remember the address as a hint for next time */
3922 if (use_cache)
3923 mm->free_area_cache = addr;
3924 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
3925 mm->cached_hole_size = vma->vm_start - addr;
3926
3927 /* try just below the current vma->vm_start */
3928 - addr = vma->vm_start;
3929 + addr = skip_heap_stack_gap(vma, len);
3930 }
3931
3932 /*
3933 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
3934 if (fixed && addr > (mm->task_size - len))
3935 return -EINVAL;
3936
3937 +#ifdef CONFIG_PAX_RANDMMAP
3938 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
3939 + addr = 0;
3940 +#endif
3941 +
3942 /* If hint, make sure it matches our alignment restrictions */
3943 if (!fixed && addr) {
3944 addr = _ALIGN_UP(addr, 1ul << pshift);
3945 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
3946 index 8517d2a..d2738d4 100644
3947 --- a/arch/s390/include/asm/atomic.h
3948 +++ b/arch/s390/include/asm/atomic.h
3949 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
3950 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
3951 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3952
3953 +#define atomic64_read_unchecked(v) atomic64_read(v)
3954 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3955 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3956 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3957 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3958 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3959 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3960 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3961 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3962 +
3963 #define smp_mb__before_atomic_dec() smp_mb()
3964 #define smp_mb__after_atomic_dec() smp_mb()
3965 #define smp_mb__before_atomic_inc() smp_mb()
3966 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
3967 index 2a30d5a..5e5586f 100644
3968 --- a/arch/s390/include/asm/cache.h
3969 +++ b/arch/s390/include/asm/cache.h
3970 @@ -11,8 +11,10 @@
3971 #ifndef __ARCH_S390_CACHE_H
3972 #define __ARCH_S390_CACHE_H
3973
3974 -#define L1_CACHE_BYTES 256
3975 +#include <linux/const.h>
3976 +
3977 #define L1_CACHE_SHIFT 8
3978 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3979 #define NET_SKB_PAD 32
3980
3981 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
3982 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
3983 index 547f1a6..0b22b53 100644
3984 --- a/arch/s390/include/asm/elf.h
3985 +++ b/arch/s390/include/asm/elf.h
3986 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
3987 the loader. We need to make sure that it is out of the way of the program
3988 that it will "exec", and that there is sufficient room for the brk. */
3989
3990 -extern unsigned long randomize_et_dyn(unsigned long base);
3991 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
3992 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
3993 +
3994 +#ifdef CONFIG_PAX_ASLR
3995 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
3996 +
3997 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
3998 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
3999 +#endif
4000
4001 /* This yields a mask that user programs can use to figure out what
4002 instruction set this CPU supports. */
4003 @@ -211,7 +217,4 @@ struct linux_binprm;
4004 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4005 int arch_setup_additional_pages(struct linux_binprm *, int);
4006
4007 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4008 -#define arch_randomize_brk arch_randomize_brk
4009 -
4010 #endif
4011 diff --git a/arch/s390/include/asm/system.h b/arch/s390/include/asm/system.h
4012 index ef573c1..75a1ce6 100644
4013 --- a/arch/s390/include/asm/system.h
4014 +++ b/arch/s390/include/asm/system.h
4015 @@ -262,7 +262,7 @@ extern void (*_machine_restart)(char *command);
4016 extern void (*_machine_halt)(void);
4017 extern void (*_machine_power_off)(void);
4018
4019 -extern unsigned long arch_align_stack(unsigned long sp);
4020 +#define arch_align_stack(x) ((x) & ~0xfUL)
4021
4022 static inline int tprot(unsigned long addr)
4023 {
4024 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4025 index 2b23885..e136e31 100644
4026 --- a/arch/s390/include/asm/uaccess.h
4027 +++ b/arch/s390/include/asm/uaccess.h
4028 @@ -235,6 +235,10 @@ static inline unsigned long __must_check
4029 copy_to_user(void __user *to, const void *from, unsigned long n)
4030 {
4031 might_fault();
4032 +
4033 + if ((long)n < 0)
4034 + return n;
4035 +
4036 if (access_ok(VERIFY_WRITE, to, n))
4037 n = __copy_to_user(to, from, n);
4038 return n;
4039 @@ -260,6 +264,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4040 static inline unsigned long __must_check
4041 __copy_from_user(void *to, const void __user *from, unsigned long n)
4042 {
4043 + if ((long)n < 0)
4044 + return n;
4045 +
4046 if (__builtin_constant_p(n) && (n <= 256))
4047 return uaccess.copy_from_user_small(n, from, to);
4048 else
4049 @@ -294,6 +301,10 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
4050 unsigned int sz = __compiletime_object_size(to);
4051
4052 might_fault();
4053 +
4054 + if ((long)n < 0)
4055 + return n;
4056 +
4057 if (unlikely(sz != -1 && sz < n)) {
4058 copy_from_user_overflow();
4059 return n;
4060 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4061 index dfcb343..eda788a 100644
4062 --- a/arch/s390/kernel/module.c
4063 +++ b/arch/s390/kernel/module.c
4064 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4065
4066 /* Increase core size by size of got & plt and set start
4067 offsets for got and plt. */
4068 - me->core_size = ALIGN(me->core_size, 4);
4069 - me->arch.got_offset = me->core_size;
4070 - me->core_size += me->arch.got_size;
4071 - me->arch.plt_offset = me->core_size;
4072 - me->core_size += me->arch.plt_size;
4073 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4074 + me->arch.got_offset = me->core_size_rw;
4075 + me->core_size_rw += me->arch.got_size;
4076 + me->arch.plt_offset = me->core_size_rx;
4077 + me->core_size_rx += me->arch.plt_size;
4078 return 0;
4079 }
4080
4081 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4082 if (info->got_initialized == 0) {
4083 Elf_Addr *gotent;
4084
4085 - gotent = me->module_core + me->arch.got_offset +
4086 + gotent = me->module_core_rw + me->arch.got_offset +
4087 info->got_offset;
4088 *gotent = val;
4089 info->got_initialized = 1;
4090 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4091 else if (r_type == R_390_GOTENT ||
4092 r_type == R_390_GOTPLTENT)
4093 *(unsigned int *) loc =
4094 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4095 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4096 else if (r_type == R_390_GOT64 ||
4097 r_type == R_390_GOTPLT64)
4098 *(unsigned long *) loc = val;
4099 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4100 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4101 if (info->plt_initialized == 0) {
4102 unsigned int *ip;
4103 - ip = me->module_core + me->arch.plt_offset +
4104 + ip = me->module_core_rx + me->arch.plt_offset +
4105 info->plt_offset;
4106 #ifndef CONFIG_64BIT
4107 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4108 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4109 val - loc + 0xffffUL < 0x1ffffeUL) ||
4110 (r_type == R_390_PLT32DBL &&
4111 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4112 - val = (Elf_Addr) me->module_core +
4113 + val = (Elf_Addr) me->module_core_rx +
4114 me->arch.plt_offset +
4115 info->plt_offset;
4116 val += rela->r_addend - loc;
4117 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4118 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4119 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4120 val = val + rela->r_addend -
4121 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4122 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4123 if (r_type == R_390_GOTOFF16)
4124 *(unsigned short *) loc = val;
4125 else if (r_type == R_390_GOTOFF32)
4126 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4127 break;
4128 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4129 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4130 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4131 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4132 rela->r_addend - loc;
4133 if (r_type == R_390_GOTPC)
4134 *(unsigned int *) loc = val;
4135 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4136 index 9451b21..ed8956f 100644
4137 --- a/arch/s390/kernel/process.c
4138 +++ b/arch/s390/kernel/process.c
4139 @@ -321,39 +321,3 @@ unsigned long get_wchan(struct task_struct *p)
4140 }
4141 return 0;
4142 }
4143 -
4144 -unsigned long arch_align_stack(unsigned long sp)
4145 -{
4146 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4147 - sp -= get_random_int() & ~PAGE_MASK;
4148 - return sp & ~0xf;
4149 -}
4150 -
4151 -static inline unsigned long brk_rnd(void)
4152 -{
4153 - /* 8MB for 32bit, 1GB for 64bit */
4154 - if (is_32bit_task())
4155 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4156 - else
4157 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4158 -}
4159 -
4160 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4161 -{
4162 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4163 -
4164 - if (ret < mm->brk)
4165 - return mm->brk;
4166 - return ret;
4167 -}
4168 -
4169 -unsigned long randomize_et_dyn(unsigned long base)
4170 -{
4171 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4172 -
4173 - if (!(current->flags & PF_RANDOMIZE))
4174 - return base;
4175 - if (ret < base)
4176 - return base;
4177 - return ret;
4178 -}
4179 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4180 index f09c748..cf9ec1d 100644
4181 --- a/arch/s390/mm/mmap.c
4182 +++ b/arch/s390/mm/mmap.c
4183 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4184 */
4185 if (mmap_is_legacy()) {
4186 mm->mmap_base = TASK_UNMAPPED_BASE;
4187 +
4188 +#ifdef CONFIG_PAX_RANDMMAP
4189 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4190 + mm->mmap_base += mm->delta_mmap;
4191 +#endif
4192 +
4193 mm->get_unmapped_area = arch_get_unmapped_area;
4194 mm->unmap_area = arch_unmap_area;
4195 } else {
4196 mm->mmap_base = mmap_base();
4197 +
4198 +#ifdef CONFIG_PAX_RANDMMAP
4199 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4200 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4201 +#endif
4202 +
4203 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4204 mm->unmap_area = arch_unmap_area_topdown;
4205 }
4206 @@ -167,10 +179,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4207 */
4208 if (mmap_is_legacy()) {
4209 mm->mmap_base = TASK_UNMAPPED_BASE;
4210 +
4211 +#ifdef CONFIG_PAX_RANDMMAP
4212 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4213 + mm->mmap_base += mm->delta_mmap;
4214 +#endif
4215 +
4216 mm->get_unmapped_area = s390_get_unmapped_area;
4217 mm->unmap_area = arch_unmap_area;
4218 } else {
4219 mm->mmap_base = mmap_base();
4220 +
4221 +#ifdef CONFIG_PAX_RANDMMAP
4222 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4223 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4224 +#endif
4225 +
4226 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4227 mm->unmap_area = arch_unmap_area_topdown;
4228 }
4229 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4230 index ae3d59f..f65f075 100644
4231 --- a/arch/score/include/asm/cache.h
4232 +++ b/arch/score/include/asm/cache.h
4233 @@ -1,7 +1,9 @@
4234 #ifndef _ASM_SCORE_CACHE_H
4235 #define _ASM_SCORE_CACHE_H
4236
4237 +#include <linux/const.h>
4238 +
4239 #define L1_CACHE_SHIFT 4
4240 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4241 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4242
4243 #endif /* _ASM_SCORE_CACHE_H */
4244 diff --git a/arch/score/include/asm/system.h b/arch/score/include/asm/system.h
4245 index 589d5c7..669e274 100644
4246 --- a/arch/score/include/asm/system.h
4247 +++ b/arch/score/include/asm/system.h
4248 @@ -17,7 +17,7 @@ do { \
4249 #define finish_arch_switch(prev) do {} while (0)
4250
4251 typedef void (*vi_handler_t)(void);
4252 -extern unsigned long arch_align_stack(unsigned long sp);
4253 +#define arch_align_stack(x) (x)
4254
4255 #define mb() barrier()
4256 #define rmb() barrier()
4257 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4258 index 25d0803..d6c8e36 100644
4259 --- a/arch/score/kernel/process.c
4260 +++ b/arch/score/kernel/process.c
4261 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4262
4263 return task_pt_regs(task)->cp0_epc;
4264 }
4265 -
4266 -unsigned long arch_align_stack(unsigned long sp)
4267 -{
4268 - return sp;
4269 -}
4270 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4271 index ef9e555..331bd29 100644
4272 --- a/arch/sh/include/asm/cache.h
4273 +++ b/arch/sh/include/asm/cache.h
4274 @@ -9,10 +9,11 @@
4275 #define __ASM_SH_CACHE_H
4276 #ifdef __KERNEL__
4277
4278 +#include <linux/const.h>
4279 #include <linux/init.h>
4280 #include <cpu/cache.h>
4281
4282 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4283 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4284
4285 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4286
4287 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4288 index afeb710..d1d1289 100644
4289 --- a/arch/sh/mm/mmap.c
4290 +++ b/arch/sh/mm/mmap.c
4291 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4292 addr = PAGE_ALIGN(addr);
4293
4294 vma = find_vma(mm, addr);
4295 - if (TASK_SIZE - len >= addr &&
4296 - (!vma || addr + len <= vma->vm_start))
4297 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4298 return addr;
4299 }
4300
4301 @@ -106,7 +105,7 @@ full_search:
4302 }
4303 return -ENOMEM;
4304 }
4305 - if (likely(!vma || addr + len <= vma->vm_start)) {
4306 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4307 /*
4308 * Remember the place where we stopped the search:
4309 */
4310 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4311 addr = PAGE_ALIGN(addr);
4312
4313 vma = find_vma(mm, addr);
4314 - if (TASK_SIZE - len >= addr &&
4315 - (!vma || addr + len <= vma->vm_start))
4316 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4317 return addr;
4318 }
4319
4320 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4321 /* make sure it can fit in the remaining address space */
4322 if (likely(addr > len)) {
4323 vma = find_vma(mm, addr-len);
4324 - if (!vma || addr <= vma->vm_start) {
4325 + if (check_heap_stack_gap(vma, addr - len, len)) {
4326 /* remember the address as a hint for next time */
4327 return (mm->free_area_cache = addr-len);
4328 }
4329 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4330 if (unlikely(mm->mmap_base < len))
4331 goto bottomup;
4332
4333 - addr = mm->mmap_base-len;
4334 - if (do_colour_align)
4335 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4336 + addr = mm->mmap_base - len;
4337
4338 do {
4339 + if (do_colour_align)
4340 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4341 /*
4342 * Lookup failure means no vma is above this address,
4343 * else if new region fits below vma->vm_start,
4344 * return with success:
4345 */
4346 vma = find_vma(mm, addr);
4347 - if (likely(!vma || addr+len <= vma->vm_start)) {
4348 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4349 /* remember the address as a hint for next time */
4350 return (mm->free_area_cache = addr);
4351 }
4352 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4353 mm->cached_hole_size = vma->vm_start - addr;
4354
4355 /* try just below the current vma->vm_start */
4356 - addr = vma->vm_start-len;
4357 - if (do_colour_align)
4358 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4359 - } while (likely(len < vma->vm_start));
4360 + addr = skip_heap_stack_gap(vma, len);
4361 + } while (!IS_ERR_VALUE(addr));
4362
4363 bottomup:
4364 /*
4365 diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
4366 index f92602e..27060b2 100644
4367 --- a/arch/sparc/Kconfig
4368 +++ b/arch/sparc/Kconfig
4369 @@ -31,6 +31,7 @@ config SPARC
4370
4371 config SPARC32
4372 def_bool !64BIT
4373 + select GENERIC_ATOMIC64
4374
4375 config SPARC64
4376 def_bool 64BIT
4377 diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
4378 index ad1fb5d..fc5315b 100644
4379 --- a/arch/sparc/Makefile
4380 +++ b/arch/sparc/Makefile
4381 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
4382 # Export what is needed by arch/sparc/boot/Makefile
4383 export VMLINUX_INIT VMLINUX_MAIN
4384 VMLINUX_INIT := $(head-y) $(init-y)
4385 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
4386 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
4387 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
4388 VMLINUX_MAIN += $(drivers-y) $(net-y)
4389
4390 diff --git a/arch/sparc/include/asm/atomic_32.h b/arch/sparc/include/asm/atomic_32.h
4391 index 5c3c8b6..ba822fa 100644
4392 --- a/arch/sparc/include/asm/atomic_32.h
4393 +++ b/arch/sparc/include/asm/atomic_32.h
4394 @@ -13,6 +13,8 @@
4395
4396 #include <linux/types.h>
4397
4398 +#include <asm-generic/atomic64.h>
4399 +
4400 #ifdef __KERNEL__
4401
4402 #include <asm/system.h>
4403 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
4404 index 9f421df..b81fc12 100644
4405 --- a/arch/sparc/include/asm/atomic_64.h
4406 +++ b/arch/sparc/include/asm/atomic_64.h
4407 @@ -14,18 +14,40 @@
4408 #define ATOMIC64_INIT(i) { (i) }
4409
4410 #define atomic_read(v) (*(volatile int *)&(v)->counter)
4411 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
4412 +{
4413 + return v->counter;
4414 +}
4415 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
4416 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
4417 +{
4418 + return v->counter;
4419 +}
4420
4421 #define atomic_set(v, i) (((v)->counter) = i)
4422 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
4423 +{
4424 + v->counter = i;
4425 +}
4426 #define atomic64_set(v, i) (((v)->counter) = i)
4427 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
4428 +{
4429 + v->counter = i;
4430 +}
4431
4432 extern void atomic_add(int, atomic_t *);
4433 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
4434 extern void atomic64_add(long, atomic64_t *);
4435 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
4436 extern void atomic_sub(int, atomic_t *);
4437 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
4438 extern void atomic64_sub(long, atomic64_t *);
4439 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
4440
4441 extern int atomic_add_ret(int, atomic_t *);
4442 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
4443 extern long atomic64_add_ret(long, atomic64_t *);
4444 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
4445 extern int atomic_sub_ret(int, atomic_t *);
4446 extern long atomic64_sub_ret(long, atomic64_t *);
4447
4448 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4449 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
4450
4451 #define atomic_inc_return(v) atomic_add_ret(1, v)
4452 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
4453 +{
4454 + return atomic_add_ret_unchecked(1, v);
4455 +}
4456 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
4457 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
4458 +{
4459 + return atomic64_add_ret_unchecked(1, v);
4460 +}
4461
4462 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
4463 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
4464
4465 #define atomic_add_return(i, v) atomic_add_ret(i, v)
4466 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
4467 +{
4468 + return atomic_add_ret_unchecked(i, v);
4469 +}
4470 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
4471 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
4472 +{
4473 + return atomic64_add_ret_unchecked(i, v);
4474 +}
4475
4476 /*
4477 * atomic_inc_and_test - increment and test
4478 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4479 * other cases.
4480 */
4481 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
4482 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
4483 +{
4484 + return atomic_inc_return_unchecked(v) == 0;
4485 +}
4486 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
4487
4488 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
4489 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4490 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
4491
4492 #define atomic_inc(v) atomic_add(1, v)
4493 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
4494 +{
4495 + atomic_add_unchecked(1, v);
4496 +}
4497 #define atomic64_inc(v) atomic64_add(1, v)
4498 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
4499 +{
4500 + atomic64_add_unchecked(1, v);
4501 +}
4502
4503 #define atomic_dec(v) atomic_sub(1, v)
4504 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
4505 +{
4506 + atomic_sub_unchecked(1, v);
4507 +}
4508 #define atomic64_dec(v) atomic64_sub(1, v)
4509 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
4510 +{
4511 + atomic64_sub_unchecked(1, v);
4512 +}
4513
4514 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
4515 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
4516
4517 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
4518 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
4519 +{
4520 + return cmpxchg(&v->counter, old, new);
4521 +}
4522 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
4523 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
4524 +{
4525 + return xchg(&v->counter, new);
4526 +}
4527
4528 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
4529 {
4530 - int c, old;
4531 + int c, old, new;
4532 c = atomic_read(v);
4533 for (;;) {
4534 - if (unlikely(c == (u)))
4535 + if (unlikely(c == u))
4536 break;
4537 - old = atomic_cmpxchg((v), c, c + (a));
4538 +
4539 + asm volatile("addcc %2, %0, %0\n"
4540 +
4541 +#ifdef CONFIG_PAX_REFCOUNT
4542 + "tvs %%icc, 6\n"
4543 +#endif
4544 +
4545 + : "=r" (new)
4546 + : "0" (c), "ir" (a)
4547 + : "cc");
4548 +
4549 + old = atomic_cmpxchg(v, c, new);
4550 if (likely(old == c))
4551 break;
4552 c = old;
4553 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
4554 #define atomic64_cmpxchg(v, o, n) \
4555 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
4556 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
4557 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
4558 +{
4559 + return xchg(&v->counter, new);
4560 +}
4561
4562 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
4563 {
4564 - long c, old;
4565 + long c, old, new;
4566 c = atomic64_read(v);
4567 for (;;) {
4568 - if (unlikely(c == (u)))
4569 + if (unlikely(c == u))
4570 break;
4571 - old = atomic64_cmpxchg((v), c, c + (a));
4572 +
4573 + asm volatile("addcc %2, %0, %0\n"
4574 +
4575 +#ifdef CONFIG_PAX_REFCOUNT
4576 + "tvs %%xcc, 6\n"
4577 +#endif
4578 +
4579 + : "=r" (new)
4580 + : "0" (c), "ir" (a)
4581 + : "cc");
4582 +
4583 + old = atomic64_cmpxchg(v, c, new);
4584 if (likely(old == c))
4585 break;
4586 c = old;
4587 }
4588 - return c != (u);
4589 + return c != u;
4590 }
4591
4592 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4593 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
4594 index 69358b5..9d0d492 100644
4595 --- a/arch/sparc/include/asm/cache.h
4596 +++ b/arch/sparc/include/asm/cache.h
4597 @@ -7,10 +7,12 @@
4598 #ifndef _SPARC_CACHE_H
4599 #define _SPARC_CACHE_H
4600
4601 +#include <linux/const.h>
4602 +
4603 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
4604
4605 #define L1_CACHE_SHIFT 5
4606 -#define L1_CACHE_BYTES 32
4607 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4608
4609 #ifdef CONFIG_SPARC32
4610 #define SMP_CACHE_BYTES_SHIFT 5
4611 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
4612 index 4269ca6..e3da77f 100644
4613 --- a/arch/sparc/include/asm/elf_32.h
4614 +++ b/arch/sparc/include/asm/elf_32.h
4615 @@ -114,6 +114,13 @@ typedef struct {
4616
4617 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
4618
4619 +#ifdef CONFIG_PAX_ASLR
4620 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
4621 +
4622 +#define PAX_DELTA_MMAP_LEN 16
4623 +#define PAX_DELTA_STACK_LEN 16
4624 +#endif
4625 +
4626 /* This yields a mask that user programs can use to figure out what
4627 instruction set this cpu supports. This can NOT be done in userspace
4628 on Sparc. */
4629 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
4630 index 7df8b7f..4946269 100644
4631 --- a/arch/sparc/include/asm/elf_64.h
4632 +++ b/arch/sparc/include/asm/elf_64.h
4633 @@ -180,6 +180,13 @@ typedef struct {
4634 #define ELF_ET_DYN_BASE 0x0000010000000000UL
4635 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
4636
4637 +#ifdef CONFIG_PAX_ASLR
4638 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
4639 +
4640 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
4641 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
4642 +#endif
4643 +
4644 extern unsigned long sparc64_elf_hwcap;
4645 #define ELF_HWCAP sparc64_elf_hwcap
4646
4647 diff --git a/arch/sparc/include/asm/page_32.h b/arch/sparc/include/asm/page_32.h
4648 index 156707b..aefa786 100644
4649 --- a/arch/sparc/include/asm/page_32.h
4650 +++ b/arch/sparc/include/asm/page_32.h
4651 @@ -8,6 +8,8 @@
4652 #ifndef _SPARC_PAGE_H
4653 #define _SPARC_PAGE_H
4654
4655 +#include <linux/const.h>
4656 +
4657 #define PAGE_SHIFT 12
4658
4659 #ifndef __ASSEMBLY__
4660 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
4661 index a790cc6..091ed94 100644
4662 --- a/arch/sparc/include/asm/pgtable_32.h
4663 +++ b/arch/sparc/include/asm/pgtable_32.h
4664 @@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
4665 BTFIXUPDEF_INT(page_none)
4666 BTFIXUPDEF_INT(page_copy)
4667 BTFIXUPDEF_INT(page_readonly)
4668 +
4669 +#ifdef CONFIG_PAX_PAGEEXEC
4670 +BTFIXUPDEF_INT(page_shared_noexec)
4671 +BTFIXUPDEF_INT(page_copy_noexec)
4672 +BTFIXUPDEF_INT(page_readonly_noexec)
4673 +#endif
4674 +
4675 BTFIXUPDEF_INT(page_kernel)
4676
4677 #define PMD_SHIFT SUN4C_PMD_SHIFT
4678 @@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
4679 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
4680 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
4681
4682 +#ifdef CONFIG_PAX_PAGEEXEC
4683 +extern pgprot_t PAGE_SHARED_NOEXEC;
4684 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
4685 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
4686 +#else
4687 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4688 +# define PAGE_COPY_NOEXEC PAGE_COPY
4689 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4690 +#endif
4691 +
4692 extern unsigned long page_kernel;
4693
4694 #ifdef MODULE
4695 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
4696 index f6ae2b2..b03ffc7 100644
4697 --- a/arch/sparc/include/asm/pgtsrmmu.h
4698 +++ b/arch/sparc/include/asm/pgtsrmmu.h
4699 @@ -115,6 +115,13 @@
4700 SRMMU_EXEC | SRMMU_REF)
4701 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
4702 SRMMU_EXEC | SRMMU_REF)
4703 +
4704 +#ifdef CONFIG_PAX_PAGEEXEC
4705 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
4706 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4707 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4708 +#endif
4709 +
4710 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
4711 SRMMU_DIRTY | SRMMU_REF)
4712
4713 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
4714 index 9689176..63c18ea 100644
4715 --- a/arch/sparc/include/asm/spinlock_64.h
4716 +++ b/arch/sparc/include/asm/spinlock_64.h
4717 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
4718
4719 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
4720
4721 -static void inline arch_read_lock(arch_rwlock_t *lock)
4722 +static inline void arch_read_lock(arch_rwlock_t *lock)
4723 {
4724 unsigned long tmp1, tmp2;
4725
4726 __asm__ __volatile__ (
4727 "1: ldsw [%2], %0\n"
4728 " brlz,pn %0, 2f\n"
4729 -"4: add %0, 1, %1\n"
4730 +"4: addcc %0, 1, %1\n"
4731 +
4732 +#ifdef CONFIG_PAX_REFCOUNT
4733 +" tvs %%icc, 6\n"
4734 +#endif
4735 +
4736 " cas [%2], %0, %1\n"
4737 " cmp %0, %1\n"
4738 " bne,pn %%icc, 1b\n"
4739 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
4740 " .previous"
4741 : "=&r" (tmp1), "=&r" (tmp2)
4742 : "r" (lock)
4743 - : "memory");
4744 + : "memory", "cc");
4745 }
4746
4747 -static int inline arch_read_trylock(arch_rwlock_t *lock)
4748 +static inline int arch_read_trylock(arch_rwlock_t *lock)
4749 {
4750 int tmp1, tmp2;
4751
4752 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
4753 "1: ldsw [%2], %0\n"
4754 " brlz,a,pn %0, 2f\n"
4755 " mov 0, %0\n"
4756 -" add %0, 1, %1\n"
4757 +" addcc %0, 1, %1\n"
4758 +
4759 +#ifdef CONFIG_PAX_REFCOUNT
4760 +" tvs %%icc, 6\n"
4761 +#endif
4762 +
4763 " cas [%2], %0, %1\n"
4764 " cmp %0, %1\n"
4765 " bne,pn %%icc, 1b\n"
4766 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
4767 return tmp1;
4768 }
4769
4770 -static void inline arch_read_unlock(arch_rwlock_t *lock)
4771 +static inline void arch_read_unlock(arch_rwlock_t *lock)
4772 {
4773 unsigned long tmp1, tmp2;
4774
4775 __asm__ __volatile__(
4776 "1: lduw [%2], %0\n"
4777 -" sub %0, 1, %1\n"
4778 +" subcc %0, 1, %1\n"
4779 +
4780 +#ifdef CONFIG_PAX_REFCOUNT
4781 +" tvs %%icc, 6\n"
4782 +#endif
4783 +
4784 " cas [%2], %0, %1\n"
4785 " cmp %0, %1\n"
4786 " bne,pn %%xcc, 1b\n"
4787 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
4788 : "memory");
4789 }
4790
4791 -static void inline arch_write_lock(arch_rwlock_t *lock)
4792 +static inline void arch_write_lock(arch_rwlock_t *lock)
4793 {
4794 unsigned long mask, tmp1, tmp2;
4795
4796 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
4797 : "memory");
4798 }
4799
4800 -static void inline arch_write_unlock(arch_rwlock_t *lock)
4801 +static inline void arch_write_unlock(arch_rwlock_t *lock)
4802 {
4803 __asm__ __volatile__(
4804 " stw %%g0, [%0]"
4805 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
4806 : "memory");
4807 }
4808
4809 -static int inline arch_write_trylock(arch_rwlock_t *lock)
4810 +static inline int arch_write_trylock(arch_rwlock_t *lock)
4811 {
4812 unsigned long mask, tmp1, tmp2, result;
4813
4814 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
4815 index fa57532..e1a4c53 100644
4816 --- a/arch/sparc/include/asm/thread_info_32.h
4817 +++ b/arch/sparc/include/asm/thread_info_32.h
4818 @@ -50,6 +50,8 @@ struct thread_info {
4819 unsigned long w_saved;
4820
4821 struct restart_block restart_block;
4822 +
4823 + unsigned long lowest_stack;
4824 };
4825
4826 /*
4827 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
4828 index 60d86be..952dea1 100644
4829 --- a/arch/sparc/include/asm/thread_info_64.h
4830 +++ b/arch/sparc/include/asm/thread_info_64.h
4831 @@ -63,6 +63,8 @@ struct thread_info {
4832 struct pt_regs *kern_una_regs;
4833 unsigned int kern_una_insn;
4834
4835 + unsigned long lowest_stack;
4836 +
4837 unsigned long fpregs[0] __attribute__ ((aligned(64)));
4838 };
4839
4840 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
4841 index e88fbe5..96b0ce5 100644
4842 --- a/arch/sparc/include/asm/uaccess.h
4843 +++ b/arch/sparc/include/asm/uaccess.h
4844 @@ -1,5 +1,13 @@
4845 #ifndef ___ASM_SPARC_UACCESS_H
4846 #define ___ASM_SPARC_UACCESS_H
4847 +
4848 +#ifdef __KERNEL__
4849 +#ifndef __ASSEMBLY__
4850 +#include <linux/types.h>
4851 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
4852 +#endif
4853 +#endif
4854 +
4855 #if defined(__sparc__) && defined(__arch64__)
4856 #include <asm/uaccess_64.h>
4857 #else
4858 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
4859 index 8303ac4..07f333d 100644
4860 --- a/arch/sparc/include/asm/uaccess_32.h
4861 +++ b/arch/sparc/include/asm/uaccess_32.h
4862 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
4863
4864 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4865 {
4866 - if (n && __access_ok((unsigned long) to, n))
4867 + if ((long)n < 0)
4868 + return n;
4869 +
4870 + if (n && __access_ok((unsigned long) to, n)) {
4871 + if (!__builtin_constant_p(n))
4872 + check_object_size(from, n, true);
4873 return __copy_user(to, (__force void __user *) from, n);
4874 - else
4875 + } else
4876 return n;
4877 }
4878
4879 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
4880 {
4881 + if ((long)n < 0)
4882 + return n;
4883 +
4884 + if (!__builtin_constant_p(n))
4885 + check_object_size(from, n, true);
4886 +
4887 return __copy_user(to, (__force void __user *) from, n);
4888 }
4889
4890 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4891 {
4892 - if (n && __access_ok((unsigned long) from, n))
4893 + if ((long)n < 0)
4894 + return n;
4895 +
4896 + if (n && __access_ok((unsigned long) from, n)) {
4897 + if (!__builtin_constant_p(n))
4898 + check_object_size(to, n, false);
4899 return __copy_user((__force void __user *) to, from, n);
4900 - else
4901 + } else
4902 return n;
4903 }
4904
4905 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
4906 {
4907 + if ((long)n < 0)
4908 + return n;
4909 +
4910 return __copy_user((__force void __user *) to, from, n);
4911 }
4912
4913 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
4914 index 3e1449f..5293a0e 100644
4915 --- a/arch/sparc/include/asm/uaccess_64.h
4916 +++ b/arch/sparc/include/asm/uaccess_64.h
4917 @@ -10,6 +10,7 @@
4918 #include <linux/compiler.h>
4919 #include <linux/string.h>
4920 #include <linux/thread_info.h>
4921 +#include <linux/kernel.h>
4922 #include <asm/asi.h>
4923 #include <asm/system.h>
4924 #include <asm/spitfire.h>
4925 @@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
4926 static inline unsigned long __must_check
4927 copy_from_user(void *to, const void __user *from, unsigned long size)
4928 {
4929 - unsigned long ret = ___copy_from_user(to, from, size);
4930 + unsigned long ret;
4931
4932 + if ((long)size < 0 || size > INT_MAX)
4933 + return size;
4934 +
4935 + if (!__builtin_constant_p(size))
4936 + check_object_size(to, size, false);
4937 +
4938 + ret = ___copy_from_user(to, from, size);
4939 if (unlikely(ret))
4940 ret = copy_from_user_fixup(to, from, size);
4941
4942 @@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
4943 static inline unsigned long __must_check
4944 copy_to_user(void __user *to, const void *from, unsigned long size)
4945 {
4946 - unsigned long ret = ___copy_to_user(to, from, size);
4947 + unsigned long ret;
4948
4949 + if ((long)size < 0 || size > INT_MAX)
4950 + return size;
4951 +
4952 + if (!__builtin_constant_p(size))
4953 + check_object_size(from, size, true);
4954 +
4955 + ret = ___copy_to_user(to, from, size);
4956 if (unlikely(ret))
4957 ret = copy_to_user_fixup(to, from, size);
4958 return ret;
4959 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
4960 index cb85458..e063f17 100644
4961 --- a/arch/sparc/kernel/Makefile
4962 +++ b/arch/sparc/kernel/Makefile
4963 @@ -3,7 +3,7 @@
4964 #
4965
4966 asflags-y := -ansi
4967 -ccflags-y := -Werror
4968 +#ccflags-y := -Werror
4969
4970 extra-y := head_$(BITS).o
4971 extra-y += init_task.o
4972 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
4973 index f793742..4d880af 100644
4974 --- a/arch/sparc/kernel/process_32.c
4975 +++ b/arch/sparc/kernel/process_32.c
4976 @@ -204,7 +204,7 @@ void __show_backtrace(unsigned long fp)
4977 rw->ins[4], rw->ins[5],
4978 rw->ins[6],
4979 rw->ins[7]);
4980 - printk("%pS\n", (void *) rw->ins[7]);
4981 + printk("%pA\n", (void *) rw->ins[7]);
4982 rw = (struct reg_window32 *) rw->ins[6];
4983 }
4984 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
4985 @@ -271,14 +271,14 @@ void show_regs(struct pt_regs *r)
4986
4987 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
4988 r->psr, r->pc, r->npc, r->y, print_tainted());
4989 - printk("PC: <%pS>\n", (void *) r->pc);
4990 + printk("PC: <%pA>\n", (void *) r->pc);
4991 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4992 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
4993 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
4994 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4995 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
4996 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
4997 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
4998 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
4999
5000 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5001 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5002 @@ -313,7 +313,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5003 rw = (struct reg_window32 *) fp;
5004 pc = rw->ins[7];
5005 printk("[%08lx : ", pc);
5006 - printk("%pS ] ", (void *) pc);
5007 + printk("%pA ] ", (void *) pc);
5008 fp = rw->ins[6];
5009 } while (++count < 16);
5010 printk("\n");
5011 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5012 index 3739a06..48b2ff0 100644
5013 --- a/arch/sparc/kernel/process_64.c
5014 +++ b/arch/sparc/kernel/process_64.c
5015 @@ -180,14 +180,14 @@ static void show_regwindow(struct pt_regs *regs)
5016 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5017 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5018 if (regs->tstate & TSTATE_PRIV)
5019 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5020 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5021 }
5022
5023 void show_regs(struct pt_regs *regs)
5024 {
5025 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5026 regs->tpc, regs->tnpc, regs->y, print_tainted());
5027 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5028 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5029 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5030 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5031 regs->u_regs[3]);
5032 @@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
5033 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5034 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5035 regs->u_regs[15]);
5036 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5037 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5038 show_regwindow(regs);
5039 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5040 }
5041 @@ -285,7 +285,7 @@ void arch_trigger_all_cpu_backtrace(void)
5042 ((tp && tp->task) ? tp->task->pid : -1));
5043
5044 if (gp->tstate & TSTATE_PRIV) {
5045 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5046 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5047 (void *) gp->tpc,
5048 (void *) gp->o7,
5049 (void *) gp->i7,
5050 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5051 index 42b282f..28ce9f2 100644
5052 --- a/arch/sparc/kernel/sys_sparc_32.c
5053 +++ b/arch/sparc/kernel/sys_sparc_32.c
5054 @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5055 if (ARCH_SUN4C && len > 0x20000000)
5056 return -ENOMEM;
5057 if (!addr)
5058 - addr = TASK_UNMAPPED_BASE;
5059 + addr = current->mm->mmap_base;
5060
5061 if (flags & MAP_SHARED)
5062 addr = COLOUR_ALIGN(addr);
5063 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5064 }
5065 if (TASK_SIZE - PAGE_SIZE - len < addr)
5066 return -ENOMEM;
5067 - if (!vmm || addr + len <= vmm->vm_start)
5068 + if (check_heap_stack_gap(vmm, addr, len))
5069 return addr;
5070 addr = vmm->vm_end;
5071 if (flags & MAP_SHARED)
5072 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5073 index 441521a..b767073 100644
5074 --- a/arch/sparc/kernel/sys_sparc_64.c
5075 +++ b/arch/sparc/kernel/sys_sparc_64.c
5076 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5077 /* We do not accept a shared mapping if it would violate
5078 * cache aliasing constraints.
5079 */
5080 - if ((flags & MAP_SHARED) &&
5081 + if ((filp || (flags & MAP_SHARED)) &&
5082 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5083 return -EINVAL;
5084 return addr;
5085 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5086 if (filp || (flags & MAP_SHARED))
5087 do_color_align = 1;
5088
5089 +#ifdef CONFIG_PAX_RANDMMAP
5090 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5091 +#endif
5092 +
5093 if (addr) {
5094 if (do_color_align)
5095 addr = COLOUR_ALIGN(addr, pgoff);
5096 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5097 addr = PAGE_ALIGN(addr);
5098
5099 vma = find_vma(mm, addr);
5100 - if (task_size - len >= addr &&
5101 - (!vma || addr + len <= vma->vm_start))
5102 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5103 return addr;
5104 }
5105
5106 if (len > mm->cached_hole_size) {
5107 - start_addr = addr = mm->free_area_cache;
5108 + start_addr = addr = mm->free_area_cache;
5109 } else {
5110 - start_addr = addr = TASK_UNMAPPED_BASE;
5111 + start_addr = addr = mm->mmap_base;
5112 mm->cached_hole_size = 0;
5113 }
5114
5115 @@ -174,14 +177,14 @@ full_search:
5116 vma = find_vma(mm, VA_EXCLUDE_END);
5117 }
5118 if (unlikely(task_size < addr)) {
5119 - if (start_addr != TASK_UNMAPPED_BASE) {
5120 - start_addr = addr = TASK_UNMAPPED_BASE;
5121 + if (start_addr != mm->mmap_base) {
5122 + start_addr = addr = mm->mmap_base;
5123 mm->cached_hole_size = 0;
5124 goto full_search;
5125 }
5126 return -ENOMEM;
5127 }
5128 - if (likely(!vma || addr + len <= vma->vm_start)) {
5129 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5130 /*
5131 * Remember the place where we stopped the search:
5132 */
5133 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5134 /* We do not accept a shared mapping if it would violate
5135 * cache aliasing constraints.
5136 */
5137 - if ((flags & MAP_SHARED) &&
5138 + if ((filp || (flags & MAP_SHARED)) &&
5139 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5140 return -EINVAL;
5141 return addr;
5142 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5143 addr = PAGE_ALIGN(addr);
5144
5145 vma = find_vma(mm, addr);
5146 - if (task_size - len >= addr &&
5147 - (!vma || addr + len <= vma->vm_start))
5148 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5149 return addr;
5150 }
5151
5152 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5153 /* make sure it can fit in the remaining address space */
5154 if (likely(addr > len)) {
5155 vma = find_vma(mm, addr-len);
5156 - if (!vma || addr <= vma->vm_start) {
5157 + if (check_heap_stack_gap(vma, addr - len, len)) {
5158 /* remember the address as a hint for next time */
5159 return (mm->free_area_cache = addr-len);
5160 }
5161 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5162 if (unlikely(mm->mmap_base < len))
5163 goto bottomup;
5164
5165 - addr = mm->mmap_base-len;
5166 - if (do_color_align)
5167 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5168 + addr = mm->mmap_base - len;
5169
5170 do {
5171 + if (do_color_align)
5172 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5173 /*
5174 * Lookup failure means no vma is above this address,
5175 * else if new region fits below vma->vm_start,
5176 * return with success:
5177 */
5178 vma = find_vma(mm, addr);
5179 - if (likely(!vma || addr+len <= vma->vm_start)) {
5180 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5181 /* remember the address as a hint for next time */
5182 return (mm->free_area_cache = addr);
5183 }
5184 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5185 mm->cached_hole_size = vma->vm_start - addr;
5186
5187 /* try just below the current vma->vm_start */
5188 - addr = vma->vm_start-len;
5189 - if (do_color_align)
5190 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5191 - } while (likely(len < vma->vm_start));
5192 + addr = skip_heap_stack_gap(vma, len);
5193 + } while (!IS_ERR_VALUE(addr));
5194
5195 bottomup:
5196 /*
5197 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5198 gap == RLIM_INFINITY ||
5199 sysctl_legacy_va_layout) {
5200 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5201 +
5202 +#ifdef CONFIG_PAX_RANDMMAP
5203 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5204 + mm->mmap_base += mm->delta_mmap;
5205 +#endif
5206 +
5207 mm->get_unmapped_area = arch_get_unmapped_area;
5208 mm->unmap_area = arch_unmap_area;
5209 } else {
5210 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5211 gap = (task_size / 6 * 5);
5212
5213 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5214 +
5215 +#ifdef CONFIG_PAX_RANDMMAP
5216 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5217 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5218 +#endif
5219 +
5220 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5221 mm->unmap_area = arch_unmap_area_topdown;
5222 }
5223 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
5224 index 591f20c..0f1b925 100644
5225 --- a/arch/sparc/kernel/traps_32.c
5226 +++ b/arch/sparc/kernel/traps_32.c
5227 @@ -45,6 +45,8 @@ static void instruction_dump(unsigned long *pc)
5228 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
5229 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
5230
5231 +extern void gr_handle_kernel_exploit(void);
5232 +
5233 void die_if_kernel(char *str, struct pt_regs *regs)
5234 {
5235 static int die_counter;
5236 @@ -77,15 +79,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5237 count++ < 30 &&
5238 (((unsigned long) rw) >= PAGE_OFFSET) &&
5239 !(((unsigned long) rw) & 0x7)) {
5240 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
5241 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
5242 (void *) rw->ins[7]);
5243 rw = (struct reg_window32 *)rw->ins[6];
5244 }
5245 }
5246 printk("Instruction DUMP:");
5247 instruction_dump ((unsigned long *) regs->pc);
5248 - if(regs->psr & PSR_PS)
5249 + if(regs->psr & PSR_PS) {
5250 + gr_handle_kernel_exploit();
5251 do_exit(SIGKILL);
5252 + }
5253 do_exit(SIGSEGV);
5254 }
5255
5256 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
5257 index 0cbdaa4..438e4c9 100644
5258 --- a/arch/sparc/kernel/traps_64.c
5259 +++ b/arch/sparc/kernel/traps_64.c
5260 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
5261 i + 1,
5262 p->trapstack[i].tstate, p->trapstack[i].tpc,
5263 p->trapstack[i].tnpc, p->trapstack[i].tt);
5264 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
5265 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
5266 }
5267 }
5268
5269 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
5270
5271 lvl -= 0x100;
5272 if (regs->tstate & TSTATE_PRIV) {
5273 +
5274 +#ifdef CONFIG_PAX_REFCOUNT
5275 + if (lvl == 6)
5276 + pax_report_refcount_overflow(regs);
5277 +#endif
5278 +
5279 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
5280 die_if_kernel(buffer, regs);
5281 }
5282 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
5283 void bad_trap_tl1(struct pt_regs *regs, long lvl)
5284 {
5285 char buffer[32];
5286 -
5287 +
5288 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
5289 0, lvl, SIGTRAP) == NOTIFY_STOP)
5290 return;
5291
5292 +#ifdef CONFIG_PAX_REFCOUNT
5293 + if (lvl == 6)
5294 + pax_report_refcount_overflow(regs);
5295 +#endif
5296 +
5297 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
5298
5299 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
5300 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
5301 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
5302 printk("%s" "ERROR(%d): ",
5303 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
5304 - printk("TPC<%pS>\n", (void *) regs->tpc);
5305 + printk("TPC<%pA>\n", (void *) regs->tpc);
5306 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
5307 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
5308 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
5309 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5310 smp_processor_id(),
5311 (type & 0x1) ? 'I' : 'D',
5312 regs->tpc);
5313 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
5314 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
5315 panic("Irrecoverable Cheetah+ parity error.");
5316 }
5317
5318 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5319 smp_processor_id(),
5320 (type & 0x1) ? 'I' : 'D',
5321 regs->tpc);
5322 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
5323 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
5324 }
5325
5326 struct sun4v_error_entry {
5327 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
5328
5329 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
5330 regs->tpc, tl);
5331 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
5332 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
5333 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5334 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
5335 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
5336 (void *) regs->u_regs[UREG_I7]);
5337 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
5338 "pte[%lx] error[%lx]\n",
5339 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
5340
5341 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
5342 regs->tpc, tl);
5343 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
5344 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
5345 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5346 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
5347 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
5348 (void *) regs->u_regs[UREG_I7]);
5349 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
5350 "pte[%lx] error[%lx]\n",
5351 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5352 fp = (unsigned long)sf->fp + STACK_BIAS;
5353 }
5354
5355 - printk(" [%016lx] %pS\n", pc, (void *) pc);
5356 + printk(" [%016lx] %pA\n", pc, (void *) pc);
5357 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
5358 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
5359 int index = tsk->curr_ret_stack;
5360 if (tsk->ret_stack && index >= graph) {
5361 pc = tsk->ret_stack[index - graph].ret;
5362 - printk(" [%016lx] %pS\n", pc, (void *) pc);
5363 + printk(" [%016lx] %pA\n", pc, (void *) pc);
5364 graph++;
5365 }
5366 }
5367 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
5368 return (struct reg_window *) (fp + STACK_BIAS);
5369 }
5370
5371 +extern void gr_handle_kernel_exploit(void);
5372 +
5373 void die_if_kernel(char *str, struct pt_regs *regs)
5374 {
5375 static int die_counter;
5376 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5377 while (rw &&
5378 count++ < 30 &&
5379 kstack_valid(tp, (unsigned long) rw)) {
5380 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
5381 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
5382 (void *) rw->ins[7]);
5383
5384 rw = kernel_stack_up(rw);
5385 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5386 }
5387 user_instruction_dump ((unsigned int __user *) regs->tpc);
5388 }
5389 - if (regs->tstate & TSTATE_PRIV)
5390 + if (regs->tstate & TSTATE_PRIV) {
5391 + gr_handle_kernel_exploit();
5392 do_exit(SIGKILL);
5393 + }
5394 do_exit(SIGSEGV);
5395 }
5396 EXPORT_SYMBOL(die_if_kernel);
5397 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
5398 index 76e4ac1..78f8bb1 100644
5399 --- a/arch/sparc/kernel/unaligned_64.c
5400 +++ b/arch/sparc/kernel/unaligned_64.c
5401 @@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
5402 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
5403
5404 if (__ratelimit(&ratelimit)) {
5405 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
5406 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
5407 regs->tpc, (void *) regs->tpc);
5408 }
5409 }
5410 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
5411 index a3fc437..fea9957 100644
5412 --- a/arch/sparc/lib/Makefile
5413 +++ b/arch/sparc/lib/Makefile
5414 @@ -2,7 +2,7 @@
5415 #
5416
5417 asflags-y := -ansi -DST_DIV0=0x02
5418 -ccflags-y := -Werror
5419 +#ccflags-y := -Werror
5420
5421 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
5422 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
5423 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
5424 index 59186e0..f747d7a 100644
5425 --- a/arch/sparc/lib/atomic_64.S
5426 +++ b/arch/sparc/lib/atomic_64.S
5427 @@ -18,7 +18,12 @@
5428 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5429 BACKOFF_SETUP(%o2)
5430 1: lduw [%o1], %g1
5431 - add %g1, %o0, %g7
5432 + addcc %g1, %o0, %g7
5433 +
5434 +#ifdef CONFIG_PAX_REFCOUNT
5435 + tvs %icc, 6
5436 +#endif
5437 +
5438 cas [%o1], %g1, %g7
5439 cmp %g1, %g7
5440 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5441 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5442 2: BACKOFF_SPIN(%o2, %o3, 1b)
5443 .size atomic_add, .-atomic_add
5444
5445 + .globl atomic_add_unchecked
5446 + .type atomic_add_unchecked,#function
5447 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5448 + BACKOFF_SETUP(%o2)
5449 +1: lduw [%o1], %g1
5450 + add %g1, %o0, %g7
5451 + cas [%o1], %g1, %g7
5452 + cmp %g1, %g7
5453 + bne,pn %icc, 2f
5454 + nop
5455 + retl
5456 + nop
5457 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5458 + .size atomic_add_unchecked, .-atomic_add_unchecked
5459 +
5460 .globl atomic_sub
5461 .type atomic_sub,#function
5462 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5463 BACKOFF_SETUP(%o2)
5464 1: lduw [%o1], %g1
5465 - sub %g1, %o0, %g7
5466 + subcc %g1, %o0, %g7
5467 +
5468 +#ifdef CONFIG_PAX_REFCOUNT
5469 + tvs %icc, 6
5470 +#endif
5471 +
5472 cas [%o1], %g1, %g7
5473 cmp %g1, %g7
5474 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5475 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5476 2: BACKOFF_SPIN(%o2, %o3, 1b)
5477 .size atomic_sub, .-atomic_sub
5478
5479 + .globl atomic_sub_unchecked
5480 + .type atomic_sub_unchecked,#function
5481 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5482 + BACKOFF_SETUP(%o2)
5483 +1: lduw [%o1], %g1
5484 + sub %g1, %o0, %g7
5485 + cas [%o1], %g1, %g7
5486 + cmp %g1, %g7
5487 + bne,pn %icc, 2f
5488 + nop
5489 + retl
5490 + nop
5491 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5492 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
5493 +
5494 .globl atomic_add_ret
5495 .type atomic_add_ret,#function
5496 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5497 BACKOFF_SETUP(%o2)
5498 1: lduw [%o1], %g1
5499 - add %g1, %o0, %g7
5500 + addcc %g1, %o0, %g7
5501 +
5502 +#ifdef CONFIG_PAX_REFCOUNT
5503 + tvs %icc, 6
5504 +#endif
5505 +
5506 cas [%o1], %g1, %g7
5507 cmp %g1, %g7
5508 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5509 @@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5510 2: BACKOFF_SPIN(%o2, %o3, 1b)
5511 .size atomic_add_ret, .-atomic_add_ret
5512
5513 + .globl atomic_add_ret_unchecked
5514 + .type atomic_add_ret_unchecked,#function
5515 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5516 + BACKOFF_SETUP(%o2)
5517 +1: lduw [%o1], %g1
5518 + addcc %g1, %o0, %g7
5519 + cas [%o1], %g1, %g7
5520 + cmp %g1, %g7
5521 + bne,pn %icc, 2f
5522 + add %g7, %o0, %g7
5523 + sra %g7, 0, %o0
5524 + retl
5525 + nop
5526 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5527 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
5528 +
5529 .globl atomic_sub_ret
5530 .type atomic_sub_ret,#function
5531 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5532 BACKOFF_SETUP(%o2)
5533 1: lduw [%o1], %g1
5534 - sub %g1, %o0, %g7
5535 + subcc %g1, %o0, %g7
5536 +
5537 +#ifdef CONFIG_PAX_REFCOUNT
5538 + tvs %icc, 6
5539 +#endif
5540 +
5541 cas [%o1], %g1, %g7
5542 cmp %g1, %g7
5543 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5544 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5545 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5546 BACKOFF_SETUP(%o2)
5547 1: ldx [%o1], %g1
5548 - add %g1, %o0, %g7
5549 + addcc %g1, %o0, %g7
5550 +
5551 +#ifdef CONFIG_PAX_REFCOUNT
5552 + tvs %xcc, 6
5553 +#endif
5554 +
5555 casx [%o1], %g1, %g7
5556 cmp %g1, %g7
5557 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5558 @@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5559 2: BACKOFF_SPIN(%o2, %o3, 1b)
5560 .size atomic64_add, .-atomic64_add
5561
5562 + .globl atomic64_add_unchecked
5563 + .type atomic64_add_unchecked,#function
5564 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5565 + BACKOFF_SETUP(%o2)
5566 +1: ldx [%o1], %g1
5567 + addcc %g1, %o0, %g7
5568 + casx [%o1], %g1, %g7
5569 + cmp %g1, %g7
5570 + bne,pn %xcc, 2f
5571 + nop
5572 + retl
5573 + nop
5574 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5575 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
5576 +
5577 .globl atomic64_sub
5578 .type atomic64_sub,#function
5579 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5580 BACKOFF_SETUP(%o2)
5581 1: ldx [%o1], %g1
5582 - sub %g1, %o0, %g7
5583 + subcc %g1, %o0, %g7
5584 +
5585 +#ifdef CONFIG_PAX_REFCOUNT
5586 + tvs %xcc, 6
5587 +#endif
5588 +
5589 casx [%o1], %g1, %g7
5590 cmp %g1, %g7
5591 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5592 @@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5593 2: BACKOFF_SPIN(%o2, %o3, 1b)
5594 .size atomic64_sub, .-atomic64_sub
5595
5596 + .globl atomic64_sub_unchecked
5597 + .type atomic64_sub_unchecked,#function
5598 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5599 + BACKOFF_SETUP(%o2)
5600 +1: ldx [%o1], %g1
5601 + subcc %g1, %o0, %g7
5602 + casx [%o1], %g1, %g7
5603 + cmp %g1, %g7
5604 + bne,pn %xcc, 2f
5605 + nop
5606 + retl
5607 + nop
5608 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5609 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
5610 +
5611 .globl atomic64_add_ret
5612 .type atomic64_add_ret,#function
5613 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5614 BACKOFF_SETUP(%o2)
5615 1: ldx [%o1], %g1
5616 - add %g1, %o0, %g7
5617 + addcc %g1, %o0, %g7
5618 +
5619 +#ifdef CONFIG_PAX_REFCOUNT
5620 + tvs %xcc, 6
5621 +#endif
5622 +
5623 casx [%o1], %g1, %g7
5624 cmp %g1, %g7
5625 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5626 @@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5627 2: BACKOFF_SPIN(%o2, %o3, 1b)
5628 .size atomic64_add_ret, .-atomic64_add_ret
5629
5630 + .globl atomic64_add_ret_unchecked
5631 + .type atomic64_add_ret_unchecked,#function
5632 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5633 + BACKOFF_SETUP(%o2)
5634 +1: ldx [%o1], %g1
5635 + addcc %g1, %o0, %g7
5636 + casx [%o1], %g1, %g7
5637 + cmp %g1, %g7
5638 + bne,pn %xcc, 2f
5639 + add %g7, %o0, %g7
5640 + mov %g7, %o0
5641 + retl
5642 + nop
5643 +2: BACKOFF_SPIN(%o2, %o3, 1b)
5644 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
5645 +
5646 .globl atomic64_sub_ret
5647 .type atomic64_sub_ret,#function
5648 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5649 BACKOFF_SETUP(%o2)
5650 1: ldx [%o1], %g1
5651 - sub %g1, %o0, %g7
5652 + subcc %g1, %o0, %g7
5653 +
5654 +#ifdef CONFIG_PAX_REFCOUNT
5655 + tvs %xcc, 6
5656 +#endif
5657 +
5658 casx [%o1], %g1, %g7
5659 cmp %g1, %g7
5660 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5661 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
5662 index 1b30bb3..b4a16c7 100644
5663 --- a/arch/sparc/lib/ksyms.c
5664 +++ b/arch/sparc/lib/ksyms.c
5665 @@ -142,12 +142,18 @@ EXPORT_SYMBOL(__downgrade_write);
5666
5667 /* Atomic counter implementation. */
5668 EXPORT_SYMBOL(atomic_add);
5669 +EXPORT_SYMBOL(atomic_add_unchecked);
5670 EXPORT_SYMBOL(atomic_add_ret);
5671 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
5672 EXPORT_SYMBOL(atomic_sub);
5673 +EXPORT_SYMBOL(atomic_sub_unchecked);
5674 EXPORT_SYMBOL(atomic_sub_ret);
5675 EXPORT_SYMBOL(atomic64_add);
5676 +EXPORT_SYMBOL(atomic64_add_unchecked);
5677 EXPORT_SYMBOL(atomic64_add_ret);
5678 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
5679 EXPORT_SYMBOL(atomic64_sub);
5680 +EXPORT_SYMBOL(atomic64_sub_unchecked);
5681 EXPORT_SYMBOL(atomic64_sub_ret);
5682
5683 /* Atomic bit operations. */
5684 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
5685 index 301421c..e2535d1 100644
5686 --- a/arch/sparc/mm/Makefile
5687 +++ b/arch/sparc/mm/Makefile
5688 @@ -2,7 +2,7 @@
5689 #
5690
5691 asflags-y := -ansi
5692 -ccflags-y := -Werror
5693 +#ccflags-y := -Werror
5694
5695 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
5696 obj-y += fault_$(BITS).o
5697 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
5698 index 8023fd7..c8e89e9 100644
5699 --- a/arch/sparc/mm/fault_32.c
5700 +++ b/arch/sparc/mm/fault_32.c
5701 @@ -21,6 +21,9 @@
5702 #include <linux/perf_event.h>
5703 #include <linux/interrupt.h>
5704 #include <linux/kdebug.h>
5705 +#include <linux/slab.h>
5706 +#include <linux/pagemap.h>
5707 +#include <linux/compiler.h>
5708
5709 #include <asm/system.h>
5710 #include <asm/page.h>
5711 @@ -208,6 +211,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
5712 return safe_compute_effective_address(regs, insn);
5713 }
5714
5715 +#ifdef CONFIG_PAX_PAGEEXEC
5716 +#ifdef CONFIG_PAX_DLRESOLVE
5717 +static void pax_emuplt_close(struct vm_area_struct *vma)
5718 +{
5719 + vma->vm_mm->call_dl_resolve = 0UL;
5720 +}
5721 +
5722 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
5723 +{
5724 + unsigned int *kaddr;
5725 +
5726 + vmf->page = alloc_page(GFP_HIGHUSER);
5727 + if (!vmf->page)
5728 + return VM_FAULT_OOM;
5729 +
5730 + kaddr = kmap(vmf->page);
5731 + memset(kaddr, 0, PAGE_SIZE);
5732 + kaddr[0] = 0x9DE3BFA8U; /* save */
5733 + flush_dcache_page(vmf->page);
5734 + kunmap(vmf->page);
5735 + return VM_FAULT_MAJOR;
5736 +}
5737 +
5738 +static const struct vm_operations_struct pax_vm_ops = {
5739 + .close = pax_emuplt_close,
5740 + .fault = pax_emuplt_fault
5741 +};
5742 +
5743 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
5744 +{
5745 + int ret;
5746 +
5747 + INIT_LIST_HEAD(&vma->anon_vma_chain);
5748 + vma->vm_mm = current->mm;
5749 + vma->vm_start = addr;
5750 + vma->vm_end = addr + PAGE_SIZE;
5751 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
5752 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5753 + vma->vm_ops = &pax_vm_ops;
5754 +
5755 + ret = insert_vm_struct(current->mm, vma);
5756 + if (ret)
5757 + return ret;
5758 +
5759 + ++current->mm->total_vm;
5760 + return 0;
5761 +}
5762 +#endif
5763 +
5764 +/*
5765 + * PaX: decide what to do with offenders (regs->pc = fault address)
5766 + *
5767 + * returns 1 when task should be killed
5768 + * 2 when patched PLT trampoline was detected
5769 + * 3 when unpatched PLT trampoline was detected
5770 + */
5771 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5772 +{
5773 +
5774 +#ifdef CONFIG_PAX_EMUPLT
5775 + int err;
5776 +
5777 + do { /* PaX: patched PLT emulation #1 */
5778 + unsigned int sethi1, sethi2, jmpl;
5779 +
5780 + err = get_user(sethi1, (unsigned int *)regs->pc);
5781 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
5782 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
5783 +
5784 + if (err)
5785 + break;
5786 +
5787 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
5788 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
5789 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
5790 + {
5791 + unsigned int addr;
5792 +
5793 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
5794 + addr = regs->u_regs[UREG_G1];
5795 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5796 + regs->pc = addr;
5797 + regs->npc = addr+4;
5798 + return 2;
5799 + }
5800 + } while (0);
5801 +
5802 + { /* PaX: patched PLT emulation #2 */
5803 + unsigned int ba;
5804 +
5805 + err = get_user(ba, (unsigned int *)regs->pc);
5806 +
5807 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
5808 + unsigned int addr;
5809 +
5810 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
5811 + regs->pc = addr;
5812 + regs->npc = addr+4;
5813 + return 2;
5814 + }
5815 + }
5816 +
5817 + do { /* PaX: patched PLT emulation #3 */
5818 + unsigned int sethi, jmpl, nop;
5819 +
5820 + err = get_user(sethi, (unsigned int *)regs->pc);
5821 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
5822 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
5823 +
5824 + if (err)
5825 + break;
5826 +
5827 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5828 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
5829 + nop == 0x01000000U)
5830 + {
5831 + unsigned int addr;
5832 +
5833 + addr = (sethi & 0x003FFFFFU) << 10;
5834 + regs->u_regs[UREG_G1] = addr;
5835 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5836 + regs->pc = addr;
5837 + regs->npc = addr+4;
5838 + return 2;
5839 + }
5840 + } while (0);
5841 +
5842 + do { /* PaX: unpatched PLT emulation step 1 */
5843 + unsigned int sethi, ba, nop;
5844 +
5845 + err = get_user(sethi, (unsigned int *)regs->pc);
5846 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
5847 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
5848 +
5849 + if (err)
5850 + break;
5851 +
5852 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5853 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
5854 + nop == 0x01000000U)
5855 + {
5856 + unsigned int addr, save, call;
5857 +
5858 + if ((ba & 0xFFC00000U) == 0x30800000U)
5859 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
5860 + else
5861 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
5862 +
5863 + err = get_user(save, (unsigned int *)addr);
5864 + err |= get_user(call, (unsigned int *)(addr+4));
5865 + err |= get_user(nop, (unsigned int *)(addr+8));
5866 + if (err)
5867 + break;
5868 +
5869 +#ifdef CONFIG_PAX_DLRESOLVE
5870 + if (save == 0x9DE3BFA8U &&
5871 + (call & 0xC0000000U) == 0x40000000U &&
5872 + nop == 0x01000000U)
5873 + {
5874 + struct vm_area_struct *vma;
5875 + unsigned long call_dl_resolve;
5876 +
5877 + down_read(&current->mm->mmap_sem);
5878 + call_dl_resolve = current->mm->call_dl_resolve;
5879 + up_read(&current->mm->mmap_sem);
5880 + if (likely(call_dl_resolve))
5881 + goto emulate;
5882 +
5883 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
5884 +
5885 + down_write(&current->mm->mmap_sem);
5886 + if (current->mm->call_dl_resolve) {
5887 + call_dl_resolve = current->mm->call_dl_resolve;
5888 + up_write(&current->mm->mmap_sem);
5889 + if (vma)
5890 + kmem_cache_free(vm_area_cachep, vma);
5891 + goto emulate;
5892 + }
5893 +
5894 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
5895 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
5896 + up_write(&current->mm->mmap_sem);
5897 + if (vma)
5898 + kmem_cache_free(vm_area_cachep, vma);
5899 + return 1;
5900 + }
5901 +
5902 + if (pax_insert_vma(vma, call_dl_resolve)) {
5903 + up_write(&current->mm->mmap_sem);
5904 + kmem_cache_free(vm_area_cachep, vma);
5905 + return 1;
5906 + }
5907 +
5908 + current->mm->call_dl_resolve = call_dl_resolve;
5909 + up_write(&current->mm->mmap_sem);
5910 +
5911 +emulate:
5912 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5913 + regs->pc = call_dl_resolve;
5914 + regs->npc = addr+4;
5915 + return 3;
5916 + }
5917 +#endif
5918 +
5919 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
5920 + if ((save & 0xFFC00000U) == 0x05000000U &&
5921 + (call & 0xFFFFE000U) == 0x85C0A000U &&
5922 + nop == 0x01000000U)
5923 + {
5924 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5925 + regs->u_regs[UREG_G2] = addr + 4;
5926 + addr = (save & 0x003FFFFFU) << 10;
5927 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5928 + regs->pc = addr;
5929 + regs->npc = addr+4;
5930 + return 3;
5931 + }
5932 + }
5933 + } while (0);
5934 +
5935 + do { /* PaX: unpatched PLT emulation step 2 */
5936 + unsigned int save, call, nop;
5937 +
5938 + err = get_user(save, (unsigned int *)(regs->pc-4));
5939 + err |= get_user(call, (unsigned int *)regs->pc);
5940 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
5941 + if (err)
5942 + break;
5943 +
5944 + if (save == 0x9DE3BFA8U &&
5945 + (call & 0xC0000000U) == 0x40000000U &&
5946 + nop == 0x01000000U)
5947 + {
5948 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
5949 +
5950 + regs->u_regs[UREG_RETPC] = regs->pc;
5951 + regs->pc = dl_resolve;
5952 + regs->npc = dl_resolve+4;
5953 + return 3;
5954 + }
5955 + } while (0);
5956 +#endif
5957 +
5958 + return 1;
5959 +}
5960 +
5961 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5962 +{
5963 + unsigned long i;
5964 +
5965 + printk(KERN_ERR "PAX: bytes at PC: ");
5966 + for (i = 0; i < 8; i++) {
5967 + unsigned int c;
5968 + if (get_user(c, (unsigned int *)pc+i))
5969 + printk(KERN_CONT "???????? ");
5970 + else
5971 + printk(KERN_CONT "%08x ", c);
5972 + }
5973 + printk("\n");
5974 +}
5975 +#endif
5976 +
5977 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
5978 int text_fault)
5979 {
5980 @@ -280,6 +545,24 @@ good_area:
5981 if(!(vma->vm_flags & VM_WRITE))
5982 goto bad_area;
5983 } else {
5984 +
5985 +#ifdef CONFIG_PAX_PAGEEXEC
5986 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
5987 + up_read(&mm->mmap_sem);
5988 + switch (pax_handle_fetch_fault(regs)) {
5989 +
5990 +#ifdef CONFIG_PAX_EMUPLT
5991 + case 2:
5992 + case 3:
5993 + return;
5994 +#endif
5995 +
5996 + }
5997 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
5998 + do_group_exit(SIGKILL);
5999 + }
6000 +#endif
6001 +
6002 /* Allow reads even for write-only mappings */
6003 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6004 goto bad_area;
6005 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6006 index 504c062..6fcb9c6 100644
6007 --- a/arch/sparc/mm/fault_64.c
6008 +++ b/arch/sparc/mm/fault_64.c
6009 @@ -21,6 +21,9 @@
6010 #include <linux/kprobes.h>
6011 #include <linux/kdebug.h>
6012 #include <linux/percpu.h>
6013 +#include <linux/slab.h>
6014 +#include <linux/pagemap.h>
6015 +#include <linux/compiler.h>
6016
6017 #include <asm/page.h>
6018 #include <asm/pgtable.h>
6019 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6020 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6021 regs->tpc);
6022 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6023 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6024 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6025 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6026 dump_stack();
6027 unhandled_fault(regs->tpc, current, regs);
6028 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6029 show_regs(regs);
6030 }
6031
6032 +#ifdef CONFIG_PAX_PAGEEXEC
6033 +#ifdef CONFIG_PAX_DLRESOLVE
6034 +static void pax_emuplt_close(struct vm_area_struct *vma)
6035 +{
6036 + vma->vm_mm->call_dl_resolve = 0UL;
6037 +}
6038 +
6039 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6040 +{
6041 + unsigned int *kaddr;
6042 +
6043 + vmf->page = alloc_page(GFP_HIGHUSER);
6044 + if (!vmf->page)
6045 + return VM_FAULT_OOM;
6046 +
6047 + kaddr = kmap(vmf->page);
6048 + memset(kaddr, 0, PAGE_SIZE);
6049 + kaddr[0] = 0x9DE3BFA8U; /* save */
6050 + flush_dcache_page(vmf->page);
6051 + kunmap(vmf->page);
6052 + return VM_FAULT_MAJOR;
6053 +}
6054 +
6055 +static const struct vm_operations_struct pax_vm_ops = {
6056 + .close = pax_emuplt_close,
6057 + .fault = pax_emuplt_fault
6058 +};
6059 +
6060 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6061 +{
6062 + int ret;
6063 +
6064 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6065 + vma->vm_mm = current->mm;
6066 + vma->vm_start = addr;
6067 + vma->vm_end = addr + PAGE_SIZE;
6068 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6069 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6070 + vma->vm_ops = &pax_vm_ops;
6071 +
6072 + ret = insert_vm_struct(current->mm, vma);
6073 + if (ret)
6074 + return ret;
6075 +
6076 + ++current->mm->total_vm;
6077 + return 0;
6078 +}
6079 +#endif
6080 +
6081 +/*
6082 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6083 + *
6084 + * returns 1 when task should be killed
6085 + * 2 when patched PLT trampoline was detected
6086 + * 3 when unpatched PLT trampoline was detected
6087 + */
6088 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6089 +{
6090 +
6091 +#ifdef CONFIG_PAX_EMUPLT
6092 + int err;
6093 +
6094 + do { /* PaX: patched PLT emulation #1 */
6095 + unsigned int sethi1, sethi2, jmpl;
6096 +
6097 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6098 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6099 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6100 +
6101 + if (err)
6102 + break;
6103 +
6104 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6105 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6106 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6107 + {
6108 + unsigned long addr;
6109 +
6110 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6111 + addr = regs->u_regs[UREG_G1];
6112 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6113 +
6114 + if (test_thread_flag(TIF_32BIT))
6115 + addr &= 0xFFFFFFFFUL;
6116 +
6117 + regs->tpc = addr;
6118 + regs->tnpc = addr+4;
6119 + return 2;
6120 + }
6121 + } while (0);
6122 +
6123 + { /* PaX: patched PLT emulation #2 */
6124 + unsigned int ba;
6125 +
6126 + err = get_user(ba, (unsigned int *)regs->tpc);
6127 +
6128 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6129 + unsigned long addr;
6130 +
6131 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6132 +
6133 + if (test_thread_flag(TIF_32BIT))
6134 + addr &= 0xFFFFFFFFUL;
6135 +
6136 + regs->tpc = addr;
6137 + regs->tnpc = addr+4;
6138 + return 2;
6139 + }
6140 + }
6141 +
6142 + do { /* PaX: patched PLT emulation #3 */
6143 + unsigned int sethi, jmpl, nop;
6144 +
6145 + err = get_user(sethi, (unsigned int *)regs->tpc);
6146 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6147 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6148 +
6149 + if (err)
6150 + break;
6151 +
6152 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6153 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6154 + nop == 0x01000000U)
6155 + {
6156 + unsigned long addr;
6157 +
6158 + addr = (sethi & 0x003FFFFFU) << 10;
6159 + regs->u_regs[UREG_G1] = addr;
6160 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6161 +
6162 + if (test_thread_flag(TIF_32BIT))
6163 + addr &= 0xFFFFFFFFUL;
6164 +
6165 + regs->tpc = addr;
6166 + regs->tnpc = addr+4;
6167 + return 2;
6168 + }
6169 + } while (0);
6170 +
6171 + do { /* PaX: patched PLT emulation #4 */
6172 + unsigned int sethi, mov1, call, mov2;
6173 +
6174 + err = get_user(sethi, (unsigned int *)regs->tpc);
6175 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6176 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6177 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6178 +
6179 + if (err)
6180 + break;
6181 +
6182 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6183 + mov1 == 0x8210000FU &&
6184 + (call & 0xC0000000U) == 0x40000000U &&
6185 + mov2 == 0x9E100001U)
6186 + {
6187 + unsigned long addr;
6188 +
6189 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6190 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6191 +
6192 + if (test_thread_flag(TIF_32BIT))
6193 + addr &= 0xFFFFFFFFUL;
6194 +
6195 + regs->tpc = addr;
6196 + regs->tnpc = addr+4;
6197 + return 2;
6198 + }
6199 + } while (0);
6200 +
6201 + do { /* PaX: patched PLT emulation #5 */
6202 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6203 +
6204 + err = get_user(sethi, (unsigned int *)regs->tpc);
6205 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6206 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6207 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6208 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6209 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6210 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6211 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6212 +
6213 + if (err)
6214 + break;
6215 +
6216 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6217 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6218 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6219 + (or1 & 0xFFFFE000U) == 0x82106000U &&
6220 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6221 + sllx == 0x83287020U &&
6222 + jmpl == 0x81C04005U &&
6223 + nop == 0x01000000U)
6224 + {
6225 + unsigned long addr;
6226 +
6227 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6228 + regs->u_regs[UREG_G1] <<= 32;
6229 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6230 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6231 + regs->tpc = addr;
6232 + regs->tnpc = addr+4;
6233 + return 2;
6234 + }
6235 + } while (0);
6236 +
6237 + do { /* PaX: patched PLT emulation #6 */
6238 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
6239 +
6240 + err = get_user(sethi, (unsigned int *)regs->tpc);
6241 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6242 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6243 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
6244 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
6245 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
6246 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
6247 +
6248 + if (err)
6249 + break;
6250 +
6251 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6252 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6253 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6254 + sllx == 0x83287020U &&
6255 + (or & 0xFFFFE000U) == 0x8A116000U &&
6256 + jmpl == 0x81C04005U &&
6257 + nop == 0x01000000U)
6258 + {
6259 + unsigned long addr;
6260 +
6261 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
6262 + regs->u_regs[UREG_G1] <<= 32;
6263 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
6264 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6265 + regs->tpc = addr;
6266 + regs->tnpc = addr+4;
6267 + return 2;
6268 + }
6269 + } while (0);
6270 +
6271 + do { /* PaX: unpatched PLT emulation step 1 */
6272 + unsigned int sethi, ba, nop;
6273 +
6274 + err = get_user(sethi, (unsigned int *)regs->tpc);
6275 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6276 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6277 +
6278 + if (err)
6279 + break;
6280 +
6281 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6282 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6283 + nop == 0x01000000U)
6284 + {
6285 + unsigned long addr;
6286 + unsigned int save, call;
6287 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
6288 +
6289 + if ((ba & 0xFFC00000U) == 0x30800000U)
6290 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6291 + else
6292 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6293 +
6294 + if (test_thread_flag(TIF_32BIT))
6295 + addr &= 0xFFFFFFFFUL;
6296 +
6297 + err = get_user(save, (unsigned int *)addr);
6298 + err |= get_user(call, (unsigned int *)(addr+4));
6299 + err |= get_user(nop, (unsigned int *)(addr+8));
6300 + if (err)
6301 + break;
6302 +
6303 +#ifdef CONFIG_PAX_DLRESOLVE
6304 + if (save == 0x9DE3BFA8U &&
6305 + (call & 0xC0000000U) == 0x40000000U &&
6306 + nop == 0x01000000U)
6307 + {
6308 + struct vm_area_struct *vma;
6309 + unsigned long call_dl_resolve;
6310 +
6311 + down_read(&current->mm->mmap_sem);
6312 + call_dl_resolve = current->mm->call_dl_resolve;
6313 + up_read(&current->mm->mmap_sem);
6314 + if (likely(call_dl_resolve))
6315 + goto emulate;
6316 +
6317 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6318 +
6319 + down_write(&current->mm->mmap_sem);
6320 + if (current->mm->call_dl_resolve) {
6321 + call_dl_resolve = current->mm->call_dl_resolve;
6322 + up_write(&current->mm->mmap_sem);
6323 + if (vma)
6324 + kmem_cache_free(vm_area_cachep, vma);
6325 + goto emulate;
6326 + }
6327 +
6328 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6329 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6330 + up_write(&current->mm->mmap_sem);
6331 + if (vma)
6332 + kmem_cache_free(vm_area_cachep, vma);
6333 + return 1;
6334 + }
6335 +
6336 + if (pax_insert_vma(vma, call_dl_resolve)) {
6337 + up_write(&current->mm->mmap_sem);
6338 + kmem_cache_free(vm_area_cachep, vma);
6339 + return 1;
6340 + }
6341 +
6342 + current->mm->call_dl_resolve = call_dl_resolve;
6343 + up_write(&current->mm->mmap_sem);
6344 +
6345 +emulate:
6346 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6347 + regs->tpc = call_dl_resolve;
6348 + regs->tnpc = addr+4;
6349 + return 3;
6350 + }
6351 +#endif
6352 +
6353 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6354 + if ((save & 0xFFC00000U) == 0x05000000U &&
6355 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6356 + nop == 0x01000000U)
6357 + {
6358 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6359 + regs->u_regs[UREG_G2] = addr + 4;
6360 + addr = (save & 0x003FFFFFU) << 10;
6361 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6362 +
6363 + if (test_thread_flag(TIF_32BIT))
6364 + addr &= 0xFFFFFFFFUL;
6365 +
6366 + regs->tpc = addr;
6367 + regs->tnpc = addr+4;
6368 + return 3;
6369 + }
6370 +
6371 + /* PaX: 64-bit PLT stub */
6372 + err = get_user(sethi1, (unsigned int *)addr);
6373 + err |= get_user(sethi2, (unsigned int *)(addr+4));
6374 + err |= get_user(or1, (unsigned int *)(addr+8));
6375 + err |= get_user(or2, (unsigned int *)(addr+12));
6376 + err |= get_user(sllx, (unsigned int *)(addr+16));
6377 + err |= get_user(add, (unsigned int *)(addr+20));
6378 + err |= get_user(jmpl, (unsigned int *)(addr+24));
6379 + err |= get_user(nop, (unsigned int *)(addr+28));
6380 + if (err)
6381 + break;
6382 +
6383 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
6384 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6385 + (or1 & 0xFFFFE000U) == 0x88112000U &&
6386 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6387 + sllx == 0x89293020U &&
6388 + add == 0x8A010005U &&
6389 + jmpl == 0x89C14000U &&
6390 + nop == 0x01000000U)
6391 + {
6392 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6393 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6394 + regs->u_regs[UREG_G4] <<= 32;
6395 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6396 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
6397 + regs->u_regs[UREG_G4] = addr + 24;
6398 + addr = regs->u_regs[UREG_G5];
6399 + regs->tpc = addr;
6400 + regs->tnpc = addr+4;
6401 + return 3;
6402 + }
6403 + }
6404 + } while (0);
6405 +
6406 +#ifdef CONFIG_PAX_DLRESOLVE
6407 + do { /* PaX: unpatched PLT emulation step 2 */
6408 + unsigned int save, call, nop;
6409 +
6410 + err = get_user(save, (unsigned int *)(regs->tpc-4));
6411 + err |= get_user(call, (unsigned int *)regs->tpc);
6412 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
6413 + if (err)
6414 + break;
6415 +
6416 + if (save == 0x9DE3BFA8U &&
6417 + (call & 0xC0000000U) == 0x40000000U &&
6418 + nop == 0x01000000U)
6419 + {
6420 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6421 +
6422 + if (test_thread_flag(TIF_32BIT))
6423 + dl_resolve &= 0xFFFFFFFFUL;
6424 +
6425 + regs->u_regs[UREG_RETPC] = regs->tpc;
6426 + regs->tpc = dl_resolve;
6427 + regs->tnpc = dl_resolve+4;
6428 + return 3;
6429 + }
6430 + } while (0);
6431 +#endif
6432 +
6433 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
6434 + unsigned int sethi, ba, nop;
6435 +
6436 + err = get_user(sethi, (unsigned int *)regs->tpc);
6437 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6438 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6439 +
6440 + if (err)
6441 + break;
6442 +
6443 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6444 + (ba & 0xFFF00000U) == 0x30600000U &&
6445 + nop == 0x01000000U)
6446 + {
6447 + unsigned long addr;
6448 +
6449 + addr = (sethi & 0x003FFFFFU) << 10;
6450 + regs->u_regs[UREG_G1] = addr;
6451 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6452 +
6453 + if (test_thread_flag(TIF_32BIT))
6454 + addr &= 0xFFFFFFFFUL;
6455 +
6456 + regs->tpc = addr;
6457 + regs->tnpc = addr+4;
6458 + return 2;
6459 + }
6460 + } while (0);
6461 +
6462 +#endif
6463 +
6464 + return 1;
6465 +}
6466 +
6467 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6468 +{
6469 + unsigned long i;
6470 +
6471 + printk(KERN_ERR "PAX: bytes at PC: ");
6472 + for (i = 0; i < 8; i++) {
6473 + unsigned int c;
6474 + if (get_user(c, (unsigned int *)pc+i))
6475 + printk(KERN_CONT "???????? ");
6476 + else
6477 + printk(KERN_CONT "%08x ", c);
6478 + }
6479 + printk("\n");
6480 +}
6481 +#endif
6482 +
6483 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6484 {
6485 struct mm_struct *mm = current->mm;
6486 @@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6487 if (!vma)
6488 goto bad_area;
6489
6490 +#ifdef CONFIG_PAX_PAGEEXEC
6491 + /* PaX: detect ITLB misses on non-exec pages */
6492 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
6493 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
6494 + {
6495 + if (address != regs->tpc)
6496 + goto good_area;
6497 +
6498 + up_read(&mm->mmap_sem);
6499 + switch (pax_handle_fetch_fault(regs)) {
6500 +
6501 +#ifdef CONFIG_PAX_EMUPLT
6502 + case 2:
6503 + case 3:
6504 + return;
6505 +#endif
6506 +
6507 + }
6508 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
6509 + do_group_exit(SIGKILL);
6510 + }
6511 +#endif
6512 +
6513 /* Pure DTLB misses do not tell us whether the fault causing
6514 * load/store/atomic was a write or not, it only says that there
6515 * was no match. So in such a case we (carefully) read the
6516 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
6517 index 07e1453..0a7d9e9 100644
6518 --- a/arch/sparc/mm/hugetlbpage.c
6519 +++ b/arch/sparc/mm/hugetlbpage.c
6520 @@ -67,7 +67,7 @@ full_search:
6521 }
6522 return -ENOMEM;
6523 }
6524 - if (likely(!vma || addr + len <= vma->vm_start)) {
6525 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6526 /*
6527 * Remember the place where we stopped the search:
6528 */
6529 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6530 /* make sure it can fit in the remaining address space */
6531 if (likely(addr > len)) {
6532 vma = find_vma(mm, addr-len);
6533 - if (!vma || addr <= vma->vm_start) {
6534 + if (check_heap_stack_gap(vma, addr - len, len)) {
6535 /* remember the address as a hint for next time */
6536 return (mm->free_area_cache = addr-len);
6537 }
6538 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6539 if (unlikely(mm->mmap_base < len))
6540 goto bottomup;
6541
6542 - addr = (mm->mmap_base-len) & HPAGE_MASK;
6543 + addr = mm->mmap_base - len;
6544
6545 do {
6546 + addr &= HPAGE_MASK;
6547 /*
6548 * Lookup failure means no vma is above this address,
6549 * else if new region fits below vma->vm_start,
6550 * return with success:
6551 */
6552 vma = find_vma(mm, addr);
6553 - if (likely(!vma || addr+len <= vma->vm_start)) {
6554 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6555 /* remember the address as a hint for next time */
6556 return (mm->free_area_cache = addr);
6557 }
6558 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6559 mm->cached_hole_size = vma->vm_start - addr;
6560
6561 /* try just below the current vma->vm_start */
6562 - addr = (vma->vm_start-len) & HPAGE_MASK;
6563 - } while (likely(len < vma->vm_start));
6564 + addr = skip_heap_stack_gap(vma, len);
6565 + } while (!IS_ERR_VALUE(addr));
6566
6567 bottomup:
6568 /*
6569 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
6570 if (addr) {
6571 addr = ALIGN(addr, HPAGE_SIZE);
6572 vma = find_vma(mm, addr);
6573 - if (task_size - len >= addr &&
6574 - (!vma || addr + len <= vma->vm_start))
6575 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
6576 return addr;
6577 }
6578 if (mm->get_unmapped_area == arch_get_unmapped_area)
6579 diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
6580 index 7b00de6..78239f4 100644
6581 --- a/arch/sparc/mm/init_32.c
6582 +++ b/arch/sparc/mm/init_32.c
6583 @@ -316,6 +316,9 @@ extern void device_scan(void);
6584 pgprot_t PAGE_SHARED __read_mostly;
6585 EXPORT_SYMBOL(PAGE_SHARED);
6586
6587 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
6588 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
6589 +
6590 void __init paging_init(void)
6591 {
6592 switch(sparc_cpu_model) {
6593 @@ -344,17 +347,17 @@ void __init paging_init(void)
6594
6595 /* Initialize the protection map with non-constant, MMU dependent values. */
6596 protection_map[0] = PAGE_NONE;
6597 - protection_map[1] = PAGE_READONLY;
6598 - protection_map[2] = PAGE_COPY;
6599 - protection_map[3] = PAGE_COPY;
6600 + protection_map[1] = PAGE_READONLY_NOEXEC;
6601 + protection_map[2] = PAGE_COPY_NOEXEC;
6602 + protection_map[3] = PAGE_COPY_NOEXEC;
6603 protection_map[4] = PAGE_READONLY;
6604 protection_map[5] = PAGE_READONLY;
6605 protection_map[6] = PAGE_COPY;
6606 protection_map[7] = PAGE_COPY;
6607 protection_map[8] = PAGE_NONE;
6608 - protection_map[9] = PAGE_READONLY;
6609 - protection_map[10] = PAGE_SHARED;
6610 - protection_map[11] = PAGE_SHARED;
6611 + protection_map[9] = PAGE_READONLY_NOEXEC;
6612 + protection_map[10] = PAGE_SHARED_NOEXEC;
6613 + protection_map[11] = PAGE_SHARED_NOEXEC;
6614 protection_map[12] = PAGE_READONLY;
6615 protection_map[13] = PAGE_READONLY;
6616 protection_map[14] = PAGE_SHARED;
6617 diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
6618 index cbef74e..c38fead 100644
6619 --- a/arch/sparc/mm/srmmu.c
6620 +++ b/arch/sparc/mm/srmmu.c
6621 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
6622 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
6623 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
6624 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
6625 +
6626 +#ifdef CONFIG_PAX_PAGEEXEC
6627 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
6628 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
6629 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
6630 +#endif
6631 +
6632 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
6633 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
6634
6635 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
6636 index 27fe667..36d474c 100644
6637 --- a/arch/tile/include/asm/atomic_64.h
6638 +++ b/arch/tile/include/asm/atomic_64.h
6639 @@ -142,6 +142,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
6640
6641 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6642
6643 +#define atomic64_read_unchecked(v) atomic64_read(v)
6644 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6645 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6646 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6647 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6648 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
6649 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6650 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
6651 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6652 +
6653 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
6654 #define smp_mb__before_atomic_dec() smp_mb()
6655 #define smp_mb__after_atomic_dec() smp_mb()
6656 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
6657 index 392e533..536b092 100644
6658 --- a/arch/tile/include/asm/cache.h
6659 +++ b/arch/tile/include/asm/cache.h
6660 @@ -15,11 +15,12 @@
6661 #ifndef _ASM_TILE_CACHE_H
6662 #define _ASM_TILE_CACHE_H
6663
6664 +#include <linux/const.h>
6665 #include <arch/chip.h>
6666
6667 /* bytes per L1 data cache line */
6668 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
6669 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6670 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6671
6672 /* bytes per L2 cache line */
6673 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
6674 diff --git a/arch/um/Makefile b/arch/um/Makefile
6675 index 7730af6..cce5b19 100644
6676 --- a/arch/um/Makefile
6677 +++ b/arch/um/Makefile
6678 @@ -61,6 +61,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
6679 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
6680 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
6681
6682 +ifdef CONSTIFY_PLUGIN
6683 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
6684 +endif
6685 +
6686 #This will adjust *FLAGS accordingly to the platform.
6687 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
6688
6689 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
6690 index 19e1bdd..3665b77 100644
6691 --- a/arch/um/include/asm/cache.h
6692 +++ b/arch/um/include/asm/cache.h
6693 @@ -1,6 +1,7 @@
6694 #ifndef __UM_CACHE_H
6695 #define __UM_CACHE_H
6696
6697 +#include <linux/const.h>
6698
6699 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
6700 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
6701 @@ -12,6 +13,6 @@
6702 # define L1_CACHE_SHIFT 5
6703 #endif
6704
6705 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6706 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6707
6708 #endif
6709 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
6710 index 6c03acd..a5e0215 100644
6711 --- a/arch/um/include/asm/kmap_types.h
6712 +++ b/arch/um/include/asm/kmap_types.h
6713 @@ -23,6 +23,7 @@ enum km_type {
6714 KM_IRQ1,
6715 KM_SOFTIRQ0,
6716 KM_SOFTIRQ1,
6717 + KM_CLEARPAGE,
6718 KM_TYPE_NR
6719 };
6720
6721 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
6722 index 7cfc3ce..cbd1a58 100644
6723 --- a/arch/um/include/asm/page.h
6724 +++ b/arch/um/include/asm/page.h
6725 @@ -14,6 +14,9 @@
6726 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
6727 #define PAGE_MASK (~(PAGE_SIZE-1))
6728
6729 +#define ktla_ktva(addr) (addr)
6730 +#define ktva_ktla(addr) (addr)
6731 +
6732 #ifndef __ASSEMBLY__
6733
6734 struct page;
6735 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
6736 index c533835..84db18e 100644
6737 --- a/arch/um/kernel/process.c
6738 +++ b/arch/um/kernel/process.c
6739 @@ -406,22 +406,6 @@ int singlestepping(void * t)
6740 return 2;
6741 }
6742
6743 -/*
6744 - * Only x86 and x86_64 have an arch_align_stack().
6745 - * All other arches have "#define arch_align_stack(x) (x)"
6746 - * in their asm/system.h
6747 - * As this is included in UML from asm-um/system-generic.h,
6748 - * we can use it to behave as the subarch does.
6749 - */
6750 -#ifndef arch_align_stack
6751 -unsigned long arch_align_stack(unsigned long sp)
6752 -{
6753 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6754 - sp -= get_random_int() % 8192;
6755 - return sp & ~0xf;
6756 -}
6757 -#endif
6758 -
6759 unsigned long get_wchan(struct task_struct *p)
6760 {
6761 unsigned long stack_page, sp, ip;
6762 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
6763 index ad8f795..2c7eec6 100644
6764 --- a/arch/unicore32/include/asm/cache.h
6765 +++ b/arch/unicore32/include/asm/cache.h
6766 @@ -12,8 +12,10 @@
6767 #ifndef __UNICORE_CACHE_H__
6768 #define __UNICORE_CACHE_H__
6769
6770 -#define L1_CACHE_SHIFT (5)
6771 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6772 +#include <linux/const.h>
6773 +
6774 +#define L1_CACHE_SHIFT 5
6775 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6776
6777 /*
6778 * Memory returned by kmalloc() may be used for DMA, so we must make
6779 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
6780 index efb4294..61bc18c 100644
6781 --- a/arch/x86/Kconfig
6782 +++ b/arch/x86/Kconfig
6783 @@ -235,7 +235,7 @@ config X86_HT
6784
6785 config X86_32_LAZY_GS
6786 def_bool y
6787 - depends on X86_32 && !CC_STACKPROTECTOR
6788 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
6789
6790 config ARCH_HWEIGHT_CFLAGS
6791 string
6792 @@ -1022,7 +1022,7 @@ choice
6793
6794 config NOHIGHMEM
6795 bool "off"
6796 - depends on !X86_NUMAQ
6797 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
6798 ---help---
6799 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
6800 However, the address space of 32-bit x86 processors is only 4
6801 @@ -1059,7 +1059,7 @@ config NOHIGHMEM
6802
6803 config HIGHMEM4G
6804 bool "4GB"
6805 - depends on !X86_NUMAQ
6806 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
6807 ---help---
6808 Select this if you have a 32-bit processor and between 1 and 4
6809 gigabytes of physical RAM.
6810 @@ -1113,7 +1113,7 @@ config PAGE_OFFSET
6811 hex
6812 default 0xB0000000 if VMSPLIT_3G_OPT
6813 default 0x80000000 if VMSPLIT_2G
6814 - default 0x78000000 if VMSPLIT_2G_OPT
6815 + default 0x70000000 if VMSPLIT_2G_OPT
6816 default 0x40000000 if VMSPLIT_1G
6817 default 0xC0000000
6818 depends on X86_32
6819 @@ -1496,6 +1496,7 @@ config SECCOMP
6820
6821 config CC_STACKPROTECTOR
6822 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
6823 + depends on X86_64 || !PAX_MEMORY_UDEREF
6824 ---help---
6825 This option turns on the -fstack-protector GCC feature. This
6826 feature puts, at the beginning of functions, a canary value on
6827 @@ -1553,6 +1554,7 @@ config KEXEC_JUMP
6828 config PHYSICAL_START
6829 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
6830 default "0x1000000"
6831 + range 0x400000 0x40000000
6832 ---help---
6833 This gives the physical address where the kernel is loaded.
6834
6835 @@ -1616,6 +1618,7 @@ config X86_NEED_RELOCS
6836 config PHYSICAL_ALIGN
6837 hex "Alignment value to which kernel should be aligned" if X86_32
6838 default "0x1000000"
6839 + range 0x400000 0x1000000 if PAX_KERNEXEC
6840 range 0x2000 0x1000000
6841 ---help---
6842 This value puts the alignment restrictions on physical address
6843 @@ -1647,9 +1650,10 @@ config HOTPLUG_CPU
6844 Say N if you want to disable CPU hotplug.
6845
6846 config COMPAT_VDSO
6847 - def_bool y
6848 + def_bool n
6849 prompt "Compat VDSO support"
6850 depends on X86_32 || IA32_EMULATION
6851 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
6852 ---help---
6853 Map the 32-bit VDSO to the predictable old-style address too.
6854
6855 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
6856 index e3ca7e0..b30b28a 100644
6857 --- a/arch/x86/Kconfig.cpu
6858 +++ b/arch/x86/Kconfig.cpu
6859 @@ -341,7 +341,7 @@ config X86_PPRO_FENCE
6860
6861 config X86_F00F_BUG
6862 def_bool y
6863 - depends on M586MMX || M586TSC || M586 || M486 || M386
6864 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
6865
6866 config X86_INVD_BUG
6867 def_bool y
6868 @@ -365,7 +365,7 @@ config X86_POPAD_OK
6869
6870 config X86_ALIGNMENT_16
6871 def_bool y
6872 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
6873 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
6874
6875 config X86_INTEL_USERCOPY
6876 def_bool y
6877 @@ -411,7 +411,7 @@ config X86_CMPXCHG64
6878 # generates cmov.
6879 config X86_CMOV
6880 def_bool y
6881 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
6882 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
6883
6884 config X86_MINIMUM_CPU_FAMILY
6885 int
6886 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
6887 index bf56e17..05f9891 100644
6888 --- a/arch/x86/Kconfig.debug
6889 +++ b/arch/x86/Kconfig.debug
6890 @@ -81,7 +81,7 @@ config X86_PTDUMP
6891 config DEBUG_RODATA
6892 bool "Write protect kernel read-only data structures"
6893 default y
6894 - depends on DEBUG_KERNEL
6895 + depends on DEBUG_KERNEL && BROKEN
6896 ---help---
6897 Mark the kernel read-only data as write-protected in the pagetables,
6898 in order to catch accidental (and incorrect) writes to such const
6899 @@ -99,7 +99,7 @@ config DEBUG_RODATA_TEST
6900
6901 config DEBUG_SET_MODULE_RONX
6902 bool "Set loadable kernel module data as NX and text as RO"
6903 - depends on MODULES
6904 + depends on MODULES && BROKEN
6905 ---help---
6906 This option helps catch unintended modifications to loadable
6907 kernel module's text and read-only data. It also prevents execution
6908 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
6909 index b02e509..2631e48 100644
6910 --- a/arch/x86/Makefile
6911 +++ b/arch/x86/Makefile
6912 @@ -46,6 +46,7 @@ else
6913 UTS_MACHINE := x86_64
6914 CHECKFLAGS += -D__x86_64__ -m64
6915
6916 + biarch := $(call cc-option,-m64)
6917 KBUILD_AFLAGS += -m64
6918 KBUILD_CFLAGS += -m64
6919
6920 @@ -195,3 +196,12 @@ define archhelp
6921 echo ' FDARGS="..." arguments for the booted kernel'
6922 echo ' FDINITRD=file initrd for the booted kernel'
6923 endef
6924 +
6925 +define OLD_LD
6926 +
6927 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
6928 +*** Please upgrade your binutils to 2.18 or newer
6929 +endef
6930 +
6931 +archprepare:
6932 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
6933 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
6934 index 95365a8..52f857b 100644
6935 --- a/arch/x86/boot/Makefile
6936 +++ b/arch/x86/boot/Makefile
6937 @@ -63,6 +63,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
6938 $(call cc-option, -fno-stack-protector) \
6939 $(call cc-option, -mpreferred-stack-boundary=2)
6940 KBUILD_CFLAGS += $(call cc-option, -m32)
6941 +ifdef CONSTIFY_PLUGIN
6942 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
6943 +endif
6944 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
6945 GCOV_PROFILE := n
6946
6947 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
6948 index 878e4b9..20537ab 100644
6949 --- a/arch/x86/boot/bitops.h
6950 +++ b/arch/x86/boot/bitops.h
6951 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
6952 u8 v;
6953 const u32 *p = (const u32 *)addr;
6954
6955 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
6956 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
6957 return v;
6958 }
6959
6960 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
6961
6962 static inline void set_bit(int nr, void *addr)
6963 {
6964 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
6965 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
6966 }
6967
6968 #endif /* BOOT_BITOPS_H */
6969 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
6970 index c7093bd..d4247ffe0 100644
6971 --- a/arch/x86/boot/boot.h
6972 +++ b/arch/x86/boot/boot.h
6973 @@ -85,7 +85,7 @@ static inline void io_delay(void)
6974 static inline u16 ds(void)
6975 {
6976 u16 seg;
6977 - asm("movw %%ds,%0" : "=rm" (seg));
6978 + asm volatile("movw %%ds,%0" : "=rm" (seg));
6979 return seg;
6980 }
6981
6982 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
6983 static inline int memcmp(const void *s1, const void *s2, size_t len)
6984 {
6985 u8 diff;
6986 - asm("repe; cmpsb; setnz %0"
6987 + asm volatile("repe; cmpsb; setnz %0"
6988 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
6989 return diff;
6990 }
6991 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
6992 index 09664ef..edc5d03 100644
6993 --- a/arch/x86/boot/compressed/Makefile
6994 +++ b/arch/x86/boot/compressed/Makefile
6995 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
6996 KBUILD_CFLAGS += $(cflags-y)
6997 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
6998 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
6999 +ifdef CONSTIFY_PLUGIN
7000 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7001 +endif
7002
7003 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7004 GCOV_PROFILE := n
7005 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7006 index 67a655a..b924059 100644
7007 --- a/arch/x86/boot/compressed/head_32.S
7008 +++ b/arch/x86/boot/compressed/head_32.S
7009 @@ -76,7 +76,7 @@ ENTRY(startup_32)
7010 notl %eax
7011 andl %eax, %ebx
7012 #else
7013 - movl $LOAD_PHYSICAL_ADDR, %ebx
7014 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7015 #endif
7016
7017 /* Target address to relocate to for decompression */
7018 @@ -162,7 +162,7 @@ relocated:
7019 * and where it was actually loaded.
7020 */
7021 movl %ebp, %ebx
7022 - subl $LOAD_PHYSICAL_ADDR, %ebx
7023 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7024 jz 2f /* Nothing to be done if loaded at compiled addr. */
7025 /*
7026 * Process relocations.
7027 @@ -170,8 +170,7 @@ relocated:
7028
7029 1: subl $4, %edi
7030 movl (%edi), %ecx
7031 - testl %ecx, %ecx
7032 - jz 2f
7033 + jecxz 2f
7034 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7035 jmp 1b
7036 2:
7037 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7038 index 35af09d..99c9676 100644
7039 --- a/arch/x86/boot/compressed/head_64.S
7040 +++ b/arch/x86/boot/compressed/head_64.S
7041 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7042 notl %eax
7043 andl %eax, %ebx
7044 #else
7045 - movl $LOAD_PHYSICAL_ADDR, %ebx
7046 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7047 #endif
7048
7049 /* Target address to relocate to for decompression */
7050 @@ -233,7 +233,7 @@ ENTRY(startup_64)
7051 notq %rax
7052 andq %rax, %rbp
7053 #else
7054 - movq $LOAD_PHYSICAL_ADDR, %rbp
7055 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7056 #endif
7057
7058 /* Target address to relocate to for decompression */
7059 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7060 index 3a19d04..7c1d55a 100644
7061 --- a/arch/x86/boot/compressed/misc.c
7062 +++ b/arch/x86/boot/compressed/misc.c
7063 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7064 case PT_LOAD:
7065 #ifdef CONFIG_RELOCATABLE
7066 dest = output;
7067 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7068 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7069 #else
7070 dest = (void *)(phdr->p_paddr);
7071 #endif
7072 @@ -363,7 +363,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7073 error("Destination address too large");
7074 #endif
7075 #ifndef CONFIG_RELOCATABLE
7076 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7077 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7078 error("Wrong destination address");
7079 #endif
7080
7081 diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
7082 index 89bbf4e..869908e 100644
7083 --- a/arch/x86/boot/compressed/relocs.c
7084 +++ b/arch/x86/boot/compressed/relocs.c
7085 @@ -13,8 +13,11 @@
7086
7087 static void die(char *fmt, ...);
7088
7089 +#include "../../../../include/generated/autoconf.h"
7090 +
7091 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
7092 static Elf32_Ehdr ehdr;
7093 +static Elf32_Phdr *phdr;
7094 static unsigned long reloc_count, reloc_idx;
7095 static unsigned long *relocs;
7096
7097 @@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
7098 }
7099 }
7100
7101 +static void read_phdrs(FILE *fp)
7102 +{
7103 + unsigned int i;
7104 +
7105 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
7106 + if (!phdr) {
7107 + die("Unable to allocate %d program headers\n",
7108 + ehdr.e_phnum);
7109 + }
7110 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
7111 + die("Seek to %d failed: %s\n",
7112 + ehdr.e_phoff, strerror(errno));
7113 + }
7114 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
7115 + die("Cannot read ELF program headers: %s\n",
7116 + strerror(errno));
7117 + }
7118 + for(i = 0; i < ehdr.e_phnum; i++) {
7119 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
7120 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
7121 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
7122 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
7123 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
7124 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
7125 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
7126 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
7127 + }
7128 +
7129 +}
7130 +
7131 static void read_shdrs(FILE *fp)
7132 {
7133 - int i;
7134 + unsigned int i;
7135 Elf32_Shdr shdr;
7136
7137 secs = calloc(ehdr.e_shnum, sizeof(struct section));
7138 @@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
7139
7140 static void read_strtabs(FILE *fp)
7141 {
7142 - int i;
7143 + unsigned int i;
7144 for (i = 0; i < ehdr.e_shnum; i++) {
7145 struct section *sec = &secs[i];
7146 if (sec->shdr.sh_type != SHT_STRTAB) {
7147 @@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
7148
7149 static void read_symtabs(FILE *fp)
7150 {
7151 - int i,j;
7152 + unsigned int i,j;
7153 for (i = 0; i < ehdr.e_shnum; i++) {
7154 struct section *sec = &secs[i];
7155 if (sec->shdr.sh_type != SHT_SYMTAB) {
7156 @@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
7157
7158 static void read_relocs(FILE *fp)
7159 {
7160 - int i,j;
7161 + unsigned int i,j;
7162 + uint32_t base;
7163 +
7164 for (i = 0; i < ehdr.e_shnum; i++) {
7165 struct section *sec = &secs[i];
7166 if (sec->shdr.sh_type != SHT_REL) {
7167 @@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
7168 die("Cannot read symbol table: %s\n",
7169 strerror(errno));
7170 }
7171 + base = 0;
7172 + for (j = 0; j < ehdr.e_phnum; j++) {
7173 + if (phdr[j].p_type != PT_LOAD )
7174 + continue;
7175 + 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)
7176 + continue;
7177 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
7178 + break;
7179 + }
7180 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
7181 Elf32_Rel *rel = &sec->reltab[j];
7182 - rel->r_offset = elf32_to_cpu(rel->r_offset);
7183 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
7184 rel->r_info = elf32_to_cpu(rel->r_info);
7185 }
7186 }
7187 @@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
7188
7189 static void print_absolute_symbols(void)
7190 {
7191 - int i;
7192 + unsigned int i;
7193 printf("Absolute symbols\n");
7194 printf(" Num: Value Size Type Bind Visibility Name\n");
7195 for (i = 0; i < ehdr.e_shnum; i++) {
7196 struct section *sec = &secs[i];
7197 char *sym_strtab;
7198 Elf32_Sym *sh_symtab;
7199 - int j;
7200 + unsigned int j;
7201
7202 if (sec->shdr.sh_type != SHT_SYMTAB) {
7203 continue;
7204 @@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
7205
7206 static void print_absolute_relocs(void)
7207 {
7208 - int i, printed = 0;
7209 + unsigned int i, printed = 0;
7210
7211 for (i = 0; i < ehdr.e_shnum; i++) {
7212 struct section *sec = &secs[i];
7213 struct section *sec_applies, *sec_symtab;
7214 char *sym_strtab;
7215 Elf32_Sym *sh_symtab;
7216 - int j;
7217 + unsigned int j;
7218 if (sec->shdr.sh_type != SHT_REL) {
7219 continue;
7220 }
7221 @@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
7222
7223 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7224 {
7225 - int i;
7226 + unsigned int i;
7227 /* Walk through the relocations */
7228 for (i = 0; i < ehdr.e_shnum; i++) {
7229 char *sym_strtab;
7230 Elf32_Sym *sh_symtab;
7231 struct section *sec_applies, *sec_symtab;
7232 - int j;
7233 + unsigned int j;
7234 struct section *sec = &secs[i];
7235
7236 if (sec->shdr.sh_type != SHT_REL) {
7237 @@ -530,6 +574,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7238 !is_rel_reloc(sym_name(sym_strtab, sym))) {
7239 continue;
7240 }
7241 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
7242 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
7243 + continue;
7244 +
7245 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
7246 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
7247 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
7248 + continue;
7249 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
7250 + continue;
7251 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
7252 + continue;
7253 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
7254 + continue;
7255 +#endif
7256 +
7257 switch (r_type) {
7258 case R_386_NONE:
7259 case R_386_PC32:
7260 @@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, const void *vb)
7261
7262 static void emit_relocs(int as_text)
7263 {
7264 - int i;
7265 + unsigned int i;
7266 /* Count how many relocations I have and allocate space for them. */
7267 reloc_count = 0;
7268 walk_relocs(count_reloc);
7269 @@ -665,6 +725,7 @@ int main(int argc, char **argv)
7270 fname, strerror(errno));
7271 }
7272 read_ehdr(fp);
7273 + read_phdrs(fp);
7274 read_shdrs(fp);
7275 read_strtabs(fp);
7276 read_symtabs(fp);
7277 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7278 index 4d3ff03..e4972ff 100644
7279 --- a/arch/x86/boot/cpucheck.c
7280 +++ b/arch/x86/boot/cpucheck.c
7281 @@ -74,7 +74,7 @@ static int has_fpu(void)
7282 u16 fcw = -1, fsw = -1;
7283 u32 cr0;
7284
7285 - asm("movl %%cr0,%0" : "=r" (cr0));
7286 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7287 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7288 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7289 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7290 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7291 {
7292 u32 f0, f1;
7293
7294 - asm("pushfl ; "
7295 + asm volatile("pushfl ; "
7296 "pushfl ; "
7297 "popl %0 ; "
7298 "movl %0,%1 ; "
7299 @@ -115,7 +115,7 @@ static void get_flags(void)
7300 set_bit(X86_FEATURE_FPU, cpu.flags);
7301
7302 if (has_eflag(X86_EFLAGS_ID)) {
7303 - asm("cpuid"
7304 + asm volatile("cpuid"
7305 : "=a" (max_intel_level),
7306 "=b" (cpu_vendor[0]),
7307 "=d" (cpu_vendor[1]),
7308 @@ -124,7 +124,7 @@ static void get_flags(void)
7309
7310 if (max_intel_level >= 0x00000001 &&
7311 max_intel_level <= 0x0000ffff) {
7312 - asm("cpuid"
7313 + asm volatile("cpuid"
7314 : "=a" (tfms),
7315 "=c" (cpu.flags[4]),
7316 "=d" (cpu.flags[0])
7317 @@ -136,7 +136,7 @@ static void get_flags(void)
7318 cpu.model += ((tfms >> 16) & 0xf) << 4;
7319 }
7320
7321 - asm("cpuid"
7322 + asm volatile("cpuid"
7323 : "=a" (max_amd_level)
7324 : "a" (0x80000000)
7325 : "ebx", "ecx", "edx");
7326 @@ -144,7 +144,7 @@ static void get_flags(void)
7327 if (max_amd_level >= 0x80000001 &&
7328 max_amd_level <= 0x8000ffff) {
7329 u32 eax = 0x80000001;
7330 - asm("cpuid"
7331 + asm volatile("cpuid"
7332 : "+a" (eax),
7333 "=c" (cpu.flags[6]),
7334 "=d" (cpu.flags[1])
7335 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7336 u32 ecx = MSR_K7_HWCR;
7337 u32 eax, edx;
7338
7339 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7340 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7341 eax &= ~(1 << 15);
7342 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7343 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7344
7345 get_flags(); /* Make sure it really did something */
7346 err = check_flags();
7347 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7348 u32 ecx = MSR_VIA_FCR;
7349 u32 eax, edx;
7350
7351 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7352 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7353 eax |= (1<<1)|(1<<7);
7354 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7355 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7356
7357 set_bit(X86_FEATURE_CX8, cpu.flags);
7358 err = check_flags();
7359 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7360 u32 eax, edx;
7361 u32 level = 1;
7362
7363 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7364 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7365 - asm("cpuid"
7366 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7367 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7368 + asm volatile("cpuid"
7369 : "+a" (level), "=d" (cpu.flags[0])
7370 : : "ecx", "ebx");
7371 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7372 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7373
7374 err = check_flags();
7375 }
7376 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7377 index bdb4d45..0476680 100644
7378 --- a/arch/x86/boot/header.S
7379 +++ b/arch/x86/boot/header.S
7380 @@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
7381 # single linked list of
7382 # struct setup_data
7383
7384 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7385 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7386
7387 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7388 #define VO_INIT_SIZE (VO__end - VO__text)
7389 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7390 index db75d07..8e6d0af 100644
7391 --- a/arch/x86/boot/memory.c
7392 +++ b/arch/x86/boot/memory.c
7393 @@ -19,7 +19,7 @@
7394
7395 static int detect_memory_e820(void)
7396 {
7397 - int count = 0;
7398 + unsigned int count = 0;
7399 struct biosregs ireg, oreg;
7400 struct e820entry *desc = boot_params.e820_map;
7401 static struct e820entry buf; /* static so it is zeroed */
7402 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
7403 index 11e8c6e..fdbb1ed 100644
7404 --- a/arch/x86/boot/video-vesa.c
7405 +++ b/arch/x86/boot/video-vesa.c
7406 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7407
7408 boot_params.screen_info.vesapm_seg = oreg.es;
7409 boot_params.screen_info.vesapm_off = oreg.di;
7410 + boot_params.screen_info.vesapm_size = oreg.cx;
7411 }
7412
7413 /*
7414 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
7415 index 43eda28..5ab5fdb 100644
7416 --- a/arch/x86/boot/video.c
7417 +++ b/arch/x86/boot/video.c
7418 @@ -96,7 +96,7 @@ static void store_mode_params(void)
7419 static unsigned int get_entry(void)
7420 {
7421 char entry_buf[4];
7422 - int i, len = 0;
7423 + unsigned int i, len = 0;
7424 int key;
7425 unsigned int v;
7426
7427 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
7428 index 5b577d5..3c1fed4 100644
7429 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
7430 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
7431 @@ -8,6 +8,8 @@
7432 * including this sentence is retained in full.
7433 */
7434
7435 +#include <asm/alternative-asm.h>
7436 +
7437 .extern crypto_ft_tab
7438 .extern crypto_it_tab
7439 .extern crypto_fl_tab
7440 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
7441 je B192; \
7442 leaq 32(r9),r9;
7443
7444 +#define ret pax_force_retaddr 0, 1; ret
7445 +
7446 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
7447 movq r1,r2; \
7448 movq r3,r4; \
7449 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
7450 index be6d9e3..21fbbca 100644
7451 --- a/arch/x86/crypto/aesni-intel_asm.S
7452 +++ b/arch/x86/crypto/aesni-intel_asm.S
7453 @@ -31,6 +31,7 @@
7454
7455 #include <linux/linkage.h>
7456 #include <asm/inst.h>
7457 +#include <asm/alternative-asm.h>
7458
7459 #ifdef __x86_64__
7460 .data
7461 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
7462 pop %r14
7463 pop %r13
7464 pop %r12
7465 + pax_force_retaddr 0, 1
7466 ret
7467 +ENDPROC(aesni_gcm_dec)
7468
7469
7470 /*****************************************************************************
7471 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
7472 pop %r14
7473 pop %r13
7474 pop %r12
7475 + pax_force_retaddr 0, 1
7476 ret
7477 +ENDPROC(aesni_gcm_enc)
7478
7479 #endif
7480
7481 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
7482 pxor %xmm1, %xmm0
7483 movaps %xmm0, (TKEYP)
7484 add $0x10, TKEYP
7485 + pax_force_retaddr_bts
7486 ret
7487
7488 .align 4
7489 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
7490 shufps $0b01001110, %xmm2, %xmm1
7491 movaps %xmm1, 0x10(TKEYP)
7492 add $0x20, TKEYP
7493 + pax_force_retaddr_bts
7494 ret
7495
7496 .align 4
7497 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
7498
7499 movaps %xmm0, (TKEYP)
7500 add $0x10, TKEYP
7501 + pax_force_retaddr_bts
7502 ret
7503
7504 .align 4
7505 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
7506 pxor %xmm1, %xmm2
7507 movaps %xmm2, (TKEYP)
7508 add $0x10, TKEYP
7509 + pax_force_retaddr_bts
7510 ret
7511
7512 /*
7513 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
7514 #ifndef __x86_64__
7515 popl KEYP
7516 #endif
7517 + pax_force_retaddr 0, 1
7518 ret
7519 +ENDPROC(aesni_set_key)
7520
7521 /*
7522 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
7523 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
7524 popl KLEN
7525 popl KEYP
7526 #endif
7527 + pax_force_retaddr 0, 1
7528 ret
7529 +ENDPROC(aesni_enc)
7530
7531 /*
7532 * _aesni_enc1: internal ABI
7533 @@ -1959,6 +1972,7 @@ _aesni_enc1:
7534 AESENC KEY STATE
7535 movaps 0x70(TKEYP), KEY
7536 AESENCLAST KEY STATE
7537 + pax_force_retaddr_bts
7538 ret
7539
7540 /*
7541 @@ -2067,6 +2081,7 @@ _aesni_enc4:
7542 AESENCLAST KEY STATE2
7543 AESENCLAST KEY STATE3
7544 AESENCLAST KEY STATE4
7545 + pax_force_retaddr_bts
7546 ret
7547
7548 /*
7549 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
7550 popl KLEN
7551 popl KEYP
7552 #endif
7553 + pax_force_retaddr 0, 1
7554 ret
7555 +ENDPROC(aesni_dec)
7556
7557 /*
7558 * _aesni_dec1: internal ABI
7559 @@ -2146,6 +2163,7 @@ _aesni_dec1:
7560 AESDEC KEY STATE
7561 movaps 0x70(TKEYP), KEY
7562 AESDECLAST KEY STATE
7563 + pax_force_retaddr_bts
7564 ret
7565
7566 /*
7567 @@ -2254,6 +2272,7 @@ _aesni_dec4:
7568 AESDECLAST KEY STATE2
7569 AESDECLAST KEY STATE3
7570 AESDECLAST KEY STATE4
7571 + pax_force_retaddr_bts
7572 ret
7573
7574 /*
7575 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
7576 popl KEYP
7577 popl LEN
7578 #endif
7579 + pax_force_retaddr 0, 1
7580 ret
7581 +ENDPROC(aesni_ecb_enc)
7582
7583 /*
7584 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7585 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
7586 popl KEYP
7587 popl LEN
7588 #endif
7589 + pax_force_retaddr 0, 1
7590 ret
7591 +ENDPROC(aesni_ecb_dec)
7592
7593 /*
7594 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7595 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
7596 popl LEN
7597 popl IVP
7598 #endif
7599 + pax_force_retaddr 0, 1
7600 ret
7601 +ENDPROC(aesni_cbc_enc)
7602
7603 /*
7604 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7605 @@ -2498,7 +2523,9 @@ ENTRY(aesni_cbc_dec)
7606 popl LEN
7607 popl IVP
7608 #endif
7609 + pax_force_retaddr 0, 1
7610 ret
7611 +ENDPROC(aesni_cbc_dec)
7612
7613 #ifdef __x86_64__
7614 .align 16
7615 @@ -2524,6 +2551,7 @@ _aesni_inc_init:
7616 mov $1, TCTR_LOW
7617 MOVQ_R64_XMM TCTR_LOW INC
7618 MOVQ_R64_XMM CTR TCTR_LOW
7619 + pax_force_retaddr_bts
7620 ret
7621
7622 /*
7623 @@ -2552,6 +2580,7 @@ _aesni_inc:
7624 .Linc_low:
7625 movaps CTR, IV
7626 PSHUFB_XMM BSWAP_MASK IV
7627 + pax_force_retaddr_bts
7628 ret
7629
7630 /*
7631 @@ -2612,5 +2641,7 @@ ENTRY(aesni_ctr_enc)
7632 .Lctr_enc_ret:
7633 movups IV, (IVP)
7634 .Lctr_enc_just_ret:
7635 + pax_force_retaddr 0, 1
7636 ret
7637 +ENDPROC(aesni_ctr_enc)
7638 #endif
7639 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
7640 index 391d245..67f35c2 100644
7641 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
7642 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
7643 @@ -20,6 +20,8 @@
7644 *
7645 */
7646
7647 +#include <asm/alternative-asm.h>
7648 +
7649 .file "blowfish-x86_64-asm.S"
7650 .text
7651
7652 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
7653 jnz __enc_xor;
7654
7655 write_block();
7656 + pax_force_retaddr 0, 1
7657 ret;
7658 __enc_xor:
7659 xor_block();
7660 + pax_force_retaddr 0, 1
7661 ret;
7662
7663 .align 8
7664 @@ -188,6 +192,7 @@ blowfish_dec_blk:
7665
7666 movq %r11, %rbp;
7667
7668 + pax_force_retaddr 0, 1
7669 ret;
7670
7671 /**********************************************************************
7672 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
7673
7674 popq %rbx;
7675 popq %rbp;
7676 + pax_force_retaddr 0, 1
7677 ret;
7678
7679 __enc_xor4:
7680 @@ -349,6 +355,7 @@ __enc_xor4:
7681
7682 popq %rbx;
7683 popq %rbp;
7684 + pax_force_retaddr 0, 1
7685 ret;
7686
7687 .align 8
7688 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
7689 popq %rbx;
7690 popq %rbp;
7691
7692 + pax_force_retaddr 0, 1
7693 ret;
7694
7695 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
7696 index 6214a9b..1f4fc9a 100644
7697 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
7698 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
7699 @@ -1,3 +1,5 @@
7700 +#include <asm/alternative-asm.h>
7701 +
7702 # enter ECRYPT_encrypt_bytes
7703 .text
7704 .p2align 5
7705 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
7706 add %r11,%rsp
7707 mov %rdi,%rax
7708 mov %rsi,%rdx
7709 + pax_force_retaddr 0, 1
7710 ret
7711 # bytesatleast65:
7712 ._bytesatleast65:
7713 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
7714 add %r11,%rsp
7715 mov %rdi,%rax
7716 mov %rsi,%rdx
7717 + pax_force_retaddr
7718 ret
7719 # enter ECRYPT_ivsetup
7720 .text
7721 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
7722 add %r11,%rsp
7723 mov %rdi,%rax
7724 mov %rsi,%rdx
7725 + pax_force_retaddr
7726 ret
7727 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
7728 index b2c2f57..8470cab 100644
7729 --- a/arch/x86/crypto/sha1_ssse3_asm.S
7730 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
7731 @@ -28,6 +28,8 @@
7732 * (at your option) any later version.
7733 */
7734
7735 +#include <asm/alternative-asm.h>
7736 +
7737 #define CTX %rdi // arg1
7738 #define BUF %rsi // arg2
7739 #define CNT %rdx // arg3
7740 @@ -104,6 +106,7 @@
7741 pop %r12
7742 pop %rbp
7743 pop %rbx
7744 + pax_force_retaddr 0, 1
7745 ret
7746
7747 .size \name, .-\name
7748 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
7749 index 5b012a2..36d5364 100644
7750 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
7751 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
7752 @@ -20,6 +20,8 @@
7753 *
7754 */
7755
7756 +#include <asm/alternative-asm.h>
7757 +
7758 .file "twofish-x86_64-asm-3way.S"
7759 .text
7760
7761 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
7762 popq %r13;
7763 popq %r14;
7764 popq %r15;
7765 + pax_force_retaddr 0, 1
7766 ret;
7767
7768 __enc_xor3:
7769 @@ -271,6 +274,7 @@ __enc_xor3:
7770 popq %r13;
7771 popq %r14;
7772 popq %r15;
7773 + pax_force_retaddr 0, 1
7774 ret;
7775
7776 .global twofish_dec_blk_3way
7777 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
7778 popq %r13;
7779 popq %r14;
7780 popq %r15;
7781 + pax_force_retaddr 0, 1
7782 ret;
7783
7784 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
7785 index 7bcf3fc..f53832f 100644
7786 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
7787 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
7788 @@ -21,6 +21,7 @@
7789 .text
7790
7791 #include <asm/asm-offsets.h>
7792 +#include <asm/alternative-asm.h>
7793
7794 #define a_offset 0
7795 #define b_offset 4
7796 @@ -268,6 +269,7 @@ twofish_enc_blk:
7797
7798 popq R1
7799 movq $1,%rax
7800 + pax_force_retaddr 0, 1
7801 ret
7802
7803 twofish_dec_blk:
7804 @@ -319,4 +321,5 @@ twofish_dec_blk:
7805
7806 popq R1
7807 movq $1,%rax
7808 + pax_force_retaddr 0, 1
7809 ret
7810 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
7811 index fd84387..887aa7e 100644
7812 --- a/arch/x86/ia32/ia32_aout.c
7813 +++ b/arch/x86/ia32/ia32_aout.c
7814 @@ -162,6 +162,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
7815 unsigned long dump_start, dump_size;
7816 struct user32 dump;
7817
7818 + memset(&dump, 0, sizeof(dump));
7819 +
7820 fs = get_fs();
7821 set_fs(KERNEL_DS);
7822 has_dumped = 1;
7823 @@ -315,6 +317,13 @@ static int load_aout_binary(struct linux_binprm *bprm, struct pt_regs *regs)
7824 current->mm->free_area_cache = TASK_UNMAPPED_BASE;
7825 current->mm->cached_hole_size = 0;
7826
7827 + retval = setup_arg_pages(bprm, IA32_STACK_TOP, EXSTACK_DEFAULT);
7828 + if (retval < 0) {
7829 + /* Someone check-me: is this error path enough? */
7830 + send_sig(SIGKILL, current, 0);
7831 + return retval;
7832 + }
7833 +
7834 install_exec_creds(bprm);
7835 current->flags &= ~PF_FORKNOEXEC;
7836
7837 @@ -410,13 +419,6 @@ beyond_if:
7838
7839 set_brk(current->mm->start_brk, current->mm->brk);
7840
7841 - retval = setup_arg_pages(bprm, IA32_STACK_TOP, EXSTACK_DEFAULT);
7842 - if (retval < 0) {
7843 - /* Someone check-me: is this error path enough? */
7844 - send_sig(SIGKILL, current, 0);
7845 - return retval;
7846 - }
7847 -
7848 current->mm->start_stack =
7849 (unsigned long)create_aout_tables((char __user *)bprm->p, bprm);
7850 /* start thread */
7851 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
7852 index 6557769..ef6ae89 100644
7853 --- a/arch/x86/ia32/ia32_signal.c
7854 +++ b/arch/x86/ia32/ia32_signal.c
7855 @@ -169,7 +169,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
7856 }
7857 seg = get_fs();
7858 set_fs(KERNEL_DS);
7859 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
7860 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
7861 set_fs(seg);
7862 if (ret >= 0 && uoss_ptr) {
7863 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
7864 @@ -370,7 +370,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
7865 */
7866 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
7867 size_t frame_size,
7868 - void **fpstate)
7869 + void __user **fpstate)
7870 {
7871 unsigned long sp;
7872
7873 @@ -391,7 +391,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
7874
7875 if (used_math()) {
7876 sp = sp - sig_xstate_ia32_size;
7877 - *fpstate = (struct _fpstate_ia32 *) sp;
7878 + *fpstate = (struct _fpstate_ia32 __user *) sp;
7879 if (save_i387_xstate_ia32(*fpstate) < 0)
7880 return (void __user *) -1L;
7881 }
7882 @@ -399,7 +399,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
7883 sp -= frame_size;
7884 /* Align the stack pointer according to the i386 ABI,
7885 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
7886 - sp = ((sp + 4) & -16ul) - 4;
7887 + sp = ((sp - 12) & -16ul) - 4;
7888 return (void __user *) sp;
7889 }
7890
7891 @@ -457,7 +457,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
7892 * These are actually not used anymore, but left because some
7893 * gdb versions depend on them as a marker.
7894 */
7895 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
7896 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
7897 } put_user_catch(err);
7898
7899 if (err)
7900 @@ -499,7 +499,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
7901 0xb8,
7902 __NR_ia32_rt_sigreturn,
7903 0x80cd,
7904 - 0,
7905 + 0
7906 };
7907
7908 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
7909 @@ -529,16 +529,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
7910
7911 if (ka->sa.sa_flags & SA_RESTORER)
7912 restorer = ka->sa.sa_restorer;
7913 + else if (current->mm->context.vdso)
7914 + /* Return stub is in 32bit vsyscall page */
7915 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
7916 else
7917 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
7918 - rt_sigreturn);
7919 + restorer = &frame->retcode;
7920 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
7921
7922 /*
7923 * Not actually used anymore, but left because some gdb
7924 * versions need it.
7925 */
7926 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
7927 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
7928 } put_user_catch(err);
7929
7930 if (err)
7931 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
7932 index a6253ec..4ad2120 100644
7933 --- a/arch/x86/ia32/ia32entry.S
7934 +++ b/arch/x86/ia32/ia32entry.S
7935 @@ -13,7 +13,9 @@
7936 #include <asm/thread_info.h>
7937 #include <asm/segment.h>
7938 #include <asm/irqflags.h>
7939 +#include <asm/pgtable.h>
7940 #include <linux/linkage.h>
7941 +#include <asm/alternative-asm.h>
7942
7943 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
7944 #include <linux/elf-em.h>
7945 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
7946 ENDPROC(native_irq_enable_sysexit)
7947 #endif
7948
7949 + .macro pax_enter_kernel_user
7950 + pax_set_fptr_mask
7951 +#ifdef CONFIG_PAX_MEMORY_UDEREF
7952 + call pax_enter_kernel_user
7953 +#endif
7954 + .endm
7955 +
7956 + .macro pax_exit_kernel_user
7957 +#ifdef CONFIG_PAX_MEMORY_UDEREF
7958 + call pax_exit_kernel_user
7959 +#endif
7960 +#ifdef CONFIG_PAX_RANDKSTACK
7961 + pushq %rax
7962 + pushq %r11
7963 + call pax_randomize_kstack
7964 + popq %r11
7965 + popq %rax
7966 +#endif
7967 + .endm
7968 +
7969 +.macro pax_erase_kstack
7970 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
7971 + call pax_erase_kstack
7972 +#endif
7973 +.endm
7974 +
7975 /*
7976 * 32bit SYSENTER instruction entry.
7977 *
7978 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
7979 CFI_REGISTER rsp,rbp
7980 SWAPGS_UNSAFE_STACK
7981 movq PER_CPU_VAR(kernel_stack), %rsp
7982 - addq $(KERNEL_STACK_OFFSET),%rsp
7983 - /*
7984 - * No need to follow this irqs on/off section: the syscall
7985 - * disabled irqs, here we enable it straight after entry:
7986 - */
7987 - ENABLE_INTERRUPTS(CLBR_NONE)
7988 movl %ebp,%ebp /* zero extension */
7989 pushq_cfi $__USER32_DS
7990 /*CFI_REL_OFFSET ss,0*/
7991 @@ -134,25 +156,39 @@ ENTRY(ia32_sysenter_target)
7992 CFI_REL_OFFSET rsp,0
7993 pushfq_cfi
7994 /*CFI_REL_OFFSET rflags,0*/
7995 - movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
7996 - CFI_REGISTER rip,r10
7997 + orl $X86_EFLAGS_IF,(%rsp)
7998 + GET_THREAD_INFO(%r11)
7999 + movl TI_sysenter_return(%r11), %r11d
8000 + CFI_REGISTER rip,r11
8001 pushq_cfi $__USER32_CS
8002 /*CFI_REL_OFFSET cs,0*/
8003 movl %eax, %eax
8004 - pushq_cfi %r10
8005 + pushq_cfi %r11
8006 CFI_REL_OFFSET rip,0
8007 pushq_cfi %rax
8008 cld
8009 SAVE_ARGS 0,1,0
8010 + pax_enter_kernel_user
8011 + /*
8012 + * No need to follow this irqs on/off section: the syscall
8013 + * disabled irqs, here we enable it straight after entry:
8014 + */
8015 + ENABLE_INTERRUPTS(CLBR_NONE)
8016 /* no need to do an access_ok check here because rbp has been
8017 32bit zero extended */
8018 +
8019 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8020 + mov $PAX_USER_SHADOW_BASE,%r11
8021 + add %r11,%rbp
8022 +#endif
8023 +
8024 1: movl (%rbp),%ebp
8025 .section __ex_table,"a"
8026 .quad 1b,ia32_badarg
8027 .previous
8028 - GET_THREAD_INFO(%r10)
8029 - orl $TS_COMPAT,TI_status(%r10)
8030 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
8031 + GET_THREAD_INFO(%r11)
8032 + orl $TS_COMPAT,TI_status(%r11)
8033 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8034 CFI_REMEMBER_STATE
8035 jnz sysenter_tracesys
8036 cmpq $(IA32_NR_syscalls-1),%rax
8037 @@ -162,13 +198,15 @@ sysenter_do_call:
8038 sysenter_dispatch:
8039 call *ia32_sys_call_table(,%rax,8)
8040 movq %rax,RAX-ARGOFFSET(%rsp)
8041 - GET_THREAD_INFO(%r10)
8042 + GET_THREAD_INFO(%r11)
8043 DISABLE_INTERRUPTS(CLBR_NONE)
8044 TRACE_IRQS_OFF
8045 - testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
8046 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8047 jnz sysexit_audit
8048 sysexit_from_sys_call:
8049 - andl $~TS_COMPAT,TI_status(%r10)
8050 + pax_exit_kernel_user
8051 + pax_erase_kstack
8052 + andl $~TS_COMPAT,TI_status(%r11)
8053 /* clear IF, that popfq doesn't enable interrupts early */
8054 andl $~0x200,EFLAGS-R11(%rsp)
8055 movl RIP-R11(%rsp),%edx /* User %eip */
8056 @@ -194,6 +232,9 @@ sysexit_from_sys_call:
8057 movl %eax,%esi /* 2nd arg: syscall number */
8058 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8059 call audit_syscall_entry
8060 +
8061 + pax_erase_kstack
8062 +
8063 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8064 cmpq $(IA32_NR_syscalls-1),%rax
8065 ja ia32_badsys
8066 @@ -205,7 +246,7 @@ sysexit_from_sys_call:
8067 .endm
8068
8069 .macro auditsys_exit exit
8070 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
8071 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8072 jnz ia32_ret_from_sys_call
8073 TRACE_IRQS_ON
8074 sti
8075 @@ -215,12 +256,12 @@ sysexit_from_sys_call:
8076 movzbl %al,%edi /* zero-extend that into %edi */
8077 inc %edi /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
8078 call audit_syscall_exit
8079 - GET_THREAD_INFO(%r10)
8080 + GET_THREAD_INFO(%r11)
8081 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall return value */
8082 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8083 cli
8084 TRACE_IRQS_OFF
8085 - testl %edi,TI_flags(%r10)
8086 + testl %edi,TI_flags(%r11)
8087 jz \exit
8088 CLEAR_RREGS -ARGOFFSET
8089 jmp int_with_check
8090 @@ -238,7 +279,7 @@ sysexit_audit:
8091
8092 sysenter_tracesys:
8093 #ifdef CONFIG_AUDITSYSCALL
8094 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
8095 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8096 jz sysenter_auditsys
8097 #endif
8098 SAVE_REST
8099 @@ -246,6 +287,9 @@ sysenter_tracesys:
8100 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8101 movq %rsp,%rdi /* &pt_regs -> arg1 */
8102 call syscall_trace_enter
8103 +
8104 + pax_erase_kstack
8105 +
8106 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8107 RESTORE_REST
8108 cmpq $(IA32_NR_syscalls-1),%rax
8109 @@ -277,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
8110 ENTRY(ia32_cstar_target)
8111 CFI_STARTPROC32 simple
8112 CFI_SIGNAL_FRAME
8113 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8114 + CFI_DEF_CFA rsp,0
8115 CFI_REGISTER rip,rcx
8116 /*CFI_REGISTER rflags,r11*/
8117 SWAPGS_UNSAFE_STACK
8118 movl %esp,%r8d
8119 CFI_REGISTER rsp,r8
8120 movq PER_CPU_VAR(kernel_stack),%rsp
8121 + SAVE_ARGS 8*6,0,0
8122 + pax_enter_kernel_user
8123 /*
8124 * No need to follow this irqs on/off section: the syscall
8125 * disabled irqs and here we enable it straight after entry:
8126 */
8127 ENABLE_INTERRUPTS(CLBR_NONE)
8128 - SAVE_ARGS 8,0,0
8129 movl %eax,%eax /* zero extension */
8130 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8131 movq %rcx,RIP-ARGOFFSET(%rsp)
8132 @@ -305,13 +350,19 @@ ENTRY(ia32_cstar_target)
8133 /* no need to do an access_ok check here because r8 has been
8134 32bit zero extended */
8135 /* hardware stack frame is complete now */
8136 +
8137 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8138 + mov $PAX_USER_SHADOW_BASE,%r11
8139 + add %r11,%r8
8140 +#endif
8141 +
8142 1: movl (%r8),%r9d
8143 .section __ex_table,"a"
8144 .quad 1b,ia32_badarg
8145 .previous
8146 - GET_THREAD_INFO(%r10)
8147 - orl $TS_COMPAT,TI_status(%r10)
8148 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
8149 + GET_THREAD_INFO(%r11)
8150 + orl $TS_COMPAT,TI_status(%r11)
8151 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8152 CFI_REMEMBER_STATE
8153 jnz cstar_tracesys
8154 cmpq $IA32_NR_syscalls-1,%rax
8155 @@ -321,13 +372,15 @@ cstar_do_call:
8156 cstar_dispatch:
8157 call *ia32_sys_call_table(,%rax,8)
8158 movq %rax,RAX-ARGOFFSET(%rsp)
8159 - GET_THREAD_INFO(%r10)
8160 + GET_THREAD_INFO(%r11)
8161 DISABLE_INTERRUPTS(CLBR_NONE)
8162 TRACE_IRQS_OFF
8163 - testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
8164 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8165 jnz sysretl_audit
8166 sysretl_from_sys_call:
8167 - andl $~TS_COMPAT,TI_status(%r10)
8168 + pax_exit_kernel_user
8169 + pax_erase_kstack
8170 + andl $~TS_COMPAT,TI_status(%r11)
8171 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8172 movl RIP-ARGOFFSET(%rsp),%ecx
8173 CFI_REGISTER rip,rcx
8174 @@ -355,7 +408,7 @@ sysretl_audit:
8175
8176 cstar_tracesys:
8177 #ifdef CONFIG_AUDITSYSCALL
8178 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
8179 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8180 jz cstar_auditsys
8181 #endif
8182 xchgl %r9d,%ebp
8183 @@ -364,6 +417,9 @@ cstar_tracesys:
8184 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8185 movq %rsp,%rdi /* &pt_regs -> arg1 */
8186 call syscall_trace_enter
8187 +
8188 + pax_erase_kstack
8189 +
8190 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8191 RESTORE_REST
8192 xchgl %ebp,%r9d
8193 @@ -409,20 +465,21 @@ ENTRY(ia32_syscall)
8194 CFI_REL_OFFSET rip,RIP-RIP
8195 PARAVIRT_ADJUST_EXCEPTION_FRAME
8196 SWAPGS
8197 - /*
8198 - * No need to follow this irqs on/off section: the syscall
8199 - * disabled irqs and here we enable it straight after entry:
8200 - */
8201 - ENABLE_INTERRUPTS(CLBR_NONE)
8202 movl %eax,%eax
8203 pushq_cfi %rax
8204 cld
8205 /* note the registers are not zero extended to the sf.
8206 this could be a problem. */
8207 SAVE_ARGS 0,1,0
8208 - GET_THREAD_INFO(%r10)
8209 - orl $TS_COMPAT,TI_status(%r10)
8210 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
8211 + pax_enter_kernel_user
8212 + /*
8213 + * No need to follow this irqs on/off section: the syscall
8214 + * disabled irqs and here we enable it straight after entry:
8215 + */
8216 + ENABLE_INTERRUPTS(CLBR_NONE)
8217 + GET_THREAD_INFO(%r11)
8218 + orl $TS_COMPAT,TI_status(%r11)
8219 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8220 jnz ia32_tracesys
8221 cmpq $(IA32_NR_syscalls-1),%rax
8222 ja ia32_badsys
8223 @@ -441,6 +498,9 @@ ia32_tracesys:
8224 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8225 movq %rsp,%rdi /* &pt_regs -> arg1 */
8226 call syscall_trace_enter
8227 +
8228 + pax_erase_kstack
8229 +
8230 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8231 RESTORE_REST
8232 cmpq $(IA32_NR_syscalls-1),%rax
8233 @@ -455,6 +515,7 @@ ia32_badsys:
8234
8235 quiet_ni_syscall:
8236 movq $-ENOSYS,%rax
8237 + pax_force_retaddr
8238 ret
8239 CFI_ENDPROC
8240
8241 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8242 index f6f5c53..b358b28 100644
8243 --- a/arch/x86/ia32/sys_ia32.c
8244 +++ b/arch/x86/ia32/sys_ia32.c
8245 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8246 */
8247 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8248 {
8249 - typeof(ubuf->st_uid) uid = 0;
8250 - typeof(ubuf->st_gid) gid = 0;
8251 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8252 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8253 SET_UID(uid, stat->uid);
8254 SET_GID(gid, stat->gid);
8255 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8256 @@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
8257 }
8258 set_fs(KERNEL_DS);
8259 ret = sys_rt_sigprocmask(how,
8260 - set ? (sigset_t __user *)&s : NULL,
8261 - oset ? (sigset_t __user *)&s : NULL,
8262 + set ? (sigset_t __force_user *)&s : NULL,
8263 + oset ? (sigset_t __force_user *)&s : NULL,
8264 sigsetsize);
8265 set_fs(old_fs);
8266 if (ret)
8267 @@ -332,7 +332,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
8268 return alarm_setitimer(seconds);
8269 }
8270
8271 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8272 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8273 int options)
8274 {
8275 return compat_sys_wait4(pid, stat_addr, options, NULL);
8276 @@ -353,7 +353,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8277 mm_segment_t old_fs = get_fs();
8278
8279 set_fs(KERNEL_DS);
8280 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8281 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8282 set_fs(old_fs);
8283 if (put_compat_timespec(&t, interval))
8284 return -EFAULT;
8285 @@ -369,7 +369,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8286 mm_segment_t old_fs = get_fs();
8287
8288 set_fs(KERNEL_DS);
8289 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8290 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8291 set_fs(old_fs);
8292 if (!ret) {
8293 switch (_NSIG_WORDS) {
8294 @@ -394,7 +394,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8295 if (copy_siginfo_from_user32(&info, uinfo))
8296 return -EFAULT;
8297 set_fs(KERNEL_DS);
8298 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8299 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8300 set_fs(old_fs);
8301 return ret;
8302 }
8303 @@ -439,7 +439,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8304 return -EFAULT;
8305
8306 set_fs(KERNEL_DS);
8307 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
8308 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
8309 count);
8310 set_fs(old_fs);
8311
8312 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8313 index 091508b..7692c6f 100644
8314 --- a/arch/x86/include/asm/alternative-asm.h
8315 +++ b/arch/x86/include/asm/alternative-asm.h
8316 @@ -4,10 +4,10 @@
8317
8318 #ifdef CONFIG_SMP
8319 .macro LOCK_PREFIX
8320 -1: lock
8321 +672: lock
8322 .section .smp_locks,"a"
8323 .balign 4
8324 - .long 1b - .
8325 + .long 672b - .
8326 .previous
8327 .endm
8328 #else
8329 @@ -15,6 +15,45 @@
8330 .endm
8331 #endif
8332
8333 +#ifdef KERNEXEC_PLUGIN
8334 + .macro pax_force_retaddr_bts rip=0
8335 + btsq $63,\rip(%rsp)
8336 + .endm
8337 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
8338 + .macro pax_force_retaddr rip=0, reload=0
8339 + btsq $63,\rip(%rsp)
8340 + .endm
8341 + .macro pax_force_fptr ptr
8342 + btsq $63,\ptr
8343 + .endm
8344 + .macro pax_set_fptr_mask
8345 + .endm
8346 +#endif
8347 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
8348 + .macro pax_force_retaddr rip=0, reload=0
8349 + .if \reload
8350 + pax_set_fptr_mask
8351 + .endif
8352 + orq %r10,\rip(%rsp)
8353 + .endm
8354 + .macro pax_force_fptr ptr
8355 + orq %r10,\ptr
8356 + .endm
8357 + .macro pax_set_fptr_mask
8358 + movabs $0x8000000000000000,%r10
8359 + .endm
8360 +#endif
8361 +#else
8362 + .macro pax_force_retaddr rip=0, reload=0
8363 + .endm
8364 + .macro pax_force_fptr ptr
8365 + .endm
8366 + .macro pax_force_retaddr_bts rip=0
8367 + .endm
8368 + .macro pax_set_fptr_mask
8369 + .endm
8370 +#endif
8371 +
8372 .macro altinstruction_entry orig alt feature orig_len alt_len
8373 .long \orig - .
8374 .long \alt - .
8375 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
8376 index 37ad100..7d47faa 100644
8377 --- a/arch/x86/include/asm/alternative.h
8378 +++ b/arch/x86/include/asm/alternative.h
8379 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
8380 ".section .discard,\"aw\",@progbits\n" \
8381 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
8382 ".previous\n" \
8383 - ".section .altinstr_replacement, \"ax\"\n" \
8384 + ".section .altinstr_replacement, \"a\"\n" \
8385 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
8386 ".previous"
8387
8388 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
8389 index 1a6c09a..fec2432 100644
8390 --- a/arch/x86/include/asm/apic.h
8391 +++ b/arch/x86/include/asm/apic.h
8392 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
8393
8394 #ifdef CONFIG_X86_LOCAL_APIC
8395
8396 -extern unsigned int apic_verbosity;
8397 +extern int apic_verbosity;
8398 extern int local_apic_timer_c2_ok;
8399
8400 extern int disable_apic;
8401 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
8402 index 20370c6..a2eb9b0 100644
8403 --- a/arch/x86/include/asm/apm.h
8404 +++ b/arch/x86/include/asm/apm.h
8405 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
8406 __asm__ __volatile__(APM_DO_ZERO_SEGS
8407 "pushl %%edi\n\t"
8408 "pushl %%ebp\n\t"
8409 - "lcall *%%cs:apm_bios_entry\n\t"
8410 + "lcall *%%ss:apm_bios_entry\n\t"
8411 "setc %%al\n\t"
8412 "popl %%ebp\n\t"
8413 "popl %%edi\n\t"
8414 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
8415 __asm__ __volatile__(APM_DO_ZERO_SEGS
8416 "pushl %%edi\n\t"
8417 "pushl %%ebp\n\t"
8418 - "lcall *%%cs:apm_bios_entry\n\t"
8419 + "lcall *%%ss:apm_bios_entry\n\t"
8420 "setc %%bl\n\t"
8421 "popl %%ebp\n\t"
8422 "popl %%edi\n\t"
8423 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
8424 index 58cb6d4..ca9010d 100644
8425 --- a/arch/x86/include/asm/atomic.h
8426 +++ b/arch/x86/include/asm/atomic.h
8427 @@ -22,7 +22,18 @@
8428 */
8429 static inline int atomic_read(const atomic_t *v)
8430 {
8431 - return (*(volatile int *)&(v)->counter);
8432 + return (*(volatile const int *)&(v)->counter);
8433 +}
8434 +
8435 +/**
8436 + * atomic_read_unchecked - read atomic variable
8437 + * @v: pointer of type atomic_unchecked_t
8438 + *
8439 + * Atomically reads the value of @v.
8440 + */
8441 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8442 +{
8443 + return (*(volatile const int *)&(v)->counter);
8444 }
8445
8446 /**
8447 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
8448 }
8449
8450 /**
8451 + * atomic_set_unchecked - set atomic variable
8452 + * @v: pointer of type atomic_unchecked_t
8453 + * @i: required value
8454 + *
8455 + * Atomically sets the value of @v to @i.
8456 + */
8457 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8458 +{
8459 + v->counter = i;
8460 +}
8461 +
8462 +/**
8463 * atomic_add - add integer to atomic variable
8464 * @i: integer value to add
8465 * @v: pointer of type atomic_t
8466 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
8467 */
8468 static inline void atomic_add(int i, atomic_t *v)
8469 {
8470 - asm volatile(LOCK_PREFIX "addl %1,%0"
8471 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8472 +
8473 +#ifdef CONFIG_PAX_REFCOUNT
8474 + "jno 0f\n"
8475 + LOCK_PREFIX "subl %1,%0\n"
8476 + "int $4\n0:\n"
8477 + _ASM_EXTABLE(0b, 0b)
8478 +#endif
8479 +
8480 + : "+m" (v->counter)
8481 + : "ir" (i));
8482 +}
8483 +
8484 +/**
8485 + * atomic_add_unchecked - add integer to atomic variable
8486 + * @i: integer value to add
8487 + * @v: pointer of type atomic_unchecked_t
8488 + *
8489 + * Atomically adds @i to @v.
8490 + */
8491 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8492 +{
8493 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8494 : "+m" (v->counter)
8495 : "ir" (i));
8496 }
8497 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
8498 */
8499 static inline void atomic_sub(int i, atomic_t *v)
8500 {
8501 - asm volatile(LOCK_PREFIX "subl %1,%0"
8502 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8503 +
8504 +#ifdef CONFIG_PAX_REFCOUNT
8505 + "jno 0f\n"
8506 + LOCK_PREFIX "addl %1,%0\n"
8507 + "int $4\n0:\n"
8508 + _ASM_EXTABLE(0b, 0b)
8509 +#endif
8510 +
8511 + : "+m" (v->counter)
8512 + : "ir" (i));
8513 +}
8514 +
8515 +/**
8516 + * atomic_sub_unchecked - subtract integer from atomic variable
8517 + * @i: integer value to subtract
8518 + * @v: pointer of type atomic_unchecked_t
8519 + *
8520 + * Atomically subtracts @i from @v.
8521 + */
8522 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8523 +{
8524 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8525 : "+m" (v->counter)
8526 : "ir" (i));
8527 }
8528 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8529 {
8530 unsigned char c;
8531
8532 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8533 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
8534 +
8535 +#ifdef CONFIG_PAX_REFCOUNT
8536 + "jno 0f\n"
8537 + LOCK_PREFIX "addl %2,%0\n"
8538 + "int $4\n0:\n"
8539 + _ASM_EXTABLE(0b, 0b)
8540 +#endif
8541 +
8542 + "sete %1\n"
8543 : "+m" (v->counter), "=qm" (c)
8544 : "ir" (i) : "memory");
8545 return c;
8546 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8547 */
8548 static inline void atomic_inc(atomic_t *v)
8549 {
8550 - asm volatile(LOCK_PREFIX "incl %0"
8551 + asm volatile(LOCK_PREFIX "incl %0\n"
8552 +
8553 +#ifdef CONFIG_PAX_REFCOUNT
8554 + "jno 0f\n"
8555 + LOCK_PREFIX "decl %0\n"
8556 + "int $4\n0:\n"
8557 + _ASM_EXTABLE(0b, 0b)
8558 +#endif
8559 +
8560 + : "+m" (v->counter));
8561 +}
8562 +
8563 +/**
8564 + * atomic_inc_unchecked - increment atomic variable
8565 + * @v: pointer of type atomic_unchecked_t
8566 + *
8567 + * Atomically increments @v by 1.
8568 + */
8569 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8570 +{
8571 + asm volatile(LOCK_PREFIX "incl %0\n"
8572 : "+m" (v->counter));
8573 }
8574
8575 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
8576 */
8577 static inline void atomic_dec(atomic_t *v)
8578 {
8579 - asm volatile(LOCK_PREFIX "decl %0"
8580 + asm volatile(LOCK_PREFIX "decl %0\n"
8581 +
8582 +#ifdef CONFIG_PAX_REFCOUNT
8583 + "jno 0f\n"
8584 + LOCK_PREFIX "incl %0\n"
8585 + "int $4\n0:\n"
8586 + _ASM_EXTABLE(0b, 0b)
8587 +#endif
8588 +
8589 + : "+m" (v->counter));
8590 +}
8591 +
8592 +/**
8593 + * atomic_dec_unchecked - decrement atomic variable
8594 + * @v: pointer of type atomic_unchecked_t
8595 + *
8596 + * Atomically decrements @v by 1.
8597 + */
8598 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8599 +{
8600 + asm volatile(LOCK_PREFIX "decl %0\n"
8601 : "+m" (v->counter));
8602 }
8603
8604 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
8605 {
8606 unsigned char c;
8607
8608 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
8609 + asm volatile(LOCK_PREFIX "decl %0\n"
8610 +
8611 +#ifdef CONFIG_PAX_REFCOUNT
8612 + "jno 0f\n"
8613 + LOCK_PREFIX "incl %0\n"
8614 + "int $4\n0:\n"
8615 + _ASM_EXTABLE(0b, 0b)
8616 +#endif
8617 +
8618 + "sete %1\n"
8619 : "+m" (v->counter), "=qm" (c)
8620 : : "memory");
8621 return c != 0;
8622 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
8623 {
8624 unsigned char c;
8625
8626 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
8627 + asm volatile(LOCK_PREFIX "incl %0\n"
8628 +
8629 +#ifdef CONFIG_PAX_REFCOUNT
8630 + "jno 0f\n"
8631 + LOCK_PREFIX "decl %0\n"
8632 + "int $4\n0:\n"
8633 + _ASM_EXTABLE(0b, 0b)
8634 +#endif
8635 +
8636 + "sete %1\n"
8637 + : "+m" (v->counter), "=qm" (c)
8638 + : : "memory");
8639 + return c != 0;
8640 +}
8641 +
8642 +/**
8643 + * atomic_inc_and_test_unchecked - increment and test
8644 + * @v: pointer of type atomic_unchecked_t
8645 + *
8646 + * Atomically increments @v by 1
8647 + * and returns true if the result is zero, or false for all
8648 + * other cases.
8649 + */
8650 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8651 +{
8652 + unsigned char c;
8653 +
8654 + asm volatile(LOCK_PREFIX "incl %0\n"
8655 + "sete %1\n"
8656 : "+m" (v->counter), "=qm" (c)
8657 : : "memory");
8658 return c != 0;
8659 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
8660 {
8661 unsigned char c;
8662
8663 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
8664 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
8665 +
8666 +#ifdef CONFIG_PAX_REFCOUNT
8667 + "jno 0f\n"
8668 + LOCK_PREFIX "subl %2,%0\n"
8669 + "int $4\n0:\n"
8670 + _ASM_EXTABLE(0b, 0b)
8671 +#endif
8672 +
8673 + "sets %1\n"
8674 : "+m" (v->counter), "=qm" (c)
8675 : "ir" (i) : "memory");
8676 return c;
8677 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
8678 goto no_xadd;
8679 #endif
8680 /* Modern 486+ processor */
8681 - return i + xadd(&v->counter, i);
8682 + return i + xadd_check_overflow(&v->counter, i);
8683
8684 #ifdef CONFIG_M386
8685 no_xadd: /* Legacy 386 processor */
8686 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
8687 }
8688
8689 /**
8690 + * atomic_add_return_unchecked - add integer and return
8691 + * @i: integer value to add
8692 + * @v: pointer of type atomic_unchecked_t
8693 + *
8694 + * Atomically adds @i to @v and returns @i + @v
8695 + */
8696 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8697 +{
8698 +#ifdef CONFIG_M386
8699 + int __i;
8700 + unsigned long flags;
8701 + if (unlikely(boot_cpu_data.x86 <= 3))
8702 + goto no_xadd;
8703 +#endif
8704 + /* Modern 486+ processor */
8705 + return i + xadd(&v->counter, i);
8706 +
8707 +#ifdef CONFIG_M386
8708 +no_xadd: /* Legacy 386 processor */
8709 + raw_local_irq_save(flags);
8710 + __i = atomic_read_unchecked(v);
8711 + atomic_set_unchecked(v, i + __i);
8712 + raw_local_irq_restore(flags);
8713 + return i + __i;
8714 +#endif
8715 +}
8716 +
8717 +/**
8718 * atomic_sub_return - subtract integer and return
8719 * @v: pointer of type atomic_t
8720 * @i: integer value to subtract
8721 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
8722 }
8723
8724 #define atomic_inc_return(v) (atomic_add_return(1, v))
8725 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8726 +{
8727 + return atomic_add_return_unchecked(1, v);
8728 +}
8729 #define atomic_dec_return(v) (atomic_sub_return(1, v))
8730
8731 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
8732 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
8733 return cmpxchg(&v->counter, old, new);
8734 }
8735
8736 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8737 +{
8738 + return cmpxchg(&v->counter, old, new);
8739 +}
8740 +
8741 static inline int atomic_xchg(atomic_t *v, int new)
8742 {
8743 return xchg(&v->counter, new);
8744 }
8745
8746 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8747 +{
8748 + return xchg(&v->counter, new);
8749 +}
8750 +
8751 /**
8752 * __atomic_add_unless - add unless the number is already a given value
8753 * @v: pointer of type atomic_t
8754 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
8755 */
8756 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8757 {
8758 - int c, old;
8759 + int c, old, new;
8760 c = atomic_read(v);
8761 for (;;) {
8762 - if (unlikely(c == (u)))
8763 + if (unlikely(c == u))
8764 break;
8765 - old = atomic_cmpxchg((v), c, c + (a));
8766 +
8767 + asm volatile("addl %2,%0\n"
8768 +
8769 +#ifdef CONFIG_PAX_REFCOUNT
8770 + "jno 0f\n"
8771 + "subl %2,%0\n"
8772 + "int $4\n0:\n"
8773 + _ASM_EXTABLE(0b, 0b)
8774 +#endif
8775 +
8776 + : "=r" (new)
8777 + : "0" (c), "ir" (a));
8778 +
8779 + old = atomic_cmpxchg(v, c, new);
8780 if (likely(old == c))
8781 break;
8782 c = old;
8783 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8784 return c;
8785 }
8786
8787 +/**
8788 + * atomic_inc_not_zero_hint - increment if not null
8789 + * @v: pointer of type atomic_t
8790 + * @hint: probable value of the atomic before the increment
8791 + *
8792 + * This version of atomic_inc_not_zero() gives a hint of probable
8793 + * value of the atomic. This helps processor to not read the memory
8794 + * before doing the atomic read/modify/write cycle, lowering
8795 + * number of bus transactions on some arches.
8796 + *
8797 + * Returns: 0 if increment was not done, 1 otherwise.
8798 + */
8799 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
8800 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
8801 +{
8802 + int val, c = hint, new;
8803 +
8804 + /* sanity test, should be removed by compiler if hint is a constant */
8805 + if (!hint)
8806 + return __atomic_add_unless(v, 1, 0);
8807 +
8808 + do {
8809 + asm volatile("incl %0\n"
8810 +
8811 +#ifdef CONFIG_PAX_REFCOUNT
8812 + "jno 0f\n"
8813 + "decl %0\n"
8814 + "int $4\n0:\n"
8815 + _ASM_EXTABLE(0b, 0b)
8816 +#endif
8817 +
8818 + : "=r" (new)
8819 + : "0" (c));
8820 +
8821 + val = atomic_cmpxchg(v, c, new);
8822 + if (val == c)
8823 + return 1;
8824 + c = val;
8825 + } while (c);
8826 +
8827 + return 0;
8828 +}
8829
8830 /*
8831 * atomic_dec_if_positive - decrement by 1 if old value positive
8832 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
8833 index 24098aa..1e37723 100644
8834 --- a/arch/x86/include/asm/atomic64_32.h
8835 +++ b/arch/x86/include/asm/atomic64_32.h
8836 @@ -12,6 +12,14 @@ typedef struct {
8837 u64 __aligned(8) counter;
8838 } atomic64_t;
8839
8840 +#ifdef CONFIG_PAX_REFCOUNT
8841 +typedef struct {
8842 + u64 __aligned(8) counter;
8843 +} atomic64_unchecked_t;
8844 +#else
8845 +typedef atomic64_t atomic64_unchecked_t;
8846 +#endif
8847 +
8848 #define ATOMIC64_INIT(val) { (val) }
8849
8850 #ifdef CONFIG_X86_CMPXCHG64
8851 @@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
8852 }
8853
8854 /**
8855 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
8856 + * @p: pointer to type atomic64_unchecked_t
8857 + * @o: expected value
8858 + * @n: new value
8859 + *
8860 + * Atomically sets @v to @n if it was equal to @o and returns
8861 + * the old value.
8862 + */
8863 +
8864 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
8865 +{
8866 + return cmpxchg64(&v->counter, o, n);
8867 +}
8868 +
8869 +/**
8870 * atomic64_xchg - xchg atomic64 variable
8871 * @v: pointer to type atomic64_t
8872 * @n: value to assign
8873 @@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64_t *v, long long i)
8874 }
8875
8876 /**
8877 + * atomic64_set_unchecked - set atomic64 variable
8878 + * @v: pointer to type atomic64_unchecked_t
8879 + * @n: value to assign
8880 + *
8881 + * Atomically sets the value of @v to @n.
8882 + */
8883 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
8884 +{
8885 + unsigned high = (unsigned)(i >> 32);
8886 + unsigned low = (unsigned)i;
8887 + asm volatile(ATOMIC64_ALTERNATIVE(set)
8888 + : "+b" (low), "+c" (high)
8889 + : "S" (v)
8890 + : "eax", "edx", "memory"
8891 + );
8892 +}
8893 +
8894 +/**
8895 * atomic64_read - read atomic64 variable
8896 * @v: pointer to type atomic64_t
8897 *
8898 @@ -93,6 +134,22 @@ static inline long long atomic64_read(atomic64_t *v)
8899 }
8900
8901 /**
8902 + * atomic64_read_unchecked - read atomic64 variable
8903 + * @v: pointer to type atomic64_unchecked_t
8904 + *
8905 + * Atomically reads the value of @v and returns it.
8906 + */
8907 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
8908 +{
8909 + long long r;
8910 + asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
8911 + : "=A" (r), "+c" (v)
8912 + : : "memory"
8913 + );
8914 + return r;
8915 + }
8916 +
8917 +/**
8918 * atomic64_add_return - add and return
8919 * @i: integer value to add
8920 * @v: pointer to type atomic64_t
8921 @@ -108,6 +165,22 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
8922 return i;
8923 }
8924
8925 +/**
8926 + * atomic64_add_return_unchecked - add and return
8927 + * @i: integer value to add
8928 + * @v: pointer to type atomic64_unchecked_t
8929 + *
8930 + * Atomically adds @i to @v and returns @i + *@v
8931 + */
8932 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
8933 +{
8934 + asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
8935 + : "+A" (i), "+c" (v)
8936 + : : "memory"
8937 + );
8938 + return i;
8939 +}
8940 +
8941 /*
8942 * Other variants with different arithmetic operators:
8943 */
8944 @@ -131,6 +204,17 @@ static inline long long atomic64_inc_return(atomic64_t *v)
8945 return a;
8946 }
8947
8948 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8949 +{
8950 + long long a;
8951 + asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
8952 + : "=A" (a)
8953 + : "S" (v)
8954 + : "memory", "ecx"
8955 + );
8956 + return a;
8957 +}
8958 +
8959 static inline long long atomic64_dec_return(atomic64_t *v)
8960 {
8961 long long a;
8962 @@ -159,6 +243,22 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
8963 }
8964
8965 /**
8966 + * atomic64_add_unchecked - add integer to atomic64 variable
8967 + * @i: integer value to add
8968 + * @v: pointer to type atomic64_unchecked_t
8969 + *
8970 + * Atomically adds @i to @v.
8971 + */
8972 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
8973 +{
8974 + asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
8975 + : "+A" (i), "+c" (v)
8976 + : : "memory"
8977 + );
8978 + return i;
8979 +}
8980 +
8981 +/**
8982 * atomic64_sub - subtract the atomic64 variable
8983 * @i: integer value to subtract
8984 * @v: pointer to type atomic64_t
8985 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
8986 index 0e1cbfc..5623683 100644
8987 --- a/arch/x86/include/asm/atomic64_64.h
8988 +++ b/arch/x86/include/asm/atomic64_64.h
8989 @@ -18,7 +18,19 @@
8990 */
8991 static inline long atomic64_read(const atomic64_t *v)
8992 {
8993 - return (*(volatile long *)&(v)->counter);
8994 + return (*(volatile const long *)&(v)->counter);
8995 +}
8996 +
8997 +/**
8998 + * atomic64_read_unchecked - read atomic64 variable
8999 + * @v: pointer of type atomic64_unchecked_t
9000 + *
9001 + * Atomically reads the value of @v.
9002 + * Doesn't imply a read memory barrier.
9003 + */
9004 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9005 +{
9006 + return (*(volatile const long *)&(v)->counter);
9007 }
9008
9009 /**
9010 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9011 }
9012
9013 /**
9014 + * atomic64_set_unchecked - set atomic64 variable
9015 + * @v: pointer to type atomic64_unchecked_t
9016 + * @i: required value
9017 + *
9018 + * Atomically sets the value of @v to @i.
9019 + */
9020 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9021 +{
9022 + v->counter = i;
9023 +}
9024 +
9025 +/**
9026 * atomic64_add - add integer to atomic64 variable
9027 * @i: integer value to add
9028 * @v: pointer to type atomic64_t
9029 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9030 */
9031 static inline void atomic64_add(long i, atomic64_t *v)
9032 {
9033 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9034 +
9035 +#ifdef CONFIG_PAX_REFCOUNT
9036 + "jno 0f\n"
9037 + LOCK_PREFIX "subq %1,%0\n"
9038 + "int $4\n0:\n"
9039 + _ASM_EXTABLE(0b, 0b)
9040 +#endif
9041 +
9042 + : "=m" (v->counter)
9043 + : "er" (i), "m" (v->counter));
9044 +}
9045 +
9046 +/**
9047 + * atomic64_add_unchecked - add integer to atomic64 variable
9048 + * @i: integer value to add
9049 + * @v: pointer to type atomic64_unchecked_t
9050 + *
9051 + * Atomically adds @i to @v.
9052 + */
9053 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9054 +{
9055 asm volatile(LOCK_PREFIX "addq %1,%0"
9056 : "=m" (v->counter)
9057 : "er" (i), "m" (v->counter));
9058 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9059 */
9060 static inline void atomic64_sub(long i, atomic64_t *v)
9061 {
9062 - asm volatile(LOCK_PREFIX "subq %1,%0"
9063 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9064 +
9065 +#ifdef CONFIG_PAX_REFCOUNT
9066 + "jno 0f\n"
9067 + LOCK_PREFIX "addq %1,%0\n"
9068 + "int $4\n0:\n"
9069 + _ASM_EXTABLE(0b, 0b)
9070 +#endif
9071 +
9072 + : "=m" (v->counter)
9073 + : "er" (i), "m" (v->counter));
9074 +}
9075 +
9076 +/**
9077 + * atomic64_sub_unchecked - subtract the atomic64 variable
9078 + * @i: integer value to subtract
9079 + * @v: pointer to type atomic64_unchecked_t
9080 + *
9081 + * Atomically subtracts @i from @v.
9082 + */
9083 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9084 +{
9085 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9086 : "=m" (v->counter)
9087 : "er" (i), "m" (v->counter));
9088 }
9089 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9090 {
9091 unsigned char c;
9092
9093 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9094 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9095 +
9096 +#ifdef CONFIG_PAX_REFCOUNT
9097 + "jno 0f\n"
9098 + LOCK_PREFIX "addq %2,%0\n"
9099 + "int $4\n0:\n"
9100 + _ASM_EXTABLE(0b, 0b)
9101 +#endif
9102 +
9103 + "sete %1\n"
9104 : "=m" (v->counter), "=qm" (c)
9105 : "er" (i), "m" (v->counter) : "memory");
9106 return c;
9107 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9108 */
9109 static inline void atomic64_inc(atomic64_t *v)
9110 {
9111 + asm volatile(LOCK_PREFIX "incq %0\n"
9112 +
9113 +#ifdef CONFIG_PAX_REFCOUNT
9114 + "jno 0f\n"
9115 + LOCK_PREFIX "decq %0\n"
9116 + "int $4\n0:\n"
9117 + _ASM_EXTABLE(0b, 0b)
9118 +#endif
9119 +
9120 + : "=m" (v->counter)
9121 + : "m" (v->counter));
9122 +}
9123 +
9124 +/**
9125 + * atomic64_inc_unchecked - increment atomic64 variable
9126 + * @v: pointer to type atomic64_unchecked_t
9127 + *
9128 + * Atomically increments @v by 1.
9129 + */
9130 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9131 +{
9132 asm volatile(LOCK_PREFIX "incq %0"
9133 : "=m" (v->counter)
9134 : "m" (v->counter));
9135 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9136 */
9137 static inline void atomic64_dec(atomic64_t *v)
9138 {
9139 - asm volatile(LOCK_PREFIX "decq %0"
9140 + asm volatile(LOCK_PREFIX "decq %0\n"
9141 +
9142 +#ifdef CONFIG_PAX_REFCOUNT
9143 + "jno 0f\n"
9144 + LOCK_PREFIX "incq %0\n"
9145 + "int $4\n0:\n"
9146 + _ASM_EXTABLE(0b, 0b)
9147 +#endif
9148 +
9149 + : "=m" (v->counter)
9150 + : "m" (v->counter));
9151 +}
9152 +
9153 +/**
9154 + * atomic64_dec_unchecked - decrement atomic64 variable
9155 + * @v: pointer to type atomic64_t
9156 + *
9157 + * Atomically decrements @v by 1.
9158 + */
9159 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9160 +{
9161 + asm volatile(LOCK_PREFIX "decq %0\n"
9162 : "=m" (v->counter)
9163 : "m" (v->counter));
9164 }
9165 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9166 {
9167 unsigned char c;
9168
9169 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9170 + asm volatile(LOCK_PREFIX "decq %0\n"
9171 +
9172 +#ifdef CONFIG_PAX_REFCOUNT
9173 + "jno 0f\n"
9174 + LOCK_PREFIX "incq %0\n"
9175 + "int $4\n0:\n"
9176 + _ASM_EXTABLE(0b, 0b)
9177 +#endif
9178 +
9179 + "sete %1\n"
9180 : "=m" (v->counter), "=qm" (c)
9181 : "m" (v->counter) : "memory");
9182 return c != 0;
9183 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9184 {
9185 unsigned char c;
9186
9187 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9188 + asm volatile(LOCK_PREFIX "incq %0\n"
9189 +
9190 +#ifdef CONFIG_PAX_REFCOUNT
9191 + "jno 0f\n"
9192 + LOCK_PREFIX "decq %0\n"
9193 + "int $4\n0:\n"
9194 + _ASM_EXTABLE(0b, 0b)
9195 +#endif
9196 +
9197 + "sete %1\n"
9198 : "=m" (v->counter), "=qm" (c)
9199 : "m" (v->counter) : "memory");
9200 return c != 0;
9201 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9202 {
9203 unsigned char c;
9204
9205 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9206 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9207 +
9208 +#ifdef CONFIG_PAX_REFCOUNT
9209 + "jno 0f\n"
9210 + LOCK_PREFIX "subq %2,%0\n"
9211 + "int $4\n0:\n"
9212 + _ASM_EXTABLE(0b, 0b)
9213 +#endif
9214 +
9215 + "sets %1\n"
9216 : "=m" (v->counter), "=qm" (c)
9217 : "er" (i), "m" (v->counter) : "memory");
9218 return c;
9219 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9220 */
9221 static inline long atomic64_add_return(long i, atomic64_t *v)
9222 {
9223 + return i + xadd_check_overflow(&v->counter, i);
9224 +}
9225 +
9226 +/**
9227 + * atomic64_add_return_unchecked - add and return
9228 + * @i: integer value to add
9229 + * @v: pointer to type atomic64_unchecked_t
9230 + *
9231 + * Atomically adds @i to @v and returns @i + @v
9232 + */
9233 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9234 +{
9235 return i + xadd(&v->counter, i);
9236 }
9237
9238 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9239 }
9240
9241 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9242 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9243 +{
9244 + return atomic64_add_return_unchecked(1, v);
9245 +}
9246 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9247
9248 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9249 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9250 return cmpxchg(&v->counter, old, new);
9251 }
9252
9253 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9254 +{
9255 + return cmpxchg(&v->counter, old, new);
9256 +}
9257 +
9258 static inline long atomic64_xchg(atomic64_t *v, long new)
9259 {
9260 return xchg(&v->counter, new);
9261 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
9262 */
9263 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9264 {
9265 - long c, old;
9266 + long c, old, new;
9267 c = atomic64_read(v);
9268 for (;;) {
9269 - if (unlikely(c == (u)))
9270 + if (unlikely(c == u))
9271 break;
9272 - old = atomic64_cmpxchg((v), c, c + (a));
9273 +
9274 + asm volatile("add %2,%0\n"
9275 +
9276 +#ifdef CONFIG_PAX_REFCOUNT
9277 + "jno 0f\n"
9278 + "sub %2,%0\n"
9279 + "int $4\n0:\n"
9280 + _ASM_EXTABLE(0b, 0b)
9281 +#endif
9282 +
9283 + : "=r" (new)
9284 + : "0" (c), "ir" (a));
9285 +
9286 + old = atomic64_cmpxchg(v, c, new);
9287 if (likely(old == c))
9288 break;
9289 c = old;
9290 }
9291 - return c != (u);
9292 + return c != u;
9293 }
9294
9295 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9296 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
9297 index 1775d6e..b65017f 100644
9298 --- a/arch/x86/include/asm/bitops.h
9299 +++ b/arch/x86/include/asm/bitops.h
9300 @@ -38,7 +38,7 @@
9301 * a mask operation on a byte.
9302 */
9303 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
9304 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
9305 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
9306 #define CONST_MASK(nr) (1 << ((nr) & 7))
9307
9308 /**
9309 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
9310 index 5e1a2ee..c9f9533 100644
9311 --- a/arch/x86/include/asm/boot.h
9312 +++ b/arch/x86/include/asm/boot.h
9313 @@ -11,10 +11,15 @@
9314 #include <asm/pgtable_types.h>
9315
9316 /* Physical address where kernel should be loaded. */
9317 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9318 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9319 + (CONFIG_PHYSICAL_ALIGN - 1)) \
9320 & ~(CONFIG_PHYSICAL_ALIGN - 1))
9321
9322 +#ifndef __ASSEMBLY__
9323 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
9324 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
9325 +#endif
9326 +
9327 /* Minimum kernel alignment, as a power of two */
9328 #ifdef CONFIG_X86_64
9329 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
9330 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
9331 index 48f99f1..d78ebf9 100644
9332 --- a/arch/x86/include/asm/cache.h
9333 +++ b/arch/x86/include/asm/cache.h
9334 @@ -5,12 +5,13 @@
9335
9336 /* L1 cache line size */
9337 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9338 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9339 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9340
9341 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9342 +#define __read_only __attribute__((__section__(".data..read_only")))
9343
9344 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
9345 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
9346 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
9347
9348 #ifdef CONFIG_X86_VSMP
9349 #ifdef CONFIG_SMP
9350 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
9351 index 4e12668..501d239 100644
9352 --- a/arch/x86/include/asm/cacheflush.h
9353 +++ b/arch/x86/include/asm/cacheflush.h
9354 @@ -26,7 +26,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
9355 unsigned long pg_flags = pg->flags & _PGMT_MASK;
9356
9357 if (pg_flags == _PGMT_DEFAULT)
9358 - return -1;
9359 + return ~0UL;
9360 else if (pg_flags == _PGMT_WC)
9361 return _PAGE_CACHE_WC;
9362 else if (pg_flags == _PGMT_UC_MINUS)
9363 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
9364 index 46fc474..b02b0f9 100644
9365 --- a/arch/x86/include/asm/checksum_32.h
9366 +++ b/arch/x86/include/asm/checksum_32.h
9367 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
9368 int len, __wsum sum,
9369 int *src_err_ptr, int *dst_err_ptr);
9370
9371 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
9372 + int len, __wsum sum,
9373 + int *src_err_ptr, int *dst_err_ptr);
9374 +
9375 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
9376 + int len, __wsum sum,
9377 + int *src_err_ptr, int *dst_err_ptr);
9378 +
9379 /*
9380 * Note: when you get a NULL pointer exception here this means someone
9381 * passed in an incorrect kernel address to one of these functions.
9382 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
9383 int *err_ptr)
9384 {
9385 might_sleep();
9386 - return csum_partial_copy_generic((__force void *)src, dst,
9387 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
9388 len, sum, err_ptr, NULL);
9389 }
9390
9391 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
9392 {
9393 might_sleep();
9394 if (access_ok(VERIFY_WRITE, dst, len))
9395 - return csum_partial_copy_generic(src, (__force void *)dst,
9396 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
9397 len, sum, NULL, err_ptr);
9398
9399 if (len)
9400 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
9401 index 5d3acdf..6447a02 100644
9402 --- a/arch/x86/include/asm/cmpxchg.h
9403 +++ b/arch/x86/include/asm/cmpxchg.h
9404 @@ -14,6 +14,8 @@ extern void __cmpxchg_wrong_size(void)
9405 __compiletime_error("Bad argument size for cmpxchg");
9406 extern void __xadd_wrong_size(void)
9407 __compiletime_error("Bad argument size for xadd");
9408 +extern void __xadd_check_overflow_wrong_size(void)
9409 + __compiletime_error("Bad argument size for xadd_check_overflow");
9410
9411 /*
9412 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
9413 @@ -195,6 +197,34 @@ extern void __xadd_wrong_size(void)
9414 __ret; \
9415 })
9416
9417 +#define __xadd_check_overflow(ptr, inc, lock) \
9418 + ({ \
9419 + __typeof__ (*(ptr)) __ret = (inc); \
9420 + switch (sizeof(*(ptr))) { \
9421 + case __X86_CASE_L: \
9422 + asm volatile (lock "xaddl %0, %1\n" \
9423 + "jno 0f\n" \
9424 + "mov %0,%1\n" \
9425 + "int $4\n0:\n" \
9426 + _ASM_EXTABLE(0b, 0b) \
9427 + : "+r" (__ret), "+m" (*(ptr)) \
9428 + : : "memory", "cc"); \
9429 + break; \
9430 + case __X86_CASE_Q: \
9431 + asm volatile (lock "xaddq %q0, %1\n" \
9432 + "jno 0f\n" \
9433 + "mov %0,%1\n" \
9434 + "int $4\n0:\n" \
9435 + _ASM_EXTABLE(0b, 0b) \
9436 + : "+r" (__ret), "+m" (*(ptr)) \
9437 + : : "memory", "cc"); \
9438 + break; \
9439 + default: \
9440 + __xadd_check_overflow_wrong_size(); \
9441 + } \
9442 + __ret; \
9443 + })
9444 +
9445 /*
9446 * xadd() adds "inc" to "*ptr" and atomically returns the previous
9447 * value of "*ptr".
9448 @@ -207,4 +237,6 @@ extern void __xadd_wrong_size(void)
9449 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
9450 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
9451
9452 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
9453 +
9454 #endif /* ASM_X86_CMPXCHG_H */
9455 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
9456 index f3444f7..051a196 100644
9457 --- a/arch/x86/include/asm/cpufeature.h
9458 +++ b/arch/x86/include/asm/cpufeature.h
9459 @@ -363,7 +363,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
9460 ".section .discard,\"aw\",@progbits\n"
9461 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
9462 ".previous\n"
9463 - ".section .altinstr_replacement,\"ax\"\n"
9464 + ".section .altinstr_replacement,\"a\"\n"
9465 "3: movb $1,%0\n"
9466 "4:\n"
9467 ".previous\n"
9468 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
9469 index 41935fa..3b40db8 100644
9470 --- a/arch/x86/include/asm/desc.h
9471 +++ b/arch/x86/include/asm/desc.h
9472 @@ -4,6 +4,7 @@
9473 #include <asm/desc_defs.h>
9474 #include <asm/ldt.h>
9475 #include <asm/mmu.h>
9476 +#include <asm/pgtable.h>
9477
9478 #include <linux/smp.h>
9479
9480 @@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9481
9482 desc->type = (info->read_exec_only ^ 1) << 1;
9483 desc->type |= info->contents << 2;
9484 + desc->type |= info->seg_not_present ^ 1;
9485
9486 desc->s = 1;
9487 desc->dpl = 0x3;
9488 @@ -34,17 +36,12 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9489 }
9490
9491 extern struct desc_ptr idt_descr;
9492 -extern gate_desc idt_table[];
9493 -
9494 -struct gdt_page {
9495 - struct desc_struct gdt[GDT_ENTRIES];
9496 -} __attribute__((aligned(PAGE_SIZE)));
9497 -
9498 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
9499 +extern gate_desc idt_table[256];
9500
9501 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
9502 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
9503 {
9504 - return per_cpu(gdt_page, cpu).gdt;
9505 + return cpu_gdt_table[cpu];
9506 }
9507
9508 #ifdef CONFIG_X86_64
9509 @@ -69,8 +66,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
9510 unsigned long base, unsigned dpl, unsigned flags,
9511 unsigned short seg)
9512 {
9513 - gate->a = (seg << 16) | (base & 0xffff);
9514 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
9515 + gate->gate.offset_low = base;
9516 + gate->gate.seg = seg;
9517 + gate->gate.reserved = 0;
9518 + gate->gate.type = type;
9519 + gate->gate.s = 0;
9520 + gate->gate.dpl = dpl;
9521 + gate->gate.p = 1;
9522 + gate->gate.offset_high = base >> 16;
9523 }
9524
9525 #endif
9526 @@ -115,12 +118,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
9527
9528 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
9529 {
9530 + pax_open_kernel();
9531 memcpy(&idt[entry], gate, sizeof(*gate));
9532 + pax_close_kernel();
9533 }
9534
9535 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
9536 {
9537 + pax_open_kernel();
9538 memcpy(&ldt[entry], desc, 8);
9539 + pax_close_kernel();
9540 }
9541
9542 static inline void
9543 @@ -134,7 +141,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
9544 default: size = sizeof(*gdt); break;
9545 }
9546
9547 + pax_open_kernel();
9548 memcpy(&gdt[entry], desc, size);
9549 + pax_close_kernel();
9550 }
9551
9552 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
9553 @@ -207,7 +216,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
9554
9555 static inline void native_load_tr_desc(void)
9556 {
9557 + pax_open_kernel();
9558 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
9559 + pax_close_kernel();
9560 }
9561
9562 static inline void native_load_gdt(const struct desc_ptr *dtr)
9563 @@ -244,8 +255,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
9564 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
9565 unsigned int i;
9566
9567 + pax_open_kernel();
9568 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
9569 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
9570 + pax_close_kernel();
9571 }
9572
9573 #define _LDT_empty(info) \
9574 @@ -307,7 +320,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
9575 desc->limit = (limit >> 16) & 0xf;
9576 }
9577
9578 -static inline void _set_gate(int gate, unsigned type, void *addr,
9579 +static inline void _set_gate(int gate, unsigned type, const void *addr,
9580 unsigned dpl, unsigned ist, unsigned seg)
9581 {
9582 gate_desc s;
9583 @@ -326,7 +339,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
9584 * Pentium F0 0F bugfix can have resulted in the mapped
9585 * IDT being write-protected.
9586 */
9587 -static inline void set_intr_gate(unsigned int n, void *addr)
9588 +static inline void set_intr_gate(unsigned int n, const void *addr)
9589 {
9590 BUG_ON((unsigned)n > 0xFF);
9591 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
9592 @@ -356,19 +369,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
9593 /*
9594 * This routine sets up an interrupt gate at directory privilege level 3.
9595 */
9596 -static inline void set_system_intr_gate(unsigned int n, void *addr)
9597 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
9598 {
9599 BUG_ON((unsigned)n > 0xFF);
9600 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
9601 }
9602
9603 -static inline void set_system_trap_gate(unsigned int n, void *addr)
9604 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
9605 {
9606 BUG_ON((unsigned)n > 0xFF);
9607 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
9608 }
9609
9610 -static inline void set_trap_gate(unsigned int n, void *addr)
9611 +static inline void set_trap_gate(unsigned int n, const void *addr)
9612 {
9613 BUG_ON((unsigned)n > 0xFF);
9614 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
9615 @@ -377,19 +390,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
9616 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
9617 {
9618 BUG_ON((unsigned)n > 0xFF);
9619 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
9620 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
9621 }
9622
9623 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
9624 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
9625 {
9626 BUG_ON((unsigned)n > 0xFF);
9627 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
9628 }
9629
9630 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
9631 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
9632 {
9633 BUG_ON((unsigned)n > 0xFF);
9634 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
9635 }
9636
9637 +#ifdef CONFIG_X86_32
9638 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
9639 +{
9640 + struct desc_struct d;
9641 +
9642 + if (likely(limit))
9643 + limit = (limit - 1UL) >> PAGE_SHIFT;
9644 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
9645 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
9646 +}
9647 +#endif
9648 +
9649 #endif /* _ASM_X86_DESC_H */
9650 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
9651 index 278441f..b95a174 100644
9652 --- a/arch/x86/include/asm/desc_defs.h
9653 +++ b/arch/x86/include/asm/desc_defs.h
9654 @@ -31,6 +31,12 @@ struct desc_struct {
9655 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
9656 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
9657 };
9658 + struct {
9659 + u16 offset_low;
9660 + u16 seg;
9661 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
9662 + unsigned offset_high: 16;
9663 + } gate;
9664 };
9665 } __attribute__((packed));
9666
9667 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
9668 index 908b969..a1f4eb4 100644
9669 --- a/arch/x86/include/asm/e820.h
9670 +++ b/arch/x86/include/asm/e820.h
9671 @@ -69,7 +69,7 @@ struct e820map {
9672 #define ISA_START_ADDRESS 0xa0000
9673 #define ISA_END_ADDRESS 0x100000
9674
9675 -#define BIOS_BEGIN 0x000a0000
9676 +#define BIOS_BEGIN 0x000c0000
9677 #define BIOS_END 0x00100000
9678
9679 #define BIOS_ROM_BASE 0xffe00000
9680 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
9681 index 5f962df..7289f09 100644
9682 --- a/arch/x86/include/asm/elf.h
9683 +++ b/arch/x86/include/asm/elf.h
9684 @@ -238,7 +238,25 @@ extern int force_personality32;
9685 the loader. We need to make sure that it is out of the way of the program
9686 that it will "exec", and that there is sufficient room for the brk. */
9687
9688 +#ifdef CONFIG_PAX_SEGMEXEC
9689 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
9690 +#else
9691 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
9692 +#endif
9693 +
9694 +#ifdef CONFIG_PAX_ASLR
9695 +#ifdef CONFIG_X86_32
9696 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
9697 +
9698 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9699 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9700 +#else
9701 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
9702 +
9703 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9704 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9705 +#endif
9706 +#endif
9707
9708 /* This yields a mask that user programs can use to figure out what
9709 instruction set this CPU supports. This could be done in user space,
9710 @@ -291,9 +309,7 @@ do { \
9711
9712 #define ARCH_DLINFO \
9713 do { \
9714 - if (vdso_enabled) \
9715 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
9716 - (unsigned long)current->mm->context.vdso); \
9717 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
9718 } while (0)
9719
9720 #define AT_SYSINFO 32
9721 @@ -304,7 +320,7 @@ do { \
9722
9723 #endif /* !CONFIG_X86_32 */
9724
9725 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
9726 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
9727
9728 #define VDSO_ENTRY \
9729 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
9730 @@ -318,9 +334,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
9731 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
9732 #define compat_arch_setup_additional_pages syscall32_setup_pages
9733
9734 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9735 -#define arch_randomize_brk arch_randomize_brk
9736 -
9737 /*
9738 * True on X86_32 or when emulating IA32 on X86_64
9739 */
9740 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
9741 index cc70c1c..d96d011 100644
9742 --- a/arch/x86/include/asm/emergency-restart.h
9743 +++ b/arch/x86/include/asm/emergency-restart.h
9744 @@ -15,6 +15,6 @@ enum reboot_type {
9745
9746 extern enum reboot_type reboot_type;
9747
9748 -extern void machine_emergency_restart(void);
9749 +extern void machine_emergency_restart(void) __noreturn;
9750
9751 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
9752 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
9753 index d09bb03..4ea4194 100644
9754 --- a/arch/x86/include/asm/futex.h
9755 +++ b/arch/x86/include/asm/futex.h
9756 @@ -12,16 +12,18 @@
9757 #include <asm/system.h>
9758
9759 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
9760 + typecheck(u32 __user *, uaddr); \
9761 asm volatile("1:\t" insn "\n" \
9762 "2:\t.section .fixup,\"ax\"\n" \
9763 "3:\tmov\t%3, %1\n" \
9764 "\tjmp\t2b\n" \
9765 "\t.previous\n" \
9766 _ASM_EXTABLE(1b, 3b) \
9767 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
9768 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
9769 : "i" (-EFAULT), "0" (oparg), "1" (0))
9770
9771 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
9772 + typecheck(u32 __user *, uaddr); \
9773 asm volatile("1:\tmovl %2, %0\n" \
9774 "\tmovl\t%0, %3\n" \
9775 "\t" insn "\n" \
9776 @@ -34,7 +36,7 @@
9777 _ASM_EXTABLE(1b, 4b) \
9778 _ASM_EXTABLE(2b, 4b) \
9779 : "=&a" (oldval), "=&r" (ret), \
9780 - "+m" (*uaddr), "=&r" (tem) \
9781 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
9782 : "r" (oparg), "i" (-EFAULT), "1" (0))
9783
9784 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
9785 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
9786
9787 switch (op) {
9788 case FUTEX_OP_SET:
9789 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
9790 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
9791 break;
9792 case FUTEX_OP_ADD:
9793 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
9794 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
9795 uaddr, oparg);
9796 break;
9797 case FUTEX_OP_OR:
9798 @@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
9799 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
9800 return -EFAULT;
9801
9802 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
9803 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
9804 "2:\t.section .fixup, \"ax\"\n"
9805 "3:\tmov %3, %0\n"
9806 "\tjmp 2b\n"
9807 "\t.previous\n"
9808 _ASM_EXTABLE(1b, 3b)
9809 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
9810 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
9811 : "i" (-EFAULT), "r" (newval), "1" (oldval)
9812 : "memory"
9813 );
9814 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
9815 index eb92a6e..b98b2f4 100644
9816 --- a/arch/x86/include/asm/hw_irq.h
9817 +++ b/arch/x86/include/asm/hw_irq.h
9818 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
9819 extern void enable_IO_APIC(void);
9820
9821 /* Statistics */
9822 -extern atomic_t irq_err_count;
9823 -extern atomic_t irq_mis_count;
9824 +extern atomic_unchecked_t irq_err_count;
9825 +extern atomic_unchecked_t irq_mis_count;
9826
9827 /* EISA */
9828 extern void eisa_set_level_irq(unsigned int irq);
9829 diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
9830 index a850b4d..bae26dc 100644
9831 --- a/arch/x86/include/asm/i387.h
9832 +++ b/arch/x86/include/asm/i387.h
9833 @@ -92,6 +92,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
9834 {
9835 int err;
9836
9837 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9838 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
9839 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
9840 +#endif
9841 +
9842 /* See comment in fxsave() below. */
9843 #ifdef CONFIG_AS_FXSAVEQ
9844 asm volatile("1: fxrstorq %[fx]\n\t"
9845 @@ -121,6 +126,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
9846 {
9847 int err;
9848
9849 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9850 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
9851 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
9852 +#endif
9853 +
9854 /*
9855 * Clear the bytes not touched by the fxsave and reserved
9856 * for the SW usage.
9857 @@ -424,7 +434,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
9858 static inline bool interrupted_user_mode(void)
9859 {
9860 struct pt_regs *regs = get_irq_regs();
9861 - return regs && user_mode_vm(regs);
9862 + return regs && user_mode(regs);
9863 }
9864
9865 /*
9866 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
9867 index d8e8eef..99f81ae 100644
9868 --- a/arch/x86/include/asm/io.h
9869 +++ b/arch/x86/include/asm/io.h
9870 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
9871
9872 #include <linux/vmalloc.h>
9873
9874 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
9875 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
9876 +{
9877 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
9878 +}
9879 +
9880 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
9881 +{
9882 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
9883 +}
9884 +
9885 /*
9886 * Convert a virtual cached pointer to an uncached pointer
9887 */
9888 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
9889 index bba3cf8..06bc8da 100644
9890 --- a/arch/x86/include/asm/irqflags.h
9891 +++ b/arch/x86/include/asm/irqflags.h
9892 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
9893 sti; \
9894 sysexit
9895
9896 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
9897 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
9898 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
9899 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
9900 +
9901 #else
9902 #define INTERRUPT_RETURN iret
9903 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
9904 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
9905 index 5478825..839e88c 100644
9906 --- a/arch/x86/include/asm/kprobes.h
9907 +++ b/arch/x86/include/asm/kprobes.h
9908 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
9909 #define RELATIVEJUMP_SIZE 5
9910 #define RELATIVECALL_OPCODE 0xe8
9911 #define RELATIVE_ADDR_SIZE 4
9912 -#define MAX_STACK_SIZE 64
9913 -#define MIN_STACK_SIZE(ADDR) \
9914 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
9915 - THREAD_SIZE - (unsigned long)(ADDR))) \
9916 - ? (MAX_STACK_SIZE) \
9917 - : (((unsigned long)current_thread_info()) + \
9918 - THREAD_SIZE - (unsigned long)(ADDR)))
9919 +#define MAX_STACK_SIZE 64UL
9920 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
9921
9922 #define flush_insn_slot(p) do { } while (0)
9923
9924 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
9925 index b4973f4..7c4d3fc 100644
9926 --- a/arch/x86/include/asm/kvm_host.h
9927 +++ b/arch/x86/include/asm/kvm_host.h
9928 @@ -459,7 +459,7 @@ struct kvm_arch {
9929 unsigned int n_requested_mmu_pages;
9930 unsigned int n_max_mmu_pages;
9931 unsigned int indirect_shadow_pages;
9932 - atomic_t invlpg_counter;
9933 + atomic_unchecked_t invlpg_counter;
9934 struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
9935 /*
9936 * Hash table of struct kvm_mmu_page.
9937 @@ -638,7 +638,7 @@ struct kvm_x86_ops {
9938 int (*check_intercept)(struct kvm_vcpu *vcpu,
9939 struct x86_instruction_info *info,
9940 enum x86_intercept_stage stage);
9941 -};
9942 +} __do_const;
9943
9944 struct kvm_arch_async_pf {
9945 u32 token;
9946 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
9947 index 9cdae5d..300d20f 100644
9948 --- a/arch/x86/include/asm/local.h
9949 +++ b/arch/x86/include/asm/local.h
9950 @@ -18,26 +18,58 @@ typedef struct {
9951
9952 static inline void local_inc(local_t *l)
9953 {
9954 - asm volatile(_ASM_INC "%0"
9955 + asm volatile(_ASM_INC "%0\n"
9956 +
9957 +#ifdef CONFIG_PAX_REFCOUNT
9958 + "jno 0f\n"
9959 + _ASM_DEC "%0\n"
9960 + "int $4\n0:\n"
9961 + _ASM_EXTABLE(0b, 0b)
9962 +#endif
9963 +
9964 : "+m" (l->a.counter));
9965 }
9966
9967 static inline void local_dec(local_t *l)
9968 {
9969 - asm volatile(_ASM_DEC "%0"
9970 + asm volatile(_ASM_DEC "%0\n"
9971 +
9972 +#ifdef CONFIG_PAX_REFCOUNT
9973 + "jno 0f\n"
9974 + _ASM_INC "%0\n"
9975 + "int $4\n0:\n"
9976 + _ASM_EXTABLE(0b, 0b)
9977 +#endif
9978 +
9979 : "+m" (l->a.counter));
9980 }
9981
9982 static inline void local_add(long i, local_t *l)
9983 {
9984 - asm volatile(_ASM_ADD "%1,%0"
9985 + asm volatile(_ASM_ADD "%1,%0\n"
9986 +
9987 +#ifdef CONFIG_PAX_REFCOUNT
9988 + "jno 0f\n"
9989 + _ASM_SUB "%1,%0\n"
9990 + "int $4\n0:\n"
9991 + _ASM_EXTABLE(0b, 0b)
9992 +#endif
9993 +
9994 : "+m" (l->a.counter)
9995 : "ir" (i));
9996 }
9997
9998 static inline void local_sub(long i, local_t *l)
9999 {
10000 - asm volatile(_ASM_SUB "%1,%0"
10001 + asm volatile(_ASM_SUB "%1,%0\n"
10002 +
10003 +#ifdef CONFIG_PAX_REFCOUNT
10004 + "jno 0f\n"
10005 + _ASM_ADD "%1,%0\n"
10006 + "int $4\n0:\n"
10007 + _ASM_EXTABLE(0b, 0b)
10008 +#endif
10009 +
10010 : "+m" (l->a.counter)
10011 : "ir" (i));
10012 }
10013 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10014 {
10015 unsigned char c;
10016
10017 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10018 + asm volatile(_ASM_SUB "%2,%0\n"
10019 +
10020 +#ifdef CONFIG_PAX_REFCOUNT
10021 + "jno 0f\n"
10022 + _ASM_ADD "%2,%0\n"
10023 + "int $4\n0:\n"
10024 + _ASM_EXTABLE(0b, 0b)
10025 +#endif
10026 +
10027 + "sete %1\n"
10028 : "+m" (l->a.counter), "=qm" (c)
10029 : "ir" (i) : "memory");
10030 return c;
10031 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
10032 {
10033 unsigned char c;
10034
10035 - asm volatile(_ASM_DEC "%0; sete %1"
10036 + asm volatile(_ASM_DEC "%0\n"
10037 +
10038 +#ifdef CONFIG_PAX_REFCOUNT
10039 + "jno 0f\n"
10040 + _ASM_INC "%0\n"
10041 + "int $4\n0:\n"
10042 + _ASM_EXTABLE(0b, 0b)
10043 +#endif
10044 +
10045 + "sete %1\n"
10046 : "+m" (l->a.counter), "=qm" (c)
10047 : : "memory");
10048 return c != 0;
10049 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
10050 {
10051 unsigned char c;
10052
10053 - asm volatile(_ASM_INC "%0; sete %1"
10054 + asm volatile(_ASM_INC "%0\n"
10055 +
10056 +#ifdef CONFIG_PAX_REFCOUNT
10057 + "jno 0f\n"
10058 + _ASM_DEC "%0\n"
10059 + "int $4\n0:\n"
10060 + _ASM_EXTABLE(0b, 0b)
10061 +#endif
10062 +
10063 + "sete %1\n"
10064 : "+m" (l->a.counter), "=qm" (c)
10065 : : "memory");
10066 return c != 0;
10067 @@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
10068 {
10069 unsigned char c;
10070
10071 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10072 + asm volatile(_ASM_ADD "%2,%0\n"
10073 +
10074 +#ifdef CONFIG_PAX_REFCOUNT
10075 + "jno 0f\n"
10076 + _ASM_SUB "%2,%0\n"
10077 + "int $4\n0:\n"
10078 + _ASM_EXTABLE(0b, 0b)
10079 +#endif
10080 +
10081 + "sets %1\n"
10082 : "+m" (l->a.counter), "=qm" (c)
10083 : "ir" (i) : "memory");
10084 return c;
10085 @@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
10086 #endif
10087 /* Modern 486+ processor */
10088 __i = i;
10089 - asm volatile(_ASM_XADD "%0, %1;"
10090 + asm volatile(_ASM_XADD "%0, %1\n"
10091 +
10092 +#ifdef CONFIG_PAX_REFCOUNT
10093 + "jno 0f\n"
10094 + _ASM_MOV "%0,%1\n"
10095 + "int $4\n0:\n"
10096 + _ASM_EXTABLE(0b, 0b)
10097 +#endif
10098 +
10099 : "+r" (i), "+m" (l->a.counter)
10100 : : "memory");
10101 return i + __i;
10102 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10103 index 593e51d..fa69c9a 100644
10104 --- a/arch/x86/include/asm/mman.h
10105 +++ b/arch/x86/include/asm/mman.h
10106 @@ -5,4 +5,14 @@
10107
10108 #include <asm-generic/mman.h>
10109
10110 +#ifdef __KERNEL__
10111 +#ifndef __ASSEMBLY__
10112 +#ifdef CONFIG_X86_32
10113 +#define arch_mmap_check i386_mmap_check
10114 +int i386_mmap_check(unsigned long addr, unsigned long len,
10115 + unsigned long flags);
10116 +#endif
10117 +#endif
10118 +#endif
10119 +
10120 #endif /* _ASM_X86_MMAN_H */
10121 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10122 index 5f55e69..e20bfb1 100644
10123 --- a/arch/x86/include/asm/mmu.h
10124 +++ b/arch/x86/include/asm/mmu.h
10125 @@ -9,7 +9,7 @@
10126 * we put the segment information here.
10127 */
10128 typedef struct {
10129 - void *ldt;
10130 + struct desc_struct *ldt;
10131 int size;
10132
10133 #ifdef CONFIG_X86_64
10134 @@ -18,7 +18,19 @@ typedef struct {
10135 #endif
10136
10137 struct mutex lock;
10138 - void *vdso;
10139 + unsigned long vdso;
10140 +
10141 +#ifdef CONFIG_X86_32
10142 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10143 + unsigned long user_cs_base;
10144 + unsigned long user_cs_limit;
10145 +
10146 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10147 + cpumask_t cpu_user_cs_mask;
10148 +#endif
10149 +
10150 +#endif
10151 +#endif
10152 } mm_context_t;
10153
10154 #ifdef CONFIG_SMP
10155 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10156 index 6902152..399f3a2 100644
10157 --- a/arch/x86/include/asm/mmu_context.h
10158 +++ b/arch/x86/include/asm/mmu_context.h
10159 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10160
10161 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10162 {
10163 +
10164 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10165 + unsigned int i;
10166 + pgd_t *pgd;
10167 +
10168 + pax_open_kernel();
10169 + pgd = get_cpu_pgd(smp_processor_id());
10170 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10171 + set_pgd_batched(pgd+i, native_make_pgd(0));
10172 + pax_close_kernel();
10173 +#endif
10174 +
10175 #ifdef CONFIG_SMP
10176 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10177 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10178 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10179 struct task_struct *tsk)
10180 {
10181 unsigned cpu = smp_processor_id();
10182 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10183 + int tlbstate = TLBSTATE_OK;
10184 +#endif
10185
10186 if (likely(prev != next)) {
10187 #ifdef CONFIG_SMP
10188 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10189 + tlbstate = percpu_read(cpu_tlbstate.state);
10190 +#endif
10191 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10192 percpu_write(cpu_tlbstate.active_mm, next);
10193 #endif
10194 cpumask_set_cpu(cpu, mm_cpumask(next));
10195
10196 /* Re-load page tables */
10197 +#ifdef CONFIG_PAX_PER_CPU_PGD
10198 + pax_open_kernel();
10199 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10200 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10201 + pax_close_kernel();
10202 + load_cr3(get_cpu_pgd(cpu));
10203 +#else
10204 load_cr3(next->pgd);
10205 +#endif
10206
10207 /* stop flush ipis for the previous mm */
10208 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10209 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10210 */
10211 if (unlikely(prev->context.ldt != next->context.ldt))
10212 load_LDT_nolock(&next->context);
10213 - }
10214 +
10215 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10216 + if (!(__supported_pte_mask & _PAGE_NX)) {
10217 + smp_mb__before_clear_bit();
10218 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10219 + smp_mb__after_clear_bit();
10220 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10221 + }
10222 +#endif
10223 +
10224 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10225 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10226 + prev->context.user_cs_limit != next->context.user_cs_limit))
10227 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10228 #ifdef CONFIG_SMP
10229 + else if (unlikely(tlbstate != TLBSTATE_OK))
10230 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10231 +#endif
10232 +#endif
10233 +
10234 + }
10235 else {
10236 +
10237 +#ifdef CONFIG_PAX_PER_CPU_PGD
10238 + pax_open_kernel();
10239 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10240 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10241 + pax_close_kernel();
10242 + load_cr3(get_cpu_pgd(cpu));
10243 +#endif
10244 +
10245 +#ifdef CONFIG_SMP
10246 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10247 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10248
10249 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10250 * tlb flush IPI delivery. We must reload CR3
10251 * to make sure to use no freed page tables.
10252 */
10253 +
10254 +#ifndef CONFIG_PAX_PER_CPU_PGD
10255 load_cr3(next->pgd);
10256 +#endif
10257 +
10258 load_LDT_nolock(&next->context);
10259 +
10260 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10261 + if (!(__supported_pte_mask & _PAGE_NX))
10262 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10263 +#endif
10264 +
10265 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10266 +#ifdef CONFIG_PAX_PAGEEXEC
10267 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10268 +#endif
10269 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10270 +#endif
10271 +
10272 }
10273 +#endif
10274 }
10275 -#endif
10276 }
10277
10278 #define activate_mm(prev, next) \
10279 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
10280 index 9eae775..c914fea 100644
10281 --- a/arch/x86/include/asm/module.h
10282 +++ b/arch/x86/include/asm/module.h
10283 @@ -5,6 +5,7 @@
10284
10285 #ifdef CONFIG_X86_64
10286 /* X86_64 does not define MODULE_PROC_FAMILY */
10287 +#define MODULE_PROC_FAMILY ""
10288 #elif defined CONFIG_M386
10289 #define MODULE_PROC_FAMILY "386 "
10290 #elif defined CONFIG_M486
10291 @@ -59,8 +60,20 @@
10292 #error unknown processor family
10293 #endif
10294
10295 -#ifdef CONFIG_X86_32
10296 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
10297 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10298 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
10299 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
10300 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
10301 +#else
10302 +#define MODULE_PAX_KERNEXEC ""
10303 #endif
10304
10305 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10306 +#define MODULE_PAX_UDEREF "UDEREF "
10307 +#else
10308 +#define MODULE_PAX_UDEREF ""
10309 +#endif
10310 +
10311 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
10312 +
10313 #endif /* _ASM_X86_MODULE_H */
10314 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
10315 index 7639dbf..e08a58c 100644
10316 --- a/arch/x86/include/asm/page_64_types.h
10317 +++ b/arch/x86/include/asm/page_64_types.h
10318 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10319
10320 /* duplicated to the one in bootmem.h */
10321 extern unsigned long max_pfn;
10322 -extern unsigned long phys_base;
10323 +extern const unsigned long phys_base;
10324
10325 extern unsigned long __phys_addr(unsigned long);
10326 #define __phys_reloc_hide(x) (x)
10327 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
10328 index a7d2db9..edb023e 100644
10329 --- a/arch/x86/include/asm/paravirt.h
10330 +++ b/arch/x86/include/asm/paravirt.h
10331 @@ -667,6 +667,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
10332 val);
10333 }
10334
10335 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
10336 +{
10337 + pgdval_t val = native_pgd_val(pgd);
10338 +
10339 + if (sizeof(pgdval_t) > sizeof(long))
10340 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
10341 + val, (u64)val >> 32);
10342 + else
10343 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
10344 + val);
10345 +}
10346 +
10347 static inline void pgd_clear(pgd_t *pgdp)
10348 {
10349 set_pgd(pgdp, __pgd(0));
10350 @@ -748,6 +760,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
10351 pv_mmu_ops.set_fixmap(idx, phys, flags);
10352 }
10353
10354 +#ifdef CONFIG_PAX_KERNEXEC
10355 +static inline unsigned long pax_open_kernel(void)
10356 +{
10357 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10358 +}
10359 +
10360 +static inline unsigned long pax_close_kernel(void)
10361 +{
10362 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10363 +}
10364 +#else
10365 +static inline unsigned long pax_open_kernel(void) { return 0; }
10366 +static inline unsigned long pax_close_kernel(void) { return 0; }
10367 +#endif
10368 +
10369 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10370
10371 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
10372 @@ -964,7 +991,7 @@ extern void default_banner(void);
10373
10374 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10375 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10376 -#define PARA_INDIRECT(addr) *%cs:addr
10377 +#define PARA_INDIRECT(addr) *%ss:addr
10378 #endif
10379
10380 #define INTERRUPT_RETURN \
10381 @@ -1041,6 +1068,21 @@ extern void default_banner(void);
10382 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
10383 CLBR_NONE, \
10384 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
10385 +
10386 +#define GET_CR0_INTO_RDI \
10387 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
10388 + mov %rax,%rdi
10389 +
10390 +#define SET_RDI_INTO_CR0 \
10391 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
10392 +
10393 +#define GET_CR3_INTO_RDI \
10394 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
10395 + mov %rax,%rdi
10396 +
10397 +#define SET_RDI_INTO_CR3 \
10398 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
10399 +
10400 #endif /* CONFIG_X86_32 */
10401
10402 #endif /* __ASSEMBLY__ */
10403 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
10404 index 8e8b9a4..f07d725 100644
10405 --- a/arch/x86/include/asm/paravirt_types.h
10406 +++ b/arch/x86/include/asm/paravirt_types.h
10407 @@ -84,20 +84,20 @@ struct pv_init_ops {
10408 */
10409 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
10410 unsigned long addr, unsigned len);
10411 -};
10412 +} __no_const;
10413
10414
10415 struct pv_lazy_ops {
10416 /* Set deferred update mode, used for batching operations. */
10417 void (*enter)(void);
10418 void (*leave)(void);
10419 -};
10420 +} __no_const;
10421
10422 struct pv_time_ops {
10423 unsigned long long (*sched_clock)(void);
10424 unsigned long long (*steal_clock)(int cpu);
10425 unsigned long (*get_tsc_khz)(void);
10426 -};
10427 +} __no_const;
10428
10429 struct pv_cpu_ops {
10430 /* hooks for various privileged instructions */
10431 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
10432
10433 void (*start_context_switch)(struct task_struct *prev);
10434 void (*end_context_switch)(struct task_struct *next);
10435 -};
10436 +} __no_const;
10437
10438 struct pv_irq_ops {
10439 /*
10440 @@ -224,7 +224,7 @@ struct pv_apic_ops {
10441 unsigned long start_eip,
10442 unsigned long start_esp);
10443 #endif
10444 -};
10445 +} __no_const;
10446
10447 struct pv_mmu_ops {
10448 unsigned long (*read_cr2)(void);
10449 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
10450 struct paravirt_callee_save make_pud;
10451
10452 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
10453 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
10454 #endif /* PAGETABLE_LEVELS == 4 */
10455 #endif /* PAGETABLE_LEVELS >= 3 */
10456
10457 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
10458 an mfn. We can tell which is which from the index. */
10459 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
10460 phys_addr_t phys, pgprot_t flags);
10461 +
10462 +#ifdef CONFIG_PAX_KERNEXEC
10463 + unsigned long (*pax_open_kernel)(void);
10464 + unsigned long (*pax_close_kernel)(void);
10465 +#endif
10466 +
10467 };
10468
10469 struct arch_spinlock;
10470 @@ -334,7 +341,7 @@ struct pv_lock_ops {
10471 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
10472 int (*spin_trylock)(struct arch_spinlock *lock);
10473 void (*spin_unlock)(struct arch_spinlock *lock);
10474 -};
10475 +} __no_const;
10476
10477 /* This contains all the paravirt structures: we get a convenient
10478 * number for each function using the offset which we use to indicate
10479 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
10480 index b4389a4..b7ff22c 100644
10481 --- a/arch/x86/include/asm/pgalloc.h
10482 +++ b/arch/x86/include/asm/pgalloc.h
10483 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
10484 pmd_t *pmd, pte_t *pte)
10485 {
10486 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10487 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
10488 +}
10489 +
10490 +static inline void pmd_populate_user(struct mm_struct *mm,
10491 + pmd_t *pmd, pte_t *pte)
10492 +{
10493 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10494 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
10495 }
10496
10497 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
10498 index 98391db..8f6984e 100644
10499 --- a/arch/x86/include/asm/pgtable-2level.h
10500 +++ b/arch/x86/include/asm/pgtable-2level.h
10501 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
10502
10503 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10504 {
10505 + pax_open_kernel();
10506 *pmdp = pmd;
10507 + pax_close_kernel();
10508 }
10509
10510 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10511 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
10512 index effff47..f9e4035 100644
10513 --- a/arch/x86/include/asm/pgtable-3level.h
10514 +++ b/arch/x86/include/asm/pgtable-3level.h
10515 @@ -38,12 +38,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10516
10517 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10518 {
10519 + pax_open_kernel();
10520 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
10521 + pax_close_kernel();
10522 }
10523
10524 static inline void native_set_pud(pud_t *pudp, pud_t pud)
10525 {
10526 + pax_open_kernel();
10527 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
10528 + pax_close_kernel();
10529 }
10530
10531 /*
10532 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
10533 index 18601c8..3d716d1 100644
10534 --- a/arch/x86/include/asm/pgtable.h
10535 +++ b/arch/x86/include/asm/pgtable.h
10536 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
10537
10538 #ifndef __PAGETABLE_PUD_FOLDED
10539 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
10540 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
10541 #define pgd_clear(pgd) native_pgd_clear(pgd)
10542 #endif
10543
10544 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
10545
10546 #define arch_end_context_switch(prev) do {} while(0)
10547
10548 +#define pax_open_kernel() native_pax_open_kernel()
10549 +#define pax_close_kernel() native_pax_close_kernel()
10550 #endif /* CONFIG_PARAVIRT */
10551
10552 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
10553 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
10554 +
10555 +#ifdef CONFIG_PAX_KERNEXEC
10556 +static inline unsigned long native_pax_open_kernel(void)
10557 +{
10558 + unsigned long cr0;
10559 +
10560 + preempt_disable();
10561 + barrier();
10562 + cr0 = read_cr0() ^ X86_CR0_WP;
10563 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
10564 + write_cr0(cr0);
10565 + return cr0 ^ X86_CR0_WP;
10566 +}
10567 +
10568 +static inline unsigned long native_pax_close_kernel(void)
10569 +{
10570 + unsigned long cr0;
10571 +
10572 + cr0 = read_cr0() ^ X86_CR0_WP;
10573 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
10574 + write_cr0(cr0);
10575 + barrier();
10576 + preempt_enable_no_resched();
10577 + return cr0 ^ X86_CR0_WP;
10578 +}
10579 +#else
10580 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
10581 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
10582 +#endif
10583 +
10584 /*
10585 * The following only work if pte_present() is true.
10586 * Undefined behaviour if not..
10587 */
10588 +static inline int pte_user(pte_t pte)
10589 +{
10590 + return pte_val(pte) & _PAGE_USER;
10591 +}
10592 +
10593 static inline int pte_dirty(pte_t pte)
10594 {
10595 return pte_flags(pte) & _PAGE_DIRTY;
10596 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
10597 return pte_clear_flags(pte, _PAGE_RW);
10598 }
10599
10600 +static inline pte_t pte_mkread(pte_t pte)
10601 +{
10602 + return __pte(pte_val(pte) | _PAGE_USER);
10603 +}
10604 +
10605 static inline pte_t pte_mkexec(pte_t pte)
10606 {
10607 - return pte_clear_flags(pte, _PAGE_NX);
10608 +#ifdef CONFIG_X86_PAE
10609 + if (__supported_pte_mask & _PAGE_NX)
10610 + return pte_clear_flags(pte, _PAGE_NX);
10611 + else
10612 +#endif
10613 + return pte_set_flags(pte, _PAGE_USER);
10614 +}
10615 +
10616 +static inline pte_t pte_exprotect(pte_t pte)
10617 +{
10618 +#ifdef CONFIG_X86_PAE
10619 + if (__supported_pte_mask & _PAGE_NX)
10620 + return pte_set_flags(pte, _PAGE_NX);
10621 + else
10622 +#endif
10623 + return pte_clear_flags(pte, _PAGE_USER);
10624 }
10625
10626 static inline pte_t pte_mkdirty(pte_t pte)
10627 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
10628 #endif
10629
10630 #ifndef __ASSEMBLY__
10631 +
10632 +#ifdef CONFIG_PAX_PER_CPU_PGD
10633 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
10634 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
10635 +{
10636 + return cpu_pgd[cpu];
10637 +}
10638 +#endif
10639 +
10640 #include <linux/mm_types.h>
10641
10642 static inline int pte_none(pte_t pte)
10643 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
10644
10645 static inline int pgd_bad(pgd_t pgd)
10646 {
10647 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
10648 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
10649 }
10650
10651 static inline int pgd_none(pgd_t pgd)
10652 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
10653 * pgd_offset() returns a (pgd_t *)
10654 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
10655 */
10656 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
10657 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
10658 +
10659 +#ifdef CONFIG_PAX_PER_CPU_PGD
10660 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
10661 +#endif
10662 +
10663 /*
10664 * a shortcut which implies the use of the kernel's pgd, instead
10665 * of a process's
10666 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
10667 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
10668 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
10669
10670 +#ifdef CONFIG_X86_32
10671 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
10672 +#else
10673 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
10674 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
10675 +
10676 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10677 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
10678 +#else
10679 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
10680 +#endif
10681 +
10682 +#endif
10683 +
10684 #ifndef __ASSEMBLY__
10685
10686 extern int direct_gbpages;
10687 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
10688 * dst and src can be on the same page, but the range must not overlap,
10689 * and must not cross a page boundary.
10690 */
10691 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
10692 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
10693 {
10694 - memcpy(dst, src, count * sizeof(pgd_t));
10695 + pax_open_kernel();
10696 + while (count--)
10697 + *dst++ = *src++;
10698 + pax_close_kernel();
10699 }
10700
10701 +#ifdef CONFIG_PAX_PER_CPU_PGD
10702 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10703 +#endif
10704 +
10705 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10706 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10707 +#else
10708 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
10709 +#endif
10710
10711 #include <asm-generic/pgtable.h>
10712 #endif /* __ASSEMBLY__ */
10713 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
10714 index 0c92113..34a77c6 100644
10715 --- a/arch/x86/include/asm/pgtable_32.h
10716 +++ b/arch/x86/include/asm/pgtable_32.h
10717 @@ -25,9 +25,6 @@
10718 struct mm_struct;
10719 struct vm_area_struct;
10720
10721 -extern pgd_t swapper_pg_dir[1024];
10722 -extern pgd_t initial_page_table[1024];
10723 -
10724 static inline void pgtable_cache_init(void) { }
10725 static inline void check_pgt_cache(void) { }
10726 void paging_init(void);
10727 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
10728 # include <asm/pgtable-2level.h>
10729 #endif
10730
10731 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
10732 +extern pgd_t initial_page_table[PTRS_PER_PGD];
10733 +#ifdef CONFIG_X86_PAE
10734 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
10735 +#endif
10736 +
10737 #if defined(CONFIG_HIGHPTE)
10738 #define pte_offset_map(dir, address) \
10739 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
10740 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
10741 /* Clear a kernel PTE and flush it from the TLB */
10742 #define kpte_clear_flush(ptep, vaddr) \
10743 do { \
10744 + pax_open_kernel(); \
10745 pte_clear(&init_mm, (vaddr), (ptep)); \
10746 + pax_close_kernel(); \
10747 __flush_tlb_one((vaddr)); \
10748 } while (0)
10749
10750 @@ -74,6 +79,9 @@ do { \
10751
10752 #endif /* !__ASSEMBLY__ */
10753
10754 +#define HAVE_ARCH_UNMAPPED_AREA
10755 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
10756 +
10757 /*
10758 * kern_addr_valid() is (1) for FLATMEM and (0) for
10759 * SPARSEMEM and DISCONTIGMEM
10760 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
10761 index ed5903b..c7fe163 100644
10762 --- a/arch/x86/include/asm/pgtable_32_types.h
10763 +++ b/arch/x86/include/asm/pgtable_32_types.h
10764 @@ -8,7 +8,7 @@
10765 */
10766 #ifdef CONFIG_X86_PAE
10767 # include <asm/pgtable-3level_types.h>
10768 -# define PMD_SIZE (1UL << PMD_SHIFT)
10769 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
10770 # define PMD_MASK (~(PMD_SIZE - 1))
10771 #else
10772 # include <asm/pgtable-2level_types.h>
10773 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
10774 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
10775 #endif
10776
10777 +#ifdef CONFIG_PAX_KERNEXEC
10778 +#ifndef __ASSEMBLY__
10779 +extern unsigned char MODULES_EXEC_VADDR[];
10780 +extern unsigned char MODULES_EXEC_END[];
10781 +#endif
10782 +#include <asm/boot.h>
10783 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
10784 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
10785 +#else
10786 +#define ktla_ktva(addr) (addr)
10787 +#define ktva_ktla(addr) (addr)
10788 +#endif
10789 +
10790 #define MODULES_VADDR VMALLOC_START
10791 #define MODULES_END VMALLOC_END
10792 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
10793 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
10794 index 975f709..107976d 100644
10795 --- a/arch/x86/include/asm/pgtable_64.h
10796 +++ b/arch/x86/include/asm/pgtable_64.h
10797 @@ -16,10 +16,14 @@
10798
10799 extern pud_t level3_kernel_pgt[512];
10800 extern pud_t level3_ident_pgt[512];
10801 +extern pud_t level3_vmalloc_start_pgt[512];
10802 +extern pud_t level3_vmalloc_end_pgt[512];
10803 +extern pud_t level3_vmemmap_pgt[512];
10804 +extern pud_t level2_vmemmap_pgt[512];
10805 extern pmd_t level2_kernel_pgt[512];
10806 extern pmd_t level2_fixmap_pgt[512];
10807 -extern pmd_t level2_ident_pgt[512];
10808 -extern pgd_t init_level4_pgt[];
10809 +extern pmd_t level2_ident_pgt[512*2];
10810 +extern pgd_t init_level4_pgt[512];
10811
10812 #define swapper_pg_dir init_level4_pgt
10813
10814 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10815
10816 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10817 {
10818 + pax_open_kernel();
10819 *pmdp = pmd;
10820 + pax_close_kernel();
10821 }
10822
10823 static inline void native_pmd_clear(pmd_t *pmd)
10824 @@ -107,6 +113,13 @@ static inline void native_pud_clear(pud_t *pud)
10825
10826 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
10827 {
10828 + pax_open_kernel();
10829 + *pgdp = pgd;
10830 + pax_close_kernel();
10831 +}
10832 +
10833 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
10834 +{
10835 *pgdp = pgd;
10836 }
10837
10838 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
10839 index 766ea16..5b96cb3 100644
10840 --- a/arch/x86/include/asm/pgtable_64_types.h
10841 +++ b/arch/x86/include/asm/pgtable_64_types.h
10842 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
10843 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
10844 #define MODULES_END _AC(0xffffffffff000000, UL)
10845 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
10846 +#define MODULES_EXEC_VADDR MODULES_VADDR
10847 +#define MODULES_EXEC_END MODULES_END
10848 +
10849 +#define ktla_ktva(addr) (addr)
10850 +#define ktva_ktla(addr) (addr)
10851
10852 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
10853 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
10854 index 013286a..8b42f4f 100644
10855 --- a/arch/x86/include/asm/pgtable_types.h
10856 +++ b/arch/x86/include/asm/pgtable_types.h
10857 @@ -16,13 +16,12 @@
10858 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
10859 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
10860 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
10861 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
10862 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
10863 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
10864 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
10865 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
10866 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
10867 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
10868 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
10869 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
10870 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
10871 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
10872
10873 /* If _PAGE_BIT_PRESENT is clear, we use these: */
10874 @@ -40,7 +39,6 @@
10875 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
10876 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
10877 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
10878 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
10879 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
10880 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
10881 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
10882 @@ -57,8 +55,10 @@
10883
10884 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
10885 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
10886 -#else
10887 +#elif defined(CONFIG_KMEMCHECK)
10888 #define _PAGE_NX (_AT(pteval_t, 0))
10889 +#else
10890 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
10891 #endif
10892
10893 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
10894 @@ -96,6 +96,9 @@
10895 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
10896 _PAGE_ACCESSED)
10897
10898 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
10899 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
10900 +
10901 #define __PAGE_KERNEL_EXEC \
10902 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
10903 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
10904 @@ -106,7 +109,7 @@
10905 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
10906 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
10907 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
10908 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
10909 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
10910 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
10911 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
10912 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
10913 @@ -168,8 +171,8 @@
10914 * bits are combined, this will alow user to access the high address mapped
10915 * VDSO in the presence of CONFIG_COMPAT_VDSO
10916 */
10917 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
10918 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
10919 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
10920 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
10921 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
10922 #endif
10923
10924 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
10925 {
10926 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
10927 }
10928 +#endif
10929
10930 +#if PAGETABLE_LEVELS == 3
10931 +#include <asm-generic/pgtable-nopud.h>
10932 +#endif
10933 +
10934 +#if PAGETABLE_LEVELS == 2
10935 +#include <asm-generic/pgtable-nopmd.h>
10936 +#endif
10937 +
10938 +#ifndef __ASSEMBLY__
10939 #if PAGETABLE_LEVELS > 3
10940 typedef struct { pudval_t pud; } pud_t;
10941
10942 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
10943 return pud.pud;
10944 }
10945 #else
10946 -#include <asm-generic/pgtable-nopud.h>
10947 -
10948 static inline pudval_t native_pud_val(pud_t pud)
10949 {
10950 return native_pgd_val(pud.pgd);
10951 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
10952 return pmd.pmd;
10953 }
10954 #else
10955 -#include <asm-generic/pgtable-nopmd.h>
10956 -
10957 static inline pmdval_t native_pmd_val(pmd_t pmd)
10958 {
10959 return native_pgd_val(pmd.pud.pgd);
10960 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
10961
10962 extern pteval_t __supported_pte_mask;
10963 extern void set_nx(void);
10964 -extern int nx_enabled;
10965
10966 #define pgprot_writecombine pgprot_writecombine
10967 extern pgprot_t pgprot_writecombine(pgprot_t prot);
10968 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
10969 index bb3ee36..781a6b8 100644
10970 --- a/arch/x86/include/asm/processor.h
10971 +++ b/arch/x86/include/asm/processor.h
10972 @@ -268,7 +268,7 @@ struct tss_struct {
10973
10974 } ____cacheline_aligned;
10975
10976 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
10977 +extern struct tss_struct init_tss[NR_CPUS];
10978
10979 /*
10980 * Save the original ist values for checking stack pointers during debugging
10981 @@ -861,11 +861,18 @@ static inline void spin_lock_prefetch(const void *x)
10982 */
10983 #define TASK_SIZE PAGE_OFFSET
10984 #define TASK_SIZE_MAX TASK_SIZE
10985 +
10986 +#ifdef CONFIG_PAX_SEGMEXEC
10987 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
10988 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
10989 +#else
10990 #define STACK_TOP TASK_SIZE
10991 -#define STACK_TOP_MAX STACK_TOP
10992 +#endif
10993 +
10994 +#define STACK_TOP_MAX TASK_SIZE
10995
10996 #define INIT_THREAD { \
10997 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
10998 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
10999 .vm86_info = NULL, \
11000 .sysenter_cs = __KERNEL_CS, \
11001 .io_bitmap_ptr = NULL, \
11002 @@ -879,7 +886,7 @@ static inline void spin_lock_prefetch(const void *x)
11003 */
11004 #define INIT_TSS { \
11005 .x86_tss = { \
11006 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11007 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11008 .ss0 = __KERNEL_DS, \
11009 .ss1 = __KERNEL_CS, \
11010 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11011 @@ -890,11 +897,7 @@ static inline void spin_lock_prefetch(const void *x)
11012 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11013
11014 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11015 -#define KSTK_TOP(info) \
11016 -({ \
11017 - unsigned long *__ptr = (unsigned long *)(info); \
11018 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11019 -})
11020 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11021
11022 /*
11023 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11024 @@ -909,7 +912,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11025 #define task_pt_regs(task) \
11026 ({ \
11027 struct pt_regs *__regs__; \
11028 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11029 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11030 __regs__ - 1; \
11031 })
11032
11033 @@ -919,13 +922,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11034 /*
11035 * User space process size. 47bits minus one guard page.
11036 */
11037 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11038 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11039
11040 /* This decides where the kernel will search for a free chunk of vm
11041 * space during mmap's.
11042 */
11043 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11044 - 0xc0000000 : 0xFFFFe000)
11045 + 0xc0000000 : 0xFFFFf000)
11046
11047 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
11048 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11049 @@ -936,11 +939,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11050 #define STACK_TOP_MAX TASK_SIZE_MAX
11051
11052 #define INIT_THREAD { \
11053 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11054 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11055 }
11056
11057 #define INIT_TSS { \
11058 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11059 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11060 }
11061
11062 /*
11063 @@ -962,6 +965,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11064 */
11065 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11066
11067 +#ifdef CONFIG_PAX_SEGMEXEC
11068 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11069 +#endif
11070 +
11071 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11072
11073 /* Get/set a process' ability to use the timestamp counter instruction */
11074 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11075 index 3566454..4bdfb8c 100644
11076 --- a/arch/x86/include/asm/ptrace.h
11077 +++ b/arch/x86/include/asm/ptrace.h
11078 @@ -156,28 +156,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11079 }
11080
11081 /*
11082 - * user_mode_vm(regs) determines whether a register set came from user mode.
11083 + * user_mode(regs) determines whether a register set came from user mode.
11084 * This is true if V8086 mode was enabled OR if the register set was from
11085 * protected mode with RPL-3 CS value. This tricky test checks that with
11086 * one comparison. Many places in the kernel can bypass this full check
11087 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11088 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11089 + * be used.
11090 */
11091 -static inline int user_mode(struct pt_regs *regs)
11092 +static inline int user_mode_novm(struct pt_regs *regs)
11093 {
11094 #ifdef CONFIG_X86_32
11095 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11096 #else
11097 - return !!(regs->cs & 3);
11098 + return !!(regs->cs & SEGMENT_RPL_MASK);
11099 #endif
11100 }
11101
11102 -static inline int user_mode_vm(struct pt_regs *regs)
11103 +static inline int user_mode(struct pt_regs *regs)
11104 {
11105 #ifdef CONFIG_X86_32
11106 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11107 USER_RPL;
11108 #else
11109 - return user_mode(regs);
11110 + return user_mode_novm(regs);
11111 #endif
11112 }
11113
11114 @@ -193,15 +194,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11115 #ifdef CONFIG_X86_64
11116 static inline bool user_64bit_mode(struct pt_regs *regs)
11117 {
11118 + unsigned long cs = regs->cs & 0xffff;
11119 #ifndef CONFIG_PARAVIRT
11120 /*
11121 * On non-paravirt systems, this is the only long mode CPL 3
11122 * selector. We do not allow long mode selectors in the LDT.
11123 */
11124 - return regs->cs == __USER_CS;
11125 + return cs == __USER_CS;
11126 #else
11127 /* Headers are too twisted for this to go in paravirt.h. */
11128 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11129 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11130 #endif
11131 }
11132 #endif
11133 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11134 index 92f29706..a79cbbb 100644
11135 --- a/arch/x86/include/asm/reboot.h
11136 +++ b/arch/x86/include/asm/reboot.h
11137 @@ -6,19 +6,19 @@
11138 struct pt_regs;
11139
11140 struct machine_ops {
11141 - void (*restart)(char *cmd);
11142 - void (*halt)(void);
11143 - void (*power_off)(void);
11144 + void (* __noreturn restart)(char *cmd);
11145 + void (* __noreturn halt)(void);
11146 + void (* __noreturn power_off)(void);
11147 void (*shutdown)(void);
11148 void (*crash_shutdown)(struct pt_regs *);
11149 - void (*emergency_restart)(void);
11150 -};
11151 + void (* __noreturn emergency_restart)(void);
11152 +} __no_const;
11153
11154 extern struct machine_ops machine_ops;
11155
11156 void native_machine_crash_shutdown(struct pt_regs *regs);
11157 void native_machine_shutdown(void);
11158 -void machine_real_restart(unsigned int type);
11159 +void machine_real_restart(unsigned int type) __noreturn;
11160 /* These must match dispatch_table in reboot_32.S */
11161 #define MRR_BIOS 0
11162 #define MRR_APM 1
11163 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11164 index 2dbe4a7..ce1db00 100644
11165 --- a/arch/x86/include/asm/rwsem.h
11166 +++ b/arch/x86/include/asm/rwsem.h
11167 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11168 {
11169 asm volatile("# beginning down_read\n\t"
11170 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11171 +
11172 +#ifdef CONFIG_PAX_REFCOUNT
11173 + "jno 0f\n"
11174 + LOCK_PREFIX _ASM_DEC "(%1)\n"
11175 + "int $4\n0:\n"
11176 + _ASM_EXTABLE(0b, 0b)
11177 +#endif
11178 +
11179 /* adds 0x00000001 */
11180 " jns 1f\n"
11181 " call call_rwsem_down_read_failed\n"
11182 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11183 "1:\n\t"
11184 " mov %1,%2\n\t"
11185 " add %3,%2\n\t"
11186 +
11187 +#ifdef CONFIG_PAX_REFCOUNT
11188 + "jno 0f\n"
11189 + "sub %3,%2\n"
11190 + "int $4\n0:\n"
11191 + _ASM_EXTABLE(0b, 0b)
11192 +#endif
11193 +
11194 " jle 2f\n\t"
11195 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11196 " jnz 1b\n\t"
11197 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
11198 long tmp;
11199 asm volatile("# beginning down_write\n\t"
11200 LOCK_PREFIX " xadd %1,(%2)\n\t"
11201 +
11202 +#ifdef CONFIG_PAX_REFCOUNT
11203 + "jno 0f\n"
11204 + "mov %1,(%2)\n"
11205 + "int $4\n0:\n"
11206 + _ASM_EXTABLE(0b, 0b)
11207 +#endif
11208 +
11209 /* adds 0xffff0001, returns the old value */
11210 " test %1,%1\n\t"
11211 /* was the count 0 before? */
11212 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
11213 long tmp;
11214 asm volatile("# beginning __up_read\n\t"
11215 LOCK_PREFIX " xadd %1,(%2)\n\t"
11216 +
11217 +#ifdef CONFIG_PAX_REFCOUNT
11218 + "jno 0f\n"
11219 + "mov %1,(%2)\n"
11220 + "int $4\n0:\n"
11221 + _ASM_EXTABLE(0b, 0b)
11222 +#endif
11223 +
11224 /* subtracts 1, returns the old value */
11225 " jns 1f\n\t"
11226 " call call_rwsem_wake\n" /* expects old value in %edx */
11227 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
11228 long tmp;
11229 asm volatile("# beginning __up_write\n\t"
11230 LOCK_PREFIX " xadd %1,(%2)\n\t"
11231 +
11232 +#ifdef CONFIG_PAX_REFCOUNT
11233 + "jno 0f\n"
11234 + "mov %1,(%2)\n"
11235 + "int $4\n0:\n"
11236 + _ASM_EXTABLE(0b, 0b)
11237 +#endif
11238 +
11239 /* subtracts 0xffff0001, returns the old value */
11240 " jns 1f\n\t"
11241 " call call_rwsem_wake\n" /* expects old value in %edx */
11242 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11243 {
11244 asm volatile("# beginning __downgrade_write\n\t"
11245 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
11246 +
11247 +#ifdef CONFIG_PAX_REFCOUNT
11248 + "jno 0f\n"
11249 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11250 + "int $4\n0:\n"
11251 + _ASM_EXTABLE(0b, 0b)
11252 +#endif
11253 +
11254 /*
11255 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11256 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11257 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11258 */
11259 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11260 {
11261 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11262 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11263 +
11264 +#ifdef CONFIG_PAX_REFCOUNT
11265 + "jno 0f\n"
11266 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
11267 + "int $4\n0:\n"
11268 + _ASM_EXTABLE(0b, 0b)
11269 +#endif
11270 +
11271 : "+m" (sem->count)
11272 : "er" (delta));
11273 }
11274 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11275 */
11276 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
11277 {
11278 - return delta + xadd(&sem->count, delta);
11279 + return delta + xadd_check_overflow(&sem->count, delta);
11280 }
11281
11282 #endif /* __KERNEL__ */
11283 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
11284 index 5e64171..f58957e 100644
11285 --- a/arch/x86/include/asm/segment.h
11286 +++ b/arch/x86/include/asm/segment.h
11287 @@ -64,10 +64,15 @@
11288 * 26 - ESPFIX small SS
11289 * 27 - per-cpu [ offset to per-cpu data area ]
11290 * 28 - stack_canary-20 [ for stack protector ]
11291 - * 29 - unused
11292 - * 30 - unused
11293 + * 29 - PCI BIOS CS
11294 + * 30 - PCI BIOS DS
11295 * 31 - TSS for double fault handler
11296 */
11297 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
11298 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
11299 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
11300 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
11301 +
11302 #define GDT_ENTRY_TLS_MIN 6
11303 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
11304
11305 @@ -79,6 +84,8 @@
11306
11307 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
11308
11309 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
11310 +
11311 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
11312
11313 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
11314 @@ -104,6 +111,12 @@
11315 #define __KERNEL_STACK_CANARY 0
11316 #endif
11317
11318 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
11319 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
11320 +
11321 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
11322 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
11323 +
11324 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
11325
11326 /*
11327 @@ -141,7 +154,7 @@
11328 */
11329
11330 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
11331 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
11332 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
11333
11334
11335 #else
11336 @@ -165,6 +178,8 @@
11337 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
11338 #define __USER32_DS __USER_DS
11339
11340 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
11341 +
11342 #define GDT_ENTRY_TSS 8 /* needs two entries */
11343 #define GDT_ENTRY_LDT 10 /* needs two entries */
11344 #define GDT_ENTRY_TLS_MIN 12
11345 @@ -185,6 +200,7 @@
11346 #endif
11347
11348 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
11349 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
11350 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
11351 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
11352 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
11353 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
11354 index 73b11bc..d4a3b63 100644
11355 --- a/arch/x86/include/asm/smp.h
11356 +++ b/arch/x86/include/asm/smp.h
11357 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
11358 /* cpus sharing the last level cache: */
11359 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
11360 DECLARE_PER_CPU(u16, cpu_llc_id);
11361 -DECLARE_PER_CPU(int, cpu_number);
11362 +DECLARE_PER_CPU(unsigned int, cpu_number);
11363
11364 static inline struct cpumask *cpu_sibling_mask(int cpu)
11365 {
11366 @@ -77,7 +77,7 @@ struct smp_ops {
11367
11368 void (*send_call_func_ipi)(const struct cpumask *mask);
11369 void (*send_call_func_single_ipi)(int cpu);
11370 -};
11371 +} __no_const;
11372
11373 /* Globals due to paravirt */
11374 extern void set_cpu_sibling_map(int cpu);
11375 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
11376 extern int safe_smp_processor_id(void);
11377
11378 #elif defined(CONFIG_X86_64_SMP)
11379 -#define raw_smp_processor_id() (percpu_read(cpu_number))
11380 -
11381 -#define stack_smp_processor_id() \
11382 -({ \
11383 - struct thread_info *ti; \
11384 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
11385 - ti->cpu; \
11386 -})
11387 +#define raw_smp_processor_id() (percpu_read(cpu_number))
11388 +#define stack_smp_processor_id() raw_smp_processor_id()
11389 #define safe_smp_processor_id() smp_processor_id()
11390
11391 #endif
11392 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
11393 index 972c260..43ab1fd 100644
11394 --- a/arch/x86/include/asm/spinlock.h
11395 +++ b/arch/x86/include/asm/spinlock.h
11396 @@ -188,6 +188,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
11397 static inline void arch_read_lock(arch_rwlock_t *rw)
11398 {
11399 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
11400 +
11401 +#ifdef CONFIG_PAX_REFCOUNT
11402 + "jno 0f\n"
11403 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
11404 + "int $4\n0:\n"
11405 + _ASM_EXTABLE(0b, 0b)
11406 +#endif
11407 +
11408 "jns 1f\n"
11409 "call __read_lock_failed\n\t"
11410 "1:\n"
11411 @@ -197,6 +205,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
11412 static inline void arch_write_lock(arch_rwlock_t *rw)
11413 {
11414 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
11415 +
11416 +#ifdef CONFIG_PAX_REFCOUNT
11417 + "jno 0f\n"
11418 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
11419 + "int $4\n0:\n"
11420 + _ASM_EXTABLE(0b, 0b)
11421 +#endif
11422 +
11423 "jz 1f\n"
11424 "call __write_lock_failed\n\t"
11425 "1:\n"
11426 @@ -226,13 +242,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
11427
11428 static inline void arch_read_unlock(arch_rwlock_t *rw)
11429 {
11430 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
11431 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
11432 +
11433 +#ifdef CONFIG_PAX_REFCOUNT
11434 + "jno 0f\n"
11435 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
11436 + "int $4\n0:\n"
11437 + _ASM_EXTABLE(0b, 0b)
11438 +#endif
11439 +
11440 :"+m" (rw->lock) : : "memory");
11441 }
11442
11443 static inline void arch_write_unlock(arch_rwlock_t *rw)
11444 {
11445 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
11446 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
11447 +
11448 +#ifdef CONFIG_PAX_REFCOUNT
11449 + "jno 0f\n"
11450 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
11451 + "int $4\n0:\n"
11452 + _ASM_EXTABLE(0b, 0b)
11453 +#endif
11454 +
11455 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
11456 }
11457
11458 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
11459 index 1575177..cb23f52 100644
11460 --- a/arch/x86/include/asm/stackprotector.h
11461 +++ b/arch/x86/include/asm/stackprotector.h
11462 @@ -48,7 +48,7 @@
11463 * head_32 for boot CPU and setup_per_cpu_areas() for others.
11464 */
11465 #define GDT_STACK_CANARY_INIT \
11466 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
11467 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
11468
11469 /*
11470 * Initialize the stackprotector canary value.
11471 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
11472
11473 static inline void load_stack_canary_segment(void)
11474 {
11475 -#ifdef CONFIG_X86_32
11476 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
11477 asm volatile ("mov %0, %%gs" : : "r" (0));
11478 #endif
11479 }
11480 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
11481 index 70bbe39..4ae2bd4 100644
11482 --- a/arch/x86/include/asm/stacktrace.h
11483 +++ b/arch/x86/include/asm/stacktrace.h
11484 @@ -11,28 +11,20 @@
11485
11486 extern int kstack_depth_to_print;
11487
11488 -struct thread_info;
11489 +struct task_struct;
11490 struct stacktrace_ops;
11491
11492 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
11493 - unsigned long *stack,
11494 - unsigned long bp,
11495 - const struct stacktrace_ops *ops,
11496 - void *data,
11497 - unsigned long *end,
11498 - int *graph);
11499 +typedef unsigned long walk_stack_t(struct task_struct *task,
11500 + void *stack_start,
11501 + unsigned long *stack,
11502 + unsigned long bp,
11503 + const struct stacktrace_ops *ops,
11504 + void *data,
11505 + unsigned long *end,
11506 + int *graph);
11507
11508 -extern unsigned long
11509 -print_context_stack(struct thread_info *tinfo,
11510 - unsigned long *stack, unsigned long bp,
11511 - const struct stacktrace_ops *ops, void *data,
11512 - unsigned long *end, int *graph);
11513 -
11514 -extern unsigned long
11515 -print_context_stack_bp(struct thread_info *tinfo,
11516 - unsigned long *stack, unsigned long bp,
11517 - const struct stacktrace_ops *ops, void *data,
11518 - unsigned long *end, int *graph);
11519 +extern walk_stack_t print_context_stack;
11520 +extern walk_stack_t print_context_stack_bp;
11521
11522 /* Generic stack tracer with callbacks */
11523
11524 @@ -40,7 +32,7 @@ struct stacktrace_ops {
11525 void (*address)(void *data, unsigned long address, int reliable);
11526 /* On negative return stop dumping */
11527 int (*stack)(void *data, char *name);
11528 - walk_stack_t walk_stack;
11529 + walk_stack_t *walk_stack;
11530 };
11531
11532 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
11533 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
11534 index cb23852..2dde194 100644
11535 --- a/arch/x86/include/asm/sys_ia32.h
11536 +++ b/arch/x86/include/asm/sys_ia32.h
11537 @@ -40,7 +40,7 @@ asmlinkage long sys32_rt_sigprocmask(int, compat_sigset_t __user *,
11538 compat_sigset_t __user *, unsigned int);
11539 asmlinkage long sys32_alarm(unsigned int);
11540
11541 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
11542 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
11543 asmlinkage long sys32_sysfs(int, u32, u32);
11544
11545 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
11546 diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
11547 index 2d2f01c..f985723 100644
11548 --- a/arch/x86/include/asm/system.h
11549 +++ b/arch/x86/include/asm/system.h
11550 @@ -129,7 +129,7 @@ do { \
11551 "call __switch_to\n\t" \
11552 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
11553 __switch_canary \
11554 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
11555 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
11556 "movq %%rax,%%rdi\n\t" \
11557 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
11558 "jnz ret_from_fork\n\t" \
11559 @@ -140,7 +140,7 @@ do { \
11560 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
11561 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
11562 [_tif_fork] "i" (_TIF_FORK), \
11563 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
11564 + [thread_info] "m" (current_tinfo), \
11565 [current_task] "m" (current_task) \
11566 __switch_canary_iparam \
11567 : "memory", "cc" __EXTRA_CLOBBER)
11568 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
11569 {
11570 unsigned long __limit;
11571 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
11572 - return __limit + 1;
11573 + return __limit;
11574 }
11575
11576 static inline void native_clts(void)
11577 @@ -397,13 +397,13 @@ void enable_hlt(void);
11578
11579 void cpu_idle_wait(void);
11580
11581 -extern unsigned long arch_align_stack(unsigned long sp);
11582 +#define arch_align_stack(x) ((x) & ~0xfUL)
11583 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11584
11585 void default_idle(void);
11586 bool set_pm_idle_to_default(void);
11587
11588 -void stop_this_cpu(void *dummy);
11589 +void stop_this_cpu(void *dummy) __noreturn;
11590
11591 /*
11592 * Force strict CPU ordering.
11593 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
11594 index d7ef849..6af292e 100644
11595 --- a/arch/x86/include/asm/thread_info.h
11596 +++ b/arch/x86/include/asm/thread_info.h
11597 @@ -10,6 +10,7 @@
11598 #include <linux/compiler.h>
11599 #include <asm/page.h>
11600 #include <asm/types.h>
11601 +#include <asm/percpu.h>
11602
11603 /*
11604 * low level task data that entry.S needs immediate access to
11605 @@ -24,7 +25,6 @@ struct exec_domain;
11606 #include <linux/atomic.h>
11607
11608 struct thread_info {
11609 - struct task_struct *task; /* main task structure */
11610 struct exec_domain *exec_domain; /* execution domain */
11611 __u32 flags; /* low level flags */
11612 __u32 status; /* thread synchronous flags */
11613 @@ -34,18 +34,12 @@ struct thread_info {
11614 mm_segment_t addr_limit;
11615 struct restart_block restart_block;
11616 void __user *sysenter_return;
11617 -#ifdef CONFIG_X86_32
11618 - unsigned long previous_esp; /* ESP of the previous stack in
11619 - case of nested (IRQ) stacks
11620 - */
11621 - __u8 supervisor_stack[0];
11622 -#endif
11623 + unsigned long lowest_stack;
11624 int uaccess_err;
11625 };
11626
11627 -#define INIT_THREAD_INFO(tsk) \
11628 +#define INIT_THREAD_INFO \
11629 { \
11630 - .task = &tsk, \
11631 .exec_domain = &default_exec_domain, \
11632 .flags = 0, \
11633 .cpu = 0, \
11634 @@ -56,7 +50,7 @@ struct thread_info {
11635 }, \
11636 }
11637
11638 -#define init_thread_info (init_thread_union.thread_info)
11639 +#define init_thread_info (init_thread_union.stack)
11640 #define init_stack (init_thread_union.stack)
11641
11642 #else /* !__ASSEMBLY__ */
11643 @@ -170,45 +164,40 @@ struct thread_info {
11644 ret; \
11645 })
11646
11647 -#ifdef CONFIG_X86_32
11648 -
11649 -#define STACK_WARN (THREAD_SIZE/8)
11650 -/*
11651 - * macros/functions for gaining access to the thread information structure
11652 - *
11653 - * preempt_count needs to be 1 initially, until the scheduler is functional.
11654 - */
11655 -#ifndef __ASSEMBLY__
11656 -
11657 -
11658 -/* how to get the current stack pointer from C */
11659 -register unsigned long current_stack_pointer asm("esp") __used;
11660 -
11661 -/* how to get the thread information struct from C */
11662 -static inline struct thread_info *current_thread_info(void)
11663 -{
11664 - return (struct thread_info *)
11665 - (current_stack_pointer & ~(THREAD_SIZE - 1));
11666 -}
11667 -
11668 -#else /* !__ASSEMBLY__ */
11669 -
11670 +#ifdef __ASSEMBLY__
11671 /* how to get the thread information struct from ASM */
11672 #define GET_THREAD_INFO(reg) \
11673 - movl $-THREAD_SIZE, reg; \
11674 - andl %esp, reg
11675 + mov PER_CPU_VAR(current_tinfo), reg
11676
11677 /* use this one if reg already contains %esp */
11678 -#define GET_THREAD_INFO_WITH_ESP(reg) \
11679 - andl $-THREAD_SIZE, reg
11680 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
11681 +#else
11682 +/* how to get the thread information struct from C */
11683 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
11684 +
11685 +static __always_inline struct thread_info *current_thread_info(void)
11686 +{
11687 + return percpu_read_stable(current_tinfo);
11688 +}
11689 +#endif
11690 +
11691 +#ifdef CONFIG_X86_32
11692 +
11693 +#define STACK_WARN (THREAD_SIZE/8)
11694 +/*
11695 + * macros/functions for gaining access to the thread information structure
11696 + *
11697 + * preempt_count needs to be 1 initially, until the scheduler is functional.
11698 + */
11699 +#ifndef __ASSEMBLY__
11700 +
11701 +/* how to get the current stack pointer from C */
11702 +register unsigned long current_stack_pointer asm("esp") __used;
11703
11704 #endif
11705
11706 #else /* X86_32 */
11707
11708 -#include <asm/percpu.h>
11709 -#define KERNEL_STACK_OFFSET (5*8)
11710 -
11711 /*
11712 * macros/functions for gaining access to the thread information structure
11713 * preempt_count needs to be 1 initially, until the scheduler is functional.
11714 @@ -216,21 +205,8 @@ static inline struct thread_info *current_thread_info(void)
11715 #ifndef __ASSEMBLY__
11716 DECLARE_PER_CPU(unsigned long, kernel_stack);
11717
11718 -static inline struct thread_info *current_thread_info(void)
11719 -{
11720 - struct thread_info *ti;
11721 - ti = (void *)(percpu_read_stable(kernel_stack) +
11722 - KERNEL_STACK_OFFSET - THREAD_SIZE);
11723 - return ti;
11724 -}
11725 -
11726 -#else /* !__ASSEMBLY__ */
11727 -
11728 -/* how to get the thread information struct from ASM */
11729 -#define GET_THREAD_INFO(reg) \
11730 - movq PER_CPU_VAR(kernel_stack),reg ; \
11731 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
11732 -
11733 +/* how to get the current stack pointer from C */
11734 +register unsigned long current_stack_pointer asm("rsp") __used;
11735 #endif
11736
11737 #endif /* !X86_32 */
11738 @@ -264,5 +240,16 @@ extern void arch_task_cache_init(void);
11739 extern void free_thread_info(struct thread_info *ti);
11740 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
11741 #define arch_task_cache_init arch_task_cache_init
11742 +
11743 +#define __HAVE_THREAD_FUNCTIONS
11744 +#define task_thread_info(task) (&(task)->tinfo)
11745 +#define task_stack_page(task) ((task)->stack)
11746 +#define setup_thread_stack(p, org) do {} while (0)
11747 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
11748 +
11749 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
11750 +extern struct task_struct *alloc_task_struct_node(int node);
11751 +extern void free_task_struct(struct task_struct *);
11752 +
11753 #endif
11754 #endif /* _ASM_X86_THREAD_INFO_H */
11755 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
11756 index 36361bf..324f262 100644
11757 --- a/arch/x86/include/asm/uaccess.h
11758 +++ b/arch/x86/include/asm/uaccess.h
11759 @@ -7,12 +7,15 @@
11760 #include <linux/compiler.h>
11761 #include <linux/thread_info.h>
11762 #include <linux/string.h>
11763 +#include <linux/sched.h>
11764 #include <asm/asm.h>
11765 #include <asm/page.h>
11766
11767 #define VERIFY_READ 0
11768 #define VERIFY_WRITE 1
11769
11770 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
11771 +
11772 /*
11773 * The fs value determines whether argument validity checking should be
11774 * performed or not. If get_fs() == USER_DS, checking is performed, with
11775 @@ -28,7 +31,12 @@
11776
11777 #define get_ds() (KERNEL_DS)
11778 #define get_fs() (current_thread_info()->addr_limit)
11779 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
11780 +void __set_fs(mm_segment_t x);
11781 +void set_fs(mm_segment_t x);
11782 +#else
11783 #define set_fs(x) (current_thread_info()->addr_limit = (x))
11784 +#endif
11785
11786 #define segment_eq(a, b) ((a).seg == (b).seg)
11787
11788 @@ -76,7 +84,33 @@
11789 * checks that the pointer is in the user space range - after calling
11790 * this function, memory access functions may still return -EFAULT.
11791 */
11792 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
11793 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
11794 +#define access_ok(type, addr, size) \
11795 +({ \
11796 + long __size = size; \
11797 + unsigned long __addr = (unsigned long)addr; \
11798 + unsigned long __addr_ao = __addr & PAGE_MASK; \
11799 + unsigned long __end_ao = __addr + __size - 1; \
11800 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
11801 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
11802 + while(__addr_ao <= __end_ao) { \
11803 + char __c_ao; \
11804 + __addr_ao += PAGE_SIZE; \
11805 + if (__size > PAGE_SIZE) \
11806 + cond_resched(); \
11807 + if (__get_user(__c_ao, (char __user *)__addr)) \
11808 + break; \
11809 + if (type != VERIFY_WRITE) { \
11810 + __addr = __addr_ao; \
11811 + continue; \
11812 + } \
11813 + if (__put_user(__c_ao, (char __user *)__addr)) \
11814 + break; \
11815 + __addr = __addr_ao; \
11816 + } \
11817 + } \
11818 + __ret_ao; \
11819 +})
11820
11821 /*
11822 * The exception table consists of pairs of addresses: the first is the
11823 @@ -182,12 +216,20 @@ extern int __get_user_bad(void);
11824 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
11825 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
11826
11827 -
11828 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
11829 +#define __copyuser_seg "gs;"
11830 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
11831 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
11832 +#else
11833 +#define __copyuser_seg
11834 +#define __COPYUSER_SET_ES
11835 +#define __COPYUSER_RESTORE_ES
11836 +#endif
11837
11838 #ifdef CONFIG_X86_32
11839 #define __put_user_asm_u64(x, addr, err, errret) \
11840 - asm volatile("1: movl %%eax,0(%2)\n" \
11841 - "2: movl %%edx,4(%2)\n" \
11842 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
11843 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
11844 "3:\n" \
11845 ".section .fixup,\"ax\"\n" \
11846 "4: movl %3,%0\n" \
11847 @@ -199,8 +241,8 @@ extern int __get_user_bad(void);
11848 : "A" (x), "r" (addr), "i" (errret), "0" (err))
11849
11850 #define __put_user_asm_ex_u64(x, addr) \
11851 - asm volatile("1: movl %%eax,0(%1)\n" \
11852 - "2: movl %%edx,4(%1)\n" \
11853 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
11854 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
11855 "3:\n" \
11856 _ASM_EXTABLE(1b, 2b - 1b) \
11857 _ASM_EXTABLE(2b, 3b - 2b) \
11858 @@ -252,7 +294,7 @@ extern void __put_user_8(void);
11859 __typeof__(*(ptr)) __pu_val; \
11860 __chk_user_ptr(ptr); \
11861 might_fault(); \
11862 - __pu_val = x; \
11863 + __pu_val = (x); \
11864 switch (sizeof(*(ptr))) { \
11865 case 1: \
11866 __put_user_x(1, __pu_val, ptr, __ret_pu); \
11867 @@ -373,7 +415,7 @@ do { \
11868 } while (0)
11869
11870 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
11871 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
11872 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
11873 "2:\n" \
11874 ".section .fixup,\"ax\"\n" \
11875 "3: mov %3,%0\n" \
11876 @@ -381,7 +423,7 @@ do { \
11877 " jmp 2b\n" \
11878 ".previous\n" \
11879 _ASM_EXTABLE(1b, 3b) \
11880 - : "=r" (err), ltype(x) \
11881 + : "=r" (err), ltype (x) \
11882 : "m" (__m(addr)), "i" (errret), "0" (err))
11883
11884 #define __get_user_size_ex(x, ptr, size) \
11885 @@ -406,7 +448,7 @@ do { \
11886 } while (0)
11887
11888 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
11889 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
11890 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
11891 "2:\n" \
11892 _ASM_EXTABLE(1b, 2b - 1b) \
11893 : ltype(x) : "m" (__m(addr)))
11894 @@ -423,13 +465,24 @@ do { \
11895 int __gu_err; \
11896 unsigned long __gu_val; \
11897 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
11898 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
11899 + (x) = (__typeof__(*(ptr)))__gu_val; \
11900 __gu_err; \
11901 })
11902
11903 /* FIXME: this hack is definitely wrong -AK */
11904 struct __large_struct { unsigned long buf[100]; };
11905 -#define __m(x) (*(struct __large_struct __user *)(x))
11906 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11907 +#define ____m(x) \
11908 +({ \
11909 + unsigned long ____x = (unsigned long)(x); \
11910 + if (____x < PAX_USER_SHADOW_BASE) \
11911 + ____x += PAX_USER_SHADOW_BASE; \
11912 + (void __user *)____x; \
11913 +})
11914 +#else
11915 +#define ____m(x) (x)
11916 +#endif
11917 +#define __m(x) (*(struct __large_struct __user *)____m(x))
11918
11919 /*
11920 * Tell gcc we read from memory instead of writing: this is because
11921 @@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
11922 * aliasing issues.
11923 */
11924 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
11925 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
11926 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
11927 "2:\n" \
11928 ".section .fixup,\"ax\"\n" \
11929 "3: mov %3,%0\n" \
11930 @@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
11931 ".previous\n" \
11932 _ASM_EXTABLE(1b, 3b) \
11933 : "=r"(err) \
11934 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
11935 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
11936
11937 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
11938 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
11939 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
11940 "2:\n" \
11941 _ASM_EXTABLE(1b, 2b - 1b) \
11942 : : ltype(x), "m" (__m(addr)))
11943 @@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
11944 * On error, the variable @x is set to zero.
11945 */
11946
11947 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11948 +#define __get_user(x, ptr) get_user((x), (ptr))
11949 +#else
11950 #define __get_user(x, ptr) \
11951 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
11952 +#endif
11953
11954 /**
11955 * __put_user: - Write a simple value into user space, with less checking.
11956 @@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
11957 * Returns zero on success, or -EFAULT on error.
11958 */
11959
11960 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11961 +#define __put_user(x, ptr) put_user((x), (ptr))
11962 +#else
11963 #define __put_user(x, ptr) \
11964 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
11965 +#endif
11966
11967 #define __get_user_unaligned __get_user
11968 #define __put_user_unaligned __put_user
11969 @@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
11970 #define get_user_ex(x, ptr) do { \
11971 unsigned long __gue_val; \
11972 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
11973 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
11974 + (x) = (__typeof__(*(ptr)))__gue_val; \
11975 } while (0)
11976
11977 #ifdef CONFIG_X86_WP_WORKS_OK
11978 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
11979 index 566e803..b9521e9 100644
11980 --- a/arch/x86/include/asm/uaccess_32.h
11981 +++ b/arch/x86/include/asm/uaccess_32.h
11982 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
11983 static __always_inline unsigned long __must_check
11984 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
11985 {
11986 + if ((long)n < 0)
11987 + return n;
11988 +
11989 if (__builtin_constant_p(n)) {
11990 unsigned long ret;
11991
11992 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
11993 return ret;
11994 }
11995 }
11996 + if (!__builtin_constant_p(n))
11997 + check_object_size(from, n, true);
11998 return __copy_to_user_ll(to, from, n);
11999 }
12000
12001 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12002 __copy_to_user(void __user *to, const void *from, unsigned long n)
12003 {
12004 might_fault();
12005 +
12006 return __copy_to_user_inatomic(to, from, n);
12007 }
12008
12009 static __always_inline unsigned long
12010 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12011 {
12012 + if ((long)n < 0)
12013 + return n;
12014 +
12015 /* Avoid zeroing the tail if the copy fails..
12016 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12017 * but as the zeroing behaviour is only significant when n is not
12018 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12019 __copy_from_user(void *to, const void __user *from, unsigned long n)
12020 {
12021 might_fault();
12022 +
12023 + if ((long)n < 0)
12024 + return n;
12025 +
12026 if (__builtin_constant_p(n)) {
12027 unsigned long ret;
12028
12029 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12030 return ret;
12031 }
12032 }
12033 + if (!__builtin_constant_p(n))
12034 + check_object_size(to, n, false);
12035 return __copy_from_user_ll(to, from, n);
12036 }
12037
12038 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12039 const void __user *from, unsigned long n)
12040 {
12041 might_fault();
12042 +
12043 + if ((long)n < 0)
12044 + return n;
12045 +
12046 if (__builtin_constant_p(n)) {
12047 unsigned long ret;
12048
12049 @@ -181,15 +200,19 @@ static __always_inline unsigned long
12050 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12051 unsigned long n)
12052 {
12053 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12054 + if ((long)n < 0)
12055 + return n;
12056 +
12057 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12058 }
12059
12060 -unsigned long __must_check copy_to_user(void __user *to,
12061 - const void *from, unsigned long n);
12062 -unsigned long __must_check _copy_from_user(void *to,
12063 - const void __user *from,
12064 - unsigned long n);
12065 -
12066 +extern void copy_to_user_overflow(void)
12067 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12068 + __compiletime_error("copy_to_user() buffer size is not provably correct")
12069 +#else
12070 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
12071 +#endif
12072 +;
12073
12074 extern void copy_from_user_overflow(void)
12075 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12076 @@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
12077 #endif
12078 ;
12079
12080 -static inline unsigned long __must_check copy_from_user(void *to,
12081 - const void __user *from,
12082 - unsigned long n)
12083 +/**
12084 + * copy_to_user: - Copy a block of data into user space.
12085 + * @to: Destination address, in user space.
12086 + * @from: Source address, in kernel space.
12087 + * @n: Number of bytes to copy.
12088 + *
12089 + * Context: User context only. This function may sleep.
12090 + *
12091 + * Copy data from kernel space to user space.
12092 + *
12093 + * Returns number of bytes that could not be copied.
12094 + * On success, this will be zero.
12095 + */
12096 +static inline unsigned long __must_check
12097 +copy_to_user(void __user *to, const void *from, unsigned long n)
12098 +{
12099 + int sz = __compiletime_object_size(from);
12100 +
12101 + if (unlikely(sz != -1 && sz < n))
12102 + copy_to_user_overflow();
12103 + else if (access_ok(VERIFY_WRITE, to, n))
12104 + n = __copy_to_user(to, from, n);
12105 + return n;
12106 +}
12107 +
12108 +/**
12109 + * copy_from_user: - Copy a block of data from user space.
12110 + * @to: Destination address, in kernel space.
12111 + * @from: Source address, in user space.
12112 + * @n: Number of bytes to copy.
12113 + *
12114 + * Context: User context only. This function may sleep.
12115 + *
12116 + * Copy data from user space to kernel space.
12117 + *
12118 + * Returns number of bytes that could not be copied.
12119 + * On success, this will be zero.
12120 + *
12121 + * If some data could not be copied, this function will pad the copied
12122 + * data to the requested size using zero bytes.
12123 + */
12124 +static inline unsigned long __must_check
12125 +copy_from_user(void *to, const void __user *from, unsigned long n)
12126 {
12127 int sz = __compiletime_object_size(to);
12128
12129 - if (likely(sz == -1 || sz >= n))
12130 - n = _copy_from_user(to, from, n);
12131 - else
12132 + if (unlikely(sz != -1 && sz < n))
12133 copy_from_user_overflow();
12134 -
12135 + else if (access_ok(VERIFY_READ, from, n))
12136 + n = __copy_from_user(to, from, n);
12137 + else if ((long)n > 0) {
12138 + if (!__builtin_constant_p(n))
12139 + check_object_size(to, n, false);
12140 + memset(to, 0, n);
12141 + }
12142 return n;
12143 }
12144
12145 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12146 index 1c66d30..e66922c 100644
12147 --- a/arch/x86/include/asm/uaccess_64.h
12148 +++ b/arch/x86/include/asm/uaccess_64.h
12149 @@ -10,6 +10,9 @@
12150 #include <asm/alternative.h>
12151 #include <asm/cpufeature.h>
12152 #include <asm/page.h>
12153 +#include <asm/pgtable.h>
12154 +
12155 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
12156
12157 /*
12158 * Copy To/From Userspace
12159 @@ -17,12 +20,12 @@
12160
12161 /* Handles exceptions in both to and from, but doesn't do access_ok */
12162 __must_check unsigned long
12163 -copy_user_generic_string(void *to, const void *from, unsigned len);
12164 +copy_user_generic_string(void *to, const void *from, unsigned long len);
12165 __must_check unsigned long
12166 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
12167 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len);
12168
12169 static __always_inline __must_check unsigned long
12170 -copy_user_generic(void *to, const void *from, unsigned len)
12171 +copy_user_generic(void *to, const void *from, unsigned long len)
12172 {
12173 unsigned ret;
12174
12175 @@ -32,142 +35,226 @@ copy_user_generic(void *to, const void *from, unsigned len)
12176 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
12177 "=d" (len)),
12178 "1" (to), "2" (from), "3" (len)
12179 - : "memory", "rcx", "r8", "r9", "r10", "r11");
12180 + : "memory", "rcx", "r8", "r9", "r11");
12181 return ret;
12182 }
12183
12184 +static __always_inline __must_check unsigned long
12185 +__copy_to_user(void __user *to, const void *from, unsigned long len);
12186 +static __always_inline __must_check unsigned long
12187 +__copy_from_user(void *to, const void __user *from, unsigned long len);
12188 __must_check unsigned long
12189 -_copy_to_user(void __user *to, const void *from, unsigned len);
12190 -__must_check unsigned long
12191 -_copy_from_user(void *to, const void __user *from, unsigned len);
12192 -__must_check unsigned long
12193 -copy_in_user(void __user *to, const void __user *from, unsigned len);
12194 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
12195
12196 static inline unsigned long __must_check copy_from_user(void *to,
12197 const void __user *from,
12198 unsigned long n)
12199 {
12200 - int sz = __compiletime_object_size(to);
12201 -
12202 might_fault();
12203 - if (likely(sz == -1 || sz >= n))
12204 - n = _copy_from_user(to, from, n);
12205 -#ifdef CONFIG_DEBUG_VM
12206 - else
12207 - WARN(1, "Buffer overflow detected!\n");
12208 -#endif
12209 +
12210 + if (access_ok(VERIFY_READ, from, n))
12211 + n = __copy_from_user(to, from, n);
12212 + else if (n < INT_MAX) {
12213 + if (!__builtin_constant_p(n))
12214 + check_object_size(to, n, false);
12215 + memset(to, 0, n);
12216 + }
12217 return n;
12218 }
12219
12220 static __always_inline __must_check
12221 -int copy_to_user(void __user *dst, const void *src, unsigned size)
12222 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
12223 {
12224 might_fault();
12225
12226 - return _copy_to_user(dst, src, size);
12227 + if (access_ok(VERIFY_WRITE, dst, size))
12228 + size = __copy_to_user(dst, src, size);
12229 + return size;
12230 }
12231
12232 static __always_inline __must_check
12233 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
12234 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
12235 {
12236 - int ret = 0;
12237 + int sz = __compiletime_object_size(dst);
12238 + unsigned ret = 0;
12239
12240 might_fault();
12241 - if (!__builtin_constant_p(size))
12242 - return copy_user_generic(dst, (__force void *)src, size);
12243 +
12244 + if (size > INT_MAX)
12245 + return size;
12246 +
12247 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12248 + if (!__access_ok(VERIFY_READ, src, size))
12249 + return size;
12250 +#endif
12251 +
12252 + if (unlikely(sz != -1 && sz < size)) {
12253 +#ifdef CONFIG_DEBUG_VM
12254 + WARN(1, "Buffer overflow detected!\n");
12255 +#endif
12256 + return size;
12257 + }
12258 +
12259 + if (!__builtin_constant_p(size)) {
12260 + check_object_size(dst, size, false);
12261 +
12262 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12263 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12264 + src += PAX_USER_SHADOW_BASE;
12265 +#endif
12266 +
12267 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12268 + }
12269 switch (size) {
12270 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
12271 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
12272 ret, "b", "b", "=q", 1);
12273 return ret;
12274 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
12275 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
12276 ret, "w", "w", "=r", 2);
12277 return ret;
12278 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
12279 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
12280 ret, "l", "k", "=r", 4);
12281 return ret;
12282 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
12283 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12284 ret, "q", "", "=r", 8);
12285 return ret;
12286 case 10:
12287 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12288 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12289 ret, "q", "", "=r", 10);
12290 if (unlikely(ret))
12291 return ret;
12292 __get_user_asm(*(u16 *)(8 + (char *)dst),
12293 - (u16 __user *)(8 + (char __user *)src),
12294 + (const u16 __user *)(8 + (const char __user *)src),
12295 ret, "w", "w", "=r", 2);
12296 return ret;
12297 case 16:
12298 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12299 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12300 ret, "q", "", "=r", 16);
12301 if (unlikely(ret))
12302 return ret;
12303 __get_user_asm(*(u64 *)(8 + (char *)dst),
12304 - (u64 __user *)(8 + (char __user *)src),
12305 + (const u64 __user *)(8 + (const char __user *)src),
12306 ret, "q", "", "=r", 8);
12307 return ret;
12308 default:
12309 - return copy_user_generic(dst, (__force void *)src, size);
12310 +
12311 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12312 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12313 + src += PAX_USER_SHADOW_BASE;
12314 +#endif
12315 +
12316 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12317 }
12318 }
12319
12320 static __always_inline __must_check
12321 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
12322 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
12323 {
12324 - int ret = 0;
12325 + int sz = __compiletime_object_size(src);
12326 + unsigned ret = 0;
12327
12328 might_fault();
12329 - if (!__builtin_constant_p(size))
12330 - return copy_user_generic((__force void *)dst, src, size);
12331 +
12332 + if (size > INT_MAX)
12333 + return size;
12334 +
12335 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12336 + if (!__access_ok(VERIFY_WRITE, dst, size))
12337 + return size;
12338 +#endif
12339 +
12340 + if (unlikely(sz != -1 && sz < size)) {
12341 +#ifdef CONFIG_DEBUG_VM
12342 + WARN(1, "Buffer overflow detected!\n");
12343 +#endif
12344 + return size;
12345 + }
12346 +
12347 + if (!__builtin_constant_p(size)) {
12348 + check_object_size(src, size, true);
12349 +
12350 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12351 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12352 + dst += PAX_USER_SHADOW_BASE;
12353 +#endif
12354 +
12355 + return copy_user_generic((__force_kernel void *)dst, src, size);
12356 + }
12357 switch (size) {
12358 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
12359 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
12360 ret, "b", "b", "iq", 1);
12361 return ret;
12362 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
12363 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
12364 ret, "w", "w", "ir", 2);
12365 return ret;
12366 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
12367 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
12368 ret, "l", "k", "ir", 4);
12369 return ret;
12370 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
12371 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12372 ret, "q", "", "er", 8);
12373 return ret;
12374 case 10:
12375 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12376 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12377 ret, "q", "", "er", 10);
12378 if (unlikely(ret))
12379 return ret;
12380 asm("":::"memory");
12381 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
12382 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
12383 ret, "w", "w", "ir", 2);
12384 return ret;
12385 case 16:
12386 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12387 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12388 ret, "q", "", "er", 16);
12389 if (unlikely(ret))
12390 return ret;
12391 asm("":::"memory");
12392 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
12393 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
12394 ret, "q", "", "er", 8);
12395 return ret;
12396 default:
12397 - return copy_user_generic((__force void *)dst, src, size);
12398 +
12399 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12400 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12401 + dst += PAX_USER_SHADOW_BASE;
12402 +#endif
12403 +
12404 + return copy_user_generic((__force_kernel void *)dst, src, size);
12405 }
12406 }
12407
12408 static __always_inline __must_check
12409 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12410 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
12411 {
12412 - int ret = 0;
12413 + unsigned ret = 0;
12414
12415 might_fault();
12416 - if (!__builtin_constant_p(size))
12417 - return copy_user_generic((__force void *)dst,
12418 - (__force void *)src, size);
12419 +
12420 + if (size > INT_MAX)
12421 + return size;
12422 +
12423 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12424 + if (!__access_ok(VERIFY_READ, src, size))
12425 + return size;
12426 + if (!__access_ok(VERIFY_WRITE, dst, size))
12427 + return size;
12428 +#endif
12429 +
12430 + if (!__builtin_constant_p(size)) {
12431 +
12432 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12433 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12434 + src += PAX_USER_SHADOW_BASE;
12435 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12436 + dst += PAX_USER_SHADOW_BASE;
12437 +#endif
12438 +
12439 + return copy_user_generic((__force_kernel void *)dst,
12440 + (__force_kernel const void *)src, size);
12441 + }
12442 switch (size) {
12443 case 1: {
12444 u8 tmp;
12445 - __get_user_asm(tmp, (u8 __user *)src,
12446 + __get_user_asm(tmp, (const u8 __user *)src,
12447 ret, "b", "b", "=q", 1);
12448 if (likely(!ret))
12449 __put_user_asm(tmp, (u8 __user *)dst,
12450 @@ -176,7 +263,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12451 }
12452 case 2: {
12453 u16 tmp;
12454 - __get_user_asm(tmp, (u16 __user *)src,
12455 + __get_user_asm(tmp, (const u16 __user *)src,
12456 ret, "w", "w", "=r", 2);
12457 if (likely(!ret))
12458 __put_user_asm(tmp, (u16 __user *)dst,
12459 @@ -186,7 +273,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12460
12461 case 4: {
12462 u32 tmp;
12463 - __get_user_asm(tmp, (u32 __user *)src,
12464 + __get_user_asm(tmp, (const u32 __user *)src,
12465 ret, "l", "k", "=r", 4);
12466 if (likely(!ret))
12467 __put_user_asm(tmp, (u32 __user *)dst,
12468 @@ -195,7 +282,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12469 }
12470 case 8: {
12471 u64 tmp;
12472 - __get_user_asm(tmp, (u64 __user *)src,
12473 + __get_user_asm(tmp, (const u64 __user *)src,
12474 ret, "q", "", "=r", 8);
12475 if (likely(!ret))
12476 __put_user_asm(tmp, (u64 __user *)dst,
12477 @@ -203,8 +290,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12478 return ret;
12479 }
12480 default:
12481 - return copy_user_generic((__force void *)dst,
12482 - (__force void *)src, size);
12483 +
12484 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12485 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12486 + src += PAX_USER_SHADOW_BASE;
12487 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12488 + dst += PAX_USER_SHADOW_BASE;
12489 +#endif
12490 +
12491 + return copy_user_generic((__force_kernel void *)dst,
12492 + (__force_kernel const void *)src, size);
12493 }
12494 }
12495
12496 @@ -219,35 +314,72 @@ __must_check unsigned long clear_user(void __user *mem, unsigned long len);
12497 __must_check unsigned long __clear_user(void __user *mem, unsigned long len);
12498
12499 static __must_check __always_inline int
12500 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
12501 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
12502 {
12503 - return copy_user_generic(dst, (__force const void *)src, size);
12504 + if (size > INT_MAX)
12505 + return size;
12506 +
12507 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12508 + if (!__access_ok(VERIFY_READ, src, size))
12509 + return size;
12510 +
12511 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12512 + src += PAX_USER_SHADOW_BASE;
12513 +#endif
12514 +
12515 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
12516 }
12517
12518 -static __must_check __always_inline int
12519 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
12520 +static __must_check __always_inline unsigned long
12521 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
12522 {
12523 - return copy_user_generic((__force void *)dst, src, size);
12524 + if (size > INT_MAX)
12525 + return size;
12526 +
12527 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12528 + if (!__access_ok(VERIFY_WRITE, dst, size))
12529 + return size;
12530 +
12531 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12532 + dst += PAX_USER_SHADOW_BASE;
12533 +#endif
12534 +
12535 + return copy_user_generic((__force_kernel void *)dst, src, size);
12536 }
12537
12538 -extern long __copy_user_nocache(void *dst, const void __user *src,
12539 - unsigned size, int zerorest);
12540 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
12541 + unsigned long size, int zerorest);
12542
12543 -static inline int
12544 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12545 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
12546 {
12547 might_sleep();
12548 +
12549 + if (size > INT_MAX)
12550 + return size;
12551 +
12552 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12553 + if (!__access_ok(VERIFY_READ, src, size))
12554 + return size;
12555 +#endif
12556 +
12557 return __copy_user_nocache(dst, src, size, 1);
12558 }
12559
12560 -static inline int
12561 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12562 - unsigned size)
12563 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12564 + unsigned long size)
12565 {
12566 + if (size > INT_MAX)
12567 + return size;
12568 +
12569 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12570 + if (!__access_ok(VERIFY_READ, src, size))
12571 + return size;
12572 +#endif
12573 +
12574 return __copy_user_nocache(dst, src, size, 0);
12575 }
12576
12577 -unsigned long
12578 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
12579 +extern unsigned long
12580 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest);
12581
12582 #endif /* _ASM_X86_UACCESS_64_H */
12583 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
12584 index bb05228..d763d5b 100644
12585 --- a/arch/x86/include/asm/vdso.h
12586 +++ b/arch/x86/include/asm/vdso.h
12587 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
12588 #define VDSO32_SYMBOL(base, name) \
12589 ({ \
12590 extern const char VDSO32_##name[]; \
12591 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
12592 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
12593 })
12594 #endif
12595
12596 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
12597 index 1971e65..1e3559b 100644
12598 --- a/arch/x86/include/asm/x86_init.h
12599 +++ b/arch/x86/include/asm/x86_init.h
12600 @@ -28,7 +28,7 @@ struct x86_init_mpparse {
12601 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
12602 void (*find_smp_config)(void);
12603 void (*get_smp_config)(unsigned int early);
12604 -};
12605 +} __no_const;
12606
12607 /**
12608 * struct x86_init_resources - platform specific resource related ops
12609 @@ -42,7 +42,7 @@ struct x86_init_resources {
12610 void (*probe_roms)(void);
12611 void (*reserve_resources)(void);
12612 char *(*memory_setup)(void);
12613 -};
12614 +} __no_const;
12615
12616 /**
12617 * struct x86_init_irqs - platform specific interrupt setup
12618 @@ -55,7 +55,7 @@ struct x86_init_irqs {
12619 void (*pre_vector_init)(void);
12620 void (*intr_init)(void);
12621 void (*trap_init)(void);
12622 -};
12623 +} __no_const;
12624
12625 /**
12626 * struct x86_init_oem - oem platform specific customizing functions
12627 @@ -65,7 +65,7 @@ struct x86_init_irqs {
12628 struct x86_init_oem {
12629 void (*arch_setup)(void);
12630 void (*banner)(void);
12631 -};
12632 +} __no_const;
12633
12634 /**
12635 * struct x86_init_mapping - platform specific initial kernel pagetable setup
12636 @@ -76,7 +76,7 @@ struct x86_init_oem {
12637 */
12638 struct x86_init_mapping {
12639 void (*pagetable_reserve)(u64 start, u64 end);
12640 -};
12641 +} __no_const;
12642
12643 /**
12644 * struct x86_init_paging - platform specific paging functions
12645 @@ -86,7 +86,7 @@ struct x86_init_mapping {
12646 struct x86_init_paging {
12647 void (*pagetable_setup_start)(pgd_t *base);
12648 void (*pagetable_setup_done)(pgd_t *base);
12649 -};
12650 +} __no_const;
12651
12652 /**
12653 * struct x86_init_timers - platform specific timer setup
12654 @@ -101,7 +101,7 @@ struct x86_init_timers {
12655 void (*tsc_pre_init)(void);
12656 void (*timer_init)(void);
12657 void (*wallclock_init)(void);
12658 -};
12659 +} __no_const;
12660
12661 /**
12662 * struct x86_init_iommu - platform specific iommu setup
12663 @@ -109,7 +109,7 @@ struct x86_init_timers {
12664 */
12665 struct x86_init_iommu {
12666 int (*iommu_init)(void);
12667 -};
12668 +} __no_const;
12669
12670 /**
12671 * struct x86_init_pci - platform specific pci init functions
12672 @@ -123,7 +123,7 @@ struct x86_init_pci {
12673 int (*init)(void);
12674 void (*init_irq)(void);
12675 void (*fixup_irqs)(void);
12676 -};
12677 +} __no_const;
12678
12679 /**
12680 * struct x86_init_ops - functions for platform specific setup
12681 @@ -139,7 +139,7 @@ struct x86_init_ops {
12682 struct x86_init_timers timers;
12683 struct x86_init_iommu iommu;
12684 struct x86_init_pci pci;
12685 -};
12686 +} __no_const;
12687
12688 /**
12689 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
12690 @@ -147,7 +147,7 @@ struct x86_init_ops {
12691 */
12692 struct x86_cpuinit_ops {
12693 void (*setup_percpu_clockev)(void);
12694 -};
12695 +} __no_const;
12696
12697 /**
12698 * struct x86_platform_ops - platform specific runtime functions
12699 @@ -169,7 +169,7 @@ struct x86_platform_ops {
12700 void (*nmi_init)(void);
12701 unsigned char (*get_nmi_reason)(void);
12702 int (*i8042_detect)(void);
12703 -};
12704 +} __no_const;
12705
12706 struct pci_dev;
12707
12708 @@ -177,7 +177,7 @@ struct x86_msi_ops {
12709 int (*setup_msi_irqs)(struct pci_dev *dev, int nvec, int type);
12710 void (*teardown_msi_irq)(unsigned int irq);
12711 void (*teardown_msi_irqs)(struct pci_dev *dev);
12712 -};
12713 +} __no_const;
12714
12715 extern struct x86_init_ops x86_init;
12716 extern struct x86_cpuinit_ops x86_cpuinit;
12717 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
12718 index c6ce245..ffbdab7 100644
12719 --- a/arch/x86/include/asm/xsave.h
12720 +++ b/arch/x86/include/asm/xsave.h
12721 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
12722 {
12723 int err;
12724
12725 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12726 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
12727 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
12728 +#endif
12729 +
12730 /*
12731 * Clear the xsave header first, so that reserved fields are
12732 * initialized to zero.
12733 @@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
12734 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
12735 {
12736 int err;
12737 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
12738 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
12739 u32 lmask = mask;
12740 u32 hmask = mask >> 32;
12741
12742 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12743 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
12744 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
12745 +#endif
12746 +
12747 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
12748 "2:\n"
12749 ".section .fixup,\"ax\"\n"
12750 diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
12751 index 6a564ac..9b1340c 100644
12752 --- a/arch/x86/kernel/acpi/realmode/Makefile
12753 +++ b/arch/x86/kernel/acpi/realmode/Makefile
12754 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
12755 $(call cc-option, -fno-stack-protector) \
12756 $(call cc-option, -mpreferred-stack-boundary=2)
12757 KBUILD_CFLAGS += $(call cc-option, -m32)
12758 +ifdef CONSTIFY_PLUGIN
12759 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
12760 +endif
12761 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12762 GCOV_PROFILE := n
12763
12764 diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
12765 index b4fd836..4358fe3 100644
12766 --- a/arch/x86/kernel/acpi/realmode/wakeup.S
12767 +++ b/arch/x86/kernel/acpi/realmode/wakeup.S
12768 @@ -108,6 +108,9 @@ wakeup_code:
12769 /* Do any other stuff... */
12770
12771 #ifndef CONFIG_64BIT
12772 + /* Recheck NX bit overrides (64bit path does this in trampoline */
12773 + call verify_cpu
12774 +
12775 /* This could also be done in C code... */
12776 movl pmode_cr3, %eax
12777 movl %eax, %cr3
12778 @@ -131,6 +134,7 @@ wakeup_code:
12779 movl pmode_cr0, %eax
12780 movl %eax, %cr0
12781 jmp pmode_return
12782 +# include "../../verify_cpu.S"
12783 #else
12784 pushw $0
12785 pushw trampoline_segment
12786 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
12787 index 103b6ab..2004d0a 100644
12788 --- a/arch/x86/kernel/acpi/sleep.c
12789 +++ b/arch/x86/kernel/acpi/sleep.c
12790 @@ -94,8 +94,12 @@ int acpi_suspend_lowlevel(void)
12791 header->trampoline_segment = trampoline_address() >> 4;
12792 #ifdef CONFIG_SMP
12793 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
12794 +
12795 + pax_open_kernel();
12796 early_gdt_descr.address =
12797 (unsigned long)get_cpu_gdt_table(smp_processor_id());
12798 + pax_close_kernel();
12799 +
12800 initial_gs = per_cpu_offset(smp_processor_id());
12801 #endif
12802 initial_code = (unsigned long)wakeup_long64;
12803 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
12804 index 13ab720..95d5442 100644
12805 --- a/arch/x86/kernel/acpi/wakeup_32.S
12806 +++ b/arch/x86/kernel/acpi/wakeup_32.S
12807 @@ -30,13 +30,11 @@ wakeup_pmode_return:
12808 # and restore the stack ... but you need gdt for this to work
12809 movl saved_context_esp, %esp
12810
12811 - movl %cs:saved_magic, %eax
12812 - cmpl $0x12345678, %eax
12813 + cmpl $0x12345678, saved_magic
12814 jne bogus_magic
12815
12816 # jump to place where we left off
12817 - movl saved_eip, %eax
12818 - jmp *%eax
12819 + jmp *(saved_eip)
12820
12821 bogus_magic:
12822 jmp bogus_magic
12823 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
12824 index 1f84794..e23f862 100644
12825 --- a/arch/x86/kernel/alternative.c
12826 +++ b/arch/x86/kernel/alternative.c
12827 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
12828 */
12829 for (a = start; a < end; a++) {
12830 instr = (u8 *)&a->instr_offset + a->instr_offset;
12831 +
12832 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12833 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
12834 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
12835 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
12836 +#endif
12837 +
12838 replacement = (u8 *)&a->repl_offset + a->repl_offset;
12839 BUG_ON(a->replacementlen > a->instrlen);
12840 BUG_ON(a->instrlen > sizeof(insnbuf));
12841 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
12842 for (poff = start; poff < end; poff++) {
12843 u8 *ptr = (u8 *)poff + *poff;
12844
12845 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12846 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
12847 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
12848 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
12849 +#endif
12850 +
12851 if (!*poff || ptr < text || ptr >= text_end)
12852 continue;
12853 /* turn DS segment override prefix into lock prefix */
12854 - if (*ptr == 0x3e)
12855 + if (*ktla_ktva(ptr) == 0x3e)
12856 text_poke(ptr, ((unsigned char []){0xf0}), 1);
12857 };
12858 mutex_unlock(&text_mutex);
12859 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
12860 for (poff = start; poff < end; poff++) {
12861 u8 *ptr = (u8 *)poff + *poff;
12862
12863 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12864 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
12865 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
12866 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
12867 +#endif
12868 +
12869 if (!*poff || ptr < text || ptr >= text_end)
12870 continue;
12871 /* turn lock prefix into DS segment override prefix */
12872 - if (*ptr == 0xf0)
12873 + if (*ktla_ktva(ptr) == 0xf0)
12874 text_poke(ptr, ((unsigned char []){0x3E}), 1);
12875 };
12876 mutex_unlock(&text_mutex);
12877 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
12878
12879 BUG_ON(p->len > MAX_PATCH_LEN);
12880 /* prep the buffer with the original instructions */
12881 - memcpy(insnbuf, p->instr, p->len);
12882 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
12883 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
12884 (unsigned long)p->instr, p->len);
12885
12886 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
12887 if (smp_alt_once)
12888 free_init_pages("SMP alternatives",
12889 (unsigned long)__smp_locks,
12890 - (unsigned long)__smp_locks_end);
12891 + PAGE_ALIGN((unsigned long)__smp_locks_end));
12892
12893 restart_nmi();
12894 }
12895 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
12896 * instructions. And on the local CPU you need to be protected again NMI or MCE
12897 * handlers seeing an inconsistent instruction while you patch.
12898 */
12899 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
12900 +void *__kprobes text_poke_early(void *addr, const void *opcode,
12901 size_t len)
12902 {
12903 unsigned long flags;
12904 local_irq_save(flags);
12905 - memcpy(addr, opcode, len);
12906 +
12907 + pax_open_kernel();
12908 + memcpy(ktla_ktva(addr), opcode, len);
12909 sync_core();
12910 + pax_close_kernel();
12911 +
12912 local_irq_restore(flags);
12913 /* Could also do a CLFLUSH here to speed up CPU recovery; but
12914 that causes hangs on some VIA CPUs. */
12915 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
12916 */
12917 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
12918 {
12919 - unsigned long flags;
12920 - char *vaddr;
12921 + unsigned char *vaddr = ktla_ktva(addr);
12922 struct page *pages[2];
12923 - int i;
12924 + size_t i;
12925
12926 if (!core_kernel_text((unsigned long)addr)) {
12927 - pages[0] = vmalloc_to_page(addr);
12928 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
12929 + pages[0] = vmalloc_to_page(vaddr);
12930 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
12931 } else {
12932 - pages[0] = virt_to_page(addr);
12933 + pages[0] = virt_to_page(vaddr);
12934 WARN_ON(!PageReserved(pages[0]));
12935 - pages[1] = virt_to_page(addr + PAGE_SIZE);
12936 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
12937 }
12938 BUG_ON(!pages[0]);
12939 - local_irq_save(flags);
12940 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
12941 - if (pages[1])
12942 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
12943 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
12944 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
12945 - clear_fixmap(FIX_TEXT_POKE0);
12946 - if (pages[1])
12947 - clear_fixmap(FIX_TEXT_POKE1);
12948 - local_flush_tlb();
12949 - sync_core();
12950 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
12951 - that causes hangs on some VIA CPUs. */
12952 + text_poke_early(addr, opcode, len);
12953 for (i = 0; i < len; i++)
12954 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
12955 - local_irq_restore(flags);
12956 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
12957 return addr;
12958 }
12959
12960 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
12961 index f98d84c..e402a69 100644
12962 --- a/arch/x86/kernel/apic/apic.c
12963 +++ b/arch/x86/kernel/apic/apic.c
12964 @@ -174,7 +174,7 @@ int first_system_vector = 0xfe;
12965 /*
12966 * Debug level, exported for io_apic.c
12967 */
12968 -unsigned int apic_verbosity;
12969 +int apic_verbosity;
12970
12971 int pic_mode;
12972
12973 @@ -1853,7 +1853,7 @@ void smp_error_interrupt(struct pt_regs *regs)
12974 apic_write(APIC_ESR, 0);
12975 v1 = apic_read(APIC_ESR);
12976 ack_APIC_irq();
12977 - atomic_inc(&irq_err_count);
12978 + atomic_inc_unchecked(&irq_err_count);
12979
12980 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
12981 smp_processor_id(), v0 , v1);
12982 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
12983 index 6d939d7..0697fcc 100644
12984 --- a/arch/x86/kernel/apic/io_apic.c
12985 +++ b/arch/x86/kernel/apic/io_apic.c
12986 @@ -1096,7 +1096,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
12987 }
12988 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
12989
12990 -void lock_vector_lock(void)
12991 +void lock_vector_lock(void) __acquires(vector_lock)
12992 {
12993 /* Used to the online set of cpus does not change
12994 * during assign_irq_vector.
12995 @@ -1104,7 +1104,7 @@ void lock_vector_lock(void)
12996 raw_spin_lock(&vector_lock);
12997 }
12998
12999 -void unlock_vector_lock(void)
13000 +void unlock_vector_lock(void) __releases(vector_lock)
13001 {
13002 raw_spin_unlock(&vector_lock);
13003 }
13004 @@ -2510,7 +2510,7 @@ static void ack_apic_edge(struct irq_data *data)
13005 ack_APIC_irq();
13006 }
13007
13008 -atomic_t irq_mis_count;
13009 +atomic_unchecked_t irq_mis_count;
13010
13011 static void ack_apic_level(struct irq_data *data)
13012 {
13013 @@ -2576,7 +2576,7 @@ static void ack_apic_level(struct irq_data *data)
13014 * at the cpu.
13015 */
13016 if (!(v & (1 << (i & 0x1f)))) {
13017 - atomic_inc(&irq_mis_count);
13018 + atomic_inc_unchecked(&irq_mis_count);
13019
13020 eoi_ioapic_irq(irq, cfg);
13021 }
13022 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13023 index a46bd38..6b906d7 100644
13024 --- a/arch/x86/kernel/apm_32.c
13025 +++ b/arch/x86/kernel/apm_32.c
13026 @@ -411,7 +411,7 @@ static DEFINE_MUTEX(apm_mutex);
13027 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13028 * even though they are called in protected mode.
13029 */
13030 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13031 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13032 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13033
13034 static const char driver_version[] = "1.16ac"; /* no spaces */
13035 @@ -589,7 +589,10 @@ static long __apm_bios_call(void *_call)
13036 BUG_ON(cpu != 0);
13037 gdt = get_cpu_gdt_table(cpu);
13038 save_desc_40 = gdt[0x40 / 8];
13039 +
13040 + pax_open_kernel();
13041 gdt[0x40 / 8] = bad_bios_desc;
13042 + pax_close_kernel();
13043
13044 apm_irq_save(flags);
13045 APM_DO_SAVE_SEGS;
13046 @@ -598,7 +601,11 @@ static long __apm_bios_call(void *_call)
13047 &call->esi);
13048 APM_DO_RESTORE_SEGS;
13049 apm_irq_restore(flags);
13050 +
13051 + pax_open_kernel();
13052 gdt[0x40 / 8] = save_desc_40;
13053 + pax_close_kernel();
13054 +
13055 put_cpu();
13056
13057 return call->eax & 0xff;
13058 @@ -665,7 +672,10 @@ static long __apm_bios_call_simple(void *_call)
13059 BUG_ON(cpu != 0);
13060 gdt = get_cpu_gdt_table(cpu);
13061 save_desc_40 = gdt[0x40 / 8];
13062 +
13063 + pax_open_kernel();
13064 gdt[0x40 / 8] = bad_bios_desc;
13065 + pax_close_kernel();
13066
13067 apm_irq_save(flags);
13068 APM_DO_SAVE_SEGS;
13069 @@ -673,7 +683,11 @@ static long __apm_bios_call_simple(void *_call)
13070 &call->eax);
13071 APM_DO_RESTORE_SEGS;
13072 apm_irq_restore(flags);
13073 +
13074 + pax_open_kernel();
13075 gdt[0x40 / 8] = save_desc_40;
13076 + pax_close_kernel();
13077 +
13078 put_cpu();
13079 return error;
13080 }
13081 @@ -2347,12 +2361,15 @@ static int __init apm_init(void)
13082 * code to that CPU.
13083 */
13084 gdt = get_cpu_gdt_table(0);
13085 +
13086 + pax_open_kernel();
13087 set_desc_base(&gdt[APM_CS >> 3],
13088 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13089 set_desc_base(&gdt[APM_CS_16 >> 3],
13090 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13091 set_desc_base(&gdt[APM_DS >> 3],
13092 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13093 + pax_close_kernel();
13094
13095 proc_create("apm", 0, NULL, &apm_file_ops);
13096
13097 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13098 index 4f13faf..87db5d2 100644
13099 --- a/arch/x86/kernel/asm-offsets.c
13100 +++ b/arch/x86/kernel/asm-offsets.c
13101 @@ -33,6 +33,8 @@ void common(void) {
13102 OFFSET(TI_status, thread_info, status);
13103 OFFSET(TI_addr_limit, thread_info, addr_limit);
13104 OFFSET(TI_preempt_count, thread_info, preempt_count);
13105 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13106 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13107
13108 BLANK();
13109 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
13110 @@ -53,8 +55,26 @@ void common(void) {
13111 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13112 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13113 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13114 +
13115 +#ifdef CONFIG_PAX_KERNEXEC
13116 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13117 #endif
13118
13119 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13120 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13121 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13122 +#ifdef CONFIG_X86_64
13123 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13124 +#endif
13125 +#endif
13126 +
13127 +#endif
13128 +
13129 + BLANK();
13130 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13131 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13132 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13133 +
13134 #ifdef CONFIG_XEN
13135 BLANK();
13136 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13137 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13138 index e72a119..6e2955d 100644
13139 --- a/arch/x86/kernel/asm-offsets_64.c
13140 +++ b/arch/x86/kernel/asm-offsets_64.c
13141 @@ -69,6 +69,7 @@ int main(void)
13142 BLANK();
13143 #undef ENTRY
13144
13145 + DEFINE(TSS_size, sizeof(struct tss_struct));
13146 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
13147 BLANK();
13148
13149 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
13150 index 25f24dc..4094a7f 100644
13151 --- a/arch/x86/kernel/cpu/Makefile
13152 +++ b/arch/x86/kernel/cpu/Makefile
13153 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
13154 CFLAGS_REMOVE_perf_event.o = -pg
13155 endif
13156
13157 -# Make sure load_percpu_segment has no stackprotector
13158 -nostackp := $(call cc-option, -fno-stack-protector)
13159 -CFLAGS_common.o := $(nostackp)
13160 -
13161 obj-y := intel_cacheinfo.o scattered.o topology.o
13162 obj-y += proc.o capflags.o powerflags.o common.o
13163 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
13164 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
13165 index 0bab2b1..d0a1bf8 100644
13166 --- a/arch/x86/kernel/cpu/amd.c
13167 +++ b/arch/x86/kernel/cpu/amd.c
13168 @@ -664,7 +664,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
13169 unsigned int size)
13170 {
13171 /* AMD errata T13 (order #21922) */
13172 - if ((c->x86 == 6)) {
13173 + if (c->x86 == 6) {
13174 /* Duron Rev A0 */
13175 if (c->x86_model == 3 && c->x86_mask == 0)
13176 size = 64;
13177 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
13178 index aa003b1..47ea638 100644
13179 --- a/arch/x86/kernel/cpu/common.c
13180 +++ b/arch/x86/kernel/cpu/common.c
13181 @@ -84,60 +84,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
13182
13183 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
13184
13185 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
13186 -#ifdef CONFIG_X86_64
13187 - /*
13188 - * We need valid kernel segments for data and code in long mode too
13189 - * IRET will check the segment types kkeil 2000/10/28
13190 - * Also sysret mandates a special GDT layout
13191 - *
13192 - * TLS descriptors are currently at a different place compared to i386.
13193 - * Hopefully nobody expects them at a fixed place (Wine?)
13194 - */
13195 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
13196 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
13197 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
13198 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
13199 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
13200 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
13201 -#else
13202 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
13203 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13204 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
13205 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
13206 - /*
13207 - * Segments used for calling PnP BIOS have byte granularity.
13208 - * They code segments and data segments have fixed 64k limits,
13209 - * the transfer segment sizes are set at run time.
13210 - */
13211 - /* 32-bit code */
13212 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13213 - /* 16-bit code */
13214 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13215 - /* 16-bit data */
13216 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
13217 - /* 16-bit data */
13218 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
13219 - /* 16-bit data */
13220 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
13221 - /*
13222 - * The APM segments have byte granularity and their bases
13223 - * are set at run time. All have 64k limits.
13224 - */
13225 - /* 32-bit code */
13226 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13227 - /* 16-bit code */
13228 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13229 - /* data */
13230 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
13231 -
13232 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13233 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13234 - GDT_STACK_CANARY_INIT
13235 -#endif
13236 -} };
13237 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
13238 -
13239 static int __init x86_xsave_setup(char *s)
13240 {
13241 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
13242 @@ -372,7 +318,7 @@ void switch_to_new_gdt(int cpu)
13243 {
13244 struct desc_ptr gdt_descr;
13245
13246 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
13247 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
13248 gdt_descr.size = GDT_SIZE - 1;
13249 load_gdt(&gdt_descr);
13250 /* Reload the per-cpu base */
13251 @@ -844,6 +790,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
13252 /* Filter out anything that depends on CPUID levels we don't have */
13253 filter_cpuid_features(c, true);
13254
13255 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
13256 + setup_clear_cpu_cap(X86_FEATURE_SEP);
13257 +#endif
13258 +
13259 /* If the model name is still unset, do table lookup. */
13260 if (!c->x86_model_id[0]) {
13261 const char *p;
13262 @@ -1024,6 +974,9 @@ static __init int setup_disablecpuid(char *arg)
13263 }
13264 __setup("clearcpuid=", setup_disablecpuid);
13265
13266 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
13267 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
13268 +
13269 #ifdef CONFIG_X86_64
13270 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
13271
13272 @@ -1039,7 +992,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
13273 EXPORT_PER_CPU_SYMBOL(current_task);
13274
13275 DEFINE_PER_CPU(unsigned long, kernel_stack) =
13276 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
13277 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
13278 EXPORT_PER_CPU_SYMBOL(kernel_stack);
13279
13280 DEFINE_PER_CPU(char *, irq_stack_ptr) =
13281 @@ -1104,7 +1057,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
13282 {
13283 memset(regs, 0, sizeof(struct pt_regs));
13284 regs->fs = __KERNEL_PERCPU;
13285 - regs->gs = __KERNEL_STACK_CANARY;
13286 + savesegment(gs, regs->gs);
13287
13288 return regs;
13289 }
13290 @@ -1159,7 +1112,7 @@ void __cpuinit cpu_init(void)
13291 int i;
13292
13293 cpu = stack_smp_processor_id();
13294 - t = &per_cpu(init_tss, cpu);
13295 + t = init_tss + cpu;
13296 oist = &per_cpu(orig_ist, cpu);
13297
13298 #ifdef CONFIG_NUMA
13299 @@ -1185,7 +1138,7 @@ void __cpuinit cpu_init(void)
13300 switch_to_new_gdt(cpu);
13301 loadsegment(fs, 0);
13302
13303 - load_idt((const struct desc_ptr *)&idt_descr);
13304 + load_idt(&idt_descr);
13305
13306 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
13307 syscall_init();
13308 @@ -1194,7 +1147,6 @@ void __cpuinit cpu_init(void)
13309 wrmsrl(MSR_KERNEL_GS_BASE, 0);
13310 barrier();
13311
13312 - x86_configure_nx();
13313 if (cpu != 0)
13314 enable_x2apic();
13315
13316 @@ -1248,7 +1200,7 @@ void __cpuinit cpu_init(void)
13317 {
13318 int cpu = smp_processor_id();
13319 struct task_struct *curr = current;
13320 - struct tss_struct *t = &per_cpu(init_tss, cpu);
13321 + struct tss_struct *t = init_tss + cpu;
13322 struct thread_struct *thread = &curr->thread;
13323
13324 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
13325 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
13326 index 5231312..a78a987 100644
13327 --- a/arch/x86/kernel/cpu/intel.c
13328 +++ b/arch/x86/kernel/cpu/intel.c
13329 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
13330 * Update the IDT descriptor and reload the IDT so that
13331 * it uses the read-only mapped virtual address.
13332 */
13333 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
13334 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
13335 load_idt(&idt_descr);
13336 }
13337 #endif
13338 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
13339 index 2af127d..8ff7ac0 100644
13340 --- a/arch/x86/kernel/cpu/mcheck/mce.c
13341 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
13342 @@ -42,6 +42,7 @@
13343 #include <asm/processor.h>
13344 #include <asm/mce.h>
13345 #include <asm/msr.h>
13346 +#include <asm/local.h>
13347
13348 #include "mce-internal.h"
13349
13350 @@ -202,7 +203,7 @@ static void print_mce(struct mce *m)
13351 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
13352 m->cs, m->ip);
13353
13354 - if (m->cs == __KERNEL_CS)
13355 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
13356 print_symbol("{%s}", m->ip);
13357 pr_cont("\n");
13358 }
13359 @@ -235,10 +236,10 @@ static void print_mce(struct mce *m)
13360
13361 #define PANIC_TIMEOUT 5 /* 5 seconds */
13362
13363 -static atomic_t mce_paniced;
13364 +static atomic_unchecked_t mce_paniced;
13365
13366 static int fake_panic;
13367 -static atomic_t mce_fake_paniced;
13368 +static atomic_unchecked_t mce_fake_paniced;
13369
13370 /* Panic in progress. Enable interrupts and wait for final IPI */
13371 static void wait_for_panic(void)
13372 @@ -262,7 +263,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13373 /*
13374 * Make sure only one CPU runs in machine check panic
13375 */
13376 - if (atomic_inc_return(&mce_paniced) > 1)
13377 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
13378 wait_for_panic();
13379 barrier();
13380
13381 @@ -270,7 +271,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13382 console_verbose();
13383 } else {
13384 /* Don't log too much for fake panic */
13385 - if (atomic_inc_return(&mce_fake_paniced) > 1)
13386 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
13387 return;
13388 }
13389 /* First print corrected ones that are still unlogged */
13390 @@ -610,7 +611,7 @@ static int mce_timed_out(u64 *t)
13391 * might have been modified by someone else.
13392 */
13393 rmb();
13394 - if (atomic_read(&mce_paniced))
13395 + if (atomic_read_unchecked(&mce_paniced))
13396 wait_for_panic();
13397 if (!monarch_timeout)
13398 goto out;
13399 @@ -1398,7 +1399,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
13400 }
13401
13402 /* Call the installed machine check handler for this CPU setup. */
13403 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
13404 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
13405 unexpected_machine_check;
13406
13407 /*
13408 @@ -1421,7 +1422,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
13409 return;
13410 }
13411
13412 + pax_open_kernel();
13413 machine_check_vector = do_machine_check;
13414 + pax_close_kernel();
13415
13416 __mcheck_cpu_init_generic();
13417 __mcheck_cpu_init_vendor(c);
13418 @@ -1435,7 +1438,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
13419 */
13420
13421 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
13422 -static int mce_chrdev_open_count; /* #times opened */
13423 +static local_t mce_chrdev_open_count; /* #times opened */
13424 static int mce_chrdev_open_exclu; /* already open exclusive? */
13425
13426 static int mce_chrdev_open(struct inode *inode, struct file *file)
13427 @@ -1443,7 +1446,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
13428 spin_lock(&mce_chrdev_state_lock);
13429
13430 if (mce_chrdev_open_exclu ||
13431 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
13432 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
13433 spin_unlock(&mce_chrdev_state_lock);
13434
13435 return -EBUSY;
13436 @@ -1451,7 +1454,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
13437
13438 if (file->f_flags & O_EXCL)
13439 mce_chrdev_open_exclu = 1;
13440 - mce_chrdev_open_count++;
13441 + local_inc(&mce_chrdev_open_count);
13442
13443 spin_unlock(&mce_chrdev_state_lock);
13444
13445 @@ -1462,7 +1465,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
13446 {
13447 spin_lock(&mce_chrdev_state_lock);
13448
13449 - mce_chrdev_open_count--;
13450 + local_dec(&mce_chrdev_open_count);
13451 mce_chrdev_open_exclu = 0;
13452
13453 spin_unlock(&mce_chrdev_state_lock);
13454 @@ -2171,7 +2174,7 @@ struct dentry *mce_get_debugfs_dir(void)
13455 static void mce_reset(void)
13456 {
13457 cpu_missing = 0;
13458 - atomic_set(&mce_fake_paniced, 0);
13459 + atomic_set_unchecked(&mce_fake_paniced, 0);
13460 atomic_set(&mce_executing, 0);
13461 atomic_set(&mce_callin, 0);
13462 atomic_set(&global_nwo, 0);
13463 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
13464 index 5c0e653..0882b0a 100644
13465 --- a/arch/x86/kernel/cpu/mcheck/p5.c
13466 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
13467 @@ -12,6 +12,7 @@
13468 #include <asm/system.h>
13469 #include <asm/mce.h>
13470 #include <asm/msr.h>
13471 +#include <asm/pgtable.h>
13472
13473 /* By default disabled */
13474 int mce_p5_enabled __read_mostly;
13475 @@ -50,7 +51,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
13476 if (!cpu_has(c, X86_FEATURE_MCE))
13477 return;
13478
13479 + pax_open_kernel();
13480 machine_check_vector = pentium_machine_check;
13481 + pax_close_kernel();
13482 /* Make sure the vector pointer is visible before we enable MCEs: */
13483 wmb();
13484
13485 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
13486 index 54060f5..c1a7577 100644
13487 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
13488 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
13489 @@ -11,6 +11,7 @@
13490 #include <asm/system.h>
13491 #include <asm/mce.h>
13492 #include <asm/msr.h>
13493 +#include <asm/pgtable.h>
13494
13495 /* Machine check handler for WinChip C6: */
13496 static void winchip_machine_check(struct pt_regs *regs, long error_code)
13497 @@ -24,7 +25,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
13498 {
13499 u32 lo, hi;
13500
13501 + pax_open_kernel();
13502 machine_check_vector = winchip_machine_check;
13503 + pax_close_kernel();
13504 /* Make sure the vector pointer is visible before we enable MCEs: */
13505 wmb();
13506
13507 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
13508 index 6b96110..0da73eb 100644
13509 --- a/arch/x86/kernel/cpu/mtrr/main.c
13510 +++ b/arch/x86/kernel/cpu/mtrr/main.c
13511 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
13512 u64 size_or_mask, size_and_mask;
13513 static bool mtrr_aps_delayed_init;
13514
13515 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
13516 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
13517
13518 const struct mtrr_ops *mtrr_if;
13519
13520 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
13521 index df5e41f..816c719 100644
13522 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
13523 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
13524 @@ -25,7 +25,7 @@ struct mtrr_ops {
13525 int (*validate_add_page)(unsigned long base, unsigned long size,
13526 unsigned int type);
13527 int (*have_wrcomb)(void);
13528 -};
13529 +} __do_const;
13530
13531 extern int generic_get_free_region(unsigned long base, unsigned long size,
13532 int replace_reg);
13533 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
13534 index 2bda212..78cc605 100644
13535 --- a/arch/x86/kernel/cpu/perf_event.c
13536 +++ b/arch/x86/kernel/cpu/perf_event.c
13537 @@ -1529,7 +1529,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
13538 break;
13539
13540 perf_callchain_store(entry, frame.return_address);
13541 - fp = frame.next_frame;
13542 + fp = (const void __force_user *)frame.next_frame;
13543 }
13544 }
13545
13546 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
13547 index 13ad899..f642b9a 100644
13548 --- a/arch/x86/kernel/crash.c
13549 +++ b/arch/x86/kernel/crash.c
13550 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
13551 {
13552 #ifdef CONFIG_X86_32
13553 struct pt_regs fixed_regs;
13554 -#endif
13555
13556 -#ifdef CONFIG_X86_32
13557 - if (!user_mode_vm(regs)) {
13558 + if (!user_mode(regs)) {
13559 crash_fixup_ss_esp(&fixed_regs, regs);
13560 regs = &fixed_regs;
13561 }
13562 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
13563 index 37250fe..bf2ec74 100644
13564 --- a/arch/x86/kernel/doublefault_32.c
13565 +++ b/arch/x86/kernel/doublefault_32.c
13566 @@ -11,7 +11,7 @@
13567
13568 #define DOUBLEFAULT_STACKSIZE (1024)
13569 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
13570 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
13571 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
13572
13573 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
13574
13575 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
13576 unsigned long gdt, tss;
13577
13578 store_gdt(&gdt_desc);
13579 - gdt = gdt_desc.address;
13580 + gdt = (unsigned long)gdt_desc.address;
13581
13582 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
13583
13584 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
13585 /* 0x2 bit is always set */
13586 .flags = X86_EFLAGS_SF | 0x2,
13587 .sp = STACK_START,
13588 - .es = __USER_DS,
13589 + .es = __KERNEL_DS,
13590 .cs = __KERNEL_CS,
13591 .ss = __KERNEL_DS,
13592 - .ds = __USER_DS,
13593 + .ds = __KERNEL_DS,
13594 .fs = __KERNEL_PERCPU,
13595
13596 .__cr3 = __pa_nodebug(swapper_pg_dir),
13597 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
13598 index 1aae78f..aab3a3d 100644
13599 --- a/arch/x86/kernel/dumpstack.c
13600 +++ b/arch/x86/kernel/dumpstack.c
13601 @@ -2,6 +2,9 @@
13602 * Copyright (C) 1991, 1992 Linus Torvalds
13603 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
13604 */
13605 +#ifdef CONFIG_GRKERNSEC_HIDESYM
13606 +#define __INCLUDED_BY_HIDESYM 1
13607 +#endif
13608 #include <linux/kallsyms.h>
13609 #include <linux/kprobes.h>
13610 #include <linux/uaccess.h>
13611 @@ -35,9 +38,8 @@ void printk_address(unsigned long address, int reliable)
13612 static void
13613 print_ftrace_graph_addr(unsigned long addr, void *data,
13614 const struct stacktrace_ops *ops,
13615 - struct thread_info *tinfo, int *graph)
13616 + struct task_struct *task, int *graph)
13617 {
13618 - struct task_struct *task = tinfo->task;
13619 unsigned long ret_addr;
13620 int index = task->curr_ret_stack;
13621
13622 @@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
13623 static inline void
13624 print_ftrace_graph_addr(unsigned long addr, void *data,
13625 const struct stacktrace_ops *ops,
13626 - struct thread_info *tinfo, int *graph)
13627 + struct task_struct *task, int *graph)
13628 { }
13629 #endif
13630
13631 @@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
13632 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
13633 */
13634
13635 -static inline int valid_stack_ptr(struct thread_info *tinfo,
13636 - void *p, unsigned int size, void *end)
13637 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
13638 {
13639 - void *t = tinfo;
13640 if (end) {
13641 if (p < end && p >= (end-THREAD_SIZE))
13642 return 1;
13643 @@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
13644 }
13645
13646 unsigned long
13647 -print_context_stack(struct thread_info *tinfo,
13648 +print_context_stack(struct task_struct *task, void *stack_start,
13649 unsigned long *stack, unsigned long bp,
13650 const struct stacktrace_ops *ops, void *data,
13651 unsigned long *end, int *graph)
13652 {
13653 struct stack_frame *frame = (struct stack_frame *)bp;
13654
13655 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
13656 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
13657 unsigned long addr;
13658
13659 addr = *stack;
13660 @@ -102,7 +102,7 @@ print_context_stack(struct thread_info *tinfo,
13661 } else {
13662 ops->address(data, addr, 0);
13663 }
13664 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
13665 + print_ftrace_graph_addr(addr, data, ops, task, graph);
13666 }
13667 stack++;
13668 }
13669 @@ -111,7 +111,7 @@ print_context_stack(struct thread_info *tinfo,
13670 EXPORT_SYMBOL_GPL(print_context_stack);
13671
13672 unsigned long
13673 -print_context_stack_bp(struct thread_info *tinfo,
13674 +print_context_stack_bp(struct task_struct *task, void *stack_start,
13675 unsigned long *stack, unsigned long bp,
13676 const struct stacktrace_ops *ops, void *data,
13677 unsigned long *end, int *graph)
13678 @@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_info *tinfo,
13679 struct stack_frame *frame = (struct stack_frame *)bp;
13680 unsigned long *ret_addr = &frame->return_address;
13681
13682 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
13683 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
13684 unsigned long addr = *ret_addr;
13685
13686 if (!__kernel_text_address(addr))
13687 @@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_info *tinfo,
13688 ops->address(data, addr, 1);
13689 frame = frame->next_frame;
13690 ret_addr = &frame->return_address;
13691 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
13692 + print_ftrace_graph_addr(addr, data, ops, task, graph);
13693 }
13694
13695 return (unsigned long)frame;
13696 @@ -186,7 +186,7 @@ void dump_stack(void)
13697
13698 bp = stack_frame(current, NULL);
13699 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
13700 - current->pid, current->comm, print_tainted(),
13701 + task_pid_nr(current), current->comm, print_tainted(),
13702 init_utsname()->release,
13703 (int)strcspn(init_utsname()->version, " "),
13704 init_utsname()->version);
13705 @@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
13706 }
13707 EXPORT_SYMBOL_GPL(oops_begin);
13708
13709 +extern void gr_handle_kernel_exploit(void);
13710 +
13711 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
13712 {
13713 if (regs && kexec_should_crash(current))
13714 @@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
13715 panic("Fatal exception in interrupt");
13716 if (panic_on_oops)
13717 panic("Fatal exception");
13718 - do_exit(signr);
13719 +
13720 + gr_handle_kernel_exploit();
13721 +
13722 + do_group_exit(signr);
13723 }
13724
13725 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
13726 @@ -269,7 +274,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
13727
13728 show_registers(regs);
13729 #ifdef CONFIG_X86_32
13730 - if (user_mode_vm(regs)) {
13731 + if (user_mode(regs)) {
13732 sp = regs->sp;
13733 ss = regs->ss & 0xffff;
13734 } else {
13735 @@ -297,7 +302,7 @@ void die(const char *str, struct pt_regs *regs, long err)
13736 unsigned long flags = oops_begin();
13737 int sig = SIGSEGV;
13738
13739 - if (!user_mode_vm(regs))
13740 + if (!user_mode(regs))
13741 report_bug(regs->ip, regs);
13742
13743 if (__die(str, regs, err))
13744 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
13745 index c99f9ed..2a15d80 100644
13746 --- a/arch/x86/kernel/dumpstack_32.c
13747 +++ b/arch/x86/kernel/dumpstack_32.c
13748 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
13749 bp = stack_frame(task, regs);
13750
13751 for (;;) {
13752 - struct thread_info *context;
13753 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
13754
13755 - context = (struct thread_info *)
13756 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
13757 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
13758 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
13759
13760 - stack = (unsigned long *)context->previous_esp;
13761 - if (!stack)
13762 + if (stack_start == task_stack_page(task))
13763 break;
13764 + stack = *(unsigned long **)stack_start;
13765 if (ops->stack(data, "IRQ") < 0)
13766 break;
13767 touch_nmi_watchdog();
13768 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
13769 * When in-kernel, we also print out the stack and code at the
13770 * time of the fault..
13771 */
13772 - if (!user_mode_vm(regs)) {
13773 + if (!user_mode(regs)) {
13774 unsigned int code_prologue = code_bytes * 43 / 64;
13775 unsigned int code_len = code_bytes;
13776 unsigned char c;
13777 u8 *ip;
13778 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
13779
13780 printk(KERN_EMERG "Stack:\n");
13781 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
13782
13783 printk(KERN_EMERG "Code: ");
13784
13785 - ip = (u8 *)regs->ip - code_prologue;
13786 + ip = (u8 *)regs->ip - code_prologue + cs_base;
13787 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
13788 /* try starting at IP */
13789 - ip = (u8 *)regs->ip;
13790 + ip = (u8 *)regs->ip + cs_base;
13791 code_len = code_len - code_prologue + 1;
13792 }
13793 for (i = 0; i < code_len; i++, ip++) {
13794 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
13795 printk(KERN_CONT " Bad EIP value.");
13796 break;
13797 }
13798 - if (ip == (u8 *)regs->ip)
13799 + if (ip == (u8 *)regs->ip + cs_base)
13800 printk(KERN_CONT "<%02x> ", c);
13801 else
13802 printk(KERN_CONT "%02x ", c);
13803 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
13804 {
13805 unsigned short ud2;
13806
13807 + ip = ktla_ktva(ip);
13808 if (ip < PAGE_OFFSET)
13809 return 0;
13810 if (probe_kernel_address((unsigned short *)ip, ud2))
13811 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
13812
13813 return ud2 == 0x0b0f;
13814 }
13815 +
13816 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13817 +void pax_check_alloca(unsigned long size)
13818 +{
13819 + unsigned long sp = (unsigned long)&sp, stack_left;
13820 +
13821 + /* all kernel stacks are of the same size */
13822 + stack_left = sp & (THREAD_SIZE - 1);
13823 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
13824 +}
13825 +EXPORT_SYMBOL(pax_check_alloca);
13826 +#endif
13827 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
13828 index 6d728d9..279514e 100644
13829 --- a/arch/x86/kernel/dumpstack_64.c
13830 +++ b/arch/x86/kernel/dumpstack_64.c
13831 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
13832 unsigned long *irq_stack_end =
13833 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
13834 unsigned used = 0;
13835 - struct thread_info *tinfo;
13836 int graph = 0;
13837 unsigned long dummy;
13838 + void *stack_start;
13839
13840 if (!task)
13841 task = current;
13842 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
13843 * current stack address. If the stacks consist of nested
13844 * exceptions
13845 */
13846 - tinfo = task_thread_info(task);
13847 for (;;) {
13848 char *id;
13849 unsigned long *estack_end;
13850 +
13851 estack_end = in_exception_stack(cpu, (unsigned long)stack,
13852 &used, &id);
13853
13854 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
13855 if (ops->stack(data, id) < 0)
13856 break;
13857
13858 - bp = ops->walk_stack(tinfo, stack, bp, ops,
13859 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
13860 data, estack_end, &graph);
13861 ops->stack(data, "<EOE>");
13862 /*
13863 @@ -172,7 +172,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
13864 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
13865 if (ops->stack(data, "IRQ") < 0)
13866 break;
13867 - bp = ops->walk_stack(tinfo, stack, bp,
13868 + bp = ops->walk_stack(task, irq_stack, stack, bp,
13869 ops, data, irq_stack_end, &graph);
13870 /*
13871 * We link to the next stack (which would be
13872 @@ -191,7 +191,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
13873 /*
13874 * This handles the process stack:
13875 */
13876 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
13877 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
13878 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
13879 put_cpu();
13880 }
13881 EXPORT_SYMBOL(dump_trace);
13882 @@ -305,3 +306,50 @@ int is_valid_bugaddr(unsigned long ip)
13883
13884 return ud2 == 0x0b0f;
13885 }
13886 +
13887 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13888 +void pax_check_alloca(unsigned long size)
13889 +{
13890 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
13891 + unsigned cpu, used;
13892 + char *id;
13893 +
13894 + /* check the process stack first */
13895 + stack_start = (unsigned long)task_stack_page(current);
13896 + stack_end = stack_start + THREAD_SIZE;
13897 + if (likely(stack_start <= sp && sp < stack_end)) {
13898 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
13899 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
13900 + return;
13901 + }
13902 +
13903 + cpu = get_cpu();
13904 +
13905 + /* check the irq stacks */
13906 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
13907 + stack_start = stack_end - IRQ_STACK_SIZE;
13908 + if (stack_start <= sp && sp < stack_end) {
13909 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
13910 + put_cpu();
13911 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
13912 + return;
13913 + }
13914 +
13915 + /* check the exception stacks */
13916 + used = 0;
13917 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
13918 + stack_start = stack_end - EXCEPTION_STKSZ;
13919 + if (stack_end && stack_start <= sp && sp < stack_end) {
13920 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
13921 + put_cpu();
13922 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
13923 + return;
13924 + }
13925 +
13926 + put_cpu();
13927 +
13928 + /* unknown stack */
13929 + BUG();
13930 +}
13931 +EXPORT_SYMBOL(pax_check_alloca);
13932 +#endif
13933 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
13934 index cd28a35..c72ed9a 100644
13935 --- a/arch/x86/kernel/early_printk.c
13936 +++ b/arch/x86/kernel/early_printk.c
13937 @@ -7,6 +7,7 @@
13938 #include <linux/pci_regs.h>
13939 #include <linux/pci_ids.h>
13940 #include <linux/errno.h>
13941 +#include <linux/sched.h>
13942 #include <asm/io.h>
13943 #include <asm/processor.h>
13944 #include <asm/fcntl.h>
13945 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
13946 index f3f6f53..0841b66 100644
13947 --- a/arch/x86/kernel/entry_32.S
13948 +++ b/arch/x86/kernel/entry_32.S
13949 @@ -186,13 +186,146 @@
13950 /*CFI_REL_OFFSET gs, PT_GS*/
13951 .endm
13952 .macro SET_KERNEL_GS reg
13953 +
13954 +#ifdef CONFIG_CC_STACKPROTECTOR
13955 movl $(__KERNEL_STACK_CANARY), \reg
13956 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
13957 + movl $(__USER_DS), \reg
13958 +#else
13959 + xorl \reg, \reg
13960 +#endif
13961 +
13962 movl \reg, %gs
13963 .endm
13964
13965 #endif /* CONFIG_X86_32_LAZY_GS */
13966
13967 -.macro SAVE_ALL
13968 +.macro pax_enter_kernel
13969 +#ifdef CONFIG_PAX_KERNEXEC
13970 + call pax_enter_kernel
13971 +#endif
13972 +.endm
13973 +
13974 +.macro pax_exit_kernel
13975 +#ifdef CONFIG_PAX_KERNEXEC
13976 + call pax_exit_kernel
13977 +#endif
13978 +.endm
13979 +
13980 +#ifdef CONFIG_PAX_KERNEXEC
13981 +ENTRY(pax_enter_kernel)
13982 +#ifdef CONFIG_PARAVIRT
13983 + pushl %eax
13984 + pushl %ecx
13985 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
13986 + mov %eax, %esi
13987 +#else
13988 + mov %cr0, %esi
13989 +#endif
13990 + bts $16, %esi
13991 + jnc 1f
13992 + mov %cs, %esi
13993 + cmp $__KERNEL_CS, %esi
13994 + jz 3f
13995 + ljmp $__KERNEL_CS, $3f
13996 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
13997 +2:
13998 +#ifdef CONFIG_PARAVIRT
13999 + mov %esi, %eax
14000 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14001 +#else
14002 + mov %esi, %cr0
14003 +#endif
14004 +3:
14005 +#ifdef CONFIG_PARAVIRT
14006 + popl %ecx
14007 + popl %eax
14008 +#endif
14009 + ret
14010 +ENDPROC(pax_enter_kernel)
14011 +
14012 +ENTRY(pax_exit_kernel)
14013 +#ifdef CONFIG_PARAVIRT
14014 + pushl %eax
14015 + pushl %ecx
14016 +#endif
14017 + mov %cs, %esi
14018 + cmp $__KERNEXEC_KERNEL_CS, %esi
14019 + jnz 2f
14020 +#ifdef CONFIG_PARAVIRT
14021 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14022 + mov %eax, %esi
14023 +#else
14024 + mov %cr0, %esi
14025 +#endif
14026 + btr $16, %esi
14027 + ljmp $__KERNEL_CS, $1f
14028 +1:
14029 +#ifdef CONFIG_PARAVIRT
14030 + mov %esi, %eax
14031 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14032 +#else
14033 + mov %esi, %cr0
14034 +#endif
14035 +2:
14036 +#ifdef CONFIG_PARAVIRT
14037 + popl %ecx
14038 + popl %eax
14039 +#endif
14040 + ret
14041 +ENDPROC(pax_exit_kernel)
14042 +#endif
14043 +
14044 +.macro pax_erase_kstack
14045 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14046 + call pax_erase_kstack
14047 +#endif
14048 +.endm
14049 +
14050 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14051 +/*
14052 + * ebp: thread_info
14053 + * ecx, edx: can be clobbered
14054 + */
14055 +ENTRY(pax_erase_kstack)
14056 + pushl %edi
14057 + pushl %eax
14058 +
14059 + mov TI_lowest_stack(%ebp), %edi
14060 + mov $-0xBEEF, %eax
14061 + std
14062 +
14063 +1: mov %edi, %ecx
14064 + and $THREAD_SIZE_asm - 1, %ecx
14065 + shr $2, %ecx
14066 + repne scasl
14067 + jecxz 2f
14068 +
14069 + cmp $2*16, %ecx
14070 + jc 2f
14071 +
14072 + mov $2*16, %ecx
14073 + repe scasl
14074 + jecxz 2f
14075 + jne 1b
14076 +
14077 +2: cld
14078 + mov %esp, %ecx
14079 + sub %edi, %ecx
14080 + shr $2, %ecx
14081 + rep stosl
14082 +
14083 + mov TI_task_thread_sp0(%ebp), %edi
14084 + sub $128, %edi
14085 + mov %edi, TI_lowest_stack(%ebp)
14086 +
14087 + popl %eax
14088 + popl %edi
14089 + ret
14090 +ENDPROC(pax_erase_kstack)
14091 +#endif
14092 +
14093 +.macro __SAVE_ALL _DS
14094 cld
14095 PUSH_GS
14096 pushl_cfi %fs
14097 @@ -215,7 +348,7 @@
14098 CFI_REL_OFFSET ecx, 0
14099 pushl_cfi %ebx
14100 CFI_REL_OFFSET ebx, 0
14101 - movl $(__USER_DS), %edx
14102 + movl $\_DS, %edx
14103 movl %edx, %ds
14104 movl %edx, %es
14105 movl $(__KERNEL_PERCPU), %edx
14106 @@ -223,6 +356,15 @@
14107 SET_KERNEL_GS %edx
14108 .endm
14109
14110 +.macro SAVE_ALL
14111 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
14112 + __SAVE_ALL __KERNEL_DS
14113 + pax_enter_kernel
14114 +#else
14115 + __SAVE_ALL __USER_DS
14116 +#endif
14117 +.endm
14118 +
14119 .macro RESTORE_INT_REGS
14120 popl_cfi %ebx
14121 CFI_RESTORE ebx
14122 @@ -308,7 +450,7 @@ ENTRY(ret_from_fork)
14123 popfl_cfi
14124 jmp syscall_exit
14125 CFI_ENDPROC
14126 -END(ret_from_fork)
14127 +ENDPROC(ret_from_fork)
14128
14129 /*
14130 * Interrupt exit functions should be protected against kprobes
14131 @@ -333,7 +475,15 @@ check_userspace:
14132 movb PT_CS(%esp), %al
14133 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
14134 cmpl $USER_RPL, %eax
14135 +
14136 +#ifdef CONFIG_PAX_KERNEXEC
14137 + jae resume_userspace
14138 +
14139 + PAX_EXIT_KERNEL
14140 + jmp resume_kernel
14141 +#else
14142 jb resume_kernel # not returning to v8086 or userspace
14143 +#endif
14144
14145 ENTRY(resume_userspace)
14146 LOCKDEP_SYS_EXIT
14147 @@ -345,8 +495,8 @@ ENTRY(resume_userspace)
14148 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
14149 # int/exception return?
14150 jne work_pending
14151 - jmp restore_all
14152 -END(ret_from_exception)
14153 + jmp restore_all_pax
14154 +ENDPROC(ret_from_exception)
14155
14156 #ifdef CONFIG_PREEMPT
14157 ENTRY(resume_kernel)
14158 @@ -361,7 +511,7 @@ need_resched:
14159 jz restore_all
14160 call preempt_schedule_irq
14161 jmp need_resched
14162 -END(resume_kernel)
14163 +ENDPROC(resume_kernel)
14164 #endif
14165 CFI_ENDPROC
14166 /*
14167 @@ -395,23 +545,34 @@ sysenter_past_esp:
14168 /*CFI_REL_OFFSET cs, 0*/
14169 /*
14170 * Push current_thread_info()->sysenter_return to the stack.
14171 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
14172 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
14173 */
14174 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
14175 + pushl_cfi $0
14176 CFI_REL_OFFSET eip, 0
14177
14178 pushl_cfi %eax
14179 SAVE_ALL
14180 + GET_THREAD_INFO(%ebp)
14181 + movl TI_sysenter_return(%ebp),%ebp
14182 + movl %ebp,PT_EIP(%esp)
14183 ENABLE_INTERRUPTS(CLBR_NONE)
14184
14185 /*
14186 * Load the potential sixth argument from user stack.
14187 * Careful about security.
14188 */
14189 + movl PT_OLDESP(%esp),%ebp
14190 +
14191 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14192 + mov PT_OLDSS(%esp),%ds
14193 +1: movl %ds:(%ebp),%ebp
14194 + push %ss
14195 + pop %ds
14196 +#else
14197 cmpl $__PAGE_OFFSET-3,%ebp
14198 jae syscall_fault
14199 1: movl (%ebp),%ebp
14200 +#endif
14201 +
14202 movl %ebp,PT_EBP(%esp)
14203 .section __ex_table,"a"
14204 .align 4
14205 @@ -434,12 +595,24 @@ sysenter_do_call:
14206 testl $_TIF_ALLWORK_MASK, %ecx
14207 jne sysexit_audit
14208 sysenter_exit:
14209 +
14210 +#ifdef CONFIG_PAX_RANDKSTACK
14211 + pushl_cfi %eax
14212 + movl %esp, %eax
14213 + call pax_randomize_kstack
14214 + popl_cfi %eax
14215 +#endif
14216 +
14217 + pax_erase_kstack
14218 +
14219 /* if something modifies registers it must also disable sysexit */
14220 movl PT_EIP(%esp), %edx
14221 movl PT_OLDESP(%esp), %ecx
14222 xorl %ebp,%ebp
14223 TRACE_IRQS_ON
14224 1: mov PT_FS(%esp), %fs
14225 +2: mov PT_DS(%esp), %ds
14226 +3: mov PT_ES(%esp), %es
14227 PTGS_TO_GS
14228 ENABLE_INTERRUPTS_SYSEXIT
14229
14230 @@ -456,6 +629,9 @@ sysenter_audit:
14231 movl %eax,%edx /* 2nd arg: syscall number */
14232 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
14233 call audit_syscall_entry
14234 +
14235 + pax_erase_kstack
14236 +
14237 pushl_cfi %ebx
14238 movl PT_EAX(%esp),%eax /* reload syscall number */
14239 jmp sysenter_do_call
14240 @@ -482,11 +658,17 @@ sysexit_audit:
14241
14242 CFI_ENDPROC
14243 .pushsection .fixup,"ax"
14244 -2: movl $0,PT_FS(%esp)
14245 +4: movl $0,PT_FS(%esp)
14246 + jmp 1b
14247 +5: movl $0,PT_DS(%esp)
14248 + jmp 1b
14249 +6: movl $0,PT_ES(%esp)
14250 jmp 1b
14251 .section __ex_table,"a"
14252 .align 4
14253 - .long 1b,2b
14254 + .long 1b,4b
14255 + .long 2b,5b
14256 + .long 3b,6b
14257 .popsection
14258 PTGS_TO_GS_EX
14259 ENDPROC(ia32_sysenter_target)
14260 @@ -519,6 +701,15 @@ syscall_exit:
14261 testl $_TIF_ALLWORK_MASK, %ecx # current->work
14262 jne syscall_exit_work
14263
14264 +restore_all_pax:
14265 +
14266 +#ifdef CONFIG_PAX_RANDKSTACK
14267 + movl %esp, %eax
14268 + call pax_randomize_kstack
14269 +#endif
14270 +
14271 + pax_erase_kstack
14272 +
14273 restore_all:
14274 TRACE_IRQS_IRET
14275 restore_all_notrace:
14276 @@ -578,14 +769,34 @@ ldt_ss:
14277 * compensating for the offset by changing to the ESPFIX segment with
14278 * a base address that matches for the difference.
14279 */
14280 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
14281 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
14282 mov %esp, %edx /* load kernel esp */
14283 mov PT_OLDESP(%esp), %eax /* load userspace esp */
14284 mov %dx, %ax /* eax: new kernel esp */
14285 sub %eax, %edx /* offset (low word is 0) */
14286 +#ifdef CONFIG_SMP
14287 + movl PER_CPU_VAR(cpu_number), %ebx
14288 + shll $PAGE_SHIFT_asm, %ebx
14289 + addl $cpu_gdt_table, %ebx
14290 +#else
14291 + movl $cpu_gdt_table, %ebx
14292 +#endif
14293 shr $16, %edx
14294 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
14295 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
14296 +
14297 +#ifdef CONFIG_PAX_KERNEXEC
14298 + mov %cr0, %esi
14299 + btr $16, %esi
14300 + mov %esi, %cr0
14301 +#endif
14302 +
14303 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
14304 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
14305 +
14306 +#ifdef CONFIG_PAX_KERNEXEC
14307 + bts $16, %esi
14308 + mov %esi, %cr0
14309 +#endif
14310 +
14311 pushl_cfi $__ESPFIX_SS
14312 pushl_cfi %eax /* new kernel esp */
14313 /* Disable interrupts, but do not irqtrace this section: we
14314 @@ -614,34 +825,28 @@ work_resched:
14315 movl TI_flags(%ebp), %ecx
14316 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
14317 # than syscall tracing?
14318 - jz restore_all
14319 + jz restore_all_pax
14320 testb $_TIF_NEED_RESCHED, %cl
14321 jnz work_resched
14322
14323 work_notifysig: # deal with pending signals and
14324 # notify-resume requests
14325 + movl %esp, %eax
14326 #ifdef CONFIG_VM86
14327 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
14328 - movl %esp, %eax
14329 - jne work_notifysig_v86 # returning to kernel-space or
14330 + jz 1f # returning to kernel-space or
14331 # vm86-space
14332 - xorl %edx, %edx
14333 - call do_notify_resume
14334 - jmp resume_userspace_sig
14335
14336 - ALIGN
14337 -work_notifysig_v86:
14338 pushl_cfi %ecx # save ti_flags for do_notify_resume
14339 call save_v86_state # %eax contains pt_regs pointer
14340 popl_cfi %ecx
14341 movl %eax, %esp
14342 -#else
14343 - movl %esp, %eax
14344 +1:
14345 #endif
14346 xorl %edx, %edx
14347 call do_notify_resume
14348 jmp resume_userspace_sig
14349 -END(work_pending)
14350 +ENDPROC(work_pending)
14351
14352 # perform syscall exit tracing
14353 ALIGN
14354 @@ -649,11 +854,14 @@ syscall_trace_entry:
14355 movl $-ENOSYS,PT_EAX(%esp)
14356 movl %esp, %eax
14357 call syscall_trace_enter
14358 +
14359 + pax_erase_kstack
14360 +
14361 /* What it returned is what we'll actually use. */
14362 cmpl $(nr_syscalls), %eax
14363 jnae syscall_call
14364 jmp syscall_exit
14365 -END(syscall_trace_entry)
14366 +ENDPROC(syscall_trace_entry)
14367
14368 # perform syscall exit tracing
14369 ALIGN
14370 @@ -666,20 +874,24 @@ syscall_exit_work:
14371 movl %esp, %eax
14372 call syscall_trace_leave
14373 jmp resume_userspace
14374 -END(syscall_exit_work)
14375 +ENDPROC(syscall_exit_work)
14376 CFI_ENDPROC
14377
14378 RING0_INT_FRAME # can't unwind into user space anyway
14379 syscall_fault:
14380 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14381 + push %ss
14382 + pop %ds
14383 +#endif
14384 GET_THREAD_INFO(%ebp)
14385 movl $-EFAULT,PT_EAX(%esp)
14386 jmp resume_userspace
14387 -END(syscall_fault)
14388 +ENDPROC(syscall_fault)
14389
14390 syscall_badsys:
14391 movl $-ENOSYS,PT_EAX(%esp)
14392 jmp resume_userspace
14393 -END(syscall_badsys)
14394 +ENDPROC(syscall_badsys)
14395 CFI_ENDPROC
14396 /*
14397 * End of kprobes section
14398 @@ -753,6 +965,36 @@ ptregs_clone:
14399 CFI_ENDPROC
14400 ENDPROC(ptregs_clone)
14401
14402 + ALIGN;
14403 +ENTRY(kernel_execve)
14404 + CFI_STARTPROC
14405 + pushl_cfi %ebp
14406 + sub $PT_OLDSS+4,%esp
14407 + pushl_cfi %edi
14408 + pushl_cfi %ecx
14409 + pushl_cfi %eax
14410 + lea 3*4(%esp),%edi
14411 + mov $PT_OLDSS/4+1,%ecx
14412 + xorl %eax,%eax
14413 + rep stosl
14414 + popl_cfi %eax
14415 + popl_cfi %ecx
14416 + popl_cfi %edi
14417 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
14418 + pushl_cfi %esp
14419 + call sys_execve
14420 + add $4,%esp
14421 + CFI_ADJUST_CFA_OFFSET -4
14422 + GET_THREAD_INFO(%ebp)
14423 + test %eax,%eax
14424 + jz syscall_exit
14425 + add $PT_OLDSS+4,%esp
14426 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
14427 + popl_cfi %ebp
14428 + ret
14429 + CFI_ENDPROC
14430 +ENDPROC(kernel_execve)
14431 +
14432 .macro FIXUP_ESPFIX_STACK
14433 /*
14434 * Switch back for ESPFIX stack to the normal zerobased stack
14435 @@ -762,8 +1004,15 @@ ENDPROC(ptregs_clone)
14436 * normal stack and adjusts ESP with the matching offset.
14437 */
14438 /* fixup the stack */
14439 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
14440 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
14441 +#ifdef CONFIG_SMP
14442 + movl PER_CPU_VAR(cpu_number), %ebx
14443 + shll $PAGE_SHIFT_asm, %ebx
14444 + addl $cpu_gdt_table, %ebx
14445 +#else
14446 + movl $cpu_gdt_table, %ebx
14447 +#endif
14448 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
14449 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
14450 shl $16, %eax
14451 addl %esp, %eax /* the adjusted stack pointer */
14452 pushl_cfi $__KERNEL_DS
14453 @@ -816,7 +1065,7 @@ vector=vector+1
14454 .endr
14455 2: jmp common_interrupt
14456 .endr
14457 -END(irq_entries_start)
14458 +ENDPROC(irq_entries_start)
14459
14460 .previous
14461 END(interrupt)
14462 @@ -864,7 +1113,7 @@ ENTRY(coprocessor_error)
14463 pushl_cfi $do_coprocessor_error
14464 jmp error_code
14465 CFI_ENDPROC
14466 -END(coprocessor_error)
14467 +ENDPROC(coprocessor_error)
14468
14469 ENTRY(simd_coprocessor_error)
14470 RING0_INT_FRAME
14471 @@ -885,7 +1134,7 @@ ENTRY(simd_coprocessor_error)
14472 #endif
14473 jmp error_code
14474 CFI_ENDPROC
14475 -END(simd_coprocessor_error)
14476 +ENDPROC(simd_coprocessor_error)
14477
14478 ENTRY(device_not_available)
14479 RING0_INT_FRAME
14480 @@ -893,7 +1142,7 @@ ENTRY(device_not_available)
14481 pushl_cfi $do_device_not_available
14482 jmp error_code
14483 CFI_ENDPROC
14484 -END(device_not_available)
14485 +ENDPROC(device_not_available)
14486
14487 #ifdef CONFIG_PARAVIRT
14488 ENTRY(native_iret)
14489 @@ -902,12 +1151,12 @@ ENTRY(native_iret)
14490 .align 4
14491 .long native_iret, iret_exc
14492 .previous
14493 -END(native_iret)
14494 +ENDPROC(native_iret)
14495
14496 ENTRY(native_irq_enable_sysexit)
14497 sti
14498 sysexit
14499 -END(native_irq_enable_sysexit)
14500 +ENDPROC(native_irq_enable_sysexit)
14501 #endif
14502
14503 ENTRY(overflow)
14504 @@ -916,7 +1165,7 @@ ENTRY(overflow)
14505 pushl_cfi $do_overflow
14506 jmp error_code
14507 CFI_ENDPROC
14508 -END(overflow)
14509 +ENDPROC(overflow)
14510
14511 ENTRY(bounds)
14512 RING0_INT_FRAME
14513 @@ -924,7 +1173,7 @@ ENTRY(bounds)
14514 pushl_cfi $do_bounds
14515 jmp error_code
14516 CFI_ENDPROC
14517 -END(bounds)
14518 +ENDPROC(bounds)
14519
14520 ENTRY(invalid_op)
14521 RING0_INT_FRAME
14522 @@ -932,7 +1181,7 @@ ENTRY(invalid_op)
14523 pushl_cfi $do_invalid_op
14524 jmp error_code
14525 CFI_ENDPROC
14526 -END(invalid_op)
14527 +ENDPROC(invalid_op)
14528
14529 ENTRY(coprocessor_segment_overrun)
14530 RING0_INT_FRAME
14531 @@ -940,35 +1189,35 @@ ENTRY(coprocessor_segment_overrun)
14532 pushl_cfi $do_coprocessor_segment_overrun
14533 jmp error_code
14534 CFI_ENDPROC
14535 -END(coprocessor_segment_overrun)
14536 +ENDPROC(coprocessor_segment_overrun)
14537
14538 ENTRY(invalid_TSS)
14539 RING0_EC_FRAME
14540 pushl_cfi $do_invalid_TSS
14541 jmp error_code
14542 CFI_ENDPROC
14543 -END(invalid_TSS)
14544 +ENDPROC(invalid_TSS)
14545
14546 ENTRY(segment_not_present)
14547 RING0_EC_FRAME
14548 pushl_cfi $do_segment_not_present
14549 jmp error_code
14550 CFI_ENDPROC
14551 -END(segment_not_present)
14552 +ENDPROC(segment_not_present)
14553
14554 ENTRY(stack_segment)
14555 RING0_EC_FRAME
14556 pushl_cfi $do_stack_segment
14557 jmp error_code
14558 CFI_ENDPROC
14559 -END(stack_segment)
14560 +ENDPROC(stack_segment)
14561
14562 ENTRY(alignment_check)
14563 RING0_EC_FRAME
14564 pushl_cfi $do_alignment_check
14565 jmp error_code
14566 CFI_ENDPROC
14567 -END(alignment_check)
14568 +ENDPROC(alignment_check)
14569
14570 ENTRY(divide_error)
14571 RING0_INT_FRAME
14572 @@ -976,7 +1225,7 @@ ENTRY(divide_error)
14573 pushl_cfi $do_divide_error
14574 jmp error_code
14575 CFI_ENDPROC
14576 -END(divide_error)
14577 +ENDPROC(divide_error)
14578
14579 #ifdef CONFIG_X86_MCE
14580 ENTRY(machine_check)
14581 @@ -985,7 +1234,7 @@ ENTRY(machine_check)
14582 pushl_cfi machine_check_vector
14583 jmp error_code
14584 CFI_ENDPROC
14585 -END(machine_check)
14586 +ENDPROC(machine_check)
14587 #endif
14588
14589 ENTRY(spurious_interrupt_bug)
14590 @@ -994,7 +1243,7 @@ ENTRY(spurious_interrupt_bug)
14591 pushl_cfi $do_spurious_interrupt_bug
14592 jmp error_code
14593 CFI_ENDPROC
14594 -END(spurious_interrupt_bug)
14595 +ENDPROC(spurious_interrupt_bug)
14596 /*
14597 * End of kprobes section
14598 */
14599 @@ -1109,7 +1358,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
14600
14601 ENTRY(mcount)
14602 ret
14603 -END(mcount)
14604 +ENDPROC(mcount)
14605
14606 ENTRY(ftrace_caller)
14607 cmpl $0, function_trace_stop
14608 @@ -1138,7 +1387,7 @@ ftrace_graph_call:
14609 .globl ftrace_stub
14610 ftrace_stub:
14611 ret
14612 -END(ftrace_caller)
14613 +ENDPROC(ftrace_caller)
14614
14615 #else /* ! CONFIG_DYNAMIC_FTRACE */
14616
14617 @@ -1174,7 +1423,7 @@ trace:
14618 popl %ecx
14619 popl %eax
14620 jmp ftrace_stub
14621 -END(mcount)
14622 +ENDPROC(mcount)
14623 #endif /* CONFIG_DYNAMIC_FTRACE */
14624 #endif /* CONFIG_FUNCTION_TRACER */
14625
14626 @@ -1195,7 +1444,7 @@ ENTRY(ftrace_graph_caller)
14627 popl %ecx
14628 popl %eax
14629 ret
14630 -END(ftrace_graph_caller)
14631 +ENDPROC(ftrace_graph_caller)
14632
14633 .globl return_to_handler
14634 return_to_handler:
14635 @@ -1209,7 +1458,6 @@ return_to_handler:
14636 jmp *%ecx
14637 #endif
14638
14639 -.section .rodata,"a"
14640 #include "syscall_table_32.S"
14641
14642 syscall_table_size=(.-sys_call_table)
14643 @@ -1255,15 +1503,18 @@ error_code:
14644 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
14645 REG_TO_PTGS %ecx
14646 SET_KERNEL_GS %ecx
14647 - movl $(__USER_DS), %ecx
14648 + movl $(__KERNEL_DS), %ecx
14649 movl %ecx, %ds
14650 movl %ecx, %es
14651 +
14652 + pax_enter_kernel
14653 +
14654 TRACE_IRQS_OFF
14655 movl %esp,%eax # pt_regs pointer
14656 call *%edi
14657 jmp ret_from_exception
14658 CFI_ENDPROC
14659 -END(page_fault)
14660 +ENDPROC(page_fault)
14661
14662 /*
14663 * Debug traps and NMI can happen at the one SYSENTER instruction
14664 @@ -1305,7 +1556,7 @@ debug_stack_correct:
14665 call do_debug
14666 jmp ret_from_exception
14667 CFI_ENDPROC
14668 -END(debug)
14669 +ENDPROC(debug)
14670
14671 /*
14672 * NMI is doubly nasty. It can happen _while_ we're handling
14673 @@ -1342,6 +1593,9 @@ nmi_stack_correct:
14674 xorl %edx,%edx # zero error code
14675 movl %esp,%eax # pt_regs pointer
14676 call do_nmi
14677 +
14678 + pax_exit_kernel
14679 +
14680 jmp restore_all_notrace
14681 CFI_ENDPROC
14682
14683 @@ -1378,12 +1632,15 @@ nmi_espfix_stack:
14684 FIXUP_ESPFIX_STACK # %eax == %esp
14685 xorl %edx,%edx # zero error code
14686 call do_nmi
14687 +
14688 + pax_exit_kernel
14689 +
14690 RESTORE_REGS
14691 lss 12+4(%esp), %esp # back to espfix stack
14692 CFI_ADJUST_CFA_OFFSET -24
14693 jmp irq_return
14694 CFI_ENDPROC
14695 -END(nmi)
14696 +ENDPROC(nmi)
14697
14698 ENTRY(int3)
14699 RING0_INT_FRAME
14700 @@ -1395,14 +1652,14 @@ ENTRY(int3)
14701 call do_int3
14702 jmp ret_from_exception
14703 CFI_ENDPROC
14704 -END(int3)
14705 +ENDPROC(int3)
14706
14707 ENTRY(general_protection)
14708 RING0_EC_FRAME
14709 pushl_cfi $do_general_protection
14710 jmp error_code
14711 CFI_ENDPROC
14712 -END(general_protection)
14713 +ENDPROC(general_protection)
14714
14715 #ifdef CONFIG_KVM_GUEST
14716 ENTRY(async_page_fault)
14717 @@ -1410,7 +1667,7 @@ ENTRY(async_page_fault)
14718 pushl_cfi $do_async_page_fault
14719 jmp error_code
14720 CFI_ENDPROC
14721 -END(async_page_fault)
14722 +ENDPROC(async_page_fault)
14723 #endif
14724
14725 /*
14726 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
14727 index faf8d5e..4f16a68 100644
14728 --- a/arch/x86/kernel/entry_64.S
14729 +++ b/arch/x86/kernel/entry_64.S
14730 @@ -55,6 +55,8 @@
14731 #include <asm/paravirt.h>
14732 #include <asm/ftrace.h>
14733 #include <asm/percpu.h>
14734 +#include <asm/pgtable.h>
14735 +#include <asm/alternative-asm.h>
14736
14737 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14738 #include <linux/elf-em.h>
14739 @@ -68,8 +70,9 @@
14740 #ifdef CONFIG_FUNCTION_TRACER
14741 #ifdef CONFIG_DYNAMIC_FTRACE
14742 ENTRY(mcount)
14743 + pax_force_retaddr
14744 retq
14745 -END(mcount)
14746 +ENDPROC(mcount)
14747
14748 ENTRY(ftrace_caller)
14749 cmpl $0, function_trace_stop
14750 @@ -92,8 +95,9 @@ GLOBAL(ftrace_graph_call)
14751 #endif
14752
14753 GLOBAL(ftrace_stub)
14754 + pax_force_retaddr
14755 retq
14756 -END(ftrace_caller)
14757 +ENDPROC(ftrace_caller)
14758
14759 #else /* ! CONFIG_DYNAMIC_FTRACE */
14760 ENTRY(mcount)
14761 @@ -112,6 +116,7 @@ ENTRY(mcount)
14762 #endif
14763
14764 GLOBAL(ftrace_stub)
14765 + pax_force_retaddr
14766 retq
14767
14768 trace:
14769 @@ -121,12 +126,13 @@ trace:
14770 movq 8(%rbp), %rsi
14771 subq $MCOUNT_INSN_SIZE, %rdi
14772
14773 + pax_force_fptr ftrace_trace_function
14774 call *ftrace_trace_function
14775
14776 MCOUNT_RESTORE_FRAME
14777
14778 jmp ftrace_stub
14779 -END(mcount)
14780 +ENDPROC(mcount)
14781 #endif /* CONFIG_DYNAMIC_FTRACE */
14782 #endif /* CONFIG_FUNCTION_TRACER */
14783
14784 @@ -146,8 +152,9 @@ ENTRY(ftrace_graph_caller)
14785
14786 MCOUNT_RESTORE_FRAME
14787
14788 + pax_force_retaddr
14789 retq
14790 -END(ftrace_graph_caller)
14791 +ENDPROC(ftrace_graph_caller)
14792
14793 GLOBAL(return_to_handler)
14794 subq $24, %rsp
14795 @@ -163,6 +170,7 @@ GLOBAL(return_to_handler)
14796 movq 8(%rsp), %rdx
14797 movq (%rsp), %rax
14798 addq $24, %rsp
14799 + pax_force_fptr %rdi
14800 jmp *%rdi
14801 #endif
14802
14803 @@ -178,6 +186,282 @@ ENTRY(native_usergs_sysret64)
14804 ENDPROC(native_usergs_sysret64)
14805 #endif /* CONFIG_PARAVIRT */
14806
14807 + .macro ljmpq sel, off
14808 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
14809 + .byte 0x48; ljmp *1234f(%rip)
14810 + .pushsection .rodata
14811 + .align 16
14812 + 1234: .quad \off; .word \sel
14813 + .popsection
14814 +#else
14815 + pushq $\sel
14816 + pushq $\off
14817 + lretq
14818 +#endif
14819 + .endm
14820 +
14821 + .macro pax_enter_kernel
14822 + pax_set_fptr_mask
14823 +#ifdef CONFIG_PAX_KERNEXEC
14824 + call pax_enter_kernel
14825 +#endif
14826 + .endm
14827 +
14828 + .macro pax_exit_kernel
14829 +#ifdef CONFIG_PAX_KERNEXEC
14830 + call pax_exit_kernel
14831 +#endif
14832 + .endm
14833 +
14834 +#ifdef CONFIG_PAX_KERNEXEC
14835 +ENTRY(pax_enter_kernel)
14836 + pushq %rdi
14837 +
14838 +#ifdef CONFIG_PARAVIRT
14839 + PV_SAVE_REGS(CLBR_RDI)
14840 +#endif
14841 +
14842 + GET_CR0_INTO_RDI
14843 + bts $16,%rdi
14844 + jnc 3f
14845 + mov %cs,%edi
14846 + cmp $__KERNEL_CS,%edi
14847 + jnz 2f
14848 +1:
14849 +
14850 +#ifdef CONFIG_PARAVIRT
14851 + PV_RESTORE_REGS(CLBR_RDI)
14852 +#endif
14853 +
14854 + popq %rdi
14855 + pax_force_retaddr
14856 + retq
14857 +
14858 +2: ljmpq __KERNEL_CS,1f
14859 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
14860 +4: SET_RDI_INTO_CR0
14861 + jmp 1b
14862 +ENDPROC(pax_enter_kernel)
14863 +
14864 +ENTRY(pax_exit_kernel)
14865 + pushq %rdi
14866 +
14867 +#ifdef CONFIG_PARAVIRT
14868 + PV_SAVE_REGS(CLBR_RDI)
14869 +#endif
14870 +
14871 + mov %cs,%rdi
14872 + cmp $__KERNEXEC_KERNEL_CS,%edi
14873 + jz 2f
14874 +1:
14875 +
14876 +#ifdef CONFIG_PARAVIRT
14877 + PV_RESTORE_REGS(CLBR_RDI);
14878 +#endif
14879 +
14880 + popq %rdi
14881 + pax_force_retaddr
14882 + retq
14883 +
14884 +2: GET_CR0_INTO_RDI
14885 + btr $16,%rdi
14886 + ljmpq __KERNEL_CS,3f
14887 +3: SET_RDI_INTO_CR0
14888 + jmp 1b
14889 +#ifdef CONFIG_PARAVIRT
14890 + PV_RESTORE_REGS(CLBR_RDI);
14891 +#endif
14892 +
14893 + popq %rdi
14894 + pax_force_retaddr
14895 + retq
14896 +ENDPROC(pax_exit_kernel)
14897 +#endif
14898 +
14899 + .macro pax_enter_kernel_user
14900 + pax_set_fptr_mask
14901 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14902 + call pax_enter_kernel_user
14903 +#endif
14904 + .endm
14905 +
14906 + .macro pax_exit_kernel_user
14907 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14908 + call pax_exit_kernel_user
14909 +#endif
14910 +#ifdef CONFIG_PAX_RANDKSTACK
14911 + pushq %rax
14912 + call pax_randomize_kstack
14913 + popq %rax
14914 +#endif
14915 + .endm
14916 +
14917 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14918 +ENTRY(pax_enter_kernel_user)
14919 + pushq %rdi
14920 + pushq %rbx
14921 +
14922 +#ifdef CONFIG_PARAVIRT
14923 + PV_SAVE_REGS(CLBR_RDI)
14924 +#endif
14925 +
14926 + GET_CR3_INTO_RDI
14927 + mov %rdi,%rbx
14928 + add $__START_KERNEL_map,%rbx
14929 + sub phys_base(%rip),%rbx
14930 +
14931 +#ifdef CONFIG_PARAVIRT
14932 + pushq %rdi
14933 + cmpl $0, pv_info+PARAVIRT_enabled
14934 + jz 1f
14935 + i = 0
14936 + .rept USER_PGD_PTRS
14937 + mov i*8(%rbx),%rsi
14938 + mov $0,%sil
14939 + lea i*8(%rbx),%rdi
14940 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
14941 + i = i + 1
14942 + .endr
14943 + jmp 2f
14944 +1:
14945 +#endif
14946 +
14947 + i = 0
14948 + .rept USER_PGD_PTRS
14949 + movb $0,i*8(%rbx)
14950 + i = i + 1
14951 + .endr
14952 +
14953 +#ifdef CONFIG_PARAVIRT
14954 +2: popq %rdi
14955 +#endif
14956 + SET_RDI_INTO_CR3
14957 +
14958 +#ifdef CONFIG_PAX_KERNEXEC
14959 + GET_CR0_INTO_RDI
14960 + bts $16,%rdi
14961 + SET_RDI_INTO_CR0
14962 +#endif
14963 +
14964 +#ifdef CONFIG_PARAVIRT
14965 + PV_RESTORE_REGS(CLBR_RDI)
14966 +#endif
14967 +
14968 + popq %rbx
14969 + popq %rdi
14970 + pax_force_retaddr
14971 + retq
14972 +ENDPROC(pax_enter_kernel_user)
14973 +
14974 +ENTRY(pax_exit_kernel_user)
14975 + push %rdi
14976 +
14977 +#ifdef CONFIG_PARAVIRT
14978 + pushq %rbx
14979 + PV_SAVE_REGS(CLBR_RDI)
14980 +#endif
14981 +
14982 +#ifdef CONFIG_PAX_KERNEXEC
14983 + GET_CR0_INTO_RDI
14984 + btr $16,%rdi
14985 + SET_RDI_INTO_CR0
14986 +#endif
14987 +
14988 + GET_CR3_INTO_RDI
14989 + add $__START_KERNEL_map,%rdi
14990 + sub phys_base(%rip),%rdi
14991 +
14992 +#ifdef CONFIG_PARAVIRT
14993 + cmpl $0, pv_info+PARAVIRT_enabled
14994 + jz 1f
14995 + mov %rdi,%rbx
14996 + i = 0
14997 + .rept USER_PGD_PTRS
14998 + mov i*8(%rbx),%rsi
14999 + mov $0x67,%sil
15000 + lea i*8(%rbx),%rdi
15001 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15002 + i = i + 1
15003 + .endr
15004 + jmp 2f
15005 +1:
15006 +#endif
15007 +
15008 + i = 0
15009 + .rept USER_PGD_PTRS
15010 + movb $0x67,i*8(%rdi)
15011 + i = i + 1
15012 + .endr
15013 +
15014 +#ifdef CONFIG_PARAVIRT
15015 +2: PV_RESTORE_REGS(CLBR_RDI)
15016 + popq %rbx
15017 +#endif
15018 +
15019 + popq %rdi
15020 + pax_force_retaddr
15021 + retq
15022 +ENDPROC(pax_exit_kernel_user)
15023 +#endif
15024 +
15025 +.macro pax_erase_kstack
15026 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15027 + call pax_erase_kstack
15028 +#endif
15029 +.endm
15030 +
15031 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15032 +/*
15033 + * r11: thread_info
15034 + * rcx, rdx: can be clobbered
15035 + */
15036 +ENTRY(pax_erase_kstack)
15037 + pushq %rdi
15038 + pushq %rax
15039 + pushq %r11
15040 +
15041 + GET_THREAD_INFO(%r11)
15042 + mov TI_lowest_stack(%r11), %rdi
15043 + mov $-0xBEEF, %rax
15044 + std
15045 +
15046 +1: mov %edi, %ecx
15047 + and $THREAD_SIZE_asm - 1, %ecx
15048 + shr $3, %ecx
15049 + repne scasq
15050 + jecxz 2f
15051 +
15052 + cmp $2*8, %ecx
15053 + jc 2f
15054 +
15055 + mov $2*8, %ecx
15056 + repe scasq
15057 + jecxz 2f
15058 + jne 1b
15059 +
15060 +2: cld
15061 + mov %esp, %ecx
15062 + sub %edi, %ecx
15063 +
15064 + cmp $THREAD_SIZE_asm, %rcx
15065 + jb 3f
15066 + ud2
15067 +3:
15068 +
15069 + shr $3, %ecx
15070 + rep stosq
15071 +
15072 + mov TI_task_thread_sp0(%r11), %rdi
15073 + sub $256, %rdi
15074 + mov %rdi, TI_lowest_stack(%r11)
15075 +
15076 + popq %r11
15077 + popq %rax
15078 + popq %rdi
15079 + pax_force_retaddr
15080 + ret
15081 +ENDPROC(pax_erase_kstack)
15082 +#endif
15083
15084 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
15085 #ifdef CONFIG_TRACE_IRQFLAGS
15086 @@ -231,8 +515,8 @@ ENDPROC(native_usergs_sysret64)
15087 .endm
15088
15089 .macro UNFAKE_STACK_FRAME
15090 - addq $8*6, %rsp
15091 - CFI_ADJUST_CFA_OFFSET -(6*8)
15092 + addq $8*6 + ARG_SKIP, %rsp
15093 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
15094 .endm
15095
15096 /*
15097 @@ -319,7 +603,7 @@ ENDPROC(native_usergs_sysret64)
15098 movq %rsp, %rsi
15099
15100 leaq -RBP(%rsp),%rdi /* arg1 for handler */
15101 - testl $3, CS(%rdi)
15102 + testb $3, CS(%rdi)
15103 je 1f
15104 SWAPGS
15105 /*
15106 @@ -355,9 +639,10 @@ ENTRY(save_rest)
15107 movq_cfi r15, R15+16
15108 movq %r11, 8(%rsp) /* return address */
15109 FIXUP_TOP_OF_STACK %r11, 16
15110 + pax_force_retaddr
15111 ret
15112 CFI_ENDPROC
15113 -END(save_rest)
15114 +ENDPROC(save_rest)
15115
15116 /* save complete stack frame */
15117 .pushsection .kprobes.text, "ax"
15118 @@ -386,9 +671,10 @@ ENTRY(save_paranoid)
15119 js 1f /* negative -> in kernel */
15120 SWAPGS
15121 xorl %ebx,%ebx
15122 -1: ret
15123 +1: pax_force_retaddr_bts
15124 + ret
15125 CFI_ENDPROC
15126 -END(save_paranoid)
15127 +ENDPROC(save_paranoid)
15128 .popsection
15129
15130 /*
15131 @@ -410,7 +696,7 @@ ENTRY(ret_from_fork)
15132
15133 RESTORE_REST
15134
15135 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15136 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15137 je int_ret_from_sys_call
15138
15139 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
15140 @@ -420,7 +706,7 @@ ENTRY(ret_from_fork)
15141 jmp ret_from_sys_call # go to the SYSRET fastpath
15142
15143 CFI_ENDPROC
15144 -END(ret_from_fork)
15145 +ENDPROC(ret_from_fork)
15146
15147 /*
15148 * System call entry. Up to 6 arguments in registers are supported.
15149 @@ -456,7 +742,7 @@ END(ret_from_fork)
15150 ENTRY(system_call)
15151 CFI_STARTPROC simple
15152 CFI_SIGNAL_FRAME
15153 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15154 + CFI_DEF_CFA rsp,0
15155 CFI_REGISTER rip,rcx
15156 /*CFI_REGISTER rflags,r11*/
15157 SWAPGS_UNSAFE_STACK
15158 @@ -469,12 +755,13 @@ ENTRY(system_call_after_swapgs)
15159
15160 movq %rsp,PER_CPU_VAR(old_rsp)
15161 movq PER_CPU_VAR(kernel_stack),%rsp
15162 + SAVE_ARGS 8*6,0
15163 + pax_enter_kernel_user
15164 /*
15165 * No need to follow this irqs off/on section - it's straight
15166 * and short:
15167 */
15168 ENABLE_INTERRUPTS(CLBR_NONE)
15169 - SAVE_ARGS 8,0
15170 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15171 movq %rcx,RIP-ARGOFFSET(%rsp)
15172 CFI_REL_OFFSET rip,RIP-ARGOFFSET
15173 @@ -484,7 +771,7 @@ ENTRY(system_call_after_swapgs)
15174 system_call_fastpath:
15175 cmpq $__NR_syscall_max,%rax
15176 ja badsys
15177 - movq %r10,%rcx
15178 + movq R10-ARGOFFSET(%rsp),%rcx
15179 call *sys_call_table(,%rax,8) # XXX: rip relative
15180 movq %rax,RAX-ARGOFFSET(%rsp)
15181 /*
15182 @@ -503,6 +790,8 @@ sysret_check:
15183 andl %edi,%edx
15184 jnz sysret_careful
15185 CFI_REMEMBER_STATE
15186 + pax_exit_kernel_user
15187 + pax_erase_kstack
15188 /*
15189 * sysretq will re-enable interrupts:
15190 */
15191 @@ -554,14 +843,18 @@ badsys:
15192 * jump back to the normal fast path.
15193 */
15194 auditsys:
15195 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
15196 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
15197 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
15198 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
15199 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
15200 movq %rax,%rsi /* 2nd arg: syscall number */
15201 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
15202 call audit_syscall_entry
15203 +
15204 + pax_erase_kstack
15205 +
15206 LOAD_ARGS 0 /* reload call-clobbered registers */
15207 + pax_set_fptr_mask
15208 jmp system_call_fastpath
15209
15210 /*
15211 @@ -591,16 +884,20 @@ tracesys:
15212 FIXUP_TOP_OF_STACK %rdi
15213 movq %rsp,%rdi
15214 call syscall_trace_enter
15215 +
15216 + pax_erase_kstack
15217 +
15218 /*
15219 * Reload arg registers from stack in case ptrace changed them.
15220 * We don't reload %rax because syscall_trace_enter() returned
15221 * the value it wants us to use in the table lookup.
15222 */
15223 LOAD_ARGS ARGOFFSET, 1
15224 + pax_set_fptr_mask
15225 RESTORE_REST
15226 cmpq $__NR_syscall_max,%rax
15227 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
15228 - movq %r10,%rcx /* fixup for C */
15229 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
15230 call *sys_call_table(,%rax,8)
15231 movq %rax,RAX-ARGOFFSET(%rsp)
15232 /* Use IRET because user could have changed frame */
15233 @@ -612,7 +909,7 @@ tracesys:
15234 GLOBAL(int_ret_from_sys_call)
15235 DISABLE_INTERRUPTS(CLBR_NONE)
15236 TRACE_IRQS_OFF
15237 - testl $3,CS-ARGOFFSET(%rsp)
15238 + testb $3,CS-ARGOFFSET(%rsp)
15239 je retint_restore_args
15240 movl $_TIF_ALLWORK_MASK,%edi
15241 /* edi: mask to check */
15242 @@ -623,6 +920,7 @@ GLOBAL(int_with_check)
15243 andl %edi,%edx
15244 jnz int_careful
15245 andl $~TS_COMPAT,TI_status(%rcx)
15246 + pax_erase_kstack
15247 jmp retint_swapgs
15248
15249 /* Either reschedule or signal or syscall exit tracking needed. */
15250 @@ -669,7 +967,7 @@ int_restore_rest:
15251 TRACE_IRQS_OFF
15252 jmp int_with_check
15253 CFI_ENDPROC
15254 -END(system_call)
15255 +ENDPROC(system_call)
15256
15257 /*
15258 * Certain special system calls that need to save a complete full stack frame.
15259 @@ -685,7 +983,7 @@ ENTRY(\label)
15260 call \func
15261 jmp ptregscall_common
15262 CFI_ENDPROC
15263 -END(\label)
15264 +ENDPROC(\label)
15265 .endm
15266
15267 PTREGSCALL stub_clone, sys_clone, %r8
15268 @@ -703,9 +1001,10 @@ ENTRY(ptregscall_common)
15269 movq_cfi_restore R12+8, r12
15270 movq_cfi_restore RBP+8, rbp
15271 movq_cfi_restore RBX+8, rbx
15272 + pax_force_retaddr
15273 ret $REST_SKIP /* pop extended registers */
15274 CFI_ENDPROC
15275 -END(ptregscall_common)
15276 +ENDPROC(ptregscall_common)
15277
15278 ENTRY(stub_execve)
15279 CFI_STARTPROC
15280 @@ -720,7 +1019,7 @@ ENTRY(stub_execve)
15281 RESTORE_REST
15282 jmp int_ret_from_sys_call
15283 CFI_ENDPROC
15284 -END(stub_execve)
15285 +ENDPROC(stub_execve)
15286
15287 /*
15288 * sigreturn is special because it needs to restore all registers on return.
15289 @@ -738,7 +1037,7 @@ ENTRY(stub_rt_sigreturn)
15290 RESTORE_REST
15291 jmp int_ret_from_sys_call
15292 CFI_ENDPROC
15293 -END(stub_rt_sigreturn)
15294 +ENDPROC(stub_rt_sigreturn)
15295
15296 /*
15297 * Build the entry stubs and pointer table with some assembler magic.
15298 @@ -773,7 +1072,7 @@ vector=vector+1
15299 2: jmp common_interrupt
15300 .endr
15301 CFI_ENDPROC
15302 -END(irq_entries_start)
15303 +ENDPROC(irq_entries_start)
15304
15305 .previous
15306 END(interrupt)
15307 @@ -793,6 +1092,16 @@ END(interrupt)
15308 subq $ORIG_RAX-RBP, %rsp
15309 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
15310 SAVE_ARGS_IRQ
15311 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15312 + testb $3, CS(%rdi)
15313 + jnz 1f
15314 + pax_enter_kernel
15315 + jmp 2f
15316 +1: pax_enter_kernel_user
15317 +2:
15318 +#else
15319 + pax_enter_kernel
15320 +#endif
15321 call \func
15322 .endm
15323
15324 @@ -824,7 +1133,7 @@ ret_from_intr:
15325
15326 exit_intr:
15327 GET_THREAD_INFO(%rcx)
15328 - testl $3,CS-ARGOFFSET(%rsp)
15329 + testb $3,CS-ARGOFFSET(%rsp)
15330 je retint_kernel
15331
15332 /* Interrupt came from user space */
15333 @@ -846,12 +1155,15 @@ retint_swapgs: /* return to user-space */
15334 * The iretq could re-enable interrupts:
15335 */
15336 DISABLE_INTERRUPTS(CLBR_ANY)
15337 + pax_exit_kernel_user
15338 TRACE_IRQS_IRETQ
15339 SWAPGS
15340 jmp restore_args
15341
15342 retint_restore_args: /* return to kernel space */
15343 DISABLE_INTERRUPTS(CLBR_ANY)
15344 + pax_exit_kernel
15345 + pax_force_retaddr RIP-ARGOFFSET
15346 /*
15347 * The iretq could re-enable interrupts:
15348 */
15349 @@ -940,7 +1252,7 @@ ENTRY(retint_kernel)
15350 #endif
15351
15352 CFI_ENDPROC
15353 -END(common_interrupt)
15354 +ENDPROC(common_interrupt)
15355 /*
15356 * End of kprobes section
15357 */
15358 @@ -956,7 +1268,7 @@ ENTRY(\sym)
15359 interrupt \do_sym
15360 jmp ret_from_intr
15361 CFI_ENDPROC
15362 -END(\sym)
15363 +ENDPROC(\sym)
15364 .endm
15365
15366 #ifdef CONFIG_SMP
15367 @@ -1021,12 +1333,22 @@ ENTRY(\sym)
15368 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15369 call error_entry
15370 DEFAULT_FRAME 0
15371 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15372 + testb $3, CS(%rsp)
15373 + jnz 1f
15374 + pax_enter_kernel
15375 + jmp 2f
15376 +1: pax_enter_kernel_user
15377 +2:
15378 +#else
15379 + pax_enter_kernel
15380 +#endif
15381 movq %rsp,%rdi /* pt_regs pointer */
15382 xorl %esi,%esi /* no error code */
15383 call \do_sym
15384 jmp error_exit /* %ebx: no swapgs flag */
15385 CFI_ENDPROC
15386 -END(\sym)
15387 +ENDPROC(\sym)
15388 .endm
15389
15390 .macro paranoidzeroentry sym do_sym
15391 @@ -1038,15 +1360,25 @@ ENTRY(\sym)
15392 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15393 call save_paranoid
15394 TRACE_IRQS_OFF
15395 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15396 + testb $3, CS(%rsp)
15397 + jnz 1f
15398 + pax_enter_kernel
15399 + jmp 2f
15400 +1: pax_enter_kernel_user
15401 +2:
15402 +#else
15403 + pax_enter_kernel
15404 +#endif
15405 movq %rsp,%rdi /* pt_regs pointer */
15406 xorl %esi,%esi /* no error code */
15407 call \do_sym
15408 jmp paranoid_exit /* %ebx: no swapgs flag */
15409 CFI_ENDPROC
15410 -END(\sym)
15411 +ENDPROC(\sym)
15412 .endm
15413
15414 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
15415 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
15416 .macro paranoidzeroentry_ist sym do_sym ist
15417 ENTRY(\sym)
15418 INTR_FRAME
15419 @@ -1056,14 +1388,30 @@ ENTRY(\sym)
15420 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15421 call save_paranoid
15422 TRACE_IRQS_OFF
15423 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15424 + testb $3, CS(%rsp)
15425 + jnz 1f
15426 + pax_enter_kernel
15427 + jmp 2f
15428 +1: pax_enter_kernel_user
15429 +2:
15430 +#else
15431 + pax_enter_kernel
15432 +#endif
15433 movq %rsp,%rdi /* pt_regs pointer */
15434 xorl %esi,%esi /* no error code */
15435 +#ifdef CONFIG_SMP
15436 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
15437 + lea init_tss(%r12), %r12
15438 +#else
15439 + lea init_tss(%rip), %r12
15440 +#endif
15441 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
15442 call \do_sym
15443 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
15444 jmp paranoid_exit /* %ebx: no swapgs flag */
15445 CFI_ENDPROC
15446 -END(\sym)
15447 +ENDPROC(\sym)
15448 .endm
15449
15450 .macro errorentry sym do_sym
15451 @@ -1074,13 +1422,23 @@ ENTRY(\sym)
15452 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15453 call error_entry
15454 DEFAULT_FRAME 0
15455 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15456 + testb $3, CS(%rsp)
15457 + jnz 1f
15458 + pax_enter_kernel
15459 + jmp 2f
15460 +1: pax_enter_kernel_user
15461 +2:
15462 +#else
15463 + pax_enter_kernel
15464 +#endif
15465 movq %rsp,%rdi /* pt_regs pointer */
15466 movq ORIG_RAX(%rsp),%rsi /* get error code */
15467 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15468 call \do_sym
15469 jmp error_exit /* %ebx: no swapgs flag */
15470 CFI_ENDPROC
15471 -END(\sym)
15472 +ENDPROC(\sym)
15473 .endm
15474
15475 /* error code is on the stack already */
15476 @@ -1093,13 +1451,23 @@ ENTRY(\sym)
15477 call save_paranoid
15478 DEFAULT_FRAME 0
15479 TRACE_IRQS_OFF
15480 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15481 + testb $3, CS(%rsp)
15482 + jnz 1f
15483 + pax_enter_kernel
15484 + jmp 2f
15485 +1: pax_enter_kernel_user
15486 +2:
15487 +#else
15488 + pax_enter_kernel
15489 +#endif
15490 movq %rsp,%rdi /* pt_regs pointer */
15491 movq ORIG_RAX(%rsp),%rsi /* get error code */
15492 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15493 call \do_sym
15494 jmp paranoid_exit /* %ebx: no swapgs flag */
15495 CFI_ENDPROC
15496 -END(\sym)
15497 +ENDPROC(\sym)
15498 .endm
15499
15500 zeroentry divide_error do_divide_error
15501 @@ -1129,9 +1497,10 @@ gs_change:
15502 2: mfence /* workaround */
15503 SWAPGS
15504 popfq_cfi
15505 + pax_force_retaddr
15506 ret
15507 CFI_ENDPROC
15508 -END(native_load_gs_index)
15509 +ENDPROC(native_load_gs_index)
15510
15511 .section __ex_table,"a"
15512 .align 8
15513 @@ -1153,13 +1522,14 @@ ENTRY(kernel_thread_helper)
15514 * Here we are in the child and the registers are set as they were
15515 * at kernel_thread() invocation in the parent.
15516 */
15517 + pax_force_fptr %rsi
15518 call *%rsi
15519 # exit
15520 mov %eax, %edi
15521 call do_exit
15522 ud2 # padding for call trace
15523 CFI_ENDPROC
15524 -END(kernel_thread_helper)
15525 +ENDPROC(kernel_thread_helper)
15526
15527 /*
15528 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
15529 @@ -1186,11 +1556,11 @@ ENTRY(kernel_execve)
15530 RESTORE_REST
15531 testq %rax,%rax
15532 je int_ret_from_sys_call
15533 - RESTORE_ARGS
15534 UNFAKE_STACK_FRAME
15535 + pax_force_retaddr
15536 ret
15537 CFI_ENDPROC
15538 -END(kernel_execve)
15539 +ENDPROC(kernel_execve)
15540
15541 /* Call softirq on interrupt stack. Interrupts are off. */
15542 ENTRY(call_softirq)
15543 @@ -1208,9 +1578,10 @@ ENTRY(call_softirq)
15544 CFI_DEF_CFA_REGISTER rsp
15545 CFI_ADJUST_CFA_OFFSET -8
15546 decl PER_CPU_VAR(irq_count)
15547 + pax_force_retaddr
15548 ret
15549 CFI_ENDPROC
15550 -END(call_softirq)
15551 +ENDPROC(call_softirq)
15552
15553 #ifdef CONFIG_XEN
15554 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
15555 @@ -1248,7 +1619,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
15556 decl PER_CPU_VAR(irq_count)
15557 jmp error_exit
15558 CFI_ENDPROC
15559 -END(xen_do_hypervisor_callback)
15560 +ENDPROC(xen_do_hypervisor_callback)
15561
15562 /*
15563 * Hypervisor uses this for application faults while it executes.
15564 @@ -1307,7 +1678,7 @@ ENTRY(xen_failsafe_callback)
15565 SAVE_ALL
15566 jmp error_exit
15567 CFI_ENDPROC
15568 -END(xen_failsafe_callback)
15569 +ENDPROC(xen_failsafe_callback)
15570
15571 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
15572 xen_hvm_callback_vector xen_evtchn_do_upcall
15573 @@ -1356,16 +1727,31 @@ ENTRY(paranoid_exit)
15574 TRACE_IRQS_OFF
15575 testl %ebx,%ebx /* swapgs needed? */
15576 jnz paranoid_restore
15577 - testl $3,CS(%rsp)
15578 + testb $3,CS(%rsp)
15579 jnz paranoid_userspace
15580 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15581 + pax_exit_kernel
15582 + TRACE_IRQS_IRETQ 0
15583 + SWAPGS_UNSAFE_STACK
15584 + RESTORE_ALL 8
15585 + pax_force_retaddr_bts
15586 + jmp irq_return
15587 +#endif
15588 paranoid_swapgs:
15589 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15590 + pax_exit_kernel_user
15591 +#else
15592 + pax_exit_kernel
15593 +#endif
15594 TRACE_IRQS_IRETQ 0
15595 SWAPGS_UNSAFE_STACK
15596 RESTORE_ALL 8
15597 jmp irq_return
15598 paranoid_restore:
15599 + pax_exit_kernel
15600 TRACE_IRQS_IRETQ 0
15601 RESTORE_ALL 8
15602 + pax_force_retaddr_bts
15603 jmp irq_return
15604 paranoid_userspace:
15605 GET_THREAD_INFO(%rcx)
15606 @@ -1394,7 +1780,7 @@ paranoid_schedule:
15607 TRACE_IRQS_OFF
15608 jmp paranoid_userspace
15609 CFI_ENDPROC
15610 -END(paranoid_exit)
15611 +ENDPROC(paranoid_exit)
15612
15613 /*
15614 * Exception entry point. This expects an error code/orig_rax on the stack.
15615 @@ -1421,12 +1807,13 @@ ENTRY(error_entry)
15616 movq_cfi r14, R14+8
15617 movq_cfi r15, R15+8
15618 xorl %ebx,%ebx
15619 - testl $3,CS+8(%rsp)
15620 + testb $3,CS+8(%rsp)
15621 je error_kernelspace
15622 error_swapgs:
15623 SWAPGS
15624 error_sti:
15625 TRACE_IRQS_OFF
15626 + pax_force_retaddr_bts
15627 ret
15628
15629 /*
15630 @@ -1453,7 +1840,7 @@ bstep_iret:
15631 movq %rcx,RIP+8(%rsp)
15632 jmp error_swapgs
15633 CFI_ENDPROC
15634 -END(error_entry)
15635 +ENDPROC(error_entry)
15636
15637
15638 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
15639 @@ -1473,7 +1860,7 @@ ENTRY(error_exit)
15640 jnz retint_careful
15641 jmp retint_swapgs
15642 CFI_ENDPROC
15643 -END(error_exit)
15644 +ENDPROC(error_exit)
15645
15646
15647 /* runs on exception stack */
15648 @@ -1485,6 +1872,16 @@ ENTRY(nmi)
15649 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15650 call save_paranoid
15651 DEFAULT_FRAME 0
15652 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15653 + testb $3, CS(%rsp)
15654 + jnz 1f
15655 + pax_enter_kernel
15656 + jmp 2f
15657 +1: pax_enter_kernel_user
15658 +2:
15659 +#else
15660 + pax_enter_kernel
15661 +#endif
15662 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
15663 movq %rsp,%rdi
15664 movq $-1,%rsi
15665 @@ -1495,12 +1892,28 @@ ENTRY(nmi)
15666 DISABLE_INTERRUPTS(CLBR_NONE)
15667 testl %ebx,%ebx /* swapgs needed? */
15668 jnz nmi_restore
15669 - testl $3,CS(%rsp)
15670 + testb $3,CS(%rsp)
15671 jnz nmi_userspace
15672 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15673 + pax_exit_kernel
15674 + SWAPGS_UNSAFE_STACK
15675 + RESTORE_ALL 8
15676 + pax_force_retaddr_bts
15677 + jmp irq_return
15678 +#endif
15679 nmi_swapgs:
15680 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15681 + pax_exit_kernel_user
15682 +#else
15683 + pax_exit_kernel
15684 +#endif
15685 SWAPGS_UNSAFE_STACK
15686 + RESTORE_ALL 8
15687 + jmp irq_return
15688 nmi_restore:
15689 + pax_exit_kernel
15690 RESTORE_ALL 8
15691 + pax_force_retaddr_bts
15692 jmp irq_return
15693 nmi_userspace:
15694 GET_THREAD_INFO(%rcx)
15695 @@ -1529,14 +1942,14 @@ nmi_schedule:
15696 jmp paranoid_exit
15697 CFI_ENDPROC
15698 #endif
15699 -END(nmi)
15700 +ENDPROC(nmi)
15701
15702 ENTRY(ignore_sysret)
15703 CFI_STARTPROC
15704 mov $-ENOSYS,%eax
15705 sysret
15706 CFI_ENDPROC
15707 -END(ignore_sysret)
15708 +ENDPROC(ignore_sysret)
15709
15710 /*
15711 * End of kprobes section
15712 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
15713 index c9a281f..ce2f317 100644
15714 --- a/arch/x86/kernel/ftrace.c
15715 +++ b/arch/x86/kernel/ftrace.c
15716 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
15717 static const void *mod_code_newcode; /* holds the text to write to the IP */
15718
15719 static unsigned nmi_wait_count;
15720 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
15721 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
15722
15723 int ftrace_arch_read_dyn_info(char *buf, int size)
15724 {
15725 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
15726
15727 r = snprintf(buf, size, "%u %u",
15728 nmi_wait_count,
15729 - atomic_read(&nmi_update_count));
15730 + atomic_read_unchecked(&nmi_update_count));
15731 return r;
15732 }
15733
15734 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
15735
15736 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
15737 smp_rmb();
15738 + pax_open_kernel();
15739 ftrace_mod_code();
15740 - atomic_inc(&nmi_update_count);
15741 + pax_close_kernel();
15742 + atomic_inc_unchecked(&nmi_update_count);
15743 }
15744 /* Must have previous changes seen before executions */
15745 smp_mb();
15746 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
15747 {
15748 unsigned char replaced[MCOUNT_INSN_SIZE];
15749
15750 + ip = ktla_ktva(ip);
15751 +
15752 /*
15753 * Note: Due to modules and __init, code can
15754 * disappear and change, we need to protect against faulting
15755 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
15756 unsigned char old[MCOUNT_INSN_SIZE], *new;
15757 int ret;
15758
15759 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
15760 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
15761 new = ftrace_call_replace(ip, (unsigned long)func);
15762 ret = ftrace_modify_code(ip, old, new);
15763
15764 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
15765 {
15766 unsigned char code[MCOUNT_INSN_SIZE];
15767
15768 + ip = ktla_ktva(ip);
15769 +
15770 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
15771 return -EFAULT;
15772
15773 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
15774 index 3bb0850..55a56f4 100644
15775 --- a/arch/x86/kernel/head32.c
15776 +++ b/arch/x86/kernel/head32.c
15777 @@ -19,6 +19,7 @@
15778 #include <asm/io_apic.h>
15779 #include <asm/bios_ebda.h>
15780 #include <asm/tlbflush.h>
15781 +#include <asm/boot.h>
15782
15783 static void __init i386_default_early_setup(void)
15784 {
15785 @@ -33,7 +34,7 @@ void __init i386_start_kernel(void)
15786 {
15787 memblock_init();
15788
15789 - memblock_x86_reserve_range(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
15790 + memblock_x86_reserve_range(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
15791
15792 #ifdef CONFIG_BLK_DEV_INITRD
15793 /* Reserve INITRD */
15794 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
15795 index ce0be7c..c41476e 100644
15796 --- a/arch/x86/kernel/head_32.S
15797 +++ b/arch/x86/kernel/head_32.S
15798 @@ -25,6 +25,12 @@
15799 /* Physical address */
15800 #define pa(X) ((X) - __PAGE_OFFSET)
15801
15802 +#ifdef CONFIG_PAX_KERNEXEC
15803 +#define ta(X) (X)
15804 +#else
15805 +#define ta(X) ((X) - __PAGE_OFFSET)
15806 +#endif
15807 +
15808 /*
15809 * References to members of the new_cpu_data structure.
15810 */
15811 @@ -54,11 +60,7 @@
15812 * and small than max_low_pfn, otherwise will waste some page table entries
15813 */
15814
15815 -#if PTRS_PER_PMD > 1
15816 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
15817 -#else
15818 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
15819 -#endif
15820 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
15821
15822 /* Number of possible pages in the lowmem region */
15823 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
15824 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
15825 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
15826
15827 /*
15828 + * Real beginning of normal "text" segment
15829 + */
15830 +ENTRY(stext)
15831 +ENTRY(_stext)
15832 +
15833 +/*
15834 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
15835 * %esi points to the real-mode code as a 32-bit pointer.
15836 * CS and DS must be 4 GB flat segments, but we don't depend on
15837 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
15838 * can.
15839 */
15840 __HEAD
15841 +
15842 +#ifdef CONFIG_PAX_KERNEXEC
15843 + jmp startup_32
15844 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
15845 +.fill PAGE_SIZE-5,1,0xcc
15846 +#endif
15847 +
15848 ENTRY(startup_32)
15849 movl pa(stack_start),%ecx
15850
15851 @@ -105,6 +120,57 @@ ENTRY(startup_32)
15852 2:
15853 leal -__PAGE_OFFSET(%ecx),%esp
15854
15855 +#ifdef CONFIG_SMP
15856 + movl $pa(cpu_gdt_table),%edi
15857 + movl $__per_cpu_load,%eax
15858 + movw %ax,__KERNEL_PERCPU + 2(%edi)
15859 + rorl $16,%eax
15860 + movb %al,__KERNEL_PERCPU + 4(%edi)
15861 + movb %ah,__KERNEL_PERCPU + 7(%edi)
15862 + movl $__per_cpu_end - 1,%eax
15863 + subl $__per_cpu_start,%eax
15864 + movw %ax,__KERNEL_PERCPU + 0(%edi)
15865 +#endif
15866 +
15867 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15868 + movl $NR_CPUS,%ecx
15869 + movl $pa(cpu_gdt_table),%edi
15870 +1:
15871 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
15872 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
15873 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
15874 + addl $PAGE_SIZE_asm,%edi
15875 + loop 1b
15876 +#endif
15877 +
15878 +#ifdef CONFIG_PAX_KERNEXEC
15879 + movl $pa(boot_gdt),%edi
15880 + movl $__LOAD_PHYSICAL_ADDR,%eax
15881 + movw %ax,__BOOT_CS + 2(%edi)
15882 + rorl $16,%eax
15883 + movb %al,__BOOT_CS + 4(%edi)
15884 + movb %ah,__BOOT_CS + 7(%edi)
15885 + rorl $16,%eax
15886 +
15887 + ljmp $(__BOOT_CS),$1f
15888 +1:
15889 +
15890 + movl $NR_CPUS,%ecx
15891 + movl $pa(cpu_gdt_table),%edi
15892 + addl $__PAGE_OFFSET,%eax
15893 +1:
15894 + movw %ax,__KERNEL_CS + 2(%edi)
15895 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
15896 + rorl $16,%eax
15897 + movb %al,__KERNEL_CS + 4(%edi)
15898 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
15899 + movb %ah,__KERNEL_CS + 7(%edi)
15900 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
15901 + rorl $16,%eax
15902 + addl $PAGE_SIZE_asm,%edi
15903 + loop 1b
15904 +#endif
15905 +
15906 /*
15907 * Clear BSS first so that there are no surprises...
15908 */
15909 @@ -195,8 +261,11 @@ ENTRY(startup_32)
15910 movl %eax, pa(max_pfn_mapped)
15911
15912 /* Do early initialization of the fixmap area */
15913 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
15914 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
15915 +#ifdef CONFIG_COMPAT_VDSO
15916 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
15917 +#else
15918 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
15919 +#endif
15920 #else /* Not PAE */
15921
15922 page_pde_offset = (__PAGE_OFFSET >> 20);
15923 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
15924 movl %eax, pa(max_pfn_mapped)
15925
15926 /* Do early initialization of the fixmap area */
15927 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
15928 - movl %eax,pa(initial_page_table+0xffc)
15929 +#ifdef CONFIG_COMPAT_VDSO
15930 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
15931 +#else
15932 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
15933 +#endif
15934 #endif
15935
15936 #ifdef CONFIG_PARAVIRT
15937 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
15938 cmpl $num_subarch_entries, %eax
15939 jae bad_subarch
15940
15941 - movl pa(subarch_entries)(,%eax,4), %eax
15942 - subl $__PAGE_OFFSET, %eax
15943 - jmp *%eax
15944 + jmp *pa(subarch_entries)(,%eax,4)
15945
15946 bad_subarch:
15947 WEAK(lguest_entry)
15948 @@ -255,10 +325,10 @@ WEAK(xen_entry)
15949 __INITDATA
15950
15951 subarch_entries:
15952 - .long default_entry /* normal x86/PC */
15953 - .long lguest_entry /* lguest hypervisor */
15954 - .long xen_entry /* Xen hypervisor */
15955 - .long default_entry /* Moorestown MID */
15956 + .long ta(default_entry) /* normal x86/PC */
15957 + .long ta(lguest_entry) /* lguest hypervisor */
15958 + .long ta(xen_entry) /* Xen hypervisor */
15959 + .long ta(default_entry) /* Moorestown MID */
15960 num_subarch_entries = (. - subarch_entries) / 4
15961 .previous
15962 #else
15963 @@ -312,6 +382,7 @@ default_entry:
15964 orl %edx,%eax
15965 movl %eax,%cr4
15966
15967 +#ifdef CONFIG_X86_PAE
15968 testb $X86_CR4_PAE, %al # check if PAE is enabled
15969 jz 6f
15970
15971 @@ -340,6 +411,9 @@ default_entry:
15972 /* Make changes effective */
15973 wrmsr
15974
15975 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
15976 +#endif
15977 +
15978 6:
15979
15980 /*
15981 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
15982 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
15983 movl %eax,%ss # after changing gdt.
15984
15985 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
15986 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
15987 movl %eax,%ds
15988 movl %eax,%es
15989
15990 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
15991 */
15992 cmpb $0,ready
15993 jne 1f
15994 - movl $gdt_page,%eax
15995 + movl $cpu_gdt_table,%eax
15996 movl $stack_canary,%ecx
15997 +#ifdef CONFIG_SMP
15998 + addl $__per_cpu_load,%ecx
15999 +#endif
16000 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16001 shrl $16, %ecx
16002 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16003 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
16004 1:
16005 -#endif
16006 movl $(__KERNEL_STACK_CANARY),%eax
16007 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16008 + movl $(__USER_DS),%eax
16009 +#else
16010 + xorl %eax,%eax
16011 +#endif
16012 movl %eax,%gs
16013
16014 xorl %eax,%eax # Clear LDT
16015 @@ -558,22 +639,22 @@ early_page_fault:
16016 jmp early_fault
16017
16018 early_fault:
16019 - cld
16020 #ifdef CONFIG_PRINTK
16021 + cmpl $1,%ss:early_recursion_flag
16022 + je hlt_loop
16023 + incl %ss:early_recursion_flag
16024 + cld
16025 pusha
16026 movl $(__KERNEL_DS),%eax
16027 movl %eax,%ds
16028 movl %eax,%es
16029 - cmpl $2,early_recursion_flag
16030 - je hlt_loop
16031 - incl early_recursion_flag
16032 movl %cr2,%eax
16033 pushl %eax
16034 pushl %edx /* trapno */
16035 pushl $fault_msg
16036 call printk
16037 +; call dump_stack
16038 #endif
16039 - call dump_stack
16040 hlt_loop:
16041 hlt
16042 jmp hlt_loop
16043 @@ -581,8 +662,11 @@ hlt_loop:
16044 /* This is the default interrupt "handler" :-) */
16045 ALIGN
16046 ignore_int:
16047 - cld
16048 #ifdef CONFIG_PRINTK
16049 + cmpl $2,%ss:early_recursion_flag
16050 + je hlt_loop
16051 + incl %ss:early_recursion_flag
16052 + cld
16053 pushl %eax
16054 pushl %ecx
16055 pushl %edx
16056 @@ -591,9 +675,6 @@ ignore_int:
16057 movl $(__KERNEL_DS),%eax
16058 movl %eax,%ds
16059 movl %eax,%es
16060 - cmpl $2,early_recursion_flag
16061 - je hlt_loop
16062 - incl early_recursion_flag
16063 pushl 16(%esp)
16064 pushl 24(%esp)
16065 pushl 32(%esp)
16066 @@ -622,29 +703,43 @@ ENTRY(initial_code)
16067 /*
16068 * BSS section
16069 */
16070 -__PAGE_ALIGNED_BSS
16071 - .align PAGE_SIZE
16072 #ifdef CONFIG_X86_PAE
16073 +.section .initial_pg_pmd,"a",@progbits
16074 initial_pg_pmd:
16075 .fill 1024*KPMDS,4,0
16076 #else
16077 +.section .initial_page_table,"a",@progbits
16078 ENTRY(initial_page_table)
16079 .fill 1024,4,0
16080 #endif
16081 +.section .initial_pg_fixmap,"a",@progbits
16082 initial_pg_fixmap:
16083 .fill 1024,4,0
16084 +.section .empty_zero_page,"a",@progbits
16085 ENTRY(empty_zero_page)
16086 .fill 4096,1,0
16087 +.section .swapper_pg_dir,"a",@progbits
16088 ENTRY(swapper_pg_dir)
16089 +#ifdef CONFIG_X86_PAE
16090 + .fill 4,8,0
16091 +#else
16092 .fill 1024,4,0
16093 +#endif
16094 +
16095 +/*
16096 + * The IDT has to be page-aligned to simplify the Pentium
16097 + * F0 0F bug workaround.. We have a special link segment
16098 + * for this.
16099 + */
16100 +.section .idt,"a",@progbits
16101 +ENTRY(idt_table)
16102 + .fill 256,8,0
16103
16104 /*
16105 * This starts the data section.
16106 */
16107 #ifdef CONFIG_X86_PAE
16108 -__PAGE_ALIGNED_DATA
16109 - /* Page-aligned for the benefit of paravirt? */
16110 - .align PAGE_SIZE
16111 +.section .initial_page_table,"a",@progbits
16112 ENTRY(initial_page_table)
16113 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
16114 # if KPMDS == 3
16115 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
16116 # error "Kernel PMDs should be 1, 2 or 3"
16117 # endif
16118 .align PAGE_SIZE /* needs to be page-sized too */
16119 +
16120 +#ifdef CONFIG_PAX_PER_CPU_PGD
16121 +ENTRY(cpu_pgd)
16122 + .rept NR_CPUS
16123 + .fill 4,8,0
16124 + .endr
16125 +#endif
16126 +
16127 #endif
16128
16129 .data
16130 .balign 4
16131 ENTRY(stack_start)
16132 - .long init_thread_union+THREAD_SIZE
16133 + .long init_thread_union+THREAD_SIZE-8
16134
16135 +ready: .byte 0
16136 +
16137 +.section .rodata,"a",@progbits
16138 early_recursion_flag:
16139 .long 0
16140
16141 -ready: .byte 0
16142 -
16143 int_msg:
16144 .asciz "Unknown interrupt or fault at: %p %p %p\n"
16145
16146 @@ -707,7 +811,7 @@ fault_msg:
16147 .word 0 # 32 bit align gdt_desc.address
16148 boot_gdt_descr:
16149 .word __BOOT_DS+7
16150 - .long boot_gdt - __PAGE_OFFSET
16151 + .long pa(boot_gdt)
16152
16153 .word 0 # 32-bit align idt_desc.address
16154 idt_descr:
16155 @@ -718,7 +822,7 @@ idt_descr:
16156 .word 0 # 32 bit align gdt_desc.address
16157 ENTRY(early_gdt_descr)
16158 .word GDT_ENTRIES*8-1
16159 - .long gdt_page /* Overwritten for secondary CPUs */
16160 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
16161
16162 /*
16163 * The boot_gdt must mirror the equivalent in setup.S and is
16164 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
16165 .align L1_CACHE_BYTES
16166 ENTRY(boot_gdt)
16167 .fill GDT_ENTRY_BOOT_CS,8,0
16168 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
16169 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
16170 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
16171 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
16172 +
16173 + .align PAGE_SIZE_asm
16174 +ENTRY(cpu_gdt_table)
16175 + .rept NR_CPUS
16176 + .quad 0x0000000000000000 /* NULL descriptor */
16177 + .quad 0x0000000000000000 /* 0x0b reserved */
16178 + .quad 0x0000000000000000 /* 0x13 reserved */
16179 + .quad 0x0000000000000000 /* 0x1b reserved */
16180 +
16181 +#ifdef CONFIG_PAX_KERNEXEC
16182 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
16183 +#else
16184 + .quad 0x0000000000000000 /* 0x20 unused */
16185 +#endif
16186 +
16187 + .quad 0x0000000000000000 /* 0x28 unused */
16188 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
16189 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
16190 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
16191 + .quad 0x0000000000000000 /* 0x4b reserved */
16192 + .quad 0x0000000000000000 /* 0x53 reserved */
16193 + .quad 0x0000000000000000 /* 0x5b reserved */
16194 +
16195 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
16196 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
16197 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
16198 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
16199 +
16200 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
16201 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
16202 +
16203 + /*
16204 + * Segments used for calling PnP BIOS have byte granularity.
16205 + * The code segments and data segments have fixed 64k limits,
16206 + * the transfer segment sizes are set at run time.
16207 + */
16208 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
16209 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
16210 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
16211 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
16212 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
16213 +
16214 + /*
16215 + * The APM segments have byte granularity and their bases
16216 + * are set at run time. All have 64k limits.
16217 + */
16218 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
16219 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
16220 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
16221 +
16222 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
16223 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
16224 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
16225 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
16226 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
16227 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
16228 +
16229 + /* Be sure this is zeroed to avoid false validations in Xen */
16230 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
16231 + .endr
16232 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
16233 index e11e394..9aebc5d 100644
16234 --- a/arch/x86/kernel/head_64.S
16235 +++ b/arch/x86/kernel/head_64.S
16236 @@ -19,6 +19,8 @@
16237 #include <asm/cache.h>
16238 #include <asm/processor-flags.h>
16239 #include <asm/percpu.h>
16240 +#include <asm/cpufeature.h>
16241 +#include <asm/alternative-asm.h>
16242
16243 #ifdef CONFIG_PARAVIRT
16244 #include <asm/asm-offsets.h>
16245 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
16246 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
16247 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
16248 L3_START_KERNEL = pud_index(__START_KERNEL_map)
16249 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
16250 +L3_VMALLOC_START = pud_index(VMALLOC_START)
16251 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
16252 +L3_VMALLOC_END = pud_index(VMALLOC_END)
16253 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
16254 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
16255
16256 .text
16257 __HEAD
16258 @@ -85,35 +93,23 @@ startup_64:
16259 */
16260 addq %rbp, init_level4_pgt + 0(%rip)
16261 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
16262 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
16263 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
16264 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
16265 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
16266
16267 addq %rbp, level3_ident_pgt + 0(%rip)
16268 +#ifndef CONFIG_XEN
16269 + addq %rbp, level3_ident_pgt + 8(%rip)
16270 +#endif
16271
16272 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
16273 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
16274 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
16275 +
16276 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
16277 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
16278
16279 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
16280 -
16281 - /* Add an Identity mapping if I am above 1G */
16282 - leaq _text(%rip), %rdi
16283 - andq $PMD_PAGE_MASK, %rdi
16284 -
16285 - movq %rdi, %rax
16286 - shrq $PUD_SHIFT, %rax
16287 - andq $(PTRS_PER_PUD - 1), %rax
16288 - jz ident_complete
16289 -
16290 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
16291 - leaq level3_ident_pgt(%rip), %rbx
16292 - movq %rdx, 0(%rbx, %rax, 8)
16293 -
16294 - movq %rdi, %rax
16295 - shrq $PMD_SHIFT, %rax
16296 - andq $(PTRS_PER_PMD - 1), %rax
16297 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
16298 - leaq level2_spare_pgt(%rip), %rbx
16299 - movq %rdx, 0(%rbx, %rax, 8)
16300 -ident_complete:
16301 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
16302
16303 /*
16304 * Fixup the kernel text+data virtual addresses. Note that
16305 @@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
16306 * after the boot processor executes this code.
16307 */
16308
16309 - /* Enable PAE mode and PGE */
16310 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
16311 + /* Enable PAE mode and PSE/PGE */
16312 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
16313 movq %rax, %cr4
16314
16315 /* Setup early boot stage 4 level pagetables. */
16316 @@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
16317 movl $MSR_EFER, %ecx
16318 rdmsr
16319 btsl $_EFER_SCE, %eax /* Enable System Call */
16320 - btl $20,%edi /* No Execute supported? */
16321 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
16322 jnc 1f
16323 btsl $_EFER_NX, %eax
16324 + leaq init_level4_pgt(%rip), %rdi
16325 +#ifndef CONFIG_EFI
16326 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
16327 +#endif
16328 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
16329 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
16330 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
16331 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
16332 1: wrmsr /* Make changes effective */
16333
16334 /* Setup cr0 */
16335 @@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
16336 * jump. In addition we need to ensure %cs is set so we make this
16337 * a far return.
16338 */
16339 + pax_set_fptr_mask
16340 movq initial_code(%rip),%rax
16341 pushq $0 # fake return address to stop unwinder
16342 pushq $__KERNEL_CS # set correct cs
16343 @@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
16344 bad_address:
16345 jmp bad_address
16346
16347 - .section ".init.text","ax"
16348 + __INIT
16349 #ifdef CONFIG_EARLY_PRINTK
16350 .globl early_idt_handlers
16351 early_idt_handlers:
16352 @@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
16353 #endif /* EARLY_PRINTK */
16354 1: hlt
16355 jmp 1b
16356 + .previous
16357
16358 #ifdef CONFIG_EARLY_PRINTK
16359 + __INITDATA
16360 early_recursion_flag:
16361 .long 0
16362 + .previous
16363
16364 + .section .rodata,"a",@progbits
16365 early_idt_msg:
16366 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
16367 early_idt_ripmsg:
16368 .asciz "RIP %s\n"
16369 + .previous
16370 #endif /* CONFIG_EARLY_PRINTK */
16371 - .previous
16372
16373 + .section .rodata,"a",@progbits
16374 #define NEXT_PAGE(name) \
16375 .balign PAGE_SIZE; \
16376 ENTRY(name)
16377 @@ -338,7 +348,6 @@ ENTRY(name)
16378 i = i + 1 ; \
16379 .endr
16380
16381 - .data
16382 /*
16383 * This default setting generates an ident mapping at address 0x100000
16384 * and a mapping for the kernel that precisely maps virtual address
16385 @@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
16386 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16387 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
16388 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16389 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
16390 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
16391 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
16392 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
16393 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
16394 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
16395 .org init_level4_pgt + L4_START_KERNEL*8, 0
16396 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
16397 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
16398
16399 +#ifdef CONFIG_PAX_PER_CPU_PGD
16400 +NEXT_PAGE(cpu_pgd)
16401 + .rept NR_CPUS
16402 + .fill 512,8,0
16403 + .endr
16404 +#endif
16405 +
16406 NEXT_PAGE(level3_ident_pgt)
16407 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16408 +#ifdef CONFIG_XEN
16409 .fill 511,8,0
16410 +#else
16411 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
16412 + .fill 510,8,0
16413 +#endif
16414 +
16415 +NEXT_PAGE(level3_vmalloc_start_pgt)
16416 + .fill 512,8,0
16417 +
16418 +NEXT_PAGE(level3_vmalloc_end_pgt)
16419 + .fill 512,8,0
16420 +
16421 +NEXT_PAGE(level3_vmemmap_pgt)
16422 + .fill L3_VMEMMAP_START,8,0
16423 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
16424
16425 NEXT_PAGE(level3_kernel_pgt)
16426 .fill L3_START_KERNEL,8,0
16427 @@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
16428 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
16429 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16430
16431 +NEXT_PAGE(level2_vmemmap_pgt)
16432 + .fill 512,8,0
16433 +
16434 NEXT_PAGE(level2_fixmap_pgt)
16435 - .fill 506,8,0
16436 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16437 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
16438 - .fill 5,8,0
16439 + .fill 507,8,0
16440 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
16441 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
16442 + .fill 4,8,0
16443
16444 -NEXT_PAGE(level1_fixmap_pgt)
16445 +NEXT_PAGE(level1_vsyscall_pgt)
16446 .fill 512,8,0
16447
16448 -NEXT_PAGE(level2_ident_pgt)
16449 - /* Since I easily can, map the first 1G.
16450 + /* Since I easily can, map the first 2G.
16451 * Don't set NX because code runs from these pages.
16452 */
16453 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
16454 +NEXT_PAGE(level2_ident_pgt)
16455 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
16456
16457 NEXT_PAGE(level2_kernel_pgt)
16458 /*
16459 @@ -389,33 +429,55 @@ NEXT_PAGE(level2_kernel_pgt)
16460 * If you want to increase this then increase MODULES_VADDR
16461 * too.)
16462 */
16463 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
16464 - KERNEL_IMAGE_SIZE/PMD_SIZE)
16465 -
16466 -NEXT_PAGE(level2_spare_pgt)
16467 - .fill 512, 8, 0
16468 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
16469
16470 #undef PMDS
16471 #undef NEXT_PAGE
16472
16473 - .data
16474 + .align PAGE_SIZE
16475 +ENTRY(cpu_gdt_table)
16476 + .rept NR_CPUS
16477 + .quad 0x0000000000000000 /* NULL descriptor */
16478 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
16479 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
16480 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
16481 + .quad 0x00cffb000000ffff /* __USER32_CS */
16482 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
16483 + .quad 0x00affb000000ffff /* __USER_CS */
16484 +
16485 +#ifdef CONFIG_PAX_KERNEXEC
16486 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
16487 +#else
16488 + .quad 0x0 /* unused */
16489 +#endif
16490 +
16491 + .quad 0,0 /* TSS */
16492 + .quad 0,0 /* LDT */
16493 + .quad 0,0,0 /* three TLS descriptors */
16494 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
16495 + /* asm/segment.h:GDT_ENTRIES must match this */
16496 +
16497 + /* zero the remaining page */
16498 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
16499 + .endr
16500 +
16501 .align 16
16502 .globl early_gdt_descr
16503 early_gdt_descr:
16504 .word GDT_ENTRIES*8-1
16505 early_gdt_descr_base:
16506 - .quad INIT_PER_CPU_VAR(gdt_page)
16507 + .quad cpu_gdt_table
16508
16509 ENTRY(phys_base)
16510 /* This must match the first entry in level2_kernel_pgt */
16511 .quad 0x0000000000000000
16512
16513 #include "../../x86/xen/xen-head.S"
16514 -
16515 - .section .bss, "aw", @nobits
16516 +
16517 + .section .rodata,"a",@progbits
16518 .align L1_CACHE_BYTES
16519 ENTRY(idt_table)
16520 - .skip IDT_ENTRIES * 16
16521 + .fill 512,8,0
16522
16523 __PAGE_ALIGNED_BSS
16524 .align PAGE_SIZE
16525 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
16526 index 9c3bd4a..e1d9b35 100644
16527 --- a/arch/x86/kernel/i386_ksyms_32.c
16528 +++ b/arch/x86/kernel/i386_ksyms_32.c
16529 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
16530 EXPORT_SYMBOL(cmpxchg8b_emu);
16531 #endif
16532
16533 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
16534 +
16535 /* Networking helper routines. */
16536 EXPORT_SYMBOL(csum_partial_copy_generic);
16537 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
16538 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
16539
16540 EXPORT_SYMBOL(__get_user_1);
16541 EXPORT_SYMBOL(__get_user_2);
16542 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
16543
16544 EXPORT_SYMBOL(csum_partial);
16545 EXPORT_SYMBOL(empty_zero_page);
16546 +
16547 +#ifdef CONFIG_PAX_KERNEXEC
16548 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
16549 +#endif
16550 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
16551 index 6104852..6114160 100644
16552 --- a/arch/x86/kernel/i8259.c
16553 +++ b/arch/x86/kernel/i8259.c
16554 @@ -210,7 +210,7 @@ spurious_8259A_irq:
16555 "spurious 8259A interrupt: IRQ%d.\n", irq);
16556 spurious_irq_mask |= irqmask;
16557 }
16558 - atomic_inc(&irq_err_count);
16559 + atomic_inc_unchecked(&irq_err_count);
16560 /*
16561 * Theoretically we do not have to handle this IRQ,
16562 * but in Linux this does not cause problems and is
16563 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
16564 index 43e9ccf..44ccf6f 100644
16565 --- a/arch/x86/kernel/init_task.c
16566 +++ b/arch/x86/kernel/init_task.c
16567 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
16568 * way process stacks are handled. This is done by having a special
16569 * "init_task" linker map entry..
16570 */
16571 -union thread_union init_thread_union __init_task_data =
16572 - { INIT_THREAD_INFO(init_task) };
16573 +union thread_union init_thread_union __init_task_data;
16574
16575 /*
16576 * Initial task structure.
16577 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
16578 * section. Since TSS's are completely CPU-local, we want them
16579 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
16580 */
16581 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
16582 -
16583 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
16584 +EXPORT_SYMBOL(init_tss);
16585 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
16586 index 8c96897..be66bfa 100644
16587 --- a/arch/x86/kernel/ioport.c
16588 +++ b/arch/x86/kernel/ioport.c
16589 @@ -6,6 +6,7 @@
16590 #include <linux/sched.h>
16591 #include <linux/kernel.h>
16592 #include <linux/capability.h>
16593 +#include <linux/security.h>
16594 #include <linux/errno.h>
16595 #include <linux/types.h>
16596 #include <linux/ioport.h>
16597 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
16598
16599 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
16600 return -EINVAL;
16601 +#ifdef CONFIG_GRKERNSEC_IO
16602 + if (turn_on && grsec_disable_privio) {
16603 + gr_handle_ioperm();
16604 + return -EPERM;
16605 + }
16606 +#endif
16607 if (turn_on && !capable(CAP_SYS_RAWIO))
16608 return -EPERM;
16609
16610 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
16611 * because the ->io_bitmap_max value must match the bitmap
16612 * contents:
16613 */
16614 - tss = &per_cpu(init_tss, get_cpu());
16615 + tss = init_tss + get_cpu();
16616
16617 if (turn_on)
16618 bitmap_clear(t->io_bitmap_ptr, from, num);
16619 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
16620 return -EINVAL;
16621 /* Trying to gain more privileges? */
16622 if (level > old) {
16623 +#ifdef CONFIG_GRKERNSEC_IO
16624 + if (grsec_disable_privio) {
16625 + gr_handle_iopl();
16626 + return -EPERM;
16627 + }
16628 +#endif
16629 if (!capable(CAP_SYS_RAWIO))
16630 return -EPERM;
16631 }
16632 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
16633 index 429e0c9..17b3ece 100644
16634 --- a/arch/x86/kernel/irq.c
16635 +++ b/arch/x86/kernel/irq.c
16636 @@ -18,7 +18,7 @@
16637 #include <asm/mce.h>
16638 #include <asm/hw_irq.h>
16639
16640 -atomic_t irq_err_count;
16641 +atomic_unchecked_t irq_err_count;
16642
16643 /* Function pointer for generic interrupt vector handling */
16644 void (*x86_platform_ipi_callback)(void) = NULL;
16645 @@ -117,9 +117,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
16646 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
16647 seq_printf(p, " Machine check polls\n");
16648 #endif
16649 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
16650 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
16651 #if defined(CONFIG_X86_IO_APIC)
16652 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
16653 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
16654 #endif
16655 return 0;
16656 }
16657 @@ -159,10 +159,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
16658
16659 u64 arch_irq_stat(void)
16660 {
16661 - u64 sum = atomic_read(&irq_err_count);
16662 + u64 sum = atomic_read_unchecked(&irq_err_count);
16663
16664 #ifdef CONFIG_X86_IO_APIC
16665 - sum += atomic_read(&irq_mis_count);
16666 + sum += atomic_read_unchecked(&irq_mis_count);
16667 #endif
16668 return sum;
16669 }
16670 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
16671 index 7209070..cbcd71a 100644
16672 --- a/arch/x86/kernel/irq_32.c
16673 +++ b/arch/x86/kernel/irq_32.c
16674 @@ -36,7 +36,7 @@ static int check_stack_overflow(void)
16675 __asm__ __volatile__("andl %%esp,%0" :
16676 "=r" (sp) : "0" (THREAD_SIZE - 1));
16677
16678 - return sp < (sizeof(struct thread_info) + STACK_WARN);
16679 + return sp < STACK_WARN;
16680 }
16681
16682 static void print_stack_overflow(void)
16683 @@ -54,8 +54,8 @@ static inline void print_stack_overflow(void) { }
16684 * per-CPU IRQ handling contexts (thread information and stack)
16685 */
16686 union irq_ctx {
16687 - struct thread_info tinfo;
16688 - u32 stack[THREAD_SIZE/sizeof(u32)];
16689 + unsigned long previous_esp;
16690 + u32 stack[THREAD_SIZE/sizeof(u32)];
16691 } __attribute__((aligned(THREAD_SIZE)));
16692
16693 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
16694 @@ -75,10 +75,9 @@ static void call_on_stack(void *func, void *stack)
16695 static inline int
16696 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
16697 {
16698 - union irq_ctx *curctx, *irqctx;
16699 + union irq_ctx *irqctx;
16700 u32 *isp, arg1, arg2;
16701
16702 - curctx = (union irq_ctx *) current_thread_info();
16703 irqctx = __this_cpu_read(hardirq_ctx);
16704
16705 /*
16706 @@ -87,21 +86,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
16707 * handler) we can't do that and just have to keep using the
16708 * current stack (which is the irq stack already after all)
16709 */
16710 - if (unlikely(curctx == irqctx))
16711 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
16712 return 0;
16713
16714 /* build the stack frame on the IRQ stack */
16715 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
16716 - irqctx->tinfo.task = curctx->tinfo.task;
16717 - irqctx->tinfo.previous_esp = current_stack_pointer;
16718 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
16719 + irqctx->previous_esp = current_stack_pointer;
16720
16721 - /*
16722 - * Copy the softirq bits in preempt_count so that the
16723 - * softirq checks work in the hardirq context.
16724 - */
16725 - irqctx->tinfo.preempt_count =
16726 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
16727 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
16728 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16729 + __set_fs(MAKE_MM_SEG(0));
16730 +#endif
16731
16732 if (unlikely(overflow))
16733 call_on_stack(print_stack_overflow, isp);
16734 @@ -113,6 +107,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
16735 : "0" (irq), "1" (desc), "2" (isp),
16736 "D" (desc->handle_irq)
16737 : "memory", "cc", "ecx");
16738 +
16739 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16740 + __set_fs(current_thread_info()->addr_limit);
16741 +#endif
16742 +
16743 return 1;
16744 }
16745
16746 @@ -121,29 +120,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
16747 */
16748 void __cpuinit irq_ctx_init(int cpu)
16749 {
16750 - union irq_ctx *irqctx;
16751 -
16752 if (per_cpu(hardirq_ctx, cpu))
16753 return;
16754
16755 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
16756 - THREAD_FLAGS,
16757 - THREAD_ORDER));
16758 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
16759 - irqctx->tinfo.cpu = cpu;
16760 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
16761 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
16762 -
16763 - per_cpu(hardirq_ctx, cpu) = irqctx;
16764 -
16765 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
16766 - THREAD_FLAGS,
16767 - THREAD_ORDER));
16768 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
16769 - irqctx->tinfo.cpu = cpu;
16770 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
16771 -
16772 - per_cpu(softirq_ctx, cpu) = irqctx;
16773 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
16774 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
16775
16776 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
16777 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
16778 @@ -152,7 +133,6 @@ void __cpuinit irq_ctx_init(int cpu)
16779 asmlinkage void do_softirq(void)
16780 {
16781 unsigned long flags;
16782 - struct thread_info *curctx;
16783 union irq_ctx *irqctx;
16784 u32 *isp;
16785
16786 @@ -162,15 +142,22 @@ asmlinkage void do_softirq(void)
16787 local_irq_save(flags);
16788
16789 if (local_softirq_pending()) {
16790 - curctx = current_thread_info();
16791 irqctx = __this_cpu_read(softirq_ctx);
16792 - irqctx->tinfo.task = curctx->task;
16793 - irqctx->tinfo.previous_esp = current_stack_pointer;
16794 + irqctx->previous_esp = current_stack_pointer;
16795
16796 /* build the stack frame on the softirq stack */
16797 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
16798 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
16799 +
16800 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16801 + __set_fs(MAKE_MM_SEG(0));
16802 +#endif
16803
16804 call_on_stack(__do_softirq, isp);
16805 +
16806 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16807 + __set_fs(current_thread_info()->addr_limit);
16808 +#endif
16809 +
16810 /*
16811 * Shouldn't happen, we returned above if in_interrupt():
16812 */
16813 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
16814 index 69bca46..0bac999 100644
16815 --- a/arch/x86/kernel/irq_64.c
16816 +++ b/arch/x86/kernel/irq_64.c
16817 @@ -38,7 +38,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
16818 #ifdef CONFIG_DEBUG_STACKOVERFLOW
16819 u64 curbase = (u64)task_stack_page(current);
16820
16821 - if (user_mode_vm(regs))
16822 + if (user_mode(regs))
16823 return;
16824
16825 WARN_ONCE(regs->sp >= curbase &&
16826 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
16827 index faba577..93b9e71 100644
16828 --- a/arch/x86/kernel/kgdb.c
16829 +++ b/arch/x86/kernel/kgdb.c
16830 @@ -124,11 +124,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
16831 #ifdef CONFIG_X86_32
16832 switch (regno) {
16833 case GDB_SS:
16834 - if (!user_mode_vm(regs))
16835 + if (!user_mode(regs))
16836 *(unsigned long *)mem = __KERNEL_DS;
16837 break;
16838 case GDB_SP:
16839 - if (!user_mode_vm(regs))
16840 + if (!user_mode(regs))
16841 *(unsigned long *)mem = kernel_stack_pointer(regs);
16842 break;
16843 case GDB_GS:
16844 @@ -473,12 +473,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
16845 case 'k':
16846 /* clear the trace bit */
16847 linux_regs->flags &= ~X86_EFLAGS_TF;
16848 - atomic_set(&kgdb_cpu_doing_single_step, -1);
16849 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
16850
16851 /* set the trace bit if we're stepping */
16852 if (remcomInBuffer[0] == 's') {
16853 linux_regs->flags |= X86_EFLAGS_TF;
16854 - atomic_set(&kgdb_cpu_doing_single_step,
16855 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
16856 raw_smp_processor_id());
16857 }
16858
16859 @@ -543,7 +543,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
16860
16861 switch (cmd) {
16862 case DIE_DEBUG:
16863 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
16864 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
16865 if (user_mode(regs))
16866 return single_step_cont(regs, args);
16867 break;
16868 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
16869 index 7da647d..56fe348 100644
16870 --- a/arch/x86/kernel/kprobes.c
16871 +++ b/arch/x86/kernel/kprobes.c
16872 @@ -118,8 +118,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
16873 } __attribute__((packed)) *insn;
16874
16875 insn = (struct __arch_relative_insn *)from;
16876 +
16877 + pax_open_kernel();
16878 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
16879 insn->op = op;
16880 + pax_close_kernel();
16881 }
16882
16883 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
16884 @@ -156,7 +159,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
16885 kprobe_opcode_t opcode;
16886 kprobe_opcode_t *orig_opcodes = opcodes;
16887
16888 - if (search_exception_tables((unsigned long)opcodes))
16889 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
16890 return 0; /* Page fault may occur on this address. */
16891
16892 retry:
16893 @@ -317,7 +320,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
16894 }
16895 }
16896 insn_get_length(&insn);
16897 + pax_open_kernel();
16898 memcpy(dest, insn.kaddr, insn.length);
16899 + pax_close_kernel();
16900
16901 #ifdef CONFIG_X86_64
16902 if (insn_rip_relative(&insn)) {
16903 @@ -341,7 +346,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
16904 (u8 *) dest;
16905 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
16906 disp = (u8 *) dest + insn_offset_displacement(&insn);
16907 + pax_open_kernel();
16908 *(s32 *) disp = (s32) newdisp;
16909 + pax_close_kernel();
16910 }
16911 #endif
16912 return insn.length;
16913 @@ -355,12 +362,12 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
16914 */
16915 __copy_instruction(p->ainsn.insn, p->addr, 0);
16916
16917 - if (can_boost(p->addr))
16918 + if (can_boost(ktla_ktva(p->addr)))
16919 p->ainsn.boostable = 0;
16920 else
16921 p->ainsn.boostable = -1;
16922
16923 - p->opcode = *p->addr;
16924 + p->opcode = *(ktla_ktva(p->addr));
16925 }
16926
16927 int __kprobes arch_prepare_kprobe(struct kprobe *p)
16928 @@ -477,7 +484,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
16929 * nor set current_kprobe, because it doesn't use single
16930 * stepping.
16931 */
16932 - regs->ip = (unsigned long)p->ainsn.insn;
16933 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
16934 preempt_enable_no_resched();
16935 return;
16936 }
16937 @@ -496,7 +503,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
16938 if (p->opcode == BREAKPOINT_INSTRUCTION)
16939 regs->ip = (unsigned long)p->addr;
16940 else
16941 - regs->ip = (unsigned long)p->ainsn.insn;
16942 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
16943 }
16944
16945 /*
16946 @@ -575,7 +582,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
16947 setup_singlestep(p, regs, kcb, 0);
16948 return 1;
16949 }
16950 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
16951 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
16952 /*
16953 * The breakpoint instruction was removed right
16954 * after we hit it. Another cpu has removed
16955 @@ -683,6 +690,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
16956 " movq %rax, 152(%rsp)\n"
16957 RESTORE_REGS_STRING
16958 " popfq\n"
16959 +#ifdef KERNEXEC_PLUGIN
16960 + " btsq $63,(%rsp)\n"
16961 +#endif
16962 #else
16963 " pushf\n"
16964 SAVE_REGS_STRING
16965 @@ -820,7 +830,7 @@ static void __kprobes resume_execution(struct kprobe *p,
16966 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
16967 {
16968 unsigned long *tos = stack_addr(regs);
16969 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
16970 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
16971 unsigned long orig_ip = (unsigned long)p->addr;
16972 kprobe_opcode_t *insn = p->ainsn.insn;
16973
16974 @@ -1002,7 +1012,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
16975 struct die_args *args = data;
16976 int ret = NOTIFY_DONE;
16977
16978 - if (args->regs && user_mode_vm(args->regs))
16979 + if (args->regs && user_mode(args->regs))
16980 return ret;
16981
16982 switch (val) {
16983 @@ -1384,7 +1394,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
16984 * Verify if the address gap is in 2GB range, because this uses
16985 * a relative jump.
16986 */
16987 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
16988 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
16989 if (abs(rel) > 0x7fffffff)
16990 return -ERANGE;
16991
16992 @@ -1405,11 +1415,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
16993 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
16994
16995 /* Set probe function call */
16996 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
16997 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
16998
16999 /* Set returning jmp instruction at the tail of out-of-line buffer */
17000 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17001 - (u8 *)op->kp.addr + op->optinsn.size);
17002 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17003
17004 flush_icache_range((unsigned long) buf,
17005 (unsigned long) buf + TMPL_END_IDX +
17006 @@ -1431,7 +1441,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17007 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17008
17009 /* Backup instructions which will be replaced by jump address */
17010 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17011 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17012 RELATIVE_ADDR_SIZE);
17013
17014 insn_buf[0] = RELATIVEJUMP_OPCODE;
17015 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
17016 index a9c2116..a52d4fc 100644
17017 --- a/arch/x86/kernel/kvm.c
17018 +++ b/arch/x86/kernel/kvm.c
17019 @@ -437,6 +437,7 @@ static void __init paravirt_ops_setup(void)
17020 pv_mmu_ops.set_pud = kvm_set_pud;
17021 #if PAGETABLE_LEVELS == 4
17022 pv_mmu_ops.set_pgd = kvm_set_pgd;
17023 + pv_mmu_ops.set_pgd_batched = kvm_set_pgd;
17024 #endif
17025 #endif
17026 pv_mmu_ops.flush_tlb_user = kvm_flush_tlb;
17027 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17028 index ea69726..604d066 100644
17029 --- a/arch/x86/kernel/ldt.c
17030 +++ b/arch/x86/kernel/ldt.c
17031 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17032 if (reload) {
17033 #ifdef CONFIG_SMP
17034 preempt_disable();
17035 - load_LDT(pc);
17036 + load_LDT_nolock(pc);
17037 if (!cpumask_equal(mm_cpumask(current->mm),
17038 cpumask_of(smp_processor_id())))
17039 smp_call_function(flush_ldt, current->mm, 1);
17040 preempt_enable();
17041 #else
17042 - load_LDT(pc);
17043 + load_LDT_nolock(pc);
17044 #endif
17045 }
17046 if (oldsize) {
17047 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17048 return err;
17049
17050 for (i = 0; i < old->size; i++)
17051 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17052 + write_ldt_entry(new->ldt, i, old->ldt + i);
17053 return 0;
17054 }
17055
17056 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17057 retval = copy_ldt(&mm->context, &old_mm->context);
17058 mutex_unlock(&old_mm->context.lock);
17059 }
17060 +
17061 + if (tsk == current) {
17062 + mm->context.vdso = 0;
17063 +
17064 +#ifdef CONFIG_X86_32
17065 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17066 + mm->context.user_cs_base = 0UL;
17067 + mm->context.user_cs_limit = ~0UL;
17068 +
17069 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17070 + cpus_clear(mm->context.cpu_user_cs_mask);
17071 +#endif
17072 +
17073 +#endif
17074 +#endif
17075 +
17076 + }
17077 +
17078 return retval;
17079 }
17080
17081 @@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
17082 }
17083 }
17084
17085 +#ifdef CONFIG_PAX_SEGMEXEC
17086 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
17087 + error = -EINVAL;
17088 + goto out_unlock;
17089 + }
17090 +#endif
17091 +
17092 fill_ldt(&ldt, &ldt_info);
17093 if (oldmode)
17094 ldt.avl = 0;
17095 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
17096 index a3fa43b..8966f4c 100644
17097 --- a/arch/x86/kernel/machine_kexec_32.c
17098 +++ b/arch/x86/kernel/machine_kexec_32.c
17099 @@ -27,7 +27,7 @@
17100 #include <asm/cacheflush.h>
17101 #include <asm/debugreg.h>
17102
17103 -static void set_idt(void *newidt, __u16 limit)
17104 +static void set_idt(struct desc_struct *newidt, __u16 limit)
17105 {
17106 struct desc_ptr curidt;
17107
17108 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16 limit)
17109 }
17110
17111
17112 -static void set_gdt(void *newgdt, __u16 limit)
17113 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
17114 {
17115 struct desc_ptr curgdt;
17116
17117 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
17118 }
17119
17120 control_page = page_address(image->control_code_page);
17121 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
17122 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
17123
17124 relocate_kernel_ptr = control_page;
17125 page_list[PA_CONTROL_PAGE] = __pa(control_page);
17126 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
17127 index 3ca42d0..7cff8cc 100644
17128 --- a/arch/x86/kernel/microcode_intel.c
17129 +++ b/arch/x86/kernel/microcode_intel.c
17130 @@ -436,13 +436,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
17131
17132 static int get_ucode_user(void *to, const void *from, size_t n)
17133 {
17134 - return copy_from_user(to, from, n);
17135 + return copy_from_user(to, (const void __force_user *)from, n);
17136 }
17137
17138 static enum ucode_state
17139 request_microcode_user(int cpu, const void __user *buf, size_t size)
17140 {
17141 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
17142 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
17143 }
17144
17145 static void microcode_fini_cpu(int cpu)
17146 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
17147 index 925179f..267ac7a 100644
17148 --- a/arch/x86/kernel/module.c
17149 +++ b/arch/x86/kernel/module.c
17150 @@ -36,15 +36,60 @@
17151 #define DEBUGP(fmt...)
17152 #endif
17153
17154 -void *module_alloc(unsigned long size)
17155 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
17156 {
17157 - if (PAGE_ALIGN(size) > MODULES_LEN)
17158 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
17159 return NULL;
17160 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
17161 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
17162 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
17163 -1, __builtin_return_address(0));
17164 }
17165
17166 +void *module_alloc(unsigned long size)
17167 +{
17168 +
17169 +#ifdef CONFIG_PAX_KERNEXEC
17170 + return __module_alloc(size, PAGE_KERNEL);
17171 +#else
17172 + return __module_alloc(size, PAGE_KERNEL_EXEC);
17173 +#endif
17174 +
17175 +}
17176 +
17177 +#ifdef CONFIG_PAX_KERNEXEC
17178 +#ifdef CONFIG_X86_32
17179 +void *module_alloc_exec(unsigned long size)
17180 +{
17181 + struct vm_struct *area;
17182 +
17183 + if (size == 0)
17184 + return NULL;
17185 +
17186 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
17187 + return area ? area->addr : NULL;
17188 +}
17189 +EXPORT_SYMBOL(module_alloc_exec);
17190 +
17191 +void module_free_exec(struct module *mod, void *module_region)
17192 +{
17193 + vunmap(module_region);
17194 +}
17195 +EXPORT_SYMBOL(module_free_exec);
17196 +#else
17197 +void module_free_exec(struct module *mod, void *module_region)
17198 +{
17199 + module_free(mod, module_region);
17200 +}
17201 +EXPORT_SYMBOL(module_free_exec);
17202 +
17203 +void *module_alloc_exec(unsigned long size)
17204 +{
17205 + return __module_alloc(size, PAGE_KERNEL_RX);
17206 +}
17207 +EXPORT_SYMBOL(module_alloc_exec);
17208 +#endif
17209 +#endif
17210 +
17211 #ifdef CONFIG_X86_32
17212 int apply_relocate(Elf32_Shdr *sechdrs,
17213 const char *strtab,
17214 @@ -55,14 +100,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
17215 unsigned int i;
17216 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
17217 Elf32_Sym *sym;
17218 - uint32_t *location;
17219 + uint32_t *plocation, location;
17220
17221 DEBUGP("Applying relocate section %u to %u\n", relsec,
17222 sechdrs[relsec].sh_info);
17223 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
17224 /* This is where to make the change */
17225 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
17226 - + rel[i].r_offset;
17227 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
17228 + location = (uint32_t)plocation;
17229 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
17230 + plocation = ktla_ktva((void *)plocation);
17231 /* This is the symbol it is referring to. Note that all
17232 undefined symbols have been resolved. */
17233 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
17234 @@ -71,11 +118,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
17235 switch (ELF32_R_TYPE(rel[i].r_info)) {
17236 case R_386_32:
17237 /* We add the value into the location given */
17238 - *location += sym->st_value;
17239 + pax_open_kernel();
17240 + *plocation += sym->st_value;
17241 + pax_close_kernel();
17242 break;
17243 case R_386_PC32:
17244 /* Add the value, subtract its postition */
17245 - *location += sym->st_value - (uint32_t)location;
17246 + pax_open_kernel();
17247 + *plocation += sym->st_value - location;
17248 + pax_close_kernel();
17249 break;
17250 default:
17251 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
17252 @@ -120,21 +171,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
17253 case R_X86_64_NONE:
17254 break;
17255 case R_X86_64_64:
17256 + pax_open_kernel();
17257 *(u64 *)loc = val;
17258 + pax_close_kernel();
17259 break;
17260 case R_X86_64_32:
17261 + pax_open_kernel();
17262 *(u32 *)loc = val;
17263 + pax_close_kernel();
17264 if (val != *(u32 *)loc)
17265 goto overflow;
17266 break;
17267 case R_X86_64_32S:
17268 + pax_open_kernel();
17269 *(s32 *)loc = val;
17270 + pax_close_kernel();
17271 if ((s64)val != *(s32 *)loc)
17272 goto overflow;
17273 break;
17274 case R_X86_64_PC32:
17275 val -= (u64)loc;
17276 + pax_open_kernel();
17277 *(u32 *)loc = val;
17278 + pax_close_kernel();
17279 +
17280 #if 0
17281 if ((s64)val != *(s32 *)loc)
17282 goto overflow;
17283 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
17284 index e88f37b..1353db6 100644
17285 --- a/arch/x86/kernel/nmi.c
17286 +++ b/arch/x86/kernel/nmi.c
17287 @@ -408,6 +408,17 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
17288 dotraplinkage notrace __kprobes void
17289 do_nmi(struct pt_regs *regs, long error_code)
17290 {
17291 +
17292 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17293 + if (!user_mode(regs)) {
17294 + unsigned long cs = regs->cs & 0xFFFF;
17295 + unsigned long ip = ktva_ktla(regs->ip);
17296 +
17297 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
17298 + regs->ip = ip;
17299 + }
17300 +#endif
17301 +
17302 nmi_enter();
17303
17304 inc_irq_stat(__nmi_count);
17305 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
17306 index 676b8c7..870ba04 100644
17307 --- a/arch/x86/kernel/paravirt-spinlocks.c
17308 +++ b/arch/x86/kernel/paravirt-spinlocks.c
17309 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
17310 arch_spin_lock(lock);
17311 }
17312
17313 -struct pv_lock_ops pv_lock_ops = {
17314 +struct pv_lock_ops pv_lock_ops __read_only = {
17315 #ifdef CONFIG_SMP
17316 .spin_is_locked = __ticket_spin_is_locked,
17317 .spin_is_contended = __ticket_spin_is_contended,
17318 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
17319 index d90272e..6bb013b 100644
17320 --- a/arch/x86/kernel/paravirt.c
17321 +++ b/arch/x86/kernel/paravirt.c
17322 @@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
17323 {
17324 return x;
17325 }
17326 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
17327 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
17328 +#endif
17329
17330 void __init default_banner(void)
17331 {
17332 @@ -145,15 +148,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
17333 if (opfunc == NULL)
17334 /* If there's no function, patch it with a ud2a (BUG) */
17335 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
17336 - else if (opfunc == _paravirt_nop)
17337 + else if (opfunc == (void *)_paravirt_nop)
17338 /* If the operation is a nop, then nop the callsite */
17339 ret = paravirt_patch_nop();
17340
17341 /* identity functions just return their single argument */
17342 - else if (opfunc == _paravirt_ident_32)
17343 + else if (opfunc == (void *)_paravirt_ident_32)
17344 ret = paravirt_patch_ident_32(insnbuf, len);
17345 - else if (opfunc == _paravirt_ident_64)
17346 + else if (opfunc == (void *)_paravirt_ident_64)
17347 ret = paravirt_patch_ident_64(insnbuf, len);
17348 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
17349 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
17350 + ret = paravirt_patch_ident_64(insnbuf, len);
17351 +#endif
17352
17353 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
17354 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
17355 @@ -178,7 +185,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
17356 if (insn_len > len || start == NULL)
17357 insn_len = len;
17358 else
17359 - memcpy(insnbuf, start, insn_len);
17360 + memcpy(insnbuf, ktla_ktva(start), insn_len);
17361
17362 return insn_len;
17363 }
17364 @@ -302,7 +309,7 @@ void arch_flush_lazy_mmu_mode(void)
17365 preempt_enable();
17366 }
17367
17368 -struct pv_info pv_info = {
17369 +struct pv_info pv_info __read_only = {
17370 .name = "bare hardware",
17371 .paravirt_enabled = 0,
17372 .kernel_rpl = 0,
17373 @@ -313,16 +320,16 @@ struct pv_info pv_info = {
17374 #endif
17375 };
17376
17377 -struct pv_init_ops pv_init_ops = {
17378 +struct pv_init_ops pv_init_ops __read_only = {
17379 .patch = native_patch,
17380 };
17381
17382 -struct pv_time_ops pv_time_ops = {
17383 +struct pv_time_ops pv_time_ops __read_only = {
17384 .sched_clock = native_sched_clock,
17385 .steal_clock = native_steal_clock,
17386 };
17387
17388 -struct pv_irq_ops pv_irq_ops = {
17389 +struct pv_irq_ops pv_irq_ops __read_only = {
17390 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
17391 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
17392 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
17393 @@ -334,7 +341,7 @@ struct pv_irq_ops pv_irq_ops = {
17394 #endif
17395 };
17396
17397 -struct pv_cpu_ops pv_cpu_ops = {
17398 +struct pv_cpu_ops pv_cpu_ops __read_only = {
17399 .cpuid = native_cpuid,
17400 .get_debugreg = native_get_debugreg,
17401 .set_debugreg = native_set_debugreg,
17402 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
17403 .end_context_switch = paravirt_nop,
17404 };
17405
17406 -struct pv_apic_ops pv_apic_ops = {
17407 +struct pv_apic_ops pv_apic_ops __read_only = {
17408 #ifdef CONFIG_X86_LOCAL_APIC
17409 .startup_ipi_hook = paravirt_nop,
17410 #endif
17411 };
17412
17413 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
17414 +#ifdef CONFIG_X86_32
17415 +#ifdef CONFIG_X86_PAE
17416 +/* 64-bit pagetable entries */
17417 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
17418 +#else
17419 /* 32-bit pagetable entries */
17420 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
17421 +#endif
17422 #else
17423 /* 64-bit pagetable entries */
17424 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
17425 #endif
17426
17427 -struct pv_mmu_ops pv_mmu_ops = {
17428 +struct pv_mmu_ops pv_mmu_ops __read_only = {
17429
17430 .read_cr2 = native_read_cr2,
17431 .write_cr2 = native_write_cr2,
17432 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
17433 .make_pud = PTE_IDENT,
17434
17435 .set_pgd = native_set_pgd,
17436 + .set_pgd_batched = native_set_pgd_batched,
17437 #endif
17438 #endif /* PAGETABLE_LEVELS >= 3 */
17439
17440 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
17441 },
17442
17443 .set_fixmap = native_set_fixmap,
17444 +
17445 +#ifdef CONFIG_PAX_KERNEXEC
17446 + .pax_open_kernel = native_pax_open_kernel,
17447 + .pax_close_kernel = native_pax_close_kernel,
17448 +#endif
17449 +
17450 };
17451
17452 EXPORT_SYMBOL_GPL(pv_time_ops);
17453 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
17454 index 35ccf75..7a15747 100644
17455 --- a/arch/x86/kernel/pci-iommu_table.c
17456 +++ b/arch/x86/kernel/pci-iommu_table.c
17457 @@ -2,7 +2,7 @@
17458 #include <asm/iommu_table.h>
17459 #include <linux/string.h>
17460 #include <linux/kallsyms.h>
17461 -
17462 +#include <linux/sched.h>
17463
17464 #define DEBUG 1
17465
17466 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
17467 index ee5d4fb..426649b 100644
17468 --- a/arch/x86/kernel/process.c
17469 +++ b/arch/x86/kernel/process.c
17470 @@ -48,16 +48,33 @@ void free_thread_xstate(struct task_struct *tsk)
17471
17472 void free_thread_info(struct thread_info *ti)
17473 {
17474 - free_thread_xstate(ti->task);
17475 free_pages((unsigned long)ti, THREAD_ORDER);
17476 }
17477
17478 +static struct kmem_cache *task_struct_cachep;
17479 +
17480 void arch_task_cache_init(void)
17481 {
17482 - task_xstate_cachep =
17483 - kmem_cache_create("task_xstate", xstate_size,
17484 + /* create a slab on which task_structs can be allocated */
17485 + task_struct_cachep =
17486 + kmem_cache_create("task_struct", sizeof(struct task_struct),
17487 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
17488 +
17489 + task_xstate_cachep =
17490 + kmem_cache_create("task_xstate", xstate_size,
17491 __alignof__(union thread_xstate),
17492 - SLAB_PANIC | SLAB_NOTRACK, NULL);
17493 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
17494 +}
17495 +
17496 +struct task_struct *alloc_task_struct_node(int node)
17497 +{
17498 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
17499 +}
17500 +
17501 +void free_task_struct(struct task_struct *task)
17502 +{
17503 + free_thread_xstate(task);
17504 + kmem_cache_free(task_struct_cachep, task);
17505 }
17506
17507 /*
17508 @@ -70,7 +87,7 @@ void exit_thread(void)
17509 unsigned long *bp = t->io_bitmap_ptr;
17510
17511 if (bp) {
17512 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
17513 + struct tss_struct *tss = init_tss + get_cpu();
17514
17515 t->io_bitmap_ptr = NULL;
17516 clear_thread_flag(TIF_IO_BITMAP);
17517 @@ -106,7 +123,7 @@ void show_regs_common(void)
17518
17519 printk(KERN_CONT "\n");
17520 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
17521 - current->pid, current->comm, print_tainted(),
17522 + task_pid_nr(current), current->comm, print_tainted(),
17523 init_utsname()->release,
17524 (int)strcspn(init_utsname()->version, " "),
17525 init_utsname()->version);
17526 @@ -120,6 +137,9 @@ void flush_thread(void)
17527 {
17528 struct task_struct *tsk = current;
17529
17530 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
17531 + loadsegment(gs, 0);
17532 +#endif
17533 flush_ptrace_hw_breakpoint(tsk);
17534 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
17535 /*
17536 @@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
17537 regs.di = (unsigned long) arg;
17538
17539 #ifdef CONFIG_X86_32
17540 - regs.ds = __USER_DS;
17541 - regs.es = __USER_DS;
17542 + regs.ds = __KERNEL_DS;
17543 + regs.es = __KERNEL_DS;
17544 regs.fs = __KERNEL_PERCPU;
17545 - regs.gs = __KERNEL_STACK_CANARY;
17546 + savesegment(gs, regs.gs);
17547 #else
17548 regs.ss = __KERNEL_DS;
17549 #endif
17550 @@ -411,7 +431,7 @@ bool set_pm_idle_to_default(void)
17551
17552 return ret;
17553 }
17554 -void stop_this_cpu(void *dummy)
17555 +__noreturn void stop_this_cpu(void *dummy)
17556 {
17557 local_irq_disable();
17558 /*
17559 @@ -653,16 +673,37 @@ static int __init idle_setup(char *str)
17560 }
17561 early_param("idle", idle_setup);
17562
17563 -unsigned long arch_align_stack(unsigned long sp)
17564 +#ifdef CONFIG_PAX_RANDKSTACK
17565 +void pax_randomize_kstack(struct pt_regs *regs)
17566 {
17567 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
17568 - sp -= get_random_int() % 8192;
17569 - return sp & ~0xf;
17570 -}
17571 + struct thread_struct *thread = &current->thread;
17572 + unsigned long time;
17573
17574 -unsigned long arch_randomize_brk(struct mm_struct *mm)
17575 -{
17576 - unsigned long range_end = mm->brk + 0x02000000;
17577 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
17578 -}
17579 + if (!randomize_va_space)
17580 + return;
17581 +
17582 + if (v8086_mode(regs))
17583 + return;
17584
17585 + rdtscl(time);
17586 +
17587 + /* P4 seems to return a 0 LSB, ignore it */
17588 +#ifdef CONFIG_MPENTIUM4
17589 + time &= 0x3EUL;
17590 + time <<= 2;
17591 +#elif defined(CONFIG_X86_64)
17592 + time &= 0xFUL;
17593 + time <<= 4;
17594 +#else
17595 + time &= 0x1FUL;
17596 + time <<= 3;
17597 +#endif
17598 +
17599 + thread->sp0 ^= time;
17600 + load_sp0(init_tss + smp_processor_id(), thread);
17601 +
17602 +#ifdef CONFIG_X86_64
17603 + percpu_write(kernel_stack, thread->sp0);
17604 +#endif
17605 +}
17606 +#endif
17607 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
17608 index 8598296..bfadef0 100644
17609 --- a/arch/x86/kernel/process_32.c
17610 +++ b/arch/x86/kernel/process_32.c
17611 @@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
17612 unsigned long thread_saved_pc(struct task_struct *tsk)
17613 {
17614 return ((unsigned long *)tsk->thread.sp)[3];
17615 +//XXX return tsk->thread.eip;
17616 }
17617
17618 #ifndef CONFIG_SMP
17619 @@ -130,15 +131,14 @@ void __show_regs(struct pt_regs *regs, int all)
17620 unsigned long sp;
17621 unsigned short ss, gs;
17622
17623 - if (user_mode_vm(regs)) {
17624 + if (user_mode(regs)) {
17625 sp = regs->sp;
17626 ss = regs->ss & 0xffff;
17627 - gs = get_user_gs(regs);
17628 } else {
17629 sp = kernel_stack_pointer(regs);
17630 savesegment(ss, ss);
17631 - savesegment(gs, gs);
17632 }
17633 + gs = get_user_gs(regs);
17634
17635 show_regs_common();
17636
17637 @@ -200,13 +200,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
17638 struct task_struct *tsk;
17639 int err;
17640
17641 - childregs = task_pt_regs(p);
17642 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
17643 *childregs = *regs;
17644 childregs->ax = 0;
17645 childregs->sp = sp;
17646
17647 p->thread.sp = (unsigned long) childregs;
17648 p->thread.sp0 = (unsigned long) (childregs+1);
17649 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
17650
17651 p->thread.ip = (unsigned long) ret_from_fork;
17652
17653 @@ -296,7 +297,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17654 struct thread_struct *prev = &prev_p->thread,
17655 *next = &next_p->thread;
17656 int cpu = smp_processor_id();
17657 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
17658 + struct tss_struct *tss = init_tss + cpu;
17659 fpu_switch_t fpu;
17660
17661 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
17662 @@ -320,6 +321,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17663 */
17664 lazy_save_gs(prev->gs);
17665
17666 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17667 + __set_fs(task_thread_info(next_p)->addr_limit);
17668 +#endif
17669 +
17670 /*
17671 * Load the per-thread Thread-Local Storage descriptor.
17672 */
17673 @@ -350,6 +355,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17674 */
17675 arch_end_context_switch(next_p);
17676
17677 + percpu_write(current_task, next_p);
17678 + percpu_write(current_tinfo, &next_p->tinfo);
17679 +
17680 /*
17681 * Restore %gs if needed (which is common)
17682 */
17683 @@ -358,8 +366,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17684
17685 switch_fpu_finish(next_p, fpu);
17686
17687 - percpu_write(current_task, next_p);
17688 -
17689 return prev_p;
17690 }
17691
17692 @@ -389,4 +395,3 @@ unsigned long get_wchan(struct task_struct *p)
17693 } while (count++ < 16);
17694 return 0;
17695 }
17696 -
17697 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
17698 index 6a364a6..b147d11 100644
17699 --- a/arch/x86/kernel/process_64.c
17700 +++ b/arch/x86/kernel/process_64.c
17701 @@ -89,7 +89,7 @@ static void __exit_idle(void)
17702 void exit_idle(void)
17703 {
17704 /* idle loop has pid 0 */
17705 - if (current->pid)
17706 + if (task_pid_nr(current))
17707 return;
17708 __exit_idle();
17709 }
17710 @@ -264,8 +264,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
17711 struct pt_regs *childregs;
17712 struct task_struct *me = current;
17713
17714 - childregs = ((struct pt_regs *)
17715 - (THREAD_SIZE + task_stack_page(p))) - 1;
17716 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
17717 *childregs = *regs;
17718
17719 childregs->ax = 0;
17720 @@ -277,6 +276,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
17721 p->thread.sp = (unsigned long) childregs;
17722 p->thread.sp0 = (unsigned long) (childregs+1);
17723 p->thread.usersp = me->thread.usersp;
17724 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
17725
17726 set_tsk_thread_flag(p, TIF_FORK);
17727
17728 @@ -379,7 +379,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17729 struct thread_struct *prev = &prev_p->thread;
17730 struct thread_struct *next = &next_p->thread;
17731 int cpu = smp_processor_id();
17732 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
17733 + struct tss_struct *tss = init_tss + cpu;
17734 unsigned fsindex, gsindex;
17735 fpu_switch_t fpu;
17736
17737 @@ -461,10 +461,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17738 prev->usersp = percpu_read(old_rsp);
17739 percpu_write(old_rsp, next->usersp);
17740 percpu_write(current_task, next_p);
17741 + percpu_write(current_tinfo, &next_p->tinfo);
17742
17743 - percpu_write(kernel_stack,
17744 - (unsigned long)task_stack_page(next_p) +
17745 - THREAD_SIZE - KERNEL_STACK_OFFSET);
17746 + percpu_write(kernel_stack, next->sp0);
17747
17748 /*
17749 * Now maybe reload the debug registers and handle I/O bitmaps
17750 @@ -519,12 +518,11 @@ unsigned long get_wchan(struct task_struct *p)
17751 if (!p || p == current || p->state == TASK_RUNNING)
17752 return 0;
17753 stack = (unsigned long)task_stack_page(p);
17754 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
17755 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
17756 return 0;
17757 fp = *(u64 *)(p->thread.sp);
17758 do {
17759 - if (fp < (unsigned long)stack ||
17760 - fp >= (unsigned long)stack+THREAD_SIZE)
17761 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
17762 return 0;
17763 ip = *(u64 *)(fp+8);
17764 if (!in_sched_functions(ip))
17765 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
17766 index 8252879..d3219e0 100644
17767 --- a/arch/x86/kernel/ptrace.c
17768 +++ b/arch/x86/kernel/ptrace.c
17769 @@ -822,7 +822,7 @@ long arch_ptrace(struct task_struct *child, long request,
17770 unsigned long addr, unsigned long data)
17771 {
17772 int ret;
17773 - unsigned long __user *datap = (unsigned long __user *)data;
17774 + unsigned long __user *datap = (__force unsigned long __user *)data;
17775
17776 switch (request) {
17777 /* read the word at location addr in the USER area. */
17778 @@ -907,14 +907,14 @@ long arch_ptrace(struct task_struct *child, long request,
17779 if ((int) addr < 0)
17780 return -EIO;
17781 ret = do_get_thread_area(child, addr,
17782 - (struct user_desc __user *)data);
17783 + (__force struct user_desc __user *) data);
17784 break;
17785
17786 case PTRACE_SET_THREAD_AREA:
17787 if ((int) addr < 0)
17788 return -EIO;
17789 ret = do_set_thread_area(child, addr,
17790 - (struct user_desc __user *)data, 0);
17791 + (__force struct user_desc __user *) data, 0);
17792 break;
17793 #endif
17794
17795 @@ -1331,7 +1331,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
17796 memset(info, 0, sizeof(*info));
17797 info->si_signo = SIGTRAP;
17798 info->si_code = si_code;
17799 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
17800 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
17801 }
17802
17803 void user_single_step_siginfo(struct task_struct *tsk,
17804 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
17805 index 42eb330..139955c 100644
17806 --- a/arch/x86/kernel/pvclock.c
17807 +++ b/arch/x86/kernel/pvclock.c
17808 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
17809 return pv_tsc_khz;
17810 }
17811
17812 -static atomic64_t last_value = ATOMIC64_INIT(0);
17813 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
17814
17815 void pvclock_resume(void)
17816 {
17817 - atomic64_set(&last_value, 0);
17818 + atomic64_set_unchecked(&last_value, 0);
17819 }
17820
17821 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
17822 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
17823 * updating at the same time, and one of them could be slightly behind,
17824 * making the assumption that last_value always go forward fail to hold.
17825 */
17826 - last = atomic64_read(&last_value);
17827 + last = atomic64_read_unchecked(&last_value);
17828 do {
17829 if (ret < last)
17830 return last;
17831 - last = atomic64_cmpxchg(&last_value, last, ret);
17832 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
17833 } while (unlikely(last != ret));
17834
17835 return ret;
17836 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
17837 index 37a458b..e63d183 100644
17838 --- a/arch/x86/kernel/reboot.c
17839 +++ b/arch/x86/kernel/reboot.c
17840 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
17841 EXPORT_SYMBOL(pm_power_off);
17842
17843 static const struct desc_ptr no_idt = {};
17844 -static int reboot_mode;
17845 +static unsigned short reboot_mode;
17846 enum reboot_type reboot_type = BOOT_ACPI;
17847 int reboot_force;
17848
17849 @@ -324,13 +324,17 @@ core_initcall(reboot_init);
17850 extern const unsigned char machine_real_restart_asm[];
17851 extern const u64 machine_real_restart_gdt[3];
17852
17853 -void machine_real_restart(unsigned int type)
17854 +__noreturn void machine_real_restart(unsigned int type)
17855 {
17856 void *restart_va;
17857 unsigned long restart_pa;
17858 - void (*restart_lowmem)(unsigned int);
17859 + void (* __noreturn restart_lowmem)(unsigned int);
17860 u64 *lowmem_gdt;
17861
17862 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
17863 + struct desc_struct *gdt;
17864 +#endif
17865 +
17866 local_irq_disable();
17867
17868 /* Write zero to CMOS register number 0x0f, which the BIOS POST
17869 @@ -356,14 +360,14 @@ void machine_real_restart(unsigned int type)
17870 boot)". This seems like a fairly standard thing that gets set by
17871 REBOOT.COM programs, and the previous reset routine did this
17872 too. */
17873 - *((unsigned short *)0x472) = reboot_mode;
17874 + *(unsigned short *)(__va(0x472)) = reboot_mode;
17875
17876 /* Patch the GDT in the low memory trampoline */
17877 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
17878
17879 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
17880 restart_pa = virt_to_phys(restart_va);
17881 - restart_lowmem = (void (*)(unsigned int))restart_pa;
17882 + restart_lowmem = (void *)restart_pa;
17883
17884 /* GDT[0]: GDT self-pointer */
17885 lowmem_gdt[0] =
17886 @@ -374,7 +378,33 @@ void machine_real_restart(unsigned int type)
17887 GDT_ENTRY(0x009b, restart_pa, 0xffff);
17888
17889 /* Jump to the identity-mapped low memory code */
17890 +
17891 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
17892 + gdt = get_cpu_gdt_table(smp_processor_id());
17893 + pax_open_kernel();
17894 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17895 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
17896 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
17897 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
17898 +#endif
17899 +#ifdef CONFIG_PAX_KERNEXEC
17900 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
17901 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
17902 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
17903 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
17904 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
17905 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
17906 +#endif
17907 + pax_close_kernel();
17908 +#endif
17909 +
17910 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17911 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
17912 + unreachable();
17913 +#else
17914 restart_lowmem(type);
17915 +#endif
17916 +
17917 }
17918 #ifdef CONFIG_APM_MODULE
17919 EXPORT_SYMBOL(machine_real_restart);
17920 @@ -540,7 +570,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
17921 * try to force a triple fault and then cycle between hitting the keyboard
17922 * controller and doing that
17923 */
17924 -static void native_machine_emergency_restart(void)
17925 +__noreturn static void native_machine_emergency_restart(void)
17926 {
17927 int i;
17928 int attempt = 0;
17929 @@ -664,13 +694,13 @@ void native_machine_shutdown(void)
17930 #endif
17931 }
17932
17933 -static void __machine_emergency_restart(int emergency)
17934 +static __noreturn void __machine_emergency_restart(int emergency)
17935 {
17936 reboot_emergency = emergency;
17937 machine_ops.emergency_restart();
17938 }
17939
17940 -static void native_machine_restart(char *__unused)
17941 +static __noreturn void native_machine_restart(char *__unused)
17942 {
17943 printk("machine restart\n");
17944
17945 @@ -679,7 +709,7 @@ static void native_machine_restart(char *__unused)
17946 __machine_emergency_restart(0);
17947 }
17948
17949 -static void native_machine_halt(void)
17950 +static __noreturn void native_machine_halt(void)
17951 {
17952 /* stop other cpus and apics */
17953 machine_shutdown();
17954 @@ -690,7 +720,7 @@ static void native_machine_halt(void)
17955 stop_this_cpu(NULL);
17956 }
17957
17958 -static void native_machine_power_off(void)
17959 +__noreturn static void native_machine_power_off(void)
17960 {
17961 if (pm_power_off) {
17962 if (!reboot_force)
17963 @@ -699,6 +729,7 @@ static void native_machine_power_off(void)
17964 }
17965 /* a fallback in case there is no PM info available */
17966 tboot_shutdown(TB_SHUTDOWN_HALT);
17967 + unreachable();
17968 }
17969
17970 struct machine_ops machine_ops = {
17971 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
17972 index 7a6f3b3..bed145d7 100644
17973 --- a/arch/x86/kernel/relocate_kernel_64.S
17974 +++ b/arch/x86/kernel/relocate_kernel_64.S
17975 @@ -11,6 +11,7 @@
17976 #include <asm/kexec.h>
17977 #include <asm/processor-flags.h>
17978 #include <asm/pgtable_types.h>
17979 +#include <asm/alternative-asm.h>
17980
17981 /*
17982 * Must be relocatable PIC code callable as a C function
17983 @@ -160,13 +161,14 @@ identity_mapped:
17984 xorq %rbp, %rbp
17985 xorq %r8, %r8
17986 xorq %r9, %r9
17987 - xorq %r10, %r9
17988 + xorq %r10, %r10
17989 xorq %r11, %r11
17990 xorq %r12, %r12
17991 xorq %r13, %r13
17992 xorq %r14, %r14
17993 xorq %r15, %r15
17994
17995 + pax_force_retaddr 0, 1
17996 ret
17997
17998 1:
17999 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18000 index cf0ef98..e3f780b 100644
18001 --- a/arch/x86/kernel/setup.c
18002 +++ b/arch/x86/kernel/setup.c
18003 @@ -447,7 +447,7 @@ static void __init parse_setup_data(void)
18004
18005 switch (data->type) {
18006 case SETUP_E820_EXT:
18007 - parse_e820_ext(data);
18008 + parse_e820_ext((struct setup_data __force_kernel *)data);
18009 break;
18010 case SETUP_DTB:
18011 add_dtb(pa_data);
18012 @@ -650,7 +650,7 @@ static void __init trim_bios_range(void)
18013 * area (640->1Mb) as ram even though it is not.
18014 * take them out.
18015 */
18016 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18017 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18018 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18019 }
18020
18021 @@ -773,14 +773,14 @@ void __init setup_arch(char **cmdline_p)
18022
18023 if (!boot_params.hdr.root_flags)
18024 root_mountflags &= ~MS_RDONLY;
18025 - init_mm.start_code = (unsigned long) _text;
18026 - init_mm.end_code = (unsigned long) _etext;
18027 + init_mm.start_code = ktla_ktva((unsigned long) _text);
18028 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
18029 init_mm.end_data = (unsigned long) _edata;
18030 init_mm.brk = _brk_end;
18031
18032 - code_resource.start = virt_to_phys(_text);
18033 - code_resource.end = virt_to_phys(_etext)-1;
18034 - data_resource.start = virt_to_phys(_etext);
18035 + code_resource.start = virt_to_phys(ktla_ktva(_text));
18036 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18037 + data_resource.start = virt_to_phys(_sdata);
18038 data_resource.end = virt_to_phys(_edata)-1;
18039 bss_resource.start = virt_to_phys(&__bss_start);
18040 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18041 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18042 index 71f4727..16dc9f7 100644
18043 --- a/arch/x86/kernel/setup_percpu.c
18044 +++ b/arch/x86/kernel/setup_percpu.c
18045 @@ -21,19 +21,17 @@
18046 #include <asm/cpu.h>
18047 #include <asm/stackprotector.h>
18048
18049 -DEFINE_PER_CPU(int, cpu_number);
18050 +#ifdef CONFIG_SMP
18051 +DEFINE_PER_CPU(unsigned int, cpu_number);
18052 EXPORT_PER_CPU_SYMBOL(cpu_number);
18053 +#endif
18054
18055 -#ifdef CONFIG_X86_64
18056 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18057 -#else
18058 -#define BOOT_PERCPU_OFFSET 0
18059 -#endif
18060
18061 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18062 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18063
18064 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18065 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18066 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
18067 };
18068 EXPORT_SYMBOL(__per_cpu_offset);
18069 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
18070 {
18071 #ifdef CONFIG_X86_32
18072 struct desc_struct gdt;
18073 + unsigned long base = per_cpu_offset(cpu);
18074
18075 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
18076 - 0x2 | DESCTYPE_S, 0x8);
18077 - gdt.s = 1;
18078 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
18079 + 0x83 | DESCTYPE_S, 0xC);
18080 write_gdt_entry(get_cpu_gdt_table(cpu),
18081 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
18082 #endif
18083 @@ -207,6 +205,11 @@ void __init setup_per_cpu_areas(void)
18084 /* alrighty, percpu areas up and running */
18085 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
18086 for_each_possible_cpu(cpu) {
18087 +#ifdef CONFIG_CC_STACKPROTECTOR
18088 +#ifdef CONFIG_X86_32
18089 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
18090 +#endif
18091 +#endif
18092 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
18093 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
18094 per_cpu(cpu_number, cpu) = cpu;
18095 @@ -247,6 +250,12 @@ void __init setup_per_cpu_areas(void)
18096 */
18097 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
18098 #endif
18099 +#ifdef CONFIG_CC_STACKPROTECTOR
18100 +#ifdef CONFIG_X86_32
18101 + if (!cpu)
18102 + per_cpu(stack_canary.canary, cpu) = canary;
18103 +#endif
18104 +#endif
18105 /*
18106 * Up to this point, the boot CPU has been using .init.data
18107 * area. Reload any changed state for the boot CPU.
18108 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
18109 index 54ddaeb2..22c3bdc 100644
18110 --- a/arch/x86/kernel/signal.c
18111 +++ b/arch/x86/kernel/signal.c
18112 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsigned long sp)
18113 * Align the stack pointer according to the i386 ABI,
18114 * i.e. so that on function entry ((sp + 4) & 15) == 0.
18115 */
18116 - sp = ((sp + 4) & -16ul) - 4;
18117 + sp = ((sp - 12) & -16ul) - 4;
18118 #else /* !CONFIG_X86_32 */
18119 sp = round_down(sp, 16) - 8;
18120 #endif
18121 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
18122 * Return an always-bogus address instead so we will die with SIGSEGV.
18123 */
18124 if (onsigstack && !likely(on_sig_stack(sp)))
18125 - return (void __user *)-1L;
18126 + return (__force void __user *)-1L;
18127
18128 /* save i387 state */
18129 if (used_math() && save_i387_xstate(*fpstate) < 0)
18130 - return (void __user *)-1L;
18131 + return (__force void __user *)-1L;
18132
18133 return (void __user *)sp;
18134 }
18135 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18136 }
18137
18138 if (current->mm->context.vdso)
18139 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18140 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18141 else
18142 - restorer = &frame->retcode;
18143 + restorer = (void __user *)&frame->retcode;
18144 if (ka->sa.sa_flags & SA_RESTORER)
18145 restorer = ka->sa.sa_restorer;
18146
18147 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18148 * reasons and because gdb uses it as a signature to notice
18149 * signal handler stack frames.
18150 */
18151 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
18152 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
18153
18154 if (err)
18155 return -EFAULT;
18156 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18157 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
18158
18159 /* Set up to return from userspace. */
18160 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18161 + if (current->mm->context.vdso)
18162 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18163 + else
18164 + restorer = (void __user *)&frame->retcode;
18165 if (ka->sa.sa_flags & SA_RESTORER)
18166 restorer = ka->sa.sa_restorer;
18167 put_user_ex(restorer, &frame->pretcode);
18168 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18169 * reasons and because gdb uses it as a signature to notice
18170 * signal handler stack frames.
18171 */
18172 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
18173 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
18174 } put_user_catch(err);
18175
18176 if (err)
18177 @@ -769,7 +772,7 @@ static void do_signal(struct pt_regs *regs)
18178 * X86_32: vm86 regs switched out by assembly code before reaching
18179 * here, so testing against kernel CS suffices.
18180 */
18181 - if (!user_mode(regs))
18182 + if (!user_mode_novm(regs))
18183 return;
18184
18185 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
18186 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
18187 index 9f548cb..caf76f7 100644
18188 --- a/arch/x86/kernel/smpboot.c
18189 +++ b/arch/x86/kernel/smpboot.c
18190 @@ -709,17 +709,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
18191 set_idle_for_cpu(cpu, c_idle.idle);
18192 do_rest:
18193 per_cpu(current_task, cpu) = c_idle.idle;
18194 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
18195 #ifdef CONFIG_X86_32
18196 /* Stack for startup_32 can be just as for start_secondary onwards */
18197 irq_ctx_init(cpu);
18198 #else
18199 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
18200 initial_gs = per_cpu_offset(cpu);
18201 - per_cpu(kernel_stack, cpu) =
18202 - (unsigned long)task_stack_page(c_idle.idle) -
18203 - KERNEL_STACK_OFFSET + THREAD_SIZE;
18204 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
18205 #endif
18206 +
18207 + pax_open_kernel();
18208 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
18209 + pax_close_kernel();
18210 +
18211 initial_code = (unsigned long)start_secondary;
18212 stack_start = c_idle.idle->thread.sp;
18213
18214 @@ -861,6 +864,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
18215
18216 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
18217
18218 +#ifdef CONFIG_PAX_PER_CPU_PGD
18219 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
18220 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
18221 + KERNEL_PGD_PTRS);
18222 +#endif
18223 +
18224 err = do_boot_cpu(apicid, cpu);
18225 if (err) {
18226 pr_debug("do_boot_cpu failed %d\n", err);
18227 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
18228 index c346d11..d43b163 100644
18229 --- a/arch/x86/kernel/step.c
18230 +++ b/arch/x86/kernel/step.c
18231 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
18232 struct desc_struct *desc;
18233 unsigned long base;
18234
18235 - seg &= ~7UL;
18236 + seg >>= 3;
18237
18238 mutex_lock(&child->mm->context.lock);
18239 - if (unlikely((seg >> 3) >= child->mm->context.size))
18240 + if (unlikely(seg >= child->mm->context.size))
18241 addr = -1L; /* bogus selector, access would fault */
18242 else {
18243 desc = child->mm->context.ldt + seg;
18244 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
18245 addr += base;
18246 }
18247 mutex_unlock(&child->mm->context.lock);
18248 - }
18249 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
18250 + addr = ktla_ktva(addr);
18251
18252 return addr;
18253 }
18254 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
18255 unsigned char opcode[15];
18256 unsigned long addr = convert_ip_to_linear(child, regs);
18257
18258 + if (addr == -EINVAL)
18259 + return 0;
18260 +
18261 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
18262 for (i = 0; i < copied; i++) {
18263 switch (opcode[i]) {
18264 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
18265 index 0b0cb5f..db6b9ed 100644
18266 --- a/arch/x86/kernel/sys_i386_32.c
18267 +++ b/arch/x86/kernel/sys_i386_32.c
18268 @@ -24,17 +24,224 @@
18269
18270 #include <asm/syscalls.h>
18271
18272 -/*
18273 - * Do a system call from kernel instead of calling sys_execve so we
18274 - * end up with proper pt_regs.
18275 - */
18276 -int kernel_execve(const char *filename,
18277 - const char *const argv[],
18278 - const char *const envp[])
18279 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
18280 {
18281 - long __res;
18282 - asm volatile ("int $0x80"
18283 - : "=a" (__res)
18284 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
18285 - return __res;
18286 + unsigned long pax_task_size = TASK_SIZE;
18287 +
18288 +#ifdef CONFIG_PAX_SEGMEXEC
18289 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
18290 + pax_task_size = SEGMEXEC_TASK_SIZE;
18291 +#endif
18292 +
18293 + if (len > pax_task_size || addr > pax_task_size - len)
18294 + return -EINVAL;
18295 +
18296 + return 0;
18297 +}
18298 +
18299 +unsigned long
18300 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
18301 + unsigned long len, unsigned long pgoff, unsigned long flags)
18302 +{
18303 + struct mm_struct *mm = current->mm;
18304 + struct vm_area_struct *vma;
18305 + unsigned long start_addr, pax_task_size = TASK_SIZE;
18306 +
18307 +#ifdef CONFIG_PAX_SEGMEXEC
18308 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18309 + pax_task_size = SEGMEXEC_TASK_SIZE;
18310 +#endif
18311 +
18312 + pax_task_size -= PAGE_SIZE;
18313 +
18314 + if (len > pax_task_size)
18315 + return -ENOMEM;
18316 +
18317 + if (flags & MAP_FIXED)
18318 + return addr;
18319 +
18320 +#ifdef CONFIG_PAX_RANDMMAP
18321 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18322 +#endif
18323 +
18324 + if (addr) {
18325 + addr = PAGE_ALIGN(addr);
18326 + if (pax_task_size - len >= addr) {
18327 + vma = find_vma(mm, addr);
18328 + if (check_heap_stack_gap(vma, addr, len))
18329 + return addr;
18330 + }
18331 + }
18332 + if (len > mm->cached_hole_size) {
18333 + start_addr = addr = mm->free_area_cache;
18334 + } else {
18335 + start_addr = addr = mm->mmap_base;
18336 + mm->cached_hole_size = 0;
18337 + }
18338 +
18339 +#ifdef CONFIG_PAX_PAGEEXEC
18340 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
18341 + start_addr = 0x00110000UL;
18342 +
18343 +#ifdef CONFIG_PAX_RANDMMAP
18344 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18345 + start_addr += mm->delta_mmap & 0x03FFF000UL;
18346 +#endif
18347 +
18348 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
18349 + start_addr = addr = mm->mmap_base;
18350 + else
18351 + addr = start_addr;
18352 + }
18353 +#endif
18354 +
18355 +full_search:
18356 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
18357 + /* At this point: (!vma || addr < vma->vm_end). */
18358 + if (pax_task_size - len < addr) {
18359 + /*
18360 + * Start a new search - just in case we missed
18361 + * some holes.
18362 + */
18363 + if (start_addr != mm->mmap_base) {
18364 + start_addr = addr = mm->mmap_base;
18365 + mm->cached_hole_size = 0;
18366 + goto full_search;
18367 + }
18368 + return -ENOMEM;
18369 + }
18370 + if (check_heap_stack_gap(vma, addr, len))
18371 + break;
18372 + if (addr + mm->cached_hole_size < vma->vm_start)
18373 + mm->cached_hole_size = vma->vm_start - addr;
18374 + addr = vma->vm_end;
18375 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
18376 + start_addr = addr = mm->mmap_base;
18377 + mm->cached_hole_size = 0;
18378 + goto full_search;
18379 + }
18380 + }
18381 +
18382 + /*
18383 + * Remember the place where we stopped the search:
18384 + */
18385 + mm->free_area_cache = addr + len;
18386 + return addr;
18387 +}
18388 +
18389 +unsigned long
18390 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18391 + const unsigned long len, const unsigned long pgoff,
18392 + const unsigned long flags)
18393 +{
18394 + struct vm_area_struct *vma;
18395 + struct mm_struct *mm = current->mm;
18396 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
18397 +
18398 +#ifdef CONFIG_PAX_SEGMEXEC
18399 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18400 + pax_task_size = SEGMEXEC_TASK_SIZE;
18401 +#endif
18402 +
18403 + pax_task_size -= PAGE_SIZE;
18404 +
18405 + /* requested length too big for entire address space */
18406 + if (len > pax_task_size)
18407 + return -ENOMEM;
18408 +
18409 + if (flags & MAP_FIXED)
18410 + return addr;
18411 +
18412 +#ifdef CONFIG_PAX_PAGEEXEC
18413 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
18414 + goto bottomup;
18415 +#endif
18416 +
18417 +#ifdef CONFIG_PAX_RANDMMAP
18418 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18419 +#endif
18420 +
18421 + /* requesting a specific address */
18422 + if (addr) {
18423 + addr = PAGE_ALIGN(addr);
18424 + if (pax_task_size - len >= addr) {
18425 + vma = find_vma(mm, addr);
18426 + if (check_heap_stack_gap(vma, addr, len))
18427 + return addr;
18428 + }
18429 + }
18430 +
18431 + /* check if free_area_cache is useful for us */
18432 + if (len <= mm->cached_hole_size) {
18433 + mm->cached_hole_size = 0;
18434 + mm->free_area_cache = mm->mmap_base;
18435 + }
18436 +
18437 + /* either no address requested or can't fit in requested address hole */
18438 + addr = mm->free_area_cache;
18439 +
18440 + /* make sure it can fit in the remaining address space */
18441 + if (addr > len) {
18442 + vma = find_vma(mm, addr-len);
18443 + if (check_heap_stack_gap(vma, addr - len, len))
18444 + /* remember the address as a hint for next time */
18445 + return (mm->free_area_cache = addr-len);
18446 + }
18447 +
18448 + if (mm->mmap_base < len)
18449 + goto bottomup;
18450 +
18451 + addr = mm->mmap_base-len;
18452 +
18453 + do {
18454 + /*
18455 + * Lookup failure means no vma is above this address,
18456 + * else if new region fits below vma->vm_start,
18457 + * return with success:
18458 + */
18459 + vma = find_vma(mm, addr);
18460 + if (check_heap_stack_gap(vma, addr, len))
18461 + /* remember the address as a hint for next time */
18462 + return (mm->free_area_cache = addr);
18463 +
18464 + /* remember the largest hole we saw so far */
18465 + if (addr + mm->cached_hole_size < vma->vm_start)
18466 + mm->cached_hole_size = vma->vm_start - addr;
18467 +
18468 + /* try just below the current vma->vm_start */
18469 + addr = skip_heap_stack_gap(vma, len);
18470 + } while (!IS_ERR_VALUE(addr));
18471 +
18472 +bottomup:
18473 + /*
18474 + * A failed mmap() very likely causes application failure,
18475 + * so fall back to the bottom-up function here. This scenario
18476 + * can happen with large stack limits and large mmap()
18477 + * allocations.
18478 + */
18479 +
18480 +#ifdef CONFIG_PAX_SEGMEXEC
18481 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18482 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
18483 + else
18484 +#endif
18485 +
18486 + mm->mmap_base = TASK_UNMAPPED_BASE;
18487 +
18488 +#ifdef CONFIG_PAX_RANDMMAP
18489 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18490 + mm->mmap_base += mm->delta_mmap;
18491 +#endif
18492 +
18493 + mm->free_area_cache = mm->mmap_base;
18494 + mm->cached_hole_size = ~0UL;
18495 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
18496 + /*
18497 + * Restore the topdown base:
18498 + */
18499 + mm->mmap_base = base;
18500 + mm->free_area_cache = base;
18501 + mm->cached_hole_size = ~0UL;
18502 +
18503 + return addr;
18504 }
18505 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
18506 index 0514890..3dbebce 100644
18507 --- a/arch/x86/kernel/sys_x86_64.c
18508 +++ b/arch/x86/kernel/sys_x86_64.c
18509 @@ -95,8 +95,8 @@ out:
18510 return error;
18511 }
18512
18513 -static void find_start_end(unsigned long flags, unsigned long *begin,
18514 - unsigned long *end)
18515 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
18516 + unsigned long *begin, unsigned long *end)
18517 {
18518 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
18519 unsigned long new_begin;
18520 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
18521 *begin = new_begin;
18522 }
18523 } else {
18524 - *begin = TASK_UNMAPPED_BASE;
18525 + *begin = mm->mmap_base;
18526 *end = TASK_SIZE;
18527 }
18528 }
18529 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
18530 if (flags & MAP_FIXED)
18531 return addr;
18532
18533 - find_start_end(flags, &begin, &end);
18534 + find_start_end(mm, flags, &begin, &end);
18535
18536 if (len > end)
18537 return -ENOMEM;
18538
18539 +#ifdef CONFIG_PAX_RANDMMAP
18540 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18541 +#endif
18542 +
18543 if (addr) {
18544 addr = PAGE_ALIGN(addr);
18545 vma = find_vma(mm, addr);
18546 - if (end - len >= addr &&
18547 - (!vma || addr + len <= vma->vm_start))
18548 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
18549 return addr;
18550 }
18551 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
18552 @@ -172,7 +175,7 @@ full_search:
18553 }
18554 return -ENOMEM;
18555 }
18556 - if (!vma || addr + len <= vma->vm_start) {
18557 + if (check_heap_stack_gap(vma, addr, len)) {
18558 /*
18559 * Remember the place where we stopped the search:
18560 */
18561 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18562 {
18563 struct vm_area_struct *vma;
18564 struct mm_struct *mm = current->mm;
18565 - unsigned long addr = addr0;
18566 + unsigned long base = mm->mmap_base, addr = addr0;
18567
18568 /* requested length too big for entire address space */
18569 if (len > TASK_SIZE)
18570 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18571 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
18572 goto bottomup;
18573
18574 +#ifdef CONFIG_PAX_RANDMMAP
18575 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18576 +#endif
18577 +
18578 /* requesting a specific address */
18579 if (addr) {
18580 addr = PAGE_ALIGN(addr);
18581 - vma = find_vma(mm, addr);
18582 - if (TASK_SIZE - len >= addr &&
18583 - (!vma || addr + len <= vma->vm_start))
18584 - return addr;
18585 + if (TASK_SIZE - len >= addr) {
18586 + vma = find_vma(mm, addr);
18587 + if (check_heap_stack_gap(vma, addr, len))
18588 + return addr;
18589 + }
18590 }
18591
18592 /* check if free_area_cache is useful for us */
18593 @@ -232,7 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18594 ALIGN_TOPDOWN);
18595
18596 vma = find_vma(mm, tmp_addr);
18597 - if (!vma || tmp_addr + len <= vma->vm_start)
18598 + if (check_heap_stack_gap(vma, tmp_addr, len))
18599 /* remember the address as a hint for next time */
18600 return mm->free_area_cache = tmp_addr;
18601 }
18602 @@ -251,7 +259,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18603 * return with success:
18604 */
18605 vma = find_vma(mm, addr);
18606 - if (!vma || addr+len <= vma->vm_start)
18607 + if (check_heap_stack_gap(vma, addr, len))
18608 /* remember the address as a hint for next time */
18609 return mm->free_area_cache = addr;
18610
18611 @@ -260,8 +268,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18612 mm->cached_hole_size = vma->vm_start - addr;
18613
18614 /* try just below the current vma->vm_start */
18615 - addr = vma->vm_start-len;
18616 - } while (len < vma->vm_start);
18617 + addr = skip_heap_stack_gap(vma, len);
18618 + } while (!IS_ERR_VALUE(addr));
18619
18620 bottomup:
18621 /*
18622 @@ -270,13 +278,21 @@ bottomup:
18623 * can happen with large stack limits and large mmap()
18624 * allocations.
18625 */
18626 + mm->mmap_base = TASK_UNMAPPED_BASE;
18627 +
18628 +#ifdef CONFIG_PAX_RANDMMAP
18629 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18630 + mm->mmap_base += mm->delta_mmap;
18631 +#endif
18632 +
18633 + mm->free_area_cache = mm->mmap_base;
18634 mm->cached_hole_size = ~0UL;
18635 - mm->free_area_cache = TASK_UNMAPPED_BASE;
18636 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
18637 /*
18638 * Restore the topdown base:
18639 */
18640 - mm->free_area_cache = mm->mmap_base;
18641 + mm->mmap_base = base;
18642 + mm->free_area_cache = base;
18643 mm->cached_hole_size = ~0UL;
18644
18645 return addr;
18646 diff --git a/arch/x86/kernel/syscall_table_32.S b/arch/x86/kernel/syscall_table_32.S
18647 index 9a0e312..e6f66f2 100644
18648 --- a/arch/x86/kernel/syscall_table_32.S
18649 +++ b/arch/x86/kernel/syscall_table_32.S
18650 @@ -1,3 +1,4 @@
18651 +.section .rodata,"a",@progbits
18652 ENTRY(sys_call_table)
18653 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
18654 .long sys_exit
18655 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
18656 index e2410e2..4fe3fbc 100644
18657 --- a/arch/x86/kernel/tboot.c
18658 +++ b/arch/x86/kernel/tboot.c
18659 @@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
18660
18661 void tboot_shutdown(u32 shutdown_type)
18662 {
18663 - void (*shutdown)(void);
18664 + void (* __noreturn shutdown)(void);
18665
18666 if (!tboot_enabled())
18667 return;
18668 @@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
18669
18670 switch_to_tboot_pt();
18671
18672 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
18673 + shutdown = (void *)tboot->shutdown_entry;
18674 shutdown();
18675
18676 /* should not reach here */
18677 @@ -298,7 +298,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
18678 tboot_shutdown(acpi_shutdown_map[sleep_state]);
18679 }
18680
18681 -static atomic_t ap_wfs_count;
18682 +static atomic_unchecked_t ap_wfs_count;
18683
18684 static int tboot_wait_for_aps(int num_aps)
18685 {
18686 @@ -322,9 +322,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
18687 {
18688 switch (action) {
18689 case CPU_DYING:
18690 - atomic_inc(&ap_wfs_count);
18691 + atomic_inc_unchecked(&ap_wfs_count);
18692 if (num_online_cpus() == 1)
18693 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
18694 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
18695 return NOTIFY_BAD;
18696 break;
18697 }
18698 @@ -343,7 +343,7 @@ static __init int tboot_late_init(void)
18699
18700 tboot_create_trampoline();
18701
18702 - atomic_set(&ap_wfs_count, 0);
18703 + atomic_set_unchecked(&ap_wfs_count, 0);
18704 register_hotcpu_notifier(&tboot_cpu_notifier);
18705 return 0;
18706 }
18707 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
18708 index dd5fbf4..b7f2232 100644
18709 --- a/arch/x86/kernel/time.c
18710 +++ b/arch/x86/kernel/time.c
18711 @@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
18712 {
18713 unsigned long pc = instruction_pointer(regs);
18714
18715 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
18716 + if (!user_mode(regs) && in_lock_functions(pc)) {
18717 #ifdef CONFIG_FRAME_POINTER
18718 - return *(unsigned long *)(regs->bp + sizeof(long));
18719 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
18720 #else
18721 unsigned long *sp =
18722 (unsigned long *)kernel_stack_pointer(regs);
18723 @@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
18724 * or above a saved flags. Eflags has bits 22-31 zero,
18725 * kernel addresses don't.
18726 */
18727 +
18728 +#ifdef CONFIG_PAX_KERNEXEC
18729 + return ktla_ktva(sp[0]);
18730 +#else
18731 if (sp[0] >> 22)
18732 return sp[0];
18733 if (sp[1] >> 22)
18734 return sp[1];
18735 #endif
18736 +
18737 +#endif
18738 }
18739 return pc;
18740 }
18741 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
18742 index 6bb7b85..dd853e1 100644
18743 --- a/arch/x86/kernel/tls.c
18744 +++ b/arch/x86/kernel/tls.c
18745 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
18746 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
18747 return -EINVAL;
18748
18749 +#ifdef CONFIG_PAX_SEGMEXEC
18750 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
18751 + return -EINVAL;
18752 +#endif
18753 +
18754 set_tls_desc(p, idx, &info, 1);
18755
18756 return 0;
18757 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
18758 index 451c0a7..e57f551 100644
18759 --- a/arch/x86/kernel/trampoline_32.S
18760 +++ b/arch/x86/kernel/trampoline_32.S
18761 @@ -32,6 +32,12 @@
18762 #include <asm/segment.h>
18763 #include <asm/page_types.h>
18764
18765 +#ifdef CONFIG_PAX_KERNEXEC
18766 +#define ta(X) (X)
18767 +#else
18768 +#define ta(X) ((X) - __PAGE_OFFSET)
18769 +#endif
18770 +
18771 #ifdef CONFIG_SMP
18772
18773 .section ".x86_trampoline","a"
18774 @@ -62,7 +68,7 @@ r_base = .
18775 inc %ax # protected mode (PE) bit
18776 lmsw %ax # into protected mode
18777 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
18778 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
18779 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
18780
18781 # These need to be in the same 64K segment as the above;
18782 # hence we don't use the boot_gdt_descr defined in head.S
18783 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
18784 index 09ff517..df19fbff 100644
18785 --- a/arch/x86/kernel/trampoline_64.S
18786 +++ b/arch/x86/kernel/trampoline_64.S
18787 @@ -90,7 +90,7 @@ startup_32:
18788 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
18789 movl %eax, %ds
18790
18791 - movl $X86_CR4_PAE, %eax
18792 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
18793 movl %eax, %cr4 # Enable PAE mode
18794
18795 # Setup trampoline 4 level pagetables
18796 @@ -138,7 +138,7 @@ tidt:
18797 # so the kernel can live anywhere
18798 .balign 4
18799 tgdt:
18800 - .short tgdt_end - tgdt # gdt limit
18801 + .short tgdt_end - tgdt - 1 # gdt limit
18802 .long tgdt - r_base
18803 .short 0
18804 .quad 0x00cf9b000000ffff # __KERNEL32_CS
18805 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
18806 index 31d9d0f..e244dd9 100644
18807 --- a/arch/x86/kernel/traps.c
18808 +++ b/arch/x86/kernel/traps.c
18809 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
18810
18811 /* Do we ignore FPU interrupts ? */
18812 char ignore_fpu_irq;
18813 -
18814 -/*
18815 - * The IDT has to be page-aligned to simplify the Pentium
18816 - * F0 0F bug workaround.
18817 - */
18818 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
18819 #endif
18820
18821 DECLARE_BITMAP(used_vectors, NR_VECTORS);
18822 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
18823 }
18824
18825 static void __kprobes
18826 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
18827 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
18828 long error_code, siginfo_t *info)
18829 {
18830 struct task_struct *tsk = current;
18831
18832 #ifdef CONFIG_X86_32
18833 - if (regs->flags & X86_VM_MASK) {
18834 + if (v8086_mode(regs)) {
18835 /*
18836 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
18837 * On nmi (interrupt 2), do_trap should not be called.
18838 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
18839 }
18840 #endif
18841
18842 - if (!user_mode(regs))
18843 + if (!user_mode_novm(regs))
18844 goto kernel_trap;
18845
18846 #ifdef CONFIG_X86_32
18847 @@ -148,7 +142,7 @@ trap_signal:
18848 printk_ratelimit()) {
18849 printk(KERN_INFO
18850 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
18851 - tsk->comm, tsk->pid, str,
18852 + tsk->comm, task_pid_nr(tsk), str,
18853 regs->ip, regs->sp, error_code);
18854 print_vma_addr(" in ", regs->ip);
18855 printk("\n");
18856 @@ -165,8 +159,20 @@ kernel_trap:
18857 if (!fixup_exception(regs)) {
18858 tsk->thread.error_code = error_code;
18859 tsk->thread.trap_no = trapnr;
18860 +
18861 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18862 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
18863 + str = "PAX: suspicious stack segment fault";
18864 +#endif
18865 +
18866 die(str, regs, error_code);
18867 }
18868 +
18869 +#ifdef CONFIG_PAX_REFCOUNT
18870 + if (trapnr == 4)
18871 + pax_report_refcount_overflow(regs);
18872 +#endif
18873 +
18874 return;
18875
18876 #ifdef CONFIG_X86_32
18877 @@ -255,14 +261,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
18878 conditional_sti(regs);
18879
18880 #ifdef CONFIG_X86_32
18881 - if (regs->flags & X86_VM_MASK)
18882 + if (v8086_mode(regs))
18883 goto gp_in_vm86;
18884 #endif
18885
18886 tsk = current;
18887 - if (!user_mode(regs))
18888 + if (!user_mode_novm(regs))
18889 goto gp_in_kernel;
18890
18891 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
18892 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
18893 + struct mm_struct *mm = tsk->mm;
18894 + unsigned long limit;
18895 +
18896 + down_write(&mm->mmap_sem);
18897 + limit = mm->context.user_cs_limit;
18898 + if (limit < TASK_SIZE) {
18899 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
18900 + up_write(&mm->mmap_sem);
18901 + return;
18902 + }
18903 + up_write(&mm->mmap_sem);
18904 + }
18905 +#endif
18906 +
18907 tsk->thread.error_code = error_code;
18908 tsk->thread.trap_no = 13;
18909
18910 @@ -295,6 +317,13 @@ gp_in_kernel:
18911 if (notify_die(DIE_GPF, "general protection fault", regs,
18912 error_code, 13, SIGSEGV) == NOTIFY_STOP)
18913 return;
18914 +
18915 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18916 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
18917 + die("PAX: suspicious general protection fault", regs, error_code);
18918 + else
18919 +#endif
18920 +
18921 die("general protection fault", regs, error_code);
18922 }
18923
18924 @@ -414,7 +443,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
18925 /* It's safe to allow irq's after DR6 has been saved */
18926 preempt_conditional_sti(regs);
18927
18928 - if (regs->flags & X86_VM_MASK) {
18929 + if (v8086_mode(regs)) {
18930 handle_vm86_trap((struct kernel_vm86_regs *) regs,
18931 error_code, 1);
18932 preempt_conditional_cli(regs);
18933 @@ -428,7 +457,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
18934 * We already checked v86 mode above, so we can check for kernel mode
18935 * by just checking the CPL of CS.
18936 */
18937 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
18938 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
18939 tsk->thread.debugreg6 &= ~DR_STEP;
18940 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
18941 regs->flags &= ~X86_EFLAGS_TF;
18942 @@ -457,7 +486,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
18943 return;
18944 conditional_sti(regs);
18945
18946 - if (!user_mode_vm(regs))
18947 + if (!user_mode(regs))
18948 {
18949 if (!fixup_exception(regs)) {
18950 task->thread.error_code = error_code;
18951 @@ -569,8 +598,8 @@ asmlinkage void __attribute__((weak)) smp_threshold_interrupt(void)
18952 void __math_state_restore(struct task_struct *tsk)
18953 {
18954 /* We need a safe address that is cheap to find and that is already
18955 - in L1. We've just brought in "tsk->thread.has_fpu", so use that */
18956 -#define safe_address (tsk->thread.has_fpu)
18957 + in L1. */
18958 +#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
18959
18960 /* AMD K7/K8 CPUs don't save/restore FDP/FIP/FOP unless an exception
18961 is pending. Clear the x87 state here by setting it to fixed
18962 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
18963 index b9242ba..50c5edd 100644
18964 --- a/arch/x86/kernel/verify_cpu.S
18965 +++ b/arch/x86/kernel/verify_cpu.S
18966 @@ -20,6 +20,7 @@
18967 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
18968 * arch/x86/kernel/trampoline_64.S: secondary processor verification
18969 * arch/x86/kernel/head_32.S: processor startup
18970 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
18971 *
18972 * verify_cpu, returns the status of longmode and SSE in register %eax.
18973 * 0: Success 1: Failure
18974 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
18975 index 863f875..4307295 100644
18976 --- a/arch/x86/kernel/vm86_32.c
18977 +++ b/arch/x86/kernel/vm86_32.c
18978 @@ -41,6 +41,7 @@
18979 #include <linux/ptrace.h>
18980 #include <linux/audit.h>
18981 #include <linux/stddef.h>
18982 +#include <linux/grsecurity.h>
18983
18984 #include <asm/uaccess.h>
18985 #include <asm/io.h>
18986 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
18987 do_exit(SIGSEGV);
18988 }
18989
18990 - tss = &per_cpu(init_tss, get_cpu());
18991 + tss = init_tss + get_cpu();
18992 current->thread.sp0 = current->thread.saved_sp0;
18993 current->thread.sysenter_cs = __KERNEL_CS;
18994 load_sp0(tss, &current->thread);
18995 @@ -208,6 +209,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
18996 struct task_struct *tsk;
18997 int tmp, ret = -EPERM;
18998
18999 +#ifdef CONFIG_GRKERNSEC_VM86
19000 + if (!capable(CAP_SYS_RAWIO)) {
19001 + gr_handle_vm86();
19002 + goto out;
19003 + }
19004 +#endif
19005 +
19006 tsk = current;
19007 if (tsk->thread.saved_sp0)
19008 goto out;
19009 @@ -238,6 +246,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19010 int tmp, ret;
19011 struct vm86plus_struct __user *v86;
19012
19013 +#ifdef CONFIG_GRKERNSEC_VM86
19014 + if (!capable(CAP_SYS_RAWIO)) {
19015 + gr_handle_vm86();
19016 + ret = -EPERM;
19017 + goto out;
19018 + }
19019 +#endif
19020 +
19021 tsk = current;
19022 switch (cmd) {
19023 case VM86_REQUEST_IRQ:
19024 @@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19025 tsk->thread.saved_fs = info->regs32->fs;
19026 tsk->thread.saved_gs = get_user_gs(info->regs32);
19027
19028 - tss = &per_cpu(init_tss, get_cpu());
19029 + tss = init_tss + get_cpu();
19030 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19031 if (cpu_has_sep)
19032 tsk->thread.sysenter_cs = 0;
19033 @@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19034 goto cannot_handle;
19035 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19036 goto cannot_handle;
19037 - intr_ptr = (unsigned long __user *) (i << 2);
19038 + intr_ptr = (__force unsigned long __user *) (i << 2);
19039 if (get_user(segoffs, intr_ptr))
19040 goto cannot_handle;
19041 if ((segoffs >> 16) == BIOSSEG)
19042 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19043 index 0f703f1..9e15f64 100644
19044 --- a/arch/x86/kernel/vmlinux.lds.S
19045 +++ b/arch/x86/kernel/vmlinux.lds.S
19046 @@ -26,6 +26,13 @@
19047 #include <asm/page_types.h>
19048 #include <asm/cache.h>
19049 #include <asm/boot.h>
19050 +#include <asm/segment.h>
19051 +
19052 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19053 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19054 +#else
19055 +#define __KERNEL_TEXT_OFFSET 0
19056 +#endif
19057
19058 #undef i386 /* in case the preprocessor is a 32bit one */
19059
19060 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19061
19062 PHDRS {
19063 text PT_LOAD FLAGS(5); /* R_E */
19064 +#ifdef CONFIG_X86_32
19065 + module PT_LOAD FLAGS(5); /* R_E */
19066 +#endif
19067 +#ifdef CONFIG_XEN
19068 + rodata PT_LOAD FLAGS(5); /* R_E */
19069 +#else
19070 + rodata PT_LOAD FLAGS(4); /* R__ */
19071 +#endif
19072 data PT_LOAD FLAGS(6); /* RW_ */
19073 -#ifdef CONFIG_X86_64
19074 + init.begin PT_LOAD FLAGS(6); /* RW_ */
19075 #ifdef CONFIG_SMP
19076 percpu PT_LOAD FLAGS(6); /* RW_ */
19077 #endif
19078 + text.init PT_LOAD FLAGS(5); /* R_E */
19079 + text.exit PT_LOAD FLAGS(5); /* R_E */
19080 init PT_LOAD FLAGS(7); /* RWE */
19081 -#endif
19082 note PT_NOTE FLAGS(0); /* ___ */
19083 }
19084
19085 SECTIONS
19086 {
19087 #ifdef CONFIG_X86_32
19088 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19089 - phys_startup_32 = startup_32 - LOAD_OFFSET;
19090 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19091 #else
19092 - . = __START_KERNEL;
19093 - phys_startup_64 = startup_64 - LOAD_OFFSET;
19094 + . = __START_KERNEL;
19095 #endif
19096
19097 /* Text and read-only data */
19098 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
19099 - _text = .;
19100 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19101 /* bootstrapping code */
19102 +#ifdef CONFIG_X86_32
19103 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19104 +#else
19105 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19106 +#endif
19107 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19108 + _text = .;
19109 HEAD_TEXT
19110 #ifdef CONFIG_X86_32
19111 . = ALIGN(PAGE_SIZE);
19112 @@ -108,13 +128,47 @@ SECTIONS
19113 IRQENTRY_TEXT
19114 *(.fixup)
19115 *(.gnu.warning)
19116 - /* End of text section */
19117 - _etext = .;
19118 } :text = 0x9090
19119
19120 - NOTES :text :note
19121 + . += __KERNEL_TEXT_OFFSET;
19122
19123 - EXCEPTION_TABLE(16) :text = 0x9090
19124 +#ifdef CONFIG_X86_32
19125 + . = ALIGN(PAGE_SIZE);
19126 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19127 +
19128 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19129 + MODULES_EXEC_VADDR = .;
19130 + BYTE(0)
19131 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19132 + . = ALIGN(HPAGE_SIZE);
19133 + MODULES_EXEC_END = . - 1;
19134 +#endif
19135 +
19136 + } :module
19137 +#endif
19138 +
19139 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19140 + /* End of text section */
19141 + _etext = . - __KERNEL_TEXT_OFFSET;
19142 + }
19143 +
19144 +#ifdef CONFIG_X86_32
19145 + . = ALIGN(PAGE_SIZE);
19146 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
19147 + *(.idt)
19148 + . = ALIGN(PAGE_SIZE);
19149 + *(.empty_zero_page)
19150 + *(.initial_pg_fixmap)
19151 + *(.initial_pg_pmd)
19152 + *(.initial_page_table)
19153 + *(.swapper_pg_dir)
19154 + } :rodata
19155 +#endif
19156 +
19157 + . = ALIGN(PAGE_SIZE);
19158 + NOTES :rodata :note
19159 +
19160 + EXCEPTION_TABLE(16) :rodata
19161
19162 #if defined(CONFIG_DEBUG_RODATA)
19163 /* .text should occupy whole number of pages */
19164 @@ -126,16 +180,20 @@ SECTIONS
19165
19166 /* Data */
19167 .data : AT(ADDR(.data) - LOAD_OFFSET) {
19168 +
19169 +#ifdef CONFIG_PAX_KERNEXEC
19170 + . = ALIGN(HPAGE_SIZE);
19171 +#else
19172 + . = ALIGN(PAGE_SIZE);
19173 +#endif
19174 +
19175 /* Start of data section */
19176 _sdata = .;
19177
19178 /* init_task */
19179 INIT_TASK_DATA(THREAD_SIZE)
19180
19181 -#ifdef CONFIG_X86_32
19182 - /* 32 bit has nosave before _edata */
19183 NOSAVE_DATA
19184 -#endif
19185
19186 PAGE_ALIGNED_DATA(PAGE_SIZE)
19187
19188 @@ -176,12 +234,19 @@ SECTIONS
19189 #endif /* CONFIG_X86_64 */
19190
19191 /* Init code and data - will be freed after init */
19192 - . = ALIGN(PAGE_SIZE);
19193 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
19194 + BYTE(0)
19195 +
19196 +#ifdef CONFIG_PAX_KERNEXEC
19197 + . = ALIGN(HPAGE_SIZE);
19198 +#else
19199 + . = ALIGN(PAGE_SIZE);
19200 +#endif
19201 +
19202 __init_begin = .; /* paired with __init_end */
19203 - }
19204 + } :init.begin
19205
19206 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
19207 +#ifdef CONFIG_SMP
19208 /*
19209 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
19210 * output PHDR, so the next output section - .init.text - should
19211 @@ -190,12 +255,27 @@ SECTIONS
19212 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
19213 #endif
19214
19215 - INIT_TEXT_SECTION(PAGE_SIZE)
19216 -#ifdef CONFIG_X86_64
19217 - :init
19218 -#endif
19219 + . = ALIGN(PAGE_SIZE);
19220 + init_begin = .;
19221 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
19222 + VMLINUX_SYMBOL(_sinittext) = .;
19223 + INIT_TEXT
19224 + VMLINUX_SYMBOL(_einittext) = .;
19225 + . = ALIGN(PAGE_SIZE);
19226 + } :text.init
19227
19228 - INIT_DATA_SECTION(16)
19229 + /*
19230 + * .exit.text is discard at runtime, not link time, to deal with
19231 + * references from .altinstructions and .eh_frame
19232 + */
19233 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19234 + EXIT_TEXT
19235 + . = ALIGN(16);
19236 + } :text.exit
19237 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
19238 +
19239 + . = ALIGN(PAGE_SIZE);
19240 + INIT_DATA_SECTION(16) :init
19241
19242 /*
19243 * Code and data for a variety of lowlevel trampolines, to be
19244 @@ -269,19 +349,12 @@ SECTIONS
19245 }
19246
19247 . = ALIGN(8);
19248 - /*
19249 - * .exit.text is discard at runtime, not link time, to deal with
19250 - * references from .altinstructions and .eh_frame
19251 - */
19252 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
19253 - EXIT_TEXT
19254 - }
19255
19256 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
19257 EXIT_DATA
19258 }
19259
19260 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
19261 +#ifndef CONFIG_SMP
19262 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
19263 #endif
19264
19265 @@ -300,16 +373,10 @@ SECTIONS
19266 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
19267 __smp_locks = .;
19268 *(.smp_locks)
19269 - . = ALIGN(PAGE_SIZE);
19270 __smp_locks_end = .;
19271 + . = ALIGN(PAGE_SIZE);
19272 }
19273
19274 -#ifdef CONFIG_X86_64
19275 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
19276 - NOSAVE_DATA
19277 - }
19278 -#endif
19279 -
19280 /* BSS */
19281 . = ALIGN(PAGE_SIZE);
19282 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
19283 @@ -325,6 +392,7 @@ SECTIONS
19284 __brk_base = .;
19285 . += 64 * 1024; /* 64k alignment slop space */
19286 *(.brk_reservation) /* areas brk users have reserved */
19287 + . = ALIGN(HPAGE_SIZE);
19288 __brk_limit = .;
19289 }
19290
19291 @@ -351,13 +419,12 @@ SECTIONS
19292 * for the boot processor.
19293 */
19294 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
19295 -INIT_PER_CPU(gdt_page);
19296 INIT_PER_CPU(irq_stack_union);
19297
19298 /*
19299 * Build-time check on the image size:
19300 */
19301 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
19302 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
19303 "kernel image bigger than KERNEL_IMAGE_SIZE");
19304
19305 #ifdef CONFIG_SMP
19306 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
19307 index e4d4a22..47ee71f 100644
19308 --- a/arch/x86/kernel/vsyscall_64.c
19309 +++ b/arch/x86/kernel/vsyscall_64.c
19310 @@ -57,15 +57,13 @@ DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
19311 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
19312 };
19313
19314 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = NATIVE;
19315 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
19316
19317 static int __init vsyscall_setup(char *str)
19318 {
19319 if (str) {
19320 if (!strcmp("emulate", str))
19321 vsyscall_mode = EMULATE;
19322 - else if (!strcmp("native", str))
19323 - vsyscall_mode = NATIVE;
19324 else if (!strcmp("none", str))
19325 vsyscall_mode = NONE;
19326 else
19327 @@ -178,7 +176,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
19328
19329 tsk = current;
19330 if (seccomp_mode(&tsk->seccomp))
19331 - do_exit(SIGKILL);
19332 + do_group_exit(SIGKILL);
19333
19334 switch (vsyscall_nr) {
19335 case 0:
19336 @@ -220,8 +218,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
19337 return true;
19338
19339 sigsegv:
19340 - force_sig(SIGSEGV, current);
19341 - return true;
19342 + do_group_exit(SIGKILL);
19343 }
19344
19345 /*
19346 @@ -274,10 +271,7 @@ void __init map_vsyscall(void)
19347 extern char __vvar_page;
19348 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
19349
19350 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
19351 - vsyscall_mode == NATIVE
19352 - ? PAGE_KERNEL_VSYSCALL
19353 - : PAGE_KERNEL_VVAR);
19354 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
19355 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
19356 (unsigned long)VSYSCALL_START);
19357
19358 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
19359 index 9796c2f..f686fbf 100644
19360 --- a/arch/x86/kernel/x8664_ksyms_64.c
19361 +++ b/arch/x86/kernel/x8664_ksyms_64.c
19362 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
19363 EXPORT_SYMBOL(copy_user_generic_string);
19364 EXPORT_SYMBOL(copy_user_generic_unrolled);
19365 EXPORT_SYMBOL(__copy_user_nocache);
19366 -EXPORT_SYMBOL(_copy_from_user);
19367 -EXPORT_SYMBOL(_copy_to_user);
19368
19369 EXPORT_SYMBOL(copy_page);
19370 EXPORT_SYMBOL(clear_page);
19371 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
19372 index 7110911..e8cdee5 100644
19373 --- a/arch/x86/kernel/xsave.c
19374 +++ b/arch/x86/kernel/xsave.c
19375 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
19376 fx_sw_user->xstate_size > fx_sw_user->extended_size)
19377 return -EINVAL;
19378
19379 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
19380 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
19381 fx_sw_user->extended_size -
19382 FP_XSTATE_MAGIC2_SIZE));
19383 if (err)
19384 @@ -266,7 +266,7 @@ fx_only:
19385 * the other extended state.
19386 */
19387 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
19388 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
19389 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
19390 }
19391
19392 /*
19393 @@ -295,7 +295,7 @@ int restore_i387_xstate(void __user *buf)
19394 if (use_xsave())
19395 err = restore_user_xstate(buf);
19396 else
19397 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
19398 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
19399 buf);
19400 if (unlikely(err)) {
19401 /*
19402 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
19403 index f1e3be1..588efc8 100644
19404 --- a/arch/x86/kvm/emulate.c
19405 +++ b/arch/x86/kvm/emulate.c
19406 @@ -249,6 +249,7 @@ struct gprefix {
19407
19408 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
19409 do { \
19410 + unsigned long _tmp; \
19411 __asm__ __volatile__ ( \
19412 _PRE_EFLAGS("0", "4", "2") \
19413 _op _suffix " %"_x"3,%1; " \
19414 @@ -263,8 +264,6 @@ struct gprefix {
19415 /* Raw emulation: instruction has two explicit operands. */
19416 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
19417 do { \
19418 - unsigned long _tmp; \
19419 - \
19420 switch ((ctxt)->dst.bytes) { \
19421 case 2: \
19422 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
19423 @@ -280,7 +279,6 @@ struct gprefix {
19424
19425 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
19426 do { \
19427 - unsigned long _tmp; \
19428 switch ((ctxt)->dst.bytes) { \
19429 case 1: \
19430 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
19431 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
19432 index 54abb40..a192606 100644
19433 --- a/arch/x86/kvm/lapic.c
19434 +++ b/arch/x86/kvm/lapic.c
19435 @@ -53,7 +53,7 @@
19436 #define APIC_BUS_CYCLE_NS 1
19437
19438 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
19439 -#define apic_debug(fmt, arg...)
19440 +#define apic_debug(fmt, arg...) do {} while (0)
19441
19442 #define APIC_LVT_NUM 6
19443 /* 14 is the version for Xeon and Pentium 8.4.8*/
19444 diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
19445 index f1b36cf..af8a124 100644
19446 --- a/arch/x86/kvm/mmu.c
19447 +++ b/arch/x86/kvm/mmu.c
19448 @@ -3555,7 +3555,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
19449
19450 pgprintk("%s: gpa %llx bytes %d\n", __func__, gpa, bytes);
19451
19452 - invlpg_counter = atomic_read(&vcpu->kvm->arch.invlpg_counter);
19453 + invlpg_counter = atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter);
19454
19455 /*
19456 * Assume that the pte write on a page table of the same type
19457 @@ -3587,7 +3587,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
19458 }
19459
19460 spin_lock(&vcpu->kvm->mmu_lock);
19461 - if (atomic_read(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
19462 + if (atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
19463 gentry = 0;
19464 kvm_mmu_free_some_pages(vcpu);
19465 ++vcpu->kvm->stat.mmu_pte_write;
19466 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
19467 index 9299410..ade2f9b 100644
19468 --- a/arch/x86/kvm/paging_tmpl.h
19469 +++ b/arch/x86/kvm/paging_tmpl.h
19470 @@ -197,7 +197,7 @@ retry_walk:
19471 if (unlikely(kvm_is_error_hva(host_addr)))
19472 goto error;
19473
19474 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
19475 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
19476 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
19477 goto error;
19478
19479 @@ -705,7 +705,7 @@ static void FNAME(invlpg)(struct kvm_vcpu *vcpu, gva_t gva)
19480 if (need_flush)
19481 kvm_flush_remote_tlbs(vcpu->kvm);
19482
19483 - atomic_inc(&vcpu->kvm->arch.invlpg_counter);
19484 + atomic_inc_unchecked(&vcpu->kvm->arch.invlpg_counter);
19485
19486 spin_unlock(&vcpu->kvm->mmu_lock);
19487
19488 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
19489 index e32243e..a6e6172 100644
19490 --- a/arch/x86/kvm/svm.c
19491 +++ b/arch/x86/kvm/svm.c
19492 @@ -3400,7 +3400,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
19493 int cpu = raw_smp_processor_id();
19494
19495 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
19496 +
19497 + pax_open_kernel();
19498 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
19499 + pax_close_kernel();
19500 +
19501 load_TR_desc();
19502 }
19503
19504 @@ -3778,6 +3782,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
19505 #endif
19506 #endif
19507
19508 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19509 + __set_fs(current_thread_info()->addr_limit);
19510 +#endif
19511 +
19512 reload_tss(vcpu);
19513
19514 local_irq_disable();
19515 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
19516 index 4ea7678..b3a7084 100644
19517 --- a/arch/x86/kvm/vmx.c
19518 +++ b/arch/x86/kvm/vmx.c
19519 @@ -1305,7 +1305,11 @@ static void reload_tss(void)
19520 struct desc_struct *descs;
19521
19522 descs = (void *)gdt->address;
19523 +
19524 + pax_open_kernel();
19525 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
19526 + pax_close_kernel();
19527 +
19528 load_TR_desc();
19529 }
19530
19531 @@ -2633,8 +2637,11 @@ static __init int hardware_setup(void)
19532 if (!cpu_has_vmx_flexpriority())
19533 flexpriority_enabled = 0;
19534
19535 - if (!cpu_has_vmx_tpr_shadow())
19536 - kvm_x86_ops->update_cr8_intercept = NULL;
19537 + if (!cpu_has_vmx_tpr_shadow()) {
19538 + pax_open_kernel();
19539 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
19540 + pax_close_kernel();
19541 + }
19542
19543 if (enable_ept && !cpu_has_vmx_ept_2m_page())
19544 kvm_disable_largepages();
19545 @@ -3648,7 +3655,7 @@ static void vmx_set_constant_host_state(void)
19546 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
19547
19548 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
19549 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
19550 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
19551
19552 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
19553 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
19554 @@ -6169,6 +6176,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
19555 "jmp .Lkvm_vmx_return \n\t"
19556 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
19557 ".Lkvm_vmx_return: "
19558 +
19559 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19560 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
19561 + ".Lkvm_vmx_return2: "
19562 +#endif
19563 +
19564 /* Save guest registers, load host registers, keep flags */
19565 "mov %0, %c[wordsize](%%"R"sp) \n\t"
19566 "pop %0 \n\t"
19567 @@ -6217,6 +6230,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
19568 #endif
19569 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
19570 [wordsize]"i"(sizeof(ulong))
19571 +
19572 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19573 + ,[cs]"i"(__KERNEL_CS)
19574 +#endif
19575 +
19576 : "cc", "memory"
19577 , R"ax", R"bx", R"di", R"si"
19578 #ifdef CONFIG_X86_64
19579 @@ -6245,7 +6263,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
19580 }
19581 }
19582
19583 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
19584 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
19585 +
19586 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19587 + loadsegment(fs, __KERNEL_PERCPU);
19588 +#endif
19589 +
19590 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19591 + __set_fs(current_thread_info()->addr_limit);
19592 +#endif
19593 +
19594 vmx->loaded_vmcs->launched = 1;
19595
19596 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
19597 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
19598 index 4c938da..4ddef65 100644
19599 --- a/arch/x86/kvm/x86.c
19600 +++ b/arch/x86/kvm/x86.c
19601 @@ -1345,8 +1345,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
19602 {
19603 struct kvm *kvm = vcpu->kvm;
19604 int lm = is_long_mode(vcpu);
19605 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
19606 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
19607 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
19608 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
19609 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
19610 : kvm->arch.xen_hvm_config.blob_size_32;
19611 u32 page_num = data & ~PAGE_MASK;
19612 @@ -2165,6 +2165,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
19613 if (n < msr_list.nmsrs)
19614 goto out;
19615 r = -EFAULT;
19616 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
19617 + goto out;
19618 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
19619 num_msrs_to_save * sizeof(u32)))
19620 goto out;
19621 @@ -2340,15 +2342,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
19622 struct kvm_cpuid2 *cpuid,
19623 struct kvm_cpuid_entry2 __user *entries)
19624 {
19625 - int r;
19626 + int r, i;
19627
19628 r = -E2BIG;
19629 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
19630 goto out;
19631 r = -EFAULT;
19632 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
19633 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
19634 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
19635 goto out;
19636 + for (i = 0; i < cpuid->nent; ++i) {
19637 + struct kvm_cpuid_entry2 cpuid_entry;
19638 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
19639 + goto out;
19640 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
19641 + }
19642 vcpu->arch.cpuid_nent = cpuid->nent;
19643 kvm_apic_set_version(vcpu);
19644 kvm_x86_ops->cpuid_update(vcpu);
19645 @@ -2363,15 +2370,19 @@ static int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
19646 struct kvm_cpuid2 *cpuid,
19647 struct kvm_cpuid_entry2 __user *entries)
19648 {
19649 - int r;
19650 + int r, i;
19651
19652 r = -E2BIG;
19653 if (cpuid->nent < vcpu->arch.cpuid_nent)
19654 goto out;
19655 r = -EFAULT;
19656 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
19657 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
19658 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
19659 goto out;
19660 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
19661 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
19662 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
19663 + goto out;
19664 + }
19665 return 0;
19666
19667 out:
19668 @@ -2746,7 +2757,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
19669 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
19670 struct kvm_interrupt *irq)
19671 {
19672 - if (irq->irq < 0 || irq->irq >= 256)
19673 + if (irq->irq >= 256)
19674 return -EINVAL;
19675 if (irqchip_in_kernel(vcpu->kvm))
19676 return -ENXIO;
19677 @@ -5162,7 +5173,7 @@ static void kvm_set_mmio_spte_mask(void)
19678 kvm_mmu_set_mmio_spte_mask(mask);
19679 }
19680
19681 -int kvm_arch_init(void *opaque)
19682 +int kvm_arch_init(const void *opaque)
19683 {
19684 int r;
19685 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
19686 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
19687 index cf4603b..7cdde38 100644
19688 --- a/arch/x86/lguest/boot.c
19689 +++ b/arch/x86/lguest/boot.c
19690 @@ -1195,9 +1195,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
19691 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
19692 * Launcher to reboot us.
19693 */
19694 -static void lguest_restart(char *reason)
19695 +static __noreturn void lguest_restart(char *reason)
19696 {
19697 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
19698 + BUG();
19699 }
19700
19701 /*G:050
19702 diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
19703 index 042f682..c92afb6 100644
19704 --- a/arch/x86/lib/atomic64_32.c
19705 +++ b/arch/x86/lib/atomic64_32.c
19706 @@ -8,18 +8,30 @@
19707
19708 long long atomic64_read_cx8(long long, const atomic64_t *v);
19709 EXPORT_SYMBOL(atomic64_read_cx8);
19710 +long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
19711 +EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
19712 long long atomic64_set_cx8(long long, const atomic64_t *v);
19713 EXPORT_SYMBOL(atomic64_set_cx8);
19714 +long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
19715 +EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
19716 long long atomic64_xchg_cx8(long long, unsigned high);
19717 EXPORT_SYMBOL(atomic64_xchg_cx8);
19718 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
19719 EXPORT_SYMBOL(atomic64_add_return_cx8);
19720 +long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
19721 +EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
19722 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
19723 EXPORT_SYMBOL(atomic64_sub_return_cx8);
19724 +long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
19725 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
19726 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
19727 EXPORT_SYMBOL(atomic64_inc_return_cx8);
19728 +long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
19729 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
19730 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
19731 EXPORT_SYMBOL(atomic64_dec_return_cx8);
19732 +long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
19733 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
19734 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
19735 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
19736 int atomic64_inc_not_zero_cx8(atomic64_t *v);
19737 @@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
19738 #ifndef CONFIG_X86_CMPXCHG64
19739 long long atomic64_read_386(long long, const atomic64_t *v);
19740 EXPORT_SYMBOL(atomic64_read_386);
19741 +long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
19742 +EXPORT_SYMBOL(atomic64_read_unchecked_386);
19743 long long atomic64_set_386(long long, const atomic64_t *v);
19744 EXPORT_SYMBOL(atomic64_set_386);
19745 +long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
19746 +EXPORT_SYMBOL(atomic64_set_unchecked_386);
19747 long long atomic64_xchg_386(long long, unsigned high);
19748 EXPORT_SYMBOL(atomic64_xchg_386);
19749 long long atomic64_add_return_386(long long a, atomic64_t *v);
19750 EXPORT_SYMBOL(atomic64_add_return_386);
19751 +long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
19752 +EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
19753 long long atomic64_sub_return_386(long long a, atomic64_t *v);
19754 EXPORT_SYMBOL(atomic64_sub_return_386);
19755 +long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
19756 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
19757 long long atomic64_inc_return_386(long long a, atomic64_t *v);
19758 EXPORT_SYMBOL(atomic64_inc_return_386);
19759 +long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
19760 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
19761 long long atomic64_dec_return_386(long long a, atomic64_t *v);
19762 EXPORT_SYMBOL(atomic64_dec_return_386);
19763 +long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
19764 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
19765 long long atomic64_add_386(long long a, atomic64_t *v);
19766 EXPORT_SYMBOL(atomic64_add_386);
19767 +long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
19768 +EXPORT_SYMBOL(atomic64_add_unchecked_386);
19769 long long atomic64_sub_386(long long a, atomic64_t *v);
19770 EXPORT_SYMBOL(atomic64_sub_386);
19771 +long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
19772 +EXPORT_SYMBOL(atomic64_sub_unchecked_386);
19773 long long atomic64_inc_386(long long a, atomic64_t *v);
19774 EXPORT_SYMBOL(atomic64_inc_386);
19775 +long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
19776 +EXPORT_SYMBOL(atomic64_inc_unchecked_386);
19777 long long atomic64_dec_386(long long a, atomic64_t *v);
19778 EXPORT_SYMBOL(atomic64_dec_386);
19779 +long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
19780 +EXPORT_SYMBOL(atomic64_dec_unchecked_386);
19781 long long atomic64_dec_if_positive_386(atomic64_t *v);
19782 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
19783 int atomic64_inc_not_zero_386(atomic64_t *v);
19784 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
19785 index e8e7e0d..56fd1b0 100644
19786 --- a/arch/x86/lib/atomic64_386_32.S
19787 +++ b/arch/x86/lib/atomic64_386_32.S
19788 @@ -48,6 +48,10 @@ BEGIN(read)
19789 movl (v), %eax
19790 movl 4(v), %edx
19791 RET_ENDP
19792 +BEGIN(read_unchecked)
19793 + movl (v), %eax
19794 + movl 4(v), %edx
19795 +RET_ENDP
19796 #undef v
19797
19798 #define v %esi
19799 @@ -55,6 +59,10 @@ BEGIN(set)
19800 movl %ebx, (v)
19801 movl %ecx, 4(v)
19802 RET_ENDP
19803 +BEGIN(set_unchecked)
19804 + movl %ebx, (v)
19805 + movl %ecx, 4(v)
19806 +RET_ENDP
19807 #undef v
19808
19809 #define v %esi
19810 @@ -70,6 +78,20 @@ RET_ENDP
19811 BEGIN(add)
19812 addl %eax, (v)
19813 adcl %edx, 4(v)
19814 +
19815 +#ifdef CONFIG_PAX_REFCOUNT
19816 + jno 0f
19817 + subl %eax, (v)
19818 + sbbl %edx, 4(v)
19819 + int $4
19820 +0:
19821 + _ASM_EXTABLE(0b, 0b)
19822 +#endif
19823 +
19824 +RET_ENDP
19825 +BEGIN(add_unchecked)
19826 + addl %eax, (v)
19827 + adcl %edx, 4(v)
19828 RET_ENDP
19829 #undef v
19830
19831 @@ -77,6 +99,24 @@ RET_ENDP
19832 BEGIN(add_return)
19833 addl (v), %eax
19834 adcl 4(v), %edx
19835 +
19836 +#ifdef CONFIG_PAX_REFCOUNT
19837 + into
19838 +1234:
19839 + _ASM_EXTABLE(1234b, 2f)
19840 +#endif
19841 +
19842 + movl %eax, (v)
19843 + movl %edx, 4(v)
19844 +
19845 +#ifdef CONFIG_PAX_REFCOUNT
19846 +2:
19847 +#endif
19848 +
19849 +RET_ENDP
19850 +BEGIN(add_return_unchecked)
19851 + addl (v), %eax
19852 + adcl 4(v), %edx
19853 movl %eax, (v)
19854 movl %edx, 4(v)
19855 RET_ENDP
19856 @@ -86,6 +126,20 @@ RET_ENDP
19857 BEGIN(sub)
19858 subl %eax, (v)
19859 sbbl %edx, 4(v)
19860 +
19861 +#ifdef CONFIG_PAX_REFCOUNT
19862 + jno 0f
19863 + addl %eax, (v)
19864 + adcl %edx, 4(v)
19865 + int $4
19866 +0:
19867 + _ASM_EXTABLE(0b, 0b)
19868 +#endif
19869 +
19870 +RET_ENDP
19871 +BEGIN(sub_unchecked)
19872 + subl %eax, (v)
19873 + sbbl %edx, 4(v)
19874 RET_ENDP
19875 #undef v
19876
19877 @@ -96,6 +150,27 @@ BEGIN(sub_return)
19878 sbbl $0, %edx
19879 addl (v), %eax
19880 adcl 4(v), %edx
19881 +
19882 +#ifdef CONFIG_PAX_REFCOUNT
19883 + into
19884 +1234:
19885 + _ASM_EXTABLE(1234b, 2f)
19886 +#endif
19887 +
19888 + movl %eax, (v)
19889 + movl %edx, 4(v)
19890 +
19891 +#ifdef CONFIG_PAX_REFCOUNT
19892 +2:
19893 +#endif
19894 +
19895 +RET_ENDP
19896 +BEGIN(sub_return_unchecked)
19897 + negl %edx
19898 + negl %eax
19899 + sbbl $0, %edx
19900 + addl (v), %eax
19901 + adcl 4(v), %edx
19902 movl %eax, (v)
19903 movl %edx, 4(v)
19904 RET_ENDP
19905 @@ -105,6 +180,20 @@ RET_ENDP
19906 BEGIN(inc)
19907 addl $1, (v)
19908 adcl $0, 4(v)
19909 +
19910 +#ifdef CONFIG_PAX_REFCOUNT
19911 + jno 0f
19912 + subl $1, (v)
19913 + sbbl $0, 4(v)
19914 + int $4
19915 +0:
19916 + _ASM_EXTABLE(0b, 0b)
19917 +#endif
19918 +
19919 +RET_ENDP
19920 +BEGIN(inc_unchecked)
19921 + addl $1, (v)
19922 + adcl $0, 4(v)
19923 RET_ENDP
19924 #undef v
19925
19926 @@ -114,6 +203,26 @@ BEGIN(inc_return)
19927 movl 4(v), %edx
19928 addl $1, %eax
19929 adcl $0, %edx
19930 +
19931 +#ifdef CONFIG_PAX_REFCOUNT
19932 + into
19933 +1234:
19934 + _ASM_EXTABLE(1234b, 2f)
19935 +#endif
19936 +
19937 + movl %eax, (v)
19938 + movl %edx, 4(v)
19939 +
19940 +#ifdef CONFIG_PAX_REFCOUNT
19941 +2:
19942 +#endif
19943 +
19944 +RET_ENDP
19945 +BEGIN(inc_return_unchecked)
19946 + movl (v), %eax
19947 + movl 4(v), %edx
19948 + addl $1, %eax
19949 + adcl $0, %edx
19950 movl %eax, (v)
19951 movl %edx, 4(v)
19952 RET_ENDP
19953 @@ -123,6 +232,20 @@ RET_ENDP
19954 BEGIN(dec)
19955 subl $1, (v)
19956 sbbl $0, 4(v)
19957 +
19958 +#ifdef CONFIG_PAX_REFCOUNT
19959 + jno 0f
19960 + addl $1, (v)
19961 + adcl $0, 4(v)
19962 + int $4
19963 +0:
19964 + _ASM_EXTABLE(0b, 0b)
19965 +#endif
19966 +
19967 +RET_ENDP
19968 +BEGIN(dec_unchecked)
19969 + subl $1, (v)
19970 + sbbl $0, 4(v)
19971 RET_ENDP
19972 #undef v
19973
19974 @@ -132,6 +255,26 @@ BEGIN(dec_return)
19975 movl 4(v), %edx
19976 subl $1, %eax
19977 sbbl $0, %edx
19978 +
19979 +#ifdef CONFIG_PAX_REFCOUNT
19980 + into
19981 +1234:
19982 + _ASM_EXTABLE(1234b, 2f)
19983 +#endif
19984 +
19985 + movl %eax, (v)
19986 + movl %edx, 4(v)
19987 +
19988 +#ifdef CONFIG_PAX_REFCOUNT
19989 +2:
19990 +#endif
19991 +
19992 +RET_ENDP
19993 +BEGIN(dec_return_unchecked)
19994 + movl (v), %eax
19995 + movl 4(v), %edx
19996 + subl $1, %eax
19997 + sbbl $0, %edx
19998 movl %eax, (v)
19999 movl %edx, 4(v)
20000 RET_ENDP
20001 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20002 adcl %edx, %edi
20003 addl (v), %eax
20004 adcl 4(v), %edx
20005 +
20006 +#ifdef CONFIG_PAX_REFCOUNT
20007 + into
20008 +1234:
20009 + _ASM_EXTABLE(1234b, 2f)
20010 +#endif
20011 +
20012 cmpl %eax, %esi
20013 je 3f
20014 1:
20015 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20016 1:
20017 addl $1, %eax
20018 adcl $0, %edx
20019 +
20020 +#ifdef CONFIG_PAX_REFCOUNT
20021 + into
20022 +1234:
20023 + _ASM_EXTABLE(1234b, 2f)
20024 +#endif
20025 +
20026 movl %eax, (v)
20027 movl %edx, 4(v)
20028 movl $1, %eax
20029 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20030 movl 4(v), %edx
20031 subl $1, %eax
20032 sbbl $0, %edx
20033 +
20034 +#ifdef CONFIG_PAX_REFCOUNT
20035 + into
20036 +1234:
20037 + _ASM_EXTABLE(1234b, 1f)
20038 +#endif
20039 +
20040 js 1f
20041 movl %eax, (v)
20042 movl %edx, 4(v)
20043 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20044 index 391a083..d658e9f 100644
20045 --- a/arch/x86/lib/atomic64_cx8_32.S
20046 +++ b/arch/x86/lib/atomic64_cx8_32.S
20047 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20048 CFI_STARTPROC
20049
20050 read64 %ecx
20051 + pax_force_retaddr
20052 ret
20053 CFI_ENDPROC
20054 ENDPROC(atomic64_read_cx8)
20055
20056 +ENTRY(atomic64_read_unchecked_cx8)
20057 + CFI_STARTPROC
20058 +
20059 + read64 %ecx
20060 + pax_force_retaddr
20061 + ret
20062 + CFI_ENDPROC
20063 +ENDPROC(atomic64_read_unchecked_cx8)
20064 +
20065 ENTRY(atomic64_set_cx8)
20066 CFI_STARTPROC
20067
20068 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20069 cmpxchg8b (%esi)
20070 jne 1b
20071
20072 + pax_force_retaddr
20073 ret
20074 CFI_ENDPROC
20075 ENDPROC(atomic64_set_cx8)
20076
20077 +ENTRY(atomic64_set_unchecked_cx8)
20078 + CFI_STARTPROC
20079 +
20080 +1:
20081 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20082 + * are atomic on 586 and newer */
20083 + cmpxchg8b (%esi)
20084 + jne 1b
20085 +
20086 + pax_force_retaddr
20087 + ret
20088 + CFI_ENDPROC
20089 +ENDPROC(atomic64_set_unchecked_cx8)
20090 +
20091 ENTRY(atomic64_xchg_cx8)
20092 CFI_STARTPROC
20093
20094 @@ -62,12 +87,13 @@ ENTRY(atomic64_xchg_cx8)
20095 cmpxchg8b (%esi)
20096 jne 1b
20097
20098 + pax_force_retaddr
20099 ret
20100 CFI_ENDPROC
20101 ENDPROC(atomic64_xchg_cx8)
20102
20103 -.macro addsub_return func ins insc
20104 -ENTRY(atomic64_\func\()_return_cx8)
20105 +.macro addsub_return func ins insc unchecked=""
20106 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20107 CFI_STARTPROC
20108 SAVE ebp
20109 SAVE ebx
20110 @@ -84,27 +110,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20111 movl %edx, %ecx
20112 \ins\()l %esi, %ebx
20113 \insc\()l %edi, %ecx
20114 +
20115 +.ifb \unchecked
20116 +#ifdef CONFIG_PAX_REFCOUNT
20117 + into
20118 +2:
20119 + _ASM_EXTABLE(2b, 3f)
20120 +#endif
20121 +.endif
20122 +
20123 LOCK_PREFIX
20124 cmpxchg8b (%ebp)
20125 jne 1b
20126 -
20127 -10:
20128 movl %ebx, %eax
20129 movl %ecx, %edx
20130 +
20131 +.ifb \unchecked
20132 +#ifdef CONFIG_PAX_REFCOUNT
20133 +3:
20134 +#endif
20135 +.endif
20136 +
20137 RESTORE edi
20138 RESTORE esi
20139 RESTORE ebx
20140 RESTORE ebp
20141 + pax_force_retaddr
20142 ret
20143 CFI_ENDPROC
20144 -ENDPROC(atomic64_\func\()_return_cx8)
20145 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20146 .endm
20147
20148 addsub_return add add adc
20149 addsub_return sub sub sbb
20150 +addsub_return add add adc _unchecked
20151 +addsub_return sub sub sbb _unchecked
20152
20153 -.macro incdec_return func ins insc
20154 -ENTRY(atomic64_\func\()_return_cx8)
20155 +.macro incdec_return func ins insc unchecked
20156 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20157 CFI_STARTPROC
20158 SAVE ebx
20159
20160 @@ -114,21 +157,39 @@ ENTRY(atomic64_\func\()_return_cx8)
20161 movl %edx, %ecx
20162 \ins\()l $1, %ebx
20163 \insc\()l $0, %ecx
20164 +
20165 +.ifb \unchecked
20166 +#ifdef CONFIG_PAX_REFCOUNT
20167 + into
20168 +2:
20169 + _ASM_EXTABLE(2b, 3f)
20170 +#endif
20171 +.endif
20172 +
20173 LOCK_PREFIX
20174 cmpxchg8b (%esi)
20175 jne 1b
20176
20177 -10:
20178 movl %ebx, %eax
20179 movl %ecx, %edx
20180 +
20181 +.ifb \unchecked
20182 +#ifdef CONFIG_PAX_REFCOUNT
20183 +3:
20184 +#endif
20185 +.endif
20186 +
20187 RESTORE ebx
20188 + pax_force_retaddr
20189 ret
20190 CFI_ENDPROC
20191 -ENDPROC(atomic64_\func\()_return_cx8)
20192 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20193 .endm
20194
20195 incdec_return inc add adc
20196 incdec_return dec sub sbb
20197 +incdec_return inc add adc _unchecked
20198 +incdec_return dec sub sbb _unchecked
20199
20200 ENTRY(atomic64_dec_if_positive_cx8)
20201 CFI_STARTPROC
20202 @@ -140,6 +201,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
20203 movl %edx, %ecx
20204 subl $1, %ebx
20205 sbb $0, %ecx
20206 +
20207 +#ifdef CONFIG_PAX_REFCOUNT
20208 + into
20209 +1234:
20210 + _ASM_EXTABLE(1234b, 2f)
20211 +#endif
20212 +
20213 js 2f
20214 LOCK_PREFIX
20215 cmpxchg8b (%esi)
20216 @@ -149,6 +217,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
20217 movl %ebx, %eax
20218 movl %ecx, %edx
20219 RESTORE ebx
20220 + pax_force_retaddr
20221 ret
20222 CFI_ENDPROC
20223 ENDPROC(atomic64_dec_if_positive_cx8)
20224 @@ -174,6 +243,13 @@ ENTRY(atomic64_add_unless_cx8)
20225 movl %edx, %ecx
20226 addl %esi, %ebx
20227 adcl %edi, %ecx
20228 +
20229 +#ifdef CONFIG_PAX_REFCOUNT
20230 + into
20231 +1234:
20232 + _ASM_EXTABLE(1234b, 3f)
20233 +#endif
20234 +
20235 LOCK_PREFIX
20236 cmpxchg8b (%ebp)
20237 jne 1b
20238 @@ -184,6 +260,7 @@ ENTRY(atomic64_add_unless_cx8)
20239 CFI_ADJUST_CFA_OFFSET -8
20240 RESTORE ebx
20241 RESTORE ebp
20242 + pax_force_retaddr
20243 ret
20244 4:
20245 cmpl %edx, 4(%esp)
20246 @@ -206,6 +283,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
20247 movl %edx, %ecx
20248 addl $1, %ebx
20249 adcl $0, %ecx
20250 +
20251 +#ifdef CONFIG_PAX_REFCOUNT
20252 + into
20253 +1234:
20254 + _ASM_EXTABLE(1234b, 3f)
20255 +#endif
20256 +
20257 LOCK_PREFIX
20258 cmpxchg8b (%esi)
20259 jne 1b
20260 @@ -213,6 +297,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
20261 movl $1, %eax
20262 3:
20263 RESTORE ebx
20264 + pax_force_retaddr
20265 ret
20266 4:
20267 testl %edx, %edx
20268 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
20269 index 78d16a5..fbcf666 100644
20270 --- a/arch/x86/lib/checksum_32.S
20271 +++ b/arch/x86/lib/checksum_32.S
20272 @@ -28,7 +28,8 @@
20273 #include <linux/linkage.h>
20274 #include <asm/dwarf2.h>
20275 #include <asm/errno.h>
20276 -
20277 +#include <asm/segment.h>
20278 +
20279 /*
20280 * computes a partial checksum, e.g. for TCP/UDP fragments
20281 */
20282 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
20283
20284 #define ARGBASE 16
20285 #define FP 12
20286 -
20287 -ENTRY(csum_partial_copy_generic)
20288 +
20289 +ENTRY(csum_partial_copy_generic_to_user)
20290 CFI_STARTPROC
20291 +
20292 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20293 + pushl_cfi %gs
20294 + popl_cfi %es
20295 + jmp csum_partial_copy_generic
20296 +#endif
20297 +
20298 +ENTRY(csum_partial_copy_generic_from_user)
20299 +
20300 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20301 + pushl_cfi %gs
20302 + popl_cfi %ds
20303 +#endif
20304 +
20305 +ENTRY(csum_partial_copy_generic)
20306 subl $4,%esp
20307 CFI_ADJUST_CFA_OFFSET 4
20308 pushl_cfi %edi
20309 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
20310 jmp 4f
20311 SRC(1: movw (%esi), %bx )
20312 addl $2, %esi
20313 -DST( movw %bx, (%edi) )
20314 +DST( movw %bx, %es:(%edi) )
20315 addl $2, %edi
20316 addw %bx, %ax
20317 adcl $0, %eax
20318 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
20319 SRC(1: movl (%esi), %ebx )
20320 SRC( movl 4(%esi), %edx )
20321 adcl %ebx, %eax
20322 -DST( movl %ebx, (%edi) )
20323 +DST( movl %ebx, %es:(%edi) )
20324 adcl %edx, %eax
20325 -DST( movl %edx, 4(%edi) )
20326 +DST( movl %edx, %es:4(%edi) )
20327
20328 SRC( movl 8(%esi), %ebx )
20329 SRC( movl 12(%esi), %edx )
20330 adcl %ebx, %eax
20331 -DST( movl %ebx, 8(%edi) )
20332 +DST( movl %ebx, %es:8(%edi) )
20333 adcl %edx, %eax
20334 -DST( movl %edx, 12(%edi) )
20335 +DST( movl %edx, %es:12(%edi) )
20336
20337 SRC( movl 16(%esi), %ebx )
20338 SRC( movl 20(%esi), %edx )
20339 adcl %ebx, %eax
20340 -DST( movl %ebx, 16(%edi) )
20341 +DST( movl %ebx, %es:16(%edi) )
20342 adcl %edx, %eax
20343 -DST( movl %edx, 20(%edi) )
20344 +DST( movl %edx, %es:20(%edi) )
20345
20346 SRC( movl 24(%esi), %ebx )
20347 SRC( movl 28(%esi), %edx )
20348 adcl %ebx, %eax
20349 -DST( movl %ebx, 24(%edi) )
20350 +DST( movl %ebx, %es:24(%edi) )
20351 adcl %edx, %eax
20352 -DST( movl %edx, 28(%edi) )
20353 +DST( movl %edx, %es:28(%edi) )
20354
20355 lea 32(%esi), %esi
20356 lea 32(%edi), %edi
20357 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
20358 shrl $2, %edx # This clears CF
20359 SRC(3: movl (%esi), %ebx )
20360 adcl %ebx, %eax
20361 -DST( movl %ebx, (%edi) )
20362 +DST( movl %ebx, %es:(%edi) )
20363 lea 4(%esi), %esi
20364 lea 4(%edi), %edi
20365 dec %edx
20366 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
20367 jb 5f
20368 SRC( movw (%esi), %cx )
20369 leal 2(%esi), %esi
20370 -DST( movw %cx, (%edi) )
20371 +DST( movw %cx, %es:(%edi) )
20372 leal 2(%edi), %edi
20373 je 6f
20374 shll $16,%ecx
20375 SRC(5: movb (%esi), %cl )
20376 -DST( movb %cl, (%edi) )
20377 +DST( movb %cl, %es:(%edi) )
20378 6: addl %ecx, %eax
20379 adcl $0, %eax
20380 7:
20381 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
20382
20383 6001:
20384 movl ARGBASE+20(%esp), %ebx # src_err_ptr
20385 - movl $-EFAULT, (%ebx)
20386 + movl $-EFAULT, %ss:(%ebx)
20387
20388 # zero the complete destination - computing the rest
20389 # is too much work
20390 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
20391
20392 6002:
20393 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
20394 - movl $-EFAULT,(%ebx)
20395 + movl $-EFAULT,%ss:(%ebx)
20396 jmp 5000b
20397
20398 .previous
20399
20400 + pushl_cfi %ss
20401 + popl_cfi %ds
20402 + pushl_cfi %ss
20403 + popl_cfi %es
20404 popl_cfi %ebx
20405 CFI_RESTORE ebx
20406 popl_cfi %esi
20407 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
20408 popl_cfi %ecx # equivalent to addl $4,%esp
20409 ret
20410 CFI_ENDPROC
20411 -ENDPROC(csum_partial_copy_generic)
20412 +ENDPROC(csum_partial_copy_generic_to_user)
20413
20414 #else
20415
20416 /* Version for PentiumII/PPro */
20417
20418 #define ROUND1(x) \
20419 + nop; nop; nop; \
20420 SRC(movl x(%esi), %ebx ) ; \
20421 addl %ebx, %eax ; \
20422 - DST(movl %ebx, x(%edi) ) ;
20423 + DST(movl %ebx, %es:x(%edi)) ;
20424
20425 #define ROUND(x) \
20426 + nop; nop; nop; \
20427 SRC(movl x(%esi), %ebx ) ; \
20428 adcl %ebx, %eax ; \
20429 - DST(movl %ebx, x(%edi) ) ;
20430 + DST(movl %ebx, %es:x(%edi)) ;
20431
20432 #define ARGBASE 12
20433 -
20434 -ENTRY(csum_partial_copy_generic)
20435 +
20436 +ENTRY(csum_partial_copy_generic_to_user)
20437 CFI_STARTPROC
20438 +
20439 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20440 + pushl_cfi %gs
20441 + popl_cfi %es
20442 + jmp csum_partial_copy_generic
20443 +#endif
20444 +
20445 +ENTRY(csum_partial_copy_generic_from_user)
20446 +
20447 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20448 + pushl_cfi %gs
20449 + popl_cfi %ds
20450 +#endif
20451 +
20452 +ENTRY(csum_partial_copy_generic)
20453 pushl_cfi %ebx
20454 CFI_REL_OFFSET ebx, 0
20455 pushl_cfi %edi
20456 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
20457 subl %ebx, %edi
20458 lea -1(%esi),%edx
20459 andl $-32,%edx
20460 - lea 3f(%ebx,%ebx), %ebx
20461 + lea 3f(%ebx,%ebx,2), %ebx
20462 testl %esi, %esi
20463 jmp *%ebx
20464 1: addl $64,%esi
20465 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
20466 jb 5f
20467 SRC( movw (%esi), %dx )
20468 leal 2(%esi), %esi
20469 -DST( movw %dx, (%edi) )
20470 +DST( movw %dx, %es:(%edi) )
20471 leal 2(%edi), %edi
20472 je 6f
20473 shll $16,%edx
20474 5:
20475 SRC( movb (%esi), %dl )
20476 -DST( movb %dl, (%edi) )
20477 +DST( movb %dl, %es:(%edi) )
20478 6: addl %edx, %eax
20479 adcl $0, %eax
20480 7:
20481 .section .fixup, "ax"
20482 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
20483 - movl $-EFAULT, (%ebx)
20484 + movl $-EFAULT, %ss:(%ebx)
20485 # zero the complete destination (computing the rest is too much work)
20486 movl ARGBASE+8(%esp),%edi # dst
20487 movl ARGBASE+12(%esp),%ecx # len
20488 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
20489 rep; stosb
20490 jmp 7b
20491 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
20492 - movl $-EFAULT, (%ebx)
20493 + movl $-EFAULT, %ss:(%ebx)
20494 jmp 7b
20495 .previous
20496
20497 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20498 + pushl_cfi %ss
20499 + popl_cfi %ds
20500 + pushl_cfi %ss
20501 + popl_cfi %es
20502 +#endif
20503 +
20504 popl_cfi %esi
20505 CFI_RESTORE esi
20506 popl_cfi %edi
20507 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
20508 CFI_RESTORE ebx
20509 ret
20510 CFI_ENDPROC
20511 -ENDPROC(csum_partial_copy_generic)
20512 +ENDPROC(csum_partial_copy_generic_to_user)
20513
20514 #undef ROUND
20515 #undef ROUND1
20516 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
20517 index f2145cf..cea889d 100644
20518 --- a/arch/x86/lib/clear_page_64.S
20519 +++ b/arch/x86/lib/clear_page_64.S
20520 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
20521 movl $4096/8,%ecx
20522 xorl %eax,%eax
20523 rep stosq
20524 + pax_force_retaddr
20525 ret
20526 CFI_ENDPROC
20527 ENDPROC(clear_page_c)
20528 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
20529 movl $4096,%ecx
20530 xorl %eax,%eax
20531 rep stosb
20532 + pax_force_retaddr
20533 ret
20534 CFI_ENDPROC
20535 ENDPROC(clear_page_c_e)
20536 @@ -43,6 +45,7 @@ ENTRY(clear_page)
20537 leaq 64(%rdi),%rdi
20538 jnz .Lloop
20539 nop
20540 + pax_force_retaddr
20541 ret
20542 CFI_ENDPROC
20543 .Lclear_page_end:
20544 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
20545
20546 #include <asm/cpufeature.h>
20547
20548 - .section .altinstr_replacement,"ax"
20549 + .section .altinstr_replacement,"a"
20550 1: .byte 0xeb /* jmp <disp8> */
20551 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
20552 2: .byte 0xeb /* jmp <disp8> */
20553 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
20554 index 1e572c5..2a162cd 100644
20555 --- a/arch/x86/lib/cmpxchg16b_emu.S
20556 +++ b/arch/x86/lib/cmpxchg16b_emu.S
20557 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
20558
20559 popf
20560 mov $1, %al
20561 + pax_force_retaddr
20562 ret
20563
20564 not_same:
20565 popf
20566 xor %al,%al
20567 + pax_force_retaddr
20568 ret
20569
20570 CFI_ENDPROC
20571 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
20572 index 01c805b..dccb07f 100644
20573 --- a/arch/x86/lib/copy_page_64.S
20574 +++ b/arch/x86/lib/copy_page_64.S
20575 @@ -9,6 +9,7 @@ copy_page_c:
20576 CFI_STARTPROC
20577 movl $4096/8,%ecx
20578 rep movsq
20579 + pax_force_retaddr
20580 ret
20581 CFI_ENDPROC
20582 ENDPROC(copy_page_c)
20583 @@ -39,7 +40,7 @@ ENTRY(copy_page)
20584 movq 16 (%rsi), %rdx
20585 movq 24 (%rsi), %r8
20586 movq 32 (%rsi), %r9
20587 - movq 40 (%rsi), %r10
20588 + movq 40 (%rsi), %r13
20589 movq 48 (%rsi), %r11
20590 movq 56 (%rsi), %r12
20591
20592 @@ -50,7 +51,7 @@ ENTRY(copy_page)
20593 movq %rdx, 16 (%rdi)
20594 movq %r8, 24 (%rdi)
20595 movq %r9, 32 (%rdi)
20596 - movq %r10, 40 (%rdi)
20597 + movq %r13, 40 (%rdi)
20598 movq %r11, 48 (%rdi)
20599 movq %r12, 56 (%rdi)
20600
20601 @@ -69,7 +70,7 @@ ENTRY(copy_page)
20602 movq 16 (%rsi), %rdx
20603 movq 24 (%rsi), %r8
20604 movq 32 (%rsi), %r9
20605 - movq 40 (%rsi), %r10
20606 + movq 40 (%rsi), %r13
20607 movq 48 (%rsi), %r11
20608 movq 56 (%rsi), %r12
20609
20610 @@ -78,7 +79,7 @@ ENTRY(copy_page)
20611 movq %rdx, 16 (%rdi)
20612 movq %r8, 24 (%rdi)
20613 movq %r9, 32 (%rdi)
20614 - movq %r10, 40 (%rdi)
20615 + movq %r13, 40 (%rdi)
20616 movq %r11, 48 (%rdi)
20617 movq %r12, 56 (%rdi)
20618
20619 @@ -95,6 +96,7 @@ ENTRY(copy_page)
20620 CFI_RESTORE r13
20621 addq $3*8,%rsp
20622 CFI_ADJUST_CFA_OFFSET -3*8
20623 + pax_force_retaddr
20624 ret
20625 .Lcopy_page_end:
20626 CFI_ENDPROC
20627 @@ -105,7 +107,7 @@ ENDPROC(copy_page)
20628
20629 #include <asm/cpufeature.h>
20630
20631 - .section .altinstr_replacement,"ax"
20632 + .section .altinstr_replacement,"a"
20633 1: .byte 0xeb /* jmp <disp8> */
20634 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
20635 2:
20636 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
20637 index 0248402..821c786 100644
20638 --- a/arch/x86/lib/copy_user_64.S
20639 +++ b/arch/x86/lib/copy_user_64.S
20640 @@ -16,6 +16,7 @@
20641 #include <asm/thread_info.h>
20642 #include <asm/cpufeature.h>
20643 #include <asm/alternative-asm.h>
20644 +#include <asm/pgtable.h>
20645
20646 /*
20647 * By placing feature2 after feature1 in altinstructions section, we logically
20648 @@ -29,7 +30,7 @@
20649 .byte 0xe9 /* 32bit jump */
20650 .long \orig-1f /* by default jump to orig */
20651 1:
20652 - .section .altinstr_replacement,"ax"
20653 + .section .altinstr_replacement,"a"
20654 2: .byte 0xe9 /* near jump with 32bit immediate */
20655 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
20656 3: .byte 0xe9 /* near jump with 32bit immediate */
20657 @@ -71,47 +72,20 @@
20658 #endif
20659 .endm
20660
20661 -/* Standard copy_to_user with segment limit checking */
20662 -ENTRY(_copy_to_user)
20663 - CFI_STARTPROC
20664 - GET_THREAD_INFO(%rax)
20665 - movq %rdi,%rcx
20666 - addq %rdx,%rcx
20667 - jc bad_to_user
20668 - cmpq TI_addr_limit(%rax),%rcx
20669 - ja bad_to_user
20670 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
20671 - copy_user_generic_unrolled,copy_user_generic_string, \
20672 - copy_user_enhanced_fast_string
20673 - CFI_ENDPROC
20674 -ENDPROC(_copy_to_user)
20675 -
20676 -/* Standard copy_from_user with segment limit checking */
20677 -ENTRY(_copy_from_user)
20678 - CFI_STARTPROC
20679 - GET_THREAD_INFO(%rax)
20680 - movq %rsi,%rcx
20681 - addq %rdx,%rcx
20682 - jc bad_from_user
20683 - cmpq TI_addr_limit(%rax),%rcx
20684 - ja bad_from_user
20685 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
20686 - copy_user_generic_unrolled,copy_user_generic_string, \
20687 - copy_user_enhanced_fast_string
20688 - CFI_ENDPROC
20689 -ENDPROC(_copy_from_user)
20690 -
20691 .section .fixup,"ax"
20692 /* must zero dest */
20693 ENTRY(bad_from_user)
20694 bad_from_user:
20695 CFI_STARTPROC
20696 + testl %edx,%edx
20697 + js bad_to_user
20698 movl %edx,%ecx
20699 xorl %eax,%eax
20700 rep
20701 stosb
20702 bad_to_user:
20703 movl %edx,%eax
20704 + pax_force_retaddr
20705 ret
20706 CFI_ENDPROC
20707 ENDPROC(bad_from_user)
20708 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
20709 jz 17f
20710 1: movq (%rsi),%r8
20711 2: movq 1*8(%rsi),%r9
20712 -3: movq 2*8(%rsi),%r10
20713 +3: movq 2*8(%rsi),%rax
20714 4: movq 3*8(%rsi),%r11
20715 5: movq %r8,(%rdi)
20716 6: movq %r9,1*8(%rdi)
20717 -7: movq %r10,2*8(%rdi)
20718 +7: movq %rax,2*8(%rdi)
20719 8: movq %r11,3*8(%rdi)
20720 9: movq 4*8(%rsi),%r8
20721 10: movq 5*8(%rsi),%r9
20722 -11: movq 6*8(%rsi),%r10
20723 +11: movq 6*8(%rsi),%rax
20724 12: movq 7*8(%rsi),%r11
20725 13: movq %r8,4*8(%rdi)
20726 14: movq %r9,5*8(%rdi)
20727 -15: movq %r10,6*8(%rdi)
20728 +15: movq %rax,6*8(%rdi)
20729 16: movq %r11,7*8(%rdi)
20730 leaq 64(%rsi),%rsi
20731 leaq 64(%rdi),%rdi
20732 @@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
20733 decl %ecx
20734 jnz 21b
20735 23: xor %eax,%eax
20736 + pax_force_retaddr
20737 ret
20738
20739 .section .fixup,"ax"
20740 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
20741 3: rep
20742 movsb
20743 4: xorl %eax,%eax
20744 + pax_force_retaddr
20745 ret
20746
20747 .section .fixup,"ax"
20748 @@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
20749 1: rep
20750 movsb
20751 2: xorl %eax,%eax
20752 + pax_force_retaddr
20753 ret
20754
20755 .section .fixup,"ax"
20756 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
20757 index cb0c112..e3a6895 100644
20758 --- a/arch/x86/lib/copy_user_nocache_64.S
20759 +++ b/arch/x86/lib/copy_user_nocache_64.S
20760 @@ -8,12 +8,14 @@
20761
20762 #include <linux/linkage.h>
20763 #include <asm/dwarf2.h>
20764 +#include <asm/alternative-asm.h>
20765
20766 #define FIX_ALIGNMENT 1
20767
20768 #include <asm/current.h>
20769 #include <asm/asm-offsets.h>
20770 #include <asm/thread_info.h>
20771 +#include <asm/pgtable.h>
20772
20773 .macro ALIGN_DESTINATION
20774 #ifdef FIX_ALIGNMENT
20775 @@ -50,6 +52,15 @@
20776 */
20777 ENTRY(__copy_user_nocache)
20778 CFI_STARTPROC
20779 +
20780 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20781 + mov $PAX_USER_SHADOW_BASE,%rcx
20782 + cmp %rcx,%rsi
20783 + jae 1f
20784 + add %rcx,%rsi
20785 +1:
20786 +#endif
20787 +
20788 cmpl $8,%edx
20789 jb 20f /* less then 8 bytes, go to byte copy loop */
20790 ALIGN_DESTINATION
20791 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
20792 jz 17f
20793 1: movq (%rsi),%r8
20794 2: movq 1*8(%rsi),%r9
20795 -3: movq 2*8(%rsi),%r10
20796 +3: movq 2*8(%rsi),%rax
20797 4: movq 3*8(%rsi),%r11
20798 5: movnti %r8,(%rdi)
20799 6: movnti %r9,1*8(%rdi)
20800 -7: movnti %r10,2*8(%rdi)
20801 +7: movnti %rax,2*8(%rdi)
20802 8: movnti %r11,3*8(%rdi)
20803 9: movq 4*8(%rsi),%r8
20804 10: movq 5*8(%rsi),%r9
20805 -11: movq 6*8(%rsi),%r10
20806 +11: movq 6*8(%rsi),%rax
20807 12: movq 7*8(%rsi),%r11
20808 13: movnti %r8,4*8(%rdi)
20809 14: movnti %r9,5*8(%rdi)
20810 -15: movnti %r10,6*8(%rdi)
20811 +15: movnti %rax,6*8(%rdi)
20812 16: movnti %r11,7*8(%rdi)
20813 leaq 64(%rsi),%rsi
20814 leaq 64(%rdi),%rdi
20815 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
20816 jnz 21b
20817 23: xorl %eax,%eax
20818 sfence
20819 + pax_force_retaddr
20820 ret
20821
20822 .section .fixup,"ax"
20823 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
20824 index fb903b7..c92b7f7 100644
20825 --- a/arch/x86/lib/csum-copy_64.S
20826 +++ b/arch/x86/lib/csum-copy_64.S
20827 @@ -8,6 +8,7 @@
20828 #include <linux/linkage.h>
20829 #include <asm/dwarf2.h>
20830 #include <asm/errno.h>
20831 +#include <asm/alternative-asm.h>
20832
20833 /*
20834 * Checksum copy with exception handling.
20835 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
20836 CFI_RESTORE rbp
20837 addq $7*8, %rsp
20838 CFI_ADJUST_CFA_OFFSET -7*8
20839 + pax_force_retaddr 0, 1
20840 ret
20841 CFI_RESTORE_STATE
20842
20843 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
20844 index 459b58a..9570bc7 100644
20845 --- a/arch/x86/lib/csum-wrappers_64.c
20846 +++ b/arch/x86/lib/csum-wrappers_64.c
20847 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
20848 len -= 2;
20849 }
20850 }
20851 - isum = csum_partial_copy_generic((__force const void *)src,
20852 +
20853 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20854 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
20855 + src += PAX_USER_SHADOW_BASE;
20856 +#endif
20857 +
20858 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
20859 dst, len, isum, errp, NULL);
20860 if (unlikely(*errp))
20861 goto out_err;
20862 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
20863 }
20864
20865 *errp = 0;
20866 - return csum_partial_copy_generic(src, (void __force *)dst,
20867 +
20868 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20869 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
20870 + dst += PAX_USER_SHADOW_BASE;
20871 +#endif
20872 +
20873 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
20874 len, isum, NULL, errp);
20875 }
20876 EXPORT_SYMBOL(csum_partial_copy_to_user);
20877 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
20878 index 51f1504..ddac4c1 100644
20879 --- a/arch/x86/lib/getuser.S
20880 +++ b/arch/x86/lib/getuser.S
20881 @@ -33,15 +33,38 @@
20882 #include <asm/asm-offsets.h>
20883 #include <asm/thread_info.h>
20884 #include <asm/asm.h>
20885 +#include <asm/segment.h>
20886 +#include <asm/pgtable.h>
20887 +#include <asm/alternative-asm.h>
20888 +
20889 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20890 +#define __copyuser_seg gs;
20891 +#else
20892 +#define __copyuser_seg
20893 +#endif
20894
20895 .text
20896 ENTRY(__get_user_1)
20897 CFI_STARTPROC
20898 +
20899 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20900 GET_THREAD_INFO(%_ASM_DX)
20901 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
20902 jae bad_get_user
20903 -1: movzb (%_ASM_AX),%edx
20904 +
20905 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20906 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
20907 + cmp %_ASM_DX,%_ASM_AX
20908 + jae 1234f
20909 + add %_ASM_DX,%_ASM_AX
20910 +1234:
20911 +#endif
20912 +
20913 +#endif
20914 +
20915 +1: __copyuser_seg movzb (%_ASM_AX),%edx
20916 xor %eax,%eax
20917 + pax_force_retaddr
20918 ret
20919 CFI_ENDPROC
20920 ENDPROC(__get_user_1)
20921 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
20922 ENTRY(__get_user_2)
20923 CFI_STARTPROC
20924 add $1,%_ASM_AX
20925 +
20926 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20927 jc bad_get_user
20928 GET_THREAD_INFO(%_ASM_DX)
20929 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
20930 jae bad_get_user
20931 -2: movzwl -1(%_ASM_AX),%edx
20932 +
20933 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20934 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
20935 + cmp %_ASM_DX,%_ASM_AX
20936 + jae 1234f
20937 + add %_ASM_DX,%_ASM_AX
20938 +1234:
20939 +#endif
20940 +
20941 +#endif
20942 +
20943 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
20944 xor %eax,%eax
20945 + pax_force_retaddr
20946 ret
20947 CFI_ENDPROC
20948 ENDPROC(__get_user_2)
20949 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
20950 ENTRY(__get_user_4)
20951 CFI_STARTPROC
20952 add $3,%_ASM_AX
20953 +
20954 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20955 jc bad_get_user
20956 GET_THREAD_INFO(%_ASM_DX)
20957 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
20958 jae bad_get_user
20959 -3: mov -3(%_ASM_AX),%edx
20960 +
20961 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20962 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
20963 + cmp %_ASM_DX,%_ASM_AX
20964 + jae 1234f
20965 + add %_ASM_DX,%_ASM_AX
20966 +1234:
20967 +#endif
20968 +
20969 +#endif
20970 +
20971 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
20972 xor %eax,%eax
20973 + pax_force_retaddr
20974 ret
20975 CFI_ENDPROC
20976 ENDPROC(__get_user_4)
20977 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
20978 GET_THREAD_INFO(%_ASM_DX)
20979 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
20980 jae bad_get_user
20981 +
20982 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20983 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
20984 + cmp %_ASM_DX,%_ASM_AX
20985 + jae 1234f
20986 + add %_ASM_DX,%_ASM_AX
20987 +1234:
20988 +#endif
20989 +
20990 4: movq -7(%_ASM_AX),%_ASM_DX
20991 xor %eax,%eax
20992 + pax_force_retaddr
20993 ret
20994 CFI_ENDPROC
20995 ENDPROC(__get_user_8)
20996 @@ -91,6 +152,7 @@ bad_get_user:
20997 CFI_STARTPROC
20998 xor %edx,%edx
20999 mov $(-EFAULT),%_ASM_AX
21000 + pax_force_retaddr
21001 ret
21002 CFI_ENDPROC
21003 END(bad_get_user)
21004 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21005 index 374562e..a75830b 100644
21006 --- a/arch/x86/lib/insn.c
21007 +++ b/arch/x86/lib/insn.c
21008 @@ -21,6 +21,11 @@
21009 #include <linux/string.h>
21010 #include <asm/inat.h>
21011 #include <asm/insn.h>
21012 +#ifdef __KERNEL__
21013 +#include <asm/pgtable_types.h>
21014 +#else
21015 +#define ktla_ktva(addr) addr
21016 +#endif
21017
21018 /* Verify next sizeof(t) bytes can be on the same instruction */
21019 #define validate_next(t, insn, n) \
21020 @@ -49,8 +54,8 @@
21021 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21022 {
21023 memset(insn, 0, sizeof(*insn));
21024 - insn->kaddr = kaddr;
21025 - insn->next_byte = kaddr;
21026 + insn->kaddr = ktla_ktva(kaddr);
21027 + insn->next_byte = ktla_ktva(kaddr);
21028 insn->x86_64 = x86_64 ? 1 : 0;
21029 insn->opnd_bytes = 4;
21030 if (x86_64)
21031 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21032 index 05a95e7..326f2fa 100644
21033 --- a/arch/x86/lib/iomap_copy_64.S
21034 +++ b/arch/x86/lib/iomap_copy_64.S
21035 @@ -17,6 +17,7 @@
21036
21037 #include <linux/linkage.h>
21038 #include <asm/dwarf2.h>
21039 +#include <asm/alternative-asm.h>
21040
21041 /*
21042 * override generic version in lib/iomap_copy.c
21043 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21044 CFI_STARTPROC
21045 movl %edx,%ecx
21046 rep movsd
21047 + pax_force_retaddr
21048 ret
21049 CFI_ENDPROC
21050 ENDPROC(__iowrite32_copy)
21051 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21052 index efbf2a0..8893637 100644
21053 --- a/arch/x86/lib/memcpy_64.S
21054 +++ b/arch/x86/lib/memcpy_64.S
21055 @@ -34,6 +34,7 @@
21056 rep movsq
21057 movl %edx, %ecx
21058 rep movsb
21059 + pax_force_retaddr
21060 ret
21061 .Lmemcpy_e:
21062 .previous
21063 @@ -51,6 +52,7 @@
21064
21065 movl %edx, %ecx
21066 rep movsb
21067 + pax_force_retaddr
21068 ret
21069 .Lmemcpy_e_e:
21070 .previous
21071 @@ -81,13 +83,13 @@ ENTRY(memcpy)
21072 */
21073 movq 0*8(%rsi), %r8
21074 movq 1*8(%rsi), %r9
21075 - movq 2*8(%rsi), %r10
21076 + movq 2*8(%rsi), %rcx
21077 movq 3*8(%rsi), %r11
21078 leaq 4*8(%rsi), %rsi
21079
21080 movq %r8, 0*8(%rdi)
21081 movq %r9, 1*8(%rdi)
21082 - movq %r10, 2*8(%rdi)
21083 + movq %rcx, 2*8(%rdi)
21084 movq %r11, 3*8(%rdi)
21085 leaq 4*8(%rdi), %rdi
21086 jae .Lcopy_forward_loop
21087 @@ -110,12 +112,12 @@ ENTRY(memcpy)
21088 subq $0x20, %rdx
21089 movq -1*8(%rsi), %r8
21090 movq -2*8(%rsi), %r9
21091 - movq -3*8(%rsi), %r10
21092 + movq -3*8(%rsi), %rcx
21093 movq -4*8(%rsi), %r11
21094 leaq -4*8(%rsi), %rsi
21095 movq %r8, -1*8(%rdi)
21096 movq %r9, -2*8(%rdi)
21097 - movq %r10, -3*8(%rdi)
21098 + movq %rcx, -3*8(%rdi)
21099 movq %r11, -4*8(%rdi)
21100 leaq -4*8(%rdi), %rdi
21101 jae .Lcopy_backward_loop
21102 @@ -135,12 +137,13 @@ ENTRY(memcpy)
21103 */
21104 movq 0*8(%rsi), %r8
21105 movq 1*8(%rsi), %r9
21106 - movq -2*8(%rsi, %rdx), %r10
21107 + movq -2*8(%rsi, %rdx), %rcx
21108 movq -1*8(%rsi, %rdx), %r11
21109 movq %r8, 0*8(%rdi)
21110 movq %r9, 1*8(%rdi)
21111 - movq %r10, -2*8(%rdi, %rdx)
21112 + movq %rcx, -2*8(%rdi, %rdx)
21113 movq %r11, -1*8(%rdi, %rdx)
21114 + pax_force_retaddr
21115 retq
21116 .p2align 4
21117 .Lless_16bytes:
21118 @@ -153,6 +156,7 @@ ENTRY(memcpy)
21119 movq -1*8(%rsi, %rdx), %r9
21120 movq %r8, 0*8(%rdi)
21121 movq %r9, -1*8(%rdi, %rdx)
21122 + pax_force_retaddr
21123 retq
21124 .p2align 4
21125 .Lless_8bytes:
21126 @@ -166,6 +170,7 @@ ENTRY(memcpy)
21127 movl -4(%rsi, %rdx), %r8d
21128 movl %ecx, (%rdi)
21129 movl %r8d, -4(%rdi, %rdx)
21130 + pax_force_retaddr
21131 retq
21132 .p2align 4
21133 .Lless_3bytes:
21134 @@ -183,6 +188,7 @@ ENTRY(memcpy)
21135 jnz .Lloop_1
21136
21137 .Lend:
21138 + pax_force_retaddr
21139 retq
21140 CFI_ENDPROC
21141 ENDPROC(memcpy)
21142 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
21143 index ee16461..c39c199 100644
21144 --- a/arch/x86/lib/memmove_64.S
21145 +++ b/arch/x86/lib/memmove_64.S
21146 @@ -61,13 +61,13 @@ ENTRY(memmove)
21147 5:
21148 sub $0x20, %rdx
21149 movq 0*8(%rsi), %r11
21150 - movq 1*8(%rsi), %r10
21151 + movq 1*8(%rsi), %rcx
21152 movq 2*8(%rsi), %r9
21153 movq 3*8(%rsi), %r8
21154 leaq 4*8(%rsi), %rsi
21155
21156 movq %r11, 0*8(%rdi)
21157 - movq %r10, 1*8(%rdi)
21158 + movq %rcx, 1*8(%rdi)
21159 movq %r9, 2*8(%rdi)
21160 movq %r8, 3*8(%rdi)
21161 leaq 4*8(%rdi), %rdi
21162 @@ -81,10 +81,10 @@ ENTRY(memmove)
21163 4:
21164 movq %rdx, %rcx
21165 movq -8(%rsi, %rdx), %r11
21166 - lea -8(%rdi, %rdx), %r10
21167 + lea -8(%rdi, %rdx), %r9
21168 shrq $3, %rcx
21169 rep movsq
21170 - movq %r11, (%r10)
21171 + movq %r11, (%r9)
21172 jmp 13f
21173 .Lmemmove_end_forward:
21174
21175 @@ -95,14 +95,14 @@ ENTRY(memmove)
21176 7:
21177 movq %rdx, %rcx
21178 movq (%rsi), %r11
21179 - movq %rdi, %r10
21180 + movq %rdi, %r9
21181 leaq -8(%rsi, %rdx), %rsi
21182 leaq -8(%rdi, %rdx), %rdi
21183 shrq $3, %rcx
21184 std
21185 rep movsq
21186 cld
21187 - movq %r11, (%r10)
21188 + movq %r11, (%r9)
21189 jmp 13f
21190
21191 /*
21192 @@ -127,13 +127,13 @@ ENTRY(memmove)
21193 8:
21194 subq $0x20, %rdx
21195 movq -1*8(%rsi), %r11
21196 - movq -2*8(%rsi), %r10
21197 + movq -2*8(%rsi), %rcx
21198 movq -3*8(%rsi), %r9
21199 movq -4*8(%rsi), %r8
21200 leaq -4*8(%rsi), %rsi
21201
21202 movq %r11, -1*8(%rdi)
21203 - movq %r10, -2*8(%rdi)
21204 + movq %rcx, -2*8(%rdi)
21205 movq %r9, -3*8(%rdi)
21206 movq %r8, -4*8(%rdi)
21207 leaq -4*8(%rdi), %rdi
21208 @@ -151,11 +151,11 @@ ENTRY(memmove)
21209 * Move data from 16 bytes to 31 bytes.
21210 */
21211 movq 0*8(%rsi), %r11
21212 - movq 1*8(%rsi), %r10
21213 + movq 1*8(%rsi), %rcx
21214 movq -2*8(%rsi, %rdx), %r9
21215 movq -1*8(%rsi, %rdx), %r8
21216 movq %r11, 0*8(%rdi)
21217 - movq %r10, 1*8(%rdi)
21218 + movq %rcx, 1*8(%rdi)
21219 movq %r9, -2*8(%rdi, %rdx)
21220 movq %r8, -1*8(%rdi, %rdx)
21221 jmp 13f
21222 @@ -167,9 +167,9 @@ ENTRY(memmove)
21223 * Move data from 8 bytes to 15 bytes.
21224 */
21225 movq 0*8(%rsi), %r11
21226 - movq -1*8(%rsi, %rdx), %r10
21227 + movq -1*8(%rsi, %rdx), %r9
21228 movq %r11, 0*8(%rdi)
21229 - movq %r10, -1*8(%rdi, %rdx)
21230 + movq %r9, -1*8(%rdi, %rdx)
21231 jmp 13f
21232 10:
21233 cmpq $4, %rdx
21234 @@ -178,9 +178,9 @@ ENTRY(memmove)
21235 * Move data from 4 bytes to 7 bytes.
21236 */
21237 movl (%rsi), %r11d
21238 - movl -4(%rsi, %rdx), %r10d
21239 + movl -4(%rsi, %rdx), %r9d
21240 movl %r11d, (%rdi)
21241 - movl %r10d, -4(%rdi, %rdx)
21242 + movl %r9d, -4(%rdi, %rdx)
21243 jmp 13f
21244 11:
21245 cmp $2, %rdx
21246 @@ -189,9 +189,9 @@ ENTRY(memmove)
21247 * Move data from 2 bytes to 3 bytes.
21248 */
21249 movw (%rsi), %r11w
21250 - movw -2(%rsi, %rdx), %r10w
21251 + movw -2(%rsi, %rdx), %r9w
21252 movw %r11w, (%rdi)
21253 - movw %r10w, -2(%rdi, %rdx)
21254 + movw %r9w, -2(%rdi, %rdx)
21255 jmp 13f
21256 12:
21257 cmp $1, %rdx
21258 @@ -202,6 +202,7 @@ ENTRY(memmove)
21259 movb (%rsi), %r11b
21260 movb %r11b, (%rdi)
21261 13:
21262 + pax_force_retaddr
21263 retq
21264 CFI_ENDPROC
21265
21266 @@ -210,6 +211,7 @@ ENTRY(memmove)
21267 /* Forward moving data. */
21268 movq %rdx, %rcx
21269 rep movsb
21270 + pax_force_retaddr
21271 retq
21272 .Lmemmove_end_forward_efs:
21273 .previous
21274 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
21275 index 79bd454..dff325a 100644
21276 --- a/arch/x86/lib/memset_64.S
21277 +++ b/arch/x86/lib/memset_64.S
21278 @@ -31,6 +31,7 @@
21279 movl %r8d,%ecx
21280 rep stosb
21281 movq %r9,%rax
21282 + pax_force_retaddr
21283 ret
21284 .Lmemset_e:
21285 .previous
21286 @@ -53,6 +54,7 @@
21287 movl %edx,%ecx
21288 rep stosb
21289 movq %r9,%rax
21290 + pax_force_retaddr
21291 ret
21292 .Lmemset_e_e:
21293 .previous
21294 @@ -60,13 +62,13 @@
21295 ENTRY(memset)
21296 ENTRY(__memset)
21297 CFI_STARTPROC
21298 - movq %rdi,%r10
21299 movq %rdx,%r11
21300
21301 /* expand byte value */
21302 movzbl %sil,%ecx
21303 movabs $0x0101010101010101,%rax
21304 mul %rcx /* with rax, clobbers rdx */
21305 + movq %rdi,%rdx
21306
21307 /* align dst */
21308 movl %edi,%r9d
21309 @@ -120,7 +122,8 @@ ENTRY(__memset)
21310 jnz .Lloop_1
21311
21312 .Lende:
21313 - movq %r10,%rax
21314 + movq %rdx,%rax
21315 + pax_force_retaddr
21316 ret
21317
21318 CFI_RESTORE_STATE
21319 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
21320 index c9f2d9b..e7fd2c0 100644
21321 --- a/arch/x86/lib/mmx_32.c
21322 +++ b/arch/x86/lib/mmx_32.c
21323 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
21324 {
21325 void *p;
21326 int i;
21327 + unsigned long cr0;
21328
21329 if (unlikely(in_interrupt()))
21330 return __memcpy(to, from, len);
21331 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
21332 kernel_fpu_begin();
21333
21334 __asm__ __volatile__ (
21335 - "1: prefetch (%0)\n" /* This set is 28 bytes */
21336 - " prefetch 64(%0)\n"
21337 - " prefetch 128(%0)\n"
21338 - " prefetch 192(%0)\n"
21339 - " prefetch 256(%0)\n"
21340 + "1: prefetch (%1)\n" /* This set is 28 bytes */
21341 + " prefetch 64(%1)\n"
21342 + " prefetch 128(%1)\n"
21343 + " prefetch 192(%1)\n"
21344 + " prefetch 256(%1)\n"
21345 "2: \n"
21346 ".section .fixup, \"ax\"\n"
21347 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21348 + "3: \n"
21349 +
21350 +#ifdef CONFIG_PAX_KERNEXEC
21351 + " movl %%cr0, %0\n"
21352 + " movl %0, %%eax\n"
21353 + " andl $0xFFFEFFFF, %%eax\n"
21354 + " movl %%eax, %%cr0\n"
21355 +#endif
21356 +
21357 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21358 +
21359 +#ifdef CONFIG_PAX_KERNEXEC
21360 + " movl %0, %%cr0\n"
21361 +#endif
21362 +
21363 " jmp 2b\n"
21364 ".previous\n"
21365 _ASM_EXTABLE(1b, 3b)
21366 - : : "r" (from));
21367 + : "=&r" (cr0) : "r" (from) : "ax");
21368
21369 for ( ; i > 5; i--) {
21370 __asm__ __volatile__ (
21371 - "1: prefetch 320(%0)\n"
21372 - "2: movq (%0), %%mm0\n"
21373 - " movq 8(%0), %%mm1\n"
21374 - " movq 16(%0), %%mm2\n"
21375 - " movq 24(%0), %%mm3\n"
21376 - " movq %%mm0, (%1)\n"
21377 - " movq %%mm1, 8(%1)\n"
21378 - " movq %%mm2, 16(%1)\n"
21379 - " movq %%mm3, 24(%1)\n"
21380 - " movq 32(%0), %%mm0\n"
21381 - " movq 40(%0), %%mm1\n"
21382 - " movq 48(%0), %%mm2\n"
21383 - " movq 56(%0), %%mm3\n"
21384 - " movq %%mm0, 32(%1)\n"
21385 - " movq %%mm1, 40(%1)\n"
21386 - " movq %%mm2, 48(%1)\n"
21387 - " movq %%mm3, 56(%1)\n"
21388 + "1: prefetch 320(%1)\n"
21389 + "2: movq (%1), %%mm0\n"
21390 + " movq 8(%1), %%mm1\n"
21391 + " movq 16(%1), %%mm2\n"
21392 + " movq 24(%1), %%mm3\n"
21393 + " movq %%mm0, (%2)\n"
21394 + " movq %%mm1, 8(%2)\n"
21395 + " movq %%mm2, 16(%2)\n"
21396 + " movq %%mm3, 24(%2)\n"
21397 + " movq 32(%1), %%mm0\n"
21398 + " movq 40(%1), %%mm1\n"
21399 + " movq 48(%1), %%mm2\n"
21400 + " movq 56(%1), %%mm3\n"
21401 + " movq %%mm0, 32(%2)\n"
21402 + " movq %%mm1, 40(%2)\n"
21403 + " movq %%mm2, 48(%2)\n"
21404 + " movq %%mm3, 56(%2)\n"
21405 ".section .fixup, \"ax\"\n"
21406 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21407 + "3:\n"
21408 +
21409 +#ifdef CONFIG_PAX_KERNEXEC
21410 + " movl %%cr0, %0\n"
21411 + " movl %0, %%eax\n"
21412 + " andl $0xFFFEFFFF, %%eax\n"
21413 + " movl %%eax, %%cr0\n"
21414 +#endif
21415 +
21416 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21417 +
21418 +#ifdef CONFIG_PAX_KERNEXEC
21419 + " movl %0, %%cr0\n"
21420 +#endif
21421 +
21422 " jmp 2b\n"
21423 ".previous\n"
21424 _ASM_EXTABLE(1b, 3b)
21425 - : : "r" (from), "r" (to) : "memory");
21426 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
21427
21428 from += 64;
21429 to += 64;
21430 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
21431 static void fast_copy_page(void *to, void *from)
21432 {
21433 int i;
21434 + unsigned long cr0;
21435
21436 kernel_fpu_begin();
21437
21438 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
21439 * but that is for later. -AV
21440 */
21441 __asm__ __volatile__(
21442 - "1: prefetch (%0)\n"
21443 - " prefetch 64(%0)\n"
21444 - " prefetch 128(%0)\n"
21445 - " prefetch 192(%0)\n"
21446 - " prefetch 256(%0)\n"
21447 + "1: prefetch (%1)\n"
21448 + " prefetch 64(%1)\n"
21449 + " prefetch 128(%1)\n"
21450 + " prefetch 192(%1)\n"
21451 + " prefetch 256(%1)\n"
21452 "2: \n"
21453 ".section .fixup, \"ax\"\n"
21454 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21455 + "3: \n"
21456 +
21457 +#ifdef CONFIG_PAX_KERNEXEC
21458 + " movl %%cr0, %0\n"
21459 + " movl %0, %%eax\n"
21460 + " andl $0xFFFEFFFF, %%eax\n"
21461 + " movl %%eax, %%cr0\n"
21462 +#endif
21463 +
21464 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21465 +
21466 +#ifdef CONFIG_PAX_KERNEXEC
21467 + " movl %0, %%cr0\n"
21468 +#endif
21469 +
21470 " jmp 2b\n"
21471 ".previous\n"
21472 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
21473 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
21474
21475 for (i = 0; i < (4096-320)/64; i++) {
21476 __asm__ __volatile__ (
21477 - "1: prefetch 320(%0)\n"
21478 - "2: movq (%0), %%mm0\n"
21479 - " movntq %%mm0, (%1)\n"
21480 - " movq 8(%0), %%mm1\n"
21481 - " movntq %%mm1, 8(%1)\n"
21482 - " movq 16(%0), %%mm2\n"
21483 - " movntq %%mm2, 16(%1)\n"
21484 - " movq 24(%0), %%mm3\n"
21485 - " movntq %%mm3, 24(%1)\n"
21486 - " movq 32(%0), %%mm4\n"
21487 - " movntq %%mm4, 32(%1)\n"
21488 - " movq 40(%0), %%mm5\n"
21489 - " movntq %%mm5, 40(%1)\n"
21490 - " movq 48(%0), %%mm6\n"
21491 - " movntq %%mm6, 48(%1)\n"
21492 - " movq 56(%0), %%mm7\n"
21493 - " movntq %%mm7, 56(%1)\n"
21494 + "1: prefetch 320(%1)\n"
21495 + "2: movq (%1), %%mm0\n"
21496 + " movntq %%mm0, (%2)\n"
21497 + " movq 8(%1), %%mm1\n"
21498 + " movntq %%mm1, 8(%2)\n"
21499 + " movq 16(%1), %%mm2\n"
21500 + " movntq %%mm2, 16(%2)\n"
21501 + " movq 24(%1), %%mm3\n"
21502 + " movntq %%mm3, 24(%2)\n"
21503 + " movq 32(%1), %%mm4\n"
21504 + " movntq %%mm4, 32(%2)\n"
21505 + " movq 40(%1), %%mm5\n"
21506 + " movntq %%mm5, 40(%2)\n"
21507 + " movq 48(%1), %%mm6\n"
21508 + " movntq %%mm6, 48(%2)\n"
21509 + " movq 56(%1), %%mm7\n"
21510 + " movntq %%mm7, 56(%2)\n"
21511 ".section .fixup, \"ax\"\n"
21512 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21513 + "3:\n"
21514 +
21515 +#ifdef CONFIG_PAX_KERNEXEC
21516 + " movl %%cr0, %0\n"
21517 + " movl %0, %%eax\n"
21518 + " andl $0xFFFEFFFF, %%eax\n"
21519 + " movl %%eax, %%cr0\n"
21520 +#endif
21521 +
21522 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21523 +
21524 +#ifdef CONFIG_PAX_KERNEXEC
21525 + " movl %0, %%cr0\n"
21526 +#endif
21527 +
21528 " jmp 2b\n"
21529 ".previous\n"
21530 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
21531 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
21532
21533 from += 64;
21534 to += 64;
21535 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
21536 static void fast_copy_page(void *to, void *from)
21537 {
21538 int i;
21539 + unsigned long cr0;
21540
21541 kernel_fpu_begin();
21542
21543 __asm__ __volatile__ (
21544 - "1: prefetch (%0)\n"
21545 - " prefetch 64(%0)\n"
21546 - " prefetch 128(%0)\n"
21547 - " prefetch 192(%0)\n"
21548 - " prefetch 256(%0)\n"
21549 + "1: prefetch (%1)\n"
21550 + " prefetch 64(%1)\n"
21551 + " prefetch 128(%1)\n"
21552 + " prefetch 192(%1)\n"
21553 + " prefetch 256(%1)\n"
21554 "2: \n"
21555 ".section .fixup, \"ax\"\n"
21556 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21557 + "3: \n"
21558 +
21559 +#ifdef CONFIG_PAX_KERNEXEC
21560 + " movl %%cr0, %0\n"
21561 + " movl %0, %%eax\n"
21562 + " andl $0xFFFEFFFF, %%eax\n"
21563 + " movl %%eax, %%cr0\n"
21564 +#endif
21565 +
21566 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21567 +
21568 +#ifdef CONFIG_PAX_KERNEXEC
21569 + " movl %0, %%cr0\n"
21570 +#endif
21571 +
21572 " jmp 2b\n"
21573 ".previous\n"
21574 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
21575 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
21576
21577 for (i = 0; i < 4096/64; i++) {
21578 __asm__ __volatile__ (
21579 - "1: prefetch 320(%0)\n"
21580 - "2: movq (%0), %%mm0\n"
21581 - " movq 8(%0), %%mm1\n"
21582 - " movq 16(%0), %%mm2\n"
21583 - " movq 24(%0), %%mm3\n"
21584 - " movq %%mm0, (%1)\n"
21585 - " movq %%mm1, 8(%1)\n"
21586 - " movq %%mm2, 16(%1)\n"
21587 - " movq %%mm3, 24(%1)\n"
21588 - " movq 32(%0), %%mm0\n"
21589 - " movq 40(%0), %%mm1\n"
21590 - " movq 48(%0), %%mm2\n"
21591 - " movq 56(%0), %%mm3\n"
21592 - " movq %%mm0, 32(%1)\n"
21593 - " movq %%mm1, 40(%1)\n"
21594 - " movq %%mm2, 48(%1)\n"
21595 - " movq %%mm3, 56(%1)\n"
21596 + "1: prefetch 320(%1)\n"
21597 + "2: movq (%1), %%mm0\n"
21598 + " movq 8(%1), %%mm1\n"
21599 + " movq 16(%1), %%mm2\n"
21600 + " movq 24(%1), %%mm3\n"
21601 + " movq %%mm0, (%2)\n"
21602 + " movq %%mm1, 8(%2)\n"
21603 + " movq %%mm2, 16(%2)\n"
21604 + " movq %%mm3, 24(%2)\n"
21605 + " movq 32(%1), %%mm0\n"
21606 + " movq 40(%1), %%mm1\n"
21607 + " movq 48(%1), %%mm2\n"
21608 + " movq 56(%1), %%mm3\n"
21609 + " movq %%mm0, 32(%2)\n"
21610 + " movq %%mm1, 40(%2)\n"
21611 + " movq %%mm2, 48(%2)\n"
21612 + " movq %%mm3, 56(%2)\n"
21613 ".section .fixup, \"ax\"\n"
21614 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21615 + "3:\n"
21616 +
21617 +#ifdef CONFIG_PAX_KERNEXEC
21618 + " movl %%cr0, %0\n"
21619 + " movl %0, %%eax\n"
21620 + " andl $0xFFFEFFFF, %%eax\n"
21621 + " movl %%eax, %%cr0\n"
21622 +#endif
21623 +
21624 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21625 +
21626 +#ifdef CONFIG_PAX_KERNEXEC
21627 + " movl %0, %%cr0\n"
21628 +#endif
21629 +
21630 " jmp 2b\n"
21631 ".previous\n"
21632 _ASM_EXTABLE(1b, 3b)
21633 - : : "r" (from), "r" (to) : "memory");
21634 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
21635
21636 from += 64;
21637 to += 64;
21638 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
21639 index 69fa106..adda88b 100644
21640 --- a/arch/x86/lib/msr-reg.S
21641 +++ b/arch/x86/lib/msr-reg.S
21642 @@ -3,6 +3,7 @@
21643 #include <asm/dwarf2.h>
21644 #include <asm/asm.h>
21645 #include <asm/msr.h>
21646 +#include <asm/alternative-asm.h>
21647
21648 #ifdef CONFIG_X86_64
21649 /*
21650 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
21651 CFI_STARTPROC
21652 pushq_cfi %rbx
21653 pushq_cfi %rbp
21654 - movq %rdi, %r10 /* Save pointer */
21655 + movq %rdi, %r9 /* Save pointer */
21656 xorl %r11d, %r11d /* Return value */
21657 movl (%rdi), %eax
21658 movl 4(%rdi), %ecx
21659 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
21660 movl 28(%rdi), %edi
21661 CFI_REMEMBER_STATE
21662 1: \op
21663 -2: movl %eax, (%r10)
21664 +2: movl %eax, (%r9)
21665 movl %r11d, %eax /* Return value */
21666 - movl %ecx, 4(%r10)
21667 - movl %edx, 8(%r10)
21668 - movl %ebx, 12(%r10)
21669 - movl %ebp, 20(%r10)
21670 - movl %esi, 24(%r10)
21671 - movl %edi, 28(%r10)
21672 + movl %ecx, 4(%r9)
21673 + movl %edx, 8(%r9)
21674 + movl %ebx, 12(%r9)
21675 + movl %ebp, 20(%r9)
21676 + movl %esi, 24(%r9)
21677 + movl %edi, 28(%r9)
21678 popq_cfi %rbp
21679 popq_cfi %rbx
21680 + pax_force_retaddr
21681 ret
21682 3:
21683 CFI_RESTORE_STATE
21684 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
21685 index 36b0d15..d381858 100644
21686 --- a/arch/x86/lib/putuser.S
21687 +++ b/arch/x86/lib/putuser.S
21688 @@ -15,7 +15,9 @@
21689 #include <asm/thread_info.h>
21690 #include <asm/errno.h>
21691 #include <asm/asm.h>
21692 -
21693 +#include <asm/segment.h>
21694 +#include <asm/pgtable.h>
21695 +#include <asm/alternative-asm.h>
21696
21697 /*
21698 * __put_user_X
21699 @@ -29,52 +31,119 @@
21700 * as they get called from within inline assembly.
21701 */
21702
21703 -#define ENTER CFI_STARTPROC ; \
21704 - GET_THREAD_INFO(%_ASM_BX)
21705 -#define EXIT ret ; \
21706 +#define ENTER CFI_STARTPROC
21707 +#define EXIT pax_force_retaddr; ret ; \
21708 CFI_ENDPROC
21709
21710 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21711 +#define _DEST %_ASM_CX,%_ASM_BX
21712 +#else
21713 +#define _DEST %_ASM_CX
21714 +#endif
21715 +
21716 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21717 +#define __copyuser_seg gs;
21718 +#else
21719 +#define __copyuser_seg
21720 +#endif
21721 +
21722 .text
21723 ENTRY(__put_user_1)
21724 ENTER
21725 +
21726 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21727 + GET_THREAD_INFO(%_ASM_BX)
21728 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
21729 jae bad_put_user
21730 -1: movb %al,(%_ASM_CX)
21731 +
21732 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21733 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
21734 + cmp %_ASM_BX,%_ASM_CX
21735 + jb 1234f
21736 + xor %ebx,%ebx
21737 +1234:
21738 +#endif
21739 +
21740 +#endif
21741 +
21742 +1: __copyuser_seg movb %al,(_DEST)
21743 xor %eax,%eax
21744 EXIT
21745 ENDPROC(__put_user_1)
21746
21747 ENTRY(__put_user_2)
21748 ENTER
21749 +
21750 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21751 + GET_THREAD_INFO(%_ASM_BX)
21752 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
21753 sub $1,%_ASM_BX
21754 cmp %_ASM_BX,%_ASM_CX
21755 jae bad_put_user
21756 -2: movw %ax,(%_ASM_CX)
21757 +
21758 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21759 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
21760 + cmp %_ASM_BX,%_ASM_CX
21761 + jb 1234f
21762 + xor %ebx,%ebx
21763 +1234:
21764 +#endif
21765 +
21766 +#endif
21767 +
21768 +2: __copyuser_seg movw %ax,(_DEST)
21769 xor %eax,%eax
21770 EXIT
21771 ENDPROC(__put_user_2)
21772
21773 ENTRY(__put_user_4)
21774 ENTER
21775 +
21776 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21777 + GET_THREAD_INFO(%_ASM_BX)
21778 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
21779 sub $3,%_ASM_BX
21780 cmp %_ASM_BX,%_ASM_CX
21781 jae bad_put_user
21782 -3: movl %eax,(%_ASM_CX)
21783 +
21784 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21785 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
21786 + cmp %_ASM_BX,%_ASM_CX
21787 + jb 1234f
21788 + xor %ebx,%ebx
21789 +1234:
21790 +#endif
21791 +
21792 +#endif
21793 +
21794 +3: __copyuser_seg movl %eax,(_DEST)
21795 xor %eax,%eax
21796 EXIT
21797 ENDPROC(__put_user_4)
21798
21799 ENTRY(__put_user_8)
21800 ENTER
21801 +
21802 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21803 + GET_THREAD_INFO(%_ASM_BX)
21804 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
21805 sub $7,%_ASM_BX
21806 cmp %_ASM_BX,%_ASM_CX
21807 jae bad_put_user
21808 -4: mov %_ASM_AX,(%_ASM_CX)
21809 +
21810 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21811 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
21812 + cmp %_ASM_BX,%_ASM_CX
21813 + jb 1234f
21814 + xor %ebx,%ebx
21815 +1234:
21816 +#endif
21817 +
21818 +#endif
21819 +
21820 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
21821 #ifdef CONFIG_X86_32
21822 -5: movl %edx,4(%_ASM_CX)
21823 +5: __copyuser_seg movl %edx,4(_DEST)
21824 #endif
21825 xor %eax,%eax
21826 EXIT
21827 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
21828 index 1cad221..de671ee 100644
21829 --- a/arch/x86/lib/rwlock.S
21830 +++ b/arch/x86/lib/rwlock.S
21831 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
21832 FRAME
21833 0: LOCK_PREFIX
21834 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
21835 +
21836 +#ifdef CONFIG_PAX_REFCOUNT
21837 + jno 1234f
21838 + LOCK_PREFIX
21839 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
21840 + int $4
21841 +1234:
21842 + _ASM_EXTABLE(1234b, 1234b)
21843 +#endif
21844 +
21845 1: rep; nop
21846 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
21847 jne 1b
21848 LOCK_PREFIX
21849 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
21850 +
21851 +#ifdef CONFIG_PAX_REFCOUNT
21852 + jno 1234f
21853 + LOCK_PREFIX
21854 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
21855 + int $4
21856 +1234:
21857 + _ASM_EXTABLE(1234b, 1234b)
21858 +#endif
21859 +
21860 jnz 0b
21861 ENDFRAME
21862 + pax_force_retaddr
21863 ret
21864 CFI_ENDPROC
21865 END(__write_lock_failed)
21866 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
21867 FRAME
21868 0: LOCK_PREFIX
21869 READ_LOCK_SIZE(inc) (%__lock_ptr)
21870 +
21871 +#ifdef CONFIG_PAX_REFCOUNT
21872 + jno 1234f
21873 + LOCK_PREFIX
21874 + READ_LOCK_SIZE(dec) (%__lock_ptr)
21875 + int $4
21876 +1234:
21877 + _ASM_EXTABLE(1234b, 1234b)
21878 +#endif
21879 +
21880 1: rep; nop
21881 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
21882 js 1b
21883 LOCK_PREFIX
21884 READ_LOCK_SIZE(dec) (%__lock_ptr)
21885 +
21886 +#ifdef CONFIG_PAX_REFCOUNT
21887 + jno 1234f
21888 + LOCK_PREFIX
21889 + READ_LOCK_SIZE(inc) (%__lock_ptr)
21890 + int $4
21891 +1234:
21892 + _ASM_EXTABLE(1234b, 1234b)
21893 +#endif
21894 +
21895 js 0b
21896 ENDFRAME
21897 + pax_force_retaddr
21898 ret
21899 CFI_ENDPROC
21900 END(__read_lock_failed)
21901 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
21902 index 5dff5f0..cadebf4 100644
21903 --- a/arch/x86/lib/rwsem.S
21904 +++ b/arch/x86/lib/rwsem.S
21905 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
21906 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
21907 CFI_RESTORE __ASM_REG(dx)
21908 restore_common_regs
21909 + pax_force_retaddr
21910 ret
21911 CFI_ENDPROC
21912 ENDPROC(call_rwsem_down_read_failed)
21913 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
21914 movq %rax,%rdi
21915 call rwsem_down_write_failed
21916 restore_common_regs
21917 + pax_force_retaddr
21918 ret
21919 CFI_ENDPROC
21920 ENDPROC(call_rwsem_down_write_failed)
21921 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
21922 movq %rax,%rdi
21923 call rwsem_wake
21924 restore_common_regs
21925 -1: ret
21926 +1: pax_force_retaddr
21927 + ret
21928 CFI_ENDPROC
21929 ENDPROC(call_rwsem_wake)
21930
21931 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
21932 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
21933 CFI_RESTORE __ASM_REG(dx)
21934 restore_common_regs
21935 + pax_force_retaddr
21936 ret
21937 CFI_ENDPROC
21938 ENDPROC(call_rwsem_downgrade_wake)
21939 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
21940 index a63efd6..ccecad8 100644
21941 --- a/arch/x86/lib/thunk_64.S
21942 +++ b/arch/x86/lib/thunk_64.S
21943 @@ -8,6 +8,7 @@
21944 #include <linux/linkage.h>
21945 #include <asm/dwarf2.h>
21946 #include <asm/calling.h>
21947 +#include <asm/alternative-asm.h>
21948
21949 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
21950 .macro THUNK name, func, put_ret_addr_in_rdi=0
21951 @@ -41,5 +42,6 @@
21952 SAVE_ARGS
21953 restore:
21954 RESTORE_ARGS
21955 + pax_force_retaddr
21956 ret
21957 CFI_ENDPROC
21958 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
21959 index e218d5d..35679b4 100644
21960 --- a/arch/x86/lib/usercopy_32.c
21961 +++ b/arch/x86/lib/usercopy_32.c
21962 @@ -43,7 +43,7 @@ do { \
21963 __asm__ __volatile__( \
21964 " testl %1,%1\n" \
21965 " jz 2f\n" \
21966 - "0: lodsb\n" \
21967 + "0: "__copyuser_seg"lodsb\n" \
21968 " stosb\n" \
21969 " testb %%al,%%al\n" \
21970 " jz 1f\n" \
21971 @@ -128,10 +128,12 @@ do { \
21972 int __d0; \
21973 might_fault(); \
21974 __asm__ __volatile__( \
21975 + __COPYUSER_SET_ES \
21976 "0: rep; stosl\n" \
21977 " movl %2,%0\n" \
21978 "1: rep; stosb\n" \
21979 "2:\n" \
21980 + __COPYUSER_RESTORE_ES \
21981 ".section .fixup,\"ax\"\n" \
21982 "3: lea 0(%2,%0,4),%0\n" \
21983 " jmp 2b\n" \
21984 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
21985 might_fault();
21986
21987 __asm__ __volatile__(
21988 + __COPYUSER_SET_ES
21989 " testl %0, %0\n"
21990 " jz 3f\n"
21991 " andl %0,%%ecx\n"
21992 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
21993 " subl %%ecx,%0\n"
21994 " addl %0,%%eax\n"
21995 "1:\n"
21996 + __COPYUSER_RESTORE_ES
21997 ".section .fixup,\"ax\"\n"
21998 "2: xorl %%eax,%%eax\n"
21999 " jmp 1b\n"
22000 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
22001
22002 #ifdef CONFIG_X86_INTEL_USERCOPY
22003 static unsigned long
22004 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22005 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22006 {
22007 int d0, d1;
22008 __asm__ __volatile__(
22009 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22010 " .align 2,0x90\n"
22011 "3: movl 0(%4), %%eax\n"
22012 "4: movl 4(%4), %%edx\n"
22013 - "5: movl %%eax, 0(%3)\n"
22014 - "6: movl %%edx, 4(%3)\n"
22015 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22016 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22017 "7: movl 8(%4), %%eax\n"
22018 "8: movl 12(%4),%%edx\n"
22019 - "9: movl %%eax, 8(%3)\n"
22020 - "10: movl %%edx, 12(%3)\n"
22021 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22022 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22023 "11: movl 16(%4), %%eax\n"
22024 "12: movl 20(%4), %%edx\n"
22025 - "13: movl %%eax, 16(%3)\n"
22026 - "14: movl %%edx, 20(%3)\n"
22027 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22028 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22029 "15: movl 24(%4), %%eax\n"
22030 "16: movl 28(%4), %%edx\n"
22031 - "17: movl %%eax, 24(%3)\n"
22032 - "18: movl %%edx, 28(%3)\n"
22033 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22034 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22035 "19: movl 32(%4), %%eax\n"
22036 "20: movl 36(%4), %%edx\n"
22037 - "21: movl %%eax, 32(%3)\n"
22038 - "22: movl %%edx, 36(%3)\n"
22039 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22040 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22041 "23: movl 40(%4), %%eax\n"
22042 "24: movl 44(%4), %%edx\n"
22043 - "25: movl %%eax, 40(%3)\n"
22044 - "26: movl %%edx, 44(%3)\n"
22045 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22046 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22047 "27: movl 48(%4), %%eax\n"
22048 "28: movl 52(%4), %%edx\n"
22049 - "29: movl %%eax, 48(%3)\n"
22050 - "30: movl %%edx, 52(%3)\n"
22051 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22052 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22053 "31: movl 56(%4), %%eax\n"
22054 "32: movl 60(%4), %%edx\n"
22055 - "33: movl %%eax, 56(%3)\n"
22056 - "34: movl %%edx, 60(%3)\n"
22057 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22058 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22059 " addl $-64, %0\n"
22060 " addl $64, %4\n"
22061 " addl $64, %3\n"
22062 @@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22063 " shrl $2, %0\n"
22064 " andl $3, %%eax\n"
22065 " cld\n"
22066 + __COPYUSER_SET_ES
22067 "99: rep; movsl\n"
22068 "36: movl %%eax, %0\n"
22069 "37: rep; movsb\n"
22070 "100:\n"
22071 + __COPYUSER_RESTORE_ES
22072 + ".section .fixup,\"ax\"\n"
22073 + "101: lea 0(%%eax,%0,4),%0\n"
22074 + " jmp 100b\n"
22075 + ".previous\n"
22076 + ".section __ex_table,\"a\"\n"
22077 + " .align 4\n"
22078 + " .long 1b,100b\n"
22079 + " .long 2b,100b\n"
22080 + " .long 3b,100b\n"
22081 + " .long 4b,100b\n"
22082 + " .long 5b,100b\n"
22083 + " .long 6b,100b\n"
22084 + " .long 7b,100b\n"
22085 + " .long 8b,100b\n"
22086 + " .long 9b,100b\n"
22087 + " .long 10b,100b\n"
22088 + " .long 11b,100b\n"
22089 + " .long 12b,100b\n"
22090 + " .long 13b,100b\n"
22091 + " .long 14b,100b\n"
22092 + " .long 15b,100b\n"
22093 + " .long 16b,100b\n"
22094 + " .long 17b,100b\n"
22095 + " .long 18b,100b\n"
22096 + " .long 19b,100b\n"
22097 + " .long 20b,100b\n"
22098 + " .long 21b,100b\n"
22099 + " .long 22b,100b\n"
22100 + " .long 23b,100b\n"
22101 + " .long 24b,100b\n"
22102 + " .long 25b,100b\n"
22103 + " .long 26b,100b\n"
22104 + " .long 27b,100b\n"
22105 + " .long 28b,100b\n"
22106 + " .long 29b,100b\n"
22107 + " .long 30b,100b\n"
22108 + " .long 31b,100b\n"
22109 + " .long 32b,100b\n"
22110 + " .long 33b,100b\n"
22111 + " .long 34b,100b\n"
22112 + " .long 35b,100b\n"
22113 + " .long 36b,100b\n"
22114 + " .long 37b,100b\n"
22115 + " .long 99b,101b\n"
22116 + ".previous"
22117 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
22118 + : "1"(to), "2"(from), "0"(size)
22119 + : "eax", "edx", "memory");
22120 + return size;
22121 +}
22122 +
22123 +static unsigned long
22124 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22125 +{
22126 + int d0, d1;
22127 + __asm__ __volatile__(
22128 + " .align 2,0x90\n"
22129 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22130 + " cmpl $67, %0\n"
22131 + " jbe 3f\n"
22132 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22133 + " .align 2,0x90\n"
22134 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22135 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22136 + "5: movl %%eax, 0(%3)\n"
22137 + "6: movl %%edx, 4(%3)\n"
22138 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22139 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22140 + "9: movl %%eax, 8(%3)\n"
22141 + "10: movl %%edx, 12(%3)\n"
22142 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22143 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22144 + "13: movl %%eax, 16(%3)\n"
22145 + "14: movl %%edx, 20(%3)\n"
22146 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22147 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22148 + "17: movl %%eax, 24(%3)\n"
22149 + "18: movl %%edx, 28(%3)\n"
22150 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22151 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22152 + "21: movl %%eax, 32(%3)\n"
22153 + "22: movl %%edx, 36(%3)\n"
22154 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22155 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22156 + "25: movl %%eax, 40(%3)\n"
22157 + "26: movl %%edx, 44(%3)\n"
22158 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22159 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22160 + "29: movl %%eax, 48(%3)\n"
22161 + "30: movl %%edx, 52(%3)\n"
22162 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22163 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22164 + "33: movl %%eax, 56(%3)\n"
22165 + "34: movl %%edx, 60(%3)\n"
22166 + " addl $-64, %0\n"
22167 + " addl $64, %4\n"
22168 + " addl $64, %3\n"
22169 + " cmpl $63, %0\n"
22170 + " ja 1b\n"
22171 + "35: movl %0, %%eax\n"
22172 + " shrl $2, %0\n"
22173 + " andl $3, %%eax\n"
22174 + " cld\n"
22175 + "99: rep; "__copyuser_seg" movsl\n"
22176 + "36: movl %%eax, %0\n"
22177 + "37: rep; "__copyuser_seg" movsb\n"
22178 + "100:\n"
22179 ".section .fixup,\"ax\"\n"
22180 "101: lea 0(%%eax,%0,4),%0\n"
22181 " jmp 100b\n"
22182 @@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22183 int d0, d1;
22184 __asm__ __volatile__(
22185 " .align 2,0x90\n"
22186 - "0: movl 32(%4), %%eax\n"
22187 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22188 " cmpl $67, %0\n"
22189 " jbe 2f\n"
22190 - "1: movl 64(%4), %%eax\n"
22191 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22192 " .align 2,0x90\n"
22193 - "2: movl 0(%4), %%eax\n"
22194 - "21: movl 4(%4), %%edx\n"
22195 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22196 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22197 " movl %%eax, 0(%3)\n"
22198 " movl %%edx, 4(%3)\n"
22199 - "3: movl 8(%4), %%eax\n"
22200 - "31: movl 12(%4),%%edx\n"
22201 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22202 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22203 " movl %%eax, 8(%3)\n"
22204 " movl %%edx, 12(%3)\n"
22205 - "4: movl 16(%4), %%eax\n"
22206 - "41: movl 20(%4), %%edx\n"
22207 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22208 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22209 " movl %%eax, 16(%3)\n"
22210 " movl %%edx, 20(%3)\n"
22211 - "10: movl 24(%4), %%eax\n"
22212 - "51: movl 28(%4), %%edx\n"
22213 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22214 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22215 " movl %%eax, 24(%3)\n"
22216 " movl %%edx, 28(%3)\n"
22217 - "11: movl 32(%4), %%eax\n"
22218 - "61: movl 36(%4), %%edx\n"
22219 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22220 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22221 " movl %%eax, 32(%3)\n"
22222 " movl %%edx, 36(%3)\n"
22223 - "12: movl 40(%4), %%eax\n"
22224 - "71: movl 44(%4), %%edx\n"
22225 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22226 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22227 " movl %%eax, 40(%3)\n"
22228 " movl %%edx, 44(%3)\n"
22229 - "13: movl 48(%4), %%eax\n"
22230 - "81: movl 52(%4), %%edx\n"
22231 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22232 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22233 " movl %%eax, 48(%3)\n"
22234 " movl %%edx, 52(%3)\n"
22235 - "14: movl 56(%4), %%eax\n"
22236 - "91: movl 60(%4), %%edx\n"
22237 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22238 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22239 " movl %%eax, 56(%3)\n"
22240 " movl %%edx, 60(%3)\n"
22241 " addl $-64, %0\n"
22242 @@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22243 " shrl $2, %0\n"
22244 " andl $3, %%eax\n"
22245 " cld\n"
22246 - "6: rep; movsl\n"
22247 + "6: rep; "__copyuser_seg" movsl\n"
22248 " movl %%eax,%0\n"
22249 - "7: rep; movsb\n"
22250 + "7: rep; "__copyuser_seg" movsb\n"
22251 "8:\n"
22252 ".section .fixup,\"ax\"\n"
22253 "9: lea 0(%%eax,%0,4),%0\n"
22254 @@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22255
22256 __asm__ __volatile__(
22257 " .align 2,0x90\n"
22258 - "0: movl 32(%4), %%eax\n"
22259 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22260 " cmpl $67, %0\n"
22261 " jbe 2f\n"
22262 - "1: movl 64(%4), %%eax\n"
22263 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22264 " .align 2,0x90\n"
22265 - "2: movl 0(%4), %%eax\n"
22266 - "21: movl 4(%4), %%edx\n"
22267 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22268 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22269 " movnti %%eax, 0(%3)\n"
22270 " movnti %%edx, 4(%3)\n"
22271 - "3: movl 8(%4), %%eax\n"
22272 - "31: movl 12(%4),%%edx\n"
22273 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22274 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22275 " movnti %%eax, 8(%3)\n"
22276 " movnti %%edx, 12(%3)\n"
22277 - "4: movl 16(%4), %%eax\n"
22278 - "41: movl 20(%4), %%edx\n"
22279 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22280 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22281 " movnti %%eax, 16(%3)\n"
22282 " movnti %%edx, 20(%3)\n"
22283 - "10: movl 24(%4), %%eax\n"
22284 - "51: movl 28(%4), %%edx\n"
22285 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22286 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22287 " movnti %%eax, 24(%3)\n"
22288 " movnti %%edx, 28(%3)\n"
22289 - "11: movl 32(%4), %%eax\n"
22290 - "61: movl 36(%4), %%edx\n"
22291 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22292 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22293 " movnti %%eax, 32(%3)\n"
22294 " movnti %%edx, 36(%3)\n"
22295 - "12: movl 40(%4), %%eax\n"
22296 - "71: movl 44(%4), %%edx\n"
22297 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22298 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22299 " movnti %%eax, 40(%3)\n"
22300 " movnti %%edx, 44(%3)\n"
22301 - "13: movl 48(%4), %%eax\n"
22302 - "81: movl 52(%4), %%edx\n"
22303 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22304 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22305 " movnti %%eax, 48(%3)\n"
22306 " movnti %%edx, 52(%3)\n"
22307 - "14: movl 56(%4), %%eax\n"
22308 - "91: movl 60(%4), %%edx\n"
22309 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22310 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22311 " movnti %%eax, 56(%3)\n"
22312 " movnti %%edx, 60(%3)\n"
22313 " addl $-64, %0\n"
22314 @@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22315 " shrl $2, %0\n"
22316 " andl $3, %%eax\n"
22317 " cld\n"
22318 - "6: rep; movsl\n"
22319 + "6: rep; "__copyuser_seg" movsl\n"
22320 " movl %%eax,%0\n"
22321 - "7: rep; movsb\n"
22322 + "7: rep; "__copyuser_seg" movsb\n"
22323 "8:\n"
22324 ".section .fixup,\"ax\"\n"
22325 "9: lea 0(%%eax,%0,4),%0\n"
22326 @@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
22327
22328 __asm__ __volatile__(
22329 " .align 2,0x90\n"
22330 - "0: movl 32(%4), %%eax\n"
22331 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22332 " cmpl $67, %0\n"
22333 " jbe 2f\n"
22334 - "1: movl 64(%4), %%eax\n"
22335 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22336 " .align 2,0x90\n"
22337 - "2: movl 0(%4), %%eax\n"
22338 - "21: movl 4(%4), %%edx\n"
22339 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22340 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22341 " movnti %%eax, 0(%3)\n"
22342 " movnti %%edx, 4(%3)\n"
22343 - "3: movl 8(%4), %%eax\n"
22344 - "31: movl 12(%4),%%edx\n"
22345 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22346 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22347 " movnti %%eax, 8(%3)\n"
22348 " movnti %%edx, 12(%3)\n"
22349 - "4: movl 16(%4), %%eax\n"
22350 - "41: movl 20(%4), %%edx\n"
22351 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22352 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22353 " movnti %%eax, 16(%3)\n"
22354 " movnti %%edx, 20(%3)\n"
22355 - "10: movl 24(%4), %%eax\n"
22356 - "51: movl 28(%4), %%edx\n"
22357 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22358 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22359 " movnti %%eax, 24(%3)\n"
22360 " movnti %%edx, 28(%3)\n"
22361 - "11: movl 32(%4), %%eax\n"
22362 - "61: movl 36(%4), %%edx\n"
22363 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22364 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22365 " movnti %%eax, 32(%3)\n"
22366 " movnti %%edx, 36(%3)\n"
22367 - "12: movl 40(%4), %%eax\n"
22368 - "71: movl 44(%4), %%edx\n"
22369 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22370 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22371 " movnti %%eax, 40(%3)\n"
22372 " movnti %%edx, 44(%3)\n"
22373 - "13: movl 48(%4), %%eax\n"
22374 - "81: movl 52(%4), %%edx\n"
22375 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22376 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22377 " movnti %%eax, 48(%3)\n"
22378 " movnti %%edx, 52(%3)\n"
22379 - "14: movl 56(%4), %%eax\n"
22380 - "91: movl 60(%4), %%edx\n"
22381 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22382 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22383 " movnti %%eax, 56(%3)\n"
22384 " movnti %%edx, 60(%3)\n"
22385 " addl $-64, %0\n"
22386 @@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
22387 " shrl $2, %0\n"
22388 " andl $3, %%eax\n"
22389 " cld\n"
22390 - "6: rep; movsl\n"
22391 + "6: rep; "__copyuser_seg" movsl\n"
22392 " movl %%eax,%0\n"
22393 - "7: rep; movsb\n"
22394 + "7: rep; "__copyuser_seg" movsb\n"
22395 "8:\n"
22396 ".section .fixup,\"ax\"\n"
22397 "9: lea 0(%%eax,%0,4),%0\n"
22398 @@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
22399 */
22400 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
22401 unsigned long size);
22402 -unsigned long __copy_user_intel(void __user *to, const void *from,
22403 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
22404 + unsigned long size);
22405 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
22406 unsigned long size);
22407 unsigned long __copy_user_zeroing_intel_nocache(void *to,
22408 const void __user *from, unsigned long size);
22409 #endif /* CONFIG_X86_INTEL_USERCOPY */
22410
22411 /* Generic arbitrary sized copy. */
22412 -#define __copy_user(to, from, size) \
22413 +#define __copy_user(to, from, size, prefix, set, restore) \
22414 do { \
22415 int __d0, __d1, __d2; \
22416 __asm__ __volatile__( \
22417 + set \
22418 " cmp $7,%0\n" \
22419 " jbe 1f\n" \
22420 " movl %1,%0\n" \
22421 " negl %0\n" \
22422 " andl $7,%0\n" \
22423 " subl %0,%3\n" \
22424 - "4: rep; movsb\n" \
22425 + "4: rep; "prefix"movsb\n" \
22426 " movl %3,%0\n" \
22427 " shrl $2,%0\n" \
22428 " andl $3,%3\n" \
22429 " .align 2,0x90\n" \
22430 - "0: rep; movsl\n" \
22431 + "0: rep; "prefix"movsl\n" \
22432 " movl %3,%0\n" \
22433 - "1: rep; movsb\n" \
22434 + "1: rep; "prefix"movsb\n" \
22435 "2:\n" \
22436 + restore \
22437 ".section .fixup,\"ax\"\n" \
22438 "5: addl %3,%0\n" \
22439 " jmp 2b\n" \
22440 @@ -682,14 +799,14 @@ do { \
22441 " negl %0\n" \
22442 " andl $7,%0\n" \
22443 " subl %0,%3\n" \
22444 - "4: rep; movsb\n" \
22445 + "4: rep; "__copyuser_seg"movsb\n" \
22446 " movl %3,%0\n" \
22447 " shrl $2,%0\n" \
22448 " andl $3,%3\n" \
22449 " .align 2,0x90\n" \
22450 - "0: rep; movsl\n" \
22451 + "0: rep; "__copyuser_seg"movsl\n" \
22452 " movl %3,%0\n" \
22453 - "1: rep; movsb\n" \
22454 + "1: rep; "__copyuser_seg"movsb\n" \
22455 "2:\n" \
22456 ".section .fixup,\"ax\"\n" \
22457 "5: addl %3,%0\n" \
22458 @@ -775,9 +892,9 @@ survive:
22459 }
22460 #endif
22461 if (movsl_is_ok(to, from, n))
22462 - __copy_user(to, from, n);
22463 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
22464 else
22465 - n = __copy_user_intel(to, from, n);
22466 + n = __generic_copy_to_user_intel(to, from, n);
22467 return n;
22468 }
22469 EXPORT_SYMBOL(__copy_to_user_ll);
22470 @@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
22471 unsigned long n)
22472 {
22473 if (movsl_is_ok(to, from, n))
22474 - __copy_user(to, from, n);
22475 + __copy_user(to, from, n, __copyuser_seg, "", "");
22476 else
22477 - n = __copy_user_intel((void __user *)to,
22478 - (const void *)from, n);
22479 + n = __generic_copy_from_user_intel(to, from, n);
22480 return n;
22481 }
22482 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
22483 @@ -827,65 +943,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
22484 if (n > 64 && cpu_has_xmm2)
22485 n = __copy_user_intel_nocache(to, from, n);
22486 else
22487 - __copy_user(to, from, n);
22488 + __copy_user(to, from, n, __copyuser_seg, "", "");
22489 #else
22490 - __copy_user(to, from, n);
22491 + __copy_user(to, from, n, __copyuser_seg, "", "");
22492 #endif
22493 return n;
22494 }
22495 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
22496
22497 -/**
22498 - * copy_to_user: - Copy a block of data into user space.
22499 - * @to: Destination address, in user space.
22500 - * @from: Source address, in kernel space.
22501 - * @n: Number of bytes to copy.
22502 - *
22503 - * Context: User context only. This function may sleep.
22504 - *
22505 - * Copy data from kernel space to user space.
22506 - *
22507 - * Returns number of bytes that could not be copied.
22508 - * On success, this will be zero.
22509 - */
22510 -unsigned long
22511 -copy_to_user(void __user *to, const void *from, unsigned long n)
22512 -{
22513 - if (access_ok(VERIFY_WRITE, to, n))
22514 - n = __copy_to_user(to, from, n);
22515 - return n;
22516 -}
22517 -EXPORT_SYMBOL(copy_to_user);
22518 -
22519 -/**
22520 - * copy_from_user: - Copy a block of data from user space.
22521 - * @to: Destination address, in kernel space.
22522 - * @from: Source address, in user space.
22523 - * @n: Number of bytes to copy.
22524 - *
22525 - * Context: User context only. This function may sleep.
22526 - *
22527 - * Copy data from user space to kernel space.
22528 - *
22529 - * Returns number of bytes that could not be copied.
22530 - * On success, this will be zero.
22531 - *
22532 - * If some data could not be copied, this function will pad the copied
22533 - * data to the requested size using zero bytes.
22534 - */
22535 -unsigned long
22536 -_copy_from_user(void *to, const void __user *from, unsigned long n)
22537 -{
22538 - if (access_ok(VERIFY_READ, from, n))
22539 - n = __copy_from_user(to, from, n);
22540 - else
22541 - memset(to, 0, n);
22542 - return n;
22543 -}
22544 -EXPORT_SYMBOL(_copy_from_user);
22545 -
22546 void copy_from_user_overflow(void)
22547 {
22548 WARN(1, "Buffer overflow detected!\n");
22549 }
22550 EXPORT_SYMBOL(copy_from_user_overflow);
22551 +
22552 +void copy_to_user_overflow(void)
22553 +{
22554 + WARN(1, "Buffer overflow detected!\n");
22555 +}
22556 +EXPORT_SYMBOL(copy_to_user_overflow);
22557 +
22558 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22559 +void __set_fs(mm_segment_t x)
22560 +{
22561 + switch (x.seg) {
22562 + case 0:
22563 + loadsegment(gs, 0);
22564 + break;
22565 + case TASK_SIZE_MAX:
22566 + loadsegment(gs, __USER_DS);
22567 + break;
22568 + case -1UL:
22569 + loadsegment(gs, __KERNEL_DS);
22570 + break;
22571 + default:
22572 + BUG();
22573 + }
22574 + return;
22575 +}
22576 +EXPORT_SYMBOL(__set_fs);
22577 +
22578 +void set_fs(mm_segment_t x)
22579 +{
22580 + current_thread_info()->addr_limit = x;
22581 + __set_fs(x);
22582 +}
22583 +EXPORT_SYMBOL(set_fs);
22584 +#endif
22585 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
22586 index b7c2849..8633ad8 100644
22587 --- a/arch/x86/lib/usercopy_64.c
22588 +++ b/arch/x86/lib/usercopy_64.c
22589 @@ -42,6 +42,12 @@ long
22590 __strncpy_from_user(char *dst, const char __user *src, long count)
22591 {
22592 long res;
22593 +
22594 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22595 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
22596 + src += PAX_USER_SHADOW_BASE;
22597 +#endif
22598 +
22599 __do_strncpy_from_user(dst, src, count, res);
22600 return res;
22601 }
22602 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
22603 {
22604 long __d0;
22605 might_fault();
22606 +
22607 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22608 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
22609 + addr += PAX_USER_SHADOW_BASE;
22610 +#endif
22611 +
22612 /* no memory constraint because it doesn't change any memory gcc knows
22613 about */
22614 asm volatile(
22615 @@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
22616 }
22617 EXPORT_SYMBOL(strlen_user);
22618
22619 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
22620 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
22621 {
22622 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
22623 - return copy_user_generic((__force void *)to, (__force void *)from, len);
22624 - }
22625 - return len;
22626 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
22627 +
22628 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22629 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
22630 + to += PAX_USER_SHADOW_BASE;
22631 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
22632 + from += PAX_USER_SHADOW_BASE;
22633 +#endif
22634 +
22635 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
22636 + }
22637 + return len;
22638 }
22639 EXPORT_SYMBOL(copy_in_user);
22640
22641 @@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
22642 * it is not necessary to optimize tail handling.
22643 */
22644 unsigned long
22645 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
22646 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
22647 {
22648 char c;
22649 unsigned zero_len;
22650 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
22651 index d0474ad..36e9257 100644
22652 --- a/arch/x86/mm/extable.c
22653 +++ b/arch/x86/mm/extable.c
22654 @@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
22655 const struct exception_table_entry *fixup;
22656
22657 #ifdef CONFIG_PNPBIOS
22658 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
22659 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
22660 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
22661 extern u32 pnp_bios_is_utter_crap;
22662 pnp_bios_is_utter_crap = 1;
22663 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
22664 index 5db0490..2ddce45 100644
22665 --- a/arch/x86/mm/fault.c
22666 +++ b/arch/x86/mm/fault.c
22667 @@ -13,11 +13,18 @@
22668 #include <linux/perf_event.h> /* perf_sw_event */
22669 #include <linux/hugetlb.h> /* hstate_index_to_shift */
22670 #include <linux/prefetch.h> /* prefetchw */
22671 +#include <linux/unistd.h>
22672 +#include <linux/compiler.h>
22673
22674 #include <asm/traps.h> /* dotraplinkage, ... */
22675 #include <asm/pgalloc.h> /* pgd_*(), ... */
22676 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
22677 #include <asm/fixmap.h> /* VSYSCALL_START */
22678 +#include <asm/tlbflush.h>
22679 +
22680 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22681 +#include <asm/stacktrace.h>
22682 +#endif
22683
22684 /*
22685 * Page fault error code bits:
22686 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
22687 int ret = 0;
22688
22689 /* kprobe_running() needs smp_processor_id() */
22690 - if (kprobes_built_in() && !user_mode_vm(regs)) {
22691 + if (kprobes_built_in() && !user_mode(regs)) {
22692 preempt_disable();
22693 if (kprobe_running() && kprobe_fault_handler(regs, 14))
22694 ret = 1;
22695 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
22696 return !instr_lo || (instr_lo>>1) == 1;
22697 case 0x00:
22698 /* Prefetch instruction is 0x0F0D or 0x0F18 */
22699 - if (probe_kernel_address(instr, opcode))
22700 + if (user_mode(regs)) {
22701 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
22702 + return 0;
22703 + } else if (probe_kernel_address(instr, opcode))
22704 return 0;
22705
22706 *prefetch = (instr_lo == 0xF) &&
22707 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
22708 while (instr < max_instr) {
22709 unsigned char opcode;
22710
22711 - if (probe_kernel_address(instr, opcode))
22712 + if (user_mode(regs)) {
22713 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
22714 + break;
22715 + } else if (probe_kernel_address(instr, opcode))
22716 break;
22717
22718 instr++;
22719 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
22720 force_sig_info(si_signo, &info, tsk);
22721 }
22722
22723 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22724 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
22725 +#endif
22726 +
22727 +#ifdef CONFIG_PAX_EMUTRAMP
22728 +static int pax_handle_fetch_fault(struct pt_regs *regs);
22729 +#endif
22730 +
22731 +#ifdef CONFIG_PAX_PAGEEXEC
22732 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
22733 +{
22734 + pgd_t *pgd;
22735 + pud_t *pud;
22736 + pmd_t *pmd;
22737 +
22738 + pgd = pgd_offset(mm, address);
22739 + if (!pgd_present(*pgd))
22740 + return NULL;
22741 + pud = pud_offset(pgd, address);
22742 + if (!pud_present(*pud))
22743 + return NULL;
22744 + pmd = pmd_offset(pud, address);
22745 + if (!pmd_present(*pmd))
22746 + return NULL;
22747 + return pmd;
22748 +}
22749 +#endif
22750 +
22751 DEFINE_SPINLOCK(pgd_lock);
22752 LIST_HEAD(pgd_list);
22753
22754 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
22755 for (address = VMALLOC_START & PMD_MASK;
22756 address >= TASK_SIZE && address < FIXADDR_TOP;
22757 address += PMD_SIZE) {
22758 +
22759 +#ifdef CONFIG_PAX_PER_CPU_PGD
22760 + unsigned long cpu;
22761 +#else
22762 struct page *page;
22763 +#endif
22764
22765 spin_lock(&pgd_lock);
22766 +
22767 +#ifdef CONFIG_PAX_PER_CPU_PGD
22768 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
22769 + pgd_t *pgd = get_cpu_pgd(cpu);
22770 + pmd_t *ret;
22771 +#else
22772 list_for_each_entry(page, &pgd_list, lru) {
22773 + pgd_t *pgd = page_address(page);
22774 spinlock_t *pgt_lock;
22775 pmd_t *ret;
22776
22777 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
22778 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
22779
22780 spin_lock(pgt_lock);
22781 - ret = vmalloc_sync_one(page_address(page), address);
22782 +#endif
22783 +
22784 + ret = vmalloc_sync_one(pgd, address);
22785 +
22786 +#ifndef CONFIG_PAX_PER_CPU_PGD
22787 spin_unlock(pgt_lock);
22788 +#endif
22789
22790 if (!ret)
22791 break;
22792 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
22793 * an interrupt in the middle of a task switch..
22794 */
22795 pgd_paddr = read_cr3();
22796 +
22797 +#ifdef CONFIG_PAX_PER_CPU_PGD
22798 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
22799 +#endif
22800 +
22801 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
22802 if (!pmd_k)
22803 return -1;
22804 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
22805 * happen within a race in page table update. In the later
22806 * case just flush:
22807 */
22808 +
22809 +#ifdef CONFIG_PAX_PER_CPU_PGD
22810 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
22811 + pgd = pgd_offset_cpu(smp_processor_id(), address);
22812 +#else
22813 pgd = pgd_offset(current->active_mm, address);
22814 +#endif
22815 +
22816 pgd_ref = pgd_offset_k(address);
22817 if (pgd_none(*pgd_ref))
22818 return -1;
22819 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
22820 static int is_errata100(struct pt_regs *regs, unsigned long address)
22821 {
22822 #ifdef CONFIG_X86_64
22823 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
22824 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
22825 return 1;
22826 #endif
22827 return 0;
22828 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
22829 }
22830
22831 static const char nx_warning[] = KERN_CRIT
22832 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
22833 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
22834
22835 static void
22836 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
22837 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
22838 if (!oops_may_print())
22839 return;
22840
22841 - if (error_code & PF_INSTR) {
22842 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
22843 unsigned int level;
22844
22845 pte_t *pte = lookup_address(address, &level);
22846
22847 if (pte && pte_present(*pte) && !pte_exec(*pte))
22848 - printk(nx_warning, current_uid());
22849 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
22850 }
22851
22852 +#ifdef CONFIG_PAX_KERNEXEC
22853 + if (init_mm.start_code <= address && address < init_mm.end_code) {
22854 + if (current->signal->curr_ip)
22855 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
22856 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
22857 + else
22858 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
22859 + current->comm, task_pid_nr(current), current_uid(), current_euid());
22860 + }
22861 +#endif
22862 +
22863 printk(KERN_ALERT "BUG: unable to handle kernel ");
22864 if (address < PAGE_SIZE)
22865 printk(KERN_CONT "NULL pointer dereference");
22866 @@ -739,6 +820,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
22867 }
22868 #endif
22869
22870 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22871 + if (pax_is_fetch_fault(regs, error_code, address)) {
22872 +
22873 +#ifdef CONFIG_PAX_EMUTRAMP
22874 + switch (pax_handle_fetch_fault(regs)) {
22875 + case 2:
22876 + return;
22877 + }
22878 +#endif
22879 +
22880 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
22881 + do_group_exit(SIGKILL);
22882 + }
22883 +#endif
22884 +
22885 if (unlikely(show_unhandled_signals))
22886 show_signal_msg(regs, error_code, address, tsk);
22887
22888 @@ -835,7 +931,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
22889 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
22890 printk(KERN_ERR
22891 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
22892 - tsk->comm, tsk->pid, address);
22893 + tsk->comm, task_pid_nr(tsk), address);
22894 code = BUS_MCEERR_AR;
22895 }
22896 #endif
22897 @@ -890,6 +986,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
22898 return 1;
22899 }
22900
22901 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
22902 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
22903 +{
22904 + pte_t *pte;
22905 + pmd_t *pmd;
22906 + spinlock_t *ptl;
22907 + unsigned char pte_mask;
22908 +
22909 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
22910 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
22911 + return 0;
22912 +
22913 + /* PaX: it's our fault, let's handle it if we can */
22914 +
22915 + /* PaX: take a look at read faults before acquiring any locks */
22916 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
22917 + /* instruction fetch attempt from a protected page in user mode */
22918 + up_read(&mm->mmap_sem);
22919 +
22920 +#ifdef CONFIG_PAX_EMUTRAMP
22921 + switch (pax_handle_fetch_fault(regs)) {
22922 + case 2:
22923 + return 1;
22924 + }
22925 +#endif
22926 +
22927 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
22928 + do_group_exit(SIGKILL);
22929 + }
22930 +
22931 + pmd = pax_get_pmd(mm, address);
22932 + if (unlikely(!pmd))
22933 + return 0;
22934 +
22935 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
22936 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
22937 + pte_unmap_unlock(pte, ptl);
22938 + return 0;
22939 + }
22940 +
22941 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
22942 + /* write attempt to a protected page in user mode */
22943 + pte_unmap_unlock(pte, ptl);
22944 + return 0;
22945 + }
22946 +
22947 +#ifdef CONFIG_SMP
22948 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
22949 +#else
22950 + if (likely(address > get_limit(regs->cs)))
22951 +#endif
22952 + {
22953 + set_pte(pte, pte_mkread(*pte));
22954 + __flush_tlb_one(address);
22955 + pte_unmap_unlock(pte, ptl);
22956 + up_read(&mm->mmap_sem);
22957 + return 1;
22958 + }
22959 +
22960 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
22961 +
22962 + /*
22963 + * PaX: fill DTLB with user rights and retry
22964 + */
22965 + __asm__ __volatile__ (
22966 + "orb %2,(%1)\n"
22967 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
22968 +/*
22969 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
22970 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
22971 + * page fault when examined during a TLB load attempt. this is true not only
22972 + * for PTEs holding a non-present entry but also present entries that will
22973 + * raise a page fault (such as those set up by PaX, or the copy-on-write
22974 + * mechanism). in effect it means that we do *not* need to flush the TLBs
22975 + * for our target pages since their PTEs are simply not in the TLBs at all.
22976 +
22977 + * the best thing in omitting it is that we gain around 15-20% speed in the
22978 + * fast path of the page fault handler and can get rid of tracing since we
22979 + * can no longer flush unintended entries.
22980 + */
22981 + "invlpg (%0)\n"
22982 +#endif
22983 + __copyuser_seg"testb $0,(%0)\n"
22984 + "xorb %3,(%1)\n"
22985 + :
22986 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
22987 + : "memory", "cc");
22988 + pte_unmap_unlock(pte, ptl);
22989 + up_read(&mm->mmap_sem);
22990 + return 1;
22991 +}
22992 +#endif
22993 +
22994 /*
22995 * Handle a spurious fault caused by a stale TLB entry.
22996 *
22997 @@ -962,6 +1151,9 @@ int show_unhandled_signals = 1;
22998 static inline int
22999 access_error(unsigned long error_code, struct vm_area_struct *vma)
23000 {
23001 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23002 + return 1;
23003 +
23004 if (error_code & PF_WRITE) {
23005 /* write, present and write, not present: */
23006 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23007 @@ -995,18 +1187,32 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23008 {
23009 struct vm_area_struct *vma;
23010 struct task_struct *tsk;
23011 - unsigned long address;
23012 struct mm_struct *mm;
23013 int fault;
23014 int write = error_code & PF_WRITE;
23015 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23016 (write ? FAULT_FLAG_WRITE : 0);
23017
23018 - tsk = current;
23019 - mm = tsk->mm;
23020 -
23021 /* Get the faulting address: */
23022 - address = read_cr2();
23023 + unsigned long address = read_cr2();
23024 +
23025 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23026 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23027 + if (!search_exception_tables(regs->ip)) {
23028 + bad_area_nosemaphore(regs, error_code, address);
23029 + return;
23030 + }
23031 + if (address < PAX_USER_SHADOW_BASE) {
23032 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23033 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23034 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23035 + } else
23036 + address -= PAX_USER_SHADOW_BASE;
23037 + }
23038 +#endif
23039 +
23040 + tsk = current;
23041 + mm = tsk->mm;
23042
23043 /*
23044 * Detect and handle instructions that would cause a page fault for
23045 @@ -1067,7 +1273,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23046 * User-mode registers count as a user access even for any
23047 * potential system fault or CPU buglet:
23048 */
23049 - if (user_mode_vm(regs)) {
23050 + if (user_mode(regs)) {
23051 local_irq_enable();
23052 error_code |= PF_USER;
23053 } else {
23054 @@ -1122,6 +1328,11 @@ retry:
23055 might_sleep();
23056 }
23057
23058 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23059 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23060 + return;
23061 +#endif
23062 +
23063 vma = find_vma(mm, address);
23064 if (unlikely(!vma)) {
23065 bad_area(regs, error_code, address);
23066 @@ -1133,18 +1344,24 @@ retry:
23067 bad_area(regs, error_code, address);
23068 return;
23069 }
23070 - if (error_code & PF_USER) {
23071 - /*
23072 - * Accessing the stack below %sp is always a bug.
23073 - * The large cushion allows instructions like enter
23074 - * and pusha to work. ("enter $65535, $31" pushes
23075 - * 32 pointers and then decrements %sp by 65535.)
23076 - */
23077 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23078 - bad_area(regs, error_code, address);
23079 - return;
23080 - }
23081 + /*
23082 + * Accessing the stack below %sp is always a bug.
23083 + * The large cushion allows instructions like enter
23084 + * and pusha to work. ("enter $65535, $31" pushes
23085 + * 32 pointers and then decrements %sp by 65535.)
23086 + */
23087 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23088 + bad_area(regs, error_code, address);
23089 + return;
23090 }
23091 +
23092 +#ifdef CONFIG_PAX_SEGMEXEC
23093 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23094 + bad_area(regs, error_code, address);
23095 + return;
23096 + }
23097 +#endif
23098 +
23099 if (unlikely(expand_stack(vma, address))) {
23100 bad_area(regs, error_code, address);
23101 return;
23102 @@ -1199,3 +1416,292 @@ good_area:
23103
23104 up_read(&mm->mmap_sem);
23105 }
23106 +
23107 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23108 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23109 +{
23110 + struct mm_struct *mm = current->mm;
23111 + unsigned long ip = regs->ip;
23112 +
23113 + if (v8086_mode(regs))
23114 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
23115 +
23116 +#ifdef CONFIG_PAX_PAGEEXEC
23117 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
23118 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
23119 + return true;
23120 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
23121 + return true;
23122 + return false;
23123 + }
23124 +#endif
23125 +
23126 +#ifdef CONFIG_PAX_SEGMEXEC
23127 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
23128 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
23129 + return true;
23130 + return false;
23131 + }
23132 +#endif
23133 +
23134 + return false;
23135 +}
23136 +#endif
23137 +
23138 +#ifdef CONFIG_PAX_EMUTRAMP
23139 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
23140 +{
23141 + int err;
23142 +
23143 + do { /* PaX: libffi trampoline emulation */
23144 + unsigned char mov, jmp;
23145 + unsigned int addr1, addr2;
23146 +
23147 +#ifdef CONFIG_X86_64
23148 + if ((regs->ip + 9) >> 32)
23149 + break;
23150 +#endif
23151 +
23152 + err = get_user(mov, (unsigned char __user *)regs->ip);
23153 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23154 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23155 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23156 +
23157 + if (err)
23158 + break;
23159 +
23160 + if (mov == 0xB8 && jmp == 0xE9) {
23161 + regs->ax = addr1;
23162 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23163 + return 2;
23164 + }
23165 + } while (0);
23166 +
23167 + do { /* PaX: gcc trampoline emulation #1 */
23168 + unsigned char mov1, mov2;
23169 + unsigned short jmp;
23170 + unsigned int addr1, addr2;
23171 +
23172 +#ifdef CONFIG_X86_64
23173 + if ((regs->ip + 11) >> 32)
23174 + break;
23175 +#endif
23176 +
23177 + err = get_user(mov1, (unsigned char __user *)regs->ip);
23178 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23179 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
23180 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23181 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
23182 +
23183 + if (err)
23184 + break;
23185 +
23186 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
23187 + regs->cx = addr1;
23188 + regs->ax = addr2;
23189 + regs->ip = addr2;
23190 + return 2;
23191 + }
23192 + } while (0);
23193 +
23194 + do { /* PaX: gcc trampoline emulation #2 */
23195 + unsigned char mov, jmp;
23196 + unsigned int addr1, addr2;
23197 +
23198 +#ifdef CONFIG_X86_64
23199 + if ((regs->ip + 9) >> 32)
23200 + break;
23201 +#endif
23202 +
23203 + err = get_user(mov, (unsigned char __user *)regs->ip);
23204 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23205 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23206 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23207 +
23208 + if (err)
23209 + break;
23210 +
23211 + if (mov == 0xB9 && jmp == 0xE9) {
23212 + regs->cx = addr1;
23213 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23214 + return 2;
23215 + }
23216 + } while (0);
23217 +
23218 + return 1; /* PaX in action */
23219 +}
23220 +
23221 +#ifdef CONFIG_X86_64
23222 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
23223 +{
23224 + int err;
23225 +
23226 + do { /* PaX: libffi trampoline emulation */
23227 + unsigned short mov1, mov2, jmp1;
23228 + unsigned char stcclc, jmp2;
23229 + unsigned long addr1, addr2;
23230 +
23231 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23232 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23233 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23234 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23235 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
23236 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
23237 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
23238 +
23239 + if (err)
23240 + break;
23241 +
23242 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23243 + regs->r11 = addr1;
23244 + regs->r10 = addr2;
23245 + if (stcclc == 0xF8)
23246 + regs->flags &= ~X86_EFLAGS_CF;
23247 + else
23248 + regs->flags |= X86_EFLAGS_CF;
23249 + regs->ip = addr1;
23250 + return 2;
23251 + }
23252 + } while (0);
23253 +
23254 + do { /* PaX: gcc trampoline emulation #1 */
23255 + unsigned short mov1, mov2, jmp1;
23256 + unsigned char jmp2;
23257 + unsigned int addr1;
23258 + unsigned long addr2;
23259 +
23260 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23261 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
23262 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
23263 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
23264 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
23265 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
23266 +
23267 + if (err)
23268 + break;
23269 +
23270 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23271 + regs->r11 = addr1;
23272 + regs->r10 = addr2;
23273 + regs->ip = addr1;
23274 + return 2;
23275 + }
23276 + } while (0);
23277 +
23278 + do { /* PaX: gcc trampoline emulation #2 */
23279 + unsigned short mov1, mov2, jmp1;
23280 + unsigned char jmp2;
23281 + unsigned long addr1, addr2;
23282 +
23283 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23284 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23285 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23286 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23287 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
23288 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
23289 +
23290 + if (err)
23291 + break;
23292 +
23293 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23294 + regs->r11 = addr1;
23295 + regs->r10 = addr2;
23296 + regs->ip = addr1;
23297 + return 2;
23298 + }
23299 + } while (0);
23300 +
23301 + return 1; /* PaX in action */
23302 +}
23303 +#endif
23304 +
23305 +/*
23306 + * PaX: decide what to do with offenders (regs->ip = fault address)
23307 + *
23308 + * returns 1 when task should be killed
23309 + * 2 when gcc trampoline was detected
23310 + */
23311 +static int pax_handle_fetch_fault(struct pt_regs *regs)
23312 +{
23313 + if (v8086_mode(regs))
23314 + return 1;
23315 +
23316 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
23317 + return 1;
23318 +
23319 +#ifdef CONFIG_X86_32
23320 + return pax_handle_fetch_fault_32(regs);
23321 +#else
23322 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
23323 + return pax_handle_fetch_fault_32(regs);
23324 + else
23325 + return pax_handle_fetch_fault_64(regs);
23326 +#endif
23327 +}
23328 +#endif
23329 +
23330 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23331 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
23332 +{
23333 + long i;
23334 +
23335 + printk(KERN_ERR "PAX: bytes at PC: ");
23336 + for (i = 0; i < 20; i++) {
23337 + unsigned char c;
23338 + if (get_user(c, (unsigned char __force_user *)pc+i))
23339 + printk(KERN_CONT "?? ");
23340 + else
23341 + printk(KERN_CONT "%02x ", c);
23342 + }
23343 + printk("\n");
23344 +
23345 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
23346 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
23347 + unsigned long c;
23348 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
23349 +#ifdef CONFIG_X86_32
23350 + printk(KERN_CONT "???????? ");
23351 +#else
23352 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
23353 + printk(KERN_CONT "???????? ???????? ");
23354 + else
23355 + printk(KERN_CONT "???????????????? ");
23356 +#endif
23357 + } else {
23358 +#ifdef CONFIG_X86_64
23359 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
23360 + printk(KERN_CONT "%08x ", (unsigned int)c);
23361 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
23362 + } else
23363 +#endif
23364 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
23365 + }
23366 + }
23367 + printk("\n");
23368 +}
23369 +#endif
23370 +
23371 +/**
23372 + * probe_kernel_write(): safely attempt to write to a location
23373 + * @dst: address to write to
23374 + * @src: pointer to the data that shall be written
23375 + * @size: size of the data chunk
23376 + *
23377 + * Safely write to address @dst from the buffer at @src. If a kernel fault
23378 + * happens, handle that and return -EFAULT.
23379 + */
23380 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
23381 +{
23382 + long ret;
23383 + mm_segment_t old_fs = get_fs();
23384 +
23385 + set_fs(KERNEL_DS);
23386 + pagefault_disable();
23387 + pax_open_kernel();
23388 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
23389 + pax_close_kernel();
23390 + pagefault_enable();
23391 + set_fs(old_fs);
23392 +
23393 + return ret ? -EFAULT : 0;
23394 +}
23395 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
23396 index dd74e46..7d26398 100644
23397 --- a/arch/x86/mm/gup.c
23398 +++ b/arch/x86/mm/gup.c
23399 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
23400 addr = start;
23401 len = (unsigned long) nr_pages << PAGE_SHIFT;
23402 end = start + len;
23403 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
23404 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
23405 (void __user *)start, len)))
23406 return 0;
23407
23408 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
23409 index f4f29b1..5cac4fb 100644
23410 --- a/arch/x86/mm/highmem_32.c
23411 +++ b/arch/x86/mm/highmem_32.c
23412 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
23413 idx = type + KM_TYPE_NR*smp_processor_id();
23414 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
23415 BUG_ON(!pte_none(*(kmap_pte-idx)));
23416 +
23417 + pax_open_kernel();
23418 set_pte(kmap_pte-idx, mk_pte(page, prot));
23419 + pax_close_kernel();
23420 +
23421 arch_flush_lazy_mmu_mode();
23422
23423 return (void *)vaddr;
23424 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
23425 index f581a18..29efd37 100644
23426 --- a/arch/x86/mm/hugetlbpage.c
23427 +++ b/arch/x86/mm/hugetlbpage.c
23428 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
23429 struct hstate *h = hstate_file(file);
23430 struct mm_struct *mm = current->mm;
23431 struct vm_area_struct *vma;
23432 - unsigned long start_addr;
23433 + unsigned long start_addr, pax_task_size = TASK_SIZE;
23434 +
23435 +#ifdef CONFIG_PAX_SEGMEXEC
23436 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23437 + pax_task_size = SEGMEXEC_TASK_SIZE;
23438 +#endif
23439 +
23440 + pax_task_size -= PAGE_SIZE;
23441
23442 if (len > mm->cached_hole_size) {
23443 - start_addr = mm->free_area_cache;
23444 + start_addr = mm->free_area_cache;
23445 } else {
23446 - start_addr = TASK_UNMAPPED_BASE;
23447 - mm->cached_hole_size = 0;
23448 + start_addr = mm->mmap_base;
23449 + mm->cached_hole_size = 0;
23450 }
23451
23452 full_search:
23453 @@ -280,26 +287,27 @@ full_search:
23454
23455 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
23456 /* At this point: (!vma || addr < vma->vm_end). */
23457 - if (TASK_SIZE - len < addr) {
23458 + if (pax_task_size - len < addr) {
23459 /*
23460 * Start a new search - just in case we missed
23461 * some holes.
23462 */
23463 - if (start_addr != TASK_UNMAPPED_BASE) {
23464 - start_addr = TASK_UNMAPPED_BASE;
23465 + if (start_addr != mm->mmap_base) {
23466 + start_addr = mm->mmap_base;
23467 mm->cached_hole_size = 0;
23468 goto full_search;
23469 }
23470 return -ENOMEM;
23471 }
23472 - if (!vma || addr + len <= vma->vm_start) {
23473 - mm->free_area_cache = addr + len;
23474 - return addr;
23475 - }
23476 + if (check_heap_stack_gap(vma, addr, len))
23477 + break;
23478 if (addr + mm->cached_hole_size < vma->vm_start)
23479 mm->cached_hole_size = vma->vm_start - addr;
23480 addr = ALIGN(vma->vm_end, huge_page_size(h));
23481 }
23482 +
23483 + mm->free_area_cache = addr + len;
23484 + return addr;
23485 }
23486
23487 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
23488 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
23489 {
23490 struct hstate *h = hstate_file(file);
23491 struct mm_struct *mm = current->mm;
23492 - struct vm_area_struct *vma, *prev_vma;
23493 - unsigned long base = mm->mmap_base, addr = addr0;
23494 + struct vm_area_struct *vma;
23495 + unsigned long base = mm->mmap_base, addr;
23496 unsigned long largest_hole = mm->cached_hole_size;
23497 - int first_time = 1;
23498
23499 /* don't allow allocations above current base */
23500 if (mm->free_area_cache > base)
23501 @@ -321,64 +328,63 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
23502 largest_hole = 0;
23503 mm->free_area_cache = base;
23504 }
23505 -try_again:
23506 +
23507 /* make sure it can fit in the remaining address space */
23508 if (mm->free_area_cache < len)
23509 goto fail;
23510
23511 /* either no address requested or can't fit in requested address hole */
23512 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
23513 + addr = (mm->free_area_cache - len);
23514 do {
23515 + addr &= huge_page_mask(h);
23516 + vma = find_vma(mm, addr);
23517 /*
23518 * Lookup failure means no vma is above this address,
23519 * i.e. return with success:
23520 - */
23521 - if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
23522 - return addr;
23523 -
23524 - /*
23525 * new region fits between prev_vma->vm_end and
23526 * vma->vm_start, use it:
23527 */
23528 - if (addr + len <= vma->vm_start &&
23529 - (!prev_vma || (addr >= prev_vma->vm_end))) {
23530 + if (check_heap_stack_gap(vma, addr, len)) {
23531 /* remember the address as a hint for next time */
23532 - mm->cached_hole_size = largest_hole;
23533 - return (mm->free_area_cache = addr);
23534 - } else {
23535 - /* pull free_area_cache down to the first hole */
23536 - if (mm->free_area_cache == vma->vm_end) {
23537 - mm->free_area_cache = vma->vm_start;
23538 - mm->cached_hole_size = largest_hole;
23539 - }
23540 + mm->cached_hole_size = largest_hole;
23541 + return (mm->free_area_cache = addr);
23542 + }
23543 + /* pull free_area_cache down to the first hole */
23544 + if (mm->free_area_cache == vma->vm_end) {
23545 + mm->free_area_cache = vma->vm_start;
23546 + mm->cached_hole_size = largest_hole;
23547 }
23548
23549 /* remember the largest hole we saw so far */
23550 if (addr + largest_hole < vma->vm_start)
23551 - largest_hole = vma->vm_start - addr;
23552 + largest_hole = vma->vm_start - addr;
23553
23554 /* try just below the current vma->vm_start */
23555 - addr = (vma->vm_start - len) & huge_page_mask(h);
23556 - } while (len <= vma->vm_start);
23557 + addr = skip_heap_stack_gap(vma, len);
23558 + } while (!IS_ERR_VALUE(addr));
23559
23560 fail:
23561 /*
23562 - * if hint left us with no space for the requested
23563 - * mapping then try again:
23564 - */
23565 - if (first_time) {
23566 - mm->free_area_cache = base;
23567 - largest_hole = 0;
23568 - first_time = 0;
23569 - goto try_again;
23570 - }
23571 - /*
23572 * A failed mmap() very likely causes application failure,
23573 * so fall back to the bottom-up function here. This scenario
23574 * can happen with large stack limits and large mmap()
23575 * allocations.
23576 */
23577 - mm->free_area_cache = TASK_UNMAPPED_BASE;
23578 +
23579 +#ifdef CONFIG_PAX_SEGMEXEC
23580 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23581 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
23582 + else
23583 +#endif
23584 +
23585 + mm->mmap_base = TASK_UNMAPPED_BASE;
23586 +
23587 +#ifdef CONFIG_PAX_RANDMMAP
23588 + if (mm->pax_flags & MF_PAX_RANDMMAP)
23589 + mm->mmap_base += mm->delta_mmap;
23590 +#endif
23591 +
23592 + mm->free_area_cache = mm->mmap_base;
23593 mm->cached_hole_size = ~0UL;
23594 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
23595 len, pgoff, flags);
23596 @@ -386,6 +392,7 @@ fail:
23597 /*
23598 * Restore the topdown base:
23599 */
23600 + mm->mmap_base = base;
23601 mm->free_area_cache = base;
23602 mm->cached_hole_size = ~0UL;
23603
23604 @@ -399,10 +406,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
23605 struct hstate *h = hstate_file(file);
23606 struct mm_struct *mm = current->mm;
23607 struct vm_area_struct *vma;
23608 + unsigned long pax_task_size = TASK_SIZE;
23609
23610 if (len & ~huge_page_mask(h))
23611 return -EINVAL;
23612 - if (len > TASK_SIZE)
23613 +
23614 +#ifdef CONFIG_PAX_SEGMEXEC
23615 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23616 + pax_task_size = SEGMEXEC_TASK_SIZE;
23617 +#endif
23618 +
23619 + pax_task_size -= PAGE_SIZE;
23620 +
23621 + if (len > pax_task_size)
23622 return -ENOMEM;
23623
23624 if (flags & MAP_FIXED) {
23625 @@ -414,8 +430,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
23626 if (addr) {
23627 addr = ALIGN(addr, huge_page_size(h));
23628 vma = find_vma(mm, addr);
23629 - if (TASK_SIZE - len >= addr &&
23630 - (!vma || addr + len <= vma->vm_start))
23631 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
23632 return addr;
23633 }
23634 if (mm->get_unmapped_area == arch_get_unmapped_area)
23635 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
23636 index 87488b9..399f416 100644
23637 --- a/arch/x86/mm/init.c
23638 +++ b/arch/x86/mm/init.c
23639 @@ -15,6 +15,7 @@
23640 #include <asm/tlbflush.h>
23641 #include <asm/tlb.h>
23642 #include <asm/proto.h>
23643 +#include <asm/desc.h>
23644
23645 unsigned long __initdata pgt_buf_start;
23646 unsigned long __meminitdata pgt_buf_end;
23647 @@ -31,7 +32,7 @@ int direct_gbpages
23648 static void __init find_early_table_space(unsigned long end, int use_pse,
23649 int use_gbpages)
23650 {
23651 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
23652 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
23653 phys_addr_t base;
23654
23655 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
23656 @@ -312,8 +313,29 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
23657 */
23658 int devmem_is_allowed(unsigned long pagenr)
23659 {
23660 +#ifdef CONFIG_GRKERNSEC_KMEM
23661 + /* allow BDA */
23662 + if (!pagenr)
23663 + return 1;
23664 + /* allow EBDA */
23665 + if ((0x9f000 >> PAGE_SHIFT) == pagenr)
23666 + return 1;
23667 +#else
23668 + if (!pagenr)
23669 + return 1;
23670 +#ifdef CONFIG_VM86
23671 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
23672 + return 1;
23673 +#endif
23674 +#endif
23675 +
23676 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
23677 + return 1;
23678 +#ifdef CONFIG_GRKERNSEC_KMEM
23679 + /* throw out everything else below 1MB */
23680 if (pagenr <= 256)
23681 - return 1;
23682 + return 0;
23683 +#endif
23684 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
23685 return 0;
23686 if (!page_is_ram(pagenr))
23687 @@ -372,6 +394,86 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
23688
23689 void free_initmem(void)
23690 {
23691 +
23692 +#ifdef CONFIG_PAX_KERNEXEC
23693 +#ifdef CONFIG_X86_32
23694 + /* PaX: limit KERNEL_CS to actual size */
23695 + unsigned long addr, limit;
23696 + struct desc_struct d;
23697 + int cpu;
23698 +
23699 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
23700 + limit = (limit - 1UL) >> PAGE_SHIFT;
23701 +
23702 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
23703 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
23704 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
23705 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
23706 + }
23707 +
23708 + /* PaX: make KERNEL_CS read-only */
23709 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
23710 + if (!paravirt_enabled())
23711 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
23712 +/*
23713 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
23714 + pgd = pgd_offset_k(addr);
23715 + pud = pud_offset(pgd, addr);
23716 + pmd = pmd_offset(pud, addr);
23717 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
23718 + }
23719 +*/
23720 +#ifdef CONFIG_X86_PAE
23721 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
23722 +/*
23723 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
23724 + pgd = pgd_offset_k(addr);
23725 + pud = pud_offset(pgd, addr);
23726 + pmd = pmd_offset(pud, addr);
23727 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
23728 + }
23729 +*/
23730 +#endif
23731 +
23732 +#ifdef CONFIG_MODULES
23733 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
23734 +#endif
23735 +
23736 +#else
23737 + pgd_t *pgd;
23738 + pud_t *pud;
23739 + pmd_t *pmd;
23740 + unsigned long addr, end;
23741 +
23742 + /* PaX: make kernel code/rodata read-only, rest non-executable */
23743 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
23744 + pgd = pgd_offset_k(addr);
23745 + pud = pud_offset(pgd, addr);
23746 + pmd = pmd_offset(pud, addr);
23747 + if (!pmd_present(*pmd))
23748 + continue;
23749 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
23750 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
23751 + else
23752 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
23753 + }
23754 +
23755 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
23756 + end = addr + KERNEL_IMAGE_SIZE;
23757 + for (; addr < end; addr += PMD_SIZE) {
23758 + pgd = pgd_offset_k(addr);
23759 + pud = pud_offset(pgd, addr);
23760 + pmd = pmd_offset(pud, addr);
23761 + if (!pmd_present(*pmd))
23762 + continue;
23763 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
23764 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
23765 + }
23766 +#endif
23767 +
23768 + flush_tlb_all();
23769 +#endif
23770 +
23771 free_init_pages("unused kernel memory",
23772 (unsigned long)(&__init_begin),
23773 (unsigned long)(&__init_end));
23774 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
23775 index 29f7c6d..b46b35b 100644
23776 --- a/arch/x86/mm/init_32.c
23777 +++ b/arch/x86/mm/init_32.c
23778 @@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
23779 }
23780
23781 /*
23782 - * Creates a middle page table and puts a pointer to it in the
23783 - * given global directory entry. This only returns the gd entry
23784 - * in non-PAE compilation mode, since the middle layer is folded.
23785 - */
23786 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
23787 -{
23788 - pud_t *pud;
23789 - pmd_t *pmd_table;
23790 -
23791 -#ifdef CONFIG_X86_PAE
23792 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
23793 - if (after_bootmem)
23794 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
23795 - else
23796 - pmd_table = (pmd_t *)alloc_low_page();
23797 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
23798 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
23799 - pud = pud_offset(pgd, 0);
23800 - BUG_ON(pmd_table != pmd_offset(pud, 0));
23801 -
23802 - return pmd_table;
23803 - }
23804 -#endif
23805 - pud = pud_offset(pgd, 0);
23806 - pmd_table = pmd_offset(pud, 0);
23807 -
23808 - return pmd_table;
23809 -}
23810 -
23811 -/*
23812 * Create a page table and place a pointer to it in a middle page
23813 * directory entry:
23814 */
23815 @@ -123,13 +93,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
23816 page_table = (pte_t *)alloc_low_page();
23817
23818 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
23819 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23820 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
23821 +#else
23822 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
23823 +#endif
23824 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
23825 }
23826
23827 return pte_offset_kernel(pmd, 0);
23828 }
23829
23830 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
23831 +{
23832 + pud_t *pud;
23833 + pmd_t *pmd_table;
23834 +
23835 + pud = pud_offset(pgd, 0);
23836 + pmd_table = pmd_offset(pud, 0);
23837 +
23838 + return pmd_table;
23839 +}
23840 +
23841 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
23842 {
23843 int pgd_idx = pgd_index(vaddr);
23844 @@ -203,6 +188,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
23845 int pgd_idx, pmd_idx;
23846 unsigned long vaddr;
23847 pgd_t *pgd;
23848 + pud_t *pud;
23849 pmd_t *pmd;
23850 pte_t *pte = NULL;
23851
23852 @@ -212,8 +198,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
23853 pgd = pgd_base + pgd_idx;
23854
23855 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
23856 - pmd = one_md_table_init(pgd);
23857 - pmd = pmd + pmd_index(vaddr);
23858 + pud = pud_offset(pgd, vaddr);
23859 + pmd = pmd_offset(pud, vaddr);
23860 +
23861 +#ifdef CONFIG_X86_PAE
23862 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
23863 +#endif
23864 +
23865 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
23866 pmd++, pmd_idx++) {
23867 pte = page_table_kmap_check(one_page_table_init(pmd),
23868 @@ -225,11 +216,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
23869 }
23870 }
23871
23872 -static inline int is_kernel_text(unsigned long addr)
23873 +static inline int is_kernel_text(unsigned long start, unsigned long end)
23874 {
23875 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
23876 - return 1;
23877 - return 0;
23878 + if ((start > ktla_ktva((unsigned long)_etext) ||
23879 + end <= ktla_ktva((unsigned long)_stext)) &&
23880 + (start > ktla_ktva((unsigned long)_einittext) ||
23881 + end <= ktla_ktva((unsigned long)_sinittext)) &&
23882 +
23883 +#ifdef CONFIG_ACPI_SLEEP
23884 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
23885 +#endif
23886 +
23887 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
23888 + return 0;
23889 + return 1;
23890 }
23891
23892 /*
23893 @@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned long start,
23894 unsigned long last_map_addr = end;
23895 unsigned long start_pfn, end_pfn;
23896 pgd_t *pgd_base = swapper_pg_dir;
23897 - int pgd_idx, pmd_idx, pte_ofs;
23898 + unsigned int pgd_idx, pmd_idx, pte_ofs;
23899 unsigned long pfn;
23900 pgd_t *pgd;
23901 + pud_t *pud;
23902 pmd_t *pmd;
23903 pte_t *pte;
23904 unsigned pages_2m, pages_4k;
23905 @@ -281,8 +282,13 @@ repeat:
23906 pfn = start_pfn;
23907 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
23908 pgd = pgd_base + pgd_idx;
23909 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
23910 - pmd = one_md_table_init(pgd);
23911 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
23912 + pud = pud_offset(pgd, 0);
23913 + pmd = pmd_offset(pud, 0);
23914 +
23915 +#ifdef CONFIG_X86_PAE
23916 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
23917 +#endif
23918
23919 if (pfn >= end_pfn)
23920 continue;
23921 @@ -294,14 +300,13 @@ repeat:
23922 #endif
23923 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
23924 pmd++, pmd_idx++) {
23925 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
23926 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
23927
23928 /*
23929 * Map with big pages if possible, otherwise
23930 * create normal page tables:
23931 */
23932 if (use_pse) {
23933 - unsigned int addr2;
23934 pgprot_t prot = PAGE_KERNEL_LARGE;
23935 /*
23936 * first pass will use the same initial
23937 @@ -311,11 +316,7 @@ repeat:
23938 __pgprot(PTE_IDENT_ATTR |
23939 _PAGE_PSE);
23940
23941 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
23942 - PAGE_OFFSET + PAGE_SIZE-1;
23943 -
23944 - if (is_kernel_text(addr) ||
23945 - is_kernel_text(addr2))
23946 + if (is_kernel_text(address, address + PMD_SIZE))
23947 prot = PAGE_KERNEL_LARGE_EXEC;
23948
23949 pages_2m++;
23950 @@ -332,7 +333,7 @@ repeat:
23951 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
23952 pte += pte_ofs;
23953 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
23954 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
23955 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
23956 pgprot_t prot = PAGE_KERNEL;
23957 /*
23958 * first pass will use the same initial
23959 @@ -340,7 +341,7 @@ repeat:
23960 */
23961 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
23962
23963 - if (is_kernel_text(addr))
23964 + if (is_kernel_text(address, address + PAGE_SIZE))
23965 prot = PAGE_KERNEL_EXEC;
23966
23967 pages_4k++;
23968 @@ -472,7 +473,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
23969
23970 pud = pud_offset(pgd, va);
23971 pmd = pmd_offset(pud, va);
23972 - if (!pmd_present(*pmd))
23973 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
23974 break;
23975
23976 pte = pte_offset_kernel(pmd, va);
23977 @@ -524,12 +525,10 @@ void __init early_ioremap_page_table_range_init(void)
23978
23979 static void __init pagetable_init(void)
23980 {
23981 - pgd_t *pgd_base = swapper_pg_dir;
23982 -
23983 - permanent_kmaps_init(pgd_base);
23984 + permanent_kmaps_init(swapper_pg_dir);
23985 }
23986
23987 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
23988 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
23989 EXPORT_SYMBOL_GPL(__supported_pte_mask);
23990
23991 /* user-defined highmem size */
23992 @@ -757,6 +756,12 @@ void __init mem_init(void)
23993
23994 pci_iommu_alloc();
23995
23996 +#ifdef CONFIG_PAX_PER_CPU_PGD
23997 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
23998 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
23999 + KERNEL_PGD_PTRS);
24000 +#endif
24001 +
24002 #ifdef CONFIG_FLATMEM
24003 BUG_ON(!mem_map);
24004 #endif
24005 @@ -774,7 +779,7 @@ void __init mem_init(void)
24006 set_highmem_pages_init();
24007
24008 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24009 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24010 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24011 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24012
24013 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24014 @@ -815,10 +820,10 @@ void __init mem_init(void)
24015 ((unsigned long)&__init_end -
24016 (unsigned long)&__init_begin) >> 10,
24017
24018 - (unsigned long)&_etext, (unsigned long)&_edata,
24019 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24020 + (unsigned long)&_sdata, (unsigned long)&_edata,
24021 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24022
24023 - (unsigned long)&_text, (unsigned long)&_etext,
24024 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24025 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24026
24027 /*
24028 @@ -896,6 +901,7 @@ void set_kernel_text_rw(void)
24029 if (!kernel_set_to_readonly)
24030 return;
24031
24032 + start = ktla_ktva(start);
24033 pr_debug("Set kernel text: %lx - %lx for read write\n",
24034 start, start+size);
24035
24036 @@ -910,6 +916,7 @@ void set_kernel_text_ro(void)
24037 if (!kernel_set_to_readonly)
24038 return;
24039
24040 + start = ktla_ktva(start);
24041 pr_debug("Set kernel text: %lx - %lx for read only\n",
24042 start, start+size);
24043
24044 @@ -938,6 +945,7 @@ void mark_rodata_ro(void)
24045 unsigned long start = PFN_ALIGN(_text);
24046 unsigned long size = PFN_ALIGN(_etext) - start;
24047
24048 + start = ktla_ktva(start);
24049 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24050 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24051 size >> 10);
24052 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24053 index bbaaa00..796fa65 100644
24054 --- a/arch/x86/mm/init_64.c
24055 +++ b/arch/x86/mm/init_64.c
24056 @@ -75,7 +75,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24057 * around without checking the pgd every time.
24058 */
24059
24060 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24061 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24062 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24063
24064 int force_personality32;
24065 @@ -108,12 +108,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24066
24067 for (address = start; address <= end; address += PGDIR_SIZE) {
24068 const pgd_t *pgd_ref = pgd_offset_k(address);
24069 +
24070 +#ifdef CONFIG_PAX_PER_CPU_PGD
24071 + unsigned long cpu;
24072 +#else
24073 struct page *page;
24074 +#endif
24075
24076 if (pgd_none(*pgd_ref))
24077 continue;
24078
24079 spin_lock(&pgd_lock);
24080 +
24081 +#ifdef CONFIG_PAX_PER_CPU_PGD
24082 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24083 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
24084 +#else
24085 list_for_each_entry(page, &pgd_list, lru) {
24086 pgd_t *pgd;
24087 spinlock_t *pgt_lock;
24088 @@ -122,6 +132,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24089 /* the pgt_lock only for Xen */
24090 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24091 spin_lock(pgt_lock);
24092 +#endif
24093
24094 if (pgd_none(*pgd))
24095 set_pgd(pgd, *pgd_ref);
24096 @@ -129,7 +140,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24097 BUG_ON(pgd_page_vaddr(*pgd)
24098 != pgd_page_vaddr(*pgd_ref));
24099
24100 +#ifndef CONFIG_PAX_PER_CPU_PGD
24101 spin_unlock(pgt_lock);
24102 +#endif
24103 +
24104 }
24105 spin_unlock(&pgd_lock);
24106 }
24107 @@ -203,7 +217,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
24108 pmd = fill_pmd(pud, vaddr);
24109 pte = fill_pte(pmd, vaddr);
24110
24111 + pax_open_kernel();
24112 set_pte(pte, new_pte);
24113 + pax_close_kernel();
24114
24115 /*
24116 * It's enough to flush this one mapping.
24117 @@ -262,14 +278,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
24118 pgd = pgd_offset_k((unsigned long)__va(phys));
24119 if (pgd_none(*pgd)) {
24120 pud = (pud_t *) spp_getpage();
24121 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
24122 - _PAGE_USER));
24123 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
24124 }
24125 pud = pud_offset(pgd, (unsigned long)__va(phys));
24126 if (pud_none(*pud)) {
24127 pmd = (pmd_t *) spp_getpage();
24128 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
24129 - _PAGE_USER));
24130 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
24131 }
24132 pmd = pmd_offset(pud, phys);
24133 BUG_ON(!pmd_none(*pmd));
24134 @@ -330,7 +344,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
24135 if (pfn >= pgt_buf_top)
24136 panic("alloc_low_page: ran out of memory");
24137
24138 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24139 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24140 clear_page(adr);
24141 *phys = pfn * PAGE_SIZE;
24142 return adr;
24143 @@ -346,7 +360,7 @@ static __ref void *map_low_page(void *virt)
24144
24145 phys = __pa(virt);
24146 left = phys & (PAGE_SIZE - 1);
24147 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24148 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24149 adr = (void *)(((unsigned long)adr) | left);
24150
24151 return adr;
24152 @@ -693,6 +707,12 @@ void __init mem_init(void)
24153
24154 pci_iommu_alloc();
24155
24156 +#ifdef CONFIG_PAX_PER_CPU_PGD
24157 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24158 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24159 + KERNEL_PGD_PTRS);
24160 +#endif
24161 +
24162 /* clear_bss() already clear the empty_zero_page */
24163
24164 reservedpages = 0;
24165 @@ -853,8 +873,8 @@ int kern_addr_valid(unsigned long addr)
24166 static struct vm_area_struct gate_vma = {
24167 .vm_start = VSYSCALL_START,
24168 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
24169 - .vm_page_prot = PAGE_READONLY_EXEC,
24170 - .vm_flags = VM_READ | VM_EXEC
24171 + .vm_page_prot = PAGE_READONLY,
24172 + .vm_flags = VM_READ
24173 };
24174
24175 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
24176 @@ -888,7 +908,7 @@ int in_gate_area_no_mm(unsigned long addr)
24177
24178 const char *arch_vma_name(struct vm_area_struct *vma)
24179 {
24180 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24181 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24182 return "[vdso]";
24183 if (vma == &gate_vma)
24184 return "[vsyscall]";
24185 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
24186 index 7b179b4..6bd1777 100644
24187 --- a/arch/x86/mm/iomap_32.c
24188 +++ b/arch/x86/mm/iomap_32.c
24189 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
24190 type = kmap_atomic_idx_push();
24191 idx = type + KM_TYPE_NR * smp_processor_id();
24192 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24193 +
24194 + pax_open_kernel();
24195 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
24196 + pax_close_kernel();
24197 +
24198 arch_flush_lazy_mmu_mode();
24199
24200 return (void *)vaddr;
24201 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
24202 index be1ef57..55f0160 100644
24203 --- a/arch/x86/mm/ioremap.c
24204 +++ b/arch/x86/mm/ioremap.c
24205 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
24206 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
24207 int is_ram = page_is_ram(pfn);
24208
24209 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
24210 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
24211 return NULL;
24212 WARN_ON_ONCE(is_ram);
24213 }
24214 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
24215
24216 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
24217 if (page_is_ram(start >> PAGE_SHIFT))
24218 +#ifdef CONFIG_HIGHMEM
24219 + if ((start >> PAGE_SHIFT) < max_low_pfn)
24220 +#endif
24221 return __va(phys);
24222
24223 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
24224 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
24225 early_param("early_ioremap_debug", early_ioremap_debug_setup);
24226
24227 static __initdata int after_paging_init;
24228 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
24229 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
24230
24231 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
24232 {
24233 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
24234 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
24235
24236 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
24237 - memset(bm_pte, 0, sizeof(bm_pte));
24238 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
24239 + pmd_populate_user(&init_mm, pmd, bm_pte);
24240
24241 /*
24242 * The boot-ioremap range spans multiple pmds, for which
24243 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
24244 index d87dd6d..bf3fa66 100644
24245 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
24246 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
24247 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
24248 * memory (e.g. tracked pages)? For now, we need this to avoid
24249 * invoking kmemcheck for PnP BIOS calls.
24250 */
24251 - if (regs->flags & X86_VM_MASK)
24252 + if (v8086_mode(regs))
24253 return false;
24254 - if (regs->cs != __KERNEL_CS)
24255 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
24256 return false;
24257
24258 pte = kmemcheck_pte_lookup(address);
24259 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
24260 index 845df68..1d8d29f 100644
24261 --- a/arch/x86/mm/mmap.c
24262 +++ b/arch/x86/mm/mmap.c
24263 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
24264 * Leave an at least ~128 MB hole with possible stack randomization.
24265 */
24266 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
24267 -#define MAX_GAP (TASK_SIZE/6*5)
24268 +#define MAX_GAP (pax_task_size/6*5)
24269
24270 static int mmap_is_legacy(void)
24271 {
24272 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
24273 return rnd << PAGE_SHIFT;
24274 }
24275
24276 -static unsigned long mmap_base(void)
24277 +static unsigned long mmap_base(struct mm_struct *mm)
24278 {
24279 unsigned long gap = rlimit(RLIMIT_STACK);
24280 + unsigned long pax_task_size = TASK_SIZE;
24281 +
24282 +#ifdef CONFIG_PAX_SEGMEXEC
24283 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24284 + pax_task_size = SEGMEXEC_TASK_SIZE;
24285 +#endif
24286
24287 if (gap < MIN_GAP)
24288 gap = MIN_GAP;
24289 else if (gap > MAX_GAP)
24290 gap = MAX_GAP;
24291
24292 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
24293 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
24294 }
24295
24296 /*
24297 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
24298 * does, but not when emulating X86_32
24299 */
24300 -static unsigned long mmap_legacy_base(void)
24301 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
24302 {
24303 - if (mmap_is_ia32())
24304 + if (mmap_is_ia32()) {
24305 +
24306 +#ifdef CONFIG_PAX_SEGMEXEC
24307 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24308 + return SEGMEXEC_TASK_UNMAPPED_BASE;
24309 + else
24310 +#endif
24311 +
24312 return TASK_UNMAPPED_BASE;
24313 - else
24314 + } else
24315 return TASK_UNMAPPED_BASE + mmap_rnd();
24316 }
24317
24318 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
24319 void arch_pick_mmap_layout(struct mm_struct *mm)
24320 {
24321 if (mmap_is_legacy()) {
24322 - mm->mmap_base = mmap_legacy_base();
24323 + mm->mmap_base = mmap_legacy_base(mm);
24324 +
24325 +#ifdef CONFIG_PAX_RANDMMAP
24326 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24327 + mm->mmap_base += mm->delta_mmap;
24328 +#endif
24329 +
24330 mm->get_unmapped_area = arch_get_unmapped_area;
24331 mm->unmap_area = arch_unmap_area;
24332 } else {
24333 - mm->mmap_base = mmap_base();
24334 + mm->mmap_base = mmap_base(mm);
24335 +
24336 +#ifdef CONFIG_PAX_RANDMMAP
24337 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24338 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
24339 +#endif
24340 +
24341 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
24342 mm->unmap_area = arch_unmap_area_topdown;
24343 }
24344 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
24345 index de54b9b..799051e 100644
24346 --- a/arch/x86/mm/mmio-mod.c
24347 +++ b/arch/x86/mm/mmio-mod.c
24348 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
24349 break;
24350 default:
24351 {
24352 - unsigned char *ip = (unsigned char *)instptr;
24353 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
24354 my_trace->opcode = MMIO_UNKNOWN_OP;
24355 my_trace->width = 0;
24356 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
24357 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
24358 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
24359 void __iomem *addr)
24360 {
24361 - static atomic_t next_id;
24362 + static atomic_unchecked_t next_id;
24363 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
24364 /* These are page-unaligned. */
24365 struct mmiotrace_map map = {
24366 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
24367 .private = trace
24368 },
24369 .phys = offset,
24370 - .id = atomic_inc_return(&next_id)
24371 + .id = atomic_inc_return_unchecked(&next_id)
24372 };
24373 map.map_id = trace->id;
24374
24375 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
24376 index b008656..773eac2 100644
24377 --- a/arch/x86/mm/pageattr-test.c
24378 +++ b/arch/x86/mm/pageattr-test.c
24379 @@ -36,7 +36,7 @@ enum {
24380
24381 static int pte_testbit(pte_t pte)
24382 {
24383 - return pte_flags(pte) & _PAGE_UNUSED1;
24384 + return pte_flags(pte) & _PAGE_CPA_TEST;
24385 }
24386
24387 struct split_state {
24388 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
24389 index f9e5267..77b1a40 100644
24390 --- a/arch/x86/mm/pageattr.c
24391 +++ b/arch/x86/mm/pageattr.c
24392 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
24393 */
24394 #ifdef CONFIG_PCI_BIOS
24395 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
24396 - pgprot_val(forbidden) |= _PAGE_NX;
24397 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
24398 #endif
24399
24400 /*
24401 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
24402 * Does not cover __inittext since that is gone later on. On
24403 * 64bit we do not enforce !NX on the low mapping
24404 */
24405 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
24406 - pgprot_val(forbidden) |= _PAGE_NX;
24407 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
24408 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
24409
24410 +#ifdef CONFIG_DEBUG_RODATA
24411 /*
24412 * The .rodata section needs to be read-only. Using the pfn
24413 * catches all aliases.
24414 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
24415 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
24416 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
24417 pgprot_val(forbidden) |= _PAGE_RW;
24418 +#endif
24419
24420 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
24421 /*
24422 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
24423 }
24424 #endif
24425
24426 +#ifdef CONFIG_PAX_KERNEXEC
24427 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
24428 + pgprot_val(forbidden) |= _PAGE_RW;
24429 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
24430 + }
24431 +#endif
24432 +
24433 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
24434
24435 return prot;
24436 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
24437 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
24438 {
24439 /* change init_mm */
24440 + pax_open_kernel();
24441 set_pte_atomic(kpte, pte);
24442 +
24443 #ifdef CONFIG_X86_32
24444 if (!SHARED_KERNEL_PMD) {
24445 +
24446 +#ifdef CONFIG_PAX_PER_CPU_PGD
24447 + unsigned long cpu;
24448 +#else
24449 struct page *page;
24450 +#endif
24451
24452 +#ifdef CONFIG_PAX_PER_CPU_PGD
24453 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24454 + pgd_t *pgd = get_cpu_pgd(cpu);
24455 +#else
24456 list_for_each_entry(page, &pgd_list, lru) {
24457 - pgd_t *pgd;
24458 + pgd_t *pgd = (pgd_t *)page_address(page);
24459 +#endif
24460 +
24461 pud_t *pud;
24462 pmd_t *pmd;
24463
24464 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
24465 + pgd += pgd_index(address);
24466 pud = pud_offset(pgd, address);
24467 pmd = pmd_offset(pud, address);
24468 set_pte_atomic((pte_t *)pmd, pte);
24469 }
24470 }
24471 #endif
24472 + pax_close_kernel();
24473 }
24474
24475 static int
24476 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
24477 index f6ff57b..481690f 100644
24478 --- a/arch/x86/mm/pat.c
24479 +++ b/arch/x86/mm/pat.c
24480 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
24481
24482 if (!entry) {
24483 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
24484 - current->comm, current->pid, start, end);
24485 + current->comm, task_pid_nr(current), start, end);
24486 return -EINVAL;
24487 }
24488
24489 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
24490 while (cursor < to) {
24491 if (!devmem_is_allowed(pfn)) {
24492 printk(KERN_INFO
24493 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
24494 - current->comm, from, to);
24495 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
24496 + current->comm, from, to, cursor);
24497 return 0;
24498 }
24499 cursor += PAGE_SIZE;
24500 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
24501 printk(KERN_INFO
24502 "%s:%d ioremap_change_attr failed %s "
24503 "for %Lx-%Lx\n",
24504 - current->comm, current->pid,
24505 + current->comm, task_pid_nr(current),
24506 cattr_name(flags),
24507 base, (unsigned long long)(base + size));
24508 return -EINVAL;
24509 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
24510 if (want_flags != flags) {
24511 printk(KERN_WARNING
24512 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
24513 - current->comm, current->pid,
24514 + current->comm, task_pid_nr(current),
24515 cattr_name(want_flags),
24516 (unsigned long long)paddr,
24517 (unsigned long long)(paddr + size),
24518 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
24519 free_memtype(paddr, paddr + size);
24520 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
24521 " for %Lx-%Lx, got %s\n",
24522 - current->comm, current->pid,
24523 + current->comm, task_pid_nr(current),
24524 cattr_name(want_flags),
24525 (unsigned long long)paddr,
24526 (unsigned long long)(paddr + size),
24527 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
24528 index 9f0614d..92ae64a 100644
24529 --- a/arch/x86/mm/pf_in.c
24530 +++ b/arch/x86/mm/pf_in.c
24531 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
24532 int i;
24533 enum reason_type rv = OTHERS;
24534
24535 - p = (unsigned char *)ins_addr;
24536 + p = (unsigned char *)ktla_ktva(ins_addr);
24537 p += skip_prefix(p, &prf);
24538 p += get_opcode(p, &opcode);
24539
24540 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
24541 struct prefix_bits prf;
24542 int i;
24543
24544 - p = (unsigned char *)ins_addr;
24545 + p = (unsigned char *)ktla_ktva(ins_addr);
24546 p += skip_prefix(p, &prf);
24547 p += get_opcode(p, &opcode);
24548
24549 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
24550 struct prefix_bits prf;
24551 int i;
24552
24553 - p = (unsigned char *)ins_addr;
24554 + p = (unsigned char *)ktla_ktva(ins_addr);
24555 p += skip_prefix(p, &prf);
24556 p += get_opcode(p, &opcode);
24557
24558 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
24559 struct prefix_bits prf;
24560 int i;
24561
24562 - p = (unsigned char *)ins_addr;
24563 + p = (unsigned char *)ktla_ktva(ins_addr);
24564 p += skip_prefix(p, &prf);
24565 p += get_opcode(p, &opcode);
24566 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
24567 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
24568 struct prefix_bits prf;
24569 int i;
24570
24571 - p = (unsigned char *)ins_addr;
24572 + p = (unsigned char *)ktla_ktva(ins_addr);
24573 p += skip_prefix(p, &prf);
24574 p += get_opcode(p, &opcode);
24575 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
24576 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
24577 index 8573b83..c3b1a30 100644
24578 --- a/arch/x86/mm/pgtable.c
24579 +++ b/arch/x86/mm/pgtable.c
24580 @@ -84,10 +84,52 @@ static inline void pgd_list_del(pgd_t *pgd)
24581 list_del(&page->lru);
24582 }
24583
24584 -#define UNSHARED_PTRS_PER_PGD \
24585 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
24586 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24587 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
24588
24589 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
24590 +{
24591 + while (count--)
24592 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
24593 +}
24594 +#endif
24595
24596 +#ifdef CONFIG_PAX_PER_CPU_PGD
24597 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
24598 +{
24599 + while (count--)
24600 +
24601 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24602 + *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
24603 +#else
24604 + *dst++ = *src++;
24605 +#endif
24606 +
24607 +}
24608 +#endif
24609 +
24610 +#ifdef CONFIG_X86_64
24611 +#define pxd_t pud_t
24612 +#define pyd_t pgd_t
24613 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
24614 +#define pxd_free(mm, pud) pud_free((mm), (pud))
24615 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
24616 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
24617 +#define PYD_SIZE PGDIR_SIZE
24618 +#else
24619 +#define pxd_t pmd_t
24620 +#define pyd_t pud_t
24621 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
24622 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
24623 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
24624 +#define pyd_offset(mm, address) pud_offset((mm), (address))
24625 +#define PYD_SIZE PUD_SIZE
24626 +#endif
24627 +
24628 +#ifdef CONFIG_PAX_PER_CPU_PGD
24629 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
24630 +static inline void pgd_dtor(pgd_t *pgd) {}
24631 +#else
24632 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
24633 {
24634 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
24635 @@ -128,6 +170,7 @@ static void pgd_dtor(pgd_t *pgd)
24636 pgd_list_del(pgd);
24637 spin_unlock(&pgd_lock);
24638 }
24639 +#endif
24640
24641 /*
24642 * List of all pgd's needed for non-PAE so it can invalidate entries
24643 @@ -140,7 +183,7 @@ static void pgd_dtor(pgd_t *pgd)
24644 * -- wli
24645 */
24646
24647 -#ifdef CONFIG_X86_PAE
24648 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24649 /*
24650 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
24651 * updating the top-level pagetable entries to guarantee the
24652 @@ -152,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
24653 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
24654 * and initialize the kernel pmds here.
24655 */
24656 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
24657 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
24658
24659 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
24660 {
24661 @@ -170,36 +213,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
24662 */
24663 flush_tlb_mm(mm);
24664 }
24665 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
24666 +#define PREALLOCATED_PXDS USER_PGD_PTRS
24667 #else /* !CONFIG_X86_PAE */
24668
24669 /* No need to prepopulate any pagetable entries in non-PAE modes. */
24670 -#define PREALLOCATED_PMDS 0
24671 +#define PREALLOCATED_PXDS 0
24672
24673 #endif /* CONFIG_X86_PAE */
24674
24675 -static void free_pmds(pmd_t *pmds[])
24676 +static void free_pxds(pxd_t *pxds[])
24677 {
24678 int i;
24679
24680 - for(i = 0; i < PREALLOCATED_PMDS; i++)
24681 - if (pmds[i])
24682 - free_page((unsigned long)pmds[i]);
24683 + for(i = 0; i < PREALLOCATED_PXDS; i++)
24684 + if (pxds[i])
24685 + free_page((unsigned long)pxds[i]);
24686 }
24687
24688 -static int preallocate_pmds(pmd_t *pmds[])
24689 +static int preallocate_pxds(pxd_t *pxds[])
24690 {
24691 int i;
24692 bool failed = false;
24693
24694 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
24695 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
24696 - if (pmd == NULL)
24697 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
24698 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
24699 + if (pxd == NULL)
24700 failed = true;
24701 - pmds[i] = pmd;
24702 + pxds[i] = pxd;
24703 }
24704
24705 if (failed) {
24706 - free_pmds(pmds);
24707 + free_pxds(pxds);
24708 return -ENOMEM;
24709 }
24710
24711 @@ -212,51 +257,55 @@ static int preallocate_pmds(pmd_t *pmds[])
24712 * preallocate which never got a corresponding vma will need to be
24713 * freed manually.
24714 */
24715 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
24716 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
24717 {
24718 int i;
24719
24720 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
24721 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
24722 pgd_t pgd = pgdp[i];
24723
24724 if (pgd_val(pgd) != 0) {
24725 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
24726 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
24727
24728 - pgdp[i] = native_make_pgd(0);
24729 + set_pgd(pgdp + i, native_make_pgd(0));
24730
24731 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
24732 - pmd_free(mm, pmd);
24733 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
24734 + pxd_free(mm, pxd);
24735 }
24736 }
24737 }
24738
24739 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
24740 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
24741 {
24742 - pud_t *pud;
24743 + pyd_t *pyd;
24744 unsigned long addr;
24745 int i;
24746
24747 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
24748 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
24749 return;
24750
24751 - pud = pud_offset(pgd, 0);
24752 +#ifdef CONFIG_X86_64
24753 + pyd = pyd_offset(mm, 0L);
24754 +#else
24755 + pyd = pyd_offset(pgd, 0L);
24756 +#endif
24757
24758 - for (addr = i = 0; i < PREALLOCATED_PMDS;
24759 - i++, pud++, addr += PUD_SIZE) {
24760 - pmd_t *pmd = pmds[i];
24761 + for (addr = i = 0; i < PREALLOCATED_PXDS;
24762 + i++, pyd++, addr += PYD_SIZE) {
24763 + pxd_t *pxd = pxds[i];
24764
24765 if (i >= KERNEL_PGD_BOUNDARY)
24766 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
24767 - sizeof(pmd_t) * PTRS_PER_PMD);
24768 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
24769 + sizeof(pxd_t) * PTRS_PER_PMD);
24770
24771 - pud_populate(mm, pud, pmd);
24772 + pyd_populate(mm, pyd, pxd);
24773 }
24774 }
24775
24776 pgd_t *pgd_alloc(struct mm_struct *mm)
24777 {
24778 pgd_t *pgd;
24779 - pmd_t *pmds[PREALLOCATED_PMDS];
24780 + pxd_t *pxds[PREALLOCATED_PXDS];
24781
24782 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
24783
24784 @@ -265,11 +314,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
24785
24786 mm->pgd = pgd;
24787
24788 - if (preallocate_pmds(pmds) != 0)
24789 + if (preallocate_pxds(pxds) != 0)
24790 goto out_free_pgd;
24791
24792 if (paravirt_pgd_alloc(mm) != 0)
24793 - goto out_free_pmds;
24794 + goto out_free_pxds;
24795
24796 /*
24797 * Make sure that pre-populating the pmds is atomic with
24798 @@ -279,14 +328,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
24799 spin_lock(&pgd_lock);
24800
24801 pgd_ctor(mm, pgd);
24802 - pgd_prepopulate_pmd(mm, pgd, pmds);
24803 + pgd_prepopulate_pxd(mm, pgd, pxds);
24804
24805 spin_unlock(&pgd_lock);
24806
24807 return pgd;
24808
24809 -out_free_pmds:
24810 - free_pmds(pmds);
24811 +out_free_pxds:
24812 + free_pxds(pxds);
24813 out_free_pgd:
24814 free_page((unsigned long)pgd);
24815 out:
24816 @@ -295,7 +344,7 @@ out:
24817
24818 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
24819 {
24820 - pgd_mop_up_pmds(mm, pgd);
24821 + pgd_mop_up_pxds(mm, pgd);
24822 pgd_dtor(pgd);
24823 paravirt_pgd_free(mm, pgd);
24824 free_page((unsigned long)pgd);
24825 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
24826 index cac7184..09a39fa 100644
24827 --- a/arch/x86/mm/pgtable_32.c
24828 +++ b/arch/x86/mm/pgtable_32.c
24829 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
24830 return;
24831 }
24832 pte = pte_offset_kernel(pmd, vaddr);
24833 +
24834 + pax_open_kernel();
24835 if (pte_val(pteval))
24836 set_pte_at(&init_mm, vaddr, pte, pteval);
24837 else
24838 pte_clear(&init_mm, vaddr, pte);
24839 + pax_close_kernel();
24840
24841 /*
24842 * It's enough to flush this one mapping.
24843 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
24844 index 410531d..0f16030 100644
24845 --- a/arch/x86/mm/setup_nx.c
24846 +++ b/arch/x86/mm/setup_nx.c
24847 @@ -5,8 +5,10 @@
24848 #include <asm/pgtable.h>
24849 #include <asm/proto.h>
24850
24851 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
24852 static int disable_nx __cpuinitdata;
24853
24854 +#ifndef CONFIG_PAX_PAGEEXEC
24855 /*
24856 * noexec = on|off
24857 *
24858 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
24859 return 0;
24860 }
24861 early_param("noexec", noexec_setup);
24862 +#endif
24863 +
24864 +#endif
24865
24866 void __cpuinit x86_configure_nx(void)
24867 {
24868 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
24869 if (cpu_has_nx && !disable_nx)
24870 __supported_pte_mask |= _PAGE_NX;
24871 else
24872 +#endif
24873 __supported_pte_mask &= ~_PAGE_NX;
24874 }
24875
24876 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
24877 index d6c0418..06a0ad5 100644
24878 --- a/arch/x86/mm/tlb.c
24879 +++ b/arch/x86/mm/tlb.c
24880 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
24881 BUG();
24882 cpumask_clear_cpu(cpu,
24883 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
24884 +
24885 +#ifndef CONFIG_PAX_PER_CPU_PGD
24886 load_cr3(swapper_pg_dir);
24887 +#endif
24888 +
24889 }
24890 EXPORT_SYMBOL_GPL(leave_mm);
24891
24892 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
24893 index 6687022..ceabcfa 100644
24894 --- a/arch/x86/net/bpf_jit.S
24895 +++ b/arch/x86/net/bpf_jit.S
24896 @@ -9,6 +9,7 @@
24897 */
24898 #include <linux/linkage.h>
24899 #include <asm/dwarf2.h>
24900 +#include <asm/alternative-asm.h>
24901
24902 /*
24903 * Calling convention :
24904 @@ -35,6 +36,7 @@ sk_load_word:
24905 jle bpf_slow_path_word
24906 mov (SKBDATA,%rsi),%eax
24907 bswap %eax /* ntohl() */
24908 + pax_force_retaddr
24909 ret
24910
24911
24912 @@ -53,6 +55,7 @@ sk_load_half:
24913 jle bpf_slow_path_half
24914 movzwl (SKBDATA,%rsi),%eax
24915 rol $8,%ax # ntohs()
24916 + pax_force_retaddr
24917 ret
24918
24919 sk_load_byte_ind:
24920 @@ -66,6 +69,7 @@ sk_load_byte:
24921 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
24922 jle bpf_slow_path_byte
24923 movzbl (SKBDATA,%rsi),%eax
24924 + pax_force_retaddr
24925 ret
24926
24927 /**
24928 @@ -82,6 +86,7 @@ ENTRY(sk_load_byte_msh)
24929 movzbl (SKBDATA,%rsi),%ebx
24930 and $15,%bl
24931 shl $2,%bl
24932 + pax_force_retaddr
24933 ret
24934 CFI_ENDPROC
24935 ENDPROC(sk_load_byte_msh)
24936 @@ -91,6 +96,7 @@ bpf_error:
24937 xor %eax,%eax
24938 mov -8(%rbp),%rbx
24939 leaveq
24940 + pax_force_retaddr
24941 ret
24942
24943 /* rsi contains offset and can be scratched */
24944 @@ -113,6 +119,7 @@ bpf_slow_path_word:
24945 js bpf_error
24946 mov -12(%rbp),%eax
24947 bswap %eax
24948 + pax_force_retaddr
24949 ret
24950
24951 bpf_slow_path_half:
24952 @@ -121,12 +128,14 @@ bpf_slow_path_half:
24953 mov -12(%rbp),%ax
24954 rol $8,%ax
24955 movzwl %ax,%eax
24956 + pax_force_retaddr
24957 ret
24958
24959 bpf_slow_path_byte:
24960 bpf_slow_path_common(1)
24961 js bpf_error
24962 movzbl -12(%rbp),%eax
24963 + pax_force_retaddr
24964 ret
24965
24966 bpf_slow_path_byte_msh:
24967 @@ -137,4 +146,5 @@ bpf_slow_path_byte_msh:
24968 and $15,%al
24969 shl $2,%al
24970 xchg %eax,%ebx
24971 + pax_force_retaddr
24972 ret
24973 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
24974 index 7c1b765..8c072c6 100644
24975 --- a/arch/x86/net/bpf_jit_comp.c
24976 +++ b/arch/x86/net/bpf_jit_comp.c
24977 @@ -117,6 +117,10 @@ static inline void bpf_flush_icache(void *start, void *end)
24978 set_fs(old_fs);
24979 }
24980
24981 +struct bpf_jit_work {
24982 + struct work_struct work;
24983 + void *image;
24984 +};
24985
24986 void bpf_jit_compile(struct sk_filter *fp)
24987 {
24988 @@ -141,6 +145,10 @@ void bpf_jit_compile(struct sk_filter *fp)
24989 if (addrs == NULL)
24990 return;
24991
24992 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
24993 + if (!fp->work)
24994 + goto out;
24995 +
24996 /* Before first pass, make a rough estimation of addrs[]
24997 * each bpf instruction is translated to less than 64 bytes
24998 */
24999 @@ -476,7 +484,7 @@ void bpf_jit_compile(struct sk_filter *fp)
25000 func = sk_load_word;
25001 common_load: seen |= SEEN_DATAREF;
25002 if ((int)K < 0)
25003 - goto out;
25004 + goto error;
25005 t_offset = func - (image + addrs[i]);
25006 EMIT1_off32(0xbe, K); /* mov imm32,%esi */
25007 EMIT1_off32(0xe8, t_offset); /* call */
25008 @@ -586,17 +594,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25009 break;
25010 default:
25011 /* hmm, too complex filter, give up with jit compiler */
25012 - goto out;
25013 + goto error;
25014 }
25015 ilen = prog - temp;
25016 if (image) {
25017 if (unlikely(proglen + ilen > oldproglen)) {
25018 pr_err("bpb_jit_compile fatal error\n");
25019 - kfree(addrs);
25020 - module_free(NULL, image);
25021 - return;
25022 + module_free_exec(NULL, image);
25023 + goto error;
25024 }
25025 + pax_open_kernel();
25026 memcpy(image + proglen, temp, ilen);
25027 + pax_close_kernel();
25028 }
25029 proglen += ilen;
25030 addrs[i] = proglen;
25031 @@ -617,11 +626,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25032 break;
25033 }
25034 if (proglen == oldproglen) {
25035 - image = module_alloc(max_t(unsigned int,
25036 - proglen,
25037 - sizeof(struct work_struct)));
25038 + image = module_alloc_exec(proglen);
25039 if (!image)
25040 - goto out;
25041 + goto error;
25042 }
25043 oldproglen = proglen;
25044 }
25045 @@ -637,7 +644,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25046 bpf_flush_icache(image, image + proglen);
25047
25048 fp->bpf_func = (void *)image;
25049 - }
25050 + } else
25051 +error:
25052 + kfree(fp->work);
25053 +
25054 out:
25055 kfree(addrs);
25056 return;
25057 @@ -645,18 +655,20 @@ out:
25058
25059 static void jit_free_defer(struct work_struct *arg)
25060 {
25061 - module_free(NULL, arg);
25062 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
25063 + kfree(arg);
25064 }
25065
25066 /* run from softirq, we must use a work_struct to call
25067 - * module_free() from process context
25068 + * module_free_exec() from process context
25069 */
25070 void bpf_jit_free(struct sk_filter *fp)
25071 {
25072 if (fp->bpf_func != sk_run_filter) {
25073 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
25074 + struct work_struct *work = &fp->work->work;
25075
25076 INIT_WORK(work, jit_free_defer);
25077 + fp->work->image = fp->bpf_func;
25078 schedule_work(work);
25079 }
25080 }
25081 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
25082 index bff89df..377758a 100644
25083 --- a/arch/x86/oprofile/backtrace.c
25084 +++ b/arch/x86/oprofile/backtrace.c
25085 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
25086 struct stack_frame_ia32 *fp;
25087 unsigned long bytes;
25088
25089 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25090 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25091 if (bytes != sizeof(bufhead))
25092 return NULL;
25093
25094 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
25095 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
25096
25097 oprofile_add_trace(bufhead[0].return_address);
25098
25099 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
25100 struct stack_frame bufhead[2];
25101 unsigned long bytes;
25102
25103 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25104 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25105 if (bytes != sizeof(bufhead))
25106 return NULL;
25107
25108 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
25109 {
25110 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
25111
25112 - if (!user_mode_vm(regs)) {
25113 + if (!user_mode(regs)) {
25114 unsigned long stack = kernel_stack_pointer(regs);
25115 if (depth)
25116 dump_trace(NULL, regs, (unsigned long *)stack, 0,
25117 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
25118 index cb29191..036766d 100644
25119 --- a/arch/x86/pci/mrst.c
25120 +++ b/arch/x86/pci/mrst.c
25121 @@ -234,7 +234,9 @@ int __init pci_mrst_init(void)
25122 printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n");
25123 pci_mmcfg_late_init();
25124 pcibios_enable_irq = mrst_pci_irq_enable;
25125 - pci_root_ops = pci_mrst_ops;
25126 + pax_open_kernel();
25127 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
25128 + pax_close_kernel();
25129 /* Continue with standard init */
25130 return 1;
25131 }
25132 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
25133 index db0e9a5..0372c14 100644
25134 --- a/arch/x86/pci/pcbios.c
25135 +++ b/arch/x86/pci/pcbios.c
25136 @@ -79,50 +79,93 @@ union bios32 {
25137 static struct {
25138 unsigned long address;
25139 unsigned short segment;
25140 -} bios32_indirect = { 0, __KERNEL_CS };
25141 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
25142
25143 /*
25144 * Returns the entry point for the given service, NULL on error
25145 */
25146
25147 -static unsigned long bios32_service(unsigned long service)
25148 +static unsigned long __devinit bios32_service(unsigned long service)
25149 {
25150 unsigned char return_code; /* %al */
25151 unsigned long address; /* %ebx */
25152 unsigned long length; /* %ecx */
25153 unsigned long entry; /* %edx */
25154 unsigned long flags;
25155 + struct desc_struct d, *gdt;
25156
25157 local_irq_save(flags);
25158 - __asm__("lcall *(%%edi); cld"
25159 +
25160 + gdt = get_cpu_gdt_table(smp_processor_id());
25161 +
25162 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
25163 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25164 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
25165 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25166 +
25167 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
25168 : "=a" (return_code),
25169 "=b" (address),
25170 "=c" (length),
25171 "=d" (entry)
25172 : "0" (service),
25173 "1" (0),
25174 - "D" (&bios32_indirect));
25175 + "D" (&bios32_indirect),
25176 + "r"(__PCIBIOS_DS)
25177 + : "memory");
25178 +
25179 + pax_open_kernel();
25180 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
25181 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
25182 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
25183 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
25184 + pax_close_kernel();
25185 +
25186 local_irq_restore(flags);
25187
25188 switch (return_code) {
25189 - case 0:
25190 - return address + entry;
25191 - case 0x80: /* Not present */
25192 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
25193 - return 0;
25194 - default: /* Shouldn't happen */
25195 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
25196 - service, return_code);
25197 + case 0: {
25198 + int cpu;
25199 + unsigned char flags;
25200 +
25201 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
25202 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
25203 + printk(KERN_WARNING "bios32_service: not valid\n");
25204 return 0;
25205 + }
25206 + address = address + PAGE_OFFSET;
25207 + length += 16UL; /* some BIOSs underreport this... */
25208 + flags = 4;
25209 + if (length >= 64*1024*1024) {
25210 + length >>= PAGE_SHIFT;
25211 + flags |= 8;
25212 + }
25213 +
25214 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
25215 + gdt = get_cpu_gdt_table(cpu);
25216 + pack_descriptor(&d, address, length, 0x9b, flags);
25217 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25218 + pack_descriptor(&d, address, length, 0x93, flags);
25219 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25220 + }
25221 + return entry;
25222 + }
25223 + case 0x80: /* Not present */
25224 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
25225 + return 0;
25226 + default: /* Shouldn't happen */
25227 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
25228 + service, return_code);
25229 + return 0;
25230 }
25231 }
25232
25233 static struct {
25234 unsigned long address;
25235 unsigned short segment;
25236 -} pci_indirect = { 0, __KERNEL_CS };
25237 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
25238
25239 -static int pci_bios_present;
25240 +static int pci_bios_present __read_only;
25241
25242 static int __devinit check_pcibios(void)
25243 {
25244 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
25245 unsigned long flags, pcibios_entry;
25246
25247 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
25248 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
25249 + pci_indirect.address = pcibios_entry;
25250
25251 local_irq_save(flags);
25252 - __asm__(
25253 - "lcall *(%%edi); cld\n\t"
25254 + __asm__("movw %w6, %%ds\n\t"
25255 + "lcall *%%ss:(%%edi); cld\n\t"
25256 + "push %%ss\n\t"
25257 + "pop %%ds\n\t"
25258 "jc 1f\n\t"
25259 "xor %%ah, %%ah\n"
25260 "1:"
25261 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
25262 "=b" (ebx),
25263 "=c" (ecx)
25264 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
25265 - "D" (&pci_indirect)
25266 + "D" (&pci_indirect),
25267 + "r" (__PCIBIOS_DS)
25268 : "memory");
25269 local_irq_restore(flags);
25270
25271 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25272
25273 switch (len) {
25274 case 1:
25275 - __asm__("lcall *(%%esi); cld\n\t"
25276 + __asm__("movw %w6, %%ds\n\t"
25277 + "lcall *%%ss:(%%esi); cld\n\t"
25278 + "push %%ss\n\t"
25279 + "pop %%ds\n\t"
25280 "jc 1f\n\t"
25281 "xor %%ah, %%ah\n"
25282 "1:"
25283 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25284 : "1" (PCIBIOS_READ_CONFIG_BYTE),
25285 "b" (bx),
25286 "D" ((long)reg),
25287 - "S" (&pci_indirect));
25288 + "S" (&pci_indirect),
25289 + "r" (__PCIBIOS_DS));
25290 /*
25291 * Zero-extend the result beyond 8 bits, do not trust the
25292 * BIOS having done it:
25293 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25294 *value &= 0xff;
25295 break;
25296 case 2:
25297 - __asm__("lcall *(%%esi); cld\n\t"
25298 + __asm__("movw %w6, %%ds\n\t"
25299 + "lcall *%%ss:(%%esi); cld\n\t"
25300 + "push %%ss\n\t"
25301 + "pop %%ds\n\t"
25302 "jc 1f\n\t"
25303 "xor %%ah, %%ah\n"
25304 "1:"
25305 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25306 : "1" (PCIBIOS_READ_CONFIG_WORD),
25307 "b" (bx),
25308 "D" ((long)reg),
25309 - "S" (&pci_indirect));
25310 + "S" (&pci_indirect),
25311 + "r" (__PCIBIOS_DS));
25312 /*
25313 * Zero-extend the result beyond 16 bits, do not trust the
25314 * BIOS having done it:
25315 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25316 *value &= 0xffff;
25317 break;
25318 case 4:
25319 - __asm__("lcall *(%%esi); cld\n\t"
25320 + __asm__("movw %w6, %%ds\n\t"
25321 + "lcall *%%ss:(%%esi); cld\n\t"
25322 + "push %%ss\n\t"
25323 + "pop %%ds\n\t"
25324 "jc 1f\n\t"
25325 "xor %%ah, %%ah\n"
25326 "1:"
25327 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25328 : "1" (PCIBIOS_READ_CONFIG_DWORD),
25329 "b" (bx),
25330 "D" ((long)reg),
25331 - "S" (&pci_indirect));
25332 + "S" (&pci_indirect),
25333 + "r" (__PCIBIOS_DS));
25334 break;
25335 }
25336
25337 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
25338
25339 switch (len) {
25340 case 1:
25341 - __asm__("lcall *(%%esi); cld\n\t"
25342 + __asm__("movw %w6, %%ds\n\t"
25343 + "lcall *%%ss:(%%esi); cld\n\t"
25344 + "push %%ss\n\t"
25345 + "pop %%ds\n\t"
25346 "jc 1f\n\t"
25347 "xor %%ah, %%ah\n"
25348 "1:"
25349 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
25350 "c" (value),
25351 "b" (bx),
25352 "D" ((long)reg),
25353 - "S" (&pci_indirect));
25354 + "S" (&pci_indirect),
25355 + "r" (__PCIBIOS_DS));
25356 break;
25357 case 2:
25358 - __asm__("lcall *(%%esi); cld\n\t"
25359 + __asm__("movw %w6, %%ds\n\t"
25360 + "lcall *%%ss:(%%esi); cld\n\t"
25361 + "push %%ss\n\t"
25362 + "pop %%ds\n\t"
25363 "jc 1f\n\t"
25364 "xor %%ah, %%ah\n"
25365 "1:"
25366 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
25367 "c" (value),
25368 "b" (bx),
25369 "D" ((long)reg),
25370 - "S" (&pci_indirect));
25371 + "S" (&pci_indirect),
25372 + "r" (__PCIBIOS_DS));
25373 break;
25374 case 4:
25375 - __asm__("lcall *(%%esi); cld\n\t"
25376 + __asm__("movw %w6, %%ds\n\t"
25377 + "lcall *%%ss:(%%esi); cld\n\t"
25378 + "push %%ss\n\t"
25379 + "pop %%ds\n\t"
25380 "jc 1f\n\t"
25381 "xor %%ah, %%ah\n"
25382 "1:"
25383 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
25384 "c" (value),
25385 "b" (bx),
25386 "D" ((long)reg),
25387 - "S" (&pci_indirect));
25388 + "S" (&pci_indirect),
25389 + "r" (__PCIBIOS_DS));
25390 break;
25391 }
25392
25393 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
25394
25395 DBG("PCI: Fetching IRQ routing table... ");
25396 __asm__("push %%es\n\t"
25397 + "movw %w8, %%ds\n\t"
25398 "push %%ds\n\t"
25399 "pop %%es\n\t"
25400 - "lcall *(%%esi); cld\n\t"
25401 + "lcall *%%ss:(%%esi); cld\n\t"
25402 "pop %%es\n\t"
25403 + "push %%ss\n\t"
25404 + "pop %%ds\n"
25405 "jc 1f\n\t"
25406 "xor %%ah, %%ah\n"
25407 "1:"
25408 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
25409 "1" (0),
25410 "D" ((long) &opt),
25411 "S" (&pci_indirect),
25412 - "m" (opt)
25413 + "m" (opt),
25414 + "r" (__PCIBIOS_DS)
25415 : "memory");
25416 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
25417 if (ret & 0xff00)
25418 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
25419 {
25420 int ret;
25421
25422 - __asm__("lcall *(%%esi); cld\n\t"
25423 + __asm__("movw %w5, %%ds\n\t"
25424 + "lcall *%%ss:(%%esi); cld\n\t"
25425 + "push %%ss\n\t"
25426 + "pop %%ds\n"
25427 "jc 1f\n\t"
25428 "xor %%ah, %%ah\n"
25429 "1:"
25430 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
25431 : "0" (PCIBIOS_SET_PCI_HW_INT),
25432 "b" ((dev->bus->number << 8) | dev->devfn),
25433 "c" ((irq << 8) | (pin + 10)),
25434 - "S" (&pci_indirect));
25435 + "S" (&pci_indirect),
25436 + "r" (__PCIBIOS_DS));
25437 return !(ret & 0xff00);
25438 }
25439 EXPORT_SYMBOL(pcibios_set_irq_routing);
25440 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
25441 index 40e4469..1ab536e 100644
25442 --- a/arch/x86/platform/efi/efi_32.c
25443 +++ b/arch/x86/platform/efi/efi_32.c
25444 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
25445 {
25446 struct desc_ptr gdt_descr;
25447
25448 +#ifdef CONFIG_PAX_KERNEXEC
25449 + struct desc_struct d;
25450 +#endif
25451 +
25452 local_irq_save(efi_rt_eflags);
25453
25454 load_cr3(initial_page_table);
25455 __flush_tlb_all();
25456
25457 +#ifdef CONFIG_PAX_KERNEXEC
25458 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
25459 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
25460 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
25461 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
25462 +#endif
25463 +
25464 gdt_descr.address = __pa(get_cpu_gdt_table(0));
25465 gdt_descr.size = GDT_SIZE - 1;
25466 load_gdt(&gdt_descr);
25467 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
25468 {
25469 struct desc_ptr gdt_descr;
25470
25471 +#ifdef CONFIG_PAX_KERNEXEC
25472 + struct desc_struct d;
25473 +
25474 + memset(&d, 0, sizeof d);
25475 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
25476 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
25477 +#endif
25478 +
25479 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
25480 gdt_descr.size = GDT_SIZE - 1;
25481 load_gdt(&gdt_descr);
25482 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
25483 index fbe66e6..c5c0dd2 100644
25484 --- a/arch/x86/platform/efi/efi_stub_32.S
25485 +++ b/arch/x86/platform/efi/efi_stub_32.S
25486 @@ -6,7 +6,9 @@
25487 */
25488
25489 #include <linux/linkage.h>
25490 +#include <linux/init.h>
25491 #include <asm/page_types.h>
25492 +#include <asm/segment.h>
25493
25494 /*
25495 * efi_call_phys(void *, ...) is a function with variable parameters.
25496 @@ -20,7 +22,7 @@
25497 * service functions will comply with gcc calling convention, too.
25498 */
25499
25500 -.text
25501 +__INIT
25502 ENTRY(efi_call_phys)
25503 /*
25504 * 0. The function can only be called in Linux kernel. So CS has been
25505 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
25506 * The mapping of lower virtual memory has been created in prelog and
25507 * epilog.
25508 */
25509 - movl $1f, %edx
25510 - subl $__PAGE_OFFSET, %edx
25511 - jmp *%edx
25512 + movl $(__KERNEXEC_EFI_DS), %edx
25513 + mov %edx, %ds
25514 + mov %edx, %es
25515 + mov %edx, %ss
25516 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
25517 1:
25518
25519 /*
25520 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
25521 * parameter 2, ..., param n. To make things easy, we save the return
25522 * address of efi_call_phys in a global variable.
25523 */
25524 - popl %edx
25525 - movl %edx, saved_return_addr
25526 - /* get the function pointer into ECX*/
25527 - popl %ecx
25528 - movl %ecx, efi_rt_function_ptr
25529 - movl $2f, %edx
25530 - subl $__PAGE_OFFSET, %edx
25531 - pushl %edx
25532 + popl (saved_return_addr)
25533 + popl (efi_rt_function_ptr)
25534
25535 /*
25536 * 3. Clear PG bit in %CR0.
25537 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
25538 /*
25539 * 5. Call the physical function.
25540 */
25541 - jmp *%ecx
25542 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
25543
25544 -2:
25545 /*
25546 * 6. After EFI runtime service returns, control will return to
25547 * following instruction. We'd better readjust stack pointer first.
25548 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
25549 movl %cr0, %edx
25550 orl $0x80000000, %edx
25551 movl %edx, %cr0
25552 - jmp 1f
25553 -1:
25554 +
25555 /*
25556 * 8. Now restore the virtual mode from flat mode by
25557 * adding EIP with PAGE_OFFSET.
25558 */
25559 - movl $1f, %edx
25560 - jmp *%edx
25561 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
25562 1:
25563 + movl $(__KERNEL_DS), %edx
25564 + mov %edx, %ds
25565 + mov %edx, %es
25566 + mov %edx, %ss
25567
25568 /*
25569 * 9. Balance the stack. And because EAX contain the return value,
25570 * we'd better not clobber it.
25571 */
25572 - leal efi_rt_function_ptr, %edx
25573 - movl (%edx), %ecx
25574 - pushl %ecx
25575 + pushl (efi_rt_function_ptr)
25576
25577 /*
25578 - * 10. Push the saved return address onto the stack and return.
25579 + * 10. Return to the saved return address.
25580 */
25581 - leal saved_return_addr, %edx
25582 - movl (%edx), %ecx
25583 - pushl %ecx
25584 - ret
25585 + jmpl *(saved_return_addr)
25586 ENDPROC(efi_call_phys)
25587 .previous
25588
25589 -.data
25590 +__INITDATA
25591 saved_return_addr:
25592 .long 0
25593 efi_rt_function_ptr:
25594 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
25595 index 4c07cca..2c8427d 100644
25596 --- a/arch/x86/platform/efi/efi_stub_64.S
25597 +++ b/arch/x86/platform/efi/efi_stub_64.S
25598 @@ -7,6 +7,7 @@
25599 */
25600
25601 #include <linux/linkage.h>
25602 +#include <asm/alternative-asm.h>
25603
25604 #define SAVE_XMM \
25605 mov %rsp, %rax; \
25606 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
25607 call *%rdi
25608 addq $32, %rsp
25609 RESTORE_XMM
25610 + pax_force_retaddr 0, 1
25611 ret
25612 ENDPROC(efi_call0)
25613
25614 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
25615 call *%rdi
25616 addq $32, %rsp
25617 RESTORE_XMM
25618 + pax_force_retaddr 0, 1
25619 ret
25620 ENDPROC(efi_call1)
25621
25622 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
25623 call *%rdi
25624 addq $32, %rsp
25625 RESTORE_XMM
25626 + pax_force_retaddr 0, 1
25627 ret
25628 ENDPROC(efi_call2)
25629
25630 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
25631 call *%rdi
25632 addq $32, %rsp
25633 RESTORE_XMM
25634 + pax_force_retaddr 0, 1
25635 ret
25636 ENDPROC(efi_call3)
25637
25638 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
25639 call *%rdi
25640 addq $32, %rsp
25641 RESTORE_XMM
25642 + pax_force_retaddr 0, 1
25643 ret
25644 ENDPROC(efi_call4)
25645
25646 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
25647 call *%rdi
25648 addq $48, %rsp
25649 RESTORE_XMM
25650 + pax_force_retaddr 0, 1
25651 ret
25652 ENDPROC(efi_call5)
25653
25654 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
25655 call *%rdi
25656 addq $48, %rsp
25657 RESTORE_XMM
25658 + pax_force_retaddr 0, 1
25659 ret
25660 ENDPROC(efi_call6)
25661 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
25662 index ad4ec1c..686479e 100644
25663 --- a/arch/x86/platform/mrst/mrst.c
25664 +++ b/arch/x86/platform/mrst/mrst.c
25665 @@ -76,18 +76,20 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
25666 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
25667 int sfi_mrtc_num;
25668
25669 -static void mrst_power_off(void)
25670 +static __noreturn void mrst_power_off(void)
25671 {
25672 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
25673 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 1);
25674 + BUG();
25675 }
25676
25677 -static void mrst_reboot(void)
25678 +static __noreturn void mrst_reboot(void)
25679 {
25680 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
25681 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
25682 else
25683 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
25684 + BUG();
25685 }
25686
25687 /* parse all the mtimer info to a static mtimer array */
25688 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
25689 index f10c0af..3ec1f95 100644
25690 --- a/arch/x86/power/cpu.c
25691 +++ b/arch/x86/power/cpu.c
25692 @@ -131,7 +131,7 @@ static void do_fpu_end(void)
25693 static void fix_processor_context(void)
25694 {
25695 int cpu = smp_processor_id();
25696 - struct tss_struct *t = &per_cpu(init_tss, cpu);
25697 + struct tss_struct *t = init_tss + cpu;
25698
25699 set_tss_desc(cpu, t); /*
25700 * This just modifies memory; should not be
25701 @@ -141,7 +141,9 @@ static void fix_processor_context(void)
25702 */
25703
25704 #ifdef CONFIG_X86_64
25705 + pax_open_kernel();
25706 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
25707 + pax_close_kernel();
25708
25709 syscall_init(); /* This sets MSR_*STAR and related */
25710 #endif
25711 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
25712 index 5d17950..2253fc9 100644
25713 --- a/arch/x86/vdso/Makefile
25714 +++ b/arch/x86/vdso/Makefile
25715 @@ -137,7 +137,7 @@ quiet_cmd_vdso = VDSO $@
25716 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
25717 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
25718
25719 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
25720 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
25721 GCOV_PROFILE := n
25722
25723 #
25724 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
25725 index 468d591..8e80a0a 100644
25726 --- a/arch/x86/vdso/vdso32-setup.c
25727 +++ b/arch/x86/vdso/vdso32-setup.c
25728 @@ -25,6 +25,7 @@
25729 #include <asm/tlbflush.h>
25730 #include <asm/vdso.h>
25731 #include <asm/proto.h>
25732 +#include <asm/mman.h>
25733
25734 enum {
25735 VDSO_DISABLED = 0,
25736 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
25737 void enable_sep_cpu(void)
25738 {
25739 int cpu = get_cpu();
25740 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
25741 + struct tss_struct *tss = init_tss + cpu;
25742
25743 if (!boot_cpu_has(X86_FEATURE_SEP)) {
25744 put_cpu();
25745 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
25746 gate_vma.vm_start = FIXADDR_USER_START;
25747 gate_vma.vm_end = FIXADDR_USER_END;
25748 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
25749 - gate_vma.vm_page_prot = __P101;
25750 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
25751 /*
25752 * Make sure the vDSO gets into every core dump.
25753 * Dumping its contents makes post-mortem fully interpretable later
25754 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
25755 if (compat)
25756 addr = VDSO_HIGH_BASE;
25757 else {
25758 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
25759 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
25760 if (IS_ERR_VALUE(addr)) {
25761 ret = addr;
25762 goto up_fail;
25763 }
25764 }
25765
25766 - current->mm->context.vdso = (void *)addr;
25767 + current->mm->context.vdso = addr;
25768
25769 if (compat_uses_vma || !compat) {
25770 /*
25771 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
25772 }
25773
25774 current_thread_info()->sysenter_return =
25775 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
25776 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
25777
25778 up_fail:
25779 if (ret)
25780 - current->mm->context.vdso = NULL;
25781 + current->mm->context.vdso = 0;
25782
25783 up_write(&mm->mmap_sem);
25784
25785 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
25786
25787 const char *arch_vma_name(struct vm_area_struct *vma)
25788 {
25789 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25790 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25791 return "[vdso]";
25792 +
25793 +#ifdef CONFIG_PAX_SEGMEXEC
25794 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
25795 + return "[vdso]";
25796 +#endif
25797 +
25798 return NULL;
25799 }
25800
25801 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25802 * Check to see if the corresponding task was created in compat vdso
25803 * mode.
25804 */
25805 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
25806 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
25807 return &gate_vma;
25808 return NULL;
25809 }
25810 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
25811 index 153407c..611cba9 100644
25812 --- a/arch/x86/vdso/vma.c
25813 +++ b/arch/x86/vdso/vma.c
25814 @@ -16,8 +16,6 @@
25815 #include <asm/vdso.h>
25816 #include <asm/page.h>
25817
25818 -unsigned int __read_mostly vdso_enabled = 1;
25819 -
25820 extern char vdso_start[], vdso_end[];
25821 extern unsigned short vdso_sync_cpuid;
25822
25823 @@ -96,7 +94,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
25824 * unaligned here as a result of stack start randomization.
25825 */
25826 addr = PAGE_ALIGN(addr);
25827 - addr = align_addr(addr, NULL, ALIGN_VDSO);
25828
25829 return addr;
25830 }
25831 @@ -106,40 +103,35 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
25832 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
25833 {
25834 struct mm_struct *mm = current->mm;
25835 - unsigned long addr;
25836 + unsigned long addr = 0;
25837 int ret;
25838
25839 - if (!vdso_enabled)
25840 - return 0;
25841 -
25842 down_write(&mm->mmap_sem);
25843 +
25844 +#ifdef CONFIG_PAX_RANDMMAP
25845 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25846 +#endif
25847 +
25848 addr = vdso_addr(mm->start_stack, vdso_size);
25849 + addr = align_addr(addr, NULL, ALIGN_VDSO);
25850 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
25851 if (IS_ERR_VALUE(addr)) {
25852 ret = addr;
25853 goto up_fail;
25854 }
25855
25856 - current->mm->context.vdso = (void *)addr;
25857 + mm->context.vdso = addr;
25858
25859 ret = install_special_mapping(mm, addr, vdso_size,
25860 VM_READ|VM_EXEC|
25861 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
25862 VM_ALWAYSDUMP,
25863 vdso_pages);
25864 - if (ret) {
25865 - current->mm->context.vdso = NULL;
25866 - goto up_fail;
25867 - }
25868 +
25869 + if (ret)
25870 + mm->context.vdso = 0;
25871
25872 up_fail:
25873 up_write(&mm->mmap_sem);
25874 return ret;
25875 }
25876 -
25877 -static __init int vdso_setup(char *s)
25878 -{
25879 - vdso_enabled = simple_strtoul(s, NULL, 0);
25880 - return 0;
25881 -}
25882 -__setup("vdso=", vdso_setup);
25883 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
25884 index 1f92865..c843b20 100644
25885 --- a/arch/x86/xen/enlighten.c
25886 +++ b/arch/x86/xen/enlighten.c
25887 @@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
25888
25889 struct shared_info xen_dummy_shared_info;
25890
25891 -void *xen_initial_gdt;
25892 -
25893 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
25894 __read_mostly int xen_have_vector_callback;
25895 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
25896 @@ -1029,7 +1027,7 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
25897 #endif
25898 };
25899
25900 -static void xen_reboot(int reason)
25901 +static __noreturn void xen_reboot(int reason)
25902 {
25903 struct sched_shutdown r = { .reason = reason };
25904
25905 @@ -1037,17 +1035,17 @@ static void xen_reboot(int reason)
25906 BUG();
25907 }
25908
25909 -static void xen_restart(char *msg)
25910 +static __noreturn void xen_restart(char *msg)
25911 {
25912 xen_reboot(SHUTDOWN_reboot);
25913 }
25914
25915 -static void xen_emergency_restart(void)
25916 +static __noreturn void xen_emergency_restart(void)
25917 {
25918 xen_reboot(SHUTDOWN_reboot);
25919 }
25920
25921 -static void xen_machine_halt(void)
25922 +static __noreturn void xen_machine_halt(void)
25923 {
25924 xen_reboot(SHUTDOWN_poweroff);
25925 }
25926 @@ -1153,7 +1151,17 @@ asmlinkage void __init xen_start_kernel(void)
25927 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
25928
25929 /* Work out if we support NX */
25930 - x86_configure_nx();
25931 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25932 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
25933 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
25934 + unsigned l, h;
25935 +
25936 + __supported_pte_mask |= _PAGE_NX;
25937 + rdmsr(MSR_EFER, l, h);
25938 + l |= EFER_NX;
25939 + wrmsr(MSR_EFER, l, h);
25940 + }
25941 +#endif
25942
25943 xen_setup_features();
25944
25945 @@ -1184,13 +1192,6 @@ asmlinkage void __init xen_start_kernel(void)
25946
25947 machine_ops = xen_machine_ops;
25948
25949 - /*
25950 - * The only reliable way to retain the initial address of the
25951 - * percpu gdt_page is to remember it here, so we can go and
25952 - * mark it RW later, when the initial percpu area is freed.
25953 - */
25954 - xen_initial_gdt = &per_cpu(gdt_page, 0);
25955 -
25956 xen_smp_init();
25957
25958 #ifdef CONFIG_ACPI_NUMA
25959 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
25960 index 87f6673..e2555a6 100644
25961 --- a/arch/x86/xen/mmu.c
25962 +++ b/arch/x86/xen/mmu.c
25963 @@ -1733,6 +1733,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
25964 convert_pfn_mfn(init_level4_pgt);
25965 convert_pfn_mfn(level3_ident_pgt);
25966 convert_pfn_mfn(level3_kernel_pgt);
25967 + convert_pfn_mfn(level3_vmalloc_start_pgt);
25968 + convert_pfn_mfn(level3_vmalloc_end_pgt);
25969 + convert_pfn_mfn(level3_vmemmap_pgt);
25970
25971 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
25972 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
25973 @@ -1751,7 +1754,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
25974 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
25975 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
25976 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
25977 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
25978 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
25979 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
25980 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
25981 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
25982 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
25983 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
25984
25985 @@ -1962,6 +1969,7 @@ static void __init xen_post_allocator_init(void)
25986 pv_mmu_ops.set_pud = xen_set_pud;
25987 #if PAGETABLE_LEVELS == 4
25988 pv_mmu_ops.set_pgd = xen_set_pgd;
25989 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
25990 #endif
25991
25992 /* This will work as long as patching hasn't happened yet
25993 @@ -2043,6 +2051,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
25994 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
25995 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
25996 .set_pgd = xen_set_pgd_hyper,
25997 + .set_pgd_batched = xen_set_pgd_hyper,
25998
25999 .alloc_pud = xen_alloc_pmd_init,
26000 .release_pud = xen_release_pmd_init,
26001 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
26002 index 041d4fe..7666b7e 100644
26003 --- a/arch/x86/xen/smp.c
26004 +++ b/arch/x86/xen/smp.c
26005 @@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
26006 {
26007 BUG_ON(smp_processor_id() != 0);
26008 native_smp_prepare_boot_cpu();
26009 -
26010 - /* We've switched to the "real" per-cpu gdt, so make sure the
26011 - old memory can be recycled */
26012 - make_lowmem_page_readwrite(xen_initial_gdt);
26013 -
26014 xen_filter_cpu_maps();
26015 xen_setup_vcpu_info_placement();
26016 }
26017 @@ -275,12 +270,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
26018 gdt = get_cpu_gdt_table(cpu);
26019
26020 ctxt->flags = VGCF_IN_KERNEL;
26021 - ctxt->user_regs.ds = __USER_DS;
26022 - ctxt->user_regs.es = __USER_DS;
26023 + ctxt->user_regs.ds = __KERNEL_DS;
26024 + ctxt->user_regs.es = __KERNEL_DS;
26025 ctxt->user_regs.ss = __KERNEL_DS;
26026 #ifdef CONFIG_X86_32
26027 ctxt->user_regs.fs = __KERNEL_PERCPU;
26028 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
26029 + savesegment(gs, ctxt->user_regs.gs);
26030 #else
26031 ctxt->gs_base_kernel = per_cpu_offset(cpu);
26032 #endif
26033 @@ -331,13 +326,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
26034 int rc;
26035
26036 per_cpu(current_task, cpu) = idle;
26037 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
26038 #ifdef CONFIG_X86_32
26039 irq_ctx_init(cpu);
26040 #else
26041 clear_tsk_thread_flag(idle, TIF_FORK);
26042 - per_cpu(kernel_stack, cpu) =
26043 - (unsigned long)task_stack_page(idle) -
26044 - KERNEL_STACK_OFFSET + THREAD_SIZE;
26045 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26046 #endif
26047 xen_setup_runstate_info(cpu);
26048 xen_setup_timer(cpu);
26049 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
26050 index b040b0e..8cc4fe0 100644
26051 --- a/arch/x86/xen/xen-asm_32.S
26052 +++ b/arch/x86/xen/xen-asm_32.S
26053 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
26054 ESP_OFFSET=4 # bytes pushed onto stack
26055
26056 /*
26057 - * Store vcpu_info pointer for easy access. Do it this way to
26058 - * avoid having to reload %fs
26059 + * Store vcpu_info pointer for easy access.
26060 */
26061 #ifdef CONFIG_SMP
26062 - GET_THREAD_INFO(%eax)
26063 - movl TI_cpu(%eax), %eax
26064 - movl __per_cpu_offset(,%eax,4), %eax
26065 - mov xen_vcpu(%eax), %eax
26066 + push %fs
26067 + mov $(__KERNEL_PERCPU), %eax
26068 + mov %eax, %fs
26069 + mov PER_CPU_VAR(xen_vcpu), %eax
26070 + pop %fs
26071 #else
26072 movl xen_vcpu, %eax
26073 #endif
26074 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
26075 index aaa7291..3f77960 100644
26076 --- a/arch/x86/xen/xen-head.S
26077 +++ b/arch/x86/xen/xen-head.S
26078 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
26079 #ifdef CONFIG_X86_32
26080 mov %esi,xen_start_info
26081 mov $init_thread_union+THREAD_SIZE,%esp
26082 +#ifdef CONFIG_SMP
26083 + movl $cpu_gdt_table,%edi
26084 + movl $__per_cpu_load,%eax
26085 + movw %ax,__KERNEL_PERCPU + 2(%edi)
26086 + rorl $16,%eax
26087 + movb %al,__KERNEL_PERCPU + 4(%edi)
26088 + movb %ah,__KERNEL_PERCPU + 7(%edi)
26089 + movl $__per_cpu_end - 1,%eax
26090 + subl $__per_cpu_start,%eax
26091 + movw %ax,__KERNEL_PERCPU + 0(%edi)
26092 +#endif
26093 #else
26094 mov %rsi,xen_start_info
26095 mov $init_thread_union+THREAD_SIZE,%rsp
26096 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
26097 index b095739..8c17bcd 100644
26098 --- a/arch/x86/xen/xen-ops.h
26099 +++ b/arch/x86/xen/xen-ops.h
26100 @@ -10,8 +10,6 @@
26101 extern const char xen_hypervisor_callback[];
26102 extern const char xen_failsafe_callback[];
26103
26104 -extern void *xen_initial_gdt;
26105 -
26106 struct trap_info;
26107 void xen_copy_trap_info(struct trap_info *traps);
26108
26109 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
26110 index 525bd3d..ef888b1 100644
26111 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
26112 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
26113 @@ -119,9 +119,9 @@
26114 ----------------------------------------------------------------------*/
26115
26116 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
26117 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
26118 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
26119 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
26120 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26121
26122 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
26123 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
26124 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
26125 index 2f33760..835e50a 100644
26126 --- a/arch/xtensa/variants/fsf/include/variant/core.h
26127 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
26128 @@ -11,6 +11,7 @@
26129 #ifndef _XTENSA_CORE_H
26130 #define _XTENSA_CORE_H
26131
26132 +#include <linux/const.h>
26133
26134 /****************************************************************************
26135 Parameters Useful for Any Code, USER or PRIVILEGED
26136 @@ -112,9 +113,9 @@
26137 ----------------------------------------------------------------------*/
26138
26139 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
26140 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
26141 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
26142 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
26143 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26144
26145 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
26146 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
26147 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
26148 index af00795..2bb8105 100644
26149 --- a/arch/xtensa/variants/s6000/include/variant/core.h
26150 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
26151 @@ -11,6 +11,7 @@
26152 #ifndef _XTENSA_CORE_CONFIGURATION_H
26153 #define _XTENSA_CORE_CONFIGURATION_H
26154
26155 +#include <linux/const.h>
26156
26157 /****************************************************************************
26158 Parameters Useful for Any Code, USER or PRIVILEGED
26159 @@ -118,9 +119,9 @@
26160 ----------------------------------------------------------------------*/
26161
26162 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
26163 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
26164 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
26165 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
26166 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26167
26168 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
26169 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
26170 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
26171 index 58916af..9cb880b 100644
26172 --- a/block/blk-iopoll.c
26173 +++ b/block/blk-iopoll.c
26174 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
26175 }
26176 EXPORT_SYMBOL(blk_iopoll_complete);
26177
26178 -static void blk_iopoll_softirq(struct softirq_action *h)
26179 +static void blk_iopoll_softirq(void)
26180 {
26181 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
26182 int rearm = 0, budget = blk_iopoll_budget;
26183 diff --git a/block/blk-map.c b/block/blk-map.c
26184 index 623e1cd..ca1e109 100644
26185 --- a/block/blk-map.c
26186 +++ b/block/blk-map.c
26187 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
26188 if (!len || !kbuf)
26189 return -EINVAL;
26190
26191 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
26192 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
26193 if (do_copy)
26194 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
26195 else
26196 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
26197 index 1366a89..e17f54b 100644
26198 --- a/block/blk-softirq.c
26199 +++ b/block/blk-softirq.c
26200 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
26201 * Softirq action handler - move entries to local list and loop over them
26202 * while passing them to the queue registered handler.
26203 */
26204 -static void blk_done_softirq(struct softirq_action *h)
26205 +static void blk_done_softirq(void)
26206 {
26207 struct list_head *cpu_list, local_list;
26208
26209 diff --git a/block/bsg.c b/block/bsg.c
26210 index 702f131..37808bf 100644
26211 --- a/block/bsg.c
26212 +++ b/block/bsg.c
26213 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
26214 struct sg_io_v4 *hdr, struct bsg_device *bd,
26215 fmode_t has_write_perm)
26216 {
26217 + unsigned char tmpcmd[sizeof(rq->__cmd)];
26218 + unsigned char *cmdptr;
26219 +
26220 if (hdr->request_len > BLK_MAX_CDB) {
26221 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
26222 if (!rq->cmd)
26223 return -ENOMEM;
26224 - }
26225 + cmdptr = rq->cmd;
26226 + } else
26227 + cmdptr = tmpcmd;
26228
26229 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
26230 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
26231 hdr->request_len))
26232 return -EFAULT;
26233
26234 + if (cmdptr != rq->cmd)
26235 + memcpy(rq->cmd, cmdptr, hdr->request_len);
26236 +
26237 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
26238 if (blk_verify_command(rq->cmd, has_write_perm))
26239 return -EPERM;
26240 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
26241 index 7b72502..646105c 100644
26242 --- a/block/compat_ioctl.c
26243 +++ b/block/compat_ioctl.c
26244 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
26245 err |= __get_user(f->spec1, &uf->spec1);
26246 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
26247 err |= __get_user(name, &uf->name);
26248 - f->name = compat_ptr(name);
26249 + f->name = (void __force_kernel *)compat_ptr(name);
26250 if (err) {
26251 err = -EFAULT;
26252 goto out;
26253 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
26254 index 688be8a..8a37d98 100644
26255 --- a/block/scsi_ioctl.c
26256 +++ b/block/scsi_ioctl.c
26257 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
26258 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
26259 struct sg_io_hdr *hdr, fmode_t mode)
26260 {
26261 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
26262 + unsigned char tmpcmd[sizeof(rq->__cmd)];
26263 + unsigned char *cmdptr;
26264 +
26265 + if (rq->cmd != rq->__cmd)
26266 + cmdptr = rq->cmd;
26267 + else
26268 + cmdptr = tmpcmd;
26269 +
26270 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
26271 return -EFAULT;
26272 +
26273 + if (cmdptr != rq->cmd)
26274 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
26275 +
26276 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
26277 return -EPERM;
26278
26279 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
26280 int err;
26281 unsigned int in_len, out_len, bytes, opcode, cmdlen;
26282 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
26283 + unsigned char tmpcmd[sizeof(rq->__cmd)];
26284 + unsigned char *cmdptr;
26285
26286 if (!sic)
26287 return -EINVAL;
26288 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
26289 */
26290 err = -EFAULT;
26291 rq->cmd_len = cmdlen;
26292 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
26293 +
26294 + if (rq->cmd != rq->__cmd)
26295 + cmdptr = rq->cmd;
26296 + else
26297 + cmdptr = tmpcmd;
26298 +
26299 + if (copy_from_user(cmdptr, sic->data, cmdlen))
26300 goto error;
26301
26302 + if (rq->cmd != cmdptr)
26303 + memcpy(rq->cmd, cmdptr, cmdlen);
26304 +
26305 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
26306 goto error;
26307
26308 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
26309 index 671d4d6..5f24030 100644
26310 --- a/crypto/cryptd.c
26311 +++ b/crypto/cryptd.c
26312 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
26313
26314 struct cryptd_blkcipher_request_ctx {
26315 crypto_completion_t complete;
26316 -};
26317 +} __no_const;
26318
26319 struct cryptd_hash_ctx {
26320 struct crypto_shash *child;
26321 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
26322
26323 struct cryptd_aead_request_ctx {
26324 crypto_completion_t complete;
26325 -};
26326 +} __no_const;
26327
26328 static void cryptd_queue_worker(struct work_struct *work);
26329
26330 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
26331 index 5d41894..22021e4 100644
26332 --- a/drivers/acpi/apei/cper.c
26333 +++ b/drivers/acpi/apei/cper.c
26334 @@ -38,12 +38,12 @@
26335 */
26336 u64 cper_next_record_id(void)
26337 {
26338 - static atomic64_t seq;
26339 + static atomic64_unchecked_t seq;
26340
26341 - if (!atomic64_read(&seq))
26342 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
26343 + if (!atomic64_read_unchecked(&seq))
26344 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
26345
26346 - return atomic64_inc_return(&seq);
26347 + return atomic64_inc_return_unchecked(&seq);
26348 }
26349 EXPORT_SYMBOL_GPL(cper_next_record_id);
26350
26351 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
26352 index 6c47ae9..abfdd63 100644
26353 --- a/drivers/acpi/ec_sys.c
26354 +++ b/drivers/acpi/ec_sys.c
26355 @@ -12,6 +12,7 @@
26356 #include <linux/acpi.h>
26357 #include <linux/debugfs.h>
26358 #include <linux/module.h>
26359 +#include <linux/uaccess.h>
26360 #include "internal.h"
26361
26362 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
26363 @@ -40,7 +41,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
26364 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
26365 */
26366 unsigned int size = EC_SPACE_SIZE;
26367 - u8 *data = (u8 *) buf;
26368 + u8 data;
26369 loff_t init_off = *off;
26370 int err = 0;
26371
26372 @@ -53,9 +54,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
26373 size = count;
26374
26375 while (size) {
26376 - err = ec_read(*off, &data[*off - init_off]);
26377 + err = ec_read(*off, &data);
26378 if (err)
26379 return err;
26380 + if (put_user(data, &buf[*off - init_off]))
26381 + return -EFAULT;
26382 *off += 1;
26383 size--;
26384 }
26385 @@ -71,7 +74,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
26386
26387 unsigned int size = count;
26388 loff_t init_off = *off;
26389 - u8 *data = (u8 *) buf;
26390 int err = 0;
26391
26392 if (*off >= EC_SPACE_SIZE)
26393 @@ -82,7 +84,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
26394 }
26395
26396 while (size) {
26397 - u8 byte_write = data[*off - init_off];
26398 + u8 byte_write;
26399 + if (get_user(byte_write, &buf[*off - init_off]))
26400 + return -EFAULT;
26401 err = ec_write(*off, byte_write);
26402 if (err)
26403 return err;
26404 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
26405 index 251c7b62..000462d 100644
26406 --- a/drivers/acpi/proc.c
26407 +++ b/drivers/acpi/proc.c
26408 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
26409 size_t count, loff_t * ppos)
26410 {
26411 struct list_head *node, *next;
26412 - char strbuf[5];
26413 - char str[5] = "";
26414 - unsigned int len = count;
26415 + char strbuf[5] = {0};
26416
26417 - if (len > 4)
26418 - len = 4;
26419 - if (len < 0)
26420 + if (count > 4)
26421 + count = 4;
26422 + if (copy_from_user(strbuf, buffer, count))
26423 return -EFAULT;
26424 -
26425 - if (copy_from_user(strbuf, buffer, len))
26426 - return -EFAULT;
26427 - strbuf[len] = '\0';
26428 - sscanf(strbuf, "%s", str);
26429 + strbuf[count] = '\0';
26430
26431 mutex_lock(&acpi_device_lock);
26432 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
26433 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
26434 if (!dev->wakeup.flags.valid)
26435 continue;
26436
26437 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
26438 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
26439 if (device_can_wakeup(&dev->dev)) {
26440 bool enable = !device_may_wakeup(&dev->dev);
26441 device_set_wakeup_enable(&dev->dev, enable);
26442 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
26443 index 9d7bc9f..a6fc091 100644
26444 --- a/drivers/acpi/processor_driver.c
26445 +++ b/drivers/acpi/processor_driver.c
26446 @@ -473,7 +473,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
26447 return 0;
26448 #endif
26449
26450 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
26451 + BUG_ON(pr->id >= nr_cpu_ids);
26452
26453 /*
26454 * Buggy BIOS check
26455 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
26456 index c04ad68..0b99473 100644
26457 --- a/drivers/ata/libata-core.c
26458 +++ b/drivers/ata/libata-core.c
26459 @@ -4733,7 +4733,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
26460 struct ata_port *ap;
26461 unsigned int tag;
26462
26463 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
26464 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
26465 ap = qc->ap;
26466
26467 qc->flags = 0;
26468 @@ -4749,7 +4749,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
26469 struct ata_port *ap;
26470 struct ata_link *link;
26471
26472 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
26473 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
26474 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
26475 ap = qc->ap;
26476 link = qc->dev->link;
26477 @@ -5754,6 +5754,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
26478 return;
26479
26480 spin_lock(&lock);
26481 + pax_open_kernel();
26482
26483 for (cur = ops->inherits; cur; cur = cur->inherits) {
26484 void **inherit = (void **)cur;
26485 @@ -5767,8 +5768,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
26486 if (IS_ERR(*pp))
26487 *pp = NULL;
26488
26489 - ops->inherits = NULL;
26490 + *(struct ata_port_operations **)&ops->inherits = NULL;
26491
26492 + pax_close_kernel();
26493 spin_unlock(&lock);
26494 }
26495
26496 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
26497 index e8574bb..f9f6a72 100644
26498 --- a/drivers/ata/pata_arasan_cf.c
26499 +++ b/drivers/ata/pata_arasan_cf.c
26500 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
26501 /* Handle platform specific quirks */
26502 if (pdata->quirk) {
26503 if (pdata->quirk & CF_BROKEN_PIO) {
26504 - ap->ops->set_piomode = NULL;
26505 + pax_open_kernel();
26506 + *(void **)&ap->ops->set_piomode = NULL;
26507 + pax_close_kernel();
26508 ap->pio_mask = 0;
26509 }
26510 if (pdata->quirk & CF_BROKEN_MWDMA)
26511 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
26512 index f9b983a..887b9d8 100644
26513 --- a/drivers/atm/adummy.c
26514 +++ b/drivers/atm/adummy.c
26515 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
26516 vcc->pop(vcc, skb);
26517 else
26518 dev_kfree_skb_any(skb);
26519 - atomic_inc(&vcc->stats->tx);
26520 + atomic_inc_unchecked(&vcc->stats->tx);
26521
26522 return 0;
26523 }
26524 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
26525 index f8f41e0..1f987dd 100644
26526 --- a/drivers/atm/ambassador.c
26527 +++ b/drivers/atm/ambassador.c
26528 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
26529 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
26530
26531 // VC layer stats
26532 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26533 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26534
26535 // free the descriptor
26536 kfree (tx_descr);
26537 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
26538 dump_skb ("<<<", vc, skb);
26539
26540 // VC layer stats
26541 - atomic_inc(&atm_vcc->stats->rx);
26542 + atomic_inc_unchecked(&atm_vcc->stats->rx);
26543 __net_timestamp(skb);
26544 // end of our responsibility
26545 atm_vcc->push (atm_vcc, skb);
26546 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
26547 } else {
26548 PRINTK (KERN_INFO, "dropped over-size frame");
26549 // should we count this?
26550 - atomic_inc(&atm_vcc->stats->rx_drop);
26551 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26552 }
26553
26554 } else {
26555 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
26556 }
26557
26558 if (check_area (skb->data, skb->len)) {
26559 - atomic_inc(&atm_vcc->stats->tx_err);
26560 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
26561 return -ENOMEM; // ?
26562 }
26563
26564 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
26565 index b22d71c..d6e1049 100644
26566 --- a/drivers/atm/atmtcp.c
26567 +++ b/drivers/atm/atmtcp.c
26568 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
26569 if (vcc->pop) vcc->pop(vcc,skb);
26570 else dev_kfree_skb(skb);
26571 if (dev_data) return 0;
26572 - atomic_inc(&vcc->stats->tx_err);
26573 + atomic_inc_unchecked(&vcc->stats->tx_err);
26574 return -ENOLINK;
26575 }
26576 size = skb->len+sizeof(struct atmtcp_hdr);
26577 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
26578 if (!new_skb) {
26579 if (vcc->pop) vcc->pop(vcc,skb);
26580 else dev_kfree_skb(skb);
26581 - atomic_inc(&vcc->stats->tx_err);
26582 + atomic_inc_unchecked(&vcc->stats->tx_err);
26583 return -ENOBUFS;
26584 }
26585 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
26586 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
26587 if (vcc->pop) vcc->pop(vcc,skb);
26588 else dev_kfree_skb(skb);
26589 out_vcc->push(out_vcc,new_skb);
26590 - atomic_inc(&vcc->stats->tx);
26591 - atomic_inc(&out_vcc->stats->rx);
26592 + atomic_inc_unchecked(&vcc->stats->tx);
26593 + atomic_inc_unchecked(&out_vcc->stats->rx);
26594 return 0;
26595 }
26596
26597 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
26598 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
26599 read_unlock(&vcc_sklist_lock);
26600 if (!out_vcc) {
26601 - atomic_inc(&vcc->stats->tx_err);
26602 + atomic_inc_unchecked(&vcc->stats->tx_err);
26603 goto done;
26604 }
26605 skb_pull(skb,sizeof(struct atmtcp_hdr));
26606 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
26607 __net_timestamp(new_skb);
26608 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
26609 out_vcc->push(out_vcc,new_skb);
26610 - atomic_inc(&vcc->stats->tx);
26611 - atomic_inc(&out_vcc->stats->rx);
26612 + atomic_inc_unchecked(&vcc->stats->tx);
26613 + atomic_inc_unchecked(&out_vcc->stats->rx);
26614 done:
26615 if (vcc->pop) vcc->pop(vcc,skb);
26616 else dev_kfree_skb(skb);
26617 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
26618 index 956e9ac..133516d 100644
26619 --- a/drivers/atm/eni.c
26620 +++ b/drivers/atm/eni.c
26621 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
26622 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
26623 vcc->dev->number);
26624 length = 0;
26625 - atomic_inc(&vcc->stats->rx_err);
26626 + atomic_inc_unchecked(&vcc->stats->rx_err);
26627 }
26628 else {
26629 length = ATM_CELL_SIZE-1; /* no HEC */
26630 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26631 size);
26632 }
26633 eff = length = 0;
26634 - atomic_inc(&vcc->stats->rx_err);
26635 + atomic_inc_unchecked(&vcc->stats->rx_err);
26636 }
26637 else {
26638 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
26639 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26640 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
26641 vcc->dev->number,vcc->vci,length,size << 2,descr);
26642 length = eff = 0;
26643 - atomic_inc(&vcc->stats->rx_err);
26644 + atomic_inc_unchecked(&vcc->stats->rx_err);
26645 }
26646 }
26647 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
26648 @@ -771,7 +771,7 @@ rx_dequeued++;
26649 vcc->push(vcc,skb);
26650 pushed++;
26651 }
26652 - atomic_inc(&vcc->stats->rx);
26653 + atomic_inc_unchecked(&vcc->stats->rx);
26654 }
26655 wake_up(&eni_dev->rx_wait);
26656 }
26657 @@ -1229,7 +1229,7 @@ static void dequeue_tx(struct atm_dev *dev)
26658 PCI_DMA_TODEVICE);
26659 if (vcc->pop) vcc->pop(vcc,skb);
26660 else dev_kfree_skb_irq(skb);
26661 - atomic_inc(&vcc->stats->tx);
26662 + atomic_inc_unchecked(&vcc->stats->tx);
26663 wake_up(&eni_dev->tx_wait);
26664 dma_complete++;
26665 }
26666 @@ -1569,7 +1569,7 @@ tx_complete++;
26667 /*--------------------------------- entries ---------------------------------*/
26668
26669
26670 -static const char *media_name[] __devinitdata = {
26671 +static const char *media_name[] __devinitconst = {
26672 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
26673 "UTP", "05?", "06?", "07?", /* 4- 7 */
26674 "TAXI","09?", "10?", "11?", /* 8-11 */
26675 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
26676 index 5072f8a..fa52520d 100644
26677 --- a/drivers/atm/firestream.c
26678 +++ b/drivers/atm/firestream.c
26679 @@ -750,7 +750,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
26680 }
26681 }
26682
26683 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26684 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26685
26686 fs_dprintk (FS_DEBUG_TXMEM, "i");
26687 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
26688 @@ -817,7 +817,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
26689 #endif
26690 skb_put (skb, qe->p1 & 0xffff);
26691 ATM_SKB(skb)->vcc = atm_vcc;
26692 - atomic_inc(&atm_vcc->stats->rx);
26693 + atomic_inc_unchecked(&atm_vcc->stats->rx);
26694 __net_timestamp(skb);
26695 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
26696 atm_vcc->push (atm_vcc, skb);
26697 @@ -838,12 +838,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
26698 kfree (pe);
26699 }
26700 if (atm_vcc)
26701 - atomic_inc(&atm_vcc->stats->rx_drop);
26702 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26703 break;
26704 case 0x1f: /* Reassembly abort: no buffers. */
26705 /* Silently increment error counter. */
26706 if (atm_vcc)
26707 - atomic_inc(&atm_vcc->stats->rx_drop);
26708 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26709 break;
26710 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
26711 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
26712 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
26713 index 361f5ae..7fc552d 100644
26714 --- a/drivers/atm/fore200e.c
26715 +++ b/drivers/atm/fore200e.c
26716 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
26717 #endif
26718 /* check error condition */
26719 if (*entry->status & STATUS_ERROR)
26720 - atomic_inc(&vcc->stats->tx_err);
26721 + atomic_inc_unchecked(&vcc->stats->tx_err);
26722 else
26723 - atomic_inc(&vcc->stats->tx);
26724 + atomic_inc_unchecked(&vcc->stats->tx);
26725 }
26726 }
26727
26728 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
26729 if (skb == NULL) {
26730 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
26731
26732 - atomic_inc(&vcc->stats->rx_drop);
26733 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26734 return -ENOMEM;
26735 }
26736
26737 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
26738
26739 dev_kfree_skb_any(skb);
26740
26741 - atomic_inc(&vcc->stats->rx_drop);
26742 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26743 return -ENOMEM;
26744 }
26745
26746 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
26747
26748 vcc->push(vcc, skb);
26749 - atomic_inc(&vcc->stats->rx);
26750 + atomic_inc_unchecked(&vcc->stats->rx);
26751
26752 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
26753
26754 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
26755 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
26756 fore200e->atm_dev->number,
26757 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
26758 - atomic_inc(&vcc->stats->rx_err);
26759 + atomic_inc_unchecked(&vcc->stats->rx_err);
26760 }
26761 }
26762
26763 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
26764 goto retry_here;
26765 }
26766
26767 - atomic_inc(&vcc->stats->tx_err);
26768 + atomic_inc_unchecked(&vcc->stats->tx_err);
26769
26770 fore200e->tx_sat++;
26771 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
26772 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
26773 index 9a51df4..f3bb5f8 100644
26774 --- a/drivers/atm/he.c
26775 +++ b/drivers/atm/he.c
26776 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
26777
26778 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
26779 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
26780 - atomic_inc(&vcc->stats->rx_drop);
26781 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26782 goto return_host_buffers;
26783 }
26784
26785 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
26786 RBRQ_LEN_ERR(he_dev->rbrq_head)
26787 ? "LEN_ERR" : "",
26788 vcc->vpi, vcc->vci);
26789 - atomic_inc(&vcc->stats->rx_err);
26790 + atomic_inc_unchecked(&vcc->stats->rx_err);
26791 goto return_host_buffers;
26792 }
26793
26794 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
26795 vcc->push(vcc, skb);
26796 spin_lock(&he_dev->global_lock);
26797
26798 - atomic_inc(&vcc->stats->rx);
26799 + atomic_inc_unchecked(&vcc->stats->rx);
26800
26801 return_host_buffers:
26802 ++pdus_assembled;
26803 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
26804 tpd->vcc->pop(tpd->vcc, tpd->skb);
26805 else
26806 dev_kfree_skb_any(tpd->skb);
26807 - atomic_inc(&tpd->vcc->stats->tx_err);
26808 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
26809 }
26810 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
26811 return;
26812 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
26813 vcc->pop(vcc, skb);
26814 else
26815 dev_kfree_skb_any(skb);
26816 - atomic_inc(&vcc->stats->tx_err);
26817 + atomic_inc_unchecked(&vcc->stats->tx_err);
26818 return -EINVAL;
26819 }
26820
26821 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
26822 vcc->pop(vcc, skb);
26823 else
26824 dev_kfree_skb_any(skb);
26825 - atomic_inc(&vcc->stats->tx_err);
26826 + atomic_inc_unchecked(&vcc->stats->tx_err);
26827 return -EINVAL;
26828 }
26829 #endif
26830 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
26831 vcc->pop(vcc, skb);
26832 else
26833 dev_kfree_skb_any(skb);
26834 - atomic_inc(&vcc->stats->tx_err);
26835 + atomic_inc_unchecked(&vcc->stats->tx_err);
26836 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26837 return -ENOMEM;
26838 }
26839 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
26840 vcc->pop(vcc, skb);
26841 else
26842 dev_kfree_skb_any(skb);
26843 - atomic_inc(&vcc->stats->tx_err);
26844 + atomic_inc_unchecked(&vcc->stats->tx_err);
26845 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26846 return -ENOMEM;
26847 }
26848 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
26849 __enqueue_tpd(he_dev, tpd, cid);
26850 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26851
26852 - atomic_inc(&vcc->stats->tx);
26853 + atomic_inc_unchecked(&vcc->stats->tx);
26854
26855 return 0;
26856 }
26857 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
26858 index b812103..e391a49 100644
26859 --- a/drivers/atm/horizon.c
26860 +++ b/drivers/atm/horizon.c
26861 @@ -1035,7 +1035,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
26862 {
26863 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
26864 // VC layer stats
26865 - atomic_inc(&vcc->stats->rx);
26866 + atomic_inc_unchecked(&vcc->stats->rx);
26867 __net_timestamp(skb);
26868 // end of our responsibility
26869 vcc->push (vcc, skb);
26870 @@ -1187,7 +1187,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
26871 dev->tx_iovec = NULL;
26872
26873 // VC layer stats
26874 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26875 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26876
26877 // free the skb
26878 hrz_kfree_skb (skb);
26879 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
26880 index 1c05212..c28e200 100644
26881 --- a/drivers/atm/idt77252.c
26882 +++ b/drivers/atm/idt77252.c
26883 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
26884 else
26885 dev_kfree_skb(skb);
26886
26887 - atomic_inc(&vcc->stats->tx);
26888 + atomic_inc_unchecked(&vcc->stats->tx);
26889 }
26890
26891 atomic_dec(&scq->used);
26892 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
26893 if ((sb = dev_alloc_skb(64)) == NULL) {
26894 printk("%s: Can't allocate buffers for aal0.\n",
26895 card->name);
26896 - atomic_add(i, &vcc->stats->rx_drop);
26897 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
26898 break;
26899 }
26900 if (!atm_charge(vcc, sb->truesize)) {
26901 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
26902 card->name);
26903 - atomic_add(i - 1, &vcc->stats->rx_drop);
26904 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
26905 dev_kfree_skb(sb);
26906 break;
26907 }
26908 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
26909 ATM_SKB(sb)->vcc = vcc;
26910 __net_timestamp(sb);
26911 vcc->push(vcc, sb);
26912 - atomic_inc(&vcc->stats->rx);
26913 + atomic_inc_unchecked(&vcc->stats->rx);
26914
26915 cell += ATM_CELL_PAYLOAD;
26916 }
26917 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
26918 "(CDC: %08x)\n",
26919 card->name, len, rpp->len, readl(SAR_REG_CDC));
26920 recycle_rx_pool_skb(card, rpp);
26921 - atomic_inc(&vcc->stats->rx_err);
26922 + atomic_inc_unchecked(&vcc->stats->rx_err);
26923 return;
26924 }
26925 if (stat & SAR_RSQE_CRC) {
26926 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
26927 recycle_rx_pool_skb(card, rpp);
26928 - atomic_inc(&vcc->stats->rx_err);
26929 + atomic_inc_unchecked(&vcc->stats->rx_err);
26930 return;
26931 }
26932 if (skb_queue_len(&rpp->queue) > 1) {
26933 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
26934 RXPRINTK("%s: Can't alloc RX skb.\n",
26935 card->name);
26936 recycle_rx_pool_skb(card, rpp);
26937 - atomic_inc(&vcc->stats->rx_err);
26938 + atomic_inc_unchecked(&vcc->stats->rx_err);
26939 return;
26940 }
26941 if (!atm_charge(vcc, skb->truesize)) {
26942 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
26943 __net_timestamp(skb);
26944
26945 vcc->push(vcc, skb);
26946 - atomic_inc(&vcc->stats->rx);
26947 + atomic_inc_unchecked(&vcc->stats->rx);
26948
26949 return;
26950 }
26951 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
26952 __net_timestamp(skb);
26953
26954 vcc->push(vcc, skb);
26955 - atomic_inc(&vcc->stats->rx);
26956 + atomic_inc_unchecked(&vcc->stats->rx);
26957
26958 if (skb->truesize > SAR_FB_SIZE_3)
26959 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
26960 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
26961 if (vcc->qos.aal != ATM_AAL0) {
26962 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
26963 card->name, vpi, vci);
26964 - atomic_inc(&vcc->stats->rx_drop);
26965 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26966 goto drop;
26967 }
26968
26969 if ((sb = dev_alloc_skb(64)) == NULL) {
26970 printk("%s: Can't allocate buffers for AAL0.\n",
26971 card->name);
26972 - atomic_inc(&vcc->stats->rx_err);
26973 + atomic_inc_unchecked(&vcc->stats->rx_err);
26974 goto drop;
26975 }
26976
26977 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
26978 ATM_SKB(sb)->vcc = vcc;
26979 __net_timestamp(sb);
26980 vcc->push(vcc, sb);
26981 - atomic_inc(&vcc->stats->rx);
26982 + atomic_inc_unchecked(&vcc->stats->rx);
26983
26984 drop:
26985 skb_pull(queue, 64);
26986 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
26987
26988 if (vc == NULL) {
26989 printk("%s: NULL connection in send().\n", card->name);
26990 - atomic_inc(&vcc->stats->tx_err);
26991 + atomic_inc_unchecked(&vcc->stats->tx_err);
26992 dev_kfree_skb(skb);
26993 return -EINVAL;
26994 }
26995 if (!test_bit(VCF_TX, &vc->flags)) {
26996 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
26997 - atomic_inc(&vcc->stats->tx_err);
26998 + atomic_inc_unchecked(&vcc->stats->tx_err);
26999 dev_kfree_skb(skb);
27000 return -EINVAL;
27001 }
27002 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27003 break;
27004 default:
27005 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
27006 - atomic_inc(&vcc->stats->tx_err);
27007 + atomic_inc_unchecked(&vcc->stats->tx_err);
27008 dev_kfree_skb(skb);
27009 return -EINVAL;
27010 }
27011
27012 if (skb_shinfo(skb)->nr_frags != 0) {
27013 printk("%s: No scatter-gather yet.\n", card->name);
27014 - atomic_inc(&vcc->stats->tx_err);
27015 + atomic_inc_unchecked(&vcc->stats->tx_err);
27016 dev_kfree_skb(skb);
27017 return -EINVAL;
27018 }
27019 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27020
27021 err = queue_skb(card, vc, skb, oam);
27022 if (err) {
27023 - atomic_inc(&vcc->stats->tx_err);
27024 + atomic_inc_unchecked(&vcc->stats->tx_err);
27025 dev_kfree_skb(skb);
27026 return err;
27027 }
27028 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
27029 skb = dev_alloc_skb(64);
27030 if (!skb) {
27031 printk("%s: Out of memory in send_oam().\n", card->name);
27032 - atomic_inc(&vcc->stats->tx_err);
27033 + atomic_inc_unchecked(&vcc->stats->tx_err);
27034 return -ENOMEM;
27035 }
27036 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
27037 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
27038 index 3d0c2b0..45441fa 100644
27039 --- a/drivers/atm/iphase.c
27040 +++ b/drivers/atm/iphase.c
27041 @@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
27042 status = (u_short) (buf_desc_ptr->desc_mode);
27043 if (status & (RX_CER | RX_PTE | RX_OFL))
27044 {
27045 - atomic_inc(&vcc->stats->rx_err);
27046 + atomic_inc_unchecked(&vcc->stats->rx_err);
27047 IF_ERR(printk("IA: bad packet, dropping it");)
27048 if (status & RX_CER) {
27049 IF_ERR(printk(" cause: packet CRC error\n");)
27050 @@ -1169,7 +1169,7 @@ static int rx_pkt(struct atm_dev *dev)
27051 len = dma_addr - buf_addr;
27052 if (len > iadev->rx_buf_sz) {
27053 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
27054 - atomic_inc(&vcc->stats->rx_err);
27055 + atomic_inc_unchecked(&vcc->stats->rx_err);
27056 goto out_free_desc;
27057 }
27058
27059 @@ -1319,7 +1319,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27060 ia_vcc = INPH_IA_VCC(vcc);
27061 if (ia_vcc == NULL)
27062 {
27063 - atomic_inc(&vcc->stats->rx_err);
27064 + atomic_inc_unchecked(&vcc->stats->rx_err);
27065 dev_kfree_skb_any(skb);
27066 atm_return(vcc, atm_guess_pdu2truesize(len));
27067 goto INCR_DLE;
27068 @@ -1331,7 +1331,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27069 if ((length > iadev->rx_buf_sz) || (length >
27070 (skb->len - sizeof(struct cpcs_trailer))))
27071 {
27072 - atomic_inc(&vcc->stats->rx_err);
27073 + atomic_inc_unchecked(&vcc->stats->rx_err);
27074 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
27075 length, skb->len);)
27076 dev_kfree_skb_any(skb);
27077 @@ -1347,7 +1347,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27078
27079 IF_RX(printk("rx_dle_intr: skb push");)
27080 vcc->push(vcc,skb);
27081 - atomic_inc(&vcc->stats->rx);
27082 + atomic_inc_unchecked(&vcc->stats->rx);
27083 iadev->rx_pkt_cnt++;
27084 }
27085 INCR_DLE:
27086 @@ -2827,15 +2827,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
27087 {
27088 struct k_sonet_stats *stats;
27089 stats = &PRIV(_ia_dev[board])->sonet_stats;
27090 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
27091 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
27092 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
27093 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
27094 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
27095 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
27096 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
27097 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
27098 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
27099 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
27100 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
27101 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
27102 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
27103 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
27104 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
27105 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
27106 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
27107 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
27108 }
27109 ia_cmds.status = 0;
27110 break;
27111 @@ -2940,7 +2940,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
27112 if ((desc == 0) || (desc > iadev->num_tx_desc))
27113 {
27114 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
27115 - atomic_inc(&vcc->stats->tx);
27116 + atomic_inc_unchecked(&vcc->stats->tx);
27117 if (vcc->pop)
27118 vcc->pop(vcc, skb);
27119 else
27120 @@ -3045,14 +3045,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
27121 ATM_DESC(skb) = vcc->vci;
27122 skb_queue_tail(&iadev->tx_dma_q, skb);
27123
27124 - atomic_inc(&vcc->stats->tx);
27125 + atomic_inc_unchecked(&vcc->stats->tx);
27126 iadev->tx_pkt_cnt++;
27127 /* Increment transaction counter */
27128 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
27129
27130 #if 0
27131 /* add flow control logic */
27132 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
27133 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
27134 if (iavcc->vc_desc_cnt > 10) {
27135 vcc->tx_quota = vcc->tx_quota * 3 / 4;
27136 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
27137 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
27138 index f556969..0da15eb 100644
27139 --- a/drivers/atm/lanai.c
27140 +++ b/drivers/atm/lanai.c
27141 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
27142 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
27143 lanai_endtx(lanai, lvcc);
27144 lanai_free_skb(lvcc->tx.atmvcc, skb);
27145 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
27146 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
27147 }
27148
27149 /* Try to fill the buffer - don't call unless there is backlog */
27150 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
27151 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
27152 __net_timestamp(skb);
27153 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
27154 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
27155 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
27156 out:
27157 lvcc->rx.buf.ptr = end;
27158 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
27159 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
27160 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
27161 "vcc %d\n", lanai->number, (unsigned int) s, vci);
27162 lanai->stats.service_rxnotaal5++;
27163 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27164 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27165 return 0;
27166 }
27167 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
27168 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
27169 int bytes;
27170 read_unlock(&vcc_sklist_lock);
27171 DPRINTK("got trashed rx pdu on vci %d\n", vci);
27172 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27173 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27174 lvcc->stats.x.aal5.service_trash++;
27175 bytes = (SERVICE_GET_END(s) * 16) -
27176 (((unsigned long) lvcc->rx.buf.ptr) -
27177 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
27178 }
27179 if (s & SERVICE_STREAM) {
27180 read_unlock(&vcc_sklist_lock);
27181 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27182 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27183 lvcc->stats.x.aal5.service_stream++;
27184 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
27185 "PDU on VCI %d!\n", lanai->number, vci);
27186 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
27187 return 0;
27188 }
27189 DPRINTK("got rx crc error on vci %d\n", vci);
27190 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27191 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27192 lvcc->stats.x.aal5.service_rxcrc++;
27193 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
27194 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
27195 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
27196 index 1c70c45..300718d 100644
27197 --- a/drivers/atm/nicstar.c
27198 +++ b/drivers/atm/nicstar.c
27199 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
27200 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
27201 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
27202 card->index);
27203 - atomic_inc(&vcc->stats->tx_err);
27204 + atomic_inc_unchecked(&vcc->stats->tx_err);
27205 dev_kfree_skb_any(skb);
27206 return -EINVAL;
27207 }
27208 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
27209 if (!vc->tx) {
27210 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
27211 card->index);
27212 - atomic_inc(&vcc->stats->tx_err);
27213 + atomic_inc_unchecked(&vcc->stats->tx_err);
27214 dev_kfree_skb_any(skb);
27215 return -EINVAL;
27216 }
27217 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
27218 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
27219 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
27220 card->index);
27221 - atomic_inc(&vcc->stats->tx_err);
27222 + atomic_inc_unchecked(&vcc->stats->tx_err);
27223 dev_kfree_skb_any(skb);
27224 return -EINVAL;
27225 }
27226
27227 if (skb_shinfo(skb)->nr_frags != 0) {
27228 printk("nicstar%d: No scatter-gather yet.\n", card->index);
27229 - atomic_inc(&vcc->stats->tx_err);
27230 + atomic_inc_unchecked(&vcc->stats->tx_err);
27231 dev_kfree_skb_any(skb);
27232 return -EINVAL;
27233 }
27234 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
27235 }
27236
27237 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
27238 - atomic_inc(&vcc->stats->tx_err);
27239 + atomic_inc_unchecked(&vcc->stats->tx_err);
27240 dev_kfree_skb_any(skb);
27241 return -EIO;
27242 }
27243 - atomic_inc(&vcc->stats->tx);
27244 + atomic_inc_unchecked(&vcc->stats->tx);
27245
27246 return 0;
27247 }
27248 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27249 printk
27250 ("nicstar%d: Can't allocate buffers for aal0.\n",
27251 card->index);
27252 - atomic_add(i, &vcc->stats->rx_drop);
27253 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
27254 break;
27255 }
27256 if (!atm_charge(vcc, sb->truesize)) {
27257 RXPRINTK
27258 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
27259 card->index);
27260 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
27261 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
27262 dev_kfree_skb_any(sb);
27263 break;
27264 }
27265 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27266 ATM_SKB(sb)->vcc = vcc;
27267 __net_timestamp(sb);
27268 vcc->push(vcc, sb);
27269 - atomic_inc(&vcc->stats->rx);
27270 + atomic_inc_unchecked(&vcc->stats->rx);
27271 cell += ATM_CELL_PAYLOAD;
27272 }
27273
27274 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27275 if (iovb == NULL) {
27276 printk("nicstar%d: Out of iovec buffers.\n",
27277 card->index);
27278 - atomic_inc(&vcc->stats->rx_drop);
27279 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27280 recycle_rx_buf(card, skb);
27281 return;
27282 }
27283 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27284 small or large buffer itself. */
27285 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
27286 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
27287 - atomic_inc(&vcc->stats->rx_err);
27288 + atomic_inc_unchecked(&vcc->stats->rx_err);
27289 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27290 NS_MAX_IOVECS);
27291 NS_PRV_IOVCNT(iovb) = 0;
27292 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27293 ("nicstar%d: Expected a small buffer, and this is not one.\n",
27294 card->index);
27295 which_list(card, skb);
27296 - atomic_inc(&vcc->stats->rx_err);
27297 + atomic_inc_unchecked(&vcc->stats->rx_err);
27298 recycle_rx_buf(card, skb);
27299 vc->rx_iov = NULL;
27300 recycle_iov_buf(card, iovb);
27301 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27302 ("nicstar%d: Expected a large buffer, and this is not one.\n",
27303 card->index);
27304 which_list(card, skb);
27305 - atomic_inc(&vcc->stats->rx_err);
27306 + atomic_inc_unchecked(&vcc->stats->rx_err);
27307 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27308 NS_PRV_IOVCNT(iovb));
27309 vc->rx_iov = NULL;
27310 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27311 printk(" - PDU size mismatch.\n");
27312 else
27313 printk(".\n");
27314 - atomic_inc(&vcc->stats->rx_err);
27315 + atomic_inc_unchecked(&vcc->stats->rx_err);
27316 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27317 NS_PRV_IOVCNT(iovb));
27318 vc->rx_iov = NULL;
27319 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27320 /* skb points to a small buffer */
27321 if (!atm_charge(vcc, skb->truesize)) {
27322 push_rxbufs(card, skb);
27323 - atomic_inc(&vcc->stats->rx_drop);
27324 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27325 } else {
27326 skb_put(skb, len);
27327 dequeue_sm_buf(card, skb);
27328 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27329 ATM_SKB(skb)->vcc = vcc;
27330 __net_timestamp(skb);
27331 vcc->push(vcc, skb);
27332 - atomic_inc(&vcc->stats->rx);
27333 + atomic_inc_unchecked(&vcc->stats->rx);
27334 }
27335 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
27336 struct sk_buff *sb;
27337 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27338 if (len <= NS_SMBUFSIZE) {
27339 if (!atm_charge(vcc, sb->truesize)) {
27340 push_rxbufs(card, sb);
27341 - atomic_inc(&vcc->stats->rx_drop);
27342 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27343 } else {
27344 skb_put(sb, len);
27345 dequeue_sm_buf(card, sb);
27346 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27347 ATM_SKB(sb)->vcc = vcc;
27348 __net_timestamp(sb);
27349 vcc->push(vcc, sb);
27350 - atomic_inc(&vcc->stats->rx);
27351 + atomic_inc_unchecked(&vcc->stats->rx);
27352 }
27353
27354 push_rxbufs(card, skb);
27355 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27356
27357 if (!atm_charge(vcc, skb->truesize)) {
27358 push_rxbufs(card, skb);
27359 - atomic_inc(&vcc->stats->rx_drop);
27360 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27361 } else {
27362 dequeue_lg_buf(card, skb);
27363 #ifdef NS_USE_DESTRUCTORS
27364 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27365 ATM_SKB(skb)->vcc = vcc;
27366 __net_timestamp(skb);
27367 vcc->push(vcc, skb);
27368 - atomic_inc(&vcc->stats->rx);
27369 + atomic_inc_unchecked(&vcc->stats->rx);
27370 }
27371
27372 push_rxbufs(card, sb);
27373 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27374 printk
27375 ("nicstar%d: Out of huge buffers.\n",
27376 card->index);
27377 - atomic_inc(&vcc->stats->rx_drop);
27378 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27379 recycle_iovec_rx_bufs(card,
27380 (struct iovec *)
27381 iovb->data,
27382 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27383 card->hbpool.count++;
27384 } else
27385 dev_kfree_skb_any(hb);
27386 - atomic_inc(&vcc->stats->rx_drop);
27387 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27388 } else {
27389 /* Copy the small buffer to the huge buffer */
27390 sb = (struct sk_buff *)iov->iov_base;
27391 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27392 #endif /* NS_USE_DESTRUCTORS */
27393 __net_timestamp(hb);
27394 vcc->push(vcc, hb);
27395 - atomic_inc(&vcc->stats->rx);
27396 + atomic_inc_unchecked(&vcc->stats->rx);
27397 }
27398 }
27399
27400 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
27401 index 5d1d076..12fbca4 100644
27402 --- a/drivers/atm/solos-pci.c
27403 +++ b/drivers/atm/solos-pci.c
27404 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
27405 }
27406 atm_charge(vcc, skb->truesize);
27407 vcc->push(vcc, skb);
27408 - atomic_inc(&vcc->stats->rx);
27409 + atomic_inc_unchecked(&vcc->stats->rx);
27410 break;
27411
27412 case PKT_STATUS:
27413 @@ -1008,7 +1008,7 @@ static uint32_t fpga_tx(struct solos_card *card)
27414 vcc = SKB_CB(oldskb)->vcc;
27415
27416 if (vcc) {
27417 - atomic_inc(&vcc->stats->tx);
27418 + atomic_inc_unchecked(&vcc->stats->tx);
27419 solos_pop(vcc, oldskb);
27420 } else
27421 dev_kfree_skb_irq(oldskb);
27422 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
27423 index 90f1ccc..04c4a1e 100644
27424 --- a/drivers/atm/suni.c
27425 +++ b/drivers/atm/suni.c
27426 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
27427
27428
27429 #define ADD_LIMITED(s,v) \
27430 - atomic_add((v),&stats->s); \
27431 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
27432 + atomic_add_unchecked((v),&stats->s); \
27433 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
27434
27435
27436 static void suni_hz(unsigned long from_timer)
27437 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
27438 index 5120a96..e2572bd 100644
27439 --- a/drivers/atm/uPD98402.c
27440 +++ b/drivers/atm/uPD98402.c
27441 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
27442 struct sonet_stats tmp;
27443 int error = 0;
27444
27445 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
27446 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
27447 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
27448 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
27449 if (zero && !error) {
27450 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
27451
27452
27453 #define ADD_LIMITED(s,v) \
27454 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
27455 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
27456 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
27457 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
27458 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
27459 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
27460
27461
27462 static void stat_event(struct atm_dev *dev)
27463 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
27464 if (reason & uPD98402_INT_PFM) stat_event(dev);
27465 if (reason & uPD98402_INT_PCO) {
27466 (void) GET(PCOCR); /* clear interrupt cause */
27467 - atomic_add(GET(HECCT),
27468 + atomic_add_unchecked(GET(HECCT),
27469 &PRIV(dev)->sonet_stats.uncorr_hcs);
27470 }
27471 if ((reason & uPD98402_INT_RFO) &&
27472 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
27473 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
27474 uPD98402_INT_LOS),PIMR); /* enable them */
27475 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
27476 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
27477 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
27478 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
27479 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
27480 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
27481 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
27482 return 0;
27483 }
27484
27485 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
27486 index d889f56..17eb71e 100644
27487 --- a/drivers/atm/zatm.c
27488 +++ b/drivers/atm/zatm.c
27489 @@ -460,7 +460,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
27490 }
27491 if (!size) {
27492 dev_kfree_skb_irq(skb);
27493 - if (vcc) atomic_inc(&vcc->stats->rx_err);
27494 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
27495 continue;
27496 }
27497 if (!atm_charge(vcc,skb->truesize)) {
27498 @@ -470,7 +470,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
27499 skb->len = size;
27500 ATM_SKB(skb)->vcc = vcc;
27501 vcc->push(vcc,skb);
27502 - atomic_inc(&vcc->stats->rx);
27503 + atomic_inc_unchecked(&vcc->stats->rx);
27504 }
27505 zout(pos & 0xffff,MTA(mbx));
27506 #if 0 /* probably a stupid idea */
27507 @@ -734,7 +734,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
27508 skb_queue_head(&zatm_vcc->backlog,skb);
27509 break;
27510 }
27511 - atomic_inc(&vcc->stats->tx);
27512 + atomic_inc_unchecked(&vcc->stats->tx);
27513 wake_up(&zatm_vcc->tx_wait);
27514 }
27515
27516 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
27517 index a4760e0..51283cf 100644
27518 --- a/drivers/base/devtmpfs.c
27519 +++ b/drivers/base/devtmpfs.c
27520 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
27521 if (!thread)
27522 return 0;
27523
27524 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
27525 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
27526 if (err)
27527 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
27528 else
27529 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
27530 index caf995f..6f76697 100644
27531 --- a/drivers/base/power/wakeup.c
27532 +++ b/drivers/base/power/wakeup.c
27533 @@ -30,14 +30,14 @@ bool events_check_enabled;
27534 * They need to be modified together atomically, so it's better to use one
27535 * atomic variable to hold them both.
27536 */
27537 -static atomic_t combined_event_count = ATOMIC_INIT(0);
27538 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
27539
27540 #define IN_PROGRESS_BITS (sizeof(int) * 4)
27541 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
27542
27543 static void split_counters(unsigned int *cnt, unsigned int *inpr)
27544 {
27545 - unsigned int comb = atomic_read(&combined_event_count);
27546 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
27547
27548 *cnt = (comb >> IN_PROGRESS_BITS);
27549 *inpr = comb & MAX_IN_PROGRESS;
27550 @@ -353,7 +353,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
27551 ws->last_time = ktime_get();
27552
27553 /* Increment the counter of events in progress. */
27554 - atomic_inc(&combined_event_count);
27555 + atomic_inc_unchecked(&combined_event_count);
27556 }
27557
27558 /**
27559 @@ -443,7 +443,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
27560 * Increment the counter of registered wakeup events and decrement the
27561 * couter of wakeup events in progress simultaneously.
27562 */
27563 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
27564 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
27565 }
27566
27567 /**
27568 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
27569 index b0f553b..77b928b 100644
27570 --- a/drivers/block/cciss.c
27571 +++ b/drivers/block/cciss.c
27572 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
27573 int err;
27574 u32 cp;
27575
27576 + memset(&arg64, 0, sizeof(arg64));
27577 +
27578 err = 0;
27579 err |=
27580 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
27581 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
27582 while (!list_empty(&h->reqQ)) {
27583 c = list_entry(h->reqQ.next, CommandList_struct, list);
27584 /* can't do anything if fifo is full */
27585 - if ((h->access.fifo_full(h))) {
27586 + if ((h->access->fifo_full(h))) {
27587 dev_warn(&h->pdev->dev, "fifo full\n");
27588 break;
27589 }
27590 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
27591 h->Qdepth--;
27592
27593 /* Tell the controller execute command */
27594 - h->access.submit_command(h, c);
27595 + h->access->submit_command(h, c);
27596
27597 /* Put job onto the completed Q */
27598 addQ(&h->cmpQ, c);
27599 @@ -3443,17 +3445,17 @@ startio:
27600
27601 static inline unsigned long get_next_completion(ctlr_info_t *h)
27602 {
27603 - return h->access.command_completed(h);
27604 + return h->access->command_completed(h);
27605 }
27606
27607 static inline int interrupt_pending(ctlr_info_t *h)
27608 {
27609 - return h->access.intr_pending(h);
27610 + return h->access->intr_pending(h);
27611 }
27612
27613 static inline long interrupt_not_for_us(ctlr_info_t *h)
27614 {
27615 - return ((h->access.intr_pending(h) == 0) ||
27616 + return ((h->access->intr_pending(h) == 0) ||
27617 (h->interrupts_enabled == 0));
27618 }
27619
27620 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
27621 u32 a;
27622
27623 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
27624 - return h->access.command_completed(h);
27625 + return h->access->command_completed(h);
27626
27627 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
27628 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
27629 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
27630 trans_support & CFGTBL_Trans_use_short_tags);
27631
27632 /* Change the access methods to the performant access methods */
27633 - h->access = SA5_performant_access;
27634 + h->access = &SA5_performant_access;
27635 h->transMethod = CFGTBL_Trans_Performant;
27636
27637 return;
27638 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
27639 if (prod_index < 0)
27640 return -ENODEV;
27641 h->product_name = products[prod_index].product_name;
27642 - h->access = *(products[prod_index].access);
27643 + h->access = products[prod_index].access;
27644
27645 if (cciss_board_disabled(h)) {
27646 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
27647 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
27648 }
27649
27650 /* make sure the board interrupts are off */
27651 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
27652 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
27653 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
27654 if (rc)
27655 goto clean2;
27656 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
27657 * fake ones to scoop up any residual completions.
27658 */
27659 spin_lock_irqsave(&h->lock, flags);
27660 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
27661 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
27662 spin_unlock_irqrestore(&h->lock, flags);
27663 free_irq(h->intr[h->intr_mode], h);
27664 rc = cciss_request_irq(h, cciss_msix_discard_completions,
27665 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
27666 dev_info(&h->pdev->dev, "Board READY.\n");
27667 dev_info(&h->pdev->dev,
27668 "Waiting for stale completions to drain.\n");
27669 - h->access.set_intr_mask(h, CCISS_INTR_ON);
27670 + h->access->set_intr_mask(h, CCISS_INTR_ON);
27671 msleep(10000);
27672 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
27673 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
27674
27675 rc = controller_reset_failed(h->cfgtable);
27676 if (rc)
27677 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
27678 cciss_scsi_setup(h);
27679
27680 /* Turn the interrupts on so we can service requests */
27681 - h->access.set_intr_mask(h, CCISS_INTR_ON);
27682 + h->access->set_intr_mask(h, CCISS_INTR_ON);
27683
27684 /* Get the firmware version */
27685 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
27686 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
27687 kfree(flush_buf);
27688 if (return_code != IO_OK)
27689 dev_warn(&h->pdev->dev, "Error flushing cache\n");
27690 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
27691 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
27692 free_irq(h->intr[h->intr_mode], h);
27693 }
27694
27695 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
27696 index 7fda30e..eb5dfe0 100644
27697 --- a/drivers/block/cciss.h
27698 +++ b/drivers/block/cciss.h
27699 @@ -101,7 +101,7 @@ struct ctlr_info
27700 /* information about each logical volume */
27701 drive_info_struct *drv[CISS_MAX_LUN];
27702
27703 - struct access_method access;
27704 + struct access_method *access;
27705
27706 /* queue and queue Info */
27707 struct list_head reqQ;
27708 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
27709 index 9125bbe..eede5c8 100644
27710 --- a/drivers/block/cpqarray.c
27711 +++ b/drivers/block/cpqarray.c
27712 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
27713 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
27714 goto Enomem4;
27715 }
27716 - hba[i]->access.set_intr_mask(hba[i], 0);
27717 + hba[i]->access->set_intr_mask(hba[i], 0);
27718 if (request_irq(hba[i]->intr, do_ida_intr,
27719 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
27720 {
27721 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
27722 add_timer(&hba[i]->timer);
27723
27724 /* Enable IRQ now that spinlock and rate limit timer are set up */
27725 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
27726 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
27727
27728 for(j=0; j<NWD; j++) {
27729 struct gendisk *disk = ida_gendisk[i][j];
27730 @@ -694,7 +694,7 @@ DBGINFO(
27731 for(i=0; i<NR_PRODUCTS; i++) {
27732 if (board_id == products[i].board_id) {
27733 c->product_name = products[i].product_name;
27734 - c->access = *(products[i].access);
27735 + c->access = products[i].access;
27736 break;
27737 }
27738 }
27739 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
27740 hba[ctlr]->intr = intr;
27741 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
27742 hba[ctlr]->product_name = products[j].product_name;
27743 - hba[ctlr]->access = *(products[j].access);
27744 + hba[ctlr]->access = products[j].access;
27745 hba[ctlr]->ctlr = ctlr;
27746 hba[ctlr]->board_id = board_id;
27747 hba[ctlr]->pci_dev = NULL; /* not PCI */
27748 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
27749
27750 while((c = h->reqQ) != NULL) {
27751 /* Can't do anything if we're busy */
27752 - if (h->access.fifo_full(h) == 0)
27753 + if (h->access->fifo_full(h) == 0)
27754 return;
27755
27756 /* Get the first entry from the request Q */
27757 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
27758 h->Qdepth--;
27759
27760 /* Tell the controller to do our bidding */
27761 - h->access.submit_command(h, c);
27762 + h->access->submit_command(h, c);
27763
27764 /* Get onto the completion Q */
27765 addQ(&h->cmpQ, c);
27766 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
27767 unsigned long flags;
27768 __u32 a,a1;
27769
27770 - istat = h->access.intr_pending(h);
27771 + istat = h->access->intr_pending(h);
27772 /* Is this interrupt for us? */
27773 if (istat == 0)
27774 return IRQ_NONE;
27775 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
27776 */
27777 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
27778 if (istat & FIFO_NOT_EMPTY) {
27779 - while((a = h->access.command_completed(h))) {
27780 + while((a = h->access->command_completed(h))) {
27781 a1 = a; a &= ~3;
27782 if ((c = h->cmpQ) == NULL)
27783 {
27784 @@ -1449,11 +1449,11 @@ static int sendcmd(
27785 /*
27786 * Disable interrupt
27787 */
27788 - info_p->access.set_intr_mask(info_p, 0);
27789 + info_p->access->set_intr_mask(info_p, 0);
27790 /* Make sure there is room in the command FIFO */
27791 /* Actually it should be completely empty at this time. */
27792 for (i = 200000; i > 0; i--) {
27793 - temp = info_p->access.fifo_full(info_p);
27794 + temp = info_p->access->fifo_full(info_p);
27795 if (temp != 0) {
27796 break;
27797 }
27798 @@ -1466,7 +1466,7 @@ DBG(
27799 /*
27800 * Send the cmd
27801 */
27802 - info_p->access.submit_command(info_p, c);
27803 + info_p->access->submit_command(info_p, c);
27804 complete = pollcomplete(ctlr);
27805
27806 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
27807 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
27808 * we check the new geometry. Then turn interrupts back on when
27809 * we're done.
27810 */
27811 - host->access.set_intr_mask(host, 0);
27812 + host->access->set_intr_mask(host, 0);
27813 getgeometry(ctlr);
27814 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
27815 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
27816
27817 for(i=0; i<NWD; i++) {
27818 struct gendisk *disk = ida_gendisk[ctlr][i];
27819 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
27820 /* Wait (up to 2 seconds) for a command to complete */
27821
27822 for (i = 200000; i > 0; i--) {
27823 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
27824 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
27825 if (done == 0) {
27826 udelay(10); /* a short fixed delay */
27827 } else
27828 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
27829 index be73e9d..7fbf140 100644
27830 --- a/drivers/block/cpqarray.h
27831 +++ b/drivers/block/cpqarray.h
27832 @@ -99,7 +99,7 @@ struct ctlr_info {
27833 drv_info_t drv[NWD];
27834 struct proc_dir_entry *proc;
27835
27836 - struct access_method access;
27837 + struct access_method *access;
27838
27839 cmdlist_t *reqQ;
27840 cmdlist_t *cmpQ;
27841 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
27842 index 9cf2035..bffca95 100644
27843 --- a/drivers/block/drbd/drbd_int.h
27844 +++ b/drivers/block/drbd/drbd_int.h
27845 @@ -736,7 +736,7 @@ struct drbd_request;
27846 struct drbd_epoch {
27847 struct list_head list;
27848 unsigned int barrier_nr;
27849 - atomic_t epoch_size; /* increased on every request added. */
27850 + atomic_unchecked_t epoch_size; /* increased on every request added. */
27851 atomic_t active; /* increased on every req. added, and dec on every finished. */
27852 unsigned long flags;
27853 };
27854 @@ -1108,7 +1108,7 @@ struct drbd_conf {
27855 void *int_dig_in;
27856 void *int_dig_vv;
27857 wait_queue_head_t seq_wait;
27858 - atomic_t packet_seq;
27859 + atomic_unchecked_t packet_seq;
27860 unsigned int peer_seq;
27861 spinlock_t peer_seq_lock;
27862 unsigned int minor;
27863 @@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
27864
27865 static inline void drbd_tcp_cork(struct socket *sock)
27866 {
27867 - int __user val = 1;
27868 + int val = 1;
27869 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
27870 - (char __user *)&val, sizeof(val));
27871 + (char __force_user *)&val, sizeof(val));
27872 }
27873
27874 static inline void drbd_tcp_uncork(struct socket *sock)
27875 {
27876 - int __user val = 0;
27877 + int val = 0;
27878 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
27879 - (char __user *)&val, sizeof(val));
27880 + (char __force_user *)&val, sizeof(val));
27881 }
27882
27883 static inline void drbd_tcp_nodelay(struct socket *sock)
27884 {
27885 - int __user val = 1;
27886 + int val = 1;
27887 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
27888 - (char __user *)&val, sizeof(val));
27889 + (char __force_user *)&val, sizeof(val));
27890 }
27891
27892 static inline void drbd_tcp_quickack(struct socket *sock)
27893 {
27894 - int __user val = 2;
27895 + int val = 2;
27896 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
27897 - (char __user *)&val, sizeof(val));
27898 + (char __force_user *)&val, sizeof(val));
27899 }
27900
27901 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
27902 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
27903 index 0358e55..bc33689 100644
27904 --- a/drivers/block/drbd/drbd_main.c
27905 +++ b/drivers/block/drbd/drbd_main.c
27906 @@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
27907 p.sector = sector;
27908 p.block_id = block_id;
27909 p.blksize = blksize;
27910 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
27911 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
27912
27913 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
27914 return false;
27915 @@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
27916 p.sector = cpu_to_be64(req->sector);
27917 p.block_id = (unsigned long)req;
27918 p.seq_num = cpu_to_be32(req->seq_num =
27919 - atomic_add_return(1, &mdev->packet_seq));
27920 + atomic_add_return_unchecked(1, &mdev->packet_seq));
27921
27922 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
27923
27924 @@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
27925 atomic_set(&mdev->unacked_cnt, 0);
27926 atomic_set(&mdev->local_cnt, 0);
27927 atomic_set(&mdev->net_cnt, 0);
27928 - atomic_set(&mdev->packet_seq, 0);
27929 + atomic_set_unchecked(&mdev->packet_seq, 0);
27930 atomic_set(&mdev->pp_in_use, 0);
27931 atomic_set(&mdev->pp_in_use_by_net, 0);
27932 atomic_set(&mdev->rs_sect_in, 0);
27933 @@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
27934 mdev->receiver.t_state);
27935
27936 /* no need to lock it, I'm the only thread alive */
27937 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
27938 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
27939 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
27940 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
27941 mdev->al_writ_cnt =
27942 mdev->bm_writ_cnt =
27943 mdev->read_cnt =
27944 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
27945 index af2a250..219c74b 100644
27946 --- a/drivers/block/drbd/drbd_nl.c
27947 +++ b/drivers/block/drbd/drbd_nl.c
27948 @@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
27949 module_put(THIS_MODULE);
27950 }
27951
27952 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
27953 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
27954
27955 static unsigned short *
27956 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
27957 @@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
27958 cn_reply->id.idx = CN_IDX_DRBD;
27959 cn_reply->id.val = CN_VAL_DRBD;
27960
27961 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
27962 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
27963 cn_reply->ack = 0; /* not used here. */
27964 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27965 (int)((char *)tl - (char *)reply->tag_list);
27966 @@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
27967 cn_reply->id.idx = CN_IDX_DRBD;
27968 cn_reply->id.val = CN_VAL_DRBD;
27969
27970 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
27971 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
27972 cn_reply->ack = 0; /* not used here. */
27973 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27974 (int)((char *)tl - (char *)reply->tag_list);
27975 @@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
27976 cn_reply->id.idx = CN_IDX_DRBD;
27977 cn_reply->id.val = CN_VAL_DRBD;
27978
27979 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
27980 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
27981 cn_reply->ack = 0; // not used here.
27982 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27983 (int)((char*)tl - (char*)reply->tag_list);
27984 @@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
27985 cn_reply->id.idx = CN_IDX_DRBD;
27986 cn_reply->id.val = CN_VAL_DRBD;
27987
27988 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
27989 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
27990 cn_reply->ack = 0; /* not used here. */
27991 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27992 (int)((char *)tl - (char *)reply->tag_list);
27993 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
27994 index 43beaca..4a5b1dd 100644
27995 --- a/drivers/block/drbd/drbd_receiver.c
27996 +++ b/drivers/block/drbd/drbd_receiver.c
27997 @@ -894,7 +894,7 @@ retry:
27998 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
27999 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
28000
28001 - atomic_set(&mdev->packet_seq, 0);
28002 + atomic_set_unchecked(&mdev->packet_seq, 0);
28003 mdev->peer_seq = 0;
28004
28005 drbd_thread_start(&mdev->asender);
28006 @@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
28007 do {
28008 next_epoch = NULL;
28009
28010 - epoch_size = atomic_read(&epoch->epoch_size);
28011 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
28012
28013 switch (ev & ~EV_CLEANUP) {
28014 case EV_PUT:
28015 @@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
28016 rv = FE_DESTROYED;
28017 } else {
28018 epoch->flags = 0;
28019 - atomic_set(&epoch->epoch_size, 0);
28020 + atomic_set_unchecked(&epoch->epoch_size, 0);
28021 /* atomic_set(&epoch->active, 0); is already zero */
28022 if (rv == FE_STILL_LIVE)
28023 rv = FE_RECYCLED;
28024 @@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
28025 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
28026 drbd_flush(mdev);
28027
28028 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
28029 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
28030 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
28031 if (epoch)
28032 break;
28033 }
28034
28035 epoch = mdev->current_epoch;
28036 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
28037 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
28038
28039 D_ASSERT(atomic_read(&epoch->active) == 0);
28040 D_ASSERT(epoch->flags == 0);
28041 @@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
28042 }
28043
28044 epoch->flags = 0;
28045 - atomic_set(&epoch->epoch_size, 0);
28046 + atomic_set_unchecked(&epoch->epoch_size, 0);
28047 atomic_set(&epoch->active, 0);
28048
28049 spin_lock(&mdev->epoch_lock);
28050 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
28051 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
28052 list_add(&epoch->list, &mdev->current_epoch->list);
28053 mdev->current_epoch = epoch;
28054 mdev->epochs++;
28055 @@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
28056 spin_unlock(&mdev->peer_seq_lock);
28057
28058 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
28059 - atomic_inc(&mdev->current_epoch->epoch_size);
28060 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
28061 return drbd_drain_block(mdev, data_size);
28062 }
28063
28064 @@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
28065
28066 spin_lock(&mdev->epoch_lock);
28067 e->epoch = mdev->current_epoch;
28068 - atomic_inc(&e->epoch->epoch_size);
28069 + atomic_inc_unchecked(&e->epoch->epoch_size);
28070 atomic_inc(&e->epoch->active);
28071 spin_unlock(&mdev->epoch_lock);
28072
28073 @@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
28074 D_ASSERT(list_empty(&mdev->done_ee));
28075
28076 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
28077 - atomic_set(&mdev->current_epoch->epoch_size, 0);
28078 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
28079 D_ASSERT(list_empty(&mdev->current_epoch->list));
28080 }
28081
28082 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
28083 index 1e888c9..05cf1b0 100644
28084 --- a/drivers/block/loop.c
28085 +++ b/drivers/block/loop.c
28086 @@ -227,7 +227,7 @@ static int __do_lo_send_write(struct file *file,
28087 mm_segment_t old_fs = get_fs();
28088
28089 set_fs(get_ds());
28090 - bw = file->f_op->write(file, buf, len, &pos);
28091 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
28092 set_fs(old_fs);
28093 if (likely(bw == len))
28094 return 0;
28095 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
28096 index 4364303..9adf4ee 100644
28097 --- a/drivers/char/Kconfig
28098 +++ b/drivers/char/Kconfig
28099 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
28100
28101 config DEVKMEM
28102 bool "/dev/kmem virtual device support"
28103 - default y
28104 + default n
28105 + depends on !GRKERNSEC_KMEM
28106 help
28107 Say Y here if you want to support the /dev/kmem device. The
28108 /dev/kmem device is rarely used, but can be used for certain
28109 @@ -596,6 +597,7 @@ config DEVPORT
28110 bool
28111 depends on !M68K
28112 depends on ISA || PCI
28113 + depends on !GRKERNSEC_KMEM
28114 default y
28115
28116 source "drivers/s390/char/Kconfig"
28117 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
28118 index 2e04433..22afc64 100644
28119 --- a/drivers/char/agp/frontend.c
28120 +++ b/drivers/char/agp/frontend.c
28121 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
28122 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
28123 return -EFAULT;
28124
28125 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
28126 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
28127 return -EFAULT;
28128
28129 client = agp_find_client_by_pid(reserve.pid);
28130 diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
28131 index 095ab90..afad0a4 100644
28132 --- a/drivers/char/briq_panel.c
28133 +++ b/drivers/char/briq_panel.c
28134 @@ -9,6 +9,7 @@
28135 #include <linux/types.h>
28136 #include <linux/errno.h>
28137 #include <linux/tty.h>
28138 +#include <linux/mutex.h>
28139 #include <linux/timer.h>
28140 #include <linux/kernel.h>
28141 #include <linux/wait.h>
28142 @@ -34,6 +35,7 @@ static int vfd_is_open;
28143 static unsigned char vfd[40];
28144 static int vfd_cursor;
28145 static unsigned char ledpb, led;
28146 +static DEFINE_MUTEX(vfd_mutex);
28147
28148 static void update_vfd(void)
28149 {
28150 @@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
28151 if (!vfd_is_open)
28152 return -EBUSY;
28153
28154 + mutex_lock(&vfd_mutex);
28155 for (;;) {
28156 char c;
28157 if (!indx)
28158 break;
28159 - if (get_user(c, buf))
28160 + if (get_user(c, buf)) {
28161 + mutex_unlock(&vfd_mutex);
28162 return -EFAULT;
28163 + }
28164 if (esc) {
28165 set_led(c);
28166 esc = 0;
28167 @@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
28168 buf++;
28169 }
28170 update_vfd();
28171 + mutex_unlock(&vfd_mutex);
28172
28173 return len;
28174 }
28175 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
28176 index f773a9d..65cd683 100644
28177 --- a/drivers/char/genrtc.c
28178 +++ b/drivers/char/genrtc.c
28179 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
28180 switch (cmd) {
28181
28182 case RTC_PLL_GET:
28183 + memset(&pll, 0, sizeof(pll));
28184 if (get_rtc_pll(&pll))
28185 return -EINVAL;
28186 else
28187 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
28188 index 0833896..cccce52 100644
28189 --- a/drivers/char/hpet.c
28190 +++ b/drivers/char/hpet.c
28191 @@ -572,7 +572,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
28192 }
28193
28194 static int
28195 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
28196 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
28197 struct hpet_info *info)
28198 {
28199 struct hpet_timer __iomem *timer;
28200 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
28201 index 58c0e63..46c16bf 100644
28202 --- a/drivers/char/ipmi/ipmi_msghandler.c
28203 +++ b/drivers/char/ipmi/ipmi_msghandler.c
28204 @@ -415,7 +415,7 @@ struct ipmi_smi {
28205 struct proc_dir_entry *proc_dir;
28206 char proc_dir_name[10];
28207
28208 - atomic_t stats[IPMI_NUM_STATS];
28209 + atomic_unchecked_t stats[IPMI_NUM_STATS];
28210
28211 /*
28212 * run_to_completion duplicate of smb_info, smi_info
28213 @@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
28214
28215
28216 #define ipmi_inc_stat(intf, stat) \
28217 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
28218 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
28219 #define ipmi_get_stat(intf, stat) \
28220 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
28221 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
28222
28223 static int is_lan_addr(struct ipmi_addr *addr)
28224 {
28225 @@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
28226 INIT_LIST_HEAD(&intf->cmd_rcvrs);
28227 init_waitqueue_head(&intf->waitq);
28228 for (i = 0; i < IPMI_NUM_STATS; i++)
28229 - atomic_set(&intf->stats[i], 0);
28230 + atomic_set_unchecked(&intf->stats[i], 0);
28231
28232 intf->proc_dir = NULL;
28233
28234 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
28235 index 9397ab4..d01bee1 100644
28236 --- a/drivers/char/ipmi/ipmi_si_intf.c
28237 +++ b/drivers/char/ipmi/ipmi_si_intf.c
28238 @@ -277,7 +277,7 @@ struct smi_info {
28239 unsigned char slave_addr;
28240
28241 /* Counters and things for the proc filesystem. */
28242 - atomic_t stats[SI_NUM_STATS];
28243 + atomic_unchecked_t stats[SI_NUM_STATS];
28244
28245 struct task_struct *thread;
28246
28247 @@ -286,9 +286,9 @@ struct smi_info {
28248 };
28249
28250 #define smi_inc_stat(smi, stat) \
28251 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
28252 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
28253 #define smi_get_stat(smi, stat) \
28254 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
28255 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
28256
28257 #define SI_MAX_PARMS 4
28258
28259 @@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info *new_smi)
28260 atomic_set(&new_smi->req_events, 0);
28261 new_smi->run_to_completion = 0;
28262 for (i = 0; i < SI_NUM_STATS; i++)
28263 - atomic_set(&new_smi->stats[i], 0);
28264 + atomic_set_unchecked(&new_smi->stats[i], 0);
28265
28266 new_smi->interrupt_disabled = 1;
28267 atomic_set(&new_smi->stop_operation, 0);
28268 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
28269 index 1aeaaba..e018570 100644
28270 --- a/drivers/char/mbcs.c
28271 +++ b/drivers/char/mbcs.c
28272 @@ -800,7 +800,7 @@ static int mbcs_remove(struct cx_dev *dev)
28273 return 0;
28274 }
28275
28276 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
28277 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
28278 {
28279 .part_num = MBCS_PART_NUM,
28280 .mfg_num = MBCS_MFG_NUM,
28281 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
28282 index 1451790..f705c30 100644
28283 --- a/drivers/char/mem.c
28284 +++ b/drivers/char/mem.c
28285 @@ -18,6 +18,7 @@
28286 #include <linux/raw.h>
28287 #include <linux/tty.h>
28288 #include <linux/capability.h>
28289 +#include <linux/security.h>
28290 #include <linux/ptrace.h>
28291 #include <linux/device.h>
28292 #include <linux/highmem.h>
28293 @@ -35,6 +36,10 @@
28294 # include <linux/efi.h>
28295 #endif
28296
28297 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
28298 +extern const struct file_operations grsec_fops;
28299 +#endif
28300 +
28301 static inline unsigned long size_inside_page(unsigned long start,
28302 unsigned long size)
28303 {
28304 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28305
28306 while (cursor < to) {
28307 if (!devmem_is_allowed(pfn)) {
28308 +#ifdef CONFIG_GRKERNSEC_KMEM
28309 + gr_handle_mem_readwrite(from, to);
28310 +#else
28311 printk(KERN_INFO
28312 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
28313 current->comm, from, to);
28314 +#endif
28315 return 0;
28316 }
28317 cursor += PAGE_SIZE;
28318 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28319 }
28320 return 1;
28321 }
28322 +#elif defined(CONFIG_GRKERNSEC_KMEM)
28323 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28324 +{
28325 + return 0;
28326 +}
28327 #else
28328 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28329 {
28330 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
28331
28332 while (count > 0) {
28333 unsigned long remaining;
28334 + char *temp;
28335
28336 sz = size_inside_page(p, count);
28337
28338 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
28339 if (!ptr)
28340 return -EFAULT;
28341
28342 - remaining = copy_to_user(buf, ptr, sz);
28343 +#ifdef CONFIG_PAX_USERCOPY
28344 + temp = kmalloc(sz, GFP_KERNEL);
28345 + if (!temp) {
28346 + unxlate_dev_mem_ptr(p, ptr);
28347 + return -ENOMEM;
28348 + }
28349 + memcpy(temp, ptr, sz);
28350 +#else
28351 + temp = ptr;
28352 +#endif
28353 +
28354 + remaining = copy_to_user(buf, temp, sz);
28355 +
28356 +#ifdef CONFIG_PAX_USERCOPY
28357 + kfree(temp);
28358 +#endif
28359 +
28360 unxlate_dev_mem_ptr(p, ptr);
28361 if (remaining)
28362 return -EFAULT;
28363 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
28364 size_t count, loff_t *ppos)
28365 {
28366 unsigned long p = *ppos;
28367 - ssize_t low_count, read, sz;
28368 + ssize_t low_count, read, sz, err = 0;
28369 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
28370 - int err = 0;
28371
28372 read = 0;
28373 if (p < (unsigned long) high_memory) {
28374 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
28375 }
28376 #endif
28377 while (low_count > 0) {
28378 + char *temp;
28379 +
28380 sz = size_inside_page(p, low_count);
28381
28382 /*
28383 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
28384 */
28385 kbuf = xlate_dev_kmem_ptr((char *)p);
28386
28387 - if (copy_to_user(buf, kbuf, sz))
28388 +#ifdef CONFIG_PAX_USERCOPY
28389 + temp = kmalloc(sz, GFP_KERNEL);
28390 + if (!temp)
28391 + return -ENOMEM;
28392 + memcpy(temp, kbuf, sz);
28393 +#else
28394 + temp = kbuf;
28395 +#endif
28396 +
28397 + err = copy_to_user(buf, temp, sz);
28398 +
28399 +#ifdef CONFIG_PAX_USERCOPY
28400 + kfree(temp);
28401 +#endif
28402 +
28403 + if (err)
28404 return -EFAULT;
28405 buf += sz;
28406 p += sz;
28407 @@ -867,6 +914,9 @@ static const struct memdev {
28408 #ifdef CONFIG_CRASH_DUMP
28409 [12] = { "oldmem", 0, &oldmem_fops, NULL },
28410 #endif
28411 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
28412 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
28413 +#endif
28414 };
28415
28416 static int memory_open(struct inode *inode, struct file *filp)
28417 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
28418 index da3cfee..a5a6606 100644
28419 --- a/drivers/char/nvram.c
28420 +++ b/drivers/char/nvram.c
28421 @@ -248,7 +248,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
28422
28423 spin_unlock_irq(&rtc_lock);
28424
28425 - if (copy_to_user(buf, contents, tmp - contents))
28426 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
28427 return -EFAULT;
28428
28429 *ppos = i;
28430 diff --git a/drivers/char/random.c b/drivers/char/random.c
28431 index 6035ab8..bdfe4fd 100644
28432 --- a/drivers/char/random.c
28433 +++ b/drivers/char/random.c
28434 @@ -261,8 +261,13 @@
28435 /*
28436 * Configuration information
28437 */
28438 +#ifdef CONFIG_GRKERNSEC_RANDNET
28439 +#define INPUT_POOL_WORDS 512
28440 +#define OUTPUT_POOL_WORDS 128
28441 +#else
28442 #define INPUT_POOL_WORDS 128
28443 #define OUTPUT_POOL_WORDS 32
28444 +#endif
28445 #define SEC_XFER_SIZE 512
28446 #define EXTRACT_SIZE 10
28447
28448 @@ -300,10 +305,17 @@ static struct poolinfo {
28449 int poolwords;
28450 int tap1, tap2, tap3, tap4, tap5;
28451 } poolinfo_table[] = {
28452 +#ifdef CONFIG_GRKERNSEC_RANDNET
28453 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
28454 + { 512, 411, 308, 208, 104, 1 },
28455 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
28456 + { 128, 103, 76, 51, 25, 1 },
28457 +#else
28458 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
28459 { 128, 103, 76, 51, 25, 1 },
28460 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
28461 { 32, 26, 20, 14, 7, 1 },
28462 +#endif
28463 #if 0
28464 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
28465 { 2048, 1638, 1231, 819, 411, 1 },
28466 @@ -909,7 +921,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
28467
28468 extract_buf(r, tmp);
28469 i = min_t(int, nbytes, EXTRACT_SIZE);
28470 - if (copy_to_user(buf, tmp, i)) {
28471 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
28472 ret = -EFAULT;
28473 break;
28474 }
28475 @@ -1228,7 +1240,7 @@ EXPORT_SYMBOL(generate_random_uuid);
28476 #include <linux/sysctl.h>
28477
28478 static int min_read_thresh = 8, min_write_thresh;
28479 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
28480 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
28481 static int max_write_thresh = INPUT_POOL_WORDS * 32;
28482 static char sysctl_bootid[16];
28483
28484 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
28485 index 1ee8ce7..b778bef 100644
28486 --- a/drivers/char/sonypi.c
28487 +++ b/drivers/char/sonypi.c
28488 @@ -55,6 +55,7 @@
28489 #include <asm/uaccess.h>
28490 #include <asm/io.h>
28491 #include <asm/system.h>
28492 +#include <asm/local.h>
28493
28494 #include <linux/sonypi.h>
28495
28496 @@ -491,7 +492,7 @@ static struct sonypi_device {
28497 spinlock_t fifo_lock;
28498 wait_queue_head_t fifo_proc_list;
28499 struct fasync_struct *fifo_async;
28500 - int open_count;
28501 + local_t open_count;
28502 int model;
28503 struct input_dev *input_jog_dev;
28504 struct input_dev *input_key_dev;
28505 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
28506 static int sonypi_misc_release(struct inode *inode, struct file *file)
28507 {
28508 mutex_lock(&sonypi_device.lock);
28509 - sonypi_device.open_count--;
28510 + local_dec(&sonypi_device.open_count);
28511 mutex_unlock(&sonypi_device.lock);
28512 return 0;
28513 }
28514 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
28515 {
28516 mutex_lock(&sonypi_device.lock);
28517 /* Flush input queue on first open */
28518 - if (!sonypi_device.open_count)
28519 + if (!local_read(&sonypi_device.open_count))
28520 kfifo_reset(&sonypi_device.fifo);
28521 - sonypi_device.open_count++;
28522 + local_inc(&sonypi_device.open_count);
28523 mutex_unlock(&sonypi_device.lock);
28524
28525 return 0;
28526 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
28527 index 361a1df..2471eee 100644
28528 --- a/drivers/char/tpm/tpm.c
28529 +++ b/drivers/char/tpm/tpm.c
28530 @@ -414,7 +414,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
28531 chip->vendor.req_complete_val)
28532 goto out_recv;
28533
28534 - if ((status == chip->vendor.req_canceled)) {
28535 + if (status == chip->vendor.req_canceled) {
28536 dev_err(chip->dev, "Operation Canceled\n");
28537 rc = -ECANCELED;
28538 goto out;
28539 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
28540 index 0636520..169c1d0 100644
28541 --- a/drivers/char/tpm/tpm_bios.c
28542 +++ b/drivers/char/tpm/tpm_bios.c
28543 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
28544 event = addr;
28545
28546 if ((event->event_type == 0 && event->event_size == 0) ||
28547 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
28548 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
28549 return NULL;
28550
28551 return addr;
28552 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
28553 return NULL;
28554
28555 if ((event->event_type == 0 && event->event_size == 0) ||
28556 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
28557 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
28558 return NULL;
28559
28560 (*pos)++;
28561 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
28562 int i;
28563
28564 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
28565 - seq_putc(m, data[i]);
28566 + if (!seq_putc(m, data[i]))
28567 + return -EFAULT;
28568
28569 return 0;
28570 }
28571 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
28572 log->bios_event_log_end = log->bios_event_log + len;
28573
28574 virt = acpi_os_map_memory(start, len);
28575 + if (!virt) {
28576 + kfree(log->bios_event_log);
28577 + log->bios_event_log = NULL;
28578 + return -EFAULT;
28579 + }
28580
28581 - memcpy(log->bios_event_log, virt, len);
28582 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
28583
28584 acpi_os_unmap_memory(virt, len);
28585 return 0;
28586 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
28587 index 8e3c46d..c139b99 100644
28588 --- a/drivers/char/virtio_console.c
28589 +++ b/drivers/char/virtio_console.c
28590 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
28591 if (to_user) {
28592 ssize_t ret;
28593
28594 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
28595 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
28596 if (ret)
28597 return -EFAULT;
28598 } else {
28599 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
28600 if (!port_has_data(port) && !port->host_connected)
28601 return 0;
28602
28603 - return fill_readbuf(port, ubuf, count, true);
28604 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
28605 }
28606
28607 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
28608 diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
28609 index eb1d864..39ee5a7 100644
28610 --- a/drivers/dma/dmatest.c
28611 +++ b/drivers/dma/dmatest.c
28612 @@ -591,7 +591,7 @@ static int dmatest_add_channel(struct dma_chan *chan)
28613 }
28614 if (dma_has_cap(DMA_PQ, dma_dev->cap_mask)) {
28615 cnt = dmatest_add_threads(dtc, DMA_PQ);
28616 - thread_count += cnt > 0 ?: 0;
28617 + thread_count += cnt > 0 ? cnt : 0;
28618 }
28619
28620 pr_info("dmatest: Started %u threads using %s\n",
28621 diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
28622 index c9eee6d..f9d5280 100644
28623 --- a/drivers/edac/amd64_edac.c
28624 +++ b/drivers/edac/amd64_edac.c
28625 @@ -2685,7 +2685,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
28626 * PCI core identifies what devices are on a system during boot, and then
28627 * inquiry this table to see if this driver is for a given device found.
28628 */
28629 -static const struct pci_device_id amd64_pci_table[] __devinitdata = {
28630 +static const struct pci_device_id amd64_pci_table[] __devinitconst = {
28631 {
28632 .vendor = PCI_VENDOR_ID_AMD,
28633 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
28634 diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
28635 index e47e73b..348e0bd 100644
28636 --- a/drivers/edac/amd76x_edac.c
28637 +++ b/drivers/edac/amd76x_edac.c
28638 @@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
28639 edac_mc_free(mci);
28640 }
28641
28642 -static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
28643 +static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
28644 {
28645 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
28646 AMD762},
28647 diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
28648 index 1af531a..3a8ff27 100644
28649 --- a/drivers/edac/e752x_edac.c
28650 +++ b/drivers/edac/e752x_edac.c
28651 @@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
28652 edac_mc_free(mci);
28653 }
28654
28655 -static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
28656 +static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
28657 {
28658 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
28659 E7520},
28660 diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
28661 index 6ffb6d2..383d8d7 100644
28662 --- a/drivers/edac/e7xxx_edac.c
28663 +++ b/drivers/edac/e7xxx_edac.c
28664 @@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
28665 edac_mc_free(mci);
28666 }
28667
28668 -static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
28669 +static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
28670 {
28671 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
28672 E7205},
28673 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
28674 index 495198a..ac08c85 100644
28675 --- a/drivers/edac/edac_pci_sysfs.c
28676 +++ b/drivers/edac/edac_pci_sysfs.c
28677 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
28678 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
28679 static int edac_pci_poll_msec = 1000; /* one second workq period */
28680
28681 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
28682 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
28683 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
28684 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
28685
28686 static struct kobject *edac_pci_top_main_kobj;
28687 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
28688 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28689 edac_printk(KERN_CRIT, EDAC_PCI,
28690 "Signaled System Error on %s\n",
28691 pci_name(dev));
28692 - atomic_inc(&pci_nonparity_count);
28693 + atomic_inc_unchecked(&pci_nonparity_count);
28694 }
28695
28696 if (status & (PCI_STATUS_PARITY)) {
28697 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28698 "Master Data Parity Error on %s\n",
28699 pci_name(dev));
28700
28701 - atomic_inc(&pci_parity_count);
28702 + atomic_inc_unchecked(&pci_parity_count);
28703 }
28704
28705 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28706 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28707 "Detected Parity Error on %s\n",
28708 pci_name(dev));
28709
28710 - atomic_inc(&pci_parity_count);
28711 + atomic_inc_unchecked(&pci_parity_count);
28712 }
28713 }
28714
28715 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28716 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
28717 "Signaled System Error on %s\n",
28718 pci_name(dev));
28719 - atomic_inc(&pci_nonparity_count);
28720 + atomic_inc_unchecked(&pci_nonparity_count);
28721 }
28722
28723 if (status & (PCI_STATUS_PARITY)) {
28724 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28725 "Master Data Parity Error on "
28726 "%s\n", pci_name(dev));
28727
28728 - atomic_inc(&pci_parity_count);
28729 + atomic_inc_unchecked(&pci_parity_count);
28730 }
28731
28732 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28733 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28734 "Detected Parity Error on %s\n",
28735 pci_name(dev));
28736
28737 - atomic_inc(&pci_parity_count);
28738 + atomic_inc_unchecked(&pci_parity_count);
28739 }
28740 }
28741 }
28742 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
28743 if (!check_pci_errors)
28744 return;
28745
28746 - before_count = atomic_read(&pci_parity_count);
28747 + before_count = atomic_read_unchecked(&pci_parity_count);
28748
28749 /* scan all PCI devices looking for a Parity Error on devices and
28750 * bridges.
28751 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
28752 /* Only if operator has selected panic on PCI Error */
28753 if (edac_pci_get_panic_on_pe()) {
28754 /* If the count is different 'after' from 'before' */
28755 - if (before_count != atomic_read(&pci_parity_count))
28756 + if (before_count != atomic_read_unchecked(&pci_parity_count))
28757 panic("EDAC: PCI Parity Error");
28758 }
28759 }
28760 diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
28761 index c0510b3..6e2a954 100644
28762 --- a/drivers/edac/i3000_edac.c
28763 +++ b/drivers/edac/i3000_edac.c
28764 @@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
28765 edac_mc_free(mci);
28766 }
28767
28768 -static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
28769 +static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
28770 {
28771 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
28772 I3000},
28773 diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
28774 index aa08497..7e6822a 100644
28775 --- a/drivers/edac/i3200_edac.c
28776 +++ b/drivers/edac/i3200_edac.c
28777 @@ -456,7 +456,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
28778 edac_mc_free(mci);
28779 }
28780
28781 -static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
28782 +static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
28783 {
28784 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
28785 I3200},
28786 diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
28787 index 4dc3ac2..67d05a6 100644
28788 --- a/drivers/edac/i5000_edac.c
28789 +++ b/drivers/edac/i5000_edac.c
28790 @@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
28791 *
28792 * The "E500P" device is the first device supported.
28793 */
28794 -static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
28795 +static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
28796 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
28797 .driver_data = I5000P},
28798
28799 diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
28800 index bcbdeec..9886d16 100644
28801 --- a/drivers/edac/i5100_edac.c
28802 +++ b/drivers/edac/i5100_edac.c
28803 @@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
28804 edac_mc_free(mci);
28805 }
28806
28807 -static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
28808 +static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
28809 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
28810 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
28811 { 0, }
28812 diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
28813 index 74d6ec34..baff517 100644
28814 --- a/drivers/edac/i5400_edac.c
28815 +++ b/drivers/edac/i5400_edac.c
28816 @@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
28817 *
28818 * The "E500P" device is the first device supported.
28819 */
28820 -static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
28821 +static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
28822 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
28823 {0,} /* 0 terminated list. */
28824 };
28825 diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
28826 index 6104dba..e7ea8e1 100644
28827 --- a/drivers/edac/i7300_edac.c
28828 +++ b/drivers/edac/i7300_edac.c
28829 @@ -1192,7 +1192,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
28830 *
28831 * Has only 8086:360c PCI ID
28832 */
28833 -static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
28834 +static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
28835 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
28836 {0,} /* 0 terminated list. */
28837 };
28838 diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
28839 index 70ad892..178943c 100644
28840 --- a/drivers/edac/i7core_edac.c
28841 +++ b/drivers/edac/i7core_edac.c
28842 @@ -391,7 +391,7 @@ static const struct pci_id_table pci_dev_table[] = {
28843 /*
28844 * pci_device_id table for which devices we are looking for
28845 */
28846 -static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
28847 +static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
28848 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
28849 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
28850 {0,} /* 0 terminated list. */
28851 diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
28852 index 4329d39..f3022ef 100644
28853 --- a/drivers/edac/i82443bxgx_edac.c
28854 +++ b/drivers/edac/i82443bxgx_edac.c
28855 @@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
28856
28857 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
28858
28859 -static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
28860 +static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
28861 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
28862 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
28863 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
28864 diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
28865 index 931a057..fd28340 100644
28866 --- a/drivers/edac/i82860_edac.c
28867 +++ b/drivers/edac/i82860_edac.c
28868 @@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
28869 edac_mc_free(mci);
28870 }
28871
28872 -static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
28873 +static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
28874 {
28875 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
28876 I82860},
28877 diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
28878 index 33864c6..01edc61 100644
28879 --- a/drivers/edac/i82875p_edac.c
28880 +++ b/drivers/edac/i82875p_edac.c
28881 @@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
28882 edac_mc_free(mci);
28883 }
28884
28885 -static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
28886 +static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
28887 {
28888 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
28889 I82875P},
28890 diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
28891 index a5da732..983363b 100644
28892 --- a/drivers/edac/i82975x_edac.c
28893 +++ b/drivers/edac/i82975x_edac.c
28894 @@ -604,7 +604,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
28895 edac_mc_free(mci);
28896 }
28897
28898 -static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
28899 +static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
28900 {
28901 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
28902 I82975X
28903 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
28904 index 0106747..0b40417 100644
28905 --- a/drivers/edac/mce_amd.h
28906 +++ b/drivers/edac/mce_amd.h
28907 @@ -83,7 +83,7 @@ struct amd_decoder_ops {
28908 bool (*dc_mce)(u16, u8);
28909 bool (*ic_mce)(u16, u8);
28910 bool (*nb_mce)(u16, u8);
28911 -};
28912 +} __no_const;
28913
28914 void amd_report_gart_errors(bool);
28915 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
28916 diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
28917 index b153674..ad2ba9b 100644
28918 --- a/drivers/edac/r82600_edac.c
28919 +++ b/drivers/edac/r82600_edac.c
28920 @@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
28921 edac_mc_free(mci);
28922 }
28923
28924 -static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
28925 +static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
28926 {
28927 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
28928 },
28929 diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
28930 index 7a402bf..af0b211 100644
28931 --- a/drivers/edac/sb_edac.c
28932 +++ b/drivers/edac/sb_edac.c
28933 @@ -367,7 +367,7 @@ static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
28934 /*
28935 * pci_device_id table for which devices we are looking for
28936 */
28937 -static const struct pci_device_id sbridge_pci_tbl[] __devinitdata = {
28938 +static const struct pci_device_id sbridge_pci_tbl[] __devinitconst = {
28939 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
28940 {0,} /* 0 terminated list. */
28941 };
28942 diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
28943 index b6f47de..c5acf3a 100644
28944 --- a/drivers/edac/x38_edac.c
28945 +++ b/drivers/edac/x38_edac.c
28946 @@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
28947 edac_mc_free(mci);
28948 }
28949
28950 -static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
28951 +static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
28952 {
28953 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
28954 X38},
28955 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
28956 index 85661b0..c784559a 100644
28957 --- a/drivers/firewire/core-card.c
28958 +++ b/drivers/firewire/core-card.c
28959 @@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
28960
28961 void fw_core_remove_card(struct fw_card *card)
28962 {
28963 - struct fw_card_driver dummy_driver = dummy_driver_template;
28964 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
28965
28966 card->driver->update_phy_reg(card, 4,
28967 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
28968 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
28969 index 4799393..37bd3ab 100644
28970 --- a/drivers/firewire/core-cdev.c
28971 +++ b/drivers/firewire/core-cdev.c
28972 @@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
28973 int ret;
28974
28975 if ((request->channels == 0 && request->bandwidth == 0) ||
28976 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
28977 - request->bandwidth < 0)
28978 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
28979 return -EINVAL;
28980
28981 r = kmalloc(sizeof(*r), GFP_KERNEL);
28982 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
28983 index 855ab3f..11f4bbd 100644
28984 --- a/drivers/firewire/core-transaction.c
28985 +++ b/drivers/firewire/core-transaction.c
28986 @@ -37,6 +37,7 @@
28987 #include <linux/timer.h>
28988 #include <linux/types.h>
28989 #include <linux/workqueue.h>
28990 +#include <linux/sched.h>
28991
28992 #include <asm/byteorder.h>
28993
28994 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
28995 index b45be57..5fad18b 100644
28996 --- a/drivers/firewire/core.h
28997 +++ b/drivers/firewire/core.h
28998 @@ -101,6 +101,7 @@ struct fw_card_driver {
28999
29000 int (*stop_iso)(struct fw_iso_context *ctx);
29001 };
29002 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
29003
29004 void fw_card_initialize(struct fw_card *card,
29005 const struct fw_card_driver *driver, struct device *device);
29006 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
29007 index 153980b..4b4d046 100644
29008 --- a/drivers/firmware/dmi_scan.c
29009 +++ b/drivers/firmware/dmi_scan.c
29010 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
29011 }
29012 }
29013 else {
29014 - /*
29015 - * no iounmap() for that ioremap(); it would be a no-op, but
29016 - * it's so early in setup that sucker gets confused into doing
29017 - * what it shouldn't if we actually call it.
29018 - */
29019 p = dmi_ioremap(0xF0000, 0x10000);
29020 if (p == NULL)
29021 goto error;
29022 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
29023 if (buf == NULL)
29024 return -1;
29025
29026 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
29027 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
29028
29029 iounmap(buf);
29030 return 0;
29031 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
29032 index 98723cb..10ca85b 100644
29033 --- a/drivers/gpio/gpio-vr41xx.c
29034 +++ b/drivers/gpio/gpio-vr41xx.c
29035 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
29036 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
29037 maskl, pendl, maskh, pendh);
29038
29039 - atomic_inc(&irq_err_count);
29040 + atomic_inc_unchecked(&irq_err_count);
29041
29042 return -EINVAL;
29043 }
29044 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
29045 index 8323fc3..5c1d755 100644
29046 --- a/drivers/gpu/drm/drm_crtc.c
29047 +++ b/drivers/gpu/drm/drm_crtc.c
29048 @@ -1379,7 +1379,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
29049 */
29050 if ((out_resp->count_modes >= mode_count) && mode_count) {
29051 copied = 0;
29052 - mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
29053 + mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
29054 list_for_each_entry(mode, &connector->modes, head) {
29055 drm_crtc_convert_to_umode(&u_mode, mode);
29056 if (copy_to_user(mode_ptr + copied,
29057 @@ -1394,8 +1394,8 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
29058
29059 if ((out_resp->count_props >= props_count) && props_count) {
29060 copied = 0;
29061 - prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
29062 - prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
29063 + prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr);
29064 + prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr);
29065 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
29066 if (connector->property_ids[i] != 0) {
29067 if (put_user(connector->property_ids[i],
29068 @@ -1417,7 +1417,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
29069
29070 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
29071 copied = 0;
29072 - encoder_ptr = (uint32_t *)(unsigned long)(out_resp->encoders_ptr);
29073 + encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
29074 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
29075 if (connector->encoder_ids[i] != 0) {
29076 if (put_user(connector->encoder_ids[i],
29077 @@ -1576,7 +1576,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
29078 }
29079
29080 for (i = 0; i < crtc_req->count_connectors; i++) {
29081 - set_connectors_ptr = (uint32_t *)(unsigned long)crtc_req->set_connectors_ptr;
29082 + set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
29083 if (get_user(out_id, &set_connectors_ptr[i])) {
29084 ret = -EFAULT;
29085 goto out;
29086 @@ -1857,7 +1857,7 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
29087 fb = obj_to_fb(obj);
29088
29089 num_clips = r->num_clips;
29090 - clips_ptr = (struct drm_clip_rect *)(unsigned long)r->clips_ptr;
29091 + clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr;
29092
29093 if (!num_clips != !clips_ptr) {
29094 ret = -EINVAL;
29095 @@ -2283,7 +2283,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
29096 out_resp->flags = property->flags;
29097
29098 if ((out_resp->count_values >= value_count) && value_count) {
29099 - values_ptr = (uint64_t *)(unsigned long)out_resp->values_ptr;
29100 + values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
29101 for (i = 0; i < value_count; i++) {
29102 if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
29103 ret = -EFAULT;
29104 @@ -2296,7 +2296,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
29105 if (property->flags & DRM_MODE_PROP_ENUM) {
29106 if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
29107 copied = 0;
29108 - enum_ptr = (struct drm_mode_property_enum *)(unsigned long)out_resp->enum_blob_ptr;
29109 + enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
29110 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
29111
29112 if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
29113 @@ -2319,7 +2319,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
29114 if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
29115 copied = 0;
29116 blob_id_ptr = (uint32_t *)(unsigned long)out_resp->enum_blob_ptr;
29117 - blob_length_ptr = (uint32_t *)(unsigned long)out_resp->values_ptr;
29118 + blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr;
29119
29120 list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
29121 if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
29122 @@ -2380,7 +2380,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
29123 struct drm_mode_get_blob *out_resp = data;
29124 struct drm_property_blob *blob;
29125 int ret = 0;
29126 - void *blob_ptr;
29127 + void __user *blob_ptr;
29128
29129 if (!drm_core_check_feature(dev, DRIVER_MODESET))
29130 return -EINVAL;
29131 @@ -2394,7 +2394,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
29132 blob = obj_to_blob(obj);
29133
29134 if (out_resp->length == blob->length) {
29135 - blob_ptr = (void *)(unsigned long)out_resp->data;
29136 + blob_ptr = (void __user *)(unsigned long)out_resp->data;
29137 if (copy_to_user(blob_ptr, blob->data, blob->length)){
29138 ret = -EFAULT;
29139 goto done;
29140 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
29141 index d2619d7..bd6bd00 100644
29142 --- a/drivers/gpu/drm/drm_crtc_helper.c
29143 +++ b/drivers/gpu/drm/drm_crtc_helper.c
29144 @@ -279,7 +279,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
29145 struct drm_crtc *tmp;
29146 int crtc_mask = 1;
29147
29148 - WARN(!crtc, "checking null crtc?\n");
29149 + BUG_ON(!crtc);
29150
29151 dev = crtc->dev;
29152
29153 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
29154 index 40c187c..5746164 100644
29155 --- a/drivers/gpu/drm/drm_drv.c
29156 +++ b/drivers/gpu/drm/drm_drv.c
29157 @@ -308,7 +308,7 @@ module_exit(drm_core_exit);
29158 /**
29159 * Copy and IOCTL return string to user space
29160 */
29161 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
29162 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
29163 {
29164 int len;
29165
29166 @@ -387,7 +387,7 @@ long drm_ioctl(struct file *filp,
29167
29168 dev = file_priv->minor->dev;
29169 atomic_inc(&dev->ioctl_count);
29170 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
29171 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
29172 ++file_priv->ioctl_count;
29173
29174 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
29175 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
29176 index 828bf65..cdaa0e9 100644
29177 --- a/drivers/gpu/drm/drm_fops.c
29178 +++ b/drivers/gpu/drm/drm_fops.c
29179 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
29180 }
29181
29182 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
29183 - atomic_set(&dev->counts[i], 0);
29184 + atomic_set_unchecked(&dev->counts[i], 0);
29185
29186 dev->sigdata.lock = NULL;
29187
29188 @@ -135,8 +135,8 @@ int drm_open(struct inode *inode, struct file *filp)
29189
29190 retcode = drm_open_helper(inode, filp, dev);
29191 if (!retcode) {
29192 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
29193 - if (!dev->open_count++)
29194 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
29195 + if (local_inc_return(&dev->open_count) == 1)
29196 retcode = drm_setup(dev);
29197 }
29198 if (!retcode) {
29199 @@ -473,7 +473,7 @@ int drm_release(struct inode *inode, struct file *filp)
29200
29201 mutex_lock(&drm_global_mutex);
29202
29203 - DRM_DEBUG("open_count = %d\n", dev->open_count);
29204 + DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
29205
29206 if (dev->driver->preclose)
29207 dev->driver->preclose(dev, file_priv);
29208 @@ -485,7 +485,7 @@ int drm_release(struct inode *inode, struct file *filp)
29209 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
29210 task_pid_nr(current),
29211 (long)old_encode_dev(file_priv->minor->device),
29212 - dev->open_count);
29213 + local_read(&dev->open_count));
29214
29215 /* Release any auth tokens that might point to this file_priv,
29216 (do that under the drm_global_mutex) */
29217 @@ -571,8 +571,8 @@ int drm_release(struct inode *inode, struct file *filp)
29218 * End inline drm_release
29219 */
29220
29221 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
29222 - if (!--dev->open_count) {
29223 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
29224 + if (local_dec_and_test(&dev->open_count)) {
29225 if (atomic_read(&dev->ioctl_count)) {
29226 DRM_ERROR("Device busy: %d\n",
29227 atomic_read(&dev->ioctl_count));
29228 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
29229 index c87dc96..326055d 100644
29230 --- a/drivers/gpu/drm/drm_global.c
29231 +++ b/drivers/gpu/drm/drm_global.c
29232 @@ -36,7 +36,7 @@
29233 struct drm_global_item {
29234 struct mutex mutex;
29235 void *object;
29236 - int refcount;
29237 + atomic_t refcount;
29238 };
29239
29240 static struct drm_global_item glob[DRM_GLOBAL_NUM];
29241 @@ -49,7 +49,7 @@ void drm_global_init(void)
29242 struct drm_global_item *item = &glob[i];
29243 mutex_init(&item->mutex);
29244 item->object = NULL;
29245 - item->refcount = 0;
29246 + atomic_set(&item->refcount, 0);
29247 }
29248 }
29249
29250 @@ -59,7 +59,7 @@ void drm_global_release(void)
29251 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
29252 struct drm_global_item *item = &glob[i];
29253 BUG_ON(item->object != NULL);
29254 - BUG_ON(item->refcount != 0);
29255 + BUG_ON(atomic_read(&item->refcount) != 0);
29256 }
29257 }
29258
29259 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
29260 void *object;
29261
29262 mutex_lock(&item->mutex);
29263 - if (item->refcount == 0) {
29264 + if (atomic_read(&item->refcount) == 0) {
29265 item->object = kzalloc(ref->size, GFP_KERNEL);
29266 if (unlikely(item->object == NULL)) {
29267 ret = -ENOMEM;
29268 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
29269 goto out_err;
29270
29271 }
29272 - ++item->refcount;
29273 + atomic_inc(&item->refcount);
29274 ref->object = item->object;
29275 object = item->object;
29276 mutex_unlock(&item->mutex);
29277 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
29278 struct drm_global_item *item = &glob[ref->global_type];
29279
29280 mutex_lock(&item->mutex);
29281 - BUG_ON(item->refcount == 0);
29282 + BUG_ON(atomic_read(&item->refcount) == 0);
29283 BUG_ON(ref->object != item->object);
29284 - if (--item->refcount == 0) {
29285 + if (atomic_dec_and_test(&item->refcount)) {
29286 ref->release(ref);
29287 item->object = NULL;
29288 }
29289 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
29290 index ab1162d..42587b2 100644
29291 --- a/drivers/gpu/drm/drm_info.c
29292 +++ b/drivers/gpu/drm/drm_info.c
29293 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
29294 struct drm_local_map *map;
29295 struct drm_map_list *r_list;
29296
29297 - /* Hardcoded from _DRM_FRAME_BUFFER,
29298 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
29299 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
29300 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
29301 + static const char * const types[] = {
29302 + [_DRM_FRAME_BUFFER] = "FB",
29303 + [_DRM_REGISTERS] = "REG",
29304 + [_DRM_SHM] = "SHM",
29305 + [_DRM_AGP] = "AGP",
29306 + [_DRM_SCATTER_GATHER] = "SG",
29307 + [_DRM_CONSISTENT] = "PCI",
29308 + [_DRM_GEM] = "GEM" };
29309 const char *type;
29310 int i;
29311
29312 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
29313 map = r_list->map;
29314 if (!map)
29315 continue;
29316 - if (map->type < 0 || map->type > 5)
29317 + if (map->type >= ARRAY_SIZE(types))
29318 type = "??";
29319 else
29320 type = types[map->type];
29321 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
29322 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
29323 vma->vm_flags & VM_LOCKED ? 'l' : '-',
29324 vma->vm_flags & VM_IO ? 'i' : '-',
29325 +#ifdef CONFIG_GRKERNSEC_HIDESYM
29326 + 0);
29327 +#else
29328 vma->vm_pgoff);
29329 +#endif
29330
29331 #if defined(__i386__)
29332 pgprot = pgprot_val(vma->vm_page_prot);
29333 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
29334 index ddd70db..40321e6 100644
29335 --- a/drivers/gpu/drm/drm_ioc32.c
29336 +++ b/drivers/gpu/drm/drm_ioc32.c
29337 @@ -456,7 +456,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
29338 request = compat_alloc_user_space(nbytes);
29339 if (!access_ok(VERIFY_WRITE, request, nbytes))
29340 return -EFAULT;
29341 - list = (struct drm_buf_desc *) (request + 1);
29342 + list = (struct drm_buf_desc __user *) (request + 1);
29343
29344 if (__put_user(count, &request->count)
29345 || __put_user(list, &request->list))
29346 @@ -517,7 +517,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
29347 request = compat_alloc_user_space(nbytes);
29348 if (!access_ok(VERIFY_WRITE, request, nbytes))
29349 return -EFAULT;
29350 - list = (struct drm_buf_pub *) (request + 1);
29351 + list = (struct drm_buf_pub __user *) (request + 1);
29352
29353 if (__put_user(count, &request->count)
29354 || __put_user(list, &request->list))
29355 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
29356 index 904d7e9..ab88581 100644
29357 --- a/drivers/gpu/drm/drm_ioctl.c
29358 +++ b/drivers/gpu/drm/drm_ioctl.c
29359 @@ -256,7 +256,7 @@ int drm_getstats(struct drm_device *dev, void *data,
29360 stats->data[i].value =
29361 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
29362 else
29363 - stats->data[i].value = atomic_read(&dev->counts[i]);
29364 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
29365 stats->data[i].type = dev->types[i];
29366 }
29367
29368 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
29369 index 632ae24..244cf4a 100644
29370 --- a/drivers/gpu/drm/drm_lock.c
29371 +++ b/drivers/gpu/drm/drm_lock.c
29372 @@ -89,7 +89,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
29373 if (drm_lock_take(&master->lock, lock->context)) {
29374 master->lock.file_priv = file_priv;
29375 master->lock.lock_time = jiffies;
29376 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
29377 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
29378 break; /* Got lock */
29379 }
29380
29381 @@ -160,7 +160,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
29382 return -EINVAL;
29383 }
29384
29385 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
29386 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
29387
29388 if (drm_lock_free(&master->lock, lock->context)) {
29389 /* FIXME: Should really bail out here. */
29390 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
29391 index 8f371e8..9f85d52 100644
29392 --- a/drivers/gpu/drm/i810/i810_dma.c
29393 +++ b/drivers/gpu/drm/i810/i810_dma.c
29394 @@ -950,8 +950,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
29395 dma->buflist[vertex->idx],
29396 vertex->discard, vertex->used);
29397
29398 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
29399 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
29400 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
29401 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
29402 sarea_priv->last_enqueue = dev_priv->counter - 1;
29403 sarea_priv->last_dispatch = (int)hw_status[5];
29404
29405 @@ -1111,8 +1111,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
29406 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
29407 mc->last_render);
29408
29409 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
29410 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
29411 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
29412 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
29413 sarea_priv->last_enqueue = dev_priv->counter - 1;
29414 sarea_priv->last_dispatch = (int)hw_status[5];
29415
29416 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
29417 index c9339f4..f5e1b9d 100644
29418 --- a/drivers/gpu/drm/i810/i810_drv.h
29419 +++ b/drivers/gpu/drm/i810/i810_drv.h
29420 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
29421 int page_flipping;
29422
29423 wait_queue_head_t irq_queue;
29424 - atomic_t irq_received;
29425 - atomic_t irq_emitted;
29426 + atomic_unchecked_t irq_received;
29427 + atomic_unchecked_t irq_emitted;
29428
29429 int front_offset;
29430 } drm_i810_private_t;
29431 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
29432 index b2e3c97..58cf079 100644
29433 --- a/drivers/gpu/drm/i915/i915_debugfs.c
29434 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
29435 @@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
29436 I915_READ(GTIMR));
29437 }
29438 seq_printf(m, "Interrupts received: %d\n",
29439 - atomic_read(&dev_priv->irq_received));
29440 + atomic_read_unchecked(&dev_priv->irq_received));
29441 for (i = 0; i < I915_NUM_RINGS; i++) {
29442 if (IS_GEN6(dev) || IS_GEN7(dev)) {
29443 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
29444 @@ -1232,7 +1232,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
29445 return ret;
29446
29447 if (opregion->header)
29448 - seq_write(m, opregion->header, OPREGION_SIZE);
29449 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
29450
29451 mutex_unlock(&dev->struct_mutex);
29452
29453 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
29454 index c4da951..3c59c5c 100644
29455 --- a/drivers/gpu/drm/i915/i915_dma.c
29456 +++ b/drivers/gpu/drm/i915/i915_dma.c
29457 @@ -1172,7 +1172,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
29458 bool can_switch;
29459
29460 spin_lock(&dev->count_lock);
29461 - can_switch = (dev->open_count == 0);
29462 + can_switch = (local_read(&dev->open_count) == 0);
29463 spin_unlock(&dev->count_lock);
29464 return can_switch;
29465 }
29466 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
29467 index ae294a0..1755461 100644
29468 --- a/drivers/gpu/drm/i915/i915_drv.h
29469 +++ b/drivers/gpu/drm/i915/i915_drv.h
29470 @@ -229,7 +229,7 @@ struct drm_i915_display_funcs {
29471 /* render clock increase/decrease */
29472 /* display clock increase/decrease */
29473 /* pll clock increase/decrease */
29474 -};
29475 +} __no_const;
29476
29477 struct intel_device_info {
29478 u8 gen;
29479 @@ -318,7 +318,7 @@ typedef struct drm_i915_private {
29480 int current_page;
29481 int page_flipping;
29482
29483 - atomic_t irq_received;
29484 + atomic_unchecked_t irq_received;
29485
29486 /* protects the irq masks */
29487 spinlock_t irq_lock;
29488 @@ -893,7 +893,7 @@ struct drm_i915_gem_object {
29489 * will be page flipped away on the next vblank. When it
29490 * reaches 0, dev_priv->pending_flip_queue will be woken up.
29491 */
29492 - atomic_t pending_flip;
29493 + atomic_unchecked_t pending_flip;
29494 };
29495
29496 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
29497 @@ -1273,7 +1273,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
29498 extern void intel_teardown_gmbus(struct drm_device *dev);
29499 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
29500 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
29501 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
29502 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
29503 {
29504 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
29505 }
29506 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
29507 index b9da890..cad1d98 100644
29508 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
29509 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
29510 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
29511 i915_gem_clflush_object(obj);
29512
29513 if (obj->base.pending_write_domain)
29514 - cd->flips |= atomic_read(&obj->pending_flip);
29515 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
29516
29517 /* The actual obj->write_domain will be updated with
29518 * pending_write_domain after we emit the accumulated flush for all
29519 @@ -882,9 +882,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
29520
29521 static int
29522 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
29523 - int count)
29524 + unsigned int count)
29525 {
29526 - int i;
29527 + unsigned int i;
29528
29529 for (i = 0; i < count; i++) {
29530 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
29531 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
29532 index d47a53b..61154c2 100644
29533 --- a/drivers/gpu/drm/i915/i915_irq.c
29534 +++ b/drivers/gpu/drm/i915/i915_irq.c
29535 @@ -475,7 +475,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
29536 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
29537 struct drm_i915_master_private *master_priv;
29538
29539 - atomic_inc(&dev_priv->irq_received);
29540 + atomic_inc_unchecked(&dev_priv->irq_received);
29541
29542 /* disable master interrupt before clearing iir */
29543 de_ier = I915_READ(DEIER);
29544 @@ -566,7 +566,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
29545 struct drm_i915_master_private *master_priv;
29546 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
29547
29548 - atomic_inc(&dev_priv->irq_received);
29549 + atomic_inc_unchecked(&dev_priv->irq_received);
29550
29551 if (IS_GEN6(dev))
29552 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
29553 @@ -1231,7 +1231,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
29554 int ret = IRQ_NONE, pipe;
29555 bool blc_event = false;
29556
29557 - atomic_inc(&dev_priv->irq_received);
29558 + atomic_inc_unchecked(&dev_priv->irq_received);
29559
29560 iir = I915_READ(IIR);
29561
29562 @@ -1750,7 +1750,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
29563 {
29564 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
29565
29566 - atomic_set(&dev_priv->irq_received, 0);
29567 + atomic_set_unchecked(&dev_priv->irq_received, 0);
29568
29569 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
29570 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
29571 @@ -1938,7 +1938,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
29572 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
29573 int pipe;
29574
29575 - atomic_set(&dev_priv->irq_received, 0);
29576 + atomic_set_unchecked(&dev_priv->irq_received, 0);
29577
29578 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
29579 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
29580 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
29581 index daa5743..c0757a9 100644
29582 --- a/drivers/gpu/drm/i915/intel_display.c
29583 +++ b/drivers/gpu/drm/i915/intel_display.c
29584 @@ -2230,7 +2230,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
29585
29586 wait_event(dev_priv->pending_flip_queue,
29587 atomic_read(&dev_priv->mm.wedged) ||
29588 - atomic_read(&obj->pending_flip) == 0);
29589 + atomic_read_unchecked(&obj->pending_flip) == 0);
29590
29591 /* Big Hammer, we also need to ensure that any pending
29592 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
29593 @@ -2851,7 +2851,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
29594 obj = to_intel_framebuffer(crtc->fb)->obj;
29595 dev_priv = crtc->dev->dev_private;
29596 wait_event(dev_priv->pending_flip_queue,
29597 - atomic_read(&obj->pending_flip) == 0);
29598 + atomic_read_unchecked(&obj->pending_flip) == 0);
29599 }
29600
29601 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
29602 @@ -6952,7 +6952,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
29603
29604 atomic_clear_mask(1 << intel_crtc->plane,
29605 &obj->pending_flip.counter);
29606 - if (atomic_read(&obj->pending_flip) == 0)
29607 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
29608 wake_up(&dev_priv->pending_flip_queue);
29609
29610 schedule_work(&work->work);
29611 @@ -7242,7 +7242,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
29612 /* Block clients from rendering to the new back buffer until
29613 * the flip occurs and the object is no longer visible.
29614 */
29615 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29616 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29617
29618 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
29619 if (ret)
29620 @@ -7256,7 +7256,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
29621 return 0;
29622
29623 cleanup_pending:
29624 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29625 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29626 drm_gem_object_unreference(&work->old_fb_obj->base);
29627 drm_gem_object_unreference(&obj->base);
29628 mutex_unlock(&dev->struct_mutex);
29629 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
29630 index 54558a0..2d97005 100644
29631 --- a/drivers/gpu/drm/mga/mga_drv.h
29632 +++ b/drivers/gpu/drm/mga/mga_drv.h
29633 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
29634 u32 clear_cmd;
29635 u32 maccess;
29636
29637 - atomic_t vbl_received; /**< Number of vblanks received. */
29638 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
29639 wait_queue_head_t fence_queue;
29640 - atomic_t last_fence_retired;
29641 + atomic_unchecked_t last_fence_retired;
29642 u32 next_fence_to_post;
29643
29644 unsigned int fb_cpp;
29645 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
29646 index 2581202..f230a8d9 100644
29647 --- a/drivers/gpu/drm/mga/mga_irq.c
29648 +++ b/drivers/gpu/drm/mga/mga_irq.c
29649 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
29650 if (crtc != 0)
29651 return 0;
29652
29653 - return atomic_read(&dev_priv->vbl_received);
29654 + return atomic_read_unchecked(&dev_priv->vbl_received);
29655 }
29656
29657
29658 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
29659 /* VBLANK interrupt */
29660 if (status & MGA_VLINEPEN) {
29661 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
29662 - atomic_inc(&dev_priv->vbl_received);
29663 + atomic_inc_unchecked(&dev_priv->vbl_received);
29664 drm_handle_vblank(dev, 0);
29665 handled = 1;
29666 }
29667 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
29668 if ((prim_start & ~0x03) != (prim_end & ~0x03))
29669 MGA_WRITE(MGA_PRIMEND, prim_end);
29670
29671 - atomic_inc(&dev_priv->last_fence_retired);
29672 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
29673 DRM_WAKEUP(&dev_priv->fence_queue);
29674 handled = 1;
29675 }
29676 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
29677 * using fences.
29678 */
29679 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
29680 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
29681 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
29682 - *sequence) <= (1 << 23)));
29683
29684 *sequence = cur_fence;
29685 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
29686 index 5fc201b..7b032b9 100644
29687 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
29688 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
29689 @@ -201,7 +201,7 @@ struct methods {
29690 const char desc[8];
29691 void (*loadbios)(struct drm_device *, uint8_t *);
29692 const bool rw;
29693 -};
29694 +} __do_const;
29695
29696 static struct methods shadow_methods[] = {
29697 { "PRAMIN", load_vbios_pramin, true },
29698 @@ -5474,7 +5474,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
29699 struct bit_table {
29700 const char id;
29701 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
29702 -};
29703 +} __no_const;
29704
29705 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
29706
29707 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
29708 index 4c0be3a..5757582 100644
29709 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
29710 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
29711 @@ -238,7 +238,7 @@ struct nouveau_channel {
29712 struct list_head pending;
29713 uint32_t sequence;
29714 uint32_t sequence_ack;
29715 - atomic_t last_sequence_irq;
29716 + atomic_unchecked_t last_sequence_irq;
29717 struct nouveau_vma vma;
29718 } fence;
29719
29720 @@ -319,7 +319,7 @@ struct nouveau_exec_engine {
29721 u32 handle, u16 class);
29722 void (*set_tile_region)(struct drm_device *dev, int i);
29723 void (*tlb_flush)(struct drm_device *, int engine);
29724 -};
29725 +} __no_const;
29726
29727 struct nouveau_instmem_engine {
29728 void *priv;
29729 @@ -341,13 +341,13 @@ struct nouveau_instmem_engine {
29730 struct nouveau_mc_engine {
29731 int (*init)(struct drm_device *dev);
29732 void (*takedown)(struct drm_device *dev);
29733 -};
29734 +} __no_const;
29735
29736 struct nouveau_timer_engine {
29737 int (*init)(struct drm_device *dev);
29738 void (*takedown)(struct drm_device *dev);
29739 uint64_t (*read)(struct drm_device *dev);
29740 -};
29741 +} __no_const;
29742
29743 struct nouveau_fb_engine {
29744 int num_tiles;
29745 @@ -558,7 +558,7 @@ struct nouveau_vram_engine {
29746 void (*put)(struct drm_device *, struct nouveau_mem **);
29747
29748 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
29749 -};
29750 +} __no_const;
29751
29752 struct nouveau_engine {
29753 struct nouveau_instmem_engine instmem;
29754 @@ -706,7 +706,7 @@ struct drm_nouveau_private {
29755 struct drm_global_reference mem_global_ref;
29756 struct ttm_bo_global_ref bo_global_ref;
29757 struct ttm_bo_device bdev;
29758 - atomic_t validate_sequence;
29759 + atomic_unchecked_t validate_sequence;
29760 } ttm;
29761
29762 struct {
29763 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
29764 index 2f6daae..c9d7b9e 100644
29765 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
29766 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
29767 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
29768 if (USE_REFCNT(dev))
29769 sequence = nvchan_rd32(chan, 0x48);
29770 else
29771 - sequence = atomic_read(&chan->fence.last_sequence_irq);
29772 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
29773
29774 if (chan->fence.sequence_ack == sequence)
29775 goto out;
29776 @@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
29777 return ret;
29778 }
29779
29780 - atomic_set(&chan->fence.last_sequence_irq, 0);
29781 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
29782 return 0;
29783 }
29784
29785 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
29786 index 7ce3fde..cb3ea04 100644
29787 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
29788 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
29789 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
29790 int trycnt = 0;
29791 int ret, i;
29792
29793 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
29794 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
29795 retry:
29796 if (++trycnt > 100000) {
29797 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
29798 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
29799 index d8831ab..0ba8356 100644
29800 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
29801 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
29802 @@ -542,7 +542,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
29803 bool can_switch;
29804
29805 spin_lock(&dev->count_lock);
29806 - can_switch = (dev->open_count == 0);
29807 + can_switch = (local_read(&dev->open_count) == 0);
29808 spin_unlock(&dev->count_lock);
29809 return can_switch;
29810 }
29811 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
29812 index dbdea8e..cd6eeeb 100644
29813 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
29814 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
29815 @@ -554,7 +554,7 @@ static int
29816 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
29817 u32 class, u32 mthd, u32 data)
29818 {
29819 - atomic_set(&chan->fence.last_sequence_irq, data);
29820 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
29821 return 0;
29822 }
29823
29824 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
29825 index bcac90b..53bfc76 100644
29826 --- a/drivers/gpu/drm/r128/r128_cce.c
29827 +++ b/drivers/gpu/drm/r128/r128_cce.c
29828 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
29829
29830 /* GH: Simple idle check.
29831 */
29832 - atomic_set(&dev_priv->idle_count, 0);
29833 + atomic_set_unchecked(&dev_priv->idle_count, 0);
29834
29835 /* We don't support anything other than bus-mastering ring mode,
29836 * but the ring can be in either AGP or PCI space for the ring
29837 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
29838 index 930c71b..499aded 100644
29839 --- a/drivers/gpu/drm/r128/r128_drv.h
29840 +++ b/drivers/gpu/drm/r128/r128_drv.h
29841 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
29842 int is_pci;
29843 unsigned long cce_buffers_offset;
29844
29845 - atomic_t idle_count;
29846 + atomic_unchecked_t idle_count;
29847
29848 int page_flipping;
29849 int current_page;
29850 u32 crtc_offset;
29851 u32 crtc_offset_cntl;
29852
29853 - atomic_t vbl_received;
29854 + atomic_unchecked_t vbl_received;
29855
29856 u32 color_fmt;
29857 unsigned int front_offset;
29858 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
29859 index 429d5a0..7e899ed 100644
29860 --- a/drivers/gpu/drm/r128/r128_irq.c
29861 +++ b/drivers/gpu/drm/r128/r128_irq.c
29862 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
29863 if (crtc != 0)
29864 return 0;
29865
29866 - return atomic_read(&dev_priv->vbl_received);
29867 + return atomic_read_unchecked(&dev_priv->vbl_received);
29868 }
29869
29870 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
29871 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
29872 /* VBLANK interrupt */
29873 if (status & R128_CRTC_VBLANK_INT) {
29874 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
29875 - atomic_inc(&dev_priv->vbl_received);
29876 + atomic_inc_unchecked(&dev_priv->vbl_received);
29877 drm_handle_vblank(dev, 0);
29878 return IRQ_HANDLED;
29879 }
29880 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
29881 index a9e33ce..09edd4b 100644
29882 --- a/drivers/gpu/drm/r128/r128_state.c
29883 +++ b/drivers/gpu/drm/r128/r128_state.c
29884 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
29885
29886 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
29887 {
29888 - if (atomic_read(&dev_priv->idle_count) == 0)
29889 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
29890 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
29891 else
29892 - atomic_set(&dev_priv->idle_count, 0);
29893 + atomic_set_unchecked(&dev_priv->idle_count, 0);
29894 }
29895
29896 #endif
29897 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
29898 index 5a82b6b..9e69c73 100644
29899 --- a/drivers/gpu/drm/radeon/mkregtable.c
29900 +++ b/drivers/gpu/drm/radeon/mkregtable.c
29901 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
29902 regex_t mask_rex;
29903 regmatch_t match[4];
29904 char buf[1024];
29905 - size_t end;
29906 + long end;
29907 int len;
29908 int done = 0;
29909 int r;
29910 unsigned o;
29911 struct offset *offset;
29912 char last_reg_s[10];
29913 - int last_reg;
29914 + unsigned long last_reg;
29915
29916 if (regcomp
29917 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
29918 diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c
29919 index cb1acff..8861bc5 100644
29920 --- a/drivers/gpu/drm/radeon/r600_cs.c
29921 +++ b/drivers/gpu/drm/radeon/r600_cs.c
29922 @@ -1304,6 +1304,7 @@ static int r600_check_texture_resource(struct radeon_cs_parser *p, u32 idx,
29923 h0 = G_038004_TEX_HEIGHT(word1) + 1;
29924 d0 = G_038004_TEX_DEPTH(word1);
29925 nfaces = 1;
29926 + array = 0;
29927 switch (G_038000_DIM(word0)) {
29928 case V_038000_SQ_TEX_DIM_1D:
29929 case V_038000_SQ_TEX_DIM_2D:
29930 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
29931 index 8227e76..ce0b195 100644
29932 --- a/drivers/gpu/drm/radeon/radeon.h
29933 +++ b/drivers/gpu/drm/radeon/radeon.h
29934 @@ -192,7 +192,7 @@ extern int sumo_get_temp(struct radeon_device *rdev);
29935 */
29936 struct radeon_fence_driver {
29937 uint32_t scratch_reg;
29938 - atomic_t seq;
29939 + atomic_unchecked_t seq;
29940 uint32_t last_seq;
29941 unsigned long last_jiffies;
29942 unsigned long last_timeout;
29943 @@ -530,7 +530,7 @@ struct r600_blit_cp_primitives {
29944 int x2, int y2);
29945 void (*draw_auto)(struct radeon_device *rdev);
29946 void (*set_default_state)(struct radeon_device *rdev);
29947 -};
29948 +} __no_const;
29949
29950 struct r600_blit {
29951 struct mutex mutex;
29952 @@ -954,7 +954,7 @@ struct radeon_asic {
29953 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
29954 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
29955 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
29956 -};
29957 +} __no_const;
29958
29959 /*
29960 * Asic structures
29961 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
29962 index 9231564..78b00fd 100644
29963 --- a/drivers/gpu/drm/radeon/radeon_device.c
29964 +++ b/drivers/gpu/drm/radeon/radeon_device.c
29965 @@ -687,7 +687,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
29966 bool can_switch;
29967
29968 spin_lock(&dev->count_lock);
29969 - can_switch = (dev->open_count == 0);
29970 + can_switch = (local_read(&dev->open_count) == 0);
29971 spin_unlock(&dev->count_lock);
29972 return can_switch;
29973 }
29974 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
29975 index a1b59ca..86f2d44 100644
29976 --- a/drivers/gpu/drm/radeon/radeon_drv.h
29977 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
29978 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
29979
29980 /* SW interrupt */
29981 wait_queue_head_t swi_queue;
29982 - atomic_t swi_emitted;
29983 + atomic_unchecked_t swi_emitted;
29984 int vblank_crtc;
29985 uint32_t irq_enable_reg;
29986 uint32_t r500_disp_irq_reg;
29987 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
29988 index 76ec0e9..6feb1a3 100644
29989 --- a/drivers/gpu/drm/radeon/radeon_fence.c
29990 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
29991 @@ -78,7 +78,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
29992 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
29993 return 0;
29994 }
29995 - fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
29996 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
29997 if (!rdev->cp.ready)
29998 /* FIXME: cp is not running assume everythings is done right
29999 * away
30000 @@ -373,7 +373,7 @@ int radeon_fence_driver_init(struct radeon_device *rdev)
30001 return r;
30002 }
30003 radeon_fence_write(rdev, 0);
30004 - atomic_set(&rdev->fence_drv.seq, 0);
30005 + atomic_set_unchecked(&rdev->fence_drv.seq, 0);
30006 INIT_LIST_HEAD(&rdev->fence_drv.created);
30007 INIT_LIST_HEAD(&rdev->fence_drv.emited);
30008 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
30009 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30010 index 48b7cea..342236f 100644
30011 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30012 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30013 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30014 request = compat_alloc_user_space(sizeof(*request));
30015 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30016 || __put_user(req32.param, &request->param)
30017 - || __put_user((void __user *)(unsigned long)req32.value,
30018 + || __put_user((unsigned long)req32.value,
30019 &request->value))
30020 return -EFAULT;
30021
30022 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30023 index 00da384..32f972d 100644
30024 --- a/drivers/gpu/drm/radeon/radeon_irq.c
30025 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
30026 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30027 unsigned int ret;
30028 RING_LOCALS;
30029
30030 - atomic_inc(&dev_priv->swi_emitted);
30031 - ret = atomic_read(&dev_priv->swi_emitted);
30032 + atomic_inc_unchecked(&dev_priv->swi_emitted);
30033 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30034
30035 BEGIN_RING(4);
30036 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30037 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30038 drm_radeon_private_t *dev_priv =
30039 (drm_radeon_private_t *) dev->dev_private;
30040
30041 - atomic_set(&dev_priv->swi_emitted, 0);
30042 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30043 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30044
30045 dev->max_vblank_count = 0x001fffff;
30046 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30047 index e8422ae..d22d4a8 100644
30048 --- a/drivers/gpu/drm/radeon/radeon_state.c
30049 +++ b/drivers/gpu/drm/radeon/radeon_state.c
30050 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30051 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30052 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30053
30054 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30055 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30056 sarea_priv->nbox * sizeof(depth_boxes[0])))
30057 return -EFAULT;
30058
30059 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30060 {
30061 drm_radeon_private_t *dev_priv = dev->dev_private;
30062 drm_radeon_getparam_t *param = data;
30063 - int value;
30064 + int value = 0;
30065
30066 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30067
30068 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30069 index 0b5468b..9c4b308 100644
30070 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
30071 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30072 @@ -672,8 +672,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30073 }
30074 if (unlikely(ttm_vm_ops == NULL)) {
30075 ttm_vm_ops = vma->vm_ops;
30076 - radeon_ttm_vm_ops = *ttm_vm_ops;
30077 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30078 + pax_open_kernel();
30079 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
30080 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30081 + pax_close_kernel();
30082 }
30083 vma->vm_ops = &radeon_ttm_vm_ops;
30084 return 0;
30085 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
30086 index a9049ed..501f284 100644
30087 --- a/drivers/gpu/drm/radeon/rs690.c
30088 +++ b/drivers/gpu/drm/radeon/rs690.c
30089 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
30090 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
30091 rdev->pm.sideport_bandwidth.full)
30092 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
30093 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
30094 + read_delay_latency.full = dfixed_const(800 * 1000);
30095 read_delay_latency.full = dfixed_div(read_delay_latency,
30096 rdev->pm.igp_sideport_mclk);
30097 + a.full = dfixed_const(370);
30098 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
30099 } else {
30100 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
30101 rdev->pm.k8_bandwidth.full)
30102 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30103 index 727e93d..1565650 100644
30104 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
30105 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30106 @@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
30107 static int ttm_pool_mm_shrink(struct shrinker *shrink,
30108 struct shrink_control *sc)
30109 {
30110 - static atomic_t start_pool = ATOMIC_INIT(0);
30111 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
30112 unsigned i;
30113 - unsigned pool_offset = atomic_add_return(1, &start_pool);
30114 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
30115 struct ttm_page_pool *pool;
30116 int shrink_pages = sc->nr_to_scan;
30117
30118 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
30119 index 9cf87d9..2000b7d 100644
30120 --- a/drivers/gpu/drm/via/via_drv.h
30121 +++ b/drivers/gpu/drm/via/via_drv.h
30122 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
30123 typedef uint32_t maskarray_t[5];
30124
30125 typedef struct drm_via_irq {
30126 - atomic_t irq_received;
30127 + atomic_unchecked_t irq_received;
30128 uint32_t pending_mask;
30129 uint32_t enable_mask;
30130 wait_queue_head_t irq_queue;
30131 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
30132 struct timeval last_vblank;
30133 int last_vblank_valid;
30134 unsigned usec_per_vblank;
30135 - atomic_t vbl_received;
30136 + atomic_unchecked_t vbl_received;
30137 drm_via_state_t hc_state;
30138 char pci_buf[VIA_PCI_BUF_SIZE];
30139 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
30140 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
30141 index d391f48..10c8ca3 100644
30142 --- a/drivers/gpu/drm/via/via_irq.c
30143 +++ b/drivers/gpu/drm/via/via_irq.c
30144 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
30145 if (crtc != 0)
30146 return 0;
30147
30148 - return atomic_read(&dev_priv->vbl_received);
30149 + return atomic_read_unchecked(&dev_priv->vbl_received);
30150 }
30151
30152 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30153 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30154
30155 status = VIA_READ(VIA_REG_INTERRUPT);
30156 if (status & VIA_IRQ_VBLANK_PENDING) {
30157 - atomic_inc(&dev_priv->vbl_received);
30158 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
30159 + atomic_inc_unchecked(&dev_priv->vbl_received);
30160 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
30161 do_gettimeofday(&cur_vblank);
30162 if (dev_priv->last_vblank_valid) {
30163 dev_priv->usec_per_vblank =
30164 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30165 dev_priv->last_vblank = cur_vblank;
30166 dev_priv->last_vblank_valid = 1;
30167 }
30168 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
30169 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
30170 DRM_DEBUG("US per vblank is: %u\n",
30171 dev_priv->usec_per_vblank);
30172 }
30173 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30174
30175 for (i = 0; i < dev_priv->num_irqs; ++i) {
30176 if (status & cur_irq->pending_mask) {
30177 - atomic_inc(&cur_irq->irq_received);
30178 + atomic_inc_unchecked(&cur_irq->irq_received);
30179 DRM_WAKEUP(&cur_irq->irq_queue);
30180 handled = 1;
30181 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
30182 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
30183 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
30184 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
30185 masks[irq][4]));
30186 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
30187 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
30188 } else {
30189 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
30190 (((cur_irq_sequence =
30191 - atomic_read(&cur_irq->irq_received)) -
30192 + atomic_read_unchecked(&cur_irq->irq_received)) -
30193 *sequence) <= (1 << 23)));
30194 }
30195 *sequence = cur_irq_sequence;
30196 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
30197 }
30198
30199 for (i = 0; i < dev_priv->num_irqs; ++i) {
30200 - atomic_set(&cur_irq->irq_received, 0);
30201 + atomic_set_unchecked(&cur_irq->irq_received, 0);
30202 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
30203 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
30204 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
30205 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
30206 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
30207 case VIA_IRQ_RELATIVE:
30208 irqwait->request.sequence +=
30209 - atomic_read(&cur_irq->irq_received);
30210 + atomic_read_unchecked(&cur_irq->irq_received);
30211 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
30212 case VIA_IRQ_ABSOLUTE:
30213 break;
30214 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
30215 index dc27970..f18b008 100644
30216 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
30217 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
30218 @@ -260,7 +260,7 @@ struct vmw_private {
30219 * Fencing and IRQs.
30220 */
30221
30222 - atomic_t marker_seq;
30223 + atomic_unchecked_t marker_seq;
30224 wait_queue_head_t fence_queue;
30225 wait_queue_head_t fifo_queue;
30226 int fence_queue_waiters; /* Protected by hw_mutex */
30227 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
30228 index a0c2f12..68ae6cb 100644
30229 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
30230 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
30231 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
30232 (unsigned int) min,
30233 (unsigned int) fifo->capabilities);
30234
30235 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
30236 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
30237 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
30238 vmw_marker_queue_init(&fifo->marker_queue);
30239 return vmw_fifo_send_fence(dev_priv, &dummy);
30240 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
30241 if (reserveable)
30242 iowrite32(bytes, fifo_mem +
30243 SVGA_FIFO_RESERVED);
30244 - return fifo_mem + (next_cmd >> 2);
30245 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
30246 } else {
30247 need_bounce = true;
30248 }
30249 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
30250
30251 fm = vmw_fifo_reserve(dev_priv, bytes);
30252 if (unlikely(fm == NULL)) {
30253 - *seqno = atomic_read(&dev_priv->marker_seq);
30254 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
30255 ret = -ENOMEM;
30256 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
30257 false, 3*HZ);
30258 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
30259 }
30260
30261 do {
30262 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
30263 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
30264 } while (*seqno == 0);
30265
30266 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
30267 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
30268 index cabc95f..14b3d77 100644
30269 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
30270 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
30271 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
30272 * emitted. Then the fence is stale and signaled.
30273 */
30274
30275 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
30276 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
30277 > VMW_FENCE_WRAP);
30278
30279 return ret;
30280 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
30281
30282 if (fifo_idle)
30283 down_read(&fifo_state->rwsem);
30284 - signal_seq = atomic_read(&dev_priv->marker_seq);
30285 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
30286 ret = 0;
30287
30288 for (;;) {
30289 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
30290 index 8a8725c..afed796 100644
30291 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
30292 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
30293 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
30294 while (!vmw_lag_lt(queue, us)) {
30295 spin_lock(&queue->lock);
30296 if (list_empty(&queue->head))
30297 - seqno = atomic_read(&dev_priv->marker_seq);
30298 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
30299 else {
30300 marker = list_first_entry(&queue->head,
30301 struct vmw_marker, head);
30302 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
30303 index bb656d8..4169fca 100644
30304 --- a/drivers/hid/hid-core.c
30305 +++ b/drivers/hid/hid-core.c
30306 @@ -2012,7 +2012,7 @@ static bool hid_ignore(struct hid_device *hdev)
30307
30308 int hid_add_device(struct hid_device *hdev)
30309 {
30310 - static atomic_t id = ATOMIC_INIT(0);
30311 + static atomic_unchecked_t id = ATOMIC_INIT(0);
30312 int ret;
30313
30314 if (WARN_ON(hdev->status & HID_STAT_ADDED))
30315 @@ -2027,7 +2027,7 @@ int hid_add_device(struct hid_device *hdev)
30316 /* XXX hack, any other cleaner solution after the driver core
30317 * is converted to allow more than 20 bytes as the device name? */
30318 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
30319 - hdev->vendor, hdev->product, atomic_inc_return(&id));
30320 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
30321
30322 hid_debug_register(hdev, dev_name(&hdev->dev));
30323 ret = device_add(&hdev->dev);
30324 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
30325 index 4ef02b2..8a96831 100644
30326 --- a/drivers/hid/usbhid/hiddev.c
30327 +++ b/drivers/hid/usbhid/hiddev.c
30328 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
30329 break;
30330
30331 case HIDIOCAPPLICATION:
30332 - if (arg < 0 || arg >= hid->maxapplication)
30333 + if (arg >= hid->maxapplication)
30334 break;
30335
30336 for (i = 0; i < hid->maxcollection; i++)
30337 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
30338 index 4065374..10ed7dc 100644
30339 --- a/drivers/hv/channel.c
30340 +++ b/drivers/hv/channel.c
30341 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
30342 int ret = 0;
30343 int t;
30344
30345 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
30346 - atomic_inc(&vmbus_connection.next_gpadl_handle);
30347 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
30348 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
30349
30350 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
30351 if (ret)
30352 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
30353 index 0fb100e..baf87e5 100644
30354 --- a/drivers/hv/hv.c
30355 +++ b/drivers/hv/hv.c
30356 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
30357 u64 output_address = (output) ? virt_to_phys(output) : 0;
30358 u32 output_address_hi = output_address >> 32;
30359 u32 output_address_lo = output_address & 0xFFFFFFFF;
30360 - void *hypercall_page = hv_context.hypercall_page;
30361 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
30362
30363 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
30364 "=a"(hv_status_lo) : "d" (control_hi),
30365 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
30366 index 0aee112..b72d21f 100644
30367 --- a/drivers/hv/hyperv_vmbus.h
30368 +++ b/drivers/hv/hyperv_vmbus.h
30369 @@ -556,7 +556,7 @@ enum vmbus_connect_state {
30370 struct vmbus_connection {
30371 enum vmbus_connect_state conn_state;
30372
30373 - atomic_t next_gpadl_handle;
30374 + atomic_unchecked_t next_gpadl_handle;
30375
30376 /*
30377 * Represents channel interrupts. Each bit position represents a
30378 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
30379 index d2d0a2a..90b8f4d 100644
30380 --- a/drivers/hv/vmbus_drv.c
30381 +++ b/drivers/hv/vmbus_drv.c
30382 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
30383 {
30384 int ret = 0;
30385
30386 - static atomic_t device_num = ATOMIC_INIT(0);
30387 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
30388
30389 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
30390 - atomic_inc_return(&device_num));
30391 + atomic_inc_return_unchecked(&device_num));
30392
30393 child_device_obj->device.bus = &hv_bus;
30394 child_device_obj->device.parent = &hv_acpi_dev->dev;
30395 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
30396 index 66f6729..2d6de0a 100644
30397 --- a/drivers/hwmon/acpi_power_meter.c
30398 +++ b/drivers/hwmon/acpi_power_meter.c
30399 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
30400 return res;
30401
30402 temp /= 1000;
30403 - if (temp < 0)
30404 - return -EINVAL;
30405
30406 mutex_lock(&resource->lock);
30407 resource->trip[attr->index - 7] = temp;
30408 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
30409 index 5357925..6cf0418 100644
30410 --- a/drivers/hwmon/sht15.c
30411 +++ b/drivers/hwmon/sht15.c
30412 @@ -166,7 +166,7 @@ struct sht15_data {
30413 int supply_uV;
30414 bool supply_uV_valid;
30415 struct work_struct update_supply_work;
30416 - atomic_t interrupt_handled;
30417 + atomic_unchecked_t interrupt_handled;
30418 };
30419
30420 /**
30421 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
30422 return ret;
30423
30424 gpio_direction_input(data->pdata->gpio_data);
30425 - atomic_set(&data->interrupt_handled, 0);
30426 + atomic_set_unchecked(&data->interrupt_handled, 0);
30427
30428 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30429 if (gpio_get_value(data->pdata->gpio_data) == 0) {
30430 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
30431 /* Only relevant if the interrupt hasn't occurred. */
30432 - if (!atomic_read(&data->interrupt_handled))
30433 + if (!atomic_read_unchecked(&data->interrupt_handled))
30434 schedule_work(&data->read_work);
30435 }
30436 ret = wait_event_timeout(data->wait_queue,
30437 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
30438
30439 /* First disable the interrupt */
30440 disable_irq_nosync(irq);
30441 - atomic_inc(&data->interrupt_handled);
30442 + atomic_inc_unchecked(&data->interrupt_handled);
30443 /* Then schedule a reading work struct */
30444 if (data->state != SHT15_READING_NOTHING)
30445 schedule_work(&data->read_work);
30446 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
30447 * If not, then start the interrupt again - care here as could
30448 * have gone low in meantime so verify it hasn't!
30449 */
30450 - atomic_set(&data->interrupt_handled, 0);
30451 + atomic_set_unchecked(&data->interrupt_handled, 0);
30452 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30453 /* If still not occurred or another handler has been scheduled */
30454 if (gpio_get_value(data->pdata->gpio_data)
30455 - || atomic_read(&data->interrupt_handled))
30456 + || atomic_read_unchecked(&data->interrupt_handled))
30457 return;
30458 }
30459
30460 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
30461 index 378fcb5..5e91fa8 100644
30462 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
30463 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
30464 @@ -43,7 +43,7 @@
30465 extern struct i2c_adapter amd756_smbus;
30466
30467 static struct i2c_adapter *s4882_adapter;
30468 -static struct i2c_algorithm *s4882_algo;
30469 +static i2c_algorithm_no_const *s4882_algo;
30470
30471 /* Wrapper access functions for multiplexed SMBus */
30472 static DEFINE_MUTEX(amd756_lock);
30473 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
30474 index 29015eb..af2d8e9 100644
30475 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
30476 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
30477 @@ -41,7 +41,7 @@
30478 extern struct i2c_adapter *nforce2_smbus;
30479
30480 static struct i2c_adapter *s4985_adapter;
30481 -static struct i2c_algorithm *s4985_algo;
30482 +static i2c_algorithm_no_const *s4985_algo;
30483
30484 /* Wrapper access functions for multiplexed SMBus */
30485 static DEFINE_MUTEX(nforce2_lock);
30486 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
30487 index d7a4833..7fae376 100644
30488 --- a/drivers/i2c/i2c-mux.c
30489 +++ b/drivers/i2c/i2c-mux.c
30490 @@ -28,7 +28,7 @@
30491 /* multiplexer per channel data */
30492 struct i2c_mux_priv {
30493 struct i2c_adapter adap;
30494 - struct i2c_algorithm algo;
30495 + i2c_algorithm_no_const algo;
30496
30497 struct i2c_adapter *parent;
30498 void *mux_dev; /* the mux chip/device */
30499 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
30500 index 57d00ca..0145194 100644
30501 --- a/drivers/ide/aec62xx.c
30502 +++ b/drivers/ide/aec62xx.c
30503 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
30504 .cable_detect = atp86x_cable_detect,
30505 };
30506
30507 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
30508 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
30509 { /* 0: AEC6210 */
30510 .name = DRV_NAME,
30511 .init_chipset = init_chipset_aec62xx,
30512 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
30513 index 2c8016a..911a27c 100644
30514 --- a/drivers/ide/alim15x3.c
30515 +++ b/drivers/ide/alim15x3.c
30516 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
30517 .dma_sff_read_status = ide_dma_sff_read_status,
30518 };
30519
30520 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
30521 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
30522 .name = DRV_NAME,
30523 .init_chipset = init_chipset_ali15x3,
30524 .init_hwif = init_hwif_ali15x3,
30525 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
30526 index 3747b25..56fc995 100644
30527 --- a/drivers/ide/amd74xx.c
30528 +++ b/drivers/ide/amd74xx.c
30529 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
30530 .udma_mask = udma, \
30531 }
30532
30533 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
30534 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
30535 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
30536 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
30537 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
30538 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
30539 index 15f0ead..cb43480 100644
30540 --- a/drivers/ide/atiixp.c
30541 +++ b/drivers/ide/atiixp.c
30542 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
30543 .cable_detect = atiixp_cable_detect,
30544 };
30545
30546 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
30547 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
30548 { /* 0: IXP200/300/400/700 */
30549 .name = DRV_NAME,
30550 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
30551 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
30552 index 5f80312..d1fc438 100644
30553 --- a/drivers/ide/cmd64x.c
30554 +++ b/drivers/ide/cmd64x.c
30555 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
30556 .dma_sff_read_status = ide_dma_sff_read_status,
30557 };
30558
30559 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
30560 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
30561 { /* 0: CMD643 */
30562 .name = DRV_NAME,
30563 .init_chipset = init_chipset_cmd64x,
30564 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
30565 index 2c1e5f7..1444762 100644
30566 --- a/drivers/ide/cs5520.c
30567 +++ b/drivers/ide/cs5520.c
30568 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
30569 .set_dma_mode = cs5520_set_dma_mode,
30570 };
30571
30572 -static const struct ide_port_info cyrix_chipset __devinitdata = {
30573 +static const struct ide_port_info cyrix_chipset __devinitconst = {
30574 .name = DRV_NAME,
30575 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
30576 .port_ops = &cs5520_port_ops,
30577 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
30578 index 4dc4eb9..49b40ad 100644
30579 --- a/drivers/ide/cs5530.c
30580 +++ b/drivers/ide/cs5530.c
30581 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
30582 .udma_filter = cs5530_udma_filter,
30583 };
30584
30585 -static const struct ide_port_info cs5530_chipset __devinitdata = {
30586 +static const struct ide_port_info cs5530_chipset __devinitconst = {
30587 .name = DRV_NAME,
30588 .init_chipset = init_chipset_cs5530,
30589 .init_hwif = init_hwif_cs5530,
30590 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
30591 index 5059faf..18d4c85 100644
30592 --- a/drivers/ide/cs5535.c
30593 +++ b/drivers/ide/cs5535.c
30594 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
30595 .cable_detect = cs5535_cable_detect,
30596 };
30597
30598 -static const struct ide_port_info cs5535_chipset __devinitdata = {
30599 +static const struct ide_port_info cs5535_chipset __devinitconst = {
30600 .name = DRV_NAME,
30601 .port_ops = &cs5535_port_ops,
30602 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
30603 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
30604 index 847553f..3ffb49d 100644
30605 --- a/drivers/ide/cy82c693.c
30606 +++ b/drivers/ide/cy82c693.c
30607 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
30608 .set_dma_mode = cy82c693_set_dma_mode,
30609 };
30610
30611 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
30612 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
30613 .name = DRV_NAME,
30614 .init_iops = init_iops_cy82c693,
30615 .port_ops = &cy82c693_port_ops,
30616 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
30617 index 58c51cd..4aec3b8 100644
30618 --- a/drivers/ide/hpt366.c
30619 +++ b/drivers/ide/hpt366.c
30620 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
30621 }
30622 };
30623
30624 -static const struct hpt_info hpt36x __devinitdata = {
30625 +static const struct hpt_info hpt36x __devinitconst = {
30626 .chip_name = "HPT36x",
30627 .chip_type = HPT36x,
30628 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
30629 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
30630 .timings = &hpt36x_timings
30631 };
30632
30633 -static const struct hpt_info hpt370 __devinitdata = {
30634 +static const struct hpt_info hpt370 __devinitconst = {
30635 .chip_name = "HPT370",
30636 .chip_type = HPT370,
30637 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
30638 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
30639 .timings = &hpt37x_timings
30640 };
30641
30642 -static const struct hpt_info hpt370a __devinitdata = {
30643 +static const struct hpt_info hpt370a __devinitconst = {
30644 .chip_name = "HPT370A",
30645 .chip_type = HPT370A,
30646 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
30647 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
30648 .timings = &hpt37x_timings
30649 };
30650
30651 -static const struct hpt_info hpt374 __devinitdata = {
30652 +static const struct hpt_info hpt374 __devinitconst = {
30653 .chip_name = "HPT374",
30654 .chip_type = HPT374,
30655 .udma_mask = ATA_UDMA5,
30656 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
30657 .timings = &hpt37x_timings
30658 };
30659
30660 -static const struct hpt_info hpt372 __devinitdata = {
30661 +static const struct hpt_info hpt372 __devinitconst = {
30662 .chip_name = "HPT372",
30663 .chip_type = HPT372,
30664 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30665 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
30666 .timings = &hpt37x_timings
30667 };
30668
30669 -static const struct hpt_info hpt372a __devinitdata = {
30670 +static const struct hpt_info hpt372a __devinitconst = {
30671 .chip_name = "HPT372A",
30672 .chip_type = HPT372A,
30673 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30674 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
30675 .timings = &hpt37x_timings
30676 };
30677
30678 -static const struct hpt_info hpt302 __devinitdata = {
30679 +static const struct hpt_info hpt302 __devinitconst = {
30680 .chip_name = "HPT302",
30681 .chip_type = HPT302,
30682 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30683 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
30684 .timings = &hpt37x_timings
30685 };
30686
30687 -static const struct hpt_info hpt371 __devinitdata = {
30688 +static const struct hpt_info hpt371 __devinitconst = {
30689 .chip_name = "HPT371",
30690 .chip_type = HPT371,
30691 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30692 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
30693 .timings = &hpt37x_timings
30694 };
30695
30696 -static const struct hpt_info hpt372n __devinitdata = {
30697 +static const struct hpt_info hpt372n __devinitconst = {
30698 .chip_name = "HPT372N",
30699 .chip_type = HPT372N,
30700 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30701 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
30702 .timings = &hpt37x_timings
30703 };
30704
30705 -static const struct hpt_info hpt302n __devinitdata = {
30706 +static const struct hpt_info hpt302n __devinitconst = {
30707 .chip_name = "HPT302N",
30708 .chip_type = HPT302N,
30709 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30710 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
30711 .timings = &hpt37x_timings
30712 };
30713
30714 -static const struct hpt_info hpt371n __devinitdata = {
30715 +static const struct hpt_info hpt371n __devinitconst = {
30716 .chip_name = "HPT371N",
30717 .chip_type = HPT371N,
30718 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30719 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
30720 .dma_sff_read_status = ide_dma_sff_read_status,
30721 };
30722
30723 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
30724 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
30725 { /* 0: HPT36x */
30726 .name = DRV_NAME,
30727 .init_chipset = init_chipset_hpt366,
30728 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
30729 index 8126824..55a2798 100644
30730 --- a/drivers/ide/ide-cd.c
30731 +++ b/drivers/ide/ide-cd.c
30732 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
30733 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
30734 if ((unsigned long)buf & alignment
30735 || blk_rq_bytes(rq) & q->dma_pad_mask
30736 - || object_is_on_stack(buf))
30737 + || object_starts_on_stack(buf))
30738 drive->dma = 0;
30739 }
30740 }
30741 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
30742 index a743e68..1cfd674 100644
30743 --- a/drivers/ide/ide-pci-generic.c
30744 +++ b/drivers/ide/ide-pci-generic.c
30745 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
30746 .udma_mask = ATA_UDMA6, \
30747 }
30748
30749 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
30750 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
30751 /* 0: Unknown */
30752 DECLARE_GENERIC_PCI_DEV(0),
30753
30754 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
30755 index 560e66d..d5dd180 100644
30756 --- a/drivers/ide/it8172.c
30757 +++ b/drivers/ide/it8172.c
30758 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
30759 .set_dma_mode = it8172_set_dma_mode,
30760 };
30761
30762 -static const struct ide_port_info it8172_port_info __devinitdata = {
30763 +static const struct ide_port_info it8172_port_info __devinitconst = {
30764 .name = DRV_NAME,
30765 .port_ops = &it8172_port_ops,
30766 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
30767 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
30768 index 46816ba..1847aeb 100644
30769 --- a/drivers/ide/it8213.c
30770 +++ b/drivers/ide/it8213.c
30771 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
30772 .cable_detect = it8213_cable_detect,
30773 };
30774
30775 -static const struct ide_port_info it8213_chipset __devinitdata = {
30776 +static const struct ide_port_info it8213_chipset __devinitconst = {
30777 .name = DRV_NAME,
30778 .enablebits = { {0x41, 0x80, 0x80} },
30779 .port_ops = &it8213_port_ops,
30780 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
30781 index 2e3169f..c5611db 100644
30782 --- a/drivers/ide/it821x.c
30783 +++ b/drivers/ide/it821x.c
30784 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
30785 .cable_detect = it821x_cable_detect,
30786 };
30787
30788 -static const struct ide_port_info it821x_chipset __devinitdata = {
30789 +static const struct ide_port_info it821x_chipset __devinitconst = {
30790 .name = DRV_NAME,
30791 .init_chipset = init_chipset_it821x,
30792 .init_hwif = init_hwif_it821x,
30793 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
30794 index 74c2c4a..efddd7d 100644
30795 --- a/drivers/ide/jmicron.c
30796 +++ b/drivers/ide/jmicron.c
30797 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
30798 .cable_detect = jmicron_cable_detect,
30799 };
30800
30801 -static const struct ide_port_info jmicron_chipset __devinitdata = {
30802 +static const struct ide_port_info jmicron_chipset __devinitconst = {
30803 .name = DRV_NAME,
30804 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
30805 .port_ops = &jmicron_port_ops,
30806 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
30807 index 95327a2..73f78d8 100644
30808 --- a/drivers/ide/ns87415.c
30809 +++ b/drivers/ide/ns87415.c
30810 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
30811 .dma_sff_read_status = superio_dma_sff_read_status,
30812 };
30813
30814 -static const struct ide_port_info ns87415_chipset __devinitdata = {
30815 +static const struct ide_port_info ns87415_chipset __devinitconst = {
30816 .name = DRV_NAME,
30817 .init_hwif = init_hwif_ns87415,
30818 .tp_ops = &ns87415_tp_ops,
30819 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
30820 index 1a53a4c..39edc66 100644
30821 --- a/drivers/ide/opti621.c
30822 +++ b/drivers/ide/opti621.c
30823 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
30824 .set_pio_mode = opti621_set_pio_mode,
30825 };
30826
30827 -static const struct ide_port_info opti621_chipset __devinitdata = {
30828 +static const struct ide_port_info opti621_chipset __devinitconst = {
30829 .name = DRV_NAME,
30830 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
30831 .port_ops = &opti621_port_ops,
30832 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
30833 index 9546fe2..2e5ceb6 100644
30834 --- a/drivers/ide/pdc202xx_new.c
30835 +++ b/drivers/ide/pdc202xx_new.c
30836 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
30837 .udma_mask = udma, \
30838 }
30839
30840 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
30841 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
30842 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
30843 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
30844 };
30845 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
30846 index 3a35ec6..5634510 100644
30847 --- a/drivers/ide/pdc202xx_old.c
30848 +++ b/drivers/ide/pdc202xx_old.c
30849 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
30850 .max_sectors = sectors, \
30851 }
30852
30853 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
30854 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
30855 { /* 0: PDC20246 */
30856 .name = DRV_NAME,
30857 .init_chipset = init_chipset_pdc202xx,
30858 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
30859 index 1892e81..fe0fd60 100644
30860 --- a/drivers/ide/piix.c
30861 +++ b/drivers/ide/piix.c
30862 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
30863 .udma_mask = udma, \
30864 }
30865
30866 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
30867 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
30868 /* 0: MPIIX */
30869 { /*
30870 * MPIIX actually has only a single IDE channel mapped to
30871 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
30872 index a6414a8..c04173e 100644
30873 --- a/drivers/ide/rz1000.c
30874 +++ b/drivers/ide/rz1000.c
30875 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
30876 }
30877 }
30878
30879 -static const struct ide_port_info rz1000_chipset __devinitdata = {
30880 +static const struct ide_port_info rz1000_chipset __devinitconst = {
30881 .name = DRV_NAME,
30882 .host_flags = IDE_HFLAG_NO_DMA,
30883 };
30884 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
30885 index 356b9b5..d4758eb 100644
30886 --- a/drivers/ide/sc1200.c
30887 +++ b/drivers/ide/sc1200.c
30888 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
30889 .dma_sff_read_status = ide_dma_sff_read_status,
30890 };
30891
30892 -static const struct ide_port_info sc1200_chipset __devinitdata = {
30893 +static const struct ide_port_info sc1200_chipset __devinitconst = {
30894 .name = DRV_NAME,
30895 .port_ops = &sc1200_port_ops,
30896 .dma_ops = &sc1200_dma_ops,
30897 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
30898 index b7f5b0c..9701038 100644
30899 --- a/drivers/ide/scc_pata.c
30900 +++ b/drivers/ide/scc_pata.c
30901 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
30902 .dma_sff_read_status = scc_dma_sff_read_status,
30903 };
30904
30905 -static const struct ide_port_info scc_chipset __devinitdata = {
30906 +static const struct ide_port_info scc_chipset __devinitconst = {
30907 .name = "sccIDE",
30908 .init_iops = init_iops_scc,
30909 .init_dma = scc_init_dma,
30910 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
30911 index 35fb8da..24d72ef 100644
30912 --- a/drivers/ide/serverworks.c
30913 +++ b/drivers/ide/serverworks.c
30914 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
30915 .cable_detect = svwks_cable_detect,
30916 };
30917
30918 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
30919 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
30920 { /* 0: OSB4 */
30921 .name = DRV_NAME,
30922 .init_chipset = init_chipset_svwks,
30923 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
30924 index ddeda44..46f7e30 100644
30925 --- a/drivers/ide/siimage.c
30926 +++ b/drivers/ide/siimage.c
30927 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
30928 .udma_mask = ATA_UDMA6, \
30929 }
30930
30931 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
30932 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
30933 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
30934 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
30935 };
30936 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
30937 index 4a00225..09e61b4 100644
30938 --- a/drivers/ide/sis5513.c
30939 +++ b/drivers/ide/sis5513.c
30940 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
30941 .cable_detect = sis_cable_detect,
30942 };
30943
30944 -static const struct ide_port_info sis5513_chipset __devinitdata = {
30945 +static const struct ide_port_info sis5513_chipset __devinitconst = {
30946 .name = DRV_NAME,
30947 .init_chipset = init_chipset_sis5513,
30948 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
30949 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
30950 index f21dc2a..d051cd2 100644
30951 --- a/drivers/ide/sl82c105.c
30952 +++ b/drivers/ide/sl82c105.c
30953 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
30954 .dma_sff_read_status = ide_dma_sff_read_status,
30955 };
30956
30957 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
30958 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
30959 .name = DRV_NAME,
30960 .init_chipset = init_chipset_sl82c105,
30961 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
30962 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
30963 index 864ffe0..863a5e9 100644
30964 --- a/drivers/ide/slc90e66.c
30965 +++ b/drivers/ide/slc90e66.c
30966 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
30967 .cable_detect = slc90e66_cable_detect,
30968 };
30969
30970 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
30971 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
30972 .name = DRV_NAME,
30973 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
30974 .port_ops = &slc90e66_port_ops,
30975 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
30976 index 4799d5c..1794678 100644
30977 --- a/drivers/ide/tc86c001.c
30978 +++ b/drivers/ide/tc86c001.c
30979 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
30980 .dma_sff_read_status = ide_dma_sff_read_status,
30981 };
30982
30983 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
30984 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
30985 .name = DRV_NAME,
30986 .init_hwif = init_hwif_tc86c001,
30987 .port_ops = &tc86c001_port_ops,
30988 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
30989 index 281c914..55ce1b8 100644
30990 --- a/drivers/ide/triflex.c
30991 +++ b/drivers/ide/triflex.c
30992 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
30993 .set_dma_mode = triflex_set_mode,
30994 };
30995
30996 -static const struct ide_port_info triflex_device __devinitdata = {
30997 +static const struct ide_port_info triflex_device __devinitconst = {
30998 .name = DRV_NAME,
30999 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31000 .port_ops = &triflex_port_ops,
31001 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31002 index 4b42ca0..e494a98 100644
31003 --- a/drivers/ide/trm290.c
31004 +++ b/drivers/ide/trm290.c
31005 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31006 .dma_check = trm290_dma_check,
31007 };
31008
31009 -static const struct ide_port_info trm290_chipset __devinitdata = {
31010 +static const struct ide_port_info trm290_chipset __devinitconst = {
31011 .name = DRV_NAME,
31012 .init_hwif = init_hwif_trm290,
31013 .tp_ops = &trm290_tp_ops,
31014 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31015 index f46f49c..eb77678 100644
31016 --- a/drivers/ide/via82cxxx.c
31017 +++ b/drivers/ide/via82cxxx.c
31018 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31019 .cable_detect = via82cxxx_cable_detect,
31020 };
31021
31022 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31023 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31024 .name = DRV_NAME,
31025 .init_chipset = init_chipset_via82cxxx,
31026 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31027 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31028 index eb0e2cc..14241c7 100644
31029 --- a/drivers/ieee802154/fakehard.c
31030 +++ b/drivers/ieee802154/fakehard.c
31031 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31032 phy->transmit_power = 0xbf;
31033
31034 dev->netdev_ops = &fake_ops;
31035 - dev->ml_priv = &fake_mlme;
31036 + dev->ml_priv = (void *)&fake_mlme;
31037
31038 priv = netdev_priv(dev);
31039 priv->phy = phy;
31040 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31041 index 8b72f39..55df4c8 100644
31042 --- a/drivers/infiniband/core/cm.c
31043 +++ b/drivers/infiniband/core/cm.c
31044 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31045
31046 struct cm_counter_group {
31047 struct kobject obj;
31048 - atomic_long_t counter[CM_ATTR_COUNT];
31049 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31050 };
31051
31052 struct cm_counter_attribute {
31053 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31054 struct ib_mad_send_buf *msg = NULL;
31055 int ret;
31056
31057 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31058 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31059 counter[CM_REQ_COUNTER]);
31060
31061 /* Quick state check to discard duplicate REQs. */
31062 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
31063 if (!cm_id_priv)
31064 return;
31065
31066 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31067 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31068 counter[CM_REP_COUNTER]);
31069 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
31070 if (ret)
31071 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
31072 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
31073 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
31074 spin_unlock_irq(&cm_id_priv->lock);
31075 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31076 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31077 counter[CM_RTU_COUNTER]);
31078 goto out;
31079 }
31080 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
31081 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
31082 dreq_msg->local_comm_id);
31083 if (!cm_id_priv) {
31084 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31085 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31086 counter[CM_DREQ_COUNTER]);
31087 cm_issue_drep(work->port, work->mad_recv_wc);
31088 return -EINVAL;
31089 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
31090 case IB_CM_MRA_REP_RCVD:
31091 break;
31092 case IB_CM_TIMEWAIT:
31093 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31094 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31095 counter[CM_DREQ_COUNTER]);
31096 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31097 goto unlock;
31098 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
31099 cm_free_msg(msg);
31100 goto deref;
31101 case IB_CM_DREQ_RCVD:
31102 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31103 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31104 counter[CM_DREQ_COUNTER]);
31105 goto unlock;
31106 default:
31107 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
31108 ib_modify_mad(cm_id_priv->av.port->mad_agent,
31109 cm_id_priv->msg, timeout)) {
31110 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
31111 - atomic_long_inc(&work->port->
31112 + atomic_long_inc_unchecked(&work->port->
31113 counter_group[CM_RECV_DUPLICATES].
31114 counter[CM_MRA_COUNTER]);
31115 goto out;
31116 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
31117 break;
31118 case IB_CM_MRA_REQ_RCVD:
31119 case IB_CM_MRA_REP_RCVD:
31120 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31121 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31122 counter[CM_MRA_COUNTER]);
31123 /* fall through */
31124 default:
31125 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
31126 case IB_CM_LAP_IDLE:
31127 break;
31128 case IB_CM_MRA_LAP_SENT:
31129 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31130 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31131 counter[CM_LAP_COUNTER]);
31132 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31133 goto unlock;
31134 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
31135 cm_free_msg(msg);
31136 goto deref;
31137 case IB_CM_LAP_RCVD:
31138 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31139 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31140 counter[CM_LAP_COUNTER]);
31141 goto unlock;
31142 default:
31143 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
31144 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
31145 if (cur_cm_id_priv) {
31146 spin_unlock_irq(&cm.lock);
31147 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31148 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31149 counter[CM_SIDR_REQ_COUNTER]);
31150 goto out; /* Duplicate message. */
31151 }
31152 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
31153 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
31154 msg->retries = 1;
31155
31156 - atomic_long_add(1 + msg->retries,
31157 + atomic_long_add_unchecked(1 + msg->retries,
31158 &port->counter_group[CM_XMIT].counter[attr_index]);
31159 if (msg->retries)
31160 - atomic_long_add(msg->retries,
31161 + atomic_long_add_unchecked(msg->retries,
31162 &port->counter_group[CM_XMIT_RETRIES].
31163 counter[attr_index]);
31164
31165 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
31166 }
31167
31168 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
31169 - atomic_long_inc(&port->counter_group[CM_RECV].
31170 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
31171 counter[attr_id - CM_ATTR_ID_OFFSET]);
31172
31173 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
31174 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
31175 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
31176
31177 return sprintf(buf, "%ld\n",
31178 - atomic_long_read(&group->counter[cm_attr->index]));
31179 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
31180 }
31181
31182 static const struct sysfs_ops cm_counter_ops = {
31183 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
31184 index 176c8f9..2627b62 100644
31185 --- a/drivers/infiniband/core/fmr_pool.c
31186 +++ b/drivers/infiniband/core/fmr_pool.c
31187 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
31188
31189 struct task_struct *thread;
31190
31191 - atomic_t req_ser;
31192 - atomic_t flush_ser;
31193 + atomic_unchecked_t req_ser;
31194 + atomic_unchecked_t flush_ser;
31195
31196 wait_queue_head_t force_wait;
31197 };
31198 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
31199 struct ib_fmr_pool *pool = pool_ptr;
31200
31201 do {
31202 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
31203 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
31204 ib_fmr_batch_release(pool);
31205
31206 - atomic_inc(&pool->flush_ser);
31207 + atomic_inc_unchecked(&pool->flush_ser);
31208 wake_up_interruptible(&pool->force_wait);
31209
31210 if (pool->flush_function)
31211 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
31212 }
31213
31214 set_current_state(TASK_INTERRUPTIBLE);
31215 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
31216 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
31217 !kthread_should_stop())
31218 schedule();
31219 __set_current_state(TASK_RUNNING);
31220 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
31221 pool->dirty_watermark = params->dirty_watermark;
31222 pool->dirty_len = 0;
31223 spin_lock_init(&pool->pool_lock);
31224 - atomic_set(&pool->req_ser, 0);
31225 - atomic_set(&pool->flush_ser, 0);
31226 + atomic_set_unchecked(&pool->req_ser, 0);
31227 + atomic_set_unchecked(&pool->flush_ser, 0);
31228 init_waitqueue_head(&pool->force_wait);
31229
31230 pool->thread = kthread_run(ib_fmr_cleanup_thread,
31231 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
31232 }
31233 spin_unlock_irq(&pool->pool_lock);
31234
31235 - serial = atomic_inc_return(&pool->req_ser);
31236 + serial = atomic_inc_return_unchecked(&pool->req_ser);
31237 wake_up_process(pool->thread);
31238
31239 if (wait_event_interruptible(pool->force_wait,
31240 - atomic_read(&pool->flush_ser) - serial >= 0))
31241 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
31242 return -EINTR;
31243
31244 return 0;
31245 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
31246 } else {
31247 list_add_tail(&fmr->list, &pool->dirty_list);
31248 if (++pool->dirty_len >= pool->dirty_watermark) {
31249 - atomic_inc(&pool->req_ser);
31250 + atomic_inc_unchecked(&pool->req_ser);
31251 wake_up_process(pool->thread);
31252 }
31253 }
31254 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
31255 index 40c8353..946b0e4 100644
31256 --- a/drivers/infiniband/hw/cxgb4/mem.c
31257 +++ b/drivers/infiniband/hw/cxgb4/mem.c
31258 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
31259 int err;
31260 struct fw_ri_tpte tpt;
31261 u32 stag_idx;
31262 - static atomic_t key;
31263 + static atomic_unchecked_t key;
31264
31265 if (c4iw_fatal_error(rdev))
31266 return -EIO;
31267 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
31268 &rdev->resource.tpt_fifo_lock);
31269 if (!stag_idx)
31270 return -ENOMEM;
31271 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
31272 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
31273 }
31274 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
31275 __func__, stag_state, type, pdid, stag_idx);
31276 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
31277 index 79b3dbc..96e5fcc 100644
31278 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
31279 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
31280 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
31281 struct ib_atomic_eth *ateth;
31282 struct ipath_ack_entry *e;
31283 u64 vaddr;
31284 - atomic64_t *maddr;
31285 + atomic64_unchecked_t *maddr;
31286 u64 sdata;
31287 u32 rkey;
31288 u8 next;
31289 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
31290 IB_ACCESS_REMOTE_ATOMIC)))
31291 goto nack_acc_unlck;
31292 /* Perform atomic OP and save result. */
31293 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
31294 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
31295 sdata = be64_to_cpu(ateth->swap_data);
31296 e = &qp->s_ack_queue[qp->r_head_ack_queue];
31297 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
31298 - (u64) atomic64_add_return(sdata, maddr) - sdata :
31299 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
31300 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
31301 be64_to_cpu(ateth->compare_data),
31302 sdata);
31303 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
31304 index 1f95bba..9530f87 100644
31305 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
31306 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
31307 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
31308 unsigned long flags;
31309 struct ib_wc wc;
31310 u64 sdata;
31311 - atomic64_t *maddr;
31312 + atomic64_unchecked_t *maddr;
31313 enum ib_wc_status send_status;
31314
31315 /*
31316 @@ -382,11 +382,11 @@ again:
31317 IB_ACCESS_REMOTE_ATOMIC)))
31318 goto acc_err;
31319 /* Perform atomic OP and save result. */
31320 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
31321 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
31322 sdata = wqe->wr.wr.atomic.compare_add;
31323 *(u64 *) sqp->s_sge.sge.vaddr =
31324 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
31325 - (u64) atomic64_add_return(sdata, maddr) - sdata :
31326 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
31327 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
31328 sdata, wqe->wr.wr.atomic.swap);
31329 goto send_comp;
31330 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
31331 index 5965b3d..16817fb 100644
31332 --- a/drivers/infiniband/hw/nes/nes.c
31333 +++ b/drivers/infiniband/hw/nes/nes.c
31334 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
31335 LIST_HEAD(nes_adapter_list);
31336 static LIST_HEAD(nes_dev_list);
31337
31338 -atomic_t qps_destroyed;
31339 +atomic_unchecked_t qps_destroyed;
31340
31341 static unsigned int ee_flsh_adapter;
31342 static unsigned int sysfs_nonidx_addr;
31343 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
31344 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
31345 struct nes_adapter *nesadapter = nesdev->nesadapter;
31346
31347 - atomic_inc(&qps_destroyed);
31348 + atomic_inc_unchecked(&qps_destroyed);
31349
31350 /* Free the control structures */
31351
31352 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
31353 index 568b4f1..5ea3eff 100644
31354 --- a/drivers/infiniband/hw/nes/nes.h
31355 +++ b/drivers/infiniband/hw/nes/nes.h
31356 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
31357 extern unsigned int wqm_quanta;
31358 extern struct list_head nes_adapter_list;
31359
31360 -extern atomic_t cm_connects;
31361 -extern atomic_t cm_accepts;
31362 -extern atomic_t cm_disconnects;
31363 -extern atomic_t cm_closes;
31364 -extern atomic_t cm_connecteds;
31365 -extern atomic_t cm_connect_reqs;
31366 -extern atomic_t cm_rejects;
31367 -extern atomic_t mod_qp_timouts;
31368 -extern atomic_t qps_created;
31369 -extern atomic_t qps_destroyed;
31370 -extern atomic_t sw_qps_destroyed;
31371 +extern atomic_unchecked_t cm_connects;
31372 +extern atomic_unchecked_t cm_accepts;
31373 +extern atomic_unchecked_t cm_disconnects;
31374 +extern atomic_unchecked_t cm_closes;
31375 +extern atomic_unchecked_t cm_connecteds;
31376 +extern atomic_unchecked_t cm_connect_reqs;
31377 +extern atomic_unchecked_t cm_rejects;
31378 +extern atomic_unchecked_t mod_qp_timouts;
31379 +extern atomic_unchecked_t qps_created;
31380 +extern atomic_unchecked_t qps_destroyed;
31381 +extern atomic_unchecked_t sw_qps_destroyed;
31382 extern u32 mh_detected;
31383 extern u32 mh_pauses_sent;
31384 extern u32 cm_packets_sent;
31385 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
31386 extern u32 cm_packets_received;
31387 extern u32 cm_packets_dropped;
31388 extern u32 cm_packets_retrans;
31389 -extern atomic_t cm_listens_created;
31390 -extern atomic_t cm_listens_destroyed;
31391 +extern atomic_unchecked_t cm_listens_created;
31392 +extern atomic_unchecked_t cm_listens_destroyed;
31393 extern u32 cm_backlog_drops;
31394 -extern atomic_t cm_loopbacks;
31395 -extern atomic_t cm_nodes_created;
31396 -extern atomic_t cm_nodes_destroyed;
31397 -extern atomic_t cm_accel_dropped_pkts;
31398 -extern atomic_t cm_resets_recvd;
31399 -extern atomic_t pau_qps_created;
31400 -extern atomic_t pau_qps_destroyed;
31401 +extern atomic_unchecked_t cm_loopbacks;
31402 +extern atomic_unchecked_t cm_nodes_created;
31403 +extern atomic_unchecked_t cm_nodes_destroyed;
31404 +extern atomic_unchecked_t cm_accel_dropped_pkts;
31405 +extern atomic_unchecked_t cm_resets_recvd;
31406 +extern atomic_unchecked_t pau_qps_created;
31407 +extern atomic_unchecked_t pau_qps_destroyed;
31408
31409 extern u32 int_mod_timer_init;
31410 extern u32 int_mod_cq_depth_256;
31411 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
31412 index 0a52d72..0642f36 100644
31413 --- a/drivers/infiniband/hw/nes/nes_cm.c
31414 +++ b/drivers/infiniband/hw/nes/nes_cm.c
31415 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
31416 u32 cm_packets_retrans;
31417 u32 cm_packets_created;
31418 u32 cm_packets_received;
31419 -atomic_t cm_listens_created;
31420 -atomic_t cm_listens_destroyed;
31421 +atomic_unchecked_t cm_listens_created;
31422 +atomic_unchecked_t cm_listens_destroyed;
31423 u32 cm_backlog_drops;
31424 -atomic_t cm_loopbacks;
31425 -atomic_t cm_nodes_created;
31426 -atomic_t cm_nodes_destroyed;
31427 -atomic_t cm_accel_dropped_pkts;
31428 -atomic_t cm_resets_recvd;
31429 +atomic_unchecked_t cm_loopbacks;
31430 +atomic_unchecked_t cm_nodes_created;
31431 +atomic_unchecked_t cm_nodes_destroyed;
31432 +atomic_unchecked_t cm_accel_dropped_pkts;
31433 +atomic_unchecked_t cm_resets_recvd;
31434
31435 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
31436 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
31437 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
31438
31439 static struct nes_cm_core *g_cm_core;
31440
31441 -atomic_t cm_connects;
31442 -atomic_t cm_accepts;
31443 -atomic_t cm_disconnects;
31444 -atomic_t cm_closes;
31445 -atomic_t cm_connecteds;
31446 -atomic_t cm_connect_reqs;
31447 -atomic_t cm_rejects;
31448 +atomic_unchecked_t cm_connects;
31449 +atomic_unchecked_t cm_accepts;
31450 +atomic_unchecked_t cm_disconnects;
31451 +atomic_unchecked_t cm_closes;
31452 +atomic_unchecked_t cm_connecteds;
31453 +atomic_unchecked_t cm_connect_reqs;
31454 +atomic_unchecked_t cm_rejects;
31455
31456 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
31457 {
31458 @@ -1271,7 +1271,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
31459 kfree(listener);
31460 listener = NULL;
31461 ret = 0;
31462 - atomic_inc(&cm_listens_destroyed);
31463 + atomic_inc_unchecked(&cm_listens_destroyed);
31464 } else {
31465 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
31466 }
31467 @@ -1473,7 +1473,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
31468 cm_node->rem_mac);
31469
31470 add_hte_node(cm_core, cm_node);
31471 - atomic_inc(&cm_nodes_created);
31472 + atomic_inc_unchecked(&cm_nodes_created);
31473
31474 return cm_node;
31475 }
31476 @@ -1531,7 +1531,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
31477 }
31478
31479 atomic_dec(&cm_core->node_cnt);
31480 - atomic_inc(&cm_nodes_destroyed);
31481 + atomic_inc_unchecked(&cm_nodes_destroyed);
31482 nesqp = cm_node->nesqp;
31483 if (nesqp) {
31484 nesqp->cm_node = NULL;
31485 @@ -1595,7 +1595,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
31486
31487 static void drop_packet(struct sk_buff *skb)
31488 {
31489 - atomic_inc(&cm_accel_dropped_pkts);
31490 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
31491 dev_kfree_skb_any(skb);
31492 }
31493
31494 @@ -1658,7 +1658,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
31495 {
31496
31497 int reset = 0; /* whether to send reset in case of err.. */
31498 - atomic_inc(&cm_resets_recvd);
31499 + atomic_inc_unchecked(&cm_resets_recvd);
31500 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
31501 " refcnt=%d\n", cm_node, cm_node->state,
31502 atomic_read(&cm_node->ref_count));
31503 @@ -2299,7 +2299,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
31504 rem_ref_cm_node(cm_node->cm_core, cm_node);
31505 return NULL;
31506 }
31507 - atomic_inc(&cm_loopbacks);
31508 + atomic_inc_unchecked(&cm_loopbacks);
31509 loopbackremotenode->loopbackpartner = cm_node;
31510 loopbackremotenode->tcp_cntxt.rcv_wscale =
31511 NES_CM_DEFAULT_RCV_WND_SCALE;
31512 @@ -2574,7 +2574,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
31513 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
31514 else {
31515 rem_ref_cm_node(cm_core, cm_node);
31516 - atomic_inc(&cm_accel_dropped_pkts);
31517 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
31518 dev_kfree_skb_any(skb);
31519 }
31520 break;
31521 @@ -2880,7 +2880,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
31522
31523 if ((cm_id) && (cm_id->event_handler)) {
31524 if (issue_disconn) {
31525 - atomic_inc(&cm_disconnects);
31526 + atomic_inc_unchecked(&cm_disconnects);
31527 cm_event.event = IW_CM_EVENT_DISCONNECT;
31528 cm_event.status = disconn_status;
31529 cm_event.local_addr = cm_id->local_addr;
31530 @@ -2902,7 +2902,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
31531 }
31532
31533 if (issue_close) {
31534 - atomic_inc(&cm_closes);
31535 + atomic_inc_unchecked(&cm_closes);
31536 nes_disconnect(nesqp, 1);
31537
31538 cm_id->provider_data = nesqp;
31539 @@ -3038,7 +3038,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
31540
31541 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
31542 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
31543 - atomic_inc(&cm_accepts);
31544 + atomic_inc_unchecked(&cm_accepts);
31545
31546 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
31547 netdev_refcnt_read(nesvnic->netdev));
31548 @@ -3240,7 +3240,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
31549 struct nes_cm_core *cm_core;
31550 u8 *start_buff;
31551
31552 - atomic_inc(&cm_rejects);
31553 + atomic_inc_unchecked(&cm_rejects);
31554 cm_node = (struct nes_cm_node *)cm_id->provider_data;
31555 loopback = cm_node->loopbackpartner;
31556 cm_core = cm_node->cm_core;
31557 @@ -3300,7 +3300,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
31558 ntohl(cm_id->local_addr.sin_addr.s_addr),
31559 ntohs(cm_id->local_addr.sin_port));
31560
31561 - atomic_inc(&cm_connects);
31562 + atomic_inc_unchecked(&cm_connects);
31563 nesqp->active_conn = 1;
31564
31565 /* cache the cm_id in the qp */
31566 @@ -3406,7 +3406,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
31567 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
31568 return err;
31569 }
31570 - atomic_inc(&cm_listens_created);
31571 + atomic_inc_unchecked(&cm_listens_created);
31572 }
31573
31574 cm_id->add_ref(cm_id);
31575 @@ -3507,7 +3507,7 @@ static void cm_event_connected(struct nes_cm_event *event)
31576
31577 if (nesqp->destroyed)
31578 return;
31579 - atomic_inc(&cm_connecteds);
31580 + atomic_inc_unchecked(&cm_connecteds);
31581 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
31582 " local port 0x%04X. jiffies = %lu.\n",
31583 nesqp->hwqp.qp_id,
31584 @@ -3694,7 +3694,7 @@ static void cm_event_reset(struct nes_cm_event *event)
31585
31586 cm_id->add_ref(cm_id);
31587 ret = cm_id->event_handler(cm_id, &cm_event);
31588 - atomic_inc(&cm_closes);
31589 + atomic_inc_unchecked(&cm_closes);
31590 cm_event.event = IW_CM_EVENT_CLOSE;
31591 cm_event.status = 0;
31592 cm_event.provider_data = cm_id->provider_data;
31593 @@ -3730,7 +3730,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
31594 return;
31595 cm_id = cm_node->cm_id;
31596
31597 - atomic_inc(&cm_connect_reqs);
31598 + atomic_inc_unchecked(&cm_connect_reqs);
31599 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
31600 cm_node, cm_id, jiffies);
31601
31602 @@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
31603 return;
31604 cm_id = cm_node->cm_id;
31605
31606 - atomic_inc(&cm_connect_reqs);
31607 + atomic_inc_unchecked(&cm_connect_reqs);
31608 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
31609 cm_node, cm_id, jiffies);
31610
31611 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
31612 index b3b2a24..7bfaf1e 100644
31613 --- a/drivers/infiniband/hw/nes/nes_mgt.c
31614 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
31615 @@ -40,8 +40,8 @@
31616 #include "nes.h"
31617 #include "nes_mgt.h"
31618
31619 -atomic_t pau_qps_created;
31620 -atomic_t pau_qps_destroyed;
31621 +atomic_unchecked_t pau_qps_created;
31622 +atomic_unchecked_t pau_qps_destroyed;
31623
31624 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
31625 {
31626 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
31627 {
31628 struct sk_buff *skb;
31629 unsigned long flags;
31630 - atomic_inc(&pau_qps_destroyed);
31631 + atomic_inc_unchecked(&pau_qps_destroyed);
31632
31633 /* Free packets that have not yet been forwarded */
31634 /* Lock is acquired by skb_dequeue when removing the skb */
31635 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
31636 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
31637 skb_queue_head_init(&nesqp->pau_list);
31638 spin_lock_init(&nesqp->pau_lock);
31639 - atomic_inc(&pau_qps_created);
31640 + atomic_inc_unchecked(&pau_qps_created);
31641 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
31642 }
31643
31644 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
31645 index c00d2f3..8834298 100644
31646 --- a/drivers/infiniband/hw/nes/nes_nic.c
31647 +++ b/drivers/infiniband/hw/nes/nes_nic.c
31648 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
31649 target_stat_values[++index] = mh_detected;
31650 target_stat_values[++index] = mh_pauses_sent;
31651 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
31652 - target_stat_values[++index] = atomic_read(&cm_connects);
31653 - target_stat_values[++index] = atomic_read(&cm_accepts);
31654 - target_stat_values[++index] = atomic_read(&cm_disconnects);
31655 - target_stat_values[++index] = atomic_read(&cm_connecteds);
31656 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
31657 - target_stat_values[++index] = atomic_read(&cm_rejects);
31658 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
31659 - target_stat_values[++index] = atomic_read(&qps_created);
31660 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
31661 - target_stat_values[++index] = atomic_read(&qps_destroyed);
31662 - target_stat_values[++index] = atomic_read(&cm_closes);
31663 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
31664 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
31665 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
31666 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
31667 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
31668 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
31669 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
31670 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
31671 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
31672 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
31673 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
31674 target_stat_values[++index] = cm_packets_sent;
31675 target_stat_values[++index] = cm_packets_bounced;
31676 target_stat_values[++index] = cm_packets_created;
31677 target_stat_values[++index] = cm_packets_received;
31678 target_stat_values[++index] = cm_packets_dropped;
31679 target_stat_values[++index] = cm_packets_retrans;
31680 - target_stat_values[++index] = atomic_read(&cm_listens_created);
31681 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
31682 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
31683 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
31684 target_stat_values[++index] = cm_backlog_drops;
31685 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
31686 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
31687 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
31688 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
31689 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
31690 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
31691 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
31692 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
31693 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
31694 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
31695 target_stat_values[++index] = nesadapter->free_4kpbl;
31696 target_stat_values[++index] = nesadapter->free_256pbl;
31697 target_stat_values[++index] = int_mod_timer_init;
31698 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
31699 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
31700 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
31701 - target_stat_values[++index] = atomic_read(&pau_qps_created);
31702 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
31703 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
31704 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
31705 }
31706
31707 /**
31708 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
31709 index 5095bc4..41e8fff 100644
31710 --- a/drivers/infiniband/hw/nes/nes_verbs.c
31711 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
31712 @@ -46,9 +46,9 @@
31713
31714 #include <rdma/ib_umem.h>
31715
31716 -atomic_t mod_qp_timouts;
31717 -atomic_t qps_created;
31718 -atomic_t sw_qps_destroyed;
31719 +atomic_unchecked_t mod_qp_timouts;
31720 +atomic_unchecked_t qps_created;
31721 +atomic_unchecked_t sw_qps_destroyed;
31722
31723 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
31724
31725 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
31726 if (init_attr->create_flags)
31727 return ERR_PTR(-EINVAL);
31728
31729 - atomic_inc(&qps_created);
31730 + atomic_inc_unchecked(&qps_created);
31731 switch (init_attr->qp_type) {
31732 case IB_QPT_RC:
31733 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
31734 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
31735 struct iw_cm_event cm_event;
31736 int ret = 0;
31737
31738 - atomic_inc(&sw_qps_destroyed);
31739 + atomic_inc_unchecked(&sw_qps_destroyed);
31740 nesqp->destroyed = 1;
31741
31742 /* Blow away the connection if it exists. */
31743 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
31744 index b881bdc..c2e360c 100644
31745 --- a/drivers/infiniband/hw/qib/qib.h
31746 +++ b/drivers/infiniband/hw/qib/qib.h
31747 @@ -51,6 +51,7 @@
31748 #include <linux/completion.h>
31749 #include <linux/kref.h>
31750 #include <linux/sched.h>
31751 +#include <linux/slab.h>
31752
31753 #include "qib_common.h"
31754 #include "qib_verbs.h"
31755 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
31756 index c351aa4..e6967c2 100644
31757 --- a/drivers/input/gameport/gameport.c
31758 +++ b/drivers/input/gameport/gameport.c
31759 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
31760 */
31761 static void gameport_init_port(struct gameport *gameport)
31762 {
31763 - static atomic_t gameport_no = ATOMIC_INIT(0);
31764 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
31765
31766 __module_get(THIS_MODULE);
31767
31768 mutex_init(&gameport->drv_mutex);
31769 device_initialize(&gameport->dev);
31770 dev_set_name(&gameport->dev, "gameport%lu",
31771 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
31772 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
31773 gameport->dev.bus = &gameport_bus;
31774 gameport->dev.release = gameport_release_port;
31775 if (gameport->parent)
31776 diff --git a/drivers/input/input.c b/drivers/input/input.c
31777 index da38d97..2aa0b79 100644
31778 --- a/drivers/input/input.c
31779 +++ b/drivers/input/input.c
31780 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
31781 */
31782 int input_register_device(struct input_dev *dev)
31783 {
31784 - static atomic_t input_no = ATOMIC_INIT(0);
31785 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
31786 struct input_handler *handler;
31787 const char *path;
31788 int error;
31789 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
31790 dev->setkeycode = input_default_setkeycode;
31791
31792 dev_set_name(&dev->dev, "input%ld",
31793 - (unsigned long) atomic_inc_return(&input_no) - 1);
31794 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
31795
31796 error = device_add(&dev->dev);
31797 if (error)
31798 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
31799 index b8d8611..7a4a04b 100644
31800 --- a/drivers/input/joystick/sidewinder.c
31801 +++ b/drivers/input/joystick/sidewinder.c
31802 @@ -30,6 +30,7 @@
31803 #include <linux/kernel.h>
31804 #include <linux/module.h>
31805 #include <linux/slab.h>
31806 +#include <linux/sched.h>
31807 #include <linux/init.h>
31808 #include <linux/input.h>
31809 #include <linux/gameport.h>
31810 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
31811 index d728875..844c89b 100644
31812 --- a/drivers/input/joystick/xpad.c
31813 +++ b/drivers/input/joystick/xpad.c
31814 @@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
31815
31816 static int xpad_led_probe(struct usb_xpad *xpad)
31817 {
31818 - static atomic_t led_seq = ATOMIC_INIT(0);
31819 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
31820 long led_no;
31821 struct xpad_led *led;
31822 struct led_classdev *led_cdev;
31823 @@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
31824 if (!led)
31825 return -ENOMEM;
31826
31827 - led_no = (long)atomic_inc_return(&led_seq) - 1;
31828 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
31829
31830 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
31831 led->xpad = xpad;
31832 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
31833 index 0110b5a..d3ad144 100644
31834 --- a/drivers/input/mousedev.c
31835 +++ b/drivers/input/mousedev.c
31836 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
31837
31838 spin_unlock_irq(&client->packet_lock);
31839
31840 - if (copy_to_user(buffer, data, count))
31841 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
31842 return -EFAULT;
31843
31844 return count;
31845 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
31846 index ba70058..571d25d 100644
31847 --- a/drivers/input/serio/serio.c
31848 +++ b/drivers/input/serio/serio.c
31849 @@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
31850 */
31851 static void serio_init_port(struct serio *serio)
31852 {
31853 - static atomic_t serio_no = ATOMIC_INIT(0);
31854 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
31855
31856 __module_get(THIS_MODULE);
31857
31858 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
31859 mutex_init(&serio->drv_mutex);
31860 device_initialize(&serio->dev);
31861 dev_set_name(&serio->dev, "serio%ld",
31862 - (long)atomic_inc_return(&serio_no) - 1);
31863 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
31864 serio->dev.bus = &serio_bus;
31865 serio->dev.release = serio_release_port;
31866 serio->dev.groups = serio_device_attr_groups;
31867 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
31868 index e44933d..9ba484a 100644
31869 --- a/drivers/isdn/capi/capi.c
31870 +++ b/drivers/isdn/capi/capi.c
31871 @@ -83,8 +83,8 @@ struct capiminor {
31872
31873 struct capi20_appl *ap;
31874 u32 ncci;
31875 - atomic_t datahandle;
31876 - atomic_t msgid;
31877 + atomic_unchecked_t datahandle;
31878 + atomic_unchecked_t msgid;
31879
31880 struct tty_port port;
31881 int ttyinstop;
31882 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
31883 capimsg_setu16(s, 2, mp->ap->applid);
31884 capimsg_setu8 (s, 4, CAPI_DATA_B3);
31885 capimsg_setu8 (s, 5, CAPI_RESP);
31886 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
31887 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
31888 capimsg_setu32(s, 8, mp->ncci);
31889 capimsg_setu16(s, 12, datahandle);
31890 }
31891 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
31892 mp->outbytes -= len;
31893 spin_unlock_bh(&mp->outlock);
31894
31895 - datahandle = atomic_inc_return(&mp->datahandle);
31896 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
31897 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
31898 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
31899 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
31900 capimsg_setu16(skb->data, 2, mp->ap->applid);
31901 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
31902 capimsg_setu8 (skb->data, 5, CAPI_REQ);
31903 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
31904 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
31905 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
31906 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
31907 capimsg_setu16(skb->data, 16, len); /* Data length */
31908 diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
31909 index db621db..825ea1a 100644
31910 --- a/drivers/isdn/gigaset/common.c
31911 +++ b/drivers/isdn/gigaset/common.c
31912 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
31913 cs->commands_pending = 0;
31914 cs->cur_at_seq = 0;
31915 cs->gotfwver = -1;
31916 - cs->open_count = 0;
31917 + local_set(&cs->open_count, 0);
31918 cs->dev = NULL;
31919 cs->tty = NULL;
31920 cs->tty_dev = NULL;
31921 diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
31922 index 212efaf..f187c6b 100644
31923 --- a/drivers/isdn/gigaset/gigaset.h
31924 +++ b/drivers/isdn/gigaset/gigaset.h
31925 @@ -35,6 +35,7 @@
31926 #include <linux/tty_driver.h>
31927 #include <linux/list.h>
31928 #include <linux/atomic.h>
31929 +#include <asm/local.h>
31930
31931 #define GIG_VERSION {0, 5, 0, 0}
31932 #define GIG_COMPAT {0, 4, 0, 0}
31933 @@ -433,7 +434,7 @@ struct cardstate {
31934 spinlock_t cmdlock;
31935 unsigned curlen, cmdbytes;
31936
31937 - unsigned open_count;
31938 + local_t open_count;
31939 struct tty_struct *tty;
31940 struct tasklet_struct if_wake_tasklet;
31941 unsigned control_state;
31942 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
31943 index ee0a549..a7c9798 100644
31944 --- a/drivers/isdn/gigaset/interface.c
31945 +++ b/drivers/isdn/gigaset/interface.c
31946 @@ -163,9 +163,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
31947 }
31948 tty->driver_data = cs;
31949
31950 - ++cs->open_count;
31951 -
31952 - if (cs->open_count == 1) {
31953 + if (local_inc_return(&cs->open_count) == 1) {
31954 spin_lock_irqsave(&cs->lock, flags);
31955 cs->tty = tty;
31956 spin_unlock_irqrestore(&cs->lock, flags);
31957 @@ -193,10 +191,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
31958
31959 if (!cs->connected)
31960 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31961 - else if (!cs->open_count)
31962 + else if (!local_read(&cs->open_count))
31963 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31964 else {
31965 - if (!--cs->open_count) {
31966 + if (!local_dec_return(&cs->open_count)) {
31967 spin_lock_irqsave(&cs->lock, flags);
31968 cs->tty = NULL;
31969 spin_unlock_irqrestore(&cs->lock, flags);
31970 @@ -231,7 +229,7 @@ static int if_ioctl(struct tty_struct *tty,
31971 if (!cs->connected) {
31972 gig_dbg(DEBUG_IF, "not connected");
31973 retval = -ENODEV;
31974 - } else if (!cs->open_count)
31975 + } else if (!local_read(&cs->open_count))
31976 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31977 else {
31978 retval = 0;
31979 @@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
31980 retval = -ENODEV;
31981 goto done;
31982 }
31983 - if (!cs->open_count) {
31984 + if (!local_read(&cs->open_count)) {
31985 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31986 retval = -ENODEV;
31987 goto done;
31988 @@ -414,7 +412,7 @@ static int if_write_room(struct tty_struct *tty)
31989 if (!cs->connected) {
31990 gig_dbg(DEBUG_IF, "not connected");
31991 retval = -ENODEV;
31992 - } else if (!cs->open_count)
31993 + } else if (!local_read(&cs->open_count))
31994 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31995 else if (cs->mstate != MS_LOCKED) {
31996 dev_warn(cs->dev, "can't write to unlocked device\n");
31997 @@ -444,7 +442,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
31998
31999 if (!cs->connected)
32000 gig_dbg(DEBUG_IF, "not connected");
32001 - else if (!cs->open_count)
32002 + else if (!local_read(&cs->open_count))
32003 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32004 else if (cs->mstate != MS_LOCKED)
32005 dev_warn(cs->dev, "can't write to unlocked device\n");
32006 @@ -472,7 +470,7 @@ static void if_throttle(struct tty_struct *tty)
32007
32008 if (!cs->connected)
32009 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32010 - else if (!cs->open_count)
32011 + else if (!local_read(&cs->open_count))
32012 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32013 else
32014 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
32015 @@ -496,7 +494,7 @@ static void if_unthrottle(struct tty_struct *tty)
32016
32017 if (!cs->connected)
32018 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32019 - else if (!cs->open_count)
32020 + else if (!local_read(&cs->open_count))
32021 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32022 else
32023 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
32024 @@ -527,7 +525,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
32025 goto out;
32026 }
32027
32028 - if (!cs->open_count) {
32029 + if (!local_read(&cs->open_count)) {
32030 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32031 goto out;
32032 }
32033 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32034 index 2a57da59..e7a12ed 100644
32035 --- a/drivers/isdn/hardware/avm/b1.c
32036 +++ b/drivers/isdn/hardware/avm/b1.c
32037 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
32038 }
32039 if (left) {
32040 if (t4file->user) {
32041 - if (copy_from_user(buf, dp, left))
32042 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32043 return -EFAULT;
32044 } else {
32045 memcpy(buf, dp, left);
32046 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
32047 }
32048 if (left) {
32049 if (config->user) {
32050 - if (copy_from_user(buf, dp, left))
32051 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32052 return -EFAULT;
32053 } else {
32054 memcpy(buf, dp, left);
32055 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32056 index 85784a7..a19ca98 100644
32057 --- a/drivers/isdn/hardware/eicon/divasync.h
32058 +++ b/drivers/isdn/hardware/eicon/divasync.h
32059 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32060 } diva_didd_add_adapter_t;
32061 typedef struct _diva_didd_remove_adapter {
32062 IDI_CALL p_request;
32063 -} diva_didd_remove_adapter_t;
32064 +} __no_const diva_didd_remove_adapter_t;
32065 typedef struct _diva_didd_read_adapter_array {
32066 void * buffer;
32067 dword length;
32068 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32069 index a3bd163..8956575 100644
32070 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32071 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32072 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32073 typedef struct _diva_os_idi_adapter_interface {
32074 diva_init_card_proc_t cleanup_adapter_proc;
32075 diva_cmd_card_proc_t cmd_proc;
32076 -} diva_os_idi_adapter_interface_t;
32077 +} __no_const diva_os_idi_adapter_interface_t;
32078
32079 typedef struct _diva_os_xdi_adapter {
32080 struct list_head link;
32081 diff --git a/drivers/isdn/i4l/isdn_net.c b/drivers/isdn/i4l/isdn_net.c
32082 index 2339d73..802ab87 100644
32083 --- a/drivers/isdn/i4l/isdn_net.c
32084 +++ b/drivers/isdn/i4l/isdn_net.c
32085 @@ -1901,7 +1901,7 @@ static int isdn_net_header(struct sk_buff *skb, struct net_device *dev,
32086 {
32087 isdn_net_local *lp = netdev_priv(dev);
32088 unsigned char *p;
32089 - ushort len = 0;
32090 + int len = 0;
32091
32092 switch (lp->p_encap) {
32093 case ISDN_NET_ENCAP_ETHER:
32094 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32095 index 1f355bb..43f1fea 100644
32096 --- a/drivers/isdn/icn/icn.c
32097 +++ b/drivers/isdn/icn/icn.c
32098 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
32099 if (count > len)
32100 count = len;
32101 if (user) {
32102 - if (copy_from_user(msg, buf, count))
32103 + if (count > sizeof msg || copy_from_user(msg, buf, count))
32104 return -EFAULT;
32105 } else
32106 memcpy(msg, buf, count);
32107 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32108 index b5fdcb7..5b6c59f 100644
32109 --- a/drivers/lguest/core.c
32110 +++ b/drivers/lguest/core.c
32111 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
32112 * it's worked so far. The end address needs +1 because __get_vm_area
32113 * allocates an extra guard page, so we need space for that.
32114 */
32115 +
32116 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32117 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32118 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32119 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32120 +#else
32121 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32122 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32123 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32124 +#endif
32125 +
32126 if (!switcher_vma) {
32127 err = -ENOMEM;
32128 printk("lguest: could not map switcher pages high\n");
32129 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
32130 * Now the Switcher is mapped at the right address, we can't fail!
32131 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
32132 */
32133 - memcpy(switcher_vma->addr, start_switcher_text,
32134 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32135 end_switcher_text - start_switcher_text);
32136
32137 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32138 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
32139 index 65af42f..530c87a 100644
32140 --- a/drivers/lguest/x86/core.c
32141 +++ b/drivers/lguest/x86/core.c
32142 @@ -59,7 +59,7 @@ static struct {
32143 /* Offset from where switcher.S was compiled to where we've copied it */
32144 static unsigned long switcher_offset(void)
32145 {
32146 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
32147 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
32148 }
32149
32150 /* This cpu's struct lguest_pages. */
32151 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
32152 * These copies are pretty cheap, so we do them unconditionally: */
32153 /* Save the current Host top-level page directory.
32154 */
32155 +
32156 +#ifdef CONFIG_PAX_PER_CPU_PGD
32157 + pages->state.host_cr3 = read_cr3();
32158 +#else
32159 pages->state.host_cr3 = __pa(current->mm->pgd);
32160 +#endif
32161 +
32162 /*
32163 * Set up the Guest's page tables to see this CPU's pages (and no
32164 * other CPU's pages).
32165 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
32166 * compiled-in switcher code and the high-mapped copy we just made.
32167 */
32168 for (i = 0; i < IDT_ENTRIES; i++)
32169 - default_idt_entries[i] += switcher_offset();
32170 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
32171
32172 /*
32173 * Set up the Switcher's per-cpu areas.
32174 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
32175 * it will be undisturbed when we switch. To change %cs and jump we
32176 * need this structure to feed to Intel's "lcall" instruction.
32177 */
32178 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
32179 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
32180 lguest_entry.segment = LGUEST_CS;
32181
32182 /*
32183 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
32184 index 40634b0..4f5855e 100644
32185 --- a/drivers/lguest/x86/switcher_32.S
32186 +++ b/drivers/lguest/x86/switcher_32.S
32187 @@ -87,6 +87,7 @@
32188 #include <asm/page.h>
32189 #include <asm/segment.h>
32190 #include <asm/lguest.h>
32191 +#include <asm/processor-flags.h>
32192
32193 // We mark the start of the code to copy
32194 // It's placed in .text tho it's never run here
32195 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
32196 // Changes type when we load it: damn Intel!
32197 // For after we switch over our page tables
32198 // That entry will be read-only: we'd crash.
32199 +
32200 +#ifdef CONFIG_PAX_KERNEXEC
32201 + mov %cr0, %edx
32202 + xor $X86_CR0_WP, %edx
32203 + mov %edx, %cr0
32204 +#endif
32205 +
32206 movl $(GDT_ENTRY_TSS*8), %edx
32207 ltr %dx
32208
32209 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
32210 // Let's clear it again for our return.
32211 // The GDT descriptor of the Host
32212 // Points to the table after two "size" bytes
32213 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
32214 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
32215 // Clear "used" from type field (byte 5, bit 2)
32216 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
32217 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
32218 +
32219 +#ifdef CONFIG_PAX_KERNEXEC
32220 + mov %cr0, %eax
32221 + xor $X86_CR0_WP, %eax
32222 + mov %eax, %cr0
32223 +#endif
32224
32225 // Once our page table's switched, the Guest is live!
32226 // The Host fades as we run this final step.
32227 @@ -295,13 +309,12 @@ deliver_to_host:
32228 // I consulted gcc, and it gave
32229 // These instructions, which I gladly credit:
32230 leal (%edx,%ebx,8), %eax
32231 - movzwl (%eax),%edx
32232 - movl 4(%eax), %eax
32233 - xorw %ax, %ax
32234 - orl %eax, %edx
32235 + movl 4(%eax), %edx
32236 + movw (%eax), %dx
32237 // Now the address of the handler's in %edx
32238 // We call it now: its "iret" drops us home.
32239 - jmp *%edx
32240 + ljmp $__KERNEL_CS, $1f
32241 +1: jmp *%edx
32242
32243 // Every interrupt can come to us here
32244 // But we must truly tell each apart.
32245 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
32246 index 4daf9e5..b8d1d0f 100644
32247 --- a/drivers/macintosh/macio_asic.c
32248 +++ b/drivers/macintosh/macio_asic.c
32249 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
32250 * MacIO is matched against any Apple ID, it's probe() function
32251 * will then decide wether it applies or not
32252 */
32253 -static const struct pci_device_id __devinitdata pci_ids [] = { {
32254 +static const struct pci_device_id __devinitconst pci_ids [] = { {
32255 .vendor = PCI_VENDOR_ID_APPLE,
32256 .device = PCI_ANY_ID,
32257 .subvendor = PCI_ANY_ID,
32258 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
32259 index 31c2dc2..a2de7a6 100644
32260 --- a/drivers/md/dm-ioctl.c
32261 +++ b/drivers/md/dm-ioctl.c
32262 @@ -1589,7 +1589,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
32263 cmd == DM_LIST_VERSIONS_CMD)
32264 return 0;
32265
32266 - if ((cmd == DM_DEV_CREATE_CMD)) {
32267 + if (cmd == DM_DEV_CREATE_CMD) {
32268 if (!*param->name) {
32269 DMWARN("name not supplied when creating device");
32270 return -EINVAL;
32271 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
32272 index 9bfd057..01180bc 100644
32273 --- a/drivers/md/dm-raid1.c
32274 +++ b/drivers/md/dm-raid1.c
32275 @@ -40,7 +40,7 @@ enum dm_raid1_error {
32276
32277 struct mirror {
32278 struct mirror_set *ms;
32279 - atomic_t error_count;
32280 + atomic_unchecked_t error_count;
32281 unsigned long error_type;
32282 struct dm_dev *dev;
32283 sector_t offset;
32284 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
32285 struct mirror *m;
32286
32287 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
32288 - if (!atomic_read(&m->error_count))
32289 + if (!atomic_read_unchecked(&m->error_count))
32290 return m;
32291
32292 return NULL;
32293 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
32294 * simple way to tell if a device has encountered
32295 * errors.
32296 */
32297 - atomic_inc(&m->error_count);
32298 + atomic_inc_unchecked(&m->error_count);
32299
32300 if (test_and_set_bit(error_type, &m->error_type))
32301 return;
32302 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
32303 struct mirror *m = get_default_mirror(ms);
32304
32305 do {
32306 - if (likely(!atomic_read(&m->error_count)))
32307 + if (likely(!atomic_read_unchecked(&m->error_count)))
32308 return m;
32309
32310 if (m-- == ms->mirror)
32311 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
32312 {
32313 struct mirror *default_mirror = get_default_mirror(m->ms);
32314
32315 - return !atomic_read(&default_mirror->error_count);
32316 + return !atomic_read_unchecked(&default_mirror->error_count);
32317 }
32318
32319 static int mirror_available(struct mirror_set *ms, struct bio *bio)
32320 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
32321 */
32322 if (likely(region_in_sync(ms, region, 1)))
32323 m = choose_mirror(ms, bio->bi_sector);
32324 - else if (m && atomic_read(&m->error_count))
32325 + else if (m && atomic_read_unchecked(&m->error_count))
32326 m = NULL;
32327
32328 if (likely(m))
32329 @@ -937,7 +937,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
32330 }
32331
32332 ms->mirror[mirror].ms = ms;
32333 - atomic_set(&(ms->mirror[mirror].error_count), 0);
32334 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
32335 ms->mirror[mirror].error_type = 0;
32336 ms->mirror[mirror].offset = offset;
32337
32338 @@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_target *ti)
32339 */
32340 static char device_status_char(struct mirror *m)
32341 {
32342 - if (!atomic_read(&(m->error_count)))
32343 + if (!atomic_read_unchecked(&(m->error_count)))
32344 return 'A';
32345
32346 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
32347 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
32348 index 3d80cf0..b77cc47 100644
32349 --- a/drivers/md/dm-stripe.c
32350 +++ b/drivers/md/dm-stripe.c
32351 @@ -20,7 +20,7 @@ struct stripe {
32352 struct dm_dev *dev;
32353 sector_t physical_start;
32354
32355 - atomic_t error_count;
32356 + atomic_unchecked_t error_count;
32357 };
32358
32359 struct stripe_c {
32360 @@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
32361 kfree(sc);
32362 return r;
32363 }
32364 - atomic_set(&(sc->stripe[i].error_count), 0);
32365 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
32366 }
32367
32368 ti->private = sc;
32369 @@ -314,7 +314,7 @@ static int stripe_status(struct dm_target *ti,
32370 DMEMIT("%d ", sc->stripes);
32371 for (i = 0; i < sc->stripes; i++) {
32372 DMEMIT("%s ", sc->stripe[i].dev->name);
32373 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
32374 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
32375 'D' : 'A';
32376 }
32377 buffer[i] = '\0';
32378 @@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
32379 */
32380 for (i = 0; i < sc->stripes; i++)
32381 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
32382 - atomic_inc(&(sc->stripe[i].error_count));
32383 - if (atomic_read(&(sc->stripe[i].error_count)) <
32384 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
32385 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
32386 DM_IO_ERROR_THRESHOLD)
32387 schedule_work(&sc->trigger_event);
32388 }
32389 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
32390 index 8e91321..fd17aef 100644
32391 --- a/drivers/md/dm-table.c
32392 +++ b/drivers/md/dm-table.c
32393 @@ -391,7 +391,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
32394 if (!dev_size)
32395 return 0;
32396
32397 - if ((start >= dev_size) || (start + len > dev_size)) {
32398 + if ((start >= dev_size) || (len > dev_size - start)) {
32399 DMWARN("%s: %s too small for target: "
32400 "start=%llu, len=%llu, dev_size=%llu",
32401 dm_device_name(ti->table->md), bdevname(bdev, b),
32402 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
32403 index 59c4f04..4c7b661 100644
32404 --- a/drivers/md/dm-thin-metadata.c
32405 +++ b/drivers/md/dm-thin-metadata.c
32406 @@ -431,7 +431,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
32407
32408 pmd->info.tm = tm;
32409 pmd->info.levels = 2;
32410 - pmd->info.value_type.context = pmd->data_sm;
32411 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
32412 pmd->info.value_type.size = sizeof(__le64);
32413 pmd->info.value_type.inc = data_block_inc;
32414 pmd->info.value_type.dec = data_block_dec;
32415 @@ -450,7 +450,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
32416
32417 pmd->bl_info.tm = tm;
32418 pmd->bl_info.levels = 1;
32419 - pmd->bl_info.value_type.context = pmd->data_sm;
32420 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
32421 pmd->bl_info.value_type.size = sizeof(__le64);
32422 pmd->bl_info.value_type.inc = data_block_inc;
32423 pmd->bl_info.value_type.dec = data_block_dec;
32424 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
32425 index 4720f68..78d1df7 100644
32426 --- a/drivers/md/dm.c
32427 +++ b/drivers/md/dm.c
32428 @@ -177,9 +177,9 @@ struct mapped_device {
32429 /*
32430 * Event handling.
32431 */
32432 - atomic_t event_nr;
32433 + atomic_unchecked_t event_nr;
32434 wait_queue_head_t eventq;
32435 - atomic_t uevent_seq;
32436 + atomic_unchecked_t uevent_seq;
32437 struct list_head uevent_list;
32438 spinlock_t uevent_lock; /* Protect access to uevent_list */
32439
32440 @@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
32441 rwlock_init(&md->map_lock);
32442 atomic_set(&md->holders, 1);
32443 atomic_set(&md->open_count, 0);
32444 - atomic_set(&md->event_nr, 0);
32445 - atomic_set(&md->uevent_seq, 0);
32446 + atomic_set_unchecked(&md->event_nr, 0);
32447 + atomic_set_unchecked(&md->uevent_seq, 0);
32448 INIT_LIST_HEAD(&md->uevent_list);
32449 spin_lock_init(&md->uevent_lock);
32450
32451 @@ -1980,7 +1980,7 @@ static void event_callback(void *context)
32452
32453 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
32454
32455 - atomic_inc(&md->event_nr);
32456 + atomic_inc_unchecked(&md->event_nr);
32457 wake_up(&md->eventq);
32458 }
32459
32460 @@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
32461
32462 uint32_t dm_next_uevent_seq(struct mapped_device *md)
32463 {
32464 - return atomic_add_return(1, &md->uevent_seq);
32465 + return atomic_add_return_unchecked(1, &md->uevent_seq);
32466 }
32467
32468 uint32_t dm_get_event_nr(struct mapped_device *md)
32469 {
32470 - return atomic_read(&md->event_nr);
32471 + return atomic_read_unchecked(&md->event_nr);
32472 }
32473
32474 int dm_wait_event(struct mapped_device *md, int event_nr)
32475 {
32476 return wait_event_interruptible(md->eventq,
32477 - (event_nr != atomic_read(&md->event_nr)));
32478 + (event_nr != atomic_read_unchecked(&md->event_nr)));
32479 }
32480
32481 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
32482 diff --git a/drivers/md/md.c b/drivers/md/md.c
32483 index f47f1f8..b7f559e 100644
32484 --- a/drivers/md/md.c
32485 +++ b/drivers/md/md.c
32486 @@ -278,10 +278,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
32487 * start build, activate spare
32488 */
32489 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
32490 -static atomic_t md_event_count;
32491 +static atomic_unchecked_t md_event_count;
32492 void md_new_event(struct mddev *mddev)
32493 {
32494 - atomic_inc(&md_event_count);
32495 + atomic_inc_unchecked(&md_event_count);
32496 wake_up(&md_event_waiters);
32497 }
32498 EXPORT_SYMBOL_GPL(md_new_event);
32499 @@ -291,7 +291,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
32500 */
32501 static void md_new_event_inintr(struct mddev *mddev)
32502 {
32503 - atomic_inc(&md_event_count);
32504 + atomic_inc_unchecked(&md_event_count);
32505 wake_up(&md_event_waiters);
32506 }
32507
32508 @@ -1525,7 +1525,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
32509
32510 rdev->preferred_minor = 0xffff;
32511 rdev->data_offset = le64_to_cpu(sb->data_offset);
32512 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
32513 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
32514
32515 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
32516 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
32517 @@ -1742,7 +1742,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
32518 else
32519 sb->resync_offset = cpu_to_le64(0);
32520
32521 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
32522 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
32523
32524 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
32525 sb->size = cpu_to_le64(mddev->dev_sectors);
32526 @@ -2639,7 +2639,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
32527 static ssize_t
32528 errors_show(struct md_rdev *rdev, char *page)
32529 {
32530 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
32531 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
32532 }
32533
32534 static ssize_t
32535 @@ -2648,7 +2648,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
32536 char *e;
32537 unsigned long n = simple_strtoul(buf, &e, 10);
32538 if (*buf && (*e == 0 || *e == '\n')) {
32539 - atomic_set(&rdev->corrected_errors, n);
32540 + atomic_set_unchecked(&rdev->corrected_errors, n);
32541 return len;
32542 }
32543 return -EINVAL;
32544 @@ -3039,8 +3039,8 @@ int md_rdev_init(struct md_rdev *rdev)
32545 rdev->sb_loaded = 0;
32546 rdev->bb_page = NULL;
32547 atomic_set(&rdev->nr_pending, 0);
32548 - atomic_set(&rdev->read_errors, 0);
32549 - atomic_set(&rdev->corrected_errors, 0);
32550 + atomic_set_unchecked(&rdev->read_errors, 0);
32551 + atomic_set_unchecked(&rdev->corrected_errors, 0);
32552
32553 INIT_LIST_HEAD(&rdev->same_set);
32554 init_waitqueue_head(&rdev->blocked_wait);
32555 @@ -6683,7 +6683,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
32556
32557 spin_unlock(&pers_lock);
32558 seq_printf(seq, "\n");
32559 - seq->poll_event = atomic_read(&md_event_count);
32560 + seq->poll_event = atomic_read_unchecked(&md_event_count);
32561 return 0;
32562 }
32563 if (v == (void*)2) {
32564 @@ -6772,7 +6772,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
32565 chunk_kb ? "KB" : "B");
32566 if (bitmap->file) {
32567 seq_printf(seq, ", file: ");
32568 - seq_path(seq, &bitmap->file->f_path, " \t\n");
32569 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
32570 }
32571
32572 seq_printf(seq, "\n");
32573 @@ -6803,7 +6803,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
32574 return error;
32575
32576 seq = file->private_data;
32577 - seq->poll_event = atomic_read(&md_event_count);
32578 + seq->poll_event = atomic_read_unchecked(&md_event_count);
32579 return error;
32580 }
32581
32582 @@ -6817,7 +6817,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
32583 /* always allow read */
32584 mask = POLLIN | POLLRDNORM;
32585
32586 - if (seq->poll_event != atomic_read(&md_event_count))
32587 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
32588 mask |= POLLERR | POLLPRI;
32589 return mask;
32590 }
32591 @@ -6861,7 +6861,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
32592 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
32593 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
32594 (int)part_stat_read(&disk->part0, sectors[1]) -
32595 - atomic_read(&disk->sync_io);
32596 + atomic_read_unchecked(&disk->sync_io);
32597 /* sync IO will cause sync_io to increase before the disk_stats
32598 * as sync_io is counted when a request starts, and
32599 * disk_stats is counted when it completes.
32600 diff --git a/drivers/md/md.h b/drivers/md/md.h
32601 index cf742d9..7c7c745 100644
32602 --- a/drivers/md/md.h
32603 +++ b/drivers/md/md.h
32604 @@ -120,13 +120,13 @@ struct md_rdev {
32605 * only maintained for arrays that
32606 * support hot removal
32607 */
32608 - atomic_t read_errors; /* number of consecutive read errors that
32609 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
32610 * we have tried to ignore.
32611 */
32612 struct timespec last_read_error; /* monotonic time since our
32613 * last read error
32614 */
32615 - atomic_t corrected_errors; /* number of corrected read errors,
32616 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
32617 * for reporting to userspace and storing
32618 * in superblock.
32619 */
32620 @@ -410,7 +410,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
32621
32622 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
32623 {
32624 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32625 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32626 }
32627
32628 struct md_personality
32629 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
32630 index 50ed53b..4f29d7d 100644
32631 --- a/drivers/md/persistent-data/dm-space-map-checker.c
32632 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
32633 @@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
32634 /*----------------------------------------------------------------*/
32635
32636 struct sm_checker {
32637 - struct dm_space_map sm;
32638 + dm_space_map_no_const sm;
32639
32640 struct count_array old_counts;
32641 struct count_array counts;
32642 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
32643 index fc469ba..2d91555 100644
32644 --- a/drivers/md/persistent-data/dm-space-map-disk.c
32645 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
32646 @@ -23,7 +23,7 @@
32647 * Space map interface.
32648 */
32649 struct sm_disk {
32650 - struct dm_space_map sm;
32651 + dm_space_map_no_const sm;
32652
32653 struct ll_disk ll;
32654 struct ll_disk old_ll;
32655 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
32656 index e89ae5e..062e4c2 100644
32657 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
32658 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
32659 @@ -43,7 +43,7 @@ struct block_op {
32660 };
32661
32662 struct sm_metadata {
32663 - struct dm_space_map sm;
32664 + dm_space_map_no_const sm;
32665
32666 struct ll_disk ll;
32667 struct ll_disk old_ll;
32668 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
32669 index 1cbfc6b..56e1dbb 100644
32670 --- a/drivers/md/persistent-data/dm-space-map.h
32671 +++ b/drivers/md/persistent-data/dm-space-map.h
32672 @@ -60,6 +60,7 @@ struct dm_space_map {
32673 int (*root_size)(struct dm_space_map *sm, size_t *result);
32674 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
32675 };
32676 +typedef struct dm_space_map __no_const dm_space_map_no_const;
32677
32678 /*----------------------------------------------------------------*/
32679
32680 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
32681 index 7d9e071..015b1d5 100644
32682 --- a/drivers/md/raid1.c
32683 +++ b/drivers/md/raid1.c
32684 @@ -1568,7 +1568,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
32685 if (r1_sync_page_io(rdev, sect, s,
32686 bio->bi_io_vec[idx].bv_page,
32687 READ) != 0)
32688 - atomic_add(s, &rdev->corrected_errors);
32689 + atomic_add_unchecked(s, &rdev->corrected_errors);
32690 }
32691 sectors -= s;
32692 sect += s;
32693 @@ -1781,7 +1781,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
32694 test_bit(In_sync, &rdev->flags)) {
32695 if (r1_sync_page_io(rdev, sect, s,
32696 conf->tmppage, READ)) {
32697 - atomic_add(s, &rdev->corrected_errors);
32698 + atomic_add_unchecked(s, &rdev->corrected_errors);
32699 printk(KERN_INFO
32700 "md/raid1:%s: read error corrected "
32701 "(%d sectors at %llu on %s)\n",
32702 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
32703 index 685ddf3..955b087 100644
32704 --- a/drivers/md/raid10.c
32705 +++ b/drivers/md/raid10.c
32706 @@ -1440,7 +1440,7 @@ static void end_sync_read(struct bio *bio, int error)
32707 /* The write handler will notice the lack of
32708 * R10BIO_Uptodate and record any errors etc
32709 */
32710 - atomic_add(r10_bio->sectors,
32711 + atomic_add_unchecked(r10_bio->sectors,
32712 &conf->mirrors[d].rdev->corrected_errors);
32713
32714 /* for reconstruct, we always reschedule after a read.
32715 @@ -1740,7 +1740,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
32716 {
32717 struct timespec cur_time_mon;
32718 unsigned long hours_since_last;
32719 - unsigned int read_errors = atomic_read(&rdev->read_errors);
32720 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
32721
32722 ktime_get_ts(&cur_time_mon);
32723
32724 @@ -1762,9 +1762,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
32725 * overflowing the shift of read_errors by hours_since_last.
32726 */
32727 if (hours_since_last >= 8 * sizeof(read_errors))
32728 - atomic_set(&rdev->read_errors, 0);
32729 + atomic_set_unchecked(&rdev->read_errors, 0);
32730 else
32731 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
32732 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
32733 }
32734
32735 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
32736 @@ -1814,8 +1814,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
32737 return;
32738
32739 check_decay_read_errors(mddev, rdev);
32740 - atomic_inc(&rdev->read_errors);
32741 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
32742 + atomic_inc_unchecked(&rdev->read_errors);
32743 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
32744 char b[BDEVNAME_SIZE];
32745 bdevname(rdev->bdev, b);
32746
32747 @@ -1823,7 +1823,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
32748 "md/raid10:%s: %s: Raid device exceeded "
32749 "read_error threshold [cur %d:max %d]\n",
32750 mdname(mddev), b,
32751 - atomic_read(&rdev->read_errors), max_read_errors);
32752 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
32753 printk(KERN_NOTICE
32754 "md/raid10:%s: %s: Failing raid device\n",
32755 mdname(mddev), b);
32756 @@ -1968,7 +1968,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
32757 (unsigned long long)(
32758 sect + rdev->data_offset),
32759 bdevname(rdev->bdev, b));
32760 - atomic_add(s, &rdev->corrected_errors);
32761 + atomic_add_unchecked(s, &rdev->corrected_errors);
32762 }
32763
32764 rdev_dec_pending(rdev, mddev);
32765 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
32766 index 858fdbb..b2dac95 100644
32767 --- a/drivers/md/raid5.c
32768 +++ b/drivers/md/raid5.c
32769 @@ -1610,19 +1610,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
32770 (unsigned long long)(sh->sector
32771 + rdev->data_offset),
32772 bdevname(rdev->bdev, b));
32773 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
32774 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
32775 clear_bit(R5_ReadError, &sh->dev[i].flags);
32776 clear_bit(R5_ReWrite, &sh->dev[i].flags);
32777 }
32778 - if (atomic_read(&conf->disks[i].rdev->read_errors))
32779 - atomic_set(&conf->disks[i].rdev->read_errors, 0);
32780 + if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
32781 + atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
32782 } else {
32783 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
32784 int retry = 0;
32785 rdev = conf->disks[i].rdev;
32786
32787 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
32788 - atomic_inc(&rdev->read_errors);
32789 + atomic_inc_unchecked(&rdev->read_errors);
32790 if (conf->mddev->degraded >= conf->max_degraded)
32791 printk_ratelimited(
32792 KERN_WARNING
32793 @@ -1642,7 +1642,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
32794 (unsigned long long)(sh->sector
32795 + rdev->data_offset),
32796 bdn);
32797 - else if (atomic_read(&rdev->read_errors)
32798 + else if (atomic_read_unchecked(&rdev->read_errors)
32799 > conf->max_nr_stripes)
32800 printk(KERN_WARNING
32801 "md/raid:%s: Too many read errors, failing device %s.\n",
32802 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
32803 index ba9a643..e474ab5 100644
32804 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
32805 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
32806 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
32807 .subvendor = _subvend, .subdevice = _subdev, \
32808 .driver_data = (unsigned long)&_driverdata }
32809
32810 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
32811 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
32812 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
32813 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
32814 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
32815 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
32816 index a7d876f..8c21b61 100644
32817 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
32818 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
32819 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
32820 union {
32821 dmx_ts_cb ts;
32822 dmx_section_cb sec;
32823 - } cb;
32824 + } __no_const cb;
32825
32826 struct dvb_demux *demux;
32827 void *priv;
32828 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
32829 index f732877..d38c35a 100644
32830 --- a/drivers/media/dvb/dvb-core/dvbdev.c
32831 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
32832 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
32833 const struct dvb_device *template, void *priv, int type)
32834 {
32835 struct dvb_device *dvbdev;
32836 - struct file_operations *dvbdevfops;
32837 + file_operations_no_const *dvbdevfops;
32838 struct device *clsdev;
32839 int minor;
32840 int id;
32841 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
32842 index 9f2a02c..5920f88 100644
32843 --- a/drivers/media/dvb/dvb-usb/cxusb.c
32844 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
32845 @@ -1069,7 +1069,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
32846 struct dib0700_adapter_state {
32847 int (*set_param_save) (struct dvb_frontend *,
32848 struct dvb_frontend_parameters *);
32849 -};
32850 +} __no_const;
32851
32852 static int dib7070_set_param_override(struct dvb_frontend *fe,
32853 struct dvb_frontend_parameters *fep)
32854 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
32855 index f103ec1..5e8968b 100644
32856 --- a/drivers/media/dvb/dvb-usb/dw2102.c
32857 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
32858 @@ -95,7 +95,7 @@ struct su3000_state {
32859
32860 struct s6x0_state {
32861 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
32862 -};
32863 +} __no_const;
32864
32865 /* debug */
32866 static int dvb_usb_dw2102_debug;
32867 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
32868 index 404f63a..4796533 100644
32869 --- a/drivers/media/dvb/frontends/dib3000.h
32870 +++ b/drivers/media/dvb/frontends/dib3000.h
32871 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
32872 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
32873 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
32874 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
32875 -};
32876 +} __no_const;
32877
32878 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
32879 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
32880 diff --git a/drivers/media/dvb/frontends/ds3000.c b/drivers/media/dvb/frontends/ds3000.c
32881 index 90bf573..e8463da 100644
32882 --- a/drivers/media/dvb/frontends/ds3000.c
32883 +++ b/drivers/media/dvb/frontends/ds3000.c
32884 @@ -1210,7 +1210,7 @@ static int ds3000_set_frontend(struct dvb_frontend *fe,
32885
32886 for (i = 0; i < 30 ; i++) {
32887 ds3000_read_status(fe, &status);
32888 - if (status && FE_HAS_LOCK)
32889 + if (status & FE_HAS_LOCK)
32890 break;
32891
32892 msleep(10);
32893 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
32894 index 0564192..75b16f5 100644
32895 --- a/drivers/media/dvb/ngene/ngene-cards.c
32896 +++ b/drivers/media/dvb/ngene/ngene-cards.c
32897 @@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
32898
32899 /****************************************************************************/
32900
32901 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
32902 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
32903 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
32904 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
32905 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
32906 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
32907 index 16a089f..ab1667d 100644
32908 --- a/drivers/media/radio/radio-cadet.c
32909 +++ b/drivers/media/radio/radio-cadet.c
32910 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
32911 unsigned char readbuf[RDS_BUFFER];
32912 int i = 0;
32913
32914 + if (count > RDS_BUFFER)
32915 + return -EFAULT;
32916 mutex_lock(&dev->lock);
32917 if (dev->rdsstat == 0) {
32918 dev->rdsstat = 1;
32919 diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
32920 index 61287fc..8b08712 100644
32921 --- a/drivers/media/rc/redrat3.c
32922 +++ b/drivers/media/rc/redrat3.c
32923 @@ -905,7 +905,7 @@ static int redrat3_set_tx_carrier(struct rc_dev *dev, u32 carrier)
32924 return carrier;
32925 }
32926
32927 -static int redrat3_transmit_ir(struct rc_dev *rcdev, int *txbuf, u32 n)
32928 +static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, u32 n)
32929 {
32930 struct redrat3_dev *rr3 = rcdev->priv;
32931 struct device *dev = rr3->dev;
32932 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
32933 index 9cde353..8c6a1c3 100644
32934 --- a/drivers/media/video/au0828/au0828.h
32935 +++ b/drivers/media/video/au0828/au0828.h
32936 @@ -191,7 +191,7 @@ struct au0828_dev {
32937
32938 /* I2C */
32939 struct i2c_adapter i2c_adap;
32940 - struct i2c_algorithm i2c_algo;
32941 + i2c_algorithm_no_const i2c_algo;
32942 struct i2c_client i2c_client;
32943 u32 i2c_rc;
32944
32945 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
32946 index 68d1240..46b32eb 100644
32947 --- a/drivers/media/video/cx88/cx88-alsa.c
32948 +++ b/drivers/media/video/cx88/cx88-alsa.c
32949 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
32950 * Only boards with eeprom and byte 1 at eeprom=1 have it
32951 */
32952
32953 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
32954 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
32955 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
32956 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
32957 {0, }
32958 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
32959 index 305e6aa..0143317 100644
32960 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
32961 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
32962 @@ -196,7 +196,7 @@ struct pvr2_hdw {
32963
32964 /* I2C stuff */
32965 struct i2c_adapter i2c_adap;
32966 - struct i2c_algorithm i2c_algo;
32967 + i2c_algorithm_no_const i2c_algo;
32968 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
32969 int i2c_cx25840_hack_state;
32970 int i2c_linked;
32971 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
32972 index a0895bf..b7ebb1b 100644
32973 --- a/drivers/media/video/timblogiw.c
32974 +++ b/drivers/media/video/timblogiw.c
32975 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
32976
32977 /* Platform device functions */
32978
32979 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
32980 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
32981 .vidioc_querycap = timblogiw_querycap,
32982 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
32983 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
32984 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
32985 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
32986 };
32987
32988 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
32989 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
32990 .owner = THIS_MODULE,
32991 .open = timblogiw_open,
32992 .release = timblogiw_close,
32993 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
32994 index e9c6a60..daf6a33 100644
32995 --- a/drivers/message/fusion/mptbase.c
32996 +++ b/drivers/message/fusion/mptbase.c
32997 @@ -6753,8 +6753,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
32998 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
32999 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33000
33001 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33002 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33003 +#else
33004 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33005 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33006 +#endif
33007 +
33008 /*
33009 * Rounding UP to nearest 4-kB boundary here...
33010 */
33011 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33012 index 9d95042..b808101 100644
33013 --- a/drivers/message/fusion/mptsas.c
33014 +++ b/drivers/message/fusion/mptsas.c
33015 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33016 return 0;
33017 }
33018
33019 +static inline void
33020 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33021 +{
33022 + if (phy_info->port_details) {
33023 + phy_info->port_details->rphy = rphy;
33024 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33025 + ioc->name, rphy));
33026 + }
33027 +
33028 + if (rphy) {
33029 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33030 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33031 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33032 + ioc->name, rphy, rphy->dev.release));
33033 + }
33034 +}
33035 +
33036 /* no mutex */
33037 static void
33038 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33039 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33040 return NULL;
33041 }
33042
33043 -static inline void
33044 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33045 -{
33046 - if (phy_info->port_details) {
33047 - phy_info->port_details->rphy = rphy;
33048 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33049 - ioc->name, rphy));
33050 - }
33051 -
33052 - if (rphy) {
33053 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33054 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33055 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33056 - ioc->name, rphy, rphy->dev.release));
33057 - }
33058 -}
33059 -
33060 static inline struct sas_port *
33061 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33062 {
33063 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
33064 index 0c3ced7..1fe34ec 100644
33065 --- a/drivers/message/fusion/mptscsih.c
33066 +++ b/drivers/message/fusion/mptscsih.c
33067 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33068
33069 h = shost_priv(SChost);
33070
33071 - if (h) {
33072 - if (h->info_kbuf == NULL)
33073 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33074 - return h->info_kbuf;
33075 - h->info_kbuf[0] = '\0';
33076 + if (!h)
33077 + return NULL;
33078
33079 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33080 - h->info_kbuf[size-1] = '\0';
33081 - }
33082 + if (h->info_kbuf == NULL)
33083 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33084 + return h->info_kbuf;
33085 + h->info_kbuf[0] = '\0';
33086 +
33087 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33088 + h->info_kbuf[size-1] = '\0';
33089
33090 return h->info_kbuf;
33091 }
33092 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
33093 index 07dbeaf..5533142 100644
33094 --- a/drivers/message/i2o/i2o_proc.c
33095 +++ b/drivers/message/i2o/i2o_proc.c
33096 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
33097 "Array Controller Device"
33098 };
33099
33100 -static char *chtostr(u8 * chars, int n)
33101 -{
33102 - char tmp[256];
33103 - tmp[0] = 0;
33104 - return strncat(tmp, (char *)chars, n);
33105 -}
33106 -
33107 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33108 char *group)
33109 {
33110 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
33111
33112 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33113 seq_printf(seq, "%-#8x", ddm_table.module_id);
33114 - seq_printf(seq, "%-29s",
33115 - chtostr(ddm_table.module_name_version, 28));
33116 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33117 seq_printf(seq, "%9d ", ddm_table.data_size);
33118 seq_printf(seq, "%8d", ddm_table.code_size);
33119
33120 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
33121
33122 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33123 seq_printf(seq, "%-#8x", dst->module_id);
33124 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33125 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33126 + seq_printf(seq, "%-.28s", dst->module_name_version);
33127 + seq_printf(seq, "%-.8s", dst->date);
33128 seq_printf(seq, "%8d ", dst->module_size);
33129 seq_printf(seq, "%8d ", dst->mpb_size);
33130 seq_printf(seq, "0x%04x", dst->module_flags);
33131 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
33132 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
33133 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
33134 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
33135 - seq_printf(seq, "Vendor info : %s\n",
33136 - chtostr((u8 *) (work32 + 2), 16));
33137 - seq_printf(seq, "Product info : %s\n",
33138 - chtostr((u8 *) (work32 + 6), 16));
33139 - seq_printf(seq, "Description : %s\n",
33140 - chtostr((u8 *) (work32 + 10), 16));
33141 - seq_printf(seq, "Product rev. : %s\n",
33142 - chtostr((u8 *) (work32 + 14), 8));
33143 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
33144 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
33145 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
33146 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
33147
33148 seq_printf(seq, "Serial number : ");
33149 print_serial_number(seq, (u8 *) (work32 + 16),
33150 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
33151 }
33152
33153 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
33154 - seq_printf(seq, "Module name : %s\n",
33155 - chtostr(result.module_name, 24));
33156 - seq_printf(seq, "Module revision : %s\n",
33157 - chtostr(result.module_rev, 8));
33158 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
33159 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
33160
33161 seq_printf(seq, "Serial number : ");
33162 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
33163 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
33164 return 0;
33165 }
33166
33167 - seq_printf(seq, "Device name : %s\n",
33168 - chtostr(result.device_name, 64));
33169 - seq_printf(seq, "Service name : %s\n",
33170 - chtostr(result.service_name, 64));
33171 - seq_printf(seq, "Physical name : %s\n",
33172 - chtostr(result.physical_location, 64));
33173 - seq_printf(seq, "Instance number : %s\n",
33174 - chtostr(result.instance_number, 4));
33175 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
33176 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
33177 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
33178 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
33179
33180 return 0;
33181 }
33182 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
33183 index a8c08f3..155fe3d 100644
33184 --- a/drivers/message/i2o/iop.c
33185 +++ b/drivers/message/i2o/iop.c
33186 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
33187
33188 spin_lock_irqsave(&c->context_list_lock, flags);
33189
33190 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
33191 - atomic_inc(&c->context_list_counter);
33192 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
33193 + atomic_inc_unchecked(&c->context_list_counter);
33194
33195 - entry->context = atomic_read(&c->context_list_counter);
33196 + entry->context = atomic_read_unchecked(&c->context_list_counter);
33197
33198 list_add(&entry->list, &c->context_list);
33199
33200 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
33201
33202 #if BITS_PER_LONG == 64
33203 spin_lock_init(&c->context_list_lock);
33204 - atomic_set(&c->context_list_counter, 0);
33205 + atomic_set_unchecked(&c->context_list_counter, 0);
33206 INIT_LIST_HEAD(&c->context_list);
33207 #endif
33208
33209 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
33210 index 7ce65f4..e66e9bc 100644
33211 --- a/drivers/mfd/abx500-core.c
33212 +++ b/drivers/mfd/abx500-core.c
33213 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
33214
33215 struct abx500_device_entry {
33216 struct list_head list;
33217 - struct abx500_ops ops;
33218 + abx500_ops_no_const ops;
33219 struct device *dev;
33220 };
33221
33222 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
33223 index 5c2a06a..8fa077c 100644
33224 --- a/drivers/mfd/janz-cmodio.c
33225 +++ b/drivers/mfd/janz-cmodio.c
33226 @@ -13,6 +13,7 @@
33227
33228 #include <linux/kernel.h>
33229 #include <linux/module.h>
33230 +#include <linux/slab.h>
33231 #include <linux/init.h>
33232 #include <linux/pci.h>
33233 #include <linux/interrupt.h>
33234 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
33235 index 29d12a7..f900ba4 100644
33236 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
33237 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
33238 @@ -464,7 +464,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
33239 * the lid is closed. This leads to interrupts as soon as a little move
33240 * is done.
33241 */
33242 - atomic_inc(&lis3->count);
33243 + atomic_inc_unchecked(&lis3->count);
33244
33245 wake_up_interruptible(&lis3->misc_wait);
33246 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
33247 @@ -550,7 +550,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
33248 if (lis3->pm_dev)
33249 pm_runtime_get_sync(lis3->pm_dev);
33250
33251 - atomic_set(&lis3->count, 0);
33252 + atomic_set_unchecked(&lis3->count, 0);
33253 return 0;
33254 }
33255
33256 @@ -583,7 +583,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
33257 add_wait_queue(&lis3->misc_wait, &wait);
33258 while (true) {
33259 set_current_state(TASK_INTERRUPTIBLE);
33260 - data = atomic_xchg(&lis3->count, 0);
33261 + data = atomic_xchg_unchecked(&lis3->count, 0);
33262 if (data)
33263 break;
33264
33265 @@ -624,7 +624,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
33266 struct lis3lv02d, miscdev);
33267
33268 poll_wait(file, &lis3->misc_wait, wait);
33269 - if (atomic_read(&lis3->count))
33270 + if (atomic_read_unchecked(&lis3->count))
33271 return POLLIN | POLLRDNORM;
33272 return 0;
33273 }
33274 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
33275 index 2b1482a..5d33616 100644
33276 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
33277 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
33278 @@ -266,7 +266,7 @@ struct lis3lv02d {
33279 struct input_polled_dev *idev; /* input device */
33280 struct platform_device *pdev; /* platform device */
33281 struct regulator_bulk_data regulators[2];
33282 - atomic_t count; /* interrupt count after last read */
33283 + atomic_unchecked_t count; /* interrupt count after last read */
33284 union axis_conversion ac; /* hw -> logical axis */
33285 int mapped_btns[3];
33286
33287 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
33288 index 2f30bad..c4c13d0 100644
33289 --- a/drivers/misc/sgi-gru/gruhandles.c
33290 +++ b/drivers/misc/sgi-gru/gruhandles.c
33291 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
33292 unsigned long nsec;
33293
33294 nsec = CLKS2NSEC(clks);
33295 - atomic_long_inc(&mcs_op_statistics[op].count);
33296 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
33297 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
33298 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
33299 if (mcs_op_statistics[op].max < nsec)
33300 mcs_op_statistics[op].max = nsec;
33301 }
33302 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
33303 index 7768b87..f8aac38 100644
33304 --- a/drivers/misc/sgi-gru/gruprocfs.c
33305 +++ b/drivers/misc/sgi-gru/gruprocfs.c
33306 @@ -32,9 +32,9 @@
33307
33308 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
33309
33310 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
33311 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
33312 {
33313 - unsigned long val = atomic_long_read(v);
33314 + unsigned long val = atomic_long_read_unchecked(v);
33315
33316 seq_printf(s, "%16lu %s\n", val, id);
33317 }
33318 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
33319
33320 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
33321 for (op = 0; op < mcsop_last; op++) {
33322 - count = atomic_long_read(&mcs_op_statistics[op].count);
33323 - total = atomic_long_read(&mcs_op_statistics[op].total);
33324 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
33325 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
33326 max = mcs_op_statistics[op].max;
33327 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
33328 count ? total / count : 0, max);
33329 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
33330 index 5c3ce24..4915ccb 100644
33331 --- a/drivers/misc/sgi-gru/grutables.h
33332 +++ b/drivers/misc/sgi-gru/grutables.h
33333 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
33334 * GRU statistics.
33335 */
33336 struct gru_stats_s {
33337 - atomic_long_t vdata_alloc;
33338 - atomic_long_t vdata_free;
33339 - atomic_long_t gts_alloc;
33340 - atomic_long_t gts_free;
33341 - atomic_long_t gms_alloc;
33342 - atomic_long_t gms_free;
33343 - atomic_long_t gts_double_allocate;
33344 - atomic_long_t assign_context;
33345 - atomic_long_t assign_context_failed;
33346 - atomic_long_t free_context;
33347 - atomic_long_t load_user_context;
33348 - atomic_long_t load_kernel_context;
33349 - atomic_long_t lock_kernel_context;
33350 - atomic_long_t unlock_kernel_context;
33351 - atomic_long_t steal_user_context;
33352 - atomic_long_t steal_kernel_context;
33353 - atomic_long_t steal_context_failed;
33354 - atomic_long_t nopfn;
33355 - atomic_long_t asid_new;
33356 - atomic_long_t asid_next;
33357 - atomic_long_t asid_wrap;
33358 - atomic_long_t asid_reuse;
33359 - atomic_long_t intr;
33360 - atomic_long_t intr_cbr;
33361 - atomic_long_t intr_tfh;
33362 - atomic_long_t intr_spurious;
33363 - atomic_long_t intr_mm_lock_failed;
33364 - atomic_long_t call_os;
33365 - atomic_long_t call_os_wait_queue;
33366 - atomic_long_t user_flush_tlb;
33367 - atomic_long_t user_unload_context;
33368 - atomic_long_t user_exception;
33369 - atomic_long_t set_context_option;
33370 - atomic_long_t check_context_retarget_intr;
33371 - atomic_long_t check_context_unload;
33372 - atomic_long_t tlb_dropin;
33373 - atomic_long_t tlb_preload_page;
33374 - atomic_long_t tlb_dropin_fail_no_asid;
33375 - atomic_long_t tlb_dropin_fail_upm;
33376 - atomic_long_t tlb_dropin_fail_invalid;
33377 - atomic_long_t tlb_dropin_fail_range_active;
33378 - atomic_long_t tlb_dropin_fail_idle;
33379 - atomic_long_t tlb_dropin_fail_fmm;
33380 - atomic_long_t tlb_dropin_fail_no_exception;
33381 - atomic_long_t tfh_stale_on_fault;
33382 - atomic_long_t mmu_invalidate_range;
33383 - atomic_long_t mmu_invalidate_page;
33384 - atomic_long_t flush_tlb;
33385 - atomic_long_t flush_tlb_gru;
33386 - atomic_long_t flush_tlb_gru_tgh;
33387 - atomic_long_t flush_tlb_gru_zero_asid;
33388 + atomic_long_unchecked_t vdata_alloc;
33389 + atomic_long_unchecked_t vdata_free;
33390 + atomic_long_unchecked_t gts_alloc;
33391 + atomic_long_unchecked_t gts_free;
33392 + atomic_long_unchecked_t gms_alloc;
33393 + atomic_long_unchecked_t gms_free;
33394 + atomic_long_unchecked_t gts_double_allocate;
33395 + atomic_long_unchecked_t assign_context;
33396 + atomic_long_unchecked_t assign_context_failed;
33397 + atomic_long_unchecked_t free_context;
33398 + atomic_long_unchecked_t load_user_context;
33399 + atomic_long_unchecked_t load_kernel_context;
33400 + atomic_long_unchecked_t lock_kernel_context;
33401 + atomic_long_unchecked_t unlock_kernel_context;
33402 + atomic_long_unchecked_t steal_user_context;
33403 + atomic_long_unchecked_t steal_kernel_context;
33404 + atomic_long_unchecked_t steal_context_failed;
33405 + atomic_long_unchecked_t nopfn;
33406 + atomic_long_unchecked_t asid_new;
33407 + atomic_long_unchecked_t asid_next;
33408 + atomic_long_unchecked_t asid_wrap;
33409 + atomic_long_unchecked_t asid_reuse;
33410 + atomic_long_unchecked_t intr;
33411 + atomic_long_unchecked_t intr_cbr;
33412 + atomic_long_unchecked_t intr_tfh;
33413 + atomic_long_unchecked_t intr_spurious;
33414 + atomic_long_unchecked_t intr_mm_lock_failed;
33415 + atomic_long_unchecked_t call_os;
33416 + atomic_long_unchecked_t call_os_wait_queue;
33417 + atomic_long_unchecked_t user_flush_tlb;
33418 + atomic_long_unchecked_t user_unload_context;
33419 + atomic_long_unchecked_t user_exception;
33420 + atomic_long_unchecked_t set_context_option;
33421 + atomic_long_unchecked_t check_context_retarget_intr;
33422 + atomic_long_unchecked_t check_context_unload;
33423 + atomic_long_unchecked_t tlb_dropin;
33424 + atomic_long_unchecked_t tlb_preload_page;
33425 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
33426 + atomic_long_unchecked_t tlb_dropin_fail_upm;
33427 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
33428 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
33429 + atomic_long_unchecked_t tlb_dropin_fail_idle;
33430 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
33431 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
33432 + atomic_long_unchecked_t tfh_stale_on_fault;
33433 + atomic_long_unchecked_t mmu_invalidate_range;
33434 + atomic_long_unchecked_t mmu_invalidate_page;
33435 + atomic_long_unchecked_t flush_tlb;
33436 + atomic_long_unchecked_t flush_tlb_gru;
33437 + atomic_long_unchecked_t flush_tlb_gru_tgh;
33438 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
33439
33440 - atomic_long_t copy_gpa;
33441 - atomic_long_t read_gpa;
33442 + atomic_long_unchecked_t copy_gpa;
33443 + atomic_long_unchecked_t read_gpa;
33444
33445 - atomic_long_t mesq_receive;
33446 - atomic_long_t mesq_receive_none;
33447 - atomic_long_t mesq_send;
33448 - atomic_long_t mesq_send_failed;
33449 - atomic_long_t mesq_noop;
33450 - atomic_long_t mesq_send_unexpected_error;
33451 - atomic_long_t mesq_send_lb_overflow;
33452 - atomic_long_t mesq_send_qlimit_reached;
33453 - atomic_long_t mesq_send_amo_nacked;
33454 - atomic_long_t mesq_send_put_nacked;
33455 - atomic_long_t mesq_page_overflow;
33456 - atomic_long_t mesq_qf_locked;
33457 - atomic_long_t mesq_qf_noop_not_full;
33458 - atomic_long_t mesq_qf_switch_head_failed;
33459 - atomic_long_t mesq_qf_unexpected_error;
33460 - atomic_long_t mesq_noop_unexpected_error;
33461 - atomic_long_t mesq_noop_lb_overflow;
33462 - atomic_long_t mesq_noop_qlimit_reached;
33463 - atomic_long_t mesq_noop_amo_nacked;
33464 - atomic_long_t mesq_noop_put_nacked;
33465 - atomic_long_t mesq_noop_page_overflow;
33466 + atomic_long_unchecked_t mesq_receive;
33467 + atomic_long_unchecked_t mesq_receive_none;
33468 + atomic_long_unchecked_t mesq_send;
33469 + atomic_long_unchecked_t mesq_send_failed;
33470 + atomic_long_unchecked_t mesq_noop;
33471 + atomic_long_unchecked_t mesq_send_unexpected_error;
33472 + atomic_long_unchecked_t mesq_send_lb_overflow;
33473 + atomic_long_unchecked_t mesq_send_qlimit_reached;
33474 + atomic_long_unchecked_t mesq_send_amo_nacked;
33475 + atomic_long_unchecked_t mesq_send_put_nacked;
33476 + atomic_long_unchecked_t mesq_page_overflow;
33477 + atomic_long_unchecked_t mesq_qf_locked;
33478 + atomic_long_unchecked_t mesq_qf_noop_not_full;
33479 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
33480 + atomic_long_unchecked_t mesq_qf_unexpected_error;
33481 + atomic_long_unchecked_t mesq_noop_unexpected_error;
33482 + atomic_long_unchecked_t mesq_noop_lb_overflow;
33483 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
33484 + atomic_long_unchecked_t mesq_noop_amo_nacked;
33485 + atomic_long_unchecked_t mesq_noop_put_nacked;
33486 + atomic_long_unchecked_t mesq_noop_page_overflow;
33487
33488 };
33489
33490 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
33491 tghop_invalidate, mcsop_last};
33492
33493 struct mcs_op_statistic {
33494 - atomic_long_t count;
33495 - atomic_long_t total;
33496 + atomic_long_unchecked_t count;
33497 + atomic_long_unchecked_t total;
33498 unsigned long max;
33499 };
33500
33501 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
33502
33503 #define STAT(id) do { \
33504 if (gru_options & OPT_STATS) \
33505 - atomic_long_inc(&gru_stats.id); \
33506 + atomic_long_inc_unchecked(&gru_stats.id); \
33507 } while (0)
33508
33509 #ifdef CONFIG_SGI_GRU_DEBUG
33510 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
33511 index 851b2f2..a4ec097 100644
33512 --- a/drivers/misc/sgi-xp/xp.h
33513 +++ b/drivers/misc/sgi-xp/xp.h
33514 @@ -289,7 +289,7 @@ struct xpc_interface {
33515 xpc_notify_func, void *);
33516 void (*received) (short, int, void *);
33517 enum xp_retval (*partid_to_nasids) (short, void *);
33518 -};
33519 +} __no_const;
33520
33521 extern struct xpc_interface xpc_interface;
33522
33523 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
33524 index b94d5f7..7f494c5 100644
33525 --- a/drivers/misc/sgi-xp/xpc.h
33526 +++ b/drivers/misc/sgi-xp/xpc.h
33527 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
33528 void (*received_payload) (struct xpc_channel *, void *);
33529 void (*notify_senders_of_disconnect) (struct xpc_channel *);
33530 };
33531 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
33532
33533 /* struct xpc_partition act_state values (for XPC HB) */
33534
33535 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
33536 /* found in xpc_main.c */
33537 extern struct device *xpc_part;
33538 extern struct device *xpc_chan;
33539 -extern struct xpc_arch_operations xpc_arch_ops;
33540 +extern xpc_arch_operations_no_const xpc_arch_ops;
33541 extern int xpc_disengage_timelimit;
33542 extern int xpc_disengage_timedout;
33543 extern int xpc_activate_IRQ_rcvd;
33544 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
33545 index 8d082b4..aa749ae 100644
33546 --- a/drivers/misc/sgi-xp/xpc_main.c
33547 +++ b/drivers/misc/sgi-xp/xpc_main.c
33548 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
33549 .notifier_call = xpc_system_die,
33550 };
33551
33552 -struct xpc_arch_operations xpc_arch_ops;
33553 +xpc_arch_operations_no_const xpc_arch_ops;
33554
33555 /*
33556 * Timer function to enforce the timelimit on the partition disengage.
33557 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
33558 index 6878a94..fe5c5f1 100644
33559 --- a/drivers/mmc/host/sdhci-pci.c
33560 +++ b/drivers/mmc/host/sdhci-pci.c
33561 @@ -673,7 +673,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
33562 .probe = via_probe,
33563 };
33564
33565 -static const struct pci_device_id pci_ids[] __devinitdata = {
33566 +static const struct pci_device_id pci_ids[] __devinitconst = {
33567 {
33568 .vendor = PCI_VENDOR_ID_RICOH,
33569 .device = PCI_DEVICE_ID_RICOH_R5C822,
33570 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
33571 index e9fad91..0a7a16a 100644
33572 --- a/drivers/mtd/devices/doc2000.c
33573 +++ b/drivers/mtd/devices/doc2000.c
33574 @@ -773,7 +773,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
33575
33576 /* The ECC will not be calculated correctly if less than 512 is written */
33577 /* DBB-
33578 - if (len != 0x200 && eccbuf)
33579 + if (len != 0x200)
33580 printk(KERN_WARNING
33581 "ECC needs a full sector write (adr: %lx size %lx)\n",
33582 (long) to, (long) len);
33583 diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
33584 index a3f7a27..234016e 100644
33585 --- a/drivers/mtd/devices/doc2001.c
33586 +++ b/drivers/mtd/devices/doc2001.c
33587 @@ -392,7 +392,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
33588 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
33589
33590 /* Don't allow read past end of device */
33591 - if (from >= this->totlen)
33592 + if (from >= this->totlen || !len)
33593 return -EINVAL;
33594
33595 /* Don't allow a single read to cross a 512-byte block boundary */
33596 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
33597 index 3984d48..28aa897 100644
33598 --- a/drivers/mtd/nand/denali.c
33599 +++ b/drivers/mtd/nand/denali.c
33600 @@ -26,6 +26,7 @@
33601 #include <linux/pci.h>
33602 #include <linux/mtd/mtd.h>
33603 #include <linux/module.h>
33604 +#include <linux/slab.h>
33605
33606 #include "denali.h"
33607
33608 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
33609 index ac40925..483b753 100644
33610 --- a/drivers/mtd/nftlmount.c
33611 +++ b/drivers/mtd/nftlmount.c
33612 @@ -24,6 +24,7 @@
33613 #include <asm/errno.h>
33614 #include <linux/delay.h>
33615 #include <linux/slab.h>
33616 +#include <linux/sched.h>
33617 #include <linux/mtd/mtd.h>
33618 #include <linux/mtd/nand.h>
33619 #include <linux/mtd/nftl.h>
33620 diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
33621 index 6c3fb5a..c542a81 100644
33622 --- a/drivers/mtd/ubi/build.c
33623 +++ b/drivers/mtd/ubi/build.c
33624 @@ -1311,7 +1311,7 @@ module_exit(ubi_exit);
33625 static int __init bytes_str_to_int(const char *str)
33626 {
33627 char *endp;
33628 - unsigned long result;
33629 + unsigned long result, scale = 1;
33630
33631 result = simple_strtoul(str, &endp, 0);
33632 if (str == endp || result >= INT_MAX) {
33633 @@ -1322,11 +1322,11 @@ static int __init bytes_str_to_int(const char *str)
33634
33635 switch (*endp) {
33636 case 'G':
33637 - result *= 1024;
33638 + scale *= 1024;
33639 case 'M':
33640 - result *= 1024;
33641 + scale *= 1024;
33642 case 'K':
33643 - result *= 1024;
33644 + scale *= 1024;
33645 if (endp[1] == 'i' && endp[2] == 'B')
33646 endp += 2;
33647 case '\0':
33648 @@ -1337,7 +1337,13 @@ static int __init bytes_str_to_int(const char *str)
33649 return -EINVAL;
33650 }
33651
33652 - return result;
33653 + if ((intoverflow_t)result*scale >= INT_MAX) {
33654 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
33655 + str);
33656 + return -EINVAL;
33657 + }
33658 +
33659 + return result*scale;
33660 }
33661
33662 /**
33663 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
33664 index 1feae59..c2a61d2 100644
33665 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
33666 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
33667 @@ -2857,7 +2857,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
33668 */
33669
33670 #define ATL2_PARAM(X, desc) \
33671 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
33672 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
33673 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
33674 MODULE_PARM_DESC(X, desc);
33675 #else
33676 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
33677 index 9a517c2..a50cfcb 100644
33678 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
33679 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
33680 @@ -449,7 +449,7 @@ struct bnx2x_rx_mode_obj {
33681
33682 int (*wait_comp)(struct bnx2x *bp,
33683 struct bnx2x_rx_mode_ramrod_params *p);
33684 -};
33685 +} __no_const;
33686
33687 /********************** Set multicast group ***********************************/
33688
33689 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
33690 index 94b4bd0..73c02de 100644
33691 --- a/drivers/net/ethernet/broadcom/tg3.h
33692 +++ b/drivers/net/ethernet/broadcom/tg3.h
33693 @@ -134,6 +134,7 @@
33694 #define CHIPREV_ID_5750_A0 0x4000
33695 #define CHIPREV_ID_5750_A1 0x4001
33696 #define CHIPREV_ID_5750_A3 0x4003
33697 +#define CHIPREV_ID_5750_C1 0x4201
33698 #define CHIPREV_ID_5750_C2 0x4202
33699 #define CHIPREV_ID_5752_A0_HW 0x5000
33700 #define CHIPREV_ID_5752_A0 0x6000
33701 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
33702 index c5f5479..2e8c260 100644
33703 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
33704 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
33705 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
33706 */
33707 struct l2t_skb_cb {
33708 arp_failure_handler_func arp_failure_handler;
33709 -};
33710 +} __no_const;
33711
33712 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
33713
33714 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
33715 index 871bcaa..4043505 100644
33716 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
33717 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
33718 @@ -5397,7 +5397,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
33719 for (i=0; i<ETH_ALEN; i++) {
33720 tmp.addr[i] = dev->dev_addr[i];
33721 }
33722 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
33723 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
33724 break;
33725
33726 case DE4X5_SET_HWADDR: /* Set the hardware address */
33727 @@ -5437,7 +5437,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
33728 spin_lock_irqsave(&lp->lock, flags);
33729 memcpy(&statbuf, &lp->pktStats, ioc->len);
33730 spin_unlock_irqrestore(&lp->lock, flags);
33731 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
33732 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
33733 return -EFAULT;
33734 break;
33735 }
33736 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
33737 index 14d5b61..1398636 100644
33738 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
33739 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
33740 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
33741 {NULL}};
33742
33743
33744 -static const char *block_name[] __devinitdata = {
33745 +static const char *block_name[] __devinitconst = {
33746 "21140 non-MII",
33747 "21140 MII PHY",
33748 "21142 Serial PHY",
33749 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
33750 index 4d01219..b58d26d 100644
33751 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
33752 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
33753 @@ -236,7 +236,7 @@ struct pci_id_info {
33754 int drv_flags; /* Driver use, intended as capability flags. */
33755 };
33756
33757 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
33758 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
33759 { /* Sometime a Level-One switch card. */
33760 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
33761 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
33762 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
33763 index dcd7f7a..ecb7fb3 100644
33764 --- a/drivers/net/ethernet/dlink/sundance.c
33765 +++ b/drivers/net/ethernet/dlink/sundance.c
33766 @@ -218,7 +218,7 @@ enum {
33767 struct pci_id_info {
33768 const char *name;
33769 };
33770 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
33771 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
33772 {"D-Link DFE-550TX FAST Ethernet Adapter"},
33773 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
33774 {"D-Link DFE-580TX 4 port Server Adapter"},
33775 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
33776 index bf266a0..e024af7 100644
33777 --- a/drivers/net/ethernet/emulex/benet/be_main.c
33778 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
33779 @@ -397,7 +397,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
33780
33781 if (wrapped)
33782 newacc += 65536;
33783 - ACCESS_ONCE(*acc) = newacc;
33784 + ACCESS_ONCE_RW(*acc) = newacc;
33785 }
33786
33787 void be_parse_stats(struct be_adapter *adapter)
33788 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
33789 index 61d2bdd..7f1154a 100644
33790 --- a/drivers/net/ethernet/fealnx.c
33791 +++ b/drivers/net/ethernet/fealnx.c
33792 @@ -150,7 +150,7 @@ struct chip_info {
33793 int flags;
33794 };
33795
33796 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
33797 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
33798 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
33799 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
33800 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
33801 diff --git a/drivers/net/ethernet/intel/e1000e/80003es2lan.c b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
33802 index e1159e5..e18684d 100644
33803 --- a/drivers/net/ethernet/intel/e1000e/80003es2lan.c
33804 +++ b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
33805 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
33806 {
33807 struct e1000_hw *hw = &adapter->hw;
33808 struct e1000_mac_info *mac = &hw->mac;
33809 - struct e1000_mac_operations *func = &mac->ops;
33810 + e1000_mac_operations_no_const *func = &mac->ops;
33811
33812 /* Set media type */
33813 switch (adapter->pdev->device) {
33814 diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
33815 index a3e65fd..f451444 100644
33816 --- a/drivers/net/ethernet/intel/e1000e/82571.c
33817 +++ b/drivers/net/ethernet/intel/e1000e/82571.c
33818 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
33819 {
33820 struct e1000_hw *hw = &adapter->hw;
33821 struct e1000_mac_info *mac = &hw->mac;
33822 - struct e1000_mac_operations *func = &mac->ops;
33823 + e1000_mac_operations_no_const *func = &mac->ops;
33824 u32 swsm = 0;
33825 u32 swsm2 = 0;
33826 bool force_clear_smbi = false;
33827 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
33828 index 2967039..ca8c40c 100644
33829 --- a/drivers/net/ethernet/intel/e1000e/hw.h
33830 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
33831 @@ -778,6 +778,7 @@ struct e1000_mac_operations {
33832 void (*write_vfta)(struct e1000_hw *, u32, u32);
33833 s32 (*read_mac_addr)(struct e1000_hw *);
33834 };
33835 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
33836
33837 /*
33838 * When to use various PHY register access functions:
33839 @@ -818,6 +819,7 @@ struct e1000_phy_operations {
33840 void (*power_up)(struct e1000_hw *);
33841 void (*power_down)(struct e1000_hw *);
33842 };
33843 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
33844
33845 /* Function pointers for the NVM. */
33846 struct e1000_nvm_operations {
33847 @@ -829,9 +831,10 @@ struct e1000_nvm_operations {
33848 s32 (*validate)(struct e1000_hw *);
33849 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
33850 };
33851 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
33852
33853 struct e1000_mac_info {
33854 - struct e1000_mac_operations ops;
33855 + e1000_mac_operations_no_const ops;
33856 u8 addr[ETH_ALEN];
33857 u8 perm_addr[ETH_ALEN];
33858
33859 @@ -872,7 +875,7 @@ struct e1000_mac_info {
33860 };
33861
33862 struct e1000_phy_info {
33863 - struct e1000_phy_operations ops;
33864 + e1000_phy_operations_no_const ops;
33865
33866 enum e1000_phy_type type;
33867
33868 @@ -906,7 +909,7 @@ struct e1000_phy_info {
33869 };
33870
33871 struct e1000_nvm_info {
33872 - struct e1000_nvm_operations ops;
33873 + e1000_nvm_operations_no_const ops;
33874
33875 enum e1000_nvm_type type;
33876 enum e1000_nvm_override override;
33877 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
33878 index 4519a13..f97fcd0 100644
33879 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
33880 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
33881 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
33882 s32 (*read_mac_addr)(struct e1000_hw *);
33883 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
33884 };
33885 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
33886
33887 struct e1000_phy_operations {
33888 s32 (*acquire)(struct e1000_hw *);
33889 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
33890 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
33891 s32 (*write_reg)(struct e1000_hw *, u32, u16);
33892 };
33893 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
33894
33895 struct e1000_nvm_operations {
33896 s32 (*acquire)(struct e1000_hw *);
33897 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
33898 s32 (*update)(struct e1000_hw *);
33899 s32 (*validate)(struct e1000_hw *);
33900 };
33901 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
33902
33903 struct e1000_info {
33904 s32 (*get_invariants)(struct e1000_hw *);
33905 @@ -350,7 +353,7 @@ struct e1000_info {
33906 extern const struct e1000_info e1000_82575_info;
33907
33908 struct e1000_mac_info {
33909 - struct e1000_mac_operations ops;
33910 + e1000_mac_operations_no_const ops;
33911
33912 u8 addr[6];
33913 u8 perm_addr[6];
33914 @@ -388,7 +391,7 @@ struct e1000_mac_info {
33915 };
33916
33917 struct e1000_phy_info {
33918 - struct e1000_phy_operations ops;
33919 + e1000_phy_operations_no_const ops;
33920
33921 enum e1000_phy_type type;
33922
33923 @@ -423,7 +426,7 @@ struct e1000_phy_info {
33924 };
33925
33926 struct e1000_nvm_info {
33927 - struct e1000_nvm_operations ops;
33928 + e1000_nvm_operations_no_const ops;
33929 enum e1000_nvm_type type;
33930 enum e1000_nvm_override override;
33931
33932 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
33933 s32 (*check_for_ack)(struct e1000_hw *, u16);
33934 s32 (*check_for_rst)(struct e1000_hw *, u16);
33935 };
33936 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
33937
33938 struct e1000_mbx_stats {
33939 u32 msgs_tx;
33940 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
33941 };
33942
33943 struct e1000_mbx_info {
33944 - struct e1000_mbx_operations ops;
33945 + e1000_mbx_operations_no_const ops;
33946 struct e1000_mbx_stats stats;
33947 u32 timeout;
33948 u32 usec_delay;
33949 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
33950 index d7ed58f..64cde36 100644
33951 --- a/drivers/net/ethernet/intel/igbvf/vf.h
33952 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
33953 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
33954 s32 (*read_mac_addr)(struct e1000_hw *);
33955 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
33956 };
33957 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
33958
33959 struct e1000_mac_info {
33960 - struct e1000_mac_operations ops;
33961 + e1000_mac_operations_no_const ops;
33962 u8 addr[6];
33963 u8 perm_addr[6];
33964
33965 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
33966 s32 (*check_for_ack)(struct e1000_hw *);
33967 s32 (*check_for_rst)(struct e1000_hw *);
33968 };
33969 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
33970
33971 struct e1000_mbx_stats {
33972 u32 msgs_tx;
33973 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
33974 };
33975
33976 struct e1000_mbx_info {
33977 - struct e1000_mbx_operations ops;
33978 + e1000_mbx_operations_no_const ops;
33979 struct e1000_mbx_stats stats;
33980 u32 timeout;
33981 u32 usec_delay;
33982 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
33983 index 6c5cca8..de8ef63 100644
33984 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
33985 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
33986 @@ -2708,6 +2708,7 @@ struct ixgbe_eeprom_operations {
33987 s32 (*update_checksum)(struct ixgbe_hw *);
33988 u16 (*calc_checksum)(struct ixgbe_hw *);
33989 };
33990 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
33991
33992 struct ixgbe_mac_operations {
33993 s32 (*init_hw)(struct ixgbe_hw *);
33994 @@ -2769,6 +2770,7 @@ struct ixgbe_mac_operations {
33995 /* Manageability interface */
33996 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
33997 };
33998 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
33999
34000 struct ixgbe_phy_operations {
34001 s32 (*identify)(struct ixgbe_hw *);
34002 @@ -2788,9 +2790,10 @@ struct ixgbe_phy_operations {
34003 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34004 s32 (*check_overtemp)(struct ixgbe_hw *);
34005 };
34006 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34007
34008 struct ixgbe_eeprom_info {
34009 - struct ixgbe_eeprom_operations ops;
34010 + ixgbe_eeprom_operations_no_const ops;
34011 enum ixgbe_eeprom_type type;
34012 u32 semaphore_delay;
34013 u16 word_size;
34014 @@ -2800,7 +2803,7 @@ struct ixgbe_eeprom_info {
34015
34016 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34017 struct ixgbe_mac_info {
34018 - struct ixgbe_mac_operations ops;
34019 + ixgbe_mac_operations_no_const ops;
34020 enum ixgbe_mac_type type;
34021 u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
34022 u8 perm_addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
34023 @@ -2828,7 +2831,7 @@ struct ixgbe_mac_info {
34024 };
34025
34026 struct ixgbe_phy_info {
34027 - struct ixgbe_phy_operations ops;
34028 + ixgbe_phy_operations_no_const ops;
34029 struct mdio_if_info mdio;
34030 enum ixgbe_phy_type type;
34031 u32 id;
34032 @@ -2856,6 +2859,7 @@ struct ixgbe_mbx_operations {
34033 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34034 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34035 };
34036 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34037
34038 struct ixgbe_mbx_stats {
34039 u32 msgs_tx;
34040 @@ -2867,7 +2871,7 @@ struct ixgbe_mbx_stats {
34041 };
34042
34043 struct ixgbe_mbx_info {
34044 - struct ixgbe_mbx_operations ops;
34045 + ixgbe_mbx_operations_no_const ops;
34046 struct ixgbe_mbx_stats stats;
34047 u32 timeout;
34048 u32 usec_delay;
34049 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
34050 index 10306b4..28df758 100644
34051 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
34052 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
34053 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
34054 s32 (*clear_vfta)(struct ixgbe_hw *);
34055 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
34056 };
34057 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34058
34059 enum ixgbe_mac_type {
34060 ixgbe_mac_unknown = 0,
34061 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
34062 };
34063
34064 struct ixgbe_mac_info {
34065 - struct ixgbe_mac_operations ops;
34066 + ixgbe_mac_operations_no_const ops;
34067 u8 addr[6];
34068 u8 perm_addr[6];
34069
34070 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
34071 s32 (*check_for_ack)(struct ixgbe_hw *);
34072 s32 (*check_for_rst)(struct ixgbe_hw *);
34073 };
34074 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34075
34076 struct ixgbe_mbx_stats {
34077 u32 msgs_tx;
34078 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
34079 };
34080
34081 struct ixgbe_mbx_info {
34082 - struct ixgbe_mbx_operations ops;
34083 + ixgbe_mbx_operations_no_const ops;
34084 struct ixgbe_mbx_stats stats;
34085 u32 timeout;
34086 u32 udelay;
34087 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
34088 index 94bbc85..78c12e6 100644
34089 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
34090 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
34091 @@ -40,6 +40,7 @@
34092 #include <linux/dma-mapping.h>
34093 #include <linux/slab.h>
34094 #include <linux/io-mapping.h>
34095 +#include <linux/sched.h>
34096
34097 #include <linux/mlx4/device.h>
34098 #include <linux/mlx4/doorbell.h>
34099 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34100 index 5046a64..71ca936 100644
34101 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
34102 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34103 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
34104 void (*link_down)(struct __vxge_hw_device *devh);
34105 void (*crit_err)(struct __vxge_hw_device *devh,
34106 enum vxge_hw_event type, u64 ext_data);
34107 -};
34108 +} __no_const;
34109
34110 /*
34111 * struct __vxge_hw_blockpool_entry - Block private data structure
34112 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34113 index 4a518a3..936b334 100644
34114 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34115 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34116 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
34117 struct vxge_hw_mempool_dma *dma_object,
34118 u32 index,
34119 u32 is_last);
34120 -};
34121 +} __no_const;
34122
34123 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
34124 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
34125 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
34126 index c8f47f1..5da9840 100644
34127 --- a/drivers/net/ethernet/realtek/r8169.c
34128 +++ b/drivers/net/ethernet/realtek/r8169.c
34129 @@ -698,17 +698,17 @@ struct rtl8169_private {
34130 struct mdio_ops {
34131 void (*write)(void __iomem *, int, int);
34132 int (*read)(void __iomem *, int);
34133 - } mdio_ops;
34134 + } __no_const mdio_ops;
34135
34136 struct pll_power_ops {
34137 void (*down)(struct rtl8169_private *);
34138 void (*up)(struct rtl8169_private *);
34139 - } pll_power_ops;
34140 + } __no_const pll_power_ops;
34141
34142 struct jumbo_ops {
34143 void (*enable)(struct rtl8169_private *);
34144 void (*disable)(struct rtl8169_private *);
34145 - } jumbo_ops;
34146 + } __no_const jumbo_ops;
34147
34148 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
34149 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
34150 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
34151 index 1b4658c..a30dabb 100644
34152 --- a/drivers/net/ethernet/sis/sis190.c
34153 +++ b/drivers/net/ethernet/sis/sis190.c
34154 @@ -1624,7 +1624,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
34155 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
34156 struct net_device *dev)
34157 {
34158 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
34159 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
34160 struct sis190_private *tp = netdev_priv(dev);
34161 struct pci_dev *isa_bridge;
34162 u8 reg, tmp8;
34163 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
34164 index edfa15d..002bfa9 100644
34165 --- a/drivers/net/ppp/ppp_generic.c
34166 +++ b/drivers/net/ppp/ppp_generic.c
34167 @@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34168 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
34169 struct ppp_stats stats;
34170 struct ppp_comp_stats cstats;
34171 - char *vers;
34172
34173 switch (cmd) {
34174 case SIOCGPPPSTATS:
34175 @@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34176 break;
34177
34178 case SIOCGPPPVER:
34179 - vers = PPP_VERSION;
34180 - if (copy_to_user(addr, vers, strlen(vers) + 1))
34181 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
34182 break;
34183 err = 0;
34184 break;
34185 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
34186 index 515f122..41dd273 100644
34187 --- a/drivers/net/tokenring/abyss.c
34188 +++ b/drivers/net/tokenring/abyss.c
34189 @@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
34190
34191 static int __init abyss_init (void)
34192 {
34193 - abyss_netdev_ops = tms380tr_netdev_ops;
34194 + pax_open_kernel();
34195 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34196
34197 - abyss_netdev_ops.ndo_open = abyss_open;
34198 - abyss_netdev_ops.ndo_stop = abyss_close;
34199 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
34200 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
34201 + pax_close_kernel();
34202
34203 return pci_register_driver(&abyss_driver);
34204 }
34205 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
34206 index 6153cfd..cf69c1c 100644
34207 --- a/drivers/net/tokenring/madgemc.c
34208 +++ b/drivers/net/tokenring/madgemc.c
34209 @@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
34210
34211 static int __init madgemc_init (void)
34212 {
34213 - madgemc_netdev_ops = tms380tr_netdev_ops;
34214 - madgemc_netdev_ops.ndo_open = madgemc_open;
34215 - madgemc_netdev_ops.ndo_stop = madgemc_close;
34216 + pax_open_kernel();
34217 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34218 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
34219 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
34220 + pax_close_kernel();
34221
34222 return mca_register_driver (&madgemc_driver);
34223 }
34224 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
34225 index 8d362e6..f91cc52 100644
34226 --- a/drivers/net/tokenring/proteon.c
34227 +++ b/drivers/net/tokenring/proteon.c
34228 @@ -353,9 +353,11 @@ static int __init proteon_init(void)
34229 struct platform_device *pdev;
34230 int i, num = 0, err = 0;
34231
34232 - proteon_netdev_ops = tms380tr_netdev_ops;
34233 - proteon_netdev_ops.ndo_open = proteon_open;
34234 - proteon_netdev_ops.ndo_stop = tms380tr_close;
34235 + pax_open_kernel();
34236 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34237 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
34238 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
34239 + pax_close_kernel();
34240
34241 err = platform_driver_register(&proteon_driver);
34242 if (err)
34243 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
34244 index 46db5c5..37c1536 100644
34245 --- a/drivers/net/tokenring/skisa.c
34246 +++ b/drivers/net/tokenring/skisa.c
34247 @@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
34248 struct platform_device *pdev;
34249 int i, num = 0, err = 0;
34250
34251 - sk_isa_netdev_ops = tms380tr_netdev_ops;
34252 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
34253 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
34254 + pax_open_kernel();
34255 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34256 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
34257 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
34258 + pax_close_kernel();
34259
34260 err = platform_driver_register(&sk_isa_driver);
34261 if (err)
34262 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
34263 index 304fe78..db112fa 100644
34264 --- a/drivers/net/usb/hso.c
34265 +++ b/drivers/net/usb/hso.c
34266 @@ -71,7 +71,7 @@
34267 #include <asm/byteorder.h>
34268 #include <linux/serial_core.h>
34269 #include <linux/serial.h>
34270 -
34271 +#include <asm/local.h>
34272
34273 #define MOD_AUTHOR "Option Wireless"
34274 #define MOD_DESCRIPTION "USB High Speed Option driver"
34275 @@ -257,7 +257,7 @@ struct hso_serial {
34276
34277 /* from usb_serial_port */
34278 struct tty_struct *tty;
34279 - int open_count;
34280 + local_t open_count;
34281 spinlock_t serial_lock;
34282
34283 int (*write_data) (struct hso_serial *serial);
34284 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
34285 struct urb *urb;
34286
34287 urb = serial->rx_urb[0];
34288 - if (serial->open_count > 0) {
34289 + if (local_read(&serial->open_count) > 0) {
34290 count = put_rxbuf_data(urb, serial);
34291 if (count == -1)
34292 return;
34293 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
34294 DUMP1(urb->transfer_buffer, urb->actual_length);
34295
34296 /* Anyone listening? */
34297 - if (serial->open_count == 0)
34298 + if (local_read(&serial->open_count) == 0)
34299 return;
34300
34301 if (status == 0) {
34302 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
34303 spin_unlock_irq(&serial->serial_lock);
34304
34305 /* check for port already opened, if not set the termios */
34306 - serial->open_count++;
34307 - if (serial->open_count == 1) {
34308 + if (local_inc_return(&serial->open_count) == 1) {
34309 serial->rx_state = RX_IDLE;
34310 /* Force default termio settings */
34311 _hso_serial_set_termios(tty, NULL);
34312 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
34313 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
34314 if (result) {
34315 hso_stop_serial_device(serial->parent);
34316 - serial->open_count--;
34317 + local_dec(&serial->open_count);
34318 kref_put(&serial->parent->ref, hso_serial_ref_free);
34319 }
34320 } else {
34321 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
34322
34323 /* reset the rts and dtr */
34324 /* do the actual close */
34325 - serial->open_count--;
34326 + local_dec(&serial->open_count);
34327
34328 - if (serial->open_count <= 0) {
34329 - serial->open_count = 0;
34330 + if (local_read(&serial->open_count) <= 0) {
34331 + local_set(&serial->open_count, 0);
34332 spin_lock_irq(&serial->serial_lock);
34333 if (serial->tty == tty) {
34334 serial->tty->driver_data = NULL;
34335 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
34336
34337 /* the actual setup */
34338 spin_lock_irqsave(&serial->serial_lock, flags);
34339 - if (serial->open_count)
34340 + if (local_read(&serial->open_count))
34341 _hso_serial_set_termios(tty, old);
34342 else
34343 tty->termios = old;
34344 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
34345 D1("Pending read interrupt on port %d\n", i);
34346 spin_lock(&serial->serial_lock);
34347 if (serial->rx_state == RX_IDLE &&
34348 - serial->open_count > 0) {
34349 + local_read(&serial->open_count) > 0) {
34350 /* Setup and send a ctrl req read on
34351 * port i */
34352 if (!serial->rx_urb_filled[0]) {
34353 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
34354 /* Start all serial ports */
34355 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
34356 if (serial_table[i] && (serial_table[i]->interface == iface)) {
34357 - if (dev2ser(serial_table[i])->open_count) {
34358 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
34359 result =
34360 hso_start_serial_device(serial_table[i], GFP_NOIO);
34361 hso_kick_transmit(dev2ser(serial_table[i]));
34362 diff --git a/drivers/net/vmxnet3/vmxnet3_ethtool.c b/drivers/net/vmxnet3/vmxnet3_ethtool.c
34363 index e662cbc..8d4a102 100644
34364 --- a/drivers/net/vmxnet3/vmxnet3_ethtool.c
34365 +++ b/drivers/net/vmxnet3/vmxnet3_ethtool.c
34366 @@ -601,8 +601,7 @@ vmxnet3_set_rss_indir(struct net_device *netdev,
34367 * Return with error code if any of the queue indices
34368 * is out of range
34369 */
34370 - if (p->ring_index[i] < 0 ||
34371 - p->ring_index[i] >= adapter->num_rx_queues)
34372 + if (p->ring_index[i] >= adapter->num_rx_queues)
34373 return -EINVAL;
34374 }
34375
34376 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
34377 index 0f9ee46..e2d6e65 100644
34378 --- a/drivers/net/wireless/ath/ath.h
34379 +++ b/drivers/net/wireless/ath/ath.h
34380 @@ -119,6 +119,7 @@ struct ath_ops {
34381 void (*write_flush) (void *);
34382 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
34383 };
34384 +typedef struct ath_ops __no_const ath_ops_no_const;
34385
34386 struct ath_common;
34387 struct ath_bus_ops;
34388 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
34389 index b592016..fe47870 100644
34390 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
34391 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
34392 @@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34393 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
34394 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
34395
34396 - ACCESS_ONCE(ads->ds_link) = i->link;
34397 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
34398 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
34399 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
34400
34401 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
34402 ctl6 = SM(i->keytype, AR_EncrType);
34403 @@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34404
34405 if ((i->is_first || i->is_last) &&
34406 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
34407 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
34408 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
34409 | set11nTries(i->rates, 1)
34410 | set11nTries(i->rates, 2)
34411 | set11nTries(i->rates, 3)
34412 | (i->dur_update ? AR_DurUpdateEna : 0)
34413 | SM(0, AR_BurstDur);
34414
34415 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
34416 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
34417 | set11nRate(i->rates, 1)
34418 | set11nRate(i->rates, 2)
34419 | set11nRate(i->rates, 3);
34420 } else {
34421 - ACCESS_ONCE(ads->ds_ctl2) = 0;
34422 - ACCESS_ONCE(ads->ds_ctl3) = 0;
34423 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
34424 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
34425 }
34426
34427 if (!i->is_first) {
34428 - ACCESS_ONCE(ads->ds_ctl0) = 0;
34429 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
34430 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
34431 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
34432 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
34433 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
34434 return;
34435 }
34436
34437 @@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34438 break;
34439 }
34440
34441 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
34442 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
34443 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
34444 | SM(i->txpower, AR_XmitPower)
34445 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
34446 @@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34447 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
34448 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
34449
34450 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
34451 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
34452 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
34453 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
34454
34455 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
34456 return;
34457
34458 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
34459 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
34460 | set11nPktDurRTSCTS(i->rates, 1);
34461
34462 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
34463 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
34464 | set11nPktDurRTSCTS(i->rates, 3);
34465
34466 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
34467 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
34468 | set11nRateFlags(i->rates, 1)
34469 | set11nRateFlags(i->rates, 2)
34470 | set11nRateFlags(i->rates, 3)
34471 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
34472 index f5ae3c6..7936af3 100644
34473 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
34474 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
34475 @@ -35,47 +35,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34476 (i->qcu << AR_TxQcuNum_S) | 0x17;
34477
34478 checksum += val;
34479 - ACCESS_ONCE(ads->info) = val;
34480 + ACCESS_ONCE_RW(ads->info) = val;
34481
34482 checksum += i->link;
34483 - ACCESS_ONCE(ads->link) = i->link;
34484 + ACCESS_ONCE_RW(ads->link) = i->link;
34485
34486 checksum += i->buf_addr[0];
34487 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
34488 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
34489 checksum += i->buf_addr[1];
34490 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
34491 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
34492 checksum += i->buf_addr[2];
34493 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
34494 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
34495 checksum += i->buf_addr[3];
34496 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
34497 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
34498
34499 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
34500 - ACCESS_ONCE(ads->ctl3) = val;
34501 + ACCESS_ONCE_RW(ads->ctl3) = val;
34502 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
34503 - ACCESS_ONCE(ads->ctl5) = val;
34504 + ACCESS_ONCE_RW(ads->ctl5) = val;
34505 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
34506 - ACCESS_ONCE(ads->ctl7) = val;
34507 + ACCESS_ONCE_RW(ads->ctl7) = val;
34508 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
34509 - ACCESS_ONCE(ads->ctl9) = val;
34510 + ACCESS_ONCE_RW(ads->ctl9) = val;
34511
34512 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
34513 - ACCESS_ONCE(ads->ctl10) = checksum;
34514 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
34515
34516 if (i->is_first || i->is_last) {
34517 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
34518 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
34519 | set11nTries(i->rates, 1)
34520 | set11nTries(i->rates, 2)
34521 | set11nTries(i->rates, 3)
34522 | (i->dur_update ? AR_DurUpdateEna : 0)
34523 | SM(0, AR_BurstDur);
34524
34525 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
34526 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
34527 | set11nRate(i->rates, 1)
34528 | set11nRate(i->rates, 2)
34529 | set11nRate(i->rates, 3);
34530 } else {
34531 - ACCESS_ONCE(ads->ctl13) = 0;
34532 - ACCESS_ONCE(ads->ctl14) = 0;
34533 + ACCESS_ONCE_RW(ads->ctl13) = 0;
34534 + ACCESS_ONCE_RW(ads->ctl14) = 0;
34535 }
34536
34537 ads->ctl20 = 0;
34538 @@ -84,17 +84,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34539
34540 ctl17 = SM(i->keytype, AR_EncrType);
34541 if (!i->is_first) {
34542 - ACCESS_ONCE(ads->ctl11) = 0;
34543 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
34544 - ACCESS_ONCE(ads->ctl15) = 0;
34545 - ACCESS_ONCE(ads->ctl16) = 0;
34546 - ACCESS_ONCE(ads->ctl17) = ctl17;
34547 - ACCESS_ONCE(ads->ctl18) = 0;
34548 - ACCESS_ONCE(ads->ctl19) = 0;
34549 + ACCESS_ONCE_RW(ads->ctl11) = 0;
34550 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
34551 + ACCESS_ONCE_RW(ads->ctl15) = 0;
34552 + ACCESS_ONCE_RW(ads->ctl16) = 0;
34553 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
34554 + ACCESS_ONCE_RW(ads->ctl18) = 0;
34555 + ACCESS_ONCE_RW(ads->ctl19) = 0;
34556 return;
34557 }
34558
34559 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
34560 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
34561 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
34562 | SM(i->txpower, AR_XmitPower)
34563 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
34564 @@ -130,22 +130,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34565 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
34566 ctl12 |= SM(val, AR_PAPRDChainMask);
34567
34568 - ACCESS_ONCE(ads->ctl12) = ctl12;
34569 - ACCESS_ONCE(ads->ctl17) = ctl17;
34570 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
34571 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
34572
34573 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
34574 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
34575 | set11nPktDurRTSCTS(i->rates, 1);
34576
34577 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
34578 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
34579 | set11nPktDurRTSCTS(i->rates, 3);
34580
34581 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
34582 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
34583 | set11nRateFlags(i->rates, 1)
34584 | set11nRateFlags(i->rates, 2)
34585 | set11nRateFlags(i->rates, 3)
34586 | SM(i->rtscts_rate, AR_RTSCTSRate);
34587
34588 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
34589 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
34590 }
34591
34592 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
34593 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
34594 index f389b3c..7359e18 100644
34595 --- a/drivers/net/wireless/ath/ath9k/hw.h
34596 +++ b/drivers/net/wireless/ath/ath9k/hw.h
34597 @@ -605,7 +605,7 @@ struct ath_hw_private_ops {
34598
34599 /* ANI */
34600 void (*ani_cache_ini_regs)(struct ath_hw *ah);
34601 -};
34602 +} __no_const;
34603
34604 /**
34605 * struct ath_hw_ops - callbacks used by hardware code and driver code
34606 @@ -635,7 +635,7 @@ struct ath_hw_ops {
34607 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
34608 struct ath_hw_antcomb_conf *antconf);
34609
34610 -};
34611 +} __no_const;
34612
34613 struct ath_nf_limits {
34614 s16 max;
34615 @@ -655,7 +655,7 @@ enum ath_cal_list {
34616 #define AH_FASTCC 0x4
34617
34618 struct ath_hw {
34619 - struct ath_ops reg_ops;
34620 + ath_ops_no_const reg_ops;
34621
34622 struct ieee80211_hw *hw;
34623 struct ath_common common;
34624 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
34625 index bea8524..c677c06 100644
34626 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
34627 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
34628 @@ -547,7 +547,7 @@ struct phy_func_ptr {
34629 void (*carrsuppr)(struct brcms_phy *);
34630 s32 (*rxsigpwr)(struct brcms_phy *, s32);
34631 void (*detach)(struct brcms_phy *);
34632 -};
34633 +} __no_const;
34634
34635 struct brcms_phy {
34636 struct brcms_phy_pub pubpi_ro;
34637 diff --git a/drivers/net/wireless/iwlegacy/iwl3945-base.c b/drivers/net/wireless/iwlegacy/iwl3945-base.c
34638 index 05f2ad1..ae00eea 100644
34639 --- a/drivers/net/wireless/iwlegacy/iwl3945-base.c
34640 +++ b/drivers/net/wireless/iwlegacy/iwl3945-base.c
34641 @@ -3685,7 +3685,9 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
34642 */
34643 if (iwl3945_mod_params.disable_hw_scan) {
34644 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
34645 - iwl3945_hw_ops.hw_scan = NULL;
34646 + pax_open_kernel();
34647 + *(void **)&iwl3945_hw_ops.hw_scan = NULL;
34648 + pax_close_kernel();
34649 }
34650
34651 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
34652 diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
34653 index 69a77e2..552b42c 100644
34654 --- a/drivers/net/wireless/iwlwifi/iwl-debug.h
34655 +++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
34656 @@ -71,8 +71,8 @@ do { \
34657 } while (0)
34658
34659 #else
34660 -#define IWL_DEBUG(m, level, fmt, args...)
34661 -#define IWL_DEBUG_LIMIT(m, level, fmt, args...)
34662 +#define IWL_DEBUG(m, level, fmt, args...) do {} while (0)
34663 +#define IWL_DEBUG_LIMIT(m, level, fmt, args...) do {} while (0)
34664 #define iwl_print_hex_dump(m, level, p, len)
34665 #endif /* CONFIG_IWLWIFI_DEBUG */
34666
34667 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
34668 index 523ad55..f8c5dc5 100644
34669 --- a/drivers/net/wireless/mac80211_hwsim.c
34670 +++ b/drivers/net/wireless/mac80211_hwsim.c
34671 @@ -1678,9 +1678,11 @@ static int __init init_mac80211_hwsim(void)
34672 return -EINVAL;
34673
34674 if (fake_hw_scan) {
34675 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
34676 - mac80211_hwsim_ops.sw_scan_start = NULL;
34677 - mac80211_hwsim_ops.sw_scan_complete = NULL;
34678 + pax_open_kernel();
34679 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
34680 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
34681 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
34682 + pax_close_kernel();
34683 }
34684
34685 spin_lock_init(&hwsim_radio_lock);
34686 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
34687 index 30f138b..c904585 100644
34688 --- a/drivers/net/wireless/mwifiex/main.h
34689 +++ b/drivers/net/wireless/mwifiex/main.h
34690 @@ -543,7 +543,7 @@ struct mwifiex_if_ops {
34691 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
34692 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
34693 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
34694 -};
34695 +} __no_const;
34696
34697 struct mwifiex_adapter {
34698 u8 iface_type;
34699 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
34700 index 0c13840..a5c3ed6 100644
34701 --- a/drivers/net/wireless/rndis_wlan.c
34702 +++ b/drivers/net/wireless/rndis_wlan.c
34703 @@ -1275,7 +1275,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
34704
34705 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
34706
34707 - if (rts_threshold < 0 || rts_threshold > 2347)
34708 + if (rts_threshold > 2347)
34709 rts_threshold = 2347;
34710
34711 tmp = cpu_to_le32(rts_threshold);
34712 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
34713 index a77f1bb..c608b2b 100644
34714 --- a/drivers/net/wireless/wl1251/wl1251.h
34715 +++ b/drivers/net/wireless/wl1251/wl1251.h
34716 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
34717 void (*reset)(struct wl1251 *wl);
34718 void (*enable_irq)(struct wl1251 *wl);
34719 void (*disable_irq)(struct wl1251 *wl);
34720 -};
34721 +} __no_const;
34722
34723 struct wl1251 {
34724 struct ieee80211_hw *hw;
34725 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
34726 index f34b5b2..b5abb9f 100644
34727 --- a/drivers/oprofile/buffer_sync.c
34728 +++ b/drivers/oprofile/buffer_sync.c
34729 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
34730 if (cookie == NO_COOKIE)
34731 offset = pc;
34732 if (cookie == INVALID_COOKIE) {
34733 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
34734 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
34735 offset = pc;
34736 }
34737 if (cookie != last_cookie) {
34738 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
34739 /* add userspace sample */
34740
34741 if (!mm) {
34742 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
34743 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
34744 return 0;
34745 }
34746
34747 cookie = lookup_dcookie(mm, s->eip, &offset);
34748
34749 if (cookie == INVALID_COOKIE) {
34750 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
34751 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
34752 return 0;
34753 }
34754
34755 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
34756 /* ignore backtraces if failed to add a sample */
34757 if (state == sb_bt_start) {
34758 state = sb_bt_ignore;
34759 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
34760 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
34761 }
34762 }
34763 release_mm(mm);
34764 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
34765 index c0cc4e7..44d4e54 100644
34766 --- a/drivers/oprofile/event_buffer.c
34767 +++ b/drivers/oprofile/event_buffer.c
34768 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
34769 }
34770
34771 if (buffer_pos == buffer_size) {
34772 - atomic_inc(&oprofile_stats.event_lost_overflow);
34773 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
34774 return;
34775 }
34776
34777 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
34778 index f8c752e..28bf4fc 100644
34779 --- a/drivers/oprofile/oprof.c
34780 +++ b/drivers/oprofile/oprof.c
34781 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
34782 if (oprofile_ops.switch_events())
34783 return;
34784
34785 - atomic_inc(&oprofile_stats.multiplex_counter);
34786 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
34787 start_switch_worker();
34788 }
34789
34790 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
34791 index 917d28e..d62d981 100644
34792 --- a/drivers/oprofile/oprofile_stats.c
34793 +++ b/drivers/oprofile/oprofile_stats.c
34794 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
34795 cpu_buf->sample_invalid_eip = 0;
34796 }
34797
34798 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
34799 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
34800 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
34801 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
34802 - atomic_set(&oprofile_stats.multiplex_counter, 0);
34803 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
34804 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
34805 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
34806 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
34807 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
34808 }
34809
34810
34811 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
34812 index 38b6fc0..b5cbfce 100644
34813 --- a/drivers/oprofile/oprofile_stats.h
34814 +++ b/drivers/oprofile/oprofile_stats.h
34815 @@ -13,11 +13,11 @@
34816 #include <linux/atomic.h>
34817
34818 struct oprofile_stat_struct {
34819 - atomic_t sample_lost_no_mm;
34820 - atomic_t sample_lost_no_mapping;
34821 - atomic_t bt_lost_no_mapping;
34822 - atomic_t event_lost_overflow;
34823 - atomic_t multiplex_counter;
34824 + atomic_unchecked_t sample_lost_no_mm;
34825 + atomic_unchecked_t sample_lost_no_mapping;
34826 + atomic_unchecked_t bt_lost_no_mapping;
34827 + atomic_unchecked_t event_lost_overflow;
34828 + atomic_unchecked_t multiplex_counter;
34829 };
34830
34831 extern struct oprofile_stat_struct oprofile_stats;
34832 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
34833 index 2f0aa0f..90fab02 100644
34834 --- a/drivers/oprofile/oprofilefs.c
34835 +++ b/drivers/oprofile/oprofilefs.c
34836 @@ -193,7 +193,7 @@ static const struct file_operations atomic_ro_fops = {
34837
34838
34839 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
34840 - char const *name, atomic_t *val)
34841 + char const *name, atomic_unchecked_t *val)
34842 {
34843 return __oprofilefs_create_file(sb, root, name,
34844 &atomic_ro_fops, 0444, val);
34845 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
34846 index 3f56bc0..707d642 100644
34847 --- a/drivers/parport/procfs.c
34848 +++ b/drivers/parport/procfs.c
34849 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
34850
34851 *ppos += len;
34852
34853 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
34854 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
34855 }
34856
34857 #ifdef CONFIG_PARPORT_1284
34858 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
34859
34860 *ppos += len;
34861
34862 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
34863 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
34864 }
34865 #endif /* IEEE1284.3 support. */
34866
34867 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
34868 index 9fff878..ad0ad53 100644
34869 --- a/drivers/pci/hotplug/cpci_hotplug.h
34870 +++ b/drivers/pci/hotplug/cpci_hotplug.h
34871 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
34872 int (*hardware_test) (struct slot* slot, u32 value);
34873 u8 (*get_power) (struct slot* slot);
34874 int (*set_power) (struct slot* slot, int value);
34875 -};
34876 +} __no_const;
34877
34878 struct cpci_hp_controller {
34879 unsigned int irq;
34880 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
34881 index 76ba8a1..20ca857 100644
34882 --- a/drivers/pci/hotplug/cpqphp_nvram.c
34883 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
34884 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
34885
34886 void compaq_nvram_init (void __iomem *rom_start)
34887 {
34888 +
34889 +#ifndef CONFIG_PAX_KERNEXEC
34890 if (rom_start) {
34891 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
34892 }
34893 +#endif
34894 +
34895 dbg("int15 entry = %p\n", compaq_int15_entry_point);
34896
34897 /* initialize our int15 lock */
34898 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
34899 index 1cfbf22..be96487 100644
34900 --- a/drivers/pci/pcie/aspm.c
34901 +++ b/drivers/pci/pcie/aspm.c
34902 @@ -27,9 +27,9 @@
34903 #define MODULE_PARAM_PREFIX "pcie_aspm."
34904
34905 /* Note: those are not register definitions */
34906 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
34907 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
34908 -#define ASPM_STATE_L1 (4) /* L1 state */
34909 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
34910 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
34911 +#define ASPM_STATE_L1 (4U) /* L1 state */
34912 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
34913 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
34914
34915 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
34916 index dfee1b3..a454fb6 100644
34917 --- a/drivers/pci/probe.c
34918 +++ b/drivers/pci/probe.c
34919 @@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
34920 u32 l, sz, mask;
34921 u16 orig_cmd;
34922
34923 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
34924 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
34925
34926 if (!dev->mmio_always_on) {
34927 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
34928 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
34929 index 27911b5..5b6db88 100644
34930 --- a/drivers/pci/proc.c
34931 +++ b/drivers/pci/proc.c
34932 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
34933 static int __init pci_proc_init(void)
34934 {
34935 struct pci_dev *dev = NULL;
34936 +
34937 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
34938 +#ifdef CONFIG_GRKERNSEC_PROC_USER
34939 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
34940 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
34941 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
34942 +#endif
34943 +#else
34944 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
34945 +#endif
34946 proc_create("devices", 0, proc_bus_pci_dir,
34947 &proc_bus_pci_dev_operations);
34948 proc_initialized = 1;
34949 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
34950 index 7b82868..b9344c9 100644
34951 --- a/drivers/platform/x86/thinkpad_acpi.c
34952 +++ b/drivers/platform/x86/thinkpad_acpi.c
34953 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
34954 return 0;
34955 }
34956
34957 -void static hotkey_mask_warn_incomplete_mask(void)
34958 +static void hotkey_mask_warn_incomplete_mask(void)
34959 {
34960 /* log only what the user can fix... */
34961 const u32 wantedmask = hotkey_driver_mask &
34962 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
34963 }
34964 }
34965
34966 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
34967 - struct tp_nvram_state *newn,
34968 - const u32 event_mask)
34969 -{
34970 -
34971 #define TPACPI_COMPARE_KEY(__scancode, __member) \
34972 do { \
34973 if ((event_mask & (1 << __scancode)) && \
34974 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
34975 tpacpi_hotkey_send_key(__scancode); \
34976 } while (0)
34977
34978 - void issue_volchange(const unsigned int oldvol,
34979 - const unsigned int newvol)
34980 - {
34981 - unsigned int i = oldvol;
34982 +static void issue_volchange(const unsigned int oldvol,
34983 + const unsigned int newvol,
34984 + const u32 event_mask)
34985 +{
34986 + unsigned int i = oldvol;
34987
34988 - while (i > newvol) {
34989 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
34990 - i--;
34991 - }
34992 - while (i < newvol) {
34993 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
34994 - i++;
34995 - }
34996 + while (i > newvol) {
34997 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
34998 + i--;
34999 }
35000 + while (i < newvol) {
35001 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35002 + i++;
35003 + }
35004 +}
35005
35006 - void issue_brightnesschange(const unsigned int oldbrt,
35007 - const unsigned int newbrt)
35008 - {
35009 - unsigned int i = oldbrt;
35010 +static void issue_brightnesschange(const unsigned int oldbrt,
35011 + const unsigned int newbrt,
35012 + const u32 event_mask)
35013 +{
35014 + unsigned int i = oldbrt;
35015
35016 - while (i > newbrt) {
35017 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35018 - i--;
35019 - }
35020 - while (i < newbrt) {
35021 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35022 - i++;
35023 - }
35024 + while (i > newbrt) {
35025 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35026 + i--;
35027 + }
35028 + while (i < newbrt) {
35029 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35030 + i++;
35031 }
35032 +}
35033
35034 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35035 + struct tp_nvram_state *newn,
35036 + const u32 event_mask)
35037 +{
35038 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35039 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35040 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35041 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35042 oldn->volume_level != newn->volume_level) {
35043 /* recently muted, or repeated mute keypress, or
35044 * multiple presses ending in mute */
35045 - issue_volchange(oldn->volume_level, newn->volume_level);
35046 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35047 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
35048 }
35049 } else {
35050 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35051 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35052 }
35053 if (oldn->volume_level != newn->volume_level) {
35054 - issue_volchange(oldn->volume_level, newn->volume_level);
35055 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35056 } else if (oldn->volume_toggle != newn->volume_toggle) {
35057 /* repeated vol up/down keypress at end of scale ? */
35058 if (newn->volume_level == 0)
35059 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35060 /* handle brightness */
35061 if (oldn->brightness_level != newn->brightness_level) {
35062 issue_brightnesschange(oldn->brightness_level,
35063 - newn->brightness_level);
35064 + newn->brightness_level,
35065 + event_mask);
35066 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
35067 /* repeated key presses that didn't change state */
35068 if (newn->brightness_level == 0)
35069 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35070 && !tp_features.bright_unkfw)
35071 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35072 }
35073 +}
35074
35075 #undef TPACPI_COMPARE_KEY
35076 #undef TPACPI_MAY_SEND_KEY
35077 -}
35078
35079 /*
35080 * Polling driver
35081 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
35082 index b859d16..5cc6b1a 100644
35083 --- a/drivers/pnp/pnpbios/bioscalls.c
35084 +++ b/drivers/pnp/pnpbios/bioscalls.c
35085 @@ -59,7 +59,7 @@ do { \
35086 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
35087 } while(0)
35088
35089 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
35090 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
35091 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
35092
35093 /*
35094 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35095
35096 cpu = get_cpu();
35097 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
35098 +
35099 + pax_open_kernel();
35100 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
35101 + pax_close_kernel();
35102
35103 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
35104 spin_lock_irqsave(&pnp_bios_lock, flags);
35105 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35106 :"memory");
35107 spin_unlock_irqrestore(&pnp_bios_lock, flags);
35108
35109 + pax_open_kernel();
35110 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
35111 + pax_close_kernel();
35112 +
35113 put_cpu();
35114
35115 /* If we get here and this is set then the PnP BIOS faulted on us. */
35116 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
35117 return status;
35118 }
35119
35120 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
35121 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
35122 {
35123 int i;
35124
35125 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35126 pnp_bios_callpoint.offset = header->fields.pm16offset;
35127 pnp_bios_callpoint.segment = PNP_CS16;
35128
35129 + pax_open_kernel();
35130 +
35131 for_each_possible_cpu(i) {
35132 struct desc_struct *gdt = get_cpu_gdt_table(i);
35133 if (!gdt)
35134 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35135 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
35136 (unsigned long)__va(header->fields.pm16dseg));
35137 }
35138 +
35139 + pax_close_kernel();
35140 }
35141 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
35142 index b0ecacb..7c9da2e 100644
35143 --- a/drivers/pnp/resource.c
35144 +++ b/drivers/pnp/resource.c
35145 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
35146 return 1;
35147
35148 /* check if the resource is valid */
35149 - if (*irq < 0 || *irq > 15)
35150 + if (*irq > 15)
35151 return 0;
35152
35153 /* check if the resource is reserved */
35154 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
35155 return 1;
35156
35157 /* check if the resource is valid */
35158 - if (*dma < 0 || *dma == 4 || *dma > 7)
35159 + if (*dma == 4 || *dma > 7)
35160 return 0;
35161
35162 /* check if the resource is reserved */
35163 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
35164 index bb16f5b..c751eef 100644
35165 --- a/drivers/power/bq27x00_battery.c
35166 +++ b/drivers/power/bq27x00_battery.c
35167 @@ -67,7 +67,7 @@
35168 struct bq27x00_device_info;
35169 struct bq27x00_access_methods {
35170 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
35171 -};
35172 +} __no_const;
35173
35174 enum bq27x00_chip { BQ27000, BQ27500 };
35175
35176 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
35177 index 33f5d9a..d957d3f 100644
35178 --- a/drivers/regulator/max8660.c
35179 +++ b/drivers/regulator/max8660.c
35180 @@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
35181 max8660->shadow_regs[MAX8660_OVER1] = 5;
35182 } else {
35183 /* Otherwise devices can be toggled via software */
35184 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
35185 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
35186 + pax_open_kernel();
35187 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
35188 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
35189 + pax_close_kernel();
35190 }
35191
35192 /*
35193 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
35194 index 023d17d..74ef35b 100644
35195 --- a/drivers/regulator/mc13892-regulator.c
35196 +++ b/drivers/regulator/mc13892-regulator.c
35197 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
35198 }
35199 mc13xxx_unlock(mc13892);
35200
35201 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
35202 + pax_open_kernel();
35203 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
35204 = mc13892_vcam_set_mode;
35205 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
35206 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
35207 = mc13892_vcam_get_mode;
35208 + pax_close_kernel();
35209 for (i = 0; i < pdata->num_regulators; i++) {
35210 init_data = &pdata->regulators[i];
35211 priv->regulators[i] = regulator_register(
35212 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
35213 index cace6d3..f623fda 100644
35214 --- a/drivers/rtc/rtc-dev.c
35215 +++ b/drivers/rtc/rtc-dev.c
35216 @@ -14,6 +14,7 @@
35217 #include <linux/module.h>
35218 #include <linux/rtc.h>
35219 #include <linux/sched.h>
35220 +#include <linux/grsecurity.h>
35221 #include "rtc-core.h"
35222
35223 static dev_t rtc_devt;
35224 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
35225 if (copy_from_user(&tm, uarg, sizeof(tm)))
35226 return -EFAULT;
35227
35228 + gr_log_timechange();
35229 +
35230 return rtc_set_time(rtc, &tm);
35231
35232 case RTC_PIE_ON:
35233 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
35234 index ffb5878..e6d785c 100644
35235 --- a/drivers/scsi/aacraid/aacraid.h
35236 +++ b/drivers/scsi/aacraid/aacraid.h
35237 @@ -492,7 +492,7 @@ struct adapter_ops
35238 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
35239 /* Administrative operations */
35240 int (*adapter_comm)(struct aac_dev * dev, int comm);
35241 -};
35242 +} __no_const;
35243
35244 /*
35245 * Define which interrupt handler needs to be installed
35246 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
35247 index 705e13e..91c873c 100644
35248 --- a/drivers/scsi/aacraid/linit.c
35249 +++ b/drivers/scsi/aacraid/linit.c
35250 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
35251 #elif defined(__devinitconst)
35252 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
35253 #else
35254 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
35255 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
35256 #endif
35257 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
35258 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
35259 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
35260 index d5ff142..49c0ebb 100644
35261 --- a/drivers/scsi/aic94xx/aic94xx_init.c
35262 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
35263 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
35264 .lldd_control_phy = asd_control_phy,
35265 };
35266
35267 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
35268 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
35269 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
35270 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
35271 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
35272 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
35273 index a796de9..1ef20e1 100644
35274 --- a/drivers/scsi/bfa/bfa.h
35275 +++ b/drivers/scsi/bfa/bfa.h
35276 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
35277 u32 *end);
35278 int cpe_vec_q0;
35279 int rme_vec_q0;
35280 -};
35281 +} __no_const;
35282 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
35283
35284 struct bfa_faa_cbfn_s {
35285 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
35286 index e07bd47..cd1bbbb 100644
35287 --- a/drivers/scsi/bfa/bfa_fcpim.c
35288 +++ b/drivers/scsi/bfa/bfa_fcpim.c
35289 @@ -4121,7 +4121,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
35290
35291 bfa_iotag_attach(fcp);
35292
35293 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
35294 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
35295 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
35296 (fcp->num_itns * sizeof(struct bfa_itn_s));
35297 memset(fcp->itn_arr, 0,
35298 @@ -4179,7 +4179,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
35299 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
35300 {
35301 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
35302 - struct bfa_itn_s *itn;
35303 + bfa_itn_s_no_const *itn;
35304
35305 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
35306 itn->isr = isr;
35307 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
35308 index 1080bcb..a3b39e3 100644
35309 --- a/drivers/scsi/bfa/bfa_fcpim.h
35310 +++ b/drivers/scsi/bfa/bfa_fcpim.h
35311 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
35312 struct bfa_itn_s {
35313 bfa_isr_func_t isr;
35314 };
35315 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
35316
35317 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
35318 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
35319 @@ -149,7 +150,7 @@ struct bfa_fcp_mod_s {
35320 struct list_head iotag_tio_free_q; /* free IO resources */
35321 struct list_head iotag_unused_q; /* unused IO resources*/
35322 struct bfa_iotag_s *iotag_arr;
35323 - struct bfa_itn_s *itn_arr;
35324 + bfa_itn_s_no_const *itn_arr;
35325 int num_ioim_reqs;
35326 int num_fwtio_reqs;
35327 int num_itns;
35328 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
35329 index 546d46b..642fa5b 100644
35330 --- a/drivers/scsi/bfa/bfa_ioc.h
35331 +++ b/drivers/scsi/bfa/bfa_ioc.h
35332 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
35333 bfa_ioc_disable_cbfn_t disable_cbfn;
35334 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
35335 bfa_ioc_reset_cbfn_t reset_cbfn;
35336 -};
35337 +} __no_const;
35338
35339 /*
35340 * IOC event notification mechanism.
35341 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
35342 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
35343 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
35344 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
35345 -};
35346 +} __no_const;
35347
35348 /*
35349 * Queue element to wait for room in request queue. FIFO order is
35350 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
35351 index 351dc0b..951dc32 100644
35352 --- a/drivers/scsi/hosts.c
35353 +++ b/drivers/scsi/hosts.c
35354 @@ -42,7 +42,7 @@
35355 #include "scsi_logging.h"
35356
35357
35358 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
35359 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
35360
35361
35362 static void scsi_host_cls_release(struct device *dev)
35363 @@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
35364 * subtract one because we increment first then return, but we need to
35365 * know what the next host number was before increment
35366 */
35367 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
35368 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
35369 shost->dma_channel = 0xff;
35370
35371 /* These three are default values which can be overridden */
35372 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
35373 index 865d452..e9b7fa7 100644
35374 --- a/drivers/scsi/hpsa.c
35375 +++ b/drivers/scsi/hpsa.c
35376 @@ -505,7 +505,7 @@ static inline u32 next_command(struct ctlr_info *h)
35377 u32 a;
35378
35379 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
35380 - return h->access.command_completed(h);
35381 + return h->access->command_completed(h);
35382
35383 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
35384 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
35385 @@ -2989,7 +2989,7 @@ static void start_io(struct ctlr_info *h)
35386 while (!list_empty(&h->reqQ)) {
35387 c = list_entry(h->reqQ.next, struct CommandList, list);
35388 /* can't do anything if fifo is full */
35389 - if ((h->access.fifo_full(h))) {
35390 + if ((h->access->fifo_full(h))) {
35391 dev_warn(&h->pdev->dev, "fifo full\n");
35392 break;
35393 }
35394 @@ -2999,7 +2999,7 @@ static void start_io(struct ctlr_info *h)
35395 h->Qdepth--;
35396
35397 /* Tell the controller execute command */
35398 - h->access.submit_command(h, c);
35399 + h->access->submit_command(h, c);
35400
35401 /* Put job onto the completed Q */
35402 addQ(&h->cmpQ, c);
35403 @@ -3008,17 +3008,17 @@ static void start_io(struct ctlr_info *h)
35404
35405 static inline unsigned long get_next_completion(struct ctlr_info *h)
35406 {
35407 - return h->access.command_completed(h);
35408 + return h->access->command_completed(h);
35409 }
35410
35411 static inline bool interrupt_pending(struct ctlr_info *h)
35412 {
35413 - return h->access.intr_pending(h);
35414 + return h->access->intr_pending(h);
35415 }
35416
35417 static inline long interrupt_not_for_us(struct ctlr_info *h)
35418 {
35419 - return (h->access.intr_pending(h) == 0) ||
35420 + return (h->access->intr_pending(h) == 0) ||
35421 (h->interrupts_enabled == 0);
35422 }
35423
35424 @@ -3917,7 +3917,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
35425 if (prod_index < 0)
35426 return -ENODEV;
35427 h->product_name = products[prod_index].product_name;
35428 - h->access = *(products[prod_index].access);
35429 + h->access = products[prod_index].access;
35430
35431 if (hpsa_board_disabled(h->pdev)) {
35432 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
35433 @@ -4162,7 +4162,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
35434
35435 assert_spin_locked(&lockup_detector_lock);
35436 remove_ctlr_from_lockup_detector_list(h);
35437 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
35438 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
35439 spin_lock_irqsave(&h->lock, flags);
35440 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
35441 spin_unlock_irqrestore(&h->lock, flags);
35442 @@ -4340,7 +4340,7 @@ reinit_after_soft_reset:
35443 }
35444
35445 /* make sure the board interrupts are off */
35446 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
35447 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
35448
35449 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
35450 goto clean2;
35451 @@ -4374,7 +4374,7 @@ reinit_after_soft_reset:
35452 * fake ones to scoop up any residual completions.
35453 */
35454 spin_lock_irqsave(&h->lock, flags);
35455 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
35456 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
35457 spin_unlock_irqrestore(&h->lock, flags);
35458 free_irq(h->intr[h->intr_mode], h);
35459 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
35460 @@ -4393,9 +4393,9 @@ reinit_after_soft_reset:
35461 dev_info(&h->pdev->dev, "Board READY.\n");
35462 dev_info(&h->pdev->dev,
35463 "Waiting for stale completions to drain.\n");
35464 - h->access.set_intr_mask(h, HPSA_INTR_ON);
35465 + h->access->set_intr_mask(h, HPSA_INTR_ON);
35466 msleep(10000);
35467 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
35468 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
35469
35470 rc = controller_reset_failed(h->cfgtable);
35471 if (rc)
35472 @@ -4416,7 +4416,7 @@ reinit_after_soft_reset:
35473 }
35474
35475 /* Turn the interrupts on so we can service requests */
35476 - h->access.set_intr_mask(h, HPSA_INTR_ON);
35477 + h->access->set_intr_mask(h, HPSA_INTR_ON);
35478
35479 hpsa_hba_inquiry(h);
35480 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
35481 @@ -4468,7 +4468,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
35482 * To write all data in the battery backed cache to disks
35483 */
35484 hpsa_flush_cache(h);
35485 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
35486 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
35487 free_irq(h->intr[h->intr_mode], h);
35488 #ifdef CONFIG_PCI_MSI
35489 if (h->msix_vector)
35490 @@ -4632,7 +4632,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
35491 return;
35492 }
35493 /* Change the access methods to the performant access methods */
35494 - h->access = SA5_performant_access;
35495 + h->access = &SA5_performant_access;
35496 h->transMethod = CFGTBL_Trans_Performant;
35497 }
35498
35499 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
35500 index 91edafb..a9b88ec 100644
35501 --- a/drivers/scsi/hpsa.h
35502 +++ b/drivers/scsi/hpsa.h
35503 @@ -73,7 +73,7 @@ struct ctlr_info {
35504 unsigned int msix_vector;
35505 unsigned int msi_vector;
35506 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
35507 - struct access_method access;
35508 + struct access_method *access;
35509
35510 /* queue and queue Info */
35511 struct list_head reqQ;
35512 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
35513 index f2df059..a3a9930 100644
35514 --- a/drivers/scsi/ips.h
35515 +++ b/drivers/scsi/ips.h
35516 @@ -1027,7 +1027,7 @@ typedef struct {
35517 int (*intr)(struct ips_ha *);
35518 void (*enableint)(struct ips_ha *);
35519 uint32_t (*statupd)(struct ips_ha *);
35520 -} ips_hw_func_t;
35521 +} __no_const ips_hw_func_t;
35522
35523 typedef struct ips_ha {
35524 uint8_t ha_id[IPS_MAX_CHANNELS+1];
35525 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
35526 index 9de9db2..1e09660 100644
35527 --- a/drivers/scsi/libfc/fc_exch.c
35528 +++ b/drivers/scsi/libfc/fc_exch.c
35529 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
35530 * all together if not used XXX
35531 */
35532 struct {
35533 - atomic_t no_free_exch;
35534 - atomic_t no_free_exch_xid;
35535 - atomic_t xid_not_found;
35536 - atomic_t xid_busy;
35537 - atomic_t seq_not_found;
35538 - atomic_t non_bls_resp;
35539 + atomic_unchecked_t no_free_exch;
35540 + atomic_unchecked_t no_free_exch_xid;
35541 + atomic_unchecked_t xid_not_found;
35542 + atomic_unchecked_t xid_busy;
35543 + atomic_unchecked_t seq_not_found;
35544 + atomic_unchecked_t non_bls_resp;
35545 } stats;
35546 };
35547
35548 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
35549 /* allocate memory for exchange */
35550 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
35551 if (!ep) {
35552 - atomic_inc(&mp->stats.no_free_exch);
35553 + atomic_inc_unchecked(&mp->stats.no_free_exch);
35554 goto out;
35555 }
35556 memset(ep, 0, sizeof(*ep));
35557 @@ -780,7 +780,7 @@ out:
35558 return ep;
35559 err:
35560 spin_unlock_bh(&pool->lock);
35561 - atomic_inc(&mp->stats.no_free_exch_xid);
35562 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
35563 mempool_free(ep, mp->ep_pool);
35564 return NULL;
35565 }
35566 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
35567 xid = ntohs(fh->fh_ox_id); /* we originated exch */
35568 ep = fc_exch_find(mp, xid);
35569 if (!ep) {
35570 - atomic_inc(&mp->stats.xid_not_found);
35571 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35572 reject = FC_RJT_OX_ID;
35573 goto out;
35574 }
35575 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
35576 ep = fc_exch_find(mp, xid);
35577 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
35578 if (ep) {
35579 - atomic_inc(&mp->stats.xid_busy);
35580 + atomic_inc_unchecked(&mp->stats.xid_busy);
35581 reject = FC_RJT_RX_ID;
35582 goto rel;
35583 }
35584 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
35585 }
35586 xid = ep->xid; /* get our XID */
35587 } else if (!ep) {
35588 - atomic_inc(&mp->stats.xid_not_found);
35589 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35590 reject = FC_RJT_RX_ID; /* XID not found */
35591 goto out;
35592 }
35593 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
35594 } else {
35595 sp = &ep->seq;
35596 if (sp->id != fh->fh_seq_id) {
35597 - atomic_inc(&mp->stats.seq_not_found);
35598 + atomic_inc_unchecked(&mp->stats.seq_not_found);
35599 if (f_ctl & FC_FC_END_SEQ) {
35600 /*
35601 * Update sequence_id based on incoming last
35602 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
35603
35604 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
35605 if (!ep) {
35606 - atomic_inc(&mp->stats.xid_not_found);
35607 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35608 goto out;
35609 }
35610 if (ep->esb_stat & ESB_ST_COMPLETE) {
35611 - atomic_inc(&mp->stats.xid_not_found);
35612 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35613 goto rel;
35614 }
35615 if (ep->rxid == FC_XID_UNKNOWN)
35616 ep->rxid = ntohs(fh->fh_rx_id);
35617 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
35618 - atomic_inc(&mp->stats.xid_not_found);
35619 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35620 goto rel;
35621 }
35622 if (ep->did != ntoh24(fh->fh_s_id) &&
35623 ep->did != FC_FID_FLOGI) {
35624 - atomic_inc(&mp->stats.xid_not_found);
35625 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35626 goto rel;
35627 }
35628 sof = fr_sof(fp);
35629 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
35630 sp->ssb_stat |= SSB_ST_RESP;
35631 sp->id = fh->fh_seq_id;
35632 } else if (sp->id != fh->fh_seq_id) {
35633 - atomic_inc(&mp->stats.seq_not_found);
35634 + atomic_inc_unchecked(&mp->stats.seq_not_found);
35635 goto rel;
35636 }
35637
35638 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
35639 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
35640
35641 if (!sp)
35642 - atomic_inc(&mp->stats.xid_not_found);
35643 + atomic_inc_unchecked(&mp->stats.xid_not_found);
35644 else
35645 - atomic_inc(&mp->stats.non_bls_resp);
35646 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
35647
35648 fc_frame_free(fp);
35649 }
35650 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
35651 index db9238f..4378ed2 100644
35652 --- a/drivers/scsi/libsas/sas_ata.c
35653 +++ b/drivers/scsi/libsas/sas_ata.c
35654 @@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
35655 .postreset = ata_std_postreset,
35656 .error_handler = ata_std_error_handler,
35657 .post_internal_cmd = sas_ata_post_internal,
35658 - .qc_defer = ata_std_qc_defer,
35659 + .qc_defer = ata_std_qc_defer,
35660 .qc_prep = ata_noop_qc_prep,
35661 .qc_issue = sas_ata_qc_issue,
35662 .qc_fill_rtf = sas_ata_qc_fill_rtf,
35663 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
35664 index bb4c8e0..f33d849 100644
35665 --- a/drivers/scsi/lpfc/lpfc.h
35666 +++ b/drivers/scsi/lpfc/lpfc.h
35667 @@ -425,7 +425,7 @@ struct lpfc_vport {
35668 struct dentry *debug_nodelist;
35669 struct dentry *vport_debugfs_root;
35670 struct lpfc_debugfs_trc *disc_trc;
35671 - atomic_t disc_trc_cnt;
35672 + atomic_unchecked_t disc_trc_cnt;
35673 #endif
35674 uint8_t stat_data_enabled;
35675 uint8_t stat_data_blocked;
35676 @@ -835,8 +835,8 @@ struct lpfc_hba {
35677 struct timer_list fabric_block_timer;
35678 unsigned long bit_flags;
35679 #define FABRIC_COMANDS_BLOCKED 0
35680 - atomic_t num_rsrc_err;
35681 - atomic_t num_cmd_success;
35682 + atomic_unchecked_t num_rsrc_err;
35683 + atomic_unchecked_t num_cmd_success;
35684 unsigned long last_rsrc_error_time;
35685 unsigned long last_ramp_down_time;
35686 unsigned long last_ramp_up_time;
35687 @@ -866,7 +866,7 @@ struct lpfc_hba {
35688
35689 struct dentry *debug_slow_ring_trc;
35690 struct lpfc_debugfs_trc *slow_ring_trc;
35691 - atomic_t slow_ring_trc_cnt;
35692 + atomic_unchecked_t slow_ring_trc_cnt;
35693 /* iDiag debugfs sub-directory */
35694 struct dentry *idiag_root;
35695 struct dentry *idiag_pci_cfg;
35696 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
35697 index 2838259..a07cfb5 100644
35698 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
35699 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
35700 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
35701
35702 #include <linux/debugfs.h>
35703
35704 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
35705 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
35706 static unsigned long lpfc_debugfs_start_time = 0L;
35707
35708 /* iDiag */
35709 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
35710 lpfc_debugfs_enable = 0;
35711
35712 len = 0;
35713 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
35714 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
35715 (lpfc_debugfs_max_disc_trc - 1);
35716 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
35717 dtp = vport->disc_trc + i;
35718 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
35719 lpfc_debugfs_enable = 0;
35720
35721 len = 0;
35722 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
35723 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
35724 (lpfc_debugfs_max_slow_ring_trc - 1);
35725 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
35726 dtp = phba->slow_ring_trc + i;
35727 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
35728 !vport || !vport->disc_trc)
35729 return;
35730
35731 - index = atomic_inc_return(&vport->disc_trc_cnt) &
35732 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
35733 (lpfc_debugfs_max_disc_trc - 1);
35734 dtp = vport->disc_trc + index;
35735 dtp->fmt = fmt;
35736 dtp->data1 = data1;
35737 dtp->data2 = data2;
35738 dtp->data3 = data3;
35739 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
35740 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
35741 dtp->jif = jiffies;
35742 #endif
35743 return;
35744 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
35745 !phba || !phba->slow_ring_trc)
35746 return;
35747
35748 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
35749 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
35750 (lpfc_debugfs_max_slow_ring_trc - 1);
35751 dtp = phba->slow_ring_trc + index;
35752 dtp->fmt = fmt;
35753 dtp->data1 = data1;
35754 dtp->data2 = data2;
35755 dtp->data3 = data3;
35756 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
35757 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
35758 dtp->jif = jiffies;
35759 #endif
35760 return;
35761 @@ -3986,7 +3986,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
35762 "slow_ring buffer\n");
35763 goto debug_failed;
35764 }
35765 - atomic_set(&phba->slow_ring_trc_cnt, 0);
35766 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
35767 memset(phba->slow_ring_trc, 0,
35768 (sizeof(struct lpfc_debugfs_trc) *
35769 lpfc_debugfs_max_slow_ring_trc));
35770 @@ -4032,7 +4032,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
35771 "buffer\n");
35772 goto debug_failed;
35773 }
35774 - atomic_set(&vport->disc_trc_cnt, 0);
35775 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
35776
35777 snprintf(name, sizeof(name), "discovery_trace");
35778 vport->debug_disc_trc =
35779 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
35780 index 55bc4fc..a2a109c 100644
35781 --- a/drivers/scsi/lpfc/lpfc_init.c
35782 +++ b/drivers/scsi/lpfc/lpfc_init.c
35783 @@ -10027,8 +10027,10 @@ lpfc_init(void)
35784 printk(LPFC_COPYRIGHT "\n");
35785
35786 if (lpfc_enable_npiv) {
35787 - lpfc_transport_functions.vport_create = lpfc_vport_create;
35788 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
35789 + pax_open_kernel();
35790 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
35791 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
35792 + pax_close_kernel();
35793 }
35794 lpfc_transport_template =
35795 fc_attach_transport(&lpfc_transport_functions);
35796 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
35797 index 2e1e54e..1af0a0d 100644
35798 --- a/drivers/scsi/lpfc/lpfc_scsi.c
35799 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
35800 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
35801 uint32_t evt_posted;
35802
35803 spin_lock_irqsave(&phba->hbalock, flags);
35804 - atomic_inc(&phba->num_rsrc_err);
35805 + atomic_inc_unchecked(&phba->num_rsrc_err);
35806 phba->last_rsrc_error_time = jiffies;
35807
35808 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
35809 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
35810 unsigned long flags;
35811 struct lpfc_hba *phba = vport->phba;
35812 uint32_t evt_posted;
35813 - atomic_inc(&phba->num_cmd_success);
35814 + atomic_inc_unchecked(&phba->num_cmd_success);
35815
35816 if (vport->cfg_lun_queue_depth <= queue_depth)
35817 return;
35818 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
35819 unsigned long num_rsrc_err, num_cmd_success;
35820 int i;
35821
35822 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
35823 - num_cmd_success = atomic_read(&phba->num_cmd_success);
35824 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
35825 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
35826
35827 vports = lpfc_create_vport_work_array(phba);
35828 if (vports != NULL)
35829 @@ -411,8 +411,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
35830 }
35831 }
35832 lpfc_destroy_vport_work_array(phba, vports);
35833 - atomic_set(&phba->num_rsrc_err, 0);
35834 - atomic_set(&phba->num_cmd_success, 0);
35835 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
35836 + atomic_set_unchecked(&phba->num_cmd_success, 0);
35837 }
35838
35839 /**
35840 @@ -446,8 +446,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
35841 }
35842 }
35843 lpfc_destroy_vport_work_array(phba, vports);
35844 - atomic_set(&phba->num_rsrc_err, 0);
35845 - atomic_set(&phba->num_cmd_success, 0);
35846 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
35847 + atomic_set_unchecked(&phba->num_cmd_success, 0);
35848 }
35849
35850 /**
35851 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
35852 index 5163edb..7b142bc 100644
35853 --- a/drivers/scsi/pmcraid.c
35854 +++ b/drivers/scsi/pmcraid.c
35855 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
35856 res->scsi_dev = scsi_dev;
35857 scsi_dev->hostdata = res;
35858 res->change_detected = 0;
35859 - atomic_set(&res->read_failures, 0);
35860 - atomic_set(&res->write_failures, 0);
35861 + atomic_set_unchecked(&res->read_failures, 0);
35862 + atomic_set_unchecked(&res->write_failures, 0);
35863 rc = 0;
35864 }
35865 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
35866 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
35867
35868 /* If this was a SCSI read/write command keep count of errors */
35869 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
35870 - atomic_inc(&res->read_failures);
35871 + atomic_inc_unchecked(&res->read_failures);
35872 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
35873 - atomic_inc(&res->write_failures);
35874 + atomic_inc_unchecked(&res->write_failures);
35875
35876 if (!RES_IS_GSCSI(res->cfg_entry) &&
35877 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
35878 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
35879 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
35880 * hrrq_id assigned here in queuecommand
35881 */
35882 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
35883 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
35884 pinstance->num_hrrq;
35885 cmd->cmd_done = pmcraid_io_done;
35886
35887 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
35888 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
35889 * hrrq_id assigned here in queuecommand
35890 */
35891 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
35892 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
35893 pinstance->num_hrrq;
35894
35895 if (request_size) {
35896 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
35897
35898 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
35899 /* add resources only after host is added into system */
35900 - if (!atomic_read(&pinstance->expose_resources))
35901 + if (!atomic_read_unchecked(&pinstance->expose_resources))
35902 return;
35903
35904 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
35905 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
35906 init_waitqueue_head(&pinstance->reset_wait_q);
35907
35908 atomic_set(&pinstance->outstanding_cmds, 0);
35909 - atomic_set(&pinstance->last_message_id, 0);
35910 - atomic_set(&pinstance->expose_resources, 0);
35911 + atomic_set_unchecked(&pinstance->last_message_id, 0);
35912 + atomic_set_unchecked(&pinstance->expose_resources, 0);
35913
35914 INIT_LIST_HEAD(&pinstance->free_res_q);
35915 INIT_LIST_HEAD(&pinstance->used_res_q);
35916 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
35917 /* Schedule worker thread to handle CCN and take care of adding and
35918 * removing devices to OS
35919 */
35920 - atomic_set(&pinstance->expose_resources, 1);
35921 + atomic_set_unchecked(&pinstance->expose_resources, 1);
35922 schedule_work(&pinstance->worker_q);
35923 return rc;
35924
35925 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
35926 index ca496c7..9c791d5 100644
35927 --- a/drivers/scsi/pmcraid.h
35928 +++ b/drivers/scsi/pmcraid.h
35929 @@ -748,7 +748,7 @@ struct pmcraid_instance {
35930 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
35931
35932 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
35933 - atomic_t last_message_id;
35934 + atomic_unchecked_t last_message_id;
35935
35936 /* configuration table */
35937 struct pmcraid_config_table *cfg_table;
35938 @@ -777,7 +777,7 @@ struct pmcraid_instance {
35939 atomic_t outstanding_cmds;
35940
35941 /* should add/delete resources to mid-layer now ?*/
35942 - atomic_t expose_resources;
35943 + atomic_unchecked_t expose_resources;
35944
35945
35946
35947 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
35948 struct pmcraid_config_table_entry_ext cfg_entry_ext;
35949 };
35950 struct scsi_device *scsi_dev; /* Link scsi_device structure */
35951 - atomic_t read_failures; /* count of failed READ commands */
35952 - atomic_t write_failures; /* count of failed WRITE commands */
35953 + atomic_unchecked_t read_failures; /* count of failed READ commands */
35954 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
35955
35956 /* To indicate add/delete/modify during CCN */
35957 u8 change_detected;
35958 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
35959 index fcf052c..a8025a4 100644
35960 --- a/drivers/scsi/qla2xxx/qla_def.h
35961 +++ b/drivers/scsi/qla2xxx/qla_def.h
35962 @@ -2244,7 +2244,7 @@ struct isp_operations {
35963 int (*get_flash_version) (struct scsi_qla_host *, void *);
35964 int (*start_scsi) (srb_t *);
35965 int (*abort_isp) (struct scsi_qla_host *);
35966 -};
35967 +} __no_const;
35968
35969 /* MSI-X Support *************************************************************/
35970
35971 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
35972 index fd5edc6..4906148 100644
35973 --- a/drivers/scsi/qla4xxx/ql4_def.h
35974 +++ b/drivers/scsi/qla4xxx/ql4_def.h
35975 @@ -258,7 +258,7 @@ struct ddb_entry {
35976 * (4000 only) */
35977 atomic_t relogin_timer; /* Max Time to wait for
35978 * relogin to complete */
35979 - atomic_t relogin_retry_count; /* Num of times relogin has been
35980 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
35981 * retried */
35982 uint32_t default_time2wait; /* Default Min time between
35983 * relogins (+aens) */
35984 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
35985 index 4169c8b..a8b896b 100644
35986 --- a/drivers/scsi/qla4xxx/ql4_os.c
35987 +++ b/drivers/scsi/qla4xxx/ql4_os.c
35988 @@ -2104,12 +2104,12 @@ void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
35989 */
35990 if (!iscsi_is_session_online(cls_sess)) {
35991 /* Reset retry relogin timer */
35992 - atomic_inc(&ddb_entry->relogin_retry_count);
35993 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
35994 DEBUG2(ql4_printk(KERN_INFO, ha,
35995 "%s: index[%d] relogin timed out-retrying"
35996 " relogin (%d), retry (%d)\n", __func__,
35997 ddb_entry->fw_ddb_index,
35998 - atomic_read(&ddb_entry->relogin_retry_count),
35999 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
36000 ddb_entry->default_time2wait + 4));
36001 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
36002 atomic_set(&ddb_entry->retry_relogin_timer,
36003 @@ -3835,7 +3835,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
36004
36005 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36006 atomic_set(&ddb_entry->relogin_timer, 0);
36007 - atomic_set(&ddb_entry->relogin_retry_count, 0);
36008 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36009
36010 ddb_entry->default_relogin_timeout =
36011 le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
36012 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
36013 index 2aeb2e9..46e3925 100644
36014 --- a/drivers/scsi/scsi.c
36015 +++ b/drivers/scsi/scsi.c
36016 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
36017 unsigned long timeout;
36018 int rtn = 0;
36019
36020 - atomic_inc(&cmd->device->iorequest_cnt);
36021 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36022
36023 /* check if the device is still usable */
36024 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
36025 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
36026 index f85cfa6..a57c9e8 100644
36027 --- a/drivers/scsi/scsi_lib.c
36028 +++ b/drivers/scsi/scsi_lib.c
36029 @@ -1416,7 +1416,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
36030 shost = sdev->host;
36031 scsi_init_cmd_errh(cmd);
36032 cmd->result = DID_NO_CONNECT << 16;
36033 - atomic_inc(&cmd->device->iorequest_cnt);
36034 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36035
36036 /*
36037 * SCSI request completion path will do scsi_device_unbusy(),
36038 @@ -1442,9 +1442,9 @@ static void scsi_softirq_done(struct request *rq)
36039
36040 INIT_LIST_HEAD(&cmd->eh_entry);
36041
36042 - atomic_inc(&cmd->device->iodone_cnt);
36043 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
36044 if (cmd->result)
36045 - atomic_inc(&cmd->device->ioerr_cnt);
36046 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
36047
36048 disposition = scsi_decide_disposition(cmd);
36049 if (disposition != SUCCESS &&
36050 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
36051 index 04c2a27..9d8bd66 100644
36052 --- a/drivers/scsi/scsi_sysfs.c
36053 +++ b/drivers/scsi/scsi_sysfs.c
36054 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
36055 char *buf) \
36056 { \
36057 struct scsi_device *sdev = to_scsi_device(dev); \
36058 - unsigned long long count = atomic_read(&sdev->field); \
36059 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
36060 return snprintf(buf, 20, "0x%llx\n", count); \
36061 } \
36062 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
36063 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
36064 index 84a1fdf..693b0d6 100644
36065 --- a/drivers/scsi/scsi_tgt_lib.c
36066 +++ b/drivers/scsi/scsi_tgt_lib.c
36067 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
36068 int err;
36069
36070 dprintk("%lx %u\n", uaddr, len);
36071 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
36072 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
36073 if (err) {
36074 /*
36075 * TODO: need to fixup sg_tablesize, max_segment_size,
36076 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
36077 index 1b21491..1b7f60e 100644
36078 --- a/drivers/scsi/scsi_transport_fc.c
36079 +++ b/drivers/scsi/scsi_transport_fc.c
36080 @@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
36081 * Netlink Infrastructure
36082 */
36083
36084 -static atomic_t fc_event_seq;
36085 +static atomic_unchecked_t fc_event_seq;
36086
36087 /**
36088 * fc_get_event_number - Obtain the next sequential FC event number
36089 @@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
36090 u32
36091 fc_get_event_number(void)
36092 {
36093 - return atomic_add_return(1, &fc_event_seq);
36094 + return atomic_add_return_unchecked(1, &fc_event_seq);
36095 }
36096 EXPORT_SYMBOL(fc_get_event_number);
36097
36098 @@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
36099 {
36100 int error;
36101
36102 - atomic_set(&fc_event_seq, 0);
36103 + atomic_set_unchecked(&fc_event_seq, 0);
36104
36105 error = transport_class_register(&fc_host_class);
36106 if (error)
36107 @@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
36108 char *cp;
36109
36110 *val = simple_strtoul(buf, &cp, 0);
36111 - if ((*cp && (*cp != '\n')) || (*val < 0))
36112 + if (*cp && (*cp != '\n'))
36113 return -EINVAL;
36114 /*
36115 * Check for overflow; dev_loss_tmo is u32
36116 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
36117 index 96029e6..4d77fa0 100644
36118 --- a/drivers/scsi/scsi_transport_iscsi.c
36119 +++ b/drivers/scsi/scsi_transport_iscsi.c
36120 @@ -79,7 +79,7 @@ struct iscsi_internal {
36121 struct transport_container session_cont;
36122 };
36123
36124 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
36125 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
36126 static struct workqueue_struct *iscsi_eh_timer_workq;
36127
36128 static DEFINE_IDA(iscsi_sess_ida);
36129 @@ -1062,7 +1062,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
36130 int err;
36131
36132 ihost = shost->shost_data;
36133 - session->sid = atomic_add_return(1, &iscsi_session_nr);
36134 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
36135
36136 if (target_id == ISCSI_MAX_TARGET) {
36137 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
36138 @@ -2663,7 +2663,7 @@ static __init int iscsi_transport_init(void)
36139 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
36140 ISCSI_TRANSPORT_VERSION);
36141
36142 - atomic_set(&iscsi_session_nr, 0);
36143 + atomic_set_unchecked(&iscsi_session_nr, 0);
36144
36145 err = class_register(&iscsi_transport_class);
36146 if (err)
36147 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
36148 index 21a045e..ec89e03 100644
36149 --- a/drivers/scsi/scsi_transport_srp.c
36150 +++ b/drivers/scsi/scsi_transport_srp.c
36151 @@ -33,7 +33,7 @@
36152 #include "scsi_transport_srp_internal.h"
36153
36154 struct srp_host_attrs {
36155 - atomic_t next_port_id;
36156 + atomic_unchecked_t next_port_id;
36157 };
36158 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
36159
36160 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
36161 struct Scsi_Host *shost = dev_to_shost(dev);
36162 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
36163
36164 - atomic_set(&srp_host->next_port_id, 0);
36165 + atomic_set_unchecked(&srp_host->next_port_id, 0);
36166 return 0;
36167 }
36168
36169 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
36170 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
36171 rport->roles = ids->roles;
36172
36173 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
36174 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
36175 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
36176
36177 transport_setup_device(&rport->dev);
36178 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
36179 index 441a1c5..07cece7 100644
36180 --- a/drivers/scsi/sg.c
36181 +++ b/drivers/scsi/sg.c
36182 @@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
36183 sdp->disk->disk_name,
36184 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
36185 NULL,
36186 - (char *)arg);
36187 + (char __user *)arg);
36188 case BLKTRACESTART:
36189 return blk_trace_startstop(sdp->device->request_queue, 1);
36190 case BLKTRACESTOP:
36191 @@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
36192 const struct file_operations * fops;
36193 };
36194
36195 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
36196 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
36197 {"allow_dio", &adio_fops},
36198 {"debug", &debug_fops},
36199 {"def_reserved_size", &dressz_fops},
36200 @@ -2327,7 +2327,7 @@ sg_proc_init(void)
36201 {
36202 int k, mask;
36203 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
36204 - struct sg_proc_leaf * leaf;
36205 + const struct sg_proc_leaf * leaf;
36206
36207 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
36208 if (!sg_proc_sgp)
36209 diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
36210 index f64250e..1ee3049 100644
36211 --- a/drivers/spi/spi-dw-pci.c
36212 +++ b/drivers/spi/spi-dw-pci.c
36213 @@ -149,7 +149,7 @@ static int spi_resume(struct pci_dev *pdev)
36214 #define spi_resume NULL
36215 #endif
36216
36217 -static const struct pci_device_id pci_ids[] __devinitdata = {
36218 +static const struct pci_device_id pci_ids[] __devinitconst = {
36219 /* Intel MID platform SPI controller 0 */
36220 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
36221 {},
36222 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
36223 index 77eae99..b7cdcc9 100644
36224 --- a/drivers/spi/spi.c
36225 +++ b/drivers/spi/spi.c
36226 @@ -1024,7 +1024,7 @@ int spi_bus_unlock(struct spi_master *master)
36227 EXPORT_SYMBOL_GPL(spi_bus_unlock);
36228
36229 /* portable code must never pass more than 32 bytes */
36230 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
36231 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
36232
36233 static u8 *buf;
36234
36235 diff --git a/drivers/staging/gma500/power.c b/drivers/staging/gma500/power.c
36236 index 436fe97..4082570 100644
36237 --- a/drivers/staging/gma500/power.c
36238 +++ b/drivers/staging/gma500/power.c
36239 @@ -266,7 +266,7 @@ bool gma_power_begin(struct drm_device *dev, bool force_on)
36240 ret = gma_resume_pci(dev->pdev);
36241 if (ret == 0) {
36242 /* FIXME: we want to defer this for Medfield/Oaktrail */
36243 - gma_resume_display(dev);
36244 + gma_resume_display(dev->pdev);
36245 psb_irq_preinstall(dev);
36246 psb_irq_postinstall(dev);
36247 pm_runtime_get(&dev->pdev->dev);
36248 diff --git a/drivers/staging/hv/rndis_filter.c b/drivers/staging/hv/rndis_filter.c
36249 index bafccb3..e3ac78d 100644
36250 --- a/drivers/staging/hv/rndis_filter.c
36251 +++ b/drivers/staging/hv/rndis_filter.c
36252 @@ -42,7 +42,7 @@ struct rndis_device {
36253
36254 enum rndis_device_state state;
36255 bool link_state;
36256 - atomic_t new_req_id;
36257 + atomic_unchecked_t new_req_id;
36258
36259 spinlock_t request_lock;
36260 struct list_head req_list;
36261 @@ -116,7 +116,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
36262 * template
36263 */
36264 set = &rndis_msg->msg.set_req;
36265 - set->req_id = atomic_inc_return(&dev->new_req_id);
36266 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36267
36268 /* Add to the request list */
36269 spin_lock_irqsave(&dev->request_lock, flags);
36270 @@ -646,7 +646,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
36271
36272 /* Setup the rndis set */
36273 halt = &request->request_msg.msg.halt_req;
36274 - halt->req_id = atomic_inc_return(&dev->new_req_id);
36275 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36276
36277 /* Ignore return since this msg is optional. */
36278 rndis_filter_send_request(dev, request);
36279 diff --git a/drivers/staging/iio/buffer_generic.h b/drivers/staging/iio/buffer_generic.h
36280 index 9e8f010..af9efb56 100644
36281 --- a/drivers/staging/iio/buffer_generic.h
36282 +++ b/drivers/staging/iio/buffer_generic.h
36283 @@ -64,7 +64,7 @@ struct iio_buffer_access_funcs {
36284
36285 int (*is_enabled)(struct iio_buffer *buffer);
36286 int (*enable)(struct iio_buffer *buffer);
36287 -};
36288 +} __no_const;
36289
36290 /**
36291 * struct iio_buffer_setup_ops - buffer setup related callbacks
36292 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
36293 index 8b307b4..a97ac91 100644
36294 --- a/drivers/staging/octeon/ethernet-rx.c
36295 +++ b/drivers/staging/octeon/ethernet-rx.c
36296 @@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
36297 /* Increment RX stats for virtual ports */
36298 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
36299 #ifdef CONFIG_64BIT
36300 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
36301 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
36302 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
36303 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
36304 #else
36305 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
36306 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
36307 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
36308 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
36309 #endif
36310 }
36311 netif_receive_skb(skb);
36312 @@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
36313 dev->name);
36314 */
36315 #ifdef CONFIG_64BIT
36316 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
36317 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
36318 #else
36319 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
36320 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
36321 #endif
36322 dev_kfree_skb_irq(skb);
36323 }
36324 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
36325 index 076f866..2308070 100644
36326 --- a/drivers/staging/octeon/ethernet.c
36327 +++ b/drivers/staging/octeon/ethernet.c
36328 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
36329 * since the RX tasklet also increments it.
36330 */
36331 #ifdef CONFIG_64BIT
36332 - atomic64_add(rx_status.dropped_packets,
36333 - (atomic64_t *)&priv->stats.rx_dropped);
36334 + atomic64_add_unchecked(rx_status.dropped_packets,
36335 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
36336 #else
36337 - atomic_add(rx_status.dropped_packets,
36338 - (atomic_t *)&priv->stats.rx_dropped);
36339 + atomic_add_unchecked(rx_status.dropped_packets,
36340 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
36341 #endif
36342 }
36343
36344 diff --git a/drivers/staging/pohmelfs/inode.c b/drivers/staging/pohmelfs/inode.c
36345 index 7a19555..466456d 100644
36346 --- a/drivers/staging/pohmelfs/inode.c
36347 +++ b/drivers/staging/pohmelfs/inode.c
36348 @@ -1861,7 +1861,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
36349 mutex_init(&psb->mcache_lock);
36350 psb->mcache_root = RB_ROOT;
36351 psb->mcache_timeout = msecs_to_jiffies(5000);
36352 - atomic_long_set(&psb->mcache_gen, 0);
36353 + atomic_long_set_unchecked(&psb->mcache_gen, 0);
36354
36355 psb->trans_max_pages = 100;
36356
36357 @@ -1876,7 +1876,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
36358 INIT_LIST_HEAD(&psb->crypto_ready_list);
36359 INIT_LIST_HEAD(&psb->crypto_active_list);
36360
36361 - atomic_set(&psb->trans_gen, 1);
36362 + atomic_set_unchecked(&psb->trans_gen, 1);
36363 atomic_long_set(&psb->total_inodes, 0);
36364
36365 mutex_init(&psb->state_lock);
36366 diff --git a/drivers/staging/pohmelfs/mcache.c b/drivers/staging/pohmelfs/mcache.c
36367 index e22665c..a2a9390 100644
36368 --- a/drivers/staging/pohmelfs/mcache.c
36369 +++ b/drivers/staging/pohmelfs/mcache.c
36370 @@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_alloc(struct pohmelfs_sb *psb, u64 start
36371 m->data = data;
36372 m->start = start;
36373 m->size = size;
36374 - m->gen = atomic_long_inc_return(&psb->mcache_gen);
36375 + m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
36376
36377 mutex_lock(&psb->mcache_lock);
36378 err = pohmelfs_mcache_insert(psb, m);
36379 diff --git a/drivers/staging/pohmelfs/netfs.h b/drivers/staging/pohmelfs/netfs.h
36380 index 985b6b7..7699e05 100644
36381 --- a/drivers/staging/pohmelfs/netfs.h
36382 +++ b/drivers/staging/pohmelfs/netfs.h
36383 @@ -571,14 +571,14 @@ struct pohmelfs_config;
36384 struct pohmelfs_sb {
36385 struct rb_root mcache_root;
36386 struct mutex mcache_lock;
36387 - atomic_long_t mcache_gen;
36388 + atomic_long_unchecked_t mcache_gen;
36389 unsigned long mcache_timeout;
36390
36391 unsigned int idx;
36392
36393 unsigned int trans_retries;
36394
36395 - atomic_t trans_gen;
36396 + atomic_unchecked_t trans_gen;
36397
36398 unsigned int crypto_attached_size;
36399 unsigned int crypto_align_size;
36400 diff --git a/drivers/staging/pohmelfs/trans.c b/drivers/staging/pohmelfs/trans.c
36401 index 06c1a74..866eebc 100644
36402 --- a/drivers/staging/pohmelfs/trans.c
36403 +++ b/drivers/staging/pohmelfs/trans.c
36404 @@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_trans *t, struct pohmelfs_sb *psb)
36405 int err;
36406 struct netfs_cmd *cmd = t->iovec.iov_base;
36407
36408 - t->gen = atomic_inc_return(&psb->trans_gen);
36409 + t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
36410
36411 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
36412 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
36413 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
36414 index 86308a0..feaa925 100644
36415 --- a/drivers/staging/rtl8712/rtl871x_io.h
36416 +++ b/drivers/staging/rtl8712/rtl871x_io.h
36417 @@ -108,7 +108,7 @@ struct _io_ops {
36418 u8 *pmem);
36419 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
36420 u8 *pmem);
36421 -};
36422 +} __no_const;
36423
36424 struct io_req {
36425 struct list_head list;
36426 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
36427 index c7b5e8b..783d6cb 100644
36428 --- a/drivers/staging/sbe-2t3e3/netdev.c
36429 +++ b/drivers/staging/sbe-2t3e3/netdev.c
36430 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36431 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
36432
36433 if (rlen)
36434 - if (copy_to_user(data, &resp, rlen))
36435 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
36436 return -EFAULT;
36437
36438 return 0;
36439 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
36440 index be21617..0954e45 100644
36441 --- a/drivers/staging/usbip/usbip_common.h
36442 +++ b/drivers/staging/usbip/usbip_common.h
36443 @@ -289,7 +289,7 @@ struct usbip_device {
36444 void (*shutdown)(struct usbip_device *);
36445 void (*reset)(struct usbip_device *);
36446 void (*unusable)(struct usbip_device *);
36447 - } eh_ops;
36448 + } __no_const eh_ops;
36449 };
36450
36451 #if 0
36452 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
36453 index 88b3298..3783eee 100644
36454 --- a/drivers/staging/usbip/vhci.h
36455 +++ b/drivers/staging/usbip/vhci.h
36456 @@ -88,7 +88,7 @@ struct vhci_hcd {
36457 unsigned resuming:1;
36458 unsigned long re_timeout;
36459
36460 - atomic_t seqnum;
36461 + atomic_unchecked_t seqnum;
36462
36463 /*
36464 * NOTE:
36465 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
36466 index 2ee97e2..0420b86 100644
36467 --- a/drivers/staging/usbip/vhci_hcd.c
36468 +++ b/drivers/staging/usbip/vhci_hcd.c
36469 @@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
36470 return;
36471 }
36472
36473 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
36474 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
36475 if (priv->seqnum == 0xffff)
36476 dev_info(&urb->dev->dev, "seqnum max\n");
36477
36478 @@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
36479 return -ENOMEM;
36480 }
36481
36482 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
36483 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
36484 if (unlink->seqnum == 0xffff)
36485 pr_info("seqnum max\n");
36486
36487 @@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
36488 vdev->rhport = rhport;
36489 }
36490
36491 - atomic_set(&vhci->seqnum, 0);
36492 + atomic_set_unchecked(&vhci->seqnum, 0);
36493 spin_lock_init(&vhci->lock);
36494
36495 hcd->power_budget = 0; /* no limit */
36496 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
36497 index 3872b8c..fe6d2f4 100644
36498 --- a/drivers/staging/usbip/vhci_rx.c
36499 +++ b/drivers/staging/usbip/vhci_rx.c
36500 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
36501 if (!urb) {
36502 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
36503 pr_info("max seqnum %d\n",
36504 - atomic_read(&the_controller->seqnum));
36505 + atomic_read_unchecked(&the_controller->seqnum));
36506 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
36507 return;
36508 }
36509 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
36510 index 7735027..30eed13 100644
36511 --- a/drivers/staging/vt6655/hostap.c
36512 +++ b/drivers/staging/vt6655/hostap.c
36513 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
36514 *
36515 */
36516
36517 +static net_device_ops_no_const apdev_netdev_ops;
36518 +
36519 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
36520 {
36521 PSDevice apdev_priv;
36522 struct net_device *dev = pDevice->dev;
36523 int ret;
36524 - const struct net_device_ops apdev_netdev_ops = {
36525 - .ndo_start_xmit = pDevice->tx_80211,
36526 - };
36527
36528 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
36529
36530 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
36531 *apdev_priv = *pDevice;
36532 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
36533
36534 + /* only half broken now */
36535 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
36536 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
36537
36538 pDevice->apdev->type = ARPHRD_IEEE80211;
36539 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
36540 index 51b5adf..098e320 100644
36541 --- a/drivers/staging/vt6656/hostap.c
36542 +++ b/drivers/staging/vt6656/hostap.c
36543 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
36544 *
36545 */
36546
36547 +static net_device_ops_no_const apdev_netdev_ops;
36548 +
36549 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
36550 {
36551 PSDevice apdev_priv;
36552 struct net_device *dev = pDevice->dev;
36553 int ret;
36554 - const struct net_device_ops apdev_netdev_ops = {
36555 - .ndo_start_xmit = pDevice->tx_80211,
36556 - };
36557
36558 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
36559
36560 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
36561 *apdev_priv = *pDevice;
36562 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
36563
36564 + /* only half broken now */
36565 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
36566 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
36567
36568 pDevice->apdev->type = ARPHRD_IEEE80211;
36569 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
36570 index 7843dfd..3db105f 100644
36571 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
36572 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
36573 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
36574
36575 struct usbctlx_completor {
36576 int (*complete) (struct usbctlx_completor *);
36577 -};
36578 +} __no_const;
36579
36580 static int
36581 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
36582 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
36583 index 1ca66ea..76f1343 100644
36584 --- a/drivers/staging/zcache/tmem.c
36585 +++ b/drivers/staging/zcache/tmem.c
36586 @@ -39,7 +39,7 @@
36587 * A tmem host implementation must use this function to register callbacks
36588 * for memory allocation.
36589 */
36590 -static struct tmem_hostops tmem_hostops;
36591 +static tmem_hostops_no_const tmem_hostops;
36592
36593 static void tmem_objnode_tree_init(void);
36594
36595 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
36596 * A tmem host implementation must use this function to register
36597 * callbacks for a page-accessible memory (PAM) implementation
36598 */
36599 -static struct tmem_pamops tmem_pamops;
36600 +static tmem_pamops_no_const tmem_pamops;
36601
36602 void tmem_register_pamops(struct tmem_pamops *m)
36603 {
36604 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
36605 index ed147c4..94fc3c6 100644
36606 --- a/drivers/staging/zcache/tmem.h
36607 +++ b/drivers/staging/zcache/tmem.h
36608 @@ -180,6 +180,7 @@ struct tmem_pamops {
36609 void (*new_obj)(struct tmem_obj *);
36610 int (*replace_in_obj)(void *, struct tmem_obj *);
36611 };
36612 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
36613 extern void tmem_register_pamops(struct tmem_pamops *m);
36614
36615 /* memory allocation methods provided by the host implementation */
36616 @@ -189,6 +190,7 @@ struct tmem_hostops {
36617 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
36618 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
36619 };
36620 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
36621 extern void tmem_register_hostops(struct tmem_hostops *m);
36622
36623 /* core tmem accessor functions */
36624 diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
36625 index 0c1d5c73..88e90a8 100644
36626 --- a/drivers/target/iscsi/iscsi_target.c
36627 +++ b/drivers/target/iscsi/iscsi_target.c
36628 @@ -1364,7 +1364,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
36629 * outstanding_r2ts reaches zero, go ahead and send the delayed
36630 * TASK_ABORTED status.
36631 */
36632 - if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
36633 + if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
36634 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
36635 if (--cmd->outstanding_r2ts < 1) {
36636 iscsit_stop_dataout_timer(cmd);
36637 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
36638 index 6845228..df77141 100644
36639 --- a/drivers/target/target_core_tmr.c
36640 +++ b/drivers/target/target_core_tmr.c
36641 @@ -250,7 +250,7 @@ static void core_tmr_drain_task_list(
36642 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
36643 cmd->t_task_list_num,
36644 atomic_read(&cmd->t_task_cdbs_left),
36645 - atomic_read(&cmd->t_task_cdbs_sent),
36646 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
36647 atomic_read(&cmd->t_transport_active),
36648 atomic_read(&cmd->t_transport_stop),
36649 atomic_read(&cmd->t_transport_sent));
36650 @@ -281,7 +281,7 @@ static void core_tmr_drain_task_list(
36651 pr_debug("LUN_RESET: got t_transport_active = 1 for"
36652 " task: %p, t_fe_count: %d dev: %p\n", task,
36653 fe_count, dev);
36654 - atomic_set(&cmd->t_transport_aborted, 1);
36655 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
36656 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
36657
36658 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
36659 @@ -289,7 +289,7 @@ static void core_tmr_drain_task_list(
36660 }
36661 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
36662 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
36663 - atomic_set(&cmd->t_transport_aborted, 1);
36664 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
36665 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
36666
36667 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
36668 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
36669 index e4ddb93..2fc6e0f 100644
36670 --- a/drivers/target/target_core_transport.c
36671 +++ b/drivers/target/target_core_transport.c
36672 @@ -1343,7 +1343,7 @@ struct se_device *transport_add_device_to_core_hba(
36673
36674 dev->queue_depth = dev_limits->queue_depth;
36675 atomic_set(&dev->depth_left, dev->queue_depth);
36676 - atomic_set(&dev->dev_ordered_id, 0);
36677 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
36678
36679 se_dev_set_default_attribs(dev, dev_limits);
36680
36681 @@ -1530,7 +1530,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
36682 * Used to determine when ORDERED commands should go from
36683 * Dormant to Active status.
36684 */
36685 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
36686 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
36687 smp_mb__after_atomic_inc();
36688 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
36689 cmd->se_ordered_id, cmd->sam_task_attr,
36690 @@ -1800,7 +1800,7 @@ static void transport_generic_request_failure(struct se_cmd *cmd)
36691 " t_transport_active: %d t_transport_stop: %d"
36692 " t_transport_sent: %d\n", cmd->t_task_list_num,
36693 atomic_read(&cmd->t_task_cdbs_left),
36694 - atomic_read(&cmd->t_task_cdbs_sent),
36695 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
36696 atomic_read(&cmd->t_task_cdbs_ex_left),
36697 atomic_read(&cmd->t_transport_active),
36698 atomic_read(&cmd->t_transport_stop),
36699 @@ -2089,9 +2089,9 @@ check_depth:
36700
36701 spin_lock_irqsave(&cmd->t_state_lock, flags);
36702 task->task_flags |= (TF_ACTIVE | TF_SENT);
36703 - atomic_inc(&cmd->t_task_cdbs_sent);
36704 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
36705
36706 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
36707 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
36708 cmd->t_task_list_num)
36709 atomic_set(&cmd->t_transport_sent, 1);
36710
36711 @@ -4296,7 +4296,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
36712 atomic_set(&cmd->transport_lun_stop, 0);
36713 }
36714 if (!atomic_read(&cmd->t_transport_active) ||
36715 - atomic_read(&cmd->t_transport_aborted)) {
36716 + atomic_read_unchecked(&cmd->t_transport_aborted)) {
36717 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
36718 return false;
36719 }
36720 @@ -4545,7 +4545,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
36721 {
36722 int ret = 0;
36723
36724 - if (atomic_read(&cmd->t_transport_aborted) != 0) {
36725 + if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
36726 if (!send_status ||
36727 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
36728 return 1;
36729 @@ -4582,7 +4582,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
36730 */
36731 if (cmd->data_direction == DMA_TO_DEVICE) {
36732 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
36733 - atomic_inc(&cmd->t_transport_aborted);
36734 + atomic_inc_unchecked(&cmd->t_transport_aborted);
36735 smp_mb__after_atomic_inc();
36736 }
36737 }
36738 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
36739 index b9040be..e3f5aab 100644
36740 --- a/drivers/tty/hvc/hvcs.c
36741 +++ b/drivers/tty/hvc/hvcs.c
36742 @@ -83,6 +83,7 @@
36743 #include <asm/hvcserver.h>
36744 #include <asm/uaccess.h>
36745 #include <asm/vio.h>
36746 +#include <asm/local.h>
36747
36748 /*
36749 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
36750 @@ -270,7 +271,7 @@ struct hvcs_struct {
36751 unsigned int index;
36752
36753 struct tty_struct *tty;
36754 - int open_count;
36755 + local_t open_count;
36756
36757 /*
36758 * Used to tell the driver kernel_thread what operations need to take
36759 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
36760
36761 spin_lock_irqsave(&hvcsd->lock, flags);
36762
36763 - if (hvcsd->open_count > 0) {
36764 + if (local_read(&hvcsd->open_count) > 0) {
36765 spin_unlock_irqrestore(&hvcsd->lock, flags);
36766 printk(KERN_INFO "HVCS: vterm state unchanged. "
36767 "The hvcs device node is still in use.\n");
36768 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
36769 if ((retval = hvcs_partner_connect(hvcsd)))
36770 goto error_release;
36771
36772 - hvcsd->open_count = 1;
36773 + local_set(&hvcsd->open_count, 1);
36774 hvcsd->tty = tty;
36775 tty->driver_data = hvcsd;
36776
36777 @@ -1179,7 +1180,7 @@ fast_open:
36778
36779 spin_lock_irqsave(&hvcsd->lock, flags);
36780 kref_get(&hvcsd->kref);
36781 - hvcsd->open_count++;
36782 + local_inc(&hvcsd->open_count);
36783 hvcsd->todo_mask |= HVCS_SCHED_READ;
36784 spin_unlock_irqrestore(&hvcsd->lock, flags);
36785
36786 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
36787 hvcsd = tty->driver_data;
36788
36789 spin_lock_irqsave(&hvcsd->lock, flags);
36790 - if (--hvcsd->open_count == 0) {
36791 + if (local_dec_and_test(&hvcsd->open_count)) {
36792
36793 vio_disable_interrupts(hvcsd->vdev);
36794
36795 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
36796 free_irq(irq, hvcsd);
36797 kref_put(&hvcsd->kref, destroy_hvcs_struct);
36798 return;
36799 - } else if (hvcsd->open_count < 0) {
36800 + } else if (local_read(&hvcsd->open_count) < 0) {
36801 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
36802 " is missmanaged.\n",
36803 - hvcsd->vdev->unit_address, hvcsd->open_count);
36804 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
36805 }
36806
36807 spin_unlock_irqrestore(&hvcsd->lock, flags);
36808 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
36809
36810 spin_lock_irqsave(&hvcsd->lock, flags);
36811 /* Preserve this so that we know how many kref refs to put */
36812 - temp_open_count = hvcsd->open_count;
36813 + temp_open_count = local_read(&hvcsd->open_count);
36814
36815 /*
36816 * Don't kref put inside the spinlock because the destruction
36817 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
36818 hvcsd->tty->driver_data = NULL;
36819 hvcsd->tty = NULL;
36820
36821 - hvcsd->open_count = 0;
36822 + local_set(&hvcsd->open_count, 0);
36823
36824 /* This will drop any buffered data on the floor which is OK in a hangup
36825 * scenario. */
36826 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
36827 * the middle of a write operation? This is a crummy place to do this
36828 * but we want to keep it all in the spinlock.
36829 */
36830 - if (hvcsd->open_count <= 0) {
36831 + if (local_read(&hvcsd->open_count) <= 0) {
36832 spin_unlock_irqrestore(&hvcsd->lock, flags);
36833 return -ENODEV;
36834 }
36835 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
36836 {
36837 struct hvcs_struct *hvcsd = tty->driver_data;
36838
36839 - if (!hvcsd || hvcsd->open_count <= 0)
36840 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
36841 return 0;
36842
36843 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
36844 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
36845 index ef92869..f4ebd88 100644
36846 --- a/drivers/tty/ipwireless/tty.c
36847 +++ b/drivers/tty/ipwireless/tty.c
36848 @@ -29,6 +29,7 @@
36849 #include <linux/tty_driver.h>
36850 #include <linux/tty_flip.h>
36851 #include <linux/uaccess.h>
36852 +#include <asm/local.h>
36853
36854 #include "tty.h"
36855 #include "network.h"
36856 @@ -51,7 +52,7 @@ struct ipw_tty {
36857 int tty_type;
36858 struct ipw_network *network;
36859 struct tty_struct *linux_tty;
36860 - int open_count;
36861 + local_t open_count;
36862 unsigned int control_lines;
36863 struct mutex ipw_tty_mutex;
36864 int tx_bytes_queued;
36865 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
36866 mutex_unlock(&tty->ipw_tty_mutex);
36867 return -ENODEV;
36868 }
36869 - if (tty->open_count == 0)
36870 + if (local_read(&tty->open_count) == 0)
36871 tty->tx_bytes_queued = 0;
36872
36873 - tty->open_count++;
36874 + local_inc(&tty->open_count);
36875
36876 tty->linux_tty = linux_tty;
36877 linux_tty->driver_data = tty;
36878 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
36879
36880 static void do_ipw_close(struct ipw_tty *tty)
36881 {
36882 - tty->open_count--;
36883 -
36884 - if (tty->open_count == 0) {
36885 + if (local_dec_return(&tty->open_count) == 0) {
36886 struct tty_struct *linux_tty = tty->linux_tty;
36887
36888 if (linux_tty != NULL) {
36889 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
36890 return;
36891
36892 mutex_lock(&tty->ipw_tty_mutex);
36893 - if (tty->open_count == 0) {
36894 + if (local_read(&tty->open_count) == 0) {
36895 mutex_unlock(&tty->ipw_tty_mutex);
36896 return;
36897 }
36898 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
36899 return;
36900 }
36901
36902 - if (!tty->open_count) {
36903 + if (!local_read(&tty->open_count)) {
36904 mutex_unlock(&tty->ipw_tty_mutex);
36905 return;
36906 }
36907 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
36908 return -ENODEV;
36909
36910 mutex_lock(&tty->ipw_tty_mutex);
36911 - if (!tty->open_count) {
36912 + if (!local_read(&tty->open_count)) {
36913 mutex_unlock(&tty->ipw_tty_mutex);
36914 return -EINVAL;
36915 }
36916 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
36917 if (!tty)
36918 return -ENODEV;
36919
36920 - if (!tty->open_count)
36921 + if (!local_read(&tty->open_count))
36922 return -EINVAL;
36923
36924 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
36925 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
36926 if (!tty)
36927 return 0;
36928
36929 - if (!tty->open_count)
36930 + if (!local_read(&tty->open_count))
36931 return 0;
36932
36933 return tty->tx_bytes_queued;
36934 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
36935 if (!tty)
36936 return -ENODEV;
36937
36938 - if (!tty->open_count)
36939 + if (!local_read(&tty->open_count))
36940 return -EINVAL;
36941
36942 return get_control_lines(tty);
36943 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
36944 if (!tty)
36945 return -ENODEV;
36946
36947 - if (!tty->open_count)
36948 + if (!local_read(&tty->open_count))
36949 return -EINVAL;
36950
36951 return set_control_lines(tty, set, clear);
36952 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
36953 if (!tty)
36954 return -ENODEV;
36955
36956 - if (!tty->open_count)
36957 + if (!local_read(&tty->open_count))
36958 return -EINVAL;
36959
36960 /* FIXME: Exactly how is the tty object locked here .. */
36961 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
36962 against a parallel ioctl etc */
36963 mutex_lock(&ttyj->ipw_tty_mutex);
36964 }
36965 - while (ttyj->open_count)
36966 + while (local_read(&ttyj->open_count))
36967 do_ipw_close(ttyj);
36968 ipwireless_disassociate_network_ttys(network,
36969 ttyj->channel_idx);
36970 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
36971 index fc7bbba..9527e93 100644
36972 --- a/drivers/tty/n_gsm.c
36973 +++ b/drivers/tty/n_gsm.c
36974 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
36975 kref_init(&dlci->ref);
36976 mutex_init(&dlci->mutex);
36977 dlci->fifo = &dlci->_fifo;
36978 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
36979 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
36980 kfree(dlci);
36981 return NULL;
36982 }
36983 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
36984 index 39d6ab6..eb97f41 100644
36985 --- a/drivers/tty/n_tty.c
36986 +++ b/drivers/tty/n_tty.c
36987 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
36988 {
36989 *ops = tty_ldisc_N_TTY;
36990 ops->owner = NULL;
36991 - ops->refcount = ops->flags = 0;
36992 + atomic_set(&ops->refcount, 0);
36993 + ops->flags = 0;
36994 }
36995 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
36996 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
36997 index e18604b..a7d5a11 100644
36998 --- a/drivers/tty/pty.c
36999 +++ b/drivers/tty/pty.c
37000 @@ -773,8 +773,10 @@ static void __init unix98_pty_init(void)
37001 register_sysctl_table(pty_root_table);
37002
37003 /* Now create the /dev/ptmx special device */
37004 + pax_open_kernel();
37005 tty_default_fops(&ptmx_fops);
37006 - ptmx_fops.open = ptmx_open;
37007 + *(void **)&ptmx_fops.open = ptmx_open;
37008 + pax_close_kernel();
37009
37010 cdev_init(&ptmx_cdev, &ptmx_fops);
37011 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37012 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37013 index 2b42a01..32a2ed3 100644
37014 --- a/drivers/tty/serial/kgdboc.c
37015 +++ b/drivers/tty/serial/kgdboc.c
37016 @@ -24,8 +24,9 @@
37017 #define MAX_CONFIG_LEN 40
37018
37019 static struct kgdb_io kgdboc_io_ops;
37020 +static struct kgdb_io kgdboc_io_ops_console;
37021
37022 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37023 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37024 static int configured = -1;
37025
37026 static char config[MAX_CONFIG_LEN];
37027 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37028 kgdboc_unregister_kbd();
37029 if (configured == 1)
37030 kgdb_unregister_io_module(&kgdboc_io_ops);
37031 + else if (configured == 2)
37032 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
37033 }
37034
37035 static int configure_kgdboc(void)
37036 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37037 int err;
37038 char *cptr = config;
37039 struct console *cons;
37040 + int is_console = 0;
37041
37042 err = kgdboc_option_setup(config);
37043 if (err || !strlen(config) || isspace(config[0]))
37044 goto noconfig;
37045
37046 err = -ENODEV;
37047 - kgdboc_io_ops.is_console = 0;
37048 kgdb_tty_driver = NULL;
37049
37050 kgdboc_use_kms = 0;
37051 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37052 int idx;
37053 if (cons->device && cons->device(cons, &idx) == p &&
37054 idx == tty_line) {
37055 - kgdboc_io_ops.is_console = 1;
37056 + is_console = 1;
37057 break;
37058 }
37059 cons = cons->next;
37060 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37061 kgdb_tty_line = tty_line;
37062
37063 do_register:
37064 - err = kgdb_register_io_module(&kgdboc_io_ops);
37065 + if (is_console) {
37066 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
37067 + configured = 2;
37068 + } else {
37069 + err = kgdb_register_io_module(&kgdboc_io_ops);
37070 + configured = 1;
37071 + }
37072 if (err)
37073 goto noconfig;
37074
37075 - configured = 1;
37076 -
37077 return 0;
37078
37079 noconfig:
37080 @@ -213,7 +220,7 @@ noconfig:
37081 static int __init init_kgdboc(void)
37082 {
37083 /* Already configured? */
37084 - if (configured == 1)
37085 + if (configured >= 1)
37086 return 0;
37087
37088 return configure_kgdboc();
37089 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37090 if (config[len - 1] == '\n')
37091 config[len - 1] = '\0';
37092
37093 - if (configured == 1)
37094 + if (configured >= 1)
37095 cleanup_kgdboc();
37096
37097 /* Go and configure with the new params. */
37098 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37099 .post_exception = kgdboc_post_exp_handler,
37100 };
37101
37102 +static struct kgdb_io kgdboc_io_ops_console = {
37103 + .name = "kgdboc",
37104 + .read_char = kgdboc_get_char,
37105 + .write_char = kgdboc_put_char,
37106 + .pre_exception = kgdboc_pre_exp_handler,
37107 + .post_exception = kgdboc_post_exp_handler,
37108 + .is_console = 1
37109 +};
37110 +
37111 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
37112 /* This is only available if kgdboc is a built in for early debugging */
37113 static int __init kgdboc_early_init(char *opt)
37114 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
37115 index 05085be..67eadb0 100644
37116 --- a/drivers/tty/tty_io.c
37117 +++ b/drivers/tty/tty_io.c
37118 @@ -3240,7 +3240,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
37119
37120 void tty_default_fops(struct file_operations *fops)
37121 {
37122 - *fops = tty_fops;
37123 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
37124 }
37125
37126 /*
37127 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
37128 index 8e0924f..4204eb4 100644
37129 --- a/drivers/tty/tty_ldisc.c
37130 +++ b/drivers/tty/tty_ldisc.c
37131 @@ -75,7 +75,7 @@ static void put_ldisc(struct tty_ldisc *ld)
37132 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
37133 struct tty_ldisc_ops *ldo = ld->ops;
37134
37135 - ldo->refcount--;
37136 + atomic_dec(&ldo->refcount);
37137 module_put(ldo->owner);
37138 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37139
37140 @@ -110,7 +110,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
37141 spin_lock_irqsave(&tty_ldisc_lock, flags);
37142 tty_ldiscs[disc] = new_ldisc;
37143 new_ldisc->num = disc;
37144 - new_ldisc->refcount = 0;
37145 + atomic_set(&new_ldisc->refcount, 0);
37146 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37147
37148 return ret;
37149 @@ -138,7 +138,7 @@ int tty_unregister_ldisc(int disc)
37150 return -EINVAL;
37151
37152 spin_lock_irqsave(&tty_ldisc_lock, flags);
37153 - if (tty_ldiscs[disc]->refcount)
37154 + if (atomic_read(&tty_ldiscs[disc]->refcount))
37155 ret = -EBUSY;
37156 else
37157 tty_ldiscs[disc] = NULL;
37158 @@ -159,7 +159,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
37159 if (ldops) {
37160 ret = ERR_PTR(-EAGAIN);
37161 if (try_module_get(ldops->owner)) {
37162 - ldops->refcount++;
37163 + atomic_inc(&ldops->refcount);
37164 ret = ldops;
37165 }
37166 }
37167 @@ -172,7 +172,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
37168 unsigned long flags;
37169
37170 spin_lock_irqsave(&tty_ldisc_lock, flags);
37171 - ldops->refcount--;
37172 + atomic_dec(&ldops->refcount);
37173 module_put(ldops->owner);
37174 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37175 }
37176 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
37177 index a605549..6bd3c96 100644
37178 --- a/drivers/tty/vt/keyboard.c
37179 +++ b/drivers/tty/vt/keyboard.c
37180 @@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
37181 kbd->kbdmode == VC_OFF) &&
37182 value != KVAL(K_SAK))
37183 return; /* SAK is allowed even in raw mode */
37184 +
37185 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
37186 + {
37187 + void *func = fn_handler[value];
37188 + if (func == fn_show_state || func == fn_show_ptregs ||
37189 + func == fn_show_mem)
37190 + return;
37191 + }
37192 +#endif
37193 +
37194 fn_handler[value](vc);
37195 }
37196
37197 diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
37198 index 65447c5..0526f0a 100644
37199 --- a/drivers/tty/vt/vt_ioctl.c
37200 +++ b/drivers/tty/vt/vt_ioctl.c
37201 @@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
37202 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
37203 return -EFAULT;
37204
37205 - if (!capable(CAP_SYS_TTY_CONFIG))
37206 - perm = 0;
37207 -
37208 switch (cmd) {
37209 case KDGKBENT:
37210 key_map = key_maps[s];
37211 @@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
37212 val = (i ? K_HOLE : K_NOSUCHMAP);
37213 return put_user(val, &user_kbe->kb_value);
37214 case KDSKBENT:
37215 + if (!capable(CAP_SYS_TTY_CONFIG))
37216 + perm = 0;
37217 +
37218 if (!perm)
37219 return -EPERM;
37220 if (!i && v == K_NOSUCHMAP) {
37221 @@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
37222 int i, j, k;
37223 int ret;
37224
37225 - if (!capable(CAP_SYS_TTY_CONFIG))
37226 - perm = 0;
37227 -
37228 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
37229 if (!kbs) {
37230 ret = -ENOMEM;
37231 @@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
37232 kfree(kbs);
37233 return ((p && *p) ? -EOVERFLOW : 0);
37234 case KDSKBSENT:
37235 + if (!capable(CAP_SYS_TTY_CONFIG))
37236 + perm = 0;
37237 +
37238 if (!perm) {
37239 ret = -EPERM;
37240 goto reterr;
37241 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
37242 index a783d53..cb30d94 100644
37243 --- a/drivers/uio/uio.c
37244 +++ b/drivers/uio/uio.c
37245 @@ -25,6 +25,7 @@
37246 #include <linux/kobject.h>
37247 #include <linux/cdev.h>
37248 #include <linux/uio_driver.h>
37249 +#include <asm/local.h>
37250
37251 #define UIO_MAX_DEVICES (1U << MINORBITS)
37252
37253 @@ -32,10 +33,10 @@ struct uio_device {
37254 struct module *owner;
37255 struct device *dev;
37256 int minor;
37257 - atomic_t event;
37258 + atomic_unchecked_t event;
37259 struct fasync_struct *async_queue;
37260 wait_queue_head_t wait;
37261 - int vma_count;
37262 + local_t vma_count;
37263 struct uio_info *info;
37264 struct kobject *map_dir;
37265 struct kobject *portio_dir;
37266 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
37267 struct device_attribute *attr, char *buf)
37268 {
37269 struct uio_device *idev = dev_get_drvdata(dev);
37270 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
37271 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
37272 }
37273
37274 static struct device_attribute uio_class_attributes[] = {
37275 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
37276 {
37277 struct uio_device *idev = info->uio_dev;
37278
37279 - atomic_inc(&idev->event);
37280 + atomic_inc_unchecked(&idev->event);
37281 wake_up_interruptible(&idev->wait);
37282 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
37283 }
37284 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
37285 }
37286
37287 listener->dev = idev;
37288 - listener->event_count = atomic_read(&idev->event);
37289 + listener->event_count = atomic_read_unchecked(&idev->event);
37290 filep->private_data = listener;
37291
37292 if (idev->info->open) {
37293 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
37294 return -EIO;
37295
37296 poll_wait(filep, &idev->wait, wait);
37297 - if (listener->event_count != atomic_read(&idev->event))
37298 + if (listener->event_count != atomic_read_unchecked(&idev->event))
37299 return POLLIN | POLLRDNORM;
37300 return 0;
37301 }
37302 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
37303 do {
37304 set_current_state(TASK_INTERRUPTIBLE);
37305
37306 - event_count = atomic_read(&idev->event);
37307 + event_count = atomic_read_unchecked(&idev->event);
37308 if (event_count != listener->event_count) {
37309 if (copy_to_user(buf, &event_count, count))
37310 retval = -EFAULT;
37311 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
37312 static void uio_vma_open(struct vm_area_struct *vma)
37313 {
37314 struct uio_device *idev = vma->vm_private_data;
37315 - idev->vma_count++;
37316 + local_inc(&idev->vma_count);
37317 }
37318
37319 static void uio_vma_close(struct vm_area_struct *vma)
37320 {
37321 struct uio_device *idev = vma->vm_private_data;
37322 - idev->vma_count--;
37323 + local_dec(&idev->vma_count);
37324 }
37325
37326 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
37327 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
37328 idev->owner = owner;
37329 idev->info = info;
37330 init_waitqueue_head(&idev->wait);
37331 - atomic_set(&idev->event, 0);
37332 + atomic_set_unchecked(&idev->event, 0);
37333
37334 ret = uio_get_minor(idev);
37335 if (ret)
37336 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
37337 index a845f8b..4f54072 100644
37338 --- a/drivers/usb/atm/cxacru.c
37339 +++ b/drivers/usb/atm/cxacru.c
37340 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
37341 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
37342 if (ret < 2)
37343 return -EINVAL;
37344 - if (index < 0 || index > 0x7f)
37345 + if (index > 0x7f)
37346 return -EINVAL;
37347 pos += tmp;
37348
37349 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
37350 index d3448ca..d2864ca 100644
37351 --- a/drivers/usb/atm/usbatm.c
37352 +++ b/drivers/usb/atm/usbatm.c
37353 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37354 if (printk_ratelimit())
37355 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
37356 __func__, vpi, vci);
37357 - atomic_inc(&vcc->stats->rx_err);
37358 + atomic_inc_unchecked(&vcc->stats->rx_err);
37359 return;
37360 }
37361
37362 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37363 if (length > ATM_MAX_AAL5_PDU) {
37364 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
37365 __func__, length, vcc);
37366 - atomic_inc(&vcc->stats->rx_err);
37367 + atomic_inc_unchecked(&vcc->stats->rx_err);
37368 goto out;
37369 }
37370
37371 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37372 if (sarb->len < pdu_length) {
37373 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
37374 __func__, pdu_length, sarb->len, vcc);
37375 - atomic_inc(&vcc->stats->rx_err);
37376 + atomic_inc_unchecked(&vcc->stats->rx_err);
37377 goto out;
37378 }
37379
37380 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
37381 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
37382 __func__, vcc);
37383 - atomic_inc(&vcc->stats->rx_err);
37384 + atomic_inc_unchecked(&vcc->stats->rx_err);
37385 goto out;
37386 }
37387
37388 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37389 if (printk_ratelimit())
37390 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
37391 __func__, length);
37392 - atomic_inc(&vcc->stats->rx_drop);
37393 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37394 goto out;
37395 }
37396
37397 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37398
37399 vcc->push(vcc, skb);
37400
37401 - atomic_inc(&vcc->stats->rx);
37402 + atomic_inc_unchecked(&vcc->stats->rx);
37403 out:
37404 skb_trim(sarb, 0);
37405 }
37406 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
37407 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
37408
37409 usbatm_pop(vcc, skb);
37410 - atomic_inc(&vcc->stats->tx);
37411 + atomic_inc_unchecked(&vcc->stats->tx);
37412
37413 skb = skb_dequeue(&instance->sndqueue);
37414 }
37415 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
37416 if (!left--)
37417 return sprintf(page,
37418 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
37419 - atomic_read(&atm_dev->stats.aal5.tx),
37420 - atomic_read(&atm_dev->stats.aal5.tx_err),
37421 - atomic_read(&atm_dev->stats.aal5.rx),
37422 - atomic_read(&atm_dev->stats.aal5.rx_err),
37423 - atomic_read(&atm_dev->stats.aal5.rx_drop));
37424 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
37425 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
37426 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
37427 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
37428 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
37429
37430 if (!left--) {
37431 if (instance->disconnected)
37432 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
37433 index d956965..4179a77 100644
37434 --- a/drivers/usb/core/devices.c
37435 +++ b/drivers/usb/core/devices.c
37436 @@ -126,7 +126,7 @@ static const char format_endpt[] =
37437 * time it gets called.
37438 */
37439 static struct device_connect_event {
37440 - atomic_t count;
37441 + atomic_unchecked_t count;
37442 wait_queue_head_t wait;
37443 } device_event = {
37444 .count = ATOMIC_INIT(1),
37445 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
37446
37447 void usbfs_conn_disc_event(void)
37448 {
37449 - atomic_add(2, &device_event.count);
37450 + atomic_add_unchecked(2, &device_event.count);
37451 wake_up(&device_event.wait);
37452 }
37453
37454 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
37455
37456 poll_wait(file, &device_event.wait, wait);
37457
37458 - event_count = atomic_read(&device_event.count);
37459 + event_count = atomic_read_unchecked(&device_event.count);
37460 if (file->f_version != event_count) {
37461 file->f_version = event_count;
37462 return POLLIN | POLLRDNORM;
37463 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
37464 index b3bdfed..a9460e0 100644
37465 --- a/drivers/usb/core/message.c
37466 +++ b/drivers/usb/core/message.c
37467 @@ -869,8 +869,8 @@ char *usb_cache_string(struct usb_device *udev, int index)
37468 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
37469 if (buf) {
37470 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
37471 - if (len > 0) {
37472 - smallbuf = kmalloc(++len, GFP_NOIO);
37473 + if (len++ > 0) {
37474 + smallbuf = kmalloc(len, GFP_NOIO);
37475 if (!smallbuf)
37476 return buf;
37477 memcpy(smallbuf, buf, len);
37478 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
37479 index 1fc8f12..20647c1 100644
37480 --- a/drivers/usb/early/ehci-dbgp.c
37481 +++ b/drivers/usb/early/ehci-dbgp.c
37482 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
37483
37484 #ifdef CONFIG_KGDB
37485 static struct kgdb_io kgdbdbgp_io_ops;
37486 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
37487 +static struct kgdb_io kgdbdbgp_io_ops_console;
37488 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
37489 #else
37490 #define dbgp_kgdb_mode (0)
37491 #endif
37492 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
37493 .write_char = kgdbdbgp_write_char,
37494 };
37495
37496 +static struct kgdb_io kgdbdbgp_io_ops_console = {
37497 + .name = "kgdbdbgp",
37498 + .read_char = kgdbdbgp_read_char,
37499 + .write_char = kgdbdbgp_write_char,
37500 + .is_console = 1
37501 +};
37502 +
37503 static int kgdbdbgp_wait_time;
37504
37505 static int __init kgdbdbgp_parse_config(char *str)
37506 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
37507 ptr++;
37508 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
37509 }
37510 - kgdb_register_io_module(&kgdbdbgp_io_ops);
37511 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
37512 + if (early_dbgp_console.index != -1)
37513 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
37514 + else
37515 + kgdb_register_io_module(&kgdbdbgp_io_ops);
37516
37517 return 0;
37518 }
37519 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
37520 index d6bea3e..60b250e 100644
37521 --- a/drivers/usb/wusbcore/wa-hc.h
37522 +++ b/drivers/usb/wusbcore/wa-hc.h
37523 @@ -192,7 +192,7 @@ struct wahc {
37524 struct list_head xfer_delayed_list;
37525 spinlock_t xfer_list_lock;
37526 struct work_struct xfer_work;
37527 - atomic_t xfer_id_count;
37528 + atomic_unchecked_t xfer_id_count;
37529 };
37530
37531
37532 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
37533 INIT_LIST_HEAD(&wa->xfer_delayed_list);
37534 spin_lock_init(&wa->xfer_list_lock);
37535 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
37536 - atomic_set(&wa->xfer_id_count, 1);
37537 + atomic_set_unchecked(&wa->xfer_id_count, 1);
37538 }
37539
37540 /**
37541 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
37542 index 57c01ab..8a05959 100644
37543 --- a/drivers/usb/wusbcore/wa-xfer.c
37544 +++ b/drivers/usb/wusbcore/wa-xfer.c
37545 @@ -296,7 +296,7 @@ out:
37546 */
37547 static void wa_xfer_id_init(struct wa_xfer *xfer)
37548 {
37549 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
37550 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
37551 }
37552
37553 /*
37554 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
37555 index c14c42b..f955cc2 100644
37556 --- a/drivers/vhost/vhost.c
37557 +++ b/drivers/vhost/vhost.c
37558 @@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
37559 return 0;
37560 }
37561
37562 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
37563 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
37564 {
37565 struct file *eventfp, *filep = NULL,
37566 *pollstart = NULL, *pollstop = NULL;
37567 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
37568 index b0b2ac3..89a4399 100644
37569 --- a/drivers/video/aty/aty128fb.c
37570 +++ b/drivers/video/aty/aty128fb.c
37571 @@ -148,7 +148,7 @@ enum {
37572 };
37573
37574 /* Must match above enum */
37575 -static const char *r128_family[] __devinitdata = {
37576 +static const char *r128_family[] __devinitconst = {
37577 "AGP",
37578 "PCI",
37579 "PRO AGP",
37580 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
37581 index 5c3960d..15cf8fc 100644
37582 --- a/drivers/video/fbcmap.c
37583 +++ b/drivers/video/fbcmap.c
37584 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
37585 rc = -ENODEV;
37586 goto out;
37587 }
37588 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
37589 - !info->fbops->fb_setcmap)) {
37590 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
37591 rc = -EINVAL;
37592 goto out1;
37593 }
37594 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
37595 index ad93629..e020fc3 100644
37596 --- a/drivers/video/fbmem.c
37597 +++ b/drivers/video/fbmem.c
37598 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
37599 image->dx += image->width + 8;
37600 }
37601 } else if (rotate == FB_ROTATE_UD) {
37602 - for (x = 0; x < num && image->dx >= 0; x++) {
37603 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
37604 info->fbops->fb_imageblit(info, image);
37605 image->dx -= image->width + 8;
37606 }
37607 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
37608 image->dy += image->height + 8;
37609 }
37610 } else if (rotate == FB_ROTATE_CCW) {
37611 - for (x = 0; x < num && image->dy >= 0; x++) {
37612 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
37613 info->fbops->fb_imageblit(info, image);
37614 image->dy -= image->height + 8;
37615 }
37616 @@ -1143,7 +1143,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
37617 return -EFAULT;
37618 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
37619 return -EINVAL;
37620 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
37621 + if (con2fb.framebuffer >= FB_MAX)
37622 return -EINVAL;
37623 if (!registered_fb[con2fb.framebuffer])
37624 request_module("fb%d", con2fb.framebuffer);
37625 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
37626 index 5a5d092..265c5ed 100644
37627 --- a/drivers/video/geode/gx1fb_core.c
37628 +++ b/drivers/video/geode/gx1fb_core.c
37629 @@ -29,7 +29,7 @@ static int crt_option = 1;
37630 static char panel_option[32] = "";
37631
37632 /* Modes relevant to the GX1 (taken from modedb.c) */
37633 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
37634 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
37635 /* 640x480-60 VESA */
37636 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
37637 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
37638 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
37639 index 0fad23f..0e9afa4 100644
37640 --- a/drivers/video/gxt4500.c
37641 +++ b/drivers/video/gxt4500.c
37642 @@ -156,7 +156,7 @@ struct gxt4500_par {
37643 static char *mode_option;
37644
37645 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
37646 -static const struct fb_videomode defaultmode __devinitdata = {
37647 +static const struct fb_videomode defaultmode __devinitconst = {
37648 .refresh = 60,
37649 .xres = 1280,
37650 .yres = 1024,
37651 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
37652 return 0;
37653 }
37654
37655 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
37656 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
37657 .id = "IBM GXT4500P",
37658 .type = FB_TYPE_PACKED_PIXELS,
37659 .visual = FB_VISUAL_PSEUDOCOLOR,
37660 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
37661 index 7672d2e..b56437f 100644
37662 --- a/drivers/video/i810/i810_accel.c
37663 +++ b/drivers/video/i810/i810_accel.c
37664 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
37665 }
37666 }
37667 printk("ringbuffer lockup!!!\n");
37668 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
37669 i810_report_error(mmio);
37670 par->dev_flags |= LOCKUP;
37671 info->pixmap.scan_align = 1;
37672 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
37673 index 318f6fb..9a389c1 100644
37674 --- a/drivers/video/i810/i810_main.c
37675 +++ b/drivers/video/i810/i810_main.c
37676 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
37677 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
37678
37679 /* PCI */
37680 -static const char *i810_pci_list[] __devinitdata = {
37681 +static const char *i810_pci_list[] __devinitconst = {
37682 "Intel(R) 810 Framebuffer Device" ,
37683 "Intel(R) 810-DC100 Framebuffer Device" ,
37684 "Intel(R) 810E Framebuffer Device" ,
37685 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
37686 index de36693..3c63fc2 100644
37687 --- a/drivers/video/jz4740_fb.c
37688 +++ b/drivers/video/jz4740_fb.c
37689 @@ -136,7 +136,7 @@ struct jzfb {
37690 uint32_t pseudo_palette[16];
37691 };
37692
37693 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
37694 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
37695 .id = "JZ4740 FB",
37696 .type = FB_TYPE_PACKED_PIXELS,
37697 .visual = FB_VISUAL_TRUECOLOR,
37698 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
37699 index 3c14e43..eafa544 100644
37700 --- a/drivers/video/logo/logo_linux_clut224.ppm
37701 +++ b/drivers/video/logo/logo_linux_clut224.ppm
37702 @@ -1,1604 +1,1123 @@
37703 P3
37704 -# Standard 224-color Linux logo
37705 80 80
37706 255
37707 - 0 0 0 0 0 0 0 0 0 0 0 0
37708 - 0 0 0 0 0 0 0 0 0 0 0 0
37709 - 0 0 0 0 0 0 0 0 0 0 0 0
37710 - 0 0 0 0 0 0 0 0 0 0 0 0
37711 - 0 0 0 0 0 0 0 0 0 0 0 0
37712 - 0 0 0 0 0 0 0 0 0 0 0 0
37713 - 0 0 0 0 0 0 0 0 0 0 0 0
37714 - 0 0 0 0 0 0 0 0 0 0 0 0
37715 - 0 0 0 0 0 0 0 0 0 0 0 0
37716 - 6 6 6 6 6 6 10 10 10 10 10 10
37717 - 10 10 10 6 6 6 6 6 6 6 6 6
37718 - 0 0 0 0 0 0 0 0 0 0 0 0
37719 - 0 0 0 0 0 0 0 0 0 0 0 0
37720 - 0 0 0 0 0 0 0 0 0 0 0 0
37721 - 0 0 0 0 0 0 0 0 0 0 0 0
37722 - 0 0 0 0 0 0 0 0 0 0 0 0
37723 - 0 0 0 0 0 0 0 0 0 0 0 0
37724 - 0 0 0 0 0 0 0 0 0 0 0 0
37725 - 0 0 0 0 0 0 0 0 0 0 0 0
37726 - 0 0 0 0 0 0 0 0 0 0 0 0
37727 - 0 0 0 0 0 0 0 0 0 0 0 0
37728 - 0 0 0 0 0 0 0 0 0 0 0 0
37729 - 0 0 0 0 0 0 0 0 0 0 0 0
37730 - 0 0 0 0 0 0 0 0 0 0 0 0
37731 - 0 0 0 0 0 0 0 0 0 0 0 0
37732 - 0 0 0 0 0 0 0 0 0 0 0 0
37733 - 0 0 0 0 0 0 0 0 0 0 0 0
37734 - 0 0 0 0 0 0 0 0 0 0 0 0
37735 - 0 0 0 6 6 6 10 10 10 14 14 14
37736 - 22 22 22 26 26 26 30 30 30 34 34 34
37737 - 30 30 30 30 30 30 26 26 26 18 18 18
37738 - 14 14 14 10 10 10 6 6 6 0 0 0
37739 - 0 0 0 0 0 0 0 0 0 0 0 0
37740 - 0 0 0 0 0 0 0 0 0 0 0 0
37741 - 0 0 0 0 0 0 0 0 0 0 0 0
37742 - 0 0 0 0 0 0 0 0 0 0 0 0
37743 - 0 0 0 0 0 0 0 0 0 0 0 0
37744 - 0 0 0 0 0 0 0 0 0 0 0 0
37745 - 0 0 0 0 0 0 0 0 0 0 0 0
37746 - 0 0 0 0 0 0 0 0 0 0 0 0
37747 - 0 0 0 0 0 0 0 0 0 0 0 0
37748 - 0 0 0 0 0 1 0 0 1 0 0 0
37749 - 0 0 0 0 0 0 0 0 0 0 0 0
37750 - 0 0 0 0 0 0 0 0 0 0 0 0
37751 - 0 0 0 0 0 0 0 0 0 0 0 0
37752 - 0 0 0 0 0 0 0 0 0 0 0 0
37753 - 0 0 0 0 0 0 0 0 0 0 0 0
37754 - 0 0 0 0 0 0 0 0 0 0 0 0
37755 - 6 6 6 14 14 14 26 26 26 42 42 42
37756 - 54 54 54 66 66 66 78 78 78 78 78 78
37757 - 78 78 78 74 74 74 66 66 66 54 54 54
37758 - 42 42 42 26 26 26 18 18 18 10 10 10
37759 - 6 6 6 0 0 0 0 0 0 0 0 0
37760 - 0 0 0 0 0 0 0 0 0 0 0 0
37761 - 0 0 0 0 0 0 0 0 0 0 0 0
37762 - 0 0 0 0 0 0 0 0 0 0 0 0
37763 - 0 0 0 0 0 0 0 0 0 0 0 0
37764 - 0 0 0 0 0 0 0 0 0 0 0 0
37765 - 0 0 0 0 0 0 0 0 0 0 0 0
37766 - 0 0 0 0 0 0 0 0 0 0 0 0
37767 - 0 0 0 0 0 0 0 0 0 0 0 0
37768 - 0 0 1 0 0 0 0 0 0 0 0 0
37769 - 0 0 0 0 0 0 0 0 0 0 0 0
37770 - 0 0 0 0 0 0 0 0 0 0 0 0
37771 - 0 0 0 0 0 0 0 0 0 0 0 0
37772 - 0 0 0 0 0 0 0 0 0 0 0 0
37773 - 0 0 0 0 0 0 0 0 0 0 0 0
37774 - 0 0 0 0 0 0 0 0 0 10 10 10
37775 - 22 22 22 42 42 42 66 66 66 86 86 86
37776 - 66 66 66 38 38 38 38 38 38 22 22 22
37777 - 26 26 26 34 34 34 54 54 54 66 66 66
37778 - 86 86 86 70 70 70 46 46 46 26 26 26
37779 - 14 14 14 6 6 6 0 0 0 0 0 0
37780 - 0 0 0 0 0 0 0 0 0 0 0 0
37781 - 0 0 0 0 0 0 0 0 0 0 0 0
37782 - 0 0 0 0 0 0 0 0 0 0 0 0
37783 - 0 0 0 0 0 0 0 0 0 0 0 0
37784 - 0 0 0 0 0 0 0 0 0 0 0 0
37785 - 0 0 0 0 0 0 0 0 0 0 0 0
37786 - 0 0 0 0 0 0 0 0 0 0 0 0
37787 - 0 0 0 0 0 0 0 0 0 0 0 0
37788 - 0 0 1 0 0 1 0 0 1 0 0 0
37789 - 0 0 0 0 0 0 0 0 0 0 0 0
37790 - 0 0 0 0 0 0 0 0 0 0 0 0
37791 - 0 0 0 0 0 0 0 0 0 0 0 0
37792 - 0 0 0 0 0 0 0 0 0 0 0 0
37793 - 0 0 0 0 0 0 0 0 0 0 0 0
37794 - 0 0 0 0 0 0 10 10 10 26 26 26
37795 - 50 50 50 82 82 82 58 58 58 6 6 6
37796 - 2 2 6 2 2 6 2 2 6 2 2 6
37797 - 2 2 6 2 2 6 2 2 6 2 2 6
37798 - 6 6 6 54 54 54 86 86 86 66 66 66
37799 - 38 38 38 18 18 18 6 6 6 0 0 0
37800 - 0 0 0 0 0 0 0 0 0 0 0 0
37801 - 0 0 0 0 0 0 0 0 0 0 0 0
37802 - 0 0 0 0 0 0 0 0 0 0 0 0
37803 - 0 0 0 0 0 0 0 0 0 0 0 0
37804 - 0 0 0 0 0 0 0 0 0 0 0 0
37805 - 0 0 0 0 0 0 0 0 0 0 0 0
37806 - 0 0 0 0 0 0 0 0 0 0 0 0
37807 - 0 0 0 0 0 0 0 0 0 0 0 0
37808 - 0 0 0 0 0 0 0 0 0 0 0 0
37809 - 0 0 0 0 0 0 0 0 0 0 0 0
37810 - 0 0 0 0 0 0 0 0 0 0 0 0
37811 - 0 0 0 0 0 0 0 0 0 0 0 0
37812 - 0 0 0 0 0 0 0 0 0 0 0 0
37813 - 0 0 0 0 0 0 0 0 0 0 0 0
37814 - 0 0 0 6 6 6 22 22 22 50 50 50
37815 - 78 78 78 34 34 34 2 2 6 2 2 6
37816 - 2 2 6 2 2 6 2 2 6 2 2 6
37817 - 2 2 6 2 2 6 2 2 6 2 2 6
37818 - 2 2 6 2 2 6 6 6 6 70 70 70
37819 - 78 78 78 46 46 46 22 22 22 6 6 6
37820 - 0 0 0 0 0 0 0 0 0 0 0 0
37821 - 0 0 0 0 0 0 0 0 0 0 0 0
37822 - 0 0 0 0 0 0 0 0 0 0 0 0
37823 - 0 0 0 0 0 0 0 0 0 0 0 0
37824 - 0 0 0 0 0 0 0 0 0 0 0 0
37825 - 0 0 0 0 0 0 0 0 0 0 0 0
37826 - 0 0 0 0 0 0 0 0 0 0 0 0
37827 - 0 0 0 0 0 0 0 0 0 0 0 0
37828 - 0 0 1 0 0 1 0 0 1 0 0 0
37829 - 0 0 0 0 0 0 0 0 0 0 0 0
37830 - 0 0 0 0 0 0 0 0 0 0 0 0
37831 - 0 0 0 0 0 0 0 0 0 0 0 0
37832 - 0 0 0 0 0 0 0 0 0 0 0 0
37833 - 0 0 0 0 0 0 0 0 0 0 0 0
37834 - 6 6 6 18 18 18 42 42 42 82 82 82
37835 - 26 26 26 2 2 6 2 2 6 2 2 6
37836 - 2 2 6 2 2 6 2 2 6 2 2 6
37837 - 2 2 6 2 2 6 2 2 6 14 14 14
37838 - 46 46 46 34 34 34 6 6 6 2 2 6
37839 - 42 42 42 78 78 78 42 42 42 18 18 18
37840 - 6 6 6 0 0 0 0 0 0 0 0 0
37841 - 0 0 0 0 0 0 0 0 0 0 0 0
37842 - 0 0 0 0 0 0 0 0 0 0 0 0
37843 - 0 0 0 0 0 0 0 0 0 0 0 0
37844 - 0 0 0 0 0 0 0 0 0 0 0 0
37845 - 0 0 0 0 0 0 0 0 0 0 0 0
37846 - 0 0 0 0 0 0 0 0 0 0 0 0
37847 - 0 0 0 0 0 0 0 0 0 0 0 0
37848 - 0 0 1 0 0 0 0 0 1 0 0 0
37849 - 0 0 0 0 0 0 0 0 0 0 0 0
37850 - 0 0 0 0 0 0 0 0 0 0 0 0
37851 - 0 0 0 0 0 0 0 0 0 0 0 0
37852 - 0 0 0 0 0 0 0 0 0 0 0 0
37853 - 0 0 0 0 0 0 0 0 0 0 0 0
37854 - 10 10 10 30 30 30 66 66 66 58 58 58
37855 - 2 2 6 2 2 6 2 2 6 2 2 6
37856 - 2 2 6 2 2 6 2 2 6 2 2 6
37857 - 2 2 6 2 2 6 2 2 6 26 26 26
37858 - 86 86 86 101 101 101 46 46 46 10 10 10
37859 - 2 2 6 58 58 58 70 70 70 34 34 34
37860 - 10 10 10 0 0 0 0 0 0 0 0 0
37861 - 0 0 0 0 0 0 0 0 0 0 0 0
37862 - 0 0 0 0 0 0 0 0 0 0 0 0
37863 - 0 0 0 0 0 0 0 0 0 0 0 0
37864 - 0 0 0 0 0 0 0 0 0 0 0 0
37865 - 0 0 0 0 0 0 0 0 0 0 0 0
37866 - 0 0 0 0 0 0 0 0 0 0 0 0
37867 - 0 0 0 0 0 0 0 0 0 0 0 0
37868 - 0 0 1 0 0 1 0 0 1 0 0 0
37869 - 0 0 0 0 0 0 0 0 0 0 0 0
37870 - 0 0 0 0 0 0 0 0 0 0 0 0
37871 - 0 0 0 0 0 0 0 0 0 0 0 0
37872 - 0 0 0 0 0 0 0 0 0 0 0 0
37873 - 0 0 0 0 0 0 0 0 0 0 0 0
37874 - 14 14 14 42 42 42 86 86 86 10 10 10
37875 - 2 2 6 2 2 6 2 2 6 2 2 6
37876 - 2 2 6 2 2 6 2 2 6 2 2 6
37877 - 2 2 6 2 2 6 2 2 6 30 30 30
37878 - 94 94 94 94 94 94 58 58 58 26 26 26
37879 - 2 2 6 6 6 6 78 78 78 54 54 54
37880 - 22 22 22 6 6 6 0 0 0 0 0 0
37881 - 0 0 0 0 0 0 0 0 0 0 0 0
37882 - 0 0 0 0 0 0 0 0 0 0 0 0
37883 - 0 0 0 0 0 0 0 0 0 0 0 0
37884 - 0 0 0 0 0 0 0 0 0 0 0 0
37885 - 0 0 0 0 0 0 0 0 0 0 0 0
37886 - 0 0 0 0 0 0 0 0 0 0 0 0
37887 - 0 0 0 0 0 0 0 0 0 0 0 0
37888 - 0 0 0 0 0 0 0 0 0 0 0 0
37889 - 0 0 0 0 0 0 0 0 0 0 0 0
37890 - 0 0 0 0 0 0 0 0 0 0 0 0
37891 - 0 0 0 0 0 0 0 0 0 0 0 0
37892 - 0 0 0 0 0 0 0 0 0 0 0 0
37893 - 0 0 0 0 0 0 0 0 0 6 6 6
37894 - 22 22 22 62 62 62 62 62 62 2 2 6
37895 - 2 2 6 2 2 6 2 2 6 2 2 6
37896 - 2 2 6 2 2 6 2 2 6 2 2 6
37897 - 2 2 6 2 2 6 2 2 6 26 26 26
37898 - 54 54 54 38 38 38 18 18 18 10 10 10
37899 - 2 2 6 2 2 6 34 34 34 82 82 82
37900 - 38 38 38 14 14 14 0 0 0 0 0 0
37901 - 0 0 0 0 0 0 0 0 0 0 0 0
37902 - 0 0 0 0 0 0 0 0 0 0 0 0
37903 - 0 0 0 0 0 0 0 0 0 0 0 0
37904 - 0 0 0 0 0 0 0 0 0 0 0 0
37905 - 0 0 0 0 0 0 0 0 0 0 0 0
37906 - 0 0 0 0 0 0 0 0 0 0 0 0
37907 - 0 0 0 0 0 0 0 0 0 0 0 0
37908 - 0 0 0 0 0 1 0 0 1 0 0 0
37909 - 0 0 0 0 0 0 0 0 0 0 0 0
37910 - 0 0 0 0 0 0 0 0 0 0 0 0
37911 - 0 0 0 0 0 0 0 0 0 0 0 0
37912 - 0 0 0 0 0 0 0 0 0 0 0 0
37913 - 0 0 0 0 0 0 0 0 0 6 6 6
37914 - 30 30 30 78 78 78 30 30 30 2 2 6
37915 - 2 2 6 2 2 6 2 2 6 2 2 6
37916 - 2 2 6 2 2 6 2 2 6 2 2 6
37917 - 2 2 6 2 2 6 2 2 6 10 10 10
37918 - 10 10 10 2 2 6 2 2 6 2 2 6
37919 - 2 2 6 2 2 6 2 2 6 78 78 78
37920 - 50 50 50 18 18 18 6 6 6 0 0 0
37921 - 0 0 0 0 0 0 0 0 0 0 0 0
37922 - 0 0 0 0 0 0 0 0 0 0 0 0
37923 - 0 0 0 0 0 0 0 0 0 0 0 0
37924 - 0 0 0 0 0 0 0 0 0 0 0 0
37925 - 0 0 0 0 0 0 0 0 0 0 0 0
37926 - 0 0 0 0 0 0 0 0 0 0 0 0
37927 - 0 0 0 0 0 0 0 0 0 0 0 0
37928 - 0 0 1 0 0 0 0 0 0 0 0 0
37929 - 0 0 0 0 0 0 0 0 0 0 0 0
37930 - 0 0 0 0 0 0 0 0 0 0 0 0
37931 - 0 0 0 0 0 0 0 0 0 0 0 0
37932 - 0 0 0 0 0 0 0 0 0 0 0 0
37933 - 0 0 0 0 0 0 0 0 0 10 10 10
37934 - 38 38 38 86 86 86 14 14 14 2 2 6
37935 - 2 2 6 2 2 6 2 2 6 2 2 6
37936 - 2 2 6 2 2 6 2 2 6 2 2 6
37937 - 2 2 6 2 2 6 2 2 6 2 2 6
37938 - 2 2 6 2 2 6 2 2 6 2 2 6
37939 - 2 2 6 2 2 6 2 2 6 54 54 54
37940 - 66 66 66 26 26 26 6 6 6 0 0 0
37941 - 0 0 0 0 0 0 0 0 0 0 0 0
37942 - 0 0 0 0 0 0 0 0 0 0 0 0
37943 - 0 0 0 0 0 0 0 0 0 0 0 0
37944 - 0 0 0 0 0 0 0 0 0 0 0 0
37945 - 0 0 0 0 0 0 0 0 0 0 0 0
37946 - 0 0 0 0 0 0 0 0 0 0 0 0
37947 - 0 0 0 0 0 0 0 0 0 0 0 0
37948 - 0 0 0 0 0 1 0 0 1 0 0 0
37949 - 0 0 0 0 0 0 0 0 0 0 0 0
37950 - 0 0 0 0 0 0 0 0 0 0 0 0
37951 - 0 0 0 0 0 0 0 0 0 0 0 0
37952 - 0 0 0 0 0 0 0 0 0 0 0 0
37953 - 0 0 0 0 0 0 0 0 0 14 14 14
37954 - 42 42 42 82 82 82 2 2 6 2 2 6
37955 - 2 2 6 6 6 6 10 10 10 2 2 6
37956 - 2 2 6 2 2 6 2 2 6 2 2 6
37957 - 2 2 6 2 2 6 2 2 6 6 6 6
37958 - 14 14 14 10 10 10 2 2 6 2 2 6
37959 - 2 2 6 2 2 6 2 2 6 18 18 18
37960 - 82 82 82 34 34 34 10 10 10 0 0 0
37961 - 0 0 0 0 0 0 0 0 0 0 0 0
37962 - 0 0 0 0 0 0 0 0 0 0 0 0
37963 - 0 0 0 0 0 0 0 0 0 0 0 0
37964 - 0 0 0 0 0 0 0 0 0 0 0 0
37965 - 0 0 0 0 0 0 0 0 0 0 0 0
37966 - 0 0 0 0 0 0 0 0 0 0 0 0
37967 - 0 0 0 0 0 0 0 0 0 0 0 0
37968 - 0 0 1 0 0 0 0 0 0 0 0 0
37969 - 0 0 0 0 0 0 0 0 0 0 0 0
37970 - 0 0 0 0 0 0 0 0 0 0 0 0
37971 - 0 0 0 0 0 0 0 0 0 0 0 0
37972 - 0 0 0 0 0 0 0 0 0 0 0 0
37973 - 0 0 0 0 0 0 0 0 0 14 14 14
37974 - 46 46 46 86 86 86 2 2 6 2 2 6
37975 - 6 6 6 6 6 6 22 22 22 34 34 34
37976 - 6 6 6 2 2 6 2 2 6 2 2 6
37977 - 2 2 6 2 2 6 18 18 18 34 34 34
37978 - 10 10 10 50 50 50 22 22 22 2 2 6
37979 - 2 2 6 2 2 6 2 2 6 10 10 10
37980 - 86 86 86 42 42 42 14 14 14 0 0 0
37981 - 0 0 0 0 0 0 0 0 0 0 0 0
37982 - 0 0 0 0 0 0 0 0 0 0 0 0
37983 - 0 0 0 0 0 0 0 0 0 0 0 0
37984 - 0 0 0 0 0 0 0 0 0 0 0 0
37985 - 0 0 0 0 0 0 0 0 0 0 0 0
37986 - 0 0 0 0 0 0 0 0 0 0 0 0
37987 - 0 0 0 0 0 0 0 0 0 0 0 0
37988 - 0 0 1 0 0 1 0 0 1 0 0 0
37989 - 0 0 0 0 0 0 0 0 0 0 0 0
37990 - 0 0 0 0 0 0 0 0 0 0 0 0
37991 - 0 0 0 0 0 0 0 0 0 0 0 0
37992 - 0 0 0 0 0 0 0 0 0 0 0 0
37993 - 0 0 0 0 0 0 0 0 0 14 14 14
37994 - 46 46 46 86 86 86 2 2 6 2 2 6
37995 - 38 38 38 116 116 116 94 94 94 22 22 22
37996 - 22 22 22 2 2 6 2 2 6 2 2 6
37997 - 14 14 14 86 86 86 138 138 138 162 162 162
37998 -154 154 154 38 38 38 26 26 26 6 6 6
37999 - 2 2 6 2 2 6 2 2 6 2 2 6
38000 - 86 86 86 46 46 46 14 14 14 0 0 0
38001 - 0 0 0 0 0 0 0 0 0 0 0 0
38002 - 0 0 0 0 0 0 0 0 0 0 0 0
38003 - 0 0 0 0 0 0 0 0 0 0 0 0
38004 - 0 0 0 0 0 0 0 0 0 0 0 0
38005 - 0 0 0 0 0 0 0 0 0 0 0 0
38006 - 0 0 0 0 0 0 0 0 0 0 0 0
38007 - 0 0 0 0 0 0 0 0 0 0 0 0
38008 - 0 0 0 0 0 0 0 0 0 0 0 0
38009 - 0 0 0 0 0 0 0 0 0 0 0 0
38010 - 0 0 0 0 0 0 0 0 0 0 0 0
38011 - 0 0 0 0 0 0 0 0 0 0 0 0
38012 - 0 0 0 0 0 0 0 0 0 0 0 0
38013 - 0 0 0 0 0 0 0 0 0 14 14 14
38014 - 46 46 46 86 86 86 2 2 6 14 14 14
38015 -134 134 134 198 198 198 195 195 195 116 116 116
38016 - 10 10 10 2 2 6 2 2 6 6 6 6
38017 -101 98 89 187 187 187 210 210 210 218 218 218
38018 -214 214 214 134 134 134 14 14 14 6 6 6
38019 - 2 2 6 2 2 6 2 2 6 2 2 6
38020 - 86 86 86 50 50 50 18 18 18 6 6 6
38021 - 0 0 0 0 0 0 0 0 0 0 0 0
38022 - 0 0 0 0 0 0 0 0 0 0 0 0
38023 - 0 0 0 0 0 0 0 0 0 0 0 0
38024 - 0 0 0 0 0 0 0 0 0 0 0 0
38025 - 0 0 0 0 0 0 0 0 0 0 0 0
38026 - 0 0 0 0 0 0 0 0 0 0 0 0
38027 - 0 0 0 0 0 0 0 0 1 0 0 0
38028 - 0 0 1 0 0 1 0 0 1 0 0 0
38029 - 0 0 0 0 0 0 0 0 0 0 0 0
38030 - 0 0 0 0 0 0 0 0 0 0 0 0
38031 - 0 0 0 0 0 0 0 0 0 0 0 0
38032 - 0 0 0 0 0 0 0 0 0 0 0 0
38033 - 0 0 0 0 0 0 0 0 0 14 14 14
38034 - 46 46 46 86 86 86 2 2 6 54 54 54
38035 -218 218 218 195 195 195 226 226 226 246 246 246
38036 - 58 58 58 2 2 6 2 2 6 30 30 30
38037 -210 210 210 253 253 253 174 174 174 123 123 123
38038 -221 221 221 234 234 234 74 74 74 2 2 6
38039 - 2 2 6 2 2 6 2 2 6 2 2 6
38040 - 70 70 70 58 58 58 22 22 22 6 6 6
38041 - 0 0 0 0 0 0 0 0 0 0 0 0
38042 - 0 0 0 0 0 0 0 0 0 0 0 0
38043 - 0 0 0 0 0 0 0 0 0 0 0 0
38044 - 0 0 0 0 0 0 0 0 0 0 0 0
38045 - 0 0 0 0 0 0 0 0 0 0 0 0
38046 - 0 0 0 0 0 0 0 0 0 0 0 0
38047 - 0 0 0 0 0 0 0 0 0 0 0 0
38048 - 0 0 0 0 0 0 0 0 0 0 0 0
38049 - 0 0 0 0 0 0 0 0 0 0 0 0
38050 - 0 0 0 0 0 0 0 0 0 0 0 0
38051 - 0 0 0 0 0 0 0 0 0 0 0 0
38052 - 0 0 0 0 0 0 0 0 0 0 0 0
38053 - 0 0 0 0 0 0 0 0 0 14 14 14
38054 - 46 46 46 82 82 82 2 2 6 106 106 106
38055 -170 170 170 26 26 26 86 86 86 226 226 226
38056 -123 123 123 10 10 10 14 14 14 46 46 46
38057 -231 231 231 190 190 190 6 6 6 70 70 70
38058 - 90 90 90 238 238 238 158 158 158 2 2 6
38059 - 2 2 6 2 2 6 2 2 6 2 2 6
38060 - 70 70 70 58 58 58 22 22 22 6 6 6
38061 - 0 0 0 0 0 0 0 0 0 0 0 0
38062 - 0 0 0 0 0 0 0 0 0 0 0 0
38063 - 0 0 0 0 0 0 0 0 0 0 0 0
38064 - 0 0 0 0 0 0 0 0 0 0 0 0
38065 - 0 0 0 0 0 0 0 0 0 0 0 0
38066 - 0 0 0 0 0 0 0 0 0 0 0 0
38067 - 0 0 0 0 0 0 0 0 1 0 0 0
38068 - 0 0 1 0 0 1 0 0 1 0 0 0
38069 - 0 0 0 0 0 0 0 0 0 0 0 0
38070 - 0 0 0 0 0 0 0 0 0 0 0 0
38071 - 0 0 0 0 0 0 0 0 0 0 0 0
38072 - 0 0 0 0 0 0 0 0 0 0 0 0
38073 - 0 0 0 0 0 0 0 0 0 14 14 14
38074 - 42 42 42 86 86 86 6 6 6 116 116 116
38075 -106 106 106 6 6 6 70 70 70 149 149 149
38076 -128 128 128 18 18 18 38 38 38 54 54 54
38077 -221 221 221 106 106 106 2 2 6 14 14 14
38078 - 46 46 46 190 190 190 198 198 198 2 2 6
38079 - 2 2 6 2 2 6 2 2 6 2 2 6
38080 - 74 74 74 62 62 62 22 22 22 6 6 6
38081 - 0 0 0 0 0 0 0 0 0 0 0 0
38082 - 0 0 0 0 0 0 0 0 0 0 0 0
38083 - 0 0 0 0 0 0 0 0 0 0 0 0
38084 - 0 0 0 0 0 0 0 0 0 0 0 0
38085 - 0 0 0 0 0 0 0 0 0 0 0 0
38086 - 0 0 0 0 0 0 0 0 0 0 0 0
38087 - 0 0 0 0 0 0 0 0 1 0 0 0
38088 - 0 0 1 0 0 0 0 0 1 0 0 0
38089 - 0 0 0 0 0 0 0 0 0 0 0 0
38090 - 0 0 0 0 0 0 0 0 0 0 0 0
38091 - 0 0 0 0 0 0 0 0 0 0 0 0
38092 - 0 0 0 0 0 0 0 0 0 0 0 0
38093 - 0 0 0 0 0 0 0 0 0 14 14 14
38094 - 42 42 42 94 94 94 14 14 14 101 101 101
38095 -128 128 128 2 2 6 18 18 18 116 116 116
38096 -118 98 46 121 92 8 121 92 8 98 78 10
38097 -162 162 162 106 106 106 2 2 6 2 2 6
38098 - 2 2 6 195 195 195 195 195 195 6 6 6
38099 - 2 2 6 2 2 6 2 2 6 2 2 6
38100 - 74 74 74 62 62 62 22 22 22 6 6 6
38101 - 0 0 0 0 0 0 0 0 0 0 0 0
38102 - 0 0 0 0 0 0 0 0 0 0 0 0
38103 - 0 0 0 0 0 0 0 0 0 0 0 0
38104 - 0 0 0 0 0 0 0 0 0 0 0 0
38105 - 0 0 0 0 0 0 0 0 0 0 0 0
38106 - 0 0 0 0 0 0 0 0 0 0 0 0
38107 - 0 0 0 0 0 0 0 0 1 0 0 1
38108 - 0 0 1 0 0 0 0 0 1 0 0 0
38109 - 0 0 0 0 0 0 0 0 0 0 0 0
38110 - 0 0 0 0 0 0 0 0 0 0 0 0
38111 - 0 0 0 0 0 0 0 0 0 0 0 0
38112 - 0 0 0 0 0 0 0 0 0 0 0 0
38113 - 0 0 0 0 0 0 0 0 0 10 10 10
38114 - 38 38 38 90 90 90 14 14 14 58 58 58
38115 -210 210 210 26 26 26 54 38 6 154 114 10
38116 -226 170 11 236 186 11 225 175 15 184 144 12
38117 -215 174 15 175 146 61 37 26 9 2 2 6
38118 - 70 70 70 246 246 246 138 138 138 2 2 6
38119 - 2 2 6 2 2 6 2 2 6 2 2 6
38120 - 70 70 70 66 66 66 26 26 26 6 6 6
38121 - 0 0 0 0 0 0 0 0 0 0 0 0
38122 - 0 0 0 0 0 0 0 0 0 0 0 0
38123 - 0 0 0 0 0 0 0 0 0 0 0 0
38124 - 0 0 0 0 0 0 0 0 0 0 0 0
38125 - 0 0 0 0 0 0 0 0 0 0 0 0
38126 - 0 0 0 0 0 0 0 0 0 0 0 0
38127 - 0 0 0 0 0 0 0 0 0 0 0 0
38128 - 0 0 0 0 0 0 0 0 0 0 0 0
38129 - 0 0 0 0 0 0 0 0 0 0 0 0
38130 - 0 0 0 0 0 0 0 0 0 0 0 0
38131 - 0 0 0 0 0 0 0 0 0 0 0 0
38132 - 0 0 0 0 0 0 0 0 0 0 0 0
38133 - 0 0 0 0 0 0 0 0 0 10 10 10
38134 - 38 38 38 86 86 86 14 14 14 10 10 10
38135 -195 195 195 188 164 115 192 133 9 225 175 15
38136 -239 182 13 234 190 10 232 195 16 232 200 30
38137 -245 207 45 241 208 19 232 195 16 184 144 12
38138 -218 194 134 211 206 186 42 42 42 2 2 6
38139 - 2 2 6 2 2 6 2 2 6 2 2 6
38140 - 50 50 50 74 74 74 30 30 30 6 6 6
38141 - 0 0 0 0 0 0 0 0 0 0 0 0
38142 - 0 0 0 0 0 0 0 0 0 0 0 0
38143 - 0 0 0 0 0 0 0 0 0 0 0 0
38144 - 0 0 0 0 0 0 0 0 0 0 0 0
38145 - 0 0 0 0 0 0 0 0 0 0 0 0
38146 - 0 0 0 0 0 0 0 0 0 0 0 0
38147 - 0 0 0 0 0 0 0 0 0 0 0 0
38148 - 0 0 0 0 0 0 0 0 0 0 0 0
38149 - 0 0 0 0 0 0 0 0 0 0 0 0
38150 - 0 0 0 0 0 0 0 0 0 0 0 0
38151 - 0 0 0 0 0 0 0 0 0 0 0 0
38152 - 0 0 0 0 0 0 0 0 0 0 0 0
38153 - 0 0 0 0 0 0 0 0 0 10 10 10
38154 - 34 34 34 86 86 86 14 14 14 2 2 6
38155 -121 87 25 192 133 9 219 162 10 239 182 13
38156 -236 186 11 232 195 16 241 208 19 244 214 54
38157 -246 218 60 246 218 38 246 215 20 241 208 19
38158 -241 208 19 226 184 13 121 87 25 2 2 6
38159 - 2 2 6 2 2 6 2 2 6 2 2 6
38160 - 50 50 50 82 82 82 34 34 34 10 10 10
38161 - 0 0 0 0 0 0 0 0 0 0 0 0
38162 - 0 0 0 0 0 0 0 0 0 0 0 0
38163 - 0 0 0 0 0 0 0 0 0 0 0 0
38164 - 0 0 0 0 0 0 0 0 0 0 0 0
38165 - 0 0 0 0 0 0 0 0 0 0 0 0
38166 - 0 0 0 0 0 0 0 0 0 0 0 0
38167 - 0 0 0 0 0 0 0 0 0 0 0 0
38168 - 0 0 0 0 0 0 0 0 0 0 0 0
38169 - 0 0 0 0 0 0 0 0 0 0 0 0
38170 - 0 0 0 0 0 0 0 0 0 0 0 0
38171 - 0 0 0 0 0 0 0 0 0 0 0 0
38172 - 0 0 0 0 0 0 0 0 0 0 0 0
38173 - 0 0 0 0 0 0 0 0 0 10 10 10
38174 - 34 34 34 82 82 82 30 30 30 61 42 6
38175 -180 123 7 206 145 10 230 174 11 239 182 13
38176 -234 190 10 238 202 15 241 208 19 246 218 74
38177 -246 218 38 246 215 20 246 215 20 246 215 20
38178 -226 184 13 215 174 15 184 144 12 6 6 6
38179 - 2 2 6 2 2 6 2 2 6 2 2 6
38180 - 26 26 26 94 94 94 42 42 42 14 14 14
38181 - 0 0 0 0 0 0 0 0 0 0 0 0
38182 - 0 0 0 0 0 0 0 0 0 0 0 0
38183 - 0 0 0 0 0 0 0 0 0 0 0 0
38184 - 0 0 0 0 0 0 0 0 0 0 0 0
38185 - 0 0 0 0 0 0 0 0 0 0 0 0
38186 - 0 0 0 0 0 0 0 0 0 0 0 0
38187 - 0 0 0 0 0 0 0 0 0 0 0 0
38188 - 0 0 0 0 0 0 0 0 0 0 0 0
38189 - 0 0 0 0 0 0 0 0 0 0 0 0
38190 - 0 0 0 0 0 0 0 0 0 0 0 0
38191 - 0 0 0 0 0 0 0 0 0 0 0 0
38192 - 0 0 0 0 0 0 0 0 0 0 0 0
38193 - 0 0 0 0 0 0 0 0 0 10 10 10
38194 - 30 30 30 78 78 78 50 50 50 104 69 6
38195 -192 133 9 216 158 10 236 178 12 236 186 11
38196 -232 195 16 241 208 19 244 214 54 245 215 43
38197 -246 215 20 246 215 20 241 208 19 198 155 10
38198 -200 144 11 216 158 10 156 118 10 2 2 6
38199 - 2 2 6 2 2 6 2 2 6 2 2 6
38200 - 6 6 6 90 90 90 54 54 54 18 18 18
38201 - 6 6 6 0 0 0 0 0 0 0 0 0
38202 - 0 0 0 0 0 0 0 0 0 0 0 0
38203 - 0 0 0 0 0 0 0 0 0 0 0 0
38204 - 0 0 0 0 0 0 0 0 0 0 0 0
38205 - 0 0 0 0 0 0 0 0 0 0 0 0
38206 - 0 0 0 0 0 0 0 0 0 0 0 0
38207 - 0 0 0 0 0 0 0 0 0 0 0 0
38208 - 0 0 0 0 0 0 0 0 0 0 0 0
38209 - 0 0 0 0 0 0 0 0 0 0 0 0
38210 - 0 0 0 0 0 0 0 0 0 0 0 0
38211 - 0 0 0 0 0 0 0 0 0 0 0 0
38212 - 0 0 0 0 0 0 0 0 0 0 0 0
38213 - 0 0 0 0 0 0 0 0 0 10 10 10
38214 - 30 30 30 78 78 78 46 46 46 22 22 22
38215 -137 92 6 210 162 10 239 182 13 238 190 10
38216 -238 202 15 241 208 19 246 215 20 246 215 20
38217 -241 208 19 203 166 17 185 133 11 210 150 10
38218 -216 158 10 210 150 10 102 78 10 2 2 6
38219 - 6 6 6 54 54 54 14 14 14 2 2 6
38220 - 2 2 6 62 62 62 74 74 74 30 30 30
38221 - 10 10 10 0 0 0 0 0 0 0 0 0
38222 - 0 0 0 0 0 0 0 0 0 0 0 0
38223 - 0 0 0 0 0 0 0 0 0 0 0 0
38224 - 0 0 0 0 0 0 0 0 0 0 0 0
38225 - 0 0 0 0 0 0 0 0 0 0 0 0
38226 - 0 0 0 0 0 0 0 0 0 0 0 0
38227 - 0 0 0 0 0 0 0 0 0 0 0 0
38228 - 0 0 0 0 0 0 0 0 0 0 0 0
38229 - 0 0 0 0 0 0 0 0 0 0 0 0
38230 - 0 0 0 0 0 0 0 0 0 0 0 0
38231 - 0 0 0 0 0 0 0 0 0 0 0 0
38232 - 0 0 0 0 0 0 0 0 0 0 0 0
38233 - 0 0 0 0 0 0 0 0 0 10 10 10
38234 - 34 34 34 78 78 78 50 50 50 6 6 6
38235 - 94 70 30 139 102 15 190 146 13 226 184 13
38236 -232 200 30 232 195 16 215 174 15 190 146 13
38237 -168 122 10 192 133 9 210 150 10 213 154 11
38238 -202 150 34 182 157 106 101 98 89 2 2 6
38239 - 2 2 6 78 78 78 116 116 116 58 58 58
38240 - 2 2 6 22 22 22 90 90 90 46 46 46
38241 - 18 18 18 6 6 6 0 0 0 0 0 0
38242 - 0 0 0 0 0 0 0 0 0 0 0 0
38243 - 0 0 0 0 0 0 0 0 0 0 0 0
38244 - 0 0 0 0 0 0 0 0 0 0 0 0
38245 - 0 0 0 0 0 0 0 0 0 0 0 0
38246 - 0 0 0 0 0 0 0 0 0 0 0 0
38247 - 0 0 0 0 0 0 0 0 0 0 0 0
38248 - 0 0 0 0 0 0 0 0 0 0 0 0
38249 - 0 0 0 0 0 0 0 0 0 0 0 0
38250 - 0 0 0 0 0 0 0 0 0 0 0 0
38251 - 0 0 0 0 0 0 0 0 0 0 0 0
38252 - 0 0 0 0 0 0 0 0 0 0 0 0
38253 - 0 0 0 0 0 0 0 0 0 10 10 10
38254 - 38 38 38 86 86 86 50 50 50 6 6 6
38255 -128 128 128 174 154 114 156 107 11 168 122 10
38256 -198 155 10 184 144 12 197 138 11 200 144 11
38257 -206 145 10 206 145 10 197 138 11 188 164 115
38258 -195 195 195 198 198 198 174 174 174 14 14 14
38259 - 2 2 6 22 22 22 116 116 116 116 116 116
38260 - 22 22 22 2 2 6 74 74 74 70 70 70
38261 - 30 30 30 10 10 10 0 0 0 0 0 0
38262 - 0 0 0 0 0 0 0 0 0 0 0 0
38263 - 0 0 0 0 0 0 0 0 0 0 0 0
38264 - 0 0 0 0 0 0 0 0 0 0 0 0
38265 - 0 0 0 0 0 0 0 0 0 0 0 0
38266 - 0 0 0 0 0 0 0 0 0 0 0 0
38267 - 0 0 0 0 0 0 0 0 0 0 0 0
38268 - 0 0 0 0 0 0 0 0 0 0 0 0
38269 - 0 0 0 0 0 0 0 0 0 0 0 0
38270 - 0 0 0 0 0 0 0 0 0 0 0 0
38271 - 0 0 0 0 0 0 0 0 0 0 0 0
38272 - 0 0 0 0 0 0 0 0 0 0 0 0
38273 - 0 0 0 0 0 0 6 6 6 18 18 18
38274 - 50 50 50 101 101 101 26 26 26 10 10 10
38275 -138 138 138 190 190 190 174 154 114 156 107 11
38276 -197 138 11 200 144 11 197 138 11 192 133 9
38277 -180 123 7 190 142 34 190 178 144 187 187 187
38278 -202 202 202 221 221 221 214 214 214 66 66 66
38279 - 2 2 6 2 2 6 50 50 50 62 62 62
38280 - 6 6 6 2 2 6 10 10 10 90 90 90
38281 - 50 50 50 18 18 18 6 6 6 0 0 0
38282 - 0 0 0 0 0 0 0 0 0 0 0 0
38283 - 0 0 0 0 0 0 0 0 0 0 0 0
38284 - 0 0 0 0 0 0 0 0 0 0 0 0
38285 - 0 0 0 0 0 0 0 0 0 0 0 0
38286 - 0 0 0 0 0 0 0 0 0 0 0 0
38287 - 0 0 0 0 0 0 0 0 0 0 0 0
38288 - 0 0 0 0 0 0 0 0 0 0 0 0
38289 - 0 0 0 0 0 0 0 0 0 0 0 0
38290 - 0 0 0 0 0 0 0 0 0 0 0 0
38291 - 0 0 0 0 0 0 0 0 0 0 0 0
38292 - 0 0 0 0 0 0 0 0 0 0 0 0
38293 - 0 0 0 0 0 0 10 10 10 34 34 34
38294 - 74 74 74 74 74 74 2 2 6 6 6 6
38295 -144 144 144 198 198 198 190 190 190 178 166 146
38296 -154 121 60 156 107 11 156 107 11 168 124 44
38297 -174 154 114 187 187 187 190 190 190 210 210 210
38298 -246 246 246 253 253 253 253 253 253 182 182 182
38299 - 6 6 6 2 2 6 2 2 6 2 2 6
38300 - 2 2 6 2 2 6 2 2 6 62 62 62
38301 - 74 74 74 34 34 34 14 14 14 0 0 0
38302 - 0 0 0 0 0 0 0 0 0 0 0 0
38303 - 0 0 0 0 0 0 0 0 0 0 0 0
38304 - 0 0 0 0 0 0 0 0 0 0 0 0
38305 - 0 0 0 0 0 0 0 0 0 0 0 0
38306 - 0 0 0 0 0 0 0 0 0 0 0 0
38307 - 0 0 0 0 0 0 0 0 0 0 0 0
38308 - 0 0 0 0 0 0 0 0 0 0 0 0
38309 - 0 0 0 0 0 0 0 0 0 0 0 0
38310 - 0 0 0 0 0 0 0 0 0 0 0 0
38311 - 0 0 0 0 0 0 0 0 0 0 0 0
38312 - 0 0 0 0 0 0 0 0 0 0 0 0
38313 - 0 0 0 10 10 10 22 22 22 54 54 54
38314 - 94 94 94 18 18 18 2 2 6 46 46 46
38315 -234 234 234 221 221 221 190 190 190 190 190 190
38316 -190 190 190 187 187 187 187 187 187 190 190 190
38317 -190 190 190 195 195 195 214 214 214 242 242 242
38318 -253 253 253 253 253 253 253 253 253 253 253 253
38319 - 82 82 82 2 2 6 2 2 6 2 2 6
38320 - 2 2 6 2 2 6 2 2 6 14 14 14
38321 - 86 86 86 54 54 54 22 22 22 6 6 6
38322 - 0 0 0 0 0 0 0 0 0 0 0 0
38323 - 0 0 0 0 0 0 0 0 0 0 0 0
38324 - 0 0 0 0 0 0 0 0 0 0 0 0
38325 - 0 0 0 0 0 0 0 0 0 0 0 0
38326 - 0 0 0 0 0 0 0 0 0 0 0 0
38327 - 0 0 0 0 0 0 0 0 0 0 0 0
38328 - 0 0 0 0 0 0 0 0 0 0 0 0
38329 - 0 0 0 0 0 0 0 0 0 0 0 0
38330 - 0 0 0 0 0 0 0 0 0 0 0 0
38331 - 0 0 0 0 0 0 0 0 0 0 0 0
38332 - 0 0 0 0 0 0 0 0 0 0 0 0
38333 - 6 6 6 18 18 18 46 46 46 90 90 90
38334 - 46 46 46 18 18 18 6 6 6 182 182 182
38335 -253 253 253 246 246 246 206 206 206 190 190 190
38336 -190 190 190 190 190 190 190 190 190 190 190 190
38337 -206 206 206 231 231 231 250 250 250 253 253 253
38338 -253 253 253 253 253 253 253 253 253 253 253 253
38339 -202 202 202 14 14 14 2 2 6 2 2 6
38340 - 2 2 6 2 2 6 2 2 6 2 2 6
38341 - 42 42 42 86 86 86 42 42 42 18 18 18
38342 - 6 6 6 0 0 0 0 0 0 0 0 0
38343 - 0 0 0 0 0 0 0 0 0 0 0 0
38344 - 0 0 0 0 0 0 0 0 0 0 0 0
38345 - 0 0 0 0 0 0 0 0 0 0 0 0
38346 - 0 0 0 0 0 0 0 0 0 0 0 0
38347 - 0 0 0 0 0 0 0 0 0 0 0 0
38348 - 0 0 0 0 0 0 0 0 0 0 0 0
38349 - 0 0 0 0 0 0 0 0 0 0 0 0
38350 - 0 0 0 0 0 0 0 0 0 0 0 0
38351 - 0 0 0 0 0 0 0 0 0 0 0 0
38352 - 0 0 0 0 0 0 0 0 0 6 6 6
38353 - 14 14 14 38 38 38 74 74 74 66 66 66
38354 - 2 2 6 6 6 6 90 90 90 250 250 250
38355 -253 253 253 253 253 253 238 238 238 198 198 198
38356 -190 190 190 190 190 190 195 195 195 221 221 221
38357 -246 246 246 253 253 253 253 253 253 253 253 253
38358 -253 253 253 253 253 253 253 253 253 253 253 253
38359 -253 253 253 82 82 82 2 2 6 2 2 6
38360 - 2 2 6 2 2 6 2 2 6 2 2 6
38361 - 2 2 6 78 78 78 70 70 70 34 34 34
38362 - 14 14 14 6 6 6 0 0 0 0 0 0
38363 - 0 0 0 0 0 0 0 0 0 0 0 0
38364 - 0 0 0 0 0 0 0 0 0 0 0 0
38365 - 0 0 0 0 0 0 0 0 0 0 0 0
38366 - 0 0 0 0 0 0 0 0 0 0 0 0
38367 - 0 0 0 0 0 0 0 0 0 0 0 0
38368 - 0 0 0 0 0 0 0 0 0 0 0 0
38369 - 0 0 0 0 0 0 0 0 0 0 0 0
38370 - 0 0 0 0 0 0 0 0 0 0 0 0
38371 - 0 0 0 0 0 0 0 0 0 0 0 0
38372 - 0 0 0 0 0 0 0 0 0 14 14 14
38373 - 34 34 34 66 66 66 78 78 78 6 6 6
38374 - 2 2 6 18 18 18 218 218 218 253 253 253
38375 -253 253 253 253 253 253 253 253 253 246 246 246
38376 -226 226 226 231 231 231 246 246 246 253 253 253
38377 -253 253 253 253 253 253 253 253 253 253 253 253
38378 -253 253 253 253 253 253 253 253 253 253 253 253
38379 -253 253 253 178 178 178 2 2 6 2 2 6
38380 - 2 2 6 2 2 6 2 2 6 2 2 6
38381 - 2 2 6 18 18 18 90 90 90 62 62 62
38382 - 30 30 30 10 10 10 0 0 0 0 0 0
38383 - 0 0 0 0 0 0 0 0 0 0 0 0
38384 - 0 0 0 0 0 0 0 0 0 0 0 0
38385 - 0 0 0 0 0 0 0 0 0 0 0 0
38386 - 0 0 0 0 0 0 0 0 0 0 0 0
38387 - 0 0 0 0 0 0 0 0 0 0 0 0
38388 - 0 0 0 0 0 0 0 0 0 0 0 0
38389 - 0 0 0 0 0 0 0 0 0 0 0 0
38390 - 0 0 0 0 0 0 0 0 0 0 0 0
38391 - 0 0 0 0 0 0 0 0 0 0 0 0
38392 - 0 0 0 0 0 0 10 10 10 26 26 26
38393 - 58 58 58 90 90 90 18 18 18 2 2 6
38394 - 2 2 6 110 110 110 253 253 253 253 253 253
38395 -253 253 253 253 253 253 253 253 253 253 253 253
38396 -250 250 250 253 253 253 253 253 253 253 253 253
38397 -253 253 253 253 253 253 253 253 253 253 253 253
38398 -253 253 253 253 253 253 253 253 253 253 253 253
38399 -253 253 253 231 231 231 18 18 18 2 2 6
38400 - 2 2 6 2 2 6 2 2 6 2 2 6
38401 - 2 2 6 2 2 6 18 18 18 94 94 94
38402 - 54 54 54 26 26 26 10 10 10 0 0 0
38403 - 0 0 0 0 0 0 0 0 0 0 0 0
38404 - 0 0 0 0 0 0 0 0 0 0 0 0
38405 - 0 0 0 0 0 0 0 0 0 0 0 0
38406 - 0 0 0 0 0 0 0 0 0 0 0 0
38407 - 0 0 0 0 0 0 0 0 0 0 0 0
38408 - 0 0 0 0 0 0 0 0 0 0 0 0
38409 - 0 0 0 0 0 0 0 0 0 0 0 0
38410 - 0 0 0 0 0 0 0 0 0 0 0 0
38411 - 0 0 0 0 0 0 0 0 0 0 0 0
38412 - 0 0 0 6 6 6 22 22 22 50 50 50
38413 - 90 90 90 26 26 26 2 2 6 2 2 6
38414 - 14 14 14 195 195 195 250 250 250 253 253 253
38415 -253 253 253 253 253 253 253 253 253 253 253 253
38416 -253 253 253 253 253 253 253 253 253 253 253 253
38417 -253 253 253 253 253 253 253 253 253 253 253 253
38418 -253 253 253 253 253 253 253 253 253 253 253 253
38419 -250 250 250 242 242 242 54 54 54 2 2 6
38420 - 2 2 6 2 2 6 2 2 6 2 2 6
38421 - 2 2 6 2 2 6 2 2 6 38 38 38
38422 - 86 86 86 50 50 50 22 22 22 6 6 6
38423 - 0 0 0 0 0 0 0 0 0 0 0 0
38424 - 0 0 0 0 0 0 0 0 0 0 0 0
38425 - 0 0 0 0 0 0 0 0 0 0 0 0
38426 - 0 0 0 0 0 0 0 0 0 0 0 0
38427 - 0 0 0 0 0 0 0 0 0 0 0 0
38428 - 0 0 0 0 0 0 0 0 0 0 0 0
38429 - 0 0 0 0 0 0 0 0 0 0 0 0
38430 - 0 0 0 0 0 0 0 0 0 0 0 0
38431 - 0 0 0 0 0 0 0 0 0 0 0 0
38432 - 6 6 6 14 14 14 38 38 38 82 82 82
38433 - 34 34 34 2 2 6 2 2 6 2 2 6
38434 - 42 42 42 195 195 195 246 246 246 253 253 253
38435 -253 253 253 253 253 253 253 253 253 250 250 250
38436 -242 242 242 242 242 242 250 250 250 253 253 253
38437 -253 253 253 253 253 253 253 253 253 253 253 253
38438 -253 253 253 250 250 250 246 246 246 238 238 238
38439 -226 226 226 231 231 231 101 101 101 6 6 6
38440 - 2 2 6 2 2 6 2 2 6 2 2 6
38441 - 2 2 6 2 2 6 2 2 6 2 2 6
38442 - 38 38 38 82 82 82 42 42 42 14 14 14
38443 - 6 6 6 0 0 0 0 0 0 0 0 0
38444 - 0 0 0 0 0 0 0 0 0 0 0 0
38445 - 0 0 0 0 0 0 0 0 0 0 0 0
38446 - 0 0 0 0 0 0 0 0 0 0 0 0
38447 - 0 0 0 0 0 0 0 0 0 0 0 0
38448 - 0 0 0 0 0 0 0 0 0 0 0 0
38449 - 0 0 0 0 0 0 0 0 0 0 0 0
38450 - 0 0 0 0 0 0 0 0 0 0 0 0
38451 - 0 0 0 0 0 0 0 0 0 0 0 0
38452 - 10 10 10 26 26 26 62 62 62 66 66 66
38453 - 2 2 6 2 2 6 2 2 6 6 6 6
38454 - 70 70 70 170 170 170 206 206 206 234 234 234
38455 -246 246 246 250 250 250 250 250 250 238 238 238
38456 -226 226 226 231 231 231 238 238 238 250 250 250
38457 -250 250 250 250 250 250 246 246 246 231 231 231
38458 -214 214 214 206 206 206 202 202 202 202 202 202
38459 -198 198 198 202 202 202 182 182 182 18 18 18
38460 - 2 2 6 2 2 6 2 2 6 2 2 6
38461 - 2 2 6 2 2 6 2 2 6 2 2 6
38462 - 2 2 6 62 62 62 66 66 66 30 30 30
38463 - 10 10 10 0 0 0 0 0 0 0 0 0
38464 - 0 0 0 0 0 0 0 0 0 0 0 0
38465 - 0 0 0 0 0 0 0 0 0 0 0 0
38466 - 0 0 0 0 0 0 0 0 0 0 0 0
38467 - 0 0 0 0 0 0 0 0 0 0 0 0
38468 - 0 0 0 0 0 0 0 0 0 0 0 0
38469 - 0 0 0 0 0 0 0 0 0 0 0 0
38470 - 0 0 0 0 0 0 0 0 0 0 0 0
38471 - 0 0 0 0 0 0 0 0 0 0 0 0
38472 - 14 14 14 42 42 42 82 82 82 18 18 18
38473 - 2 2 6 2 2 6 2 2 6 10 10 10
38474 - 94 94 94 182 182 182 218 218 218 242 242 242
38475 -250 250 250 253 253 253 253 253 253 250 250 250
38476 -234 234 234 253 253 253 253 253 253 253 253 253
38477 -253 253 253 253 253 253 253 253 253 246 246 246
38478 -238 238 238 226 226 226 210 210 210 202 202 202
38479 -195 195 195 195 195 195 210 210 210 158 158 158
38480 - 6 6 6 14 14 14 50 50 50 14 14 14
38481 - 2 2 6 2 2 6 2 2 6 2 2 6
38482 - 2 2 6 6 6 6 86 86 86 46 46 46
38483 - 18 18 18 6 6 6 0 0 0 0 0 0
38484 - 0 0 0 0 0 0 0 0 0 0 0 0
38485 - 0 0 0 0 0 0 0 0 0 0 0 0
38486 - 0 0 0 0 0 0 0 0 0 0 0 0
38487 - 0 0 0 0 0 0 0 0 0 0 0 0
38488 - 0 0 0 0 0 0 0 0 0 0 0 0
38489 - 0 0 0 0 0 0 0 0 0 0 0 0
38490 - 0 0 0 0 0 0 0 0 0 0 0 0
38491 - 0 0 0 0 0 0 0 0 0 6 6 6
38492 - 22 22 22 54 54 54 70 70 70 2 2 6
38493 - 2 2 6 10 10 10 2 2 6 22 22 22
38494 -166 166 166 231 231 231 250 250 250 253 253 253
38495 -253 253 253 253 253 253 253 253 253 250 250 250
38496 -242 242 242 253 253 253 253 253 253 253 253 253
38497 -253 253 253 253 253 253 253 253 253 253 253 253
38498 -253 253 253 253 253 253 253 253 253 246 246 246
38499 -231 231 231 206 206 206 198 198 198 226 226 226
38500 - 94 94 94 2 2 6 6 6 6 38 38 38
38501 - 30 30 30 2 2 6 2 2 6 2 2 6
38502 - 2 2 6 2 2 6 62 62 62 66 66 66
38503 - 26 26 26 10 10 10 0 0 0 0 0 0
38504 - 0 0 0 0 0 0 0 0 0 0 0 0
38505 - 0 0 0 0 0 0 0 0 0 0 0 0
38506 - 0 0 0 0 0 0 0 0 0 0 0 0
38507 - 0 0 0 0 0 0 0 0 0 0 0 0
38508 - 0 0 0 0 0 0 0 0 0 0 0 0
38509 - 0 0 0 0 0 0 0 0 0 0 0 0
38510 - 0 0 0 0 0 0 0 0 0 0 0 0
38511 - 0 0 0 0 0 0 0 0 0 10 10 10
38512 - 30 30 30 74 74 74 50 50 50 2 2 6
38513 - 26 26 26 26 26 26 2 2 6 106 106 106
38514 -238 238 238 253 253 253 253 253 253 253 253 253
38515 -253 253 253 253 253 253 253 253 253 253 253 253
38516 -253 253 253 253 253 253 253 253 253 253 253 253
38517 -253 253 253 253 253 253 253 253 253 253 253 253
38518 -253 253 253 253 253 253 253 253 253 253 253 253
38519 -253 253 253 246 246 246 218 218 218 202 202 202
38520 -210 210 210 14 14 14 2 2 6 2 2 6
38521 - 30 30 30 22 22 22 2 2 6 2 2 6
38522 - 2 2 6 2 2 6 18 18 18 86 86 86
38523 - 42 42 42 14 14 14 0 0 0 0 0 0
38524 - 0 0 0 0 0 0 0 0 0 0 0 0
38525 - 0 0 0 0 0 0 0 0 0 0 0 0
38526 - 0 0 0 0 0 0 0 0 0 0 0 0
38527 - 0 0 0 0 0 0 0 0 0 0 0 0
38528 - 0 0 0 0 0 0 0 0 0 0 0 0
38529 - 0 0 0 0 0 0 0 0 0 0 0 0
38530 - 0 0 0 0 0 0 0 0 0 0 0 0
38531 - 0 0 0 0 0 0 0 0 0 14 14 14
38532 - 42 42 42 90 90 90 22 22 22 2 2 6
38533 - 42 42 42 2 2 6 18 18 18 218 218 218
38534 -253 253 253 253 253 253 253 253 253 253 253 253
38535 -253 253 253 253 253 253 253 253 253 253 253 253
38536 -253 253 253 253 253 253 253 253 253 253 253 253
38537 -253 253 253 253 253 253 253 253 253 253 253 253
38538 -253 253 253 253 253 253 253 253 253 253 253 253
38539 -253 253 253 253 253 253 250 250 250 221 221 221
38540 -218 218 218 101 101 101 2 2 6 14 14 14
38541 - 18 18 18 38 38 38 10 10 10 2 2 6
38542 - 2 2 6 2 2 6 2 2 6 78 78 78
38543 - 58 58 58 22 22 22 6 6 6 0 0 0
38544 - 0 0 0 0 0 0 0 0 0 0 0 0
38545 - 0 0 0 0 0 0 0 0 0 0 0 0
38546 - 0 0 0 0 0 0 0 0 0 0 0 0
38547 - 0 0 0 0 0 0 0 0 0 0 0 0
38548 - 0 0 0 0 0 0 0 0 0 0 0 0
38549 - 0 0 0 0 0 0 0 0 0 0 0 0
38550 - 0 0 0 0 0 0 0 0 0 0 0 0
38551 - 0 0 0 0 0 0 6 6 6 18 18 18
38552 - 54 54 54 82 82 82 2 2 6 26 26 26
38553 - 22 22 22 2 2 6 123 123 123 253 253 253
38554 -253 253 253 253 253 253 253 253 253 253 253 253
38555 -253 253 253 253 253 253 253 253 253 253 253 253
38556 -253 253 253 253 253 253 253 253 253 253 253 253
38557 -253 253 253 253 253 253 253 253 253 253 253 253
38558 -253 253 253 253 253 253 253 253 253 253 253 253
38559 -253 253 253 253 253 253 253 253 253 250 250 250
38560 -238 238 238 198 198 198 6 6 6 38 38 38
38561 - 58 58 58 26 26 26 38 38 38 2 2 6
38562 - 2 2 6 2 2 6 2 2 6 46 46 46
38563 - 78 78 78 30 30 30 10 10 10 0 0 0
38564 - 0 0 0 0 0 0 0 0 0 0 0 0
38565 - 0 0 0 0 0 0 0 0 0 0 0 0
38566 - 0 0 0 0 0 0 0 0 0 0 0 0
38567 - 0 0 0 0 0 0 0 0 0 0 0 0
38568 - 0 0 0 0 0 0 0 0 0 0 0 0
38569 - 0 0 0 0 0 0 0 0 0 0 0 0
38570 - 0 0 0 0 0 0 0 0 0 0 0 0
38571 - 0 0 0 0 0 0 10 10 10 30 30 30
38572 - 74 74 74 58 58 58 2 2 6 42 42 42
38573 - 2 2 6 22 22 22 231 231 231 253 253 253
38574 -253 253 253 253 253 253 253 253 253 253 253 253
38575 -253 253 253 253 253 253 253 253 253 250 250 250
38576 -253 253 253 253 253 253 253 253 253 253 253 253
38577 -253 253 253 253 253 253 253 253 253 253 253 253
38578 -253 253 253 253 253 253 253 253 253 253 253 253
38579 -253 253 253 253 253 253 253 253 253 253 253 253
38580 -253 253 253 246 246 246 46 46 46 38 38 38
38581 - 42 42 42 14 14 14 38 38 38 14 14 14
38582 - 2 2 6 2 2 6 2 2 6 6 6 6
38583 - 86 86 86 46 46 46 14 14 14 0 0 0
38584 - 0 0 0 0 0 0 0 0 0 0 0 0
38585 - 0 0 0 0 0 0 0 0 0 0 0 0
38586 - 0 0 0 0 0 0 0 0 0 0 0 0
38587 - 0 0 0 0 0 0 0 0 0 0 0 0
38588 - 0 0 0 0 0 0 0 0 0 0 0 0
38589 - 0 0 0 0 0 0 0 0 0 0 0 0
38590 - 0 0 0 0 0 0 0 0 0 0 0 0
38591 - 0 0 0 6 6 6 14 14 14 42 42 42
38592 - 90 90 90 18 18 18 18 18 18 26 26 26
38593 - 2 2 6 116 116 116 253 253 253 253 253 253
38594 -253 253 253 253 253 253 253 253 253 253 253 253
38595 -253 253 253 253 253 253 250 250 250 238 238 238
38596 -253 253 253 253 253 253 253 253 253 253 253 253
38597 -253 253 253 253 253 253 253 253 253 253 253 253
38598 -253 253 253 253 253 253 253 253 253 253 253 253
38599 -253 253 253 253 253 253 253 253 253 253 253 253
38600 -253 253 253 253 253 253 94 94 94 6 6 6
38601 - 2 2 6 2 2 6 10 10 10 34 34 34
38602 - 2 2 6 2 2 6 2 2 6 2 2 6
38603 - 74 74 74 58 58 58 22 22 22 6 6 6
38604 - 0 0 0 0 0 0 0 0 0 0 0 0
38605 - 0 0 0 0 0 0 0 0 0 0 0 0
38606 - 0 0 0 0 0 0 0 0 0 0 0 0
38607 - 0 0 0 0 0 0 0 0 0 0 0 0
38608 - 0 0 0 0 0 0 0 0 0 0 0 0
38609 - 0 0 0 0 0 0 0 0 0 0 0 0
38610 - 0 0 0 0 0 0 0 0 0 0 0 0
38611 - 0 0 0 10 10 10 26 26 26 66 66 66
38612 - 82 82 82 2 2 6 38 38 38 6 6 6
38613 - 14 14 14 210 210 210 253 253 253 253 253 253
38614 -253 253 253 253 253 253 253 253 253 253 253 253
38615 -253 253 253 253 253 253 246 246 246 242 242 242
38616 -253 253 253 253 253 253 253 253 253 253 253 253
38617 -253 253 253 253 253 253 253 253 253 253 253 253
38618 -253 253 253 253 253 253 253 253 253 253 253 253
38619 -253 253 253 253 253 253 253 253 253 253 253 253
38620 -253 253 253 253 253 253 144 144 144 2 2 6
38621 - 2 2 6 2 2 6 2 2 6 46 46 46
38622 - 2 2 6 2 2 6 2 2 6 2 2 6
38623 - 42 42 42 74 74 74 30 30 30 10 10 10
38624 - 0 0 0 0 0 0 0 0 0 0 0 0
38625 - 0 0 0 0 0 0 0 0 0 0 0 0
38626 - 0 0 0 0 0 0 0 0 0 0 0 0
38627 - 0 0 0 0 0 0 0 0 0 0 0 0
38628 - 0 0 0 0 0 0 0 0 0 0 0 0
38629 - 0 0 0 0 0 0 0 0 0 0 0 0
38630 - 0 0 0 0 0 0 0 0 0 0 0 0
38631 - 6 6 6 14 14 14 42 42 42 90 90 90
38632 - 26 26 26 6 6 6 42 42 42 2 2 6
38633 - 74 74 74 250 250 250 253 253 253 253 253 253
38634 -253 253 253 253 253 253 253 253 253 253 253 253
38635 -253 253 253 253 253 253 242 242 242 242 242 242
38636 -253 253 253 253 253 253 253 253 253 253 253 253
38637 -253 253 253 253 253 253 253 253 253 253 253 253
38638 -253 253 253 253 253 253 253 253 253 253 253 253
38639 -253 253 253 253 253 253 253 253 253 253 253 253
38640 -253 253 253 253 253 253 182 182 182 2 2 6
38641 - 2 2 6 2 2 6 2 2 6 46 46 46
38642 - 2 2 6 2 2 6 2 2 6 2 2 6
38643 - 10 10 10 86 86 86 38 38 38 10 10 10
38644 - 0 0 0 0 0 0 0 0 0 0 0 0
38645 - 0 0 0 0 0 0 0 0 0 0 0 0
38646 - 0 0 0 0 0 0 0 0 0 0 0 0
38647 - 0 0 0 0 0 0 0 0 0 0 0 0
38648 - 0 0 0 0 0 0 0 0 0 0 0 0
38649 - 0 0 0 0 0 0 0 0 0 0 0 0
38650 - 0 0 0 0 0 0 0 0 0 0 0 0
38651 - 10 10 10 26 26 26 66 66 66 82 82 82
38652 - 2 2 6 22 22 22 18 18 18 2 2 6
38653 -149 149 149 253 253 253 253 253 253 253 253 253
38654 -253 253 253 253 253 253 253 253 253 253 253 253
38655 -253 253 253 253 253 253 234 234 234 242 242 242
38656 -253 253 253 253 253 253 253 253 253 253 253 253
38657 -253 253 253 253 253 253 253 253 253 253 253 253
38658 -253 253 253 253 253 253 253 253 253 253 253 253
38659 -253 253 253 253 253 253 253 253 253 253 253 253
38660 -253 253 253 253 253 253 206 206 206 2 2 6
38661 - 2 2 6 2 2 6 2 2 6 38 38 38
38662 - 2 2 6 2 2 6 2 2 6 2 2 6
38663 - 6 6 6 86 86 86 46 46 46 14 14 14
38664 - 0 0 0 0 0 0 0 0 0 0 0 0
38665 - 0 0 0 0 0 0 0 0 0 0 0 0
38666 - 0 0 0 0 0 0 0 0 0 0 0 0
38667 - 0 0 0 0 0 0 0 0 0 0 0 0
38668 - 0 0 0 0 0 0 0 0 0 0 0 0
38669 - 0 0 0 0 0 0 0 0 0 0 0 0
38670 - 0 0 0 0 0 0 0 0 0 6 6 6
38671 - 18 18 18 46 46 46 86 86 86 18 18 18
38672 - 2 2 6 34 34 34 10 10 10 6 6 6
38673 -210 210 210 253 253 253 253 253 253 253 253 253
38674 -253 253 253 253 253 253 253 253 253 253 253 253
38675 -253 253 253 253 253 253 234 234 234 242 242 242
38676 -253 253 253 253 253 253 253 253 253 253 253 253
38677 -253 253 253 253 253 253 253 253 253 253 253 253
38678 -253 253 253 253 253 253 253 253 253 253 253 253
38679 -253 253 253 253 253 253 253 253 253 253 253 253
38680 -253 253 253 253 253 253 221 221 221 6 6 6
38681 - 2 2 6 2 2 6 6 6 6 30 30 30
38682 - 2 2 6 2 2 6 2 2 6 2 2 6
38683 - 2 2 6 82 82 82 54 54 54 18 18 18
38684 - 6 6 6 0 0 0 0 0 0 0 0 0
38685 - 0 0 0 0 0 0 0 0 0 0 0 0
38686 - 0 0 0 0 0 0 0 0 0 0 0 0
38687 - 0 0 0 0 0 0 0 0 0 0 0 0
38688 - 0 0 0 0 0 0 0 0 0 0 0 0
38689 - 0 0 0 0 0 0 0 0 0 0 0 0
38690 - 0 0 0 0 0 0 0 0 0 10 10 10
38691 - 26 26 26 66 66 66 62 62 62 2 2 6
38692 - 2 2 6 38 38 38 10 10 10 26 26 26
38693 -238 238 238 253 253 253 253 253 253 253 253 253
38694 -253 253 253 253 253 253 253 253 253 253 253 253
38695 -253 253 253 253 253 253 231 231 231 238 238 238
38696 -253 253 253 253 253 253 253 253 253 253 253 253
38697 -253 253 253 253 253 253 253 253 253 253 253 253
38698 -253 253 253 253 253 253 253 253 253 253 253 253
38699 -253 253 253 253 253 253 253 253 253 253 253 253
38700 -253 253 253 253 253 253 231 231 231 6 6 6
38701 - 2 2 6 2 2 6 10 10 10 30 30 30
38702 - 2 2 6 2 2 6 2 2 6 2 2 6
38703 - 2 2 6 66 66 66 58 58 58 22 22 22
38704 - 6 6 6 0 0 0 0 0 0 0 0 0
38705 - 0 0 0 0 0 0 0 0 0 0 0 0
38706 - 0 0 0 0 0 0 0 0 0 0 0 0
38707 - 0 0 0 0 0 0 0 0 0 0 0 0
38708 - 0 0 0 0 0 0 0 0 0 0 0 0
38709 - 0 0 0 0 0 0 0 0 0 0 0 0
38710 - 0 0 0 0 0 0 0 0 0 10 10 10
38711 - 38 38 38 78 78 78 6 6 6 2 2 6
38712 - 2 2 6 46 46 46 14 14 14 42 42 42
38713 -246 246 246 253 253 253 253 253 253 253 253 253
38714 -253 253 253 253 253 253 253 253 253 253 253 253
38715 -253 253 253 253 253 253 231 231 231 242 242 242
38716 -253 253 253 253 253 253 253 253 253 253 253 253
38717 -253 253 253 253 253 253 253 253 253 253 253 253
38718 -253 253 253 253 253 253 253 253 253 253 253 253
38719 -253 253 253 253 253 253 253 253 253 253 253 253
38720 -253 253 253 253 253 253 234 234 234 10 10 10
38721 - 2 2 6 2 2 6 22 22 22 14 14 14
38722 - 2 2 6 2 2 6 2 2 6 2 2 6
38723 - 2 2 6 66 66 66 62 62 62 22 22 22
38724 - 6 6 6 0 0 0 0 0 0 0 0 0
38725 - 0 0 0 0 0 0 0 0 0 0 0 0
38726 - 0 0 0 0 0 0 0 0 0 0 0 0
38727 - 0 0 0 0 0 0 0 0 0 0 0 0
38728 - 0 0 0 0 0 0 0 0 0 0 0 0
38729 - 0 0 0 0 0 0 0 0 0 0 0 0
38730 - 0 0 0 0 0 0 6 6 6 18 18 18
38731 - 50 50 50 74 74 74 2 2 6 2 2 6
38732 - 14 14 14 70 70 70 34 34 34 62 62 62
38733 -250 250 250 253 253 253 253 253 253 253 253 253
38734 -253 253 253 253 253 253 253 253 253 253 253 253
38735 -253 253 253 253 253 253 231 231 231 246 246 246
38736 -253 253 253 253 253 253 253 253 253 253 253 253
38737 -253 253 253 253 253 253 253 253 253 253 253 253
38738 -253 253 253 253 253 253 253 253 253 253 253 253
38739 -253 253 253 253 253 253 253 253 253 253 253 253
38740 -253 253 253 253 253 253 234 234 234 14 14 14
38741 - 2 2 6 2 2 6 30 30 30 2 2 6
38742 - 2 2 6 2 2 6 2 2 6 2 2 6
38743 - 2 2 6 66 66 66 62 62 62 22 22 22
38744 - 6 6 6 0 0 0 0 0 0 0 0 0
38745 - 0 0 0 0 0 0 0 0 0 0 0 0
38746 - 0 0 0 0 0 0 0 0 0 0 0 0
38747 - 0 0 0 0 0 0 0 0 0 0 0 0
38748 - 0 0 0 0 0 0 0 0 0 0 0 0
38749 - 0 0 0 0 0 0 0 0 0 0 0 0
38750 - 0 0 0 0 0 0 6 6 6 18 18 18
38751 - 54 54 54 62 62 62 2 2 6 2 2 6
38752 - 2 2 6 30 30 30 46 46 46 70 70 70
38753 -250 250 250 253 253 253 253 253 253 253 253 253
38754 -253 253 253 253 253 253 253 253 253 253 253 253
38755 -253 253 253 253 253 253 231 231 231 246 246 246
38756 -253 253 253 253 253 253 253 253 253 253 253 253
38757 -253 253 253 253 253 253 253 253 253 253 253 253
38758 -253 253 253 253 253 253 253 253 253 253 253 253
38759 -253 253 253 253 253 253 253 253 253 253 253 253
38760 -253 253 253 253 253 253 226 226 226 10 10 10
38761 - 2 2 6 6 6 6 30 30 30 2 2 6
38762 - 2 2 6 2 2 6 2 2 6 2 2 6
38763 - 2 2 6 66 66 66 58 58 58 22 22 22
38764 - 6 6 6 0 0 0 0 0 0 0 0 0
38765 - 0 0 0 0 0 0 0 0 0 0 0 0
38766 - 0 0 0 0 0 0 0 0 0 0 0 0
38767 - 0 0 0 0 0 0 0 0 0 0 0 0
38768 - 0 0 0 0 0 0 0 0 0 0 0 0
38769 - 0 0 0 0 0 0 0 0 0 0 0 0
38770 - 0 0 0 0 0 0 6 6 6 22 22 22
38771 - 58 58 58 62 62 62 2 2 6 2 2 6
38772 - 2 2 6 2 2 6 30 30 30 78 78 78
38773 -250 250 250 253 253 253 253 253 253 253 253 253
38774 -253 253 253 253 253 253 253 253 253 253 253 253
38775 -253 253 253 253 253 253 231 231 231 246 246 246
38776 -253 253 253 253 253 253 253 253 253 253 253 253
38777 -253 253 253 253 253 253 253 253 253 253 253 253
38778 -253 253 253 253 253 253 253 253 253 253 253 253
38779 -253 253 253 253 253 253 253 253 253 253 253 253
38780 -253 253 253 253 253 253 206 206 206 2 2 6
38781 - 22 22 22 34 34 34 18 14 6 22 22 22
38782 - 26 26 26 18 18 18 6 6 6 2 2 6
38783 - 2 2 6 82 82 82 54 54 54 18 18 18
38784 - 6 6 6 0 0 0 0 0 0 0 0 0
38785 - 0 0 0 0 0 0 0 0 0 0 0 0
38786 - 0 0 0 0 0 0 0 0 0 0 0 0
38787 - 0 0 0 0 0 0 0 0 0 0 0 0
38788 - 0 0 0 0 0 0 0 0 0 0 0 0
38789 - 0 0 0 0 0 0 0 0 0 0 0 0
38790 - 0 0 0 0 0 0 6 6 6 26 26 26
38791 - 62 62 62 106 106 106 74 54 14 185 133 11
38792 -210 162 10 121 92 8 6 6 6 62 62 62
38793 -238 238 238 253 253 253 253 253 253 253 253 253
38794 -253 253 253 253 253 253 253 253 253 253 253 253
38795 -253 253 253 253 253 253 231 231 231 246 246 246
38796 -253 253 253 253 253 253 253 253 253 253 253 253
38797 -253 253 253 253 253 253 253 253 253 253 253 253
38798 -253 253 253 253 253 253 253 253 253 253 253 253
38799 -253 253 253 253 253 253 253 253 253 253 253 253
38800 -253 253 253 253 253 253 158 158 158 18 18 18
38801 - 14 14 14 2 2 6 2 2 6 2 2 6
38802 - 6 6 6 18 18 18 66 66 66 38 38 38
38803 - 6 6 6 94 94 94 50 50 50 18 18 18
38804 - 6 6 6 0 0 0 0 0 0 0 0 0
38805 - 0 0 0 0 0 0 0 0 0 0 0 0
38806 - 0 0 0 0 0 0 0 0 0 0 0 0
38807 - 0 0 0 0 0 0 0 0 0 0 0 0
38808 - 0 0 0 0 0 0 0 0 0 0 0 0
38809 - 0 0 0 0 0 0 0 0 0 6 6 6
38810 - 10 10 10 10 10 10 18 18 18 38 38 38
38811 - 78 78 78 142 134 106 216 158 10 242 186 14
38812 -246 190 14 246 190 14 156 118 10 10 10 10
38813 - 90 90 90 238 238 238 253 253 253 253 253 253
38814 -253 253 253 253 253 253 253 253 253 253 253 253
38815 -253 253 253 253 253 253 231 231 231 250 250 250
38816 -253 253 253 253 253 253 253 253 253 253 253 253
38817 -253 253 253 253 253 253 253 253 253 253 253 253
38818 -253 253 253 253 253 253 253 253 253 253 253 253
38819 -253 253 253 253 253 253 253 253 253 246 230 190
38820 -238 204 91 238 204 91 181 142 44 37 26 9
38821 - 2 2 6 2 2 6 2 2 6 2 2 6
38822 - 2 2 6 2 2 6 38 38 38 46 46 46
38823 - 26 26 26 106 106 106 54 54 54 18 18 18
38824 - 6 6 6 0 0 0 0 0 0 0 0 0
38825 - 0 0 0 0 0 0 0 0 0 0 0 0
38826 - 0 0 0 0 0 0 0 0 0 0 0 0
38827 - 0 0 0 0 0 0 0 0 0 0 0 0
38828 - 0 0 0 0 0 0 0 0 0 0 0 0
38829 - 0 0 0 6 6 6 14 14 14 22 22 22
38830 - 30 30 30 38 38 38 50 50 50 70 70 70
38831 -106 106 106 190 142 34 226 170 11 242 186 14
38832 -246 190 14 246 190 14 246 190 14 154 114 10
38833 - 6 6 6 74 74 74 226 226 226 253 253 253
38834 -253 253 253 253 253 253 253 253 253 253 253 253
38835 -253 253 253 253 253 253 231 231 231 250 250 250
38836 -253 253 253 253 253 253 253 253 253 253 253 253
38837 -253 253 253 253 253 253 253 253 253 253 253 253
38838 -253 253 253 253 253 253 253 253 253 253 253 253
38839 -253 253 253 253 253 253 253 253 253 228 184 62
38840 -241 196 14 241 208 19 232 195 16 38 30 10
38841 - 2 2 6 2 2 6 2 2 6 2 2 6
38842 - 2 2 6 6 6 6 30 30 30 26 26 26
38843 -203 166 17 154 142 90 66 66 66 26 26 26
38844 - 6 6 6 0 0 0 0 0 0 0 0 0
38845 - 0 0 0 0 0 0 0 0 0 0 0 0
38846 - 0 0 0 0 0 0 0 0 0 0 0 0
38847 - 0 0 0 0 0 0 0 0 0 0 0 0
38848 - 0 0 0 0 0 0 0 0 0 0 0 0
38849 - 6 6 6 18 18 18 38 38 38 58 58 58
38850 - 78 78 78 86 86 86 101 101 101 123 123 123
38851 -175 146 61 210 150 10 234 174 13 246 186 14
38852 -246 190 14 246 190 14 246 190 14 238 190 10
38853 -102 78 10 2 2 6 46 46 46 198 198 198
38854 -253 253 253 253 253 253 253 253 253 253 253 253
38855 -253 253 253 253 253 253 234 234 234 242 242 242
38856 -253 253 253 253 253 253 253 253 253 253 253 253
38857 -253 253 253 253 253 253 253 253 253 253 253 253
38858 -253 253 253 253 253 253 253 253 253 253 253 253
38859 -253 253 253 253 253 253 253 253 253 224 178 62
38860 -242 186 14 241 196 14 210 166 10 22 18 6
38861 - 2 2 6 2 2 6 2 2 6 2 2 6
38862 - 2 2 6 2 2 6 6 6 6 121 92 8
38863 -238 202 15 232 195 16 82 82 82 34 34 34
38864 - 10 10 10 0 0 0 0 0 0 0 0 0
38865 - 0 0 0 0 0 0 0 0 0 0 0 0
38866 - 0 0 0 0 0 0 0 0 0 0 0 0
38867 - 0 0 0 0 0 0 0 0 0 0 0 0
38868 - 0 0 0 0 0 0 0 0 0 0 0 0
38869 - 14 14 14 38 38 38 70 70 70 154 122 46
38870 -190 142 34 200 144 11 197 138 11 197 138 11
38871 -213 154 11 226 170 11 242 186 14 246 190 14
38872 -246 190 14 246 190 14 246 190 14 246 190 14
38873 -225 175 15 46 32 6 2 2 6 22 22 22
38874 -158 158 158 250 250 250 253 253 253 253 253 253
38875 -253 253 253 253 253 253 253 253 253 253 253 253
38876 -253 253 253 253 253 253 253 253 253 253 253 253
38877 -253 253 253 253 253 253 253 253 253 253 253 253
38878 -253 253 253 253 253 253 253 253 253 253 253 253
38879 -253 253 253 250 250 250 242 242 242 224 178 62
38880 -239 182 13 236 186 11 213 154 11 46 32 6
38881 - 2 2 6 2 2 6 2 2 6 2 2 6
38882 - 2 2 6 2 2 6 61 42 6 225 175 15
38883 -238 190 10 236 186 11 112 100 78 42 42 42
38884 - 14 14 14 0 0 0 0 0 0 0 0 0
38885 - 0 0 0 0 0 0 0 0 0 0 0 0
38886 - 0 0 0 0 0 0 0 0 0 0 0 0
38887 - 0 0 0 0 0 0 0 0 0 0 0 0
38888 - 0 0 0 0 0 0 0 0 0 6 6 6
38889 - 22 22 22 54 54 54 154 122 46 213 154 11
38890 -226 170 11 230 174 11 226 170 11 226 170 11
38891 -236 178 12 242 186 14 246 190 14 246 190 14
38892 -246 190 14 246 190 14 246 190 14 246 190 14
38893 -241 196 14 184 144 12 10 10 10 2 2 6
38894 - 6 6 6 116 116 116 242 242 242 253 253 253
38895 -253 253 253 253 253 253 253 253 253 253 253 253
38896 -253 253 253 253 253 253 253 253 253 253 253 253
38897 -253 253 253 253 253 253 253 253 253 253 253 253
38898 -253 253 253 253 253 253 253 253 253 253 253 253
38899 -253 253 253 231 231 231 198 198 198 214 170 54
38900 -236 178 12 236 178 12 210 150 10 137 92 6
38901 - 18 14 6 2 2 6 2 2 6 2 2 6
38902 - 6 6 6 70 47 6 200 144 11 236 178 12
38903 -239 182 13 239 182 13 124 112 88 58 58 58
38904 - 22 22 22 6 6 6 0 0 0 0 0 0
38905 - 0 0 0 0 0 0 0 0 0 0 0 0
38906 - 0 0 0 0 0 0 0 0 0 0 0 0
38907 - 0 0 0 0 0 0 0 0 0 0 0 0
38908 - 0 0 0 0 0 0 0 0 0 10 10 10
38909 - 30 30 30 70 70 70 180 133 36 226 170 11
38910 -239 182 13 242 186 14 242 186 14 246 186 14
38911 -246 190 14 246 190 14 246 190 14 246 190 14
38912 -246 190 14 246 190 14 246 190 14 246 190 14
38913 -246 190 14 232 195 16 98 70 6 2 2 6
38914 - 2 2 6 2 2 6 66 66 66 221 221 221
38915 -253 253 253 253 253 253 253 253 253 253 253 253
38916 -253 253 253 253 253 253 253 253 253 253 253 253
38917 -253 253 253 253 253 253 253 253 253 253 253 253
38918 -253 253 253 253 253 253 253 253 253 253 253 253
38919 -253 253 253 206 206 206 198 198 198 214 166 58
38920 -230 174 11 230 174 11 216 158 10 192 133 9
38921 -163 110 8 116 81 8 102 78 10 116 81 8
38922 -167 114 7 197 138 11 226 170 11 239 182 13
38923 -242 186 14 242 186 14 162 146 94 78 78 78
38924 - 34 34 34 14 14 14 6 6 6 0 0 0
38925 - 0 0 0 0 0 0 0 0 0 0 0 0
38926 - 0 0 0 0 0 0 0 0 0 0 0 0
38927 - 0 0 0 0 0 0 0 0 0 0 0 0
38928 - 0 0 0 0 0 0 0 0 0 6 6 6
38929 - 30 30 30 78 78 78 190 142 34 226 170 11
38930 -239 182 13 246 190 14 246 190 14 246 190 14
38931 -246 190 14 246 190 14 246 190 14 246 190 14
38932 -246 190 14 246 190 14 246 190 14 246 190 14
38933 -246 190 14 241 196 14 203 166 17 22 18 6
38934 - 2 2 6 2 2 6 2 2 6 38 38 38
38935 -218 218 218 253 253 253 253 253 253 253 253 253
38936 -253 253 253 253 253 253 253 253 253 253 253 253
38937 -253 253 253 253 253 253 253 253 253 253 253 253
38938 -253 253 253 253 253 253 253 253 253 253 253 253
38939 -250 250 250 206 206 206 198 198 198 202 162 69
38940 -226 170 11 236 178 12 224 166 10 210 150 10
38941 -200 144 11 197 138 11 192 133 9 197 138 11
38942 -210 150 10 226 170 11 242 186 14 246 190 14
38943 -246 190 14 246 186 14 225 175 15 124 112 88
38944 - 62 62 62 30 30 30 14 14 14 6 6 6
38945 - 0 0 0 0 0 0 0 0 0 0 0 0
38946 - 0 0 0 0 0 0 0 0 0 0 0 0
38947 - 0 0 0 0 0 0 0 0 0 0 0 0
38948 - 0 0 0 0 0 0 0 0 0 10 10 10
38949 - 30 30 30 78 78 78 174 135 50 224 166 10
38950 -239 182 13 246 190 14 246 190 14 246 190 14
38951 -246 190 14 246 190 14 246 190 14 246 190 14
38952 -246 190 14 246 190 14 246 190 14 246 190 14
38953 -246 190 14 246 190 14 241 196 14 139 102 15
38954 - 2 2 6 2 2 6 2 2 6 2 2 6
38955 - 78 78 78 250 250 250 253 253 253 253 253 253
38956 -253 253 253 253 253 253 253 253 253 253 253 253
38957 -253 253 253 253 253 253 253 253 253 253 253 253
38958 -253 253 253 253 253 253 253 253 253 253 253 253
38959 -250 250 250 214 214 214 198 198 198 190 150 46
38960 -219 162 10 236 178 12 234 174 13 224 166 10
38961 -216 158 10 213 154 11 213 154 11 216 158 10
38962 -226 170 11 239 182 13 246 190 14 246 190 14
38963 -246 190 14 246 190 14 242 186 14 206 162 42
38964 -101 101 101 58 58 58 30 30 30 14 14 14
38965 - 6 6 6 0 0 0 0 0 0 0 0 0
38966 - 0 0 0 0 0 0 0 0 0 0 0 0
38967 - 0 0 0 0 0 0 0 0 0 0 0 0
38968 - 0 0 0 0 0 0 0 0 0 10 10 10
38969 - 30 30 30 74 74 74 174 135 50 216 158 10
38970 -236 178 12 246 190 14 246 190 14 246 190 14
38971 -246 190 14 246 190 14 246 190 14 246 190 14
38972 -246 190 14 246 190 14 246 190 14 246 190 14
38973 -246 190 14 246 190 14 241 196 14 226 184 13
38974 - 61 42 6 2 2 6 2 2 6 2 2 6
38975 - 22 22 22 238 238 238 253 253 253 253 253 253
38976 -253 253 253 253 253 253 253 253 253 253 253 253
38977 -253 253 253 253 253 253 253 253 253 253 253 253
38978 -253 253 253 253 253 253 253 253 253 253 253 253
38979 -253 253 253 226 226 226 187 187 187 180 133 36
38980 -216 158 10 236 178 12 239 182 13 236 178 12
38981 -230 174 11 226 170 11 226 170 11 230 174 11
38982 -236 178 12 242 186 14 246 190 14 246 190 14
38983 -246 190 14 246 190 14 246 186 14 239 182 13
38984 -206 162 42 106 106 106 66 66 66 34 34 34
38985 - 14 14 14 6 6 6 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 6 6 6
38989 - 26 26 26 70 70 70 163 133 67 213 154 11
38990 -236 178 12 246 190 14 246 190 14 246 190 14
38991 -246 190 14 246 190 14 246 190 14 246 190 14
38992 -246 190 14 246 190 14 246 190 14 246 190 14
38993 -246 190 14 246 190 14 246 190 14 241 196 14
38994 -190 146 13 18 14 6 2 2 6 2 2 6
38995 - 46 46 46 246 246 246 253 253 253 253 253 253
38996 -253 253 253 253 253 253 253 253 253 253 253 253
38997 -253 253 253 253 253 253 253 253 253 253 253 253
38998 -253 253 253 253 253 253 253 253 253 253 253 253
38999 -253 253 253 221 221 221 86 86 86 156 107 11
39000 -216 158 10 236 178 12 242 186 14 246 186 14
39001 -242 186 14 239 182 13 239 182 13 242 186 14
39002 -242 186 14 246 186 14 246 190 14 246 190 14
39003 -246 190 14 246 190 14 246 190 14 246 190 14
39004 -242 186 14 225 175 15 142 122 72 66 66 66
39005 - 30 30 30 10 10 10 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 6 6 6
39009 - 26 26 26 70 70 70 163 133 67 210 150 10
39010 -236 178 12 246 190 14 246 190 14 246 190 14
39011 -246 190 14 246 190 14 246 190 14 246 190 14
39012 -246 190 14 246 190 14 246 190 14 246 190 14
39013 -246 190 14 246 190 14 246 190 14 246 190 14
39014 -232 195 16 121 92 8 34 34 34 106 106 106
39015 -221 221 221 253 253 253 253 253 253 253 253 253
39016 -253 253 253 253 253 253 253 253 253 253 253 253
39017 -253 253 253 253 253 253 253 253 253 253 253 253
39018 -253 253 253 253 253 253 253 253 253 253 253 253
39019 -242 242 242 82 82 82 18 14 6 163 110 8
39020 -216 158 10 236 178 12 242 186 14 246 190 14
39021 -246 190 14 246 190 14 246 190 14 246 190 14
39022 -246 190 14 246 190 14 246 190 14 246 190 14
39023 -246 190 14 246 190 14 246 190 14 246 190 14
39024 -246 190 14 246 190 14 242 186 14 163 133 67
39025 - 46 46 46 18 18 18 6 6 6 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 10 10 10
39029 - 30 30 30 78 78 78 163 133 67 210 150 10
39030 -236 178 12 246 186 14 246 190 14 246 190 14
39031 -246 190 14 246 190 14 246 190 14 246 190 14
39032 -246 190 14 246 190 14 246 190 14 246 190 14
39033 -246 190 14 246 190 14 246 190 14 246 190 14
39034 -241 196 14 215 174 15 190 178 144 253 253 253
39035 -253 253 253 253 253 253 253 253 253 253 253 253
39036 -253 253 253 253 253 253 253 253 253 253 253 253
39037 -253 253 253 253 253 253 253 253 253 253 253 253
39038 -253 253 253 253 253 253 253 253 253 218 218 218
39039 - 58 58 58 2 2 6 22 18 6 167 114 7
39040 -216 158 10 236 178 12 246 186 14 246 190 14
39041 -246 190 14 246 190 14 246 190 14 246 190 14
39042 -246 190 14 246 190 14 246 190 14 246 190 14
39043 -246 190 14 246 190 14 246 190 14 246 190 14
39044 -246 190 14 246 186 14 242 186 14 190 150 46
39045 - 54 54 54 22 22 22 6 6 6 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 14 14 14
39049 - 38 38 38 86 86 86 180 133 36 213 154 11
39050 -236 178 12 246 186 14 246 190 14 246 190 14
39051 -246 190 14 246 190 14 246 190 14 246 190 14
39052 -246 190 14 246 190 14 246 190 14 246 190 14
39053 -246 190 14 246 190 14 246 190 14 246 190 14
39054 -246 190 14 232 195 16 190 146 13 214 214 214
39055 -253 253 253 253 253 253 253 253 253 253 253 253
39056 -253 253 253 253 253 253 253 253 253 253 253 253
39057 -253 253 253 253 253 253 253 253 253 253 253 253
39058 -253 253 253 250 250 250 170 170 170 26 26 26
39059 - 2 2 6 2 2 6 37 26 9 163 110 8
39060 -219 162 10 239 182 13 246 186 14 246 190 14
39061 -246 190 14 246 190 14 246 190 14 246 190 14
39062 -246 190 14 246 190 14 246 190 14 246 190 14
39063 -246 190 14 246 190 14 246 190 14 246 190 14
39064 -246 186 14 236 178 12 224 166 10 142 122 72
39065 - 46 46 46 18 18 18 6 6 6 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 6 6 6 18 18 18
39069 - 50 50 50 109 106 95 192 133 9 224 166 10
39070 -242 186 14 246 190 14 246 190 14 246 190 14
39071 -246 190 14 246 190 14 246 190 14 246 190 14
39072 -246 190 14 246 190 14 246 190 14 246 190 14
39073 -246 190 14 246 190 14 246 190 14 246 190 14
39074 -242 186 14 226 184 13 210 162 10 142 110 46
39075 -226 226 226 253 253 253 253 253 253 253 253 253
39076 -253 253 253 253 253 253 253 253 253 253 253 253
39077 -253 253 253 253 253 253 253 253 253 253 253 253
39078 -198 198 198 66 66 66 2 2 6 2 2 6
39079 - 2 2 6 2 2 6 50 34 6 156 107 11
39080 -219 162 10 239 182 13 246 186 14 246 190 14
39081 -246 190 14 246 190 14 246 190 14 246 190 14
39082 -246 190 14 246 190 14 246 190 14 246 190 14
39083 -246 190 14 246 190 14 246 190 14 242 186 14
39084 -234 174 13 213 154 11 154 122 46 66 66 66
39085 - 30 30 30 10 10 10 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 6 6 6 22 22 22
39089 - 58 58 58 154 121 60 206 145 10 234 174 13
39090 -242 186 14 246 186 14 246 190 14 246 190 14
39091 -246 190 14 246 190 14 246 190 14 246 190 14
39092 -246 190 14 246 190 14 246 190 14 246 190 14
39093 -246 190 14 246 190 14 246 190 14 246 190 14
39094 -246 186 14 236 178 12 210 162 10 163 110 8
39095 - 61 42 6 138 138 138 218 218 218 250 250 250
39096 -253 253 253 253 253 253 253 253 253 250 250 250
39097 -242 242 242 210 210 210 144 144 144 66 66 66
39098 - 6 6 6 2 2 6 2 2 6 2 2 6
39099 - 2 2 6 2 2 6 61 42 6 163 110 8
39100 -216 158 10 236 178 12 246 190 14 246 190 14
39101 -246 190 14 246 190 14 246 190 14 246 190 14
39102 -246 190 14 246 190 14 246 190 14 246 190 14
39103 -246 190 14 239 182 13 230 174 11 216 158 10
39104 -190 142 34 124 112 88 70 70 70 38 38 38
39105 - 18 18 18 6 6 6 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 6 6 6 22 22 22
39109 - 62 62 62 168 124 44 206 145 10 224 166 10
39110 -236 178 12 239 182 13 242 186 14 242 186 14
39111 -246 186 14 246 190 14 246 190 14 246 190 14
39112 -246 190 14 246 190 14 246 190 14 246 190 14
39113 -246 190 14 246 190 14 246 190 14 246 190 14
39114 -246 190 14 236 178 12 216 158 10 175 118 6
39115 - 80 54 7 2 2 6 6 6 6 30 30 30
39116 - 54 54 54 62 62 62 50 50 50 38 38 38
39117 - 14 14 14 2 2 6 2 2 6 2 2 6
39118 - 2 2 6 2 2 6 2 2 6 2 2 6
39119 - 2 2 6 6 6 6 80 54 7 167 114 7
39120 -213 154 11 236 178 12 246 190 14 246 190 14
39121 -246 190 14 246 190 14 246 190 14 246 190 14
39122 -246 190 14 242 186 14 239 182 13 239 182 13
39123 -230 174 11 210 150 10 174 135 50 124 112 88
39124 - 82 82 82 54 54 54 34 34 34 18 18 18
39125 - 6 6 6 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 6 6 6 18 18 18
39129 - 50 50 50 158 118 36 192 133 9 200 144 11
39130 -216 158 10 219 162 10 224 166 10 226 170 11
39131 -230 174 11 236 178 12 239 182 13 239 182 13
39132 -242 186 14 246 186 14 246 190 14 246 190 14
39133 -246 190 14 246 190 14 246 190 14 246 190 14
39134 -246 186 14 230 174 11 210 150 10 163 110 8
39135 -104 69 6 10 10 10 2 2 6 2 2 6
39136 - 2 2 6 2 2 6 2 2 6 2 2 6
39137 - 2 2 6 2 2 6 2 2 6 2 2 6
39138 - 2 2 6 2 2 6 2 2 6 2 2 6
39139 - 2 2 6 6 6 6 91 60 6 167 114 7
39140 -206 145 10 230 174 11 242 186 14 246 190 14
39141 -246 190 14 246 190 14 246 186 14 242 186 14
39142 -239 182 13 230 174 11 224 166 10 213 154 11
39143 -180 133 36 124 112 88 86 86 86 58 58 58
39144 - 38 38 38 22 22 22 10 10 10 6 6 6
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 14 14 14
39149 - 34 34 34 70 70 70 138 110 50 158 118 36
39150 -167 114 7 180 123 7 192 133 9 197 138 11
39151 -200 144 11 206 145 10 213 154 11 219 162 10
39152 -224 166 10 230 174 11 239 182 13 242 186 14
39153 -246 186 14 246 186 14 246 186 14 246 186 14
39154 -239 182 13 216 158 10 185 133 11 152 99 6
39155 -104 69 6 18 14 6 2 2 6 2 2 6
39156 - 2 2 6 2 2 6 2 2 6 2 2 6
39157 - 2 2 6 2 2 6 2 2 6 2 2 6
39158 - 2 2 6 2 2 6 2 2 6 2 2 6
39159 - 2 2 6 6 6 6 80 54 7 152 99 6
39160 -192 133 9 219 162 10 236 178 12 239 182 13
39161 -246 186 14 242 186 14 239 182 13 236 178 12
39162 -224 166 10 206 145 10 192 133 9 154 121 60
39163 - 94 94 94 62 62 62 42 42 42 22 22 22
39164 - 14 14 14 6 6 6 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 - 18 18 18 34 34 34 58 58 58 78 78 78
39170 -101 98 89 124 112 88 142 110 46 156 107 11
39171 -163 110 8 167 114 7 175 118 6 180 123 7
39172 -185 133 11 197 138 11 210 150 10 219 162 10
39173 -226 170 11 236 178 12 236 178 12 234 174 13
39174 -219 162 10 197 138 11 163 110 8 130 83 6
39175 - 91 60 6 10 10 10 2 2 6 2 2 6
39176 - 18 18 18 38 38 38 38 38 38 38 38 38
39177 - 38 38 38 38 38 38 38 38 38 38 38 38
39178 - 38 38 38 38 38 38 26 26 26 2 2 6
39179 - 2 2 6 6 6 6 70 47 6 137 92 6
39180 -175 118 6 200 144 11 219 162 10 230 174 11
39181 -234 174 13 230 174 11 219 162 10 210 150 10
39182 -192 133 9 163 110 8 124 112 88 82 82 82
39183 - 50 50 50 30 30 30 14 14 14 6 6 6
39184 - 0 0 0 0 0 0 0 0 0 0 0 0
39185 - 0 0 0 0 0 0 0 0 0 0 0 0
39186 - 0 0 0 0 0 0 0 0 0 0 0 0
39187 - 0 0 0 0 0 0 0 0 0 0 0 0
39188 - 0 0 0 0 0 0 0 0 0 0 0 0
39189 - 6 6 6 14 14 14 22 22 22 34 34 34
39190 - 42 42 42 58 58 58 74 74 74 86 86 86
39191 -101 98 89 122 102 70 130 98 46 121 87 25
39192 -137 92 6 152 99 6 163 110 8 180 123 7
39193 -185 133 11 197 138 11 206 145 10 200 144 11
39194 -180 123 7 156 107 11 130 83 6 104 69 6
39195 - 50 34 6 54 54 54 110 110 110 101 98 89
39196 - 86 86 86 82 82 82 78 78 78 78 78 78
39197 - 78 78 78 78 78 78 78 78 78 78 78 78
39198 - 78 78 78 82 82 82 86 86 86 94 94 94
39199 -106 106 106 101 101 101 86 66 34 124 80 6
39200 -156 107 11 180 123 7 192 133 9 200 144 11
39201 -206 145 10 200 144 11 192 133 9 175 118 6
39202 -139 102 15 109 106 95 70 70 70 42 42 42
39203 - 22 22 22 10 10 10 0 0 0 0 0 0
39204 - 0 0 0 0 0 0 0 0 0 0 0 0
39205 - 0 0 0 0 0 0 0 0 0 0 0 0
39206 - 0 0 0 0 0 0 0 0 0 0 0 0
39207 - 0 0 0 0 0 0 0 0 0 0 0 0
39208 - 0 0 0 0 0 0 0 0 0 0 0 0
39209 - 0 0 0 0 0 0 6 6 6 10 10 10
39210 - 14 14 14 22 22 22 30 30 30 38 38 38
39211 - 50 50 50 62 62 62 74 74 74 90 90 90
39212 -101 98 89 112 100 78 121 87 25 124 80 6
39213 -137 92 6 152 99 6 152 99 6 152 99 6
39214 -138 86 6 124 80 6 98 70 6 86 66 30
39215 -101 98 89 82 82 82 58 58 58 46 46 46
39216 - 38 38 38 34 34 34 34 34 34 34 34 34
39217 - 34 34 34 34 34 34 34 34 34 34 34 34
39218 - 34 34 34 34 34 34 38 38 38 42 42 42
39219 - 54 54 54 82 82 82 94 86 76 91 60 6
39220 -134 86 6 156 107 11 167 114 7 175 118 6
39221 -175 118 6 167 114 7 152 99 6 121 87 25
39222 -101 98 89 62 62 62 34 34 34 18 18 18
39223 - 6 6 6 0 0 0 0 0 0 0 0 0
39224 - 0 0 0 0 0 0 0 0 0 0 0 0
39225 - 0 0 0 0 0 0 0 0 0 0 0 0
39226 - 0 0 0 0 0 0 0 0 0 0 0 0
39227 - 0 0 0 0 0 0 0 0 0 0 0 0
39228 - 0 0 0 0 0 0 0 0 0 0 0 0
39229 - 0 0 0 0 0 0 0 0 0 0 0 0
39230 - 0 0 0 6 6 6 6 6 6 10 10 10
39231 - 18 18 18 22 22 22 30 30 30 42 42 42
39232 - 50 50 50 66 66 66 86 86 86 101 98 89
39233 -106 86 58 98 70 6 104 69 6 104 69 6
39234 -104 69 6 91 60 6 82 62 34 90 90 90
39235 - 62 62 62 38 38 38 22 22 22 14 14 14
39236 - 10 10 10 10 10 10 10 10 10 10 10 10
39237 - 10 10 10 10 10 10 6 6 6 10 10 10
39238 - 10 10 10 10 10 10 10 10 10 14 14 14
39239 - 22 22 22 42 42 42 70 70 70 89 81 66
39240 - 80 54 7 104 69 6 124 80 6 137 92 6
39241 -134 86 6 116 81 8 100 82 52 86 86 86
39242 - 58 58 58 30 30 30 14 14 14 6 6 6
39243 - 0 0 0 0 0 0 0 0 0 0 0 0
39244 - 0 0 0 0 0 0 0 0 0 0 0 0
39245 - 0 0 0 0 0 0 0 0 0 0 0 0
39246 - 0 0 0 0 0 0 0 0 0 0 0 0
39247 - 0 0 0 0 0 0 0 0 0 0 0 0
39248 - 0 0 0 0 0 0 0 0 0 0 0 0
39249 - 0 0 0 0 0 0 0 0 0 0 0 0
39250 - 0 0 0 0 0 0 0 0 0 0 0 0
39251 - 0 0 0 6 6 6 10 10 10 14 14 14
39252 - 18 18 18 26 26 26 38 38 38 54 54 54
39253 - 70 70 70 86 86 86 94 86 76 89 81 66
39254 - 89 81 66 86 86 86 74 74 74 50 50 50
39255 - 30 30 30 14 14 14 6 6 6 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 - 6 6 6 18 18 18 34 34 34 58 58 58
39260 - 82 82 82 89 81 66 89 81 66 89 81 66
39261 - 94 86 66 94 86 76 74 74 74 50 50 50
39262 - 26 26 26 14 14 14 6 6 6 0 0 0
39263 - 0 0 0 0 0 0 0 0 0 0 0 0
39264 - 0 0 0 0 0 0 0 0 0 0 0 0
39265 - 0 0 0 0 0 0 0 0 0 0 0 0
39266 - 0 0 0 0 0 0 0 0 0 0 0 0
39267 - 0 0 0 0 0 0 0 0 0 0 0 0
39268 - 0 0 0 0 0 0 0 0 0 0 0 0
39269 - 0 0 0 0 0 0 0 0 0 0 0 0
39270 - 0 0 0 0 0 0 0 0 0 0 0 0
39271 - 0 0 0 0 0 0 0 0 0 0 0 0
39272 - 6 6 6 6 6 6 14 14 14 18 18 18
39273 - 30 30 30 38 38 38 46 46 46 54 54 54
39274 - 50 50 50 42 42 42 30 30 30 18 18 18
39275 - 10 10 10 0 0 0 0 0 0 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 6 6 6 14 14 14 26 26 26
39280 - 38 38 38 50 50 50 58 58 58 58 58 58
39281 - 54 54 54 42 42 42 30 30 30 18 18 18
39282 - 10 10 10 0 0 0 0 0 0 0 0 0
39283 - 0 0 0 0 0 0 0 0 0 0 0 0
39284 - 0 0 0 0 0 0 0 0 0 0 0 0
39285 - 0 0 0 0 0 0 0 0 0 0 0 0
39286 - 0 0 0 0 0 0 0 0 0 0 0 0
39287 - 0 0 0 0 0 0 0 0 0 0 0 0
39288 - 0 0 0 0 0 0 0 0 0 0 0 0
39289 - 0 0 0 0 0 0 0 0 0 0 0 0
39290 - 0 0 0 0 0 0 0 0 0 0 0 0
39291 - 0 0 0 0 0 0 0 0 0 0 0 0
39292 - 0 0 0 0 0 0 0 0 0 6 6 6
39293 - 6 6 6 10 10 10 14 14 14 18 18 18
39294 - 18 18 18 14 14 14 10 10 10 6 6 6
39295 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
39300 - 14 14 14 18 18 18 22 22 22 22 22 22
39301 - 18 18 18 14 14 14 10 10 10 6 6 6
39302 - 0 0 0 0 0 0 0 0 0 0 0 0
39303 - 0 0 0 0 0 0 0 0 0 0 0 0
39304 - 0 0 0 0 0 0 0 0 0 0 0 0
39305 - 0 0 0 0 0 0 0 0 0 0 0 0
39306 - 0 0 0 0 0 0 0 0 0 0 0 0
39307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39318 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39319 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39320 +4 4 4 4 4 4
39321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39332 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39334 +4 4 4 4 4 4
39335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39348 +4 4 4 4 4 4
39349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39362 +4 4 4 4 4 4
39363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39376 +4 4 4 4 4 4
39377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39390 +4 4 4 4 4 4
39391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39392 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39395 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
39396 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
39397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39400 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
39401 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
39402 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
39403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39404 +4 4 4 4 4 4
39405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39406 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39409 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
39410 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
39411 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39414 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
39415 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
39416 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
39417 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39418 +4 4 4 4 4 4
39419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39420 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39421 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39422 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39423 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
39424 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
39425 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
39426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39428 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
39429 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
39430 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
39431 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
39432 +4 4 4 4 4 4
39433 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39434 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39436 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
39437 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
39438 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
39439 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
39440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39441 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
39442 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
39443 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
39444 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
39445 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
39446 +4 4 4 4 4 4
39447 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39448 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39450 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
39451 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
39452 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
39453 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
39454 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
39455 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
39456 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
39457 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
39458 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
39459 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
39460 +4 4 4 4 4 4
39461 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39462 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39463 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
39464 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
39465 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
39466 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
39467 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
39468 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
39469 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
39470 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
39471 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
39472 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
39473 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
39474 +4 4 4 4 4 4
39475 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39477 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
39478 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
39479 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
39480 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
39481 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
39482 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
39483 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
39484 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
39485 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
39486 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
39487 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
39488 +4 4 4 4 4 4
39489 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39491 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
39492 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
39493 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
39494 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
39495 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
39496 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
39497 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
39498 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
39499 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
39500 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
39501 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
39502 +4 4 4 4 4 4
39503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39504 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39505 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
39506 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
39507 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
39508 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
39509 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
39510 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
39511 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
39512 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
39513 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
39514 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
39515 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
39516 +4 4 4 4 4 4
39517 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39518 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39519 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
39520 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
39521 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
39522 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
39523 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
39524 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
39525 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
39526 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
39527 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
39528 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
39529 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
39530 +4 4 4 4 4 4
39531 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39532 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
39533 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
39534 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
39535 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
39536 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
39537 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
39538 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
39539 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
39540 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
39541 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
39542 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
39543 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
39544 +4 4 4 4 4 4
39545 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39546 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
39547 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
39548 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
39549 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
39550 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
39551 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
39552 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
39553 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
39554 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
39555 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
39556 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
39557 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
39558 +0 0 0 4 4 4
39559 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
39560 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
39561 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
39562 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
39563 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
39564 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
39565 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
39566 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
39567 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
39568 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
39569 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
39570 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
39571 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
39572 +2 0 0 0 0 0
39573 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
39574 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
39575 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
39576 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
39577 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
39578 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
39579 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
39580 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
39581 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
39582 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
39583 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
39584 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
39585 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
39586 +37 38 37 0 0 0
39587 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
39588 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
39589 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
39590 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
39591 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
39592 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
39593 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
39594 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
39595 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
39596 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
39597 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
39598 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
39599 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
39600 +85 115 134 4 0 0
39601 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
39602 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
39603 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
39604 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
39605 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
39606 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
39607 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
39608 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
39609 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
39610 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
39611 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
39612 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
39613 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
39614 +60 73 81 4 0 0
39615 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
39616 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
39617 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
39618 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
39619 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
39620 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
39621 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
39622 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
39623 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
39624 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
39625 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
39626 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
39627 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
39628 +16 19 21 4 0 0
39629 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
39630 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
39631 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
39632 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
39633 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
39634 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
39635 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
39636 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
39637 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
39638 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
39639 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
39640 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
39641 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
39642 +4 0 0 4 3 3
39643 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
39644 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
39645 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
39646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
39647 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
39648 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
39649 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
39650 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
39651 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
39652 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
39653 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
39654 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
39655 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
39656 +3 2 2 4 4 4
39657 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
39658 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
39659 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
39660 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
39661 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
39662 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
39663 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
39664 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
39665 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
39666 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
39667 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
39668 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
39669 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
39670 +4 4 4 4 4 4
39671 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
39672 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
39673 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
39674 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
39675 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
39676 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
39677 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
39678 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
39679 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
39680 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
39681 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
39682 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
39683 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
39684 +4 4 4 4 4 4
39685 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
39686 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
39687 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
39688 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
39689 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
39690 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
39691 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
39692 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
39693 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
39694 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
39695 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
39696 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
39697 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
39698 +5 5 5 5 5 5
39699 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
39700 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
39701 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
39702 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
39703 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
39704 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
39705 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
39706 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
39707 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
39708 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
39709 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
39710 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
39711 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
39712 +5 5 5 4 4 4
39713 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
39714 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
39715 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
39716 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
39717 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
39718 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
39719 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
39720 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
39721 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
39722 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
39723 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
39724 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
39725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39726 +4 4 4 4 4 4
39727 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
39728 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
39729 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
39730 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
39731 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
39732 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
39733 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
39734 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
39735 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
39736 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
39737 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
39738 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
39739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39740 +4 4 4 4 4 4
39741 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
39742 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
39743 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
39744 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
39745 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
39746 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
39747 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
39748 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
39749 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
39750 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
39751 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
39752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39754 +4 4 4 4 4 4
39755 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
39756 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
39757 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
39758 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
39759 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
39760 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
39761 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
39762 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
39763 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
39764 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
39765 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
39766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39768 +4 4 4 4 4 4
39769 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
39770 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
39771 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
39772 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
39773 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
39774 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
39775 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
39776 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
39777 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
39778 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
39779 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39781 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39782 +4 4 4 4 4 4
39783 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
39784 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
39785 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
39786 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
39787 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
39788 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
39789 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
39790 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
39791 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
39792 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
39793 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
39794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39795 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39796 +4 4 4 4 4 4
39797 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
39798 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
39799 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
39800 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
39801 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
39802 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
39803 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
39804 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
39805 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
39806 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
39807 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
39808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39809 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39810 +4 4 4 4 4 4
39811 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
39812 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
39813 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
39814 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
39815 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
39816 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
39817 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
39818 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
39819 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
39820 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
39821 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39823 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39824 +4 4 4 4 4 4
39825 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
39826 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
39827 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
39828 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
39829 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
39830 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
39831 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
39832 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
39833 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
39834 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
39835 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39836 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39837 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39838 +4 4 4 4 4 4
39839 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
39840 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
39841 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
39842 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
39843 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
39844 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
39845 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
39846 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
39847 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
39848 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
39849 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39851 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39852 +4 4 4 4 4 4
39853 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
39854 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
39855 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
39856 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
39857 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
39858 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
39859 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
39860 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
39861 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
39862 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
39863 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39865 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39866 +4 4 4 4 4 4
39867 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
39868 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
39869 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
39870 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
39871 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
39872 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
39873 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
39874 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
39875 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
39876 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
39877 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39879 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39880 +4 4 4 4 4 4
39881 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
39882 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
39883 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
39884 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
39885 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
39886 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
39887 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
39888 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
39889 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
39890 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
39891 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39892 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39893 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39894 +4 4 4 4 4 4
39895 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
39896 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
39897 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
39898 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
39899 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
39900 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
39901 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
39902 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
39903 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
39904 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
39905 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39906 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39907 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39908 +4 4 4 4 4 4
39909 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
39910 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
39911 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
39912 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
39913 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
39914 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
39915 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
39916 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
39917 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
39918 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
39919 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39921 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39922 +4 4 4 4 4 4
39923 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
39924 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
39925 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
39926 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
39927 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
39928 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
39929 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
39930 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
39931 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
39932 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
39933 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39934 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39935 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39936 +4 4 4 4 4 4
39937 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
39938 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
39939 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
39940 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
39941 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
39942 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
39943 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
39944 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
39945 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
39946 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
39947 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39949 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39950 +4 4 4 4 4 4
39951 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
39952 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
39953 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
39954 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
39955 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
39956 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
39957 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
39958 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
39959 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
39960 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
39961 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39964 +4 4 4 4 4 4
39965 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
39966 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
39967 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
39968 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
39969 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
39970 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
39971 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
39972 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
39973 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
39974 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
39975 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39978 +4 4 4 4 4 4
39979 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
39980 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
39981 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
39982 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
39983 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
39984 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
39985 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
39986 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
39987 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
39988 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
39989 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39992 +4 4 4 4 4 4
39993 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
39994 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
39995 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
39996 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
39997 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
39998 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
39999 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40000 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
40001 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40002 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40003 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40006 +4 4 4 4 4 4
40007 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
40008 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
40009 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
40010 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
40011 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
40012 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
40013 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
40014 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
40015 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
40016 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40017 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40020 +4 4 4 4 4 4
40021 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40022 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
40023 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
40024 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
40025 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
40026 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
40027 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
40028 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
40029 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
40030 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40031 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40034 +4 4 4 4 4 4
40035 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
40036 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
40037 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
40038 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
40039 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
40040 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
40041 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
40042 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
40043 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
40044 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40045 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40048 +4 4 4 4 4 4
40049 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40050 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
40051 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
40052 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
40053 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
40054 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
40055 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
40056 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
40057 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
40058 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40059 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40062 +4 4 4 4 4 4
40063 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
40064 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
40065 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
40066 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
40067 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
40068 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
40069 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
40070 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
40071 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
40072 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
40073 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40076 +4 4 4 4 4 4
40077 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
40078 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40079 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
40080 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
40081 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
40082 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
40083 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
40084 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
40085 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
40086 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
40087 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40090 +4 4 4 4 4 4
40091 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
40092 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40093 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
40094 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
40095 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
40096 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
40097 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40098 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
40099 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
40100 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
40101 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40104 +4 4 4 4 4 4
40105 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
40106 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
40107 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
40108 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
40109 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
40110 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
40111 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
40112 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
40113 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
40114 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
40115 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40118 +4 4 4 4 4 4
40119 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
40120 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
40121 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
40122 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
40123 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
40124 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
40125 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
40126 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
40127 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
40128 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
40129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40132 +4 4 4 4 4 4
40133 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40134 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
40135 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
40136 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
40137 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
40138 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
40139 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
40140 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
40141 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
40142 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
40143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40146 +4 4 4 4 4 4
40147 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
40148 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
40149 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
40150 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
40151 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
40152 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
40153 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
40154 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
40155 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
40156 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40160 +4 4 4 4 4 4
40161 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
40162 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
40163 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
40164 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
40165 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
40166 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
40167 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
40168 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
40169 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40170 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40174 +4 4 4 4 4 4
40175 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
40176 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40177 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
40178 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
40179 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
40180 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
40181 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
40182 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
40183 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
40184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40188 +4 4 4 4 4 4
40189 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
40190 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
40191 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
40192 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
40193 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
40194 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
40195 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
40196 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
40197 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
40198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40202 +4 4 4 4 4 4
40203 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
40204 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
40205 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
40206 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
40207 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
40208 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
40209 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
40210 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
40211 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40216 +4 4 4 4 4 4
40217 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
40218 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
40219 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
40220 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
40221 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
40222 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
40223 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
40224 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
40225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40230 +4 4 4 4 4 4
40231 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
40232 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
40233 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
40234 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
40235 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
40236 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
40237 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
40238 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
40239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40244 +4 4 4 4 4 4
40245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40246 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
40247 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40248 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
40249 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
40250 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
40251 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
40252 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
40253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40258 +4 4 4 4 4 4
40259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40260 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
40261 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
40262 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
40263 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
40264 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
40265 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
40266 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
40267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40272 +4 4 4 4 4 4
40273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40274 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40275 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
40276 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
40277 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
40278 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
40279 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
40280 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40286 +4 4 4 4 4 4
40287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40289 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
40290 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
40291 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
40292 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
40293 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
40294 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40300 +4 4 4 4 4 4
40301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40304 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40305 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
40306 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
40307 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
40308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40314 +4 4 4 4 4 4
40315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40318 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
40319 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
40320 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
40321 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
40322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40328 +4 4 4 4 4 4
40329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40332 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
40333 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40334 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
40335 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
40336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40342 +4 4 4 4 4 4
40343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40346 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
40347 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
40348 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
40349 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
40350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40356 +4 4 4 4 4 4
40357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40361 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
40362 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40363 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40370 +4 4 4 4 4 4
40371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40375 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
40376 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
40377 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40384 +4 4 4 4 4 4
40385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40389 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
40390 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
40391 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40392 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40398 +4 4 4 4 4 4
40399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40400 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40403 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
40404 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
40405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40406 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40412 +4 4 4 4 4 4
40413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40414 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40416 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40417 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
40418 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
40419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40420 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40421 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40422 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40426 +4 4 4 4 4 4
40427 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
40428 index 3473e75..c930142 100644
40429 --- a/drivers/video/udlfb.c
40430 +++ b/drivers/video/udlfb.c
40431 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
40432 dlfb_urb_completion(urb);
40433
40434 error:
40435 - atomic_add(bytes_sent, &dev->bytes_sent);
40436 - atomic_add(bytes_identical, &dev->bytes_identical);
40437 - atomic_add(width*height*2, &dev->bytes_rendered);
40438 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
40439 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
40440 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
40441 end_cycles = get_cycles();
40442 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
40443 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
40444 >> 10)), /* Kcycles */
40445 &dev->cpu_kcycles_used);
40446
40447 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
40448 dlfb_urb_completion(urb);
40449
40450 error:
40451 - atomic_add(bytes_sent, &dev->bytes_sent);
40452 - atomic_add(bytes_identical, &dev->bytes_identical);
40453 - atomic_add(bytes_rendered, &dev->bytes_rendered);
40454 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
40455 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
40456 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
40457 end_cycles = get_cycles();
40458 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
40459 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
40460 >> 10)), /* Kcycles */
40461 &dev->cpu_kcycles_used);
40462 }
40463 @@ -1368,7 +1368,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
40464 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40465 struct dlfb_data *dev = fb_info->par;
40466 return snprintf(buf, PAGE_SIZE, "%u\n",
40467 - atomic_read(&dev->bytes_rendered));
40468 + atomic_read_unchecked(&dev->bytes_rendered));
40469 }
40470
40471 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
40472 @@ -1376,7 +1376,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
40473 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40474 struct dlfb_data *dev = fb_info->par;
40475 return snprintf(buf, PAGE_SIZE, "%u\n",
40476 - atomic_read(&dev->bytes_identical));
40477 + atomic_read_unchecked(&dev->bytes_identical));
40478 }
40479
40480 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
40481 @@ -1384,7 +1384,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
40482 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40483 struct dlfb_data *dev = fb_info->par;
40484 return snprintf(buf, PAGE_SIZE, "%u\n",
40485 - atomic_read(&dev->bytes_sent));
40486 + atomic_read_unchecked(&dev->bytes_sent));
40487 }
40488
40489 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
40490 @@ -1392,7 +1392,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
40491 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40492 struct dlfb_data *dev = fb_info->par;
40493 return snprintf(buf, PAGE_SIZE, "%u\n",
40494 - atomic_read(&dev->cpu_kcycles_used));
40495 + atomic_read_unchecked(&dev->cpu_kcycles_used));
40496 }
40497
40498 static ssize_t edid_show(
40499 @@ -1449,10 +1449,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
40500 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40501 struct dlfb_data *dev = fb_info->par;
40502
40503 - atomic_set(&dev->bytes_rendered, 0);
40504 - atomic_set(&dev->bytes_identical, 0);
40505 - atomic_set(&dev->bytes_sent, 0);
40506 - atomic_set(&dev->cpu_kcycles_used, 0);
40507 + atomic_set_unchecked(&dev->bytes_rendered, 0);
40508 + atomic_set_unchecked(&dev->bytes_identical, 0);
40509 + atomic_set_unchecked(&dev->bytes_sent, 0);
40510 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
40511
40512 return count;
40513 }
40514 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
40515 index 7f8472c..9842e87 100644
40516 --- a/drivers/video/uvesafb.c
40517 +++ b/drivers/video/uvesafb.c
40518 @@ -19,6 +19,7 @@
40519 #include <linux/io.h>
40520 #include <linux/mutex.h>
40521 #include <linux/slab.h>
40522 +#include <linux/moduleloader.h>
40523 #include <video/edid.h>
40524 #include <video/uvesafb.h>
40525 #ifdef CONFIG_X86
40526 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
40527 NULL,
40528 };
40529
40530 - return call_usermodehelper(v86d_path, argv, envp, 1);
40531 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
40532 }
40533
40534 /*
40535 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
40536 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
40537 par->pmi_setpal = par->ypan = 0;
40538 } else {
40539 +
40540 +#ifdef CONFIG_PAX_KERNEXEC
40541 +#ifdef CONFIG_MODULES
40542 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
40543 +#endif
40544 + if (!par->pmi_code) {
40545 + par->pmi_setpal = par->ypan = 0;
40546 + return 0;
40547 + }
40548 +#endif
40549 +
40550 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
40551 + task->t.regs.edi);
40552 +
40553 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40554 + pax_open_kernel();
40555 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
40556 + pax_close_kernel();
40557 +
40558 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
40559 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
40560 +#else
40561 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
40562 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
40563 +#endif
40564 +
40565 printk(KERN_INFO "uvesafb: protected mode interface info at "
40566 "%04x:%04x\n",
40567 (u16)task->t.regs.es, (u16)task->t.regs.edi);
40568 @@ -1821,6 +1844,11 @@ out:
40569 if (par->vbe_modes)
40570 kfree(par->vbe_modes);
40571
40572 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40573 + if (par->pmi_code)
40574 + module_free_exec(NULL, par->pmi_code);
40575 +#endif
40576 +
40577 framebuffer_release(info);
40578 return err;
40579 }
40580 @@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platform_device *dev)
40581 kfree(par->vbe_state_orig);
40582 if (par->vbe_state_saved)
40583 kfree(par->vbe_state_saved);
40584 +
40585 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40586 + if (par->pmi_code)
40587 + module_free_exec(NULL, par->pmi_code);
40588 +#endif
40589 +
40590 }
40591
40592 framebuffer_release(info);
40593 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
40594 index 501b340..86bd4cf 100644
40595 --- a/drivers/video/vesafb.c
40596 +++ b/drivers/video/vesafb.c
40597 @@ -9,6 +9,7 @@
40598 */
40599
40600 #include <linux/module.h>
40601 +#include <linux/moduleloader.h>
40602 #include <linux/kernel.h>
40603 #include <linux/errno.h>
40604 #include <linux/string.h>
40605 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
40606 static int vram_total __initdata; /* Set total amount of memory */
40607 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
40608 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
40609 -static void (*pmi_start)(void) __read_mostly;
40610 -static void (*pmi_pal) (void) __read_mostly;
40611 +static void (*pmi_start)(void) __read_only;
40612 +static void (*pmi_pal) (void) __read_only;
40613 static int depth __read_mostly;
40614 static int vga_compat __read_mostly;
40615 /* --------------------------------------------------------------------- */
40616 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
40617 unsigned int size_vmode;
40618 unsigned int size_remap;
40619 unsigned int size_total;
40620 + void *pmi_code = NULL;
40621
40622 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
40623 return -ENODEV;
40624 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
40625 size_remap = size_total;
40626 vesafb_fix.smem_len = size_remap;
40627
40628 -#ifndef __i386__
40629 - screen_info.vesapm_seg = 0;
40630 -#endif
40631 -
40632 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
40633 printk(KERN_WARNING
40634 "vesafb: cannot reserve video memory at 0x%lx\n",
40635 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
40636 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
40637 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
40638
40639 +#ifdef __i386__
40640 +
40641 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40642 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
40643 + if (!pmi_code)
40644 +#elif !defined(CONFIG_PAX_KERNEXEC)
40645 + if (0)
40646 +#endif
40647 +
40648 +#endif
40649 + screen_info.vesapm_seg = 0;
40650 +
40651 if (screen_info.vesapm_seg) {
40652 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
40653 - screen_info.vesapm_seg,screen_info.vesapm_off);
40654 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
40655 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
40656 }
40657
40658 if (screen_info.vesapm_seg < 0xc000)
40659 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
40660
40661 if (ypan || pmi_setpal) {
40662 unsigned short *pmi_base;
40663 +
40664 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
40665 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
40666 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
40667 +
40668 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40669 + pax_open_kernel();
40670 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
40671 +#else
40672 + pmi_code = pmi_base;
40673 +#endif
40674 +
40675 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
40676 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
40677 +
40678 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40679 + pmi_start = ktva_ktla(pmi_start);
40680 + pmi_pal = ktva_ktla(pmi_pal);
40681 + pax_close_kernel();
40682 +#endif
40683 +
40684 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
40685 if (pmi_base[3]) {
40686 printk(KERN_INFO "vesafb: pmi: ports = ");
40687 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
40688 info->node, info->fix.id);
40689 return 0;
40690 err:
40691 +
40692 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40693 + module_free_exec(NULL, pmi_code);
40694 +#endif
40695 +
40696 if (info->screen_base)
40697 iounmap(info->screen_base);
40698 framebuffer_release(info);
40699 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
40700 index 88714ae..16c2e11 100644
40701 --- a/drivers/video/via/via_clock.h
40702 +++ b/drivers/video/via/via_clock.h
40703 @@ -56,7 +56,7 @@ struct via_clock {
40704
40705 void (*set_engine_pll_state)(u8 state);
40706 void (*set_engine_pll)(struct via_pll_config config);
40707 -};
40708 +} __no_const;
40709
40710
40711 static inline u32 get_pll_internal_frequency(u32 ref_freq,
40712 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
40713 index e56c934..fc22f4b 100644
40714 --- a/drivers/xen/xen-pciback/conf_space.h
40715 +++ b/drivers/xen/xen-pciback/conf_space.h
40716 @@ -44,15 +44,15 @@ struct config_field {
40717 struct {
40718 conf_dword_write write;
40719 conf_dword_read read;
40720 - } dw;
40721 + } __no_const dw;
40722 struct {
40723 conf_word_write write;
40724 conf_word_read read;
40725 - } w;
40726 + } __no_const w;
40727 struct {
40728 conf_byte_write write;
40729 conf_byte_read read;
40730 - } b;
40731 + } __no_const b;
40732 } u;
40733 struct list_head list;
40734 };
40735 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
40736 index 879ed88..bc03a01 100644
40737 --- a/fs/9p/vfs_inode.c
40738 +++ b/fs/9p/vfs_inode.c
40739 @@ -1286,7 +1286,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
40740 void
40741 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
40742 {
40743 - char *s = nd_get_link(nd);
40744 + const char *s = nd_get_link(nd);
40745
40746 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
40747 IS_ERR(s) ? "<error>" : s);
40748 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
40749 index 79e2ca7..5828ad1 100644
40750 --- a/fs/Kconfig.binfmt
40751 +++ b/fs/Kconfig.binfmt
40752 @@ -86,7 +86,7 @@ config HAVE_AOUT
40753
40754 config BINFMT_AOUT
40755 tristate "Kernel support for a.out and ECOFF binaries"
40756 - depends on HAVE_AOUT
40757 + depends on HAVE_AOUT && BROKEN
40758 ---help---
40759 A.out (Assembler.OUTput) is a set of formats for libraries and
40760 executables used in the earliest versions of UNIX. Linux used
40761 diff --git a/fs/aio.c b/fs/aio.c
40762 index 969beb0..09fab51 100644
40763 --- a/fs/aio.c
40764 +++ b/fs/aio.c
40765 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
40766 size += sizeof(struct io_event) * nr_events;
40767 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
40768
40769 - if (nr_pages < 0)
40770 + if (nr_pages <= 0)
40771 return -EINVAL;
40772
40773 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
40774 @@ -1461,22 +1461,27 @@ static ssize_t aio_fsync(struct kiocb *iocb)
40775 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
40776 {
40777 ssize_t ret;
40778 + struct iovec iovstack;
40779
40780 #ifdef CONFIG_COMPAT
40781 if (compat)
40782 ret = compat_rw_copy_check_uvector(type,
40783 (struct compat_iovec __user *)kiocb->ki_buf,
40784 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
40785 + kiocb->ki_nbytes, 1, &iovstack,
40786 &kiocb->ki_iovec, 1);
40787 else
40788 #endif
40789 ret = rw_copy_check_uvector(type,
40790 (struct iovec __user *)kiocb->ki_buf,
40791 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
40792 + kiocb->ki_nbytes, 1, &iovstack,
40793 &kiocb->ki_iovec, 1);
40794 if (ret < 0)
40795 goto out;
40796
40797 + if (kiocb->ki_iovec == &iovstack) {
40798 + kiocb->ki_inline_vec = iovstack;
40799 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
40800 + }
40801 kiocb->ki_nr_segs = kiocb->ki_nbytes;
40802 kiocb->ki_cur_seg = 0;
40803 /* ki_nbytes/left now reflect bytes instead of segs */
40804 diff --git a/fs/attr.c b/fs/attr.c
40805 index 7ee7ba4..0c61a60 100644
40806 --- a/fs/attr.c
40807 +++ b/fs/attr.c
40808 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
40809 unsigned long limit;
40810
40811 limit = rlimit(RLIMIT_FSIZE);
40812 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
40813 if (limit != RLIM_INFINITY && offset > limit)
40814 goto out_sig;
40815 if (offset > inode->i_sb->s_maxbytes)
40816 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
40817 index e1fbdee..cd5ea56 100644
40818 --- a/fs/autofs4/waitq.c
40819 +++ b/fs/autofs4/waitq.c
40820 @@ -60,7 +60,7 @@ static int autofs4_write(struct file *file, const void *addr, int bytes)
40821 {
40822 unsigned long sigpipe, flags;
40823 mm_segment_t fs;
40824 - const char *data = (const char *)addr;
40825 + const char __user *data = (const char __force_user *)addr;
40826 ssize_t wr = 0;
40827
40828 /** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
40829 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
40830 index 8342ca6..82fd192 100644
40831 --- a/fs/befs/linuxvfs.c
40832 +++ b/fs/befs/linuxvfs.c
40833 @@ -503,7 +503,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
40834 {
40835 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
40836 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
40837 - char *link = nd_get_link(nd);
40838 + const char *link = nd_get_link(nd);
40839 if (!IS_ERR(link))
40840 kfree(link);
40841 }
40842 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
40843 index a6395bd..f1e376a 100644
40844 --- a/fs/binfmt_aout.c
40845 +++ b/fs/binfmt_aout.c
40846 @@ -16,6 +16,7 @@
40847 #include <linux/string.h>
40848 #include <linux/fs.h>
40849 #include <linux/file.h>
40850 +#include <linux/security.h>
40851 #include <linux/stat.h>
40852 #include <linux/fcntl.h>
40853 #include <linux/ptrace.h>
40854 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
40855 #endif
40856 # define START_STACK(u) ((void __user *)u.start_stack)
40857
40858 + memset(&dump, 0, sizeof(dump));
40859 +
40860 fs = get_fs();
40861 set_fs(KERNEL_DS);
40862 has_dumped = 1;
40863 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
40864
40865 /* If the size of the dump file exceeds the rlimit, then see what would happen
40866 if we wrote the stack, but not the data area. */
40867 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
40868 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
40869 dump.u_dsize = 0;
40870
40871 /* Make sure we have enough room to write the stack and data areas. */
40872 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
40873 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
40874 dump.u_ssize = 0;
40875
40876 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
40877 rlim = rlimit(RLIMIT_DATA);
40878 if (rlim >= RLIM_INFINITY)
40879 rlim = ~0;
40880 +
40881 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
40882 if (ex.a_data + ex.a_bss > rlim)
40883 return -ENOMEM;
40884
40885 @@ -259,9 +266,37 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
40886 current->mm->free_area_cache = current->mm->mmap_base;
40887 current->mm->cached_hole_size = 0;
40888
40889 + retval = setup_arg_pages(bprm, STACK_TOP, EXSTACK_DEFAULT);
40890 + if (retval < 0) {
40891 + /* Someone check-me: is this error path enough? */
40892 + send_sig(SIGKILL, current, 0);
40893 + return retval;
40894 + }
40895 +
40896 install_exec_creds(bprm);
40897 current->flags &= ~PF_FORKNOEXEC;
40898
40899 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
40900 + current->mm->pax_flags = 0UL;
40901 +#endif
40902 +
40903 +#ifdef CONFIG_PAX_PAGEEXEC
40904 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
40905 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
40906 +
40907 +#ifdef CONFIG_PAX_EMUTRAMP
40908 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
40909 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
40910 +#endif
40911 +
40912 +#ifdef CONFIG_PAX_MPROTECT
40913 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
40914 + current->mm->pax_flags |= MF_PAX_MPROTECT;
40915 +#endif
40916 +
40917 + }
40918 +#endif
40919 +
40920 if (N_MAGIC(ex) == OMAGIC) {
40921 unsigned long text_addr, map_size;
40922 loff_t pos;
40923 @@ -334,7 +369,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
40924
40925 down_write(&current->mm->mmap_sem);
40926 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
40927 - PROT_READ | PROT_WRITE | PROT_EXEC,
40928 + PROT_READ | PROT_WRITE,
40929 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
40930 fd_offset + ex.a_text);
40931 up_write(&current->mm->mmap_sem);
40932 @@ -352,13 +387,6 @@ beyond_if:
40933 return retval;
40934 }
40935
40936 - retval = setup_arg_pages(bprm, STACK_TOP, EXSTACK_DEFAULT);
40937 - if (retval < 0) {
40938 - /* Someone check-me: is this error path enough? */
40939 - send_sig(SIGKILL, current, 0);
40940 - return retval;
40941 - }
40942 -
40943 current->mm->start_stack =
40944 (unsigned long) create_aout_tables((char __user *) bprm->p, bprm);
40945 #ifdef __alpha__
40946 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
40947 index 21ac5ee..dbf63ee 100644
40948 --- a/fs/binfmt_elf.c
40949 +++ b/fs/binfmt_elf.c
40950 @@ -32,6 +32,7 @@
40951 #include <linux/elf.h>
40952 #include <linux/utsname.h>
40953 #include <linux/coredump.h>
40954 +#include <linux/xattr.h>
40955 #include <asm/uaccess.h>
40956 #include <asm/param.h>
40957 #include <asm/page.h>
40958 @@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
40959 #define elf_core_dump NULL
40960 #endif
40961
40962 +#ifdef CONFIG_PAX_MPROTECT
40963 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
40964 +#endif
40965 +
40966 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
40967 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
40968 #else
40969 @@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
40970 .load_binary = load_elf_binary,
40971 .load_shlib = load_elf_library,
40972 .core_dump = elf_core_dump,
40973 +
40974 +#ifdef CONFIG_PAX_MPROTECT
40975 + .handle_mprotect= elf_handle_mprotect,
40976 +#endif
40977 +
40978 .min_coredump = ELF_EXEC_PAGESIZE,
40979 };
40980
40981 @@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
40982
40983 static int set_brk(unsigned long start, unsigned long end)
40984 {
40985 + unsigned long e = end;
40986 +
40987 start = ELF_PAGEALIGN(start);
40988 end = ELF_PAGEALIGN(end);
40989 if (end > start) {
40990 @@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
40991 if (BAD_ADDR(addr))
40992 return addr;
40993 }
40994 - current->mm->start_brk = current->mm->brk = end;
40995 + current->mm->start_brk = current->mm->brk = e;
40996 return 0;
40997 }
40998
40999 @@ -148,12 +160,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41000 elf_addr_t __user *u_rand_bytes;
41001 const char *k_platform = ELF_PLATFORM;
41002 const char *k_base_platform = ELF_BASE_PLATFORM;
41003 - unsigned char k_rand_bytes[16];
41004 + u32 k_rand_bytes[4];
41005 int items;
41006 elf_addr_t *elf_info;
41007 int ei_index = 0;
41008 const struct cred *cred = current_cred();
41009 struct vm_area_struct *vma;
41010 + unsigned long saved_auxv[AT_VECTOR_SIZE];
41011
41012 /*
41013 * In some cases (e.g. Hyper-Threading), we want to avoid L1
41014 @@ -195,8 +208,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41015 * Generate 16 random bytes for userspace PRNG seeding.
41016 */
41017 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
41018 - u_rand_bytes = (elf_addr_t __user *)
41019 - STACK_ALLOC(p, sizeof(k_rand_bytes));
41020 + srandom32(k_rand_bytes[0] ^ random32());
41021 + srandom32(k_rand_bytes[1] ^ random32());
41022 + srandom32(k_rand_bytes[2] ^ random32());
41023 + srandom32(k_rand_bytes[3] ^ random32());
41024 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
41025 + u_rand_bytes = (elf_addr_t __user *) p;
41026 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
41027 return -EFAULT;
41028
41029 @@ -308,9 +325,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41030 return -EFAULT;
41031 current->mm->env_end = p;
41032
41033 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
41034 +
41035 /* Put the elf_info on the stack in the right place. */
41036 sp = (elf_addr_t __user *)envp + 1;
41037 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
41038 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
41039 return -EFAULT;
41040 return 0;
41041 }
41042 @@ -381,10 +400,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41043 {
41044 struct elf_phdr *elf_phdata;
41045 struct elf_phdr *eppnt;
41046 - unsigned long load_addr = 0;
41047 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
41048 int load_addr_set = 0;
41049 unsigned long last_bss = 0, elf_bss = 0;
41050 - unsigned long error = ~0UL;
41051 + unsigned long error = -EINVAL;
41052 unsigned long total_size;
41053 int retval, i, size;
41054
41055 @@ -430,6 +449,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41056 goto out_close;
41057 }
41058
41059 +#ifdef CONFIG_PAX_SEGMEXEC
41060 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
41061 + pax_task_size = SEGMEXEC_TASK_SIZE;
41062 +#endif
41063 +
41064 eppnt = elf_phdata;
41065 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
41066 if (eppnt->p_type == PT_LOAD) {
41067 @@ -473,8 +497,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41068 k = load_addr + eppnt->p_vaddr;
41069 if (BAD_ADDR(k) ||
41070 eppnt->p_filesz > eppnt->p_memsz ||
41071 - eppnt->p_memsz > TASK_SIZE ||
41072 - TASK_SIZE - eppnt->p_memsz < k) {
41073 + eppnt->p_memsz > pax_task_size ||
41074 + pax_task_size - eppnt->p_memsz < k) {
41075 error = -ENOMEM;
41076 goto out_close;
41077 }
41078 @@ -528,6 +552,351 @@ out:
41079 return error;
41080 }
41081
41082 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
41083 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
41084 +{
41085 + unsigned long pax_flags = 0UL;
41086 +
41087 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
41088 +
41089 +#ifdef CONFIG_PAX_PAGEEXEC
41090 + if (elf_phdata->p_flags & PF_PAGEEXEC)
41091 + pax_flags |= MF_PAX_PAGEEXEC;
41092 +#endif
41093 +
41094 +#ifdef CONFIG_PAX_SEGMEXEC
41095 + if (elf_phdata->p_flags & PF_SEGMEXEC)
41096 + pax_flags |= MF_PAX_SEGMEXEC;
41097 +#endif
41098 +
41099 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41100 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41101 + if ((__supported_pte_mask & _PAGE_NX))
41102 + pax_flags &= ~MF_PAX_SEGMEXEC;
41103 + else
41104 + pax_flags &= ~MF_PAX_PAGEEXEC;
41105 + }
41106 +#endif
41107 +
41108 +#ifdef CONFIG_PAX_EMUTRAMP
41109 + if (elf_phdata->p_flags & PF_EMUTRAMP)
41110 + pax_flags |= MF_PAX_EMUTRAMP;
41111 +#endif
41112 +
41113 +#ifdef CONFIG_PAX_MPROTECT
41114 + if (elf_phdata->p_flags & PF_MPROTECT)
41115 + pax_flags |= MF_PAX_MPROTECT;
41116 +#endif
41117 +
41118 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41119 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
41120 + pax_flags |= MF_PAX_RANDMMAP;
41121 +#endif
41122 +
41123 +#endif
41124 +
41125 + return pax_flags;
41126 +}
41127 +
41128 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
41129 +{
41130 + unsigned long pax_flags = 0UL;
41131 +
41132 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
41133 +
41134 +#ifdef CONFIG_PAX_PAGEEXEC
41135 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
41136 + pax_flags |= MF_PAX_PAGEEXEC;
41137 +#endif
41138 +
41139 +#ifdef CONFIG_PAX_SEGMEXEC
41140 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
41141 + pax_flags |= MF_PAX_SEGMEXEC;
41142 +#endif
41143 +
41144 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41145 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41146 + if ((__supported_pte_mask & _PAGE_NX))
41147 + pax_flags &= ~MF_PAX_SEGMEXEC;
41148 + else
41149 + pax_flags &= ~MF_PAX_PAGEEXEC;
41150 + }
41151 +#endif
41152 +
41153 +#ifdef CONFIG_PAX_EMUTRAMP
41154 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
41155 + pax_flags |= MF_PAX_EMUTRAMP;
41156 +#endif
41157 +
41158 +#ifdef CONFIG_PAX_MPROTECT
41159 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
41160 + pax_flags |= MF_PAX_MPROTECT;
41161 +#endif
41162 +
41163 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41164 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
41165 + pax_flags |= MF_PAX_RANDMMAP;
41166 +#endif
41167 +
41168 +#endif
41169 +
41170 + return pax_flags;
41171 +}
41172 +
41173 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
41174 +{
41175 + unsigned long pax_flags = 0UL;
41176 +
41177 +#ifdef CONFIG_PAX_EI_PAX
41178 +
41179 +#ifdef CONFIG_PAX_PAGEEXEC
41180 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
41181 + pax_flags |= MF_PAX_PAGEEXEC;
41182 +#endif
41183 +
41184 +#ifdef CONFIG_PAX_SEGMEXEC
41185 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
41186 + pax_flags |= MF_PAX_SEGMEXEC;
41187 +#endif
41188 +
41189 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41190 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41191 + if ((__supported_pte_mask & _PAGE_NX))
41192 + pax_flags &= ~MF_PAX_SEGMEXEC;
41193 + else
41194 + pax_flags &= ~MF_PAX_PAGEEXEC;
41195 + }
41196 +#endif
41197 +
41198 +#ifdef CONFIG_PAX_EMUTRAMP
41199 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
41200 + pax_flags |= MF_PAX_EMUTRAMP;
41201 +#endif
41202 +
41203 +#ifdef CONFIG_PAX_MPROTECT
41204 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
41205 + pax_flags |= MF_PAX_MPROTECT;
41206 +#endif
41207 +
41208 +#ifdef CONFIG_PAX_ASLR
41209 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
41210 + pax_flags |= MF_PAX_RANDMMAP;
41211 +#endif
41212 +
41213 +#else
41214 +
41215 +#ifdef CONFIG_PAX_PAGEEXEC
41216 + pax_flags |= MF_PAX_PAGEEXEC;
41217 +#endif
41218 +
41219 +#ifdef CONFIG_PAX_MPROTECT
41220 + pax_flags |= MF_PAX_MPROTECT;
41221 +#endif
41222 +
41223 +#ifdef CONFIG_PAX_RANDMMAP
41224 + pax_flags |= MF_PAX_RANDMMAP;
41225 +#endif
41226 +
41227 +#ifdef CONFIG_PAX_SEGMEXEC
41228 + if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
41229 + pax_flags &= ~MF_PAX_PAGEEXEC;
41230 + pax_flags |= MF_PAX_SEGMEXEC;
41231 + }
41232 +#endif
41233 +
41234 +#endif
41235 +
41236 + return pax_flags;
41237 +}
41238 +
41239 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
41240 +{
41241 +
41242 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
41243 + unsigned long i;
41244 +
41245 + for (i = 0UL; i < elf_ex->e_phnum; i++)
41246 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
41247 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
41248 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
41249 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
41250 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
41251 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
41252 + return ~0UL;
41253 +
41254 +#ifdef CONFIG_PAX_SOFTMODE
41255 + if (pax_softmode)
41256 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
41257 + else
41258 +#endif
41259 +
41260 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
41261 + break;
41262 + }
41263 +#endif
41264 +
41265 + return ~0UL;
41266 +}
41267 +
41268 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
41269 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
41270 +{
41271 + unsigned long pax_flags = 0UL;
41272 +
41273 +#ifdef CONFIG_PAX_PAGEEXEC
41274 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
41275 + pax_flags |= MF_PAX_PAGEEXEC;
41276 +#endif
41277 +
41278 +#ifdef CONFIG_PAX_SEGMEXEC
41279 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
41280 + pax_flags |= MF_PAX_SEGMEXEC;
41281 +#endif
41282 +
41283 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41284 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41285 + if ((__supported_pte_mask & _PAGE_NX))
41286 + pax_flags &= ~MF_PAX_SEGMEXEC;
41287 + else
41288 + pax_flags &= ~MF_PAX_PAGEEXEC;
41289 + }
41290 +#endif
41291 +
41292 +#ifdef CONFIG_PAX_EMUTRAMP
41293 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
41294 + pax_flags |= MF_PAX_EMUTRAMP;
41295 +#endif
41296 +
41297 +#ifdef CONFIG_PAX_MPROTECT
41298 + if (pax_flags_softmode & MF_PAX_MPROTECT)
41299 + pax_flags |= MF_PAX_MPROTECT;
41300 +#endif
41301 +
41302 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41303 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
41304 + pax_flags |= MF_PAX_RANDMMAP;
41305 +#endif
41306 +
41307 + return pax_flags;
41308 +}
41309 +
41310 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
41311 +{
41312 + unsigned long pax_flags = 0UL;
41313 +
41314 +#ifdef CONFIG_PAX_PAGEEXEC
41315 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
41316 + pax_flags |= MF_PAX_PAGEEXEC;
41317 +#endif
41318 +
41319 +#ifdef CONFIG_PAX_SEGMEXEC
41320 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
41321 + pax_flags |= MF_PAX_SEGMEXEC;
41322 +#endif
41323 +
41324 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41325 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41326 + if ((__supported_pte_mask & _PAGE_NX))
41327 + pax_flags &= ~MF_PAX_SEGMEXEC;
41328 + else
41329 + pax_flags &= ~MF_PAX_PAGEEXEC;
41330 + }
41331 +#endif
41332 +
41333 +#ifdef CONFIG_PAX_EMUTRAMP
41334 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
41335 + pax_flags |= MF_PAX_EMUTRAMP;
41336 +#endif
41337 +
41338 +#ifdef CONFIG_PAX_MPROTECT
41339 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
41340 + pax_flags |= MF_PAX_MPROTECT;
41341 +#endif
41342 +
41343 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41344 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
41345 + pax_flags |= MF_PAX_RANDMMAP;
41346 +#endif
41347 +
41348 + return pax_flags;
41349 +}
41350 +#endif
41351 +
41352 +static unsigned long pax_parse_xattr_pax(struct file * const file)
41353 +{
41354 +
41355 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
41356 + ssize_t xattr_size, i;
41357 + unsigned char xattr_value[5];
41358 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
41359 +
41360 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
41361 + if (xattr_size <= 0)
41362 + return ~0UL;
41363 +
41364 + for (i = 0; i < xattr_size; i++)
41365 + switch (xattr_value[i]) {
41366 + default:
41367 + return ~0UL;
41368 +
41369 +#define parse_flag(option1, option2, flag) \
41370 + case option1: \
41371 + pax_flags_hardmode |= MF_PAX_##flag; \
41372 + break; \
41373 + case option2: \
41374 + pax_flags_softmode |= MF_PAX_##flag; \
41375 + break;
41376 +
41377 + parse_flag('p', 'P', PAGEEXEC);
41378 + parse_flag('e', 'E', EMUTRAMP);
41379 + parse_flag('m', 'M', MPROTECT);
41380 + parse_flag('r', 'R', RANDMMAP);
41381 + parse_flag('s', 'S', SEGMEXEC);
41382 +
41383 +#undef parse_flag
41384 + }
41385 +
41386 + if (pax_flags_hardmode & pax_flags_softmode)
41387 + return ~0UL;
41388 +
41389 +#ifdef CONFIG_PAX_SOFTMODE
41390 + if (pax_softmode)
41391 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
41392 + else
41393 +#endif
41394 +
41395 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
41396 +#else
41397 + return ~0UL;
41398 +#endif
41399 +
41400 +}
41401 +
41402 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
41403 +{
41404 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
41405 +
41406 + pax_flags = pax_parse_ei_pax(elf_ex);
41407 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
41408 + xattr_pax_flags = pax_parse_xattr_pax(file);
41409 +
41410 + if (pt_pax_flags == ~0UL)
41411 + pt_pax_flags = xattr_pax_flags;
41412 + else if (xattr_pax_flags == ~0UL)
41413 + xattr_pax_flags = pt_pax_flags;
41414 + if (pt_pax_flags != xattr_pax_flags)
41415 + return -EINVAL;
41416 + if (pt_pax_flags != ~0UL)
41417 + pax_flags = pt_pax_flags;
41418 +
41419 + if (0 > pax_check_flags(&pax_flags))
41420 + return -EINVAL;
41421 +
41422 + current->mm->pax_flags = pax_flags;
41423 + return 0;
41424 +}
41425 +#endif
41426 +
41427 /*
41428 * These are the functions used to load ELF style executables and shared
41429 * libraries. There is no binary dependent code anywhere else.
41430 @@ -544,6 +913,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
41431 {
41432 unsigned int random_variable = 0;
41433
41434 +#ifdef CONFIG_PAX_RANDUSTACK
41435 + if (randomize_va_space)
41436 + return stack_top - current->mm->delta_stack;
41437 +#endif
41438 +
41439 if ((current->flags & PF_RANDOMIZE) &&
41440 !(current->personality & ADDR_NO_RANDOMIZE)) {
41441 random_variable = get_random_int() & STACK_RND_MASK;
41442 @@ -562,7 +936,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41443 unsigned long load_addr = 0, load_bias = 0;
41444 int load_addr_set = 0;
41445 char * elf_interpreter = NULL;
41446 - unsigned long error;
41447 + unsigned long error = 0;
41448 struct elf_phdr *elf_ppnt, *elf_phdata;
41449 unsigned long elf_bss, elf_brk;
41450 int retval, i;
41451 @@ -572,11 +946,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41452 unsigned long start_code, end_code, start_data, end_data;
41453 unsigned long reloc_func_desc __maybe_unused = 0;
41454 int executable_stack = EXSTACK_DEFAULT;
41455 - unsigned long def_flags = 0;
41456 struct {
41457 struct elfhdr elf_ex;
41458 struct elfhdr interp_elf_ex;
41459 } *loc;
41460 + unsigned long pax_task_size = TASK_SIZE;
41461
41462 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
41463 if (!loc) {
41464 @@ -713,11 +1087,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41465
41466 /* OK, This is the point of no return */
41467 current->flags &= ~PF_FORKNOEXEC;
41468 - current->mm->def_flags = def_flags;
41469 +
41470 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
41471 + current->mm->pax_flags = 0UL;
41472 +#endif
41473 +
41474 +#ifdef CONFIG_PAX_DLRESOLVE
41475 + current->mm->call_dl_resolve = 0UL;
41476 +#endif
41477 +
41478 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
41479 + current->mm->call_syscall = 0UL;
41480 +#endif
41481 +
41482 +#ifdef CONFIG_PAX_ASLR
41483 + current->mm->delta_mmap = 0UL;
41484 + current->mm->delta_stack = 0UL;
41485 +#endif
41486 +
41487 + current->mm->def_flags = 0;
41488 +
41489 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
41490 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
41491 + send_sig(SIGKILL, current, 0);
41492 + goto out_free_dentry;
41493 + }
41494 +#endif
41495 +
41496 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
41497 + pax_set_initial_flags(bprm);
41498 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
41499 + if (pax_set_initial_flags_func)
41500 + (pax_set_initial_flags_func)(bprm);
41501 +#endif
41502 +
41503 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
41504 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
41505 + current->mm->context.user_cs_limit = PAGE_SIZE;
41506 + current->mm->def_flags |= VM_PAGEEXEC;
41507 + }
41508 +#endif
41509 +
41510 +#ifdef CONFIG_PAX_SEGMEXEC
41511 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
41512 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
41513 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
41514 + pax_task_size = SEGMEXEC_TASK_SIZE;
41515 + current->mm->def_flags |= VM_NOHUGEPAGE;
41516 + }
41517 +#endif
41518 +
41519 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
41520 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41521 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
41522 + put_cpu();
41523 + }
41524 +#endif
41525
41526 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
41527 may depend on the personality. */
41528 SET_PERSONALITY(loc->elf_ex);
41529 +
41530 +#ifdef CONFIG_PAX_ASLR
41531 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
41532 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
41533 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
41534 + }
41535 +#endif
41536 +
41537 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
41538 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41539 + executable_stack = EXSTACK_DISABLE_X;
41540 + current->personality &= ~READ_IMPLIES_EXEC;
41541 + } else
41542 +#endif
41543 +
41544 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
41545 current->personality |= READ_IMPLIES_EXEC;
41546
41547 @@ -808,6 +1252,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41548 #else
41549 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
41550 #endif
41551 +
41552 +#ifdef CONFIG_PAX_RANDMMAP
41553 + /* PaX: randomize base address at the default exe base if requested */
41554 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
41555 +#ifdef CONFIG_SPARC64
41556 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
41557 +#else
41558 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
41559 +#endif
41560 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
41561 + elf_flags |= MAP_FIXED;
41562 + }
41563 +#endif
41564 +
41565 }
41566
41567 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
41568 @@ -840,9 +1298,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41569 * allowed task size. Note that p_filesz must always be
41570 * <= p_memsz so it is only necessary to check p_memsz.
41571 */
41572 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
41573 - elf_ppnt->p_memsz > TASK_SIZE ||
41574 - TASK_SIZE - elf_ppnt->p_memsz < k) {
41575 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
41576 + elf_ppnt->p_memsz > pax_task_size ||
41577 + pax_task_size - elf_ppnt->p_memsz < k) {
41578 /* set_brk can never work. Avoid overflows. */
41579 send_sig(SIGKILL, current, 0);
41580 retval = -EINVAL;
41581 @@ -870,6 +1328,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41582 start_data += load_bias;
41583 end_data += load_bias;
41584
41585 +#ifdef CONFIG_PAX_RANDMMAP
41586 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
41587 + elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
41588 +#endif
41589 +
41590 /* Calling set_brk effectively mmaps the pages that we need
41591 * for the bss and break sections. We must do this before
41592 * mapping in the interpreter, to make sure it doesn't wind
41593 @@ -881,9 +1344,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41594 goto out_free_dentry;
41595 }
41596 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
41597 - send_sig(SIGSEGV, current, 0);
41598 - retval = -EFAULT; /* Nobody gets to see this, but.. */
41599 - goto out_free_dentry;
41600 + /*
41601 + * This bss-zeroing can fail if the ELF
41602 + * file specifies odd protections. So
41603 + * we don't check the return value
41604 + */
41605 }
41606
41607 if (elf_interpreter) {
41608 @@ -1098,7 +1563,7 @@ out:
41609 * Decide what to dump of a segment, part, all or none.
41610 */
41611 static unsigned long vma_dump_size(struct vm_area_struct *vma,
41612 - unsigned long mm_flags)
41613 + unsigned long mm_flags, long signr)
41614 {
41615 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
41616
41617 @@ -1132,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
41618 if (vma->vm_file == NULL)
41619 return 0;
41620
41621 - if (FILTER(MAPPED_PRIVATE))
41622 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
41623 goto whole;
41624
41625 /*
41626 @@ -1354,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
41627 {
41628 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
41629 int i = 0;
41630 - do
41631 + do {
41632 i += 2;
41633 - while (auxv[i - 2] != AT_NULL);
41634 + } while (auxv[i - 2] != AT_NULL);
41635 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
41636 }
41637
41638 @@ -1421,7 +1886,7 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,
41639 for (i = 1; i < view->n; ++i) {
41640 const struct user_regset *regset = &view->regsets[i];
41641 do_thread_regset_writeback(t->task, regset);
41642 - if (regset->core_note_type &&
41643 + if (regset->core_note_type && regset->get &&
41644 (!regset->active || regset->active(t->task, regset))) {
41645 int ret;
41646 size_t size = regset->n * regset->size;
41647 @@ -1862,14 +2327,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
41648 }
41649
41650 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
41651 - unsigned long mm_flags)
41652 + struct coredump_params *cprm)
41653 {
41654 struct vm_area_struct *vma;
41655 size_t size = 0;
41656
41657 for (vma = first_vma(current, gate_vma); vma != NULL;
41658 vma = next_vma(vma, gate_vma))
41659 - size += vma_dump_size(vma, mm_flags);
41660 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
41661 return size;
41662 }
41663
41664 @@ -1963,7 +2428,7 @@ static int elf_core_dump(struct coredump_params *cprm)
41665
41666 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
41667
41668 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
41669 + offset += elf_core_vma_data_size(gate_vma, cprm);
41670 offset += elf_core_extra_data_size();
41671 e_shoff = offset;
41672
41673 @@ -1977,10 +2442,12 @@ static int elf_core_dump(struct coredump_params *cprm)
41674 offset = dataoff;
41675
41676 size += sizeof(*elf);
41677 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
41678 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
41679 goto end_coredump;
41680
41681 size += sizeof(*phdr4note);
41682 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
41683 if (size > cprm->limit
41684 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
41685 goto end_coredump;
41686 @@ -1994,7 +2461,7 @@ static int elf_core_dump(struct coredump_params *cprm)
41687 phdr.p_offset = offset;
41688 phdr.p_vaddr = vma->vm_start;
41689 phdr.p_paddr = 0;
41690 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
41691 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
41692 phdr.p_memsz = vma->vm_end - vma->vm_start;
41693 offset += phdr.p_filesz;
41694 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
41695 @@ -2005,6 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
41696 phdr.p_align = ELF_EXEC_PAGESIZE;
41697
41698 size += sizeof(phdr);
41699 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
41700 if (size > cprm->limit
41701 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
41702 goto end_coredump;
41703 @@ -2029,7 +2497,7 @@ static int elf_core_dump(struct coredump_params *cprm)
41704 unsigned long addr;
41705 unsigned long end;
41706
41707 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
41708 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
41709
41710 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
41711 struct page *page;
41712 @@ -2038,6 +2506,7 @@ static int elf_core_dump(struct coredump_params *cprm)
41713 page = get_dump_page(addr);
41714 if (page) {
41715 void *kaddr = kmap(page);
41716 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
41717 stop = ((size += PAGE_SIZE) > cprm->limit) ||
41718 !dump_write(cprm->file, kaddr,
41719 PAGE_SIZE);
41720 @@ -2055,6 +2524,7 @@ static int elf_core_dump(struct coredump_params *cprm)
41721
41722 if (e_phnum == PN_XNUM) {
41723 size += sizeof(*shdr4extnum);
41724 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
41725 if (size > cprm->limit
41726 || !dump_write(cprm->file, shdr4extnum,
41727 sizeof(*shdr4extnum)))
41728 @@ -2075,6 +2545,97 @@ out:
41729
41730 #endif /* CONFIG_ELF_CORE */
41731
41732 +#ifdef CONFIG_PAX_MPROTECT
41733 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
41734 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
41735 + * we'll remove VM_MAYWRITE for good on RELRO segments.
41736 + *
41737 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
41738 + * basis because we want to allow the common case and not the special ones.
41739 + */
41740 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
41741 +{
41742 + struct elfhdr elf_h;
41743 + struct elf_phdr elf_p;
41744 + unsigned long i;
41745 + unsigned long oldflags;
41746 + bool is_textrel_rw, is_textrel_rx, is_relro;
41747 +
41748 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
41749 + return;
41750 +
41751 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
41752 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
41753 +
41754 +#ifdef CONFIG_PAX_ELFRELOCS
41755 + /* possible TEXTREL */
41756 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
41757 + 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);
41758 +#else
41759 + is_textrel_rw = false;
41760 + is_textrel_rx = false;
41761 +#endif
41762 +
41763 + /* possible RELRO */
41764 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
41765 +
41766 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
41767 + return;
41768 +
41769 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
41770 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
41771 +
41772 +#ifdef CONFIG_PAX_ETEXECRELOCS
41773 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
41774 +#else
41775 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
41776 +#endif
41777 +
41778 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
41779 + !elf_check_arch(&elf_h) ||
41780 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
41781 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
41782 + return;
41783 +
41784 + for (i = 0UL; i < elf_h.e_phnum; i++) {
41785 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
41786 + return;
41787 + switch (elf_p.p_type) {
41788 + case PT_DYNAMIC:
41789 + if (!is_textrel_rw && !is_textrel_rx)
41790 + continue;
41791 + i = 0UL;
41792 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
41793 + elf_dyn dyn;
41794 +
41795 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
41796 + return;
41797 + if (dyn.d_tag == DT_NULL)
41798 + return;
41799 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
41800 + gr_log_textrel(vma);
41801 + if (is_textrel_rw)
41802 + vma->vm_flags |= VM_MAYWRITE;
41803 + else
41804 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
41805 + vma->vm_flags &= ~VM_MAYWRITE;
41806 + return;
41807 + }
41808 + i++;
41809 + }
41810 + return;
41811 +
41812 + case PT_GNU_RELRO:
41813 + if (!is_relro)
41814 + continue;
41815 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
41816 + vma->vm_flags &= ~VM_MAYWRITE;
41817 + return;
41818 + }
41819 + }
41820 +}
41821 +#endif
41822 +
41823 static int __init init_elf_binfmt(void)
41824 {
41825 return register_binfmt(&elf_format);
41826 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
41827 index 1bffbe0..c8c283e 100644
41828 --- a/fs/binfmt_flat.c
41829 +++ b/fs/binfmt_flat.c
41830 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
41831 realdatastart = (unsigned long) -ENOMEM;
41832 printk("Unable to allocate RAM for process data, errno %d\n",
41833 (int)-realdatastart);
41834 + down_write(&current->mm->mmap_sem);
41835 do_munmap(current->mm, textpos, text_len);
41836 + up_write(&current->mm->mmap_sem);
41837 ret = realdatastart;
41838 goto err;
41839 }
41840 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
41841 }
41842 if (IS_ERR_VALUE(result)) {
41843 printk("Unable to read data+bss, errno %d\n", (int)-result);
41844 + down_write(&current->mm->mmap_sem);
41845 do_munmap(current->mm, textpos, text_len);
41846 do_munmap(current->mm, realdatastart, len);
41847 + up_write(&current->mm->mmap_sem);
41848 ret = result;
41849 goto err;
41850 }
41851 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
41852 }
41853 if (IS_ERR_VALUE(result)) {
41854 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
41855 + down_write(&current->mm->mmap_sem);
41856 do_munmap(current->mm, textpos, text_len + data_len + extra +
41857 MAX_SHARED_LIBS * sizeof(unsigned long));
41858 + up_write(&current->mm->mmap_sem);
41859 ret = result;
41860 goto err;
41861 }
41862 diff --git a/fs/bio.c b/fs/bio.c
41863 index b1fe82c..84da0a9 100644
41864 --- a/fs/bio.c
41865 +++ b/fs/bio.c
41866 @@ -1233,7 +1233,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
41867 const int read = bio_data_dir(bio) == READ;
41868 struct bio_map_data *bmd = bio->bi_private;
41869 int i;
41870 - char *p = bmd->sgvecs[0].iov_base;
41871 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
41872
41873 __bio_for_each_segment(bvec, bio, i, 0) {
41874 char *addr = page_address(bvec->bv_page);
41875 diff --git a/fs/block_dev.c b/fs/block_dev.c
41876 index b07f1da..9efcb92 100644
41877 --- a/fs/block_dev.c
41878 +++ b/fs/block_dev.c
41879 @@ -681,7 +681,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
41880 else if (bdev->bd_contains == bdev)
41881 return true; /* is a whole device which isn't held */
41882
41883 - else if (whole->bd_holder == bd_may_claim)
41884 + else if (whole->bd_holder == (void *)bd_may_claim)
41885 return true; /* is a partition of a device that is being partitioned */
41886 else if (whole->bd_holder != NULL)
41887 return false; /* is a partition of a held device */
41888 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
41889 index dede441..f2a2507 100644
41890 --- a/fs/btrfs/ctree.c
41891 +++ b/fs/btrfs/ctree.c
41892 @@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
41893 free_extent_buffer(buf);
41894 add_root_to_dirty_list(root);
41895 } else {
41896 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
41897 - parent_start = parent->start;
41898 - else
41899 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
41900 + if (parent)
41901 + parent_start = parent->start;
41902 + else
41903 + parent_start = 0;
41904 + } else
41905 parent_start = 0;
41906
41907 WARN_ON(trans->transid != btrfs_header_generation(parent));
41908 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
41909 index fd1a06d..6e9033d 100644
41910 --- a/fs/btrfs/inode.c
41911 +++ b/fs/btrfs/inode.c
41912 @@ -6895,7 +6895,7 @@ fail:
41913 return -ENOMEM;
41914 }
41915
41916 -static int btrfs_getattr(struct vfsmount *mnt,
41917 +int btrfs_getattr(struct vfsmount *mnt,
41918 struct dentry *dentry, struct kstat *stat)
41919 {
41920 struct inode *inode = dentry->d_inode;
41921 @@ -6909,6 +6909,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
41922 return 0;
41923 }
41924
41925 +EXPORT_SYMBOL(btrfs_getattr);
41926 +
41927 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
41928 +{
41929 + return BTRFS_I(inode)->root->anon_dev;
41930 +}
41931 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
41932 +
41933 /*
41934 * If a file is moved, it will inherit the cow and compression flags of the new
41935 * directory.
41936 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
41937 index c04f02c..f5c9e2e 100644
41938 --- a/fs/btrfs/ioctl.c
41939 +++ b/fs/btrfs/ioctl.c
41940 @@ -2733,9 +2733,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
41941 for (i = 0; i < num_types; i++) {
41942 struct btrfs_space_info *tmp;
41943
41944 + /* Don't copy in more than we allocated */
41945 if (!slot_count)
41946 break;
41947
41948 + slot_count--;
41949 +
41950 info = NULL;
41951 rcu_read_lock();
41952 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
41953 @@ -2757,15 +2760,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
41954 memcpy(dest, &space, sizeof(space));
41955 dest++;
41956 space_args.total_spaces++;
41957 - slot_count--;
41958 }
41959 - if (!slot_count)
41960 - break;
41961 }
41962 up_read(&info->groups_sem);
41963 }
41964
41965 - user_dest = (struct btrfs_ioctl_space_info *)
41966 + user_dest = (struct btrfs_ioctl_space_info __user *)
41967 (arg + sizeof(struct btrfs_ioctl_space_args));
41968
41969 if (copy_to_user(user_dest, dest_orig, alloc_size))
41970 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
41971 index cfb5543..1ae7347 100644
41972 --- a/fs/btrfs/relocation.c
41973 +++ b/fs/btrfs/relocation.c
41974 @@ -1244,7 +1244,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
41975 }
41976 spin_unlock(&rc->reloc_root_tree.lock);
41977
41978 - BUG_ON((struct btrfs_root *)node->data != root);
41979 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
41980
41981 if (!del) {
41982 spin_lock(&rc->reloc_root_tree.lock);
41983 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
41984 index 622f469..e8d2d55 100644
41985 --- a/fs/cachefiles/bind.c
41986 +++ b/fs/cachefiles/bind.c
41987 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
41988 args);
41989
41990 /* start by checking things over */
41991 - ASSERT(cache->fstop_percent >= 0 &&
41992 - cache->fstop_percent < cache->fcull_percent &&
41993 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
41994 cache->fcull_percent < cache->frun_percent &&
41995 cache->frun_percent < 100);
41996
41997 - ASSERT(cache->bstop_percent >= 0 &&
41998 - cache->bstop_percent < cache->bcull_percent &&
41999 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
42000 cache->bcull_percent < cache->brun_percent &&
42001 cache->brun_percent < 100);
42002
42003 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
42004 index 0a1467b..6a53245 100644
42005 --- a/fs/cachefiles/daemon.c
42006 +++ b/fs/cachefiles/daemon.c
42007 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
42008 if (n > buflen)
42009 return -EMSGSIZE;
42010
42011 - if (copy_to_user(_buffer, buffer, n) != 0)
42012 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
42013 return -EFAULT;
42014
42015 return n;
42016 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
42017 if (test_bit(CACHEFILES_DEAD, &cache->flags))
42018 return -EIO;
42019
42020 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
42021 + if (datalen > PAGE_SIZE - 1)
42022 return -EOPNOTSUPP;
42023
42024 /* drag the command string into the kernel so we can parse it */
42025 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
42026 if (args[0] != '%' || args[1] != '\0')
42027 return -EINVAL;
42028
42029 - if (fstop < 0 || fstop >= cache->fcull_percent)
42030 + if (fstop >= cache->fcull_percent)
42031 return cachefiles_daemon_range_error(cache, args);
42032
42033 cache->fstop_percent = fstop;
42034 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
42035 if (args[0] != '%' || args[1] != '\0')
42036 return -EINVAL;
42037
42038 - if (bstop < 0 || bstop >= cache->bcull_percent)
42039 + if (bstop >= cache->bcull_percent)
42040 return cachefiles_daemon_range_error(cache, args);
42041
42042 cache->bstop_percent = bstop;
42043 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
42044 index bd6bc1b..b627b53 100644
42045 --- a/fs/cachefiles/internal.h
42046 +++ b/fs/cachefiles/internal.h
42047 @@ -57,7 +57,7 @@ struct cachefiles_cache {
42048 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
42049 struct rb_root active_nodes; /* active nodes (can't be culled) */
42050 rwlock_t active_lock; /* lock for active_nodes */
42051 - atomic_t gravecounter; /* graveyard uniquifier */
42052 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
42053 unsigned frun_percent; /* when to stop culling (% files) */
42054 unsigned fcull_percent; /* when to start culling (% files) */
42055 unsigned fstop_percent; /* when to stop allocating (% files) */
42056 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
42057 * proc.c
42058 */
42059 #ifdef CONFIG_CACHEFILES_HISTOGRAM
42060 -extern atomic_t cachefiles_lookup_histogram[HZ];
42061 -extern atomic_t cachefiles_mkdir_histogram[HZ];
42062 -extern atomic_t cachefiles_create_histogram[HZ];
42063 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42064 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42065 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
42066
42067 extern int __init cachefiles_proc_init(void);
42068 extern void cachefiles_proc_cleanup(void);
42069 static inline
42070 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
42071 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
42072 {
42073 unsigned long jif = jiffies - start_jif;
42074 if (jif >= HZ)
42075 jif = HZ - 1;
42076 - atomic_inc(&histogram[jif]);
42077 + atomic_inc_unchecked(&histogram[jif]);
42078 }
42079
42080 #else
42081 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
42082 index a0358c2..d6137f2 100644
42083 --- a/fs/cachefiles/namei.c
42084 +++ b/fs/cachefiles/namei.c
42085 @@ -318,7 +318,7 @@ try_again:
42086 /* first step is to make up a grave dentry in the graveyard */
42087 sprintf(nbuffer, "%08x%08x",
42088 (uint32_t) get_seconds(),
42089 - (uint32_t) atomic_inc_return(&cache->gravecounter));
42090 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
42091
42092 /* do the multiway lock magic */
42093 trap = lock_rename(cache->graveyard, dir);
42094 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
42095 index eccd339..4c1d995 100644
42096 --- a/fs/cachefiles/proc.c
42097 +++ b/fs/cachefiles/proc.c
42098 @@ -14,9 +14,9 @@
42099 #include <linux/seq_file.h>
42100 #include "internal.h"
42101
42102 -atomic_t cachefiles_lookup_histogram[HZ];
42103 -atomic_t cachefiles_mkdir_histogram[HZ];
42104 -atomic_t cachefiles_create_histogram[HZ];
42105 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42106 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42107 +atomic_unchecked_t cachefiles_create_histogram[HZ];
42108
42109 /*
42110 * display the latency histogram
42111 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
42112 return 0;
42113 default:
42114 index = (unsigned long) v - 3;
42115 - x = atomic_read(&cachefiles_lookup_histogram[index]);
42116 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
42117 - z = atomic_read(&cachefiles_create_histogram[index]);
42118 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
42119 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
42120 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
42121 if (x == 0 && y == 0 && z == 0)
42122 return 0;
42123
42124 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
42125 index 0e3c092..818480e 100644
42126 --- a/fs/cachefiles/rdwr.c
42127 +++ b/fs/cachefiles/rdwr.c
42128 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
42129 old_fs = get_fs();
42130 set_fs(KERNEL_DS);
42131 ret = file->f_op->write(
42132 - file, (const void __user *) data, len, &pos);
42133 + file, (const void __force_user *) data, len, &pos);
42134 set_fs(old_fs);
42135 kunmap(page);
42136 if (ret != len)
42137 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
42138 index 9895400..fa40a7d 100644
42139 --- a/fs/ceph/dir.c
42140 +++ b/fs/ceph/dir.c
42141 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
42142 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
42143 struct ceph_mds_client *mdsc = fsc->mdsc;
42144 unsigned frag = fpos_frag(filp->f_pos);
42145 - int off = fpos_off(filp->f_pos);
42146 + unsigned int off = fpos_off(filp->f_pos);
42147 int err;
42148 u32 ftype;
42149 struct ceph_mds_reply_info_parsed *rinfo;
42150 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
42151 index 84e8c07..6170d31 100644
42152 --- a/fs/cifs/cifs_debug.c
42153 +++ b/fs/cifs/cifs_debug.c
42154 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
42155
42156 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
42157 #ifdef CONFIG_CIFS_STATS2
42158 - atomic_set(&totBufAllocCount, 0);
42159 - atomic_set(&totSmBufAllocCount, 0);
42160 + atomic_set_unchecked(&totBufAllocCount, 0);
42161 + atomic_set_unchecked(&totSmBufAllocCount, 0);
42162 #endif /* CONFIG_CIFS_STATS2 */
42163 spin_lock(&cifs_tcp_ses_lock);
42164 list_for_each(tmp1, &cifs_tcp_ses_list) {
42165 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
42166 tcon = list_entry(tmp3,
42167 struct cifs_tcon,
42168 tcon_list);
42169 - atomic_set(&tcon->num_smbs_sent, 0);
42170 - atomic_set(&tcon->num_writes, 0);
42171 - atomic_set(&tcon->num_reads, 0);
42172 - atomic_set(&tcon->num_oplock_brks, 0);
42173 - atomic_set(&tcon->num_opens, 0);
42174 - atomic_set(&tcon->num_posixopens, 0);
42175 - atomic_set(&tcon->num_posixmkdirs, 0);
42176 - atomic_set(&tcon->num_closes, 0);
42177 - atomic_set(&tcon->num_deletes, 0);
42178 - atomic_set(&tcon->num_mkdirs, 0);
42179 - atomic_set(&tcon->num_rmdirs, 0);
42180 - atomic_set(&tcon->num_renames, 0);
42181 - atomic_set(&tcon->num_t2renames, 0);
42182 - atomic_set(&tcon->num_ffirst, 0);
42183 - atomic_set(&tcon->num_fnext, 0);
42184 - atomic_set(&tcon->num_fclose, 0);
42185 - atomic_set(&tcon->num_hardlinks, 0);
42186 - atomic_set(&tcon->num_symlinks, 0);
42187 - atomic_set(&tcon->num_locks, 0);
42188 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
42189 + atomic_set_unchecked(&tcon->num_writes, 0);
42190 + atomic_set_unchecked(&tcon->num_reads, 0);
42191 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
42192 + atomic_set_unchecked(&tcon->num_opens, 0);
42193 + atomic_set_unchecked(&tcon->num_posixopens, 0);
42194 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
42195 + atomic_set_unchecked(&tcon->num_closes, 0);
42196 + atomic_set_unchecked(&tcon->num_deletes, 0);
42197 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
42198 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
42199 + atomic_set_unchecked(&tcon->num_renames, 0);
42200 + atomic_set_unchecked(&tcon->num_t2renames, 0);
42201 + atomic_set_unchecked(&tcon->num_ffirst, 0);
42202 + atomic_set_unchecked(&tcon->num_fnext, 0);
42203 + atomic_set_unchecked(&tcon->num_fclose, 0);
42204 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
42205 + atomic_set_unchecked(&tcon->num_symlinks, 0);
42206 + atomic_set_unchecked(&tcon->num_locks, 0);
42207 }
42208 }
42209 }
42210 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
42211 smBufAllocCount.counter, cifs_min_small);
42212 #ifdef CONFIG_CIFS_STATS2
42213 seq_printf(m, "Total Large %d Small %d Allocations\n",
42214 - atomic_read(&totBufAllocCount),
42215 - atomic_read(&totSmBufAllocCount));
42216 + atomic_read_unchecked(&totBufAllocCount),
42217 + atomic_read_unchecked(&totSmBufAllocCount));
42218 #endif /* CONFIG_CIFS_STATS2 */
42219
42220 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
42221 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
42222 if (tcon->need_reconnect)
42223 seq_puts(m, "\tDISCONNECTED ");
42224 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
42225 - atomic_read(&tcon->num_smbs_sent),
42226 - atomic_read(&tcon->num_oplock_brks));
42227 + atomic_read_unchecked(&tcon->num_smbs_sent),
42228 + atomic_read_unchecked(&tcon->num_oplock_brks));
42229 seq_printf(m, "\nReads: %d Bytes: %lld",
42230 - atomic_read(&tcon->num_reads),
42231 + atomic_read_unchecked(&tcon->num_reads),
42232 (long long)(tcon->bytes_read));
42233 seq_printf(m, "\nWrites: %d Bytes: %lld",
42234 - atomic_read(&tcon->num_writes),
42235 + atomic_read_unchecked(&tcon->num_writes),
42236 (long long)(tcon->bytes_written));
42237 seq_printf(m, "\nFlushes: %d",
42238 - atomic_read(&tcon->num_flushes));
42239 + atomic_read_unchecked(&tcon->num_flushes));
42240 seq_printf(m, "\nLocks: %d HardLinks: %d "
42241 "Symlinks: %d",
42242 - atomic_read(&tcon->num_locks),
42243 - atomic_read(&tcon->num_hardlinks),
42244 - atomic_read(&tcon->num_symlinks));
42245 + atomic_read_unchecked(&tcon->num_locks),
42246 + atomic_read_unchecked(&tcon->num_hardlinks),
42247 + atomic_read_unchecked(&tcon->num_symlinks));
42248 seq_printf(m, "\nOpens: %d Closes: %d "
42249 "Deletes: %d",
42250 - atomic_read(&tcon->num_opens),
42251 - atomic_read(&tcon->num_closes),
42252 - atomic_read(&tcon->num_deletes));
42253 + atomic_read_unchecked(&tcon->num_opens),
42254 + atomic_read_unchecked(&tcon->num_closes),
42255 + atomic_read_unchecked(&tcon->num_deletes));
42256 seq_printf(m, "\nPosix Opens: %d "
42257 "Posix Mkdirs: %d",
42258 - atomic_read(&tcon->num_posixopens),
42259 - atomic_read(&tcon->num_posixmkdirs));
42260 + atomic_read_unchecked(&tcon->num_posixopens),
42261 + atomic_read_unchecked(&tcon->num_posixmkdirs));
42262 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
42263 - atomic_read(&tcon->num_mkdirs),
42264 - atomic_read(&tcon->num_rmdirs));
42265 + atomic_read_unchecked(&tcon->num_mkdirs),
42266 + atomic_read_unchecked(&tcon->num_rmdirs));
42267 seq_printf(m, "\nRenames: %d T2 Renames %d",
42268 - atomic_read(&tcon->num_renames),
42269 - atomic_read(&tcon->num_t2renames));
42270 + atomic_read_unchecked(&tcon->num_renames),
42271 + atomic_read_unchecked(&tcon->num_t2renames));
42272 seq_printf(m, "\nFindFirst: %d FNext %d "
42273 "FClose %d",
42274 - atomic_read(&tcon->num_ffirst),
42275 - atomic_read(&tcon->num_fnext),
42276 - atomic_read(&tcon->num_fclose));
42277 + atomic_read_unchecked(&tcon->num_ffirst),
42278 + atomic_read_unchecked(&tcon->num_fnext),
42279 + atomic_read_unchecked(&tcon->num_fclose));
42280 }
42281 }
42282 }
42283 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
42284 index 8f1fe32..38f9e27 100644
42285 --- a/fs/cifs/cifsfs.c
42286 +++ b/fs/cifs/cifsfs.c
42287 @@ -989,7 +989,7 @@ cifs_init_request_bufs(void)
42288 cifs_req_cachep = kmem_cache_create("cifs_request",
42289 CIFSMaxBufSize +
42290 MAX_CIFS_HDR_SIZE, 0,
42291 - SLAB_HWCACHE_ALIGN, NULL);
42292 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
42293 if (cifs_req_cachep == NULL)
42294 return -ENOMEM;
42295
42296 @@ -1016,7 +1016,7 @@ cifs_init_request_bufs(void)
42297 efficient to alloc 1 per page off the slab compared to 17K (5page)
42298 alloc of large cifs buffers even when page debugging is on */
42299 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
42300 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
42301 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
42302 NULL);
42303 if (cifs_sm_req_cachep == NULL) {
42304 mempool_destroy(cifs_req_poolp);
42305 @@ -1101,8 +1101,8 @@ init_cifs(void)
42306 atomic_set(&bufAllocCount, 0);
42307 atomic_set(&smBufAllocCount, 0);
42308 #ifdef CONFIG_CIFS_STATS2
42309 - atomic_set(&totBufAllocCount, 0);
42310 - atomic_set(&totSmBufAllocCount, 0);
42311 + atomic_set_unchecked(&totBufAllocCount, 0);
42312 + atomic_set_unchecked(&totSmBufAllocCount, 0);
42313 #endif /* CONFIG_CIFS_STATS2 */
42314
42315 atomic_set(&midCount, 0);
42316 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
42317 index 8238aa1..0347196 100644
42318 --- a/fs/cifs/cifsglob.h
42319 +++ b/fs/cifs/cifsglob.h
42320 @@ -392,28 +392,28 @@ struct cifs_tcon {
42321 __u16 Flags; /* optional support bits */
42322 enum statusEnum tidStatus;
42323 #ifdef CONFIG_CIFS_STATS
42324 - atomic_t num_smbs_sent;
42325 - atomic_t num_writes;
42326 - atomic_t num_reads;
42327 - atomic_t num_flushes;
42328 - atomic_t num_oplock_brks;
42329 - atomic_t num_opens;
42330 - atomic_t num_closes;
42331 - atomic_t num_deletes;
42332 - atomic_t num_mkdirs;
42333 - atomic_t num_posixopens;
42334 - atomic_t num_posixmkdirs;
42335 - atomic_t num_rmdirs;
42336 - atomic_t num_renames;
42337 - atomic_t num_t2renames;
42338 - atomic_t num_ffirst;
42339 - atomic_t num_fnext;
42340 - atomic_t num_fclose;
42341 - atomic_t num_hardlinks;
42342 - atomic_t num_symlinks;
42343 - atomic_t num_locks;
42344 - atomic_t num_acl_get;
42345 - atomic_t num_acl_set;
42346 + atomic_unchecked_t num_smbs_sent;
42347 + atomic_unchecked_t num_writes;
42348 + atomic_unchecked_t num_reads;
42349 + atomic_unchecked_t num_flushes;
42350 + atomic_unchecked_t num_oplock_brks;
42351 + atomic_unchecked_t num_opens;
42352 + atomic_unchecked_t num_closes;
42353 + atomic_unchecked_t num_deletes;
42354 + atomic_unchecked_t num_mkdirs;
42355 + atomic_unchecked_t num_posixopens;
42356 + atomic_unchecked_t num_posixmkdirs;
42357 + atomic_unchecked_t num_rmdirs;
42358 + atomic_unchecked_t num_renames;
42359 + atomic_unchecked_t num_t2renames;
42360 + atomic_unchecked_t num_ffirst;
42361 + atomic_unchecked_t num_fnext;
42362 + atomic_unchecked_t num_fclose;
42363 + atomic_unchecked_t num_hardlinks;
42364 + atomic_unchecked_t num_symlinks;
42365 + atomic_unchecked_t num_locks;
42366 + atomic_unchecked_t num_acl_get;
42367 + atomic_unchecked_t num_acl_set;
42368 #ifdef CONFIG_CIFS_STATS2
42369 unsigned long long time_writes;
42370 unsigned long long time_reads;
42371 @@ -628,7 +628,7 @@ convert_delimiter(char *path, char delim)
42372 }
42373
42374 #ifdef CONFIG_CIFS_STATS
42375 -#define cifs_stats_inc atomic_inc
42376 +#define cifs_stats_inc atomic_inc_unchecked
42377
42378 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
42379 unsigned int bytes)
42380 @@ -985,8 +985,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
42381 /* Various Debug counters */
42382 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
42383 #ifdef CONFIG_CIFS_STATS2
42384 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
42385 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
42386 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
42387 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
42388 #endif
42389 GLOBAL_EXTERN atomic_t smBufAllocCount;
42390 GLOBAL_EXTERN atomic_t midCount;
42391 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
42392 index 6b0e064..94e6c3c 100644
42393 --- a/fs/cifs/link.c
42394 +++ b/fs/cifs/link.c
42395 @@ -600,7 +600,7 @@ symlink_exit:
42396
42397 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
42398 {
42399 - char *p = nd_get_link(nd);
42400 + const char *p = nd_get_link(nd);
42401 if (!IS_ERR(p))
42402 kfree(p);
42403 }
42404 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
42405 index 703ef5c..2a44ed5 100644
42406 --- a/fs/cifs/misc.c
42407 +++ b/fs/cifs/misc.c
42408 @@ -156,7 +156,7 @@ cifs_buf_get(void)
42409 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
42410 atomic_inc(&bufAllocCount);
42411 #ifdef CONFIG_CIFS_STATS2
42412 - atomic_inc(&totBufAllocCount);
42413 + atomic_inc_unchecked(&totBufAllocCount);
42414 #endif /* CONFIG_CIFS_STATS2 */
42415 }
42416
42417 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
42418 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
42419 atomic_inc(&smBufAllocCount);
42420 #ifdef CONFIG_CIFS_STATS2
42421 - atomic_inc(&totSmBufAllocCount);
42422 + atomic_inc_unchecked(&totSmBufAllocCount);
42423 #endif /* CONFIG_CIFS_STATS2 */
42424
42425 }
42426 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
42427 index 6901578..d402eb5 100644
42428 --- a/fs/coda/cache.c
42429 +++ b/fs/coda/cache.c
42430 @@ -24,7 +24,7 @@
42431 #include "coda_linux.h"
42432 #include "coda_cache.h"
42433
42434 -static atomic_t permission_epoch = ATOMIC_INIT(0);
42435 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
42436
42437 /* replace or extend an acl cache hit */
42438 void coda_cache_enter(struct inode *inode, int mask)
42439 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
42440 struct coda_inode_info *cii = ITOC(inode);
42441
42442 spin_lock(&cii->c_lock);
42443 - cii->c_cached_epoch = atomic_read(&permission_epoch);
42444 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
42445 if (cii->c_uid != current_fsuid()) {
42446 cii->c_uid = current_fsuid();
42447 cii->c_cached_perm = mask;
42448 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
42449 {
42450 struct coda_inode_info *cii = ITOC(inode);
42451 spin_lock(&cii->c_lock);
42452 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
42453 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
42454 spin_unlock(&cii->c_lock);
42455 }
42456
42457 /* remove all acl caches */
42458 void coda_cache_clear_all(struct super_block *sb)
42459 {
42460 - atomic_inc(&permission_epoch);
42461 + atomic_inc_unchecked(&permission_epoch);
42462 }
42463
42464
42465 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
42466 spin_lock(&cii->c_lock);
42467 hit = (mask & cii->c_cached_perm) == mask &&
42468 cii->c_uid == current_fsuid() &&
42469 - cii->c_cached_epoch == atomic_read(&permission_epoch);
42470 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
42471 spin_unlock(&cii->c_lock);
42472
42473 return hit;
42474 diff --git a/fs/compat.c b/fs/compat.c
42475 index c987875..08771ca 100644
42476 --- a/fs/compat.c
42477 +++ b/fs/compat.c
42478 @@ -132,8 +132,8 @@ asmlinkage long compat_sys_utimes(const char __user *filename, struct compat_tim
42479 static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
42480 {
42481 compat_ino_t ino = stat->ino;
42482 - typeof(ubuf->st_uid) uid = 0;
42483 - typeof(ubuf->st_gid) gid = 0;
42484 + typeof(((struct compat_stat *)0)->st_uid) uid = 0;
42485 + typeof(((struct compat_stat *)0)->st_gid) gid = 0;
42486 int err;
42487
42488 SET_UID(uid, stat->uid);
42489 @@ -504,7 +504,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
42490
42491 set_fs(KERNEL_DS);
42492 /* The __user pointer cast is valid because of the set_fs() */
42493 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
42494 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
42495 set_fs(oldfs);
42496 /* truncating is ok because it's a user address */
42497 if (!ret)
42498 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
42499 goto out;
42500
42501 ret = -EINVAL;
42502 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
42503 + if (nr_segs > UIO_MAXIOV)
42504 goto out;
42505 if (nr_segs > fast_segs) {
42506 ret = -ENOMEM;
42507 @@ -845,6 +845,7 @@ struct compat_old_linux_dirent {
42508
42509 struct compat_readdir_callback {
42510 struct compat_old_linux_dirent __user *dirent;
42511 + struct file * file;
42512 int result;
42513 };
42514
42515 @@ -862,6 +863,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
42516 buf->result = -EOVERFLOW;
42517 return -EOVERFLOW;
42518 }
42519 +
42520 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
42521 + return 0;
42522 +
42523 buf->result++;
42524 dirent = buf->dirent;
42525 if (!access_ok(VERIFY_WRITE, dirent,
42526 @@ -894,6 +899,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
42527
42528 buf.result = 0;
42529 buf.dirent = dirent;
42530 + buf.file = file;
42531
42532 error = vfs_readdir(file, compat_fillonedir, &buf);
42533 if (buf.result)
42534 @@ -914,6 +920,7 @@ struct compat_linux_dirent {
42535 struct compat_getdents_callback {
42536 struct compat_linux_dirent __user *current_dir;
42537 struct compat_linux_dirent __user *previous;
42538 + struct file * file;
42539 int count;
42540 int error;
42541 };
42542 @@ -935,6 +942,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
42543 buf->error = -EOVERFLOW;
42544 return -EOVERFLOW;
42545 }
42546 +
42547 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
42548 + return 0;
42549 +
42550 dirent = buf->previous;
42551 if (dirent) {
42552 if (__put_user(offset, &dirent->d_off))
42553 @@ -982,6 +993,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
42554 buf.previous = NULL;
42555 buf.count = count;
42556 buf.error = 0;
42557 + buf.file = file;
42558
42559 error = vfs_readdir(file, compat_filldir, &buf);
42560 if (error >= 0)
42561 @@ -1003,6 +1015,7 @@ out:
42562 struct compat_getdents_callback64 {
42563 struct linux_dirent64 __user *current_dir;
42564 struct linux_dirent64 __user *previous;
42565 + struct file * file;
42566 int count;
42567 int error;
42568 };
42569 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
42570 buf->error = -EINVAL; /* only used if we fail.. */
42571 if (reclen > buf->count)
42572 return -EINVAL;
42573 +
42574 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
42575 + return 0;
42576 +
42577 dirent = buf->previous;
42578
42579 if (dirent) {
42580 @@ -1070,13 +1087,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
42581 buf.previous = NULL;
42582 buf.count = count;
42583 buf.error = 0;
42584 + buf.file = file;
42585
42586 error = vfs_readdir(file, compat_filldir64, &buf);
42587 if (error >= 0)
42588 error = buf.error;
42589 lastdirent = buf.previous;
42590 if (lastdirent) {
42591 - typeof(lastdirent->d_off) d_off = file->f_pos;
42592 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
42593 if (__put_user_unaligned(d_off, &lastdirent->d_off))
42594 error = -EFAULT;
42595 else
42596 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
42597 index 112e45a..b59845b 100644
42598 --- a/fs/compat_binfmt_elf.c
42599 +++ b/fs/compat_binfmt_elf.c
42600 @@ -30,11 +30,13 @@
42601 #undef elf_phdr
42602 #undef elf_shdr
42603 #undef elf_note
42604 +#undef elf_dyn
42605 #undef elf_addr_t
42606 #define elfhdr elf32_hdr
42607 #define elf_phdr elf32_phdr
42608 #define elf_shdr elf32_shdr
42609 #define elf_note elf32_note
42610 +#define elf_dyn Elf32_Dyn
42611 #define elf_addr_t Elf32_Addr
42612
42613 /*
42614 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
42615 index 51352de..93292ff 100644
42616 --- a/fs/compat_ioctl.c
42617 +++ b/fs/compat_ioctl.c
42618 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
42619
42620 err = get_user(palp, &up->palette);
42621 err |= get_user(length, &up->length);
42622 + if (err)
42623 + return -EFAULT;
42624
42625 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
42626 err = put_user(compat_ptr(palp), &up_native->palette);
42627 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
42628 return -EFAULT;
42629 if (__get_user(udata, &ss32->iomem_base))
42630 return -EFAULT;
42631 - ss.iomem_base = compat_ptr(udata);
42632 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
42633 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
42634 __get_user(ss.port_high, &ss32->port_high))
42635 return -EFAULT;
42636 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
42637 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
42638 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
42639 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
42640 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
42641 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
42642 return -EFAULT;
42643
42644 return ioctl_preallocate(file, p);
42645 @@ -1644,8 +1646,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
42646 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
42647 {
42648 unsigned int a, b;
42649 - a = *(unsigned int *)p;
42650 - b = *(unsigned int *)q;
42651 + a = *(const unsigned int *)p;
42652 + b = *(const unsigned int *)q;
42653 if (a > b)
42654 return 1;
42655 if (a < b)
42656 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
42657 index 9a37a9b..35792b6 100644
42658 --- a/fs/configfs/dir.c
42659 +++ b/fs/configfs/dir.c
42660 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
42661 }
42662 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
42663 struct configfs_dirent *next;
42664 - const char * name;
42665 + const unsigned char * name;
42666 + char d_name[sizeof(next->s_dentry->d_iname)];
42667 int len;
42668 struct inode *inode = NULL;
42669
42670 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
42671 continue;
42672
42673 name = configfs_get_name(next);
42674 - len = strlen(name);
42675 + if (next->s_dentry && name == next->s_dentry->d_iname) {
42676 + len = next->s_dentry->d_name.len;
42677 + memcpy(d_name, name, len);
42678 + name = d_name;
42679 + } else
42680 + len = strlen(name);
42681
42682 /*
42683 * We'll have a dentry and an inode for
42684 diff --git a/fs/dcache.c b/fs/dcache.c
42685 index f7908ae..920a680 100644
42686 --- a/fs/dcache.c
42687 +++ b/fs/dcache.c
42688 @@ -3042,7 +3042,7 @@ void __init vfs_caches_init(unsigned long mempages)
42689 mempages -= reserve;
42690
42691 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
42692 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
42693 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
42694
42695 dcache_init();
42696 inode_init();
42697 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
42698 index f3a257d..715ac0f 100644
42699 --- a/fs/debugfs/inode.c
42700 +++ b/fs/debugfs/inode.c
42701 @@ -261,7 +261,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
42702 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
42703 {
42704 return debugfs_create_file(name,
42705 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
42706 + S_IFDIR | S_IRWXU,
42707 +#else
42708 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
42709 +#endif
42710 parent, NULL, NULL);
42711 }
42712 EXPORT_SYMBOL_GPL(debugfs_create_dir);
42713 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
42714 index af11098..81e3bbe 100644
42715 --- a/fs/ecryptfs/inode.c
42716 +++ b/fs/ecryptfs/inode.c
42717 @@ -691,7 +691,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
42718 old_fs = get_fs();
42719 set_fs(get_ds());
42720 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
42721 - (char __user *)lower_buf,
42722 + (char __force_user *)lower_buf,
42723 lower_bufsiz);
42724 set_fs(old_fs);
42725 if (rc < 0)
42726 @@ -737,7 +737,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42727 }
42728 old_fs = get_fs();
42729 set_fs(get_ds());
42730 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
42731 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
42732 set_fs(old_fs);
42733 if (rc < 0) {
42734 kfree(buf);
42735 @@ -752,7 +752,7 @@ out:
42736 static void
42737 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
42738 {
42739 - char *buf = nd_get_link(nd);
42740 + const char *buf = nd_get_link(nd);
42741 if (!IS_ERR(buf)) {
42742 /* Free the char* */
42743 kfree(buf);
42744 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
42745 index 0dc5a3d..d3cdeea 100644
42746 --- a/fs/ecryptfs/miscdev.c
42747 +++ b/fs/ecryptfs/miscdev.c
42748 @@ -328,7 +328,7 @@ check_list:
42749 goto out_unlock_msg_ctx;
42750 i = 5;
42751 if (msg_ctx->msg) {
42752 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
42753 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
42754 goto out_unlock_msg_ctx;
42755 i += packet_length_size;
42756 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
42757 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
42758 index 608c1c3..7d040a8 100644
42759 --- a/fs/ecryptfs/read_write.c
42760 +++ b/fs/ecryptfs/read_write.c
42761 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
42762 return -EIO;
42763 fs_save = get_fs();
42764 set_fs(get_ds());
42765 - rc = vfs_write(lower_file, data, size, &offset);
42766 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
42767 set_fs(fs_save);
42768 mark_inode_dirty_sync(ecryptfs_inode);
42769 return rc;
42770 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
42771 return -EIO;
42772 fs_save = get_fs();
42773 set_fs(get_ds());
42774 - rc = vfs_read(lower_file, data, size, &offset);
42775 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
42776 set_fs(fs_save);
42777 return rc;
42778 }
42779 diff --git a/fs/exec.c b/fs/exec.c
42780 index 3625464..cdeecdb 100644
42781 --- a/fs/exec.c
42782 +++ b/fs/exec.c
42783 @@ -55,12 +55,28 @@
42784 #include <linux/pipe_fs_i.h>
42785 #include <linux/oom.h>
42786 #include <linux/compat.h>
42787 +#include <linux/random.h>
42788 +#include <linux/seq_file.h>
42789 +
42790 +#ifdef CONFIG_PAX_REFCOUNT
42791 +#include <linux/kallsyms.h>
42792 +#include <linux/kdebug.h>
42793 +#endif
42794
42795 #include <asm/uaccess.h>
42796 #include <asm/mmu_context.h>
42797 #include <asm/tlb.h>
42798 #include "internal.h"
42799
42800 +#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
42801 +void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
42802 +#endif
42803 +
42804 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
42805 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
42806 +EXPORT_SYMBOL(pax_set_initial_flags_func);
42807 +#endif
42808 +
42809 int core_uses_pid;
42810 char core_pattern[CORENAME_MAX_SIZE] = "core";
42811 unsigned int core_pipe_limit;
42812 @@ -70,7 +86,7 @@ struct core_name {
42813 char *corename;
42814 int used, size;
42815 };
42816 -static atomic_t call_count = ATOMIC_INIT(1);
42817 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
42818
42819 /* The maximal length of core_pattern is also specified in sysctl.c */
42820
42821 @@ -188,18 +204,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
42822 int write)
42823 {
42824 struct page *page;
42825 - int ret;
42826
42827 -#ifdef CONFIG_STACK_GROWSUP
42828 - if (write) {
42829 - ret = expand_downwards(bprm->vma, pos);
42830 - if (ret < 0)
42831 - return NULL;
42832 - }
42833 -#endif
42834 - ret = get_user_pages(current, bprm->mm, pos,
42835 - 1, write, 1, &page, NULL);
42836 - if (ret <= 0)
42837 + if (0 > expand_downwards(bprm->vma, pos))
42838 + return NULL;
42839 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
42840 return NULL;
42841
42842 if (write) {
42843 @@ -215,6 +223,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
42844 if (size <= ARG_MAX)
42845 return page;
42846
42847 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42848 + // only allow 512KB for argv+env on suid/sgid binaries
42849 + // to prevent easy ASLR exhaustion
42850 + if (((bprm->cred->euid != current_euid()) ||
42851 + (bprm->cred->egid != current_egid())) &&
42852 + (size > (512 * 1024))) {
42853 + put_page(page);
42854 + return NULL;
42855 + }
42856 +#endif
42857 +
42858 /*
42859 * Limit to 1/4-th the stack size for the argv+env strings.
42860 * This ensures that:
42861 @@ -274,6 +293,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
42862 vma->vm_end = STACK_TOP_MAX;
42863 vma->vm_start = vma->vm_end - PAGE_SIZE;
42864 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
42865 +
42866 +#ifdef CONFIG_PAX_SEGMEXEC
42867 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
42868 +#endif
42869 +
42870 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
42871 INIT_LIST_HEAD(&vma->anon_vma_chain);
42872
42873 @@ -288,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
42874 mm->stack_vm = mm->total_vm = 1;
42875 up_write(&mm->mmap_sem);
42876 bprm->p = vma->vm_end - sizeof(void *);
42877 +
42878 +#ifdef CONFIG_PAX_RANDUSTACK
42879 + if (randomize_va_space)
42880 + bprm->p ^= random32() & ~PAGE_MASK;
42881 +#endif
42882 +
42883 return 0;
42884 err:
42885 up_write(&mm->mmap_sem);
42886 @@ -396,19 +426,7 @@ err:
42887 return err;
42888 }
42889
42890 -struct user_arg_ptr {
42891 -#ifdef CONFIG_COMPAT
42892 - bool is_compat;
42893 -#endif
42894 - union {
42895 - const char __user *const __user *native;
42896 -#ifdef CONFIG_COMPAT
42897 - compat_uptr_t __user *compat;
42898 -#endif
42899 - } ptr;
42900 -};
42901 -
42902 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
42903 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
42904 {
42905 const char __user *native;
42906
42907 @@ -417,14 +435,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
42908 compat_uptr_t compat;
42909
42910 if (get_user(compat, argv.ptr.compat + nr))
42911 - return ERR_PTR(-EFAULT);
42912 + return (const char __force_user *)ERR_PTR(-EFAULT);
42913
42914 return compat_ptr(compat);
42915 }
42916 #endif
42917
42918 if (get_user(native, argv.ptr.native + nr))
42919 - return ERR_PTR(-EFAULT);
42920 + return (const char __force_user *)ERR_PTR(-EFAULT);
42921
42922 return native;
42923 }
42924 @@ -443,7 +461,7 @@ static int count(struct user_arg_ptr argv, int max)
42925 if (!p)
42926 break;
42927
42928 - if (IS_ERR(p))
42929 + if (IS_ERR((const char __force_kernel *)p))
42930 return -EFAULT;
42931
42932 if (i++ >= max)
42933 @@ -477,7 +495,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
42934
42935 ret = -EFAULT;
42936 str = get_user_arg_ptr(argv, argc);
42937 - if (IS_ERR(str))
42938 + if (IS_ERR((const char __force_kernel *)str))
42939 goto out;
42940
42941 len = strnlen_user(str, MAX_ARG_STRLEN);
42942 @@ -559,7 +577,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
42943 int r;
42944 mm_segment_t oldfs = get_fs();
42945 struct user_arg_ptr argv = {
42946 - .ptr.native = (const char __user *const __user *)__argv,
42947 + .ptr.native = (const char __force_user *const __force_user *)__argv,
42948 };
42949
42950 set_fs(KERNEL_DS);
42951 @@ -594,7 +612,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
42952 unsigned long new_end = old_end - shift;
42953 struct mmu_gather tlb;
42954
42955 - BUG_ON(new_start > new_end);
42956 + if (new_start >= new_end || new_start < mmap_min_addr)
42957 + return -ENOMEM;
42958
42959 /*
42960 * ensure there are no vmas between where we want to go
42961 @@ -603,6 +622,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
42962 if (vma != find_vma(mm, new_start))
42963 return -EFAULT;
42964
42965 +#ifdef CONFIG_PAX_SEGMEXEC
42966 + BUG_ON(pax_find_mirror_vma(vma));
42967 +#endif
42968 +
42969 /*
42970 * cover the whole range: [new_start, old_end)
42971 */
42972 @@ -683,10 +706,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
42973 stack_top = arch_align_stack(stack_top);
42974 stack_top = PAGE_ALIGN(stack_top);
42975
42976 - if (unlikely(stack_top < mmap_min_addr) ||
42977 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
42978 - return -ENOMEM;
42979 -
42980 stack_shift = vma->vm_end - stack_top;
42981
42982 bprm->p -= stack_shift;
42983 @@ -698,8 +717,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
42984 bprm->exec -= stack_shift;
42985
42986 down_write(&mm->mmap_sem);
42987 +
42988 + /* Move stack pages down in memory. */
42989 + if (stack_shift) {
42990 + ret = shift_arg_pages(vma, stack_shift);
42991 + if (ret)
42992 + goto out_unlock;
42993 + }
42994 +
42995 vm_flags = VM_STACK_FLAGS;
42996
42997 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42998 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42999 + vm_flags &= ~VM_EXEC;
43000 +
43001 +#ifdef CONFIG_PAX_MPROTECT
43002 + if (mm->pax_flags & MF_PAX_MPROTECT)
43003 + vm_flags &= ~VM_MAYEXEC;
43004 +#endif
43005 +
43006 + }
43007 +#endif
43008 +
43009 /*
43010 * Adjust stack execute permissions; explicitly enable for
43011 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
43012 @@ -718,13 +757,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43013 goto out_unlock;
43014 BUG_ON(prev != vma);
43015
43016 - /* Move stack pages down in memory. */
43017 - if (stack_shift) {
43018 - ret = shift_arg_pages(vma, stack_shift);
43019 - if (ret)
43020 - goto out_unlock;
43021 - }
43022 -
43023 /* mprotect_fixup is overkill to remove the temporary stack flags */
43024 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
43025
43026 @@ -805,7 +837,7 @@ int kernel_read(struct file *file, loff_t offset,
43027 old_fs = get_fs();
43028 set_fs(get_ds());
43029 /* The cast to a user pointer is valid due to the set_fs() */
43030 - result = vfs_read(file, (void __user *)addr, count, &pos);
43031 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
43032 set_fs(old_fs);
43033 return result;
43034 }
43035 @@ -1067,6 +1099,21 @@ void set_task_comm(struct task_struct *tsk, char *buf)
43036 perf_event_comm(tsk);
43037 }
43038
43039 +static void filename_to_taskname(char *tcomm, const char *fn, unsigned int len)
43040 +{
43041 + int i, ch;
43042 +
43043 + /* Copies the binary name from after last slash */
43044 + for (i = 0; (ch = *(fn++)) != '\0';) {
43045 + if (ch == '/')
43046 + i = 0; /* overwrite what we wrote */
43047 + else
43048 + if (i < len - 1)
43049 + tcomm[i++] = ch;
43050 + }
43051 + tcomm[i] = '\0';
43052 +}
43053 +
43054 int flush_old_exec(struct linux_binprm * bprm)
43055 {
43056 int retval;
43057 @@ -1081,6 +1128,7 @@ int flush_old_exec(struct linux_binprm * bprm)
43058
43059 set_mm_exe_file(bprm->mm, bprm->file);
43060
43061 + filename_to_taskname(bprm->tcomm, bprm->filename, sizeof(bprm->tcomm));
43062 /*
43063 * Release all of the old mmap stuff
43064 */
43065 @@ -1112,10 +1160,6 @@ EXPORT_SYMBOL(would_dump);
43066
43067 void setup_new_exec(struct linux_binprm * bprm)
43068 {
43069 - int i, ch;
43070 - const char *name;
43071 - char tcomm[sizeof(current->comm)];
43072 -
43073 arch_pick_mmap_layout(current->mm);
43074
43075 /* This is the point of no return */
43076 @@ -1126,18 +1170,7 @@ void setup_new_exec(struct linux_binprm * bprm)
43077 else
43078 set_dumpable(current->mm, suid_dumpable);
43079
43080 - name = bprm->filename;
43081 -
43082 - /* Copies the binary name from after last slash */
43083 - for (i=0; (ch = *(name++)) != '\0';) {
43084 - if (ch == '/')
43085 - i = 0; /* overwrite what we wrote */
43086 - else
43087 - if (i < (sizeof(tcomm) - 1))
43088 - tcomm[i++] = ch;
43089 - }
43090 - tcomm[i] = '\0';
43091 - set_task_comm(current, tcomm);
43092 + set_task_comm(current, bprm->tcomm);
43093
43094 /* Set the new mm task size. We have to do that late because it may
43095 * depend on TIF_32BIT which is only updated in flush_thread() on
43096 @@ -1247,7 +1280,7 @@ int check_unsafe_exec(struct linux_binprm *bprm)
43097 }
43098 rcu_read_unlock();
43099
43100 - if (p->fs->users > n_fs) {
43101 + if (atomic_read(&p->fs->users) > n_fs) {
43102 bprm->unsafe |= LSM_UNSAFE_SHARE;
43103 } else {
43104 res = -EAGAIN;
43105 @@ -1442,6 +1475,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
43106
43107 EXPORT_SYMBOL(search_binary_handler);
43108
43109 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43110 +static DEFINE_PER_CPU(u64, exec_counter);
43111 +static int __init init_exec_counters(void)
43112 +{
43113 + unsigned int cpu;
43114 +
43115 + for_each_possible_cpu(cpu) {
43116 + per_cpu(exec_counter, cpu) = (u64)cpu;
43117 + }
43118 +
43119 + return 0;
43120 +}
43121 +early_initcall(init_exec_counters);
43122 +static inline void increment_exec_counter(void)
43123 +{
43124 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
43125 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
43126 +}
43127 +#else
43128 +static inline void increment_exec_counter(void) {}
43129 +#endif
43130 +
43131 /*
43132 * sys_execve() executes a new program.
43133 */
43134 @@ -1450,6 +1505,11 @@ static int do_execve_common(const char *filename,
43135 struct user_arg_ptr envp,
43136 struct pt_regs *regs)
43137 {
43138 +#ifdef CONFIG_GRKERNSEC
43139 + struct file *old_exec_file;
43140 + struct acl_subject_label *old_acl;
43141 + struct rlimit old_rlim[RLIM_NLIMITS];
43142 +#endif
43143 struct linux_binprm *bprm;
43144 struct file *file;
43145 struct files_struct *displaced;
43146 @@ -1457,6 +1517,8 @@ static int do_execve_common(const char *filename,
43147 int retval;
43148 const struct cred *cred = current_cred();
43149
43150 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
43151 +
43152 /*
43153 * We move the actual failure in case of RLIMIT_NPROC excess from
43154 * set*uid() to execve() because too many poorly written programs
43155 @@ -1497,12 +1559,27 @@ static int do_execve_common(const char *filename,
43156 if (IS_ERR(file))
43157 goto out_unmark;
43158
43159 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
43160 + retval = -EPERM;
43161 + goto out_file;
43162 + }
43163 +
43164 sched_exec();
43165
43166 bprm->file = file;
43167 bprm->filename = filename;
43168 bprm->interp = filename;
43169
43170 + if (gr_process_user_ban()) {
43171 + retval = -EPERM;
43172 + goto out_file;
43173 + }
43174 +
43175 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
43176 + retval = -EACCES;
43177 + goto out_file;
43178 + }
43179 +
43180 retval = bprm_mm_init(bprm);
43181 if (retval)
43182 goto out_file;
43183 @@ -1519,24 +1596,65 @@ static int do_execve_common(const char *filename,
43184 if (retval < 0)
43185 goto out;
43186
43187 +#ifdef CONFIG_GRKERNSEC
43188 + old_acl = current->acl;
43189 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
43190 + old_exec_file = current->exec_file;
43191 + get_file(file);
43192 + current->exec_file = file;
43193 +#endif
43194 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43195 + /* limit suid stack to 8MB
43196 + we saved the old limits above and will restore them if this exec fails
43197 + */
43198 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
43199 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
43200 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
43201 +#endif
43202 +
43203 + if (!gr_tpe_allow(file)) {
43204 + retval = -EACCES;
43205 + goto out_fail;
43206 + }
43207 +
43208 + if (gr_check_crash_exec(file)) {
43209 + retval = -EACCES;
43210 + goto out_fail;
43211 + }
43212 +
43213 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
43214 + bprm->unsafe);
43215 + if (retval < 0)
43216 + goto out_fail;
43217 +
43218 retval = copy_strings_kernel(1, &bprm->filename, bprm);
43219 if (retval < 0)
43220 - goto out;
43221 + goto out_fail;
43222
43223 bprm->exec = bprm->p;
43224 retval = copy_strings(bprm->envc, envp, bprm);
43225 if (retval < 0)
43226 - goto out;
43227 + goto out_fail;
43228
43229 retval = copy_strings(bprm->argc, argv, bprm);
43230 if (retval < 0)
43231 - goto out;
43232 + goto out_fail;
43233 +
43234 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
43235 +
43236 + gr_handle_exec_args(bprm, argv);
43237
43238 retval = search_binary_handler(bprm,regs);
43239 if (retval < 0)
43240 - goto out;
43241 + goto out_fail;
43242 +#ifdef CONFIG_GRKERNSEC
43243 + if (old_exec_file)
43244 + fput(old_exec_file);
43245 +#endif
43246
43247 /* execve succeeded */
43248 +
43249 + increment_exec_counter();
43250 current->fs->in_exec = 0;
43251 current->in_execve = 0;
43252 acct_update_integrals(current);
43253 @@ -1545,6 +1663,14 @@ static int do_execve_common(const char *filename,
43254 put_files_struct(displaced);
43255 return retval;
43256
43257 +out_fail:
43258 +#ifdef CONFIG_GRKERNSEC
43259 + current->acl = old_acl;
43260 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
43261 + fput(current->exec_file);
43262 + current->exec_file = old_exec_file;
43263 +#endif
43264 +
43265 out:
43266 if (bprm->mm) {
43267 acct_arg_size(bprm, 0);
43268 @@ -1618,7 +1744,7 @@ static int expand_corename(struct core_name *cn)
43269 {
43270 char *old_corename = cn->corename;
43271
43272 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
43273 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
43274 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
43275
43276 if (!cn->corename) {
43277 @@ -1715,7 +1841,7 @@ static int format_corename(struct core_name *cn, long signr)
43278 int pid_in_pattern = 0;
43279 int err = 0;
43280
43281 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
43282 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
43283 cn->corename = kmalloc(cn->size, GFP_KERNEL);
43284 cn->used = 0;
43285
43286 @@ -1812,6 +1938,218 @@ out:
43287 return ispipe;
43288 }
43289
43290 +int pax_check_flags(unsigned long *flags)
43291 +{
43292 + int retval = 0;
43293 +
43294 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
43295 + if (*flags & MF_PAX_SEGMEXEC)
43296 + {
43297 + *flags &= ~MF_PAX_SEGMEXEC;
43298 + retval = -EINVAL;
43299 + }
43300 +#endif
43301 +
43302 + if ((*flags & MF_PAX_PAGEEXEC)
43303 +
43304 +#ifdef CONFIG_PAX_PAGEEXEC
43305 + && (*flags & MF_PAX_SEGMEXEC)
43306 +#endif
43307 +
43308 + )
43309 + {
43310 + *flags &= ~MF_PAX_PAGEEXEC;
43311 + retval = -EINVAL;
43312 + }
43313 +
43314 + if ((*flags & MF_PAX_MPROTECT)
43315 +
43316 +#ifdef CONFIG_PAX_MPROTECT
43317 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
43318 +#endif
43319 +
43320 + )
43321 + {
43322 + *flags &= ~MF_PAX_MPROTECT;
43323 + retval = -EINVAL;
43324 + }
43325 +
43326 + if ((*flags & MF_PAX_EMUTRAMP)
43327 +
43328 +#ifdef CONFIG_PAX_EMUTRAMP
43329 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
43330 +#endif
43331 +
43332 + )
43333 + {
43334 + *flags &= ~MF_PAX_EMUTRAMP;
43335 + retval = -EINVAL;
43336 + }
43337 +
43338 + return retval;
43339 +}
43340 +
43341 +EXPORT_SYMBOL(pax_check_flags);
43342 +
43343 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43344 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
43345 +{
43346 + struct task_struct *tsk = current;
43347 + struct mm_struct *mm = current->mm;
43348 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
43349 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
43350 + char *path_exec = NULL;
43351 + char *path_fault = NULL;
43352 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
43353 +
43354 + if (buffer_exec && buffer_fault) {
43355 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
43356 +
43357 + down_read(&mm->mmap_sem);
43358 + vma = mm->mmap;
43359 + while (vma && (!vma_exec || !vma_fault)) {
43360 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
43361 + vma_exec = vma;
43362 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
43363 + vma_fault = vma;
43364 + vma = vma->vm_next;
43365 + }
43366 + if (vma_exec) {
43367 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
43368 + if (IS_ERR(path_exec))
43369 + path_exec = "<path too long>";
43370 + else {
43371 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
43372 + if (path_exec) {
43373 + *path_exec = 0;
43374 + path_exec = buffer_exec;
43375 + } else
43376 + path_exec = "<path too long>";
43377 + }
43378 + }
43379 + if (vma_fault) {
43380 + start = vma_fault->vm_start;
43381 + end = vma_fault->vm_end;
43382 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
43383 + if (vma_fault->vm_file) {
43384 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
43385 + if (IS_ERR(path_fault))
43386 + path_fault = "<path too long>";
43387 + else {
43388 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
43389 + if (path_fault) {
43390 + *path_fault = 0;
43391 + path_fault = buffer_fault;
43392 + } else
43393 + path_fault = "<path too long>";
43394 + }
43395 + } else
43396 + path_fault = "<anonymous mapping>";
43397 + }
43398 + up_read(&mm->mmap_sem);
43399 + }
43400 + if (tsk->signal->curr_ip)
43401 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
43402 + else
43403 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
43404 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
43405 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
43406 + task_uid(tsk), task_euid(tsk), pc, sp);
43407 + free_page((unsigned long)buffer_exec);
43408 + free_page((unsigned long)buffer_fault);
43409 + pax_report_insns(regs, pc, sp);
43410 + do_coredump(SIGKILL, SIGKILL, regs);
43411 +}
43412 +#endif
43413 +
43414 +#ifdef CONFIG_PAX_REFCOUNT
43415 +void pax_report_refcount_overflow(struct pt_regs *regs)
43416 +{
43417 + if (current->signal->curr_ip)
43418 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
43419 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
43420 + else
43421 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
43422 + current->comm, task_pid_nr(current), current_uid(), current_euid());
43423 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
43424 + show_regs(regs);
43425 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
43426 +}
43427 +#endif
43428 +
43429 +#ifdef CONFIG_PAX_USERCOPY
43430 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
43431 +int object_is_on_stack(const void *obj, unsigned long len)
43432 +{
43433 + const void * const stack = task_stack_page(current);
43434 + const void * const stackend = stack + THREAD_SIZE;
43435 +
43436 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
43437 + const void *frame = NULL;
43438 + const void *oldframe;
43439 +#endif
43440 +
43441 + if (obj + len < obj)
43442 + return -1;
43443 +
43444 + if (obj + len <= stack || stackend <= obj)
43445 + return 0;
43446 +
43447 + if (obj < stack || stackend < obj + len)
43448 + return -1;
43449 +
43450 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
43451 + oldframe = __builtin_frame_address(1);
43452 + if (oldframe)
43453 + frame = __builtin_frame_address(2);
43454 + /*
43455 + low ----------------------------------------------> high
43456 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
43457 + ^----------------^
43458 + allow copies only within here
43459 + */
43460 + while (stack <= frame && frame < stackend) {
43461 + /* if obj + len extends past the last frame, this
43462 + check won't pass and the next frame will be 0,
43463 + causing us to bail out and correctly report
43464 + the copy as invalid
43465 + */
43466 + if (obj + len <= frame)
43467 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
43468 + oldframe = frame;
43469 + frame = *(const void * const *)frame;
43470 + }
43471 + return -1;
43472 +#else
43473 + return 1;
43474 +#endif
43475 +}
43476 +
43477 +__noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
43478 +{
43479 + if (current->signal->curr_ip)
43480 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
43481 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
43482 + else
43483 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
43484 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
43485 + dump_stack();
43486 + gr_handle_kernel_exploit();
43487 + do_group_exit(SIGKILL);
43488 +}
43489 +#endif
43490 +
43491 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
43492 +void pax_track_stack(void)
43493 +{
43494 + unsigned long sp = (unsigned long)&sp;
43495 + if (sp < current_thread_info()->lowest_stack &&
43496 + sp > (unsigned long)task_stack_page(current))
43497 + current_thread_info()->lowest_stack = sp;
43498 +}
43499 +EXPORT_SYMBOL(pax_track_stack);
43500 +#endif
43501 +
43502 static int zap_process(struct task_struct *start, int exit_code)
43503 {
43504 struct task_struct *t;
43505 @@ -2023,17 +2361,17 @@ static void wait_for_dump_helpers(struct file *file)
43506 pipe = file->f_path.dentry->d_inode->i_pipe;
43507
43508 pipe_lock(pipe);
43509 - pipe->readers++;
43510 - pipe->writers--;
43511 + atomic_inc(&pipe->readers);
43512 + atomic_dec(&pipe->writers);
43513
43514 - while ((pipe->readers > 1) && (!signal_pending(current))) {
43515 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
43516 wake_up_interruptible_sync(&pipe->wait);
43517 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
43518 pipe_wait(pipe);
43519 }
43520
43521 - pipe->readers--;
43522 - pipe->writers++;
43523 + atomic_dec(&pipe->readers);
43524 + atomic_inc(&pipe->writers);
43525 pipe_unlock(pipe);
43526
43527 }
43528 @@ -2094,7 +2432,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
43529 int retval = 0;
43530 int flag = 0;
43531 int ispipe;
43532 - static atomic_t core_dump_count = ATOMIC_INIT(0);
43533 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
43534 struct coredump_params cprm = {
43535 .signr = signr,
43536 .regs = regs,
43537 @@ -2109,6 +2447,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
43538
43539 audit_core_dumps(signr);
43540
43541 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
43542 + gr_handle_brute_attach(current, cprm.mm_flags);
43543 +
43544 binfmt = mm->binfmt;
43545 if (!binfmt || !binfmt->core_dump)
43546 goto fail;
43547 @@ -2176,7 +2517,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
43548 }
43549 cprm.limit = RLIM_INFINITY;
43550
43551 - dump_count = atomic_inc_return(&core_dump_count);
43552 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
43553 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
43554 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
43555 task_tgid_vnr(current), current->comm);
43556 @@ -2203,6 +2544,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
43557 } else {
43558 struct inode *inode;
43559
43560 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
43561 +
43562 if (cprm.limit < binfmt->min_coredump)
43563 goto fail_unlock;
43564
43565 @@ -2246,7 +2589,7 @@ close_fail:
43566 filp_close(cprm.file, NULL);
43567 fail_dropcount:
43568 if (ispipe)
43569 - atomic_dec(&core_dump_count);
43570 + atomic_dec_unchecked(&core_dump_count);
43571 fail_unlock:
43572 kfree(cn.corename);
43573 fail_corename:
43574 @@ -2265,7 +2608,7 @@ fail:
43575 */
43576 int dump_write(struct file *file, const void *addr, int nr)
43577 {
43578 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
43579 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
43580 }
43581 EXPORT_SYMBOL(dump_write);
43582
43583 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
43584 index a8cbe1b..fed04cb 100644
43585 --- a/fs/ext2/balloc.c
43586 +++ b/fs/ext2/balloc.c
43587 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
43588
43589 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
43590 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
43591 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
43592 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
43593 sbi->s_resuid != current_fsuid() &&
43594 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
43595 return 0;
43596 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
43597 index a203892..4e64db5 100644
43598 --- a/fs/ext3/balloc.c
43599 +++ b/fs/ext3/balloc.c
43600 @@ -1446,9 +1446,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
43601
43602 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
43603 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
43604 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
43605 + if (free_blocks < root_blocks + 1 &&
43606 !use_reservation && sbi->s_resuid != current_fsuid() &&
43607 - (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
43608 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
43609 + !capable_nolog(CAP_SYS_RESOURCE)) {
43610 return 0;
43611 }
43612 return 1;
43613 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
43614 index 12ccacd..a6035fce0 100644
43615 --- a/fs/ext4/balloc.c
43616 +++ b/fs/ext4/balloc.c
43617 @@ -436,8 +436,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
43618 /* Hm, nope. Are (enough) root reserved clusters available? */
43619 if (sbi->s_resuid == current_fsuid() ||
43620 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
43621 - capable(CAP_SYS_RESOURCE) ||
43622 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
43623 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
43624 + capable_nolog(CAP_SYS_RESOURCE)) {
43625
43626 if (free_clusters >= (nclusters + dirty_clusters))
43627 return 1;
43628 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
43629 index 5b0e26a..0aa002d 100644
43630 --- a/fs/ext4/ext4.h
43631 +++ b/fs/ext4/ext4.h
43632 @@ -1208,19 +1208,19 @@ struct ext4_sb_info {
43633 unsigned long s_mb_last_start;
43634
43635 /* stats for buddy allocator */
43636 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
43637 - atomic_t s_bal_success; /* we found long enough chunks */
43638 - atomic_t s_bal_allocated; /* in blocks */
43639 - atomic_t s_bal_ex_scanned; /* total extents scanned */
43640 - atomic_t s_bal_goals; /* goal hits */
43641 - atomic_t s_bal_breaks; /* too long searches */
43642 - atomic_t s_bal_2orders; /* 2^order hits */
43643 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
43644 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
43645 + atomic_unchecked_t s_bal_allocated; /* in blocks */
43646 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
43647 + atomic_unchecked_t s_bal_goals; /* goal hits */
43648 + atomic_unchecked_t s_bal_breaks; /* too long searches */
43649 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
43650 spinlock_t s_bal_lock;
43651 unsigned long s_mb_buddies_generated;
43652 unsigned long long s_mb_generation_time;
43653 - atomic_t s_mb_lost_chunks;
43654 - atomic_t s_mb_preallocated;
43655 - atomic_t s_mb_discarded;
43656 + atomic_unchecked_t s_mb_lost_chunks;
43657 + atomic_unchecked_t s_mb_preallocated;
43658 + atomic_unchecked_t s_mb_discarded;
43659 atomic_t s_lock_busy;
43660
43661 /* locality groups */
43662 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
43663 index e2d8be8..c7f0ce9 100644
43664 --- a/fs/ext4/mballoc.c
43665 +++ b/fs/ext4/mballoc.c
43666 @@ -1794,7 +1794,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
43667 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
43668
43669 if (EXT4_SB(sb)->s_mb_stats)
43670 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
43671 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
43672
43673 break;
43674 }
43675 @@ -2088,7 +2088,7 @@ repeat:
43676 ac->ac_status = AC_STATUS_CONTINUE;
43677 ac->ac_flags |= EXT4_MB_HINT_FIRST;
43678 cr = 3;
43679 - atomic_inc(&sbi->s_mb_lost_chunks);
43680 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
43681 goto repeat;
43682 }
43683 }
43684 @@ -2592,25 +2592,25 @@ int ext4_mb_release(struct super_block *sb)
43685 if (sbi->s_mb_stats) {
43686 ext4_msg(sb, KERN_INFO,
43687 "mballoc: %u blocks %u reqs (%u success)",
43688 - atomic_read(&sbi->s_bal_allocated),
43689 - atomic_read(&sbi->s_bal_reqs),
43690 - atomic_read(&sbi->s_bal_success));
43691 + atomic_read_unchecked(&sbi->s_bal_allocated),
43692 + atomic_read_unchecked(&sbi->s_bal_reqs),
43693 + atomic_read_unchecked(&sbi->s_bal_success));
43694 ext4_msg(sb, KERN_INFO,
43695 "mballoc: %u extents scanned, %u goal hits, "
43696 "%u 2^N hits, %u breaks, %u lost",
43697 - atomic_read(&sbi->s_bal_ex_scanned),
43698 - atomic_read(&sbi->s_bal_goals),
43699 - atomic_read(&sbi->s_bal_2orders),
43700 - atomic_read(&sbi->s_bal_breaks),
43701 - atomic_read(&sbi->s_mb_lost_chunks));
43702 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
43703 + atomic_read_unchecked(&sbi->s_bal_goals),
43704 + atomic_read_unchecked(&sbi->s_bal_2orders),
43705 + atomic_read_unchecked(&sbi->s_bal_breaks),
43706 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
43707 ext4_msg(sb, KERN_INFO,
43708 "mballoc: %lu generated and it took %Lu",
43709 sbi->s_mb_buddies_generated,
43710 sbi->s_mb_generation_time);
43711 ext4_msg(sb, KERN_INFO,
43712 "mballoc: %u preallocated, %u discarded",
43713 - atomic_read(&sbi->s_mb_preallocated),
43714 - atomic_read(&sbi->s_mb_discarded));
43715 + atomic_read_unchecked(&sbi->s_mb_preallocated),
43716 + atomic_read_unchecked(&sbi->s_mb_discarded));
43717 }
43718
43719 free_percpu(sbi->s_locality_groups);
43720 @@ -3096,16 +3096,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
43721 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
43722
43723 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
43724 - atomic_inc(&sbi->s_bal_reqs);
43725 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
43726 + atomic_inc_unchecked(&sbi->s_bal_reqs);
43727 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
43728 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
43729 - atomic_inc(&sbi->s_bal_success);
43730 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
43731 + atomic_inc_unchecked(&sbi->s_bal_success);
43732 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
43733 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
43734 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
43735 - atomic_inc(&sbi->s_bal_goals);
43736 + atomic_inc_unchecked(&sbi->s_bal_goals);
43737 if (ac->ac_found > sbi->s_mb_max_to_scan)
43738 - atomic_inc(&sbi->s_bal_breaks);
43739 + atomic_inc_unchecked(&sbi->s_bal_breaks);
43740 }
43741
43742 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
43743 @@ -3509,7 +3509,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
43744 trace_ext4_mb_new_inode_pa(ac, pa);
43745
43746 ext4_mb_use_inode_pa(ac, pa);
43747 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
43748 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
43749
43750 ei = EXT4_I(ac->ac_inode);
43751 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
43752 @@ -3569,7 +3569,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
43753 trace_ext4_mb_new_group_pa(ac, pa);
43754
43755 ext4_mb_use_group_pa(ac, pa);
43756 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
43757 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
43758
43759 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
43760 lg = ac->ac_lg;
43761 @@ -3658,7 +3658,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
43762 * from the bitmap and continue.
43763 */
43764 }
43765 - atomic_add(free, &sbi->s_mb_discarded);
43766 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
43767
43768 return err;
43769 }
43770 @@ -3676,7 +3676,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
43771 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
43772 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
43773 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
43774 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
43775 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
43776 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
43777
43778 return 0;
43779 diff --git a/fs/fcntl.c b/fs/fcntl.c
43780 index 22764c7..86372c9 100644
43781 --- a/fs/fcntl.c
43782 +++ b/fs/fcntl.c
43783 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
43784 if (err)
43785 return err;
43786
43787 + if (gr_handle_chroot_fowner(pid, type))
43788 + return -ENOENT;
43789 + if (gr_check_protected_task_fowner(pid, type))
43790 + return -EACCES;
43791 +
43792 f_modown(filp, pid, type, force);
43793 return 0;
43794 }
43795 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
43796
43797 static int f_setown_ex(struct file *filp, unsigned long arg)
43798 {
43799 - struct f_owner_ex * __user owner_p = (void * __user)arg;
43800 + struct f_owner_ex __user *owner_p = (void __user *)arg;
43801 struct f_owner_ex owner;
43802 struct pid *pid;
43803 int type;
43804 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
43805
43806 static int f_getown_ex(struct file *filp, unsigned long arg)
43807 {
43808 - struct f_owner_ex * __user owner_p = (void * __user)arg;
43809 + struct f_owner_ex __user *owner_p = (void __user *)arg;
43810 struct f_owner_ex owner;
43811 int ret = 0;
43812
43813 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
43814 switch (cmd) {
43815 case F_DUPFD:
43816 case F_DUPFD_CLOEXEC:
43817 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
43818 if (arg >= rlimit(RLIMIT_NOFILE))
43819 break;
43820 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
43821 diff --git a/fs/fifo.c b/fs/fifo.c
43822 index b1a524d..4ee270e 100644
43823 --- a/fs/fifo.c
43824 +++ b/fs/fifo.c
43825 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
43826 */
43827 filp->f_op = &read_pipefifo_fops;
43828 pipe->r_counter++;
43829 - if (pipe->readers++ == 0)
43830 + if (atomic_inc_return(&pipe->readers) == 1)
43831 wake_up_partner(inode);
43832
43833 - if (!pipe->writers) {
43834 + if (!atomic_read(&pipe->writers)) {
43835 if ((filp->f_flags & O_NONBLOCK)) {
43836 /* suppress POLLHUP until we have
43837 * seen a writer */
43838 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
43839 * errno=ENXIO when there is no process reading the FIFO.
43840 */
43841 ret = -ENXIO;
43842 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
43843 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
43844 goto err;
43845
43846 filp->f_op = &write_pipefifo_fops;
43847 pipe->w_counter++;
43848 - if (!pipe->writers++)
43849 + if (atomic_inc_return(&pipe->writers) == 1)
43850 wake_up_partner(inode);
43851
43852 - if (!pipe->readers) {
43853 + if (!atomic_read(&pipe->readers)) {
43854 wait_for_partner(inode, &pipe->r_counter);
43855 if (signal_pending(current))
43856 goto err_wr;
43857 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
43858 */
43859 filp->f_op = &rdwr_pipefifo_fops;
43860
43861 - pipe->readers++;
43862 - pipe->writers++;
43863 + atomic_inc(&pipe->readers);
43864 + atomic_inc(&pipe->writers);
43865 pipe->r_counter++;
43866 pipe->w_counter++;
43867 - if (pipe->readers == 1 || pipe->writers == 1)
43868 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
43869 wake_up_partner(inode);
43870 break;
43871
43872 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
43873 return 0;
43874
43875 err_rd:
43876 - if (!--pipe->readers)
43877 + if (atomic_dec_and_test(&pipe->readers))
43878 wake_up_interruptible(&pipe->wait);
43879 ret = -ERESTARTSYS;
43880 goto err;
43881
43882 err_wr:
43883 - if (!--pipe->writers)
43884 + if (atomic_dec_and_test(&pipe->writers))
43885 wake_up_interruptible(&pipe->wait);
43886 ret = -ERESTARTSYS;
43887 goto err;
43888
43889 err:
43890 - if (!pipe->readers && !pipe->writers)
43891 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
43892 free_pipe_info(inode);
43893
43894 err_nocleanup:
43895 diff --git a/fs/file.c b/fs/file.c
43896 index 4c6992d..104cdea 100644
43897 --- a/fs/file.c
43898 +++ b/fs/file.c
43899 @@ -15,6 +15,7 @@
43900 #include <linux/slab.h>
43901 #include <linux/vmalloc.h>
43902 #include <linux/file.h>
43903 +#include <linux/security.h>
43904 #include <linux/fdtable.h>
43905 #include <linux/bitops.h>
43906 #include <linux/interrupt.h>
43907 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
43908 * N.B. For clone tasks sharing a files structure, this test
43909 * will limit the total number of files that can be opened.
43910 */
43911 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
43912 if (nr >= rlimit(RLIMIT_NOFILE))
43913 return -EMFILE;
43914
43915 diff --git a/fs/filesystems.c b/fs/filesystems.c
43916 index 0845f84..7b4ebef 100644
43917 --- a/fs/filesystems.c
43918 +++ b/fs/filesystems.c
43919 @@ -274,7 +274,12 @@ struct file_system_type *get_fs_type(const char *name)
43920 int len = dot ? dot - name : strlen(name);
43921
43922 fs = __get_fs_type(name, len);
43923 +
43924 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
43925 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
43926 +#else
43927 if (!fs && (request_module("%.*s", len, name) == 0))
43928 +#endif
43929 fs = __get_fs_type(name, len);
43930
43931 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
43932 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
43933 index 78b519c..a8b4979 100644
43934 --- a/fs/fs_struct.c
43935 +++ b/fs/fs_struct.c
43936 @@ -4,6 +4,7 @@
43937 #include <linux/path.h>
43938 #include <linux/slab.h>
43939 #include <linux/fs_struct.h>
43940 +#include <linux/grsecurity.h>
43941 #include "internal.h"
43942
43943 static inline void path_get_longterm(struct path *path)
43944 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
43945 old_root = fs->root;
43946 fs->root = *path;
43947 path_get_longterm(path);
43948 + gr_set_chroot_entries(current, path);
43949 write_seqcount_end(&fs->seq);
43950 spin_unlock(&fs->lock);
43951 if (old_root.dentry)
43952 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
43953 && fs->root.mnt == old_root->mnt) {
43954 path_get_longterm(new_root);
43955 fs->root = *new_root;
43956 + gr_set_chroot_entries(p, new_root);
43957 count++;
43958 }
43959 if (fs->pwd.dentry == old_root->dentry
43960 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
43961 spin_lock(&fs->lock);
43962 write_seqcount_begin(&fs->seq);
43963 tsk->fs = NULL;
43964 - kill = !--fs->users;
43965 + gr_clear_chroot_entries(tsk);
43966 + kill = !atomic_dec_return(&fs->users);
43967 write_seqcount_end(&fs->seq);
43968 spin_unlock(&fs->lock);
43969 task_unlock(tsk);
43970 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
43971 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
43972 /* We don't need to lock fs - think why ;-) */
43973 if (fs) {
43974 - fs->users = 1;
43975 + atomic_set(&fs->users, 1);
43976 fs->in_exec = 0;
43977 spin_lock_init(&fs->lock);
43978 seqcount_init(&fs->seq);
43979 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
43980 spin_lock(&old->lock);
43981 fs->root = old->root;
43982 path_get_longterm(&fs->root);
43983 + /* instead of calling gr_set_chroot_entries here,
43984 + we call it from every caller of this function
43985 + */
43986 fs->pwd = old->pwd;
43987 path_get_longterm(&fs->pwd);
43988 spin_unlock(&old->lock);
43989 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
43990
43991 task_lock(current);
43992 spin_lock(&fs->lock);
43993 - kill = !--fs->users;
43994 + kill = !atomic_dec_return(&fs->users);
43995 current->fs = new_fs;
43996 + gr_set_chroot_entries(current, &new_fs->root);
43997 spin_unlock(&fs->lock);
43998 task_unlock(current);
43999
44000 @@ -164,13 +172,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
44001
44002 int current_umask(void)
44003 {
44004 - return current->fs->umask;
44005 + return current->fs->umask | gr_acl_umask();
44006 }
44007 EXPORT_SYMBOL(current_umask);
44008
44009 /* to be mentioned only in INIT_TASK */
44010 struct fs_struct init_fs = {
44011 - .users = 1,
44012 + .users = ATOMIC_INIT(1),
44013 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
44014 .seq = SEQCNT_ZERO,
44015 .umask = 0022,
44016 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
44017 task_lock(current);
44018
44019 spin_lock(&init_fs.lock);
44020 - init_fs.users++;
44021 + atomic_inc(&init_fs.users);
44022 spin_unlock(&init_fs.lock);
44023
44024 spin_lock(&fs->lock);
44025 current->fs = &init_fs;
44026 - kill = !--fs->users;
44027 + gr_set_chroot_entries(current, &current->fs->root);
44028 + kill = !atomic_dec_return(&fs->users);
44029 spin_unlock(&fs->lock);
44030
44031 task_unlock(current);
44032 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
44033 index 9905350..02eaec4 100644
44034 --- a/fs/fscache/cookie.c
44035 +++ b/fs/fscache/cookie.c
44036 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
44037 parent ? (char *) parent->def->name : "<no-parent>",
44038 def->name, netfs_data);
44039
44040 - fscache_stat(&fscache_n_acquires);
44041 + fscache_stat_unchecked(&fscache_n_acquires);
44042
44043 /* if there's no parent cookie, then we don't create one here either */
44044 if (!parent) {
44045 - fscache_stat(&fscache_n_acquires_null);
44046 + fscache_stat_unchecked(&fscache_n_acquires_null);
44047 _leave(" [no parent]");
44048 return NULL;
44049 }
44050 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
44051 /* allocate and initialise a cookie */
44052 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
44053 if (!cookie) {
44054 - fscache_stat(&fscache_n_acquires_oom);
44055 + fscache_stat_unchecked(&fscache_n_acquires_oom);
44056 _leave(" [ENOMEM]");
44057 return NULL;
44058 }
44059 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44060
44061 switch (cookie->def->type) {
44062 case FSCACHE_COOKIE_TYPE_INDEX:
44063 - fscache_stat(&fscache_n_cookie_index);
44064 + fscache_stat_unchecked(&fscache_n_cookie_index);
44065 break;
44066 case FSCACHE_COOKIE_TYPE_DATAFILE:
44067 - fscache_stat(&fscache_n_cookie_data);
44068 + fscache_stat_unchecked(&fscache_n_cookie_data);
44069 break;
44070 default:
44071 - fscache_stat(&fscache_n_cookie_special);
44072 + fscache_stat_unchecked(&fscache_n_cookie_special);
44073 break;
44074 }
44075
44076 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44077 if (fscache_acquire_non_index_cookie(cookie) < 0) {
44078 atomic_dec(&parent->n_children);
44079 __fscache_cookie_put(cookie);
44080 - fscache_stat(&fscache_n_acquires_nobufs);
44081 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
44082 _leave(" = NULL");
44083 return NULL;
44084 }
44085 }
44086
44087 - fscache_stat(&fscache_n_acquires_ok);
44088 + fscache_stat_unchecked(&fscache_n_acquires_ok);
44089 _leave(" = %p", cookie);
44090 return cookie;
44091 }
44092 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
44093 cache = fscache_select_cache_for_object(cookie->parent);
44094 if (!cache) {
44095 up_read(&fscache_addremove_sem);
44096 - fscache_stat(&fscache_n_acquires_no_cache);
44097 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
44098 _leave(" = -ENOMEDIUM [no cache]");
44099 return -ENOMEDIUM;
44100 }
44101 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
44102 object = cache->ops->alloc_object(cache, cookie);
44103 fscache_stat_d(&fscache_n_cop_alloc_object);
44104 if (IS_ERR(object)) {
44105 - fscache_stat(&fscache_n_object_no_alloc);
44106 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
44107 ret = PTR_ERR(object);
44108 goto error;
44109 }
44110
44111 - fscache_stat(&fscache_n_object_alloc);
44112 + fscache_stat_unchecked(&fscache_n_object_alloc);
44113
44114 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
44115
44116 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
44117 struct fscache_object *object;
44118 struct hlist_node *_p;
44119
44120 - fscache_stat(&fscache_n_updates);
44121 + fscache_stat_unchecked(&fscache_n_updates);
44122
44123 if (!cookie) {
44124 - fscache_stat(&fscache_n_updates_null);
44125 + fscache_stat_unchecked(&fscache_n_updates_null);
44126 _leave(" [no cookie]");
44127 return;
44128 }
44129 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
44130 struct fscache_object *object;
44131 unsigned long event;
44132
44133 - fscache_stat(&fscache_n_relinquishes);
44134 + fscache_stat_unchecked(&fscache_n_relinquishes);
44135 if (retire)
44136 - fscache_stat(&fscache_n_relinquishes_retire);
44137 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
44138
44139 if (!cookie) {
44140 - fscache_stat(&fscache_n_relinquishes_null);
44141 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
44142 _leave(" [no cookie]");
44143 return;
44144 }
44145 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
44146
44147 /* wait for the cookie to finish being instantiated (or to fail) */
44148 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
44149 - fscache_stat(&fscache_n_relinquishes_waitcrt);
44150 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
44151 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
44152 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
44153 }
44154 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
44155 index f6aad48..88dcf26 100644
44156 --- a/fs/fscache/internal.h
44157 +++ b/fs/fscache/internal.h
44158 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
44159 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
44160 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
44161
44162 -extern atomic_t fscache_n_op_pend;
44163 -extern atomic_t fscache_n_op_run;
44164 -extern atomic_t fscache_n_op_enqueue;
44165 -extern atomic_t fscache_n_op_deferred_release;
44166 -extern atomic_t fscache_n_op_release;
44167 -extern atomic_t fscache_n_op_gc;
44168 -extern atomic_t fscache_n_op_cancelled;
44169 -extern atomic_t fscache_n_op_rejected;
44170 +extern atomic_unchecked_t fscache_n_op_pend;
44171 +extern atomic_unchecked_t fscache_n_op_run;
44172 +extern atomic_unchecked_t fscache_n_op_enqueue;
44173 +extern atomic_unchecked_t fscache_n_op_deferred_release;
44174 +extern atomic_unchecked_t fscache_n_op_release;
44175 +extern atomic_unchecked_t fscache_n_op_gc;
44176 +extern atomic_unchecked_t fscache_n_op_cancelled;
44177 +extern atomic_unchecked_t fscache_n_op_rejected;
44178
44179 -extern atomic_t fscache_n_attr_changed;
44180 -extern atomic_t fscache_n_attr_changed_ok;
44181 -extern atomic_t fscache_n_attr_changed_nobufs;
44182 -extern atomic_t fscache_n_attr_changed_nomem;
44183 -extern atomic_t fscache_n_attr_changed_calls;
44184 +extern atomic_unchecked_t fscache_n_attr_changed;
44185 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
44186 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
44187 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
44188 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
44189
44190 -extern atomic_t fscache_n_allocs;
44191 -extern atomic_t fscache_n_allocs_ok;
44192 -extern atomic_t fscache_n_allocs_wait;
44193 -extern atomic_t fscache_n_allocs_nobufs;
44194 -extern atomic_t fscache_n_allocs_intr;
44195 -extern atomic_t fscache_n_allocs_object_dead;
44196 -extern atomic_t fscache_n_alloc_ops;
44197 -extern atomic_t fscache_n_alloc_op_waits;
44198 +extern atomic_unchecked_t fscache_n_allocs;
44199 +extern atomic_unchecked_t fscache_n_allocs_ok;
44200 +extern atomic_unchecked_t fscache_n_allocs_wait;
44201 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
44202 +extern atomic_unchecked_t fscache_n_allocs_intr;
44203 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
44204 +extern atomic_unchecked_t fscache_n_alloc_ops;
44205 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
44206
44207 -extern atomic_t fscache_n_retrievals;
44208 -extern atomic_t fscache_n_retrievals_ok;
44209 -extern atomic_t fscache_n_retrievals_wait;
44210 -extern atomic_t fscache_n_retrievals_nodata;
44211 -extern atomic_t fscache_n_retrievals_nobufs;
44212 -extern atomic_t fscache_n_retrievals_intr;
44213 -extern atomic_t fscache_n_retrievals_nomem;
44214 -extern atomic_t fscache_n_retrievals_object_dead;
44215 -extern atomic_t fscache_n_retrieval_ops;
44216 -extern atomic_t fscache_n_retrieval_op_waits;
44217 +extern atomic_unchecked_t fscache_n_retrievals;
44218 +extern atomic_unchecked_t fscache_n_retrievals_ok;
44219 +extern atomic_unchecked_t fscache_n_retrievals_wait;
44220 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
44221 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
44222 +extern atomic_unchecked_t fscache_n_retrievals_intr;
44223 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
44224 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
44225 +extern atomic_unchecked_t fscache_n_retrieval_ops;
44226 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
44227
44228 -extern atomic_t fscache_n_stores;
44229 -extern atomic_t fscache_n_stores_ok;
44230 -extern atomic_t fscache_n_stores_again;
44231 -extern atomic_t fscache_n_stores_nobufs;
44232 -extern atomic_t fscache_n_stores_oom;
44233 -extern atomic_t fscache_n_store_ops;
44234 -extern atomic_t fscache_n_store_calls;
44235 -extern atomic_t fscache_n_store_pages;
44236 -extern atomic_t fscache_n_store_radix_deletes;
44237 -extern atomic_t fscache_n_store_pages_over_limit;
44238 +extern atomic_unchecked_t fscache_n_stores;
44239 +extern atomic_unchecked_t fscache_n_stores_ok;
44240 +extern atomic_unchecked_t fscache_n_stores_again;
44241 +extern atomic_unchecked_t fscache_n_stores_nobufs;
44242 +extern atomic_unchecked_t fscache_n_stores_oom;
44243 +extern atomic_unchecked_t fscache_n_store_ops;
44244 +extern atomic_unchecked_t fscache_n_store_calls;
44245 +extern atomic_unchecked_t fscache_n_store_pages;
44246 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
44247 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
44248
44249 -extern atomic_t fscache_n_store_vmscan_not_storing;
44250 -extern atomic_t fscache_n_store_vmscan_gone;
44251 -extern atomic_t fscache_n_store_vmscan_busy;
44252 -extern atomic_t fscache_n_store_vmscan_cancelled;
44253 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
44254 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
44255 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
44256 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
44257
44258 -extern atomic_t fscache_n_marks;
44259 -extern atomic_t fscache_n_uncaches;
44260 +extern atomic_unchecked_t fscache_n_marks;
44261 +extern atomic_unchecked_t fscache_n_uncaches;
44262
44263 -extern atomic_t fscache_n_acquires;
44264 -extern atomic_t fscache_n_acquires_null;
44265 -extern atomic_t fscache_n_acquires_no_cache;
44266 -extern atomic_t fscache_n_acquires_ok;
44267 -extern atomic_t fscache_n_acquires_nobufs;
44268 -extern atomic_t fscache_n_acquires_oom;
44269 +extern atomic_unchecked_t fscache_n_acquires;
44270 +extern atomic_unchecked_t fscache_n_acquires_null;
44271 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
44272 +extern atomic_unchecked_t fscache_n_acquires_ok;
44273 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
44274 +extern atomic_unchecked_t fscache_n_acquires_oom;
44275
44276 -extern atomic_t fscache_n_updates;
44277 -extern atomic_t fscache_n_updates_null;
44278 -extern atomic_t fscache_n_updates_run;
44279 +extern atomic_unchecked_t fscache_n_updates;
44280 +extern atomic_unchecked_t fscache_n_updates_null;
44281 +extern atomic_unchecked_t fscache_n_updates_run;
44282
44283 -extern atomic_t fscache_n_relinquishes;
44284 -extern atomic_t fscache_n_relinquishes_null;
44285 -extern atomic_t fscache_n_relinquishes_waitcrt;
44286 -extern atomic_t fscache_n_relinquishes_retire;
44287 +extern atomic_unchecked_t fscache_n_relinquishes;
44288 +extern atomic_unchecked_t fscache_n_relinquishes_null;
44289 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
44290 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
44291
44292 -extern atomic_t fscache_n_cookie_index;
44293 -extern atomic_t fscache_n_cookie_data;
44294 -extern atomic_t fscache_n_cookie_special;
44295 +extern atomic_unchecked_t fscache_n_cookie_index;
44296 +extern atomic_unchecked_t fscache_n_cookie_data;
44297 +extern atomic_unchecked_t fscache_n_cookie_special;
44298
44299 -extern atomic_t fscache_n_object_alloc;
44300 -extern atomic_t fscache_n_object_no_alloc;
44301 -extern atomic_t fscache_n_object_lookups;
44302 -extern atomic_t fscache_n_object_lookups_negative;
44303 -extern atomic_t fscache_n_object_lookups_positive;
44304 -extern atomic_t fscache_n_object_lookups_timed_out;
44305 -extern atomic_t fscache_n_object_created;
44306 -extern atomic_t fscache_n_object_avail;
44307 -extern atomic_t fscache_n_object_dead;
44308 +extern atomic_unchecked_t fscache_n_object_alloc;
44309 +extern atomic_unchecked_t fscache_n_object_no_alloc;
44310 +extern atomic_unchecked_t fscache_n_object_lookups;
44311 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
44312 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
44313 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
44314 +extern atomic_unchecked_t fscache_n_object_created;
44315 +extern atomic_unchecked_t fscache_n_object_avail;
44316 +extern atomic_unchecked_t fscache_n_object_dead;
44317
44318 -extern atomic_t fscache_n_checkaux_none;
44319 -extern atomic_t fscache_n_checkaux_okay;
44320 -extern atomic_t fscache_n_checkaux_update;
44321 -extern atomic_t fscache_n_checkaux_obsolete;
44322 +extern atomic_unchecked_t fscache_n_checkaux_none;
44323 +extern atomic_unchecked_t fscache_n_checkaux_okay;
44324 +extern atomic_unchecked_t fscache_n_checkaux_update;
44325 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
44326
44327 extern atomic_t fscache_n_cop_alloc_object;
44328 extern atomic_t fscache_n_cop_lookup_object;
44329 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
44330 atomic_inc(stat);
44331 }
44332
44333 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
44334 +{
44335 + atomic_inc_unchecked(stat);
44336 +}
44337 +
44338 static inline void fscache_stat_d(atomic_t *stat)
44339 {
44340 atomic_dec(stat);
44341 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
44342
44343 #define __fscache_stat(stat) (NULL)
44344 #define fscache_stat(stat) do {} while (0)
44345 +#define fscache_stat_unchecked(stat) do {} while (0)
44346 #define fscache_stat_d(stat) do {} while (0)
44347 #endif
44348
44349 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
44350 index b6b897c..0ffff9c 100644
44351 --- a/fs/fscache/object.c
44352 +++ b/fs/fscache/object.c
44353 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
44354 /* update the object metadata on disk */
44355 case FSCACHE_OBJECT_UPDATING:
44356 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
44357 - fscache_stat(&fscache_n_updates_run);
44358 + fscache_stat_unchecked(&fscache_n_updates_run);
44359 fscache_stat(&fscache_n_cop_update_object);
44360 object->cache->ops->update_object(object);
44361 fscache_stat_d(&fscache_n_cop_update_object);
44362 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
44363 spin_lock(&object->lock);
44364 object->state = FSCACHE_OBJECT_DEAD;
44365 spin_unlock(&object->lock);
44366 - fscache_stat(&fscache_n_object_dead);
44367 + fscache_stat_unchecked(&fscache_n_object_dead);
44368 goto terminal_transit;
44369
44370 /* handle the parent cache of this object being withdrawn from
44371 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
44372 spin_lock(&object->lock);
44373 object->state = FSCACHE_OBJECT_DEAD;
44374 spin_unlock(&object->lock);
44375 - fscache_stat(&fscache_n_object_dead);
44376 + fscache_stat_unchecked(&fscache_n_object_dead);
44377 goto terminal_transit;
44378
44379 /* complain about the object being woken up once it is
44380 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
44381 parent->cookie->def->name, cookie->def->name,
44382 object->cache->tag->name);
44383
44384 - fscache_stat(&fscache_n_object_lookups);
44385 + fscache_stat_unchecked(&fscache_n_object_lookups);
44386 fscache_stat(&fscache_n_cop_lookup_object);
44387 ret = object->cache->ops->lookup_object(object);
44388 fscache_stat_d(&fscache_n_cop_lookup_object);
44389 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
44390 if (ret == -ETIMEDOUT) {
44391 /* probably stuck behind another object, so move this one to
44392 * the back of the queue */
44393 - fscache_stat(&fscache_n_object_lookups_timed_out);
44394 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
44395 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
44396 }
44397
44398 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
44399
44400 spin_lock(&object->lock);
44401 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
44402 - fscache_stat(&fscache_n_object_lookups_negative);
44403 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
44404
44405 /* transit here to allow write requests to begin stacking up
44406 * and read requests to begin returning ENODATA */
44407 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
44408 * result, in which case there may be data available */
44409 spin_lock(&object->lock);
44410 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
44411 - fscache_stat(&fscache_n_object_lookups_positive);
44412 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
44413
44414 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
44415
44416 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
44417 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
44418 } else {
44419 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
44420 - fscache_stat(&fscache_n_object_created);
44421 + fscache_stat_unchecked(&fscache_n_object_created);
44422
44423 object->state = FSCACHE_OBJECT_AVAILABLE;
44424 spin_unlock(&object->lock);
44425 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
44426 fscache_enqueue_dependents(object);
44427
44428 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
44429 - fscache_stat(&fscache_n_object_avail);
44430 + fscache_stat_unchecked(&fscache_n_object_avail);
44431
44432 _leave("");
44433 }
44434 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
44435 enum fscache_checkaux result;
44436
44437 if (!object->cookie->def->check_aux) {
44438 - fscache_stat(&fscache_n_checkaux_none);
44439 + fscache_stat_unchecked(&fscache_n_checkaux_none);
44440 return FSCACHE_CHECKAUX_OKAY;
44441 }
44442
44443 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
44444 switch (result) {
44445 /* entry okay as is */
44446 case FSCACHE_CHECKAUX_OKAY:
44447 - fscache_stat(&fscache_n_checkaux_okay);
44448 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
44449 break;
44450
44451 /* entry requires update */
44452 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
44453 - fscache_stat(&fscache_n_checkaux_update);
44454 + fscache_stat_unchecked(&fscache_n_checkaux_update);
44455 break;
44456
44457 /* entry requires deletion */
44458 case FSCACHE_CHECKAUX_OBSOLETE:
44459 - fscache_stat(&fscache_n_checkaux_obsolete);
44460 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
44461 break;
44462
44463 default:
44464 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
44465 index 30afdfa..2256596 100644
44466 --- a/fs/fscache/operation.c
44467 +++ b/fs/fscache/operation.c
44468 @@ -17,7 +17,7 @@
44469 #include <linux/slab.h>
44470 #include "internal.h"
44471
44472 -atomic_t fscache_op_debug_id;
44473 +atomic_unchecked_t fscache_op_debug_id;
44474 EXPORT_SYMBOL(fscache_op_debug_id);
44475
44476 /**
44477 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
44478 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
44479 ASSERTCMP(atomic_read(&op->usage), >, 0);
44480
44481 - fscache_stat(&fscache_n_op_enqueue);
44482 + fscache_stat_unchecked(&fscache_n_op_enqueue);
44483 switch (op->flags & FSCACHE_OP_TYPE) {
44484 case FSCACHE_OP_ASYNC:
44485 _debug("queue async");
44486 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
44487 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
44488 if (op->processor)
44489 fscache_enqueue_operation(op);
44490 - fscache_stat(&fscache_n_op_run);
44491 + fscache_stat_unchecked(&fscache_n_op_run);
44492 }
44493
44494 /*
44495 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
44496 if (object->n_ops > 1) {
44497 atomic_inc(&op->usage);
44498 list_add_tail(&op->pend_link, &object->pending_ops);
44499 - fscache_stat(&fscache_n_op_pend);
44500 + fscache_stat_unchecked(&fscache_n_op_pend);
44501 } else if (!list_empty(&object->pending_ops)) {
44502 atomic_inc(&op->usage);
44503 list_add_tail(&op->pend_link, &object->pending_ops);
44504 - fscache_stat(&fscache_n_op_pend);
44505 + fscache_stat_unchecked(&fscache_n_op_pend);
44506 fscache_start_operations(object);
44507 } else {
44508 ASSERTCMP(object->n_in_progress, ==, 0);
44509 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
44510 object->n_exclusive++; /* reads and writes must wait */
44511 atomic_inc(&op->usage);
44512 list_add_tail(&op->pend_link, &object->pending_ops);
44513 - fscache_stat(&fscache_n_op_pend);
44514 + fscache_stat_unchecked(&fscache_n_op_pend);
44515 ret = 0;
44516 } else {
44517 /* not allowed to submit ops in any other state */
44518 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
44519 if (object->n_exclusive > 0) {
44520 atomic_inc(&op->usage);
44521 list_add_tail(&op->pend_link, &object->pending_ops);
44522 - fscache_stat(&fscache_n_op_pend);
44523 + fscache_stat_unchecked(&fscache_n_op_pend);
44524 } else if (!list_empty(&object->pending_ops)) {
44525 atomic_inc(&op->usage);
44526 list_add_tail(&op->pend_link, &object->pending_ops);
44527 - fscache_stat(&fscache_n_op_pend);
44528 + fscache_stat_unchecked(&fscache_n_op_pend);
44529 fscache_start_operations(object);
44530 } else {
44531 ASSERTCMP(object->n_exclusive, ==, 0);
44532 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
44533 object->n_ops++;
44534 atomic_inc(&op->usage);
44535 list_add_tail(&op->pend_link, &object->pending_ops);
44536 - fscache_stat(&fscache_n_op_pend);
44537 + fscache_stat_unchecked(&fscache_n_op_pend);
44538 ret = 0;
44539 } else if (object->state == FSCACHE_OBJECT_DYING ||
44540 object->state == FSCACHE_OBJECT_LC_DYING ||
44541 object->state == FSCACHE_OBJECT_WITHDRAWING) {
44542 - fscache_stat(&fscache_n_op_rejected);
44543 + fscache_stat_unchecked(&fscache_n_op_rejected);
44544 ret = -ENOBUFS;
44545 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
44546 fscache_report_unexpected_submission(object, op, ostate);
44547 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
44548
44549 ret = -EBUSY;
44550 if (!list_empty(&op->pend_link)) {
44551 - fscache_stat(&fscache_n_op_cancelled);
44552 + fscache_stat_unchecked(&fscache_n_op_cancelled);
44553 list_del_init(&op->pend_link);
44554 object->n_ops--;
44555 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
44556 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
44557 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
44558 BUG();
44559
44560 - fscache_stat(&fscache_n_op_release);
44561 + fscache_stat_unchecked(&fscache_n_op_release);
44562
44563 if (op->release) {
44564 op->release(op);
44565 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
44566 * lock, and defer it otherwise */
44567 if (!spin_trylock(&object->lock)) {
44568 _debug("defer put");
44569 - fscache_stat(&fscache_n_op_deferred_release);
44570 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
44571
44572 cache = object->cache;
44573 spin_lock(&cache->op_gc_list_lock);
44574 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
44575
44576 _debug("GC DEFERRED REL OBJ%x OP%x",
44577 object->debug_id, op->debug_id);
44578 - fscache_stat(&fscache_n_op_gc);
44579 + fscache_stat_unchecked(&fscache_n_op_gc);
44580
44581 ASSERTCMP(atomic_read(&op->usage), ==, 0);
44582
44583 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
44584 index 3f7a59b..cf196cc 100644
44585 --- a/fs/fscache/page.c
44586 +++ b/fs/fscache/page.c
44587 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
44588 val = radix_tree_lookup(&cookie->stores, page->index);
44589 if (!val) {
44590 rcu_read_unlock();
44591 - fscache_stat(&fscache_n_store_vmscan_not_storing);
44592 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
44593 __fscache_uncache_page(cookie, page);
44594 return true;
44595 }
44596 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
44597 spin_unlock(&cookie->stores_lock);
44598
44599 if (xpage) {
44600 - fscache_stat(&fscache_n_store_vmscan_cancelled);
44601 - fscache_stat(&fscache_n_store_radix_deletes);
44602 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
44603 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
44604 ASSERTCMP(xpage, ==, page);
44605 } else {
44606 - fscache_stat(&fscache_n_store_vmscan_gone);
44607 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
44608 }
44609
44610 wake_up_bit(&cookie->flags, 0);
44611 @@ -107,7 +107,7 @@ page_busy:
44612 /* we might want to wait here, but that could deadlock the allocator as
44613 * the work threads writing to the cache may all end up sleeping
44614 * on memory allocation */
44615 - fscache_stat(&fscache_n_store_vmscan_busy);
44616 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
44617 return false;
44618 }
44619 EXPORT_SYMBOL(__fscache_maybe_release_page);
44620 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
44621 FSCACHE_COOKIE_STORING_TAG);
44622 if (!radix_tree_tag_get(&cookie->stores, page->index,
44623 FSCACHE_COOKIE_PENDING_TAG)) {
44624 - fscache_stat(&fscache_n_store_radix_deletes);
44625 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
44626 xpage = radix_tree_delete(&cookie->stores, page->index);
44627 }
44628 spin_unlock(&cookie->stores_lock);
44629 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
44630
44631 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
44632
44633 - fscache_stat(&fscache_n_attr_changed_calls);
44634 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
44635
44636 if (fscache_object_is_active(object)) {
44637 fscache_stat(&fscache_n_cop_attr_changed);
44638 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
44639
44640 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
44641
44642 - fscache_stat(&fscache_n_attr_changed);
44643 + fscache_stat_unchecked(&fscache_n_attr_changed);
44644
44645 op = kzalloc(sizeof(*op), GFP_KERNEL);
44646 if (!op) {
44647 - fscache_stat(&fscache_n_attr_changed_nomem);
44648 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
44649 _leave(" = -ENOMEM");
44650 return -ENOMEM;
44651 }
44652 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
44653 if (fscache_submit_exclusive_op(object, op) < 0)
44654 goto nobufs;
44655 spin_unlock(&cookie->lock);
44656 - fscache_stat(&fscache_n_attr_changed_ok);
44657 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
44658 fscache_put_operation(op);
44659 _leave(" = 0");
44660 return 0;
44661 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
44662 nobufs:
44663 spin_unlock(&cookie->lock);
44664 kfree(op);
44665 - fscache_stat(&fscache_n_attr_changed_nobufs);
44666 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
44667 _leave(" = %d", -ENOBUFS);
44668 return -ENOBUFS;
44669 }
44670 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
44671 /* allocate a retrieval operation and attempt to submit it */
44672 op = kzalloc(sizeof(*op), GFP_NOIO);
44673 if (!op) {
44674 - fscache_stat(&fscache_n_retrievals_nomem);
44675 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
44676 return NULL;
44677 }
44678
44679 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
44680 return 0;
44681 }
44682
44683 - fscache_stat(&fscache_n_retrievals_wait);
44684 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
44685
44686 jif = jiffies;
44687 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
44688 fscache_wait_bit_interruptible,
44689 TASK_INTERRUPTIBLE) != 0) {
44690 - fscache_stat(&fscache_n_retrievals_intr);
44691 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
44692 _leave(" = -ERESTARTSYS");
44693 return -ERESTARTSYS;
44694 }
44695 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
44696 */
44697 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
44698 struct fscache_retrieval *op,
44699 - atomic_t *stat_op_waits,
44700 - atomic_t *stat_object_dead)
44701 + atomic_unchecked_t *stat_op_waits,
44702 + atomic_unchecked_t *stat_object_dead)
44703 {
44704 int ret;
44705
44706 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
44707 goto check_if_dead;
44708
44709 _debug(">>> WT");
44710 - fscache_stat(stat_op_waits);
44711 + fscache_stat_unchecked(stat_op_waits);
44712 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
44713 fscache_wait_bit_interruptible,
44714 TASK_INTERRUPTIBLE) < 0) {
44715 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
44716
44717 check_if_dead:
44718 if (unlikely(fscache_object_is_dead(object))) {
44719 - fscache_stat(stat_object_dead);
44720 + fscache_stat_unchecked(stat_object_dead);
44721 return -ENOBUFS;
44722 }
44723 return 0;
44724 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
44725
44726 _enter("%p,%p,,,", cookie, page);
44727
44728 - fscache_stat(&fscache_n_retrievals);
44729 + fscache_stat_unchecked(&fscache_n_retrievals);
44730
44731 if (hlist_empty(&cookie->backing_objects))
44732 goto nobufs;
44733 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
44734 goto nobufs_unlock;
44735 spin_unlock(&cookie->lock);
44736
44737 - fscache_stat(&fscache_n_retrieval_ops);
44738 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
44739
44740 /* pin the netfs read context in case we need to do the actual netfs
44741 * read because we've encountered a cache read failure */
44742 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
44743
44744 error:
44745 if (ret == -ENOMEM)
44746 - fscache_stat(&fscache_n_retrievals_nomem);
44747 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
44748 else if (ret == -ERESTARTSYS)
44749 - fscache_stat(&fscache_n_retrievals_intr);
44750 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
44751 else if (ret == -ENODATA)
44752 - fscache_stat(&fscache_n_retrievals_nodata);
44753 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
44754 else if (ret < 0)
44755 - fscache_stat(&fscache_n_retrievals_nobufs);
44756 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
44757 else
44758 - fscache_stat(&fscache_n_retrievals_ok);
44759 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
44760
44761 fscache_put_retrieval(op);
44762 _leave(" = %d", ret);
44763 @@ -429,7 +429,7 @@ nobufs_unlock:
44764 spin_unlock(&cookie->lock);
44765 kfree(op);
44766 nobufs:
44767 - fscache_stat(&fscache_n_retrievals_nobufs);
44768 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
44769 _leave(" = -ENOBUFS");
44770 return -ENOBUFS;
44771 }
44772 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
44773
44774 _enter("%p,,%d,,,", cookie, *nr_pages);
44775
44776 - fscache_stat(&fscache_n_retrievals);
44777 + fscache_stat_unchecked(&fscache_n_retrievals);
44778
44779 if (hlist_empty(&cookie->backing_objects))
44780 goto nobufs;
44781 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
44782 goto nobufs_unlock;
44783 spin_unlock(&cookie->lock);
44784
44785 - fscache_stat(&fscache_n_retrieval_ops);
44786 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
44787
44788 /* pin the netfs read context in case we need to do the actual netfs
44789 * read because we've encountered a cache read failure */
44790 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
44791
44792 error:
44793 if (ret == -ENOMEM)
44794 - fscache_stat(&fscache_n_retrievals_nomem);
44795 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
44796 else if (ret == -ERESTARTSYS)
44797 - fscache_stat(&fscache_n_retrievals_intr);
44798 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
44799 else if (ret == -ENODATA)
44800 - fscache_stat(&fscache_n_retrievals_nodata);
44801 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
44802 else if (ret < 0)
44803 - fscache_stat(&fscache_n_retrievals_nobufs);
44804 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
44805 else
44806 - fscache_stat(&fscache_n_retrievals_ok);
44807 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
44808
44809 fscache_put_retrieval(op);
44810 _leave(" = %d", ret);
44811 @@ -545,7 +545,7 @@ nobufs_unlock:
44812 spin_unlock(&cookie->lock);
44813 kfree(op);
44814 nobufs:
44815 - fscache_stat(&fscache_n_retrievals_nobufs);
44816 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
44817 _leave(" = -ENOBUFS");
44818 return -ENOBUFS;
44819 }
44820 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
44821
44822 _enter("%p,%p,,,", cookie, page);
44823
44824 - fscache_stat(&fscache_n_allocs);
44825 + fscache_stat_unchecked(&fscache_n_allocs);
44826
44827 if (hlist_empty(&cookie->backing_objects))
44828 goto nobufs;
44829 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
44830 goto nobufs_unlock;
44831 spin_unlock(&cookie->lock);
44832
44833 - fscache_stat(&fscache_n_alloc_ops);
44834 + fscache_stat_unchecked(&fscache_n_alloc_ops);
44835
44836 ret = fscache_wait_for_retrieval_activation(
44837 object, op,
44838 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
44839
44840 error:
44841 if (ret == -ERESTARTSYS)
44842 - fscache_stat(&fscache_n_allocs_intr);
44843 + fscache_stat_unchecked(&fscache_n_allocs_intr);
44844 else if (ret < 0)
44845 - fscache_stat(&fscache_n_allocs_nobufs);
44846 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
44847 else
44848 - fscache_stat(&fscache_n_allocs_ok);
44849 + fscache_stat_unchecked(&fscache_n_allocs_ok);
44850
44851 fscache_put_retrieval(op);
44852 _leave(" = %d", ret);
44853 @@ -625,7 +625,7 @@ nobufs_unlock:
44854 spin_unlock(&cookie->lock);
44855 kfree(op);
44856 nobufs:
44857 - fscache_stat(&fscache_n_allocs_nobufs);
44858 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
44859 _leave(" = -ENOBUFS");
44860 return -ENOBUFS;
44861 }
44862 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
44863
44864 spin_lock(&cookie->stores_lock);
44865
44866 - fscache_stat(&fscache_n_store_calls);
44867 + fscache_stat_unchecked(&fscache_n_store_calls);
44868
44869 /* find a page to store */
44870 page = NULL;
44871 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
44872 page = results[0];
44873 _debug("gang %d [%lx]", n, page->index);
44874 if (page->index > op->store_limit) {
44875 - fscache_stat(&fscache_n_store_pages_over_limit);
44876 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
44877 goto superseded;
44878 }
44879
44880 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
44881 spin_unlock(&cookie->stores_lock);
44882 spin_unlock(&object->lock);
44883
44884 - fscache_stat(&fscache_n_store_pages);
44885 + fscache_stat_unchecked(&fscache_n_store_pages);
44886 fscache_stat(&fscache_n_cop_write_page);
44887 ret = object->cache->ops->write_page(op, page);
44888 fscache_stat_d(&fscache_n_cop_write_page);
44889 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
44890 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
44891 ASSERT(PageFsCache(page));
44892
44893 - fscache_stat(&fscache_n_stores);
44894 + fscache_stat_unchecked(&fscache_n_stores);
44895
44896 op = kzalloc(sizeof(*op), GFP_NOIO);
44897 if (!op)
44898 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
44899 spin_unlock(&cookie->stores_lock);
44900 spin_unlock(&object->lock);
44901
44902 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
44903 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
44904 op->store_limit = object->store_limit;
44905
44906 if (fscache_submit_op(object, &op->op) < 0)
44907 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
44908
44909 spin_unlock(&cookie->lock);
44910 radix_tree_preload_end();
44911 - fscache_stat(&fscache_n_store_ops);
44912 - fscache_stat(&fscache_n_stores_ok);
44913 + fscache_stat_unchecked(&fscache_n_store_ops);
44914 + fscache_stat_unchecked(&fscache_n_stores_ok);
44915
44916 /* the work queue now carries its own ref on the object */
44917 fscache_put_operation(&op->op);
44918 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
44919 return 0;
44920
44921 already_queued:
44922 - fscache_stat(&fscache_n_stores_again);
44923 + fscache_stat_unchecked(&fscache_n_stores_again);
44924 already_pending:
44925 spin_unlock(&cookie->stores_lock);
44926 spin_unlock(&object->lock);
44927 spin_unlock(&cookie->lock);
44928 radix_tree_preload_end();
44929 kfree(op);
44930 - fscache_stat(&fscache_n_stores_ok);
44931 + fscache_stat_unchecked(&fscache_n_stores_ok);
44932 _leave(" = 0");
44933 return 0;
44934
44935 @@ -851,14 +851,14 @@ nobufs:
44936 spin_unlock(&cookie->lock);
44937 radix_tree_preload_end();
44938 kfree(op);
44939 - fscache_stat(&fscache_n_stores_nobufs);
44940 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
44941 _leave(" = -ENOBUFS");
44942 return -ENOBUFS;
44943
44944 nomem_free:
44945 kfree(op);
44946 nomem:
44947 - fscache_stat(&fscache_n_stores_oom);
44948 + fscache_stat_unchecked(&fscache_n_stores_oom);
44949 _leave(" = -ENOMEM");
44950 return -ENOMEM;
44951 }
44952 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
44953 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
44954 ASSERTCMP(page, !=, NULL);
44955
44956 - fscache_stat(&fscache_n_uncaches);
44957 + fscache_stat_unchecked(&fscache_n_uncaches);
44958
44959 /* cache withdrawal may beat us to it */
44960 if (!PageFsCache(page))
44961 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
44962 unsigned long loop;
44963
44964 #ifdef CONFIG_FSCACHE_STATS
44965 - atomic_add(pagevec->nr, &fscache_n_marks);
44966 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
44967 #endif
44968
44969 for (loop = 0; loop < pagevec->nr; loop++) {
44970 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
44971 index 4765190..2a067f2 100644
44972 --- a/fs/fscache/stats.c
44973 +++ b/fs/fscache/stats.c
44974 @@ -18,95 +18,95 @@
44975 /*
44976 * operation counters
44977 */
44978 -atomic_t fscache_n_op_pend;
44979 -atomic_t fscache_n_op_run;
44980 -atomic_t fscache_n_op_enqueue;
44981 -atomic_t fscache_n_op_requeue;
44982 -atomic_t fscache_n_op_deferred_release;
44983 -atomic_t fscache_n_op_release;
44984 -atomic_t fscache_n_op_gc;
44985 -atomic_t fscache_n_op_cancelled;
44986 -atomic_t fscache_n_op_rejected;
44987 +atomic_unchecked_t fscache_n_op_pend;
44988 +atomic_unchecked_t fscache_n_op_run;
44989 +atomic_unchecked_t fscache_n_op_enqueue;
44990 +atomic_unchecked_t fscache_n_op_requeue;
44991 +atomic_unchecked_t fscache_n_op_deferred_release;
44992 +atomic_unchecked_t fscache_n_op_release;
44993 +atomic_unchecked_t fscache_n_op_gc;
44994 +atomic_unchecked_t fscache_n_op_cancelled;
44995 +atomic_unchecked_t fscache_n_op_rejected;
44996
44997 -atomic_t fscache_n_attr_changed;
44998 -atomic_t fscache_n_attr_changed_ok;
44999 -atomic_t fscache_n_attr_changed_nobufs;
45000 -atomic_t fscache_n_attr_changed_nomem;
45001 -atomic_t fscache_n_attr_changed_calls;
45002 +atomic_unchecked_t fscache_n_attr_changed;
45003 +atomic_unchecked_t fscache_n_attr_changed_ok;
45004 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
45005 +atomic_unchecked_t fscache_n_attr_changed_nomem;
45006 +atomic_unchecked_t fscache_n_attr_changed_calls;
45007
45008 -atomic_t fscache_n_allocs;
45009 -atomic_t fscache_n_allocs_ok;
45010 -atomic_t fscache_n_allocs_wait;
45011 -atomic_t fscache_n_allocs_nobufs;
45012 -atomic_t fscache_n_allocs_intr;
45013 -atomic_t fscache_n_allocs_object_dead;
45014 -atomic_t fscache_n_alloc_ops;
45015 -atomic_t fscache_n_alloc_op_waits;
45016 +atomic_unchecked_t fscache_n_allocs;
45017 +atomic_unchecked_t fscache_n_allocs_ok;
45018 +atomic_unchecked_t fscache_n_allocs_wait;
45019 +atomic_unchecked_t fscache_n_allocs_nobufs;
45020 +atomic_unchecked_t fscache_n_allocs_intr;
45021 +atomic_unchecked_t fscache_n_allocs_object_dead;
45022 +atomic_unchecked_t fscache_n_alloc_ops;
45023 +atomic_unchecked_t fscache_n_alloc_op_waits;
45024
45025 -atomic_t fscache_n_retrievals;
45026 -atomic_t fscache_n_retrievals_ok;
45027 -atomic_t fscache_n_retrievals_wait;
45028 -atomic_t fscache_n_retrievals_nodata;
45029 -atomic_t fscache_n_retrievals_nobufs;
45030 -atomic_t fscache_n_retrievals_intr;
45031 -atomic_t fscache_n_retrievals_nomem;
45032 -atomic_t fscache_n_retrievals_object_dead;
45033 -atomic_t fscache_n_retrieval_ops;
45034 -atomic_t fscache_n_retrieval_op_waits;
45035 +atomic_unchecked_t fscache_n_retrievals;
45036 +atomic_unchecked_t fscache_n_retrievals_ok;
45037 +atomic_unchecked_t fscache_n_retrievals_wait;
45038 +atomic_unchecked_t fscache_n_retrievals_nodata;
45039 +atomic_unchecked_t fscache_n_retrievals_nobufs;
45040 +atomic_unchecked_t fscache_n_retrievals_intr;
45041 +atomic_unchecked_t fscache_n_retrievals_nomem;
45042 +atomic_unchecked_t fscache_n_retrievals_object_dead;
45043 +atomic_unchecked_t fscache_n_retrieval_ops;
45044 +atomic_unchecked_t fscache_n_retrieval_op_waits;
45045
45046 -atomic_t fscache_n_stores;
45047 -atomic_t fscache_n_stores_ok;
45048 -atomic_t fscache_n_stores_again;
45049 -atomic_t fscache_n_stores_nobufs;
45050 -atomic_t fscache_n_stores_oom;
45051 -atomic_t fscache_n_store_ops;
45052 -atomic_t fscache_n_store_calls;
45053 -atomic_t fscache_n_store_pages;
45054 -atomic_t fscache_n_store_radix_deletes;
45055 -atomic_t fscache_n_store_pages_over_limit;
45056 +atomic_unchecked_t fscache_n_stores;
45057 +atomic_unchecked_t fscache_n_stores_ok;
45058 +atomic_unchecked_t fscache_n_stores_again;
45059 +atomic_unchecked_t fscache_n_stores_nobufs;
45060 +atomic_unchecked_t fscache_n_stores_oom;
45061 +atomic_unchecked_t fscache_n_store_ops;
45062 +atomic_unchecked_t fscache_n_store_calls;
45063 +atomic_unchecked_t fscache_n_store_pages;
45064 +atomic_unchecked_t fscache_n_store_radix_deletes;
45065 +atomic_unchecked_t fscache_n_store_pages_over_limit;
45066
45067 -atomic_t fscache_n_store_vmscan_not_storing;
45068 -atomic_t fscache_n_store_vmscan_gone;
45069 -atomic_t fscache_n_store_vmscan_busy;
45070 -atomic_t fscache_n_store_vmscan_cancelled;
45071 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45072 +atomic_unchecked_t fscache_n_store_vmscan_gone;
45073 +atomic_unchecked_t fscache_n_store_vmscan_busy;
45074 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45075
45076 -atomic_t fscache_n_marks;
45077 -atomic_t fscache_n_uncaches;
45078 +atomic_unchecked_t fscache_n_marks;
45079 +atomic_unchecked_t fscache_n_uncaches;
45080
45081 -atomic_t fscache_n_acquires;
45082 -atomic_t fscache_n_acquires_null;
45083 -atomic_t fscache_n_acquires_no_cache;
45084 -atomic_t fscache_n_acquires_ok;
45085 -atomic_t fscache_n_acquires_nobufs;
45086 -atomic_t fscache_n_acquires_oom;
45087 +atomic_unchecked_t fscache_n_acquires;
45088 +atomic_unchecked_t fscache_n_acquires_null;
45089 +atomic_unchecked_t fscache_n_acquires_no_cache;
45090 +atomic_unchecked_t fscache_n_acquires_ok;
45091 +atomic_unchecked_t fscache_n_acquires_nobufs;
45092 +atomic_unchecked_t fscache_n_acquires_oom;
45093
45094 -atomic_t fscache_n_updates;
45095 -atomic_t fscache_n_updates_null;
45096 -atomic_t fscache_n_updates_run;
45097 +atomic_unchecked_t fscache_n_updates;
45098 +atomic_unchecked_t fscache_n_updates_null;
45099 +atomic_unchecked_t fscache_n_updates_run;
45100
45101 -atomic_t fscache_n_relinquishes;
45102 -atomic_t fscache_n_relinquishes_null;
45103 -atomic_t fscache_n_relinquishes_waitcrt;
45104 -atomic_t fscache_n_relinquishes_retire;
45105 +atomic_unchecked_t fscache_n_relinquishes;
45106 +atomic_unchecked_t fscache_n_relinquishes_null;
45107 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45108 +atomic_unchecked_t fscache_n_relinquishes_retire;
45109
45110 -atomic_t fscache_n_cookie_index;
45111 -atomic_t fscache_n_cookie_data;
45112 -atomic_t fscache_n_cookie_special;
45113 +atomic_unchecked_t fscache_n_cookie_index;
45114 +atomic_unchecked_t fscache_n_cookie_data;
45115 +atomic_unchecked_t fscache_n_cookie_special;
45116
45117 -atomic_t fscache_n_object_alloc;
45118 -atomic_t fscache_n_object_no_alloc;
45119 -atomic_t fscache_n_object_lookups;
45120 -atomic_t fscache_n_object_lookups_negative;
45121 -atomic_t fscache_n_object_lookups_positive;
45122 -atomic_t fscache_n_object_lookups_timed_out;
45123 -atomic_t fscache_n_object_created;
45124 -atomic_t fscache_n_object_avail;
45125 -atomic_t fscache_n_object_dead;
45126 +atomic_unchecked_t fscache_n_object_alloc;
45127 +atomic_unchecked_t fscache_n_object_no_alloc;
45128 +atomic_unchecked_t fscache_n_object_lookups;
45129 +atomic_unchecked_t fscache_n_object_lookups_negative;
45130 +atomic_unchecked_t fscache_n_object_lookups_positive;
45131 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
45132 +atomic_unchecked_t fscache_n_object_created;
45133 +atomic_unchecked_t fscache_n_object_avail;
45134 +atomic_unchecked_t fscache_n_object_dead;
45135
45136 -atomic_t fscache_n_checkaux_none;
45137 -atomic_t fscache_n_checkaux_okay;
45138 -atomic_t fscache_n_checkaux_update;
45139 -atomic_t fscache_n_checkaux_obsolete;
45140 +atomic_unchecked_t fscache_n_checkaux_none;
45141 +atomic_unchecked_t fscache_n_checkaux_okay;
45142 +atomic_unchecked_t fscache_n_checkaux_update;
45143 +atomic_unchecked_t fscache_n_checkaux_obsolete;
45144
45145 atomic_t fscache_n_cop_alloc_object;
45146 atomic_t fscache_n_cop_lookup_object;
45147 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
45148 seq_puts(m, "FS-Cache statistics\n");
45149
45150 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
45151 - atomic_read(&fscache_n_cookie_index),
45152 - atomic_read(&fscache_n_cookie_data),
45153 - atomic_read(&fscache_n_cookie_special));
45154 + atomic_read_unchecked(&fscache_n_cookie_index),
45155 + atomic_read_unchecked(&fscache_n_cookie_data),
45156 + atomic_read_unchecked(&fscache_n_cookie_special));
45157
45158 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
45159 - atomic_read(&fscache_n_object_alloc),
45160 - atomic_read(&fscache_n_object_no_alloc),
45161 - atomic_read(&fscache_n_object_avail),
45162 - atomic_read(&fscache_n_object_dead));
45163 + atomic_read_unchecked(&fscache_n_object_alloc),
45164 + atomic_read_unchecked(&fscache_n_object_no_alloc),
45165 + atomic_read_unchecked(&fscache_n_object_avail),
45166 + atomic_read_unchecked(&fscache_n_object_dead));
45167 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
45168 - atomic_read(&fscache_n_checkaux_none),
45169 - atomic_read(&fscache_n_checkaux_okay),
45170 - atomic_read(&fscache_n_checkaux_update),
45171 - atomic_read(&fscache_n_checkaux_obsolete));
45172 + atomic_read_unchecked(&fscache_n_checkaux_none),
45173 + atomic_read_unchecked(&fscache_n_checkaux_okay),
45174 + atomic_read_unchecked(&fscache_n_checkaux_update),
45175 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
45176
45177 seq_printf(m, "Pages : mrk=%u unc=%u\n",
45178 - atomic_read(&fscache_n_marks),
45179 - atomic_read(&fscache_n_uncaches));
45180 + atomic_read_unchecked(&fscache_n_marks),
45181 + atomic_read_unchecked(&fscache_n_uncaches));
45182
45183 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
45184 " oom=%u\n",
45185 - atomic_read(&fscache_n_acquires),
45186 - atomic_read(&fscache_n_acquires_null),
45187 - atomic_read(&fscache_n_acquires_no_cache),
45188 - atomic_read(&fscache_n_acquires_ok),
45189 - atomic_read(&fscache_n_acquires_nobufs),
45190 - atomic_read(&fscache_n_acquires_oom));
45191 + atomic_read_unchecked(&fscache_n_acquires),
45192 + atomic_read_unchecked(&fscache_n_acquires_null),
45193 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
45194 + atomic_read_unchecked(&fscache_n_acquires_ok),
45195 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
45196 + atomic_read_unchecked(&fscache_n_acquires_oom));
45197
45198 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
45199 - atomic_read(&fscache_n_object_lookups),
45200 - atomic_read(&fscache_n_object_lookups_negative),
45201 - atomic_read(&fscache_n_object_lookups_positive),
45202 - atomic_read(&fscache_n_object_created),
45203 - atomic_read(&fscache_n_object_lookups_timed_out));
45204 + atomic_read_unchecked(&fscache_n_object_lookups),
45205 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
45206 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
45207 + atomic_read_unchecked(&fscache_n_object_created),
45208 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
45209
45210 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
45211 - atomic_read(&fscache_n_updates),
45212 - atomic_read(&fscache_n_updates_null),
45213 - atomic_read(&fscache_n_updates_run));
45214 + atomic_read_unchecked(&fscache_n_updates),
45215 + atomic_read_unchecked(&fscache_n_updates_null),
45216 + atomic_read_unchecked(&fscache_n_updates_run));
45217
45218 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
45219 - atomic_read(&fscache_n_relinquishes),
45220 - atomic_read(&fscache_n_relinquishes_null),
45221 - atomic_read(&fscache_n_relinquishes_waitcrt),
45222 - atomic_read(&fscache_n_relinquishes_retire));
45223 + atomic_read_unchecked(&fscache_n_relinquishes),
45224 + atomic_read_unchecked(&fscache_n_relinquishes_null),
45225 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
45226 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
45227
45228 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
45229 - atomic_read(&fscache_n_attr_changed),
45230 - atomic_read(&fscache_n_attr_changed_ok),
45231 - atomic_read(&fscache_n_attr_changed_nobufs),
45232 - atomic_read(&fscache_n_attr_changed_nomem),
45233 - atomic_read(&fscache_n_attr_changed_calls));
45234 + atomic_read_unchecked(&fscache_n_attr_changed),
45235 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
45236 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
45237 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
45238 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
45239
45240 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
45241 - atomic_read(&fscache_n_allocs),
45242 - atomic_read(&fscache_n_allocs_ok),
45243 - atomic_read(&fscache_n_allocs_wait),
45244 - atomic_read(&fscache_n_allocs_nobufs),
45245 - atomic_read(&fscache_n_allocs_intr));
45246 + atomic_read_unchecked(&fscache_n_allocs),
45247 + atomic_read_unchecked(&fscache_n_allocs_ok),
45248 + atomic_read_unchecked(&fscache_n_allocs_wait),
45249 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
45250 + atomic_read_unchecked(&fscache_n_allocs_intr));
45251 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
45252 - atomic_read(&fscache_n_alloc_ops),
45253 - atomic_read(&fscache_n_alloc_op_waits),
45254 - atomic_read(&fscache_n_allocs_object_dead));
45255 + atomic_read_unchecked(&fscache_n_alloc_ops),
45256 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
45257 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
45258
45259 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
45260 " int=%u oom=%u\n",
45261 - atomic_read(&fscache_n_retrievals),
45262 - atomic_read(&fscache_n_retrievals_ok),
45263 - atomic_read(&fscache_n_retrievals_wait),
45264 - atomic_read(&fscache_n_retrievals_nodata),
45265 - atomic_read(&fscache_n_retrievals_nobufs),
45266 - atomic_read(&fscache_n_retrievals_intr),
45267 - atomic_read(&fscache_n_retrievals_nomem));
45268 + atomic_read_unchecked(&fscache_n_retrievals),
45269 + atomic_read_unchecked(&fscache_n_retrievals_ok),
45270 + atomic_read_unchecked(&fscache_n_retrievals_wait),
45271 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
45272 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
45273 + atomic_read_unchecked(&fscache_n_retrievals_intr),
45274 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
45275 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
45276 - atomic_read(&fscache_n_retrieval_ops),
45277 - atomic_read(&fscache_n_retrieval_op_waits),
45278 - atomic_read(&fscache_n_retrievals_object_dead));
45279 + atomic_read_unchecked(&fscache_n_retrieval_ops),
45280 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
45281 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
45282
45283 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
45284 - atomic_read(&fscache_n_stores),
45285 - atomic_read(&fscache_n_stores_ok),
45286 - atomic_read(&fscache_n_stores_again),
45287 - atomic_read(&fscache_n_stores_nobufs),
45288 - atomic_read(&fscache_n_stores_oom));
45289 + atomic_read_unchecked(&fscache_n_stores),
45290 + atomic_read_unchecked(&fscache_n_stores_ok),
45291 + atomic_read_unchecked(&fscache_n_stores_again),
45292 + atomic_read_unchecked(&fscache_n_stores_nobufs),
45293 + atomic_read_unchecked(&fscache_n_stores_oom));
45294 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
45295 - atomic_read(&fscache_n_store_ops),
45296 - atomic_read(&fscache_n_store_calls),
45297 - atomic_read(&fscache_n_store_pages),
45298 - atomic_read(&fscache_n_store_radix_deletes),
45299 - atomic_read(&fscache_n_store_pages_over_limit));
45300 + atomic_read_unchecked(&fscache_n_store_ops),
45301 + atomic_read_unchecked(&fscache_n_store_calls),
45302 + atomic_read_unchecked(&fscache_n_store_pages),
45303 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
45304 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
45305
45306 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
45307 - atomic_read(&fscache_n_store_vmscan_not_storing),
45308 - atomic_read(&fscache_n_store_vmscan_gone),
45309 - atomic_read(&fscache_n_store_vmscan_busy),
45310 - atomic_read(&fscache_n_store_vmscan_cancelled));
45311 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
45312 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
45313 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
45314 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
45315
45316 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
45317 - atomic_read(&fscache_n_op_pend),
45318 - atomic_read(&fscache_n_op_run),
45319 - atomic_read(&fscache_n_op_enqueue),
45320 - atomic_read(&fscache_n_op_cancelled),
45321 - atomic_read(&fscache_n_op_rejected));
45322 + atomic_read_unchecked(&fscache_n_op_pend),
45323 + atomic_read_unchecked(&fscache_n_op_run),
45324 + atomic_read_unchecked(&fscache_n_op_enqueue),
45325 + atomic_read_unchecked(&fscache_n_op_cancelled),
45326 + atomic_read_unchecked(&fscache_n_op_rejected));
45327 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
45328 - atomic_read(&fscache_n_op_deferred_release),
45329 - atomic_read(&fscache_n_op_release),
45330 - atomic_read(&fscache_n_op_gc));
45331 + atomic_read_unchecked(&fscache_n_op_deferred_release),
45332 + atomic_read_unchecked(&fscache_n_op_release),
45333 + atomic_read_unchecked(&fscache_n_op_gc));
45334
45335 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
45336 atomic_read(&fscache_n_cop_alloc_object),
45337 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
45338 index 3426521..3b75162 100644
45339 --- a/fs/fuse/cuse.c
45340 +++ b/fs/fuse/cuse.c
45341 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
45342 INIT_LIST_HEAD(&cuse_conntbl[i]);
45343
45344 /* inherit and extend fuse_dev_operations */
45345 - cuse_channel_fops = fuse_dev_operations;
45346 - cuse_channel_fops.owner = THIS_MODULE;
45347 - cuse_channel_fops.open = cuse_channel_open;
45348 - cuse_channel_fops.release = cuse_channel_release;
45349 + pax_open_kernel();
45350 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
45351 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
45352 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
45353 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
45354 + pax_close_kernel();
45355
45356 cuse_class = class_create(THIS_MODULE, "cuse");
45357 if (IS_ERR(cuse_class))
45358 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
45359 index 2aaf3ea..8e50863 100644
45360 --- a/fs/fuse/dev.c
45361 +++ b/fs/fuse/dev.c
45362 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
45363 ret = 0;
45364 pipe_lock(pipe);
45365
45366 - if (!pipe->readers) {
45367 + if (!atomic_read(&pipe->readers)) {
45368 send_sig(SIGPIPE, current, 0);
45369 if (!ret)
45370 ret = -EPIPE;
45371 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
45372 index 9f63e49..d8a64c0 100644
45373 --- a/fs/fuse/dir.c
45374 +++ b/fs/fuse/dir.c
45375 @@ -1147,7 +1147,7 @@ static char *read_link(struct dentry *dentry)
45376 return link;
45377 }
45378
45379 -static void free_link(char *link)
45380 +static void free_link(const char *link)
45381 {
45382 if (!IS_ERR(link))
45383 free_page((unsigned long) link);
45384 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
45385 index cfd4959..a780959 100644
45386 --- a/fs/gfs2/inode.c
45387 +++ b/fs/gfs2/inode.c
45388 @@ -1490,7 +1490,7 @@ out:
45389
45390 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
45391 {
45392 - char *s = nd_get_link(nd);
45393 + const char *s = nd_get_link(nd);
45394 if (!IS_ERR(s))
45395 kfree(s);
45396 }
45397 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
45398 index 0be5a78..9cfb853 100644
45399 --- a/fs/hugetlbfs/inode.c
45400 +++ b/fs/hugetlbfs/inode.c
45401 @@ -915,7 +915,7 @@ static struct file_system_type hugetlbfs_fs_type = {
45402 .kill_sb = kill_litter_super,
45403 };
45404
45405 -static struct vfsmount *hugetlbfs_vfsmount;
45406 +struct vfsmount *hugetlbfs_vfsmount;
45407
45408 static int can_do_hugetlb_shm(void)
45409 {
45410 diff --git a/fs/inode.c b/fs/inode.c
45411 index ee4e66b..0451521 100644
45412 --- a/fs/inode.c
45413 +++ b/fs/inode.c
45414 @@ -787,8 +787,8 @@ unsigned int get_next_ino(void)
45415
45416 #ifdef CONFIG_SMP
45417 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
45418 - static atomic_t shared_last_ino;
45419 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
45420 + static atomic_unchecked_t shared_last_ino;
45421 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
45422
45423 res = next - LAST_INO_BATCH;
45424 }
45425 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
45426 index e513f19..2ab1351 100644
45427 --- a/fs/jffs2/erase.c
45428 +++ b/fs/jffs2/erase.c
45429 @@ -439,7 +439,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
45430 struct jffs2_unknown_node marker = {
45431 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
45432 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
45433 - .totlen = cpu_to_je32(c->cleanmarker_size)
45434 + .totlen = cpu_to_je32(c->cleanmarker_size),
45435 + .hdr_crc = cpu_to_je32(0)
45436 };
45437
45438 jffs2_prealloc_raw_node_refs(c, jeb, 1);
45439 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
45440 index b09e51d..e482afa 100644
45441 --- a/fs/jffs2/wbuf.c
45442 +++ b/fs/jffs2/wbuf.c
45443 @@ -1011,7 +1011,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
45444 {
45445 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
45446 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
45447 - .totlen = constant_cpu_to_je32(8)
45448 + .totlen = constant_cpu_to_je32(8),
45449 + .hdr_crc = constant_cpu_to_je32(0)
45450 };
45451
45452 /*
45453 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
45454 index a44eff0..462e07d 100644
45455 --- a/fs/jfs/super.c
45456 +++ b/fs/jfs/super.c
45457 @@ -802,7 +802,7 @@ static int __init init_jfs_fs(void)
45458
45459 jfs_inode_cachep =
45460 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
45461 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
45462 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
45463 init_once);
45464 if (jfs_inode_cachep == NULL)
45465 return -ENOMEM;
45466 diff --git a/fs/libfs.c b/fs/libfs.c
45467 index f6d411e..e82a08d 100644
45468 --- a/fs/libfs.c
45469 +++ b/fs/libfs.c
45470 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
45471
45472 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
45473 struct dentry *next;
45474 + char d_name[sizeof(next->d_iname)];
45475 + const unsigned char *name;
45476 +
45477 next = list_entry(p, struct dentry, d_u.d_child);
45478 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
45479 if (!simple_positive(next)) {
45480 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
45481
45482 spin_unlock(&next->d_lock);
45483 spin_unlock(&dentry->d_lock);
45484 - if (filldir(dirent, next->d_name.name,
45485 + name = next->d_name.name;
45486 + if (name == next->d_iname) {
45487 + memcpy(d_name, name, next->d_name.len);
45488 + name = d_name;
45489 + }
45490 + if (filldir(dirent, name,
45491 next->d_name.len, filp->f_pos,
45492 next->d_inode->i_ino,
45493 dt_type(next->d_inode)) < 0)
45494 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
45495 index 8392cb8..80d6193 100644
45496 --- a/fs/lockd/clntproc.c
45497 +++ b/fs/lockd/clntproc.c
45498 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
45499 /*
45500 * Cookie counter for NLM requests
45501 */
45502 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
45503 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
45504
45505 void nlmclnt_next_cookie(struct nlm_cookie *c)
45506 {
45507 - u32 cookie = atomic_inc_return(&nlm_cookie);
45508 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
45509
45510 memcpy(c->data, &cookie, 4);
45511 c->len=4;
45512 diff --git a/fs/locks.c b/fs/locks.c
45513 index 637694b..f84a121 100644
45514 --- a/fs/locks.c
45515 +++ b/fs/locks.c
45516 @@ -2074,16 +2074,16 @@ void locks_remove_flock(struct file *filp)
45517 return;
45518
45519 if (filp->f_op && filp->f_op->flock) {
45520 - struct file_lock fl = {
45521 + struct file_lock flock = {
45522 .fl_pid = current->tgid,
45523 .fl_file = filp,
45524 .fl_flags = FL_FLOCK,
45525 .fl_type = F_UNLCK,
45526 .fl_end = OFFSET_MAX,
45527 };
45528 - filp->f_op->flock(filp, F_SETLKW, &fl);
45529 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
45530 - fl.fl_ops->fl_release_private(&fl);
45531 + filp->f_op->flock(filp, F_SETLKW, &flock);
45532 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
45533 + flock.fl_ops->fl_release_private(&flock);
45534 }
45535
45536 lock_flocks();
45537 diff --git a/fs/namei.c b/fs/namei.c
45538 index 744e942..24ef47f 100644
45539 --- a/fs/namei.c
45540 +++ b/fs/namei.c
45541 @@ -279,16 +279,32 @@ int generic_permission(struct inode *inode, int mask)
45542 if (ret != -EACCES)
45543 return ret;
45544
45545 +#ifdef CONFIG_GRKERNSEC
45546 + /* we'll block if we have to log due to a denied capability use */
45547 + if (mask & MAY_NOT_BLOCK)
45548 + return -ECHILD;
45549 +#endif
45550 +
45551 if (S_ISDIR(inode->i_mode)) {
45552 /* DACs are overridable for directories */
45553 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
45554 - return 0;
45555 if (!(mask & MAY_WRITE))
45556 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
45557 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
45558 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
45559 return 0;
45560 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
45561 + return 0;
45562 return -EACCES;
45563 }
45564 /*
45565 + * Searching includes executable on directories, else just read.
45566 + */
45567 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
45568 + if (mask == MAY_READ)
45569 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
45570 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
45571 + return 0;
45572 +
45573 + /*
45574 * Read/write DACs are always overridable.
45575 * Executable DACs are overridable when there is
45576 * at least one exec bit set.
45577 @@ -297,14 +313,6 @@ int generic_permission(struct inode *inode, int mask)
45578 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
45579 return 0;
45580
45581 - /*
45582 - * Searching includes executable on directories, else just read.
45583 - */
45584 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
45585 - if (mask == MAY_READ)
45586 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
45587 - return 0;
45588 -
45589 return -EACCES;
45590 }
45591
45592 @@ -653,11 +661,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
45593 return error;
45594 }
45595
45596 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
45597 + dentry->d_inode, dentry, nd->path.mnt)) {
45598 + error = -EACCES;
45599 + *p = ERR_PTR(error); /* no ->put_link(), please */
45600 + path_put(&nd->path);
45601 + return error;
45602 + }
45603 +
45604 nd->last_type = LAST_BIND;
45605 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
45606 error = PTR_ERR(*p);
45607 if (!IS_ERR(*p)) {
45608 - char *s = nd_get_link(nd);
45609 + const char *s = nd_get_link(nd);
45610 error = 0;
45611 if (s)
45612 error = __vfs_follow_link(nd, s);
45613 @@ -1624,6 +1640,21 @@ static int path_lookupat(int dfd, const char *name,
45614 if (!err)
45615 err = complete_walk(nd);
45616
45617 + if (!(nd->flags & LOOKUP_PARENT)) {
45618 +#ifdef CONFIG_GRKERNSEC
45619 + if (flags & LOOKUP_RCU) {
45620 + if (!err)
45621 + path_put(&nd->path);
45622 + err = -ECHILD;
45623 + } else
45624 +#endif
45625 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
45626 + if (!err)
45627 + path_put(&nd->path);
45628 + err = -ENOENT;
45629 + }
45630 + }
45631 +
45632 if (!err && nd->flags & LOOKUP_DIRECTORY) {
45633 if (!nd->inode->i_op->lookup) {
45634 path_put(&nd->path);
45635 @@ -1651,6 +1682,15 @@ static int do_path_lookup(int dfd, const char *name,
45636 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
45637
45638 if (likely(!retval)) {
45639 + if (*name != '/' && nd->path.dentry && nd->inode) {
45640 +#ifdef CONFIG_GRKERNSEC
45641 + if (flags & LOOKUP_RCU)
45642 + return -ECHILD;
45643 +#endif
45644 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
45645 + return -ENOENT;
45646 + }
45647 +
45648 if (unlikely(!audit_dummy_context())) {
45649 if (nd->path.dentry && nd->inode)
45650 audit_inode(name, nd->path.dentry);
45651 @@ -2048,6 +2088,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
45652 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
45653 return -EPERM;
45654
45655 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
45656 + return -EPERM;
45657 + if (gr_handle_rawio(inode))
45658 + return -EPERM;
45659 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
45660 + return -EACCES;
45661 +
45662 return 0;
45663 }
45664
45665 @@ -2109,6 +2156,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
45666 error = complete_walk(nd);
45667 if (error)
45668 return ERR_PTR(error);
45669 +#ifdef CONFIG_GRKERNSEC
45670 + if (nd->flags & LOOKUP_RCU) {
45671 + error = -ECHILD;
45672 + goto exit;
45673 + }
45674 +#endif
45675 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
45676 + error = -ENOENT;
45677 + goto exit;
45678 + }
45679 audit_inode(pathname, nd->path.dentry);
45680 if (open_flag & O_CREAT) {
45681 error = -EISDIR;
45682 @@ -2119,6 +2176,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
45683 error = complete_walk(nd);
45684 if (error)
45685 return ERR_PTR(error);
45686 +#ifdef CONFIG_GRKERNSEC
45687 + if (nd->flags & LOOKUP_RCU) {
45688 + error = -ECHILD;
45689 + goto exit;
45690 + }
45691 +#endif
45692 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
45693 + error = -ENOENT;
45694 + goto exit;
45695 + }
45696 audit_inode(pathname, dir);
45697 goto ok;
45698 }
45699 @@ -2140,6 +2207,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
45700 error = complete_walk(nd);
45701 if (error)
45702 return ERR_PTR(-ECHILD);
45703 +#ifdef CONFIG_GRKERNSEC
45704 + if (nd->flags & LOOKUP_RCU) {
45705 + error = -ECHILD;
45706 + goto exit;
45707 + }
45708 +#endif
45709 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
45710 + error = -ENOENT;
45711 + goto exit;
45712 + }
45713
45714 error = -ENOTDIR;
45715 if (nd->flags & LOOKUP_DIRECTORY) {
45716 @@ -2180,6 +2257,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
45717 /* Negative dentry, just create the file */
45718 if (!dentry->d_inode) {
45719 int mode = op->mode;
45720 +
45721 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
45722 + error = -EACCES;
45723 + goto exit_mutex_unlock;
45724 + }
45725 +
45726 if (!IS_POSIXACL(dir->d_inode))
45727 mode &= ~current_umask();
45728 /*
45729 @@ -2203,6 +2286,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
45730 error = vfs_create(dir->d_inode, dentry, mode, nd);
45731 if (error)
45732 goto exit_mutex_unlock;
45733 + else
45734 + gr_handle_create(path->dentry, path->mnt);
45735 mutex_unlock(&dir->d_inode->i_mutex);
45736 dput(nd->path.dentry);
45737 nd->path.dentry = dentry;
45738 @@ -2212,6 +2297,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
45739 /*
45740 * It already exists.
45741 */
45742 +
45743 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
45744 + error = -ENOENT;
45745 + goto exit_mutex_unlock;
45746 + }
45747 +
45748 + /* only check if O_CREAT is specified, all other checks need to go
45749 + into may_open */
45750 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
45751 + error = -EACCES;
45752 + goto exit_mutex_unlock;
45753 + }
45754 +
45755 mutex_unlock(&dir->d_inode->i_mutex);
45756 audit_inode(pathname, path->dentry);
45757
45758 @@ -2424,6 +2522,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
45759 *path = nd.path;
45760 return dentry;
45761 eexist:
45762 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
45763 + dput(dentry);
45764 + dentry = ERR_PTR(-ENOENT);
45765 + goto fail;
45766 + }
45767 dput(dentry);
45768 dentry = ERR_PTR(-EEXIST);
45769 fail:
45770 @@ -2446,6 +2549,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
45771 }
45772 EXPORT_SYMBOL(user_path_create);
45773
45774 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
45775 +{
45776 + char *tmp = getname(pathname);
45777 + struct dentry *res;
45778 + if (IS_ERR(tmp))
45779 + return ERR_CAST(tmp);
45780 + res = kern_path_create(dfd, tmp, path, is_dir);
45781 + if (IS_ERR(res))
45782 + putname(tmp);
45783 + else
45784 + *to = tmp;
45785 + return res;
45786 +}
45787 +
45788 int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
45789 {
45790 int error = may_create(dir, dentry);
45791 @@ -2513,6 +2630,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
45792 error = mnt_want_write(path.mnt);
45793 if (error)
45794 goto out_dput;
45795 +
45796 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
45797 + error = -EPERM;
45798 + goto out_drop_write;
45799 + }
45800 +
45801 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
45802 + error = -EACCES;
45803 + goto out_drop_write;
45804 + }
45805 +
45806 error = security_path_mknod(&path, dentry, mode, dev);
45807 if (error)
45808 goto out_drop_write;
45809 @@ -2530,6 +2658,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
45810 }
45811 out_drop_write:
45812 mnt_drop_write(path.mnt);
45813 +
45814 + if (!error)
45815 + gr_handle_create(dentry, path.mnt);
45816 out_dput:
45817 dput(dentry);
45818 mutex_unlock(&path.dentry->d_inode->i_mutex);
45819 @@ -2579,12 +2710,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
45820 error = mnt_want_write(path.mnt);
45821 if (error)
45822 goto out_dput;
45823 +
45824 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
45825 + error = -EACCES;
45826 + goto out_drop_write;
45827 + }
45828 +
45829 error = security_path_mkdir(&path, dentry, mode);
45830 if (error)
45831 goto out_drop_write;
45832 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
45833 out_drop_write:
45834 mnt_drop_write(path.mnt);
45835 +
45836 + if (!error)
45837 + gr_handle_create(dentry, path.mnt);
45838 out_dput:
45839 dput(dentry);
45840 mutex_unlock(&path.dentry->d_inode->i_mutex);
45841 @@ -2664,6 +2804,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
45842 char * name;
45843 struct dentry *dentry;
45844 struct nameidata nd;
45845 + ino_t saved_ino = 0;
45846 + dev_t saved_dev = 0;
45847
45848 error = user_path_parent(dfd, pathname, &nd, &name);
45849 if (error)
45850 @@ -2692,6 +2834,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
45851 error = -ENOENT;
45852 goto exit3;
45853 }
45854 +
45855 + saved_ino = dentry->d_inode->i_ino;
45856 + saved_dev = gr_get_dev_from_dentry(dentry);
45857 +
45858 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
45859 + error = -EACCES;
45860 + goto exit3;
45861 + }
45862 +
45863 error = mnt_want_write(nd.path.mnt);
45864 if (error)
45865 goto exit3;
45866 @@ -2699,6 +2850,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
45867 if (error)
45868 goto exit4;
45869 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
45870 + if (!error && (saved_dev || saved_ino))
45871 + gr_handle_delete(saved_ino, saved_dev);
45872 exit4:
45873 mnt_drop_write(nd.path.mnt);
45874 exit3:
45875 @@ -2761,6 +2914,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
45876 struct dentry *dentry;
45877 struct nameidata nd;
45878 struct inode *inode = NULL;
45879 + ino_t saved_ino = 0;
45880 + dev_t saved_dev = 0;
45881
45882 error = user_path_parent(dfd, pathname, &nd, &name);
45883 if (error)
45884 @@ -2783,6 +2938,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
45885 if (!inode)
45886 goto slashes;
45887 ihold(inode);
45888 +
45889 + if (inode->i_nlink <= 1) {
45890 + saved_ino = inode->i_ino;
45891 + saved_dev = gr_get_dev_from_dentry(dentry);
45892 + }
45893 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
45894 + error = -EACCES;
45895 + goto exit2;
45896 + }
45897 +
45898 error = mnt_want_write(nd.path.mnt);
45899 if (error)
45900 goto exit2;
45901 @@ -2790,6 +2955,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
45902 if (error)
45903 goto exit3;
45904 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
45905 + if (!error && (saved_ino || saved_dev))
45906 + gr_handle_delete(saved_ino, saved_dev);
45907 exit3:
45908 mnt_drop_write(nd.path.mnt);
45909 exit2:
45910 @@ -2865,10 +3032,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
45911 error = mnt_want_write(path.mnt);
45912 if (error)
45913 goto out_dput;
45914 +
45915 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
45916 + error = -EACCES;
45917 + goto out_drop_write;
45918 + }
45919 +
45920 error = security_path_symlink(&path, dentry, from);
45921 if (error)
45922 goto out_drop_write;
45923 error = vfs_symlink(path.dentry->d_inode, dentry, from);
45924 + if (!error)
45925 + gr_handle_create(dentry, path.mnt);
45926 out_drop_write:
45927 mnt_drop_write(path.mnt);
45928 out_dput:
45929 @@ -2940,6 +3115,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
45930 {
45931 struct dentry *new_dentry;
45932 struct path old_path, new_path;
45933 + char *to = NULL;
45934 int how = 0;
45935 int error;
45936
45937 @@ -2963,7 +3139,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
45938 if (error)
45939 return error;
45940
45941 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
45942 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
45943 error = PTR_ERR(new_dentry);
45944 if (IS_ERR(new_dentry))
45945 goto out;
45946 @@ -2974,13 +3150,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
45947 error = mnt_want_write(new_path.mnt);
45948 if (error)
45949 goto out_dput;
45950 +
45951 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
45952 + old_path.dentry->d_inode,
45953 + old_path.dentry->d_inode->i_mode, to)) {
45954 + error = -EACCES;
45955 + goto out_drop_write;
45956 + }
45957 +
45958 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
45959 + old_path.dentry, old_path.mnt, to)) {
45960 + error = -EACCES;
45961 + goto out_drop_write;
45962 + }
45963 +
45964 error = security_path_link(old_path.dentry, &new_path, new_dentry);
45965 if (error)
45966 goto out_drop_write;
45967 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
45968 + if (!error)
45969 + gr_handle_create(new_dentry, new_path.mnt);
45970 out_drop_write:
45971 mnt_drop_write(new_path.mnt);
45972 out_dput:
45973 + putname(to);
45974 dput(new_dentry);
45975 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
45976 path_put(&new_path);
45977 @@ -3208,6 +3401,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
45978 if (new_dentry == trap)
45979 goto exit5;
45980
45981 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
45982 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
45983 + to);
45984 + if (error)
45985 + goto exit5;
45986 +
45987 error = mnt_want_write(oldnd.path.mnt);
45988 if (error)
45989 goto exit5;
45990 @@ -3217,6 +3416,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
45991 goto exit6;
45992 error = vfs_rename(old_dir->d_inode, old_dentry,
45993 new_dir->d_inode, new_dentry);
45994 + if (!error)
45995 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
45996 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
45997 exit6:
45998 mnt_drop_write(oldnd.path.mnt);
45999 exit5:
46000 @@ -3242,6 +3444,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
46001
46002 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
46003 {
46004 + char tmpbuf[64];
46005 + const char *newlink;
46006 int len;
46007
46008 len = PTR_ERR(link);
46009 @@ -3251,7 +3455,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
46010 len = strlen(link);
46011 if (len > (unsigned) buflen)
46012 len = buflen;
46013 - if (copy_to_user(buffer, link, len))
46014 +
46015 + if (len < sizeof(tmpbuf)) {
46016 + memcpy(tmpbuf, link, len);
46017 + newlink = tmpbuf;
46018 + } else
46019 + newlink = link;
46020 +
46021 + if (copy_to_user(buffer, newlink, len))
46022 len = -EFAULT;
46023 out:
46024 return len;
46025 diff --git a/fs/namespace.c b/fs/namespace.c
46026 index cfc6d44..b4632a5 100644
46027 --- a/fs/namespace.c
46028 +++ b/fs/namespace.c
46029 @@ -1326,6 +1326,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
46030 if (!(sb->s_flags & MS_RDONLY))
46031 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
46032 up_write(&sb->s_umount);
46033 +
46034 + gr_log_remount(mnt->mnt_devname, retval);
46035 +
46036 return retval;
46037 }
46038
46039 @@ -1345,6 +1348,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
46040 br_write_unlock(vfsmount_lock);
46041 up_write(&namespace_sem);
46042 release_mounts(&umount_list);
46043 +
46044 + gr_log_unmount(mnt->mnt_devname, retval);
46045 +
46046 return retval;
46047 }
46048
46049 @@ -2336,6 +2342,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
46050 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
46051 MS_STRICTATIME);
46052
46053 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
46054 + retval = -EPERM;
46055 + goto dput_out;
46056 + }
46057 +
46058 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
46059 + retval = -EPERM;
46060 + goto dput_out;
46061 + }
46062 +
46063 if (flags & MS_REMOUNT)
46064 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
46065 data_page);
46066 @@ -2350,6 +2366,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
46067 dev_name, data_page);
46068 dput_out:
46069 path_put(&path);
46070 +
46071 + gr_log_mount(dev_name, dir_name, retval);
46072 +
46073 return retval;
46074 }
46075
46076 @@ -2605,6 +2624,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
46077 if (error)
46078 goto out2;
46079
46080 + if (gr_handle_chroot_pivot()) {
46081 + error = -EPERM;
46082 + goto out2;
46083 + }
46084 +
46085 get_fs_root(current->fs, &root);
46086 error = lock_mount(&old);
46087 if (error)
46088 diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
46089 index 3db6b82..a57597e 100644
46090 --- a/fs/nfs/blocklayout/blocklayout.c
46091 +++ b/fs/nfs/blocklayout/blocklayout.c
46092 @@ -90,7 +90,7 @@ static int is_writable(struct pnfs_block_extent *be, sector_t isect)
46093 */
46094 struct parallel_io {
46095 struct kref refcnt;
46096 - struct rpc_call_ops call_ops;
46097 + rpc_call_ops_no_const call_ops;
46098 void (*pnfs_callback) (void *data);
46099 void *data;
46100 };
46101 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
46102 index 50a15fa..ca113f9 100644
46103 --- a/fs/nfs/inode.c
46104 +++ b/fs/nfs/inode.c
46105 @@ -150,7 +150,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
46106 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
46107 nfsi->attrtimeo_timestamp = jiffies;
46108
46109 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
46110 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
46111 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
46112 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
46113 else
46114 @@ -1002,16 +1002,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
46115 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
46116 }
46117
46118 -static atomic_long_t nfs_attr_generation_counter;
46119 +static atomic_long_unchecked_t nfs_attr_generation_counter;
46120
46121 static unsigned long nfs_read_attr_generation_counter(void)
46122 {
46123 - return atomic_long_read(&nfs_attr_generation_counter);
46124 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
46125 }
46126
46127 unsigned long nfs_inc_attr_generation_counter(void)
46128 {
46129 - return atomic_long_inc_return(&nfs_attr_generation_counter);
46130 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
46131 }
46132
46133 void nfs_fattr_init(struct nfs_fattr *fattr)
46134 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
46135 index 7a2e442..8e544cc 100644
46136 --- a/fs/nfsd/vfs.c
46137 +++ b/fs/nfsd/vfs.c
46138 @@ -914,7 +914,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
46139 } else {
46140 oldfs = get_fs();
46141 set_fs(KERNEL_DS);
46142 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
46143 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
46144 set_fs(oldfs);
46145 }
46146
46147 @@ -1018,7 +1018,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
46148
46149 /* Write the data. */
46150 oldfs = get_fs(); set_fs(KERNEL_DS);
46151 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
46152 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
46153 set_fs(oldfs);
46154 if (host_err < 0)
46155 goto out_nfserr;
46156 @@ -1553,7 +1553,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
46157 */
46158
46159 oldfs = get_fs(); set_fs(KERNEL_DS);
46160 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
46161 + host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
46162 set_fs(oldfs);
46163
46164 if (host_err < 0)
46165 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
46166 index 9fde1c0..14e8827 100644
46167 --- a/fs/notify/fanotify/fanotify_user.c
46168 +++ b/fs/notify/fanotify/fanotify_user.c
46169 @@ -276,7 +276,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
46170 goto out_close_fd;
46171
46172 ret = -EFAULT;
46173 - if (copy_to_user(buf, &fanotify_event_metadata,
46174 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
46175 + copy_to_user(buf, &fanotify_event_metadata,
46176 fanotify_event_metadata.event_len))
46177 goto out_kill_access_response;
46178
46179 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
46180 index ee18815..7aa5d01 100644
46181 --- a/fs/notify/notification.c
46182 +++ b/fs/notify/notification.c
46183 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
46184 * get set to 0 so it will never get 'freed'
46185 */
46186 static struct fsnotify_event *q_overflow_event;
46187 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46188 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46189
46190 /**
46191 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
46192 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46193 */
46194 u32 fsnotify_get_cookie(void)
46195 {
46196 - return atomic_inc_return(&fsnotify_sync_cookie);
46197 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
46198 }
46199 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
46200
46201 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
46202 index 99e3610..02c1068 100644
46203 --- a/fs/ntfs/dir.c
46204 +++ b/fs/ntfs/dir.c
46205 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
46206 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
46207 ~(s64)(ndir->itype.index.block_size - 1)));
46208 /* Bounds checks. */
46209 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
46210 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
46211 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
46212 "inode 0x%lx or driver bug.", vdir->i_ino);
46213 goto err_out;
46214 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
46215 index c587e2d..3641eaa 100644
46216 --- a/fs/ntfs/file.c
46217 +++ b/fs/ntfs/file.c
46218 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
46219 #endif /* NTFS_RW */
46220 };
46221
46222 -const struct file_operations ntfs_empty_file_ops = {};
46223 +const struct file_operations ntfs_empty_file_ops __read_only;
46224
46225 -const struct inode_operations ntfs_empty_inode_ops = {};
46226 +const struct inode_operations ntfs_empty_inode_ops __read_only;
46227 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
46228 index 210c352..a174f83 100644
46229 --- a/fs/ocfs2/localalloc.c
46230 +++ b/fs/ocfs2/localalloc.c
46231 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
46232 goto bail;
46233 }
46234
46235 - atomic_inc(&osb->alloc_stats.moves);
46236 + atomic_inc_unchecked(&osb->alloc_stats.moves);
46237
46238 bail:
46239 if (handle)
46240 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
46241 index d355e6e..578d905 100644
46242 --- a/fs/ocfs2/ocfs2.h
46243 +++ b/fs/ocfs2/ocfs2.h
46244 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
46245
46246 struct ocfs2_alloc_stats
46247 {
46248 - atomic_t moves;
46249 - atomic_t local_data;
46250 - atomic_t bitmap_data;
46251 - atomic_t bg_allocs;
46252 - atomic_t bg_extends;
46253 + atomic_unchecked_t moves;
46254 + atomic_unchecked_t local_data;
46255 + atomic_unchecked_t bitmap_data;
46256 + atomic_unchecked_t bg_allocs;
46257 + atomic_unchecked_t bg_extends;
46258 };
46259
46260 enum ocfs2_local_alloc_state
46261 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
46262 index ba5d97e..c77db25 100644
46263 --- a/fs/ocfs2/suballoc.c
46264 +++ b/fs/ocfs2/suballoc.c
46265 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
46266 mlog_errno(status);
46267 goto bail;
46268 }
46269 - atomic_inc(&osb->alloc_stats.bg_extends);
46270 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
46271
46272 /* You should never ask for this much metadata */
46273 BUG_ON(bits_wanted >
46274 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
46275 mlog_errno(status);
46276 goto bail;
46277 }
46278 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46279 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46280
46281 *suballoc_loc = res.sr_bg_blkno;
46282 *suballoc_bit_start = res.sr_bit_offset;
46283 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
46284 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
46285 res->sr_bits);
46286
46287 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46288 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46289
46290 BUG_ON(res->sr_bits != 1);
46291
46292 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
46293 mlog_errno(status);
46294 goto bail;
46295 }
46296 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46297 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46298
46299 BUG_ON(res.sr_bits != 1);
46300
46301 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
46302 cluster_start,
46303 num_clusters);
46304 if (!status)
46305 - atomic_inc(&osb->alloc_stats.local_data);
46306 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
46307 } else {
46308 if (min_clusters > (osb->bitmap_cpg - 1)) {
46309 /* The only paths asking for contiguousness
46310 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
46311 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
46312 res.sr_bg_blkno,
46313 res.sr_bit_offset);
46314 - atomic_inc(&osb->alloc_stats.bitmap_data);
46315 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
46316 *num_clusters = res.sr_bits;
46317 }
46318 }
46319 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
46320 index 4994f8b..eaab8eb 100644
46321 --- a/fs/ocfs2/super.c
46322 +++ b/fs/ocfs2/super.c
46323 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
46324 "%10s => GlobalAllocs: %d LocalAllocs: %d "
46325 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
46326 "Stats",
46327 - atomic_read(&osb->alloc_stats.bitmap_data),
46328 - atomic_read(&osb->alloc_stats.local_data),
46329 - atomic_read(&osb->alloc_stats.bg_allocs),
46330 - atomic_read(&osb->alloc_stats.moves),
46331 - atomic_read(&osb->alloc_stats.bg_extends));
46332 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
46333 + atomic_read_unchecked(&osb->alloc_stats.local_data),
46334 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
46335 + atomic_read_unchecked(&osb->alloc_stats.moves),
46336 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
46337
46338 out += snprintf(buf + out, len - out,
46339 "%10s => State: %u Descriptor: %llu Size: %u bits "
46340 @@ -2119,11 +2119,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
46341 spin_lock_init(&osb->osb_xattr_lock);
46342 ocfs2_init_steal_slots(osb);
46343
46344 - atomic_set(&osb->alloc_stats.moves, 0);
46345 - atomic_set(&osb->alloc_stats.local_data, 0);
46346 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
46347 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
46348 - atomic_set(&osb->alloc_stats.bg_extends, 0);
46349 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
46350 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
46351 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
46352 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
46353 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
46354
46355 /* Copy the blockcheck stats from the superblock probe */
46356 osb->osb_ecc_stats = *stats;
46357 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
46358 index 5d22872..523db20 100644
46359 --- a/fs/ocfs2/symlink.c
46360 +++ b/fs/ocfs2/symlink.c
46361 @@ -142,7 +142,7 @@ bail:
46362
46363 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
46364 {
46365 - char *link = nd_get_link(nd);
46366 + const char *link = nd_get_link(nd);
46367 if (!IS_ERR(link))
46368 kfree(link);
46369 }
46370 diff --git a/fs/open.c b/fs/open.c
46371 index 22c41b5..78894cf 100644
46372 --- a/fs/open.c
46373 +++ b/fs/open.c
46374 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
46375 error = locks_verify_truncate(inode, NULL, length);
46376 if (!error)
46377 error = security_path_truncate(&path);
46378 +
46379 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
46380 + error = -EACCES;
46381 +
46382 if (!error)
46383 error = do_truncate(path.dentry, length, 0, NULL);
46384
46385 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
46386 if (__mnt_is_readonly(path.mnt))
46387 res = -EROFS;
46388
46389 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
46390 + res = -EACCES;
46391 +
46392 out_path_release:
46393 path_put(&path);
46394 out:
46395 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
46396 if (error)
46397 goto dput_and_out;
46398
46399 + gr_log_chdir(path.dentry, path.mnt);
46400 +
46401 set_fs_pwd(current->fs, &path);
46402
46403 dput_and_out:
46404 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
46405 goto out_putf;
46406
46407 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
46408 +
46409 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
46410 + error = -EPERM;
46411 +
46412 + if (!error)
46413 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
46414 +
46415 if (!error)
46416 set_fs_pwd(current->fs, &file->f_path);
46417 out_putf:
46418 @@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
46419 if (error)
46420 goto dput_and_out;
46421
46422 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
46423 + goto dput_and_out;
46424 +
46425 set_fs_root(current->fs, &path);
46426 +
46427 + gr_handle_chroot_chdir(&path);
46428 +
46429 error = 0;
46430 dput_and_out:
46431 path_put(&path);
46432 @@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
46433 if (error)
46434 return error;
46435 mutex_lock(&inode->i_mutex);
46436 +
46437 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
46438 + error = -EACCES;
46439 + goto out_unlock;
46440 + }
46441 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
46442 + error = -EACCES;
46443 + goto out_unlock;
46444 + }
46445 +
46446 error = security_path_chmod(path->dentry, path->mnt, mode);
46447 if (error)
46448 goto out_unlock;
46449 @@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
46450 int error;
46451 struct iattr newattrs;
46452
46453 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
46454 + return -EACCES;
46455 +
46456 newattrs.ia_valid = ATTR_CTIME;
46457 if (user != (uid_t) -1) {
46458 newattrs.ia_valid |= ATTR_UID;
46459 diff --git a/fs/partitions/efi.c b/fs/partitions/efi.c
46460 index 6296b40..417c00f 100644
46461 --- a/fs/partitions/efi.c
46462 +++ b/fs/partitions/efi.c
46463 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
46464 if (!gpt)
46465 return NULL;
46466
46467 + if (!le32_to_cpu(gpt->num_partition_entries))
46468 + return NULL;
46469 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
46470 + if (!pte)
46471 + return NULL;
46472 +
46473 count = le32_to_cpu(gpt->num_partition_entries) *
46474 le32_to_cpu(gpt->sizeof_partition_entry);
46475 - if (!count)
46476 - return NULL;
46477 - pte = kzalloc(count, GFP_KERNEL);
46478 - if (!pte)
46479 - return NULL;
46480 -
46481 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
46482 (u8 *) pte,
46483 count) < count) {
46484 diff --git a/fs/partitions/ldm.c b/fs/partitions/ldm.c
46485 index bd8ae78..539d250 100644
46486 --- a/fs/partitions/ldm.c
46487 +++ b/fs/partitions/ldm.c
46488 @@ -1324,7 +1324,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
46489 goto found;
46490 }
46491
46492 - f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
46493 + f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
46494 if (!f) {
46495 ldm_crit ("Out of memory.");
46496 return false;
46497 diff --git a/fs/pipe.c b/fs/pipe.c
46498 index 4065f07..68c0706 100644
46499 --- a/fs/pipe.c
46500 +++ b/fs/pipe.c
46501 @@ -420,9 +420,9 @@ redo:
46502 }
46503 if (bufs) /* More to do? */
46504 continue;
46505 - if (!pipe->writers)
46506 + if (!atomic_read(&pipe->writers))
46507 break;
46508 - if (!pipe->waiting_writers) {
46509 + if (!atomic_read(&pipe->waiting_writers)) {
46510 /* syscall merging: Usually we must not sleep
46511 * if O_NONBLOCK is set, or if we got some data.
46512 * But if a writer sleeps in kernel space, then
46513 @@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
46514 mutex_lock(&inode->i_mutex);
46515 pipe = inode->i_pipe;
46516
46517 - if (!pipe->readers) {
46518 + if (!atomic_read(&pipe->readers)) {
46519 send_sig(SIGPIPE, current, 0);
46520 ret = -EPIPE;
46521 goto out;
46522 @@ -530,7 +530,7 @@ redo1:
46523 for (;;) {
46524 int bufs;
46525
46526 - if (!pipe->readers) {
46527 + if (!atomic_read(&pipe->readers)) {
46528 send_sig(SIGPIPE, current, 0);
46529 if (!ret)
46530 ret = -EPIPE;
46531 @@ -616,9 +616,9 @@ redo2:
46532 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
46533 do_wakeup = 0;
46534 }
46535 - pipe->waiting_writers++;
46536 + atomic_inc(&pipe->waiting_writers);
46537 pipe_wait(pipe);
46538 - pipe->waiting_writers--;
46539 + atomic_dec(&pipe->waiting_writers);
46540 }
46541 out:
46542 mutex_unlock(&inode->i_mutex);
46543 @@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table *wait)
46544 mask = 0;
46545 if (filp->f_mode & FMODE_READ) {
46546 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
46547 - if (!pipe->writers && filp->f_version != pipe->w_counter)
46548 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
46549 mask |= POLLHUP;
46550 }
46551
46552 @@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table *wait)
46553 * Most Unices do not set POLLERR for FIFOs but on Linux they
46554 * behave exactly like pipes for poll().
46555 */
46556 - if (!pipe->readers)
46557 + if (!atomic_read(&pipe->readers))
46558 mask |= POLLERR;
46559 }
46560
46561 @@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int decr, int decw)
46562
46563 mutex_lock(&inode->i_mutex);
46564 pipe = inode->i_pipe;
46565 - pipe->readers -= decr;
46566 - pipe->writers -= decw;
46567 + atomic_sub(decr, &pipe->readers);
46568 + atomic_sub(decw, &pipe->writers);
46569
46570 - if (!pipe->readers && !pipe->writers) {
46571 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
46572 free_pipe_info(inode);
46573 } else {
46574 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
46575 @@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
46576
46577 if (inode->i_pipe) {
46578 ret = 0;
46579 - inode->i_pipe->readers++;
46580 + atomic_inc(&inode->i_pipe->readers);
46581 }
46582
46583 mutex_unlock(&inode->i_mutex);
46584 @@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
46585
46586 if (inode->i_pipe) {
46587 ret = 0;
46588 - inode->i_pipe->writers++;
46589 + atomic_inc(&inode->i_pipe->writers);
46590 }
46591
46592 mutex_unlock(&inode->i_mutex);
46593 @@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
46594 if (inode->i_pipe) {
46595 ret = 0;
46596 if (filp->f_mode & FMODE_READ)
46597 - inode->i_pipe->readers++;
46598 + atomic_inc(&inode->i_pipe->readers);
46599 if (filp->f_mode & FMODE_WRITE)
46600 - inode->i_pipe->writers++;
46601 + atomic_inc(&inode->i_pipe->writers);
46602 }
46603
46604 mutex_unlock(&inode->i_mutex);
46605 @@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
46606 inode->i_pipe = NULL;
46607 }
46608
46609 -static struct vfsmount *pipe_mnt __read_mostly;
46610 +struct vfsmount *pipe_mnt __read_mostly;
46611
46612 /*
46613 * pipefs_dname() is called from d_path().
46614 @@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(void)
46615 goto fail_iput;
46616 inode->i_pipe = pipe;
46617
46618 - pipe->readers = pipe->writers = 1;
46619 + atomic_set(&pipe->readers, 1);
46620 + atomic_set(&pipe->writers, 1);
46621 inode->i_fop = &rdwr_pipefifo_fops;
46622
46623 /*
46624 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
46625 index 15af622..0e9f4467 100644
46626 --- a/fs/proc/Kconfig
46627 +++ b/fs/proc/Kconfig
46628 @@ -30,12 +30,12 @@ config PROC_FS
46629
46630 config PROC_KCORE
46631 bool "/proc/kcore support" if !ARM
46632 - depends on PROC_FS && MMU
46633 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
46634
46635 config PROC_VMCORE
46636 bool "/proc/vmcore support"
46637 - depends on PROC_FS && CRASH_DUMP
46638 - default y
46639 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
46640 + default n
46641 help
46642 Exports the dump image of crashed kernel in ELF format.
46643
46644 @@ -59,8 +59,8 @@ config PROC_SYSCTL
46645 limited in memory.
46646
46647 config PROC_PAGE_MONITOR
46648 - default y
46649 - depends on PROC_FS && MMU
46650 + default n
46651 + depends on PROC_FS && MMU && !GRKERNSEC
46652 bool "Enable /proc page monitoring" if EXPERT
46653 help
46654 Various /proc files exist to monitor process memory utilization:
46655 diff --git a/fs/proc/array.c b/fs/proc/array.c
46656 index 3a1dafd..bf1bd84 100644
46657 --- a/fs/proc/array.c
46658 +++ b/fs/proc/array.c
46659 @@ -60,6 +60,7 @@
46660 #include <linux/tty.h>
46661 #include <linux/string.h>
46662 #include <linux/mman.h>
46663 +#include <linux/grsecurity.h>
46664 #include <linux/proc_fs.h>
46665 #include <linux/ioport.h>
46666 #include <linux/uaccess.h>
46667 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
46668 seq_putc(m, '\n');
46669 }
46670
46671 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
46672 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
46673 +{
46674 + if (p->mm)
46675 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
46676 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
46677 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
46678 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
46679 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
46680 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
46681 + else
46682 + seq_printf(m, "PaX:\t-----\n");
46683 +}
46684 +#endif
46685 +
46686 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
46687 struct pid *pid, struct task_struct *task)
46688 {
46689 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
46690 task_cpus_allowed(m, task);
46691 cpuset_task_status_allowed(m, task);
46692 task_context_switch_counts(m, task);
46693 +
46694 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
46695 + task_pax(m, task);
46696 +#endif
46697 +
46698 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
46699 + task_grsec_rbac(m, task);
46700 +#endif
46701 +
46702 return 0;
46703 }
46704
46705 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46706 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
46707 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
46708 + _mm->pax_flags & MF_PAX_SEGMEXEC))
46709 +#endif
46710 +
46711 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
46712 struct pid *pid, struct task_struct *task, int whole)
46713 {
46714 @@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
46715 char tcomm[sizeof(task->comm)];
46716 unsigned long flags;
46717
46718 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46719 + if (current->exec_id != m->exec_id) {
46720 + gr_log_badprocpid("stat");
46721 + return 0;
46722 + }
46723 +#endif
46724 +
46725 state = *get_task_state(task);
46726 vsize = eip = esp = 0;
46727 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
46728 @@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
46729 gtime = task->gtime;
46730 }
46731
46732 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46733 + if (PAX_RAND_FLAGS(mm)) {
46734 + eip = 0;
46735 + esp = 0;
46736 + wchan = 0;
46737 + }
46738 +#endif
46739 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46740 + wchan = 0;
46741 + eip =0;
46742 + esp =0;
46743 +#endif
46744 +
46745 /* scale priority and nice values from timeslices to -20..20 */
46746 /* to make it look like a "normal" Unix priority/nice value */
46747 priority = task_prio(task);
46748 @@ -489,9 +540,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
46749 vsize,
46750 mm ? get_mm_rss(mm) : 0,
46751 rsslim,
46752 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46753 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
46754 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
46755 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
46756 +#else
46757 mm ? (permitted ? mm->start_code : 1) : 0,
46758 mm ? (permitted ? mm->end_code : 1) : 0,
46759 (permitted && mm) ? mm->start_stack : 0,
46760 +#endif
46761 esp,
46762 eip,
46763 /* The signal information here is obsolete.
46764 @@ -533,8 +590,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
46765 struct pid *pid, struct task_struct *task)
46766 {
46767 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
46768 - struct mm_struct *mm = get_task_mm(task);
46769 + struct mm_struct *mm;
46770
46771 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46772 + if (current->exec_id != m->exec_id) {
46773 + gr_log_badprocpid("statm");
46774 + return 0;
46775 + }
46776 +#endif
46777 + mm = get_task_mm(task);
46778 if (mm) {
46779 size = task_statm(mm, &shared, &text, &data, &resident);
46780 mmput(mm);
46781 @@ -544,3 +608,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
46782
46783 return 0;
46784 }
46785 +
46786 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
46787 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
46788 +{
46789 + u32 curr_ip = 0;
46790 + unsigned long flags;
46791 +
46792 + if (lock_task_sighand(task, &flags)) {
46793 + curr_ip = task->signal->curr_ip;
46794 + unlock_task_sighand(task, &flags);
46795 + }
46796 +
46797 + return sprintf(buffer, "%pI4\n", &curr_ip);
46798 +}
46799 +#endif
46800 diff --git a/fs/proc/base.c b/fs/proc/base.c
46801 index 1ace83d..f5e575d 100644
46802 --- a/fs/proc/base.c
46803 +++ b/fs/proc/base.c
46804 @@ -107,6 +107,22 @@ struct pid_entry {
46805 union proc_op op;
46806 };
46807
46808 +struct getdents_callback {
46809 + struct linux_dirent __user * current_dir;
46810 + struct linux_dirent __user * previous;
46811 + struct file * file;
46812 + int count;
46813 + int error;
46814 +};
46815 +
46816 +static int gr_fake_filldir(void * __buf, const char *name, int namlen,
46817 + loff_t offset, u64 ino, unsigned int d_type)
46818 +{
46819 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
46820 + buf->error = -EINVAL;
46821 + return 0;
46822 +}
46823 +
46824 #define NOD(NAME, MODE, IOP, FOP, OP) { \
46825 .name = (NAME), \
46826 .len = sizeof(NAME) - 1, \
46827 @@ -194,26 +210,6 @@ static int proc_root_link(struct inode *inode, struct path *path)
46828 return result;
46829 }
46830
46831 -static struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
46832 -{
46833 - struct mm_struct *mm;
46834 - int err;
46835 -
46836 - err = mutex_lock_killable(&task->signal->cred_guard_mutex);
46837 - if (err)
46838 - return ERR_PTR(err);
46839 -
46840 - mm = get_task_mm(task);
46841 - if (mm && mm != current->mm &&
46842 - !ptrace_may_access(task, mode)) {
46843 - mmput(mm);
46844 - mm = ERR_PTR(-EACCES);
46845 - }
46846 - mutex_unlock(&task->signal->cred_guard_mutex);
46847 -
46848 - return mm;
46849 -}
46850 -
46851 struct mm_struct *mm_for_maps(struct task_struct *task)
46852 {
46853 return mm_access(task, PTRACE_MODE_READ);
46854 @@ -229,6 +225,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
46855 if (!mm->arg_end)
46856 goto out_mm; /* Shh! No looking before we're done */
46857
46858 + if (gr_acl_handle_procpidmem(task))
46859 + goto out_mm;
46860 +
46861 len = mm->arg_end - mm->arg_start;
46862
46863 if (len > PAGE_SIZE)
46864 @@ -256,12 +255,28 @@ out:
46865 return res;
46866 }
46867
46868 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46869 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
46870 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
46871 + _mm->pax_flags & MF_PAX_SEGMEXEC))
46872 +#endif
46873 +
46874 static int proc_pid_auxv(struct task_struct *task, char *buffer)
46875 {
46876 struct mm_struct *mm = mm_for_maps(task);
46877 int res = PTR_ERR(mm);
46878 if (mm && !IS_ERR(mm)) {
46879 unsigned int nwords = 0;
46880 +
46881 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46882 + /* allow if we're currently ptracing this task */
46883 + if (PAX_RAND_FLAGS(mm) &&
46884 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
46885 + mmput(mm);
46886 + return 0;
46887 + }
46888 +#endif
46889 +
46890 do {
46891 nwords += 2;
46892 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
46893 @@ -275,7 +290,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
46894 }
46895
46896
46897 -#ifdef CONFIG_KALLSYMS
46898 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
46899 /*
46900 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
46901 * Returns the resolved symbol. If that fails, simply return the address.
46902 @@ -314,7 +329,7 @@ static void unlock_trace(struct task_struct *task)
46903 mutex_unlock(&task->signal->cred_guard_mutex);
46904 }
46905
46906 -#ifdef CONFIG_STACKTRACE
46907 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
46908
46909 #define MAX_STACK_TRACE_DEPTH 64
46910
46911 @@ -505,7 +520,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
46912 return count;
46913 }
46914
46915 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
46916 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
46917 static int proc_pid_syscall(struct task_struct *task, char *buffer)
46918 {
46919 long nr;
46920 @@ -534,7 +549,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
46921 /************************************************************************/
46922
46923 /* permission checks */
46924 -static int proc_fd_access_allowed(struct inode *inode)
46925 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
46926 {
46927 struct task_struct *task;
46928 int allowed = 0;
46929 @@ -544,7 +559,10 @@ static int proc_fd_access_allowed(struct inode *inode)
46930 */
46931 task = get_proc_task(inode);
46932 if (task) {
46933 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
46934 + if (log)
46935 + allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
46936 + else
46937 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
46938 put_task_struct(task);
46939 }
46940 return allowed;
46941 @@ -786,6 +804,10 @@ static int mem_open(struct inode* inode, struct file* file)
46942 file->f_mode |= FMODE_UNSIGNED_OFFSET;
46943 file->private_data = mm;
46944
46945 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46946 + file->f_version = current->exec_id;
46947 +#endif
46948 +
46949 return 0;
46950 }
46951
46952 @@ -797,6 +819,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
46953 ssize_t copied;
46954 char *page;
46955
46956 +#ifdef CONFIG_GRKERNSEC
46957 + if (write)
46958 + return -EPERM;
46959 +#endif
46960 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46961 + if (file->f_version != current->exec_id) {
46962 + gr_log_badprocpid("mem");
46963 + return 0;
46964 + }
46965 +#endif
46966 +
46967 if (!mm)
46968 return 0;
46969
46970 @@ -897,6 +930,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
46971 if (!task)
46972 goto out_no_task;
46973
46974 + if (gr_acl_handle_procpidmem(task))
46975 + goto out;
46976 +
46977 ret = -ENOMEM;
46978 page = (char *)__get_free_page(GFP_TEMPORARY);
46979 if (!page)
46980 @@ -1519,7 +1555,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
46981 path_put(&nd->path);
46982
46983 /* Are we allowed to snoop on the tasks file descriptors? */
46984 - if (!proc_fd_access_allowed(inode))
46985 + if (!proc_fd_access_allowed(inode,0))
46986 goto out;
46987
46988 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
46989 @@ -1558,8 +1594,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
46990 struct path path;
46991
46992 /* Are we allowed to snoop on the tasks file descriptors? */
46993 - if (!proc_fd_access_allowed(inode))
46994 - goto out;
46995 + /* logging this is needed for learning on chromium to work properly,
46996 + but we don't want to flood the logs from 'ps' which does a readlink
46997 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
46998 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
46999 + */
47000 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
47001 + if (!proc_fd_access_allowed(inode,0))
47002 + goto out;
47003 + } else {
47004 + if (!proc_fd_access_allowed(inode,1))
47005 + goto out;
47006 + }
47007
47008 error = PROC_I(inode)->op.proc_get_link(inode, &path);
47009 if (error)
47010 @@ -1624,7 +1670,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
47011 rcu_read_lock();
47012 cred = __task_cred(task);
47013 inode->i_uid = cred->euid;
47014 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47015 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47016 +#else
47017 inode->i_gid = cred->egid;
47018 +#endif
47019 rcu_read_unlock();
47020 }
47021 security_task_to_inode(task, inode);
47022 @@ -1642,6 +1692,9 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
47023 struct inode *inode = dentry->d_inode;
47024 struct task_struct *task;
47025 const struct cred *cred;
47026 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47027 + const struct cred *tmpcred = current_cred();
47028 +#endif
47029
47030 generic_fillattr(inode, stat);
47031
47032 @@ -1649,13 +1702,41 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
47033 stat->uid = 0;
47034 stat->gid = 0;
47035 task = pid_task(proc_pid(inode), PIDTYPE_PID);
47036 +
47037 + if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
47038 + rcu_read_unlock();
47039 + return -ENOENT;
47040 + }
47041 +
47042 if (task) {
47043 + cred = __task_cred(task);
47044 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47045 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
47046 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47047 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
47048 +#endif
47049 + ) {
47050 +#endif
47051 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
47052 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47053 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
47054 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47055 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
47056 +#endif
47057 task_dumpable(task)) {
47058 - cred = __task_cred(task);
47059 stat->uid = cred->euid;
47060 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47061 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
47062 +#else
47063 stat->gid = cred->egid;
47064 +#endif
47065 }
47066 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47067 + } else {
47068 + rcu_read_unlock();
47069 + return -ENOENT;
47070 + }
47071 +#endif
47072 }
47073 rcu_read_unlock();
47074 return 0;
47075 @@ -1692,11 +1773,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
47076
47077 if (task) {
47078 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
47079 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47080 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
47081 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47082 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
47083 +#endif
47084 task_dumpable(task)) {
47085 rcu_read_lock();
47086 cred = __task_cred(task);
47087 inode->i_uid = cred->euid;
47088 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47089 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47090 +#else
47091 inode->i_gid = cred->egid;
47092 +#endif
47093 rcu_read_unlock();
47094 } else {
47095 inode->i_uid = 0;
47096 @@ -1814,7 +1904,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
47097 int fd = proc_fd(inode);
47098
47099 if (task) {
47100 - files = get_files_struct(task);
47101 + if (!gr_acl_handle_procpidmem(task))
47102 + files = get_files_struct(task);
47103 put_task_struct(task);
47104 }
47105 if (files) {
47106 @@ -2082,11 +2173,21 @@ static const struct file_operations proc_fd_operations = {
47107 */
47108 static int proc_fd_permission(struct inode *inode, int mask)
47109 {
47110 + struct task_struct *task;
47111 int rv = generic_permission(inode, mask);
47112 - if (rv == 0)
47113 - return 0;
47114 +
47115 if (task_pid(current) == proc_pid(inode))
47116 rv = 0;
47117 +
47118 + task = get_proc_task(inode);
47119 + if (task == NULL)
47120 + return rv;
47121 +
47122 + if (gr_acl_handle_procpidmem(task))
47123 + rv = -EACCES;
47124 +
47125 + put_task_struct(task);
47126 +
47127 return rv;
47128 }
47129
47130 @@ -2196,6 +2297,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
47131 if (!task)
47132 goto out_no_task;
47133
47134 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47135 + goto out;
47136 +
47137 /*
47138 * Yes, it does not scale. And it should not. Don't add
47139 * new entries into /proc/<tgid>/ without very good reasons.
47140 @@ -2240,6 +2344,9 @@ static int proc_pident_readdir(struct file *filp,
47141 if (!task)
47142 goto out_no_task;
47143
47144 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47145 + goto out;
47146 +
47147 ret = 0;
47148 i = filp->f_pos;
47149 switch (i) {
47150 @@ -2510,7 +2617,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
47151 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
47152 void *cookie)
47153 {
47154 - char *s = nd_get_link(nd);
47155 + const char *s = nd_get_link(nd);
47156 if (!IS_ERR(s))
47157 __putname(s);
47158 }
47159 @@ -2708,7 +2815,7 @@ static const struct pid_entry tgid_base_stuff[] = {
47160 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
47161 #endif
47162 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
47163 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47164 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47165 INF("syscall", S_IRUGO, proc_pid_syscall),
47166 #endif
47167 INF("cmdline", S_IRUGO, proc_pid_cmdline),
47168 @@ -2733,10 +2840,10 @@ static const struct pid_entry tgid_base_stuff[] = {
47169 #ifdef CONFIG_SECURITY
47170 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
47171 #endif
47172 -#ifdef CONFIG_KALLSYMS
47173 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47174 INF("wchan", S_IRUGO, proc_pid_wchan),
47175 #endif
47176 -#ifdef CONFIG_STACKTRACE
47177 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47178 ONE("stack", S_IRUGO, proc_pid_stack),
47179 #endif
47180 #ifdef CONFIG_SCHEDSTATS
47181 @@ -2770,6 +2877,9 @@ static const struct pid_entry tgid_base_stuff[] = {
47182 #ifdef CONFIG_HARDWALL
47183 INF("hardwall", S_IRUGO, proc_pid_hardwall),
47184 #endif
47185 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47186 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
47187 +#endif
47188 };
47189
47190 static int proc_tgid_base_readdir(struct file * filp,
47191 @@ -2895,7 +3005,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
47192 if (!inode)
47193 goto out;
47194
47195 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47196 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
47197 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47198 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47199 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
47200 +#else
47201 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
47202 +#endif
47203 inode->i_op = &proc_tgid_base_inode_operations;
47204 inode->i_fop = &proc_tgid_base_operations;
47205 inode->i_flags|=S_IMMUTABLE;
47206 @@ -2937,7 +3054,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
47207 if (!task)
47208 goto out;
47209
47210 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47211 + goto out_put_task;
47212 +
47213 result = proc_pid_instantiate(dir, dentry, task, NULL);
47214 +out_put_task:
47215 put_task_struct(task);
47216 out:
47217 return result;
47218 @@ -3002,6 +3123,11 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
47219 {
47220 unsigned int nr;
47221 struct task_struct *reaper;
47222 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47223 + const struct cred *tmpcred = current_cred();
47224 + const struct cred *itercred;
47225 +#endif
47226 + filldir_t __filldir = filldir;
47227 struct tgid_iter iter;
47228 struct pid_namespace *ns;
47229
47230 @@ -3025,8 +3151,27 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
47231 for (iter = next_tgid(ns, iter);
47232 iter.task;
47233 iter.tgid += 1, iter = next_tgid(ns, iter)) {
47234 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47235 + rcu_read_lock();
47236 + itercred = __task_cred(iter.task);
47237 +#endif
47238 + if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
47239 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47240 + || (tmpcred->uid && (itercred->uid != tmpcred->uid)
47241 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47242 + && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
47243 +#endif
47244 + )
47245 +#endif
47246 + )
47247 + __filldir = &gr_fake_filldir;
47248 + else
47249 + __filldir = filldir;
47250 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47251 + rcu_read_unlock();
47252 +#endif
47253 filp->f_pos = iter.tgid + TGID_OFFSET;
47254 - if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
47255 + if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
47256 put_task_struct(iter.task);
47257 goto out;
47258 }
47259 @@ -3054,7 +3199,7 @@ static const struct pid_entry tid_base_stuff[] = {
47260 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
47261 #endif
47262 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
47263 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47264 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47265 INF("syscall", S_IRUGO, proc_pid_syscall),
47266 #endif
47267 INF("cmdline", S_IRUGO, proc_pid_cmdline),
47268 @@ -3078,10 +3223,10 @@ static const struct pid_entry tid_base_stuff[] = {
47269 #ifdef CONFIG_SECURITY
47270 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
47271 #endif
47272 -#ifdef CONFIG_KALLSYMS
47273 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47274 INF("wchan", S_IRUGO, proc_pid_wchan),
47275 #endif
47276 -#ifdef CONFIG_STACKTRACE
47277 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47278 ONE("stack", S_IRUGO, proc_pid_stack),
47279 #endif
47280 #ifdef CONFIG_SCHEDSTATS
47281 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
47282 index 82676e3..5f8518a 100644
47283 --- a/fs/proc/cmdline.c
47284 +++ b/fs/proc/cmdline.c
47285 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
47286
47287 static int __init proc_cmdline_init(void)
47288 {
47289 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47290 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
47291 +#else
47292 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
47293 +#endif
47294 return 0;
47295 }
47296 module_init(proc_cmdline_init);
47297 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
47298 index b143471..bb105e5 100644
47299 --- a/fs/proc/devices.c
47300 +++ b/fs/proc/devices.c
47301 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
47302
47303 static int __init proc_devices_init(void)
47304 {
47305 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47306 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
47307 +#else
47308 proc_create("devices", 0, NULL, &proc_devinfo_operations);
47309 +#endif
47310 return 0;
47311 }
47312 module_init(proc_devices_init);
47313 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
47314 index 7737c54..7172574 100644
47315 --- a/fs/proc/inode.c
47316 +++ b/fs/proc/inode.c
47317 @@ -18,12 +18,18 @@
47318 #include <linux/module.h>
47319 #include <linux/sysctl.h>
47320 #include <linux/slab.h>
47321 +#include <linux/grsecurity.h>
47322
47323 #include <asm/system.h>
47324 #include <asm/uaccess.h>
47325
47326 #include "internal.h"
47327
47328 +#ifdef CONFIG_PROC_SYSCTL
47329 +extern const struct inode_operations proc_sys_inode_operations;
47330 +extern const struct inode_operations proc_sys_dir_operations;
47331 +#endif
47332 +
47333 static void proc_evict_inode(struct inode *inode)
47334 {
47335 struct proc_dir_entry *de;
47336 @@ -49,6 +55,13 @@ static void proc_evict_inode(struct inode *inode)
47337 ns_ops = PROC_I(inode)->ns_ops;
47338 if (ns_ops && ns_ops->put)
47339 ns_ops->put(PROC_I(inode)->ns);
47340 +
47341 +#ifdef CONFIG_PROC_SYSCTL
47342 + if (inode->i_op == &proc_sys_inode_operations ||
47343 + inode->i_op == &proc_sys_dir_operations)
47344 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
47345 +#endif
47346 +
47347 }
47348
47349 static struct kmem_cache * proc_inode_cachep;
47350 @@ -440,7 +453,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
47351 if (de->mode) {
47352 inode->i_mode = de->mode;
47353 inode->i_uid = de->uid;
47354 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47355 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47356 +#else
47357 inode->i_gid = de->gid;
47358 +#endif
47359 }
47360 if (de->size)
47361 inode->i_size = de->size;
47362 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
47363 index 7838e5c..ff92cbc 100644
47364 --- a/fs/proc/internal.h
47365 +++ b/fs/proc/internal.h
47366 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47367 struct pid *pid, struct task_struct *task);
47368 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47369 struct pid *pid, struct task_struct *task);
47370 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47371 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
47372 +#endif
47373 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
47374
47375 extern const struct file_operations proc_maps_operations;
47376 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
47377 index d245cb2..f4e8498 100644
47378 --- a/fs/proc/kcore.c
47379 +++ b/fs/proc/kcore.c
47380 @@ -478,9 +478,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
47381 * the addresses in the elf_phdr on our list.
47382 */
47383 start = kc_offset_to_vaddr(*fpos - elf_buflen);
47384 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
47385 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
47386 + if (tsz > buflen)
47387 tsz = buflen;
47388 -
47389 +
47390 while (buflen) {
47391 struct kcore_list *m;
47392
47393 @@ -509,20 +510,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
47394 kfree(elf_buf);
47395 } else {
47396 if (kern_addr_valid(start)) {
47397 - unsigned long n;
47398 + char *elf_buf;
47399 + mm_segment_t oldfs;
47400
47401 - n = copy_to_user(buffer, (char *)start, tsz);
47402 - /*
47403 - * We cannot distingush between fault on source
47404 - * and fault on destination. When this happens
47405 - * we clear too and hope it will trigger the
47406 - * EFAULT again.
47407 - */
47408 - if (n) {
47409 - if (clear_user(buffer + tsz - n,
47410 - n))
47411 + elf_buf = kmalloc(tsz, GFP_KERNEL);
47412 + if (!elf_buf)
47413 + return -ENOMEM;
47414 + oldfs = get_fs();
47415 + set_fs(KERNEL_DS);
47416 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
47417 + set_fs(oldfs);
47418 + if (copy_to_user(buffer, elf_buf, tsz)) {
47419 + kfree(elf_buf);
47420 return -EFAULT;
47421 + }
47422 }
47423 + set_fs(oldfs);
47424 + kfree(elf_buf);
47425 } else {
47426 if (clear_user(buffer, tsz))
47427 return -EFAULT;
47428 @@ -542,6 +546,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
47429
47430 static int open_kcore(struct inode *inode, struct file *filp)
47431 {
47432 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
47433 + return -EPERM;
47434 +#endif
47435 if (!capable(CAP_SYS_RAWIO))
47436 return -EPERM;
47437 if (kcore_need_update)
47438 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
47439 index 80e4645..53e5fcf 100644
47440 --- a/fs/proc/meminfo.c
47441 +++ b/fs/proc/meminfo.c
47442 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
47443 vmi.used >> 10,
47444 vmi.largest_chunk >> 10
47445 #ifdef CONFIG_MEMORY_FAILURE
47446 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
47447 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
47448 #endif
47449 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
47450 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
47451 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
47452 index b1822dd..df622cb 100644
47453 --- a/fs/proc/nommu.c
47454 +++ b/fs/proc/nommu.c
47455 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
47456 if (len < 1)
47457 len = 1;
47458 seq_printf(m, "%*c", len, ' ');
47459 - seq_path(m, &file->f_path, "");
47460 + seq_path(m, &file->f_path, "\n\\");
47461 }
47462
47463 seq_putc(m, '\n');
47464 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
47465 index f738024..876984a 100644
47466 --- a/fs/proc/proc_net.c
47467 +++ b/fs/proc/proc_net.c
47468 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
47469 struct task_struct *task;
47470 struct nsproxy *ns;
47471 struct net *net = NULL;
47472 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47473 + const struct cred *cred = current_cred();
47474 +#endif
47475 +
47476 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47477 + if (cred->fsuid)
47478 + return net;
47479 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47480 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
47481 + return net;
47482 +#endif
47483
47484 rcu_read_lock();
47485 task = pid_task(proc_pid(dir), PIDTYPE_PID);
47486 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
47487 index a6b6217..1e0579d 100644
47488 --- a/fs/proc/proc_sysctl.c
47489 +++ b/fs/proc/proc_sysctl.c
47490 @@ -9,11 +9,13 @@
47491 #include <linux/namei.h>
47492 #include "internal.h"
47493
47494 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
47495 +
47496 static const struct dentry_operations proc_sys_dentry_operations;
47497 static const struct file_operations proc_sys_file_operations;
47498 -static const struct inode_operations proc_sys_inode_operations;
47499 +const struct inode_operations proc_sys_inode_operations;
47500 static const struct file_operations proc_sys_dir_file_operations;
47501 -static const struct inode_operations proc_sys_dir_operations;
47502 +const struct inode_operations proc_sys_dir_operations;
47503
47504 void proc_sys_poll_notify(struct ctl_table_poll *poll)
47505 {
47506 @@ -131,8 +133,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
47507
47508 err = NULL;
47509 d_set_d_op(dentry, &proc_sys_dentry_operations);
47510 +
47511 + gr_handle_proc_create(dentry, inode);
47512 +
47513 d_add(dentry, inode);
47514
47515 + if (gr_handle_sysctl(p, MAY_EXEC))
47516 + err = ERR_PTR(-ENOENT);
47517 +
47518 out:
47519 sysctl_head_finish(head);
47520 return err;
47521 @@ -163,6 +171,12 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
47522 if (!table->proc_handler)
47523 goto out;
47524
47525 +#ifdef CONFIG_GRKERNSEC
47526 + error = -EPERM;
47527 + if (write && !capable(CAP_SYS_ADMIN))
47528 + goto out;
47529 +#endif
47530 +
47531 /* careful: calling conventions are nasty here */
47532 res = count;
47533 error = table->proc_handler(table, write, buf, &res, ppos);
47534 @@ -245,6 +259,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
47535 return -ENOMEM;
47536 } else {
47537 d_set_d_op(child, &proc_sys_dentry_operations);
47538 +
47539 + gr_handle_proc_create(child, inode);
47540 +
47541 d_add(child, inode);
47542 }
47543 } else {
47544 @@ -273,6 +290,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
47545 if (*pos < file->f_pos)
47546 continue;
47547
47548 + if (gr_handle_sysctl(table, 0))
47549 + continue;
47550 +
47551 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
47552 if (res)
47553 return res;
47554 @@ -398,6 +418,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
47555 if (IS_ERR(head))
47556 return PTR_ERR(head);
47557
47558 + if (table && gr_handle_sysctl(table, MAY_EXEC))
47559 + return -ENOENT;
47560 +
47561 generic_fillattr(inode, stat);
47562 if (table)
47563 stat->mode = (stat->mode & S_IFMT) | table->mode;
47564 @@ -420,13 +443,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
47565 .llseek = generic_file_llseek,
47566 };
47567
47568 -static const struct inode_operations proc_sys_inode_operations = {
47569 +const struct inode_operations proc_sys_inode_operations = {
47570 .permission = proc_sys_permission,
47571 .setattr = proc_sys_setattr,
47572 .getattr = proc_sys_getattr,
47573 };
47574
47575 -static const struct inode_operations proc_sys_dir_operations = {
47576 +const struct inode_operations proc_sys_dir_operations = {
47577 .lookup = proc_sys_lookup,
47578 .permission = proc_sys_permission,
47579 .setattr = proc_sys_setattr,
47580 diff --git a/fs/proc/root.c b/fs/proc/root.c
47581 index 03102d9..4ae347e 100644
47582 --- a/fs/proc/root.c
47583 +++ b/fs/proc/root.c
47584 @@ -121,7 +121,15 @@ void __init proc_root_init(void)
47585 #ifdef CONFIG_PROC_DEVICETREE
47586 proc_device_tree_init();
47587 #endif
47588 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47589 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47590 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
47591 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47592 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47593 +#endif
47594 +#else
47595 proc_mkdir("bus", NULL);
47596 +#endif
47597 proc_sys_init();
47598 }
47599
47600 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
47601 index 7dcd2a2..b2f410e 100644
47602 --- a/fs/proc/task_mmu.c
47603 +++ b/fs/proc/task_mmu.c
47604 @@ -11,6 +11,7 @@
47605 #include <linux/rmap.h>
47606 #include <linux/swap.h>
47607 #include <linux/swapops.h>
47608 +#include <linux/grsecurity.h>
47609
47610 #include <asm/elf.h>
47611 #include <asm/uaccess.h>
47612 @@ -52,8 +53,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
47613 "VmExe:\t%8lu kB\n"
47614 "VmLib:\t%8lu kB\n"
47615 "VmPTE:\t%8lu kB\n"
47616 - "VmSwap:\t%8lu kB\n",
47617 - hiwater_vm << (PAGE_SHIFT-10),
47618 + "VmSwap:\t%8lu kB\n"
47619 +
47620 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
47621 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
47622 +#endif
47623 +
47624 + ,hiwater_vm << (PAGE_SHIFT-10),
47625 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
47626 mm->locked_vm << (PAGE_SHIFT-10),
47627 mm->pinned_vm << (PAGE_SHIFT-10),
47628 @@ -62,7 +68,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
47629 data << (PAGE_SHIFT-10),
47630 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
47631 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
47632 - swap << (PAGE_SHIFT-10));
47633 + swap << (PAGE_SHIFT-10)
47634 +
47635 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
47636 + , mm->context.user_cs_base, mm->context.user_cs_limit
47637 +#endif
47638 +
47639 + );
47640 }
47641
47642 unsigned long task_vsize(struct mm_struct *mm)
47643 @@ -209,6 +221,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
47644 return ret;
47645 }
47646
47647 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47648 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47649 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47650 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47651 +#endif
47652 +
47653 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
47654 {
47655 struct mm_struct *mm = vma->vm_mm;
47656 @@ -227,13 +245,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
47657 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
47658 }
47659
47660 - /* We don't show the stack guard page in /proc/maps */
47661 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47662 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
47663 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
47664 +#else
47665 start = vma->vm_start;
47666 - if (stack_guard_page_start(vma, start))
47667 - start += PAGE_SIZE;
47668 end = vma->vm_end;
47669 - if (stack_guard_page_end(vma, end))
47670 - end -= PAGE_SIZE;
47671 +#endif
47672
47673 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
47674 start,
47675 @@ -242,7 +260,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
47676 flags & VM_WRITE ? 'w' : '-',
47677 flags & VM_EXEC ? 'x' : '-',
47678 flags & VM_MAYSHARE ? 's' : 'p',
47679 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47680 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
47681 +#else
47682 pgoff,
47683 +#endif
47684 MAJOR(dev), MINOR(dev), ino, &len);
47685
47686 /*
47687 @@ -251,7 +273,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
47688 */
47689 if (file) {
47690 pad_len_spaces(m, len);
47691 - seq_path(m, &file->f_path, "\n");
47692 + seq_path(m, &file->f_path, "\n\\");
47693 } else {
47694 const char *name = arch_vma_name(vma);
47695 if (!name) {
47696 @@ -259,8 +281,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
47697 if (vma->vm_start <= mm->brk &&
47698 vma->vm_end >= mm->start_brk) {
47699 name = "[heap]";
47700 - } else if (vma->vm_start <= mm->start_stack &&
47701 - vma->vm_end >= mm->start_stack) {
47702 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
47703 + (vma->vm_start <= mm->start_stack &&
47704 + vma->vm_end >= mm->start_stack)) {
47705 name = "[stack]";
47706 }
47707 } else {
47708 @@ -281,6 +304,13 @@ static int show_map(struct seq_file *m, void *v)
47709 struct proc_maps_private *priv = m->private;
47710 struct task_struct *task = priv->task;
47711
47712 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47713 + if (current->exec_id != m->exec_id) {
47714 + gr_log_badprocpid("maps");
47715 + return 0;
47716 + }
47717 +#endif
47718 +
47719 show_map_vma(m, vma);
47720
47721 if (m->count < m->size) /* vma is copied successfully */
47722 @@ -434,12 +464,23 @@ static int show_smap(struct seq_file *m, void *v)
47723 .private = &mss,
47724 };
47725
47726 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47727 + if (current->exec_id != m->exec_id) {
47728 + gr_log_badprocpid("smaps");
47729 + return 0;
47730 + }
47731 +#endif
47732 memset(&mss, 0, sizeof mss);
47733 - mss.vma = vma;
47734 - /* mmap_sem is held in m_start */
47735 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
47736 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
47737 -
47738 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47739 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
47740 +#endif
47741 + mss.vma = vma;
47742 + /* mmap_sem is held in m_start */
47743 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
47744 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
47745 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47746 + }
47747 +#endif
47748 show_map_vma(m, vma);
47749
47750 seq_printf(m,
47751 @@ -457,7 +498,11 @@ static int show_smap(struct seq_file *m, void *v)
47752 "KernelPageSize: %8lu kB\n"
47753 "MMUPageSize: %8lu kB\n"
47754 "Locked: %8lu kB\n",
47755 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47756 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
47757 +#else
47758 (vma->vm_end - vma->vm_start) >> 10,
47759 +#endif
47760 mss.resident >> 10,
47761 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
47762 mss.shared_clean >> 10,
47763 @@ -1015,6 +1060,13 @@ static int show_numa_map(struct seq_file *m, void *v)
47764 int n;
47765 char buffer[50];
47766
47767 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47768 + if (current->exec_id != m->exec_id) {
47769 + gr_log_badprocpid("numa_maps");
47770 + return 0;
47771 + }
47772 +#endif
47773 +
47774 if (!mm)
47775 return 0;
47776
47777 @@ -1032,11 +1084,15 @@ static int show_numa_map(struct seq_file *m, void *v)
47778 mpol_to_str(buffer, sizeof(buffer), pol, 0);
47779 mpol_cond_put(pol);
47780
47781 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47782 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
47783 +#else
47784 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
47785 +#endif
47786
47787 if (file) {
47788 seq_printf(m, " file=");
47789 - seq_path(m, &file->f_path, "\n\t= ");
47790 + seq_path(m, &file->f_path, "\n\t\\= ");
47791 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
47792 seq_printf(m, " heap");
47793 } else if (vma->vm_start <= mm->start_stack &&
47794 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
47795 index 980de54..2a4db5f 100644
47796 --- a/fs/proc/task_nommu.c
47797 +++ b/fs/proc/task_nommu.c
47798 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
47799 else
47800 bytes += kobjsize(mm);
47801
47802 - if (current->fs && current->fs->users > 1)
47803 + if (current->fs && atomic_read(&current->fs->users) > 1)
47804 sbytes += kobjsize(current->fs);
47805 else
47806 bytes += kobjsize(current->fs);
47807 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
47808
47809 if (file) {
47810 pad_len_spaces(m, len);
47811 - seq_path(m, &file->f_path, "");
47812 + seq_path(m, &file->f_path, "\n\\");
47813 } else if (mm) {
47814 if (vma->vm_start <= mm->start_stack &&
47815 vma->vm_end >= mm->start_stack) {
47816 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
47817 index d67908b..d13f6a6 100644
47818 --- a/fs/quota/netlink.c
47819 +++ b/fs/quota/netlink.c
47820 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
47821 void quota_send_warning(short type, unsigned int id, dev_t dev,
47822 const char warntype)
47823 {
47824 - static atomic_t seq;
47825 + static atomic_unchecked_t seq;
47826 struct sk_buff *skb;
47827 void *msg_head;
47828 int ret;
47829 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
47830 "VFS: Not enough memory to send quota warning.\n");
47831 return;
47832 }
47833 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
47834 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
47835 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
47836 if (!msg_head) {
47837 printk(KERN_ERR
47838 diff --git a/fs/readdir.c b/fs/readdir.c
47839 index 356f715..c918d38 100644
47840 --- a/fs/readdir.c
47841 +++ b/fs/readdir.c
47842 @@ -17,6 +17,7 @@
47843 #include <linux/security.h>
47844 #include <linux/syscalls.h>
47845 #include <linux/unistd.h>
47846 +#include <linux/namei.h>
47847
47848 #include <asm/uaccess.h>
47849
47850 @@ -67,6 +68,7 @@ struct old_linux_dirent {
47851
47852 struct readdir_callback {
47853 struct old_linux_dirent __user * dirent;
47854 + struct file * file;
47855 int result;
47856 };
47857
47858 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
47859 buf->result = -EOVERFLOW;
47860 return -EOVERFLOW;
47861 }
47862 +
47863 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47864 + return 0;
47865 +
47866 buf->result++;
47867 dirent = buf->dirent;
47868 if (!access_ok(VERIFY_WRITE, dirent,
47869 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
47870
47871 buf.result = 0;
47872 buf.dirent = dirent;
47873 + buf.file = file;
47874
47875 error = vfs_readdir(file, fillonedir, &buf);
47876 if (buf.result)
47877 @@ -142,6 +149,7 @@ struct linux_dirent {
47878 struct getdents_callback {
47879 struct linux_dirent __user * current_dir;
47880 struct linux_dirent __user * previous;
47881 + struct file * file;
47882 int count;
47883 int error;
47884 };
47885 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
47886 buf->error = -EOVERFLOW;
47887 return -EOVERFLOW;
47888 }
47889 +
47890 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47891 + return 0;
47892 +
47893 dirent = buf->previous;
47894 if (dirent) {
47895 if (__put_user(offset, &dirent->d_off))
47896 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
47897 buf.previous = NULL;
47898 buf.count = count;
47899 buf.error = 0;
47900 + buf.file = file;
47901
47902 error = vfs_readdir(file, filldir, &buf);
47903 if (error >= 0)
47904 @@ -229,6 +242,7 @@ out:
47905 struct getdents_callback64 {
47906 struct linux_dirent64 __user * current_dir;
47907 struct linux_dirent64 __user * previous;
47908 + struct file *file;
47909 int count;
47910 int error;
47911 };
47912 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
47913 buf->error = -EINVAL; /* only used if we fail.. */
47914 if (reclen > buf->count)
47915 return -EINVAL;
47916 +
47917 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47918 + return 0;
47919 +
47920 dirent = buf->previous;
47921 if (dirent) {
47922 if (__put_user(offset, &dirent->d_off))
47923 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
47924
47925 buf.current_dir = dirent;
47926 buf.previous = NULL;
47927 + buf.file = file;
47928 buf.count = count;
47929 buf.error = 0;
47930
47931 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
47932 error = buf.error;
47933 lastdirent = buf.previous;
47934 if (lastdirent) {
47935 - typeof(lastdirent->d_off) d_off = file->f_pos;
47936 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
47937 if (__put_user(d_off, &lastdirent->d_off))
47938 error = -EFAULT;
47939 else
47940 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
47941 index 60c0804..d814f98 100644
47942 --- a/fs/reiserfs/do_balan.c
47943 +++ b/fs/reiserfs/do_balan.c
47944 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
47945 return;
47946 }
47947
47948 - atomic_inc(&(fs_generation(tb->tb_sb)));
47949 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
47950 do_balance_starts(tb);
47951
47952 /* balance leaf returns 0 except if combining L R and S into
47953 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
47954 index 7a99811..a7c96c4 100644
47955 --- a/fs/reiserfs/procfs.c
47956 +++ b/fs/reiserfs/procfs.c
47957 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
47958 "SMALL_TAILS " : "NO_TAILS ",
47959 replay_only(sb) ? "REPLAY_ONLY " : "",
47960 convert_reiserfs(sb) ? "CONV " : "",
47961 - atomic_read(&r->s_generation_counter),
47962 + atomic_read_unchecked(&r->s_generation_counter),
47963 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
47964 SF(s_do_balance), SF(s_unneeded_left_neighbor),
47965 SF(s_good_search_by_key_reada), SF(s_bmaps),
47966 diff --git a/fs/select.c b/fs/select.c
47967 index d33418f..2a5345e 100644
47968 --- a/fs/select.c
47969 +++ b/fs/select.c
47970 @@ -20,6 +20,7 @@
47971 #include <linux/module.h>
47972 #include <linux/slab.h>
47973 #include <linux/poll.h>
47974 +#include <linux/security.h>
47975 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
47976 #include <linux/file.h>
47977 #include <linux/fdtable.h>
47978 @@ -837,6 +838,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
47979 struct poll_list *walk = head;
47980 unsigned long todo = nfds;
47981
47982 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
47983 if (nfds > rlimit(RLIMIT_NOFILE))
47984 return -EINVAL;
47985
47986 diff --git a/fs/seq_file.c b/fs/seq_file.c
47987 index dba43c3..9fb8511 100644
47988 --- a/fs/seq_file.c
47989 +++ b/fs/seq_file.c
47990 @@ -9,6 +9,7 @@
47991 #include <linux/module.h>
47992 #include <linux/seq_file.h>
47993 #include <linux/slab.h>
47994 +#include <linux/sched.h>
47995
47996 #include <asm/uaccess.h>
47997 #include <asm/page.h>
47998 @@ -40,6 +41,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
47999 memset(p, 0, sizeof(*p));
48000 mutex_init(&p->lock);
48001 p->op = op;
48002 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48003 + p->exec_id = current->exec_id;
48004 +#endif
48005
48006 /*
48007 * Wrappers around seq_open(e.g. swaps_open) need to be
48008 @@ -76,7 +80,8 @@ static int traverse(struct seq_file *m, loff_t offset)
48009 return 0;
48010 }
48011 if (!m->buf) {
48012 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
48013 + m->size = PAGE_SIZE;
48014 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
48015 if (!m->buf)
48016 return -ENOMEM;
48017 }
48018 @@ -116,7 +121,8 @@ static int traverse(struct seq_file *m, loff_t offset)
48019 Eoverflow:
48020 m->op->stop(m, p);
48021 kfree(m->buf);
48022 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
48023 + m->size <<= 1;
48024 + m->buf = kmalloc(m->size, GFP_KERNEL);
48025 return !m->buf ? -ENOMEM : -EAGAIN;
48026 }
48027
48028 @@ -169,7 +175,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
48029 m->version = file->f_version;
48030 /* grab buffer if we didn't have one */
48031 if (!m->buf) {
48032 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
48033 + m->size = PAGE_SIZE;
48034 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
48035 if (!m->buf)
48036 goto Enomem;
48037 }
48038 @@ -210,7 +217,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
48039 goto Fill;
48040 m->op->stop(m, p);
48041 kfree(m->buf);
48042 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
48043 + m->size <<= 1;
48044 + m->buf = kmalloc(m->size, GFP_KERNEL);
48045 if (!m->buf)
48046 goto Enomem;
48047 m->count = 0;
48048 @@ -549,7 +557,7 @@ static void single_stop(struct seq_file *p, void *v)
48049 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
48050 void *data)
48051 {
48052 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
48053 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
48054 int res = -ENOMEM;
48055
48056 if (op) {
48057 diff --git a/fs/splice.c b/fs/splice.c
48058 index fa2defa..8601650 100644
48059 --- a/fs/splice.c
48060 +++ b/fs/splice.c
48061 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
48062 pipe_lock(pipe);
48063
48064 for (;;) {
48065 - if (!pipe->readers) {
48066 + if (!atomic_read(&pipe->readers)) {
48067 send_sig(SIGPIPE, current, 0);
48068 if (!ret)
48069 ret = -EPIPE;
48070 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
48071 do_wakeup = 0;
48072 }
48073
48074 - pipe->waiting_writers++;
48075 + atomic_inc(&pipe->waiting_writers);
48076 pipe_wait(pipe);
48077 - pipe->waiting_writers--;
48078 + atomic_dec(&pipe->waiting_writers);
48079 }
48080
48081 pipe_unlock(pipe);
48082 @@ -560,7 +560,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
48083 old_fs = get_fs();
48084 set_fs(get_ds());
48085 /* The cast to a user pointer is valid due to the set_fs() */
48086 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
48087 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
48088 set_fs(old_fs);
48089
48090 return res;
48091 @@ -575,7 +575,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
48092 old_fs = get_fs();
48093 set_fs(get_ds());
48094 /* The cast to a user pointer is valid due to the set_fs() */
48095 - res = vfs_write(file, (const char __user *)buf, count, &pos);
48096 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
48097 set_fs(old_fs);
48098
48099 return res;
48100 @@ -626,7 +626,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
48101 goto err;
48102
48103 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
48104 - vec[i].iov_base = (void __user *) page_address(page);
48105 + vec[i].iov_base = (void __force_user *) page_address(page);
48106 vec[i].iov_len = this_len;
48107 spd.pages[i] = page;
48108 spd.nr_pages++;
48109 @@ -846,10 +846,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
48110 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
48111 {
48112 while (!pipe->nrbufs) {
48113 - if (!pipe->writers)
48114 + if (!atomic_read(&pipe->writers))
48115 return 0;
48116
48117 - if (!pipe->waiting_writers && sd->num_spliced)
48118 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
48119 return 0;
48120
48121 if (sd->flags & SPLICE_F_NONBLOCK)
48122 @@ -1182,7 +1182,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
48123 * out of the pipe right after the splice_to_pipe(). So set
48124 * PIPE_READERS appropriately.
48125 */
48126 - pipe->readers = 1;
48127 + atomic_set(&pipe->readers, 1);
48128
48129 current->splice_pipe = pipe;
48130 }
48131 @@ -1734,9 +1734,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48132 ret = -ERESTARTSYS;
48133 break;
48134 }
48135 - if (!pipe->writers)
48136 + if (!atomic_read(&pipe->writers))
48137 break;
48138 - if (!pipe->waiting_writers) {
48139 + if (!atomic_read(&pipe->waiting_writers)) {
48140 if (flags & SPLICE_F_NONBLOCK) {
48141 ret = -EAGAIN;
48142 break;
48143 @@ -1768,7 +1768,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48144 pipe_lock(pipe);
48145
48146 while (pipe->nrbufs >= pipe->buffers) {
48147 - if (!pipe->readers) {
48148 + if (!atomic_read(&pipe->readers)) {
48149 send_sig(SIGPIPE, current, 0);
48150 ret = -EPIPE;
48151 break;
48152 @@ -1781,9 +1781,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48153 ret = -ERESTARTSYS;
48154 break;
48155 }
48156 - pipe->waiting_writers++;
48157 + atomic_inc(&pipe->waiting_writers);
48158 pipe_wait(pipe);
48159 - pipe->waiting_writers--;
48160 + atomic_dec(&pipe->waiting_writers);
48161 }
48162
48163 pipe_unlock(pipe);
48164 @@ -1819,14 +1819,14 @@ retry:
48165 pipe_double_lock(ipipe, opipe);
48166
48167 do {
48168 - if (!opipe->readers) {
48169 + if (!atomic_read(&opipe->readers)) {
48170 send_sig(SIGPIPE, current, 0);
48171 if (!ret)
48172 ret = -EPIPE;
48173 break;
48174 }
48175
48176 - if (!ipipe->nrbufs && !ipipe->writers)
48177 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
48178 break;
48179
48180 /*
48181 @@ -1923,7 +1923,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
48182 pipe_double_lock(ipipe, opipe);
48183
48184 do {
48185 - if (!opipe->readers) {
48186 + if (!atomic_read(&opipe->readers)) {
48187 send_sig(SIGPIPE, current, 0);
48188 if (!ret)
48189 ret = -EPIPE;
48190 @@ -1968,7 +1968,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
48191 * return EAGAIN if we have the potential of some data in the
48192 * future, otherwise just return 0
48193 */
48194 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
48195 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
48196 ret = -EAGAIN;
48197
48198 pipe_unlock(ipipe);
48199 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
48200 index 7fdf6a7..e6cd8ad 100644
48201 --- a/fs/sysfs/dir.c
48202 +++ b/fs/sysfs/dir.c
48203 @@ -642,6 +642,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
48204 struct sysfs_dirent *sd;
48205 int rc;
48206
48207 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
48208 + const char *parent_name = parent_sd->s_name;
48209 +
48210 + mode = S_IFDIR | S_IRWXU;
48211 +
48212 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
48213 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
48214 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
48215 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
48216 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
48217 +#endif
48218 +
48219 /* allocate */
48220 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
48221 if (!sd)
48222 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
48223 index 779789a..f58193c 100644
48224 --- a/fs/sysfs/file.c
48225 +++ b/fs/sysfs/file.c
48226 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
48227
48228 struct sysfs_open_dirent {
48229 atomic_t refcnt;
48230 - atomic_t event;
48231 + atomic_unchecked_t event;
48232 wait_queue_head_t poll;
48233 struct list_head buffers; /* goes through sysfs_buffer.list */
48234 };
48235 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
48236 if (!sysfs_get_active(attr_sd))
48237 return -ENODEV;
48238
48239 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
48240 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
48241 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
48242
48243 sysfs_put_active(attr_sd);
48244 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
48245 return -ENOMEM;
48246
48247 atomic_set(&new_od->refcnt, 0);
48248 - atomic_set(&new_od->event, 1);
48249 + atomic_set_unchecked(&new_od->event, 1);
48250 init_waitqueue_head(&new_od->poll);
48251 INIT_LIST_HEAD(&new_od->buffers);
48252 goto retry;
48253 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
48254
48255 sysfs_put_active(attr_sd);
48256
48257 - if (buffer->event != atomic_read(&od->event))
48258 + if (buffer->event != atomic_read_unchecked(&od->event))
48259 goto trigger;
48260
48261 return DEFAULT_POLLMASK;
48262 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
48263
48264 od = sd->s_attr.open;
48265 if (od) {
48266 - atomic_inc(&od->event);
48267 + atomic_inc_unchecked(&od->event);
48268 wake_up_interruptible(&od->poll);
48269 }
48270
48271 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
48272 index a7ac78f..02158e1 100644
48273 --- a/fs/sysfs/symlink.c
48274 +++ b/fs/sysfs/symlink.c
48275 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48276
48277 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
48278 {
48279 - char *page = nd_get_link(nd);
48280 + const char *page = nd_get_link(nd);
48281 if (!IS_ERR(page))
48282 free_page((unsigned long)page);
48283 }
48284 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
48285 index c175b4d..8f36a16 100644
48286 --- a/fs/udf/misc.c
48287 +++ b/fs/udf/misc.c
48288 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
48289
48290 u8 udf_tag_checksum(const struct tag *t)
48291 {
48292 - u8 *data = (u8 *)t;
48293 + const u8 *data = (const u8 *)t;
48294 u8 checksum = 0;
48295 int i;
48296 for (i = 0; i < sizeof(struct tag); ++i)
48297 diff --git a/fs/utimes.c b/fs/utimes.c
48298 index ba653f3..06ea4b1 100644
48299 --- a/fs/utimes.c
48300 +++ b/fs/utimes.c
48301 @@ -1,6 +1,7 @@
48302 #include <linux/compiler.h>
48303 #include <linux/file.h>
48304 #include <linux/fs.h>
48305 +#include <linux/security.h>
48306 #include <linux/linkage.h>
48307 #include <linux/mount.h>
48308 #include <linux/namei.h>
48309 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
48310 goto mnt_drop_write_and_out;
48311 }
48312 }
48313 +
48314 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
48315 + error = -EACCES;
48316 + goto mnt_drop_write_and_out;
48317 + }
48318 +
48319 mutex_lock(&inode->i_mutex);
48320 error = notify_change(path->dentry, &newattrs);
48321 mutex_unlock(&inode->i_mutex);
48322 diff --git a/fs/xattr.c b/fs/xattr.c
48323 index 67583de..c5aad14 100644
48324 --- a/fs/xattr.c
48325 +++ b/fs/xattr.c
48326 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
48327 * Extended attribute SET operations
48328 */
48329 static long
48330 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
48331 +setxattr(struct path *path, const char __user *name, const void __user *value,
48332 size_t size, int flags)
48333 {
48334 int error;
48335 @@ -339,7 +339,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
48336 return PTR_ERR(kvalue);
48337 }
48338
48339 - error = vfs_setxattr(d, kname, kvalue, size, flags);
48340 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
48341 + error = -EACCES;
48342 + goto out;
48343 + }
48344 +
48345 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
48346 +out:
48347 kfree(kvalue);
48348 return error;
48349 }
48350 @@ -356,7 +362,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
48351 return error;
48352 error = mnt_want_write(path.mnt);
48353 if (!error) {
48354 - error = setxattr(path.dentry, name, value, size, flags);
48355 + error = setxattr(&path, name, value, size, flags);
48356 mnt_drop_write(path.mnt);
48357 }
48358 path_put(&path);
48359 @@ -375,7 +381,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
48360 return error;
48361 error = mnt_want_write(path.mnt);
48362 if (!error) {
48363 - error = setxattr(path.dentry, name, value, size, flags);
48364 + error = setxattr(&path, name, value, size, flags);
48365 mnt_drop_write(path.mnt);
48366 }
48367 path_put(&path);
48368 @@ -386,17 +392,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
48369 const void __user *,value, size_t, size, int, flags)
48370 {
48371 struct file *f;
48372 - struct dentry *dentry;
48373 int error = -EBADF;
48374
48375 f = fget(fd);
48376 if (!f)
48377 return error;
48378 - dentry = f->f_path.dentry;
48379 - audit_inode(NULL, dentry);
48380 + audit_inode(NULL, f->f_path.dentry);
48381 error = mnt_want_write_file(f);
48382 if (!error) {
48383 - error = setxattr(dentry, name, value, size, flags);
48384 + error = setxattr(&f->f_path, name, value, size, flags);
48385 mnt_drop_write(f->f_path.mnt);
48386 }
48387 fput(f);
48388 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
48389 index 8d5a506..7f62712 100644
48390 --- a/fs/xattr_acl.c
48391 +++ b/fs/xattr_acl.c
48392 @@ -17,8 +17,8 @@
48393 struct posix_acl *
48394 posix_acl_from_xattr(const void *value, size_t size)
48395 {
48396 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
48397 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
48398 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
48399 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
48400 int count;
48401 struct posix_acl *acl;
48402 struct posix_acl_entry *acl_e;
48403 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
48404 index d0ab788..827999b 100644
48405 --- a/fs/xfs/xfs_bmap.c
48406 +++ b/fs/xfs/xfs_bmap.c
48407 @@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
48408 int nmap,
48409 int ret_nmap);
48410 #else
48411 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
48412 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
48413 #endif /* DEBUG */
48414
48415 STATIC int
48416 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
48417 index 79d05e8..e3e5861 100644
48418 --- a/fs/xfs/xfs_dir2_sf.c
48419 +++ b/fs/xfs/xfs_dir2_sf.c
48420 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
48421 }
48422
48423 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
48424 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
48425 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
48426 + char name[sfep->namelen];
48427 + memcpy(name, sfep->name, sfep->namelen);
48428 + if (filldir(dirent, name, sfep->namelen,
48429 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
48430 + *offset = off & 0x7fffffff;
48431 + return 0;
48432 + }
48433 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
48434 off & 0x7fffffff, ino, DT_UNKNOWN)) {
48435 *offset = off & 0x7fffffff;
48436 return 0;
48437 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
48438 index d99a905..9f88202 100644
48439 --- a/fs/xfs/xfs_ioctl.c
48440 +++ b/fs/xfs/xfs_ioctl.c
48441 @@ -128,7 +128,7 @@ xfs_find_handle(
48442 }
48443
48444 error = -EFAULT;
48445 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
48446 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
48447 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
48448 goto out_put;
48449
48450 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
48451 index 23ce927..e274cc1 100644
48452 --- a/fs/xfs/xfs_iops.c
48453 +++ b/fs/xfs/xfs_iops.c
48454 @@ -447,7 +447,7 @@ xfs_vn_put_link(
48455 struct nameidata *nd,
48456 void *p)
48457 {
48458 - char *s = nd_get_link(nd);
48459 + const char *s = nd_get_link(nd);
48460
48461 if (!IS_ERR(s))
48462 kfree(s);
48463 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
48464 new file mode 100644
48465 index 0000000..4089e05
48466 --- /dev/null
48467 +++ b/grsecurity/Kconfig
48468 @@ -0,0 +1,1078 @@
48469 +#
48470 +# grecurity configuration
48471 +#
48472 +
48473 +menu "Grsecurity"
48474 +
48475 +config GRKERNSEC
48476 + bool "Grsecurity"
48477 + select CRYPTO
48478 + select CRYPTO_SHA256
48479 + help
48480 + If you say Y here, you will be able to configure many features
48481 + that will enhance the security of your system. It is highly
48482 + recommended that you say Y here and read through the help
48483 + for each option so that you fully understand the features and
48484 + can evaluate their usefulness for your machine.
48485 +
48486 +choice
48487 + prompt "Security Level"
48488 + depends on GRKERNSEC
48489 + default GRKERNSEC_CUSTOM
48490 +
48491 +config GRKERNSEC_LOW
48492 + bool "Low"
48493 + select GRKERNSEC_LINK
48494 + select GRKERNSEC_FIFO
48495 + select GRKERNSEC_RANDNET
48496 + select GRKERNSEC_DMESG
48497 + select GRKERNSEC_CHROOT
48498 + select GRKERNSEC_CHROOT_CHDIR
48499 +
48500 + help
48501 + If you choose this option, several of the grsecurity options will
48502 + be enabled that will give you greater protection against a number
48503 + of attacks, while assuring that none of your software will have any
48504 + conflicts with the additional security measures. If you run a lot
48505 + of unusual software, or you are having problems with the higher
48506 + security levels, you should say Y here. With this option, the
48507 + following features are enabled:
48508 +
48509 + - Linking restrictions
48510 + - FIFO restrictions
48511 + - Restricted dmesg
48512 + - Enforced chdir("/") on chroot
48513 + - Runtime module disabling
48514 +
48515 +config GRKERNSEC_MEDIUM
48516 + bool "Medium"
48517 + select PAX
48518 + select PAX_EI_PAX
48519 + select PAX_PT_PAX_FLAGS
48520 + select PAX_HAVE_ACL_FLAGS
48521 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
48522 + select GRKERNSEC_CHROOT
48523 + select GRKERNSEC_CHROOT_SYSCTL
48524 + select GRKERNSEC_LINK
48525 + select GRKERNSEC_FIFO
48526 + select GRKERNSEC_DMESG
48527 + select GRKERNSEC_RANDNET
48528 + select GRKERNSEC_FORKFAIL
48529 + select GRKERNSEC_TIME
48530 + select GRKERNSEC_SIGNAL
48531 + select GRKERNSEC_CHROOT
48532 + select GRKERNSEC_CHROOT_UNIX
48533 + select GRKERNSEC_CHROOT_MOUNT
48534 + select GRKERNSEC_CHROOT_PIVOT
48535 + select GRKERNSEC_CHROOT_DOUBLE
48536 + select GRKERNSEC_CHROOT_CHDIR
48537 + select GRKERNSEC_CHROOT_MKNOD
48538 + select GRKERNSEC_PROC
48539 + select GRKERNSEC_PROC_USERGROUP
48540 + select PAX_RANDUSTACK
48541 + select PAX_ASLR
48542 + select PAX_RANDMMAP
48543 + select PAX_REFCOUNT if (X86 || SPARC64)
48544 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
48545 +
48546 + help
48547 + If you say Y here, several features in addition to those included
48548 + in the low additional security level will be enabled. These
48549 + features provide even more security to your system, though in rare
48550 + cases they may be incompatible with very old or poorly written
48551 + software. If you enable this option, make sure that your auth
48552 + service (identd) is running as gid 1001. With this option,
48553 + the following features (in addition to those provided in the
48554 + low additional security level) will be enabled:
48555 +
48556 + - Failed fork logging
48557 + - Time change logging
48558 + - Signal logging
48559 + - Deny mounts in chroot
48560 + - Deny double chrooting
48561 + - Deny sysctl writes in chroot
48562 + - Deny mknod in chroot
48563 + - Deny access to abstract AF_UNIX sockets out of chroot
48564 + - Deny pivot_root in chroot
48565 + - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
48566 + - /proc restrictions with special GID set to 10 (usually wheel)
48567 + - Address Space Layout Randomization (ASLR)
48568 + - Prevent exploitation of most refcount overflows
48569 + - Bounds checking of copying between the kernel and userland
48570 +
48571 +config GRKERNSEC_HIGH
48572 + bool "High"
48573 + select GRKERNSEC_LINK
48574 + select GRKERNSEC_FIFO
48575 + select GRKERNSEC_DMESG
48576 + select GRKERNSEC_FORKFAIL
48577 + select GRKERNSEC_TIME
48578 + select GRKERNSEC_SIGNAL
48579 + select GRKERNSEC_CHROOT
48580 + select GRKERNSEC_CHROOT_SHMAT
48581 + select GRKERNSEC_CHROOT_UNIX
48582 + select GRKERNSEC_CHROOT_MOUNT
48583 + select GRKERNSEC_CHROOT_FCHDIR
48584 + select GRKERNSEC_CHROOT_PIVOT
48585 + select GRKERNSEC_CHROOT_DOUBLE
48586 + select GRKERNSEC_CHROOT_CHDIR
48587 + select GRKERNSEC_CHROOT_MKNOD
48588 + select GRKERNSEC_CHROOT_CAPS
48589 + select GRKERNSEC_CHROOT_SYSCTL
48590 + select GRKERNSEC_CHROOT_FINDTASK
48591 + select GRKERNSEC_SYSFS_RESTRICT
48592 + select GRKERNSEC_PROC
48593 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
48594 + select GRKERNSEC_HIDESYM
48595 + select GRKERNSEC_BRUTE
48596 + select GRKERNSEC_PROC_USERGROUP
48597 + select GRKERNSEC_KMEM
48598 + select GRKERNSEC_RESLOG
48599 + select GRKERNSEC_RANDNET
48600 + select GRKERNSEC_PROC_ADD
48601 + select GRKERNSEC_CHROOT_CHMOD
48602 + select GRKERNSEC_CHROOT_NICE
48603 + select GRKERNSEC_SETXID
48604 + select GRKERNSEC_AUDIT_MOUNT
48605 + select GRKERNSEC_MODHARDEN if (MODULES)
48606 + select GRKERNSEC_HARDEN_PTRACE
48607 + select GRKERNSEC_PTRACE_READEXEC
48608 + select GRKERNSEC_VM86 if (X86_32)
48609 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
48610 + select PAX
48611 + select PAX_RANDUSTACK
48612 + select PAX_ASLR
48613 + select PAX_RANDMMAP
48614 + select PAX_NOEXEC
48615 + select PAX_MPROTECT
48616 + select PAX_EI_PAX
48617 + select PAX_PT_PAX_FLAGS
48618 + select PAX_HAVE_ACL_FLAGS
48619 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
48620 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
48621 + select PAX_RANDKSTACK if (X86_TSC && X86)
48622 + select PAX_SEGMEXEC if (X86_32)
48623 + select PAX_PAGEEXEC
48624 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
48625 + select PAX_EMUTRAMP if (PARISC)
48626 + select PAX_EMUSIGRT if (PARISC)
48627 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
48628 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
48629 + select PAX_REFCOUNT if (X86 || SPARC64)
48630 + select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
48631 + help
48632 + If you say Y here, many of the features of grsecurity will be
48633 + enabled, which will protect you against many kinds of attacks
48634 + against your system. The heightened security comes at a cost
48635 + of an increased chance of incompatibilities with rare software
48636 + on your machine. Since this security level enables PaX, you should
48637 + view <http://pax.grsecurity.net> and read about the PaX
48638 + project. While you are there, download chpax and run it on
48639 + binaries that cause problems with PaX. Also remember that
48640 + since the /proc restrictions are enabled, you must run your
48641 + identd as gid 1001. This security level enables the following
48642 + features in addition to those listed in the low and medium
48643 + security levels:
48644 +
48645 + - Additional /proc restrictions
48646 + - Chmod restrictions in chroot
48647 + - No signals, ptrace, or viewing of processes outside of chroot
48648 + - Capability restrictions in chroot
48649 + - Deny fchdir out of chroot
48650 + - Priority restrictions in chroot
48651 + - Segmentation-based implementation of PaX
48652 + - Mprotect restrictions
48653 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
48654 + - Kernel stack randomization
48655 + - Mount/unmount/remount logging
48656 + - Kernel symbol hiding
48657 + - Hardening of module auto-loading
48658 + - Ptrace restrictions
48659 + - Restricted vm86 mode
48660 + - Restricted sysfs/debugfs
48661 + - Active kernel exploit response
48662 +
48663 +config GRKERNSEC_CUSTOM
48664 + bool "Custom"
48665 + help
48666 + If you say Y here, you will be able to configure every grsecurity
48667 + option, which allows you to enable many more features that aren't
48668 + covered in the basic security levels. These additional features
48669 + include TPE, socket restrictions, and the sysctl system for
48670 + grsecurity. It is advised that you read through the help for
48671 + each option to determine its usefulness in your situation.
48672 +
48673 +endchoice
48674 +
48675 +menu "Memory Protections"
48676 +depends on GRKERNSEC
48677 +
48678 +config GRKERNSEC_KMEM
48679 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
48680 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
48681 + help
48682 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
48683 + be written to or read from to modify or leak the contents of the running
48684 + kernel. /dev/port will also not be allowed to be opened. If you have module
48685 + support disabled, enabling this will close up four ways that are
48686 + currently used to insert malicious code into the running kernel.
48687 + Even with all these features enabled, we still highly recommend that
48688 + you use the RBAC system, as it is still possible for an attacker to
48689 + modify the running kernel through privileged I/O granted by ioperm/iopl.
48690 + If you are not using XFree86, you may be able to stop this additional
48691 + case by enabling the 'Disable privileged I/O' option. Though nothing
48692 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
48693 + but only to video memory, which is the only writing we allow in this
48694 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
48695 + not be allowed to mprotect it with PROT_WRITE later.
48696 + It is highly recommended that you say Y here if you meet all the
48697 + conditions above.
48698 +
48699 +config GRKERNSEC_VM86
48700 + bool "Restrict VM86 mode"
48701 + depends on X86_32
48702 +
48703 + help
48704 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
48705 + make use of a special execution mode on 32bit x86 processors called
48706 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
48707 + video cards and will still work with this option enabled. The purpose
48708 + of the option is to prevent exploitation of emulation errors in
48709 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
48710 + Nearly all users should be able to enable this option.
48711 +
48712 +config GRKERNSEC_IO
48713 + bool "Disable privileged I/O"
48714 + depends on X86
48715 + select RTC_CLASS
48716 + select RTC_INTF_DEV
48717 + select RTC_DRV_CMOS
48718 +
48719 + help
48720 + If you say Y here, all ioperm and iopl calls will return an error.
48721 + Ioperm and iopl can be used to modify the running kernel.
48722 + Unfortunately, some programs need this access to operate properly,
48723 + the most notable of which are XFree86 and hwclock. hwclock can be
48724 + remedied by having RTC support in the kernel, so real-time
48725 + clock support is enabled if this option is enabled, to ensure
48726 + that hwclock operates correctly. XFree86 still will not
48727 + operate correctly with this option enabled, so DO NOT CHOOSE Y
48728 + IF YOU USE XFree86. If you use XFree86 and you still want to
48729 + protect your kernel against modification, use the RBAC system.
48730 +
48731 +config GRKERNSEC_PROC_MEMMAP
48732 + bool "Harden ASLR against information leaks and entropy reduction"
48733 + default y if (PAX_NOEXEC || PAX_ASLR)
48734 + depends on PAX_NOEXEC || PAX_ASLR
48735 + help
48736 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
48737 + give no information about the addresses of its mappings if
48738 + PaX features that rely on random addresses are enabled on the task.
48739 + In addition to sanitizing this information and disabling other
48740 + dangerous sources of information, this option causes reads of sensitive
48741 + /proc/<pid> entries where the file descriptor was opened in a different
48742 + task than the one performing the read. Such attempts are logged.
48743 + This option also limits argv/env strings for suid/sgid binaries
48744 + to 512KB to prevent a complete exhaustion of the stack entropy provided
48745 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
48746 + binaries to prevent alternative mmap layouts from being abused.
48747 +
48748 + If you use PaX it is essential that you say Y here as it closes up
48749 + several holes that make full ASLR useless locally.
48750 +
48751 +config GRKERNSEC_BRUTE
48752 + bool "Deter exploit bruteforcing"
48753 + help
48754 + If you say Y here, attempts to bruteforce exploits against forking
48755 + daemons such as apache or sshd, as well as against suid/sgid binaries
48756 + will be deterred. When a child of a forking daemon is killed by PaX
48757 + or crashes due to an illegal instruction or other suspicious signal,
48758 + the parent process will be delayed 30 seconds upon every subsequent
48759 + fork until the administrator is able to assess the situation and
48760 + restart the daemon.
48761 + In the suid/sgid case, the attempt is logged, the user has all their
48762 + processes terminated, and they are prevented from executing any further
48763 + processes for 15 minutes.
48764 + It is recommended that you also enable signal logging in the auditing
48765 + section so that logs are generated when a process triggers a suspicious
48766 + signal.
48767 + If the sysctl option is enabled, a sysctl option with name
48768 + "deter_bruteforce" is created.
48769 +
48770 +
48771 +config GRKERNSEC_MODHARDEN
48772 + bool "Harden module auto-loading"
48773 + depends on MODULES
48774 + help
48775 + If you say Y here, module auto-loading in response to use of some
48776 + feature implemented by an unloaded module will be restricted to
48777 + root users. Enabling this option helps defend against attacks
48778 + by unprivileged users who abuse the auto-loading behavior to
48779 + cause a vulnerable module to load that is then exploited.
48780 +
48781 + If this option prevents a legitimate use of auto-loading for a
48782 + non-root user, the administrator can execute modprobe manually
48783 + with the exact name of the module mentioned in the alert log.
48784 + Alternatively, the administrator can add the module to the list
48785 + of modules loaded at boot by modifying init scripts.
48786 +
48787 + Modification of init scripts will most likely be needed on
48788 + Ubuntu servers with encrypted home directory support enabled,
48789 + as the first non-root user logging in will cause the ecb(aes),
48790 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
48791 +
48792 +config GRKERNSEC_HIDESYM
48793 + bool "Hide kernel symbols"
48794 + help
48795 + If you say Y here, getting information on loaded modules, and
48796 + displaying all kernel symbols through a syscall will be restricted
48797 + to users with CAP_SYS_MODULE. For software compatibility reasons,
48798 + /proc/kallsyms will be restricted to the root user. The RBAC
48799 + system can hide that entry even from root.
48800 +
48801 + This option also prevents leaking of kernel addresses through
48802 + several /proc entries.
48803 +
48804 + Note that this option is only effective provided the following
48805 + conditions are met:
48806 + 1) The kernel using grsecurity is not precompiled by some distribution
48807 + 2) You have also enabled GRKERNSEC_DMESG
48808 + 3) You are using the RBAC system and hiding other files such as your
48809 + kernel image and System.map. Alternatively, enabling this option
48810 + causes the permissions on /boot, /lib/modules, and the kernel
48811 + source directory to change at compile time to prevent
48812 + reading by non-root users.
48813 + If the above conditions are met, this option will aid in providing a
48814 + useful protection against local kernel exploitation of overflows
48815 + and arbitrary read/write vulnerabilities.
48816 +
48817 +config GRKERNSEC_KERN_LOCKOUT
48818 + bool "Active kernel exploit response"
48819 + depends on X86 || ARM || PPC || SPARC
48820 + help
48821 + If you say Y here, when a PaX alert is triggered due to suspicious
48822 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
48823 + or an OOPs occurs due to bad memory accesses, instead of just
48824 + terminating the offending process (and potentially allowing
48825 + a subsequent exploit from the same user), we will take one of two
48826 + actions:
48827 + If the user was root, we will panic the system
48828 + If the user was non-root, we will log the attempt, terminate
48829 + all processes owned by the user, then prevent them from creating
48830 + any new processes until the system is restarted
48831 + This deters repeated kernel exploitation/bruteforcing attempts
48832 + and is useful for later forensics.
48833 +
48834 +endmenu
48835 +menu "Role Based Access Control Options"
48836 +depends on GRKERNSEC
48837 +
48838 +config GRKERNSEC_RBAC_DEBUG
48839 + bool
48840 +
48841 +config GRKERNSEC_NO_RBAC
48842 + bool "Disable RBAC system"
48843 + help
48844 + If you say Y here, the /dev/grsec device will be removed from the kernel,
48845 + preventing the RBAC system from being enabled. You should only say Y
48846 + here if you have no intention of using the RBAC system, so as to prevent
48847 + an attacker with root access from misusing the RBAC system to hide files
48848 + and processes when loadable module support and /dev/[k]mem have been
48849 + locked down.
48850 +
48851 +config GRKERNSEC_ACL_HIDEKERN
48852 + bool "Hide kernel processes"
48853 + help
48854 + If you say Y here, all kernel threads will be hidden to all
48855 + processes but those whose subject has the "view hidden processes"
48856 + flag.
48857 +
48858 +config GRKERNSEC_ACL_MAXTRIES
48859 + int "Maximum tries before password lockout"
48860 + default 3
48861 + help
48862 + This option enforces the maximum number of times a user can attempt
48863 + to authorize themselves with the grsecurity RBAC system before being
48864 + denied the ability to attempt authorization again for a specified time.
48865 + The lower the number, the harder it will be to brute-force a password.
48866 +
48867 +config GRKERNSEC_ACL_TIMEOUT
48868 + int "Time to wait after max password tries, in seconds"
48869 + default 30
48870 + help
48871 + This option specifies the time the user must wait after attempting to
48872 + authorize to the RBAC system with the maximum number of invalid
48873 + passwords. The higher the number, the harder it will be to brute-force
48874 + a password.
48875 +
48876 +endmenu
48877 +menu "Filesystem Protections"
48878 +depends on GRKERNSEC
48879 +
48880 +config GRKERNSEC_PROC
48881 + bool "Proc restrictions"
48882 + help
48883 + If you say Y here, the permissions of the /proc filesystem
48884 + will be altered to enhance system security and privacy. You MUST
48885 + choose either a user only restriction or a user and group restriction.
48886 + Depending upon the option you choose, you can either restrict users to
48887 + see only the processes they themselves run, or choose a group that can
48888 + view all processes and files normally restricted to root if you choose
48889 + the "restrict to user only" option. NOTE: If you're running identd or
48890 + ntpd as a non-root user, you will have to run it as the group you
48891 + specify here.
48892 +
48893 +config GRKERNSEC_PROC_USER
48894 + bool "Restrict /proc to user only"
48895 + depends on GRKERNSEC_PROC
48896 + help
48897 + If you say Y here, non-root users will only be able to view their own
48898 + processes, and restricts them from viewing network-related information,
48899 + and viewing kernel symbol and module information.
48900 +
48901 +config GRKERNSEC_PROC_USERGROUP
48902 + bool "Allow special group"
48903 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
48904 + help
48905 + If you say Y here, you will be able to select a group that will be
48906 + able to view all processes and network-related information. If you've
48907 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
48908 + remain hidden. This option is useful if you want to run identd as
48909 + a non-root user.
48910 +
48911 +config GRKERNSEC_PROC_GID
48912 + int "GID for special group"
48913 + depends on GRKERNSEC_PROC_USERGROUP
48914 + default 1001
48915 +
48916 +config GRKERNSEC_PROC_ADD
48917 + bool "Additional restrictions"
48918 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
48919 + help
48920 + If you say Y here, additional restrictions will be placed on
48921 + /proc that keep normal users from viewing device information and
48922 + slabinfo information that could be useful for exploits.
48923 +
48924 +config GRKERNSEC_LINK
48925 + bool "Linking restrictions"
48926 + help
48927 + If you say Y here, /tmp race exploits will be prevented, since users
48928 + will no longer be able to follow symlinks owned by other users in
48929 + world-writable +t directories (e.g. /tmp), unless the owner of the
48930 + symlink is the owner of the directory. users will also not be
48931 + able to hardlink to files they do not own. If the sysctl option is
48932 + enabled, a sysctl option with name "linking_restrictions" is created.
48933 +
48934 +config GRKERNSEC_FIFO
48935 + bool "FIFO restrictions"
48936 + help
48937 + If you say Y here, users will not be able to write to FIFOs they don't
48938 + own in world-writable +t directories (e.g. /tmp), unless the owner of
48939 + the FIFO is the same owner of the directory it's held in. If the sysctl
48940 + option is enabled, a sysctl option with name "fifo_restrictions" is
48941 + created.
48942 +
48943 +config GRKERNSEC_SYSFS_RESTRICT
48944 + bool "Sysfs/debugfs restriction"
48945 + depends on SYSFS
48946 + help
48947 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
48948 + any filesystem normally mounted under it (e.g. debugfs) will be
48949 + mostly accessible only by root. These filesystems generally provide access
48950 + to hardware and debug information that isn't appropriate for unprivileged
48951 + users of the system. Sysfs and debugfs have also become a large source
48952 + of new vulnerabilities, ranging from infoleaks to local compromise.
48953 + There has been very little oversight with an eye toward security involved
48954 + in adding new exporters of information to these filesystems, so their
48955 + use is discouraged.
48956 + For reasons of compatibility, a few directories have been whitelisted
48957 + for access by non-root users:
48958 + /sys/fs/selinux
48959 + /sys/fs/fuse
48960 + /sys/devices/system/cpu
48961 +
48962 +config GRKERNSEC_ROFS
48963 + bool "Runtime read-only mount protection"
48964 + help
48965 + If you say Y here, a sysctl option with name "romount_protect" will
48966 + be created. By setting this option to 1 at runtime, filesystems
48967 + will be protected in the following ways:
48968 + * No new writable mounts will be allowed
48969 + * Existing read-only mounts won't be able to be remounted read/write
48970 + * Write operations will be denied on all block devices
48971 + This option acts independently of grsec_lock: once it is set to 1,
48972 + it cannot be turned off. Therefore, please be mindful of the resulting
48973 + behavior if this option is enabled in an init script on a read-only
48974 + filesystem. This feature is mainly intended for secure embedded systems.
48975 +
48976 +config GRKERNSEC_CHROOT
48977 + bool "Chroot jail restrictions"
48978 + help
48979 + If you say Y here, you will be able to choose several options that will
48980 + make breaking out of a chrooted jail much more difficult. If you
48981 + encounter no software incompatibilities with the following options, it
48982 + is recommended that you enable each one.
48983 +
48984 +config GRKERNSEC_CHROOT_MOUNT
48985 + bool "Deny mounts"
48986 + depends on GRKERNSEC_CHROOT
48987 + help
48988 + If you say Y here, processes inside a chroot will not be able to
48989 + mount or remount filesystems. If the sysctl option is enabled, a
48990 + sysctl option with name "chroot_deny_mount" is created.
48991 +
48992 +config GRKERNSEC_CHROOT_DOUBLE
48993 + bool "Deny double-chroots"
48994 + depends on GRKERNSEC_CHROOT
48995 + help
48996 + If you say Y here, processes inside a chroot will not be able to chroot
48997 + again outside the chroot. This is a widely used method of breaking
48998 + out of a chroot jail and should not be allowed. If the sysctl
48999 + option is enabled, a sysctl option with name
49000 + "chroot_deny_chroot" is created.
49001 +
49002 +config GRKERNSEC_CHROOT_PIVOT
49003 + bool "Deny pivot_root in chroot"
49004 + depends on GRKERNSEC_CHROOT
49005 + help
49006 + If you say Y here, processes inside a chroot will not be able to use
49007 + a function called pivot_root() that was introduced in Linux 2.3.41. It
49008 + works similar to chroot in that it changes the root filesystem. This
49009 + function could be misused in a chrooted process to attempt to break out
49010 + of the chroot, and therefore should not be allowed. If the sysctl
49011 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
49012 + created.
49013 +
49014 +config GRKERNSEC_CHROOT_CHDIR
49015 + bool "Enforce chdir(\"/\") on all chroots"
49016 + depends on GRKERNSEC_CHROOT
49017 + help
49018 + If you say Y here, the current working directory of all newly-chrooted
49019 + applications will be set to the the root directory of the chroot.
49020 + The man page on chroot(2) states:
49021 + Note that this call does not change the current working
49022 + directory, so that `.' can be outside the tree rooted at
49023 + `/'. In particular, the super-user can escape from a
49024 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
49025 +
49026 + It is recommended that you say Y here, since it's not known to break
49027 + any software. If the sysctl option is enabled, a sysctl option with
49028 + name "chroot_enforce_chdir" is created.
49029 +
49030 +config GRKERNSEC_CHROOT_CHMOD
49031 + bool "Deny (f)chmod +s"
49032 + depends on GRKERNSEC_CHROOT
49033 + help
49034 + If you say Y here, processes inside a chroot will not be able to chmod
49035 + or fchmod files to make them have suid or sgid bits. This protects
49036 + against another published method of breaking a chroot. If the sysctl
49037 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
49038 + created.
49039 +
49040 +config GRKERNSEC_CHROOT_FCHDIR
49041 + bool "Deny fchdir out of chroot"
49042 + depends on GRKERNSEC_CHROOT
49043 + help
49044 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
49045 + to a file descriptor of the chrooting process that points to a directory
49046 + outside the filesystem will be stopped. If the sysctl option
49047 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
49048 +
49049 +config GRKERNSEC_CHROOT_MKNOD
49050 + bool "Deny mknod"
49051 + depends on GRKERNSEC_CHROOT
49052 + help
49053 + If you say Y here, processes inside a chroot will not be allowed to
49054 + mknod. The problem with using mknod inside a chroot is that it
49055 + would allow an attacker to create a device entry that is the same
49056 + as one on the physical root of your system, which could range from
49057 + anything from the console device to a device for your harddrive (which
49058 + they could then use to wipe the drive or steal data). It is recommended
49059 + that you say Y here, unless you run into software incompatibilities.
49060 + If the sysctl option is enabled, a sysctl option with name
49061 + "chroot_deny_mknod" is created.
49062 +
49063 +config GRKERNSEC_CHROOT_SHMAT
49064 + bool "Deny shmat() out of chroot"
49065 + depends on GRKERNSEC_CHROOT
49066 + help
49067 + If you say Y here, processes inside a chroot will not be able to attach
49068 + to shared memory segments that were created outside of the chroot jail.
49069 + It is recommended that you say Y here. If the sysctl option is enabled,
49070 + a sysctl option with name "chroot_deny_shmat" is created.
49071 +
49072 +config GRKERNSEC_CHROOT_UNIX
49073 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
49074 + depends on GRKERNSEC_CHROOT
49075 + help
49076 + If you say Y here, processes inside a chroot will not be able to
49077 + connect to abstract (meaning not belonging to a filesystem) Unix
49078 + domain sockets that were bound outside of a chroot. It is recommended
49079 + that you say Y here. If the sysctl option is enabled, a sysctl option
49080 + with name "chroot_deny_unix" is created.
49081 +
49082 +config GRKERNSEC_CHROOT_FINDTASK
49083 + bool "Protect outside processes"
49084 + depends on GRKERNSEC_CHROOT
49085 + help
49086 + If you say Y here, processes inside a chroot will not be able to
49087 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
49088 + getsid, or view any process outside of the chroot. If the sysctl
49089 + option is enabled, a sysctl option with name "chroot_findtask" is
49090 + created.
49091 +
49092 +config GRKERNSEC_CHROOT_NICE
49093 + bool "Restrict priority changes"
49094 + depends on GRKERNSEC_CHROOT
49095 + help
49096 + If you say Y here, processes inside a chroot will not be able to raise
49097 + the priority of processes in the chroot, or alter the priority of
49098 + processes outside the chroot. This provides more security than simply
49099 + removing CAP_SYS_NICE from the process' capability set. If the
49100 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
49101 + is created.
49102 +
49103 +config GRKERNSEC_CHROOT_SYSCTL
49104 + bool "Deny sysctl writes"
49105 + depends on GRKERNSEC_CHROOT
49106 + help
49107 + If you say Y here, an attacker in a chroot will not be able to
49108 + write to sysctl entries, either by sysctl(2) or through a /proc
49109 + interface. It is strongly recommended that you say Y here. If the
49110 + sysctl option is enabled, a sysctl option with name
49111 + "chroot_deny_sysctl" is created.
49112 +
49113 +config GRKERNSEC_CHROOT_CAPS
49114 + bool "Capability restrictions"
49115 + depends on GRKERNSEC_CHROOT
49116 + help
49117 + If you say Y here, the capabilities on all processes within a
49118 + chroot jail will be lowered to stop module insertion, raw i/o,
49119 + system and net admin tasks, rebooting the system, modifying immutable
49120 + files, modifying IPC owned by another, and changing the system time.
49121 + This is left an option because it can break some apps. Disable this
49122 + if your chrooted apps are having problems performing those kinds of
49123 + tasks. If the sysctl option is enabled, a sysctl option with
49124 + name "chroot_caps" is created.
49125 +
49126 +endmenu
49127 +menu "Kernel Auditing"
49128 +depends on GRKERNSEC
49129 +
49130 +config GRKERNSEC_AUDIT_GROUP
49131 + bool "Single group for auditing"
49132 + help
49133 + If you say Y here, the exec, chdir, and (un)mount logging features
49134 + will only operate on a group you specify. This option is recommended
49135 + if you only want to watch certain users instead of having a large
49136 + amount of logs from the entire system. If the sysctl option is enabled,
49137 + a sysctl option with name "audit_group" is created.
49138 +
49139 +config GRKERNSEC_AUDIT_GID
49140 + int "GID for auditing"
49141 + depends on GRKERNSEC_AUDIT_GROUP
49142 + default 1007
49143 +
49144 +config GRKERNSEC_EXECLOG
49145 + bool "Exec logging"
49146 + help
49147 + If you say Y here, all execve() calls will be logged (since the
49148 + other exec*() calls are frontends to execve(), all execution
49149 + will be logged). Useful for shell-servers that like to keep track
49150 + of their users. If the sysctl option is enabled, a sysctl option with
49151 + name "exec_logging" is created.
49152 + WARNING: This option when enabled will produce a LOT of logs, especially
49153 + on an active system.
49154 +
49155 +config GRKERNSEC_RESLOG
49156 + bool "Resource logging"
49157 + help
49158 + If you say Y here, all attempts to overstep resource limits will
49159 + be logged with the resource name, the requested size, and the current
49160 + limit. It is highly recommended that you say Y here. If the sysctl
49161 + option is enabled, a sysctl option with name "resource_logging" is
49162 + created. If the RBAC system is enabled, the sysctl value is ignored.
49163 +
49164 +config GRKERNSEC_CHROOT_EXECLOG
49165 + bool "Log execs within chroot"
49166 + help
49167 + If you say Y here, all executions inside a chroot jail will be logged
49168 + to syslog. This can cause a large amount of logs if certain
49169 + applications (eg. djb's daemontools) are installed on the system, and
49170 + is therefore left as an option. If the sysctl option is enabled, a
49171 + sysctl option with name "chroot_execlog" is created.
49172 +
49173 +config GRKERNSEC_AUDIT_PTRACE
49174 + bool "Ptrace logging"
49175 + help
49176 + If you say Y here, all attempts to attach to a process via ptrace
49177 + will be logged. If the sysctl option is enabled, a sysctl option
49178 + with name "audit_ptrace" is created.
49179 +
49180 +config GRKERNSEC_AUDIT_CHDIR
49181 + bool "Chdir logging"
49182 + help
49183 + If you say Y here, all chdir() calls will be logged. If the sysctl
49184 + option is enabled, a sysctl option with name "audit_chdir" is created.
49185 +
49186 +config GRKERNSEC_AUDIT_MOUNT
49187 + bool "(Un)Mount logging"
49188 + help
49189 + If you say Y here, all mounts and unmounts will be logged. If the
49190 + sysctl option is enabled, a sysctl option with name "audit_mount" is
49191 + created.
49192 +
49193 +config GRKERNSEC_SIGNAL
49194 + bool "Signal logging"
49195 + help
49196 + If you say Y here, certain important signals will be logged, such as
49197 + SIGSEGV, which will as a result inform you of when a error in a program
49198 + occurred, which in some cases could mean a possible exploit attempt.
49199 + If the sysctl option is enabled, a sysctl option with name
49200 + "signal_logging" is created.
49201 +
49202 +config GRKERNSEC_FORKFAIL
49203 + bool "Fork failure logging"
49204 + help
49205 + If you say Y here, all failed fork() attempts will be logged.
49206 + This could suggest a fork bomb, or someone attempting to overstep
49207 + their process limit. If the sysctl option is enabled, a sysctl option
49208 + with name "forkfail_logging" is created.
49209 +
49210 +config GRKERNSEC_TIME
49211 + bool "Time change logging"
49212 + help
49213 + If you say Y here, any changes of the system clock will be logged.
49214 + If the sysctl option is enabled, a sysctl option with name
49215 + "timechange_logging" is created.
49216 +
49217 +config GRKERNSEC_PROC_IPADDR
49218 + bool "/proc/<pid>/ipaddr support"
49219 + help
49220 + If you say Y here, a new entry will be added to each /proc/<pid>
49221 + directory that contains the IP address of the person using the task.
49222 + The IP is carried across local TCP and AF_UNIX stream sockets.
49223 + This information can be useful for IDS/IPSes to perform remote response
49224 + to a local attack. The entry is readable by only the owner of the
49225 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
49226 + the RBAC system), and thus does not create privacy concerns.
49227 +
49228 +config GRKERNSEC_RWXMAP_LOG
49229 + bool 'Denied RWX mmap/mprotect logging'
49230 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
49231 + help
49232 + If you say Y here, calls to mmap() and mprotect() with explicit
49233 + usage of PROT_WRITE and PROT_EXEC together will be logged when
49234 + denied by the PAX_MPROTECT feature. If the sysctl option is
49235 + enabled, a sysctl option with name "rwxmap_logging" is created.
49236 +
49237 +config GRKERNSEC_AUDIT_TEXTREL
49238 + bool 'ELF text relocations logging (READ HELP)'
49239 + depends on PAX_MPROTECT
49240 + help
49241 + If you say Y here, text relocations will be logged with the filename
49242 + of the offending library or binary. The purpose of the feature is
49243 + to help Linux distribution developers get rid of libraries and
49244 + binaries that need text relocations which hinder the future progress
49245 + of PaX. Only Linux distribution developers should say Y here, and
49246 + never on a production machine, as this option creates an information
49247 + leak that could aid an attacker in defeating the randomization of
49248 + a single memory region. If the sysctl option is enabled, a sysctl
49249 + option with name "audit_textrel" is created.
49250 +
49251 +endmenu
49252 +
49253 +menu "Executable Protections"
49254 +depends on GRKERNSEC
49255 +
49256 +config GRKERNSEC_DMESG
49257 + bool "Dmesg(8) restriction"
49258 + help
49259 + If you say Y here, non-root users will not be able to use dmesg(8)
49260 + to view up to the last 4kb of messages in the kernel's log buffer.
49261 + The kernel's log buffer often contains kernel addresses and other
49262 + identifying information useful to an attacker in fingerprinting a
49263 + system for a targeted exploit.
49264 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
49265 + created.
49266 +
49267 +config GRKERNSEC_HARDEN_PTRACE
49268 + bool "Deter ptrace-based process snooping"
49269 + help
49270 + If you say Y here, TTY sniffers and other malicious monitoring
49271 + programs implemented through ptrace will be defeated. If you
49272 + have been using the RBAC system, this option has already been
49273 + enabled for several years for all users, with the ability to make
49274 + fine-grained exceptions.
49275 +
49276 + This option only affects the ability of non-root users to ptrace
49277 + processes that are not a descendent of the ptracing process.
49278 + This means that strace ./binary and gdb ./binary will still work,
49279 + but attaching to arbitrary processes will not. If the sysctl
49280 + option is enabled, a sysctl option with name "harden_ptrace" is
49281 + created.
49282 +
49283 +config GRKERNSEC_PTRACE_READEXEC
49284 + bool "Require read access to ptrace sensitive binaries"
49285 + help
49286 + If you say Y here, unprivileged users will not be able to ptrace unreadable
49287 + binaries. This option is useful in environments that
49288 + remove the read bits (e.g. file mode 4711) from suid binaries to
49289 + prevent infoleaking of their contents. This option adds
49290 + consistency to the use of that file mode, as the binary could normally
49291 + be read out when run without privileges while ptracing.
49292 +
49293 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
49294 + is created.
49295 +
49296 +config GRKERNSEC_SETXID
49297 + bool "Enforce consistent multithreaded privileges"
49298 + help
49299 + If you say Y here, a change from a root uid to a non-root uid
49300 + in a multithreaded application will cause the resulting uids,
49301 + gids, supplementary groups, and capabilities in that thread
49302 + to be propagated to the other threads of the process. In most
49303 + cases this is unnecessary, as glibc will emulate this behavior
49304 + on behalf of the application. Other libcs do not act in the
49305 + same way, allowing the other threads of the process to continue
49306 + running with root privileges. If the sysctl option is enabled,
49307 + a sysctl option with name "consistent_setxid" is created.
49308 +
49309 +config GRKERNSEC_TPE
49310 + bool "Trusted Path Execution (TPE)"
49311 + help
49312 + If you say Y here, you will be able to choose a gid to add to the
49313 + supplementary groups of users you want to mark as "untrusted."
49314 + These users will not be able to execute any files that are not in
49315 + root-owned directories writable only by root. If the sysctl option
49316 + is enabled, a sysctl option with name "tpe" is created.
49317 +
49318 +config GRKERNSEC_TPE_ALL
49319 + bool "Partially restrict all non-root users"
49320 + depends on GRKERNSEC_TPE
49321 + help
49322 + If you say Y here, all non-root users will be covered under
49323 + a weaker TPE restriction. This is separate from, and in addition to,
49324 + the main TPE options that you have selected elsewhere. Thus, if a
49325 + "trusted" GID is chosen, this restriction applies to even that GID.
49326 + Under this restriction, all non-root users will only be allowed to
49327 + execute files in directories they own that are not group or
49328 + world-writable, or in directories owned by root and writable only by
49329 + root. If the sysctl option is enabled, a sysctl option with name
49330 + "tpe_restrict_all" is created.
49331 +
49332 +config GRKERNSEC_TPE_INVERT
49333 + bool "Invert GID option"
49334 + depends on GRKERNSEC_TPE
49335 + help
49336 + If you say Y here, the group you specify in the TPE configuration will
49337 + decide what group TPE restrictions will be *disabled* for. This
49338 + option is useful if you want TPE restrictions to be applied to most
49339 + users on the system. If the sysctl option is enabled, a sysctl option
49340 + with name "tpe_invert" is created. Unlike other sysctl options, this
49341 + entry will default to on for backward-compatibility.
49342 +
49343 +config GRKERNSEC_TPE_GID
49344 + int "GID for untrusted users"
49345 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
49346 + default 1005
49347 + help
49348 + Setting this GID determines what group TPE restrictions will be
49349 + *enabled* for. If the sysctl option is enabled, a sysctl option
49350 + with name "tpe_gid" is created.
49351 +
49352 +config GRKERNSEC_TPE_GID
49353 + int "GID for trusted users"
49354 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
49355 + default 1005
49356 + help
49357 + Setting this GID determines what group TPE restrictions will be
49358 + *disabled* for. If the sysctl option is enabled, a sysctl option
49359 + with name "tpe_gid" is created.
49360 +
49361 +endmenu
49362 +menu "Network Protections"
49363 +depends on GRKERNSEC
49364 +
49365 +config GRKERNSEC_RANDNET
49366 + bool "Larger entropy pools"
49367 + help
49368 + If you say Y here, the entropy pools used for many features of Linux
49369 + and grsecurity will be doubled in size. Since several grsecurity
49370 + features use additional randomness, it is recommended that you say Y
49371 + here. Saying Y here has a similar effect as modifying
49372 + /proc/sys/kernel/random/poolsize.
49373 +
49374 +config GRKERNSEC_BLACKHOLE
49375 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
49376 + depends on NET
49377 + help
49378 + If you say Y here, neither TCP resets nor ICMP
49379 + destination-unreachable packets will be sent in response to packets
49380 + sent to ports for which no associated listening process exists.
49381 + This feature supports both IPV4 and IPV6 and exempts the
49382 + loopback interface from blackholing. Enabling this feature
49383 + makes a host more resilient to DoS attacks and reduces network
49384 + visibility against scanners.
49385 +
49386 + The blackhole feature as-implemented is equivalent to the FreeBSD
49387 + blackhole feature, as it prevents RST responses to all packets, not
49388 + just SYNs. Under most application behavior this causes no
49389 + problems, but applications (like haproxy) may not close certain
49390 + connections in a way that cleanly terminates them on the remote
49391 + end, leaving the remote host in LAST_ACK state. Because of this
49392 + side-effect and to prevent intentional LAST_ACK DoSes, this
49393 + feature also adds automatic mitigation against such attacks.
49394 + The mitigation drastically reduces the amount of time a socket
49395 + can spend in LAST_ACK state. If you're using haproxy and not
49396 + all servers it connects to have this option enabled, consider
49397 + disabling this feature on the haproxy host.
49398 +
49399 + If the sysctl option is enabled, two sysctl options with names
49400 + "ip_blackhole" and "lastack_retries" will be created.
49401 + While "ip_blackhole" takes the standard zero/non-zero on/off
49402 + toggle, "lastack_retries" uses the same kinds of values as
49403 + "tcp_retries1" and "tcp_retries2". The default value of 4
49404 + prevents a socket from lasting more than 45 seconds in LAST_ACK
49405 + state.
49406 +
49407 +config GRKERNSEC_SOCKET
49408 + bool "Socket restrictions"
49409 + depends on NET
49410 + help
49411 + If you say Y here, you will be able to choose from several options.
49412 + If you assign a GID on your system and add it to the supplementary
49413 + groups of users you want to restrict socket access to, this patch
49414 + will perform up to three things, based on the option(s) you choose.
49415 +
49416 +config GRKERNSEC_SOCKET_ALL
49417 + bool "Deny any sockets to group"
49418 + depends on GRKERNSEC_SOCKET
49419 + help
49420 + If you say Y here, you will be able to choose a GID of whose users will
49421 + be unable to connect to other hosts from your machine or run server
49422 + applications from your machine. If the sysctl option is enabled, a
49423 + sysctl option with name "socket_all" is created.
49424 +
49425 +config GRKERNSEC_SOCKET_ALL_GID
49426 + int "GID to deny all sockets for"
49427 + depends on GRKERNSEC_SOCKET_ALL
49428 + default 1004
49429 + help
49430 + Here you can choose the GID to disable socket access for. Remember to
49431 + add the users you want socket access disabled for to the GID
49432 + specified here. If the sysctl option is enabled, a sysctl option
49433 + with name "socket_all_gid" is created.
49434 +
49435 +config GRKERNSEC_SOCKET_CLIENT
49436 + bool "Deny client sockets to group"
49437 + depends on GRKERNSEC_SOCKET
49438 + help
49439 + If you say Y here, you will be able to choose a GID of whose users will
49440 + be unable to connect to other hosts from your machine, but will be
49441 + able to run servers. If this option is enabled, all users in the group
49442 + you specify will have to use passive mode when initiating ftp transfers
49443 + from the shell on your machine. If the sysctl option is enabled, a
49444 + sysctl option with name "socket_client" is created.
49445 +
49446 +config GRKERNSEC_SOCKET_CLIENT_GID
49447 + int "GID to deny client sockets for"
49448 + depends on GRKERNSEC_SOCKET_CLIENT
49449 + default 1003
49450 + help
49451 + Here you can choose the GID to disable client socket access for.
49452 + Remember to add the users you want client socket access disabled for to
49453 + the GID specified here. If the sysctl option is enabled, a sysctl
49454 + option with name "socket_client_gid" is created.
49455 +
49456 +config GRKERNSEC_SOCKET_SERVER
49457 + bool "Deny server sockets to group"
49458 + depends on GRKERNSEC_SOCKET
49459 + help
49460 + If you say Y here, you will be able to choose a GID of whose users will
49461 + be unable to run server applications from your machine. If the sysctl
49462 + option is enabled, a sysctl option with name "socket_server" is created.
49463 +
49464 +config GRKERNSEC_SOCKET_SERVER_GID
49465 + int "GID to deny server sockets for"
49466 + depends on GRKERNSEC_SOCKET_SERVER
49467 + default 1002
49468 + help
49469 + Here you can choose the GID to disable server socket access for.
49470 + Remember to add the users you want server socket access disabled for to
49471 + the GID specified here. If the sysctl option is enabled, a sysctl
49472 + option with name "socket_server_gid" is created.
49473 +
49474 +endmenu
49475 +menu "Sysctl support"
49476 +depends on GRKERNSEC && SYSCTL
49477 +
49478 +config GRKERNSEC_SYSCTL
49479 + bool "Sysctl support"
49480 + help
49481 + If you say Y here, you will be able to change the options that
49482 + grsecurity runs with at bootup, without having to recompile your
49483 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
49484 + to enable (1) or disable (0) various features. All the sysctl entries
49485 + are mutable until the "grsec_lock" entry is set to a non-zero value.
49486 + All features enabled in the kernel configuration are disabled at boot
49487 + if you do not say Y to the "Turn on features by default" option.
49488 + All options should be set at startup, and the grsec_lock entry should
49489 + be set to a non-zero value after all the options are set.
49490 + *THIS IS EXTREMELY IMPORTANT*
49491 +
49492 +config GRKERNSEC_SYSCTL_DISTRO
49493 + bool "Extra sysctl support for distro makers (READ HELP)"
49494 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
49495 + help
49496 + If you say Y here, additional sysctl options will be created
49497 + for features that affect processes running as root. Therefore,
49498 + it is critical when using this option that the grsec_lock entry be
49499 + enabled after boot. Only distros with prebuilt kernel packages
49500 + with this option enabled that can ensure grsec_lock is enabled
49501 + after boot should use this option.
49502 + *Failure to set grsec_lock after boot makes all grsec features
49503 + this option covers useless*
49504 +
49505 + Currently this option creates the following sysctl entries:
49506 + "Disable Privileged I/O": "disable_priv_io"
49507 +
49508 +config GRKERNSEC_SYSCTL_ON
49509 + bool "Turn on features by default"
49510 + depends on GRKERNSEC_SYSCTL
49511 + help
49512 + If you say Y here, instead of having all features enabled in the
49513 + kernel configuration disabled at boot time, the features will be
49514 + enabled at boot time. It is recommended you say Y here unless
49515 + there is some reason you would want all sysctl-tunable features to
49516 + be disabled by default. As mentioned elsewhere, it is important
49517 + to enable the grsec_lock entry once you have finished modifying
49518 + the sysctl entries.
49519 +
49520 +endmenu
49521 +menu "Logging Options"
49522 +depends on GRKERNSEC
49523 +
49524 +config GRKERNSEC_FLOODTIME
49525 + int "Seconds in between log messages (minimum)"
49526 + default 10
49527 + help
49528 + This option allows you to enforce the number of seconds between
49529 + grsecurity log messages. The default should be suitable for most
49530 + people, however, if you choose to change it, choose a value small enough
49531 + to allow informative logs to be produced, but large enough to
49532 + prevent flooding.
49533 +
49534 +config GRKERNSEC_FLOODBURST
49535 + int "Number of messages in a burst (maximum)"
49536 + default 6
49537 + help
49538 + This option allows you to choose the maximum number of messages allowed
49539 + within the flood time interval you chose in a separate option. The
49540 + default should be suitable for most people, however if you find that
49541 + many of your logs are being interpreted as flooding, you may want to
49542 + raise this value.
49543 +
49544 +endmenu
49545 +
49546 +endmenu
49547 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
49548 new file mode 100644
49549 index 0000000..1b9afa9
49550 --- /dev/null
49551 +++ b/grsecurity/Makefile
49552 @@ -0,0 +1,38 @@
49553 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
49554 +# during 2001-2009 it has been completely redesigned by Brad Spengler
49555 +# into an RBAC system
49556 +#
49557 +# All code in this directory and various hooks inserted throughout the kernel
49558 +# are copyright Brad Spengler - Open Source Security, Inc., and released
49559 +# under the GPL v2 or higher
49560 +
49561 +KBUILD_CFLAGS += -Werror
49562 +
49563 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
49564 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
49565 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
49566 +
49567 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
49568 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
49569 + gracl_learn.o grsec_log.o
49570 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
49571 +
49572 +ifdef CONFIG_NET
49573 +obj-y += grsec_sock.o
49574 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
49575 +endif
49576 +
49577 +ifndef CONFIG_GRKERNSEC
49578 +obj-y += grsec_disabled.o
49579 +endif
49580 +
49581 +ifdef CONFIG_GRKERNSEC_HIDESYM
49582 +extra-y := grsec_hidesym.o
49583 +$(obj)/grsec_hidesym.o:
49584 + @-chmod -f 500 /boot
49585 + @-chmod -f 500 /lib/modules
49586 + @-chmod -f 500 /lib64/modules
49587 + @-chmod -f 500 /lib32/modules
49588 + @-chmod -f 700 .
49589 + @echo ' grsec: protected kernel image paths'
49590 +endif
49591 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
49592 new file mode 100644
49593 index 0000000..2733872
49594 --- /dev/null
49595 +++ b/grsecurity/gracl.c
49596 @@ -0,0 +1,4163 @@
49597 +#include <linux/kernel.h>
49598 +#include <linux/module.h>
49599 +#include <linux/sched.h>
49600 +#include <linux/mm.h>
49601 +#include <linux/file.h>
49602 +#include <linux/fs.h>
49603 +#include <linux/namei.h>
49604 +#include <linux/mount.h>
49605 +#include <linux/tty.h>
49606 +#include <linux/proc_fs.h>
49607 +#include <linux/lglock.h>
49608 +#include <linux/slab.h>
49609 +#include <linux/vmalloc.h>
49610 +#include <linux/types.h>
49611 +#include <linux/sysctl.h>
49612 +#include <linux/netdevice.h>
49613 +#include <linux/ptrace.h>
49614 +#include <linux/gracl.h>
49615 +#include <linux/gralloc.h>
49616 +#include <linux/security.h>
49617 +#include <linux/grinternal.h>
49618 +#include <linux/pid_namespace.h>
49619 +#include <linux/fdtable.h>
49620 +#include <linux/percpu.h>
49621 +
49622 +#include <asm/uaccess.h>
49623 +#include <asm/errno.h>
49624 +#include <asm/mman.h>
49625 +
49626 +static struct acl_role_db acl_role_set;
49627 +static struct name_db name_set;
49628 +static struct inodev_db inodev_set;
49629 +
49630 +/* for keeping track of userspace pointers used for subjects, so we
49631 + can share references in the kernel as well
49632 +*/
49633 +
49634 +static struct path real_root;
49635 +
49636 +static struct acl_subj_map_db subj_map_set;
49637 +
49638 +static struct acl_role_label *default_role;
49639 +
49640 +static struct acl_role_label *role_list;
49641 +
49642 +static u16 acl_sp_role_value;
49643 +
49644 +extern char *gr_shared_page[4];
49645 +static DEFINE_MUTEX(gr_dev_mutex);
49646 +DEFINE_RWLOCK(gr_inode_lock);
49647 +
49648 +struct gr_arg *gr_usermode;
49649 +
49650 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
49651 +
49652 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
49653 +extern void gr_clear_learn_entries(void);
49654 +
49655 +#ifdef CONFIG_GRKERNSEC_RESLOG
49656 +extern void gr_log_resource(const struct task_struct *task,
49657 + const int res, const unsigned long wanted, const int gt);
49658 +#endif
49659 +
49660 +unsigned char *gr_system_salt;
49661 +unsigned char *gr_system_sum;
49662 +
49663 +static struct sprole_pw **acl_special_roles = NULL;
49664 +static __u16 num_sprole_pws = 0;
49665 +
49666 +static struct acl_role_label *kernel_role = NULL;
49667 +
49668 +static unsigned int gr_auth_attempts = 0;
49669 +static unsigned long gr_auth_expires = 0UL;
49670 +
49671 +#ifdef CONFIG_NET
49672 +extern struct vfsmount *sock_mnt;
49673 +#endif
49674 +
49675 +extern struct vfsmount *pipe_mnt;
49676 +extern struct vfsmount *shm_mnt;
49677 +#ifdef CONFIG_HUGETLBFS
49678 +extern struct vfsmount *hugetlbfs_vfsmount;
49679 +#endif
49680 +
49681 +static struct acl_object_label *fakefs_obj_rw;
49682 +static struct acl_object_label *fakefs_obj_rwx;
49683 +
49684 +extern int gr_init_uidset(void);
49685 +extern void gr_free_uidset(void);
49686 +extern void gr_remove_uid(uid_t uid);
49687 +extern int gr_find_uid(uid_t uid);
49688 +
49689 +DECLARE_BRLOCK(vfsmount_lock);
49690 +
49691 +__inline__ int
49692 +gr_acl_is_enabled(void)
49693 +{
49694 + return (gr_status & GR_READY);
49695 +}
49696 +
49697 +#ifdef CONFIG_BTRFS_FS
49698 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
49699 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
49700 +#endif
49701 +
49702 +static inline dev_t __get_dev(const struct dentry *dentry)
49703 +{
49704 +#ifdef CONFIG_BTRFS_FS
49705 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
49706 + return get_btrfs_dev_from_inode(dentry->d_inode);
49707 + else
49708 +#endif
49709 + return dentry->d_inode->i_sb->s_dev;
49710 +}
49711 +
49712 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
49713 +{
49714 + return __get_dev(dentry);
49715 +}
49716 +
49717 +static char gr_task_roletype_to_char(struct task_struct *task)
49718 +{
49719 + switch (task->role->roletype &
49720 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
49721 + GR_ROLE_SPECIAL)) {
49722 + case GR_ROLE_DEFAULT:
49723 + return 'D';
49724 + case GR_ROLE_USER:
49725 + return 'U';
49726 + case GR_ROLE_GROUP:
49727 + return 'G';
49728 + case GR_ROLE_SPECIAL:
49729 + return 'S';
49730 + }
49731 +
49732 + return 'X';
49733 +}
49734 +
49735 +char gr_roletype_to_char(void)
49736 +{
49737 + return gr_task_roletype_to_char(current);
49738 +}
49739 +
49740 +__inline__ int
49741 +gr_acl_tpe_check(void)
49742 +{
49743 + if (unlikely(!(gr_status & GR_READY)))
49744 + return 0;
49745 + if (current->role->roletype & GR_ROLE_TPE)
49746 + return 1;
49747 + else
49748 + return 0;
49749 +}
49750 +
49751 +int
49752 +gr_handle_rawio(const struct inode *inode)
49753 +{
49754 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
49755 + if (inode && S_ISBLK(inode->i_mode) &&
49756 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
49757 + !capable(CAP_SYS_RAWIO))
49758 + return 1;
49759 +#endif
49760 + return 0;
49761 +}
49762 +
49763 +static int
49764 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
49765 +{
49766 + if (likely(lena != lenb))
49767 + return 0;
49768 +
49769 + return !memcmp(a, b, lena);
49770 +}
49771 +
49772 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
49773 +{
49774 + *buflen -= namelen;
49775 + if (*buflen < 0)
49776 + return -ENAMETOOLONG;
49777 + *buffer -= namelen;
49778 + memcpy(*buffer, str, namelen);
49779 + return 0;
49780 +}
49781 +
49782 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
49783 +{
49784 + return prepend(buffer, buflen, name->name, name->len);
49785 +}
49786 +
49787 +static int prepend_path(const struct path *path, struct path *root,
49788 + char **buffer, int *buflen)
49789 +{
49790 + struct dentry *dentry = path->dentry;
49791 + struct vfsmount *vfsmnt = path->mnt;
49792 + bool slash = false;
49793 + int error = 0;
49794 +
49795 + while (dentry != root->dentry || vfsmnt != root->mnt) {
49796 + struct dentry * parent;
49797 +
49798 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
49799 + /* Global root? */
49800 + if (vfsmnt->mnt_parent == vfsmnt) {
49801 + goto out;
49802 + }
49803 + dentry = vfsmnt->mnt_mountpoint;
49804 + vfsmnt = vfsmnt->mnt_parent;
49805 + continue;
49806 + }
49807 + parent = dentry->d_parent;
49808 + prefetch(parent);
49809 + spin_lock(&dentry->d_lock);
49810 + error = prepend_name(buffer, buflen, &dentry->d_name);
49811 + spin_unlock(&dentry->d_lock);
49812 + if (!error)
49813 + error = prepend(buffer, buflen, "/", 1);
49814 + if (error)
49815 + break;
49816 +
49817 + slash = true;
49818 + dentry = parent;
49819 + }
49820 +
49821 +out:
49822 + if (!error && !slash)
49823 + error = prepend(buffer, buflen, "/", 1);
49824 +
49825 + return error;
49826 +}
49827 +
49828 +/* this must be called with vfsmount_lock and rename_lock held */
49829 +
49830 +static char *__our_d_path(const struct path *path, struct path *root,
49831 + char *buf, int buflen)
49832 +{
49833 + char *res = buf + buflen;
49834 + int error;
49835 +
49836 + prepend(&res, &buflen, "\0", 1);
49837 + error = prepend_path(path, root, &res, &buflen);
49838 + if (error)
49839 + return ERR_PTR(error);
49840 +
49841 + return res;
49842 +}
49843 +
49844 +static char *
49845 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
49846 +{
49847 + char *retval;
49848 +
49849 + retval = __our_d_path(path, root, buf, buflen);
49850 + if (unlikely(IS_ERR(retval)))
49851 + retval = strcpy(buf, "<path too long>");
49852 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
49853 + retval[1] = '\0';
49854 +
49855 + return retval;
49856 +}
49857 +
49858 +static char *
49859 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
49860 + char *buf, int buflen)
49861 +{
49862 + struct path path;
49863 + char *res;
49864 +
49865 + path.dentry = (struct dentry *)dentry;
49866 + path.mnt = (struct vfsmount *)vfsmnt;
49867 +
49868 + /* we can use real_root.dentry, real_root.mnt, because this is only called
49869 + by the RBAC system */
49870 + res = gen_full_path(&path, &real_root, buf, buflen);
49871 +
49872 + return res;
49873 +}
49874 +
49875 +static char *
49876 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
49877 + char *buf, int buflen)
49878 +{
49879 + char *res;
49880 + struct path path;
49881 + struct path root;
49882 + struct task_struct *reaper = &init_task;
49883 +
49884 + path.dentry = (struct dentry *)dentry;
49885 + path.mnt = (struct vfsmount *)vfsmnt;
49886 +
49887 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
49888 + get_fs_root(reaper->fs, &root);
49889 +
49890 + write_seqlock(&rename_lock);
49891 + br_read_lock(vfsmount_lock);
49892 + res = gen_full_path(&path, &root, buf, buflen);
49893 + br_read_unlock(vfsmount_lock);
49894 + write_sequnlock(&rename_lock);
49895 +
49896 + path_put(&root);
49897 + return res;
49898 +}
49899 +
49900 +static char *
49901 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
49902 +{
49903 + char *ret;
49904 + write_seqlock(&rename_lock);
49905 + br_read_lock(vfsmount_lock);
49906 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
49907 + PAGE_SIZE);
49908 + br_read_unlock(vfsmount_lock);
49909 + write_sequnlock(&rename_lock);
49910 + return ret;
49911 +}
49912 +
49913 +static char *
49914 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
49915 +{
49916 + char *ret;
49917 + char *buf;
49918 + int buflen;
49919 +
49920 + write_seqlock(&rename_lock);
49921 + br_read_lock(vfsmount_lock);
49922 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
49923 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
49924 + buflen = (int)(ret - buf);
49925 + if (buflen >= 5)
49926 + prepend(&ret, &buflen, "/proc", 5);
49927 + else
49928 + ret = strcpy(buf, "<path too long>");
49929 + br_read_unlock(vfsmount_lock);
49930 + write_sequnlock(&rename_lock);
49931 + return ret;
49932 +}
49933 +
49934 +char *
49935 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
49936 +{
49937 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
49938 + PAGE_SIZE);
49939 +}
49940 +
49941 +char *
49942 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
49943 +{
49944 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
49945 + PAGE_SIZE);
49946 +}
49947 +
49948 +char *
49949 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
49950 +{
49951 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
49952 + PAGE_SIZE);
49953 +}
49954 +
49955 +char *
49956 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
49957 +{
49958 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
49959 + PAGE_SIZE);
49960 +}
49961 +
49962 +char *
49963 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
49964 +{
49965 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
49966 + PAGE_SIZE);
49967 +}
49968 +
49969 +__inline__ __u32
49970 +to_gr_audit(const __u32 reqmode)
49971 +{
49972 + /* masks off auditable permission flags, then shifts them to create
49973 + auditing flags, and adds the special case of append auditing if
49974 + we're requesting write */
49975 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
49976 +}
49977 +
49978 +struct acl_subject_label *
49979 +lookup_subject_map(const struct acl_subject_label *userp)
49980 +{
49981 + unsigned int index = shash(userp, subj_map_set.s_size);
49982 + struct subject_map *match;
49983 +
49984 + match = subj_map_set.s_hash[index];
49985 +
49986 + while (match && match->user != userp)
49987 + match = match->next;
49988 +
49989 + if (match != NULL)
49990 + return match->kernel;
49991 + else
49992 + return NULL;
49993 +}
49994 +
49995 +static void
49996 +insert_subj_map_entry(struct subject_map *subjmap)
49997 +{
49998 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
49999 + struct subject_map **curr;
50000 +
50001 + subjmap->prev = NULL;
50002 +
50003 + curr = &subj_map_set.s_hash[index];
50004 + if (*curr != NULL)
50005 + (*curr)->prev = subjmap;
50006 +
50007 + subjmap->next = *curr;
50008 + *curr = subjmap;
50009 +
50010 + return;
50011 +}
50012 +
50013 +static struct acl_role_label *
50014 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
50015 + const gid_t gid)
50016 +{
50017 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
50018 + struct acl_role_label *match;
50019 + struct role_allowed_ip *ipp;
50020 + unsigned int x;
50021 + u32 curr_ip = task->signal->curr_ip;
50022 +
50023 + task->signal->saved_ip = curr_ip;
50024 +
50025 + match = acl_role_set.r_hash[index];
50026 +
50027 + while (match) {
50028 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
50029 + for (x = 0; x < match->domain_child_num; x++) {
50030 + if (match->domain_children[x] == uid)
50031 + goto found;
50032 + }
50033 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
50034 + break;
50035 + match = match->next;
50036 + }
50037 +found:
50038 + if (match == NULL) {
50039 + try_group:
50040 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
50041 + match = acl_role_set.r_hash[index];
50042 +
50043 + while (match) {
50044 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
50045 + for (x = 0; x < match->domain_child_num; x++) {
50046 + if (match->domain_children[x] == gid)
50047 + goto found2;
50048 + }
50049 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
50050 + break;
50051 + match = match->next;
50052 + }
50053 +found2:
50054 + if (match == NULL)
50055 + match = default_role;
50056 + if (match->allowed_ips == NULL)
50057 + return match;
50058 + else {
50059 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
50060 + if (likely
50061 + ((ntohl(curr_ip) & ipp->netmask) ==
50062 + (ntohl(ipp->addr) & ipp->netmask)))
50063 + return match;
50064 + }
50065 + match = default_role;
50066 + }
50067 + } else if (match->allowed_ips == NULL) {
50068 + return match;
50069 + } else {
50070 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
50071 + if (likely
50072 + ((ntohl(curr_ip) & ipp->netmask) ==
50073 + (ntohl(ipp->addr) & ipp->netmask)))
50074 + return match;
50075 + }
50076 + goto try_group;
50077 + }
50078 +
50079 + return match;
50080 +}
50081 +
50082 +struct acl_subject_label *
50083 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
50084 + const struct acl_role_label *role)
50085 +{
50086 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
50087 + struct acl_subject_label *match;
50088 +
50089 + match = role->subj_hash[index];
50090 +
50091 + while (match && (match->inode != ino || match->device != dev ||
50092 + (match->mode & GR_DELETED))) {
50093 + match = match->next;
50094 + }
50095 +
50096 + if (match && !(match->mode & GR_DELETED))
50097 + return match;
50098 + else
50099 + return NULL;
50100 +}
50101 +
50102 +struct acl_subject_label *
50103 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
50104 + const struct acl_role_label *role)
50105 +{
50106 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
50107 + struct acl_subject_label *match;
50108 +
50109 + match = role->subj_hash[index];
50110 +
50111 + while (match && (match->inode != ino || match->device != dev ||
50112 + !(match->mode & GR_DELETED))) {
50113 + match = match->next;
50114 + }
50115 +
50116 + if (match && (match->mode & GR_DELETED))
50117 + return match;
50118 + else
50119 + return NULL;
50120 +}
50121 +
50122 +static struct acl_object_label *
50123 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
50124 + const struct acl_subject_label *subj)
50125 +{
50126 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
50127 + struct acl_object_label *match;
50128 +
50129 + match = subj->obj_hash[index];
50130 +
50131 + while (match && (match->inode != ino || match->device != dev ||
50132 + (match->mode & GR_DELETED))) {
50133 + match = match->next;
50134 + }
50135 +
50136 + if (match && !(match->mode & GR_DELETED))
50137 + return match;
50138 + else
50139 + return NULL;
50140 +}
50141 +
50142 +static struct acl_object_label *
50143 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
50144 + const struct acl_subject_label *subj)
50145 +{
50146 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
50147 + struct acl_object_label *match;
50148 +
50149 + match = subj->obj_hash[index];
50150 +
50151 + while (match && (match->inode != ino || match->device != dev ||
50152 + !(match->mode & GR_DELETED))) {
50153 + match = match->next;
50154 + }
50155 +
50156 + if (match && (match->mode & GR_DELETED))
50157 + return match;
50158 +
50159 + match = subj->obj_hash[index];
50160 +
50161 + while (match && (match->inode != ino || match->device != dev ||
50162 + (match->mode & GR_DELETED))) {
50163 + match = match->next;
50164 + }
50165 +
50166 + if (match && !(match->mode & GR_DELETED))
50167 + return match;
50168 + else
50169 + return NULL;
50170 +}
50171 +
50172 +static struct name_entry *
50173 +lookup_name_entry(const char *name)
50174 +{
50175 + unsigned int len = strlen(name);
50176 + unsigned int key = full_name_hash(name, len);
50177 + unsigned int index = key % name_set.n_size;
50178 + struct name_entry *match;
50179 +
50180 + match = name_set.n_hash[index];
50181 +
50182 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
50183 + match = match->next;
50184 +
50185 + return match;
50186 +}
50187 +
50188 +static struct name_entry *
50189 +lookup_name_entry_create(const char *name)
50190 +{
50191 + unsigned int len = strlen(name);
50192 + unsigned int key = full_name_hash(name, len);
50193 + unsigned int index = key % name_set.n_size;
50194 + struct name_entry *match;
50195 +
50196 + match = name_set.n_hash[index];
50197 +
50198 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
50199 + !match->deleted))
50200 + match = match->next;
50201 +
50202 + if (match && match->deleted)
50203 + return match;
50204 +
50205 + match = name_set.n_hash[index];
50206 +
50207 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
50208 + match->deleted))
50209 + match = match->next;
50210 +
50211 + if (match && !match->deleted)
50212 + return match;
50213 + else
50214 + return NULL;
50215 +}
50216 +
50217 +static struct inodev_entry *
50218 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
50219 +{
50220 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
50221 + struct inodev_entry *match;
50222 +
50223 + match = inodev_set.i_hash[index];
50224 +
50225 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
50226 + match = match->next;
50227 +
50228 + return match;
50229 +}
50230 +
50231 +static void
50232 +insert_inodev_entry(struct inodev_entry *entry)
50233 +{
50234 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
50235 + inodev_set.i_size);
50236 + struct inodev_entry **curr;
50237 +
50238 + entry->prev = NULL;
50239 +
50240 + curr = &inodev_set.i_hash[index];
50241 + if (*curr != NULL)
50242 + (*curr)->prev = entry;
50243 +
50244 + entry->next = *curr;
50245 + *curr = entry;
50246 +
50247 + return;
50248 +}
50249 +
50250 +static void
50251 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
50252 +{
50253 + unsigned int index =
50254 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
50255 + struct acl_role_label **curr;
50256 + struct acl_role_label *tmp;
50257 +
50258 + curr = &acl_role_set.r_hash[index];
50259 +
50260 + /* if role was already inserted due to domains and already has
50261 + a role in the same bucket as it attached, then we need to
50262 + combine these two buckets
50263 + */
50264 + if (role->next) {
50265 + tmp = role->next;
50266 + while (tmp->next)
50267 + tmp = tmp->next;
50268 + tmp->next = *curr;
50269 + } else
50270 + role->next = *curr;
50271 + *curr = role;
50272 +
50273 + return;
50274 +}
50275 +
50276 +static void
50277 +insert_acl_role_label(struct acl_role_label *role)
50278 +{
50279 + int i;
50280 +
50281 + if (role_list == NULL) {
50282 + role_list = role;
50283 + role->prev = NULL;
50284 + } else {
50285 + role->prev = role_list;
50286 + role_list = role;
50287 + }
50288 +
50289 + /* used for hash chains */
50290 + role->next = NULL;
50291 +
50292 + if (role->roletype & GR_ROLE_DOMAIN) {
50293 + for (i = 0; i < role->domain_child_num; i++)
50294 + __insert_acl_role_label(role, role->domain_children[i]);
50295 + } else
50296 + __insert_acl_role_label(role, role->uidgid);
50297 +}
50298 +
50299 +static int
50300 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
50301 +{
50302 + struct name_entry **curr, *nentry;
50303 + struct inodev_entry *ientry;
50304 + unsigned int len = strlen(name);
50305 + unsigned int key = full_name_hash(name, len);
50306 + unsigned int index = key % name_set.n_size;
50307 +
50308 + curr = &name_set.n_hash[index];
50309 +
50310 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
50311 + curr = &((*curr)->next);
50312 +
50313 + if (*curr != NULL)
50314 + return 1;
50315 +
50316 + nentry = acl_alloc(sizeof (struct name_entry));
50317 + if (nentry == NULL)
50318 + return 0;
50319 + ientry = acl_alloc(sizeof (struct inodev_entry));
50320 + if (ientry == NULL)
50321 + return 0;
50322 + ientry->nentry = nentry;
50323 +
50324 + nentry->key = key;
50325 + nentry->name = name;
50326 + nentry->inode = inode;
50327 + nentry->device = device;
50328 + nentry->len = len;
50329 + nentry->deleted = deleted;
50330 +
50331 + nentry->prev = NULL;
50332 + curr = &name_set.n_hash[index];
50333 + if (*curr != NULL)
50334 + (*curr)->prev = nentry;
50335 + nentry->next = *curr;
50336 + *curr = nentry;
50337 +
50338 + /* insert us into the table searchable by inode/dev */
50339 + insert_inodev_entry(ientry);
50340 +
50341 + return 1;
50342 +}
50343 +
50344 +static void
50345 +insert_acl_obj_label(struct acl_object_label *obj,
50346 + struct acl_subject_label *subj)
50347 +{
50348 + unsigned int index =
50349 + fhash(obj->inode, obj->device, subj->obj_hash_size);
50350 + struct acl_object_label **curr;
50351 +
50352 +
50353 + obj->prev = NULL;
50354 +
50355 + curr = &subj->obj_hash[index];
50356 + if (*curr != NULL)
50357 + (*curr)->prev = obj;
50358 +
50359 + obj->next = *curr;
50360 + *curr = obj;
50361 +
50362 + return;
50363 +}
50364 +
50365 +static void
50366 +insert_acl_subj_label(struct acl_subject_label *obj,
50367 + struct acl_role_label *role)
50368 +{
50369 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
50370 + struct acl_subject_label **curr;
50371 +
50372 + obj->prev = NULL;
50373 +
50374 + curr = &role->subj_hash[index];
50375 + if (*curr != NULL)
50376 + (*curr)->prev = obj;
50377 +
50378 + obj->next = *curr;
50379 + *curr = obj;
50380 +
50381 + return;
50382 +}
50383 +
50384 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
50385 +
50386 +static void *
50387 +create_table(__u32 * len, int elementsize)
50388 +{
50389 + unsigned int table_sizes[] = {
50390 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
50391 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
50392 + 4194301, 8388593, 16777213, 33554393, 67108859
50393 + };
50394 + void *newtable = NULL;
50395 + unsigned int pwr = 0;
50396 +
50397 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
50398 + table_sizes[pwr] <= *len)
50399 + pwr++;
50400 +
50401 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
50402 + return newtable;
50403 +
50404 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
50405 + newtable =
50406 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
50407 + else
50408 + newtable = vmalloc(table_sizes[pwr] * elementsize);
50409 +
50410 + *len = table_sizes[pwr];
50411 +
50412 + return newtable;
50413 +}
50414 +
50415 +static int
50416 +init_variables(const struct gr_arg *arg)
50417 +{
50418 + struct task_struct *reaper = &init_task;
50419 + unsigned int stacksize;
50420 +
50421 + subj_map_set.s_size = arg->role_db.num_subjects;
50422 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
50423 + name_set.n_size = arg->role_db.num_objects;
50424 + inodev_set.i_size = arg->role_db.num_objects;
50425 +
50426 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
50427 + !name_set.n_size || !inodev_set.i_size)
50428 + return 1;
50429 +
50430 + if (!gr_init_uidset())
50431 + return 1;
50432 +
50433 + /* set up the stack that holds allocation info */
50434 +
50435 + stacksize = arg->role_db.num_pointers + 5;
50436 +
50437 + if (!acl_alloc_stack_init(stacksize))
50438 + return 1;
50439 +
50440 + /* grab reference for the real root dentry and vfsmount */
50441 + get_fs_root(reaper->fs, &real_root);
50442 +
50443 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
50444 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
50445 +#endif
50446 +
50447 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
50448 + if (fakefs_obj_rw == NULL)
50449 + return 1;
50450 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
50451 +
50452 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
50453 + if (fakefs_obj_rwx == NULL)
50454 + return 1;
50455 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
50456 +
50457 + subj_map_set.s_hash =
50458 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
50459 + acl_role_set.r_hash =
50460 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
50461 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
50462 + inodev_set.i_hash =
50463 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
50464 +
50465 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
50466 + !name_set.n_hash || !inodev_set.i_hash)
50467 + return 1;
50468 +
50469 + memset(subj_map_set.s_hash, 0,
50470 + sizeof(struct subject_map *) * subj_map_set.s_size);
50471 + memset(acl_role_set.r_hash, 0,
50472 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
50473 + memset(name_set.n_hash, 0,
50474 + sizeof (struct name_entry *) * name_set.n_size);
50475 + memset(inodev_set.i_hash, 0,
50476 + sizeof (struct inodev_entry *) * inodev_set.i_size);
50477 +
50478 + return 0;
50479 +}
50480 +
50481 +/* free information not needed after startup
50482 + currently contains user->kernel pointer mappings for subjects
50483 +*/
50484 +
50485 +static void
50486 +free_init_variables(void)
50487 +{
50488 + __u32 i;
50489 +
50490 + if (subj_map_set.s_hash) {
50491 + for (i = 0; i < subj_map_set.s_size; i++) {
50492 + if (subj_map_set.s_hash[i]) {
50493 + kfree(subj_map_set.s_hash[i]);
50494 + subj_map_set.s_hash[i] = NULL;
50495 + }
50496 + }
50497 +
50498 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
50499 + PAGE_SIZE)
50500 + kfree(subj_map_set.s_hash);
50501 + else
50502 + vfree(subj_map_set.s_hash);
50503 + }
50504 +
50505 + return;
50506 +}
50507 +
50508 +static void
50509 +free_variables(void)
50510 +{
50511 + struct acl_subject_label *s;
50512 + struct acl_role_label *r;
50513 + struct task_struct *task, *task2;
50514 + unsigned int x;
50515 +
50516 + gr_clear_learn_entries();
50517 +
50518 + read_lock(&tasklist_lock);
50519 + do_each_thread(task2, task) {
50520 + task->acl_sp_role = 0;
50521 + task->acl_role_id = 0;
50522 + task->acl = NULL;
50523 + task->role = NULL;
50524 + } while_each_thread(task2, task);
50525 + read_unlock(&tasklist_lock);
50526 +
50527 + /* release the reference to the real root dentry and vfsmount */
50528 + path_put(&real_root);
50529 +
50530 + /* free all object hash tables */
50531 +
50532 + FOR_EACH_ROLE_START(r)
50533 + if (r->subj_hash == NULL)
50534 + goto next_role;
50535 + FOR_EACH_SUBJECT_START(r, s, x)
50536 + if (s->obj_hash == NULL)
50537 + break;
50538 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
50539 + kfree(s->obj_hash);
50540 + else
50541 + vfree(s->obj_hash);
50542 + FOR_EACH_SUBJECT_END(s, x)
50543 + FOR_EACH_NESTED_SUBJECT_START(r, s)
50544 + if (s->obj_hash == NULL)
50545 + break;
50546 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
50547 + kfree(s->obj_hash);
50548 + else
50549 + vfree(s->obj_hash);
50550 + FOR_EACH_NESTED_SUBJECT_END(s)
50551 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
50552 + kfree(r->subj_hash);
50553 + else
50554 + vfree(r->subj_hash);
50555 + r->subj_hash = NULL;
50556 +next_role:
50557 + FOR_EACH_ROLE_END(r)
50558 +
50559 + acl_free_all();
50560 +
50561 + if (acl_role_set.r_hash) {
50562 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
50563 + PAGE_SIZE)
50564 + kfree(acl_role_set.r_hash);
50565 + else
50566 + vfree(acl_role_set.r_hash);
50567 + }
50568 + if (name_set.n_hash) {
50569 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
50570 + PAGE_SIZE)
50571 + kfree(name_set.n_hash);
50572 + else
50573 + vfree(name_set.n_hash);
50574 + }
50575 +
50576 + if (inodev_set.i_hash) {
50577 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
50578 + PAGE_SIZE)
50579 + kfree(inodev_set.i_hash);
50580 + else
50581 + vfree(inodev_set.i_hash);
50582 + }
50583 +
50584 + gr_free_uidset();
50585 +
50586 + memset(&name_set, 0, sizeof (struct name_db));
50587 + memset(&inodev_set, 0, sizeof (struct inodev_db));
50588 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
50589 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
50590 +
50591 + default_role = NULL;
50592 + role_list = NULL;
50593 +
50594 + return;
50595 +}
50596 +
50597 +static __u32
50598 +count_user_objs(struct acl_object_label *userp)
50599 +{
50600 + struct acl_object_label o_tmp;
50601 + __u32 num = 0;
50602 +
50603 + while (userp) {
50604 + if (copy_from_user(&o_tmp, userp,
50605 + sizeof (struct acl_object_label)))
50606 + break;
50607 +
50608 + userp = o_tmp.prev;
50609 + num++;
50610 + }
50611 +
50612 + return num;
50613 +}
50614 +
50615 +static struct acl_subject_label *
50616 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
50617 +
50618 +static int
50619 +copy_user_glob(struct acl_object_label *obj)
50620 +{
50621 + struct acl_object_label *g_tmp, **guser;
50622 + unsigned int len;
50623 + char *tmp;
50624 +
50625 + if (obj->globbed == NULL)
50626 + return 0;
50627 +
50628 + guser = &obj->globbed;
50629 + while (*guser) {
50630 + g_tmp = (struct acl_object_label *)
50631 + acl_alloc(sizeof (struct acl_object_label));
50632 + if (g_tmp == NULL)
50633 + return -ENOMEM;
50634 +
50635 + if (copy_from_user(g_tmp, *guser,
50636 + sizeof (struct acl_object_label)))
50637 + return -EFAULT;
50638 +
50639 + len = strnlen_user(g_tmp->filename, PATH_MAX);
50640 +
50641 + if (!len || len >= PATH_MAX)
50642 + return -EINVAL;
50643 +
50644 + if ((tmp = (char *) acl_alloc(len)) == NULL)
50645 + return -ENOMEM;
50646 +
50647 + if (copy_from_user(tmp, g_tmp->filename, len))
50648 + return -EFAULT;
50649 + tmp[len-1] = '\0';
50650 + g_tmp->filename = tmp;
50651 +
50652 + *guser = g_tmp;
50653 + guser = &(g_tmp->next);
50654 + }
50655 +
50656 + return 0;
50657 +}
50658 +
50659 +static int
50660 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
50661 + struct acl_role_label *role)
50662 +{
50663 + struct acl_object_label *o_tmp;
50664 + unsigned int len;
50665 + int ret;
50666 + char *tmp;
50667 +
50668 + while (userp) {
50669 + if ((o_tmp = (struct acl_object_label *)
50670 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
50671 + return -ENOMEM;
50672 +
50673 + if (copy_from_user(o_tmp, userp,
50674 + sizeof (struct acl_object_label)))
50675 + return -EFAULT;
50676 +
50677 + userp = o_tmp->prev;
50678 +
50679 + len = strnlen_user(o_tmp->filename, PATH_MAX);
50680 +
50681 + if (!len || len >= PATH_MAX)
50682 + return -EINVAL;
50683 +
50684 + if ((tmp = (char *) acl_alloc(len)) == NULL)
50685 + return -ENOMEM;
50686 +
50687 + if (copy_from_user(tmp, o_tmp->filename, len))
50688 + return -EFAULT;
50689 + tmp[len-1] = '\0';
50690 + o_tmp->filename = tmp;
50691 +
50692 + insert_acl_obj_label(o_tmp, subj);
50693 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
50694 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
50695 + return -ENOMEM;
50696 +
50697 + ret = copy_user_glob(o_tmp);
50698 + if (ret)
50699 + return ret;
50700 +
50701 + if (o_tmp->nested) {
50702 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
50703 + if (IS_ERR(o_tmp->nested))
50704 + return PTR_ERR(o_tmp->nested);
50705 +
50706 + /* insert into nested subject list */
50707 + o_tmp->nested->next = role->hash->first;
50708 + role->hash->first = o_tmp->nested;
50709 + }
50710 + }
50711 +
50712 + return 0;
50713 +}
50714 +
50715 +static __u32
50716 +count_user_subjs(struct acl_subject_label *userp)
50717 +{
50718 + struct acl_subject_label s_tmp;
50719 + __u32 num = 0;
50720 +
50721 + while (userp) {
50722 + if (copy_from_user(&s_tmp, userp,
50723 + sizeof (struct acl_subject_label)))
50724 + break;
50725 +
50726 + userp = s_tmp.prev;
50727 + /* do not count nested subjects against this count, since
50728 + they are not included in the hash table, but are
50729 + attached to objects. We have already counted
50730 + the subjects in userspace for the allocation
50731 + stack
50732 + */
50733 + if (!(s_tmp.mode & GR_NESTED))
50734 + num++;
50735 + }
50736 +
50737 + return num;
50738 +}
50739 +
50740 +static int
50741 +copy_user_allowedips(struct acl_role_label *rolep)
50742 +{
50743 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
50744 +
50745 + ruserip = rolep->allowed_ips;
50746 +
50747 + while (ruserip) {
50748 + rlast = rtmp;
50749 +
50750 + if ((rtmp = (struct role_allowed_ip *)
50751 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
50752 + return -ENOMEM;
50753 +
50754 + if (copy_from_user(rtmp, ruserip,
50755 + sizeof (struct role_allowed_ip)))
50756 + return -EFAULT;
50757 +
50758 + ruserip = rtmp->prev;
50759 +
50760 + if (!rlast) {
50761 + rtmp->prev = NULL;
50762 + rolep->allowed_ips = rtmp;
50763 + } else {
50764 + rlast->next = rtmp;
50765 + rtmp->prev = rlast;
50766 + }
50767 +
50768 + if (!ruserip)
50769 + rtmp->next = NULL;
50770 + }
50771 +
50772 + return 0;
50773 +}
50774 +
50775 +static int
50776 +copy_user_transitions(struct acl_role_label *rolep)
50777 +{
50778 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
50779 +
50780 + unsigned int len;
50781 + char *tmp;
50782 +
50783 + rusertp = rolep->transitions;
50784 +
50785 + while (rusertp) {
50786 + rlast = rtmp;
50787 +
50788 + if ((rtmp = (struct role_transition *)
50789 + acl_alloc(sizeof (struct role_transition))) == NULL)
50790 + return -ENOMEM;
50791 +
50792 + if (copy_from_user(rtmp, rusertp,
50793 + sizeof (struct role_transition)))
50794 + return -EFAULT;
50795 +
50796 + rusertp = rtmp->prev;
50797 +
50798 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
50799 +
50800 + if (!len || len >= GR_SPROLE_LEN)
50801 + return -EINVAL;
50802 +
50803 + if ((tmp = (char *) acl_alloc(len)) == NULL)
50804 + return -ENOMEM;
50805 +
50806 + if (copy_from_user(tmp, rtmp->rolename, len))
50807 + return -EFAULT;
50808 + tmp[len-1] = '\0';
50809 + rtmp->rolename = tmp;
50810 +
50811 + if (!rlast) {
50812 + rtmp->prev = NULL;
50813 + rolep->transitions = rtmp;
50814 + } else {
50815 + rlast->next = rtmp;
50816 + rtmp->prev = rlast;
50817 + }
50818 +
50819 + if (!rusertp)
50820 + rtmp->next = NULL;
50821 + }
50822 +
50823 + return 0;
50824 +}
50825 +
50826 +static struct acl_subject_label *
50827 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
50828 +{
50829 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
50830 + unsigned int len;
50831 + char *tmp;
50832 + __u32 num_objs;
50833 + struct acl_ip_label **i_tmp, *i_utmp2;
50834 + struct gr_hash_struct ghash;
50835 + struct subject_map *subjmap;
50836 + unsigned int i_num;
50837 + int err;
50838 +
50839 + s_tmp = lookup_subject_map(userp);
50840 +
50841 + /* we've already copied this subject into the kernel, just return
50842 + the reference to it, and don't copy it over again
50843 + */
50844 + if (s_tmp)
50845 + return(s_tmp);
50846 +
50847 + if ((s_tmp = (struct acl_subject_label *)
50848 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
50849 + return ERR_PTR(-ENOMEM);
50850 +
50851 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
50852 + if (subjmap == NULL)
50853 + return ERR_PTR(-ENOMEM);
50854 +
50855 + subjmap->user = userp;
50856 + subjmap->kernel = s_tmp;
50857 + insert_subj_map_entry(subjmap);
50858 +
50859 + if (copy_from_user(s_tmp, userp,
50860 + sizeof (struct acl_subject_label)))
50861 + return ERR_PTR(-EFAULT);
50862 +
50863 + len = strnlen_user(s_tmp->filename, PATH_MAX);
50864 +
50865 + if (!len || len >= PATH_MAX)
50866 + return ERR_PTR(-EINVAL);
50867 +
50868 + if ((tmp = (char *) acl_alloc(len)) == NULL)
50869 + return ERR_PTR(-ENOMEM);
50870 +
50871 + if (copy_from_user(tmp, s_tmp->filename, len))
50872 + return ERR_PTR(-EFAULT);
50873 + tmp[len-1] = '\0';
50874 + s_tmp->filename = tmp;
50875 +
50876 + if (!strcmp(s_tmp->filename, "/"))
50877 + role->root_label = s_tmp;
50878 +
50879 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
50880 + return ERR_PTR(-EFAULT);
50881 +
50882 + /* copy user and group transition tables */
50883 +
50884 + if (s_tmp->user_trans_num) {
50885 + uid_t *uidlist;
50886 +
50887 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
50888 + if (uidlist == NULL)
50889 + return ERR_PTR(-ENOMEM);
50890 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
50891 + return ERR_PTR(-EFAULT);
50892 +
50893 + s_tmp->user_transitions = uidlist;
50894 + }
50895 +
50896 + if (s_tmp->group_trans_num) {
50897 + gid_t *gidlist;
50898 +
50899 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
50900 + if (gidlist == NULL)
50901 + return ERR_PTR(-ENOMEM);
50902 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
50903 + return ERR_PTR(-EFAULT);
50904 +
50905 + s_tmp->group_transitions = gidlist;
50906 + }
50907 +
50908 + /* set up object hash table */
50909 + num_objs = count_user_objs(ghash.first);
50910 +
50911 + s_tmp->obj_hash_size = num_objs;
50912 + s_tmp->obj_hash =
50913 + (struct acl_object_label **)
50914 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
50915 +
50916 + if (!s_tmp->obj_hash)
50917 + return ERR_PTR(-ENOMEM);
50918 +
50919 + memset(s_tmp->obj_hash, 0,
50920 + s_tmp->obj_hash_size *
50921 + sizeof (struct acl_object_label *));
50922 +
50923 + /* add in objects */
50924 + err = copy_user_objs(ghash.first, s_tmp, role);
50925 +
50926 + if (err)
50927 + return ERR_PTR(err);
50928 +
50929 + /* set pointer for parent subject */
50930 + if (s_tmp->parent_subject) {
50931 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
50932 +
50933 + if (IS_ERR(s_tmp2))
50934 + return s_tmp2;
50935 +
50936 + s_tmp->parent_subject = s_tmp2;
50937 + }
50938 +
50939 + /* add in ip acls */
50940 +
50941 + if (!s_tmp->ip_num) {
50942 + s_tmp->ips = NULL;
50943 + goto insert;
50944 + }
50945 +
50946 + i_tmp =
50947 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
50948 + sizeof (struct acl_ip_label *));
50949 +
50950 + if (!i_tmp)
50951 + return ERR_PTR(-ENOMEM);
50952 +
50953 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
50954 + *(i_tmp + i_num) =
50955 + (struct acl_ip_label *)
50956 + acl_alloc(sizeof (struct acl_ip_label));
50957 + if (!*(i_tmp + i_num))
50958 + return ERR_PTR(-ENOMEM);
50959 +
50960 + if (copy_from_user
50961 + (&i_utmp2, s_tmp->ips + i_num,
50962 + sizeof (struct acl_ip_label *)))
50963 + return ERR_PTR(-EFAULT);
50964 +
50965 + if (copy_from_user
50966 + (*(i_tmp + i_num), i_utmp2,
50967 + sizeof (struct acl_ip_label)))
50968 + return ERR_PTR(-EFAULT);
50969 +
50970 + if ((*(i_tmp + i_num))->iface == NULL)
50971 + continue;
50972 +
50973 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
50974 + if (!len || len >= IFNAMSIZ)
50975 + return ERR_PTR(-EINVAL);
50976 + tmp = acl_alloc(len);
50977 + if (tmp == NULL)
50978 + return ERR_PTR(-ENOMEM);
50979 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
50980 + return ERR_PTR(-EFAULT);
50981 + (*(i_tmp + i_num))->iface = tmp;
50982 + }
50983 +
50984 + s_tmp->ips = i_tmp;
50985 +
50986 +insert:
50987 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
50988 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
50989 + return ERR_PTR(-ENOMEM);
50990 +
50991 + return s_tmp;
50992 +}
50993 +
50994 +static int
50995 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
50996 +{
50997 + struct acl_subject_label s_pre;
50998 + struct acl_subject_label * ret;
50999 + int err;
51000 +
51001 + while (userp) {
51002 + if (copy_from_user(&s_pre, userp,
51003 + sizeof (struct acl_subject_label)))
51004 + return -EFAULT;
51005 +
51006 + /* do not add nested subjects here, add
51007 + while parsing objects
51008 + */
51009 +
51010 + if (s_pre.mode & GR_NESTED) {
51011 + userp = s_pre.prev;
51012 + continue;
51013 + }
51014 +
51015 + ret = do_copy_user_subj(userp, role);
51016 +
51017 + err = PTR_ERR(ret);
51018 + if (IS_ERR(ret))
51019 + return err;
51020 +
51021 + insert_acl_subj_label(ret, role);
51022 +
51023 + userp = s_pre.prev;
51024 + }
51025 +
51026 + return 0;
51027 +}
51028 +
51029 +static int
51030 +copy_user_acl(struct gr_arg *arg)
51031 +{
51032 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
51033 + struct sprole_pw *sptmp;
51034 + struct gr_hash_struct *ghash;
51035 + uid_t *domainlist;
51036 + unsigned int r_num;
51037 + unsigned int len;
51038 + char *tmp;
51039 + int err = 0;
51040 + __u16 i;
51041 + __u32 num_subjs;
51042 +
51043 + /* we need a default and kernel role */
51044 + if (arg->role_db.num_roles < 2)
51045 + return -EINVAL;
51046 +
51047 + /* copy special role authentication info from userspace */
51048 +
51049 + num_sprole_pws = arg->num_sprole_pws;
51050 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
51051 +
51052 + if (!acl_special_roles) {
51053 + err = -ENOMEM;
51054 + goto cleanup;
51055 + }
51056 +
51057 + for (i = 0; i < num_sprole_pws; i++) {
51058 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
51059 + if (!sptmp) {
51060 + err = -ENOMEM;
51061 + goto cleanup;
51062 + }
51063 + if (copy_from_user(sptmp, arg->sprole_pws + i,
51064 + sizeof (struct sprole_pw))) {
51065 + err = -EFAULT;
51066 + goto cleanup;
51067 + }
51068 +
51069 + len =
51070 + strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
51071 +
51072 + if (!len || len >= GR_SPROLE_LEN) {
51073 + err = -EINVAL;
51074 + goto cleanup;
51075 + }
51076 +
51077 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
51078 + err = -ENOMEM;
51079 + goto cleanup;
51080 + }
51081 +
51082 + if (copy_from_user(tmp, sptmp->rolename, len)) {
51083 + err = -EFAULT;
51084 + goto cleanup;
51085 + }
51086 + tmp[len-1] = '\0';
51087 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51088 + printk(KERN_ALERT "Copying special role %s\n", tmp);
51089 +#endif
51090 + sptmp->rolename = tmp;
51091 + acl_special_roles[i] = sptmp;
51092 + }
51093 +
51094 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
51095 +
51096 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
51097 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
51098 +
51099 + if (!r_tmp) {
51100 + err = -ENOMEM;
51101 + goto cleanup;
51102 + }
51103 +
51104 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
51105 + sizeof (struct acl_role_label *))) {
51106 + err = -EFAULT;
51107 + goto cleanup;
51108 + }
51109 +
51110 + if (copy_from_user(r_tmp, r_utmp2,
51111 + sizeof (struct acl_role_label))) {
51112 + err = -EFAULT;
51113 + goto cleanup;
51114 + }
51115 +
51116 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
51117 +
51118 + if (!len || len >= PATH_MAX) {
51119 + err = -EINVAL;
51120 + goto cleanup;
51121 + }
51122 +
51123 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
51124 + err = -ENOMEM;
51125 + goto cleanup;
51126 + }
51127 + if (copy_from_user(tmp, r_tmp->rolename, len)) {
51128 + err = -EFAULT;
51129 + goto cleanup;
51130 + }
51131 + tmp[len-1] = '\0';
51132 + r_tmp->rolename = tmp;
51133 +
51134 + if (!strcmp(r_tmp->rolename, "default")
51135 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
51136 + default_role = r_tmp;
51137 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
51138 + kernel_role = r_tmp;
51139 + }
51140 +
51141 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
51142 + err = -ENOMEM;
51143 + goto cleanup;
51144 + }
51145 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
51146 + err = -EFAULT;
51147 + goto cleanup;
51148 + }
51149 +
51150 + r_tmp->hash = ghash;
51151 +
51152 + num_subjs = count_user_subjs(r_tmp->hash->first);
51153 +
51154 + r_tmp->subj_hash_size = num_subjs;
51155 + r_tmp->subj_hash =
51156 + (struct acl_subject_label **)
51157 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
51158 +
51159 + if (!r_tmp->subj_hash) {
51160 + err = -ENOMEM;
51161 + goto cleanup;
51162 + }
51163 +
51164 + err = copy_user_allowedips(r_tmp);
51165 + if (err)
51166 + goto cleanup;
51167 +
51168 + /* copy domain info */
51169 + if (r_tmp->domain_children != NULL) {
51170 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
51171 + if (domainlist == NULL) {
51172 + err = -ENOMEM;
51173 + goto cleanup;
51174 + }
51175 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
51176 + err = -EFAULT;
51177 + goto cleanup;
51178 + }
51179 + r_tmp->domain_children = domainlist;
51180 + }
51181 +
51182 + err = copy_user_transitions(r_tmp);
51183 + if (err)
51184 + goto cleanup;
51185 +
51186 + memset(r_tmp->subj_hash, 0,
51187 + r_tmp->subj_hash_size *
51188 + sizeof (struct acl_subject_label *));
51189 +
51190 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
51191 +
51192 + if (err)
51193 + goto cleanup;
51194 +
51195 + /* set nested subject list to null */
51196 + r_tmp->hash->first = NULL;
51197 +
51198 + insert_acl_role_label(r_tmp);
51199 + }
51200 +
51201 + goto return_err;
51202 + cleanup:
51203 + free_variables();
51204 + return_err:
51205 + return err;
51206 +
51207 +}
51208 +
51209 +static int
51210 +gracl_init(struct gr_arg *args)
51211 +{
51212 + int error = 0;
51213 +
51214 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
51215 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
51216 +
51217 + if (init_variables(args)) {
51218 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
51219 + error = -ENOMEM;
51220 + free_variables();
51221 + goto out;
51222 + }
51223 +
51224 + error = copy_user_acl(args);
51225 + free_init_variables();
51226 + if (error) {
51227 + free_variables();
51228 + goto out;
51229 + }
51230 +
51231 + if ((error = gr_set_acls(0))) {
51232 + free_variables();
51233 + goto out;
51234 + }
51235 +
51236 + pax_open_kernel();
51237 + gr_status |= GR_READY;
51238 + pax_close_kernel();
51239 +
51240 + out:
51241 + return error;
51242 +}
51243 +
51244 +/* derived from glibc fnmatch() 0: match, 1: no match*/
51245 +
51246 +static int
51247 +glob_match(const char *p, const char *n)
51248 +{
51249 + char c;
51250 +
51251 + while ((c = *p++) != '\0') {
51252 + switch (c) {
51253 + case '?':
51254 + if (*n == '\0')
51255 + return 1;
51256 + else if (*n == '/')
51257 + return 1;
51258 + break;
51259 + case '\\':
51260 + if (*n != c)
51261 + return 1;
51262 + break;
51263 + case '*':
51264 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
51265 + if (*n == '/')
51266 + return 1;
51267 + else if (c == '?') {
51268 + if (*n == '\0')
51269 + return 1;
51270 + else
51271 + ++n;
51272 + }
51273 + }
51274 + if (c == '\0') {
51275 + return 0;
51276 + } else {
51277 + const char *endp;
51278 +
51279 + if ((endp = strchr(n, '/')) == NULL)
51280 + endp = n + strlen(n);
51281 +
51282 + if (c == '[') {
51283 + for (--p; n < endp; ++n)
51284 + if (!glob_match(p, n))
51285 + return 0;
51286 + } else if (c == '/') {
51287 + while (*n != '\0' && *n != '/')
51288 + ++n;
51289 + if (*n == '/' && !glob_match(p, n + 1))
51290 + return 0;
51291 + } else {
51292 + for (--p; n < endp; ++n)
51293 + if (*n == c && !glob_match(p, n))
51294 + return 0;
51295 + }
51296 +
51297 + return 1;
51298 + }
51299 + case '[':
51300 + {
51301 + int not;
51302 + char cold;
51303 +
51304 + if (*n == '\0' || *n == '/')
51305 + return 1;
51306 +
51307 + not = (*p == '!' || *p == '^');
51308 + if (not)
51309 + ++p;
51310 +
51311 + c = *p++;
51312 + for (;;) {
51313 + unsigned char fn = (unsigned char)*n;
51314 +
51315 + if (c == '\0')
51316 + return 1;
51317 + else {
51318 + if (c == fn)
51319 + goto matched;
51320 + cold = c;
51321 + c = *p++;
51322 +
51323 + if (c == '-' && *p != ']') {
51324 + unsigned char cend = *p++;
51325 +
51326 + if (cend == '\0')
51327 + return 1;
51328 +
51329 + if (cold <= fn && fn <= cend)
51330 + goto matched;
51331 +
51332 + c = *p++;
51333 + }
51334 + }
51335 +
51336 + if (c == ']')
51337 + break;
51338 + }
51339 + if (!not)
51340 + return 1;
51341 + break;
51342 + matched:
51343 + while (c != ']') {
51344 + if (c == '\0')
51345 + return 1;
51346 +
51347 + c = *p++;
51348 + }
51349 + if (not)
51350 + return 1;
51351 + }
51352 + break;
51353 + default:
51354 + if (c != *n)
51355 + return 1;
51356 + }
51357 +
51358 + ++n;
51359 + }
51360 +
51361 + if (*n == '\0')
51362 + return 0;
51363 +
51364 + if (*n == '/')
51365 + return 0;
51366 +
51367 + return 1;
51368 +}
51369 +
51370 +static struct acl_object_label *
51371 +chk_glob_label(struct acl_object_label *globbed,
51372 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
51373 +{
51374 + struct acl_object_label *tmp;
51375 +
51376 + if (*path == NULL)
51377 + *path = gr_to_filename_nolock(dentry, mnt);
51378 +
51379 + tmp = globbed;
51380 +
51381 + while (tmp) {
51382 + if (!glob_match(tmp->filename, *path))
51383 + return tmp;
51384 + tmp = tmp->next;
51385 + }
51386 +
51387 + return NULL;
51388 +}
51389 +
51390 +static struct acl_object_label *
51391 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
51392 + const ino_t curr_ino, const dev_t curr_dev,
51393 + const struct acl_subject_label *subj, char **path, const int checkglob)
51394 +{
51395 + struct acl_subject_label *tmpsubj;
51396 + struct acl_object_label *retval;
51397 + struct acl_object_label *retval2;
51398 +
51399 + tmpsubj = (struct acl_subject_label *) subj;
51400 + read_lock(&gr_inode_lock);
51401 + do {
51402 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
51403 + if (retval) {
51404 + if (checkglob && retval->globbed) {
51405 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
51406 + if (retval2)
51407 + retval = retval2;
51408 + }
51409 + break;
51410 + }
51411 + } while ((tmpsubj = tmpsubj->parent_subject));
51412 + read_unlock(&gr_inode_lock);
51413 +
51414 + return retval;
51415 +}
51416 +
51417 +static __inline__ struct acl_object_label *
51418 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
51419 + struct dentry *curr_dentry,
51420 + const struct acl_subject_label *subj, char **path, const int checkglob)
51421 +{
51422 + int newglob = checkglob;
51423 + ino_t inode;
51424 + dev_t device;
51425 +
51426 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
51427 + as we don't want a / * rule to match instead of the / object
51428 + don't do this for create lookups that call this function though, since they're looking up
51429 + on the parent and thus need globbing checks on all paths
51430 + */
51431 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
51432 + newglob = GR_NO_GLOB;
51433 +
51434 + spin_lock(&curr_dentry->d_lock);
51435 + inode = curr_dentry->d_inode->i_ino;
51436 + device = __get_dev(curr_dentry);
51437 + spin_unlock(&curr_dentry->d_lock);
51438 +
51439 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
51440 +}
51441 +
51442 +static struct acl_object_label *
51443 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51444 + const struct acl_subject_label *subj, char *path, const int checkglob)
51445 +{
51446 + struct dentry *dentry = (struct dentry *) l_dentry;
51447 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
51448 + struct acl_object_label *retval;
51449 + struct dentry *parent;
51450 +
51451 + write_seqlock(&rename_lock);
51452 + br_read_lock(vfsmount_lock);
51453 +
51454 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
51455 +#ifdef CONFIG_NET
51456 + mnt == sock_mnt ||
51457 +#endif
51458 +#ifdef CONFIG_HUGETLBFS
51459 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
51460 +#endif
51461 + /* ignore Eric Biederman */
51462 + IS_PRIVATE(l_dentry->d_inode))) {
51463 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
51464 + goto out;
51465 + }
51466 +
51467 + for (;;) {
51468 + if (dentry == real_root.dentry && mnt == real_root.mnt)
51469 + break;
51470 +
51471 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
51472 + if (mnt->mnt_parent == mnt)
51473 + break;
51474 +
51475 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
51476 + if (retval != NULL)
51477 + goto out;
51478 +
51479 + dentry = mnt->mnt_mountpoint;
51480 + mnt = mnt->mnt_parent;
51481 + continue;
51482 + }
51483 +
51484 + parent = dentry->d_parent;
51485 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
51486 + if (retval != NULL)
51487 + goto out;
51488 +
51489 + dentry = parent;
51490 + }
51491 +
51492 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
51493 +
51494 + /* real_root is pinned so we don't have to hold a reference */
51495 + if (retval == NULL)
51496 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
51497 +out:
51498 + br_read_unlock(vfsmount_lock);
51499 + write_sequnlock(&rename_lock);
51500 +
51501 + BUG_ON(retval == NULL);
51502 +
51503 + return retval;
51504 +}
51505 +
51506 +static __inline__ struct acl_object_label *
51507 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51508 + const struct acl_subject_label *subj)
51509 +{
51510 + char *path = NULL;
51511 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
51512 +}
51513 +
51514 +static __inline__ struct acl_object_label *
51515 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51516 + const struct acl_subject_label *subj)
51517 +{
51518 + char *path = NULL;
51519 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
51520 +}
51521 +
51522 +static __inline__ struct acl_object_label *
51523 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51524 + const struct acl_subject_label *subj, char *path)
51525 +{
51526 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
51527 +}
51528 +
51529 +static struct acl_subject_label *
51530 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51531 + const struct acl_role_label *role)
51532 +{
51533 + struct dentry *dentry = (struct dentry *) l_dentry;
51534 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
51535 + struct acl_subject_label *retval;
51536 + struct dentry *parent;
51537 +
51538 + write_seqlock(&rename_lock);
51539 + br_read_lock(vfsmount_lock);
51540 +
51541 + for (;;) {
51542 + if (dentry == real_root.dentry && mnt == real_root.mnt)
51543 + break;
51544 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
51545 + if (mnt->mnt_parent == mnt)
51546 + break;
51547 +
51548 + spin_lock(&dentry->d_lock);
51549 + read_lock(&gr_inode_lock);
51550 + retval =
51551 + lookup_acl_subj_label(dentry->d_inode->i_ino,
51552 + __get_dev(dentry), role);
51553 + read_unlock(&gr_inode_lock);
51554 + spin_unlock(&dentry->d_lock);
51555 + if (retval != NULL)
51556 + goto out;
51557 +
51558 + dentry = mnt->mnt_mountpoint;
51559 + mnt = mnt->mnt_parent;
51560 + continue;
51561 + }
51562 +
51563 + spin_lock(&dentry->d_lock);
51564 + read_lock(&gr_inode_lock);
51565 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
51566 + __get_dev(dentry), role);
51567 + read_unlock(&gr_inode_lock);
51568 + parent = dentry->d_parent;
51569 + spin_unlock(&dentry->d_lock);
51570 +
51571 + if (retval != NULL)
51572 + goto out;
51573 +
51574 + dentry = parent;
51575 + }
51576 +
51577 + spin_lock(&dentry->d_lock);
51578 + read_lock(&gr_inode_lock);
51579 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
51580 + __get_dev(dentry), role);
51581 + read_unlock(&gr_inode_lock);
51582 + spin_unlock(&dentry->d_lock);
51583 +
51584 + if (unlikely(retval == NULL)) {
51585 + /* real_root is pinned, we don't need to hold a reference */
51586 + read_lock(&gr_inode_lock);
51587 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
51588 + __get_dev(real_root.dentry), role);
51589 + read_unlock(&gr_inode_lock);
51590 + }
51591 +out:
51592 + br_read_unlock(vfsmount_lock);
51593 + write_sequnlock(&rename_lock);
51594 +
51595 + BUG_ON(retval == NULL);
51596 +
51597 + return retval;
51598 +}
51599 +
51600 +static void
51601 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
51602 +{
51603 + struct task_struct *task = current;
51604 + const struct cred *cred = current_cred();
51605 +
51606 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
51607 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
51608 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
51609 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
51610 +
51611 + return;
51612 +}
51613 +
51614 +static void
51615 +gr_log_learn_sysctl(const char *path, const __u32 mode)
51616 +{
51617 + struct task_struct *task = current;
51618 + const struct cred *cred = current_cred();
51619 +
51620 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
51621 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
51622 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
51623 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
51624 +
51625 + return;
51626 +}
51627 +
51628 +static void
51629 +gr_log_learn_id_change(const char type, const unsigned int real,
51630 + const unsigned int effective, const unsigned int fs)
51631 +{
51632 + struct task_struct *task = current;
51633 + const struct cred *cred = current_cred();
51634 +
51635 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
51636 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
51637 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
51638 + type, real, effective, fs, &task->signal->saved_ip);
51639 +
51640 + return;
51641 +}
51642 +
51643 +__u32
51644 +gr_search_file(const struct dentry * dentry, const __u32 mode,
51645 + const struct vfsmount * mnt)
51646 +{
51647 + __u32 retval = mode;
51648 + struct acl_subject_label *curracl;
51649 + struct acl_object_label *currobj;
51650 +
51651 + if (unlikely(!(gr_status & GR_READY)))
51652 + return (mode & ~GR_AUDITS);
51653 +
51654 + curracl = current->acl;
51655 +
51656 + currobj = chk_obj_label(dentry, mnt, curracl);
51657 + retval = currobj->mode & mode;
51658 +
51659 + /* if we're opening a specified transfer file for writing
51660 + (e.g. /dev/initctl), then transfer our role to init
51661 + */
51662 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
51663 + current->role->roletype & GR_ROLE_PERSIST)) {
51664 + struct task_struct *task = init_pid_ns.child_reaper;
51665 +
51666 + if (task->role != current->role) {
51667 + task->acl_sp_role = 0;
51668 + task->acl_role_id = current->acl_role_id;
51669 + task->role = current->role;
51670 + rcu_read_lock();
51671 + read_lock(&grsec_exec_file_lock);
51672 + gr_apply_subject_to_task(task);
51673 + read_unlock(&grsec_exec_file_lock);
51674 + rcu_read_unlock();
51675 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
51676 + }
51677 + }
51678 +
51679 + if (unlikely
51680 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
51681 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
51682 + __u32 new_mode = mode;
51683 +
51684 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
51685 +
51686 + retval = new_mode;
51687 +
51688 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
51689 + new_mode |= GR_INHERIT;
51690 +
51691 + if (!(mode & GR_NOLEARN))
51692 + gr_log_learn(dentry, mnt, new_mode);
51693 + }
51694 +
51695 + return retval;
51696 +}
51697 +
51698 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
51699 + const struct dentry *parent,
51700 + const struct vfsmount *mnt)
51701 +{
51702 + struct name_entry *match;
51703 + struct acl_object_label *matchpo;
51704 + struct acl_subject_label *curracl;
51705 + char *path;
51706 +
51707 + if (unlikely(!(gr_status & GR_READY)))
51708 + return NULL;
51709 +
51710 + preempt_disable();
51711 + path = gr_to_filename_rbac(new_dentry, mnt);
51712 + match = lookup_name_entry_create(path);
51713 +
51714 + curracl = current->acl;
51715 +
51716 + if (match) {
51717 + read_lock(&gr_inode_lock);
51718 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
51719 + read_unlock(&gr_inode_lock);
51720 +
51721 + if (matchpo) {
51722 + preempt_enable();
51723 + return matchpo;
51724 + }
51725 + }
51726 +
51727 + // lookup parent
51728 +
51729 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
51730 +
51731 + preempt_enable();
51732 + return matchpo;
51733 +}
51734 +
51735 +__u32
51736 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
51737 + const struct vfsmount * mnt, const __u32 mode)
51738 +{
51739 + struct acl_object_label *matchpo;
51740 + __u32 retval;
51741 +
51742 + if (unlikely(!(gr_status & GR_READY)))
51743 + return (mode & ~GR_AUDITS);
51744 +
51745 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
51746 +
51747 + retval = matchpo->mode & mode;
51748 +
51749 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
51750 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
51751 + __u32 new_mode = mode;
51752 +
51753 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
51754 +
51755 + gr_log_learn(new_dentry, mnt, new_mode);
51756 + return new_mode;
51757 + }
51758 +
51759 + return retval;
51760 +}
51761 +
51762 +__u32
51763 +gr_check_link(const struct dentry * new_dentry,
51764 + const struct dentry * parent_dentry,
51765 + const struct vfsmount * parent_mnt,
51766 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
51767 +{
51768 + struct acl_object_label *obj;
51769 + __u32 oldmode, newmode;
51770 + __u32 needmode;
51771 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
51772 + GR_DELETE | GR_INHERIT;
51773 +
51774 + if (unlikely(!(gr_status & GR_READY)))
51775 + return (GR_CREATE | GR_LINK);
51776 +
51777 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
51778 + oldmode = obj->mode;
51779 +
51780 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
51781 + newmode = obj->mode;
51782 +
51783 + needmode = newmode & checkmodes;
51784 +
51785 + // old name for hardlink must have at least the permissions of the new name
51786 + if ((oldmode & needmode) != needmode)
51787 + goto bad;
51788 +
51789 + // if old name had restrictions/auditing, make sure the new name does as well
51790 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
51791 +
51792 + // don't allow hardlinking of suid/sgid files without permission
51793 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
51794 + needmode |= GR_SETID;
51795 +
51796 + if ((newmode & needmode) != needmode)
51797 + goto bad;
51798 +
51799 + // enforce minimum permissions
51800 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
51801 + return newmode;
51802 +bad:
51803 + needmode = oldmode;
51804 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
51805 + needmode |= GR_SETID;
51806 +
51807 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
51808 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
51809 + return (GR_CREATE | GR_LINK);
51810 + } else if (newmode & GR_SUPPRESS)
51811 + return GR_SUPPRESS;
51812 + else
51813 + return 0;
51814 +}
51815 +
51816 +int
51817 +gr_check_hidden_task(const struct task_struct *task)
51818 +{
51819 + if (unlikely(!(gr_status & GR_READY)))
51820 + return 0;
51821 +
51822 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
51823 + return 1;
51824 +
51825 + return 0;
51826 +}
51827 +
51828 +int
51829 +gr_check_protected_task(const struct task_struct *task)
51830 +{
51831 + if (unlikely(!(gr_status & GR_READY) || !task))
51832 + return 0;
51833 +
51834 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
51835 + task->acl != current->acl)
51836 + return 1;
51837 +
51838 + return 0;
51839 +}
51840 +
51841 +int
51842 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
51843 +{
51844 + struct task_struct *p;
51845 + int ret = 0;
51846 +
51847 + if (unlikely(!(gr_status & GR_READY) || !pid))
51848 + return ret;
51849 +
51850 + read_lock(&tasklist_lock);
51851 + do_each_pid_task(pid, type, p) {
51852 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
51853 + p->acl != current->acl) {
51854 + ret = 1;
51855 + goto out;
51856 + }
51857 + } while_each_pid_task(pid, type, p);
51858 +out:
51859 + read_unlock(&tasklist_lock);
51860 +
51861 + return ret;
51862 +}
51863 +
51864 +void
51865 +gr_copy_label(struct task_struct *tsk)
51866 +{
51867 + /* plain copying of fields is already done by dup_task_struct */
51868 + tsk->signal->used_accept = 0;
51869 + tsk->acl_sp_role = 0;
51870 + //tsk->acl_role_id = current->acl_role_id;
51871 + //tsk->acl = current->acl;
51872 + //tsk->role = current->role;
51873 + tsk->signal->curr_ip = current->signal->curr_ip;
51874 + tsk->signal->saved_ip = current->signal->saved_ip;
51875 + if (current->exec_file)
51876 + get_file(current->exec_file);
51877 + //tsk->exec_file = current->exec_file;
51878 + //tsk->is_writable = current->is_writable;
51879 + if (unlikely(current->signal->used_accept)) {
51880 + current->signal->curr_ip = 0;
51881 + current->signal->saved_ip = 0;
51882 + }
51883 +
51884 + return;
51885 +}
51886 +
51887 +static void
51888 +gr_set_proc_res(struct task_struct *task)
51889 +{
51890 + struct acl_subject_label *proc;
51891 + unsigned short i;
51892 +
51893 + proc = task->acl;
51894 +
51895 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
51896 + return;
51897 +
51898 + for (i = 0; i < RLIM_NLIMITS; i++) {
51899 + if (!(proc->resmask & (1 << i)))
51900 + continue;
51901 +
51902 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
51903 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
51904 + }
51905 +
51906 + return;
51907 +}
51908 +
51909 +extern int __gr_process_user_ban(struct user_struct *user);
51910 +
51911 +int
51912 +gr_check_user_change(int real, int effective, int fs)
51913 +{
51914 + unsigned int i;
51915 + __u16 num;
51916 + uid_t *uidlist;
51917 + int curuid;
51918 + int realok = 0;
51919 + int effectiveok = 0;
51920 + int fsok = 0;
51921 +
51922 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
51923 + struct user_struct *user;
51924 +
51925 + if (real == -1)
51926 + goto skipit;
51927 +
51928 + user = find_user(real);
51929 + if (user == NULL)
51930 + goto skipit;
51931 +
51932 + if (__gr_process_user_ban(user)) {
51933 + /* for find_user */
51934 + free_uid(user);
51935 + return 1;
51936 + }
51937 +
51938 + /* for find_user */
51939 + free_uid(user);
51940 +
51941 +skipit:
51942 +#endif
51943 +
51944 + if (unlikely(!(gr_status & GR_READY)))
51945 + return 0;
51946 +
51947 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
51948 + gr_log_learn_id_change('u', real, effective, fs);
51949 +
51950 + num = current->acl->user_trans_num;
51951 + uidlist = current->acl->user_transitions;
51952 +
51953 + if (uidlist == NULL)
51954 + return 0;
51955 +
51956 + if (real == -1)
51957 + realok = 1;
51958 + if (effective == -1)
51959 + effectiveok = 1;
51960 + if (fs == -1)
51961 + fsok = 1;
51962 +
51963 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
51964 + for (i = 0; i < num; i++) {
51965 + curuid = (int)uidlist[i];
51966 + if (real == curuid)
51967 + realok = 1;
51968 + if (effective == curuid)
51969 + effectiveok = 1;
51970 + if (fs == curuid)
51971 + fsok = 1;
51972 + }
51973 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
51974 + for (i = 0; i < num; i++) {
51975 + curuid = (int)uidlist[i];
51976 + if (real == curuid)
51977 + break;
51978 + if (effective == curuid)
51979 + break;
51980 + if (fs == curuid)
51981 + break;
51982 + }
51983 + /* not in deny list */
51984 + if (i == num) {
51985 + realok = 1;
51986 + effectiveok = 1;
51987 + fsok = 1;
51988 + }
51989 + }
51990 +
51991 + if (realok && effectiveok && fsok)
51992 + return 0;
51993 + else {
51994 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
51995 + return 1;
51996 + }
51997 +}
51998 +
51999 +int
52000 +gr_check_group_change(int real, int effective, int fs)
52001 +{
52002 + unsigned int i;
52003 + __u16 num;
52004 + gid_t *gidlist;
52005 + int curgid;
52006 + int realok = 0;
52007 + int effectiveok = 0;
52008 + int fsok = 0;
52009 +
52010 + if (unlikely(!(gr_status & GR_READY)))
52011 + return 0;
52012 +
52013 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52014 + gr_log_learn_id_change('g', real, effective, fs);
52015 +
52016 + num = current->acl->group_trans_num;
52017 + gidlist = current->acl->group_transitions;
52018 +
52019 + if (gidlist == NULL)
52020 + return 0;
52021 +
52022 + if (real == -1)
52023 + realok = 1;
52024 + if (effective == -1)
52025 + effectiveok = 1;
52026 + if (fs == -1)
52027 + fsok = 1;
52028 +
52029 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
52030 + for (i = 0; i < num; i++) {
52031 + curgid = (int)gidlist[i];
52032 + if (real == curgid)
52033 + realok = 1;
52034 + if (effective == curgid)
52035 + effectiveok = 1;
52036 + if (fs == curgid)
52037 + fsok = 1;
52038 + }
52039 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
52040 + for (i = 0; i < num; i++) {
52041 + curgid = (int)gidlist[i];
52042 + if (real == curgid)
52043 + break;
52044 + if (effective == curgid)
52045 + break;
52046 + if (fs == curgid)
52047 + break;
52048 + }
52049 + /* not in deny list */
52050 + if (i == num) {
52051 + realok = 1;
52052 + effectiveok = 1;
52053 + fsok = 1;
52054 + }
52055 + }
52056 +
52057 + if (realok && effectiveok && fsok)
52058 + return 0;
52059 + else {
52060 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
52061 + return 1;
52062 + }
52063 +}
52064 +
52065 +extern int gr_acl_is_capable(const int cap);
52066 +
52067 +void
52068 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
52069 +{
52070 + struct acl_role_label *role = task->role;
52071 + struct acl_subject_label *subj = NULL;
52072 + struct acl_object_label *obj;
52073 + struct file *filp;
52074 +
52075 + if (unlikely(!(gr_status & GR_READY)))
52076 + return;
52077 +
52078 + filp = task->exec_file;
52079 +
52080 + /* kernel process, we'll give them the kernel role */
52081 + if (unlikely(!filp)) {
52082 + task->role = kernel_role;
52083 + task->acl = kernel_role->root_label;
52084 + return;
52085 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
52086 + role = lookup_acl_role_label(task, uid, gid);
52087 +
52088 + /* don't change the role if we're not a privileged process */
52089 + if (role && task->role != role &&
52090 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
52091 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
52092 + return;
52093 +
52094 + /* perform subject lookup in possibly new role
52095 + we can use this result below in the case where role == task->role
52096 + */
52097 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
52098 +
52099 + /* if we changed uid/gid, but result in the same role
52100 + and are using inheritance, don't lose the inherited subject
52101 + if current subject is other than what normal lookup
52102 + would result in, we arrived via inheritance, don't
52103 + lose subject
52104 + */
52105 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
52106 + (subj == task->acl)))
52107 + task->acl = subj;
52108 +
52109 + task->role = role;
52110 +
52111 + task->is_writable = 0;
52112 +
52113 + /* ignore additional mmap checks for processes that are writable
52114 + by the default ACL */
52115 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52116 + if (unlikely(obj->mode & GR_WRITE))
52117 + task->is_writable = 1;
52118 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
52119 + if (unlikely(obj->mode & GR_WRITE))
52120 + task->is_writable = 1;
52121 +
52122 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52123 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52124 +#endif
52125 +
52126 + gr_set_proc_res(task);
52127 +
52128 + return;
52129 +}
52130 +
52131 +int
52132 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
52133 + const int unsafe_flags)
52134 +{
52135 + struct task_struct *task = current;
52136 + struct acl_subject_label *newacl;
52137 + struct acl_object_label *obj;
52138 + __u32 retmode;
52139 +
52140 + if (unlikely(!(gr_status & GR_READY)))
52141 + return 0;
52142 +
52143 + newacl = chk_subj_label(dentry, mnt, task->role);
52144 +
52145 + task_lock(task);
52146 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
52147 + !(task->role->roletype & GR_ROLE_GOD) &&
52148 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
52149 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52150 + task_unlock(task);
52151 + if (unsafe_flags & LSM_UNSAFE_SHARE)
52152 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
52153 + else
52154 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
52155 + return -EACCES;
52156 + }
52157 + task_unlock(task);
52158 +
52159 + obj = chk_obj_label(dentry, mnt, task->acl);
52160 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
52161 +
52162 + if (!(task->acl->mode & GR_INHERITLEARN) &&
52163 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
52164 + if (obj->nested)
52165 + task->acl = obj->nested;
52166 + else
52167 + task->acl = newacl;
52168 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
52169 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
52170 +
52171 + task->is_writable = 0;
52172 +
52173 + /* ignore additional mmap checks for processes that are writable
52174 + by the default ACL */
52175 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
52176 + if (unlikely(obj->mode & GR_WRITE))
52177 + task->is_writable = 1;
52178 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
52179 + if (unlikely(obj->mode & GR_WRITE))
52180 + task->is_writable = 1;
52181 +
52182 + gr_set_proc_res(task);
52183 +
52184 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52185 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52186 +#endif
52187 + return 0;
52188 +}
52189 +
52190 +/* always called with valid inodev ptr */
52191 +static void
52192 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
52193 +{
52194 + struct acl_object_label *matchpo;
52195 + struct acl_subject_label *matchps;
52196 + struct acl_subject_label *subj;
52197 + struct acl_role_label *role;
52198 + unsigned int x;
52199 +
52200 + FOR_EACH_ROLE_START(role)
52201 + FOR_EACH_SUBJECT_START(role, subj, x)
52202 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
52203 + matchpo->mode |= GR_DELETED;
52204 + FOR_EACH_SUBJECT_END(subj,x)
52205 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
52206 + if (subj->inode == ino && subj->device == dev)
52207 + subj->mode |= GR_DELETED;
52208 + FOR_EACH_NESTED_SUBJECT_END(subj)
52209 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
52210 + matchps->mode |= GR_DELETED;
52211 + FOR_EACH_ROLE_END(role)
52212 +
52213 + inodev->nentry->deleted = 1;
52214 +
52215 + return;
52216 +}
52217 +
52218 +void
52219 +gr_handle_delete(const ino_t ino, const dev_t dev)
52220 +{
52221 + struct inodev_entry *inodev;
52222 +
52223 + if (unlikely(!(gr_status & GR_READY)))
52224 + return;
52225 +
52226 + write_lock(&gr_inode_lock);
52227 + inodev = lookup_inodev_entry(ino, dev);
52228 + if (inodev != NULL)
52229 + do_handle_delete(inodev, ino, dev);
52230 + write_unlock(&gr_inode_lock);
52231 +
52232 + return;
52233 +}
52234 +
52235 +static void
52236 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
52237 + const ino_t newinode, const dev_t newdevice,
52238 + struct acl_subject_label *subj)
52239 +{
52240 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
52241 + struct acl_object_label *match;
52242 +
52243 + match = subj->obj_hash[index];
52244 +
52245 + while (match && (match->inode != oldinode ||
52246 + match->device != olddevice ||
52247 + !(match->mode & GR_DELETED)))
52248 + match = match->next;
52249 +
52250 + if (match && (match->inode == oldinode)
52251 + && (match->device == olddevice)
52252 + && (match->mode & GR_DELETED)) {
52253 + if (match->prev == NULL) {
52254 + subj->obj_hash[index] = match->next;
52255 + if (match->next != NULL)
52256 + match->next->prev = NULL;
52257 + } else {
52258 + match->prev->next = match->next;
52259 + if (match->next != NULL)
52260 + match->next->prev = match->prev;
52261 + }
52262 + match->prev = NULL;
52263 + match->next = NULL;
52264 + match->inode = newinode;
52265 + match->device = newdevice;
52266 + match->mode &= ~GR_DELETED;
52267 +
52268 + insert_acl_obj_label(match, subj);
52269 + }
52270 +
52271 + return;
52272 +}
52273 +
52274 +static void
52275 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
52276 + const ino_t newinode, const dev_t newdevice,
52277 + struct acl_role_label *role)
52278 +{
52279 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
52280 + struct acl_subject_label *match;
52281 +
52282 + match = role->subj_hash[index];
52283 +
52284 + while (match && (match->inode != oldinode ||
52285 + match->device != olddevice ||
52286 + !(match->mode & GR_DELETED)))
52287 + match = match->next;
52288 +
52289 + if (match && (match->inode == oldinode)
52290 + && (match->device == olddevice)
52291 + && (match->mode & GR_DELETED)) {
52292 + if (match->prev == NULL) {
52293 + role->subj_hash[index] = match->next;
52294 + if (match->next != NULL)
52295 + match->next->prev = NULL;
52296 + } else {
52297 + match->prev->next = match->next;
52298 + if (match->next != NULL)
52299 + match->next->prev = match->prev;
52300 + }
52301 + match->prev = NULL;
52302 + match->next = NULL;
52303 + match->inode = newinode;
52304 + match->device = newdevice;
52305 + match->mode &= ~GR_DELETED;
52306 +
52307 + insert_acl_subj_label(match, role);
52308 + }
52309 +
52310 + return;
52311 +}
52312 +
52313 +static void
52314 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
52315 + const ino_t newinode, const dev_t newdevice)
52316 +{
52317 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
52318 + struct inodev_entry *match;
52319 +
52320 + match = inodev_set.i_hash[index];
52321 +
52322 + while (match && (match->nentry->inode != oldinode ||
52323 + match->nentry->device != olddevice || !match->nentry->deleted))
52324 + match = match->next;
52325 +
52326 + if (match && (match->nentry->inode == oldinode)
52327 + && (match->nentry->device == olddevice) &&
52328 + match->nentry->deleted) {
52329 + if (match->prev == NULL) {
52330 + inodev_set.i_hash[index] = match->next;
52331 + if (match->next != NULL)
52332 + match->next->prev = NULL;
52333 + } else {
52334 + match->prev->next = match->next;
52335 + if (match->next != NULL)
52336 + match->next->prev = match->prev;
52337 + }
52338 + match->prev = NULL;
52339 + match->next = NULL;
52340 + match->nentry->inode = newinode;
52341 + match->nentry->device = newdevice;
52342 + match->nentry->deleted = 0;
52343 +
52344 + insert_inodev_entry(match);
52345 + }
52346 +
52347 + return;
52348 +}
52349 +
52350 +static void
52351 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
52352 +{
52353 + struct acl_subject_label *subj;
52354 + struct acl_role_label *role;
52355 + unsigned int x;
52356 +
52357 + FOR_EACH_ROLE_START(role)
52358 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
52359 +
52360 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
52361 + if ((subj->inode == ino) && (subj->device == dev)) {
52362 + subj->inode = ino;
52363 + subj->device = dev;
52364 + }
52365 + FOR_EACH_NESTED_SUBJECT_END(subj)
52366 + FOR_EACH_SUBJECT_START(role, subj, x)
52367 + update_acl_obj_label(matchn->inode, matchn->device,
52368 + ino, dev, subj);
52369 + FOR_EACH_SUBJECT_END(subj,x)
52370 + FOR_EACH_ROLE_END(role)
52371 +
52372 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
52373 +
52374 + return;
52375 +}
52376 +
52377 +static void
52378 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
52379 + const struct vfsmount *mnt)
52380 +{
52381 + ino_t ino = dentry->d_inode->i_ino;
52382 + dev_t dev = __get_dev(dentry);
52383 +
52384 + __do_handle_create(matchn, ino, dev);
52385 +
52386 + return;
52387 +}
52388 +
52389 +void
52390 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
52391 +{
52392 + struct name_entry *matchn;
52393 +
52394 + if (unlikely(!(gr_status & GR_READY)))
52395 + return;
52396 +
52397 + preempt_disable();
52398 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
52399 +
52400 + if (unlikely((unsigned long)matchn)) {
52401 + write_lock(&gr_inode_lock);
52402 + do_handle_create(matchn, dentry, mnt);
52403 + write_unlock(&gr_inode_lock);
52404 + }
52405 + preempt_enable();
52406 +
52407 + return;
52408 +}
52409 +
52410 +void
52411 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
52412 +{
52413 + struct name_entry *matchn;
52414 +
52415 + if (unlikely(!(gr_status & GR_READY)))
52416 + return;
52417 +
52418 + preempt_disable();
52419 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
52420 +
52421 + if (unlikely((unsigned long)matchn)) {
52422 + write_lock(&gr_inode_lock);
52423 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
52424 + write_unlock(&gr_inode_lock);
52425 + }
52426 + preempt_enable();
52427 +
52428 + return;
52429 +}
52430 +
52431 +void
52432 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
52433 + struct dentry *old_dentry,
52434 + struct dentry *new_dentry,
52435 + struct vfsmount *mnt, const __u8 replace)
52436 +{
52437 + struct name_entry *matchn;
52438 + struct inodev_entry *inodev;
52439 + struct inode *inode = new_dentry->d_inode;
52440 + ino_t old_ino = old_dentry->d_inode->i_ino;
52441 + dev_t old_dev = __get_dev(old_dentry);
52442 +
52443 + /* vfs_rename swaps the name and parent link for old_dentry and
52444 + new_dentry
52445 + at this point, old_dentry has the new name, parent link, and inode
52446 + for the renamed file
52447 + if a file is being replaced by a rename, new_dentry has the inode
52448 + and name for the replaced file
52449 + */
52450 +
52451 + if (unlikely(!(gr_status & GR_READY)))
52452 + return;
52453 +
52454 + preempt_disable();
52455 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
52456 +
52457 + /* we wouldn't have to check d_inode if it weren't for
52458 + NFS silly-renaming
52459 + */
52460 +
52461 + write_lock(&gr_inode_lock);
52462 + if (unlikely(replace && inode)) {
52463 + ino_t new_ino = inode->i_ino;
52464 + dev_t new_dev = __get_dev(new_dentry);
52465 +
52466 + inodev = lookup_inodev_entry(new_ino, new_dev);
52467 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
52468 + do_handle_delete(inodev, new_ino, new_dev);
52469 + }
52470 +
52471 + inodev = lookup_inodev_entry(old_ino, old_dev);
52472 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
52473 + do_handle_delete(inodev, old_ino, old_dev);
52474 +
52475 + if (unlikely((unsigned long)matchn))
52476 + do_handle_create(matchn, old_dentry, mnt);
52477 +
52478 + write_unlock(&gr_inode_lock);
52479 + preempt_enable();
52480 +
52481 + return;
52482 +}
52483 +
52484 +static int
52485 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
52486 + unsigned char **sum)
52487 +{
52488 + struct acl_role_label *r;
52489 + struct role_allowed_ip *ipp;
52490 + struct role_transition *trans;
52491 + unsigned int i;
52492 + int found = 0;
52493 + u32 curr_ip = current->signal->curr_ip;
52494 +
52495 + current->signal->saved_ip = curr_ip;
52496 +
52497 + /* check transition table */
52498 +
52499 + for (trans = current->role->transitions; trans; trans = trans->next) {
52500 + if (!strcmp(rolename, trans->rolename)) {
52501 + found = 1;
52502 + break;
52503 + }
52504 + }
52505 +
52506 + if (!found)
52507 + return 0;
52508 +
52509 + /* handle special roles that do not require authentication
52510 + and check ip */
52511 +
52512 + FOR_EACH_ROLE_START(r)
52513 + if (!strcmp(rolename, r->rolename) &&
52514 + (r->roletype & GR_ROLE_SPECIAL)) {
52515 + found = 0;
52516 + if (r->allowed_ips != NULL) {
52517 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
52518 + if ((ntohl(curr_ip) & ipp->netmask) ==
52519 + (ntohl(ipp->addr) & ipp->netmask))
52520 + found = 1;
52521 + }
52522 + } else
52523 + found = 2;
52524 + if (!found)
52525 + return 0;
52526 +
52527 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
52528 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
52529 + *salt = NULL;
52530 + *sum = NULL;
52531 + return 1;
52532 + }
52533 + }
52534 + FOR_EACH_ROLE_END(r)
52535 +
52536 + for (i = 0; i < num_sprole_pws; i++) {
52537 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
52538 + *salt = acl_special_roles[i]->salt;
52539 + *sum = acl_special_roles[i]->sum;
52540 + return 1;
52541 + }
52542 + }
52543 +
52544 + return 0;
52545 +}
52546 +
52547 +static void
52548 +assign_special_role(char *rolename)
52549 +{
52550 + struct acl_object_label *obj;
52551 + struct acl_role_label *r;
52552 + struct acl_role_label *assigned = NULL;
52553 + struct task_struct *tsk;
52554 + struct file *filp;
52555 +
52556 + FOR_EACH_ROLE_START(r)
52557 + if (!strcmp(rolename, r->rolename) &&
52558 + (r->roletype & GR_ROLE_SPECIAL)) {
52559 + assigned = r;
52560 + break;
52561 + }
52562 + FOR_EACH_ROLE_END(r)
52563 +
52564 + if (!assigned)
52565 + return;
52566 +
52567 + read_lock(&tasklist_lock);
52568 + read_lock(&grsec_exec_file_lock);
52569 +
52570 + tsk = current->real_parent;
52571 + if (tsk == NULL)
52572 + goto out_unlock;
52573 +
52574 + filp = tsk->exec_file;
52575 + if (filp == NULL)
52576 + goto out_unlock;
52577 +
52578 + tsk->is_writable = 0;
52579 +
52580 + tsk->acl_sp_role = 1;
52581 + tsk->acl_role_id = ++acl_sp_role_value;
52582 + tsk->role = assigned;
52583 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
52584 +
52585 + /* ignore additional mmap checks for processes that are writable
52586 + by the default ACL */
52587 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52588 + if (unlikely(obj->mode & GR_WRITE))
52589 + tsk->is_writable = 1;
52590 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
52591 + if (unlikely(obj->mode & GR_WRITE))
52592 + tsk->is_writable = 1;
52593 +
52594 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52595 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
52596 +#endif
52597 +
52598 +out_unlock:
52599 + read_unlock(&grsec_exec_file_lock);
52600 + read_unlock(&tasklist_lock);
52601 + return;
52602 +}
52603 +
52604 +int gr_check_secure_terminal(struct task_struct *task)
52605 +{
52606 + struct task_struct *p, *p2, *p3;
52607 + struct files_struct *files;
52608 + struct fdtable *fdt;
52609 + struct file *our_file = NULL, *file;
52610 + int i;
52611 +
52612 + if (task->signal->tty == NULL)
52613 + return 1;
52614 +
52615 + files = get_files_struct(task);
52616 + if (files != NULL) {
52617 + rcu_read_lock();
52618 + fdt = files_fdtable(files);
52619 + for (i=0; i < fdt->max_fds; i++) {
52620 + file = fcheck_files(files, i);
52621 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
52622 + get_file(file);
52623 + our_file = file;
52624 + }
52625 + }
52626 + rcu_read_unlock();
52627 + put_files_struct(files);
52628 + }
52629 +
52630 + if (our_file == NULL)
52631 + return 1;
52632 +
52633 + read_lock(&tasklist_lock);
52634 + do_each_thread(p2, p) {
52635 + files = get_files_struct(p);
52636 + if (files == NULL ||
52637 + (p->signal && p->signal->tty == task->signal->tty)) {
52638 + if (files != NULL)
52639 + put_files_struct(files);
52640 + continue;
52641 + }
52642 + rcu_read_lock();
52643 + fdt = files_fdtable(files);
52644 + for (i=0; i < fdt->max_fds; i++) {
52645 + file = fcheck_files(files, i);
52646 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
52647 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
52648 + p3 = task;
52649 + while (p3->pid > 0) {
52650 + if (p3 == p)
52651 + break;
52652 + p3 = p3->real_parent;
52653 + }
52654 + if (p3 == p)
52655 + break;
52656 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
52657 + gr_handle_alertkill(p);
52658 + rcu_read_unlock();
52659 + put_files_struct(files);
52660 + read_unlock(&tasklist_lock);
52661 + fput(our_file);
52662 + return 0;
52663 + }
52664 + }
52665 + rcu_read_unlock();
52666 + put_files_struct(files);
52667 + } while_each_thread(p2, p);
52668 + read_unlock(&tasklist_lock);
52669 +
52670 + fput(our_file);
52671 + return 1;
52672 +}
52673 +
52674 +ssize_t
52675 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
52676 +{
52677 + struct gr_arg_wrapper uwrap;
52678 + unsigned char *sprole_salt = NULL;
52679 + unsigned char *sprole_sum = NULL;
52680 + int error = sizeof (struct gr_arg_wrapper);
52681 + int error2 = 0;
52682 +
52683 + mutex_lock(&gr_dev_mutex);
52684 +
52685 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
52686 + error = -EPERM;
52687 + goto out;
52688 + }
52689 +
52690 + if (count != sizeof (struct gr_arg_wrapper)) {
52691 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
52692 + error = -EINVAL;
52693 + goto out;
52694 + }
52695 +
52696 +
52697 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
52698 + gr_auth_expires = 0;
52699 + gr_auth_attempts = 0;
52700 + }
52701 +
52702 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
52703 + error = -EFAULT;
52704 + goto out;
52705 + }
52706 +
52707 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
52708 + error = -EINVAL;
52709 + goto out;
52710 + }
52711 +
52712 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
52713 + error = -EFAULT;
52714 + goto out;
52715 + }
52716 +
52717 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
52718 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
52719 + time_after(gr_auth_expires, get_seconds())) {
52720 + error = -EBUSY;
52721 + goto out;
52722 + }
52723 +
52724 + /* if non-root trying to do anything other than use a special role,
52725 + do not attempt authentication, do not count towards authentication
52726 + locking
52727 + */
52728 +
52729 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
52730 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
52731 + current_uid()) {
52732 + error = -EPERM;
52733 + goto out;
52734 + }
52735 +
52736 + /* ensure pw and special role name are null terminated */
52737 +
52738 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
52739 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
52740 +
52741 + /* Okay.
52742 + * We have our enough of the argument structure..(we have yet
52743 + * to copy_from_user the tables themselves) . Copy the tables
52744 + * only if we need them, i.e. for loading operations. */
52745 +
52746 + switch (gr_usermode->mode) {
52747 + case GR_STATUS:
52748 + if (gr_status & GR_READY) {
52749 + error = 1;
52750 + if (!gr_check_secure_terminal(current))
52751 + error = 3;
52752 + } else
52753 + error = 2;
52754 + goto out;
52755 + case GR_SHUTDOWN:
52756 + if ((gr_status & GR_READY)
52757 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
52758 + pax_open_kernel();
52759 + gr_status &= ~GR_READY;
52760 + pax_close_kernel();
52761 +
52762 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
52763 + free_variables();
52764 + memset(gr_usermode, 0, sizeof (struct gr_arg));
52765 + memset(gr_system_salt, 0, GR_SALT_LEN);
52766 + memset(gr_system_sum, 0, GR_SHA_LEN);
52767 + } else if (gr_status & GR_READY) {
52768 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
52769 + error = -EPERM;
52770 + } else {
52771 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
52772 + error = -EAGAIN;
52773 + }
52774 + break;
52775 + case GR_ENABLE:
52776 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
52777 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
52778 + else {
52779 + if (gr_status & GR_READY)
52780 + error = -EAGAIN;
52781 + else
52782 + error = error2;
52783 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
52784 + }
52785 + break;
52786 + case GR_RELOAD:
52787 + if (!(gr_status & GR_READY)) {
52788 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
52789 + error = -EAGAIN;
52790 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
52791 + preempt_disable();
52792 +
52793 + pax_open_kernel();
52794 + gr_status &= ~GR_READY;
52795 + pax_close_kernel();
52796 +
52797 + free_variables();
52798 + if (!(error2 = gracl_init(gr_usermode))) {
52799 + preempt_enable();
52800 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
52801 + } else {
52802 + preempt_enable();
52803 + error = error2;
52804 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
52805 + }
52806 + } else {
52807 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
52808 + error = -EPERM;
52809 + }
52810 + break;
52811 + case GR_SEGVMOD:
52812 + if (unlikely(!(gr_status & GR_READY))) {
52813 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
52814 + error = -EAGAIN;
52815 + break;
52816 + }
52817 +
52818 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
52819 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
52820 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
52821 + struct acl_subject_label *segvacl;
52822 + segvacl =
52823 + lookup_acl_subj_label(gr_usermode->segv_inode,
52824 + gr_usermode->segv_device,
52825 + current->role);
52826 + if (segvacl) {
52827 + segvacl->crashes = 0;
52828 + segvacl->expires = 0;
52829 + }
52830 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
52831 + gr_remove_uid(gr_usermode->segv_uid);
52832 + }
52833 + } else {
52834 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
52835 + error = -EPERM;
52836 + }
52837 + break;
52838 + case GR_SPROLE:
52839 + case GR_SPROLEPAM:
52840 + if (unlikely(!(gr_status & GR_READY))) {
52841 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
52842 + error = -EAGAIN;
52843 + break;
52844 + }
52845 +
52846 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
52847 + current->role->expires = 0;
52848 + current->role->auth_attempts = 0;
52849 + }
52850 +
52851 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
52852 + time_after(current->role->expires, get_seconds())) {
52853 + error = -EBUSY;
52854 + goto out;
52855 + }
52856 +
52857 + if (lookup_special_role_auth
52858 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
52859 + && ((!sprole_salt && !sprole_sum)
52860 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
52861 + char *p = "";
52862 + assign_special_role(gr_usermode->sp_role);
52863 + read_lock(&tasklist_lock);
52864 + if (current->real_parent)
52865 + p = current->real_parent->role->rolename;
52866 + read_unlock(&tasklist_lock);
52867 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
52868 + p, acl_sp_role_value);
52869 + } else {
52870 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
52871 + error = -EPERM;
52872 + if(!(current->role->auth_attempts++))
52873 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
52874 +
52875 + goto out;
52876 + }
52877 + break;
52878 + case GR_UNSPROLE:
52879 + if (unlikely(!(gr_status & GR_READY))) {
52880 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
52881 + error = -EAGAIN;
52882 + break;
52883 + }
52884 +
52885 + if (current->role->roletype & GR_ROLE_SPECIAL) {
52886 + char *p = "";
52887 + int i = 0;
52888 +
52889 + read_lock(&tasklist_lock);
52890 + if (current->real_parent) {
52891 + p = current->real_parent->role->rolename;
52892 + i = current->real_parent->acl_role_id;
52893 + }
52894 + read_unlock(&tasklist_lock);
52895 +
52896 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
52897 + gr_set_acls(1);
52898 + } else {
52899 + error = -EPERM;
52900 + goto out;
52901 + }
52902 + break;
52903 + default:
52904 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
52905 + error = -EINVAL;
52906 + break;
52907 + }
52908 +
52909 + if (error != -EPERM)
52910 + goto out;
52911 +
52912 + if(!(gr_auth_attempts++))
52913 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
52914 +
52915 + out:
52916 + mutex_unlock(&gr_dev_mutex);
52917 + return error;
52918 +}
52919 +
52920 +/* must be called with
52921 + rcu_read_lock();
52922 + read_lock(&tasklist_lock);
52923 + read_lock(&grsec_exec_file_lock);
52924 +*/
52925 +int gr_apply_subject_to_task(struct task_struct *task)
52926 +{
52927 + struct acl_object_label *obj;
52928 + char *tmpname;
52929 + struct acl_subject_label *tmpsubj;
52930 + struct file *filp;
52931 + struct name_entry *nmatch;
52932 +
52933 + filp = task->exec_file;
52934 + if (filp == NULL)
52935 + return 0;
52936 +
52937 + /* the following is to apply the correct subject
52938 + on binaries running when the RBAC system
52939 + is enabled, when the binaries have been
52940 + replaced or deleted since their execution
52941 + -----
52942 + when the RBAC system starts, the inode/dev
52943 + from exec_file will be one the RBAC system
52944 + is unaware of. It only knows the inode/dev
52945 + of the present file on disk, or the absence
52946 + of it.
52947 + */
52948 + preempt_disable();
52949 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
52950 +
52951 + nmatch = lookup_name_entry(tmpname);
52952 + preempt_enable();
52953 + tmpsubj = NULL;
52954 + if (nmatch) {
52955 + if (nmatch->deleted)
52956 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
52957 + else
52958 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
52959 + if (tmpsubj != NULL)
52960 + task->acl = tmpsubj;
52961 + }
52962 + if (tmpsubj == NULL)
52963 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
52964 + task->role);
52965 + if (task->acl) {
52966 + task->is_writable = 0;
52967 + /* ignore additional mmap checks for processes that are writable
52968 + by the default ACL */
52969 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52970 + if (unlikely(obj->mode & GR_WRITE))
52971 + task->is_writable = 1;
52972 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
52973 + if (unlikely(obj->mode & GR_WRITE))
52974 + task->is_writable = 1;
52975 +
52976 + gr_set_proc_res(task);
52977 +
52978 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52979 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52980 +#endif
52981 + } else {
52982 + return 1;
52983 + }
52984 +
52985 + return 0;
52986 +}
52987 +
52988 +int
52989 +gr_set_acls(const int type)
52990 +{
52991 + struct task_struct *task, *task2;
52992 + struct acl_role_label *role = current->role;
52993 + __u16 acl_role_id = current->acl_role_id;
52994 + const struct cred *cred;
52995 + int ret;
52996 +
52997 + rcu_read_lock();
52998 + read_lock(&tasklist_lock);
52999 + read_lock(&grsec_exec_file_lock);
53000 + do_each_thread(task2, task) {
53001 + /* check to see if we're called from the exit handler,
53002 + if so, only replace ACLs that have inherited the admin
53003 + ACL */
53004 +
53005 + if (type && (task->role != role ||
53006 + task->acl_role_id != acl_role_id))
53007 + continue;
53008 +
53009 + task->acl_role_id = 0;
53010 + task->acl_sp_role = 0;
53011 +
53012 + if (task->exec_file) {
53013 + cred = __task_cred(task);
53014 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
53015 + ret = gr_apply_subject_to_task(task);
53016 + if (ret) {
53017 + read_unlock(&grsec_exec_file_lock);
53018 + read_unlock(&tasklist_lock);
53019 + rcu_read_unlock();
53020 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
53021 + return ret;
53022 + }
53023 + } else {
53024 + // it's a kernel process
53025 + task->role = kernel_role;
53026 + task->acl = kernel_role->root_label;
53027 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
53028 + task->acl->mode &= ~GR_PROCFIND;
53029 +#endif
53030 + }
53031 + } while_each_thread(task2, task);
53032 + read_unlock(&grsec_exec_file_lock);
53033 + read_unlock(&tasklist_lock);
53034 + rcu_read_unlock();
53035 +
53036 + return 0;
53037 +}
53038 +
53039 +void
53040 +gr_learn_resource(const struct task_struct *task,
53041 + const int res, const unsigned long wanted, const int gt)
53042 +{
53043 + struct acl_subject_label *acl;
53044 + const struct cred *cred;
53045 +
53046 + if (unlikely((gr_status & GR_READY) &&
53047 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
53048 + goto skip_reslog;
53049 +
53050 +#ifdef CONFIG_GRKERNSEC_RESLOG
53051 + gr_log_resource(task, res, wanted, gt);
53052 +#endif
53053 + skip_reslog:
53054 +
53055 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
53056 + return;
53057 +
53058 + acl = task->acl;
53059 +
53060 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
53061 + !(acl->resmask & (1 << (unsigned short) res))))
53062 + return;
53063 +
53064 + if (wanted >= acl->res[res].rlim_cur) {
53065 + unsigned long res_add;
53066 +
53067 + res_add = wanted;
53068 + switch (res) {
53069 + case RLIMIT_CPU:
53070 + res_add += GR_RLIM_CPU_BUMP;
53071 + break;
53072 + case RLIMIT_FSIZE:
53073 + res_add += GR_RLIM_FSIZE_BUMP;
53074 + break;
53075 + case RLIMIT_DATA:
53076 + res_add += GR_RLIM_DATA_BUMP;
53077 + break;
53078 + case RLIMIT_STACK:
53079 + res_add += GR_RLIM_STACK_BUMP;
53080 + break;
53081 + case RLIMIT_CORE:
53082 + res_add += GR_RLIM_CORE_BUMP;
53083 + break;
53084 + case RLIMIT_RSS:
53085 + res_add += GR_RLIM_RSS_BUMP;
53086 + break;
53087 + case RLIMIT_NPROC:
53088 + res_add += GR_RLIM_NPROC_BUMP;
53089 + break;
53090 + case RLIMIT_NOFILE:
53091 + res_add += GR_RLIM_NOFILE_BUMP;
53092 + break;
53093 + case RLIMIT_MEMLOCK:
53094 + res_add += GR_RLIM_MEMLOCK_BUMP;
53095 + break;
53096 + case RLIMIT_AS:
53097 + res_add += GR_RLIM_AS_BUMP;
53098 + break;
53099 + case RLIMIT_LOCKS:
53100 + res_add += GR_RLIM_LOCKS_BUMP;
53101 + break;
53102 + case RLIMIT_SIGPENDING:
53103 + res_add += GR_RLIM_SIGPENDING_BUMP;
53104 + break;
53105 + case RLIMIT_MSGQUEUE:
53106 + res_add += GR_RLIM_MSGQUEUE_BUMP;
53107 + break;
53108 + case RLIMIT_NICE:
53109 + res_add += GR_RLIM_NICE_BUMP;
53110 + break;
53111 + case RLIMIT_RTPRIO:
53112 + res_add += GR_RLIM_RTPRIO_BUMP;
53113 + break;
53114 + case RLIMIT_RTTIME:
53115 + res_add += GR_RLIM_RTTIME_BUMP;
53116 + break;
53117 + }
53118 +
53119 + acl->res[res].rlim_cur = res_add;
53120 +
53121 + if (wanted > acl->res[res].rlim_max)
53122 + acl->res[res].rlim_max = res_add;
53123 +
53124 + /* only log the subject filename, since resource logging is supported for
53125 + single-subject learning only */
53126 + rcu_read_lock();
53127 + cred = __task_cred(task);
53128 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
53129 + task->role->roletype, cred->uid, cred->gid, acl->filename,
53130 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
53131 + "", (unsigned long) res, &task->signal->saved_ip);
53132 + rcu_read_unlock();
53133 + }
53134 +
53135 + return;
53136 +}
53137 +
53138 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
53139 +void
53140 +pax_set_initial_flags(struct linux_binprm *bprm)
53141 +{
53142 + struct task_struct *task = current;
53143 + struct acl_subject_label *proc;
53144 + unsigned long flags;
53145 +
53146 + if (unlikely(!(gr_status & GR_READY)))
53147 + return;
53148 +
53149 + flags = pax_get_flags(task);
53150 +
53151 + proc = task->acl;
53152 +
53153 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
53154 + flags &= ~MF_PAX_PAGEEXEC;
53155 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
53156 + flags &= ~MF_PAX_SEGMEXEC;
53157 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
53158 + flags &= ~MF_PAX_RANDMMAP;
53159 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
53160 + flags &= ~MF_PAX_EMUTRAMP;
53161 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
53162 + flags &= ~MF_PAX_MPROTECT;
53163 +
53164 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
53165 + flags |= MF_PAX_PAGEEXEC;
53166 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
53167 + flags |= MF_PAX_SEGMEXEC;
53168 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
53169 + flags |= MF_PAX_RANDMMAP;
53170 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
53171 + flags |= MF_PAX_EMUTRAMP;
53172 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
53173 + flags |= MF_PAX_MPROTECT;
53174 +
53175 + pax_set_flags(task, flags);
53176 +
53177 + return;
53178 +}
53179 +#endif
53180 +
53181 +#ifdef CONFIG_SYSCTL
53182 +/* Eric Biederman likes breaking userland ABI and every inode-based security
53183 + system to save 35kb of memory */
53184 +
53185 +/* we modify the passed in filename, but adjust it back before returning */
53186 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
53187 +{
53188 + struct name_entry *nmatch;
53189 + char *p, *lastp = NULL;
53190 + struct acl_object_label *obj = NULL, *tmp;
53191 + struct acl_subject_label *tmpsubj;
53192 + char c = '\0';
53193 +
53194 + read_lock(&gr_inode_lock);
53195 +
53196 + p = name + len - 1;
53197 + do {
53198 + nmatch = lookup_name_entry(name);
53199 + if (lastp != NULL)
53200 + *lastp = c;
53201 +
53202 + if (nmatch == NULL)
53203 + goto next_component;
53204 + tmpsubj = current->acl;
53205 + do {
53206 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
53207 + if (obj != NULL) {
53208 + tmp = obj->globbed;
53209 + while (tmp) {
53210 + if (!glob_match(tmp->filename, name)) {
53211 + obj = tmp;
53212 + goto found_obj;
53213 + }
53214 + tmp = tmp->next;
53215 + }
53216 + goto found_obj;
53217 + }
53218 + } while ((tmpsubj = tmpsubj->parent_subject));
53219 +next_component:
53220 + /* end case */
53221 + if (p == name)
53222 + break;
53223 +
53224 + while (*p != '/')
53225 + p--;
53226 + if (p == name)
53227 + lastp = p + 1;
53228 + else {
53229 + lastp = p;
53230 + p--;
53231 + }
53232 + c = *lastp;
53233 + *lastp = '\0';
53234 + } while (1);
53235 +found_obj:
53236 + read_unlock(&gr_inode_lock);
53237 + /* obj returned will always be non-null */
53238 + return obj;
53239 +}
53240 +
53241 +/* returns 0 when allowing, non-zero on error
53242 + op of 0 is used for readdir, so we don't log the names of hidden files
53243 +*/
53244 +__u32
53245 +gr_handle_sysctl(const struct ctl_table *table, const int op)
53246 +{
53247 + struct ctl_table *tmp;
53248 + const char *proc_sys = "/proc/sys";
53249 + char *path;
53250 + struct acl_object_label *obj;
53251 + unsigned short len = 0, pos = 0, depth = 0, i;
53252 + __u32 err = 0;
53253 + __u32 mode = 0;
53254 +
53255 + if (unlikely(!(gr_status & GR_READY)))
53256 + return 0;
53257 +
53258 + /* for now, ignore operations on non-sysctl entries if it's not a
53259 + readdir*/
53260 + if (table->child != NULL && op != 0)
53261 + return 0;
53262 +
53263 + mode |= GR_FIND;
53264 + /* it's only a read if it's an entry, read on dirs is for readdir */
53265 + if (op & MAY_READ)
53266 + mode |= GR_READ;
53267 + if (op & MAY_WRITE)
53268 + mode |= GR_WRITE;
53269 +
53270 + preempt_disable();
53271 +
53272 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
53273 +
53274 + /* it's only a read/write if it's an actual entry, not a dir
53275 + (which are opened for readdir)
53276 + */
53277 +
53278 + /* convert the requested sysctl entry into a pathname */
53279 +
53280 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
53281 + len += strlen(tmp->procname);
53282 + len++;
53283 + depth++;
53284 + }
53285 +
53286 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
53287 + /* deny */
53288 + goto out;
53289 + }
53290 +
53291 + memset(path, 0, PAGE_SIZE);
53292 +
53293 + memcpy(path, proc_sys, strlen(proc_sys));
53294 +
53295 + pos += strlen(proc_sys);
53296 +
53297 + for (; depth > 0; depth--) {
53298 + path[pos] = '/';
53299 + pos++;
53300 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
53301 + if (depth == i) {
53302 + memcpy(path + pos, tmp->procname,
53303 + strlen(tmp->procname));
53304 + pos += strlen(tmp->procname);
53305 + }
53306 + i++;
53307 + }
53308 + }
53309 +
53310 + obj = gr_lookup_by_name(path, pos);
53311 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
53312 +
53313 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
53314 + ((err & mode) != mode))) {
53315 + __u32 new_mode = mode;
53316 +
53317 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53318 +
53319 + err = 0;
53320 + gr_log_learn_sysctl(path, new_mode);
53321 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
53322 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
53323 + err = -ENOENT;
53324 + } else if (!(err & GR_FIND)) {
53325 + err = -ENOENT;
53326 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
53327 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
53328 + path, (mode & GR_READ) ? " reading" : "",
53329 + (mode & GR_WRITE) ? " writing" : "");
53330 + err = -EACCES;
53331 + } else if ((err & mode) != mode) {
53332 + err = -EACCES;
53333 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
53334 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
53335 + path, (mode & GR_READ) ? " reading" : "",
53336 + (mode & GR_WRITE) ? " writing" : "");
53337 + err = 0;
53338 + } else
53339 + err = 0;
53340 +
53341 + out:
53342 + preempt_enable();
53343 +
53344 + return err;
53345 +}
53346 +#endif
53347 +
53348 +int
53349 +gr_handle_proc_ptrace(struct task_struct *task)
53350 +{
53351 + struct file *filp;
53352 + struct task_struct *tmp = task;
53353 + struct task_struct *curtemp = current;
53354 + __u32 retmode;
53355 +
53356 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
53357 + if (unlikely(!(gr_status & GR_READY)))
53358 + return 0;
53359 +#endif
53360 +
53361 + read_lock(&tasklist_lock);
53362 + read_lock(&grsec_exec_file_lock);
53363 + filp = task->exec_file;
53364 +
53365 + while (tmp->pid > 0) {
53366 + if (tmp == curtemp)
53367 + break;
53368 + tmp = tmp->real_parent;
53369 + }
53370 +
53371 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
53372 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
53373 + read_unlock(&grsec_exec_file_lock);
53374 + read_unlock(&tasklist_lock);
53375 + return 1;
53376 + }
53377 +
53378 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
53379 + if (!(gr_status & GR_READY)) {
53380 + read_unlock(&grsec_exec_file_lock);
53381 + read_unlock(&tasklist_lock);
53382 + return 0;
53383 + }
53384 +#endif
53385 +
53386 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
53387 + read_unlock(&grsec_exec_file_lock);
53388 + read_unlock(&tasklist_lock);
53389 +
53390 + if (retmode & GR_NOPTRACE)
53391 + return 1;
53392 +
53393 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
53394 + && (current->acl != task->acl || (current->acl != current->role->root_label
53395 + && current->pid != task->pid)))
53396 + return 1;
53397 +
53398 + return 0;
53399 +}
53400 +
53401 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
53402 +{
53403 + if (unlikely(!(gr_status & GR_READY)))
53404 + return;
53405 +
53406 + if (!(current->role->roletype & GR_ROLE_GOD))
53407 + return;
53408 +
53409 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
53410 + p->role->rolename, gr_task_roletype_to_char(p),
53411 + p->acl->filename);
53412 +}
53413 +
53414 +int
53415 +gr_handle_ptrace(struct task_struct *task, const long request)
53416 +{
53417 + struct task_struct *tmp = task;
53418 + struct task_struct *curtemp = current;
53419 + __u32 retmode;
53420 +
53421 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
53422 + if (unlikely(!(gr_status & GR_READY)))
53423 + return 0;
53424 +#endif
53425 +
53426 + read_lock(&tasklist_lock);
53427 + while (tmp->pid > 0) {
53428 + if (tmp == curtemp)
53429 + break;
53430 + tmp = tmp->real_parent;
53431 + }
53432 +
53433 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
53434 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
53435 + read_unlock(&tasklist_lock);
53436 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53437 + return 1;
53438 + }
53439 + read_unlock(&tasklist_lock);
53440 +
53441 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
53442 + if (!(gr_status & GR_READY))
53443 + return 0;
53444 +#endif
53445 +
53446 + read_lock(&grsec_exec_file_lock);
53447 + if (unlikely(!task->exec_file)) {
53448 + read_unlock(&grsec_exec_file_lock);
53449 + return 0;
53450 + }
53451 +
53452 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
53453 + read_unlock(&grsec_exec_file_lock);
53454 +
53455 + if (retmode & GR_NOPTRACE) {
53456 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53457 + return 1;
53458 + }
53459 +
53460 + if (retmode & GR_PTRACERD) {
53461 + switch (request) {
53462 + case PTRACE_SEIZE:
53463 + case PTRACE_POKETEXT:
53464 + case PTRACE_POKEDATA:
53465 + case PTRACE_POKEUSR:
53466 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
53467 + case PTRACE_SETREGS:
53468 + case PTRACE_SETFPREGS:
53469 +#endif
53470 +#ifdef CONFIG_X86
53471 + case PTRACE_SETFPXREGS:
53472 +#endif
53473 +#ifdef CONFIG_ALTIVEC
53474 + case PTRACE_SETVRREGS:
53475 +#endif
53476 + return 1;
53477 + default:
53478 + return 0;
53479 + }
53480 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
53481 + !(current->role->roletype & GR_ROLE_GOD) &&
53482 + (current->acl != task->acl)) {
53483 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53484 + return 1;
53485 + }
53486 +
53487 + return 0;
53488 +}
53489 +
53490 +static int is_writable_mmap(const struct file *filp)
53491 +{
53492 + struct task_struct *task = current;
53493 + struct acl_object_label *obj, *obj2;
53494 +
53495 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
53496 + !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))) {
53497 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53498 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
53499 + task->role->root_label);
53500 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
53501 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
53502 + return 1;
53503 + }
53504 + }
53505 + return 0;
53506 +}
53507 +
53508 +int
53509 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
53510 +{
53511 + __u32 mode;
53512 +
53513 + if (unlikely(!file || !(prot & PROT_EXEC)))
53514 + return 1;
53515 +
53516 + if (is_writable_mmap(file))
53517 + return 0;
53518 +
53519 + mode =
53520 + gr_search_file(file->f_path.dentry,
53521 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
53522 + file->f_path.mnt);
53523 +
53524 + if (!gr_tpe_allow(file))
53525 + return 0;
53526 +
53527 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
53528 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53529 + return 0;
53530 + } else if (unlikely(!(mode & GR_EXEC))) {
53531 + return 0;
53532 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
53533 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53534 + return 1;
53535 + }
53536 +
53537 + return 1;
53538 +}
53539 +
53540 +int
53541 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
53542 +{
53543 + __u32 mode;
53544 +
53545 + if (unlikely(!file || !(prot & PROT_EXEC)))
53546 + return 1;
53547 +
53548 + if (is_writable_mmap(file))
53549 + return 0;
53550 +
53551 + mode =
53552 + gr_search_file(file->f_path.dentry,
53553 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
53554 + file->f_path.mnt);
53555 +
53556 + if (!gr_tpe_allow(file))
53557 + return 0;
53558 +
53559 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
53560 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53561 + return 0;
53562 + } else if (unlikely(!(mode & GR_EXEC))) {
53563 + return 0;
53564 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
53565 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53566 + return 1;
53567 + }
53568 +
53569 + return 1;
53570 +}
53571 +
53572 +void
53573 +gr_acl_handle_psacct(struct task_struct *task, const long code)
53574 +{
53575 + unsigned long runtime;
53576 + unsigned long cputime;
53577 + unsigned int wday, cday;
53578 + __u8 whr, chr;
53579 + __u8 wmin, cmin;
53580 + __u8 wsec, csec;
53581 + struct timespec timeval;
53582 +
53583 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
53584 + !(task->acl->mode & GR_PROCACCT)))
53585 + return;
53586 +
53587 + do_posix_clock_monotonic_gettime(&timeval);
53588 + runtime = timeval.tv_sec - task->start_time.tv_sec;
53589 + wday = runtime / (3600 * 24);
53590 + runtime -= wday * (3600 * 24);
53591 + whr = runtime / 3600;
53592 + runtime -= whr * 3600;
53593 + wmin = runtime / 60;
53594 + runtime -= wmin * 60;
53595 + wsec = runtime;
53596 +
53597 + cputime = (task->utime + task->stime) / HZ;
53598 + cday = cputime / (3600 * 24);
53599 + cputime -= cday * (3600 * 24);
53600 + chr = cputime / 3600;
53601 + cputime -= chr * 3600;
53602 + cmin = cputime / 60;
53603 + cputime -= cmin * 60;
53604 + csec = cputime;
53605 +
53606 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
53607 +
53608 + return;
53609 +}
53610 +
53611 +void gr_set_kernel_label(struct task_struct *task)
53612 +{
53613 + if (gr_status & GR_READY) {
53614 + task->role = kernel_role;
53615 + task->acl = kernel_role->root_label;
53616 + }
53617 + return;
53618 +}
53619 +
53620 +#ifdef CONFIG_TASKSTATS
53621 +int gr_is_taskstats_denied(int pid)
53622 +{
53623 + struct task_struct *task;
53624 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53625 + const struct cred *cred;
53626 +#endif
53627 + int ret = 0;
53628 +
53629 + /* restrict taskstats viewing to un-chrooted root users
53630 + who have the 'view' subject flag if the RBAC system is enabled
53631 + */
53632 +
53633 + rcu_read_lock();
53634 + read_lock(&tasklist_lock);
53635 + task = find_task_by_vpid(pid);
53636 + if (task) {
53637 +#ifdef CONFIG_GRKERNSEC_CHROOT
53638 + if (proc_is_chrooted(task))
53639 + ret = -EACCES;
53640 +#endif
53641 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53642 + cred = __task_cred(task);
53643 +#ifdef CONFIG_GRKERNSEC_PROC_USER
53644 + if (cred->uid != 0)
53645 + ret = -EACCES;
53646 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53647 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
53648 + ret = -EACCES;
53649 +#endif
53650 +#endif
53651 + if (gr_status & GR_READY) {
53652 + if (!(task->acl->mode & GR_VIEW))
53653 + ret = -EACCES;
53654 + }
53655 + } else
53656 + ret = -ENOENT;
53657 +
53658 + read_unlock(&tasklist_lock);
53659 + rcu_read_unlock();
53660 +
53661 + return ret;
53662 +}
53663 +#endif
53664 +
53665 +/* AUXV entries are filled via a descendant of search_binary_handler
53666 + after we've already applied the subject for the target
53667 +*/
53668 +int gr_acl_enable_at_secure(void)
53669 +{
53670 + if (unlikely(!(gr_status & GR_READY)))
53671 + return 0;
53672 +
53673 + if (current->acl->mode & GR_ATSECURE)
53674 + return 1;
53675 +
53676 + return 0;
53677 +}
53678 +
53679 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
53680 +{
53681 + struct task_struct *task = current;
53682 + struct dentry *dentry = file->f_path.dentry;
53683 + struct vfsmount *mnt = file->f_path.mnt;
53684 + struct acl_object_label *obj, *tmp;
53685 + struct acl_subject_label *subj;
53686 + unsigned int bufsize;
53687 + int is_not_root;
53688 + char *path;
53689 + dev_t dev = __get_dev(dentry);
53690 +
53691 + if (unlikely(!(gr_status & GR_READY)))
53692 + return 1;
53693 +
53694 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53695 + return 1;
53696 +
53697 + /* ignore Eric Biederman */
53698 + if (IS_PRIVATE(dentry->d_inode))
53699 + return 1;
53700 +
53701 + subj = task->acl;
53702 + do {
53703 + obj = lookup_acl_obj_label(ino, dev, subj);
53704 + if (obj != NULL)
53705 + return (obj->mode & GR_FIND) ? 1 : 0;
53706 + } while ((subj = subj->parent_subject));
53707 +
53708 + /* this is purely an optimization since we're looking for an object
53709 + for the directory we're doing a readdir on
53710 + if it's possible for any globbed object to match the entry we're
53711 + filling into the directory, then the object we find here will be
53712 + an anchor point with attached globbed objects
53713 + */
53714 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
53715 + if (obj->globbed == NULL)
53716 + return (obj->mode & GR_FIND) ? 1 : 0;
53717 +
53718 + is_not_root = ((obj->filename[0] == '/') &&
53719 + (obj->filename[1] == '\0')) ? 0 : 1;
53720 + bufsize = PAGE_SIZE - namelen - is_not_root;
53721 +
53722 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
53723 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
53724 + return 1;
53725 +
53726 + preempt_disable();
53727 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
53728 + bufsize);
53729 +
53730 + bufsize = strlen(path);
53731 +
53732 + /* if base is "/", don't append an additional slash */
53733 + if (is_not_root)
53734 + *(path + bufsize) = '/';
53735 + memcpy(path + bufsize + is_not_root, name, namelen);
53736 + *(path + bufsize + namelen + is_not_root) = '\0';
53737 +
53738 + tmp = obj->globbed;
53739 + while (tmp) {
53740 + if (!glob_match(tmp->filename, path)) {
53741 + preempt_enable();
53742 + return (tmp->mode & GR_FIND) ? 1 : 0;
53743 + }
53744 + tmp = tmp->next;
53745 + }
53746 + preempt_enable();
53747 + return (obj->mode & GR_FIND) ? 1 : 0;
53748 +}
53749 +
53750 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
53751 +EXPORT_SYMBOL(gr_acl_is_enabled);
53752 +#endif
53753 +EXPORT_SYMBOL(gr_learn_resource);
53754 +EXPORT_SYMBOL(gr_set_kernel_label);
53755 +#ifdef CONFIG_SECURITY
53756 +EXPORT_SYMBOL(gr_check_user_change);
53757 +EXPORT_SYMBOL(gr_check_group_change);
53758 +#endif
53759 +
53760 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
53761 new file mode 100644
53762 index 0000000..34fefda
53763 --- /dev/null
53764 +++ b/grsecurity/gracl_alloc.c
53765 @@ -0,0 +1,105 @@
53766 +#include <linux/kernel.h>
53767 +#include <linux/mm.h>
53768 +#include <linux/slab.h>
53769 +#include <linux/vmalloc.h>
53770 +#include <linux/gracl.h>
53771 +#include <linux/grsecurity.h>
53772 +
53773 +static unsigned long alloc_stack_next = 1;
53774 +static unsigned long alloc_stack_size = 1;
53775 +static void **alloc_stack;
53776 +
53777 +static __inline__ int
53778 +alloc_pop(void)
53779 +{
53780 + if (alloc_stack_next == 1)
53781 + return 0;
53782 +
53783 + kfree(alloc_stack[alloc_stack_next - 2]);
53784 +
53785 + alloc_stack_next--;
53786 +
53787 + return 1;
53788 +}
53789 +
53790 +static __inline__ int
53791 +alloc_push(void *buf)
53792 +{
53793 + if (alloc_stack_next >= alloc_stack_size)
53794 + return 1;
53795 +
53796 + alloc_stack[alloc_stack_next - 1] = buf;
53797 +
53798 + alloc_stack_next++;
53799 +
53800 + return 0;
53801 +}
53802 +
53803 +void *
53804 +acl_alloc(unsigned long len)
53805 +{
53806 + void *ret = NULL;
53807 +
53808 + if (!len || len > PAGE_SIZE)
53809 + goto out;
53810 +
53811 + ret = kmalloc(len, GFP_KERNEL);
53812 +
53813 + if (ret) {
53814 + if (alloc_push(ret)) {
53815 + kfree(ret);
53816 + ret = NULL;
53817 + }
53818 + }
53819 +
53820 +out:
53821 + return ret;
53822 +}
53823 +
53824 +void *
53825 +acl_alloc_num(unsigned long num, unsigned long len)
53826 +{
53827 + if (!len || (num > (PAGE_SIZE / len)))
53828 + return NULL;
53829 +
53830 + return acl_alloc(num * len);
53831 +}
53832 +
53833 +void
53834 +acl_free_all(void)
53835 +{
53836 + if (gr_acl_is_enabled() || !alloc_stack)
53837 + return;
53838 +
53839 + while (alloc_pop()) ;
53840 +
53841 + if (alloc_stack) {
53842 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
53843 + kfree(alloc_stack);
53844 + else
53845 + vfree(alloc_stack);
53846 + }
53847 +
53848 + alloc_stack = NULL;
53849 + alloc_stack_size = 1;
53850 + alloc_stack_next = 1;
53851 +
53852 + return;
53853 +}
53854 +
53855 +int
53856 +acl_alloc_stack_init(unsigned long size)
53857 +{
53858 + if ((size * sizeof (void *)) <= PAGE_SIZE)
53859 + alloc_stack =
53860 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
53861 + else
53862 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
53863 +
53864 + alloc_stack_size = size;
53865 +
53866 + if (!alloc_stack)
53867 + return 0;
53868 + else
53869 + return 1;
53870 +}
53871 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
53872 new file mode 100644
53873 index 0000000..955ddfb
53874 --- /dev/null
53875 +++ b/grsecurity/gracl_cap.c
53876 @@ -0,0 +1,101 @@
53877 +#include <linux/kernel.h>
53878 +#include <linux/module.h>
53879 +#include <linux/sched.h>
53880 +#include <linux/gracl.h>
53881 +#include <linux/grsecurity.h>
53882 +#include <linux/grinternal.h>
53883 +
53884 +extern const char *captab_log[];
53885 +extern int captab_log_entries;
53886 +
53887 +int
53888 +gr_acl_is_capable(const int cap)
53889 +{
53890 + struct task_struct *task = current;
53891 + const struct cred *cred = current_cred();
53892 + struct acl_subject_label *curracl;
53893 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
53894 + kernel_cap_t cap_audit = __cap_empty_set;
53895 +
53896 + if (!gr_acl_is_enabled())
53897 + return 1;
53898 +
53899 + curracl = task->acl;
53900 +
53901 + cap_drop = curracl->cap_lower;
53902 + cap_mask = curracl->cap_mask;
53903 + cap_audit = curracl->cap_invert_audit;
53904 +
53905 + while ((curracl = curracl->parent_subject)) {
53906 + /* if the cap isn't specified in the current computed mask but is specified in the
53907 + current level subject, and is lowered in the current level subject, then add
53908 + it to the set of dropped capabilities
53909 + otherwise, add the current level subject's mask to the current computed mask
53910 + */
53911 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
53912 + cap_raise(cap_mask, cap);
53913 + if (cap_raised(curracl->cap_lower, cap))
53914 + cap_raise(cap_drop, cap);
53915 + if (cap_raised(curracl->cap_invert_audit, cap))
53916 + cap_raise(cap_audit, cap);
53917 + }
53918 + }
53919 +
53920 + if (!cap_raised(cap_drop, cap)) {
53921 + if (cap_raised(cap_audit, cap))
53922 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
53923 + return 1;
53924 + }
53925 +
53926 + curracl = task->acl;
53927 +
53928 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
53929 + && cap_raised(cred->cap_effective, cap)) {
53930 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
53931 + task->role->roletype, cred->uid,
53932 + cred->gid, task->exec_file ?
53933 + gr_to_filename(task->exec_file->f_path.dentry,
53934 + task->exec_file->f_path.mnt) : curracl->filename,
53935 + curracl->filename, 0UL,
53936 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
53937 + return 1;
53938 + }
53939 +
53940 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
53941 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
53942 + return 0;
53943 +}
53944 +
53945 +int
53946 +gr_acl_is_capable_nolog(const int cap)
53947 +{
53948 + struct acl_subject_label *curracl;
53949 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
53950 +
53951 + if (!gr_acl_is_enabled())
53952 + return 1;
53953 +
53954 + curracl = current->acl;
53955 +
53956 + cap_drop = curracl->cap_lower;
53957 + cap_mask = curracl->cap_mask;
53958 +
53959 + while ((curracl = curracl->parent_subject)) {
53960 + /* if the cap isn't specified in the current computed mask but is specified in the
53961 + current level subject, and is lowered in the current level subject, then add
53962 + it to the set of dropped capabilities
53963 + otherwise, add the current level subject's mask to the current computed mask
53964 + */
53965 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
53966 + cap_raise(cap_mask, cap);
53967 + if (cap_raised(curracl->cap_lower, cap))
53968 + cap_raise(cap_drop, cap);
53969 + }
53970 + }
53971 +
53972 + if (!cap_raised(cap_drop, cap))
53973 + return 1;
53974 +
53975 + return 0;
53976 +}
53977 +
53978 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
53979 new file mode 100644
53980 index 0000000..88d0e87
53981 --- /dev/null
53982 +++ b/grsecurity/gracl_fs.c
53983 @@ -0,0 +1,435 @@
53984 +#include <linux/kernel.h>
53985 +#include <linux/sched.h>
53986 +#include <linux/types.h>
53987 +#include <linux/fs.h>
53988 +#include <linux/file.h>
53989 +#include <linux/stat.h>
53990 +#include <linux/grsecurity.h>
53991 +#include <linux/grinternal.h>
53992 +#include <linux/gracl.h>
53993 +
53994 +umode_t
53995 +gr_acl_umask(void)
53996 +{
53997 + if (unlikely(!gr_acl_is_enabled()))
53998 + return 0;
53999 +
54000 + return current->role->umask;
54001 +}
54002 +
54003 +__u32
54004 +gr_acl_handle_hidden_file(const struct dentry * dentry,
54005 + const struct vfsmount * mnt)
54006 +{
54007 + __u32 mode;
54008 +
54009 + if (unlikely(!dentry->d_inode))
54010 + return GR_FIND;
54011 +
54012 + mode =
54013 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
54014 +
54015 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
54016 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
54017 + return mode;
54018 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
54019 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
54020 + return 0;
54021 + } else if (unlikely(!(mode & GR_FIND)))
54022 + return 0;
54023 +
54024 + return GR_FIND;
54025 +}
54026 +
54027 +__u32
54028 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
54029 + int acc_mode)
54030 +{
54031 + __u32 reqmode = GR_FIND;
54032 + __u32 mode;
54033 +
54034 + if (unlikely(!dentry->d_inode))
54035 + return reqmode;
54036 +
54037 + if (acc_mode & MAY_APPEND)
54038 + reqmode |= GR_APPEND;
54039 + else if (acc_mode & MAY_WRITE)
54040 + reqmode |= GR_WRITE;
54041 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
54042 + reqmode |= GR_READ;
54043 +
54044 + mode =
54045 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54046 + mnt);
54047 +
54048 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54049 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54050 + reqmode & GR_READ ? " reading" : "",
54051 + reqmode & GR_WRITE ? " writing" : reqmode &
54052 + GR_APPEND ? " appending" : "");
54053 + return reqmode;
54054 + } else
54055 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54056 + {
54057 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54058 + reqmode & GR_READ ? " reading" : "",
54059 + reqmode & GR_WRITE ? " writing" : reqmode &
54060 + GR_APPEND ? " appending" : "");
54061 + return 0;
54062 + } else if (unlikely((mode & reqmode) != reqmode))
54063 + return 0;
54064 +
54065 + return reqmode;
54066 +}
54067 +
54068 +__u32
54069 +gr_acl_handle_creat(const struct dentry * dentry,
54070 + const struct dentry * p_dentry,
54071 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
54072 + const int imode)
54073 +{
54074 + __u32 reqmode = GR_WRITE | GR_CREATE;
54075 + __u32 mode;
54076 +
54077 + if (acc_mode & MAY_APPEND)
54078 + reqmode |= GR_APPEND;
54079 + // if a directory was required or the directory already exists, then
54080 + // don't count this open as a read
54081 + if ((acc_mode & MAY_READ) &&
54082 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
54083 + reqmode |= GR_READ;
54084 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
54085 + reqmode |= GR_SETID;
54086 +
54087 + mode =
54088 + gr_check_create(dentry, p_dentry, p_mnt,
54089 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
54090 +
54091 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54092 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54093 + reqmode & GR_READ ? " reading" : "",
54094 + reqmode & GR_WRITE ? " writing" : reqmode &
54095 + GR_APPEND ? " appending" : "");
54096 + return reqmode;
54097 + } else
54098 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54099 + {
54100 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54101 + reqmode & GR_READ ? " reading" : "",
54102 + reqmode & GR_WRITE ? " writing" : reqmode &
54103 + GR_APPEND ? " appending" : "");
54104 + return 0;
54105 + } else if (unlikely((mode & reqmode) != reqmode))
54106 + return 0;
54107 +
54108 + return reqmode;
54109 +}
54110 +
54111 +__u32
54112 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
54113 + const int fmode)
54114 +{
54115 + __u32 mode, reqmode = GR_FIND;
54116 +
54117 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
54118 + reqmode |= GR_EXEC;
54119 + if (fmode & S_IWOTH)
54120 + reqmode |= GR_WRITE;
54121 + if (fmode & S_IROTH)
54122 + reqmode |= GR_READ;
54123 +
54124 + mode =
54125 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54126 + mnt);
54127 +
54128 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54129 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54130 + reqmode & GR_READ ? " reading" : "",
54131 + reqmode & GR_WRITE ? " writing" : "",
54132 + reqmode & GR_EXEC ? " executing" : "");
54133 + return reqmode;
54134 + } else
54135 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54136 + {
54137 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54138 + reqmode & GR_READ ? " reading" : "",
54139 + reqmode & GR_WRITE ? " writing" : "",
54140 + reqmode & GR_EXEC ? " executing" : "");
54141 + return 0;
54142 + } else if (unlikely((mode & reqmode) != reqmode))
54143 + return 0;
54144 +
54145 + return reqmode;
54146 +}
54147 +
54148 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
54149 +{
54150 + __u32 mode;
54151 +
54152 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
54153 +
54154 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
54155 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
54156 + return mode;
54157 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
54158 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
54159 + return 0;
54160 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
54161 + return 0;
54162 +
54163 + return (reqmode);
54164 +}
54165 +
54166 +__u32
54167 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
54168 +{
54169 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
54170 +}
54171 +
54172 +__u32
54173 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
54174 +{
54175 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
54176 +}
54177 +
54178 +__u32
54179 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
54180 +{
54181 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
54182 +}
54183 +
54184 +__u32
54185 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
54186 +{
54187 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
54188 +}
54189 +
54190 +__u32
54191 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
54192 + umode_t *modeptr)
54193 +{
54194 + umode_t mode;
54195 +
54196 + *modeptr &= ~gr_acl_umask();
54197 + mode = *modeptr;
54198 +
54199 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
54200 + return 1;
54201 +
54202 + if (unlikely(mode & (S_ISUID | S_ISGID))) {
54203 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
54204 + GR_CHMOD_ACL_MSG);
54205 + } else {
54206 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
54207 + }
54208 +}
54209 +
54210 +__u32
54211 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
54212 +{
54213 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
54214 +}
54215 +
54216 +__u32
54217 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
54218 +{
54219 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
54220 +}
54221 +
54222 +__u32
54223 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
54224 +{
54225 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
54226 +}
54227 +
54228 +__u32
54229 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
54230 +{
54231 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
54232 + GR_UNIXCONNECT_ACL_MSG);
54233 +}
54234 +
54235 +/* hardlinks require at minimum create and link permission,
54236 + any additional privilege required is based on the
54237 + privilege of the file being linked to
54238 +*/
54239 +__u32
54240 +gr_acl_handle_link(const struct dentry * new_dentry,
54241 + const struct dentry * parent_dentry,
54242 + const struct vfsmount * parent_mnt,
54243 + const struct dentry * old_dentry,
54244 + const struct vfsmount * old_mnt, const char *to)
54245 +{
54246 + __u32 mode;
54247 + __u32 needmode = GR_CREATE | GR_LINK;
54248 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
54249 +
54250 + mode =
54251 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
54252 + old_mnt);
54253 +
54254 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
54255 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
54256 + return mode;
54257 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
54258 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
54259 + return 0;
54260 + } else if (unlikely((mode & needmode) != needmode))
54261 + return 0;
54262 +
54263 + return 1;
54264 +}
54265 +
54266 +__u32
54267 +gr_acl_handle_symlink(const struct dentry * new_dentry,
54268 + const struct dentry * parent_dentry,
54269 + const struct vfsmount * parent_mnt, const char *from)
54270 +{
54271 + __u32 needmode = GR_WRITE | GR_CREATE;
54272 + __u32 mode;
54273 +
54274 + mode =
54275 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
54276 + GR_CREATE | GR_AUDIT_CREATE |
54277 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
54278 +
54279 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
54280 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
54281 + return mode;
54282 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
54283 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
54284 + return 0;
54285 + } else if (unlikely((mode & needmode) != needmode))
54286 + return 0;
54287 +
54288 + return (GR_WRITE | GR_CREATE);
54289 +}
54290 +
54291 +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)
54292 +{
54293 + __u32 mode;
54294 +
54295 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
54296 +
54297 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
54298 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
54299 + return mode;
54300 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
54301 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
54302 + return 0;
54303 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
54304 + return 0;
54305 +
54306 + return (reqmode);
54307 +}
54308 +
54309 +__u32
54310 +gr_acl_handle_mknod(const struct dentry * new_dentry,
54311 + const struct dentry * parent_dentry,
54312 + const struct vfsmount * parent_mnt,
54313 + const int mode)
54314 +{
54315 + __u32 reqmode = GR_WRITE | GR_CREATE;
54316 + if (unlikely(mode & (S_ISUID | S_ISGID)))
54317 + reqmode |= GR_SETID;
54318 +
54319 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
54320 + reqmode, GR_MKNOD_ACL_MSG);
54321 +}
54322 +
54323 +__u32
54324 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
54325 + const struct dentry *parent_dentry,
54326 + const struct vfsmount *parent_mnt)
54327 +{
54328 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
54329 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
54330 +}
54331 +
54332 +#define RENAME_CHECK_SUCCESS(old, new) \
54333 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
54334 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
54335 +
54336 +int
54337 +gr_acl_handle_rename(struct dentry *new_dentry,
54338 + struct dentry *parent_dentry,
54339 + const struct vfsmount *parent_mnt,
54340 + struct dentry *old_dentry,
54341 + struct inode *old_parent_inode,
54342 + struct vfsmount *old_mnt, const char *newname)
54343 +{
54344 + __u32 comp1, comp2;
54345 + int error = 0;
54346 +
54347 + if (unlikely(!gr_acl_is_enabled()))
54348 + return 0;
54349 +
54350 + if (!new_dentry->d_inode) {
54351 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
54352 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
54353 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
54354 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
54355 + GR_DELETE | GR_AUDIT_DELETE |
54356 + GR_AUDIT_READ | GR_AUDIT_WRITE |
54357 + GR_SUPPRESS, old_mnt);
54358 + } else {
54359 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
54360 + GR_CREATE | GR_DELETE |
54361 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
54362 + GR_AUDIT_READ | GR_AUDIT_WRITE |
54363 + GR_SUPPRESS, parent_mnt);
54364 + comp2 =
54365 + gr_search_file(old_dentry,
54366 + GR_READ | GR_WRITE | GR_AUDIT_READ |
54367 + GR_DELETE | GR_AUDIT_DELETE |
54368 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
54369 + }
54370 +
54371 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
54372 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
54373 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
54374 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
54375 + && !(comp2 & GR_SUPPRESS)) {
54376 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
54377 + error = -EACCES;
54378 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
54379 + error = -EACCES;
54380 +
54381 + return error;
54382 +}
54383 +
54384 +void
54385 +gr_acl_handle_exit(void)
54386 +{
54387 + u16 id;
54388 + char *rolename;
54389 + struct file *exec_file;
54390 +
54391 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
54392 + !(current->role->roletype & GR_ROLE_PERSIST))) {
54393 + id = current->acl_role_id;
54394 + rolename = current->role->rolename;
54395 + gr_set_acls(1);
54396 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
54397 + }
54398 +
54399 + write_lock(&grsec_exec_file_lock);
54400 + exec_file = current->exec_file;
54401 + current->exec_file = NULL;
54402 + write_unlock(&grsec_exec_file_lock);
54403 +
54404 + if (exec_file)
54405 + fput(exec_file);
54406 +}
54407 +
54408 +int
54409 +gr_acl_handle_procpidmem(const struct task_struct *task)
54410 +{
54411 + if (unlikely(!gr_acl_is_enabled()))
54412 + return 0;
54413 +
54414 + if (task != current && task->acl->mode & GR_PROTPROCFD)
54415 + return -EACCES;
54416 +
54417 + return 0;
54418 +}
54419 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
54420 new file mode 100644
54421 index 0000000..17050ca
54422 --- /dev/null
54423 +++ b/grsecurity/gracl_ip.c
54424 @@ -0,0 +1,381 @@
54425 +#include <linux/kernel.h>
54426 +#include <asm/uaccess.h>
54427 +#include <asm/errno.h>
54428 +#include <net/sock.h>
54429 +#include <linux/file.h>
54430 +#include <linux/fs.h>
54431 +#include <linux/net.h>
54432 +#include <linux/in.h>
54433 +#include <linux/skbuff.h>
54434 +#include <linux/ip.h>
54435 +#include <linux/udp.h>
54436 +#include <linux/types.h>
54437 +#include <linux/sched.h>
54438 +#include <linux/netdevice.h>
54439 +#include <linux/inetdevice.h>
54440 +#include <linux/gracl.h>
54441 +#include <linux/grsecurity.h>
54442 +#include <linux/grinternal.h>
54443 +
54444 +#define GR_BIND 0x01
54445 +#define GR_CONNECT 0x02
54446 +#define GR_INVERT 0x04
54447 +#define GR_BINDOVERRIDE 0x08
54448 +#define GR_CONNECTOVERRIDE 0x10
54449 +#define GR_SOCK_FAMILY 0x20
54450 +
54451 +static const char * gr_protocols[IPPROTO_MAX] = {
54452 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
54453 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
54454 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
54455 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
54456 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
54457 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
54458 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
54459 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
54460 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
54461 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
54462 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
54463 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
54464 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
54465 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
54466 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
54467 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
54468 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
54469 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
54470 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
54471 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
54472 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
54473 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
54474 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
54475 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
54476 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
54477 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
54478 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
54479 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
54480 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
54481 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
54482 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
54483 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
54484 + };
54485 +
54486 +static const char * gr_socktypes[SOCK_MAX] = {
54487 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
54488 + "unknown:7", "unknown:8", "unknown:9", "packet"
54489 + };
54490 +
54491 +static const char * gr_sockfamilies[AF_MAX+1] = {
54492 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
54493 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
54494 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
54495 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
54496 + };
54497 +
54498 +const char *
54499 +gr_proto_to_name(unsigned char proto)
54500 +{
54501 + return gr_protocols[proto];
54502 +}
54503 +
54504 +const char *
54505 +gr_socktype_to_name(unsigned char type)
54506 +{
54507 + return gr_socktypes[type];
54508 +}
54509 +
54510 +const char *
54511 +gr_sockfamily_to_name(unsigned char family)
54512 +{
54513 + return gr_sockfamilies[family];
54514 +}
54515 +
54516 +int
54517 +gr_search_socket(const int domain, const int type, const int protocol)
54518 +{
54519 + struct acl_subject_label *curr;
54520 + const struct cred *cred = current_cred();
54521 +
54522 + if (unlikely(!gr_acl_is_enabled()))
54523 + goto exit;
54524 +
54525 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
54526 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
54527 + goto exit; // let the kernel handle it
54528 +
54529 + curr = current->acl;
54530 +
54531 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
54532 + /* the family is allowed, if this is PF_INET allow it only if
54533 + the extra sock type/protocol checks pass */
54534 + if (domain == PF_INET)
54535 + goto inet_check;
54536 + goto exit;
54537 + } else {
54538 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
54539 + __u32 fakeip = 0;
54540 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54541 + current->role->roletype, cred->uid,
54542 + cred->gid, current->exec_file ?
54543 + gr_to_filename(current->exec_file->f_path.dentry,
54544 + current->exec_file->f_path.mnt) :
54545 + curr->filename, curr->filename,
54546 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
54547 + &current->signal->saved_ip);
54548 + goto exit;
54549 + }
54550 + goto exit_fail;
54551 + }
54552 +
54553 +inet_check:
54554 + /* the rest of this checking is for IPv4 only */
54555 + if (!curr->ips)
54556 + goto exit;
54557 +
54558 + if ((curr->ip_type & (1 << type)) &&
54559 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
54560 + goto exit;
54561 +
54562 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
54563 + /* we don't place acls on raw sockets , and sometimes
54564 + dgram/ip sockets are opened for ioctl and not
54565 + bind/connect, so we'll fake a bind learn log */
54566 + if (type == SOCK_RAW || type == SOCK_PACKET) {
54567 + __u32 fakeip = 0;
54568 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54569 + current->role->roletype, cred->uid,
54570 + cred->gid, current->exec_file ?
54571 + gr_to_filename(current->exec_file->f_path.dentry,
54572 + current->exec_file->f_path.mnt) :
54573 + curr->filename, curr->filename,
54574 + &fakeip, 0, type,
54575 + protocol, GR_CONNECT, &current->signal->saved_ip);
54576 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
54577 + __u32 fakeip = 0;
54578 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54579 + current->role->roletype, cred->uid,
54580 + cred->gid, current->exec_file ?
54581 + gr_to_filename(current->exec_file->f_path.dentry,
54582 + current->exec_file->f_path.mnt) :
54583 + curr->filename, curr->filename,
54584 + &fakeip, 0, type,
54585 + protocol, GR_BIND, &current->signal->saved_ip);
54586 + }
54587 + /* we'll log when they use connect or bind */
54588 + goto exit;
54589 + }
54590 +
54591 +exit_fail:
54592 + if (domain == PF_INET)
54593 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
54594 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
54595 + else
54596 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
54597 + gr_socktype_to_name(type), protocol);
54598 +
54599 + return 0;
54600 +exit:
54601 + return 1;
54602 +}
54603 +
54604 +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)
54605 +{
54606 + if ((ip->mode & mode) &&
54607 + (ip_port >= ip->low) &&
54608 + (ip_port <= ip->high) &&
54609 + ((ntohl(ip_addr) & our_netmask) ==
54610 + (ntohl(our_addr) & our_netmask))
54611 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
54612 + && (ip->type & (1 << type))) {
54613 + if (ip->mode & GR_INVERT)
54614 + return 2; // specifically denied
54615 + else
54616 + return 1; // allowed
54617 + }
54618 +
54619 + return 0; // not specifically allowed, may continue parsing
54620 +}
54621 +
54622 +static int
54623 +gr_search_connectbind(const int full_mode, struct sock *sk,
54624 + struct sockaddr_in *addr, const int type)
54625 +{
54626 + char iface[IFNAMSIZ] = {0};
54627 + struct acl_subject_label *curr;
54628 + struct acl_ip_label *ip;
54629 + struct inet_sock *isk;
54630 + struct net_device *dev;
54631 + struct in_device *idev;
54632 + unsigned long i;
54633 + int ret;
54634 + int mode = full_mode & (GR_BIND | GR_CONNECT);
54635 + __u32 ip_addr = 0;
54636 + __u32 our_addr;
54637 + __u32 our_netmask;
54638 + char *p;
54639 + __u16 ip_port = 0;
54640 + const struct cred *cred = current_cred();
54641 +
54642 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
54643 + return 0;
54644 +
54645 + curr = current->acl;
54646 + isk = inet_sk(sk);
54647 +
54648 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
54649 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
54650 + addr->sin_addr.s_addr = curr->inaddr_any_override;
54651 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
54652 + struct sockaddr_in saddr;
54653 + int err;
54654 +
54655 + saddr.sin_family = AF_INET;
54656 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
54657 + saddr.sin_port = isk->inet_sport;
54658 +
54659 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
54660 + if (err)
54661 + return err;
54662 +
54663 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
54664 + if (err)
54665 + return err;
54666 + }
54667 +
54668 + if (!curr->ips)
54669 + return 0;
54670 +
54671 + ip_addr = addr->sin_addr.s_addr;
54672 + ip_port = ntohs(addr->sin_port);
54673 +
54674 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
54675 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54676 + current->role->roletype, cred->uid,
54677 + cred->gid, current->exec_file ?
54678 + gr_to_filename(current->exec_file->f_path.dentry,
54679 + current->exec_file->f_path.mnt) :
54680 + curr->filename, curr->filename,
54681 + &ip_addr, ip_port, type,
54682 + sk->sk_protocol, mode, &current->signal->saved_ip);
54683 + return 0;
54684 + }
54685 +
54686 + for (i = 0; i < curr->ip_num; i++) {
54687 + ip = *(curr->ips + i);
54688 + if (ip->iface != NULL) {
54689 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
54690 + p = strchr(iface, ':');
54691 + if (p != NULL)
54692 + *p = '\0';
54693 + dev = dev_get_by_name(sock_net(sk), iface);
54694 + if (dev == NULL)
54695 + continue;
54696 + idev = in_dev_get(dev);
54697 + if (idev == NULL) {
54698 + dev_put(dev);
54699 + continue;
54700 + }
54701 + rcu_read_lock();
54702 + for_ifa(idev) {
54703 + if (!strcmp(ip->iface, ifa->ifa_label)) {
54704 + our_addr = ifa->ifa_address;
54705 + our_netmask = 0xffffffff;
54706 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
54707 + if (ret == 1) {
54708 + rcu_read_unlock();
54709 + in_dev_put(idev);
54710 + dev_put(dev);
54711 + return 0;
54712 + } else if (ret == 2) {
54713 + rcu_read_unlock();
54714 + in_dev_put(idev);
54715 + dev_put(dev);
54716 + goto denied;
54717 + }
54718 + }
54719 + } endfor_ifa(idev);
54720 + rcu_read_unlock();
54721 + in_dev_put(idev);
54722 + dev_put(dev);
54723 + } else {
54724 + our_addr = ip->addr;
54725 + our_netmask = ip->netmask;
54726 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
54727 + if (ret == 1)
54728 + return 0;
54729 + else if (ret == 2)
54730 + goto denied;
54731 + }
54732 + }
54733 +
54734 +denied:
54735 + if (mode == GR_BIND)
54736 + 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));
54737 + else if (mode == GR_CONNECT)
54738 + 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));
54739 +
54740 + return -EACCES;
54741 +}
54742 +
54743 +int
54744 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
54745 +{
54746 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
54747 +}
54748 +
54749 +int
54750 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
54751 +{
54752 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
54753 +}
54754 +
54755 +int gr_search_listen(struct socket *sock)
54756 +{
54757 + struct sock *sk = sock->sk;
54758 + struct sockaddr_in addr;
54759 +
54760 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
54761 + addr.sin_port = inet_sk(sk)->inet_sport;
54762 +
54763 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
54764 +}
54765 +
54766 +int gr_search_accept(struct socket *sock)
54767 +{
54768 + struct sock *sk = sock->sk;
54769 + struct sockaddr_in addr;
54770 +
54771 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
54772 + addr.sin_port = inet_sk(sk)->inet_sport;
54773 +
54774 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
54775 +}
54776 +
54777 +int
54778 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
54779 +{
54780 + if (addr)
54781 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
54782 + else {
54783 + struct sockaddr_in sin;
54784 + const struct inet_sock *inet = inet_sk(sk);
54785 +
54786 + sin.sin_addr.s_addr = inet->inet_daddr;
54787 + sin.sin_port = inet->inet_dport;
54788 +
54789 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
54790 + }
54791 +}
54792 +
54793 +int
54794 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
54795 +{
54796 + struct sockaddr_in sin;
54797 +
54798 + if (unlikely(skb->len < sizeof (struct udphdr)))
54799 + return 0; // skip this packet
54800 +
54801 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
54802 + sin.sin_port = udp_hdr(skb)->source;
54803 +
54804 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
54805 +}
54806 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
54807 new file mode 100644
54808 index 0000000..25f54ef
54809 --- /dev/null
54810 +++ b/grsecurity/gracl_learn.c
54811 @@ -0,0 +1,207 @@
54812 +#include <linux/kernel.h>
54813 +#include <linux/mm.h>
54814 +#include <linux/sched.h>
54815 +#include <linux/poll.h>
54816 +#include <linux/string.h>
54817 +#include <linux/file.h>
54818 +#include <linux/types.h>
54819 +#include <linux/vmalloc.h>
54820 +#include <linux/grinternal.h>
54821 +
54822 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
54823 + size_t count, loff_t *ppos);
54824 +extern int gr_acl_is_enabled(void);
54825 +
54826 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
54827 +static int gr_learn_attached;
54828 +
54829 +/* use a 512k buffer */
54830 +#define LEARN_BUFFER_SIZE (512 * 1024)
54831 +
54832 +static DEFINE_SPINLOCK(gr_learn_lock);
54833 +static DEFINE_MUTEX(gr_learn_user_mutex);
54834 +
54835 +/* we need to maintain two buffers, so that the kernel context of grlearn
54836 + uses a semaphore around the userspace copying, and the other kernel contexts
54837 + use a spinlock when copying into the buffer, since they cannot sleep
54838 +*/
54839 +static char *learn_buffer;
54840 +static char *learn_buffer_user;
54841 +static int learn_buffer_len;
54842 +static int learn_buffer_user_len;
54843 +
54844 +static ssize_t
54845 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
54846 +{
54847 + DECLARE_WAITQUEUE(wait, current);
54848 + ssize_t retval = 0;
54849 +
54850 + add_wait_queue(&learn_wait, &wait);
54851 + set_current_state(TASK_INTERRUPTIBLE);
54852 + do {
54853 + mutex_lock(&gr_learn_user_mutex);
54854 + spin_lock(&gr_learn_lock);
54855 + if (learn_buffer_len)
54856 + break;
54857 + spin_unlock(&gr_learn_lock);
54858 + mutex_unlock(&gr_learn_user_mutex);
54859 + if (file->f_flags & O_NONBLOCK) {
54860 + retval = -EAGAIN;
54861 + goto out;
54862 + }
54863 + if (signal_pending(current)) {
54864 + retval = -ERESTARTSYS;
54865 + goto out;
54866 + }
54867 +
54868 + schedule();
54869 + } while (1);
54870 +
54871 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
54872 + learn_buffer_user_len = learn_buffer_len;
54873 + retval = learn_buffer_len;
54874 + learn_buffer_len = 0;
54875 +
54876 + spin_unlock(&gr_learn_lock);
54877 +
54878 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
54879 + retval = -EFAULT;
54880 +
54881 + mutex_unlock(&gr_learn_user_mutex);
54882 +out:
54883 + set_current_state(TASK_RUNNING);
54884 + remove_wait_queue(&learn_wait, &wait);
54885 + return retval;
54886 +}
54887 +
54888 +static unsigned int
54889 +poll_learn(struct file * file, poll_table * wait)
54890 +{
54891 + poll_wait(file, &learn_wait, wait);
54892 +
54893 + if (learn_buffer_len)
54894 + return (POLLIN | POLLRDNORM);
54895 +
54896 + return 0;
54897 +}
54898 +
54899 +void
54900 +gr_clear_learn_entries(void)
54901 +{
54902 + char *tmp;
54903 +
54904 + mutex_lock(&gr_learn_user_mutex);
54905 + spin_lock(&gr_learn_lock);
54906 + tmp = learn_buffer;
54907 + learn_buffer = NULL;
54908 + spin_unlock(&gr_learn_lock);
54909 + if (tmp)
54910 + vfree(tmp);
54911 + if (learn_buffer_user != NULL) {
54912 + vfree(learn_buffer_user);
54913 + learn_buffer_user = NULL;
54914 + }
54915 + learn_buffer_len = 0;
54916 + mutex_unlock(&gr_learn_user_mutex);
54917 +
54918 + return;
54919 +}
54920 +
54921 +void
54922 +gr_add_learn_entry(const char *fmt, ...)
54923 +{
54924 + va_list args;
54925 + unsigned int len;
54926 +
54927 + if (!gr_learn_attached)
54928 + return;
54929 +
54930 + spin_lock(&gr_learn_lock);
54931 +
54932 + /* leave a gap at the end so we know when it's "full" but don't have to
54933 + compute the exact length of the string we're trying to append
54934 + */
54935 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
54936 + spin_unlock(&gr_learn_lock);
54937 + wake_up_interruptible(&learn_wait);
54938 + return;
54939 + }
54940 + if (learn_buffer == NULL) {
54941 + spin_unlock(&gr_learn_lock);
54942 + return;
54943 + }
54944 +
54945 + va_start(args, fmt);
54946 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
54947 + va_end(args);
54948 +
54949 + learn_buffer_len += len + 1;
54950 +
54951 + spin_unlock(&gr_learn_lock);
54952 + wake_up_interruptible(&learn_wait);
54953 +
54954 + return;
54955 +}
54956 +
54957 +static int
54958 +open_learn(struct inode *inode, struct file *file)
54959 +{
54960 + if (file->f_mode & FMODE_READ && gr_learn_attached)
54961 + return -EBUSY;
54962 + if (file->f_mode & FMODE_READ) {
54963 + int retval = 0;
54964 + mutex_lock(&gr_learn_user_mutex);
54965 + if (learn_buffer == NULL)
54966 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
54967 + if (learn_buffer_user == NULL)
54968 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
54969 + if (learn_buffer == NULL) {
54970 + retval = -ENOMEM;
54971 + goto out_error;
54972 + }
54973 + if (learn_buffer_user == NULL) {
54974 + retval = -ENOMEM;
54975 + goto out_error;
54976 + }
54977 + learn_buffer_len = 0;
54978 + learn_buffer_user_len = 0;
54979 + gr_learn_attached = 1;
54980 +out_error:
54981 + mutex_unlock(&gr_learn_user_mutex);
54982 + return retval;
54983 + }
54984 + return 0;
54985 +}
54986 +
54987 +static int
54988 +close_learn(struct inode *inode, struct file *file)
54989 +{
54990 + if (file->f_mode & FMODE_READ) {
54991 + char *tmp = NULL;
54992 + mutex_lock(&gr_learn_user_mutex);
54993 + spin_lock(&gr_learn_lock);
54994 + tmp = learn_buffer;
54995 + learn_buffer = NULL;
54996 + spin_unlock(&gr_learn_lock);
54997 + if (tmp)
54998 + vfree(tmp);
54999 + if (learn_buffer_user != NULL) {
55000 + vfree(learn_buffer_user);
55001 + learn_buffer_user = NULL;
55002 + }
55003 + learn_buffer_len = 0;
55004 + learn_buffer_user_len = 0;
55005 + gr_learn_attached = 0;
55006 + mutex_unlock(&gr_learn_user_mutex);
55007 + }
55008 +
55009 + return 0;
55010 +}
55011 +
55012 +const struct file_operations grsec_fops = {
55013 + .read = read_learn,
55014 + .write = write_grsec_handler,
55015 + .open = open_learn,
55016 + .release = close_learn,
55017 + .poll = poll_learn,
55018 +};
55019 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
55020 new file mode 100644
55021 index 0000000..39645c9
55022 --- /dev/null
55023 +++ b/grsecurity/gracl_res.c
55024 @@ -0,0 +1,68 @@
55025 +#include <linux/kernel.h>
55026 +#include <linux/sched.h>
55027 +#include <linux/gracl.h>
55028 +#include <linux/grinternal.h>
55029 +
55030 +static const char *restab_log[] = {
55031 + [RLIMIT_CPU] = "RLIMIT_CPU",
55032 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
55033 + [RLIMIT_DATA] = "RLIMIT_DATA",
55034 + [RLIMIT_STACK] = "RLIMIT_STACK",
55035 + [RLIMIT_CORE] = "RLIMIT_CORE",
55036 + [RLIMIT_RSS] = "RLIMIT_RSS",
55037 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
55038 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
55039 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
55040 + [RLIMIT_AS] = "RLIMIT_AS",
55041 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
55042 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
55043 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
55044 + [RLIMIT_NICE] = "RLIMIT_NICE",
55045 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
55046 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
55047 + [GR_CRASH_RES] = "RLIMIT_CRASH"
55048 +};
55049 +
55050 +void
55051 +gr_log_resource(const struct task_struct *task,
55052 + const int res, const unsigned long wanted, const int gt)
55053 +{
55054 + const struct cred *cred;
55055 + unsigned long rlim;
55056 +
55057 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
55058 + return;
55059 +
55060 + // not yet supported resource
55061 + if (unlikely(!restab_log[res]))
55062 + return;
55063 +
55064 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
55065 + rlim = task_rlimit_max(task, res);
55066 + else
55067 + rlim = task_rlimit(task, res);
55068 +
55069 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
55070 + return;
55071 +
55072 + rcu_read_lock();
55073 + cred = __task_cred(task);
55074 +
55075 + if (res == RLIMIT_NPROC &&
55076 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
55077 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
55078 + goto out_rcu_unlock;
55079 + else if (res == RLIMIT_MEMLOCK &&
55080 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
55081 + goto out_rcu_unlock;
55082 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
55083 + goto out_rcu_unlock;
55084 + rcu_read_unlock();
55085 +
55086 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
55087 +
55088 + return;
55089 +out_rcu_unlock:
55090 + rcu_read_unlock();
55091 + return;
55092 +}
55093 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
55094 new file mode 100644
55095 index 0000000..5556be3
55096 --- /dev/null
55097 +++ b/grsecurity/gracl_segv.c
55098 @@ -0,0 +1,299 @@
55099 +#include <linux/kernel.h>
55100 +#include <linux/mm.h>
55101 +#include <asm/uaccess.h>
55102 +#include <asm/errno.h>
55103 +#include <asm/mman.h>
55104 +#include <net/sock.h>
55105 +#include <linux/file.h>
55106 +#include <linux/fs.h>
55107 +#include <linux/net.h>
55108 +#include <linux/in.h>
55109 +#include <linux/slab.h>
55110 +#include <linux/types.h>
55111 +#include <linux/sched.h>
55112 +#include <linux/timer.h>
55113 +#include <linux/gracl.h>
55114 +#include <linux/grsecurity.h>
55115 +#include <linux/grinternal.h>
55116 +
55117 +static struct crash_uid *uid_set;
55118 +static unsigned short uid_used;
55119 +static DEFINE_SPINLOCK(gr_uid_lock);
55120 +extern rwlock_t gr_inode_lock;
55121 +extern struct acl_subject_label *
55122 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
55123 + struct acl_role_label *role);
55124 +
55125 +#ifdef CONFIG_BTRFS_FS
55126 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
55127 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
55128 +#endif
55129 +
55130 +static inline dev_t __get_dev(const struct dentry *dentry)
55131 +{
55132 +#ifdef CONFIG_BTRFS_FS
55133 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
55134 + return get_btrfs_dev_from_inode(dentry->d_inode);
55135 + else
55136 +#endif
55137 + return dentry->d_inode->i_sb->s_dev;
55138 +}
55139 +
55140 +int
55141 +gr_init_uidset(void)
55142 +{
55143 + uid_set =
55144 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
55145 + uid_used = 0;
55146 +
55147 + return uid_set ? 1 : 0;
55148 +}
55149 +
55150 +void
55151 +gr_free_uidset(void)
55152 +{
55153 + if (uid_set)
55154 + kfree(uid_set);
55155 +
55156 + return;
55157 +}
55158 +
55159 +int
55160 +gr_find_uid(const uid_t uid)
55161 +{
55162 + struct crash_uid *tmp = uid_set;
55163 + uid_t buid;
55164 + int low = 0, high = uid_used - 1, mid;
55165 +
55166 + while (high >= low) {
55167 + mid = (low + high) >> 1;
55168 + buid = tmp[mid].uid;
55169 + if (buid == uid)
55170 + return mid;
55171 + if (buid > uid)
55172 + high = mid - 1;
55173 + if (buid < uid)
55174 + low = mid + 1;
55175 + }
55176 +
55177 + return -1;
55178 +}
55179 +
55180 +static __inline__ void
55181 +gr_insertsort(void)
55182 +{
55183 + unsigned short i, j;
55184 + struct crash_uid index;
55185 +
55186 + for (i = 1; i < uid_used; i++) {
55187 + index = uid_set[i];
55188 + j = i;
55189 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
55190 + uid_set[j] = uid_set[j - 1];
55191 + j--;
55192 + }
55193 + uid_set[j] = index;
55194 + }
55195 +
55196 + return;
55197 +}
55198 +
55199 +static __inline__ void
55200 +gr_insert_uid(const uid_t uid, const unsigned long expires)
55201 +{
55202 + int loc;
55203 +
55204 + if (uid_used == GR_UIDTABLE_MAX)
55205 + return;
55206 +
55207 + loc = gr_find_uid(uid);
55208 +
55209 + if (loc >= 0) {
55210 + uid_set[loc].expires = expires;
55211 + return;
55212 + }
55213 +
55214 + uid_set[uid_used].uid = uid;
55215 + uid_set[uid_used].expires = expires;
55216 + uid_used++;
55217 +
55218 + gr_insertsort();
55219 +
55220 + return;
55221 +}
55222 +
55223 +void
55224 +gr_remove_uid(const unsigned short loc)
55225 +{
55226 + unsigned short i;
55227 +
55228 + for (i = loc + 1; i < uid_used; i++)
55229 + uid_set[i - 1] = uid_set[i];
55230 +
55231 + uid_used--;
55232 +
55233 + return;
55234 +}
55235 +
55236 +int
55237 +gr_check_crash_uid(const uid_t uid)
55238 +{
55239 + int loc;
55240 + int ret = 0;
55241 +
55242 + if (unlikely(!gr_acl_is_enabled()))
55243 + return 0;
55244 +
55245 + spin_lock(&gr_uid_lock);
55246 + loc = gr_find_uid(uid);
55247 +
55248 + if (loc < 0)
55249 + goto out_unlock;
55250 +
55251 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
55252 + gr_remove_uid(loc);
55253 + else
55254 + ret = 1;
55255 +
55256 +out_unlock:
55257 + spin_unlock(&gr_uid_lock);
55258 + return ret;
55259 +}
55260 +
55261 +static __inline__ int
55262 +proc_is_setxid(const struct cred *cred)
55263 +{
55264 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
55265 + cred->uid != cred->fsuid)
55266 + return 1;
55267 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
55268 + cred->gid != cred->fsgid)
55269 + return 1;
55270 +
55271 + return 0;
55272 +}
55273 +
55274 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
55275 +
55276 +void
55277 +gr_handle_crash(struct task_struct *task, const int sig)
55278 +{
55279 + struct acl_subject_label *curr;
55280 + struct task_struct *tsk, *tsk2;
55281 + const struct cred *cred;
55282 + const struct cred *cred2;
55283 +
55284 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
55285 + return;
55286 +
55287 + if (unlikely(!gr_acl_is_enabled()))
55288 + return;
55289 +
55290 + curr = task->acl;
55291 +
55292 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
55293 + return;
55294 +
55295 + if (time_before_eq(curr->expires, get_seconds())) {
55296 + curr->expires = 0;
55297 + curr->crashes = 0;
55298 + }
55299 +
55300 + curr->crashes++;
55301 +
55302 + if (!curr->expires)
55303 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
55304 +
55305 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
55306 + time_after(curr->expires, get_seconds())) {
55307 + rcu_read_lock();
55308 + cred = __task_cred(task);
55309 + if (cred->uid && proc_is_setxid(cred)) {
55310 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
55311 + spin_lock(&gr_uid_lock);
55312 + gr_insert_uid(cred->uid, curr->expires);
55313 + spin_unlock(&gr_uid_lock);
55314 + curr->expires = 0;
55315 + curr->crashes = 0;
55316 + read_lock(&tasklist_lock);
55317 + do_each_thread(tsk2, tsk) {
55318 + cred2 = __task_cred(tsk);
55319 + if (tsk != task && cred2->uid == cred->uid)
55320 + gr_fake_force_sig(SIGKILL, tsk);
55321 + } while_each_thread(tsk2, tsk);
55322 + read_unlock(&tasklist_lock);
55323 + } else {
55324 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
55325 + read_lock(&tasklist_lock);
55326 + read_lock(&grsec_exec_file_lock);
55327 + do_each_thread(tsk2, tsk) {
55328 + if (likely(tsk != task)) {
55329 + // if this thread has the same subject as the one that triggered
55330 + // RES_CRASH and it's the same binary, kill it
55331 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
55332 + gr_fake_force_sig(SIGKILL, tsk);
55333 + }
55334 + } while_each_thread(tsk2, tsk);
55335 + read_unlock(&grsec_exec_file_lock);
55336 + read_unlock(&tasklist_lock);
55337 + }
55338 + rcu_read_unlock();
55339 + }
55340 +
55341 + return;
55342 +}
55343 +
55344 +int
55345 +gr_check_crash_exec(const struct file *filp)
55346 +{
55347 + struct acl_subject_label *curr;
55348 +
55349 + if (unlikely(!gr_acl_is_enabled()))
55350 + return 0;
55351 +
55352 + read_lock(&gr_inode_lock);
55353 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
55354 + __get_dev(filp->f_path.dentry),
55355 + current->role);
55356 + read_unlock(&gr_inode_lock);
55357 +
55358 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
55359 + (!curr->crashes && !curr->expires))
55360 + return 0;
55361 +
55362 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
55363 + time_after(curr->expires, get_seconds()))
55364 + return 1;
55365 + else if (time_before_eq(curr->expires, get_seconds())) {
55366 + curr->crashes = 0;
55367 + curr->expires = 0;
55368 + }
55369 +
55370 + return 0;
55371 +}
55372 +
55373 +void
55374 +gr_handle_alertkill(struct task_struct *task)
55375 +{
55376 + struct acl_subject_label *curracl;
55377 + __u32 curr_ip;
55378 + struct task_struct *p, *p2;
55379 +
55380 + if (unlikely(!gr_acl_is_enabled()))
55381 + return;
55382 +
55383 + curracl = task->acl;
55384 + curr_ip = task->signal->curr_ip;
55385 +
55386 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
55387 + read_lock(&tasklist_lock);
55388 + do_each_thread(p2, p) {
55389 + if (p->signal->curr_ip == curr_ip)
55390 + gr_fake_force_sig(SIGKILL, p);
55391 + } while_each_thread(p2, p);
55392 + read_unlock(&tasklist_lock);
55393 + } else if (curracl->mode & GR_KILLPROC)
55394 + gr_fake_force_sig(SIGKILL, task);
55395 +
55396 + return;
55397 +}
55398 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
55399 new file mode 100644
55400 index 0000000..9d83a69
55401 --- /dev/null
55402 +++ b/grsecurity/gracl_shm.c
55403 @@ -0,0 +1,40 @@
55404 +#include <linux/kernel.h>
55405 +#include <linux/mm.h>
55406 +#include <linux/sched.h>
55407 +#include <linux/file.h>
55408 +#include <linux/ipc.h>
55409 +#include <linux/gracl.h>
55410 +#include <linux/grsecurity.h>
55411 +#include <linux/grinternal.h>
55412 +
55413 +int
55414 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
55415 + const time_t shm_createtime, const uid_t cuid, const int shmid)
55416 +{
55417 + struct task_struct *task;
55418 +
55419 + if (!gr_acl_is_enabled())
55420 + return 1;
55421 +
55422 + rcu_read_lock();
55423 + read_lock(&tasklist_lock);
55424 +
55425 + task = find_task_by_vpid(shm_cprid);
55426 +
55427 + if (unlikely(!task))
55428 + task = find_task_by_vpid(shm_lapid);
55429 +
55430 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
55431 + (task->pid == shm_lapid)) &&
55432 + (task->acl->mode & GR_PROTSHM) &&
55433 + (task->acl != current->acl))) {
55434 + read_unlock(&tasklist_lock);
55435 + rcu_read_unlock();
55436 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
55437 + return 0;
55438 + }
55439 + read_unlock(&tasklist_lock);
55440 + rcu_read_unlock();
55441 +
55442 + return 1;
55443 +}
55444 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
55445 new file mode 100644
55446 index 0000000..bc0be01
55447 --- /dev/null
55448 +++ b/grsecurity/grsec_chdir.c
55449 @@ -0,0 +1,19 @@
55450 +#include <linux/kernel.h>
55451 +#include <linux/sched.h>
55452 +#include <linux/fs.h>
55453 +#include <linux/file.h>
55454 +#include <linux/grsecurity.h>
55455 +#include <linux/grinternal.h>
55456 +
55457 +void
55458 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
55459 +{
55460 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
55461 + if ((grsec_enable_chdir && grsec_enable_group &&
55462 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
55463 + !grsec_enable_group)) {
55464 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
55465 + }
55466 +#endif
55467 + return;
55468 +}
55469 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
55470 new file mode 100644
55471 index 0000000..a2dc675
55472 --- /dev/null
55473 +++ b/grsecurity/grsec_chroot.c
55474 @@ -0,0 +1,351 @@
55475 +#include <linux/kernel.h>
55476 +#include <linux/module.h>
55477 +#include <linux/sched.h>
55478 +#include <linux/file.h>
55479 +#include <linux/fs.h>
55480 +#include <linux/mount.h>
55481 +#include <linux/types.h>
55482 +#include <linux/pid_namespace.h>
55483 +#include <linux/grsecurity.h>
55484 +#include <linux/grinternal.h>
55485 +
55486 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
55487 +{
55488 +#ifdef CONFIG_GRKERNSEC
55489 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
55490 + path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
55491 + task->gr_is_chrooted = 1;
55492 + else
55493 + task->gr_is_chrooted = 0;
55494 +
55495 + task->gr_chroot_dentry = path->dentry;
55496 +#endif
55497 + return;
55498 +}
55499 +
55500 +void gr_clear_chroot_entries(struct task_struct *task)
55501 +{
55502 +#ifdef CONFIG_GRKERNSEC
55503 + task->gr_is_chrooted = 0;
55504 + task->gr_chroot_dentry = NULL;
55505 +#endif
55506 + return;
55507 +}
55508 +
55509 +int
55510 +gr_handle_chroot_unix(const pid_t pid)
55511 +{
55512 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
55513 + struct task_struct *p;
55514 +
55515 + if (unlikely(!grsec_enable_chroot_unix))
55516 + return 1;
55517 +
55518 + if (likely(!proc_is_chrooted(current)))
55519 + return 1;
55520 +
55521 + rcu_read_lock();
55522 + read_lock(&tasklist_lock);
55523 + p = find_task_by_vpid_unrestricted(pid);
55524 + if (unlikely(p && !have_same_root(current, p))) {
55525 + read_unlock(&tasklist_lock);
55526 + rcu_read_unlock();
55527 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
55528 + return 0;
55529 + }
55530 + read_unlock(&tasklist_lock);
55531 + rcu_read_unlock();
55532 +#endif
55533 + return 1;
55534 +}
55535 +
55536 +int
55537 +gr_handle_chroot_nice(void)
55538 +{
55539 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
55540 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
55541 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
55542 + return -EPERM;
55543 + }
55544 +#endif
55545 + return 0;
55546 +}
55547 +
55548 +int
55549 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
55550 +{
55551 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
55552 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
55553 + && proc_is_chrooted(current)) {
55554 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
55555 + return -EACCES;
55556 + }
55557 +#endif
55558 + return 0;
55559 +}
55560 +
55561 +int
55562 +gr_handle_chroot_rawio(const struct inode *inode)
55563 +{
55564 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55565 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
55566 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
55567 + return 1;
55568 +#endif
55569 + return 0;
55570 +}
55571 +
55572 +int
55573 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
55574 +{
55575 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
55576 + struct task_struct *p;
55577 + int ret = 0;
55578 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
55579 + return ret;
55580 +
55581 + read_lock(&tasklist_lock);
55582 + do_each_pid_task(pid, type, p) {
55583 + if (!have_same_root(current, p)) {
55584 + ret = 1;
55585 + goto out;
55586 + }
55587 + } while_each_pid_task(pid, type, p);
55588 +out:
55589 + read_unlock(&tasklist_lock);
55590 + return ret;
55591 +#endif
55592 + return 0;
55593 +}
55594 +
55595 +int
55596 +gr_pid_is_chrooted(struct task_struct *p)
55597 +{
55598 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
55599 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
55600 + return 0;
55601 +
55602 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
55603 + !have_same_root(current, p)) {
55604 + return 1;
55605 + }
55606 +#endif
55607 + return 0;
55608 +}
55609 +
55610 +EXPORT_SYMBOL(gr_pid_is_chrooted);
55611 +
55612 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
55613 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
55614 +{
55615 + struct path path, currentroot;
55616 + int ret = 0;
55617 +
55618 + path.dentry = (struct dentry *)u_dentry;
55619 + path.mnt = (struct vfsmount *)u_mnt;
55620 + get_fs_root(current->fs, &currentroot);
55621 + if (path_is_under(&path, &currentroot))
55622 + ret = 1;
55623 + path_put(&currentroot);
55624 +
55625 + return ret;
55626 +}
55627 +#endif
55628 +
55629 +int
55630 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
55631 +{
55632 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
55633 + if (!grsec_enable_chroot_fchdir)
55634 + return 1;
55635 +
55636 + if (!proc_is_chrooted(current))
55637 + return 1;
55638 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
55639 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
55640 + return 0;
55641 + }
55642 +#endif
55643 + return 1;
55644 +}
55645 +
55646 +int
55647 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
55648 + const time_t shm_createtime)
55649 +{
55650 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
55651 + struct task_struct *p;
55652 + time_t starttime;
55653 +
55654 + if (unlikely(!grsec_enable_chroot_shmat))
55655 + return 1;
55656 +
55657 + if (likely(!proc_is_chrooted(current)))
55658 + return 1;
55659 +
55660 + rcu_read_lock();
55661 + read_lock(&tasklist_lock);
55662 +
55663 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
55664 + starttime = p->start_time.tv_sec;
55665 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
55666 + if (have_same_root(current, p)) {
55667 + goto allow;
55668 + } else {
55669 + read_unlock(&tasklist_lock);
55670 + rcu_read_unlock();
55671 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
55672 + return 0;
55673 + }
55674 + }
55675 + /* creator exited, pid reuse, fall through to next check */
55676 + }
55677 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
55678 + if (unlikely(!have_same_root(current, p))) {
55679 + read_unlock(&tasklist_lock);
55680 + rcu_read_unlock();
55681 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
55682 + return 0;
55683 + }
55684 + }
55685 +
55686 +allow:
55687 + read_unlock(&tasklist_lock);
55688 + rcu_read_unlock();
55689 +#endif
55690 + return 1;
55691 +}
55692 +
55693 +void
55694 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
55695 +{
55696 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
55697 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
55698 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
55699 +#endif
55700 + return;
55701 +}
55702 +
55703 +int
55704 +gr_handle_chroot_mknod(const struct dentry *dentry,
55705 + const struct vfsmount *mnt, const int mode)
55706 +{
55707 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
55708 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
55709 + proc_is_chrooted(current)) {
55710 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
55711 + return -EPERM;
55712 + }
55713 +#endif
55714 + return 0;
55715 +}
55716 +
55717 +int
55718 +gr_handle_chroot_mount(const struct dentry *dentry,
55719 + const struct vfsmount *mnt, const char *dev_name)
55720 +{
55721 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
55722 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
55723 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
55724 + return -EPERM;
55725 + }
55726 +#endif
55727 + return 0;
55728 +}
55729 +
55730 +int
55731 +gr_handle_chroot_pivot(void)
55732 +{
55733 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
55734 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
55735 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
55736 + return -EPERM;
55737 + }
55738 +#endif
55739 + return 0;
55740 +}
55741 +
55742 +int
55743 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
55744 +{
55745 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
55746 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
55747 + !gr_is_outside_chroot(dentry, mnt)) {
55748 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
55749 + return -EPERM;
55750 + }
55751 +#endif
55752 + return 0;
55753 +}
55754 +
55755 +extern const char *captab_log[];
55756 +extern int captab_log_entries;
55757 +
55758 +int
55759 +gr_chroot_is_capable(const int cap)
55760 +{
55761 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55762 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
55763 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
55764 + if (cap_raised(chroot_caps, cap)) {
55765 + const struct cred *creds = current_cred();
55766 + if (cap_raised(creds->cap_effective, cap) && cap < captab_log_entries) {
55767 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, current, captab_log[cap]);
55768 + }
55769 + return 0;
55770 + }
55771 + }
55772 +#endif
55773 + return 1;
55774 +}
55775 +
55776 +int
55777 +gr_chroot_is_capable_nolog(const int cap)
55778 +{
55779 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55780 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
55781 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
55782 + if (cap_raised(chroot_caps, cap)) {
55783 + return 0;
55784 + }
55785 + }
55786 +#endif
55787 + return 1;
55788 +}
55789 +
55790 +int
55791 +gr_handle_chroot_sysctl(const int op)
55792 +{
55793 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
55794 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
55795 + proc_is_chrooted(current))
55796 + return -EACCES;
55797 +#endif
55798 + return 0;
55799 +}
55800 +
55801 +void
55802 +gr_handle_chroot_chdir(struct path *path)
55803 +{
55804 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
55805 + if (grsec_enable_chroot_chdir)
55806 + set_fs_pwd(current->fs, path);
55807 +#endif
55808 + return;
55809 +}
55810 +
55811 +int
55812 +gr_handle_chroot_chmod(const struct dentry *dentry,
55813 + const struct vfsmount *mnt, const int mode)
55814 +{
55815 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
55816 + /* allow chmod +s on directories, but not files */
55817 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
55818 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
55819 + proc_is_chrooted(current)) {
55820 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
55821 + return -EPERM;
55822 + }
55823 +#endif
55824 + return 0;
55825 +}
55826 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
55827 new file mode 100644
55828 index 0000000..213ad8b
55829 --- /dev/null
55830 +++ b/grsecurity/grsec_disabled.c
55831 @@ -0,0 +1,437 @@
55832 +#include <linux/kernel.h>
55833 +#include <linux/module.h>
55834 +#include <linux/sched.h>
55835 +#include <linux/file.h>
55836 +#include <linux/fs.h>
55837 +#include <linux/kdev_t.h>
55838 +#include <linux/net.h>
55839 +#include <linux/in.h>
55840 +#include <linux/ip.h>
55841 +#include <linux/skbuff.h>
55842 +#include <linux/sysctl.h>
55843 +
55844 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
55845 +void
55846 +pax_set_initial_flags(struct linux_binprm *bprm)
55847 +{
55848 + return;
55849 +}
55850 +#endif
55851 +
55852 +#ifdef CONFIG_SYSCTL
55853 +__u32
55854 +gr_handle_sysctl(const struct ctl_table * table, const int op)
55855 +{
55856 + return 0;
55857 +}
55858 +#endif
55859 +
55860 +#ifdef CONFIG_TASKSTATS
55861 +int gr_is_taskstats_denied(int pid)
55862 +{
55863 + return 0;
55864 +}
55865 +#endif
55866 +
55867 +int
55868 +gr_acl_is_enabled(void)
55869 +{
55870 + return 0;
55871 +}
55872 +
55873 +void
55874 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
55875 +{
55876 + return;
55877 +}
55878 +
55879 +int
55880 +gr_handle_rawio(const struct inode *inode)
55881 +{
55882 + return 0;
55883 +}
55884 +
55885 +void
55886 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55887 +{
55888 + return;
55889 +}
55890 +
55891 +int
55892 +gr_handle_ptrace(struct task_struct *task, const long request)
55893 +{
55894 + return 0;
55895 +}
55896 +
55897 +int
55898 +gr_handle_proc_ptrace(struct task_struct *task)
55899 +{
55900 + return 0;
55901 +}
55902 +
55903 +void
55904 +gr_learn_resource(const struct task_struct *task,
55905 + const int res, const unsigned long wanted, const int gt)
55906 +{
55907 + return;
55908 +}
55909 +
55910 +int
55911 +gr_set_acls(const int type)
55912 +{
55913 + return 0;
55914 +}
55915 +
55916 +int
55917 +gr_check_hidden_task(const struct task_struct *tsk)
55918 +{
55919 + return 0;
55920 +}
55921 +
55922 +int
55923 +gr_check_protected_task(const struct task_struct *task)
55924 +{
55925 + return 0;
55926 +}
55927 +
55928 +int
55929 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
55930 +{
55931 + return 0;
55932 +}
55933 +
55934 +void
55935 +gr_copy_label(struct task_struct *tsk)
55936 +{
55937 + return;
55938 +}
55939 +
55940 +void
55941 +gr_set_pax_flags(struct task_struct *task)
55942 +{
55943 + return;
55944 +}
55945 +
55946 +int
55947 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
55948 + const int unsafe_share)
55949 +{
55950 + return 0;
55951 +}
55952 +
55953 +void
55954 +gr_handle_delete(const ino_t ino, const dev_t dev)
55955 +{
55956 + return;
55957 +}
55958 +
55959 +void
55960 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
55961 +{
55962 + return;
55963 +}
55964 +
55965 +void
55966 +gr_handle_crash(struct task_struct *task, const int sig)
55967 +{
55968 + return;
55969 +}
55970 +
55971 +int
55972 +gr_check_crash_exec(const struct file *filp)
55973 +{
55974 + return 0;
55975 +}
55976 +
55977 +int
55978 +gr_check_crash_uid(const uid_t uid)
55979 +{
55980 + return 0;
55981 +}
55982 +
55983 +void
55984 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
55985 + struct dentry *old_dentry,
55986 + struct dentry *new_dentry,
55987 + struct vfsmount *mnt, const __u8 replace)
55988 +{
55989 + return;
55990 +}
55991 +
55992 +int
55993 +gr_search_socket(const int family, const int type, const int protocol)
55994 +{
55995 + return 1;
55996 +}
55997 +
55998 +int
55999 +gr_search_connectbind(const int mode, const struct socket *sock,
56000 + const struct sockaddr_in *addr)
56001 +{
56002 + return 0;
56003 +}
56004 +
56005 +void
56006 +gr_handle_alertkill(struct task_struct *task)
56007 +{
56008 + return;
56009 +}
56010 +
56011 +__u32
56012 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
56013 +{
56014 + return 1;
56015 +}
56016 +
56017 +__u32
56018 +gr_acl_handle_hidden_file(const struct dentry * dentry,
56019 + const struct vfsmount * mnt)
56020 +{
56021 + return 1;
56022 +}
56023 +
56024 +__u32
56025 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56026 + int acc_mode)
56027 +{
56028 + return 1;
56029 +}
56030 +
56031 +__u32
56032 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56033 +{
56034 + return 1;
56035 +}
56036 +
56037 +__u32
56038 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
56039 +{
56040 + return 1;
56041 +}
56042 +
56043 +int
56044 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
56045 + unsigned int *vm_flags)
56046 +{
56047 + return 1;
56048 +}
56049 +
56050 +__u32
56051 +gr_acl_handle_truncate(const struct dentry * dentry,
56052 + const struct vfsmount * mnt)
56053 +{
56054 + return 1;
56055 +}
56056 +
56057 +__u32
56058 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
56059 +{
56060 + return 1;
56061 +}
56062 +
56063 +__u32
56064 +gr_acl_handle_access(const struct dentry * dentry,
56065 + const struct vfsmount * mnt, const int fmode)
56066 +{
56067 + return 1;
56068 +}
56069 +
56070 +__u32
56071 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
56072 + umode_t *mode)
56073 +{
56074 + return 1;
56075 +}
56076 +
56077 +__u32
56078 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
56079 +{
56080 + return 1;
56081 +}
56082 +
56083 +__u32
56084 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
56085 +{
56086 + return 1;
56087 +}
56088 +
56089 +void
56090 +grsecurity_init(void)
56091 +{
56092 + return;
56093 +}
56094 +
56095 +umode_t gr_acl_umask(void)
56096 +{
56097 + return 0;
56098 +}
56099 +
56100 +__u32
56101 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56102 + const struct dentry * parent_dentry,
56103 + const struct vfsmount * parent_mnt,
56104 + const int mode)
56105 +{
56106 + return 1;
56107 +}
56108 +
56109 +__u32
56110 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
56111 + const struct dentry * parent_dentry,
56112 + const struct vfsmount * parent_mnt)
56113 +{
56114 + return 1;
56115 +}
56116 +
56117 +__u32
56118 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56119 + const struct dentry * parent_dentry,
56120 + const struct vfsmount * parent_mnt, const char *from)
56121 +{
56122 + return 1;
56123 +}
56124 +
56125 +__u32
56126 +gr_acl_handle_link(const struct dentry * new_dentry,
56127 + const struct dentry * parent_dentry,
56128 + const struct vfsmount * parent_mnt,
56129 + const struct dentry * old_dentry,
56130 + const struct vfsmount * old_mnt, const char *to)
56131 +{
56132 + return 1;
56133 +}
56134 +
56135 +int
56136 +gr_acl_handle_rename(const struct dentry *new_dentry,
56137 + const struct dentry *parent_dentry,
56138 + const struct vfsmount *parent_mnt,
56139 + const struct dentry *old_dentry,
56140 + const struct inode *old_parent_inode,
56141 + const struct vfsmount *old_mnt, const char *newname)
56142 +{
56143 + return 0;
56144 +}
56145 +
56146 +int
56147 +gr_acl_handle_filldir(const struct file *file, const char *name,
56148 + const int namelen, const ino_t ino)
56149 +{
56150 + return 1;
56151 +}
56152 +
56153 +int
56154 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56155 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56156 +{
56157 + return 1;
56158 +}
56159 +
56160 +int
56161 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
56162 +{
56163 + return 0;
56164 +}
56165 +
56166 +int
56167 +gr_search_accept(const struct socket *sock)
56168 +{
56169 + return 0;
56170 +}
56171 +
56172 +int
56173 +gr_search_listen(const struct socket *sock)
56174 +{
56175 + return 0;
56176 +}
56177 +
56178 +int
56179 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
56180 +{
56181 + return 0;
56182 +}
56183 +
56184 +__u32
56185 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
56186 +{
56187 + return 1;
56188 +}
56189 +
56190 +__u32
56191 +gr_acl_handle_creat(const struct dentry * dentry,
56192 + const struct dentry * p_dentry,
56193 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56194 + const int imode)
56195 +{
56196 + return 1;
56197 +}
56198 +
56199 +void
56200 +gr_acl_handle_exit(void)
56201 +{
56202 + return;
56203 +}
56204 +
56205 +int
56206 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
56207 +{
56208 + return 1;
56209 +}
56210 +
56211 +void
56212 +gr_set_role_label(const uid_t uid, const gid_t gid)
56213 +{
56214 + return;
56215 +}
56216 +
56217 +int
56218 +gr_acl_handle_procpidmem(const struct task_struct *task)
56219 +{
56220 + return 0;
56221 +}
56222 +
56223 +int
56224 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
56225 +{
56226 + return 0;
56227 +}
56228 +
56229 +int
56230 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
56231 +{
56232 + return 0;
56233 +}
56234 +
56235 +void
56236 +gr_set_kernel_label(struct task_struct *task)
56237 +{
56238 + return;
56239 +}
56240 +
56241 +int
56242 +gr_check_user_change(int real, int effective, int fs)
56243 +{
56244 + return 0;
56245 +}
56246 +
56247 +int
56248 +gr_check_group_change(int real, int effective, int fs)
56249 +{
56250 + return 0;
56251 +}
56252 +
56253 +int gr_acl_enable_at_secure(void)
56254 +{
56255 + return 0;
56256 +}
56257 +
56258 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
56259 +{
56260 + return dentry->d_inode->i_sb->s_dev;
56261 +}
56262 +
56263 +EXPORT_SYMBOL(gr_learn_resource);
56264 +EXPORT_SYMBOL(gr_set_kernel_label);
56265 +#ifdef CONFIG_SECURITY
56266 +EXPORT_SYMBOL(gr_check_user_change);
56267 +EXPORT_SYMBOL(gr_check_group_change);
56268 +#endif
56269 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
56270 new file mode 100644
56271 index 0000000..2b05ada
56272 --- /dev/null
56273 +++ b/grsecurity/grsec_exec.c
56274 @@ -0,0 +1,146 @@
56275 +#include <linux/kernel.h>
56276 +#include <linux/sched.h>
56277 +#include <linux/file.h>
56278 +#include <linux/binfmts.h>
56279 +#include <linux/fs.h>
56280 +#include <linux/types.h>
56281 +#include <linux/grdefs.h>
56282 +#include <linux/grsecurity.h>
56283 +#include <linux/grinternal.h>
56284 +#include <linux/capability.h>
56285 +#include <linux/module.h>
56286 +
56287 +#include <asm/uaccess.h>
56288 +
56289 +#ifdef CONFIG_GRKERNSEC_EXECLOG
56290 +static char gr_exec_arg_buf[132];
56291 +static DEFINE_MUTEX(gr_exec_arg_mutex);
56292 +#endif
56293 +
56294 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
56295 +
56296 +void
56297 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
56298 +{
56299 +#ifdef CONFIG_GRKERNSEC_EXECLOG
56300 + char *grarg = gr_exec_arg_buf;
56301 + unsigned int i, x, execlen = 0;
56302 + char c;
56303 +
56304 + if (!((grsec_enable_execlog && grsec_enable_group &&
56305 + in_group_p(grsec_audit_gid))
56306 + || (grsec_enable_execlog && !grsec_enable_group)))
56307 + return;
56308 +
56309 + mutex_lock(&gr_exec_arg_mutex);
56310 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
56311 +
56312 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
56313 + const char __user *p;
56314 + unsigned int len;
56315 +
56316 + p = get_user_arg_ptr(argv, i);
56317 + if (IS_ERR(p))
56318 + goto log;
56319 +
56320 + len = strnlen_user(p, 128 - execlen);
56321 + if (len > 128 - execlen)
56322 + len = 128 - execlen;
56323 + else if (len > 0)
56324 + len--;
56325 + if (copy_from_user(grarg + execlen, p, len))
56326 + goto log;
56327 +
56328 + /* rewrite unprintable characters */
56329 + for (x = 0; x < len; x++) {
56330 + c = *(grarg + execlen + x);
56331 + if (c < 32 || c > 126)
56332 + *(grarg + execlen + x) = ' ';
56333 + }
56334 +
56335 + execlen += len;
56336 + *(grarg + execlen) = ' ';
56337 + *(grarg + execlen + 1) = '\0';
56338 + execlen++;
56339 + }
56340 +
56341 + log:
56342 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
56343 + bprm->file->f_path.mnt, grarg);
56344 + mutex_unlock(&gr_exec_arg_mutex);
56345 +#endif
56346 + return;
56347 +}
56348 +
56349 +#ifdef CONFIG_GRKERNSEC
56350 +extern int gr_acl_is_capable(const int cap);
56351 +extern int gr_acl_is_capable_nolog(const int cap);
56352 +extern int gr_chroot_is_capable(const int cap);
56353 +extern int gr_chroot_is_capable_nolog(const int cap);
56354 +#endif
56355 +
56356 +const char *captab_log[] = {
56357 + "CAP_CHOWN",
56358 + "CAP_DAC_OVERRIDE",
56359 + "CAP_DAC_READ_SEARCH",
56360 + "CAP_FOWNER",
56361 + "CAP_FSETID",
56362 + "CAP_KILL",
56363 + "CAP_SETGID",
56364 + "CAP_SETUID",
56365 + "CAP_SETPCAP",
56366 + "CAP_LINUX_IMMUTABLE",
56367 + "CAP_NET_BIND_SERVICE",
56368 + "CAP_NET_BROADCAST",
56369 + "CAP_NET_ADMIN",
56370 + "CAP_NET_RAW",
56371 + "CAP_IPC_LOCK",
56372 + "CAP_IPC_OWNER",
56373 + "CAP_SYS_MODULE",
56374 + "CAP_SYS_RAWIO",
56375 + "CAP_SYS_CHROOT",
56376 + "CAP_SYS_PTRACE",
56377 + "CAP_SYS_PACCT",
56378 + "CAP_SYS_ADMIN",
56379 + "CAP_SYS_BOOT",
56380 + "CAP_SYS_NICE",
56381 + "CAP_SYS_RESOURCE",
56382 + "CAP_SYS_TIME",
56383 + "CAP_SYS_TTY_CONFIG",
56384 + "CAP_MKNOD",
56385 + "CAP_LEASE",
56386 + "CAP_AUDIT_WRITE",
56387 + "CAP_AUDIT_CONTROL",
56388 + "CAP_SETFCAP",
56389 + "CAP_MAC_OVERRIDE",
56390 + "CAP_MAC_ADMIN",
56391 + "CAP_SYSLOG",
56392 + "CAP_WAKE_ALARM"
56393 +};
56394 +
56395 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
56396 +
56397 +int gr_is_capable(const int cap)
56398 +{
56399 +#ifdef CONFIG_GRKERNSEC
56400 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
56401 + return 1;
56402 + return 0;
56403 +#else
56404 + return 1;
56405 +#endif
56406 +}
56407 +
56408 +int gr_is_capable_nolog(const int cap)
56409 +{
56410 +#ifdef CONFIG_GRKERNSEC
56411 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
56412 + return 1;
56413 + return 0;
56414 +#else
56415 + return 1;
56416 +#endif
56417 +}
56418 +
56419 +EXPORT_SYMBOL(gr_is_capable);
56420 +EXPORT_SYMBOL(gr_is_capable_nolog);
56421 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
56422 new file mode 100644
56423 index 0000000..d3ee748
56424 --- /dev/null
56425 +++ b/grsecurity/grsec_fifo.c
56426 @@ -0,0 +1,24 @@
56427 +#include <linux/kernel.h>
56428 +#include <linux/sched.h>
56429 +#include <linux/fs.h>
56430 +#include <linux/file.h>
56431 +#include <linux/grinternal.h>
56432 +
56433 +int
56434 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
56435 + const struct dentry *dir, const int flag, const int acc_mode)
56436 +{
56437 +#ifdef CONFIG_GRKERNSEC_FIFO
56438 + const struct cred *cred = current_cred();
56439 +
56440 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
56441 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
56442 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
56443 + (cred->fsuid != dentry->d_inode->i_uid)) {
56444 + if (!inode_permission(dentry->d_inode, acc_mode))
56445 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
56446 + return -EACCES;
56447 + }
56448 +#endif
56449 + return 0;
56450 +}
56451 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
56452 new file mode 100644
56453 index 0000000..8ca18bf
56454 --- /dev/null
56455 +++ b/grsecurity/grsec_fork.c
56456 @@ -0,0 +1,23 @@
56457 +#include <linux/kernel.h>
56458 +#include <linux/sched.h>
56459 +#include <linux/grsecurity.h>
56460 +#include <linux/grinternal.h>
56461 +#include <linux/errno.h>
56462 +
56463 +void
56464 +gr_log_forkfail(const int retval)
56465 +{
56466 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
56467 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
56468 + switch (retval) {
56469 + case -EAGAIN:
56470 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
56471 + break;
56472 + case -ENOMEM:
56473 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
56474 + break;
56475 + }
56476 + }
56477 +#endif
56478 + return;
56479 +}
56480 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
56481 new file mode 100644
56482 index 0000000..01ddde4
56483 --- /dev/null
56484 +++ b/grsecurity/grsec_init.c
56485 @@ -0,0 +1,277 @@
56486 +#include <linux/kernel.h>
56487 +#include <linux/sched.h>
56488 +#include <linux/mm.h>
56489 +#include <linux/gracl.h>
56490 +#include <linux/slab.h>
56491 +#include <linux/vmalloc.h>
56492 +#include <linux/percpu.h>
56493 +#include <linux/module.h>
56494 +
56495 +int grsec_enable_ptrace_readexec;
56496 +int grsec_enable_setxid;
56497 +int grsec_enable_brute;
56498 +int grsec_enable_link;
56499 +int grsec_enable_dmesg;
56500 +int grsec_enable_harden_ptrace;
56501 +int grsec_enable_fifo;
56502 +int grsec_enable_execlog;
56503 +int grsec_enable_signal;
56504 +int grsec_enable_forkfail;
56505 +int grsec_enable_audit_ptrace;
56506 +int grsec_enable_time;
56507 +int grsec_enable_audit_textrel;
56508 +int grsec_enable_group;
56509 +int grsec_audit_gid;
56510 +int grsec_enable_chdir;
56511 +int grsec_enable_mount;
56512 +int grsec_enable_rofs;
56513 +int grsec_enable_chroot_findtask;
56514 +int grsec_enable_chroot_mount;
56515 +int grsec_enable_chroot_shmat;
56516 +int grsec_enable_chroot_fchdir;
56517 +int grsec_enable_chroot_double;
56518 +int grsec_enable_chroot_pivot;
56519 +int grsec_enable_chroot_chdir;
56520 +int grsec_enable_chroot_chmod;
56521 +int grsec_enable_chroot_mknod;
56522 +int grsec_enable_chroot_nice;
56523 +int grsec_enable_chroot_execlog;
56524 +int grsec_enable_chroot_caps;
56525 +int grsec_enable_chroot_sysctl;
56526 +int grsec_enable_chroot_unix;
56527 +int grsec_enable_tpe;
56528 +int grsec_tpe_gid;
56529 +int grsec_enable_blackhole;
56530 +#ifdef CONFIG_IPV6_MODULE
56531 +EXPORT_SYMBOL(grsec_enable_blackhole);
56532 +#endif
56533 +int grsec_lastack_retries;
56534 +int grsec_enable_tpe_all;
56535 +int grsec_enable_tpe_invert;
56536 +int grsec_enable_socket_all;
56537 +int grsec_socket_all_gid;
56538 +int grsec_enable_socket_client;
56539 +int grsec_socket_client_gid;
56540 +int grsec_enable_socket_server;
56541 +int grsec_socket_server_gid;
56542 +int grsec_resource_logging;
56543 +int grsec_disable_privio;
56544 +int grsec_enable_log_rwxmaps;
56545 +int grsec_lock;
56546 +
56547 +DEFINE_SPINLOCK(grsec_alert_lock);
56548 +unsigned long grsec_alert_wtime = 0;
56549 +unsigned long grsec_alert_fyet = 0;
56550 +
56551 +DEFINE_SPINLOCK(grsec_audit_lock);
56552 +
56553 +DEFINE_RWLOCK(grsec_exec_file_lock);
56554 +
56555 +char *gr_shared_page[4];
56556 +
56557 +char *gr_alert_log_fmt;
56558 +char *gr_audit_log_fmt;
56559 +char *gr_alert_log_buf;
56560 +char *gr_audit_log_buf;
56561 +
56562 +extern struct gr_arg *gr_usermode;
56563 +extern unsigned char *gr_system_salt;
56564 +extern unsigned char *gr_system_sum;
56565 +
56566 +void __init
56567 +grsecurity_init(void)
56568 +{
56569 + int j;
56570 + /* create the per-cpu shared pages */
56571 +
56572 +#ifdef CONFIG_X86
56573 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
56574 +#endif
56575 +
56576 + for (j = 0; j < 4; j++) {
56577 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
56578 + if (gr_shared_page[j] == NULL) {
56579 + panic("Unable to allocate grsecurity shared page");
56580 + return;
56581 + }
56582 + }
56583 +
56584 + /* allocate log buffers */
56585 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
56586 + if (!gr_alert_log_fmt) {
56587 + panic("Unable to allocate grsecurity alert log format buffer");
56588 + return;
56589 + }
56590 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
56591 + if (!gr_audit_log_fmt) {
56592 + panic("Unable to allocate grsecurity audit log format buffer");
56593 + return;
56594 + }
56595 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
56596 + if (!gr_alert_log_buf) {
56597 + panic("Unable to allocate grsecurity alert log buffer");
56598 + return;
56599 + }
56600 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
56601 + if (!gr_audit_log_buf) {
56602 + panic("Unable to allocate grsecurity audit log buffer");
56603 + return;
56604 + }
56605 +
56606 + /* allocate memory for authentication structure */
56607 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
56608 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
56609 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
56610 +
56611 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
56612 + panic("Unable to allocate grsecurity authentication structure");
56613 + return;
56614 + }
56615 +
56616 +
56617 +#ifdef CONFIG_GRKERNSEC_IO
56618 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
56619 + grsec_disable_privio = 1;
56620 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
56621 + grsec_disable_privio = 1;
56622 +#else
56623 + grsec_disable_privio = 0;
56624 +#endif
56625 +#endif
56626 +
56627 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
56628 + /* for backward compatibility, tpe_invert always defaults to on if
56629 + enabled in the kernel
56630 + */
56631 + grsec_enable_tpe_invert = 1;
56632 +#endif
56633 +
56634 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
56635 +#ifndef CONFIG_GRKERNSEC_SYSCTL
56636 + grsec_lock = 1;
56637 +#endif
56638 +
56639 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
56640 + grsec_enable_audit_textrel = 1;
56641 +#endif
56642 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56643 + grsec_enable_log_rwxmaps = 1;
56644 +#endif
56645 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
56646 + grsec_enable_group = 1;
56647 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
56648 +#endif
56649 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
56650 + grsec_enable_ptrace_readexec = 1;
56651 +#endif
56652 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56653 + grsec_enable_chdir = 1;
56654 +#endif
56655 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
56656 + grsec_enable_harden_ptrace = 1;
56657 +#endif
56658 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
56659 + grsec_enable_mount = 1;
56660 +#endif
56661 +#ifdef CONFIG_GRKERNSEC_LINK
56662 + grsec_enable_link = 1;
56663 +#endif
56664 +#ifdef CONFIG_GRKERNSEC_BRUTE
56665 + grsec_enable_brute = 1;
56666 +#endif
56667 +#ifdef CONFIG_GRKERNSEC_DMESG
56668 + grsec_enable_dmesg = 1;
56669 +#endif
56670 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56671 + grsec_enable_blackhole = 1;
56672 + grsec_lastack_retries = 4;
56673 +#endif
56674 +#ifdef CONFIG_GRKERNSEC_FIFO
56675 + grsec_enable_fifo = 1;
56676 +#endif
56677 +#ifdef CONFIG_GRKERNSEC_EXECLOG
56678 + grsec_enable_execlog = 1;
56679 +#endif
56680 +#ifdef CONFIG_GRKERNSEC_SETXID
56681 + grsec_enable_setxid = 1;
56682 +#endif
56683 +#ifdef CONFIG_GRKERNSEC_SIGNAL
56684 + grsec_enable_signal = 1;
56685 +#endif
56686 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
56687 + grsec_enable_forkfail = 1;
56688 +#endif
56689 +#ifdef CONFIG_GRKERNSEC_TIME
56690 + grsec_enable_time = 1;
56691 +#endif
56692 +#ifdef CONFIG_GRKERNSEC_RESLOG
56693 + grsec_resource_logging = 1;
56694 +#endif
56695 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56696 + grsec_enable_chroot_findtask = 1;
56697 +#endif
56698 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56699 + grsec_enable_chroot_unix = 1;
56700 +#endif
56701 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56702 + grsec_enable_chroot_mount = 1;
56703 +#endif
56704 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56705 + grsec_enable_chroot_fchdir = 1;
56706 +#endif
56707 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56708 + grsec_enable_chroot_shmat = 1;
56709 +#endif
56710 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
56711 + grsec_enable_audit_ptrace = 1;
56712 +#endif
56713 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56714 + grsec_enable_chroot_double = 1;
56715 +#endif
56716 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56717 + grsec_enable_chroot_pivot = 1;
56718 +#endif
56719 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56720 + grsec_enable_chroot_chdir = 1;
56721 +#endif
56722 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56723 + grsec_enable_chroot_chmod = 1;
56724 +#endif
56725 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56726 + grsec_enable_chroot_mknod = 1;
56727 +#endif
56728 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56729 + grsec_enable_chroot_nice = 1;
56730 +#endif
56731 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56732 + grsec_enable_chroot_execlog = 1;
56733 +#endif
56734 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56735 + grsec_enable_chroot_caps = 1;
56736 +#endif
56737 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56738 + grsec_enable_chroot_sysctl = 1;
56739 +#endif
56740 +#ifdef CONFIG_GRKERNSEC_TPE
56741 + grsec_enable_tpe = 1;
56742 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
56743 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
56744 + grsec_enable_tpe_all = 1;
56745 +#endif
56746 +#endif
56747 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
56748 + grsec_enable_socket_all = 1;
56749 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
56750 +#endif
56751 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
56752 + grsec_enable_socket_client = 1;
56753 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
56754 +#endif
56755 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
56756 + grsec_enable_socket_server = 1;
56757 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
56758 +#endif
56759 +#endif
56760 +
56761 + return;
56762 +}
56763 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
56764 new file mode 100644
56765 index 0000000..3efe141
56766 --- /dev/null
56767 +++ b/grsecurity/grsec_link.c
56768 @@ -0,0 +1,43 @@
56769 +#include <linux/kernel.h>
56770 +#include <linux/sched.h>
56771 +#include <linux/fs.h>
56772 +#include <linux/file.h>
56773 +#include <linux/grinternal.h>
56774 +
56775 +int
56776 +gr_handle_follow_link(const struct inode *parent,
56777 + const struct inode *inode,
56778 + const struct dentry *dentry, const struct vfsmount *mnt)
56779 +{
56780 +#ifdef CONFIG_GRKERNSEC_LINK
56781 + const struct cred *cred = current_cred();
56782 +
56783 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
56784 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
56785 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
56786 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
56787 + return -EACCES;
56788 + }
56789 +#endif
56790 + return 0;
56791 +}
56792 +
56793 +int
56794 +gr_handle_hardlink(const struct dentry *dentry,
56795 + const struct vfsmount *mnt,
56796 + struct inode *inode, const int mode, const char *to)
56797 +{
56798 +#ifdef CONFIG_GRKERNSEC_LINK
56799 + const struct cred *cred = current_cred();
56800 +
56801 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
56802 + (!S_ISREG(mode) || (mode & S_ISUID) ||
56803 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
56804 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
56805 + !capable(CAP_FOWNER) && cred->uid) {
56806 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
56807 + return -EPERM;
56808 + }
56809 +#endif
56810 + return 0;
56811 +}
56812 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
56813 new file mode 100644
56814 index 0000000..a45d2e9
56815 --- /dev/null
56816 +++ b/grsecurity/grsec_log.c
56817 @@ -0,0 +1,322 @@
56818 +#include <linux/kernel.h>
56819 +#include <linux/sched.h>
56820 +#include <linux/file.h>
56821 +#include <linux/tty.h>
56822 +#include <linux/fs.h>
56823 +#include <linux/grinternal.h>
56824 +
56825 +#ifdef CONFIG_TREE_PREEMPT_RCU
56826 +#define DISABLE_PREEMPT() preempt_disable()
56827 +#define ENABLE_PREEMPT() preempt_enable()
56828 +#else
56829 +#define DISABLE_PREEMPT()
56830 +#define ENABLE_PREEMPT()
56831 +#endif
56832 +
56833 +#define BEGIN_LOCKS(x) \
56834 + DISABLE_PREEMPT(); \
56835 + rcu_read_lock(); \
56836 + read_lock(&tasklist_lock); \
56837 + read_lock(&grsec_exec_file_lock); \
56838 + if (x != GR_DO_AUDIT) \
56839 + spin_lock(&grsec_alert_lock); \
56840 + else \
56841 + spin_lock(&grsec_audit_lock)
56842 +
56843 +#define END_LOCKS(x) \
56844 + if (x != GR_DO_AUDIT) \
56845 + spin_unlock(&grsec_alert_lock); \
56846 + else \
56847 + spin_unlock(&grsec_audit_lock); \
56848 + read_unlock(&grsec_exec_file_lock); \
56849 + read_unlock(&tasklist_lock); \
56850 + rcu_read_unlock(); \
56851 + ENABLE_PREEMPT(); \
56852 + if (x == GR_DONT_AUDIT) \
56853 + gr_handle_alertkill(current)
56854 +
56855 +enum {
56856 + FLOODING,
56857 + NO_FLOODING
56858 +};
56859 +
56860 +extern char *gr_alert_log_fmt;
56861 +extern char *gr_audit_log_fmt;
56862 +extern char *gr_alert_log_buf;
56863 +extern char *gr_audit_log_buf;
56864 +
56865 +static int gr_log_start(int audit)
56866 +{
56867 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
56868 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
56869 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
56870 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
56871 + unsigned long curr_secs = get_seconds();
56872 +
56873 + if (audit == GR_DO_AUDIT)
56874 + goto set_fmt;
56875 +
56876 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
56877 + grsec_alert_wtime = curr_secs;
56878 + grsec_alert_fyet = 0;
56879 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
56880 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
56881 + grsec_alert_fyet++;
56882 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
56883 + grsec_alert_wtime = curr_secs;
56884 + grsec_alert_fyet++;
56885 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
56886 + return FLOODING;
56887 + }
56888 + else return FLOODING;
56889 +
56890 +set_fmt:
56891 +#endif
56892 + memset(buf, 0, PAGE_SIZE);
56893 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
56894 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
56895 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
56896 + } else if (current->signal->curr_ip) {
56897 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
56898 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
56899 + } else if (gr_acl_is_enabled()) {
56900 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
56901 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
56902 + } else {
56903 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
56904 + strcpy(buf, fmt);
56905 + }
56906 +
56907 + return NO_FLOODING;
56908 +}
56909 +
56910 +static void gr_log_middle(int audit, const char *msg, va_list ap)
56911 + __attribute__ ((format (printf, 2, 0)));
56912 +
56913 +static void gr_log_middle(int audit, const char *msg, va_list ap)
56914 +{
56915 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
56916 + unsigned int len = strlen(buf);
56917 +
56918 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
56919 +
56920 + return;
56921 +}
56922 +
56923 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
56924 + __attribute__ ((format (printf, 2, 3)));
56925 +
56926 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
56927 +{
56928 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
56929 + unsigned int len = strlen(buf);
56930 + va_list ap;
56931 +
56932 + va_start(ap, msg);
56933 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
56934 + va_end(ap);
56935 +
56936 + return;
56937 +}
56938 +
56939 +static void gr_log_end(int audit, int append_default)
56940 +{
56941 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
56942 +
56943 + if (append_default) {
56944 + unsigned int len = strlen(buf);
56945 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
56946 + }
56947 +
56948 + printk("%s\n", buf);
56949 +
56950 + return;
56951 +}
56952 +
56953 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
56954 +{
56955 + int logtype;
56956 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
56957 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
56958 + void *voidptr = NULL;
56959 + int num1 = 0, num2 = 0;
56960 + unsigned long ulong1 = 0, ulong2 = 0;
56961 + struct dentry *dentry = NULL;
56962 + struct vfsmount *mnt = NULL;
56963 + struct file *file = NULL;
56964 + struct task_struct *task = NULL;
56965 + const struct cred *cred, *pcred;
56966 + va_list ap;
56967 +
56968 + BEGIN_LOCKS(audit);
56969 + logtype = gr_log_start(audit);
56970 + if (logtype == FLOODING) {
56971 + END_LOCKS(audit);
56972 + return;
56973 + }
56974 + va_start(ap, argtypes);
56975 + switch (argtypes) {
56976 + case GR_TTYSNIFF:
56977 + task = va_arg(ap, struct task_struct *);
56978 + 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);
56979 + break;
56980 + case GR_SYSCTL_HIDDEN:
56981 + str1 = va_arg(ap, char *);
56982 + gr_log_middle_varargs(audit, msg, result, str1);
56983 + break;
56984 + case GR_RBAC:
56985 + dentry = va_arg(ap, struct dentry *);
56986 + mnt = va_arg(ap, struct vfsmount *);
56987 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
56988 + break;
56989 + case GR_RBAC_STR:
56990 + dentry = va_arg(ap, struct dentry *);
56991 + mnt = va_arg(ap, struct vfsmount *);
56992 + str1 = va_arg(ap, char *);
56993 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
56994 + break;
56995 + case GR_STR_RBAC:
56996 + str1 = va_arg(ap, char *);
56997 + dentry = va_arg(ap, struct dentry *);
56998 + mnt = va_arg(ap, struct vfsmount *);
56999 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
57000 + break;
57001 + case GR_RBAC_MODE2:
57002 + dentry = va_arg(ap, struct dentry *);
57003 + mnt = va_arg(ap, struct vfsmount *);
57004 + str1 = va_arg(ap, char *);
57005 + str2 = va_arg(ap, char *);
57006 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
57007 + break;
57008 + case GR_RBAC_MODE3:
57009 + dentry = va_arg(ap, struct dentry *);
57010 + mnt = va_arg(ap, struct vfsmount *);
57011 + str1 = va_arg(ap, char *);
57012 + str2 = va_arg(ap, char *);
57013 + str3 = va_arg(ap, char *);
57014 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
57015 + break;
57016 + case GR_FILENAME:
57017 + dentry = va_arg(ap, struct dentry *);
57018 + mnt = va_arg(ap, struct vfsmount *);
57019 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
57020 + break;
57021 + case GR_STR_FILENAME:
57022 + str1 = va_arg(ap, char *);
57023 + dentry = va_arg(ap, struct dentry *);
57024 + mnt = va_arg(ap, struct vfsmount *);
57025 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
57026 + break;
57027 + case GR_FILENAME_STR:
57028 + dentry = va_arg(ap, struct dentry *);
57029 + mnt = va_arg(ap, struct vfsmount *);
57030 + str1 = va_arg(ap, char *);
57031 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
57032 + break;
57033 + case GR_FILENAME_TWO_INT:
57034 + dentry = va_arg(ap, struct dentry *);
57035 + mnt = va_arg(ap, struct vfsmount *);
57036 + num1 = va_arg(ap, int);
57037 + num2 = va_arg(ap, int);
57038 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
57039 + break;
57040 + case GR_FILENAME_TWO_INT_STR:
57041 + dentry = va_arg(ap, struct dentry *);
57042 + mnt = va_arg(ap, struct vfsmount *);
57043 + num1 = va_arg(ap, int);
57044 + num2 = va_arg(ap, int);
57045 + str1 = va_arg(ap, char *);
57046 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
57047 + break;
57048 + case GR_TEXTREL:
57049 + file = va_arg(ap, struct file *);
57050 + ulong1 = va_arg(ap, unsigned long);
57051 + ulong2 = va_arg(ap, unsigned long);
57052 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
57053 + break;
57054 + case GR_PTRACE:
57055 + task = va_arg(ap, struct task_struct *);
57056 + 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);
57057 + break;
57058 + case GR_RESOURCE:
57059 + task = va_arg(ap, struct task_struct *);
57060 + cred = __task_cred(task);
57061 + pcred = __task_cred(task->real_parent);
57062 + ulong1 = va_arg(ap, unsigned long);
57063 + str1 = va_arg(ap, char *);
57064 + ulong2 = va_arg(ap, unsigned long);
57065 + 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);
57066 + break;
57067 + case GR_CAP:
57068 + task = va_arg(ap, struct task_struct *);
57069 + cred = __task_cred(task);
57070 + pcred = __task_cred(task->real_parent);
57071 + str1 = va_arg(ap, char *);
57072 + 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);
57073 + break;
57074 + case GR_SIG:
57075 + str1 = va_arg(ap, char *);
57076 + voidptr = va_arg(ap, void *);
57077 + gr_log_middle_varargs(audit, msg, str1, voidptr);
57078 + break;
57079 + case GR_SIG2:
57080 + task = va_arg(ap, struct task_struct *);
57081 + cred = __task_cred(task);
57082 + pcred = __task_cred(task->real_parent);
57083 + num1 = va_arg(ap, int);
57084 + 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);
57085 + break;
57086 + case GR_CRASH1:
57087 + task = va_arg(ap, struct task_struct *);
57088 + cred = __task_cred(task);
57089 + pcred = __task_cred(task->real_parent);
57090 + ulong1 = va_arg(ap, unsigned long);
57091 + 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);
57092 + break;
57093 + case GR_CRASH2:
57094 + task = va_arg(ap, struct task_struct *);
57095 + cred = __task_cred(task);
57096 + pcred = __task_cred(task->real_parent);
57097 + ulong1 = va_arg(ap, unsigned long);
57098 + 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);
57099 + break;
57100 + case GR_RWXMAP:
57101 + file = va_arg(ap, struct file *);
57102 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
57103 + break;
57104 + case GR_PSACCT:
57105 + {
57106 + unsigned int wday, cday;
57107 + __u8 whr, chr;
57108 + __u8 wmin, cmin;
57109 + __u8 wsec, csec;
57110 + char cur_tty[64] = { 0 };
57111 + char parent_tty[64] = { 0 };
57112 +
57113 + task = va_arg(ap, struct task_struct *);
57114 + wday = va_arg(ap, unsigned int);
57115 + cday = va_arg(ap, unsigned int);
57116 + whr = va_arg(ap, int);
57117 + chr = va_arg(ap, int);
57118 + wmin = va_arg(ap, int);
57119 + cmin = va_arg(ap, int);
57120 + wsec = va_arg(ap, int);
57121 + csec = va_arg(ap, int);
57122 + ulong1 = va_arg(ap, unsigned long);
57123 + cred = __task_cred(task);
57124 + pcred = __task_cred(task->real_parent);
57125 +
57126 + 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);
57127 + }
57128 + break;
57129 + default:
57130 + gr_log_middle(audit, msg, ap);
57131 + }
57132 + va_end(ap);
57133 + // these don't need DEFAULTSECARGS printed on the end
57134 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
57135 + gr_log_end(audit, 0);
57136 + else
57137 + gr_log_end(audit, 1);
57138 + END_LOCKS(audit);
57139 +}
57140 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
57141 new file mode 100644
57142 index 0000000..f536303
57143 --- /dev/null
57144 +++ b/grsecurity/grsec_mem.c
57145 @@ -0,0 +1,40 @@
57146 +#include <linux/kernel.h>
57147 +#include <linux/sched.h>
57148 +#include <linux/mm.h>
57149 +#include <linux/mman.h>
57150 +#include <linux/grinternal.h>
57151 +
57152 +void
57153 +gr_handle_ioperm(void)
57154 +{
57155 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
57156 + return;
57157 +}
57158 +
57159 +void
57160 +gr_handle_iopl(void)
57161 +{
57162 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
57163 + return;
57164 +}
57165 +
57166 +void
57167 +gr_handle_mem_readwrite(u64 from, u64 to)
57168 +{
57169 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
57170 + return;
57171 +}
57172 +
57173 +void
57174 +gr_handle_vm86(void)
57175 +{
57176 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
57177 + return;
57178 +}
57179 +
57180 +void
57181 +gr_log_badprocpid(const char *entry)
57182 +{
57183 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
57184 + return;
57185 +}
57186 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
57187 new file mode 100644
57188 index 0000000..2131422
57189 --- /dev/null
57190 +++ b/grsecurity/grsec_mount.c
57191 @@ -0,0 +1,62 @@
57192 +#include <linux/kernel.h>
57193 +#include <linux/sched.h>
57194 +#include <linux/mount.h>
57195 +#include <linux/grsecurity.h>
57196 +#include <linux/grinternal.h>
57197 +
57198 +void
57199 +gr_log_remount(const char *devname, const int retval)
57200 +{
57201 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57202 + if (grsec_enable_mount && (retval >= 0))
57203 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
57204 +#endif
57205 + return;
57206 +}
57207 +
57208 +void
57209 +gr_log_unmount(const char *devname, const int retval)
57210 +{
57211 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57212 + if (grsec_enable_mount && (retval >= 0))
57213 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
57214 +#endif
57215 + return;
57216 +}
57217 +
57218 +void
57219 +gr_log_mount(const char *from, const char *to, const int retval)
57220 +{
57221 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57222 + if (grsec_enable_mount && (retval >= 0))
57223 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
57224 +#endif
57225 + return;
57226 +}
57227 +
57228 +int
57229 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
57230 +{
57231 +#ifdef CONFIG_GRKERNSEC_ROFS
57232 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
57233 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
57234 + return -EPERM;
57235 + } else
57236 + return 0;
57237 +#endif
57238 + return 0;
57239 +}
57240 +
57241 +int
57242 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
57243 +{
57244 +#ifdef CONFIG_GRKERNSEC_ROFS
57245 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
57246 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
57247 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
57248 + return -EPERM;
57249 + } else
57250 + return 0;
57251 +#endif
57252 + return 0;
57253 +}
57254 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
57255 new file mode 100644
57256 index 0000000..a3b12a0
57257 --- /dev/null
57258 +++ b/grsecurity/grsec_pax.c
57259 @@ -0,0 +1,36 @@
57260 +#include <linux/kernel.h>
57261 +#include <linux/sched.h>
57262 +#include <linux/mm.h>
57263 +#include <linux/file.h>
57264 +#include <linux/grinternal.h>
57265 +#include <linux/grsecurity.h>
57266 +
57267 +void
57268 +gr_log_textrel(struct vm_area_struct * vma)
57269 +{
57270 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57271 + if (grsec_enable_audit_textrel)
57272 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
57273 +#endif
57274 + return;
57275 +}
57276 +
57277 +void
57278 +gr_log_rwxmmap(struct file *file)
57279 +{
57280 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57281 + if (grsec_enable_log_rwxmaps)
57282 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
57283 +#endif
57284 + return;
57285 +}
57286 +
57287 +void
57288 +gr_log_rwxmprotect(struct file *file)
57289 +{
57290 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57291 + if (grsec_enable_log_rwxmaps)
57292 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
57293 +#endif
57294 + return;
57295 +}
57296 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
57297 new file mode 100644
57298 index 0000000..f7f29aa
57299 --- /dev/null
57300 +++ b/grsecurity/grsec_ptrace.c
57301 @@ -0,0 +1,30 @@
57302 +#include <linux/kernel.h>
57303 +#include <linux/sched.h>
57304 +#include <linux/grinternal.h>
57305 +#include <linux/security.h>
57306 +
57307 +void
57308 +gr_audit_ptrace(struct task_struct *task)
57309 +{
57310 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57311 + if (grsec_enable_audit_ptrace)
57312 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
57313 +#endif
57314 + return;
57315 +}
57316 +
57317 +int
57318 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
57319 +{
57320 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57321 + const struct dentry *dentry = file->f_path.dentry;
57322 + const struct vfsmount *mnt = file->f_path.mnt;
57323 +
57324 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
57325 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
57326 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
57327 + return -EACCES;
57328 + }
57329 +#endif
57330 + return 0;
57331 +}
57332 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
57333 new file mode 100644
57334 index 0000000..7a5b2de
57335 --- /dev/null
57336 +++ b/grsecurity/grsec_sig.c
57337 @@ -0,0 +1,207 @@
57338 +#include <linux/kernel.h>
57339 +#include <linux/sched.h>
57340 +#include <linux/delay.h>
57341 +#include <linux/grsecurity.h>
57342 +#include <linux/grinternal.h>
57343 +#include <linux/hardirq.h>
57344 +
57345 +char *signames[] = {
57346 + [SIGSEGV] = "Segmentation fault",
57347 + [SIGILL] = "Illegal instruction",
57348 + [SIGABRT] = "Abort",
57349 + [SIGBUS] = "Invalid alignment/Bus error"
57350 +};
57351 +
57352 +void
57353 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
57354 +{
57355 +#ifdef CONFIG_GRKERNSEC_SIGNAL
57356 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
57357 + (sig == SIGABRT) || (sig == SIGBUS))) {
57358 + if (t->pid == current->pid) {
57359 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
57360 + } else {
57361 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
57362 + }
57363 + }
57364 +#endif
57365 + return;
57366 +}
57367 +
57368 +int
57369 +gr_handle_signal(const struct task_struct *p, const int sig)
57370 +{
57371 +#ifdef CONFIG_GRKERNSEC
57372 + /* ignore the 0 signal for protected task checks */
57373 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
57374 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
57375 + return -EPERM;
57376 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
57377 + return -EPERM;
57378 + }
57379 +#endif
57380 + return 0;
57381 +}
57382 +
57383 +#ifdef CONFIG_GRKERNSEC
57384 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
57385 +
57386 +int gr_fake_force_sig(int sig, struct task_struct *t)
57387 +{
57388 + unsigned long int flags;
57389 + int ret, blocked, ignored;
57390 + struct k_sigaction *action;
57391 +
57392 + spin_lock_irqsave(&t->sighand->siglock, flags);
57393 + action = &t->sighand->action[sig-1];
57394 + ignored = action->sa.sa_handler == SIG_IGN;
57395 + blocked = sigismember(&t->blocked, sig);
57396 + if (blocked || ignored) {
57397 + action->sa.sa_handler = SIG_DFL;
57398 + if (blocked) {
57399 + sigdelset(&t->blocked, sig);
57400 + recalc_sigpending_and_wake(t);
57401 + }
57402 + }
57403 + if (action->sa.sa_handler == SIG_DFL)
57404 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
57405 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
57406 +
57407 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
57408 +
57409 + return ret;
57410 +}
57411 +#endif
57412 +
57413 +#ifdef CONFIG_GRKERNSEC_BRUTE
57414 +#define GR_USER_BAN_TIME (15 * 60)
57415 +
57416 +static int __get_dumpable(unsigned long mm_flags)
57417 +{
57418 + int ret;
57419 +
57420 + ret = mm_flags & MMF_DUMPABLE_MASK;
57421 + return (ret >= 2) ? 2 : ret;
57422 +}
57423 +#endif
57424 +
57425 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
57426 +{
57427 +#ifdef CONFIG_GRKERNSEC_BRUTE
57428 + uid_t uid = 0;
57429 +
57430 + if (!grsec_enable_brute)
57431 + return;
57432 +
57433 + rcu_read_lock();
57434 + read_lock(&tasklist_lock);
57435 + read_lock(&grsec_exec_file_lock);
57436 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
57437 + p->real_parent->brute = 1;
57438 + else {
57439 + const struct cred *cred = __task_cred(p), *cred2;
57440 + struct task_struct *tsk, *tsk2;
57441 +
57442 + if (!__get_dumpable(mm_flags) && cred->uid) {
57443 + struct user_struct *user;
57444 +
57445 + uid = cred->uid;
57446 +
57447 + /* this is put upon execution past expiration */
57448 + user = find_user(uid);
57449 + if (user == NULL)
57450 + goto unlock;
57451 + user->banned = 1;
57452 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
57453 + if (user->ban_expires == ~0UL)
57454 + user->ban_expires--;
57455 +
57456 + do_each_thread(tsk2, tsk) {
57457 + cred2 = __task_cred(tsk);
57458 + if (tsk != p && cred2->uid == uid)
57459 + gr_fake_force_sig(SIGKILL, tsk);
57460 + } while_each_thread(tsk2, tsk);
57461 + }
57462 + }
57463 +unlock:
57464 + read_unlock(&grsec_exec_file_lock);
57465 + read_unlock(&tasklist_lock);
57466 + rcu_read_unlock();
57467 +
57468 + if (uid)
57469 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
57470 +
57471 +#endif
57472 + return;
57473 +}
57474 +
57475 +void gr_handle_brute_check(void)
57476 +{
57477 +#ifdef CONFIG_GRKERNSEC_BRUTE
57478 + if (current->brute)
57479 + msleep(30 * 1000);
57480 +#endif
57481 + return;
57482 +}
57483 +
57484 +void gr_handle_kernel_exploit(void)
57485 +{
57486 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
57487 + const struct cred *cred;
57488 + struct task_struct *tsk, *tsk2;
57489 + struct user_struct *user;
57490 + uid_t uid;
57491 +
57492 + if (in_irq() || in_serving_softirq() || in_nmi())
57493 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
57494 +
57495 + uid = current_uid();
57496 +
57497 + if (uid == 0)
57498 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
57499 + else {
57500 + /* kill all the processes of this user, hold a reference
57501 + to their creds struct, and prevent them from creating
57502 + another process until system reset
57503 + */
57504 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
57505 + /* we intentionally leak this ref */
57506 + user = get_uid(current->cred->user);
57507 + if (user) {
57508 + user->banned = 1;
57509 + user->ban_expires = ~0UL;
57510 + }
57511 +
57512 + read_lock(&tasklist_lock);
57513 + do_each_thread(tsk2, tsk) {
57514 + cred = __task_cred(tsk);
57515 + if (cred->uid == uid)
57516 + gr_fake_force_sig(SIGKILL, tsk);
57517 + } while_each_thread(tsk2, tsk);
57518 + read_unlock(&tasklist_lock);
57519 + }
57520 +#endif
57521 +}
57522 +
57523 +int __gr_process_user_ban(struct user_struct *user)
57524 +{
57525 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
57526 + if (unlikely(user->banned)) {
57527 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
57528 + user->banned = 0;
57529 + user->ban_expires = 0;
57530 + free_uid(user);
57531 + } else
57532 + return -EPERM;
57533 + }
57534 +#endif
57535 + return 0;
57536 +}
57537 +
57538 +int gr_process_user_ban(void)
57539 +{
57540 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
57541 + return __gr_process_user_ban(current->cred->user);
57542 +#endif
57543 + return 0;
57544 +}
57545 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
57546 new file mode 100644
57547 index 0000000..4030d57
57548 --- /dev/null
57549 +++ b/grsecurity/grsec_sock.c
57550 @@ -0,0 +1,244 @@
57551 +#include <linux/kernel.h>
57552 +#include <linux/module.h>
57553 +#include <linux/sched.h>
57554 +#include <linux/file.h>
57555 +#include <linux/net.h>
57556 +#include <linux/in.h>
57557 +#include <linux/ip.h>
57558 +#include <net/sock.h>
57559 +#include <net/inet_sock.h>
57560 +#include <linux/grsecurity.h>
57561 +#include <linux/grinternal.h>
57562 +#include <linux/gracl.h>
57563 +
57564 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
57565 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
57566 +
57567 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
57568 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
57569 +
57570 +#ifdef CONFIG_UNIX_MODULE
57571 +EXPORT_SYMBOL(gr_acl_handle_unix);
57572 +EXPORT_SYMBOL(gr_acl_handle_mknod);
57573 +EXPORT_SYMBOL(gr_handle_chroot_unix);
57574 +EXPORT_SYMBOL(gr_handle_create);
57575 +#endif
57576 +
57577 +#ifdef CONFIG_GRKERNSEC
57578 +#define gr_conn_table_size 32749
57579 +struct conn_table_entry {
57580 + struct conn_table_entry *next;
57581 + struct signal_struct *sig;
57582 +};
57583 +
57584 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
57585 +DEFINE_SPINLOCK(gr_conn_table_lock);
57586 +
57587 +extern const char * gr_socktype_to_name(unsigned char type);
57588 +extern const char * gr_proto_to_name(unsigned char proto);
57589 +extern const char * gr_sockfamily_to_name(unsigned char family);
57590 +
57591 +static __inline__ int
57592 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
57593 +{
57594 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
57595 +}
57596 +
57597 +static __inline__ int
57598 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
57599 + __u16 sport, __u16 dport)
57600 +{
57601 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
57602 + sig->gr_sport == sport && sig->gr_dport == dport))
57603 + return 1;
57604 + else
57605 + return 0;
57606 +}
57607 +
57608 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
57609 +{
57610 + struct conn_table_entry **match;
57611 + unsigned int index;
57612 +
57613 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
57614 + sig->gr_sport, sig->gr_dport,
57615 + gr_conn_table_size);
57616 +
57617 + newent->sig = sig;
57618 +
57619 + match = &gr_conn_table[index];
57620 + newent->next = *match;
57621 + *match = newent;
57622 +
57623 + return;
57624 +}
57625 +
57626 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
57627 +{
57628 + struct conn_table_entry *match, *last = NULL;
57629 + unsigned int index;
57630 +
57631 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
57632 + sig->gr_sport, sig->gr_dport,
57633 + gr_conn_table_size);
57634 +
57635 + match = gr_conn_table[index];
57636 + while (match && !conn_match(match->sig,
57637 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
57638 + sig->gr_dport)) {
57639 + last = match;
57640 + match = match->next;
57641 + }
57642 +
57643 + if (match) {
57644 + if (last)
57645 + last->next = match->next;
57646 + else
57647 + gr_conn_table[index] = NULL;
57648 + kfree(match);
57649 + }
57650 +
57651 + return;
57652 +}
57653 +
57654 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
57655 + __u16 sport, __u16 dport)
57656 +{
57657 + struct conn_table_entry *match;
57658 + unsigned int index;
57659 +
57660 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
57661 +
57662 + match = gr_conn_table[index];
57663 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
57664 + match = match->next;
57665 +
57666 + if (match)
57667 + return match->sig;
57668 + else
57669 + return NULL;
57670 +}
57671 +
57672 +#endif
57673 +
57674 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
57675 +{
57676 +#ifdef CONFIG_GRKERNSEC
57677 + struct signal_struct *sig = task->signal;
57678 + struct conn_table_entry *newent;
57679 +
57680 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
57681 + if (newent == NULL)
57682 + return;
57683 + /* no bh lock needed since we are called with bh disabled */
57684 + spin_lock(&gr_conn_table_lock);
57685 + gr_del_task_from_ip_table_nolock(sig);
57686 + sig->gr_saddr = inet->inet_rcv_saddr;
57687 + sig->gr_daddr = inet->inet_daddr;
57688 + sig->gr_sport = inet->inet_sport;
57689 + sig->gr_dport = inet->inet_dport;
57690 + gr_add_to_task_ip_table_nolock(sig, newent);
57691 + spin_unlock(&gr_conn_table_lock);
57692 +#endif
57693 + return;
57694 +}
57695 +
57696 +void gr_del_task_from_ip_table(struct task_struct *task)
57697 +{
57698 +#ifdef CONFIG_GRKERNSEC
57699 + spin_lock_bh(&gr_conn_table_lock);
57700 + gr_del_task_from_ip_table_nolock(task->signal);
57701 + spin_unlock_bh(&gr_conn_table_lock);
57702 +#endif
57703 + return;
57704 +}
57705 +
57706 +void
57707 +gr_attach_curr_ip(const struct sock *sk)
57708 +{
57709 +#ifdef CONFIG_GRKERNSEC
57710 + struct signal_struct *p, *set;
57711 + const struct inet_sock *inet = inet_sk(sk);
57712 +
57713 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
57714 + return;
57715 +
57716 + set = current->signal;
57717 +
57718 + spin_lock_bh(&gr_conn_table_lock);
57719 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
57720 + inet->inet_dport, inet->inet_sport);
57721 + if (unlikely(p != NULL)) {
57722 + set->curr_ip = p->curr_ip;
57723 + set->used_accept = 1;
57724 + gr_del_task_from_ip_table_nolock(p);
57725 + spin_unlock_bh(&gr_conn_table_lock);
57726 + return;
57727 + }
57728 + spin_unlock_bh(&gr_conn_table_lock);
57729 +
57730 + set->curr_ip = inet->inet_daddr;
57731 + set->used_accept = 1;
57732 +#endif
57733 + return;
57734 +}
57735 +
57736 +int
57737 +gr_handle_sock_all(const int family, const int type, const int protocol)
57738 +{
57739 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
57740 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
57741 + (family != AF_UNIX)) {
57742 + if (family == AF_INET)
57743 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
57744 + else
57745 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
57746 + return -EACCES;
57747 + }
57748 +#endif
57749 + return 0;
57750 +}
57751 +
57752 +int
57753 +gr_handle_sock_server(const struct sockaddr *sck)
57754 +{
57755 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57756 + if (grsec_enable_socket_server &&
57757 + in_group_p(grsec_socket_server_gid) &&
57758 + sck && (sck->sa_family != AF_UNIX) &&
57759 + (sck->sa_family != AF_LOCAL)) {
57760 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
57761 + return -EACCES;
57762 + }
57763 +#endif
57764 + return 0;
57765 +}
57766 +
57767 +int
57768 +gr_handle_sock_server_other(const struct sock *sck)
57769 +{
57770 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57771 + if (grsec_enable_socket_server &&
57772 + in_group_p(grsec_socket_server_gid) &&
57773 + sck && (sck->sk_family != AF_UNIX) &&
57774 + (sck->sk_family != AF_LOCAL)) {
57775 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
57776 + return -EACCES;
57777 + }
57778 +#endif
57779 + return 0;
57780 +}
57781 +
57782 +int
57783 +gr_handle_sock_client(const struct sockaddr *sck)
57784 +{
57785 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
57786 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
57787 + sck && (sck->sa_family != AF_UNIX) &&
57788 + (sck->sa_family != AF_LOCAL)) {
57789 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
57790 + return -EACCES;
57791 + }
57792 +#endif
57793 + return 0;
57794 +}
57795 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
57796 new file mode 100644
57797 index 0000000..a1aedd7
57798 --- /dev/null
57799 +++ b/grsecurity/grsec_sysctl.c
57800 @@ -0,0 +1,451 @@
57801 +#include <linux/kernel.h>
57802 +#include <linux/sched.h>
57803 +#include <linux/sysctl.h>
57804 +#include <linux/grsecurity.h>
57805 +#include <linux/grinternal.h>
57806 +
57807 +int
57808 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
57809 +{
57810 +#ifdef CONFIG_GRKERNSEC_SYSCTL
57811 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
57812 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
57813 + return -EACCES;
57814 + }
57815 +#endif
57816 + return 0;
57817 +}
57818 +
57819 +#ifdef CONFIG_GRKERNSEC_ROFS
57820 +static int __maybe_unused one = 1;
57821 +#endif
57822 +
57823 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
57824 +struct ctl_table grsecurity_table[] = {
57825 +#ifdef CONFIG_GRKERNSEC_SYSCTL
57826 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
57827 +#ifdef CONFIG_GRKERNSEC_IO
57828 + {
57829 + .procname = "disable_priv_io",
57830 + .data = &grsec_disable_privio,
57831 + .maxlen = sizeof(int),
57832 + .mode = 0600,
57833 + .proc_handler = &proc_dointvec,
57834 + },
57835 +#endif
57836 +#endif
57837 +#ifdef CONFIG_GRKERNSEC_LINK
57838 + {
57839 + .procname = "linking_restrictions",
57840 + .data = &grsec_enable_link,
57841 + .maxlen = sizeof(int),
57842 + .mode = 0600,
57843 + .proc_handler = &proc_dointvec,
57844 + },
57845 +#endif
57846 +#ifdef CONFIG_GRKERNSEC_BRUTE
57847 + {
57848 + .procname = "deter_bruteforce",
57849 + .data = &grsec_enable_brute,
57850 + .maxlen = sizeof(int),
57851 + .mode = 0600,
57852 + .proc_handler = &proc_dointvec,
57853 + },
57854 +#endif
57855 +#ifdef CONFIG_GRKERNSEC_FIFO
57856 + {
57857 + .procname = "fifo_restrictions",
57858 + .data = &grsec_enable_fifo,
57859 + .maxlen = sizeof(int),
57860 + .mode = 0600,
57861 + .proc_handler = &proc_dointvec,
57862 + },
57863 +#endif
57864 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57865 + {
57866 + .procname = "ptrace_readexec",
57867 + .data = &grsec_enable_ptrace_readexec,
57868 + .maxlen = sizeof(int),
57869 + .mode = 0600,
57870 + .proc_handler = &proc_dointvec,
57871 + },
57872 +#endif
57873 +#ifdef CONFIG_GRKERNSEC_SETXID
57874 + {
57875 + .procname = "consistent_setxid",
57876 + .data = &grsec_enable_setxid,
57877 + .maxlen = sizeof(int),
57878 + .mode = 0600,
57879 + .proc_handler = &proc_dointvec,
57880 + },
57881 +#endif
57882 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57883 + {
57884 + .procname = "ip_blackhole",
57885 + .data = &grsec_enable_blackhole,
57886 + .maxlen = sizeof(int),
57887 + .mode = 0600,
57888 + .proc_handler = &proc_dointvec,
57889 + },
57890 + {
57891 + .procname = "lastack_retries",
57892 + .data = &grsec_lastack_retries,
57893 + .maxlen = sizeof(int),
57894 + .mode = 0600,
57895 + .proc_handler = &proc_dointvec,
57896 + },
57897 +#endif
57898 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57899 + {
57900 + .procname = "exec_logging",
57901 + .data = &grsec_enable_execlog,
57902 + .maxlen = sizeof(int),
57903 + .mode = 0600,
57904 + .proc_handler = &proc_dointvec,
57905 + },
57906 +#endif
57907 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57908 + {
57909 + .procname = "rwxmap_logging",
57910 + .data = &grsec_enable_log_rwxmaps,
57911 + .maxlen = sizeof(int),
57912 + .mode = 0600,
57913 + .proc_handler = &proc_dointvec,
57914 + },
57915 +#endif
57916 +#ifdef CONFIG_GRKERNSEC_SIGNAL
57917 + {
57918 + .procname = "signal_logging",
57919 + .data = &grsec_enable_signal,
57920 + .maxlen = sizeof(int),
57921 + .mode = 0600,
57922 + .proc_handler = &proc_dointvec,
57923 + },
57924 +#endif
57925 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57926 + {
57927 + .procname = "forkfail_logging",
57928 + .data = &grsec_enable_forkfail,
57929 + .maxlen = sizeof(int),
57930 + .mode = 0600,
57931 + .proc_handler = &proc_dointvec,
57932 + },
57933 +#endif
57934 +#ifdef CONFIG_GRKERNSEC_TIME
57935 + {
57936 + .procname = "timechange_logging",
57937 + .data = &grsec_enable_time,
57938 + .maxlen = sizeof(int),
57939 + .mode = 0600,
57940 + .proc_handler = &proc_dointvec,
57941 + },
57942 +#endif
57943 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57944 + {
57945 + .procname = "chroot_deny_shmat",
57946 + .data = &grsec_enable_chroot_shmat,
57947 + .maxlen = sizeof(int),
57948 + .mode = 0600,
57949 + .proc_handler = &proc_dointvec,
57950 + },
57951 +#endif
57952 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57953 + {
57954 + .procname = "chroot_deny_unix",
57955 + .data = &grsec_enable_chroot_unix,
57956 + .maxlen = sizeof(int),
57957 + .mode = 0600,
57958 + .proc_handler = &proc_dointvec,
57959 + },
57960 +#endif
57961 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57962 + {
57963 + .procname = "chroot_deny_mount",
57964 + .data = &grsec_enable_chroot_mount,
57965 + .maxlen = sizeof(int),
57966 + .mode = 0600,
57967 + .proc_handler = &proc_dointvec,
57968 + },
57969 +#endif
57970 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57971 + {
57972 + .procname = "chroot_deny_fchdir",
57973 + .data = &grsec_enable_chroot_fchdir,
57974 + .maxlen = sizeof(int),
57975 + .mode = 0600,
57976 + .proc_handler = &proc_dointvec,
57977 + },
57978 +#endif
57979 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57980 + {
57981 + .procname = "chroot_deny_chroot",
57982 + .data = &grsec_enable_chroot_double,
57983 + .maxlen = sizeof(int),
57984 + .mode = 0600,
57985 + .proc_handler = &proc_dointvec,
57986 + },
57987 +#endif
57988 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57989 + {
57990 + .procname = "chroot_deny_pivot",
57991 + .data = &grsec_enable_chroot_pivot,
57992 + .maxlen = sizeof(int),
57993 + .mode = 0600,
57994 + .proc_handler = &proc_dointvec,
57995 + },
57996 +#endif
57997 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57998 + {
57999 + .procname = "chroot_enforce_chdir",
58000 + .data = &grsec_enable_chroot_chdir,
58001 + .maxlen = sizeof(int),
58002 + .mode = 0600,
58003 + .proc_handler = &proc_dointvec,
58004 + },
58005 +#endif
58006 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58007 + {
58008 + .procname = "chroot_deny_chmod",
58009 + .data = &grsec_enable_chroot_chmod,
58010 + .maxlen = sizeof(int),
58011 + .mode = 0600,
58012 + .proc_handler = &proc_dointvec,
58013 + },
58014 +#endif
58015 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58016 + {
58017 + .procname = "chroot_deny_mknod",
58018 + .data = &grsec_enable_chroot_mknod,
58019 + .maxlen = sizeof(int),
58020 + .mode = 0600,
58021 + .proc_handler = &proc_dointvec,
58022 + },
58023 +#endif
58024 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58025 + {
58026 + .procname = "chroot_restrict_nice",
58027 + .data = &grsec_enable_chroot_nice,
58028 + .maxlen = sizeof(int),
58029 + .mode = 0600,
58030 + .proc_handler = &proc_dointvec,
58031 + },
58032 +#endif
58033 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58034 + {
58035 + .procname = "chroot_execlog",
58036 + .data = &grsec_enable_chroot_execlog,
58037 + .maxlen = sizeof(int),
58038 + .mode = 0600,
58039 + .proc_handler = &proc_dointvec,
58040 + },
58041 +#endif
58042 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58043 + {
58044 + .procname = "chroot_caps",
58045 + .data = &grsec_enable_chroot_caps,
58046 + .maxlen = sizeof(int),
58047 + .mode = 0600,
58048 + .proc_handler = &proc_dointvec,
58049 + },
58050 +#endif
58051 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58052 + {
58053 + .procname = "chroot_deny_sysctl",
58054 + .data = &grsec_enable_chroot_sysctl,
58055 + .maxlen = sizeof(int),
58056 + .mode = 0600,
58057 + .proc_handler = &proc_dointvec,
58058 + },
58059 +#endif
58060 +#ifdef CONFIG_GRKERNSEC_TPE
58061 + {
58062 + .procname = "tpe",
58063 + .data = &grsec_enable_tpe,
58064 + .maxlen = sizeof(int),
58065 + .mode = 0600,
58066 + .proc_handler = &proc_dointvec,
58067 + },
58068 + {
58069 + .procname = "tpe_gid",
58070 + .data = &grsec_tpe_gid,
58071 + .maxlen = sizeof(int),
58072 + .mode = 0600,
58073 + .proc_handler = &proc_dointvec,
58074 + },
58075 +#endif
58076 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58077 + {
58078 + .procname = "tpe_invert",
58079 + .data = &grsec_enable_tpe_invert,
58080 + .maxlen = sizeof(int),
58081 + .mode = 0600,
58082 + .proc_handler = &proc_dointvec,
58083 + },
58084 +#endif
58085 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58086 + {
58087 + .procname = "tpe_restrict_all",
58088 + .data = &grsec_enable_tpe_all,
58089 + .maxlen = sizeof(int),
58090 + .mode = 0600,
58091 + .proc_handler = &proc_dointvec,
58092 + },
58093 +#endif
58094 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58095 + {
58096 + .procname = "socket_all",
58097 + .data = &grsec_enable_socket_all,
58098 + .maxlen = sizeof(int),
58099 + .mode = 0600,
58100 + .proc_handler = &proc_dointvec,
58101 + },
58102 + {
58103 + .procname = "socket_all_gid",
58104 + .data = &grsec_socket_all_gid,
58105 + .maxlen = sizeof(int),
58106 + .mode = 0600,
58107 + .proc_handler = &proc_dointvec,
58108 + },
58109 +#endif
58110 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58111 + {
58112 + .procname = "socket_client",
58113 + .data = &grsec_enable_socket_client,
58114 + .maxlen = sizeof(int),
58115 + .mode = 0600,
58116 + .proc_handler = &proc_dointvec,
58117 + },
58118 + {
58119 + .procname = "socket_client_gid",
58120 + .data = &grsec_socket_client_gid,
58121 + .maxlen = sizeof(int),
58122 + .mode = 0600,
58123 + .proc_handler = &proc_dointvec,
58124 + },
58125 +#endif
58126 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58127 + {
58128 + .procname = "socket_server",
58129 + .data = &grsec_enable_socket_server,
58130 + .maxlen = sizeof(int),
58131 + .mode = 0600,
58132 + .proc_handler = &proc_dointvec,
58133 + },
58134 + {
58135 + .procname = "socket_server_gid",
58136 + .data = &grsec_socket_server_gid,
58137 + .maxlen = sizeof(int),
58138 + .mode = 0600,
58139 + .proc_handler = &proc_dointvec,
58140 + },
58141 +#endif
58142 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58143 + {
58144 + .procname = "audit_group",
58145 + .data = &grsec_enable_group,
58146 + .maxlen = sizeof(int),
58147 + .mode = 0600,
58148 + .proc_handler = &proc_dointvec,
58149 + },
58150 + {
58151 + .procname = "audit_gid",
58152 + .data = &grsec_audit_gid,
58153 + .maxlen = sizeof(int),
58154 + .mode = 0600,
58155 + .proc_handler = &proc_dointvec,
58156 + },
58157 +#endif
58158 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58159 + {
58160 + .procname = "audit_chdir",
58161 + .data = &grsec_enable_chdir,
58162 + .maxlen = sizeof(int),
58163 + .mode = 0600,
58164 + .proc_handler = &proc_dointvec,
58165 + },
58166 +#endif
58167 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58168 + {
58169 + .procname = "audit_mount",
58170 + .data = &grsec_enable_mount,
58171 + .maxlen = sizeof(int),
58172 + .mode = 0600,
58173 + .proc_handler = &proc_dointvec,
58174 + },
58175 +#endif
58176 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58177 + {
58178 + .procname = "audit_textrel",
58179 + .data = &grsec_enable_audit_textrel,
58180 + .maxlen = sizeof(int),
58181 + .mode = 0600,
58182 + .proc_handler = &proc_dointvec,
58183 + },
58184 +#endif
58185 +#ifdef CONFIG_GRKERNSEC_DMESG
58186 + {
58187 + .procname = "dmesg",
58188 + .data = &grsec_enable_dmesg,
58189 + .maxlen = sizeof(int),
58190 + .mode = 0600,
58191 + .proc_handler = &proc_dointvec,
58192 + },
58193 +#endif
58194 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58195 + {
58196 + .procname = "chroot_findtask",
58197 + .data = &grsec_enable_chroot_findtask,
58198 + .maxlen = sizeof(int),
58199 + .mode = 0600,
58200 + .proc_handler = &proc_dointvec,
58201 + },
58202 +#endif
58203 +#ifdef CONFIG_GRKERNSEC_RESLOG
58204 + {
58205 + .procname = "resource_logging",
58206 + .data = &grsec_resource_logging,
58207 + .maxlen = sizeof(int),
58208 + .mode = 0600,
58209 + .proc_handler = &proc_dointvec,
58210 + },
58211 +#endif
58212 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58213 + {
58214 + .procname = "audit_ptrace",
58215 + .data = &grsec_enable_audit_ptrace,
58216 + .maxlen = sizeof(int),
58217 + .mode = 0600,
58218 + .proc_handler = &proc_dointvec,
58219 + },
58220 +#endif
58221 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58222 + {
58223 + .procname = "harden_ptrace",
58224 + .data = &grsec_enable_harden_ptrace,
58225 + .maxlen = sizeof(int),
58226 + .mode = 0600,
58227 + .proc_handler = &proc_dointvec,
58228 + },
58229 +#endif
58230 + {
58231 + .procname = "grsec_lock",
58232 + .data = &grsec_lock,
58233 + .maxlen = sizeof(int),
58234 + .mode = 0600,
58235 + .proc_handler = &proc_dointvec,
58236 + },
58237 +#endif
58238 +#ifdef CONFIG_GRKERNSEC_ROFS
58239 + {
58240 + .procname = "romount_protect",
58241 + .data = &grsec_enable_rofs,
58242 + .maxlen = sizeof(int),
58243 + .mode = 0600,
58244 + .proc_handler = &proc_dointvec_minmax,
58245 + .extra1 = &one,
58246 + .extra2 = &one,
58247 + },
58248 +#endif
58249 + { }
58250 +};
58251 +#endif
58252 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
58253 new file mode 100644
58254 index 0000000..0dc13c3
58255 --- /dev/null
58256 +++ b/grsecurity/grsec_time.c
58257 @@ -0,0 +1,16 @@
58258 +#include <linux/kernel.h>
58259 +#include <linux/sched.h>
58260 +#include <linux/grinternal.h>
58261 +#include <linux/module.h>
58262 +
58263 +void
58264 +gr_log_timechange(void)
58265 +{
58266 +#ifdef CONFIG_GRKERNSEC_TIME
58267 + if (grsec_enable_time)
58268 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
58269 +#endif
58270 + return;
58271 +}
58272 +
58273 +EXPORT_SYMBOL(gr_log_timechange);
58274 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
58275 new file mode 100644
58276 index 0000000..07e0dc0
58277 --- /dev/null
58278 +++ b/grsecurity/grsec_tpe.c
58279 @@ -0,0 +1,73 @@
58280 +#include <linux/kernel.h>
58281 +#include <linux/sched.h>
58282 +#include <linux/file.h>
58283 +#include <linux/fs.h>
58284 +#include <linux/grinternal.h>
58285 +
58286 +extern int gr_acl_tpe_check(void);
58287 +
58288 +int
58289 +gr_tpe_allow(const struct file *file)
58290 +{
58291 +#ifdef CONFIG_GRKERNSEC
58292 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
58293 + const struct cred *cred = current_cred();
58294 + char *msg = NULL;
58295 + char *msg2 = NULL;
58296 +
58297 + // never restrict root
58298 + if (!cred->uid)
58299 + return 1;
58300 +
58301 + if (grsec_enable_tpe) {
58302 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58303 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
58304 + msg = "not being in trusted group";
58305 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
58306 + msg = "being in untrusted group";
58307 +#else
58308 + if (in_group_p(grsec_tpe_gid))
58309 + msg = "being in untrusted group";
58310 +#endif
58311 + }
58312 + if (!msg && gr_acl_tpe_check())
58313 + msg = "being in untrusted role";
58314 +
58315 + // not in any affected group/role
58316 + if (!msg)
58317 + goto next_check;
58318 +
58319 + if (inode->i_uid)
58320 + msg2 = "file in non-root-owned directory";
58321 + else if (inode->i_mode & S_IWOTH)
58322 + msg2 = "file in world-writable directory";
58323 + else if (inode->i_mode & S_IWGRP)
58324 + msg2 = "file in group-writable directory";
58325 +
58326 + if (msg && msg2) {
58327 + char fullmsg[70] = {0};
58328 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
58329 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
58330 + return 0;
58331 + }
58332 + msg = NULL;
58333 +next_check:
58334 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58335 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
58336 + return 1;
58337 +
58338 + if (inode->i_uid && (inode->i_uid != cred->uid))
58339 + msg = "directory not owned by user";
58340 + else if (inode->i_mode & S_IWOTH)
58341 + msg = "file in world-writable directory";
58342 + else if (inode->i_mode & S_IWGRP)
58343 + msg = "file in group-writable directory";
58344 +
58345 + if (msg) {
58346 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
58347 + return 0;
58348 + }
58349 +#endif
58350 +#endif
58351 + return 1;
58352 +}
58353 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
58354 new file mode 100644
58355 index 0000000..9f7b1ac
58356 --- /dev/null
58357 +++ b/grsecurity/grsum.c
58358 @@ -0,0 +1,61 @@
58359 +#include <linux/err.h>
58360 +#include <linux/kernel.h>
58361 +#include <linux/sched.h>
58362 +#include <linux/mm.h>
58363 +#include <linux/scatterlist.h>
58364 +#include <linux/crypto.h>
58365 +#include <linux/gracl.h>
58366 +
58367 +
58368 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
58369 +#error "crypto and sha256 must be built into the kernel"
58370 +#endif
58371 +
58372 +int
58373 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
58374 +{
58375 + char *p;
58376 + struct crypto_hash *tfm;
58377 + struct hash_desc desc;
58378 + struct scatterlist sg;
58379 + unsigned char temp_sum[GR_SHA_LEN];
58380 + volatile int retval = 0;
58381 + volatile int dummy = 0;
58382 + unsigned int i;
58383 +
58384 + sg_init_table(&sg, 1);
58385 +
58386 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
58387 + if (IS_ERR(tfm)) {
58388 + /* should never happen, since sha256 should be built in */
58389 + return 1;
58390 + }
58391 +
58392 + desc.tfm = tfm;
58393 + desc.flags = 0;
58394 +
58395 + crypto_hash_init(&desc);
58396 +
58397 + p = salt;
58398 + sg_set_buf(&sg, p, GR_SALT_LEN);
58399 + crypto_hash_update(&desc, &sg, sg.length);
58400 +
58401 + p = entry->pw;
58402 + sg_set_buf(&sg, p, strlen(p));
58403 +
58404 + crypto_hash_update(&desc, &sg, sg.length);
58405 +
58406 + crypto_hash_final(&desc, temp_sum);
58407 +
58408 + memset(entry->pw, 0, GR_PW_LEN);
58409 +
58410 + for (i = 0; i < GR_SHA_LEN; i++)
58411 + if (sum[i] != temp_sum[i])
58412 + retval = 1;
58413 + else
58414 + dummy = 1; // waste a cycle
58415 +
58416 + crypto_free_hash(tfm);
58417 +
58418 + return retval;
58419 +}
58420 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
58421 index 6cd5b64..f620d2d 100644
58422 --- a/include/acpi/acpi_bus.h
58423 +++ b/include/acpi/acpi_bus.h
58424 @@ -107,7 +107,7 @@ struct acpi_device_ops {
58425 acpi_op_bind bind;
58426 acpi_op_unbind unbind;
58427 acpi_op_notify notify;
58428 -};
58429 +} __no_const;
58430
58431 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
58432
58433 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
58434 index b7babf0..71e4e74 100644
58435 --- a/include/asm-generic/atomic-long.h
58436 +++ b/include/asm-generic/atomic-long.h
58437 @@ -22,6 +22,12 @@
58438
58439 typedef atomic64_t atomic_long_t;
58440
58441 +#ifdef CONFIG_PAX_REFCOUNT
58442 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
58443 +#else
58444 +typedef atomic64_t atomic_long_unchecked_t;
58445 +#endif
58446 +
58447 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
58448
58449 static inline long atomic_long_read(atomic_long_t *l)
58450 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
58451 return (long)atomic64_read(v);
58452 }
58453
58454 +#ifdef CONFIG_PAX_REFCOUNT
58455 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
58456 +{
58457 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58458 +
58459 + return (long)atomic64_read_unchecked(v);
58460 +}
58461 +#endif
58462 +
58463 static inline void atomic_long_set(atomic_long_t *l, long i)
58464 {
58465 atomic64_t *v = (atomic64_t *)l;
58466 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
58467 atomic64_set(v, i);
58468 }
58469
58470 +#ifdef CONFIG_PAX_REFCOUNT
58471 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
58472 +{
58473 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58474 +
58475 + atomic64_set_unchecked(v, i);
58476 +}
58477 +#endif
58478 +
58479 static inline void atomic_long_inc(atomic_long_t *l)
58480 {
58481 atomic64_t *v = (atomic64_t *)l;
58482 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
58483 atomic64_inc(v);
58484 }
58485
58486 +#ifdef CONFIG_PAX_REFCOUNT
58487 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
58488 +{
58489 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58490 +
58491 + atomic64_inc_unchecked(v);
58492 +}
58493 +#endif
58494 +
58495 static inline void atomic_long_dec(atomic_long_t *l)
58496 {
58497 atomic64_t *v = (atomic64_t *)l;
58498 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
58499 atomic64_dec(v);
58500 }
58501
58502 +#ifdef CONFIG_PAX_REFCOUNT
58503 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
58504 +{
58505 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58506 +
58507 + atomic64_dec_unchecked(v);
58508 +}
58509 +#endif
58510 +
58511 static inline void atomic_long_add(long i, atomic_long_t *l)
58512 {
58513 atomic64_t *v = (atomic64_t *)l;
58514 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
58515 atomic64_add(i, v);
58516 }
58517
58518 +#ifdef CONFIG_PAX_REFCOUNT
58519 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
58520 +{
58521 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58522 +
58523 + atomic64_add_unchecked(i, v);
58524 +}
58525 +#endif
58526 +
58527 static inline void atomic_long_sub(long i, atomic_long_t *l)
58528 {
58529 atomic64_t *v = (atomic64_t *)l;
58530 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
58531 atomic64_sub(i, v);
58532 }
58533
58534 +#ifdef CONFIG_PAX_REFCOUNT
58535 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
58536 +{
58537 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58538 +
58539 + atomic64_sub_unchecked(i, v);
58540 +}
58541 +#endif
58542 +
58543 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
58544 {
58545 atomic64_t *v = (atomic64_t *)l;
58546 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
58547 return (long)atomic64_inc_return(v);
58548 }
58549
58550 +#ifdef CONFIG_PAX_REFCOUNT
58551 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
58552 +{
58553 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58554 +
58555 + return (long)atomic64_inc_return_unchecked(v);
58556 +}
58557 +#endif
58558 +
58559 static inline long atomic_long_dec_return(atomic_long_t *l)
58560 {
58561 atomic64_t *v = (atomic64_t *)l;
58562 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
58563
58564 typedef atomic_t atomic_long_t;
58565
58566 +#ifdef CONFIG_PAX_REFCOUNT
58567 +typedef atomic_unchecked_t atomic_long_unchecked_t;
58568 +#else
58569 +typedef atomic_t atomic_long_unchecked_t;
58570 +#endif
58571 +
58572 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
58573 static inline long atomic_long_read(atomic_long_t *l)
58574 {
58575 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
58576 return (long)atomic_read(v);
58577 }
58578
58579 +#ifdef CONFIG_PAX_REFCOUNT
58580 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
58581 +{
58582 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58583 +
58584 + return (long)atomic_read_unchecked(v);
58585 +}
58586 +#endif
58587 +
58588 static inline void atomic_long_set(atomic_long_t *l, long i)
58589 {
58590 atomic_t *v = (atomic_t *)l;
58591 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
58592 atomic_set(v, i);
58593 }
58594
58595 +#ifdef CONFIG_PAX_REFCOUNT
58596 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
58597 +{
58598 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58599 +
58600 + atomic_set_unchecked(v, i);
58601 +}
58602 +#endif
58603 +
58604 static inline void atomic_long_inc(atomic_long_t *l)
58605 {
58606 atomic_t *v = (atomic_t *)l;
58607 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
58608 atomic_inc(v);
58609 }
58610
58611 +#ifdef CONFIG_PAX_REFCOUNT
58612 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
58613 +{
58614 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58615 +
58616 + atomic_inc_unchecked(v);
58617 +}
58618 +#endif
58619 +
58620 static inline void atomic_long_dec(atomic_long_t *l)
58621 {
58622 atomic_t *v = (atomic_t *)l;
58623 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
58624 atomic_dec(v);
58625 }
58626
58627 +#ifdef CONFIG_PAX_REFCOUNT
58628 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
58629 +{
58630 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58631 +
58632 + atomic_dec_unchecked(v);
58633 +}
58634 +#endif
58635 +
58636 static inline void atomic_long_add(long i, atomic_long_t *l)
58637 {
58638 atomic_t *v = (atomic_t *)l;
58639 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
58640 atomic_add(i, v);
58641 }
58642
58643 +#ifdef CONFIG_PAX_REFCOUNT
58644 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
58645 +{
58646 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58647 +
58648 + atomic_add_unchecked(i, v);
58649 +}
58650 +#endif
58651 +
58652 static inline void atomic_long_sub(long i, atomic_long_t *l)
58653 {
58654 atomic_t *v = (atomic_t *)l;
58655 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
58656 atomic_sub(i, v);
58657 }
58658
58659 +#ifdef CONFIG_PAX_REFCOUNT
58660 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
58661 +{
58662 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58663 +
58664 + atomic_sub_unchecked(i, v);
58665 +}
58666 +#endif
58667 +
58668 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
58669 {
58670 atomic_t *v = (atomic_t *)l;
58671 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
58672 return (long)atomic_inc_return(v);
58673 }
58674
58675 +#ifdef CONFIG_PAX_REFCOUNT
58676 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
58677 +{
58678 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58679 +
58680 + return (long)atomic_inc_return_unchecked(v);
58681 +}
58682 +#endif
58683 +
58684 static inline long atomic_long_dec_return(atomic_long_t *l)
58685 {
58686 atomic_t *v = (atomic_t *)l;
58687 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
58688
58689 #endif /* BITS_PER_LONG == 64 */
58690
58691 +#ifdef CONFIG_PAX_REFCOUNT
58692 +static inline void pax_refcount_needs_these_functions(void)
58693 +{
58694 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
58695 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
58696 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
58697 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
58698 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
58699 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
58700 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
58701 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
58702 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
58703 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
58704 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
58705 +
58706 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
58707 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
58708 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
58709 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
58710 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
58711 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
58712 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
58713 +}
58714 +#else
58715 +#define atomic_read_unchecked(v) atomic_read(v)
58716 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
58717 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
58718 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
58719 +#define atomic_inc_unchecked(v) atomic_inc(v)
58720 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
58721 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
58722 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
58723 +#define atomic_dec_unchecked(v) atomic_dec(v)
58724 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
58725 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
58726 +
58727 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
58728 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
58729 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
58730 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
58731 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
58732 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
58733 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
58734 +#endif
58735 +
58736 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
58737 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
58738 index b18ce4f..2ee2843 100644
58739 --- a/include/asm-generic/atomic64.h
58740 +++ b/include/asm-generic/atomic64.h
58741 @@ -16,6 +16,8 @@ typedef struct {
58742 long long counter;
58743 } atomic64_t;
58744
58745 +typedef atomic64_t atomic64_unchecked_t;
58746 +
58747 #define ATOMIC64_INIT(i) { (i) }
58748
58749 extern long long atomic64_read(const atomic64_t *v);
58750 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
58751 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
58752 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
58753
58754 +#define atomic64_read_unchecked(v) atomic64_read(v)
58755 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
58756 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
58757 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
58758 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
58759 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
58760 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
58761 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
58762 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
58763 +
58764 #endif /* _ASM_GENERIC_ATOMIC64_H */
58765 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
58766 index 1bfcfe5..e04c5c9 100644
58767 --- a/include/asm-generic/cache.h
58768 +++ b/include/asm-generic/cache.h
58769 @@ -6,7 +6,7 @@
58770 * cache lines need to provide their own cache.h.
58771 */
58772
58773 -#define L1_CACHE_SHIFT 5
58774 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
58775 +#define L1_CACHE_SHIFT 5UL
58776 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
58777
58778 #endif /* __ASM_GENERIC_CACHE_H */
58779 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
58780 index 0d68a1e..b74a761 100644
58781 --- a/include/asm-generic/emergency-restart.h
58782 +++ b/include/asm-generic/emergency-restart.h
58783 @@ -1,7 +1,7 @@
58784 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
58785 #define _ASM_GENERIC_EMERGENCY_RESTART_H
58786
58787 -static inline void machine_emergency_restart(void)
58788 +static inline __noreturn void machine_emergency_restart(void)
58789 {
58790 machine_restart(NULL);
58791 }
58792 diff --git a/include/asm-generic/int-l64.h b/include/asm-generic/int-l64.h
58793 index 1ca3efc..e3dc852 100644
58794 --- a/include/asm-generic/int-l64.h
58795 +++ b/include/asm-generic/int-l64.h
58796 @@ -46,6 +46,8 @@ typedef unsigned int u32;
58797 typedef signed long s64;
58798 typedef unsigned long u64;
58799
58800 +typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
58801 +
58802 #define S8_C(x) x
58803 #define U8_C(x) x ## U
58804 #define S16_C(x) x
58805 diff --git a/include/asm-generic/int-ll64.h b/include/asm-generic/int-ll64.h
58806 index f394147..b6152b9 100644
58807 --- a/include/asm-generic/int-ll64.h
58808 +++ b/include/asm-generic/int-ll64.h
58809 @@ -51,6 +51,8 @@ typedef unsigned int u32;
58810 typedef signed long long s64;
58811 typedef unsigned long long u64;
58812
58813 +typedef unsigned long long intoverflow_t;
58814 +
58815 #define S8_C(x) x
58816 #define U8_C(x) x ## U
58817 #define S16_C(x) x
58818 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
58819 index 0232ccb..13d9165 100644
58820 --- a/include/asm-generic/kmap_types.h
58821 +++ b/include/asm-generic/kmap_types.h
58822 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
58823 KMAP_D(17) KM_NMI,
58824 KMAP_D(18) KM_NMI_PTE,
58825 KMAP_D(19) KM_KDB,
58826 +KMAP_D(20) KM_CLEARPAGE,
58827 /*
58828 * Remember to update debug_kmap_atomic() when adding new kmap types!
58829 */
58830 -KMAP_D(20) KM_TYPE_NR
58831 +KMAP_D(21) KM_TYPE_NR
58832 };
58833
58834 #undef KMAP_D
58835 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
58836 index 725612b..9cc513a 100644
58837 --- a/include/asm-generic/pgtable-nopmd.h
58838 +++ b/include/asm-generic/pgtable-nopmd.h
58839 @@ -1,14 +1,19 @@
58840 #ifndef _PGTABLE_NOPMD_H
58841 #define _PGTABLE_NOPMD_H
58842
58843 -#ifndef __ASSEMBLY__
58844 -
58845 #include <asm-generic/pgtable-nopud.h>
58846
58847 -struct mm_struct;
58848 -
58849 #define __PAGETABLE_PMD_FOLDED
58850
58851 +#define PMD_SHIFT PUD_SHIFT
58852 +#define PTRS_PER_PMD 1
58853 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
58854 +#define PMD_MASK (~(PMD_SIZE-1))
58855 +
58856 +#ifndef __ASSEMBLY__
58857 +
58858 +struct mm_struct;
58859 +
58860 /*
58861 * Having the pmd type consist of a pud gets the size right, and allows
58862 * us to conceptually access the pud entry that this pmd is folded into
58863 @@ -16,11 +21,6 @@ struct mm_struct;
58864 */
58865 typedef struct { pud_t pud; } pmd_t;
58866
58867 -#define PMD_SHIFT PUD_SHIFT
58868 -#define PTRS_PER_PMD 1
58869 -#define PMD_SIZE (1UL << PMD_SHIFT)
58870 -#define PMD_MASK (~(PMD_SIZE-1))
58871 -
58872 /*
58873 * The "pud_xxx()" functions here are trivial for a folded two-level
58874 * setup: the pmd is never bad, and a pmd always exists (as it's folded
58875 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
58876 index 810431d..ccc3638 100644
58877 --- a/include/asm-generic/pgtable-nopud.h
58878 +++ b/include/asm-generic/pgtable-nopud.h
58879 @@ -1,10 +1,15 @@
58880 #ifndef _PGTABLE_NOPUD_H
58881 #define _PGTABLE_NOPUD_H
58882
58883 -#ifndef __ASSEMBLY__
58884 -
58885 #define __PAGETABLE_PUD_FOLDED
58886
58887 +#define PUD_SHIFT PGDIR_SHIFT
58888 +#define PTRS_PER_PUD 1
58889 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
58890 +#define PUD_MASK (~(PUD_SIZE-1))
58891 +
58892 +#ifndef __ASSEMBLY__
58893 +
58894 /*
58895 * Having the pud type consist of a pgd gets the size right, and allows
58896 * us to conceptually access the pgd entry that this pud is folded into
58897 @@ -12,11 +17,6 @@
58898 */
58899 typedef struct { pgd_t pgd; } pud_t;
58900
58901 -#define PUD_SHIFT PGDIR_SHIFT
58902 -#define PTRS_PER_PUD 1
58903 -#define PUD_SIZE (1UL << PUD_SHIFT)
58904 -#define PUD_MASK (~(PUD_SIZE-1))
58905 -
58906 /*
58907 * The "pgd_xxx()" functions here are trivial for a folded two-level
58908 * setup: the pud is never bad, and a pud always exists (as it's folded
58909 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
58910 index 76bff2b..c7a14e2 100644
58911 --- a/include/asm-generic/pgtable.h
58912 +++ b/include/asm-generic/pgtable.h
58913 @@ -443,6 +443,14 @@ static inline int pmd_write(pmd_t pmd)
58914 #endif /* __HAVE_ARCH_PMD_WRITE */
58915 #endif
58916
58917 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
58918 +static inline unsigned long pax_open_kernel(void) { return 0; }
58919 +#endif
58920 +
58921 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
58922 +static inline unsigned long pax_close_kernel(void) { return 0; }
58923 +#endif
58924 +
58925 #endif /* !__ASSEMBLY__ */
58926
58927 #endif /* _ASM_GENERIC_PGTABLE_H */
58928 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
58929 index b5e2e4c..6a5373e 100644
58930 --- a/include/asm-generic/vmlinux.lds.h
58931 +++ b/include/asm-generic/vmlinux.lds.h
58932 @@ -217,6 +217,7 @@
58933 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
58934 VMLINUX_SYMBOL(__start_rodata) = .; \
58935 *(.rodata) *(.rodata.*) \
58936 + *(.data..read_only) \
58937 *(__vermagic) /* Kernel version magic */ \
58938 . = ALIGN(8); \
58939 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
58940 @@ -722,17 +723,18 @@
58941 * section in the linker script will go there too. @phdr should have
58942 * a leading colon.
58943 *
58944 - * Note that this macros defines __per_cpu_load as an absolute symbol.
58945 + * Note that this macros defines per_cpu_load as an absolute symbol.
58946 * If there is no need to put the percpu section at a predetermined
58947 * address, use PERCPU_SECTION.
58948 */
58949 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
58950 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
58951 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
58952 + per_cpu_load = .; \
58953 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
58954 - LOAD_OFFSET) { \
58955 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
58956 PERCPU_INPUT(cacheline) \
58957 } phdr \
58958 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
58959 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
58960
58961 /**
58962 * PERCPU_SECTION - define output section for percpu area, simple version
58963 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
58964 index bf4b2dc..2d0762f 100644
58965 --- a/include/drm/drmP.h
58966 +++ b/include/drm/drmP.h
58967 @@ -72,6 +72,7 @@
58968 #include <linux/workqueue.h>
58969 #include <linux/poll.h>
58970 #include <asm/pgalloc.h>
58971 +#include <asm/local.h>
58972 #include "drm.h"
58973
58974 #include <linux/idr.h>
58975 @@ -1038,7 +1039,7 @@ struct drm_device {
58976
58977 /** \name Usage Counters */
58978 /*@{ */
58979 - int open_count; /**< Outstanding files open */
58980 + local_t open_count; /**< Outstanding files open */
58981 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
58982 atomic_t vma_count; /**< Outstanding vma areas open */
58983 int buf_use; /**< Buffers in use -- cannot alloc */
58984 @@ -1049,7 +1050,7 @@ struct drm_device {
58985 /*@{ */
58986 unsigned long counters;
58987 enum drm_stat_type types[15];
58988 - atomic_t counts[15];
58989 + atomic_unchecked_t counts[15];
58990 /*@} */
58991
58992 struct list_head filelist;
58993 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
58994 index 73b0712..0b7ef2f 100644
58995 --- a/include/drm/drm_crtc_helper.h
58996 +++ b/include/drm/drm_crtc_helper.h
58997 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
58998
58999 /* disable crtc when not in use - more explicit than dpms off */
59000 void (*disable)(struct drm_crtc *crtc);
59001 -};
59002 +} __no_const;
59003
59004 struct drm_encoder_helper_funcs {
59005 void (*dpms)(struct drm_encoder *encoder, int mode);
59006 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
59007 struct drm_connector *connector);
59008 /* disable encoder when not in use - more explicit than dpms off */
59009 void (*disable)(struct drm_encoder *encoder);
59010 -};
59011 +} __no_const;
59012
59013 struct drm_connector_helper_funcs {
59014 int (*get_modes)(struct drm_connector *connector);
59015 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
59016 index 26c1f78..6722682 100644
59017 --- a/include/drm/ttm/ttm_memory.h
59018 +++ b/include/drm/ttm/ttm_memory.h
59019 @@ -47,7 +47,7 @@
59020
59021 struct ttm_mem_shrink {
59022 int (*do_shrink) (struct ttm_mem_shrink *);
59023 -};
59024 +} __no_const;
59025
59026 /**
59027 * struct ttm_mem_global - Global memory accounting structure.
59028 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
59029 index e86dfca..40cc55f 100644
59030 --- a/include/linux/a.out.h
59031 +++ b/include/linux/a.out.h
59032 @@ -39,6 +39,14 @@ enum machine_type {
59033 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
59034 };
59035
59036 +/* Constants for the N_FLAGS field */
59037 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
59038 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
59039 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
59040 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
59041 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
59042 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
59043 +
59044 #if !defined (N_MAGIC)
59045 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
59046 #endif
59047 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
59048 index 49a83ca..df96b54 100644
59049 --- a/include/linux/atmdev.h
59050 +++ b/include/linux/atmdev.h
59051 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
59052 #endif
59053
59054 struct k_atm_aal_stats {
59055 -#define __HANDLE_ITEM(i) atomic_t i
59056 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
59057 __AAL_STAT_ITEMS
59058 #undef __HANDLE_ITEM
59059 };
59060 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
59061 index fd88a39..8a801b4 100644
59062 --- a/include/linux/binfmts.h
59063 +++ b/include/linux/binfmts.h
59064 @@ -18,7 +18,7 @@ struct pt_regs;
59065 #define BINPRM_BUF_SIZE 128
59066
59067 #ifdef __KERNEL__
59068 -#include <linux/list.h>
59069 +#include <linux/sched.h>
59070
59071 #define CORENAME_MAX_SIZE 128
59072
59073 @@ -58,6 +58,7 @@ struct linux_binprm {
59074 unsigned interp_flags;
59075 unsigned interp_data;
59076 unsigned long loader, exec;
59077 + char tcomm[TASK_COMM_LEN];
59078 };
59079
59080 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
59081 @@ -88,6 +89,7 @@ struct linux_binfmt {
59082 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
59083 int (*load_shlib)(struct file *);
59084 int (*core_dump)(struct coredump_params *cprm);
59085 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
59086 unsigned long min_coredump; /* minimal dump size */
59087 };
59088
59089 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
59090 index 0ed1eb0..3ab569b 100644
59091 --- a/include/linux/blkdev.h
59092 +++ b/include/linux/blkdev.h
59093 @@ -1315,7 +1315,7 @@ struct block_device_operations {
59094 /* this callback is with swap_lock and sometimes page table lock held */
59095 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
59096 struct module *owner;
59097 -};
59098 +} __do_const;
59099
59100 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
59101 unsigned long);
59102 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
59103 index 4d1a074..88f929a 100644
59104 --- a/include/linux/blktrace_api.h
59105 +++ b/include/linux/blktrace_api.h
59106 @@ -162,7 +162,7 @@ struct blk_trace {
59107 struct dentry *dir;
59108 struct dentry *dropped_file;
59109 struct dentry *msg_file;
59110 - atomic_t dropped;
59111 + atomic_unchecked_t dropped;
59112 };
59113
59114 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
59115 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
59116 index 83195fb..0b0f77d 100644
59117 --- a/include/linux/byteorder/little_endian.h
59118 +++ b/include/linux/byteorder/little_endian.h
59119 @@ -42,51 +42,51 @@
59120
59121 static inline __le64 __cpu_to_le64p(const __u64 *p)
59122 {
59123 - return (__force __le64)*p;
59124 + return (__force const __le64)*p;
59125 }
59126 static inline __u64 __le64_to_cpup(const __le64 *p)
59127 {
59128 - return (__force __u64)*p;
59129 + return (__force const __u64)*p;
59130 }
59131 static inline __le32 __cpu_to_le32p(const __u32 *p)
59132 {
59133 - return (__force __le32)*p;
59134 + return (__force const __le32)*p;
59135 }
59136 static inline __u32 __le32_to_cpup(const __le32 *p)
59137 {
59138 - return (__force __u32)*p;
59139 + return (__force const __u32)*p;
59140 }
59141 static inline __le16 __cpu_to_le16p(const __u16 *p)
59142 {
59143 - return (__force __le16)*p;
59144 + return (__force const __le16)*p;
59145 }
59146 static inline __u16 __le16_to_cpup(const __le16 *p)
59147 {
59148 - return (__force __u16)*p;
59149 + return (__force const __u16)*p;
59150 }
59151 static inline __be64 __cpu_to_be64p(const __u64 *p)
59152 {
59153 - return (__force __be64)__swab64p(p);
59154 + return (__force const __be64)__swab64p(p);
59155 }
59156 static inline __u64 __be64_to_cpup(const __be64 *p)
59157 {
59158 - return __swab64p((__u64 *)p);
59159 + return __swab64p((const __u64 *)p);
59160 }
59161 static inline __be32 __cpu_to_be32p(const __u32 *p)
59162 {
59163 - return (__force __be32)__swab32p(p);
59164 + return (__force const __be32)__swab32p(p);
59165 }
59166 static inline __u32 __be32_to_cpup(const __be32 *p)
59167 {
59168 - return __swab32p((__u32 *)p);
59169 + return __swab32p((const __u32 *)p);
59170 }
59171 static inline __be16 __cpu_to_be16p(const __u16 *p)
59172 {
59173 - return (__force __be16)__swab16p(p);
59174 + return (__force const __be16)__swab16p(p);
59175 }
59176 static inline __u16 __be16_to_cpup(const __be16 *p)
59177 {
59178 - return __swab16p((__u16 *)p);
59179 + return __swab16p((const __u16 *)p);
59180 }
59181 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
59182 #define __le64_to_cpus(x) do { (void)(x); } while (0)
59183 diff --git a/include/linux/cache.h b/include/linux/cache.h
59184 index 4c57065..4307975 100644
59185 --- a/include/linux/cache.h
59186 +++ b/include/linux/cache.h
59187 @@ -16,6 +16,10 @@
59188 #define __read_mostly
59189 #endif
59190
59191 +#ifndef __read_only
59192 +#define __read_only __read_mostly
59193 +#endif
59194 +
59195 #ifndef ____cacheline_aligned
59196 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
59197 #endif
59198 diff --git a/include/linux/capability.h b/include/linux/capability.h
59199 index a63d13d..069bfd5 100644
59200 --- a/include/linux/capability.h
59201 +++ b/include/linux/capability.h
59202 @@ -548,6 +548,9 @@ extern bool capable(int cap);
59203 extern bool ns_capable(struct user_namespace *ns, int cap);
59204 extern bool task_ns_capable(struct task_struct *t, int cap);
59205 extern bool nsown_capable(int cap);
59206 +extern bool task_ns_capable_nolog(struct task_struct *t, int cap);
59207 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
59208 +extern bool capable_nolog(int cap);
59209
59210 /* audit system wants to get cap info from files as well */
59211 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
59212 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
59213 index 04ffb2e..6799180 100644
59214 --- a/include/linux/cleancache.h
59215 +++ b/include/linux/cleancache.h
59216 @@ -31,7 +31,7 @@ struct cleancache_ops {
59217 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
59218 void (*flush_inode)(int, struct cleancache_filekey);
59219 void (*flush_fs)(int);
59220 -};
59221 +} __no_const;
59222
59223 extern struct cleancache_ops
59224 cleancache_register_ops(struct cleancache_ops *ops);
59225 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
59226 index dfadc96..c0e70c1 100644
59227 --- a/include/linux/compiler-gcc4.h
59228 +++ b/include/linux/compiler-gcc4.h
59229 @@ -31,6 +31,12 @@
59230
59231
59232 #if __GNUC_MINOR__ >= 5
59233 +
59234 +#ifdef CONSTIFY_PLUGIN
59235 +#define __no_const __attribute__((no_const))
59236 +#define __do_const __attribute__((do_const))
59237 +#endif
59238 +
59239 /*
59240 * Mark a position in code as unreachable. This can be used to
59241 * suppress control flow warnings after asm blocks that transfer
59242 @@ -46,6 +52,11 @@
59243 #define __noclone __attribute__((__noclone__))
59244
59245 #endif
59246 +
59247 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
59248 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
59249 +#define __bos0(ptr) __bos((ptr), 0)
59250 +#define __bos1(ptr) __bos((ptr), 1)
59251 #endif
59252
59253 #if __GNUC_MINOR__ > 0
59254 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
59255 index 320d6c9..8573a1c 100644
59256 --- a/include/linux/compiler.h
59257 +++ b/include/linux/compiler.h
59258 @@ -5,31 +5,62 @@
59259
59260 #ifdef __CHECKER__
59261 # define __user __attribute__((noderef, address_space(1)))
59262 +# define __force_user __force __user
59263 # define __kernel __attribute__((address_space(0)))
59264 +# define __force_kernel __force __kernel
59265 # define __safe __attribute__((safe))
59266 # define __force __attribute__((force))
59267 # define __nocast __attribute__((nocast))
59268 # define __iomem __attribute__((noderef, address_space(2)))
59269 +# define __force_iomem __force __iomem
59270 # define __acquires(x) __attribute__((context(x,0,1)))
59271 # define __releases(x) __attribute__((context(x,1,0)))
59272 # define __acquire(x) __context__(x,1)
59273 # define __release(x) __context__(x,-1)
59274 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
59275 # define __percpu __attribute__((noderef, address_space(3)))
59276 +# define __force_percpu __force __percpu
59277 #ifdef CONFIG_SPARSE_RCU_POINTER
59278 # define __rcu __attribute__((noderef, address_space(4)))
59279 +# define __force_rcu __force __rcu
59280 #else
59281 # define __rcu
59282 +# define __force_rcu
59283 #endif
59284 extern void __chk_user_ptr(const volatile void __user *);
59285 extern void __chk_io_ptr(const volatile void __iomem *);
59286 +#elif defined(CHECKER_PLUGIN)
59287 +//# define __user
59288 +//# define __force_user
59289 +//# define __kernel
59290 +//# define __force_kernel
59291 +# define __safe
59292 +# define __force
59293 +# define __nocast
59294 +# define __iomem
59295 +# define __force_iomem
59296 +# define __chk_user_ptr(x) (void)0
59297 +# define __chk_io_ptr(x) (void)0
59298 +# define __builtin_warning(x, y...) (1)
59299 +# define __acquires(x)
59300 +# define __releases(x)
59301 +# define __acquire(x) (void)0
59302 +# define __release(x) (void)0
59303 +# define __cond_lock(x,c) (c)
59304 +# define __percpu
59305 +# define __force_percpu
59306 +# define __rcu
59307 +# define __force_rcu
59308 #else
59309 # define __user
59310 +# define __force_user
59311 # define __kernel
59312 +# define __force_kernel
59313 # define __safe
59314 # define __force
59315 # define __nocast
59316 # define __iomem
59317 +# define __force_iomem
59318 # define __chk_user_ptr(x) (void)0
59319 # define __chk_io_ptr(x) (void)0
59320 # define __builtin_warning(x, y...) (1)
59321 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
59322 # define __release(x) (void)0
59323 # define __cond_lock(x,c) (c)
59324 # define __percpu
59325 +# define __force_percpu
59326 # define __rcu
59327 +# define __force_rcu
59328 #endif
59329
59330 #ifdef __KERNEL__
59331 @@ -264,6 +297,14 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59332 # define __attribute_const__ /* unimplemented */
59333 #endif
59334
59335 +#ifndef __no_const
59336 +# define __no_const
59337 +#endif
59338 +
59339 +#ifndef __do_const
59340 +# define __do_const
59341 +#endif
59342 +
59343 /*
59344 * Tell gcc if a function is cold. The compiler will assume any path
59345 * directly leading to the call is unlikely.
59346 @@ -273,6 +314,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59347 #define __cold
59348 #endif
59349
59350 +#ifndef __alloc_size
59351 +#define __alloc_size(...)
59352 +#endif
59353 +
59354 +#ifndef __bos
59355 +#define __bos(ptr, arg)
59356 +#endif
59357 +
59358 +#ifndef __bos0
59359 +#define __bos0(ptr)
59360 +#endif
59361 +
59362 +#ifndef __bos1
59363 +#define __bos1(ptr)
59364 +#endif
59365 +
59366 /* Simple shorthand for a section definition */
59367 #ifndef __section
59368 # define __section(S) __attribute__ ((__section__(#S)))
59369 @@ -306,6 +363,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59370 * use is to mediate communication between process-level code and irq/NMI
59371 * handlers, all running on the same CPU.
59372 */
59373 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
59374 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
59375 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
59376
59377 #endif /* __LINUX_COMPILER_H */
59378 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
59379 index e9eaec5..bfeb9bb 100644
59380 --- a/include/linux/cpuset.h
59381 +++ b/include/linux/cpuset.h
59382 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
59383 * nodemask.
59384 */
59385 smp_mb();
59386 - --ACCESS_ONCE(current->mems_allowed_change_disable);
59387 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
59388 }
59389
59390 static inline void set_mems_allowed(nodemask_t nodemask)
59391 diff --git a/include/linux/cred.h b/include/linux/cred.h
59392 index 4030896..8d6f342 100644
59393 --- a/include/linux/cred.h
59394 +++ b/include/linux/cred.h
59395 @@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
59396 static inline void validate_process_creds(void)
59397 {
59398 }
59399 +static inline void validate_task_creds(struct task_struct *task)
59400 +{
59401 +}
59402 #endif
59403
59404 /**
59405 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
59406 index 8a94217..15d49e3 100644
59407 --- a/include/linux/crypto.h
59408 +++ b/include/linux/crypto.h
59409 @@ -365,7 +365,7 @@ struct cipher_tfm {
59410 const u8 *key, unsigned int keylen);
59411 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
59412 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
59413 -};
59414 +} __no_const;
59415
59416 struct hash_tfm {
59417 int (*init)(struct hash_desc *desc);
59418 @@ -386,13 +386,13 @@ struct compress_tfm {
59419 int (*cot_decompress)(struct crypto_tfm *tfm,
59420 const u8 *src, unsigned int slen,
59421 u8 *dst, unsigned int *dlen);
59422 -};
59423 +} __no_const;
59424
59425 struct rng_tfm {
59426 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
59427 unsigned int dlen);
59428 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
59429 -};
59430 +} __no_const;
59431
59432 #define crt_ablkcipher crt_u.ablkcipher
59433 #define crt_aead crt_u.aead
59434 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
59435 index 7925bf0..d5143d2 100644
59436 --- a/include/linux/decompress/mm.h
59437 +++ b/include/linux/decompress/mm.h
59438 @@ -77,7 +77,7 @@ static void free(void *where)
59439 * warnings when not needed (indeed large_malloc / large_free are not
59440 * needed by inflate */
59441
59442 -#define malloc(a) kmalloc(a, GFP_KERNEL)
59443 +#define malloc(a) kmalloc((a), GFP_KERNEL)
59444 #define free(a) kfree(a)
59445
59446 #define large_malloc(a) vmalloc(a)
59447 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
59448 index e13117c..e9fc938 100644
59449 --- a/include/linux/dma-mapping.h
59450 +++ b/include/linux/dma-mapping.h
59451 @@ -46,7 +46,7 @@ struct dma_map_ops {
59452 u64 (*get_required_mask)(struct device *dev);
59453 #endif
59454 int is_phys;
59455 -};
59456 +} __do_const;
59457
59458 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
59459
59460 diff --git a/include/linux/efi.h b/include/linux/efi.h
59461 index 2362a0b..cfaf8fcc 100644
59462 --- a/include/linux/efi.h
59463 +++ b/include/linux/efi.h
59464 @@ -446,7 +446,7 @@ struct efivar_operations {
59465 efi_get_variable_t *get_variable;
59466 efi_get_next_variable_t *get_next_variable;
59467 efi_set_variable_t *set_variable;
59468 -};
59469 +} __no_const;
59470
59471 struct efivars {
59472 /*
59473 diff --git a/include/linux/elf.h b/include/linux/elf.h
59474 index 31f0508..5421c01 100644
59475 --- a/include/linux/elf.h
59476 +++ b/include/linux/elf.h
59477 @@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
59478 #define PT_GNU_EH_FRAME 0x6474e550
59479
59480 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
59481 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
59482 +
59483 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
59484 +
59485 +/* Constants for the e_flags field */
59486 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
59487 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
59488 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
59489 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
59490 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
59491 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
59492
59493 /*
59494 * Extended Numbering
59495 @@ -106,6 +117,8 @@ typedef __s64 Elf64_Sxword;
59496 #define DT_DEBUG 21
59497 #define DT_TEXTREL 22
59498 #define DT_JMPREL 23
59499 +#define DT_FLAGS 30
59500 + #define DF_TEXTREL 0x00000004
59501 #define DT_ENCODING 32
59502 #define OLD_DT_LOOS 0x60000000
59503 #define DT_LOOS 0x6000000d
59504 @@ -252,6 +265,19 @@ typedef struct elf64_hdr {
59505 #define PF_W 0x2
59506 #define PF_X 0x1
59507
59508 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
59509 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
59510 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
59511 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
59512 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
59513 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
59514 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
59515 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
59516 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
59517 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
59518 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
59519 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
59520 +
59521 typedef struct elf32_phdr{
59522 Elf32_Word p_type;
59523 Elf32_Off p_offset;
59524 @@ -344,6 +370,8 @@ typedef struct elf64_shdr {
59525 #define EI_OSABI 7
59526 #define EI_PAD 8
59527
59528 +#define EI_PAX 14
59529 +
59530 #define ELFMAG0 0x7f /* EI_MAG */
59531 #define ELFMAG1 'E'
59532 #define ELFMAG2 'L'
59533 @@ -423,6 +451,7 @@ extern Elf32_Dyn _DYNAMIC [];
59534 #define elf_note elf32_note
59535 #define elf_addr_t Elf32_Off
59536 #define Elf_Half Elf32_Half
59537 +#define elf_dyn Elf32_Dyn
59538
59539 #else
59540
59541 @@ -433,6 +462,7 @@ extern Elf64_Dyn _DYNAMIC [];
59542 #define elf_note elf64_note
59543 #define elf_addr_t Elf64_Off
59544 #define Elf_Half Elf64_Half
59545 +#define elf_dyn Elf64_Dyn
59546
59547 #endif
59548
59549 diff --git a/include/linux/filter.h b/include/linux/filter.h
59550 index 8eeb205..d59bfa2 100644
59551 --- a/include/linux/filter.h
59552 +++ b/include/linux/filter.h
59553 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
59554
59555 struct sk_buff;
59556 struct sock;
59557 +struct bpf_jit_work;
59558
59559 struct sk_filter
59560 {
59561 @@ -141,6 +142,9 @@ struct sk_filter
59562 unsigned int len; /* Number of filter blocks */
59563 unsigned int (*bpf_func)(const struct sk_buff *skb,
59564 const struct sock_filter *filter);
59565 +#ifdef CONFIG_BPF_JIT
59566 + struct bpf_jit_work *work;
59567 +#endif
59568 struct rcu_head rcu;
59569 struct sock_filter insns[0];
59570 };
59571 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
59572 index 84ccf8e..2e9b14c 100644
59573 --- a/include/linux/firewire.h
59574 +++ b/include/linux/firewire.h
59575 @@ -428,7 +428,7 @@ struct fw_iso_context {
59576 union {
59577 fw_iso_callback_t sc;
59578 fw_iso_mc_callback_t mc;
59579 - } callback;
59580 + } __no_const callback;
59581 void *callback_data;
59582 };
59583
59584 diff --git a/include/linux/fs.h b/include/linux/fs.h
59585 index 10b2288..09180e4 100644
59586 --- a/include/linux/fs.h
59587 +++ b/include/linux/fs.h
59588 @@ -1609,7 +1609,8 @@ struct file_operations {
59589 int (*setlease)(struct file *, long, struct file_lock **);
59590 long (*fallocate)(struct file *file, int mode, loff_t offset,
59591 loff_t len);
59592 -};
59593 +} __do_const;
59594 +typedef struct file_operations __no_const file_operations_no_const;
59595
59596 struct inode_operations {
59597 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
59598 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
59599 index 003dc0f..3c4ea97 100644
59600 --- a/include/linux/fs_struct.h
59601 +++ b/include/linux/fs_struct.h
59602 @@ -6,7 +6,7 @@
59603 #include <linux/seqlock.h>
59604
59605 struct fs_struct {
59606 - int users;
59607 + atomic_t users;
59608 spinlock_t lock;
59609 seqcount_t seq;
59610 int umask;
59611 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
59612 index ce31408..b1ad003 100644
59613 --- a/include/linux/fscache-cache.h
59614 +++ b/include/linux/fscache-cache.h
59615 @@ -102,7 +102,7 @@ struct fscache_operation {
59616 fscache_operation_release_t release;
59617 };
59618
59619 -extern atomic_t fscache_op_debug_id;
59620 +extern atomic_unchecked_t fscache_op_debug_id;
59621 extern void fscache_op_work_func(struct work_struct *work);
59622
59623 extern void fscache_enqueue_operation(struct fscache_operation *);
59624 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
59625 {
59626 INIT_WORK(&op->work, fscache_op_work_func);
59627 atomic_set(&op->usage, 1);
59628 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59629 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59630 op->processor = processor;
59631 op->release = release;
59632 INIT_LIST_HEAD(&op->pend_link);
59633 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
59634 index 2a53f10..0187fdf 100644
59635 --- a/include/linux/fsnotify.h
59636 +++ b/include/linux/fsnotify.h
59637 @@ -314,7 +314,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
59638 */
59639 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
59640 {
59641 - return kstrdup(name, GFP_KERNEL);
59642 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
59643 }
59644
59645 /*
59646 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
59647 index 91d0e0a3..035666b 100644
59648 --- a/include/linux/fsnotify_backend.h
59649 +++ b/include/linux/fsnotify_backend.h
59650 @@ -105,6 +105,7 @@ struct fsnotify_ops {
59651 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
59652 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
59653 };
59654 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
59655
59656 /*
59657 * A group is a "thing" that wants to receive notification about filesystem
59658 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
59659 index c3da42d..c70e0df 100644
59660 --- a/include/linux/ftrace_event.h
59661 +++ b/include/linux/ftrace_event.h
59662 @@ -97,7 +97,7 @@ struct trace_event_functions {
59663 trace_print_func raw;
59664 trace_print_func hex;
59665 trace_print_func binary;
59666 -};
59667 +} __no_const;
59668
59669 struct trace_event {
59670 struct hlist_node node;
59671 @@ -254,7 +254,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
59672 extern int trace_add_event_call(struct ftrace_event_call *call);
59673 extern void trace_remove_event_call(struct ftrace_event_call *call);
59674
59675 -#define is_signed_type(type) (((type)(-1)) < 0)
59676 +#define is_signed_type(type) (((type)(-1)) < (type)1)
59677
59678 int trace_set_clr_event(const char *system, const char *event, int set);
59679
59680 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
59681 index 6d18f35..ab71e2c 100644
59682 --- a/include/linux/genhd.h
59683 +++ b/include/linux/genhd.h
59684 @@ -185,7 +185,7 @@ struct gendisk {
59685 struct kobject *slave_dir;
59686
59687 struct timer_rand_state *random;
59688 - atomic_t sync_io; /* RAID */
59689 + atomic_unchecked_t sync_io; /* RAID */
59690 struct disk_events *ev;
59691 #ifdef CONFIG_BLK_DEV_INTEGRITY
59692 struct blk_integrity *integrity;
59693 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
59694 new file mode 100644
59695 index 0000000..8a130b6
59696 --- /dev/null
59697 +++ b/include/linux/gracl.h
59698 @@ -0,0 +1,319 @@
59699 +#ifndef GR_ACL_H
59700 +#define GR_ACL_H
59701 +
59702 +#include <linux/grdefs.h>
59703 +#include <linux/resource.h>
59704 +#include <linux/capability.h>
59705 +#include <linux/dcache.h>
59706 +#include <asm/resource.h>
59707 +
59708 +/* Major status information */
59709 +
59710 +#define GR_VERSION "grsecurity 2.9"
59711 +#define GRSECURITY_VERSION 0x2900
59712 +
59713 +enum {
59714 + GR_SHUTDOWN = 0,
59715 + GR_ENABLE = 1,
59716 + GR_SPROLE = 2,
59717 + GR_RELOAD = 3,
59718 + GR_SEGVMOD = 4,
59719 + GR_STATUS = 5,
59720 + GR_UNSPROLE = 6,
59721 + GR_PASSSET = 7,
59722 + GR_SPROLEPAM = 8,
59723 +};
59724 +
59725 +/* Password setup definitions
59726 + * kernel/grhash.c */
59727 +enum {
59728 + GR_PW_LEN = 128,
59729 + GR_SALT_LEN = 16,
59730 + GR_SHA_LEN = 32,
59731 +};
59732 +
59733 +enum {
59734 + GR_SPROLE_LEN = 64,
59735 +};
59736 +
59737 +enum {
59738 + GR_NO_GLOB = 0,
59739 + GR_REG_GLOB,
59740 + GR_CREATE_GLOB
59741 +};
59742 +
59743 +#define GR_NLIMITS 32
59744 +
59745 +/* Begin Data Structures */
59746 +
59747 +struct sprole_pw {
59748 + unsigned char *rolename;
59749 + unsigned char salt[GR_SALT_LEN];
59750 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
59751 +};
59752 +
59753 +struct name_entry {
59754 + __u32 key;
59755 + ino_t inode;
59756 + dev_t device;
59757 + char *name;
59758 + __u16 len;
59759 + __u8 deleted;
59760 + struct name_entry *prev;
59761 + struct name_entry *next;
59762 +};
59763 +
59764 +struct inodev_entry {
59765 + struct name_entry *nentry;
59766 + struct inodev_entry *prev;
59767 + struct inodev_entry *next;
59768 +};
59769 +
59770 +struct acl_role_db {
59771 + struct acl_role_label **r_hash;
59772 + __u32 r_size;
59773 +};
59774 +
59775 +struct inodev_db {
59776 + struct inodev_entry **i_hash;
59777 + __u32 i_size;
59778 +};
59779 +
59780 +struct name_db {
59781 + struct name_entry **n_hash;
59782 + __u32 n_size;
59783 +};
59784 +
59785 +struct crash_uid {
59786 + uid_t uid;
59787 + unsigned long expires;
59788 +};
59789 +
59790 +struct gr_hash_struct {
59791 + void **table;
59792 + void **nametable;
59793 + void *first;
59794 + __u32 table_size;
59795 + __u32 used_size;
59796 + int type;
59797 +};
59798 +
59799 +/* Userspace Grsecurity ACL data structures */
59800 +
59801 +struct acl_subject_label {
59802 + char *filename;
59803 + ino_t inode;
59804 + dev_t device;
59805 + __u32 mode;
59806 + kernel_cap_t cap_mask;
59807 + kernel_cap_t cap_lower;
59808 + kernel_cap_t cap_invert_audit;
59809 +
59810 + struct rlimit res[GR_NLIMITS];
59811 + __u32 resmask;
59812 +
59813 + __u8 user_trans_type;
59814 + __u8 group_trans_type;
59815 + uid_t *user_transitions;
59816 + gid_t *group_transitions;
59817 + __u16 user_trans_num;
59818 + __u16 group_trans_num;
59819 +
59820 + __u32 sock_families[2];
59821 + __u32 ip_proto[8];
59822 + __u32 ip_type;
59823 + struct acl_ip_label **ips;
59824 + __u32 ip_num;
59825 + __u32 inaddr_any_override;
59826 +
59827 + __u32 crashes;
59828 + unsigned long expires;
59829 +
59830 + struct acl_subject_label *parent_subject;
59831 + struct gr_hash_struct *hash;
59832 + struct acl_subject_label *prev;
59833 + struct acl_subject_label *next;
59834 +
59835 + struct acl_object_label **obj_hash;
59836 + __u32 obj_hash_size;
59837 + __u16 pax_flags;
59838 +};
59839 +
59840 +struct role_allowed_ip {
59841 + __u32 addr;
59842 + __u32 netmask;
59843 +
59844 + struct role_allowed_ip *prev;
59845 + struct role_allowed_ip *next;
59846 +};
59847 +
59848 +struct role_transition {
59849 + char *rolename;
59850 +
59851 + struct role_transition *prev;
59852 + struct role_transition *next;
59853 +};
59854 +
59855 +struct acl_role_label {
59856 + char *rolename;
59857 + uid_t uidgid;
59858 + __u16 roletype;
59859 +
59860 + __u16 auth_attempts;
59861 + unsigned long expires;
59862 +
59863 + struct acl_subject_label *root_label;
59864 + struct gr_hash_struct *hash;
59865 +
59866 + struct acl_role_label *prev;
59867 + struct acl_role_label *next;
59868 +
59869 + struct role_transition *transitions;
59870 + struct role_allowed_ip *allowed_ips;
59871 + uid_t *domain_children;
59872 + __u16 domain_child_num;
59873 +
59874 + umode_t umask;
59875 +
59876 + struct acl_subject_label **subj_hash;
59877 + __u32 subj_hash_size;
59878 +};
59879 +
59880 +struct user_acl_role_db {
59881 + struct acl_role_label **r_table;
59882 + __u32 num_pointers; /* Number of allocations to track */
59883 + __u32 num_roles; /* Number of roles */
59884 + __u32 num_domain_children; /* Number of domain children */
59885 + __u32 num_subjects; /* Number of subjects */
59886 + __u32 num_objects; /* Number of objects */
59887 +};
59888 +
59889 +struct acl_object_label {
59890 + char *filename;
59891 + ino_t inode;
59892 + dev_t device;
59893 + __u32 mode;
59894 +
59895 + struct acl_subject_label *nested;
59896 + struct acl_object_label *globbed;
59897 +
59898 + /* next two structures not used */
59899 +
59900 + struct acl_object_label *prev;
59901 + struct acl_object_label *next;
59902 +};
59903 +
59904 +struct acl_ip_label {
59905 + char *iface;
59906 + __u32 addr;
59907 + __u32 netmask;
59908 + __u16 low, high;
59909 + __u8 mode;
59910 + __u32 type;
59911 + __u32 proto[8];
59912 +
59913 + /* next two structures not used */
59914 +
59915 + struct acl_ip_label *prev;
59916 + struct acl_ip_label *next;
59917 +};
59918 +
59919 +struct gr_arg {
59920 + struct user_acl_role_db role_db;
59921 + unsigned char pw[GR_PW_LEN];
59922 + unsigned char salt[GR_SALT_LEN];
59923 + unsigned char sum[GR_SHA_LEN];
59924 + unsigned char sp_role[GR_SPROLE_LEN];
59925 + struct sprole_pw *sprole_pws;
59926 + dev_t segv_device;
59927 + ino_t segv_inode;
59928 + uid_t segv_uid;
59929 + __u16 num_sprole_pws;
59930 + __u16 mode;
59931 +};
59932 +
59933 +struct gr_arg_wrapper {
59934 + struct gr_arg *arg;
59935 + __u32 version;
59936 + __u32 size;
59937 +};
59938 +
59939 +struct subject_map {
59940 + struct acl_subject_label *user;
59941 + struct acl_subject_label *kernel;
59942 + struct subject_map *prev;
59943 + struct subject_map *next;
59944 +};
59945 +
59946 +struct acl_subj_map_db {
59947 + struct subject_map **s_hash;
59948 + __u32 s_size;
59949 +};
59950 +
59951 +/* End Data Structures Section */
59952 +
59953 +/* Hash functions generated by empirical testing by Brad Spengler
59954 + Makes good use of the low bits of the inode. Generally 0-1 times
59955 + in loop for successful match. 0-3 for unsuccessful match.
59956 + Shift/add algorithm with modulus of table size and an XOR*/
59957 +
59958 +static __inline__ unsigned int
59959 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
59960 +{
59961 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
59962 +}
59963 +
59964 + static __inline__ unsigned int
59965 +shash(const struct acl_subject_label *userp, const unsigned int sz)
59966 +{
59967 + return ((const unsigned long)userp % sz);
59968 +}
59969 +
59970 +static __inline__ unsigned int
59971 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
59972 +{
59973 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
59974 +}
59975 +
59976 +static __inline__ unsigned int
59977 +nhash(const char *name, const __u16 len, const unsigned int sz)
59978 +{
59979 + return full_name_hash((const unsigned char *)name, len) % sz;
59980 +}
59981 +
59982 +#define FOR_EACH_ROLE_START(role) \
59983 + role = role_list; \
59984 + while (role) {
59985 +
59986 +#define FOR_EACH_ROLE_END(role) \
59987 + role = role->prev; \
59988 + }
59989 +
59990 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
59991 + subj = NULL; \
59992 + iter = 0; \
59993 + while (iter < role->subj_hash_size) { \
59994 + if (subj == NULL) \
59995 + subj = role->subj_hash[iter]; \
59996 + if (subj == NULL) { \
59997 + iter++; \
59998 + continue; \
59999 + }
60000 +
60001 +#define FOR_EACH_SUBJECT_END(subj,iter) \
60002 + subj = subj->next; \
60003 + if (subj == NULL) \
60004 + iter++; \
60005 + }
60006 +
60007 +
60008 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
60009 + subj = role->hash->first; \
60010 + while (subj != NULL) {
60011 +
60012 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
60013 + subj = subj->next; \
60014 + }
60015 +
60016 +#endif
60017 +
60018 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
60019 new file mode 100644
60020 index 0000000..323ecf2
60021 --- /dev/null
60022 +++ b/include/linux/gralloc.h
60023 @@ -0,0 +1,9 @@
60024 +#ifndef __GRALLOC_H
60025 +#define __GRALLOC_H
60026 +
60027 +void acl_free_all(void);
60028 +int acl_alloc_stack_init(unsigned long size);
60029 +void *acl_alloc(unsigned long len);
60030 +void *acl_alloc_num(unsigned long num, unsigned long len);
60031 +
60032 +#endif
60033 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
60034 new file mode 100644
60035 index 0000000..b30e9bc
60036 --- /dev/null
60037 +++ b/include/linux/grdefs.h
60038 @@ -0,0 +1,140 @@
60039 +#ifndef GRDEFS_H
60040 +#define GRDEFS_H
60041 +
60042 +/* Begin grsecurity status declarations */
60043 +
60044 +enum {
60045 + GR_READY = 0x01,
60046 + GR_STATUS_INIT = 0x00 // disabled state
60047 +};
60048 +
60049 +/* Begin ACL declarations */
60050 +
60051 +/* Role flags */
60052 +
60053 +enum {
60054 + GR_ROLE_USER = 0x0001,
60055 + GR_ROLE_GROUP = 0x0002,
60056 + GR_ROLE_DEFAULT = 0x0004,
60057 + GR_ROLE_SPECIAL = 0x0008,
60058 + GR_ROLE_AUTH = 0x0010,
60059 + GR_ROLE_NOPW = 0x0020,
60060 + GR_ROLE_GOD = 0x0040,
60061 + GR_ROLE_LEARN = 0x0080,
60062 + GR_ROLE_TPE = 0x0100,
60063 + GR_ROLE_DOMAIN = 0x0200,
60064 + GR_ROLE_PAM = 0x0400,
60065 + GR_ROLE_PERSIST = 0x0800
60066 +};
60067 +
60068 +/* ACL Subject and Object mode flags */
60069 +enum {
60070 + GR_DELETED = 0x80000000
60071 +};
60072 +
60073 +/* ACL Object-only mode flags */
60074 +enum {
60075 + GR_READ = 0x00000001,
60076 + GR_APPEND = 0x00000002,
60077 + GR_WRITE = 0x00000004,
60078 + GR_EXEC = 0x00000008,
60079 + GR_FIND = 0x00000010,
60080 + GR_INHERIT = 0x00000020,
60081 + GR_SETID = 0x00000040,
60082 + GR_CREATE = 0x00000080,
60083 + GR_DELETE = 0x00000100,
60084 + GR_LINK = 0x00000200,
60085 + GR_AUDIT_READ = 0x00000400,
60086 + GR_AUDIT_APPEND = 0x00000800,
60087 + GR_AUDIT_WRITE = 0x00001000,
60088 + GR_AUDIT_EXEC = 0x00002000,
60089 + GR_AUDIT_FIND = 0x00004000,
60090 + GR_AUDIT_INHERIT= 0x00008000,
60091 + GR_AUDIT_SETID = 0x00010000,
60092 + GR_AUDIT_CREATE = 0x00020000,
60093 + GR_AUDIT_DELETE = 0x00040000,
60094 + GR_AUDIT_LINK = 0x00080000,
60095 + GR_PTRACERD = 0x00100000,
60096 + GR_NOPTRACE = 0x00200000,
60097 + GR_SUPPRESS = 0x00400000,
60098 + GR_NOLEARN = 0x00800000,
60099 + GR_INIT_TRANSFER= 0x01000000
60100 +};
60101 +
60102 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
60103 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
60104 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
60105 +
60106 +/* ACL subject-only mode flags */
60107 +enum {
60108 + GR_KILL = 0x00000001,
60109 + GR_VIEW = 0x00000002,
60110 + GR_PROTECTED = 0x00000004,
60111 + GR_LEARN = 0x00000008,
60112 + GR_OVERRIDE = 0x00000010,
60113 + /* just a placeholder, this mode is only used in userspace */
60114 + GR_DUMMY = 0x00000020,
60115 + GR_PROTSHM = 0x00000040,
60116 + GR_KILLPROC = 0x00000080,
60117 + GR_KILLIPPROC = 0x00000100,
60118 + /* just a placeholder, this mode is only used in userspace */
60119 + GR_NOTROJAN = 0x00000200,
60120 + GR_PROTPROCFD = 0x00000400,
60121 + GR_PROCACCT = 0x00000800,
60122 + GR_RELAXPTRACE = 0x00001000,
60123 + GR_NESTED = 0x00002000,
60124 + GR_INHERITLEARN = 0x00004000,
60125 + GR_PROCFIND = 0x00008000,
60126 + GR_POVERRIDE = 0x00010000,
60127 + GR_KERNELAUTH = 0x00020000,
60128 + GR_ATSECURE = 0x00040000,
60129 + GR_SHMEXEC = 0x00080000
60130 +};
60131 +
60132 +enum {
60133 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
60134 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
60135 + GR_PAX_ENABLE_MPROTECT = 0x0004,
60136 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
60137 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
60138 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
60139 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
60140 + GR_PAX_DISABLE_MPROTECT = 0x0400,
60141 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
60142 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
60143 +};
60144 +
60145 +enum {
60146 + GR_ID_USER = 0x01,
60147 + GR_ID_GROUP = 0x02,
60148 +};
60149 +
60150 +enum {
60151 + GR_ID_ALLOW = 0x01,
60152 + GR_ID_DENY = 0x02,
60153 +};
60154 +
60155 +#define GR_CRASH_RES 31
60156 +#define GR_UIDTABLE_MAX 500
60157 +
60158 +/* begin resource learning section */
60159 +enum {
60160 + GR_RLIM_CPU_BUMP = 60,
60161 + GR_RLIM_FSIZE_BUMP = 50000,
60162 + GR_RLIM_DATA_BUMP = 10000,
60163 + GR_RLIM_STACK_BUMP = 1000,
60164 + GR_RLIM_CORE_BUMP = 10000,
60165 + GR_RLIM_RSS_BUMP = 500000,
60166 + GR_RLIM_NPROC_BUMP = 1,
60167 + GR_RLIM_NOFILE_BUMP = 5,
60168 + GR_RLIM_MEMLOCK_BUMP = 50000,
60169 + GR_RLIM_AS_BUMP = 500000,
60170 + GR_RLIM_LOCKS_BUMP = 2,
60171 + GR_RLIM_SIGPENDING_BUMP = 5,
60172 + GR_RLIM_MSGQUEUE_BUMP = 10000,
60173 + GR_RLIM_NICE_BUMP = 1,
60174 + GR_RLIM_RTPRIO_BUMP = 1,
60175 + GR_RLIM_RTTIME_BUMP = 1000000
60176 +};
60177 +
60178 +#endif
60179 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
60180 new file mode 100644
60181 index 0000000..da390f1
60182 --- /dev/null
60183 +++ b/include/linux/grinternal.h
60184 @@ -0,0 +1,221 @@
60185 +#ifndef __GRINTERNAL_H
60186 +#define __GRINTERNAL_H
60187 +
60188 +#ifdef CONFIG_GRKERNSEC
60189 +
60190 +#include <linux/fs.h>
60191 +#include <linux/mnt_namespace.h>
60192 +#include <linux/nsproxy.h>
60193 +#include <linux/gracl.h>
60194 +#include <linux/grdefs.h>
60195 +#include <linux/grmsg.h>
60196 +
60197 +void gr_add_learn_entry(const char *fmt, ...)
60198 + __attribute__ ((format (printf, 1, 2)));
60199 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
60200 + const struct vfsmount *mnt);
60201 +__u32 gr_check_create(const struct dentry *new_dentry,
60202 + const struct dentry *parent,
60203 + const struct vfsmount *mnt, const __u32 mode);
60204 +int gr_check_protected_task(const struct task_struct *task);
60205 +__u32 to_gr_audit(const __u32 reqmode);
60206 +int gr_set_acls(const int type);
60207 +int gr_apply_subject_to_task(struct task_struct *task);
60208 +int gr_acl_is_enabled(void);
60209 +char gr_roletype_to_char(void);
60210 +
60211 +void gr_handle_alertkill(struct task_struct *task);
60212 +char *gr_to_filename(const struct dentry *dentry,
60213 + const struct vfsmount *mnt);
60214 +char *gr_to_filename1(const struct dentry *dentry,
60215 + const struct vfsmount *mnt);
60216 +char *gr_to_filename2(const struct dentry *dentry,
60217 + const struct vfsmount *mnt);
60218 +char *gr_to_filename3(const struct dentry *dentry,
60219 + const struct vfsmount *mnt);
60220 +
60221 +extern int grsec_enable_ptrace_readexec;
60222 +extern int grsec_enable_harden_ptrace;
60223 +extern int grsec_enable_link;
60224 +extern int grsec_enable_fifo;
60225 +extern int grsec_enable_execve;
60226 +extern int grsec_enable_shm;
60227 +extern int grsec_enable_execlog;
60228 +extern int grsec_enable_signal;
60229 +extern int grsec_enable_audit_ptrace;
60230 +extern int grsec_enable_forkfail;
60231 +extern int grsec_enable_time;
60232 +extern int grsec_enable_rofs;
60233 +extern int grsec_enable_chroot_shmat;
60234 +extern int grsec_enable_chroot_mount;
60235 +extern int grsec_enable_chroot_double;
60236 +extern int grsec_enable_chroot_pivot;
60237 +extern int grsec_enable_chroot_chdir;
60238 +extern int grsec_enable_chroot_chmod;
60239 +extern int grsec_enable_chroot_mknod;
60240 +extern int grsec_enable_chroot_fchdir;
60241 +extern int grsec_enable_chroot_nice;
60242 +extern int grsec_enable_chroot_execlog;
60243 +extern int grsec_enable_chroot_caps;
60244 +extern int grsec_enable_chroot_sysctl;
60245 +extern int grsec_enable_chroot_unix;
60246 +extern int grsec_enable_tpe;
60247 +extern int grsec_tpe_gid;
60248 +extern int grsec_enable_tpe_all;
60249 +extern int grsec_enable_tpe_invert;
60250 +extern int grsec_enable_socket_all;
60251 +extern int grsec_socket_all_gid;
60252 +extern int grsec_enable_socket_client;
60253 +extern int grsec_socket_client_gid;
60254 +extern int grsec_enable_socket_server;
60255 +extern int grsec_socket_server_gid;
60256 +extern int grsec_audit_gid;
60257 +extern int grsec_enable_group;
60258 +extern int grsec_enable_audit_textrel;
60259 +extern int grsec_enable_log_rwxmaps;
60260 +extern int grsec_enable_mount;
60261 +extern int grsec_enable_chdir;
60262 +extern int grsec_resource_logging;
60263 +extern int grsec_enable_blackhole;
60264 +extern int grsec_lastack_retries;
60265 +extern int grsec_enable_brute;
60266 +extern int grsec_lock;
60267 +
60268 +extern spinlock_t grsec_alert_lock;
60269 +extern unsigned long grsec_alert_wtime;
60270 +extern unsigned long grsec_alert_fyet;
60271 +
60272 +extern spinlock_t grsec_audit_lock;
60273 +
60274 +extern rwlock_t grsec_exec_file_lock;
60275 +
60276 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
60277 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
60278 + (tsk)->exec_file->f_vfsmnt) : "/")
60279 +
60280 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
60281 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
60282 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
60283 +
60284 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
60285 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
60286 + (tsk)->exec_file->f_vfsmnt) : "/")
60287 +
60288 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
60289 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
60290 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
60291 +
60292 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
60293 +
60294 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
60295 +
60296 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
60297 + (task)->pid, (cred)->uid, \
60298 + (cred)->euid, (cred)->gid, (cred)->egid, \
60299 + gr_parent_task_fullpath(task), \
60300 + (task)->real_parent->comm, (task)->real_parent->pid, \
60301 + (pcred)->uid, (pcred)->euid, \
60302 + (pcred)->gid, (pcred)->egid
60303 +
60304 +#define GR_CHROOT_CAPS {{ \
60305 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
60306 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
60307 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
60308 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
60309 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
60310 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
60311 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
60312 +
60313 +#define security_learn(normal_msg,args...) \
60314 +({ \
60315 + read_lock(&grsec_exec_file_lock); \
60316 + gr_add_learn_entry(normal_msg "\n", ## args); \
60317 + read_unlock(&grsec_exec_file_lock); \
60318 +})
60319 +
60320 +enum {
60321 + GR_DO_AUDIT,
60322 + GR_DONT_AUDIT,
60323 + /* used for non-audit messages that we shouldn't kill the task on */
60324 + GR_DONT_AUDIT_GOOD
60325 +};
60326 +
60327 +enum {
60328 + GR_TTYSNIFF,
60329 + GR_RBAC,
60330 + GR_RBAC_STR,
60331 + GR_STR_RBAC,
60332 + GR_RBAC_MODE2,
60333 + GR_RBAC_MODE3,
60334 + GR_FILENAME,
60335 + GR_SYSCTL_HIDDEN,
60336 + GR_NOARGS,
60337 + GR_ONE_INT,
60338 + GR_ONE_INT_TWO_STR,
60339 + GR_ONE_STR,
60340 + GR_STR_INT,
60341 + GR_TWO_STR_INT,
60342 + GR_TWO_INT,
60343 + GR_TWO_U64,
60344 + GR_THREE_INT,
60345 + GR_FIVE_INT_TWO_STR,
60346 + GR_TWO_STR,
60347 + GR_THREE_STR,
60348 + GR_FOUR_STR,
60349 + GR_STR_FILENAME,
60350 + GR_FILENAME_STR,
60351 + GR_FILENAME_TWO_INT,
60352 + GR_FILENAME_TWO_INT_STR,
60353 + GR_TEXTREL,
60354 + GR_PTRACE,
60355 + GR_RESOURCE,
60356 + GR_CAP,
60357 + GR_SIG,
60358 + GR_SIG2,
60359 + GR_CRASH1,
60360 + GR_CRASH2,
60361 + GR_PSACCT,
60362 + GR_RWXMAP
60363 +};
60364 +
60365 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
60366 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
60367 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
60368 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
60369 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
60370 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
60371 +#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)
60372 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
60373 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
60374 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
60375 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
60376 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
60377 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
60378 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
60379 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
60380 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
60381 +#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)
60382 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
60383 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
60384 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
60385 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
60386 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
60387 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
60388 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
60389 +#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)
60390 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
60391 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
60392 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
60393 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
60394 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
60395 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
60396 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
60397 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
60398 +#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)
60399 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
60400 +
60401 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
60402 +
60403 +#endif
60404 +
60405 +#endif
60406 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
60407 new file mode 100644
60408 index 0000000..ae576a1
60409 --- /dev/null
60410 +++ b/include/linux/grmsg.h
60411 @@ -0,0 +1,109 @@
60412 +#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"
60413 +#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"
60414 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
60415 +#define GR_STOPMOD_MSG "denied modification of module state by "
60416 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
60417 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
60418 +#define GR_IOPERM_MSG "denied use of ioperm() by "
60419 +#define GR_IOPL_MSG "denied use of iopl() by "
60420 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
60421 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
60422 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
60423 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
60424 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
60425 +#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"
60426 +#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"
60427 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
60428 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
60429 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
60430 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
60431 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
60432 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
60433 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
60434 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
60435 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
60436 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
60437 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
60438 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
60439 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
60440 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
60441 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
60442 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
60443 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
60444 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
60445 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
60446 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
60447 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
60448 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
60449 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
60450 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
60451 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
60452 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
60453 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
60454 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
60455 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
60456 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
60457 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
60458 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
60459 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
60460 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
60461 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
60462 +#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"
60463 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
60464 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
60465 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
60466 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
60467 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
60468 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
60469 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
60470 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
60471 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
60472 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
60473 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
60474 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
60475 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
60476 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
60477 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
60478 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
60479 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
60480 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
60481 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
60482 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
60483 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
60484 +#define GR_NICE_CHROOT_MSG "denied priority change by "
60485 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
60486 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
60487 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
60488 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
60489 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
60490 +#define GR_TIME_MSG "time set by "
60491 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
60492 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
60493 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
60494 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
60495 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
60496 +#define GR_BIND_MSG "denied bind() by "
60497 +#define GR_CONNECT_MSG "denied connect() by "
60498 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
60499 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
60500 +#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"
60501 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
60502 +#define GR_CAP_ACL_MSG "use of %s denied for "
60503 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
60504 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
60505 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
60506 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
60507 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
60508 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
60509 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
60510 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
60511 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
60512 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
60513 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
60514 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
60515 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
60516 +#define GR_VM86_MSG "denied use of vm86 by "
60517 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
60518 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
60519 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
60520 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
60521 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
60522 new file mode 100644
60523 index 0000000..2ccf677
60524 --- /dev/null
60525 +++ b/include/linux/grsecurity.h
60526 @@ -0,0 +1,229 @@
60527 +#ifndef GR_SECURITY_H
60528 +#define GR_SECURITY_H
60529 +#include <linux/fs.h>
60530 +#include <linux/fs_struct.h>
60531 +#include <linux/binfmts.h>
60532 +#include <linux/gracl.h>
60533 +
60534 +/* notify of brain-dead configs */
60535 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60536 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
60537 +#endif
60538 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
60539 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
60540 +#endif
60541 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
60542 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
60543 +#endif
60544 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
60545 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
60546 +#endif
60547 +
60548 +#include <linux/compat.h>
60549 +
60550 +struct user_arg_ptr {
60551 +#ifdef CONFIG_COMPAT
60552 + bool is_compat;
60553 +#endif
60554 + union {
60555 + const char __user *const __user *native;
60556 +#ifdef CONFIG_COMPAT
60557 + compat_uptr_t __user *compat;
60558 +#endif
60559 + } ptr;
60560 +};
60561 +
60562 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
60563 +void gr_handle_brute_check(void);
60564 +void gr_handle_kernel_exploit(void);
60565 +int gr_process_user_ban(void);
60566 +
60567 +char gr_roletype_to_char(void);
60568 +
60569 +int gr_acl_enable_at_secure(void);
60570 +
60571 +int gr_check_user_change(int real, int effective, int fs);
60572 +int gr_check_group_change(int real, int effective, int fs);
60573 +
60574 +void gr_del_task_from_ip_table(struct task_struct *p);
60575 +
60576 +int gr_pid_is_chrooted(struct task_struct *p);
60577 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
60578 +int gr_handle_chroot_nice(void);
60579 +int gr_handle_chroot_sysctl(const int op);
60580 +int gr_handle_chroot_setpriority(struct task_struct *p,
60581 + const int niceval);
60582 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
60583 +int gr_handle_chroot_chroot(const struct dentry *dentry,
60584 + const struct vfsmount *mnt);
60585 +void gr_handle_chroot_chdir(struct path *path);
60586 +int gr_handle_chroot_chmod(const struct dentry *dentry,
60587 + const struct vfsmount *mnt, const int mode);
60588 +int gr_handle_chroot_mknod(const struct dentry *dentry,
60589 + const struct vfsmount *mnt, const int mode);
60590 +int gr_handle_chroot_mount(const struct dentry *dentry,
60591 + const struct vfsmount *mnt,
60592 + const char *dev_name);
60593 +int gr_handle_chroot_pivot(void);
60594 +int gr_handle_chroot_unix(const pid_t pid);
60595 +
60596 +int gr_handle_rawio(const struct inode *inode);
60597 +
60598 +void gr_handle_ioperm(void);
60599 +void gr_handle_iopl(void);
60600 +
60601 +umode_t gr_acl_umask(void);
60602 +
60603 +int gr_tpe_allow(const struct file *file);
60604 +
60605 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
60606 +void gr_clear_chroot_entries(struct task_struct *task);
60607 +
60608 +void gr_log_forkfail(const int retval);
60609 +void gr_log_timechange(void);
60610 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
60611 +void gr_log_chdir(const struct dentry *dentry,
60612 + const struct vfsmount *mnt);
60613 +void gr_log_chroot_exec(const struct dentry *dentry,
60614 + const struct vfsmount *mnt);
60615 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
60616 +void gr_log_remount(const char *devname, const int retval);
60617 +void gr_log_unmount(const char *devname, const int retval);
60618 +void gr_log_mount(const char *from, const char *to, const int retval);
60619 +void gr_log_textrel(struct vm_area_struct *vma);
60620 +void gr_log_rwxmmap(struct file *file);
60621 +void gr_log_rwxmprotect(struct file *file);
60622 +
60623 +int gr_handle_follow_link(const struct inode *parent,
60624 + const struct inode *inode,
60625 + const struct dentry *dentry,
60626 + const struct vfsmount *mnt);
60627 +int gr_handle_fifo(const struct dentry *dentry,
60628 + const struct vfsmount *mnt,
60629 + const struct dentry *dir, const int flag,
60630 + const int acc_mode);
60631 +int gr_handle_hardlink(const struct dentry *dentry,
60632 + const struct vfsmount *mnt,
60633 + struct inode *inode,
60634 + const int mode, const char *to);
60635 +
60636 +int gr_is_capable(const int cap);
60637 +int gr_is_capable_nolog(const int cap);
60638 +void gr_learn_resource(const struct task_struct *task, const int limit,
60639 + const unsigned long wanted, const int gt);
60640 +void gr_copy_label(struct task_struct *tsk);
60641 +void gr_handle_crash(struct task_struct *task, const int sig);
60642 +int gr_handle_signal(const struct task_struct *p, const int sig);
60643 +int gr_check_crash_uid(const uid_t uid);
60644 +int gr_check_protected_task(const struct task_struct *task);
60645 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
60646 +int gr_acl_handle_mmap(const struct file *file,
60647 + const unsigned long prot);
60648 +int gr_acl_handle_mprotect(const struct file *file,
60649 + const unsigned long prot);
60650 +int gr_check_hidden_task(const struct task_struct *tsk);
60651 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
60652 + const struct vfsmount *mnt);
60653 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
60654 + const struct vfsmount *mnt);
60655 +__u32 gr_acl_handle_access(const struct dentry *dentry,
60656 + const struct vfsmount *mnt, const int fmode);
60657 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
60658 + const struct vfsmount *mnt, umode_t *mode);
60659 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
60660 + const struct vfsmount *mnt);
60661 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
60662 + const struct vfsmount *mnt);
60663 +int gr_handle_ptrace(struct task_struct *task, const long request);
60664 +int gr_handle_proc_ptrace(struct task_struct *task);
60665 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
60666 + const struct vfsmount *mnt);
60667 +int gr_check_crash_exec(const struct file *filp);
60668 +int gr_acl_is_enabled(void);
60669 +void gr_set_kernel_label(struct task_struct *task);
60670 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
60671 + const gid_t gid);
60672 +int gr_set_proc_label(const struct dentry *dentry,
60673 + const struct vfsmount *mnt,
60674 + const int unsafe_flags);
60675 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
60676 + const struct vfsmount *mnt);
60677 +__u32 gr_acl_handle_open(const struct dentry *dentry,
60678 + const struct vfsmount *mnt, int acc_mode);
60679 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
60680 + const struct dentry *p_dentry,
60681 + const struct vfsmount *p_mnt,
60682 + int open_flags, int acc_mode, const int imode);
60683 +void gr_handle_create(const struct dentry *dentry,
60684 + const struct vfsmount *mnt);
60685 +void gr_handle_proc_create(const struct dentry *dentry,
60686 + const struct inode *inode);
60687 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
60688 + const struct dentry *parent_dentry,
60689 + const struct vfsmount *parent_mnt,
60690 + const int mode);
60691 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
60692 + const struct dentry *parent_dentry,
60693 + const struct vfsmount *parent_mnt);
60694 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
60695 + const struct vfsmount *mnt);
60696 +void gr_handle_delete(const ino_t ino, const dev_t dev);
60697 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
60698 + const struct vfsmount *mnt);
60699 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
60700 + const struct dentry *parent_dentry,
60701 + const struct vfsmount *parent_mnt,
60702 + const char *from);
60703 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
60704 + const struct dentry *parent_dentry,
60705 + const struct vfsmount *parent_mnt,
60706 + const struct dentry *old_dentry,
60707 + const struct vfsmount *old_mnt, const char *to);
60708 +int gr_acl_handle_rename(struct dentry *new_dentry,
60709 + struct dentry *parent_dentry,
60710 + const struct vfsmount *parent_mnt,
60711 + struct dentry *old_dentry,
60712 + struct inode *old_parent_inode,
60713 + struct vfsmount *old_mnt, const char *newname);
60714 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
60715 + struct dentry *old_dentry,
60716 + struct dentry *new_dentry,
60717 + struct vfsmount *mnt, const __u8 replace);
60718 +__u32 gr_check_link(const struct dentry *new_dentry,
60719 + const struct dentry *parent_dentry,
60720 + const struct vfsmount *parent_mnt,
60721 + const struct dentry *old_dentry,
60722 + const struct vfsmount *old_mnt);
60723 +int gr_acl_handle_filldir(const struct file *file, const char *name,
60724 + const unsigned int namelen, const ino_t ino);
60725 +
60726 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
60727 + const struct vfsmount *mnt);
60728 +void gr_acl_handle_exit(void);
60729 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
60730 +int gr_acl_handle_procpidmem(const struct task_struct *task);
60731 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
60732 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
60733 +void gr_audit_ptrace(struct task_struct *task);
60734 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
60735 +
60736 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
60737 +
60738 +#ifdef CONFIG_GRKERNSEC
60739 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
60740 +void gr_handle_vm86(void);
60741 +void gr_handle_mem_readwrite(u64 from, u64 to);
60742 +
60743 +void gr_log_badprocpid(const char *entry);
60744 +
60745 +extern int grsec_enable_dmesg;
60746 +extern int grsec_disable_privio;
60747 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60748 +extern int grsec_enable_chroot_findtask;
60749 +#endif
60750 +#ifdef CONFIG_GRKERNSEC_SETXID
60751 +extern int grsec_enable_setxid;
60752 +#endif
60753 +#endif
60754 +
60755 +#endif
60756 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
60757 new file mode 100644
60758 index 0000000..e7ffaaf
60759 --- /dev/null
60760 +++ b/include/linux/grsock.h
60761 @@ -0,0 +1,19 @@
60762 +#ifndef __GRSOCK_H
60763 +#define __GRSOCK_H
60764 +
60765 +extern void gr_attach_curr_ip(const struct sock *sk);
60766 +extern int gr_handle_sock_all(const int family, const int type,
60767 + const int protocol);
60768 +extern int gr_handle_sock_server(const struct sockaddr *sck);
60769 +extern int gr_handle_sock_server_other(const struct sock *sck);
60770 +extern int gr_handle_sock_client(const struct sockaddr *sck);
60771 +extern int gr_search_connect(struct socket * sock,
60772 + struct sockaddr_in * addr);
60773 +extern int gr_search_bind(struct socket * sock,
60774 + struct sockaddr_in * addr);
60775 +extern int gr_search_listen(struct socket * sock);
60776 +extern int gr_search_accept(struct socket * sock);
60777 +extern int gr_search_socket(const int domain, const int type,
60778 + const int protocol);
60779 +
60780 +#endif
60781 diff --git a/include/linux/hid.h b/include/linux/hid.h
60782 index c235e4e..f0cf7a0 100644
60783 --- a/include/linux/hid.h
60784 +++ b/include/linux/hid.h
60785 @@ -679,7 +679,7 @@ struct hid_ll_driver {
60786 unsigned int code, int value);
60787
60788 int (*parse)(struct hid_device *hdev);
60789 -};
60790 +} __no_const;
60791
60792 #define PM_HINT_FULLON 1<<5
60793 #define PM_HINT_NORMAL 1<<1
60794 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
60795 index 3a93f73..b19d0b3 100644
60796 --- a/include/linux/highmem.h
60797 +++ b/include/linux/highmem.h
60798 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
60799 kunmap_atomic(kaddr, KM_USER0);
60800 }
60801
60802 +static inline void sanitize_highpage(struct page *page)
60803 +{
60804 + void *kaddr;
60805 + unsigned long flags;
60806 +
60807 + local_irq_save(flags);
60808 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
60809 + clear_page(kaddr);
60810 + kunmap_atomic(kaddr, KM_CLEARPAGE);
60811 + local_irq_restore(flags);
60812 +}
60813 +
60814 static inline void zero_user_segments(struct page *page,
60815 unsigned start1, unsigned end1,
60816 unsigned start2, unsigned end2)
60817 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
60818 index 07d103a..04ec65b 100644
60819 --- a/include/linux/i2c.h
60820 +++ b/include/linux/i2c.h
60821 @@ -364,6 +364,7 @@ struct i2c_algorithm {
60822 /* To determine what the adapter supports */
60823 u32 (*functionality) (struct i2c_adapter *);
60824 };
60825 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
60826
60827 /*
60828 * i2c_adapter is the structure used to identify a physical i2c bus along
60829 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
60830 index a6deef4..c56a7f2 100644
60831 --- a/include/linux/i2o.h
60832 +++ b/include/linux/i2o.h
60833 @@ -564,7 +564,7 @@ struct i2o_controller {
60834 struct i2o_device *exec; /* Executive */
60835 #if BITS_PER_LONG == 64
60836 spinlock_t context_list_lock; /* lock for context_list */
60837 - atomic_t context_list_counter; /* needed for unique contexts */
60838 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
60839 struct list_head context_list; /* list of context id's
60840 and pointers */
60841 #endif
60842 diff --git a/include/linux/init.h b/include/linux/init.h
60843 index 9146f39..885354d 100644
60844 --- a/include/linux/init.h
60845 +++ b/include/linux/init.h
60846 @@ -293,13 +293,13 @@ void __init parse_early_options(char *cmdline);
60847
60848 /* Each module must use one module_init(). */
60849 #define module_init(initfn) \
60850 - static inline initcall_t __inittest(void) \
60851 + static inline __used initcall_t __inittest(void) \
60852 { return initfn; } \
60853 int init_module(void) __attribute__((alias(#initfn)));
60854
60855 /* This is only required if you want to be unloadable. */
60856 #define module_exit(exitfn) \
60857 - static inline exitcall_t __exittest(void) \
60858 + static inline __used exitcall_t __exittest(void) \
60859 { return exitfn; } \
60860 void cleanup_module(void) __attribute__((alias(#exitfn)));
60861
60862 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
60863 index 32574ee..00d4ef1 100644
60864 --- a/include/linux/init_task.h
60865 +++ b/include/linux/init_task.h
60866 @@ -128,6 +128,12 @@ extern struct cred init_cred;
60867
60868 #define INIT_TASK_COMM "swapper"
60869
60870 +#ifdef CONFIG_X86
60871 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
60872 +#else
60873 +#define INIT_TASK_THREAD_INFO
60874 +#endif
60875 +
60876 /*
60877 * INIT_TASK is used to set up the first task table, touch at
60878 * your own risk!. Base=0, limit=0x1fffff (=2MB)
60879 @@ -166,6 +172,7 @@ extern struct cred init_cred;
60880 RCU_INIT_POINTER(.cred, &init_cred), \
60881 .comm = INIT_TASK_COMM, \
60882 .thread = INIT_THREAD, \
60883 + INIT_TASK_THREAD_INFO \
60884 .fs = &init_fs, \
60885 .files = &init_files, \
60886 .signal = &init_signals, \
60887 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
60888 index e6ca56d..8583707 100644
60889 --- a/include/linux/intel-iommu.h
60890 +++ b/include/linux/intel-iommu.h
60891 @@ -296,7 +296,7 @@ struct iommu_flush {
60892 u8 fm, u64 type);
60893 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
60894 unsigned int size_order, u64 type);
60895 -};
60896 +} __no_const;
60897
60898 enum {
60899 SR_DMAR_FECTL_REG,
60900 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
60901 index a64b00e..464d8bc 100644
60902 --- a/include/linux/interrupt.h
60903 +++ b/include/linux/interrupt.h
60904 @@ -441,7 +441,7 @@ enum
60905 /* map softirq index to softirq name. update 'softirq_to_name' in
60906 * kernel/softirq.c when adding a new softirq.
60907 */
60908 -extern char *softirq_to_name[NR_SOFTIRQS];
60909 +extern const char * const softirq_to_name[NR_SOFTIRQS];
60910
60911 /* softirq mask and active fields moved to irq_cpustat_t in
60912 * asm/hardirq.h to get better cache usage. KAO
60913 @@ -449,12 +449,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
60914
60915 struct softirq_action
60916 {
60917 - void (*action)(struct softirq_action *);
60918 + void (*action)(void);
60919 };
60920
60921 asmlinkage void do_softirq(void);
60922 asmlinkage void __do_softirq(void);
60923 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
60924 +extern void open_softirq(int nr, void (*action)(void));
60925 extern void softirq_init(void);
60926 static inline void __raise_softirq_irqoff(unsigned int nr)
60927 {
60928 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
60929 index 3875719..4cd454c 100644
60930 --- a/include/linux/kallsyms.h
60931 +++ b/include/linux/kallsyms.h
60932 @@ -15,7 +15,8 @@
60933
60934 struct module;
60935
60936 -#ifdef CONFIG_KALLSYMS
60937 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
60938 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60939 /* Lookup the address for a symbol. Returns 0 if not found. */
60940 unsigned long kallsyms_lookup_name(const char *name);
60941
60942 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
60943 /* Stupid that this does nothing, but I didn't create this mess. */
60944 #define __print_symbol(fmt, addr)
60945 #endif /*CONFIG_KALLSYMS*/
60946 +#else /* when included by kallsyms.c, vsnprintf.c, or
60947 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
60948 +extern void __print_symbol(const char *fmt, unsigned long address);
60949 +extern int sprint_backtrace(char *buffer, unsigned long address);
60950 +extern int sprint_symbol(char *buffer, unsigned long address);
60951 +const char *kallsyms_lookup(unsigned long addr,
60952 + unsigned long *symbolsize,
60953 + unsigned long *offset,
60954 + char **modname, char *namebuf);
60955 +#endif
60956
60957 /* This macro allows us to keep printk typechecking */
60958 static __printf(1, 2)
60959 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
60960 index fa39183..40160be 100644
60961 --- a/include/linux/kgdb.h
60962 +++ b/include/linux/kgdb.h
60963 @@ -53,7 +53,7 @@ extern int kgdb_connected;
60964 extern int kgdb_io_module_registered;
60965
60966 extern atomic_t kgdb_setting_breakpoint;
60967 -extern atomic_t kgdb_cpu_doing_single_step;
60968 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
60969
60970 extern struct task_struct *kgdb_usethread;
60971 extern struct task_struct *kgdb_contthread;
60972 @@ -251,7 +251,7 @@ struct kgdb_arch {
60973 void (*disable_hw_break)(struct pt_regs *regs);
60974 void (*remove_all_hw_break)(void);
60975 void (*correct_hw_break)(void);
60976 -};
60977 +} __do_const;
60978
60979 /**
60980 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
60981 @@ -276,7 +276,7 @@ struct kgdb_io {
60982 void (*pre_exception) (void);
60983 void (*post_exception) (void);
60984 int is_console;
60985 -};
60986 +} __do_const;
60987
60988 extern struct kgdb_arch arch_kgdb_ops;
60989
60990 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
60991 index b16f653..eb908f4 100644
60992 --- a/include/linux/kmod.h
60993 +++ b/include/linux/kmod.h
60994 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
60995 * usually useless though. */
60996 extern __printf(2, 3)
60997 int __request_module(bool wait, const char *name, ...);
60998 +extern __printf(3, 4)
60999 +int ___request_module(bool wait, char *param_name, const char *name, ...);
61000 #define request_module(mod...) __request_module(true, mod)
61001 #define request_module_nowait(mod...) __request_module(false, mod)
61002 #define try_then_request_module(x, mod...) \
61003 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
61004 index d526231..086e89b 100644
61005 --- a/include/linux/kvm_host.h
61006 +++ b/include/linux/kvm_host.h
61007 @@ -308,7 +308,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
61008 void vcpu_load(struct kvm_vcpu *vcpu);
61009 void vcpu_put(struct kvm_vcpu *vcpu);
61010
61011 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
61012 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
61013 struct module *module);
61014 void kvm_exit(void);
61015
61016 @@ -454,7 +454,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
61017 struct kvm_guest_debug *dbg);
61018 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
61019
61020 -int kvm_arch_init(void *opaque);
61021 +int kvm_arch_init(const void *opaque);
61022 void kvm_arch_exit(void);
61023
61024 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
61025 diff --git a/include/linux/libata.h b/include/linux/libata.h
61026 index cafc09a..d7e7829 100644
61027 --- a/include/linux/libata.h
61028 +++ b/include/linux/libata.h
61029 @@ -909,7 +909,7 @@ struct ata_port_operations {
61030 * fields must be pointers.
61031 */
61032 const struct ata_port_operations *inherits;
61033 -};
61034 +} __do_const;
61035
61036 struct ata_port_info {
61037 unsigned long flags;
61038 diff --git a/include/linux/mca.h b/include/linux/mca.h
61039 index 3797270..7765ede 100644
61040 --- a/include/linux/mca.h
61041 +++ b/include/linux/mca.h
61042 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
61043 int region);
61044 void * (*mca_transform_memory)(struct mca_device *,
61045 void *memory);
61046 -};
61047 +} __no_const;
61048
61049 struct mca_bus {
61050 u64 default_dma_mask;
61051 diff --git a/include/linux/memory.h b/include/linux/memory.h
61052 index 935699b..11042cc 100644
61053 --- a/include/linux/memory.h
61054 +++ b/include/linux/memory.h
61055 @@ -144,7 +144,7 @@ struct memory_accessor {
61056 size_t count);
61057 ssize_t (*write)(struct memory_accessor *, const char *buf,
61058 off_t offset, size_t count);
61059 -};
61060 +} __no_const;
61061
61062 /*
61063 * Kernel text modification mutex, used for code patching. Users of this lock
61064 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
61065 index 9970337..9444122 100644
61066 --- a/include/linux/mfd/abx500.h
61067 +++ b/include/linux/mfd/abx500.h
61068 @@ -188,6 +188,7 @@ struct abx500_ops {
61069 int (*event_registers_startup_state_get) (struct device *, u8 *);
61070 int (*startup_irq_enabled) (struct device *, unsigned int);
61071 };
61072 +typedef struct abx500_ops __no_const abx500_ops_no_const;
61073
61074 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
61075 void abx500_remove_ops(struct device *dev);
61076 diff --git a/include/linux/mm.h b/include/linux/mm.h
61077 index 4baadd1..2e0b45e 100644
61078 --- a/include/linux/mm.h
61079 +++ b/include/linux/mm.h
61080 @@ -115,7 +115,14 @@ extern unsigned int kobjsize(const void *objp);
61081
61082 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
61083 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
61084 +
61085 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
61086 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
61087 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
61088 +#else
61089 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
61090 +#endif
61091 +
61092 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
61093 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
61094
61095 @@ -1012,34 +1019,6 @@ int set_page_dirty(struct page *page);
61096 int set_page_dirty_lock(struct page *page);
61097 int clear_page_dirty_for_io(struct page *page);
61098
61099 -/* Is the vma a continuation of the stack vma above it? */
61100 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
61101 -{
61102 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
61103 -}
61104 -
61105 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
61106 - unsigned long addr)
61107 -{
61108 - return (vma->vm_flags & VM_GROWSDOWN) &&
61109 - (vma->vm_start == addr) &&
61110 - !vma_growsdown(vma->vm_prev, addr);
61111 -}
61112 -
61113 -/* Is the vma a continuation of the stack vma below it? */
61114 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
61115 -{
61116 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
61117 -}
61118 -
61119 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
61120 - unsigned long addr)
61121 -{
61122 - return (vma->vm_flags & VM_GROWSUP) &&
61123 - (vma->vm_end == addr) &&
61124 - !vma_growsup(vma->vm_next, addr);
61125 -}
61126 -
61127 extern unsigned long move_page_tables(struct vm_area_struct *vma,
61128 unsigned long old_addr, struct vm_area_struct *new_vma,
61129 unsigned long new_addr, unsigned long len);
61130 @@ -1134,6 +1113,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
61131 }
61132 #endif
61133
61134 +#ifdef CONFIG_MMU
61135 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
61136 +#else
61137 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
61138 +{
61139 + return __pgprot(0);
61140 +}
61141 +#endif
61142 +
61143 int vma_wants_writenotify(struct vm_area_struct *vma);
61144
61145 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
61146 @@ -1419,6 +1407,7 @@ out:
61147 }
61148
61149 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
61150 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
61151
61152 extern unsigned long do_brk(unsigned long, unsigned long);
61153
61154 @@ -1476,6 +1465,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
61155 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
61156 struct vm_area_struct **pprev);
61157
61158 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
61159 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
61160 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
61161 +
61162 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
61163 NULL if none. Assume start_addr < end_addr. */
61164 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
61165 @@ -1492,15 +1485,6 @@ static inline unsigned long vma_pages(struct vm_area_struct *vma)
61166 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
61167 }
61168
61169 -#ifdef CONFIG_MMU
61170 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
61171 -#else
61172 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
61173 -{
61174 - return __pgprot(0);
61175 -}
61176 -#endif
61177 -
61178 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
61179 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
61180 unsigned long pfn, unsigned long size, pgprot_t);
61181 @@ -1614,7 +1598,7 @@ extern int unpoison_memory(unsigned long pfn);
61182 extern int sysctl_memory_failure_early_kill;
61183 extern int sysctl_memory_failure_recovery;
61184 extern void shake_page(struct page *p, int access);
61185 -extern atomic_long_t mce_bad_pages;
61186 +extern atomic_long_unchecked_t mce_bad_pages;
61187 extern int soft_offline_page(struct page *page, int flags);
61188
61189 extern void dump_page(struct page *page);
61190 @@ -1628,5 +1612,11 @@ extern void copy_user_huge_page(struct page *dst, struct page *src,
61191 unsigned int pages_per_huge_page);
61192 #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
61193
61194 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
61195 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
61196 +#else
61197 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
61198 +#endif
61199 +
61200 #endif /* __KERNEL__ */
61201 #endif /* _LINUX_MM_H */
61202 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
61203 index 5b42f1b..759e4b4 100644
61204 --- a/include/linux/mm_types.h
61205 +++ b/include/linux/mm_types.h
61206 @@ -253,6 +253,8 @@ struct vm_area_struct {
61207 #ifdef CONFIG_NUMA
61208 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
61209 #endif
61210 +
61211 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
61212 };
61213
61214 struct core_thread {
61215 @@ -389,6 +391,24 @@ struct mm_struct {
61216 #ifdef CONFIG_CPUMASK_OFFSTACK
61217 struct cpumask cpumask_allocation;
61218 #endif
61219 +
61220 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
61221 + unsigned long pax_flags;
61222 +#endif
61223 +
61224 +#ifdef CONFIG_PAX_DLRESOLVE
61225 + unsigned long call_dl_resolve;
61226 +#endif
61227 +
61228 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
61229 + unsigned long call_syscall;
61230 +#endif
61231 +
61232 +#ifdef CONFIG_PAX_ASLR
61233 + unsigned long delta_mmap; /* randomized offset */
61234 + unsigned long delta_stack; /* randomized offset */
61235 +#endif
61236 +
61237 };
61238
61239 static inline void mm_init_cpumask(struct mm_struct *mm)
61240 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
61241 index 1d1b1e1..2a13c78 100644
61242 --- a/include/linux/mmu_notifier.h
61243 +++ b/include/linux/mmu_notifier.h
61244 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
61245 */
61246 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
61247 ({ \
61248 - pte_t __pte; \
61249 + pte_t ___pte; \
61250 struct vm_area_struct *___vma = __vma; \
61251 unsigned long ___address = __address; \
61252 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
61253 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
61254 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
61255 - __pte; \
61256 + ___pte; \
61257 })
61258
61259 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
61260 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
61261 index 188cb2f..d78409b 100644
61262 --- a/include/linux/mmzone.h
61263 +++ b/include/linux/mmzone.h
61264 @@ -369,7 +369,7 @@ struct zone {
61265 unsigned long flags; /* zone flags, see below */
61266
61267 /* Zone statistics */
61268 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61269 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61270
61271 /*
61272 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
61273 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
61274 index 468819c..17b9db3 100644
61275 --- a/include/linux/mod_devicetable.h
61276 +++ b/include/linux/mod_devicetable.h
61277 @@ -12,7 +12,7 @@
61278 typedef unsigned long kernel_ulong_t;
61279 #endif
61280
61281 -#define PCI_ANY_ID (~0)
61282 +#define PCI_ANY_ID ((__u16)~0)
61283
61284 struct pci_device_id {
61285 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
61286 @@ -131,7 +131,7 @@ struct usb_device_id {
61287 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
61288 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
61289
61290 -#define HID_ANY_ID (~0)
61291 +#define HID_ANY_ID (~0U)
61292
61293 struct hid_device_id {
61294 __u16 bus;
61295 diff --git a/include/linux/module.h b/include/linux/module.h
61296 index 3cb7839..511cb87 100644
61297 --- a/include/linux/module.h
61298 +++ b/include/linux/module.h
61299 @@ -17,6 +17,7 @@
61300 #include <linux/moduleparam.h>
61301 #include <linux/tracepoint.h>
61302 #include <linux/export.h>
61303 +#include <linux/fs.h>
61304
61305 #include <linux/percpu.h>
61306 #include <asm/module.h>
61307 @@ -261,19 +262,16 @@ struct module
61308 int (*init)(void);
61309
61310 /* If this is non-NULL, vfree after init() returns */
61311 - void *module_init;
61312 + void *module_init_rx, *module_init_rw;
61313
61314 /* Here is the actual code + data, vfree'd on unload. */
61315 - void *module_core;
61316 + void *module_core_rx, *module_core_rw;
61317
61318 /* Here are the sizes of the init and core sections */
61319 - unsigned int init_size, core_size;
61320 + unsigned int init_size_rw, core_size_rw;
61321
61322 /* The size of the executable code in each section. */
61323 - unsigned int init_text_size, core_text_size;
61324 -
61325 - /* Size of RO sections of the module (text+rodata) */
61326 - unsigned int init_ro_size, core_ro_size;
61327 + unsigned int init_size_rx, core_size_rx;
61328
61329 /* Arch-specific module values */
61330 struct mod_arch_specific arch;
61331 @@ -329,6 +327,10 @@ struct module
61332 #ifdef CONFIG_EVENT_TRACING
61333 struct ftrace_event_call **trace_events;
61334 unsigned int num_trace_events;
61335 + struct file_operations trace_id;
61336 + struct file_operations trace_enable;
61337 + struct file_operations trace_format;
61338 + struct file_operations trace_filter;
61339 #endif
61340 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
61341 unsigned int num_ftrace_callsites;
61342 @@ -379,16 +381,46 @@ bool is_module_address(unsigned long addr);
61343 bool is_module_percpu_address(unsigned long addr);
61344 bool is_module_text_address(unsigned long addr);
61345
61346 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
61347 +{
61348 +
61349 +#ifdef CONFIG_PAX_KERNEXEC
61350 + if (ktla_ktva(addr) >= (unsigned long)start &&
61351 + ktla_ktva(addr) < (unsigned long)start + size)
61352 + return 1;
61353 +#endif
61354 +
61355 + return ((void *)addr >= start && (void *)addr < start + size);
61356 +}
61357 +
61358 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
61359 +{
61360 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
61361 +}
61362 +
61363 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
61364 +{
61365 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
61366 +}
61367 +
61368 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
61369 +{
61370 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
61371 +}
61372 +
61373 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
61374 +{
61375 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
61376 +}
61377 +
61378 static inline int within_module_core(unsigned long addr, struct module *mod)
61379 {
61380 - return (unsigned long)mod->module_core <= addr &&
61381 - addr < (unsigned long)mod->module_core + mod->core_size;
61382 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
61383 }
61384
61385 static inline int within_module_init(unsigned long addr, struct module *mod)
61386 {
61387 - return (unsigned long)mod->module_init <= addr &&
61388 - addr < (unsigned long)mod->module_init + mod->init_size;
61389 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
61390 }
61391
61392 /* Search for module by name: must hold module_mutex. */
61393 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
61394 index b2be02e..6a9fdb1 100644
61395 --- a/include/linux/moduleloader.h
61396 +++ b/include/linux/moduleloader.h
61397 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
61398 sections. Returns NULL on failure. */
61399 void *module_alloc(unsigned long size);
61400
61401 +#ifdef CONFIG_PAX_KERNEXEC
61402 +void *module_alloc_exec(unsigned long size);
61403 +#else
61404 +#define module_alloc_exec(x) module_alloc(x)
61405 +#endif
61406 +
61407 /* Free memory returned from module_alloc. */
61408 void module_free(struct module *mod, void *module_region);
61409
61410 +#ifdef CONFIG_PAX_KERNEXEC
61411 +void module_free_exec(struct module *mod, void *module_region);
61412 +#else
61413 +#define module_free_exec(x, y) module_free((x), (y))
61414 +#endif
61415 +
61416 /* Apply the given relocation to the (simplified) ELF. Return -error
61417 or 0. */
61418 int apply_relocate(Elf_Shdr *sechdrs,
61419 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
61420 index 7939f63..ec6df57 100644
61421 --- a/include/linux/moduleparam.h
61422 +++ b/include/linux/moduleparam.h
61423 @@ -260,7 +260,7 @@ static inline void __kernel_param_unlock(void)
61424 * @len is usually just sizeof(string).
61425 */
61426 #define module_param_string(name, string, len, perm) \
61427 - static const struct kparam_string __param_string_##name \
61428 + static const struct kparam_string __param_string_##name __used \
61429 = { len, string }; \
61430 __module_param_call(MODULE_PARAM_PREFIX, name, \
61431 &param_ops_string, \
61432 @@ -395,7 +395,7 @@ extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
61433 * module_param_named() for why this might be necessary.
61434 */
61435 #define module_param_array_named(name, array, type, nump, perm) \
61436 - static const struct kparam_array __param_arr_##name \
61437 + static const struct kparam_array __param_arr_##name __used \
61438 = { .max = ARRAY_SIZE(array), .num = nump, \
61439 .ops = &param_ops_##type, \
61440 .elemsize = sizeof(array[0]), .elem = array }; \
61441 diff --git a/include/linux/namei.h b/include/linux/namei.h
61442 index ffc0213..2c1f2cb 100644
61443 --- a/include/linux/namei.h
61444 +++ b/include/linux/namei.h
61445 @@ -24,7 +24,7 @@ struct nameidata {
61446 unsigned seq;
61447 int last_type;
61448 unsigned depth;
61449 - char *saved_names[MAX_NESTED_LINKS + 1];
61450 + const char *saved_names[MAX_NESTED_LINKS + 1];
61451
61452 /* Intent data */
61453 union {
61454 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
61455 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
61456 extern void unlock_rename(struct dentry *, struct dentry *);
61457
61458 -static inline void nd_set_link(struct nameidata *nd, char *path)
61459 +static inline void nd_set_link(struct nameidata *nd, const char *path)
61460 {
61461 nd->saved_names[nd->depth] = path;
61462 }
61463
61464 -static inline char *nd_get_link(struct nameidata *nd)
61465 +static inline const char *nd_get_link(const struct nameidata *nd)
61466 {
61467 return nd->saved_names[nd->depth];
61468 }
61469 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
61470 index a82ad4d..90d15b7 100644
61471 --- a/include/linux/netdevice.h
61472 +++ b/include/linux/netdevice.h
61473 @@ -949,6 +949,7 @@ struct net_device_ops {
61474 int (*ndo_set_features)(struct net_device *dev,
61475 u32 features);
61476 };
61477 +typedef struct net_device_ops __no_const net_device_ops_no_const;
61478
61479 /*
61480 * The DEVICE structure.
61481 @@ -1088,7 +1089,7 @@ struct net_device {
61482 int iflink;
61483
61484 struct net_device_stats stats;
61485 - atomic_long_t rx_dropped; /* dropped packets by core network
61486 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
61487 * Do not use this in drivers.
61488 */
61489
61490 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
61491 new file mode 100644
61492 index 0000000..33f4af8
61493 --- /dev/null
61494 +++ b/include/linux/netfilter/xt_gradm.h
61495 @@ -0,0 +1,9 @@
61496 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
61497 +#define _LINUX_NETFILTER_XT_GRADM_H 1
61498 +
61499 +struct xt_gradm_mtinfo {
61500 + __u16 flags;
61501 + __u16 invflags;
61502 +};
61503 +
61504 +#endif
61505 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
61506 index c65a18a..0c05f3a 100644
61507 --- a/include/linux/of_pdt.h
61508 +++ b/include/linux/of_pdt.h
61509 @@ -32,7 +32,7 @@ struct of_pdt_ops {
61510
61511 /* return 0 on success; fill in 'len' with number of bytes in path */
61512 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
61513 -};
61514 +} __no_const;
61515
61516 extern void *prom_early_alloc(unsigned long size);
61517
61518 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
61519 index a4c5624..79d6d88 100644
61520 --- a/include/linux/oprofile.h
61521 +++ b/include/linux/oprofile.h
61522 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
61523 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
61524 char const * name, ulong * val);
61525
61526 -/** Create a file for read-only access to an atomic_t. */
61527 +/** Create a file for read-only access to an atomic_unchecked_t. */
61528 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
61529 - char const * name, atomic_t * val);
61530 + char const * name, atomic_unchecked_t * val);
61531
61532 /** create a directory */
61533 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
61534 diff --git a/include/linux/padata.h b/include/linux/padata.h
61535 index 4633b2f..988bc08 100644
61536 --- a/include/linux/padata.h
61537 +++ b/include/linux/padata.h
61538 @@ -129,7 +129,7 @@ struct parallel_data {
61539 struct padata_instance *pinst;
61540 struct padata_parallel_queue __percpu *pqueue;
61541 struct padata_serial_queue __percpu *squeue;
61542 - atomic_t seq_nr;
61543 + atomic_unchecked_t seq_nr;
61544 atomic_t reorder_objects;
61545 atomic_t refcnt;
61546 unsigned int max_seq_nr;
61547 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
61548 index b1f8912..c955bff 100644
61549 --- a/include/linux/perf_event.h
61550 +++ b/include/linux/perf_event.h
61551 @@ -748,8 +748,8 @@ struct perf_event {
61552
61553 enum perf_event_active_state state;
61554 unsigned int attach_state;
61555 - local64_t count;
61556 - atomic64_t child_count;
61557 + local64_t count; /* PaX: fix it one day */
61558 + atomic64_unchecked_t child_count;
61559
61560 /*
61561 * These are the total time in nanoseconds that the event
61562 @@ -800,8 +800,8 @@ struct perf_event {
61563 * These accumulate total time (in nanoseconds) that children
61564 * events have been enabled and running, respectively.
61565 */
61566 - atomic64_t child_total_time_enabled;
61567 - atomic64_t child_total_time_running;
61568 + atomic64_unchecked_t child_total_time_enabled;
61569 + atomic64_unchecked_t child_total_time_running;
61570
61571 /*
61572 * Protect attach/detach and child_list:
61573 diff --git a/include/linux/personality.h b/include/linux/personality.h
61574 index 8fc7dd1a..c19d89e 100644
61575 --- a/include/linux/personality.h
61576 +++ b/include/linux/personality.h
61577 @@ -44,6 +44,7 @@ enum {
61578 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
61579 ADDR_NO_RANDOMIZE | \
61580 ADDR_COMPAT_LAYOUT | \
61581 + ADDR_LIMIT_3GB | \
61582 MMAP_PAGE_ZERO)
61583
61584 /*
61585 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
61586 index 77257c9..51d473a 100644
61587 --- a/include/linux/pipe_fs_i.h
61588 +++ b/include/linux/pipe_fs_i.h
61589 @@ -46,9 +46,9 @@ struct pipe_buffer {
61590 struct pipe_inode_info {
61591 wait_queue_head_t wait;
61592 unsigned int nrbufs, curbuf, buffers;
61593 - unsigned int readers;
61594 - unsigned int writers;
61595 - unsigned int waiting_writers;
61596 + atomic_t readers;
61597 + atomic_t writers;
61598 + atomic_t waiting_writers;
61599 unsigned int r_counter;
61600 unsigned int w_counter;
61601 struct page *tmp_page;
61602 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
61603 index d3085e7..fd01052 100644
61604 --- a/include/linux/pm_runtime.h
61605 +++ b/include/linux/pm_runtime.h
61606 @@ -95,7 +95,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
61607
61608 static inline void pm_runtime_mark_last_busy(struct device *dev)
61609 {
61610 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
61611 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
61612 }
61613
61614 #else /* !CONFIG_PM_RUNTIME */
61615 diff --git a/include/linux/poison.h b/include/linux/poison.h
61616 index 79159de..f1233a9 100644
61617 --- a/include/linux/poison.h
61618 +++ b/include/linux/poison.h
61619 @@ -19,8 +19,8 @@
61620 * under normal circumstances, used to verify that nobody uses
61621 * non-initialized list entries.
61622 */
61623 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
61624 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
61625 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
61626 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
61627
61628 /********** include/linux/timer.h **********/
61629 /*
61630 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
61631 index 58969b2..ead129b 100644
61632 --- a/include/linux/preempt.h
61633 +++ b/include/linux/preempt.h
61634 @@ -123,7 +123,7 @@ struct preempt_ops {
61635 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
61636 void (*sched_out)(struct preempt_notifier *notifier,
61637 struct task_struct *next);
61638 -};
61639 +} __no_const;
61640
61641 /**
61642 * preempt_notifier - key for installing preemption notifiers
61643 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
61644 index 643b96c..ef55a9c 100644
61645 --- a/include/linux/proc_fs.h
61646 +++ b/include/linux/proc_fs.h
61647 @@ -155,6 +155,19 @@ static inline struct proc_dir_entry *proc_create(const char *name, mode_t mode,
61648 return proc_create_data(name, mode, parent, proc_fops, NULL);
61649 }
61650
61651 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
61652 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
61653 +{
61654 +#ifdef CONFIG_GRKERNSEC_PROC_USER
61655 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
61656 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61657 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
61658 +#else
61659 + return proc_create_data(name, mode, parent, proc_fops, NULL);
61660 +#endif
61661 +}
61662 +
61663 +
61664 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
61665 mode_t mode, struct proc_dir_entry *base,
61666 read_proc_t *read_proc, void * data)
61667 @@ -258,7 +271,7 @@ union proc_op {
61668 int (*proc_show)(struct seq_file *m,
61669 struct pid_namespace *ns, struct pid *pid,
61670 struct task_struct *task);
61671 -};
61672 +} __no_const;
61673
61674 struct ctl_table_header;
61675 struct ctl_table;
61676 diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
61677 index 800f113..e9ee2e3 100644
61678 --- a/include/linux/ptrace.h
61679 +++ b/include/linux/ptrace.h
61680 @@ -129,10 +129,12 @@ extern void __ptrace_unlink(struct task_struct *child);
61681 extern void exit_ptrace(struct task_struct *tracer);
61682 #define PTRACE_MODE_READ 1
61683 #define PTRACE_MODE_ATTACH 2
61684 -/* Returns 0 on success, -errno on denial. */
61685 -extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
61686 /* Returns true on success, false on denial. */
61687 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
61688 +/* Returns true on success, false on denial. */
61689 +extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
61690 +/* Returns true on success, false on denial. */
61691 +extern bool ptrace_may_access_nolock(struct task_struct *task, unsigned int mode);
61692
61693 static inline int ptrace_reparented(struct task_struct *child)
61694 {
61695 diff --git a/include/linux/random.h b/include/linux/random.h
61696 index 8f74538..02a1012 100644
61697 --- a/include/linux/random.h
61698 +++ b/include/linux/random.h
61699 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
61700
61701 u32 prandom32(struct rnd_state *);
61702
61703 +static inline unsigned long pax_get_random_long(void)
61704 +{
61705 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
61706 +}
61707 +
61708 /*
61709 * Handle minimum values for seeds
61710 */
61711 static inline u32 __seed(u32 x, u32 m)
61712 {
61713 - return (x < m) ? x + m : x;
61714 + return (x <= m) ? x + m + 1 : x;
61715 }
61716
61717 /**
61718 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
61719 index e0879a7..a12f962 100644
61720 --- a/include/linux/reboot.h
61721 +++ b/include/linux/reboot.h
61722 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
61723 * Architecture-specific implementations of sys_reboot commands.
61724 */
61725
61726 -extern void machine_restart(char *cmd);
61727 -extern void machine_halt(void);
61728 -extern void machine_power_off(void);
61729 +extern void machine_restart(char *cmd) __noreturn;
61730 +extern void machine_halt(void) __noreturn;
61731 +extern void machine_power_off(void) __noreturn;
61732
61733 extern void machine_shutdown(void);
61734 struct pt_regs;
61735 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
61736 */
61737
61738 extern void kernel_restart_prepare(char *cmd);
61739 -extern void kernel_restart(char *cmd);
61740 -extern void kernel_halt(void);
61741 -extern void kernel_power_off(void);
61742 +extern void kernel_restart(char *cmd) __noreturn;
61743 +extern void kernel_halt(void) __noreturn;
61744 +extern void kernel_power_off(void) __noreturn;
61745
61746 extern int C_A_D; /* for sysctl */
61747 void ctrl_alt_del(void);
61748 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
61749 * Emergency restart, callable from an interrupt handler.
61750 */
61751
61752 -extern void emergency_restart(void);
61753 +extern void emergency_restart(void) __noreturn;
61754 #include <asm/emergency-restart.h>
61755
61756 #endif
61757 diff --git a/include/linux/regset.h b/include/linux/regset.h
61758 index 8abee65..5150fd1 100644
61759 --- a/include/linux/regset.h
61760 +++ b/include/linux/regset.h
61761 @@ -335,6 +335,9 @@ static inline int copy_regset_to_user(struct task_struct *target,
61762 {
61763 const struct user_regset *regset = &view->regsets[setno];
61764
61765 + if (!regset->get)
61766 + return -EOPNOTSUPP;
61767 +
61768 if (!access_ok(VERIFY_WRITE, data, size))
61769 return -EIO;
61770
61771 @@ -358,6 +361,9 @@ static inline int copy_regset_from_user(struct task_struct *target,
61772 {
61773 const struct user_regset *regset = &view->regsets[setno];
61774
61775 + if (!regset->set)
61776 + return -EOPNOTSUPP;
61777 +
61778 if (!access_ok(VERIFY_READ, data, size))
61779 return -EIO;
61780
61781 diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
61782 index 96d465f..b084e05 100644
61783 --- a/include/linux/reiserfs_fs.h
61784 +++ b/include/linux/reiserfs_fs.h
61785 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
61786 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
61787
61788 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
61789 -#define get_generation(s) atomic_read (&fs_generation(s))
61790 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
61791 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
61792 #define __fs_changed(gen,s) (gen != get_generation (s))
61793 #define fs_changed(gen,s) \
61794 diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
61795 index 52c83b6..18ed7eb 100644
61796 --- a/include/linux/reiserfs_fs_sb.h
61797 +++ b/include/linux/reiserfs_fs_sb.h
61798 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
61799 /* Comment? -Hans */
61800 wait_queue_head_t s_wait;
61801 /* To be obsoleted soon by per buffer seals.. -Hans */
61802 - atomic_t s_generation_counter; // increased by one every time the
61803 + atomic_unchecked_t s_generation_counter; // increased by one every time the
61804 // tree gets re-balanced
61805 unsigned long s_properties; /* File system properties. Currently holds
61806 on-disk FS format */
61807 diff --git a/include/linux/relay.h b/include/linux/relay.h
61808 index 14a86bc..17d0700 100644
61809 --- a/include/linux/relay.h
61810 +++ b/include/linux/relay.h
61811 @@ -159,7 +159,7 @@ struct rchan_callbacks
61812 * The callback should return 0 if successful, negative if not.
61813 */
61814 int (*remove_buf_file)(struct dentry *dentry);
61815 -};
61816 +} __no_const;
61817
61818 /*
61819 * CONFIG_RELAY kernel API, kernel/relay.c
61820 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
61821 index c6c6084..5bf1212 100644
61822 --- a/include/linux/rfkill.h
61823 +++ b/include/linux/rfkill.h
61824 @@ -147,6 +147,7 @@ struct rfkill_ops {
61825 void (*query)(struct rfkill *rfkill, void *data);
61826 int (*set_block)(void *data, bool blocked);
61827 };
61828 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
61829
61830 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
61831 /**
61832 diff --git a/include/linux/rio.h b/include/linux/rio.h
61833 index 4d50611..c6858a2 100644
61834 --- a/include/linux/rio.h
61835 +++ b/include/linux/rio.h
61836 @@ -315,7 +315,7 @@ struct rio_ops {
61837 int mbox, void *buffer, size_t len);
61838 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
61839 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
61840 -};
61841 +} __no_const;
61842
61843 #define RIO_RESOURCE_MEM 0x00000100
61844 #define RIO_RESOURCE_DOORBELL 0x00000200
61845 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
61846 index 2148b12..519b820 100644
61847 --- a/include/linux/rmap.h
61848 +++ b/include/linux/rmap.h
61849 @@ -119,8 +119,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
61850 void anon_vma_init(void); /* create anon_vma_cachep */
61851 int anon_vma_prepare(struct vm_area_struct *);
61852 void unlink_anon_vmas(struct vm_area_struct *);
61853 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
61854 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
61855 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
61856 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
61857 void __anon_vma_link(struct vm_area_struct *);
61858
61859 static inline void anon_vma_merge(struct vm_area_struct *vma,
61860 diff --git a/include/linux/sched.h b/include/linux/sched.h
61861 index 1c4f3e9..342eb1f 100644
61862 --- a/include/linux/sched.h
61863 +++ b/include/linux/sched.h
61864 @@ -101,6 +101,7 @@ struct bio_list;
61865 struct fs_struct;
61866 struct perf_event_context;
61867 struct blk_plug;
61868 +struct linux_binprm;
61869
61870 /*
61871 * List of flags we want to share for kernel threads,
61872 @@ -380,10 +381,13 @@ struct user_namespace;
61873 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
61874
61875 extern int sysctl_max_map_count;
61876 +extern unsigned long sysctl_heap_stack_gap;
61877
61878 #include <linux/aio.h>
61879
61880 #ifdef CONFIG_MMU
61881 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
61882 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
61883 extern void arch_pick_mmap_layout(struct mm_struct *mm);
61884 extern unsigned long
61885 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
61886 @@ -629,6 +633,17 @@ struct signal_struct {
61887 #ifdef CONFIG_TASKSTATS
61888 struct taskstats *stats;
61889 #endif
61890 +
61891 +#ifdef CONFIG_GRKERNSEC
61892 + u32 curr_ip;
61893 + u32 saved_ip;
61894 + u32 gr_saddr;
61895 + u32 gr_daddr;
61896 + u16 gr_sport;
61897 + u16 gr_dport;
61898 + u8 used_accept:1;
61899 +#endif
61900 +
61901 #ifdef CONFIG_AUDIT
61902 unsigned audit_tty;
61903 struct tty_audit_buf *tty_audit_buf;
61904 @@ -710,6 +725,11 @@ struct user_struct {
61905 struct key *session_keyring; /* UID's default session keyring */
61906 #endif
61907
61908 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61909 + unsigned int banned;
61910 + unsigned long ban_expires;
61911 +#endif
61912 +
61913 /* Hash table maintenance information */
61914 struct hlist_node uidhash_node;
61915 uid_t uid;
61916 @@ -1337,8 +1357,8 @@ struct task_struct {
61917 struct list_head thread_group;
61918
61919 struct completion *vfork_done; /* for vfork() */
61920 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
61921 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
61922 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
61923 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
61924
61925 cputime_t utime, stime, utimescaled, stimescaled;
61926 cputime_t gtime;
61927 @@ -1354,13 +1374,6 @@ struct task_struct {
61928 struct task_cputime cputime_expires;
61929 struct list_head cpu_timers[3];
61930
61931 -/* process credentials */
61932 - const struct cred __rcu *real_cred; /* objective and real subjective task
61933 - * credentials (COW) */
61934 - const struct cred __rcu *cred; /* effective (overridable) subjective task
61935 - * credentials (COW) */
61936 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
61937 -
61938 char comm[TASK_COMM_LEN]; /* executable name excluding path
61939 - access with [gs]et_task_comm (which lock
61940 it with task_lock())
61941 @@ -1377,8 +1390,16 @@ struct task_struct {
61942 #endif
61943 /* CPU-specific state of this task */
61944 struct thread_struct thread;
61945 +/* thread_info moved to task_struct */
61946 +#ifdef CONFIG_X86
61947 + struct thread_info tinfo;
61948 +#endif
61949 /* filesystem information */
61950 struct fs_struct *fs;
61951 +
61952 + const struct cred __rcu *cred; /* effective (overridable) subjective task
61953 + * credentials (COW) */
61954 +
61955 /* open file information */
61956 struct files_struct *files;
61957 /* namespaces */
61958 @@ -1425,6 +1446,11 @@ struct task_struct {
61959 struct rt_mutex_waiter *pi_blocked_on;
61960 #endif
61961
61962 +/* process credentials */
61963 + const struct cred __rcu *real_cred; /* objective and real subjective task
61964 + * credentials (COW) */
61965 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
61966 +
61967 #ifdef CONFIG_DEBUG_MUTEXES
61968 /* mutex deadlock detection */
61969 struct mutex_waiter *blocked_on;
61970 @@ -1540,6 +1566,27 @@ struct task_struct {
61971 unsigned long default_timer_slack_ns;
61972
61973 struct list_head *scm_work_list;
61974 +
61975 +#ifdef CONFIG_GRKERNSEC
61976 + /* grsecurity */
61977 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61978 + u64 exec_id;
61979 +#endif
61980 +#ifdef CONFIG_GRKERNSEC_SETXID
61981 + const struct cred *delayed_cred;
61982 +#endif
61983 + struct dentry *gr_chroot_dentry;
61984 + struct acl_subject_label *acl;
61985 + struct acl_role_label *role;
61986 + struct file *exec_file;
61987 + u16 acl_role_id;
61988 + /* is this the task that authenticated to the special role */
61989 + u8 acl_sp_role;
61990 + u8 is_writable;
61991 + u8 brute;
61992 + u8 gr_is_chrooted;
61993 +#endif
61994 +
61995 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
61996 /* Index of current stored address in ret_stack */
61997 int curr_ret_stack;
61998 @@ -1574,6 +1621,51 @@ struct task_struct {
61999 #endif
62000 };
62001
62002 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
62003 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
62004 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
62005 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
62006 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
62007 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
62008 +
62009 +#ifdef CONFIG_PAX_SOFTMODE
62010 +extern int pax_softmode;
62011 +#endif
62012 +
62013 +extern int pax_check_flags(unsigned long *);
62014 +
62015 +/* if tsk != current then task_lock must be held on it */
62016 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62017 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
62018 +{
62019 + if (likely(tsk->mm))
62020 + return tsk->mm->pax_flags;
62021 + else
62022 + return 0UL;
62023 +}
62024 +
62025 +/* if tsk != current then task_lock must be held on it */
62026 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
62027 +{
62028 + if (likely(tsk->mm)) {
62029 + tsk->mm->pax_flags = flags;
62030 + return 0;
62031 + }
62032 + return -EINVAL;
62033 +}
62034 +#endif
62035 +
62036 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
62037 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
62038 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
62039 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
62040 +#endif
62041 +
62042 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
62043 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
62044 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
62045 +extern __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
62046 +
62047 /* Future-safe accessor for struct task_struct's cpus_allowed. */
62048 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
62049
62050 @@ -2081,7 +2173,9 @@ void yield(void);
62051 extern struct exec_domain default_exec_domain;
62052
62053 union thread_union {
62054 +#ifndef CONFIG_X86
62055 struct thread_info thread_info;
62056 +#endif
62057 unsigned long stack[THREAD_SIZE/sizeof(long)];
62058 };
62059
62060 @@ -2114,6 +2208,7 @@ extern struct pid_namespace init_pid_ns;
62061 */
62062
62063 extern struct task_struct *find_task_by_vpid(pid_t nr);
62064 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
62065 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
62066 struct pid_namespace *ns);
62067
62068 @@ -2235,6 +2330,12 @@ static inline void mmdrop(struct mm_struct * mm)
62069 extern void mmput(struct mm_struct *);
62070 /* Grab a reference to a task's mm, if it is not already going away */
62071 extern struct mm_struct *get_task_mm(struct task_struct *task);
62072 +/*
62073 + * Grab a reference to a task's mm, if it is not already going away
62074 + * and ptrace_may_access with the mode parameter passed to it
62075 + * succeeds.
62076 + */
62077 +extern struct mm_struct *mm_access(struct task_struct *task, unsigned int mode);
62078 /* Remove the current tasks stale references to the old mm_struct */
62079 extern void mm_release(struct task_struct *, struct mm_struct *);
62080 /* Allocate a new mm structure and copy contents from tsk->mm */
62081 @@ -2251,7 +2352,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
62082 extern void exit_itimers(struct signal_struct *);
62083 extern void flush_itimer_signals(void);
62084
62085 -extern NORET_TYPE void do_group_exit(int);
62086 +extern __noreturn void do_group_exit(int);
62087
62088 extern void daemonize(const char *, ...);
62089 extern int allow_signal(int);
62090 @@ -2416,13 +2517,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
62091
62092 #endif
62093
62094 -static inline int object_is_on_stack(void *obj)
62095 +static inline int object_starts_on_stack(void *obj)
62096 {
62097 - void *stack = task_stack_page(current);
62098 + const void *stack = task_stack_page(current);
62099
62100 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
62101 }
62102
62103 +#ifdef CONFIG_PAX_USERCOPY
62104 +extern int object_is_on_stack(const void *obj, unsigned long len);
62105 +#endif
62106 +
62107 extern void thread_info_cache_init(void);
62108
62109 #ifdef CONFIG_DEBUG_STACK_USAGE
62110 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
62111 index 899fbb4..1cb4138 100644
62112 --- a/include/linux/screen_info.h
62113 +++ b/include/linux/screen_info.h
62114 @@ -43,7 +43,8 @@ struct screen_info {
62115 __u16 pages; /* 0x32 */
62116 __u16 vesa_attributes; /* 0x34 */
62117 __u32 capabilities; /* 0x36 */
62118 - __u8 _reserved[6]; /* 0x3a */
62119 + __u16 vesapm_size; /* 0x3a */
62120 + __u8 _reserved[4]; /* 0x3c */
62121 } __attribute__((packed));
62122
62123 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
62124 diff --git a/include/linux/security.h b/include/linux/security.h
62125 index e8c619d..e0cbd1c 100644
62126 --- a/include/linux/security.h
62127 +++ b/include/linux/security.h
62128 @@ -37,6 +37,7 @@
62129 #include <linux/xfrm.h>
62130 #include <linux/slab.h>
62131 #include <linux/xattr.h>
62132 +#include <linux/grsecurity.h>
62133 #include <net/flow.h>
62134
62135 /* Maximum number of letters for an LSM name string */
62136 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
62137 index 0b69a46..b2ffa4c 100644
62138 --- a/include/linux/seq_file.h
62139 +++ b/include/linux/seq_file.h
62140 @@ -24,6 +24,9 @@ struct seq_file {
62141 struct mutex lock;
62142 const struct seq_operations *op;
62143 int poll_event;
62144 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62145 + u64 exec_id;
62146 +#endif
62147 void *private;
62148 };
62149
62150 @@ -33,6 +36,7 @@ struct seq_operations {
62151 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
62152 int (*show) (struct seq_file *m, void *v);
62153 };
62154 +typedef struct seq_operations __no_const seq_operations_no_const;
62155
62156 #define SEQ_SKIP 1
62157
62158 diff --git a/include/linux/shm.h b/include/linux/shm.h
62159 index 92808b8..c28cac4 100644
62160 --- a/include/linux/shm.h
62161 +++ b/include/linux/shm.h
62162 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
62163
62164 /* The task created the shm object. NULL if the task is dead. */
62165 struct task_struct *shm_creator;
62166 +#ifdef CONFIG_GRKERNSEC
62167 + time_t shm_createtime;
62168 + pid_t shm_lapid;
62169 +#endif
62170 };
62171
62172 /* shm_mode upper byte flags */
62173 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
62174 index fe86488..1563c1c 100644
62175 --- a/include/linux/skbuff.h
62176 +++ b/include/linux/skbuff.h
62177 @@ -642,7 +642,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
62178 */
62179 static inline int skb_queue_empty(const struct sk_buff_head *list)
62180 {
62181 - return list->next == (struct sk_buff *)list;
62182 + return list->next == (const struct sk_buff *)list;
62183 }
62184
62185 /**
62186 @@ -655,7 +655,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
62187 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
62188 const struct sk_buff *skb)
62189 {
62190 - return skb->next == (struct sk_buff *)list;
62191 + return skb->next == (const struct sk_buff *)list;
62192 }
62193
62194 /**
62195 @@ -668,7 +668,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
62196 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
62197 const struct sk_buff *skb)
62198 {
62199 - return skb->prev == (struct sk_buff *)list;
62200 + return skb->prev == (const struct sk_buff *)list;
62201 }
62202
62203 /**
62204 @@ -1523,7 +1523,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
62205 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
62206 */
62207 #ifndef NET_SKB_PAD
62208 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
62209 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
62210 #endif
62211
62212 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
62213 diff --git a/include/linux/slab.h b/include/linux/slab.h
62214 index 573c809..e84c132 100644
62215 --- a/include/linux/slab.h
62216 +++ b/include/linux/slab.h
62217 @@ -11,12 +11,20 @@
62218
62219 #include <linux/gfp.h>
62220 #include <linux/types.h>
62221 +#include <linux/err.h>
62222
62223 /*
62224 * Flags to pass to kmem_cache_create().
62225 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
62226 */
62227 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
62228 +
62229 +#ifdef CONFIG_PAX_USERCOPY
62230 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
62231 +#else
62232 +#define SLAB_USERCOPY 0x00000000UL
62233 +#endif
62234 +
62235 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
62236 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
62237 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
62238 @@ -87,10 +95,13 @@
62239 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
62240 * Both make kfree a no-op.
62241 */
62242 -#define ZERO_SIZE_PTR ((void *)16)
62243 +#define ZERO_SIZE_PTR \
62244 +({ \
62245 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
62246 + (void *)(-MAX_ERRNO-1L); \
62247 +})
62248
62249 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
62250 - (unsigned long)ZERO_SIZE_PTR)
62251 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
62252
62253 /*
62254 * struct kmem_cache related prototypes
62255 @@ -161,6 +172,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
62256 void kfree(const void *);
62257 void kzfree(const void *);
62258 size_t ksize(const void *);
62259 +void check_object_size(const void *ptr, unsigned long n, bool to);
62260
62261 /*
62262 * Allocator specific definitions. These are mainly used to establish optimized
62263 @@ -353,4 +365,59 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
62264
62265 void __init kmem_cache_init_late(void);
62266
62267 +#define kmalloc(x, y) \
62268 +({ \
62269 + void *___retval; \
62270 + intoverflow_t ___x = (intoverflow_t)x; \
62271 + if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n")) \
62272 + ___retval = NULL; \
62273 + else \
62274 + ___retval = kmalloc((size_t)___x, (y)); \
62275 + ___retval; \
62276 +})
62277 +
62278 +#define kmalloc_node(x, y, z) \
62279 +({ \
62280 + void *___retval; \
62281 + intoverflow_t ___x = (intoverflow_t)x; \
62282 + if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
62283 + ___retval = NULL; \
62284 + else \
62285 + ___retval = kmalloc_node((size_t)___x, (y), (z));\
62286 + ___retval; \
62287 +})
62288 +
62289 +#define kzalloc(x, y) \
62290 +({ \
62291 + void *___retval; \
62292 + intoverflow_t ___x = (intoverflow_t)x; \
62293 + if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n")) \
62294 + ___retval = NULL; \
62295 + else \
62296 + ___retval = kzalloc((size_t)___x, (y)); \
62297 + ___retval; \
62298 +})
62299 +
62300 +#define __krealloc(x, y, z) \
62301 +({ \
62302 + void *___retval; \
62303 + intoverflow_t ___y = (intoverflow_t)y; \
62304 + if (WARN(___y > ULONG_MAX, "__krealloc size overflow\n"))\
62305 + ___retval = NULL; \
62306 + else \
62307 + ___retval = __krealloc((x), (size_t)___y, (z)); \
62308 + ___retval; \
62309 +})
62310 +
62311 +#define krealloc(x, y, z) \
62312 +({ \
62313 + void *___retval; \
62314 + intoverflow_t ___y = (intoverflow_t)y; \
62315 + if (WARN(___y > ULONG_MAX, "krealloc size overflow\n")) \
62316 + ___retval = NULL; \
62317 + else \
62318 + ___retval = krealloc((x), (size_t)___y, (z)); \
62319 + ___retval; \
62320 +})
62321 +
62322 #endif /* _LINUX_SLAB_H */
62323 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
62324 index d00e0ba..1b3bf7b 100644
62325 --- a/include/linux/slab_def.h
62326 +++ b/include/linux/slab_def.h
62327 @@ -68,10 +68,10 @@ struct kmem_cache {
62328 unsigned long node_allocs;
62329 unsigned long node_frees;
62330 unsigned long node_overflow;
62331 - atomic_t allochit;
62332 - atomic_t allocmiss;
62333 - atomic_t freehit;
62334 - atomic_t freemiss;
62335 + atomic_unchecked_t allochit;
62336 + atomic_unchecked_t allocmiss;
62337 + atomic_unchecked_t freehit;
62338 + atomic_unchecked_t freemiss;
62339
62340 /*
62341 * If debugging is enabled, then the allocator can add additional
62342 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
62343 index a32bcfd..53b71f4 100644
62344 --- a/include/linux/slub_def.h
62345 +++ b/include/linux/slub_def.h
62346 @@ -89,7 +89,7 @@ struct kmem_cache {
62347 struct kmem_cache_order_objects max;
62348 struct kmem_cache_order_objects min;
62349 gfp_t allocflags; /* gfp flags to use on each alloc */
62350 - int refcount; /* Refcount for slab cache destroy */
62351 + atomic_t refcount; /* Refcount for slab cache destroy */
62352 void (*ctor)(void *);
62353 int inuse; /* Offset to metadata */
62354 int align; /* Alignment */
62355 @@ -215,7 +215,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
62356 }
62357
62358 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
62359 -void *__kmalloc(size_t size, gfp_t flags);
62360 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
62361
62362 static __always_inline void *
62363 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
62364 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
62365 index de8832d..0147b46 100644
62366 --- a/include/linux/sonet.h
62367 +++ b/include/linux/sonet.h
62368 @@ -61,7 +61,7 @@ struct sonet_stats {
62369 #include <linux/atomic.h>
62370
62371 struct k_sonet_stats {
62372 -#define __HANDLE_ITEM(i) atomic_t i
62373 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
62374 __SONET_ITEMS
62375 #undef __HANDLE_ITEM
62376 };
62377 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
62378 index 3d8f9c4..69f1c0a 100644
62379 --- a/include/linux/sunrpc/clnt.h
62380 +++ b/include/linux/sunrpc/clnt.h
62381 @@ -172,9 +172,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
62382 {
62383 switch (sap->sa_family) {
62384 case AF_INET:
62385 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
62386 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
62387 case AF_INET6:
62388 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
62389 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
62390 }
62391 return 0;
62392 }
62393 @@ -207,7 +207,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
62394 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
62395 const struct sockaddr *src)
62396 {
62397 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
62398 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
62399 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
62400
62401 dsin->sin_family = ssin->sin_family;
62402 @@ -310,7 +310,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
62403 if (sa->sa_family != AF_INET6)
62404 return 0;
62405
62406 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
62407 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
62408 }
62409
62410 #endif /* __KERNEL__ */
62411 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
62412 index e775689..9e206d9 100644
62413 --- a/include/linux/sunrpc/sched.h
62414 +++ b/include/linux/sunrpc/sched.h
62415 @@ -105,6 +105,7 @@ struct rpc_call_ops {
62416 void (*rpc_call_done)(struct rpc_task *, void *);
62417 void (*rpc_release)(void *);
62418 };
62419 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
62420
62421 struct rpc_task_setup {
62422 struct rpc_task *task;
62423 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
62424 index c14fe86..393245e 100644
62425 --- a/include/linux/sunrpc/svc_rdma.h
62426 +++ b/include/linux/sunrpc/svc_rdma.h
62427 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
62428 extern unsigned int svcrdma_max_requests;
62429 extern unsigned int svcrdma_max_req_size;
62430
62431 -extern atomic_t rdma_stat_recv;
62432 -extern atomic_t rdma_stat_read;
62433 -extern atomic_t rdma_stat_write;
62434 -extern atomic_t rdma_stat_sq_starve;
62435 -extern atomic_t rdma_stat_rq_starve;
62436 -extern atomic_t rdma_stat_rq_poll;
62437 -extern atomic_t rdma_stat_rq_prod;
62438 -extern atomic_t rdma_stat_sq_poll;
62439 -extern atomic_t rdma_stat_sq_prod;
62440 +extern atomic_unchecked_t rdma_stat_recv;
62441 +extern atomic_unchecked_t rdma_stat_read;
62442 +extern atomic_unchecked_t rdma_stat_write;
62443 +extern atomic_unchecked_t rdma_stat_sq_starve;
62444 +extern atomic_unchecked_t rdma_stat_rq_starve;
62445 +extern atomic_unchecked_t rdma_stat_rq_poll;
62446 +extern atomic_unchecked_t rdma_stat_rq_prod;
62447 +extern atomic_unchecked_t rdma_stat_sq_poll;
62448 +extern atomic_unchecked_t rdma_stat_sq_prod;
62449
62450 #define RPCRDMA_VERSION 1
62451
62452 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
62453 index 703cfa33..0b8ca72ac 100644
62454 --- a/include/linux/sysctl.h
62455 +++ b/include/linux/sysctl.h
62456 @@ -155,7 +155,11 @@ enum
62457 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
62458 };
62459
62460 -
62461 +#ifdef CONFIG_PAX_SOFTMODE
62462 +enum {
62463 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
62464 +};
62465 +#endif
62466
62467 /* CTL_VM names: */
62468 enum
62469 @@ -968,6 +972,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
62470
62471 extern int proc_dostring(struct ctl_table *, int,
62472 void __user *, size_t *, loff_t *);
62473 +extern int proc_dostring_modpriv(struct ctl_table *, int,
62474 + void __user *, size_t *, loff_t *);
62475 extern int proc_dointvec(struct ctl_table *, int,
62476 void __user *, size_t *, loff_t *);
62477 extern int proc_dointvec_minmax(struct ctl_table *, int,
62478 diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
62479 index a71a292..51bd91d 100644
62480 --- a/include/linux/tracehook.h
62481 +++ b/include/linux/tracehook.h
62482 @@ -54,12 +54,12 @@ struct linux_binprm;
62483 /*
62484 * ptrace report for syscall entry and exit looks identical.
62485 */
62486 -static inline void ptrace_report_syscall(struct pt_regs *regs)
62487 +static inline int ptrace_report_syscall(struct pt_regs *regs)
62488 {
62489 int ptrace = current->ptrace;
62490
62491 if (!(ptrace & PT_PTRACED))
62492 - return;
62493 + return 0;
62494
62495 ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
62496
62497 @@ -72,6 +72,8 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
62498 send_sig(current->exit_code, current, 1);
62499 current->exit_code = 0;
62500 }
62501 +
62502 + return fatal_signal_pending(current);
62503 }
62504
62505 /**
62506 @@ -96,8 +98,7 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
62507 static inline __must_check int tracehook_report_syscall_entry(
62508 struct pt_regs *regs)
62509 {
62510 - ptrace_report_syscall(regs);
62511 - return 0;
62512 + return ptrace_report_syscall(regs);
62513 }
62514
62515 /**
62516 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
62517 index ff7dc08..893e1bd 100644
62518 --- a/include/linux/tty_ldisc.h
62519 +++ b/include/linux/tty_ldisc.h
62520 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
62521
62522 struct module *owner;
62523
62524 - int refcount;
62525 + atomic_t refcount;
62526 };
62527
62528 struct tty_ldisc {
62529 diff --git a/include/linux/types.h b/include/linux/types.h
62530 index 57a9723..dbe234a 100644
62531 --- a/include/linux/types.h
62532 +++ b/include/linux/types.h
62533 @@ -213,10 +213,26 @@ typedef struct {
62534 int counter;
62535 } atomic_t;
62536
62537 +#ifdef CONFIG_PAX_REFCOUNT
62538 +typedef struct {
62539 + int counter;
62540 +} atomic_unchecked_t;
62541 +#else
62542 +typedef atomic_t atomic_unchecked_t;
62543 +#endif
62544 +
62545 #ifdef CONFIG_64BIT
62546 typedef struct {
62547 long counter;
62548 } atomic64_t;
62549 +
62550 +#ifdef CONFIG_PAX_REFCOUNT
62551 +typedef struct {
62552 + long counter;
62553 +} atomic64_unchecked_t;
62554 +#else
62555 +typedef atomic64_t atomic64_unchecked_t;
62556 +#endif
62557 #endif
62558
62559 struct list_head {
62560 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
62561 index 5ca0951..ab496a5 100644
62562 --- a/include/linux/uaccess.h
62563 +++ b/include/linux/uaccess.h
62564 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
62565 long ret; \
62566 mm_segment_t old_fs = get_fs(); \
62567 \
62568 - set_fs(KERNEL_DS); \
62569 pagefault_disable(); \
62570 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
62571 - pagefault_enable(); \
62572 + set_fs(KERNEL_DS); \
62573 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
62574 set_fs(old_fs); \
62575 + pagefault_enable(); \
62576 ret; \
62577 })
62578
62579 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
62580 index 99c1b4d..bb94261 100644
62581 --- a/include/linux/unaligned/access_ok.h
62582 +++ b/include/linux/unaligned/access_ok.h
62583 @@ -6,32 +6,32 @@
62584
62585 static inline u16 get_unaligned_le16(const void *p)
62586 {
62587 - return le16_to_cpup((__le16 *)p);
62588 + return le16_to_cpup((const __le16 *)p);
62589 }
62590
62591 static inline u32 get_unaligned_le32(const void *p)
62592 {
62593 - return le32_to_cpup((__le32 *)p);
62594 + return le32_to_cpup((const __le32 *)p);
62595 }
62596
62597 static inline u64 get_unaligned_le64(const void *p)
62598 {
62599 - return le64_to_cpup((__le64 *)p);
62600 + return le64_to_cpup((const __le64 *)p);
62601 }
62602
62603 static inline u16 get_unaligned_be16(const void *p)
62604 {
62605 - return be16_to_cpup((__be16 *)p);
62606 + return be16_to_cpup((const __be16 *)p);
62607 }
62608
62609 static inline u32 get_unaligned_be32(const void *p)
62610 {
62611 - return be32_to_cpup((__be32 *)p);
62612 + return be32_to_cpup((const __be32 *)p);
62613 }
62614
62615 static inline u64 get_unaligned_be64(const void *p)
62616 {
62617 - return be64_to_cpup((__be64 *)p);
62618 + return be64_to_cpup((const __be64 *)p);
62619 }
62620
62621 static inline void put_unaligned_le16(u16 val, void *p)
62622 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
62623 index e5a40c3..20ab0f6 100644
62624 --- a/include/linux/usb/renesas_usbhs.h
62625 +++ b/include/linux/usb/renesas_usbhs.h
62626 @@ -39,7 +39,7 @@ enum {
62627 */
62628 struct renesas_usbhs_driver_callback {
62629 int (*notify_hotplug)(struct platform_device *pdev);
62630 -};
62631 +} __no_const;
62632
62633 /*
62634 * callback functions for platform
62635 @@ -89,7 +89,7 @@ struct renesas_usbhs_platform_callback {
62636 * VBUS control is needed for Host
62637 */
62638 int (*set_vbus)(struct platform_device *pdev, int enable);
62639 -};
62640 +} __no_const;
62641
62642 /*
62643 * parameters for renesas usbhs
62644 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
62645 index 6f8fbcf..8259001 100644
62646 --- a/include/linux/vermagic.h
62647 +++ b/include/linux/vermagic.h
62648 @@ -25,9 +25,35 @@
62649 #define MODULE_ARCH_VERMAGIC ""
62650 #endif
62651
62652 +#ifdef CONFIG_PAX_REFCOUNT
62653 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
62654 +#else
62655 +#define MODULE_PAX_REFCOUNT ""
62656 +#endif
62657 +
62658 +#ifdef CONSTIFY_PLUGIN
62659 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
62660 +#else
62661 +#define MODULE_CONSTIFY_PLUGIN ""
62662 +#endif
62663 +
62664 +#ifdef STACKLEAK_PLUGIN
62665 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
62666 +#else
62667 +#define MODULE_STACKLEAK_PLUGIN ""
62668 +#endif
62669 +
62670 +#ifdef CONFIG_GRKERNSEC
62671 +#define MODULE_GRSEC "GRSEC "
62672 +#else
62673 +#define MODULE_GRSEC ""
62674 +#endif
62675 +
62676 #define VERMAGIC_STRING \
62677 UTS_RELEASE " " \
62678 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
62679 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
62680 - MODULE_ARCH_VERMAGIC
62681 + MODULE_ARCH_VERMAGIC \
62682 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
62683 + MODULE_GRSEC
62684
62685 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
62686 index 4bde182..aec92c1 100644
62687 --- a/include/linux/vmalloc.h
62688 +++ b/include/linux/vmalloc.h
62689 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
62690 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
62691 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
62692 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
62693 +
62694 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
62695 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
62696 +#endif
62697 +
62698 /* bits [20..32] reserved for arch specific ioremap internals */
62699
62700 /*
62701 @@ -156,4 +161,103 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
62702 # endif
62703 #endif
62704
62705 +#define vmalloc(x) \
62706 +({ \
62707 + void *___retval; \
62708 + intoverflow_t ___x = (intoverflow_t)x; \
62709 + if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
62710 + ___retval = NULL; \
62711 + else \
62712 + ___retval = vmalloc((unsigned long)___x); \
62713 + ___retval; \
62714 +})
62715 +
62716 +#define vzalloc(x) \
62717 +({ \
62718 + void *___retval; \
62719 + intoverflow_t ___x = (intoverflow_t)x; \
62720 + if (WARN(___x > ULONG_MAX, "vzalloc size overflow\n")) \
62721 + ___retval = NULL; \
62722 + else \
62723 + ___retval = vzalloc((unsigned long)___x); \
62724 + ___retval; \
62725 +})
62726 +
62727 +#define __vmalloc(x, y, z) \
62728 +({ \
62729 + void *___retval; \
62730 + intoverflow_t ___x = (intoverflow_t)x; \
62731 + if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
62732 + ___retval = NULL; \
62733 + else \
62734 + ___retval = __vmalloc((unsigned long)___x, (y), (z));\
62735 + ___retval; \
62736 +})
62737 +
62738 +#define vmalloc_user(x) \
62739 +({ \
62740 + void *___retval; \
62741 + intoverflow_t ___x = (intoverflow_t)x; \
62742 + if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
62743 + ___retval = NULL; \
62744 + else \
62745 + ___retval = vmalloc_user((unsigned long)___x); \
62746 + ___retval; \
62747 +})
62748 +
62749 +#define vmalloc_exec(x) \
62750 +({ \
62751 + void *___retval; \
62752 + intoverflow_t ___x = (intoverflow_t)x; \
62753 + if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
62754 + ___retval = NULL; \
62755 + else \
62756 + ___retval = vmalloc_exec((unsigned long)___x); \
62757 + ___retval; \
62758 +})
62759 +
62760 +#define vmalloc_node(x, y) \
62761 +({ \
62762 + void *___retval; \
62763 + intoverflow_t ___x = (intoverflow_t)x; \
62764 + if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
62765 + ___retval = NULL; \
62766 + else \
62767 + ___retval = vmalloc_node((unsigned long)___x, (y));\
62768 + ___retval; \
62769 +})
62770 +
62771 +#define vzalloc_node(x, y) \
62772 +({ \
62773 + void *___retval; \
62774 + intoverflow_t ___x = (intoverflow_t)x; \
62775 + if (WARN(___x > ULONG_MAX, "vzalloc_node size overflow\n"))\
62776 + ___retval = NULL; \
62777 + else \
62778 + ___retval = vzalloc_node((unsigned long)___x, (y));\
62779 + ___retval; \
62780 +})
62781 +
62782 +#define vmalloc_32(x) \
62783 +({ \
62784 + void *___retval; \
62785 + intoverflow_t ___x = (intoverflow_t)x; \
62786 + if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
62787 + ___retval = NULL; \
62788 + else \
62789 + ___retval = vmalloc_32((unsigned long)___x); \
62790 + ___retval; \
62791 +})
62792 +
62793 +#define vmalloc_32_user(x) \
62794 +({ \
62795 +void *___retval; \
62796 + intoverflow_t ___x = (intoverflow_t)x; \
62797 + if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
62798 + ___retval = NULL; \
62799 + else \
62800 + ___retval = vmalloc_32_user((unsigned long)___x);\
62801 + ___retval; \
62802 +})
62803 +
62804 #endif /* _LINUX_VMALLOC_H */
62805 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
62806 index 65efb92..137adbb 100644
62807 --- a/include/linux/vmstat.h
62808 +++ b/include/linux/vmstat.h
62809 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
62810 /*
62811 * Zone based page accounting with per cpu differentials.
62812 */
62813 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62814 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62815
62816 static inline void zone_page_state_add(long x, struct zone *zone,
62817 enum zone_stat_item item)
62818 {
62819 - atomic_long_add(x, &zone->vm_stat[item]);
62820 - atomic_long_add(x, &vm_stat[item]);
62821 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
62822 + atomic_long_add_unchecked(x, &vm_stat[item]);
62823 }
62824
62825 static inline unsigned long global_page_state(enum zone_stat_item item)
62826 {
62827 - long x = atomic_long_read(&vm_stat[item]);
62828 + long x = atomic_long_read_unchecked(&vm_stat[item]);
62829 #ifdef CONFIG_SMP
62830 if (x < 0)
62831 x = 0;
62832 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
62833 static inline unsigned long zone_page_state(struct zone *zone,
62834 enum zone_stat_item item)
62835 {
62836 - long x = atomic_long_read(&zone->vm_stat[item]);
62837 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
62838 #ifdef CONFIG_SMP
62839 if (x < 0)
62840 x = 0;
62841 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
62842 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
62843 enum zone_stat_item item)
62844 {
62845 - long x = atomic_long_read(&zone->vm_stat[item]);
62846 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
62847
62848 #ifdef CONFIG_SMP
62849 int cpu;
62850 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
62851
62852 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
62853 {
62854 - atomic_long_inc(&zone->vm_stat[item]);
62855 - atomic_long_inc(&vm_stat[item]);
62856 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
62857 + atomic_long_inc_unchecked(&vm_stat[item]);
62858 }
62859
62860 static inline void __inc_zone_page_state(struct page *page,
62861 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
62862
62863 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
62864 {
62865 - atomic_long_dec(&zone->vm_stat[item]);
62866 - atomic_long_dec(&vm_stat[item]);
62867 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
62868 + atomic_long_dec_unchecked(&vm_stat[item]);
62869 }
62870
62871 static inline void __dec_zone_page_state(struct page *page,
62872 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
62873 index e5d1220..ef6e406 100644
62874 --- a/include/linux/xattr.h
62875 +++ b/include/linux/xattr.h
62876 @@ -57,6 +57,11 @@
62877 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
62878 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
62879
62880 +/* User namespace */
62881 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
62882 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
62883 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
62884 +
62885 #ifdef __KERNEL__
62886
62887 #include <linux/types.h>
62888 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
62889 index 4aeff96..b378cdc 100644
62890 --- a/include/media/saa7146_vv.h
62891 +++ b/include/media/saa7146_vv.h
62892 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
62893 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
62894
62895 /* the extension can override this */
62896 - struct v4l2_ioctl_ops ops;
62897 + v4l2_ioctl_ops_no_const ops;
62898 /* pointer to the saa7146 core ops */
62899 const struct v4l2_ioctl_ops *core_ops;
62900
62901 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
62902 index c7c40f1..4f01585 100644
62903 --- a/include/media/v4l2-dev.h
62904 +++ b/include/media/v4l2-dev.h
62905 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
62906
62907
62908 struct v4l2_file_operations {
62909 - struct module *owner;
62910 + struct module * const owner;
62911 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
62912 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
62913 unsigned int (*poll) (struct file *, struct poll_table_struct *);
62914 @@ -68,6 +68,7 @@ struct v4l2_file_operations {
62915 int (*open) (struct file *);
62916 int (*release) (struct file *);
62917 };
62918 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
62919
62920 /*
62921 * Newer version of video_device, handled by videodev2.c
62922 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
62923 index 4d1c74a..65e1221 100644
62924 --- a/include/media/v4l2-ioctl.h
62925 +++ b/include/media/v4l2-ioctl.h
62926 @@ -274,7 +274,7 @@ struct v4l2_ioctl_ops {
62927 long (*vidioc_default) (struct file *file, void *fh,
62928 bool valid_prio, int cmd, void *arg);
62929 };
62930 -
62931 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
62932
62933 /* v4l debugging and diagnostics */
62934
62935 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
62936 index 8d55251..dfe5b0a 100644
62937 --- a/include/net/caif/caif_hsi.h
62938 +++ b/include/net/caif/caif_hsi.h
62939 @@ -98,7 +98,7 @@ struct cfhsi_drv {
62940 void (*rx_done_cb) (struct cfhsi_drv *drv);
62941 void (*wake_up_cb) (struct cfhsi_drv *drv);
62942 void (*wake_down_cb) (struct cfhsi_drv *drv);
62943 -};
62944 +} __no_const;
62945
62946 /* Structure implemented by HSI device. */
62947 struct cfhsi_dev {
62948 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
62949 index 9e5425b..8136ffc 100644
62950 --- a/include/net/caif/cfctrl.h
62951 +++ b/include/net/caif/cfctrl.h
62952 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
62953 void (*radioset_rsp)(void);
62954 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
62955 struct cflayer *client_layer);
62956 -};
62957 +} __no_const;
62958
62959 /* Link Setup Parameters for CAIF-Links. */
62960 struct cfctrl_link_param {
62961 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
62962 struct cfctrl {
62963 struct cfsrvl serv;
62964 struct cfctrl_rsp res;
62965 - atomic_t req_seq_no;
62966 - atomic_t rsp_seq_no;
62967 + atomic_unchecked_t req_seq_no;
62968 + atomic_unchecked_t rsp_seq_no;
62969 struct list_head list;
62970 /* Protects from simultaneous access to first_req list */
62971 spinlock_t info_list_lock;
62972 diff --git a/include/net/flow.h b/include/net/flow.h
62973 index 2a7eefd..3250f3b 100644
62974 --- a/include/net/flow.h
62975 +++ b/include/net/flow.h
62976 @@ -218,6 +218,6 @@ extern struct flow_cache_object *flow_cache_lookup(
62977
62978 extern void flow_cache_flush(void);
62979 extern void flow_cache_flush_deferred(void);
62980 -extern atomic_t flow_cache_genid;
62981 +extern atomic_unchecked_t flow_cache_genid;
62982
62983 #endif
62984 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
62985 index e9ff3fc..9d3e5c7 100644
62986 --- a/include/net/inetpeer.h
62987 +++ b/include/net/inetpeer.h
62988 @@ -48,8 +48,8 @@ struct inet_peer {
62989 */
62990 union {
62991 struct {
62992 - atomic_t rid; /* Frag reception counter */
62993 - atomic_t ip_id_count; /* IP ID for the next packet */
62994 + atomic_unchecked_t rid; /* Frag reception counter */
62995 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
62996 __u32 tcp_ts;
62997 __u32 tcp_ts_stamp;
62998 };
62999 @@ -113,11 +113,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
63000 more++;
63001 inet_peer_refcheck(p);
63002 do {
63003 - old = atomic_read(&p->ip_id_count);
63004 + old = atomic_read_unchecked(&p->ip_id_count);
63005 new = old + more;
63006 if (!new)
63007 new = 1;
63008 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
63009 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
63010 return new;
63011 }
63012
63013 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
63014 index 10422ef..662570f 100644
63015 --- a/include/net/ip_fib.h
63016 +++ b/include/net/ip_fib.h
63017 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
63018
63019 #define FIB_RES_SADDR(net, res) \
63020 ((FIB_RES_NH(res).nh_saddr_genid == \
63021 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
63022 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
63023 FIB_RES_NH(res).nh_saddr : \
63024 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
63025 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
63026 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
63027 index e5a7b9a..f4fc44b 100644
63028 --- a/include/net/ip_vs.h
63029 +++ b/include/net/ip_vs.h
63030 @@ -509,7 +509,7 @@ struct ip_vs_conn {
63031 struct ip_vs_conn *control; /* Master control connection */
63032 atomic_t n_control; /* Number of controlled ones */
63033 struct ip_vs_dest *dest; /* real server */
63034 - atomic_t in_pkts; /* incoming packet counter */
63035 + atomic_unchecked_t in_pkts; /* incoming packet counter */
63036
63037 /* packet transmitter for different forwarding methods. If it
63038 mangles the packet, it must return NF_DROP or better NF_STOLEN,
63039 @@ -647,7 +647,7 @@ struct ip_vs_dest {
63040 __be16 port; /* port number of the server */
63041 union nf_inet_addr addr; /* IP address of the server */
63042 volatile unsigned flags; /* dest status flags */
63043 - atomic_t conn_flags; /* flags to copy to conn */
63044 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
63045 atomic_t weight; /* server weight */
63046
63047 atomic_t refcnt; /* reference counter */
63048 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
63049 index 69b610a..fe3962c 100644
63050 --- a/include/net/irda/ircomm_core.h
63051 +++ b/include/net/irda/ircomm_core.h
63052 @@ -51,7 +51,7 @@ typedef struct {
63053 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
63054 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
63055 struct ircomm_info *);
63056 -} call_t;
63057 +} __no_const call_t;
63058
63059 struct ircomm_cb {
63060 irda_queue_t queue;
63061 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
63062 index 59ba38bc..d515662 100644
63063 --- a/include/net/irda/ircomm_tty.h
63064 +++ b/include/net/irda/ircomm_tty.h
63065 @@ -35,6 +35,7 @@
63066 #include <linux/termios.h>
63067 #include <linux/timer.h>
63068 #include <linux/tty.h> /* struct tty_struct */
63069 +#include <asm/local.h>
63070
63071 #include <net/irda/irias_object.h>
63072 #include <net/irda/ircomm_core.h>
63073 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
63074 unsigned short close_delay;
63075 unsigned short closing_wait; /* time to wait before closing */
63076
63077 - int open_count;
63078 - int blocked_open; /* # of blocked opens */
63079 + local_t open_count;
63080 + local_t blocked_open; /* # of blocked opens */
63081
63082 /* Protect concurent access to :
63083 * o self->open_count
63084 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
63085 index f2419cf..473679f 100644
63086 --- a/include/net/iucv/af_iucv.h
63087 +++ b/include/net/iucv/af_iucv.h
63088 @@ -139,7 +139,7 @@ struct iucv_sock {
63089 struct iucv_sock_list {
63090 struct hlist_head head;
63091 rwlock_t lock;
63092 - atomic_t autobind_name;
63093 + atomic_unchecked_t autobind_name;
63094 };
63095
63096 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
63097 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
63098 index 2720884..3aa5c25 100644
63099 --- a/include/net/neighbour.h
63100 +++ b/include/net/neighbour.h
63101 @@ -122,7 +122,7 @@ struct neigh_ops {
63102 void (*error_report)(struct neighbour *, struct sk_buff *);
63103 int (*output)(struct neighbour *, struct sk_buff *);
63104 int (*connected_output)(struct neighbour *, struct sk_buff *);
63105 -};
63106 +} __do_const;
63107
63108 struct pneigh_entry {
63109 struct pneigh_entry *next;
63110 diff --git a/include/net/netlink.h b/include/net/netlink.h
63111 index cb1f350..3279d2c 100644
63112 --- a/include/net/netlink.h
63113 +++ b/include/net/netlink.h
63114 @@ -569,7 +569,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
63115 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
63116 {
63117 if (mark)
63118 - skb_trim(skb, (unsigned char *) mark - skb->data);
63119 + skb_trim(skb, (const unsigned char *) mark - skb->data);
63120 }
63121
63122 /**
63123 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
63124 index d786b4f..4c3dd41 100644
63125 --- a/include/net/netns/ipv4.h
63126 +++ b/include/net/netns/ipv4.h
63127 @@ -56,8 +56,8 @@ struct netns_ipv4 {
63128
63129 unsigned int sysctl_ping_group_range[2];
63130
63131 - atomic_t rt_genid;
63132 - atomic_t dev_addr_genid;
63133 + atomic_unchecked_t rt_genid;
63134 + atomic_unchecked_t dev_addr_genid;
63135
63136 #ifdef CONFIG_IP_MROUTE
63137 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
63138 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
63139 index 6a72a58..e6a127d 100644
63140 --- a/include/net/sctp/sctp.h
63141 +++ b/include/net/sctp/sctp.h
63142 @@ -318,9 +318,9 @@ do { \
63143
63144 #else /* SCTP_DEBUG */
63145
63146 -#define SCTP_DEBUG_PRINTK(whatever...)
63147 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
63148 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
63149 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
63150 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
63151 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
63152 #define SCTP_ENABLE_DEBUG
63153 #define SCTP_DISABLE_DEBUG
63154 #define SCTP_ASSERT(expr, str, func)
63155 diff --git a/include/net/sock.h b/include/net/sock.h
63156 index 32e3937..87a1dbc 100644
63157 --- a/include/net/sock.h
63158 +++ b/include/net/sock.h
63159 @@ -277,7 +277,7 @@ struct sock {
63160 #ifdef CONFIG_RPS
63161 __u32 sk_rxhash;
63162 #endif
63163 - atomic_t sk_drops;
63164 + atomic_unchecked_t sk_drops;
63165 int sk_rcvbuf;
63166
63167 struct sk_filter __rcu *sk_filter;
63168 @@ -1402,7 +1402,7 @@ static inline void sk_nocaps_add(struct sock *sk, int flags)
63169 }
63170
63171 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
63172 - char __user *from, char *to,
63173 + char __user *from, unsigned char *to,
63174 int copy, int offset)
63175 {
63176 if (skb->ip_summed == CHECKSUM_NONE) {
63177 diff --git a/include/net/tcp.h b/include/net/tcp.h
63178 index bb18c4d..bb87972 100644
63179 --- a/include/net/tcp.h
63180 +++ b/include/net/tcp.h
63181 @@ -1409,7 +1409,7 @@ struct tcp_seq_afinfo {
63182 char *name;
63183 sa_family_t family;
63184 const struct file_operations *seq_fops;
63185 - struct seq_operations seq_ops;
63186 + seq_operations_no_const seq_ops;
63187 };
63188
63189 struct tcp_iter_state {
63190 diff --git a/include/net/udp.h b/include/net/udp.h
63191 index 3b285f4..0219639 100644
63192 --- a/include/net/udp.h
63193 +++ b/include/net/udp.h
63194 @@ -237,7 +237,7 @@ struct udp_seq_afinfo {
63195 sa_family_t family;
63196 struct udp_table *udp_table;
63197 const struct file_operations *seq_fops;
63198 - struct seq_operations seq_ops;
63199 + seq_operations_no_const seq_ops;
63200 };
63201
63202 struct udp_iter_state {
63203 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
63204 index b203e14..1df3991 100644
63205 --- a/include/net/xfrm.h
63206 +++ b/include/net/xfrm.h
63207 @@ -505,7 +505,7 @@ struct xfrm_policy {
63208 struct timer_list timer;
63209
63210 struct flow_cache_object flo;
63211 - atomic_t genid;
63212 + atomic_unchecked_t genid;
63213 u32 priority;
63214 u32 index;
63215 struct xfrm_mark mark;
63216 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
63217 index 1a046b1..ee0bef0 100644
63218 --- a/include/rdma/iw_cm.h
63219 +++ b/include/rdma/iw_cm.h
63220 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
63221 int backlog);
63222
63223 int (*destroy_listen)(struct iw_cm_id *cm_id);
63224 -};
63225 +} __no_const;
63226
63227 /**
63228 * iw_create_cm_id - Create an IW CM identifier.
63229 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
63230 index 5d1a758..1dbf795 100644
63231 --- a/include/scsi/libfc.h
63232 +++ b/include/scsi/libfc.h
63233 @@ -748,6 +748,7 @@ struct libfc_function_template {
63234 */
63235 void (*disc_stop_final) (struct fc_lport *);
63236 };
63237 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
63238
63239 /**
63240 * struct fc_disc - Discovery context
63241 @@ -851,7 +852,7 @@ struct fc_lport {
63242 struct fc_vport *vport;
63243
63244 /* Operational Information */
63245 - struct libfc_function_template tt;
63246 + libfc_function_template_no_const tt;
63247 u8 link_up;
63248 u8 qfull;
63249 enum fc_lport_state state;
63250 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
63251 index 5591ed5..13eb457 100644
63252 --- a/include/scsi/scsi_device.h
63253 +++ b/include/scsi/scsi_device.h
63254 @@ -161,9 +161,9 @@ struct scsi_device {
63255 unsigned int max_device_blocked; /* what device_blocked counts down from */
63256 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
63257
63258 - atomic_t iorequest_cnt;
63259 - atomic_t iodone_cnt;
63260 - atomic_t ioerr_cnt;
63261 + atomic_unchecked_t iorequest_cnt;
63262 + atomic_unchecked_t iodone_cnt;
63263 + atomic_unchecked_t ioerr_cnt;
63264
63265 struct device sdev_gendev,
63266 sdev_dev;
63267 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
63268 index 2a65167..91e01f8 100644
63269 --- a/include/scsi/scsi_transport_fc.h
63270 +++ b/include/scsi/scsi_transport_fc.h
63271 @@ -711,7 +711,7 @@ struct fc_function_template {
63272 unsigned long show_host_system_hostname:1;
63273
63274 unsigned long disable_target_scan:1;
63275 -};
63276 +} __do_const;
63277
63278
63279 /**
63280 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
63281 index 030b87c..98a6954 100644
63282 --- a/include/sound/ak4xxx-adda.h
63283 +++ b/include/sound/ak4xxx-adda.h
63284 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
63285 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
63286 unsigned char val);
63287 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
63288 -};
63289 +} __no_const;
63290
63291 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
63292
63293 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
63294 index 8c05e47..2b5df97 100644
63295 --- a/include/sound/hwdep.h
63296 +++ b/include/sound/hwdep.h
63297 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
63298 struct snd_hwdep_dsp_status *status);
63299 int (*dsp_load)(struct snd_hwdep *hw,
63300 struct snd_hwdep_dsp_image *image);
63301 -};
63302 +} __no_const;
63303
63304 struct snd_hwdep {
63305 struct snd_card *card;
63306 diff --git a/include/sound/info.h b/include/sound/info.h
63307 index 5492cc4..1a65278 100644
63308 --- a/include/sound/info.h
63309 +++ b/include/sound/info.h
63310 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
63311 struct snd_info_buffer *buffer);
63312 void (*write)(struct snd_info_entry *entry,
63313 struct snd_info_buffer *buffer);
63314 -};
63315 +} __no_const;
63316
63317 struct snd_info_entry_ops {
63318 int (*open)(struct snd_info_entry *entry,
63319 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
63320 index 0cf91b2..b70cae4 100644
63321 --- a/include/sound/pcm.h
63322 +++ b/include/sound/pcm.h
63323 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
63324 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
63325 int (*ack)(struct snd_pcm_substream *substream);
63326 };
63327 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
63328
63329 /*
63330 *
63331 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
63332 index af1b49e..a5d55a5 100644
63333 --- a/include/sound/sb16_csp.h
63334 +++ b/include/sound/sb16_csp.h
63335 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
63336 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
63337 int (*csp_stop) (struct snd_sb_csp * p);
63338 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
63339 -};
63340 +} __no_const;
63341
63342 /*
63343 * CSP private data
63344 diff --git a/include/sound/soc.h b/include/sound/soc.h
63345 index 11cfb59..e3f93f4 100644
63346 --- a/include/sound/soc.h
63347 +++ b/include/sound/soc.h
63348 @@ -683,7 +683,7 @@ struct snd_soc_platform_driver {
63349 /* platform IO - used for platform DAPM */
63350 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
63351 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
63352 -};
63353 +} __do_const;
63354
63355 struct snd_soc_platform {
63356 const char *name;
63357 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
63358 index 444cd6b..3327cc5 100644
63359 --- a/include/sound/ymfpci.h
63360 +++ b/include/sound/ymfpci.h
63361 @@ -358,7 +358,7 @@ struct snd_ymfpci {
63362 spinlock_t reg_lock;
63363 spinlock_t voice_lock;
63364 wait_queue_head_t interrupt_sleep;
63365 - atomic_t interrupt_sleep_count;
63366 + atomic_unchecked_t interrupt_sleep_count;
63367 struct snd_info_entry *proc_entry;
63368 const struct firmware *dsp_microcode;
63369 const struct firmware *controller_microcode;
63370 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
63371 index 94bbec3..3a8c6b0 100644
63372 --- a/include/target/target_core_base.h
63373 +++ b/include/target/target_core_base.h
63374 @@ -346,7 +346,7 @@ struct t10_reservation_ops {
63375 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
63376 int (*t10_pr_register)(struct se_cmd *);
63377 int (*t10_pr_clear)(struct se_cmd *);
63378 -};
63379 +} __no_const;
63380
63381 struct t10_reservation {
63382 /* Reservation effects all target ports */
63383 @@ -465,8 +465,8 @@ struct se_cmd {
63384 atomic_t t_se_count;
63385 atomic_t t_task_cdbs_left;
63386 atomic_t t_task_cdbs_ex_left;
63387 - atomic_t t_task_cdbs_sent;
63388 - atomic_t t_transport_aborted;
63389 + atomic_unchecked_t t_task_cdbs_sent;
63390 + atomic_unchecked_t t_transport_aborted;
63391 atomic_t t_transport_active;
63392 atomic_t t_transport_complete;
63393 atomic_t t_transport_queue_active;
63394 @@ -705,7 +705,7 @@ struct se_device {
63395 /* Active commands on this virtual SE device */
63396 atomic_t simple_cmds;
63397 atomic_t depth_left;
63398 - atomic_t dev_ordered_id;
63399 + atomic_unchecked_t dev_ordered_id;
63400 atomic_t execute_tasks;
63401 atomic_t dev_ordered_sync;
63402 atomic_t dev_qf_count;
63403 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
63404 index 1c09820..7f5ec79 100644
63405 --- a/include/trace/events/irq.h
63406 +++ b/include/trace/events/irq.h
63407 @@ -36,7 +36,7 @@ struct softirq_action;
63408 */
63409 TRACE_EVENT(irq_handler_entry,
63410
63411 - TP_PROTO(int irq, struct irqaction *action),
63412 + TP_PROTO(int irq, const struct irqaction *action),
63413
63414 TP_ARGS(irq, action),
63415
63416 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
63417 */
63418 TRACE_EVENT(irq_handler_exit,
63419
63420 - TP_PROTO(int irq, struct irqaction *action, int ret),
63421 + TP_PROTO(int irq, const struct irqaction *action, int ret),
63422
63423 TP_ARGS(irq, action, ret),
63424
63425 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
63426 index c41f308..6918de3 100644
63427 --- a/include/video/udlfb.h
63428 +++ b/include/video/udlfb.h
63429 @@ -52,10 +52,10 @@ struct dlfb_data {
63430 u32 pseudo_palette[256];
63431 int blank_mode; /*one of FB_BLANK_ */
63432 /* blit-only rendering path metrics, exposed through sysfs */
63433 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
63434 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
63435 - atomic_t bytes_sent; /* to usb, after compression including overhead */
63436 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
63437 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
63438 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
63439 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
63440 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
63441 };
63442
63443 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
63444 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
63445 index 0993a22..32ba2fe 100644
63446 --- a/include/video/uvesafb.h
63447 +++ b/include/video/uvesafb.h
63448 @@ -177,6 +177,7 @@ struct uvesafb_par {
63449 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
63450 u8 pmi_setpal; /* PMI for palette changes */
63451 u16 *pmi_base; /* protected mode interface location */
63452 + u8 *pmi_code; /* protected mode code location */
63453 void *pmi_start;
63454 void *pmi_pal;
63455 u8 *vbe_state_orig; /*
63456 diff --git a/init/Kconfig b/init/Kconfig
63457 index 43298f9..2f56c12 100644
63458 --- a/init/Kconfig
63459 +++ b/init/Kconfig
63460 @@ -1214,7 +1214,7 @@ config SLUB_DEBUG
63461
63462 config COMPAT_BRK
63463 bool "Disable heap randomization"
63464 - default y
63465 + default n
63466 help
63467 Randomizing heap placement makes heap exploits harder, but it
63468 also breaks ancient binaries (including anything libc5 based).
63469 diff --git a/init/do_mounts.c b/init/do_mounts.c
63470 index db6e5ee..7677ff7 100644
63471 --- a/init/do_mounts.c
63472 +++ b/init/do_mounts.c
63473 @@ -325,11 +325,11 @@ static void __init get_fs_names(char *page)
63474
63475 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
63476 {
63477 - int err = sys_mount(name, "/root", fs, flags, data);
63478 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
63479 if (err)
63480 return err;
63481
63482 - sys_chdir((const char __user __force *)"/root");
63483 + sys_chdir((const char __force_user*)"/root");
63484 ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
63485 printk(KERN_INFO
63486 "VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
63487 @@ -448,18 +448,18 @@ void __init change_floppy(char *fmt, ...)
63488 va_start(args, fmt);
63489 vsprintf(buf, fmt, args);
63490 va_end(args);
63491 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
63492 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
63493 if (fd >= 0) {
63494 sys_ioctl(fd, FDEJECT, 0);
63495 sys_close(fd);
63496 }
63497 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
63498 - fd = sys_open("/dev/console", O_RDWR, 0);
63499 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
63500 if (fd >= 0) {
63501 sys_ioctl(fd, TCGETS, (long)&termios);
63502 termios.c_lflag &= ~ICANON;
63503 sys_ioctl(fd, TCSETSF, (long)&termios);
63504 - sys_read(fd, &c, 1);
63505 + sys_read(fd, (char __user *)&c, 1);
63506 termios.c_lflag |= ICANON;
63507 sys_ioctl(fd, TCSETSF, (long)&termios);
63508 sys_close(fd);
63509 @@ -553,6 +553,6 @@ void __init prepare_namespace(void)
63510 mount_root();
63511 out:
63512 devtmpfs_mount("dev");
63513 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
63514 - sys_chroot((const char __user __force *)".");
63515 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
63516 + sys_chroot((const char __force_user *)".");
63517 }
63518 diff --git a/init/do_mounts.h b/init/do_mounts.h
63519 index f5b978a..69dbfe8 100644
63520 --- a/init/do_mounts.h
63521 +++ b/init/do_mounts.h
63522 @@ -15,15 +15,15 @@ extern int root_mountflags;
63523
63524 static inline int create_dev(char *name, dev_t dev)
63525 {
63526 - sys_unlink(name);
63527 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
63528 + sys_unlink((char __force_user *)name);
63529 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
63530 }
63531
63532 #if BITS_PER_LONG == 32
63533 static inline u32 bstat(char *name)
63534 {
63535 struct stat64 stat;
63536 - if (sys_stat64(name, &stat) != 0)
63537 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
63538 return 0;
63539 if (!S_ISBLK(stat.st_mode))
63540 return 0;
63541 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
63542 static inline u32 bstat(char *name)
63543 {
63544 struct stat stat;
63545 - if (sys_newstat(name, &stat) != 0)
63546 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
63547 return 0;
63548 if (!S_ISBLK(stat.st_mode))
63549 return 0;
63550 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
63551 index 3098a38..253064e 100644
63552 --- a/init/do_mounts_initrd.c
63553 +++ b/init/do_mounts_initrd.c
63554 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
63555 create_dev("/dev/root.old", Root_RAM0);
63556 /* mount initrd on rootfs' /root */
63557 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
63558 - sys_mkdir("/old", 0700);
63559 - root_fd = sys_open("/", 0, 0);
63560 - old_fd = sys_open("/old", 0, 0);
63561 + sys_mkdir((const char __force_user *)"/old", 0700);
63562 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
63563 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
63564 /* move initrd over / and chdir/chroot in initrd root */
63565 - sys_chdir("/root");
63566 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
63567 - sys_chroot(".");
63568 + sys_chdir((const char __force_user *)"/root");
63569 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
63570 + sys_chroot((const char __force_user *)".");
63571
63572 /*
63573 * In case that a resume from disk is carried out by linuxrc or one of
63574 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
63575
63576 /* move initrd to rootfs' /old */
63577 sys_fchdir(old_fd);
63578 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
63579 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
63580 /* switch root and cwd back to / of rootfs */
63581 sys_fchdir(root_fd);
63582 - sys_chroot(".");
63583 + sys_chroot((const char __force_user *)".");
63584 sys_close(old_fd);
63585 sys_close(root_fd);
63586
63587 if (new_decode_dev(real_root_dev) == Root_RAM0) {
63588 - sys_chdir("/old");
63589 + sys_chdir((const char __force_user *)"/old");
63590 return;
63591 }
63592
63593 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
63594 mount_root();
63595
63596 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
63597 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
63598 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
63599 if (!error)
63600 printk("okay\n");
63601 else {
63602 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
63603 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
63604 if (error == -ENOENT)
63605 printk("/initrd does not exist. Ignored.\n");
63606 else
63607 printk("failed\n");
63608 printk(KERN_NOTICE "Unmounting old root\n");
63609 - sys_umount("/old", MNT_DETACH);
63610 + sys_umount((char __force_user *)"/old", MNT_DETACH);
63611 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
63612 if (fd < 0) {
63613 error = fd;
63614 @@ -116,11 +116,11 @@ int __init initrd_load(void)
63615 * mounted in the normal path.
63616 */
63617 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
63618 - sys_unlink("/initrd.image");
63619 + sys_unlink((const char __force_user *)"/initrd.image");
63620 handle_initrd();
63621 return 1;
63622 }
63623 }
63624 - sys_unlink("/initrd.image");
63625 + sys_unlink((const char __force_user *)"/initrd.image");
63626 return 0;
63627 }
63628 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
63629 index 32c4799..c27ee74 100644
63630 --- a/init/do_mounts_md.c
63631 +++ b/init/do_mounts_md.c
63632 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
63633 partitioned ? "_d" : "", minor,
63634 md_setup_args[ent].device_names);
63635
63636 - fd = sys_open(name, 0, 0);
63637 + fd = sys_open((char __force_user *)name, 0, 0);
63638 if (fd < 0) {
63639 printk(KERN_ERR "md: open failed - cannot start "
63640 "array %s\n", name);
63641 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
63642 * array without it
63643 */
63644 sys_close(fd);
63645 - fd = sys_open(name, 0, 0);
63646 + fd = sys_open((char __force_user *)name, 0, 0);
63647 sys_ioctl(fd, BLKRRPART, 0);
63648 }
63649 sys_close(fd);
63650 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
63651
63652 wait_for_device_probe();
63653
63654 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
63655 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
63656 if (fd >= 0) {
63657 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
63658 sys_close(fd);
63659 diff --git a/init/initramfs.c b/init/initramfs.c
63660 index 2531811..040d4d4 100644
63661 --- a/init/initramfs.c
63662 +++ b/init/initramfs.c
63663 @@ -74,7 +74,7 @@ static void __init free_hash(void)
63664 }
63665 }
63666
63667 -static long __init do_utime(char __user *filename, time_t mtime)
63668 +static long __init do_utime(__force char __user *filename, time_t mtime)
63669 {
63670 struct timespec t[2];
63671
63672 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
63673 struct dir_entry *de, *tmp;
63674 list_for_each_entry_safe(de, tmp, &dir_list, list) {
63675 list_del(&de->list);
63676 - do_utime(de->name, de->mtime);
63677 + do_utime((char __force_user *)de->name, de->mtime);
63678 kfree(de->name);
63679 kfree(de);
63680 }
63681 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
63682 if (nlink >= 2) {
63683 char *old = find_link(major, minor, ino, mode, collected);
63684 if (old)
63685 - return (sys_link(old, collected) < 0) ? -1 : 1;
63686 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
63687 }
63688 return 0;
63689 }
63690 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, mode_t mode)
63691 {
63692 struct stat st;
63693
63694 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
63695 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
63696 if (S_ISDIR(st.st_mode))
63697 - sys_rmdir(path);
63698 + sys_rmdir((char __force_user *)path);
63699 else
63700 - sys_unlink(path);
63701 + sys_unlink((char __force_user *)path);
63702 }
63703 }
63704
63705 @@ -305,7 +305,7 @@ static int __init do_name(void)
63706 int openflags = O_WRONLY|O_CREAT;
63707 if (ml != 1)
63708 openflags |= O_TRUNC;
63709 - wfd = sys_open(collected, openflags, mode);
63710 + wfd = sys_open((char __force_user *)collected, openflags, mode);
63711
63712 if (wfd >= 0) {
63713 sys_fchown(wfd, uid, gid);
63714 @@ -317,17 +317,17 @@ static int __init do_name(void)
63715 }
63716 }
63717 } else if (S_ISDIR(mode)) {
63718 - sys_mkdir(collected, mode);
63719 - sys_chown(collected, uid, gid);
63720 - sys_chmod(collected, mode);
63721 + sys_mkdir((char __force_user *)collected, mode);
63722 + sys_chown((char __force_user *)collected, uid, gid);
63723 + sys_chmod((char __force_user *)collected, mode);
63724 dir_add(collected, mtime);
63725 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
63726 S_ISFIFO(mode) || S_ISSOCK(mode)) {
63727 if (maybe_link() == 0) {
63728 - sys_mknod(collected, mode, rdev);
63729 - sys_chown(collected, uid, gid);
63730 - sys_chmod(collected, mode);
63731 - do_utime(collected, mtime);
63732 + sys_mknod((char __force_user *)collected, mode, rdev);
63733 + sys_chown((char __force_user *)collected, uid, gid);
63734 + sys_chmod((char __force_user *)collected, mode);
63735 + do_utime((char __force_user *)collected, mtime);
63736 }
63737 }
63738 return 0;
63739 @@ -336,15 +336,15 @@ static int __init do_name(void)
63740 static int __init do_copy(void)
63741 {
63742 if (count >= body_len) {
63743 - sys_write(wfd, victim, body_len);
63744 + sys_write(wfd, (char __force_user *)victim, body_len);
63745 sys_close(wfd);
63746 - do_utime(vcollected, mtime);
63747 + do_utime((char __force_user *)vcollected, mtime);
63748 kfree(vcollected);
63749 eat(body_len);
63750 state = SkipIt;
63751 return 0;
63752 } else {
63753 - sys_write(wfd, victim, count);
63754 + sys_write(wfd, (char __force_user *)victim, count);
63755 body_len -= count;
63756 eat(count);
63757 return 1;
63758 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
63759 {
63760 collected[N_ALIGN(name_len) + body_len] = '\0';
63761 clean_path(collected, 0);
63762 - sys_symlink(collected + N_ALIGN(name_len), collected);
63763 - sys_lchown(collected, uid, gid);
63764 - do_utime(collected, mtime);
63765 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
63766 + sys_lchown((char __force_user *)collected, uid, gid);
63767 + do_utime((char __force_user *)collected, mtime);
63768 state = SkipIt;
63769 next_state = Reset;
63770 return 0;
63771 diff --git a/init/main.c b/init/main.c
63772 index 217ed23..ec5406f 100644
63773 --- a/init/main.c
63774 +++ b/init/main.c
63775 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
63776 extern void tc_init(void);
63777 #endif
63778
63779 +extern void grsecurity_init(void);
63780 +
63781 /*
63782 * Debug helper: via this flag we know that we are in 'early bootup code'
63783 * where only the boot processor is running with IRQ disabled. This means
63784 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
63785
63786 __setup("reset_devices", set_reset_devices);
63787
63788 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
63789 +extern char pax_enter_kernel_user[];
63790 +extern char pax_exit_kernel_user[];
63791 +extern pgdval_t clone_pgd_mask;
63792 +#endif
63793 +
63794 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
63795 +static int __init setup_pax_nouderef(char *str)
63796 +{
63797 +#ifdef CONFIG_X86_32
63798 + unsigned int cpu;
63799 + struct desc_struct *gdt;
63800 +
63801 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
63802 + gdt = get_cpu_gdt_table(cpu);
63803 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
63804 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
63805 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
63806 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
63807 + }
63808 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
63809 +#else
63810 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
63811 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
63812 + clone_pgd_mask = ~(pgdval_t)0UL;
63813 +#endif
63814 +
63815 + return 0;
63816 +}
63817 +early_param("pax_nouderef", setup_pax_nouderef);
63818 +#endif
63819 +
63820 +#ifdef CONFIG_PAX_SOFTMODE
63821 +int pax_softmode;
63822 +
63823 +static int __init setup_pax_softmode(char *str)
63824 +{
63825 + get_option(&str, &pax_softmode);
63826 + return 1;
63827 +}
63828 +__setup("pax_softmode=", setup_pax_softmode);
63829 +#endif
63830 +
63831 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
63832 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
63833 static const char *panic_later, *panic_param;
63834 @@ -681,6 +726,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
63835 {
63836 int count = preempt_count();
63837 int ret;
63838 + const char *msg1 = "", *msg2 = "";
63839
63840 if (initcall_debug)
63841 ret = do_one_initcall_debug(fn);
63842 @@ -693,15 +739,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
63843 sprintf(msgbuf, "error code %d ", ret);
63844
63845 if (preempt_count() != count) {
63846 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
63847 + msg1 = " preemption imbalance";
63848 preempt_count() = count;
63849 }
63850 if (irqs_disabled()) {
63851 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
63852 + msg2 = " disabled interrupts";
63853 local_irq_enable();
63854 }
63855 - if (msgbuf[0]) {
63856 - printk("initcall %pF returned with %s\n", fn, msgbuf);
63857 + if (msgbuf[0] || *msg1 || *msg2) {
63858 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
63859 }
63860
63861 return ret;
63862 @@ -820,7 +866,7 @@ static int __init kernel_init(void * unused)
63863 do_basic_setup();
63864
63865 /* Open the /dev/console on the rootfs, this should never fail */
63866 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
63867 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
63868 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
63869
63870 (void) sys_dup(0);
63871 @@ -833,11 +879,13 @@ static int __init kernel_init(void * unused)
63872 if (!ramdisk_execute_command)
63873 ramdisk_execute_command = "/init";
63874
63875 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
63876 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
63877 ramdisk_execute_command = NULL;
63878 prepare_namespace();
63879 }
63880
63881 + grsecurity_init();
63882 +
63883 /*
63884 * Ok, we have completed the initial bootup, and
63885 * we're essentially up and running. Get rid of the
63886 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
63887 index 5b4293d..f179875 100644
63888 --- a/ipc/mqueue.c
63889 +++ b/ipc/mqueue.c
63890 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
63891 mq_bytes = (mq_msg_tblsz +
63892 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
63893
63894 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
63895 spin_lock(&mq_lock);
63896 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
63897 u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE)) {
63898 diff --git a/ipc/msg.c b/ipc/msg.c
63899 index 7385de2..a8180e08 100644
63900 --- a/ipc/msg.c
63901 +++ b/ipc/msg.c
63902 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
63903 return security_msg_queue_associate(msq, msgflg);
63904 }
63905
63906 +static struct ipc_ops msg_ops = {
63907 + .getnew = newque,
63908 + .associate = msg_security,
63909 + .more_checks = NULL
63910 +};
63911 +
63912 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
63913 {
63914 struct ipc_namespace *ns;
63915 - struct ipc_ops msg_ops;
63916 struct ipc_params msg_params;
63917
63918 ns = current->nsproxy->ipc_ns;
63919
63920 - msg_ops.getnew = newque;
63921 - msg_ops.associate = msg_security;
63922 - msg_ops.more_checks = NULL;
63923 -
63924 msg_params.key = key;
63925 msg_params.flg = msgflg;
63926
63927 diff --git a/ipc/sem.c b/ipc/sem.c
63928 index 5215a81..cfc0cac 100644
63929 --- a/ipc/sem.c
63930 +++ b/ipc/sem.c
63931 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
63932 return 0;
63933 }
63934
63935 +static struct ipc_ops sem_ops = {
63936 + .getnew = newary,
63937 + .associate = sem_security,
63938 + .more_checks = sem_more_checks
63939 +};
63940 +
63941 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
63942 {
63943 struct ipc_namespace *ns;
63944 - struct ipc_ops sem_ops;
63945 struct ipc_params sem_params;
63946
63947 ns = current->nsproxy->ipc_ns;
63948 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
63949 if (nsems < 0 || nsems > ns->sc_semmsl)
63950 return -EINVAL;
63951
63952 - sem_ops.getnew = newary;
63953 - sem_ops.associate = sem_security;
63954 - sem_ops.more_checks = sem_more_checks;
63955 -
63956 sem_params.key = key;
63957 sem_params.flg = semflg;
63958 sem_params.u.nsems = nsems;
63959 diff --git a/ipc/shm.c b/ipc/shm.c
63960 index b76be5b..859e750 100644
63961 --- a/ipc/shm.c
63962 +++ b/ipc/shm.c
63963 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
63964 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
63965 #endif
63966
63967 +#ifdef CONFIG_GRKERNSEC
63968 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63969 + const time_t shm_createtime, const uid_t cuid,
63970 + const int shmid);
63971 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63972 + const time_t shm_createtime);
63973 +#endif
63974 +
63975 void shm_init_ns(struct ipc_namespace *ns)
63976 {
63977 ns->shm_ctlmax = SHMMAX;
63978 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
63979 shp->shm_lprid = 0;
63980 shp->shm_atim = shp->shm_dtim = 0;
63981 shp->shm_ctim = get_seconds();
63982 +#ifdef CONFIG_GRKERNSEC
63983 + {
63984 + struct timespec timeval;
63985 + do_posix_clock_monotonic_gettime(&timeval);
63986 +
63987 + shp->shm_createtime = timeval.tv_sec;
63988 + }
63989 +#endif
63990 shp->shm_segsz = size;
63991 shp->shm_nattch = 0;
63992 shp->shm_file = file;
63993 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
63994 return 0;
63995 }
63996
63997 +static struct ipc_ops shm_ops = {
63998 + .getnew = newseg,
63999 + .associate = shm_security,
64000 + .more_checks = shm_more_checks
64001 +};
64002 +
64003 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
64004 {
64005 struct ipc_namespace *ns;
64006 - struct ipc_ops shm_ops;
64007 struct ipc_params shm_params;
64008
64009 ns = current->nsproxy->ipc_ns;
64010
64011 - shm_ops.getnew = newseg;
64012 - shm_ops.associate = shm_security;
64013 - shm_ops.more_checks = shm_more_checks;
64014 -
64015 shm_params.key = key;
64016 shm_params.flg = shmflg;
64017 shm_params.u.size = size;
64018 @@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
64019 f_mode = FMODE_READ | FMODE_WRITE;
64020 }
64021 if (shmflg & SHM_EXEC) {
64022 +
64023 +#ifdef CONFIG_PAX_MPROTECT
64024 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
64025 + goto out;
64026 +#endif
64027 +
64028 prot |= PROT_EXEC;
64029 acc_mode |= S_IXUGO;
64030 }
64031 @@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
64032 if (err)
64033 goto out_unlock;
64034
64035 +#ifdef CONFIG_GRKERNSEC
64036 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
64037 + shp->shm_perm.cuid, shmid) ||
64038 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
64039 + err = -EACCES;
64040 + goto out_unlock;
64041 + }
64042 +#endif
64043 +
64044 path = shp->shm_file->f_path;
64045 path_get(&path);
64046 shp->shm_nattch++;
64047 +#ifdef CONFIG_GRKERNSEC
64048 + shp->shm_lapid = current->pid;
64049 +#endif
64050 size = i_size_read(path.dentry->d_inode);
64051 shm_unlock(shp);
64052
64053 diff --git a/kernel/acct.c b/kernel/acct.c
64054 index fa7eb3d..7faf116 100644
64055 --- a/kernel/acct.c
64056 +++ b/kernel/acct.c
64057 @@ -570,7 +570,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
64058 */
64059 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
64060 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
64061 - file->f_op->write(file, (char *)&ac,
64062 + file->f_op->write(file, (char __force_user *)&ac,
64063 sizeof(acct_t), &file->f_pos);
64064 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
64065 set_fs(fs);
64066 diff --git a/kernel/audit.c b/kernel/audit.c
64067 index 09fae26..ed71d5b 100644
64068 --- a/kernel/audit.c
64069 +++ b/kernel/audit.c
64070 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
64071 3) suppressed due to audit_rate_limit
64072 4) suppressed due to audit_backlog_limit
64073 */
64074 -static atomic_t audit_lost = ATOMIC_INIT(0);
64075 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
64076
64077 /* The netlink socket. */
64078 static struct sock *audit_sock;
64079 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
64080 unsigned long now;
64081 int print;
64082
64083 - atomic_inc(&audit_lost);
64084 + atomic_inc_unchecked(&audit_lost);
64085
64086 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
64087
64088 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
64089 printk(KERN_WARNING
64090 "audit: audit_lost=%d audit_rate_limit=%d "
64091 "audit_backlog_limit=%d\n",
64092 - atomic_read(&audit_lost),
64093 + atomic_read_unchecked(&audit_lost),
64094 audit_rate_limit,
64095 audit_backlog_limit);
64096 audit_panic(message);
64097 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
64098 status_set.pid = audit_pid;
64099 status_set.rate_limit = audit_rate_limit;
64100 status_set.backlog_limit = audit_backlog_limit;
64101 - status_set.lost = atomic_read(&audit_lost);
64102 + status_set.lost = atomic_read_unchecked(&audit_lost);
64103 status_set.backlog = skb_queue_len(&audit_skb_queue);
64104 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
64105 &status_set, sizeof(status_set));
64106 @@ -1260,12 +1260,13 @@ static void audit_log_vformat(struct audit_buffer *ab, const char *fmt,
64107 avail = audit_expand(ab,
64108 max_t(unsigned, AUDIT_BUFSIZ, 1+len-avail));
64109 if (!avail)
64110 - goto out;
64111 + goto out_va_end;
64112 len = vsnprintf(skb_tail_pointer(skb), avail, fmt, args2);
64113 }
64114 - va_end(args2);
64115 if (len > 0)
64116 skb_put(skb, len);
64117 +out_va_end:
64118 + va_end(args2);
64119 out:
64120 return;
64121 }
64122 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
64123 index 47b7fc1..c003c33 100644
64124 --- a/kernel/auditsc.c
64125 +++ b/kernel/auditsc.c
64126 @@ -1166,8 +1166,8 @@ static void audit_log_execve_info(struct audit_context *context,
64127 struct audit_buffer **ab,
64128 struct audit_aux_data_execve *axi)
64129 {
64130 - int i;
64131 - size_t len, len_sent = 0;
64132 + int i, len;
64133 + size_t len_sent = 0;
64134 const char __user *p;
64135 char *buf;
64136
64137 @@ -2118,7 +2118,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
64138 }
64139
64140 /* global counter which is incremented every time something logs in */
64141 -static atomic_t session_id = ATOMIC_INIT(0);
64142 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
64143
64144 /**
64145 * audit_set_loginuid - set a task's audit_context loginuid
64146 @@ -2131,7 +2131,7 @@ static atomic_t session_id = ATOMIC_INIT(0);
64147 */
64148 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
64149 {
64150 - unsigned int sessionid = atomic_inc_return(&session_id);
64151 + unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
64152 struct audit_context *context = task->audit_context;
64153
64154 if (context && context->in_syscall) {
64155 diff --git a/kernel/capability.c b/kernel/capability.c
64156 index b463871..fa3ea1f 100644
64157 --- a/kernel/capability.c
64158 +++ b/kernel/capability.c
64159 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
64160 * before modification is attempted and the application
64161 * fails.
64162 */
64163 + if (tocopy > ARRAY_SIZE(kdata))
64164 + return -EFAULT;
64165 +
64166 if (copy_to_user(dataptr, kdata, tocopy
64167 * sizeof(struct __user_cap_data_struct))) {
64168 return -EFAULT;
64169 @@ -374,7 +377,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
64170 BUG();
64171 }
64172
64173 - if (security_capable(ns, current_cred(), cap) == 0) {
64174 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable(cap)) {
64175 current->flags |= PF_SUPERPRIV;
64176 return true;
64177 }
64178 @@ -382,6 +385,27 @@ bool ns_capable(struct user_namespace *ns, int cap)
64179 }
64180 EXPORT_SYMBOL(ns_capable);
64181
64182 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
64183 +{
64184 + if (unlikely(!cap_valid(cap))) {
64185 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
64186 + BUG();
64187 + }
64188 +
64189 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable_nolog(cap)) {
64190 + current->flags |= PF_SUPERPRIV;
64191 + return true;
64192 + }
64193 + return false;
64194 +}
64195 +EXPORT_SYMBOL(ns_capable_nolog);
64196 +
64197 +bool capable_nolog(int cap)
64198 +{
64199 + return ns_capable_nolog(&init_user_ns, cap);
64200 +}
64201 +EXPORT_SYMBOL(capable_nolog);
64202 +
64203 /**
64204 * task_ns_capable - Determine whether current task has a superior
64205 * capability targeted at a specific task's user namespace.
64206 @@ -396,6 +420,12 @@ bool task_ns_capable(struct task_struct *t, int cap)
64207 }
64208 EXPORT_SYMBOL(task_ns_capable);
64209
64210 +bool task_ns_capable_nolog(struct task_struct *t, int cap)
64211 +{
64212 + return ns_capable_nolog(task_cred_xxx(t, user)->user_ns, cap);
64213 +}
64214 +EXPORT_SYMBOL(task_ns_capable_nolog);
64215 +
64216 /**
64217 * nsown_capable - Check superior capability to one's own user_ns
64218 * @cap: The capability in question
64219 diff --git a/kernel/compat.c b/kernel/compat.c
64220 index f346ced..aa2b1f4 100644
64221 --- a/kernel/compat.c
64222 +++ b/kernel/compat.c
64223 @@ -13,6 +13,7 @@
64224
64225 #include <linux/linkage.h>
64226 #include <linux/compat.h>
64227 +#include <linux/module.h>
64228 #include <linux/errno.h>
64229 #include <linux/time.h>
64230 #include <linux/signal.h>
64231 @@ -168,7 +169,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
64232 mm_segment_t oldfs;
64233 long ret;
64234
64235 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
64236 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
64237 oldfs = get_fs();
64238 set_fs(KERNEL_DS);
64239 ret = hrtimer_nanosleep_restart(restart);
64240 @@ -200,7 +201,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
64241 oldfs = get_fs();
64242 set_fs(KERNEL_DS);
64243 ret = hrtimer_nanosleep(&tu,
64244 - rmtp ? (struct timespec __user *)&rmt : NULL,
64245 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
64246 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
64247 set_fs(oldfs);
64248
64249 @@ -309,7 +310,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
64250 mm_segment_t old_fs = get_fs();
64251
64252 set_fs(KERNEL_DS);
64253 - ret = sys_sigpending((old_sigset_t __user *) &s);
64254 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
64255 set_fs(old_fs);
64256 if (ret == 0)
64257 ret = put_user(s, set);
64258 @@ -332,8 +333,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
64259 old_fs = get_fs();
64260 set_fs(KERNEL_DS);
64261 ret = sys_sigprocmask(how,
64262 - set ? (old_sigset_t __user *) &s : NULL,
64263 - oset ? (old_sigset_t __user *) &s : NULL);
64264 + set ? (old_sigset_t __force_user *) &s : NULL,
64265 + oset ? (old_sigset_t __force_user *) &s : NULL);
64266 set_fs(old_fs);
64267 if (ret == 0)
64268 if (oset)
64269 @@ -370,7 +371,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
64270 mm_segment_t old_fs = get_fs();
64271
64272 set_fs(KERNEL_DS);
64273 - ret = sys_old_getrlimit(resource, &r);
64274 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
64275 set_fs(old_fs);
64276
64277 if (!ret) {
64278 @@ -442,7 +443,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
64279 mm_segment_t old_fs = get_fs();
64280
64281 set_fs(KERNEL_DS);
64282 - ret = sys_getrusage(who, (struct rusage __user *) &r);
64283 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
64284 set_fs(old_fs);
64285
64286 if (ret)
64287 @@ -469,8 +470,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
64288 set_fs (KERNEL_DS);
64289 ret = sys_wait4(pid,
64290 (stat_addr ?
64291 - (unsigned int __user *) &status : NULL),
64292 - options, (struct rusage __user *) &r);
64293 + (unsigned int __force_user *) &status : NULL),
64294 + options, (struct rusage __force_user *) &r);
64295 set_fs (old_fs);
64296
64297 if (ret > 0) {
64298 @@ -495,8 +496,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
64299 memset(&info, 0, sizeof(info));
64300
64301 set_fs(KERNEL_DS);
64302 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
64303 - uru ? (struct rusage __user *)&ru : NULL);
64304 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
64305 + uru ? (struct rusage __force_user *)&ru : NULL);
64306 set_fs(old_fs);
64307
64308 if ((ret < 0) || (info.si_signo == 0))
64309 @@ -626,8 +627,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
64310 oldfs = get_fs();
64311 set_fs(KERNEL_DS);
64312 err = sys_timer_settime(timer_id, flags,
64313 - (struct itimerspec __user *) &newts,
64314 - (struct itimerspec __user *) &oldts);
64315 + (struct itimerspec __force_user *) &newts,
64316 + (struct itimerspec __force_user *) &oldts);
64317 set_fs(oldfs);
64318 if (!err && old && put_compat_itimerspec(old, &oldts))
64319 return -EFAULT;
64320 @@ -644,7 +645,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
64321 oldfs = get_fs();
64322 set_fs(KERNEL_DS);
64323 err = sys_timer_gettime(timer_id,
64324 - (struct itimerspec __user *) &ts);
64325 + (struct itimerspec __force_user *) &ts);
64326 set_fs(oldfs);
64327 if (!err && put_compat_itimerspec(setting, &ts))
64328 return -EFAULT;
64329 @@ -663,7 +664,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
64330 oldfs = get_fs();
64331 set_fs(KERNEL_DS);
64332 err = sys_clock_settime(which_clock,
64333 - (struct timespec __user *) &ts);
64334 + (struct timespec __force_user *) &ts);
64335 set_fs(oldfs);
64336 return err;
64337 }
64338 @@ -678,7 +679,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
64339 oldfs = get_fs();
64340 set_fs(KERNEL_DS);
64341 err = sys_clock_gettime(which_clock,
64342 - (struct timespec __user *) &ts);
64343 + (struct timespec __force_user *) &ts);
64344 set_fs(oldfs);
64345 if (!err && put_compat_timespec(&ts, tp))
64346 return -EFAULT;
64347 @@ -698,7 +699,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
64348
64349 oldfs = get_fs();
64350 set_fs(KERNEL_DS);
64351 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
64352 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
64353 set_fs(oldfs);
64354
64355 err = compat_put_timex(utp, &txc);
64356 @@ -718,7 +719,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
64357 oldfs = get_fs();
64358 set_fs(KERNEL_DS);
64359 err = sys_clock_getres(which_clock,
64360 - (struct timespec __user *) &ts);
64361 + (struct timespec __force_user *) &ts);
64362 set_fs(oldfs);
64363 if (!err && tp && put_compat_timespec(&ts, tp))
64364 return -EFAULT;
64365 @@ -730,9 +731,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
64366 long err;
64367 mm_segment_t oldfs;
64368 struct timespec tu;
64369 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
64370 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
64371
64372 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
64373 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
64374 oldfs = get_fs();
64375 set_fs(KERNEL_DS);
64376 err = clock_nanosleep_restart(restart);
64377 @@ -764,8 +765,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
64378 oldfs = get_fs();
64379 set_fs(KERNEL_DS);
64380 err = sys_clock_nanosleep(which_clock, flags,
64381 - (struct timespec __user *) &in,
64382 - (struct timespec __user *) &out);
64383 + (struct timespec __force_user *) &in,
64384 + (struct timespec __force_user *) &out);
64385 set_fs(oldfs);
64386
64387 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
64388 diff --git a/kernel/configs.c b/kernel/configs.c
64389 index 42e8fa0..9e7406b 100644
64390 --- a/kernel/configs.c
64391 +++ b/kernel/configs.c
64392 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
64393 struct proc_dir_entry *entry;
64394
64395 /* create the current config file */
64396 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64397 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
64398 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
64399 + &ikconfig_file_ops);
64400 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64401 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
64402 + &ikconfig_file_ops);
64403 +#endif
64404 +#else
64405 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
64406 &ikconfig_file_ops);
64407 +#endif
64408 +
64409 if (!entry)
64410 return -ENOMEM;
64411
64412 diff --git a/kernel/cred.c b/kernel/cred.c
64413 index 5791612..a3c04dc 100644
64414 --- a/kernel/cred.c
64415 +++ b/kernel/cred.c
64416 @@ -204,6 +204,15 @@ void exit_creds(struct task_struct *tsk)
64417 validate_creds(cred);
64418 put_cred(cred);
64419 }
64420 +
64421 +#ifdef CONFIG_GRKERNSEC_SETXID
64422 + cred = (struct cred *) tsk->delayed_cred;
64423 + if (cred) {
64424 + tsk->delayed_cred = NULL;
64425 + validate_creds(cred);
64426 + put_cred(cred);
64427 + }
64428 +#endif
64429 }
64430
64431 /**
64432 @@ -470,7 +479,7 @@ error_put:
64433 * Always returns 0 thus allowing this function to be tail-called at the end
64434 * of, say, sys_setgid().
64435 */
64436 -int commit_creds(struct cred *new)
64437 +static int __commit_creds(struct cred *new)
64438 {
64439 struct task_struct *task = current;
64440 const struct cred *old = task->real_cred;
64441 @@ -489,6 +498,8 @@ int commit_creds(struct cred *new)
64442
64443 get_cred(new); /* we will require a ref for the subj creds too */
64444
64445 + gr_set_role_label(task, new->uid, new->gid);
64446 +
64447 /* dumpability changes */
64448 if (old->euid != new->euid ||
64449 old->egid != new->egid ||
64450 @@ -538,6 +549,92 @@ int commit_creds(struct cred *new)
64451 put_cred(old);
64452 return 0;
64453 }
64454 +#ifdef CONFIG_GRKERNSEC_SETXID
64455 +extern int set_user(struct cred *new);
64456 +
64457 +void gr_delayed_cred_worker(void)
64458 +{
64459 + const struct cred *new = current->delayed_cred;
64460 + struct cred *ncred;
64461 +
64462 + current->delayed_cred = NULL;
64463 +
64464 + if (current_uid() && new != NULL) {
64465 + // from doing get_cred on it when queueing this
64466 + put_cred(new);
64467 + return;
64468 + } else if (new == NULL)
64469 + return;
64470 +
64471 + ncred = prepare_creds();
64472 + if (!ncred)
64473 + goto die;
64474 + // uids
64475 + ncred->uid = new->uid;
64476 + ncred->euid = new->euid;
64477 + ncred->suid = new->suid;
64478 + ncred->fsuid = new->fsuid;
64479 + // gids
64480 + ncred->gid = new->gid;
64481 + ncred->egid = new->egid;
64482 + ncred->sgid = new->sgid;
64483 + ncred->fsgid = new->fsgid;
64484 + // groups
64485 + if (set_groups(ncred, new->group_info) < 0) {
64486 + abort_creds(ncred);
64487 + goto die;
64488 + }
64489 + // caps
64490 + ncred->securebits = new->securebits;
64491 + ncred->cap_inheritable = new->cap_inheritable;
64492 + ncred->cap_permitted = new->cap_permitted;
64493 + ncred->cap_effective = new->cap_effective;
64494 + ncred->cap_bset = new->cap_bset;
64495 +
64496 + if (set_user(ncred)) {
64497 + abort_creds(ncred);
64498 + goto die;
64499 + }
64500 +
64501 + // from doing get_cred on it when queueing this
64502 + put_cred(new);
64503 +
64504 + __commit_creds(ncred);
64505 + return;
64506 +die:
64507 + // from doing get_cred on it when queueing this
64508 + put_cred(new);
64509 + do_group_exit(SIGKILL);
64510 +}
64511 +#endif
64512 +
64513 +int commit_creds(struct cred *new)
64514 +{
64515 +#ifdef CONFIG_GRKERNSEC_SETXID
64516 + struct task_struct *t;
64517 +
64518 + /* we won't get called with tasklist_lock held for writing
64519 + and interrupts disabled as the cred struct in that case is
64520 + init_cred
64521 + */
64522 + if (grsec_enable_setxid && !current_is_single_threaded() &&
64523 + !current_uid() && new->uid) {
64524 + rcu_read_lock();
64525 + read_lock(&tasklist_lock);
64526 + for (t = next_thread(current); t != current;
64527 + t = next_thread(t)) {
64528 + if (t->delayed_cred == NULL) {
64529 + t->delayed_cred = get_cred(new);
64530 + set_tsk_need_resched(t);
64531 + }
64532 + }
64533 + read_unlock(&tasklist_lock);
64534 + rcu_read_unlock();
64535 + }
64536 +#endif
64537 + return __commit_creds(new);
64538 +}
64539 +
64540 EXPORT_SYMBOL(commit_creds);
64541
64542 /**
64543 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
64544 index 0d7c087..01b8cef 100644
64545 --- a/kernel/debug/debug_core.c
64546 +++ b/kernel/debug/debug_core.c
64547 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
64548 */
64549 static atomic_t masters_in_kgdb;
64550 static atomic_t slaves_in_kgdb;
64551 -static atomic_t kgdb_break_tasklet_var;
64552 +static atomic_unchecked_t kgdb_break_tasklet_var;
64553 atomic_t kgdb_setting_breakpoint;
64554
64555 struct task_struct *kgdb_usethread;
64556 @@ -129,7 +129,7 @@ int kgdb_single_step;
64557 static pid_t kgdb_sstep_pid;
64558
64559 /* to keep track of the CPU which is doing the single stepping*/
64560 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
64561 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
64562
64563 /*
64564 * If you are debugging a problem where roundup (the collection of
64565 @@ -542,7 +542,7 @@ return_normal:
64566 * kernel will only try for the value of sstep_tries before
64567 * giving up and continuing on.
64568 */
64569 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
64570 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
64571 (kgdb_info[cpu].task &&
64572 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
64573 atomic_set(&kgdb_active, -1);
64574 @@ -636,8 +636,8 @@ cpu_master_loop:
64575 }
64576
64577 kgdb_restore:
64578 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
64579 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
64580 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
64581 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
64582 if (kgdb_info[sstep_cpu].task)
64583 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
64584 else
64585 @@ -834,18 +834,18 @@ static void kgdb_unregister_callbacks(void)
64586 static void kgdb_tasklet_bpt(unsigned long ing)
64587 {
64588 kgdb_breakpoint();
64589 - atomic_set(&kgdb_break_tasklet_var, 0);
64590 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
64591 }
64592
64593 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
64594
64595 void kgdb_schedule_breakpoint(void)
64596 {
64597 - if (atomic_read(&kgdb_break_tasklet_var) ||
64598 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
64599 atomic_read(&kgdb_active) != -1 ||
64600 atomic_read(&kgdb_setting_breakpoint))
64601 return;
64602 - atomic_inc(&kgdb_break_tasklet_var);
64603 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
64604 tasklet_schedule(&kgdb_tasklet_breakpoint);
64605 }
64606 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
64607 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
64608 index 63786e7..0780cac 100644
64609 --- a/kernel/debug/kdb/kdb_main.c
64610 +++ b/kernel/debug/kdb/kdb_main.c
64611 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
64612 list_for_each_entry(mod, kdb_modules, list) {
64613
64614 kdb_printf("%-20s%8u 0x%p ", mod->name,
64615 - mod->core_size, (void *)mod);
64616 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
64617 #ifdef CONFIG_MODULE_UNLOAD
64618 kdb_printf("%4d ", module_refcount(mod));
64619 #endif
64620 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
64621 kdb_printf(" (Loading)");
64622 else
64623 kdb_printf(" (Live)");
64624 - kdb_printf(" 0x%p", mod->module_core);
64625 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
64626
64627 #ifdef CONFIG_MODULE_UNLOAD
64628 {
64629 diff --git a/kernel/events/core.c b/kernel/events/core.c
64630 index 58690af..d903d75 100644
64631 --- a/kernel/events/core.c
64632 +++ b/kernel/events/core.c
64633 @@ -173,7 +173,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
64634 return 0;
64635 }
64636
64637 -static atomic64_t perf_event_id;
64638 +static atomic64_unchecked_t perf_event_id;
64639
64640 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
64641 enum event_type_t event_type);
64642 @@ -2540,7 +2540,7 @@ static void __perf_event_read(void *info)
64643
64644 static inline u64 perf_event_count(struct perf_event *event)
64645 {
64646 - return local64_read(&event->count) + atomic64_read(&event->child_count);
64647 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
64648 }
64649
64650 static u64 perf_event_read(struct perf_event *event)
64651 @@ -3065,9 +3065,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
64652 mutex_lock(&event->child_mutex);
64653 total += perf_event_read(event);
64654 *enabled += event->total_time_enabled +
64655 - atomic64_read(&event->child_total_time_enabled);
64656 + atomic64_read_unchecked(&event->child_total_time_enabled);
64657 *running += event->total_time_running +
64658 - atomic64_read(&event->child_total_time_running);
64659 + atomic64_read_unchecked(&event->child_total_time_running);
64660
64661 list_for_each_entry(child, &event->child_list, child_list) {
64662 total += perf_event_read(child);
64663 @@ -3474,10 +3474,10 @@ void perf_event_update_userpage(struct perf_event *event)
64664 userpg->offset -= local64_read(&event->hw.prev_count);
64665
64666 userpg->time_enabled = enabled +
64667 - atomic64_read(&event->child_total_time_enabled);
64668 + atomic64_read_unchecked(&event->child_total_time_enabled);
64669
64670 userpg->time_running = running +
64671 - atomic64_read(&event->child_total_time_running);
64672 + atomic64_read_unchecked(&event->child_total_time_running);
64673
64674 barrier();
64675 ++userpg->lock;
64676 @@ -3906,11 +3906,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
64677 values[n++] = perf_event_count(event);
64678 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
64679 values[n++] = enabled +
64680 - atomic64_read(&event->child_total_time_enabled);
64681 + atomic64_read_unchecked(&event->child_total_time_enabled);
64682 }
64683 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
64684 values[n++] = running +
64685 - atomic64_read(&event->child_total_time_running);
64686 + atomic64_read_unchecked(&event->child_total_time_running);
64687 }
64688 if (read_format & PERF_FORMAT_ID)
64689 values[n++] = primary_event_id(event);
64690 @@ -4561,12 +4561,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
64691 * need to add enough zero bytes after the string to handle
64692 * the 64bit alignment we do later.
64693 */
64694 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
64695 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
64696 if (!buf) {
64697 name = strncpy(tmp, "//enomem", sizeof(tmp));
64698 goto got_name;
64699 }
64700 - name = d_path(&file->f_path, buf, PATH_MAX);
64701 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
64702 if (IS_ERR(name)) {
64703 name = strncpy(tmp, "//toolong", sizeof(tmp));
64704 goto got_name;
64705 @@ -5921,7 +5921,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
64706 event->parent = parent_event;
64707
64708 event->ns = get_pid_ns(current->nsproxy->pid_ns);
64709 - event->id = atomic64_inc_return(&perf_event_id);
64710 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
64711
64712 event->state = PERF_EVENT_STATE_INACTIVE;
64713
64714 @@ -6443,10 +6443,10 @@ static void sync_child_event(struct perf_event *child_event,
64715 /*
64716 * Add back the child's count to the parent's count:
64717 */
64718 - atomic64_add(child_val, &parent_event->child_count);
64719 - atomic64_add(child_event->total_time_enabled,
64720 + atomic64_add_unchecked(child_val, &parent_event->child_count);
64721 + atomic64_add_unchecked(child_event->total_time_enabled,
64722 &parent_event->child_total_time_enabled);
64723 - atomic64_add(child_event->total_time_running,
64724 + atomic64_add_unchecked(child_event->total_time_running,
64725 &parent_event->child_total_time_running);
64726
64727 /*
64728 diff --git a/kernel/exit.c b/kernel/exit.c
64729 index e6e01b9..0a21b0a 100644
64730 --- a/kernel/exit.c
64731 +++ b/kernel/exit.c
64732 @@ -57,6 +57,10 @@
64733 #include <asm/pgtable.h>
64734 #include <asm/mmu_context.h>
64735
64736 +#ifdef CONFIG_GRKERNSEC
64737 +extern rwlock_t grsec_exec_file_lock;
64738 +#endif
64739 +
64740 static void exit_mm(struct task_struct * tsk);
64741
64742 static void __unhash_process(struct task_struct *p, bool group_dead)
64743 @@ -168,6 +172,10 @@ void release_task(struct task_struct * p)
64744 struct task_struct *leader;
64745 int zap_leader;
64746 repeat:
64747 +#ifdef CONFIG_NET
64748 + gr_del_task_from_ip_table(p);
64749 +#endif
64750 +
64751 /* don't need to get the RCU readlock here - the process is dead and
64752 * can't be modifying its own credentials. But shut RCU-lockdep up */
64753 rcu_read_lock();
64754 @@ -380,7 +388,7 @@ int allow_signal(int sig)
64755 * know it'll be handled, so that they don't get converted to
64756 * SIGKILL or just silently dropped.
64757 */
64758 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
64759 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
64760 recalc_sigpending();
64761 spin_unlock_irq(&current->sighand->siglock);
64762 return 0;
64763 @@ -416,6 +424,17 @@ void daemonize(const char *name, ...)
64764 vsnprintf(current->comm, sizeof(current->comm), name, args);
64765 va_end(args);
64766
64767 +#ifdef CONFIG_GRKERNSEC
64768 + write_lock(&grsec_exec_file_lock);
64769 + if (current->exec_file) {
64770 + fput(current->exec_file);
64771 + current->exec_file = NULL;
64772 + }
64773 + write_unlock(&grsec_exec_file_lock);
64774 +#endif
64775 +
64776 + gr_set_kernel_label(current);
64777 +
64778 /*
64779 * If we were started as result of loading a module, close all of the
64780 * user space pages. We don't need them, and if we didn't close them
64781 @@ -893,6 +912,8 @@ NORET_TYPE void do_exit(long code)
64782 struct task_struct *tsk = current;
64783 int group_dead;
64784
64785 + set_fs(USER_DS);
64786 +
64787 profile_task_exit(tsk);
64788
64789 WARN_ON(blk_needs_flush_plug(tsk));
64790 @@ -909,7 +930,6 @@ NORET_TYPE void do_exit(long code)
64791 * mm_release()->clear_child_tid() from writing to a user-controlled
64792 * kernel address.
64793 */
64794 - set_fs(USER_DS);
64795
64796 ptrace_event(PTRACE_EVENT_EXIT, code);
64797
64798 @@ -971,6 +991,9 @@ NORET_TYPE void do_exit(long code)
64799 tsk->exit_code = code;
64800 taskstats_exit(tsk, group_dead);
64801
64802 + gr_acl_handle_psacct(tsk, code);
64803 + gr_acl_handle_exit();
64804 +
64805 exit_mm(tsk);
64806
64807 if (group_dead)
64808 @@ -1068,7 +1091,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
64809 * Take down every thread in the group. This is called by fatal signals
64810 * as well as by sys_exit_group (below).
64811 */
64812 -NORET_TYPE void
64813 +__noreturn void
64814 do_group_exit(int exit_code)
64815 {
64816 struct signal_struct *sig = current->signal;
64817 diff --git a/kernel/fork.c b/kernel/fork.c
64818 index 0acf42c0..9e40e2e 100644
64819 --- a/kernel/fork.c
64820 +++ b/kernel/fork.c
64821 @@ -281,7 +281,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
64822 *stackend = STACK_END_MAGIC; /* for overflow detection */
64823
64824 #ifdef CONFIG_CC_STACKPROTECTOR
64825 - tsk->stack_canary = get_random_int();
64826 + tsk->stack_canary = pax_get_random_long();
64827 #endif
64828
64829 /*
64830 @@ -305,13 +305,77 @@ out:
64831 }
64832
64833 #ifdef CONFIG_MMU
64834 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
64835 +{
64836 + struct vm_area_struct *tmp;
64837 + unsigned long charge;
64838 + struct mempolicy *pol;
64839 + struct file *file;
64840 +
64841 + charge = 0;
64842 + if (mpnt->vm_flags & VM_ACCOUNT) {
64843 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
64844 + if (security_vm_enough_memory(len))
64845 + goto fail_nomem;
64846 + charge = len;
64847 + }
64848 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
64849 + if (!tmp)
64850 + goto fail_nomem;
64851 + *tmp = *mpnt;
64852 + tmp->vm_mm = mm;
64853 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
64854 + pol = mpol_dup(vma_policy(mpnt));
64855 + if (IS_ERR(pol))
64856 + goto fail_nomem_policy;
64857 + vma_set_policy(tmp, pol);
64858 + if (anon_vma_fork(tmp, mpnt))
64859 + goto fail_nomem_anon_vma_fork;
64860 + tmp->vm_flags &= ~VM_LOCKED;
64861 + tmp->vm_next = tmp->vm_prev = NULL;
64862 + tmp->vm_mirror = NULL;
64863 + file = tmp->vm_file;
64864 + if (file) {
64865 + struct inode *inode = file->f_path.dentry->d_inode;
64866 + struct address_space *mapping = file->f_mapping;
64867 +
64868 + get_file(file);
64869 + if (tmp->vm_flags & VM_DENYWRITE)
64870 + atomic_dec(&inode->i_writecount);
64871 + mutex_lock(&mapping->i_mmap_mutex);
64872 + if (tmp->vm_flags & VM_SHARED)
64873 + mapping->i_mmap_writable++;
64874 + flush_dcache_mmap_lock(mapping);
64875 + /* insert tmp into the share list, just after mpnt */
64876 + vma_prio_tree_add(tmp, mpnt);
64877 + flush_dcache_mmap_unlock(mapping);
64878 + mutex_unlock(&mapping->i_mmap_mutex);
64879 + }
64880 +
64881 + /*
64882 + * Clear hugetlb-related page reserves for children. This only
64883 + * affects MAP_PRIVATE mappings. Faults generated by the child
64884 + * are not guaranteed to succeed, even if read-only
64885 + */
64886 + if (is_vm_hugetlb_page(tmp))
64887 + reset_vma_resv_huge_pages(tmp);
64888 +
64889 + return tmp;
64890 +
64891 +fail_nomem_anon_vma_fork:
64892 + mpol_put(pol);
64893 +fail_nomem_policy:
64894 + kmem_cache_free(vm_area_cachep, tmp);
64895 +fail_nomem:
64896 + vm_unacct_memory(charge);
64897 + return NULL;
64898 +}
64899 +
64900 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
64901 {
64902 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
64903 struct rb_node **rb_link, *rb_parent;
64904 int retval;
64905 - unsigned long charge;
64906 - struct mempolicy *pol;
64907
64908 down_write(&oldmm->mmap_sem);
64909 flush_cache_dup_mm(oldmm);
64910 @@ -323,8 +387,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
64911 mm->locked_vm = 0;
64912 mm->mmap = NULL;
64913 mm->mmap_cache = NULL;
64914 - mm->free_area_cache = oldmm->mmap_base;
64915 - mm->cached_hole_size = ~0UL;
64916 + mm->free_area_cache = oldmm->free_area_cache;
64917 + mm->cached_hole_size = oldmm->cached_hole_size;
64918 mm->map_count = 0;
64919 cpumask_clear(mm_cpumask(mm));
64920 mm->mm_rb = RB_ROOT;
64921 @@ -340,8 +404,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
64922
64923 prev = NULL;
64924 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
64925 - struct file *file;
64926 -
64927 if (mpnt->vm_flags & VM_DONTCOPY) {
64928 long pages = vma_pages(mpnt);
64929 mm->total_vm -= pages;
64930 @@ -349,53 +411,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
64931 -pages);
64932 continue;
64933 }
64934 - charge = 0;
64935 - if (mpnt->vm_flags & VM_ACCOUNT) {
64936 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
64937 - if (security_vm_enough_memory(len))
64938 - goto fail_nomem;
64939 - charge = len;
64940 + tmp = dup_vma(mm, mpnt);
64941 + if (!tmp) {
64942 + retval = -ENOMEM;
64943 + goto out;
64944 }
64945 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
64946 - if (!tmp)
64947 - goto fail_nomem;
64948 - *tmp = *mpnt;
64949 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
64950 - pol = mpol_dup(vma_policy(mpnt));
64951 - retval = PTR_ERR(pol);
64952 - if (IS_ERR(pol))
64953 - goto fail_nomem_policy;
64954 - vma_set_policy(tmp, pol);
64955 - tmp->vm_mm = mm;
64956 - if (anon_vma_fork(tmp, mpnt))
64957 - goto fail_nomem_anon_vma_fork;
64958 - tmp->vm_flags &= ~VM_LOCKED;
64959 - tmp->vm_next = tmp->vm_prev = NULL;
64960 - file = tmp->vm_file;
64961 - if (file) {
64962 - struct inode *inode = file->f_path.dentry->d_inode;
64963 - struct address_space *mapping = file->f_mapping;
64964 -
64965 - get_file(file);
64966 - if (tmp->vm_flags & VM_DENYWRITE)
64967 - atomic_dec(&inode->i_writecount);
64968 - mutex_lock(&mapping->i_mmap_mutex);
64969 - if (tmp->vm_flags & VM_SHARED)
64970 - mapping->i_mmap_writable++;
64971 - flush_dcache_mmap_lock(mapping);
64972 - /* insert tmp into the share list, just after mpnt */
64973 - vma_prio_tree_add(tmp, mpnt);
64974 - flush_dcache_mmap_unlock(mapping);
64975 - mutex_unlock(&mapping->i_mmap_mutex);
64976 - }
64977 -
64978 - /*
64979 - * Clear hugetlb-related page reserves for children. This only
64980 - * affects MAP_PRIVATE mappings. Faults generated by the child
64981 - * are not guaranteed to succeed, even if read-only
64982 - */
64983 - if (is_vm_hugetlb_page(tmp))
64984 - reset_vma_resv_huge_pages(tmp);
64985
64986 /*
64987 * Link in the new vma and copy the page table entries.
64988 @@ -418,6 +438,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
64989 if (retval)
64990 goto out;
64991 }
64992 +
64993 +#ifdef CONFIG_PAX_SEGMEXEC
64994 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
64995 + struct vm_area_struct *mpnt_m;
64996 +
64997 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
64998 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
64999 +
65000 + if (!mpnt->vm_mirror)
65001 + continue;
65002 +
65003 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
65004 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
65005 + mpnt->vm_mirror = mpnt_m;
65006 + } else {
65007 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
65008 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
65009 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
65010 + mpnt->vm_mirror->vm_mirror = mpnt;
65011 + }
65012 + }
65013 + BUG_ON(mpnt_m);
65014 + }
65015 +#endif
65016 +
65017 /* a new mm has just been created */
65018 arch_dup_mmap(oldmm, mm);
65019 retval = 0;
65020 @@ -426,14 +471,6 @@ out:
65021 flush_tlb_mm(oldmm);
65022 up_write(&oldmm->mmap_sem);
65023 return retval;
65024 -fail_nomem_anon_vma_fork:
65025 - mpol_put(pol);
65026 -fail_nomem_policy:
65027 - kmem_cache_free(vm_area_cachep, tmp);
65028 -fail_nomem:
65029 - retval = -ENOMEM;
65030 - vm_unacct_memory(charge);
65031 - goto out;
65032 }
65033
65034 static inline int mm_alloc_pgd(struct mm_struct *mm)
65035 @@ -645,6 +682,26 @@ struct mm_struct *get_task_mm(struct task_struct *task)
65036 }
65037 EXPORT_SYMBOL_GPL(get_task_mm);
65038
65039 +struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
65040 +{
65041 + struct mm_struct *mm;
65042 + int err;
65043 +
65044 + err = mutex_lock_killable(&task->signal->cred_guard_mutex);
65045 + if (err)
65046 + return ERR_PTR(err);
65047 +
65048 + mm = get_task_mm(task);
65049 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
65050 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
65051 + mmput(mm);
65052 + mm = ERR_PTR(-EACCES);
65053 + }
65054 + mutex_unlock(&task->signal->cred_guard_mutex);
65055 +
65056 + return mm;
65057 +}
65058 +
65059 /* Please note the differences between mmput and mm_release.
65060 * mmput is called whenever we stop holding onto a mm_struct,
65061 * error success whatever.
65062 @@ -830,13 +887,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
65063 spin_unlock(&fs->lock);
65064 return -EAGAIN;
65065 }
65066 - fs->users++;
65067 + atomic_inc(&fs->users);
65068 spin_unlock(&fs->lock);
65069 return 0;
65070 }
65071 tsk->fs = copy_fs_struct(fs);
65072 if (!tsk->fs)
65073 return -ENOMEM;
65074 + gr_set_chroot_entries(tsk, &tsk->fs->root);
65075 return 0;
65076 }
65077
65078 @@ -1100,6 +1158,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
65079 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
65080 #endif
65081 retval = -EAGAIN;
65082 +
65083 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
65084 +
65085 if (atomic_read(&p->real_cred->user->processes) >=
65086 task_rlimit(p, RLIMIT_NPROC)) {
65087 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
65088 @@ -1259,6 +1320,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
65089 if (clone_flags & CLONE_THREAD)
65090 p->tgid = current->tgid;
65091
65092 + gr_copy_label(p);
65093 +
65094 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
65095 /*
65096 * Clear TID on mm_release()?
65097 @@ -1421,6 +1484,8 @@ bad_fork_cleanup_count:
65098 bad_fork_free:
65099 free_task(p);
65100 fork_out:
65101 + gr_log_forkfail(retval);
65102 +
65103 return ERR_PTR(retval);
65104 }
65105
65106 @@ -1521,6 +1586,8 @@ long do_fork(unsigned long clone_flags,
65107 if (clone_flags & CLONE_PARENT_SETTID)
65108 put_user(nr, parent_tidptr);
65109
65110 + gr_handle_brute_check();
65111 +
65112 if (clone_flags & CLONE_VFORK) {
65113 p->vfork_done = &vfork;
65114 init_completion(&vfork);
65115 @@ -1630,7 +1697,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
65116 return 0;
65117
65118 /* don't need lock here; in the worst case we'll do useless copy */
65119 - if (fs->users == 1)
65120 + if (atomic_read(&fs->users) == 1)
65121 return 0;
65122
65123 *new_fsp = copy_fs_struct(fs);
65124 @@ -1719,7 +1786,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
65125 fs = current->fs;
65126 spin_lock(&fs->lock);
65127 current->fs = new_fs;
65128 - if (--fs->users)
65129 + gr_set_chroot_entries(current, &current->fs->root);
65130 + if (atomic_dec_return(&fs->users))
65131 new_fs = NULL;
65132 else
65133 new_fs = fs;
65134 diff --git a/kernel/futex.c b/kernel/futex.c
65135 index 1614be2..37abc7e 100644
65136 --- a/kernel/futex.c
65137 +++ b/kernel/futex.c
65138 @@ -54,6 +54,7 @@
65139 #include <linux/mount.h>
65140 #include <linux/pagemap.h>
65141 #include <linux/syscalls.h>
65142 +#include <linux/ptrace.h>
65143 #include <linux/signal.h>
65144 #include <linux/export.h>
65145 #include <linux/magic.h>
65146 @@ -238,6 +239,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
65147 struct page *page, *page_head;
65148 int err, ro = 0;
65149
65150 +#ifdef CONFIG_PAX_SEGMEXEC
65151 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
65152 + return -EFAULT;
65153 +#endif
65154 +
65155 /*
65156 * The futex address must be "naturally" aligned.
65157 */
65158 @@ -2459,6 +2465,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
65159 if (!p)
65160 goto err_unlock;
65161 ret = -EPERM;
65162 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65163 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
65164 + goto err_unlock;
65165 +#endif
65166 pcred = __task_cred(p);
65167 /* If victim is in different user_ns, then uids are not
65168 comparable, so we must have CAP_SYS_PTRACE */
65169 @@ -2724,6 +2734,7 @@ static int __init futex_init(void)
65170 {
65171 u32 curval;
65172 int i;
65173 + mm_segment_t oldfs;
65174
65175 /*
65176 * This will fail and we want it. Some arch implementations do
65177 @@ -2735,8 +2746,11 @@ static int __init futex_init(void)
65178 * implementation, the non-functional ones will return
65179 * -ENOSYS.
65180 */
65181 + oldfs = get_fs();
65182 + set_fs(USER_DS);
65183 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
65184 futex_cmpxchg_enabled = 1;
65185 + set_fs(oldfs);
65186
65187 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
65188 plist_head_init(&futex_queues[i].chain);
65189 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
65190 index 5f9e689..582d46d 100644
65191 --- a/kernel/futex_compat.c
65192 +++ b/kernel/futex_compat.c
65193 @@ -10,6 +10,7 @@
65194 #include <linux/compat.h>
65195 #include <linux/nsproxy.h>
65196 #include <linux/futex.h>
65197 +#include <linux/ptrace.h>
65198
65199 #include <asm/uaccess.h>
65200
65201 @@ -136,7 +137,8 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
65202 {
65203 struct compat_robust_list_head __user *head;
65204 unsigned long ret;
65205 - const struct cred *cred = current_cred(), *pcred;
65206 + const struct cred *cred = current_cred();
65207 + const struct cred *pcred;
65208
65209 if (!futex_cmpxchg_enabled)
65210 return -ENOSYS;
65211 @@ -152,6 +154,10 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
65212 if (!p)
65213 goto err_unlock;
65214 ret = -EPERM;
65215 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65216 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
65217 + goto err_unlock;
65218 +#endif
65219 pcred = __task_cred(p);
65220 /* If victim is in different user_ns, then uids are not
65221 comparable, so we must have CAP_SYS_PTRACE */
65222 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
65223 index 9b22d03..6295b62 100644
65224 --- a/kernel/gcov/base.c
65225 +++ b/kernel/gcov/base.c
65226 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
65227 }
65228
65229 #ifdef CONFIG_MODULES
65230 -static inline int within(void *addr, void *start, unsigned long size)
65231 -{
65232 - return ((addr >= start) && (addr < start + size));
65233 -}
65234 -
65235 /* Update list and generate events when modules are unloaded. */
65236 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
65237 void *data)
65238 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
65239 prev = NULL;
65240 /* Remove entries located in module from linked list. */
65241 for (info = gcov_info_head; info; info = info->next) {
65242 - if (within(info, mod->module_core, mod->core_size)) {
65243 + if (within_module_core_rw((unsigned long)info, mod)) {
65244 if (prev)
65245 prev->next = info->next;
65246 else
65247 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
65248 index ae34bf5..4e2f3d0 100644
65249 --- a/kernel/hrtimer.c
65250 +++ b/kernel/hrtimer.c
65251 @@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
65252 local_irq_restore(flags);
65253 }
65254
65255 -static void run_hrtimer_softirq(struct softirq_action *h)
65256 +static void run_hrtimer_softirq(void)
65257 {
65258 hrtimer_peek_ahead_timers();
65259 }
65260 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
65261 index 66ff710..05a5128 100644
65262 --- a/kernel/jump_label.c
65263 +++ b/kernel/jump_label.c
65264 @@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
65265
65266 size = (((unsigned long)stop - (unsigned long)start)
65267 / sizeof(struct jump_entry));
65268 + pax_open_kernel();
65269 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
65270 + pax_close_kernel();
65271 }
65272
65273 static void jump_label_update(struct jump_label_key *key, int enable);
65274 @@ -303,10 +305,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
65275 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
65276 struct jump_entry *iter;
65277
65278 + pax_open_kernel();
65279 for (iter = iter_start; iter < iter_stop; iter++) {
65280 if (within_module_init(iter->code, mod))
65281 iter->code = 0;
65282 }
65283 + pax_close_kernel();
65284 }
65285
65286 static int
65287 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
65288 index 079f1d3..a407562 100644
65289 --- a/kernel/kallsyms.c
65290 +++ b/kernel/kallsyms.c
65291 @@ -11,6 +11,9 @@
65292 * Changed the compression method from stem compression to "table lookup"
65293 * compression (see scripts/kallsyms.c for a more complete description)
65294 */
65295 +#ifdef CONFIG_GRKERNSEC_HIDESYM
65296 +#define __INCLUDED_BY_HIDESYM 1
65297 +#endif
65298 #include <linux/kallsyms.h>
65299 #include <linux/module.h>
65300 #include <linux/init.h>
65301 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
65302
65303 static inline int is_kernel_inittext(unsigned long addr)
65304 {
65305 + if (system_state != SYSTEM_BOOTING)
65306 + return 0;
65307 +
65308 if (addr >= (unsigned long)_sinittext
65309 && addr <= (unsigned long)_einittext)
65310 return 1;
65311 return 0;
65312 }
65313
65314 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65315 +#ifdef CONFIG_MODULES
65316 +static inline int is_module_text(unsigned long addr)
65317 +{
65318 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
65319 + return 1;
65320 +
65321 + addr = ktla_ktva(addr);
65322 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
65323 +}
65324 +#else
65325 +static inline int is_module_text(unsigned long addr)
65326 +{
65327 + return 0;
65328 +}
65329 +#endif
65330 +#endif
65331 +
65332 static inline int is_kernel_text(unsigned long addr)
65333 {
65334 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
65335 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
65336
65337 static inline int is_kernel(unsigned long addr)
65338 {
65339 +
65340 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65341 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
65342 + return 1;
65343 +
65344 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
65345 +#else
65346 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
65347 +#endif
65348 +
65349 return 1;
65350 return in_gate_area_no_mm(addr);
65351 }
65352
65353 static int is_ksym_addr(unsigned long addr)
65354 {
65355 +
65356 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65357 + if (is_module_text(addr))
65358 + return 0;
65359 +#endif
65360 +
65361 if (all_var)
65362 return is_kernel(addr);
65363
65364 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
65365
65366 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
65367 {
65368 - iter->name[0] = '\0';
65369 iter->nameoff = get_symbol_offset(new_pos);
65370 iter->pos = new_pos;
65371 }
65372 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
65373 {
65374 struct kallsym_iter *iter = m->private;
65375
65376 +#ifdef CONFIG_GRKERNSEC_HIDESYM
65377 + if (current_uid())
65378 + return 0;
65379 +#endif
65380 +
65381 /* Some debugging symbols have no name. Ignore them. */
65382 if (!iter->name[0])
65383 return 0;
65384 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
65385 struct kallsym_iter *iter;
65386 int ret;
65387
65388 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
65389 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
65390 if (!iter)
65391 return -ENOMEM;
65392 reset_iter(iter, 0);
65393 diff --git a/kernel/kexec.c b/kernel/kexec.c
65394 index dc7bc08..4601964 100644
65395 --- a/kernel/kexec.c
65396 +++ b/kernel/kexec.c
65397 @@ -1048,7 +1048,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
65398 unsigned long flags)
65399 {
65400 struct compat_kexec_segment in;
65401 - struct kexec_segment out, __user *ksegments;
65402 + struct kexec_segment out;
65403 + struct kexec_segment __user *ksegments;
65404 unsigned long i, result;
65405
65406 /* Don't allow clients that don't understand the native
65407 diff --git a/kernel/kmod.c b/kernel/kmod.c
65408 index a4bea97..7a1ae9a 100644
65409 --- a/kernel/kmod.c
65410 +++ b/kernel/kmod.c
65411 @@ -73,13 +73,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
65412 * If module auto-loading support is disabled then this function
65413 * becomes a no-operation.
65414 */
65415 -int __request_module(bool wait, const char *fmt, ...)
65416 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
65417 {
65418 - va_list args;
65419 char module_name[MODULE_NAME_LEN];
65420 unsigned int max_modprobes;
65421 int ret;
65422 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
65423 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
65424 static char *envp[] = { "HOME=/",
65425 "TERM=linux",
65426 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
65427 @@ -88,9 +87,7 @@ int __request_module(bool wait, const char *fmt, ...)
65428 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
65429 static int kmod_loop_msg;
65430
65431 - va_start(args, fmt);
65432 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
65433 - va_end(args);
65434 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
65435 if (ret >= MODULE_NAME_LEN)
65436 return -ENAMETOOLONG;
65437
65438 @@ -98,6 +95,20 @@ int __request_module(bool wait, const char *fmt, ...)
65439 if (ret)
65440 return ret;
65441
65442 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
65443 + if (!current_uid()) {
65444 + /* hack to workaround consolekit/udisks stupidity */
65445 + read_lock(&tasklist_lock);
65446 + if (!strcmp(current->comm, "mount") &&
65447 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
65448 + read_unlock(&tasklist_lock);
65449 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
65450 + return -EPERM;
65451 + }
65452 + read_unlock(&tasklist_lock);
65453 + }
65454 +#endif
65455 +
65456 /* If modprobe needs a service that is in a module, we get a recursive
65457 * loop. Limit the number of running kmod threads to max_threads/2 or
65458 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
65459 @@ -133,6 +144,47 @@ int __request_module(bool wait, const char *fmt, ...)
65460 atomic_dec(&kmod_concurrent);
65461 return ret;
65462 }
65463 +
65464 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
65465 +{
65466 + va_list args;
65467 + int ret;
65468 +
65469 + va_start(args, fmt);
65470 + ret = ____request_module(wait, module_param, fmt, args);
65471 + va_end(args);
65472 +
65473 + return ret;
65474 +}
65475 +
65476 +int __request_module(bool wait, const char *fmt, ...)
65477 +{
65478 + va_list args;
65479 + int ret;
65480 +
65481 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
65482 + if (current_uid()) {
65483 + char module_param[MODULE_NAME_LEN];
65484 +
65485 + memset(module_param, 0, sizeof(module_param));
65486 +
65487 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
65488 +
65489 + va_start(args, fmt);
65490 + ret = ____request_module(wait, module_param, fmt, args);
65491 + va_end(args);
65492 +
65493 + return ret;
65494 + }
65495 +#endif
65496 +
65497 + va_start(args, fmt);
65498 + ret = ____request_module(wait, NULL, fmt, args);
65499 + va_end(args);
65500 +
65501 + return ret;
65502 +}
65503 +
65504 EXPORT_SYMBOL(__request_module);
65505 #endif /* CONFIG_MODULES */
65506
65507 @@ -222,7 +274,7 @@ static int wait_for_helper(void *data)
65508 *
65509 * Thus the __user pointer cast is valid here.
65510 */
65511 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
65512 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
65513
65514 /*
65515 * If ret is 0, either ____call_usermodehelper failed and the
65516 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
65517 index faa39d1..d7ad37e 100644
65518 --- a/kernel/kprobes.c
65519 +++ b/kernel/kprobes.c
65520 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
65521 * kernel image and loaded module images reside. This is required
65522 * so x86_64 can correctly handle the %rip-relative fixups.
65523 */
65524 - kip->insns = module_alloc(PAGE_SIZE);
65525 + kip->insns = module_alloc_exec(PAGE_SIZE);
65526 if (!kip->insns) {
65527 kfree(kip);
65528 return NULL;
65529 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
65530 */
65531 if (!list_is_singular(&kip->list)) {
65532 list_del(&kip->list);
65533 - module_free(NULL, kip->insns);
65534 + module_free_exec(NULL, kip->insns);
65535 kfree(kip);
65536 }
65537 return 1;
65538 @@ -1953,7 +1953,7 @@ static int __init init_kprobes(void)
65539 {
65540 int i, err = 0;
65541 unsigned long offset = 0, size = 0;
65542 - char *modname, namebuf[128];
65543 + char *modname, namebuf[KSYM_NAME_LEN];
65544 const char *symbol_name;
65545 void *addr;
65546 struct kprobe_blackpoint *kb;
65547 @@ -2079,7 +2079,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
65548 const char *sym = NULL;
65549 unsigned int i = *(loff_t *) v;
65550 unsigned long offset = 0;
65551 - char *modname, namebuf[128];
65552 + char *modname, namebuf[KSYM_NAME_LEN];
65553
65554 head = &kprobe_table[i];
65555 preempt_disable();
65556 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
65557 index b2e08c9..01d8049 100644
65558 --- a/kernel/lockdep.c
65559 +++ b/kernel/lockdep.c
65560 @@ -592,6 +592,10 @@ static int static_obj(void *obj)
65561 end = (unsigned long) &_end,
65562 addr = (unsigned long) obj;
65563
65564 +#ifdef CONFIG_PAX_KERNEXEC
65565 + start = ktla_ktva(start);
65566 +#endif
65567 +
65568 /*
65569 * static variable?
65570 */
65571 @@ -731,6 +735,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
65572 if (!static_obj(lock->key)) {
65573 debug_locks_off();
65574 printk("INFO: trying to register non-static key.\n");
65575 + printk("lock:%pS key:%pS.\n", lock, lock->key);
65576 printk("the code is fine but needs lockdep annotation.\n");
65577 printk("turning off the locking correctness validator.\n");
65578 dump_stack();
65579 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
65580 if (!class)
65581 return 0;
65582 }
65583 - atomic_inc((atomic_t *)&class->ops);
65584 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
65585 if (very_verbose(class)) {
65586 printk("\nacquire class [%p] %s", class->key, class->name);
65587 if (class->name_version > 1)
65588 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
65589 index 91c32a0..b2c71c5 100644
65590 --- a/kernel/lockdep_proc.c
65591 +++ b/kernel/lockdep_proc.c
65592 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
65593
65594 static void print_name(struct seq_file *m, struct lock_class *class)
65595 {
65596 - char str[128];
65597 + char str[KSYM_NAME_LEN];
65598 const char *name = class->name;
65599
65600 if (!name) {
65601 diff --git a/kernel/module.c b/kernel/module.c
65602 index 178333c..04e3408 100644
65603 --- a/kernel/module.c
65604 +++ b/kernel/module.c
65605 @@ -58,6 +58,7 @@
65606 #include <linux/jump_label.h>
65607 #include <linux/pfn.h>
65608 #include <linux/bsearch.h>
65609 +#include <linux/grsecurity.h>
65610
65611 #define CREATE_TRACE_POINTS
65612 #include <trace/events/module.h>
65613 @@ -119,7 +120,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
65614
65615 /* Bounds of module allocation, for speeding __module_address.
65616 * Protected by module_mutex. */
65617 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
65618 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
65619 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
65620
65621 int register_module_notifier(struct notifier_block * nb)
65622 {
65623 @@ -284,7 +286,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
65624 return true;
65625
65626 list_for_each_entry_rcu(mod, &modules, list) {
65627 - struct symsearch arr[] = {
65628 + struct symsearch modarr[] = {
65629 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
65630 NOT_GPL_ONLY, false },
65631 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
65632 @@ -306,7 +308,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
65633 #endif
65634 };
65635
65636 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
65637 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
65638 return true;
65639 }
65640 return false;
65641 @@ -438,7 +440,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
65642 static int percpu_modalloc(struct module *mod,
65643 unsigned long size, unsigned long align)
65644 {
65645 - if (align > PAGE_SIZE) {
65646 + if (align-1 >= PAGE_SIZE) {
65647 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
65648 mod->name, align, PAGE_SIZE);
65649 align = PAGE_SIZE;
65650 @@ -1183,7 +1185,7 @@ resolve_symbol_wait(struct module *mod,
65651 */
65652 #ifdef CONFIG_SYSFS
65653
65654 -#ifdef CONFIG_KALLSYMS
65655 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65656 static inline bool sect_empty(const Elf_Shdr *sect)
65657 {
65658 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
65659 @@ -1649,21 +1651,21 @@ static void set_section_ro_nx(void *base,
65660
65661 static void unset_module_core_ro_nx(struct module *mod)
65662 {
65663 - set_page_attributes(mod->module_core + mod->core_text_size,
65664 - mod->module_core + mod->core_size,
65665 + set_page_attributes(mod->module_core_rw,
65666 + mod->module_core_rw + mod->core_size_rw,
65667 set_memory_x);
65668 - set_page_attributes(mod->module_core,
65669 - mod->module_core + mod->core_ro_size,
65670 + set_page_attributes(mod->module_core_rx,
65671 + mod->module_core_rx + mod->core_size_rx,
65672 set_memory_rw);
65673 }
65674
65675 static void unset_module_init_ro_nx(struct module *mod)
65676 {
65677 - set_page_attributes(mod->module_init + mod->init_text_size,
65678 - mod->module_init + mod->init_size,
65679 + set_page_attributes(mod->module_init_rw,
65680 + mod->module_init_rw + mod->init_size_rw,
65681 set_memory_x);
65682 - set_page_attributes(mod->module_init,
65683 - mod->module_init + mod->init_ro_size,
65684 + set_page_attributes(mod->module_init_rx,
65685 + mod->module_init_rx + mod->init_size_rx,
65686 set_memory_rw);
65687 }
65688
65689 @@ -1674,14 +1676,14 @@ void set_all_modules_text_rw(void)
65690
65691 mutex_lock(&module_mutex);
65692 list_for_each_entry_rcu(mod, &modules, list) {
65693 - if ((mod->module_core) && (mod->core_text_size)) {
65694 - set_page_attributes(mod->module_core,
65695 - mod->module_core + mod->core_text_size,
65696 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
65697 + set_page_attributes(mod->module_core_rx,
65698 + mod->module_core_rx + mod->core_size_rx,
65699 set_memory_rw);
65700 }
65701 - if ((mod->module_init) && (mod->init_text_size)) {
65702 - set_page_attributes(mod->module_init,
65703 - mod->module_init + mod->init_text_size,
65704 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
65705 + set_page_attributes(mod->module_init_rx,
65706 + mod->module_init_rx + mod->init_size_rx,
65707 set_memory_rw);
65708 }
65709 }
65710 @@ -1695,14 +1697,14 @@ void set_all_modules_text_ro(void)
65711
65712 mutex_lock(&module_mutex);
65713 list_for_each_entry_rcu(mod, &modules, list) {
65714 - if ((mod->module_core) && (mod->core_text_size)) {
65715 - set_page_attributes(mod->module_core,
65716 - mod->module_core + mod->core_text_size,
65717 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
65718 + set_page_attributes(mod->module_core_rx,
65719 + mod->module_core_rx + mod->core_size_rx,
65720 set_memory_ro);
65721 }
65722 - if ((mod->module_init) && (mod->init_text_size)) {
65723 - set_page_attributes(mod->module_init,
65724 - mod->module_init + mod->init_text_size,
65725 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
65726 + set_page_attributes(mod->module_init_rx,
65727 + mod->module_init_rx + mod->init_size_rx,
65728 set_memory_ro);
65729 }
65730 }
65731 @@ -1748,16 +1750,19 @@ static void free_module(struct module *mod)
65732
65733 /* This may be NULL, but that's OK */
65734 unset_module_init_ro_nx(mod);
65735 - module_free(mod, mod->module_init);
65736 + module_free(mod, mod->module_init_rw);
65737 + module_free_exec(mod, mod->module_init_rx);
65738 kfree(mod->args);
65739 percpu_modfree(mod);
65740
65741 /* Free lock-classes: */
65742 - lockdep_free_key_range(mod->module_core, mod->core_size);
65743 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
65744 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
65745
65746 /* Finally, free the core (containing the module structure) */
65747 unset_module_core_ro_nx(mod);
65748 - module_free(mod, mod->module_core);
65749 + module_free_exec(mod, mod->module_core_rx);
65750 + module_free(mod, mod->module_core_rw);
65751
65752 #ifdef CONFIG_MPU
65753 update_protections(current->mm);
65754 @@ -1826,10 +1831,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
65755 unsigned int i;
65756 int ret = 0;
65757 const struct kernel_symbol *ksym;
65758 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
65759 + int is_fs_load = 0;
65760 + int register_filesystem_found = 0;
65761 + char *p;
65762 +
65763 + p = strstr(mod->args, "grsec_modharden_fs");
65764 + if (p) {
65765 + char *endptr = p + strlen("grsec_modharden_fs");
65766 + /* copy \0 as well */
65767 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
65768 + is_fs_load = 1;
65769 + }
65770 +#endif
65771
65772 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
65773 const char *name = info->strtab + sym[i].st_name;
65774
65775 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
65776 + /* it's a real shame this will never get ripped and copied
65777 + upstream! ;(
65778 + */
65779 + if (is_fs_load && !strcmp(name, "register_filesystem"))
65780 + register_filesystem_found = 1;
65781 +#endif
65782 +
65783 switch (sym[i].st_shndx) {
65784 case SHN_COMMON:
65785 /* We compiled with -fno-common. These are not
65786 @@ -1850,7 +1876,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
65787 ksym = resolve_symbol_wait(mod, info, name);
65788 /* Ok if resolved. */
65789 if (ksym && !IS_ERR(ksym)) {
65790 + pax_open_kernel();
65791 sym[i].st_value = ksym->value;
65792 + pax_close_kernel();
65793 break;
65794 }
65795
65796 @@ -1869,11 +1897,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
65797 secbase = (unsigned long)mod_percpu(mod);
65798 else
65799 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
65800 + pax_open_kernel();
65801 sym[i].st_value += secbase;
65802 + pax_close_kernel();
65803 break;
65804 }
65805 }
65806
65807 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
65808 + if (is_fs_load && !register_filesystem_found) {
65809 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
65810 + ret = -EPERM;
65811 + }
65812 +#endif
65813 +
65814 return ret;
65815 }
65816
65817 @@ -1977,22 +2014,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
65818 || s->sh_entsize != ~0UL
65819 || strstarts(sname, ".init"))
65820 continue;
65821 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
65822 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
65823 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
65824 + else
65825 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
65826 DEBUGP("\t%s\n", name);
65827 }
65828 - switch (m) {
65829 - case 0: /* executable */
65830 - mod->core_size = debug_align(mod->core_size);
65831 - mod->core_text_size = mod->core_size;
65832 - break;
65833 - case 1: /* RO: text and ro-data */
65834 - mod->core_size = debug_align(mod->core_size);
65835 - mod->core_ro_size = mod->core_size;
65836 - break;
65837 - case 3: /* whole core */
65838 - mod->core_size = debug_align(mod->core_size);
65839 - break;
65840 - }
65841 }
65842
65843 DEBUGP("Init section allocation order:\n");
65844 @@ -2006,23 +2033,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
65845 || s->sh_entsize != ~0UL
65846 || !strstarts(sname, ".init"))
65847 continue;
65848 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
65849 - | INIT_OFFSET_MASK);
65850 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
65851 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
65852 + else
65853 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
65854 + s->sh_entsize |= INIT_OFFSET_MASK;
65855 DEBUGP("\t%s\n", sname);
65856 }
65857 - switch (m) {
65858 - case 0: /* executable */
65859 - mod->init_size = debug_align(mod->init_size);
65860 - mod->init_text_size = mod->init_size;
65861 - break;
65862 - case 1: /* RO: text and ro-data */
65863 - mod->init_size = debug_align(mod->init_size);
65864 - mod->init_ro_size = mod->init_size;
65865 - break;
65866 - case 3: /* whole init */
65867 - mod->init_size = debug_align(mod->init_size);
65868 - break;
65869 - }
65870 }
65871 }
65872
65873 @@ -2187,7 +2204,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
65874
65875 /* Put symbol section at end of init part of module. */
65876 symsect->sh_flags |= SHF_ALLOC;
65877 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
65878 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
65879 info->index.sym) | INIT_OFFSET_MASK;
65880 DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
65881
65882 @@ -2204,19 +2221,19 @@ static void layout_symtab(struct module *mod, struct load_info *info)
65883 }
65884
65885 /* Append room for core symbols at end of core part. */
65886 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
65887 - mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
65888 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
65889 + mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
65890
65891 /* Put string table section at end of init part of module. */
65892 strsect->sh_flags |= SHF_ALLOC;
65893 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
65894 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
65895 info->index.str) | INIT_OFFSET_MASK;
65896 DEBUGP("\t%s\n", info->secstrings + strsect->sh_name);
65897
65898 /* Append room for core symbols' strings at end of core part. */
65899 - info->stroffs = mod->core_size;
65900 + info->stroffs = mod->core_size_rx;
65901 __set_bit(0, info->strmap);
65902 - mod->core_size += bitmap_weight(info->strmap, strsect->sh_size);
65903 + mod->core_size_rx += bitmap_weight(info->strmap, strsect->sh_size);
65904 }
65905
65906 static void add_kallsyms(struct module *mod, const struct load_info *info)
65907 @@ -2232,11 +2249,13 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
65908 /* Make sure we get permanent strtab: don't use info->strtab. */
65909 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
65910
65911 + pax_open_kernel();
65912 +
65913 /* Set types up while we still have access to sections. */
65914 for (i = 0; i < mod->num_symtab; i++)
65915 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
65916
65917 - mod->core_symtab = dst = mod->module_core + info->symoffs;
65918 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
65919 src = mod->symtab;
65920 *dst = *src;
65921 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
65922 @@ -2249,10 +2268,12 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
65923 }
65924 mod->core_num_syms = ndst;
65925
65926 - mod->core_strtab = s = mod->module_core + info->stroffs;
65927 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
65928 for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i)
65929 if (test_bit(i, info->strmap))
65930 *++s = mod->strtab[i];
65931 +
65932 + pax_close_kernel();
65933 }
65934 #else
65935 static inline void layout_symtab(struct module *mod, struct load_info *info)
65936 @@ -2286,17 +2307,33 @@ void * __weak module_alloc(unsigned long size)
65937 return size == 0 ? NULL : vmalloc_exec(size);
65938 }
65939
65940 -static void *module_alloc_update_bounds(unsigned long size)
65941 +static void *module_alloc_update_bounds_rw(unsigned long size)
65942 {
65943 void *ret = module_alloc(size);
65944
65945 if (ret) {
65946 mutex_lock(&module_mutex);
65947 /* Update module bounds. */
65948 - if ((unsigned long)ret < module_addr_min)
65949 - module_addr_min = (unsigned long)ret;
65950 - if ((unsigned long)ret + size > module_addr_max)
65951 - module_addr_max = (unsigned long)ret + size;
65952 + if ((unsigned long)ret < module_addr_min_rw)
65953 + module_addr_min_rw = (unsigned long)ret;
65954 + if ((unsigned long)ret + size > module_addr_max_rw)
65955 + module_addr_max_rw = (unsigned long)ret + size;
65956 + mutex_unlock(&module_mutex);
65957 + }
65958 + return ret;
65959 +}
65960 +
65961 +static void *module_alloc_update_bounds_rx(unsigned long size)
65962 +{
65963 + void *ret = module_alloc_exec(size);
65964 +
65965 + if (ret) {
65966 + mutex_lock(&module_mutex);
65967 + /* Update module bounds. */
65968 + if ((unsigned long)ret < module_addr_min_rx)
65969 + module_addr_min_rx = (unsigned long)ret;
65970 + if ((unsigned long)ret + size > module_addr_max_rx)
65971 + module_addr_max_rx = (unsigned long)ret + size;
65972 mutex_unlock(&module_mutex);
65973 }
65974 return ret;
65975 @@ -2474,8 +2511,14 @@ static struct module *setup_load_info(struct load_info *info)
65976 static int check_modinfo(struct module *mod, struct load_info *info)
65977 {
65978 const char *modmagic = get_modinfo(info, "vermagic");
65979 + const char *license = get_modinfo(info, "license");
65980 int err;
65981
65982 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
65983 + if (!license || !license_is_gpl_compatible(license))
65984 + return -ENOEXEC;
65985 +#endif
65986 +
65987 /* This is allowed: modprobe --force will invalidate it. */
65988 if (!modmagic) {
65989 err = try_to_force_load(mod, "bad vermagic");
65990 @@ -2498,7 +2541,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
65991 }
65992
65993 /* Set up license info based on the info section */
65994 - set_license(mod, get_modinfo(info, "license"));
65995 + set_license(mod, license);
65996
65997 return 0;
65998 }
65999 @@ -2592,7 +2635,7 @@ static int move_module(struct module *mod, struct load_info *info)
66000 void *ptr;
66001
66002 /* Do the allocs. */
66003 - ptr = module_alloc_update_bounds(mod->core_size);
66004 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
66005 /*
66006 * The pointer to this block is stored in the module structure
66007 * which is inside the block. Just mark it as not being a
66008 @@ -2602,23 +2645,50 @@ static int move_module(struct module *mod, struct load_info *info)
66009 if (!ptr)
66010 return -ENOMEM;
66011
66012 - memset(ptr, 0, mod->core_size);
66013 - mod->module_core = ptr;
66014 + memset(ptr, 0, mod->core_size_rw);
66015 + mod->module_core_rw = ptr;
66016
66017 - ptr = module_alloc_update_bounds(mod->init_size);
66018 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
66019 /*
66020 * The pointer to this block is stored in the module structure
66021 * which is inside the block. This block doesn't need to be
66022 * scanned as it contains data and code that will be freed
66023 * after the module is initialized.
66024 */
66025 - kmemleak_ignore(ptr);
66026 - if (!ptr && mod->init_size) {
66027 - module_free(mod, mod->module_core);
66028 + kmemleak_not_leak(ptr);
66029 + if (!ptr && mod->init_size_rw) {
66030 + module_free(mod, mod->module_core_rw);
66031 return -ENOMEM;
66032 }
66033 - memset(ptr, 0, mod->init_size);
66034 - mod->module_init = ptr;
66035 + memset(ptr, 0, mod->init_size_rw);
66036 + mod->module_init_rw = ptr;
66037 +
66038 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
66039 + kmemleak_not_leak(ptr);
66040 + if (!ptr) {
66041 + module_free(mod, mod->module_init_rw);
66042 + module_free(mod, mod->module_core_rw);
66043 + return -ENOMEM;
66044 + }
66045 +
66046 + pax_open_kernel();
66047 + memset(ptr, 0, mod->core_size_rx);
66048 + pax_close_kernel();
66049 + mod->module_core_rx = ptr;
66050 +
66051 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
66052 + kmemleak_not_leak(ptr);
66053 + if (!ptr && mod->init_size_rx) {
66054 + module_free_exec(mod, mod->module_core_rx);
66055 + module_free(mod, mod->module_init_rw);
66056 + module_free(mod, mod->module_core_rw);
66057 + return -ENOMEM;
66058 + }
66059 +
66060 + pax_open_kernel();
66061 + memset(ptr, 0, mod->init_size_rx);
66062 + pax_close_kernel();
66063 + mod->module_init_rx = ptr;
66064
66065 /* Transfer each section which specifies SHF_ALLOC */
66066 DEBUGP("final section addresses:\n");
66067 @@ -2629,16 +2699,45 @@ static int move_module(struct module *mod, struct load_info *info)
66068 if (!(shdr->sh_flags & SHF_ALLOC))
66069 continue;
66070
66071 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
66072 - dest = mod->module_init
66073 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66074 - else
66075 - dest = mod->module_core + shdr->sh_entsize;
66076 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
66077 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
66078 + dest = mod->module_init_rw
66079 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66080 + else
66081 + dest = mod->module_init_rx
66082 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66083 + } else {
66084 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
66085 + dest = mod->module_core_rw + shdr->sh_entsize;
66086 + else
66087 + dest = mod->module_core_rx + shdr->sh_entsize;
66088 + }
66089 +
66090 + if (shdr->sh_type != SHT_NOBITS) {
66091 +
66092 +#ifdef CONFIG_PAX_KERNEXEC
66093 +#ifdef CONFIG_X86_64
66094 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
66095 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
66096 +#endif
66097 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
66098 + pax_open_kernel();
66099 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
66100 + pax_close_kernel();
66101 + } else
66102 +#endif
66103
66104 - if (shdr->sh_type != SHT_NOBITS)
66105 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
66106 + }
66107 /* Update sh_addr to point to copy in image. */
66108 - shdr->sh_addr = (unsigned long)dest;
66109 +
66110 +#ifdef CONFIG_PAX_KERNEXEC
66111 + if (shdr->sh_flags & SHF_EXECINSTR)
66112 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
66113 + else
66114 +#endif
66115 +
66116 + shdr->sh_addr = (unsigned long)dest;
66117 DEBUGP("\t0x%lx %s\n",
66118 shdr->sh_addr, info->secstrings + shdr->sh_name);
66119 }
66120 @@ -2689,12 +2788,12 @@ static void flush_module_icache(const struct module *mod)
66121 * Do it before processing of module parameters, so the module
66122 * can provide parameter accessor functions of its own.
66123 */
66124 - if (mod->module_init)
66125 - flush_icache_range((unsigned long)mod->module_init,
66126 - (unsigned long)mod->module_init
66127 - + mod->init_size);
66128 - flush_icache_range((unsigned long)mod->module_core,
66129 - (unsigned long)mod->module_core + mod->core_size);
66130 + if (mod->module_init_rx)
66131 + flush_icache_range((unsigned long)mod->module_init_rx,
66132 + (unsigned long)mod->module_init_rx
66133 + + mod->init_size_rx);
66134 + flush_icache_range((unsigned long)mod->module_core_rx,
66135 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
66136
66137 set_fs(old_fs);
66138 }
66139 @@ -2774,8 +2873,10 @@ static void module_deallocate(struct module *mod, struct load_info *info)
66140 {
66141 kfree(info->strmap);
66142 percpu_modfree(mod);
66143 - module_free(mod, mod->module_init);
66144 - module_free(mod, mod->module_core);
66145 + module_free_exec(mod, mod->module_init_rx);
66146 + module_free_exec(mod, mod->module_core_rx);
66147 + module_free(mod, mod->module_init_rw);
66148 + module_free(mod, mod->module_core_rw);
66149 }
66150
66151 int __weak module_finalize(const Elf_Ehdr *hdr,
66152 @@ -2839,9 +2940,38 @@ static struct module *load_module(void __user *umod,
66153 if (err)
66154 goto free_unload;
66155
66156 + /* Now copy in args */
66157 + mod->args = strndup_user(uargs, ~0UL >> 1);
66158 + if (IS_ERR(mod->args)) {
66159 + err = PTR_ERR(mod->args);
66160 + goto free_unload;
66161 + }
66162 +
66163 /* Set up MODINFO_ATTR fields */
66164 setup_modinfo(mod, &info);
66165
66166 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66167 + {
66168 + char *p, *p2;
66169 +
66170 + if (strstr(mod->args, "grsec_modharden_netdev")) {
66171 + 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);
66172 + err = -EPERM;
66173 + goto free_modinfo;
66174 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
66175 + p += strlen("grsec_modharden_normal");
66176 + p2 = strstr(p, "_");
66177 + if (p2) {
66178 + *p2 = '\0';
66179 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
66180 + *p2 = '_';
66181 + }
66182 + err = -EPERM;
66183 + goto free_modinfo;
66184 + }
66185 + }
66186 +#endif
66187 +
66188 /* Fix up syms, so that st_value is a pointer to location. */
66189 err = simplify_symbols(mod, &info);
66190 if (err < 0)
66191 @@ -2857,13 +2987,6 @@ static struct module *load_module(void __user *umod,
66192
66193 flush_module_icache(mod);
66194
66195 - /* Now copy in args */
66196 - mod->args = strndup_user(uargs, ~0UL >> 1);
66197 - if (IS_ERR(mod->args)) {
66198 - err = PTR_ERR(mod->args);
66199 - goto free_arch_cleanup;
66200 - }
66201 -
66202 /* Mark state as coming so strong_try_module_get() ignores us. */
66203 mod->state = MODULE_STATE_COMING;
66204
66205 @@ -2921,11 +3044,10 @@ static struct module *load_module(void __user *umod,
66206 unlock:
66207 mutex_unlock(&module_mutex);
66208 synchronize_sched();
66209 - kfree(mod->args);
66210 - free_arch_cleanup:
66211 module_arch_cleanup(mod);
66212 free_modinfo:
66213 free_modinfo(mod);
66214 + kfree(mod->args);
66215 free_unload:
66216 module_unload_free(mod);
66217 free_module:
66218 @@ -2966,16 +3088,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
66219 MODULE_STATE_COMING, mod);
66220
66221 /* Set RO and NX regions for core */
66222 - set_section_ro_nx(mod->module_core,
66223 - mod->core_text_size,
66224 - mod->core_ro_size,
66225 - mod->core_size);
66226 + set_section_ro_nx(mod->module_core_rx,
66227 + mod->core_size_rx,
66228 + mod->core_size_rx,
66229 + mod->core_size_rx);
66230
66231 /* Set RO and NX regions for init */
66232 - set_section_ro_nx(mod->module_init,
66233 - mod->init_text_size,
66234 - mod->init_ro_size,
66235 - mod->init_size);
66236 + set_section_ro_nx(mod->module_init_rx,
66237 + mod->init_size_rx,
66238 + mod->init_size_rx,
66239 + mod->init_size_rx);
66240
66241 do_mod_ctors(mod);
66242 /* Start the module */
66243 @@ -3021,11 +3143,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
66244 mod->strtab = mod->core_strtab;
66245 #endif
66246 unset_module_init_ro_nx(mod);
66247 - module_free(mod, mod->module_init);
66248 - mod->module_init = NULL;
66249 - mod->init_size = 0;
66250 - mod->init_ro_size = 0;
66251 - mod->init_text_size = 0;
66252 + module_free(mod, mod->module_init_rw);
66253 + module_free_exec(mod, mod->module_init_rx);
66254 + mod->module_init_rw = NULL;
66255 + mod->module_init_rx = NULL;
66256 + mod->init_size_rw = 0;
66257 + mod->init_size_rx = 0;
66258 mutex_unlock(&module_mutex);
66259
66260 return 0;
66261 @@ -3056,10 +3179,16 @@ static const char *get_ksymbol(struct module *mod,
66262 unsigned long nextval;
66263
66264 /* At worse, next value is at end of module */
66265 - if (within_module_init(addr, mod))
66266 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
66267 + if (within_module_init_rx(addr, mod))
66268 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
66269 + else if (within_module_init_rw(addr, mod))
66270 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
66271 + else if (within_module_core_rx(addr, mod))
66272 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
66273 + else if (within_module_core_rw(addr, mod))
66274 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
66275 else
66276 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
66277 + return NULL;
66278
66279 /* Scan for closest preceding symbol, and next symbol. (ELF
66280 starts real symbols at 1). */
66281 @@ -3307,7 +3436,7 @@ static int m_show(struct seq_file *m, void *p)
66282 char buf[8];
66283
66284 seq_printf(m, "%s %u",
66285 - mod->name, mod->init_size + mod->core_size);
66286 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
66287 print_unload_info(m, mod);
66288
66289 /* Informative for users. */
66290 @@ -3316,7 +3445,7 @@ static int m_show(struct seq_file *m, void *p)
66291 mod->state == MODULE_STATE_COMING ? "Loading":
66292 "Live");
66293 /* Used by oprofile and other similar tools. */
66294 - seq_printf(m, " 0x%pK", mod->module_core);
66295 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
66296
66297 /* Taints info */
66298 if (mod->taints)
66299 @@ -3352,7 +3481,17 @@ static const struct file_operations proc_modules_operations = {
66300
66301 static int __init proc_modules_init(void)
66302 {
66303 +#ifndef CONFIG_GRKERNSEC_HIDESYM
66304 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66305 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
66306 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66307 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
66308 +#else
66309 proc_create("modules", 0, NULL, &proc_modules_operations);
66310 +#endif
66311 +#else
66312 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
66313 +#endif
66314 return 0;
66315 }
66316 module_init(proc_modules_init);
66317 @@ -3411,12 +3550,12 @@ struct module *__module_address(unsigned long addr)
66318 {
66319 struct module *mod;
66320
66321 - if (addr < module_addr_min || addr > module_addr_max)
66322 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
66323 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
66324 return NULL;
66325
66326 list_for_each_entry_rcu(mod, &modules, list)
66327 - if (within_module_core(addr, mod)
66328 - || within_module_init(addr, mod))
66329 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
66330 return mod;
66331 return NULL;
66332 }
66333 @@ -3450,11 +3589,20 @@ bool is_module_text_address(unsigned long addr)
66334 */
66335 struct module *__module_text_address(unsigned long addr)
66336 {
66337 - struct module *mod = __module_address(addr);
66338 + struct module *mod;
66339 +
66340 +#ifdef CONFIG_X86_32
66341 + addr = ktla_ktva(addr);
66342 +#endif
66343 +
66344 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
66345 + return NULL;
66346 +
66347 + mod = __module_address(addr);
66348 +
66349 if (mod) {
66350 /* Make sure it's within the text section. */
66351 - if (!within(addr, mod->module_init, mod->init_text_size)
66352 - && !within(addr, mod->module_core, mod->core_text_size))
66353 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
66354 mod = NULL;
66355 }
66356 return mod;
66357 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
66358 index 7e3443f..b2a1e6b 100644
66359 --- a/kernel/mutex-debug.c
66360 +++ b/kernel/mutex-debug.c
66361 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
66362 }
66363
66364 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66365 - struct thread_info *ti)
66366 + struct task_struct *task)
66367 {
66368 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
66369
66370 /* Mark the current thread as blocked on the lock: */
66371 - ti->task->blocked_on = waiter;
66372 + task->blocked_on = waiter;
66373 }
66374
66375 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66376 - struct thread_info *ti)
66377 + struct task_struct *task)
66378 {
66379 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
66380 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
66381 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
66382 - ti->task->blocked_on = NULL;
66383 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
66384 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
66385 + task->blocked_on = NULL;
66386
66387 list_del_init(&waiter->list);
66388 waiter->task = NULL;
66389 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
66390 index 0799fd3..d06ae3b 100644
66391 --- a/kernel/mutex-debug.h
66392 +++ b/kernel/mutex-debug.h
66393 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
66394 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
66395 extern void debug_mutex_add_waiter(struct mutex *lock,
66396 struct mutex_waiter *waiter,
66397 - struct thread_info *ti);
66398 + struct task_struct *task);
66399 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66400 - struct thread_info *ti);
66401 + struct task_struct *task);
66402 extern void debug_mutex_unlock(struct mutex *lock);
66403 extern void debug_mutex_init(struct mutex *lock, const char *name,
66404 struct lock_class_key *key);
66405 diff --git a/kernel/mutex.c b/kernel/mutex.c
66406 index 89096dd..f91ebc5 100644
66407 --- a/kernel/mutex.c
66408 +++ b/kernel/mutex.c
66409 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66410 spin_lock_mutex(&lock->wait_lock, flags);
66411
66412 debug_mutex_lock_common(lock, &waiter);
66413 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
66414 + debug_mutex_add_waiter(lock, &waiter, task);
66415
66416 /* add waiting tasks to the end of the waitqueue (FIFO): */
66417 list_add_tail(&waiter.list, &lock->wait_list);
66418 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66419 * TASK_UNINTERRUPTIBLE case.)
66420 */
66421 if (unlikely(signal_pending_state(state, task))) {
66422 - mutex_remove_waiter(lock, &waiter,
66423 - task_thread_info(task));
66424 + mutex_remove_waiter(lock, &waiter, task);
66425 mutex_release(&lock->dep_map, 1, ip);
66426 spin_unlock_mutex(&lock->wait_lock, flags);
66427
66428 @@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66429 done:
66430 lock_acquired(&lock->dep_map, ip);
66431 /* got the lock - rejoice! */
66432 - mutex_remove_waiter(lock, &waiter, current_thread_info());
66433 + mutex_remove_waiter(lock, &waiter, task);
66434 mutex_set_owner(lock);
66435
66436 /* set it to 0 if there are no waiters left: */
66437 diff --git a/kernel/padata.c b/kernel/padata.c
66438 index b452599..5d68f4e 100644
66439 --- a/kernel/padata.c
66440 +++ b/kernel/padata.c
66441 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
66442 padata->pd = pd;
66443 padata->cb_cpu = cb_cpu;
66444
66445 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
66446 - atomic_set(&pd->seq_nr, -1);
66447 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
66448 + atomic_set_unchecked(&pd->seq_nr, -1);
66449
66450 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
66451 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
66452
66453 target_cpu = padata_cpu_hash(padata);
66454 queue = per_cpu_ptr(pd->pqueue, target_cpu);
66455 @@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
66456 padata_init_pqueues(pd);
66457 padata_init_squeues(pd);
66458 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
66459 - atomic_set(&pd->seq_nr, -1);
66460 + atomic_set_unchecked(&pd->seq_nr, -1);
66461 atomic_set(&pd->reorder_objects, 0);
66462 atomic_set(&pd->refcnt, 0);
66463 pd->pinst = pinst;
66464 diff --git a/kernel/panic.c b/kernel/panic.c
66465 index 3458469..342c500 100644
66466 --- a/kernel/panic.c
66467 +++ b/kernel/panic.c
66468 @@ -78,7 +78,11 @@ NORET_TYPE void panic(const char * fmt, ...)
66469 va_end(args);
66470 printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf);
66471 #ifdef CONFIG_DEBUG_BUGVERBOSE
66472 - dump_stack();
66473 + /*
66474 + * Avoid nested stack-dumping if a panic occurs during oops processing
66475 + */
66476 + if (!oops_in_progress)
66477 + dump_stack();
66478 #endif
66479
66480 /*
66481 @@ -382,7 +386,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
66482 const char *board;
66483
66484 printk(KERN_WARNING "------------[ cut here ]------------\n");
66485 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
66486 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
66487 board = dmi_get_system_info(DMI_PRODUCT_NAME);
66488 if (board)
66489 printk(KERN_WARNING "Hardware name: %s\n", board);
66490 @@ -437,7 +441,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
66491 */
66492 void __stack_chk_fail(void)
66493 {
66494 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
66495 + dump_stack();
66496 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
66497 __builtin_return_address(0));
66498 }
66499 EXPORT_SYMBOL(__stack_chk_fail);
66500 diff --git a/kernel/pid.c b/kernel/pid.c
66501 index fa5f722..0c93e57 100644
66502 --- a/kernel/pid.c
66503 +++ b/kernel/pid.c
66504 @@ -33,6 +33,7 @@
66505 #include <linux/rculist.h>
66506 #include <linux/bootmem.h>
66507 #include <linux/hash.h>
66508 +#include <linux/security.h>
66509 #include <linux/pid_namespace.h>
66510 #include <linux/init_task.h>
66511 #include <linux/syscalls.h>
66512 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
66513
66514 int pid_max = PID_MAX_DEFAULT;
66515
66516 -#define RESERVED_PIDS 300
66517 +#define RESERVED_PIDS 500
66518
66519 int pid_max_min = RESERVED_PIDS + 1;
66520 int pid_max_max = PID_MAX_LIMIT;
66521 @@ -418,10 +419,18 @@ EXPORT_SYMBOL(pid_task);
66522 */
66523 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
66524 {
66525 + struct task_struct *task;
66526 +
66527 rcu_lockdep_assert(rcu_read_lock_held(),
66528 "find_task_by_pid_ns() needs rcu_read_lock()"
66529 " protection");
66530 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
66531 +
66532 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
66533 +
66534 + if (gr_pid_is_chrooted(task))
66535 + return NULL;
66536 +
66537 + return task;
66538 }
66539
66540 struct task_struct *find_task_by_vpid(pid_t vnr)
66541 @@ -429,6 +438,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
66542 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
66543 }
66544
66545 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
66546 +{
66547 + rcu_lockdep_assert(rcu_read_lock_held(),
66548 + "find_task_by_pid_ns() needs rcu_read_lock()"
66549 + " protection");
66550 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
66551 +}
66552 +
66553 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
66554 {
66555 struct pid *pid;
66556 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
66557 index e7cb76d..75eceb3 100644
66558 --- a/kernel/posix-cpu-timers.c
66559 +++ b/kernel/posix-cpu-timers.c
66560 @@ -6,6 +6,7 @@
66561 #include <linux/posix-timers.h>
66562 #include <linux/errno.h>
66563 #include <linux/math64.h>
66564 +#include <linux/security.h>
66565 #include <asm/uaccess.h>
66566 #include <linux/kernel_stat.h>
66567 #include <trace/events/timer.h>
66568 @@ -1606,14 +1607,14 @@ struct k_clock clock_posix_cpu = {
66569
66570 static __init int init_posix_cpu_timers(void)
66571 {
66572 - struct k_clock process = {
66573 + static struct k_clock process = {
66574 .clock_getres = process_cpu_clock_getres,
66575 .clock_get = process_cpu_clock_get,
66576 .timer_create = process_cpu_timer_create,
66577 .nsleep = process_cpu_nsleep,
66578 .nsleep_restart = process_cpu_nsleep_restart,
66579 };
66580 - struct k_clock thread = {
66581 + static struct k_clock thread = {
66582 .clock_getres = thread_cpu_clock_getres,
66583 .clock_get = thread_cpu_clock_get,
66584 .timer_create = thread_cpu_timer_create,
66585 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
66586 index 69185ae..cc2847a 100644
66587 --- a/kernel/posix-timers.c
66588 +++ b/kernel/posix-timers.c
66589 @@ -43,6 +43,7 @@
66590 #include <linux/idr.h>
66591 #include <linux/posix-clock.h>
66592 #include <linux/posix-timers.h>
66593 +#include <linux/grsecurity.h>
66594 #include <linux/syscalls.h>
66595 #include <linux/wait.h>
66596 #include <linux/workqueue.h>
66597 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
66598 * which we beg off on and pass to do_sys_settimeofday().
66599 */
66600
66601 -static struct k_clock posix_clocks[MAX_CLOCKS];
66602 +static struct k_clock *posix_clocks[MAX_CLOCKS];
66603
66604 /*
66605 * These ones are defined below.
66606 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
66607 */
66608 static __init int init_posix_timers(void)
66609 {
66610 - struct k_clock clock_realtime = {
66611 + static struct k_clock clock_realtime = {
66612 .clock_getres = hrtimer_get_res,
66613 .clock_get = posix_clock_realtime_get,
66614 .clock_set = posix_clock_realtime_set,
66615 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
66616 .timer_get = common_timer_get,
66617 .timer_del = common_timer_del,
66618 };
66619 - struct k_clock clock_monotonic = {
66620 + static struct k_clock clock_monotonic = {
66621 .clock_getres = hrtimer_get_res,
66622 .clock_get = posix_ktime_get_ts,
66623 .nsleep = common_nsleep,
66624 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
66625 .timer_get = common_timer_get,
66626 .timer_del = common_timer_del,
66627 };
66628 - struct k_clock clock_monotonic_raw = {
66629 + static struct k_clock clock_monotonic_raw = {
66630 .clock_getres = hrtimer_get_res,
66631 .clock_get = posix_get_monotonic_raw,
66632 };
66633 - struct k_clock clock_realtime_coarse = {
66634 + static struct k_clock clock_realtime_coarse = {
66635 .clock_getres = posix_get_coarse_res,
66636 .clock_get = posix_get_realtime_coarse,
66637 };
66638 - struct k_clock clock_monotonic_coarse = {
66639 + static struct k_clock clock_monotonic_coarse = {
66640 .clock_getres = posix_get_coarse_res,
66641 .clock_get = posix_get_monotonic_coarse,
66642 };
66643 - struct k_clock clock_boottime = {
66644 + static struct k_clock clock_boottime = {
66645 .clock_getres = hrtimer_get_res,
66646 .clock_get = posix_get_boottime,
66647 .nsleep = common_nsleep,
66648 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
66649 return;
66650 }
66651
66652 - posix_clocks[clock_id] = *new_clock;
66653 + posix_clocks[clock_id] = new_clock;
66654 }
66655 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
66656
66657 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
66658 return (id & CLOCKFD_MASK) == CLOCKFD ?
66659 &clock_posix_dynamic : &clock_posix_cpu;
66660
66661 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
66662 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
66663 return NULL;
66664 - return &posix_clocks[id];
66665 + return posix_clocks[id];
66666 }
66667
66668 static int common_timer_create(struct k_itimer *new_timer)
66669 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
66670 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
66671 return -EFAULT;
66672
66673 + /* only the CLOCK_REALTIME clock can be set, all other clocks
66674 + have their clock_set fptr set to a nosettime dummy function
66675 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
66676 + call common_clock_set, which calls do_sys_settimeofday, which
66677 + we hook
66678 + */
66679 +
66680 return kc->clock_set(which_clock, &new_tp);
66681 }
66682
66683 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
66684 index d523593..68197a4 100644
66685 --- a/kernel/power/poweroff.c
66686 +++ b/kernel/power/poweroff.c
66687 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
66688 .enable_mask = SYSRQ_ENABLE_BOOT,
66689 };
66690
66691 -static int pm_sysrq_init(void)
66692 +static int __init pm_sysrq_init(void)
66693 {
66694 register_sysrq_key('o', &sysrq_poweroff_op);
66695 return 0;
66696 diff --git a/kernel/power/process.c b/kernel/power/process.c
66697 index 3d4b954..11af930 100644
66698 --- a/kernel/power/process.c
66699 +++ b/kernel/power/process.c
66700 @@ -41,6 +41,7 @@ static int try_to_freeze_tasks(bool sig_only)
66701 u64 elapsed_csecs64;
66702 unsigned int elapsed_csecs;
66703 bool wakeup = false;
66704 + bool timedout = false;
66705
66706 do_gettimeofday(&start);
66707
66708 @@ -51,6 +52,8 @@ static int try_to_freeze_tasks(bool sig_only)
66709
66710 while (true) {
66711 todo = 0;
66712 + if (time_after(jiffies, end_time))
66713 + timedout = true;
66714 read_lock(&tasklist_lock);
66715 do_each_thread(g, p) {
66716 if (frozen(p) || !freezable(p))
66717 @@ -71,9 +74,13 @@ static int try_to_freeze_tasks(bool sig_only)
66718 * try_to_stop() after schedule() in ptrace/signal
66719 * stop sees TIF_FREEZE.
66720 */
66721 - if (!task_is_stopped_or_traced(p) &&
66722 - !freezer_should_skip(p))
66723 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
66724 todo++;
66725 + if (timedout) {
66726 + printk(KERN_ERR "Task refusing to freeze:\n");
66727 + sched_show_task(p);
66728 + }
66729 + }
66730 } while_each_thread(g, p);
66731 read_unlock(&tasklist_lock);
66732
66733 @@ -82,7 +89,7 @@ static int try_to_freeze_tasks(bool sig_only)
66734 todo += wq_busy;
66735 }
66736
66737 - if (!todo || time_after(jiffies, end_time))
66738 + if (!todo || timedout)
66739 break;
66740
66741 if (pm_wakeup_pending()) {
66742 diff --git a/kernel/printk.c b/kernel/printk.c
66743 index 7982a0a..2095fdc 100644
66744 --- a/kernel/printk.c
66745 +++ b/kernel/printk.c
66746 @@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
66747 if (from_file && type != SYSLOG_ACTION_OPEN)
66748 return 0;
66749
66750 +#ifdef CONFIG_GRKERNSEC_DMESG
66751 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
66752 + return -EPERM;
66753 +#endif
66754 +
66755 if (syslog_action_restricted(type)) {
66756 if (capable(CAP_SYSLOG))
66757 return 0;
66758 diff --git a/kernel/profile.c b/kernel/profile.c
66759 index 76b8e77..a2930e8 100644
66760 --- a/kernel/profile.c
66761 +++ b/kernel/profile.c
66762 @@ -39,7 +39,7 @@ struct profile_hit {
66763 /* Oprofile timer tick hook */
66764 static int (*timer_hook)(struct pt_regs *) __read_mostly;
66765
66766 -static atomic_t *prof_buffer;
66767 +static atomic_unchecked_t *prof_buffer;
66768 static unsigned long prof_len, prof_shift;
66769
66770 int prof_on __read_mostly;
66771 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
66772 hits[i].pc = 0;
66773 continue;
66774 }
66775 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
66776 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
66777 hits[i].hits = hits[i].pc = 0;
66778 }
66779 }
66780 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
66781 * Add the current hit(s) and flush the write-queue out
66782 * to the global buffer:
66783 */
66784 - atomic_add(nr_hits, &prof_buffer[pc]);
66785 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
66786 for (i = 0; i < NR_PROFILE_HIT; ++i) {
66787 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
66788 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
66789 hits[i].pc = hits[i].hits = 0;
66790 }
66791 out:
66792 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
66793 {
66794 unsigned long pc;
66795 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
66796 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
66797 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
66798 }
66799 #endif /* !CONFIG_SMP */
66800
66801 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
66802 return -EFAULT;
66803 buf++; p++; count--; read++;
66804 }
66805 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
66806 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
66807 if (copy_to_user(buf, (void *)pnt, count))
66808 return -EFAULT;
66809 read += count;
66810 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
66811 }
66812 #endif
66813 profile_discard_flip_buffers();
66814 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
66815 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
66816 return count;
66817 }
66818
66819 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
66820 index 78ab24a..332c915 100644
66821 --- a/kernel/ptrace.c
66822 +++ b/kernel/ptrace.c
66823 @@ -172,7 +172,8 @@ int ptrace_check_attach(struct task_struct *child, bool ignore_state)
66824 return ret;
66825 }
66826
66827 -int __ptrace_may_access(struct task_struct *task, unsigned int mode)
66828 +static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
66829 + unsigned int log)
66830 {
66831 const struct cred *cred = current_cred(), *tcred;
66832
66833 @@ -198,7 +199,8 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
66834 cred->gid == tcred->sgid &&
66835 cred->gid == tcred->gid))
66836 goto ok;
66837 - if (ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE))
66838 + if ((!log && ns_capable_nolog(tcred->user->user_ns, CAP_SYS_PTRACE)) ||
66839 + (log && ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE)))
66840 goto ok;
66841 rcu_read_unlock();
66842 return -EPERM;
66843 @@ -207,7 +209,9 @@ ok:
66844 smp_rmb();
66845 if (task->mm)
66846 dumpable = get_dumpable(task->mm);
66847 - if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
66848 + if (!dumpable &&
66849 + ((!log && !task_ns_capable_nolog(task, CAP_SYS_PTRACE)) ||
66850 + (log && !task_ns_capable(task, CAP_SYS_PTRACE))))
66851 return -EPERM;
66852
66853 return security_ptrace_access_check(task, mode);
66854 @@ -217,7 +221,21 @@ bool ptrace_may_access(struct task_struct *task, unsigned int mode)
66855 {
66856 int err;
66857 task_lock(task);
66858 - err = __ptrace_may_access(task, mode);
66859 + err = __ptrace_may_access(task, mode, 0);
66860 + task_unlock(task);
66861 + return !err;
66862 +}
66863 +
66864 +bool ptrace_may_access_nolock(struct task_struct *task, unsigned int mode)
66865 +{
66866 + return __ptrace_may_access(task, mode, 0);
66867 +}
66868 +
66869 +bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
66870 +{
66871 + int err;
66872 + task_lock(task);
66873 + err = __ptrace_may_access(task, mode, 1);
66874 task_unlock(task);
66875 return !err;
66876 }
66877 @@ -262,7 +280,7 @@ static int ptrace_attach(struct task_struct *task, long request,
66878 goto out;
66879
66880 task_lock(task);
66881 - retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
66882 + retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
66883 task_unlock(task);
66884 if (retval)
66885 goto unlock_creds;
66886 @@ -277,7 +295,7 @@ static int ptrace_attach(struct task_struct *task, long request,
66887 task->ptrace = PT_PTRACED;
66888 if (seize)
66889 task->ptrace |= PT_SEIZED;
66890 - if (task_ns_capable(task, CAP_SYS_PTRACE))
66891 + if (task_ns_capable_nolog(task, CAP_SYS_PTRACE))
66892 task->ptrace |= PT_PTRACE_CAP;
66893
66894 __ptrace_link(task, current);
66895 @@ -483,7 +501,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
66896 break;
66897 return -EIO;
66898 }
66899 - if (copy_to_user(dst, buf, retval))
66900 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
66901 return -EFAULT;
66902 copied += retval;
66903 src += retval;
66904 @@ -680,7 +698,7 @@ int ptrace_request(struct task_struct *child, long request,
66905 bool seized = child->ptrace & PT_SEIZED;
66906 int ret = -EIO;
66907 siginfo_t siginfo, *si;
66908 - void __user *datavp = (void __user *) data;
66909 + void __user *datavp = (__force void __user *) data;
66910 unsigned long __user *datalp = datavp;
66911 unsigned long flags;
66912
66913 @@ -882,14 +900,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
66914 goto out;
66915 }
66916
66917 + if (gr_handle_ptrace(child, request)) {
66918 + ret = -EPERM;
66919 + goto out_put_task_struct;
66920 + }
66921 +
66922 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
66923 ret = ptrace_attach(child, request, data);
66924 /*
66925 * Some architectures need to do book-keeping after
66926 * a ptrace attach.
66927 */
66928 - if (!ret)
66929 + if (!ret) {
66930 arch_ptrace_attach(child);
66931 + gr_audit_ptrace(child);
66932 + }
66933 goto out_put_task_struct;
66934 }
66935
66936 @@ -915,7 +940,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
66937 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
66938 if (copied != sizeof(tmp))
66939 return -EIO;
66940 - return put_user(tmp, (unsigned long __user *)data);
66941 + return put_user(tmp, (__force unsigned long __user *)data);
66942 }
66943
66944 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
66945 @@ -1025,14 +1050,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
66946 goto out;
66947 }
66948
66949 + if (gr_handle_ptrace(child, request)) {
66950 + ret = -EPERM;
66951 + goto out_put_task_struct;
66952 + }
66953 +
66954 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
66955 ret = ptrace_attach(child, request, data);
66956 /*
66957 * Some architectures need to do book-keeping after
66958 * a ptrace attach.
66959 */
66960 - if (!ret)
66961 + if (!ret) {
66962 arch_ptrace_attach(child);
66963 + gr_audit_ptrace(child);
66964 + }
66965 goto out_put_task_struct;
66966 }
66967
66968 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
66969 index 764825c..3aa6ac4 100644
66970 --- a/kernel/rcutorture.c
66971 +++ b/kernel/rcutorture.c
66972 @@ -138,12 +138,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
66973 { 0 };
66974 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
66975 { 0 };
66976 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
66977 -static atomic_t n_rcu_torture_alloc;
66978 -static atomic_t n_rcu_torture_alloc_fail;
66979 -static atomic_t n_rcu_torture_free;
66980 -static atomic_t n_rcu_torture_mberror;
66981 -static atomic_t n_rcu_torture_error;
66982 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
66983 +static atomic_unchecked_t n_rcu_torture_alloc;
66984 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
66985 +static atomic_unchecked_t n_rcu_torture_free;
66986 +static atomic_unchecked_t n_rcu_torture_mberror;
66987 +static atomic_unchecked_t n_rcu_torture_error;
66988 static long n_rcu_torture_boost_ktrerror;
66989 static long n_rcu_torture_boost_rterror;
66990 static long n_rcu_torture_boost_failure;
66991 @@ -223,11 +223,11 @@ rcu_torture_alloc(void)
66992
66993 spin_lock_bh(&rcu_torture_lock);
66994 if (list_empty(&rcu_torture_freelist)) {
66995 - atomic_inc(&n_rcu_torture_alloc_fail);
66996 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
66997 spin_unlock_bh(&rcu_torture_lock);
66998 return NULL;
66999 }
67000 - atomic_inc(&n_rcu_torture_alloc);
67001 + atomic_inc_unchecked(&n_rcu_torture_alloc);
67002 p = rcu_torture_freelist.next;
67003 list_del_init(p);
67004 spin_unlock_bh(&rcu_torture_lock);
67005 @@ -240,7 +240,7 @@ rcu_torture_alloc(void)
67006 static void
67007 rcu_torture_free(struct rcu_torture *p)
67008 {
67009 - atomic_inc(&n_rcu_torture_free);
67010 + atomic_inc_unchecked(&n_rcu_torture_free);
67011 spin_lock_bh(&rcu_torture_lock);
67012 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
67013 spin_unlock_bh(&rcu_torture_lock);
67014 @@ -360,7 +360,7 @@ rcu_torture_cb(struct rcu_head *p)
67015 i = rp->rtort_pipe_count;
67016 if (i > RCU_TORTURE_PIPE_LEN)
67017 i = RCU_TORTURE_PIPE_LEN;
67018 - atomic_inc(&rcu_torture_wcount[i]);
67019 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
67020 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
67021 rp->rtort_mbtest = 0;
67022 rcu_torture_free(rp);
67023 @@ -407,7 +407,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
67024 i = rp->rtort_pipe_count;
67025 if (i > RCU_TORTURE_PIPE_LEN)
67026 i = RCU_TORTURE_PIPE_LEN;
67027 - atomic_inc(&rcu_torture_wcount[i]);
67028 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
67029 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
67030 rp->rtort_mbtest = 0;
67031 list_del(&rp->rtort_free);
67032 @@ -872,7 +872,7 @@ rcu_torture_writer(void *arg)
67033 i = old_rp->rtort_pipe_count;
67034 if (i > RCU_TORTURE_PIPE_LEN)
67035 i = RCU_TORTURE_PIPE_LEN;
67036 - atomic_inc(&rcu_torture_wcount[i]);
67037 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
67038 old_rp->rtort_pipe_count++;
67039 cur_ops->deferred_free(old_rp);
67040 }
67041 @@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
67042 return;
67043 }
67044 if (p->rtort_mbtest == 0)
67045 - atomic_inc(&n_rcu_torture_mberror);
67046 + atomic_inc_unchecked(&n_rcu_torture_mberror);
67047 spin_lock(&rand_lock);
67048 cur_ops->read_delay(&rand);
67049 n_rcu_torture_timers++;
67050 @@ -1001,7 +1001,7 @@ rcu_torture_reader(void *arg)
67051 continue;
67052 }
67053 if (p->rtort_mbtest == 0)
67054 - atomic_inc(&n_rcu_torture_mberror);
67055 + atomic_inc_unchecked(&n_rcu_torture_mberror);
67056 cur_ops->read_delay(&rand);
67057 preempt_disable();
67058 pipe_count = p->rtort_pipe_count;
67059 @@ -1060,16 +1060,16 @@ rcu_torture_printk(char *page)
67060 rcu_torture_current,
67061 rcu_torture_current_version,
67062 list_empty(&rcu_torture_freelist),
67063 - atomic_read(&n_rcu_torture_alloc),
67064 - atomic_read(&n_rcu_torture_alloc_fail),
67065 - atomic_read(&n_rcu_torture_free),
67066 - atomic_read(&n_rcu_torture_mberror),
67067 + atomic_read_unchecked(&n_rcu_torture_alloc),
67068 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
67069 + atomic_read_unchecked(&n_rcu_torture_free),
67070 + atomic_read_unchecked(&n_rcu_torture_mberror),
67071 n_rcu_torture_boost_ktrerror,
67072 n_rcu_torture_boost_rterror,
67073 n_rcu_torture_boost_failure,
67074 n_rcu_torture_boosts,
67075 n_rcu_torture_timers);
67076 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
67077 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
67078 n_rcu_torture_boost_ktrerror != 0 ||
67079 n_rcu_torture_boost_rterror != 0 ||
67080 n_rcu_torture_boost_failure != 0)
67081 @@ -1077,7 +1077,7 @@ rcu_torture_printk(char *page)
67082 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
67083 if (i > 1) {
67084 cnt += sprintf(&page[cnt], "!!! ");
67085 - atomic_inc(&n_rcu_torture_error);
67086 + atomic_inc_unchecked(&n_rcu_torture_error);
67087 WARN_ON_ONCE(1);
67088 }
67089 cnt += sprintf(&page[cnt], "Reader Pipe: ");
67090 @@ -1091,7 +1091,7 @@ rcu_torture_printk(char *page)
67091 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
67092 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
67093 cnt += sprintf(&page[cnt], " %d",
67094 - atomic_read(&rcu_torture_wcount[i]));
67095 + atomic_read_unchecked(&rcu_torture_wcount[i]));
67096 }
67097 cnt += sprintf(&page[cnt], "\n");
67098 if (cur_ops->stats)
67099 @@ -1401,7 +1401,7 @@ rcu_torture_cleanup(void)
67100
67101 if (cur_ops->cleanup)
67102 cur_ops->cleanup();
67103 - if (atomic_read(&n_rcu_torture_error))
67104 + if (atomic_read_unchecked(&n_rcu_torture_error))
67105 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
67106 else
67107 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
67108 @@ -1465,17 +1465,17 @@ rcu_torture_init(void)
67109
67110 rcu_torture_current = NULL;
67111 rcu_torture_current_version = 0;
67112 - atomic_set(&n_rcu_torture_alloc, 0);
67113 - atomic_set(&n_rcu_torture_alloc_fail, 0);
67114 - atomic_set(&n_rcu_torture_free, 0);
67115 - atomic_set(&n_rcu_torture_mberror, 0);
67116 - atomic_set(&n_rcu_torture_error, 0);
67117 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
67118 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
67119 + atomic_set_unchecked(&n_rcu_torture_free, 0);
67120 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
67121 + atomic_set_unchecked(&n_rcu_torture_error, 0);
67122 n_rcu_torture_boost_ktrerror = 0;
67123 n_rcu_torture_boost_rterror = 0;
67124 n_rcu_torture_boost_failure = 0;
67125 n_rcu_torture_boosts = 0;
67126 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
67127 - atomic_set(&rcu_torture_wcount[i], 0);
67128 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
67129 for_each_possible_cpu(cpu) {
67130 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
67131 per_cpu(rcu_torture_count, cpu)[i] = 0;
67132 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
67133 index 6b76d81..7afc1b3 100644
67134 --- a/kernel/rcutree.c
67135 +++ b/kernel/rcutree.c
67136 @@ -367,9 +367,9 @@ void rcu_enter_nohz(void)
67137 trace_rcu_dyntick("Start");
67138 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
67139 smp_mb__before_atomic_inc(); /* See above. */
67140 - atomic_inc(&rdtp->dynticks);
67141 + atomic_inc_unchecked(&rdtp->dynticks);
67142 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
67143 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
67144 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
67145 local_irq_restore(flags);
67146 }
67147
67148 @@ -391,10 +391,10 @@ void rcu_exit_nohz(void)
67149 return;
67150 }
67151 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
67152 - atomic_inc(&rdtp->dynticks);
67153 + atomic_inc_unchecked(&rdtp->dynticks);
67154 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
67155 smp_mb__after_atomic_inc(); /* See above. */
67156 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
67157 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
67158 trace_rcu_dyntick("End");
67159 local_irq_restore(flags);
67160 }
67161 @@ -411,14 +411,14 @@ void rcu_nmi_enter(void)
67162 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
67163
67164 if (rdtp->dynticks_nmi_nesting == 0 &&
67165 - (atomic_read(&rdtp->dynticks) & 0x1))
67166 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
67167 return;
67168 rdtp->dynticks_nmi_nesting++;
67169 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
67170 - atomic_inc(&rdtp->dynticks);
67171 + atomic_inc_unchecked(&rdtp->dynticks);
67172 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
67173 smp_mb__after_atomic_inc(); /* See above. */
67174 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
67175 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
67176 }
67177
67178 /**
67179 @@ -437,9 +437,9 @@ void rcu_nmi_exit(void)
67180 return;
67181 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
67182 smp_mb__before_atomic_inc(); /* See above. */
67183 - atomic_inc(&rdtp->dynticks);
67184 + atomic_inc_unchecked(&rdtp->dynticks);
67185 smp_mb__after_atomic_inc(); /* Force delay to next write. */
67186 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
67187 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
67188 }
67189
67190 /**
67191 @@ -474,7 +474,7 @@ void rcu_irq_exit(void)
67192 */
67193 static int dyntick_save_progress_counter(struct rcu_data *rdp)
67194 {
67195 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
67196 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
67197 return 0;
67198 }
67199
67200 @@ -489,7 +489,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
67201 unsigned int curr;
67202 unsigned int snap;
67203
67204 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
67205 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
67206 snap = (unsigned int)rdp->dynticks_snap;
67207
67208 /*
67209 @@ -1552,7 +1552,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
67210 /*
67211 * Do RCU core processing for the current CPU.
67212 */
67213 -static void rcu_process_callbacks(struct softirq_action *unused)
67214 +static void rcu_process_callbacks(void)
67215 {
67216 trace_rcu_utilization("Start RCU core");
67217 __rcu_process_callbacks(&rcu_sched_state,
67218 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
67219 index 849ce9e..74bc9de 100644
67220 --- a/kernel/rcutree.h
67221 +++ b/kernel/rcutree.h
67222 @@ -86,7 +86,7 @@
67223 struct rcu_dynticks {
67224 int dynticks_nesting; /* Track irq/process nesting level. */
67225 int dynticks_nmi_nesting; /* Track NMI nesting level. */
67226 - atomic_t dynticks; /* Even value for dynticks-idle, else odd. */
67227 + atomic_unchecked_t dynticks; /* Even value for dynticks-idle, else odd. */
67228 };
67229
67230 /* RCU's kthread states for tracing. */
67231 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
67232 index 4b9b9f8..2326053 100644
67233 --- a/kernel/rcutree_plugin.h
67234 +++ b/kernel/rcutree_plugin.h
67235 @@ -842,7 +842,7 @@ void synchronize_rcu_expedited(void)
67236
67237 /* Clean up and exit. */
67238 smp_mb(); /* ensure expedited GP seen before counter increment. */
67239 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
67240 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
67241 unlock_mb_ret:
67242 mutex_unlock(&sync_rcu_preempt_exp_mutex);
67243 mb_ret:
67244 @@ -1815,8 +1815,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
67245
67246 #else /* #ifndef CONFIG_SMP */
67247
67248 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
67249 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
67250 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
67251 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
67252
67253 static int synchronize_sched_expedited_cpu_stop(void *data)
67254 {
67255 @@ -1871,7 +1871,7 @@ void synchronize_sched_expedited(void)
67256 int firstsnap, s, snap, trycount = 0;
67257
67258 /* Note that atomic_inc_return() implies full memory barrier. */
67259 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
67260 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
67261 get_online_cpus();
67262
67263 /*
67264 @@ -1892,7 +1892,7 @@ void synchronize_sched_expedited(void)
67265 }
67266
67267 /* Check to see if someone else did our work for us. */
67268 - s = atomic_read(&sync_sched_expedited_done);
67269 + s = atomic_read_unchecked(&sync_sched_expedited_done);
67270 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
67271 smp_mb(); /* ensure test happens before caller kfree */
67272 return;
67273 @@ -1907,7 +1907,7 @@ void synchronize_sched_expedited(void)
67274 * grace period works for us.
67275 */
67276 get_online_cpus();
67277 - snap = atomic_read(&sync_sched_expedited_started) - 1;
67278 + snap = atomic_read_unchecked(&sync_sched_expedited_started) - 1;
67279 smp_mb(); /* ensure read is before try_stop_cpus(). */
67280 }
67281
67282 @@ -1918,12 +1918,12 @@ void synchronize_sched_expedited(void)
67283 * than we did beat us to the punch.
67284 */
67285 do {
67286 - s = atomic_read(&sync_sched_expedited_done);
67287 + s = atomic_read_unchecked(&sync_sched_expedited_done);
67288 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
67289 smp_mb(); /* ensure test happens before caller kfree */
67290 break;
67291 }
67292 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
67293 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
67294
67295 put_online_cpus();
67296 }
67297 @@ -1985,7 +1985,7 @@ int rcu_needs_cpu(int cpu)
67298 for_each_online_cpu(thatcpu) {
67299 if (thatcpu == cpu)
67300 continue;
67301 - snap = atomic_add_return(0, &per_cpu(rcu_dynticks,
67302 + snap = atomic_add_return_unchecked(0, &per_cpu(rcu_dynticks,
67303 thatcpu).dynticks);
67304 smp_mb(); /* Order sampling of snap with end of grace period. */
67305 if ((snap & 0x1) != 0) {
67306 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
67307 index 9feffa4..54058df 100644
67308 --- a/kernel/rcutree_trace.c
67309 +++ b/kernel/rcutree_trace.c
67310 @@ -69,7 +69,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
67311 rdp->qs_pending);
67312 #ifdef CONFIG_NO_HZ
67313 seq_printf(m, " dt=%d/%d/%d df=%lu",
67314 - atomic_read(&rdp->dynticks->dynticks),
67315 + atomic_read_unchecked(&rdp->dynticks->dynticks),
67316 rdp->dynticks->dynticks_nesting,
67317 rdp->dynticks->dynticks_nmi_nesting,
67318 rdp->dynticks_fqs);
67319 @@ -143,7 +143,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
67320 rdp->qs_pending);
67321 #ifdef CONFIG_NO_HZ
67322 seq_printf(m, ",%d,%d,%d,%lu",
67323 - atomic_read(&rdp->dynticks->dynticks),
67324 + atomic_read_unchecked(&rdp->dynticks->dynticks),
67325 rdp->dynticks->dynticks_nesting,
67326 rdp->dynticks->dynticks_nmi_nesting,
67327 rdp->dynticks_fqs);
67328 diff --git a/kernel/resource.c b/kernel/resource.c
67329 index 7640b3a..5879283 100644
67330 --- a/kernel/resource.c
67331 +++ b/kernel/resource.c
67332 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
67333
67334 static int __init ioresources_init(void)
67335 {
67336 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67337 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67338 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
67339 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
67340 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67341 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
67342 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
67343 +#endif
67344 +#else
67345 proc_create("ioports", 0, NULL, &proc_ioports_operations);
67346 proc_create("iomem", 0, NULL, &proc_iomem_operations);
67347 +#endif
67348 return 0;
67349 }
67350 __initcall(ioresources_init);
67351 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
67352 index 3d9f31c..7fefc9e 100644
67353 --- a/kernel/rtmutex-tester.c
67354 +++ b/kernel/rtmutex-tester.c
67355 @@ -20,7 +20,7 @@
67356 #define MAX_RT_TEST_MUTEXES 8
67357
67358 static spinlock_t rttest_lock;
67359 -static atomic_t rttest_event;
67360 +static atomic_unchecked_t rttest_event;
67361
67362 struct test_thread_data {
67363 int opcode;
67364 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67365
67366 case RTTEST_LOCKCONT:
67367 td->mutexes[td->opdata] = 1;
67368 - td->event = atomic_add_return(1, &rttest_event);
67369 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67370 return 0;
67371
67372 case RTTEST_RESET:
67373 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67374 return 0;
67375
67376 case RTTEST_RESETEVENT:
67377 - atomic_set(&rttest_event, 0);
67378 + atomic_set_unchecked(&rttest_event, 0);
67379 return 0;
67380
67381 default:
67382 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67383 return ret;
67384
67385 td->mutexes[id] = 1;
67386 - td->event = atomic_add_return(1, &rttest_event);
67387 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67388 rt_mutex_lock(&mutexes[id]);
67389 - td->event = atomic_add_return(1, &rttest_event);
67390 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67391 td->mutexes[id] = 4;
67392 return 0;
67393
67394 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67395 return ret;
67396
67397 td->mutexes[id] = 1;
67398 - td->event = atomic_add_return(1, &rttest_event);
67399 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67400 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
67401 - td->event = atomic_add_return(1, &rttest_event);
67402 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67403 td->mutexes[id] = ret ? 0 : 4;
67404 return ret ? -EINTR : 0;
67405
67406 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67407 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
67408 return ret;
67409
67410 - td->event = atomic_add_return(1, &rttest_event);
67411 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67412 rt_mutex_unlock(&mutexes[id]);
67413 - td->event = atomic_add_return(1, &rttest_event);
67414 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67415 td->mutexes[id] = 0;
67416 return 0;
67417
67418 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67419 break;
67420
67421 td->mutexes[dat] = 2;
67422 - td->event = atomic_add_return(1, &rttest_event);
67423 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67424 break;
67425
67426 default:
67427 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67428 return;
67429
67430 td->mutexes[dat] = 3;
67431 - td->event = atomic_add_return(1, &rttest_event);
67432 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67433 break;
67434
67435 case RTTEST_LOCKNOWAIT:
67436 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67437 return;
67438
67439 td->mutexes[dat] = 1;
67440 - td->event = atomic_add_return(1, &rttest_event);
67441 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67442 return;
67443
67444 default:
67445 diff --git a/kernel/sched.c b/kernel/sched.c
67446 index d6b149c..896cbb8 100644
67447 --- a/kernel/sched.c
67448 +++ b/kernel/sched.c
67449 @@ -4389,6 +4389,19 @@ pick_next_task(struct rq *rq)
67450 BUG(); /* the idle class will always have a runnable task */
67451 }
67452
67453 +#ifdef CONFIG_GRKERNSEC_SETXID
67454 +extern void gr_delayed_cred_worker(void);
67455 +static inline void gr_cred_schedule(void)
67456 +{
67457 + if (unlikely(current->delayed_cred))
67458 + gr_delayed_cred_worker();
67459 +}
67460 +#else
67461 +static inline void gr_cred_schedule(void)
67462 +{
67463 +}
67464 +#endif
67465 +
67466 /*
67467 * __schedule() is the main scheduler function.
67468 */
67469 @@ -4408,6 +4421,8 @@ need_resched:
67470
67471 schedule_debug(prev);
67472
67473 + gr_cred_schedule();
67474 +
67475 if (sched_feat(HRTICK))
67476 hrtick_clear(rq);
67477
67478 @@ -5098,6 +5113,8 @@ int can_nice(const struct task_struct *p, const int nice)
67479 /* convert nice value [19,-20] to rlimit style value [1,40] */
67480 int nice_rlim = 20 - nice;
67481
67482 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
67483 +
67484 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
67485 capable(CAP_SYS_NICE));
67486 }
67487 @@ -5131,7 +5148,8 @@ SYSCALL_DEFINE1(nice, int, increment)
67488 if (nice > 19)
67489 nice = 19;
67490
67491 - if (increment < 0 && !can_nice(current, nice))
67492 + if (increment < 0 && (!can_nice(current, nice) ||
67493 + gr_handle_chroot_nice()))
67494 return -EPERM;
67495
67496 retval = security_task_setnice(current, nice);
67497 @@ -5288,6 +5306,7 @@ recheck:
67498 unsigned long rlim_rtprio =
67499 task_rlimit(p, RLIMIT_RTPRIO);
67500
67501 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
67502 /* can't set/change the rt policy */
67503 if (policy != p->policy && !rlim_rtprio)
67504 return -EPERM;
67505 diff --git a/kernel/sched_autogroup.c b/kernel/sched_autogroup.c
67506 index 429242f..d7cca82 100644
67507 --- a/kernel/sched_autogroup.c
67508 +++ b/kernel/sched_autogroup.c
67509 @@ -7,7 +7,7 @@
67510
67511 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
67512 static struct autogroup autogroup_default;
67513 -static atomic_t autogroup_seq_nr;
67514 +static atomic_unchecked_t autogroup_seq_nr;
67515
67516 static void __init autogroup_init(struct task_struct *init_task)
67517 {
67518 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
67519
67520 kref_init(&ag->kref);
67521 init_rwsem(&ag->lock);
67522 - ag->id = atomic_inc_return(&autogroup_seq_nr);
67523 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
67524 ag->tg = tg;
67525 #ifdef CONFIG_RT_GROUP_SCHED
67526 /*
67527 diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
67528 index 8a39fa3..34f3dbc 100644
67529 --- a/kernel/sched_fair.c
67530 +++ b/kernel/sched_fair.c
67531 @@ -4801,7 +4801,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
67532 * run_rebalance_domains is triggered when needed from the scheduler tick.
67533 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
67534 */
67535 -static void run_rebalance_domains(struct softirq_action *h)
67536 +static void run_rebalance_domains(void)
67537 {
67538 int this_cpu = smp_processor_id();
67539 struct rq *this_rq = cpu_rq(this_cpu);
67540 diff --git a/kernel/signal.c b/kernel/signal.c
67541 index 2065515..aed2987 100644
67542 --- a/kernel/signal.c
67543 +++ b/kernel/signal.c
67544 @@ -45,12 +45,12 @@ static struct kmem_cache *sigqueue_cachep;
67545
67546 int print_fatal_signals __read_mostly;
67547
67548 -static void __user *sig_handler(struct task_struct *t, int sig)
67549 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
67550 {
67551 return t->sighand->action[sig - 1].sa.sa_handler;
67552 }
67553
67554 -static int sig_handler_ignored(void __user *handler, int sig)
67555 +static int sig_handler_ignored(__sighandler_t handler, int sig)
67556 {
67557 /* Is it explicitly or implicitly ignored? */
67558 return handler == SIG_IGN ||
67559 @@ -60,7 +60,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
67560 static int sig_task_ignored(struct task_struct *t, int sig,
67561 int from_ancestor_ns)
67562 {
67563 - void __user *handler;
67564 + __sighandler_t handler;
67565
67566 handler = sig_handler(t, sig);
67567
67568 @@ -364,6 +364,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
67569 atomic_inc(&user->sigpending);
67570 rcu_read_unlock();
67571
67572 + if (!override_rlimit)
67573 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
67574 +
67575 if (override_rlimit ||
67576 atomic_read(&user->sigpending) <=
67577 task_rlimit(t, RLIMIT_SIGPENDING)) {
67578 @@ -488,7 +491,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
67579
67580 int unhandled_signal(struct task_struct *tsk, int sig)
67581 {
67582 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
67583 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
67584 if (is_global_init(tsk))
67585 return 1;
67586 if (handler != SIG_IGN && handler != SIG_DFL)
67587 @@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
67588 }
67589 }
67590
67591 + /* allow glibc communication via tgkill to other threads in our
67592 + thread group */
67593 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
67594 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
67595 + && gr_handle_signal(t, sig))
67596 + return -EPERM;
67597 +
67598 return security_task_kill(t, info, sig, 0);
67599 }
67600
67601 @@ -1165,7 +1175,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
67602 return send_signal(sig, info, p, 1);
67603 }
67604
67605 -static int
67606 +int
67607 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
67608 {
67609 return send_signal(sig, info, t, 0);
67610 @@ -1202,6 +1212,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
67611 unsigned long int flags;
67612 int ret, blocked, ignored;
67613 struct k_sigaction *action;
67614 + int is_unhandled = 0;
67615
67616 spin_lock_irqsave(&t->sighand->siglock, flags);
67617 action = &t->sighand->action[sig-1];
67618 @@ -1216,9 +1227,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
67619 }
67620 if (action->sa.sa_handler == SIG_DFL)
67621 t->signal->flags &= ~SIGNAL_UNKILLABLE;
67622 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
67623 + is_unhandled = 1;
67624 ret = specific_send_sig_info(sig, info, t);
67625 spin_unlock_irqrestore(&t->sighand->siglock, flags);
67626
67627 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
67628 + normal operation */
67629 + if (is_unhandled) {
67630 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
67631 + gr_handle_crash(t, sig);
67632 + }
67633 +
67634 return ret;
67635 }
67636
67637 @@ -1285,8 +1305,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
67638 ret = check_kill_permission(sig, info, p);
67639 rcu_read_unlock();
67640
67641 - if (!ret && sig)
67642 + if (!ret && sig) {
67643 ret = do_send_sig_info(sig, info, p, true);
67644 + if (!ret)
67645 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
67646 + }
67647
67648 return ret;
67649 }
67650 @@ -2754,7 +2777,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
67651 int error = -ESRCH;
67652
67653 rcu_read_lock();
67654 - p = find_task_by_vpid(pid);
67655 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
67656 + /* allow glibc communication via tgkill to other threads in our
67657 + thread group */
67658 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
67659 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
67660 + p = find_task_by_vpid_unrestricted(pid);
67661 + else
67662 +#endif
67663 + p = find_task_by_vpid(pid);
67664 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
67665 error = check_kill_permission(sig, info, p);
67666 /*
67667 diff --git a/kernel/smp.c b/kernel/smp.c
67668 index db197d6..17aef0b 100644
67669 --- a/kernel/smp.c
67670 +++ b/kernel/smp.c
67671 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
67672 }
67673 EXPORT_SYMBOL(smp_call_function);
67674
67675 -void ipi_call_lock(void)
67676 +void ipi_call_lock(void) __acquires(call_function.lock)
67677 {
67678 raw_spin_lock(&call_function.lock);
67679 }
67680
67681 -void ipi_call_unlock(void)
67682 +void ipi_call_unlock(void) __releases(call_function.lock)
67683 {
67684 raw_spin_unlock(&call_function.lock);
67685 }
67686
67687 -void ipi_call_lock_irq(void)
67688 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
67689 {
67690 raw_spin_lock_irq(&call_function.lock);
67691 }
67692
67693 -void ipi_call_unlock_irq(void)
67694 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
67695 {
67696 raw_spin_unlock_irq(&call_function.lock);
67697 }
67698 diff --git a/kernel/softirq.c b/kernel/softirq.c
67699 index 2c71d91..1021f81 100644
67700 --- a/kernel/softirq.c
67701 +++ b/kernel/softirq.c
67702 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
67703
67704 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
67705
67706 -char *softirq_to_name[NR_SOFTIRQS] = {
67707 +const char * const softirq_to_name[NR_SOFTIRQS] = {
67708 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
67709 "TASKLET", "SCHED", "HRTIMER", "RCU"
67710 };
67711 @@ -235,7 +235,7 @@ restart:
67712 kstat_incr_softirqs_this_cpu(vec_nr);
67713
67714 trace_softirq_entry(vec_nr);
67715 - h->action(h);
67716 + h->action();
67717 trace_softirq_exit(vec_nr);
67718 if (unlikely(prev_count != preempt_count())) {
67719 printk(KERN_ERR "huh, entered softirq %u %s %p"
67720 @@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
67721 local_irq_restore(flags);
67722 }
67723
67724 -void open_softirq(int nr, void (*action)(struct softirq_action *))
67725 +void open_softirq(int nr, void (*action)(void))
67726 {
67727 - softirq_vec[nr].action = action;
67728 + pax_open_kernel();
67729 + *(void **)&softirq_vec[nr].action = action;
67730 + pax_close_kernel();
67731 }
67732
67733 /*
67734 @@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
67735
67736 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
67737
67738 -static void tasklet_action(struct softirq_action *a)
67739 +static void tasklet_action(void)
67740 {
67741 struct tasklet_struct *list;
67742
67743 @@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
67744 }
67745 }
67746
67747 -static void tasklet_hi_action(struct softirq_action *a)
67748 +static void tasklet_hi_action(void)
67749 {
67750 struct tasklet_struct *list;
67751
67752 diff --git a/kernel/sys.c b/kernel/sys.c
67753 index 481611f..0754d86 100644
67754 --- a/kernel/sys.c
67755 +++ b/kernel/sys.c
67756 @@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
67757 error = -EACCES;
67758 goto out;
67759 }
67760 +
67761 + if (gr_handle_chroot_setpriority(p, niceval)) {
67762 + error = -EACCES;
67763 + goto out;
67764 + }
67765 +
67766 no_nice = security_task_setnice(p, niceval);
67767 if (no_nice) {
67768 error = no_nice;
67769 @@ -572,6 +578,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
67770 goto error;
67771 }
67772
67773 + if (gr_check_group_change(new->gid, new->egid, -1))
67774 + goto error;
67775 +
67776 if (rgid != (gid_t) -1 ||
67777 (egid != (gid_t) -1 && egid != old->gid))
67778 new->sgid = new->egid;
67779 @@ -601,6 +610,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
67780 old = current_cred();
67781
67782 retval = -EPERM;
67783 +
67784 + if (gr_check_group_change(gid, gid, gid))
67785 + goto error;
67786 +
67787 if (nsown_capable(CAP_SETGID))
67788 new->gid = new->egid = new->sgid = new->fsgid = gid;
67789 else if (gid == old->gid || gid == old->sgid)
67790 @@ -618,7 +631,7 @@ error:
67791 /*
67792 * change the user struct in a credentials set to match the new UID
67793 */
67794 -static int set_user(struct cred *new)
67795 +int set_user(struct cred *new)
67796 {
67797 struct user_struct *new_user;
67798
67799 @@ -688,6 +701,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
67800 goto error;
67801 }
67802
67803 + if (gr_check_user_change(new->uid, new->euid, -1))
67804 + goto error;
67805 +
67806 if (new->uid != old->uid) {
67807 retval = set_user(new);
67808 if (retval < 0)
67809 @@ -732,6 +748,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
67810 old = current_cred();
67811
67812 retval = -EPERM;
67813 +
67814 + if (gr_check_crash_uid(uid))
67815 + goto error;
67816 + if (gr_check_user_change(uid, uid, uid))
67817 + goto error;
67818 +
67819 if (nsown_capable(CAP_SETUID)) {
67820 new->suid = new->uid = uid;
67821 if (uid != old->uid) {
67822 @@ -786,6 +808,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
67823 goto error;
67824 }
67825
67826 + if (gr_check_user_change(ruid, euid, -1))
67827 + goto error;
67828 +
67829 if (ruid != (uid_t) -1) {
67830 new->uid = ruid;
67831 if (ruid != old->uid) {
67832 @@ -850,6 +875,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
67833 goto error;
67834 }
67835
67836 + if (gr_check_group_change(rgid, egid, -1))
67837 + goto error;
67838 +
67839 if (rgid != (gid_t) -1)
67840 new->gid = rgid;
67841 if (egid != (gid_t) -1)
67842 @@ -896,6 +924,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
67843 old = current_cred();
67844 old_fsuid = old->fsuid;
67845
67846 + if (gr_check_user_change(-1, -1, uid))
67847 + goto error;
67848 +
67849 if (uid == old->uid || uid == old->euid ||
67850 uid == old->suid || uid == old->fsuid ||
67851 nsown_capable(CAP_SETUID)) {
67852 @@ -906,6 +937,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
67853 }
67854 }
67855
67856 +error:
67857 abort_creds(new);
67858 return old_fsuid;
67859
67860 @@ -932,12 +964,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
67861 if (gid == old->gid || gid == old->egid ||
67862 gid == old->sgid || gid == old->fsgid ||
67863 nsown_capable(CAP_SETGID)) {
67864 + if (gr_check_group_change(-1, -1, gid))
67865 + goto error;
67866 +
67867 if (gid != old_fsgid) {
67868 new->fsgid = gid;
67869 goto change_okay;
67870 }
67871 }
67872
67873 +error:
67874 abort_creds(new);
67875 return old_fsgid;
67876
67877 @@ -1189,7 +1225,10 @@ static int override_release(char __user *release, int len)
67878 }
67879 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
67880 snprintf(buf, len, "2.6.%u%s", v, rest);
67881 - ret = copy_to_user(release, buf, len);
67882 + if (len > sizeof(buf))
67883 + ret = -EFAULT;
67884 + else
67885 + ret = copy_to_user(release, buf, len);
67886 }
67887 return ret;
67888 }
67889 @@ -1243,19 +1282,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
67890 return -EFAULT;
67891
67892 down_read(&uts_sem);
67893 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
67894 + error = __copy_to_user(name->sysname, &utsname()->sysname,
67895 __OLD_UTS_LEN);
67896 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
67897 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
67898 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
67899 __OLD_UTS_LEN);
67900 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
67901 - error |= __copy_to_user(&name->release, &utsname()->release,
67902 + error |= __copy_to_user(name->release, &utsname()->release,
67903 __OLD_UTS_LEN);
67904 error |= __put_user(0, name->release + __OLD_UTS_LEN);
67905 - error |= __copy_to_user(&name->version, &utsname()->version,
67906 + error |= __copy_to_user(name->version, &utsname()->version,
67907 __OLD_UTS_LEN);
67908 error |= __put_user(0, name->version + __OLD_UTS_LEN);
67909 - error |= __copy_to_user(&name->machine, &utsname()->machine,
67910 + error |= __copy_to_user(name->machine, &utsname()->machine,
67911 __OLD_UTS_LEN);
67912 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
67913 up_read(&uts_sem);
67914 @@ -1720,7 +1759,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
67915 error = get_dumpable(me->mm);
67916 break;
67917 case PR_SET_DUMPABLE:
67918 - if (arg2 < 0 || arg2 > 1) {
67919 + if (arg2 > 1) {
67920 error = -EINVAL;
67921 break;
67922 }
67923 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
67924 index ae27196..7506d69 100644
67925 --- a/kernel/sysctl.c
67926 +++ b/kernel/sysctl.c
67927 @@ -86,6 +86,13 @@
67928
67929
67930 #if defined(CONFIG_SYSCTL)
67931 +#include <linux/grsecurity.h>
67932 +#include <linux/grinternal.h>
67933 +
67934 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
67935 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
67936 + const int op);
67937 +extern int gr_handle_chroot_sysctl(const int op);
67938
67939 /* External variables not in a header file. */
67940 extern int sysctl_overcommit_memory;
67941 @@ -191,6 +198,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
67942 }
67943
67944 #endif
67945 +extern struct ctl_table grsecurity_table[];
67946
67947 static struct ctl_table root_table[];
67948 static struct ctl_table_root sysctl_table_root;
67949 @@ -220,6 +228,20 @@ extern struct ctl_table epoll_table[];
67950 int sysctl_legacy_va_layout;
67951 #endif
67952
67953 +#ifdef CONFIG_PAX_SOFTMODE
67954 +static ctl_table pax_table[] = {
67955 + {
67956 + .procname = "softmode",
67957 + .data = &pax_softmode,
67958 + .maxlen = sizeof(unsigned int),
67959 + .mode = 0600,
67960 + .proc_handler = &proc_dointvec,
67961 + },
67962 +
67963 + { }
67964 +};
67965 +#endif
67966 +
67967 /* The default sysctl tables: */
67968
67969 static struct ctl_table root_table[] = {
67970 @@ -266,6 +288,22 @@ static int max_extfrag_threshold = 1000;
67971 #endif
67972
67973 static struct ctl_table kern_table[] = {
67974 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
67975 + {
67976 + .procname = "grsecurity",
67977 + .mode = 0500,
67978 + .child = grsecurity_table,
67979 + },
67980 +#endif
67981 +
67982 +#ifdef CONFIG_PAX_SOFTMODE
67983 + {
67984 + .procname = "pax",
67985 + .mode = 0500,
67986 + .child = pax_table,
67987 + },
67988 +#endif
67989 +
67990 {
67991 .procname = "sched_child_runs_first",
67992 .data = &sysctl_sched_child_runs_first,
67993 @@ -550,7 +588,7 @@ static struct ctl_table kern_table[] = {
67994 .data = &modprobe_path,
67995 .maxlen = KMOD_PATH_LEN,
67996 .mode = 0644,
67997 - .proc_handler = proc_dostring,
67998 + .proc_handler = proc_dostring_modpriv,
67999 },
68000 {
68001 .procname = "modules_disabled",
68002 @@ -717,16 +755,20 @@ static struct ctl_table kern_table[] = {
68003 .extra1 = &zero,
68004 .extra2 = &one,
68005 },
68006 +#endif
68007 {
68008 .procname = "kptr_restrict",
68009 .data = &kptr_restrict,
68010 .maxlen = sizeof(int),
68011 .mode = 0644,
68012 .proc_handler = proc_dmesg_restrict,
68013 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68014 + .extra1 = &two,
68015 +#else
68016 .extra1 = &zero,
68017 +#endif
68018 .extra2 = &two,
68019 },
68020 -#endif
68021 {
68022 .procname = "ngroups_max",
68023 .data = &ngroups_max,
68024 @@ -1216,6 +1258,13 @@ static struct ctl_table vm_table[] = {
68025 .proc_handler = proc_dointvec_minmax,
68026 .extra1 = &zero,
68027 },
68028 + {
68029 + .procname = "heap_stack_gap",
68030 + .data = &sysctl_heap_stack_gap,
68031 + .maxlen = sizeof(sysctl_heap_stack_gap),
68032 + .mode = 0644,
68033 + .proc_handler = proc_doulongvec_minmax,
68034 + },
68035 #else
68036 {
68037 .procname = "nr_trim_pages",
68038 @@ -1720,6 +1769,17 @@ static int test_perm(int mode, int op)
68039 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
68040 {
68041 int mode;
68042 + int error;
68043 +
68044 + if (table->parent != NULL && table->parent->procname != NULL &&
68045 + table->procname != NULL &&
68046 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
68047 + return -EACCES;
68048 + if (gr_handle_chroot_sysctl(op))
68049 + return -EACCES;
68050 + error = gr_handle_sysctl(table, op);
68051 + if (error)
68052 + return error;
68053
68054 if (root->permissions)
68055 mode = root->permissions(root, current->nsproxy, table);
68056 @@ -2124,6 +2184,16 @@ int proc_dostring(struct ctl_table *table, int write,
68057 buffer, lenp, ppos);
68058 }
68059
68060 +int proc_dostring_modpriv(struct ctl_table *table, int write,
68061 + void __user *buffer, size_t *lenp, loff_t *ppos)
68062 +{
68063 + if (write && !capable(CAP_SYS_MODULE))
68064 + return -EPERM;
68065 +
68066 + return _proc_do_string(table->data, table->maxlen, write,
68067 + buffer, lenp, ppos);
68068 +}
68069 +
68070 static size_t proc_skip_spaces(char **buf)
68071 {
68072 size_t ret;
68073 @@ -2229,6 +2299,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
68074 len = strlen(tmp);
68075 if (len > *size)
68076 len = *size;
68077 + if (len > sizeof(tmp))
68078 + len = sizeof(tmp);
68079 if (copy_to_user(*buf, tmp, len))
68080 return -EFAULT;
68081 *size -= len;
68082 @@ -2545,8 +2617,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
68083 *i = val;
68084 } else {
68085 val = convdiv * (*i) / convmul;
68086 - if (!first)
68087 + if (!first) {
68088 err = proc_put_char(&buffer, &left, '\t');
68089 + if (err)
68090 + break;
68091 + }
68092 err = proc_put_long(&buffer, &left, val, false);
68093 if (err)
68094 break;
68095 @@ -2941,6 +3016,12 @@ int proc_dostring(struct ctl_table *table, int write,
68096 return -ENOSYS;
68097 }
68098
68099 +int proc_dostring_modpriv(struct ctl_table *table, int write,
68100 + void __user *buffer, size_t *lenp, loff_t *ppos)
68101 +{
68102 + return -ENOSYS;
68103 +}
68104 +
68105 int proc_dointvec(struct ctl_table *table, int write,
68106 void __user *buffer, size_t *lenp, loff_t *ppos)
68107 {
68108 @@ -2997,6 +3078,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
68109 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
68110 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
68111 EXPORT_SYMBOL(proc_dostring);
68112 +EXPORT_SYMBOL(proc_dostring_modpriv);
68113 EXPORT_SYMBOL(proc_doulongvec_minmax);
68114 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
68115 EXPORT_SYMBOL(register_sysctl_table);
68116 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
68117 index a650694..aaeeb20 100644
68118 --- a/kernel/sysctl_binary.c
68119 +++ b/kernel/sysctl_binary.c
68120 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
68121 int i;
68122
68123 set_fs(KERNEL_DS);
68124 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
68125 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
68126 set_fs(old_fs);
68127 if (result < 0)
68128 goto out_kfree;
68129 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
68130 }
68131
68132 set_fs(KERNEL_DS);
68133 - result = vfs_write(file, buffer, str - buffer, &pos);
68134 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
68135 set_fs(old_fs);
68136 if (result < 0)
68137 goto out_kfree;
68138 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
68139 int i;
68140
68141 set_fs(KERNEL_DS);
68142 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
68143 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
68144 set_fs(old_fs);
68145 if (result < 0)
68146 goto out_kfree;
68147 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
68148 }
68149
68150 set_fs(KERNEL_DS);
68151 - result = vfs_write(file, buffer, str - buffer, &pos);
68152 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
68153 set_fs(old_fs);
68154 if (result < 0)
68155 goto out_kfree;
68156 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
68157 int i;
68158
68159 set_fs(KERNEL_DS);
68160 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
68161 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
68162 set_fs(old_fs);
68163 if (result < 0)
68164 goto out;
68165 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
68166 __le16 dnaddr;
68167
68168 set_fs(KERNEL_DS);
68169 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
68170 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
68171 set_fs(old_fs);
68172 if (result < 0)
68173 goto out;
68174 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
68175 le16_to_cpu(dnaddr) & 0x3ff);
68176
68177 set_fs(KERNEL_DS);
68178 - result = vfs_write(file, buf, len, &pos);
68179 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
68180 set_fs(old_fs);
68181 if (result < 0)
68182 goto out;
68183 diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
68184 index 362da65..ab8ef8c 100644
68185 --- a/kernel/sysctl_check.c
68186 +++ b/kernel/sysctl_check.c
68187 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
68188 set_fail(&fail, table, "Directory with extra2");
68189 } else {
68190 if ((table->proc_handler == proc_dostring) ||
68191 + (table->proc_handler == proc_dostring_modpriv) ||
68192 (table->proc_handler == proc_dointvec) ||
68193 (table->proc_handler == proc_dointvec_minmax) ||
68194 (table->proc_handler == proc_dointvec_jiffies) ||
68195 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
68196 index e660464..c8b9e67 100644
68197 --- a/kernel/taskstats.c
68198 +++ b/kernel/taskstats.c
68199 @@ -27,9 +27,12 @@
68200 #include <linux/cgroup.h>
68201 #include <linux/fs.h>
68202 #include <linux/file.h>
68203 +#include <linux/grsecurity.h>
68204 #include <net/genetlink.h>
68205 #include <linux/atomic.h>
68206
68207 +extern int gr_is_taskstats_denied(int pid);
68208 +
68209 /*
68210 * Maximum length of a cpumask that can be specified in
68211 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
68212 @@ -556,6 +559,9 @@ err:
68213
68214 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
68215 {
68216 + if (gr_is_taskstats_denied(current->pid))
68217 + return -EACCES;
68218 +
68219 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
68220 return cmd_attr_register_cpumask(info);
68221 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
68222 diff --git a/kernel/time.c b/kernel/time.c
68223 index 73e416d..cfc6f69 100644
68224 --- a/kernel/time.c
68225 +++ b/kernel/time.c
68226 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
68227 return error;
68228
68229 if (tz) {
68230 + /* we log in do_settimeofday called below, so don't log twice
68231 + */
68232 + if (!tv)
68233 + gr_log_timechange();
68234 +
68235 /* SMP safe, global irq locking makes it work. */
68236 sys_tz = *tz;
68237 update_vsyscall_tz();
68238 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
68239 index 8a46f5d..bbe6f9c 100644
68240 --- a/kernel/time/alarmtimer.c
68241 +++ b/kernel/time/alarmtimer.c
68242 @@ -773,7 +773,7 @@ static int __init alarmtimer_init(void)
68243 struct platform_device *pdev;
68244 int error = 0;
68245 int i;
68246 - struct k_clock alarm_clock = {
68247 + static struct k_clock alarm_clock = {
68248 .clock_getres = alarm_clock_getres,
68249 .clock_get = alarm_clock_get,
68250 .timer_create = alarm_timer_create,
68251 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
68252 index fd4a7b1..fae5c2a 100644
68253 --- a/kernel/time/tick-broadcast.c
68254 +++ b/kernel/time/tick-broadcast.c
68255 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
68256 * then clear the broadcast bit.
68257 */
68258 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
68259 - int cpu = smp_processor_id();
68260 + cpu = smp_processor_id();
68261
68262 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
68263 tick_broadcast_clear_oneshot(cpu);
68264 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
68265 index 2378413..be455fd 100644
68266 --- a/kernel/time/timekeeping.c
68267 +++ b/kernel/time/timekeeping.c
68268 @@ -14,6 +14,7 @@
68269 #include <linux/init.h>
68270 #include <linux/mm.h>
68271 #include <linux/sched.h>
68272 +#include <linux/grsecurity.h>
68273 #include <linux/syscore_ops.h>
68274 #include <linux/clocksource.h>
68275 #include <linux/jiffies.h>
68276 @@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
68277 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
68278 return -EINVAL;
68279
68280 + gr_log_timechange();
68281 +
68282 write_seqlock_irqsave(&xtime_lock, flags);
68283
68284 timekeeping_forward_now();
68285 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
68286 index 3258455..f35227d 100644
68287 --- a/kernel/time/timer_list.c
68288 +++ b/kernel/time/timer_list.c
68289 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
68290
68291 static void print_name_offset(struct seq_file *m, void *sym)
68292 {
68293 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68294 + SEQ_printf(m, "<%p>", NULL);
68295 +#else
68296 char symname[KSYM_NAME_LEN];
68297
68298 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
68299 SEQ_printf(m, "<%pK>", sym);
68300 else
68301 SEQ_printf(m, "%s", symname);
68302 +#endif
68303 }
68304
68305 static void
68306 @@ -112,7 +116,11 @@ next_one:
68307 static void
68308 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
68309 {
68310 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68311 + SEQ_printf(m, " .base: %p\n", NULL);
68312 +#else
68313 SEQ_printf(m, " .base: %pK\n", base);
68314 +#endif
68315 SEQ_printf(m, " .index: %d\n",
68316 base->index);
68317 SEQ_printf(m, " .resolution: %Lu nsecs\n",
68318 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
68319 {
68320 struct proc_dir_entry *pe;
68321
68322 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68323 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
68324 +#else
68325 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
68326 +#endif
68327 if (!pe)
68328 return -ENOMEM;
68329 return 0;
68330 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
68331 index 0b537f2..9e71eca 100644
68332 --- a/kernel/time/timer_stats.c
68333 +++ b/kernel/time/timer_stats.c
68334 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
68335 static unsigned long nr_entries;
68336 static struct entry entries[MAX_ENTRIES];
68337
68338 -static atomic_t overflow_count;
68339 +static atomic_unchecked_t overflow_count;
68340
68341 /*
68342 * The entries are in a hash-table, for fast lookup:
68343 @@ -140,7 +140,7 @@ static void reset_entries(void)
68344 nr_entries = 0;
68345 memset(entries, 0, sizeof(entries));
68346 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
68347 - atomic_set(&overflow_count, 0);
68348 + atomic_set_unchecked(&overflow_count, 0);
68349 }
68350
68351 static struct entry *alloc_entry(void)
68352 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
68353 if (likely(entry))
68354 entry->count++;
68355 else
68356 - atomic_inc(&overflow_count);
68357 + atomic_inc_unchecked(&overflow_count);
68358
68359 out_unlock:
68360 raw_spin_unlock_irqrestore(lock, flags);
68361 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
68362
68363 static void print_name_offset(struct seq_file *m, unsigned long addr)
68364 {
68365 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68366 + seq_printf(m, "<%p>", NULL);
68367 +#else
68368 char symname[KSYM_NAME_LEN];
68369
68370 if (lookup_symbol_name(addr, symname) < 0)
68371 seq_printf(m, "<%p>", (void *)addr);
68372 else
68373 seq_printf(m, "%s", symname);
68374 +#endif
68375 }
68376
68377 static int tstats_show(struct seq_file *m, void *v)
68378 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
68379
68380 seq_puts(m, "Timer Stats Version: v0.2\n");
68381 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
68382 - if (atomic_read(&overflow_count))
68383 + if (atomic_read_unchecked(&overflow_count))
68384 seq_printf(m, "Overflow: %d entries\n",
68385 - atomic_read(&overflow_count));
68386 + atomic_read_unchecked(&overflow_count));
68387
68388 for (i = 0; i < nr_entries; i++) {
68389 entry = entries + i;
68390 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
68391 {
68392 struct proc_dir_entry *pe;
68393
68394 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68395 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
68396 +#else
68397 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
68398 +#endif
68399 if (!pe)
68400 return -ENOMEM;
68401 return 0;
68402 diff --git a/kernel/timer.c b/kernel/timer.c
68403 index 9c3c62b..441690e 100644
68404 --- a/kernel/timer.c
68405 +++ b/kernel/timer.c
68406 @@ -1304,7 +1304,7 @@ void update_process_times(int user_tick)
68407 /*
68408 * This function runs timers and the timer-tq in bottom half context.
68409 */
68410 -static void run_timer_softirq(struct softirq_action *h)
68411 +static void run_timer_softirq(void)
68412 {
68413 struct tvec_base *base = __this_cpu_read(tvec_bases);
68414
68415 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
68416 index 16fc34a..efd8bb8 100644
68417 --- a/kernel/trace/blktrace.c
68418 +++ b/kernel/trace/blktrace.c
68419 @@ -324,7 +324,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
68420 struct blk_trace *bt = filp->private_data;
68421 char buf[16];
68422
68423 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
68424 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
68425
68426 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
68427 }
68428 @@ -389,7 +389,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
68429 return 1;
68430
68431 bt = buf->chan->private_data;
68432 - atomic_inc(&bt->dropped);
68433 + atomic_inc_unchecked(&bt->dropped);
68434 return 0;
68435 }
68436
68437 @@ -490,7 +490,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
68438
68439 bt->dir = dir;
68440 bt->dev = dev;
68441 - atomic_set(&bt->dropped, 0);
68442 + atomic_set_unchecked(&bt->dropped, 0);
68443
68444 ret = -EIO;
68445 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
68446 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
68447 index 25b4f4d..6f4772d 100644
68448 --- a/kernel/trace/ftrace.c
68449 +++ b/kernel/trace/ftrace.c
68450 @@ -1587,12 +1587,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
68451 if (unlikely(ftrace_disabled))
68452 return 0;
68453
68454 + ret = ftrace_arch_code_modify_prepare();
68455 + FTRACE_WARN_ON(ret);
68456 + if (ret)
68457 + return 0;
68458 +
68459 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
68460 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
68461 if (ret) {
68462 ftrace_bug(ret, ip);
68463 - return 0;
68464 }
68465 - return 1;
68466 + return ret ? 0 : 1;
68467 }
68468
68469 /*
68470 @@ -2608,7 +2613,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
68471
68472 int
68473 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
68474 - void *data)
68475 + void *data)
68476 {
68477 struct ftrace_func_probe *entry;
68478 struct ftrace_page *pg;
68479 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
68480 index f2bd275..adaf3a2 100644
68481 --- a/kernel/trace/trace.c
68482 +++ b/kernel/trace/trace.c
68483 @@ -4201,10 +4201,9 @@ static const struct file_operations tracing_dyn_info_fops = {
68484 };
68485 #endif
68486
68487 -static struct dentry *d_tracer;
68488 -
68489 struct dentry *tracing_init_dentry(void)
68490 {
68491 + static struct dentry *d_tracer;
68492 static int once;
68493
68494 if (d_tracer)
68495 @@ -4224,10 +4223,9 @@ struct dentry *tracing_init_dentry(void)
68496 return d_tracer;
68497 }
68498
68499 -static struct dentry *d_percpu;
68500 -
68501 struct dentry *tracing_dentry_percpu(void)
68502 {
68503 + static struct dentry *d_percpu;
68504 static int once;
68505 struct dentry *d_tracer;
68506
68507 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
68508 index c212a7f..7b02394 100644
68509 --- a/kernel/trace/trace_events.c
68510 +++ b/kernel/trace/trace_events.c
68511 @@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
68512 struct ftrace_module_file_ops {
68513 struct list_head list;
68514 struct module *mod;
68515 - struct file_operations id;
68516 - struct file_operations enable;
68517 - struct file_operations format;
68518 - struct file_operations filter;
68519 };
68520
68521 static struct ftrace_module_file_ops *
68522 @@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
68523
68524 file_ops->mod = mod;
68525
68526 - file_ops->id = ftrace_event_id_fops;
68527 - file_ops->id.owner = mod;
68528 -
68529 - file_ops->enable = ftrace_enable_fops;
68530 - file_ops->enable.owner = mod;
68531 -
68532 - file_ops->filter = ftrace_event_filter_fops;
68533 - file_ops->filter.owner = mod;
68534 -
68535 - file_ops->format = ftrace_event_format_fops;
68536 - file_ops->format.owner = mod;
68537 + pax_open_kernel();
68538 + *(void **)&mod->trace_id.owner = mod;
68539 + *(void **)&mod->trace_enable.owner = mod;
68540 + *(void **)&mod->trace_filter.owner = mod;
68541 + *(void **)&mod->trace_format.owner = mod;
68542 + pax_close_kernel();
68543
68544 list_add(&file_ops->list, &ftrace_module_file_list);
68545
68546 @@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
68547
68548 for_each_event(call, start, end) {
68549 __trace_add_event_call(*call, mod,
68550 - &file_ops->id, &file_ops->enable,
68551 - &file_ops->filter, &file_ops->format);
68552 + &mod->trace_id, &mod->trace_enable,
68553 + &mod->trace_filter, &mod->trace_format);
68554 }
68555 }
68556
68557 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
68558 index 00d527c..7c5b1a3 100644
68559 --- a/kernel/trace/trace_kprobe.c
68560 +++ b/kernel/trace/trace_kprobe.c
68561 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
68562 long ret;
68563 int maxlen = get_rloc_len(*(u32 *)dest);
68564 u8 *dst = get_rloc_data(dest);
68565 - u8 *src = addr;
68566 + const u8 __user *src = (const u8 __force_user *)addr;
68567 mm_segment_t old_fs = get_fs();
68568 if (!maxlen)
68569 return;
68570 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
68571 pagefault_disable();
68572 do
68573 ret = __copy_from_user_inatomic(dst++, src++, 1);
68574 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
68575 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
68576 dst[-1] = '\0';
68577 pagefault_enable();
68578 set_fs(old_fs);
68579 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
68580 ((u8 *)get_rloc_data(dest))[0] = '\0';
68581 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
68582 } else
68583 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
68584 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
68585 get_rloc_offs(*(u32 *)dest));
68586 }
68587 /* Return the length of string -- including null terminal byte */
68588 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
68589 set_fs(KERNEL_DS);
68590 pagefault_disable();
68591 do {
68592 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
68593 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
68594 len++;
68595 } while (c && ret == 0 && len < MAX_STRING_SIZE);
68596 pagefault_enable();
68597 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
68598 index fd3c8aa..5f324a6 100644
68599 --- a/kernel/trace/trace_mmiotrace.c
68600 +++ b/kernel/trace/trace_mmiotrace.c
68601 @@ -24,7 +24,7 @@ struct header_iter {
68602 static struct trace_array *mmio_trace_array;
68603 static bool overrun_detected;
68604 static unsigned long prev_overruns;
68605 -static atomic_t dropped_count;
68606 +static atomic_unchecked_t dropped_count;
68607
68608 static void mmio_reset_data(struct trace_array *tr)
68609 {
68610 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
68611
68612 static unsigned long count_overruns(struct trace_iterator *iter)
68613 {
68614 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
68615 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
68616 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
68617
68618 if (over > prev_overruns)
68619 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
68620 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
68621 sizeof(*entry), 0, pc);
68622 if (!event) {
68623 - atomic_inc(&dropped_count);
68624 + atomic_inc_unchecked(&dropped_count);
68625 return;
68626 }
68627 entry = ring_buffer_event_data(event);
68628 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
68629 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
68630 sizeof(*entry), 0, pc);
68631 if (!event) {
68632 - atomic_inc(&dropped_count);
68633 + atomic_inc_unchecked(&dropped_count);
68634 return;
68635 }
68636 entry = ring_buffer_event_data(event);
68637 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
68638 index 5199930..26c73a0 100644
68639 --- a/kernel/trace/trace_output.c
68640 +++ b/kernel/trace/trace_output.c
68641 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
68642
68643 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
68644 if (!IS_ERR(p)) {
68645 - p = mangle_path(s->buffer + s->len, p, "\n");
68646 + p = mangle_path(s->buffer + s->len, p, "\n\\");
68647 if (p) {
68648 s->len = p - s->buffer;
68649 return 1;
68650 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
68651 index 77575b3..6e623d1 100644
68652 --- a/kernel/trace/trace_stack.c
68653 +++ b/kernel/trace/trace_stack.c
68654 @@ -50,7 +50,7 @@ static inline void check_stack(void)
68655 return;
68656
68657 /* we do not handle interrupt stacks yet */
68658 - if (!object_is_on_stack(&this_size))
68659 + if (!object_starts_on_stack(&this_size))
68660 return;
68661
68662 local_irq_save(flags);
68663 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
68664 index 209b379..7f76423 100644
68665 --- a/kernel/trace/trace_workqueue.c
68666 +++ b/kernel/trace/trace_workqueue.c
68667 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
68668 int cpu;
68669 pid_t pid;
68670 /* Can be inserted from interrupt or user context, need to be atomic */
68671 - atomic_t inserted;
68672 + atomic_unchecked_t inserted;
68673 /*
68674 * Don't need to be atomic, works are serialized in a single workqueue thread
68675 * on a single CPU.
68676 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
68677 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
68678 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
68679 if (node->pid == wq_thread->pid) {
68680 - atomic_inc(&node->inserted);
68681 + atomic_inc_unchecked(&node->inserted);
68682 goto found;
68683 }
68684 }
68685 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
68686 tsk = get_pid_task(pid, PIDTYPE_PID);
68687 if (tsk) {
68688 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
68689 - atomic_read(&cws->inserted), cws->executed,
68690 + atomic_read_unchecked(&cws->inserted), cws->executed,
68691 tsk->comm);
68692 put_task_struct(tsk);
68693 }
68694 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
68695 index 82928f5..92da771 100644
68696 --- a/lib/Kconfig.debug
68697 +++ b/lib/Kconfig.debug
68698 @@ -1103,6 +1103,7 @@ config LATENCYTOP
68699 depends on DEBUG_KERNEL
68700 depends on STACKTRACE_SUPPORT
68701 depends on PROC_FS
68702 + depends on !GRKERNSEC_HIDESYM
68703 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
68704 select KALLSYMS
68705 select KALLSYMS_ALL
68706 diff --git a/lib/bitmap.c b/lib/bitmap.c
68707 index 0d4a127..33a06c7 100644
68708 --- a/lib/bitmap.c
68709 +++ b/lib/bitmap.c
68710 @@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
68711 {
68712 int c, old_c, totaldigits, ndigits, nchunks, nbits;
68713 u32 chunk;
68714 - const char __user __force *ubuf = (const char __user __force *)buf;
68715 + const char __user *ubuf = (const char __force_user *)buf;
68716
68717 bitmap_zero(maskp, nmaskbits);
68718
68719 @@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
68720 {
68721 if (!access_ok(VERIFY_READ, ubuf, ulen))
68722 return -EFAULT;
68723 - return __bitmap_parse((const char __force *)ubuf,
68724 + return __bitmap_parse((const char __force_kernel *)ubuf,
68725 ulen, 1, maskp, nmaskbits);
68726
68727 }
68728 @@ -596,7 +596,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
68729 {
68730 unsigned a, b;
68731 int c, old_c, totaldigits;
68732 - const char __user __force *ubuf = (const char __user __force *)buf;
68733 + const char __user *ubuf = (const char __force_user *)buf;
68734 int exp_digit, in_range;
68735
68736 totaldigits = c = 0;
68737 @@ -696,7 +696,7 @@ int bitmap_parselist_user(const char __user *ubuf,
68738 {
68739 if (!access_ok(VERIFY_READ, ubuf, ulen))
68740 return -EFAULT;
68741 - return __bitmap_parselist((const char __force *)ubuf,
68742 + return __bitmap_parselist((const char __force_kernel *)ubuf,
68743 ulen, 1, maskp, nmaskbits);
68744 }
68745 EXPORT_SYMBOL(bitmap_parselist_user);
68746 diff --git a/lib/bug.c b/lib/bug.c
68747 index 1955209..cbbb2ad 100644
68748 --- a/lib/bug.c
68749 +++ b/lib/bug.c
68750 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
68751 return BUG_TRAP_TYPE_NONE;
68752
68753 bug = find_bug(bugaddr);
68754 + if (!bug)
68755 + return BUG_TRAP_TYPE_NONE;
68756
68757 file = NULL;
68758 line = 0;
68759 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
68760 index a78b7c6..2c73084 100644
68761 --- a/lib/debugobjects.c
68762 +++ b/lib/debugobjects.c
68763 @@ -284,7 +284,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
68764 if (limit > 4)
68765 return;
68766
68767 - is_on_stack = object_is_on_stack(addr);
68768 + is_on_stack = object_starts_on_stack(addr);
68769 if (is_on_stack == onstack)
68770 return;
68771
68772 diff --git a/lib/devres.c b/lib/devres.c
68773 index 7c0e953..f642b5c 100644
68774 --- a/lib/devres.c
68775 +++ b/lib/devres.c
68776 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
68777 void devm_iounmap(struct device *dev, void __iomem *addr)
68778 {
68779 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
68780 - (void *)addr));
68781 + (void __force *)addr));
68782 iounmap(addr);
68783 }
68784 EXPORT_SYMBOL(devm_iounmap);
68785 @@ -141,7 +141,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
68786 {
68787 ioport_unmap(addr);
68788 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
68789 - devm_ioport_map_match, (void *)addr));
68790 + devm_ioport_map_match, (void __force *)addr));
68791 }
68792 EXPORT_SYMBOL(devm_ioport_unmap);
68793
68794 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
68795 index fea790a..ebb0e82 100644
68796 --- a/lib/dma-debug.c
68797 +++ b/lib/dma-debug.c
68798 @@ -925,7 +925,7 @@ out:
68799
68800 static void check_for_stack(struct device *dev, void *addr)
68801 {
68802 - if (object_is_on_stack(addr))
68803 + if (object_starts_on_stack(addr))
68804 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
68805 "stack [addr=%p]\n", addr);
68806 }
68807 diff --git a/lib/extable.c b/lib/extable.c
68808 index 4cac81e..63e9b8f 100644
68809 --- a/lib/extable.c
68810 +++ b/lib/extable.c
68811 @@ -13,6 +13,7 @@
68812 #include <linux/init.h>
68813 #include <linux/sort.h>
68814 #include <asm/uaccess.h>
68815 +#include <asm/pgtable.h>
68816
68817 #ifndef ARCH_HAS_SORT_EXTABLE
68818 /*
68819 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
68820 void sort_extable(struct exception_table_entry *start,
68821 struct exception_table_entry *finish)
68822 {
68823 + pax_open_kernel();
68824 sort(start, finish - start, sizeof(struct exception_table_entry),
68825 cmp_ex, NULL);
68826 + pax_close_kernel();
68827 }
68828
68829 #ifdef CONFIG_MODULES
68830 diff --git a/lib/inflate.c b/lib/inflate.c
68831 index 013a761..c28f3fc 100644
68832 --- a/lib/inflate.c
68833 +++ b/lib/inflate.c
68834 @@ -269,7 +269,7 @@ static void free(void *where)
68835 malloc_ptr = free_mem_ptr;
68836 }
68837 #else
68838 -#define malloc(a) kmalloc(a, GFP_KERNEL)
68839 +#define malloc(a) kmalloc((a), GFP_KERNEL)
68840 #define free(a) kfree(a)
68841 #endif
68842
68843 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
68844 index bd2bea9..6b3c95e 100644
68845 --- a/lib/is_single_threaded.c
68846 +++ b/lib/is_single_threaded.c
68847 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
68848 struct task_struct *p, *t;
68849 bool ret;
68850
68851 + if (!mm)
68852 + return true;
68853 +
68854 if (atomic_read(&task->signal->live) != 1)
68855 return false;
68856
68857 diff --git a/lib/kref.c b/lib/kref.c
68858 index 3efb882..8492f4c 100644
68859 --- a/lib/kref.c
68860 +++ b/lib/kref.c
68861 @@ -52,7 +52,7 @@ void kref_get(struct kref *kref)
68862 */
68863 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
68864 {
68865 - WARN_ON(release == NULL);
68866 + BUG_ON(release == NULL);
68867 WARN_ON(release == (void (*)(struct kref *))kfree);
68868
68869 if (atomic_dec_and_test(&kref->refcount)) {
68870 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
68871 index d9df745..e73c2fe 100644
68872 --- a/lib/radix-tree.c
68873 +++ b/lib/radix-tree.c
68874 @@ -80,7 +80,7 @@ struct radix_tree_preload {
68875 int nr;
68876 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
68877 };
68878 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
68879 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
68880
68881 static inline void *ptr_to_indirect(void *ptr)
68882 {
68883 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
68884 index 993599e..f1dbc14 100644
68885 --- a/lib/vsprintf.c
68886 +++ b/lib/vsprintf.c
68887 @@ -16,6 +16,9 @@
68888 * - scnprintf and vscnprintf
68889 */
68890
68891 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68892 +#define __INCLUDED_BY_HIDESYM 1
68893 +#endif
68894 #include <stdarg.h>
68895 #include <linux/module.h>
68896 #include <linux/types.h>
68897 @@ -413,7 +416,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
68898 char sym[KSYM_SYMBOL_LEN];
68899 if (ext == 'B')
68900 sprint_backtrace(sym, value);
68901 - else if (ext != 'f' && ext != 's')
68902 + else if (ext != 'f' && ext != 's' && ext != 'a')
68903 sprint_symbol(sym, value);
68904 else
68905 kallsyms_lookup(value, NULL, NULL, NULL, sym);
68906 @@ -777,7 +780,11 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
68907 return string(buf, end, uuid, spec);
68908 }
68909
68910 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68911 +int kptr_restrict __read_mostly = 2;
68912 +#else
68913 int kptr_restrict __read_mostly;
68914 +#endif
68915
68916 /*
68917 * Show a '%p' thing. A kernel extension is that the '%p' is followed
68918 @@ -791,6 +798,8 @@ int kptr_restrict __read_mostly;
68919 * - 'S' For symbolic direct pointers with offset
68920 * - 's' For symbolic direct pointers without offset
68921 * - 'B' For backtraced symbolic direct pointers with offset
68922 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
68923 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
68924 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
68925 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
68926 * - 'M' For a 6-byte MAC address, it prints the address in the
68927 @@ -835,12 +844,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
68928 {
68929 if (!ptr && *fmt != 'K') {
68930 /*
68931 - * Print (null) with the same width as a pointer so it makes
68932 + * Print (nil) with the same width as a pointer so it makes
68933 * tabular output look nice.
68934 */
68935 if (spec.field_width == -1)
68936 spec.field_width = 2 * sizeof(void *);
68937 - return string(buf, end, "(null)", spec);
68938 + return string(buf, end, "(nil)", spec);
68939 }
68940
68941 switch (*fmt) {
68942 @@ -850,6 +859,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
68943 /* Fallthrough */
68944 case 'S':
68945 case 's':
68946 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68947 + break;
68948 +#else
68949 + return symbol_string(buf, end, ptr, spec, *fmt);
68950 +#endif
68951 + case 'A':
68952 + case 'a':
68953 case 'B':
68954 return symbol_string(buf, end, ptr, spec, *fmt);
68955 case 'R':
68956 @@ -878,9 +894,15 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
68957 case 'U':
68958 return uuid_string(buf, end, ptr, spec, fmt);
68959 case 'V':
68960 - return buf + vsnprintf(buf, end > buf ? end - buf : 0,
68961 - ((struct va_format *)ptr)->fmt,
68962 - *(((struct va_format *)ptr)->va));
68963 + {
68964 + va_list va;
68965 +
68966 + va_copy(va, *((struct va_format *)ptr)->va);
68967 + buf += vsnprintf(buf, end > buf ? end - buf : 0,
68968 + ((struct va_format *)ptr)->fmt, va);
68969 + va_end(va);
68970 + return buf;
68971 + }
68972 case 'K':
68973 /*
68974 * %pK cannot be used in IRQ context because its test
68975 @@ -1608,11 +1630,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
68976 typeof(type) value; \
68977 if (sizeof(type) == 8) { \
68978 args = PTR_ALIGN(args, sizeof(u32)); \
68979 - *(u32 *)&value = *(u32 *)args; \
68980 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
68981 + *(u32 *)&value = *(const u32 *)args; \
68982 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
68983 } else { \
68984 args = PTR_ALIGN(args, sizeof(type)); \
68985 - value = *(typeof(type) *)args; \
68986 + value = *(const typeof(type) *)args; \
68987 } \
68988 args += sizeof(type); \
68989 value; \
68990 @@ -1675,7 +1697,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
68991 case FORMAT_TYPE_STR: {
68992 const char *str_arg = args;
68993 args += strlen(str_arg) + 1;
68994 - str = string(str, end, (char *)str_arg, spec);
68995 + str = string(str, end, str_arg, spec);
68996 break;
68997 }
68998
68999 diff --git a/localversion-grsec b/localversion-grsec
69000 new file mode 100644
69001 index 0000000..7cd6065
69002 --- /dev/null
69003 +++ b/localversion-grsec
69004 @@ -0,0 +1 @@
69005 +-grsec
69006 diff --git a/mm/Kconfig b/mm/Kconfig
69007 index 011b110..b492af2 100644
69008 --- a/mm/Kconfig
69009 +++ b/mm/Kconfig
69010 @@ -241,10 +241,10 @@ config KSM
69011 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
69012
69013 config DEFAULT_MMAP_MIN_ADDR
69014 - int "Low address space to protect from user allocation"
69015 + int "Low address space to protect from user allocation"
69016 depends on MMU
69017 - default 4096
69018 - help
69019 + default 65536
69020 + help
69021 This is the portion of low virtual memory which should be protected
69022 from userspace allocation. Keeping a user from writing to low pages
69023 can help reduce the impact of kernel NULL pointer bugs.
69024 diff --git a/mm/filemap.c b/mm/filemap.c
69025 index 03c5b0e..a01e793 100644
69026 --- a/mm/filemap.c
69027 +++ b/mm/filemap.c
69028 @@ -1770,7 +1770,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
69029 struct address_space *mapping = file->f_mapping;
69030
69031 if (!mapping->a_ops->readpage)
69032 - return -ENOEXEC;
69033 + return -ENODEV;
69034 file_accessed(file);
69035 vma->vm_ops = &generic_file_vm_ops;
69036 vma->vm_flags |= VM_CAN_NONLINEAR;
69037 @@ -2176,6 +2176,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
69038 *pos = i_size_read(inode);
69039
69040 if (limit != RLIM_INFINITY) {
69041 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
69042 if (*pos >= limit) {
69043 send_sig(SIGXFSZ, current, 0);
69044 return -EFBIG;
69045 diff --git a/mm/fremap.c b/mm/fremap.c
69046 index 9ed4fd4..c42648d 100644
69047 --- a/mm/fremap.c
69048 +++ b/mm/fremap.c
69049 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
69050 retry:
69051 vma = find_vma(mm, start);
69052
69053 +#ifdef CONFIG_PAX_SEGMEXEC
69054 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
69055 + goto out;
69056 +#endif
69057 +
69058 /*
69059 * Make sure the vma is shared, that it supports prefaulting,
69060 * and that the remapped range is valid and fully within
69061 diff --git a/mm/highmem.c b/mm/highmem.c
69062 index 57d82c6..e9e0552 100644
69063 --- a/mm/highmem.c
69064 +++ b/mm/highmem.c
69065 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
69066 * So no dangers, even with speculative execution.
69067 */
69068 page = pte_page(pkmap_page_table[i]);
69069 + pax_open_kernel();
69070 pte_clear(&init_mm, (unsigned long)page_address(page),
69071 &pkmap_page_table[i]);
69072 -
69073 + pax_close_kernel();
69074 set_page_address(page, NULL);
69075 need_flush = 1;
69076 }
69077 @@ -186,9 +187,11 @@ start:
69078 }
69079 }
69080 vaddr = PKMAP_ADDR(last_pkmap_nr);
69081 +
69082 + pax_open_kernel();
69083 set_pte_at(&init_mm, vaddr,
69084 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
69085 -
69086 + pax_close_kernel();
69087 pkmap_count[last_pkmap_nr] = 1;
69088 set_page_address(page, (void *)vaddr);
69089
69090 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
69091 index 33141f5..e56bef9 100644
69092 --- a/mm/huge_memory.c
69093 +++ b/mm/huge_memory.c
69094 @@ -703,7 +703,7 @@ out:
69095 * run pte_offset_map on the pmd, if an huge pmd could
69096 * materialize from under us from a different thread.
69097 */
69098 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
69099 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
69100 return VM_FAULT_OOM;
69101 /* if an huge pmd materialized from under us just retry later */
69102 if (unlikely(pmd_trans_huge(*pmd)))
69103 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
69104 index 2316840..b418671 100644
69105 --- a/mm/hugetlb.c
69106 +++ b/mm/hugetlb.c
69107 @@ -2347,6 +2347,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
69108 return 1;
69109 }
69110
69111 +#ifdef CONFIG_PAX_SEGMEXEC
69112 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
69113 +{
69114 + struct mm_struct *mm = vma->vm_mm;
69115 + struct vm_area_struct *vma_m;
69116 + unsigned long address_m;
69117 + pte_t *ptep_m;
69118 +
69119 + vma_m = pax_find_mirror_vma(vma);
69120 + if (!vma_m)
69121 + return;
69122 +
69123 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69124 + address_m = address + SEGMEXEC_TASK_SIZE;
69125 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
69126 + get_page(page_m);
69127 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
69128 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
69129 +}
69130 +#endif
69131 +
69132 /*
69133 * Hugetlb_cow() should be called with page lock of the original hugepage held.
69134 */
69135 @@ -2450,6 +2471,11 @@ retry_avoidcopy:
69136 make_huge_pte(vma, new_page, 1));
69137 page_remove_rmap(old_page);
69138 hugepage_add_new_anon_rmap(new_page, vma, address);
69139 +
69140 +#ifdef CONFIG_PAX_SEGMEXEC
69141 + pax_mirror_huge_pte(vma, address, new_page);
69142 +#endif
69143 +
69144 /* Make the old page be freed below */
69145 new_page = old_page;
69146 mmu_notifier_invalidate_range_end(mm,
69147 @@ -2601,6 +2627,10 @@ retry:
69148 && (vma->vm_flags & VM_SHARED)));
69149 set_huge_pte_at(mm, address, ptep, new_pte);
69150
69151 +#ifdef CONFIG_PAX_SEGMEXEC
69152 + pax_mirror_huge_pte(vma, address, page);
69153 +#endif
69154 +
69155 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
69156 /* Optimization, do the COW without a second fault */
69157 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
69158 @@ -2630,6 +2660,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69159 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
69160 struct hstate *h = hstate_vma(vma);
69161
69162 +#ifdef CONFIG_PAX_SEGMEXEC
69163 + struct vm_area_struct *vma_m;
69164 +#endif
69165 +
69166 ptep = huge_pte_offset(mm, address);
69167 if (ptep) {
69168 entry = huge_ptep_get(ptep);
69169 @@ -2641,6 +2675,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69170 VM_FAULT_SET_HINDEX(h - hstates);
69171 }
69172
69173 +#ifdef CONFIG_PAX_SEGMEXEC
69174 + vma_m = pax_find_mirror_vma(vma);
69175 + if (vma_m) {
69176 + unsigned long address_m;
69177 +
69178 + if (vma->vm_start > vma_m->vm_start) {
69179 + address_m = address;
69180 + address -= SEGMEXEC_TASK_SIZE;
69181 + vma = vma_m;
69182 + h = hstate_vma(vma);
69183 + } else
69184 + address_m = address + SEGMEXEC_TASK_SIZE;
69185 +
69186 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
69187 + return VM_FAULT_OOM;
69188 + address_m &= HPAGE_MASK;
69189 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
69190 + }
69191 +#endif
69192 +
69193 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
69194 if (!ptep)
69195 return VM_FAULT_OOM;
69196 diff --git a/mm/internal.h b/mm/internal.h
69197 index 2189af4..f2ca332 100644
69198 --- a/mm/internal.h
69199 +++ b/mm/internal.h
69200 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
69201 * in mm/page_alloc.c
69202 */
69203 extern void __free_pages_bootmem(struct page *page, unsigned int order);
69204 +extern void free_compound_page(struct page *page);
69205 extern void prep_compound_page(struct page *page, unsigned long order);
69206 #ifdef CONFIG_MEMORY_FAILURE
69207 extern bool is_free_buddy_page(struct page *page);
69208 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
69209 index f3b2a00..61da94d 100644
69210 --- a/mm/kmemleak.c
69211 +++ b/mm/kmemleak.c
69212 @@ -357,7 +357,7 @@ static void print_unreferenced(struct seq_file *seq,
69213
69214 for (i = 0; i < object->trace_len; i++) {
69215 void *ptr = (void *)object->trace[i];
69216 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
69217 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
69218 }
69219 }
69220
69221 diff --git a/mm/maccess.c b/mm/maccess.c
69222 index d53adf9..03a24bf 100644
69223 --- a/mm/maccess.c
69224 +++ b/mm/maccess.c
69225 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
69226 set_fs(KERNEL_DS);
69227 pagefault_disable();
69228 ret = __copy_from_user_inatomic(dst,
69229 - (__force const void __user *)src, size);
69230 + (const void __force_user *)src, size);
69231 pagefault_enable();
69232 set_fs(old_fs);
69233
69234 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
69235
69236 set_fs(KERNEL_DS);
69237 pagefault_disable();
69238 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
69239 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
69240 pagefault_enable();
69241 set_fs(old_fs);
69242
69243 diff --git a/mm/madvise.c b/mm/madvise.c
69244 index 74bf193..feb6fd3 100644
69245 --- a/mm/madvise.c
69246 +++ b/mm/madvise.c
69247 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
69248 pgoff_t pgoff;
69249 unsigned long new_flags = vma->vm_flags;
69250
69251 +#ifdef CONFIG_PAX_SEGMEXEC
69252 + struct vm_area_struct *vma_m;
69253 +#endif
69254 +
69255 switch (behavior) {
69256 case MADV_NORMAL:
69257 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
69258 @@ -110,6 +114,13 @@ success:
69259 /*
69260 * vm_flags is protected by the mmap_sem held in write mode.
69261 */
69262 +
69263 +#ifdef CONFIG_PAX_SEGMEXEC
69264 + vma_m = pax_find_mirror_vma(vma);
69265 + if (vma_m)
69266 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
69267 +#endif
69268 +
69269 vma->vm_flags = new_flags;
69270
69271 out:
69272 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
69273 struct vm_area_struct ** prev,
69274 unsigned long start, unsigned long end)
69275 {
69276 +
69277 +#ifdef CONFIG_PAX_SEGMEXEC
69278 + struct vm_area_struct *vma_m;
69279 +#endif
69280 +
69281 *prev = vma;
69282 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
69283 return -EINVAL;
69284 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
69285 zap_page_range(vma, start, end - start, &details);
69286 } else
69287 zap_page_range(vma, start, end - start, NULL);
69288 +
69289 +#ifdef CONFIG_PAX_SEGMEXEC
69290 + vma_m = pax_find_mirror_vma(vma);
69291 + if (vma_m) {
69292 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
69293 + struct zap_details details = {
69294 + .nonlinear_vma = vma_m,
69295 + .last_index = ULONG_MAX,
69296 + };
69297 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
69298 + } else
69299 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
69300 + }
69301 +#endif
69302 +
69303 return 0;
69304 }
69305
69306 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
69307 if (end < start)
69308 goto out;
69309
69310 +#ifdef CONFIG_PAX_SEGMEXEC
69311 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
69312 + if (end > SEGMEXEC_TASK_SIZE)
69313 + goto out;
69314 + } else
69315 +#endif
69316 +
69317 + if (end > TASK_SIZE)
69318 + goto out;
69319 +
69320 error = 0;
69321 if (end == start)
69322 goto out;
69323 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
69324 index 06d3479..0778eef 100644
69325 --- a/mm/memory-failure.c
69326 +++ b/mm/memory-failure.c
69327 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
69328
69329 int sysctl_memory_failure_recovery __read_mostly = 1;
69330
69331 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
69332 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
69333
69334 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
69335
69336 @@ -202,7 +202,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
69337 si.si_signo = SIGBUS;
69338 si.si_errno = 0;
69339 si.si_code = BUS_MCEERR_AO;
69340 - si.si_addr = (void *)addr;
69341 + si.si_addr = (void __user *)addr;
69342 #ifdef __ARCH_SI_TRAPNO
69343 si.si_trapno = trapno;
69344 #endif
69345 @@ -1010,7 +1010,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
69346 }
69347
69348 nr_pages = 1 << compound_trans_order(hpage);
69349 - atomic_long_add(nr_pages, &mce_bad_pages);
69350 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
69351
69352 /*
69353 * We need/can do nothing about count=0 pages.
69354 @@ -1040,7 +1040,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
69355 if (!PageHWPoison(hpage)
69356 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
69357 || (p != hpage && TestSetPageHWPoison(hpage))) {
69358 - atomic_long_sub(nr_pages, &mce_bad_pages);
69359 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69360 return 0;
69361 }
69362 set_page_hwpoison_huge_page(hpage);
69363 @@ -1098,7 +1098,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
69364 }
69365 if (hwpoison_filter(p)) {
69366 if (TestClearPageHWPoison(p))
69367 - atomic_long_sub(nr_pages, &mce_bad_pages);
69368 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69369 unlock_page(hpage);
69370 put_page(hpage);
69371 return 0;
69372 @@ -1315,7 +1315,7 @@ int unpoison_memory(unsigned long pfn)
69373 return 0;
69374 }
69375 if (TestClearPageHWPoison(p))
69376 - atomic_long_sub(nr_pages, &mce_bad_pages);
69377 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69378 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
69379 return 0;
69380 }
69381 @@ -1329,7 +1329,7 @@ int unpoison_memory(unsigned long pfn)
69382 */
69383 if (TestClearPageHWPoison(page)) {
69384 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
69385 - atomic_long_sub(nr_pages, &mce_bad_pages);
69386 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69387 freeit = 1;
69388 if (PageHuge(page))
69389 clear_page_hwpoison_huge_page(page);
69390 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
69391 }
69392 done:
69393 if (!PageHWPoison(hpage))
69394 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
69395 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
69396 set_page_hwpoison_huge_page(hpage);
69397 dequeue_hwpoisoned_huge_page(hpage);
69398 /* keep elevated page count for bad page */
69399 @@ -1573,7 +1573,7 @@ int soft_offline_page(struct page *page, int flags)
69400 return ret;
69401
69402 done:
69403 - atomic_long_add(1, &mce_bad_pages);
69404 + atomic_long_add_unchecked(1, &mce_bad_pages);
69405 SetPageHWPoison(page);
69406 /* keep elevated page count for bad page */
69407 return ret;
69408 diff --git a/mm/memory.c b/mm/memory.c
69409 index 829d437..3d3926a 100644
69410 --- a/mm/memory.c
69411 +++ b/mm/memory.c
69412 @@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
69413 return;
69414
69415 pmd = pmd_offset(pud, start);
69416 +
69417 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
69418 pud_clear(pud);
69419 pmd_free_tlb(tlb, pmd, start);
69420 +#endif
69421 +
69422 }
69423
69424 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
69425 @@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
69426 if (end - 1 > ceiling - 1)
69427 return;
69428
69429 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
69430 pud = pud_offset(pgd, start);
69431 pgd_clear(pgd);
69432 pud_free_tlb(tlb, pud, start);
69433 +#endif
69434 +
69435 }
69436
69437 /*
69438 @@ -1566,12 +1573,6 @@ no_page_table:
69439 return page;
69440 }
69441
69442 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
69443 -{
69444 - return stack_guard_page_start(vma, addr) ||
69445 - stack_guard_page_end(vma, addr+PAGE_SIZE);
69446 -}
69447 -
69448 /**
69449 * __get_user_pages() - pin user pages in memory
69450 * @tsk: task_struct of target task
69451 @@ -1644,10 +1645,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69452 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
69453 i = 0;
69454
69455 - do {
69456 + while (nr_pages) {
69457 struct vm_area_struct *vma;
69458
69459 - vma = find_extend_vma(mm, start);
69460 + vma = find_vma(mm, start);
69461 if (!vma && in_gate_area(mm, start)) {
69462 unsigned long pg = start & PAGE_MASK;
69463 pgd_t *pgd;
69464 @@ -1695,7 +1696,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69465 goto next_page;
69466 }
69467
69468 - if (!vma ||
69469 + if (!vma || start < vma->vm_start ||
69470 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
69471 !(vm_flags & vma->vm_flags))
69472 return i ? : -EFAULT;
69473 @@ -1722,11 +1723,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69474 int ret;
69475 unsigned int fault_flags = 0;
69476
69477 - /* For mlock, just skip the stack guard page. */
69478 - if (foll_flags & FOLL_MLOCK) {
69479 - if (stack_guard_page(vma, start))
69480 - goto next_page;
69481 - }
69482 if (foll_flags & FOLL_WRITE)
69483 fault_flags |= FAULT_FLAG_WRITE;
69484 if (nonblocking)
69485 @@ -1800,7 +1796,7 @@ next_page:
69486 start += PAGE_SIZE;
69487 nr_pages--;
69488 } while (nr_pages && start < vma->vm_end);
69489 - } while (nr_pages);
69490 + }
69491 return i;
69492 }
69493 EXPORT_SYMBOL(__get_user_pages);
69494 @@ -2007,6 +2003,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
69495 page_add_file_rmap(page);
69496 set_pte_at(mm, addr, pte, mk_pte(page, prot));
69497
69498 +#ifdef CONFIG_PAX_SEGMEXEC
69499 + pax_mirror_file_pte(vma, addr, page, ptl);
69500 +#endif
69501 +
69502 retval = 0;
69503 pte_unmap_unlock(pte, ptl);
69504 return retval;
69505 @@ -2041,10 +2041,22 @@ out:
69506 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
69507 struct page *page)
69508 {
69509 +
69510 +#ifdef CONFIG_PAX_SEGMEXEC
69511 + struct vm_area_struct *vma_m;
69512 +#endif
69513 +
69514 if (addr < vma->vm_start || addr >= vma->vm_end)
69515 return -EFAULT;
69516 if (!page_count(page))
69517 return -EINVAL;
69518 +
69519 +#ifdef CONFIG_PAX_SEGMEXEC
69520 + vma_m = pax_find_mirror_vma(vma);
69521 + if (vma_m)
69522 + vma_m->vm_flags |= VM_INSERTPAGE;
69523 +#endif
69524 +
69525 vma->vm_flags |= VM_INSERTPAGE;
69526 return insert_page(vma, addr, page, vma->vm_page_prot);
69527 }
69528 @@ -2130,6 +2142,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
69529 unsigned long pfn)
69530 {
69531 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
69532 + BUG_ON(vma->vm_mirror);
69533
69534 if (addr < vma->vm_start || addr >= vma->vm_end)
69535 return -EFAULT;
69536 @@ -2445,6 +2458,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
69537 copy_user_highpage(dst, src, va, vma);
69538 }
69539
69540 +#ifdef CONFIG_PAX_SEGMEXEC
69541 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
69542 +{
69543 + struct mm_struct *mm = vma->vm_mm;
69544 + spinlock_t *ptl;
69545 + pte_t *pte, entry;
69546 +
69547 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
69548 + entry = *pte;
69549 + if (!pte_present(entry)) {
69550 + if (!pte_none(entry)) {
69551 + BUG_ON(pte_file(entry));
69552 + free_swap_and_cache(pte_to_swp_entry(entry));
69553 + pte_clear_not_present_full(mm, address, pte, 0);
69554 + }
69555 + } else {
69556 + struct page *page;
69557 +
69558 + flush_cache_page(vma, address, pte_pfn(entry));
69559 + entry = ptep_clear_flush(vma, address, pte);
69560 + BUG_ON(pte_dirty(entry));
69561 + page = vm_normal_page(vma, address, entry);
69562 + if (page) {
69563 + update_hiwater_rss(mm);
69564 + if (PageAnon(page))
69565 + dec_mm_counter_fast(mm, MM_ANONPAGES);
69566 + else
69567 + dec_mm_counter_fast(mm, MM_FILEPAGES);
69568 + page_remove_rmap(page);
69569 + page_cache_release(page);
69570 + }
69571 + }
69572 + pte_unmap_unlock(pte, ptl);
69573 +}
69574 +
69575 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
69576 + *
69577 + * the ptl of the lower mapped page is held on entry and is not released on exit
69578 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
69579 + */
69580 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
69581 +{
69582 + struct mm_struct *mm = vma->vm_mm;
69583 + unsigned long address_m;
69584 + spinlock_t *ptl_m;
69585 + struct vm_area_struct *vma_m;
69586 + pmd_t *pmd_m;
69587 + pte_t *pte_m, entry_m;
69588 +
69589 + BUG_ON(!page_m || !PageAnon(page_m));
69590 +
69591 + vma_m = pax_find_mirror_vma(vma);
69592 + if (!vma_m)
69593 + return;
69594 +
69595 + BUG_ON(!PageLocked(page_m));
69596 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69597 + address_m = address + SEGMEXEC_TASK_SIZE;
69598 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
69599 + pte_m = pte_offset_map(pmd_m, address_m);
69600 + ptl_m = pte_lockptr(mm, pmd_m);
69601 + if (ptl != ptl_m) {
69602 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
69603 + if (!pte_none(*pte_m))
69604 + goto out;
69605 + }
69606 +
69607 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
69608 + page_cache_get(page_m);
69609 + page_add_anon_rmap(page_m, vma_m, address_m);
69610 + inc_mm_counter_fast(mm, MM_ANONPAGES);
69611 + set_pte_at(mm, address_m, pte_m, entry_m);
69612 + update_mmu_cache(vma_m, address_m, entry_m);
69613 +out:
69614 + if (ptl != ptl_m)
69615 + spin_unlock(ptl_m);
69616 + pte_unmap(pte_m);
69617 + unlock_page(page_m);
69618 +}
69619 +
69620 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
69621 +{
69622 + struct mm_struct *mm = vma->vm_mm;
69623 + unsigned long address_m;
69624 + spinlock_t *ptl_m;
69625 + struct vm_area_struct *vma_m;
69626 + pmd_t *pmd_m;
69627 + pte_t *pte_m, entry_m;
69628 +
69629 + BUG_ON(!page_m || PageAnon(page_m));
69630 +
69631 + vma_m = pax_find_mirror_vma(vma);
69632 + if (!vma_m)
69633 + return;
69634 +
69635 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69636 + address_m = address + SEGMEXEC_TASK_SIZE;
69637 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
69638 + pte_m = pte_offset_map(pmd_m, address_m);
69639 + ptl_m = pte_lockptr(mm, pmd_m);
69640 + if (ptl != ptl_m) {
69641 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
69642 + if (!pte_none(*pte_m))
69643 + goto out;
69644 + }
69645 +
69646 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
69647 + page_cache_get(page_m);
69648 + page_add_file_rmap(page_m);
69649 + inc_mm_counter_fast(mm, MM_FILEPAGES);
69650 + set_pte_at(mm, address_m, pte_m, entry_m);
69651 + update_mmu_cache(vma_m, address_m, entry_m);
69652 +out:
69653 + if (ptl != ptl_m)
69654 + spin_unlock(ptl_m);
69655 + pte_unmap(pte_m);
69656 +}
69657 +
69658 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
69659 +{
69660 + struct mm_struct *mm = vma->vm_mm;
69661 + unsigned long address_m;
69662 + spinlock_t *ptl_m;
69663 + struct vm_area_struct *vma_m;
69664 + pmd_t *pmd_m;
69665 + pte_t *pte_m, entry_m;
69666 +
69667 + vma_m = pax_find_mirror_vma(vma);
69668 + if (!vma_m)
69669 + return;
69670 +
69671 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69672 + address_m = address + SEGMEXEC_TASK_SIZE;
69673 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
69674 + pte_m = pte_offset_map(pmd_m, address_m);
69675 + ptl_m = pte_lockptr(mm, pmd_m);
69676 + if (ptl != ptl_m) {
69677 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
69678 + if (!pte_none(*pte_m))
69679 + goto out;
69680 + }
69681 +
69682 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
69683 + set_pte_at(mm, address_m, pte_m, entry_m);
69684 +out:
69685 + if (ptl != ptl_m)
69686 + spin_unlock(ptl_m);
69687 + pte_unmap(pte_m);
69688 +}
69689 +
69690 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
69691 +{
69692 + struct page *page_m;
69693 + pte_t entry;
69694 +
69695 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
69696 + goto out;
69697 +
69698 + entry = *pte;
69699 + page_m = vm_normal_page(vma, address, entry);
69700 + if (!page_m)
69701 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
69702 + else if (PageAnon(page_m)) {
69703 + if (pax_find_mirror_vma(vma)) {
69704 + pte_unmap_unlock(pte, ptl);
69705 + lock_page(page_m);
69706 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
69707 + if (pte_same(entry, *pte))
69708 + pax_mirror_anon_pte(vma, address, page_m, ptl);
69709 + else
69710 + unlock_page(page_m);
69711 + }
69712 + } else
69713 + pax_mirror_file_pte(vma, address, page_m, ptl);
69714 +
69715 +out:
69716 + pte_unmap_unlock(pte, ptl);
69717 +}
69718 +#endif
69719 +
69720 /*
69721 * This routine handles present pages, when users try to write
69722 * to a shared page. It is done by copying the page to a new address
69723 @@ -2656,6 +2849,12 @@ gotten:
69724 */
69725 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
69726 if (likely(pte_same(*page_table, orig_pte))) {
69727 +
69728 +#ifdef CONFIG_PAX_SEGMEXEC
69729 + if (pax_find_mirror_vma(vma))
69730 + BUG_ON(!trylock_page(new_page));
69731 +#endif
69732 +
69733 if (old_page) {
69734 if (!PageAnon(old_page)) {
69735 dec_mm_counter_fast(mm, MM_FILEPAGES);
69736 @@ -2707,6 +2906,10 @@ gotten:
69737 page_remove_rmap(old_page);
69738 }
69739
69740 +#ifdef CONFIG_PAX_SEGMEXEC
69741 + pax_mirror_anon_pte(vma, address, new_page, ptl);
69742 +#endif
69743 +
69744 /* Free the old page.. */
69745 new_page = old_page;
69746 ret |= VM_FAULT_WRITE;
69747 @@ -2986,6 +3189,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
69748 swap_free(entry);
69749 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
69750 try_to_free_swap(page);
69751 +
69752 +#ifdef CONFIG_PAX_SEGMEXEC
69753 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
69754 +#endif
69755 +
69756 unlock_page(page);
69757 if (swapcache) {
69758 /*
69759 @@ -3009,6 +3217,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
69760
69761 /* No need to invalidate - it was non-present before */
69762 update_mmu_cache(vma, address, page_table);
69763 +
69764 +#ifdef CONFIG_PAX_SEGMEXEC
69765 + pax_mirror_anon_pte(vma, address, page, ptl);
69766 +#endif
69767 +
69768 unlock:
69769 pte_unmap_unlock(page_table, ptl);
69770 out:
69771 @@ -3028,40 +3241,6 @@ out_release:
69772 }
69773
69774 /*
69775 - * This is like a special single-page "expand_{down|up}wards()",
69776 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
69777 - * doesn't hit another vma.
69778 - */
69779 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
69780 -{
69781 - address &= PAGE_MASK;
69782 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
69783 - struct vm_area_struct *prev = vma->vm_prev;
69784 -
69785 - /*
69786 - * Is there a mapping abutting this one below?
69787 - *
69788 - * That's only ok if it's the same stack mapping
69789 - * that has gotten split..
69790 - */
69791 - if (prev && prev->vm_end == address)
69792 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
69793 -
69794 - expand_downwards(vma, address - PAGE_SIZE);
69795 - }
69796 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
69797 - struct vm_area_struct *next = vma->vm_next;
69798 -
69799 - /* As VM_GROWSDOWN but s/below/above/ */
69800 - if (next && next->vm_start == address + PAGE_SIZE)
69801 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
69802 -
69803 - expand_upwards(vma, address + PAGE_SIZE);
69804 - }
69805 - return 0;
69806 -}
69807 -
69808 -/*
69809 * We enter with non-exclusive mmap_sem (to exclude vma changes,
69810 * but allow concurrent faults), and pte mapped but not yet locked.
69811 * We return with mmap_sem still held, but pte unmapped and unlocked.
69812 @@ -3070,27 +3249,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
69813 unsigned long address, pte_t *page_table, pmd_t *pmd,
69814 unsigned int flags)
69815 {
69816 - struct page *page;
69817 + struct page *page = NULL;
69818 spinlock_t *ptl;
69819 pte_t entry;
69820
69821 - pte_unmap(page_table);
69822 -
69823 - /* Check if we need to add a guard page to the stack */
69824 - if (check_stack_guard_page(vma, address) < 0)
69825 - return VM_FAULT_SIGBUS;
69826 -
69827 - /* Use the zero-page for reads */
69828 if (!(flags & FAULT_FLAG_WRITE)) {
69829 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
69830 vma->vm_page_prot));
69831 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
69832 + ptl = pte_lockptr(mm, pmd);
69833 + spin_lock(ptl);
69834 if (!pte_none(*page_table))
69835 goto unlock;
69836 goto setpte;
69837 }
69838
69839 /* Allocate our own private page. */
69840 + pte_unmap(page_table);
69841 +
69842 if (unlikely(anon_vma_prepare(vma)))
69843 goto oom;
69844 page = alloc_zeroed_user_highpage_movable(vma, address);
69845 @@ -3109,6 +3284,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
69846 if (!pte_none(*page_table))
69847 goto release;
69848
69849 +#ifdef CONFIG_PAX_SEGMEXEC
69850 + if (pax_find_mirror_vma(vma))
69851 + BUG_ON(!trylock_page(page));
69852 +#endif
69853 +
69854 inc_mm_counter_fast(mm, MM_ANONPAGES);
69855 page_add_new_anon_rmap(page, vma, address);
69856 setpte:
69857 @@ -3116,6 +3296,12 @@ setpte:
69858
69859 /* No need to invalidate - it was non-present before */
69860 update_mmu_cache(vma, address, page_table);
69861 +
69862 +#ifdef CONFIG_PAX_SEGMEXEC
69863 + if (page)
69864 + pax_mirror_anon_pte(vma, address, page, ptl);
69865 +#endif
69866 +
69867 unlock:
69868 pte_unmap_unlock(page_table, ptl);
69869 return 0;
69870 @@ -3259,6 +3445,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69871 */
69872 /* Only go through if we didn't race with anybody else... */
69873 if (likely(pte_same(*page_table, orig_pte))) {
69874 +
69875 +#ifdef CONFIG_PAX_SEGMEXEC
69876 + if (anon && pax_find_mirror_vma(vma))
69877 + BUG_ON(!trylock_page(page));
69878 +#endif
69879 +
69880 flush_icache_page(vma, page);
69881 entry = mk_pte(page, vma->vm_page_prot);
69882 if (flags & FAULT_FLAG_WRITE)
69883 @@ -3278,6 +3470,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69884
69885 /* no need to invalidate: a not-present page won't be cached */
69886 update_mmu_cache(vma, address, page_table);
69887 +
69888 +#ifdef CONFIG_PAX_SEGMEXEC
69889 + if (anon)
69890 + pax_mirror_anon_pte(vma, address, page, ptl);
69891 + else
69892 + pax_mirror_file_pte(vma, address, page, ptl);
69893 +#endif
69894 +
69895 } else {
69896 if (cow_page)
69897 mem_cgroup_uncharge_page(cow_page);
69898 @@ -3431,6 +3631,12 @@ int handle_pte_fault(struct mm_struct *mm,
69899 if (flags & FAULT_FLAG_WRITE)
69900 flush_tlb_fix_spurious_fault(vma, address);
69901 }
69902 +
69903 +#ifdef CONFIG_PAX_SEGMEXEC
69904 + pax_mirror_pte(vma, address, pte, pmd, ptl);
69905 + return 0;
69906 +#endif
69907 +
69908 unlock:
69909 pte_unmap_unlock(pte, ptl);
69910 return 0;
69911 @@ -3447,6 +3653,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69912 pmd_t *pmd;
69913 pte_t *pte;
69914
69915 +#ifdef CONFIG_PAX_SEGMEXEC
69916 + struct vm_area_struct *vma_m;
69917 +#endif
69918 +
69919 __set_current_state(TASK_RUNNING);
69920
69921 count_vm_event(PGFAULT);
69922 @@ -3458,6 +3668,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69923 if (unlikely(is_vm_hugetlb_page(vma)))
69924 return hugetlb_fault(mm, vma, address, flags);
69925
69926 +#ifdef CONFIG_PAX_SEGMEXEC
69927 + vma_m = pax_find_mirror_vma(vma);
69928 + if (vma_m) {
69929 + unsigned long address_m;
69930 + pgd_t *pgd_m;
69931 + pud_t *pud_m;
69932 + pmd_t *pmd_m;
69933 +
69934 + if (vma->vm_start > vma_m->vm_start) {
69935 + address_m = address;
69936 + address -= SEGMEXEC_TASK_SIZE;
69937 + vma = vma_m;
69938 + } else
69939 + address_m = address + SEGMEXEC_TASK_SIZE;
69940 +
69941 + pgd_m = pgd_offset(mm, address_m);
69942 + pud_m = pud_alloc(mm, pgd_m, address_m);
69943 + if (!pud_m)
69944 + return VM_FAULT_OOM;
69945 + pmd_m = pmd_alloc(mm, pud_m, address_m);
69946 + if (!pmd_m)
69947 + return VM_FAULT_OOM;
69948 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
69949 + return VM_FAULT_OOM;
69950 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
69951 + }
69952 +#endif
69953 +
69954 pgd = pgd_offset(mm, address);
69955 pud = pud_alloc(mm, pgd, address);
69956 if (!pud)
69957 @@ -3487,7 +3725,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69958 * run pte_offset_map on the pmd, if an huge pmd could
69959 * materialize from under us from a different thread.
69960 */
69961 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
69962 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
69963 return VM_FAULT_OOM;
69964 /* if an huge pmd materialized from under us just retry later */
69965 if (unlikely(pmd_trans_huge(*pmd)))
69966 @@ -3591,7 +3829,7 @@ static int __init gate_vma_init(void)
69967 gate_vma.vm_start = FIXADDR_USER_START;
69968 gate_vma.vm_end = FIXADDR_USER_END;
69969 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
69970 - gate_vma.vm_page_prot = __P101;
69971 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
69972 /*
69973 * Make sure the vDSO gets into every core dump.
69974 * Dumping its contents makes post-mortem fully interpretable later
69975 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
69976 index c3fdbcb..2e8ef90 100644
69977 --- a/mm/mempolicy.c
69978 +++ b/mm/mempolicy.c
69979 @@ -640,6 +640,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
69980 unsigned long vmstart;
69981 unsigned long vmend;
69982
69983 +#ifdef CONFIG_PAX_SEGMEXEC
69984 + struct vm_area_struct *vma_m;
69985 +#endif
69986 +
69987 vma = find_vma_prev(mm, start, &prev);
69988 if (!vma || vma->vm_start > start)
69989 return -EFAULT;
69990 @@ -678,6 +682,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
69991 err = policy_vma(vma, new_pol);
69992 if (err)
69993 goto out;
69994 +
69995 +#ifdef CONFIG_PAX_SEGMEXEC
69996 + vma_m = pax_find_mirror_vma(vma);
69997 + if (vma_m) {
69998 + err = policy_vma(vma_m, new_pol);
69999 + if (err)
70000 + goto out;
70001 + }
70002 +#endif
70003 +
70004 }
70005
70006 out:
70007 @@ -1111,6 +1125,17 @@ static long do_mbind(unsigned long start, unsigned long len,
70008
70009 if (end < start)
70010 return -EINVAL;
70011 +
70012 +#ifdef CONFIG_PAX_SEGMEXEC
70013 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
70014 + if (end > SEGMEXEC_TASK_SIZE)
70015 + return -EINVAL;
70016 + } else
70017 +#endif
70018 +
70019 + if (end > TASK_SIZE)
70020 + return -EINVAL;
70021 +
70022 if (end == start)
70023 return 0;
70024
70025 @@ -1329,6 +1354,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
70026 if (!mm)
70027 goto out;
70028
70029 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70030 + if (mm != current->mm &&
70031 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
70032 + err = -EPERM;
70033 + goto out;
70034 + }
70035 +#endif
70036 +
70037 /*
70038 * Check if this process has the right to modify the specified
70039 * process. The right exists if the process has administrative
70040 @@ -1338,8 +1371,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
70041 rcu_read_lock();
70042 tcred = __task_cred(task);
70043 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
70044 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
70045 - !capable(CAP_SYS_NICE)) {
70046 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
70047 rcu_read_unlock();
70048 err = -EPERM;
70049 goto out;
70050 diff --git a/mm/migrate.c b/mm/migrate.c
70051 index 177aca4..ab3a744 100644
70052 --- a/mm/migrate.c
70053 +++ b/mm/migrate.c
70054 @@ -1313,6 +1313,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
70055 if (!mm)
70056 return -EINVAL;
70057
70058 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70059 + if (mm != current->mm &&
70060 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
70061 + err = -EPERM;
70062 + goto out;
70063 + }
70064 +#endif
70065 +
70066 /*
70067 * Check if this process has the right to modify the specified
70068 * process. The right exists if the process has administrative
70069 @@ -1322,8 +1330,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
70070 rcu_read_lock();
70071 tcred = __task_cred(task);
70072 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
70073 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
70074 - !capable(CAP_SYS_NICE)) {
70075 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
70076 rcu_read_unlock();
70077 err = -EPERM;
70078 goto out;
70079 diff --git a/mm/mlock.c b/mm/mlock.c
70080 index 4f4f53b..9511904 100644
70081 --- a/mm/mlock.c
70082 +++ b/mm/mlock.c
70083 @@ -13,6 +13,7 @@
70084 #include <linux/pagemap.h>
70085 #include <linux/mempolicy.h>
70086 #include <linux/syscalls.h>
70087 +#include <linux/security.h>
70088 #include <linux/sched.h>
70089 #include <linux/export.h>
70090 #include <linux/rmap.h>
70091 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
70092 return -EINVAL;
70093 if (end == start)
70094 return 0;
70095 + if (end > TASK_SIZE)
70096 + return -EINVAL;
70097 +
70098 vma = find_vma_prev(current->mm, start, &prev);
70099 if (!vma || vma->vm_start > start)
70100 return -ENOMEM;
70101 @@ -395,6 +399,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
70102 for (nstart = start ; ; ) {
70103 vm_flags_t newflags;
70104
70105 +#ifdef CONFIG_PAX_SEGMEXEC
70106 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
70107 + break;
70108 +#endif
70109 +
70110 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
70111
70112 newflags = vma->vm_flags | VM_LOCKED;
70113 @@ -500,6 +509,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
70114 lock_limit >>= PAGE_SHIFT;
70115
70116 /* check against resource limits */
70117 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
70118 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
70119 error = do_mlock(start, len, 1);
70120 up_write(&current->mm->mmap_sem);
70121 @@ -523,17 +533,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
70122 static int do_mlockall(int flags)
70123 {
70124 struct vm_area_struct * vma, * prev = NULL;
70125 - unsigned int def_flags = 0;
70126
70127 if (flags & MCL_FUTURE)
70128 - def_flags = VM_LOCKED;
70129 - current->mm->def_flags = def_flags;
70130 + current->mm->def_flags |= VM_LOCKED;
70131 + else
70132 + current->mm->def_flags &= ~VM_LOCKED;
70133 if (flags == MCL_FUTURE)
70134 goto out;
70135
70136 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
70137 vm_flags_t newflags;
70138
70139 +#ifdef CONFIG_PAX_SEGMEXEC
70140 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
70141 + break;
70142 +#endif
70143 +
70144 + BUG_ON(vma->vm_end > TASK_SIZE);
70145 newflags = vma->vm_flags | VM_LOCKED;
70146 if (!(flags & MCL_CURRENT))
70147 newflags &= ~VM_LOCKED;
70148 @@ -566,6 +582,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
70149 lock_limit >>= PAGE_SHIFT;
70150
70151 ret = -ENOMEM;
70152 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
70153 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
70154 capable(CAP_IPC_LOCK))
70155 ret = do_mlockall(flags);
70156 diff --git a/mm/mmap.c b/mm/mmap.c
70157 index eae90af..c930262 100644
70158 --- a/mm/mmap.c
70159 +++ b/mm/mmap.c
70160 @@ -46,6 +46,16 @@
70161 #define arch_rebalance_pgtables(addr, len) (addr)
70162 #endif
70163
70164 +static inline void verify_mm_writelocked(struct mm_struct *mm)
70165 +{
70166 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
70167 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
70168 + up_read(&mm->mmap_sem);
70169 + BUG();
70170 + }
70171 +#endif
70172 +}
70173 +
70174 static void unmap_region(struct mm_struct *mm,
70175 struct vm_area_struct *vma, struct vm_area_struct *prev,
70176 unsigned long start, unsigned long end);
70177 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
70178 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
70179 *
70180 */
70181 -pgprot_t protection_map[16] = {
70182 +pgprot_t protection_map[16] __read_only = {
70183 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
70184 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
70185 };
70186
70187 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
70188 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
70189 {
70190 - return __pgprot(pgprot_val(protection_map[vm_flags &
70191 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
70192 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
70193 pgprot_val(arch_vm_get_page_prot(vm_flags)));
70194 +
70195 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70196 + if (!(__supported_pte_mask & _PAGE_NX) &&
70197 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
70198 + (vm_flags & (VM_READ | VM_WRITE)))
70199 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
70200 +#endif
70201 +
70202 + return prot;
70203 }
70204 EXPORT_SYMBOL(vm_get_page_prot);
70205
70206 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
70207 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
70208 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
70209 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
70210 /*
70211 * Make sure vm_committed_as in one cacheline and not cacheline shared with
70212 * other variables. It can be updated by several CPUs frequently.
70213 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
70214 struct vm_area_struct *next = vma->vm_next;
70215
70216 might_sleep();
70217 + BUG_ON(vma->vm_mirror);
70218 if (vma->vm_ops && vma->vm_ops->close)
70219 vma->vm_ops->close(vma);
70220 if (vma->vm_file) {
70221 @@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
70222 * not page aligned -Ram Gupta
70223 */
70224 rlim = rlimit(RLIMIT_DATA);
70225 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
70226 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
70227 (mm->end_data - mm->start_data) > rlim)
70228 goto out;
70229 @@ -689,6 +711,12 @@ static int
70230 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
70231 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
70232 {
70233 +
70234 +#ifdef CONFIG_PAX_SEGMEXEC
70235 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
70236 + return 0;
70237 +#endif
70238 +
70239 if (is_mergeable_vma(vma, file, vm_flags) &&
70240 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
70241 if (vma->vm_pgoff == vm_pgoff)
70242 @@ -708,6 +736,12 @@ static int
70243 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
70244 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
70245 {
70246 +
70247 +#ifdef CONFIG_PAX_SEGMEXEC
70248 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
70249 + return 0;
70250 +#endif
70251 +
70252 if (is_mergeable_vma(vma, file, vm_flags) &&
70253 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
70254 pgoff_t vm_pglen;
70255 @@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
70256 struct vm_area_struct *vma_merge(struct mm_struct *mm,
70257 struct vm_area_struct *prev, unsigned long addr,
70258 unsigned long end, unsigned long vm_flags,
70259 - struct anon_vma *anon_vma, struct file *file,
70260 + struct anon_vma *anon_vma, struct file *file,
70261 pgoff_t pgoff, struct mempolicy *policy)
70262 {
70263 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
70264 struct vm_area_struct *area, *next;
70265 int err;
70266
70267 +#ifdef CONFIG_PAX_SEGMEXEC
70268 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
70269 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
70270 +
70271 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
70272 +#endif
70273 +
70274 /*
70275 * We later require that vma->vm_flags == vm_flags,
70276 * so this tests vma->vm_flags & VM_SPECIAL, too.
70277 @@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70278 if (next && next->vm_end == end) /* cases 6, 7, 8 */
70279 next = next->vm_next;
70280
70281 +#ifdef CONFIG_PAX_SEGMEXEC
70282 + if (prev)
70283 + prev_m = pax_find_mirror_vma(prev);
70284 + if (area)
70285 + area_m = pax_find_mirror_vma(area);
70286 + if (next)
70287 + next_m = pax_find_mirror_vma(next);
70288 +#endif
70289 +
70290 /*
70291 * Can it merge with the predecessor?
70292 */
70293 @@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70294 /* cases 1, 6 */
70295 err = vma_adjust(prev, prev->vm_start,
70296 next->vm_end, prev->vm_pgoff, NULL);
70297 - } else /* cases 2, 5, 7 */
70298 +
70299 +#ifdef CONFIG_PAX_SEGMEXEC
70300 + if (!err && prev_m)
70301 + err = vma_adjust(prev_m, prev_m->vm_start,
70302 + next_m->vm_end, prev_m->vm_pgoff, NULL);
70303 +#endif
70304 +
70305 + } else { /* cases 2, 5, 7 */
70306 err = vma_adjust(prev, prev->vm_start,
70307 end, prev->vm_pgoff, NULL);
70308 +
70309 +#ifdef CONFIG_PAX_SEGMEXEC
70310 + if (!err && prev_m)
70311 + err = vma_adjust(prev_m, prev_m->vm_start,
70312 + end_m, prev_m->vm_pgoff, NULL);
70313 +#endif
70314 +
70315 + }
70316 if (err)
70317 return NULL;
70318 khugepaged_enter_vma_merge(prev);
70319 @@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70320 mpol_equal(policy, vma_policy(next)) &&
70321 can_vma_merge_before(next, vm_flags,
70322 anon_vma, file, pgoff+pglen)) {
70323 - if (prev && addr < prev->vm_end) /* case 4 */
70324 + if (prev && addr < prev->vm_end) { /* case 4 */
70325 err = vma_adjust(prev, prev->vm_start,
70326 addr, prev->vm_pgoff, NULL);
70327 - else /* cases 3, 8 */
70328 +
70329 +#ifdef CONFIG_PAX_SEGMEXEC
70330 + if (!err && prev_m)
70331 + err = vma_adjust(prev_m, prev_m->vm_start,
70332 + addr_m, prev_m->vm_pgoff, NULL);
70333 +#endif
70334 +
70335 + } else { /* cases 3, 8 */
70336 err = vma_adjust(area, addr, next->vm_end,
70337 next->vm_pgoff - pglen, NULL);
70338 +
70339 +#ifdef CONFIG_PAX_SEGMEXEC
70340 + if (!err && area_m)
70341 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
70342 + next_m->vm_pgoff - pglen, NULL);
70343 +#endif
70344 +
70345 + }
70346 if (err)
70347 return NULL;
70348 khugepaged_enter_vma_merge(area);
70349 @@ -921,14 +1001,11 @@ none:
70350 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
70351 struct file *file, long pages)
70352 {
70353 - const unsigned long stack_flags
70354 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
70355 -
70356 if (file) {
70357 mm->shared_vm += pages;
70358 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
70359 mm->exec_vm += pages;
70360 - } else if (flags & stack_flags)
70361 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
70362 mm->stack_vm += pages;
70363 if (flags & (VM_RESERVED|VM_IO))
70364 mm->reserved_vm += pages;
70365 @@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70366 * (the exception is when the underlying filesystem is noexec
70367 * mounted, in which case we dont add PROT_EXEC.)
70368 */
70369 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
70370 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
70371 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
70372 prot |= PROT_EXEC;
70373
70374 @@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70375 /* Obtain the address to map to. we verify (or select) it and ensure
70376 * that it represents a valid section of the address space.
70377 */
70378 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
70379 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
70380 if (addr & ~PAGE_MASK)
70381 return addr;
70382
70383 @@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70384 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
70385 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
70386
70387 +#ifdef CONFIG_PAX_MPROTECT
70388 + if (mm->pax_flags & MF_PAX_MPROTECT) {
70389 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
70390 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
70391 + gr_log_rwxmmap(file);
70392 +
70393 +#ifdef CONFIG_PAX_EMUPLT
70394 + vm_flags &= ~VM_EXEC;
70395 +#else
70396 + return -EPERM;
70397 +#endif
70398 +
70399 + }
70400 +
70401 + if (!(vm_flags & VM_EXEC))
70402 + vm_flags &= ~VM_MAYEXEC;
70403 +#else
70404 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
70405 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
70406 +#endif
70407 + else
70408 + vm_flags &= ~VM_MAYWRITE;
70409 + }
70410 +#endif
70411 +
70412 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70413 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
70414 + vm_flags &= ~VM_PAGEEXEC;
70415 +#endif
70416 +
70417 if (flags & MAP_LOCKED)
70418 if (!can_do_mlock())
70419 return -EPERM;
70420 @@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70421 locked += mm->locked_vm;
70422 lock_limit = rlimit(RLIMIT_MEMLOCK);
70423 lock_limit >>= PAGE_SHIFT;
70424 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
70425 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
70426 return -EAGAIN;
70427 }
70428 @@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70429 if (error)
70430 return error;
70431
70432 + if (!gr_acl_handle_mmap(file, prot))
70433 + return -EACCES;
70434 +
70435 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
70436 }
70437 EXPORT_SYMBOL(do_mmap_pgoff);
70438 @@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
70439 vm_flags_t vm_flags = vma->vm_flags;
70440
70441 /* If it was private or non-writable, the write bit is already clear */
70442 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
70443 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
70444 return 0;
70445
70446 /* The backer wishes to know when pages are first written to? */
70447 @@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
70448 unsigned long charged = 0;
70449 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
70450
70451 +#ifdef CONFIG_PAX_SEGMEXEC
70452 + struct vm_area_struct *vma_m = NULL;
70453 +#endif
70454 +
70455 + /*
70456 + * mm->mmap_sem is required to protect against another thread
70457 + * changing the mappings in case we sleep.
70458 + */
70459 + verify_mm_writelocked(mm);
70460 +
70461 /* Clear old maps */
70462 error = -ENOMEM;
70463 -munmap_back:
70464 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
70465 if (vma && vma->vm_start < addr + len) {
70466 if (do_munmap(mm, addr, len))
70467 return -ENOMEM;
70468 - goto munmap_back;
70469 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
70470 + BUG_ON(vma && vma->vm_start < addr + len);
70471 }
70472
70473 /* Check against address space limit. */
70474 @@ -1258,6 +1379,16 @@ munmap_back:
70475 goto unacct_error;
70476 }
70477
70478 +#ifdef CONFIG_PAX_SEGMEXEC
70479 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
70480 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
70481 + if (!vma_m) {
70482 + error = -ENOMEM;
70483 + goto free_vma;
70484 + }
70485 + }
70486 +#endif
70487 +
70488 vma->vm_mm = mm;
70489 vma->vm_start = addr;
70490 vma->vm_end = addr + len;
70491 @@ -1266,8 +1397,9 @@ munmap_back:
70492 vma->vm_pgoff = pgoff;
70493 INIT_LIST_HEAD(&vma->anon_vma_chain);
70494
70495 + error = -EINVAL; /* when rejecting VM_GROWSDOWN|VM_GROWSUP */
70496 +
70497 if (file) {
70498 - error = -EINVAL;
70499 if (vm_flags & (VM_GROWSDOWN|VM_GROWSUP))
70500 goto free_vma;
70501 if (vm_flags & VM_DENYWRITE) {
70502 @@ -1281,6 +1413,19 @@ munmap_back:
70503 error = file->f_op->mmap(file, vma);
70504 if (error)
70505 goto unmap_and_free_vma;
70506 +
70507 +#ifdef CONFIG_PAX_SEGMEXEC
70508 + if (vma_m && (vm_flags & VM_EXECUTABLE))
70509 + added_exe_file_vma(mm);
70510 +#endif
70511 +
70512 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70513 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
70514 + vma->vm_flags |= VM_PAGEEXEC;
70515 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
70516 + }
70517 +#endif
70518 +
70519 if (vm_flags & VM_EXECUTABLE)
70520 added_exe_file_vma(mm);
70521
70522 @@ -1293,6 +1438,8 @@ munmap_back:
70523 pgoff = vma->vm_pgoff;
70524 vm_flags = vma->vm_flags;
70525 } else if (vm_flags & VM_SHARED) {
70526 + if (unlikely(vm_flags & (VM_GROWSDOWN|VM_GROWSUP)))
70527 + goto free_vma;
70528 error = shmem_zero_setup(vma);
70529 if (error)
70530 goto free_vma;
70531 @@ -1316,6 +1463,11 @@ munmap_back:
70532 vma_link(mm, vma, prev, rb_link, rb_parent);
70533 file = vma->vm_file;
70534
70535 +#ifdef CONFIG_PAX_SEGMEXEC
70536 + if (vma_m)
70537 + BUG_ON(pax_mirror_vma(vma_m, vma));
70538 +#endif
70539 +
70540 /* Once vma denies write, undo our temporary denial count */
70541 if (correct_wcount)
70542 atomic_inc(&inode->i_writecount);
70543 @@ -1324,6 +1476,7 @@ out:
70544
70545 mm->total_vm += len >> PAGE_SHIFT;
70546 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
70547 + track_exec_limit(mm, addr, addr + len, vm_flags);
70548 if (vm_flags & VM_LOCKED) {
70549 if (!mlock_vma_pages_range(vma, addr, addr + len))
70550 mm->locked_vm += (len >> PAGE_SHIFT);
70551 @@ -1341,6 +1494,12 @@ unmap_and_free_vma:
70552 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
70553 charged = 0;
70554 free_vma:
70555 +
70556 +#ifdef CONFIG_PAX_SEGMEXEC
70557 + if (vma_m)
70558 + kmem_cache_free(vm_area_cachep, vma_m);
70559 +#endif
70560 +
70561 kmem_cache_free(vm_area_cachep, vma);
70562 unacct_error:
70563 if (charged)
70564 @@ -1348,6 +1507,44 @@ unacct_error:
70565 return error;
70566 }
70567
70568 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
70569 +{
70570 + if (!vma) {
70571 +#ifdef CONFIG_STACK_GROWSUP
70572 + if (addr > sysctl_heap_stack_gap)
70573 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
70574 + else
70575 + vma = find_vma(current->mm, 0);
70576 + if (vma && (vma->vm_flags & VM_GROWSUP))
70577 + return false;
70578 +#endif
70579 + return true;
70580 + }
70581 +
70582 + if (addr + len > vma->vm_start)
70583 + return false;
70584 +
70585 + if (vma->vm_flags & VM_GROWSDOWN)
70586 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
70587 +#ifdef CONFIG_STACK_GROWSUP
70588 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
70589 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
70590 +#endif
70591 +
70592 + return true;
70593 +}
70594 +
70595 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
70596 +{
70597 + if (vma->vm_start < len)
70598 + return -ENOMEM;
70599 + if (!(vma->vm_flags & VM_GROWSDOWN))
70600 + return vma->vm_start - len;
70601 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
70602 + return vma->vm_start - len - sysctl_heap_stack_gap;
70603 + return -ENOMEM;
70604 +}
70605 +
70606 /* Get an address range which is currently unmapped.
70607 * For shmat() with addr=0.
70608 *
70609 @@ -1374,18 +1571,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
70610 if (flags & MAP_FIXED)
70611 return addr;
70612
70613 +#ifdef CONFIG_PAX_RANDMMAP
70614 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
70615 +#endif
70616 +
70617 if (addr) {
70618 addr = PAGE_ALIGN(addr);
70619 - vma = find_vma(mm, addr);
70620 - if (TASK_SIZE - len >= addr &&
70621 - (!vma || addr + len <= vma->vm_start))
70622 - return addr;
70623 + if (TASK_SIZE - len >= addr) {
70624 + vma = find_vma(mm, addr);
70625 + if (check_heap_stack_gap(vma, addr, len))
70626 + return addr;
70627 + }
70628 }
70629 if (len > mm->cached_hole_size) {
70630 - start_addr = addr = mm->free_area_cache;
70631 + start_addr = addr = mm->free_area_cache;
70632 } else {
70633 - start_addr = addr = TASK_UNMAPPED_BASE;
70634 - mm->cached_hole_size = 0;
70635 + start_addr = addr = mm->mmap_base;
70636 + mm->cached_hole_size = 0;
70637 }
70638
70639 full_search:
70640 @@ -1396,34 +1598,40 @@ full_search:
70641 * Start a new search - just in case we missed
70642 * some holes.
70643 */
70644 - if (start_addr != TASK_UNMAPPED_BASE) {
70645 - addr = TASK_UNMAPPED_BASE;
70646 - start_addr = addr;
70647 + if (start_addr != mm->mmap_base) {
70648 + start_addr = addr = mm->mmap_base;
70649 mm->cached_hole_size = 0;
70650 goto full_search;
70651 }
70652 return -ENOMEM;
70653 }
70654 - if (!vma || addr + len <= vma->vm_start) {
70655 - /*
70656 - * Remember the place where we stopped the search:
70657 - */
70658 - mm->free_area_cache = addr + len;
70659 - return addr;
70660 - }
70661 + if (check_heap_stack_gap(vma, addr, len))
70662 + break;
70663 if (addr + mm->cached_hole_size < vma->vm_start)
70664 mm->cached_hole_size = vma->vm_start - addr;
70665 addr = vma->vm_end;
70666 }
70667 +
70668 + /*
70669 + * Remember the place where we stopped the search:
70670 + */
70671 + mm->free_area_cache = addr + len;
70672 + return addr;
70673 }
70674 #endif
70675
70676 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
70677 {
70678 +
70679 +#ifdef CONFIG_PAX_SEGMEXEC
70680 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
70681 + return;
70682 +#endif
70683 +
70684 /*
70685 * Is this a new hole at the lowest possible address?
70686 */
70687 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
70688 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
70689 mm->free_area_cache = addr;
70690 mm->cached_hole_size = ~0UL;
70691 }
70692 @@ -1441,7 +1649,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
70693 {
70694 struct vm_area_struct *vma;
70695 struct mm_struct *mm = current->mm;
70696 - unsigned long addr = addr0;
70697 + unsigned long base = mm->mmap_base, addr = addr0;
70698
70699 /* requested length too big for entire address space */
70700 if (len > TASK_SIZE)
70701 @@ -1450,13 +1658,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
70702 if (flags & MAP_FIXED)
70703 return addr;
70704
70705 +#ifdef CONFIG_PAX_RANDMMAP
70706 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
70707 +#endif
70708 +
70709 /* requesting a specific address */
70710 if (addr) {
70711 addr = PAGE_ALIGN(addr);
70712 - vma = find_vma(mm, addr);
70713 - if (TASK_SIZE - len >= addr &&
70714 - (!vma || addr + len <= vma->vm_start))
70715 - return addr;
70716 + if (TASK_SIZE - len >= addr) {
70717 + vma = find_vma(mm, addr);
70718 + if (check_heap_stack_gap(vma, addr, len))
70719 + return addr;
70720 + }
70721 }
70722
70723 /* check if free_area_cache is useful for us */
70724 @@ -1471,7 +1684,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
70725 /* make sure it can fit in the remaining address space */
70726 if (addr > len) {
70727 vma = find_vma(mm, addr-len);
70728 - if (!vma || addr <= vma->vm_start)
70729 + if (check_heap_stack_gap(vma, addr - len, len))
70730 /* remember the address as a hint for next time */
70731 return (mm->free_area_cache = addr-len);
70732 }
70733 @@ -1488,7 +1701,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
70734 * return with success:
70735 */
70736 vma = find_vma(mm, addr);
70737 - if (!vma || addr+len <= vma->vm_start)
70738 + if (check_heap_stack_gap(vma, addr, len))
70739 /* remember the address as a hint for next time */
70740 return (mm->free_area_cache = addr);
70741
70742 @@ -1497,8 +1710,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
70743 mm->cached_hole_size = vma->vm_start - addr;
70744
70745 /* try just below the current vma->vm_start */
70746 - addr = vma->vm_start-len;
70747 - } while (len < vma->vm_start);
70748 + addr = skip_heap_stack_gap(vma, len);
70749 + } while (!IS_ERR_VALUE(addr));
70750
70751 bottomup:
70752 /*
70753 @@ -1507,13 +1720,21 @@ bottomup:
70754 * can happen with large stack limits and large mmap()
70755 * allocations.
70756 */
70757 + mm->mmap_base = TASK_UNMAPPED_BASE;
70758 +
70759 +#ifdef CONFIG_PAX_RANDMMAP
70760 + if (mm->pax_flags & MF_PAX_RANDMMAP)
70761 + mm->mmap_base += mm->delta_mmap;
70762 +#endif
70763 +
70764 + mm->free_area_cache = mm->mmap_base;
70765 mm->cached_hole_size = ~0UL;
70766 - mm->free_area_cache = TASK_UNMAPPED_BASE;
70767 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
70768 /*
70769 * Restore the topdown base:
70770 */
70771 - mm->free_area_cache = mm->mmap_base;
70772 + mm->mmap_base = base;
70773 + mm->free_area_cache = base;
70774 mm->cached_hole_size = ~0UL;
70775
70776 return addr;
70777 @@ -1522,6 +1743,12 @@ bottomup:
70778
70779 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
70780 {
70781 +
70782 +#ifdef CONFIG_PAX_SEGMEXEC
70783 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
70784 + return;
70785 +#endif
70786 +
70787 /*
70788 * Is this a new hole at the highest possible address?
70789 */
70790 @@ -1529,8 +1756,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
70791 mm->free_area_cache = addr;
70792
70793 /* dont allow allocations above current base */
70794 - if (mm->free_area_cache > mm->mmap_base)
70795 + if (mm->free_area_cache > mm->mmap_base) {
70796 mm->free_area_cache = mm->mmap_base;
70797 + mm->cached_hole_size = ~0UL;
70798 + }
70799 }
70800
70801 unsigned long
70802 @@ -1603,40 +1832,50 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
70803
70804 EXPORT_SYMBOL(find_vma);
70805
70806 -/* Same as find_vma, but also return a pointer to the previous VMA in *pprev. */
70807 +/*
70808 + * Same as find_vma, but also return a pointer to the previous VMA in *pprev.
70809 + */
70810 struct vm_area_struct *
70811 find_vma_prev(struct mm_struct *mm, unsigned long addr,
70812 struct vm_area_struct **pprev)
70813 {
70814 - struct vm_area_struct *vma = NULL, *prev = NULL;
70815 - struct rb_node *rb_node;
70816 - if (!mm)
70817 - goto out;
70818 -
70819 - /* Guard against addr being lower than the first VMA */
70820 - vma = mm->mmap;
70821 -
70822 - /* Go through the RB tree quickly. */
70823 - rb_node = mm->mm_rb.rb_node;
70824 -
70825 - while (rb_node) {
70826 - struct vm_area_struct *vma_tmp;
70827 - vma_tmp = rb_entry(rb_node, struct vm_area_struct, vm_rb);
70828 -
70829 - if (addr < vma_tmp->vm_end) {
70830 - rb_node = rb_node->rb_left;
70831 - } else {
70832 - prev = vma_tmp;
70833 - if (!prev->vm_next || (addr < prev->vm_next->vm_end))
70834 - break;
70835 + struct vm_area_struct *vma;
70836 +
70837 + vma = find_vma(mm, addr);
70838 + if (vma) {
70839 + *pprev = vma->vm_prev;
70840 + } else {
70841 + struct rb_node *rb_node = mm->mm_rb.rb_node;
70842 + *pprev = NULL;
70843 + while (rb_node) {
70844 + *pprev = rb_entry(rb_node, struct vm_area_struct, vm_rb);
70845 rb_node = rb_node->rb_right;
70846 }
70847 }
70848 + return vma;
70849 +}
70850 +
70851 +#ifdef CONFIG_PAX_SEGMEXEC
70852 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
70853 +{
70854 + struct vm_area_struct *vma_m;
70855
70856 -out:
70857 - *pprev = prev;
70858 - return prev ? prev->vm_next : vma;
70859 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
70860 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
70861 + BUG_ON(vma->vm_mirror);
70862 + return NULL;
70863 + }
70864 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
70865 + vma_m = vma->vm_mirror;
70866 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
70867 + BUG_ON(vma->vm_file != vma_m->vm_file);
70868 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
70869 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
70870 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
70871 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
70872 + return vma_m;
70873 }
70874 +#endif
70875
70876 /*
70877 * Verify that the stack growth is acceptable and
70878 @@ -1654,6 +1893,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
70879 return -ENOMEM;
70880
70881 /* Stack limit test */
70882 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
70883 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
70884 return -ENOMEM;
70885
70886 @@ -1664,6 +1904,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
70887 locked = mm->locked_vm + grow;
70888 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
70889 limit >>= PAGE_SHIFT;
70890 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
70891 if (locked > limit && !capable(CAP_IPC_LOCK))
70892 return -ENOMEM;
70893 }
70894 @@ -1694,37 +1935,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
70895 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
70896 * vma is the last one with address > vma->vm_end. Have to extend vma.
70897 */
70898 +#ifndef CONFIG_IA64
70899 +static
70900 +#endif
70901 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
70902 {
70903 int error;
70904 + bool locknext;
70905
70906 if (!(vma->vm_flags & VM_GROWSUP))
70907 return -EFAULT;
70908
70909 + /* Also guard against wrapping around to address 0. */
70910 + if (address < PAGE_ALIGN(address+1))
70911 + address = PAGE_ALIGN(address+1);
70912 + else
70913 + return -ENOMEM;
70914 +
70915 /*
70916 * We must make sure the anon_vma is allocated
70917 * so that the anon_vma locking is not a noop.
70918 */
70919 if (unlikely(anon_vma_prepare(vma)))
70920 return -ENOMEM;
70921 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
70922 + if (locknext && anon_vma_prepare(vma->vm_next))
70923 + return -ENOMEM;
70924 vma_lock_anon_vma(vma);
70925 + if (locknext)
70926 + vma_lock_anon_vma(vma->vm_next);
70927
70928 /*
70929 * vma->vm_start/vm_end cannot change under us because the caller
70930 * is required to hold the mmap_sem in read mode. We need the
70931 - * anon_vma lock to serialize against concurrent expand_stacks.
70932 - * Also guard against wrapping around to address 0.
70933 + * anon_vma locks to serialize against concurrent expand_stacks
70934 + * and expand_upwards.
70935 */
70936 - if (address < PAGE_ALIGN(address+4))
70937 - address = PAGE_ALIGN(address+4);
70938 - else {
70939 - vma_unlock_anon_vma(vma);
70940 - return -ENOMEM;
70941 - }
70942 error = 0;
70943
70944 /* Somebody else might have raced and expanded it already */
70945 - if (address > vma->vm_end) {
70946 + 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)
70947 + error = -ENOMEM;
70948 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
70949 unsigned long size, grow;
70950
70951 size = address - vma->vm_start;
70952 @@ -1739,6 +1991,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
70953 }
70954 }
70955 }
70956 + if (locknext)
70957 + vma_unlock_anon_vma(vma->vm_next);
70958 vma_unlock_anon_vma(vma);
70959 khugepaged_enter_vma_merge(vma);
70960 return error;
70961 @@ -1752,6 +2006,8 @@ int expand_downwards(struct vm_area_struct *vma,
70962 unsigned long address)
70963 {
70964 int error;
70965 + bool lockprev = false;
70966 + struct vm_area_struct *prev;
70967
70968 /*
70969 * We must make sure the anon_vma is allocated
70970 @@ -1765,6 +2021,15 @@ int expand_downwards(struct vm_area_struct *vma,
70971 if (error)
70972 return error;
70973
70974 + prev = vma->vm_prev;
70975 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
70976 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
70977 +#endif
70978 + if (lockprev && anon_vma_prepare(prev))
70979 + return -ENOMEM;
70980 + if (lockprev)
70981 + vma_lock_anon_vma(prev);
70982 +
70983 vma_lock_anon_vma(vma);
70984
70985 /*
70986 @@ -1774,9 +2039,17 @@ int expand_downwards(struct vm_area_struct *vma,
70987 */
70988
70989 /* Somebody else might have raced and expanded it already */
70990 - if (address < vma->vm_start) {
70991 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
70992 + error = -ENOMEM;
70993 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
70994 unsigned long size, grow;
70995
70996 +#ifdef CONFIG_PAX_SEGMEXEC
70997 + struct vm_area_struct *vma_m;
70998 +
70999 + vma_m = pax_find_mirror_vma(vma);
71000 +#endif
71001 +
71002 size = vma->vm_end - address;
71003 grow = (vma->vm_start - address) >> PAGE_SHIFT;
71004
71005 @@ -1786,11 +2059,22 @@ int expand_downwards(struct vm_area_struct *vma,
71006 if (!error) {
71007 vma->vm_start = address;
71008 vma->vm_pgoff -= grow;
71009 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
71010 +
71011 +#ifdef CONFIG_PAX_SEGMEXEC
71012 + if (vma_m) {
71013 + vma_m->vm_start -= grow << PAGE_SHIFT;
71014 + vma_m->vm_pgoff -= grow;
71015 + }
71016 +#endif
71017 +
71018 perf_event_mmap(vma);
71019 }
71020 }
71021 }
71022 vma_unlock_anon_vma(vma);
71023 + if (lockprev)
71024 + vma_unlock_anon_vma(prev);
71025 khugepaged_enter_vma_merge(vma);
71026 return error;
71027 }
71028 @@ -1860,6 +2144,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
71029 do {
71030 long nrpages = vma_pages(vma);
71031
71032 +#ifdef CONFIG_PAX_SEGMEXEC
71033 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
71034 + vma = remove_vma(vma);
71035 + continue;
71036 + }
71037 +#endif
71038 +
71039 mm->total_vm -= nrpages;
71040 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
71041 vma = remove_vma(vma);
71042 @@ -1905,6 +2196,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
71043 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
71044 vma->vm_prev = NULL;
71045 do {
71046 +
71047 +#ifdef CONFIG_PAX_SEGMEXEC
71048 + if (vma->vm_mirror) {
71049 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
71050 + vma->vm_mirror->vm_mirror = NULL;
71051 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
71052 + vma->vm_mirror = NULL;
71053 + }
71054 +#endif
71055 +
71056 rb_erase(&vma->vm_rb, &mm->mm_rb);
71057 mm->map_count--;
71058 tail_vma = vma;
71059 @@ -1933,14 +2234,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71060 struct vm_area_struct *new;
71061 int err = -ENOMEM;
71062
71063 +#ifdef CONFIG_PAX_SEGMEXEC
71064 + struct vm_area_struct *vma_m, *new_m = NULL;
71065 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
71066 +#endif
71067 +
71068 if (is_vm_hugetlb_page(vma) && (addr &
71069 ~(huge_page_mask(hstate_vma(vma)))))
71070 return -EINVAL;
71071
71072 +#ifdef CONFIG_PAX_SEGMEXEC
71073 + vma_m = pax_find_mirror_vma(vma);
71074 +#endif
71075 +
71076 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
71077 if (!new)
71078 goto out_err;
71079
71080 +#ifdef CONFIG_PAX_SEGMEXEC
71081 + if (vma_m) {
71082 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
71083 + if (!new_m) {
71084 + kmem_cache_free(vm_area_cachep, new);
71085 + goto out_err;
71086 + }
71087 + }
71088 +#endif
71089 +
71090 /* most fields are the same, copy all, and then fixup */
71091 *new = *vma;
71092
71093 @@ -1953,6 +2273,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71094 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
71095 }
71096
71097 +#ifdef CONFIG_PAX_SEGMEXEC
71098 + if (vma_m) {
71099 + *new_m = *vma_m;
71100 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
71101 + new_m->vm_mirror = new;
71102 + new->vm_mirror = new_m;
71103 +
71104 + if (new_below)
71105 + new_m->vm_end = addr_m;
71106 + else {
71107 + new_m->vm_start = addr_m;
71108 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
71109 + }
71110 + }
71111 +#endif
71112 +
71113 pol = mpol_dup(vma_policy(vma));
71114 if (IS_ERR(pol)) {
71115 err = PTR_ERR(pol);
71116 @@ -1978,6 +2314,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71117 else
71118 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
71119
71120 +#ifdef CONFIG_PAX_SEGMEXEC
71121 + if (!err && vma_m) {
71122 + if (anon_vma_clone(new_m, vma_m))
71123 + goto out_free_mpol;
71124 +
71125 + mpol_get(pol);
71126 + vma_set_policy(new_m, pol);
71127 +
71128 + if (new_m->vm_file) {
71129 + get_file(new_m->vm_file);
71130 + if (vma_m->vm_flags & VM_EXECUTABLE)
71131 + added_exe_file_vma(mm);
71132 + }
71133 +
71134 + if (new_m->vm_ops && new_m->vm_ops->open)
71135 + new_m->vm_ops->open(new_m);
71136 +
71137 + if (new_below)
71138 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
71139 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
71140 + else
71141 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
71142 +
71143 + if (err) {
71144 + if (new_m->vm_ops && new_m->vm_ops->close)
71145 + new_m->vm_ops->close(new_m);
71146 + if (new_m->vm_file) {
71147 + if (vma_m->vm_flags & VM_EXECUTABLE)
71148 + removed_exe_file_vma(mm);
71149 + fput(new_m->vm_file);
71150 + }
71151 + mpol_put(pol);
71152 + }
71153 + }
71154 +#endif
71155 +
71156 /* Success. */
71157 if (!err)
71158 return 0;
71159 @@ -1990,10 +2362,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71160 removed_exe_file_vma(mm);
71161 fput(new->vm_file);
71162 }
71163 - unlink_anon_vmas(new);
71164 out_free_mpol:
71165 mpol_put(pol);
71166 out_free_vma:
71167 +
71168 +#ifdef CONFIG_PAX_SEGMEXEC
71169 + if (new_m) {
71170 + unlink_anon_vmas(new_m);
71171 + kmem_cache_free(vm_area_cachep, new_m);
71172 + }
71173 +#endif
71174 +
71175 + unlink_anon_vmas(new);
71176 kmem_cache_free(vm_area_cachep, new);
71177 out_err:
71178 return err;
71179 @@ -2006,6 +2386,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71180 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71181 unsigned long addr, int new_below)
71182 {
71183 +
71184 +#ifdef CONFIG_PAX_SEGMEXEC
71185 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71186 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
71187 + if (mm->map_count >= sysctl_max_map_count-1)
71188 + return -ENOMEM;
71189 + } else
71190 +#endif
71191 +
71192 if (mm->map_count >= sysctl_max_map_count)
71193 return -ENOMEM;
71194
71195 @@ -2017,11 +2406,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71196 * work. This now handles partial unmappings.
71197 * Jeremy Fitzhardinge <jeremy@goop.org>
71198 */
71199 +#ifdef CONFIG_PAX_SEGMEXEC
71200 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71201 {
71202 + int ret = __do_munmap(mm, start, len);
71203 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
71204 + return ret;
71205 +
71206 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
71207 +}
71208 +
71209 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71210 +#else
71211 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71212 +#endif
71213 +{
71214 unsigned long end;
71215 struct vm_area_struct *vma, *prev, *last;
71216
71217 + /*
71218 + * mm->mmap_sem is required to protect against another thread
71219 + * changing the mappings in case we sleep.
71220 + */
71221 + verify_mm_writelocked(mm);
71222 +
71223 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
71224 return -EINVAL;
71225
71226 @@ -2096,6 +2504,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71227 /* Fix up all other VM information */
71228 remove_vma_list(mm, vma);
71229
71230 + track_exec_limit(mm, start, end, 0UL);
71231 +
71232 return 0;
71233 }
71234
71235 @@ -2108,22 +2518,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
71236
71237 profile_munmap(addr);
71238
71239 +#ifdef CONFIG_PAX_SEGMEXEC
71240 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
71241 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
71242 + return -EINVAL;
71243 +#endif
71244 +
71245 down_write(&mm->mmap_sem);
71246 ret = do_munmap(mm, addr, len);
71247 up_write(&mm->mmap_sem);
71248 return ret;
71249 }
71250
71251 -static inline void verify_mm_writelocked(struct mm_struct *mm)
71252 -{
71253 -#ifdef CONFIG_DEBUG_VM
71254 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71255 - WARN_ON(1);
71256 - up_read(&mm->mmap_sem);
71257 - }
71258 -#endif
71259 -}
71260 -
71261 /*
71262 * this is really a simplified "do_mmap". it only handles
71263 * anonymous maps. eventually we may be able to do some
71264 @@ -2137,6 +2543,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71265 struct rb_node ** rb_link, * rb_parent;
71266 pgoff_t pgoff = addr >> PAGE_SHIFT;
71267 int error;
71268 + unsigned long charged;
71269
71270 len = PAGE_ALIGN(len);
71271 if (!len)
71272 @@ -2148,16 +2555,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71273
71274 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
71275
71276 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
71277 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
71278 + flags &= ~VM_EXEC;
71279 +
71280 +#ifdef CONFIG_PAX_MPROTECT
71281 + if (mm->pax_flags & MF_PAX_MPROTECT)
71282 + flags &= ~VM_MAYEXEC;
71283 +#endif
71284 +
71285 + }
71286 +#endif
71287 +
71288 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
71289 if (error & ~PAGE_MASK)
71290 return error;
71291
71292 + charged = len >> PAGE_SHIFT;
71293 +
71294 /*
71295 * mlock MCL_FUTURE?
71296 */
71297 if (mm->def_flags & VM_LOCKED) {
71298 unsigned long locked, lock_limit;
71299 - locked = len >> PAGE_SHIFT;
71300 + locked = charged;
71301 locked += mm->locked_vm;
71302 lock_limit = rlimit(RLIMIT_MEMLOCK);
71303 lock_limit >>= PAGE_SHIFT;
71304 @@ -2174,22 +2595,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71305 /*
71306 * Clear old maps. this also does some error checking for us
71307 */
71308 - munmap_back:
71309 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71310 if (vma && vma->vm_start < addr + len) {
71311 if (do_munmap(mm, addr, len))
71312 return -ENOMEM;
71313 - goto munmap_back;
71314 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71315 + BUG_ON(vma && vma->vm_start < addr + len);
71316 }
71317
71318 /* Check against address space limits *after* clearing old maps... */
71319 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
71320 + if (!may_expand_vm(mm, charged))
71321 return -ENOMEM;
71322
71323 if (mm->map_count > sysctl_max_map_count)
71324 return -ENOMEM;
71325
71326 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
71327 + if (security_vm_enough_memory(charged))
71328 return -ENOMEM;
71329
71330 /* Can we just expand an old private anonymous mapping? */
71331 @@ -2203,7 +2624,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71332 */
71333 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71334 if (!vma) {
71335 - vm_unacct_memory(len >> PAGE_SHIFT);
71336 + vm_unacct_memory(charged);
71337 return -ENOMEM;
71338 }
71339
71340 @@ -2217,11 +2638,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71341 vma_link(mm, vma, prev, rb_link, rb_parent);
71342 out:
71343 perf_event_mmap(vma);
71344 - mm->total_vm += len >> PAGE_SHIFT;
71345 + mm->total_vm += charged;
71346 if (flags & VM_LOCKED) {
71347 if (!mlock_vma_pages_range(vma, addr, addr + len))
71348 - mm->locked_vm += (len >> PAGE_SHIFT);
71349 + mm->locked_vm += charged;
71350 }
71351 + track_exec_limit(mm, addr, addr + len, flags);
71352 return addr;
71353 }
71354
71355 @@ -2268,8 +2690,10 @@ void exit_mmap(struct mm_struct *mm)
71356 * Walk the list again, actually closing and freeing it,
71357 * with preemption enabled, without holding any MM locks.
71358 */
71359 - while (vma)
71360 + while (vma) {
71361 + vma->vm_mirror = NULL;
71362 vma = remove_vma(vma);
71363 + }
71364
71365 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
71366 }
71367 @@ -2283,6 +2707,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
71368 struct vm_area_struct * __vma, * prev;
71369 struct rb_node ** rb_link, * rb_parent;
71370
71371 +#ifdef CONFIG_PAX_SEGMEXEC
71372 + struct vm_area_struct *vma_m = NULL;
71373 +#endif
71374 +
71375 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
71376 + return -EPERM;
71377 +
71378 /*
71379 * The vm_pgoff of a purely anonymous vma should be irrelevant
71380 * until its first write fault, when page's anon_vma and index
71381 @@ -2305,7 +2736,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
71382 if ((vma->vm_flags & VM_ACCOUNT) &&
71383 security_vm_enough_memory_mm(mm, vma_pages(vma)))
71384 return -ENOMEM;
71385 +
71386 +#ifdef CONFIG_PAX_SEGMEXEC
71387 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
71388 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71389 + if (!vma_m)
71390 + return -ENOMEM;
71391 + }
71392 +#endif
71393 +
71394 vma_link(mm, vma, prev, rb_link, rb_parent);
71395 +
71396 +#ifdef CONFIG_PAX_SEGMEXEC
71397 + if (vma_m)
71398 + BUG_ON(pax_mirror_vma(vma_m, vma));
71399 +#endif
71400 +
71401 return 0;
71402 }
71403
71404 @@ -2323,6 +2769,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
71405 struct rb_node **rb_link, *rb_parent;
71406 struct mempolicy *pol;
71407
71408 + BUG_ON(vma->vm_mirror);
71409 +
71410 /*
71411 * If anonymous vma has not yet been faulted, update new pgoff
71412 * to match new location, to increase its chance of merging.
71413 @@ -2373,6 +2821,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
71414 return NULL;
71415 }
71416
71417 +#ifdef CONFIG_PAX_SEGMEXEC
71418 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
71419 +{
71420 + struct vm_area_struct *prev_m;
71421 + struct rb_node **rb_link_m, *rb_parent_m;
71422 + struct mempolicy *pol_m;
71423 +
71424 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
71425 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
71426 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
71427 + *vma_m = *vma;
71428 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
71429 + if (anon_vma_clone(vma_m, vma))
71430 + return -ENOMEM;
71431 + pol_m = vma_policy(vma_m);
71432 + mpol_get(pol_m);
71433 + vma_set_policy(vma_m, pol_m);
71434 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
71435 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
71436 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
71437 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
71438 + if (vma_m->vm_file)
71439 + get_file(vma_m->vm_file);
71440 + if (vma_m->vm_ops && vma_m->vm_ops->open)
71441 + vma_m->vm_ops->open(vma_m);
71442 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
71443 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
71444 + vma_m->vm_mirror = vma;
71445 + vma->vm_mirror = vma_m;
71446 + return 0;
71447 +}
71448 +#endif
71449 +
71450 /*
71451 * Return true if the calling process may expand its vm space by the passed
71452 * number of pages
71453 @@ -2383,7 +2864,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
71454 unsigned long lim;
71455
71456 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
71457 -
71458 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
71459 if (cur + npages > lim)
71460 return 0;
71461 return 1;
71462 @@ -2454,6 +2935,22 @@ int install_special_mapping(struct mm_struct *mm,
71463 vma->vm_start = addr;
71464 vma->vm_end = addr + len;
71465
71466 +#ifdef CONFIG_PAX_MPROTECT
71467 + if (mm->pax_flags & MF_PAX_MPROTECT) {
71468 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
71469 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
71470 + return -EPERM;
71471 + if (!(vm_flags & VM_EXEC))
71472 + vm_flags &= ~VM_MAYEXEC;
71473 +#else
71474 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71475 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71476 +#endif
71477 + else
71478 + vm_flags &= ~VM_MAYWRITE;
71479 + }
71480 +#endif
71481 +
71482 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
71483 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71484
71485 diff --git a/mm/mprotect.c b/mm/mprotect.c
71486 index 5a688a2..27e031c 100644
71487 --- a/mm/mprotect.c
71488 +++ b/mm/mprotect.c
71489 @@ -23,10 +23,16 @@
71490 #include <linux/mmu_notifier.h>
71491 #include <linux/migrate.h>
71492 #include <linux/perf_event.h>
71493 +
71494 +#ifdef CONFIG_PAX_MPROTECT
71495 +#include <linux/elf.h>
71496 +#endif
71497 +
71498 #include <asm/uaccess.h>
71499 #include <asm/pgtable.h>
71500 #include <asm/cacheflush.h>
71501 #include <asm/tlbflush.h>
71502 +#include <asm/mmu_context.h>
71503
71504 #ifndef pgprot_modify
71505 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
71506 @@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
71507 flush_tlb_range(vma, start, end);
71508 }
71509
71510 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
71511 +/* called while holding the mmap semaphor for writing except stack expansion */
71512 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
71513 +{
71514 + unsigned long oldlimit, newlimit = 0UL;
71515 +
71516 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
71517 + return;
71518 +
71519 + spin_lock(&mm->page_table_lock);
71520 + oldlimit = mm->context.user_cs_limit;
71521 + if ((prot & VM_EXEC) && oldlimit < end)
71522 + /* USER_CS limit moved up */
71523 + newlimit = end;
71524 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
71525 + /* USER_CS limit moved down */
71526 + newlimit = start;
71527 +
71528 + if (newlimit) {
71529 + mm->context.user_cs_limit = newlimit;
71530 +
71531 +#ifdef CONFIG_SMP
71532 + wmb();
71533 + cpus_clear(mm->context.cpu_user_cs_mask);
71534 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
71535 +#endif
71536 +
71537 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
71538 + }
71539 + spin_unlock(&mm->page_table_lock);
71540 + if (newlimit == end) {
71541 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
71542 +
71543 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
71544 + if (is_vm_hugetlb_page(vma))
71545 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
71546 + else
71547 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
71548 + }
71549 +}
71550 +#endif
71551 +
71552 int
71553 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
71554 unsigned long start, unsigned long end, unsigned long newflags)
71555 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
71556 int error;
71557 int dirty_accountable = 0;
71558
71559 +#ifdef CONFIG_PAX_SEGMEXEC
71560 + struct vm_area_struct *vma_m = NULL;
71561 + unsigned long start_m, end_m;
71562 +
71563 + start_m = start + SEGMEXEC_TASK_SIZE;
71564 + end_m = end + SEGMEXEC_TASK_SIZE;
71565 +#endif
71566 +
71567 if (newflags == oldflags) {
71568 *pprev = vma;
71569 return 0;
71570 }
71571
71572 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
71573 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
71574 +
71575 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
71576 + return -ENOMEM;
71577 +
71578 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
71579 + return -ENOMEM;
71580 + }
71581 +
71582 /*
71583 * If we make a private mapping writable we increase our commit;
71584 * but (without finer accounting) cannot reduce our commit if we
71585 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
71586 }
71587 }
71588
71589 +#ifdef CONFIG_PAX_SEGMEXEC
71590 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
71591 + if (start != vma->vm_start) {
71592 + error = split_vma(mm, vma, start, 1);
71593 + if (error)
71594 + goto fail;
71595 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
71596 + *pprev = (*pprev)->vm_next;
71597 + }
71598 +
71599 + if (end != vma->vm_end) {
71600 + error = split_vma(mm, vma, end, 0);
71601 + if (error)
71602 + goto fail;
71603 + }
71604 +
71605 + if (pax_find_mirror_vma(vma)) {
71606 + error = __do_munmap(mm, start_m, end_m - start_m);
71607 + if (error)
71608 + goto fail;
71609 + } else {
71610 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71611 + if (!vma_m) {
71612 + error = -ENOMEM;
71613 + goto fail;
71614 + }
71615 + vma->vm_flags = newflags;
71616 + error = pax_mirror_vma(vma_m, vma);
71617 + if (error) {
71618 + vma->vm_flags = oldflags;
71619 + goto fail;
71620 + }
71621 + }
71622 + }
71623 +#endif
71624 +
71625 /*
71626 * First try to merge with previous and/or next vma.
71627 */
71628 @@ -204,9 +306,21 @@ success:
71629 * vm_flags and vm_page_prot are protected by the mmap_sem
71630 * held in write mode.
71631 */
71632 +
71633 +#ifdef CONFIG_PAX_SEGMEXEC
71634 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
71635 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
71636 +#endif
71637 +
71638 vma->vm_flags = newflags;
71639 +
71640 +#ifdef CONFIG_PAX_MPROTECT
71641 + if (mm->binfmt && mm->binfmt->handle_mprotect)
71642 + mm->binfmt->handle_mprotect(vma, newflags);
71643 +#endif
71644 +
71645 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
71646 - vm_get_page_prot(newflags));
71647 + vm_get_page_prot(vma->vm_flags));
71648
71649 if (vma_wants_writenotify(vma)) {
71650 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
71651 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
71652 end = start + len;
71653 if (end <= start)
71654 return -ENOMEM;
71655 +
71656 +#ifdef CONFIG_PAX_SEGMEXEC
71657 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71658 + if (end > SEGMEXEC_TASK_SIZE)
71659 + return -EINVAL;
71660 + } else
71661 +#endif
71662 +
71663 + if (end > TASK_SIZE)
71664 + return -EINVAL;
71665 +
71666 if (!arch_validate_prot(prot))
71667 return -EINVAL;
71668
71669 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
71670 /*
71671 * Does the application expect PROT_READ to imply PROT_EXEC:
71672 */
71673 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
71674 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
71675 prot |= PROT_EXEC;
71676
71677 vm_flags = calc_vm_prot_bits(prot);
71678 @@ -287,6 +412,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
71679 if (start > vma->vm_start)
71680 prev = vma;
71681
71682 +#ifdef CONFIG_PAX_MPROTECT
71683 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
71684 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
71685 +#endif
71686 +
71687 for (nstart = start ; ; ) {
71688 unsigned long newflags;
71689
71690 @@ -296,6 +426,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
71691
71692 /* newflags >> 4 shift VM_MAY% in place of VM_% */
71693 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
71694 + if (prot & (PROT_WRITE | PROT_EXEC))
71695 + gr_log_rwxmprotect(vma->vm_file);
71696 +
71697 + error = -EACCES;
71698 + goto out;
71699 + }
71700 +
71701 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
71702 error = -EACCES;
71703 goto out;
71704 }
71705 @@ -310,6 +448,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
71706 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
71707 if (error)
71708 goto out;
71709 +
71710 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
71711 +
71712 nstart = tmp;
71713
71714 if (nstart < prev->vm_end)
71715 diff --git a/mm/mremap.c b/mm/mremap.c
71716 index d6959cb..18a402a 100644
71717 --- a/mm/mremap.c
71718 +++ b/mm/mremap.c
71719 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
71720 continue;
71721 pte = ptep_get_and_clear(mm, old_addr, old_pte);
71722 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
71723 +
71724 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
71725 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
71726 + pte = pte_exprotect(pte);
71727 +#endif
71728 +
71729 set_pte_at(mm, new_addr, new_pte, pte);
71730 }
71731
71732 @@ -290,6 +296,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
71733 if (is_vm_hugetlb_page(vma))
71734 goto Einval;
71735
71736 +#ifdef CONFIG_PAX_SEGMEXEC
71737 + if (pax_find_mirror_vma(vma))
71738 + goto Einval;
71739 +#endif
71740 +
71741 /* We can't remap across vm area boundaries */
71742 if (old_len > vma->vm_end - addr)
71743 goto Efault;
71744 @@ -346,20 +357,25 @@ static unsigned long mremap_to(unsigned long addr,
71745 unsigned long ret = -EINVAL;
71746 unsigned long charged = 0;
71747 unsigned long map_flags;
71748 + unsigned long pax_task_size = TASK_SIZE;
71749
71750 if (new_addr & ~PAGE_MASK)
71751 goto out;
71752
71753 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
71754 +#ifdef CONFIG_PAX_SEGMEXEC
71755 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
71756 + pax_task_size = SEGMEXEC_TASK_SIZE;
71757 +#endif
71758 +
71759 + pax_task_size -= PAGE_SIZE;
71760 +
71761 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
71762 goto out;
71763
71764 /* Check if the location we're moving into overlaps the
71765 * old location at all, and fail if it does.
71766 */
71767 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
71768 - goto out;
71769 -
71770 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
71771 + if (addr + old_len > new_addr && new_addr + new_len > addr)
71772 goto out;
71773
71774 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
71775 @@ -431,6 +447,7 @@ unsigned long do_mremap(unsigned long addr,
71776 struct vm_area_struct *vma;
71777 unsigned long ret = -EINVAL;
71778 unsigned long charged = 0;
71779 + unsigned long pax_task_size = TASK_SIZE;
71780
71781 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
71782 goto out;
71783 @@ -449,6 +466,17 @@ unsigned long do_mremap(unsigned long addr,
71784 if (!new_len)
71785 goto out;
71786
71787 +#ifdef CONFIG_PAX_SEGMEXEC
71788 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
71789 + pax_task_size = SEGMEXEC_TASK_SIZE;
71790 +#endif
71791 +
71792 + pax_task_size -= PAGE_SIZE;
71793 +
71794 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
71795 + old_len > pax_task_size || addr > pax_task_size-old_len)
71796 + goto out;
71797 +
71798 if (flags & MREMAP_FIXED) {
71799 if (flags & MREMAP_MAYMOVE)
71800 ret = mremap_to(addr, old_len, new_addr, new_len);
71801 @@ -498,6 +526,7 @@ unsigned long do_mremap(unsigned long addr,
71802 addr + new_len);
71803 }
71804 ret = addr;
71805 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
71806 goto out;
71807 }
71808 }
71809 @@ -524,7 +553,13 @@ unsigned long do_mremap(unsigned long addr,
71810 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
71811 if (ret)
71812 goto out;
71813 +
71814 + map_flags = vma->vm_flags;
71815 ret = move_vma(vma, addr, old_len, new_len, new_addr);
71816 + if (!(ret & ~PAGE_MASK)) {
71817 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
71818 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
71819 + }
71820 }
71821 out:
71822 if (ret & ~PAGE_MASK)
71823 diff --git a/mm/nobootmem.c b/mm/nobootmem.c
71824 index 7fa41b4..6087460 100644
71825 --- a/mm/nobootmem.c
71826 +++ b/mm/nobootmem.c
71827 @@ -110,19 +110,30 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end)
71828 unsigned long __init free_all_memory_core_early(int nodeid)
71829 {
71830 int i;
71831 - u64 start, end;
71832 + u64 start, end, startrange, endrange;
71833 unsigned long count = 0;
71834 - struct range *range = NULL;
71835 + struct range *range = NULL, rangerange = { 0, 0 };
71836 int nr_range;
71837
71838 nr_range = get_free_all_memory_range(&range, nodeid);
71839 + startrange = __pa(range) >> PAGE_SHIFT;
71840 + endrange = (__pa(range + nr_range) - 1) >> PAGE_SHIFT;
71841
71842 for (i = 0; i < nr_range; i++) {
71843 start = range[i].start;
71844 end = range[i].end;
71845 + if (start <= endrange && startrange < end) {
71846 + BUG_ON(rangerange.start | rangerange.end);
71847 + rangerange = range[i];
71848 + continue;
71849 + }
71850 count += end - start;
71851 __free_pages_memory(start, end);
71852 }
71853 + start = rangerange.start;
71854 + end = rangerange.end;
71855 + count += end - start;
71856 + __free_pages_memory(start, end);
71857
71858 return count;
71859 }
71860 diff --git a/mm/nommu.c b/mm/nommu.c
71861 index ee7e57e..cae4e40 100644
71862 --- a/mm/nommu.c
71863 +++ b/mm/nommu.c
71864 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
71865 int sysctl_overcommit_ratio = 50; /* default is 50% */
71866 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
71867 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
71868 -int heap_stack_gap = 0;
71869
71870 atomic_long_t mmap_pages_allocated;
71871
71872 @@ -829,15 +828,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
71873 EXPORT_SYMBOL(find_vma);
71874
71875 /*
71876 - * find a VMA
71877 - * - we don't extend stack VMAs under NOMMU conditions
71878 - */
71879 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
71880 -{
71881 - return find_vma(mm, addr);
71882 -}
71883 -
71884 -/*
71885 * expand a stack to a given address
71886 * - not supported under NOMMU conditions
71887 */
71888 @@ -1557,6 +1547,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71889
71890 /* most fields are the same, copy all, and then fixup */
71891 *new = *vma;
71892 + INIT_LIST_HEAD(&new->anon_vma_chain);
71893 *region = *vma->vm_region;
71894 new->vm_region = region;
71895
71896 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
71897 index 485be89..c059ad3 100644
71898 --- a/mm/page_alloc.c
71899 +++ b/mm/page_alloc.c
71900 @@ -341,7 +341,7 @@ out:
71901 * This usage means that zero-order pages may not be compound.
71902 */
71903
71904 -static void free_compound_page(struct page *page)
71905 +void free_compound_page(struct page *page)
71906 {
71907 __free_pages_ok(page, compound_order(page));
71908 }
71909 @@ -654,6 +654,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
71910 int i;
71911 int bad = 0;
71912
71913 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
71914 + unsigned long index = 1UL << order;
71915 +#endif
71916 +
71917 trace_mm_page_free_direct(page, order);
71918 kmemcheck_free_shadow(page, order);
71919
71920 @@ -669,6 +673,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
71921 debug_check_no_obj_freed(page_address(page),
71922 PAGE_SIZE << order);
71923 }
71924 +
71925 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
71926 + for (; index; --index)
71927 + sanitize_highpage(page + index - 1);
71928 +#endif
71929 +
71930 arch_free_page(page, order);
71931 kernel_map_pages(page, 1 << order, 0);
71932
71933 @@ -784,8 +794,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
71934 arch_alloc_page(page, order);
71935 kernel_map_pages(page, 1 << order, 1);
71936
71937 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
71938 if (gfp_flags & __GFP_ZERO)
71939 prep_zero_page(page, order, gfp_flags);
71940 +#endif
71941
71942 if (order && (gfp_flags & __GFP_COMP))
71943 prep_compound_page(page, order);
71944 @@ -3357,7 +3369,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
71945 unsigned long pfn;
71946
71947 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
71948 +#ifdef CONFIG_X86_32
71949 + /* boot failures in VMware 8 on 32bit vanilla since
71950 + this change */
71951 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
71952 +#else
71953 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
71954 +#endif
71955 return 1;
71956 }
71957 return 0;
71958 diff --git a/mm/percpu.c b/mm/percpu.c
71959 index 716eb4a..8d10419 100644
71960 --- a/mm/percpu.c
71961 +++ b/mm/percpu.c
71962 @@ -121,7 +121,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
71963 static unsigned int pcpu_high_unit_cpu __read_mostly;
71964
71965 /* the address of the first chunk which starts with the kernel static area */
71966 -void *pcpu_base_addr __read_mostly;
71967 +void *pcpu_base_addr __read_only;
71968 EXPORT_SYMBOL_GPL(pcpu_base_addr);
71969
71970 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
71971 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
71972 index e920aa3..137702a 100644
71973 --- a/mm/process_vm_access.c
71974 +++ b/mm/process_vm_access.c
71975 @@ -13,6 +13,7 @@
71976 #include <linux/uio.h>
71977 #include <linux/sched.h>
71978 #include <linux/highmem.h>
71979 +#include <linux/security.h>
71980 #include <linux/ptrace.h>
71981 #include <linux/slab.h>
71982 #include <linux/syscalls.h>
71983 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
71984 size_t iov_l_curr_offset = 0;
71985 ssize_t iov_len;
71986
71987 + return -ENOSYS; // PaX: until properly audited
71988 +
71989 /*
71990 * Work out how many pages of struct pages we're going to need
71991 * when eventually calling get_user_pages
71992 */
71993 for (i = 0; i < riovcnt; i++) {
71994 iov_len = rvec[i].iov_len;
71995 - if (iov_len > 0) {
71996 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
71997 - + iov_len)
71998 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
71999 - / PAGE_SIZE + 1;
72000 - nr_pages = max(nr_pages, nr_pages_iov);
72001 - }
72002 + if (iov_len <= 0)
72003 + continue;
72004 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
72005 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
72006 + nr_pages = max(nr_pages, nr_pages_iov);
72007 }
72008
72009 if (nr_pages == 0)
72010 @@ -298,23 +299,23 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
72011 goto free_proc_pages;
72012 }
72013
72014 - task_lock(task);
72015 - if (__ptrace_may_access(task, PTRACE_MODE_ATTACH)) {
72016 - task_unlock(task);
72017 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
72018 rc = -EPERM;
72019 goto put_task_struct;
72020 }
72021 - mm = task->mm;
72022
72023 - if (!mm || (task->flags & PF_KTHREAD)) {
72024 - task_unlock(task);
72025 - rc = -EINVAL;
72026 + mm = mm_access(task, PTRACE_MODE_ATTACH);
72027 + if (!mm || IS_ERR(mm)) {
72028 + rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
72029 + /*
72030 + * Explicitly map EACCES to EPERM as EPERM is a more a
72031 + * appropriate error code for process_vw_readv/writev
72032 + */
72033 + if (rc == -EACCES)
72034 + rc = -EPERM;
72035 goto put_task_struct;
72036 }
72037
72038 - atomic_inc(&mm->mm_users);
72039 - task_unlock(task);
72040 -
72041 for (i = 0; i < riovcnt && iov_l_curr_idx < liovcnt; i++) {
72042 rc = process_vm_rw_single_vec(
72043 (unsigned long)rvec[i].iov_base, rvec[i].iov_len,
72044 diff --git a/mm/rmap.c b/mm/rmap.c
72045 index a4fd368..e0ffec7 100644
72046 --- a/mm/rmap.c
72047 +++ b/mm/rmap.c
72048 @@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72049 struct anon_vma *anon_vma = vma->anon_vma;
72050 struct anon_vma_chain *avc;
72051
72052 +#ifdef CONFIG_PAX_SEGMEXEC
72053 + struct anon_vma_chain *avc_m = NULL;
72054 +#endif
72055 +
72056 might_sleep();
72057 if (unlikely(!anon_vma)) {
72058 struct mm_struct *mm = vma->vm_mm;
72059 @@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72060 if (!avc)
72061 goto out_enomem;
72062
72063 +#ifdef CONFIG_PAX_SEGMEXEC
72064 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
72065 + if (!avc_m)
72066 + goto out_enomem_free_avc;
72067 +#endif
72068 +
72069 anon_vma = find_mergeable_anon_vma(vma);
72070 allocated = NULL;
72071 if (!anon_vma) {
72072 @@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72073 /* page_table_lock to protect against threads */
72074 spin_lock(&mm->page_table_lock);
72075 if (likely(!vma->anon_vma)) {
72076 +
72077 +#ifdef CONFIG_PAX_SEGMEXEC
72078 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
72079 +
72080 + if (vma_m) {
72081 + BUG_ON(vma_m->anon_vma);
72082 + vma_m->anon_vma = anon_vma;
72083 + avc_m->anon_vma = anon_vma;
72084 + avc_m->vma = vma;
72085 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
72086 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
72087 + avc_m = NULL;
72088 + }
72089 +#endif
72090 +
72091 vma->anon_vma = anon_vma;
72092 avc->anon_vma = anon_vma;
72093 avc->vma = vma;
72094 @@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72095
72096 if (unlikely(allocated))
72097 put_anon_vma(allocated);
72098 +
72099 +#ifdef CONFIG_PAX_SEGMEXEC
72100 + if (unlikely(avc_m))
72101 + anon_vma_chain_free(avc_m);
72102 +#endif
72103 +
72104 if (unlikely(avc))
72105 anon_vma_chain_free(avc);
72106 }
72107 return 0;
72108
72109 out_enomem_free_avc:
72110 +
72111 +#ifdef CONFIG_PAX_SEGMEXEC
72112 + if (avc_m)
72113 + anon_vma_chain_free(avc_m);
72114 +#endif
72115 +
72116 anon_vma_chain_free(avc);
72117 out_enomem:
72118 return -ENOMEM;
72119 @@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
72120 * Attach the anon_vmas from src to dst.
72121 * Returns 0 on success, -ENOMEM on failure.
72122 */
72123 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
72124 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
72125 {
72126 struct anon_vma_chain *avc, *pavc;
72127 struct anon_vma *root = NULL;
72128 @@ -276,7 +313,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
72129 * the corresponding VMA in the parent process is attached to.
72130 * Returns 0 on success, non-zero on failure.
72131 */
72132 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
72133 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
72134 {
72135 struct anon_vma_chain *avc;
72136 struct anon_vma *anon_vma;
72137 diff --git a/mm/shmem.c b/mm/shmem.c
72138 index 6c253f7..367e20a 100644
72139 --- a/mm/shmem.c
72140 +++ b/mm/shmem.c
72141 @@ -31,7 +31,7 @@
72142 #include <linux/export.h>
72143 #include <linux/swap.h>
72144
72145 -static struct vfsmount *shm_mnt;
72146 +struct vfsmount *shm_mnt;
72147
72148 #ifdef CONFIG_SHMEM
72149 /*
72150 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
72151 #define BOGO_DIRENT_SIZE 20
72152
72153 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
72154 -#define SHORT_SYMLINK_LEN 128
72155 +#define SHORT_SYMLINK_LEN 64
72156
72157 struct shmem_xattr {
72158 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
72159 @@ -2180,8 +2180,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
72160 int err = -ENOMEM;
72161
72162 /* Round up to L1_CACHE_BYTES to resist false sharing */
72163 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
72164 - L1_CACHE_BYTES), GFP_KERNEL);
72165 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
72166 if (!sbinfo)
72167 return -ENOMEM;
72168
72169 diff --git a/mm/slab.c b/mm/slab.c
72170 index 83311c9a..fcf8f86 100644
72171 --- a/mm/slab.c
72172 +++ b/mm/slab.c
72173 @@ -151,7 +151,7 @@
72174
72175 /* Legal flag mask for kmem_cache_create(). */
72176 #if DEBUG
72177 -# define CREATE_MASK (SLAB_RED_ZONE | \
72178 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
72179 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
72180 SLAB_CACHE_DMA | \
72181 SLAB_STORE_USER | \
72182 @@ -159,7 +159,7 @@
72183 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
72184 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
72185 #else
72186 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
72187 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
72188 SLAB_CACHE_DMA | \
72189 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
72190 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
72191 @@ -288,7 +288,7 @@ struct kmem_list3 {
72192 * Need this for bootstrapping a per node allocator.
72193 */
72194 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
72195 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
72196 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
72197 #define CACHE_CACHE 0
72198 #define SIZE_AC MAX_NUMNODES
72199 #define SIZE_L3 (2 * MAX_NUMNODES)
72200 @@ -389,10 +389,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
72201 if ((x)->max_freeable < i) \
72202 (x)->max_freeable = i; \
72203 } while (0)
72204 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
72205 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
72206 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
72207 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
72208 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
72209 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
72210 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
72211 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
72212 #else
72213 #define STATS_INC_ACTIVE(x) do { } while (0)
72214 #define STATS_DEC_ACTIVE(x) do { } while (0)
72215 @@ -538,7 +538,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
72216 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
72217 */
72218 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
72219 - const struct slab *slab, void *obj)
72220 + const struct slab *slab, const void *obj)
72221 {
72222 u32 offset = (obj - slab->s_mem);
72223 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
72224 @@ -564,7 +564,7 @@ struct cache_names {
72225 static struct cache_names __initdata cache_names[] = {
72226 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
72227 #include <linux/kmalloc_sizes.h>
72228 - {NULL,}
72229 + {NULL}
72230 #undef CACHE
72231 };
72232
72233 @@ -1572,7 +1572,7 @@ void __init kmem_cache_init(void)
72234 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
72235 sizes[INDEX_AC].cs_size,
72236 ARCH_KMALLOC_MINALIGN,
72237 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72238 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72239 NULL);
72240
72241 if (INDEX_AC != INDEX_L3) {
72242 @@ -1580,7 +1580,7 @@ void __init kmem_cache_init(void)
72243 kmem_cache_create(names[INDEX_L3].name,
72244 sizes[INDEX_L3].cs_size,
72245 ARCH_KMALLOC_MINALIGN,
72246 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72247 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72248 NULL);
72249 }
72250
72251 @@ -1598,7 +1598,7 @@ void __init kmem_cache_init(void)
72252 sizes->cs_cachep = kmem_cache_create(names->name,
72253 sizes->cs_size,
72254 ARCH_KMALLOC_MINALIGN,
72255 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72256 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72257 NULL);
72258 }
72259 #ifdef CONFIG_ZONE_DMA
72260 @@ -4322,10 +4322,10 @@ static int s_show(struct seq_file *m, void *p)
72261 }
72262 /* cpu stats */
72263 {
72264 - unsigned long allochit = atomic_read(&cachep->allochit);
72265 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
72266 - unsigned long freehit = atomic_read(&cachep->freehit);
72267 - unsigned long freemiss = atomic_read(&cachep->freemiss);
72268 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
72269 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
72270 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
72271 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
72272
72273 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
72274 allochit, allocmiss, freehit, freemiss);
72275 @@ -4584,13 +4584,62 @@ static int __init slab_proc_init(void)
72276 {
72277 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
72278 #ifdef CONFIG_DEBUG_SLAB_LEAK
72279 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
72280 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
72281 #endif
72282 return 0;
72283 }
72284 module_init(slab_proc_init);
72285 #endif
72286
72287 +void check_object_size(const void *ptr, unsigned long n, bool to)
72288 +{
72289 +
72290 +#ifdef CONFIG_PAX_USERCOPY
72291 + struct page *page;
72292 + struct kmem_cache *cachep = NULL;
72293 + struct slab *slabp;
72294 + unsigned int objnr;
72295 + unsigned long offset;
72296 + const char *type;
72297 +
72298 + if (!n)
72299 + return;
72300 +
72301 + type = "<null>";
72302 + if (ZERO_OR_NULL_PTR(ptr))
72303 + goto report;
72304 +
72305 + if (!virt_addr_valid(ptr))
72306 + return;
72307 +
72308 + page = virt_to_head_page(ptr);
72309 +
72310 + type = "<process stack>";
72311 + if (!PageSlab(page)) {
72312 + if (object_is_on_stack(ptr, n) == -1)
72313 + goto report;
72314 + return;
72315 + }
72316 +
72317 + cachep = page_get_cache(page);
72318 + type = cachep->name;
72319 + if (!(cachep->flags & SLAB_USERCOPY))
72320 + goto report;
72321 +
72322 + slabp = page_get_slab(page);
72323 + objnr = obj_to_index(cachep, slabp, ptr);
72324 + BUG_ON(objnr >= cachep->num);
72325 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
72326 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
72327 + return;
72328 +
72329 +report:
72330 + pax_report_usercopy(ptr, n, to, type);
72331 +#endif
72332 +
72333 +}
72334 +EXPORT_SYMBOL(check_object_size);
72335 +
72336 /**
72337 * ksize - get the actual amount of memory allocated for a given object
72338 * @objp: Pointer to the object
72339 diff --git a/mm/slob.c b/mm/slob.c
72340 index 8105be4..e045f96 100644
72341 --- a/mm/slob.c
72342 +++ b/mm/slob.c
72343 @@ -29,7 +29,7 @@
72344 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
72345 * alloc_pages() directly, allocating compound pages so the page order
72346 * does not have to be separately tracked, and also stores the exact
72347 - * allocation size in page->private so that it can be used to accurately
72348 + * allocation size in slob_page->size so that it can be used to accurately
72349 * provide ksize(). These objects are detected in kfree() because slob_page()
72350 * is false for them.
72351 *
72352 @@ -58,6 +58,7 @@
72353 */
72354
72355 #include <linux/kernel.h>
72356 +#include <linux/sched.h>
72357 #include <linux/slab.h>
72358 #include <linux/mm.h>
72359 #include <linux/swap.h> /* struct reclaim_state */
72360 @@ -102,7 +103,8 @@ struct slob_page {
72361 unsigned long flags; /* mandatory */
72362 atomic_t _count; /* mandatory */
72363 slobidx_t units; /* free units left in page */
72364 - unsigned long pad[2];
72365 + unsigned long pad[1];
72366 + unsigned long size; /* size when >=PAGE_SIZE */
72367 slob_t *free; /* first free slob_t in page */
72368 struct list_head list; /* linked list of free pages */
72369 };
72370 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
72371 */
72372 static inline int is_slob_page(struct slob_page *sp)
72373 {
72374 - return PageSlab((struct page *)sp);
72375 + return PageSlab((struct page *)sp) && !sp->size;
72376 }
72377
72378 static inline void set_slob_page(struct slob_page *sp)
72379 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
72380
72381 static inline struct slob_page *slob_page(const void *addr)
72382 {
72383 - return (struct slob_page *)virt_to_page(addr);
72384 + return (struct slob_page *)virt_to_head_page(addr);
72385 }
72386
72387 /*
72388 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
72389 /*
72390 * Return the size of a slob block.
72391 */
72392 -static slobidx_t slob_units(slob_t *s)
72393 +static slobidx_t slob_units(const slob_t *s)
72394 {
72395 if (s->units > 0)
72396 return s->units;
72397 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
72398 /*
72399 * Return the next free slob block pointer after this one.
72400 */
72401 -static slob_t *slob_next(slob_t *s)
72402 +static slob_t *slob_next(const slob_t *s)
72403 {
72404 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
72405 slobidx_t next;
72406 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
72407 /*
72408 * Returns true if s is the last free block in its page.
72409 */
72410 -static int slob_last(slob_t *s)
72411 +static int slob_last(const slob_t *s)
72412 {
72413 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
72414 }
72415 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
72416 if (!page)
72417 return NULL;
72418
72419 + set_slob_page(page);
72420 return page_address(page);
72421 }
72422
72423 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
72424 if (!b)
72425 return NULL;
72426 sp = slob_page(b);
72427 - set_slob_page(sp);
72428
72429 spin_lock_irqsave(&slob_lock, flags);
72430 sp->units = SLOB_UNITS(PAGE_SIZE);
72431 sp->free = b;
72432 + sp->size = 0;
72433 INIT_LIST_HEAD(&sp->list);
72434 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
72435 set_slob_page_free(sp, slob_list);
72436 @@ -476,10 +479,9 @@ out:
72437 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
72438 */
72439
72440 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72441 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
72442 {
72443 - unsigned int *m;
72444 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72445 + slob_t *m;
72446 void *ret;
72447
72448 gfp &= gfp_allowed_mask;
72449 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72450
72451 if (!m)
72452 return NULL;
72453 - *m = size;
72454 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
72455 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
72456 + m[0].units = size;
72457 + m[1].units = align;
72458 ret = (void *)m + align;
72459
72460 trace_kmalloc_node(_RET_IP_, ret,
72461 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72462 gfp |= __GFP_COMP;
72463 ret = slob_new_pages(gfp, order, node);
72464 if (ret) {
72465 - struct page *page;
72466 - page = virt_to_page(ret);
72467 - page->private = size;
72468 + struct slob_page *sp;
72469 + sp = slob_page(ret);
72470 + sp->size = size;
72471 }
72472
72473 trace_kmalloc_node(_RET_IP_, ret,
72474 size, PAGE_SIZE << order, gfp, node);
72475 }
72476
72477 - kmemleak_alloc(ret, size, 1, gfp);
72478 + return ret;
72479 +}
72480 +
72481 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72482 +{
72483 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72484 + void *ret = __kmalloc_node_align(size, gfp, node, align);
72485 +
72486 + if (!ZERO_OR_NULL_PTR(ret))
72487 + kmemleak_alloc(ret, size, 1, gfp);
72488 return ret;
72489 }
72490 EXPORT_SYMBOL(__kmalloc_node);
72491 @@ -533,13 +547,92 @@ void kfree(const void *block)
72492 sp = slob_page(block);
72493 if (is_slob_page(sp)) {
72494 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72495 - unsigned int *m = (unsigned int *)(block - align);
72496 - slob_free(m, *m + align);
72497 - } else
72498 + slob_t *m = (slob_t *)(block - align);
72499 + slob_free(m, m[0].units + align);
72500 + } else {
72501 + clear_slob_page(sp);
72502 + free_slob_page(sp);
72503 + sp->size = 0;
72504 put_page(&sp->page);
72505 + }
72506 }
72507 EXPORT_SYMBOL(kfree);
72508
72509 +void check_object_size(const void *ptr, unsigned long n, bool to)
72510 +{
72511 +
72512 +#ifdef CONFIG_PAX_USERCOPY
72513 + struct slob_page *sp;
72514 + const slob_t *free;
72515 + const void *base;
72516 + unsigned long flags;
72517 + const char *type;
72518 +
72519 + if (!n)
72520 + return;
72521 +
72522 + type = "<null>";
72523 + if (ZERO_OR_NULL_PTR(ptr))
72524 + goto report;
72525 +
72526 + if (!virt_addr_valid(ptr))
72527 + return;
72528 +
72529 + type = "<process stack>";
72530 + sp = slob_page(ptr);
72531 + if (!PageSlab((struct page *)sp)) {
72532 + if (object_is_on_stack(ptr, n) == -1)
72533 + goto report;
72534 + return;
72535 + }
72536 +
72537 + type = "<slob>";
72538 + if (sp->size) {
72539 + base = page_address(&sp->page);
72540 + if (base <= ptr && n <= sp->size - (ptr - base))
72541 + return;
72542 + goto report;
72543 + }
72544 +
72545 + /* some tricky double walking to find the chunk */
72546 + spin_lock_irqsave(&slob_lock, flags);
72547 + base = (void *)((unsigned long)ptr & PAGE_MASK);
72548 + free = sp->free;
72549 +
72550 + while (!slob_last(free) && (void *)free <= ptr) {
72551 + base = free + slob_units(free);
72552 + free = slob_next(free);
72553 + }
72554 +
72555 + while (base < (void *)free) {
72556 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
72557 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
72558 + int offset;
72559 +
72560 + if (ptr < base + align)
72561 + break;
72562 +
72563 + offset = ptr - base - align;
72564 + if (offset >= m) {
72565 + base += size;
72566 + continue;
72567 + }
72568 +
72569 + if (n > m - offset)
72570 + break;
72571 +
72572 + spin_unlock_irqrestore(&slob_lock, flags);
72573 + return;
72574 + }
72575 +
72576 + spin_unlock_irqrestore(&slob_lock, flags);
72577 +report:
72578 + pax_report_usercopy(ptr, n, to, type);
72579 +#endif
72580 +
72581 +}
72582 +EXPORT_SYMBOL(check_object_size);
72583 +
72584 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
72585 size_t ksize(const void *block)
72586 {
72587 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
72588 sp = slob_page(block);
72589 if (is_slob_page(sp)) {
72590 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72591 - unsigned int *m = (unsigned int *)(block - align);
72592 - return SLOB_UNITS(*m) * SLOB_UNIT;
72593 + slob_t *m = (slob_t *)(block - align);
72594 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
72595 } else
72596 - return sp->page.private;
72597 + return sp->size;
72598 }
72599 EXPORT_SYMBOL(ksize);
72600
72601 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
72602 {
72603 struct kmem_cache *c;
72604
72605 +#ifdef CONFIG_PAX_USERCOPY
72606 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
72607 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
72608 +#else
72609 c = slob_alloc(sizeof(struct kmem_cache),
72610 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
72611 +#endif
72612
72613 if (c) {
72614 c->name = name;
72615 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
72616
72617 lockdep_trace_alloc(flags);
72618
72619 +#ifdef CONFIG_PAX_USERCOPY
72620 + b = __kmalloc_node_align(c->size, flags, node, c->align);
72621 +#else
72622 if (c->size < PAGE_SIZE) {
72623 b = slob_alloc(c->size, flags, c->align, node);
72624 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
72625 SLOB_UNITS(c->size) * SLOB_UNIT,
72626 flags, node);
72627 } else {
72628 + struct slob_page *sp;
72629 +
72630 b = slob_new_pages(flags, get_order(c->size), node);
72631 + sp = slob_page(b);
72632 + sp->size = c->size;
72633 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
72634 PAGE_SIZE << get_order(c->size),
72635 flags, node);
72636 }
72637 +#endif
72638
72639 if (c->ctor)
72640 c->ctor(b);
72641 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
72642
72643 static void __kmem_cache_free(void *b, int size)
72644 {
72645 - if (size < PAGE_SIZE)
72646 + struct slob_page *sp = slob_page(b);
72647 +
72648 + if (is_slob_page(sp))
72649 slob_free(b, size);
72650 - else
72651 + else {
72652 + clear_slob_page(sp);
72653 + free_slob_page(sp);
72654 + sp->size = 0;
72655 slob_free_pages(b, get_order(size));
72656 + }
72657 }
72658
72659 static void kmem_rcu_free(struct rcu_head *head)
72660 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
72661
72662 void kmem_cache_free(struct kmem_cache *c, void *b)
72663 {
72664 + int size = c->size;
72665 +
72666 +#ifdef CONFIG_PAX_USERCOPY
72667 + if (size + c->align < PAGE_SIZE) {
72668 + size += c->align;
72669 + b -= c->align;
72670 + }
72671 +#endif
72672 +
72673 kmemleak_free_recursive(b, c->flags);
72674 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
72675 struct slob_rcu *slob_rcu;
72676 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
72677 - slob_rcu->size = c->size;
72678 + slob_rcu = b + (size - sizeof(struct slob_rcu));
72679 + slob_rcu->size = size;
72680 call_rcu(&slob_rcu->head, kmem_rcu_free);
72681 } else {
72682 - __kmem_cache_free(b, c->size);
72683 + __kmem_cache_free(b, size);
72684 }
72685
72686 +#ifdef CONFIG_PAX_USERCOPY
72687 + trace_kfree(_RET_IP_, b);
72688 +#else
72689 trace_kmem_cache_free(_RET_IP_, b);
72690 +#endif
72691 +
72692 }
72693 EXPORT_SYMBOL(kmem_cache_free);
72694
72695 diff --git a/mm/slub.c b/mm/slub.c
72696 index 1a919f0..1739c9b 100644
72697 --- a/mm/slub.c
72698 +++ b/mm/slub.c
72699 @@ -208,7 +208,7 @@ struct track {
72700
72701 enum track_item { TRACK_ALLOC, TRACK_FREE };
72702
72703 -#ifdef CONFIG_SYSFS
72704 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
72705 static int sysfs_slab_add(struct kmem_cache *);
72706 static int sysfs_slab_alias(struct kmem_cache *, const char *);
72707 static void sysfs_slab_remove(struct kmem_cache *);
72708 @@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
72709 if (!t->addr)
72710 return;
72711
72712 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
72713 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
72714 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
72715 #ifdef CONFIG_STACKTRACE
72716 {
72717 @@ -2559,6 +2559,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
72718
72719 page = virt_to_head_page(x);
72720
72721 + BUG_ON(!PageSlab(page));
72722 +
72723 slab_free(s, page, x, _RET_IP_);
72724
72725 trace_kmem_cache_free(_RET_IP_, x);
72726 @@ -2592,7 +2594,7 @@ static int slub_min_objects;
72727 * Merge control. If this is set then no merging of slab caches will occur.
72728 * (Could be removed. This was introduced to pacify the merge skeptics.)
72729 */
72730 -static int slub_nomerge;
72731 +static int slub_nomerge = 1;
72732
72733 /*
72734 * Calculate the order of allocation given an slab object size.
72735 @@ -3042,7 +3044,7 @@ static int kmem_cache_open(struct kmem_cache *s,
72736 else
72737 s->cpu_partial = 30;
72738
72739 - s->refcount = 1;
72740 + atomic_set(&s->refcount, 1);
72741 #ifdef CONFIG_NUMA
72742 s->remote_node_defrag_ratio = 1000;
72743 #endif
72744 @@ -3146,8 +3148,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
72745 void kmem_cache_destroy(struct kmem_cache *s)
72746 {
72747 down_write(&slub_lock);
72748 - s->refcount--;
72749 - if (!s->refcount) {
72750 + if (atomic_dec_and_test(&s->refcount)) {
72751 list_del(&s->list);
72752 up_write(&slub_lock);
72753 if (kmem_cache_close(s)) {
72754 @@ -3358,6 +3359,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
72755 EXPORT_SYMBOL(__kmalloc_node);
72756 #endif
72757
72758 +void check_object_size(const void *ptr, unsigned long n, bool to)
72759 +{
72760 +
72761 +#ifdef CONFIG_PAX_USERCOPY
72762 + struct page *page;
72763 + struct kmem_cache *s = NULL;
72764 + unsigned long offset;
72765 + const char *type;
72766 +
72767 + if (!n)
72768 + return;
72769 +
72770 + type = "<null>";
72771 + if (ZERO_OR_NULL_PTR(ptr))
72772 + goto report;
72773 +
72774 + if (!virt_addr_valid(ptr))
72775 + return;
72776 +
72777 + page = virt_to_head_page(ptr);
72778 +
72779 + type = "<process stack>";
72780 + if (!PageSlab(page)) {
72781 + if (object_is_on_stack(ptr, n) == -1)
72782 + goto report;
72783 + return;
72784 + }
72785 +
72786 + s = page->slab;
72787 + type = s->name;
72788 + if (!(s->flags & SLAB_USERCOPY))
72789 + goto report;
72790 +
72791 + offset = (ptr - page_address(page)) % s->size;
72792 + if (offset <= s->objsize && n <= s->objsize - offset)
72793 + return;
72794 +
72795 +report:
72796 + pax_report_usercopy(ptr, n, to, type);
72797 +#endif
72798 +
72799 +}
72800 +EXPORT_SYMBOL(check_object_size);
72801 +
72802 size_t ksize(const void *object)
72803 {
72804 struct page *page;
72805 @@ -3632,7 +3677,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
72806 int node;
72807
72808 list_add(&s->list, &slab_caches);
72809 - s->refcount = -1;
72810 + atomic_set(&s->refcount, -1);
72811
72812 for_each_node_state(node, N_NORMAL_MEMORY) {
72813 struct kmem_cache_node *n = get_node(s, node);
72814 @@ -3749,17 +3794,17 @@ void __init kmem_cache_init(void)
72815
72816 /* Caches that are not of the two-to-the-power-of size */
72817 if (KMALLOC_MIN_SIZE <= 32) {
72818 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
72819 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
72820 caches++;
72821 }
72822
72823 if (KMALLOC_MIN_SIZE <= 64) {
72824 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
72825 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
72826 caches++;
72827 }
72828
72829 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
72830 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
72831 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
72832 caches++;
72833 }
72834
72835 @@ -3827,7 +3872,7 @@ static int slab_unmergeable(struct kmem_cache *s)
72836 /*
72837 * We may have set a slab to be unmergeable during bootstrap.
72838 */
72839 - if (s->refcount < 0)
72840 + if (atomic_read(&s->refcount) < 0)
72841 return 1;
72842
72843 return 0;
72844 @@ -3886,7 +3931,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
72845 down_write(&slub_lock);
72846 s = find_mergeable(size, align, flags, name, ctor);
72847 if (s) {
72848 - s->refcount++;
72849 + atomic_inc(&s->refcount);
72850 /*
72851 * Adjust the object sizes so that we clear
72852 * the complete object on kzalloc.
72853 @@ -3895,7 +3940,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
72854 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
72855
72856 if (sysfs_slab_alias(s, name)) {
72857 - s->refcount--;
72858 + atomic_dec(&s->refcount);
72859 goto err;
72860 }
72861 up_write(&slub_lock);
72862 @@ -4023,7 +4068,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
72863 }
72864 #endif
72865
72866 -#ifdef CONFIG_SYSFS
72867 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
72868 static int count_inuse(struct page *page)
72869 {
72870 return page->inuse;
72871 @@ -4410,12 +4455,12 @@ static void resiliency_test(void)
72872 validate_slab_cache(kmalloc_caches[9]);
72873 }
72874 #else
72875 -#ifdef CONFIG_SYSFS
72876 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
72877 static void resiliency_test(void) {};
72878 #endif
72879 #endif
72880
72881 -#ifdef CONFIG_SYSFS
72882 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
72883 enum slab_stat_type {
72884 SL_ALL, /* All slabs */
72885 SL_PARTIAL, /* Only partially allocated slabs */
72886 @@ -4656,7 +4701,7 @@ SLAB_ATTR_RO(ctor);
72887
72888 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
72889 {
72890 - return sprintf(buf, "%d\n", s->refcount - 1);
72891 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
72892 }
72893 SLAB_ATTR_RO(aliases);
72894
72895 @@ -5223,6 +5268,7 @@ static char *create_unique_id(struct kmem_cache *s)
72896 return name;
72897 }
72898
72899 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
72900 static int sysfs_slab_add(struct kmem_cache *s)
72901 {
72902 int err;
72903 @@ -5285,6 +5331,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
72904 kobject_del(&s->kobj);
72905 kobject_put(&s->kobj);
72906 }
72907 +#endif
72908
72909 /*
72910 * Need to buffer aliases during bootup until sysfs becomes
72911 @@ -5298,6 +5345,7 @@ struct saved_alias {
72912
72913 static struct saved_alias *alias_list;
72914
72915 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
72916 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
72917 {
72918 struct saved_alias *al;
72919 @@ -5320,6 +5368,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
72920 alias_list = al;
72921 return 0;
72922 }
72923 +#endif
72924
72925 static int __init slab_sysfs_init(void)
72926 {
72927 diff --git a/mm/swap.c b/mm/swap.c
72928 index 55b266d..a532537 100644
72929 --- a/mm/swap.c
72930 +++ b/mm/swap.c
72931 @@ -31,6 +31,7 @@
72932 #include <linux/backing-dev.h>
72933 #include <linux/memcontrol.h>
72934 #include <linux/gfp.h>
72935 +#include <linux/hugetlb.h>
72936
72937 #include "internal.h"
72938
72939 @@ -71,6 +72,8 @@ static void __put_compound_page(struct page *page)
72940
72941 __page_cache_release(page);
72942 dtor = get_compound_page_dtor(page);
72943 + if (!PageHuge(page))
72944 + BUG_ON(dtor != free_compound_page);
72945 (*dtor)(page);
72946 }
72947
72948 diff --git a/mm/swapfile.c b/mm/swapfile.c
72949 index b1cd120..aaae885 100644
72950 --- a/mm/swapfile.c
72951 +++ b/mm/swapfile.c
72952 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
72953
72954 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
72955 /* Activity counter to indicate that a swapon or swapoff has occurred */
72956 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
72957 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
72958
72959 static inline unsigned char swap_count(unsigned char ent)
72960 {
72961 @@ -1670,7 +1670,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
72962 }
72963 filp_close(swap_file, NULL);
72964 err = 0;
72965 - atomic_inc(&proc_poll_event);
72966 + atomic_inc_unchecked(&proc_poll_event);
72967 wake_up_interruptible(&proc_poll_wait);
72968
72969 out_dput:
72970 @@ -1686,8 +1686,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
72971
72972 poll_wait(file, &proc_poll_wait, wait);
72973
72974 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
72975 - seq->poll_event = atomic_read(&proc_poll_event);
72976 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
72977 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
72978 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
72979 }
72980
72981 @@ -1785,7 +1785,7 @@ static int swaps_open(struct inode *inode, struct file *file)
72982 return ret;
72983
72984 seq = file->private_data;
72985 - seq->poll_event = atomic_read(&proc_poll_event);
72986 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
72987 return 0;
72988 }
72989
72990 @@ -2123,7 +2123,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
72991 (p->flags & SWP_DISCARDABLE) ? "D" : "");
72992
72993 mutex_unlock(&swapon_mutex);
72994 - atomic_inc(&proc_poll_event);
72995 + atomic_inc_unchecked(&proc_poll_event);
72996 wake_up_interruptible(&proc_poll_wait);
72997
72998 if (S_ISREG(inode->i_mode))
72999 diff --git a/mm/util.c b/mm/util.c
73000 index 136ac4f..5117eef 100644
73001 --- a/mm/util.c
73002 +++ b/mm/util.c
73003 @@ -114,6 +114,7 @@ EXPORT_SYMBOL(memdup_user);
73004 * allocated buffer. Use this if you don't want to free the buffer immediately
73005 * like, for example, with RCU.
73006 */
73007 +#undef __krealloc
73008 void *__krealloc(const void *p, size_t new_size, gfp_t flags)
73009 {
73010 void *ret;
73011 @@ -147,6 +148,7 @@ EXPORT_SYMBOL(__krealloc);
73012 * behaves exactly like kmalloc(). If @size is 0 and @p is not a
73013 * %NULL pointer, the object pointed to is freed.
73014 */
73015 +#undef krealloc
73016 void *krealloc(const void *p, size_t new_size, gfp_t flags)
73017 {
73018 void *ret;
73019 @@ -243,6 +245,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
73020 void arch_pick_mmap_layout(struct mm_struct *mm)
73021 {
73022 mm->mmap_base = TASK_UNMAPPED_BASE;
73023 +
73024 +#ifdef CONFIG_PAX_RANDMMAP
73025 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73026 + mm->mmap_base += mm->delta_mmap;
73027 +#endif
73028 +
73029 mm->get_unmapped_area = arch_get_unmapped_area;
73030 mm->unmap_area = arch_unmap_area;
73031 }
73032 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
73033 index 27be2f0..0aef2c2 100644
73034 --- a/mm/vmalloc.c
73035 +++ b/mm/vmalloc.c
73036 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
73037
73038 pte = pte_offset_kernel(pmd, addr);
73039 do {
73040 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
73041 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
73042 +
73043 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73044 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
73045 + BUG_ON(!pte_exec(*pte));
73046 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
73047 + continue;
73048 + }
73049 +#endif
73050 +
73051 + {
73052 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
73053 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
73054 + }
73055 } while (pte++, addr += PAGE_SIZE, addr != end);
73056 }
73057
73058 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
73059 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
73060 {
73061 pte_t *pte;
73062 + int ret = -ENOMEM;
73063
73064 /*
73065 * nr is a running index into the array which helps higher level
73066 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
73067 pte = pte_alloc_kernel(pmd, addr);
73068 if (!pte)
73069 return -ENOMEM;
73070 +
73071 + pax_open_kernel();
73072 do {
73073 struct page *page = pages[*nr];
73074
73075 - if (WARN_ON(!pte_none(*pte)))
73076 - return -EBUSY;
73077 - if (WARN_ON(!page))
73078 - return -ENOMEM;
73079 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73080 + if (pgprot_val(prot) & _PAGE_NX)
73081 +#endif
73082 +
73083 + if (WARN_ON(!pte_none(*pte))) {
73084 + ret = -EBUSY;
73085 + goto out;
73086 + }
73087 + if (WARN_ON(!page)) {
73088 + ret = -ENOMEM;
73089 + goto out;
73090 + }
73091 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
73092 (*nr)++;
73093 } while (pte++, addr += PAGE_SIZE, addr != end);
73094 - return 0;
73095 + ret = 0;
73096 +out:
73097 + pax_close_kernel();
73098 + return ret;
73099 }
73100
73101 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
73102 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
73103 * and fall back on vmalloc() if that fails. Others
73104 * just put it in the vmalloc space.
73105 */
73106 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
73107 +#ifdef CONFIG_MODULES
73108 +#ifdef MODULES_VADDR
73109 unsigned long addr = (unsigned long)x;
73110 if (addr >= MODULES_VADDR && addr < MODULES_END)
73111 return 1;
73112 #endif
73113 +
73114 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73115 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
73116 + return 1;
73117 +#endif
73118 +
73119 +#endif
73120 +
73121 return is_vmalloc_addr(x);
73122 }
73123
73124 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
73125
73126 if (!pgd_none(*pgd)) {
73127 pud_t *pud = pud_offset(pgd, addr);
73128 +#ifdef CONFIG_X86
73129 + if (!pud_large(*pud))
73130 +#endif
73131 if (!pud_none(*pud)) {
73132 pmd_t *pmd = pmd_offset(pud, addr);
73133 +#ifdef CONFIG_X86
73134 + if (!pmd_large(*pmd))
73135 +#endif
73136 if (!pmd_none(*pmd)) {
73137 pte_t *ptep, pte;
73138
73139 @@ -1294,6 +1334,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
73140 struct vm_struct *area;
73141
73142 BUG_ON(in_interrupt());
73143 +
73144 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73145 + if (flags & VM_KERNEXEC) {
73146 + if (start != VMALLOC_START || end != VMALLOC_END)
73147 + return NULL;
73148 + start = (unsigned long)MODULES_EXEC_VADDR;
73149 + end = (unsigned long)MODULES_EXEC_END;
73150 + }
73151 +#endif
73152 +
73153 if (flags & VM_IOREMAP) {
73154 int bit = fls(size);
73155
73156 @@ -1526,6 +1576,11 @@ void *vmap(struct page **pages, unsigned int count,
73157 if (count > totalram_pages)
73158 return NULL;
73159
73160 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73161 + if (!(pgprot_val(prot) & _PAGE_NX))
73162 + flags |= VM_KERNEXEC;
73163 +#endif
73164 +
73165 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
73166 __builtin_return_address(0));
73167 if (!area)
73168 @@ -1627,6 +1682,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
73169 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
73170 goto fail;
73171
73172 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73173 + if (!(pgprot_val(prot) & _PAGE_NX))
73174 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
73175 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
73176 + else
73177 +#endif
73178 +
73179 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
73180 start, end, node, gfp_mask, caller);
73181 if (!area)
73182 @@ -1679,6 +1741,7 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
73183 gfp_mask, prot, node, caller);
73184 }
73185
73186 +#undef __vmalloc
73187 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
73188 {
73189 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
73190 @@ -1702,6 +1765,7 @@ static inline void *__vmalloc_node_flags(unsigned long size,
73191 * For tight control over page level allocator and protection flags
73192 * use __vmalloc() instead.
73193 */
73194 +#undef vmalloc
73195 void *vmalloc(unsigned long size)
73196 {
73197 return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
73198 @@ -1718,6 +1782,7 @@ EXPORT_SYMBOL(vmalloc);
73199 * For tight control over page level allocator and protection flags
73200 * use __vmalloc() instead.
73201 */
73202 +#undef vzalloc
73203 void *vzalloc(unsigned long size)
73204 {
73205 return __vmalloc_node_flags(size, -1,
73206 @@ -1732,6 +1797,7 @@ EXPORT_SYMBOL(vzalloc);
73207 * The resulting memory area is zeroed so it can be mapped to userspace
73208 * without leaking data.
73209 */
73210 +#undef vmalloc_user
73211 void *vmalloc_user(unsigned long size)
73212 {
73213 struct vm_struct *area;
73214 @@ -1759,6 +1825,7 @@ EXPORT_SYMBOL(vmalloc_user);
73215 * For tight control over page level allocator and protection flags
73216 * use __vmalloc() instead.
73217 */
73218 +#undef vmalloc_node
73219 void *vmalloc_node(unsigned long size, int node)
73220 {
73221 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
73222 @@ -1778,6 +1845,7 @@ EXPORT_SYMBOL(vmalloc_node);
73223 * For tight control over page level allocator and protection flags
73224 * use __vmalloc_node() instead.
73225 */
73226 +#undef vzalloc_node
73227 void *vzalloc_node(unsigned long size, int node)
73228 {
73229 return __vmalloc_node_flags(size, node,
73230 @@ -1800,10 +1868,10 @@ EXPORT_SYMBOL(vzalloc_node);
73231 * For tight control over page level allocator and protection flags
73232 * use __vmalloc() instead.
73233 */
73234 -
73235 +#undef vmalloc_exec
73236 void *vmalloc_exec(unsigned long size)
73237 {
73238 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
73239 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
73240 -1, __builtin_return_address(0));
73241 }
73242
73243 @@ -1822,6 +1890,7 @@ void *vmalloc_exec(unsigned long size)
73244 * Allocate enough 32bit PA addressable pages to cover @size from the
73245 * page level allocator and map them into contiguous kernel virtual space.
73246 */
73247 +#undef vmalloc_32
73248 void *vmalloc_32(unsigned long size)
73249 {
73250 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
73251 @@ -1836,6 +1905,7 @@ EXPORT_SYMBOL(vmalloc_32);
73252 * The resulting memory area is 32bit addressable and zeroed so it can be
73253 * mapped to userspace without leaking data.
73254 */
73255 +#undef vmalloc_32_user
73256 void *vmalloc_32_user(unsigned long size)
73257 {
73258 struct vm_struct *area;
73259 @@ -2098,6 +2168,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
73260 unsigned long uaddr = vma->vm_start;
73261 unsigned long usize = vma->vm_end - vma->vm_start;
73262
73263 + BUG_ON(vma->vm_mirror);
73264 +
73265 if ((PAGE_SIZE-1) & (unsigned long)addr)
73266 return -EINVAL;
73267
73268 diff --git a/mm/vmstat.c b/mm/vmstat.c
73269 index 8fd603b..cf0d930 100644
73270 --- a/mm/vmstat.c
73271 +++ b/mm/vmstat.c
73272 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
73273 *
73274 * vm_stat contains the global counters
73275 */
73276 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
73277 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
73278 EXPORT_SYMBOL(vm_stat);
73279
73280 #ifdef CONFIG_SMP
73281 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
73282 v = p->vm_stat_diff[i];
73283 p->vm_stat_diff[i] = 0;
73284 local_irq_restore(flags);
73285 - atomic_long_add(v, &zone->vm_stat[i]);
73286 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
73287 global_diff[i] += v;
73288 #ifdef CONFIG_NUMA
73289 /* 3 seconds idle till flush */
73290 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
73291
73292 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
73293 if (global_diff[i])
73294 - atomic_long_add(global_diff[i], &vm_stat[i]);
73295 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
73296 }
73297
73298 #endif
73299 @@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
73300 start_cpu_timer(cpu);
73301 #endif
73302 #ifdef CONFIG_PROC_FS
73303 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
73304 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
73305 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
73306 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
73307 + {
73308 + mode_t gr_mode = S_IRUGO;
73309 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
73310 + gr_mode = S_IRUSR;
73311 +#endif
73312 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
73313 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
73314 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
73315 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
73316 +#else
73317 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
73318 +#endif
73319 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
73320 + }
73321 #endif
73322 return 0;
73323 }
73324 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
73325 index 5471628..cef8398 100644
73326 --- a/net/8021q/vlan.c
73327 +++ b/net/8021q/vlan.c
73328 @@ -588,8 +588,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
73329 err = -EPERM;
73330 if (!capable(CAP_NET_ADMIN))
73331 break;
73332 - if ((args.u.name_type >= 0) &&
73333 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
73334 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
73335 struct vlan_net *vn;
73336
73337 vn = net_generic(net, vlan_net_id);
73338 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
73339 index fdfdb57..38d368c 100644
73340 --- a/net/9p/trans_fd.c
73341 +++ b/net/9p/trans_fd.c
73342 @@ -423,7 +423,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
73343 oldfs = get_fs();
73344 set_fs(get_ds());
73345 /* The cast to a user pointer is valid due to the set_fs() */
73346 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
73347 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
73348 set_fs(oldfs);
73349
73350 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
73351 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
73352 index f41f026..fe76ea8 100644
73353 --- a/net/atm/atm_misc.c
73354 +++ b/net/atm/atm_misc.c
73355 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
73356 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
73357 return 1;
73358 atm_return(vcc, truesize);
73359 - atomic_inc(&vcc->stats->rx_drop);
73360 + atomic_inc_unchecked(&vcc->stats->rx_drop);
73361 return 0;
73362 }
73363 EXPORT_SYMBOL(atm_charge);
73364 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
73365 }
73366 }
73367 atm_return(vcc, guess);
73368 - atomic_inc(&vcc->stats->rx_drop);
73369 + atomic_inc_unchecked(&vcc->stats->rx_drop);
73370 return NULL;
73371 }
73372 EXPORT_SYMBOL(atm_alloc_charge);
73373 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
73374
73375 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
73376 {
73377 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
73378 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
73379 __SONET_ITEMS
73380 #undef __HANDLE_ITEM
73381 }
73382 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
73383
73384 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
73385 {
73386 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
73387 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
73388 __SONET_ITEMS
73389 #undef __HANDLE_ITEM
73390 }
73391 diff --git a/net/atm/lec.h b/net/atm/lec.h
73392 index dfc0719..47c5322 100644
73393 --- a/net/atm/lec.h
73394 +++ b/net/atm/lec.h
73395 @@ -48,7 +48,7 @@ struct lane2_ops {
73396 const u8 *tlvs, u32 sizeoftlvs);
73397 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
73398 const u8 *tlvs, u32 sizeoftlvs);
73399 -};
73400 +} __no_const;
73401
73402 /*
73403 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
73404 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
73405 index 0919a88..a23d54e 100644
73406 --- a/net/atm/mpc.h
73407 +++ b/net/atm/mpc.h
73408 @@ -33,7 +33,7 @@ struct mpoa_client {
73409 struct mpc_parameters parameters; /* parameters for this client */
73410
73411 const struct net_device_ops *old_ops;
73412 - struct net_device_ops new_ops;
73413 + net_device_ops_no_const new_ops;
73414 };
73415
73416
73417 diff --git a/net/atm/proc.c b/net/atm/proc.c
73418 index 0d020de..011c7bb 100644
73419 --- a/net/atm/proc.c
73420 +++ b/net/atm/proc.c
73421 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
73422 const struct k_atm_aal_stats *stats)
73423 {
73424 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
73425 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
73426 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
73427 - atomic_read(&stats->rx_drop));
73428 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
73429 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
73430 + atomic_read_unchecked(&stats->rx_drop));
73431 }
73432
73433 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
73434 diff --git a/net/atm/resources.c b/net/atm/resources.c
73435 index 23f45ce..c748f1a 100644
73436 --- a/net/atm/resources.c
73437 +++ b/net/atm/resources.c
73438 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
73439 static void copy_aal_stats(struct k_atm_aal_stats *from,
73440 struct atm_aal_stats *to)
73441 {
73442 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
73443 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
73444 __AAL_STAT_ITEMS
73445 #undef __HANDLE_ITEM
73446 }
73447 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
73448 static void subtract_aal_stats(struct k_atm_aal_stats *from,
73449 struct atm_aal_stats *to)
73450 {
73451 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
73452 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
73453 __AAL_STAT_ITEMS
73454 #undef __HANDLE_ITEM
73455 }
73456 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
73457 index 3512e25..2b33401 100644
73458 --- a/net/batman-adv/bat_iv_ogm.c
73459 +++ b/net/batman-adv/bat_iv_ogm.c
73460 @@ -541,7 +541,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
73461
73462 /* change sequence number to network order */
73463 batman_ogm_packet->seqno =
73464 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
73465 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
73466
73467 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
73468 batman_ogm_packet->tt_crc = htons((uint16_t)
73469 @@ -561,7 +561,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
73470 else
73471 batman_ogm_packet->gw_flags = NO_FLAGS;
73472
73473 - atomic_inc(&hard_iface->seqno);
73474 + atomic_inc_unchecked(&hard_iface->seqno);
73475
73476 slide_own_bcast_window(hard_iface);
73477 bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
73478 @@ -922,7 +922,7 @@ static void bat_ogm_process(const struct ethhdr *ethhdr,
73479 return;
73480
73481 /* could be changed by schedule_own_packet() */
73482 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
73483 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
73484
73485 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
73486
73487 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
73488 index 7704df4..beb4e16 100644
73489 --- a/net/batman-adv/hard-interface.c
73490 +++ b/net/batman-adv/hard-interface.c
73491 @@ -326,8 +326,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
73492 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
73493 dev_add_pack(&hard_iface->batman_adv_ptype);
73494
73495 - atomic_set(&hard_iface->seqno, 1);
73496 - atomic_set(&hard_iface->frag_seqno, 1);
73497 + atomic_set_unchecked(&hard_iface->seqno, 1);
73498 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
73499 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
73500 hard_iface->net_dev->name);
73501
73502 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
73503 index f9cc957..efd9dae 100644
73504 --- a/net/batman-adv/soft-interface.c
73505 +++ b/net/batman-adv/soft-interface.c
73506 @@ -634,7 +634,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
73507
73508 /* set broadcast sequence number */
73509 bcast_packet->seqno =
73510 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
73511 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
73512
73513 add_bcast_packet_to_list(bat_priv, skb, 1);
73514
73515 @@ -828,7 +828,7 @@ struct net_device *softif_create(const char *name)
73516 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
73517
73518 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
73519 - atomic_set(&bat_priv->bcast_seqno, 1);
73520 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
73521 atomic_set(&bat_priv->ttvn, 0);
73522 atomic_set(&bat_priv->tt_local_changes, 0);
73523 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
73524 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
73525 index ab8d0fe..ceba3fd 100644
73526 --- a/net/batman-adv/types.h
73527 +++ b/net/batman-adv/types.h
73528 @@ -38,8 +38,8 @@ struct hard_iface {
73529 int16_t if_num;
73530 char if_status;
73531 struct net_device *net_dev;
73532 - atomic_t seqno;
73533 - atomic_t frag_seqno;
73534 + atomic_unchecked_t seqno;
73535 + atomic_unchecked_t frag_seqno;
73536 unsigned char *packet_buff;
73537 int packet_len;
73538 struct kobject *hardif_obj;
73539 @@ -154,7 +154,7 @@ struct bat_priv {
73540 atomic_t orig_interval; /* uint */
73541 atomic_t hop_penalty; /* uint */
73542 atomic_t log_level; /* uint */
73543 - atomic_t bcast_seqno;
73544 + atomic_unchecked_t bcast_seqno;
73545 atomic_t bcast_queue_left;
73546 atomic_t batman_queue_left;
73547 atomic_t ttvn; /* translation table version number */
73548 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
73549 index 07d1c1d..7e9bea9 100644
73550 --- a/net/batman-adv/unicast.c
73551 +++ b/net/batman-adv/unicast.c
73552 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
73553 frag1->flags = UNI_FRAG_HEAD | large_tail;
73554 frag2->flags = large_tail;
73555
73556 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
73557 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
73558 frag1->seqno = htons(seqno - 1);
73559 frag2->seqno = htons(seqno);
73560
73561 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
73562 index c1c597e..05ebb40 100644
73563 --- a/net/bluetooth/hci_conn.c
73564 +++ b/net/bluetooth/hci_conn.c
73565 @@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
73566 memset(&cp, 0, sizeof(cp));
73567
73568 cp.handle = cpu_to_le16(conn->handle);
73569 - memcpy(cp.ltk, ltk, sizeof(ltk));
73570 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
73571
73572 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
73573 }
73574 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
73575 index 17b5b1c..826d872 100644
73576 --- a/net/bluetooth/l2cap_core.c
73577 +++ b/net/bluetooth/l2cap_core.c
73578 @@ -2176,8 +2176,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
73579 break;
73580
73581 case L2CAP_CONF_RFC:
73582 - if (olen == sizeof(rfc))
73583 - memcpy(&rfc, (void *)val, olen);
73584 + if (olen != sizeof(rfc))
73585 + break;
73586 +
73587 + memcpy(&rfc, (void *)val, olen);
73588
73589 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
73590 rfc.mode != chan->mode)
73591 @@ -2265,8 +2267,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
73592
73593 switch (type) {
73594 case L2CAP_CONF_RFC:
73595 - if (olen == sizeof(rfc))
73596 - memcpy(&rfc, (void *)val, olen);
73597 + if (olen != sizeof(rfc))
73598 + break;
73599 +
73600 + memcpy(&rfc, (void *)val, olen);
73601 goto done;
73602 }
73603 }
73604 diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
73605 index a5f4e57..910ee6d 100644
73606 --- a/net/bridge/br_multicast.c
73607 +++ b/net/bridge/br_multicast.c
73608 @@ -1485,7 +1485,7 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br,
73609 nexthdr = ip6h->nexthdr;
73610 offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr);
73611
73612 - if (offset < 0 || nexthdr != IPPROTO_ICMPV6)
73613 + if (nexthdr != IPPROTO_ICMPV6)
73614 return 0;
73615
73616 /* Okay, we found ICMPv6 header */
73617 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
73618 index 5864cc4..121f3a3 100644
73619 --- a/net/bridge/netfilter/ebtables.c
73620 +++ b/net/bridge/netfilter/ebtables.c
73621 @@ -1513,7 +1513,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
73622 tmp.valid_hooks = t->table->valid_hooks;
73623 }
73624 mutex_unlock(&ebt_mutex);
73625 - if (copy_to_user(user, &tmp, *len) != 0){
73626 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
73627 BUGPRINT("c2u Didn't work\n");
73628 ret = -EFAULT;
73629 break;
73630 diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
73631 index a986280..13444a1 100644
73632 --- a/net/caif/caif_socket.c
73633 +++ b/net/caif/caif_socket.c
73634 @@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
73635 #ifdef CONFIG_DEBUG_FS
73636 struct debug_fs_counter {
73637 atomic_t caif_nr_socks;
73638 - atomic_t caif_sock_create;
73639 - atomic_t num_connect_req;
73640 - atomic_t num_connect_resp;
73641 - atomic_t num_connect_fail_resp;
73642 - atomic_t num_disconnect;
73643 - atomic_t num_remote_shutdown_ind;
73644 - atomic_t num_tx_flow_off_ind;
73645 - atomic_t num_tx_flow_on_ind;
73646 - atomic_t num_rx_flow_off;
73647 - atomic_t num_rx_flow_on;
73648 + atomic_unchecked_t caif_sock_create;
73649 + atomic_unchecked_t num_connect_req;
73650 + atomic_unchecked_t num_connect_resp;
73651 + atomic_unchecked_t num_connect_fail_resp;
73652 + atomic_unchecked_t num_disconnect;
73653 + atomic_unchecked_t num_remote_shutdown_ind;
73654 + atomic_unchecked_t num_tx_flow_off_ind;
73655 + atomic_unchecked_t num_tx_flow_on_ind;
73656 + atomic_unchecked_t num_rx_flow_off;
73657 + atomic_unchecked_t num_rx_flow_on;
73658 };
73659 static struct debug_fs_counter cnt;
73660 #define dbfs_atomic_inc(v) atomic_inc_return(v)
73661 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
73662 #define dbfs_atomic_dec(v) atomic_dec_return(v)
73663 #else
73664 #define dbfs_atomic_inc(v) 0
73665 @@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
73666 atomic_read(&cf_sk->sk.sk_rmem_alloc),
73667 sk_rcvbuf_lowwater(cf_sk));
73668 set_rx_flow_off(cf_sk);
73669 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
73670 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
73671 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
73672 }
73673
73674 @@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
73675 set_rx_flow_off(cf_sk);
73676 if (net_ratelimit())
73677 pr_debug("sending flow OFF due to rmem_schedule\n");
73678 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
73679 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
73680 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
73681 }
73682 skb->dev = NULL;
73683 @@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
73684 switch (flow) {
73685 case CAIF_CTRLCMD_FLOW_ON_IND:
73686 /* OK from modem to start sending again */
73687 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
73688 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
73689 set_tx_flow_on(cf_sk);
73690 cf_sk->sk.sk_state_change(&cf_sk->sk);
73691 break;
73692
73693 case CAIF_CTRLCMD_FLOW_OFF_IND:
73694 /* Modem asks us to shut up */
73695 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
73696 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
73697 set_tx_flow_off(cf_sk);
73698 cf_sk->sk.sk_state_change(&cf_sk->sk);
73699 break;
73700 @@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
73701 /* We're now connected */
73702 caif_client_register_refcnt(&cf_sk->layer,
73703 cfsk_hold, cfsk_put);
73704 - dbfs_atomic_inc(&cnt.num_connect_resp);
73705 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
73706 cf_sk->sk.sk_state = CAIF_CONNECTED;
73707 set_tx_flow_on(cf_sk);
73708 cf_sk->sk.sk_state_change(&cf_sk->sk);
73709 @@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
73710
73711 case CAIF_CTRLCMD_INIT_FAIL_RSP:
73712 /* Connect request failed */
73713 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
73714 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
73715 cf_sk->sk.sk_err = ECONNREFUSED;
73716 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
73717 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
73718 @@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
73719
73720 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
73721 /* Modem has closed this connection, or device is down. */
73722 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
73723 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
73724 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
73725 cf_sk->sk.sk_err = ECONNRESET;
73726 set_rx_flow_on(cf_sk);
73727 @@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
73728 return;
73729
73730 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
73731 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
73732 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
73733 set_rx_flow_on(cf_sk);
73734 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
73735 }
73736 @@ -854,7 +855,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
73737 /*ifindex = id of the interface.*/
73738 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
73739
73740 - dbfs_atomic_inc(&cnt.num_connect_req);
73741 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
73742 cf_sk->layer.receive = caif_sktrecv_cb;
73743
73744 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
73745 @@ -943,7 +944,7 @@ static int caif_release(struct socket *sock)
73746 spin_unlock_bh(&sk->sk_receive_queue.lock);
73747 sock->sk = NULL;
73748
73749 - dbfs_atomic_inc(&cnt.num_disconnect);
73750 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
73751
73752 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
73753 if (cf_sk->debugfs_socket_dir != NULL)
73754 @@ -1122,7 +1123,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
73755 cf_sk->conn_req.protocol = protocol;
73756 /* Increase the number of sockets created. */
73757 dbfs_atomic_inc(&cnt.caif_nr_socks);
73758 - num = dbfs_atomic_inc(&cnt.caif_sock_create);
73759 + num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
73760 #ifdef CONFIG_DEBUG_FS
73761 if (!IS_ERR(debugfsdir)) {
73762
73763 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
73764 index 5cf5222..6f704ad 100644
73765 --- a/net/caif/cfctrl.c
73766 +++ b/net/caif/cfctrl.c
73767 @@ -9,6 +9,7 @@
73768 #include <linux/stddef.h>
73769 #include <linux/spinlock.h>
73770 #include <linux/slab.h>
73771 +#include <linux/sched.h>
73772 #include <net/caif/caif_layer.h>
73773 #include <net/caif/cfpkt.h>
73774 #include <net/caif/cfctrl.h>
73775 @@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
73776 memset(&dev_info, 0, sizeof(dev_info));
73777 dev_info.id = 0xff;
73778 cfsrvl_init(&this->serv, 0, &dev_info, false);
73779 - atomic_set(&this->req_seq_no, 1);
73780 - atomic_set(&this->rsp_seq_no, 1);
73781 + atomic_set_unchecked(&this->req_seq_no, 1);
73782 + atomic_set_unchecked(&this->rsp_seq_no, 1);
73783 this->serv.layer.receive = cfctrl_recv;
73784 sprintf(this->serv.layer.name, "ctrl");
73785 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
73786 @@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
73787 struct cfctrl_request_info *req)
73788 {
73789 spin_lock_bh(&ctrl->info_list_lock);
73790 - atomic_inc(&ctrl->req_seq_no);
73791 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
73792 + atomic_inc_unchecked(&ctrl->req_seq_no);
73793 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
73794 list_add_tail(&req->list, &ctrl->list);
73795 spin_unlock_bh(&ctrl->info_list_lock);
73796 }
73797 @@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
73798 if (p != first)
73799 pr_warn("Requests are not received in order\n");
73800
73801 - atomic_set(&ctrl->rsp_seq_no,
73802 + atomic_set_unchecked(&ctrl->rsp_seq_no,
73803 p->sequence_no);
73804 list_del(&p->list);
73805 goto out;
73806 diff --git a/net/can/gw.c b/net/can/gw.c
73807 index 3d79b12..8de85fa 100644
73808 --- a/net/can/gw.c
73809 +++ b/net/can/gw.c
73810 @@ -96,7 +96,7 @@ struct cf_mod {
73811 struct {
73812 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
73813 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
73814 - } csumfunc;
73815 + } __no_const csumfunc;
73816 };
73817
73818
73819 diff --git a/net/compat.c b/net/compat.c
73820 index 6def90e..c6992fa 100644
73821 --- a/net/compat.c
73822 +++ b/net/compat.c
73823 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
73824 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
73825 __get_user(kmsg->msg_flags, &umsg->msg_flags))
73826 return -EFAULT;
73827 - kmsg->msg_name = compat_ptr(tmp1);
73828 - kmsg->msg_iov = compat_ptr(tmp2);
73829 - kmsg->msg_control = compat_ptr(tmp3);
73830 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
73831 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
73832 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
73833 return 0;
73834 }
73835
73836 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
73837
73838 if (kern_msg->msg_namelen) {
73839 if (mode == VERIFY_READ) {
73840 - int err = move_addr_to_kernel(kern_msg->msg_name,
73841 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
73842 kern_msg->msg_namelen,
73843 kern_address);
73844 if (err < 0)
73845 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
73846 kern_msg->msg_name = NULL;
73847
73848 tot_len = iov_from_user_compat_to_kern(kern_iov,
73849 - (struct compat_iovec __user *)kern_msg->msg_iov,
73850 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
73851 kern_msg->msg_iovlen);
73852 if (tot_len >= 0)
73853 kern_msg->msg_iov = kern_iov;
73854 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
73855
73856 #define CMSG_COMPAT_FIRSTHDR(msg) \
73857 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
73858 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
73859 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
73860 (struct compat_cmsghdr __user *)NULL)
73861
73862 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
73863 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
73864 (ucmlen) <= (unsigned long) \
73865 ((mhdr)->msg_controllen - \
73866 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
73867 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
73868
73869 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
73870 struct compat_cmsghdr __user *cmsg, int cmsg_len)
73871 {
73872 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
73873 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
73874 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
73875 msg->msg_controllen)
73876 return NULL;
73877 return (struct compat_cmsghdr __user *)ptr;
73878 @@ -221,7 +221,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
73879 {
73880 struct compat_timeval ctv;
73881 struct compat_timespec cts[3];
73882 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
73883 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
73884 struct compat_cmsghdr cmhdr;
73885 int cmlen;
73886
73887 @@ -273,7 +273,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
73888
73889 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
73890 {
73891 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
73892 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
73893 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
73894 int fdnum = scm->fp->count;
73895 struct file **fp = scm->fp->fp;
73896 @@ -370,7 +370,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
73897 return -EFAULT;
73898 old_fs = get_fs();
73899 set_fs(KERNEL_DS);
73900 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
73901 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
73902 set_fs(old_fs);
73903
73904 return err;
73905 @@ -431,7 +431,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
73906 len = sizeof(ktime);
73907 old_fs = get_fs();
73908 set_fs(KERNEL_DS);
73909 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
73910 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
73911 set_fs(old_fs);
73912
73913 if (!err) {
73914 @@ -566,7 +566,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
73915 case MCAST_JOIN_GROUP:
73916 case MCAST_LEAVE_GROUP:
73917 {
73918 - struct compat_group_req __user *gr32 = (void *)optval;
73919 + struct compat_group_req __user *gr32 = (void __user *)optval;
73920 struct group_req __user *kgr =
73921 compat_alloc_user_space(sizeof(struct group_req));
73922 u32 interface;
73923 @@ -587,7 +587,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
73924 case MCAST_BLOCK_SOURCE:
73925 case MCAST_UNBLOCK_SOURCE:
73926 {
73927 - struct compat_group_source_req __user *gsr32 = (void *)optval;
73928 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
73929 struct group_source_req __user *kgsr = compat_alloc_user_space(
73930 sizeof(struct group_source_req));
73931 u32 interface;
73932 @@ -608,7 +608,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
73933 }
73934 case MCAST_MSFILTER:
73935 {
73936 - struct compat_group_filter __user *gf32 = (void *)optval;
73937 + struct compat_group_filter __user *gf32 = (void __user *)optval;
73938 struct group_filter __user *kgf;
73939 u32 interface, fmode, numsrc;
73940
73941 @@ -646,7 +646,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
73942 char __user *optval, int __user *optlen,
73943 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
73944 {
73945 - struct compat_group_filter __user *gf32 = (void *)optval;
73946 + struct compat_group_filter __user *gf32 = (void __user *)optval;
73947 struct group_filter __user *kgf;
73948 int __user *koptlen;
73949 u32 interface, fmode, numsrc;
73950 diff --git a/net/core/datagram.c b/net/core/datagram.c
73951 index 68bbf9f..5ef0d12 100644
73952 --- a/net/core/datagram.c
73953 +++ b/net/core/datagram.c
73954 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
73955 }
73956
73957 kfree_skb(skb);
73958 - atomic_inc(&sk->sk_drops);
73959 + atomic_inc_unchecked(&sk->sk_drops);
73960 sk_mem_reclaim_partial(sk);
73961
73962 return err;
73963 diff --git a/net/core/dev.c b/net/core/dev.c
73964 index c56cacf..b28e35f 100644
73965 --- a/net/core/dev.c
73966 +++ b/net/core/dev.c
73967 @@ -1139,10 +1139,14 @@ void dev_load(struct net *net, const char *name)
73968 if (no_module && capable(CAP_NET_ADMIN))
73969 no_module = request_module("netdev-%s", name);
73970 if (no_module && capable(CAP_SYS_MODULE)) {
73971 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
73972 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
73973 +#else
73974 if (!request_module("%s", name))
73975 pr_err("Loading kernel module for a network device "
73976 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
73977 "instead\n", name);
73978 +#endif
73979 }
73980 }
73981 EXPORT_SYMBOL(dev_load);
73982 @@ -1573,7 +1577,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
73983 {
73984 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
73985 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
73986 - atomic_long_inc(&dev->rx_dropped);
73987 + atomic_long_inc_unchecked(&dev->rx_dropped);
73988 kfree_skb(skb);
73989 return NET_RX_DROP;
73990 }
73991 @@ -1583,7 +1587,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
73992 nf_reset(skb);
73993
73994 if (unlikely(!is_skb_forwardable(dev, skb))) {
73995 - atomic_long_inc(&dev->rx_dropped);
73996 + atomic_long_inc_unchecked(&dev->rx_dropped);
73997 kfree_skb(skb);
73998 return NET_RX_DROP;
73999 }
74000 @@ -2036,7 +2040,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
74001
74002 struct dev_gso_cb {
74003 void (*destructor)(struct sk_buff *skb);
74004 -};
74005 +} __no_const;
74006
74007 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
74008
74009 @@ -2970,7 +2974,7 @@ enqueue:
74010
74011 local_irq_restore(flags);
74012
74013 - atomic_long_inc(&skb->dev->rx_dropped);
74014 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
74015 kfree_skb(skb);
74016 return NET_RX_DROP;
74017 }
74018 @@ -3044,7 +3048,7 @@ int netif_rx_ni(struct sk_buff *skb)
74019 }
74020 EXPORT_SYMBOL(netif_rx_ni);
74021
74022 -static void net_tx_action(struct softirq_action *h)
74023 +static void net_tx_action(void)
74024 {
74025 struct softnet_data *sd = &__get_cpu_var(softnet_data);
74026
74027 @@ -3333,7 +3337,7 @@ ncls:
74028 if (pt_prev) {
74029 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
74030 } else {
74031 - atomic_long_inc(&skb->dev->rx_dropped);
74032 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
74033 kfree_skb(skb);
74034 /* Jamal, now you will not able to escape explaining
74035 * me how you were going to use this. :-)
74036 @@ -3897,7 +3901,7 @@ void netif_napi_del(struct napi_struct *napi)
74037 }
74038 EXPORT_SYMBOL(netif_napi_del);
74039
74040 -static void net_rx_action(struct softirq_action *h)
74041 +static void net_rx_action(void)
74042 {
74043 struct softnet_data *sd = &__get_cpu_var(softnet_data);
74044 unsigned long time_limit = jiffies + 2;
74045 @@ -5955,7 +5959,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
74046 } else {
74047 netdev_stats_to_stats64(storage, &dev->stats);
74048 }
74049 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
74050 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
74051 return storage;
74052 }
74053 EXPORT_SYMBOL(dev_get_stats);
74054 diff --git a/net/core/flow.c b/net/core/flow.c
74055 index e318c7e..168b1d0 100644
74056 --- a/net/core/flow.c
74057 +++ b/net/core/flow.c
74058 @@ -61,7 +61,7 @@ struct flow_cache {
74059 struct timer_list rnd_timer;
74060 };
74061
74062 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
74063 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
74064 EXPORT_SYMBOL(flow_cache_genid);
74065 static struct flow_cache flow_cache_global;
74066 static struct kmem_cache *flow_cachep __read_mostly;
74067 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
74068
74069 static int flow_entry_valid(struct flow_cache_entry *fle)
74070 {
74071 - if (atomic_read(&flow_cache_genid) != fle->genid)
74072 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
74073 return 0;
74074 if (fle->object && !fle->object->ops->check(fle->object))
74075 return 0;
74076 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
74077 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
74078 fcp->hash_count++;
74079 }
74080 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
74081 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
74082 flo = fle->object;
74083 if (!flo)
74084 goto ret_object;
74085 @@ -280,7 +280,7 @@ nocache:
74086 }
74087 flo = resolver(net, key, family, dir, flo, ctx);
74088 if (fle) {
74089 - fle->genid = atomic_read(&flow_cache_genid);
74090 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
74091 if (!IS_ERR(flo))
74092 fle->object = flo;
74093 else
74094 diff --git a/net/core/iovec.c b/net/core/iovec.c
74095 index c40f27e..7f49254 100644
74096 --- a/net/core/iovec.c
74097 +++ b/net/core/iovec.c
74098 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
74099 if (m->msg_namelen) {
74100 if (mode == VERIFY_READ) {
74101 void __user *namep;
74102 - namep = (void __user __force *) m->msg_name;
74103 + namep = (void __force_user *) m->msg_name;
74104 err = move_addr_to_kernel(namep, m->msg_namelen,
74105 address);
74106 if (err < 0)
74107 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
74108 }
74109
74110 size = m->msg_iovlen * sizeof(struct iovec);
74111 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
74112 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
74113 return -EFAULT;
74114
74115 m->msg_iov = iov;
74116 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
74117 index 9083e82..1673203 100644
74118 --- a/net/core/rtnetlink.c
74119 +++ b/net/core/rtnetlink.c
74120 @@ -57,7 +57,7 @@ struct rtnl_link {
74121 rtnl_doit_func doit;
74122 rtnl_dumpit_func dumpit;
74123 rtnl_calcit_func calcit;
74124 -};
74125 +} __no_const;
74126
74127 static DEFINE_MUTEX(rtnl_mutex);
74128 static u16 min_ifinfo_dump_size;
74129 diff --git a/net/core/scm.c b/net/core/scm.c
74130 index ff52ad0..aff1c0f 100644
74131 --- a/net/core/scm.c
74132 +++ b/net/core/scm.c
74133 @@ -220,7 +220,7 @@ EXPORT_SYMBOL(__scm_send);
74134 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
74135 {
74136 struct cmsghdr __user *cm
74137 - = (__force struct cmsghdr __user *)msg->msg_control;
74138 + = (struct cmsghdr __force_user *)msg->msg_control;
74139 struct cmsghdr cmhdr;
74140 int cmlen = CMSG_LEN(len);
74141 int err;
74142 @@ -243,7 +243,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
74143 err = -EFAULT;
74144 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
74145 goto out;
74146 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
74147 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
74148 goto out;
74149 cmlen = CMSG_SPACE(len);
74150 if (msg->msg_controllen < cmlen)
74151 @@ -259,7 +259,7 @@ EXPORT_SYMBOL(put_cmsg);
74152 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
74153 {
74154 struct cmsghdr __user *cm
74155 - = (__force struct cmsghdr __user*)msg->msg_control;
74156 + = (struct cmsghdr __force_user *)msg->msg_control;
74157
74158 int fdmax = 0;
74159 int fdnum = scm->fp->count;
74160 @@ -279,7 +279,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
74161 if (fdnum < fdmax)
74162 fdmax = fdnum;
74163
74164 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
74165 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
74166 i++, cmfptr++)
74167 {
74168 int new_fd;
74169 diff --git a/net/core/sock.c b/net/core/sock.c
74170 index b23f174..b9a0d26 100644
74171 --- a/net/core/sock.c
74172 +++ b/net/core/sock.c
74173 @@ -289,7 +289,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74174 struct sk_buff_head *list = &sk->sk_receive_queue;
74175
74176 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
74177 - atomic_inc(&sk->sk_drops);
74178 + atomic_inc_unchecked(&sk->sk_drops);
74179 trace_sock_rcvqueue_full(sk, skb);
74180 return -ENOMEM;
74181 }
74182 @@ -299,7 +299,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74183 return err;
74184
74185 if (!sk_rmem_schedule(sk, skb->truesize)) {
74186 - atomic_inc(&sk->sk_drops);
74187 + atomic_inc_unchecked(&sk->sk_drops);
74188 return -ENOBUFS;
74189 }
74190
74191 @@ -319,7 +319,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74192 skb_dst_force(skb);
74193
74194 spin_lock_irqsave(&list->lock, flags);
74195 - skb->dropcount = atomic_read(&sk->sk_drops);
74196 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
74197 __skb_queue_tail(list, skb);
74198 spin_unlock_irqrestore(&list->lock, flags);
74199
74200 @@ -339,7 +339,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
74201 skb->dev = NULL;
74202
74203 if (sk_rcvqueues_full(sk, skb)) {
74204 - atomic_inc(&sk->sk_drops);
74205 + atomic_inc_unchecked(&sk->sk_drops);
74206 goto discard_and_relse;
74207 }
74208 if (nested)
74209 @@ -357,7 +357,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
74210 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
74211 } else if (sk_add_backlog(sk, skb)) {
74212 bh_unlock_sock(sk);
74213 - atomic_inc(&sk->sk_drops);
74214 + atomic_inc_unchecked(&sk->sk_drops);
74215 goto discard_and_relse;
74216 }
74217
74218 @@ -917,7 +917,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74219 if (len > sizeof(peercred))
74220 len = sizeof(peercred);
74221 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
74222 - if (copy_to_user(optval, &peercred, len))
74223 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
74224 return -EFAULT;
74225 goto lenout;
74226 }
74227 @@ -930,7 +930,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74228 return -ENOTCONN;
74229 if (lv < len)
74230 return -EINVAL;
74231 - if (copy_to_user(optval, address, len))
74232 + if (len > sizeof(address) || copy_to_user(optval, address, len))
74233 return -EFAULT;
74234 goto lenout;
74235 }
74236 @@ -963,7 +963,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74237
74238 if (len > lv)
74239 len = lv;
74240 - if (copy_to_user(optval, &v, len))
74241 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
74242 return -EFAULT;
74243 lenout:
74244 if (put_user(len, optlen))
74245 @@ -2020,7 +2020,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
74246 */
74247 smp_wmb();
74248 atomic_set(&sk->sk_refcnt, 1);
74249 - atomic_set(&sk->sk_drops, 0);
74250 + atomic_set_unchecked(&sk->sk_drops, 0);
74251 }
74252 EXPORT_SYMBOL(sock_init_data);
74253
74254 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
74255 index 02e75d1..9a57a7c 100644
74256 --- a/net/decnet/sysctl_net_decnet.c
74257 +++ b/net/decnet/sysctl_net_decnet.c
74258 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
74259
74260 if (len > *lenp) len = *lenp;
74261
74262 - if (copy_to_user(buffer, addr, len))
74263 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
74264 return -EFAULT;
74265
74266 *lenp = len;
74267 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
74268
74269 if (len > *lenp) len = *lenp;
74270
74271 - if (copy_to_user(buffer, devname, len))
74272 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
74273 return -EFAULT;
74274
74275 *lenp = len;
74276 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
74277 index 39a2d29..f39c0fe 100644
74278 --- a/net/econet/Kconfig
74279 +++ b/net/econet/Kconfig
74280 @@ -4,7 +4,7 @@
74281
74282 config ECONET
74283 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
74284 - depends on EXPERIMENTAL && INET
74285 + depends on EXPERIMENTAL && INET && BROKEN
74286 ---help---
74287 Econet is a fairly old and slow networking protocol mainly used by
74288 Acorn computers to access file and print servers. It uses native
74289 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
74290 index 92fc5f6..b790d91 100644
74291 --- a/net/ipv4/fib_frontend.c
74292 +++ b/net/ipv4/fib_frontend.c
74293 @@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
74294 #ifdef CONFIG_IP_ROUTE_MULTIPATH
74295 fib_sync_up(dev);
74296 #endif
74297 - atomic_inc(&net->ipv4.dev_addr_genid);
74298 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74299 rt_cache_flush(dev_net(dev), -1);
74300 break;
74301 case NETDEV_DOWN:
74302 fib_del_ifaddr(ifa, NULL);
74303 - atomic_inc(&net->ipv4.dev_addr_genid);
74304 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74305 if (ifa->ifa_dev->ifa_list == NULL) {
74306 /* Last address was deleted from this interface.
74307 * Disable IP.
74308 @@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
74309 #ifdef CONFIG_IP_ROUTE_MULTIPATH
74310 fib_sync_up(dev);
74311 #endif
74312 - atomic_inc(&net->ipv4.dev_addr_genid);
74313 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74314 rt_cache_flush(dev_net(dev), -1);
74315 break;
74316 case NETDEV_DOWN:
74317 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
74318 index 80106d8..232e898 100644
74319 --- a/net/ipv4/fib_semantics.c
74320 +++ b/net/ipv4/fib_semantics.c
74321 @@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
74322 nh->nh_saddr = inet_select_addr(nh->nh_dev,
74323 nh->nh_gw,
74324 nh->nh_parent->fib_scope);
74325 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
74326 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
74327
74328 return nh->nh_saddr;
74329 }
74330 diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
74331 index ccee270..db23c3c 100644
74332 --- a/net/ipv4/inet_diag.c
74333 +++ b/net/ipv4/inet_diag.c
74334 @@ -114,8 +114,14 @@ static int inet_csk_diag_fill(struct sock *sk,
74335 r->idiag_retrans = 0;
74336
74337 r->id.idiag_if = sk->sk_bound_dev_if;
74338 +
74339 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74340 + r->id.idiag_cookie[0] = 0;
74341 + r->id.idiag_cookie[1] = 0;
74342 +#else
74343 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
74344 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
74345 +#endif
74346
74347 r->id.idiag_sport = inet->inet_sport;
74348 r->id.idiag_dport = inet->inet_dport;
74349 @@ -210,8 +216,15 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
74350 r->idiag_family = tw->tw_family;
74351 r->idiag_retrans = 0;
74352 r->id.idiag_if = tw->tw_bound_dev_if;
74353 +
74354 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74355 + r->id.idiag_cookie[0] = 0;
74356 + r->id.idiag_cookie[1] = 0;
74357 +#else
74358 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
74359 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
74360 +#endif
74361 +
74362 r->id.idiag_sport = tw->tw_sport;
74363 r->id.idiag_dport = tw->tw_dport;
74364 r->id.idiag_src[0] = tw->tw_rcv_saddr;
74365 @@ -294,12 +307,14 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
74366 if (sk == NULL)
74367 goto unlock;
74368
74369 +#ifndef CONFIG_GRKERNSEC_HIDESYM
74370 err = -ESTALE;
74371 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
74372 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
74373 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
74374 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
74375 goto out;
74376 +#endif
74377
74378 err = -ENOMEM;
74379 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
74380 @@ -589,8 +604,14 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
74381 r->idiag_retrans = req->retrans;
74382
74383 r->id.idiag_if = sk->sk_bound_dev_if;
74384 +
74385 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74386 + r->id.idiag_cookie[0] = 0;
74387 + r->id.idiag_cookie[1] = 0;
74388 +#else
74389 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
74390 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
74391 +#endif
74392
74393 tmo = req->expires - jiffies;
74394 if (tmo < 0)
74395 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
74396 index 984ec65..97ac518 100644
74397 --- a/net/ipv4/inet_hashtables.c
74398 +++ b/net/ipv4/inet_hashtables.c
74399 @@ -18,12 +18,15 @@
74400 #include <linux/sched.h>
74401 #include <linux/slab.h>
74402 #include <linux/wait.h>
74403 +#include <linux/security.h>
74404
74405 #include <net/inet_connection_sock.h>
74406 #include <net/inet_hashtables.h>
74407 #include <net/secure_seq.h>
74408 #include <net/ip.h>
74409
74410 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
74411 +
74412 /*
74413 * Allocate and initialize a new local port bind bucket.
74414 * The bindhash mutex for snum's hash chain must be held here.
74415 @@ -530,6 +533,8 @@ ok:
74416 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
74417 spin_unlock(&head->lock);
74418
74419 + gr_update_task_in_ip_table(current, inet_sk(sk));
74420 +
74421 if (tw) {
74422 inet_twsk_deschedule(tw, death_row);
74423 while (twrefcnt) {
74424 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
74425 index 86f13c67..59a35b5 100644
74426 --- a/net/ipv4/inetpeer.c
74427 +++ b/net/ipv4/inetpeer.c
74428 @@ -436,8 +436,8 @@ relookup:
74429 if (p) {
74430 p->daddr = *daddr;
74431 atomic_set(&p->refcnt, 1);
74432 - atomic_set(&p->rid, 0);
74433 - atomic_set(&p->ip_id_count,
74434 + atomic_set_unchecked(&p->rid, 0);
74435 + atomic_set_unchecked(&p->ip_id_count,
74436 (daddr->family == AF_INET) ?
74437 secure_ip_id(daddr->addr.a4) :
74438 secure_ipv6_id(daddr->addr.a6));
74439 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
74440 index fdaabf2..0ec3205 100644
74441 --- a/net/ipv4/ip_fragment.c
74442 +++ b/net/ipv4/ip_fragment.c
74443 @@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
74444 return 0;
74445
74446 start = qp->rid;
74447 - end = atomic_inc_return(&peer->rid);
74448 + end = atomic_inc_return_unchecked(&peer->rid);
74449 qp->rid = end;
74450
74451 rc = qp->q.fragments && (end - start) > max;
74452 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
74453 index 09ff51b..d3968eb 100644
74454 --- a/net/ipv4/ip_sockglue.c
74455 +++ b/net/ipv4/ip_sockglue.c
74456 @@ -1111,7 +1111,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
74457 len = min_t(unsigned int, len, opt->optlen);
74458 if (put_user(len, optlen))
74459 return -EFAULT;
74460 - if (copy_to_user(optval, opt->__data, len))
74461 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
74462 + copy_to_user(optval, opt->__data, len))
74463 return -EFAULT;
74464 return 0;
74465 }
74466 @@ -1239,7 +1240,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
74467 if (sk->sk_type != SOCK_STREAM)
74468 return -ENOPROTOOPT;
74469
74470 - msg.msg_control = optval;
74471 + msg.msg_control = (void __force_kernel *)optval;
74472 msg.msg_controllen = len;
74473 msg.msg_flags = flags;
74474
74475 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
74476 index 99ec116..c5628fe 100644
74477 --- a/net/ipv4/ipconfig.c
74478 +++ b/net/ipv4/ipconfig.c
74479 @@ -318,7 +318,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
74480
74481 mm_segment_t oldfs = get_fs();
74482 set_fs(get_ds());
74483 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
74484 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
74485 set_fs(oldfs);
74486 return res;
74487 }
74488 @@ -329,7 +329,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
74489
74490 mm_segment_t oldfs = get_fs();
74491 set_fs(get_ds());
74492 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
74493 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
74494 set_fs(oldfs);
74495 return res;
74496 }
74497 @@ -340,7 +340,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
74498
74499 mm_segment_t oldfs = get_fs();
74500 set_fs(get_ds());
74501 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
74502 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
74503 set_fs(oldfs);
74504 return res;
74505 }
74506 diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
74507 index 2133c30..5c4b40b 100644
74508 --- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
74509 +++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
74510 @@ -399,7 +399,7 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
74511
74512 *len = 0;
74513
74514 - *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
74515 + *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
74516 if (*octets == NULL)
74517 return 0;
74518
74519 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
74520 index 43d4c3b..1914409 100644
74521 --- a/net/ipv4/ping.c
74522 +++ b/net/ipv4/ping.c
74523 @@ -836,7 +836,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
74524 sk_rmem_alloc_get(sp),
74525 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74526 atomic_read(&sp->sk_refcnt), sp,
74527 - atomic_read(&sp->sk_drops), len);
74528 + atomic_read_unchecked(&sp->sk_drops), len);
74529 }
74530
74531 static int ping_seq_show(struct seq_file *seq, void *v)
74532 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
74533 index 007e2eb..85a18a0 100644
74534 --- a/net/ipv4/raw.c
74535 +++ b/net/ipv4/raw.c
74536 @@ -303,7 +303,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
74537 int raw_rcv(struct sock *sk, struct sk_buff *skb)
74538 {
74539 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
74540 - atomic_inc(&sk->sk_drops);
74541 + atomic_inc_unchecked(&sk->sk_drops);
74542 kfree_skb(skb);
74543 return NET_RX_DROP;
74544 }
74545 @@ -738,16 +738,20 @@ static int raw_init(struct sock *sk)
74546
74547 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
74548 {
74549 + struct icmp_filter filter;
74550 +
74551 if (optlen > sizeof(struct icmp_filter))
74552 optlen = sizeof(struct icmp_filter);
74553 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
74554 + if (copy_from_user(&filter, optval, optlen))
74555 return -EFAULT;
74556 + raw_sk(sk)->filter = filter;
74557 return 0;
74558 }
74559
74560 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
74561 {
74562 int len, ret = -EFAULT;
74563 + struct icmp_filter filter;
74564
74565 if (get_user(len, optlen))
74566 goto out;
74567 @@ -757,8 +761,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
74568 if (len > sizeof(struct icmp_filter))
74569 len = sizeof(struct icmp_filter);
74570 ret = -EFAULT;
74571 - if (put_user(len, optlen) ||
74572 - copy_to_user(optval, &raw_sk(sk)->filter, len))
74573 + filter = raw_sk(sk)->filter;
74574 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
74575 goto out;
74576 ret = 0;
74577 out: return ret;
74578 @@ -986,7 +990,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
74579 sk_wmem_alloc_get(sp),
74580 sk_rmem_alloc_get(sp),
74581 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74582 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
74583 + atomic_read(&sp->sk_refcnt),
74584 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74585 + NULL,
74586 +#else
74587 + sp,
74588 +#endif
74589 + atomic_read_unchecked(&sp->sk_drops));
74590 }
74591
74592 static int raw_seq_show(struct seq_file *seq, void *v)
74593 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
74594 index 94cdbc5..0cb0063 100644
74595 --- a/net/ipv4/route.c
74596 +++ b/net/ipv4/route.c
74597 @@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
74598
74599 static inline int rt_genid(struct net *net)
74600 {
74601 - return atomic_read(&net->ipv4.rt_genid);
74602 + return atomic_read_unchecked(&net->ipv4.rt_genid);
74603 }
74604
74605 #ifdef CONFIG_PROC_FS
74606 @@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
74607 unsigned char shuffle;
74608
74609 get_random_bytes(&shuffle, sizeof(shuffle));
74610 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
74611 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
74612 redirect_genid++;
74613 }
74614
74615 @@ -3022,7 +3022,7 @@ static int rt_fill_info(struct net *net,
74616 error = rt->dst.error;
74617 if (peer) {
74618 inet_peer_refcheck(rt->peer);
74619 - id = atomic_read(&peer->ip_id_count) & 0xffff;
74620 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
74621 if (peer->tcp_ts_stamp) {
74622 ts = peer->tcp_ts;
74623 tsage = get_seconds() - peer->tcp_ts_stamp;
74624 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
74625 index eb90aa8..22bf114 100644
74626 --- a/net/ipv4/tcp_ipv4.c
74627 +++ b/net/ipv4/tcp_ipv4.c
74628 @@ -87,6 +87,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
74629 int sysctl_tcp_low_latency __read_mostly;
74630 EXPORT_SYMBOL(sysctl_tcp_low_latency);
74631
74632 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74633 +extern int grsec_enable_blackhole;
74634 +#endif
74635
74636 #ifdef CONFIG_TCP_MD5SIG
74637 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
74638 @@ -1632,6 +1635,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
74639 return 0;
74640
74641 reset:
74642 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74643 + if (!grsec_enable_blackhole)
74644 +#endif
74645 tcp_v4_send_reset(rsk, skb);
74646 discard:
74647 kfree_skb(skb);
74648 @@ -1694,12 +1700,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
74649 TCP_SKB_CB(skb)->sacked = 0;
74650
74651 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
74652 - if (!sk)
74653 + if (!sk) {
74654 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74655 + ret = 1;
74656 +#endif
74657 goto no_tcp_socket;
74658 -
74659 + }
74660 process:
74661 - if (sk->sk_state == TCP_TIME_WAIT)
74662 + if (sk->sk_state == TCP_TIME_WAIT) {
74663 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74664 + ret = 2;
74665 +#endif
74666 goto do_time_wait;
74667 + }
74668
74669 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
74670 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
74671 @@ -1749,6 +1762,10 @@ no_tcp_socket:
74672 bad_packet:
74673 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
74674 } else {
74675 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74676 + if (!grsec_enable_blackhole || (ret == 1 &&
74677 + (skb->dev->flags & IFF_LOOPBACK)))
74678 +#endif
74679 tcp_v4_send_reset(NULL, skb);
74680 }
74681
74682 @@ -2409,7 +2426,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
74683 0, /* non standard timer */
74684 0, /* open_requests have no inode */
74685 atomic_read(&sk->sk_refcnt),
74686 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74687 + NULL,
74688 +#else
74689 req,
74690 +#endif
74691 len);
74692 }
74693
74694 @@ -2459,7 +2480,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
74695 sock_i_uid(sk),
74696 icsk->icsk_probes_out,
74697 sock_i_ino(sk),
74698 - atomic_read(&sk->sk_refcnt), sk,
74699 + atomic_read(&sk->sk_refcnt),
74700 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74701 + NULL,
74702 +#else
74703 + sk,
74704 +#endif
74705 jiffies_to_clock_t(icsk->icsk_rto),
74706 jiffies_to_clock_t(icsk->icsk_ack.ato),
74707 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
74708 @@ -2487,7 +2513,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
74709 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
74710 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
74711 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
74712 - atomic_read(&tw->tw_refcnt), tw, len);
74713 + atomic_read(&tw->tw_refcnt),
74714 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74715 + NULL,
74716 +#else
74717 + tw,
74718 +#endif
74719 + len);
74720 }
74721
74722 #define TMPSZ 150
74723 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
74724 index 66363b6..b0654a3 100644
74725 --- a/net/ipv4/tcp_minisocks.c
74726 +++ b/net/ipv4/tcp_minisocks.c
74727 @@ -27,6 +27,10 @@
74728 #include <net/inet_common.h>
74729 #include <net/xfrm.h>
74730
74731 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74732 +extern int grsec_enable_blackhole;
74733 +#endif
74734 +
74735 int sysctl_tcp_syncookies __read_mostly = 1;
74736 EXPORT_SYMBOL(sysctl_tcp_syncookies);
74737
74738 @@ -751,6 +755,10 @@ listen_overflow:
74739
74740 embryonic_reset:
74741 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
74742 +
74743 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74744 + if (!grsec_enable_blackhole)
74745 +#endif
74746 if (!(flg & TCP_FLAG_RST))
74747 req->rsk_ops->send_reset(sk, skb);
74748
74749 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
74750 index 85ee7eb..53277ab 100644
74751 --- a/net/ipv4/tcp_probe.c
74752 +++ b/net/ipv4/tcp_probe.c
74753 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
74754 if (cnt + width >= len)
74755 break;
74756
74757 - if (copy_to_user(buf + cnt, tbuf, width))
74758 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
74759 return -EFAULT;
74760 cnt += width;
74761 }
74762 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
74763 index 2e0f0af..e2948bf 100644
74764 --- a/net/ipv4/tcp_timer.c
74765 +++ b/net/ipv4/tcp_timer.c
74766 @@ -22,6 +22,10 @@
74767 #include <linux/gfp.h>
74768 #include <net/tcp.h>
74769
74770 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74771 +extern int grsec_lastack_retries;
74772 +#endif
74773 +
74774 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
74775 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
74776 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
74777 @@ -199,6 +203,13 @@ static int tcp_write_timeout(struct sock *sk)
74778 }
74779 }
74780
74781 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74782 + if ((sk->sk_state == TCP_LAST_ACK) &&
74783 + (grsec_lastack_retries > 0) &&
74784 + (grsec_lastack_retries < retry_until))
74785 + retry_until = grsec_lastack_retries;
74786 +#endif
74787 +
74788 if (retransmits_timed_out(sk, retry_until,
74789 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
74790 /* Has it gone just too far? */
74791 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
74792 index 5a65eea..bd913a1 100644
74793 --- a/net/ipv4/udp.c
74794 +++ b/net/ipv4/udp.c
74795 @@ -86,6 +86,7 @@
74796 #include <linux/types.h>
74797 #include <linux/fcntl.h>
74798 #include <linux/module.h>
74799 +#include <linux/security.h>
74800 #include <linux/socket.h>
74801 #include <linux/sockios.h>
74802 #include <linux/igmp.h>
74803 @@ -108,6 +109,10 @@
74804 #include <trace/events/udp.h>
74805 #include "udp_impl.h"
74806
74807 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74808 +extern int grsec_enable_blackhole;
74809 +#endif
74810 +
74811 struct udp_table udp_table __read_mostly;
74812 EXPORT_SYMBOL(udp_table);
74813
74814 @@ -565,6 +570,9 @@ found:
74815 return s;
74816 }
74817
74818 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
74819 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
74820 +
74821 /*
74822 * This routine is called by the ICMP module when it gets some
74823 * sort of error condition. If err < 0 then the socket should
74824 @@ -856,9 +864,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
74825 dport = usin->sin_port;
74826 if (dport == 0)
74827 return -EINVAL;
74828 +
74829 + err = gr_search_udp_sendmsg(sk, usin);
74830 + if (err)
74831 + return err;
74832 } else {
74833 if (sk->sk_state != TCP_ESTABLISHED)
74834 return -EDESTADDRREQ;
74835 +
74836 + err = gr_search_udp_sendmsg(sk, NULL);
74837 + if (err)
74838 + return err;
74839 +
74840 daddr = inet->inet_daddr;
74841 dport = inet->inet_dport;
74842 /* Open fast path for connected socket.
74843 @@ -1099,7 +1116,7 @@ static unsigned int first_packet_length(struct sock *sk)
74844 udp_lib_checksum_complete(skb)) {
74845 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
74846 IS_UDPLITE(sk));
74847 - atomic_inc(&sk->sk_drops);
74848 + atomic_inc_unchecked(&sk->sk_drops);
74849 __skb_unlink(skb, rcvq);
74850 __skb_queue_tail(&list_kill, skb);
74851 }
74852 @@ -1185,6 +1202,10 @@ try_again:
74853 if (!skb)
74854 goto out;
74855
74856 + err = gr_search_udp_recvmsg(sk, skb);
74857 + if (err)
74858 + goto out_free;
74859 +
74860 ulen = skb->len - sizeof(struct udphdr);
74861 copied = len;
74862 if (copied > ulen)
74863 @@ -1487,7 +1508,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74864
74865 drop:
74866 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
74867 - atomic_inc(&sk->sk_drops);
74868 + atomic_inc_unchecked(&sk->sk_drops);
74869 kfree_skb(skb);
74870 return -1;
74871 }
74872 @@ -1506,7 +1527,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
74873 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
74874
74875 if (!skb1) {
74876 - atomic_inc(&sk->sk_drops);
74877 + atomic_inc_unchecked(&sk->sk_drops);
74878 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
74879 IS_UDPLITE(sk));
74880 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
74881 @@ -1675,6 +1696,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
74882 goto csum_error;
74883
74884 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
74885 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74886 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
74887 +#endif
74888 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
74889
74890 /*
74891 @@ -2098,8 +2122,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
74892 sk_wmem_alloc_get(sp),
74893 sk_rmem_alloc_get(sp),
74894 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74895 - atomic_read(&sp->sk_refcnt), sp,
74896 - atomic_read(&sp->sk_drops), len);
74897 + atomic_read(&sp->sk_refcnt),
74898 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74899 + NULL,
74900 +#else
74901 + sp,
74902 +#endif
74903 + atomic_read_unchecked(&sp->sk_drops), len);
74904 }
74905
74906 int udp4_seq_show(struct seq_file *seq, void *v)
74907 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
74908 index 836c4ea..cbb74dc 100644
74909 --- a/net/ipv6/addrconf.c
74910 +++ b/net/ipv6/addrconf.c
74911 @@ -2149,7 +2149,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
74912 p.iph.ihl = 5;
74913 p.iph.protocol = IPPROTO_IPV6;
74914 p.iph.ttl = 64;
74915 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
74916 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
74917
74918 if (ops->ndo_do_ioctl) {
74919 mm_segment_t oldfs = get_fs();
74920 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
74921 index 1567fb1..29af910 100644
74922 --- a/net/ipv6/inet6_connection_sock.c
74923 +++ b/net/ipv6/inet6_connection_sock.c
74924 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
74925 #ifdef CONFIG_XFRM
74926 {
74927 struct rt6_info *rt = (struct rt6_info *)dst;
74928 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
74929 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
74930 }
74931 #endif
74932 }
74933 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
74934 #ifdef CONFIG_XFRM
74935 if (dst) {
74936 struct rt6_info *rt = (struct rt6_info *)dst;
74937 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
74938 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
74939 __sk_dst_reset(sk);
74940 dst = NULL;
74941 }
74942 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
74943 index 26cb08c..8af9877 100644
74944 --- a/net/ipv6/ipv6_sockglue.c
74945 +++ b/net/ipv6/ipv6_sockglue.c
74946 @@ -960,7 +960,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
74947 if (sk->sk_type != SOCK_STREAM)
74948 return -ENOPROTOOPT;
74949
74950 - msg.msg_control = optval;
74951 + msg.msg_control = (void __force_kernel *)optval;
74952 msg.msg_controllen = len;
74953 msg.msg_flags = flags;
74954
74955 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
74956 index 361ebf3..d5628fb 100644
74957 --- a/net/ipv6/raw.c
74958 +++ b/net/ipv6/raw.c
74959 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
74960 {
74961 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
74962 skb_checksum_complete(skb)) {
74963 - atomic_inc(&sk->sk_drops);
74964 + atomic_inc_unchecked(&sk->sk_drops);
74965 kfree_skb(skb);
74966 return NET_RX_DROP;
74967 }
74968 @@ -404,7 +404,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
74969 struct raw6_sock *rp = raw6_sk(sk);
74970
74971 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
74972 - atomic_inc(&sk->sk_drops);
74973 + atomic_inc_unchecked(&sk->sk_drops);
74974 kfree_skb(skb);
74975 return NET_RX_DROP;
74976 }
74977 @@ -428,7 +428,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
74978
74979 if (inet->hdrincl) {
74980 if (skb_checksum_complete(skb)) {
74981 - atomic_inc(&sk->sk_drops);
74982 + atomic_inc_unchecked(&sk->sk_drops);
74983 kfree_skb(skb);
74984 return NET_RX_DROP;
74985 }
74986 @@ -601,7 +601,7 @@ out:
74987 return err;
74988 }
74989
74990 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
74991 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
74992 struct flowi6 *fl6, struct dst_entry **dstp,
74993 unsigned int flags)
74994 {
74995 @@ -909,12 +909,15 @@ do_confirm:
74996 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
74997 char __user *optval, int optlen)
74998 {
74999 + struct icmp6_filter filter;
75000 +
75001 switch (optname) {
75002 case ICMPV6_FILTER:
75003 if (optlen > sizeof(struct icmp6_filter))
75004 optlen = sizeof(struct icmp6_filter);
75005 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
75006 + if (copy_from_user(&filter, optval, optlen))
75007 return -EFAULT;
75008 + raw6_sk(sk)->filter = filter;
75009 return 0;
75010 default:
75011 return -ENOPROTOOPT;
75012 @@ -927,6 +930,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
75013 char __user *optval, int __user *optlen)
75014 {
75015 int len;
75016 + struct icmp6_filter filter;
75017
75018 switch (optname) {
75019 case ICMPV6_FILTER:
75020 @@ -938,7 +942,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
75021 len = sizeof(struct icmp6_filter);
75022 if (put_user(len, optlen))
75023 return -EFAULT;
75024 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
75025 + filter = raw6_sk(sk)->filter;
75026 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
75027 return -EFAULT;
75028 return 0;
75029 default:
75030 @@ -1245,7 +1250,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
75031 0, 0L, 0,
75032 sock_i_uid(sp), 0,
75033 sock_i_ino(sp),
75034 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
75035 + atomic_read(&sp->sk_refcnt),
75036 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75037 + NULL,
75038 +#else
75039 + sp,
75040 +#endif
75041 + atomic_read_unchecked(&sp->sk_drops));
75042 }
75043
75044 static int raw6_seq_show(struct seq_file *seq, void *v)
75045 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
75046 index b859e4a..f9d1589 100644
75047 --- a/net/ipv6/tcp_ipv6.c
75048 +++ b/net/ipv6/tcp_ipv6.c
75049 @@ -93,6 +93,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
75050 }
75051 #endif
75052
75053 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75054 +extern int grsec_enable_blackhole;
75055 +#endif
75056 +
75057 static void tcp_v6_hash(struct sock *sk)
75058 {
75059 if (sk->sk_state != TCP_CLOSE) {
75060 @@ -1651,6 +1655,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
75061 return 0;
75062
75063 reset:
75064 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75065 + if (!grsec_enable_blackhole)
75066 +#endif
75067 tcp_v6_send_reset(sk, skb);
75068 discard:
75069 if (opt_skb)
75070 @@ -1730,12 +1737,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
75071 TCP_SKB_CB(skb)->sacked = 0;
75072
75073 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
75074 - if (!sk)
75075 + if (!sk) {
75076 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75077 + ret = 1;
75078 +#endif
75079 goto no_tcp_socket;
75080 + }
75081
75082 process:
75083 - if (sk->sk_state == TCP_TIME_WAIT)
75084 + if (sk->sk_state == TCP_TIME_WAIT) {
75085 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75086 + ret = 2;
75087 +#endif
75088 goto do_time_wait;
75089 + }
75090
75091 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
75092 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
75093 @@ -1783,6 +1798,10 @@ no_tcp_socket:
75094 bad_packet:
75095 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
75096 } else {
75097 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75098 + if (!grsec_enable_blackhole || (ret == 1 &&
75099 + (skb->dev->flags & IFF_LOOPBACK)))
75100 +#endif
75101 tcp_v6_send_reset(NULL, skb);
75102 }
75103
75104 @@ -2043,7 +2062,13 @@ static void get_openreq6(struct seq_file *seq,
75105 uid,
75106 0, /* non standard timer */
75107 0, /* open_requests have no inode */
75108 - 0, req);
75109 + 0,
75110 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75111 + NULL
75112 +#else
75113 + req
75114 +#endif
75115 + );
75116 }
75117
75118 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
75119 @@ -2093,7 +2118,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
75120 sock_i_uid(sp),
75121 icsk->icsk_probes_out,
75122 sock_i_ino(sp),
75123 - atomic_read(&sp->sk_refcnt), sp,
75124 + atomic_read(&sp->sk_refcnt),
75125 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75126 + NULL,
75127 +#else
75128 + sp,
75129 +#endif
75130 jiffies_to_clock_t(icsk->icsk_rto),
75131 jiffies_to_clock_t(icsk->icsk_ack.ato),
75132 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
75133 @@ -2128,7 +2158,13 @@ static void get_timewait6_sock(struct seq_file *seq,
75134 dest->s6_addr32[2], dest->s6_addr32[3], destp,
75135 tw->tw_substate, 0, 0,
75136 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
75137 - atomic_read(&tw->tw_refcnt), tw);
75138 + atomic_read(&tw->tw_refcnt),
75139 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75140 + NULL
75141 +#else
75142 + tw
75143 +#endif
75144 + );
75145 }
75146
75147 static int tcp6_seq_show(struct seq_file *seq, void *v)
75148 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
75149 index 8c25419..47a51ae 100644
75150 --- a/net/ipv6/udp.c
75151 +++ b/net/ipv6/udp.c
75152 @@ -50,6 +50,10 @@
75153 #include <linux/seq_file.h>
75154 #include "udp_impl.h"
75155
75156 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75157 +extern int grsec_enable_blackhole;
75158 +#endif
75159 +
75160 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
75161 {
75162 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
75163 @@ -549,7 +553,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
75164
75165 return 0;
75166 drop:
75167 - atomic_inc(&sk->sk_drops);
75168 + atomic_inc_unchecked(&sk->sk_drops);
75169 drop_no_sk_drops_inc:
75170 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75171 kfree_skb(skb);
75172 @@ -625,7 +629,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75173 continue;
75174 }
75175 drop:
75176 - atomic_inc(&sk->sk_drops);
75177 + atomic_inc_unchecked(&sk->sk_drops);
75178 UDP6_INC_STATS_BH(sock_net(sk),
75179 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
75180 UDP6_INC_STATS_BH(sock_net(sk),
75181 @@ -780,6 +784,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75182 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
75183 proto == IPPROTO_UDPLITE);
75184
75185 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75186 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75187 +#endif
75188 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
75189
75190 kfree_skb(skb);
75191 @@ -796,7 +803,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75192 if (!sock_owned_by_user(sk))
75193 udpv6_queue_rcv_skb(sk, skb);
75194 else if (sk_add_backlog(sk, skb)) {
75195 - atomic_inc(&sk->sk_drops);
75196 + atomic_inc_unchecked(&sk->sk_drops);
75197 bh_unlock_sock(sk);
75198 sock_put(sk);
75199 goto discard;
75200 @@ -1407,8 +1414,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
75201 0, 0L, 0,
75202 sock_i_uid(sp), 0,
75203 sock_i_ino(sp),
75204 - atomic_read(&sp->sk_refcnt), sp,
75205 - atomic_read(&sp->sk_drops));
75206 + atomic_read(&sp->sk_refcnt),
75207 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75208 + NULL,
75209 +#else
75210 + sp,
75211 +#endif
75212 + atomic_read_unchecked(&sp->sk_drops));
75213 }
75214
75215 int udp6_seq_show(struct seq_file *seq, void *v)
75216 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
75217 index 253695d..9481ce8 100644
75218 --- a/net/irda/ircomm/ircomm_tty.c
75219 +++ b/net/irda/ircomm/ircomm_tty.c
75220 @@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75221 add_wait_queue(&self->open_wait, &wait);
75222
75223 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
75224 - __FILE__,__LINE__, tty->driver->name, self->open_count );
75225 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
75226
75227 /* As far as I can see, we protect open_count - Jean II */
75228 spin_lock_irqsave(&self->spinlock, flags);
75229 if (!tty_hung_up_p(filp)) {
75230 extra_count = 1;
75231 - self->open_count--;
75232 + local_dec(&self->open_count);
75233 }
75234 spin_unlock_irqrestore(&self->spinlock, flags);
75235 - self->blocked_open++;
75236 + local_inc(&self->blocked_open);
75237
75238 while (1) {
75239 if (tty->termios->c_cflag & CBAUD) {
75240 @@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75241 }
75242
75243 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
75244 - __FILE__,__LINE__, tty->driver->name, self->open_count );
75245 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
75246
75247 schedule();
75248 }
75249 @@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75250 if (extra_count) {
75251 /* ++ is not atomic, so this should be protected - Jean II */
75252 spin_lock_irqsave(&self->spinlock, flags);
75253 - self->open_count++;
75254 + local_inc(&self->open_count);
75255 spin_unlock_irqrestore(&self->spinlock, flags);
75256 }
75257 - self->blocked_open--;
75258 + local_dec(&self->blocked_open);
75259
75260 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
75261 - __FILE__,__LINE__, tty->driver->name, self->open_count);
75262 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
75263
75264 if (!retval)
75265 self->flags |= ASYNC_NORMAL_ACTIVE;
75266 @@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
75267 }
75268 /* ++ is not atomic, so this should be protected - Jean II */
75269 spin_lock_irqsave(&self->spinlock, flags);
75270 - self->open_count++;
75271 + local_inc(&self->open_count);
75272
75273 tty->driver_data = self;
75274 self->tty = tty;
75275 spin_unlock_irqrestore(&self->spinlock, flags);
75276
75277 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
75278 - self->line, self->open_count);
75279 + self->line, local_read(&self->open_count));
75280
75281 /* Not really used by us, but lets do it anyway */
75282 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
75283 @@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75284 return;
75285 }
75286
75287 - if ((tty->count == 1) && (self->open_count != 1)) {
75288 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
75289 /*
75290 * Uh, oh. tty->count is 1, which means that the tty
75291 * structure will be freed. state->count should always
75292 @@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75293 */
75294 IRDA_DEBUG(0, "%s(), bad serial port count; "
75295 "tty->count is 1, state->count is %d\n", __func__ ,
75296 - self->open_count);
75297 - self->open_count = 1;
75298 + local_read(&self->open_count));
75299 + local_set(&self->open_count, 1);
75300 }
75301
75302 - if (--self->open_count < 0) {
75303 + if (local_dec_return(&self->open_count) < 0) {
75304 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
75305 - __func__, self->line, self->open_count);
75306 - self->open_count = 0;
75307 + __func__, self->line, local_read(&self->open_count));
75308 + local_set(&self->open_count, 0);
75309 }
75310 - if (self->open_count) {
75311 + if (local_read(&self->open_count)) {
75312 spin_unlock_irqrestore(&self->spinlock, flags);
75313
75314 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
75315 @@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75316 tty->closing = 0;
75317 self->tty = NULL;
75318
75319 - if (self->blocked_open) {
75320 + if (local_read(&self->blocked_open)) {
75321 if (self->close_delay)
75322 schedule_timeout_interruptible(self->close_delay);
75323 wake_up_interruptible(&self->open_wait);
75324 @@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
75325 spin_lock_irqsave(&self->spinlock, flags);
75326 self->flags &= ~ASYNC_NORMAL_ACTIVE;
75327 self->tty = NULL;
75328 - self->open_count = 0;
75329 + local_set(&self->open_count, 0);
75330 spin_unlock_irqrestore(&self->spinlock, flags);
75331
75332 wake_up_interruptible(&self->open_wait);
75333 @@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
75334 seq_putc(m, '\n');
75335
75336 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
75337 - seq_printf(m, "Open count: %d\n", self->open_count);
75338 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
75339 seq_printf(m, "Max data size: %d\n", self->max_data_size);
75340 seq_printf(m, "Max header size: %d\n", self->max_header_size);
75341
75342 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
75343 index 274d150..656a144 100644
75344 --- a/net/iucv/af_iucv.c
75345 +++ b/net/iucv/af_iucv.c
75346 @@ -787,10 +787,10 @@ static int iucv_sock_autobind(struct sock *sk)
75347
75348 write_lock_bh(&iucv_sk_list.lock);
75349
75350 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
75351 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
75352 while (__iucv_get_sock_by_name(name)) {
75353 sprintf(name, "%08x",
75354 - atomic_inc_return(&iucv_sk_list.autobind_name));
75355 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
75356 }
75357
75358 write_unlock_bh(&iucv_sk_list.lock);
75359 diff --git a/net/key/af_key.c b/net/key/af_key.c
75360 index 1e733e9..3d73c9f 100644
75361 --- a/net/key/af_key.c
75362 +++ b/net/key/af_key.c
75363 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
75364 static u32 get_acqseq(void)
75365 {
75366 u32 res;
75367 - static atomic_t acqseq;
75368 + static atomic_unchecked_t acqseq;
75369
75370 do {
75371 - res = atomic_inc_return(&acqseq);
75372 + res = atomic_inc_return_unchecked(&acqseq);
75373 } while (!res);
75374 return res;
75375 }
75376 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
75377 index 73495f1..ad51356 100644
75378 --- a/net/mac80211/ieee80211_i.h
75379 +++ b/net/mac80211/ieee80211_i.h
75380 @@ -27,6 +27,7 @@
75381 #include <net/ieee80211_radiotap.h>
75382 #include <net/cfg80211.h>
75383 #include <net/mac80211.h>
75384 +#include <asm/local.h>
75385 #include "key.h"
75386 #include "sta_info.h"
75387
75388 @@ -764,7 +765,7 @@ struct ieee80211_local {
75389 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
75390 spinlock_t queue_stop_reason_lock;
75391
75392 - int open_count;
75393 + local_t open_count;
75394 int monitors, cooked_mntrs;
75395 /* number of interfaces with corresponding FIF_ flags */
75396 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
75397 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
75398 index 30d7355..e260095 100644
75399 --- a/net/mac80211/iface.c
75400 +++ b/net/mac80211/iface.c
75401 @@ -211,7 +211,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75402 break;
75403 }
75404
75405 - if (local->open_count == 0) {
75406 + if (local_read(&local->open_count) == 0) {
75407 res = drv_start(local);
75408 if (res)
75409 goto err_del_bss;
75410 @@ -235,7 +235,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75411 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
75412
75413 if (!is_valid_ether_addr(dev->dev_addr)) {
75414 - if (!local->open_count)
75415 + if (!local_read(&local->open_count))
75416 drv_stop(local);
75417 return -EADDRNOTAVAIL;
75418 }
75419 @@ -327,7 +327,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75420 mutex_unlock(&local->mtx);
75421
75422 if (coming_up)
75423 - local->open_count++;
75424 + local_inc(&local->open_count);
75425
75426 if (hw_reconf_flags) {
75427 ieee80211_hw_config(local, hw_reconf_flags);
75428 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75429 err_del_interface:
75430 drv_remove_interface(local, &sdata->vif);
75431 err_stop:
75432 - if (!local->open_count)
75433 + if (!local_read(&local->open_count))
75434 drv_stop(local);
75435 err_del_bss:
75436 sdata->bss = NULL;
75437 @@ -472,7 +472,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
75438 }
75439
75440 if (going_down)
75441 - local->open_count--;
75442 + local_dec(&local->open_count);
75443
75444 switch (sdata->vif.type) {
75445 case NL80211_IFTYPE_AP_VLAN:
75446 @@ -531,7 +531,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
75447
75448 ieee80211_recalc_ps(local, -1);
75449
75450 - if (local->open_count == 0) {
75451 + if (local_read(&local->open_count) == 0) {
75452 if (local->ops->napi_poll)
75453 napi_disable(&local->napi);
75454 ieee80211_clear_tx_pending(local);
75455 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
75456 index 7d9b21d..0687004 100644
75457 --- a/net/mac80211/main.c
75458 +++ b/net/mac80211/main.c
75459 @@ -163,7 +163,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
75460 local->hw.conf.power_level = power;
75461 }
75462
75463 - if (changed && local->open_count) {
75464 + if (changed && local_read(&local->open_count)) {
75465 ret = drv_config(local, changed);
75466 /*
75467 * Goal:
75468 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
75469 index 9ee7164..56c5061 100644
75470 --- a/net/mac80211/pm.c
75471 +++ b/net/mac80211/pm.c
75472 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75473 struct ieee80211_sub_if_data *sdata;
75474 struct sta_info *sta;
75475
75476 - if (!local->open_count)
75477 + if (!local_read(&local->open_count))
75478 goto suspend;
75479
75480 ieee80211_scan_cancel(local);
75481 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75482 cancel_work_sync(&local->dynamic_ps_enable_work);
75483 del_timer_sync(&local->dynamic_ps_timer);
75484
75485 - local->wowlan = wowlan && local->open_count;
75486 + local->wowlan = wowlan && local_read(&local->open_count);
75487 if (local->wowlan) {
75488 int err = drv_suspend(local, wowlan);
75489 if (err < 0) {
75490 @@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75491 }
75492
75493 /* stop hardware - this must stop RX */
75494 - if (local->open_count)
75495 + if (local_read(&local->open_count))
75496 ieee80211_stop_device(local);
75497
75498 suspend:
75499 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
75500 index 5a5a776..9600b11 100644
75501 --- a/net/mac80211/rate.c
75502 +++ b/net/mac80211/rate.c
75503 @@ -401,7 +401,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
75504
75505 ASSERT_RTNL();
75506
75507 - if (local->open_count)
75508 + if (local_read(&local->open_count))
75509 return -EBUSY;
75510
75511 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
75512 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
75513 index c97a065..ff61928 100644
75514 --- a/net/mac80211/rc80211_pid_debugfs.c
75515 +++ b/net/mac80211/rc80211_pid_debugfs.c
75516 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
75517
75518 spin_unlock_irqrestore(&events->lock, status);
75519
75520 - if (copy_to_user(buf, pb, p))
75521 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
75522 return -EFAULT;
75523
75524 return p;
75525 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
75526 index d5230ec..c604b21 100644
75527 --- a/net/mac80211/util.c
75528 +++ b/net/mac80211/util.c
75529 @@ -1000,7 +1000,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
75530 drv_set_coverage_class(local, hw->wiphy->coverage_class);
75531
75532 /* everything else happens only if HW was up & running */
75533 - if (!local->open_count)
75534 + if (!local_read(&local->open_count))
75535 goto wake_up;
75536
75537 /*
75538 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
75539 index d5597b7..ab6d39c 100644
75540 --- a/net/netfilter/Kconfig
75541 +++ b/net/netfilter/Kconfig
75542 @@ -779,6 +779,16 @@ config NETFILTER_XT_MATCH_ESP
75543
75544 To compile it as a module, choose M here. If unsure, say N.
75545
75546 +config NETFILTER_XT_MATCH_GRADM
75547 + tristate '"gradm" match support'
75548 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
75549 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
75550 + ---help---
75551 + The gradm match allows to match on grsecurity RBAC being enabled.
75552 + It is useful when iptables rules are applied early on bootup to
75553 + prevent connections to the machine (except from a trusted host)
75554 + while the RBAC system is disabled.
75555 +
75556 config NETFILTER_XT_MATCH_HASHLIMIT
75557 tristate '"hashlimit" match support'
75558 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
75559 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
75560 index 1a02853..5d8c22e 100644
75561 --- a/net/netfilter/Makefile
75562 +++ b/net/netfilter/Makefile
75563 @@ -81,6 +81,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
75564 obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
75565 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
75566 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
75567 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
75568 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
75569 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
75570 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
75571 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
75572 index 29fa5ba..8debc79 100644
75573 --- a/net/netfilter/ipvs/ip_vs_conn.c
75574 +++ b/net/netfilter/ipvs/ip_vs_conn.c
75575 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
75576 /* Increase the refcnt counter of the dest */
75577 atomic_inc(&dest->refcnt);
75578
75579 - conn_flags = atomic_read(&dest->conn_flags);
75580 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
75581 if (cp->protocol != IPPROTO_UDP)
75582 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
75583 /* Bind with the destination and its corresponding transmitter */
75584 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
75585 atomic_set(&cp->refcnt, 1);
75586
75587 atomic_set(&cp->n_control, 0);
75588 - atomic_set(&cp->in_pkts, 0);
75589 + atomic_set_unchecked(&cp->in_pkts, 0);
75590
75591 atomic_inc(&ipvs->conn_count);
75592 if (flags & IP_VS_CONN_F_NO_CPORT)
75593 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
75594
75595 /* Don't drop the entry if its number of incoming packets is not
75596 located in [0, 8] */
75597 - i = atomic_read(&cp->in_pkts);
75598 + i = atomic_read_unchecked(&cp->in_pkts);
75599 if (i > 8 || i < 0) return 0;
75600
75601 if (!todrop_rate[i]) return 0;
75602 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
75603 index 6dc7d7d..e45913a 100644
75604 --- a/net/netfilter/ipvs/ip_vs_core.c
75605 +++ b/net/netfilter/ipvs/ip_vs_core.c
75606 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
75607 ret = cp->packet_xmit(skb, cp, pd->pp);
75608 /* do not touch skb anymore */
75609
75610 - atomic_inc(&cp->in_pkts);
75611 + atomic_inc_unchecked(&cp->in_pkts);
75612 ip_vs_conn_put(cp);
75613 return ret;
75614 }
75615 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
75616 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
75617 pkts = sysctl_sync_threshold(ipvs);
75618 else
75619 - pkts = atomic_add_return(1, &cp->in_pkts);
75620 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
75621
75622 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
75623 cp->protocol == IPPROTO_SCTP) {
75624 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
75625 index e1a66cf..0910076 100644
75626 --- a/net/netfilter/ipvs/ip_vs_ctl.c
75627 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
75628 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
75629 ip_vs_rs_hash(ipvs, dest);
75630 write_unlock_bh(&ipvs->rs_lock);
75631 }
75632 - atomic_set(&dest->conn_flags, conn_flags);
75633 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
75634
75635 /* bind the service */
75636 if (!dest->svc) {
75637 @@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
75638 " %-7s %-6d %-10d %-10d\n",
75639 &dest->addr.in6,
75640 ntohs(dest->port),
75641 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
75642 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
75643 atomic_read(&dest->weight),
75644 atomic_read(&dest->activeconns),
75645 atomic_read(&dest->inactconns));
75646 @@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
75647 "%-7s %-6d %-10d %-10d\n",
75648 ntohl(dest->addr.ip),
75649 ntohs(dest->port),
75650 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
75651 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
75652 atomic_read(&dest->weight),
75653 atomic_read(&dest->activeconns),
75654 atomic_read(&dest->inactconns));
75655 @@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
75656
75657 entry.addr = dest->addr.ip;
75658 entry.port = dest->port;
75659 - entry.conn_flags = atomic_read(&dest->conn_flags);
75660 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
75661 entry.weight = atomic_read(&dest->weight);
75662 entry.u_threshold = dest->u_threshold;
75663 entry.l_threshold = dest->l_threshold;
75664 @@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
75665 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
75666
75667 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
75668 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
75669 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
75670 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
75671 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
75672 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
75673 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
75674 index 2b6678c0..aaa41fc 100644
75675 --- a/net/netfilter/ipvs/ip_vs_sync.c
75676 +++ b/net/netfilter/ipvs/ip_vs_sync.c
75677 @@ -649,7 +649,7 @@ control:
75678 * i.e only increment in_pkts for Templates.
75679 */
75680 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
75681 - int pkts = atomic_add_return(1, &cp->in_pkts);
75682 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
75683
75684 if (pkts % sysctl_sync_period(ipvs) != 1)
75685 return;
75686 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
75687
75688 if (opt)
75689 memcpy(&cp->in_seq, opt, sizeof(*opt));
75690 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
75691 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
75692 cp->state = state;
75693 cp->old_state = cp->state;
75694 /*
75695 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
75696 index aa2d720..d8aa111 100644
75697 --- a/net/netfilter/ipvs/ip_vs_xmit.c
75698 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
75699 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
75700 else
75701 rc = NF_ACCEPT;
75702 /* do not touch skb anymore */
75703 - atomic_inc(&cp->in_pkts);
75704 + atomic_inc_unchecked(&cp->in_pkts);
75705 goto out;
75706 }
75707
75708 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
75709 else
75710 rc = NF_ACCEPT;
75711 /* do not touch skb anymore */
75712 - atomic_inc(&cp->in_pkts);
75713 + atomic_inc_unchecked(&cp->in_pkts);
75714 goto out;
75715 }
75716
75717 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
75718 index 66b2c54..c7884e3 100644
75719 --- a/net/netfilter/nfnetlink_log.c
75720 +++ b/net/netfilter/nfnetlink_log.c
75721 @@ -70,7 +70,7 @@ struct nfulnl_instance {
75722 };
75723
75724 static DEFINE_SPINLOCK(instances_lock);
75725 -static atomic_t global_seq;
75726 +static atomic_unchecked_t global_seq;
75727
75728 #define INSTANCE_BUCKETS 16
75729 static struct hlist_head instance_table[INSTANCE_BUCKETS];
75730 @@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
75731 /* global sequence number */
75732 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
75733 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
75734 - htonl(atomic_inc_return(&global_seq)));
75735 + htonl(atomic_inc_return_unchecked(&global_seq)));
75736
75737 if (data_len) {
75738 struct nlattr *nla;
75739 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
75740 new file mode 100644
75741 index 0000000..6905327
75742 --- /dev/null
75743 +++ b/net/netfilter/xt_gradm.c
75744 @@ -0,0 +1,51 @@
75745 +/*
75746 + * gradm match for netfilter
75747 + * Copyright © Zbigniew Krzystolik, 2010
75748 + *
75749 + * This program is free software; you can redistribute it and/or modify
75750 + * it under the terms of the GNU General Public License; either version
75751 + * 2 or 3 as published by the Free Software Foundation.
75752 + */
75753 +#include <linux/module.h>
75754 +#include <linux/moduleparam.h>
75755 +#include <linux/skbuff.h>
75756 +#include <linux/netfilter/x_tables.h>
75757 +#include <linux/grsecurity.h>
75758 +#include <linux/netfilter/xt_gradm.h>
75759 +
75760 +static bool
75761 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
75762 +{
75763 + const struct xt_gradm_mtinfo *info = par->matchinfo;
75764 + bool retval = false;
75765 + if (gr_acl_is_enabled())
75766 + retval = true;
75767 + return retval ^ info->invflags;
75768 +}
75769 +
75770 +static struct xt_match gradm_mt_reg __read_mostly = {
75771 + .name = "gradm",
75772 + .revision = 0,
75773 + .family = NFPROTO_UNSPEC,
75774 + .match = gradm_mt,
75775 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
75776 + .me = THIS_MODULE,
75777 +};
75778 +
75779 +static int __init gradm_mt_init(void)
75780 +{
75781 + return xt_register_match(&gradm_mt_reg);
75782 +}
75783 +
75784 +static void __exit gradm_mt_exit(void)
75785 +{
75786 + xt_unregister_match(&gradm_mt_reg);
75787 +}
75788 +
75789 +module_init(gradm_mt_init);
75790 +module_exit(gradm_mt_exit);
75791 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
75792 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
75793 +MODULE_LICENSE("GPL");
75794 +MODULE_ALIAS("ipt_gradm");
75795 +MODULE_ALIAS("ip6t_gradm");
75796 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
75797 index 4fe4fb4..87a89e5 100644
75798 --- a/net/netfilter/xt_statistic.c
75799 +++ b/net/netfilter/xt_statistic.c
75800 @@ -19,7 +19,7 @@
75801 #include <linux/module.h>
75802
75803 struct xt_statistic_priv {
75804 - atomic_t count;
75805 + atomic_unchecked_t count;
75806 } ____cacheline_aligned_in_smp;
75807
75808 MODULE_LICENSE("GPL");
75809 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
75810 break;
75811 case XT_STATISTIC_MODE_NTH:
75812 do {
75813 - oval = atomic_read(&info->master->count);
75814 + oval = atomic_read_unchecked(&info->master->count);
75815 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
75816 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
75817 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
75818 if (nval == 0)
75819 ret = !ret;
75820 break;
75821 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
75822 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
75823 if (info->master == NULL)
75824 return -ENOMEM;
75825 - atomic_set(&info->master->count, info->u.nth.count);
75826 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
75827
75828 return 0;
75829 }
75830 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
75831 index 1201b6d..bcff8c6 100644
75832 --- a/net/netlink/af_netlink.c
75833 +++ b/net/netlink/af_netlink.c
75834 @@ -742,7 +742,7 @@ static void netlink_overrun(struct sock *sk)
75835 sk->sk_error_report(sk);
75836 }
75837 }
75838 - atomic_inc(&sk->sk_drops);
75839 + atomic_inc_unchecked(&sk->sk_drops);
75840 }
75841
75842 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
75843 @@ -1999,7 +1999,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
75844 sk_wmem_alloc_get(s),
75845 nlk->cb,
75846 atomic_read(&s->sk_refcnt),
75847 - atomic_read(&s->sk_drops),
75848 + atomic_read_unchecked(&s->sk_drops),
75849 sock_i_ino(s)
75850 );
75851
75852 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
75853 index 732152f..60bb09e 100644
75854 --- a/net/netrom/af_netrom.c
75855 +++ b/net/netrom/af_netrom.c
75856 @@ -839,6 +839,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
75857 struct sock *sk = sock->sk;
75858 struct nr_sock *nr = nr_sk(sk);
75859
75860 + memset(sax, 0, sizeof(*sax));
75861 lock_sock(sk);
75862 if (peer != 0) {
75863 if (sk->sk_state != TCP_ESTABLISHED) {
75864 @@ -853,7 +854,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
75865 *uaddr_len = sizeof(struct full_sockaddr_ax25);
75866 } else {
75867 sax->fsa_ax25.sax25_family = AF_NETROM;
75868 - sax->fsa_ax25.sax25_ndigis = 0;
75869 sax->fsa_ax25.sax25_call = nr->source_addr;
75870 *uaddr_len = sizeof(struct sockaddr_ax25);
75871 }
75872 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
75873 index d9d4970..d5a6a68 100644
75874 --- a/net/packet/af_packet.c
75875 +++ b/net/packet/af_packet.c
75876 @@ -1675,7 +1675,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
75877
75878 spin_lock(&sk->sk_receive_queue.lock);
75879 po->stats.tp_packets++;
75880 - skb->dropcount = atomic_read(&sk->sk_drops);
75881 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75882 __skb_queue_tail(&sk->sk_receive_queue, skb);
75883 spin_unlock(&sk->sk_receive_queue.lock);
75884 sk->sk_data_ready(sk, skb->len);
75885 @@ -1684,7 +1684,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
75886 drop_n_acct:
75887 spin_lock(&sk->sk_receive_queue.lock);
75888 po->stats.tp_drops++;
75889 - atomic_inc(&sk->sk_drops);
75890 + atomic_inc_unchecked(&sk->sk_drops);
75891 spin_unlock(&sk->sk_receive_queue.lock);
75892
75893 drop_n_restore:
75894 @@ -3266,7 +3266,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
75895 case PACKET_HDRLEN:
75896 if (len > sizeof(int))
75897 len = sizeof(int);
75898 - if (copy_from_user(&val, optval, len))
75899 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
75900 return -EFAULT;
75901 switch (val) {
75902 case TPACKET_V1:
75903 @@ -3316,7 +3316,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
75904
75905 if (put_user(len, optlen))
75906 return -EFAULT;
75907 - if (copy_to_user(optval, data, len))
75908 + if (len > sizeof(st) || copy_to_user(optval, data, len))
75909 return -EFAULT;
75910 return 0;
75911 }
75912 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
75913 index d65f699..05aa6ce 100644
75914 --- a/net/phonet/af_phonet.c
75915 +++ b/net/phonet/af_phonet.c
75916 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
75917 {
75918 struct phonet_protocol *pp;
75919
75920 - if (protocol >= PHONET_NPROTO)
75921 + if (protocol < 0 || protocol >= PHONET_NPROTO)
75922 return NULL;
75923
75924 rcu_read_lock();
75925 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
75926 {
75927 int err = 0;
75928
75929 - if (protocol >= PHONET_NPROTO)
75930 + if (protocol < 0 || protocol >= PHONET_NPROTO)
75931 return -EINVAL;
75932
75933 err = proto_register(pp->prot, 1);
75934 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
75935 index 2ba6e9f..409573f 100644
75936 --- a/net/phonet/pep.c
75937 +++ b/net/phonet/pep.c
75938 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
75939
75940 case PNS_PEP_CTRL_REQ:
75941 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
75942 - atomic_inc(&sk->sk_drops);
75943 + atomic_inc_unchecked(&sk->sk_drops);
75944 break;
75945 }
75946 __skb_pull(skb, 4);
75947 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
75948 }
75949
75950 if (pn->rx_credits == 0) {
75951 - atomic_inc(&sk->sk_drops);
75952 + atomic_inc_unchecked(&sk->sk_drops);
75953 err = -ENOBUFS;
75954 break;
75955 }
75956 @@ -557,7 +557,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
75957 }
75958
75959 if (pn->rx_credits == 0) {
75960 - atomic_inc(&sk->sk_drops);
75961 + atomic_inc_unchecked(&sk->sk_drops);
75962 err = NET_RX_DROP;
75963 break;
75964 }
75965 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
75966 index 4c7eff3..59c727f 100644
75967 --- a/net/phonet/socket.c
75968 +++ b/net/phonet/socket.c
75969 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
75970 pn->resource, sk->sk_state,
75971 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
75972 sock_i_uid(sk), sock_i_ino(sk),
75973 - atomic_read(&sk->sk_refcnt), sk,
75974 - atomic_read(&sk->sk_drops), &len);
75975 + atomic_read(&sk->sk_refcnt),
75976 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75977 + NULL,
75978 +#else
75979 + sk,
75980 +#endif
75981 + atomic_read_unchecked(&sk->sk_drops), &len);
75982 }
75983 seq_printf(seq, "%*s\n", 127 - len, "");
75984 return 0;
75985 diff --git a/net/rds/cong.c b/net/rds/cong.c
75986 index e5b65ac..f3b6fb7 100644
75987 --- a/net/rds/cong.c
75988 +++ b/net/rds/cong.c
75989 @@ -78,7 +78,7 @@
75990 * finds that the saved generation number is smaller than the global generation
75991 * number, it wakes up the process.
75992 */
75993 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
75994 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
75995
75996 /*
75997 * Congestion monitoring
75998 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
75999 rdsdebug("waking map %p for %pI4\n",
76000 map, &map->m_addr);
76001 rds_stats_inc(s_cong_update_received);
76002 - atomic_inc(&rds_cong_generation);
76003 + atomic_inc_unchecked(&rds_cong_generation);
76004 if (waitqueue_active(&map->m_waitq))
76005 wake_up(&map->m_waitq);
76006 if (waitqueue_active(&rds_poll_waitq))
76007 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
76008
76009 int rds_cong_updated_since(unsigned long *recent)
76010 {
76011 - unsigned long gen = atomic_read(&rds_cong_generation);
76012 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
76013
76014 if (likely(*recent == gen))
76015 return 0;
76016 diff --git a/net/rds/ib.h b/net/rds/ib.h
76017 index edfaaaf..8c89879 100644
76018 --- a/net/rds/ib.h
76019 +++ b/net/rds/ib.h
76020 @@ -128,7 +128,7 @@ struct rds_ib_connection {
76021 /* sending acks */
76022 unsigned long i_ack_flags;
76023 #ifdef KERNEL_HAS_ATOMIC64
76024 - atomic64_t i_ack_next; /* next ACK to send */
76025 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
76026 #else
76027 spinlock_t i_ack_lock; /* protect i_ack_next */
76028 u64 i_ack_next; /* next ACK to send */
76029 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
76030 index 51c8689..36c555f 100644
76031 --- a/net/rds/ib_cm.c
76032 +++ b/net/rds/ib_cm.c
76033 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
76034 /* Clear the ACK state */
76035 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
76036 #ifdef KERNEL_HAS_ATOMIC64
76037 - atomic64_set(&ic->i_ack_next, 0);
76038 + atomic64_set_unchecked(&ic->i_ack_next, 0);
76039 #else
76040 ic->i_ack_next = 0;
76041 #endif
76042 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
76043 index e29e0ca..fa3a6a3 100644
76044 --- a/net/rds/ib_recv.c
76045 +++ b/net/rds/ib_recv.c
76046 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
76047 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
76048 int ack_required)
76049 {
76050 - atomic64_set(&ic->i_ack_next, seq);
76051 + atomic64_set_unchecked(&ic->i_ack_next, seq);
76052 if (ack_required) {
76053 smp_mb__before_clear_bit();
76054 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76055 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
76056 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76057 smp_mb__after_clear_bit();
76058
76059 - return atomic64_read(&ic->i_ack_next);
76060 + return atomic64_read_unchecked(&ic->i_ack_next);
76061 }
76062 #endif
76063
76064 diff --git a/net/rds/iw.h b/net/rds/iw.h
76065 index 04ce3b1..48119a6 100644
76066 --- a/net/rds/iw.h
76067 +++ b/net/rds/iw.h
76068 @@ -134,7 +134,7 @@ struct rds_iw_connection {
76069 /* sending acks */
76070 unsigned long i_ack_flags;
76071 #ifdef KERNEL_HAS_ATOMIC64
76072 - atomic64_t i_ack_next; /* next ACK to send */
76073 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
76074 #else
76075 spinlock_t i_ack_lock; /* protect i_ack_next */
76076 u64 i_ack_next; /* next ACK to send */
76077 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
76078 index 9556d28..f046d0e 100644
76079 --- a/net/rds/iw_cm.c
76080 +++ b/net/rds/iw_cm.c
76081 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
76082 /* Clear the ACK state */
76083 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
76084 #ifdef KERNEL_HAS_ATOMIC64
76085 - atomic64_set(&ic->i_ack_next, 0);
76086 + atomic64_set_unchecked(&ic->i_ack_next, 0);
76087 #else
76088 ic->i_ack_next = 0;
76089 #endif
76090 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
76091 index 5e57347..3916042 100644
76092 --- a/net/rds/iw_recv.c
76093 +++ b/net/rds/iw_recv.c
76094 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
76095 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
76096 int ack_required)
76097 {
76098 - atomic64_set(&ic->i_ack_next, seq);
76099 + atomic64_set_unchecked(&ic->i_ack_next, seq);
76100 if (ack_required) {
76101 smp_mb__before_clear_bit();
76102 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76103 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
76104 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76105 smp_mb__after_clear_bit();
76106
76107 - return atomic64_read(&ic->i_ack_next);
76108 + return atomic64_read_unchecked(&ic->i_ack_next);
76109 }
76110 #endif
76111
76112 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
76113 index edac9ef..16bcb98 100644
76114 --- a/net/rds/tcp.c
76115 +++ b/net/rds/tcp.c
76116 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
76117 int val = 1;
76118
76119 set_fs(KERNEL_DS);
76120 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
76121 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
76122 sizeof(val));
76123 set_fs(oldfs);
76124 }
76125 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
76126 index 1b4fd68..2234175 100644
76127 --- a/net/rds/tcp_send.c
76128 +++ b/net/rds/tcp_send.c
76129 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
76130
76131 oldfs = get_fs();
76132 set_fs(KERNEL_DS);
76133 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
76134 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
76135 sizeof(val));
76136 set_fs(oldfs);
76137 }
76138 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
76139 index 74c064c..fdec26f 100644
76140 --- a/net/rxrpc/af_rxrpc.c
76141 +++ b/net/rxrpc/af_rxrpc.c
76142 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
76143 __be32 rxrpc_epoch;
76144
76145 /* current debugging ID */
76146 -atomic_t rxrpc_debug_id;
76147 +atomic_unchecked_t rxrpc_debug_id;
76148
76149 /* count of skbs currently in use */
76150 atomic_t rxrpc_n_skbs;
76151 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
76152 index f99cfce..cc529dd 100644
76153 --- a/net/rxrpc/ar-ack.c
76154 +++ b/net/rxrpc/ar-ack.c
76155 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
76156
76157 _enter("{%d,%d,%d,%d},",
76158 call->acks_hard, call->acks_unacked,
76159 - atomic_read(&call->sequence),
76160 + atomic_read_unchecked(&call->sequence),
76161 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
76162
76163 stop = 0;
76164 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
76165
76166 /* each Tx packet has a new serial number */
76167 sp->hdr.serial =
76168 - htonl(atomic_inc_return(&call->conn->serial));
76169 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
76170
76171 hdr = (struct rxrpc_header *) txb->head;
76172 hdr->serial = sp->hdr.serial;
76173 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
76174 */
76175 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
76176 {
76177 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
76178 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
76179 }
76180
76181 /*
76182 @@ -629,7 +629,7 @@ process_further:
76183
76184 latest = ntohl(sp->hdr.serial);
76185 hard = ntohl(ack.firstPacket);
76186 - tx = atomic_read(&call->sequence);
76187 + tx = atomic_read_unchecked(&call->sequence);
76188
76189 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
76190 latest,
76191 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
76192 goto maybe_reschedule;
76193
76194 send_ACK_with_skew:
76195 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
76196 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
76197 ntohl(ack.serial));
76198 send_ACK:
76199 mtu = call->conn->trans->peer->if_mtu;
76200 @@ -1173,7 +1173,7 @@ send_ACK:
76201 ackinfo.rxMTU = htonl(5692);
76202 ackinfo.jumbo_max = htonl(4);
76203
76204 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
76205 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
76206 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
76207 ntohl(hdr.serial),
76208 ntohs(ack.maxSkew),
76209 @@ -1191,7 +1191,7 @@ send_ACK:
76210 send_message:
76211 _debug("send message");
76212
76213 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
76214 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
76215 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
76216 send_message_2:
76217
76218 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
76219 index bf656c2..48f9d27 100644
76220 --- a/net/rxrpc/ar-call.c
76221 +++ b/net/rxrpc/ar-call.c
76222 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
76223 spin_lock_init(&call->lock);
76224 rwlock_init(&call->state_lock);
76225 atomic_set(&call->usage, 1);
76226 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
76227 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76228 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
76229
76230 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
76231 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
76232 index 4106ca9..a338d7a 100644
76233 --- a/net/rxrpc/ar-connection.c
76234 +++ b/net/rxrpc/ar-connection.c
76235 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
76236 rwlock_init(&conn->lock);
76237 spin_lock_init(&conn->state_lock);
76238 atomic_set(&conn->usage, 1);
76239 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
76240 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76241 conn->avail_calls = RXRPC_MAXCALLS;
76242 conn->size_align = 4;
76243 conn->header_size = sizeof(struct rxrpc_header);
76244 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
76245 index e7ed43a..6afa140 100644
76246 --- a/net/rxrpc/ar-connevent.c
76247 +++ b/net/rxrpc/ar-connevent.c
76248 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
76249
76250 len = iov[0].iov_len + iov[1].iov_len;
76251
76252 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
76253 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
76254 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
76255
76256 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
76257 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
76258 index 1a2b0633..e8d1382 100644
76259 --- a/net/rxrpc/ar-input.c
76260 +++ b/net/rxrpc/ar-input.c
76261 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
76262 /* track the latest serial number on this connection for ACK packet
76263 * information */
76264 serial = ntohl(sp->hdr.serial);
76265 - hi_serial = atomic_read(&call->conn->hi_serial);
76266 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
76267 while (serial > hi_serial)
76268 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
76269 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
76270 serial);
76271
76272 /* request ACK generation for any ACK or DATA packet that requests
76273 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
76274 index 8e22bd3..f66d1c0 100644
76275 --- a/net/rxrpc/ar-internal.h
76276 +++ b/net/rxrpc/ar-internal.h
76277 @@ -272,8 +272,8 @@ struct rxrpc_connection {
76278 int error; /* error code for local abort */
76279 int debug_id; /* debug ID for printks */
76280 unsigned call_counter; /* call ID counter */
76281 - atomic_t serial; /* packet serial number counter */
76282 - atomic_t hi_serial; /* highest serial number received */
76283 + atomic_unchecked_t serial; /* packet serial number counter */
76284 + atomic_unchecked_t hi_serial; /* highest serial number received */
76285 u8 avail_calls; /* number of calls available */
76286 u8 size_align; /* data size alignment (for security) */
76287 u8 header_size; /* rxrpc + security header size */
76288 @@ -346,7 +346,7 @@ struct rxrpc_call {
76289 spinlock_t lock;
76290 rwlock_t state_lock; /* lock for state transition */
76291 atomic_t usage;
76292 - atomic_t sequence; /* Tx data packet sequence counter */
76293 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
76294 u32 abort_code; /* local/remote abort code */
76295 enum { /* current state of call */
76296 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
76297 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
76298 */
76299 extern atomic_t rxrpc_n_skbs;
76300 extern __be32 rxrpc_epoch;
76301 -extern atomic_t rxrpc_debug_id;
76302 +extern atomic_unchecked_t rxrpc_debug_id;
76303 extern struct workqueue_struct *rxrpc_workqueue;
76304
76305 /*
76306 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
76307 index 87f7135..74d3703 100644
76308 --- a/net/rxrpc/ar-local.c
76309 +++ b/net/rxrpc/ar-local.c
76310 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
76311 spin_lock_init(&local->lock);
76312 rwlock_init(&local->services_lock);
76313 atomic_set(&local->usage, 1);
76314 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
76315 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76316 memcpy(&local->srx, srx, sizeof(*srx));
76317 }
76318
76319 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
76320 index 338d793..47391d0 100644
76321 --- a/net/rxrpc/ar-output.c
76322 +++ b/net/rxrpc/ar-output.c
76323 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
76324 sp->hdr.cid = call->cid;
76325 sp->hdr.callNumber = call->call_id;
76326 sp->hdr.seq =
76327 - htonl(atomic_inc_return(&call->sequence));
76328 + htonl(atomic_inc_return_unchecked(&call->sequence));
76329 sp->hdr.serial =
76330 - htonl(atomic_inc_return(&conn->serial));
76331 + htonl(atomic_inc_return_unchecked(&conn->serial));
76332 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
76333 sp->hdr.userStatus = 0;
76334 sp->hdr.securityIndex = conn->security_ix;
76335 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
76336 index 2754f09..b20e38f 100644
76337 --- a/net/rxrpc/ar-peer.c
76338 +++ b/net/rxrpc/ar-peer.c
76339 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
76340 INIT_LIST_HEAD(&peer->error_targets);
76341 spin_lock_init(&peer->lock);
76342 atomic_set(&peer->usage, 1);
76343 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
76344 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76345 memcpy(&peer->srx, srx, sizeof(*srx));
76346
76347 rxrpc_assess_MTU_size(peer);
76348 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
76349 index 38047f7..9f48511 100644
76350 --- a/net/rxrpc/ar-proc.c
76351 +++ b/net/rxrpc/ar-proc.c
76352 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
76353 atomic_read(&conn->usage),
76354 rxrpc_conn_states[conn->state],
76355 key_serial(conn->key),
76356 - atomic_read(&conn->serial),
76357 - atomic_read(&conn->hi_serial));
76358 + atomic_read_unchecked(&conn->serial),
76359 + atomic_read_unchecked(&conn->hi_serial));
76360
76361 return 0;
76362 }
76363 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
76364 index 92df566..87ec1bf 100644
76365 --- a/net/rxrpc/ar-transport.c
76366 +++ b/net/rxrpc/ar-transport.c
76367 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
76368 spin_lock_init(&trans->client_lock);
76369 rwlock_init(&trans->conn_lock);
76370 atomic_set(&trans->usage, 1);
76371 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
76372 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76373
76374 if (peer->srx.transport.family == AF_INET) {
76375 switch (peer->srx.transport_type) {
76376 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
76377 index 7635107..4670276 100644
76378 --- a/net/rxrpc/rxkad.c
76379 +++ b/net/rxrpc/rxkad.c
76380 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
76381
76382 len = iov[0].iov_len + iov[1].iov_len;
76383
76384 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
76385 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
76386 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
76387
76388 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
76389 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
76390
76391 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
76392
76393 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
76394 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
76395 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
76396
76397 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
76398 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
76399 index 1e2eee8..ce3967e 100644
76400 --- a/net/sctp/proc.c
76401 +++ b/net/sctp/proc.c
76402 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
76403 seq_printf(seq,
76404 "%8pK %8pK %-3d %-3d %-2d %-4d "
76405 "%4d %8d %8d %7d %5lu %-5d %5d ",
76406 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
76407 + assoc, sk,
76408 + sctp_sk(sk)->type, sk->sk_state,
76409 assoc->state, hash,
76410 assoc->assoc_id,
76411 assoc->sndbuf_used,
76412 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
76413 index 54a7cd2..944edae 100644
76414 --- a/net/sctp/socket.c
76415 +++ b/net/sctp/socket.c
76416 @@ -4574,7 +4574,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
76417 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
76418 if (space_left < addrlen)
76419 return -ENOMEM;
76420 - if (copy_to_user(to, &temp, addrlen))
76421 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
76422 return -EFAULT;
76423 to += addrlen;
76424 cnt++;
76425 diff --git a/net/socket.c b/net/socket.c
76426 index 2dce67a..1e91168 100644
76427 --- a/net/socket.c
76428 +++ b/net/socket.c
76429 @@ -88,6 +88,7 @@
76430 #include <linux/nsproxy.h>
76431 #include <linux/magic.h>
76432 #include <linux/slab.h>
76433 +#include <linux/in.h>
76434
76435 #include <asm/uaccess.h>
76436 #include <asm/unistd.h>
76437 @@ -105,6 +106,8 @@
76438 #include <linux/sockios.h>
76439 #include <linux/atalk.h>
76440
76441 +#include <linux/grsock.h>
76442 +
76443 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
76444 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
76445 unsigned long nr_segs, loff_t pos);
76446 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
76447 &sockfs_dentry_operations, SOCKFS_MAGIC);
76448 }
76449
76450 -static struct vfsmount *sock_mnt __read_mostly;
76451 +struct vfsmount *sock_mnt __read_mostly;
76452
76453 static struct file_system_type sock_fs_type = {
76454 .name = "sockfs",
76455 @@ -1187,6 +1190,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
76456 return -EAFNOSUPPORT;
76457 if (type < 0 || type >= SOCK_MAX)
76458 return -EINVAL;
76459 + if (protocol < 0)
76460 + return -EINVAL;
76461
76462 /* Compatibility.
76463
76464 @@ -1319,6 +1324,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
76465 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
76466 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
76467
76468 + if(!gr_search_socket(family, type, protocol)) {
76469 + retval = -EACCES;
76470 + goto out;
76471 + }
76472 +
76473 + if (gr_handle_sock_all(family, type, protocol)) {
76474 + retval = -EACCES;
76475 + goto out;
76476 + }
76477 +
76478 retval = sock_create(family, type, protocol, &sock);
76479 if (retval < 0)
76480 goto out;
76481 @@ -1431,6 +1446,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
76482 if (sock) {
76483 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
76484 if (err >= 0) {
76485 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
76486 + err = -EACCES;
76487 + goto error;
76488 + }
76489 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
76490 + if (err)
76491 + goto error;
76492 +
76493 err = security_socket_bind(sock,
76494 (struct sockaddr *)&address,
76495 addrlen);
76496 @@ -1439,6 +1462,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
76497 (struct sockaddr *)
76498 &address, addrlen);
76499 }
76500 +error:
76501 fput_light(sock->file, fput_needed);
76502 }
76503 return err;
76504 @@ -1462,10 +1486,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
76505 if ((unsigned)backlog > somaxconn)
76506 backlog = somaxconn;
76507
76508 + if (gr_handle_sock_server_other(sock->sk)) {
76509 + err = -EPERM;
76510 + goto error;
76511 + }
76512 +
76513 + err = gr_search_listen(sock);
76514 + if (err)
76515 + goto error;
76516 +
76517 err = security_socket_listen(sock, backlog);
76518 if (!err)
76519 err = sock->ops->listen(sock, backlog);
76520
76521 +error:
76522 fput_light(sock->file, fput_needed);
76523 }
76524 return err;
76525 @@ -1509,6 +1543,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
76526 newsock->type = sock->type;
76527 newsock->ops = sock->ops;
76528
76529 + if (gr_handle_sock_server_other(sock->sk)) {
76530 + err = -EPERM;
76531 + sock_release(newsock);
76532 + goto out_put;
76533 + }
76534 +
76535 + err = gr_search_accept(sock);
76536 + if (err) {
76537 + sock_release(newsock);
76538 + goto out_put;
76539 + }
76540 +
76541 /*
76542 * We don't need try_module_get here, as the listening socket (sock)
76543 * has the protocol module (sock->ops->owner) held.
76544 @@ -1547,6 +1593,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
76545 fd_install(newfd, newfile);
76546 err = newfd;
76547
76548 + gr_attach_curr_ip(newsock->sk);
76549 +
76550 out_put:
76551 fput_light(sock->file, fput_needed);
76552 out:
76553 @@ -1579,6 +1627,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
76554 int, addrlen)
76555 {
76556 struct socket *sock;
76557 + struct sockaddr *sck;
76558 struct sockaddr_storage address;
76559 int err, fput_needed;
76560
76561 @@ -1589,6 +1638,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
76562 if (err < 0)
76563 goto out_put;
76564
76565 + sck = (struct sockaddr *)&address;
76566 +
76567 + if (gr_handle_sock_client(sck)) {
76568 + err = -EACCES;
76569 + goto out_put;
76570 + }
76571 +
76572 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
76573 + if (err)
76574 + goto out_put;
76575 +
76576 err =
76577 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
76578 if (err)
76579 @@ -1950,7 +2010,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
76580 * checking falls down on this.
76581 */
76582 if (copy_from_user(ctl_buf,
76583 - (void __user __force *)msg_sys->msg_control,
76584 + (void __force_user *)msg_sys->msg_control,
76585 ctl_len))
76586 goto out_freectl;
76587 msg_sys->msg_control = ctl_buf;
76588 @@ -2120,7 +2180,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
76589 * kernel msghdr to use the kernel address space)
76590 */
76591
76592 - uaddr = (__force void __user *)msg_sys->msg_name;
76593 + uaddr = (void __force_user *)msg_sys->msg_name;
76594 uaddr_len = COMPAT_NAMELEN(msg);
76595 if (MSG_CMSG_COMPAT & flags) {
76596 err = verify_compat_iovec(msg_sys, iov,
76597 @@ -2748,7 +2808,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
76598 }
76599
76600 ifr = compat_alloc_user_space(buf_size);
76601 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
76602 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
76603
76604 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
76605 return -EFAULT;
76606 @@ -2772,12 +2832,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
76607 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
76608
76609 if (copy_in_user(rxnfc, compat_rxnfc,
76610 - (void *)(&rxnfc->fs.m_ext + 1) -
76611 - (void *)rxnfc) ||
76612 + (void __user *)(&rxnfc->fs.m_ext + 1) -
76613 + (void __user *)rxnfc) ||
76614 copy_in_user(&rxnfc->fs.ring_cookie,
76615 &compat_rxnfc->fs.ring_cookie,
76616 - (void *)(&rxnfc->fs.location + 1) -
76617 - (void *)&rxnfc->fs.ring_cookie) ||
76618 + (void __user *)(&rxnfc->fs.location + 1) -
76619 + (void __user *)&rxnfc->fs.ring_cookie) ||
76620 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
76621 sizeof(rxnfc->rule_cnt)))
76622 return -EFAULT;
76623 @@ -2789,12 +2849,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
76624
76625 if (convert_out) {
76626 if (copy_in_user(compat_rxnfc, rxnfc,
76627 - (const void *)(&rxnfc->fs.m_ext + 1) -
76628 - (const void *)rxnfc) ||
76629 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
76630 + (const void __user *)rxnfc) ||
76631 copy_in_user(&compat_rxnfc->fs.ring_cookie,
76632 &rxnfc->fs.ring_cookie,
76633 - (const void *)(&rxnfc->fs.location + 1) -
76634 - (const void *)&rxnfc->fs.ring_cookie) ||
76635 + (const void __user *)(&rxnfc->fs.location + 1) -
76636 + (const void __user *)&rxnfc->fs.ring_cookie) ||
76637 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
76638 sizeof(rxnfc->rule_cnt)))
76639 return -EFAULT;
76640 @@ -2864,7 +2924,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
76641 old_fs = get_fs();
76642 set_fs(KERNEL_DS);
76643 err = dev_ioctl(net, cmd,
76644 - (struct ifreq __user __force *) &kifr);
76645 + (struct ifreq __force_user *) &kifr);
76646 set_fs(old_fs);
76647
76648 return err;
76649 @@ -2973,7 +3033,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
76650
76651 old_fs = get_fs();
76652 set_fs(KERNEL_DS);
76653 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
76654 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
76655 set_fs(old_fs);
76656
76657 if (cmd == SIOCGIFMAP && !err) {
76658 @@ -3078,7 +3138,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
76659 ret |= __get_user(rtdev, &(ur4->rt_dev));
76660 if (rtdev) {
76661 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
76662 - r4.rt_dev = (char __user __force *)devname;
76663 + r4.rt_dev = (char __force_user *)devname;
76664 devname[15] = 0;
76665 } else
76666 r4.rt_dev = NULL;
76667 @@ -3318,8 +3378,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
76668 int __user *uoptlen;
76669 int err;
76670
76671 - uoptval = (char __user __force *) optval;
76672 - uoptlen = (int __user __force *) optlen;
76673 + uoptval = (char __force_user *) optval;
76674 + uoptlen = (int __force_user *) optlen;
76675
76676 set_fs(KERNEL_DS);
76677 if (level == SOL_SOCKET)
76678 @@ -3339,7 +3399,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
76679 char __user *uoptval;
76680 int err;
76681
76682 - uoptval = (char __user __force *) optval;
76683 + uoptval = (char __force_user *) optval;
76684
76685 set_fs(KERNEL_DS);
76686 if (level == SOL_SOCKET)
76687 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
76688 index 00a1a2a..6a0138a 100644
76689 --- a/net/sunrpc/sched.c
76690 +++ b/net/sunrpc/sched.c
76691 @@ -238,9 +238,9 @@ static int rpc_wait_bit_killable(void *word)
76692 #ifdef RPC_DEBUG
76693 static void rpc_task_set_debuginfo(struct rpc_task *task)
76694 {
76695 - static atomic_t rpc_pid;
76696 + static atomic_unchecked_t rpc_pid;
76697
76698 - task->tk_pid = atomic_inc_return(&rpc_pid);
76699 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
76700 }
76701 #else
76702 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
76703 diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
76704 index 71bed1c..5dff36d 100644
76705 --- a/net/sunrpc/svcsock.c
76706 +++ b/net/sunrpc/svcsock.c
76707 @@ -396,7 +396,7 @@ static int svc_partial_recvfrom(struct svc_rqst *rqstp,
76708 int buflen, unsigned int base)
76709 {
76710 size_t save_iovlen;
76711 - void __user *save_iovbase;
76712 + void *save_iovbase;
76713 unsigned int i;
76714 int ret;
76715
76716 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
76717 index 09af4fa..77110a9 100644
76718 --- a/net/sunrpc/xprtrdma/svc_rdma.c
76719 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
76720 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
76721 static unsigned int min_max_inline = 4096;
76722 static unsigned int max_max_inline = 65536;
76723
76724 -atomic_t rdma_stat_recv;
76725 -atomic_t rdma_stat_read;
76726 -atomic_t rdma_stat_write;
76727 -atomic_t rdma_stat_sq_starve;
76728 -atomic_t rdma_stat_rq_starve;
76729 -atomic_t rdma_stat_rq_poll;
76730 -atomic_t rdma_stat_rq_prod;
76731 -atomic_t rdma_stat_sq_poll;
76732 -atomic_t rdma_stat_sq_prod;
76733 +atomic_unchecked_t rdma_stat_recv;
76734 +atomic_unchecked_t rdma_stat_read;
76735 +atomic_unchecked_t rdma_stat_write;
76736 +atomic_unchecked_t rdma_stat_sq_starve;
76737 +atomic_unchecked_t rdma_stat_rq_starve;
76738 +atomic_unchecked_t rdma_stat_rq_poll;
76739 +atomic_unchecked_t rdma_stat_rq_prod;
76740 +atomic_unchecked_t rdma_stat_sq_poll;
76741 +atomic_unchecked_t rdma_stat_sq_prod;
76742
76743 /* Temporary NFS request map and context caches */
76744 struct kmem_cache *svc_rdma_map_cachep;
76745 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *table, int write,
76746 len -= *ppos;
76747 if (len > *lenp)
76748 len = *lenp;
76749 - if (len && copy_to_user(buffer, str_buf, len))
76750 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
76751 return -EFAULT;
76752 *lenp = len;
76753 *ppos += len;
76754 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] = {
76755 {
76756 .procname = "rdma_stat_read",
76757 .data = &rdma_stat_read,
76758 - .maxlen = sizeof(atomic_t),
76759 + .maxlen = sizeof(atomic_unchecked_t),
76760 .mode = 0644,
76761 .proc_handler = read_reset_stat,
76762 },
76763 {
76764 .procname = "rdma_stat_recv",
76765 .data = &rdma_stat_recv,
76766 - .maxlen = sizeof(atomic_t),
76767 + .maxlen = sizeof(atomic_unchecked_t),
76768 .mode = 0644,
76769 .proc_handler = read_reset_stat,
76770 },
76771 {
76772 .procname = "rdma_stat_write",
76773 .data = &rdma_stat_write,
76774 - .maxlen = sizeof(atomic_t),
76775 + .maxlen = sizeof(atomic_unchecked_t),
76776 .mode = 0644,
76777 .proc_handler = read_reset_stat,
76778 },
76779 {
76780 .procname = "rdma_stat_sq_starve",
76781 .data = &rdma_stat_sq_starve,
76782 - .maxlen = sizeof(atomic_t),
76783 + .maxlen = sizeof(atomic_unchecked_t),
76784 .mode = 0644,
76785 .proc_handler = read_reset_stat,
76786 },
76787 {
76788 .procname = "rdma_stat_rq_starve",
76789 .data = &rdma_stat_rq_starve,
76790 - .maxlen = sizeof(atomic_t),
76791 + .maxlen = sizeof(atomic_unchecked_t),
76792 .mode = 0644,
76793 .proc_handler = read_reset_stat,
76794 },
76795 {
76796 .procname = "rdma_stat_rq_poll",
76797 .data = &rdma_stat_rq_poll,
76798 - .maxlen = sizeof(atomic_t),
76799 + .maxlen = sizeof(atomic_unchecked_t),
76800 .mode = 0644,
76801 .proc_handler = read_reset_stat,
76802 },
76803 {
76804 .procname = "rdma_stat_rq_prod",
76805 .data = &rdma_stat_rq_prod,
76806 - .maxlen = sizeof(atomic_t),
76807 + .maxlen = sizeof(atomic_unchecked_t),
76808 .mode = 0644,
76809 .proc_handler = read_reset_stat,
76810 },
76811 {
76812 .procname = "rdma_stat_sq_poll",
76813 .data = &rdma_stat_sq_poll,
76814 - .maxlen = sizeof(atomic_t),
76815 + .maxlen = sizeof(atomic_unchecked_t),
76816 .mode = 0644,
76817 .proc_handler = read_reset_stat,
76818 },
76819 {
76820 .procname = "rdma_stat_sq_prod",
76821 .data = &rdma_stat_sq_prod,
76822 - .maxlen = sizeof(atomic_t),
76823 + .maxlen = sizeof(atomic_unchecked_t),
76824 .mode = 0644,
76825 .proc_handler = read_reset_stat,
76826 },
76827 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
76828 index df67211..c354b13 100644
76829 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
76830 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
76831 @@ -499,7 +499,7 @@ next_sge:
76832 svc_rdma_put_context(ctxt, 0);
76833 goto out;
76834 }
76835 - atomic_inc(&rdma_stat_read);
76836 + atomic_inc_unchecked(&rdma_stat_read);
76837
76838 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
76839 chl_map->ch[ch_no].count -= read_wr.num_sge;
76840 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
76841 dto_q);
76842 list_del_init(&ctxt->dto_q);
76843 } else {
76844 - atomic_inc(&rdma_stat_rq_starve);
76845 + atomic_inc_unchecked(&rdma_stat_rq_starve);
76846 clear_bit(XPT_DATA, &xprt->xpt_flags);
76847 ctxt = NULL;
76848 }
76849 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
76850 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
76851 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
76852 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
76853 - atomic_inc(&rdma_stat_recv);
76854 + atomic_inc_unchecked(&rdma_stat_recv);
76855
76856 /* Build up the XDR from the receive buffers. */
76857 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
76858 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
76859 index 249a835..fb2794b 100644
76860 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
76861 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
76862 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
76863 write_wr.wr.rdma.remote_addr = to;
76864
76865 /* Post It */
76866 - atomic_inc(&rdma_stat_write);
76867 + atomic_inc_unchecked(&rdma_stat_write);
76868 if (svc_rdma_send(xprt, &write_wr))
76869 goto err;
76870 return 0;
76871 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
76872 index ba1296d..0fec1a5 100644
76873 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
76874 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
76875 @@ -300,7 +300,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
76876 return;
76877
76878 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
76879 - atomic_inc(&rdma_stat_rq_poll);
76880 + atomic_inc_unchecked(&rdma_stat_rq_poll);
76881
76882 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
76883 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
76884 @@ -322,7 +322,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
76885 }
76886
76887 if (ctxt)
76888 - atomic_inc(&rdma_stat_rq_prod);
76889 + atomic_inc_unchecked(&rdma_stat_rq_prod);
76890
76891 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
76892 /*
76893 @@ -394,7 +394,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
76894 return;
76895
76896 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
76897 - atomic_inc(&rdma_stat_sq_poll);
76898 + atomic_inc_unchecked(&rdma_stat_sq_poll);
76899 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
76900 if (wc.status != IB_WC_SUCCESS)
76901 /* Close the transport */
76902 @@ -412,7 +412,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
76903 }
76904
76905 if (ctxt)
76906 - atomic_inc(&rdma_stat_sq_prod);
76907 + atomic_inc_unchecked(&rdma_stat_sq_prod);
76908 }
76909
76910 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
76911 @@ -1274,7 +1274,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
76912 spin_lock_bh(&xprt->sc_lock);
76913 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
76914 spin_unlock_bh(&xprt->sc_lock);
76915 - atomic_inc(&rdma_stat_sq_starve);
76916 + atomic_inc_unchecked(&rdma_stat_sq_starve);
76917
76918 /* See if we can opportunistically reap SQ WR to make room */
76919 sq_cq_reap(xprt);
76920 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
76921 index e758139..d29ea47 100644
76922 --- a/net/sysctl_net.c
76923 +++ b/net/sysctl_net.c
76924 @@ -47,7 +47,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
76925 struct ctl_table *table)
76926 {
76927 /* Allow network administrator to have same access as root. */
76928 - if (capable(CAP_NET_ADMIN)) {
76929 + if (capable_nolog(CAP_NET_ADMIN)) {
76930 int mode = (table->mode >> 6) & 7;
76931 return (mode << 6) | (mode << 3) | mode;
76932 }
76933 diff --git a/net/tipc/link.c b/net/tipc/link.c
76934 index ae98a72..7bb6056 100644
76935 --- a/net/tipc/link.c
76936 +++ b/net/tipc/link.c
76937 @@ -1203,7 +1203,7 @@ static int link_send_sections_long(struct tipc_port *sender,
76938 struct tipc_msg fragm_hdr;
76939 struct sk_buff *buf, *buf_chain, *prev;
76940 u32 fragm_crs, fragm_rest, hsz, sect_rest;
76941 - const unchar *sect_crs;
76942 + const unchar __user *sect_crs;
76943 int curr_sect;
76944 u32 fragm_no;
76945
76946 @@ -1247,7 +1247,7 @@ again:
76947
76948 if (!sect_rest) {
76949 sect_rest = msg_sect[++curr_sect].iov_len;
76950 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
76951 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
76952 }
76953
76954 if (sect_rest < fragm_rest)
76955 @@ -1266,7 +1266,7 @@ error:
76956 }
76957 } else
76958 skb_copy_to_linear_data_offset(buf, fragm_crs,
76959 - sect_crs, sz);
76960 + (const void __force_kernel *)sect_crs, sz);
76961 sect_crs += sz;
76962 sect_rest -= sz;
76963 fragm_crs += sz;
76964 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
76965 index 83d5096..dcba497 100644
76966 --- a/net/tipc/msg.c
76967 +++ b/net/tipc/msg.c
76968 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
76969 msg_sect[cnt].iov_len);
76970 else
76971 skb_copy_to_linear_data_offset(*buf, pos,
76972 - msg_sect[cnt].iov_base,
76973 + (const void __force_kernel *)msg_sect[cnt].iov_base,
76974 msg_sect[cnt].iov_len);
76975 pos += msg_sect[cnt].iov_len;
76976 }
76977 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
76978 index 1983717..4d6102c 100644
76979 --- a/net/tipc/subscr.c
76980 +++ b/net/tipc/subscr.c
76981 @@ -101,7 +101,7 @@ static void subscr_send_event(struct subscription *sub,
76982 {
76983 struct iovec msg_sect;
76984
76985 - msg_sect.iov_base = (void *)&sub->evt;
76986 + msg_sect.iov_base = (void __force_user *)&sub->evt;
76987 msg_sect.iov_len = sizeof(struct tipc_event);
76988
76989 sub->evt.event = htohl(event, sub->swap);
76990 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
76991 index d99678a..3514a21 100644
76992 --- a/net/unix/af_unix.c
76993 +++ b/net/unix/af_unix.c
76994 @@ -767,6 +767,12 @@ static struct sock *unix_find_other(struct net *net,
76995 err = -ECONNREFUSED;
76996 if (!S_ISSOCK(inode->i_mode))
76997 goto put_fail;
76998 +
76999 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
77000 + err = -EACCES;
77001 + goto put_fail;
77002 + }
77003 +
77004 u = unix_find_socket_byinode(inode);
77005 if (!u)
77006 goto put_fail;
77007 @@ -787,6 +793,13 @@ static struct sock *unix_find_other(struct net *net,
77008 if (u) {
77009 struct dentry *dentry;
77010 dentry = unix_sk(u)->dentry;
77011 +
77012 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
77013 + err = -EPERM;
77014 + sock_put(u);
77015 + goto fail;
77016 + }
77017 +
77018 if (dentry)
77019 touch_atime(unix_sk(u)->mnt, dentry);
77020 } else
77021 @@ -869,11 +882,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
77022 err = security_path_mknod(&path, dentry, mode, 0);
77023 if (err)
77024 goto out_mknod_drop_write;
77025 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
77026 + err = -EACCES;
77027 + goto out_mknod_drop_write;
77028 + }
77029 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
77030 out_mknod_drop_write:
77031 mnt_drop_write(path.mnt);
77032 if (err)
77033 goto out_mknod_dput;
77034 +
77035 + gr_handle_create(dentry, path.mnt);
77036 +
77037 mutex_unlock(&path.dentry->d_inode->i_mutex);
77038 dput(path.dentry);
77039 path.dentry = dentry;
77040 diff --git a/net/wireless/core.h b/net/wireless/core.h
77041 index b9ec306..b4a563e 100644
77042 --- a/net/wireless/core.h
77043 +++ b/net/wireless/core.h
77044 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
77045 struct mutex mtx;
77046
77047 /* rfkill support */
77048 - struct rfkill_ops rfkill_ops;
77049 + rfkill_ops_no_const rfkill_ops;
77050 struct rfkill *rfkill;
77051 struct work_struct rfkill_sync;
77052
77053 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
77054 index 0af7f54..c916d2f 100644
77055 --- a/net/wireless/wext-core.c
77056 +++ b/net/wireless/wext-core.c
77057 @@ -747,8 +747,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
77058 */
77059
77060 /* Support for very large requests */
77061 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
77062 - (user_length > descr->max_tokens)) {
77063 + if (user_length > descr->max_tokens) {
77064 /* Allow userspace to GET more than max so
77065 * we can support any size GET requests.
77066 * There is still a limit : -ENOMEM.
77067 @@ -785,22 +784,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
77068 }
77069 }
77070
77071 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
77072 - /*
77073 - * If this is a GET, but not NOMAX, it means that the extra
77074 - * data is not bounded by userspace, but by max_tokens. Thus
77075 - * set the length to max_tokens. This matches the extra data
77076 - * allocation.
77077 - * The driver should fill it with the number of tokens it
77078 - * provided, and it may check iwp->length rather than having
77079 - * knowledge of max_tokens. If the driver doesn't change the
77080 - * iwp->length, this ioctl just copies back max_token tokens
77081 - * filled with zeroes. Hopefully the driver isn't claiming
77082 - * them to be valid data.
77083 - */
77084 - iwp->length = descr->max_tokens;
77085 - }
77086 -
77087 err = handler(dev, info, (union iwreq_data *) iwp, extra);
77088
77089 iwp->length += essid_compat;
77090 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
77091 index 9049a5c..cfa6f5c 100644
77092 --- a/net/xfrm/xfrm_policy.c
77093 +++ b/net/xfrm/xfrm_policy.c
77094 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
77095 {
77096 policy->walk.dead = 1;
77097
77098 - atomic_inc(&policy->genid);
77099 + atomic_inc_unchecked(&policy->genid);
77100
77101 if (del_timer(&policy->timer))
77102 xfrm_pol_put(policy);
77103 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
77104 hlist_add_head(&policy->bydst, chain);
77105 xfrm_pol_hold(policy);
77106 net->xfrm.policy_count[dir]++;
77107 - atomic_inc(&flow_cache_genid);
77108 + atomic_inc_unchecked(&flow_cache_genid);
77109 if (delpol)
77110 __xfrm_policy_unlink(delpol, dir);
77111 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
77112 @@ -1530,7 +1530,7 @@ free_dst:
77113 goto out;
77114 }
77115
77116 -static int inline
77117 +static inline int
77118 xfrm_dst_alloc_copy(void **target, const void *src, int size)
77119 {
77120 if (!*target) {
77121 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
77122 return 0;
77123 }
77124
77125 -static int inline
77126 +static inline int
77127 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
77128 {
77129 #ifdef CONFIG_XFRM_SUB_POLICY
77130 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
77131 #endif
77132 }
77133
77134 -static int inline
77135 +static inline int
77136 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
77137 {
77138 #ifdef CONFIG_XFRM_SUB_POLICY
77139 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
77140
77141 xdst->num_pols = num_pols;
77142 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
77143 - xdst->policy_genid = atomic_read(&pols[0]->genid);
77144 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
77145
77146 return xdst;
77147 }
77148 @@ -2345,7 +2345,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
77149 if (xdst->xfrm_genid != dst->xfrm->genid)
77150 return 0;
77151 if (xdst->num_pols > 0 &&
77152 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
77153 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
77154 return 0;
77155
77156 mtu = dst_mtu(dst->child);
77157 @@ -2882,7 +2882,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
77158 sizeof(pol->xfrm_vec[i].saddr));
77159 pol->xfrm_vec[i].encap_family = mp->new_family;
77160 /* flush bundles */
77161 - atomic_inc(&pol->genid);
77162 + atomic_inc_unchecked(&pol->genid);
77163 }
77164 }
77165
77166 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
77167 index d2b366c..51ff91ebc 100644
77168 --- a/scripts/Makefile.build
77169 +++ b/scripts/Makefile.build
77170 @@ -109,7 +109,7 @@ endif
77171 endif
77172
77173 # Do not include host rules unless needed
77174 -ifneq ($(hostprogs-y)$(hostprogs-m),)
77175 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
77176 include scripts/Makefile.host
77177 endif
77178
77179 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
77180 index 686cb0d..9d653bf 100644
77181 --- a/scripts/Makefile.clean
77182 +++ b/scripts/Makefile.clean
77183 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
77184 __clean-files := $(extra-y) $(always) \
77185 $(targets) $(clean-files) \
77186 $(host-progs) \
77187 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
77188 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
77189 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
77190
77191 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
77192
77193 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
77194 index 1ac414f..a1c1451 100644
77195 --- a/scripts/Makefile.host
77196 +++ b/scripts/Makefile.host
77197 @@ -31,6 +31,7 @@
77198 # Note: Shared libraries consisting of C++ files are not supported
77199
77200 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
77201 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
77202
77203 # C code
77204 # Executables compiled from a single .c file
77205 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
77206 # Shared libaries (only .c supported)
77207 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
77208 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
77209 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
77210 # Remove .so files from "xxx-objs"
77211 host-cobjs := $(filter-out %.so,$(host-cobjs))
77212
77213 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
77214 index cb1f50c..cef2a7c 100644
77215 --- a/scripts/basic/fixdep.c
77216 +++ b/scripts/basic/fixdep.c
77217 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
77218 /*
77219 * Lookup a value in the configuration string.
77220 */
77221 -static int is_defined_config(const char *name, int len, unsigned int hash)
77222 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
77223 {
77224 struct item *aux;
77225
77226 @@ -211,10 +211,10 @@ static void clear_config(void)
77227 /*
77228 * Record the use of a CONFIG_* word.
77229 */
77230 -static void use_config(const char *m, int slen)
77231 +static void use_config(const char *m, unsigned int slen)
77232 {
77233 unsigned int hash = strhash(m, slen);
77234 - int c, i;
77235 + unsigned int c, i;
77236
77237 if (is_defined_config(m, slen, hash))
77238 return;
77239 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
77240
77241 static void parse_config_file(const char *map, size_t len)
77242 {
77243 - const int *end = (const int *) (map + len);
77244 + const unsigned int *end = (const unsigned int *) (map + len);
77245 /* start at +1, so that p can never be < map */
77246 - const int *m = (const int *) map + 1;
77247 + const unsigned int *m = (const unsigned int *) map + 1;
77248 const char *p, *q;
77249
77250 for (; m < end; m++) {
77251 @@ -406,7 +406,7 @@ static void print_deps(void)
77252 static void traps(void)
77253 {
77254 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
77255 - int *p = (int *)test;
77256 + unsigned int *p = (unsigned int *)test;
77257
77258 if (*p != INT_CONF) {
77259 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
77260 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
77261 new file mode 100644
77262 index 0000000..8729101
77263 --- /dev/null
77264 +++ b/scripts/gcc-plugin.sh
77265 @@ -0,0 +1,2 @@
77266 +#!/bin/sh
77267 +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"
77268 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
77269 index f936d1f..a66d95f 100644
77270 --- a/scripts/mod/file2alias.c
77271 +++ b/scripts/mod/file2alias.c
77272 @@ -72,7 +72,7 @@ static void device_id_check(const char *modname, const char *device_id,
77273 unsigned long size, unsigned long id_size,
77274 void *symval)
77275 {
77276 - int i;
77277 + unsigned int i;
77278
77279 if (size % id_size || size < id_size) {
77280 if (cross_build != 0)
77281 @@ -102,7 +102,7 @@ static void device_id_check(const char *modname, const char *device_id,
77282 /* USB is special because the bcdDevice can be matched against a numeric range */
77283 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
77284 static void do_usb_entry(struct usb_device_id *id,
77285 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
77286 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
77287 unsigned char range_lo, unsigned char range_hi,
77288 unsigned char max, struct module *mod)
77289 {
77290 @@ -203,7 +203,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
77291 {
77292 unsigned int devlo, devhi;
77293 unsigned char chi, clo, max;
77294 - int ndigits;
77295 + unsigned int ndigits;
77296
77297 id->match_flags = TO_NATIVE(id->match_flags);
77298 id->idVendor = TO_NATIVE(id->idVendor);
77299 @@ -437,7 +437,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
77300 for (i = 0; i < count; i++) {
77301 const char *id = (char *)devs[i].id;
77302 char acpi_id[sizeof(devs[0].id)];
77303 - int j;
77304 + unsigned int j;
77305
77306 buf_printf(&mod->dev_table_buf,
77307 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
77308 @@ -467,7 +467,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
77309
77310 for (j = 0; j < PNP_MAX_DEVICES; j++) {
77311 const char *id = (char *)card->devs[j].id;
77312 - int i2, j2;
77313 + unsigned int i2, j2;
77314 int dup = 0;
77315
77316 if (!id[0])
77317 @@ -493,7 +493,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
77318 /* add an individual alias for every device entry */
77319 if (!dup) {
77320 char acpi_id[sizeof(card->devs[0].id)];
77321 - int k;
77322 + unsigned int k;
77323
77324 buf_printf(&mod->dev_table_buf,
77325 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
77326 @@ -807,7 +807,7 @@ static void dmi_ascii_filter(char *d, const char *s)
77327 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
77328 char *alias)
77329 {
77330 - int i, j;
77331 + unsigned int i, j;
77332
77333 sprintf(alias, "dmi*");
77334
77335 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
77336 index 2bd594e..d43245e 100644
77337 --- a/scripts/mod/modpost.c
77338 +++ b/scripts/mod/modpost.c
77339 @@ -919,6 +919,7 @@ enum mismatch {
77340 ANY_INIT_TO_ANY_EXIT,
77341 ANY_EXIT_TO_ANY_INIT,
77342 EXPORT_TO_INIT_EXIT,
77343 + DATA_TO_TEXT
77344 };
77345
77346 struct sectioncheck {
77347 @@ -1027,6 +1028,12 @@ const struct sectioncheck sectioncheck[] = {
77348 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
77349 .mismatch = EXPORT_TO_INIT_EXIT,
77350 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
77351 +},
77352 +/* Do not reference code from writable data */
77353 +{
77354 + .fromsec = { DATA_SECTIONS, NULL },
77355 + .tosec = { TEXT_SECTIONS, NULL },
77356 + .mismatch = DATA_TO_TEXT
77357 }
77358 };
77359
77360 @@ -1149,10 +1156,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
77361 continue;
77362 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
77363 continue;
77364 - if (sym->st_value == addr)
77365 - return sym;
77366 /* Find a symbol nearby - addr are maybe negative */
77367 d = sym->st_value - addr;
77368 + if (d == 0)
77369 + return sym;
77370 if (d < 0)
77371 d = addr - sym->st_value;
77372 if (d < distance) {
77373 @@ -1431,6 +1438,14 @@ static void report_sec_mismatch(const char *modname,
77374 tosym, prl_to, prl_to, tosym);
77375 free(prl_to);
77376 break;
77377 + case DATA_TO_TEXT:
77378 +/*
77379 + fprintf(stderr,
77380 + "The variable %s references\n"
77381 + "the %s %s%s%s\n",
77382 + fromsym, to, sec2annotation(tosec), tosym, to_p);
77383 +*/
77384 + break;
77385 }
77386 fprintf(stderr, "\n");
77387 }
77388 @@ -1656,7 +1671,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
77389 static void check_sec_ref(struct module *mod, const char *modname,
77390 struct elf_info *elf)
77391 {
77392 - int i;
77393 + unsigned int i;
77394 Elf_Shdr *sechdrs = elf->sechdrs;
77395
77396 /* Walk through all sections */
77397 @@ -1754,7 +1769,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
77398 va_end(ap);
77399 }
77400
77401 -void buf_write(struct buffer *buf, const char *s, int len)
77402 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
77403 {
77404 if (buf->size - buf->pos < len) {
77405 buf->size += len + SZ;
77406 @@ -1972,7 +1987,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
77407 if (fstat(fileno(file), &st) < 0)
77408 goto close_write;
77409
77410 - if (st.st_size != b->pos)
77411 + if (st.st_size != (off_t)b->pos)
77412 goto close_write;
77413
77414 tmp = NOFAIL(malloc(b->pos));
77415 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
77416 index 2031119..b5433af 100644
77417 --- a/scripts/mod/modpost.h
77418 +++ b/scripts/mod/modpost.h
77419 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
77420
77421 struct buffer {
77422 char *p;
77423 - int pos;
77424 - int size;
77425 + unsigned int pos;
77426 + unsigned int size;
77427 };
77428
77429 void __attribute__((format(printf, 2, 3)))
77430 buf_printf(struct buffer *buf, const char *fmt, ...);
77431
77432 void
77433 -buf_write(struct buffer *buf, const char *s, int len);
77434 +buf_write(struct buffer *buf, const char *s, unsigned int len);
77435
77436 struct module {
77437 struct module *next;
77438 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
77439 index 9dfcd6d..099068e 100644
77440 --- a/scripts/mod/sumversion.c
77441 +++ b/scripts/mod/sumversion.c
77442 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
77443 goto out;
77444 }
77445
77446 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
77447 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
77448 warn("writing sum in %s failed: %s\n",
77449 filename, strerror(errno));
77450 goto out;
77451 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
77452 index 5c11312..72742b5 100644
77453 --- a/scripts/pnmtologo.c
77454 +++ b/scripts/pnmtologo.c
77455 @@ -237,14 +237,14 @@ static void write_header(void)
77456 fprintf(out, " * Linux logo %s\n", logoname);
77457 fputs(" */\n\n", out);
77458 fputs("#include <linux/linux_logo.h>\n\n", out);
77459 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
77460 + fprintf(out, "static unsigned char %s_data[] = {\n",
77461 logoname);
77462 }
77463
77464 static void write_footer(void)
77465 {
77466 fputs("\n};\n\n", out);
77467 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
77468 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
77469 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
77470 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
77471 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
77472 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
77473 fputs("\n};\n\n", out);
77474
77475 /* write logo clut */
77476 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
77477 + fprintf(out, "static unsigned char %s_clut[] = {\n",
77478 logoname);
77479 write_hex_cnt = 0;
77480 for (i = 0; i < logo_clutsize; i++) {
77481 diff --git a/security/Kconfig b/security/Kconfig
77482 index 51bd5a0..3a4ebd0 100644
77483 --- a/security/Kconfig
77484 +++ b/security/Kconfig
77485 @@ -4,6 +4,627 @@
77486
77487 menu "Security options"
77488
77489 +source grsecurity/Kconfig
77490 +
77491 +menu "PaX"
77492 +
77493 + config ARCH_TRACK_EXEC_LIMIT
77494 + bool
77495 +
77496 + config PAX_KERNEXEC_PLUGIN
77497 + bool
77498 +
77499 + config PAX_PER_CPU_PGD
77500 + bool
77501 +
77502 + config TASK_SIZE_MAX_SHIFT
77503 + int
77504 + depends on X86_64
77505 + default 47 if !PAX_PER_CPU_PGD
77506 + default 42 if PAX_PER_CPU_PGD
77507 +
77508 + config PAX_ENABLE_PAE
77509 + bool
77510 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
77511 +
77512 +config PAX
77513 + bool "Enable various PaX features"
77514 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
77515 + help
77516 + This allows you to enable various PaX features. PaX adds
77517 + intrusion prevention mechanisms to the kernel that reduce
77518 + the risks posed by exploitable memory corruption bugs.
77519 +
77520 +menu "PaX Control"
77521 + depends on PAX
77522 +
77523 +config PAX_SOFTMODE
77524 + bool 'Support soft mode'
77525 + help
77526 + Enabling this option will allow you to run PaX in soft mode, that
77527 + is, PaX features will not be enforced by default, only on executables
77528 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
77529 + support as they are the only way to mark executables for soft mode use.
77530 +
77531 + Soft mode can be activated by using the "pax_softmode=1" kernel command
77532 + line option on boot. Furthermore you can control various PaX features
77533 + at runtime via the entries in /proc/sys/kernel/pax.
77534 +
77535 +config PAX_EI_PAX
77536 + bool 'Use legacy ELF header marking'
77537 + help
77538 + Enabling this option will allow you to control PaX features on
77539 + a per executable basis via the 'chpax' utility available at
77540 + http://pax.grsecurity.net/. The control flags will be read from
77541 + an otherwise reserved part of the ELF header. This marking has
77542 + numerous drawbacks (no support for soft-mode, toolchain does not
77543 + know about the non-standard use of the ELF header) therefore it
77544 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
77545 + support.
77546 +
77547 + If you have applications not marked by the PT_PAX_FLAGS ELF program
77548 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
77549 + option otherwise they will not get any protection.
77550 +
77551 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
77552 + support as well, they will override the legacy EI_PAX marks.
77553 +
77554 +config PAX_PT_PAX_FLAGS
77555 + bool 'Use ELF program header marking'
77556 + help
77557 + Enabling this option will allow you to control PaX features on
77558 + a per executable basis via the 'paxctl' utility available at
77559 + http://pax.grsecurity.net/. The control flags will be read from
77560 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
77561 + has the benefits of supporting both soft mode and being fully
77562 + integrated into the toolchain (the binutils patch is available
77563 + from http://pax.grsecurity.net).
77564 +
77565 + If you have applications not marked by the PT_PAX_FLAGS ELF program
77566 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
77567 + support otherwise they will not get any protection.
77568 +
77569 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
77570 + must make sure that the marks are the same if a binary has both marks.
77571 +
77572 + Note that if you enable the legacy EI_PAX marking support as well,
77573 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
77574 +
77575 +config PAX_XATTR_PAX_FLAGS
77576 + bool 'Use filesystem extended attributes marking'
77577 + depends on EXPERT
77578 + select CIFS_XATTR if CIFS
77579 + select EXT2_FS_XATTR if EXT2_FS
77580 + select EXT3_FS_XATTR if EXT3_FS
77581 + select EXT4_FS_XATTR if EXT4_FS
77582 + select JFFS2_FS_XATTR if JFFS2_FS
77583 + select REISERFS_FS_XATTR if REISERFS_FS
77584 + select SQUASHFS_XATTR if SQUASHFS
77585 + select TMPFS_XATTR if TMPFS
77586 + select UBIFS_FS_XATTR if UBIFS_FS
77587 + help
77588 + Enabling this option will allow you to control PaX features on
77589 + a per executable basis via the 'setfattr' utility. The control
77590 + flags will be read from the user.pax.flags extended attribute of
77591 + the file. This marking has the benefit of supporting binary-only
77592 + applications that self-check themselves (e.g., skype) and would
77593 + not tolerate chpax/paxctl changes. The main drawback is that
77594 + extended attributes are not supported by some filesystems (e.g.,
77595 + isofs, udf, vfat) so copying files through such filesystems will
77596 + lose the extended attributes and these PaX markings.
77597 +
77598 + If you have applications not marked by the PT_PAX_FLAGS ELF program
77599 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
77600 + support otherwise they will not get any protection.
77601 +
77602 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
77603 + must make sure that the marks are the same if a binary has both marks.
77604 +
77605 + Note that if you enable the legacy EI_PAX marking support as well,
77606 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
77607 +
77608 +choice
77609 + prompt 'MAC system integration'
77610 + default PAX_HAVE_ACL_FLAGS
77611 + help
77612 + Mandatory Access Control systems have the option of controlling
77613 + PaX flags on a per executable basis, choose the method supported
77614 + by your particular system.
77615 +
77616 + - "none": if your MAC system does not interact with PaX,
77617 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
77618 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
77619 +
77620 + NOTE: this option is for developers/integrators only.
77621 +
77622 + config PAX_NO_ACL_FLAGS
77623 + bool 'none'
77624 +
77625 + config PAX_HAVE_ACL_FLAGS
77626 + bool 'direct'
77627 +
77628 + config PAX_HOOK_ACL_FLAGS
77629 + bool 'hook'
77630 +endchoice
77631 +
77632 +endmenu
77633 +
77634 +menu "Non-executable pages"
77635 + depends on PAX
77636 +
77637 +config PAX_NOEXEC
77638 + bool "Enforce non-executable pages"
77639 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
77640 + help
77641 + By design some architectures do not allow for protecting memory
77642 + pages against execution or even if they do, Linux does not make
77643 + use of this feature. In practice this means that if a page is
77644 + readable (such as the stack or heap) it is also executable.
77645 +
77646 + There is a well known exploit technique that makes use of this
77647 + fact and a common programming mistake where an attacker can
77648 + introduce code of his choice somewhere in the attacked program's
77649 + memory (typically the stack or the heap) and then execute it.
77650 +
77651 + If the attacked program was running with different (typically
77652 + higher) privileges than that of the attacker, then he can elevate
77653 + his own privilege level (e.g. get a root shell, write to files for
77654 + which he does not have write access to, etc).
77655 +
77656 + Enabling this option will let you choose from various features
77657 + that prevent the injection and execution of 'foreign' code in
77658 + a program.
77659 +
77660 + This will also break programs that rely on the old behaviour and
77661 + expect that dynamically allocated memory via the malloc() family
77662 + of functions is executable (which it is not). Notable examples
77663 + are the XFree86 4.x server, the java runtime and wine.
77664 +
77665 +config PAX_PAGEEXEC
77666 + bool "Paging based non-executable pages"
77667 + 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)
77668 + select S390_SWITCH_AMODE if S390
77669 + select S390_EXEC_PROTECT if S390
77670 + select ARCH_TRACK_EXEC_LIMIT if X86_32
77671 + help
77672 + This implementation is based on the paging feature of the CPU.
77673 + On i386 without hardware non-executable bit support there is a
77674 + variable but usually low performance impact, however on Intel's
77675 + P4 core based CPUs it is very high so you should not enable this
77676 + for kernels meant to be used on such CPUs.
77677 +
77678 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
77679 + with hardware non-executable bit support there is no performance
77680 + impact, on ppc the impact is negligible.
77681 +
77682 + Note that several architectures require various emulations due to
77683 + badly designed userland ABIs, this will cause a performance impact
77684 + but will disappear as soon as userland is fixed. For example, ppc
77685 + userland MUST have been built with secure-plt by a recent toolchain.
77686 +
77687 +config PAX_SEGMEXEC
77688 + bool "Segmentation based non-executable pages"
77689 + depends on PAX_NOEXEC && X86_32
77690 + help
77691 + This implementation is based on the segmentation feature of the
77692 + CPU and has a very small performance impact, however applications
77693 + will be limited to a 1.5 GB address space instead of the normal
77694 + 3 GB.
77695 +
77696 +config PAX_EMUTRAMP
77697 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
77698 + default y if PARISC
77699 + help
77700 + There are some programs and libraries that for one reason or
77701 + another attempt to execute special small code snippets from
77702 + non-executable memory pages. Most notable examples are the
77703 + signal handler return code generated by the kernel itself and
77704 + the GCC trampolines.
77705 +
77706 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
77707 + such programs will no longer work under your kernel.
77708 +
77709 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
77710 + utilities to enable trampoline emulation for the affected programs
77711 + yet still have the protection provided by the non-executable pages.
77712 +
77713 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
77714 + your system will not even boot.
77715 +
77716 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
77717 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
77718 + for the affected files.
77719 +
77720 + NOTE: enabling this feature *may* open up a loophole in the
77721 + protection provided by non-executable pages that an attacker
77722 + could abuse. Therefore the best solution is to not have any
77723 + files on your system that would require this option. This can
77724 + be achieved by not using libc5 (which relies on the kernel
77725 + signal handler return code) and not using or rewriting programs
77726 + that make use of the nested function implementation of GCC.
77727 + Skilled users can just fix GCC itself so that it implements
77728 + nested function calls in a way that does not interfere with PaX.
77729 +
77730 +config PAX_EMUSIGRT
77731 + bool "Automatically emulate sigreturn trampolines"
77732 + depends on PAX_EMUTRAMP && PARISC
77733 + default y
77734 + help
77735 + Enabling this option will have the kernel automatically detect
77736 + and emulate signal return trampolines executing on the stack
77737 + that would otherwise lead to task termination.
77738 +
77739 + This solution is intended as a temporary one for users with
77740 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
77741 + Modula-3 runtime, etc) or executables linked to such, basically
77742 + everything that does not specify its own SA_RESTORER function in
77743 + normal executable memory like glibc 2.1+ does.
77744 +
77745 + On parisc you MUST enable this option, otherwise your system will
77746 + not even boot.
77747 +
77748 + NOTE: this feature cannot be disabled on a per executable basis
77749 + and since it *does* open up a loophole in the protection provided
77750 + by non-executable pages, the best solution is to not have any
77751 + files on your system that would require this option.
77752 +
77753 +config PAX_MPROTECT
77754 + bool "Restrict mprotect()"
77755 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
77756 + help
77757 + Enabling this option will prevent programs from
77758 + - changing the executable status of memory pages that were
77759 + not originally created as executable,
77760 + - making read-only executable pages writable again,
77761 + - creating executable pages from anonymous memory,
77762 + - making read-only-after-relocations (RELRO) data pages writable again.
77763 +
77764 + You should say Y here to complete the protection provided by
77765 + the enforcement of non-executable pages.
77766 +
77767 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
77768 + this feature on a per file basis.
77769 +
77770 +config PAX_MPROTECT_COMPAT
77771 + bool "Use legacy/compat protection demoting (read help)"
77772 + depends on PAX_MPROTECT
77773 + default n
77774 + help
77775 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
77776 + by sending the proper error code to the application. For some broken
77777 + userland, this can cause problems with Python or other applications. The
77778 + current implementation however allows for applications like clamav to
77779 + detect if JIT compilation/execution is allowed and to fall back gracefully
77780 + to an interpreter-based mode if it does not. While we encourage everyone
77781 + to use the current implementation as-is and push upstream to fix broken
77782 + userland (note that the RWX logging option can assist with this), in some
77783 + environments this may not be possible. Having to disable MPROTECT
77784 + completely on certain binaries reduces the security benefit of PaX,
77785 + so this option is provided for those environments to revert to the old
77786 + behavior.
77787 +
77788 +config PAX_ELFRELOCS
77789 + bool "Allow ELF text relocations (read help)"
77790 + depends on PAX_MPROTECT
77791 + default n
77792 + help
77793 + Non-executable pages and mprotect() restrictions are effective
77794 + in preventing the introduction of new executable code into an
77795 + attacked task's address space. There remain only two venues
77796 + for this kind of attack: if the attacker can execute already
77797 + existing code in the attacked task then he can either have it
77798 + create and mmap() a file containing his code or have it mmap()
77799 + an already existing ELF library that does not have position
77800 + independent code in it and use mprotect() on it to make it
77801 + writable and copy his code there. While protecting against
77802 + the former approach is beyond PaX, the latter can be prevented
77803 + by having only PIC ELF libraries on one's system (which do not
77804 + need to relocate their code). If you are sure this is your case,
77805 + as is the case with all modern Linux distributions, then leave
77806 + this option disabled. You should say 'n' here.
77807 +
77808 +config PAX_ETEXECRELOCS
77809 + bool "Allow ELF ET_EXEC text relocations"
77810 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
77811 + select PAX_ELFRELOCS
77812 + default y
77813 + help
77814 + On some architectures there are incorrectly created applications
77815 + that require text relocations and would not work without enabling
77816 + this option. If you are an alpha, ia64 or parisc user, you should
77817 + enable this option and disable it once you have made sure that
77818 + none of your applications need it.
77819 +
77820 +config PAX_EMUPLT
77821 + bool "Automatically emulate ELF PLT"
77822 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
77823 + default y
77824 + help
77825 + Enabling this option will have the kernel automatically detect
77826 + and emulate the Procedure Linkage Table entries in ELF files.
77827 + On some architectures such entries are in writable memory, and
77828 + become non-executable leading to task termination. Therefore
77829 + it is mandatory that you enable this option on alpha, parisc,
77830 + sparc and sparc64, otherwise your system would not even boot.
77831 +
77832 + NOTE: this feature *does* open up a loophole in the protection
77833 + provided by the non-executable pages, therefore the proper
77834 + solution is to modify the toolchain to produce a PLT that does
77835 + not need to be writable.
77836 +
77837 +config PAX_DLRESOLVE
77838 + bool 'Emulate old glibc resolver stub'
77839 + depends on PAX_EMUPLT && SPARC
77840 + default n
77841 + help
77842 + This option is needed if userland has an old glibc (before 2.4)
77843 + that puts a 'save' instruction into the runtime generated resolver
77844 + stub that needs special emulation.
77845 +
77846 +config PAX_KERNEXEC
77847 + bool "Enforce non-executable kernel pages"
77848 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
77849 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
77850 + select PAX_KERNEXEC_PLUGIN if X86_64
77851 + help
77852 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
77853 + that is, enabling this option will make it harder to inject
77854 + and execute 'foreign' code in kernel memory itself.
77855 +
77856 + Note that on x86_64 kernels there is a known regression when
77857 + this feature and KVM/VMX are both enabled in the host kernel.
77858 +
77859 +choice
77860 + prompt "Return Address Instrumentation Method"
77861 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
77862 + depends on PAX_KERNEXEC_PLUGIN
77863 + help
77864 + Select the method used to instrument function pointer dereferences.
77865 + Note that binary modules cannot be instrumented by this approach.
77866 +
77867 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
77868 + bool "bts"
77869 + help
77870 + This method is compatible with binary only modules but has
77871 + a higher runtime overhead.
77872 +
77873 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
77874 + bool "or"
77875 + depends on !PARAVIRT
77876 + help
77877 + This method is incompatible with binary only modules but has
77878 + a lower runtime overhead.
77879 +endchoice
77880 +
77881 +config PAX_KERNEXEC_PLUGIN_METHOD
77882 + string
77883 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
77884 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
77885 + default ""
77886 +
77887 +config PAX_KERNEXEC_MODULE_TEXT
77888 + int "Minimum amount of memory reserved for module code"
77889 + default "4"
77890 + depends on PAX_KERNEXEC && X86_32 && MODULES
77891 + help
77892 + Due to implementation details the kernel must reserve a fixed
77893 + amount of memory for module code at compile time that cannot be
77894 + changed at runtime. Here you can specify the minimum amount
77895 + in MB that will be reserved. Due to the same implementation
77896 + details this size will always be rounded up to the next 2/4 MB
77897 + boundary (depends on PAE) so the actually available memory for
77898 + module code will usually be more than this minimum.
77899 +
77900 + The default 4 MB should be enough for most users but if you have
77901 + an excessive number of modules (e.g., most distribution configs
77902 + compile many drivers as modules) or use huge modules such as
77903 + nvidia's kernel driver, you will need to adjust this amount.
77904 + A good rule of thumb is to look at your currently loaded kernel
77905 + modules and add up their sizes.
77906 +
77907 +endmenu
77908 +
77909 +menu "Address Space Layout Randomization"
77910 + depends on PAX
77911 +
77912 +config PAX_ASLR
77913 + bool "Address Space Layout Randomization"
77914 + help
77915 + Many if not most exploit techniques rely on the knowledge of
77916 + certain addresses in the attacked program. The following options
77917 + will allow the kernel to apply a certain amount of randomization
77918 + to specific parts of the program thereby forcing an attacker to
77919 + guess them in most cases. Any failed guess will most likely crash
77920 + the attacked program which allows the kernel to detect such attempts
77921 + and react on them. PaX itself provides no reaction mechanisms,
77922 + instead it is strongly encouraged that you make use of Nergal's
77923 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
77924 + (http://www.grsecurity.net/) built-in crash detection features or
77925 + develop one yourself.
77926 +
77927 + By saying Y here you can choose to randomize the following areas:
77928 + - top of the task's kernel stack
77929 + - top of the task's userland stack
77930 + - base address for mmap() requests that do not specify one
77931 + (this includes all libraries)
77932 + - base address of the main executable
77933 +
77934 + It is strongly recommended to say Y here as address space layout
77935 + randomization has negligible impact on performance yet it provides
77936 + a very effective protection.
77937 +
77938 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
77939 + this feature on a per file basis.
77940 +
77941 +config PAX_RANDKSTACK
77942 + bool "Randomize kernel stack base"
77943 + depends on X86_TSC && X86
77944 + help
77945 + By saying Y here the kernel will randomize every task's kernel
77946 + stack on every system call. This will not only force an attacker
77947 + to guess it but also prevent him from making use of possible
77948 + leaked information about it.
77949 +
77950 + Since the kernel stack is a rather scarce resource, randomization
77951 + may cause unexpected stack overflows, therefore you should very
77952 + carefully test your system. Note that once enabled in the kernel
77953 + configuration, this feature cannot be disabled on a per file basis.
77954 +
77955 +config PAX_RANDUSTACK
77956 + bool "Randomize user stack base"
77957 + depends on PAX_ASLR
77958 + help
77959 + By saying Y here the kernel will randomize every task's userland
77960 + stack. The randomization is done in two steps where the second
77961 + one may apply a big amount of shift to the top of the stack and
77962 + cause problems for programs that want to use lots of memory (more
77963 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
77964 + For this reason the second step can be controlled by 'chpax' or
77965 + 'paxctl' on a per file basis.
77966 +
77967 +config PAX_RANDMMAP
77968 + bool "Randomize mmap() base"
77969 + depends on PAX_ASLR
77970 + help
77971 + By saying Y here the kernel will use a randomized base address for
77972 + mmap() requests that do not specify one themselves. As a result
77973 + all dynamically loaded libraries will appear at random addresses
77974 + and therefore be harder to exploit by a technique where an attacker
77975 + attempts to execute library code for his purposes (e.g. spawn a
77976 + shell from an exploited program that is running at an elevated
77977 + privilege level).
77978 +
77979 + Furthermore, if a program is relinked as a dynamic ELF file, its
77980 + base address will be randomized as well, completing the full
77981 + randomization of the address space layout. Attacking such programs
77982 + becomes a guess game. You can find an example of doing this at
77983 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
77984 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
77985 +
77986 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
77987 + feature on a per file basis.
77988 +
77989 +endmenu
77990 +
77991 +menu "Miscellaneous hardening features"
77992 +
77993 +config PAX_MEMORY_SANITIZE
77994 + bool "Sanitize all freed memory"
77995 + depends on !HIBERNATION
77996 + help
77997 + By saying Y here the kernel will erase memory pages as soon as they
77998 + are freed. This in turn reduces the lifetime of data stored in the
77999 + pages, making it less likely that sensitive information such as
78000 + passwords, cryptographic secrets, etc stay in memory for too long.
78001 +
78002 + This is especially useful for programs whose runtime is short, long
78003 + lived processes and the kernel itself benefit from this as long as
78004 + they operate on whole memory pages and ensure timely freeing of pages
78005 + that may hold sensitive information.
78006 +
78007 + The tradeoff is performance impact, on a single CPU system kernel
78008 + compilation sees a 3% slowdown, other systems and workloads may vary
78009 + and you are advised to test this feature on your expected workload
78010 + before deploying it.
78011 +
78012 + Note that this feature does not protect data stored in live pages,
78013 + e.g., process memory swapped to disk may stay there for a long time.
78014 +
78015 +config PAX_MEMORY_STACKLEAK
78016 + bool "Sanitize kernel stack"
78017 + depends on X86
78018 + help
78019 + By saying Y here the kernel will erase the kernel stack before it
78020 + returns from a system call. This in turn reduces the information
78021 + that a kernel stack leak bug can reveal.
78022 +
78023 + Note that such a bug can still leak information that was put on
78024 + the stack by the current system call (the one eventually triggering
78025 + the bug) but traces of earlier system calls on the kernel stack
78026 + cannot leak anymore.
78027 +
78028 + The tradeoff is performance impact: on a single CPU system kernel
78029 + compilation sees a 1% slowdown, other systems and workloads may vary
78030 + and you are advised to test this feature on your expected workload
78031 + before deploying it.
78032 +
78033 + Note: full support for this feature requires gcc with plugin support
78034 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
78035 + versions means that functions with large enough stack frames may
78036 + leave uninitialized memory behind that may be exposed to a later
78037 + syscall leaking the stack.
78038 +
78039 +config PAX_MEMORY_UDEREF
78040 + bool "Prevent invalid userland pointer dereference"
78041 + depends on X86 && !UML_X86 && !XEN
78042 + select PAX_PER_CPU_PGD if X86_64
78043 + help
78044 + By saying Y here the kernel will be prevented from dereferencing
78045 + userland pointers in contexts where the kernel expects only kernel
78046 + pointers. This is both a useful runtime debugging feature and a
78047 + security measure that prevents exploiting a class of kernel bugs.
78048 +
78049 + The tradeoff is that some virtualization solutions may experience
78050 + a huge slowdown and therefore you should not enable this feature
78051 + for kernels meant to run in such environments. Whether a given VM
78052 + solution is affected or not is best determined by simply trying it
78053 + out, the performance impact will be obvious right on boot as this
78054 + mechanism engages from very early on. A good rule of thumb is that
78055 + VMs running on CPUs without hardware virtualization support (i.e.,
78056 + the majority of IA-32 CPUs) will likely experience the slowdown.
78057 +
78058 +config PAX_REFCOUNT
78059 + bool "Prevent various kernel object reference counter overflows"
78060 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
78061 + help
78062 + By saying Y here the kernel will detect and prevent overflowing
78063 + various (but not all) kinds of object reference counters. Such
78064 + overflows can normally occur due to bugs only and are often, if
78065 + not always, exploitable.
78066 +
78067 + The tradeoff is that data structures protected by an overflowed
78068 + refcount will never be freed and therefore will leak memory. Note
78069 + that this leak also happens even without this protection but in
78070 + that case the overflow can eventually trigger the freeing of the
78071 + data structure while it is still being used elsewhere, resulting
78072 + in the exploitable situation that this feature prevents.
78073 +
78074 + Since this has a negligible performance impact, you should enable
78075 + this feature.
78076 +
78077 +config PAX_USERCOPY
78078 + bool "Harden heap object copies between kernel and userland"
78079 + depends on X86 || PPC || SPARC || ARM
78080 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
78081 + help
78082 + By saying Y here the kernel will enforce the size of heap objects
78083 + when they are copied in either direction between the kernel and
78084 + userland, even if only a part of the heap object is copied.
78085 +
78086 + Specifically, this checking prevents information leaking from the
78087 + kernel heap during kernel to userland copies (if the kernel heap
78088 + object is otherwise fully initialized) and prevents kernel heap
78089 + overflows during userland to kernel copies.
78090 +
78091 + Note that the current implementation provides the strictest bounds
78092 + checks for the SLUB allocator.
78093 +
78094 + Enabling this option also enables per-slab cache protection against
78095 + data in a given cache being copied into/out of via userland
78096 + accessors. Though the whitelist of regions will be reduced over
78097 + time, it notably protects important data structures like task structs.
78098 +
78099 + If frame pointers are enabled on x86, this option will also restrict
78100 + copies into and out of the kernel stack to local variables within a
78101 + single frame.
78102 +
78103 + Since this has a negligible performance impact, you should enable
78104 + this feature.
78105 +
78106 +endmenu
78107 +
78108 +endmenu
78109 +
78110 config KEYS
78111 bool "Enable access key retention support"
78112 help
78113 @@ -169,7 +790,7 @@ config INTEL_TXT
78114 config LSM_MMAP_MIN_ADDR
78115 int "Low address space for LSM to protect from user allocation"
78116 depends on SECURITY && SECURITY_SELINUX
78117 - default 32768 if ARM
78118 + default 32768 if ALPHA || ARM || PARISC || SPARC32
78119 default 65536
78120 help
78121 This is the portion of low virtual memory which should be protected
78122 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
78123 index 3783202..1852837 100644
78124 --- a/security/apparmor/lsm.c
78125 +++ b/security/apparmor/lsm.c
78126 @@ -621,7 +621,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
78127 return error;
78128 }
78129
78130 -static struct security_operations apparmor_ops = {
78131 +static struct security_operations apparmor_ops __read_only = {
78132 .name = "apparmor",
78133
78134 .ptrace_access_check = apparmor_ptrace_access_check,
78135 diff --git a/security/commoncap.c b/security/commoncap.c
78136 index ee4f848..a320c64 100644
78137 --- a/security/commoncap.c
78138 +++ b/security/commoncap.c
78139 @@ -28,6 +28,7 @@
78140 #include <linux/prctl.h>
78141 #include <linux/securebits.h>
78142 #include <linux/user_namespace.h>
78143 +#include <net/sock.h>
78144
78145 /*
78146 * If a non-root user executes a setuid-root binary in
78147 @@ -58,7 +59,7 @@ int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
78148
78149 int cap_netlink_recv(struct sk_buff *skb, int cap)
78150 {
78151 - if (!cap_raised(current_cap(), cap))
78152 + if (!cap_raised(current_cap(), cap) || !gr_is_capable(cap))
78153 return -EPERM;
78154 return 0;
78155 }
78156 @@ -579,6 +580,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
78157 {
78158 const struct cred *cred = current_cred();
78159
78160 + if (gr_acl_enable_at_secure())
78161 + return 1;
78162 +
78163 if (cred->uid != 0) {
78164 if (bprm->cap_effective)
78165 return 1;
78166 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
78167 index 3ccf7ac..d73ad64 100644
78168 --- a/security/integrity/ima/ima.h
78169 +++ b/security/integrity/ima/ima.h
78170 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
78171 extern spinlock_t ima_queue_lock;
78172
78173 struct ima_h_table {
78174 - atomic_long_t len; /* number of stored measurements in the list */
78175 - atomic_long_t violations;
78176 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
78177 + atomic_long_unchecked_t violations;
78178 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
78179 };
78180 extern struct ima_h_table ima_htable;
78181 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
78182 index 88a2788..581ab92 100644
78183 --- a/security/integrity/ima/ima_api.c
78184 +++ b/security/integrity/ima/ima_api.c
78185 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
78186 int result;
78187
78188 /* can overflow, only indicator */
78189 - atomic_long_inc(&ima_htable.violations);
78190 + atomic_long_inc_unchecked(&ima_htable.violations);
78191
78192 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
78193 if (!entry) {
78194 diff --git a/security/integrity/ima/ima_audit.c b/security/integrity/ima/ima_audit.c
78195 index c5c5a72..2ad942f 100644
78196 --- a/security/integrity/ima/ima_audit.c
78197 +++ b/security/integrity/ima/ima_audit.c
78198 @@ -56,9 +56,11 @@ void integrity_audit_msg(int audit_msgno, struct inode *inode,
78199 audit_log_format(ab, " name=");
78200 audit_log_untrustedstring(ab, fname);
78201 }
78202 - if (inode)
78203 - audit_log_format(ab, " dev=%s ino=%lu",
78204 - inode->i_sb->s_id, inode->i_ino);
78205 + if (inode) {
78206 + audit_log_format(ab, " dev=");
78207 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
78208 + audit_log_format(ab, " ino=%lu", inode->i_ino);
78209 + }
78210 audit_log_format(ab, " res=%d", !result ? 0 : 1);
78211 audit_log_end(ab);
78212 }
78213 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
78214 index e1aa2b4..52027bf 100644
78215 --- a/security/integrity/ima/ima_fs.c
78216 +++ b/security/integrity/ima/ima_fs.c
78217 @@ -28,12 +28,12 @@
78218 static int valid_policy = 1;
78219 #define TMPBUFLEN 12
78220 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
78221 - loff_t *ppos, atomic_long_t *val)
78222 + loff_t *ppos, atomic_long_unchecked_t *val)
78223 {
78224 char tmpbuf[TMPBUFLEN];
78225 ssize_t len;
78226
78227 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
78228 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
78229 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
78230 }
78231
78232 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
78233 index 55a6271..ad829c3 100644
78234 --- a/security/integrity/ima/ima_queue.c
78235 +++ b/security/integrity/ima/ima_queue.c
78236 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
78237 INIT_LIST_HEAD(&qe->later);
78238 list_add_tail_rcu(&qe->later, &ima_measurements);
78239
78240 - atomic_long_inc(&ima_htable.len);
78241 + atomic_long_inc_unchecked(&ima_htable.len);
78242 key = ima_hash_key(entry->digest);
78243 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
78244 return 0;
78245 diff --git a/security/keys/compat.c b/security/keys/compat.c
78246 index 4c48e13..7abdac9 100644
78247 --- a/security/keys/compat.c
78248 +++ b/security/keys/compat.c
78249 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
78250 if (ret == 0)
78251 goto no_payload_free;
78252
78253 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
78254 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
78255
78256 if (iov != iovstack)
78257 kfree(iov);
78258 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
78259 index 0b3f5d7..892c8a6 100644
78260 --- a/security/keys/keyctl.c
78261 +++ b/security/keys/keyctl.c
78262 @@ -921,7 +921,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
78263 /*
78264 * Copy the iovec data from userspace
78265 */
78266 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
78267 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
78268 unsigned ioc)
78269 {
78270 for (; ioc > 0; ioc--) {
78271 @@ -943,7 +943,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
78272 * If successful, 0 will be returned.
78273 */
78274 long keyctl_instantiate_key_common(key_serial_t id,
78275 - const struct iovec *payload_iov,
78276 + const struct iovec __user *payload_iov,
78277 unsigned ioc,
78278 size_t plen,
78279 key_serial_t ringid)
78280 @@ -1038,7 +1038,7 @@ long keyctl_instantiate_key(key_serial_t id,
78281 [0].iov_len = plen
78282 };
78283
78284 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
78285 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
78286 }
78287
78288 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
78289 @@ -1071,7 +1071,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
78290 if (ret == 0)
78291 goto no_payload_free;
78292
78293 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
78294 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
78295
78296 if (iov != iovstack)
78297 kfree(iov);
78298 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
78299 index 37a7f3b..86dc19f 100644
78300 --- a/security/keys/keyring.c
78301 +++ b/security/keys/keyring.c
78302 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
78303 ret = -EFAULT;
78304
78305 for (loop = 0; loop < klist->nkeys; loop++) {
78306 + key_serial_t serial;
78307 key = klist->keys[loop];
78308 + serial = key->serial;
78309
78310 tmp = sizeof(key_serial_t);
78311 if (tmp > buflen)
78312 tmp = buflen;
78313
78314 - if (copy_to_user(buffer,
78315 - &key->serial,
78316 - tmp) != 0)
78317 + if (copy_to_user(buffer, &serial, tmp))
78318 goto error;
78319
78320 buflen -= tmp;
78321 diff --git a/security/lsm_audit.c b/security/lsm_audit.c
78322 index 893af8a..ba9237c 100644
78323 --- a/security/lsm_audit.c
78324 +++ b/security/lsm_audit.c
78325 @@ -234,10 +234,11 @@ static void dump_common_audit_data(struct audit_buffer *ab,
78326 audit_log_d_path(ab, "path=", &a->u.path);
78327
78328 inode = a->u.path.dentry->d_inode;
78329 - if (inode)
78330 - audit_log_format(ab, " dev=%s ino=%lu",
78331 - inode->i_sb->s_id,
78332 - inode->i_ino);
78333 + if (inode) {
78334 + audit_log_format(ab, " dev=");
78335 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
78336 + audit_log_format(ab, " ino=%lu", inode->i_ino);
78337 + }
78338 break;
78339 }
78340 case LSM_AUDIT_DATA_DENTRY: {
78341 @@ -247,10 +248,11 @@ static void dump_common_audit_data(struct audit_buffer *ab,
78342 audit_log_untrustedstring(ab, a->u.dentry->d_name.name);
78343
78344 inode = a->u.dentry->d_inode;
78345 - if (inode)
78346 - audit_log_format(ab, " dev=%s ino=%lu",
78347 - inode->i_sb->s_id,
78348 - inode->i_ino);
78349 + if (inode) {
78350 + audit_log_format(ab, " dev=");
78351 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
78352 + audit_log_format(ab, " ino=%lu", inode->i_ino);
78353 + }
78354 break;
78355 }
78356 case LSM_AUDIT_DATA_INODE: {
78357 @@ -265,8 +267,9 @@ static void dump_common_audit_data(struct audit_buffer *ab,
78358 dentry->d_name.name);
78359 dput(dentry);
78360 }
78361 - audit_log_format(ab, " dev=%s ino=%lu", inode->i_sb->s_id,
78362 - inode->i_ino);
78363 + audit_log_format(ab, " dev=");
78364 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
78365 + audit_log_format(ab, " ino=%lu", inode->i_ino);
78366 break;
78367 }
78368 case LSM_AUDIT_DATA_TASK:
78369 diff --git a/security/min_addr.c b/security/min_addr.c
78370 index f728728..6457a0c 100644
78371 --- a/security/min_addr.c
78372 +++ b/security/min_addr.c
78373 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
78374 */
78375 static void update_mmap_min_addr(void)
78376 {
78377 +#ifndef SPARC
78378 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
78379 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
78380 mmap_min_addr = dac_mmap_min_addr;
78381 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
78382 #else
78383 mmap_min_addr = dac_mmap_min_addr;
78384 #endif
78385 +#endif
78386 }
78387
78388 /*
78389 diff --git a/security/security.c b/security/security.c
78390 index e2f684a..8d62ef5 100644
78391 --- a/security/security.c
78392 +++ b/security/security.c
78393 @@ -26,8 +26,8 @@
78394 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
78395 CONFIG_DEFAULT_SECURITY;
78396
78397 -static struct security_operations *security_ops;
78398 -static struct security_operations default_security_ops = {
78399 +static struct security_operations *security_ops __read_only;
78400 +static struct security_operations default_security_ops __read_only = {
78401 .name = "default",
78402 };
78403
78404 @@ -68,7 +68,9 @@ int __init security_init(void)
78405
78406 void reset_security_ops(void)
78407 {
78408 + pax_open_kernel();
78409 security_ops = &default_security_ops;
78410 + pax_close_kernel();
78411 }
78412
78413 /* Save user chosen LSM */
78414 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
78415 index 1126c10..effb32b 100644
78416 --- a/security/selinux/hooks.c
78417 +++ b/security/selinux/hooks.c
78418 @@ -94,8 +94,6 @@
78419
78420 #define NUM_SEL_MNT_OPTS 5
78421
78422 -extern struct security_operations *security_ops;
78423 -
78424 /* SECMARK reference count */
78425 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
78426
78427 @@ -5449,7 +5447,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
78428
78429 #endif
78430
78431 -static struct security_operations selinux_ops = {
78432 +static struct security_operations selinux_ops __read_only = {
78433 .name = "selinux",
78434
78435 .ptrace_access_check = selinux_ptrace_access_check,
78436 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
78437 index b43813c..74be837 100644
78438 --- a/security/selinux/include/xfrm.h
78439 +++ b/security/selinux/include/xfrm.h
78440 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
78441
78442 static inline void selinux_xfrm_notify_policyload(void)
78443 {
78444 - atomic_inc(&flow_cache_genid);
78445 + atomic_inc_unchecked(&flow_cache_genid);
78446 }
78447 #else
78448 static inline int selinux_xfrm_enabled(void)
78449 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
78450 index 7db62b4..ee4d949 100644
78451 --- a/security/smack/smack_lsm.c
78452 +++ b/security/smack/smack_lsm.c
78453 @@ -3481,7 +3481,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
78454 return 0;
78455 }
78456
78457 -struct security_operations smack_ops = {
78458 +struct security_operations smack_ops __read_only = {
78459 .name = "smack",
78460
78461 .ptrace_access_check = smack_ptrace_access_check,
78462 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
78463 index 4b327b6..646c57a 100644
78464 --- a/security/tomoyo/tomoyo.c
78465 +++ b/security/tomoyo/tomoyo.c
78466 @@ -504,7 +504,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
78467 * tomoyo_security_ops is a "struct security_operations" which is used for
78468 * registering TOMOYO.
78469 */
78470 -static struct security_operations tomoyo_security_ops = {
78471 +static struct security_operations tomoyo_security_ops __read_only = {
78472 .name = "tomoyo",
78473 .cred_alloc_blank = tomoyo_cred_alloc_blank,
78474 .cred_prepare = tomoyo_cred_prepare,
78475 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
78476 index 762af68..7103453 100644
78477 --- a/sound/aoa/codecs/onyx.c
78478 +++ b/sound/aoa/codecs/onyx.c
78479 @@ -54,7 +54,7 @@ struct onyx {
78480 spdif_locked:1,
78481 analog_locked:1,
78482 original_mute:2;
78483 - int open_count;
78484 + local_t open_count;
78485 struct codec_info *codec_info;
78486
78487 /* mutex serializes concurrent access to the device
78488 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
78489 struct onyx *onyx = cii->codec_data;
78490
78491 mutex_lock(&onyx->mutex);
78492 - onyx->open_count++;
78493 + local_inc(&onyx->open_count);
78494 mutex_unlock(&onyx->mutex);
78495
78496 return 0;
78497 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
78498 struct onyx *onyx = cii->codec_data;
78499
78500 mutex_lock(&onyx->mutex);
78501 - onyx->open_count--;
78502 - if (!onyx->open_count)
78503 + if (local_dec_and_test(&onyx->open_count))
78504 onyx->spdif_locked = onyx->analog_locked = 0;
78505 mutex_unlock(&onyx->mutex);
78506
78507 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
78508 index ffd2025..df062c9 100644
78509 --- a/sound/aoa/codecs/onyx.h
78510 +++ b/sound/aoa/codecs/onyx.h
78511 @@ -11,6 +11,7 @@
78512 #include <linux/i2c.h>
78513 #include <asm/pmac_low_i2c.h>
78514 #include <asm/prom.h>
78515 +#include <asm/local.h>
78516
78517 /* PCM3052 register definitions */
78518
78519 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
78520 index 3cc4b86..af0a951 100644
78521 --- a/sound/core/oss/pcm_oss.c
78522 +++ b/sound/core/oss/pcm_oss.c
78523 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
78524 if (in_kernel) {
78525 mm_segment_t fs;
78526 fs = snd_enter_user();
78527 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
78528 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
78529 snd_leave_user(fs);
78530 } else {
78531 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
78532 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
78533 }
78534 if (ret != -EPIPE && ret != -ESTRPIPE)
78535 break;
78536 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
78537 if (in_kernel) {
78538 mm_segment_t fs;
78539 fs = snd_enter_user();
78540 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
78541 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
78542 snd_leave_user(fs);
78543 } else {
78544 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
78545 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
78546 }
78547 if (ret == -EPIPE) {
78548 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
78549 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
78550 struct snd_pcm_plugin_channel *channels;
78551 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
78552 if (!in_kernel) {
78553 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
78554 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
78555 return -EFAULT;
78556 buf = runtime->oss.buffer;
78557 }
78558 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
78559 }
78560 } else {
78561 tmp = snd_pcm_oss_write2(substream,
78562 - (const char __force *)buf,
78563 + (const char __force_kernel *)buf,
78564 runtime->oss.period_bytes, 0);
78565 if (tmp <= 0)
78566 goto err;
78567 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
78568 struct snd_pcm_runtime *runtime = substream->runtime;
78569 snd_pcm_sframes_t frames, frames1;
78570 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
78571 - char __user *final_dst = (char __force __user *)buf;
78572 + char __user *final_dst = (char __force_user *)buf;
78573 if (runtime->oss.plugin_first) {
78574 struct snd_pcm_plugin_channel *channels;
78575 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
78576 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
78577 xfer += tmp;
78578 runtime->oss.buffer_used -= tmp;
78579 } else {
78580 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
78581 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
78582 runtime->oss.period_bytes, 0);
78583 if (tmp <= 0)
78584 goto err;
78585 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
78586 size1);
78587 size1 /= runtime->channels; /* frames */
78588 fs = snd_enter_user();
78589 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
78590 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
78591 snd_leave_user(fs);
78592 }
78593 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
78594 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
78595 index 91cdf94..4085161 100644
78596 --- a/sound/core/pcm_compat.c
78597 +++ b/sound/core/pcm_compat.c
78598 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
78599 int err;
78600
78601 fs = snd_enter_user();
78602 - err = snd_pcm_delay(substream, &delay);
78603 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
78604 snd_leave_user(fs);
78605 if (err < 0)
78606 return err;
78607 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
78608 index 25ed9fe..24c46e9 100644
78609 --- a/sound/core/pcm_native.c
78610 +++ b/sound/core/pcm_native.c
78611 @@ -2765,11 +2765,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
78612 switch (substream->stream) {
78613 case SNDRV_PCM_STREAM_PLAYBACK:
78614 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
78615 - (void __user *)arg);
78616 + (void __force_user *)arg);
78617 break;
78618 case SNDRV_PCM_STREAM_CAPTURE:
78619 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
78620 - (void __user *)arg);
78621 + (void __force_user *)arg);
78622 break;
78623 default:
78624 result = -EINVAL;
78625 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
78626 index 5cf8d65..912a79c 100644
78627 --- a/sound/core/seq/seq_device.c
78628 +++ b/sound/core/seq/seq_device.c
78629 @@ -64,7 +64,7 @@ struct ops_list {
78630 int argsize; /* argument size */
78631
78632 /* operators */
78633 - struct snd_seq_dev_ops ops;
78634 + struct snd_seq_dev_ops *ops;
78635
78636 /* registred devices */
78637 struct list_head dev_list; /* list of devices */
78638 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
78639
78640 mutex_lock(&ops->reg_mutex);
78641 /* copy driver operators */
78642 - ops->ops = *entry;
78643 + ops->ops = entry;
78644 ops->driver |= DRIVER_LOADED;
78645 ops->argsize = argsize;
78646
78647 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
78648 dev->name, ops->id, ops->argsize, dev->argsize);
78649 return -EINVAL;
78650 }
78651 - if (ops->ops.init_device(dev) >= 0) {
78652 + if (ops->ops->init_device(dev) >= 0) {
78653 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
78654 ops->num_init_devices++;
78655 } else {
78656 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
78657 dev->name, ops->id, ops->argsize, dev->argsize);
78658 return -EINVAL;
78659 }
78660 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
78661 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
78662 dev->status = SNDRV_SEQ_DEVICE_FREE;
78663 dev->driver_data = NULL;
78664 ops->num_init_devices--;
78665 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
78666 index f24bf9a..1f7b67c 100644
78667 --- a/sound/drivers/mts64.c
78668 +++ b/sound/drivers/mts64.c
78669 @@ -29,6 +29,7 @@
78670 #include <sound/initval.h>
78671 #include <sound/rawmidi.h>
78672 #include <sound/control.h>
78673 +#include <asm/local.h>
78674
78675 #define CARD_NAME "Miditerminal 4140"
78676 #define DRIVER_NAME "MTS64"
78677 @@ -67,7 +68,7 @@ struct mts64 {
78678 struct pardevice *pardev;
78679 int pardev_claimed;
78680
78681 - int open_count;
78682 + local_t open_count;
78683 int current_midi_output_port;
78684 int current_midi_input_port;
78685 u8 mode[MTS64_NUM_INPUT_PORTS];
78686 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
78687 {
78688 struct mts64 *mts = substream->rmidi->private_data;
78689
78690 - if (mts->open_count == 0) {
78691 + if (local_read(&mts->open_count) == 0) {
78692 /* We don't need a spinlock here, because this is just called
78693 if the device has not been opened before.
78694 So there aren't any IRQs from the device */
78695 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
78696
78697 msleep(50);
78698 }
78699 - ++(mts->open_count);
78700 + local_inc(&mts->open_count);
78701
78702 return 0;
78703 }
78704 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
78705 struct mts64 *mts = substream->rmidi->private_data;
78706 unsigned long flags;
78707
78708 - --(mts->open_count);
78709 - if (mts->open_count == 0) {
78710 + if (local_dec_return(&mts->open_count) == 0) {
78711 /* We need the spinlock_irqsave here because we can still
78712 have IRQs at this point */
78713 spin_lock_irqsave(&mts->lock, flags);
78714 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
78715
78716 msleep(500);
78717
78718 - } else if (mts->open_count < 0)
78719 - mts->open_count = 0;
78720 + } else if (local_read(&mts->open_count) < 0)
78721 + local_set(&mts->open_count, 0);
78722
78723 return 0;
78724 }
78725 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
78726 index b953fb4..1999c01 100644
78727 --- a/sound/drivers/opl4/opl4_lib.c
78728 +++ b/sound/drivers/opl4/opl4_lib.c
78729 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
78730 MODULE_DESCRIPTION("OPL4 driver");
78731 MODULE_LICENSE("GPL");
78732
78733 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
78734 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
78735 {
78736 int timeout = 10;
78737 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
78738 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
78739 index f664823..590c745 100644
78740 --- a/sound/drivers/portman2x4.c
78741 +++ b/sound/drivers/portman2x4.c
78742 @@ -48,6 +48,7 @@
78743 #include <sound/initval.h>
78744 #include <sound/rawmidi.h>
78745 #include <sound/control.h>
78746 +#include <asm/local.h>
78747
78748 #define CARD_NAME "Portman 2x4"
78749 #define DRIVER_NAME "portman"
78750 @@ -85,7 +86,7 @@ struct portman {
78751 struct pardevice *pardev;
78752 int pardev_claimed;
78753
78754 - int open_count;
78755 + local_t open_count;
78756 int mode[PORTMAN_NUM_INPUT_PORTS];
78757 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
78758 };
78759 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
78760 index 87657dd..a8268d4 100644
78761 --- a/sound/firewire/amdtp.c
78762 +++ b/sound/firewire/amdtp.c
78763 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
78764 ptr = s->pcm_buffer_pointer + data_blocks;
78765 if (ptr >= pcm->runtime->buffer_size)
78766 ptr -= pcm->runtime->buffer_size;
78767 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
78768 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
78769
78770 s->pcm_period_pointer += data_blocks;
78771 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
78772 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
78773 */
78774 void amdtp_out_stream_update(struct amdtp_out_stream *s)
78775 {
78776 - ACCESS_ONCE(s->source_node_id_field) =
78777 + ACCESS_ONCE_RW(s->source_node_id_field) =
78778 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
78779 }
78780 EXPORT_SYMBOL(amdtp_out_stream_update);
78781 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
78782 index 537a9cb..8e8c8e9 100644
78783 --- a/sound/firewire/amdtp.h
78784 +++ b/sound/firewire/amdtp.h
78785 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
78786 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
78787 struct snd_pcm_substream *pcm)
78788 {
78789 - ACCESS_ONCE(s->pcm) = pcm;
78790 + ACCESS_ONCE_RW(s->pcm) = pcm;
78791 }
78792
78793 /**
78794 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
78795 index cd094ec..eca1277 100644
78796 --- a/sound/firewire/isight.c
78797 +++ b/sound/firewire/isight.c
78798 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
78799 ptr += count;
78800 if (ptr >= runtime->buffer_size)
78801 ptr -= runtime->buffer_size;
78802 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
78803 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
78804
78805 isight->period_counter += count;
78806 if (isight->period_counter >= runtime->period_size) {
78807 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
78808 if (err < 0)
78809 return err;
78810
78811 - ACCESS_ONCE(isight->pcm_active) = true;
78812 + ACCESS_ONCE_RW(isight->pcm_active) = true;
78813
78814 return 0;
78815 }
78816 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
78817 {
78818 struct isight *isight = substream->private_data;
78819
78820 - ACCESS_ONCE(isight->pcm_active) = false;
78821 + ACCESS_ONCE_RW(isight->pcm_active) = false;
78822
78823 mutex_lock(&isight->mutex);
78824 isight_stop_streaming(isight);
78825 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
78826
78827 switch (cmd) {
78828 case SNDRV_PCM_TRIGGER_START:
78829 - ACCESS_ONCE(isight->pcm_running) = true;
78830 + ACCESS_ONCE_RW(isight->pcm_running) = true;
78831 break;
78832 case SNDRV_PCM_TRIGGER_STOP:
78833 - ACCESS_ONCE(isight->pcm_running) = false;
78834 + ACCESS_ONCE_RW(isight->pcm_running) = false;
78835 break;
78836 default:
78837 return -EINVAL;
78838 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
78839 index c94578d..0794ac1 100644
78840 --- a/sound/isa/cmi8330.c
78841 +++ b/sound/isa/cmi8330.c
78842 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
78843
78844 struct snd_pcm *pcm;
78845 struct snd_cmi8330_stream {
78846 - struct snd_pcm_ops ops;
78847 + snd_pcm_ops_no_const ops;
78848 snd_pcm_open_callback_t open;
78849 void *private_data; /* sb or wss */
78850 } streams[2];
78851 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
78852 index 733b014..56ce96f 100644
78853 --- a/sound/oss/sb_audio.c
78854 +++ b/sound/oss/sb_audio.c
78855 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
78856 buf16 = (signed short *)(localbuf + localoffs);
78857 while (c)
78858 {
78859 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
78860 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
78861 if (copy_from_user(lbuf8,
78862 userbuf+useroffs + p,
78863 locallen))
78864 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
78865 index 09d4648..cf234c7 100644
78866 --- a/sound/oss/swarm_cs4297a.c
78867 +++ b/sound/oss/swarm_cs4297a.c
78868 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
78869 {
78870 struct cs4297a_state *s;
78871 u32 pwr, id;
78872 - mm_segment_t fs;
78873 int rval;
78874 #ifndef CONFIG_BCM_CS4297A_CSWARM
78875 u64 cfg;
78876 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
78877 if (!rval) {
78878 char *sb1250_duart_present;
78879
78880 +#if 0
78881 + mm_segment_t fs;
78882 fs = get_fs();
78883 set_fs(KERNEL_DS);
78884 -#if 0
78885 val = SOUND_MASK_LINE;
78886 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
78887 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
78888 val = initvol[i].vol;
78889 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
78890 }
78891 + set_fs(fs);
78892 // cs4297a_write_ac97(s, 0x18, 0x0808);
78893 #else
78894 // cs4297a_write_ac97(s, 0x5e, 0x180);
78895 cs4297a_write_ac97(s, 0x02, 0x0808);
78896 cs4297a_write_ac97(s, 0x18, 0x0808);
78897 #endif
78898 - set_fs(fs);
78899
78900 list_add(&s->list, &cs4297a_devs);
78901
78902 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
78903 index 5644711..a2aebc1 100644
78904 --- a/sound/pci/hda/hda_codec.h
78905 +++ b/sound/pci/hda/hda_codec.h
78906 @@ -611,7 +611,7 @@ struct hda_bus_ops {
78907 /* notify power-up/down from codec to controller */
78908 void (*pm_notify)(struct hda_bus *bus);
78909 #endif
78910 -};
78911 +} __no_const;
78912
78913 /* template to pass to the bus constructor */
78914 struct hda_bus_template {
78915 @@ -713,6 +713,7 @@ struct hda_codec_ops {
78916 #endif
78917 void (*reboot_notify)(struct hda_codec *codec);
78918 };
78919 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
78920
78921 /* record for amp information cache */
78922 struct hda_cache_head {
78923 @@ -743,7 +744,7 @@ struct hda_pcm_ops {
78924 struct snd_pcm_substream *substream);
78925 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
78926 struct snd_pcm_substream *substream);
78927 -};
78928 +} __no_const;
78929
78930 /* PCM information for each substream */
78931 struct hda_pcm_stream {
78932 @@ -801,7 +802,7 @@ struct hda_codec {
78933 const char *modelname; /* model name for preset */
78934
78935 /* set by patch */
78936 - struct hda_codec_ops patch_ops;
78937 + hda_codec_ops_no_const patch_ops;
78938
78939 /* PCM to create, set by patch_ops.build_pcms callback */
78940 unsigned int num_pcms;
78941 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
78942 index 0da778a..bc38b84 100644
78943 --- a/sound/pci/ice1712/ice1712.h
78944 +++ b/sound/pci/ice1712/ice1712.h
78945 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
78946 unsigned int mask_flags; /* total mask bits */
78947 struct snd_akm4xxx_ops {
78948 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
78949 - } ops;
78950 + } __no_const ops;
78951 };
78952
78953 struct snd_ice1712_spdif {
78954 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
78955 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
78956 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
78957 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
78958 - } ops;
78959 + } __no_const ops;
78960 };
78961
78962
78963 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
78964 index 03ee4e3..be86b46 100644
78965 --- a/sound/pci/ymfpci/ymfpci_main.c
78966 +++ b/sound/pci/ymfpci/ymfpci_main.c
78967 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
78968 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
78969 break;
78970 }
78971 - if (atomic_read(&chip->interrupt_sleep_count)) {
78972 - atomic_set(&chip->interrupt_sleep_count, 0);
78973 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
78974 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
78975 wake_up(&chip->interrupt_sleep);
78976 }
78977 __end:
78978 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
78979 continue;
78980 init_waitqueue_entry(&wait, current);
78981 add_wait_queue(&chip->interrupt_sleep, &wait);
78982 - atomic_inc(&chip->interrupt_sleep_count);
78983 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
78984 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
78985 remove_wait_queue(&chip->interrupt_sleep, &wait);
78986 }
78987 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
78988 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
78989 spin_unlock(&chip->reg_lock);
78990
78991 - if (atomic_read(&chip->interrupt_sleep_count)) {
78992 - atomic_set(&chip->interrupt_sleep_count, 0);
78993 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
78994 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
78995 wake_up(&chip->interrupt_sleep);
78996 }
78997 }
78998 @@ -2382,7 +2382,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
78999 spin_lock_init(&chip->reg_lock);
79000 spin_lock_init(&chip->voice_lock);
79001 init_waitqueue_head(&chip->interrupt_sleep);
79002 - atomic_set(&chip->interrupt_sleep_count, 0);
79003 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
79004 chip->card = card;
79005 chip->pci = pci;
79006 chip->irq = -1;
79007 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
79008 index ee15337..e2187a6 100644
79009 --- a/sound/soc/soc-pcm.c
79010 +++ b/sound/soc/soc-pcm.c
79011 @@ -583,7 +583,7 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
79012 }
79013
79014 /* ASoC PCM operations */
79015 -static struct snd_pcm_ops soc_pcm_ops = {
79016 +static snd_pcm_ops_no_const soc_pcm_ops = {
79017 .open = soc_pcm_open,
79018 .close = soc_pcm_close,
79019 .hw_params = soc_pcm_hw_params,
79020 diff --git a/sound/usb/card.h b/sound/usb/card.h
79021 index a39edcc..1014050 100644
79022 --- a/sound/usb/card.h
79023 +++ b/sound/usb/card.h
79024 @@ -44,6 +44,7 @@ struct snd_urb_ops {
79025 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
79026 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
79027 };
79028 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
79029
79030 struct snd_usb_substream {
79031 struct snd_usb_stream *stream;
79032 @@ -93,7 +94,7 @@ struct snd_usb_substream {
79033 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
79034 spinlock_t lock;
79035
79036 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
79037 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
79038 int last_frame_number; /* stored frame number */
79039 int last_delay; /* stored delay */
79040 };
79041 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
79042 new file mode 100644
79043 index 0000000..894c8bf
79044 --- /dev/null
79045 +++ b/tools/gcc/Makefile
79046 @@ -0,0 +1,23 @@
79047 +#CC := gcc
79048 +#PLUGIN_SOURCE_FILES := pax_plugin.c
79049 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
79050 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
79051 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
79052 +
79053 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
79054 +
79055 +hostlibs-y := constify_plugin.so
79056 +hostlibs-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
79057 +hostlibs-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
79058 +hostlibs-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
79059 +hostlibs-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
79060 +hostlibs-y += colorize_plugin.so
79061 +
79062 +always := $(hostlibs-y)
79063 +
79064 +constify_plugin-objs := constify_plugin.o
79065 +stackleak_plugin-objs := stackleak_plugin.o
79066 +kallocstat_plugin-objs := kallocstat_plugin.o
79067 +kernexec_plugin-objs := kernexec_plugin.o
79068 +checker_plugin-objs := checker_plugin.o
79069 +colorize_plugin-objs := colorize_plugin.o
79070 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
79071 new file mode 100644
79072 index 0000000..d41b5af
79073 --- /dev/null
79074 +++ b/tools/gcc/checker_plugin.c
79075 @@ -0,0 +1,171 @@
79076 +/*
79077 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
79078 + * Licensed under the GPL v2
79079 + *
79080 + * Note: the choice of the license means that the compilation process is
79081 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
79082 + * but for the kernel it doesn't matter since it doesn't link against
79083 + * any of the gcc libraries
79084 + *
79085 + * gcc plugin to implement various sparse (source code checker) features
79086 + *
79087 + * TODO:
79088 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
79089 + *
79090 + * BUGS:
79091 + * - none known
79092 + */
79093 +#include "gcc-plugin.h"
79094 +#include "config.h"
79095 +#include "system.h"
79096 +#include "coretypes.h"
79097 +#include "tree.h"
79098 +#include "tree-pass.h"
79099 +#include "flags.h"
79100 +#include "intl.h"
79101 +#include "toplev.h"
79102 +#include "plugin.h"
79103 +//#include "expr.h" where are you...
79104 +#include "diagnostic.h"
79105 +#include "plugin-version.h"
79106 +#include "tm.h"
79107 +#include "function.h"
79108 +#include "basic-block.h"
79109 +#include "gimple.h"
79110 +#include "rtl.h"
79111 +#include "emit-rtl.h"
79112 +#include "tree-flow.h"
79113 +#include "target.h"
79114 +
79115 +extern void c_register_addr_space (const char *str, addr_space_t as);
79116 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
79117 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
79118 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
79119 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
79120 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
79121 +
79122 +extern void print_gimple_stmt(FILE *, gimple, int, int);
79123 +extern rtx emit_move_insn(rtx x, rtx y);
79124 +
79125 +int plugin_is_GPL_compatible;
79126 +
79127 +static struct plugin_info checker_plugin_info = {
79128 + .version = "201111150100",
79129 +};
79130 +
79131 +#define ADDR_SPACE_KERNEL 0
79132 +#define ADDR_SPACE_FORCE_KERNEL 1
79133 +#define ADDR_SPACE_USER 2
79134 +#define ADDR_SPACE_FORCE_USER 3
79135 +#define ADDR_SPACE_IOMEM 0
79136 +#define ADDR_SPACE_FORCE_IOMEM 0
79137 +#define ADDR_SPACE_PERCPU 0
79138 +#define ADDR_SPACE_FORCE_PERCPU 0
79139 +#define ADDR_SPACE_RCU 0
79140 +#define ADDR_SPACE_FORCE_RCU 0
79141 +
79142 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
79143 +{
79144 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
79145 +}
79146 +
79147 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
79148 +{
79149 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
79150 +}
79151 +
79152 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
79153 +{
79154 + return default_addr_space_valid_pointer_mode(mode, as);
79155 +}
79156 +
79157 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
79158 +{
79159 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
79160 +}
79161 +
79162 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
79163 +{
79164 + return default_addr_space_legitimize_address(x, oldx, mode, as);
79165 +}
79166 +
79167 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
79168 +{
79169 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
79170 + return true;
79171 +
79172 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
79173 + return true;
79174 +
79175 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
79176 + return true;
79177 +
79178 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
79179 + return true;
79180 +
79181 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
79182 + return true;
79183 +
79184 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
79185 + return true;
79186 +
79187 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
79188 + return true;
79189 +
79190 + return subset == superset;
79191 +}
79192 +
79193 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
79194 +{
79195 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
79196 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
79197 +
79198 + return op;
79199 +}
79200 +
79201 +static void register_checker_address_spaces(void *event_data, void *data)
79202 +{
79203 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
79204 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
79205 + c_register_addr_space("__user", ADDR_SPACE_USER);
79206 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
79207 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
79208 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
79209 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
79210 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
79211 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
79212 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
79213 +
79214 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
79215 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
79216 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
79217 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
79218 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
79219 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
79220 + targetm.addr_space.convert = checker_addr_space_convert;
79221 +}
79222 +
79223 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
79224 +{
79225 + const char * const plugin_name = plugin_info->base_name;
79226 + const int argc = plugin_info->argc;
79227 + const struct plugin_argument * const argv = plugin_info->argv;
79228 + int i;
79229 +
79230 + if (!plugin_default_version_check(version, &gcc_version)) {
79231 + error(G_("incompatible gcc/plugin versions"));
79232 + return 1;
79233 + }
79234 +
79235 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
79236 +
79237 + for (i = 0; i < argc; ++i)
79238 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
79239 +
79240 + if (TARGET_64BIT == 0)
79241 + return 0;
79242 +
79243 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
79244 +
79245 + return 0;
79246 +}
79247 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
79248 new file mode 100644
79249 index 0000000..ee950d0
79250 --- /dev/null
79251 +++ b/tools/gcc/colorize_plugin.c
79252 @@ -0,0 +1,147 @@
79253 +/*
79254 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
79255 + * Licensed under the GPL v2
79256 + *
79257 + * Note: the choice of the license means that the compilation process is
79258 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
79259 + * but for the kernel it doesn't matter since it doesn't link against
79260 + * any of the gcc libraries
79261 + *
79262 + * gcc plugin to colorize diagnostic output
79263 + *
79264 + */
79265 +
79266 +#include "gcc-plugin.h"
79267 +#include "config.h"
79268 +#include "system.h"
79269 +#include "coretypes.h"
79270 +#include "tree.h"
79271 +#include "tree-pass.h"
79272 +#include "flags.h"
79273 +#include "intl.h"
79274 +#include "toplev.h"
79275 +#include "plugin.h"
79276 +#include "diagnostic.h"
79277 +#include "plugin-version.h"
79278 +#include "tm.h"
79279 +
79280 +int plugin_is_GPL_compatible;
79281 +
79282 +static struct plugin_info colorize_plugin_info = {
79283 + .version = "201203092200",
79284 +};
79285 +
79286 +#define GREEN "\033[32m\033[2m"
79287 +#define LIGHTGREEN "\033[32m\033[1m"
79288 +#define YELLOW "\033[33m\033[2m"
79289 +#define LIGHTYELLOW "\033[33m\033[1m"
79290 +#define RED "\033[31m\033[2m"
79291 +#define LIGHTRED "\033[31m\033[1m"
79292 +#define BLUE "\033[34m\033[2m"
79293 +#define LIGHTBLUE "\033[34m\033[1m"
79294 +#define BRIGHT "\033[m\033[1m"
79295 +#define NORMAL "\033[m"
79296 +
79297 +static diagnostic_starter_fn old_starter;
79298 +static diagnostic_finalizer_fn old_finalizer;
79299 +
79300 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
79301 +{
79302 + const char *color;
79303 + char *newprefix;
79304 +
79305 + switch (diagnostic->kind) {
79306 + case DK_NOTE:
79307 + color = LIGHTBLUE;
79308 + break;
79309 +
79310 + case DK_PEDWARN:
79311 + case DK_WARNING:
79312 + color = LIGHTYELLOW;
79313 + break;
79314 +
79315 + case DK_ERROR:
79316 + case DK_FATAL:
79317 + case DK_ICE:
79318 + case DK_PERMERROR:
79319 + case DK_SORRY:
79320 + color = LIGHTRED;
79321 + break;
79322 +
79323 + default:
79324 + color = NORMAL;
79325 + }
79326 +
79327 + old_starter(context, diagnostic);
79328 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
79329 + return;
79330 + pp_destroy_prefix(context->printer);
79331 + pp_set_prefix(context->printer, newprefix);
79332 +}
79333 +
79334 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
79335 +{
79336 + old_finalizer(context, diagnostic);
79337 +}
79338 +
79339 +static void colorize_arm(void)
79340 +{
79341 + old_starter = diagnostic_starter(global_dc);
79342 + old_finalizer = diagnostic_finalizer(global_dc);
79343 +
79344 + diagnostic_starter(global_dc) = start_colorize;
79345 + diagnostic_finalizer(global_dc) = finalize_colorize;
79346 +}
79347 +
79348 +static unsigned int execute_colorize_rearm(void)
79349 +{
79350 + if (diagnostic_starter(global_dc) == start_colorize)
79351 + return 0;
79352 +
79353 + colorize_arm();
79354 + return 0;
79355 +}
79356 +
79357 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
79358 + .pass = {
79359 + .type = SIMPLE_IPA_PASS,
79360 + .name = "colorize_rearm",
79361 + .gate = NULL,
79362 + .execute = execute_colorize_rearm,
79363 + .sub = NULL,
79364 + .next = NULL,
79365 + .static_pass_number = 0,
79366 + .tv_id = TV_NONE,
79367 + .properties_required = 0,
79368 + .properties_provided = 0,
79369 + .properties_destroyed = 0,
79370 + .todo_flags_start = 0,
79371 + .todo_flags_finish = 0
79372 + }
79373 +};
79374 +
79375 +static void colorize_start_unit(void *gcc_data, void *user_data)
79376 +{
79377 + colorize_arm();
79378 +}
79379 +
79380 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
79381 +{
79382 + const char * const plugin_name = plugin_info->base_name;
79383 + struct register_pass_info colorize_rearm_pass_info = {
79384 + .pass = &pass_ipa_colorize_rearm.pass,
79385 + .reference_pass_name = "*free_lang_data",
79386 + .ref_pass_instance_number = 0,
79387 + .pos_op = PASS_POS_INSERT_AFTER
79388 + };
79389 +
79390 + if (!plugin_default_version_check(version, &gcc_version)) {
79391 + error(G_("incompatible gcc/plugin versions"));
79392 + return 1;
79393 + }
79394 +
79395 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
79396 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
79397 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
79398 + return 0;
79399 +}
79400 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
79401 new file mode 100644
79402 index 0000000..704a564
79403 --- /dev/null
79404 +++ b/tools/gcc/constify_plugin.c
79405 @@ -0,0 +1,303 @@
79406 +/*
79407 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
79408 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
79409 + * Licensed under the GPL v2, or (at your option) v3
79410 + *
79411 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
79412 + *
79413 + * Homepage:
79414 + * http://www.grsecurity.net/~ephox/const_plugin/
79415 + *
79416 + * Usage:
79417 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
79418 + * $ gcc -fplugin=constify_plugin.so test.c -O2
79419 + */
79420 +
79421 +#include "gcc-plugin.h"
79422 +#include "config.h"
79423 +#include "system.h"
79424 +#include "coretypes.h"
79425 +#include "tree.h"
79426 +#include "tree-pass.h"
79427 +#include "flags.h"
79428 +#include "intl.h"
79429 +#include "toplev.h"
79430 +#include "plugin.h"
79431 +#include "diagnostic.h"
79432 +#include "plugin-version.h"
79433 +#include "tm.h"
79434 +#include "function.h"
79435 +#include "basic-block.h"
79436 +#include "gimple.h"
79437 +#include "rtl.h"
79438 +#include "emit-rtl.h"
79439 +#include "tree-flow.h"
79440 +
79441 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
79442 +
79443 +int plugin_is_GPL_compatible;
79444 +
79445 +static struct plugin_info const_plugin_info = {
79446 + .version = "201111150100",
79447 + .help = "no-constify\tturn off constification\n",
79448 +};
79449 +
79450 +static void constify_type(tree type);
79451 +static bool walk_struct(tree node);
79452 +
79453 +static tree deconstify_type(tree old_type)
79454 +{
79455 + tree new_type, field;
79456 +
79457 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
79458 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
79459 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
79460 + DECL_FIELD_CONTEXT(field) = new_type;
79461 + TYPE_READONLY(new_type) = 0;
79462 + C_TYPE_FIELDS_READONLY(new_type) = 0;
79463 + return new_type;
79464 +}
79465 +
79466 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
79467 +{
79468 + tree type;
79469 +
79470 + *no_add_attrs = true;
79471 + if (TREE_CODE(*node) == FUNCTION_DECL) {
79472 + error("%qE attribute does not apply to functions", name);
79473 + return NULL_TREE;
79474 + }
79475 +
79476 + if (TREE_CODE(*node) == VAR_DECL) {
79477 + error("%qE attribute does not apply to variables", name);
79478 + return NULL_TREE;
79479 + }
79480 +
79481 + if (TYPE_P(*node)) {
79482 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
79483 + *no_add_attrs = false;
79484 + else
79485 + error("%qE attribute applies to struct and union types only", name);
79486 + return NULL_TREE;
79487 + }
79488 +
79489 + type = TREE_TYPE(*node);
79490 +
79491 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
79492 + error("%qE attribute applies to struct and union types only", name);
79493 + return NULL_TREE;
79494 + }
79495 +
79496 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
79497 + error("%qE attribute is already applied to the type", name);
79498 + return NULL_TREE;
79499 + }
79500 +
79501 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
79502 + error("%qE attribute used on type that is not constified", name);
79503 + return NULL_TREE;
79504 + }
79505 +
79506 + if (TREE_CODE(*node) == TYPE_DECL) {
79507 + TREE_TYPE(*node) = deconstify_type(type);
79508 + TREE_READONLY(*node) = 0;
79509 + return NULL_TREE;
79510 + }
79511 +
79512 + return NULL_TREE;
79513 +}
79514 +
79515 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
79516 +{
79517 + *no_add_attrs = true;
79518 + if (!TYPE_P(*node)) {
79519 + error("%qE attribute applies to types only", name);
79520 + return NULL_TREE;
79521 + }
79522 +
79523 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
79524 + error("%qE attribute applies to struct and union types only", name);
79525 + return NULL_TREE;
79526 + }
79527 +
79528 + *no_add_attrs = false;
79529 + constify_type(*node);
79530 + return NULL_TREE;
79531 +}
79532 +
79533 +static struct attribute_spec no_const_attr = {
79534 + .name = "no_const",
79535 + .min_length = 0,
79536 + .max_length = 0,
79537 + .decl_required = false,
79538 + .type_required = false,
79539 + .function_type_required = false,
79540 + .handler = handle_no_const_attribute,
79541 +#if BUILDING_GCC_VERSION >= 4007
79542 + .affects_type_identity = true
79543 +#endif
79544 +};
79545 +
79546 +static struct attribute_spec do_const_attr = {
79547 + .name = "do_const",
79548 + .min_length = 0,
79549 + .max_length = 0,
79550 + .decl_required = false,
79551 + .type_required = false,
79552 + .function_type_required = false,
79553 + .handler = handle_do_const_attribute,
79554 +#if BUILDING_GCC_VERSION >= 4007
79555 + .affects_type_identity = true
79556 +#endif
79557 +};
79558 +
79559 +static void register_attributes(void *event_data, void *data)
79560 +{
79561 + register_attribute(&no_const_attr);
79562 + register_attribute(&do_const_attr);
79563 +}
79564 +
79565 +static void constify_type(tree type)
79566 +{
79567 + TYPE_READONLY(type) = 1;
79568 + C_TYPE_FIELDS_READONLY(type) = 1;
79569 +}
79570 +
79571 +static bool is_fptr(tree field)
79572 +{
79573 + tree ptr = TREE_TYPE(field);
79574 +
79575 + if (TREE_CODE(ptr) != POINTER_TYPE)
79576 + return false;
79577 +
79578 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
79579 +}
79580 +
79581 +static bool walk_struct(tree node)
79582 +{
79583 + tree field;
79584 +
79585 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node)))
79586 + return false;
79587 +
79588 + if (TYPE_FIELDS(node) == NULL_TREE)
79589 + return false;
79590 +
79591 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
79592 + tree type = TREE_TYPE(field);
79593 + enum tree_code code = TREE_CODE(type);
79594 + if (code == RECORD_TYPE || code == UNION_TYPE) {
79595 + if (!(walk_struct(type)))
79596 + return false;
79597 + } else if (!is_fptr(field) && !TREE_READONLY(field))
79598 + return false;
79599 + }
79600 + return true;
79601 +}
79602 +
79603 +static void finish_type(void *event_data, void *data)
79604 +{
79605 + tree type = (tree)event_data;
79606 +
79607 + if (type == NULL_TREE)
79608 + return;
79609 +
79610 + if (TYPE_READONLY(type))
79611 + return;
79612 +
79613 + if (walk_struct(type))
79614 + constify_type(type);
79615 +}
79616 +
79617 +static unsigned int check_local_variables(void);
79618 +
79619 +struct gimple_opt_pass pass_local_variable = {
79620 + {
79621 + .type = GIMPLE_PASS,
79622 + .name = "check_local_variables",
79623 + .gate = NULL,
79624 + .execute = check_local_variables,
79625 + .sub = NULL,
79626 + .next = NULL,
79627 + .static_pass_number = 0,
79628 + .tv_id = TV_NONE,
79629 + .properties_required = 0,
79630 + .properties_provided = 0,
79631 + .properties_destroyed = 0,
79632 + .todo_flags_start = 0,
79633 + .todo_flags_finish = 0
79634 + }
79635 +};
79636 +
79637 +static unsigned int check_local_variables(void)
79638 +{
79639 + tree var;
79640 + referenced_var_iterator rvi;
79641 +
79642 +#if BUILDING_GCC_VERSION == 4005
79643 + FOR_EACH_REFERENCED_VAR(var, rvi) {
79644 +#else
79645 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
79646 +#endif
79647 + tree type = TREE_TYPE(var);
79648 +
79649 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
79650 + continue;
79651 +
79652 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
79653 + continue;
79654 +
79655 + if (!TYPE_READONLY(type))
79656 + continue;
79657 +
79658 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
79659 +// continue;
79660 +
79661 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
79662 +// continue;
79663 +
79664 + if (walk_struct(type)) {
79665 + error("constified variable %qE cannot be local", var);
79666 + return 1;
79667 + }
79668 + }
79669 + return 0;
79670 +}
79671 +
79672 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
79673 +{
79674 + const char * const plugin_name = plugin_info->base_name;
79675 + const int argc = plugin_info->argc;
79676 + const struct plugin_argument * const argv = plugin_info->argv;
79677 + int i;
79678 + bool constify = true;
79679 +
79680 + struct register_pass_info local_variable_pass_info = {
79681 + .pass = &pass_local_variable.pass,
79682 + .reference_pass_name = "*referenced_vars",
79683 + .ref_pass_instance_number = 0,
79684 + .pos_op = PASS_POS_INSERT_AFTER
79685 + };
79686 +
79687 + if (!plugin_default_version_check(version, &gcc_version)) {
79688 + error(G_("incompatible gcc/plugin versions"));
79689 + return 1;
79690 + }
79691 +
79692 + for (i = 0; i < argc; ++i) {
79693 + if (!(strcmp(argv[i].key, "no-constify"))) {
79694 + constify = false;
79695 + continue;
79696 + }
79697 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
79698 + }
79699 +
79700 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
79701 + if (constify) {
79702 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
79703 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
79704 + }
79705 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
79706 +
79707 + return 0;
79708 +}
79709 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
79710 new file mode 100644
79711 index 0000000..a5eabce
79712 --- /dev/null
79713 +++ b/tools/gcc/kallocstat_plugin.c
79714 @@ -0,0 +1,167 @@
79715 +/*
79716 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
79717 + * Licensed under the GPL v2
79718 + *
79719 + * Note: the choice of the license means that the compilation process is
79720 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
79721 + * but for the kernel it doesn't matter since it doesn't link against
79722 + * any of the gcc libraries
79723 + *
79724 + * gcc plugin to find the distribution of k*alloc sizes
79725 + *
79726 + * TODO:
79727 + *
79728 + * BUGS:
79729 + * - none known
79730 + */
79731 +#include "gcc-plugin.h"
79732 +#include "config.h"
79733 +#include "system.h"
79734 +#include "coretypes.h"
79735 +#include "tree.h"
79736 +#include "tree-pass.h"
79737 +#include "flags.h"
79738 +#include "intl.h"
79739 +#include "toplev.h"
79740 +#include "plugin.h"
79741 +//#include "expr.h" where are you...
79742 +#include "diagnostic.h"
79743 +#include "plugin-version.h"
79744 +#include "tm.h"
79745 +#include "function.h"
79746 +#include "basic-block.h"
79747 +#include "gimple.h"
79748 +#include "rtl.h"
79749 +#include "emit-rtl.h"
79750 +
79751 +extern void print_gimple_stmt(FILE *, gimple, int, int);
79752 +
79753 +int plugin_is_GPL_compatible;
79754 +
79755 +static const char * const kalloc_functions[] = {
79756 + "__kmalloc",
79757 + "kmalloc",
79758 + "kmalloc_large",
79759 + "kmalloc_node",
79760 + "kmalloc_order",
79761 + "kmalloc_order_trace",
79762 + "kmalloc_slab",
79763 + "kzalloc",
79764 + "kzalloc_node",
79765 +};
79766 +
79767 +static struct plugin_info kallocstat_plugin_info = {
79768 + .version = "201111150100",
79769 +};
79770 +
79771 +static unsigned int execute_kallocstat(void);
79772 +
79773 +static struct gimple_opt_pass kallocstat_pass = {
79774 + .pass = {
79775 + .type = GIMPLE_PASS,
79776 + .name = "kallocstat",
79777 + .gate = NULL,
79778 + .execute = execute_kallocstat,
79779 + .sub = NULL,
79780 + .next = NULL,
79781 + .static_pass_number = 0,
79782 + .tv_id = TV_NONE,
79783 + .properties_required = 0,
79784 + .properties_provided = 0,
79785 + .properties_destroyed = 0,
79786 + .todo_flags_start = 0,
79787 + .todo_flags_finish = 0
79788 + }
79789 +};
79790 +
79791 +static bool is_kalloc(const char *fnname)
79792 +{
79793 + size_t i;
79794 +
79795 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
79796 + if (!strcmp(fnname, kalloc_functions[i]))
79797 + return true;
79798 + return false;
79799 +}
79800 +
79801 +static unsigned int execute_kallocstat(void)
79802 +{
79803 + basic_block bb;
79804 +
79805 + // 1. loop through BBs and GIMPLE statements
79806 + FOR_EACH_BB(bb) {
79807 + gimple_stmt_iterator gsi;
79808 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
79809 + // gimple match:
79810 + tree fndecl, size;
79811 + gimple call_stmt;
79812 + const char *fnname;
79813 +
79814 + // is it a call
79815 + call_stmt = gsi_stmt(gsi);
79816 + if (!is_gimple_call(call_stmt))
79817 + continue;
79818 + fndecl = gimple_call_fndecl(call_stmt);
79819 + if (fndecl == NULL_TREE)
79820 + continue;
79821 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
79822 + continue;
79823 +
79824 + // is it a call to k*alloc
79825 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
79826 + if (!is_kalloc(fnname))
79827 + continue;
79828 +
79829 + // is the size arg the result of a simple const assignment
79830 + size = gimple_call_arg(call_stmt, 0);
79831 + while (true) {
79832 + gimple def_stmt;
79833 + expanded_location xloc;
79834 + size_t size_val;
79835 +
79836 + if (TREE_CODE(size) != SSA_NAME)
79837 + break;
79838 + def_stmt = SSA_NAME_DEF_STMT(size);
79839 + if (!def_stmt || !is_gimple_assign(def_stmt))
79840 + break;
79841 + if (gimple_num_ops(def_stmt) != 2)
79842 + break;
79843 + size = gimple_assign_rhs1(def_stmt);
79844 + if (!TREE_CONSTANT(size))
79845 + continue;
79846 + xloc = expand_location(gimple_location(def_stmt));
79847 + if (!xloc.file)
79848 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
79849 + size_val = TREE_INT_CST_LOW(size);
79850 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
79851 + break;
79852 + }
79853 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
79854 +//debug_tree(gimple_call_fn(call_stmt));
79855 +//print_node(stderr, "pax", fndecl, 4);
79856 + }
79857 + }
79858 +
79859 + return 0;
79860 +}
79861 +
79862 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
79863 +{
79864 + const char * const plugin_name = plugin_info->base_name;
79865 + struct register_pass_info kallocstat_pass_info = {
79866 + .pass = &kallocstat_pass.pass,
79867 + .reference_pass_name = "ssa",
79868 + .ref_pass_instance_number = 0,
79869 + .pos_op = PASS_POS_INSERT_AFTER
79870 + };
79871 +
79872 + if (!plugin_default_version_check(version, &gcc_version)) {
79873 + error(G_("incompatible gcc/plugin versions"));
79874 + return 1;
79875 + }
79876 +
79877 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
79878 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
79879 +
79880 + return 0;
79881 +}
79882 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
79883 new file mode 100644
79884 index 0000000..008f159
79885 --- /dev/null
79886 +++ b/tools/gcc/kernexec_plugin.c
79887 @@ -0,0 +1,427 @@
79888 +/*
79889 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
79890 + * Licensed under the GPL v2
79891 + *
79892 + * Note: the choice of the license means that the compilation process is
79893 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
79894 + * but for the kernel it doesn't matter since it doesn't link against
79895 + * any of the gcc libraries
79896 + *
79897 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
79898 + *
79899 + * TODO:
79900 + *
79901 + * BUGS:
79902 + * - none known
79903 + */
79904 +#include "gcc-plugin.h"
79905 +#include "config.h"
79906 +#include "system.h"
79907 +#include "coretypes.h"
79908 +#include "tree.h"
79909 +#include "tree-pass.h"
79910 +#include "flags.h"
79911 +#include "intl.h"
79912 +#include "toplev.h"
79913 +#include "plugin.h"
79914 +//#include "expr.h" where are you...
79915 +#include "diagnostic.h"
79916 +#include "plugin-version.h"
79917 +#include "tm.h"
79918 +#include "function.h"
79919 +#include "basic-block.h"
79920 +#include "gimple.h"
79921 +#include "rtl.h"
79922 +#include "emit-rtl.h"
79923 +#include "tree-flow.h"
79924 +
79925 +extern void print_gimple_stmt(FILE *, gimple, int, int);
79926 +extern rtx emit_move_insn(rtx x, rtx y);
79927 +
79928 +int plugin_is_GPL_compatible;
79929 +
79930 +static struct plugin_info kernexec_plugin_info = {
79931 + .version = "201111291120",
79932 + .help = "method=[bts|or]\tinstrumentation method\n"
79933 +};
79934 +
79935 +static unsigned int execute_kernexec_reload(void);
79936 +static unsigned int execute_kernexec_fptr(void);
79937 +static unsigned int execute_kernexec_retaddr(void);
79938 +static bool kernexec_cmodel_check(void);
79939 +
79940 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
79941 +static void (*kernexec_instrument_retaddr)(rtx);
79942 +
79943 +static struct gimple_opt_pass kernexec_reload_pass = {
79944 + .pass = {
79945 + .type = GIMPLE_PASS,
79946 + .name = "kernexec_reload",
79947 + .gate = kernexec_cmodel_check,
79948 + .execute = execute_kernexec_reload,
79949 + .sub = NULL,
79950 + .next = NULL,
79951 + .static_pass_number = 0,
79952 + .tv_id = TV_NONE,
79953 + .properties_required = 0,
79954 + .properties_provided = 0,
79955 + .properties_destroyed = 0,
79956 + .todo_flags_start = 0,
79957 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
79958 + }
79959 +};
79960 +
79961 +static struct gimple_opt_pass kernexec_fptr_pass = {
79962 + .pass = {
79963 + .type = GIMPLE_PASS,
79964 + .name = "kernexec_fptr",
79965 + .gate = kernexec_cmodel_check,
79966 + .execute = execute_kernexec_fptr,
79967 + .sub = NULL,
79968 + .next = NULL,
79969 + .static_pass_number = 0,
79970 + .tv_id = TV_NONE,
79971 + .properties_required = 0,
79972 + .properties_provided = 0,
79973 + .properties_destroyed = 0,
79974 + .todo_flags_start = 0,
79975 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
79976 + }
79977 +};
79978 +
79979 +static struct rtl_opt_pass kernexec_retaddr_pass = {
79980 + .pass = {
79981 + .type = RTL_PASS,
79982 + .name = "kernexec_retaddr",
79983 + .gate = kernexec_cmodel_check,
79984 + .execute = execute_kernexec_retaddr,
79985 + .sub = NULL,
79986 + .next = NULL,
79987 + .static_pass_number = 0,
79988 + .tv_id = TV_NONE,
79989 + .properties_required = 0,
79990 + .properties_provided = 0,
79991 + .properties_destroyed = 0,
79992 + .todo_flags_start = 0,
79993 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
79994 + }
79995 +};
79996 +
79997 +static bool kernexec_cmodel_check(void)
79998 +{
79999 + tree section;
80000 +
80001 + if (ix86_cmodel != CM_KERNEL)
80002 + return false;
80003 +
80004 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
80005 + if (!section || !TREE_VALUE(section))
80006 + return true;
80007 +
80008 + section = TREE_VALUE(TREE_VALUE(section));
80009 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
80010 + return true;
80011 +
80012 + return false;
80013 +}
80014 +
80015 +/*
80016 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
80017 + */
80018 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
80019 +{
80020 + gimple asm_movabs_stmt;
80021 +
80022 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
80023 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
80024 + gimple_asm_set_volatile(asm_movabs_stmt, true);
80025 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
80026 + update_stmt(asm_movabs_stmt);
80027 +}
80028 +
80029 +/*
80030 + * find all asm() stmts that clobber r10 and add a reload of r10
80031 + */
80032 +static unsigned int execute_kernexec_reload(void)
80033 +{
80034 + basic_block bb;
80035 +
80036 + // 1. loop through BBs and GIMPLE statements
80037 + FOR_EACH_BB(bb) {
80038 + gimple_stmt_iterator gsi;
80039 +
80040 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80041 + // gimple match: __asm__ ("" : : : "r10");
80042 + gimple asm_stmt;
80043 + size_t nclobbers;
80044 +
80045 + // is it an asm ...
80046 + asm_stmt = gsi_stmt(gsi);
80047 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
80048 + continue;
80049 +
80050 + // ... clobbering r10
80051 + nclobbers = gimple_asm_nclobbers(asm_stmt);
80052 + while (nclobbers--) {
80053 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
80054 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
80055 + continue;
80056 + kernexec_reload_fptr_mask(&gsi);
80057 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
80058 + break;
80059 + }
80060 + }
80061 + }
80062 +
80063 + return 0;
80064 +}
80065 +
80066 +/*
80067 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
80068 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
80069 + */
80070 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
80071 +{
80072 + gimple assign_intptr, assign_new_fptr, call_stmt;
80073 + tree intptr, old_fptr, new_fptr, kernexec_mask;
80074 +
80075 + call_stmt = gsi_stmt(*gsi);
80076 + old_fptr = gimple_call_fn(call_stmt);
80077 +
80078 + // create temporary unsigned long variable used for bitops and cast fptr to it
80079 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
80080 + add_referenced_var(intptr);
80081 + mark_sym_for_renaming(intptr);
80082 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
80083 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
80084 + update_stmt(assign_intptr);
80085 +
80086 + // apply logical or to temporary unsigned long and bitmask
80087 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
80088 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
80089 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
80090 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
80091 + update_stmt(assign_intptr);
80092 +
80093 + // cast temporary unsigned long back to a temporary fptr variable
80094 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec");
80095 + add_referenced_var(new_fptr);
80096 + mark_sym_for_renaming(new_fptr);
80097 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
80098 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
80099 + update_stmt(assign_new_fptr);
80100 +
80101 + // replace call stmt fn with the new fptr
80102 + gimple_call_set_fn(call_stmt, new_fptr);
80103 + update_stmt(call_stmt);
80104 +}
80105 +
80106 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
80107 +{
80108 + gimple asm_or_stmt, call_stmt;
80109 + tree old_fptr, new_fptr, input, output;
80110 + VEC(tree, gc) *inputs = NULL;
80111 + VEC(tree, gc) *outputs = NULL;
80112 +
80113 + call_stmt = gsi_stmt(*gsi);
80114 + old_fptr = gimple_call_fn(call_stmt);
80115 +
80116 + // create temporary fptr variable
80117 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
80118 + add_referenced_var(new_fptr);
80119 + mark_sym_for_renaming(new_fptr);
80120 +
80121 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
80122 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
80123 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
80124 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
80125 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
80126 + VEC_safe_push(tree, gc, inputs, input);
80127 + VEC_safe_push(tree, gc, outputs, output);
80128 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
80129 + gimple_asm_set_volatile(asm_or_stmt, true);
80130 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
80131 + update_stmt(asm_or_stmt);
80132 +
80133 + // replace call stmt fn with the new fptr
80134 + gimple_call_set_fn(call_stmt, new_fptr);
80135 + update_stmt(call_stmt);
80136 +}
80137 +
80138 +/*
80139 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
80140 + */
80141 +static unsigned int execute_kernexec_fptr(void)
80142 +{
80143 + basic_block bb;
80144 +
80145 + // 1. loop through BBs and GIMPLE statements
80146 + FOR_EACH_BB(bb) {
80147 + gimple_stmt_iterator gsi;
80148 +
80149 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80150 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
80151 + tree fn;
80152 + gimple call_stmt;
80153 +
80154 + // is it a call ...
80155 + call_stmt = gsi_stmt(gsi);
80156 + if (!is_gimple_call(call_stmt))
80157 + continue;
80158 + fn = gimple_call_fn(call_stmt);
80159 + if (TREE_CODE(fn) == ADDR_EXPR)
80160 + continue;
80161 + if (TREE_CODE(fn) != SSA_NAME)
80162 + gcc_unreachable();
80163 +
80164 + // ... through a function pointer
80165 + fn = SSA_NAME_VAR(fn);
80166 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
80167 + continue;
80168 + fn = TREE_TYPE(fn);
80169 + if (TREE_CODE(fn) != POINTER_TYPE)
80170 + continue;
80171 + fn = TREE_TYPE(fn);
80172 + if (TREE_CODE(fn) != FUNCTION_TYPE)
80173 + continue;
80174 +
80175 + kernexec_instrument_fptr(&gsi);
80176 +
80177 +//debug_tree(gimple_call_fn(call_stmt));
80178 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
80179 + }
80180 + }
80181 +
80182 + return 0;
80183 +}
80184 +
80185 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
80186 +static void kernexec_instrument_retaddr_bts(rtx insn)
80187 +{
80188 + rtx btsq;
80189 + rtvec argvec, constraintvec, labelvec;
80190 + int line;
80191 +
80192 + // create asm volatile("btsq $63,(%%rsp)":::)
80193 + argvec = rtvec_alloc(0);
80194 + constraintvec = rtvec_alloc(0);
80195 + labelvec = rtvec_alloc(0);
80196 + line = expand_location(RTL_LOCATION(insn)).line;
80197 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
80198 + MEM_VOLATILE_P(btsq) = 1;
80199 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
80200 + emit_insn_before(btsq, insn);
80201 +}
80202 +
80203 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
80204 +static void kernexec_instrument_retaddr_or(rtx insn)
80205 +{
80206 + rtx orq;
80207 + rtvec argvec, constraintvec, labelvec;
80208 + int line;
80209 +
80210 + // create asm volatile("orq %%r10,(%%rsp)":::)
80211 + argvec = rtvec_alloc(0);
80212 + constraintvec = rtvec_alloc(0);
80213 + labelvec = rtvec_alloc(0);
80214 + line = expand_location(RTL_LOCATION(insn)).line;
80215 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
80216 + MEM_VOLATILE_P(orq) = 1;
80217 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
80218 + emit_insn_before(orq, insn);
80219 +}
80220 +
80221 +/*
80222 + * find all asm level function returns and forcibly set the highest bit of the return address
80223 + */
80224 +static unsigned int execute_kernexec_retaddr(void)
80225 +{
80226 + rtx insn;
80227 +
80228 + // 1. find function returns
80229 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
80230 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
80231 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
80232 + rtx body;
80233 +
80234 + // is it a retn
80235 + if (!JUMP_P(insn))
80236 + continue;
80237 + body = PATTERN(insn);
80238 + if (GET_CODE(body) == PARALLEL)
80239 + body = XVECEXP(body, 0, 0);
80240 + if (GET_CODE(body) != RETURN)
80241 + continue;
80242 + kernexec_instrument_retaddr(insn);
80243 + }
80244 +
80245 +// print_simple_rtl(stderr, get_insns());
80246 +// print_rtl(stderr, get_insns());
80247 +
80248 + return 0;
80249 +}
80250 +
80251 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80252 +{
80253 + const char * const plugin_name = plugin_info->base_name;
80254 + const int argc = plugin_info->argc;
80255 + const struct plugin_argument * const argv = plugin_info->argv;
80256 + int i;
80257 + struct register_pass_info kernexec_reload_pass_info = {
80258 + .pass = &kernexec_reload_pass.pass,
80259 + .reference_pass_name = "ssa",
80260 + .ref_pass_instance_number = 0,
80261 + .pos_op = PASS_POS_INSERT_AFTER
80262 + };
80263 + struct register_pass_info kernexec_fptr_pass_info = {
80264 + .pass = &kernexec_fptr_pass.pass,
80265 + .reference_pass_name = "ssa",
80266 + .ref_pass_instance_number = 0,
80267 + .pos_op = PASS_POS_INSERT_AFTER
80268 + };
80269 + struct register_pass_info kernexec_retaddr_pass_info = {
80270 + .pass = &kernexec_retaddr_pass.pass,
80271 + .reference_pass_name = "pro_and_epilogue",
80272 + .ref_pass_instance_number = 0,
80273 + .pos_op = PASS_POS_INSERT_AFTER
80274 + };
80275 +
80276 + if (!plugin_default_version_check(version, &gcc_version)) {
80277 + error(G_("incompatible gcc/plugin versions"));
80278 + return 1;
80279 + }
80280 +
80281 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
80282 +
80283 + if (TARGET_64BIT == 0)
80284 + return 0;
80285 +
80286 + for (i = 0; i < argc; ++i) {
80287 + if (!strcmp(argv[i].key, "method")) {
80288 + if (!argv[i].value) {
80289 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80290 + continue;
80291 + }
80292 + if (!strcmp(argv[i].value, "bts")) {
80293 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
80294 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
80295 + } else if (!strcmp(argv[i].value, "or")) {
80296 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
80297 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
80298 + fix_register("r10", 1, 1);
80299 + } else
80300 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
80301 + continue;
80302 + }
80303 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80304 + }
80305 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
80306 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
80307 +
80308 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
80309 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
80310 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
80311 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
80312 +
80313 + return 0;
80314 +}
80315 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
80316 new file mode 100644
80317 index 0000000..ea79948
80318 --- /dev/null
80319 +++ b/tools/gcc/stackleak_plugin.c
80320 @@ -0,0 +1,326 @@
80321 +/*
80322 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80323 + * Licensed under the GPL v2
80324 + *
80325 + * Note: the choice of the license means that the compilation process is
80326 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80327 + * but for the kernel it doesn't matter since it doesn't link against
80328 + * any of the gcc libraries
80329 + *
80330 + * gcc plugin to help implement various PaX features
80331 + *
80332 + * - track lowest stack pointer
80333 + *
80334 + * TODO:
80335 + * - initialize all local variables
80336 + *
80337 + * BUGS:
80338 + * - none known
80339 + */
80340 +#include "gcc-plugin.h"
80341 +#include "config.h"
80342 +#include "system.h"
80343 +#include "coretypes.h"
80344 +#include "tree.h"
80345 +#include "tree-pass.h"
80346 +#include "flags.h"
80347 +#include "intl.h"
80348 +#include "toplev.h"
80349 +#include "plugin.h"
80350 +//#include "expr.h" where are you...
80351 +#include "diagnostic.h"
80352 +#include "plugin-version.h"
80353 +#include "tm.h"
80354 +#include "function.h"
80355 +#include "basic-block.h"
80356 +#include "gimple.h"
80357 +#include "rtl.h"
80358 +#include "emit-rtl.h"
80359 +
80360 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80361 +
80362 +int plugin_is_GPL_compatible;
80363 +
80364 +static int track_frame_size = -1;
80365 +static const char track_function[] = "pax_track_stack";
80366 +static const char check_function[] = "pax_check_alloca";
80367 +static tree pax_check_alloca_decl;
80368 +static tree pax_track_stack_decl;
80369 +static bool init_locals;
80370 +
80371 +static struct plugin_info stackleak_plugin_info = {
80372 + .version = "201203021600",
80373 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
80374 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
80375 +};
80376 +
80377 +static bool gate_stackleak_track_stack(void);
80378 +static unsigned int execute_stackleak_tree_instrument(void);
80379 +static unsigned int execute_stackleak_final(void);
80380 +
80381 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
80382 + .pass = {
80383 + .type = GIMPLE_PASS,
80384 + .name = "stackleak_tree_instrument",
80385 + .gate = gate_stackleak_track_stack,
80386 + .execute = execute_stackleak_tree_instrument,
80387 + .sub = NULL,
80388 + .next = NULL,
80389 + .static_pass_number = 0,
80390 + .tv_id = TV_NONE,
80391 + .properties_required = PROP_gimple_leh | PROP_cfg,
80392 + .properties_provided = 0,
80393 + .properties_destroyed = 0,
80394 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
80395 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
80396 + }
80397 +};
80398 +
80399 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
80400 + .pass = {
80401 + .type = RTL_PASS,
80402 + .name = "stackleak_final",
80403 + .gate = gate_stackleak_track_stack,
80404 + .execute = execute_stackleak_final,
80405 + .sub = NULL,
80406 + .next = NULL,
80407 + .static_pass_number = 0,
80408 + .tv_id = TV_NONE,
80409 + .properties_required = 0,
80410 + .properties_provided = 0,
80411 + .properties_destroyed = 0,
80412 + .todo_flags_start = 0,
80413 + .todo_flags_finish = TODO_dump_func
80414 + }
80415 +};
80416 +
80417 +static bool gate_stackleak_track_stack(void)
80418 +{
80419 + return track_frame_size >= 0;
80420 +}
80421 +
80422 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
80423 +{
80424 + gimple check_alloca;
80425 + tree alloca_size;
80426 +
80427 + // insert call to void pax_check_alloca(unsigned long size)
80428 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
80429 + check_alloca = gimple_build_call(pax_check_alloca_decl, 1, alloca_size);
80430 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
80431 +}
80432 +
80433 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
80434 +{
80435 + gimple track_stack;
80436 +
80437 + // insert call to void pax_track_stack(void)
80438 + track_stack = gimple_build_call(pax_track_stack_decl, 0);
80439 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
80440 +}
80441 +
80442 +#if BUILDING_GCC_VERSION == 4005
80443 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
80444 +{
80445 + tree fndecl;
80446 +
80447 + if (!is_gimple_call(stmt))
80448 + return false;
80449 + fndecl = gimple_call_fndecl(stmt);
80450 + if (!fndecl)
80451 + return false;
80452 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
80453 + return false;
80454 +// print_node(stderr, "pax", fndecl, 4);
80455 + return DECL_FUNCTION_CODE(fndecl) == code;
80456 +}
80457 +#endif
80458 +
80459 +static bool is_alloca(gimple stmt)
80460 +{
80461 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
80462 + return true;
80463 +
80464 +#if BUILDING_GCC_VERSION >= 4007
80465 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
80466 + return true;
80467 +#endif
80468 +
80469 + return false;
80470 +}
80471 +
80472 +static unsigned int execute_stackleak_tree_instrument(void)
80473 +{
80474 + basic_block bb, entry_bb;
80475 + bool prologue_instrumented = false, is_leaf = true;
80476 +
80477 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
80478 +
80479 + // 1. loop through BBs and GIMPLE statements
80480 + FOR_EACH_BB(bb) {
80481 + gimple_stmt_iterator gsi;
80482 +
80483 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80484 + gimple stmt;
80485 +
80486 + stmt = gsi_stmt(gsi);
80487 +
80488 + if (is_gimple_call(stmt))
80489 + is_leaf = false;
80490 +
80491 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
80492 + if (!is_alloca(stmt))
80493 + continue;
80494 +
80495 + // 2. insert stack overflow check before each __builtin_alloca call
80496 + stackleak_check_alloca(&gsi);
80497 +
80498 + // 3. insert track call after each __builtin_alloca call
80499 + stackleak_add_instrumentation(&gsi);
80500 + if (bb == entry_bb)
80501 + prologue_instrumented = true;
80502 + }
80503 + }
80504 +
80505 + // special case for some bad linux code: taking the address of static inline functions will materialize them
80506 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
80507 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
80508 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
80509 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
80510 + return 0;
80511 +
80512 + // 4. insert track call at the beginning
80513 + if (!prologue_instrumented) {
80514 + gimple_stmt_iterator gsi;
80515 +
80516 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
80517 + if (dom_info_available_p(CDI_DOMINATORS))
80518 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
80519 + gsi = gsi_start_bb(bb);
80520 + stackleak_add_instrumentation(&gsi);
80521 + }
80522 +
80523 + return 0;
80524 +}
80525 +
80526 +static unsigned int execute_stackleak_final(void)
80527 +{
80528 + rtx insn;
80529 +
80530 + if (cfun->calls_alloca)
80531 + return 0;
80532 +
80533 + // keep calls only if function frame is big enough
80534 + if (get_frame_size() >= track_frame_size)
80535 + return 0;
80536 +
80537 + // 1. find pax_track_stack calls
80538 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
80539 + // 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))
80540 + rtx body;
80541 +
80542 + if (!CALL_P(insn))
80543 + continue;
80544 + body = PATTERN(insn);
80545 + if (GET_CODE(body) != CALL)
80546 + continue;
80547 + body = XEXP(body, 0);
80548 + if (GET_CODE(body) != MEM)
80549 + continue;
80550 + body = XEXP(body, 0);
80551 + if (GET_CODE(body) != SYMBOL_REF)
80552 + continue;
80553 + if (strcmp(XSTR(body, 0), track_function))
80554 + continue;
80555 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
80556 + // 2. delete call
80557 + insn = delete_insn_and_edges(insn);
80558 +#if BUILDING_GCC_VERSION >= 4007
80559 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
80560 + insn = delete_insn_and_edges(insn);
80561 +#endif
80562 + }
80563 +
80564 +// print_simple_rtl(stderr, get_insns());
80565 +// print_rtl(stderr, get_insns());
80566 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
80567 +
80568 + return 0;
80569 +}
80570 +
80571 +static void stackleak_start_unit(void *gcc_data, void *user_data)
80572 +{
80573 + tree fntype;
80574 +
80575 + // declare void pax_check_alloca(unsigned long size)
80576 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
80577 + pax_check_alloca_decl = build_fn_decl(check_function, fntype);
80578 + DECL_ASSEMBLER_NAME(pax_check_alloca_decl); // for LTO
80579 + TREE_PUBLIC(pax_check_alloca_decl) = 1;
80580 + DECL_EXTERNAL(pax_check_alloca_decl) = 1;
80581 + DECL_ARTIFICIAL(pax_check_alloca_decl) = 1;
80582 +
80583 + // declare void pax_track_stack(void)
80584 + fntype = build_function_type_list(void_type_node, NULL_TREE);
80585 + pax_track_stack_decl = build_fn_decl(track_function, fntype);
80586 + DECL_ASSEMBLER_NAME(pax_track_stack_decl); // for LTO
80587 + TREE_PUBLIC(pax_track_stack_decl) = 1;
80588 + DECL_EXTERNAL(pax_track_stack_decl) = 1;
80589 + DECL_ARTIFICIAL(pax_track_stack_decl) = 1;
80590 +}
80591 +
80592 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80593 +{
80594 + const char * const plugin_name = plugin_info->base_name;
80595 + const int argc = plugin_info->argc;
80596 + const struct plugin_argument * const argv = plugin_info->argv;
80597 + int i;
80598 + struct register_pass_info stackleak_tree_instrument_pass_info = {
80599 + .pass = &stackleak_tree_instrument_pass.pass,
80600 +// .reference_pass_name = "tree_profile",
80601 + .reference_pass_name = "optimized",
80602 + .ref_pass_instance_number = 0,
80603 + .pos_op = PASS_POS_INSERT_BEFORE
80604 + };
80605 + struct register_pass_info stackleak_final_pass_info = {
80606 + .pass = &stackleak_final_rtl_opt_pass.pass,
80607 + .reference_pass_name = "final",
80608 + .ref_pass_instance_number = 0,
80609 + .pos_op = PASS_POS_INSERT_BEFORE
80610 + };
80611 +
80612 + if (!plugin_default_version_check(version, &gcc_version)) {
80613 + error(G_("incompatible gcc/plugin versions"));
80614 + return 1;
80615 + }
80616 +
80617 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
80618 +
80619 + for (i = 0; i < argc; ++i) {
80620 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
80621 + if (!argv[i].value) {
80622 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80623 + continue;
80624 + }
80625 + track_frame_size = atoi(argv[i].value);
80626 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
80627 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
80628 + continue;
80629 + }
80630 + if (!strcmp(argv[i].key, "initialize-locals")) {
80631 + if (argv[i].value) {
80632 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
80633 + continue;
80634 + }
80635 + init_locals = true;
80636 + continue;
80637 + }
80638 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80639 + }
80640 +
80641 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
80642 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
80643 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
80644 +
80645 + return 0;
80646 +}
80647 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
80648 index 6789d78..4afd019 100644
80649 --- a/tools/perf/util/include/asm/alternative-asm.h
80650 +++ b/tools/perf/util/include/asm/alternative-asm.h
80651 @@ -5,4 +5,7 @@
80652
80653 #define altinstruction_entry #
80654
80655 + .macro pax_force_retaddr rip=0, reload=0
80656 + .endm
80657 +
80658 #endif
80659 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
80660 index af0f22f..9a7d479 100644
80661 --- a/usr/gen_init_cpio.c
80662 +++ b/usr/gen_init_cpio.c
80663 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
80664 int retval;
80665 int rc = -1;
80666 int namesize;
80667 - int i;
80668 + unsigned int i;
80669
80670 mode |= S_IFREG;
80671
80672 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
80673 *env_var = *expanded = '\0';
80674 strncat(env_var, start + 2, end - start - 2);
80675 strncat(expanded, new_location, start - new_location);
80676 - strncat(expanded, getenv(env_var), PATH_MAX);
80677 - strncat(expanded, end + 1, PATH_MAX);
80678 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
80679 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
80680 strncpy(new_location, expanded, PATH_MAX);
80681 + new_location[PATH_MAX] = 0;
80682 } else
80683 break;
80684 }
80685 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
80686 index d9cfb78..4f27c10 100644
80687 --- a/virt/kvm/kvm_main.c
80688 +++ b/virt/kvm/kvm_main.c
80689 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
80690
80691 static cpumask_var_t cpus_hardware_enabled;
80692 static int kvm_usage_count = 0;
80693 -static atomic_t hardware_enable_failed;
80694 +static atomic_unchecked_t hardware_enable_failed;
80695
80696 struct kmem_cache *kvm_vcpu_cache;
80697 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
80698 @@ -2268,7 +2268,7 @@ static void hardware_enable_nolock(void *junk)
80699
80700 if (r) {
80701 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
80702 - atomic_inc(&hardware_enable_failed);
80703 + atomic_inc_unchecked(&hardware_enable_failed);
80704 printk(KERN_INFO "kvm: enabling virtualization on "
80705 "CPU%d failed\n", cpu);
80706 }
80707 @@ -2322,10 +2322,10 @@ static int hardware_enable_all(void)
80708
80709 kvm_usage_count++;
80710 if (kvm_usage_count == 1) {
80711 - atomic_set(&hardware_enable_failed, 0);
80712 + atomic_set_unchecked(&hardware_enable_failed, 0);
80713 on_each_cpu(hardware_enable_nolock, NULL, 1);
80714
80715 - if (atomic_read(&hardware_enable_failed)) {
80716 + if (atomic_read_unchecked(&hardware_enable_failed)) {
80717 hardware_disable_all_nolock();
80718 r = -EBUSY;
80719 }
80720 @@ -2676,7 +2676,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
80721 kvm_arch_vcpu_put(vcpu);
80722 }
80723
80724 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80725 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80726 struct module *module)
80727 {
80728 int r;
80729 @@ -2739,7 +2739,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80730 if (!vcpu_align)
80731 vcpu_align = __alignof__(struct kvm_vcpu);
80732 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
80733 - 0, NULL);
80734 + SLAB_USERCOPY, NULL);
80735 if (!kvm_vcpu_cache) {
80736 r = -ENOMEM;
80737 goto out_free_3;
80738 @@ -2749,9 +2749,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80739 if (r)
80740 goto out_free;
80741
80742 - kvm_chardev_ops.owner = module;
80743 - kvm_vm_fops.owner = module;
80744 - kvm_vcpu_fops.owner = module;
80745 + pax_open_kernel();
80746 + *(void **)&kvm_chardev_ops.owner = module;
80747 + *(void **)&kvm_vm_fops.owner = module;
80748 + *(void **)&kvm_vcpu_fops.owner = module;
80749 + pax_close_kernel();
80750
80751 r = misc_register(&kvm_dev);
80752 if (r) {